2 * Copyright (c) 1993,1994
3 * Texas A&M University. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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
34 * David K. Hess, Douglas Lee Schales, David R. Safford
36 * Heavily modified for Metaware HighC + GNU C 2.8+
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 */
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")
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 }
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()
73 #error Unsupported compiler
85 * Protocol Manager API
87 PAS_PTR (ProtMan
, (struct _ReqBlock FAR
*, WORD
));
92 PAS_PTR (SystemRequest
, (DWORD
, DWORD
, WORD
, WORD
, WORD
));
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
));
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,
112 HARDWARE_MASK
= 0x0007,
115 DIAG_IN_PROGRESS
= 0x0020
119 STATUS_RING_STATUS
= 1,
120 STATUS_ADAPTER_CHECK
= 2,
121 STATUS_START_RESET
= 3,
122 STATUS_INTERRUPT
= 4,
128 FILTER_BROADCAST
= 2,
129 FILTER_PROMISCUOUS
= 4,
130 FILTER_SOURCE_ROUTE
= 8
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,
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
;
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
;
169 REQ_INITIATE_BIND
= 1,
171 REQ_INITIATE_PREBIND
= 3,
172 REQ_INITIATE_UNBIND
= 4,
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,
186 PM_REGISTER_STATUS
= 10
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
224 #define NDIS_PARAM_INTEGER 0
225 #define NDIS_PARAM_STRING 1
227 #define NDIS_TX_BUF_LENGTH 8
228 #define NDIS_TD_BUF_LENGTH 1
229 #define NDIS_RX_BUF_LENGTH 8
231 #define NDIS_PTR_PHYSICAL 0
232 #define NDIS_PTR_VIRTUAL 2
234 #define NDIS_PATH "PROTMAN$"
237 typedef struct _CommonChars
{
239 BYTE majorNdisVersion
; /* 2 - Latest version */
240 BYTE minorNdisVersion
; /* 0 */
242 BYTE majorModuleVersion
;
243 BYTE minorModuleVersion
;
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.
251 BYTE protocolLevelUpper
;
260 BYTE protocolLevelLower
;
272 SystemRequest systemRequest
;
275 BYTE
*upperDispatchTable
;
276 BYTE
*lowerDispatchTable
;
277 BYTE
*reserved2
; /* Must be NULL */
278 BYTE
*reserved3
; /* Must be NULL */
282 typedef struct _MulticastList
{
283 WORD maxMulticastAddresses
;
284 WORD numberMulticastAddresses
;
285 BYTE multicastAddress
[16][16];
289 typedef struct _MacChars
{
293 BYTE permanentAddress
[16];
294 BYTE currentAddress
[16];
295 DWORD currentFunctionalAddress
;
296 MulticastList
*multicastList
;
301 WORD txBufferAllocSize
;
303 WORD rxBufferAllocSize
;
306 BYTE
*vendorAdapterDescription
;
313 typedef struct _ProtocolChars
{
320 typedef struct _MacUpperDispatch
{
321 CommonChars
*backPointer
;
323 TransmitChain transmitChain
;
324 TransferData transferData
;
325 ReceiveRelease receiveRelease
;
326 IndicationOn indicationOn
;
327 IndicationOff indicationOff
;
331 typedef struct _MacStatusTable
{
336 BYTE
*mediaSpecificStats
;
339 DWORD totalFramesCrc
;
341 DWORD totalDiscardBufSpaceRx
;
342 DWORD totalMulticastRx
;
343 DWORD totalBroadcastRx
;
345 DWORD totalDiscardHwErrorRx
;
348 DWORD totalMulticastTx
;
349 DWORD totalBroadcastTx
;
351 DWORD totalDiscardTimeoutTx
;
352 DWORD totalDiscardHwErrorTx
;
356 typedef struct _ProtDispatch
{
357 CommonChars
*backPointer
;
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
364 void (*requestConfirm
) (void);
365 void (*transmitConfirm
) (void);
366 void (*receiveLookahead
) (void);
367 void (*indicationComplete
) (void);
368 void (*receiveChain
) (void);
369 void (*status
) (void);
373 typedef struct _ReqBlock
{
382 typedef struct _TxBufDescrRec
{
390 typedef struct _TxBufDescr
{
394 TxBufDescrRec txBufDescrRec
[NDIS_TX_BUF_LENGTH
];
398 typedef struct _TDBufDescrRec
{
406 typedef struct _TDBufDescr
{
408 TDBufDescrRec tDBufDescrRec
[NDIS_TD_BUF_LENGTH
];
412 typedef struct _RxBufDescrRec
{
418 typedef struct _RxBufDescr
{
420 RxBufDescrRec rxBufDescrRec
[NDIS_RX_BUF_LENGTH
];
424 typedef struct _PktBuf
{
425 struct _PktBuf
*nextLink
;
426 struct _PktBuf
*prevLink
;
435 typedef struct _CardHandle
{
441 typedef struct _BindingsList
{
443 BYTE moduleName
[2][16];
447 typedef struct _FailingModules
{
448 BYTE upperModuleName
[16];
449 BYTE lowerModuleName
[16];
453 typedef union _HardwareAddress
{
462 typedef struct _FddiHeader
{
464 HardwareAddress etherDestHost
;
465 HardwareAddress etherSrcHost
;
469 typedef struct _EthernetIIHeader
{
470 HardwareAddress etherDestHost
;
471 HardwareAddress etherSrcHost
;
476 typedef struct _Ieee802Dot5Header
{
477 HardwareAddress etherDestHost
;
478 HardwareAddress etherSrcHost
;
483 typedef struct _Ieee802Dot2SnapHeader
{
484 BYTE dsap
; /* 0xAA */
485 BYTE ssap
; /* 0xAA */
486 BYTE control
; /* 3 */
488 } Ieee802Dot2SnapHeader
;
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
);
503 * Assembly "glue" functions
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();
517 extern int _far
NdisGetLinkage (int handle
, char *data
, int size
);
519 extern int NdisGetLinkage (int handle
, char *data
, int size
);
523 * NDIS callback handlers
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
));
533 BYTE
*NdisAllocStack (void);
534 void NdisFreeStack (BYTE
*);
537 #define RENAME_ASM_SYM(x) pragma Alias(x,"@" #x "") /* prepend `@' */
538 #define RENAME_C_SYM(x) pragma Alias(x,"_" #x "") /* prepend `_' */
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
);