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.

1829 lines
61 KiB

  1. ////////////////////////////////////////////////////////////////////////////
  2. //
  3. //
  4. // Copyright (c) 1996, 1997 Microsoft Corporation
  5. //
  6. //
  7. // Module Name:
  8. // slip.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 "Slip.h"
  29. #include "SlipMedia.h"
  30. #include "SlipStream.h"
  31. #include "Recv.h"
  32. #include "Main.h"
  33. #include "filter.h"
  34. //////////////////////////////////////////////////////////////////////////////
  35. //
  36. //
  37. VOID
  38. DumpDataFormat (
  39. PKSDATAFORMAT pF
  40. );
  41. typedef struct _IPHeader {
  42. UCHAR ucIPVerLen; // Version and length.
  43. UCHAR ucIPTos; // Type of service.
  44. USHORT usLength; // Total length of datagram.
  45. USHORT usIPId; // Identification.
  46. USHORT usIPOffset; // Flags and fragment offset.
  47. UCHAR ucIPTtl; // Time to live.
  48. UCHAR ucProtocol ; // Protocol.
  49. USHORT usChkSum; // Header checksum.
  50. UCHAR ulIPSrc [4]; // Source address.
  51. UCHAR ulIPDst [4]; // Destination address.
  52. } IPHEADER, * PIPHEADER;
  53. //////////////////////////////////////////////////////////////////////////////
  54. VOID
  55. BuildTestIPFrame (
  56. PUCHAR pFrame
  57. )
  58. //////////////////////////////////////////////////////////////////////////////
  59. {
  60. ULONG ul = 0;
  61. PIPHEADER pHeader = (PIPHEADER) pFrame;
  62. if (pFrame == NULL)
  63. {
  64. return;
  65. }
  66. //
  67. // Do the header part 1st
  68. //
  69. pHeader->ucIPVerLen = 0x45;
  70. pHeader->ucIPTos = 0x00;
  71. pHeader->usLength = 0x1C01;
  72. pHeader->usIPId = 0x980A;
  73. pHeader->usIPOffset = 0x0000;
  74. pHeader->ucIPTtl = 0x08;
  75. pHeader->ucProtocol = 0x11;
  76. pHeader->usChkSum = 0x72B6;
  77. pHeader->ulIPSrc [0] = 0xC0;
  78. pHeader->ulIPSrc [1] = 0xA8;
  79. pHeader->ulIPSrc [2] = 0x01;
  80. pHeader->ulIPSrc [3] = 0x64;
  81. pHeader->ulIPDst [0] = 0xE3;
  82. pHeader->ulIPDst [1] = 0x02;
  83. pHeader->ulIPDst [2] = 0x02;
  84. pHeader->ulIPDst [3] = 0x02;
  85. //
  86. // Do the Data Part
  87. //
  88. for (pFrame += sizeof (IPHEADER), ul = 0; ul < 0x11C; ul++)
  89. {
  90. *pFrame++ = 0x11;
  91. }
  92. return;
  93. }
  94. //////////////////////////////////////////////////////////////////////////////
  95. VOID
  96. SlipGetConnectionProperty(
  97. PHW_STREAM_REQUEST_BLOCK pSrb
  98. )
  99. //////////////////////////////////////////////////////////////////////////////
  100. {
  101. PSTREAM pStream = (PSTREAM)pSrb->StreamObject->HwStreamExtension;
  102. PSTREAM_PROPERTY_DESCRIPTOR pSPD = pSrb->CommandData.PropertyInfo;
  103. ULONG Id = pSPD->Property->Id; // index of the property
  104. ULONG ulStreamNumber = pSrb->StreamObject->StreamNumber;
  105. pSrb->ActualBytesTransferred = 0;
  106. switch (Id)
  107. {
  108. case KSPROPERTY_CONNECTION_ALLOCATORFRAMING:
  109. {
  110. PKSALLOCATOR_FRAMING Framing = (PKSALLOCATOR_FRAMING) pSPD->PropertyInfo;
  111. Framing->RequirementsFlags = KSALLOCATOR_REQUIREMENTF_SYSTEM_MEMORY |
  112. KSALLOCATOR_REQUIREMENTF_INPLACE_MODIFIER |
  113. KSALLOCATOR_REQUIREMENTF_PREFERENCES_ONLY;
  114. Framing->PoolType = NonPagedPool;
  115. Framing->Frames = 0;
  116. Framing->FrameSize = 0;
  117. Framing->FileAlignment = 0; // None OR FILE_QUAD_ALIGNMENT-1 OR PAGE_SIZE-1;
  118. Framing->Reserved = 0;
  119. switch (ulStreamNumber)
  120. {
  121. case SLIP_IPV4:
  122. Framing->Frames = 64;
  123. Framing->FrameSize = pStream->OpenedFormat.SampleSize;
  124. pSrb->Status = STATUS_SUCCESS;
  125. break;
  126. case SLIP_STREAM:
  127. Framing->Frames = 64;
  128. Framing->FrameSize = pStream->OpenedFormat.SampleSize;
  129. pSrb->Status = STATUS_SUCCESS;
  130. break;
  131. default:
  132. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  133. break;
  134. }
  135. pSrb->ActualBytesTransferred = sizeof (KSALLOCATOR_FRAMING);
  136. }
  137. break;
  138. default:
  139. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  140. break;
  141. }
  142. return;
  143. }
  144. //////////////////////////////////////////////////////////////////////////////
  145. NTSTATUS
  146. SlipDriverInitialize (
  147. IN PDRIVER_OBJECT DriverObject,
  148. IN PUNICODE_STRING RegistryPath
  149. )
  150. //////////////////////////////////////////////////////////////////////////////
  151. {
  152. NTSTATUS ntStatus = STATUS_SUCCESS;
  153. HW_INITIALIZATION_DATA HwInitData;
  154. UNICODE_STRING DeviceNameString;
  155. UNICODE_STRING SymbolicNameString;
  156. RtlZeroMemory(&HwInitData, sizeof(HwInitData));
  157. HwInitData.HwInitializationDataSize = sizeof(HwInitData);
  158. ////////////////////////////////////////////////////////////////
  159. //
  160. // Setup the stream class dispatch table
  161. //
  162. HwInitData.HwInterrupt = NULL; // HwInterrupt is only for HW devices
  163. HwInitData.HwReceivePacket = CodecReceivePacket;
  164. HwInitData.HwCancelPacket = CodecCancelPacket;
  165. HwInitData.HwRequestTimeoutHandler = CodecTimeoutPacket;
  166. HwInitData.DeviceExtensionSize = sizeof(SLIP_FILTER);
  167. HwInitData.PerRequestExtensionSize = sizeof(SRB_EXTENSION);
  168. HwInitData.FilterInstanceExtensionSize = 0;
  169. HwInitData.PerStreamExtensionSize = sizeof(STREAM);
  170. HwInitData.BusMasterDMA = FALSE;
  171. HwInitData.Dma24BitAddresses = FALSE;
  172. HwInitData.BufferAlignment = 3;
  173. HwInitData.TurnOffSynchronization = TRUE;
  174. HwInitData.DmaBufferSize = 0;
  175. ntStatus = StreamClassRegisterAdapter (DriverObject, RegistryPath, &HwInitData);
  176. if (ntStatus != STATUS_SUCCESS)
  177. {
  178. goto ret;
  179. }
  180. ret:
  181. return ntStatus;
  182. }
  183. //
  184. //
  185. //////////////////////////////////////////////////////////////////////////////
  186. BOOLEAN
  187. CodecInitialize (
  188. IN OUT PHW_STREAM_REQUEST_BLOCK pSrb
  189. )
  190. //////////////////////////////////////////////////////////////////////////////
  191. {
  192. NTSTATUS ntStatus = STATUS_SUCCESS;
  193. BOOLEAN bStatus = FALSE;
  194. PPORT_CONFIGURATION_INFORMATION pConfigInfo = pSrb->CommandData.ConfigInfo;
  195. PSLIP_FILTER pFilter = (PSLIP_FILTER) pConfigInfo->HwDeviceExtension;
  196. //
  197. // Define the default return codes
  198. //
  199. pSrb->Status = STATUS_SUCCESS;
  200. bStatus = TRUE;
  201. //
  202. // Initialize Statistics block
  203. //
  204. RtlZeroMemory(&pFilter->Stats, sizeof (STATS));
  205. //
  206. // Check out init flag so we don't try to init more then once. The Streaming
  207. // Class driver appears to call the init handler several times for some reason.
  208. //
  209. if (pFilter->bInitializationComplete)
  210. {
  211. goto ret;
  212. }
  213. if (pConfigInfo->NumberOfAccessRanges == 0)
  214. {
  215. pConfigInfo->StreamDescriptorSize = sizeof (HW_STREAM_HEADER) +
  216. DRIVER_STREAM_COUNT * sizeof (HW_STREAM_INFORMATION);
  217. }
  218. else
  219. {
  220. pSrb->Status = STATUS_NO_SUCH_DEVICE;
  221. bStatus = FALSE;
  222. goto ret;
  223. }
  224. //
  225. // Create a filter object to represent our context
  226. //
  227. pSrb->Status = CreateFilter (pConfigInfo->ClassDeviceObject->DriverObject, pConfigInfo->ClassDeviceObject, pFilter);
  228. if (pSrb->Status != STATUS_SUCCESS)
  229. {
  230. bStatus = FALSE;
  231. goto ret;
  232. }
  233. pFilter->bInitializationComplete = TRUE;
  234. ret:
  235. return (bStatus);
  236. }
  237. //////////////////////////////////////////////////////////////////////////////
  238. BOOLEAN
  239. CodecUnInitialize (
  240. IN OUT PHW_STREAM_REQUEST_BLOCK pSrb
  241. )
  242. //////////////////////////////////////////////////////////////////////////////
  243. {
  244. NTSTATUS ntStatus = STATUS_SUCCESS;
  245. BOOLEAN bStatus = FALSE;
  246. PPORT_CONFIGURATION_INFORMATION pConfigInfo = pSrb->CommandData.ConfigInfo;
  247. PSLIP_FILTER pFilter = ((PSLIP_FILTER)pSrb->HwDeviceExtension);
  248. PSTREAM pStream = NULL;
  249. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: Codec Unitialize called\n"));
  250. if (pSrb->StreamObject != NULL)
  251. {
  252. pStream = (PSTREAM)pSrb->StreamObject->HwStreamExtension;
  253. }
  254. if (pStream)
  255. {
  256. //
  257. // Clean up the NAB_STREAM QUEUE used for deframing
  258. //
  259. DeleteNabStreamQueue (pFilter);
  260. //
  261. // Clean up any queues we have and complete any outstanding SRB's
  262. //
  263. while (QueueRemove (&pSrb, &pFilter->StreamUserSpinLock, &pFilter->StreamContxList))
  264. {
  265. pSrb->Status = STATUS_CANCELLED;
  266. StreamClassStreamNotification (StreamRequestComplete, pSrb->StreamObject, pSrb);
  267. TEST_DEBUG( TEST_DBG_SRB, ("SLIP 5Completed SRB %08X\n", pSrb));
  268. }
  269. while (QueueRemove (&pSrb, &pFilter->IpV4StreamDataSpinLock, &pFilter->IpV4StreamDataQueue))
  270. {
  271. pSrb->Status = STATUS_CANCELLED;
  272. StreamClassStreamNotification (StreamRequestComplete, pSrb->StreamObject, pSrb );
  273. TEST_DEBUG( TEST_DBG_SRB, ("SLIP 6Completed SRB %08X\n", pSrb));
  274. }
  275. while (QueueRemove (&pSrb, &pFilter->StreamDataSpinLock, &pFilter->StreamDataQueue))
  276. {
  277. pSrb->Status = STATUS_CANCELLED;
  278. StreamClassStreamNotification (StreamRequestComplete, pSrb->StreamObject, pSrb );
  279. TEST_DEBUG( TEST_DBG_SRB, ("SLIP 7Completed SRB %08X\n", pSrb));
  280. }
  281. while (QueueRemove (&pSrb, &pFilter->StreamControlSpinLock, &pFilter->StreamControlQueue))
  282. {
  283. pSrb->Status = STATUS_CANCELLED;
  284. StreamClassStreamNotification (StreamRequestComplete, pSrb->StreamObject, pSrb);
  285. TEST_DEBUG( TEST_DBG_SRB, ("SLIP 8Completed SRB %08X\n", pSrb));
  286. }
  287. }
  288. while (QueueRemove (&pSrb, &pFilter->AdapterSRBSpinLock, &pFilter->AdapterSRBQueue))
  289. {
  290. pSrb->Status = STATUS_CANCELLED;
  291. StreamClassDeviceNotification (DeviceRequestComplete, pSrb->StreamObject, pSrb);
  292. TEST_DEBUG( TEST_DBG_RECV, ("SLIP 9Completed SRB %08X\n", pSrb));
  293. }
  294. bStatus = TRUE;
  295. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: Codec Unitialize completed\n"));
  296. return (bStatus);
  297. }
  298. //////////////////////////////////////////////////////////////////////////////
  299. VOID
  300. CodecStreamInfo (
  301. PHW_STREAM_REQUEST_BLOCK pSrb
  302. )
  303. //////////////////////////////////////////////////////////////////////////////
  304. {
  305. int j;
  306. PSLIP_FILTER pFilter =
  307. ((PSLIP_FILTER)pSrb->HwDeviceExtension);
  308. //
  309. // pick up the pointer to header which preceeds the stream info structs
  310. //
  311. PHW_STREAM_HEADER pstrhdr =
  312. (PHW_STREAM_HEADER)&(pSrb->CommandData.StreamBuffer->StreamHeader);
  313. //
  314. // pick up the pointer to the array of stream information data structures
  315. //
  316. PHW_STREAM_INFORMATION pstrinfo =
  317. (PHW_STREAM_INFORMATION)&(pSrb->CommandData.StreamBuffer->StreamInfo);
  318. //
  319. // Set the header
  320. //
  321. StreamHeader.NumDevPropArrayEntries = 0;
  322. StreamHeader.DevicePropertiesArray = (PKSPROPERTY_SET)NULL;
  323. *pstrhdr = StreamHeader;
  324. //
  325. // stuff the contents of each HW_STREAM_INFORMATION struct
  326. //
  327. for (j = 0; j < DRIVER_STREAM_COUNT; j++)
  328. {
  329. *pstrinfo++ = Streams[j].hwStreamInfo;
  330. }
  331. pSrb->Status = STATUS_SUCCESS;
  332. }
  333. //////////////////////////////////////////////////////////////////////////////
  334. VOID
  335. STREAMAPI
  336. CodecCancelPacket(
  337. PHW_STREAM_REQUEST_BLOCK pSrb
  338. )
  339. //////////////////////////////////////////////////////////////////////////////
  340. {
  341. PSTREAM pStream = (PSTREAM)pSrb->StreamObject->HwStreamExtension;
  342. PSLIP_FILTER pFilter = ((PSLIP_FILTER)pSrb->HwDeviceExtension);
  343. //
  344. // Check whether the SRB to cancel is in use by this stream
  345. //
  346. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: CancelPacket Called\n"));
  347. CancelNabStreamSrb (pFilter, pSrb);
  348. if (QueueRemoveSpecific (pSrb, &pFilter->IpV4StreamDataSpinLock, &pFilter->IpV4StreamDataQueue))
  349. {
  350. pSrb->Status = STATUS_CANCELLED;
  351. StreamClassStreamNotification (StreamRequestComplete, pSrb->StreamObject, pSrb );
  352. TEST_DEBUG( TEST_DBG_SRB, ("SLIP 10Completed SRB %08X\n", pSrb));
  353. return;
  354. }
  355. if (QueueRemoveSpecific (pSrb, &pFilter->StreamDataSpinLock, &pFilter->StreamDataQueue))
  356. {
  357. pSrb->Status = STATUS_CANCELLED;
  358. StreamClassStreamNotification (StreamRequestComplete, pSrb->StreamObject, pSrb );
  359. TEST_DEBUG( TEST_DBG_SRB, ("SLIP 11Completed SRB %08X\n", pSrb));
  360. return;
  361. }
  362. if (QueueRemoveSpecific (pSrb, &pFilter->StreamControlSpinLock, &pFilter->StreamControlQueue))
  363. {
  364. pSrb->Status = STATUS_CANCELLED;
  365. StreamClassStreamNotification (StreamRequestComplete, pSrb->StreamObject, pSrb);
  366. TEST_DEBUG( TEST_DBG_SRB, ("SLIP 12Completed SRB %08X\n", pSrb));
  367. return;
  368. }
  369. if (QueueRemoveSpecific (pSrb, &pFilter->AdapterSRBSpinLock, &pFilter->AdapterSRBQueue))
  370. {
  371. pSrb->Status = STATUS_CANCELLED;
  372. StreamClassDeviceNotification (DeviceRequestComplete, pSrb->StreamObject, pSrb);
  373. TEST_DEBUG( TEST_DBG_SRB, ("SLIP 13Completed SRB %08X\n", pSrb));
  374. return;
  375. }
  376. return;
  377. }
  378. //////////////////////////////////////////////////////////////////////////////
  379. VOID
  380. STREAMAPI
  381. CodecTimeoutPacket(
  382. PHW_STREAM_REQUEST_BLOCK pSrb
  383. )
  384. //////////////////////////////////////////////////////////////////////////////
  385. {
  386. //
  387. // if we timeout while playing, then we need to consider this
  388. // condition an error, and reset the hardware, and reset everything
  389. // as well as cancelling this and all requests
  390. //
  391. //
  392. // if we are not playing, and this is a CTRL request, we still
  393. // need to reset everything as well as cancelling this and all requests
  394. //
  395. //
  396. // if this is a data request, and the device is paused, we probably have
  397. // run out of data buffer, and need more time, so just reset the timer,
  398. // and let the packet continue
  399. //
  400. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: TimeoutPacket Called\n"));
  401. pSrb->TimeoutCounter = 0;
  402. return;
  403. }
  404. //////////////////////////////////////////////////////////////////////////////
  405. VOID
  406. STREAMAPI
  407. CodecReceivePacket(
  408. IN PHW_STREAM_REQUEST_BLOCK pSrb
  409. )
  410. //////////////////////////////////////////////////////////////////////////////
  411. {
  412. PSLIP_FILTER pFilter = ((PSLIP_FILTER)pSrb->HwDeviceExtension);
  413. //
  414. // Make sure queue & SL initted
  415. //
  416. if (!pFilter->bAdapterQueueInitialized)
  417. {
  418. InitializeListHead (&pFilter->AdapterSRBQueue);
  419. KeInitializeSpinLock (&pFilter->AdapterSRBSpinLock);
  420. pFilter->bAdapterQueueInitialized = TRUE;
  421. }
  422. //
  423. // Assume success
  424. //
  425. pSrb->Status = STATUS_SUCCESS;
  426. //
  427. // determine the type of packet.
  428. //
  429. QueueAdd (pSrb, &pFilter->AdapterSRBSpinLock, &pFilter->AdapterSRBQueue);
  430. TEST_DEBUG( TEST_DBG_SRB, ("SLIP Queuing SRB %08X\n", pSrb));
  431. while (QueueRemove( &pSrb, &pFilter->AdapterSRBSpinLock, &pFilter->AdapterSRBQueue ))
  432. {
  433. switch (pSrb->Command)
  434. {
  435. case SRB_INITIALIZE_DEVICE:
  436. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: SRB_INITIALIZE Command\n"));
  437. CodecInitialize(pSrb);
  438. break;
  439. case SRB_UNINITIALIZE_DEVICE:
  440. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: SRB_UNINITIALIZE Command\n"));
  441. CodecUnInitialize(pSrb);
  442. break;
  443. case SRB_INITIALIZATION_COMPLETE:
  444. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: SRB_INITIALIZE_COMPLETE Command\n"));
  445. pSrb->Status = STATUS_SUCCESS;
  446. break;
  447. case SRB_OPEN_STREAM:
  448. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: SRB_OPEN_STREAM Command\n"));
  449. OpenStream (pSrb);
  450. break;
  451. case SRB_CLOSE_STREAM:
  452. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: SRB_CLOSE_STREAM Command\n"));
  453. CloseStream (pSrb);
  454. break;
  455. case SRB_GET_STREAM_INFO:
  456. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: SRB_GET_STREAM_INFO Command\n"));
  457. CodecStreamInfo (pSrb);
  458. break;
  459. case SRB_GET_DATA_INTERSECTION:
  460. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: SRB_GET_DATA_INTERSECTION Command\n"));
  461. //
  462. // Compare our stream formats. NOTE, the compare functions sets the SRB
  463. // status fields
  464. //
  465. CompareStreamFormat (pSrb);
  466. break;
  467. case SRB_OPEN_DEVICE_INSTANCE:
  468. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: SRB_OPEN_DEVICE_INSTANCE Command\n"));
  469. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  470. break;
  471. case SRB_CLOSE_DEVICE_INSTANCE:
  472. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: SRB_CLOSE_DEVICE_INSTANCE Command\n"));
  473. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  474. break;
  475. case SRB_UNKNOWN_DEVICE_COMMAND:
  476. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: SRB_UNKNOWN_DEVICE Command\n"));
  477. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  478. break;
  479. case SRB_CHANGE_POWER_STATE:
  480. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: SRB_CHANGE_POWER_STATE Command\n"));
  481. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  482. break;
  483. case SRB_GET_DEVICE_PROPERTY:
  484. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: SRB_GET_DEVICE_PROPERTY Command\n"));
  485. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  486. break;
  487. case SRB_SET_DEVICE_PROPERTY:
  488. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: SRB_SET_DEVICE_PROPERTY Command\n"));
  489. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  490. break;
  491. case SRB_UNKNOWN_STREAM_COMMAND:
  492. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: SRB_UNKNOWN Command\n"));
  493. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  494. break;
  495. default:
  496. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: SRB_DEFAULT Command\n"));
  497. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  498. break;
  499. };
  500. //
  501. // NOTE:
  502. //
  503. // All of the commands that we do, or do not understand can all be completed
  504. // syncronously at this point, so we can use a common callback routine here.
  505. // If any of the above commands require asyncronous processing, this will
  506. // have to change
  507. //
  508. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: SRB Status returned: %08X\n", pSrb->Status));
  509. StreamClassDeviceNotification (DeviceRequestComplete, pFilter, pSrb);
  510. TEST_DEBUG( TEST_DBG_SRB, ("SLIP 14Completed SRB %08X\n", pSrb));
  511. }
  512. }
  513. //////////////////////////////////////////////////////////////////////////////
  514. BOOL STREAMAPI
  515. QueueAdd (
  516. IN PHW_STREAM_REQUEST_BLOCK pSrb,
  517. IN PKSPIN_LOCK pQueueSpinLock,
  518. IN PLIST_ENTRY pQueue
  519. )
  520. //////////////////////////////////////////////////////////////////////////////
  521. {
  522. KIRQL Irql;
  523. PSRB_EXTENSION pSrbExtension;
  524. pSrbExtension = ( PSRB_EXTENSION )pSrb->SRBExtension;
  525. KeAcquireSpinLock( pQueueSpinLock, &Irql );
  526. pSrbExtension->pSrb = pSrb;
  527. InsertTailList( pQueue, &pSrbExtension->ListEntry );
  528. KeReleaseSpinLock( pQueueSpinLock, Irql );
  529. return TRUE;
  530. }
  531. //////////////////////////////////////////////////////////////////////////////
  532. BOOL STREAMAPI
  533. QueuePush (
  534. IN PHW_STREAM_REQUEST_BLOCK pSrb,
  535. IN PKSPIN_LOCK pQueueSpinLock,
  536. IN PLIST_ENTRY pQueue
  537. )
  538. //////////////////////////////////////////////////////////////////////////////
  539. {
  540. KIRQL Irql;
  541. PSRB_EXTENSION pSrbExtension;
  542. pSrbExtension = ( PSRB_EXTENSION )pSrb->SRBExtension;
  543. KeAcquireSpinLock( pQueueSpinLock, &Irql );
  544. pSrbExtension->pSrb = pSrb;
  545. InsertHeadList( pQueue, &pSrbExtension->ListEntry );
  546. KeReleaseSpinLock( pQueueSpinLock, Irql );
  547. return TRUE;
  548. }
  549. //////////////////////////////////////////////////////////////////////////////
  550. BOOL STREAMAPI
  551. QueueAddIfNotEmpty (
  552. IN PHW_STREAM_REQUEST_BLOCK pSrb,
  553. IN PKSPIN_LOCK pQueueSpinLock,
  554. IN PLIST_ENTRY pQueue
  555. )
  556. //////////////////////////////////////////////////////////////////////////////
  557. {
  558. KIRQL Irql;
  559. PSRB_EXTENSION pSrbExtension;
  560. BOOL bAddedSRB = FALSE;
  561. pSrbExtension = ( PSRB_EXTENSION )pSrb->SRBExtension;
  562. KeAcquireSpinLock( pQueueSpinLock, &Irql );
  563. if( !IsListEmpty( pQueue ))
  564. {
  565. pSrbExtension->pSrb = pSrb;
  566. InsertTailList (pQueue, &pSrbExtension->ListEntry );
  567. bAddedSRB = TRUE;
  568. }
  569. KeReleaseSpinLock( pQueueSpinLock, Irql );
  570. return bAddedSRB;
  571. }
  572. //////////////////////////////////////////////////////////////////////////////
  573. BOOL STREAMAPI
  574. QueueRemove (
  575. IN OUT PHW_STREAM_REQUEST_BLOCK * pSrb,
  576. IN PKSPIN_LOCK pQueueSpinLock,
  577. IN PLIST_ENTRY pQueue
  578. )
  579. //////////////////////////////////////////////////////////////////////////////
  580. {
  581. KIRQL Irql;
  582. BOOL bRemovedSRB = FALSE;
  583. KeAcquireSpinLock (pQueueSpinLock, &Irql);
  584. *pSrb = (PHW_STREAM_REQUEST_BLOCK) NULL;
  585. if( !IsListEmpty( pQueue ))
  586. {
  587. PHW_STREAM_REQUEST_BLOCK *pCurrentSrb = NULL;
  588. PUCHAR Ptr = (PUCHAR) RemoveHeadList(pQueue);
  589. pCurrentSrb = (PHW_STREAM_REQUEST_BLOCK *) (((PUCHAR)Ptr) + sizeof (LIST_ENTRY));
  590. *pSrb = *pCurrentSrb;
  591. bRemovedSRB = TRUE;
  592. }
  593. KeReleaseSpinLock (pQueueSpinLock, Irql);
  594. return bRemovedSRB;
  595. }
  596. //////////////////////////////////////////////////////////////////////////////
  597. BOOL STREAMAPI
  598. QueueRemoveSpecific (
  599. IN PHW_STREAM_REQUEST_BLOCK pSrb,
  600. IN PKSPIN_LOCK pQueueSpinLock,
  601. IN PLIST_ENTRY pQueue
  602. )
  603. //////////////////////////////////////////////////////////////////////////////
  604. {
  605. KIRQL Irql;
  606. BOOL bRemovedSRB = FALSE;
  607. PLIST_ENTRY pCurrentEntry;
  608. PHW_STREAM_REQUEST_BLOCK * pCurrentSrb;
  609. KeAcquireSpinLock( pQueueSpinLock, &Irql );
  610. if( !IsListEmpty( pQueue ))
  611. {
  612. pCurrentEntry = pQueue->Flink;
  613. while ((pCurrentEntry != pQueue ) && !bRemovedSRB)
  614. {
  615. pCurrentSrb = (PHW_STREAM_REQUEST_BLOCK * ) ((( PUCHAR )pCurrentEntry ) + sizeof( LIST_ENTRY ));
  616. if( *pCurrentSrb == pSrb )
  617. {
  618. RemoveEntryList( pCurrentEntry );
  619. bRemovedSRB = TRUE;
  620. }
  621. pCurrentEntry = pCurrentEntry->Flink;
  622. }
  623. }
  624. KeReleaseSpinLock( pQueueSpinLock, Irql );
  625. return bRemovedSRB;
  626. }
  627. //////////////////////////////////////////////////////////////////////////////
  628. NTSTATUS
  629. StreamIPIndicateEvent (
  630. PVOID pvEvent
  631. )
  632. //////////////////////////////////////////////////////////////////////////////
  633. {
  634. return STATUS_NOT_IMPLEMENTED;
  635. }
  636. //////////////////////////////////////////////////////////////////////////////
  637. BOOL
  638. CompareGUIDsAndFormatSize(
  639. IN PKSDATARANGE pDataRange1,
  640. IN PKSDATARANGE pDataRange2,
  641. BOOLEAN bCheckSize
  642. )
  643. //////////////////////////////////////////////////////////////////////////////
  644. {
  645. BOOL bResult = FALSE;
  646. if ( IsEqualGUID(&pDataRange1->MajorFormat, &KSDATAFORMAT_TYPE_WILDCARD) ||
  647. IsEqualGUID(&pDataRange2->MajorFormat, &KSDATAFORMAT_TYPE_WILDCARD) ||
  648. IsEqualGUID(&pDataRange1->MajorFormat, &pDataRange2->MajorFormat) )
  649. {
  650. if ( IsEqualGUID(&pDataRange1->SubFormat, &KSDATAFORMAT_SUBTYPE_WILDCARD) ||
  651. IsEqualGUID(&pDataRange2->SubFormat, &KSDATAFORMAT_SUBTYPE_WILDCARD) ||
  652. IsEqualGUID(&pDataRange1->SubFormat, &pDataRange2->SubFormat) )
  653. {
  654. if ( IsEqualGUID(&pDataRange1->Specifier, &KSDATAFORMAT_SPECIFIER_WILDCARD) ||
  655. IsEqualGUID(&pDataRange2->Specifier, &KSDATAFORMAT_SPECIFIER_WILDCARD) ||
  656. IsEqualGUID(&pDataRange1->Specifier, &pDataRange2->Specifier) )
  657. {
  658. if ( !bCheckSize || pDataRange1->FormatSize == pDataRange2->FormatSize)
  659. {
  660. bResult = TRUE;
  661. }
  662. }
  663. }
  664. }
  665. return bResult;
  666. }
  667. //////////////////////////////////////////////////////////////////////////////
  668. VOID
  669. DumpDataFormat (
  670. PKSDATAFORMAT pF
  671. )
  672. //////////////////////////////////////////////////////////////////////////////
  673. {
  674. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: DATA Format\n"));
  675. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: Format Size: %08X\n", pF->FormatSize));
  676. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: Flags: %08X\n", pF->Flags));
  677. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: SampleSize: %08X\n", pF->SampleSize));
  678. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: Reserved: %08X\n", pF->Reserved));
  679. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: Major GUID: %08X %04X %04X %02X %02X %02X %02X %02X %02X %02X %02X\n",
  680. pF->MajorFormat.Data1,
  681. pF->MajorFormat.Data2,
  682. pF->MajorFormat.Data3,
  683. pF->MajorFormat.Data4[0],
  684. pF->MajorFormat.Data4[1],
  685. pF->MajorFormat.Data4[2],
  686. pF->MajorFormat.Data4[3],
  687. pF->MajorFormat.Data4[4],
  688. pF->MajorFormat.Data4[5],
  689. pF->MajorFormat.Data4[6],
  690. pF->MajorFormat.Data4[7]
  691. ));
  692. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: Sub GUID: %08X %04X %04X %02X %02X %02X %02X %02X %02X %02X %02X\n",
  693. pF->SubFormat.Data1,
  694. pF->SubFormat.Data2,
  695. pF->SubFormat.Data3,
  696. pF->SubFormat.Data4[0],
  697. pF->SubFormat.Data4[1],
  698. pF->SubFormat.Data4[2],
  699. pF->SubFormat.Data4[3],
  700. pF->SubFormat.Data4[4],
  701. pF->SubFormat.Data4[5],
  702. pF->SubFormat.Data4[6],
  703. pF->SubFormat.Data4[7]
  704. ));
  705. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: Specifier: %08X %04X %04X %02X %02X %02X %02X %02X %02X %02X %02X\n",
  706. pF->Specifier.Data1,
  707. pF->Specifier.Data2,
  708. pF->Specifier.Data3,
  709. pF->Specifier.Data4[0],
  710. pF->Specifier.Data4[1],
  711. pF->Specifier.Data4[2],
  712. pF->Specifier.Data4[3],
  713. pF->Specifier.Data4[4],
  714. pF->Specifier.Data4[5],
  715. pF->Specifier.Data4[6],
  716. pF->Specifier.Data4[7]
  717. ));
  718. TEST_DEBUG (TEST_DBG_TRACE, ("\n"));
  719. }
  720. //////////////////////////////////////////////////////////////////////////////
  721. BOOL
  722. CompareStreamFormat (
  723. IN PHW_STREAM_REQUEST_BLOCK pSrb
  724. )
  725. //////////////////////////////////////////////////////////////////////////////
  726. {
  727. BOOL bStatus = FALSE;
  728. PSTREAM_DATA_INTERSECT_INFO pIntersectInfo;
  729. PKSDATARANGE pDataRange1;
  730. PKSDATARANGE pDataRange2;
  731. ULONG FormatSize = 0;
  732. ULONG ulStreamNumber;
  733. ULONG j;
  734. ULONG ulNumberOfFormatArrayEntries;
  735. PKSDATAFORMAT *pAvailableFormats;
  736. pIntersectInfo = pSrb->CommandData.IntersectInfo;
  737. ulStreamNumber = pIntersectInfo->StreamNumber;
  738. pSrb->ActualBytesTransferred = 0;
  739. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: Comparing Stream Formats\n"));
  740. //
  741. // Check that the stream number is valid
  742. //
  743. if (ulStreamNumber < DRIVER_STREAM_COUNT)
  744. {
  745. ulNumberOfFormatArrayEntries = Streams[ulStreamNumber].hwStreamInfo.NumberOfFormatArrayEntries;
  746. //
  747. // Get the pointer to the array of available formats
  748. //
  749. pAvailableFormats = Streams[ulStreamNumber].hwStreamInfo.StreamFormatsArray;
  750. //
  751. // Walk the formats supported by the stream searching for a match
  752. // of the three GUIDs which together define a DATARANGE
  753. //
  754. for (pDataRange1 = pIntersectInfo->DataRange, j = 0;
  755. j < ulNumberOfFormatArrayEntries;
  756. j++, pAvailableFormats++)
  757. {
  758. bStatus = FALSE;
  759. pSrb->Status = STATUS_UNSUCCESSFUL;
  760. pDataRange2 = *pAvailableFormats;
  761. if (CompareGUIDsAndFormatSize (pDataRange1, pDataRange2, TRUE))
  762. {
  763. ULONG ulFormatSize = pDataRange2->FormatSize;
  764. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: Stream Formats compare\n"));
  765. //
  766. // Is the caller trying to get the format, or the size of the format?
  767. //
  768. if (pIntersectInfo->SizeOfDataFormatBuffer == sizeof (ULONG))
  769. {
  770. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: Returning Stream Format size\n"));
  771. *(PULONG) pIntersectInfo->DataFormatBuffer = ulFormatSize;
  772. pSrb->ActualBytesTransferred = sizeof (ULONG);
  773. pSrb->Status = STATUS_SUCCESS;
  774. bStatus = TRUE;
  775. }
  776. else
  777. {
  778. //
  779. // Verify that there is enough room in the supplied buffer for the whole thing
  780. //
  781. pSrb->Status = STATUS_BUFFER_TOO_SMALL;
  782. bStatus = FALSE;
  783. if (pIntersectInfo->SizeOfDataFormatBuffer >= ulFormatSize)
  784. {
  785. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: Returning Stream Format\n"));
  786. RtlCopyMemory (pIntersectInfo->DataFormatBuffer, pDataRange2, ulFormatSize);
  787. pSrb->ActualBytesTransferred = ulFormatSize;
  788. pSrb->Status = STATUS_SUCCESS;
  789. bStatus = TRUE;
  790. }
  791. else
  792. {
  793. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: Stream Format return buffer too small\n"));
  794. }
  795. }
  796. break;
  797. }
  798. else
  799. {
  800. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: Stream Formats DO NOT compare\n"));
  801. }
  802. }
  803. if ( j >= ulNumberOfFormatArrayEntries )
  804. {
  805. pSrb->ActualBytesTransferred = 0;
  806. pSrb->Status = STATUS_UNSUCCESSFUL;
  807. bStatus = FALSE;
  808. }
  809. }
  810. else
  811. {
  812. pSrb->ActualBytesTransferred = 0;
  813. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  814. bStatus = FALSE;
  815. }
  816. return bStatus;
  817. }
  818. //////////////////////////////////////////////////////////////////////////////
  819. VOID
  820. CloseStream (
  821. PHW_STREAM_REQUEST_BLOCK pSrb
  822. )
  823. //////////////////////////////////////////////////////////////////////////////
  824. {
  825. //
  826. // the stream extension structure is allocated by the stream class driver
  827. //
  828. PSTREAM pStream = (PSTREAM)pSrb->StreamObject->HwStreamExtension;
  829. PSLIP_FILTER pFilter = (PSLIP_FILTER)pSrb->HwDeviceExtension;
  830. ULONG ulStreamNumber = (ULONG) pSrb->StreamObject->StreamNumber;
  831. ULONG ulStreamInstance = pStream->ulStreamInstance;
  832. PHW_STREAM_REQUEST_BLOCK pCurrentSrb = NULL;
  833. //
  834. // check that the stream index requested isn't too high
  835. // or that the maximum number of instances hasn't been exceeded
  836. //
  837. if (ulStreamNumber < DRIVER_STREAM_COUNT )
  838. {
  839. //
  840. // Flush the stream data queue
  841. //
  842. while (QueueRemove( &pCurrentSrb, &pFilter->IpV4StreamDataSpinLock, &pFilter->IpV4StreamDataQueue))
  843. {
  844. pCurrentSrb->Status = STATUS_CANCELLED;
  845. StreamClassStreamNotification( StreamRequestComplete, pCurrentSrb->StreamObject, pCurrentSrb);
  846. TEST_DEBUG( TEST_DBG_SRB, ("SLIP 15Completed SRB %08X\n", pCurrentSrb));
  847. }
  848. //
  849. // Flush the stream data queue
  850. //
  851. while (QueueRemove( &pCurrentSrb, &pFilter->StreamDataSpinLock, &pFilter->StreamDataQueue))
  852. {
  853. pCurrentSrb->Status = STATUS_CANCELLED;
  854. StreamClassStreamNotification( StreamRequestComplete, pCurrentSrb->StreamObject, pCurrentSrb);
  855. TEST_DEBUG( TEST_DBG_SRB, ("SLIP 16Completed SRB %08X\n", pCurrentSrb));
  856. }
  857. //
  858. // Flush the stream control queue
  859. //
  860. while (QueueRemove( &pCurrentSrb, &pFilter->StreamControlSpinLock, &pFilter->StreamControlQueue))
  861. {
  862. pCurrentSrb->Status = STATUS_CANCELLED;
  863. StreamClassStreamNotification (StreamRequestComplete, pCurrentSrb->StreamObject, pCurrentSrb);
  864. TEST_DEBUG( TEST_DBG_SRB, ("SLIP 17Completed SRB %08X\n", pCurrentSrb));
  865. }
  866. //
  867. // Clear this streams spot in the filters stream array
  868. //
  869. pFilter->pStream[ulStreamNumber][ulStreamInstance] = NULL;
  870. //
  871. // decrement the stream instance count for this filter
  872. //
  873. pFilter->ulActualInstances[ulStreamNumber]--;
  874. //
  875. // Indicate the clock support available on this stream
  876. //
  877. //pSrb->StreamObject->HwClockObject = 0;
  878. //
  879. // Reset the stream state to stopped
  880. //
  881. pStream->KSState = KSSTATE_STOP;
  882. //
  883. //
  884. //
  885. pStream->hMasterClock = NULL;
  886. //
  887. // Reset the stream extension blob
  888. //
  889. RtlZeroMemory(pStream, sizeof (STREAM));
  890. pSrb->Status = STATUS_SUCCESS;
  891. }
  892. else
  893. {
  894. pSrb->Status = STATUS_INVALID_PARAMETER;
  895. }
  896. }
  897. //////////////////////////////////////////////////////////////////////////////
  898. VOID
  899. OpenStream (
  900. PHW_STREAM_REQUEST_BLOCK pSrb
  901. )
  902. //////////////////////////////////////////////////////////////////////////////
  903. {
  904. //
  905. // the stream extension structure is allocated by the stream class driver
  906. //
  907. PSTREAM pStream = (PSTREAM)pSrb->StreamObject->HwStreamExtension;
  908. PSLIP_FILTER pFilter = ((PSLIP_FILTER)pSrb->HwDeviceExtension);
  909. ULONG ulStreamNumber = (ULONG) pSrb->StreamObject->StreamNumber;
  910. PKSDATAFORMAT pKSDataFormat = (PKSDATAFORMAT)pSrb->CommandData.OpenFormat;
  911. //
  912. // Initialize the stream extension blob
  913. //
  914. //RtlZeroMemory(pStream, sizeof (STREAM));
  915. //
  916. // Initialize stream state
  917. //
  918. //pStream->KSState = KSSTATE_STOP;
  919. //
  920. // Initialize the next stream life check time.
  921. //
  922. KeQuerySystemTime( &pFilter->liLastTimeChecked );
  923. //
  924. // Initialize stats dump time
  925. //
  926. KeQuerySystemTime( &pFilter->liLastTimeStatsDumped );
  927. //
  928. // check that the stream index requested isn't too high
  929. // or that the maximum number of instances hasn't been exceeded
  930. //
  931. if (ulStreamNumber < DRIVER_STREAM_COUNT )
  932. {
  933. ULONG ulStreamInstance;
  934. ULONG ulMaxInstances = Streams[ulStreamNumber].hwStreamInfo.NumberOfPossibleInstances;
  935. //
  936. // Search for next open slot
  937. //
  938. for (ulStreamInstance = 0; ulStreamInstance < ulMaxInstances; ++ulStreamInstance)
  939. {
  940. if (pFilter->pStream[ulStreamNumber][ulStreamInstance] == NULL)
  941. {
  942. break;
  943. }
  944. }
  945. if (ulStreamInstance < ulMaxInstances)
  946. {
  947. if (VerifyFormat(pKSDataFormat, ulStreamNumber, &pStream->MatchedFormat))
  948. {
  949. //
  950. // Initialize Data queues and SpinLocks
  951. //
  952. InitializeListHead(&pFilter->StreamControlQueue);
  953. KeInitializeSpinLock(&pFilter->StreamControlSpinLock);
  954. InitializeListHead(&pFilter->StreamDataQueue);
  955. KeInitializeSpinLock(&pFilter->StreamDataSpinLock);
  956. InitializeListHead(&pFilter->IpV4StreamDataQueue);
  957. KeInitializeSpinLock(&pFilter->IpV4StreamDataSpinLock);
  958. InitializeListHead(&pFilter->StreamContxList);
  959. KeInitializeSpinLock(&pFilter->StreamUserSpinLock);
  960. //
  961. // Maintain an array of all the StreamEx structures in the HwDevExt
  962. // so that we can reference IRPs from any stream
  963. //
  964. pFilter->pStream[ulStreamNumber][ulStreamInstance] = pStream;
  965. //
  966. // Save the Stream Format in the Stream Extension as well.
  967. //
  968. pStream->OpenedFormat = *pKSDataFormat;
  969. //
  970. // Set up pointers to the handlers for the stream data and control handlers
  971. //
  972. pSrb->StreamObject->ReceiveDataPacket =
  973. (PVOID) Streams[ulStreamNumber].hwStreamObject.ReceiveDataPacket;
  974. pSrb->StreamObject->ReceiveControlPacket =
  975. (PVOID) Streams[ulStreamNumber].hwStreamObject.ReceiveControlPacket;
  976. //
  977. // The DMA flag must be set when the device will be performing DMA directly
  978. // to the data buffer addresses passed in to the ReceiveDataPacket routines.
  979. //
  980. pSrb->StreamObject->Dma = Streams[ulStreamNumber].hwStreamObject.Dma;
  981. //
  982. // The PIO flag must be set when the mini driver will be accessing the data
  983. // buffers passed in using logical addressing
  984. //
  985. pSrb->StreamObject->Pio = Streams[ulStreamNumber].hwStreamObject.Pio;
  986. pSrb->StreamObject->Allocator = Streams[ulStreamNumber].hwStreamObject.Allocator;
  987. //
  988. // How many extra bytes will be passed up from the driver for each frame?
  989. //
  990. pSrb->StreamObject->StreamHeaderMediaSpecific =
  991. Streams[ulStreamNumber].hwStreamObject.StreamHeaderMediaSpecific;
  992. pSrb->StreamObject->StreamHeaderWorkspace =
  993. Streams[ulStreamNumber].hwStreamObject.StreamHeaderWorkspace;
  994. //
  995. // Indicate the clock support available on this stream
  996. //
  997. pSrb->StreamObject->HwClockObject =
  998. Streams[ulStreamNumber].hwStreamObject.HwClockObject;
  999. //
  1000. // Increment the instance count on this stream
  1001. //
  1002. pStream->ulStreamInstance = ulStreamInstance;
  1003. pFilter->ulActualInstances[ulStreamNumber]++;
  1004. //
  1005. // Retain a private copy of the HwDevExt and StreamObject in the stream extension
  1006. // so we can use a timer
  1007. //
  1008. pStream->pFilter = pFilter; // For timer use
  1009. pStream->pStreamObject = pSrb->StreamObject; // For timer use
  1010. pSrb->Status = STATUS_SUCCESS;
  1011. }
  1012. else
  1013. {
  1014. pSrb->Status = STATUS_INVALID_PARAMETER;
  1015. }
  1016. }
  1017. else
  1018. {
  1019. pSrb->Status = STATUS_INVALID_PARAMETER;
  1020. }
  1021. }
  1022. else
  1023. {
  1024. pSrb->Status = STATUS_INVALID_PARAMETER;
  1025. }
  1026. }
  1027. //////////////////////////////////////////////////////////////////////////////
  1028. BOOLEAN
  1029. VerifyFormat(
  1030. IN KSDATAFORMAT *pKSDataFormat,
  1031. UINT StreamNumber,
  1032. PKSDATARANGE pMatchedFormat
  1033. )
  1034. //////////////////////////////////////////////////////////////////////////////
  1035. {
  1036. BOOLEAN bResult = FALSE;
  1037. ULONG FormatCount = 0;
  1038. PKS_DATARANGE_VIDEO pThisFormat = NULL;
  1039. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: Verify Format\n"));
  1040. for (FormatCount = 0; !bResult && FormatCount < Streams[StreamNumber].hwStreamInfo.NumberOfFormatArrayEntries;
  1041. FormatCount++ )
  1042. {
  1043. pThisFormat = (PKS_DATARANGE_VIDEO) Streams [StreamNumber].hwStreamInfo.StreamFormatsArray [FormatCount];
  1044. if (CompareGUIDsAndFormatSize( pKSDataFormat, &pThisFormat->DataRange, FALSE ) )
  1045. {
  1046. bResult = FALSE;
  1047. if (pThisFormat->DataRange.SampleSize >= pKSDataFormat->SampleSize)
  1048. {
  1049. bResult = TRUE;
  1050. }
  1051. else
  1052. {
  1053. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: VerifyFormat: Data range Sample Sizes don't match\n"));
  1054. }
  1055. }
  1056. }
  1057. if (bResult == TRUE && pMatchedFormat)
  1058. {
  1059. *pMatchedFormat = pThisFormat->DataRange;
  1060. }
  1061. return bResult;
  1062. }
  1063. //////////////////////////////////////////////////////////////////////////////
  1064. VOID
  1065. STREAMAPI
  1066. ReceiveDataPacket (
  1067. IN PHW_STREAM_REQUEST_BLOCK pSrb
  1068. )
  1069. //////////////////////////////////////////////////////////////////////////////
  1070. {
  1071. PSLIP_FILTER pFilter = (PSLIP_FILTER) pSrb->HwDeviceExtension;
  1072. PSTREAM pStream = (PSTREAM)pSrb->StreamObject->HwStreamExtension;
  1073. int iStream = (int) pSrb->StreamObject->StreamNumber;
  1074. PKSSTREAM_HEADER pStreamHdr = pSrb->CommandData.DataBufferArray;
  1075. PKSDATAFORMAT pKSDataFormat = (PKSDATAFORMAT) &pStream->MatchedFormat;
  1076. ULONG ul = 0;
  1077. PHW_STREAM_REQUEST_BLOCK pSrbIPv4 = NULL;
  1078. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: Receive Data packet handler called\n"));
  1079. //
  1080. // Default to success, disable timeouts
  1081. //
  1082. pSrb->TimeoutCounter = 0;
  1083. pSrb->Status = STATUS_SUCCESS;
  1084. //
  1085. // Check for last buffer
  1086. //
  1087. if (pStreamHdr->OptionsFlags & KSSTREAM_HEADER_OPTIONSF_ENDOFSTREAM)
  1088. {
  1089. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: Receive Data packet is LAST PACKET\n"));
  1090. StreamClassStreamNotification (StreamRequestComplete, pSrb->StreamObject, pSrb);
  1091. TEST_DEBUG( TEST_DBG_SRB, ("SLIP: Completed SRB %08X\n", pSrb));
  1092. return;
  1093. }
  1094. if (pStreamHdr->OptionsFlags != 0)
  1095. {
  1096. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: OptionsFlags: %08X\n", pStreamHdr->OptionsFlags));
  1097. }
  1098. //
  1099. // determine the type of packet.
  1100. //
  1101. switch (pSrb->Command)
  1102. {
  1103. case SRB_WRITE_DATA:
  1104. if (pStream->KSState == KSSTATE_STOP)
  1105. {
  1106. pSrb->Status = STATUS_SUCCESS;
  1107. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: SRB_WRITE STOP SRB Status returned: %08X\n", pSrb->Status));
  1108. StreamClassStreamNotification (StreamRequestComplete, pSrb->StreamObject, pSrb );
  1109. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: StreamRequestComplete on pSrb: %08X\n", pSrb));
  1110. break;
  1111. }
  1112. //
  1113. // Update the total number of packets written statistic
  1114. //
  1115. pFilter->Stats.ulTotalDataSRBWrites += 1;
  1116. //
  1117. // Handle data input, output requests differently.
  1118. //
  1119. switch (iStream)
  1120. {
  1121. //
  1122. // Frame input stream
  1123. //
  1124. case SLIP_STREAM:
  1125. {
  1126. ULONG ulBuffers = pSrb->NumberOfBuffers;
  1127. PKSSTREAM_HEADER pIPV4StreamHdr = NULL;
  1128. PNABTSFEC_BUFFER pNabData = NULL;
  1129. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: Receive Data packet handler - SRB_WRITE - SLIP_STREAM, Processing pSrb: %08X\n", pSrb));
  1130. //
  1131. // Initialize SRB Status to success
  1132. //
  1133. pSrb->Status = STATUS_SUCCESS;
  1134. //
  1135. // Process each chained buffer of data in the SRB
  1136. //
  1137. for (ul = 0; ul < ulBuffers; ul++, pStreamHdr++)
  1138. {
  1139. if (pStreamHdr)
  1140. {
  1141. //
  1142. // Update stats for IP Stream count
  1143. //
  1144. pFilter->Stats.ulTotalSlipBuffersReceived += 1;
  1145. pFilter->Stats.ulTotalSlipBytesReceived += pStreamHdr->DataUsed;
  1146. pNabData = (PNABTSFEC_BUFFER) pStreamHdr->Data;
  1147. if (pNabData && pStreamHdr->DataUsed > 0)
  1148. {
  1149. TEST_DEBUG (TEST_DBG_WRITE_DATA, ("SLIP: NAB_DATA[%d]....dataSize: %d groupID: %d\n",
  1150. ul,
  1151. pNabData->dataSize,
  1152. pNabData->groupID ));
  1153. ASSERT(pNabData->dataSize <= sizeof(pNabData->data));
  1154. if ((pSrb->Status = ntNabtsRecv (pFilter, pNabData)) != STATUS_SUCCESS)
  1155. {
  1156. //
  1157. // Something went wrong processing the data (such as running
  1158. // out of output buffers). We'll just complete the input SRB
  1159. // and lose the data. We'll return a successful status to make sure the
  1160. // graph can continue to run. Basically this error amounts to the SRB
  1161. // being tossed out and never processed (ie. a Data Loss).
  1162. //
  1163. pSrb->Status = STATUS_SUCCESS;
  1164. pFilter->bDiscontinuity = TRUE;
  1165. break;
  1166. }
  1167. }
  1168. else
  1169. {
  1170. pFilter->Stats.ulTotalSlipZeroLengthBuffers += 1;
  1171. }
  1172. }
  1173. }
  1174. StreamClassStreamNotification (StreamRequestComplete, pSrb->StreamObject, pSrb);
  1175. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: StreamRequestComplete on pSrb: %08X\n", pSrb));
  1176. }
  1177. break;
  1178. //
  1179. // Other "unknown" streams are not valid and will be rejected.
  1180. //
  1181. case SLIP_NET_CONTROL:
  1182. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: Receive Data packet handler called - SRB_WRITE - STREAM_NET_CONTROL\n"));
  1183. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  1184. //
  1185. // Update stats for Net packet count
  1186. //
  1187. pFilter->Stats.ulTotalBadPinSRBWrites += 1;
  1188. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: SLIP_NET_CONTROL SRB Status returned: %08X\n", pSrb->Status));
  1189. StreamClassStreamNotification (StreamRequestComplete, pSrb->StreamObject, pSrb);
  1190. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: StreamRequestComplete on pSrb: %08X\n", pSrb));
  1191. break;
  1192. default:
  1193. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: Receive Data packet handler called - SRB_WRITE - Default\n"));
  1194. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  1195. //
  1196. // Update stats for Unkown packet count
  1197. //
  1198. pFilter->Stats.ulTotalBadPinSRBWrites += 1;
  1199. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: DEFAULT SRB Status returned: %08X\n", pSrb->Status));
  1200. StreamClassStreamNotification (StreamRequestComplete, pSrb->StreamObject, pSrb);
  1201. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: StreamRequestComplete on pSrb: %08X\n", pSrb));
  1202. break;
  1203. }
  1204. break;
  1205. case SRB_READ_DATA:
  1206. if (pStream->KSState == KSSTATE_STOP)
  1207. {
  1208. pSrb->Status = STATUS_SUCCESS;
  1209. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: SRB_READ STOP SRB Status returned: %08X\n", pSrb->Status));
  1210. StreamClassStreamNotification (StreamRequestComplete, pSrb->StreamObject, pSrb );
  1211. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: StreamRequestComplete on pSrb: %08X\n", pSrb));
  1212. break;
  1213. }
  1214. //
  1215. // Update stats
  1216. //
  1217. pFilter->Stats.ulTotalDataSRBReads += 1;
  1218. switch (iStream)
  1219. {
  1220. case SLIP_NET_CONTROL:
  1221. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: Receive Data packet handler called - SRB_READ - STREAM_NET_CONTROL, Processing pSrb: %08X\n", pSrb));
  1222. pSrb->Status = STATUS_SUCCESS;
  1223. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: SLIP_NET_CONTROL SRB Status returned: %08X\n", pSrb->Status));
  1224. //
  1225. // Update stats for Unkown packet count
  1226. //
  1227. pFilter->Stats.ulTotalBadPinSRBReads += 1;
  1228. StreamClassStreamNotification (StreamRequestComplete, pSrb->StreamObject, pSrb);
  1229. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: StreamRequestComplete on pSrb: %08X\n", pSrb));
  1230. break;
  1231. case SLIP_IPV4:
  1232. {
  1233. ULONG ulBuffers = pSrb->NumberOfBuffers;
  1234. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: Receive Data packet handler called - SRB_READ - SLIP_IPV4, Processing pSrb: %08X\n", pSrb));
  1235. if (pSrb->CommandData.DataBufferArray->FrameExtent < pKSDataFormat->SampleSize)
  1236. {
  1237. pSrb->Status = STATUS_BUFFER_TOO_SMALL;
  1238. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: SLIP_IPV4 SRB Buffer too small.... Status returned: %08X\n", pSrb->Status));
  1239. StreamClassStreamNotification(StreamRequestComplete, pSrb->StreamObject, pSrb);
  1240. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: StreamRequestComplete on pSrb: %08X\n", pSrb));
  1241. }
  1242. else
  1243. {
  1244. //
  1245. // Take the SRB we get and queue it up. These Queued SRB's will be filled with data on a WRITE_DATA
  1246. // request, at which point they will be completed.
  1247. //
  1248. QueueAdd (pSrb, &pFilter->IpV4StreamDataSpinLock, &pFilter->IpV4StreamDataQueue);
  1249. TEST_DEBUG( TEST_DBG_SRB, ("SLIP Queuing IPv4 SRB %08X\n", pSrb));
  1250. //
  1251. // Since the stream state may have changed while we were adding the SRB to the queue
  1252. // we'll check it again, and cancel it if necessary
  1253. //
  1254. if (pStream->KSState == KSSTATE_STOP)
  1255. {
  1256. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: SRB_READ STOP SRB Status returned: %08X\n", pSrb->Status));
  1257. if (QueueRemoveSpecific (pSrb, &pFilter->IpV4StreamDataSpinLock, &pFilter->IpV4StreamDataQueue))
  1258. {
  1259. pSrb->Status = STATUS_CANCELLED;
  1260. StreamClassStreamNotification (StreamRequestComplete, pSrb->StreamObject, pSrb );
  1261. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: StreamRequestComplete on pSrb: %08X\n", pSrb));
  1262. return;
  1263. }
  1264. break;
  1265. }
  1266. }
  1267. }
  1268. break;
  1269. default:
  1270. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: Receive Data packet handler called - SRB_READ - Default\n"));
  1271. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  1272. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: DEFAULT SRB Status returned: %08X\n", pSrb->Status));
  1273. //
  1274. // Update stats for Unkown packet count
  1275. //
  1276. pFilter->Stats.ulTotalBadPinSRBReads += 1;
  1277. StreamClassStreamNotification (StreamRequestComplete, pSrb->StreamObject, pSrb);
  1278. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: StreamRequestComplete on pSrb: %08X\n", pSrb));
  1279. break;
  1280. }
  1281. break;
  1282. default:
  1283. //
  1284. // invalid / unsupported command. Fail it as such
  1285. //
  1286. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: Receive Data packet handler called - Unsupported Command\n"));
  1287. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  1288. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: DEFAULT SRB Status returned: %08X\n", pSrb->Status));
  1289. StreamClassStreamNotification( StreamRequestComplete, pSrb->StreamObject, pSrb );
  1290. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: StreamRequestComplete on pSrb: %08X\n", pSrb));
  1291. ASSERT (FALSE);
  1292. break;
  1293. }
  1294. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: Receive Data packet handler called...status: %08X\n", pSrb->Status));
  1295. return;
  1296. }
  1297. //////////////////////////////////////////////////////////////////////////////
  1298. VOID
  1299. SlipGetProperty (
  1300. PHW_STREAM_REQUEST_BLOCK pSrb
  1301. )
  1302. //////////////////////////////////////////////////////////////////////////////
  1303. {
  1304. PSTREAM_PROPERTY_DESCRIPTOR pSPD = pSrb->CommandData.PropertyInfo;
  1305. pSrb->Status = STATUS_SUCCESS;
  1306. if (IsEqualGUID (&KSPROPSETID_Connection, &pSPD->Property->Set))
  1307. {
  1308. SlipGetConnectionProperty (pSrb);
  1309. }
  1310. else
  1311. {
  1312. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  1313. }
  1314. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: SlipGetProperty Status: %08X\n", pSrb->Status));
  1315. return;
  1316. }
  1317. //////////////////////////////////////////////////////////////////////////////
  1318. VOID
  1319. IndicateMasterClock(
  1320. PHW_STREAM_REQUEST_BLOCK pSrb
  1321. )
  1322. //////////////////////////////////////////////////////////////////////////////
  1323. {
  1324. PSTREAM pStream = (PSTREAM) pSrb->StreamObject->HwStreamExtension;
  1325. pStream->hClock = pSrb->CommandData.MasterClockHandle;
  1326. }
  1327. //////////////////////////////////////////////////////////////////////////////
  1328. VOID
  1329. STREAMAPI
  1330. ReceiveCtrlPacket(
  1331. IN PHW_STREAM_REQUEST_BLOCK pSrb
  1332. )
  1333. //////////////////////////////////////////////////////////////////////////////
  1334. {
  1335. PSLIP_FILTER pFilter = (PSLIP_FILTER) pSrb->HwDeviceExtension;
  1336. PSTREAM pStream = (PSTREAM) pSrb->StreamObject->HwStreamExtension;
  1337. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: Receive Control packet handler called\n"));
  1338. pSrb->Status = STATUS_SUCCESS;
  1339. QueueAdd (pSrb, &pFilter->StreamControlSpinLock, &pFilter->StreamControlQueue);
  1340. TEST_DEBUG( TEST_DBG_SRB, ("SLIP Queuing Control Packet SRB %08X\n", pSrb));
  1341. while (QueueRemove (&pSrb, &pFilter->StreamControlSpinLock, &pFilter->StreamControlQueue))
  1342. {
  1343. //
  1344. // determine the type of packet.
  1345. //
  1346. switch (pSrb->Command)
  1347. {
  1348. case SRB_PROPOSE_DATA_FORMAT:
  1349. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: Receive Control packet handler - Propose data format\n"));
  1350. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  1351. break;
  1352. case SRB_SET_STREAM_STATE:
  1353. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: Receive Control packet handler - Set Stream State\n"));
  1354. pSrb->Status = STATUS_SUCCESS;
  1355. SlipSetState (pSrb);
  1356. break;
  1357. case SRB_GET_STREAM_STATE:
  1358. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: Receive Control packet handler - Get Stream State\n"));
  1359. pSrb->Status = STATUS_SUCCESS;
  1360. pSrb->CommandData.StreamState = pStream->KSState;
  1361. pSrb->ActualBytesTransferred = sizeof (KSSTATE);
  1362. break;
  1363. case SRB_GET_STREAM_PROPERTY:
  1364. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: Receive Control packet handler - Get Stream Property\n"));
  1365. SlipGetProperty(pSrb);
  1366. break;
  1367. case SRB_SET_STREAM_PROPERTY:
  1368. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: Receive Control packet handler - Set Stream Property\n"));
  1369. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  1370. break;
  1371. case SRB_INDICATE_MASTER_CLOCK:
  1372. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: Receive Control packet handler - Indicate Master Clock\n"));
  1373. pSrb->Status = STATUS_SUCCESS;
  1374. IndicateMasterClock (pSrb);
  1375. break;
  1376. case SRB_SET_STREAM_RATE:
  1377. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: Receive Control packet handler - Set Stream Rate\n"));
  1378. pSrb->Status = STATUS_SUCCESS;
  1379. break;
  1380. case SRB_PROPOSE_STREAM_RATE:
  1381. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: Receive Control packet handler - Propose Stream Rate\n"));
  1382. pSrb->Status = STATUS_SUCCESS;
  1383. break;
  1384. default:
  1385. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: Receive Control packet handler - Default case\n"));
  1386. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  1387. break;
  1388. }
  1389. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: SRB Status returned: %08X\n", pSrb->Status));
  1390. StreamClassStreamNotification (StreamRequestComplete, pSrb->StreamObject, pSrb);
  1391. TEST_DEBUG( TEST_DBG_SRB, ("SLIP 29Completed SRB %08X\n", pSrb));
  1392. }
  1393. }
  1394. //////////////////////////////////////////////////////////////////////////////
  1395. VOID
  1396. SlipSetState(
  1397. PHW_STREAM_REQUEST_BLOCK pSrb
  1398. )
  1399. //////////////////////////////////////////////////////////////////////////////
  1400. {
  1401. PSLIP_FILTER pFilter = ((PSLIP_FILTER) pSrb->HwDeviceExtension);
  1402. PSTREAM pStream = (PSTREAM) pSrb->StreamObject->HwStreamExtension;
  1403. PHW_STREAM_REQUEST_BLOCK pCurrentSrb = NULL;
  1404. //
  1405. // For each stream, the following states are used:
  1406. //
  1407. // Stop: Absolute minimum resources are used. No outstanding IRPs.
  1408. // Acquire: KS only state that has no DirectShow correpondence
  1409. // Acquire needed resources.
  1410. // Pause: Getting ready to run. Allocate needed resources so that
  1411. // the eventual transition to Run is as fast as possible.
  1412. // Read SRBs will be queued at either the Stream class
  1413. // or in your driver (depending on when you send "ReadyForNext")
  1414. // Run: Streaming.
  1415. //
  1416. // Moving to Stop to Run always transitions through Pause.
  1417. //
  1418. // But since a client app could crash unexpectedly, drivers should handle
  1419. // the situation of having outstanding IRPs cancelled and open streams
  1420. // being closed WHILE THEY ARE STREAMING!
  1421. //
  1422. // Note that it is quite possible to transition repeatedly between states:
  1423. // Stop -> Pause -> Stop -> Pause -> Run -> Pause -> Run -> Pause -> Stop
  1424. //
  1425. switch (pSrb->CommandData.StreamState)
  1426. {
  1427. case KSSTATE_STOP:
  1428. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: Set Stream State KSSTATE_STOP\n"));
  1429. //
  1430. // If transitioning to STOP state, then complete any outstanding IRPs
  1431. //
  1432. while (QueueRemove(&pCurrentSrb, &pFilter->IpV4StreamDataSpinLock, &pFilter->IpV4StreamDataQueue))
  1433. {
  1434. pCurrentSrb->Status = STATUS_CANCELLED;
  1435. pCurrentSrb->CommandData.DataBufferArray->DataUsed = 0;
  1436. StreamClassStreamNotification(StreamRequestComplete, pCurrentSrb->StreamObject, pCurrentSrb);
  1437. TEST_DEBUG( TEST_DBG_SRB, ("SLIP 30Completed SRB %08X\n", pCurrentSrb));
  1438. }
  1439. pStream->KSState = pSrb->CommandData.StreamState;
  1440. pSrb->Status = STATUS_SUCCESS;
  1441. break;
  1442. case KSSTATE_ACQUIRE:
  1443. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: Set Stream State KSSTATE_ACQUIRE\n"));
  1444. pStream->KSState = pSrb->CommandData.StreamState;
  1445. pSrb->Status = STATUS_SUCCESS;
  1446. break;
  1447. case KSSTATE_PAUSE:
  1448. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: Set Stream State KSSTATE_PAUSE\n"));
  1449. pStream->KSState = pSrb->CommandData.StreamState;
  1450. pSrb->Status = STATUS_SUCCESS;
  1451. break;
  1452. case KSSTATE_RUN:
  1453. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: Set Stream State KSSTATE_RUN\n"));
  1454. pStream->KSState = pSrb->CommandData.StreamState;
  1455. pSrb->Status = STATUS_SUCCESS;
  1456. break;
  1457. } // end switch (pSrb->CommandData.StreamState)
  1458. return;
  1459. }