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.

198 lines
4.6 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. netbios.h
  5. Abstract:
  6. This is the main include file for the component of netbios that runs
  7. in the user process.
  8. Author:
  9. Colin Watson (ColinW) 24-Jun-91
  10. Revision History:
  11. --*/
  12. #include <nt.h>
  13. #include <ntrtl.h>
  14. #include <nturtl.h>
  15. #include <windows.h>
  16. #include <nb30.h>
  17. #include <nb30p.h>
  18. #include <netbios.h>
  19. //
  20. // Internal version of the ncb layout that uses the reserved area to hold
  21. // the list entry when passing ncb's to the worker thread and the IO status
  22. // block used when the ncb is passed to the netbios device driver.
  23. //
  24. #include <packon.h>
  25. struct _CHAIN_SEND {
  26. WORD ncb_length2;
  27. PUCHAR ncb_buffer2;
  28. };
  29. #include <packoff.h>
  30. //
  31. // Use packing to ensure that the cu union is not forced to word alignment.
  32. // All elements of this structure are naturally aligned.
  33. //
  34. typedef struct _NCBI {
  35. UCHAR ncb_command; /* command code */
  36. volatile UCHAR ncb_retcode; /* return code */
  37. UCHAR ncb_lsn; /* local session number */
  38. UCHAR ncb_num; /* number of our network name */
  39. PUCHAR ncb_buffer; /* address of message buffer */
  40. WORD ncb_length; /* size of message buffer */
  41. union {
  42. UCHAR ncb_callname[NCBNAMSZ];/* blank-padded name of remote */
  43. struct _CHAIN_SEND ncb_chain;
  44. } cu;
  45. UCHAR ncb_name[NCBNAMSZ]; /* our blank-padded netname */
  46. UCHAR ncb_rto; /* rcv timeout/retry count */
  47. UCHAR ncb_sto; /* send timeout/sys timeout */
  48. void (CALLBACK *ncb_post)( struct _NCB * );
  49. /* POST routine address */
  50. UCHAR ncb_lana_num; /* lana (adapter) number */
  51. volatile UCHAR ncb_cmd_cplt; /* 0xff => commmand pending */
  52. // Make driver specific use of the reserved area of the NCB.
  53. WORD ncb_reserved; /* return to natural alignment */
  54. union {
  55. LIST_ENTRY ncb_next; /* queued to worker thread */
  56. IO_STATUS_BLOCK ncb_iosb; /* used for Nt I/O interface */
  57. } u;
  58. HANDLE ncb_event; /* HANDLE to Win32 event */
  59. } NCBI, *PNCBI;
  60. C_ASSERT(FIELD_OFFSET(NCBI, cu) == FIELD_OFFSET(NCB, ncb_callname));
  61. C_ASSERT(FIELD_OFFSET(NCBI, ncb_event) == FIELD_OFFSET(NCB, ncb_event));
  62. C_ASSERT(FIELD_OFFSET(NCBI, ncb_name) == FIELD_OFFSET(NCB, ncb_name));
  63. #if AUTO_RESET
  64. typedef struct _RESET_LANA_NCB {
  65. LIST_ENTRY leList;
  66. NCB ResetNCB;
  67. } RESET_LANA_NCB, *PRESET_LANA_NCB;
  68. #endif
  69. VOID
  70. QueueToWorker(
  71. IN PNCBI pncb
  72. );
  73. DWORD
  74. NetbiosWorker(
  75. IN LPVOID Parameter
  76. );
  77. DWORD
  78. NetbiosWaiter(
  79. IN LPVOID Parameter
  80. );
  81. VOID
  82. SendNcbToDriver(
  83. IN PNCBI pncb
  84. );
  85. VOID
  86. PostRoutineCaller(
  87. PVOID Context,
  88. PIO_STATUS_BLOCK Status,
  89. ULONG Reserved
  90. );
  91. VOID
  92. ChainSendPostRoutine(
  93. PVOID Context,
  94. PIO_STATUS_BLOCK Status,
  95. ULONG Reserved
  96. );
  97. VOID
  98. HangupConnection(
  99. PNCBI pUserNcb
  100. );
  101. //
  102. // debugging info for tracking the workqueue corruption
  103. //
  104. typedef struct _NCB_INFO {
  105. PNCBI pNcbi;
  106. NCBI Ncb;
  107. DWORD dwTimeQueued;
  108. DWORD dwQueuedByThread;
  109. DWORD dwReserved;
  110. } NCB_INFO, *PNCB_INFO;
  111. extern NCB_INFO g_QueuedHistory[];
  112. extern DWORD g_dwNextQHEntry;
  113. extern NCB_INFO g_DeQueuedHistory[];
  114. extern DWORD g_dwNextDQHEntry;
  115. extern NCB_INFO g_SyncCmdsHistory[];
  116. extern DWORD g_dwNextSCEntry;
  117. #define ADD_NEW_ENTRY(Hist, Index, pNcb) \
  118. { \
  119. (Hist)[(Index)].pNcbi = (pNcb); \
  120. (Hist)[(Index)].Ncb = *(pNcb); \
  121. (Hist)[(Index)].dwTimeQueued = GetTickCount(); \
  122. (Hist)[(Index)].dwQueuedByThread = GetCurrentThreadId(); \
  123. Index = ((Index) + 1) % 16; \
  124. }
  125. #define ADD_QUEUE_ENTRY(pNcb) \
  126. ADD_NEW_ENTRY(g_QueuedHistory, g_dwNextQHEntry, pNcb)
  127. #define ADD_DEQUEUE_ENTRY(pNcb) \
  128. ADD_NEW_ENTRY(g_DeQueuedHistory, g_dwNextDQHEntry, pNcb)
  129. #define ADD_SYNCCMD_ENTRY(pNcb) \
  130. ADD_NEW_ENTRY(g_SyncCmdsHistory, g_dwNextSCEntry, pNcb)
  131. #if DBG
  132. VOID
  133. DisplayNcb(
  134. IN PNCBI pncbi
  135. );
  136. #define NbPrintf(String) NbPrint String;
  137. VOID
  138. NbPrint(
  139. char *Format,
  140. ...
  141. );
  142. #else
  143. // Dispose of debug statements in non-debug builds.
  144. #define DisplayNcb( pncb ) {};
  145. #define NbPrintf( String ) {};
  146. #endif
  147. // End of Debug related definitions
  148.