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 |
(...skipping 24 matching lines...) Expand all Loading... |
35 // WlanApi function names | 35 // WlanApi function names |
36 const char kWlanConnect[] = "WlanConnect"; | 36 const char kWlanConnect[] = "WlanConnect"; |
37 const char kWlanCloseHandle[] = "WlanCloseHandle"; | 37 const char kWlanCloseHandle[] = "WlanCloseHandle"; |
38 const char kWlanDisconnect[] = "WlanDisconnect"; | 38 const char kWlanDisconnect[] = "WlanDisconnect"; |
39 const char kWlanEnumInterfaces[] = "WlanEnumInterfaces"; | 39 const char kWlanEnumInterfaces[] = "WlanEnumInterfaces"; |
40 const char kWlanFreeMemory[] = "WlanFreeMemory"; | 40 const char kWlanFreeMemory[] = "WlanFreeMemory"; |
41 const char kWlanGetAvailableNetworkList[] = "WlanGetAvailableNetworkList"; | 41 const char kWlanGetAvailableNetworkList[] = "WlanGetAvailableNetworkList"; |
42 const char kWlanGetNetworkBssList[] = "WlanGetNetworkBssList"; | 42 const char kWlanGetNetworkBssList[] = "WlanGetNetworkBssList"; |
43 const char kWlanGetProfile[] = "WlanGetProfile"; | 43 const char kWlanGetProfile[] = "WlanGetProfile"; |
44 const char kWlanOpenHandle[] = "WlanOpenHandle"; | 44 const char kWlanOpenHandle[] = "WlanOpenHandle"; |
| 45 const char kWlanQueryInterface[] = "WlanQueryInterface"; |
45 const char kWlanRegisterNotification[] = "WlanRegisterNotification"; | 46 const char kWlanRegisterNotification[] = "WlanRegisterNotification"; |
46 const char kWlanSaveTemporaryProfile[] = "WlanSaveTemporaryProfile"; | 47 const char kWlanSaveTemporaryProfile[] = "WlanSaveTemporaryProfile"; |
47 const char kWlanScan[] = "WlanScan"; | 48 const char kWlanScan[] = "WlanScan"; |
48 | 49 |
49 // WlanApi function definitions | 50 // WlanApi function definitions |
50 typedef DWORD (WINAPI* WlanConnectFunction)( | 51 typedef DWORD (WINAPI* WlanConnectFunction)( |
51 HANDLE hClientHandle, | 52 HANDLE hClientHandle, |
52 CONST GUID *pInterfaceGuid, | 53 CONST GUID *pInterfaceGuid, |
53 CONST PWLAN_CONNECTION_PARAMETERS pConnectionParameters, | 54 CONST PWLAN_CONNECTION_PARAMETERS pConnectionParameters, |
54 PVOID pReserved); | 55 PVOID pReserved); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 LPWSTR *pstrProfileXml, | 95 LPWSTR *pstrProfileXml, |
95 DWORD *pdwFlags, | 96 DWORD *pdwFlags, |
96 DWORD *pdwGrantedAccess); | 97 DWORD *pdwGrantedAccess); |
97 | 98 |
98 typedef DWORD (WINAPI* WlanOpenHandleFunction)( | 99 typedef DWORD (WINAPI* WlanOpenHandleFunction)( |
99 DWORD dwClientVersion, | 100 DWORD dwClientVersion, |
100 PVOID pReserved, | 101 PVOID pReserved, |
101 PDWORD pdwNegotiatedVersion, | 102 PDWORD pdwNegotiatedVersion, |
102 PHANDLE phClientHandle); | 103 PHANDLE phClientHandle); |
103 | 104 |
| 105 typedef DWORD (WINAPI* WlanQueryInterfaceFunction)( |
| 106 HANDLE hClientHandle, |
| 107 const GUID *pInterfaceGuid, |
| 108 WLAN_INTF_OPCODE OpCode, |
| 109 PVOID pReserved, |
| 110 PDWORD pdwDataSize, |
| 111 PVOID *ppData, |
| 112 PWLAN_OPCODE_VALUE_TYPE pWlanOpcodeValueType); |
| 113 |
104 typedef DWORD (WINAPI* WlanRegisterNotificationFunction)( | 114 typedef DWORD (WINAPI* WlanRegisterNotificationFunction)( |
105 HANDLE hClientHandle, | 115 HANDLE hClientHandle, |
106 DWORD dwNotifSource, | 116 DWORD dwNotifSource, |
107 BOOL bIgnoreDuplicate, | 117 BOOL bIgnoreDuplicate, |
108 WLAN_NOTIFICATION_CALLBACK funcCallback, | 118 WLAN_NOTIFICATION_CALLBACK funcCallback, |
109 PVOID pCallbackContext, | 119 PVOID pCallbackContext, |
110 PVOID pReserved, | 120 PVOID pReserved, |
111 PDWORD pdwPrevNotifSource); | 121 PDWORD pdwPrevNotifSource); |
112 | 122 |
113 typedef DWORD (WINAPI* WlanSaveTemporaryProfileFunction)( | 123 typedef DWORD (WINAPI* WlanSaveTemporaryProfileFunction)( |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 | 296 |
287 // Connect to network |network_guid| using previosly stored profile if exists, | 297 // Connect to network |network_guid| using previosly stored profile if exists, |
288 // or just network sid. If |frequency| is not |kFrequencyUnknown| then | 298 // or just network sid. If |frequency| is not |kFrequencyUnknown| then |
289 // connects only to BSS which uses that frequency and returns | 299 // connects only to BSS which uses that frequency and returns |
290 // |ERROR_NOT_FOUND| if such BSS cannot be found. | 300 // |ERROR_NOT_FOUND| if such BSS cannot be found. |
291 DWORD Connect(const std::string& network_guid, Frequency frequency); | 301 DWORD Connect(const std::string& network_guid, Frequency frequency); |
292 | 302 |
293 // Disconnect from currently connected network if any. | 303 // Disconnect from currently connected network if any. |
294 DWORD Disconnect(); | 304 DWORD Disconnect(); |
295 | 305 |
| 306 // Get Frequency of currently connected network |network_guid|. If network is |
| 307 // not connected, then return |kFrequencyUnknown|. |
| 308 Frequency WiFiServiceImpl::GetConnectedFrequency( |
| 309 const std::string& network_guid); |
| 310 |
| 311 // Get desired connection freqency if it was set using |SetProperties|. |
| 312 // Default to |kFrequencyAny|. |
| 313 Frequency GetFrequencyToConnect(const std::string& network_guid) const; |
| 314 |
296 // Get DOT11_BSSID_LIST of desired BSSIDs to connect to |ssid| network on | 315 // Get DOT11_BSSID_LIST of desired BSSIDs to connect to |ssid| network on |
297 // given |frequency|. | 316 // given |frequency|. |
298 DWORD GetDesiredBssList(DOT11_SSID& ssid, | 317 DWORD GetDesiredBssList(DOT11_SSID& ssid, |
299 Frequency frequency, | 318 Frequency frequency, |
300 scoped_ptr<DOT11_BSSID_LIST>* desired_list); | 319 scoped_ptr<DOT11_BSSID_LIST>* desired_list); |
301 | 320 |
| 321 // Normalizes |frequency_in_mhz| into one of |Frequency| values. |
| 322 Frequency GetNormalizedFrequency(int frequency_in_mhz) const; |
| 323 |
302 // Save temporary wireless profile for |network_guid|. | 324 // Save temporary wireless profile for |network_guid|. |
303 DWORD SaveTempProfile(const std::string& network_guid); | 325 DWORD SaveTempProfile(const std::string& network_guid); |
304 | 326 |
305 // Get previously stored |profile_xml| for |network_guid|. | 327 // Get previously stored |profile_xml| for |network_guid|. |
306 DWORD GetProfile(const std::string& network_guid, std::string* profile_xml); | 328 DWORD GetProfile(const std::string& network_guid, std::string* profile_xml); |
307 | 329 |
308 // Return true if there is previously stored profile xml for |network_guid|. | 330 // Return true if there is previously stored profile xml for |network_guid|. |
309 bool HaveProfile(const std::string& network_guid); | 331 bool HaveProfile(const std::string& network_guid); |
310 | 332 |
311 // Notify |network_list_changed_observer_| that list of visible networks has | 333 // Notify |network_list_changed_observer_| that list of visible networks has |
(...skipping 12 matching lines...) Expand all Loading... |
324 WlanConnectFunction WlanConnect_function_; | 346 WlanConnectFunction WlanConnect_function_; |
325 WlanCloseHandleFunction WlanCloseHandle_function_; | 347 WlanCloseHandleFunction WlanCloseHandle_function_; |
326 WlanDisconnectFunction WlanDisconnect_function_; | 348 WlanDisconnectFunction WlanDisconnect_function_; |
327 WlanEnumInterfacesFunction WlanEnumInterfaces_function_; | 349 WlanEnumInterfacesFunction WlanEnumInterfaces_function_; |
328 WlanFreeMemoryFunction WlanFreeMemory_function_; | 350 WlanFreeMemoryFunction WlanFreeMemory_function_; |
329 WlanGetAvailableNetworkListFunction WlanGetAvailableNetworkList_function_; | 351 WlanGetAvailableNetworkListFunction WlanGetAvailableNetworkList_function_; |
330 // WlanGetNetworkBssList function may not be avaiable on Windows XP. | 352 // WlanGetNetworkBssList function may not be avaiable on Windows XP. |
331 WlanGetNetworkBssListFunction WlanGetNetworkBssList_function_; | 353 WlanGetNetworkBssListFunction WlanGetNetworkBssList_function_; |
332 WlanGetProfileFunction WlanGetProfile_function_; | 354 WlanGetProfileFunction WlanGetProfile_function_; |
333 WlanOpenHandleFunction WlanOpenHandle_function_; | 355 WlanOpenHandleFunction WlanOpenHandle_function_; |
| 356 WlanQueryInterfaceFunction WlanQueryInterface_function_; |
334 WlanRegisterNotificationFunction WlanRegisterNotification_function_; | 357 WlanRegisterNotificationFunction WlanRegisterNotification_function_; |
335 WlanScanFunction WlanScan_function_; | 358 WlanScanFunction WlanScan_function_; |
336 // WlanSaveTemporaryProfile function may not be avaiable on Windows XP. | 359 // WlanSaveTemporaryProfile function may not be avaiable on Windows XP. |
337 WlanSaveTemporaryProfileFunction WlanSaveTemporaryProfile_function_; | 360 WlanSaveTemporaryProfileFunction WlanSaveTemporaryProfile_function_; |
338 | 361 |
339 // WLAN service handle. | 362 // WLAN service handle. |
340 HANDLE client_; | 363 HANDLE client_; |
341 // GUID of the currently connected interface, if any, otherwise the GUID of | 364 // GUID of the currently connected interface, if any, otherwise the GUID of |
342 // one of the WLAN interfaces. | 365 // one of the WLAN interfaces. |
343 GUID interface_guid_; | 366 GUID interface_guid_; |
| 367 // Temporary storage of network properties indexed by |network_guid|. Persist |
| 368 // only in memory. |
| 369 DictionaryValue connect_properties_; |
344 // Preserved WLAN profile xml. | 370 // Preserved WLAN profile xml. |
345 std::map<std::string, std::string> saved_profiles_xml_; | 371 std::map<std::string, std::string> saved_profiles_xml_; |
346 // Observer to get notified when network(s) have changed (e.g. connect). | 372 // Observer to get notified when network(s) have changed (e.g. connect). |
347 NetworkGuidListCallback networks_changed_observer_; | 373 NetworkGuidListCallback networks_changed_observer_; |
348 // Observer to get notified when network list has changed (scan complete). | 374 // Observer to get notified when network list has changed (scan complete). |
349 NetworkGuidListCallback network_list_changed_observer_; | 375 NetworkGuidListCallback network_list_changed_observer_; |
350 // Saved value of network location wizard show value. | 376 // Saved value of network location wizard show value. |
351 scoped_ptr<DWORD> saved_nw_category_wizard_; | 377 scoped_ptr<DWORD> saved_nw_category_wizard_; |
352 // MessageLoopProxy to post events on UI thread. | 378 // MessageLoopProxy to post events on UI thread. |
353 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; | 379 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 } | 440 } |
415 } | 441 } |
416 | 442 |
417 CheckError(error_code, kWiFiServiceError, error); | 443 CheckError(error_code, kWiFiServiceError, error); |
418 } | 444 } |
419 | 445 |
420 void WiFiServiceImpl::SetProperties( | 446 void WiFiServiceImpl::SetProperties( |
421 const std::string& network_guid, | 447 const std::string& network_guid, |
422 scoped_ptr<base::DictionaryValue> properties, | 448 scoped_ptr<base::DictionaryValue> properties, |
423 std::string* error) { | 449 std::string* error) { |
424 // This method is not implemented in first version as it is not used by | 450 // Temporary preserve WiFi properties (desired frequency, wifi password) to |
425 // Google Cast extension. | 451 // use in StartConnect. |
426 CheckError(ERROR_CALL_NOT_IMPLEMENTED, kWiFiServiceError, error); | 452 DCHECK(properties.get()); |
| 453 if (!properties->HasKey(onc::network_type::kWiFi)) { |
| 454 DVLOG(0) << "Missing WiFi properties:" << *properties; |
| 455 *error = kWiFiServiceError; |
| 456 return; |
| 457 } |
| 458 connect_properties_.SetWithoutPathExpansion(network_guid, |
| 459 properties.release()); |
427 } | 460 } |
428 | 461 |
429 void WiFiServiceImpl::GetVisibleNetworks(const std::string& network_type, | 462 void WiFiServiceImpl::GetVisibleNetworks(const std::string& network_type, |
430 ListValue* network_list) { | 463 ListValue* network_list) { |
431 if (!network_type.empty() && | 464 if (!network_type.empty() && |
432 network_type != onc::network_type::kAllTypes && | 465 network_type != onc::network_type::kAllTypes && |
433 network_type != onc::network_type::kWiFi) { | 466 network_type != onc::network_type::kWiFi) { |
434 return; | 467 return; |
435 } | 468 } |
436 | 469 |
(...skipping 21 matching lines...) Expand all Loading... |
458 } | 491 } |
459 | 492 |
460 void WiFiServiceImpl::StartConnect(const std::string& network_guid, | 493 void WiFiServiceImpl::StartConnect(const std::string& network_guid, |
461 std::string* error) { | 494 std::string* error) { |
462 DVLOG(1) << "Start Connect: " << network_guid; | 495 DVLOG(1) << "Start Connect: " << network_guid; |
463 DWORD error_code = EnsureInitialized(); | 496 DWORD error_code = EnsureInitialized(); |
464 if (error_code == ERROR_SUCCESS) { | 497 if (error_code == ERROR_SUCCESS) { |
465 std::string connected_network_guid; | 498 std::string connected_network_guid; |
466 error_code = SaveCurrentConnectedNetwork(&connected_network_guid); | 499 error_code = SaveCurrentConnectedNetwork(&connected_network_guid); |
467 if (error_code == ERROR_SUCCESS) { | 500 if (error_code == ERROR_SUCCESS) { |
468 Frequency frequency = kFrequencyAny; | 501 // Check, if the network is already connected on desired frequency. |
| 502 bool already_connected = (network_guid == connected_network_guid); |
| 503 Frequency frequency = GetFrequencyToConnect(network_guid); |
| 504 if (already_connected && frequency != kFrequencyAny) { |
| 505 Frequency connected_frequency = GetConnectedFrequency(network_guid); |
| 506 already_connected = (frequency == connected_frequency); |
| 507 } |
469 // Connect only if network |network_guid| is not connected already. | 508 // Connect only if network |network_guid| is not connected already. |
470 if (network_guid != connected_network_guid) | 509 if (!already_connected) |
471 error_code = Connect(network_guid, frequency); | 510 error_code = Connect(network_guid, frequency); |
472 if (error_code == ERROR_SUCCESS) { | 511 if (error_code == ERROR_SUCCESS) { |
473 // Notify that previously connected network has changed. | 512 // Notify that previously connected network has changed. |
474 NotifyNetworkChanged(connected_network_guid); | 513 NotifyNetworkChanged(connected_network_guid); |
475 // Start waiting for network connection state change. | 514 // Start waiting for network connection state change. |
476 if (!networks_changed_observer_.is_null()) { | 515 if (!networks_changed_observer_.is_null()) { |
477 DisableNwCategoryWizard(); | 516 DisableNwCategoryWizard(); |
478 // Disable automatic network change notifications as they get fired | 517 // Disable automatic network change notifications as they get fired |
479 // when network is just connected, but not yet accessible (doesn't | 518 // when network is just connected, but not yet accessible (doesn't |
480 // have valid IP address). | 519 // have valid IP address). |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
673 ::GetProcAddress(wlan_api_library_, kWlanGetAvailableNetworkList)); | 712 ::GetProcAddress(wlan_api_library_, kWlanGetAvailableNetworkList)); |
674 WlanGetNetworkBssList_function_ = | 713 WlanGetNetworkBssList_function_ = |
675 reinterpret_cast<WlanGetNetworkBssListFunction>( | 714 reinterpret_cast<WlanGetNetworkBssListFunction>( |
676 ::GetProcAddress(wlan_api_library_, kWlanGetNetworkBssList)); | 715 ::GetProcAddress(wlan_api_library_, kWlanGetNetworkBssList)); |
677 WlanGetProfile_function_ = | 716 WlanGetProfile_function_ = |
678 reinterpret_cast<WlanGetProfileFunction>( | 717 reinterpret_cast<WlanGetProfileFunction>( |
679 ::GetProcAddress(wlan_api_library_, kWlanGetProfile)); | 718 ::GetProcAddress(wlan_api_library_, kWlanGetProfile)); |
680 WlanOpenHandle_function_ = | 719 WlanOpenHandle_function_ = |
681 reinterpret_cast<WlanOpenHandleFunction>( | 720 reinterpret_cast<WlanOpenHandleFunction>( |
682 ::GetProcAddress(wlan_api_library_, kWlanOpenHandle)); | 721 ::GetProcAddress(wlan_api_library_, kWlanOpenHandle)); |
| 722 WlanQueryInterface_function_ = |
| 723 reinterpret_cast<WlanQueryInterfaceFunction>( |
| 724 ::GetProcAddress(wlan_api_library_, kWlanQueryInterface)); |
683 WlanRegisterNotification_function_ = | 725 WlanRegisterNotification_function_ = |
684 reinterpret_cast<WlanRegisterNotificationFunction>( | 726 reinterpret_cast<WlanRegisterNotificationFunction>( |
685 ::GetProcAddress(wlan_api_library_, kWlanRegisterNotification)); | 727 ::GetProcAddress(wlan_api_library_, kWlanRegisterNotification)); |
686 WlanSaveTemporaryProfile_function_ = | 728 WlanSaveTemporaryProfile_function_ = |
687 reinterpret_cast<WlanSaveTemporaryProfileFunction>( | 729 reinterpret_cast<WlanSaveTemporaryProfileFunction>( |
688 ::GetProcAddress(wlan_api_library_, kWlanSaveTemporaryProfile)); | 730 ::GetProcAddress(wlan_api_library_, kWlanSaveTemporaryProfile)); |
689 WlanScan_function_ = | 731 WlanScan_function_ = |
690 reinterpret_cast<WlanScanFunction>( | 732 reinterpret_cast<WlanScanFunction>( |
691 ::GetProcAddress(wlan_api_library_, kWlanScan)); | 733 ::GetProcAddress(wlan_api_library_, kWlanScan)); |
692 | 734 |
693 if (!WlanConnect_function_ || | 735 if (!WlanConnect_function_ || |
694 !WlanCloseHandle_function_ || | 736 !WlanCloseHandle_function_ || |
695 !WlanDisconnect_function_ || | 737 !WlanDisconnect_function_ || |
696 !WlanEnumInterfaces_function_ || | 738 !WlanEnumInterfaces_function_ || |
697 !WlanFreeMemory_function_ || | 739 !WlanFreeMemory_function_ || |
698 !WlanGetAvailableNetworkList_function_ || | 740 !WlanGetAvailableNetworkList_function_ || |
699 !WlanGetProfile_function_ || | 741 !WlanGetProfile_function_ || |
700 !WlanOpenHandle_function_ || | 742 !WlanOpenHandle_function_ || |
| 743 !WlanQueryInterface_function_ || |
701 !WlanRegisterNotification_function_ || | 744 !WlanRegisterNotification_function_ || |
702 !WlanScan_function_) { | 745 !WlanScan_function_) { |
703 DLOG(ERROR) << "Unable to find required WlanApi function."; | 746 DLOG(ERROR) << "Unable to find required WlanApi function."; |
704 FreeLibrary(wlan_api_library_); | 747 FreeLibrary(wlan_api_library_); |
705 wlan_api_library_ = NULL; | 748 wlan_api_library_ = NULL; |
706 return ERROR_NOT_FOUND; | 749 return ERROR_NOT_FOUND; |
707 } | 750 } |
708 | 751 |
709 // Some WlanApi functions may not be available on XP. | 752 // Some WlanApi functions may not be available on XP. |
710 if (!WlanGetNetworkBssList_function_ || | 753 if (!WlanGetNetworkBssList_function_ || |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
746 WLAN_NOTIFICATION_SOURCE_ALL, | 789 WLAN_NOTIFICATION_SOURCE_ALL, |
747 FALSE, | 790 FALSE, |
748 OnWlanNotificationCallback, | 791 OnWlanNotificationCallback, |
749 this, | 792 this, |
750 NULL, | 793 NULL, |
751 NULL); | 794 NULL); |
752 } else { | 795 } else { |
753 error = ERROR_NOINTERFACE; | 796 error = ERROR_NOINTERFACE; |
754 } | 797 } |
755 } | 798 } |
756 // Clean up. | 799 // Clean up.. |
757 if (interface_list != NULL) | 800 if (interface_list != NULL) |
758 WlanFreeMemory_function_(interface_list); | 801 WlanFreeMemory_function_(interface_list); |
759 } | 802 } |
760 return error; | 803 return error; |
761 } | 804 } |
762 | 805 |
763 DWORD WiFiServiceImpl::ResetDHCP() { | 806 DWORD WiFiServiceImpl::ResetDHCP() { |
764 IP_ADAPTER_INDEX_MAP adapter_index_map = {0}; | 807 IP_ADAPTER_INDEX_MAP adapter_index_map = {0}; |
765 DWORD error = FindAdapterIndexMapByGUID(interface_guid_, &adapter_index_map); | 808 DWORD error = FindAdapterIndexMapByGUID(interface_guid_, &adapter_index_map); |
766 if (error == ERROR_SUCCESS) { | 809 if (error == ERROR_SUCCESS) { |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
929 properties->name = properties->ssid; | 972 properties->name = properties->ssid; |
930 properties->guid = GUIDFromWLAN(wlan); | 973 properties->guid = GUIDFromWLAN(wlan); |
931 properties->type = onc::network_type::kWiFi; | 974 properties->type = onc::network_type::kWiFi; |
932 | 975 |
933 for (size_t bss = 0; bss < wlan_bss_list.dwNumberOfItems; ++bss) { | 976 for (size_t bss = 0; bss < wlan_bss_list.dwNumberOfItems; ++bss) { |
934 const WLAN_BSS_ENTRY& bss_entry(wlan_bss_list.wlanBssEntries[bss]); | 977 const WLAN_BSS_ENTRY& bss_entry(wlan_bss_list.wlanBssEntries[bss]); |
935 if (bss_entry.dot11Ssid.uSSIDLength == wlan.dot11Ssid.uSSIDLength && | 978 if (bss_entry.dot11Ssid.uSSIDLength == wlan.dot11Ssid.uSSIDLength && |
936 0 == memcmp(bss_entry.dot11Ssid.ucSSID, | 979 0 == memcmp(bss_entry.dot11Ssid.ucSSID, |
937 wlan.dot11Ssid.ucSSID, | 980 wlan.dot11Ssid.ucSSID, |
938 bss_entry.dot11Ssid.uSSIDLength)) { | 981 bss_entry.dot11Ssid.uSSIDLength)) { |
939 if (bss_entry.ulChCenterFrequency < 3000000) | 982 properties->frequency = GetNormalizedFrequency( |
940 properties->frequency = kFrequency2400; | 983 bss_entry.ulChCenterFrequency / 1000); |
941 else | |
942 properties->frequency = kFrequency5000; | |
943 properties->frequency_list.push_back(properties->frequency); | 984 properties->frequency_list.push_back(properties->frequency); |
944 properties->bssid = NetworkProperties::MacAddressAsString( | 985 properties->bssid = NetworkProperties::MacAddressAsString( |
945 bss_entry.dot11Bssid); | 986 bss_entry.dot11Bssid); |
946 } | 987 } |
947 } | 988 } |
948 properties->frequency_list.sort(); | 989 properties->frequency_list.sort(); |
949 properties->frequency_list.unique(); | 990 properties->frequency_list.unique(); |
950 properties->security = | 991 properties->security = |
951 SecurityFromDot11AuthAlg(wlan.dot11DefaultAuthAlgorithm); | 992 SecurityFromDot11AuthAlg(wlan.dot11DefaultAuthAlgorithm); |
952 properties->signal_strength = wlan.wlanSignalQuality; | 993 properties->signal_strength = wlan.wlanSignalQuality; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1005 network_properties.connection_state; | 1046 network_properties.connection_state; |
1006 } | 1047 } |
1007 } else { | 1048 } else { |
1008 network_list->push_back(network_properties); | 1049 network_list->push_back(network_properties); |
1009 } | 1050 } |
1010 network_guids.insert(network_properties.guid); | 1051 network_guids.insert(network_properties.guid); |
1011 } | 1052 } |
1012 } | 1053 } |
1013 } | 1054 } |
1014 | 1055 |
1015 // clean up | 1056 // Clean up. |
1016 if (available_network_list != NULL) { | 1057 if (available_network_list != NULL) { |
1017 WlanFreeMemory_function_(available_network_list); | 1058 WlanFreeMemory_function_(available_network_list); |
1018 } | 1059 } |
1019 if (bss_list != NULL) { | 1060 if (bss_list != NULL) { |
1020 WlanFreeMemory_function_(bss_list); | 1061 WlanFreeMemory_function_(bss_list); |
1021 } | 1062 } |
1022 return error; | 1063 return error; |
1023 } | 1064 } |
1024 | 1065 |
1025 // Find currently connected network. | 1066 // Find currently connected network. |
(...skipping 12 matching lines...) Expand all Loading... |
1038 if (error == ERROR_SUCCESS && NULL != available_network_list) { | 1079 if (error == ERROR_SUCCESS && NULL != available_network_list) { |
1039 for (DWORD i = 0; i < available_network_list->dwNumberOfItems; ++i) { | 1080 for (DWORD i = 0; i < available_network_list->dwNumberOfItems; ++i) { |
1040 const WLAN_AVAILABLE_NETWORK& wlan = available_network_list->Network[i]; | 1081 const WLAN_AVAILABLE_NETWORK& wlan = available_network_list->Network[i]; |
1041 if (wlan.dwFlags & WLAN_AVAILABLE_NETWORK_CONNECTED) { | 1082 if (wlan.dwFlags & WLAN_AVAILABLE_NETWORK_CONNECTED) { |
1042 *connected_network_guid = GUIDFromWLAN(wlan); | 1083 *connected_network_guid = GUIDFromWLAN(wlan); |
1043 break; | 1084 break; |
1044 } | 1085 } |
1045 } | 1086 } |
1046 } | 1087 } |
1047 | 1088 |
1048 // clean up | 1089 // Clean up. |
1049 if (available_network_list != NULL) { | 1090 if (available_network_list != NULL) { |
1050 WlanFreeMemory_function_(available_network_list); | 1091 WlanFreeMemory_function_(available_network_list); |
1051 } | 1092 } |
1052 | 1093 |
1053 return error; | 1094 return error; |
1054 } | 1095 } |
1055 | 1096 |
| 1097 WiFiService::Frequency WiFiServiceImpl::GetConnectedFrequency( |
| 1098 const std::string& network_guid) { |
| 1099 if (client_ == NULL) { |
| 1100 NOTREACHED(); |
| 1101 return kFrequencyUnknown; |
| 1102 } |
| 1103 |
| 1104 // TODO(mef): WlanGetNetworkBssList is not available on XP. If XP support is |
| 1105 // needed, then different method of getting BSS (e.g. OID query) will have |
| 1106 // to be used. |
| 1107 if (WlanGetNetworkBssList_function_ == NULL) |
| 1108 return kFrequencyUnknown; |
| 1109 |
| 1110 Frequency frequency = kFrequencyUnknown; |
| 1111 DWORD error = ERROR_SUCCESS; |
| 1112 DWORD data_size = 0; |
| 1113 PWLAN_CONNECTION_ATTRIBUTES wlan_connection_attributes = NULL; |
| 1114 PWLAN_BSS_LIST bss_list = NULL; |
| 1115 error = WlanQueryInterface_function_( |
| 1116 client_, |
| 1117 &interface_guid_, |
| 1118 wlan_intf_opcode_current_connection, |
| 1119 NULL, |
| 1120 &data_size, |
| 1121 reinterpret_cast<PVOID*>(&wlan_connection_attributes), |
| 1122 NULL); |
| 1123 if (error == ERROR_SUCCESS && |
| 1124 wlan_connection_attributes != NULL && |
| 1125 wlan_connection_attributes->isState == wlan_interface_state_connected) { |
| 1126 WLAN_ASSOCIATION_ATTRIBUTES& connected_wlan = |
| 1127 wlan_connection_attributes->wlanAssociationAttributes; |
| 1128 // Try to find connected frequency based on bss. |
| 1129 if (GUIDFromSSID(connected_wlan.dot11Ssid) == network_guid && |
| 1130 WlanGetNetworkBssList_function_ != NULL) { |
| 1131 error = WlanGetNetworkBssList_function_(client_, |
| 1132 &interface_guid_, |
| 1133 &connected_wlan.dot11Ssid, |
| 1134 connected_wlan.dot11BssType, |
| 1135 FALSE, |
| 1136 NULL, |
| 1137 &bss_list); |
| 1138 if (error == ERROR_SUCCESS && NULL != bss_list) { |
| 1139 // Go through bss_list and find matching BSSID. |
| 1140 for (size_t bss = 0; bss < bss_list->dwNumberOfItems; ++bss) { |
| 1141 const WLAN_BSS_ENTRY& bss_entry(bss_list->wlanBssEntries[bss]); |
| 1142 if (0 == memcmp(bss_entry.dot11Bssid, |
| 1143 connected_wlan.dot11Bssid, |
| 1144 sizeof(bss_entry.dot11Bssid))) { |
| 1145 frequency = GetNormalizedFrequency( |
| 1146 bss_entry.ulChCenterFrequency / 1000); |
| 1147 break; |
| 1148 } |
| 1149 } |
| 1150 } |
| 1151 } |
| 1152 } |
| 1153 |
| 1154 // Clean up. |
| 1155 if (wlan_connection_attributes != NULL) { |
| 1156 WlanFreeMemory_function_(wlan_connection_attributes); |
| 1157 } |
| 1158 |
| 1159 if (bss_list != NULL) { |
| 1160 WlanFreeMemory_function_(bss_list); |
| 1161 } |
| 1162 |
| 1163 return frequency; |
| 1164 } |
| 1165 |
| 1166 WiFiService::Frequency WiFiServiceImpl::GetFrequencyToConnect( |
| 1167 const std::string& network_guid) const { |
| 1168 // Check whether desired frequency is set in |connect_properties_|. |
| 1169 const DictionaryValue* properties; |
| 1170 const DictionaryValue* wifi; |
| 1171 int frequency; |
| 1172 if (connect_properties_.GetDictionaryWithoutPathExpansion( |
| 1173 network_guid, &properties) && |
| 1174 properties->GetDictionary(onc::network_type::kWiFi, &wifi) && |
| 1175 wifi->GetInteger(onc::wifi::kFrequency, &frequency)) { |
| 1176 return GetNormalizedFrequency(frequency); |
| 1177 } |
| 1178 return kFrequencyAny; |
| 1179 } |
| 1180 |
1056 DWORD WiFiServiceImpl::GetDesiredBssList( | 1181 DWORD WiFiServiceImpl::GetDesiredBssList( |
1057 DOT11_SSID& ssid, | 1182 DOT11_SSID& ssid, |
1058 Frequency frequency, | 1183 Frequency frequency, |
1059 scoped_ptr<DOT11_BSSID_LIST>* desired_list) { | 1184 scoped_ptr<DOT11_BSSID_LIST>* desired_list) { |
1060 if (client_ == NULL) { | 1185 if (client_ == NULL) { |
1061 NOTREACHED(); | 1186 NOTREACHED(); |
1062 return ERROR_NOINTERFACE; | 1187 return ERROR_NOINTERFACE; |
1063 } | 1188 } |
1064 | 1189 |
1065 desired_list->reset(); | 1190 desired_list->reset(); |
1066 | 1191 |
1067 if (frequency == kFrequencyAny) | 1192 if (frequency == kFrequencyAny) |
1068 return ERROR_SUCCESS; | 1193 return ERROR_SUCCESS; |
1069 | 1194 |
1070 // TODO(mef): WlanGetNetworkBssList is not available on XP. If XP support is | 1195 // TODO(mef): WlanGetNetworkBssList is not available on XP. If XP support is |
1071 // needed, then different method of getting BSS (e.g. OID query) will have | 1196 // needed, then different method of getting BSS (e.g. OID query) will have |
1072 // to be used. | 1197 // to be used. |
1073 if (!WlanGetNetworkBssList_function_) | 1198 if (!WlanGetNetworkBssList_function_) |
1074 return ERROR_NOT_SUPPORTED; | 1199 return ERROR_NOT_SUPPORTED; |
1075 | 1200 |
1076 DWORD error = ERROR_SUCCESS; | 1201 DWORD error = ERROR_SUCCESS; |
1077 PWLAN_BSS_LIST bss_list = NULL; | 1202 PWLAN_BSS_LIST bss_list = NULL; |
1078 | 1203 |
1079 error = WlanGetNetworkBssList_function_(client_, | 1204 error = WlanGetNetworkBssList_function_(client_, |
1080 &interface_guid_, | 1205 &interface_guid_, |
1081 NULL, | 1206 &ssid, |
1082 dot11_BSS_type_any, | 1207 dot11_BSS_type_infrastructure, |
1083 FALSE, | 1208 FALSE, |
1084 NULL, | 1209 NULL, |
1085 &bss_list); | 1210 &bss_list); |
1086 if (error == ERROR_SUCCESS && NULL != bss_list) { | 1211 if (error == ERROR_SUCCESS && NULL != bss_list) { |
1087 unsigned int best_quality = 0u; | 1212 unsigned int best_quality = 0u; |
1088 size_t best_index = 0; | 1213 size_t best_index = 0; |
1089 Frequency bss_frequency; | 1214 Frequency bss_frequency; |
1090 | 1215 |
1091 // Go through bss_list and find best quality BSSID with matching frequency. | 1216 // Go through bss_list and find best quality BSSID with matching frequency. |
1092 for (size_t bss = 0; bss < bss_list->dwNumberOfItems; ++bss) { | 1217 for (size_t bss = 0; bss < bss_list->dwNumberOfItems; ++bss) { |
1093 const WLAN_BSS_ENTRY& bss_entry(bss_list->wlanBssEntries[bss]); | 1218 const WLAN_BSS_ENTRY& bss_entry(bss_list->wlanBssEntries[bss]); |
1094 if (bss_entry.dot11Ssid.uSSIDLength != ssid.uSSIDLength || | 1219 if (bss_entry.dot11Ssid.uSSIDLength != ssid.uSSIDLength || |
1095 0 != memcmp(bss_entry.dot11Ssid.ucSSID, | 1220 0 != memcmp(bss_entry.dot11Ssid.ucSSID, |
1096 ssid.ucSSID, | 1221 ssid.ucSSID, |
1097 bss_entry.dot11Ssid.uSSIDLength)) | 1222 bss_entry.dot11Ssid.uSSIDLength)) |
1098 continue; | 1223 continue; |
1099 | 1224 |
1100 if (bss_entry.ulChCenterFrequency < 3000000) | 1225 bss_frequency = GetNormalizedFrequency( |
1101 bss_frequency = kFrequency2400; | 1226 bss_entry.ulChCenterFrequency / 1000); |
1102 else | |
1103 bss_frequency = kFrequency5000; | |
1104 | |
1105 if (bss_frequency == frequency && | 1227 if (bss_frequency == frequency && |
1106 bss_entry.uLinkQuality > best_quality) { | 1228 bss_entry.uLinkQuality > best_quality) { |
1107 best_quality = bss_entry.uLinkQuality; | 1229 best_quality = bss_entry.uLinkQuality; |
1108 best_index = bss; | 1230 best_index = bss; |
1109 } | 1231 } |
1110 } | 1232 } |
1111 | 1233 |
1112 // If any matching BSS were found, prepare the header. | 1234 // If any matching BSS were found, prepare the header. |
1113 if (best_quality > 0) { | 1235 if (best_quality > 0) { |
1114 const WLAN_BSS_ENTRY& bss_entry(bss_list->wlanBssEntries[best_index]); | 1236 const WLAN_BSS_ENTRY& bss_entry(bss_list->wlanBssEntries[best_index]); |
1115 scoped_ptr<DOT11_BSSID_LIST> selected_list(new DOT11_BSSID_LIST); | 1237 scoped_ptr<DOT11_BSSID_LIST> selected_list(new DOT11_BSSID_LIST); |
1116 | 1238 |
1117 selected_list->Header.Revision = DOT11_BSSID_LIST_REVISION_1; | 1239 selected_list->Header.Revision = DOT11_BSSID_LIST_REVISION_1; |
1118 selected_list->Header.Size = sizeof(DOT11_BSSID_LIST); | 1240 selected_list->Header.Size = sizeof(DOT11_BSSID_LIST); |
1119 selected_list->Header.Type = NDIS_OBJECT_TYPE_DEFAULT; | 1241 selected_list->Header.Type = NDIS_OBJECT_TYPE_DEFAULT; |
1120 selected_list->uNumOfEntries = 1; | 1242 selected_list->uNumOfEntries = 1; |
1121 selected_list->uTotalNumOfEntries = 1; | 1243 selected_list->uTotalNumOfEntries = 1; |
1122 std::copy(bss_entry.dot11Bssid, | 1244 std::copy(bss_entry.dot11Bssid, |
1123 bss_entry.dot11Bssid+sizeof(bss_entry.dot11Bssid), | 1245 bss_entry.dot11Bssid+sizeof(bss_entry.dot11Bssid), |
1124 selected_list->BSSIDs[0]); | 1246 selected_list->BSSIDs[0]); |
1125 desired_list->swap(selected_list); | 1247 desired_list->swap(selected_list); |
1126 DVLOG(1) << "Quality: " << best_quality << " BSS: " | 1248 DVLOG(1) << "Quality: " << best_quality << " BSS: " |
1127 << NetworkProperties::MacAddressAsString(bss_entry.dot11Bssid); | 1249 << NetworkProperties::MacAddressAsString(bss_entry.dot11Bssid); |
1128 } else { | 1250 } else { |
1129 error = ERROR_NOT_FOUND; | 1251 error = ERROR_NOT_FOUND; |
1130 } | 1252 } |
1131 } | 1253 } |
1132 | 1254 |
1133 // clean up | 1255 // Clean up. |
1134 if (bss_list != NULL) { | 1256 if (bss_list != NULL) { |
1135 WlanFreeMemory_function_(bss_list); | 1257 WlanFreeMemory_function_(bss_list); |
1136 } | 1258 } |
1137 return error; | 1259 return error; |
1138 } | 1260 } |
1139 | 1261 |
| 1262 WiFiService::Frequency WiFiServiceImpl::GetNormalizedFrequency( |
| 1263 int frequency_in_mhz) const { |
| 1264 if (frequency_in_mhz == 0) |
| 1265 return kFrequencyAny; |
| 1266 if (frequency_in_mhz < 3000) |
| 1267 return kFrequency2400; |
| 1268 return kFrequency5000; |
| 1269 } |
1140 | 1270 |
1141 DWORD WiFiServiceImpl::Connect(const std::string& network_guid, | 1271 DWORD WiFiServiceImpl::Connect(const std::string& network_guid, |
1142 Frequency frequency) { | 1272 Frequency frequency) { |
1143 if (client_ == NULL) { | 1273 if (client_ == NULL) { |
1144 NOTREACHED(); | 1274 NOTREACHED(); |
1145 return ERROR_NOINTERFACE; | 1275 return ERROR_NOINTERFACE; |
1146 } | 1276 } |
1147 | 1277 |
1148 DWORD error = ERROR_SUCCESS; | 1278 DWORD error = ERROR_SUCCESS; |
1149 DOT11_SSID ssid = SSIDFromGUID(network_guid); | 1279 DOT11_SSID ssid = SSIDFromGUID(network_guid); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1230 &interface_guid_, | 1360 &interface_guid_, |
1231 profile_name.c_str(), | 1361 profile_name.c_str(), |
1232 NULL, | 1362 NULL, |
1233 &str_profile_xml, | 1363 &str_profile_xml, |
1234 NULL, | 1364 NULL, |
1235 NULL); | 1365 NULL); |
1236 | 1366 |
1237 if (error == ERROR_SUCCESS && str_profile_xml != NULL) { | 1367 if (error == ERROR_SUCCESS && str_profile_xml != NULL) { |
1238 *profile_xml = base::UTF16ToUTF8(str_profile_xml); | 1368 *profile_xml = base::UTF16ToUTF8(str_profile_xml); |
1239 } | 1369 } |
1240 // clean up | 1370 // Clean up. |
1241 if (str_profile_xml != NULL) { | 1371 if (str_profile_xml != NULL) { |
1242 WlanFreeMemory_function_(str_profile_xml); | 1372 WlanFreeMemory_function_(str_profile_xml); |
1243 } | 1373 } |
1244 | 1374 |
1245 return error; | 1375 return error; |
1246 } | 1376 } |
1247 | 1377 |
1248 bool WiFiServiceImpl::HaveProfile(const std::string& network_guid) { | 1378 bool WiFiServiceImpl::HaveProfile(const std::string& network_guid) { |
1249 DWORD error = ERROR_SUCCESS; | 1379 DWORD error = ERROR_SUCCESS; |
1250 std::string profile_xml; | 1380 std::string profile_xml; |
(...skipping 22 matching lines...) Expand all Loading... |
1273 NetworkGuidList changed_networks(1, network_guid); | 1403 NetworkGuidList changed_networks(1, network_guid); |
1274 message_loop_proxy_->PostTask( | 1404 message_loop_proxy_->PostTask( |
1275 FROM_HERE, | 1405 FROM_HERE, |
1276 base::Bind(networks_changed_observer_, changed_networks)); | 1406 base::Bind(networks_changed_observer_, changed_networks)); |
1277 } | 1407 } |
1278 } | 1408 } |
1279 | 1409 |
1280 WiFiService* WiFiService::Create() { return new WiFiServiceImpl(); } | 1410 WiFiService* WiFiService::Create() { return new WiFiServiceImpl(); } |
1281 | 1411 |
1282 } // namespace wifi | 1412 } // namespace wifi |
OLD | NEW |