Watt-32 tcp/ip  2.2 dev-rel.10
swsvpkt.h
Go to the documentation of this file.
1 
5 #ifndef _w32_SWSVPKT_H
6 #define _w32_SWSVPKT_H
7 
8 #include <winioctl.h>
9 
10 /* Win32 accessible device. Adapters have 0..31 appended */
11 #define IOCTL_DEVICE "SwsVpkt"
12 
13 /* Device type */
14 #define IOCTL_TYPE 0xA50C /* Microsoft uses 0 - 0x7FFF, OEMs use 0x8000 - 0xFFFF */
15 #define IOCTL_FCMIN 0x900 /* Microsoft uses function codes 0-0x7FF, OEM's use 0x800 - 0xFFF */
16 
17 #define IOCTL_GETMACADDR \
18  CTL_CODE (IOCTL_TYPE, (IOCTL_FCMIN + 0), METHOD_BUFFERED, FILE_READ_ACCESS)
19  /* lpvOutBuffer -> 6 BYTE MAC address */
20 
21 #define IOCTL_SETMULTICASTLIST \
22  CTL_CODE (IOCTL_TYPE, (IOCTL_FCMIN + 1), METHOD_BUFFERED, FILE_WRITE_ACCESS)
23  /* lpvInBuffer -> Multicast list */
24 
25 #define IOCTL_SETPROMISCUITY \
26  CTL_CODE (IOCTL_TYPE, (IOCTL_FCMIN + 2), METHOD_BUFFERED, FILE_WRITE_ACCESS)
27  /* lpvInBuffer -> BYTE, !0= enable promiscuous mode */
28 
29 #define IOCTL_WRITE_SCATTER \
30  CTL_CODE (IOCTL_TYPE, (IOCTL_FCMIN + 3), METHOD_OUT_DIRECT, FILE_WRITE_ACCESS)
31  /* lpvInBuffer -> array of IOCTL_BUFFER's */
32 
33 typedef struct IOCTL_BUFFER {
34  void *pv;
35  DWORD dwLen;
36  } IOCTL_BUFFER;
37 
38 #define IOCTL_GETINFO \
39  CTL_CODE (IOCTL_TYPE, (IOCTL_FCMIN + 4), METHOD_BUFFERED, FILE_READ_ACCESS)
40  /* lpvOutBuffer -> IOCTL_INFO */
41 
42 typedef struct IOCTL_INFO {
43  BOOL bPowerOn;
44  BOOL bMediaDisconnected;
45  BOOL bWan; /* Adapter is a WAN */
46  BOOL bWanDown; /* WAN is not connected */
47  } IOCTL_INFO;
48 
49 #define IOCTL_GETMULTICASTLIST \
50  CTL_CODE (IOCTL_TYPE, (IOCTL_FCMIN + 5), METHOD_BUFFERED, FILE_READ_ACCESS)
51  /* lpvOutBuffer -> Multicast list */
52 
53 #define IOCTL_GETDESC \
54  CTL_CODE (IOCTL_TYPE, (IOCTL_FCMIN + 6), METHOD_BUFFERED, FILE_READ_ACCESS)
55  /* lpvOutBuffer -> ASCIIZ string */
56 
57 /* Get a ptr to the start of a struct given a ptr to a field within it
58  */
59 #define SWS_CONTAINER(ptr, type, field) \
60  (type*) ((char*)(ptr) - offsetof(type, field))
61 
62 
63 /* Receive buffer
64  */
65 struct SRxBuffer {
66  OVERLAPPED overlap;
67 #define OVL2RXBUF(p) SWS_CONTAINER (p, struct SRxBuffer, overlap)
68  unsigned char buffer [1514];
69  };
70 
71 struct SwsVpktUsr;
72 
73 /* Rx frame callback */
74 typedef void SwsVpktRxFn (
75  struct SwsVpktUsr *, /* IN: Handle */
76  const void *, /* IN: Frame data */
77  unsigned); /* IN: Frame length */
78 
79 /* Interface instance
80  */
81 struct SwsVpktUsr {
82  HANDLE hDevice; /* Packet protocol driver */
83  OVERLAPPED txOverlap; /* For write requests */
84  HANDLE hWorker; /* Worker thread handle */
85  int iWorkerExit; /* Worker thread is exiting */
86  SwsVpktRxFn *pfnRx; /* Rx frame callback */
87  unsigned uRxBufs;
88  struct SRxBuffer rxBuffer[1]; /* VLA of Rx buffers */
89  };
90 
92  SwsVpktRxFn *pfnRx; /* Rx frame callback */
93  unsigned uRxBufs; /* No. receive buffers */
94  };
95 
97  unsigned int isPowerOn : 1;
98  unsigned int isMediaConnected : 1;
99  unsigned int isWan : 1;
100  unsigned int isWanDown : 1;
101  };
102 
103 extern struct SwsVpktUsr *SwsVpktOpen ( /* retuns NULL on error */
104  const char *, /* IN: Adapter name; \\.\SwsVpkt0..31 */
105  const struct SwsVpktOpenInfo *); /* IN: Open info */
106 
107 extern BOOL SwsVpktClose (struct SwsVpktUsr *usr);
108 
109 extern BOOL SwsVpktGetAdapterState (const struct SwsVpktUsr *usr,
110  struct SwsVpktAdapterState *state);
111 
112 extern BOOL SwsVpktGetStatistics (const struct SwsVpktUsr *usr,
113  struct PktStats *stats);
114 
115 extern UINT SwsVpktSend (struct SwsVpktUsr *usr,
116  const void *buf,
117  UINT buf_len);
118 
119 extern BOOL SwsVpktGetMacAddress (const struct SwsVpktUsr *usr,
120  mac_address *addr);
121 
122 extern BOOL SwsVpktGetDescription (const struct SwsVpktUsr *usr,
123  char *descr, size_t descr_len);
124 
125 extern BOOL SwsVpktGetNDISversion (const struct SwsVpktUsr *usr,
126  DWORD *ver);
127 
128 extern const char *SwsVpktGetDriverVersion (void);
129 
130 extern BOOL SwsVpktDeviceRequest2 (HANDLE hDevice,
131  DWORD dwIoControlCode,
132  const void *lpInBuffer,
133  DWORD nInBufferSize,
134  void *lpOutBuffer,
135  DWORD nOutBufferSize,
136  DWORD *lpBytesReturned,
137  const char *file,
138  unsigned line);
139 
140 #define SwsVpktDeviceRequest(dev,code,in_buf,in_size,out_buf,out_size,bytes_ret) \
141  SwsVpktDeviceRequest2 (dev,code,in_buf,in_size,out_buf,out_size,bytes_ret, \
142  __FILE__, __LINE__)
143 
144 #endif
145 
Definition: tcp.h:778