home *** CD-ROM | disk | FTP | other *** search
/ Super Net 1 / SUPERNET_1.iso / PC / OTROS / MSDOS / WATTCP / UNZIPPED / WNWATTCP / SRC / PCSED.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-02-10  |  3.0 KB  |  126 lines

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