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.

463 lines
14 KiB

  1. //////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 2001 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // tdiquery.cpp
  7. //
  8. // Abstract:
  9. // This module contains functions associated with querying
  10. // the tdi device objects
  11. //
  12. //////////////////////////////////////////////////////////
  13. #include "stdafx.h"
  14. // -------------------------------
  15. //
  16. // Function: DoTdiQuery
  17. //
  18. // Arguments: TdiHandle -- handle to use for query
  19. // QueryId -- which query to do
  20. // ppvData -- allocated block containing results
  21. //
  22. // Returns: none
  23. //
  24. // Descript: Handles all tdi query commands
  25. //
  26. // -------------------------------
  27. PVOID
  28. DoTdiQuery(ULONG ulTdiHandle,
  29. ULONG ulQueryId)
  30. {
  31. RECEIVE_BUFFER ReceiveBuffer; // return info from command
  32. SEND_BUFFER SendBuffer; // arguments for command
  33. //
  34. // set up arguments
  35. //
  36. SendBuffer.TdiHandle = ulTdiHandle;
  37. SendBuffer.COMMAND_ARGS.ulQueryId = ulQueryId;
  38. //
  39. // call the driver
  40. //
  41. NTSTATUS lStatus = TdiLibDeviceIO(ulQUERYINFO,
  42. &SendBuffer,
  43. &ReceiveBuffer);
  44. //
  45. // deal with results
  46. //
  47. PVOID pvBuffer = NULL; // buffer to return to caller
  48. if (lStatus == STATUS_SUCCESS)
  49. {
  50. ULONG ulCopyLength = ReceiveBuffer.RESULTS.QueryRet.ulBufferLength;
  51. if (ulCopyLength)
  52. {
  53. pvBuffer = LocalAllocateMemory(ulCopyLength);
  54. if (pvBuffer)
  55. {
  56. memcpy(pvBuffer,
  57. ReceiveBuffer.RESULTS.QueryRet.pucDataBuffer,
  58. ulCopyLength);
  59. }
  60. else
  61. {
  62. _putts(TEXT("DoTdiQuery: allocation failure\n"));
  63. }
  64. }
  65. else
  66. {
  67. _putts(TEXT("DoTdiQuery: length = 0\n"));
  68. }
  69. }
  70. else
  71. {
  72. _tprintf(TEXT("DoTdiQuery: failure, status = %s\n"), TdiLibStatusMessage(lStatus));
  73. }
  74. return pvBuffer;
  75. }
  76. // -------------------------------
  77. //
  78. // Function: DoPrintProviderInfo
  79. //
  80. // Arguments: pInfo -- ProviderInfo to print
  81. //
  82. // Returns: none
  83. //
  84. // Descript: Prints provider info to console
  85. //
  86. // -------------------------------
  87. VOID
  88. DoPrintProviderInfo(PTDI_PROVIDER_INFO pInfo)
  89. {
  90. _tprintf(TEXT("\nTDI_PROVIDER_INFO\n")
  91. TEXT("--Version: 0x%08x\n")
  92. TEXT("--MaxSendSize: %u\n")
  93. TEXT("--MaxConnUserData: %u\n")
  94. TEXT("--MaxDatagramSize: %u\n")
  95. TEXT("--MinLookaheadData: %u\n")
  96. TEXT("--MaxLookaheadData: %u\n")
  97. TEXT("--NumOfResources: %u\n")
  98. TEXT("--StartTime: %I64u\n")
  99. TEXT("--ServiceFlags: 0x%08x\n"),
  100. pInfo->Version,
  101. pInfo->MaxSendSize,
  102. pInfo->MaxConnectionUserData,
  103. pInfo->MaxDatagramSize,
  104. pInfo->MinimumLookaheadData,
  105. pInfo->MaximumLookaheadData,
  106. pInfo->NumberOfResources,
  107. pInfo->StartTime.QuadPart,
  108. pInfo->ServiceFlags);
  109. ULONG ulServiceFlags = pInfo->ServiceFlags;
  110. if (ulServiceFlags & TDI_SERVICE_CONNECTION_MODE)
  111. {
  112. _putts(TEXT("TDI_SERVICE_CONNECTION_MODE\n"));
  113. }
  114. if (ulServiceFlags & TDI_SERVICE_ORDERLY_RELEASE)
  115. {
  116. _putts(TEXT("TDI_SERVICE_ORDERLY_RELEASE\n"));
  117. }
  118. if (ulServiceFlags & TDI_SERVICE_CONNECTIONLESS_MODE)
  119. {
  120. _putts(TEXT("TDI_SERVICE_CONNECTIONLESS_MODE\n"));
  121. }
  122. if (ulServiceFlags & TDI_SERVICE_ERROR_FREE_DELIVERY)
  123. {
  124. _putts(TEXT("TDI_SERVICE_ERROR_FREE_DELIVERY\n"));
  125. }
  126. if (ulServiceFlags & TDI_SERVICE_SECURITY_LEVEL)
  127. {
  128. _putts(TEXT("TDI_SERVICE_SECURITY_LEVEL\n"));
  129. }
  130. if (ulServiceFlags & TDI_SERVICE_BROADCAST_SUPPORTED)
  131. {
  132. _putts(TEXT("TDI_SERVICE_BROADCAST_SUPPORTED\n"));
  133. }
  134. if (ulServiceFlags & TDI_SERVICE_MULTICAST_SUPPORTED)
  135. {
  136. _putts(TEXT("TDI_SERVICE_MULTICAST_SUPPORTED\n"));
  137. }
  138. if (ulServiceFlags & TDI_SERVICE_DELAYED_ACCEPTANCE)
  139. {
  140. _putts(TEXT("TDI_SERVICE_DELAYED_ACCEPTANCE\n"));
  141. }
  142. if (ulServiceFlags & TDI_SERVICE_EXPEDITED_DATA)
  143. {
  144. _putts(TEXT("TDI_SERVICE_EXPEDITED_DATA\n"));
  145. }
  146. if (ulServiceFlags & TDI_SERVICE_INTERNAL_BUFFERING)
  147. {
  148. _putts(TEXT("TDI_SERVICE_INTERNAL_BUFFERING\n"));
  149. }
  150. if (ulServiceFlags & TDI_SERVICE_ROUTE_DIRECTED)
  151. {
  152. _putts(TEXT("TDI_SERVICE_ROUTE_DIRECTED\n"));
  153. }
  154. if (ulServiceFlags & TDI_SERVICE_NO_ZERO_LENGTH)
  155. {
  156. _putts(TEXT("TDI_SERVICE_NO_ZERO_LENGTH\n"));
  157. }
  158. if (ulServiceFlags & TDI_SERVICE_POINT_TO_POINT)
  159. {
  160. _putts(TEXT("TDI_SERVICE_POINT_TO_POINT\n"));
  161. }
  162. if (ulServiceFlags & TDI_SERVICE_MESSAGE_MODE)
  163. {
  164. _putts(TEXT("TDI_SERVICE_MESSAGE_MODE\n"));
  165. }
  166. if (ulServiceFlags & TDI_SERVICE_HALF_DUPLEX)
  167. {
  168. _putts(TEXT("TDI_SERVICE_HALF_DUPLEX\n"));
  169. }
  170. if (ulServiceFlags & TDI_SERVICE_DGRAM_CONNECTION)
  171. {
  172. _putts(TEXT("TDI_SERVICE_DGRAM_CONNECTION\n"));
  173. }
  174. if (ulServiceFlags & TDI_SERVICE_FORCE_ACCESS_CHECK)
  175. {
  176. _putts(TEXT("TDI_SERVICE_FORCE_ACCESS_CHECK\n"));
  177. }
  178. if (ulServiceFlags & TDI_SERVICE_SEND_AND_DISCONNECT)
  179. {
  180. _putts(TEXT("TDI_SERVICE_SEND_AND_DISCONNECT\n"));
  181. }
  182. if (ulServiceFlags & TDI_SERVICE_DIRECT_ACCEPT)
  183. {
  184. _putts(TEXT("TDI_SERVICE_DIRECT_ACCEPT\n"));
  185. }
  186. _putts(TEXT("\n"));
  187. }
  188. // -------------------------------
  189. //
  190. // Function: DoPrintProviderStats
  191. //
  192. // Arguments: pInfo -- ProviderStats to print
  193. //
  194. // Returns: none
  195. //
  196. // Descript: Prints provider stats to console
  197. //
  198. // -------------------------------
  199. VOID
  200. DoPrintProviderStats(PTDI_PROVIDER_STATISTICS pStats)
  201. {
  202. _tprintf(TEXT("\nTDI_PROVIDER_STATISTICS\n")
  203. TEXT("--Version: 0x%08x\n")
  204. TEXT("--OpenConnections: %u\n")
  205. TEXT("--ConnectsNoRetry: %u\n")
  206. TEXT("--ConnectsWithRetry: %u\n")
  207. TEXT("--LocalDisconnects: %u\n")
  208. TEXT("--RemoteDisconnects: %u\n")
  209. TEXT("--LinkFailures: %u\n")
  210. TEXT("--AdapterFailures: %u\n")
  211. TEXT("--SessionTimeouts: %u\n")
  212. TEXT("--CancelledConnects: %u\n")
  213. TEXT("--RemResourceFails: %u\n")
  214. TEXT("--LocResourceFails: %u\n"),
  215. pStats->Version,
  216. pStats->OpenConnections,
  217. pStats->ConnectionsAfterNoRetry,
  218. pStats->ConnectionsAfterRetry,
  219. pStats->LocalDisconnects,
  220. pStats->RemoteDisconnects,
  221. pStats->LinkFailures,
  222. pStats->AdapterFailures,
  223. pStats->SessionTimeouts,
  224. pStats->CancelledConnections,
  225. pStats->RemoteResourceFailures,
  226. pStats->LocalResourceFailures);
  227. _tprintf(TEXT("--NotFoundFailures: %u\n")
  228. TEXT("--NoListenFailures: %u\n")
  229. TEXT("--DatagramsSent: %u\n")
  230. TEXT("--DatagramBytesSent: %I64u\n")
  231. TEXT("--DatagramsRecv: %u\n")
  232. TEXT("--DatagramBytesRecv: %I64u\n")
  233. TEXT("--PacketsSent: %u\n")
  234. TEXT("--PacketsRecv: %u\n")
  235. TEXT("--DataFramesSent: %u\n")
  236. TEXT("--DataFrmBytesSent: %I64u\n")
  237. TEXT("--DataFramesRecv: %u\n")
  238. TEXT("--DataFrmBytesRecv: %I64u\n"),
  239. pStats->NotFoundFailures,
  240. pStats->NoListenFailures,
  241. pStats->DatagramsSent,
  242. pStats->DatagramBytesSent.QuadPart,
  243. pStats->DatagramsReceived,
  244. pStats->DatagramBytesReceived.QuadPart,
  245. pStats->PacketsSent,
  246. pStats->PacketsReceived,
  247. pStats->DataFramesSent,
  248. pStats->DataFrameBytesSent.QuadPart,
  249. pStats->DataFramesReceived,
  250. pStats->DataFrameBytesReceived.QuadPart);
  251. _tprintf(TEXT("--DataFramesResent: %u\n")
  252. TEXT("--DataFrBytesResent: %I64u\n")
  253. TEXT("--DataFrmRejected: %u\n")
  254. TEXT("--DataFrmBytesRejd: %I64u\n")
  255. TEXT("--RespTimerExpires: %u\n")
  256. TEXT("--AckTimerExpires: %u\n")
  257. TEXT("--MaximumSendWindow: %u\n")
  258. TEXT("--AverageSendWindow: %u\n")
  259. TEXT("--PigbackAckQueued: %u\n")
  260. TEXT("--PigbackAckTimeout: %u\n")
  261. TEXT("--WastedPacketSpace: %I64u\n")
  262. TEXT("--WastedSpacePkts: %u\n")
  263. TEXT("--NumberOfResources: %u\n"),
  264. pStats->DataFramesResent,
  265. pStats->DataFrameBytesResent.QuadPart,
  266. pStats->DataFramesRejected,
  267. pStats->DataFrameBytesRejected.QuadPart,
  268. pStats->ResponseTimerExpirations,
  269. pStats->AckTimerExpirations,
  270. pStats->MaximumSendWindow,
  271. pStats->AverageSendWindow,
  272. pStats->PiggybackAckQueued,
  273. pStats->PiggybackAckTimeouts,
  274. pStats->WastedPacketSpace.QuadPart,
  275. pStats->WastedSpacePackets,
  276. pStats->NumberOfResources);
  277. if (pStats->NumberOfResources)
  278. {
  279. PTDI_PROVIDER_RESOURCE_STATS pResourceStats = pStats->ResourceStats;
  280. for (ULONG ulCount = 0; ulCount < pStats->NumberOfResources; ulCount++)
  281. {
  282. _tprintf(TEXT("--Resource #%u\n")
  283. TEXT("----ResourceId %u\n")
  284. TEXT("----MaxResourceUsed: %u\n")
  285. TEXT("----AveResourceUsed: %u\n")
  286. TEXT("----ResExhausted: %u\n"),
  287. ulCount,
  288. pResourceStats->ResourceId,
  289. pResourceStats->MaximumResourceUsed,
  290. pResourceStats->AverageResourceUsed,
  291. pResourceStats->ResourceExhausted);
  292. pResourceStats++;
  293. }
  294. }
  295. _putts(TEXT("\n"));
  296. }
  297. // -------------------------------
  298. //
  299. // Function: DoPrintAdapterStatus
  300. //
  301. // Arguments: pInfo -- AdapterStatus to print
  302. //
  303. // Returns: none
  304. //
  305. // Descript: Prints Adapter Status to console
  306. //
  307. // -------------------------------
  308. VOID
  309. DoPrintAdapterStatus(PADAPTER_STATUS pStatus)
  310. {
  311. _tprintf(TEXT("\nADAPTER_STATUS\n")
  312. TEXT("--AdapterAddress: %02x-%02x-%02x-%02x-%02x-%02x\n"),
  313. pStatus->adapter_address[0],
  314. pStatus->adapter_address[1],
  315. pStatus->adapter_address[2],
  316. pStatus->adapter_address[3],
  317. pStatus->adapter_address[4],
  318. pStatus->adapter_address[5]);
  319. _tprintf(TEXT("--RevMajor: %u\n")
  320. TEXT("--RevMinor: %u\n")
  321. TEXT("--AdapterType: %u\n")
  322. TEXT("--Duration: %u\n")
  323. TEXT("--FrmrRecv: %u\n")
  324. TEXT("--FrmrXmit: %u\n")
  325. TEXT("--FrameRecvErr: %u\n")
  326. TEXT("--XmitAbofts: %u\n")
  327. TEXT("--XmitSuccess: %u\n")
  328. TEXT("--RecvSuccess: %u\n")
  329. TEXT("--FrameXmitErr: %u\n"),
  330. pStatus->rev_major,
  331. pStatus->rev_minor,
  332. pStatus->adapter_type,
  333. pStatus->duration,
  334. pStatus->frmr_recv,
  335. pStatus->frmr_xmit,
  336. pStatus->iframe_recv_err,
  337. pStatus->xmit_aborts,
  338. pStatus->xmit_success,
  339. pStatus->recv_success,
  340. pStatus->iframe_xmit_err);
  341. _tprintf(TEXT("--RecvBufUnavail: %u\n")
  342. TEXT("--T1 Timeouts: %u\n")
  343. TEXT("--TI Timeouts: %u\n")
  344. TEXT("--FreeNcbs: %u\n")
  345. TEXT("--MaxCfgNcbs: %u\n")
  346. TEXT("--MaxNcbs: %u\n")
  347. TEXT("--XmitBufUnavail: %u\n")
  348. TEXT("--MaxDgramSize: %u\n")
  349. TEXT("--PendingSess: %u\n")
  350. TEXT("--MaxCfgSess: %u\n")
  351. TEXT("--MaxSess: %u\n")
  352. TEXT("--MaxSessPktSize: %u\n")
  353. TEXT("--Names: %u\n"),
  354. pStatus->recv_buff_unavail,
  355. pStatus->t1_timeouts,
  356. pStatus->ti_timeouts,
  357. pStatus->free_ncbs,
  358. pStatus->max_cfg_ncbs,
  359. pStatus->max_ncbs,
  360. pStatus->xmit_buf_unavail,
  361. pStatus->max_dgram_size,
  362. pStatus->pending_sess,
  363. pStatus->max_cfg_sess,
  364. pStatus->max_sess,
  365. pStatus->max_sess_pkt_size,
  366. pStatus->name_count);
  367. if (pStatus->name_count)
  368. {
  369. PUCHAR pucTemp = (PUCHAR)pStatus + sizeof(ADAPTER_STATUS);
  370. PNAME_BUFFER pNameBuffer = (PNAME_BUFFER)pucTemp;
  371. TCHAR pName[NCBNAMSZ+1];
  372. UCHAR ucFlags;
  373. pName[NCBNAMSZ] = 0;
  374. _putts(TEXT("NameBuffers\n"));
  375. for (ULONG ulCount = pStatus->name_count; ulCount != 0; ulCount--)
  376. {
  377. //
  378. // note: pNameBuffer->name not necessarily 0 terminated
  379. //
  380. for(ULONG ulIndex = 0; ulIndex < NCBNAMSZ; ulIndex++)
  381. {
  382. pName[ulIndex] = pNameBuffer->name[ulIndex];
  383. }
  384. pName[NCBNAMSZ] = 0;
  385. ucFlags = pNameBuffer->name_flags;
  386. _tprintf(TEXT("--Name: %s\n")
  387. TEXT("--NameNum: %u\n")
  388. TEXT("--NameFlags: 0x%02x\n")
  389. TEXT(" "),
  390. pName,
  391. pNameBuffer->name_num,
  392. ucFlags);
  393. if (ucFlags & GROUP_NAME)
  394. {
  395. _putts(TEXT("GROUP_NAME "));
  396. }
  397. else
  398. {
  399. _putts(TEXT("UNIQUE_NAME "));
  400. }
  401. ucFlags &= 0x07;
  402. switch (ucFlags)
  403. {
  404. case REGISTERING:
  405. _putts(TEXT("Registering\n"));
  406. break;
  407. case REGISTERED:
  408. _putts(TEXT("Registered\n"));
  409. break;
  410. case DEREGISTERED:
  411. _putts(TEXT("Deregistered\n"));
  412. break;
  413. case DUPLICATE:
  414. _putts(TEXT("Duplicate\n"));
  415. break;
  416. case DUPLICATE_DEREG:
  417. _putts(TEXT("Duplicate Dereg\n"));
  418. break;
  419. default:
  420. _putts(TEXT("UNKNOWN\n"));
  421. break;
  422. }
  423. pNameBuffer++;
  424. }
  425. }
  426. _putts(TEXT("\n"));
  427. }
  428. ////////////////////////////////////////////////////////////////////
  429. // end of file tdiquery.cpp
  430. ////////////////////////////////////////////////////////////////////