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

Go to the source code of this file.


static void get_init_stats (void)
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 (__cdecl _far *pkt_enque_ptr)(BYTE _far *buf
static int setup_rmode_callback (void)
static int lock_code_and_data (void)
static int unlock_code_and_data (void)
static int find_vector (int first, int num)
static int setup_pkt_inf (void)
static void get_rmode_data (void *dest, unsigned size, WORD seg, WORD ofs)
 Return PKTDRVR data at seg:ofs, Copy to 'dest'.
static BOOL pkt_api_entry (IREGS *reg, unsigned line)
 The API entry to the network link-driver. More...
const char *W32_CALL pkt_strerror (int code)
 Return textual error representing error-code.
BOOL W32_CALL pkt_is_init (void)
static void dump_asm4 (void)
voidpkt_tx_buf (void)
 Return address of DOS memory Tx-buffer. More...
static int pkt_set_access (void)
 Setup the receiver upcall handler. More...
static int pkt_drvr_info (void)
 Fetch the PKTDRVR information. More...
int pkt_get_params (struct PktParameters *params)
 Get PKTDRVR parameters (MTU, version etc.)
int pkt_get_mtu (void)
 Return PKTDRVR maximum-transmit-units (MTU). More...
int pkt_get_mac_len (void)
 Return length of MAC address. More...
int pkt_get_api_ver (WORD *ver)
 Return version of spec. More...
int pkt_get_drvr_ver (WORD *major, WORD *minor, WORD *unused1, WORD *unused2)
 Return version of PKTDRVR.
W32_FUNC int W32_CALL pkt_get_vector (void)
 Return PKTDRVR vector.
W32_FUNC WORD W32_CALL pkt_get_drvr_class (void)
const char *W32_CALL pkt_get_device_name (void)
static int pkt16_drvr_init (mac_address *mac_addr)
 Called from pkt_eth_init() to search for PKTDRVR. More...
static void release_callback (void)
static void release_real_mem (void)
 Release allocated DOS memory.
int DTOR pkt_release (void)
static 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'. More...
 if (index >=q->num_buf) index=0
 if (index!=q->out_index)
static void cdecl pkt_receiver_pm (SWI_REGS *r)
static void cdecl pkt_receiver_pm (__dpmi_regs *r)
static void cdecl pkt_receiver_pm (void)
void _pkt_end (void)
int pkt_send (const void *tx, int length)
 Send a link-layer frame. More...
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. More...
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. More...
int pkt_waiting (void)
 Return number of packets waiting in queue.
DWORD pkt_dropped (void)
 Return number of packets dropped.
static int parse_config_pass_1 (void)
 Search WATTCP.CFG file for "PKT.VECTOR = 0x??" etc. More...
int pkt_eth_init (mac_address *addr)
 Initialise Packet driver interface. More...
static BOOL check_intr_num (WORD intr_num)
 Check a single interrupt vector for signature string "PKT DRVR" at offset 3 into intr-handler.
static void _unlock (const void *addr, DWORD size)
int pkt_set_rcv_mode (int mode)
 Sets the receive mode of the interface. More...
int pkt_get_rcv_mode (void)
 Gets the receive mode of the interface (can never be mode 0). More...
int pkt_get_multicast_list (mac_address *listbuf, int *lenp)
 Gets the current list of multicast addresses from the PKTDRVR. More...
int pkt_set_multicast_list (const void *listbuf, int len)
 Sets the list of multicast addresses for which the PKTDRVR is responsible. More...


 Ethernet, Token, FDDI etc. More...
WORD _pkt_ip_ofs = 0
 ofs from link-layer head to ip More...
WORD _pkt_type_ofs = 0
 ofs from link-layer head to type
BOOL _pktserial = FALSE
 using serial driver, SLIP/PPP More...
BYTE _pktdevlevel = 1
 basic unless otherwise specified More...
int _pkt_rxmode = RXMODE_BROADCAST
 active receive mode More...
int _pkt_rxmode0 = -1
 startup receive mode More...
int _pkt_errno = 0
 error code set in pcpkt.c API More...
const char * pkt_error = NULL
 Last pkt error string.
int _pkt_forced_rxmode = -1
 Forced Rx-mode via WATTCP.CFG.
char _pktdrvrname [20] = "unknown"
 Name of PKDRVR.
struct pkt_info_pkt_inf = NULL
 module data that will be locked
static char pkt_sign [] = "PKT DRVR"
static WORD pkt_interrupt = 0
static DWORD pkt_drop_cnt = 0
static BYTE pkt_txretries = 2
static int pkt_txwait = 0
static BOOL pkt_use_near = FALSE
static BOOL pkt_do_reset = FALSE
static int pkt_drvr_ver = 0
static int pkt_num_rx_bufs = RX_BUFS
static struct PktStats init_stats
static struct PktParameters pkt_params
static BOOL got_params = FALSE
REALPTR rm_base
static _go32_dpmi_seginfo rm_cb
static WORD pkt_inf_sel
WORD len
static void WORD rxLen struct
q = &_pkt_inf->pkt_queue
int index = q->in_index + 1
else q num_drop
static WORD cstate_dseg = 0
 Get VJ-compression statistics from pkt-driver. More...

Detailed Description

Packet Driver interface for WatTCP/Watt-32.

Heavily modified and extended for DOSX by G.Vanem gvane.nosp@m.m@ya.nosp@m.hoo.n.nosp@m.o

Definition in file pcpkt.c.

Function Documentation

static int parse_config_pass_1 ( void  )

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

Accept "0x20 - 0xFF".

Definition at line 1410 of file pcpkt.c.

References _pkt_forced_rxmode, ARG_ATOB, ARG_ATOI, and ARG_ATOX_B.

static int pkt16_drvr_init ( mac_address *  mac_addr)

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 578 of file pcpkt.c.

References _pkt_errno, _pkt_forced_rxmode, _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().

static BOOL pkt_api_entry ( IREGS reg,
unsigned  line 

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.

Use 32-bit API; accessing card via pmode driver

Definition at line 1897 of file pcpkt.c.

References _pkt_errno.

static int pkt_drvr_info ( void  )

Fetch the PKTDRVR information.

Device level, class and name.

Definition at line 382 of file pcpkt.c.

References _pkt_errno, _pkt_ip_ofs, _pkt_type_ofs, _pktdevclass, _pktdevlevel, _pktdrvrname, _pktserial, and get_rmode_data().

static void pkt_enqueue ( unsigned  rxBuf,
WORD  rxLen 

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 1449 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 1349 of file pcpkt.c.

int pkt_get_api_ver ( WORD *  ver)

Return version of spec.

this PKTDRVR conforms to.

Return values
-1on error. Return major version in upper 8 bit, minor in lower.

Definition at line 519 of file pcpkt.c.

int pkt_get_mac_len ( void  )

Return length of MAC address.

Return values
6For Ethernet.

Definition at line 504 of file pcpkt.c.

References _pktdevclass.

int pkt_get_mtu ( void  )

Return PKTDRVR maximum-transmit-units (MTU).

This includes length of MAC-header.

Definition at line 489 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
0upon error - _pkt_errno is set
1if retrieval was successful,

Definition at line 2037 of file pcpkt.c.

int pkt_get_rcv_mode ( void  )

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

Return values
!0Okay - _pkt_errno is 0, _pkt_rxmode and retval is current mode.
0Error - _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 1999 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 1243 of file pcpkt.c.

int DTOR pkt_release ( void  )
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 838 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.

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 1090 of file pcpkt.c.

static int pkt_set_access ( void  )

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 332 of file pcpkt.c.

References _pkt_errno, and _pktdevclass.

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
0upon error - _pkt_errno is set
1if set was successful

Definition at line 2084 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 1955 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 302 of file pcpkt.c.

static int setup_pkt_inf ( void  )
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 1804 of file pcpkt.c.

Variable Documentation

int _pkt_errno = 0

error code set in pcpkt.c API

Last PKTDRVR error code.

Definition at line 58 of file pcpkt.c.

WORD _pkt_ip_ofs = 0

ofs from link-layer head to ip

Offset from MAC-header to IP-header.

Definition at line 52 of file pcpkt.c.

int _pkt_rxmode = RXMODE_BROADCAST

active receive mode

Current PKTDRVR/WinPcap Rx-mode.

Definition at line 56 of file pcpkt.c.

int _pkt_rxmode0 = -1

startup receive mode

Startup receive mode.

Definition at line 57 of file pcpkt.c.


Ethernet, Token, FDDI etc.

Driver class; <tcp.h> for values.

Definition at line 51 of file pcpkt.c.

BYTE _pktdevlevel = 1

basic unless otherwise specified

Device level.

Definition at line 55 of file pcpkt.c.

BOOL _pktserial = FALSE

using serial driver, SLIP/PPP

Driver is a serial (SLIP/PPP) driver.

Definition at line 54 of file pcpkt.c.

WORD cstate_dseg = 0

Get VJ-compression statistics from pkt-driver.

Only DOS-PPP ver 0.6+ supports the PD_GET_VJSTATS (0x81) call.

Definition at line 1297 of file pcpkt.c.