• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 1993,1994
3  *      Texas A&M University.  All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. All advertising materials mentioning features or use of this software
14  *    must display the following acknowledgement:
15  *      This product includes software developed by Texas A&M University
16  *      and its contributors.
17  * 4. Neither the name of the University nor the names of its contributors
18  *    may be used to endorse or promote products derived from this software
19  *    without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31  * SUCH DAMAGE.
32  *
33  * Developers:
34  *             David K. Hess, Douglas Lee Schales, David R. Safford
35  *
36  * Heavily modified for Metaware HighC + GNU C 2.8+
37  *             Gisle Vanem 1998
38  */
39 
40 #ifndef __PCAP_NDIS_H
41 #define __PCAP_NDIS_H
42 
43 #if defined (__HIGHC__)
44   #define pascal          _CC(_CALLEE_POPS_STACK & ~_REVERSE_PARMS) /* calling convention */
45   #define CALLBACK(foo)   pascal WORD foo
46   #define PAS_PTR(x,arg)  typedef FAR WORD pascal (*x) arg
47   #define GUARD()         _inline (0x9C,0xFA)   /* pushfd, cli */
48   #define UNGUARD()       _inline (0x9D)        /* popfd */
49   #define FAR             _far
50 
51 #elif defined(__GNUC__)
52   #define CALLBACK(foo)   WORD foo __attribute__((stdcall))
53   #define PAS_PTR(x,arg)  typedef WORD (*x) arg __attribute__((stdcall))
54   #define GUARD()         __asm__ __volatile__ ("pushfd; cli")
55   #define UNGUARD()       __asm__ __volatile__ ("popfd")
56   #define FAR
57 
58 #elif defined (__TURBOC__)
59   #define CALLBACK(foo)   WORD pascal foo
60   #define PAS_PTR(x,arg)  typedef WORD pascal (_far *x) arg
61   #define GUARD()         _asm { pushf; cli }
62   #define UNGUARD()       _asm { popf }
63   #define FAR             _far
64 
65 #elif defined (__WATCOMC__)
66   #define CALLBACK(foo)   WORD pascal foo
67   #define PAS_PTR(x,arg)  typedef WORD pascal (_far *x) arg
68   #define GUARD()         _disable()
69   #define UNGUARD()       _enable()
70   #define FAR             _far
71 
72 #else
73   #error Unsupported compiler
74 #endif
75 
76 
77 /*
78  *  Forwards
79  */
80 struct _ReqBlock;
81 struct _TxBufDescr;
82 struct _TDBufDescr;
83 
84 /*
85  * Protocol Manager API
86  */
87 PAS_PTR (ProtMan, (struct _ReqBlock FAR*, WORD));
88 
89 /*
90  * System request
91  */
92 PAS_PTR (SystemRequest, (DWORD, DWORD, WORD, WORD, WORD));
93 
94 /*
95  * MAC API
96  */
97 PAS_PTR (TransmitChain, (WORD, WORD, struct _TxBufDescr FAR*, WORD));
98 PAS_PTR (TransferData,  (WORD*,WORD, struct _TDBufDescr FAR*, WORD));
99 PAS_PTR (Request,       (WORD, WORD, WORD, DWORD, WORD, WORD));
100 PAS_PTR (ReceiveRelease,(WORD, WORD));
101 PAS_PTR (IndicationOn,  (WORD));
102 PAS_PTR (IndicationOff, (WORD));
103 
104 
105 typedef enum {
106         HARDWARE_NOT_INSTALLED  = 0,
107         HARDWARE_FAILED_DIAG    = 1,
108         HARDWARE_FAILED_CONFIG  = 2,
109         HARDWARE_HARD_FAULT     = 3,
110         HARDWARE_SOFT_FAULT     = 4,
111         HARDWARE_OK             = 7,
112         HARDWARE_MASK           = 0x0007,
113         MAC_BOUND               = 0x0008,
114         MAC_OPEN                = 0x0010,
115         DIAG_IN_PROGRESS        = 0x0020
116       } NdisMacStatus;
117 
118 typedef enum {
119         STATUS_RING_STATUS      = 1,
120         STATUS_ADAPTER_CHECK    = 2,
121         STATUS_START_RESET      = 3,
122         STATUS_INTERRUPT        = 4,
123         STATUS_END_RESET        = 5
124       } NdisStatus;
125 
126 typedef enum {
127         FILTER_DIRECTED         = 1,
128         FILTER_BROADCAST        = 2,
129         FILTER_PROMISCUOUS      = 4,
130         FILTER_SOURCE_ROUTE     = 8
131       } NdisPacketFilter;
132 
133 typedef enum {
134         REQ_INITIATE_DIAGNOSTICS     = 1,
135         REQ_READ_ERROR_LOG           = 2,
136         REQ_SET_STATION_ADDRESS      = 3,
137         REQ_OPEN_ADAPTER             = 4,
138         REQ_CLOSE_ADAPTER            = 5,
139         REQ_RESET_MAC                = 6,
140         REQ_SET_PACKET_FILTER        = 7,
141         REQ_ADD_MULTICAST_ADDRESS    = 8,
142         REQ_DELETE_MULTICAST_ADDRESS = 9,
143         REQ_UPDATE_STATISTICS        = 10,
144         REQ_CLEAR_STATISTICS         = 11,
145         REQ_INTERRUPT_REQUEST        = 12,
146         REQ_SET_FUNCTIONAL_ADDRESS   = 13,
147         REQ_SET_LOOKAHEAD            = 14
148       } NdisGeneralRequest;
149 
150 typedef enum {
151         SF_BROADCAST             = 0x00000001L,
152         SF_MULTICAST             = 0x00000002L,
153         SF_FUNCTIONAL            = 0x00000004L,
154         SF_PROMISCUOUS           = 0x00000008L,
155         SF_SOFT_ADDRESS          = 0x00000010L,
156         SF_STATS_CURRENT         = 0x00000020L,
157         SF_INITIATE_DIAGS        = 0x00000040L,
158         SF_LOOPBACK              = 0x00000080L,
159         SF_RECEIVE_CHAIN         = 0x00000100L,
160         SF_SOURCE_ROUTING        = 0x00000200L,
161         SF_RESET_MAC             = 0x00000400L,
162         SF_OPEN_CLOSE            = 0x00000800L,
163         SF_INTERRUPT_REQUEST     = 0x00001000L,
164         SF_SOURCE_ROUTING_BRIDGE = 0x00002000L,
165         SF_VIRTUAL_ADDRESSES     = 0x00004000L
166       } NdisMacServiceFlags;
167 
168 typedef enum {
169         REQ_INITIATE_BIND        = 1,
170         REQ_BIND                 = 2,
171         REQ_INITIATE_PREBIND     = 3,
172         REQ_INITIATE_UNBIND      = 4,
173         REQ_UNBIND               = 5
174       } NdisSysRequest;
175 
176 typedef enum  {
177         PM_GET_PROTOCOL_MANAGER_INFO      = 1,
178         PM_REGISTER_MODULE                = 2,
179         PM_BIND_AND_START                 = 3,
180         PM_GET_PROTOCOL_MANAGER_LINKAGE   = 4,
181         PM_GET_PROTOCOL_INI_PATH          = 5,
182         PM_REGISTER_PROTOCOL_MANAGER_INFO = 6,
183         PM_INIT_AND_REGISTER              = 7,
184         PM_UNBIND_AND_STOP                = 8,
185         PM_BIND_STATUS                    = 9,
186         PM_REGISTER_STATUS                = 10
187       } NdisProtManager;
188 
189 
190 typedef enum {
191         ERR_SUCCESS                      = 0x00,
192         ERR_WAIT_FOR_RELEASE             = 0x01,
193         ERR_REQUEST_QUEUED               = 0x02,
194         ERR_FRAME_NOT_RECOGNIZED         = 0x03,
195         ERR_FRAME_REJECTED               = 0x04,
196         ERR_FORWARD_FRAME                = 0x05,
197         ERR_OUT_OF_RESOURCE              = 0x06,
198         ERR_INVALID_PARAMETER            = 0x07,
199         ERR_INVALID_FUNCTION             = 0x08,
200         ERR_NOT_SUPPORTED                = 0x09,
201         ERR_HARDWARE_ERROR               = 0x0A,
202         ERR_TRANSMIT_ERROR               = 0x0B,
203         ERR_NO_SUCH_DESTINATION          = 0x0C,
204         ERR_BUFFER_TOO_SMALL             = 0x0D,
205         ERR_ALREADY_STARTED              = 0x20,
206         ERR_INCOMPLETE_BINDING           = 0x21,
207         ERR_DRIVER_NOT_INITIALIZED       = 0x22,
208         ERR_HARDWARE_NOT_FOUND           = 0x23,
209         ERR_HARDWARE_FAILURE             = 0x24,
210         ERR_CONFIGURATION_FAILURE        = 0x25,
211         ERR_INTERRUPT_CONFLICT           = 0x26,
212         ERR_INCOMPATIBLE_MAC             = 0x27,
213         ERR_INITIALIZATION_FAILED        = 0x28,
214         ERR_NO_BINDING                   = 0x29,
215         ERR_NETWORK_MAY_NOT_BE_CONNECTED = 0x2A,
216         ERR_INCOMPATIBLE_OS_VERSION      = 0x2B,
217         ERR_ALREADY_REGISTERED           = 0x2C,
218         ERR_PATH_NOT_FOUND               = 0x2D,
219         ERR_INSUFFICIENT_MEMORY          = 0x2E,
220         ERR_INFO_NOT_FOUND               = 0x2F,
221         ERR_GENERAL_FAILURE              = 0xFF
222       } NdisError;
223 
224 #define NDIS_PARAM_INTEGER   0
225 #define NDIS_PARAM_STRING    1
226 
227 #define NDIS_TX_BUF_LENGTH   8
228 #define NDIS_TD_BUF_LENGTH   1
229 #define NDIS_RX_BUF_LENGTH   8
230 
231 #define NDIS_PTR_PHYSICAL    0
232 #define NDIS_PTR_VIRTUAL     2
233 
234 #define NDIS_PATH    "PROTMAN$"
235 
236 
237 typedef struct _CommonChars {
238         WORD  tableSize;
239         BYTE  majorNdisVersion;        /* 2 - Latest version */
240         BYTE  minorNdisVersion;        /* 0                  */
241         WORD  reserved1;
242         BYTE  majorModuleVersion;
243         BYTE  minorModuleVersion;
244         DWORD moduleFlags;
245         /* 0 - Binding at upper boundary supported
246          * 1 - Binding at lower boundary supported
247          * 2 - Dynamically bound.
248          * 3-31 - Reserved, must be zero.
249          */
250         BYTE  moduleName[16];
251         BYTE  protocolLevelUpper;
252         /* 1 - MAC
253          * 2 - Data Link
254          * 3 - Network
255          * 4 - Transport
256          * 5 - Session
257          * -1 - Not specified
258          */
259         BYTE  interfaceUpper;
260         BYTE  protocolLevelLower;
261         /* 0 - Physical
262          * 1 - MAC
263          * 2 - Data Link
264          * 3 - Network
265          * 4 - Transport
266          * 5 - Session
267          * -1 - Not specified
268          */
269         BYTE  interfaceLower;
270         WORD  moduleId;
271         WORD  moduleDS;
272         SystemRequest systemRequest;
273         BYTE *serviceChars;
274         BYTE *serviceStatus;
275         BYTE *upperDispatchTable;
276         BYTE *lowerDispatchTable;
277         BYTE *reserved2;            /* Must be NULL */
278         BYTE *reserved3;            /* Must be NULL */
279       } CommonChars;
280 
281 
282 typedef struct _MulticastList {
283         WORD   maxMulticastAddresses;
284         WORD   numberMulticastAddresses;
285         BYTE   multicastAddress[16][16];
286       } MulticastList;
287 
288 
289 typedef struct _MacChars {
290         WORD   tableSize;
291         BYTE   macName[16];
292         WORD   addressLength;
293         BYTE   permanentAddress[16];
294         BYTE   currentAddress[16];
295         DWORD  currentFunctionalAddress;
296         MulticastList *multicastList;
297         DWORD  linkSpeed;
298         DWORD  serviceFlags;
299         WORD   maxFrameSize;
300         DWORD  txBufferSize;
301         WORD   txBufferAllocSize;
302         DWORD  rxBufferSize;
303         WORD   rxBufferAllocSize;
304         BYTE   ieeeVendor[3];
305         BYTE   vendorAdapter;
306         BYTE  *vendorAdapterDescription;
307         WORD   interruptLevel;
308         WORD   txQueueDepth;
309         WORD   maxDataBlocks;
310       } MacChars;
311 
312 
313 typedef struct _ProtocolChars {
314         WORD   length;
315         BYTE   name[16];
316         WORD   type;
317       } ProtocolChars;
318 
319 
320 typedef struct _MacUpperDispatch {
321         CommonChars      *backPointer;
322         Request           request;
323         TransmitChain     transmitChain;
324         TransferData      transferData;
325         ReceiveRelease    receiveRelease;
326         IndicationOn      indicationOn;
327         IndicationOff     indicationOff;
328       } MacUpperDispatch;
329 
330 
331 typedef struct _MacStatusTable {
332         WORD   tableSize;
333         DWORD  lastDiag;
334         DWORD  macStatus;
335         WORD   packetFilter;
336         BYTE  *mediaSpecificStats;
337         DWORD  lastClear;
338         DWORD  totalFramesRx;
339         DWORD  totalFramesCrc;
340         DWORD  totalBytesRx;
341         DWORD  totalDiscardBufSpaceRx;
342         DWORD  totalMulticastRx;
343         DWORD  totalBroadcastRx;
344         DWORD  obsolete1[5];
345         DWORD  totalDiscardHwErrorRx;
346         DWORD  totalFramesTx;
347         DWORD  totalBytesTx;
348         DWORD  totalMulticastTx;
349         DWORD  totalBroadcastTx;
350         DWORD  obsolete2[2];
351         DWORD  totalDiscardTimeoutTx;
352         DWORD  totalDiscardHwErrorTx;
353       } MacStatusTable;
354 
355 
356 typedef struct _ProtDispatch {
357         CommonChars *backPointer;
358         DWORD        flags;
359         /* 0 - handles non-LLC frames
360          * 1 - handles specific-LSAP LLC frames
361          * 2 - handles specific-LSAP LLC frames
362          * 3-31 - reserved must be 0
363          */
364         void  (*requestConfirm) (void);
365         void  (*transmitConfirm) (void);
366         void  (*receiveLookahead) (void);
367         void  (*indicationComplete) (void);
368         void  (*receiveChain) (void);
369         void  (*status) (void);
370       } ProtDispatch;
371 
372 
373 typedef struct _ReqBlock {
374         WORD      opcode;
375         WORD      status;
376         BYTE FAR *pointer1;
377         BYTE FAR *pointer2;
378         WORD      word1;
379       } ReqBlock;
380 
381 
382 typedef struct _TxBufDescrRec {
383         BYTE   txPtrType;
384         BYTE   dummy;
385         WORD   txDataLen;
386         BYTE  *txDataPtr;
387       } TxBufDescrRec;
388 
389 
390 typedef struct _TxBufDescr {
391         WORD          txImmedLen;
392         BYTE         *txImmedPtr;
393         WORD          txDataCount;
394         TxBufDescrRec txBufDescrRec[NDIS_TX_BUF_LENGTH];
395       } TxBufDescr;
396 
397 
398 typedef struct _TDBufDescrRec {
399         BYTE   tDPtrType;
400         BYTE   dummy;
401         WORD   tDDataLen;
402         BYTE  *tDDataPtr;
403       } TDBufDescrRec;
404 
405 
406 typedef struct _TDBufDescr {
407         WORD          tDDataCount;
408         TDBufDescrRec tDBufDescrRec[NDIS_TD_BUF_LENGTH];
409       } TDBufDescr;
410 
411 
412 typedef struct _RxBufDescrRec {
413         WORD   rxDataLen;
414         BYTE  *rxDataPtr;
415       } RxBufDescrRec;
416 
417 
418 typedef struct _RxBufDescr {
419         WORD          rxDataCount;
420         RxBufDescrRec rxBufDescrRec[NDIS_RX_BUF_LENGTH];
421       } RxBufDescr;
422 
423 
424 typedef struct _PktBuf {
425 	struct _PktBuf *nextLink;
426 	struct _PktBuf *prevLink;
427         int    handle;
428         int    length;
429         int    packetLength;
430         DWORD  sequence;
431         BYTE  *buffer;
432       } PktBuf;
433 
434 
435 typedef struct _CardHandle {
436         BYTE         moduleName[16];
437         CommonChars *common;
438       } CardHandle;
439 
440 
441 typedef struct _BindingsList {
442         WORD  numBindings;
443         BYTE  moduleName[2][16];
444       } BindingsList;
445 
446 
447 typedef struct _FailingModules {
448         BYTE  upperModuleName[16];
449         BYTE  lowerModuleName[16];
450       } FailingModules;
451 
452 
453 typedef union _HardwareAddress {
454         BYTE  bytes[6];
455         WORD  words[3];
456         struct {
457           BYTE bytes[6];
458         } addr;
459       } HardwareAddress;
460 
461 
462 typedef struct _FddiHeader {
463         BYTE             frameControl;
464         HardwareAddress  etherDestHost;
465         HardwareAddress  etherSrcHost;
466       } FddiHeader;
467 
468 
469 typedef struct _EthernetIIHeader {
470         HardwareAddress  etherDestHost;
471         HardwareAddress  etherSrcHost;
472         WORD             etherType;
473       } EthernetIIHeader;
474 
475 
476 typedef struct _Ieee802Dot5Header {
477         HardwareAddress  etherDestHost;
478         HardwareAddress  etherSrcHost;
479         BYTE             routeInfo[30];
480       } Ieee802Dot5Header;
481 
482 
483 typedef struct _Ieee802Dot2SnapHeader {
484         BYTE  dsap;                      /* 0xAA */
485         BYTE  ssap;                      /* 0xAA */
486         BYTE  control;                   /* 3    */
487         BYTE protocolId[5];
488       } Ieee802Dot2SnapHeader;
489 
490 
491 /*
492  *  Prototypes
493  */
494 extern char *NdisLastError        (void);
495 extern int   NdisOpen             (void);
496 extern int   NdisInit             (int promis);
497 extern int   NdisRegisterAndBind  (int promis);
498 extern void  NdisShutdown         (void);
499 extern void  NdisCheckMacFeatures (struct _CardHandle *card);
500 extern int   NdisSendPacket       (struct _PktBuf *pktBuf, int macId);
501 
502 /*
503  *  Assembly "glue" functions
504  */
505 extern int systemRequestGlue();
506 extern int requestConfirmGlue();
507 extern int transmitConfirmGlue();
508 extern int receiveLookaheadGlue();
509 extern int indicationCompleteGlue();
510 extern int receiveChainGlue();
511 extern int statusGlue();
512 
513 /*
514  *  IOCTL function
515  */
516 #ifdef __SMALL__
517 extern int _far NdisGetLinkage (int handle, char *data, int size);
518 #else
519 extern int NdisGetLinkage (int handle, char *data, int size);
520 #endif
521 
522 /*
523  *  NDIS callback handlers
524  */
525 CALLBACK (NdisSystemRequest     (DWORD,DWORD, WORD, WORD, WORD));
526 CALLBACK (NdisRequestConfirm    ( WORD, WORD, WORD, WORD, WORD,WORD));
527 CALLBACK (NdisTransmitConfirm   ( WORD, WORD, WORD, WORD, WORD));
528 CALLBACK (NdisReceiveLookahead  ( WORD, WORD, WORD, BYTE*, BYTE*, WORD));
529 CALLBACK (NdisReceiveChain      ( WORD, WORD, WORD, struct _RxBufDescr*, BYTE*, WORD));
530 CALLBACK (NdisStatusProc        ( WORD, WORD, BYTE*, WORD,WORD));
531 CALLBACK (NdisIndicationComplete( WORD, WORD));
532 
533 BYTE *NdisAllocStack (void);
534 void  NdisFreeStack  (BYTE*);
535 
536 #ifdef __HIGHC__
537   #define RENAME_ASM_SYM(x) pragma Alias(x,"@" #x "")  /* prepend `@' */
538   #define RENAME_C_SYM(x)   pragma Alias(x,"_" #x "")  /* prepend `_' */
539 
540   RENAME_ASM_SYM (systemRequestGlue);
541   RENAME_ASM_SYM (requestConfirmGlue);
542   RENAME_ASM_SYM (transmitConfirmGlue);
543   RENAME_ASM_SYM (receiveLookaheadGlue);
544   RENAME_ASM_SYM (indicationCompleteGlue);
545   RENAME_ASM_SYM (receiveChainGlue);
546   RENAME_ASM_SYM (statusGlue);
547   RENAME_ASM_SYM (NdisGetLinkage);
548   RENAME_C_SYM   (NdisSystemRequest);
549   RENAME_C_SYM   (NdisRequestConfirm);
550   RENAME_C_SYM   (NdisTransmitConfirm);
551   RENAME_C_SYM   (NdisReceiveLookahead);
552   RENAME_C_SYM   (NdisIndicationComplete);
553   RENAME_C_SYM   (NdisReceiveChain);
554   RENAME_C_SYM   (NdisStatusProc);
555   RENAME_C_SYM   (NdisAllocStack);
556   RENAME_C_SYM   (NdisFreeStack);
557 #endif
558 
559 #endif
560