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.

301 lines
8.9 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. tcwmi.c
  5. Abstract:
  6. This module contains WMI support for traffic control
  7. Author:
  8. Ofer Bar (oferbar) Oct 1, 1997
  9. Revision History:
  10. --*/
  11. #include "precomp.h"
  12. static BOOLEAN _init = FALSE;
  13. DWORD
  14. InitializeWmi(VOID)
  15. {
  16. DWORD Status = NO_ERROR;
  17. if (!_init) {
  18. __try {
  19. Status = WmiNotificationRegistration( (LPGUID)&GUID_QOS_TC_INTERFACE_UP_INDICATION,
  20. TRUE,
  21. CbWmiInterfaceNotification,
  22. 0,
  23. NOTIFICATION_CALLBACK_DIRECT
  24. );
  25. Status = WmiNotificationRegistration( (LPGUID)&GUID_QOS_TC_INTERFACE_DOWN_INDICATION,
  26. TRUE,
  27. CbWmiInterfaceNotification,
  28. 0,
  29. NOTIFICATION_CALLBACK_DIRECT
  30. );
  31. Status = WmiNotificationRegistration( (LPGUID)&GUID_QOS_TC_INTERFACE_CHANGE_INDICATION,
  32. TRUE,
  33. CbWmiInterfaceNotification,
  34. 0,
  35. NOTIFICATION_CALLBACK_DIRECT
  36. );
  37. } __except (EXCEPTION_EXECUTE_HANDLER) {
  38. Status = GetExceptionCode();
  39. IF_DEBUG(ERRORS) {
  40. WSPRINT(("InitializeWmi: Exception Error: = %X\n", Status ));
  41. }
  42. }
  43. if (Status == NO_ERROR)
  44. _init = TRUE;
  45. }
  46. return Status;
  47. }
  48. DWORD
  49. DeInitializeWmi(VOID)
  50. {
  51. DWORD Status = NO_ERROR;
  52. if (_init) {
  53. __try {
  54. Status = WmiNotificationRegistration( (LPGUID)&GUID_QOS_TC_INTERFACE_UP_INDICATION,
  55. FALSE,
  56. CbWmiInterfaceNotification,
  57. 0,
  58. NOTIFICATION_CALLBACK_DIRECT
  59. );
  60. Status = WmiNotificationRegistration( (LPGUID)&GUID_QOS_TC_INTERFACE_DOWN_INDICATION,
  61. FALSE,
  62. CbWmiInterfaceNotification,
  63. 0,
  64. NOTIFICATION_CALLBACK_DIRECT
  65. );
  66. Status = WmiNotificationRegistration( (LPGUID)&GUID_QOS_TC_INTERFACE_CHANGE_INDICATION,
  67. FALSE,
  68. CbWmiInterfaceNotification,
  69. 0,
  70. NOTIFICATION_CALLBACK_DIRECT
  71. );
  72. } __except (EXCEPTION_EXECUTE_HANDLER) {
  73. Status = GetExceptionCode();
  74. IF_DEBUG(ERRORS) {
  75. WSPRINT(("DeInitializeWmi: Exception Error: = %X\n", Status ));
  76. }
  77. }
  78. if (Status == NO_ERROR)
  79. _init = FALSE;
  80. }
  81. return Status;
  82. }
  83. DWORD
  84. WalkWnode(
  85. IN PWNODE_HEADER pWnodeHdr,
  86. IN ULONG Context,
  87. IN CB_PER_INSTANCE_ROUTINE CbPerInstance
  88. )
  89. {
  90. DWORD Status;
  91. ULONG Flags;
  92. PWCHAR NamePtr;
  93. USHORT NameSize;
  94. PBYTE DataBuffer;
  95. ULONG DataSize;
  96. PULONG NameOffset;
  97. WCHAR TmpName[512];
  98. Flags = pWnodeHdr->Flags;
  99. if (Flags & WNODE_FLAG_ALL_DATA) {
  100. //
  101. // WNODE_ALL_DATA structure has multiple interfaces
  102. //
  103. PWNODE_ALL_DATA pWnode = (PWNODE_ALL_DATA)pWnodeHdr;
  104. UINT Instance;
  105. //PULONG NameOffsets;
  106. NameOffset = (PULONG) OffsetToPtr(pWnode,
  107. pWnode->OffsetInstanceNameOffsets );
  108. DataBuffer = (PBYTE) OffsetToPtr (pWnode,
  109. pWnode->DataBlockOffset);
  110. for ( Instance = 0;
  111. Instance < pWnode->InstanceCount;
  112. Instance++) {
  113. //
  114. // Instance Name
  115. //
  116. NamePtr = (PWCHAR) OffsetToPtr(pWnode,
  117. NameOffset[Instance]
  118. + sizeof(USHORT));
  119. NameSize = * (USHORT *) OffsetToPtr(pWnode,
  120. NameOffset[Instance]);
  121. //
  122. // Instance Data
  123. //
  124. // Get size and pointer to the buffer
  125. //
  126. if ( Flags & WNODE_FLAG_FIXED_INSTANCE_SIZE ) {
  127. DataSize = pWnode->FixedInstanceSize;
  128. } else {
  129. DataSize =
  130. pWnode->OffsetInstanceDataAndLength[Instance].LengthInstanceData;
  131. DataBuffer =
  132. (PBYTE)OffsetToPtr(pWnode,
  133. pWnode->OffsetInstanceDataAndLength[Instance].OffsetInstanceData);
  134. }
  135. //
  136. // a call back to a notification handler that calls the client
  137. //
  138. CbPerInstance(Context,
  139. (LPGUID)&pWnode->WnodeHeader.Guid,
  140. (LPWSTR)NamePtr,
  141. DataSize,
  142. DataBuffer
  143. );
  144. }
  145. } else if (Flags & WNODE_FLAG_SINGLE_INSTANCE) {
  146. //
  147. // WNODE_SINGLE_INSTANCE structure has only one instance
  148. //
  149. PWNODE_SINGLE_INSTANCE pWnode = (PWNODE_SINGLE_INSTANCE)pWnodeHdr;
  150. if (Flags & WNODE_FLAG_STATIC_INSTANCE_NAMES) {
  151. //
  152. // What am I supposed to do with THAT ?!?
  153. // NOTHING! (55686)
  154. //
  155. return (-1);
  156. }
  157. NamePtr = (PWCHAR)OffsetToPtr(pWnode,
  158. pWnode->OffsetInstanceName
  159. + sizeof(USHORT) );
  160. NameSize = * (USHORT *) OffsetToPtr(pWnode,
  161. pWnode->OffsetInstanceName);
  162. memcpy(TmpName, NamePtr, NameSize);
  163. TmpName[NameSize/sizeof(WCHAR)] = L'\0';
  164. //
  165. // Data Size
  166. //
  167. DataSize = pWnode->SizeDataBlock;
  168. //
  169. // Instance Data
  170. //
  171. DataBuffer = (PBYTE)OffsetToPtr (pWnode, pWnode->DataBlockOffset);
  172. //
  173. // a call back to a notification handler that calls the client
  174. //
  175. CbPerInstance(Context,
  176. (LPGUID)&pWnode->WnodeHeader.Guid,
  177. (LPWSTR)TmpName,
  178. DataSize,
  179. DataBuffer
  180. );
  181. } else if (Flags & WNODE_FLAG_SINGLE_ITEM) {
  182. //
  183. // WNODE_SINGLE_INSTANCE structure has only one instance
  184. //
  185. PWNODE_SINGLE_ITEM pWnode = (PWNODE_SINGLE_ITEM)pWnodeHdr;
  186. if (Flags & WNODE_FLAG_STATIC_INSTANCE_NAMES) {
  187. //
  188. // What am I supposed to do with THAT ?!?
  189. // NOTHING! (55686)
  190. //
  191. return (-1);
  192. }
  193. NamePtr = (PWCHAR)OffsetToPtr(pWnode,
  194. pWnode->OffsetInstanceName
  195. + sizeof(USHORT) );
  196. NameSize = * (USHORT *) OffsetToPtr(pWnode,
  197. pWnode->OffsetInstanceName);
  198. //
  199. // Data Size
  200. //
  201. DataSize = pWnode->SizeDataItem;
  202. //
  203. // Instance Data
  204. //
  205. DataBuffer = (PBYTE)OffsetToPtr (pWnode, pWnode->DataBlockOffset);
  206. //
  207. // a call back to a notification handler that calls the client
  208. //
  209. CbPerInstance(Context,
  210. (LPGUID)&pWnode->WnodeHeader.Guid,
  211. (LPWSTR)NamePtr,
  212. DataSize,
  213. DataBuffer
  214. );
  215. } else {
  216. ASSERT(0);
  217. }
  218. return NO_ERROR;
  219. }