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.

332 lines
7.4 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. llclib.c
  5. Abstract:
  6. This module includes some general purpose library routines
  7. Contents:
  8. SwapMemCpy
  9. RemoveFromLinkList
  10. LlcSleep
  11. LlcInitUnicodeString
  12. LlcFreeUnicodeString
  13. Author:
  14. Antti Saarenheimo (o-anttis) 20-MAY-1991
  15. Revision History:
  16. --*/
  17. #include <llc.h>
  18. #include <memory.h>
  19. //
  20. // This table is used to swap the bits within each byte.
  21. // The bits are in a reverse order in the token-ring frame header.
  22. // We must swap the bits in a ethernet frame header, when the header
  23. // is copied to a user buffer.
  24. //
  25. UCHAR Swap[256] = {
  26. 0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0, 0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0,
  27. 0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8, 0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8,
  28. 0x04, 0x84, 0x44, 0xc4, 0x24, 0xa4, 0x64, 0xe4, 0x14, 0x94, 0x54, 0xd4, 0x34, 0xb4, 0x74, 0xf4,
  29. 0x0c, 0x8c, 0x4c, 0xcc, 0x2c, 0xac, 0x6c, 0xec, 0x1c, 0x9c, 0x5c, 0xdc, 0x3c, 0xbc, 0x7c, 0xfc,
  30. 0x02, 0x82, 0x42, 0xc2, 0x22, 0xa2, 0x62, 0xe2, 0x12, 0x92, 0x52, 0xd2, 0x32, 0xb2, 0x72, 0xf2,
  31. 0x0a, 0x8a, 0x4a, 0xca, 0x2a, 0xaa, 0x6a, 0xea, 0x1a, 0x9a, 0x5a, 0xda, 0x3a, 0xba, 0x7a, 0xfa,
  32. 0x06, 0x86, 0x46, 0xc6, 0x26, 0xa6, 0x66, 0xe6, 0x16, 0x96, 0x56, 0xd6, 0x36, 0xb6, 0x76, 0xf6,
  33. 0x0e, 0x8e, 0x4e, 0xce, 0x2e, 0xae, 0x6e, 0xee, 0x1e, 0x9e, 0x5e, 0xde, 0x3e, 0xbe, 0x7e, 0xfe,
  34. 0x01, 0x81, 0x41, 0xc1, 0x21, 0xa1, 0x61, 0xe1, 0x11, 0x91, 0x51, 0xd1, 0x31, 0xb1, 0x71, 0xf1,
  35. 0x09, 0x89, 0x49, 0xc9, 0x29, 0xa9, 0x69, 0xe9, 0x19, 0x99, 0x59, 0xd9, 0x39, 0xb9, 0x79, 0xf9,
  36. 0x05, 0x85, 0x45, 0xc5, 0x25, 0xa5, 0x65, 0xe5, 0x15, 0x95, 0x55, 0xd5, 0x35, 0xb5, 0x75, 0xf5,
  37. 0x0d, 0x8d, 0x4d, 0xcd, 0x2d, 0xad, 0x6d, 0xed, 0x1d, 0x9d, 0x5d, 0xdd, 0x3d, 0xbd, 0x7d, 0xfd,
  38. 0x03, 0x83, 0x43, 0xc3, 0x23, 0xa3, 0x63, 0xe3, 0x13, 0x93, 0x53, 0xd3, 0x33, 0xb3, 0x73, 0xf3,
  39. 0x0b, 0x8b, 0x4b, 0xcb, 0x2b, 0xab, 0x6b, 0xeb, 0x1b, 0x9b, 0x5b, 0xdb, 0x3b, 0xbb, 0x7b, 0xfb,
  40. 0x07, 0x87, 0x47, 0xc7, 0x27, 0xa7, 0x67, 0xe7, 0x17, 0x97, 0x57, 0xd7, 0x37, 0xb7, 0x77, 0xf7,
  41. 0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef, 0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff
  42. };
  43. VOID
  44. SwapMemCpy(
  45. IN BOOLEAN boolSwapBytes,
  46. IN PUCHAR pDest,
  47. IN PUCHAR pSrc,
  48. IN UINT Len
  49. )
  50. /*++
  51. Routine Description:
  52. conditionally swaps the bits within the copied bytes.
  53. Arguments:
  54. boolSwapBytes - TRUE if bytes are to be bit-swapped
  55. pDest - where to copy to
  56. pSrc - where to copy from
  57. Len - number of bytes to copy
  58. Return Value:
  59. None.
  60. --*/
  61. {
  62. if (boolSwapBytes) {
  63. SwappingMemCpy(pDest, pSrc, Len);
  64. } else {
  65. LlcMemCpy(pDest, pSrc, Len);
  66. }
  67. }
  68. VOID
  69. RemoveFromLinkList(
  70. IN OUT PVOID* ppBase,
  71. IN PVOID pElement
  72. )
  73. /*++
  74. Routine Description:
  75. Searches and removes the given element from a single-entry link list.
  76. ASSUMES: the link points to the link field in the next object
  77. Arguments:
  78. ppBase - pointer to pointer to queue
  79. pElement - pointer to element to remove from queue
  80. Return Value:
  81. None.
  82. --*/
  83. {
  84. for (; (PQUEUE_PACKET)*ppBase; ppBase = (PVOID*)&(((PQUEUE_PACKET)*ppBase)->pNext)) {
  85. if (*ppBase == pElement) {
  86. *ppBase = ((PQUEUE_PACKET)pElement)->pNext;
  87. #if LLC_DBG
  88. ((PQUEUE_PACKET)pElement)->pNext = NULL;
  89. #endif
  90. break;
  91. }
  92. }
  93. }
  94. VOID
  95. LlcSleep(
  96. IN LONG lMicroSeconds
  97. )
  98. /*++
  99. Routine Description:
  100. Suspends thread execution for a short time
  101. Arguments:
  102. lMicroSeconds - number of microseconds to wait
  103. Return Value:
  104. None.
  105. --*/
  106. {
  107. TIME t;
  108. t.LowTime = -(lMicroSeconds * 10);
  109. t.HighTime = -1;
  110. KeDelayExecutionThread(UserMode, FALSE, &t);
  111. }
  112. DLC_STATUS
  113. LlcInitUnicodeString(
  114. OUT PUNICODE_STRING pStringDest,
  115. IN PUNICODE_STRING pStringSrc
  116. )
  117. /*++
  118. Routine Description:
  119. initialize a UNICODE_STRING
  120. Arguments:
  121. pStringDest - pointer to UNICODE_STRING structure to initialize
  122. pStringSrc - pointer to UNICODE_STRING structure containing valid string
  123. Return Value:
  124. DLC_STATUS
  125. Success - STATUS_SUCCESS
  126. Failure - DLC_STATUS_NO_MEMORY
  127. Couldn't allocate memory from non-paged pool
  128. --*/
  129. {
  130. pStringDest->MaximumLength = (USHORT)(pStringSrc->Length + sizeof(WCHAR));
  131. pStringDest->Buffer = ALLOCATE_STRING_DRIVER(pStringDest->MaximumLength);
  132. if (pStringDest->Buffer == NULL) {
  133. return DLC_STATUS_NO_MEMORY;
  134. } else {
  135. RtlCopyUnicodeString(pStringDest, pStringSrc);
  136. return STATUS_SUCCESS;
  137. }
  138. }
  139. VOID
  140. LlcFreeUnicodeString(
  141. IN PUNICODE_STRING UnicodeString
  142. )
  143. /*++
  144. Routine Description:
  145. Companion routine to LlcInitUnicodeString - frees memory allocated from
  146. non-paged pool for a UNICODE string
  147. Arguments:
  148. UnicodeString - pointer to UNICODE_STRING structure, the buffer for which
  149. was allocated in LlcInitUnicodeString
  150. Return Value:
  151. None.
  152. --*/
  153. {
  154. FREE_STRING_DRIVER(UnicodeString->Buffer);
  155. }
  156. //#if LLC_DBG
  157. //
  158. //VOID
  159. //LlcInvalidObjectType( VOID )
  160. //{
  161. // DbgPrint( "DLC: Invalid object type!\n");
  162. // DbgBreakPoint();
  163. //}
  164. //
  165. //
  166. //VOID LlcBreakListCorrupt( VOID )
  167. //{
  168. // DbgPrint( "Link list is corrupt! ");
  169. // DbgBreakPoint();
  170. //}
  171. //
  172. //static PUCHAR aLanLlcInputStrings[] = {
  173. // "DISC0",
  174. // "DISC1",
  175. // "DM0",
  176. // "DM1",
  177. // "FRMR0",
  178. // "FRMR1",
  179. // "SABME0",
  180. // "SABME1",
  181. // "UA0",
  182. // "UA1",
  183. // "IS_I_r0",
  184. // "IS_I_r1",
  185. // "IS_I_c0",
  186. // "IS_I_c1",
  187. // "OS_I_r0",
  188. // "OS_I_r1",
  189. // "OS_I_c0",
  190. // "OS_I_c1",
  191. // "REJ_r0",
  192. // "REJ_r1",
  193. // "REJ_c0",
  194. // "REJ_c1",
  195. // "RNR_r0",
  196. // "RNR_r1",
  197. // "RNR_c0",
  198. // "RNR_c1",
  199. // "RR_r0",
  200. // "RR_r1",
  201. // "RR_c0",
  202. // "RR_c1",
  203. // "LPDU_INVALID_r0",
  204. // "LPDU_INVALID_r1",
  205. // "LPDU_INVALID_c0",
  206. // "LPDU_INVALID_c1",
  207. // "ACTIVATE_LS",
  208. // "DEACTIVATE_LS",
  209. // "ENTER_LCL_Busy",
  210. // "EXIT_LCL_Busy",
  211. // "SEND_I_POLL",
  212. // "SET_ABME",
  213. // "SET_ADM",
  214. // "Ti_Expired",
  215. // "T1_Expired",
  216. // "T2_Expired"
  217. //};
  218. //
  219. ////
  220. //// Procedure prints the last global inputs and time stamps. This
  221. //// does not print the stamps of a specific link station!!!
  222. ////
  223. //VOID
  224. //PrintLastInputs(
  225. // IN PUCHAR pszMessage,
  226. // IN PDATA_LINK pLink
  227. // )
  228. //{
  229. // UINT i;
  230. // UINT j = 0;
  231. //
  232. // DbgPrint( pszMessage );
  233. //
  234. // //
  235. // // Print 20 last time stamps and state inputs of the given
  236. // // link station.
  237. // //
  238. // for (i = InputIndex - 1; i > InputIndex - LLC_INPUT_TABLE_SIZE; i--)
  239. // {
  240. // if (aLast[ i % LLC_INPUT_TABLE_SIZE ].pLink == pLink)
  241. // {
  242. // DbgPrint(
  243. // "%4x:%10s, ",
  244. // aLast[i % LLC_INPUT_TABLE_SIZE].Time,
  245. // aLanLlcInputStrings[ aLast[i % LLC_INPUT_TABLE_SIZE].Input]
  246. // );
  247. // j++;
  248. // if ((j % 4) == 0)
  249. // {
  250. // DbgPrint( "\n" );
  251. // }
  252. // if (j == 20)
  253. // {
  254. // break;
  255. // }
  256. // }
  257. // }
  258. //}
  259. //#endif