Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1736 lines
60 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. QueueRemove (
  534. IN OUT PHW_STREAM_REQUEST_BLOCK * pSrb,
  535. IN PKSPIN_LOCK pQueueSpinLock,
  536. IN PLIST_ENTRY pQueue
  537. )
  538. //////////////////////////////////////////////////////////////////////////////
  539. {
  540. KIRQL Irql;
  541. BOOL bRemovedSRB = FALSE;
  542. KeAcquireSpinLock (pQueueSpinLock, &Irql);
  543. *pSrb = (PHW_STREAM_REQUEST_BLOCK) NULL;
  544. if( !IsListEmpty( pQueue ))
  545. {
  546. PUCHAR Ptr = (PUCHAR) RemoveHeadList(pQueue);
  547. PSRB_EXTENSION pSRBExtension = CONTAINING_RECORD(Ptr,SRB_EXTENSION, ListEntry );
  548. *pSrb = (pSRBExtension->pSrb);
  549. bRemovedSRB = TRUE;
  550. }
  551. KeReleaseSpinLock (pQueueSpinLock, Irql);
  552. return bRemovedSRB;
  553. }
  554. //////////////////////////////////////////////////////////////////////////////
  555. BOOL STREAMAPI
  556. QueueRemoveSpecific (
  557. IN PHW_STREAM_REQUEST_BLOCK pSrb,
  558. IN PKSPIN_LOCK pQueueSpinLock,
  559. IN PLIST_ENTRY pQueue
  560. )
  561. //////////////////////////////////////////////////////////////////////////////
  562. {
  563. KIRQL Irql;
  564. BOOL bRemovedSRB = FALSE;
  565. PLIST_ENTRY pCurrentEntry;
  566. PHW_STREAM_REQUEST_BLOCK pCurrentSrb;
  567. KeAcquireSpinLock( pQueueSpinLock, &Irql );
  568. if( !IsListEmpty( pQueue ))
  569. {
  570. pCurrentEntry = pQueue->Flink;
  571. while ((pCurrentEntry != pQueue ) && !bRemovedSRB)
  572. {
  573. PSRB_EXTENSION pSRBExtension = CONTAINING_RECORD(pCurrentEntry,SRB_EXTENSION, ListEntry );
  574. pCurrentSrb = pSRBExtension->pSrb;
  575. if( pCurrentSrb == pSrb )
  576. {
  577. RemoveEntryList( pCurrentEntry );
  578. bRemovedSRB = TRUE;
  579. }
  580. pCurrentEntry = pCurrentEntry->Flink;
  581. }
  582. }
  583. KeReleaseSpinLock( pQueueSpinLock, Irql );
  584. return bRemovedSRB;
  585. }
  586. //////////////////////////////////////////////////////////////////////////////
  587. BOOL
  588. CompareGUIDsAndFormatSize(
  589. IN PKSDATARANGE pDataRange1,
  590. IN PKSDATARANGE pDataRange2,
  591. BOOLEAN bCheckSize
  592. )
  593. //////////////////////////////////////////////////////////////////////////////
  594. {
  595. BOOL bResult = FALSE;
  596. if ( IsEqualGUID(&pDataRange1->MajorFormat, &KSDATAFORMAT_TYPE_WILDCARD) ||
  597. IsEqualGUID(&pDataRange2->MajorFormat, &KSDATAFORMAT_TYPE_WILDCARD) ||
  598. IsEqualGUID(&pDataRange1->MajorFormat, &pDataRange2->MajorFormat) )
  599. {
  600. if ( IsEqualGUID(&pDataRange1->SubFormat, &KSDATAFORMAT_SUBTYPE_WILDCARD) ||
  601. IsEqualGUID(&pDataRange2->SubFormat, &KSDATAFORMAT_SUBTYPE_WILDCARD) ||
  602. IsEqualGUID(&pDataRange1->SubFormat, &pDataRange2->SubFormat) )
  603. {
  604. if ( IsEqualGUID(&pDataRange1->Specifier, &KSDATAFORMAT_SPECIFIER_WILDCARD) ||
  605. IsEqualGUID(&pDataRange2->Specifier, &KSDATAFORMAT_SPECIFIER_WILDCARD) ||
  606. IsEqualGUID(&pDataRange1->Specifier, &pDataRange2->Specifier) )
  607. {
  608. if ( !bCheckSize || pDataRange1->FormatSize == pDataRange2->FormatSize)
  609. {
  610. bResult = TRUE;
  611. }
  612. }
  613. }
  614. }
  615. return bResult;
  616. }
  617. //////////////////////////////////////////////////////////////////////////////
  618. VOID
  619. DumpDataFormat (
  620. PKSDATAFORMAT pF
  621. )
  622. //////////////////////////////////////////////////////////////////////////////
  623. {
  624. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: DATA Format\n"));
  625. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: Format Size: %08X\n", pF->FormatSize));
  626. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: Flags: %08X\n", pF->Flags));
  627. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: SampleSize: %08X\n", pF->SampleSize));
  628. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: Reserved: %08X\n", pF->Reserved));
  629. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: Major GUID: %08X %04X %04X %02X %02X %02X %02X %02X %02X %02X %02X\n",
  630. pF->MajorFormat.Data1,
  631. pF->MajorFormat.Data2,
  632. pF->MajorFormat.Data3,
  633. pF->MajorFormat.Data4[0],
  634. pF->MajorFormat.Data4[1],
  635. pF->MajorFormat.Data4[2],
  636. pF->MajorFormat.Data4[3],
  637. pF->MajorFormat.Data4[4],
  638. pF->MajorFormat.Data4[5],
  639. pF->MajorFormat.Data4[6],
  640. pF->MajorFormat.Data4[7]
  641. ));
  642. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: Sub GUID: %08X %04X %04X %02X %02X %02X %02X %02X %02X %02X %02X\n",
  643. pF->SubFormat.Data1,
  644. pF->SubFormat.Data2,
  645. pF->SubFormat.Data3,
  646. pF->SubFormat.Data4[0],
  647. pF->SubFormat.Data4[1],
  648. pF->SubFormat.Data4[2],
  649. pF->SubFormat.Data4[3],
  650. pF->SubFormat.Data4[4],
  651. pF->SubFormat.Data4[5],
  652. pF->SubFormat.Data4[6],
  653. pF->SubFormat.Data4[7]
  654. ));
  655. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: Specifier: %08X %04X %04X %02X %02X %02X %02X %02X %02X %02X %02X\n",
  656. pF->Specifier.Data1,
  657. pF->Specifier.Data2,
  658. pF->Specifier.Data3,
  659. pF->Specifier.Data4[0],
  660. pF->Specifier.Data4[1],
  661. pF->Specifier.Data4[2],
  662. pF->Specifier.Data4[3],
  663. pF->Specifier.Data4[4],
  664. pF->Specifier.Data4[5],
  665. pF->Specifier.Data4[6],
  666. pF->Specifier.Data4[7]
  667. ));
  668. TEST_DEBUG (TEST_DBG_TRACE, ("\n"));
  669. }
  670. //////////////////////////////////////////////////////////////////////////////
  671. BOOL
  672. CompareStreamFormat (
  673. IN PHW_STREAM_REQUEST_BLOCK pSrb
  674. )
  675. //////////////////////////////////////////////////////////////////////////////
  676. {
  677. BOOL bStatus = FALSE;
  678. PSTREAM_DATA_INTERSECT_INFO pIntersectInfo;
  679. PKSDATARANGE pDataRange1;
  680. PKSDATARANGE pDataRange2;
  681. ULONG FormatSize = 0;
  682. ULONG ulStreamNumber;
  683. ULONG j;
  684. ULONG ulNumberOfFormatArrayEntries;
  685. PKSDATAFORMAT *pAvailableFormats;
  686. pIntersectInfo = pSrb->CommandData.IntersectInfo;
  687. ulStreamNumber = pIntersectInfo->StreamNumber;
  688. pSrb->ActualBytesTransferred = 0;
  689. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: Comparing Stream Formats\n"));
  690. //
  691. // Check that the stream number is valid
  692. //
  693. if (ulStreamNumber < DRIVER_STREAM_COUNT)
  694. {
  695. ulNumberOfFormatArrayEntries = Streams[ulStreamNumber].hwStreamInfo.NumberOfFormatArrayEntries;
  696. //
  697. // Get the pointer to the array of available formats
  698. //
  699. pAvailableFormats = Streams[ulStreamNumber].hwStreamInfo.StreamFormatsArray;
  700. //
  701. // Walk the formats supported by the stream searching for a match
  702. // of the three GUIDs which together define a DATARANGE
  703. //
  704. for (pDataRange1 = pIntersectInfo->DataRange, j = 0;
  705. j < ulNumberOfFormatArrayEntries;
  706. j++, pAvailableFormats++)
  707. {
  708. bStatus = FALSE;
  709. pSrb->Status = STATUS_UNSUCCESSFUL;
  710. pDataRange2 = *pAvailableFormats;
  711. if (CompareGUIDsAndFormatSize (pDataRange1, pDataRange2, TRUE))
  712. {
  713. ULONG ulFormatSize = pDataRange2->FormatSize;
  714. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: Stream Formats compare\n"));
  715. //
  716. // Is the caller trying to get the format, or the size of the format?
  717. //
  718. if (pIntersectInfo->SizeOfDataFormatBuffer == sizeof (ULONG))
  719. {
  720. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: Returning Stream Format size\n"));
  721. *(PULONG) pIntersectInfo->DataFormatBuffer = ulFormatSize;
  722. pSrb->ActualBytesTransferred = sizeof (ULONG);
  723. pSrb->Status = STATUS_SUCCESS;
  724. bStatus = TRUE;
  725. }
  726. else
  727. {
  728. //
  729. // Verify that there is enough room in the supplied buffer for the whole thing
  730. //
  731. pSrb->Status = STATUS_BUFFER_TOO_SMALL;
  732. bStatus = FALSE;
  733. if (pIntersectInfo->SizeOfDataFormatBuffer >= ulFormatSize)
  734. {
  735. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: Returning Stream Format\n"));
  736. RtlCopyMemory (pIntersectInfo->DataFormatBuffer, pDataRange2, ulFormatSize);
  737. pSrb->ActualBytesTransferred = ulFormatSize;
  738. pSrb->Status = STATUS_SUCCESS;
  739. bStatus = TRUE;
  740. }
  741. else
  742. {
  743. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: Stream Format return buffer too small\n"));
  744. }
  745. }
  746. break;
  747. }
  748. else
  749. {
  750. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: Stream Formats DO NOT compare\n"));
  751. }
  752. }
  753. if ( j >= ulNumberOfFormatArrayEntries )
  754. {
  755. pSrb->ActualBytesTransferred = 0;
  756. pSrb->Status = STATUS_UNSUCCESSFUL;
  757. bStatus = FALSE;
  758. }
  759. }
  760. else
  761. {
  762. pSrb->ActualBytesTransferred = 0;
  763. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  764. bStatus = FALSE;
  765. }
  766. return bStatus;
  767. }
  768. //////////////////////////////////////////////////////////////////////////////
  769. VOID
  770. CloseStream (
  771. PHW_STREAM_REQUEST_BLOCK pSrb
  772. )
  773. //////////////////////////////////////////////////////////////////////////////
  774. {
  775. //
  776. // the stream extension structure is allocated by the stream class driver
  777. //
  778. PSTREAM pStream = (PSTREAM)pSrb->StreamObject->HwStreamExtension;
  779. PSLIP_FILTER pFilter = (PSLIP_FILTER)pSrb->HwDeviceExtension;
  780. ULONG ulStreamNumber = (ULONG) pSrb->StreamObject->StreamNumber;
  781. ULONG ulStreamInstance = pStream->ulStreamInstance;
  782. PHW_STREAM_REQUEST_BLOCK pCurrentSrb = NULL;
  783. //
  784. // check that the stream index requested isn't too high
  785. // or that the maximum number of instances hasn't been exceeded
  786. //
  787. if (ulStreamNumber < DRIVER_STREAM_COUNT )
  788. {
  789. //
  790. // Flush the stream data queue
  791. //
  792. while (QueueRemove( &pCurrentSrb, &pFilter->IpV4StreamDataSpinLock, &pFilter->IpV4StreamDataQueue))
  793. {
  794. pCurrentSrb->Status = STATUS_CANCELLED;
  795. StreamClassStreamNotification( StreamRequestComplete, pCurrentSrb->StreamObject, pCurrentSrb);
  796. TEST_DEBUG( TEST_DBG_SRB, ("SLIP 15Completed SRB %08X\n", pCurrentSrb));
  797. }
  798. //
  799. // Flush the stream data queue
  800. //
  801. while (QueueRemove( &pCurrentSrb, &pFilter->StreamDataSpinLock, &pFilter->StreamDataQueue))
  802. {
  803. pCurrentSrb->Status = STATUS_CANCELLED;
  804. StreamClassStreamNotification( StreamRequestComplete, pCurrentSrb->StreamObject, pCurrentSrb);
  805. TEST_DEBUG( TEST_DBG_SRB, ("SLIP 16Completed SRB %08X\n", pCurrentSrb));
  806. }
  807. //
  808. // Flush the stream control queue
  809. //
  810. while (QueueRemove( &pCurrentSrb, &pFilter->StreamControlSpinLock, &pFilter->StreamControlQueue))
  811. {
  812. pCurrentSrb->Status = STATUS_CANCELLED;
  813. StreamClassStreamNotification (StreamRequestComplete, pCurrentSrb->StreamObject, pCurrentSrb);
  814. TEST_DEBUG( TEST_DBG_SRB, ("SLIP 17Completed SRB %08X\n", pCurrentSrb));
  815. }
  816. //
  817. // Clear this streams spot in the filters stream array
  818. //
  819. pFilter->pStream[ulStreamNumber][ulStreamInstance] = NULL;
  820. //
  821. // decrement the stream instance count for this filter
  822. //
  823. pFilter->ulActualInstances[ulStreamNumber]--;
  824. //
  825. // Indicate the clock support available on this stream
  826. //
  827. //pSrb->StreamObject->HwClockObject = 0;
  828. //
  829. // Reset the stream state to stopped
  830. //
  831. pStream->KSState = KSSTATE_STOP;
  832. //
  833. // Reset the stream extension blob
  834. //
  835. RtlZeroMemory(pStream, sizeof (STREAM));
  836. pSrb->Status = STATUS_SUCCESS;
  837. }
  838. else
  839. {
  840. pSrb->Status = STATUS_INVALID_PARAMETER;
  841. }
  842. }
  843. //////////////////////////////////////////////////////////////////////////////
  844. VOID
  845. OpenStream (
  846. PHW_STREAM_REQUEST_BLOCK pSrb
  847. )
  848. //////////////////////////////////////////////////////////////////////////////
  849. {
  850. //
  851. // the stream extension structure is allocated by the stream class driver
  852. //
  853. PSTREAM pStream = (PSTREAM)pSrb->StreamObject->HwStreamExtension;
  854. PSLIP_FILTER pFilter = ((PSLIP_FILTER)pSrb->HwDeviceExtension);
  855. ULONG ulStreamNumber = (ULONG) pSrb->StreamObject->StreamNumber;
  856. PKSDATAFORMAT pKSDataFormat = (PKSDATAFORMAT)pSrb->CommandData.OpenFormat;
  857. //
  858. // Initialize the stream extension blob
  859. //
  860. //RtlZeroMemory(pStream, sizeof (STREAM));
  861. //
  862. // Initialize stream state
  863. //
  864. //pStream->KSState = KSSTATE_STOP;
  865. //
  866. // Initialize the next stream life check time.
  867. //
  868. KeQuerySystemTime( &pFilter->liLastTimeChecked );
  869. //
  870. // Initialize stats dump time
  871. //
  872. KeQuerySystemTime( &pFilter->liLastTimeStatsDumped );
  873. //
  874. // check that the stream index requested isn't too high
  875. // or that the maximum number of instances hasn't been exceeded
  876. //
  877. if (ulStreamNumber < DRIVER_STREAM_COUNT )
  878. {
  879. ULONG ulStreamInstance;
  880. ULONG ulMaxInstances = Streams[ulStreamNumber].hwStreamInfo.NumberOfPossibleInstances;
  881. //
  882. // Search for next open slot
  883. //
  884. for (ulStreamInstance = 0; ulStreamInstance < ulMaxInstances; ++ulStreamInstance)
  885. {
  886. if (pFilter->pStream[ulStreamNumber][ulStreamInstance] == NULL)
  887. {
  888. break;
  889. }
  890. }
  891. if (ulStreamInstance < ulMaxInstances)
  892. {
  893. if (VerifyFormat(pKSDataFormat, ulStreamNumber, &pStream->MatchedFormat))
  894. {
  895. //
  896. // Initialize Data queues and SpinLocks
  897. //
  898. KeInitializeSpinLock(&(pStream->KSStateSpinLock));
  899. // Maintain an array of all the StreamEx structures in the HwDevExt
  900. // so that we can reference IRPs from any stream
  901. //
  902. pFilter->pStream[ulStreamNumber][ulStreamInstance] = pStream;
  903. //
  904. // Save the Stream Format in the Stream Extension as well.
  905. //
  906. pStream->OpenedFormat = *pKSDataFormat;
  907. //
  908. // Set up pointers to the handlers for the stream data and control handlers
  909. //
  910. pSrb->StreamObject->ReceiveDataPacket =
  911. (PVOID) Streams[ulStreamNumber].hwStreamObject.ReceiveDataPacket;
  912. pSrb->StreamObject->ReceiveControlPacket =
  913. (PVOID) Streams[ulStreamNumber].hwStreamObject.ReceiveControlPacket;
  914. //
  915. // The DMA flag must be set when the device will be performing DMA directly
  916. // to the data buffer addresses passed in to the ReceiveDataPacket routines.
  917. //
  918. pSrb->StreamObject->Dma = Streams[ulStreamNumber].hwStreamObject.Dma;
  919. //
  920. // The PIO flag must be set when the mini driver will be accessing the data
  921. // buffers passed in using logical addressing
  922. //
  923. pSrb->StreamObject->Pio = Streams[ulStreamNumber].hwStreamObject.Pio;
  924. pSrb->StreamObject->Allocator = Streams[ulStreamNumber].hwStreamObject.Allocator;
  925. //
  926. // How many extra bytes will be passed up from the driver for each frame?
  927. //
  928. pSrb->StreamObject->StreamHeaderMediaSpecific =
  929. Streams[ulStreamNumber].hwStreamObject.StreamHeaderMediaSpecific;
  930. pSrb->StreamObject->StreamHeaderWorkspace =
  931. Streams[ulStreamNumber].hwStreamObject.StreamHeaderWorkspace;
  932. //
  933. // Indicate the clock support available on this stream
  934. //
  935. pSrb->StreamObject->HwClockObject =
  936. Streams[ulStreamNumber].hwStreamObject.HwClockObject;
  937. //
  938. // Increment the instance count on this stream
  939. //
  940. pStream->ulStreamInstance = ulStreamInstance;
  941. pFilter->ulActualInstances[ulStreamNumber]++;
  942. //
  943. // Retain a private copy of the HwDevExt and StreamObject in the stream extension
  944. // so we can use a timer
  945. //
  946. pStream->pFilter = pFilter; // For timer use
  947. pStream->pStreamObject = pSrb->StreamObject; // For timer use
  948. pSrb->Status = STATUS_SUCCESS;
  949. }
  950. else
  951. {
  952. pSrb->Status = STATUS_INVALID_PARAMETER;
  953. }
  954. }
  955. else
  956. {
  957. pSrb->Status = STATUS_INVALID_PARAMETER;
  958. }
  959. }
  960. else
  961. {
  962. pSrb->Status = STATUS_INVALID_PARAMETER;
  963. }
  964. }
  965. //////////////////////////////////////////////////////////////////////////////
  966. BOOLEAN
  967. VerifyFormat(
  968. IN KSDATAFORMAT *pKSDataFormat,
  969. UINT StreamNumber,
  970. PKSDATARANGE pMatchedFormat
  971. )
  972. //////////////////////////////////////////////////////////////////////////////
  973. {
  974. BOOLEAN bResult = FALSE;
  975. ULONG FormatCount = 0;
  976. PKS_DATARANGE_VIDEO pThisFormat = NULL;
  977. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: Verify Format\n"));
  978. for (FormatCount = 0; !bResult && FormatCount < Streams[StreamNumber].hwStreamInfo.NumberOfFormatArrayEntries;
  979. FormatCount++ )
  980. {
  981. pThisFormat = (PKS_DATARANGE_VIDEO) Streams [StreamNumber].hwStreamInfo.StreamFormatsArray [FormatCount];
  982. if (CompareGUIDsAndFormatSize( pKSDataFormat, &pThisFormat->DataRange, FALSE ) )
  983. {
  984. bResult = FALSE;
  985. if (pThisFormat->DataRange.SampleSize >= pKSDataFormat->SampleSize)
  986. {
  987. bResult = TRUE;
  988. }
  989. else
  990. {
  991. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: VerifyFormat: Data range Sample Sizes don't match\n"));
  992. }
  993. }
  994. }
  995. if (bResult == TRUE && pMatchedFormat)
  996. {
  997. *pMatchedFormat = pThisFormat->DataRange;
  998. }
  999. return bResult;
  1000. }
  1001. //////////////////////////////////////////////////////////////////////////////
  1002. VOID
  1003. STREAMAPI
  1004. ReceiveDataPacket (
  1005. IN PHW_STREAM_REQUEST_BLOCK pSrb
  1006. )
  1007. //////////////////////////////////////////////////////////////////////////////
  1008. {
  1009. PSLIP_FILTER pFilter = (PSLIP_FILTER) pSrb->HwDeviceExtension;
  1010. PSTREAM pStream = (PSTREAM)pSrb->StreamObject->HwStreamExtension;
  1011. int iStream = (int) pSrb->StreamObject->StreamNumber;
  1012. PKSSTREAM_HEADER pStreamHdr = pSrb->CommandData.DataBufferArray;
  1013. PKSDATAFORMAT pKSDataFormat = (PKSDATAFORMAT) &pStream->MatchedFormat;
  1014. ULONG ul = 0;
  1015. PHW_STREAM_REQUEST_BLOCK pSrbIPv4 = NULL;
  1016. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: Receive Data packet handler called\n"));
  1017. //
  1018. // Default to success, disable timeouts
  1019. //
  1020. pSrb->TimeoutCounter = 0;
  1021. pSrb->Status = STATUS_SUCCESS;
  1022. //
  1023. // Check for last buffer
  1024. //
  1025. if (pStreamHdr->OptionsFlags & KSSTREAM_HEADER_OPTIONSF_ENDOFSTREAM)
  1026. {
  1027. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: Receive Data packet is LAST PACKET\n"));
  1028. StreamClassStreamNotification (StreamRequestComplete, pSrb->StreamObject, pSrb);
  1029. TEST_DEBUG( TEST_DBG_SRB, ("SLIP: Completed SRB %08X\n", pSrb));
  1030. return;
  1031. }
  1032. if (pStreamHdr->OptionsFlags != 0)
  1033. {
  1034. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: OptionsFlags: %08X\n", pStreamHdr->OptionsFlags));
  1035. }
  1036. //
  1037. // determine the type of packet.
  1038. //
  1039. switch (pSrb->Command)
  1040. {
  1041. case SRB_WRITE_DATA:
  1042. if (pStream->KSState == KSSTATE_STOP)
  1043. {
  1044. pSrb->Status = STATUS_SUCCESS;
  1045. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: SRB_WRITE STOP SRB Status returned: %08X\n", pSrb->Status));
  1046. StreamClassStreamNotification (StreamRequestComplete, pSrb->StreamObject, pSrb );
  1047. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: StreamRequestComplete on pSrb: %08X\n", pSrb));
  1048. break;
  1049. }
  1050. //
  1051. // Update the total number of packets written statistic
  1052. //
  1053. pFilter->Stats.ulTotalDataSRBWrites += 1;
  1054. //
  1055. // Handle data input, output requests differently.
  1056. //
  1057. switch (iStream)
  1058. {
  1059. //
  1060. // Frame input stream
  1061. //
  1062. case SLIP_STREAM:
  1063. {
  1064. ULONG ulBuffers = pSrb->NumberOfBuffers;
  1065. PKSSTREAM_HEADER pIPV4StreamHdr = NULL;
  1066. PNABTSFEC_BUFFER pNabData = NULL;
  1067. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: Receive Data packet handler - SRB_WRITE - SLIP_STREAM, Processing pSrb: %08X\n", pSrb));
  1068. //
  1069. // Initialize SRB Status to success
  1070. //
  1071. pSrb->Status = STATUS_SUCCESS;
  1072. //
  1073. // Process each chained buffer of data in the SRB
  1074. //
  1075. for (ul = 0; ul < ulBuffers; ul++, pStreamHdr++)
  1076. {
  1077. if (pStreamHdr)
  1078. {
  1079. //
  1080. // Update stats for IP Stream count
  1081. //
  1082. pFilter->Stats.ulTotalSlipBuffersReceived += 1;
  1083. pFilter->Stats.ulTotalSlipBytesReceived += pStreamHdr->DataUsed;
  1084. pNabData = (PNABTSFEC_BUFFER) pStreamHdr->Data;
  1085. if (pNabData && pStreamHdr->DataUsed > 0)
  1086. {
  1087. TEST_DEBUG (TEST_DBG_WRITE_DATA, ("SLIP: NAB_DATA[%d]....dataSize: %d groupID: %d\n",
  1088. ul,
  1089. pNabData->dataSize,
  1090. pNabData->groupID ));
  1091. if(pNabData->dataSize > sizeof(pNabData->data))
  1092. {
  1093. pSrb->Status = STATUS_SUCCESS;
  1094. pFilter->bDiscontinuity = TRUE;
  1095. break;
  1096. }
  1097. ASSERT(pNabData->dataSize <= sizeof(pNabData->data));
  1098. if ((pSrb->Status = ntNabtsRecv (pFilter, pNabData)) != STATUS_SUCCESS)
  1099. {
  1100. //
  1101. // Something went wrong processing the data (such as running
  1102. // out of output buffers). We'll just complete the input SRB
  1103. // and lose the data. We'll return a successful status to make sure the
  1104. // graph can continue to run. Basically this error amounts to the SRB
  1105. // being tossed out and never processed (ie. a Data Loss).
  1106. //
  1107. pSrb->Status = STATUS_SUCCESS;
  1108. pFilter->bDiscontinuity = TRUE;
  1109. break;
  1110. }
  1111. }
  1112. else
  1113. {
  1114. pFilter->Stats.ulTotalSlipZeroLengthBuffers += 1;
  1115. }
  1116. }
  1117. }
  1118. StreamClassStreamNotification (StreamRequestComplete, pSrb->StreamObject, pSrb);
  1119. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: StreamRequestComplete on pSrb: %08X\n", pSrb));
  1120. }
  1121. break;
  1122. //
  1123. // Other "unknown" streams are not valid and will be rejected.
  1124. //
  1125. default:
  1126. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: Receive Data packet handler called - SRB_WRITE - Default\n"));
  1127. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  1128. //
  1129. // Update stats for Unkown packet count
  1130. //
  1131. pFilter->Stats.ulTotalBadPinSRBWrites += 1;
  1132. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: DEFAULT SRB Status returned: %08X\n", pSrb->Status));
  1133. StreamClassStreamNotification (StreamRequestComplete, pSrb->StreamObject, pSrb);
  1134. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: StreamRequestComplete on pSrb: %08X\n", pSrb));
  1135. break;
  1136. }
  1137. break;
  1138. case SRB_READ_DATA:
  1139. if (pStream->KSState == KSSTATE_STOP)
  1140. {
  1141. pSrb->Status = STATUS_SUCCESS;
  1142. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: SRB_READ STOP SRB Status returned: %08X\n", pSrb->Status));
  1143. StreamClassStreamNotification (StreamRequestComplete, pSrb->StreamObject, pSrb );
  1144. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: StreamRequestComplete on pSrb: %08X\n", pSrb));
  1145. break;
  1146. }
  1147. //
  1148. // Update stats
  1149. //
  1150. pFilter->Stats.ulTotalDataSRBReads += 1;
  1151. switch (iStream)
  1152. {
  1153. case SLIP_IPV4:
  1154. {
  1155. ULONG ulBuffers = pSrb->NumberOfBuffers;
  1156. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: Receive Data packet handler called - SRB_READ - SLIP_IPV4, Processing pSrb: %08X\n", pSrb));
  1157. if (pSrb->CommandData.DataBufferArray->FrameExtent < pKSDataFormat->SampleSize)
  1158. {
  1159. pSrb->Status = STATUS_BUFFER_TOO_SMALL;
  1160. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: SLIP_IPV4 SRB Buffer too small.... Status returned: %08X\n", pSrb->Status));
  1161. StreamClassStreamNotification(StreamRequestComplete, pSrb->StreamObject, pSrb);
  1162. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: StreamRequestComplete on pSrb: %08X\n", pSrb));
  1163. }
  1164. else
  1165. {
  1166. //
  1167. // Take the SRB we get and queue it up. These Queued SRB's will be filled with data on a WRITE_DATA
  1168. // request, at which point they will be completed.
  1169. //
  1170. QueueAdd (pSrb, &pFilter->IpV4StreamDataSpinLock, &pFilter->IpV4StreamDataQueue);
  1171. TEST_DEBUG( TEST_DBG_SRB, ("SLIP Queuing IPv4 SRB %08X\n", pSrb));
  1172. //
  1173. // Since the stream state may have changed while we were adding the SRB to the queue
  1174. // we'll check it again, and cancel it if necessary
  1175. //
  1176. if (pStream->KSState == KSSTATE_STOP)
  1177. {
  1178. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: SRB_READ STOP SRB Status returned: %08X\n", pSrb->Status));
  1179. if (QueueRemoveSpecific (pSrb, &pFilter->IpV4StreamDataSpinLock, &pFilter->IpV4StreamDataQueue))
  1180. {
  1181. pSrb->Status = STATUS_CANCELLED;
  1182. StreamClassStreamNotification (StreamRequestComplete, pSrb->StreamObject, pSrb );
  1183. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: StreamRequestComplete on pSrb: %08X\n", pSrb));
  1184. return;
  1185. }
  1186. break;
  1187. }
  1188. }
  1189. }
  1190. break;
  1191. default:
  1192. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: Receive Data packet handler called - SRB_READ - Default\n"));
  1193. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  1194. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: DEFAULT SRB Status returned: %08X\n", pSrb->Status));
  1195. //
  1196. // Update stats for Unkown packet count
  1197. //
  1198. pFilter->Stats.ulTotalBadPinSRBReads += 1;
  1199. StreamClassStreamNotification (StreamRequestComplete, pSrb->StreamObject, pSrb);
  1200. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: StreamRequestComplete on pSrb: %08X\n", pSrb));
  1201. break;
  1202. }
  1203. break;
  1204. default:
  1205. //
  1206. // invalid / unsupported command. Fail it as such
  1207. //
  1208. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: Receive Data packet handler called - Unsupported Command\n"));
  1209. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  1210. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: DEFAULT SRB Status returned: %08X\n", pSrb->Status));
  1211. StreamClassStreamNotification( StreamRequestComplete, pSrb->StreamObject, pSrb );
  1212. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: StreamRequestComplete on pSrb: %08X\n", pSrb));
  1213. ASSERT (FALSE);
  1214. break;
  1215. }
  1216. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: Receive Data packet handler called...status: %08X\n", pSrb->Status));
  1217. return;
  1218. }
  1219. //////////////////////////////////////////////////////////////////////////////
  1220. VOID
  1221. SlipGetProperty (
  1222. PHW_STREAM_REQUEST_BLOCK pSrb
  1223. )
  1224. //////////////////////////////////////////////////////////////////////////////
  1225. {
  1226. PSTREAM_PROPERTY_DESCRIPTOR pSPD = pSrb->CommandData.PropertyInfo;
  1227. pSrb->Status = STATUS_SUCCESS;
  1228. if (IsEqualGUID (&KSPROPSETID_Connection, &pSPD->Property->Set))
  1229. {
  1230. SlipGetConnectionProperty (pSrb);
  1231. }
  1232. else
  1233. {
  1234. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  1235. }
  1236. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: SlipGetProperty Status: %08X\n", pSrb->Status));
  1237. return;
  1238. }
  1239. //////////////////////////////////////////////////////////////////////////////
  1240. VOID
  1241. IndicateMasterClock(
  1242. PHW_STREAM_REQUEST_BLOCK pSrb
  1243. )
  1244. //////////////////////////////////////////////////////////////////////////////
  1245. {
  1246. PSTREAM pStream = (PSTREAM) pSrb->StreamObject->HwStreamExtension;
  1247. }
  1248. //////////////////////////////////////////////////////////////////////////////
  1249. VOID
  1250. STREAMAPI
  1251. ReceiveCtrlPacket(
  1252. IN PHW_STREAM_REQUEST_BLOCK pSrb
  1253. )
  1254. //////////////////////////////////////////////////////////////////////////////
  1255. {
  1256. PSLIP_FILTER pFilter = (PSLIP_FILTER) pSrb->HwDeviceExtension;
  1257. PSTREAM pStream = (PSTREAM) pSrb->StreamObject->HwStreamExtension;
  1258. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: Receive Control packet handler called\n"));
  1259. pSrb->Status = STATUS_SUCCESS;
  1260. QueueAdd (pSrb, &pFilter->StreamControlSpinLock, &pFilter->StreamControlQueue);
  1261. TEST_DEBUG( TEST_DBG_SRB, ("SLIP Queuing Control Packet SRB %08X\n", pSrb));
  1262. while (QueueRemove (&pSrb, &pFilter->StreamControlSpinLock, &pFilter->StreamControlQueue))
  1263. {
  1264. //
  1265. // determine the type of packet.
  1266. //
  1267. switch (pSrb->Command)
  1268. {
  1269. case SRB_PROPOSE_DATA_FORMAT:
  1270. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: Receive Control packet handler - Propose data format\n"));
  1271. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  1272. break;
  1273. case SRB_SET_STREAM_STATE:
  1274. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: Receive Control packet handler - Set Stream State\n"));
  1275. pSrb->Status = STATUS_SUCCESS;
  1276. SlipSetState (pSrb);
  1277. break;
  1278. case SRB_GET_STREAM_STATE:
  1279. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: Receive Control packet handler - Get Stream State\n"));
  1280. pSrb->Status = STATUS_SUCCESS;
  1281. pSrb->CommandData.StreamState = pStream->KSState;
  1282. pSrb->ActualBytesTransferred = sizeof (KSSTATE);
  1283. break;
  1284. case SRB_GET_STREAM_PROPERTY:
  1285. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: Receive Control packet handler - Get Stream Property\n"));
  1286. SlipGetProperty(pSrb);
  1287. break;
  1288. case SRB_SET_STREAM_PROPERTY:
  1289. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: Receive Control packet handler - Set Stream Property\n"));
  1290. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  1291. break;
  1292. case SRB_INDICATE_MASTER_CLOCK:
  1293. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: Receive Control packet handler - Indicate Master Clock\n"));
  1294. pSrb->Status = STATUS_SUCCESS;
  1295. IndicateMasterClock (pSrb);
  1296. break;
  1297. case SRB_SET_STREAM_RATE:
  1298. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: Receive Control packet handler - Set Stream Rate\n"));
  1299. pSrb->Status = STATUS_SUCCESS;
  1300. break;
  1301. case SRB_PROPOSE_STREAM_RATE:
  1302. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: Receive Control packet handler - Propose Stream Rate\n"));
  1303. pSrb->Status = STATUS_SUCCESS;
  1304. break;
  1305. default:
  1306. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: Receive Control packet handler - Default case\n"));
  1307. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  1308. break;
  1309. }
  1310. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: SRB Status returned: %08X\n", pSrb->Status));
  1311. StreamClassStreamNotification (StreamRequestComplete, pSrb->StreamObject, pSrb);
  1312. TEST_DEBUG( TEST_DBG_SRB, ("SLIP 29Completed SRB %08X\n", pSrb));
  1313. }
  1314. }
  1315. //////////////////////////////////////////////////////////////////////////////
  1316. VOID
  1317. SlipSetState(
  1318. PHW_STREAM_REQUEST_BLOCK pSrb
  1319. )
  1320. //////////////////////////////////////////////////////////////////////////////
  1321. {
  1322. PSLIP_FILTER pFilter = ((PSLIP_FILTER) pSrb->HwDeviceExtension);
  1323. PSTREAM pStream = (PSTREAM) pSrb->StreamObject->HwStreamExtension;
  1324. PHW_STREAM_REQUEST_BLOCK pCurrentSrb = NULL;
  1325. //
  1326. // For each stream, the following states are used:
  1327. //
  1328. // Stop: Absolute minimum resources are used. No outstanding IRPs.
  1329. // Acquire: KS only state that has no DirectShow correpondence
  1330. // Acquire needed resources.
  1331. // Pause: Getting ready to run. Allocate needed resources so that
  1332. // the eventual transition to Run is as fast as possible.
  1333. // Read SRBs will be queued at either the Stream class
  1334. // or in your driver (depending on when you send "ReadyForNext")
  1335. // Run: Streaming.
  1336. //
  1337. // Moving to Stop to Run always transitions through Pause.
  1338. //
  1339. // But since a client app could crash unexpectedly, drivers should handle
  1340. // the situation of having outstanding IRPs cancelled and open streams
  1341. // being closed WHILE THEY ARE STREAMING!
  1342. //
  1343. // Note that it is quite possible to transition repeatedly between states:
  1344. // Stop -> Pause -> Stop -> Pause -> Run -> Pause -> Run -> Pause -> Stop
  1345. //
  1346. KIRQL Irql= {0};
  1347. KeAcquireSpinLock (&(pStream->KSStateSpinLock), &Irql);
  1348. switch (pSrb->CommandData.StreamState)
  1349. {
  1350. case KSSTATE_STOP:
  1351. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: Set Stream State KSSTATE_STOP\n"));
  1352. //
  1353. // If transitioning to STOP state, then complete any outstanding IRPs
  1354. //
  1355. while (QueueRemove(&pCurrentSrb, &pFilter->IpV4StreamDataSpinLock, &pFilter->IpV4StreamDataQueue))
  1356. {
  1357. pCurrentSrb->Status = STATUS_CANCELLED;
  1358. pCurrentSrb->CommandData.DataBufferArray->DataUsed = 0;
  1359. StreamClassStreamNotification(StreamRequestComplete, pCurrentSrb->StreamObject, pCurrentSrb);
  1360. TEST_DEBUG( TEST_DBG_SRB, ("SLIP 30Completed SRB %08X\n", pCurrentSrb));
  1361. }
  1362. pStream->KSState = pSrb->CommandData.StreamState;
  1363. pSrb->Status = STATUS_SUCCESS;
  1364. break;
  1365. case KSSTATE_ACQUIRE:
  1366. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: Set Stream State KSSTATE_ACQUIRE\n"));
  1367. pStream->KSState = pSrb->CommandData.StreamState;
  1368. pSrb->Status = STATUS_SUCCESS;
  1369. break;
  1370. case KSSTATE_PAUSE:
  1371. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: Set Stream State KSSTATE_PAUSE\n"));
  1372. pStream->KSState = pSrb->CommandData.StreamState;
  1373. pSrb->Status = STATUS_SUCCESS;
  1374. break;
  1375. case KSSTATE_RUN:
  1376. TEST_DEBUG (TEST_DBG_TRACE, ("SLIP: Set Stream State KSSTATE_RUN\n"));
  1377. pStream->KSState = pSrb->CommandData.StreamState;
  1378. pSrb->Status = STATUS_SUCCESS;
  1379. break;
  1380. } // end switch (pSrb->CommandData.StreamState)
  1381. KeReleaseSpinLock (&(pStream->KSStateSpinLock), Irql);
  1382. return;
  1383. }