home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / NCSATELN / TEL23SRC.ZIP / NET / ENET / NETBICC.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-06-24  |  11.1 KB  |  293 lines

  1. /****************************************************************************
  2.  *  BICC 411x Multi Protocol Software code                                  *
  3.  *  Inge Arnesen 1989                                                       *
  4.  *                                                                          *
  5.  *  Module to interface NCSA Telnet to the BICC 411x cards through the      *
  6.  *  ISOLAN Multi Protocol Software. This enables NCSA Telnet to coexist     *
  7.  *  with Novell Netware.                                                    *
  8.  *                                                                          *
  9.  *  THIS IS NOT A PART OF NCSA TELNET                                       *
  10.  *                                                                          *
  11.  ****************************************************************************
  12.  *                                                                          *
  13.  *                                                                          *
  14.  *      (C) Inge Arnesen                                                    *
  15.  *      Institute of Social Research                                        *
  16.  *      Munthesgt. 31                                                       *
  17.  *      N-0260 Oslo, NORWAY                                                 *
  18.  *                                                                          *
  19.  *                                                                          *
  20.  *    DISCLAIMER: This code is not property of the institute, but of        *
  21.  *                the author himself. No responsibility is claimed          *
  22.  *                for anything whatsoever due to the use of this code!      *
  23.  *                                                                          *
  24.  ****************************************************************************
  25.  *                                                                          *
  26.  *    Created      : 89.05.27  by Inge Arnesen                              *
  27.  *    Last modified: 89.05.29  by Inge Arnesen                              *
  28.  *                                                                          *
  29.  *    History: 89.05.29 Initial alpha version                               *
  30.  *             89.07.01 Beta started - no changes                           *
  31.  *             89.10.06 Final release - no changes                          *
  32.  *                                                                          *
  33.  ****************************************************************************
  34.  
  35.         ILrecv          - Polled receive (dummy)
  36.         ILetopen        - Initialize Ethernet SW
  37.         ILetclose       - Close down Ethernet SW
  38.         ILgetaddr       - Get Ethernet cards address (must be initialized first)
  39.         ILetaddr        - Set Ethernet cards address (dummy)
  40.         ILxmit          - Send data across the Ethernet
  41.         ILetupdate      - Update buffer pointers
  42.  
  43.  
  44.         COMPILE:
  45.                 cl -Ze -Zp -Gs iso.c
  46.         Options are:    Enable language extentions, pack structure members,
  47.                         Remove calls to Stack probe routine
  48.  
  49.  */
  50. /* Standard include files */
  51. #include        <conio.h>       /* Microsoft 'C' Include file   */
  52. #include        <ctype.h>       /* Microsoft 'C' Include file   */
  53. #include        <dos.h>         /* Microsoft 'C' Include file   */
  54. #include        <stdio.h>       /* Microsoft 'C' Include file   */
  55. #include        <string.h>      /* Microsoft 'C' Include file   */
  56.  
  57. /* NCSA include files */
  58. #include        "protocol.h"
  59. #include        "data.h"
  60. #include        "bicc.h"
  61. #include        "externs.h"
  62.  
  63. extern void ANR_ENTRY();
  64. unsigned int anr_c(struct acb *acb_ptr);
  65. struct mps_status stat_buf;
  66.  
  67.  
  68. extern unsigned char rstat;             /*  last status from read               */
  69. extern unsigned char *bufpt;            /*  current buffer pointer              */
  70. extern unsigned char *buforg;           /*  pointer to beginning of buffer      */
  71. extern unsigned char *bufend;           /*  pointer to end of buffer            */
  72. extern unsigned char *bufread;          /*  pointer to where program is reading */
  73. extern unsigned int bufbig;             /*  integer, how many bytes we have     */
  74. extern unsigned int buflim;             /*  integer, max bytes we can have      */
  75.  
  76. ILgetaddr(ethaddr, memaddr, ioaddr)
  77. unsigned char *ethaddr;
  78. unsigned int memaddr, ioaddr;
  79. {
  80.         int i; 
  81.         struct tcb t, *h;
  82.         union REGS inregs, outregs;
  83.         struct SREGS segregs;
  84.  
  85.         /* Then send status request */
  86.         t.tcbcommand = PORT_STATUS;
  87.         t.tcbcid = PORT_STATUS;
  88.         t.tcbbaddr.status= &stat_buf;
  89.         t.tcblength    = sizeof(struct mps_status);
  90.         t.tcblnet= 0xffffffff;
  91.  
  92.         t.tcbasync= ANR_ENTRY;  /* This is a FUNCTION ptr */
  93.  
  94.         /*
  95.          *      now issue the int5b, es:bx point at the tcb
  96.          *
  97.          */
  98.         h= &t; 
  99.         segregs.es= FP_SEG(h);
  100.         inregs.x.bx= FP_OFF(h);
  101.         int86x(0x5B, &inregs, &outregs, &segregs);
  102.  
  103.         for (i= 9; i < 15; i++)
  104.                 ethaddr[i - 9]= stat_buf.address[i];
  105.  
  106.         return(0);
  107. }
  108.  
  109. void ILrecv(void )
  110. {
  111. }
  112.  
  113. void ILetupdate(void )
  114. {
  115.         /* Update all the pointers etc. */
  116.         bufbig-= *((int *)bufread) + sizeof( int );
  117.         bufread+= *((int *)bufread) + sizeof(int);
  118.         if(bufread >= bufend)
  119.                 bufread= buforg;
  120. }
  121.  
  122. int ILxmit(pack, size)
  123. DLAYER *pack;
  124. int size;
  125. {
  126.         struct tcb t, *h;               
  127.         int i;
  128.         union REGS inregs, outregs;
  129.         struct SREGS segregs;
  130.  
  131.         t.tcbraddr[2] = 0;
  132.         t.tcbraddr[3] = 0;
  133.         t.tcbraddr[7] = 0;
  134.         t.tcbraddr[8] = 0;   /* LSAP */
  135.         t.tcbraddr[9] = pack->dest[0];     /* ETHADDR */
  136.         t.tcbraddr[10] = pack->dest[1];
  137.         t.tcbraddr[11] = pack->dest[2];
  138.         t.tcbraddr[12] = pack->dest[3];
  139.         t.tcbraddr[13] = pack->dest[4];
  140.         t.tcbraddr[14] = pack->dest[5];      /*--to here--*/
  141.         t.tcbraddr[15] = 0;
  142.         t.tcbcommand = L_DATA_SEND;
  143.  
  144.         t.tcbstatus = intswap(pack->type);
  145.         for (i = 0; i < 16; ++i)
  146.                 t.tcbladdr[i] = 0;
  147.  
  148.         t.tcbasync= 0;   /* No ANR */
  149.  
  150.         /*      setup pointer to data buffer    */
  151.         t.tcbbaddr.pt  = (char far *)pack + sizeof(DLAYER);
  152.         t.tcblength    = size - sizeof(DLAYER);
  153.         /*
  154.          *      now issue the int5b, es:bx point at the tcb
  155.          *
  156.          */
  157.         h= &t;
  158.         segregs.es= FP_SEG(h);
  159.         inregs.x.bx= FP_OFF(h);
  160.         int86x(0x5B, &inregs, &outregs, &segregs);
  161.         return(outregs.h.al);
  162. }
  163.  
  164. ILetopen(ethaddr, ioirq, memaddr, ioaddr)
  165. unsigned char *ethaddr;
  166. unsigned int ioirq;
  167. unsigned int memaddr, ioaddr;
  168. {
  169.         struct tcb t, *h;
  170.         int i;
  171.         union REGS inregs, outregs;
  172.         struct SREGS segregs;
  173.  
  174.  
  175.         t.tcbcommand = L_ACTIVATE;
  176.         t.tcbcid = L_ACTIVATE;
  177.  
  178.         for (i = 0; i < 16; ++i)
  179.                 t.tcbladdr[i] = 0;
  180.  
  181.         t.tcbasync= ANR_ENTRY;
  182.  
  183.         /*
  184.          *      now issue the int5b, es:bx point at the tcb
  185.          *
  186.          */
  187.         h= &t; 
  188.         segregs.es= FP_SEG(h);
  189.         inregs.x.bx= FP_OFF(h);
  190.         int86x(0x5B, &inregs, &outregs, &segregs);
  191.  
  192.         return(outregs.h.al);
  193. }
  194.  
  195. int ILetclose(void )
  196. {
  197.         union REGS inregs, outregs;
  198.         struct SREGS segregs;
  199.         struct tcb t, *h;               
  200.         int i;
  201.  
  202.         t.tcbcommand = L_DEACTIVATE;
  203.         t.tcbcid = 0; /* Not used */
  204.  
  205.         for (i = 0; i < 16; ++i)
  206.                 t.tcbladdr[i] = 0;
  207.  
  208.         /*
  209.          *      now issue the int5b, es:bx point at the tcb
  210.          *
  211.          */
  212.         h= &t; 
  213.         segregs.es= FP_SEG(h);
  214.         inregs.x.bx= FP_OFF(h);
  215.         int86x(0x5B, &inregs, &outregs, &segregs);
  216.         return(outregs.h.al);
  217. }
  218.  
  219.  
  220. /*
  221.  *      Note: anr_c returns zero to the Multi Protocol Handler
  222.  *
  223.  *      Inside the ANR, Operating System calls must not be made, nor must
  224.  *      space be grabbed from the Heap.  The use of Automatic variables
  225.  *      is allowed, but make sure the stack is large enough.
  226.  */
  227.  
  228. unsigned int anr_c(acb_ptr)
  229. struct  acb     *acb_ptr;
  230. {
  231.         int i;
  232.         int mine= TRUE;  /* We suspect all packets of coming from this card */
  233.                         /* Loop back is supported on link level */      
  234.                         /* If its mine, drop it like a hot potato */
  235.  
  236.         char    far     *buffer_pt;     /* buffer pointer       */
  237.  
  238.         if(acb_ptr->acbcmd != PORT_STATUS)
  239.         {
  240.                 switch(acb_ptr->acbeventcode)
  241.                 {
  242.                 case L_ACTIVATE_CONF:
  243.                         break;
  244.                 case L_DATA_IND:
  245.                 case M_DATA_IND:
  246.                         /* If it is not one of mine, mark it as such */  
  247.                         for(i= 0; i < 6 ; i++)
  248.                                 if(acb_ptr->acbraddr[i+9] != nnmyaddr[i])
  249.                                 {
  250.                                         mine= FALSE; 
  251.                                         break;
  252.                                 }       
  253.                         if (!mine)
  254.                         {
  255.                         /* with llc and mac commands, it's neccessary to copy   */
  256.                         /* the received data.                                   */
  257.  
  258.                         buffer_pt = acb_ptr->acbbaddr.pt;
  259.                         /* The above instruction in theory should not be needed */
  260.                         /* but is in practise                                   */ 
  261.  
  262.                         if(bufbig <= buflim) /* Enough room in the buffer ? */
  263.                         {
  264.                                 if(bufpt >= bufend) /* Wrap around ? */
  265.                                 {
  266.                                         bufpt= buforg;
  267.                                 }
  268.                                 /* Size of packet inc. DLAYER first in buffer */
  269.                                 *((int *)bufpt)= acb_ptr->acblen + sizeof(DLAYER);
  270.                                 bufpt+= 2;
  271.                                 ((DLAYER *)bufpt)->type= intswap(acb_ptr->acbstatus);
  272.                                 for(i= 0; i < 6 ; i++)
  273.                                 {
  274.                                         ((DLAYER *)bufpt)->dest[i]= 
  275.                                                 acb_ptr->acbladdr[i+9];
  276.                                         ((DLAYER *)bufpt)->me[i]= 
  277.                                                 acb_ptr->acbraddr[i+9];
  278.                                 }
  279.                                 bufpt+= sizeof(DLAYER);
  280.                                 movedata(FP_SEG( buffer_pt ), FP_OFF( buffer_pt ), 
  281.                                         FP_SEG(bufpt), FP_OFF(bufpt), acb_ptr->acblen);
  282.                                 bufpt+= acb_ptr->acblen;
  283.                                 bufbig+= acb_ptr->acblen + sizeof(DLAYER) + sizeof(int);
  284.                         }
  285.                         /* else we are going to drop packets ! */
  286.                         }
  287.                         break;
  288.                 }
  289.         }
  290.         return(0);
  291. }
  292.  
  293.