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.

646 lines
18 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. nbfdebug.c
  5. Abstract:
  6. This module contains code that implements debug things for NBF. It is
  7. compiled only if debug is on in the compile phase.
  8. Author:
  9. David Beaver (dbeaver) 18-Apr-1991
  10. Environment:
  11. Kernel mode
  12. Revision History:
  13. David Beaver (dbeaver) 1-July-1991
  14. modified to use new TDI interface
  15. --*/
  16. #include "precomp.h"
  17. #pragma hdrstop
  18. #if DBG
  19. VOID
  20. DisplayOneFrame(
  21. PTP_PACKET Packet
  22. )
  23. /*++
  24. Routine Description:
  25. This routine is a temporary debugging aid that displays an I-frame
  26. before it is sent. This ensures that we have formatted all our packets
  27. correctly.
  28. Arguments:
  29. Packet - Pointer to a TP_PACKET representing an I-frame to be displayed.
  30. Return Value:
  31. none.
  32. --*/
  33. {
  34. PCH s, e;
  35. ULONG ns, nr; // I-frame (NetBIOS) cracking.
  36. PNBF_HDR_CONNECTION NbfHeader;
  37. PDLC_I_FRAME DlcHeader;
  38. BOOLEAN Command, PollFinal;
  39. BOOLEAN IsUFrame=FALSE;
  40. UCHAR CmdByte;
  41. PDLC_S_FRAME SFrame; // DLC frame cracking.
  42. PDLC_U_FRAME UFrame;
  43. DlcHeader = (PDLC_I_FRAME)&(Packet->Header[14]);
  44. NbfHeader = (PNBF_HDR_CONNECTION)&(Packet->Header[18]);
  45. ns = DlcHeader->SendSeq >> 1;
  46. nr = DlcHeader->RcvSeq >> 1;
  47. PollFinal = (BOOLEAN)(DlcHeader->RcvSeq & DLC_I_PF);
  48. Command = (BOOLEAN)!(DlcHeader->Ssap & DLC_SSAP_RESPONSE);
  49. if (DlcHeader->SendSeq & DLC_I_INDICATOR) {
  50. IF_NBFDBG (NBF_DEBUG_DLCFRAMES) {
  51. } else {
  52. return; // if DLCFRAMES not set, don't print.
  53. }
  54. SFrame = (PDLC_S_FRAME)DlcHeader; // alias.
  55. UFrame = (PDLC_U_FRAME)DlcHeader; // alias.
  56. CmdByte = SFrame->Command;
  57. IsUFrame = (BOOLEAN)((UFrame->Command & DLC_U_INDICATOR) == DLC_U_INDICATOR);
  58. if (IsUFrame) {
  59. CmdByte = (UCHAR)(UFrame->Command & ~DLC_U_PF);
  60. }
  61. switch (CmdByte) {
  62. case DLC_CMD_RR:
  63. s = "RR";
  64. PollFinal = (BOOLEAN)(SFrame->RcvSeq & DLC_S_PF);
  65. DbgPrint ("DLC: %s-%s/%s(%ld) ---->\n",
  66. s,
  67. Command ? "c" : "r",
  68. PollFinal ? (Command ? "p" : "f") : "0",
  69. (ULONG)(SFrame->RcvSeq >> 1));
  70. break;
  71. case DLC_CMD_RNR:
  72. s = "RNR";
  73. PollFinal = (BOOLEAN)(SFrame->RcvSeq & DLC_S_PF);
  74. DbgPrint ("DLC: %s-%s/%s(%ld) ---->\n",
  75. s,
  76. Command ? "c" : "r",
  77. PollFinal ? (Command ? "p" : "f") : "0",
  78. (ULONG)(SFrame->RcvSeq >> 1));
  79. break;
  80. case DLC_CMD_REJ:
  81. s = "REJ";
  82. PollFinal = (BOOLEAN)(SFrame->RcvSeq & DLC_S_PF);
  83. DbgPrint ("DLC: %s-%s/%s(%ld) ---->\n",
  84. s,
  85. Command ? "c" : "r",
  86. PollFinal ? (Command ? "p" : "f") : "0",
  87. (ULONG)(SFrame->RcvSeq >> 1));
  88. break;
  89. case DLC_CMD_SABME:
  90. s = "SABME";
  91. PollFinal = (BOOLEAN)(UFrame->Command & DLC_U_PF);
  92. DbgPrint ("DLC: %s-%s/%s ---->\n",
  93. s,
  94. Command ? "c" : "r",
  95. PollFinal ? (Command ? "p" : "f") : "0");
  96. break;
  97. case DLC_CMD_DISC:
  98. s = "DISC";
  99. PollFinal = (BOOLEAN)(UFrame->Command & DLC_U_PF);
  100. DbgPrint ("DLC: %s-%s/%s ---->\n",
  101. s,
  102. Command ? "c" : "r",
  103. PollFinal ? (Command ? "p" : "f") : "0");
  104. break;
  105. case DLC_CMD_UA:
  106. s = "UA";
  107. PollFinal = (BOOLEAN)(UFrame->Command & DLC_U_PF);
  108. DbgPrint ("DLC: %s-%s/%s ---->\n",
  109. s,
  110. Command ? "c" : "r",
  111. PollFinal ? (Command ? "p" : "f") : "0");
  112. break;
  113. case DLC_CMD_DM:
  114. s = "DM";
  115. PollFinal = (BOOLEAN)(UFrame->Command & DLC_U_PF);
  116. DbgPrint ("DLC: %s-%s/%s ---->\n",
  117. s,
  118. Command ? "c" : "r",
  119. PollFinal ? (Command ? "p" : "f") : "0");
  120. break;
  121. case DLC_CMD_FRMR:
  122. s = "FRMR";
  123. PollFinal = (BOOLEAN)(UFrame->Command & DLC_U_PF);
  124. DbgPrint ("DLC: %s-%s/%s ---->\n",
  125. s,
  126. Command ? "c" : "r",
  127. PollFinal ? (Command ? "p" : "f") : "0");
  128. break;
  129. case DLC_CMD_XID:
  130. s = "XID";
  131. PollFinal = (BOOLEAN)(UFrame->Command & DLC_U_PF);
  132. DbgPrint ("DLC: %s-%s/%s ---->\n",
  133. s,
  134. Command ? "c" : "r",
  135. PollFinal ? (Command ? "p" : "f") : "0");
  136. break;
  137. case DLC_CMD_TEST:
  138. s = "TEST";
  139. PollFinal = (BOOLEAN)(UFrame->Command & DLC_U_PF);
  140. DbgPrint ("DLC: %s-%s/%s ---->\n",
  141. s,
  142. Command ? "c" : "r",
  143. PollFinal ? (Command ? "p" : "f") : "0");
  144. break;
  145. default:
  146. s = "(UNKNOWN)";
  147. PollFinal = (BOOLEAN)(UFrame->Command & DLC_U_PF);
  148. DbgPrint ("DLC: %s-%s/%s ---->\n",
  149. s,
  150. Command ? "c" : "r",
  151. PollFinal ? (Command ? "p" : "f") : "0");
  152. }
  153. return;
  154. }
  155. IF_NBFDBG (NBF_DEBUG_IFRAMES) {
  156. } else {
  157. return; // if IFRAMES not set, don't print.
  158. }
  159. switch (NbfHeader->Command) {
  160. case NBF_CMD_ADD_GROUP_NAME_QUERY:
  161. s = "ADD_GROUP_NAME_QUERY"; break;
  162. case NBF_CMD_ADD_NAME_QUERY:
  163. s = "ADD_NAME_QUERY"; break;
  164. case NBF_CMD_NAME_IN_CONFLICT:
  165. s = "NAME_IN_CONFLICT"; break;
  166. case NBF_CMD_STATUS_QUERY:
  167. s = "STATUS_QUERY"; break;
  168. case NBF_CMD_TERMINATE_TRACE:
  169. s = "TERMINATE_TRACE"; break;
  170. case NBF_CMD_DATAGRAM:
  171. s = "DATAGRAM"; break;
  172. case NBF_CMD_DATAGRAM_BROADCAST:
  173. s = "BROADCAST_DATAGRAM"; break;
  174. case NBF_CMD_NAME_QUERY:
  175. s = "NAME_QUERY"; break;
  176. case NBF_CMD_ADD_NAME_RESPONSE:
  177. s = "ADD_NAME_RESPONSE"; break;
  178. case NBF_CMD_NAME_RECOGNIZED:
  179. s = "NAME_RECOGNIZED"; break;
  180. case NBF_CMD_STATUS_RESPONSE:
  181. s = "STATUS_RESPONSE"; break;
  182. case NBF_CMD_TERMINATE_TRACE2:
  183. s = "TERMINATE_TRACE2"; break;
  184. case NBF_CMD_DATA_ACK:
  185. s = "DATA_ACK"; break;
  186. case NBF_CMD_DATA_FIRST_MIDDLE:
  187. s = "DATA_FIRST_MIDDLE"; break;
  188. case NBF_CMD_DATA_ONLY_LAST:
  189. s = "DATA_ONLY_LAST"; break;
  190. case NBF_CMD_SESSION_CONFIRM:
  191. s = "SESSION_CONFIRM"; break;
  192. case NBF_CMD_SESSION_END:
  193. s = "SESSION_END"; break;
  194. case NBF_CMD_SESSION_INITIALIZE:
  195. s = "SESSION_INITIALIZE"; break;
  196. case NBF_CMD_NO_RECEIVE:
  197. s = "NO_RECEIVE"; break;
  198. case NBF_CMD_RECEIVE_OUTSTANDING:
  199. s = "RECEIVE_OUTSTANDING"; break;
  200. case NBF_CMD_RECEIVE_CONTINUE:
  201. s = "RECEIVE_CONTINUE"; break;
  202. case NBF_CMD_SESSION_ALIVE:
  203. s = "SESSION_ALIVE"; break;
  204. default:
  205. s = "<<<<UNKNOWN I PACKET TYPE>>>>";
  206. } /* switch */
  207. if (HEADER_LENGTH(NbfHeader) != 14) {
  208. e = "(LENGTH IN ERROR) ";
  209. } else if (HEADER_SIGNATURE(NbfHeader) != NETBIOS_SIGNATURE) {
  210. e = "(SIGNATURE IN ERROR) ";
  211. } else {
  212. e = "";
  213. }
  214. DbgPrint ("DLC: I-%s/%s, N(S)=%ld, N(R)=%ld %s",
  215. Command ? "c" : "r",
  216. PollFinal ? (Command ? "p" : "f") : "0",
  217. ns, nr, e);
  218. DbgPrint (s);
  219. DbgPrint (" ( D1=%ld, D2=%ld, XC=%ld, RC=%ld )\n",
  220. (ULONG)NbfHeader->Data1,
  221. (ULONG)(NbfHeader->Data2Low+NbfHeader->Data2High*256),
  222. TRANSMIT_CORR(NbfHeader),
  223. RESPONSE_CORR(NbfHeader));
  224. } /* DisplayOneFrame */
  225. VOID
  226. NbfDisplayUIFrame(
  227. PTP_UI_FRAME OuterFrame
  228. )
  229. /*++
  230. Routine Description:
  231. This routine is a temporary debugging aid that displays a UI frame
  232. before it is sent by NbfSendUIFrame. This ensures that we have formatted
  233. all our UI frames correctly.
  234. Arguments:
  235. RawFrame - Pointer to a connectionless frame to be sent.
  236. Return Value:
  237. none.
  238. --*/
  239. {
  240. PCH s, e;
  241. UCHAR ReceiverName [17];
  242. UCHAR SenderName [17];
  243. BOOLEAN PollFinal, Command;
  244. PDLC_S_FRAME SFrame;
  245. PDLC_U_FRAME UFrame;
  246. USHORT i;
  247. PDLC_FRAME DlcHeader;
  248. PNBF_HDR_CONNECTIONLESS NbfHeader;
  249. //
  250. DlcHeader = (PDLC_FRAME)&(OuterFrame->Header[14]);
  251. NbfHeader = (PNBF_HDR_CONNECTIONLESS)&(OuterFrame->Header[17]);
  252. if (DlcHeader->Byte1 != DLC_CMD_UI) {
  253. IF_NBFDBG (NBF_DEBUG_DLCFRAMES) {
  254. } else {
  255. return; // don't print this if DLCFRAMES is off.
  256. }
  257. Command = (BOOLEAN)!(DlcHeader->Ssap & DLC_SSAP_RESPONSE);
  258. SFrame = (PDLC_S_FRAME)DlcHeader; // alias.
  259. UFrame = (PDLC_U_FRAME)DlcHeader; // alias.
  260. switch (DlcHeader->Byte1) {
  261. case DLC_CMD_RR:
  262. s = "RR";
  263. PollFinal = (BOOLEAN)(SFrame->RcvSeq & DLC_S_PF);
  264. DbgPrint ("DLC: %s-%s/%s(%ld) ---->\n",
  265. s,
  266. Command ? "c" : "r",
  267. PollFinal ? (Command ? "p" : "f") : "0",
  268. (ULONG)(SFrame->RcvSeq >> 1));
  269. break;
  270. case DLC_CMD_RNR:
  271. s = "RNR";
  272. PollFinal = (BOOLEAN)(SFrame->RcvSeq & DLC_S_PF);
  273. DbgPrint ("DLC: %s-%s/%s(%ld) ---->\n",
  274. s,
  275. Command ? "c" : "r",
  276. PollFinal ? (Command ? "p" : "f") : "0",
  277. (ULONG)(SFrame->RcvSeq >> 1));
  278. break;
  279. case DLC_CMD_REJ:
  280. s = "REJ";
  281. PollFinal = (BOOLEAN)(SFrame->RcvSeq & DLC_S_PF);
  282. DbgPrint ("DLC: %s-%s/%s(%ld) ---->\n",
  283. s,
  284. Command ? "c" : "r",
  285. PollFinal ? (Command ? "p" : "f") : "0",
  286. (ULONG)(SFrame->RcvSeq >> 1));
  287. break;
  288. case DLC_CMD_SABME:
  289. s = "SABME";
  290. PollFinal = (BOOLEAN)(UFrame->Command & DLC_U_PF);
  291. DbgPrint ("DLC: %s-%s/%s ---->\n",
  292. s,
  293. Command ? "c" : "r",
  294. PollFinal ? (Command ? "p" : "f") : "0");
  295. break;
  296. case DLC_CMD_DISC:
  297. s = "DISC";
  298. PollFinal = (BOOLEAN)(UFrame->Command & DLC_U_PF);
  299. DbgPrint ("DLC: %s-%s/%s ---->\n",
  300. s,
  301. Command ? "c" : "r",
  302. PollFinal ? (Command ? "p" : "f") : "0");
  303. break;
  304. case DLC_CMD_UA:
  305. s = "UA";
  306. PollFinal = (BOOLEAN)(UFrame->Command & DLC_U_PF);
  307. DbgPrint ("DLC: %s-%s/%s ---->\n",
  308. s,
  309. Command ? "c" : "r",
  310. PollFinal ? (Command ? "p" : "f") : "0");
  311. break;
  312. case DLC_CMD_DM:
  313. s = "DM";
  314. PollFinal = (BOOLEAN)(UFrame->Command & DLC_U_PF);
  315. DbgPrint ("DLC: %s-%s/%s ---->\n",
  316. s,
  317. Command ? "c" : "r",
  318. PollFinal ? (Command ? "p" : "f") : "0");
  319. break;
  320. case DLC_CMD_FRMR:
  321. s = "FRMR";
  322. PollFinal = (BOOLEAN)(UFrame->Command & DLC_U_PF);
  323. DbgPrint ("DLC: %s-%s/%s ---->\n",
  324. s,
  325. Command ? "c" : "r",
  326. PollFinal ? (Command ? "p" : "f") : "0");
  327. break;
  328. case DLC_CMD_XID:
  329. s = "XID";
  330. PollFinal = (BOOLEAN)(UFrame->Command & DLC_U_PF);
  331. DbgPrint ("DLC: %s-%s/%s ---->\n",
  332. s,
  333. Command ? "c" : "r",
  334. PollFinal ? (Command ? "p" : "f") : "0");
  335. break;
  336. case DLC_CMD_TEST:
  337. s = "TEST";
  338. PollFinal = (BOOLEAN)(UFrame->Command & DLC_U_PF);
  339. DbgPrint ("DLC: %s-%s/%s ---->\n",
  340. s,
  341. Command ? "c" : "r",
  342. PollFinal ? (Command ? "p" : "f") : "0");
  343. break;
  344. default:
  345. s = "(UNKNOWN)";
  346. PollFinal = (BOOLEAN)(UFrame->Command & DLC_U_PF);
  347. DbgPrint ("DLC: %s-%s/%s ---->\n",
  348. s,
  349. Command ? "c" : "r",
  350. PollFinal ? (Command ? "p" : "f") : "0");
  351. }
  352. return;
  353. }
  354. //
  355. // We know that this is an I-frame, because the bottom bit of the
  356. // first byte in the DLC header is cleared. Go ahead and print it
  357. // as though it were a NetBIOS packet, which it should be.
  358. //
  359. IF_NBFDBG (NBF_DEBUG_IFRAMES) {
  360. } else {
  361. return; // don't print this if IFRAMES is off.
  362. }
  363. switch (NbfHeader->Command) {
  364. case NBF_CMD_ADD_GROUP_NAME_QUERY:
  365. s = "ADD_GROUP_NAME_QUERY"; break;
  366. case NBF_CMD_ADD_NAME_QUERY:
  367. s = "ADD_NAME_QUERY"; break;
  368. case NBF_CMD_NAME_IN_CONFLICT:
  369. s = "NAME_IN_CONFLICT"; break;
  370. case NBF_CMD_STATUS_QUERY:
  371. s = "STATUS_QUERY"; break;
  372. case NBF_CMD_TERMINATE_TRACE:
  373. s = "TERMINATE_TRACE"; break;
  374. case NBF_CMD_DATAGRAM:
  375. s = "DATAGRAM"; break;
  376. case NBF_CMD_DATAGRAM_BROADCAST:
  377. s = "BROADCAST_DATAGRAM"; break;
  378. case NBF_CMD_NAME_QUERY:
  379. s = "NAME_QUERY"; break;
  380. case NBF_CMD_ADD_NAME_RESPONSE:
  381. s = "ADD_NAME_RESPONSE"; break;
  382. case NBF_CMD_NAME_RECOGNIZED:
  383. s = "NAME_RECOGNIZED"; break;
  384. case NBF_CMD_STATUS_RESPONSE:
  385. s = "STATUS_RESPONSE"; break;
  386. case NBF_CMD_TERMINATE_TRACE2:
  387. s = "TERMINATE_TRACE2"; break;
  388. case NBF_CMD_DATA_ACK:
  389. s = "DATA_ACK"; break;
  390. case NBF_CMD_DATA_FIRST_MIDDLE:
  391. s = "DATA_FIRST_MIDDLE"; break;
  392. case NBF_CMD_DATA_ONLY_LAST:
  393. s = "DATA_ONLY_LAST"; break;
  394. case NBF_CMD_SESSION_CONFIRM:
  395. s = "SESSION_CONFIRM"; break;
  396. case NBF_CMD_SESSION_END:
  397. s = "SESSION_END"; break;
  398. case NBF_CMD_SESSION_INITIALIZE:
  399. s = "SESSION_INITIALIZE"; break;
  400. case NBF_CMD_NO_RECEIVE:
  401. s = "NO_RECEIVE"; break;
  402. case NBF_CMD_RECEIVE_OUTSTANDING:
  403. s = "RECEIVE_OUTSTANDING"; break;
  404. case NBF_CMD_RECEIVE_CONTINUE:
  405. s = "RECEIVE_CONTINUE"; break;
  406. case NBF_CMD_SESSION_ALIVE:
  407. s = "SESSION_ALIVE"; break;
  408. default:
  409. s = "<<<<UNKNOWN UI PACKET TYPE>>>>";
  410. } /* switch */
  411. for (i=0; i<16; i++) { // copy NetBIOS names.
  412. SenderName [i] = NbfHeader->SourceName [i];
  413. ReceiverName [i] = NbfHeader->DestinationName [i];
  414. }
  415. SenderName [16] = 0; // install zero bytes.
  416. ReceiverName [16] = 0;
  417. if (HEADER_LENGTH(NbfHeader) != 44) {
  418. e = "(LENGTH IN ERROR) ";
  419. } else if (HEADER_SIGNATURE(NbfHeader) != NETBIOS_SIGNATURE) {
  420. e = "(SIGNATURE IN ERROR) ";
  421. } else {
  422. e = "";
  423. }
  424. DbgPrint ("[UI] %s", e);
  425. DbgPrint (s);
  426. DbgPrint (" ( D1=%ld, D2=%ld, XC=%ld, RC=%ld, ",
  427. (ULONG)NbfHeader->Data1,
  428. (ULONG)(NbfHeader->Data2Low+NbfHeader->Data2High*256),
  429. TRANSMIT_CORR(NbfHeader),
  430. RESPONSE_CORR(NbfHeader));
  431. DbgPrint ("'%s'->'%s' ) ---->\n", SenderName, ReceiverName);
  432. } /* NbfDisplayUIFrame */
  433. VOID
  434. NbfHexDumpLine(
  435. PCHAR pch,
  436. ULONG len,
  437. PCHAR s,
  438. PCHAR t
  439. )
  440. /*++
  441. Routine Description:
  442. This routine builds a line of text containing hex and printable characters.
  443. Arguments:
  444. IN pch - Supplies buffer to be displayed.
  445. IN len - Supplies the length of the buffer in bytes.
  446. IN s - Supplies the start of the buffer to be loaded with the string
  447. of hex characters.
  448. IN t - Supplies the start of the buffer to be loaded with the string
  449. of printable ascii characters.
  450. Return Value:
  451. none.
  452. --*/
  453. {
  454. static UCHAR rghex[] = "0123456789ABCDEF";
  455. UCHAR c;
  456. UCHAR *hex, *asc;
  457. hex = s;
  458. asc = t;
  459. *(asc++) = '*';
  460. while (len--) {
  461. c = *(pch++);
  462. *(hex++) = rghex [c >> 4] ;
  463. *(hex++) = rghex [c & 0x0F];
  464. *(hex++) = ' ';
  465. *(asc++) = (c < ' ' || c > '~') ? (CHAR )'.' : c;
  466. }
  467. *(asc++) = '*';
  468. *asc = 0;
  469. *hex = 0;
  470. }
  471. VOID
  472. NbfFormattedDump(
  473. PCHAR far_p,
  474. ULONG len
  475. )
  476. /*++
  477. Routine Description:
  478. This routine outputs a buffer in lines of text containing hex and
  479. printable characters.
  480. Arguments:
  481. IN far_p - Supplies buffer to be displayed.
  482. IN len - Supplies the length of the buffer in bytes.
  483. Return Value:
  484. none.
  485. --*/
  486. {
  487. ULONG l;
  488. char s[80], t[80];
  489. while (len) {
  490. l = len < 16 ? len : 16;
  491. DbgPrint ("\n%lx ", far_p);
  492. NbfHexDumpLine (far_p, l, s, t);
  493. DbgPrint ("%s%.*s%s", s, 1 + ((16 - l) * 3), "", t);
  494. len -= l;
  495. far_p += l;
  496. }
  497. DbgPrint ("\n");
  498. }
  499. #endif