home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / mskermit / msnsed.c < prev    next >
C/C++ Source or Header  |  2020-01-01  |  4KB  |  157 lines

  1. /* File MSNSED.C
  2.  * Ethernet Driver support routines
  3.  *
  4.  * Copyright (C) 1991, University of Waterloo.
  5.  *    Copyright (C) 1982, 1997, Trustees of Columbia University in the 
  6.  *    City of New York.  The MS-DOS Kermit software may not be, in whole 
  7.  *    or in part, licensed or sold for profit as a software product itself,
  8.  *    nor may it be included in or distributed with commercial products
  9.  *    or otherwise distributed by commercial concerns to their clients 
  10.  *    or customers without written permission of the Office of Kermit 
  11.  *    Development and Distribution, Columbia University.  This copyright 
  12.  *    notice must not be removed, altered, or obscured.
  13.  *
  14.  * Original version created by Erick Engelke of the University of
  15.  *  Waterloo, Waterloo, Ontario, Canada.
  16.  * Adapted and modified for MS-DOS Kermit by Joe R. Doupnik, 
  17.  *  Utah State University, jrd@cc.usu.edu, jrd@usu.Bitnet.
  18.  *
  19.  * Last edit
  20.  * 12 Jan 1995 v3.14
  21.  *
  22.  *  The TCP code uses Ethernet constants for protocol numbers and 48 bits
  23.  *  for address.  Also, 0xffffffffffff is assumed to be a broadcast.
  24.  *
  25.  *  If you need to write a new driver, implement it at this level and use
  26.  *  the above mentioned constants as this program's constants, not device
  27.  *  dependant constants.
  28.  *
  29.  *  The packet driver code lies below this.
  30.  *
  31.  *  eth_addr    - Ethernet address of this host.
  32.  *  eth_brdcast    - Ethernet broadcast address.
  33.  */
  34.  
  35. #include "msntcp.h"
  36. #include "msnlib.h"
  37.  
  38. #define ETH_MIN    60              /* Minimum Ethernet packet size */
  39.  
  40. eth_address eth_addr = {0};    /* local ethernet address */
  41. eth_address eth_brdcast ={0xff,0xff,0xff,0xff,0xff,0xff};
  42.                 /* Ethernet broadcast address */
  43. word pktdevclass = 1;        /* Ethernet = 1, SLIP = 6 */
  44. extern word MAC_len;
  45. static void lan_busy(void);    /* waits while lan adapter busy, or 4 secs */
  46.  
  47. /* Ethernet Interface */
  48.  
  49. struct ether {
  50.     byte    dest[6];
  51.     byte    src[6];
  52.     word    type;
  53.     byte    data[ETH_MSS + 60];
  54. };
  55. static struct ether outbuf = {{0},{0},0,{0}};
  56.  
  57. /* Write Ethernet MAC header and return pointer to data field. */
  58. /* Uses single output frame buffer, named outbuf. */
  59. byte *
  60. eth_formatpacket(void *eth_dest, word eth_type)
  61. {
  62.     memset(&outbuf, 0, 6+6+2+64);        /* clear small frame */
  63.  
  64.     switch (pktdevclass) 
  65.             {
  66.         case PD_ETHER:
  67.             bcopy(eth_dest, outbuf.dest, 6);
  68.             bcopy(eth_addr, outbuf.src, 6);
  69.             outbuf.type = eth_type;
  70.             return(outbuf.data);    /* outbuf is permanent */
  71.         case PD_SLIP:
  72.             return(outbuf.dest);    /* really data because no header */
  73.             }
  74.     return (NULL);                /* default */
  75. }
  76.  
  77. /*
  78.  * eth_send does the actual transmission once we are complete with the
  79.  * buffer.  Do any last minute patches here, like fix the size.
  80.  */
  81. int
  82. eth_send(word len)
  83. {
  84.     if (len & 1) len++;        /* if odd make even */
  85.     if ((pktdevclass == PD_ETHER) && ((len += 14) < ETH_MIN))
  86.         len = ETH_MIN;
  87.     return (pkt_send((byte *) &outbuf, len));  /* send to link driver */
  88. }
  89.  
  90. /*
  91.  * eth_free - free an input buffer once it is no longer needed
  92.  * If pointer to NULL, release all buffers
  93.  */
  94. void 
  95. eth_free(void *buf)
  96. {
  97.     if (buf != NULL)
  98.         pkt_buf_release(buf);        /* free this buffer ptr */
  99.     else
  100.         pkt_buf_wipe();            /* if none then clear all */
  101. }
  102.  
  103. /*
  104.  * eth_arrived - if a new packet has arrived, read it and fill pointer
  105.  * with type of packet
  106.  */
  107.  
  108. byte * 
  109. eth_arrived(word *type_ptr)
  110. {
  111.     register int i;
  112.     register struct ether * temp;
  113.  
  114.     if (type_ptr == NULL) return (NULL);
  115.     if ((temp = (struct ether *)pkt_received()) == NULL)
  116.         return (NULL);            /* nothing there folks */
  117.  
  118.     switch (pktdevclass)
  119.         {
  120.         case PD_ETHER:
  121.             *type_ptr = temp->type;        /* value of TYPE */
  122.             if (MAC_len == 0)    /* no MAC address to test */
  123.                 return (temp->data);
  124.                 for (i = 5; i >= 0; i--)    /*source same as us?*/
  125.                     if (temp->src[i] != eth_addr[i])
  126.                     return(temp->data); /* ptr to data */
  127.                         /* NDIS echo stupidity */
  128.             eth_free(temp->data);        /* discard packet */
  129.             return (NULL);
  130.  
  131.         case PD_SLIP:
  132.                 *type_ptr = TYPE_IP;
  133.             return((byte *)temp);        /* no MAC to skip */
  134.         default:
  135.             return (NULL);
  136.             }
  137. }
  138.  
  139. /*
  140.  * eth_release - release the hardware
  141.  */
  142. void 
  143. eth_release(void)
  144. {
  145.     pkt_release();
  146. }
  147.  
  148. /*
  149.  * eth_hardware - return pointer to source hardware address of a frame
  150.  */
  151. void *
  152. eth_hardware(byte *p)
  153. {
  154.     if (p == NULL || pktdevclass == PD_SLIP) return (NULL);
  155.     return (p - 8);
  156. }
  157.