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.

1087 lines
30 KiB

  1. /*++
  2. Copyright (c) 1989, 1990, 1991 Microsoft Corporation
  3. Module Name:
  4. framecon.c
  5. Abstract:
  6. This module contains routines which build NetBIOS Frames Protocol frames,
  7. both connection-oriented and connectionless. The following frames are
  8. constructed by routines in this module:
  9. o NBF_CMD_ADD_GROUP_NAME_QUERY
  10. o NBF_CMD_ADD_NAME_QUERY
  11. o NBF_CMD_NAME_IN_CONFLICT
  12. o NBF_CMD_STATUS_QUERY
  13. o NBF_CMD_TERMINATE_TRACE
  14. o NBF_CMD_DATAGRAM
  15. o NBF_CMD_DATAGRAM_BROADCAST
  16. o NBF_CMD_NAME_QUERY
  17. o NBF_CMD_ADD_NAME_RESPONSE
  18. o NBF_CMD_NAME_RECOGNIZED
  19. o NBF_CMD_STATUS_RESPONSE
  20. o NBF_CMD_TERMINATE_TRACE2
  21. o NBF_CMD_DATA_ACK
  22. o NBF_CMD_DATA_FIRST_MIDDLE
  23. o NBF_CMD_DATA_ONLY_LAST
  24. o NBF_CMD_SESSION_CONFIRM
  25. o NBF_CMD_SESSION_END
  26. o NBF_CMD_SESSION_INITIALIZE
  27. o NBF_CMD_NO_RECEIVE
  28. o NBF_CMD_RECEIVE_OUTSTANDING
  29. o NBF_CMD_RECEIVE_CONTINUE
  30. o NBF_CMD_SESSION_ALIVE
  31. Author:
  32. David Beaver (dbeaver) 1-July-1991
  33. Environment:
  34. Kernel mode
  35. Revision History:
  36. --*/
  37. #include "precomp.h"
  38. #pragma hdrstop
  39. VOID
  40. ConstructAddGroupNameQuery(
  41. IN PNBF_HDR_CONNECTIONLESS RawFrame,// frame buffer to format.
  42. IN USHORT Correlator, // correlator for ADD_NAME_RESPONSE.
  43. IN PNAME GroupName // NetBIOS group name to be added.
  44. )
  45. /*++
  46. Routine Description:
  47. This routine constructs an NBF_CMD_ADD_GROUP_NAME_QUERY connectionless
  48. NetBIOS Frame.
  49. Arguments:
  50. RawFrame - Pointer to an unformatted 44-byte connectionless frame buffer.
  51. Correlator - Correlator for ADD_NAME_RESPONSE frame.
  52. GroupName - Pointer to NetBIOS group name to be added.
  53. Return Value:
  54. none.
  55. --*/
  56. {
  57. USHORT i;
  58. IF_NBFDBG (NBF_DEBUG_FRAMECON) {
  59. NbfPrint0 ("ConstructAddGroupNameQuery: Entered.\n");
  60. }
  61. RawFrame->Command = NBF_CMD_ADD_GROUP_NAME_QUERY;
  62. HEADER_LENGTH(RawFrame) = sizeof(NBF_HDR_CONNECTIONLESS);
  63. HEADER_SIGNATURE(RawFrame) = NETBIOS_SIGNATURE;
  64. RawFrame->Data1 = 0; // reserved field, MBZ.
  65. RawFrame->Data2Low = 0;
  66. RawFrame->Data2High = 0;
  67. TRANSMIT_CORR(RawFrame) = Correlator;
  68. RESPONSE_CORR(RawFrame) = (USHORT)0;
  69. for (i=0; i<NETBIOS_NAME_LENGTH; i++) {
  70. RawFrame->DestinationName [i] = 0;
  71. RawFrame->SourceName [i] = GroupName [i];
  72. }
  73. } /* ConstructAddGroupNameQuery */
  74. VOID
  75. ConstructAddNameQuery(
  76. IN PNBF_HDR_CONNECTIONLESS RawFrame,// frame buffer to format.
  77. IN USHORT Correlator, // correlator for ADD_NAME_RESPONSE.
  78. IN PNAME Name // NetBIOS name to be added.
  79. )
  80. /*++
  81. Routine Description:
  82. This routine constructs an NBF_CMD_ADD_NAME_QUERY connectionless
  83. NetBIOS Frame.
  84. Arguments:
  85. RawFrame - Pointer to an unformatted 44-byte connectionless frame buffer.
  86. Correlator - Correlator for ADD_NAME_RESPONSE frame.
  87. Name - Pointer to NetBIOS name to be added.
  88. Return Value:
  89. none.
  90. --*/
  91. {
  92. USHORT i;
  93. IF_NBFDBG (NBF_DEBUG_FRAMECON) {
  94. NbfPrint0 ("ConstructAddNameQuery: Entered.\n");
  95. }
  96. RawFrame->Command = NBF_CMD_ADD_NAME_QUERY;
  97. HEADER_LENGTH(RawFrame) = sizeof(NBF_HDR_CONNECTIONLESS);
  98. HEADER_SIGNATURE(RawFrame) = NETBIOS_SIGNATURE;
  99. RawFrame->Data1 = 0; // reserved field, MBZ.
  100. RawFrame->Data2Low = 0;
  101. RawFrame->Data2High = 0;
  102. TRANSMIT_CORR(RawFrame) = Correlator;
  103. RESPONSE_CORR(RawFrame) = (USHORT)0;
  104. for (i=0; i<NETBIOS_NAME_LENGTH; i++) {
  105. RawFrame->DestinationName [i] = 0;
  106. RawFrame->SourceName [i] = Name [i];
  107. }
  108. } /* ConstructAddNameQuery */
  109. VOID
  110. ConstructNameInConflict(
  111. IN PNBF_HDR_CONNECTIONLESS RawFrame,// frame buffer to format.
  112. IN PNAME ConflictingName, // NetBIOS name that is conflicting.
  113. IN PNAME SendingPermanentName // NetBIOS permanent node name of sender.
  114. )
  115. /*++
  116. Routine Description:
  117. This routine constructs an NBF_CMD_NAME_IN_CONFLICT connectionless
  118. NetBIOS Frame.
  119. Arguments:
  120. RawFrame - Pointer to an unformatted 44-byte connectionless frame buffer.
  121. Conflictingname - Pointer to NetBIOS name that is conflicting.
  122. SendingPermanentName - Pointer to NetBIOS permanent node name of sender.
  123. Return Value:
  124. none.
  125. --*/
  126. {
  127. USHORT i;
  128. IF_NBFDBG (NBF_DEBUG_FRAMECON) {
  129. NbfPrint0 ("ConstructNameInConflict: Entered.\n");
  130. }
  131. RawFrame->Command = NBF_CMD_NAME_IN_CONFLICT;
  132. HEADER_LENGTH(RawFrame) = sizeof(NBF_HDR_CONNECTIONLESS);
  133. HEADER_SIGNATURE(RawFrame) = NETBIOS_SIGNATURE;
  134. RawFrame->Data1 = 0; // reserved field, MBZ.
  135. RawFrame->Data2Low = 0;
  136. RawFrame->Data2High = 0;
  137. TRANSMIT_CORR(RawFrame) = (USHORT)0;
  138. RESPONSE_CORR(RawFrame) = (USHORT)0;
  139. for (i=0; i<NETBIOS_NAME_LENGTH; i++) {
  140. RawFrame->DestinationName [i] = ConflictingName[i];
  141. RawFrame->SourceName [i] = SendingPermanentName[i];
  142. }
  143. } /* ConstructNameInConflict */
  144. VOID
  145. ConstructStatusQuery(
  146. IN PNBF_HDR_CONNECTIONLESS RawFrame,// frame buffer to format.
  147. IN UCHAR RequestType, // type of request.
  148. IN USHORT BufferLength, // length of user's status buffer.
  149. IN USHORT Correlator, // correlator for STATUS_RESPONSE.
  150. IN PNAME ReceiverName, // NetBIOS name of receiver.
  151. IN PNAME SendingPermanentName // NetBIOS permanent node name of sender.
  152. )
  153. /*++
  154. Routine Description:
  155. This routine constructs an NBF_CMD_STATUS_QUERY connectionless
  156. NetBIOS Frame.
  157. Arguments:
  158. RawFrame - Pointer to an unformatted 44-byte connectionless frame buffer.
  159. RequestType - Type of request. One of:
  160. 0 - request is 1.x or 2.0.
  161. 1 - first request, 2.1 or above.
  162. >1 - subsequent request, 2.1 or above.
  163. BufferLength - Length of user's status buffer.
  164. Correlator - Correlator for STATUS_RESPONSE frame.
  165. ReceiverName - Pointer to NetBIOS name of receiver.
  166. SendingPermanentName - Pointer to NetBIOS permanent node name of sender.
  167. Return Value:
  168. none.
  169. --*/
  170. {
  171. SHORT i;
  172. IF_NBFDBG (NBF_DEBUG_FRAMECON) {
  173. NbfPrint1 ("ConstructStatusQuery: Entered, frame: %lx\n", RawFrame);
  174. }
  175. RawFrame->Command = NBF_CMD_STATUS_QUERY;
  176. HEADER_LENGTH(RawFrame) = sizeof(NBF_HDR_CONNECTIONLESS);
  177. HEADER_SIGNATURE(RawFrame) = NETBIOS_SIGNATURE;
  178. RawFrame->Data1 = RequestType;
  179. RawFrame->Data2Low = (UCHAR)(BufferLength & 0xff);
  180. RawFrame->Data2High = (UCHAR)(BufferLength >> 8);
  181. TRANSMIT_CORR(RawFrame) = (USHORT)0;
  182. RESPONSE_CORR(RawFrame) = Correlator;
  183. for (i=0; i<NETBIOS_NAME_LENGTH; i++) {
  184. RawFrame->DestinationName [i] = ReceiverName [i];
  185. RawFrame->SourceName [i] = SendingPermanentName [i];
  186. }
  187. } /* ConstructStatusQuery */
  188. VOID
  189. ConstructDatagram(
  190. IN PNBF_HDR_CONNECTIONLESS RawFrame,// frame buffer to format.
  191. IN PNAME ReceiverName, // NetBIOS name of receiver.
  192. IN PNAME SenderName // NetBIOS name of sender.
  193. )
  194. /*++
  195. Routine Description:
  196. This routine constructs an NBF_CMD_DATAGRAM connectionless
  197. NetBIOS Frame.
  198. Arguments:
  199. RawFrame - Pointer to an unformatted 44-byte connectionless frame buffer.
  200. ReceiverName - Pointer to a NetBIOS name of the receiver.
  201. SenderName - Pointer to a NetBIOS name of the sender.
  202. Return Value:
  203. none.
  204. --*/
  205. {
  206. USHORT i;
  207. IF_NBFDBG (NBF_DEBUG_FRAMECON) {
  208. NbfPrint0 ("ConstructDatagram: Entered.\n");
  209. }
  210. RawFrame->Command = NBF_CMD_DATAGRAM;
  211. HEADER_LENGTH(RawFrame) = sizeof(NBF_HDR_CONNECTIONLESS);
  212. HEADER_SIGNATURE(RawFrame) = NETBIOS_SIGNATURE;
  213. RawFrame->Data1 = 0; // reserved field, MBZ.
  214. RawFrame->Data2Low = 0;
  215. RawFrame->Data2High = 0;
  216. TRANSMIT_CORR(RawFrame) = (USHORT)0;
  217. RESPONSE_CORR(RawFrame) = (USHORT)0;
  218. for (i=0; i<NETBIOS_NAME_LENGTH; i++) {
  219. RawFrame->DestinationName [i] = ReceiverName [i];
  220. RawFrame->SourceName [i] = SenderName [i];
  221. }
  222. } /* ConstructDatagram */
  223. VOID
  224. ConstructDatagramBroadcast(
  225. IN PNBF_HDR_CONNECTIONLESS RawFrame,// frame buffer to format.
  226. IN PNAME SenderName // NetBIOS name of sender.
  227. )
  228. /*++
  229. Routine Description:
  230. This routine constructs an NBF_CMD_DATAGRAM_BROADCAST connectionless
  231. NetBIOS Frame.
  232. Arguments:
  233. RawFrame - Pointer to an unformatted 44-byte connectionless frame buffer.
  234. SenderName - Pointer to a NetBIOS name of the sender.
  235. Return Value:
  236. none.
  237. --*/
  238. {
  239. USHORT i;
  240. IF_NBFDBG (NBF_DEBUG_FRAMECON) {
  241. NbfPrint0 ("ConstructDatagramBroadcast: Entered.\n");
  242. }
  243. RawFrame->Command = NBF_CMD_DATAGRAM_BROADCAST;
  244. HEADER_LENGTH(RawFrame) = sizeof(NBF_HDR_CONNECTIONLESS);
  245. HEADER_SIGNATURE(RawFrame) = NETBIOS_SIGNATURE;
  246. RawFrame->Data1 = 0; // reserved field, MBZ.
  247. RawFrame->Data2Low = 0;
  248. RawFrame->Data2High = 0;
  249. TRANSMIT_CORR(RawFrame) = (USHORT)0;
  250. RESPONSE_CORR(RawFrame) = (USHORT)0;
  251. for (i=0; i<NETBIOS_NAME_LENGTH; i++) {
  252. RawFrame->DestinationName [i] = 0;
  253. RawFrame->SourceName [i] = SenderName [i];
  254. }
  255. } /* ConstructDatagramBroadcast */
  256. VOID
  257. ConstructNameQuery(
  258. IN PNBF_HDR_CONNECTIONLESS RawFrame,// frame buffer to format.
  259. IN UCHAR NameType, // type of name.
  260. IN UCHAR LocalSessionNumber, // LSN assigned to session (0=FIND_NAME).
  261. IN USHORT Correlator, // correlator in NAME_RECOGNIZED.
  262. IN PNAME SenderName, // NetBIOS name of sender.
  263. IN PNAME ReceiverName // NetBIOS name of receiver.
  264. )
  265. /*++
  266. Routine Description:
  267. This routine constructs an NBF_CMD_NAME_QUERY connectionless
  268. NetBIOS Frame.
  269. Arguments:
  270. RawFrame - Pointer to an unformatted 44-byte connectionless frame buffer.
  271. NameType - Type of name, one of the following:
  272. NAME_QUERY_LSN_FIND_NAME
  273. LocalSessionNumber - LSN assigned to session (0=FIND.NAME).
  274. Correlator - Correlator in NAME_RECOGNIZED.
  275. SenderName - Pointer to a NetBIOS name of the sender.
  276. ReceiverName - Pointer to a NetBIOS name of the receiver.
  277. Return Value:
  278. none.
  279. --*/
  280. {
  281. SHORT i;
  282. IF_NBFDBG (NBF_DEBUG_FRAMECON) {
  283. NbfPrint1 ("ConstructNameQuery: Entered, frame: %lx\n", RawFrame);
  284. }
  285. RawFrame->Command = NBF_CMD_NAME_QUERY;
  286. HEADER_LENGTH(RawFrame) = sizeof(NBF_HDR_CONNECTIONLESS);
  287. HEADER_SIGNATURE(RawFrame) = NETBIOS_SIGNATURE;
  288. RawFrame->Data1 = 0; // reserved field, MBZ.
  289. RawFrame->Data2Low = LocalSessionNumber;
  290. RawFrame->Data2High = NameType;
  291. TRANSMIT_CORR(RawFrame) = (USHORT)0;
  292. RESPONSE_CORR(RawFrame) = Correlator;
  293. for (i=0; i<NETBIOS_NAME_LENGTH; i++) {
  294. RawFrame->DestinationName [i] = ReceiverName [i];
  295. RawFrame->SourceName [i] = SenderName [i];
  296. }
  297. } /* ConstructNameQuery */
  298. VOID
  299. ConstructAddNameResponse(
  300. IN PNBF_HDR_CONNECTIONLESS RawFrame,// frame buffer to format.
  301. IN UCHAR NameType, // type of name.
  302. IN USHORT Correlator, // correlator from ADD_[GROUP_]NAME_QUERY.
  303. IN PNAME Name // NetBIOS name being responded to.
  304. )
  305. /*++
  306. Routine Description:
  307. This routine constructs an NBF_CMD_ADD_NAME_RESPONSE connectionless
  308. NetBIOS Frame.
  309. Arguments:
  310. RawFrame - Pointer to an unformatted 44-byte connectionless frame buffer.
  311. NameType - Type of name, either group or unique.
  312. Correlator - Correlator from ADD_[GROUP]NAME_QUERY.
  313. Name - Pointer to NetBIOS name being responded to.
  314. Return Value:
  315. none.
  316. --*/
  317. {
  318. USHORT i;
  319. IF_NBFDBG (NBF_DEBUG_FRAMECON) {
  320. NbfPrint0 ("ConstructAddNameResponse: Entered.\n");
  321. }
  322. RawFrame->Command = NBF_CMD_ADD_NAME_RESPONSE;
  323. HEADER_LENGTH(RawFrame) = sizeof(NBF_HDR_CONNECTIONLESS);
  324. HEADER_SIGNATURE(RawFrame) = NETBIOS_SIGNATURE;
  325. RawFrame->Data1 = 0; // reserved field, MBZ.
  326. RawFrame->Data2Low = NameType;
  327. RawFrame->Data2High = 0;
  328. TRANSMIT_CORR(RawFrame) = Correlator;
  329. RESPONSE_CORR(RawFrame) = (USHORT)0;
  330. for (i=0; i<NETBIOS_NAME_LENGTH; i++) {
  331. RawFrame->DestinationName [i] = Name [i];
  332. RawFrame->SourceName [i] = Name [i];
  333. }
  334. } /* ConstructAddNameResponse */
  335. VOID
  336. ConstructNameRecognized(
  337. IN PNBF_HDR_CONNECTIONLESS RawFrame,// frame buffer to format.
  338. IN UCHAR NameType, // type of name.
  339. IN UCHAR LocalSessionNumber, // LSN assigned to session.
  340. IN USHORT NameQueryCorrelator, // correlator from NAME_QUERY.
  341. IN USHORT Correlator, // correlator expected from next response.
  342. IN PNAME SenderName, // NetBIOS name of sender.
  343. IN PNAME ReceiverName // NetBIOS name of receiver.
  344. )
  345. /*++
  346. Routine Description:
  347. This routine constructs an NBF_CMD_NAME_RECOGNIZED connectionless
  348. NetBIOS Frame.
  349. Arguments:
  350. RawFrame - Pointer to an unformatted 44-byte connectionless frame buffer.
  351. NameType - Type of name, either group or unique.
  352. LocalSessionNumber - LSN assigned to session. Special values are:
  353. NAME_RECOGNIZED_LSN_NO_LISTENS // no listens available.
  354. NAME_RECOGNIZED_LSN_FIND_NAME // this is a find name response.
  355. NAME_RECOGNIZED_LSN_NO_RESOURCE // listen available, but no resources.
  356. NameQueryCorrelator - Correlator from NAME_QUERY.
  357. Correlator - Correlator expected from next response.
  358. SenderName - Pointer to a NetBIOS name of the sender.
  359. ReceiverName - Pointer to a NetBIOS name of the receiver.
  360. Return Value:
  361. none.
  362. --*/
  363. {
  364. USHORT i;
  365. IF_NBFDBG (NBF_DEBUG_FRAMECON) {
  366. NbfPrint0 ("ConstructNameRecognized: Entered.\n");
  367. }
  368. RawFrame->Command = NBF_CMD_NAME_RECOGNIZED;
  369. HEADER_LENGTH(RawFrame) = sizeof(NBF_HDR_CONNECTIONLESS);
  370. HEADER_SIGNATURE(RawFrame) = NETBIOS_SIGNATURE;
  371. RawFrame->Data1 = 0; // reserved field, MBZ.
  372. RawFrame->Data2Low = LocalSessionNumber;
  373. RawFrame->Data2High = NameType;
  374. TRANSMIT_CORR(RawFrame) = NameQueryCorrelator;
  375. RESPONSE_CORR(RawFrame) = Correlator;
  376. for (i=0; i<NETBIOS_NAME_LENGTH; i++) {
  377. RawFrame->DestinationName [i] = ReceiverName [i];
  378. RawFrame->SourceName [i] = SenderName [i];
  379. }
  380. } /* ConstructNameRecognized */
  381. VOID
  382. ConstructStatusResponse(
  383. IN PNBF_HDR_CONNECTIONLESS RawFrame,// frame buffer to format.
  384. IN UCHAR RequestType, // type of request, defined below.
  385. IN BOOLEAN Truncated, // data is truncated.
  386. IN BOOLEAN DataOverflow, // too much data for user's buffer.
  387. IN USHORT DataLength, // length of data sent.
  388. IN USHORT Correlator, // correlator from STATUS_QUERY.
  389. IN PNAME ReceivingPermanentName, // NetBIOS permanent node name of receiver.
  390. IN PNAME SenderName // NetBIOS name of sender.
  391. )
  392. /*++
  393. Routine Description:
  394. This routine constructs an NBF_CMD_STATUS_RESPONSE connectionless
  395. NetBIOS Frame.
  396. Arguments:
  397. RawFrame - Pointer to an unformatted 44-byte connectionless frame buffer.
  398. RequestType - type of request, one of the below:
  399. 0 - request is 1.x or 2.0.
  400. >0 - number of names, 2.1 or above.
  401. Truncated - TRUE if there are more names.
  402. DataOverflow - TRUE if the total data is larger than the user's buffer.
  403. DataLength - The length of the data in Buffer.
  404. Correlator - Correlator from STATUS_QUERY.
  405. ReceivingPermanentName - Pointer to the NetBIOS permanent node name of the receiver,
  406. as passed in the STATUS_QUERY frame.
  407. SenderName - Pointer to a NetBIOS name of the sender.
  408. Return Value:
  409. none.
  410. --*/
  411. {
  412. SHORT i;
  413. IF_NBFDBG (NBF_DEBUG_FRAMECON) {
  414. NbfPrint0 ("ConstructStatusResponse: Entered.\n");
  415. }
  416. RawFrame->Command = NBF_CMD_STATUS_RESPONSE;
  417. HEADER_LENGTH(RawFrame) = sizeof(NBF_HDR_CONNECTIONLESS);
  418. HEADER_SIGNATURE(RawFrame) = NETBIOS_SIGNATURE;
  419. RawFrame->Data1 = RequestType;
  420. RawFrame->Data2Low = (UCHAR)(DataLength & 0xff);
  421. RawFrame->Data2High = (UCHAR)((DataLength >> 8) +
  422. (Truncated << 7) +
  423. (DataOverflow << 6));
  424. TRANSMIT_CORR(RawFrame) = Correlator;
  425. RESPONSE_CORR(RawFrame) = 0;
  426. for (i=0; i<NETBIOS_NAME_LENGTH; i++) {
  427. RawFrame->DestinationName [i] = ReceivingPermanentName [i];
  428. RawFrame->SourceName [i] = SenderName [i];
  429. }
  430. } /* ConstructStatusResponse */
  431. VOID
  432. ConstructDataAck(
  433. IN PNBF_HDR_CONNECTION RawFrame, // frame buffer to format.
  434. IN USHORT Correlator, // correlator from DATA_ONLY_LAST.
  435. IN UCHAR LocalSessionNumber, // session number of SENDER.
  436. IN UCHAR RemoteSessionNumber // session number of RECEIVER.
  437. )
  438. /*++
  439. Routine Description:
  440. This routine constructs an NBF_CMD_DATA_ACK connection-oriented
  441. NetBIOS Frame.
  442. Arguments:
  443. RawFrame - Pointer to an unformatted 14-byte connection-oriented buffer.
  444. Correlator - Correlator from DATA_ONLY_LAST being acked.
  445. LocalSessionNumber - Session number of SENDER.
  446. RemoteSessionNumber - Session number of RECEIVER.
  447. Return Value:
  448. none.
  449. --*/
  450. {
  451. IF_NBFDBG (NBF_DEBUG_FRAMECON) {
  452. NbfPrint0 ("ConstructDataAck: Entered.\n");
  453. }
  454. RawFrame->Command = NBF_CMD_DATA_ACK;
  455. HEADER_LENGTH(RawFrame) = sizeof(NBF_HDR_CONNECTION);
  456. HEADER_SIGNATURE(RawFrame) = NETBIOS_SIGNATURE;
  457. RawFrame->Data1 = 0;
  458. RawFrame->Data2Low = 0;
  459. RawFrame->Data2High = 0;
  460. TRANSMIT_CORR(RawFrame) = Correlator;
  461. RESPONSE_CORR(RawFrame) = (USHORT)0;
  462. RawFrame->SourceSessionNumber = LocalSessionNumber;
  463. RawFrame->DestinationSessionNumber = RemoteSessionNumber;
  464. } /* ConstructDataAck */
  465. VOID
  466. ConstructDataOnlyLast(
  467. IN PNBF_HDR_CONNECTION RawFrame, // frame buffer to format.
  468. IN BOOLEAN Resynched, // TRUE if we are resynching.
  469. IN USHORT Correlator, // correlator for RECEIVE_CONTINUE.
  470. IN UCHAR LocalSessionNumber, // session number of SENDER.
  471. IN UCHAR RemoteSessionNumber // session number of RECEIVER.
  472. )
  473. /*++
  474. Routine Description:
  475. This routine constructs an NBF_CMD_DATA_ONLY_LAST connection-oriented
  476. NetBIOS Frame.
  477. Arguments:
  478. RawFrame - Pointer to an unformatted 14-byte connection-oriented buffer.
  479. Resynched - TRUE if we are resynching and should set the
  480. correct bit in the frame.
  481. Correlator - Correlator for RECEIVE_CONTINUE, if any.
  482. LocalSessionNumber - Session number of SENDER.
  483. RemoteSessionNumber - Session number of RECEIVER.
  484. Return Value:
  485. none.
  486. --*/
  487. {
  488. IF_NBFDBG (NBF_DEBUG_FRAMECON) {
  489. NbfPrint0 ("ConstructDataOnlyLast: Entered.\n");
  490. }
  491. RawFrame->Command = NBF_CMD_DATA_ONLY_LAST;
  492. HEADER_LENGTH(RawFrame) = sizeof(NBF_HDR_CONNECTION);
  493. HEADER_SIGNATURE(RawFrame) = NETBIOS_SIGNATURE;
  494. RawFrame->Data1 = 0;
  495. ASSERT (TRUE == (UCHAR)1);
  496. RawFrame->Data2Low = Resynched;
  497. RawFrame->Data2High = (UCHAR)0;
  498. TRANSMIT_CORR(RawFrame) = (USHORT)0;
  499. RESPONSE_CORR(RawFrame) = Correlator;
  500. RawFrame->SourceSessionNumber = LocalSessionNumber;
  501. RawFrame->DestinationSessionNumber = RemoteSessionNumber;
  502. } /* ConstructDataOnlyLast */
  503. VOID
  504. ConstructSessionConfirm(
  505. IN PNBF_HDR_CONNECTION RawFrame, // frame buffer to format.
  506. IN UCHAR Options, // bitflag options, defined below.
  507. IN USHORT MaximumUserBufferSize, // max size of user frame on session.
  508. IN USHORT Correlator, // correlator from SESSION_INITIALIZE.
  509. IN UCHAR LocalSessionNumber, // session number of SENDER.
  510. IN UCHAR RemoteSessionNumber // session number of RECEIVER.
  511. )
  512. /*++
  513. Routine Description:
  514. This routine constructs an NBF_CMD_SESSION_CONFIRM connection-oriented
  515. NetBIOS Frame.
  516. Arguments:
  517. RawFrame - Pointer to an unformatted 14-byte connection-oriented buffer.
  518. Options - Bitflag options, any of the following:
  519. SESSION_CONFIRM_OPTIONS_20 // set if NETBIOS 2.0 or above.
  520. SESSION_CONFIRM_NO_ACK // set if NO.ACK protocol supported.
  521. MaximumUserBufferSize - Maximum size of user data per frame on this
  522. session, in bytes. This is limited by the following constant:
  523. SESSION_CONFIRM_MAXIMUM_FRAME_SIZE // defined limit of this field.
  524. Correlator - Correlator from SESSION_INITIALIZE.
  525. LocalSessionNumber - Session number of SENDER.
  526. RemoteSessionNumber - Session number of RECEIVER.
  527. Return Value:
  528. none.
  529. --*/
  530. {
  531. IF_NBFDBG (NBF_DEBUG_FRAMECON) {
  532. NbfPrint0 ("ConstructSessionConfirm: Entered.\n");
  533. }
  534. RawFrame->Command = NBF_CMD_SESSION_CONFIRM;
  535. HEADER_LENGTH(RawFrame) = sizeof(NBF_HDR_CONNECTION);
  536. HEADER_SIGNATURE(RawFrame) = NETBIOS_SIGNATURE;
  537. RawFrame->Data1 = Options;
  538. RawFrame->Data2Low = (UCHAR)(MaximumUserBufferSize & 0xff);
  539. RawFrame->Data2High = (UCHAR)(MaximumUserBufferSize >> 8);
  540. TRANSMIT_CORR(RawFrame) = Correlator;
  541. RESPONSE_CORR(RawFrame) = (USHORT)0;
  542. RawFrame->SourceSessionNumber = LocalSessionNumber;
  543. RawFrame->DestinationSessionNumber = RemoteSessionNumber;
  544. } /* ConstructSessionConfirm */
  545. VOID
  546. ConstructSessionEnd(
  547. IN PNBF_HDR_CONNECTION RawFrame, // frame buffer to format.
  548. IN USHORT Reason, // reason for termination, defined below.
  549. IN UCHAR LocalSessionNumber, // session number of SENDER.
  550. IN UCHAR RemoteSessionNumber // session number of RECEIVER.
  551. )
  552. /*++
  553. Routine Description:
  554. This routine constructs an NBF_CMD_SESSION_END connection-oriented
  555. NetBIOS Frame.
  556. Arguments:
  557. RawFrame - Pointer to an unformatted 14-byte connection-oriented buffer.
  558. Reason - Reason code for termination, any of the following:
  559. SESSION_END_REASON_HANGUP // normal termination via HANGUP.
  560. SESSION_END_REASON_ABEND // abnormal session termination.
  561. LocalSessionNumber - Session number of SENDER.
  562. RemoteSessionNumber - Session number of RECEIVER.
  563. Return Value:
  564. none.
  565. --*/
  566. {
  567. IF_NBFDBG (NBF_DEBUG_FRAMECON) {
  568. NbfPrint0 ("ConstructSessionEnd: Entered.\n");
  569. }
  570. RawFrame->Command = NBF_CMD_SESSION_END;
  571. HEADER_LENGTH(RawFrame) = sizeof(NBF_HDR_CONNECTION);
  572. HEADER_SIGNATURE(RawFrame) = NETBIOS_SIGNATURE;
  573. RawFrame->Data1 = 0;
  574. RawFrame->Data2Low = (UCHAR)(Reason & 0xff);
  575. RawFrame->Data2High = (UCHAR)(Reason >> 8);
  576. TRANSMIT_CORR(RawFrame) = (USHORT)0;
  577. RESPONSE_CORR(RawFrame) = (USHORT)0;
  578. RawFrame->SourceSessionNumber = LocalSessionNumber;
  579. RawFrame->DestinationSessionNumber = RemoteSessionNumber;
  580. } /* ConstructSessionEnd */
  581. VOID
  582. ConstructSessionInitialize(
  583. IN PNBF_HDR_CONNECTION RawFrame, // frame buffer to format.
  584. IN UCHAR Options, // bitflag options, defined below.
  585. IN USHORT MaximumUserBufferSize, // max size of user frame on session.
  586. IN USHORT NameRecognizedCorrelator, // correlator from NAME_RECOGNIZED.
  587. IN USHORT Correlator, // correlator for SESSION_CONFIRM.
  588. IN UCHAR LocalSessionNumber, // session number of SENDER.
  589. IN UCHAR RemoteSessionNumber // session number of RECEIVER.
  590. )
  591. /*++
  592. Routine Description:
  593. This routine constructs an NBF_CMD_SESSION_INITIALIZE connection-oriented
  594. NetBIOS Frame.
  595. Arguments:
  596. RawFrame - Pointer to an unformatted 14-byte connection-oriented buffer.
  597. Options - Bitflag options, any of the following:
  598. SESSION_INITIALIZE_OPTIONS_20 // set if NETBIOS 2.0 or above.
  599. SESSION_INITIALIZE_NO_ACK // set if NO.ACK protocol supported.
  600. MaximumUserBufferSize - Maximum size of user data per frame on this
  601. session, in bytes. This is limited by the following constant:
  602. SESSION_INITIALIZE_MAXIMUM_FRAME_SIZE // defined limit of this field.
  603. NameRecognizedCorrelator - Correlator from NAME_RECOGNIZED.
  604. Correlator - Correlator for SESSION_CONFIRM.
  605. LocalSessionNumber - Session number of SENDER.
  606. RemoteSessionNumber - Session number of RECEIVER.
  607. Return Value:
  608. none.
  609. --*/
  610. {
  611. IF_NBFDBG (NBF_DEBUG_FRAMECON) {
  612. NbfPrint0 ("ConstructSessionInitialize: Entered.\n");
  613. }
  614. RawFrame->Command = NBF_CMD_SESSION_INITIALIZE;
  615. HEADER_LENGTH(RawFrame) = sizeof(NBF_HDR_CONNECTION);
  616. HEADER_SIGNATURE(RawFrame) = NETBIOS_SIGNATURE;
  617. RawFrame->Data1 = Options;
  618. RawFrame->Data2Low = (UCHAR)(MaximumUserBufferSize & 0xff);
  619. RawFrame->Data2High = (UCHAR)(MaximumUserBufferSize >> 8);
  620. TRANSMIT_CORR(RawFrame) = NameRecognizedCorrelator;
  621. RESPONSE_CORR(RawFrame) = Correlator;
  622. RawFrame->SourceSessionNumber = LocalSessionNumber;
  623. RawFrame->DestinationSessionNumber = RemoteSessionNumber;
  624. } /* ConstructSessionInitialize */
  625. VOID
  626. ConstructNoReceive(
  627. IN PNBF_HDR_CONNECTION RawFrame, // frame buffer to format.
  628. IN USHORT Options, // option bitflags, defined below.
  629. IN USHORT BytesAccepted, // number of bytes accepted.
  630. IN UCHAR LocalSessionNumber, // session number of SENDER.
  631. IN UCHAR RemoteSessionNumber // session number of RECEIVER.
  632. )
  633. /*++
  634. Routine Description:
  635. This routine constructs an NBF_CMD_NO_RECEIVE connection-oriented
  636. NetBIOS Frame.
  637. Arguments:
  638. RawFrame - Pointer to an unformatted 14-byte connection-oriented buffer.
  639. Options - Bitflag options, any of the following:
  640. NO_RECEIVE_OPTIONS_PARTIAL_NO_ACK // NO.ACK data partially received.
  641. BytesAccepted - Number of bytes accepted, current outstanding message.
  642. LocalSessionNumber - Session number of SENDER.
  643. RemoteSessionNumber - Session number of RECEIVER.
  644. Return Value:
  645. none.
  646. --*/
  647. {
  648. // Options; // prevent compiler warnings
  649. IF_NBFDBG (NBF_DEBUG_FRAMECON) {
  650. NbfPrint0 ("ConstructNoReceive: Entered.\n");
  651. }
  652. RawFrame->Command = NBF_CMD_NO_RECEIVE;
  653. HEADER_LENGTH(RawFrame) = sizeof(NBF_HDR_CONNECTION);
  654. HEADER_SIGNATURE(RawFrame) = NETBIOS_SIGNATURE;
  655. if (Options == NO_RECEIVE_PARTIAL_NO_ACK) {
  656. RawFrame->Data1 = NO_RECEIVE_PARTIAL_NO_ACK;
  657. } else {
  658. RawFrame->Data1 = 0;
  659. }
  660. RawFrame->Data2Low = (UCHAR)(BytesAccepted & 0xff);
  661. RawFrame->Data2High = (UCHAR)(BytesAccepted >> 8);
  662. TRANSMIT_CORR(RawFrame) = (USHORT)0;
  663. RESPONSE_CORR(RawFrame) = (USHORT)0;
  664. RawFrame->SourceSessionNumber = LocalSessionNumber;
  665. RawFrame->DestinationSessionNumber = RemoteSessionNumber;
  666. } /* ConstructNoReceive */
  667. VOID
  668. ConstructReceiveOutstanding(
  669. IN PNBF_HDR_CONNECTION RawFrame, // frame buffer to format.
  670. IN USHORT BytesAccepted, // number of bytes accepted.
  671. IN UCHAR LocalSessionNumber, // session number of SENDER.
  672. IN UCHAR RemoteSessionNumber // session number of RECEIVER.
  673. )
  674. /*++
  675. Routine Description:
  676. This routine constructs an NBF_CMD_RECEIVE_OUTSTANDING connection-oriented
  677. NetBIOS Frame.
  678. Arguments:
  679. RawFrame - Pointer to an unformatted 14-byte connection-oriented buffer.
  680. BytesAccepted - Number of bytes accepted, current outstanding message.
  681. LocalSessionNumber - Session number of SENDER.
  682. RemoteSessionNumber - Session number of RECEIVER.
  683. Return Value:
  684. none.
  685. --*/
  686. {
  687. IF_NBFDBG (NBF_DEBUG_FRAMECON) {
  688. NbfPrint0 ("ConstructReceiveOutstanding: Entered.\n");
  689. }
  690. RawFrame->Command = NBF_CMD_RECEIVE_OUTSTANDING;
  691. HEADER_LENGTH(RawFrame) = sizeof(NBF_HDR_CONNECTION);
  692. HEADER_SIGNATURE(RawFrame) = NETBIOS_SIGNATURE;
  693. RawFrame->Data1 = 0;
  694. RawFrame->Data2Low = (UCHAR)(BytesAccepted & 0xff);
  695. RawFrame->Data2High = (UCHAR)(BytesAccepted >> 8);
  696. TRANSMIT_CORR(RawFrame) = (USHORT)0;
  697. RESPONSE_CORR(RawFrame) = (USHORT)0;
  698. RawFrame->SourceSessionNumber = LocalSessionNumber;
  699. RawFrame->DestinationSessionNumber = RemoteSessionNumber;
  700. } /* ConstructReceiveOutstanding */
  701. VOID
  702. ConstructReceiveContinue(
  703. IN PNBF_HDR_CONNECTION RawFrame, // frame buffer to format.
  704. IN USHORT Correlator, // correlator from DATA_FIRST_MIDDLE
  705. IN UCHAR LocalSessionNumber, // session number of SENDER.
  706. IN UCHAR RemoteSessionNumber // session number of RECEIVER.
  707. )
  708. /*++
  709. Routine Description:
  710. This routine constructs an NBF_CMD_RECEIVE_CONTINUE connection-oriented
  711. NetBIOS Frame.
  712. Arguments:
  713. RawFrame - Pointer to an unformatted 14-byte connection-oriented buffer.
  714. Correlator - The correlator from the DATA_FIRST_MIDDLE frame.
  715. LocalSessionNumber - Session number of SENDER.
  716. RemoteSessionNumber - Session number of RECEIVER.
  717. Return Value:
  718. none.
  719. --*/
  720. {
  721. IF_NBFDBG (NBF_DEBUG_FRAMECON) {
  722. NbfPrint0 ("ConstructReceiveContinue: Entered.\n");
  723. }
  724. RawFrame->Command = NBF_CMD_RECEIVE_CONTINUE;
  725. HEADER_LENGTH(RawFrame) = sizeof(NBF_HDR_CONNECTION);
  726. HEADER_SIGNATURE(RawFrame) = NETBIOS_SIGNATURE;
  727. RawFrame->Data1 = 0;
  728. RawFrame->Data2Low = 0;
  729. RawFrame->Data2High = 0;
  730. TRANSMIT_CORR(RawFrame) = Correlator;
  731. RESPONSE_CORR(RawFrame) = (USHORT)0;
  732. RawFrame->SourceSessionNumber = LocalSessionNumber;
  733. RawFrame->DestinationSessionNumber = RemoteSessionNumber;
  734. } /* ConstructReceiveContinue */
  735. #if 0
  736. VOID
  737. ConstructSessionAlive(
  738. IN PNBF_HDR_CONNECTION RawFrame // frame buffer to format.
  739. )
  740. /*++
  741. Routine Description:
  742. This routine constructs an NBF_CMD_SESSION_ALIVE connection-oriented
  743. NetBIOS Frame.
  744. Arguments:
  745. RawFrame - Pointer to an unformatted 14-byte connection-oriented buffer.
  746. Return Value:
  747. none.
  748. --*/
  749. {
  750. IF_NBFDBG (NBF_DEBUG_FRAMECON) {
  751. NbfPrint0 ("ConstructSessionAlive: Entered.\n");
  752. }
  753. RawFrame->Command = NBF_CMD_SESSION_ALIVE;
  754. HEADER_LENGTH(RawFrame) = sizeof(NBF_HDR_CONNECTION);
  755. HEADER_SIGNATURE(RawFrame) = NETBIOS_SIGNATURE;
  756. RawFrame->Data1 = 0;
  757. RawFrame->Data2Low = 0;
  758. RawFrame->Data2High = 0;
  759. TRANSMIT_CORR(RawFrame) = (USHORT)0;
  760. RESPONSE_CORR(RawFrame) = (USHORT)0;
  761. RawFrame->SourceSessionNumber = 0;
  762. RawFrame->DestinationSessionNumber = 0;
  763. } /* ConstructSessionAlive */
  764. #endif