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.

1698 lines
76 KiB

  1. /*****************************************************************************
  2. * portclsd.cpp - Portcls WinDbg/KD Debugger Extensions
  3. *****************************************************************************
  4. * Copyright (c) 1998 Microsoft Corporation
  5. */
  6. #include "precomp.h"
  7. #define PC_KDEXT
  8. typedef enum _PCKD_PORTTYPE
  9. {
  10. Topology = 0,
  11. WaveCyclic,
  12. WavePci,
  13. Midi,
  14. UnknownPort
  15. } PCKD_PORTTYPE;
  16. #define MAPPED_QUEUE 0
  17. #define LOCKED_QUEUE 1
  18. #define PRELOCK_QUEUE 2
  19. #define MAX_QUEUES 3
  20. typedef union _PORTCLS_FLAGS
  21. {
  22. struct
  23. {
  24. ULONG PortDump : 1;
  25. ULONG FilterDump : 1;
  26. ULONG PinDump : 1;
  27. ULONG DeviceContext : 1;
  28. ULONG PowerInfo : 1;
  29. ULONG Reserved1 : 3;
  30. ULONG Verbose : 1;
  31. ULONG ReallyVerbose : 1;
  32. ULONG Reserved : 22;
  33. };
  34. ULONG Flags;
  35. } PORTCLS_FLAGS;
  36. typedef struct _PCKD_IRPSTREAM_ENTRY
  37. {
  38. LIST_ENTRY ListEntry;
  39. PVOID Irp;
  40. ULONG QueueType;
  41. } PCKD_IRP_ENTRY;
  42. typedef struct _PCKD_PIN_ENTRY
  43. {
  44. LIST_ENTRY ListEntry;
  45. LIST_ENTRY IrpList;
  46. PVOID PinData;
  47. PVOID IrpStreamData;
  48. ULONG PinInstanceId;
  49. } PCKD_PIN_ENTRY;
  50. typedef struct _PCKD_FILTER_ENTRY
  51. {
  52. LIST_ENTRY ListEntry;
  53. LIST_ENTRY PinList;
  54. PVOID FilterData;
  55. ULONG FilterInstanceId;
  56. } PCKD_FILTER_ENTRY;
  57. typedef struct _PCKD_PORT
  58. {
  59. LIST_ENTRY FilterList;
  60. PCKD_PORTTYPE PortType;
  61. PVOID PortData;
  62. } PCKD_PORT;
  63. typedef struct {
  64. ULONG64 Create;
  65. ULONG64 Context;
  66. UNICODE_STRING ObjectClass;
  67. ULONG64 ObjectClassBuffer;
  68. ULONG64 SecurityDescriptor;
  69. ULONG Flags;
  70. } KSOBJECT_CREATE_ITEM_READ, *PKSOBJECT_CREATE_ITEM_READ;
  71. typedef struct _PCKD_SUBDEVICE_ENTRY
  72. {
  73. LIST_ENTRY ListEntry;
  74. PCKD_PORT Port;
  75. ULONG64 CreateItemAddr;
  76. KSOBJECT_CREATE_ITEM_READ CreateItem;
  77. } PCKD_SUBDEVICE_ENTRY;
  78. #define TranslateDevicePower( x ) \
  79. ( x == PowerDeviceD0 ? "PowerDeviceD0" : \
  80. x == PowerDeviceD1 ? "PowerDeviceD1" : \
  81. x == PowerDeviceD2 ? "PowerDeviceD2" : \
  82. x == PowerDeviceD3 ? "PowerDeviceD3" : "Unknown" )
  83. #define TranslateSystemPower( x ) \
  84. ( x == PowerSystemWorking ? "PowerSystemWorking" : \
  85. x == PowerSystemSleeping1 ? "PowerSystemSleeping1" : \
  86. x == PowerSystemSleeping2 ? "PowerSystemSleeping2" : \
  87. x == PowerSystemSleeping3 ? "PowerSystemSleeping3" : \
  88. x == PowerSystemHibernate ? "PowerSystemHibernate" : \
  89. x == PowerSystemShutdown ? "PowerSystemShutdown" : "Unknown" )
  90. #define TranslateKsState( x ) \
  91. ( x == KSSTATE_STOP ? "KSSTATE_STOP" : \
  92. x == KSSTATE_ACQUIRE ? "KSSTATE_ACQUIRE" : \
  93. x == KSSTATE_PAUSE ? "KSSTATE_PAUSE" : \
  94. x == KSSTATE_RUN ? "KSSTATE_RUN" : "Unknown" )
  95. #define TranslateKsDataFlow( x ) \
  96. ( x == KSPIN_DATAFLOW_IN ? "KSPIN_DATAFLOW_IN" : \
  97. x == KSPIN_DATAFLOW_OUT ? "KSPIN_DATAFLOW_OUT" : "Unknown" )
  98. #define TranslateQueueType( x ) \
  99. ( x == PRELOCK_QUEUE ? "P" : \
  100. x == LOCKED_QUEUE ? "L" : \
  101. x == MAPPED_QUEUE ? "M" : "U" )
  102. /**********************************************************************
  103. * Forward References
  104. **********************************************************************
  105. */
  106. BOOL
  107. PCKD_ValidateDevObj
  108. (
  109. PDEVICE_CONTEXT DeviceContext
  110. );
  111. VOID
  112. PCKD_AcquireDeviceData
  113. (
  114. PDEVICE_CONTEXT DeviceContext,
  115. PLIST_ENTRY SubdeviceList,
  116. ULONG Flags
  117. );
  118. VOID
  119. PCKD_DisplayDeviceData
  120. (
  121. PDEVICE_CONTEXT DeviceContext,
  122. PLIST_ENTRY SubdeviceList,
  123. ULONG Flags
  124. );
  125. VOID
  126. PCKD_FreeDeviceData
  127. (
  128. PLIST_ENTRY SubdeviceList
  129. );
  130. VOID
  131. PCKD_AcquireIrpStreamData
  132. (
  133. PVOID PinEntry,
  134. CIrpStream *RemoteIrpStream,
  135. CIrpStream *LocalIrpStream
  136. );
  137. /**********************************************************************
  138. * DECLARE_API( portcls )
  139. **********************************************************************
  140. * Description:
  141. * Dumps PortCls data given the device object (FDO) of a PortCls
  142. * bound DevObj.
  143. *
  144. * Arguments:
  145. * args - address flags
  146. *
  147. * Return Value:
  148. * None
  149. */
  150. extern "C"
  151. DECLARE_API( portcls )
  152. {
  153. ULONG64 memLoc;
  154. ULONG result;
  155. CHAR buffer[256];
  156. PORTCLS_FLAGS flags;
  157. LIST_ENTRY SubdeviceList;
  158. ULONG64 DeviceExtension;
  159. buffer[0] = '\0';
  160. flags.Flags = 0;
  161. //
  162. // get the arguments
  163. //
  164. if( !*args )
  165. {
  166. memLoc = EXPRLastDump;
  167. } else
  168. {
  169. if (GetExpressionEx(args, &memLoc, &args)) {
  170. StringCchCopy(buffer, sizeof(buffer), args);
  171. }
  172. }
  173. flags.Flags = 0;
  174. if ('\0' != buffer[0]) {
  175. flags.Flags = GetExpression(buffer);
  176. }
  177. //
  178. // print out info
  179. //
  180. dprintf("Dump Portcls DevObj Info %p %x \n", memLoc, flags.Flags );
  181. //
  182. // get the DevObj data
  183. //
  184. if( memLoc )
  185. {
  186. if( GetFieldValue( memLoc, "DEVICE_OBJECT", "DeviceExtension", DeviceExtension ) )
  187. {
  188. dprintf("Could not read DevObj data\n");
  189. return E_INVALIDARG;
  190. }
  191. } else
  192. {
  193. dprintf("\nSYNTAX: !portcls <devobj> [flags]\n");
  194. }
  195. //
  196. // check for device extension
  197. //
  198. if( !DeviceExtension )
  199. {
  200. dprintf("DevObj has no device extension\n");
  201. return E_INVALIDARG;
  202. }
  203. //
  204. // get the device context
  205. //
  206. if( InitTypeRead( DeviceExtension, "DEVICE_CONTEXT" ) )
  207. {
  208. dprintf("Could not read DevObj device extension\n");
  209. return E_INVALIDARG;
  210. }
  211. //
  212. // validate the DevObj
  213. //
  214. if( !PCKD_ValidateDevObj( DeviceExtension ) )
  215. {
  216. dprintf("DevObj not valid or not bound to PortCls\n");
  217. return E_INVALIDARG;
  218. }
  219. //
  220. // initialize the subdevice list
  221. //
  222. InitializeListHead( &SubdeviceList );
  223. //
  224. // acquire the device data
  225. //
  226. PCKD_AcquireDeviceData( DeviceExtension, &SubdeviceList, flags.Flags );
  227. //
  228. // display the requested info
  229. //
  230. PCKD_DisplayDeviceData( DeviceExtension, &SubdeviceList, flags.Flags );
  231. //
  232. // release the device data
  233. //
  234. PCKD_FreeDeviceData( &SubdeviceList );
  235. return S_OK;
  236. }
  237. /**********************************************************************
  238. * PCKD_ValidateDevObj
  239. **********************************************************************
  240. * Description:
  241. * This routine attempts to validate whether or not a given device
  242. * extension is from a PortCls bound DevObj.
  243. *
  244. * Arguments:
  245. * PDEVICE_CONTEXT DeviceContext
  246. * PORTCLS_FLAGS Flags
  247. *
  248. * Return Value:
  249. * BOOL TRUE = Valid, FALSE = Invalid
  250. */
  251. BOOL
  252. PCKD_ValidateDevObj
  253. (
  254. ULONG64 DeviceContext
  255. )
  256. {
  257. UNREFERENCED_PARAMETER( DeviceContext );
  258. // TODO - Validate device extension
  259. return TRUE;
  260. }
  261. /**********************************************************************
  262. * PCKD_AcquireDeviceData
  263. **********************************************************************
  264. * Description:
  265. * This routine acquires device data given a validated device
  266. * context and builds a subdevice list contain all of the data.
  267. *
  268. * Arguments:
  269. * PDEVICE_CONTEXT DeviceContext
  270. * PLIST_ENTRY SubdeviceList
  271. * PORTCLS_FLAGS Flags
  272. *
  273. * Return Value:
  274. * None
  275. */
  276. VOID
  277. PCKD_AcquireDeviceData
  278. (
  279. ULONG64 DeviceContext,
  280. PLIST_ENTRY SubdeviceList,
  281. ULONG flags
  282. )
  283. {
  284. ULONG SubdeviceIndex;
  285. PCKD_SUBDEVICE_ENTRY *SubdeviceEntry;
  286. ULONG64 CreateItems;
  287. ULONG64 CurrentCreateItemAddr;
  288. PKSOBJECT_CREATE_ITEM_READ ReadCreateItems;
  289. PKSOBJECT_CREATE_ITEM_READ CurrentCreateItem;
  290. PWSTR Buffer;
  291. ULONG Size;
  292. ULONG Result;
  293. ANSI_STRING AnsiString;
  294. PLIST_ENTRY ListEntry;
  295. PORTCLS_FLAGS Flags;
  296. ULONG ItemSz, MaxObjects;
  297. ULONG i;
  298. Flags.Flags = flags;
  299. ItemSz = GetTypeSize("KSOBJECT_CREATE_ITEM");
  300. InitTypeRead(DeviceContext, DEVICE_CONTEXT);
  301. // allocate local memory for the create items table
  302. Size = (MaxObjects = (ULONG) ReadField(MaxObjects)) * sizeof(KSOBJECT_CREATE_ITEM_READ);
  303. ReadCreateItems = (PKSOBJECT_CREATE_ITEM_READ)LocalAlloc( LPTR, Size );
  304. if( !ReadCreateItems )
  305. {
  306. dprintf("** Unable to allocate create item table memory\n");
  307. return;
  308. }
  309. CreateItems = ReadField(CreateItems);
  310. // copy the create items table to local memory
  311. for (i=0, CurrentCreateItemAddr=CreateItems;
  312. i<MaxObjects, CurrentCreateItemAddr+=IteSz;
  313. i++) {
  314. InitTypeRead(CurrentCreateItemAddr, KSOBJECT_CREATE_ITEM);
  315. ReadCreateItems[i].Context = ReadField(Context);
  316. ReadCreateItems[i].Create = ReadField(Create);
  317. ReadCreateItems[i].Flags = ReadField(Flags);
  318. ReadCreateItems[i].ObjectClassBuffer = ReadField(ObjectClass.Buffer);
  319. ReadCreateItems[i].ObjectClass.MaximumLength = ReadField(ObjectClass.MaximumLength);
  320. ReadCreateItems[i].ObjectClass.Length = ReadField(ObjectClass.Length);
  321. ReadCreateItems[i].SecurityDescriptor = ReadField(SecurityDescriptor);
  322. }
  323. // check out each potential subdevice
  324. for( SubdeviceIndex = 0, CurrentCreateItem = ReadCreateItems;
  325. SubdeviceIndex < MaxObjects;
  326. SubdeviceIndex++, CurrentCreateItem++ )
  327. {
  328. if( CurrentCreateItem->Create) )
  329. {
  330. // allocate a subdevice list entry
  331. SubdeviceEntry = (PCKD_SUBDEVICE_ENTRY *)LocalAlloc( LPTR, sizeof(PCKD_SUBDEVICE_ENTRY) );
  332. if( SubdeviceEntry )
  333. {
  334. // initialize the port filter list
  335. InitializeListHead( &(SubdeviceEntry->Port.FilterList) );
  336. // copy the create item data
  337. memcpy( &(SubdeviceEntry->CreateItem), CurrentCreateItem, sizeof(KSOBJECT_CREATE_ITEM_READ) );
  338. // allocate memory for the unicode string buffer
  339. Buffer = (PWSTR)LocalAlloc( LPTR, CurrentCreateItem->ObjectClass.MaximumLength );
  340. if( !Buffer )
  341. {
  342. dprintf("** Unable to allocate unicode string buffer\n");
  343. LocalFree( SubdeviceEntry );
  344. break;
  345. }
  346. // read unicode string data
  347. if( !ReadMemory( CurrentCreateItem->ObjectClassBuffer,
  348. Buffer,
  349. CurrentCreateItem->ObjectClass.MaximumLength,
  350. &Result ) )
  351. {
  352. dprintf("** Unable to read unicode string buffer (0x%p)\n",CurrentCreateItem->ObjectClassBuffer);
  353. LocalFree( Buffer );
  354. LocalFree( SubdeviceEntry );
  355. break;
  356. }
  357. // point the create item string to the local buffer
  358. // ?????
  359. SubdeviceEntry->CreateItem.ObjectClass.Buffer = Buffer;
  360. // determine port type by checking string
  361. // TODO: this should be done by the GUID
  362. //
  363. // convert to ansi
  364. RtlUnicodeStringToAnsiString( &AnsiString,
  365. &(SubdeviceEntry->CreateItem.ObjectClass),
  366. TRUE );
  367. if( 0 == _stricmp( AnsiString.Buffer, "topology" ) )
  368. {
  369. SubdeviceEntry->Port.PortType = Topology;
  370. SubdeviceEntry->Port.PortData = NULL;
  371. } else if( 0 == _stricmp( AnsiString.Buffer, "wave" ) )
  372. {
  373. SubdeviceEntry->Port.PortType = WaveCyclic;
  374. SubdeviceEntry->Port.PortData = NULL;
  375. } else if( (0 == _stricmp( AnsiString.Buffer, "uart") ) ||
  376. (0 == _stricmp( AnsiString.Buffer, "fmsynth") ) )
  377. {
  378. SubdeviceEntry->Port.PortType = Midi;
  379. SubdeviceEntry->Port.PortData = NULL;
  380. } else
  381. {
  382. SubdeviceEntry->Port.PortType = UnknownPort;
  383. SubdeviceEntry->Port.PortData = NULL;
  384. }
  385. // free the ansi string
  386. RtlFreeAnsiString( &AnsiString );
  387. // add the subdevice entry to the subdevice list
  388. InsertTailList( SubdeviceList, &(SubdeviceEntry->ListEntry) );
  389. } else
  390. {
  391. dprintf("** Unable to allocate subdevice memory\n");
  392. }
  393. }
  394. }
  395. // free the create item table local storage
  396. LocalFree( ReadCreateItems );
  397. // acquire the port, filter, and pin data
  398. if( (!IsListEmpty(SubdeviceList)) && (Flags.PortDump || Flags.FilterDump || Flags.PinDump) )
  399. {
  400. for( ListEntry = SubdeviceList->Flink; ListEntry != SubdeviceList; ListEntry = ListEntry->Flink )
  401. {
  402. SubdeviceEntry = (PCKD_SUBDEVICE_ENTRY *) ListEntry;
  403. // read basic port data
  404. PVOID Port;
  405. ULONG PortSize;
  406. switch( SubdeviceEntry->Port.PortType)
  407. {
  408. case Topology:
  409. Port = LocalAlloc( LPTR, sizeof(CPortTopology) );
  410. if( !Port )
  411. {
  412. dprintf("** Unable to allocate port memory\n");
  413. break;
  414. }
  415. if( !ReadMemory( (ULONG)((CPortTopology *)((ISubdevice *)(SubdeviceEntry->CreateItem.Context))),
  416. Port,
  417. sizeof(CPortTopology),
  418. &Result ) )
  419. {
  420. dprintf("** Unable to read port data\n");
  421. LocalFree( Port );
  422. Port = NULL;
  423. break;
  424. }
  425. break;
  426. case WaveCyclic:
  427. Port = LocalAlloc( LPTR, sizeof(CPortWaveCyclic) );
  428. if( !Port )
  429. {
  430. dprintf("** Unable to allocate port memory\n");
  431. break;
  432. }
  433. if( !ReadMemory( (ULONG)((CPortWaveCyclic *)((ISubdevice *)(SubdeviceEntry->CreateItem.Context))),
  434. Port,
  435. sizeof(CPortWaveCyclic),
  436. &Result ) )
  437. {
  438. dprintf("** Unable to read port data\n");
  439. LocalFree( Port );
  440. Port = NULL;
  441. break;
  442. }
  443. break;
  444. case WavePci:
  445. Port = LocalAlloc( LPTR, sizeof(CPortWavePci) );
  446. if( !Port )
  447. {
  448. dprintf("** Unable to allocate port memory\n");
  449. break;
  450. }
  451. if( !ReadMemory( (ULONG)((CPortWavePci *)((ISubdevice *)(SubdeviceEntry->CreateItem.Context))),
  452. Port,
  453. sizeof(CPortWavePci),
  454. &Result ) )
  455. {
  456. dprintf("** Unable to read port data\n");
  457. LocalFree( Port );
  458. Port = NULL;
  459. break;
  460. }
  461. break;
  462. case Midi:
  463. Port = LocalAlloc( LPTR, sizeof(CPortMidi) );
  464. if( !Port )
  465. {
  466. dprintf("** Unable to allocate port memory\n");
  467. break;
  468. }
  469. if( !ReadMemory( (ULONG)((CPortMidi *)((ISubdevice *)(SubdeviceEntry->CreateItem.Context))),
  470. Port,
  471. sizeof(CPortMidi),
  472. &Result ) )
  473. {
  474. dprintf("** Unable to read port data\n");
  475. LocalFree( Port );
  476. Port = NULL;
  477. break;
  478. }
  479. break;
  480. default:
  481. break;
  482. }
  483. // attach the port data to the subdevice entry
  484. SubdeviceEntry->Port.PortData = Port;
  485. switch( SubdeviceEntry->Port.PortType )
  486. {
  487. case Topology:
  488. break;
  489. case WaveCyclic:
  490. {
  491. CPortWaveCyclic *PortWaveCyclic = (CPortWaveCyclic *)Port;
  492. // get the filter and pin data
  493. if( Flags.FilterDump || Flags.PinDump )
  494. {
  495. ULONG Offset;
  496. ULONG PortBase;
  497. PLIST_ENTRY Flink;
  498. PLIST_ENTRY TempListEntry;
  499. ULONG PinNumber = 0;
  500. CPortPinWaveCyclic *PortPinWaveCyclic;
  501. CIrpStream *IrpStream;
  502. PCKD_PIN_ENTRY *CurrentPinEntry;
  503. BOOL NeedNewFilter;
  504. // get the offsets needed to walk the list
  505. Offset = FIELD_OFFSET(CPortWaveCyclic,m_PinList);
  506. PortBase = (ULONG)((CPortWaveCyclic *)((ISubdevice *)(SubdeviceEntry->CreateItem.Context)));
  507. // get the first pin pointer
  508. Flink = PortWaveCyclic->m_PinList.Flink;
  509. while (Flink != PLIST_ENTRY(PortBase + Offset))
  510. {
  511. // allocate a pin list entry
  512. CurrentPinEntry = (PCKD_PIN_ENTRY *)LocalAlloc( LPTR, sizeof(PCKD_PIN_ENTRY) );
  513. if( !CurrentPinEntry )
  514. {
  515. dprintf("** Unable to allocate pin list entry\n");
  516. break;
  517. }
  518. // initialize the pin entry
  519. InitializeListHead( &(CurrentPinEntry->IrpList) );
  520. CurrentPinEntry->PinData = NULL;
  521. CurrentPinEntry->IrpStreamData = NULL;
  522. CurrentPinEntry->PinInstanceId = PinNumber++;
  523. // allocate local storage for the pin data
  524. PortPinWaveCyclic = (CPortPinWaveCyclic *)LocalAlloc( LPTR, sizeof(CPortPinWaveCyclic) );
  525. if( !PortPinWaveCyclic )
  526. {
  527. dprintf("** Unable to allocate pin data storage\n");
  528. LocalFree( CurrentPinEntry );
  529. break;
  530. }
  531. // read the pin data
  532. if( !ReadMemory( (ULONG)CONTAINING_RECORD(Flink,
  533. CPortPinWaveCyclic,
  534. m_PinListEntry),
  535. PortPinWaveCyclic,
  536. sizeof(CPortPinWaveCyclic),
  537. &Result ) )
  538. {
  539. dprintf("** Unable to read pin data\n");
  540. LocalFree( PortPinWaveCyclic );
  541. LocalFree( CurrentPinEntry );
  542. break;
  543. }
  544. // is there an irp stream
  545. if( PortPinWaveCyclic->m_IrpStream )
  546. {
  547. // allocate local storage for the irp stream data
  548. IrpStream = (CIrpStream *)LocalAlloc( LPTR, sizeof(CIrpStream) );
  549. if( IrpStream )
  550. {
  551. // read the irp stream data
  552. if( !ReadMemory( (ULONG)((CIrpStream *)(PortPinWaveCyclic->m_IrpStream)),
  553. IrpStream,
  554. sizeof(CIrpStream),
  555. &Result ) )
  556. {
  557. dprintf("** Unable to read irp stream data\n");
  558. LocalFree( IrpStream );
  559. } else
  560. {
  561. PCKD_AcquireIrpStreamData( CurrentPinEntry,
  562. (CIrpStream *)(PortPinWaveCyclic->m_IrpStream),
  563. IrpStream );
  564. }
  565. } else
  566. {
  567. dprintf("** Unable to allocate irp stream storage\n");
  568. }
  569. }
  570. // we need a new filter unless we find it in the filter list
  571. NeedNewFilter = TRUE;
  572. // is the filter list empty?
  573. if( !IsListEmpty( &(SubdeviceEntry->Port.FilterList) ) )
  574. {
  575. PLIST_ENTRY FilterListEntry;
  576. for( FilterListEntry = SubdeviceEntry->Port.FilterList.Flink;
  577. FilterListEntry != &(SubdeviceEntry->Port.FilterList);
  578. FilterListEntry = FilterListEntry->Flink )
  579. {
  580. PCKD_FILTER_ENTRY *CurrentFilterEntry = (PCKD_FILTER_ENTRY *) FilterListEntry;
  581. if( CurrentFilterEntry->FilterInstanceId == (ULONG)(PortPinWaveCyclic->m_Filter) )
  582. {
  583. // found our filter
  584. NeedNewFilter = FALSE;
  585. // add the pin data to the pin entry
  586. CurrentPinEntry->PinData = (PVOID)PortPinWaveCyclic;
  587. // add the pin entry to the filter's pin list
  588. InsertTailList( &(CurrentFilterEntry->PinList),
  589. &(CurrentPinEntry->ListEntry) );
  590. }
  591. }
  592. }
  593. // do we need a new filter entry?
  594. if( NeedNewFilter )
  595. {
  596. PCKD_FILTER_ENTRY *CurrentFilterEntry;
  597. // allocate a new filter entry
  598. CurrentFilterEntry = (PCKD_FILTER_ENTRY *)LocalAlloc( LPTR, sizeof(PCKD_FILTER_ENTRY) );
  599. if(!CurrentFilterEntry)
  600. {
  601. dprintf("** Unable to allocate filter entry\n");
  602. LocalFree( PortPinWaveCyclic );
  603. if( CurrentPinEntry->IrpStreamData )
  604. {
  605. LocalFree( CurrentPinEntry->IrpStreamData );
  606. }
  607. // free up any irps in the irp list
  608. while(!IsListEmpty( &(CurrentPinEntry->IrpList)))
  609. {
  610. PCKD_IRP_ENTRY *IrpEntry = (PCKD_IRP_ENTRY *)RemoveTailList(&(CurrentPinEntry->IrpList));
  611. LocalFree( IrpEntry );
  612. }
  613. LocalFree( CurrentPinEntry );
  614. break;
  615. }
  616. //initialize the new filter entry
  617. InitializeListHead( &(CurrentFilterEntry->PinList) );
  618. CurrentFilterEntry->FilterData = NULL;
  619. CurrentFilterEntry->FilterInstanceId = (ULONG)(PortPinWaveCyclic->m_Filter);
  620. // add the pin data to the pin entry
  621. CurrentPinEntry->PinData = (PVOID)PortPinWaveCyclic;
  622. // add the pin entry to the filter's pin list
  623. InsertTailList( &(CurrentFilterEntry->PinList),
  624. &(CurrentPinEntry->ListEntry) );
  625. /// add the filter entry to the port's filter list
  626. InsertTailList( &(SubdeviceEntry->Port.FilterList),
  627. &(CurrentFilterEntry->ListEntry) );
  628. }
  629. // allocate list entry storage
  630. TempListEntry = (PLIST_ENTRY)LocalAlloc( LPTR, sizeof(LIST_ENTRY) );
  631. if( TempListEntry )
  632. {
  633. // read in the next list entry
  634. if( !ReadMemory( (ULONG)Flink,
  635. TempListEntry,
  636. sizeof(LIST_ENTRY),
  637. &Result ) )
  638. {
  639. dprintf("** Unable to read temp list entry\n");
  640. LocalFree(TempListEntry);
  641. break;
  642. }
  643. // update FLINK
  644. Flink = TempListEntry->Flink;
  645. // free the temp list entry
  646. LocalFree( TempListEntry );
  647. } else
  648. {
  649. dprintf("** Unable to allocate temp list entry\n");
  650. break;
  651. }
  652. }
  653. }
  654. }
  655. break;
  656. case WavePci:
  657. {
  658. CPortWavePci *PortWavePci = (CPortWavePci *)Port;
  659. // get the filter and pin data
  660. if( Flags.FilterDump || Flags.PinDump )
  661. {
  662. ULONG Offset;
  663. ULONG PortBase;
  664. PLIST_ENTRY Flink;
  665. PLIST_ENTRY TempListEntry;
  666. ULONG PinNumber = 0;
  667. CPortPinWavePci *PortPinWavePci;
  668. CIrpStream *IrpStream;
  669. PCKD_PIN_ENTRY *CurrentPinEntry;
  670. BOOL NeedNewFilter;
  671. // get the offsets needed to walk the list
  672. Offset = FIELD_OFFSET(CPortWavePci,m_PinList);
  673. PortBase = (ULONG)((CPortWavePci *)((ISubdevice *)(SubdeviceEntry->CreateItem.Context)));
  674. // get the first pin pointer
  675. Flink = PortWavePci->m_PinList.Flink;
  676. while (Flink != PLIST_ENTRY(PortBase + Offset))
  677. {
  678. // allocate a pin list entry
  679. CurrentPinEntry = (PCKD_PIN_ENTRY *)LocalAlloc( LPTR, sizeof(PCKD_PIN_ENTRY) );
  680. if( !CurrentPinEntry )
  681. {
  682. dprintf("** Unable to allocate pin list entry\n");
  683. break;
  684. }
  685. // initialize the pin entry
  686. InitializeListHead( &(CurrentPinEntry->IrpList) );
  687. CurrentPinEntry->PinData = NULL;
  688. CurrentPinEntry->IrpStreamData = NULL;
  689. CurrentPinEntry->PinInstanceId = PinNumber++;
  690. // allocate local storage for the pin data
  691. PortPinWavePci = (CPortPinWavePci *)LocalAlloc( LPTR, sizeof(CPortPinWavePci) );
  692. if( !PortPinWavePci )
  693. {
  694. dprintf("** Unable to allocate pin data storage\n");
  695. LocalFree( CurrentPinEntry );
  696. break;
  697. }
  698. // read the pin data
  699. if( !ReadMemory( (ULONG)CONTAINING_RECORD(Flink,
  700. CPortPinWavePci,
  701. m_PinListEntry),
  702. PortPinWavePci,
  703. sizeof(CPortPinWavePci),
  704. &Result ) )
  705. {
  706. dprintf("** Unable to read pin data\n");
  707. LocalFree( PortPinWavePci );
  708. LocalFree( CurrentPinEntry );
  709. break;
  710. }
  711. // is there an irp stream
  712. if( PortPinWavePci->m_IrpStream )
  713. {
  714. // allocate local storage for the irp stream data
  715. IrpStream = (CIrpStream *)LocalAlloc( LPTR, sizeof(CIrpStream) );
  716. if( IrpStream )
  717. {
  718. // read the irp stream data
  719. if( !ReadMemory( (ULONG)((CIrpStream *)(PortPinWavePci->m_IrpStream)),
  720. IrpStream,
  721. sizeof(CIrpStream),
  722. &Result ) )
  723. {
  724. dprintf("** Unable to read irp stream data\n");
  725. LocalFree( IrpStream );
  726. } else
  727. {
  728. PCKD_AcquireIrpStreamData( CurrentPinEntry,
  729. (CIrpStream *)(PortPinWavePci->m_IrpStream),
  730. IrpStream );
  731. }
  732. } else
  733. {
  734. dprintf("** Unable to allocate irp stream storage\n");
  735. }
  736. }
  737. // we need a new filter unless we find it in the filter list
  738. NeedNewFilter = TRUE;
  739. // is the filter list empty?
  740. if( !IsListEmpty( &(SubdeviceEntry->Port.FilterList) ) )
  741. {
  742. PLIST_ENTRY FilterListEntry;
  743. for( FilterListEntry = SubdeviceEntry->Port.FilterList.Flink;
  744. FilterListEntry != &(SubdeviceEntry->Port.FilterList);
  745. FilterListEntry = FilterListEntry->Flink )
  746. {
  747. PCKD_FILTER_ENTRY *CurrentFilterEntry = (PCKD_FILTER_ENTRY *) FilterListEntry;
  748. if( CurrentFilterEntry->FilterInstanceId == (ULONG)(PortPinWavePci->Filter) )
  749. {
  750. // found our filter
  751. NeedNewFilter = FALSE;
  752. // add the pin data to the pin entry
  753. CurrentPinEntry->PinData = (PVOID)PortPinWavePci;
  754. // add the pin entry to the filter's pin list
  755. InsertTailList( &(CurrentFilterEntry->PinList),
  756. &(CurrentPinEntry->ListEntry) );
  757. }
  758. }
  759. }
  760. // do we need a new filter entry?
  761. if( NeedNewFilter )
  762. {
  763. PCKD_FILTER_ENTRY *CurrentFilterEntry;
  764. // allocate a new filter entry
  765. CurrentFilterEntry = (PCKD_FILTER_ENTRY *)LocalAlloc( LPTR, sizeof(PCKD_FILTER_ENTRY) );
  766. if(!CurrentFilterEntry)
  767. {
  768. dprintf("** Unable to allocate filter entry\n");
  769. LocalFree( PortPinWavePci );
  770. if( CurrentPinEntry->IrpStreamData )
  771. {
  772. LocalFree( CurrentPinEntry->IrpStreamData );
  773. }
  774. // free up any irps in the irp list
  775. while(!IsListEmpty( &(CurrentPinEntry->IrpList)))
  776. {
  777. PCKD_IRP_ENTRY *IrpEntry = (PCKD_IRP_ENTRY *)RemoveTailList(&(CurrentPinEntry->IrpList));
  778. LocalFree( IrpEntry );
  779. }
  780. LocalFree( CurrentPinEntry );
  781. break;
  782. }
  783. //initialize the new filter entry
  784. InitializeListHead( &(CurrentFilterEntry->PinList) );
  785. CurrentFilterEntry->FilterData = NULL;
  786. CurrentFilterEntry->FilterInstanceId = (ULONG)(PortPinWavePci->Filter);
  787. // add the pin data to the pin entry
  788. CurrentPinEntry->PinData = (PVOID)PortPinWavePci;
  789. // add the pin entry to the filter's pin list
  790. InsertTailList( &(CurrentFilterEntry->PinList),
  791. &(CurrentPinEntry->ListEntry) );
  792. /// add the filter entry to the port's filter list
  793. InsertTailList( &(SubdeviceEntry->Port.FilterList),
  794. &(CurrentFilterEntry->ListEntry) );
  795. }
  796. // allocate list entry storage
  797. TempListEntry = (PLIST_ENTRY)LocalAlloc( LPTR, sizeof(LIST_ENTRY) );
  798. if( TempListEntry )
  799. {
  800. // read in the next list entry
  801. if( !ReadMemory( (ULONG)Flink,
  802. TempListEntry,
  803. sizeof(LIST_ENTRY),
  804. &Result ) )
  805. {
  806. dprintf("** Unable to read temp list entry\n");
  807. LocalFree(TempListEntry);
  808. break;
  809. }
  810. // update FLINK
  811. Flink = TempListEntry->Flink;
  812. // free the temp list entry
  813. LocalFree( TempListEntry );
  814. } else
  815. {
  816. dprintf("** Unable to allocate temp list entry\n");
  817. break;
  818. }
  819. }
  820. }
  821. }
  822. break;
  823. case Midi:
  824. {
  825. CPortMidi *PortMidi = (CPortMidi *)Port;
  826. // get the filter and pin data
  827. if( Flags.FilterDump || Flags.PinDump )
  828. {
  829. ULONG PinIndex;
  830. CPortPinMidi *PortPinMidi;
  831. CIrpStream *IrpStream;
  832. PCKD_PIN_ENTRY *CurrentPinEntry;
  833. BOOL NeedNewFilter;
  834. for( PinIndex = 0; PinIndex < PortMidi->m_PinEntriesUsed; PinIndex++ )
  835. {
  836. if( PortMidi->m_Pins[ PinIndex] )
  837. {
  838. // allocate a pin list entry
  839. CurrentPinEntry = (PCKD_PIN_ENTRY *)LocalAlloc( LPTR, sizeof(PCKD_PIN_ENTRY) );
  840. if( !CurrentPinEntry )
  841. {
  842. dprintf("** Unable to allocate pin list entry\n");
  843. break;
  844. }
  845. // initialize the pin entry
  846. InitializeListHead( &(CurrentPinEntry->IrpList) );
  847. CurrentPinEntry->PinData = NULL;
  848. CurrentPinEntry->PinInstanceId = (ULONG)(PortMidi->m_Pins[ PinIndex ]);
  849. // allocate local storage for the pin data
  850. PortPinMidi = (CPortPinMidi *)LocalAlloc( LPTR, sizeof(CPortPinMidi) );
  851. if( !PortPinMidi )
  852. {
  853. dprintf("** Unable to allocate pin data storage\n");
  854. LocalFree( CurrentPinEntry );
  855. break;
  856. }
  857. // read the pin data
  858. if( !ReadMemory( (ULONG)(PortMidi->m_Pins[ PinIndex ]),
  859. PortPinMidi,
  860. sizeof(CPortPinMidi),
  861. &Result ) )
  862. {
  863. dprintf("** Unable to read pin data\n");
  864. LocalFree( PortPinMidi );
  865. LocalFree( CurrentPinEntry );
  866. break;
  867. }
  868. // is there an irp stream
  869. if( PortPinMidi->m_IrpStream )
  870. {
  871. // allocate local storage for the irp stream data
  872. IrpStream = (CIrpStream *)LocalAlloc( LPTR, sizeof(CIrpStream) );
  873. if( IrpStream )
  874. {
  875. // read the irp stream data
  876. if( !ReadMemory( (ULONG)(PortPinMidi->m_IrpStream),
  877. IrpStream,
  878. sizeof(CIrpStream),
  879. &Result ) )
  880. {
  881. dprintf("** Unable to read irp stream data\n");
  882. LocalFree( IrpStream );
  883. } else
  884. {
  885. PCKD_AcquireIrpStreamData( CurrentPinEntry,
  886. (CIrpStream *)(PortPinMidi->m_IrpStream),
  887. IrpStream );
  888. }
  889. } else
  890. {
  891. dprintf("** Unable to allocate irp stream storage\n");
  892. }
  893. }
  894. // we need a new filter unless we find it in the filter list
  895. NeedNewFilter = TRUE;
  896. // is the filter list empty?
  897. if( !IsListEmpty( &(SubdeviceEntry->Port.FilterList) ) )
  898. {
  899. PLIST_ENTRY FilterListEntry;
  900. for( FilterListEntry = SubdeviceEntry->Port.FilterList.Flink;
  901. FilterListEntry != &(SubdeviceEntry->Port.FilterList);
  902. FilterListEntry = FilterListEntry->Flink )
  903. {
  904. PCKD_FILTER_ENTRY *CurrentFilterEntry = (PCKD_FILTER_ENTRY *) FilterListEntry;
  905. if( CurrentFilterEntry->FilterInstanceId == (ULONG)(PortPinMidi->m_Filter) )
  906. {
  907. // found our filter
  908. NeedNewFilter = FALSE;
  909. // add the pin data to the pin entry
  910. CurrentPinEntry->PinData = (PVOID)PortPinMidi;
  911. // add the pin entry to the filter's pin list
  912. InsertTailList( &(CurrentFilterEntry->PinList),
  913. &(CurrentPinEntry->ListEntry) );
  914. }
  915. }
  916. }
  917. // do we need a new filter entry?
  918. if( NeedNewFilter )
  919. {
  920. PCKD_FILTER_ENTRY *CurrentFilterEntry;
  921. // allocate a new filter entry
  922. CurrentFilterEntry = (PCKD_FILTER_ENTRY *)LocalAlloc( LPTR, sizeof(PCKD_FILTER_ENTRY) );
  923. if(!CurrentFilterEntry)
  924. {
  925. dprintf("** Unable to allocate filter entry\n");
  926. LocalFree( PortPinMidi );
  927. if( CurrentPinEntry->IrpStreamData )
  928. {
  929. LocalFree( CurrentPinEntry->IrpStreamData );
  930. }
  931. // free up any irps in the irp list
  932. while(!IsListEmpty( &(CurrentPinEntry->IrpList)))
  933. {
  934. PCKD_IRP_ENTRY *IrpEntry = (PCKD_IRP_ENTRY *)RemoveTailList(&(CurrentPinEntry->IrpList));
  935. LocalFree( IrpEntry );
  936. }
  937. LocalFree( CurrentPinEntry );
  938. break;
  939. }
  940. //initialize the new filter entry
  941. InitializeListHead( &(CurrentFilterEntry->PinList) );
  942. CurrentFilterEntry->FilterData = NULL;
  943. CurrentFilterEntry->FilterInstanceId = (ULONG)(PortPinMidi->m_Filter);
  944. // add the pin data to the pin entry
  945. CurrentPinEntry->PinData = (PVOID)PortPinMidi;
  946. // add the pin entry to the filter's pin list
  947. InsertTailList( &(CurrentFilterEntry->PinList),
  948. &(CurrentPinEntry->ListEntry) );
  949. /// add the filter entry to the port's filter list
  950. InsertTailList( &(SubdeviceEntry->Port.FilterList),
  951. &(CurrentFilterEntry->ListEntry) );
  952. }
  953. }
  954. }
  955. }
  956. }
  957. break;
  958. default:
  959. break;
  960. }
  961. }
  962. }
  963. }
  964. /**********************************************************************
  965. * PCKD_DisplayDeviceData
  966. **********************************************************************
  967. * Description:
  968. * This routine displays the requested device data on the debugger
  969. * given a valid device context and a subdevice list built with
  970. * PCKD_AcquireDeviceData.
  971. * Arguments:
  972. * PDEVICE_CONTEXT DeviceContext
  973. * PLIST_ENTRY SubdeviceList
  974. * PORTCLS_FLAGS Flags
  975. *
  976. * Return Value:
  977. * None
  978. */
  979. VOID
  980. PCKD_DisplayDeviceData
  981. (
  982. PDEVICE_CONTEXT DeviceContext,
  983. PLIST_ENTRY SubdeviceList,
  984. ULONG flags
  985. )
  986. {
  987. PLIST_ENTRY SubdeviceListEntry;
  988. PCKD_SUBDEVICE_ENTRY *SubdeviceEntry;
  989. ANSI_STRING AnsiNameString;
  990. PORTCLS_FLAGS Flags;
  991. Flags.Flags = flags;
  992. dprintf("\n");
  993. // dump misc device context information
  994. if( Flags.DeviceContext )
  995. {
  996. dprintf("\n DEVICE INFO:\n");
  997. dprintf(" PDO: 0x%x\n",DeviceContext->PhysicalDeviceObject);
  998. if( Flags.Verbose )
  999. {
  1000. if( Flags.ReallyVerbose )
  1001. {
  1002. dprintf(" Max Objects: 0x%x\n",DeviceContext->MaxObjects);
  1003. }
  1004. dprintf(" Existing Objects: 0x%x\n",DeviceContext->ExistingObjectCount);
  1005. dprintf(" Active Pin Count: 0x%x\n",DeviceContext->ActivePinCount);
  1006. dprintf(" Pending IRP Count: 0x%x\n",DeviceContext->PendingIrpCount);
  1007. }
  1008. }
  1009. // dump power management information
  1010. if( Flags.PowerInfo )
  1011. {
  1012. dprintf("\n POWER INFO:\n");
  1013. dprintf(" DeviceState: %s\n", TranslateDevicePower( DeviceContext->CurrentDeviceState ) );
  1014. dprintf(" SystemState: %s\n", TranslateSystemPower( DeviceContext->CurrentSystemState ) );
  1015. dprintf(" AdapterPower: 0x%x\n", DeviceContext->pAdapterPower );
  1016. if( Flags.Verbose && Flags.ReallyVerbose )
  1017. {
  1018. ULONG index;
  1019. dprintf(" Idle Timer: 0x%x\n", DeviceContext->IdleTimer );
  1020. dprintf(" Cons Idle Time: 0x%x\n", DeviceContext->ConservationIdleTime );
  1021. dprintf(" Perf Idle Time: 0x%x\n", DeviceContext->PerformanceIdleTime );
  1022. dprintf(" Idle Device State: %s\n", TranslateDevicePower( DeviceContext->IdleDeviceState ) );
  1023. dprintf(" State Mappings:\n");
  1024. for( index = 0; index < (ULONG)PowerSystemMaximum; index++ )
  1025. {
  1026. dprintf(" %20s ==> %14s\n", TranslateSystemPower( index ),
  1027. TranslateDevicePower( DeviceContext->DeviceStateMap[ index ] ) );
  1028. }
  1029. }
  1030. }
  1031. // dump port/filter/pin information
  1032. if( Flags.PortDump || Flags.FilterDump || Flags.PinDump )
  1033. {
  1034. if( !IsListEmpty( SubdeviceList ) )
  1035. {
  1036. // go through the subdevice list
  1037. for( SubdeviceListEntry = SubdeviceList->Flink;
  1038. SubdeviceListEntry != SubdeviceList;
  1039. SubdeviceListEntry = SubdeviceListEntry->Flink )
  1040. {
  1041. SubdeviceEntry = (PCKD_SUBDEVICE_ENTRY *)SubdeviceListEntry;
  1042. switch( SubdeviceEntry->Port.PortType )
  1043. {
  1044. case Topology:
  1045. // dump port name
  1046. dprintf("\n TOPOLOGY PORT:\n");
  1047. break;
  1048. case WaveCyclic:
  1049. // dump port name
  1050. dprintf("\n WAVECYCLIC PORT:\n");
  1051. break;
  1052. case WavePci:
  1053. // dump port name
  1054. dprintf("\n WAVEPCI PORT:\n");
  1055. break;
  1056. case Midi:
  1057. // dump port name
  1058. dprintf("\n MIDI PORT:\n");
  1059. break;
  1060. default:
  1061. // dump port name
  1062. dprintf("\n UNKNOWN PORT:\n");
  1063. break;
  1064. }
  1065. // print out the real name
  1066. RtlUnicodeStringToAnsiString( &AnsiNameString,
  1067. &(SubdeviceEntry->CreateItem.ObjectClass),
  1068. TRUE );
  1069. dprintf(" Name: %s\n",AnsiNameString.Buffer);
  1070. RtlFreeAnsiString( &AnsiNameString );
  1071. // dump the port instance
  1072. dprintf(" Port Instance: 0x%x\n",SubdeviceEntry->CreateItem.Context);
  1073. if( Flags.Verbose && Flags.ReallyVerbose )
  1074. {
  1075. // dump generic port data
  1076. dprintf(" Create: 0x%x\n",SubdeviceEntry->CreateItem.Create);
  1077. dprintf(" Security: 0x%x\n",SubdeviceEntry->CreateItem.SecurityDescriptor);
  1078. dprintf(" Flags: 0x%x\n",SubdeviceEntry->CreateItem.Flags);
  1079. }
  1080. // dump port type specific port data
  1081. switch( SubdeviceEntry->Port.PortType )
  1082. {
  1083. case Topology:
  1084. {
  1085. CPortTopology *port = (CPortTopology *)(SubdeviceEntry->Port.PortData);
  1086. dprintf(" Miniport: 0x%x\n",port->Miniport);
  1087. if( Flags.Verbose && Flags.ReallyVerbose )
  1088. {
  1089. dprintf(" Subdevice Desc: 0x%x\n",port->m_pSubdeviceDescriptor);
  1090. dprintf(" Filter Desc: 0x%x\n",port->m_pPcFilterDescriptor);
  1091. }
  1092. }
  1093. break;
  1094. case WaveCyclic:
  1095. {
  1096. CPortWaveCyclic *port = (CPortWaveCyclic *)(SubdeviceEntry->Port.PortData);
  1097. dprintf(" Miniport: 0x%x\n",port->Miniport);
  1098. if( Flags.Verbose && Flags.ReallyVerbose )
  1099. {
  1100. dprintf(" Subdevice Desc: 0x%x\n",port->m_pSubdeviceDescriptor);
  1101. dprintf(" Filter Desc: 0x%x\n",port->m_pPcFilterDescriptor);
  1102. }
  1103. }
  1104. break;
  1105. case WavePci:
  1106. {
  1107. CPortWavePci *port = (CPortWavePci *)(SubdeviceEntry->Port.PortData);
  1108. dprintf(" Miniport: 0x%x\n",port->Miniport);
  1109. if( Flags.Verbose && Flags.ReallyVerbose )
  1110. {
  1111. dprintf(" Subdevice Desc: 0x%x\n",port->m_pSubdeviceDescriptor);
  1112. dprintf(" Filter Desc: 0x%x\n",port->m_pPcFilterDescriptor);
  1113. }
  1114. }
  1115. break;
  1116. case Midi:
  1117. {
  1118. CPortMidi *port = (CPortMidi *)(SubdeviceEntry->Port.PortData);
  1119. dprintf(" Miniport: 0x%x\n",port->m_Miniport);
  1120. if( Flags.Verbose && Flags.ReallyVerbose )
  1121. {
  1122. dprintf(" Subdevice Desc: 0x%x\n",port->m_pSubdeviceDescriptor);
  1123. dprintf(" Filter Desc: 0x%x\n",port->m_pPcFilterDescriptor);
  1124. }
  1125. dprintf(" Pin Count: 0x%x\n",port->m_PinEntriesUsed);
  1126. }
  1127. break;
  1128. default:
  1129. break;
  1130. }
  1131. if( Flags.FilterDump || Flags.PinDump )
  1132. {
  1133. // dump the filters
  1134. if( !IsListEmpty( &(SubdeviceEntry->Port.FilterList) ) )
  1135. {
  1136. PLIST_ENTRY FilterListEntry;
  1137. PCKD_FILTER_ENTRY *FilterEntry;
  1138. // run through the filter list
  1139. for( FilterListEntry = SubdeviceEntry->Port.FilterList.Flink;
  1140. FilterListEntry != &(SubdeviceEntry->Port.FilterList);
  1141. FilterListEntry = FilterListEntry->Flink )
  1142. {
  1143. FilterEntry = (PCKD_FILTER_ENTRY *)FilterListEntry;
  1144. dprintf(" Filter Instance: 0x%x\n",FilterEntry->FilterInstanceId);
  1145. if( Flags.PinDump )
  1146. {
  1147. // dump the pins
  1148. if( !IsListEmpty( &(FilterEntry->PinList) ) )
  1149. {
  1150. PLIST_ENTRY PinListEntry;
  1151. PCKD_PIN_ENTRY *PinEntry;
  1152. // run through the pin list
  1153. for( PinListEntry = FilterEntry->PinList.Flink;
  1154. PinListEntry != &(FilterEntry->PinList);
  1155. PinListEntry = PinListEntry->Flink )
  1156. {
  1157. PinEntry = (PCKD_PIN_ENTRY *)PinListEntry;
  1158. dprintf(" Pin Instance: 0x%x\n",PinEntry->PinInstanceId);
  1159. // dump the pin data
  1160. switch( SubdeviceEntry->Port.PortType )
  1161. {
  1162. case WaveCyclic:
  1163. {
  1164. CPortPinWaveCyclic *pin = (CPortPinWaveCyclic *)(PinEntry->PinData);
  1165. if( pin )
  1166. {
  1167. dprintf(" Miniport Stream: 0x%x\n",pin->m_Stream);
  1168. dprintf(" Stream State: %s\n", TranslateKsState(pin->m_DeviceState));
  1169. if( Flags.Verbose && Flags.ReallyVerbose )
  1170. {
  1171. dprintf(" Pin ID: 0x%x\n",pin->m_Id);
  1172. dprintf(" Commanded State: %s\n", TranslateKsState(pin->m_CommandedState));
  1173. dprintf(" Suspended: %s\n", pin->m_Suspended ? "TRUE" : "FALSE");
  1174. }
  1175. dprintf(" Dataflow: %s\n",TranslateKsDataFlow( pin->m_DataFlow ) );
  1176. dprintf(" Data Format: 0x%x\n",pin->m_DataFormat);
  1177. if( Flags.Verbose && Flags.ReallyVerbose )
  1178. {
  1179. dprintf(" Pin Desc: 0x%x\n",pin->m_Descriptor);
  1180. }
  1181. if( Flags.Verbose )
  1182. {
  1183. dprintf(" Service Group: 0x%x\n",pin->m_ServiceGroup);
  1184. dprintf(" Dma Channel: 0x%x\n",pin->m_DmaChannel);
  1185. dprintf(" Irp Stream: 0x%x\n",pin->m_IrpStream);
  1186. if( !IsListEmpty( &(PinEntry->IrpList) ) )
  1187. {
  1188. PLIST_ENTRY IrpListEntry;
  1189. PCKD_IRP_ENTRY *IrpEntry;
  1190. // run through the irp list
  1191. for( IrpListEntry = PinEntry->IrpList.Flink;
  1192. IrpListEntry != &(PinEntry->IrpList);
  1193. IrpListEntry = IrpListEntry->Flink )
  1194. {
  1195. IrpEntry = (PCKD_IRP_ENTRY *)IrpListEntry;
  1196. dprintf(" Irp: 0x%x (%s)\n",IrpEntry->Irp,
  1197. TranslateQueueType(IrpEntry->QueueType));
  1198. }
  1199. }
  1200. }
  1201. }
  1202. }
  1203. break;
  1204. case WavePci:
  1205. {
  1206. CPortPinWavePci *pin = (CPortPinWavePci *)(PinEntry->PinData);
  1207. if( pin )
  1208. {
  1209. dprintf(" Miniport Stream: 0x%x\n",pin->Stream);
  1210. dprintf(" Stream State: %s\n", TranslateKsState(pin->m_DeviceState));
  1211. if( Flags.Verbose && Flags.ReallyVerbose )
  1212. {
  1213. dprintf(" Pin ID: 0x%x\n",pin->Id);
  1214. dprintf(" Commanded State: %s\n", TranslateKsState(pin->CommandedState));
  1215. dprintf(" Suspended: %s\n", pin->m_Suspended ? "TRUE" : "FALSE");
  1216. }
  1217. //dprintf(" Dataflow: %s\n",TranslateKsDataFlow( pin->DataFlow ) );
  1218. dprintf(" Data Format: 0x%x\n",pin->DataFormat);
  1219. if( Flags.Verbose && Flags.ReallyVerbose )
  1220. {
  1221. dprintf(" Pin Desc: 0x%x\n",pin->Descriptor);
  1222. }
  1223. if( Flags.Verbose )
  1224. {
  1225. dprintf(" Service Group: 0x%x\n",pin->ServiceGroup);
  1226. dprintf(" Dma Channel: 0x%x\n",pin->DmaChannel);
  1227. dprintf(" Irp Stream: 0x%x\n",pin->m_IrpStream);
  1228. }
  1229. }
  1230. }
  1231. break;
  1232. case Midi:
  1233. {
  1234. CPortPinMidi *pin = (CPortPinMidi *)(PinEntry->PinData);
  1235. if( pin )
  1236. {
  1237. dprintf(" Miniport Stream: 0x%x\n",pin->m_Stream);
  1238. dprintf(" Stream State: %s\n", TranslateKsState(pin->m_DeviceState));
  1239. if( Flags.Verbose && Flags.ReallyVerbose )
  1240. {
  1241. dprintf(" Pin ID: 0x%x\n",pin->m_Id);
  1242. dprintf(" Commanded State: %s\n", TranslateKsState(pin->m_CommandedState));
  1243. dprintf(" Suspended: %s\n", pin->m_Suspended ? "TRUE" : "FALSE");
  1244. }
  1245. dprintf(" Dataflow: %s\n",TranslateKsDataFlow( pin->m_DataFlow ) );
  1246. dprintf(" Data Format: 0x%x\n",pin->m_DataFormat);
  1247. if( Flags.Verbose && Flags.ReallyVerbose )
  1248. {
  1249. dprintf(" Pin Desc: 0x%x\n",pin->m_Descriptor);
  1250. }
  1251. if( Flags.Verbose )
  1252. {
  1253. dprintf(" Service Group: 0x%x\n",pin->m_ServiceGroup);
  1254. dprintf(" Irp Stream: 0x%x\n",pin->m_IrpStream);
  1255. }
  1256. }
  1257. }
  1258. break;
  1259. default:
  1260. break;
  1261. }
  1262. }
  1263. } else
  1264. {
  1265. dprintf(" No Pin Instances:\n");
  1266. }
  1267. }
  1268. }
  1269. }
  1270. }
  1271. }
  1272. }
  1273. }
  1274. return;
  1275. }
  1276. /**********************************************************************
  1277. * PCKD_FreeDeviceData
  1278. **********************************************************************
  1279. * Description:
  1280. * This routine cleans up and frees the subdevice list.
  1281. * Arguments:
  1282. * PLIST_ENTRY SubdeviceList
  1283. *
  1284. * Return Value:
  1285. * None
  1286. */
  1287. VOID
  1288. PCKD_FreeDeviceData
  1289. (
  1290. PLIST_ENTRY SubdeviceList
  1291. )
  1292. {
  1293. PLIST_ENTRY SubdeviceListEntry;
  1294. PLIST_ENTRY FilterListEntry;
  1295. PLIST_ENTRY PinListEntry;
  1296. PCKD_SUBDEVICE_ENTRY *SubdeviceEntry;
  1297. PCKD_FILTER_ENTRY *FilterEntry;
  1298. PCKD_PIN_ENTRY *PinEntry;
  1299. if( !IsListEmpty( SubdeviceList ) )
  1300. {
  1301. SubdeviceListEntry = RemoveHeadList( SubdeviceList );
  1302. while( SubdeviceListEntry )
  1303. {
  1304. SubdeviceEntry = (PCKD_SUBDEVICE_ENTRY *) SubdeviceListEntry;
  1305. // see if we have filters in the filter list
  1306. if( !IsListEmpty( &(SubdeviceEntry->Port.FilterList) ) )
  1307. {
  1308. FilterListEntry = RemoveHeadList( &(SubdeviceEntry->Port.FilterList) );
  1309. while( FilterListEntry )
  1310. {
  1311. FilterEntry = (PCKD_FILTER_ENTRY *)FilterListEntry;
  1312. // see if we have pins in the pin list
  1313. if( !IsListEmpty( &(FilterEntry->PinList) ) )
  1314. {
  1315. PinListEntry = RemoveHeadList( &(FilterEntry->PinList) );
  1316. while( PinListEntry )
  1317. {
  1318. PinEntry = (PCKD_PIN_ENTRY *)PinListEntry;
  1319. // free the pin data
  1320. if( PinEntry->PinData )
  1321. {
  1322. LocalFree( PinEntry->PinData );
  1323. }
  1324. // free the irp stream data
  1325. if( PinEntry->IrpStreamData )
  1326. {
  1327. LocalFree( PinEntry->IrpStreamData );
  1328. }
  1329. // free up any irps in the irp list
  1330. while( !IsListEmpty( &(PinEntry->IrpList) ) )
  1331. {
  1332. PCKD_IRP_ENTRY *IrpEntry = (PCKD_IRP_ENTRY *)RemoveTailList(&(PinEntry->IrpList));
  1333. LocalFree( IrpEntry );
  1334. }
  1335. // free the pin entry
  1336. LocalFree( PinEntry );
  1337. // get the next pin
  1338. if( !IsListEmpty( &(FilterEntry->PinList) ) )
  1339. {
  1340. PinListEntry = RemoveTailList( &(FilterEntry->PinList) );
  1341. } else
  1342. {
  1343. PinListEntry = NULL;
  1344. }
  1345. }
  1346. }
  1347. // free the filter data
  1348. if( FilterEntry->FilterData )
  1349. {
  1350. LocalFree( FilterEntry->FilterData );
  1351. }
  1352. // free the filter entry
  1353. LocalFree( FilterEntry );
  1354. // get the next filter
  1355. if( !IsListEmpty( &(SubdeviceEntry->Port.FilterList) ) )
  1356. {
  1357. FilterListEntry = RemoveTailList( &(SubdeviceEntry->Port.FilterList) );
  1358. } else
  1359. {
  1360. FilterListEntry = NULL;
  1361. }
  1362. }
  1363. }
  1364. // free the port data
  1365. if( SubdeviceEntry->Port.PortData )
  1366. {
  1367. LocalFree( SubdeviceEntry->Port.PortData );
  1368. }
  1369. // free the unicode string buffer
  1370. LocalFree( SubdeviceEntry->CreateItem.ObjectClass.Buffer );
  1371. // free the subdevice entry
  1372. LocalFree( SubdeviceEntry );
  1373. // on to the next subdevice
  1374. if( !IsListEmpty( SubdeviceList ) )
  1375. {
  1376. SubdeviceListEntry = RemoveTailList( SubdeviceList );
  1377. } else
  1378. {
  1379. SubdeviceListEntry = NULL;
  1380. }
  1381. }
  1382. }
  1383. return;
  1384. }
  1385. /**********************************************************************
  1386. * PCKD_AcquireIrpStreamData
  1387. **********************************************************************
  1388. * Description:
  1389. * This routine acquires irp stream irp queue data.
  1390. * Arguments:
  1391. * PCKD_PIN_ENTRY *CurrentPinEntry
  1392. * CIrpStream *RemoteIrpStream,
  1393. * CIrpStream *LocalIrpStream
  1394. *
  1395. * Return Value:
  1396. * None
  1397. */
  1398. VOID
  1399. PCKD_AcquireIrpStreamData
  1400. (
  1401. PVOID PinEntry,
  1402. CIrpStream *RemoteIrpStream,
  1403. CIrpStream *LocalIrpStream
  1404. )
  1405. {
  1406. ULONG QueueType;
  1407. PLIST_ENTRY Flink;
  1408. PLIST_ENTRY TempListEntry;
  1409. PIRP pIrp;
  1410. PCKD_IRP_ENTRY *IrpEntry;
  1411. ULONG Offset;
  1412. ULONG Result;
  1413. PCKD_PIN_ENTRY *CurrentPinEntry;
  1414. CurrentPinEntry = (PCKD_PIN_ENTRY *)PinEntry;
  1415. // processs the queues
  1416. for( QueueType = MAPPED_QUEUE; QueueType < MAX_QUEUES; QueueType++ )
  1417. {
  1418. switch( QueueType )
  1419. {
  1420. case PRELOCK_QUEUE:
  1421. Offset = FIELD_OFFSET(CIrpStream,PreLockQueue);
  1422. Flink = LocalIrpStream->PreLockQueue.Flink;
  1423. break;
  1424. case LOCKED_QUEUE:
  1425. Offset = FIELD_OFFSET(CIrpStream,LockedQueue);
  1426. Flink = LocalIrpStream->LockedQueue.Flink;
  1427. break;
  1428. case MAPPED_QUEUE:
  1429. Offset = FIELD_OFFSET(CIrpStream,MappedQueue);
  1430. Flink = LocalIrpStream->MappedQueue.Flink;
  1431. break;
  1432. default:
  1433. Flink = 0;
  1434. break;
  1435. }
  1436. // walk the list (note we can't use IsListEmpty)
  1437. while( (Flink) && (Flink != (PLIST_ENTRY)((PBYTE)RemoteIrpStream + Offset)))
  1438. {
  1439. // get the irp pointer
  1440. pIrp = CONTAINING_RECORD( Flink, IRP, Tail.Overlay.ListEntry );
  1441. // allocate an irp entry
  1442. IrpEntry = (PCKD_IRP_ENTRY *)LocalAlloc( LPTR, sizeof(PCKD_IRP_ENTRY) );
  1443. if( IrpEntry )
  1444. {
  1445. // initialize the irp entry
  1446. IrpEntry->QueueType = QueueType;
  1447. IrpEntry->Irp = pIrp;
  1448. // add the irp entry to the pin entry
  1449. InsertTailList( &(CurrentPinEntry->IrpList),
  1450. &(IrpEntry->ListEntry) );
  1451. } else
  1452. {
  1453. dprintf("** Unable to allocate irp entry\n");
  1454. }
  1455. // allocate list entry storage
  1456. TempListEntry = (PLIST_ENTRY)LocalAlloc( LPTR, sizeof(LIST_ENTRY) );
  1457. if( TempListEntry )
  1458. {
  1459. // read in the next list entry
  1460. if( !ReadMemory( (ULONG)Flink,
  1461. TempListEntry,
  1462. sizeof(LIST_ENTRY),
  1463. &Result ) )
  1464. {
  1465. dprintf("** Unable to read temp list entry\n");
  1466. LocalFree(TempListEntry);
  1467. break;
  1468. }
  1469. // update FLINK
  1470. Flink = TempListEntry->Flink;
  1471. // free the temp list entry
  1472. LocalFree( TempListEntry );
  1473. } else
  1474. {
  1475. dprintf("** Unable to allocate temp list entry\n");
  1476. break;
  1477. }
  1478. }
  1479. }
  1480. }