Watt-32 tcp/ip  2.2 dev-rel.10
Functions | Variables
pcsed.c File Reference

Go to the source code of this file.

Functions

void *W32_CALL * _eth_recv_hook (WORD *type)
 Pointer to functions that when set changes the behaviour of polling and send functions _eth_arrived() and _eth_send(). More...
 
 int (W32_CALL *_eth_recv_peek)(void *mac_buf)
 
static void __eth_release (void)
 Turn off stack-checking because _eth_release() might be called from an exception handler.
 
void *W32_CALL _eth_formatpacket (const void *mac_dest, WORD eth_type)
 _eth_format_packet() places the next packet to be transmitted into the above link-layer output packet. More...
 
static int send_loopback (link_Packet pkt, BOOL is_ip6, unsigned *err_line)
 Enqueue a link-layer frame (IPv4/v6 only) to the internal loopback device. More...
 
int W32_CALL _eth_send (WORD len, const void *sock, const char *file, unsigned line)
 _eth_send() does the actual transmission once we are complete with filling the buffer. More...
 
static voideth_mac_format (void *mac_buf, const void *mac_dest, WORD type)
 Format the MAC-header for Ethernet.
 
static voidtok_mac_format (void *mac_buf, const void *mac_dest, WORD type)
 Format the MAC-header for Token-Ring.
 
static voidfddi_mac_format (void *mac_buf, const void *mac_dest, WORD type)
 Format the MAC-header for FDDI.
 
static voidarcnet_mac_format (void *mac_buf, const void *mac_dest, WORD type)
 Format the MAC-header for ARCNET.
 
static voidnull_mac_format (void *mac_buf, const void *mac_dest, WORD type)
 Format MAC-header for protocols without MAC-headers. More...
 
