Home | History | Annotate | Line # | Download | only in dist
      1  1.3  christos /*	$NetBSD: pcap-dos.h,v 1.3 2015/03/31 21:39:42 christos Exp $	*/
      2  1.2  christos 
      3  1.1  christos /*
      4  1.1  christos  * Internal details for libpcap on DOS.
      5  1.1  christos  * 32-bit targets: djgpp, Pharlap or DOS4GW.
      6  1.1  christos  */
      7  1.1  christos 
      8  1.1  christos #ifndef __PCAP_DOS_H
      9  1.1  christos #define __PCAP_DOS_H
     10  1.1  christos 
     11  1.1  christos #ifdef __DJGPP__
     12  1.1  christos #include <pc.h>    /* simple non-conio kbhit */
     13  1.1  christos #else
     14  1.1  christos #include <conio.h>
     15  1.1  christos #endif
     16  1.1  christos 
     17  1.1  christos typedef int            BOOL;
     18  1.1  christos typedef unsigned char  BYTE;
     19  1.1  christos typedef unsigned short WORD;
     20  1.1  christos typedef unsigned long  DWORD;
     21  1.1  christos typedef BYTE           ETHER[6];
     22  1.1  christos 
     23  1.1  christos #define ETH_ALEN       sizeof(ETHER)   /* Ether address length */
     24  1.1  christos #define ETH_HLEN       (2*ETH_ALEN+2)  /* Ether header length  */
     25  1.1  christos #define ETH_MTU        1500
     26  1.1  christos #define ETH_MIN        60
     27  1.1  christos #define ETH_MAX        (ETH_MTU+ETH_HLEN)
     28  1.1  christos 
     29  1.1  christos #ifndef TRUE
     30  1.1  christos   #define TRUE   1
     31  1.1  christos   #define FALSE  0
     32  1.1  christos #endif
     33  1.1  christos 
     34  1.1  christos #define PHARLAP  1
     35  1.1  christos #define DJGPP    2
     36  1.1  christos #define DOS4GW   4
     37  1.1  christos 
     38  1.1  christos #ifdef __DJGPP__
     39  1.1  christos   #undef  DOSX
     40  1.1  christos   #define DOSX DJGPP
     41  1.1  christos #endif
     42  1.1  christos 
     43  1.1  christos #ifdef __WATCOMC__
     44  1.1  christos   #undef  DOSX
     45  1.1  christos   #define DOSX DOS4GW
     46  1.1  christos #endif
     47  1.1  christos 
     48  1.1  christos #ifdef __HIGHC__
     49  1.1  christos   #include <pharlap.h>
     50  1.1  christos   #undef  DOSX
     51  1.1  christos   #define DOSX PHARLAP
     52  1.1  christos   #define inline
     53  1.1  christos #else
     54  1.1  christos   typedef unsigned int UINT;
     55  1.1  christos #endif
     56  1.1  christos 
     57  1.1  christos 
     58  1.1  christos #if defined(__GNUC__) || defined(__HIGHC__)
     59  1.1  christos   typedef unsigned long long  uint64;
     60  1.1  christos   typedef unsigned long long  QWORD;
     61  1.1  christos #endif
     62  1.1  christos 
     63  1.1  christos #if defined(__WATCOMC__)
     64  1.1  christos   typedef unsigned __int64  uint64;
     65  1.1  christos   typedef unsigned __int64  QWORD;
     66  1.1  christos #endif
     67  1.1  christos 
     68  1.1  christos #define ARGSUSED(x)  (void) x
     69  1.1  christos 
     70  1.1  christos #if defined (__SMALL__) || defined(__LARGE__)
     71  1.1  christos   #define DOSX 0
     72  1.1  christos 
     73  1.1  christos #elif !defined(DOSX)
     74  1.1  christos   #error DOSX not defined; 1 = PharLap, 2 = djgpp, 4 = DOS4GW
     75  1.1  christos #endif
     76  1.1  christos 
     77  1.1  christos #ifdef __HIGHC__
     78  1.1  christos #define min(a,b) _min(a,b)
     79  1.1  christos #define max(a,b) _max(a,b)
     80  1.1  christos #endif
     81  1.1  christos 
     82  1.1  christos #ifndef min
     83  1.1  christos #define min(a,b) ((a) < (b) ? (a) : (b))
     84  1.1  christos #endif
     85  1.1  christos 
     86  1.1  christos #ifndef max
     87  1.1  christos #define max(a,b) ((a) < (b) ? (b) : (a))
     88  1.1  christos #endif
     89  1.1  christos 
     90  1.1  christos #if !defined(_U_) && defined(__GNUC__)
     91  1.1  christos #define _U_  __attribute__((unused))
     92  1.1  christos #endif
     93  1.1  christos 
     94  1.1  christos #ifndef _U_
     95  1.1  christos #define _U_
     96  1.1  christos #endif
     97  1.1  christos 
     98  1.1  christos #if defined(USE_32BIT_DRIVERS)
     99  1.1  christos   #include "msdos/pm_drvr/lock.h"
    100  1.1  christos 
    101  1.1  christos   #ifndef RECEIVE_QUEUE_SIZE
    102  1.1  christos   #define RECEIVE_QUEUE_SIZE  60
    103  1.1  christos   #endif
    104  1.1  christos 
    105  1.1  christos   #ifndef RECEIVE_BUF_SIZE
    106  1.1  christos   #define RECEIVE_BUF_SIZE   (ETH_MAX+20)
    107  1.1  christos   #endif
    108  1.1  christos 
    109  1.1  christos   extern struct device el2_dev     LOCKED_VAR;  /* 3Com EtherLink II */
    110  1.1  christos   extern struct device el3_dev     LOCKED_VAR;  /*      EtherLink III */
    111  1.1  christos   extern struct device tc59_dev    LOCKED_VAR;  /* 3Com Vortex Card (?) */
    112  1.1  christos   extern struct device tc515_dev   LOCKED_VAR;
    113  1.1  christos   extern struct device tc90x_dev   LOCKED_VAR;
    114  1.1  christos   extern struct device tc90bcx_dev LOCKED_VAR;
    115  1.1  christos   extern struct device wd_dev      LOCKED_VAR;
    116  1.1  christos   extern struct device ne_dev      LOCKED_VAR;
    117  1.1  christos   extern struct device acct_dev    LOCKED_VAR;
    118  1.1  christos   extern struct device cs89_dev    LOCKED_VAR;
    119  1.1  christos   extern struct device rtl8139_dev LOCKED_VAR;
    120  1.1  christos 
    121  1.1  christos   struct rx_ringbuf {
    122  1.1  christos          volatile int in_index;   /* queue index head */
    123  1.1  christos          int          out_index;  /* queue index tail */
    124  1.1  christos          int          elem_size;  /* size of each element */
    125  1.1  christos          int          num_elem;   /* number of elements */
    126  1.1  christos          char        *buf_start;  /* start of buffer pool */
    127  1.1  christos        };
    128  1.1  christos 
    129  1.1  christos   struct rx_elem {
    130  1.1  christos          DWORD size;              /* size copied to this element */
    131  1.1  christos          BYTE  data[ETH_MAX+10];  /* add some margin. data[0] should be */
    132  1.1  christos        };                         /* dword aligned */
    133  1.1  christos 
    134  1.1  christos   extern BYTE *get_rxbuf     (int len) LOCKED_FUNC;
    135  1.1  christos   extern int   peek_rxbuf    (BYTE **buf);
    136  1.1  christos   extern int   release_rxbuf (BYTE  *buf);
    137  1.1  christos 
    138  1.1  christos #else
    139  1.1  christos   #define LOCKED_VAR
    140  1.1  christos   #define LOCKED_FUNC
    141  1.1  christos 
    142  1.1  christos   struct device {
    143  1.1  christos          const char *name;
    144  1.1  christos          const char *long_name;
    145  1.1  christos          DWORD  base_addr;      /* device I/O address       */
    146  1.1  christos          int    irq;            /* device IRQ number        */
    147  1.1  christos          int    dma;            /* DMA channel              */
    148  1.1  christos          DWORD  mem_start;      /* shared mem start         */
    149  1.1  christos          DWORD  mem_end;        /* shared mem end           */
    150  1.1  christos          DWORD  rmem_start;     /* shmem "recv" start       */
    151  1.1  christos          DWORD  rmem_end;       /* shared "recv" end        */
    152  1.1  christos 
    153  1.1  christos          struct device *next;   /* next device in list      */
    154  1.1  christos 
    155  1.1  christos          /* interface service routines */
    156  1.1  christos          int   (*probe)(struct device *dev);
    157  1.1  christos          int   (*open) (struct device *dev);
    158  1.1  christos          void  (*close)(struct device *dev);
    159  1.1  christos          int   (*xmit) (struct device *dev, const void *buf, int len);
    160  1.1  christos          void *(*get_stats)(struct device *dev);
    161  1.1  christos          void  (*set_multicast_list)(struct device *dev);
    162  1.1  christos 
    163  1.1  christos          /* driver-to-pcap receive buffer routines */
    164  1.1  christos          int   (*copy_rx_buf) (BYTE *buf, int max); /* rx-copy (pktdrvr only) */
    165  1.1  christos          BYTE *(*get_rx_buf) (int len);             /* rx-buf fetch/enqueue */
    166  1.1  christos          int   (*peek_rx_buf) (BYTE **buf);         /* rx-non-copy at queue */
    167  1.1  christos          int   (*release_rx_buf) (BYTE *buf);       /* release after peek */
    168  1.1  christos 
    169  1.1  christos          WORD   flags;          /* Low-level status flags. */
    170  1.1  christos          void  *priv;           /* private data */
    171  1.1  christos        };
    172  1.1  christos 
    173  1.1  christos   /*
    174  1.1  christos    * Network device statistics
    175  1.1  christos    */
    176  1.1  christos   typedef struct net_device_stats {
    177  1.1  christos           DWORD  rx_packets;            /* total packets received       */
    178  1.1  christos           DWORD  tx_packets;            /* total packets transmitted    */
    179  1.1  christos           DWORD  rx_bytes;              /* total bytes received         */
    180  1.1  christos           DWORD  tx_bytes;              /* total bytes transmitted      */
    181  1.1  christos           DWORD  rx_errors;             /* bad packets received         */
    182  1.1  christos           DWORD  tx_errors;             /* packet transmit problems     */
    183  1.1  christos           DWORD  rx_dropped;            /* no space in Rx buffers       */
    184  1.1  christos           DWORD  tx_dropped;            /* no space available for Tx    */
    185  1.1  christos           DWORD  multicast;             /* multicast packets received   */
    186  1.1  christos 
    187  1.1  christos           /* detailed rx_errors: */
    188  1.1  christos           DWORD  rx_length_errors;
    189  1.1  christos           DWORD  rx_over_errors;        /* recv'r overrun error         */
    190  1.1  christos           DWORD  rx_osize_errors;       /* recv'r over-size error       */
    191  1.1  christos           DWORD  rx_crc_errors;         /* recv'd pkt with crc error    */
    192  1.1  christos           DWORD  rx_frame_errors;       /* recv'd frame alignment error */
    193  1.1  christos           DWORD  rx_fifo_errors;        /* recv'r fifo overrun          */
    194  1.1  christos           DWORD  rx_missed_errors;      /* recv'r missed packet         */
    195  1.1  christos 
    196  1.1  christos           /* detailed tx_errors */
    197  1.1  christos           DWORD  tx_aborted_errors;
    198  1.1  christos           DWORD  tx_carrier_errors;
    199  1.1  christos           DWORD  tx_fifo_errors;
    200  1.1  christos           DWORD  tx_heartbeat_errors;
    201  1.1  christos           DWORD  tx_window_errors;
    202  1.1  christos           DWORD  tx_collisions;
    203  1.1  christos           DWORD  tx_jabbers;
    204  1.1  christos         } NET_STATS;
    205  1.1  christos #endif
    206  1.1  christos 
    207  1.1  christos extern struct device       *active_dev  LOCKED_VAR;
    208  1.1  christos extern const struct device *dev_base    LOCKED_VAR;
    209  1.1  christos extern struct device       *probed_dev;
    210  1.1  christos 
    211  1.1  christos extern int pcap_pkt_debug;
    212  1.1  christos 
    213  1.1  christos extern void _w32_os_yield (void); /* Watt-32's misc.c */
    214  1.1  christos 
    215  1.1  christos #ifdef NDEBUG
    216  1.1  christos   #define PCAP_ASSERT(x) ((void)0)
    217  1.1  christos 
    218  1.1  christos #else
    219  1.3  christos   void pcap_assert (const char *what, const char *file, unsigned line);
    220  1.1  christos 
    221  1.1  christos   #define PCAP_ASSERT(x) do { \
    222  1.1  christos                            if (!(x)) \
    223  1.1  christos                               pcap_assert (#x, __FILE__, __LINE__); \
    224  1.1  christos                          } while (0)
    225  1.1  christos #endif
    226  1.1  christos 
    227  1.1  christos #endif  /* __PCAP_DOS_H */
    228