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.

2213 lines
72 KiB

  1. ///////////////////////////////////////////////////////////////////////////
  2. //
  3. //
  4. // Copyright (c) 1996, 1997 Microsoft Corporation
  5. //
  6. //
  7. // Module Name:
  8. // mpe.c
  9. //
  10. // Abstract:
  11. //
  12. //
  13. // Author:
  14. //
  15. // P Porzuczek
  16. //
  17. // Environment:
  18. //
  19. // Revision History:
  20. //
  21. //
  22. //////////////////////////////////////////////////////////////////////////////
  23. #include <wdm.h>
  24. #include <strmini.h>
  25. #include <ksmedia.h>
  26. #include <BdaTypes.h>
  27. #include <BdaMedia.h>
  28. #include "Mpe.h"
  29. #include "MpeMedia.h"
  30. #include "MpeStream.h"
  31. #include "Recv.h"
  32. #include "Main.h"
  33. #include "filter.h"
  34. #pragma pack (1)
  35. typedef struct
  36. {
  37. BYTE table_id;
  38. USHORT section_syntax_indicator : 1;
  39. USHORT private_indicator: 1;
  40. USHORT reserved1: 2;
  41. USHORT section_length: 12;
  42. BYTE MAC_address_6;
  43. BYTE MAC_address_5;
  44. BYTE reserved2 : 2;
  45. BYTE payload_scrambling : 2;
  46. BYTE address_scrambling : 2;
  47. BYTE LLC_SNAP_flag : 1;
  48. BYTE current_next_indicator : 1;
  49. BYTE section_number;
  50. BYTE last_section_number;
  51. BYTE MAC_address_4;
  52. BYTE MAC_address_3;
  53. BYTE MAC_address_2;
  54. BYTE MAC_address_1;
  55. BYTE Data [0];
  56. } SECTION_HEADER, *PSECTION_HEADER;
  57. typedef struct
  58. {
  59. BYTE dsap;
  60. BYTE ssap;
  61. BYTE cntl;
  62. BYTE org [3];
  63. USHORT type;
  64. BYTE Data [0];
  65. } LLC_SNAP, *PLLC_SNAP;
  66. typedef struct
  67. {
  68. BYTE MAC_Dest_Address [6];
  69. BYTE MAC_Src_Address [6];
  70. USHORT usLength;
  71. } MAC_Address, *PMAC_Address;
  72. typedef struct _HEADER_IP_
  73. {
  74. UCHAR ucVersion_Length;
  75. UCHAR ucTOS;
  76. USHORT usLength;
  77. USHORT usId;
  78. USHORT usFlags_Offset;
  79. UCHAR ucTTL;
  80. UCHAR ucProtocol;
  81. USHORT usHdrChecksum;
  82. UCHAR ucSrcAddress [4];
  83. UCHAR ucDestAddress [4];
  84. } HEADER_IP, *PHEADER_IP;
  85. #pragma pack ()
  86. #define ES2(s) ((((s) >> 8) & 0x00FF) + (((s) << 8) & 0xFF00))
  87. //////////////////////////////////////////////////////////////////////////////
  88. BOOLEAN
  89. ValidSection (
  90. PSECTION_HEADER pSection
  91. )
  92. //////////////////////////////////////////////////////////////////////////////
  93. {
  94. if (pSection->table_id != 0x3E)
  95. {
  96. return FALSE;
  97. }
  98. return TRUE;
  99. }
  100. //////////////////////////////////////////////////////////////////////////////
  101. BOOLEAN
  102. ValidSnap (
  103. PLLC_SNAP pSnap
  104. )
  105. //////////////////////////////////////////////////////////////////////////////
  106. {
  107. if (pSnap->dsap != 0xAA)
  108. {
  109. return FALSE;
  110. }
  111. if (pSnap->ssap != 0xAA)
  112. {
  113. return FALSE;
  114. }
  115. if (pSnap->cntl != 0x03)
  116. {
  117. return FALSE;
  118. }
  119. if (pSnap->type != 0x0800)
  120. {
  121. return FALSE;
  122. }
  123. return TRUE;
  124. }
  125. //////////////////////////////////////////////////////////////////////////////
  126. VOID
  127. NormalizeSection (
  128. PBYTE pStream,
  129. PSECTION_HEADER pSection
  130. )
  131. //////////////////////////////////////////////////////////////////////////////
  132. {
  133. PBYTE pb = pStream;
  134. PUSHORT ps = (PUSHORT) pStream;
  135. if (pSection)
  136. {
  137. pSection->table_id = *pb;
  138. pb += 1;
  139. pSection->section_syntax_indicator = (*pb >> 7) & 0x01;
  140. pSection->private_indicator = (*pb >> 6 )& 0x01;
  141. pSection->reserved1 = (*pb >> 4) & 0x03;
  142. ps = (PUSHORT) pb;
  143. pSection->section_length = ES2 (*ps) & 0x0FFF;
  144. pb += 2;
  145. pSection->MAC_address_6 = *pb;
  146. pb += 1;
  147. pSection->MAC_address_5 = *pb;
  148. pb += 1;
  149. pSection->reserved2 = (*pb >> 6) & 0x03;
  150. pSection->payload_scrambling = (*pb >> 4) & 0x3;
  151. pSection->address_scrambling = (*pb >> 2) & 0x3;
  152. pSection->LLC_SNAP_flag = (*pb >> 1) & 0x01;
  153. pSection->current_next_indicator = *pb & 0x01;
  154. pb += 1;
  155. pSection->section_number = *pb;
  156. pb += 1;
  157. pSection->last_section_number = *pb;
  158. pb += 1;
  159. pSection->MAC_address_4 = *pb;
  160. pb += 1;
  161. pSection->MAC_address_3 = *pb;
  162. pb += 1;
  163. pSection->MAC_address_2 = *pb;
  164. pb += 1;
  165. pSection->MAC_address_1 = *pb;
  166. }
  167. return;
  168. }
  169. //////////////////////////////////////////////////////////////////////////////
  170. VOID
  171. NormalizeSnap (
  172. PBYTE pStream,
  173. PLLC_SNAP pSnap
  174. )
  175. //////////////////////////////////////////////////////////////////////////////
  176. {
  177. PUSHORT ps = (PUSHORT) pStream;
  178. if (pSnap)
  179. {
  180. pSnap->type = ES2 (pSnap->type);
  181. }
  182. return;
  183. }
  184. //////////////////////////////////////////////////////////////////////////////
  185. //
  186. //
  187. VOID
  188. DumpDataFormat (
  189. PKSDATAFORMAT pF
  190. );
  191. //////////////////////////////////////////////////////////////////////////////
  192. VOID
  193. MpeGetConnectionProperty(
  194. PHW_STREAM_REQUEST_BLOCK pSrb
  195. )
  196. //////////////////////////////////////////////////////////////////////////////
  197. {
  198. PSTREAM pStream = (PSTREAM)pSrb->StreamObject->HwStreamExtension;
  199. PSTREAM_PROPERTY_DESCRIPTOR pSPD = pSrb->CommandData.PropertyInfo;
  200. ULONG Id = pSPD->Property->Id; // index of the property
  201. ULONG ulStreamNumber = pSrb->StreamObject->StreamNumber;
  202. pSrb->ActualBytesTransferred = 0;
  203. switch (Id)
  204. {
  205. case KSPROPERTY_CONNECTION_ALLOCATORFRAMING:
  206. {
  207. PKSALLOCATOR_FRAMING Framing = (PKSALLOCATOR_FRAMING) pSPD->PropertyInfo;
  208. Framing->RequirementsFlags = KSALLOCATOR_REQUIREMENTF_SYSTEM_MEMORY |
  209. KSALLOCATOR_REQUIREMENTF_INPLACE_MODIFIER |
  210. KSALLOCATOR_REQUIREMENTF_PREFERENCES_ONLY;
  211. Framing->PoolType = NonPagedPool;
  212. Framing->Frames = 0;
  213. Framing->FrameSize = 0;
  214. Framing->FileAlignment = 0; // None OR FILE_QUAD_ALIGNMENT-1 OR PAGE_SIZE-1;
  215. Framing->Reserved = 0;
  216. switch (ulStreamNumber)
  217. {
  218. case MPE_IPV4:
  219. Framing->Frames = 16;
  220. Framing->FrameSize = pStream->OpenedFormat.SampleSize;
  221. pSrb->Status = STATUS_SUCCESS;
  222. break;
  223. case MPE_STREAM:
  224. Framing->Frames = 32;
  225. Framing->FrameSize = pStream->OpenedFormat.SampleSize;
  226. pSrb->Status = STATUS_SUCCESS;
  227. break;
  228. default:
  229. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  230. break;
  231. }
  232. pSrb->ActualBytesTransferred = sizeof (KSALLOCATOR_FRAMING);
  233. }
  234. break;
  235. default:
  236. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  237. break;
  238. }
  239. return;
  240. }
  241. //////////////////////////////////////////////////////////////////////////////
  242. NTSTATUS
  243. MpeDriverInitialize (
  244. IN PDRIVER_OBJECT DriverObject,
  245. IN PUNICODE_STRING RegistryPath
  246. )
  247. //////////////////////////////////////////////////////////////////////////////
  248. {
  249. NTSTATUS ntStatus = STATUS_SUCCESS;
  250. HW_INITIALIZATION_DATA HwInitData;
  251. UNICODE_STRING DeviceNameString;
  252. UNICODE_STRING SymbolicNameString;
  253. RtlZeroMemory(&HwInitData, sizeof(HwInitData));
  254. HwInitData.HwInitializationDataSize = sizeof(HwInitData);
  255. ////////////////////////////////////////////////////////////////
  256. //
  257. // Setup the stream class dispatch table
  258. //
  259. HwInitData.HwInterrupt = NULL; // HwInterrupt is only for HW devices
  260. HwInitData.HwReceivePacket = CodecReceivePacket;
  261. HwInitData.HwCancelPacket = CodecCancelPacket;
  262. HwInitData.HwRequestTimeoutHandler = CodecTimeoutPacket;
  263. HwInitData.DeviceExtensionSize = sizeof(MPE_FILTER);
  264. HwInitData.PerRequestExtensionSize = sizeof(SRB_EXTENSION);
  265. HwInitData.FilterInstanceExtensionSize = 0;
  266. HwInitData.PerStreamExtensionSize = sizeof(STREAM);
  267. HwInitData.BusMasterDMA = FALSE;
  268. HwInitData.Dma24BitAddresses = FALSE;
  269. HwInitData.BufferAlignment = 3;
  270. HwInitData.TurnOffSynchronization = TRUE;
  271. HwInitData.DmaBufferSize = 0;
  272. ntStatus = StreamClassRegisterAdapter (DriverObject, RegistryPath, &HwInitData);
  273. if (ntStatus != STATUS_SUCCESS)
  274. {
  275. goto ret;
  276. }
  277. ret:
  278. return ntStatus;
  279. }
  280. //
  281. //
  282. //////////////////////////////////////////////////////////////////////////////
  283. BOOLEAN
  284. CodecInitialize (
  285. IN OUT PHW_STREAM_REQUEST_BLOCK pSrb
  286. )
  287. //////////////////////////////////////////////////////////////////////////////
  288. {
  289. NTSTATUS ntStatus = STATUS_SUCCESS;
  290. BOOLEAN bStatus = FALSE;
  291. PPORT_CONFIGURATION_INFORMATION pConfigInfo = pSrb->CommandData.ConfigInfo;
  292. PMPE_FILTER pFilter = (PMPE_FILTER) pConfigInfo->HwDeviceExtension;
  293. //
  294. // Define the default return codes
  295. //
  296. pSrb->Status = STATUS_SUCCESS;
  297. bStatus = TRUE;
  298. //
  299. // Initialize Statistics block
  300. //
  301. RtlZeroMemory(&pFilter->Stats, sizeof (STATS));
  302. //
  303. // Check out init flag so we don't try to init more then once. The Streaming
  304. // Class driver appears to call the init handler several times for some reason.
  305. //
  306. if (pFilter->bInitializationComplete)
  307. {
  308. goto ret;
  309. }
  310. if (pConfigInfo->NumberOfAccessRanges == 0)
  311. {
  312. pConfigInfo->StreamDescriptorSize = sizeof (HW_STREAM_HEADER) +
  313. DRIVER_STREAM_COUNT * sizeof (HW_STREAM_INFORMATION);
  314. }
  315. else
  316. {
  317. pSrb->Status = STATUS_NO_SUCH_DEVICE;
  318. bStatus = FALSE;
  319. goto ret;
  320. }
  321. //
  322. // Create a filter object to represent our context
  323. //
  324. pSrb->Status = CreateFilter (pConfigInfo->ClassDeviceObject->DriverObject, pConfigInfo->ClassDeviceObject, pFilter);
  325. if (pSrb->Status != STATUS_SUCCESS)
  326. {
  327. bStatus = FALSE;
  328. goto ret;
  329. }
  330. pFilter->bInitializationComplete = TRUE;
  331. ret:
  332. return (bStatus);
  333. }
  334. //////////////////////////////////////////////////////////////////////////////
  335. BOOLEAN
  336. CodecUnInitialize (
  337. IN OUT PHW_STREAM_REQUEST_BLOCK pSrb
  338. )
  339. //////////////////////////////////////////////////////////////////////////////
  340. {
  341. NTSTATUS ntStatus = STATUS_SUCCESS;
  342. BOOLEAN bStatus = FALSE;
  343. PPORT_CONFIGURATION_INFORMATION pConfigInfo = pSrb->CommandData.ConfigInfo;
  344. PMPE_FILTER pFilter = ((PMPE_FILTER)pSrb->HwDeviceExtension);
  345. PSTREAM pStream = NULL;
  346. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: Codec Unitialize called\n"));
  347. if (pSrb->StreamObject != NULL)
  348. {
  349. pStream = (PSTREAM)pSrb->StreamObject->HwStreamExtension;
  350. }
  351. if (pStream)
  352. {
  353. //
  354. // Clean up the NAB_STREAM QUEUE used for deframing
  355. //
  356. //$$BUG
  357. //DeleteNabStreamQueue (pFilter);
  358. //
  359. // Clean up any queues we have and complete any outstanding SRB's
  360. //
  361. while (QueueRemove (&pSrb, &pFilter->StreamUserSpinLock, &pFilter->StreamContxList))
  362. {
  363. pSrb->Status = STATUS_CANCELLED;
  364. StreamClassStreamNotification (StreamRequestComplete, pSrb->StreamObject, pSrb);
  365. TEST_DEBUG( TEST_DBG_SRB, ("MPE 5Completed SRB %08X\n", pSrb));
  366. }
  367. while (QueueRemove (&pSrb, &pFilter->IpV4StreamDataSpinLock, &pFilter->IpV4StreamDataQueue))
  368. {
  369. pSrb->Status = STATUS_CANCELLED;
  370. StreamClassStreamNotification (StreamRequestComplete, pSrb->StreamObject, pSrb );
  371. TEST_DEBUG( TEST_DBG_SRB, ("MPE 6Completed SRB %08X\n", pSrb));
  372. }
  373. while (QueueRemove (&pSrb, &pFilter->StreamDataSpinLock, &pFilter->StreamDataQueue))
  374. {
  375. pSrb->Status = STATUS_CANCELLED;
  376. StreamClassStreamNotification (StreamRequestComplete, pSrb->StreamObject, pSrb );
  377. TEST_DEBUG( TEST_DBG_SRB, ("MPE 7Completed SRB %08X\n", pSrb));
  378. }
  379. while (QueueRemove (&pSrb, &pFilter->StreamControlSpinLock, &pFilter->StreamControlQueue))
  380. {
  381. pSrb->Status = STATUS_CANCELLED;
  382. StreamClassStreamNotification (StreamRequestComplete, pSrb->StreamObject, pSrb);
  383. TEST_DEBUG( TEST_DBG_SRB, ("MPE 8Completed SRB %08X\n", pSrb));
  384. }
  385. }
  386. while (QueueRemove (&pSrb, &pFilter->AdapterSRBSpinLock, &pFilter->AdapterSRBQueue))
  387. {
  388. pSrb->Status = STATUS_CANCELLED;
  389. StreamClassDeviceNotification (DeviceRequestComplete, pSrb->StreamObject, pSrb);
  390. TEST_DEBUG( TEST_DBG_RECV, ("MPE 9Completed SRB %08X\n", pSrb));
  391. }
  392. bStatus = TRUE;
  393. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: Codec Unitialize completed\n"));
  394. return (bStatus);
  395. }
  396. //////////////////////////////////////////////////////////////////////////////
  397. VOID
  398. CodecStreamInfo (
  399. PHW_STREAM_REQUEST_BLOCK pSrb
  400. )
  401. //////////////////////////////////////////////////////////////////////////////
  402. {
  403. int j;
  404. PMPE_FILTER pFilter =
  405. ((PMPE_FILTER)pSrb->HwDeviceExtension);
  406. //
  407. // pick up the pointer to header which preceeds the stream info structs
  408. //
  409. PHW_STREAM_HEADER pstrhdr =
  410. (PHW_STREAM_HEADER)&(pSrb->CommandData.StreamBuffer->StreamHeader);
  411. //
  412. // pick up the pointer to the array of stream information data structures
  413. //
  414. PHW_STREAM_INFORMATION pstrinfo =
  415. (PHW_STREAM_INFORMATION)&(pSrb->CommandData.StreamBuffer->StreamInfo);
  416. //
  417. // Set the header
  418. //
  419. StreamHeader.NumDevPropArrayEntries = 0;
  420. StreamHeader.DevicePropertiesArray = (PKSPROPERTY_SET)NULL;
  421. *pstrhdr = StreamHeader;
  422. //
  423. // stuff the contents of each HW_STREAM_INFORMATION struct
  424. //
  425. for (j = 0; j < DRIVER_STREAM_COUNT; j++)
  426. {
  427. *pstrinfo++ = Streams[j].hwStreamInfo;
  428. }
  429. pSrb->Status = STATUS_SUCCESS;
  430. }
  431. //////////////////////////////////////////////////////////////////////////////
  432. VOID
  433. STREAMAPI
  434. CodecCancelPacket(
  435. PHW_STREAM_REQUEST_BLOCK pSrb
  436. )
  437. //////////////////////////////////////////////////////////////////////////////
  438. {
  439. PSTREAM pStream = (PSTREAM)pSrb->StreamObject->HwStreamExtension;
  440. PMPE_FILTER pFilter = ((PMPE_FILTER)pSrb->HwDeviceExtension);
  441. //
  442. // Check whether the SRB to cancel is in use by this stream
  443. //
  444. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: CancelPacket Called\n"));
  445. //
  446. //$$BUG
  447. //
  448. //CancelNabStreamSrb (pFilter, pSrb);
  449. if (QueueRemoveSpecific (pSrb, &pFilter->IpV4StreamDataSpinLock, &pFilter->IpV4StreamDataQueue))
  450. {
  451. pSrb->Status = STATUS_CANCELLED;
  452. StreamClassStreamNotification (StreamRequestComplete, pSrb->StreamObject, pSrb );
  453. TEST_DEBUG( TEST_DBG_SRB, ("MPE 10Completed SRB %08X\n", pSrb));
  454. return;
  455. }
  456. if (QueueRemoveSpecific (pSrb, &pFilter->StreamDataSpinLock, &pFilter->StreamDataQueue))
  457. {
  458. pSrb->Status = STATUS_CANCELLED;
  459. StreamClassStreamNotification (StreamRequestComplete, pSrb->StreamObject, pSrb );
  460. TEST_DEBUG( TEST_DBG_SRB, ("MPE 11Completed SRB %08X\n", pSrb));
  461. return;
  462. }
  463. if (QueueRemoveSpecific (pSrb, &pFilter->StreamControlSpinLock, &pFilter->StreamControlQueue))
  464. {
  465. pSrb->Status = STATUS_CANCELLED;
  466. StreamClassStreamNotification (StreamRequestComplete, pSrb->StreamObject, pSrb);
  467. TEST_DEBUG( TEST_DBG_SRB, ("MPE 12Completed SRB %08X\n", pSrb));
  468. return;
  469. }
  470. if (QueueRemoveSpecific (pSrb, &pFilter->AdapterSRBSpinLock, &pFilter->AdapterSRBQueue))
  471. {
  472. pSrb->Status = STATUS_CANCELLED;
  473. StreamClassDeviceNotification (DeviceRequestComplete, pSrb->StreamObject, pSrb);
  474. TEST_DEBUG( TEST_DBG_SRB, ("MPE 13Completed SRB %08X\n", pSrb));
  475. return;
  476. }
  477. return;
  478. }
  479. //////////////////////////////////////////////////////////////////////////////
  480. VOID
  481. STREAMAPI
  482. CodecTimeoutPacket(
  483. PHW_STREAM_REQUEST_BLOCK pSrb
  484. )
  485. //////////////////////////////////////////////////////////////////////////////
  486. {
  487. //
  488. // if we timeout while playing, then we need to consider this
  489. // condition an error, and reset the hardware, and reset everything
  490. // as well as cancelling this and all requests
  491. //
  492. //
  493. // if we are not playing, and this is a CTRL request, we still
  494. // need to reset everything as well as cancelling this and all requests
  495. //
  496. //
  497. // if this is a data request, and the device is paused, we probably have
  498. // run out of data buffer, and need more time, so just reset the timer,
  499. // and let the packet continue
  500. //
  501. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: TimeoutPacket Called\n"));
  502. pSrb->TimeoutCounter = 0;
  503. return;
  504. }
  505. //////////////////////////////////////////////////////////////////////////////
  506. VOID
  507. STREAMAPI
  508. CodecReceivePacket(
  509. IN PHW_STREAM_REQUEST_BLOCK pSrb
  510. )
  511. //////////////////////////////////////////////////////////////////////////////
  512. {
  513. PMPE_FILTER pFilter = ((PMPE_FILTER)pSrb->HwDeviceExtension);
  514. //
  515. // Make sure queue & SL initted
  516. //
  517. if (!pFilter->bAdapterQueueInitialized)
  518. {
  519. InitializeListHead (&pFilter->AdapterSRBQueue);
  520. KeInitializeSpinLock (&pFilter->AdapterSRBSpinLock);
  521. pFilter->bAdapterQueueInitialized = TRUE;
  522. }
  523. //
  524. // Assume success
  525. //
  526. pSrb->Status = STATUS_SUCCESS;
  527. //
  528. // determine the type of packet.
  529. //
  530. QueueAdd (pSrb, &pFilter->AdapterSRBSpinLock, &pFilter->AdapterSRBQueue);
  531. TEST_DEBUG( TEST_DBG_SRB, ("MPE Queuing SRB %08X\n", pSrb));
  532. while (QueueRemove( &pSrb, &pFilter->AdapterSRBSpinLock, &pFilter->AdapterSRBQueue ))
  533. {
  534. switch (pSrb->Command)
  535. {
  536. case SRB_INITIALIZE_DEVICE:
  537. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: SRB_INITIALIZE Command\n"));
  538. CodecInitialize(pSrb);
  539. break;
  540. case SRB_UNINITIALIZE_DEVICE:
  541. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: SRB_UNINITIALIZE Command\n"));
  542. CodecUnInitialize(pSrb);
  543. break;
  544. case SRB_INITIALIZATION_COMPLETE:
  545. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: SRB_INITIALIZE_COMPLETE Command\n"));
  546. pSrb->Status = STATUS_SUCCESS;
  547. break;
  548. case SRB_OPEN_STREAM:
  549. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: SRB_OPEN_STREAM Command\n"));
  550. OpenStream (pSrb);
  551. break;
  552. case SRB_CLOSE_STREAM:
  553. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: SRB_CLOSE_STREAM Command\n"));
  554. CloseStream (pSrb);
  555. break;
  556. case SRB_GET_STREAM_INFO:
  557. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: SRB_GET_STREAM_INFO Command\n"));
  558. CodecStreamInfo (pSrb);
  559. break;
  560. case SRB_GET_DATA_INTERSECTION:
  561. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: SRB_GET_DATA_INTERSECTION Command\n"));
  562. //
  563. // Compare our stream formats. NOTE, the compare functions sets the SRB
  564. // status fields
  565. //
  566. CompareStreamFormat (pSrb);
  567. break;
  568. case SRB_OPEN_DEVICE_INSTANCE:
  569. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: SRB_OPEN_DEVICE_INSTANCE Command\n"));
  570. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  571. break;
  572. case SRB_CLOSE_DEVICE_INSTANCE:
  573. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: SRB_CLOSE_DEVICE_INSTANCE Command\n"));
  574. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  575. break;
  576. case SRB_UNKNOWN_DEVICE_COMMAND:
  577. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: SRB_UNKNOWN_DEVICE Command\n"));
  578. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  579. break;
  580. case SRB_CHANGE_POWER_STATE:
  581. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: SRB_CHANGE_POWER_STATE Command\n"));
  582. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  583. break;
  584. case SRB_GET_DEVICE_PROPERTY:
  585. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: SRB_GET_DEVICE_PROPERTY Command\n"));
  586. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  587. break;
  588. case SRB_SET_DEVICE_PROPERTY:
  589. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: SRB_SET_DEVICE_PROPERTY Command\n"));
  590. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  591. break;
  592. case SRB_UNKNOWN_STREAM_COMMAND:
  593. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: SRB_UNKNOWN Command\n"));
  594. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  595. break;
  596. default:
  597. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: SRB_DEFAULT Command\n"));
  598. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  599. break;
  600. };
  601. //
  602. // NOTE:
  603. //
  604. // All of the commands that we do, or do not understand can all be completed
  605. // syncronously at this point, so we can use a common callback routine here.
  606. // If any of the above commands require asyncronous processing, this will
  607. // have to change
  608. //
  609. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: SRB Status returned: %08X\n", pSrb->Status));
  610. StreamClassDeviceNotification (DeviceRequestComplete, pFilter, pSrb);
  611. TEST_DEBUG( TEST_DBG_SRB, ("MPE 14Completed SRB %08X\n", pSrb));
  612. }
  613. }
  614. //////////////////////////////////////////////////////////////////////////////
  615. BOOL STREAMAPI
  616. QueueAdd (
  617. IN PHW_STREAM_REQUEST_BLOCK pSrb,
  618. IN PKSPIN_LOCK pQueueSpinLock,
  619. IN PLIST_ENTRY pQueue
  620. )
  621. //////////////////////////////////////////////////////////////////////////////
  622. {
  623. KIRQL Irql;
  624. PSRB_EXTENSION pSrbExtension;
  625. pSrbExtension = ( PSRB_EXTENSION )pSrb->SRBExtension;
  626. KeAcquireSpinLock( pQueueSpinLock, &Irql );
  627. pSrbExtension->pSrb = pSrb;
  628. InsertTailList( pQueue, &pSrbExtension->ListEntry );
  629. KeReleaseSpinLock( pQueueSpinLock, Irql );
  630. return TRUE;
  631. }
  632. //////////////////////////////////////////////////////////////////////////////
  633. BOOL STREAMAPI
  634. QueuePush (
  635. IN PHW_STREAM_REQUEST_BLOCK pSrb,
  636. IN PKSPIN_LOCK pQueueSpinLock,
  637. IN PLIST_ENTRY pQueue
  638. )
  639. //////////////////////////////////////////////////////////////////////////////
  640. {
  641. KIRQL Irql;
  642. PSRB_EXTENSION pSrbExtension;
  643. pSrbExtension = ( PSRB_EXTENSION )pSrb->SRBExtension;
  644. KeAcquireSpinLock( pQueueSpinLock, &Irql );
  645. pSrbExtension->pSrb = pSrb;
  646. InsertHeadList( pQueue, &pSrbExtension->ListEntry );
  647. KeReleaseSpinLock( pQueueSpinLock, Irql );
  648. return TRUE;
  649. }
  650. //////////////////////////////////////////////////////////////////////////////
  651. BOOL STREAMAPI
  652. QueueAddIfNotEmpty (
  653. IN PHW_STREAM_REQUEST_BLOCK pSrb,
  654. IN PKSPIN_LOCK pQueueSpinLock,
  655. IN PLIST_ENTRY pQueue
  656. )
  657. //////////////////////////////////////////////////////////////////////////////
  658. {
  659. KIRQL Irql;
  660. PSRB_EXTENSION pSrbExtension;
  661. BOOL bAddedSRB = FALSE;
  662. pSrbExtension = ( PSRB_EXTENSION )pSrb->SRBExtension;
  663. KeAcquireSpinLock( pQueueSpinLock, &Irql );
  664. if( !IsListEmpty( pQueue ))
  665. {
  666. pSrbExtension->pSrb = pSrb;
  667. InsertTailList (pQueue, &pSrbExtension->ListEntry );
  668. bAddedSRB = TRUE;
  669. }
  670. KeReleaseSpinLock( pQueueSpinLock, Irql );
  671. return bAddedSRB;
  672. }
  673. //////////////////////////////////////////////////////////////////////////////
  674. BOOL STREAMAPI
  675. QueueRemove (
  676. IN OUT PHW_STREAM_REQUEST_BLOCK * pSrb,
  677. IN PKSPIN_LOCK pQueueSpinLock,
  678. IN PLIST_ENTRY pQueue
  679. )
  680. //////////////////////////////////////////////////////////////////////////////
  681. {
  682. KIRQL Irql;
  683. BOOL bRemovedSRB = FALSE;
  684. KeAcquireSpinLock (pQueueSpinLock, &Irql);
  685. *pSrb = (PHW_STREAM_REQUEST_BLOCK) NULL;
  686. if( !IsListEmpty( pQueue ))
  687. {
  688. PHW_STREAM_REQUEST_BLOCK *pCurrentSrb = NULL;
  689. PUCHAR Ptr = (PUCHAR) RemoveHeadList(pQueue);
  690. pCurrentSrb = (PHW_STREAM_REQUEST_BLOCK *) (((PUCHAR)Ptr) + sizeof (LIST_ENTRY));
  691. *pSrb = *pCurrentSrb;
  692. bRemovedSRB = TRUE;
  693. }
  694. KeReleaseSpinLock (pQueueSpinLock, Irql);
  695. return bRemovedSRB;
  696. }
  697. //////////////////////////////////////////////////////////////////////////////
  698. BOOL STREAMAPI
  699. QueueRemoveSpecific (
  700. IN PHW_STREAM_REQUEST_BLOCK pSrb,
  701. IN PKSPIN_LOCK pQueueSpinLock,
  702. IN PLIST_ENTRY pQueue
  703. )
  704. //////////////////////////////////////////////////////////////////////////////
  705. {
  706. KIRQL Irql;
  707. BOOL bRemovedSRB = FALSE;
  708. PLIST_ENTRY pCurrentEntry;
  709. PHW_STREAM_REQUEST_BLOCK * pCurrentSrb;
  710. KeAcquireSpinLock( pQueueSpinLock, &Irql );
  711. if( !IsListEmpty( pQueue ))
  712. {
  713. pCurrentEntry = pQueue->Flink;
  714. while ((pCurrentEntry != pQueue ) && !bRemovedSRB)
  715. {
  716. pCurrentSrb = (PHW_STREAM_REQUEST_BLOCK * ) ((( PUCHAR )pCurrentEntry ) + sizeof( LIST_ENTRY ));
  717. if( *pCurrentSrb == pSrb )
  718. {
  719. RemoveEntryList( pCurrentEntry );
  720. bRemovedSRB = TRUE;
  721. }
  722. pCurrentEntry = pCurrentEntry->Flink;
  723. }
  724. }
  725. KeReleaseSpinLock( pQueueSpinLock, Irql );
  726. return bRemovedSRB;
  727. }
  728. //////////////////////////////////////////////////////////////////////////////
  729. NTSTATUS
  730. StreamIPIndicateEvent (
  731. PVOID pvEvent
  732. )
  733. //////////////////////////////////////////////////////////////////////////////
  734. {
  735. return STATUS_NOT_IMPLEMENTED;
  736. }
  737. //////////////////////////////////////////////////////////////////////////////
  738. BOOL
  739. CompareGUIDsAndFormatSize(
  740. IN PKSDATARANGE pDataRange1,
  741. IN PKSDATARANGE pDataRange2,
  742. BOOLEAN bCheckSize
  743. )
  744. //////////////////////////////////////////////////////////////////////////////
  745. {
  746. BOOL bResult = FALSE;
  747. if ( IsEqualGUID(&pDataRange1->MajorFormat, &KSDATAFORMAT_TYPE_WILDCARD) ||
  748. IsEqualGUID(&pDataRange2->MajorFormat, &KSDATAFORMAT_TYPE_WILDCARD) ||
  749. IsEqualGUID(&pDataRange1->MajorFormat, &pDataRange2->MajorFormat) )
  750. {
  751. if ( IsEqualGUID(&pDataRange1->SubFormat, &KSDATAFORMAT_SUBTYPE_WILDCARD) ||
  752. IsEqualGUID(&pDataRange2->SubFormat, &KSDATAFORMAT_SUBTYPE_WILDCARD) ||
  753. IsEqualGUID(&pDataRange1->SubFormat, &pDataRange2->SubFormat) )
  754. {
  755. if ( IsEqualGUID(&pDataRange1->Specifier, &KSDATAFORMAT_SPECIFIER_WILDCARD) ||
  756. IsEqualGUID(&pDataRange2->Specifier, &KSDATAFORMAT_SPECIFIER_WILDCARD) ||
  757. IsEqualGUID(&pDataRange1->Specifier, &pDataRange2->Specifier) )
  758. {
  759. if ( !bCheckSize || pDataRange1->FormatSize == pDataRange2->FormatSize)
  760. {
  761. bResult = TRUE;
  762. }
  763. }
  764. }
  765. }
  766. return bResult;
  767. }
  768. //////////////////////////////////////////////////////////////////////////////
  769. VOID
  770. DumpDataFormat (
  771. PKSDATAFORMAT pF
  772. )
  773. //////////////////////////////////////////////////////////////////////////////
  774. {
  775. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: DATA Format\n"));
  776. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: Format Size: %08X\n", pF->FormatSize));
  777. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: Flags: %08X\n", pF->Flags));
  778. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: SampleSize: %08X\n", pF->SampleSize));
  779. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: Reserved: %08X\n", pF->Reserved));
  780. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: Major GUID: %08X %04X %04X %02X %02X %02X %02X %02X %02X %02X %02X\n",
  781. pF->MajorFormat.Data1,
  782. pF->MajorFormat.Data2,
  783. pF->MajorFormat.Data3,
  784. pF->MajorFormat.Data4[0],
  785. pF->MajorFormat.Data4[1],
  786. pF->MajorFormat.Data4[2],
  787. pF->MajorFormat.Data4[3],
  788. pF->MajorFormat.Data4[4],
  789. pF->MajorFormat.Data4[5],
  790. pF->MajorFormat.Data4[6],
  791. pF->MajorFormat.Data4[7]
  792. ));
  793. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: Sub GUID: %08X %04X %04X %02X %02X %02X %02X %02X %02X %02X %02X\n",
  794. pF->SubFormat.Data1,
  795. pF->SubFormat.Data2,
  796. pF->SubFormat.Data3,
  797. pF->SubFormat.Data4[0],
  798. pF->SubFormat.Data4[1],
  799. pF->SubFormat.Data4[2],
  800. pF->SubFormat.Data4[3],
  801. pF->SubFormat.Data4[4],
  802. pF->SubFormat.Data4[5],
  803. pF->SubFormat.Data4[6],
  804. pF->SubFormat.Data4[7]
  805. ));
  806. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: Specifier: %08X %04X %04X %02X %02X %02X %02X %02X %02X %02X %02X\n",
  807. pF->Specifier.Data1,
  808. pF->Specifier.Data2,
  809. pF->Specifier.Data3,
  810. pF->Specifier.Data4[0],
  811. pF->Specifier.Data4[1],
  812. pF->Specifier.Data4[2],
  813. pF->Specifier.Data4[3],
  814. pF->Specifier.Data4[4],
  815. pF->Specifier.Data4[5],
  816. pF->Specifier.Data4[6],
  817. pF->Specifier.Data4[7]
  818. ));
  819. TEST_DEBUG (TEST_DBG_TRACE, ("\n"));
  820. }
  821. //////////////////////////////////////////////////////////////////////////////
  822. BOOL
  823. CompareStreamFormat (
  824. IN PHW_STREAM_REQUEST_BLOCK pSrb
  825. )
  826. //////////////////////////////////////////////////////////////////////////////
  827. {
  828. BOOL bStatus = FALSE;
  829. PSTREAM_DATA_INTERSECT_INFO pIntersectInfo;
  830. PKSDATARANGE pDataRange1;
  831. PKSDATARANGE pDataRange2;
  832. ULONG FormatSize = 0;
  833. ULONG ulStreamNumber;
  834. ULONG j;
  835. ULONG ulNumberOfFormatArrayEntries;
  836. PKSDATAFORMAT *pAvailableFormats;
  837. pIntersectInfo = pSrb->CommandData.IntersectInfo;
  838. ulStreamNumber = pIntersectInfo->StreamNumber;
  839. pSrb->ActualBytesTransferred = 0;
  840. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: Comparing Stream Formats\n"));
  841. //
  842. // Check that the stream number is valid
  843. //
  844. if (ulStreamNumber < DRIVER_STREAM_COUNT)
  845. {
  846. ulNumberOfFormatArrayEntries = Streams[ulStreamNumber].hwStreamInfo.NumberOfFormatArrayEntries;
  847. //
  848. // Get the pointer to the array of available formats
  849. //
  850. pAvailableFormats = Streams[ulStreamNumber].hwStreamInfo.StreamFormatsArray;
  851. //
  852. // Walk the formats supported by the stream searching for a match
  853. // of the three GUIDs which together define a DATARANGE
  854. //
  855. for (pDataRange1 = pIntersectInfo->DataRange, j = 0;
  856. j < ulNumberOfFormatArrayEntries;
  857. j++, pAvailableFormats++)
  858. {
  859. bStatus = FALSE;
  860. pSrb->Status = STATUS_UNSUCCESSFUL;
  861. pDataRange2 = *pAvailableFormats;
  862. if (CompareGUIDsAndFormatSize (pDataRange1, pDataRange2, TRUE))
  863. {
  864. ULONG ulFormatSize = pDataRange2->FormatSize;
  865. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: Stream Formats compare\n"));
  866. //
  867. // Is the caller trying to get the format, or the size of the format?
  868. //
  869. if (pIntersectInfo->SizeOfDataFormatBuffer == sizeof (ULONG))
  870. {
  871. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: Returning Stream Format size\n"));
  872. *(PULONG) pIntersectInfo->DataFormatBuffer = ulFormatSize;
  873. pSrb->ActualBytesTransferred = sizeof (ULONG);
  874. pSrb->Status = STATUS_SUCCESS;
  875. bStatus = TRUE;
  876. }
  877. else
  878. {
  879. //
  880. // Verify that there is enough room in the supplied buffer for the whole thing
  881. //
  882. pSrb->Status = STATUS_BUFFER_TOO_SMALL;
  883. bStatus = FALSE;
  884. if (pIntersectInfo->SizeOfDataFormatBuffer >= ulFormatSize)
  885. {
  886. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: Returning Stream Format\n"));
  887. RtlCopyMemory (pIntersectInfo->DataFormatBuffer, pDataRange2, ulFormatSize);
  888. pSrb->ActualBytesTransferred = ulFormatSize;
  889. pSrb->Status = STATUS_SUCCESS;
  890. bStatus = TRUE;
  891. }
  892. else
  893. {
  894. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: Stream Format return buffer too small\n"));
  895. }
  896. }
  897. break;
  898. }
  899. else
  900. {
  901. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: Stream Formats DO NOT compare\n"));
  902. }
  903. }
  904. if ( j >= ulNumberOfFormatArrayEntries )
  905. {
  906. pSrb->ActualBytesTransferred = 0;
  907. pSrb->Status = STATUS_UNSUCCESSFUL;
  908. bStatus = FALSE;
  909. }
  910. }
  911. else
  912. {
  913. pSrb->ActualBytesTransferred = 0;
  914. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  915. bStatus = FALSE;
  916. }
  917. return bStatus;
  918. }
  919. //////////////////////////////////////////////////////////////////////////////
  920. VOID
  921. CloseStream (
  922. PHW_STREAM_REQUEST_BLOCK pSrb
  923. )
  924. //////////////////////////////////////////////////////////////////////////////
  925. {
  926. //
  927. // the stream extension structure is allocated by the stream class driver
  928. //
  929. PSTREAM pStream = (PSTREAM)pSrb->StreamObject->HwStreamExtension;
  930. PMPE_FILTER pFilter = (PMPE_FILTER)pSrb->HwDeviceExtension;
  931. ULONG ulStreamNumber = (ULONG) pSrb->StreamObject->StreamNumber;
  932. ULONG ulStreamInstance = pStream->ulStreamInstance;
  933. PHW_STREAM_REQUEST_BLOCK pCurrentSrb = NULL;
  934. //
  935. // check that the stream index requested isn't too high
  936. // or that the maximum number of instances hasn't been exceeded
  937. //
  938. if (ulStreamNumber < DRIVER_STREAM_COUNT )
  939. {
  940. //
  941. // Flush the stream data queue
  942. //
  943. while (QueueRemove( &pCurrentSrb, &pFilter->IpV4StreamDataSpinLock, &pFilter->IpV4StreamDataQueue))
  944. {
  945. pCurrentSrb->Status = STATUS_CANCELLED;
  946. StreamClassStreamNotification( StreamRequestComplete, pCurrentSrb->StreamObject, pCurrentSrb);
  947. TEST_DEBUG( TEST_DBG_SRB, ("MPE 15Completed SRB %08X\n", pCurrentSrb));
  948. }
  949. //
  950. // Flush the stream data queue
  951. //
  952. while (QueueRemove( &pCurrentSrb, &pFilter->StreamDataSpinLock, &pFilter->StreamDataQueue))
  953. {
  954. pCurrentSrb->Status = STATUS_CANCELLED;
  955. StreamClassStreamNotification( StreamRequestComplete, pCurrentSrb->StreamObject, pCurrentSrb);
  956. TEST_DEBUG( TEST_DBG_SRB, ("MPE 16Completed SRB %08X\n", pCurrentSrb));
  957. }
  958. //
  959. // Flush the stream control queue
  960. //
  961. while (QueueRemove( &pCurrentSrb, &pFilter->StreamControlSpinLock, &pFilter->StreamControlQueue))
  962. {
  963. pCurrentSrb->Status = STATUS_CANCELLED;
  964. StreamClassStreamNotification (StreamRequestComplete, pCurrentSrb->StreamObject, pCurrentSrb);
  965. TEST_DEBUG( TEST_DBG_SRB, ("MPE 17Completed SRB %08X\n", pCurrentSrb));
  966. }
  967. //
  968. // Clear this streams spot in the filters stream array
  969. //
  970. pFilter->pStream[ulStreamNumber][ulStreamInstance] = NULL;
  971. //
  972. // decrement the stream instance count for this filter
  973. //
  974. pFilter->ulActualInstances[ulStreamNumber]--;
  975. //
  976. // Indicate the clock support available on this stream
  977. //
  978. //pSrb->StreamObject->HwClockObject = 0;
  979. //
  980. // Reset the stream state to stopped
  981. //
  982. pStream->KSState = KSSTATE_STOP;
  983. //
  984. //
  985. //
  986. pStream->hMasterClock = NULL;
  987. //
  988. // Cleanup the streams transform buffer
  989. //
  990. if (pStream->pTransformBuffer)
  991. {
  992. ExFreePool (pStream->pTransformBuffer);
  993. pStream->pTransformBuffer = NULL;
  994. }
  995. //
  996. // Reset the stream extension blob
  997. //
  998. RtlZeroMemory(pStream, sizeof (STREAM));
  999. pSrb->Status = STATUS_SUCCESS;
  1000. }
  1001. else
  1002. {
  1003. pSrb->Status = STATUS_INVALID_PARAMETER;
  1004. }
  1005. }
  1006. //////////////////////////////////////////////////////////////////////////////
  1007. VOID
  1008. OpenStream (
  1009. PHW_STREAM_REQUEST_BLOCK pSrb
  1010. )
  1011. //////////////////////////////////////////////////////////////////////////////
  1012. {
  1013. //
  1014. // the stream extension structure is allocated by the stream class driver
  1015. //
  1016. PSTREAM pStream = (PSTREAM)pSrb->StreamObject->HwStreamExtension;
  1017. PMPE_FILTER pFilter = ((PMPE_FILTER)pSrb->HwDeviceExtension);
  1018. ULONG ulStreamNumber = (ULONG) pSrb->StreamObject->StreamNumber;
  1019. PKSDATAFORMAT pKSDataFormat = (PKSDATAFORMAT)pSrb->CommandData.OpenFormat;
  1020. //
  1021. // Initialize the stream extension blob
  1022. //
  1023. //RtlZeroMemory(pStream, sizeof (STREAM));
  1024. //
  1025. // Initialize stream state
  1026. //
  1027. //pStream->KSState = KSSTATE_STOP;
  1028. //
  1029. // Initialize the next stream life check time.
  1030. //
  1031. KeQuerySystemTime( &pFilter->liLastTimeChecked );
  1032. //
  1033. // check that the stream index requested isn't too high
  1034. // or that the maximum number of instances hasn't been exceeded
  1035. //
  1036. if (ulStreamNumber < DRIVER_STREAM_COUNT )
  1037. {
  1038. ULONG ulStreamInstance;
  1039. ULONG ulMaxInstances = Streams[ulStreamNumber].hwStreamInfo.NumberOfPossibleInstances;
  1040. //
  1041. // Search for next open slot
  1042. //
  1043. for (ulStreamInstance = 0; ulStreamInstance < ulMaxInstances; ++ulStreamInstance)
  1044. {
  1045. if (pFilter->pStream[ulStreamNumber][ulStreamInstance] == NULL)
  1046. {
  1047. break;
  1048. }
  1049. }
  1050. if (ulStreamInstance < ulMaxInstances)
  1051. {
  1052. if (VerifyFormat(pKSDataFormat, ulStreamNumber, &pStream->MatchedFormat))
  1053. {
  1054. //
  1055. // Initialize Data queues and SpinLocks
  1056. //
  1057. InitializeListHead(&pFilter->StreamControlQueue);
  1058. KeInitializeSpinLock(&pFilter->StreamControlSpinLock);
  1059. InitializeListHead(&pFilter->StreamDataQueue);
  1060. KeInitializeSpinLock(&pFilter->StreamDataSpinLock);
  1061. InitializeListHead(&pFilter->IpV4StreamDataQueue);
  1062. KeInitializeSpinLock(&pFilter->IpV4StreamDataSpinLock);
  1063. InitializeListHead(&pFilter->StreamContxList);
  1064. KeInitializeSpinLock(&pFilter->StreamUserSpinLock);
  1065. //
  1066. // Maintain an array of all the StreamEx structures in the HwDevExt
  1067. // so that we can reference IRPs from any stream
  1068. //
  1069. pFilter->pStream[ulStreamNumber][ulStreamInstance] = pStream;
  1070. //
  1071. // Save the Stream Format in the Stream Extension as well.
  1072. //
  1073. pStream->OpenedFormat = *pKSDataFormat;
  1074. //
  1075. // Set up pointers to the handlers for the stream data and control handlers
  1076. //
  1077. pSrb->StreamObject->ReceiveDataPacket =
  1078. (PVOID) Streams[ulStreamNumber].hwStreamObject.ReceiveDataPacket;
  1079. pSrb->StreamObject->ReceiveControlPacket =
  1080. (PVOID) Streams[ulStreamNumber].hwStreamObject.ReceiveControlPacket;
  1081. //
  1082. // The DMA flag must be set when the device will be performing DMA directly
  1083. // to the data buffer addresses passed in to the ReceiveDataPacket routines.
  1084. //
  1085. pSrb->StreamObject->Dma = Streams[ulStreamNumber].hwStreamObject.Dma;
  1086. //
  1087. // The PIO flag must be set when the mini driver will be accessing the data
  1088. // buffers passed in using logical addressing
  1089. //
  1090. pSrb->StreamObject->Pio = Streams[ulStreamNumber].hwStreamObject.Pio;
  1091. pSrb->StreamObject->Allocator = Streams[ulStreamNumber].hwStreamObject.Allocator;
  1092. //
  1093. // How many extra bytes will be passed up from the driver for each frame?
  1094. //
  1095. pSrb->StreamObject->StreamHeaderMediaSpecific =
  1096. Streams[ulStreamNumber].hwStreamObject.StreamHeaderMediaSpecific;
  1097. pSrb->StreamObject->StreamHeaderWorkspace =
  1098. Streams[ulStreamNumber].hwStreamObject.StreamHeaderWorkspace;
  1099. //
  1100. // Indicate the clock support available on this stream
  1101. //
  1102. pSrb->StreamObject->HwClockObject =
  1103. Streams[ulStreamNumber].hwStreamObject.HwClockObject;
  1104. //
  1105. // Increment the instance count on this stream
  1106. //
  1107. pStream->ulStreamInstance = ulStreamInstance;
  1108. pFilter->ulActualInstances[ulStreamNumber]++;
  1109. //
  1110. // Allocate a transform buffer
  1111. //
  1112. pStream->pTransformBuffer = ExAllocatePool (NonPagedPool, sizeof(SECTION_HEADER) + 4096);
  1113. if (pStream->pTransformBuffer == NULL)
  1114. {
  1115. pSrb->Status = STATUS_NO_MEMORY;
  1116. return;
  1117. }
  1118. RtlZeroMemory (pStream->pTransformBuffer, sizeof(SECTION_HEADER) + 4096);
  1119. //
  1120. // Initalize persistent pointer to output buffer to NULL
  1121. //
  1122. pStream->pOut = NULL;
  1123. //
  1124. // Initialize the exepected section number to zero
  1125. //
  1126. pStream->bExpectedSection = 0;
  1127. //
  1128. // Retain a private copy of the HwDevExt and StreamObject in the stream extension
  1129. // so we can use a timer
  1130. //
  1131. pStream->pFilter = pFilter; // For timer use
  1132. pStream->pStreamObject = pSrb->StreamObject; // For timer use
  1133. pSrb->Status = STATUS_SUCCESS;
  1134. }
  1135. else
  1136. {
  1137. pSrb->Status = STATUS_INVALID_PARAMETER;
  1138. }
  1139. }
  1140. else
  1141. {
  1142. pSrb->Status = STATUS_INVALID_PARAMETER;
  1143. }
  1144. }
  1145. else
  1146. {
  1147. pSrb->Status = STATUS_INVALID_PARAMETER;
  1148. }
  1149. }
  1150. //////////////////////////////////////////////////////////////////////////////
  1151. BOOLEAN
  1152. VerifyFormat(
  1153. IN KSDATAFORMAT *pKSDataFormat,
  1154. UINT StreamNumber,
  1155. PKSDATARANGE pMatchedFormat
  1156. )
  1157. //////////////////////////////////////////////////////////////////////////////
  1158. {
  1159. BOOLEAN bResult = FALSE;
  1160. ULONG FormatCount = 0;
  1161. PKS_DATARANGE_VIDEO pThisFormat = NULL;
  1162. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: Verify Format\n"));
  1163. for (FormatCount = 0; !bResult && FormatCount < Streams[StreamNumber].hwStreamInfo.NumberOfFormatArrayEntries;
  1164. FormatCount++ )
  1165. {
  1166. pThisFormat = (PKS_DATARANGE_VIDEO) Streams [StreamNumber].hwStreamInfo.StreamFormatsArray [FormatCount];
  1167. if (CompareGUIDsAndFormatSize( pKSDataFormat, &pThisFormat->DataRange, FALSE ) )
  1168. {
  1169. bResult = FALSE;
  1170. if (pThisFormat->DataRange.SampleSize >= pKSDataFormat->SampleSize)
  1171. {
  1172. bResult = TRUE;
  1173. }
  1174. else
  1175. {
  1176. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: VerifyFormat: Data range Sample Sizes don't match\n"));
  1177. }
  1178. }
  1179. }
  1180. if (bResult == TRUE && pMatchedFormat)
  1181. {
  1182. *pMatchedFormat = pThisFormat->DataRange;
  1183. }
  1184. return bResult;
  1185. }
  1186. ///////////////////////////////////////////////////////////////////////////////////////
  1187. NTSTATUS
  1188. GetOutputBuffer (
  1189. PMPE_FILTER pFilter,
  1190. PHW_STREAM_REQUEST_BLOCK *ppSrb,
  1191. PUCHAR *ppBuffer,
  1192. PULONG pulSize
  1193. )
  1194. ///////////////////////////////////////////////////////////////////////////////////////
  1195. {
  1196. NTSTATUS status = STATUS_INSUFFICIENT_RESOURCES;
  1197. PKSSTREAM_HEADER pStreamHdr = NULL;
  1198. PHW_STREAM_REQUEST_BLOCK pSrb = NULL;
  1199. if (QueueRemove( &pSrb, &pFilter->IpV4StreamDataSpinLock, &pFilter->IpV4StreamDataQueue))
  1200. {
  1201. pStreamHdr = pSrb->CommandData.DataBufferArray;
  1202. *ppSrb = pSrb;
  1203. *ppBuffer = pStreamHdr->Data;
  1204. *pulSize = pStreamHdr->FrameExtent;
  1205. status = STATUS_SUCCESS;
  1206. }
  1207. return status;
  1208. }
  1209. //////////////////////////////////////////////////////////////////////////////
  1210. VOID
  1211. STREAMAPI
  1212. ReceiveDataPacket (
  1213. IN PHW_STREAM_REQUEST_BLOCK pSrb
  1214. )
  1215. //////////////////////////////////////////////////////////////////////////////
  1216. {
  1217. PMPE_FILTER pFilter = (PMPE_FILTER) pSrb->HwDeviceExtension;
  1218. PSTREAM pStream = (PSTREAM)pSrb->StreamObject->HwStreamExtension;
  1219. int iStream = (int) pSrb->StreamObject->StreamNumber;
  1220. PKSSTREAM_HEADER pStreamHdr = pSrb->CommandData.DataBufferArray;
  1221. PKSDATAFORMAT pKSDataFormat = (PKSDATAFORMAT) &pStream->MatchedFormat;
  1222. ULONG ul = 0;
  1223. PHW_STREAM_REQUEST_BLOCK pOutSrb = NULL;
  1224. SECTION_HEADER Section = {0};
  1225. PSECTION_HEADER pSection = NULL;
  1226. PUCHAR pIn = NULL;
  1227. PLLC_SNAP pSnap = NULL;
  1228. ULONG ulSize = 0;
  1229. ULONG ulLength = 0;
  1230. PHEADER_IP pIP = NULL;
  1231. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: Receive Data packet handler called\n"));
  1232. //
  1233. // Default to success, disable timeouts
  1234. //
  1235. pSrb->TimeoutCounter = 0;
  1236. pSrb->Status = STATUS_SUCCESS;
  1237. //
  1238. // Check for last buffer
  1239. //
  1240. if (pStreamHdr->OptionsFlags & KSSTREAM_HEADER_OPTIONSF_ENDOFSTREAM)
  1241. {
  1242. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: Receive Data packet is LAST PACKET\n"));
  1243. StreamClassStreamNotification (StreamRequestComplete, pSrb->StreamObject, pSrb);
  1244. TEST_DEBUG( TEST_DBG_SRB, ("MPE 18Completed SRB %08X\n", pSrb));
  1245. return;
  1246. }
  1247. if (pStreamHdr->OptionsFlags != 0)
  1248. {
  1249. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: OptionsFlags: %08X\n", pStreamHdr->OptionsFlags));
  1250. }
  1251. //
  1252. // determine the type of packet.
  1253. //
  1254. switch (pSrb->Command)
  1255. {
  1256. case SRB_WRITE_DATA:
  1257. if (pStream->KSState == KSSTATE_STOP)
  1258. {
  1259. pSrb->Status = STATUS_SUCCESS;
  1260. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: SRB_WRITE STOP SRB Status returned: %08X\n", pSrb->Status));
  1261. StreamClassStreamNotification (StreamRequestComplete, pSrb->StreamObject, pSrb );
  1262. TEST_DEBUG( TEST_DBG_SRB, ("MPE 19Completed SRB %08X\n", pSrb));
  1263. break;
  1264. }
  1265. //
  1266. // Update the total number of packets written statistic
  1267. //
  1268. pFilter->Stats.ulTotalSectionsWritten += 1;
  1269. //
  1270. // Handle data input, output requests differently.
  1271. //
  1272. switch (iStream)
  1273. {
  1274. //
  1275. // Frame input stream
  1276. //
  1277. case MPE_STREAM:
  1278. {
  1279. ULONG ulBuffers = pSrb->NumberOfBuffers;
  1280. ULONG ulSkip = 0;
  1281. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: Receive Data packet handler - SRB_WRITE - MPE_STREAM\n"));
  1282. //
  1283. // Initialize SRB Status to success
  1284. //
  1285. pSrb->Status = STATUS_SUCCESS;
  1286. //
  1287. // copy the contents of all buffers into one big buffer
  1288. //
  1289. ASSERT( ulBuffers == 1);
  1290. for (ul = 0; ul < ulBuffers; ul++, pStreamHdr++)
  1291. {
  1292. ASSERT( pStreamHdr);
  1293. ASSERT( pStreamHdr->DataUsed <= (sizeof(SECTION_HEADER) + 4096));
  1294. if ( pStreamHdr
  1295. && (pStreamHdr->DataUsed <= (sizeof(SECTION_HEADER) + 4096))
  1296. )
  1297. {
  1298. //
  1299. // Copy the data
  1300. //
  1301. RtlCopyMemory (pStream->pTransformBuffer,
  1302. pStreamHdr->Data,
  1303. pStreamHdr->DataUsed
  1304. );
  1305. }
  1306. }
  1307. //
  1308. // Process the transform buffer
  1309. //
  1310. pSection = (PSECTION_HEADER) pStream->pTransformBuffer;
  1311. NormalizeSection (pStream->pTransformBuffer, &Section);
  1312. //
  1313. // Do a quick check of the section header to confirm it looks valid
  1314. //
  1315. if (! ValidSection (&Section))
  1316. {
  1317. // Ignore non-MPE sections
  1318. //
  1319. StreamClassStreamNotification (StreamRequestComplete, pSrb->StreamObject, pSrb);
  1320. pStream->bExpectedSection = 0;
  1321. pFilter->Stats.ulTotalInvalidSections += 1;
  1322. //
  1323. // Since we're discarding the data at this point, we'll re-queue the output
  1324. // SRB and re-use it when we get re-synched.
  1325. //
  1326. if (pOutSrb)
  1327. {
  1328. //$REVIEW - Can this cause out of order completion of sections.
  1329. //
  1330. QueuePush (pOutSrb, &pFilter->IpV4StreamDataSpinLock, &pFilter->IpV4StreamDataQueue);
  1331. }
  1332. pStream->pOut = NULL;
  1333. pOutSrb = NULL;
  1334. TEST_DEBUG( TEST_DBG_SRB, ("MPE 20Completed SRB %08X\n - Invalid TableID", pSrb));
  1335. break;
  1336. }
  1337. //
  1338. // Update our UnNormalized section header with our normalized one.
  1339. //
  1340. RtlCopyMemory (pStream->pTransformBuffer, &Section, sizeof (SECTION_HEADER));
  1341. //
  1342. // Check our section number and see if it's what we expect
  1343. //
  1344. if (pSection->section_number != pStream->bExpectedSection)
  1345. {
  1346. StreamClassStreamNotification (StreamRequestComplete, pSrb->StreamObject, pSrb);
  1347. pStream->bExpectedSection = 0;
  1348. pFilter->Stats.ulTotalUnexpectedSections += 1;
  1349. //
  1350. // Since we're discarding the data at this point, we'll re-queue the output
  1351. // SRB and re-use it when we get re-synched.
  1352. //
  1353. if (pOutSrb)
  1354. {
  1355. //$REVIEW - Can this cause out of order completion of sections.
  1356. //
  1357. QueuePush (pOutSrb, &pFilter->IpV4StreamDataSpinLock, &pFilter->IpV4StreamDataQueue);
  1358. }
  1359. pStream->pOut = NULL;
  1360. pOutSrb = NULL;
  1361. TEST_DEBUG( TEST_DBG_SRB, ("MPE 20Completed SRB %08X\n - Invalid section_number", pSrb));
  1362. break;
  1363. }
  1364. //
  1365. // Process the 1st section
  1366. //
  1367. if (pSection->section_number == 0)
  1368. {
  1369. PMAC_Address pMAC = NULL;
  1370. //
  1371. // Initialize packet length to zero
  1372. //
  1373. ulLength = 0;
  1374. //
  1375. //
  1376. //
  1377. if (GetOutputBuffer (pFilter, &pOutSrb, &pStream->pOut, &ulSize) != STATUS_SUCCESS)
  1378. {
  1379. //
  1380. // Failure....no buffers available most likely
  1381. //
  1382. pFilter->Stats.ulTotalUnavailableOutputBuffers += 1;
  1383. StreamClassStreamNotification (StreamRequestComplete, pSrb->StreamObject, pSrb);
  1384. TEST_DEBUG( TEST_DBG_SRB, ("MPE 20Completed SRB %08X\n - Can't get SRB for output pin", pSrb));
  1385. break;
  1386. }
  1387. if (ulSize < (pSection->section_length - (sizeof (SECTION_HEADER) - 3)))
  1388. {
  1389. StreamClassStreamNotification (StreamRequestComplete, pSrb->StreamObject, pSrb);
  1390. pStream->bExpectedSection = 0;
  1391. pFilter->Stats.ulTotalOutputBuffersTooSmall += 1;
  1392. //
  1393. // Since we're discarding the data at this point, we'll re-queue the output
  1394. // SRB and re-use it when we get re-synched.
  1395. //
  1396. if (pOutSrb)
  1397. {
  1398. //$REVIEW - Can this cause out of order completion of sections.
  1399. //
  1400. QueuePush (pOutSrb, &pFilter->IpV4StreamDataSpinLock, &pFilter->IpV4StreamDataQueue);
  1401. }
  1402. pStream->pOut = NULL;
  1403. pOutSrb = NULL;
  1404. TEST_DEBUG( TEST_DBG_SRB, ("MPE 20Completed SRB %08X\n - Section too big", pSrb));
  1405. break;
  1406. }
  1407. pIP = (PHEADER_IP) pSection->Data;
  1408. if (pSection->LLC_SNAP_flag == 0x1)
  1409. {
  1410. pSnap = (PLLC_SNAP) pSection->Data;
  1411. pIP = (PHEADER_IP) pSnap->Data;
  1412. ulSkip = sizeof( LLC_SNAP);
  1413. }
  1414. //
  1415. // Add the MAC address to the buffer. The MAC address prefix's the IP packet
  1416. //
  1417. pMAC = (PMAC_Address) pStream->pOut;
  1418. pMAC->MAC_Dest_Address [0] = pSection->MAC_address_1;
  1419. pMAC->MAC_Dest_Address [1] = pSection->MAC_address_2;
  1420. pMAC->MAC_Dest_Address [2] = pSection->MAC_address_3;
  1421. pMAC->MAC_Dest_Address [3] = pSection->MAC_address_4;
  1422. pMAC->MAC_Dest_Address [4] = pSection->MAC_address_5;
  1423. pMAC->MAC_Dest_Address [5] = pSection->MAC_address_6;
  1424. pMAC->MAC_Src_Address [0] = 0x00;
  1425. pMAC->MAC_Src_Address [1] = 0x00;
  1426. pMAC->MAC_Src_Address [2] = 0x00;
  1427. pMAC->MAC_Src_Address [3] = 0x00;
  1428. pMAC->MAC_Src_Address [4] = 0x00;
  1429. pMAC->MAC_Src_Address [5] = 0x00;
  1430. pMAC->usLength = 0x0008;
  1431. //
  1432. // Adjust pointer to output buffer where we'll put data
  1433. //
  1434. pStream->pOut += sizeof (MAC_Address);
  1435. pIn = pSection->Data;
  1436. if (pSection->LLC_SNAP_flag == 0x1)
  1437. {
  1438. pSnap = (PLLC_SNAP) pSection->Data;
  1439. if (pSnap->type != 0x0008)
  1440. {
  1441. StreamClassStreamNotification (StreamRequestComplete, pSrb->StreamObject, pSrb);
  1442. //
  1443. // Next expected Section should be zero
  1444. //
  1445. pStream->bExpectedSection = 0;
  1446. pFilter->Stats.ulTotalInvalidIPSnapHeaders += 1;
  1447. //
  1448. // Since we're discarding the data at this point, we'll re-queue the output
  1449. // SRB and re-use it when we get re-synched.
  1450. //
  1451. if (pOutSrb)
  1452. {
  1453. //$REVIEW - Can this cause out of order completion of sections.
  1454. //
  1455. QueuePush (pOutSrb, &pFilter->IpV4StreamDataSpinLock, &pFilter->IpV4StreamDataQueue);
  1456. }
  1457. pStream->pOut = NULL;
  1458. pOutSrb = NULL;
  1459. TEST_DEBUG( TEST_DBG_SRB, ("MPE 20Completed SRB %08X\n - Bad Snap Type", pSrb));
  1460. break;
  1461. }
  1462. pIn = pSnap->Data;
  1463. }
  1464. ulLength = sizeof (MAC_Address);
  1465. }
  1466. //
  1467. // pOut should be NULL unless we've found the 1st section.
  1468. //
  1469. if (pStream->pOut)
  1470. {
  1471. ULONG ulTmp = 0;
  1472. PKSSTREAM_HEADER pOutStreamHdr;
  1473. //
  1474. // Update the datasize field of the Output SRB
  1475. //
  1476. pOutStreamHdr = (PKSSTREAM_HEADER) pOutSrb->CommandData.DataBufferArray;
  1477. //
  1478. // Copy data from transform section to output SRB buffer
  1479. //
  1480. // Compute the number of bytes to copy. We subtract of 9 bytes
  1481. // only if this is a LLSNAP packet.
  1482. //
  1483. ulTmp = pSection->section_length;
  1484. ulTmp -= ulSkip;
  1485. RtlCopyMemory (pStream->pOut, pIn, ulTmp);
  1486. ulLength += ulTmp;
  1487. pOutStreamHdr->DataUsed += ulLength;
  1488. ulLength = 0;
  1489. }
  1490. if (pSection->section_number == pSection->last_section_number)
  1491. {
  1492. pFilter->Stats.ulTotalIPPacketsWritten += 1;
  1493. pOutSrb->Status = STATUS_SUCCESS;
  1494. StreamClassStreamNotification (StreamRequestComplete, pOutSrb->StreamObject, pOutSrb);
  1495. TEST_DEBUG( TEST_DBG_SRB, ("MPE 20Completed SRB %08X\n", pSrb));
  1496. pOutSrb = NULL;
  1497. pStream->pOut = NULL;
  1498. ulSize = 0;
  1499. }
  1500. StreamClassStreamNotification (StreamRequestComplete, pSrb->StreamObject, pSrb);
  1501. TEST_DEBUG( TEST_DBG_SRB, ("MPE 20Completed SRB %08X\n - Packet Sent", pSrb));
  1502. }
  1503. break;
  1504. default:
  1505. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: Receive Data packet handler called - SRB_WRITE - Default\n"));
  1506. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  1507. //
  1508. // Update stats for Unkown packet count
  1509. //
  1510. pFilter->Stats.ulTotalUnknownPacketsWritten += 1;
  1511. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: DEFAULT SRB Status returned: %08X\n", pSrb->Status));
  1512. StreamClassStreamNotification (StreamRequestComplete, pSrb->StreamObject, pSrb);
  1513. TEST_DEBUG( TEST_DBG_SRB, ("MPE 22Completed SRB %08X\n", pSrb));
  1514. break;
  1515. }
  1516. break;
  1517. case SRB_READ_DATA:
  1518. if (pStream->KSState == KSSTATE_STOP)
  1519. {
  1520. pSrb->Status = STATUS_SUCCESS;
  1521. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: SRB_READ STOP SRB Status returned: %08X\n", pSrb->Status));
  1522. StreamClassStreamNotification (StreamRequestComplete, pSrb->StreamObject, pSrb );
  1523. TEST_DEBUG( TEST_DBG_SRB, ("MPE 23Completed SRB %08X\n", pSrb));
  1524. break;
  1525. }
  1526. //
  1527. // Update stats for Unkown packet count
  1528. //
  1529. pFilter->Stats.ulTotalPacketsRead += 1;
  1530. switch (iStream)
  1531. {
  1532. #ifdef OLD
  1533. case MPE_NET_CONTROL:
  1534. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: Receive Data packet handler called - SRB_READ - STREAM_NET_CONTROL\n"));
  1535. pSrb->Status = STATUS_SUCCESS;
  1536. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: MPE_NET_CONTROL SRB Status returned: %08X\n", pSrb->Status));
  1537. StreamClassStreamNotification (StreamRequestComplete, pSrb->StreamObject, pSrb);
  1538. TEST_DEBUG( TEST_DBG_SRB, ("MPE 24Completed SRB %08X\n", pSrb));
  1539. break;
  1540. #endif
  1541. case MPE_IPV4:
  1542. {
  1543. ULONG ulBuffers = pSrb->NumberOfBuffers;
  1544. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: Receive Data packet handler called - SRB_READ - MPE_IPV4\n"));
  1545. if (pSrb->CommandData.DataBufferArray->FrameExtent < pKSDataFormat->SampleSize)
  1546. {
  1547. pSrb->Status = STATUS_BUFFER_TOO_SMALL;
  1548. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: MPE_IPV4 SRB Buffer too small.... Status returned: %08X\n", pSrb->Status));
  1549. StreamClassStreamNotification(StreamRequestComplete, pSrb->StreamObject, pSrb);
  1550. TEST_DEBUG( TEST_DBG_SRB, ("MPE 25Completed SRB %08X\n", pSrb));
  1551. }
  1552. else
  1553. {
  1554. //
  1555. // Take the SRB we get and queue it up. These Queued SRB's will be filled with data on a WRITE_DATA
  1556. // request, at which point they will be completed.
  1557. //
  1558. QueueAdd (pSrb, &pFilter->IpV4StreamDataSpinLock, &pFilter->IpV4StreamDataQueue);
  1559. TEST_DEBUG( TEST_DBG_SRB, ("MPE Queuing IPv4 SRB %08X\n", pSrb));
  1560. //
  1561. // Since the stream state may have changed while we were adding the SRB to the queue
  1562. // we'll check it again, and cancel it if necessary
  1563. //
  1564. if (pStream->KSState == KSSTATE_STOP)
  1565. {
  1566. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: SRB_READ STOP SRB Status returned: %08X\n", pSrb->Status));
  1567. if (QueueRemoveSpecific (pSrb, &pFilter->IpV4StreamDataSpinLock, &pFilter->IpV4StreamDataQueue))
  1568. {
  1569. pSrb->Status = STATUS_CANCELLED;
  1570. StreamClassStreamNotification (StreamRequestComplete, pSrb->StreamObject, pSrb );
  1571. TEST_DEBUG( TEST_DBG_SRB, ("MPE 26Completed SRB %08X\n", pSrb));
  1572. return;
  1573. }
  1574. break;
  1575. }
  1576. }
  1577. }
  1578. break;
  1579. default:
  1580. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: Receive Data packet handler called - SRB_READ - Default\n"));
  1581. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  1582. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: DEFAULT SRB Status returned: %08X\n", pSrb->Status));
  1583. StreamClassStreamNotification (StreamRequestComplete, pSrb->StreamObject, pSrb);
  1584. TEST_DEBUG( TEST_DBG_SRB, ("MPE 27Completed SRB %08X\n", pSrb));
  1585. break;
  1586. }
  1587. break;
  1588. default:
  1589. //
  1590. // invalid / unsupported command. Fail it as such
  1591. //
  1592. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: Receive Data packet handler called - Unsupported Command\n"));
  1593. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  1594. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: DEFAULT SRB Status returned: %08X\n", pSrb->Status));
  1595. StreamClassStreamNotification( StreamRequestComplete, pSrb->StreamObject, pSrb );
  1596. TEST_DEBUG( TEST_DBG_SRB, ("MPE 28Completed SRB %08X\n", pSrb));
  1597. ASSERT (FALSE);
  1598. break;
  1599. }
  1600. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: Receive Data packet handler called...status: %08X\n", pSrb->Status));
  1601. return;
  1602. }
  1603. //////////////////////////////////////////////////////////////////////////////
  1604. VOID
  1605. MpeGetProperty (
  1606. PHW_STREAM_REQUEST_BLOCK pSrb
  1607. )
  1608. //////////////////////////////////////////////////////////////////////////////
  1609. {
  1610. PSTREAM_PROPERTY_DESCRIPTOR pSPD = pSrb->CommandData.PropertyInfo;
  1611. pSrb->Status = STATUS_SUCCESS;
  1612. if (IsEqualGUID (&KSPROPSETID_Connection, &pSPD->Property->Set))
  1613. {
  1614. MpeGetConnectionProperty (pSrb);
  1615. }
  1616. else
  1617. {
  1618. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  1619. }
  1620. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: MpeGetProperty Status: %08X\n", pSrb->Status));
  1621. return;
  1622. }
  1623. //////////////////////////////////////////////////////////////////////////////
  1624. VOID
  1625. IndicateMasterClock(
  1626. PHW_STREAM_REQUEST_BLOCK pSrb
  1627. )
  1628. //////////////////////////////////////////////////////////////////////////////
  1629. {
  1630. PSTREAM pStream = (PSTREAM) pSrb->StreamObject->HwStreamExtension;
  1631. pStream->hClock = pSrb->CommandData.MasterClockHandle;
  1632. }
  1633. //////////////////////////////////////////////////////////////////////////////
  1634. VOID
  1635. STREAMAPI
  1636. ReceiveCtrlPacket(
  1637. IN PHW_STREAM_REQUEST_BLOCK pSrb
  1638. )
  1639. //////////////////////////////////////////////////////////////////////////////
  1640. {
  1641. PMPE_FILTER pFilter = (PMPE_FILTER) pSrb->HwDeviceExtension;
  1642. PSTREAM pStream = (PSTREAM) pSrb->StreamObject->HwStreamExtension;
  1643. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: Receive Control packet handler called\n"));
  1644. pSrb->Status = STATUS_SUCCESS;
  1645. QueueAdd (pSrb, &pFilter->StreamControlSpinLock, &pFilter->StreamControlQueue);
  1646. TEST_DEBUG( TEST_DBG_SRB, ("MPE Queuing Control Packet SRB %08X\n", pSrb));
  1647. while (QueueRemove (&pSrb, &pFilter->StreamControlSpinLock, &pFilter->StreamControlQueue))
  1648. {
  1649. //
  1650. // determine the type of packet.
  1651. //
  1652. switch (pSrb->Command)
  1653. {
  1654. case SRB_PROPOSE_DATA_FORMAT:
  1655. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: Receive Control packet handler - Propose data format\n"));
  1656. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  1657. break;
  1658. case SRB_SET_STREAM_STATE:
  1659. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: Receive Control packet handler - Set Stream State\n"));
  1660. pSrb->Status = STATUS_SUCCESS;
  1661. MpeSetState (pSrb);
  1662. break;
  1663. case SRB_GET_STREAM_STATE:
  1664. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: Receive Control packet handler - Get Stream State\n"));
  1665. pSrb->Status = STATUS_SUCCESS;
  1666. pSrb->CommandData.StreamState = pStream->KSState;
  1667. pSrb->ActualBytesTransferred = sizeof (KSSTATE);
  1668. break;
  1669. case SRB_GET_STREAM_PROPERTY:
  1670. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: Receive Control packet handler - Get Stream Property\n"));
  1671. MpeGetProperty(pSrb);
  1672. break;
  1673. case SRB_SET_STREAM_PROPERTY:
  1674. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: Receive Control packet handler - Set Stream Property\n"));
  1675. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  1676. break;
  1677. case SRB_INDICATE_MASTER_CLOCK:
  1678. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: Receive Control packet handler - Indicate Master Clock\n"));
  1679. pSrb->Status = STATUS_SUCCESS;
  1680. IndicateMasterClock (pSrb);
  1681. break;
  1682. case SRB_SET_STREAM_RATE:
  1683. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: Receive Control packet handler - Set Stream Rate\n"));
  1684. pSrb->Status = STATUS_SUCCESS;
  1685. break;
  1686. case SRB_PROPOSE_STREAM_RATE:
  1687. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: Receive Control packet handler - Propose Stream Rate\n"));
  1688. pSrb->Status = STATUS_SUCCESS;
  1689. break;
  1690. default:
  1691. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: Receive Control packet handler - Default case\n"));
  1692. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  1693. break;
  1694. }
  1695. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: SRB Status returned: %08X\n", pSrb->Status));
  1696. StreamClassStreamNotification (StreamRequestComplete, pSrb->StreamObject, pSrb);
  1697. TEST_DEBUG( TEST_DBG_SRB, ("MPE 29Completed SRB %08X\n", pSrb));
  1698. }
  1699. }
  1700. //////////////////////////////////////////////////////////////////////////////
  1701. VOID
  1702. MpeSetState(
  1703. PHW_STREAM_REQUEST_BLOCK pSrb
  1704. )
  1705. //////////////////////////////////////////////////////////////////////////////
  1706. {
  1707. PMPE_FILTER pFilter = ((PMPE_FILTER) pSrb->HwDeviceExtension);
  1708. PSTREAM pStream = (PSTREAM) pSrb->StreamObject->HwStreamExtension;
  1709. PHW_STREAM_REQUEST_BLOCK pCurrentSrb = NULL;
  1710. //
  1711. // For each stream, the following states are used:
  1712. //
  1713. // Stop: Absolute minimum resources are used. No outstanding IRPs.
  1714. // Acquire: KS only state that has no DirectShow correpondence
  1715. // Acquire needed resources.
  1716. // Pause: Getting ready to run. Allocate needed resources so that
  1717. // the eventual transition to Run is as fast as possible.
  1718. // Read SRBs will be queued at either the Stream class
  1719. // or in your driver (depending on when you send "ReadyForNext")
  1720. // Run: Streaming.
  1721. //
  1722. // Moving to Stop to Run always transitions through Pause.
  1723. //
  1724. // But since a client app could crash unexpectedly, drivers should handle
  1725. // the situation of having outstanding IRPs cancelled and open streams
  1726. // being closed WHILE THEY ARE STREAMING!
  1727. //
  1728. // Note that it is quite possible to transition repeatedly between states:
  1729. // Stop -> Pause -> Stop -> Pause -> Run -> Pause -> Run -> Pause -> Stop
  1730. //
  1731. switch (pSrb->CommandData.StreamState)
  1732. {
  1733. case KSSTATE_STOP:
  1734. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: Set Stream State KSSTATE_STOP\n"));
  1735. //
  1736. // If transitioning to STOP state, then complete any outstanding IRPs
  1737. //
  1738. while (QueueRemove(&pCurrentSrb, &pFilter->IpV4StreamDataSpinLock, &pFilter->IpV4StreamDataQueue))
  1739. {
  1740. pCurrentSrb->Status = STATUS_CANCELLED;
  1741. pCurrentSrb->CommandData.DataBufferArray->DataUsed = 0;
  1742. StreamClassStreamNotification(StreamRequestComplete, pCurrentSrb->StreamObject, pCurrentSrb);
  1743. TEST_DEBUG( TEST_DBG_SRB, ("MPE 30Completed SRB %08X\n", pCurrentSrb));
  1744. }
  1745. pStream->KSState = pSrb->CommandData.StreamState;
  1746. pSrb->Status = STATUS_SUCCESS;
  1747. break;
  1748. case KSSTATE_ACQUIRE:
  1749. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: Set Stream State KSSTATE_ACQUIRE\n"));
  1750. pStream->KSState = pSrb->CommandData.StreamState;
  1751. pSrb->Status = STATUS_SUCCESS;
  1752. break;
  1753. case KSSTATE_PAUSE:
  1754. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: Set Stream State KSSTATE_PAUSE\n"));
  1755. pStream->KSState = pSrb->CommandData.StreamState;
  1756. pSrb->Status = STATUS_SUCCESS;
  1757. break;
  1758. case KSSTATE_RUN:
  1759. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: Set Stream State KSSTATE_RUN\n"));
  1760. pStream->KSState = pSrb->CommandData.StreamState;
  1761. pSrb->Status = STATUS_SUCCESS;
  1762. break;
  1763. } // end switch (pSrb->CommandData.StreamState)
  1764. return;
  1765. }