home *** CD-ROM | disk | FTP | other *** search
/ Super Net 1 / SUPERNET_1.iso / PC / OTROS / MSDOS / WATTCP / NEWWATCP.ZIP / SRC / PCSED.C < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-15  |  3.0 KB  |  121 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 <mem.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.     movmem( _pkt_eth_init() , _eth_addr, 6 );
  34.     memset( &_eth_brdcast, 0xff, sizeof( _eth_brdcast ));
  35. }
  36.  
  37. /*
  38.  * _eth_FormatPacket places the next packet into the buffer and uses the
  39.  * type field for protocol determination.  Note, I only maintain a single
  40.  * output buffer, and it gets used quickly then released.  The benefits of
  41.  * non-blocking systems are immense.
  42.  */
  43.  
  44. static struct ether outbuf;
  45.  
  46. byte *_eth_formatpacket( void *eth_dest, word eth_type )
  47. {
  48.     memset( &outbuf, 0, sizeof(struct ether));
  49.     switch ( _pktdevclass ) {
  50.     case PD_ETHER :
  51.         movmem( eth_dest, outbuf.dest, 6 );
  52.                 movmem( _eth_addr, outbuf.src, 6 );
  53.         outbuf.type = eth_type;
  54.                 return( (byte *)&outbuf.data );
  55.     case PD_SLIP :
  56.                 return( (byte *) &outbuf );      /* no header */
  57.     }
  58. }
  59.  
  60. /*
  61.  * _eth_send does the actual transmission once we are complete with the
  62.  * buffer.  Do any last minute patches here, like fix the size.
  63.  */
  64. int _eth_send( word len)
  65. {
  66.  
  67.     if (( _pktdevclass == PD_ETHER ) && ((len += 14) < ETH_MIN ))
  68.     len = ETH_MIN;
  69.  
  70.     return( pkt_send( &outbuf, len ));   /* send to packet driver */
  71. }
  72.  
  73. /*
  74.  * _eth_free - free an input buffer once it is no longer needed
  75.  * If pointer to NULL, release all buffers
  76.  */
  77. void _eth_free( void *buf)
  78. {
  79.     if ( buf )
  80.     pkt_buf_release( buf );
  81.     else
  82.     pkt_buf_wipe();
  83. }
  84.  
  85. /*
  86.  * _eth_arrived - if a new packet has arrived, read it and fill pointer
  87.  * with type of packet
  88.  */
  89.  
  90. byte *_eth_arrived( word *type_ptr)
  91. {
  92.     struct ether * temp;
  93.  
  94.     if ((temp = (struct ether * ) pkt_received()) != NULL ) {
  95.     switch ( _pktdevclass ) {
  96.         case PD_ETHER : *type_ptr = temp->type;
  97.                 return( temp->data );
  98.         case PD_SLIP  : *type_ptr = 0x008;
  99.                 return( (byte *) temp );
  100.     }
  101.     }
  102.     return( NULL );
  103. }
  104.  
  105. /*
  106.  * _eth_release - release the hardware
  107.  */
  108. void _eth_release()
  109. {
  110.     pkt_release();
  111. }
  112.  
  113. /*
  114.  * _eth_hardware - return pointer to hardware address of a packet
  115.  */
  116. void *_eth_hardware( byte *p )
  117. {
  118.     return( p - 8 );
  119. }
  120.  
  121.