home *** CD-ROM | disk | FTP | other *** search
/ ftp.wwiv.com / ftp.wwiv.com.zip / ftp.wwiv.com / pub / PPPBCKP / SRC15B44.ZIP / WATTSRC.ZIP / SRC / PCSED.C < prev    next >
Text File  |  1994-11-28  |  3KB  |  122 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(void)
  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. byte *_eth_formatpacket( eth_address *eth_dest, word eth_type )    // 94.11.19
  48. {
  49.     memset( &outbuf, 0, sizeof(struct ether));
  50.     switch ( _pktdevclass ) {
  51.     case PD_SLIP :
  52.                 return( (byte *) &outbuf );      /* no header */
  53.     case PD_ETHER :
  54.    default:             /* should never catch default case */
  55.         movmem( eth_dest, outbuf.dest, 6 );
  56.                 movmem( &_eth_addr, outbuf.src, 6 );
  57.         outbuf.type = eth_type;
  58.                 return( (byte *)&outbuf.data );
  59.     }
  60. }
  61.  
  62. /*
  63.  * _eth_send does the actual transmission once we are complete with the
  64.  * buffer.  Do any last minute patches here, like fix the size.
  65.  */
  66. int _eth_send( word len )
  67. {
  68.  
  69.     if (( _pktdevclass == PD_ETHER ) && ((len += 14) < ETH_MIN ))
  70.     len = ETH_MIN;
  71.  
  72.     return( pkt_send( (char *)&outbuf, len ));   /* send to packet driver */
  73. }
  74.  
  75. /*
  76.  * _eth_free - free an input buffer once it is no longer needed
  77.  * If pointer to NULL, release all buffers
  78.  */
  79. void _eth_free( void *buf )
  80. {
  81.     if ( buf )
  82.     pkt_buf_release( buf );
  83.     else
  84.     pkt_buf_wipe();
  85. }
  86.  
  87. /*
  88.  * _eth_arrived - if a new packet has arrived, read it and fill pointer
  89.  * with type of packet
  90.  */
  91.  
  92. byte *_eth_arrived( word *type_ptr )
  93. {
  94.     struct ether * temp;
  95.  
  96.     if ((temp = (struct ether * ) pkt_received()) != NULL ) {
  97.     switch ( _pktdevclass ) {
  98.         case PD_ETHER : *type_ptr = temp->type;
  99.                 return( temp->data );
  100.         case PD_SLIP  : *type_ptr = 0x008;
  101.                 return( (byte *) temp );
  102.     }
  103.     }
  104.     return( NULL );
  105. }
  106.  
  107. /*
  108.  * _eth_release - release the hardware
  109.  */
  110. void _eth_release( void )
  111. {
  112.     pkt_release();
  113. }
  114.  
  115. /*
  116.  * _eth_hardware - return pointer to hardware address of a packet
  117.  */
  118. void *_eth_hardware( byte *p )
  119. {
  120.     return( p - 8 );
  121. }
  122.