home *** CD-ROM | disk | FTP | other *** search
/ Hacker Chronicles 2 / HACKER2.BIN / 527.L2E.C < prev    next >
Text File  |  1988-05-14  |  11KB  |  206 lines

  1. /**************************************************************************\
  2. *                                                                          *
  3. *                                                                          *
  4. *    *****                      *****                                      *
  5. *      *****                  *****                                        *
  6. *        *****              *****                                          *
  7. *          *****          *****                                            *
  8. *            *****      *****                                              *
  9. *              *****  *****                                                *
  10. *            *****      *****                                              *
  11. *          *****          *****          The Firmware. The Net.            *
  12. *        *****              *****        Portable. Compatible.             *
  13. *      *****                  *****      Public Domain.                    *
  14. *    *****                      *****    By NORD><LINK.                    *
  15. *                                                                          *
  16. *                                                                          *
  17. *                                                                          *
  18. *    L2E.C   -   Level 2, Teil 5                                           *
  19. *                                                                          *
  20. *                Dieser Teil ist eine Zusammenfassung der                  *
  21. *                zeitunkritischsten Funktionen und kann somit mit der      *
  22. *                groessten Platzersparnis optimiert werden.                *
  23. *                                                                          *
  24. *                                                                          *
  25. *    angelegt:      DC4OX                                                  *
  26. *    modifiziert:                                                          *
  27. *                                                                          *
  28. \**************************************************************************/
  29.  
  30.  
  31.  
  32.  
  33.  
  34. /*                                                             Includes   */
  35. /**************************************************************************/
  36.  
  37. #include "all.h"         /* allgemeine Festlegungen                       */
  38. #include "l2.h"          /* Festlegungen/Datenstrukturen fuer den Level 2 */
  39. #include "l2s.h"         /* Zugriff auf die State-Tabellen                */
  40. #include "l2ext.h"       /* globale Variable / nicht int-Funktionen       */
  41.  
  42.  
  43.  
  44.  
  45.  
  46. /**************************************************************************\
  47. *                                                                          *
  48. * action      :  "level 2 initialize"                                      *
  49. *                                                                          *
  50. *                Initialisieren des dynamischen Freispeichers sowie        *
  51. *                aller Level-2-spezifischer Listen- und Framekoepfe.       *
  52. *                                                                          *
  53.  **************************************************************************
  54. *                                                                          *
  55. * parameter   :  -                                                         *
  56. *                                                                          *
  57. * r/o globals :  (Routing-Table)                                           *
  58. *                                                                          *
  59. * r/w globals :  lnkpoi   - Zeiger in lnktbl                               *
  60. *                rxfl     - "leere Liste"                                  *
  61. *                monfl    - "leere Liste"                                  *
  62. *                stfl     - "leere Liste"                                  *
  63. *                trfl     - "leere Liste"                                  *
  64. *                freel    - Liste freier 32-Byte-Buffer dynam. Speicher,   *
  65. *                           jeder Buffer ist initialisiert :  mbpc, mbgc   *
  66. *                           geloescht, mbbp initialisiert, mbl             *
  67. *                           "leere Liste", Buffer der Routing-Table        *
  68. *                           werden nicht neu allokiert bei Warmstart       *
  69. *                nmblks   - 0                                              *
  70. *                nmbfre   - Anzahl freie 32-Byte-Buffer dynam. Speicher    *
  71. *                txl2fl[] - alle Listenkoepfe "leere Liste"                *
  72. *                rxfhd[]  - alle Eintrage NULL                             *
  73. *                txfhd[]  - alle Eintrage NULL                             *
  74. *                istraf[] - alle Eintrage NULL                             *
  75. *                lnktbl   - alle Linkbloecke werden initialisiert          *
  76. *                           (rcvdil, sendil, rcvd, tosend, state, srcid    *
  77. *                           loeschen, snglT1, k, N2, V2link setzen,        *
  78. *                           reslnk() wird aufgerufen)                      *
  79. *                                                                          *
  80. * locals      :  s.u.                                                      *
  81. *                                                                          *
  82. * returns     :  -                                                         *
  83. *                                                                          *
  84. \**************************************************************************/
  85.  
  86. VOID l2init()
  87.   {
  88.     char       *actbp;        /* Zeiger auf aktuellen Freibuffer          */
  89.     char       *nextbp;       /* Zeiger auf naechsten Freibuffer          */
  90.     char       *minm;         /* niedrigste nutzbare Freispeicherstelle   */
  91.     char       *maxm;         /* hoechste nutzbare Freispeicherstelle     */
  92.     unsigned    n;            /* Laufindex                                */
  93.  
  94.  
  95.     inithd(&rxfl);            /* diverse Listenkoepfe = "leere Liste"     */
  96. #ifdef FIRMWARE
  97.     inithd(&monfl);           /* Monitor gibt es nur in Firmware          */
  98. #endif
  99.     inithd(&stfl);
  100.     inithd(&trfl);
  101.     inithd(&freel);
  102.  
  103.     nmblks = nmbfre = 0;      /* keine Links aktiv, noch keine Freibuffer */
  104.     minm = actbp = minmem();  /* niedrigste nutzbare Freispeicherstelle   */
  105.     maxm = maxmem();          /* hoechste nutzbare Freispeicherstelle     */
  106.  
  107.     while (    ((nextbp = actbp + sizeof(MB) - 1) <= maxm)
  108.             && (nextbp >= minm)
  109.           )                                  /* solange Buffer in Frei-   */
  110.       {                                      /* speicher passen, es keine */
  111.         if (!iswarm() || !isrout(actbp))     /* Routingtablebuffer sind   */
  112.           dealoc(actbp);                     /* oder Kaltstart, diese     */
  113.         actbp = nextbp + 1;                  /* initialisieren und in     */
  114.       }                                      /* Freispeicherliste haengen */
  115.        
  116.     for (n = 0; n < L2PNUM; ++n)             /* fuer alle Ports TX-Frame- */
  117.       {                                      /* listen "leer", RX- und    */
  118.        inithd(&txl2fl[n]);                   /* TX-Framekoepfe unbesetzt, */
  119.                                              /* noch nichts gesendet      */
  120.  
  121. #ifdef FIRMWARE
  122.        rxfhd[n] = txfhd[n] = (MBHEAD *)NULL;
  123. #else
  124.        rxfhd[n] = txfhd[n] = (MBHEAD *)(istraf[n] = (char)NULL);
  125. #endif
  126.  
  127.       }
  128.       
  129.     for (n = 0, lnkpoi = lnktbl; n < LINKNMBR; ++n, ++lnkpoi)  /* Link-   */
  130.       {                                                        /* bloecke */
  131.         lnkpoi->state = lnkpoi->rcvd = lnkpoi->tosend = NULL;  /* initia- */
  132.         inithd(&lnkpoi->rcvdil);                               /* lisier- */
  133.         inithd(&lnkpoi->sendil);                               /* en      */
  134.         inilbl();
  135.         reslnk(); /* damit L-Kommando nach Kaltstart im Hostmode richtig  */
  136.       }
  137.   }
  138.  
  139.  
  140.  
  141.  
  142.  
  143. /**************************************************************************\
  144. *                                                                          *
  145. * "send frame reject"                                                      *
  146. *                                                                          *
  147. * Wenn Linkzustand des aktuellen Linkblocks (lnkpoi) nicht Disconnectet/   *
  148. * Linksetup/Disconnectrequest/Framereject ist, FRMR-Zustand einnehmen      *
  149. * (state), FRMR den hoeheren Leveln melden, FRMR-Infobytes aufbauen mit    *
  150. * den Flags ZYXW und merken im Linkblock (frmr), FRACK-Timer abschalten,   *
  151. * FRMR senden.                                                             *
  152. *                                                                          *
  153. \**************************************************************************/
  154.  
  155. VOID sdfrmr(ZYXW)
  156.  
  157. char ZYXW;
  158.  
  159.   {
  160.     char *frmrip;             /* Zeiger in Linkblock-FRMR-Infobytes       */
  161.     
  162.     if (lnkpoi->state >= L2SIXFER)           /* nur ausfuehren, wenn s.o. */
  163.       {
  164.         frmrip = lnkpoi->frmr;               /* Zeiger auf FRMR-Infobytes */
  165.         *frmrip++ = rxfctl | rxfPF;          /* die FRMR-Infobytes        */
  166.         *frmrip++ =   lnkpoi->VR << 5        /* aufbauen                  */
  167.                     | (!rxfCR ? 0x10 : 0)
  168.                     | lnkpoi->VS << 1;
  169.         *frmrip   = ZYXW;
  170.         lnkpoi->state = L2SFRREJ;            /* Linkzustand: Framereject  */
  171.         clrT1();                             /* FRACK-Timer abschalten    */
  172.         l2tolx(L2MFRMRT);                    /* FRMR melden               */
  173.         xfrmr();                             /* FRMR aussenden            */
  174.       }
  175.   }
  176.  
  177.  
  178.  
  179.  
  180.  
  181. /**************************************************************************\
  182. *                                                                          *
  183. * FRMR senden mit den im aktuellen Linkblock (lnkpoi) gegebenen            *
  184. * Parametern (frmr). Die txf...-Parameter muessen gesetzt sein bis auf     *
  185. * txfctl.                                                                  *
  186. *                                                                          *
  187. \**************************************************************************/
  188.  
  189. VOID xfrmr()
  190.   {
  191.     char     *frmrip;         /* Zeiger in Linkblock-FRMR-Infobytes       */
  192.     MBHEAD   *fbp;            /* Framemessageheader fuer Frameaufbau      */
  193.     
  194.     txfctl = L2CFRMR;                   /* FRMR-Frame !                   */
  195.     fbp = makfhd(L2FUS | L2FT1ST);      /* Buffer holen, Framekopf bauen  */
  196.     frmrip = lnkpoi->frmr;              /* Zeiger auf FRMR-Infobytes      */
  197.     putchr(*frmrip++,fbp);              /* FRMR-Infobytes in Frame        */
  198.     putchr(*frmrip++,fbp);
  199.     putchr(*frmrip  ,fbp);
  200.     sdl2fr(fbp);                        /* Frame aussenden                */
  201.   }
  202.  
  203.  
  204.  
  205. /* Ende von L2E.C */
  206.