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.

376 lines
16 KiB

  1. #pragma once
  2. #include "utils.h"
  3. #include "hash.h"
  4. #include "state.h"
  5. #include "wzccrypt.h"
  6. // internal control flags - they mix with INTFCTL_* public flags, so
  7. // the values need to be in the highest 2 bytes of the dword
  8. //
  9. // the public mask can contain as many as 16 bits (0xffff). Currently it masks
  10. // - whether the service is enabled or not (INTFCTL_ENABLED)
  11. // - what is the configuration mode (INTFCTL_CM_MASK): adhoc/infra/auto
  12. // - whether should fallback to visible non preferred configs or not (INTFCTL_FALLBACK)
  13. // the default value for the public mask is for now just the bits we care about
  14. #define INTFCTL_PUBLIC_MASK 0x0000ffff
  15. #define INTFCTL_INTERNAL_MASK 0xffff0000
  16. #define INTFCTL_INTERNAL_TM_ON 0x00010000 // some timer is active for this context
  17. #define INTFCTL_INTERNAL_FAKE_WKEY 0x00020000 // a fake wep key has been set for this context
  18. #define INTFCTL_INTERNAL_FORCE_CFGREM 0x00040000 // force the removal of the selected config (bypass media state check)
  19. #define INTFCTL_INTERNAL_NO_DELAY 0x00080000 // a delayed execution of {SSr} is forbidden
  20. #define INTFCTL_INTERNAL_SIGNAL 0x00100000 // signal (UI) next time when entering the {SF} state
  21. #define INTFCTL_INTERNAL_BLK_MEDIACONN 0x00200000 // Block passing through for Media connects
  22. #define INTFCTL_INTERNAL_ONE_TIME 0x00400000 // the current config is a "one time configuration"
  23. #define INTFCTL_INTERNAL_INITFAILNOTIF 0x00800000 // the initial failure stack notification has been sent down already!
  24. // the public mask for a WZC configuration can contain as many as 16 bits (0xffff). Currently it masks
  25. // - whether a WEP key is provided (enabled) for this configuration WZCCTL_WEPK_PRESENT
  26. // - the format in which the key has been entered WZCCTL_WEPK_XFORMAT
  27. #define WZCCTL_INTERNAL_MASK 0xffff0000
  28. #define WZCCTL_INTERNAL_DELETED 0x00010000 // this configuration has been tried and failed
  29. #define WZCCTL_INTERNAL_FORCE_CONNECT 0x00020000 // this is adhoc config and failed. Keep it for a second forced plumbing
  30. #define WZCCTL_INTERNAL_BLOCKED 0x00040000 // this configuration was failed by the upper layer. Block it for the future.
  31. #define WZCCTL_INTERNAL_SHADOW 0x00080000 // this is a user-configuration shadowing a policy (read-only) configuration.
  32. // Time To Live for a blocked configuration in the pwzcBList. This TTL gets decremented
  33. // each time a "scan" shows the configuration being not visible. Generally if three successive
  34. // scans (at 1min) do not show the blocked config, we can safely assume the network is not
  35. // available hence next time we'll get into its area we are going to retry it, hence there is
  36. // no need to block it anymore.
  37. #define WZC_INTERNAL_BLOCKED_TTL 3
  38. //-----------------------------------------------------------
  39. // Type definitions
  40. typedef enum
  41. {
  42. eVPI=0, // visible, preferred infrastructure index
  43. eVI, // visible, non-preferred infrastructure index
  44. ePI, // non-visible, preferred infrastructure index
  45. eVPA, // visible, preferred adhoc index
  46. eVA, // visible, non-preferred adhoc index
  47. ePA, // non-visible, preferred adhoc index
  48. eN // invalid index
  49. } ENUM_SELCATEG;
  50. typedef struct _INTF_CONTEXT
  51. {
  52. // link for the linear hash
  53. LIST_ENTRY Link;
  54. // used for synchronizing the access to this structure
  55. RCCS_SYNC rccs;
  56. // control flags for this interface (see INTFCTL* constants)
  57. DWORD dwCtlFlags;
  58. // state handler for this interface context current state
  59. PFN_STATE_HANDLER pfnStateHandler;
  60. // NETman CONnection Status
  61. NETCON_STATUS ncStatus;
  62. // timer handle
  63. HANDLE hTimer;
  64. // ndis index of the interface
  65. DWORD dwIndex;
  66. // ndis "{guid}"
  67. LPWSTR wszGuid;
  68. // ndis interface description
  69. LPWSTR wszDescr;
  70. // local MAC address
  71. NDIS_802_11_MAC_ADDRESS ndLocalMac;
  72. // ndis media state
  73. ULONG ulMediaState;
  74. // ndis media type
  75. ULONG ulMediaType;
  76. // ndis physical media type
  77. ULONG ulPhysicalMediaType;
  78. // ndis opened handle to the interface
  79. HANDLE hIntf;
  80. // Current OID settings on the interface
  81. WZC_WLAN_CONFIG wzcCurrent;
  82. // list of visible configurations
  83. PWZC_802_11_CONFIG_LIST pwzcVList;
  84. // list of preferred configurations
  85. PWZC_802_11_CONFIG_LIST pwzcPList;
  86. // list of selected configurations
  87. PWZC_802_11_CONFIG_LIST pwzcSList;
  88. // list of configurations blocked from the upper layers
  89. PWZC_802_11_CONFIG_LIST pwzcBList;
  90. // dynamic session keys to be used in pre-shared re-keying scenario
  91. PSEC_SESSION_KEYS pSecSessionKeys;
  92. // session handler to be passed up on notification and checked down when
  93. // processing commands. In order to accept a command, the session handler
  94. // passed down with the command should match the session handler from the
  95. // context to which the command is addressed.
  96. DWORD dwSessionHandle;
  97. } INTF_CONTEXT, *PINTF_CONTEXT;
  98. typedef struct _INTF_HASHES
  99. {
  100. BOOL bValid; // tells whether the object has been initialized or not
  101. CRITICAL_SECTION csMutex; // Critical section protecting all hashes together
  102. PHASH_NODE pHnGUID; // pointer to the root Hash node for Intf GUIDs
  103. LIST_ENTRY lstIntfs; // linear list of all interfaces
  104. UINT nNumIntfs; // number of interfaces accross all hashes
  105. } INTF_HASHES, *PINTF_HASHES;
  106. extern HASH g_hshHandles; // HASH handing GUID<->Handle mapping
  107. extern INTF_HASHES g_lstIntfHashes; // set of hashes for all INTF_CONTEXTs
  108. extern HANDLE g_htmQueue; // global timer queue
  109. //-----------------------------------------------------------
  110. // Synchronization routines
  111. DWORD
  112. LstRccsReference(PINTF_CONTEXT pIntf);
  113. DWORD
  114. LstRccsLock(PINTF_CONTEXT pIntf);
  115. DWORD
  116. LstRccsUnlockUnref(PINTF_CONTEXT);
  117. //-----------------------------------------------------------
  118. // Intilializes all the internal interfaces hashes
  119. DWORD
  120. LstInitIntfHashes();
  121. //-----------------------------------------------------------
  122. // Destructs all the internal data structures - hash & lists
  123. DWORD
  124. LstDestroyIntfHashes();
  125. //-----------------------------------------------------------
  126. // Intializes the global timer queue
  127. DWORD
  128. LstInitTimerQueue();
  129. //-----------------------------------------------------------
  130. // Destructs the global timer queue
  131. DWORD
  132. LstDestroyTimerQueue();
  133. //-----------------------------------------------------------
  134. // Intilializes all the internal data structures. Reads the list of interfaces from
  135. // Ndisuio and gets all the parameters & OIDS.
  136. DWORD
  137. LstLoadInterfaces();
  138. //-----------------------------------------------------------
  139. // Constructor for the INTF_CONTEXT. Takes as parameter the binding information.
  140. // Interface's GUID constitutes the context's key info.
  141. // This call doesn't insert the new context in any hash or list
  142. DWORD
  143. LstConstructIntfContext(
  144. PNDISUIO_QUERY_BINDING pBinding,
  145. PINTF_CONTEXT *ppIntfContext);
  146. //-----------------------------------------------------------
  147. // Prepares a context for the destruction:
  148. // - Deletes any attached timer, making sure no other timer routines will be fired.
  149. // - Removes the context from any hash, making sure no one else will find the context
  150. // - Decrements the reference counter such that the context will be destroyed when unrefed.
  151. DWORD
  152. LstRemoveIntfContext(
  153. PINTF_CONTEXT pIntfContext);
  154. //-----------------------------------------------------------
  155. // Finally destructs the INTF_CONTEXT clearing all the resources allocated for it
  156. // This call doesn't remove this context from any hash or list
  157. DWORD
  158. LstDestroyIntfContext(
  159. PINTF_CONTEXT pIntfContext);
  160. //-----------------------------------------------------------
  161. // Returns the number of contexts enlisted in the service
  162. DWORD
  163. LstNumInterfaces();
  164. //-----------------------------------------------------------
  165. // Inserts the given context in all the internal hashes
  166. DWORD
  167. LstAddIntfToHashes(PINTF_CONTEXT pIntf);
  168. //-----------------------------------------------------------
  169. // Removes the context referenced by GUID from all the internal hashes.
  170. // The GUID is expected to be in the format "{guid}"
  171. // Returns in ppIntfContext the object that was removed from all hashes.
  172. DWORD
  173. LstRemIntfFromHashes(LPWSTR wszGuid, PINTF_CONTEXT *ppIntfContext);
  174. //-----------------------------------------------------------
  175. // Returns an array of *pdwNumIntfs INTF_KEY_ENTRY elements.
  176. // The INTF_KEY_ENTRY contains whatever information identifies
  177. // uniquely an adapter. Currently it includes just the GUID in
  178. // the format "{guid}"
  179. DWORD
  180. LstGetIntfsKeyInfo(
  181. PINTF_KEY_ENTRY pIntfs,
  182. LPDWORD pdwNumIntfs);
  183. //-----------------------------------------------------------
  184. // Returns requested information on the specified adapter.
  185. // [in] dwInFlags specifies the information requested. (see
  186. // bitmasks INTF_*)
  187. // [in] pIntfEntry should contain the GUID of the adapter
  188. // [out] pIntfEntry contains all the requested information that
  189. // could be successfully retrieved.
  190. // [out] pdwOutFlags provides an indication on the info that
  191. // was successfully retrieved
  192. DWORD
  193. LstQueryInterface(
  194. DWORD dwInFlags,
  195. PINTF_ENTRY pIntfEntry,
  196. LPDWORD pdwOutFlags);
  197. //-----------------------------------------------------------
  198. // Sets the specified parameters on the specified adapter.
  199. // [in] dwInFlags specifies the parameters to be set. (see
  200. // bitmasks INTF_*)
  201. // [in] pIntfEntry should contain the GUID of the adapter and
  202. // all the additional parameters to be set as specified
  203. // in dwInFlags
  204. // [out] pdwOutFlags provides an indication on the params that
  205. // were successfully set to the adapter
  206. // Each parameter for which the driver says that was set successfully
  207. // is copied into the interface's context.
  208. DWORD
  209. LstSetInterface(
  210. DWORD dwInFlags,
  211. PINTF_ENTRY pIntfEntry,
  212. LPDWORD pdwOutFlags);
  213. //-----------------------------------------------------------
  214. // Checks whether interface changes should cause the interface to be
  215. // reinserted in the state machine and it does so if needed.
  216. // [in] dwChangedFlags indicates what the changes are. (see
  217. // bitmasks INTF_*)
  218. // [in] pIntfContext context of the interface being changed.
  219. DWORD
  220. LstActOnChanges(
  221. DWORD dwChangedFlags,
  222. PINTF_CONTEXT pIntfContext);
  223. //-----------------------------------------------------------
  224. // Applies settings from the template context to the given interface context
  225. // [in] pIntfTemplate: Interface template to pick settings from
  226. // [in] pIntfContext: Interface context to apply template to.
  227. // [out] pbAltered: Tells whether the local interface context has been altered by the template
  228. DWORD
  229. LstApplyTemplate(
  230. PINTF_CONTEXT pIntfTemplate,
  231. PINTF_CONTEXT pIntfContext,
  232. LPBOOL pbAltered);
  233. //-----------------------------------------------------------
  234. // Refreshes the specified parameters on the specified adapter.
  235. // [in] dwInFlags specifies the parameters to be set. (see
  236. // bitmasks INTF_* and INTF_RFSH_*)
  237. // [in] pIntfEntry should contain the GUID of the adapter
  238. // [out] pdwOutFlags provides an indication on the params that
  239. // were successfully refreshed to the adapter
  240. // Each parameter for which the driver says that was refreshed
  241. // successfully is copied into the interface's context.
  242. DWORD
  243. LstRefreshInterface(
  244. DWORD dwInFlags,
  245. PINTF_ENTRY pIntfEntry,
  246. LPDWORD pdwOutFlags);
  247. //-----------------------------------------------------------
  248. // Builds the list of configurations to be tried from the list of visible
  249. // configurations, the list of preferred configurations and based on the
  250. // interface's mode (Auto/Infra/Adhoc) and flags (is the service enabled?,
  251. // fallback to visible?).
  252. // [in] pIntfContext: Interface for which is done the selection
  253. // [out] ppwzcSList: pointer to the list of selected configurations
  254. DWORD
  255. LstBuildSelectList(
  256. PINTF_CONTEXT pIntfContext,
  257. PWZC_802_11_CONFIG_LIST *ppwzcSList);
  258. //-----------------------------------------------------------
  259. // Checks whether the list of selected configurations has changed such
  260. // that it is required to replumb the selection.
  261. // [in] pIntfContext: Interface for which is done the selection
  262. // [in] pwzcNSList: new selection list to check the configuration against
  263. // [out] pnSelIdx: if selection changed, provides the index where to start iterate from
  264. // Returns: TRUE if replumbing is required. In this case, pnSelIdx is
  265. // set to the configuration to start iterate from.
  266. BOOL
  267. LstChangedSelectList(
  268. PINTF_CONTEXT pIntfContext,
  269. PWZC_802_11_CONFIG_LIST pwzcNSList,
  270. LPUINT pnSelIdx);
  271. //-----------------------------------------------------------
  272. // Plumbs the interface with the selected configuration as it is pointed
  273. // out by pwzcSList fields in the pIntfContext. Optional,
  274. // it can return in ppSelSSID the configuration that was plumbed down
  275. // [in] pIntfContext: Interface context identifying ctl flags & the selected SSID
  276. // [out] ppndSelSSID: pointer to the SSID that is being plumbed down.
  277. DWORD
  278. LstSetSelectedConfig(
  279. PINTF_CONTEXT pIntfContext,
  280. PWZC_WLAN_CONFIG *ppndSelSSID);
  281. //-----------------------------------------------------------
  282. // PnP notification handler
  283. // [in/out] ppIntfContext: Pointer to the Interface context for which
  284. // the notification was received
  285. // [in] dwNotifCode: Notification code (WZCNOTIF_*)
  286. // [in] wszDeviceKey: Key info on the device for which the notification
  287. // was received
  288. DWORD
  289. LstNotificationHandler(
  290. PINTF_CONTEXT *ppIntfContext,
  291. DWORD dwNotifCode,
  292. LPWSTR wszDeviceKey);
  293. //-----------------------------------------------------------
  294. // Application Command call.
  295. // [in] dwHandle: key for identifying the context (state) to which this cmd is referring
  296. // [in] dwCmdCode: Command code (one of the WZCCMD_* contants)
  297. // [in] wszIntfGuid: the guid of the interface to which this cmd is addressed
  298. // [in] prdUserData: Application data associated to this command
  299. DWORD
  300. LstCmdInterface(
  301. DWORD dwHandle,
  302. DWORD dwCmdCode,
  303. LPWSTR wszIntfGuid,
  304. PRAW_DATA prdUserData);
  305. //-----------------------------------------------------------
  306. // Network Connection's status query
  307. // [in] wszIntfGuid: the guid of the interface to which this cmd is addressed
  308. // [out] pncs: network connection status, if controlled by WZC.
  309. HRESULT
  310. LstQueryGUIDNCStatus(
  311. LPWSTR wszIntfGuid,
  312. NETCON_STATUS *pncs);
  313. //-----------------------------------------------------------
  314. // Generate the initial dynamic session keys.
  315. // [in] pIntfContext: Interface context containing the material for initial key generation.
  316. DWORD
  317. LstGenInitialSessionKeys(
  318. PINTF_CONTEXT pIntfContext);
  319. //-----------------------------------------------------------
  320. // Updates the list of blocked configurations with the selected configurations
  321. // that were blocked at this round by the upper layer (marked with WZCCTL_INTERNAL_BLOCKED
  322. // in the list of selected configurations)
  323. // [in] pIntfContext: Interface context containing the configurations lists
  324. DWORD
  325. LstUpdateBlockedList(
  326. PINTF_CONTEXT pIntfContext);
  327. //-----------------------------------------------------------
  328. // Checks each of the entries in the locked list against the visible list. If the
  329. // entry is visible, its TTL is reset. If it is not, its TTL is decremented. If the
  330. // TTL becomes 0, the entry is taken out of the list.
  331. // [in] pIntfContext: Interface context containing the configurations lists
  332. DWORD
  333. LstDeprecateBlockedList(
  334. PINTF_CONTEXT pIntfContext);