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

SRC/pcpkt.c File Reference


Detailed Description

Packet Driver interface for WatTCP/Watt-32.

Heavily modified and extended for DOSX by G.Vanem <giva@bgnett.no>

Definition in file pcpkt.c.

Go to the source code of this file.

Functions

void get_init_stats (void)
 void (__cdecl _far *pkt_enque_ptr)(BYTE _far *buf
int setup_rmode_callback (void)
int lock_code_and_data (void)
int unlock_code_and_data (void)
int find_vector (int first, int num)
int setup_pkt_inf (void)
void get_rmode_data (void *dest, unsigned size, WORD seg, WORD ofs)
 Return PKTDRVR data at seg:ofs, Copy to 'dest'.
BOOL pkt_api_entry (IREGS *reg, unsigned called_from_line)
 The API entry to the network link-driver.
const char * pkt_strerror (int code)
 Return textual error representing error-code.
void dump_asm4 (void)
void * pkt_tx_buf (void)
 Return address of DOS memory Tx-buffer.
int pkt_set_access (void)
 Setup the receiver upcall handler.
int pkt_drvr_info (void)
 Fetch the PKTDRVR information.
int pkt_get_params (struct PktParameters *params)
 Get PKTDRVR parameters (MTU, version etc.).
int pkt_get_mtu (void)
 Return PKTDRVR maximum-transmit-units (MTU).
int pkt_get_mac_len (void)
 Return length of MAC address.
int pkt_get_api_ver (DWORD *ver)
 Return version of spec.
int pkt_get_drvr_ver (WORD *major, WORD *minor)
 Return version of PKTDRVR.
int pkt_get_vector (void)
 Return PKTDRVR vector.
int pkt16_drvr_init (mac_address *mac_addr)
 Called from pkt_eth_init() to search for PKTDRVR.
int pkt_release_handle (WORD handle)
 Release the allocated protocol handle.
int pkt_reset_handle (WORD handle)
 Reset the driver-state associated with handle.
void release_callback (void)
void release_real_mem (void)
 Release allocated DOS memory.
int DTOR pkt_release (void)
void pkt_enqueue (unsigned rxBuf, WORD rxLen) static void __cdecl _far pkt_enqueue(BYTE _far *rxBuf
 Enqueue a received packet into '_pkt_inf->pkt_queue'.
int pkt_send (const void *tx, int length)
 Send a link-layer frame.
int pkt_get_addr (mac_address *mac)
 Return the MAC address.
int pkt_set_addr (const void *addr)
 Set a new MAC source address.
int pkt_get_stats (struct PktStats *stats, struct PktStats *total)
 Get PKTDRVR statistics.
int pkt_get_vjstats (struct slcompress *vjstats)
int pkt_get_cstate (struct cstate *cs, WORD cstate_ofs)
int pkt_buf_wipe (void)
 Clear the receive queue.
void pkt_free_pkt (const void *pkt)
 Release a packet from the receive queue.
int pkt_waiting (void)
 Return number of packets waiting in queue.
DWORD pkt_dropped (void)
 Return number of packets dropped.
int parse_config_pass_1 (void)
 Search WATTCP.CFG file for "PKT.VECTOR = 0x??" etc.
int pkt_eth_init (mac_address *addr)
 Initialise Packet driver interface.
BOOL check_intr_num (WORD intr_num)
 Check a single interrupt vector for signature string "PKT DRVR".
void _unlock (const void *addr, DWORD size)
int pkt_set_rcv_mode (int mode)
 Sets the receive mode of the interface.
int pkt_get_rcv_mode (void)
 Gets the receive mode of the interface (can never be mode 0).
int pkt_get_multicast_list (mac_address *listbuf, int *lenp)
 Gets the current list of multicast addresses from the PKTDRVR.
int pkt_set_multicast_list (const void *listbuf, int len)
 Sets the list of multicast addresses for which the PKTDRVR is responsible.

Variables

WORD _pktdevclass = PDCLASS_UNKNOWN
 Ethernet, Token, FDDI etc.
WORD _pkt_ip_ofs = 0
 ofs from link-layer head to ip
WORD _pkt_type_ofs = 0
 ofs from link-layer head to type
BOOL _pktserial = FALSE
 using serial driver, SLIP/PPP
BYTE _pktdevlevel = 1
 Device level.
int _pkt_rxmode = RXMODE_BROADCAST
 active receive mode
int _pkt_rxmode0 = -1
 startup receive mode
int _pkt_errno = 0
 error code set in pcpkt.c API
const char * pkt_error = NULL
 Last pkt error string.
int _pkt_forced_rxmode = -1
char _pktdrvrname [20] = "unknown"
pkt_info_pkt_inf = NULL
 module data that will be locked
char pkt_sign [] = "PKT DRVR"
WORD pkt_interrupt = 0
DWORD pkt_drop_cnt = 0
BYTE pkt_txretries = 2
int pkt_txwait = 0
BOOL pkt_use_near = FALSE
BOOL pkt_do_reset = FALSE
int pkt_drvr_ver = 0
int pkt_num_rx_bufs = RX_BUFS
PktStats init_stats
PktParameters pkt_params
BOOL got_params = FALSE
REALPTR rm_base
_go32_dpmi_seginfo rm_cb
WORD pkt_inf_sel
WORD len
WORD cstate_dseg = 0
 Get VJ-compression statistics from pkt-driver.


Function Documentation

int parse_config_pass_1 void   )  [static]
 

Search WATTCP.CFG file for "PKT.VECTOR = 0x??" etc.

Accept "0x20 - 0xFF". Definition at line 1380 of file pcpkt.c.

References ARG_ATOB, ARG_ATOI, and ARG_ATOX_B.

int pkt16_drvr_init mac_address *  mac_addr  )  [static]
 

