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.

1545 lines
28 KiB

  1. /*++
  2. Copyright (c) 1989-1993 Microsoft Corporation
  3. Module Name:
  4. nbiprocs.h
  5. Abstract:
  6. This module contains definitions specific to the
  7. Netbios module of the ISN transport.
  8. Author:
  9. Adam Barr (adamba) 16-November-1993
  10. Environment:
  11. Kernel mode
  12. Revision History:
  13. --*/
  14. //
  15. // MACROS.
  16. //
  17. //
  18. // Debugging aids
  19. //
  20. //
  21. // VOID
  22. // PANIC(
  23. // IN PSZ Message
  24. // );
  25. //
  26. #if DBG
  27. #define PANIC(Msg) \
  28. CTEPrint ((Msg))
  29. #else
  30. #define PANIC(Msg)
  31. #endif
  32. //
  33. // These are define to allow CTEPrints that disappear when
  34. // DBG is 0.
  35. //
  36. #if DBG
  37. #define NbiPrint0(fmt) DbgPrint(fmt)
  38. #define NbiPrint1(fmt,v0) DbgPrint(fmt,v0)
  39. #define NbiPrint2(fmt,v0,v1) DbgPrint(fmt,v0,v1)
  40. #define NbiPrint3(fmt,v0,v1,v2) DbgPrint(fmt,v0,v1,v2)
  41. #define NbiPrint4(fmt,v0,v1,v2,v3) DbgPrint(fmt,v0,v1,v2,v3)
  42. #define NbiPrint5(fmt,v0,v1,v2,v3,v4) DbgPrint(fmt,v0,v1,v2,v3,v4)
  43. #define NbiPrint6(fmt,v0,v1,v2,v3,v4,v5) DbgPrint(fmt,v0,v1,v2,v3,v4,v5)
  44. #else
  45. #define NbiPrint0(fmt)
  46. #define NbiPrint1(fmt,v0)
  47. #define NbiPrint2(fmt,v0,v1)
  48. #define NbiPrint3(fmt,v0,v1,v2)
  49. #define NbiPrint4(fmt,v0,v1,v2,v3)
  50. #define NbiPrint5(fmt,v0,v1,v2,v3,v4)
  51. #define NbiPrint6(fmt,v0,v1,v2,v3,v4,v5)
  52. #endif
  53. //
  54. // Routines to log packets to a buffer.
  55. //
  56. #if DBG
  57. #define NB_PACKET_LOG 1
  58. #endif
  59. #ifdef NB_PACKET_LOG
  60. //
  61. // The size of this is 64 bytes for easy display.
  62. //
  63. typedef struct _NB_PACKET_LOG_ENTRY {
  64. UCHAR SendReceive;
  65. UCHAR TimeStamp[5]; // low 5 digits of tick count.
  66. UCHAR DestMac[6];
  67. UCHAR SrcMac[6];
  68. UCHAR Length[2];
  69. IPX_HEADER NbiHeader;
  70. UCHAR Data[14];
  71. } NB_PACKET_LOG_ENTRY, *PNB_PACKET_LOG_ENTRY;
  72. #define NB_PACKET_LOG_LENGTH 128
  73. extern ULONG NbiPacketLogDebug;
  74. extern USHORT NbiPacketLogSocket;
  75. EXTERNAL_LOCK(NbiPacketLogLock);
  76. extern NB_PACKET_LOG_ENTRY NbiPacketLog[NB_PACKET_LOG_LENGTH];
  77. extern PNB_PACKET_LOG_ENTRY NbiPacketLogLoc;
  78. extern PNB_PACKET_LOG_ENTRY NbiPacketLogEnd;
  79. //
  80. // Bit fields in NbiPacketLogDebug
  81. //
  82. #define NB_PACKET_LOG_RCV_RIP 0x0001 // All RIP packets
  83. #define NB_PACKET_LOG_RCV_SPX 0x0002 // All SPX packets
  84. #define NB_PACKET_LOG_RCV_NB 0x0004 // All Netbios packets
  85. #define NB_PACKET_LOG_RCV_OTHER 0x0008 // All TDI client packets
  86. #define NB_PACKET_LOG_RCV_SOCKET 0x0010 // All packets to NbiPacketLogSocket
  87. #define NB_PACKET_LOG_RCV_ALL 0x0020 // All packets (even non-NB)
  88. #define NB_PACKET_LOG_SEND_RIP 0x0001 // All RIP packets
  89. #define NB_PACKET_LOG_SEND_SPX 0x0002 // All SPX packets
  90. #define NB_PACKET_LOG_SEND_NB 0x0004 // All Netbios packets
  91. #define NB_PACKET_LOG_SEND_OTHER 0x0008 // All TDI client packets
  92. #define NB_PACKET_LOG_SEND_SOCKET 0x0010 // All packets from NbiPacketLogSocket
  93. VOID
  94. NbiLogPacket(
  95. IN BOOLEAN Send,
  96. IN PUCHAR DestMac,
  97. IN PUCHAR SrcMac,
  98. IN USHORT Length,
  99. IN PVOID NbiHeader,
  100. IN PVOID Data
  101. );
  102. #define PACKET_LOG(_Bit) (NbiPacketLogDebug & (_Bit))
  103. #else // NB_PACKET_LOG
  104. #define NbiLogPacket(_MacHeader,_Length,_NbiHeader,_Data)
  105. #define PACKET_LOG(_Bit) 0
  106. #endif // NB_PACKET_LOG
  107. #if DBG
  108. #define NbiReferenceDevice(_Device, _Type) \
  109. (VOID)ExInterlockedAddUlong ( \
  110. &(_Device)->RefTypes[_Type], \
  111. 1, \
  112. &NbiGlobalInterlock); \
  113. NbiRefDevice (_Device)
  114. #define NbiDereferenceDevice(_Device, _Type) \
  115. (VOID)ExInterlockedAddUlong ( \
  116. &(_Device)->RefTypes[_Type], \
  117. (ULONG)-1, \
  118. &NbiGlobalInterlock); \
  119. NbiDerefDevice (_Device)
  120. #define NbiReferenceAddress(_Address, _Type) \
  121. (VOID)ExInterlockedAddUlong ( \
  122. &(_Address)->RefTypes[_Type], \
  123. 1, \
  124. &NbiGlobalInterlock); \
  125. NbiRefAddress (_Address)
  126. #define NbiReferenceAddressLock(_Address, _Type) \
  127. (VOID)ExInterlockedAddUlong ( \
  128. &(_Address)->RefTypes[_Type], \
  129. 1, \
  130. &NbiGlobalInterlock); \
  131. NbiRefAddressLock (_Address)
  132. #define NbiDereferenceAddress(_Address, _Type) \
  133. (VOID)ExInterlockedAddUlong ( \
  134. &(_Address)->RefTypes[_Type], \
  135. (ULONG)-1, \
  136. &NbiGlobalInterlock); \
  137. NbiDerefAddress (_Address)
  138. #define NbiReferenceAddressFile(_AddressFile, _Type) \
  139. (VOID)ExInterlockedAddUlong ( \
  140. &(_AddressFile)->RefTypes[_Type], \
  141. 1, \
  142. &NbiGlobalInterlock); \
  143. NbiRefAddressFile (_AddressFile)
  144. #define NbiReferenceAddressFileLock(_AddressFile, _Type) \
  145. (VOID)ExInterlockedAddUlong ( \
  146. &(_AddressFile)->RefTypes[_Type], \
  147. 1, \
  148. &NbiGlobalInterlock); \
  149. NbiRefAddressFileLock (_AddressFile)
  150. #define NbiDereferenceAddressFile(_AddressFile, _Type) \
  151. (VOID)ExInterlockedAddUlong ( \
  152. &(_AddressFile)->RefTypes[_Type], \
  153. (ULONG)-1, \
  154. &NbiGlobalInterlock); \
  155. NbiDerefAddressFile (_AddressFile)
  156. #define NbiTransferReferenceAddressFile(_AddressFile, _OldType, _NewType) \
  157. (VOID)ExInterlockedAddUlong ( \
  158. &(_AddressFile)->RefTypes[_NewType], \
  159. 1, \
  160. &NbiGlobalInterlock); \
  161. (VOID)ExInterlockedAddUlong ( \
  162. &(_AddressFile)->RefTypes[_OldType], \
  163. (ULONG)-1, \
  164. &NbiGlobalInterlock);
  165. #define NbiReferenceConnection(_Connection, _Type) \
  166. (VOID)ExInterlockedAddUlong ( \
  167. &(_Connection)->RefTypes[_Type], \
  168. 1, \
  169. &NbiGlobalInterlock); \
  170. NbiRefConnection (_Connection)
  171. #define NbiReferenceConnectionLock(_Connection, _Type) \
  172. (VOID)ExInterlockedAddUlong ( \
  173. &(_Connection)->RefTypes[_Type], \
  174. 1, \
  175. &NbiGlobalInterlock); \
  176. NbiRefConnectionLock (_Connection)
  177. #define NbiReferenceConnectionSync(_Connection, _Type) \
  178. (VOID)ExInterlockedAddUlong ( \
  179. &(_Connection)->RefTypes[_Type], \
  180. 1, \
  181. &NbiGlobalInterlock); \
  182. NbiRefConnectionSync (_Connection)
  183. #define NbiDereferenceConnection(_Connection, _Type) \
  184. (VOID)ExInterlockedAddUlong ( \
  185. &(_Connection)->RefTypes[_Type], \
  186. (ULONG)-1, \
  187. &NbiGlobalInterlock); \
  188. NbiDerefConnection (_Connection)
  189. #define NbiTransferReferenceConnection(_Connection, _OldType, _NewType) \
  190. (VOID)ExInterlockedAddUlong ( \
  191. &(_Connection)->RefTypes[_NewType], \
  192. 1, \
  193. &NbiGlobalInterlock); \
  194. (VOID)ExInterlockedAddUlong ( \
  195. &(_Connection)->RefTypes[_OldType], \
  196. (ULONG)-1, \
  197. &NbiGlobalInterlock);
  198. #else // DBG
  199. #define NbiReferenceDevice(_Device, _Type) \
  200. InterlockedIncrement(&(_Device)->ReferenceCount)
  201. #define NbiDereferenceDevice(_Device, _Type) \
  202. NbiDerefDevice (_Device)
  203. #define NbiReferenceAddress(_Address, _Type) \
  204. InterlockedIncrement( &(_Address)->ReferenceCount )
  205. #define NbiReferenceAddressLock(_Address, _Type) \
  206. InterlockedIncrement( &(_Address)->ReferenceCount )
  207. #define NbiDereferenceAddress(_Address, _Type) \
  208. NbiDerefAddress (_Address)
  209. #define NbiReferenceAddressFile(_AddressFile, _Type) \
  210. InterlockedIncrement( &(_AddressFile)->ReferenceCount )
  211. #define NbiReferenceAddressFileLock(_AddressFile, _Type) \
  212. InterlockedIncrement( &(_AddressFile)->ReferenceCount )
  213. #define NbiDereferenceAddressFile(_AddressFile, _Type) \
  214. if ( !InterlockedDecrement(&(_AddressFile)->ReferenceCount )) { \
  215. NbiDestroyAddressFile (_AddressFile); \
  216. }
  217. #define NbiTransferReferenceAddressFile(_AddressFile, _OldType, _NewType)
  218. #define NbiReferenceConnection(_Connection, _Type) { \
  219. (VOID)ExInterlockedAddUlong( \
  220. &(_Connection)->ReferenceCount, \
  221. 1, \
  222. &(_Connection)->DeviceLock->Lock); \
  223. (_Connection)->CanBeDestroyed = FALSE; \
  224. }
  225. #define NbiReferenceConnectionLock(_Connection, _Type) { \
  226. ++(_Connection)->ReferenceCount; \
  227. (_Connection)->CanBeDestroyed = FALSE; \
  228. }
  229. #define NbiReferenceConnectionSync(_Connection, _Type) { \
  230. (VOID)NB_ADD_ULONG( \
  231. &(_Connection)->ReferenceCount, \
  232. 1, \
  233. (_Connection)->DeviceLock); \
  234. (_Connection)->CanBeDestroyed = FALSE; \
  235. }
  236. #define NbiDereferenceConnection(_Connection, _Type) { \
  237. CTELockHandle _LockHandle; \
  238. NB_GET_LOCK( (_Connection)->DeviceLock, &_LockHandle ); \
  239. if ( !(--(_Connection)->ReferenceCount) ) { \
  240. (_Connection)->ThreadsInHandleConnectionZero++; \
  241. NB_FREE_LOCK( (_Connection)->DeviceLock, _LockHandle ); \
  242. NbiHandleConnectionZero (_Connection); \
  243. } else { \
  244. NB_FREE_LOCK( (_Connection)->DeviceLock, _LockHandle ); \
  245. } \
  246. }
  247. #define NbiTransferReferenceConnection(_Connection, _OldType, _NewType)
  248. #endif // DBG
  249. #if DBG
  250. #define NbiAllocateMemory(_BytesNeeded,_Tag,_Description) \
  251. NbipAllocateTaggedMemory(_BytesNeeded,_Tag,_Description)
  252. #define NbiFreeMemory(_Memory,_BytesAllocated,_Tag,_Description) \
  253. NbipFreeTaggedMemory(_Memory,_BytesAllocated,_Tag,_Description)
  254. #else // DBG
  255. #define NbiAllocateMemory(_BytesNeeded,_Tag,_Description) \
  256. NbipAllocateMemory(_BytesNeeded,_Tag,(BOOLEAN)((_Tag) != MEMORY_CONFIG))
  257. #define NbiFreeMemory(_Memory,_BytesAllocated,_Tag,_Description) \
  258. NbipFreeMemory(_Memory,_BytesAllocated,(BOOLEAN)((_Tag) != MEMORY_CONFIG))
  259. #endif // DBG
  260. VOID
  261. TdiBindHandler(
  262. TDI_PNP_OPCODE PnPOpCode,
  263. PUNICODE_STRING pDeviceName,
  264. PWSTR MultiSZBindList);
  265. //
  266. // Definition of the callback routine where an NdisTransferData
  267. // call is not needed.
  268. //
  269. typedef VOID
  270. (*NB_CALLBACK_NO_TRANSFER) (
  271. IN PIPX_LOCAL_TARGET RemoteAddress,
  272. IN ULONG MacOptions,
  273. IN PUCHAR PacketBuffer,
  274. IN UINT PacketSize
  275. );
  276. //
  277. // This routine compares two node addresses.
  278. //
  279. #define NB_NODE_EQUAL(_A,_B) \
  280. ((*(UNALIGNED ULONG *)((PUCHAR)(_A)) == *(UNALIGNED ULONG *)((PUCHAR)(_B))) && \
  281. (*(UNALIGNED USHORT *)(((PUCHAR)(_A))+4) == *(UNALIGNED USHORT *)(((PUCHAR)(_B))+4)))
  282. //
  283. // This routine checks if an address is the broadcast address.
  284. //
  285. #define NB_NODE_BROADCAST(_A) \
  286. ((*(UNALIGNED ULONG *)((PUCHAR)(_A)) == 0xffffffff) && \
  287. (*(UNALIGNED USHORT *)(((PUCHAR)(_A))+4) == 0xffff))
  288. //
  289. // Definition of the routine to handler a particular minor
  290. // code for an IOCTL_MJ_INTERNAL_DEVICE_CONTROL IRP.
  291. //
  292. typedef NTSTATUS
  293. (*NB_TDI_DISPATCH_ROUTINE) (
  294. IN PDEVICE Device,
  295. IN PREQUEST Request
  296. );
  297. //
  298. // Routines in action.c
  299. //
  300. NTSTATUS
  301. NbiTdiAction(
  302. IN PDEVICE Device,
  303. IN PREQUEST Request
  304. );
  305. //
  306. // Routines in address.c
  307. //
  308. TDI_ADDRESS_NETBIOS *
  309. NbiParseTdiAddress(
  310. IN TRANSPORT_ADDRESS UNALIGNED *TransportAddress,
  311. IN ULONG MaxBufferLength,
  312. IN BOOLEAN BroadcastAddressOk
  313. );
  314. BOOLEAN
  315. NbiValidateTdiAddress(
  316. IN TRANSPORT_ADDRESS UNALIGNED * TransportAddress,
  317. IN ULONG TransportAddressLength
  318. );
  319. NTSTATUS
  320. NbiOpenAddress(
  321. IN PDEVICE Device,
  322. IN PREQUEST Request
  323. );
  324. VOID
  325. NbiStartRegistration(
  326. IN PADDRESS Address
  327. );
  328. VOID
  329. NbiRegistrationTimeout(
  330. IN CTEEvent * Event,
  331. IN PVOID Context
  332. );
  333. VOID
  334. NbiProcessFindName(
  335. IN PIPX_LOCAL_TARGET RemoteAddress,
  336. IN ULONG MacOptions,
  337. IN PUCHAR PacketBuffer,
  338. IN UINT PacketSize
  339. );
  340. VOID
  341. NbiProcessAddName(
  342. IN PIPX_LOCAL_TARGET RemoteAddress,
  343. IN ULONG MacOptions,
  344. IN PUCHAR PacketBuffer,
  345. IN UINT PacketSize
  346. );
  347. NTSTATUS
  348. NbiOpenConnection(
  349. IN PDEVICE Device,
  350. IN PREQUEST Request
  351. );
  352. NTSTATUS
  353. NbiCreateAddress(
  354. IN PREQUEST Request,
  355. IN PADDRESS_FILE AddressFile,
  356. IN PIO_STACK_LOCATION IrpSp,
  357. IN PDEVICE Device,
  358. IN TDI_ADDRESS_NETBIOS *NetbiosAddress,
  359. OUT PADDRESS *pAddress
  360. );
  361. NTSTATUS
  362. NbiVerifyAddressFile (
  363. #if defined(_PNP_POWER)
  364. IN PADDRESS_FILE AddressFile,
  365. IN BOOLEAN ConflictIsOk
  366. #else
  367. IN PADDRESS_FILE AddressFile
  368. #endif _PNP_POWER
  369. );
  370. VOID
  371. NbiDestroyAddress(
  372. IN PVOID Parameter
  373. );
  374. #if DBG
  375. VOID
  376. NbiRefAddress(
  377. IN PADDRESS Address
  378. );
  379. VOID
  380. NbiRefAddressLock(
  381. IN PADDRESS Address
  382. );
  383. #endif
  384. VOID
  385. NbiDerefAddress(
  386. IN PADDRESS Address
  387. );
  388. PADDRESS_FILE
  389. NbiCreateAddressFile(
  390. IN PDEVICE Device
  391. );
  392. NTSTATUS
  393. NbiDestroyAddressFile(
  394. IN PADDRESS_FILE AddressFile
  395. );
  396. #if DBG
  397. VOID
  398. NbiRefAddressFile(
  399. IN PADDRESS_FILE AddressFile
  400. );
  401. VOID
  402. NbiRefAddressFileLock(
  403. IN PADDRESS_FILE AddressFile
  404. );
  405. #endif
  406. VOID
  407. NbiDerefAddressFile(
  408. IN PADDRESS_FILE AddressFile
  409. );
  410. #if !defined(_PNP_POWER)
  411. PADDRESS
  412. NbiLookupAddress(
  413. IN PDEVICE Device,
  414. IN TDI_ADDRESS_NETBIOS UNALIGNED * NetbiosAddress
  415. );
  416. #endif !_PNP_POWER
  417. PADDRESS
  418. NbiFindAddress(
  419. IN PDEVICE Device,
  420. IN PUCHAR NetbiosName
  421. );
  422. NTSTATUS
  423. NbiStopAddressFile(
  424. IN PADDRESS_FILE AddressFile,
  425. IN PADDRESS Address
  426. );
  427. NTSTATUS
  428. NbiCloseAddressFile(
  429. IN PDEVICE Device,
  430. IN PREQUEST Request
  431. );
  432. #if defined(_PNP_POWER)
  433. PADAPTER_ADDRESS
  434. NbiCreateAdapterAddress(
  435. IN PCHAR AdapterMacAddress
  436. );
  437. NTSTATUS
  438. NbiDestroyAdapterAddress(
  439. IN PADAPTER_ADDRESS AdapterAddress OPTIONAL,
  440. IN PCHAR AdapterMacAddress OPTIONAL
  441. );
  442. PADAPTER_ADDRESS
  443. NbiFindAdapterAddress(
  444. IN PCHAR NetbiosName,
  445. IN BOOLEAN LockHeld
  446. );
  447. #endif _PNP_POWER
  448. //
  449. // Routines in bind.c
  450. //
  451. NTSTATUS
  452. NbiBind(
  453. IN PDEVICE Device,
  454. IN PCONFIG Config
  455. );
  456. VOID
  457. NbiUnbind(
  458. IN PDEVICE Device
  459. );
  460. VOID
  461. NbiStatus(
  462. IN USHORT NicId,
  463. IN NDIS_STATUS GeneralStatus,
  464. IN PVOID StatusBuffer,
  465. IN UINT StatusBufferLength
  466. );
  467. VOID
  468. NbiLineUp(
  469. IN USHORT NicId,
  470. IN PIPX_LINE_INFO LineInfo,
  471. IN NDIS_MEDIUM DeviceType,
  472. IN PVOID ConfigurationData
  473. );
  474. VOID
  475. NbiLineDown(
  476. IN USHORT NicId,
  477. IN ULONG_PTR FwdAdapterCtx
  478. );
  479. //
  480. // Routines in cache.c
  481. //
  482. NTSTATUS
  483. CacheFindName(
  484. IN PDEVICE Device,
  485. IN FIND_NAME_TYPE Type,
  486. IN PUCHAR RemoteName OPTIONAL,
  487. OUT PNETBIOS_CACHE * CacheName
  488. );
  489. VOID
  490. FindNameTimeout(
  491. CTEEvent * Event,
  492. PVOID Context
  493. );
  494. VOID
  495. CacheHandlePending(
  496. IN PDEVICE Device,
  497. IN PUCHAR RemoteName,
  498. IN NETBIOS_NAME_RESULT Result,
  499. IN PNETBIOS_CACHE CacheName OPTIONAL
  500. IN NB_LOCK_HANDLE_PARAM(LockHandle)
  501. );
  502. VOID
  503. NbiProcessNameRecognized(
  504. IN PIPX_LOCAL_TARGET RemoteAddress,
  505. IN ULONG MacOptions,
  506. IN PUCHAR PacketBuffer,
  507. IN UINT PacketSize
  508. );
  509. PNETBIOS_CACHE
  510. CacheUpdateNameCache(
  511. IN PNETBIOS_CACHE NameCache,
  512. IN PIPX_LOCAL_TARGET RemoteAddress,
  513. IN TDI_ADDRESS_IPX UNALIGNED * SourceAddress,
  514. IN BOOLEAN ModifyQueue
  515. );
  516. VOID
  517. CacheUpdateFromAddName(
  518. IN PIPX_LOCAL_TARGET RemoteAddress,
  519. IN NB_CONNECTIONLESS UNALIGNED * Connectionless,
  520. IN BOOLEAN LocalFrame
  521. );
  522. VOID
  523. NbiProcessDeleteName(
  524. IN PIPX_LOCAL_TARGET RemoteAddress,
  525. IN ULONG MacOptions,
  526. IN PUCHAR PacketBuffer,
  527. IN UINT PacketSize
  528. );
  529. VOID
  530. InsertInNetbiosCacheTable(
  531. IN PNETBIOS_CACHE_TABLE CacheTable,
  532. IN PNETBIOS_CACHE CacheEntry
  533. );
  534. VOID
  535. ReinsertInNetbiosCacheTable(
  536. IN PNETBIOS_CACHE_TABLE CacheTable,
  537. IN PNETBIOS_CACHE OldEntry,
  538. IN PNETBIOS_CACHE NewEntry
  539. );
  540. VOID
  541. RemoveFromNetbiosCacheTable(
  542. IN PNETBIOS_CACHE_TABLE CacheTable,
  543. IN PNETBIOS_CACHE CacheEntry
  544. );
  545. VOID
  546. FlushOldFromNetbiosCacheTable(
  547. IN PNETBIOS_CACHE_TABLE CacheTable,
  548. IN USHORT AgeLimit
  549. );
  550. VOID
  551. FlushFailedNetbiosCacheEntries(
  552. IN PNETBIOS_CACHE_TABLE CacheTable
  553. );
  554. VOID
  555. RemoveInvalidRoutesFromNetbiosCacheTable(
  556. IN PNETBIOS_CACHE_TABLE CacheTable,
  557. IN NIC_HANDLE UNALIGNED *InvalidNicHandle
  558. );
  559. NTSTATUS
  560. FindInNetbiosCacheTable(
  561. IN PNETBIOS_CACHE_TABLE CacheTable,
  562. IN PUCHAR NameToBeFound,
  563. OUT PNETBIOS_CACHE *CacheEntry
  564. );
  565. NTSTATUS
  566. CreateNetbiosCacheTable(
  567. IN OUT PNETBIOS_CACHE_TABLE *NewTable,
  568. IN USHORT MaxHashIndex
  569. );
  570. VOID
  571. DestroyNetbiosCacheTable(
  572. IN PNETBIOS_CACHE_TABLE CacheTable
  573. );
  574. //
  575. // Routines in connect.c
  576. //
  577. VOID
  578. NbiFindRouteComplete(
  579. IN PIPX_FIND_ROUTE_REQUEST FindRouteRequest,
  580. IN BOOLEAN FoundRoute
  581. );
  582. NTSTATUS
  583. NbiOpenConnection(
  584. IN PDEVICE Device,
  585. IN PREQUEST Request
  586. );
  587. VOID
  588. NbiStopConnection(
  589. IN PCONNECTION Connection,
  590. IN NTSTATUS DisconnectStatus
  591. IN NB_LOCK_HANDLE_PARAM(LockHandle)
  592. );
  593. NTSTATUS
  594. NbiCloseConnection(
  595. IN PDEVICE Device,
  596. IN PREQUEST Request
  597. );
  598. NTSTATUS
  599. NbiTdiAssociateAddress(
  600. IN PDEVICE Device,
  601. IN PREQUEST Request
  602. );
  603. NTSTATUS
  604. NbiTdiDisassociateAddress(
  605. IN PDEVICE Device,
  606. IN PREQUEST Request
  607. );
  608. NTSTATUS
  609. NbiTdiListen(
  610. IN PDEVICE Device,
  611. IN PREQUEST Request
  612. );
  613. NTSTATUS
  614. NbiTdiAccept(
  615. IN PDEVICE Device,
  616. IN PREQUEST Request
  617. );
  618. NTSTATUS
  619. NbiTdiConnect(
  620. IN PDEVICE Device,
  621. IN PREQUEST Request
  622. );
  623. NTSTATUS
  624. NbiTdiConnectFindName(
  625. IN PDEVICE Device,
  626. IN PREQUEST Request,
  627. IN PCONNECTION Connection,
  628. IN CTELockHandle CancelLH,
  629. IN CTELockHandle ConnectionLH,
  630. IN CTELockHandle DeviceLH,
  631. IN PBOOLEAN pbLockFreed
  632. );
  633. NTSTATUS
  634. NbiTdiDisconnect(
  635. IN PDEVICE Device,
  636. IN PREQUEST Request
  637. );
  638. BOOLEAN
  639. NbiAssignConnectionId(
  640. IN PDEVICE Device,
  641. IN PCONNECTION Connection
  642. );
  643. VOID
  644. NbiDeassignConnectionId(
  645. IN PDEVICE Device,
  646. IN PCONNECTION Connection
  647. );
  648. VOID
  649. NbiConnectionTimeout(
  650. IN CTEEvent * Event,
  651. IN PVOID Context
  652. );
  653. VOID
  654. NbiCancelListen(
  655. IN PDEVICE_OBJECT DeviceObject,
  656. IN PIRP Irp
  657. );
  658. VOID
  659. NbiCancelConnectFindName(
  660. IN PDEVICE_OBJECT DeviceObject,
  661. IN PIRP Irp
  662. );
  663. VOID
  664. NbiCancelConnectWaitResponse(
  665. IN PDEVICE_OBJECT DeviceObject,
  666. IN PIRP Irp
  667. );
  668. VOID
  669. NbiCancelDisconnectWait(
  670. IN PDEVICE_OBJECT DeviceObject,
  671. IN PIRP Irp
  672. );
  673. PCONNECTION
  674. NbiLookupConnectionByContext(
  675. IN PADDRESS_FILE AddressFile,
  676. IN CONNECTION_CONTEXT ConnectionContext
  677. );
  678. PCONNECTION
  679. NbiCreateConnection(
  680. IN PDEVICE Device
  681. );
  682. NTSTATUS
  683. NbiVerifyConnection (
  684. IN PCONNECTION Connection
  685. );
  686. VOID
  687. NbiDestroyConnection(
  688. IN PCONNECTION Connection
  689. );
  690. #if DBG
  691. VOID
  692. NbiRefConnection(
  693. IN PCONNECTION Connection
  694. );
  695. VOID
  696. NbiRefConnectionLock(
  697. IN PCONNECTION Connection
  698. );
  699. VOID
  700. NbiRefConnectionSync(
  701. IN PCONNECTION Connection
  702. );
  703. VOID
  704. NbiDerefConnection(
  705. IN PCONNECTION Connection
  706. );
  707. VOID
  708. NbiDerefConnectionSync(
  709. IN PCONNECTION Connection
  710. );
  711. #endif
  712. VOID
  713. NbiHandleConnectionZero(
  714. IN PCONNECTION Connection
  715. );
  716. //
  717. // Routines in datagram.c
  718. //
  719. VOID
  720. NbiProcessDatagram(
  721. IN NDIS_HANDLE MacBindingHandle,
  722. IN NDIS_HANDLE MacReceiveContext,
  723. IN PIPX_LOCAL_TARGET RemoteAddress,
  724. IN ULONG MacOptions,
  725. IN PUCHAR LookaheadBuffer,
  726. IN UINT LookaheadBufferSize,
  727. IN UINT LookaheadBufferOffset,
  728. IN UINT PacketSize,
  729. IN BOOLEAN Broadcast
  730. );
  731. VOID
  732. NbiIndicateDatagram(
  733. IN PADDRESS Address,
  734. IN PUCHAR RemoteName,
  735. IN PUCHAR Data,
  736. IN ULONG DataLength
  737. );
  738. NTSTATUS
  739. NbiTdiSendDatagram(
  740. IN PDEVICE Device,
  741. IN PREQUEST Request
  742. );
  743. VOID
  744. NbiTransmitDatagram(
  745. IN PNB_SEND_RESERVED Reserved
  746. );
  747. NTSTATUS
  748. NbiTdiReceiveDatagram(
  749. IN PDEVICE Device,
  750. IN PREQUEST Request
  751. );
  752. VOID
  753. NbiCancelReceiveDatagram(
  754. IN PDEVICE_OBJECT DeviceObject,
  755. IN PIRP Irp
  756. );
  757. //
  758. // Routines in device.c
  759. //
  760. VOID
  761. NbiRefDevice(
  762. IN PDEVICE Device
  763. );
  764. VOID
  765. NbiDerefDevice(
  766. IN PDEVICE Device
  767. );
  768. NTSTATUS
  769. NbiCreateDevice(
  770. IN PDRIVER_OBJECT DriverObject,
  771. IN PUNICODE_STRING DeviceName,
  772. IN OUT PDEVICE *DevicePtr
  773. );
  774. VOID
  775. NbiDestroyDevice(
  776. IN PDEVICE Device
  777. );
  778. //
  779. // Routines in driver.c
  780. //
  781. PVOID
  782. NbipAllocateMemory(
  783. IN ULONG BytesNeeded,
  784. IN ULONG Tag,
  785. IN BOOLEAN ChargeDevice
  786. );
  787. VOID
  788. NbipFreeMemory(
  789. IN PVOID Memory,
  790. IN ULONG BytesAllocated,
  791. IN BOOLEAN ChargeDevice
  792. );
  793. #if DBG
  794. PVOID
  795. NbipAllocateTaggedMemory(
  796. IN ULONG BytesNeeded,
  797. IN ULONG Tag,
  798. IN PUCHAR Description
  799. );
  800. VOID
  801. NbipFreeTaggedMemory(
  802. IN PVOID Memory,
  803. IN ULONG BytesAllocated,
  804. IN ULONG Tag,
  805. IN PUCHAR Description
  806. );
  807. #endif
  808. VOID
  809. NbiWriteResourceErrorLog(
  810. IN PDEVICE Device,
  811. IN ULONG BytesNeeded,
  812. IN ULONG UniqueErrorValue
  813. );
  814. VOID
  815. NbiWriteGeneralErrorLog(
  816. IN PDEVICE Device,
  817. IN NTSTATUS ErrorCode,
  818. IN ULONG UniqueErrorValue,
  819. IN NTSTATUS FinalStatus,
  820. IN PWSTR SecondString,
  821. IN ULONG DumpDataCount,
  822. IN ULONG DumpData[]
  823. );
  824. VOID
  825. NbiWriteOidErrorLog(
  826. IN PDEVICE Device,
  827. IN NTSTATUS ErrorCode,
  828. IN NTSTATUS FinalStatus,
  829. IN PWSTR AdapterString,
  830. IN ULONG OidValue
  831. );
  832. //
  833. // Routines in event.c
  834. //
  835. NTSTATUS
  836. NbiTdiSetEventHandler(
  837. IN PDEVICE Device,
  838. IN PREQUEST Request
  839. );
  840. //
  841. // Routines in frame.c
  842. //
  843. VOID
  844. NbiSendNameFrame(
  845. IN PADDRESS Address,
  846. IN UCHAR NameTypeFlag,
  847. IN UCHAR DataStreamType,
  848. IN PIPX_LOCAL_TARGET LocalTarget OPTIONAL,
  849. #if defined(_PNP_POWER)
  850. IN NB_CONNECTIONLESS UNALIGNED * ReqFrame OPTIONAL
  851. #else
  852. IN TDI_ADDRESS_IPX UNALIGNED * DestAddress OPTIONAL
  853. #endif _PNP_POWER
  854. );
  855. VOID
  856. NbiSendSessionInitialize(
  857. IN PCONNECTION Connection
  858. );
  859. VOID
  860. NbiSendSessionInitAck(
  861. IN PCONNECTION Connection,
  862. IN PUCHAR ExtraData,
  863. IN ULONG ExtraDataLength,
  864. IN CTELockHandle * LockHandle OPTIONAL
  865. );
  866. VOID
  867. NbiSendDataAck(
  868. IN PCONNECTION Connection,
  869. IN NB_ACK_TYPE AckType
  870. IN NB_LOCK_HANDLE_PARAM (LockHandle)
  871. );
  872. VOID
  873. NbiSendSessionEnd(
  874. IN PCONNECTION Connection
  875. );
  876. VOID
  877. NbiSendSessionEndAck(
  878. IN TDI_ADDRESS_IPX UNALIGNED * RemoteAddress,
  879. IN PIPX_LOCAL_TARGET LocalTarget,
  880. IN NB_SESSION UNALIGNED * SessionEnd
  881. );
  882. //
  883. // Routines in packet.c
  884. //
  885. NTSTATUS
  886. NbiInitializeSendPacket(
  887. IN PDEVICE Device,
  888. IN NDIS_HANDLE PoolHandle OPTIONAL,
  889. IN PNB_SEND_PACKET Packet,
  890. IN PUCHAR Header,
  891. IN ULONG HeaderLength
  892. );
  893. NTSTATUS
  894. NbiInitializeReceivePacket(
  895. IN PDEVICE Device,
  896. IN NDIS_HANDLE PoolHandle OPTIONAL,
  897. IN PNB_RECEIVE_PACKET Packet
  898. );
  899. NTSTATUS
  900. NbiInitializeReceiveBuffer(
  901. IN PDEVICE Device,
  902. IN PNB_RECEIVE_BUFFER ReceiveBuffer,
  903. IN PUCHAR DataBuffer,
  904. IN ULONG DataBufferLength
  905. );
  906. VOID
  907. NbiDeinitializeSendPacket(
  908. IN PDEVICE Device,
  909. IN PNB_SEND_PACKET Packet,
  910. IN ULONG HeaderLength
  911. );
  912. VOID
  913. NbiDeinitializeReceivePacket(
  914. IN PDEVICE Device,
  915. IN PNB_RECEIVE_PACKET Packet
  916. );
  917. VOID
  918. NbiDeinitializeReceiveBuffer(
  919. IN PDEVICE Device,
  920. IN PNB_RECEIVE_BUFFER ReceiveBuffer
  921. );
  922. VOID
  923. NbiAllocateSendPool(
  924. IN PDEVICE Device
  925. );
  926. VOID
  927. NbiAllocateReceivePool(
  928. IN PDEVICE Device
  929. );
  930. #if defined(_PNP_POWER)
  931. VOID
  932. NbiAllocateReceiveBufferPool(
  933. IN PDEVICE Device,
  934. IN UINT DataLength
  935. );
  936. VOID
  937. NbiReAllocateReceiveBufferPool(
  938. IN PWORK_QUEUE_ITEM WorkItem
  939. );
  940. VOID
  941. NbiDestroyReceiveBufferPools(
  942. IN PDEVICE Device
  943. );
  944. VOID
  945. NbiPushReceiveBuffer (
  946. IN PNB_RECEIVE_BUFFER ReceiveBuffer
  947. );
  948. #else
  949. VOID
  950. NbiAllocateReceiveBufferPool(
  951. IN PDEVICE Device
  952. );
  953. #endif _PNP_POWER
  954. PSINGLE_LIST_ENTRY
  955. NbiPopSendPacket(
  956. IN PDEVICE Device,
  957. IN BOOLEAN LockAcquired
  958. );
  959. VOID
  960. NbiPushSendPacket(
  961. IN PNB_SEND_RESERVED Reserved
  962. );
  963. VOID
  964. NbiCheckForWaitPacket(
  965. IN PCONNECTION Connection
  966. );
  967. PSINGLE_LIST_ENTRY
  968. NbiPopReceivePacket(
  969. IN PDEVICE Device
  970. );
  971. PSINGLE_LIST_ENTRY
  972. NbiPopReceiveBuffer(
  973. IN PDEVICE Device
  974. );
  975. //
  976. // Routines in query.c
  977. //
  978. NTSTATUS
  979. NbiTdiQueryInformation(
  980. IN PDEVICE Device,
  981. IN PREQUEST Request
  982. );
  983. NTSTATUS
  984. NbiStoreAdapterStatus(
  985. IN ULONG MaximumLength,
  986. IN USHORT NicId,
  987. OUT PVOID * StatusBuffer,
  988. OUT ULONG * StatusBufferLength,
  989. OUT ULONG * ValidBufferLength
  990. );
  991. VOID
  992. NbiUpdateNetbiosFindName(
  993. IN PREQUEST Request,
  994. #if defined(_PNP_POWER)
  995. IN PNIC_HANDLE NicHandle,
  996. #else
  997. IN USHORT NicId,
  998. #endif _PNP_POWER
  999. IN TDI_ADDRESS_IPX UNALIGNED * RemoteIpxAddress,
  1000. IN BOOLEAN Unique
  1001. );
  1002. VOID
  1003. NbiSetNetbiosFindNameInformation(
  1004. IN PREQUEST Request
  1005. );
  1006. NTSTATUS
  1007. NbiTdiSetInformation(
  1008. IN PDEVICE Device,
  1009. IN PREQUEST Request
  1010. );
  1011. VOID
  1012. NbiProcessStatusQuery(
  1013. IN PIPX_LOCAL_TARGET RemoteAddress,
  1014. IN ULONG MacOptions,
  1015. IN PUCHAR PacketBuffer,
  1016. IN UINT PacketSize
  1017. );
  1018. VOID
  1019. NbiSendStatusQuery(
  1020. IN PREQUEST Request
  1021. );
  1022. VOID
  1023. NbiProcessStatusResponse(
  1024. IN NDIS_HANDLE MacBindingHandle,
  1025. IN NDIS_HANDLE MacReceiveContext,
  1026. IN PIPX_LOCAL_TARGET RemoteAddress,
  1027. IN ULONG MacOptions,
  1028. IN PUCHAR LookaheadBuffer,
  1029. IN UINT LookaheadBufferSize,
  1030. IN UINT LookaheadBufferOffset,
  1031. IN UINT PacketSize
  1032. );
  1033. //
  1034. // Routines in receive.c
  1035. //
  1036. BOOLEAN
  1037. NbiReceive(
  1038. IN NDIS_HANDLE MacBindingHandle,
  1039. IN NDIS_HANDLE MacReceiveContext,
  1040. IN ULONG_PTR FwdAdapterCtx,
  1041. IN PIPX_LOCAL_TARGET RemoteAddress,
  1042. IN ULONG MacOptions,
  1043. IN PUCHAR LookaheadBuffer,
  1044. IN UINT LookaheadBufferSize,
  1045. IN UINT LookaheadBufferOffset,
  1046. IN UINT PacketSize,
  1047. IN PMDL pMdl
  1048. );
  1049. VOID
  1050. NbiReceiveComplete(
  1051. IN USHORT NicId
  1052. );
  1053. VOID
  1054. NbiTransferDataComplete(
  1055. IN PNDIS_PACKET Packet,
  1056. IN NDIS_STATUS Status,
  1057. IN UINT BytesTransferred
  1058. );
  1059. VOID
  1060. NbiAcknowledgeReceive(
  1061. IN PCONNECTION Connection
  1062. IN NB_LOCK_HANDLE_PARAM(LockHandle)
  1063. );
  1064. VOID
  1065. NbiCompleteReceive(
  1066. IN PCONNECTION Connection,
  1067. IN BOOLEAN EndOfMessage,
  1068. IN CTELockHandle CancelLH
  1069. IN NB_LOCK_HANDLE_PARAM(LockHandle)
  1070. );
  1071. NTSTATUS
  1072. NbiTdiReceive(
  1073. IN PDEVICE Device,
  1074. IN PREQUEST Request
  1075. );
  1076. VOID
  1077. NbiCancelReceive(
  1078. IN PDEVICE_OBJECT DeviceObject,
  1079. IN PIRP Irp
  1080. );
  1081. //
  1082. // Routines in send.c
  1083. //
  1084. VOID
  1085. NbiSendComplete(
  1086. IN PNDIS_PACKET Packet,
  1087. IN NDIS_STATUS Status
  1088. );
  1089. VOID
  1090. NbiAssignSequenceAndSend(
  1091. IN PCONNECTION Connection,
  1092. IN PNDIS_PACKET Packet
  1093. IN NB_LOCK_HANDLE_PARAM(LockHandle)
  1094. );
  1095. NTSTATUS
  1096. NbiTdiSend(
  1097. IN PDEVICE Device,
  1098. IN PREQUEST Request
  1099. );
  1100. VOID
  1101. NbiPacketizeSend(
  1102. IN PCONNECTION Connection
  1103. IN NB_LOCK_HANDLE_PARAM(LockHandle)
  1104. );
  1105. VOID
  1106. NbiReframeConnection(
  1107. IN PCONNECTION Connection,
  1108. IN USHORT ReceiveSequence,
  1109. IN USHORT BytesReceived,
  1110. IN BOOLEAN Resend
  1111. IN NB_LOCK_HANDLE_PARAM(LockHandle)
  1112. );
  1113. VOID
  1114. NbiRestartConnection(
  1115. IN PCONNECTION Connection
  1116. );
  1117. VOID
  1118. NbiAdvanceUnAckedByBytes(
  1119. IN PCONNECTION Connection,
  1120. IN ULONG BytesAcked
  1121. );
  1122. VOID
  1123. NbiAdvanceUnAckedBySequence(
  1124. IN PCONNECTION Connection,
  1125. IN USHORT ReceiveSequence
  1126. );
  1127. VOID
  1128. NbiCancelSend(
  1129. IN PDEVICE_OBJECT DeviceObject,
  1130. IN PIRP Irp
  1131. );
  1132. NTSTATUS
  1133. NbiBuildBufferChainFromBufferChain (
  1134. IN NDIS_HANDLE BufferPoolHandle,
  1135. IN PNDIS_BUFFER CurrentSourceBuffer,
  1136. IN ULONG CurrentByteOffset,
  1137. IN ULONG DesiredLength,
  1138. OUT PNDIS_BUFFER *DestinationBuffer,
  1139. OUT PNDIS_BUFFER *NewSourceBuffer,
  1140. OUT ULONG *NewByteOffset,
  1141. OUT ULONG *ActualLength
  1142. );
  1143. //
  1144. // Routines in session.c
  1145. //
  1146. VOID
  1147. NbiProcessSessionData(
  1148. IN NDIS_HANDLE MacBindingHandle,
  1149. IN NDIS_HANDLE MacReceiveContext,
  1150. IN PIPX_LOCAL_TARGET RemoteAddress,
  1151. IN ULONG MacOptions,
  1152. IN PUCHAR LookaheadBuffer,
  1153. IN UINT LookaheadBufferSize,
  1154. IN UINT LookaheadBufferOffset,
  1155. IN UINT PacketSize
  1156. );
  1157. VOID
  1158. NbiProcessDataAck(
  1159. IN PCONNECTION Connection,
  1160. IN NB_SESSION UNALIGNED * Sess,
  1161. IN PIPX_LOCAL_TARGET RemoteAddress
  1162. IN NB_LOCK_HANDLE_PARAM(LockHandle)
  1163. );
  1164. VOID
  1165. NbiProcessSessionInitialize(
  1166. IN PIPX_LOCAL_TARGET RemoteAddress,
  1167. IN ULONG MacOptions,
  1168. IN PUCHAR PacketBuffer,
  1169. IN UINT PacketSize
  1170. );
  1171. VOID
  1172. NbiProcessSessionInitAck(
  1173. IN PCONNECTION Connection,
  1174. IN NB_SESSION UNALIGNED * Sess
  1175. IN NB_LOCK_HANDLE_PARAM(LockHandle)
  1176. );
  1177. VOID
  1178. NbiProcessSessionEnd(
  1179. IN PIPX_LOCAL_TARGET RemoteAddress,
  1180. IN ULONG MacOptions,
  1181. IN PUCHAR PacketBuffer,
  1182. IN UINT PacketSize
  1183. );
  1184. VOID
  1185. NbiProcessSessionEndAck(
  1186. IN PIPX_LOCAL_TARGET RemoteAddress,
  1187. IN ULONG MacOptions,
  1188. IN PUCHAR PacketBuffer,
  1189. IN UINT PacketSize
  1190. );
  1191. //
  1192. // Routines in timer.c
  1193. //
  1194. VOID
  1195. NbiStartRetransmit(
  1196. IN PCONNECTION Connection
  1197. );
  1198. VOID
  1199. NbiStartWatchdog(
  1200. IN PCONNECTION Connection
  1201. );
  1202. #if DBG
  1203. VOID
  1204. NbiStopRetransmit(
  1205. IN PCONNECTION Connection
  1206. );
  1207. VOID
  1208. NbiStopWatchdog(
  1209. IN PCONNECTION Connection
  1210. );
  1211. #else
  1212. #define NbiStopRetransmit(_Connection) \
  1213. (_Connection)->Retransmit = 0;
  1214. #define NbiStopWatchdog(_Connection) \
  1215. (_Connection)->Watchdog = 0;
  1216. #endif
  1217. VOID
  1218. NbiExpireRetransmit(
  1219. IN PCONNECTION Connection
  1220. );
  1221. VOID
  1222. NbiExpireWatchdog(
  1223. IN PCONNECTION Connection
  1224. );
  1225. VOID
  1226. NbiShortTimeout(
  1227. IN CTEEvent * Event,
  1228. IN PVOID Context
  1229. );
  1230. VOID
  1231. NbiLongTimeout(
  1232. IN CTEEvent * Event,
  1233. IN PVOID Context
  1234. );
  1235. VOID
  1236. NbiStartShortTimer(
  1237. IN PDEVICE Device
  1238. );
  1239. VOID
  1240. NbiInitializeTimers(
  1241. IN PDEVICE Device
  1242. );