Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1237 lines
37 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corp., 1993 **/
  4. /**********************************************************************/
  5. /*
  6. vxdprocs.h
  7. This file contains VxD specific types/manifests for the NBT driver
  8. FILE HISTORY:
  9. Johnl 29-Mar-1993 Created
  10. MohsinA, 17-Nov-96. Make it work on Memphis.
  11. Enough confusion, added DEBUG_PRINT.
  12. */
  13. #ifndef _VXDPROCS_H_
  14. #define _VXDPROCS_H_
  15. //--------------------------------------------------------------------
  16. //
  17. // Define some ndis stuff here because tdivxd.h needs it however we can't
  18. // include ndis3\inc\ndis.h because it conflicts with ntconfig.h and we
  19. // can't take out ntconfig.h because it has definitions needed by other
  20. // header files...grrrr....
  21. //
  22. #ifdef CHICAGO
  23. #ifndef NDIS_STDCALL
  24. #define NDIS_STDCALL 1
  25. #endif
  26. #include <vmm.h>
  27. #undef PAGE
  28. #define PAGE _PTEXT
  29. #endif
  30. #ifdef NDIS_STDCALL
  31. #define NDIS_API __stdcall
  32. #else
  33. #define NDIS_API
  34. #endif
  35. //
  36. // Ndis Buffer
  37. //
  38. #define BUFFER_POOL_SIGN (UINT)0X4C50424E /* NBPL */
  39. #define BUFFER_SIGN (UINT)0x4655424e /* NBUF */
  40. typedef INT NDIS_SPIN_LOCK, * PNDIS_SPIN_LOCK;
  41. struct _NDIS_BUFFER;
  42. typedef struct _NDIS_BUFFER_POOL {
  43. UINT Signature; //character signature for debug "NBPL"
  44. NDIS_SPIN_LOCK SpinLock; //to serialize access to the buffer pool
  45. struct _NDIS_BUFFER *FreeList; //linked list of free slots in pool
  46. UINT BufferLength; //amount needed for each buffer descriptor
  47. UCHAR Buffer[1]; //actual pool memory
  48. } NDIS_BUFFER_POOL, * PNDIS_BUFFER_POOL;
  49. #ifdef NDIS_STDCALL
  50. typedef struct _NDIS_BUFFER {
  51. struct _NDIS_BUFFER *Next; //pointer to next buffer descriptor in chain
  52. PVOID VirtualAddress; //linear address of this buffer
  53. PNDIS_BUFFER_POOL Pool; //pointer to pool so we can free to correct pool
  54. UINT Length; //length of this buffer
  55. UINT Signature; //character signature for debug "NBUF"
  56. } NDIS_BUFFER, * PNDIS_BUFFER;
  57. #else
  58. typedef struct _NDIS_BUFFER {
  59. UINT Signature; //character signature for debug "NBUF"
  60. struct _NDIS_BUFFER *Next; //pointer to next buffer descriptor in chain
  61. PVOID VirtualAddress; //linear address of this buffer
  62. PNDIS_BUFFER_POOL Pool; //pointer to pool so we can free to correct pool
  63. UINT Length; //length of this buffer
  64. } NDIS_BUFFER, * PNDIS_BUFFER;
  65. #endif
  66. #define NDIS_STATUS_SUCCESS 0 // Used by CTEinitBlockStruc macro
  67. //
  68. // Possible data types
  69. //
  70. typedef enum _NDIS_PARAMETER_TYPE {
  71. NdisParameterInteger,
  72. NdisParameterHexInteger,
  73. NdisParameterString,
  74. NdisParameterMultiString
  75. } NDIS_PARAMETER_TYPE, *PNDIS_PARAMETER_TYPE;
  76. typedef struct _STRING {
  77. USHORT Length;
  78. USHORT MaximumLength;
  79. PUCHAR Buffer;
  80. } STRING, *PSTRING;
  81. typedef STRING NDIS_STRING, *PNDIS_STRING;
  82. typedef PVOID NDIS_HANDLE, *PNDIS_HANDLE;
  83. //
  84. // To store configuration information
  85. //
  86. typedef struct _NDIS_CONFIGURATION_PARAMETER {
  87. NDIS_PARAMETER_TYPE ParameterType;
  88. union {
  89. ULONG IntegerData;
  90. NDIS_STRING StringData;
  91. } ParameterData;
  92. } NDIS_CONFIGURATION_PARAMETER, *PNDIS_CONFIGURATION_PARAMETER;
  93. typedef ULONG NDIS_STATUS;
  94. typedef NDIS_STATUS *PNDIS_STATUS;
  95. VOID NDIS_API
  96. NdisOpenProtocolConfiguration(
  97. OUT PNDIS_STATUS Status,
  98. OUT PNDIS_HANDLE ConfigurationHandle,
  99. IN PNDIS_STRING ProtocolName
  100. );
  101. VOID NDIS_API
  102. NdisReadConfiguration(
  103. OUT PNDIS_STATUS Status,
  104. OUT PNDIS_CONFIGURATION_PARAMETER *ParameterValue,
  105. IN NDIS_HANDLE ConfigurationHandle,
  106. IN PNDIS_STRING Parameter,
  107. IN NDIS_PARAMETER_TYPE ParameterType
  108. );
  109. VOID NDIS_API
  110. NdisCloseConfiguration(
  111. IN NDIS_HANDLE ConfigurationHandle
  112. );
  113. //--------------------------------------------------------------------
  114. #include <tdivxd.h>
  115. #include <tdistat.h>
  116. //--------------------------------------------------------------------
  117. //
  118. // Initializes a TA_NETBIOS_ADDRESS structure
  119. //
  120. // ptanb - Pointer to the TA_NETBIOS_ADDRESS
  121. // pName - Pointer to the netbios name this address structure represents
  122. //
  123. #define InitNBAddress( ptanb, pName ) \
  124. { \
  125. (ptanb)->TAAddressCount = 1 ; \
  126. (ptanb)->Address[0].AddressLength = sizeof( TDI_ADDRESS_NETBIOS );\
  127. (ptanb)->Address[0].AddressType = TDI_ADDRESS_TYPE_NETBIOS ; \
  128. (ptanb)->Address[0].Address[0].NetbiosNameType = 0 ; \
  129. CTEMemCopy( (ptanb)->Address[0].Address[0].NetbiosName, \
  130. pName, \
  131. NCBNAMSZ ) ; \
  132. }
  133. //
  134. // Initializes a TDI_CONNECTION_INFORMATION structure for Netbios
  135. //
  136. // pConnInfo - Pointer to TDI_CONNECTION_INFORMATION structure
  137. // ptanb - same as for InitNBAddress
  138. // pName - same as for InitNBAddress
  139. //
  140. #define InitNBTDIConnectInfo( pConnInfo, ptanb, pName ) \
  141. { \
  142. InitNBAddress( ((PTA_NETBIOS_ADDRESS)ptanb), (pName) ) ; \
  143. (pConnInfo)->RemoteAddressLength = sizeof( TA_NETBIOS_ADDRESS ) ; \
  144. (pConnInfo)->RemoteAddress = (ptanb) ; \
  145. }
  146. //
  147. // Initializes an NDIS buffer (doesn't allocate memory)
  148. //
  149. // pndisBuff - Pointer to NDIS buffer to initialize
  150. // pvData - Pointer to buffer data
  151. // cbLen - Length of user data (in bytes)
  152. // pndisBuffnext - Next NDIS buffer in chain (or NULL if last)
  153. //
  154. #define InitNDISBuff( pndisBuff, pvData, cbLen, pndisBuffNext ) \
  155. { \
  156. (pndisBuff)->Signature = BUFFER_SIGN ; \
  157. (pndisBuff)->Next = (pndisBuffNext) ; \
  158. (pndisBuff)->Length = (cbLen) ; \
  159. (pndisBuff)->VirtualAddress = (pvData) ; \
  160. (pndisBuff)->Pool = NULL ; \
  161. }
  162. //
  163. // Proper NCB error type
  164. //
  165. typedef uchar NCBERR ;
  166. //
  167. // This is a private NCB command used for adding name number 0 to the
  168. // name table. It is submitted directly by the Nbt driver during
  169. // initialization. Note that if a client tries to submit an NCB with
  170. // this command we'll return illegal command.
  171. //
  172. #define NCBADD_PERMANENT_NAME 0xff
  173. //
  174. // Last valid NCB session or name number
  175. //
  176. #define MAX_NCB_NUMS 254
  177. //
  178. // When a send or receive tick count reaches this value, it's timed out
  179. //
  180. #define NCB_TIMED_OUT 1
  181. //
  182. // A timeout of this value means the NCB will never timeout
  183. //
  184. #define NCB_INFINITE_TIME_OUT 0
  185. //--------------------------------------------------------------------
  186. //
  187. // Receieve session data context, set in VxdReceive.
  188. // Allocated on the heap (too big for ncb_reserve).
  189. //
  190. #define RCVCONT_SIGN 0x1900BEEF
  191. typedef struct _RCV_CONTEXT
  192. {
  193. union
  194. {
  195. LIST_ENTRY ListEntry ; // Used when NCB is put on RcvHead
  196. EventRcvBuffer evrcvbuf ; // Used for doing actual receive
  197. // (after removed from RcvHead)
  198. } ;
  199. UINT Signature ;
  200. tLOWERCONNECTION * pLowerConnId ; // Where data is arriving from
  201. NCB * pNCB ; // Pointer to NCB
  202. NDIS_BUFFER ndisBuff ; // Transport fills this buffer
  203. UCHAR RTO ; // 1/2 second ticks till timeout
  204. USHORT usFlags; // in case different from default
  205. } RCV_CONTEXT, *PRCV_CONTEXT ;
  206. //
  207. // Allocate, initialize and free a receive context structure
  208. //
  209. #define GetRcvContext( ppContext ) \
  210. (STATUS_SUCCESS == NbtGetBuffer( &NbtConfig.RcvContextFreeList, \
  211. (PLIST_ENTRY*)ppContext, \
  212. eNBT_RCV_CONTEXT ))
  213. #define FreeRcvContext( pRcvContext ) \
  214. { \
  215. ASSERT( (pRcvContext)->Signature == RCVCONT_SIGN ) ; \
  216. InsertTailList( &NbtConfig.RcvContextFreeList, \
  217. &(pRcvContext)->ListEntry ) ; \
  218. }
  219. #define InitRcvContext( pRcvCont, pRcvLowerConn, pRcvNCB ) \
  220. { \
  221. pRcvCont->Signature = RCVCONT_SIGN ; \
  222. pRcvCont->pLowerConnId= pRcvLowerConn ; \
  223. pRcvCont->pNCB = pRcvNCB ; \
  224. }
  225. //--------------------------------------------------------------------
  226. //
  227. // Send session data context, set in VxdSend.
  228. // Stored in ncb_reserve
  229. //
  230. typedef struct _SEND_CONTEXT
  231. {
  232. LIST_ENTRY ListEntry ; // Kept on timeout queue
  233. tSESSIONHDR * pHdr ; // Allocated session header
  234. UCHAR STO ; // 1/2 second ticks till timeout
  235. } SEND_CONTEXT, *PSEND_CONTEXT ;
  236. #define GetSessionHdr( ppHdr ) \
  237. (STATUS_SUCCESS == NbtGetBuffer( &NbtConfig.SessionBufferFreeList, \
  238. (PLIST_ENTRY*)ppHdr, \
  239. eNBT_SESSION_HDR ))
  240. #define FreeSessionHdr( pSessionHdr ) \
  241. { \
  242. InsertTailList( &NbtConfig.SessionBufferFreeList, \
  243. (PLIST_ENTRY) pSessionHdr ) ; \
  244. }
  245. //--------------------------------------------------------------------
  246. //
  247. // TDI Send context (used by TdiSend)
  248. //
  249. // When handling the datagram completion routines, we need to set up
  250. // another completion routine. We store the old completion routine
  251. // in this structure
  252. //
  253. typedef union _TDI_SEND_CONTEXT
  254. {
  255. LIST_ENTRY ListEntry ; // Only used when on buffer free list
  256. struct
  257. {
  258. PVOID NewContext ;
  259. NBT_COMPLETION OldRequestNotifyObject ;
  260. PVOID OldContext ;
  261. NDIS_BUFFER ndisHdr ; // Generally NBT message
  262. NDIS_BUFFER ndisData1 ; // Data or SMB
  263. NDIS_BUFFER ndisData2 ; // Data if ndisData1 is an SMB
  264. } ;
  265. } TDI_SEND_CONTEXT, * PTDI_SEND_CONTEXT ;
  266. //
  267. // Allocates a TDI_SEND_CONTEXT
  268. //
  269. #define GetSendContext( ppContext ) \
  270. (STATUS_SUCCESS == NbtGetBuffer( &NbtConfig.SendContextFreeList, \
  271. (PLIST_ENTRY*)ppContext, \
  272. eNBT_SEND_CONTEXT ))
  273. //
  274. // Frees a send context structure and its allocated memory
  275. //
  276. #define FreeSendContext( psendCont ) \
  277. { \
  278. InsertTailList( &NbtConfig.SendContextFreeList, \
  279. &(psendCont)->ListEntry ) ; \
  280. }
  281. //--------------------------------------------------------------------
  282. //
  283. // Lana related stuff
  284. //
  285. #define NBT_MAX_LANAS 8
  286. typedef struct
  287. {
  288. tDEVICECONTEXT * pDeviceContext ; // Adapter for this Lana
  289. } LANA_ENTRY, *PLANA_ENTRY ;
  290. extern LANA_ENTRY LanaTable[NBT_MAX_LANAS] ;
  291. //--------------------------------------------------------------------
  292. //
  293. // Procedures in ncb.c
  294. //
  295. //
  296. NCBERR MapTDIStatus2NCBErr( TDI_STATUS status ) ;
  297. //
  298. // Get the correct adapter for this NCBs Lana
  299. //
  300. tDEVICECONTEXT *
  301. GetDeviceContext(
  302. NCB * pNCB
  303. );
  304. BOOL
  305. NbtWouldLoopback(
  306. ULONG IpAddr
  307. );
  308. extern BOOL fNCBCompleted ; // Wait NCB completed before returning to submitter
  309. extern BOOL fWaitingForNCB ; // We are blocked waiting for a Wait NCB to complete
  310. extern CTEBlockStruc WaitNCBBlock ; // Wait on this until signaled in completion
  311. extern UCHAR LanaBase ;
  312. #define IPINFO_BUFF_SIZE (sizeof(IPInfo) + MAX_IP_NETS * sizeof(NetInfo))
  313. //--------------------------------------------------------------------
  314. //
  315. // externs from fileio.c
  316. //
  317. extern PUCHAR pFileBuff;
  318. extern PUCHAR pFilePath;
  319. //--------------------------------------------------------------------
  320. //
  321. // TDI Dispatch table (exported from vtdi.386)
  322. //
  323. extern TDIDispatchTable * TdiDispatch ;
  324. //
  325. // Wrappers for interfacing to the TDI Dispatch table
  326. //
  327. #define TdiVxdOpenAddress TdiDispatch->TdiOpenAddressEntry
  328. #define TdiVxdCloseAddress TdiDispatch->TdiCloseAddressEntry
  329. #define TdiVxdOpenConnection TdiDispatch->TdiOpenConnectionEntry
  330. #define TdiVxdCloseConnection TdiDispatch->TdiCloseConnectionEntry
  331. #define TdiVxdAssociateAddress TdiDispatch->TdiAssociateAddressEntry
  332. #define TdiVxdDisAssociateAddress TdiDispatch->TdiDisAssociateAddressEntry
  333. #define TdiVxdConnect TdiDispatch->TdiConnectEntry
  334. #define TdiVxdDisconnect TdiDispatch->TdiDisconnectEntry
  335. #define TdiVxdListen TdiDispatch->TdiListenEntry
  336. #define TdiVxdAccept TdiDispatch->TdiAcceptEntry
  337. #define TdiVxdReceive TdiDispatch->TdiReceiveEntry
  338. #define TdiVxdSend TdiDispatch->TdiSendEntry
  339. #define TdiVxdSendDatagram TdiDispatch->TdiSendDatagramEntry
  340. #define TdiVxdReceiveDatagram TdiDispatch->TdiReceiveDatagramEntry
  341. #define TdiVxdSetEventHandler TdiDispatch->TdiSetEventEntry
  342. #define TdiVxdQueryInformationEx TdiDispatch->TdiQueryInformationExEntry
  343. #define TdiVxdSetInformationEx TdiDispatch->TdiSetInformationExEntry
  344. //--------------------------------------------------------------------
  345. //
  346. // NTSTATUS to TDI_STATUS mappings.
  347. //
  348. // Rather then convert from NTSTATUS to TDI_STATUS (then sometimes back to
  349. // NTSTATUS) we'll just use TDI_STATUS codes everywhere (and map to NCBERR
  350. // when returning codes to the Netbios interface).
  351. //
  352. #undef STATUS_SUCCESS
  353. #undef STATUS_INSUFFICIENT_RESOURCES
  354. #undef STATUS_ADDRESS_ALREADY_EXISTS
  355. #undef STATUS_TOO_MANY_ADDRESSES
  356. #undef STATUS_INVALID_ADDRESS
  357. #undef STATUS_BUFFER_OVERFLOW
  358. #undef STATUS_TRANSACTION_INVALID_TYPE
  359. #undef STATUS_TRANSACTION_INVALID_ID
  360. #undef STATUS_EVENT_DONE
  361. #undef STATUS_TRANSACTION_TIMED_OUT
  362. #undef STATUS_EVENT_PENDING
  363. #undef STATUS_PENDING
  364. #undef STATUS_BAD_NETWORK_NAME
  365. #undef STATUS_REQUEST_NOT_ACCEPTED
  366. #undef STATUS_INVALID_CONNECTION
  367. #undef STATUS_DATA_NOT_ACCEPTED
  368. #undef STATUS_MORE_PROCESSING_REQUIRED
  369. #undef STATUS_IO_TIMEOUT
  370. #undef STATUS_TIMEOUT
  371. #undef STATUS_GRACEFUL_DISCONNECT
  372. #undef STATUS_CONNECTION_RESET
  373. #define STATUS_SUCCESS TDI_SUCCESS
  374. //#define STATUS_UNSUCCESSFUL
  375. #define STATUS_MORE_PROCESSING_REQUIRED TDI_MORE_PROCESSING
  376. #define STATUS_BAD_NETWORK_NAME TDI_INVALID_CONNECTION
  377. #define STATUS_DATA_NOT_ACCEPTED TDI_NOT_ACCEPTED
  378. //#define STATUS_REMOTE_NOT_LISTENING
  379. //#define STATUS_DUPLICATE_NAME
  380. //#define STATUS_INVALID_PARAMETER
  381. //#define STATUS_OBJECT_NAME_COLLISION Duplicate Name
  382. //#define STATUS_SHARING_VIOLATION Duplicate Name
  383. #define STATUS_CONNECTION_INVALID TDI_INVALID_CONNECTION
  384. #define STATUS_INVALID_CONNECTION TDI_INVALID_CONNECTION
  385. #define STATUS_INSUFFICIENT_RESOURCES TDI_NO_RESOURCES
  386. #define STATUS_ADDRESS_ALREADY_EXISTS TDI_ADDR_IN_USE
  387. #define STATUS_TOO_MANY_ADDRESSES TDI_NO_FREE_ADDR
  388. #define STATUS_INVALID_ADDRESS TDI_ADDR_INVALID
  389. #define STATUS_BUFFER_OVERFLOW TDI_BUFFER_OVERFLOW
  390. #define STATUS_TRANSACTION_INVALID_TYPE TDI_BAD_EVENT_TYPE
  391. #define STATUS_TRANSACTION_INVALID_ID TDI_BAD_OPTION // ??
  392. #define STATUS_EVENT_DONE TDI_EVENT_DONE
  393. #define STATUS_TRANSACTION_TIMED_OUT TDI_TIMED_OUT
  394. #define STATUS_IO_TIMEOUT TDI_TIMED_OUT
  395. #define STATUS_TIMEOUT TDI_TIMED_OUT
  396. #define STATUS_EVENT_PENDING TDI_PENDING
  397. #define STATUS_PENDING TDI_PENDING
  398. #define STATUS_GRACEFUL_DISCONNECT TDI_GRACEFUL_DISC
  399. #define STATUS_CONNECTION_RESET TDI_CONNECTION_RESET
  400. #define STATUS_INVALID_ADDRESS_COMPONENT TDI_BAD_ADDR
  401. //
  402. // This is the "Name deregistered but not deleted because of
  403. // active sessions" error code.
  404. //
  405. #define STATUS_NRC_ACTSES 0xCA000001
  406. //
  407. // The NT_SUCCESS macro looks at the high bytes of the errr code which isn't
  408. // appropriate for our mapping to TDI_STATUS error codes
  409. //
  410. #undef NT_SUCCESS
  411. #define NT_SUCCESS(err) ((err==TDI_SUCCESS)||(err==TDI_PENDING))
  412. //--------------------------------------------------------------------
  413. //
  414. // General porting macros
  415. //
  416. //
  417. //--------------------------------------------------------------------
  418. //
  419. // Note that the ExInterlocked* routines (in ntos\ex\i386) do a spinlock
  420. // for MP machines. Since we aren't MP we shouldn't need the spin lock.
  421. // We shouldn't need to disable interrupts either.
  422. //
  423. #define ExInterlockedInsertTailList(list, entry, spinlock ) \
  424. InsertTailList( (list), (entry) )
  425. #define ExInterlockedInsertHeadList(list, entry, spinlock ) \
  426. InsertHeadList( (list), (entry) )
  427. //
  428. // These two definitions must be kept keep a couple of NT macros use
  429. // the ExInterlocked* macros
  430. //
  431. #ifdef InterlockedIncrement
  432. #undef InterlockedIncrement
  433. #endif
  434. #ifdef InterlockedIncrementLong
  435. #undef InterlockedIncrementLong
  436. #endif
  437. #define InterlockedIncrement(n) \
  438. CTEInterlockedIncrementLong( n )
  439. #define InterlockedIncrementLong InterlockedIncrement
  440. #ifdef InterlockedDecrement
  441. #undef InterlockedDecrement
  442. #endif
  443. #ifdef InterlockedDecrementLong
  444. #undef InterlockedDecrementLong
  445. #endif
  446. #define InterlockedDecrement(n) \
  447. CTEInterlockedDecrementLong( n )
  448. #define InterlockedDecrementLong InterlockedDecrement
  449. //--------------------------------------------------------------------
  450. //
  451. // Debug helper macros
  452. //
  453. #undef ASSERT
  454. #undef ASSERTMSG
  455. #ifdef DEBUG
  456. #include <vxddebug.h>
  457. #endif
  458. #ifdef DBG_PRINT
  459. //
  460. // Debug output Definitions and functions
  461. //
  462. #define DBGFLAG_ERROR (0x00000001)
  463. #define DBGFLAG_REG (0x00000002) // Informative Printouts
  464. #define DBGFLAG_ALL (0x00000004) // Everything else
  465. #define DBGFLAG_LMHOST (0x00000008)
  466. #define DBGFLAG_KDPRINTS (0x00000010) // Jim's KdPrint output
  467. #define DBGFLAG_AUX_OUTPUT (0x00000020)
  468. extern DWORD NbtDebug ;
  469. extern char DBOut[4096] ;
  470. extern char szOutput[1024];
  471. extern int iCurPos ;
  472. extern BYTE abVecTbl[256];
  473. void VxdPrintf ( char * pszFormat, ... );
  474. int VxdSprintf ( char * pszStr, char * pszFmt, ... );
  475. void VxdDebugOutput ( char * pszMessage );
  476. void NbtPrintDebug ( char * ) ;
  477. // ========================================================================
  478. #define VXD_PRINT(args) \
  479. if ( NbtDebug & DBGFLAG_REG ) \
  480. VxdPrintf args
  481. #define DEBUG_OUTPUT(x) \
  482. if ( NbtDebug & DBGFLAG_REG ) \
  483. VxdDebugOutput(x)
  484. #undef KdPrint
  485. #define KdPrint( s ) \
  486. if ( NbtDebug & DBGFLAG_KDPRINTS ) \
  487. { \
  488. VxdPrintf s ; \
  489. }else{}
  490. // eg. DEBUG_PRINT(("Error %d, retry.\n", err ));
  491. #define DEBUG_PRINT( S ) \
  492. if ( NbtDebug & DBGFLAG_REG ) \
  493. VxdPrintf S
  494. // eg. PRINT_IPADDR( "Cannot find:", htonl(ipaddress) );
  495. #define PRINT_IPADDR( S, IP ) \
  496. if ( NbtDebug & DBGFLAG_REG ) \
  497. VxdPrintf( S "%d.%d.%d.%d\n", \
  498. (IP>>0)&0xff,(IP>>8)&0xff,(IP>>16)&0xff,(IP>>24)&0xff )
  499. // ========================================================================
  500. #define DbgPrint( s ) \
  501. if ( NbtDebug & DBGFLAG_ALL ) \
  502. { \
  503. VxdSprintf( szOutput, s ) ; \
  504. VxdCopyToDBOut() ; \
  505. NbtPrintDebug( DBOut+iCurPos ) ; \
  506. }else{}
  507. #define DbgPrintNum( n ) \
  508. if ( NbtDebug & DBGFLAG_ALL ) \
  509. { \
  510. VxdSprintf( szOutput, "%d", n ) ; \
  511. VxdCopyToDBOut() ; \
  512. NbtPrintDebug( DBOut+iCurPos ) ; \
  513. }else{}
  514. // ========================================================================
  515. // Conditional print routines
  516. //
  517. #define CDbgPrint( flag, s ) \
  518. if ( NbtDebug & (flag) ) \
  519. { \
  520. VxdSprintf( szOutput, s ); \
  521. VxdCopyToDBOut() ; \
  522. NbtPrintDebug( DBOut+iCurPos ) ; \
  523. }else{}
  524. #define CDbgPrintNum( flag, n ) \
  525. if ( NbtDebug & (flag) ) \
  526. { \
  527. VxdSprintf( szOutput, "%d", n ) ; \
  528. VxdCopyToDBOut() ; \
  529. NbtPrintDebug( DBOut+iCurPos ) ; \
  530. }else{}
  531. extern void NbtCTEPrint( char * );
  532. #else
  533. //
  534. // No debug output.
  535. //
  536. #define IF_DEBUG(flag) if(0)
  537. #define VXD_PRINT(args) /* Nothing */
  538. #define DEBUG_OUTPUT(x) /* Nothing */
  539. #undef KdPrint
  540. #define KdPrint( s ) /* Nothing */
  541. #define DEBUG_PRINT( S ) /* Nothing */
  542. #define PRINT_IPADDR( S, IP ) /* Nothing */
  543. #define DbgPrint( s ) /* Nothing */
  544. #define DbgPrintNum( n ) /* Nothing */
  545. #define CDbgPrint( flag, s ) /* Nothing */
  546. #define CDbgPrintNum( flag, n ) /* Nothing */
  547. #define NbtCTEPrint( s ) /* Nothing */
  548. #endif
  549. #ifdef DEBUG
  550. // ========================================================================
  551. #define DbgBreak() _asm int 3
  552. #define ASSERT( exp ) VXD_ASSERT( exp )
  553. #define ASSERTMSG( msg, exp ) VXD_ASSERT( exp )
  554. //
  555. // REQUIRE is an ASSERT that keeps the expression under non-debug
  556. // builds
  557. //
  558. #define REQUIRE( exp ) ASSERT( exp )
  559. #ifdef DBG_PRINT
  560. //
  561. // Consistency checks of the interrupt vector table to help watch
  562. // for NULL pointer writes
  563. //
  564. #define INIT_NULL_PTR_CHECK() memcpy( abVecTbl, 0, sizeof( abVecTbl ))
  565. #define CHECK_MEM() if(sizeof(abVecTbl) \
  566. != VxdRtlCompareMemory( 0, abVecTbl, sizeof(abVecTbl))){ \
  567. DEBUG_PRINT(("Vector table corrupt at %d\n", \
  568. VxdRtlCompareMemory( 0, abVecTbl, sizeof(abVecTbl) )));\
  569. _asm int 3 \
  570. }else{} \
  571. CTECheckMem(__FILE__) ;
  572. #else
  573. #define INIT_NULL_PTR_CHECK() /* Nothing */
  574. #define CHECK_MEM() /* Nothing */
  575. #endif // DBG_PRINT
  576. #else
  577. #define DbgBreak() /* Nothing */
  578. #define ASSERT( exp ) { ; }
  579. #define ASSERTMSG( msg, exp ) { ; }
  580. #define REQUIRE( exp ) { exp ; }
  581. #define INIT_NULL_PTR_CHECK() /* Nothing */
  582. #define CHECK_MEM() /* Nothing */
  583. #endif
  584. //---------------------------------------------------------------------
  585. //
  586. // FROM tdihndlr.c
  587. //
  588. TDI_STATUS
  589. TdiReceiveHandler (
  590. IN PVOID ReceiveEventContext,
  591. IN PVOID ConnectionContext,
  592. IN USHORT ReceiveFlags,
  593. IN ULONG BytesIndicated,
  594. IN ULONG BytesAvailable,
  595. OUT PULONG BytesTaken,
  596. IN PVOID Data,
  597. EventRcvBuffer * pevrcvbuf
  598. );
  599. TDI_STATUS
  600. ReceiveAnyHandler ( // Handles NCBRCVANY commands, is
  601. IN PVOID ReceiveEventContext, // called after all other receive
  602. IN PVOID ConnectionContext, // handlers
  603. IN USHORT ReceiveFlags,
  604. IN ULONG BytesIndicated,
  605. IN ULONG BytesAvailable,
  606. OUT PULONG BytesTaken,
  607. IN PVOID Data,
  608. PVOID * ppBuffer // Pointer to ListEntry of RCV_CONTEXT
  609. ) ;
  610. TDI_STATUS
  611. VxdDisconnectHandler ( // Cleans up Netbios stuff for remote
  612. IN PVOID DisconnectEventContext, // disconnects
  613. IN PVOID ConnectionContext,
  614. IN PVOID DisconnectData,
  615. IN ULONG DisconnectInformationLength,
  616. IN PVOID pDisconnectInformation,
  617. IN ULONG DisconnectIndicators
  618. ) ;
  619. VOID
  620. CompletionRcv(
  621. IN PVOID pContext,
  622. IN uint tdistatus,
  623. IN uint BytesRcvd
  624. );
  625. TDI_STATUS
  626. TdiConnectHandler (
  627. IN PVOID pConnectEventContext,
  628. IN int RemoteAddressLength,
  629. IN PVOID pRemoteAddress,
  630. IN int UserDataLength,
  631. IN PVOID pUserData,
  632. IN int OptionsLength,
  633. IN PVOID pOptions,
  634. IN PVOID * pAcceptingID,
  635. IN ConnectEventInfo * pEventInfo
  636. );
  637. TDI_STATUS
  638. TdiDisconnectHandler (
  639. PVOID EventContext,
  640. PVOID ConnectionContext,
  641. ULONG DisconnectDataLength,
  642. PVOID DisconnectData,
  643. ULONG DisconnectInformationLength,
  644. PVOID DisconnectInformation,
  645. ULONG DisconnectIndicators // Is this the Flags field?
  646. );
  647. TDI_STATUS
  648. TdiRcvDatagramHandler(
  649. IN PVOID pDgramEventContext,
  650. IN int SourceAddressLength,
  651. IN PVOID pSourceAddress,
  652. IN int OptionsLength,
  653. IN PVOID pOptions,
  654. IN UINT ReceiveDatagramFlags,
  655. IN ULONG BytesIndicated,
  656. IN ULONG BytesAvailable,
  657. OUT ULONG *pBytesTaken,
  658. IN PVOID pTsdu,
  659. OUT EventRcvBuffer * * ppBuffer //OUT PIRP *pIoRequestPacket
  660. );
  661. TDI_STATUS
  662. TdiRcvNameSrvHandler(
  663. IN PVOID pDgramEventContext,
  664. IN int SourceAddressLength,
  665. IN PVOID pSourceAddress,
  666. IN int OptionsLength,
  667. IN PVOID pOptions,
  668. IN UINT ReceiveDatagramFlags,
  669. IN ULONG BytesIndicated,
  670. IN ULONG BytesAvailable,
  671. OUT ULONG *pBytesTaken,
  672. IN PVOID pTsdu,
  673. OUT EventRcvBuffer * * ppBuffer //OUT PIRP *pIoRequestPacket
  674. );
  675. TDI_STATUS
  676. TdiErrorHandler (
  677. IN PVOID Context,
  678. IN ULONG Status
  679. );
  680. VOID
  681. CompletionRcvDgram(
  682. IN PVOID Context,
  683. IN UINT tdistatus,
  684. IN UINT RcvdSize
  685. ) ;
  686. //---------------------------------------------------------------------
  687. //
  688. // FROM init.c
  689. //
  690. PVOID
  691. CTEAllocInitMem(
  692. IN ULONG cbBuff ) ;
  693. NTSTATUS
  694. VxdReadIniString(
  695. IN LPTSTR pchKeyName,
  696. IN OUT LPTSTR * ppStringBuff
  697. ) ;
  698. NTSTATUS CreateDeviceObject(
  699. IN tNBTCONFIG *pConfig,
  700. IN ULONG IpAddr,
  701. IN ULONG IpMask,
  702. #ifdef MULTIPLE_WINS
  703. IN PULONG pIpNameServers,
  704. #else
  705. IN ULONG IpNameServer,
  706. IN ULONG IpBackupServer,
  707. #endif
  708. IN ULONG IpDnsServer,
  709. IN ULONG IpDnsBackupServer,
  710. IN UCHAR MacAddr[],
  711. IN UCHAR IpIndex
  712. ) ;
  713. void GetNameServerAddress( ULONG IpAddr,
  714. #ifdef WINS_PER_ADAPTER
  715. PULONG pIpNameServer,
  716. PNDIS_STRING AdapterName);
  717. #else
  718. PULONG pIpNameServer);
  719. #endif // WINS_PER_ADAPTER
  720. void GetDnsServerAddress( ULONG IpAddr,
  721. PULONG pIpNameServer);
  722. #ifdef MULTIPLE_WINS
  723. #define COUNT_NS_ADDR 2+MAX_NUM_OTHER_NAME_SERVERS // Maximum number of name server addresses
  724. #else
  725. #define COUNT_NS_ADDR 4 // Maximum number of name server addresses
  726. #endif
  727. //---------------------------------------------------------------------
  728. //
  729. // FROM vxdfile.asm
  730. //
  731. HANDLE
  732. VxdFileOpen(
  733. IN char * pchFile ) ;
  734. ULONG
  735. VxdFileRead(
  736. IN HANDLE hFile,
  737. IN ULONG BytesToRead,
  738. IN BYTE * pBuff ) ;
  739. VOID
  740. VxdFileClose(
  741. IN HANDLE hFile ) ;
  742. PUCHAR
  743. VxdWindowsPath(
  744. );
  745. //---------------------------------------------------------------------
  746. //
  747. // FROM vnbtd.asm
  748. //
  749. ULONG
  750. GetProfileHex(
  751. IN HANDLE ParametersHandle, // Not used
  752. IN PCHAR ValueName,
  753. IN ULONG DefaultValue,
  754. IN ULONG MinimumValue
  755. );
  756. ULONG
  757. GetProfileInt(
  758. IN HANDLE ParametersHandle, // Not used
  759. IN PCHAR ValueName,
  760. IN ULONG DefaultValue,
  761. IN ULONG MinimumValue
  762. );
  763. TDI_STATUS DhcpQueryInfo( UINT Type, PVOID pBuff, UINT * pSize ) ;
  764. //---------------------------------------------------------------------
  765. //
  766. // FROM tdiout.c
  767. //
  768. NTSTATUS VxdDisconnectWait( tLOWERCONNECTION * pLowerConn,
  769. tDEVICECONTEXT * pDeviceContext,
  770. ULONG Flags,
  771. PVOID Timeout) ;
  772. NTSTATUS VxdScheduleDelayedCall( tDGRAM_SEND_TRACKING * pTracker,
  773. PVOID pClientContext,
  774. PVOID ClientCompletion,
  775. PVOID CallBackRoutine,
  776. tDEVICECONTEXT *pDeviceContext,
  777. BOOLEAN CallbackInCriticalSection );
  778. //---------------------------------------------------------------------
  779. //
  780. // FROM timer.c
  781. //
  782. BOOL CheckForTimedoutNCBs( CTEEvent *pEvent, PVOID pCont ) ;
  783. VOID StopTimeoutTimer( VOID );
  784. NTSTATUS StartRefreshTimer( VOID );
  785. //---------------------------------------------------------------------
  786. //
  787. // FROM tdicnct.c
  788. //
  789. NTSTATUS CloseAddress( HANDLE hAddress ) ;
  790. //---------------------------------------------------------------------
  791. //
  792. // FROM wfw.c - Snowball specific routines
  793. //
  794. #ifndef CHICAGO
  795. BOOL GetActiveLanasFromIP( VOID );
  796. #endif //!CHICAGO
  797. //---------------------------------------------------------------------
  798. //
  799. // FROM chic.c - Chicago specific routines
  800. //
  801. #ifdef CHICAGO
  802. NTSTATUS DestroyDeviceObject(
  803. tNBTCONFIG *pConfig,
  804. ULONG IpAddr
  805. );
  806. BOOL IPRegisterAddrChangeHandler( PVOID AddChangeHandler, BOOL );
  807. TDI_STATUS IPNotification( ULONG IpAddress,
  808. ULONG IpMask,
  809. PVOID pDevNode,
  810. USHORT IPContext,
  811. #ifdef WINS_PER_ADAPTER
  812. BOOL fNew,
  813. PNDIS_STRING AdapterName);
  814. #else
  815. BOOL fNew);
  816. #endif // WINS_PER_ADAPTER
  817. BOOL VxdInitLmHostsSupport( PUCHAR pchLmHostPath, USHORT ulPathSize );
  818. VOID SaveNameDnsServerAddrs( VOID );
  819. BOOL VxdOpenNdis( VOID );
  820. VOID VxdCloseNdis( VOID );
  821. VOID ReleaseNbtConfigMem( VOID );
  822. NTSTATUS VxdUnload( LPSTR pchModuleName );
  823. #endif //CHICAGO
  824. //--------------------------------------------------------------------
  825. //
  826. // Procedures in vxdisol.c
  827. //
  828. //
  829. NCBERR VxdOpenName( tDEVICECONTEXT * pDeviceContext, NCB * pNCB ) ;
  830. NCBERR VxdCloseName( tDEVICECONTEXT * pDeviceContext, NCB * pNCB ) ;
  831. NCBERR VxdCall( tDEVICECONTEXT * pDeviceContext, NCB * pNCB ) ;
  832. NCBERR VxdListen( tDEVICECONTEXT * pDeviceContext, NCB * pNCB ) ;
  833. NCBERR VxdDgramSend( tDEVICECONTEXT * pDeviceContext, NCB * pNCB ) ;
  834. NCBERR VxdDgramReceive( tDEVICECONTEXT * pDeviceContext, NCB * pNCB ) ;
  835. NCBERR VxdReceiveAny( tDEVICECONTEXT *pDeviceContext, NCB * pNCB ) ;
  836. NCBERR VxdReceive( tDEVICECONTEXT * pDeviceContext, NCB * pNCB, BOOL fReceive ) ;
  837. NCBERR VxdHangup( tDEVICECONTEXT * pDeviceContext, NCB * pNCB ) ;
  838. NCBERR VxdCancel( tDEVICECONTEXT * pDeviceContext, NCB * pNCB ) ;
  839. NCBERR VxdSend( tDEVICECONTEXT * pDeviceContext, NCB * pNCB ) ;
  840. NCBERR VxdSessionStatus( tDEVICECONTEXT * pDeviceContext, NCB * pNCB ) ;
  841. VOID DelayedSessEstablish( PVOID pContext );
  842. //--------------------------------------------------------------------
  843. //
  844. // Procedures in dns.c
  845. //
  846. //
  847. PCHAR
  848. DnsStoreName(
  849. OUT PCHAR pDest,
  850. IN PCHAR pName,
  851. IN PCHAR pDomainName,
  852. IN enum eNSTYPE eNsType
  853. );
  854. VOID
  855. DnsExtractName(
  856. IN PCHAR pNameHdr,
  857. IN LONG NumBytes,
  858. OUT PCHAR pName,
  859. OUT PULONG pNameSize
  860. );
  861. VOID
  862. ProcessDnsResponse(
  863. IN tDEVICECONTEXT *pDeviceContext,
  864. IN PVOID pSrcAddress,
  865. IN tNAMEHDR UNALIGNED *pNameHdr,
  866. IN LONG lNumBytes,
  867. IN USHORT OpCodeFlags
  868. );
  869. VOID
  870. DnsCompletion(
  871. PVOID pContext,
  872. PVOID pContext2,
  873. tTIMERQENTRY *pTimerQEntry
  874. );
  875. //
  876. // These routines all have "Direct" at the end of the routine name
  877. // because they are used exclusively for name queries to the DNS
  878. // server to resolve DNS names and not NetBIOS names.
  879. //
  880. VOID
  881. ProcessDnsResponseDirect(
  882. IN tDEVICECONTEXT *pDeviceContext,
  883. IN PVOID pSrcAddress,
  884. IN tNAMEHDR UNALIGNED *pNameHdr,
  885. IN LONG lNumBytes,
  886. IN USHORT OpCodeFlags
  887. );
  888. ULONG
  889. DoDnsResolveDirect(
  890. PNCB pncb,
  891. PUCHAR pzDnsName,
  892. PULONG pIpAddressList
  893. );
  894. BOOL
  895. DoDnsCancelDirect(
  896. PNCB pncb
  897. );
  898. VOID
  899. DnsCompletionDirect(
  900. PVOID pContext,
  901. PVOID pContext2,
  902. tTIMERQENTRY *pTimerQEntry
  903. );
  904. PDNS_DIRECT_WORK_ITEM_CONTEXT
  905. FindContextDirect(
  906. USHORT TransactionId
  907. );
  908. VOID
  909. DnsActualCompletionDirect(
  910. IN NBT_WORK_ITEM_CONTEXT * pnbtContext
  911. );
  912. VOID
  913. DnsUnlinkAndCompleteDirect(
  914. IN PDNS_DIRECT_WORK_ITEM_CONTEXT pContext
  915. );
  916. NTSTATUS
  917. UdpSendDNSBcastDirect(
  918. IN PDNS_DIRECT_WORK_ITEM_CONTEXT pContext,
  919. IN ULONG Retries,
  920. IN ULONG Timeout
  921. );
  922. VOID
  923. SendDNSBcastDoneDirect(
  924. IN PVOID pContext,
  925. IN NTSTATUS status,
  926. IN ULONG lInfo
  927. );
  928. PDNS_DIRECT_SEND_CONTEXT
  929. CreateSendContextDirect(
  930. IN PCHAR pName,
  931. IN PCHAR pchDomainName,
  932. OUT PVOID *pHdrs,
  933. OUT PULONG pLength,
  934. IN PDNS_DIRECT_WORK_ITEM_CONTEXT pContext
  935. );
  936. VOID
  937. IpToAscii(
  938. IN DWORD IpAddress,
  939. IN OUT PCHAR pzAscii
  940. );
  941. //
  942. // Flag passed to TdiSend indicating we are dealing with a chain send
  943. // and not a normal send.
  944. //
  945. #define CHAIN_SEND_FLAG 0x80
  946. typedef struct _tBUFFERCHAINSEND
  947. {
  948. tBUFFER tBuff ; // Must be first member of this structure!!
  949. PVOID pBuffer2 ;
  950. ULONG Length2 ;
  951. } tBUFFERCHAINSEND ;
  952. //
  953. // Flag for pConnectEle->Flags indicating whether the client has been
  954. // notified the session is dead (by completing an NCB with NRC_SCLOSED)
  955. //
  956. #define NB_CLIENT_NOTIFIED 0x01
  957. //
  958. // Translates the name number/logical session number to the appropriate
  959. // structure pointer
  960. //
  961. NCBERR VxdFindClientElement( tDEVICECONTEXT * pDeviceContext,
  962. UCHAR ncbnum,
  963. tCLIENTELE * * ppClientEle,
  964. enum CLIENT_TYPE Type ) ;
  965. NCBERR VxdFindConnectElement( tDEVICECONTEXT * pDeviceContext,
  966. NCB * pNCB,
  967. tCONNECTELE * * ppConnectEle ) ;
  968. NCBERR VxdFindLSN( tDEVICECONTEXT * pDeviceContext,
  969. tCONNECTELE * pConnectEle,
  970. UCHAR * plsn ) ;
  971. NCBERR VxdFindNameNum( tDEVICECONTEXT * pDeviceContext,
  972. tADDRESSELE * pAddressEle,
  973. UCHAR * pNum ) ;
  974. //
  975. // Used by Register/Unregister for selecting either the name table or the
  976. // session table from the device context
  977. //
  978. typedef enum
  979. {
  980. NB_NAME,
  981. NB_SESSION
  982. } NB_TABLE_TYPE ;
  983. BOOL NBRegister( tDEVICECONTEXT * pDeviceContext,
  984. UCHAR * pNCBNum,
  985. PVOID pElem,
  986. NB_TABLE_TYPE NbTable ) ;
  987. BOOL NBUnregister( tDEVICECONTEXT * pDeviceContext,
  988. UCHAR NCBNum,
  989. NB_TABLE_TYPE NbTable ) ;
  990. TDI_STATUS VxdCompleteSessionNcbs( tDEVICECONTEXT * pDeviceContext,
  991. tCONNECTELE * pConnEle ) ;
  992. NCBERR VxdCleanupAddress( tDEVICECONTEXT * pDeviceContext,
  993. NCB * pNCB,
  994. tCLIENTELE * pClientEle,
  995. UCHAR NameNum,
  996. BOOL fDeleteAddress ) ;
  997. BOOL ActiveSessions( tCLIENTELE * pClientEle ) ;
  998. //
  999. // This structure holds context information while we are waiting for
  1000. // a session setup to complete (either listen or call)
  1001. //
  1002. // It is stored in the ncb_reserve field of the NCB
  1003. //
  1004. typedef struct _SESS_SETUP_CONTEXT
  1005. {
  1006. TDI_CONNECTION_INFORMATION * pRequestConnect ; //
  1007. TDI_CONNECTION_INFORMATION * pReturnConnect ; // Name who answered the listen
  1008. tCONNECTELE * pConnEle ;
  1009. UCHAR fIsWorldListen ; // Listenning for '*'?
  1010. } SESS_SETUP_CONTEXT, *PSESS_SETUP_CONTEXT ;
  1011. void VxdTearDownSession( tDEVICECONTEXT * pDevCont,
  1012. tCONNECTELE * pConnEle,
  1013. PSESS_SETUP_CONTEXT pCont,
  1014. NCB * pNCB ) ;
  1015. //
  1016. // Finishes off a Netbios request (fill in NCB fields, call the post
  1017. // routine etc.). Is macroed as CTEIoComplete.
  1018. //
  1019. VOID
  1020. VxdIoComplete(
  1021. PCTE_IRP pirp,
  1022. NTSTATUS status,
  1023. ULONG cbExtra
  1024. );
  1025. ULONG
  1026. _stdcall
  1027. VNBT_NCB_X(
  1028. PNCB pNCB,
  1029. PUCHAR pzDnsName,
  1030. PULONG pIpAddress,
  1031. PVOID pExtended,
  1032. ULONG fFlag
  1033. );
  1034. ULONG
  1035. _stdcall
  1036. VNBT_LANA_MASK();
  1037. #endif //_VXDPROCS_H_