Called from pkt_eth_init() to search for PKTDRVR.

  • Checks register struct size (for non-DOSX targets).
  • Searches for the PKTDRVR interrupt.
  • Allocates '_pkt_inf' structure.
  • Sets up a real-mode callback and lock code/data (DOSX targets).
  • Fetches PKTDRVR information.
  • Sets up driver to call our real-mode callback.
  • Fetches local MAC address.
  • Fetches parameters and initialise statistics.
Definition at line 548 of file pcpkt.c.

References _pkt_errno, _pkt_rxmode, _pkt_rxmode0, _pktdevlevel, _pktserial, pkt_drvr_info(), pkt_get_addr(), pkt_get_params(), pkt_get_rcv_mode(), pkt_release(), pkt_set_access(), pkt_set_rcv_mode(), pkt_strerror(), RXMODE_PROMISCOUS, and setup_pkt_inf().

BOOL pkt_api_entry IREGS *  reg,
unsigned  line
[static]
 

The API entry to the network link-driver.

Use either protected mode interface via a call to dynamically loaded module (not yet) or issue an interrupt for the real-mode PKTDRVR.

Return TRUE if CARRY is clear, else set _pkt_errno and return FALSE.

Todo:
Use 32-bit API; accessing card via pmode driver
Definition at line 1866 of file pcpkt.c.

References _pkt_errno.

int pkt_drvr_info void   )  [static]
 

Fetch the PKTDRVR information.

Device level, class and name. Definition at line 370 of file pcpkt.c.

References _pkt_errno, _pkt_inf, _pkt_ip_ofs, _pkt_type_ofs, _pktdevclass, _pktdevlevel, _pktserial, get_rmode_data(), pkt_info::is_serial, pkt_info::pkt_ip_ofs, and pkt_info::pkt_type_ofs.

void pkt_enqueue unsigned  rxBuf,
WORD  rxLen
[static]
 

Enqueue a received packet into '_pkt_inf->pkt_queue'.

This routine is called from pkt_receiver_rm/_pm(). The packet has been copied to rx_buffer (in DOS memory) by the packet-driver. We now must copy it to correct queue. Interrupts are disabled on entry.

Note 1: For real-mode targets SS and SP have been setup to a small work stack in asmpkt.asm (SS = CS). The stack can only take 64 pushes, hence use few local variables here.

Note 2: The C-compiler must be told NOT to use register calling for this routine (MUST use __cdecl) because it's called from asmpkt.asm via `pkt_enque_ptr' function pointer.

Note 3: Watcom/DOS4GW targets doesn't use real->prot mode upcall (RMCB), but does the following in asmpkt4.asm instead.

Note 4: For DOSX targets, all code from pkt_enqueue() down to _pkt_end() must be locked in memory.

