home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / archives / msvp98b1.lzh / MSNSED.C < prev    next >
Text File  |  1993-05-14  |  4KB  |  160 lines

  1. /* File MSNSED.C
  2.  * Ethernet Driver support routines
  3.  *
  4.  * Copyright (C) 1991, University of Waterloo.
  5.  * Copyright (C) 1985, 1992, Trustees of Columbia University in the 
  6.  * City of New York.  Permission is granted to any individual or institution
  7.  * to use this software as long as it is not sold for profit.  This copyright
  8.  * notice must be retained.  This software may not be included in commercial
  9.  * products without written permission of Columbia University.
  10.  *
  11.  * Original version created by Erick Engelke of the University of
  12.  *  Waterloo, Waterloo, Ontario, Canada.
  13.  * Adapted and modified for MS-DOS Kermit by Joe R. Doupnik, 
  14.  *  Utah State University, jrd@cc.usu.edu, jrd@usu.Bitnet.
  15.  *
  16.  * Last edit
  17.  * 6 Sept 1991
  18.  *
  19.  *  The TCP code uses Ethernet constants for protocol numbers and 48 bits
  20.  *  for address.  Also, 0xffffffffffff is assumed to be a broadcast.
  21.  *
  22.  *  If you need to write a new driver, implement it at this level and use
  23.  *  the above mentioned constants as this program's constants, not device
  24.  *  dependant constants.
  25.  *
  26.  *  The packet driver code lies below this.
  27.  *
  28.  *  eth_addr    - Ethernet address of this host.
  29.  *  eth_brdcast    - Ethernet broadcast address.
  30.  */
  31.  
  32. #include "msntcp.h"
  33. #include "msnlib.h"
  34.  
  35. #define ETH_MIN    60              /* Minimum Ethernet packet size */
  36.  
  37. eth_address eth_addr = {0};    /* local ethernet address */
  38. eth_address eth_brdcast;    /* Ethernet broadcast address */
  39. word pktdevclass = 1;        /* Ethernet = 1, SLIP = 6 */
  40.  
  41. /* Ethernet Interface */
  42.  
  43. struct ether {
  44.     byte    dest[6];
  45.     byte    src[6];
  46.     word    type;
  47.     byte    data[ETH_MSS + 60];
  48. };
  49. static struct ether outbuf = {{0},{0},0,{0}};
  50.  
  51. /*
  52.  *  Initialize the Ethernet Interface, and this package.  Enable input on
  53.  *  all packet buffers.
  54.  */
  55. int 
  56. eth_init()
  57. {
  58. /* Init Packet Driver, get Ethernet address, set bdcast address to all 1's */
  59.     memset(&outbuf, 0, sizeof(struct ether));
  60.     if (pkt_eth_init() == 0)
  61.         return (0);                /* 0 is failure */
  62.     memset(eth_brdcast, 0xff, sizeof(eth_address));
  63.     return (1);                    /* success */
  64. }
  65.  
  66. /*
  67.  * eth_FormatPacket places the next packet into the buffer and uses the
  68.  * type field for protocol determination.  Note, I only maintain a single
  69.  * output buffer, and it gets used quickly then released.  The benefits of
  70.  * non-blocking systems are immense.
  71.  */
  72.  
  73.  
  74. byte *
  75. eth_formatpacket(void *eth_dest, word eth_type)
  76. {
  77.     if (eth_dest == NULL) return (NULL);    /* failure */
  78.  
  79.     memset(&outbuf, 0, sizeof(struct ether));
  80.  
  81.     switch (pktdevclass) {
  82.     case PD_ETHER :
  83.         bcopy(eth_dest, outbuf.dest, 6);
  84.         bcopy(eth_addr, outbuf.src, 6);
  85.         outbuf.type = eth_type;
  86.         return(outbuf.data);        /* outbuf is permanent */
  87.     case PD_SLIP :
  88.         return(outbuf.dest);    /* really data because no header */
  89.     }
  90.     return (NULL);                /* default */
  91. }
  92.  
  93. /*
  94.  * eth_send does the actual transmission once we are complete with the
  95.  * buffer.  Do any last minute patches here, like fix the size.
  96.  */
  97. int
  98. eth_send(word len)
  99. {
  100.     if ((pktdevclass == PD_ETHER) && ((len += 14) < ETH_MIN))
  101.     len = ETH_MIN;
  102.     return (pkt_send((byte *) &outbuf, len));    /* send to packet driver */
  103. }
  104.  
  105. /*
  106.  * eth_free - free an input buffer once it is no longer needed
  107.  * If pointer to NULL, release all buffers
  108.  */
  109. void 
  110. eth_free(void *buf)
  111. {
  112.     if (buf != NULL)
  113.     pkt_buf_release(buf);        /* free this buffer ptr */
  114.     else
  115.     pkt_buf_wipe();            /* if none then clear all */
  116. }
  117.  
  118. /*
  119.  * eth_arrived - if a new packet has arrived, read it and fill pointer
  120.  * with type of packet
  121.  */
  122.  
  123. byte * 
  124. eth_arrived(word *type_ptr)
  125. {
  126.     struct ether * temp;    /* Expect SLIP pkts to have dummy MAC hdr */
  127.  
  128.     if (type_ptr == NULL) return (NULL);
  129.  
  130.     if ((temp = (struct ether *)pkt_received()) != NULL) {
  131.     switch (pktdevclass) {
  132.         case PD_ETHER: *type_ptr = temp->type;    /* value of TYPE */
  133.                return(temp->data);        /* address of data */
  134.         case PD_SLIP: *type_ptr = 0x0008;
  135.               return((byte *)temp);        /* none to skip */
  136.         default: return (NULL);
  137.     }
  138.     }
  139.     return(NULL);
  140. }
  141.  
  142. /*
  143.  * eth_release - release the hardware
  144.  */
  145. void 
  146. eth_release()
  147. {
  148.     pkt_release();
  149. }
  150.  
  151. /*
  152.  * eth_hardware - return pointer to hardware address of a packet
  153.  */
  154. void *
  155. eth_hardware(byte *p)
  156. {
  157.     if (p == NULL || pktdevclass == PD_SLIP) return (NULL);
  158.     return (p - 8);
  159. }
  160.