1146768Ssam/*
2146768Ssam * Internal details for libpcap on DOS.
3146768Ssam * 32-bit targets: djgpp, Pharlap or DOS4GW.
4146768Ssam */
5146768Ssam
6146768Ssam#ifndef __PCAP_DOS_H
7146768Ssam#define __PCAP_DOS_H
8146768Ssam
9146768Ssam#ifdef __DJGPP__
10146768Ssam#include <pc.h>    /* simple non-conio kbhit */
11146768Ssam#else
12146768Ssam#include <conio.h>
13146768Ssam#endif
14146768Ssam
15146768Ssamtypedef int            BOOL;
16146768Ssamtypedef unsigned char  BYTE;
17146768Ssamtypedef unsigned short WORD;
18146768Ssamtypedef unsigned long  DWORD;
19146768Ssamtypedef BYTE           ETHER[6];
20146768Ssam
21146768Ssam#define ETH_ALEN       sizeof(ETHER)   /* Ether address length */
22146768Ssam#define ETH_HLEN       (2*ETH_ALEN+2)  /* Ether header length  */
23146768Ssam#define ETH_MTU        1500
24146768Ssam#define ETH_MIN        60
25146768Ssam#define ETH_MAX        (ETH_MTU+ETH_HLEN)
26146768Ssam
27146768Ssam#ifndef TRUE
28146768Ssam  #define TRUE   1
29146768Ssam  #define FALSE  0
30146768Ssam#endif
31146768Ssam
32146768Ssam#define PHARLAP  1
33146768Ssam#define DJGPP    2
34146768Ssam#define DOS4GW   4
35146768Ssam
36146768Ssam#ifdef __DJGPP__
37146768Ssam  #undef  DOSX
38146768Ssam  #define DOSX DJGPP
39146768Ssam#endif
40146768Ssam
41146768Ssam#ifdef __WATCOMC__
42146768Ssam  #undef  DOSX
43146768Ssam  #define DOSX DOS4GW
44146768Ssam#endif
45146768Ssam
46146768Ssam#ifdef __HIGHC__
47146768Ssam  #include <pharlap.h>
48146768Ssam  #undef  DOSX
49146768Ssam  #define DOSX PHARLAP
50146768Ssam  #define inline
51146768Ssam#else
52146768Ssam  typedef unsigned int UINT;
53146768Ssam#endif
54146768Ssam
55146768Ssam
56146768Ssam#if defined(__GNUC__) || defined(__HIGHC__)
57146768Ssam  typedef unsigned long long  uint64;
58146768Ssam  typedef unsigned long long  QWORD;
59146768Ssam#endif
60146768Ssam
61146768Ssam#if defined(__WATCOMC__)
62146768Ssam  typedef unsigned __int64  uint64;
63146768Ssam  typedef unsigned __int64  QWORD;
64146768Ssam#endif
65146768Ssam
66146768Ssam#define ARGSUSED(x)  (void) x
67146768Ssam
68146768Ssam#if defined (__SMALL__) || defined(__LARGE__)
69146768Ssam  #define DOSX 0
70146768Ssam
71146768Ssam#elif !defined(DOSX)
72146768Ssam  #error DOSX not defined; 1 = PharLap, 2 = djgpp, 4 = DOS4GW
73146768Ssam#endif
74146768Ssam
75146768Ssam#ifdef __HIGHC__
76146768Ssam#define min(a,b) _min(a,b)
77146768Ssam#define max(a,b) _max(a,b)
78146768Ssam#endif
79146768Ssam
80146768Ssam#ifndef min
81146768Ssam#define min(a,b) ((a) < (b) ? (a) : (b))
82146768Ssam#endif
83146768Ssam
84146768Ssam#ifndef max
85146768Ssam#define max(a,b) ((a) < (b) ? (b) : (a))
86146768Ssam#endif
87146768Ssam
88146768Ssam#if !defined(_U_) && defined(__GNUC__)
89146768Ssam#define _U_  __attribute__((unused))
90146768Ssam#endif
91146768Ssam
92146768Ssam#ifndef _U_
93146768Ssam#define _U_
94146768Ssam#endif
95146768Ssam
96146768Ssam#if defined(USE_32BIT_DRIVERS)
97146768Ssam  #include "msdos/pm_drvr/lock.h"
98146768Ssam
99146768Ssam  #ifndef RECEIVE_QUEUE_SIZE
100146768Ssam  #define RECEIVE_QUEUE_SIZE  60
101146768Ssam  #endif
102146768Ssam
103146768Ssam  #ifndef RECEIVE_BUF_SIZE
104146768Ssam  #define RECEIVE_BUF_SIZE   (ETH_MAX+20)
105146768Ssam  #endif
106146768Ssam
107146768Ssam  extern struct device el2_dev     LOCKED_VAR;  /* 3Com EtherLink II */
108146768Ssam  extern struct device el3_dev     LOCKED_VAR;  /*      EtherLink III */
109146768Ssam  extern struct device tc59_dev    LOCKED_VAR;  /* 3Com Vortex Card (?) */
110146768Ssam  extern struct device tc515_dev   LOCKED_VAR;
111146768Ssam  extern struct device tc90x_dev   LOCKED_VAR;
112146768Ssam  extern struct device tc90bcx_dev LOCKED_VAR;
113146768Ssam  extern struct device wd_dev      LOCKED_VAR;
114146768Ssam  extern struct device ne_dev      LOCKED_VAR;
115146768Ssam  extern struct device acct_dev    LOCKED_VAR;
116146768Ssam  extern struct device cs89_dev    LOCKED_VAR;
117146768Ssam  extern struct device rtl8139_dev LOCKED_VAR;
118146768Ssam
119146768Ssam  struct rx_ringbuf {
120146768Ssam         volatile int in_index;   /* queue index head */
121146768Ssam         int          out_index;  /* queue index tail */
122146768Ssam         int          elem_size;  /* size of each element */
123146768Ssam         int          num_elem;   /* number of elements */
124146768Ssam         char        *buf_start;  /* start of buffer pool */
125146768Ssam       };
126146768Ssam
127146768Ssam  struct rx_elem {
128146768Ssam         DWORD size;              /* size copied to this element */
129146768Ssam         BYTE  data[ETH_MAX+10];  /* add some margin. data[0] should be */
130146768Ssam       };                         /* dword aligned */
131146768Ssam
132146768Ssam  extern BYTE *get_rxbuf     (int len) LOCKED_FUNC;
133146768Ssam  extern int   peek_rxbuf    (BYTE **buf);
134146768Ssam  extern int   release_rxbuf (BYTE  *buf);
135146768Ssam
136146768Ssam#else
137146768Ssam  #define LOCKED_VAR
138146768Ssam  #define LOCKED_FUNC
139146768Ssam
140146768Ssam  struct device {
141146768Ssam         const char *name;
142146768Ssam         const char *long_name;
143146768Ssam         DWORD  base_addr;      /* device I/O address       */
144146768Ssam         int    irq;            /* device IRQ number        */
145146768Ssam         int    dma;            /* DMA channel              */
146146768Ssam         DWORD  mem_start;      /* shared mem start         */
147146768Ssam         DWORD  mem_end;        /* shared mem end           */
148146768Ssam         DWORD  rmem_start;     /* shmem "recv" start       */
149146768Ssam         DWORD  rmem_end;       /* shared "recv" end        */
150146768Ssam
151146768Ssam         struct device *next;   /* next device in list      */
152146768Ssam
153146768Ssam         /* interface service routines */
154146768Ssam         int   (*probe)(struct device *dev);
155146768Ssam         int   (*open) (struct device *dev);
156146768Ssam         void  (*close)(struct device *dev);
157146768Ssam         int   (*xmit) (struct device *dev, const void *buf, int len);
158146768Ssam         void *(*get_stats)(struct device *dev);
159146768Ssam         void  (*set_multicast_list)(struct device *dev);
160146768Ssam
161146768Ssam         /* driver-to-pcap receive buffer routines */
162146768Ssam         int   (*copy_rx_buf) (BYTE *buf, int max); /* rx-copy (pktdrvr only) */
163146768Ssam         BYTE *(*get_rx_buf) (int len);             /* rx-buf fetch/enqueue */
164146768Ssam         int   (*peek_rx_buf) (BYTE **buf);         /* rx-non-copy at queue */
165146768Ssam         int   (*release_rx_buf) (BYTE *buf);       /* release after peek */
166146768Ssam
167146768Ssam         WORD   flags;          /* Low-level status flags. */
168146768Ssam         void  *priv;           /* private data */
169146768Ssam       };
170146768Ssam
171146768Ssam  /*
172146768Ssam   * Network device statistics
173146768Ssam   */
174146768Ssam  typedef struct net_device_stats {
175146768Ssam          DWORD  rx_packets;            /* total packets received       */
176146768Ssam          DWORD  tx_packets;            /* total packets transmitted    */
177146768Ssam          DWORD  rx_bytes;              /* total bytes received         */
178146768Ssam          DWORD  tx_bytes;              /* total bytes transmitted      */
179146768Ssam          DWORD  rx_errors;             /* bad packets received         */
180146768Ssam          DWORD  tx_errors;             /* packet transmit problems     */
181146768Ssam          DWORD  rx_dropped;            /* no space in Rx buffers       */
182146768Ssam          DWORD  tx_dropped;            /* no space available for Tx    */
183146768Ssam          DWORD  multicast;             /* multicast packets received   */
184146768Ssam
185146768Ssam          /* detailed rx_errors: */
186146768Ssam          DWORD  rx_length_errors;
187146768Ssam          DWORD  rx_over_errors;        /* recv'r overrun error         */
188146768Ssam          DWORD  rx_osize_errors;       /* recv'r over-size error       */
189146768Ssam          DWORD  rx_crc_errors;         /* recv'd pkt with crc error    */
190146768Ssam          DWORD  rx_frame_errors;       /* recv'd frame alignment error */
191146768Ssam          DWORD  rx_fifo_errors;        /* recv'r fifo overrun          */
192146768Ssam          DWORD  rx_missed_errors;      /* recv'r missed packet         */
193146768Ssam
194146768Ssam          /* detailed tx_errors */
195146768Ssam          DWORD  tx_aborted_errors;
196146768Ssam          DWORD  tx_carrier_errors;
197146768Ssam          DWORD  tx_fifo_errors;
198146768Ssam          DWORD  tx_heartbeat_errors;
199146768Ssam          DWORD  tx_window_errors;
200146768Ssam          DWORD  tx_collisions;
201146768Ssam          DWORD  tx_jabbers;
202146768Ssam        } NET_STATS;
203146768Ssam#endif
204146768Ssam
205146768Ssamextern struct device       *active_dev  LOCKED_VAR;
206146768Ssamextern const struct device *dev_base    LOCKED_VAR;
207146768Ssamextern struct device       *probed_dev;
208146768Ssam
209146768Ssamextern int pcap_pkt_debug;
210146768Ssam
211146768Ssamextern void _w32_os_yield (void); /* Watt-32's misc.c */
212146768Ssam
213146768Ssam#ifdef NDEBUG
214146768Ssam  #define PCAP_ASSERT(x) ((void)0)
215146768Ssam
216146768Ssam#else
217146768Ssam  void pcap_assert (const char *what, const char *file, unsigned line);
218146768Ssam
219146768Ssam  #define PCAP_ASSERT(x) do { \
220146768Ssam                           if (!(x)) \
221146768Ssam                              pcap_assert (#x, __FILE__, __LINE__); \
222146768Ssam                         } while (0)
223146768Ssam#endif
224146768Ssam
225146768Ssam#endif  /* __PCAP_DOS_H */
226