OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/wifi/wifi_service.h" | 5 #include "components/wifi/wifi_service.h" |
6 | 6 |
7 #include <iphlpapi.h> | 7 #include <iphlpapi.h> |
8 #include <objbase.h> | 8 #include <objbase.h> |
9 #include <wlanapi.h> | 9 #include <wlanapi.h> |
10 | 10 |
11 #include <set> | 11 #include <set> |
12 | 12 |
13 #include "base/base_paths_win.h" | 13 #include "base/base_paths_win.h" |
14 #include "base/bind.h" | 14 #include "base/bind.h" |
15 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
16 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
17 #include "base/message_loop/message_loop.h" | 17 #include "base/message_loop/message_loop.h" |
18 #include "base/path_service.h" | 18 #include "base/path_service.h" |
19 #include "base/strings/string16.h" | 19 #include "base/strings/string16.h" |
20 #include "base/strings/string_util.h" | 20 #include "base/strings/string_util.h" |
21 #include "base/strings/utf_string_conversions.h" | 21 #include "base/strings/utf_string_conversions.h" |
22 #include "base/win/registry.h" | 22 #include "base/win/registry.h" |
23 #include "components/onc/onc_constants.h" | 23 #include "components/onc/onc_constants.h" |
| 24 #include "third_party/libxml/chromium/libxml_utils.h" |
24 | 25 |
25 namespace { | 26 namespace { |
26 const char kWiFiServiceError[] = "Error.WiFiService"; | 27 const char kWiFiServiceError[] = "Error.WiFiService"; |
27 const wchar_t kNwCategoryWizardRegKey[] = | 28 const wchar_t kNwCategoryWizardRegKey[] = |
28 L"Software\\Microsoft\\Windows NT\\CurrentVersion\\Network\\" | 29 L"Software\\Microsoft\\Windows NT\\CurrentVersion\\Network\\" |
29 L"NwCategoryWizard"; | 30 L"NwCategoryWizard"; |
30 const wchar_t kNwCategoryWizardRegValue[] = L"Show"; | 31 const wchar_t kNwCategoryWizardRegValue[] = L"Show"; |
31 const wchar_t kNwCategoryWizardSavedRegValue[] = L"ShowSaved"; | 32 const wchar_t kNwCategoryWizardSavedRegValue[] = L"ShowSaved"; |
32 const wchar_t kNwCategoryWizardDeleteRegValue[] = L"ShowDelete"; | 33 const wchar_t kNwCategoryWizardDeleteRegValue[] = L"ShowDelete"; |
33 const wchar_t kWlanApiDll[] = L"wlanapi.dll"; | 34 const wchar_t kWlanApiDll[] = L"wlanapi.dll"; |
34 | 35 |
35 // WlanApi function names | 36 // WlanApi function names |
36 const char kWlanConnect[] = "WlanConnect"; | 37 const char kWlanConnect[] = "WlanConnect"; |
37 const char kWlanCloseHandle[] = "WlanCloseHandle"; | 38 const char kWlanCloseHandle[] = "WlanCloseHandle"; |
38 const char kWlanDisconnect[] = "WlanDisconnect"; | 39 const char kWlanDisconnect[] = "WlanDisconnect"; |
39 const char kWlanEnumInterfaces[] = "WlanEnumInterfaces"; | 40 const char kWlanEnumInterfaces[] = "WlanEnumInterfaces"; |
40 const char kWlanFreeMemory[] = "WlanFreeMemory"; | 41 const char kWlanFreeMemory[] = "WlanFreeMemory"; |
41 const char kWlanGetAvailableNetworkList[] = "WlanGetAvailableNetworkList"; | 42 const char kWlanGetAvailableNetworkList[] = "WlanGetAvailableNetworkList"; |
42 const char kWlanGetNetworkBssList[] = "WlanGetNetworkBssList"; | 43 const char kWlanGetNetworkBssList[] = "WlanGetNetworkBssList"; |
43 const char kWlanGetProfile[] = "WlanGetProfile"; | 44 const char kWlanGetProfile[] = "WlanGetProfile"; |
44 const char kWlanOpenHandle[] = "WlanOpenHandle"; | 45 const char kWlanOpenHandle[] = "WlanOpenHandle"; |
45 const char kWlanQueryInterface[] = "WlanQueryInterface"; | 46 const char kWlanQueryInterface[] = "WlanQueryInterface"; |
46 const char kWlanRegisterNotification[] = "WlanRegisterNotification"; | 47 const char kWlanRegisterNotification[] = "WlanRegisterNotification"; |
47 const char kWlanSaveTemporaryProfile[] = "WlanSaveTemporaryProfile"; | 48 const char kWlanSaveTemporaryProfile[] = "WlanSaveTemporaryProfile"; |
48 const char kWlanScan[] = "WlanScan"; | 49 const char kWlanScan[] = "WlanScan"; |
| 50 const char kWlanSetProfile[] = "WlanSetProfile"; |
49 | 51 |
50 // WlanApi function definitions | 52 // WlanApi function definitions |
51 typedef DWORD (WINAPI* WlanConnectFunction)( | 53 typedef DWORD (WINAPI* WlanConnectFunction)( |
52 HANDLE hClientHandle, | 54 HANDLE hClientHandle, |
53 CONST GUID *pInterfaceGuid, | 55 CONST GUID *pInterfaceGuid, |
54 CONST PWLAN_CONNECTION_PARAMETERS pConnectionParameters, | 56 CONST PWLAN_CONNECTION_PARAMETERS pConnectionParameters, |
55 PVOID pReserved); | 57 PVOID pReserved); |
56 | 58 |
57 typedef DWORD (WINAPI* WlanCloseHandleFunction)( | 59 typedef DWORD (WINAPI* WlanCloseHandleFunction)( |
58 HANDLE hClientHandle, | 60 HANDLE hClientHandle, |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 BOOL bOverWrite, | 131 BOOL bOverWrite, |
130 PVOID pReserved); | 132 PVOID pReserved); |
131 | 133 |
132 typedef DWORD (WINAPI* WlanScanFunction)( | 134 typedef DWORD (WINAPI* WlanScanFunction)( |
133 HANDLE hClientHandle, | 135 HANDLE hClientHandle, |
134 CONST GUID *pInterfaceGuid, | 136 CONST GUID *pInterfaceGuid, |
135 CONST PDOT11_SSID pDot11Ssid, | 137 CONST PDOT11_SSID pDot11Ssid, |
136 CONST PWLAN_RAW_DATA pIeData, | 138 CONST PWLAN_RAW_DATA pIeData, |
137 PVOID pReserved); | 139 PVOID pReserved); |
138 | 140 |
| 141 typedef DWORD (WINAPI* WlanSetProfileFunction)( |
| 142 HANDLE hClientHandle, |
| 143 const GUID *pInterfaceGuid, |
| 144 DWORD dwFlags, |
| 145 LPCWSTR strProfileXml, |
| 146 LPCWSTR strAllUserProfileSecurity, |
| 147 BOOL bOverwrite, |
| 148 PVOID pReserved, |
| 149 DWORD* pdwReasonCode); |
| 150 |
| 151 // Values for WLANProfile XML. |
| 152 const char kAuthenticationOpen[] = "open"; |
| 153 const char kAuthenticationWepPsk[] = "WEP"; |
| 154 const char kAuthenticationWpaPsk[] = "WPAPSK"; |
| 155 const char kAuthenticationWpa2Psk[] = "WPA2PSK"; |
| 156 const char kEncryptionAES[] = "AES"; |
| 157 const char kEncryptionNone[] = "none"; |
| 158 const char kEncryptionTKIP[] = "TKIP"; |
| 159 const char kEncryptionWEP[] = "WEP"; |
| 160 const char kKeyTypeNetwork[] = "networkKey"; |
| 161 const char kKeyTypePassphrase[] = "passPhrase"; |
| 162 |
139 } // namespace | 163 } // namespace |
140 | 164 |
141 namespace wifi { | 165 namespace wifi { |
142 | 166 |
143 // Implementation of WiFiService for Windows. | 167 // Implementation of WiFiService for Windows. |
144 class WiFiServiceImpl : public WiFiService, base::NonThreadSafe { | 168 class WiFiServiceImpl : public WiFiService, base::NonThreadSafe { |
145 public: | 169 public: |
146 WiFiServiceImpl(); | 170 WiFiServiceImpl(); |
147 virtual ~WiFiServiceImpl(); | 171 virtual ~WiFiServiceImpl(); |
148 | 172 |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 } | 298 } |
275 | 299 |
276 // Get unique |network_guid| string based on |wlan|. | 300 // Get unique |network_guid| string based on |wlan|. |
277 std::string GUIDFromWLAN(const WLAN_AVAILABLE_NETWORK& wlan) const { | 301 std::string GUIDFromWLAN(const WLAN_AVAILABLE_NETWORK& wlan) const { |
278 return SSIDFromWLAN(wlan); | 302 return SSIDFromWLAN(wlan); |
279 } | 303 } |
280 | 304 |
281 // Deduce |onc::wifi| security from |alg|. | 305 // Deduce |onc::wifi| security from |alg|. |
282 std::string SecurityFromDot11AuthAlg(DOT11_AUTH_ALGORITHM alg) const; | 306 std::string SecurityFromDot11AuthAlg(DOT11_AUTH_ALGORITHM alg) const; |
283 | 307 |
| 308 // Deduce WLANProfile |authEncryption| values from |onc::wifi| security. |
| 309 bool AuthEncryptionFromSecurity(const std::string& security, |
| 310 std::string* authentication, |
| 311 std::string* encryption, |
| 312 std::string* key_type) const; |
| 313 |
284 // Populate |properties| based on |wlan| and its corresponding bss info from | 314 // Populate |properties| based on |wlan| and its corresponding bss info from |
285 // |wlan_bss_list|. | 315 // |wlan_bss_list|. |
286 void NetworkPropertiesFromAvailableNetwork(const WLAN_AVAILABLE_NETWORK& wlan, | 316 void NetworkPropertiesFromAvailableNetwork(const WLAN_AVAILABLE_NETWORK& wlan, |
287 const WLAN_BSS_LIST& wlan_bss_list, | 317 const WLAN_BSS_LIST& wlan_bss_list, |
288 NetworkProperties* properties); | 318 NetworkProperties* properties); |
289 | 319 |
290 // Get the list of visible wireless networks. | 320 // Get the list of visible wireless networks. |
291 DWORD GetVisibleNetworkList(NetworkList* network_list); | 321 DWORD GetVisibleNetworkList(NetworkList* network_list); |
292 | 322 |
293 // Find currently connected network if any. Populate |connected_network_guid| | 323 // Find currently connected network if any. Populate |connected_network_guid| |
(...skipping 20 matching lines...) Expand all Loading... |
314 | 344 |
315 // Get DOT11_BSSID_LIST of desired BSSIDs to connect to |ssid| network on | 345 // Get DOT11_BSSID_LIST of desired BSSIDs to connect to |ssid| network on |
316 // given |frequency|. | 346 // given |frequency|. |
317 DWORD GetDesiredBssList(DOT11_SSID& ssid, | 347 DWORD GetDesiredBssList(DOT11_SSID& ssid, |
318 Frequency frequency, | 348 Frequency frequency, |
319 scoped_ptr<DOT11_BSSID_LIST>* desired_list); | 349 scoped_ptr<DOT11_BSSID_LIST>* desired_list); |
320 | 350 |
321 // Normalizes |frequency_in_mhz| into one of |Frequency| values. | 351 // Normalizes |frequency_in_mhz| into one of |Frequency| values. |
322 Frequency GetNormalizedFrequency(int frequency_in_mhz) const; | 352 Frequency GetNormalizedFrequency(int frequency_in_mhz) const; |
323 | 353 |
| 354 // Create |profile_xml| based on |network_properties|. |
| 355 bool CreateProfile(const NetworkProperties& network_properties, |
| 356 std::string* profile_xml); |
| 357 |
324 // Save temporary wireless profile for |network_guid|. | 358 // Save temporary wireless profile for |network_guid|. |
325 DWORD SaveTempProfile(const std::string& network_guid); | 359 DWORD SaveTempProfile(const std::string& network_guid); |
326 | 360 |
327 // Get previously stored |profile_xml| for |network_guid|. | 361 // Get previously stored |profile_xml| for |network_guid|. |
328 DWORD GetProfile(const std::string& network_guid, std::string* profile_xml); | 362 DWORD GetProfile(const std::string& network_guid, std::string* profile_xml); |
329 | 363 |
330 // Return true if there is previously stored profile xml for |network_guid|. | 364 // Return true if there is previously stored profile xml for |network_guid|. |
331 bool HaveProfile(const std::string& network_guid); | 365 bool HaveProfile(const std::string& network_guid); |
332 | 366 |
333 // Notify |network_list_changed_observer_| that list of visible networks has | 367 // Notify |network_list_changed_observer_| that list of visible networks has |
(...skipping 15 matching lines...) Expand all Loading... |
349 WlanEnumInterfacesFunction WlanEnumInterfaces_function_; | 383 WlanEnumInterfacesFunction WlanEnumInterfaces_function_; |
350 WlanFreeMemoryFunction WlanFreeMemory_function_; | 384 WlanFreeMemoryFunction WlanFreeMemory_function_; |
351 WlanGetAvailableNetworkListFunction WlanGetAvailableNetworkList_function_; | 385 WlanGetAvailableNetworkListFunction WlanGetAvailableNetworkList_function_; |
352 // WlanGetNetworkBssList function may not be avaiable on Windows XP. | 386 // WlanGetNetworkBssList function may not be avaiable on Windows XP. |
353 WlanGetNetworkBssListFunction WlanGetNetworkBssList_function_; | 387 WlanGetNetworkBssListFunction WlanGetNetworkBssList_function_; |
354 WlanGetProfileFunction WlanGetProfile_function_; | 388 WlanGetProfileFunction WlanGetProfile_function_; |
355 WlanOpenHandleFunction WlanOpenHandle_function_; | 389 WlanOpenHandleFunction WlanOpenHandle_function_; |
356 WlanQueryInterfaceFunction WlanQueryInterface_function_; | 390 WlanQueryInterfaceFunction WlanQueryInterface_function_; |
357 WlanRegisterNotificationFunction WlanRegisterNotification_function_; | 391 WlanRegisterNotificationFunction WlanRegisterNotification_function_; |
358 WlanScanFunction WlanScan_function_; | 392 WlanScanFunction WlanScan_function_; |
| 393 WlanSetProfileFunction WlanSetProfile_function_; |
359 // WlanSaveTemporaryProfile function may not be avaiable on Windows XP. | 394 // WlanSaveTemporaryProfile function may not be avaiable on Windows XP. |
360 WlanSaveTemporaryProfileFunction WlanSaveTemporaryProfile_function_; | 395 WlanSaveTemporaryProfileFunction WlanSaveTemporaryProfile_function_; |
361 | 396 |
362 // WLAN service handle. | 397 // WLAN service handle. |
363 HANDLE client_; | 398 HANDLE client_; |
364 // GUID of the currently connected interface, if any, otherwise the GUID of | 399 // GUID of the currently connected interface, if any, otherwise the GUID of |
365 // one of the WLAN interfaces. | 400 // one of the WLAN interfaces. |
366 GUID interface_guid_; | 401 GUID interface_guid_; |
367 // Temporary storage of network properties indexed by |network_guid|. Persist | 402 // Temporary storage of network properties indexed by |network_guid|. Persist |
368 // only in memory. | 403 // only in memory. |
(...skipping 26 matching lines...) Expand all Loading... |
395 WlanDisconnect_function_(NULL), | 430 WlanDisconnect_function_(NULL), |
396 WlanEnumInterfaces_function_(NULL), | 431 WlanEnumInterfaces_function_(NULL), |
397 WlanFreeMemory_function_(NULL), | 432 WlanFreeMemory_function_(NULL), |
398 WlanGetAvailableNetworkList_function_(NULL), | 433 WlanGetAvailableNetworkList_function_(NULL), |
399 WlanGetNetworkBssList_function_(NULL), | 434 WlanGetNetworkBssList_function_(NULL), |
400 WlanGetProfile_function_(NULL), | 435 WlanGetProfile_function_(NULL), |
401 WlanOpenHandle_function_(NULL), | 436 WlanOpenHandle_function_(NULL), |
402 WlanRegisterNotification_function_(NULL), | 437 WlanRegisterNotification_function_(NULL), |
403 WlanSaveTemporaryProfile_function_(NULL), | 438 WlanSaveTemporaryProfile_function_(NULL), |
404 WlanScan_function_(NULL), | 439 WlanScan_function_(NULL), |
| 440 WlanSetProfile_function_(NULL), |
405 client_(NULL), | 441 client_(NULL), |
406 enable_notify_network_changed_(true) {} | 442 enable_notify_network_changed_(true) {} |
407 | 443 |
408 WiFiServiceImpl::~WiFiServiceImpl() { UnInitialize(); } | 444 WiFiServiceImpl::~WiFiServiceImpl() { UnInitialize(); } |
409 | 445 |
410 void WiFiServiceImpl::Initialize( | 446 void WiFiServiceImpl::Initialize( |
411 scoped_refptr<base::SequencedTaskRunner> task_runner) { | 447 scoped_refptr<base::SequencedTaskRunner> task_runner) { |
412 DCHECK(!client_); | 448 DCHECK(!client_); |
413 task_runner_.swap(task_runner); | 449 task_runner_.swap(task_runner); |
414 // Restore NwCategoryWizard in case if we crashed during connect. | 450 // Restore NwCategoryWizard in case if we crashed during connect. |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
469 } | 505 } |
470 connect_properties_.SetWithoutPathExpansion(network_guid, | 506 connect_properties_.SetWithoutPathExpansion(network_guid, |
471 properties.release()); | 507 properties.release()); |
472 } | 508 } |
473 | 509 |
474 void WiFiServiceImpl::CreateNetwork( | 510 void WiFiServiceImpl::CreateNetwork( |
475 bool shared, | 511 bool shared, |
476 scoped_ptr<base::DictionaryValue> properties, | 512 scoped_ptr<base::DictionaryValue> properties, |
477 std::string* network_guid, | 513 std::string* network_guid, |
478 std::string* error) { | 514 std::string* error) { |
479 CheckError(ERROR_CALL_NOT_IMPLEMENTED, kWiFiServiceError, error); | 515 DWORD error_code = EnsureInitialized(); |
| 516 if (CheckError(error_code, kWiFiServiceError, error)) |
| 517 return; |
| 518 |
| 519 WiFiService::NetworkProperties network_properties; |
| 520 if (!network_properties.UpdateFromValue(*properties)) { |
| 521 CheckError(ERROR_INVALID_DATA, kWiFiServiceError, error); |
| 522 return; |
| 523 } |
| 524 |
| 525 network_properties.guid = network_properties.ssid; |
| 526 std::string profile_xml; |
| 527 if (!CreateProfile(network_properties, &profile_xml)) { |
| 528 CheckError(ERROR_INVALID_DATA, kWiFiServiceError, error); |
| 529 return; |
| 530 } |
| 531 |
| 532 string16 profile_xml16(UTF8ToUTF16(profile_xml)); |
| 533 DWORD reason_code = 0u; |
| 534 |
| 535 error_code = WlanSetProfile_function_(client_, |
| 536 &interface_guid_, |
| 537 shared ? 0 : WLAN_PROFILE_USER, |
| 538 profile_xml16.c_str(), |
| 539 NULL, |
| 540 FALSE, |
| 541 NULL, |
| 542 &reason_code); |
| 543 if (CheckError(error_code, kWiFiServiceError, error)) { |
| 544 DVLOG(0) << profile_xml; |
| 545 DVLOG(0) << "SetProfile Reason Code:" << reason_code; |
| 546 return; |
| 547 } |
| 548 |
| 549 *network_guid = network_properties.guid; |
480 } | 550 } |
481 | 551 |
482 void WiFiServiceImpl::GetVisibleNetworks(const std::string& network_type, | 552 void WiFiServiceImpl::GetVisibleNetworks(const std::string& network_type, |
483 ListValue* network_list) { | 553 ListValue* network_list) { |
484 if (!network_type.empty() && | 554 if (!network_type.empty() && |
485 network_type != onc::network_type::kAllTypes && | 555 network_type != onc::network_type::kAllTypes && |
486 network_type != onc::network_type::kWiFi) { | 556 network_type != onc::network_type::kWiFi) { |
487 return; | 557 return; |
488 } | 558 } |
489 | 559 |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
744 ::GetProcAddress(wlan_api_library_, kWlanQueryInterface)); | 814 ::GetProcAddress(wlan_api_library_, kWlanQueryInterface)); |
745 WlanRegisterNotification_function_ = | 815 WlanRegisterNotification_function_ = |
746 reinterpret_cast<WlanRegisterNotificationFunction>( | 816 reinterpret_cast<WlanRegisterNotificationFunction>( |
747 ::GetProcAddress(wlan_api_library_, kWlanRegisterNotification)); | 817 ::GetProcAddress(wlan_api_library_, kWlanRegisterNotification)); |
748 WlanSaveTemporaryProfile_function_ = | 818 WlanSaveTemporaryProfile_function_ = |
749 reinterpret_cast<WlanSaveTemporaryProfileFunction>( | 819 reinterpret_cast<WlanSaveTemporaryProfileFunction>( |
750 ::GetProcAddress(wlan_api_library_, kWlanSaveTemporaryProfile)); | 820 ::GetProcAddress(wlan_api_library_, kWlanSaveTemporaryProfile)); |
751 WlanScan_function_ = | 821 WlanScan_function_ = |
752 reinterpret_cast<WlanScanFunction>( | 822 reinterpret_cast<WlanScanFunction>( |
753 ::GetProcAddress(wlan_api_library_, kWlanScan)); | 823 ::GetProcAddress(wlan_api_library_, kWlanScan)); |
| 824 WlanSetProfile_function_ = |
| 825 reinterpret_cast<WlanSetProfileFunction>( |
| 826 ::GetProcAddress(wlan_api_library_, kWlanSetProfile)); |
754 | 827 |
755 if (!WlanConnect_function_ || | 828 if (!WlanConnect_function_ || |
756 !WlanCloseHandle_function_ || | 829 !WlanCloseHandle_function_ || |
757 !WlanDisconnect_function_ || | 830 !WlanDisconnect_function_ || |
758 !WlanEnumInterfaces_function_ || | 831 !WlanEnumInterfaces_function_ || |
759 !WlanFreeMemory_function_ || | 832 !WlanFreeMemory_function_ || |
760 !WlanGetAvailableNetworkList_function_ || | 833 !WlanGetAvailableNetworkList_function_ || |
761 !WlanGetProfile_function_ || | 834 !WlanGetProfile_function_ || |
762 !WlanOpenHandle_function_ || | 835 !WlanOpenHandle_function_ || |
763 !WlanQueryInterface_function_ || | 836 !WlanQueryInterface_function_ || |
764 !WlanRegisterNotification_function_ || | 837 !WlanRegisterNotification_function_ || |
765 !WlanScan_function_) { | 838 !WlanScan_function_ || |
| 839 !WlanSetProfile_function_) { |
766 DLOG(ERROR) << "Unable to find required WlanApi function."; | 840 DLOG(ERROR) << "Unable to find required WlanApi function."; |
767 FreeLibrary(wlan_api_library_); | 841 FreeLibrary(wlan_api_library_); |
768 wlan_api_library_ = NULL; | 842 wlan_api_library_ = NULL; |
769 return ERROR_NOT_FOUND; | 843 return ERROR_NOT_FOUND; |
770 } | 844 } |
771 | 845 |
772 // Some WlanApi functions may not be available on XP. | 846 // Some WlanApi functions may not be available on XP. |
773 if (!WlanGetNetworkBssList_function_ || | 847 if (!WlanGetNetworkBssList_function_ || |
774 !WlanSaveTemporaryProfile_function_) { | 848 !WlanSaveTemporaryProfile_function_) { |
775 DVLOG(1) << "WlanApi function is not be available on XP."; | 849 DVLOG(1) << "WlanApi function is not be available on XP."; |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
935 WlanDisconnect_function_ = NULL; | 1009 WlanDisconnect_function_ = NULL; |
936 WlanEnumInterfaces_function_ = NULL; | 1010 WlanEnumInterfaces_function_ = NULL; |
937 WlanFreeMemory_function_ = NULL; | 1011 WlanFreeMemory_function_ = NULL; |
938 WlanGetAvailableNetworkList_function_ = NULL; | 1012 WlanGetAvailableNetworkList_function_ = NULL; |
939 WlanGetNetworkBssList_function_ = NULL; | 1013 WlanGetNetworkBssList_function_ = NULL; |
940 WlanGetProfile_function_ = NULL; | 1014 WlanGetProfile_function_ = NULL; |
941 WlanOpenHandle_function_ = NULL; | 1015 WlanOpenHandle_function_ = NULL; |
942 WlanRegisterNotification_function_ = NULL; | 1016 WlanRegisterNotification_function_ = NULL; |
943 WlanSaveTemporaryProfile_function_ = NULL; | 1017 WlanSaveTemporaryProfile_function_ = NULL; |
944 WlanScan_function_ = NULL; | 1018 WlanScan_function_ = NULL; |
| 1019 WlanSetProfile_function_ = NULL; |
945 ::FreeLibrary(wlan_api_library_); | 1020 ::FreeLibrary(wlan_api_library_); |
946 wlan_api_library_ = NULL; | 1021 wlan_api_library_ = NULL; |
947 } | 1022 } |
948 return error; | 1023 return error; |
949 } | 1024 } |
950 | 1025 |
951 DOT11_SSID WiFiServiceImpl::SSIDFromGUID( | 1026 DOT11_SSID WiFiServiceImpl::SSIDFromGUID( |
952 const std::string& network_guid) const { | 1027 const std::string& network_guid) const { |
953 DOT11_SSID ssid = {0}; | 1028 DOT11_SSID ssid = {0}; |
954 if (network_guid.length() <= DOT11_SSID_MAX_LENGTH) { | 1029 if (network_guid.length() <= DOT11_SSID_MAX_LENGTH) { |
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1394 | 1469 |
1395 return error; | 1470 return error; |
1396 } | 1471 } |
1397 | 1472 |
1398 bool WiFiServiceImpl::HaveProfile(const std::string& network_guid) { | 1473 bool WiFiServiceImpl::HaveProfile(const std::string& network_guid) { |
1399 DWORD error = ERROR_SUCCESS; | 1474 DWORD error = ERROR_SUCCESS; |
1400 std::string profile_xml; | 1475 std::string profile_xml; |
1401 return GetProfile(network_guid, &profile_xml) == ERROR_SUCCESS; | 1476 return GetProfile(network_guid, &profile_xml) == ERROR_SUCCESS; |
1402 } | 1477 } |
1403 | 1478 |
| 1479 bool WiFiServiceImpl::AuthEncryptionFromSecurity( |
| 1480 const std::string& security, |
| 1481 std::string* authentication, |
| 1482 std::string* encryption, |
| 1483 std::string* key_type) const { |
| 1484 if (security == onc::wifi::kNone) { |
| 1485 *authentication = kAuthenticationOpen; |
| 1486 *encryption = kEncryptionNone; |
| 1487 } else if (security == onc::wifi::kWEP_PSK) { |
| 1488 *authentication = kAuthenticationOpen; |
| 1489 *encryption = kEncryptionWEP; |
| 1490 *key_type = kKeyTypeNetwork; |
| 1491 } else if (security == onc::wifi::kWPA_PSK) { |
| 1492 *authentication = kAuthenticationWpaPsk; |
| 1493 // TODO(mef): WAP |encryption| could be either |AES| or |TKIP|. It has to be |
| 1494 // determined and adjusted properly during |Connect|. |
| 1495 *encryption = kEncryptionAES; |
| 1496 *key_type = kKeyTypePassphrase; |
| 1497 } else if (security == onc::wifi::kWPA2_PSK) { |
| 1498 *authentication = kAuthenticationWpa2Psk; |
| 1499 // TODO(mef): WAP |encryption| could be either |AES| or |TKIP|. It has to be |
| 1500 // determined and adjusted properly during |Connect|. |
| 1501 *encryption = kEncryptionAES; |
| 1502 *key_type = kKeyTypePassphrase; |
| 1503 } else { |
| 1504 return false; |
| 1505 } |
| 1506 return true; |
| 1507 } |
| 1508 |
| 1509 bool WiFiServiceImpl::CreateProfile( |
| 1510 const NetworkProperties& network_properties, |
| 1511 std::string* profile_xml) { |
| 1512 // Get authentication and encryption values from security. |
| 1513 std::string authentication; |
| 1514 std::string encryption; |
| 1515 std::string key_type; |
| 1516 bool valid = AuthEncryptionFromSecurity(network_properties.security, |
| 1517 &authentication, |
| 1518 &encryption, |
| 1519 &key_type); |
| 1520 if (!valid) |
| 1521 return valid; |
| 1522 |
| 1523 // Generate profile XML. |
| 1524 XmlWriter xml_writer; |
| 1525 xml_writer.StartWriting(); |
| 1526 xml_writer.StartElement("WLANProfile"); |
| 1527 xml_writer.AddAttribute( |
| 1528 "xmlns", |
| 1529 "http://www.microsoft.com/networking/WLAN/profile/v1"); |
| 1530 xml_writer.WriteElement("name", network_properties.guid); |
| 1531 xml_writer.StartElement("SSIDConfig"); |
| 1532 xml_writer.StartElement("SSID"); |
| 1533 xml_writer.WriteElement("name", network_properties.ssid); |
| 1534 xml_writer.EndElement(); // Ends "SSID" element. |
| 1535 xml_writer.EndElement(); // Ends "SSIDConfig" element. |
| 1536 xml_writer.WriteElement("connectionType", "ESS"); |
| 1537 xml_writer.WriteElement("connectionMode", "manual"); |
| 1538 xml_writer.StartElement("MSM"); |
| 1539 xml_writer.StartElement("security"); |
| 1540 xml_writer.StartElement("authEncryption"); |
| 1541 xml_writer.WriteElement("authentication", authentication); |
| 1542 xml_writer.WriteElement("encryption", encryption); |
| 1543 xml_writer.WriteElement("useOneX", "false"); |
| 1544 xml_writer.EndElement(); // Ends "authEncryption" element. |
| 1545 if (!key_type.empty()) { |
| 1546 xml_writer.StartElement("sharedKey"); |
| 1547 xml_writer.WriteElement("keyType", key_type); |
| 1548 xml_writer.WriteElement("protected", "false"); |
| 1549 xml_writer.WriteElement("keyMaterial", network_properties.password); |
| 1550 xml_writer.EndElement(); // Ends "sharedKey" element. |
| 1551 } |
| 1552 xml_writer.EndElement(); // Ends "security" element. |
| 1553 xml_writer.EndElement(); // Ends "MSM" element. |
| 1554 xml_writer.EndElement(); // Ends "WLANProfile" element. |
| 1555 xml_writer.StopWriting(); |
| 1556 *profile_xml = xml_writer.GetWrittenString(); |
| 1557 |
| 1558 return true; |
| 1559 } |
| 1560 |
1404 void WiFiServiceImpl::NotifyNetworkListChanged(const NetworkList& networks) { | 1561 void WiFiServiceImpl::NotifyNetworkListChanged(const NetworkList& networks) { |
1405 if (network_list_changed_observer_.is_null()) | 1562 if (network_list_changed_observer_.is_null()) |
1406 return; | 1563 return; |
1407 | 1564 |
1408 NetworkGuidList current_networks; | 1565 NetworkGuidList current_networks; |
1409 for (NetworkList::const_iterator it = networks.begin(); | 1566 for (NetworkList::const_iterator it = networks.begin(); |
1410 it != networks.end(); | 1567 it != networks.end(); |
1411 ++it) { | 1568 ++it) { |
1412 current_networks.push_back(it->guid); | 1569 current_networks.push_back(it->guid); |
1413 } | 1570 } |
1414 | 1571 |
1415 message_loop_proxy_->PostTask( | 1572 message_loop_proxy_->PostTask( |
1416 FROM_HERE, | 1573 FROM_HERE, |
1417 base::Bind(network_list_changed_observer_, current_networks)); | 1574 base::Bind(network_list_changed_observer_, current_networks)); |
1418 } | 1575 } |
1419 | 1576 |
1420 void WiFiServiceImpl::NotifyNetworkChanged(const std::string& network_guid) { | 1577 void WiFiServiceImpl::NotifyNetworkChanged(const std::string& network_guid) { |
1421 if (enable_notify_network_changed_ && !networks_changed_observer_.is_null()) { | 1578 if (enable_notify_network_changed_ && !networks_changed_observer_.is_null()) { |
1422 DVLOG(1) << "NotifyNetworkChanged: " << network_guid; | 1579 DVLOG(1) << "NotifyNetworkChanged: " << network_guid; |
1423 NetworkGuidList changed_networks(1, network_guid); | 1580 NetworkGuidList changed_networks(1, network_guid); |
1424 message_loop_proxy_->PostTask( | 1581 message_loop_proxy_->PostTask( |
1425 FROM_HERE, | 1582 FROM_HERE, |
1426 base::Bind(networks_changed_observer_, changed_networks)); | 1583 base::Bind(networks_changed_observer_, changed_networks)); |
1427 } | 1584 } |
1428 } | 1585 } |
1429 | 1586 |
1430 WiFiService* WiFiService::Create() { return new WiFiServiceImpl(); } | 1587 WiFiService* WiFiService::Create() { return new WiFiServiceImpl(); } |
1431 | 1588 |
1432 } // namespace wifi | 1589 } // namespace wifi |
OLD | NEW |