Windows NT 4.0 source code leak
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.

863 lines
26 KiB

4 years ago
  1. /////////////////////////////////////////////////////////////////////////
  2. //
  3. // Filename: dgnb.c
  4. //
  5. // Description: This file contains common routines for NetBios I/O
  6. // routines for use with IPC raw network performance
  7. // tests.
  8. // This module is written using win32 API calls.
  9. //
  10. // Authors: Scott Holden (Translator from NT API to win32 API)
  11. // Mahesh Keni (Mahesh wrote this application using mostly
  12. // NT native API calls)
  13. //
  14. /////////////////////////////////////////////////////////////////////////
  15. #include "rawcom.h"
  16. #include "dgnb.h"
  17. #include "nb.h"
  18. /************************************************************************/
  19. /*++
  20. This routine is responsible for adding a given name on a net.
  21. --*/
  22. UCHAR
  23. DGNetBIOS_AddName(
  24. IN PCHAR LocalName,
  25. IN UCHAR LanaNumber,
  26. OUT PUCHAR NameNumber)
  27. {
  28. NCB AddNameNCB;
  29. UCHAR RetCode;
  30. RetCode =0;
  31. ClearNCB(&AddNameNCB); // does cleanup everything
  32. AddNameNCB.ncb_command = NCBADDNAME;
  33. RtlMoveMemory(AddNameNCB.ncb_name,LocalName,NCBNAMSZ);
  34. AddNameNCB.ncb_lana_num = LanaNumber;
  35. RetCode = Netbios(&AddNameNCB); // submit to NetBIOS
  36. if (AddNameNCB.ncb_retcode != NRC_GOODRET) {
  37. printf("Addname failed %x\n", AddNameNCB.ncb_retcode);
  38. return RetCode;
  39. }
  40. *NameNumber = AddNameNCB.ncb_num;
  41. return RetCode;
  42. }
  43. /************************************************************************/
  44. /*++
  45. This routine is responsible for deleting a given name on a net.
  46. --*/
  47. UCHAR
  48. DGNetBIOS_DelName(
  49. IN PCHAR LocalName,
  50. IN UCHAR LanaNumber)
  51. {
  52. NCB DelNameNCB;
  53. UCHAR RetCode;
  54. RetCode =0;
  55. ClearNCB(&DelNameNCB); // does cleanup everything
  56. DelNameNCB.ncb_command = NCBDELNAME;
  57. RtlMoveMemory(DelNameNCB.ncb_name,LocalName,NCBNAMSZ);
  58. DelNameNCB.ncb_lana_num = LanaNumber;
  59. RetCode = Netbios(&DelNameNCB); // submit to NetBIOS
  60. if (DelNameNCB.ncb_retcode != NRC_GOODRET) {
  61. printf("Delname failed %x\n", DelNameNCB.ncb_retcode);
  62. return RetCode;
  63. }
  64. return RetCode;
  65. }
  66. /************************************************************************/
  67. UCHAR
  68. DGNetBIOS_Reset(
  69. IN UCHAR LanaNumber)
  70. {
  71. NCB ResetNCB;
  72. UCHAR RetCode;
  73. RetCode =0;
  74. ClearNCB(&ResetNCB); // does cleanup everything
  75. ResetNCB.ncb_command = NCBRESET;
  76. ResetNCB.ncb_lana_num = LanaNumber;
  77. ResetNCB.ncb_lsn = 0;
  78. ResetNCB.ncb_callname[0] = 0; //16 sessions
  79. ResetNCB.ncb_callname[1] = 0; //16 commands
  80. ResetNCB.ncb_callname[2] = 0; //8 names
  81. RetCode = Netbios(&ResetNCB); // submit to NetBIOS
  82. if (ResetNCB.ncb_retcode != NRC_GOODRET) {
  83. printf("Reset failed %x\n", ResetNCB.ncb_retcode);
  84. return RetCode;
  85. }
  86. return RetCode;
  87. }
  88. /************************************************************************/
  89. UCHAR
  90. DGNetBIOS_Receive(
  91. IN USHORT TIndex,
  92. IN PUCHAR RecvBuffer,
  93. IN USHORT RecvLen)
  94. {
  95. NCB ReceiveNCB;
  96. NTSTATUS rstatus;
  97. UCHAR RetCode;
  98. //DbgPrint("Entering Recv..");
  99. RetCode =0;
  100. ClearNCB(&ReceiveNCB); // does cleanup everything
  101. ReceiveNCB.ncb_command = NCBDGRECV | ASYNCH;
  102. ReceiveNCB.ncb_lana_num = (UCHAR) Clients[TIndex].c_NetB.c_LanaNumber;
  103. ReceiveNCB.ncb_num = Clients[TIndex].c_NetB.c_NameNum;
  104. ReceiveNCB.ncb_lsn = Clients[TIndex].c_NetB.c_LSN;
  105. ReceiveNCB.ncb_buffer = RecvBuffer;
  106. ReceiveNCB.ncb_length = RecvLen;
  107. ReceiveNCB.ncb_event = Clients[TIndex].c_NetB.c_RecvEvent;
  108. //DbgPrint("Posting Recv..");
  109. RetCode = Netbios(&ReceiveNCB); // submit to NetBIOS
  110. if (ReceiveNCB.ncb_cmd_cplt == NRC_PENDING){
  111. rstatus = WaitForSingleObjectEx(ReceiveNCB.ncb_event,
  112. INFINITE,
  113. TRUE);
  114. }
  115. if (ReceiveNCB.ncb_cmd_cplt != NRC_GOODRET) {
  116. //DbgPrint("NBSRV:NB:Receive failed %x\n", ReceiveNCB.ncb_cmd_cplt);
  117. }
  118. //DbgPrint("Exit Recv\n");
  119. return ReceiveNCB.ncb_cmd_cplt;
  120. }
  121. /************************************************************************/
  122. UCHAR
  123. DGNetBIOS_Send(
  124. IN USHORT TIndex,
  125. IN PUCHAR SendBuffer,
  126. IN USHORT SendLen)
  127. {
  128. NCB SendNCB;
  129. NTSTATUS rstatus;
  130. UCHAR RetCode;
  131. //DbgPrint("Enter Send\n");
  132. RetCode =0;
  133. ClearNCB(&SendNCB); // does cleanup everything
  134. SendNCB.ncb_command = NCBDGSEND | ASYNCH;
  135. SendNCB.ncb_lana_num = (UCHAR) Clients[TIndex].c_NetB.c_LanaNumber;
  136. SendNCB.ncb_num = Clients[TIndex].c_NetB.c_NameNum;
  137. SendNCB.ncb_lsn = Clients[TIndex].c_NetB.c_LSN;
  138. SendNCB.ncb_buffer = SendBuffer;
  139. SendNCB.ncb_length = SendLen;
  140. SendNCB.ncb_event = Clients[TIndex].c_NetB.c_SendEvent;
  141. RtlMoveMemory(SendNCB.ncb_callname,RemoteName,NCBNAMSZ);
  142. RetCode = Netbios(&SendNCB); // submit to NetBIOS
  143. if (SendNCB.ncb_cmd_cplt == NRC_PENDING){
  144. rstatus = WaitForSingleObjectEx(SendNCB.ncb_event,
  145. INFINITE,
  146. TRUE);
  147. }
  148. if (SendNCB.ncb_cmd_cplt != NRC_GOODRET) {
  149. //DbgPrint("NBSRV:NBS:Send failed %x RetCode:%x\n",SendNCB.ncb_cmd_cplt,RetCode);
  150. }
  151. //DbgPrint("Exit Send\n");
  152. return SendNCB.ncb_cmd_cplt;
  153. }
  154. /************************************************************************/
  155. NTSTATUS
  156. DGNB_Initialize(
  157. IN USHORT NClients,
  158. IN PCHAR IServerName,
  159. IN USHORT SrvCli)
  160. {
  161. NTSTATUS Istatus;
  162. UCHAR RetCode;
  163. USHORT LanaNum;
  164. CHAR Tmp[10]; // for holding numbers
  165. //
  166. // First Reset all the adapters
  167. // Add the server name if provided otherwise use the default name
  168. // To take care of TCP/IP and other Lana Bases
  169. LanaNum = LanaBase;
  170. // initialize all the named
  171. MyDbgPrint("Initialize both Local/Remote Names\n");
  172. if (SrvCli) { // for server copy the given name as a local
  173. RtlMoveMemory(RemoteName, ALL_CLIENTS, NCBNAMSZ);
  174. if (IServerName) {
  175. RtlMoveMemory(LocalName, IServerName, NCBNAMSZ);
  176. }
  177. else {
  178. RtlMoveMemory(LocalName, PERF_NETBIOS, NCBNAMSZ);
  179. }
  180. }
  181. else { // for a client copy the name as a remote name
  182. if (IServerName) {
  183. RtlMoveMemory(RemoteName, IServerName, NCBNAMSZ);
  184. }
  185. else {
  186. RtlMoveMemory(RemoteName, PERF_NETBIOS, NCBNAMSZ);
  187. }
  188. // copy local name for client
  189. // use Rtl routines
  190. strcpy(LocalName,CLINAME);
  191. strcat(LocalName,_itoa(MachineNumber,Tmp,10));
  192. }
  193. while (LanaNum < LanaCount*2) { // for Jet and TCP/IP
  194. RetCode = NetBIOS_Reset((UCHAR) LanaNum);
  195. if (RetCode) {
  196. MyDbgPrint("Error in Reset\n");
  197. return(Istatus = -1L);
  198. }
  199. // we could assign Lana Numbers to clients and do AddName here too
  200. RetCode = NetBIOS_AddName(
  201. LocalName,
  202. (UCHAR) LanaNum,
  203. &NameNumber);
  204. if (RetCode) {
  205. //MyDbgPrint("NB: Error in Add Name retc: %C \n", RetCode);
  206. return (STATUS_UNSUCCESSFUL);
  207. }
  208. // Add the Name number to Client's structure
  209. LanaNum = LanaNum+2;
  210. }
  211. //DbgPrint("NB: Reset Done\n");
  212. return (STATUS_SUCCESS);
  213. }
  214. /************************************************************************/
  215. /*++
  216. This routine is responsible adding a NetBIOS name for the given
  217. thread.
  218. --*/
  219. NTSTATUS
  220. DGNB_PerClientInit(
  221. IN USHORT CIndex, // client index
  222. IN USHORT SrvCli )
  223. {
  224. //NTSTATUS pstatus;
  225. //UCHAR RetCode;
  226. //CHAR Tmp[10]; // for holding numbers
  227. // initialize proper client data structures
  228. Clients[CIndex].c_client_num = CIndex;
  229. // distribute clients evenly on all net cards
  230. Clients[CIndex].c_NetB.c_LanaNumber = ((CIndex % LanaCount)*2)+LanaBase;
  231. // Add the Name number to Client's structure
  232. Clients[CIndex].c_NetB.c_NameNum = NameNumber;
  233. // Set all events to Null
  234. Clients[CIndex].c_NetB.c_SendEvent = NULL;
  235. Clients[CIndex].c_NetB.c_RecvEvent = NULL;
  236. Clients[CIndex].c_NetB.c_RecvEventG = NULL;
  237. // create events to associate with an NCB for this thread
  238. Clients[CIndex].c_NetB.c_SendEvent = CreateEvent(
  239. NULL,
  240. TRUE, // manual reset event
  241. FALSE, // initial state of the event
  242. NULL); // no event name
  243. Clients[CIndex].c_NetB.c_RecvEvent = CreateEvent(
  244. NULL,
  245. TRUE, // manual reset event
  246. FALSE, // initial state of the event
  247. NULL); // no event name
  248. Clients[CIndex].c_NetB.c_RecvEventG = CreateEvent(
  249. NULL,
  250. TRUE, // manual reset event
  251. FALSE, // initial state of the event
  252. NULL); // no event name
  253. /*
  254. pstatus = NtCreateEvent(
  255. &(Clients[CIndex].c_NetB.c_SendEvent),
  256. EVENT_ALL_ACCESS,
  257. NULL,
  258. NotificationEvent,
  259. (BOOLEAN)FALSE);
  260. if (!NT_SUCCESS(pstatus)) {
  261. MyDbgPrint ("Err: Create an Send Event:%d err=%lx\n",CIndex,pstatus);
  262. return(pstatus);
  263. }
  264. pstatus = NtCreateEvent(
  265. &(Clients[CIndex].c_NetB.c_RecvEvent),
  266. EVENT_ALL_ACCESS,
  267. NULL,
  268. NotificationEvent,
  269. (BOOLEAN)FALSE);
  270. if (!NT_SUCCESS(pstatus)) {
  271. MyDbgPrint ("Err: Create an Recv Event:%d err=%lx\n",CIndex,pstatus);
  272. return(pstatus);
  273. }
  274. pstatus = NtCreateEvent(
  275. &(Clients[CIndex].c_NetB.c_RecvEventG),
  276. EVENT_ALL_ACCESS,
  277. NULL,
  278. NotificationEvent,
  279. (BOOLEAN)FALSE);
  280. if (!NT_SUCCESS(pstatus)) {
  281. MyDbgPrint ("Err: Create GRecv Event:%d err=%lx\n",CIndex,pstatus);
  282. return(pstatus);
  283. }
  284. */
  285. return (STATUS_SUCCESS);
  286. }
  287. /************************************************************************/
  288. /*++
  289. This routine is responsible for issueing Listen and waiting till a
  290. client is connected. When this routine returns successfully we can
  291. assume that a connection is established.
  292. --*/
  293. NTSTATUS
  294. DGNB_Wait_For_Client(
  295. IN USHORT CIndex) // client index
  296. {
  297. //UCHAR RetCode;
  298. // post a listen
  299. return (STATUS_SUCCESS);
  300. }
  301. /************************************************************************/
  302. /*++
  303. This routine is responsible for issueing Disconnect to close the
  304. connection with a client.
  305. --*/
  306. NTSTATUS
  307. DGNB_Disconnect_Client(
  308. IN USHORT CIndex) // client index
  309. {
  310. //UCHAR RetCode;
  311. // post a Disconnect
  312. return (STATUS_SUCCESS);
  313. }
  314. /************************************************************************/
  315. /*++
  316. This routine is responsible for establishing a connection to the
  317. server side. When this routine returns successfully we can assume that
  318. a connection is established.
  319. --*/
  320. NTSTATUS
  321. DGNB_Connect_To_Server(
  322. IN USHORT CIndex) // client index
  323. {
  324. //UCHAR RetCode;
  325. return (STATUS_SUCCESS);
  326. }
  327. /************************************************************************/
  328. /*++
  329. This routine allocates memory required for all the buffers for a client.
  330. --*/
  331. NTSTATUS
  332. DGNB_Allocate_Memory(
  333. IN USHORT CIndex) // client index and namedpipe instance number
  334. {
  335. NTSTATUS astatus = 0;
  336. ULONG AllocSize;
  337. // AllocSize = Clients[CIndex].c_reqbuf.SendSize;
  338. AllocSize = MAXBUFSIZE;
  339. // Allocate memory for Send Buffer
  340. /*
  341. astatus = NtAllocateVirtualMemory(
  342. NtCurrentProcess(),
  343. (PVOID *) (&(Clients[CIndex].c_pSendBuf)),
  344. 0L,
  345. &(AllocSize),
  346. MEM_COMMIT,
  347. PAGE_READWRITE);
  348. if (!NT_SUCCESS(astatus)) {
  349. DbgPrint("Nmp SendBuf: Allocate memory failed: err: %lx \n", astatus);
  350. return astatus;
  351. }
  352. */
  353. (LPVOID) Clients[CIndex].c_pSendBuf = VirtualAlloc(
  354. (LPVOID) Clients[CIndex].c_pSendBuf,
  355. (DWORD)AllocSize,
  356. (DWORD)MEM_COMMIT,
  357. (DWORD)PAGE_READWRITE);
  358. sprintf(Clients[CIndex].c_pSendBuf,"Client%d Send Data", CIndex+1);
  359. // AllocSize = Clients[CIndex].c_reqbuf.RecvSize;
  360. AllocSize = MAXBUFSIZE;
  361. // Allocate memory for Receive Buffer
  362. /*
  363. astatus = NtAllocateVirtualMemory(
  364. NtCurrentProcess(),
  365. (PVOID *) (&(Clients[CIndex].c_pRecvBuf)),
  366. 0L,
  367. &(AllocSize),
  368. MEM_COMMIT,
  369. PAGE_READWRITE);
  370. if (!NT_SUCCESS(astatus)) {
  371. DbgPrint("Nmp RecvBuf :Allocate memory failed: err: %lx \n", astatus);
  372. return astatus;
  373. }
  374. */
  375. (LPVOID) Clients[CIndex].c_pRecvBuf = VirtualAlloc(
  376. (LPVOID) Clients[CIndex].c_pRecvBuf,
  377. (DWORD)AllocSize,
  378. (DWORD)MEM_COMMIT,
  379. (DWORD)PAGE_READWRITE);
  380. sprintf(Clients[CIndex].c_pRecvBuf,"Client%d Recv Data", CIndex+1);
  381. // AllocSize = Clients[CIndex].c_reqbuf.RecvSize;
  382. AllocSize = MAXBUFSIZE;
  383. // Allocate memory for Global Receive Buffer
  384. /*
  385. astatus = NtAllocateVirtualMemory(
  386. NtCurrentProcess(),
  387. (PVOID *) (&(Clients[CIndex].c_NetB.c_pRecvBufG)),
  388. 0L,
  389. &(AllocSize),
  390. MEM_COMMIT,
  391. PAGE_READWRITE);
  392. if (!NT_SUCCESS(astatus)) {
  393. DbgPrint("Nmp RecvBufG :Allocate memory failed: err: %lx \n", astatus);
  394. return astatus;
  395. }
  396. */
  397. (LPVOID) Clients[CIndex].c_NetB.c_pRecvBufG = VirtualAlloc(
  398. (LPVOID) Clients[CIndex].c_NetB.c_pRecvBufG,
  399. AllocSize,
  400. MEM_COMMIT,
  401. PAGE_READWRITE);
  402. sprintf(Clients[CIndex].c_NetB.c_pRecvBufG,"Client%d RecvG Data", CIndex+1);
  403. return astatus;
  404. }
  405. /************************************************************************/
  406. /*++
  407. This routine deallocates memory for a client.
  408. --*/
  409. NTSTATUS
  410. DGNB_Deallocate_Memory(
  411. IN USHORT CIndex) // client index and namedpipe instance number
  412. {
  413. NTSTATUS dstatus;
  414. ULONG DeallocSize;
  415. // Deallocate memory for Send Buffer
  416. // DeallocSize = Clients[CIndex].c_reqbuf.SendSize;
  417. DeallocSize = MAXBUFSIZE;
  418. /*
  419. dstatus = NtFreeVirtualMemory(
  420. NtCurrentProcess(),
  421. (PVOID *) (&(Clients[CIndex].c_pSendBuf)),
  422. &(DeallocSize),
  423. MEM_DECOMMIT);
  424. */
  425. dstatus = VirtualFree(
  426. (LPVOID) Clients[CIndex].c_pSendBuf,
  427. DeallocSize,
  428. MEM_DECOMMIT);
  429. if (!NT_SUCCESS(dstatus)) {
  430. //DbgPrint("Nmp SendBuf: Deallocate memory failed: err: %lx \n", dstatus);
  431. return dstatus;
  432. }
  433. // DeallocSize = Clients[CIndex].c_reqbuf.RecvSize;
  434. DeallocSize = MAXBUFSIZE;
  435. // Deallocate memory for Receive Buffer
  436. /*
  437. dstatus = NtFreeVirtualMemory(
  438. NtCurrentProcess(),
  439. (PVOID *) (&(Clients[CIndex].c_pRecvBuf)),
  440. &(DeallocSize),
  441. MEM_DECOMMIT);
  442. */
  443. dstatus = VirtualFree(
  444. (LPVOID) Clients[CIndex].c_pRecvBuf,
  445. DeallocSize,
  446. MEM_DECOMMIT);
  447. if (!NT_SUCCESS(dstatus)) {
  448. //DbgPrint("Nmp RecvBuf :Deallocate memory failed: err: %lx \n", dstatus);
  449. return dstatus;
  450. }
  451. // DeallocSize = Clients[CIndex].c_reqbuf.RecvSize;
  452. DeallocSize = MAXBUFSIZE;
  453. // Deallocate memory for Global Receive Buffer
  454. /*
  455. dstatus = NtFreeVirtualMemory(
  456. NtCurrentProcess(),
  457. (PVOID *) (&(Clients[CIndex].c_NetB.c_pRecvBufG)),
  458. &(DeallocSize),
  459. MEM_DECOMMIT);
  460. */
  461. dstatus = VirtualFree(
  462. (LPVOID) Clients[CIndex].c_NetB.c_pRecvBufG,
  463. DeallocSize,
  464. MEM_DECOMMIT);
  465. if (!NT_SUCCESS(dstatus)) {
  466. //DbgPrint("Nmp RecvBuf :Deallocate memory failed: err: %lx \n", dstatus);
  467. return dstatus;
  468. }
  469. return dstatus;
  470. }
  471. /************************************************************************/
  472. /*++
  473. This routine is responsible for disconnecting a session.
  474. --*/
  475. NTSTATUS
  476. DGNB_Disconnect_From_Server(
  477. IN USHORT CIndex) // client index and namedpipe instance number
  478. {
  479. //UCHAR RetCode;
  480. return (STATUS_SUCCESS);
  481. }
  482. /************************************************************************/
  483. /*++
  484. This routine does handshake with it's peer. For Server this means
  485. receiving request message from a client. For Client it means just the
  486. opposite.
  487. --*/
  488. NTSTATUS
  489. DGNB_DoHandshake(
  490. IN USHORT CIndex, // client index and namedpipe instance number
  491. IN USHORT SrvCli) // if it's a server or client
  492. {
  493. //NTSTATUS dstatus;
  494. //ULONG RWLen;
  495. ULONG RWreqLen;
  496. UCHAR RetCode;
  497. RWreqLen = sizeof(struct reqbuf);
  498. // for server do receive for a request buffer
  499. if (SrvCli) {
  500. RetCode = DGNetBIOS_Receive(
  501. CIndex,
  502. (PVOID) &(Clients[CIndex].c_reqbuf),
  503. (USHORT) RWreqLen);
  504. if (RetCode) {
  505. //MyDbgPrint("NB: Err in Receive HandShake retc: %C \n", RetCode);
  506. return (STATUS_UNSUCCESSFUL);
  507. }
  508. }
  509. else { // for Client do send of reqbuf size
  510. RetCode = DGNetBIOS_Send(
  511. CIndex,
  512. (PVOID) &(Clients[CIndex].c_reqbuf),
  513. (USHORT) RWreqLen);
  514. if (RetCode) {
  515. //MyDbgPrint("NB: Err in Send HandShake retc: %C \n", RetCode);
  516. return (STATUS_UNSUCCESSFUL);
  517. }
  518. }
  519. return (STATUS_SUCCESS);
  520. }
  521. /************************************************************************/
  522. /*++
  523. This routine Reads data from IPC. For server it means reading data
  524. NumSends times in SendBuffers and for a client NumRecvs times into
  525. RecvBuffer.
  526. --*/
  527. NTSTATUS
  528. DGNB_ReadFromIPC(
  529. IN USHORT CIndex, // client index and namedpipe instance number
  530. IN OUT PULONG pReadDone,
  531. IN USHORT SrvCli ) // if it's a server or client
  532. {
  533. ULONG NumReads;
  534. ULONG ReadLen;
  535. PCHAR ReadBuf;
  536. UCHAR RetCode;
  537. if (SrvCli) { // set proper iterations and buffer for Server
  538. NumReads = Clients[CIndex].c_reqbuf.NumSends;
  539. ReadBuf = Clients[CIndex].c_pSendBuf;
  540. ReadLen = Clients[CIndex].c_reqbuf.SendSize;
  541. }
  542. else { // for client do proper settings
  543. NumReads = Clients[CIndex].c_reqbuf.NumRecvs;
  544. ReadBuf = Clients[CIndex].c_pRecvBuf;
  545. ReadLen = Clients[CIndex].c_reqbuf.RecvSize;
  546. }
  547. while (NumReads--) {
  548. RetCode = DGNetBIOS_Receive(
  549. CIndex,
  550. (PVOID) ReadBuf,
  551. (USHORT) ReadLen);
  552. if (RetCode) {
  553. //MyDbgPrint("NB: Err in Recv ReadFromIPC retc: %C \n", RetCode);
  554. return (STATUS_UNSUCCESSFUL);
  555. }
  556. // Set Read data length; I should check this from NCB
  557. *pReadDone = ReadLen;
  558. }
  559. return (STATUS_SUCCESS);
  560. }
  561. /************************************************************************/
  562. /*++
  563. This routine Writes data to IPC. For server it means writing data
  564. NumRecvs times in RecvBuffers and for a client NumSends times into
  565. SendBuffer.
  566. --*/
  567. NTSTATUS
  568. DGNB_WriteToIPC(
  569. IN USHORT CIndex, // client index and namedpipe instance number
  570. IN OUT PULONG pWriteDone,
  571. IN USHORT SrvCli) // if it's a server or client
  572. {
  573. ULONG NumWrites;
  574. ULONG WriteLen;
  575. PCHAR WriteBuf;
  576. UCHAR RetCode;
  577. if (SrvCli) { // set proper iterations and buffer for Server
  578. NumWrites = Clients[CIndex].c_reqbuf.NumRecvs;
  579. WriteBuf = Clients[CIndex].c_pRecvBuf;
  580. WriteLen = Clients[CIndex].c_reqbuf.RecvSize;
  581. }
  582. else { // for client do proper settings
  583. NumWrites = Clients[CIndex].c_reqbuf.NumSends;
  584. WriteBuf = Clients[CIndex].c_pSendBuf;
  585. WriteLen = Clients[CIndex].c_reqbuf.SendSize;
  586. }
  587. while (NumWrites--) {
  588. RetCode = DGNetBIOS_Send(
  589. CIndex,
  590. (PVOID) WriteBuf,
  591. (USHORT) WriteLen);
  592. if (RetCode) {
  593. //MyDbgPrint("NB: Err in Send WritetoIPC retc: %C \n", RetCode);
  594. return (STATUS_UNSUCCESSFUL);
  595. }
  596. // Set written data length; I should check this from NCB
  597. *pWriteDone = WriteLen;
  598. }
  599. return (STATUS_SUCCESS);
  600. }
  601. /************************************************************************/
  602. /*++
  603. This routine does Transact I/O to IPC.
  604. --*/
  605. NTSTATUS
  606. DGNB_XactIO(
  607. IN USHORT CIndex, // client index and namedpipe instance number
  608. IN OUT PULONG pReadDone,
  609. IN OUT PULONG pWriteDone,
  610. IN USHORT SrvCli, // if it's a server or client
  611. IN BOOLEAN FirstIter)
  612. {
  613. ULONG NumReads;
  614. ULONG ReadLen;
  615. PCHAR ReadBuf;
  616. ULONG WriteLen;
  617. PCHAR WriteBuf;
  618. UCHAR RetCode;
  619. NumReads = Clients[CIndex].c_reqbuf.NumRecvs;
  620. if (SrvCli) { // set proper iterations and buffer for Server
  621. ReadBuf = Clients[CIndex].c_pSendBuf;
  622. ReadLen = Clients[CIndex].c_reqbuf.SendSize;
  623. WriteBuf = Clients[CIndex].c_pRecvBuf;
  624. WriteLen = Clients[CIndex].c_reqbuf.RecvSize;
  625. }
  626. else { // for client do proper settings
  627. ReadBuf = Clients[CIndex].c_pRecvBuf;
  628. ReadLen = Clients[CIndex].c_reqbuf.RecvSize;
  629. WriteBuf = Clients[CIndex].c_pSendBuf;
  630. WriteLen = Clients[CIndex].c_reqbuf.SendSize;
  631. }
  632. while (NumReads--) {
  633. // for Srv and First Iteration just post a receive
  634. if (SrvCli && FirstIter) {
  635. RetCode = DGNetBIOS_Receive(
  636. CIndex,
  637. (PVOID) ReadBuf,
  638. (USHORT) ReadLen);
  639. if (RetCode) {
  640. //MyDbgPrint("NB: Err in Recv ReadFromIPC retc: %C \n", RetCode);
  641. return (STATUS_UNSUCCESSFUL);
  642. }
  643. }
  644. else {
  645. RetCode = DGNetBIOS_RecvSend(
  646. CIndex,
  647. WriteBuf,
  648. (USHORT) WriteLen,
  649. ReadBuf,
  650. (USHORT) ReadLen);
  651. if (RetCode) {
  652. //MyDbgPrint("NB: Err in XactIO retc: %C \n", RetCode);
  653. return (STATUS_UNSUCCESSFUL);
  654. }
  655. }
  656. }
  657. return (STATUS_SUCCESS);
  658. }
  659. /************************************************************************/
  660. NTSTATUS
  661. DGNB_Cleanup(VOID)
  662. {
  663. //USHORT Cindex = 0; // client index
  664. //NTSTATUS cstatus;
  665. //NTSTATUS exitstatus = 0;
  666. /*
  667. for (Cindex = 0; Cindex < NClients; Cindex++) {
  668. }
  669. */
  670. return (STATUS_SUCCESS);
  671. }
  672. /************************************************************************/
  673. /*++
  674. This routine does a client specific cleanup work.
  675. --*/
  676. NTSTATUS
  677. DGNB_ThreadCleanUp(
  678. IN USHORT CIndex)
  679. {
  680. NTSTATUS tstatus;
  681. UCHAR RetCode;
  682. // Close all the events
  683. tstatus = CloseHandle(Clients[CIndex].c_NetB.c_SendEvent);
  684. tstatus = CloseHandle(Clients[CIndex].c_NetB.c_RecvEvent);
  685. tstatus = CloseHandle(Clients[CIndex].c_NetB.c_RecvEventG);
  686. // Delete the name Added
  687. RetCode = NetBIOS_DelName(
  688. LocalName,
  689. (UCHAR) Clients[CIndex].c_NetB.c_LanaNumber);
  690. if (RetCode) {
  691. //MyDbgPrint("NB: Error in DelName retc: %C \n", RetCode);
  692. return (STATUS_UNSUCCESSFUL);
  693. }
  694. return STATUS_SUCCESS;
  695. }
  696. /************************************************************************/
  697. UCHAR
  698. DGNetBIOS_RecvSend(
  699. IN USHORT TIndex,
  700. IN PUCHAR SendBuffer,
  701. IN USHORT SendLen,
  702. IN PUCHAR RecvBuffer,
  703. IN USHORT RecvLen)
  704. {
  705. NCB ReceiveNCB; // Make it a part of client
  706. NCB SendNCB; // Make it a part of client struc
  707. NTSTATUS rstatus, sstatus;
  708. UCHAR RRetCode, SRetCode;
  709. RRetCode = SRetCode = 0;
  710. ClearNCB(&ReceiveNCB); // cleanup everything
  711. ClearNCB(&SendNCB); // cleanup everything
  712. // First post Receive but don't wait as this is for the next
  713. // request block
  714. ReceiveNCB.ncb_command = NCBDGRECV | ASYNCH;
  715. ReceiveNCB.ncb_lana_num = (UCHAR) Clients[TIndex].c_NetB.c_LanaNumber;
  716. ReceiveNCB.ncb_lsn = Clients[TIndex].c_NetB.c_LSN;
  717. ReceiveNCB.ncb_buffer = RecvBuffer;
  718. ReceiveNCB.ncb_length = RecvLen;
  719. ReceiveNCB.ncb_event = Clients[TIndex].c_NetB.c_RecvEvent;
  720. RRetCode = Netbios(&ReceiveNCB); // submit to NetBIOS
  721. if (ReceiveNCB.ncb_cmd_cplt == NRC_PENDING){
  722. // now do all the send(s)
  723. SendNCB.ncb_command = NCBDGSEND | ASYNCH;
  724. SendNCB.ncb_lana_num = (UCHAR) Clients[TIndex].c_NetB.c_LanaNumber;
  725. SendNCB.ncb_lsn = Clients[TIndex].c_NetB.c_LSN;
  726. SendNCB.ncb_buffer = SendBuffer;
  727. SendNCB.ncb_length = SendLen;
  728. SendNCB.ncb_event = Clients[TIndex].c_NetB.c_SendEvent;
  729. SRetCode = Netbios(&SendNCB); // submit to NetBIOS
  730. // First wait on Send , if successful then wait on receive
  731. if (SendNCB.ncb_cmd_cplt == NRC_PENDING){
  732. // First wait for the Send to complete
  733. sstatus = WaitForSingleObjectEx(SendNCB.ncb_event,
  734. INFINITE,
  735. TRUE);
  736. }
  737. if (SendNCB.ncb_cmd_cplt != NRC_GOODRET) {
  738. //DbgPrint("NBSRV:NBSR:Send failed %x RetCode:%x\n",SendNCB.ncb_cmd_cplt,SRetCode);
  739. // Cancel the receive posted earlier
  740. return SendNCB.ncb_cmd_cplt;
  741. }
  742. // Now wait for the receive to complete
  743. rstatus = WaitForSingleObjectEx(ReceiveNCB.ncb_event,
  744. INFINITE,
  745. TRUE);
  746. // check for status success here
  747. }
  748. if (ReceiveNCB.ncb_cmd_cplt != NRC_GOODRET) {
  749. //DbgPrint("NBSRV:NBSR:Receive failed %x RetCode:%x\n",ReceiveNCB.ncb_cmd_cplt,RRetCode);
  750. }
  751. return ReceiveNCB.ncb_cmd_cplt;
  752. }
  753. /************************************************************************/