Leaked source code of windows server 2003
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.

2536 lines
63 KiB

  1. /*++
  2. Copyright (c) 1989, 1990, 1991 Microsoft Corporation
  3. Module Name:
  4. nbfprocs.h
  5. Abstract:
  6. This header file defines private functions for the NT NBF transport
  7. provider.
  8. Author:
  9. David Beaver (dbeaver) 1-July-1991
  10. Revision History:
  11. --*/
  12. #ifndef _NBFPROCS_
  13. #define _NBFPROCS_
  14. //
  15. // MACROS.
  16. //
  17. //
  18. // Debugging aids
  19. //
  20. //
  21. // VOID
  22. // IF_NBFDBG(
  23. // IN PSZ Message
  24. // );
  25. //
  26. #if DBG
  27. #define IF_NBFDBG(flags) \
  28. if (NbfDebug & (flags))
  29. #else
  30. #define IF_NBFDBG(flags) \
  31. if (0)
  32. #endif
  33. //
  34. // VOID
  35. // PANIC(
  36. // IN PSZ Message
  37. // );
  38. //
  39. #if DBG
  40. #define PANIC(Msg) \
  41. DbgPrint ((Msg))
  42. #else
  43. #define PANIC(Msg)
  44. #endif
  45. //
  46. // These are define to allow DbgPrints that disappear when
  47. // DBG is 0.
  48. //
  49. #if DBG
  50. #define NbfPrint0(fmt) DbgPrint(fmt)
  51. #define NbfPrint1(fmt,v0) DbgPrint(fmt,v0)
  52. #define NbfPrint2(fmt,v0,v1) DbgPrint(fmt,v0,v1)
  53. #define NbfPrint3(fmt,v0,v1,v2) DbgPrint(fmt,v0,v1,v2)
  54. #define NbfPrint4(fmt,v0,v1,v2,v3) DbgPrint(fmt,v0,v1,v2,v3)
  55. #define NbfPrint5(fmt,v0,v1,v2,v3,v4) DbgPrint(fmt,v0,v1,v2,v3,v4)
  56. #define NbfPrint6(fmt,v0,v1,v2,v3,v4,v5) DbgPrint(fmt,v0,v1,v2,v3,v4,v5)
  57. #else
  58. #define NbfPrint0(fmt)
  59. #define NbfPrint1(fmt,v0)
  60. #define NbfPrint2(fmt,v0,v1)
  61. #define NbfPrint3(fmt,v0,v1,v2)
  62. #define NbfPrint4(fmt,v0,v1,v2,v3)
  63. #define NbfPrint5(fmt,v0,v1,v2,v3,v4)
  64. #define NbfPrint6(fmt,v0,v1,v2,v3,v4,v5)
  65. #endif
  66. //
  67. // The REFCOUNTS message take up a lot of room, so make
  68. // removing them easy.
  69. //
  70. #if 1
  71. #define IF_REFDBG IF_NBFDBG (NBF_DEBUG_REFCOUNTS)
  72. #else
  73. #define IF_REFDBG if (0)
  74. #endif
  75. #if DBG
  76. #define NbfReferenceLink( Reason, Link, Type)\
  77. if ((Link)->Destroyed) { \
  78. DbgPrint("NBF: Attempt to reference destroyed link %lx\n", Link); \
  79. DbgBreakPoint(); \
  80. } \
  81. IF_REFDBG { \
  82. DbgPrint ("RefL %x: %s %s, %ld : %ld\n", Link, Reason, __FILE__, __LINE__, (Link)->ReferenceCount);\
  83. }\
  84. (VOID)ExInterlockedAddUlong ( \
  85. (PULONG)(&(Link)->RefTypes[Type]), \
  86. 1, \
  87. &NbfGlobalInterlock); \
  88. NbfRefLink (Link)
  89. #define NbfDereferenceLink(Reason, Link, Type)\
  90. if ((Link)->Destroyed) { \
  91. DbgPrint("NBF: Attempt to dereference destroyed link %lx\n", Link); \
  92. DbgBreakPoint(); \
  93. } \
  94. IF_REFDBG { \
  95. DbgPrint ("DeRefL %x: %s %s, %ld : %ld\n", Link, Reason, __FILE__, __LINE__, (Link)->ReferenceCount);\
  96. } \
  97. (VOID)ExInterlockedAddUlong ( \
  98. (PULONG)(&(Link)->RefTypes[Type]), \
  99. (ULONG)-1, \
  100. &NbfGlobalInterlock); \
  101. NbfDerefLink (Link)
  102. #define NbfDereferenceLinkMacro(Reason, Link, Type)\
  103. NbfDereferenceLink(Reason, Link, Type)
  104. #define NbfReferenceLinkSpecial( Reason, Link, Type)\
  105. if ((Link)->Destroyed) { \
  106. DbgPrint("NBF: Attempt to special reference destroyed link %lx\n", Link); \
  107. DbgBreakPoint(); \
  108. } \
  109. IF_REFDBG { \
  110. DbgPrint ("RefLS %x: %s %s, %ld : %ld\n", Link, Reason, __FILE__, __LINE__, (Link)->SpecialRefCount);\
  111. }\
  112. (VOID)ExInterlockedAddUlong ( \
  113. (PULONG)(&(Link)->RefTypes[Type]), \
  114. 1, \
  115. &NbfGlobalInterlock); \
  116. NbfRefLinkSpecial (Link)
  117. #define NbfDereferenceLinkSpecial(Reason, Link, Type)\
  118. if ((Link)->Destroyed) { \
  119. DbgPrint("NBF: Attempt to special dereference destroyed link %lx\n", Link); \
  120. DbgBreakPoint(); \
  121. } \
  122. IF_REFDBG { \
  123. DbgPrint ("DeRefLS %x: %s %s, %ld : %ld\n", Link, Reason, __FILE__, __LINE__, (Link)->SpecialRefCount);\
  124. } \
  125. (VOID)ExInterlockedAddUlong ( \
  126. (PULONG)(&(Link)->RefTypes[Type]), \
  127. (ULONG)-1, \
  128. &NbfGlobalInterlock); \
  129. NbfDerefLinkSpecial (Link)
  130. #define NbfReferenceConnection(Reason, Connection, Type)\
  131. if ((Connection)->Destroyed) { \
  132. DbgPrint("NBF: Attempt to reference destroyed conn %lx\n", Connection); \
  133. DbgBreakPoint(); \
  134. } \
  135. IF_REFDBG { \
  136. DbgPrint ("RefC %x: %s %s, %ld : %ld\n", Connection, Reason, __FILE__, __LINE__, (Connection)->ReferenceCount);\
  137. } \
  138. (VOID)ExInterlockedAddUlong ( \
  139. (PULONG)(&(Connection)->RefTypes[Type]), \
  140. 1, \
  141. &NbfGlobalInterlock); \
  142. NbfRefConnection (Connection)
  143. #define NbfDereferenceConnection(Reason, Connection, Type)\
  144. if ((Connection)->Destroyed) { \
  145. DbgPrint("NBF: Attempt to dereference destroyed conn %lx\n", Connection); \
  146. DbgBreakPoint(); \
  147. } \
  148. IF_REFDBG { \
  149. DbgPrint ("DeRefC %x: %s %s, %ld : %ld\n", Connection, Reason, __FILE__, __LINE__, (Connection)->ReferenceCount);\
  150. } \
  151. (VOID)ExInterlockedAddUlong ( \
  152. (PULONG)&((Connection)->RefTypes[Type]), \
  153. (ULONG)-1, \
  154. &NbfGlobalInterlock); \
  155. NbfDerefConnection (Connection)
  156. #define NbfDereferenceConnectionMacro(Reason, Connection, Type)\
  157. NbfDereferenceConnection(Reason, Connection, Type)
  158. #define NbfDereferenceConnectionSpecial(Reason, Connection, Type)\
  159. IF_REFDBG { \
  160. DbgPrint ("DeRefCL %x: %s %s, %ld : %ld\n", Connection, Reason, __FILE__, __LINE__, (Connection)->ReferenceCount);\
  161. } \
  162. (VOID)ExInterlockedAddUlong ( \
  163. (PULONG)&((Connection)->RefTypes[Type]), \
  164. (ULONG)-1, \
  165. &NbfGlobalInterlock); \
  166. NbfDerefConnectionSpecial (Connection)
  167. #define NbfReferenceRequest( Reason, Request, Type)\
  168. if ((Request)->Destroyed) { \
  169. DbgPrint("NBF: Attempt to reference destroyed req %lx\n", Request); \
  170. DbgBreakPoint(); \
  171. } \
  172. IF_REFDBG { \
  173. DbgPrint ("RefR %x: %s %s, %ld : %ld\n", Request, Reason, __FILE__, __LINE__, (Request)->ReferenceCount);}\
  174. (VOID)ExInterlockedAddUlong ( \
  175. (PULONG)(&(Request)->RefTypes[Type]), \
  176. 1, \
  177. &NbfGlobalInterlock); \
  178. NbfRefRequest (Request)
  179. #define NbfDereferenceRequest(Reason, Request, Type)\
  180. if ((Request)->Destroyed) { \
  181. DbgPrint("NBF: Attempt to dereference destroyed req %lx\n", Request); \
  182. DbgBreakPoint(); \
  183. } \
  184. IF_REFDBG { \
  185. DbgPrint ("DeRefR %x: %s %s, %ld : %ld\n", Request, Reason, __FILE__, __LINE__, (Request)->ReferenceCount);\
  186. } \
  187. (VOID)ExInterlockedAddUlong ( \
  188. (PULONG)(&(Request)->RefTypes[Type]), \
  189. (ULONG)-1, \
  190. &NbfGlobalInterlock); \
  191. NbfDerefRequest (Request)
  192. #define NbfReferenceSendIrp( Reason, IrpSp, Type)\
  193. IF_REFDBG { \
  194. DbgPrint ("RefSI %x: %s %s, %ld : %ld\n", IrpSp, Reason, __FILE__, __LINE__, IRP_SEND_REFCOUNT(IrpSp));}\
  195. NbfRefSendIrp (IrpSp)
  196. #define NbfDereferenceSendIrp(Reason, IrpSp, Type)\
  197. IF_REFDBG { \
  198. DbgPrint ("DeRefSI %x: %s %s, %ld : %ld\n", IrpSp, Reason, __FILE__, __LINE__, IRP_SEND_REFCOUNT(IrpSp));\
  199. } \
  200. NbfDerefSendIrp (IrpSp)
  201. #define NbfReferenceReceiveIrpLocked( Reason, IrpSp, Type)\
  202. IF_REFDBG { \
  203. DbgPrint ("RefRI %x: %s %s, %ld : %ld\n", IrpSp, Reason, __FILE__, __LINE__, IRP_RECEIVE_REFCOUNT(IrpSp));}\
  204. NbfRefReceiveIrpLocked (IrpSp)
  205. #define NbfDereferenceReceiveIrp(Reason, IrpSp, Type)\
  206. IF_REFDBG { \
  207. DbgPrint ("DeRefRI %x: %s %s, %ld : %ld\n", IrpSp, Reason, __FILE__, __LINE__, IRP_RECEIVE_REFCOUNT(IrpSp));\
  208. } \
  209. NbfDerefReceiveIrp (IrpSp)
  210. #define NbfDereferenceReceiveIrpLocked(Reason, IrpSp, Type)\
  211. IF_REFDBG { \
  212. DbgPrint ("DeRefRILocked %x: %s %s, %ld : %ld\n", IrpSp, Reason, __FILE__, __LINE__, IRP_RECEIVE_REFCOUNT(IrpSp));\
  213. } \
  214. NbfDerefReceiveIrpLocked (IrpSp)
  215. #define NbfReferenceAddress( Reason, Address, Type)\
  216. IF_REFDBG { \
  217. DbgPrint ("RefA %x: %s %s, %ld : %ld\n", Address, Reason, __FILE__, __LINE__, (Address)->ReferenceCount);}\
  218. (VOID)ExInterlockedAddUlong ( \
  219. (PULONG)(&(Address)->RefTypes[Type]), \
  220. 1, \
  221. &NbfGlobalInterlock); \
  222. NbfRefAddress (Address)
  223. #define NbfDereferenceAddress(Reason, Address, Type)\
  224. IF_REFDBG { \
  225. DbgPrint ("DeRefA %x: %s %s, %ld : %ld\n", Address, Reason, __FILE__, __LINE__, (Address)->ReferenceCount);\
  226. } \
  227. (VOID)ExInterlockedAddUlong ( \
  228. (PULONG)(&(Address)->RefTypes[Type]), \
  229. (ULONG)-1, \
  230. &NbfGlobalInterlock); \
  231. NbfDerefAddress (Address)
  232. #define NbfReferenceDeviceContext( Reason, DeviceContext, Type)\
  233. if ((DeviceContext)->ReferenceCount == 0) \
  234. DbgBreakPoint(); \
  235. IF_REFDBG { \
  236. DbgPrint ("RefDC %x: %s %s, %ld : %ld\n", DeviceContext, Reason, __FILE__, __LINE__, (DeviceContext)->ReferenceCount);}\
  237. (VOID)ExInterlockedAddUlong ( \
  238. (PULONG)(&(DeviceContext)->RefTypes[Type]), \
  239. 1, \
  240. &NbfGlobalInterlock); \
  241. NbfRefDeviceContext (DeviceContext)
  242. #define NbfDereferenceDeviceContext(Reason, DeviceContext, Type)\
  243. if ((DeviceContext)->ReferenceCount == 0) \
  244. DbgBreakPoint(); \
  245. IF_REFDBG { \
  246. DbgPrint ("DeRefDC %x: %s %s, %ld : %ld\n", DeviceContext, Reason, __FILE__, __LINE__, (DeviceContext)->ReferenceCount);\
  247. } \
  248. (VOID)ExInterlockedAddUlong ( \
  249. (PULONG)(&(DeviceContext)->RefTypes[Type]), \
  250. (ULONG)-1, \
  251. &NbfGlobalInterlock); \
  252. NbfDerefDeviceContext (DeviceContext)
  253. #else
  254. #if defined(NBF_UP)
  255. #define NbfReferenceLink(Reason, Link, Type) \
  256. { \
  257. ULONG _ref; \
  258. _ref = ++(Link)->ReferenceCount; \
  259. if ( _ref == 0 ) { \
  260. NbfReferenceLinkSpecial ("first ref", (Link), LREF_SPECIAL_TEMP); \
  261. } \
  262. }
  263. #else
  264. #define NbfReferenceLink(Reason, Link, Type) \
  265. if (InterlockedIncrement( \
  266. &(Link)->ReferenceCount) == 0) { \
  267. NbfReferenceLinkSpecial ("first ref", (Link), LREF_SPECIAL_TEMP); \
  268. }
  269. #endif
  270. #define NbfDereferenceLink(Reason, Link, Type)\
  271. NbfDereferenceLinkMacro(Reason,Link,Type)
  272. #if defined(NBF_UP)
  273. #define NbfDereferenceLinkMacro(Reason, Link, Type){ \
  274. ULONG _ref; \
  275. _ref = --(Link)->ReferenceCount; \
  276. if (_ref < 0) { \
  277. NbfDisconnectLink (Link); \
  278. NbfDerefLinkSpecial (Link); \
  279. } \
  280. }
  281. #else
  282. #define NbfDereferenceLinkMacro(Reason, Link, Type){ \
  283. if (InterlockedDecrement( \
  284. &(Link)->ReferenceCount) < 0) { \
  285. NbfDisconnectLink (Link); \
  286. NbfDerefLinkSpecial (Link); \
  287. } \
  288. }
  289. #endif
  290. #define NbfReferenceLinkSpecial(Reason, Link, Type)\
  291. NbfRefLinkSpecial (Link)
  292. #define NbfDereferenceLinkSpecial(Reason, Link, Type)\
  293. NbfDerefLinkSpecial (Link)
  294. #define NbfReferenceConnection(Reason, Connection, Type)\
  295. if (((Connection)->ReferenceCount == -1) && \
  296. ((Connection)->SpecialRefCount == 0)) \
  297. DbgBreakPoint(); \
  298. \
  299. if (InterlockedIncrement( \
  300. &(Connection)->ReferenceCount) == 0) { \
  301. ExInterlockedAddUlong( \
  302. (PULONG)(&(Connection)->SpecialRefCount), \
  303. 1, \
  304. (Connection)->ProviderInterlock); \
  305. }
  306. #define NbfDereferenceConnection(Reason, Connection, Type)\
  307. if (((Connection)->ReferenceCount == -1) && \
  308. ((Connection)->SpecialRefCount == 0)) \
  309. DbgBreakPoint(); \
  310. \
  311. NbfDerefConnection (Connection)
  312. #define NbfDereferenceConnectionMacro(Reason, Connection, Type){ \
  313. if (((Connection)->ReferenceCount == -1) && \
  314. ((Connection)->SpecialRefCount == 0)) \
  315. DbgBreakPoint(); \
  316. \
  317. \
  318. if (InterlockedDecrement( \
  319. &(Connection)->ReferenceCount) < 0) { \
  320. if (NbfDisconnectFromLink (Connection, TRUE)) { \
  321. NbfIndicateDisconnect (Connection); \
  322. } \
  323. NbfDerefConnectionSpecial (Connection); \
  324. } \
  325. }
  326. #define NbfDereferenceConnectionSpecial(Reason, Connection, Type)\
  327. NbfDerefConnectionSpecial (Connection)
  328. #define NbfReferenceRequest(Reason, Request, Type)\
  329. (VOID)InterlockedIncrement( \
  330. &(Request)->ReferenceCount)
  331. #define NbfDereferenceRequest(Reason, Request, Type)\
  332. NbfDerefRequest (Request)
  333. #define NbfReferenceSendIrp(Reason, IrpSp, Type)\
  334. (VOID)InterlockedIncrement( \
  335. &IRP_SEND_REFCOUNT(IrpSp))
  336. #define NbfDereferenceSendIrp(Reason, IrpSp, Type) {\
  337. PIO_STACK_LOCATION _IrpSp = (IrpSp); \
  338. if (InterlockedDecrement( \
  339. &IRP_SEND_REFCOUNT(_IrpSp)) == 0) { \
  340. PIRP _Irp = IRP_SEND_IRP(_IrpSp); \
  341. IRP_SEND_REFCOUNT(_IrpSp) = 0; \
  342. IRP_SEND_IRP (_IrpSp) = NULL; \
  343. IoCompleteRequest (_Irp, IO_NETWORK_INCREMENT); \
  344. } \
  345. }
  346. #define NbfReferenceReceiveIrpLocked(Reason, IrpSp, Type)\
  347. ++IRP_RECEIVE_REFCOUNT(IrpSp)
  348. #define NbfDereferenceReceiveIrp(Reason, IrpSp, Type)\
  349. NbfDerefReceiveIrp (IrpSp)
  350. #define NbfDereferenceReceiveIrpLocked(Reason, IrpSp, Type) { \
  351. if (--IRP_RECEIVE_REFCOUNT(IrpSp) == 0) { \
  352. ExInterlockedInsertTailList( \
  353. &(IRP_DEVICE_CONTEXT(IrpSp)->IrpCompletionQueue), \
  354. &(IRP_RECEIVE_IRP(IrpSp))->Tail.Overlay.ListEntry, \
  355. &(IRP_DEVICE_CONTEXT(IrpSp)->Interlock)); \
  356. } \
  357. }
  358. #define NbfReferenceAddress(Reason, Address, Type)\
  359. if ((Address)->ReferenceCount <= 0){ DbgBreakPoint(); }\
  360. (VOID)InterlockedIncrement(&(Address)->ReferenceCount)
  361. #define NbfDereferenceAddress(Reason, Address, Type)\
  362. if ((Address)->ReferenceCount <= 0){ DbgBreakPoint(); }\
  363. NbfDerefAddress (Address)
  364. #define NbfReferenceDeviceContext(Reason, DeviceContext, Type)\
  365. if ((DeviceContext)->ReferenceCount == 0) \
  366. DbgBreakPoint(); \
  367. NbfRefDeviceContext (DeviceContext)
  368. #define NbfDereferenceDeviceContext(Reason, DeviceContext, Type)\
  369. if ((DeviceContext)->ReferenceCount == 0) \
  370. DbgBreakPoint(); \
  371. NbfDerefDeviceContext (DeviceContext)
  372. #define NbfReferencePacket(Packet) \
  373. (VOID)InterlockedIncrement(&(Packet)->ReferenceCount)
  374. #define NbfDereferencePacket(Packet){ \
  375. if (InterlockedDecrement ( \
  376. &(Packet)->ReferenceCount) == 0) { \
  377. NbfDestroyPacket (Packet); \
  378. } \
  379. }
  380. #endif
  381. //
  382. // Error and statistics Macros
  383. //
  384. // VOID
  385. // LogErrorToSystem(
  386. // NTSTATUS ErrorType,
  387. // PUCHAR ErrorDescription
  388. // )
  389. /*++
  390. Routine Description:
  391. This routine is called to log an error from the transport to the system.
  392. Errors that are of system interest should be logged using this interface.
  393. For now, this macro is defined trivially.
  394. Arguments:
  395. ErrorType - The error type, a conventional NT status
  396. ErrorDescription - A pointer to a string describing the error.
  397. Return Value:
  398. none.
  399. --*/
  400. #if DBG
  401. #define LogErrorToSystem( ErrorType, ErrorDescription) \
  402. DbgPrint ("Logging error: File: %s Line: %ld \n Description: %s\n",__FILE__, __LINE__, ErrorDescription)
  403. #else
  404. #define LogErrorToSystem( ErrorType, ErrorDescription)
  405. #endif
  406. //
  407. // Routines in TIMER.C (lightweight timer system package).
  408. // Note that all the start and stop routines for the timers assume that you
  409. // have the link spinlock when you call them!
  410. // Note also that, with the latest revisions, the timer system now works by
  411. // putting those links that have timers running on a list of links to be looked
  412. // at for each clock tick. This list is ordered, with the most recently inserted
  413. // elements at the tail of the list. Note further that anything already on the
  414. // is moved to the end of the list if the timer is restarted; thus, the list
  415. // order is preserved.
  416. //
  417. VOID
  418. NbfStartShortTimer(
  419. IN PDEVICE_CONTEXT DeviceContext
  420. );
  421. VOID
  422. NbfInitializeTimerSystem(
  423. IN PDEVICE_CONTEXT DeviceContext
  424. );
  425. VOID
  426. NbfStopTimerSystem(
  427. IN PDEVICE_CONTEXT DeviceContext
  428. );
  429. VOID
  430. StartT1(
  431. IN PTP_LINK Link,
  432. IN ULONG PacketSize
  433. );
  434. VOID
  435. StartT2(
  436. IN PTP_LINK Link
  437. );
  438. VOID
  439. StartTi(
  440. IN PTP_LINK Link
  441. );
  442. #if DBG
  443. VOID
  444. StopT1(
  445. IN PTP_LINK Link
  446. );
  447. VOID
  448. StopT2(
  449. IN PTP_LINK Link
  450. );
  451. VOID
  452. StopTi(
  453. IN PTP_LINK Link
  454. );
  455. #else
  456. #define StopT1(_Link) \
  457. { \
  458. (_Link)->CurrentPollOutstanding = FALSE; \
  459. (_Link)->T1 = 0; \
  460. }
  461. #define StopT2(_Link) \
  462. { \
  463. (_Link)->ConsecutiveIFrames = 0; \
  464. (_Link)->T2 = 0; \
  465. }
  466. #define StopTi(_Link) \
  467. (_Link)->Ti = 0;
  468. #endif
  469. //
  470. // These functions may become macros once they are finished.
  471. //
  472. ULONG
  473. GetTimerInterval(
  474. IN PTP_LINK Link
  475. );
  476. VOID
  477. BackoffCurrentT1Timeout(
  478. IN PTP_LINK Link
  479. );
  480. VOID
  481. UpdateBaseT1Timeout(
  482. IN PTP_LINK Link
  483. );
  484. VOID
  485. CancelT1Timeout(
  486. IN PTP_LINK Link
  487. );
  488. VOID
  489. UpdateDelayAndThroughput(
  490. IN PTP_LINK Link,
  491. IN ULONG TimerInterval
  492. );
  493. VOID
  494. FakeStartT1(
  495. IN PTP_LINK Link,
  496. IN ULONG PacketSize
  497. );
  498. VOID
  499. FakeUpdateBaseT1Timeout(
  500. IN PTP_LINK Link
  501. );
  502. //
  503. // Timer Macros - these are make sure that no timers are
  504. // executing after we finish call to NbfStopTimerSystem
  505. //
  506. // State Descriptions -
  507. //
  508. // If TimerState is
  509. // < TIMERS_ENABLED - Multiple ENABLE_TIMERS happened,
  510. // Will be corrected in an instant
  511. //
  512. // = TIMERS_ENABLED - ENABLE_TIMERS done but no timers
  513. // that have gone through START_TIMER
  514. // but not yet executed a LEAVE_TIMER
  515. //
  516. // > TIMERS_ENABLED &&
  517. // < TIMERS_DISABLED - ENABLE_TIMERS done and num timers =
  518. // (TimerInitialized - TIMERS_ENABLED)
  519. // that have gone through START_TIMER
  520. // but not yet executed a LEAVE_TIMER
  521. //
  522. // = TIMERS_DISABLED - DISABLE_TIMERS done and no timers
  523. // executing timer code at this pt
  524. // [This is also the initial state]
  525. //
  526. // > TIMERS_DISABLED &&
  527. // < TIMERS_DISABLED + TIMERS_RANGE
  528. // - DISABLE_TIMERS done and num timers =
  529. // (TimerInitialized - TIMERS_ENABLED)
  530. // that have gone through START_TIMER
  531. // but not yet executed a LEAVE_TIMER
  532. //
  533. // >= TIMERS_DISABLED + TIMERS_RANGE
  534. // - Multiple DISABLE_TIMERS happened,
  535. // Will be corrected in an instant
  536. //
  537. // Allow basically TIMER_RANGE = 2^24 timers
  538. // (and 2^8 / 2 simultaneous stops or starts)
  539. //
  540. #if DBG_TIMER
  541. #define DbgTimer DbgPrint
  542. #else
  543. #define DbgTimer
  544. #endif
  545. #define TIMERS_ENABLED 0x08000000
  546. #define TIMERS_DISABLED 0x09000000
  547. #define TIMERS_RANGE_ADD 0x01000000 /* TIMERS_DISABLED - TIMERS_ENABLED */
  548. #define TIMERS_RANGE_SUB 0xFF000000 /* TIMERS_ENABLED - TIMERS_DISABLED */
  549. #define INITIALIZE_TIMER_STATE(DeviceContext) \
  550. DbgTimer("*--------------- Timers State Initialized ---------*\n"); \
  551. /* Initial state is set to timers disabled */ \
  552. DeviceContext->TimerState = TIMERS_DISABLED; \
  553. #define TIMERS_INITIALIZED(DeviceContext) \
  554. (DeviceContext->TimerState == TIMERS_DISABLED) \
  555. #define ENABLE_TIMERS(DeviceContext) \
  556. { \
  557. ULONG Count; \
  558. \
  559. DbgTimer("*--------------- Enabling Timers ------------------*\n"); \
  560. Count= InterlockedExchangeAdd(&DeviceContext->TimerState, \
  561. TIMERS_RANGE_SUB); \
  562. DbgTimer("Count = %08x, TimerState = %08x\n", Count, \
  563. DeviceContext->TimerState); \
  564. if (Count < TIMERS_ENABLED) \
  565. { \
  566. DbgTimer("*--------------- Timers Already Enabled -----------*\n"); \
  567. /* We have already enabled the timers */ \
  568. InterlockedExchangeAdd(&DeviceContext->TimerState, \
  569. TIMERS_RANGE_ADD); \
  570. DbgTimer("Count = %08x, TimerState = %08x\n", Count, \
  571. DeviceContext->TimerState); \
  572. } \
  573. DbgTimer("*--------------- Enabling Timers Done -------------*\n"); \
  574. } \
  575. #define DISABLE_TIMERS(DeviceContext) \
  576. { \
  577. ULONG Count; \
  578. \
  579. DbgTimer("*--------------- Disabling Timers -----------------*\n"); \
  580. Count= InterlockedExchangeAdd(&DeviceContext->TimerState, \
  581. TIMERS_RANGE_ADD); \
  582. DbgTimer("Count = %08x, TimerState = %08x\n", Count, \
  583. DeviceContext->TimerState); \
  584. if (Count >= TIMERS_DISABLED) \
  585. { \
  586. DbgTimer("*--------------- Timers Already Disabled ----------*\n"); \
  587. /* We have already disabled the timers */ \
  588. InterlockedExchangeAdd(&DeviceContext->TimerState, \
  589. TIMERS_RANGE_SUB); \
  590. DbgTimer("Count = %08x, TimerState = %08x\n", Count, \
  591. DeviceContext->TimerState); \
  592. } \
  593. \
  594. /* Loop until we have zero timers active */ \
  595. while (*((ULONG volatile *)&DeviceContext->TimerState)!=TIMERS_DISABLED)\
  596. DbgTimer("Number of timers active = %08x\n", \
  597. DeviceContext->TimerState \
  598. - TIMERS_DISABLED); \
  599. DbgTimer("*--------------- Disabling Timers Done ------------*\n"); \
  600. } \
  601. #define START_TIMER(DeviceContext, TimerId, Timer, DueTime, Dpc) \
  602. /*DbgTimer("*---------- Entering Timer %d ---------*\n", TimerId);*/\
  603. if (InterlockedIncrement(&DeviceContext->TimerState) < \
  604. TIMERS_DISABLED) \
  605. { \
  606. KeSetTimer(Timer, DueTime, Dpc); \
  607. } \
  608. else \
  609. { \
  610. /* Timers disabled - get out and reset */ \
  611. NbfDereferenceDeviceContext("Timers disabled", \
  612. DeviceContext, \
  613. DCREF_SCAN_TIMER); \
  614. LEAVE_TIMER(DeviceContext, TimerId); \
  615. } \
  616. /*DbgTimer("*---------- Entering Done %d ---------*\n", TimerId);*/\
  617. #define LEAVE_TIMER(DeviceContext, TimerId) \
  618. /* Get out and adjust the time count */ \
  619. /*DbgTimer("*---------- Leaving Timer %d ---------*\n", TimerId);*/ \
  620. InterlockedDecrement(&DeviceContext->TimerState); \
  621. /*DbgTimer("*---------- Leaving Done %d ---------*\n", TimerId);*/ \
  622. // Basic timer types (just for debugging)
  623. #define LONG_TIMER 0
  624. #define SHORT_TIMER 1
  625. //
  626. // These macros are used to create and destroy packets, due
  627. // to the allocation or deallocation of structure which
  628. // need them.
  629. //
  630. #define NbfAddUIFrame(DeviceContext) { \
  631. PTP_UI_FRAME _UIFrame; \
  632. NbfAllocateUIFrame ((DeviceContext), &_UIFrame); \
  633. if (_UIFrame != NULL) { \
  634. ExInterlockedInsertTailList( \
  635. &(DeviceContext)->UIFramePool, \
  636. &_UIFrame->Linkage, \
  637. &(DeviceContext)->Interlock); \
  638. } \
  639. }
  640. #define NbfRemoveUIFrame(DeviceContext) { \
  641. PLIST_ENTRY p; \
  642. if (DeviceContext->UIFrameAllocated > DeviceContext->UIFrameInitAllocated) { \
  643. p = ExInterlockedRemoveHeadList( \
  644. &(DeviceContext)->UIFramePool, \
  645. &(DeviceContext)->Interlock); \
  646. if (p != NULL) { \
  647. NbfDeallocateUIFrame((DeviceContext), \
  648. (PTP_UI_FRAME)CONTAINING_RECORD(p, TP_UI_FRAME, Linkage)); \
  649. } \
  650. } \
  651. }
  652. #define NbfAddSendPacket(DeviceContext) { \
  653. PTP_PACKET _SendPacket; \
  654. NbfAllocateSendPacket ((DeviceContext), &_SendPacket); \
  655. if (_SendPacket != NULL) { \
  656. ExInterlockedPushEntryList( \
  657. &(DeviceContext)->PacketPool, \
  658. (PSINGLE_LIST_ENTRY)&_SendPacket->Linkage, \
  659. &(DeviceContext)->Interlock); \
  660. } \
  661. }
  662. #define NbfRemoveSendPacket(DeviceContext) { \
  663. PSINGLE_LIST_ENTRY s; \
  664. if (DeviceContext->PacketAllocated > DeviceContext->PacketInitAllocated) { \
  665. s = ExInterlockedPopEntryList( \
  666. &(DeviceContext)->PacketPool, \
  667. &(DeviceContext)->Interlock); \
  668. if (s != NULL) { \
  669. NbfDeallocateSendPacket((DeviceContext), \
  670. (PTP_PACKET)CONTAINING_RECORD(s, TP_PACKET, Linkage)); \
  671. } \
  672. } \
  673. }
  674. #define NbfAddReceivePacket(DeviceContext) { \
  675. if (!(DeviceContext)->MacInfo.SingleReceive) { \
  676. PNDIS_PACKET _ReceivePacket; \
  677. NbfAllocateReceivePacket ((DeviceContext), &_ReceivePacket); \
  678. if (_ReceivePacket != NULL) { \
  679. ExInterlockedPushEntryList( \
  680. &(DeviceContext)->ReceivePacketPool, \
  681. &((PRECEIVE_PACKET_TAG)_ReceivePacket->ProtocolReserved)->Linkage, \
  682. &(DeviceContext)->Interlock); \
  683. } \
  684. } \
  685. }
  686. #define NbfRemoveReceivePacket(DeviceContext) { \
  687. PSINGLE_LIST_ENTRY s; \
  688. if (DeviceContext->ReceivePacketAllocated > DeviceContext->ReceivePacketInitAllocated) { \
  689. s = ExInterlockedPopEntryList( \
  690. &(DeviceContext)->ReceivePacketPool, \
  691. &(DeviceContext)->Interlock); \
  692. if (s != NULL) { \
  693. NbfDeallocateReceivePacket((DeviceContext), \
  694. (PNDIS_PACKET)CONTAINING_RECORD(s, NDIS_PACKET, ProtocolReserved[0])); \
  695. } \
  696. } \
  697. }
  698. #define NbfAddReceiveBuffer(DeviceContext) { \
  699. if (!(DeviceContext)->MacInfo.SingleReceive) { \
  700. PBUFFER_TAG _ReceiveBuffer; \
  701. NbfAllocateReceiveBuffer ((DeviceContext), &_ReceiveBuffer); \
  702. if (_ReceiveBuffer != NULL) { \
  703. ExInterlockedPushEntryList( \
  704. &(DeviceContext)->ReceiveBufferPool, \
  705. (PSINGLE_LIST_ENTRY)&_ReceiveBuffer->Linkage, \
  706. &(DeviceContext)->Interlock); \
  707. } \
  708. } \
  709. }
  710. #define NbfRemoveReceiveBuffer(DeviceContext) { \
  711. PSINGLE_LIST_ENTRY s; \
  712. if (DeviceContext->ReceiveBufferAllocated > DeviceContext->ReceiveBufferInitAllocated) { \
  713. s = ExInterlockedPopEntryList( \
  714. &(DeviceContext)->ReceiveBufferPool, \
  715. &(DeviceContext)->Interlock); \
  716. if (s != NULL) { \
  717. NbfDeallocateReceiveBuffer(DeviceContext, \
  718. (PBUFFER_TAG)CONTAINING_RECORD(s, BUFFER_TAG, Linkage)); \
  719. } \
  720. } \
  721. }
  722. //
  723. // These routines are used to maintain counters.
  724. //
  725. #define INCREMENT_COUNTER(_DeviceContext,_Field) \
  726. ++(_DeviceContext)->Statistics._Field
  727. #define DECREMENT_COUNTER(_DeviceContext,_Field) \
  728. --(_DeviceContext)->Statistics._Field
  729. #define ADD_TO_LARGE_INTEGER(_LargeInteger,_Ulong) \
  730. ExInterlockedAddLargeStatistic((_LargeInteger), (ULONG)(_Ulong))
  731. //
  732. // Routines in PACKET.C (TP_PACKET object manager).
  733. //
  734. VOID
  735. NbfAllocateUIFrame(
  736. IN PDEVICE_CONTEXT DeviceContext,
  737. OUT PTP_UI_FRAME *TransportUIFrame
  738. );
  739. VOID
  740. NbfAllocateSendPacket(
  741. IN PDEVICE_CONTEXT DeviceContext,
  742. OUT PTP_PACKET *TransportSendPacket
  743. );
  744. VOID
  745. NbfAllocateReceivePacket(
  746. IN PDEVICE_CONTEXT DeviceContext,
  747. OUT PNDIS_PACKET *TransportReceivePacket
  748. );
  749. VOID
  750. NbfAllocateReceiveBuffer(
  751. IN PDEVICE_CONTEXT DeviceContext,
  752. OUT PBUFFER_TAG *TransportReceiveBuffer
  753. );
  754. VOID
  755. NbfDeallocateUIFrame(
  756. IN PDEVICE_CONTEXT DeviceContext,
  757. IN PTP_UI_FRAME TransportUIFrame
  758. );
  759. VOID
  760. NbfDeallocateSendPacket(
  761. IN PDEVICE_CONTEXT DeviceContext,
  762. IN PTP_PACKET TransportSendPacket
  763. );
  764. VOID
  765. NbfDeallocateReceivePacket(
  766. IN PDEVICE_CONTEXT DeviceContext,
  767. IN PNDIS_PACKET TransportReceivePacket
  768. );
  769. VOID
  770. NbfDeallocateReceiveBuffer(
  771. IN PDEVICE_CONTEXT DeviceContext,
  772. IN PBUFFER_TAG TransportReceiveBuffer
  773. );
  774. NTSTATUS
  775. NbfCreatePacket(
  776. IN PDEVICE_CONTEXT DeviceContext,
  777. IN PTP_LINK Link,
  778. OUT PTP_PACKET *Packet
  779. );
  780. NTSTATUS
  781. NbfCreateRrPacket(
  782. IN PDEVICE_CONTEXT DeviceContext,
  783. IN PTP_LINK Link,
  784. OUT PTP_PACKET *Packet
  785. );
  786. VOID
  787. NbfDestroyPacket(
  788. IN PTP_PACKET Packet
  789. );
  790. VOID
  791. NbfGrowSendPacketPool(
  792. IN PDEVICE_CONTEXT DeviceContext
  793. );
  794. #if DBG
  795. VOID
  796. NbfReferencePacket(
  797. IN PTP_PACKET Packet
  798. );
  799. VOID
  800. NbfDereferencePacket(
  801. IN PTP_PACKET Packet
  802. );
  803. #endif
  804. VOID
  805. NbfWaitPacket(
  806. IN PTP_CONNECTION Connection,
  807. IN ULONG Flags
  808. );
  809. #if DBG
  810. #define MAGIC 1
  811. extern BOOLEAN NbfEnableMagic;
  812. #else
  813. #define MAGIC 0
  814. #endif
  815. #if MAGIC
  816. VOID
  817. NbfSendMagicBullet (
  818. IN PDEVICE_CONTEXT DeviceContext,
  819. IN PTP_LINK Link
  820. );
  821. #endif
  822. //
  823. // Routines in RCVENG.C (Receive engine).
  824. //
  825. VOID
  826. AwakenReceive(
  827. IN PTP_CONNECTION Connection
  828. );
  829. VOID
  830. ActivateReceive(
  831. IN PTP_CONNECTION Connection
  832. );
  833. VOID
  834. CompleteReceive (
  835. IN PTP_CONNECTION Connection,
  836. IN BOOLEAN EndOfMessage,
  837. IN ULONG BytesTransferred
  838. );
  839. VOID
  840. NbfCancelReceive(
  841. IN PDEVICE_OBJECT DeviceObject,
  842. IN PIRP Irp
  843. );
  844. VOID
  845. NbfCancelReceiveDatagram(
  846. IN PDEVICE_OBJECT DeviceObject,
  847. IN PIRP Irp
  848. );
  849. //
  850. // Routines in SEND.C (Receive engine).
  851. //
  852. NTSTATUS
  853. NbfTdiSend(
  854. IN PIRP Irp
  855. );
  856. NTSTATUS
  857. NbfTdiSendDatagram(
  858. IN PIRP Irp
  859. );
  860. //
  861. // Routines in SENDENG.C (Send engine).
  862. //
  863. #if DBG
  864. VOID
  865. InitializeSend(
  866. PTP_CONNECTION Connection
  867. );
  868. #else
  869. // See SENDENG.C for the fully-commented description of InitializeSend.
  870. #define InitializeSend(_conn_) { \
  871. PIRP _irp_; \
  872. (_conn_)->SendState = CONNECTION_SENDSTATE_PACKETIZE; \
  873. _irp_ = CONTAINING_RECORD ((_conn_)->SendQueue.Flink, \
  874. IRP, \
  875. Tail.Overlay.ListEntry); \
  876. (_conn_)->FirstSendIrp = (_conn_)->sp.CurrentSendIrp = _irp_; \
  877. (_conn_)->FirstSendMdl = (_conn_)->sp.CurrentSendMdl = \
  878. _irp_->MdlAddress; \
  879. (_conn_)->FirstSendByteOffset = (_conn_)->sp.SendByteOffset = 0; \
  880. (_conn_)->sp.MessageBytesSent = 0; \
  881. (_conn_)->CurrentSendLength = \
  882. IRP_SEND_LENGTH(IoGetCurrentIrpStackLocation(_irp_)); \
  883. (_conn_)->StallCount = 0; \
  884. (_conn_)->StallBytesSent = 0; \
  885. if ((_conn_)->NetbiosHeader.ResponseCorrelator == 0xffff) { \
  886. (_conn_)->NetbiosHeader.ResponseCorrelator = 1; \
  887. } else { \
  888. ++((_conn_)->NetbiosHeader.ResponseCorrelator); \
  889. } \
  890. }
  891. #endif
  892. // See SENDENG.C for the fully-commented description of
  893. // StartPacketizingConnection. On a free build this is a
  894. // macro for speed.
  895. #if DBG
  896. VOID
  897. StartPacketizingConnection(
  898. PTP_CONNECTION Connection,
  899. IN BOOLEAN Immediate
  900. );
  901. #else
  902. #define StartPacketizingConnection(_conn_,_immed_) { \
  903. PDEVICE_CONTEXT _devctx_; \
  904. _devctx_ = (_conn_)->Provider; \
  905. if (((_conn_)->SendState == CONNECTION_SENDSTATE_PACKETIZE) && \
  906. !((_conn_)->Flags & CONNECTION_FLAGS_PACKETIZE)) { \
  907. (_conn_)->Flags |= CONNECTION_FLAGS_PACKETIZE; \
  908. if (!(_immed_)) { \
  909. NbfReferenceConnection("Packetize", \
  910. (_conn_), \
  911. CREF_PACKETIZE_QUEUE); \
  912. } \
  913. ExInterlockedInsertTailList (&_devctx_->PacketizeQueue, \
  914. &(_conn_)->PacketizeLinkage, \
  915. &_devctx_->SpinLock); \
  916. RELEASE_DPC_SPIN_LOCK ((_conn_)->LinkSpinLock); \
  917. } else { \
  918. RELEASE_DPC_SPIN_LOCK ((_conn_)->LinkSpinLock); \
  919. if (_immed_) { \
  920. NbfDereferenceConnection("temp TdiSend", (_conn_), CREF_BY_ID); \
  921. } \
  922. } \
  923. if (_immed_) { \
  924. PacketizeConnections (_devctx_); \
  925. } \
  926. }
  927. #endif
  928. VOID
  929. PacketizeConnections(
  930. IN PDEVICE_CONTEXT DeviceContext
  931. );
  932. VOID
  933. PacketizeSend(
  934. IN PTP_CONNECTION Connection,
  935. IN BOOLEAN Direct
  936. );
  937. BOOLEAN
  938. ResendLlcPackets(
  939. IN PTP_LINK Link,
  940. IN UCHAR AckSequenceNumber,
  941. IN BOOLEAN Resend
  942. );
  943. VOID
  944. CompleteSend(
  945. IN PTP_CONNECTION Connection,
  946. IN USHORT Correlator
  947. );
  948. VOID
  949. FailSend(
  950. IN PTP_CONNECTION Connection,
  951. IN NTSTATUS RequestStatus,
  952. IN BOOLEAN StopConnection
  953. );
  954. VOID
  955. ReframeSend(
  956. IN PTP_CONNECTION Connection,
  957. IN ULONG BytesReceived
  958. );
  959. VOID
  960. NbfCancelSend(
  961. IN PDEVICE_OBJECT DeviceObject,
  962. IN PIRP Irp
  963. );
  964. NTSTATUS
  965. SendOnePacket(
  966. IN PTP_CONNECTION Connection,
  967. IN PTP_PACKET Packet,
  968. IN BOOLEAN ForceAck,
  969. OUT PBOOLEAN LinkCheckpoint OPTIONAL
  970. );
  971. VOID
  972. SendControlPacket(
  973. IN PTP_LINK Link,
  974. IN PTP_PACKET Packet
  975. );
  976. VOID
  977. NbfNdisSend(
  978. IN PTP_LINK Link,
  979. IN PTP_PACKET Packet
  980. );
  981. VOID
  982. RestartLinkTraffic(
  983. IN PTP_LINK Link
  984. );
  985. VOID
  986. NbfSendCompletionHandler(
  987. IN NDIS_HANDLE ProtocolBindingContext,
  988. IN PNDIS_PACKET NdisPacket,
  989. IN NDIS_STATUS NdisStatus
  990. );
  991. NTSTATUS
  992. BuildBufferChainFromMdlChain (
  993. IN PDEVICE_CONTEXT DeviceContext,
  994. IN PMDL CurrentMdl,
  995. IN ULONG ByteOffset,
  996. IN ULONG DesiredLength,
  997. OUT PNDIS_BUFFER *Destination,
  998. OUT PMDL *NewCurrentMdl,
  999. OUT ULONG *NewByteOffset,
  1000. OUT ULONG *TrueLength
  1001. );
  1002. //
  1003. // Routines in DEVCTX.C (TP_DEVCTX object manager).
  1004. //
  1005. VOID
  1006. NbfRefDeviceContext(
  1007. IN PDEVICE_CONTEXT DeviceContext
  1008. );
  1009. VOID
  1010. NbfDerefDeviceContext(
  1011. IN PDEVICE_CONTEXT DeviceContext
  1012. );
  1013. NTSTATUS
  1014. NbfCreateDeviceContext(
  1015. IN PDRIVER_OBJECT DriverObject,
  1016. IN PUNICODE_STRING DeviceName,
  1017. IN OUT PDEVICE_CONTEXT *DeviceContext
  1018. );
  1019. VOID
  1020. NbfDestroyDeviceContext(
  1021. IN PDEVICE_CONTEXT DeviceContext
  1022. );
  1023. //
  1024. // Routines in ADDRESS.C (TP_ADDRESS object manager).
  1025. //
  1026. #if DBG
  1027. VOID
  1028. NbfRefAddress(
  1029. IN PTP_ADDRESS Address
  1030. );
  1031. #endif
  1032. VOID
  1033. NbfDerefAddress(
  1034. IN PTP_ADDRESS Address
  1035. );
  1036. VOID
  1037. NbfAllocateAddressFile(
  1038. IN PDEVICE_CONTEXT DeviceContext,
  1039. OUT PTP_ADDRESS_FILE *TransportAddressFile
  1040. );
  1041. VOID
  1042. NbfDeallocateAddressFile(
  1043. IN PDEVICE_CONTEXT DeviceContext,
  1044. IN PTP_ADDRESS_FILE TransportAddressFile
  1045. );
  1046. NTSTATUS
  1047. NbfCreateAddressFile(
  1048. IN PDEVICE_CONTEXT DeviceContext,
  1049. OUT PTP_ADDRESS_FILE * AddressFile
  1050. );
  1051. VOID
  1052. NbfReferenceAddressFile(
  1053. IN PTP_ADDRESS_FILE AddressFile
  1054. );
  1055. VOID
  1056. NbfDereferenceAddressFile(
  1057. IN PTP_ADDRESS_FILE AddressFile
  1058. );
  1059. VOID
  1060. NbfDestroyAddress(
  1061. IN PVOID Parameter
  1062. );
  1063. NTSTATUS
  1064. NbfOpenAddress(
  1065. IN PDEVICE_OBJECT DeviceObject,
  1066. IN PIRP Irp,
  1067. IN PIO_STACK_LOCATION IrpSp
  1068. );
  1069. NTSTATUS
  1070. NbfCloseAddress(
  1071. IN PDEVICE_OBJECT DeviceObject,
  1072. IN PIRP Irp,
  1073. IN PIO_STACK_LOCATION IrpSp
  1074. );
  1075. VOID
  1076. NbfStopAddress(
  1077. IN PTP_ADDRESS Address
  1078. );
  1079. VOID
  1080. NbfRegisterAddress(
  1081. IN PTP_ADDRESS Address
  1082. );
  1083. BOOLEAN
  1084. NbfMatchNetbiosAddress(
  1085. IN PTP_ADDRESS Address,
  1086. IN UCHAR NameType,
  1087. IN PUCHAR NetBIOSName
  1088. );
  1089. VOID
  1090. NbfAllocateAddress(
  1091. IN PDEVICE_CONTEXT DeviceContext,
  1092. OUT PTP_ADDRESS *TransportAddress
  1093. );
  1094. VOID
  1095. NbfDeallocateAddress(
  1096. IN PDEVICE_CONTEXT DeviceContext,
  1097. IN PTP_ADDRESS TransportAddress
  1098. );
  1099. NTSTATUS
  1100. NbfCreateAddress(
  1101. IN PDEVICE_CONTEXT DeviceContext,
  1102. IN PNBF_NETBIOS_ADDRESS NetworkName,
  1103. OUT PTP_ADDRESS *Address
  1104. );
  1105. PTP_ADDRESS
  1106. NbfLookupAddress(
  1107. IN PDEVICE_CONTEXT DeviceContext,
  1108. IN PNBF_NETBIOS_ADDRESS NetworkName
  1109. );
  1110. PTP_CONNECTION
  1111. NbfLookupRemoteName(
  1112. IN PTP_ADDRESS Address,
  1113. IN PUCHAR RemoteName,
  1114. IN UCHAR RemoteSessionNumber
  1115. );
  1116. NTSTATUS
  1117. NbfStopAddressFile(
  1118. IN PTP_ADDRESS_FILE AddressFile,
  1119. IN PTP_ADDRESS Address
  1120. );
  1121. VOID
  1122. AddressTimeoutHandler(
  1123. IN PKDPC Dpc,
  1124. IN PVOID DeferredContext,
  1125. IN PVOID SystemArgument1,
  1126. IN PVOID SystemArgument2
  1127. );
  1128. TDI_ADDRESS_NETBIOS *
  1129. NbfParseTdiAddress(
  1130. IN TRANSPORT_ADDRESS UNALIGNED * TransportAddress,
  1131. IN BOOLEAN BroadcastAddressOk
  1132. );
  1133. BOOLEAN
  1134. NbfValidateTdiAddress(
  1135. IN TRANSPORT_ADDRESS UNALIGNED * TransportAddress,
  1136. IN ULONG TransportAddressLength
  1137. );
  1138. NTSTATUS
  1139. NbfVerifyAddressObject (
  1140. IN PTP_ADDRESS_FILE AddressFile
  1141. );
  1142. NTSTATUS
  1143. NbfSendDatagramsOnAddress(
  1144. PTP_ADDRESS Address
  1145. );
  1146. //
  1147. // Routines in CONNECT.C.
  1148. //
  1149. NTSTATUS
  1150. NbfTdiAccept(
  1151. IN PIRP Irp
  1152. );
  1153. NTSTATUS
  1154. NbfTdiConnect(
  1155. IN PIRP Irp
  1156. );
  1157. NTSTATUS
  1158. NbfTdiDisconnect(
  1159. IN PIRP Irp
  1160. );
  1161. NTSTATUS
  1162. NbfTdiDisassociateAddress (
  1163. IN PIRP Irp
  1164. );
  1165. NTSTATUS
  1166. NbfTdiAssociateAddress(
  1167. IN PIRP Irp
  1168. );
  1169. NTSTATUS
  1170. NbfTdiListen(
  1171. IN PIRP Irp
  1172. );
  1173. NTSTATUS
  1174. NbfOpenConnection(
  1175. IN PDEVICE_OBJECT DeviceObject,
  1176. IN PIRP Irp,
  1177. IN PIO_STACK_LOCATION IrpSp
  1178. );
  1179. NTSTATUS
  1180. NbfCloseConnection(
  1181. IN PDEVICE_OBJECT DeviceObject,
  1182. IN PIRP Irp,
  1183. IN PIO_STACK_LOCATION IrpSp
  1184. );
  1185. //
  1186. //
  1187. // Routines in CONNOBJ.C (TP_CONNECTION object manager).
  1188. //
  1189. #if DBG
  1190. VOID
  1191. NbfRefConnection(
  1192. IN PTP_CONNECTION TransportConnection
  1193. );
  1194. #endif
  1195. VOID
  1196. NbfDerefConnection(
  1197. IN PTP_CONNECTION TransportConnection
  1198. );
  1199. VOID
  1200. NbfDerefConnectionSpecial(
  1201. IN PTP_CONNECTION TransportConnection
  1202. );
  1203. VOID
  1204. NbfClearConnectionLsn(
  1205. IN PTP_CONNECTION TransportConnection
  1206. );
  1207. VOID
  1208. NbfStopConnection(
  1209. IN PTP_CONNECTION TransportConnection,
  1210. IN NTSTATUS Status
  1211. );
  1212. VOID
  1213. NbfCancelConnection(
  1214. IN PDEVICE_OBJECT DeviceObject,
  1215. IN PIRP Irp
  1216. );
  1217. VOID
  1218. NbfStartConnectionTimer(
  1219. IN PTP_CONNECTION TransportConnection,
  1220. IN PKDEFERRED_ROUTINE TimeoutFunction,
  1221. IN ULONG WaitTime
  1222. );
  1223. PTP_CONNECTION
  1224. NbfLookupListeningConnection(
  1225. IN PTP_ADDRESS Address,
  1226. IN PUCHAR RemoteName
  1227. );
  1228. PTP_CONNECTION
  1229. NbfLookupConnectingConnection(
  1230. IN PTP_ADDRESS Address
  1231. );
  1232. VOID
  1233. NbfAllocateConnection(
  1234. IN PDEVICE_CONTEXT DeviceContext,
  1235. OUT PTP_CONNECTION *TransportConnection
  1236. );
  1237. VOID
  1238. NbfDeallocateConnection(
  1239. IN PDEVICE_CONTEXT DeviceContext,
  1240. IN PTP_CONNECTION TransportConnection
  1241. );
  1242. NTSTATUS
  1243. NbfCreateConnection(
  1244. IN PDEVICE_CONTEXT DeviceContext,
  1245. OUT PTP_CONNECTION *TransportConnection
  1246. );
  1247. PTP_CONNECTION
  1248. NbfLookupConnectionById(
  1249. IN PTP_ADDRESS Address,
  1250. IN USHORT ConnectionId
  1251. );
  1252. PTP_CONNECTION
  1253. NbfLookupConnectionByContext(
  1254. IN PTP_ADDRESS Address,
  1255. IN CONNECTION_CONTEXT ConnectionContext
  1256. );
  1257. #if 0
  1258. VOID
  1259. NbfWaitConnectionOnLink(
  1260. IN PTP_CONNECTION Connection,
  1261. IN ULONG Flags
  1262. );
  1263. #endif
  1264. VOID
  1265. ConnectionEstablishmentTimeout(
  1266. IN PKDPC Dpc,
  1267. IN PVOID DeferredContext,
  1268. IN PVOID SystemArgument1,
  1269. IN PVOID SystemArgument2
  1270. );
  1271. NTSTATUS
  1272. NbfVerifyConnectionObject (
  1273. IN PTP_CONNECTION Connection
  1274. );
  1275. NTSTATUS
  1276. NbfIndicateDisconnect(
  1277. IN PTP_CONNECTION TransportConnection
  1278. );
  1279. //
  1280. // Routines in INFO.C (QUERY_INFO manager).
  1281. //
  1282. NTSTATUS
  1283. NbfTdiQueryInformation(
  1284. IN PDEVICE_CONTEXT DeviceContext,
  1285. IN PIRP Irp
  1286. );
  1287. NTSTATUS
  1288. NbfTdiSetInformation(
  1289. IN PIRP Irp
  1290. );
  1291. VOID
  1292. NbfSendQueryFindName(
  1293. IN PDEVICE_CONTEXT DeviceContext,
  1294. IN PTP_REQUEST Request
  1295. );
  1296. NTSTATUS
  1297. NbfProcessQueryNameRecognized(
  1298. IN PDEVICE_CONTEXT DeviceContext,
  1299. IN PUCHAR Packet,
  1300. PNBF_HDR_CONNECTIONLESS UiFrame
  1301. );
  1302. VOID
  1303. NbfSendStatusQuery(
  1304. IN PDEVICE_CONTEXT DeviceContext,
  1305. IN PTP_REQUEST Request,
  1306. IN PHARDWARE_ADDRESS DestinationAddress,
  1307. IN PUCHAR SourceRouting,
  1308. IN UINT SourceRoutingLength
  1309. );
  1310. NTSTATUS
  1311. NbfProcessStatusResponse(
  1312. IN PDEVICE_CONTEXT DeviceContext,
  1313. IN NDIS_HANDLE ReceiveContext,
  1314. IN PNBF_HDR_CONNECTIONLESS UiFrame,
  1315. IN PHARDWARE_ADDRESS SourceAddress,
  1316. IN PUCHAR SourceRouting,
  1317. IN UINT SourceRoutingLength
  1318. );
  1319. NTSTATUS
  1320. NbfProcessStatusQuery(
  1321. IN PDEVICE_CONTEXT DeviceContext,
  1322. IN PTP_ADDRESS Address OPTIONAL,
  1323. IN PNBF_HDR_CONNECTIONLESS UiFrame,
  1324. IN PHARDWARE_ADDRESS SourceAddress,
  1325. IN PUCHAR SourceRouting,
  1326. IN UINT SourceRoutingLength
  1327. );
  1328. //
  1329. // Routines in EVENT.C.
  1330. //
  1331. NTSTATUS
  1332. NbfTdiSetEventHandler(
  1333. IN PIRP Irp
  1334. );
  1335. //
  1336. // Routines in REQUEST.C (TP_REQUEST object manager).
  1337. //
  1338. VOID
  1339. TdiRequestTimeoutHandler(
  1340. IN PKDPC Dpc,
  1341. IN PVOID DeferredContext,
  1342. IN PVOID SystemArgument1,
  1343. IN PVOID SystemArgument2
  1344. );
  1345. #if DBG
  1346. VOID
  1347. NbfRefRequest(
  1348. IN PTP_REQUEST Request
  1349. );
  1350. #endif
  1351. VOID
  1352. NbfDerefRequest(
  1353. IN PTP_REQUEST Request
  1354. );
  1355. VOID
  1356. NbfCompleteRequest(
  1357. IN PTP_REQUEST Request,
  1358. IN NTSTATUS Status,
  1359. IN ULONG Information
  1360. );
  1361. #if DBG
  1362. VOID
  1363. NbfRefSendIrp(
  1364. IN PIO_STACK_LOCATION IrpSp
  1365. );
  1366. VOID
  1367. NbfDerefSendIrp(
  1368. IN PIO_STACK_LOCATION IrpSp
  1369. );
  1370. #endif
  1371. VOID
  1372. NbfCompleteSendIrp(
  1373. IN PIRP Irp,
  1374. IN NTSTATUS Status,
  1375. IN ULONG Information
  1376. );
  1377. #if DBG
  1378. VOID
  1379. NbfRefReceiveIrpLocked(
  1380. IN PIO_STACK_LOCATION IrpSp
  1381. );
  1382. #endif
  1383. VOID
  1384. NbfDerefReceiveIrp(
  1385. IN PIO_STACK_LOCATION IrpSp
  1386. );
  1387. #if DBG
  1388. VOID
  1389. NbfDerefReceiveIrpLocked(
  1390. IN PIO_STACK_LOCATION IrpSp
  1391. );
  1392. #endif
  1393. VOID
  1394. NbfCompleteReceiveIrp(
  1395. IN PIRP Irp,
  1396. IN NTSTATUS Status,
  1397. IN ULONG Information
  1398. );
  1399. VOID
  1400. NbfAllocateRequest(
  1401. IN PDEVICE_CONTEXT DeviceContext,
  1402. OUT PTP_REQUEST *TransportRequest
  1403. );
  1404. VOID
  1405. NbfDeallocateRequest(
  1406. IN PDEVICE_CONTEXT DeviceContext,
  1407. IN PTP_REQUEST TransportRequest
  1408. );
  1409. NTSTATUS
  1410. NbfCreateRequest(
  1411. IN PIRP Irp,
  1412. IN PVOID Context,
  1413. IN ULONG Flags,
  1414. IN PMDL Buffer2,
  1415. IN ULONG Buffer2Length,
  1416. IN LARGE_INTEGER Timeout,
  1417. OUT PTP_REQUEST * TpRequest
  1418. );
  1419. //
  1420. // Routines in LINK.C (TP_LINK object manager).
  1421. //
  1422. NTSTATUS
  1423. NbfDestroyLink(
  1424. IN PTP_LINK TransportLink
  1425. );
  1426. VOID
  1427. NbfDisconnectLink(
  1428. IN PTP_LINK Link
  1429. );
  1430. #if DBG
  1431. VOID
  1432. NbfRefLink(
  1433. IN PTP_LINK TransportLink
  1434. );
  1435. #endif
  1436. VOID
  1437. NbfDerefLink(
  1438. IN PTP_LINK TransportLink
  1439. );
  1440. VOID
  1441. NbfRefLinkSpecial(
  1442. IN PTP_LINK TransportLink
  1443. );
  1444. VOID
  1445. NbfDerefLinkSpecial(
  1446. IN PTP_LINK TransportLink
  1447. );
  1448. VOID
  1449. NbfResetLink(
  1450. IN PTP_LINK Link
  1451. );
  1452. VOID
  1453. NbfStopLink(
  1454. IN PTP_LINK Link
  1455. );
  1456. VOID
  1457. NbfCompleteLink(
  1458. IN PTP_LINK Link
  1459. );
  1460. VOID
  1461. NbfActivateLink(
  1462. IN PTP_LINK Link
  1463. );
  1464. VOID
  1465. NbfWaitLink(
  1466. IN PTP_LINK Link
  1467. );
  1468. BOOLEAN
  1469. NbfDisconnectFromLink(
  1470. IN PTP_CONNECTION TransportConnection,
  1471. IN BOOLEAN VerifyReferenceCount
  1472. );
  1473. NTSTATUS
  1474. NbfAssignGroupLsn(
  1475. IN PTP_CONNECTION TransportConnection
  1476. );
  1477. NTSTATUS
  1478. NbfConnectToLink(
  1479. IN PTP_LINK Link,
  1480. IN PTP_CONNECTION TransportConnection
  1481. );
  1482. PTP_CONNECTION
  1483. NbfLookupPendingConnectOnLink(
  1484. IN PTP_LINK Link
  1485. );
  1486. PTP_CONNECTION
  1487. NbfLookupPendingListenOnLink(
  1488. IN PTP_LINK Link
  1489. );
  1490. VOID
  1491. NbfAllocateLink(
  1492. IN PDEVICE_CONTEXT DeviceContext,
  1493. OUT PTP_LINK *TransportLink
  1494. );
  1495. VOID
  1496. NbfDeallocateLink(
  1497. IN PDEVICE_CONTEXT DeviceContext,
  1498. IN PTP_LINK TransportLink
  1499. );
  1500. NTSTATUS
  1501. NbfCreateLink(
  1502. IN PDEVICE_CONTEXT DeviceContext,
  1503. IN PHARDWARE_ADDRESS HardwareAddress,
  1504. IN PUCHAR SourceRouting,
  1505. IN UINT SourceRoutingLength,
  1506. IN USHORT LoopbackLinkIndex,
  1507. OUT PTP_LINK *TransportLink
  1508. );
  1509. VOID
  1510. NbfDumpLinkInfo (
  1511. IN PTP_LINK Link
  1512. );
  1513. //
  1514. // routines in linktree.c
  1515. //
  1516. NTSTATUS
  1517. NbfAddLinkToTree (
  1518. IN PDEVICE_CONTEXT DeviceContext,
  1519. IN PTP_LINK Link
  1520. );
  1521. NTSTATUS
  1522. NbfRemoveLinkFromTree(
  1523. IN PDEVICE_CONTEXT DeviceContext,
  1524. IN PTP_LINK Link
  1525. );
  1526. PTP_LINK
  1527. NbfFindLinkInTree(
  1528. IN PDEVICE_CONTEXT DeviceContext,
  1529. IN PUCHAR Remote
  1530. );
  1531. PTP_LINK
  1532. NbfFindLink(
  1533. IN PDEVICE_CONTEXT DeviceContext,
  1534. IN PUCHAR Remote
  1535. );
  1536. //
  1537. // Routines in DLC.C (LLC frame cracker, entrypoints from NDIS interface).
  1538. //
  1539. VOID
  1540. NbfInsertInLoopbackQueue (
  1541. IN PDEVICE_CONTEXT DeviceContext,
  1542. IN PNDIS_PACKET NdisPacket,
  1543. IN UCHAR LinkIndex
  1544. );
  1545. VOID
  1546. NbfProcessLoopbackQueue (
  1547. IN PKDPC Dpc,
  1548. IN PVOID DeferredContext,
  1549. IN PVOID SystemArgument1,
  1550. IN PVOID SystemArgument2
  1551. );
  1552. NDIS_STATUS
  1553. NbfReceiveIndication(
  1554. IN NDIS_HANDLE BindingContext,
  1555. IN NDIS_HANDLE ReceiveContext,
  1556. IN PVOID HeaderBuffer,
  1557. IN UINT HeaderBufferSize,
  1558. IN PVOID LookaheadBuffer,
  1559. IN UINT LookaheadBufferSize,
  1560. IN UINT PacketSize
  1561. );
  1562. VOID
  1563. NbfGeneralReceiveHandler (
  1564. IN PDEVICE_CONTEXT DeviceContext,
  1565. IN NDIS_HANDLE ReceiveContext,
  1566. IN PHARDWARE_ADDRESS SourceAddress,
  1567. IN PTP_LINK Link,
  1568. IN PVOID HeaderBuffer,
  1569. IN UINT PacketSize,
  1570. IN PDLC_FRAME DlcHeader,
  1571. IN UINT DlcSize,
  1572. IN BOOLEAN Loopback
  1573. );
  1574. VOID
  1575. NbfReceiveComplete (
  1576. IN NDIS_HANDLE BindingContext
  1577. );
  1578. VOID
  1579. NbfProcessWanDelayedQueue(
  1580. IN PVOID Parameter
  1581. );
  1582. VOID
  1583. NbfTransferDataComplete(
  1584. IN NDIS_HANDLE BindingContext,
  1585. IN PNDIS_PACKET NdisPacket,
  1586. IN NDIS_STATUS Status,
  1587. IN UINT BytesTransferred
  1588. );
  1589. VOID
  1590. NbfTransferLoopbackData (
  1591. OUT PNDIS_STATUS NdisStatus,
  1592. IN PDEVICE_CONTEXT DeviceContext,
  1593. IN NDIS_HANDLE ReceiveContext,
  1594. IN UINT ByteOffset,
  1595. IN UINT BytesToTransfer,
  1596. IN PNDIS_PACKET Packet,
  1597. OUT PUINT BytesTransferred
  1598. );
  1599. //
  1600. // Routines in UFRAMES.C, the UI-frame NBF frame processor.
  1601. //
  1602. NTSTATUS
  1603. NbfIndicateDatagram(
  1604. IN PDEVICE_CONTEXT DeviceContext,
  1605. IN PTP_ADDRESS Address,
  1606. IN PUCHAR Dsdu,
  1607. IN ULONG Length
  1608. );
  1609. NTSTATUS
  1610. NbfProcessUi(
  1611. IN PDEVICE_CONTEXT DeviceContext,
  1612. IN PHARDWARE_ADDRESS SourceAddress,
  1613. IN PUCHAR Header,
  1614. IN PUCHAR DlcHeader,
  1615. IN ULONG DlcLength,
  1616. IN PUCHAR SourceRouting,
  1617. IN UINT SourceRoutingLength,
  1618. OUT PTP_ADDRESS * DatagramAddress
  1619. );
  1620. //
  1621. // Routines in IFRAMES.C, the I-frame NBF frame processor.
  1622. //
  1623. VOID
  1624. NbfAcknowledgeDataOnlyLast(
  1625. IN PTP_CONNECTION Connection,
  1626. IN ULONG MessageLength
  1627. );
  1628. VOID
  1629. NbfProcessIIndicate(
  1630. IN BOOLEAN Command,
  1631. IN BOOLEAN PollFinal,
  1632. IN PTP_LINK Link,
  1633. IN PUCHAR DlcHeader,
  1634. IN UINT DlcIndicatedLength,
  1635. IN UINT DlcTotalLength,
  1636. IN NDIS_HANDLE ReceiveContext,
  1637. IN BOOLEAN Loopback
  1638. );
  1639. NTSTATUS
  1640. ProcessIndicateData(
  1641. IN PTP_CONNECTION Connection,
  1642. IN PUCHAR DlcHeader,
  1643. IN UINT DlcIndicatedLength,
  1644. IN PUCHAR DataHeader,
  1645. IN UINT DataTotalLength,
  1646. IN NDIS_HANDLE ReceiveContext,
  1647. IN BOOLEAN Last,
  1648. IN BOOLEAN Loopback
  1649. );
  1650. //
  1651. // Routines in RCV.C (data copying routines for receives).
  1652. //
  1653. NTSTATUS
  1654. NbfTdiReceive(
  1655. IN PIRP Irp
  1656. );
  1657. NTSTATUS
  1658. NbfTdiReceiveDatagram(
  1659. IN PIRP Irp
  1660. );
  1661. //
  1662. // Routines in FRAMESND.C, the UI-frame (non-link) shipper.
  1663. //
  1664. VOID
  1665. NbfSendNameQuery(
  1666. IN PTP_CONNECTION Connection,
  1667. IN BOOLEAN SourceRoutingOptional
  1668. );
  1669. VOID
  1670. NbfSendNameRecognized(
  1671. IN PTP_ADDRESS Address,
  1672. IN UCHAR LocalSessionNumber, // LSN assigned to session.
  1673. IN PNBF_HDR_CONNECTIONLESS Header,
  1674. IN PHARDWARE_ADDRESS SourceAddress,
  1675. IN PUCHAR SourceRouting,
  1676. IN UINT SourceRoutingLength
  1677. );
  1678. VOID
  1679. NbfSendNameInConflict(
  1680. IN PTP_ADDRESS Address,
  1681. IN PUCHAR ConflictingName
  1682. );
  1683. NTSTATUS
  1684. NbfSendAddNameQuery(
  1685. IN PTP_ADDRESS Address
  1686. );
  1687. VOID
  1688. NbfSendSessionInitialize(
  1689. IN PTP_CONNECTION Connection
  1690. );
  1691. VOID
  1692. NbfSendSessionConfirm(
  1693. IN PTP_CONNECTION Connection
  1694. );
  1695. VOID
  1696. NbfSendSessionEnd(
  1697. IN PTP_CONNECTION Connection,
  1698. IN BOOLEAN Abort
  1699. );
  1700. VOID
  1701. NbfSendNoReceive(
  1702. IN PTP_CONNECTION Connection
  1703. );
  1704. VOID
  1705. NbfSendReceiveContinue(
  1706. IN PTP_CONNECTION Connection
  1707. );
  1708. VOID
  1709. NbfSendReceiveOutstanding(
  1710. IN PTP_CONNECTION Connection
  1711. );
  1712. VOID
  1713. NbfSendDataAck(
  1714. IN PTP_CONNECTION Connection
  1715. );
  1716. VOID
  1717. NbfSendSabme(
  1718. IN PTP_LINK Link,
  1719. IN BOOLEAN PollFinal
  1720. );
  1721. VOID
  1722. NbfSendDisc(
  1723. IN PTP_LINK Link,
  1724. IN BOOLEAN PollFinal
  1725. );
  1726. VOID
  1727. NbfSendUa(
  1728. IN PTP_LINK Link,
  1729. IN BOOLEAN PollFinal
  1730. );
  1731. VOID
  1732. NbfSendDm(
  1733. IN PTP_LINK Link,
  1734. IN BOOLEAN PollFinal
  1735. );
  1736. VOID
  1737. NbfSendRr(
  1738. IN PTP_LINK Link,
  1739. IN BOOLEAN Command,
  1740. IN BOOLEAN PollFinal
  1741. );
  1742. #if 0
  1743. //
  1744. // These functions are not currently called, so they are commented
  1745. // out.
  1746. //
  1747. VOID
  1748. NbfSendRnr(
  1749. IN PTP_LINK Link,
  1750. IN BOOLEAN Command,
  1751. IN BOOLEAN PollFinal
  1752. );
  1753. VOID
  1754. NbfSendTest(
  1755. IN PTP_LINK Link,
  1756. IN BOOLEAN Command,
  1757. IN BOOLEAN PollFinal,
  1758. IN PMDL Psdu
  1759. );
  1760. VOID
  1761. NbfSendFrmr(
  1762. IN PTP_LINK Link,
  1763. IN BOOLEAN PollFinal
  1764. );
  1765. #endif
  1766. VOID
  1767. NbfSendXid(
  1768. IN PTP_LINK Link,
  1769. IN BOOLEAN Command,
  1770. IN BOOLEAN PollFinal
  1771. );
  1772. VOID
  1773. NbfSendRej(
  1774. IN PTP_LINK Link,
  1775. IN BOOLEAN Command,
  1776. IN BOOLEAN PollFinal
  1777. );
  1778. NTSTATUS
  1779. NbfCreateConnectionlessFrame(
  1780. IN PDEVICE_CONTEXT DeviceContext,
  1781. OUT PTP_UI_FRAME *OuterFrame
  1782. );
  1783. VOID
  1784. NbfDestroyConnectionlessFrame(
  1785. IN PDEVICE_CONTEXT DeviceContext,
  1786. IN PTP_UI_FRAME RawFrame
  1787. );
  1788. VOID
  1789. NbfSendUIFrame(
  1790. IN PDEVICE_CONTEXT DeviceContext,
  1791. IN PTP_UI_FRAME RawFrame,
  1792. IN BOOLEAN Loopback
  1793. );
  1794. VOID
  1795. NbfSendUIMdlFrame(
  1796. IN PTP_ADDRESS Address
  1797. );
  1798. VOID
  1799. NbfSendDatagramCompletion(
  1800. IN PTP_ADDRESS Address,
  1801. IN PNDIS_PACKET NdisPacket,
  1802. IN NDIS_STATUS NdisStatus
  1803. );
  1804. //
  1805. // Routines in FRAMECON.C, the NetBIOS Frames Protocol Frame Constructors.
  1806. // To understand the various constant parameters to these functions (such
  1807. // as special data1 & data2 values, see NBFCONST.H for details.
  1808. //
  1809. VOID
  1810. ConstructAddGroupNameQuery(
  1811. IN PNBF_HDR_CONNECTIONLESS RawFrame,// frame buffer to format.
  1812. IN USHORT Correlator, // correlator for ADD_NAME_RESPONSE.
  1813. IN PNAME GroupName // NetBIOS group name to be added.
  1814. );
  1815. VOID
  1816. ConstructAddNameQuery(
  1817. IN PNBF_HDR_CONNECTIONLESS RawFrame,// frame buffer to format.
  1818. IN USHORT Correlator, // correlator for ADD_NAME_RESPONSE.
  1819. IN PNAME Name // NetBIOS name to be added.
  1820. );
  1821. VOID
  1822. ConstructNameInConflict(
  1823. IN PNBF_HDR_CONNECTIONLESS RawFrame,// frame buffer to format.
  1824. IN PNAME ConflictingName, // NetBIOS name that is conflicting.
  1825. IN PNAME SendingPermanentName // NetBIOS permanent node name of sender.
  1826. );
  1827. VOID
  1828. ConstructStatusQuery(
  1829. IN PNBF_HDR_CONNECTIONLESS RawFrame,// frame buffer to format.
  1830. IN UCHAR RequestType, // type of request, defined below.
  1831. IN USHORT BufferLength, // length of user's status buffer.
  1832. IN USHORT Correlator, // correlator for STATUS_RESPONSE.
  1833. IN PNAME ReceiverName, // NetBIOS name of receiver.
  1834. IN PNAME SendingPermanentName // NetBIOS permanent node name of sender.
  1835. );
  1836. VOID
  1837. ConstructTerminateTrace(
  1838. IN PNBF_HDR_CONNECTIONLESS RawFrame // frame buffer to format.
  1839. );
  1840. VOID
  1841. ConstructDatagram(
  1842. IN PNBF_HDR_CONNECTIONLESS RawFrame,// frame buffer to format.
  1843. IN PNAME ReceiverName, // NetBIOS name of receiver.
  1844. IN PNAME SenderName // NetBIOS name of sender.
  1845. );
  1846. VOID
  1847. ConstructDatagramBroadcast(
  1848. IN PNBF_HDR_CONNECTIONLESS RawFrame,// frame buffer to format.
  1849. IN PNAME SenderName // NetBIOS name of sender.
  1850. );
  1851. VOID
  1852. ConstructNameQuery(
  1853. IN PNBF_HDR_CONNECTIONLESS RawFrame,// frame buffer to format.
  1854. IN UCHAR NameType, // type of name.
  1855. IN UCHAR LocalSessionNumber, // LSN assigned to session (0=FIND_NAME).
  1856. IN USHORT Correlator, // correlator in NAME_RECOGNIZED.
  1857. IN PNAME SenderName, // NetBIOS name of sender.
  1858. IN PNAME ReceiverName // NetBIOS name of sender.
  1859. );
  1860. VOID
  1861. ConstructAddNameResponse(
  1862. IN PNBF_HDR_CONNECTIONLESS RawFrame,// frame buffer to format.
  1863. IN UCHAR NameType, // type of name.
  1864. IN USHORT Correlator, // correlator from ADD_[GROUP_]NAME_QUERY.
  1865. IN PNAME Name // NetBIOS name being responded to.
  1866. );
  1867. VOID
  1868. ConstructNameRecognized(
  1869. IN PNBF_HDR_CONNECTIONLESS RawFrame,// frame buffer to format.
  1870. IN UCHAR NameType, // type of name.
  1871. IN UCHAR LocalSessionNumber, // LSN assigned to session.
  1872. IN USHORT NameQueryCorrelator, // correlator from NAME_QUERY.
  1873. IN USHORT Correlator, // correlator expected from next response.
  1874. IN PNAME SenderName, // NetBIOS name of sender.
  1875. IN PNAME ReceiverName // NetBIOS name of receiver.
  1876. );
  1877. VOID
  1878. ConstructStatusResponse(
  1879. IN PNBF_HDR_CONNECTIONLESS RawFrame,// frame buffer to format.
  1880. IN UCHAR RequestType, // type of request, defined below.
  1881. IN BOOLEAN Truncated, // data is truncated.
  1882. IN BOOLEAN DataOverflow, // too much data for user's buffer.
  1883. IN USHORT DataLength, // length of data sent.
  1884. IN USHORT Correlator, // correlator from STATUS_QUERY.
  1885. IN PNAME ReceivingPermanentName, // NetBIOS permanent node name of receiver.
  1886. IN PNAME SenderName // NetBIOS name of sender.
  1887. );
  1888. VOID
  1889. ConstructDataAck(
  1890. IN PNBF_HDR_CONNECTION RawFrame, // frame buffer to format.
  1891. IN USHORT Correlator, // correlator from DATA_ONLY_LAST.
  1892. IN UCHAR LocalSessionNumber, // session number of SENDER.
  1893. IN UCHAR RemoteSessionNumber // session number of RECEIVER.
  1894. );
  1895. VOID
  1896. ConstructDataOnlyLast(
  1897. IN PNBF_HDR_CONNECTION RawFrame, // frame buffer to format.
  1898. IN BOOLEAN Resynched, // TRUE if we are resynching.
  1899. IN USHORT Correlator, // correlator for RECEIVE_CONTINUE.
  1900. IN UCHAR LocalSessionNumber, // session number of SENDER.
  1901. IN UCHAR RemoteSessionNumber // session number of RECEIVER.
  1902. );
  1903. VOID
  1904. ConstructSessionConfirm(
  1905. IN PNBF_HDR_CONNECTION RawFrame, // frame buffer to format.
  1906. IN UCHAR Options, // bitflag options, defined below.
  1907. IN USHORT MaximumUserBufferSize, // max size of user frame on session.
  1908. IN USHORT Correlator, // correlator from SESSION_INITIALIZE.
  1909. IN UCHAR LocalSessionNumber, // session number of SENDER.
  1910. IN UCHAR RemoteSessionNumber // session number of RECEIVER.
  1911. );
  1912. VOID
  1913. ConstructSessionEnd(
  1914. IN PNBF_HDR_CONNECTION RawFrame, // frame buffer to format.
  1915. IN USHORT Reason, // reason for termination, defined below.
  1916. IN UCHAR LocalSessionNumber, // session number of SENDER.
  1917. IN UCHAR RemoteSessionNumber // session number of RECEIVER.
  1918. );
  1919. VOID
  1920. ConstructSessionInitialize(
  1921. IN PNBF_HDR_CONNECTION RawFrame, // frame buffer to format.
  1922. IN UCHAR Options, // bitflag options, defined below.
  1923. IN USHORT MaximumUserBufferSize, // max size of user frame on session.
  1924. IN USHORT NameRecognizedCorrelator, // correlator from NAME_RECOGNIZED.
  1925. IN USHORT Correlator, // correlator for SESSION_CONFIRM.
  1926. IN UCHAR LocalSessionNumber, // session number of SENDER.
  1927. IN UCHAR RemoteSessionNumber // session number of RECEIVER.
  1928. );
  1929. VOID
  1930. ConstructNoReceive(
  1931. IN PNBF_HDR_CONNECTION RawFrame, // frame buffer to format.
  1932. IN USHORT Options, // option bitflags, defined below.
  1933. IN USHORT BytesAccepted, // number of bytes accepted.
  1934. IN UCHAR LocalSessionNumber, // session number of SENDER.
  1935. IN UCHAR RemoteSessionNumber // session number of RECEIVER.
  1936. );
  1937. VOID
  1938. ConstructReceiveOutstanding(
  1939. IN PNBF_HDR_CONNECTION RawFrame, // frame buffer to format.
  1940. IN USHORT BytesAccepted, // number of bytes accepted.
  1941. IN UCHAR LocalSessionNumber, // session number of SENDER.
  1942. IN UCHAR RemoteSessionNumber // session number of RECEIVER.
  1943. );
  1944. VOID
  1945. ConstructReceiveContinue(
  1946. IN PNBF_HDR_CONNECTION RawFrame, // frame buffer to format.
  1947. IN USHORT Correlator, // correlator from DATA_FIRST_MIDDLE
  1948. IN UCHAR LocalSessionNumber, // session number of SENDER.
  1949. IN UCHAR RemoteSessionNumber // session number of RECEIVER.
  1950. );
  1951. #if 0
  1952. VOID
  1953. ConstructSessionAlive(
  1954. IN PNBF_HDR_CONNECTION RawFrame // frame buffer to format.
  1955. );
  1956. #endif
  1957. //
  1958. // Routines in nbfndis.c.
  1959. //
  1960. #if DBG
  1961. PUCHAR
  1962. NbfGetNdisStatus (
  1963. IN NDIS_STATUS NdisStatus
  1964. );
  1965. #endif
  1966. //
  1967. // Routines in nbfdrvr.c
  1968. //
  1969. VOID
  1970. NbfWriteResourceErrorLog(
  1971. IN PDEVICE_CONTEXT DeviceContext,
  1972. IN NTSTATUS ErrorCode,
  1973. IN ULONG UniqueErrorValue,
  1974. IN ULONG BytesNeeded,
  1975. IN ULONG ResourceId
  1976. );
  1977. VOID
  1978. NbfWriteGeneralErrorLog(
  1979. IN PDEVICE_CONTEXT DeviceContext,
  1980. IN NTSTATUS ErrorCode,
  1981. IN ULONG UniqueErrorValue,
  1982. IN NTSTATUS FinalStatus,
  1983. IN PWSTR SecondString,
  1984. IN ULONG DumpDataCount,
  1985. IN ULONG DumpData[]
  1986. );
  1987. VOID
  1988. NbfWriteOidErrorLog(
  1989. IN PDEVICE_CONTEXT DeviceContext,
  1990. IN NTSTATUS ErrorCode,
  1991. IN NTSTATUS FinalStatus,
  1992. IN PWSTR AdapterString,
  1993. IN ULONG OidValue
  1994. );
  1995. VOID
  1996. NbfFreeResources(
  1997. IN PDEVICE_CONTEXT DeviceContext
  1998. );
  1999. extern
  2000. ULONG
  2001. NbfInitializeOneDeviceContext(
  2002. OUT PNDIS_STATUS NdisStatus,
  2003. IN PDRIVER_OBJECT DriverObject,
  2004. IN PCONFIG_DATA NbfConfig,
  2005. IN PUNICODE_STRING BindName,
  2006. IN PUNICODE_STRING ExportName,
  2007. IN PVOID SystemSpecific1,
  2008. IN PVOID SystemSpecific2
  2009. );
  2010. extern
  2011. VOID
  2012. NbfReInitializeDeviceContext(
  2013. OUT PNDIS_STATUS NdisStatus,
  2014. IN PDRIVER_OBJECT DriverObject,
  2015. IN PCONFIG_DATA NbfConfig,
  2016. IN PUNICODE_STRING BindName,
  2017. IN PUNICODE_STRING ExportName,
  2018. IN PVOID SystemSpecific1,
  2019. IN PVOID SystemSpecific2
  2020. );
  2021. //
  2022. // routines in nbfcnfg.c
  2023. //
  2024. NTSTATUS
  2025. NbfConfigureTransport (
  2026. IN PUNICODE_STRING RegistryPath,
  2027. IN PCONFIG_DATA * ConfigData
  2028. );
  2029. NTSTATUS
  2030. NbfGetExportNameFromRegistry(
  2031. IN PUNICODE_STRING RegistryPath,
  2032. IN PUNICODE_STRING BindName,
  2033. OUT PUNICODE_STRING ExportName
  2034. );
  2035. //
  2036. // Routines in nbfndis.c
  2037. //
  2038. NTSTATUS
  2039. NbfRegisterProtocol (
  2040. IN PUNICODE_STRING NameString
  2041. );
  2042. VOID
  2043. NbfDeregisterProtocol (
  2044. VOID
  2045. );
  2046. NTSTATUS
  2047. NbfInitializeNdis (
  2048. IN PDEVICE_CONTEXT DeviceContext,
  2049. IN PCONFIG_DATA ConfigInfo,
  2050. IN PUNICODE_STRING AdapterString
  2051. );
  2052. VOID
  2053. NbfCloseNdis (
  2054. IN PDEVICE_CONTEXT DeviceContext
  2055. );
  2056. //
  2057. // Routines in action.c
  2058. //
  2059. NTSTATUS
  2060. NbfTdiAction(
  2061. IN PDEVICE_CONTEXT DeviceContext,
  2062. IN PIRP Irp
  2063. );
  2064. VOID
  2065. NbfActionQueryIndication(
  2066. PDEVICE_CONTEXT DeviceContext,
  2067. PNBF_HDR_CONNECTIONLESS UiFrame
  2068. );
  2069. VOID
  2070. NbfActionDatagramIndication(
  2071. PDEVICE_CONTEXT DeviceContext,
  2072. PNBF_HDR_CONNECTIONLESS UiFrame,
  2073. ULONG Length
  2074. );
  2075. VOID
  2076. NbfStopControlChannel(
  2077. IN PDEVICE_CONTEXT DeviceContext,
  2078. IN USHORT ChannelIdentifier
  2079. );
  2080. //
  2081. // Routines in nbfdebug.c
  2082. //
  2083. #if DBG
  2084. VOID
  2085. DisplayOneFrame(
  2086. PTP_PACKET Packet
  2087. );
  2088. VOID
  2089. NbfDisplayUIFrame(
  2090. PTP_UI_FRAME OuterFrame
  2091. );
  2092. VOID
  2093. NbfFormattedDump(
  2094. PCHAR far_p,
  2095. ULONG len
  2096. );
  2097. #endif
  2098. //
  2099. // Routines in nbflog.c
  2100. //
  2101. #if PKT_LOG
  2102. VOID
  2103. NbfLogRcvPacket(
  2104. PTP_CONNECTION Connection,
  2105. PTP_LINK Link,
  2106. PUCHAR Header,
  2107. UINT TotalLength,
  2108. UINT AvailLength
  2109. );
  2110. VOID
  2111. NbfLogSndPacket(
  2112. PTP_LINK Link,
  2113. PTP_PACKET Packet
  2114. );
  2115. VOID
  2116. NbfLogIndPacket(
  2117. PTP_CONNECTION Connection,
  2118. PUCHAR Header,
  2119. UINT TotalLength,
  2120. UINT AvailLength,
  2121. UINT TakenLength,
  2122. ULONG Status
  2123. );
  2124. #endif // PKT_LOG
  2125. #endif // def _NBFPROCS_