Main Page | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

SRC/pcsed.c File Reference


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.

Go to the source code of this file.

Functions

void * _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.
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.
int _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.
void * eth_mac_format (void *mac_buf, const void *mac_dest, WORD type)
 Format the MAC-header for Ethernet.
void * tok_mac_format (void *mac_buf, const void *mac_dest, WORD type)
 Format the MAC-header for Token-Ring.
void * fddi_mac_format (void *mac_buf, const void *mac_dest, WORD type)
 Format the MAC-header for FDDI.
void * arcnet_mac_format (void *mac_buf, const void *mac_dest, WORD type)
 Format the MAC-header for ARCNET.
void * null_mac_format (void *mac_buf, const void *mac_dest, WORD type)
 Format MAC-header for protocols without MAC-headers.
int eth_mac_xmit (const void *buf, WORD len)
 Functions called via function pointer `mac_transmit' to actually send the data.
int fddi_mac_xmit (const void *buf, WORD len)
int arcnet_mac_xmit (const void *buf, WORD len)
int tok_mac_xmit (const void *buf, WORD len)
int null_mac_xmit (const void *buf, WORD len)
int _eth_init (void)
 Initialize the network driver interface.
int _eth_set_addr (const void *addr)
 Sets a new MAC address for our interface.
BYTE _eth_get_hwtype (BYTE *hwtype, BYTE *hwlen)
 Fill in hardware address type/length for BOOTP/DHCP packets.
void _eth_free (const void *pkt)
 Free an input buffer once it is no longer needed.
void fix_tok_head (tok_Header **trp)
BOOL fix_arc_head (const arcnet_Header *head, WORD *type)
link_Packetpoll_recv_queue (WORD *type)
 Poll the packet queue.
void fix_llc_head (void **mac)
void * _eth_arrived (WORD *type_ptr, BOOL *broadcast)
 Poll for arrival of new packets (IP/ARP/RARP/PPPoE protocol).
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).
BOOL _eth_leave_mcast_group (const struct MultiCast *mc)
 Leaves a multicast group (at the physical layer).
void _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
const char * _eth_not_init = "Packet driver not initialised"
_eth_last_info _eth_last
 Sizes and timestamps of last packet recv/sent.
void *(* _eth_recv_hook )(WORD *type)=NULL
 Pointer to functions that when set changes the behaviour of polling and send functions _eth_arrived() and _eth_send().
int(* _eth_recv_peek )(void *mac_buf)=NULL
int(* _eth_xmit_hook )(const void *mac_buf, unsigned len)=NULL
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.
int(* mac_transmit )(const void *mac_buf, WORD len)
WORD proto
void * nw_pkt
link_Packet outbuf


Function Documentation

void* _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:
Pointer past 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:
Pointer to 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 1016 of file pcsed.c.

References _eth_brdcast, _eth_free(), _eth_is_init, _eth_recv_hook, _ip_recursion, _pktdevclass, _pktserial, BYTE, fix_llc_head(), macstat::num_ip_recurse, poll_recv_queue(), update_in_stat(), and WORD.

void* _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 131 of file pcsed.c.

References WORD.

BYTE _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 740 of file pcsed.c.

References _pktdevclass, arcnet_address, ax25_address, BYTE, eth_address, fddi_address, and tok_address.

int _eth_init void   ) 
 

Initialize the network driver interface.

Returns:
0 okay.

error-code otherwise.

Definition at line 648 of file pcsed.c.

References _eth_addr, _eth_brdcast, _eth_get_hwtype(), _eth_is_init, _eth_loop_addr, _eth_mac_len, _eth_ndis3pkt, _eth_real_addr, _eth_release(), _eth_SwsVpkt, _pktdevclass, arcnet_mac_format(), eth_address, eth_mac_format(), eth_mac_xmit(), fddi_mac_format(), mac_tx_format, null_mac_format(), pkt_buf_wipe(), pkt_eth_init(), and tok_mac_format().

BOOL _eth_join_mcast_group const struct MultiCast mc  ) 
 

Joins a multicast group (at the physical layer).

Return values:
1 The group was joined successfully.
0 Attempt failed.
Definition at line 1238 of file pcsed.c.

References _pkt_errno, _pkt_rxmode, eth_address, 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:
1 The group was left successfully.
0 Attempt failed.
Definition at line 1314 of file pcsed.c.

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

int _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 302 of file pcsed.c.

References _eth_is_init, _eth_last, _pkt_ip_ofs, _pktdevclass, in_Header::destination, in6_Header::destination, has_rdtsc, send_loopback(), update_out_stat(), and WORD.

void fix_llc_head void **  mac  )  [static]
 

Todo:
handle IEEE 802.3 encapsulation also.
Definition at line 990 of file pcsed.c.

References _eth_free().

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 573 of file pcsed.c.

References WORD.

union link_Packet* poll_recv_queue WORD type  )  [static]
 

Poll the packet queue.

Return first packet in queue. Optionally do receiver profiling.

Return values:
pointer to start of MAC-header.
NULL no 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 884 of file pcsed.c.

References _eth_last, _pkt_inf, _pktdevclass, _pktserial, arcnet_Packet::data, fddi_Packet::head, arcnet_Packet::head, pkt_free_pkt(), pkt_info::pkt_queue, fddi_Header::type, tok_Header::type, uint64, and WORD.

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 150 of file pcsed.c.

References _eth_addr, _eth_loop_addr, _pkt_inf, _pkt_ip_ofs, _pktserial, BYTE, pkt_ringbuf::num_buf, and pkt_info::pkt_queue.


Variable Documentation

void*(* _eth_recv_hook)(WORD *type)=NULL
 

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. Definition at line 88 of file pcsed.c.

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 96 of file pcsed.c.


Generated on Wed Aug 4 08:55:57 2010 for Watt-32 tcp/ip by doxygen 1.3.8