static int eth_mac_xmit (const void *buf, WORD len)
 Functions called via function pointer `mac_transmit' to actually send the data.
 
static int fddi_mac_xmit (const void *buf, WORD len)
 
static int arcnet_mac_xmit (const void *buf, WORD len)
 
static int tok_mac_xmit (const void *buf, WORD len)
 
static int null_mac_xmit (const void *buf, WORD len)
 
int W32_CALL _eth_init (void)
 Initialize the network driver interface. More...
 
int W32_CALL _eth_set_addr (const void *addr)
 Sets a new MAC address for our interface.
 
BYTE W32_CALL _eth_get_hwtype (BYTE *hwtype, BYTE *hwlen)
 Fill in hardware address type/length for BOOTP/DHCP packets. More...
 
void W32_CALL _eth_free (const void *pkt)
 Free an input buffer once it is no longer needed.
 
static void fix_tok_head (tok_Header **trp)
 
static BOOL fix_arc_head (const arcnet_Header *head, WORD *type)
 
static union link_Packetpoll_recv_queue (WORD *type)
 Poll the packet queue. More...
 
static void fix_llc_head (void **mac)
 
void *W32_CALL _eth_arrived (WORD *type_ptr, BOOL *broadcast)
 Poll for arrival of new packets (IP/ARP/RARP/PPPoE protocol). More...
 
void_eth_mac_hdr (const in_Header *ip)
 Return pointer to MAC header start address of an IP packet.
 
void_eth_mac_dst (const in_Header *ip)
 Return pointer to MAC destination address of an IP packet.
 
void_eth_mac_src (const in_Header *ip)
 Return pointer to MAC source address of an IP packet.
 
WORD _eth_mac_typ (const in_Header *ip)
 Return value of protocol-type given an IP packet.
 
BOOL _eth_join_mcast_group (const struct MultiCast *mc)
 Joins a multicast group (at the physical layer). More...
 
BOOL _eth_leave_mcast_group (const struct MultiCast *mc)
 Leaves a multicast group (at the physical layer) More...
 
void W32_CALL _eth_release (void)
 Release the hardware driver.
 

Variables

mac_address _eth_addr
 Local link-layer source address.
 
mac_address _eth_brdcast
 Link-layer broadcast address.
 
mac_address _eth_loop_addr
 Link-layer loopback address.
 
mac_address _eth_real_addr
 Our real MAC address.
 
BYTE _eth_mac_len
 Size of a MAC address.
 
BOOL _eth_is_init = FALSE
 we are initialised
 
BOOL _ip_recursion = FALSE
 avoid recursion in arp_resolve()
 
BOOL _eth_ndis3pkt = FALSE
 for DOS-programs only
 
BOOL _eth_SwsVpkt = FALSE
 for DOS and Win32 programs
 
BOOL _eth_airpcap = FALSE
 for Win32 using the AirPcap adapter
 
BOOL _eth_wanpacket = FALSE
 for Win32 using an WanPacket adapter
 
BOOL _eth_winpcap = FALSE
 for Win32 using an WinPcap adapter (default)
 
const char * _eth_not_init = "Packet driver not initialised"
 
struct _eth_last_info _eth_last
 Sizes and timestamps of last packet recv/sent.
 
unsigned len = NULL
 
static void *(* mac_tx_format )(void *mac_buf, const void *mac_dest, WORD type)
 Pointer to functions that does the filling of correct MAC-header and sends the link-layer packet. More...
 
static int(* mac_transmit )(const void *mac_buf, WORD len)
 
static WORD proto
 
static voidnw_pkt
 
static union link_Packet outbuf
 

Detailed Description

Link-layer Driver Routines.

The TCP code uses Ethernet constants for protocol numbers and 48 bits for address. Also, 0xFF:FF:FF:FF:FF:FF is assumed to be a broadcast. Except for ARCNET where broadcast is 0x00.

If you need to write a new driver, implement it at this level and use the above mentioned constants as this program's constants, not device dependent constants.

The packet driver or WinPcap interface code lies below this module.

Definition in file pcsed.c.

Function Documentation

void* W32_CALL _eth_arrived ( WORD *  type_ptr,
BOOL *  broadcast 
)

Poll for arrival of new packets (IP/ARP/RARP/PPPoE protocol).

Sets protocol-type of packet received in 'type'.

For Ethernet/TokenRing-type drivers:

Return values
Pointerpast the MAC-header to the IP/ARP/RARP protocol header. Also check for link-layer broadcast.

For PPP/SLIP-type drivers (no MAC-headers):

Return values
Pointerto the IP-packet itself. IP-protocol is assumed. Can never be link-layer broadcast.

<

Todo:
push back packet, else it's lost

Definition at line 1026 of file pcsed.c.

References _eth_brdcast, _eth_free(), _eth_is_init, _eth_recv_hook(), _ip_recursion, _pktdevclass, _pktserial, fix_llc_head(), poll_recv_queue(), and update_in_stat().

void* W32_CALL _eth_formatpacket ( const void mac_dest,
WORD  eth_type 
)

_eth_format_packet() places the next packet to be transmitted into the above link-layer output packet.

Returns
address of higher-level protocol (IP/RARP/RARP) header.

Definition at line 135 of file pcsed.c.

BYTE W32_CALL _eth_get_hwtype ( BYTE *  hwtype,
BYTE *  hwlen 
)

Fill in hardware address type/length for BOOTP/DHCP packets.

Also used for ARP/RARP packets. Should never be called for PPP/SLIP.

Definition at line 751 of file pcsed.c.

References _pktdevclass.

int W32_CALL _eth_init ( void  )
BOOL _eth_join_mcast_group ( const struct MultiCast mc)

Joins a multicast group (at the physical layer).

Return values
1The group was joined successfully.
0Attempt failed.

Definition at line 1248 of file pcsed.c.

References _pkt_errno, _pkt_rxmode, MultiCast::ethaddr, pkt_get_multicast_list(), pkt_set_multicast_list(), pkt_set_rcv_mode(), RXMODE_MULTICAST1, RXMODE_MULTICAST2, and RXMODE_PROMISCOUS.

BOOL _eth_leave_mcast_group ( const struct MultiCast mc)

Leaves a multicast group (at the physical layer)

Return values
1The group was left successfully.
0Attempt failed.

Definition at line 1324 of file pcsed.c.

References _pkt_errno, _pkt_rxmode, MultiCast::ethaddr, pkt_get_multicast_list(), pkt_set_multicast_list(), pkt_set_rcv_mode(), and RXMODE_MULTICAST2.

void* W32_CALL* _eth_recv_hook ( WORD *  type)

Pointer to functions that when set changes the behaviour of polling and send functions _eth_arrived() and _eth_send().

_eth_recv_hook: If set, must point to a function that supplies frames ready to be received. Return NULL if no frame is ready. Otherwise points to a raw MAC frame. If not a serial-driver, must also set '*type'.

_eth_recv_peek: If set, must point to a function that gets a chance to peek at the raw received frame. It can modify it or even consume it by returning zero. To prevent recursion, this function cannot call tcp_tick(). It should return as fast as possible in order not to block reception of other frames waiting in the receive buffer.

_eth_xmit_hook: If set, must point to a function that should transmit all frames generated by Watt-32. Must return length of frame sent or <= 0 if it failed.

int W32_CALL _eth_send ( WORD  len,
const void sock,
const char *  file,
unsigned  line 
)

_eth_send() does the actual transmission once we are complete with filling the buffer.

Do any last minute patches here, like fix the size. Send to "loopback" device if it's IP and destination matches loopback network (127.x.x.x.).

Return length of network-layer packet (not length of link-layer packet).

Definition at line 306 of file pcsed.c.

References _eth_is_init, _eth_last, _pkt_ip_ofs, _pktdevclass, has_rdtsc, send_loopback(), and update_out_stat().

static void fix_llc_head ( void **  mac)
static
Todo:
handle IEEE 802.3 encapsulation also.

Definition at line 1000 of file pcsed.c.

References _eth_free().

static void* null_mac_format ( void mac_buf,
const void mac_dest,
WORD  type 
)
static

Format MAC-header for protocols without MAC-headers.

Nothing done here.

Definition at line 584 of file pcsed.c.

static union link_Packet* poll_recv_queue ( WORD *  type)
static

Poll the packet queue.

Return first packet in queue. Optionally do receiver profiling.

Return values
pointerto start of MAC-header.
NULLno packets are queued.
Note
Not used when e.g. libpcap has set the `_eth_recv_hook' to do it's own packet-polling.
'type' is always set.

Definition at line 895 of file pcsed.c.

References _eth_last, _pkt_inf, _pktdevclass, _pktserial, and pkt_free_pkt().

static int send_loopback ( link_Packet  pkt,
BOOL  is_ip6,
unsigned *  err_line 
)
static

Enqueue a link-layer frame (IPv4/v6 only) to the internal loopback device.

Note
This function uses call-by-value. Thus `pkt' buffer can be modified by loopback_device() and loopback handler may send using _eth_send().
Loopback device cannot send to itself (potential recursion).

Definition at line 154 of file pcsed.c.

References _eth_addr, _eth_loop_addr, _pkt_inf, _pkt_ip_ofs, and _pktserial.

Variable Documentation

void*(* mac_tx_format)(void *mac_buf, const void *mac_dest, WORD type)
static

Pointer to functions that does the filling of correct MAC-header and sends the link-layer packet.

We store 'proto' between calls.

Definition at line 99 of file pcsed.c.