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