HACK: For real-mode targets this routine is called via the `pkt_enque_ptr' function pointer. This was the only way I could avoid a fixup error for small-model programs.

int pkt_eth_init mac_address *  addr  ) 
 

Initialise Packet driver interface.

First determine vector to use; if WATTCP.CFG specifies a "PKT.VECTOR = 0xNN", use that vector, else search for PKTDRVR between PKT_FIRST_VEC and PKT_LAST_VEC (0x60 - 0x80). If the driver is outside this range, user must specify one with "PKT.VECTOR = 0x??".

If DOSX, probe and initialise protected-mode driver (not operational). Call pkt16_drvr_init() to initialise API. Definition at line 1419 of file pcpkt.c.

void pkt_free_pkt const void *  pkt  ) 
 

Release a packet from the receive queue.

If USE_FAST_PKT, pkt has already been free'd. Just update drop count. Definition at line 1319 of file pcpkt.c.

int pkt_get_api_ver DWORD ver  ) 
 

Return version of spec.

this PKTDRVR conforms to.

Return values:
-1 on error. Return major version in upper 8 bit, minor in lower.
Definition at line 507 of file pcpkt.c.

int pkt_get_mac_len void   ) 
 

Return length of MAC address.

Return values:
6 For Ethernet.
Definition at line 492 of file pcpkt.c.

References _pktdevclass, and arcnet_address.

int pkt_get_mtu void   ) 
 

Return PKTDRVR maximum-transmit-units (MTU).

Note:
This includes length of MAC-header.
Definition at line 477 of file pcpkt.c.

int pkt_get_multicast_list mac_address *  listbuf,
int *  lenp
 

Gets the current list of multicast addresses from the PKTDRVR.

  • listbuf is the buffer into which the list is placed
  • len on input: length of listbuf on output: length of list returned
Return values:
0 upon error - _pkt_errno is set
1 if retrieval was successful,
Definition at line 2006 of file pcpkt.c.

int pkt_get_rcv_mode void   ) 
 

Gets the receive mode of the interface (can never be mode 0).

Return values:
!0 Okay - _pkt_errno is 0, _pkt_rxmode and retval is current mode.
0 Error - _pkt_errno is set.
_pkt_rxmode is one of the following modes: (upon successful return)
  • 1 - turn off receiver
  • 2 - receive only packets sent to this interface
  • 3 - mode 2 plus broadcast packets (default)
  • 4 - mode 3 plus limited multicast packets
  • 5 - mode 3 plus all multicast packets
  • 6 - all packets (a.k.a promiscuous mode)
Definition at line 1968 of file pcpkt.c.

int pkt_get_stats struct PktStats *  stats,
struct PktStats *  total
 

Get PKTDRVR statistics.

Return both 'stats' for current session and 'total' statistics since driver loaded. Definition at line 1213 of file pcpkt.c.

int DTOR pkt_release void   ) 
 

Todo:
We might be called between 1st and 2nd packet-driver upcall. Need to wait for 2nd upcall to finish or else freeing the RMCB too early could cause a crash or a stuck PKTDRVR.
Definition at line 808 of file pcpkt.c.

int pkt_send const void *  tx,
int  length
 

Send a link-layer frame.

For PPP/SLIP 'tx' contains no MAC-header. For EtherNet, Token-Ring, ARCNET and FDDI, 'tx' contains the complete frame.

Todo:
Change this so that we doesn't retry if the driver was stuck for "too long". I've seen drivers using approx. 100 msec on each iteration below. Retrying if the driver is stuck is not worth the time.
Definition at line 1060 of file pcpkt.c.

int pkt_set_access void   )  [static]
 

Setup the receiver upcall handler.

The handler is called for all packets matching current receive mode. In mode 3 all broadcast and directed packets. Definition at line 320 of file pcpkt.c.

References _pkt_errno, _pkt_inf, _pktdevclass, pkt_info::handle, pkt_info::rm_seg, and WORD.

int pkt_set_multicast_list const void *  listbuf,
int  len
 

Sets the list of multicast addresses for which the PKTDRVR is responsible.

  • listbuf is the buffer containing the list
  • len is the length of listbuf
Return values:
0 upon error - _pkt_errno is set
1 if set was successful
Definition at line 2053 of file pcpkt.c.

int pkt_set_rcv_mode int  mode  ) 
 

Sets the receive mode of the interface.

mode is one of the following modes:

  • 1 - turn off receiver
  • 2 - receive only packets sent to this interface
  • 3 - mode 2 plus broadcast packets <default>
  • 4 - mode 3 plus limited multicast packets
  • 5 - mode 3 plus all multicast packets
  • 6 - all packets (AKA promiscuous mode)

Return values:
0 - upon error - _pkt_errno is set
1 - if the mode was set successfully
Definition at line 1924 of file pcpkt.c.

void * pkt_tx_buf void   ) 
 

Return address of DOS memory Tx-buffer.

For DOS4GW/X32VM (and djgpp with near-ptrs) targets, return near address of transmit buffer located in DOS memory. Definition at line 290 of file pcpkt.c.

int setup_pkt_inf void   )  [static]
 

Todo:
Make dynamic allocation based on 'pkt_num_rx_bufs'. Allocate multiple 64kB blocks if needed (would involve messy 16-bit coding in asmpkt.nas).
Definition at line 1773 of file pcpkt.c.

References _pkt_inf, pkt_info::dos_ds, pkt_ringbuf::dos_ofs, DWORD, pkt_info::pkt_queue, pkt_info::rx_buf, and pkt_info::use_near_ptr.


Variable Documentation

WORD cstate_dseg = 0 [static]
 

Get VJ-compression statistics from pkt-driver.

Only DOS-PPP ver 0.6+ supports the PD_GET_VJSTATS (0x81) call. Definition at line 1267 of file pcpkt.c.


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