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.

413 lines
10 KiB

  1. //---------------------------------------------------------------------------
  2. // Bda Topology Implementation Internal Structures
  3. //
  4. // Minidriver code should not attempt to access these structures
  5. // directly.
  6. //
  7. //---------------------------------------------------------------------------
  8. #define FILTERNAME "BdaTopology"
  9. #define DYNAMIC_TOPOLOGY TRUE
  10. #if defined(__cplusplus)
  11. extern "C" {
  12. #endif // defined(__cplusplus)
  13. //===========================================================================
  14. //
  15. // MACRO definitions
  16. //
  17. //===========================================================================
  18. #define BDA_PIN_STORAGE_INCREMENT 5
  19. //===========================================================================
  20. //
  21. // Advance declarations
  22. //
  23. //===========================================================================
  24. typedef struct _BDA_PIN_FACTORY_CONTEXT BDA_PIN_FACTORY_CONTEXT,
  25. *PBDA_PIN_FACTORY_CONTEXT;
  26. //===========================================================================
  27. //
  28. // BDA Object Context Structures
  29. //
  30. //===========================================================================
  31. typedef struct _BDA_CONTEXT_ENTRY
  32. {
  33. PVOID pvReference;
  34. PVOID pvContext;
  35. ULONG ulcbContext;
  36. } BDA_CONTEXT_ENTRY, * PBDA_CONTEXT_ENTRY;
  37. typedef struct _BDA_CONTEXT_LIST
  38. {
  39. ULONG ulcListEntries;
  40. ULONG ulcMaxListEntries;
  41. ULONG ulcListEntriesPerBlock;
  42. PBDA_CONTEXT_ENTRY pListEntries;
  43. KSPIN_LOCK lock;
  44. BOOLEAN fInitialized;
  45. } BDA_CONTEXT_LIST, * PBDA_CONTEXT_LIST;
  46. typedef struct _BDA_TEMPLATE_PATH
  47. {
  48. LIST_ENTRY leLinkage;
  49. ULONG ulInputPinType;
  50. ULONG ulOutputPinType;
  51. ULONG uliJoint;
  52. ULONG ulcControlNodesInPath;
  53. PULONG argulControlNodesInPath;
  54. } BDA_TEMPLATE_PATH, * PBDA_TEMPLATE_PATH;
  55. __inline NTSTATUS
  56. NewBdaTemplatePath(
  57. PBDA_TEMPLATE_PATH * ppTemplatePath
  58. )
  59. {
  60. NTSTATUS status = STATUS_SUCCESS;
  61. if (!ppTemplatePath)
  62. {
  63. status = STATUS_INVALID_PARAMETER;
  64. goto errExit;
  65. }
  66. *ppTemplatePath = (PBDA_TEMPLATE_PATH) ExAllocatePool(
  67. NonPagedPool,
  68. sizeof( BDA_TEMPLATE_PATH)
  69. );
  70. if (!*ppTemplatePath)
  71. {
  72. status = STATUS_INSUFFICIENT_RESOURCES;
  73. goto errExit;
  74. }
  75. RtlZeroMemory( *ppTemplatePath, sizeof( BDA_TEMPLATE_PATH));
  76. InitializeListHead( &(*ppTemplatePath)->leLinkage);
  77. errExit:
  78. return status;
  79. }
  80. __inline NTSTATUS
  81. DeleteBdaTemplatePath(
  82. PBDA_TEMPLATE_PATH pTemplatePath
  83. )
  84. {
  85. NTSTATUS status = STATUS_SUCCESS;
  86. if (!pTemplatePath)
  87. {
  88. status = STATUS_INVALID_PARAMETER;
  89. goto errExit;
  90. }
  91. if (pTemplatePath->argulControlNodesInPath)
  92. {
  93. ExFreePool( pTemplatePath->argulControlNodesInPath);
  94. pTemplatePath->argulControlNodesInPath = NULL;
  95. }
  96. RtlZeroMemory( pTemplatePath, sizeof( BDA_TEMPLATE_PATH));
  97. ExFreePool( pTemplatePath);
  98. errExit:
  99. return status;
  100. }
  101. typedef struct _BDA_DEVICE_CONTEXT
  102. {
  103. ULONG ulStartEmpty;
  104. //$BUG Add global statistics
  105. } BDA_DEVICE_CONTEXT, *PBDA_DEVICE_CONTEXT;
  106. typedef struct _BDA_PATH_STACK_ENTRY
  107. {
  108. ULONG ulHop;
  109. ULONG uliConnection;
  110. BOOLEAN fJoint;
  111. } BDA_PATH_STACK_ENTRY, *PBDA_PATH_STACK_ENTRY;
  112. typedef struct _BDA_NODE_CONTROL_INFO
  113. {
  114. ULONG ulNodeType;
  115. ULONG ulControllingPinType;
  116. } BDA_NODE_CONTROL_INFO, * PBDA_NODE_CONTROL_INFO;
  117. typedef struct _BDA_PATH_INFO
  118. {
  119. ULONG ulInputPin;
  120. ULONG ulOutputPin;
  121. ULONG ulcPathEntries;
  122. BDA_PATH_STACK_ENTRY rgPathEntries[MIN_DIMENSION];
  123. } BDA_PATH_INFO, * PBDA_PATH_INFO;
  124. typedef struct _BDA_FILTER_FACTORY_CONTEXT
  125. {
  126. const BDA_FILTER_TEMPLATE * pBdaFilterTemplate;
  127. const KSFILTER_DESCRIPTOR * pInitialFilterDescriptor;
  128. PKSFILTERFACTORY pKSFilterFactory;
  129. } BDA_FILTER_FACTORY_CONTEXT, *PBDA_FILTER_FACTORY_CONTEXT;
  130. typedef struct _BDA_FILTER_CONTEXT
  131. {
  132. PKSFILTER pKSFilter;
  133. const BDA_FILTER_TEMPLATE * pBdaFilterTemplate;
  134. // Pins are added as they are created.
  135. // Note! If the filter has m pin factories included in the
  136. // initial filter descriptor then the first m entries in this array
  137. // will contain null pointers.
  138. //
  139. ULONG ulcPinFactories;
  140. ULONG ulcPinFactoriesMax;
  141. PBDA_PIN_FACTORY_CONTEXT argPinFactoryCtx;
  142. // One node path will exist for each pin pairing.
  143. //
  144. //$REVIEW - Should we allow more than one path per pin pair?
  145. //
  146. ULONG ulcPathInfo;
  147. PBDA_PATH_INFO * argpPathInfo;
  148. } BDA_FILTER_CONTEXT, *PBDA_FILTER_CONTEXT;
  149. typedef struct _BDA_PIN_FACTORY_CONTEXT
  150. {
  151. ULONG ulPinType;
  152. ULONG ulPinFactoryId;
  153. } BDA_PIN_FACTORY_CONTEXT, *PBDA_PIN_FACTORY_CONTEXT;
  154. typedef struct _BDA_NODE_CONTEXT
  155. {
  156. ULONG ulStartEmpty;
  157. } BDA_NODE_CONTEXT, *PBDA_NODE_CONTEXT;
  158. //---------------------------------------------------------------------------
  159. // BDA Topology Implementation Internal Functions
  160. //
  161. // Minidriver code should not call these routines directly.
  162. //
  163. //---------------------------------------------------------------------------
  164. /*
  165. ** BdaFindPinPair()
  166. **
  167. ** Returns a pointer to the BDA_PIN_PAIRING that corresponds
  168. ** to the given input and output pins.
  169. **
  170. ** Arguments:
  171. **
  172. ** pTopology Pointer to the BDA topology that contains the
  173. ** pin pairing.
  174. **
  175. ** InputPinId Id of the input Pin to match
  176. **
  177. ** OutputPinId Id of the output Pin to match
  178. **
  179. ** Returns:
  180. **
  181. ** pPinPairing Pointer to a valid BDA Pin Pairing structure
  182. **
  183. ** NULL If no valid pin pairing exists with the
  184. ** given input and output pins.
  185. **
  186. ** Side Effects: none
  187. */
  188. PBDA_PIN_PAIRING
  189. BdaFindPinPair(
  190. PBDA_FILTER_TEMPLATE pFilterTemplate,
  191. ULONG InputPinId,
  192. ULONG OutputPinId
  193. );
  194. /*
  195. ** BdaGetPinFactoryContext()
  196. **
  197. ** Finds a BDA PinFactory Context that corresponds
  198. ** to the given KS Pin Instance.
  199. **
  200. ** Arguments:
  201. **
  202. **
  203. ** Returns:
  204. **
  205. **
  206. **
  207. ** Side Effects: none
  208. */
  209. STDMETHODIMP_(NTSTATUS)
  210. BdaGetPinFactoryContext(
  211. PKSPIN pKSPin,
  212. PBDA_PIN_FACTORY_CONTEXT pPinFactoryCtx
  213. );
  214. /*
  215. ** BdaInitFilterFactoryContext()
  216. **
  217. ** Initializes a BDA Filter Factory Context based on the filter's
  218. ** template descriptor.
  219. **
  220. **
  221. ** Arguments:
  222. **
  223. **
  224. ** pFilterFactoryCtx
  225. **
  226. ** Returns:
  227. **
  228. ** NULL If no valid pin pairing exists with the
  229. ** given input and output pins.
  230. **
  231. ** Side Effects: none
  232. */
  233. STDMETHODIMP_(NTSTATUS)
  234. BdaInitFilterFactoryContext(
  235. PBDA_FILTER_FACTORY_CONTEXT pFilterFactoryCtx
  236. );
  237. /*
  238. ** BdaAddNodeAutomationToPin()
  239. **
  240. ** Merges the automation tables for each node type that is controlled
  241. ** by the pin type being created into the automation table for the
  242. ** the pin factory. This is how the automation tables for BDA
  243. ** control nodes get linked to the controlling pin. Otherwise the
  244. ** nodes would not be accesable.
  245. **
  246. **
  247. ** Arguments:
  248. **
  249. **
  250. ** pFilterCtx The BDA filter context to which the pin factory
  251. ** belongs. Must have this to get at the template
  252. ** topology.
  253. **
  254. ** ulPinType BDA Pin Type of the pin being created. Need this
  255. ** to figure out which nodes are controlled by the
  256. ** pin.
  257. **
  258. ** Returns:
  259. **
  260. **
  261. ** Side Effects: none
  262. */
  263. STDMETHODIMP_(NTSTATUS)
  264. BdaAddNodeAutomationToPin(
  265. PBDA_FILTER_CONTEXT pFilterCtx,
  266. ULONG ulControllingPinType,
  267. KSOBJECT_BAG ObjectBag,
  268. const KSAUTOMATION_TABLE * pOriginalAutomationTable,
  269. PKSAUTOMATION_TABLE * ppNewAutomationTable
  270. );
  271. /*
  272. ** BdaCreateTemplatePaths()
  273. **
  274. ** Creates a list of all possible paths through the template filter.
  275. ** Determines the controlling pin type for each node type in the
  276. ** template filter.
  277. **
  278. **
  279. ** Arguments:
  280. **
  281. **
  282. ** pFilterFactoryCtx
  283. **
  284. ** Returns:
  285. **
  286. ** NULL If no valid pin pairing exists with the
  287. ** given input and output pins.
  288. **
  289. ** Side Effects: none
  290. */
  291. STDMETHODIMP_(NTSTATUS)
  292. BdaCreateTemplatePaths(
  293. const BDA_FILTER_TEMPLATE * pBdaFilterTemplate,
  294. PULONG pulcPathInfo,
  295. PBDA_PATH_INFO ** pargpPathInfo
  296. );
  297. ULONG __inline
  298. OutputBufferLenFromIrp(
  299. PIRP pIrp
  300. )
  301. {
  302. PIO_STACK_LOCATION pIrpStack;
  303. ASSERT( pIrp);
  304. if (!pIrp)
  305. {
  306. return 0;
  307. }
  308. pIrpStack = IoGetCurrentIrpStackLocation( pIrp);
  309. ASSERT( pIrpStack);
  310. if (pIrpStack)
  311. {
  312. return pIrpStack->Parameters.DeviceIoControl.OutputBufferLength;
  313. }
  314. else
  315. {
  316. return 0;
  317. }
  318. }
  319. //---------------------------------------------------------------------------
  320. // BDA Topology Const Data
  321. //
  322. // Minidriver code should not use these fields directly
  323. //
  324. //---------------------------------------------------------------------------
  325. extern const KSAUTOMATION_TABLE BdaDefaultPinAutomation;
  326. extern const KSAUTOMATION_TABLE BdaDefaultFilterAutomation;
  327. #if defined(__cplusplus)
  328. }
  329. #endif // defined(__cplusplus)