home *** CD-ROM | disk | FTP | other *** search
/ Super Net 1 / SUPERNET_1.iso / PC / OTROS / MSDOS / WATTCP / UNZIPPED / MSWATTCP / SRC / PCSED.C < prev    next >
Encoding:
C/C++ Source or Header  |  1993-03-24  |  3.0 KB  |  134 lines

  1. /***
  2.  *
  3.  * File: pcsed.c
  4.  *
  5.  * 18-jun-92 lr
  6.  *
  7.  * Ethernet Driver Routines
  8.  *
  9.  *  The TCP code uses Ethernet constants for protocol numbers and 48 bits
  10.  *  for address.  Also, 0xffffffffffff is assumed to be a broadcast.
  11.  *
  12.  *  If you need to write a new driver, implement it at this level and use
  13.  *  the above mentioned constants as this program's constants, not device
  14.  *  dependant constants.
  15.  *
  16.  *  The packet driver code lies below this and really ought to be rewritten
  17.  *  in assembly language.
  18.  *
  19.  *  _eth_addr      - Ethernet address of this host.
  20.  *  _eth_brdcast - Ethernet broadcast address.
  21.  */
  22.  
  23. #define PCSED
  24. #define WATTCP_KERNEL
  25. #include <tcp.h>
  26. #include <ethdev.h>
  27.  
  28. /********************** STATICS ***********************/
  29. static struct ether outbuf;
  30. /******************* END OF STATICS *******************/
  31.  
  32. /*
  33.  * Initialize the Ethernet Interface, and this package.
  34.  * Enable input on all packet buffers.
  35.  */
  36.  
  37. void
  38. _eth_init(void)
  39. {
  40.     movmem( _pkt_eth_init() , _eth_addr, 6 );
  41.     memset( &_eth_brdcast, 0xff, sizeof( _eth_brdcast ));
  42. }
  43.  
  44. /*
  45.  * _eth_FormatPacket places the next packet into the buffer and uses the
  46.  * type field for protocol determination.  Note, I only maintain a single
  47.  * output buffer, and it gets used quickly then released.  The benefits of
  48.  * non-blocking systems are immense.
  49.  */
  50.  
  51.  
  52. byte *
  53. _eth_formatpacket( void *eth_dest, word eth_type )
  54. {
  55.     memset( &outbuf.data, 0, sizeof(in_Header)+sizeof(tcp_Header));
  56.     switch ( _pktdevclass ) {
  57.     case PD_ETHER :
  58.         movmem( eth_dest, outbuf.dest, 6 );
  59.         movmem( _eth_addr, outbuf.src, 6 );
  60.         outbuf.type = eth_type;
  61.         return( outbuf.data );
  62.     case PD_SLIP :
  63.         return( (byte *)&outbuf );    /* no header */
  64.     }
  65.     return NULL; /* can't be, unless errors */
  66. }
  67.  
  68. /*
  69.  * _eth_send does the actual transmission once we are complete with the
  70.  * buffer.  Do any last minute patches here, like fix the size.
  71.  */
  72. int
  73. _eth_send( word len)
  74. {
  75.  
  76.     gm_eth_send++;
  77.     if (( _pktdevclass == PD_ETHER ) && ((len += 14) < ETH_MIN ))
  78.     len = ETH_MIN;
  79.  
  80.     return( pkt_send((char *)&outbuf, len ));   /* send to packet driver */
  81. }
  82.  
  83. /*
  84.  * _eth_free - free an input buffer once it is no longer needed
  85.  * If pointer to NULL, release all buffers
  86.  */
  87. void
  88. _eth_free( void *buf)
  89. {
  90.     if ( buf )
  91.     pkt_buf_release( buf );
  92.     else
  93.     pkt_buf_wipe();
  94. }
  95.  
  96. /*
  97.  * _eth_arrived - if a new packet has arrived, read it and fill pointer
  98.  * with type of packet
  99.  */
  100.  
  101. byte *
  102. _eth_arrived( word *type_ptr)
  103. {
  104.     struct ether * temp;
  105.  
  106.     if (temp = pkt_received()) {
  107.     switch ( _pktdevclass ) {
  108.         case PD_ETHER : *type_ptr = temp->type;
  109.                 return( temp->data );
  110.         case PD_SLIP  : *type_ptr = 0x008; /* IP_TYPE, intel format */
  111.                 return((byte *) temp );
  112.     }
  113.     }
  114.     return( NULL );
  115. }
  116.  
  117. /*
  118.  * _eth_release - release the hardware
  119.  */
  120. void
  121. _eth_release(void)
  122. {
  123.     pkt_release();
  124. }
  125.  
  126. /*
  127.  * _eth_hardware - return pointer to hardware address of a packet
  128.  */
  129. void *
  130. _eth_hardware( byte *p )
  131. {
  132.     return( p - 8 );
  133. }
  134.