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 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
284 | 294 |
285 // Connect to network |network_guid| using previosly stored profile if exists, | 295 // Connect to network |network_guid| using previosly stored profile if exists, |
286 // or just network sid. If |frequency| is not |kFrequencyUnknown| then | 296 // or just network sid. If |frequency| is not |kFrequencyUnknown| then |
287 // connects only to BSS which uses that frequency and returns | 297 // connects only to BSS which uses that frequency and returns |
288 // |ERROR_NOT_FOUND| if such BSS cannot be found. | 298 // |ERROR_NOT_FOUND| if such BSS cannot be found. |
289 DWORD Connect(const std::string& network_guid, Frequency frequency); | 299 DWORD Connect(const std::string& network_guid, Frequency frequency); |
290 | 300 |
291 // Disconnect from currently connected network if any. | 301 // Disconnect from currently connected network if any. |
292 DWORD Disconnect(); | 302 DWORD Disconnect(); |
293 | 303 |
304 // Get Frequency of currently connected network |network_guid|. If network is | |
305 // not connected, then return |kFrequencyUnknown|. | |
306 Frequency WiFiServiceImpl::GetConnectedFrequency( | |
307 const std::string& network_guid); | |
308 | |
309 // Get desired connection freqency if it was set using |SetProperties|. | |
310 // Default to |kFrequencyAny|. | |
311 Frequency GetFrequencyToConnect(const std::string& network_guid) const; | |
312 | |
294 // Get DOT11_BSSID_LIST of desired BSSIDs to connect to |ssid| network on | 313 // Get DOT11_BSSID_LIST of desired BSSIDs to connect to |ssid| network on |
295 // given |frequency|. | 314 // given |frequency|. |
296 DWORD GetDesiredBssList(DOT11_SSID& ssid, | 315 DWORD GetDesiredBssList(DOT11_SSID& ssid, |
297 Frequency frequency, | 316 Frequency frequency, |
298 scoped_ptr<DOT11_BSSID_LIST>* desired_list); | 317 scoped_ptr<DOT11_BSSID_LIST>* desired_list); |
299 | 318 |
319 // Normalizes |frequency_in_mhz| into one of |Frequency| values. | |
320 Frequency GetNormalizedFrequency(int frequency_in_mhz) const; | |
321 | |
300 // Save temporary wireless profile for |network_guid|. | 322 // Save temporary wireless profile for |network_guid|. |
301 DWORD SaveTempProfile(const std::string& network_guid); | 323 DWORD SaveTempProfile(const std::string& network_guid); |
302 | 324 |
303 // Get previously stored |profile_xml| for |network_guid|. | 325 // Get previously stored |profile_xml| for |network_guid|. |
304 DWORD GetProfile(const std::string& network_guid, std::string* profile_xml); | 326 DWORD GetProfile(const std::string& network_guid, std::string* profile_xml); |
305 | 327 |
306 // Return true if there is previously stored profile xml for |network_guid|. | 328 // Return true if there is previously stored profile xml for |network_guid|. |
307 bool HaveProfile(const std::string& network_guid); | 329 bool HaveProfile(const std::string& network_guid); |
308 | 330 |
309 // Notify |network_list_changed_observer_| that list of visible networks has | 331 // Notify |network_list_changed_observer_| that list of visible networks has |
(...skipping 12 matching lines...) Expand all Loading... | |
322 WlanConnectFunction WlanConnect_function_; | 344 WlanConnectFunction WlanConnect_function_; |
323 WlanCloseHandleFunction WlanCloseHandle_function_; | 345 WlanCloseHandleFunction WlanCloseHandle_function_; |
324 WlanDisconnectFunction WlanDisconnect_function_; | 346 WlanDisconnectFunction WlanDisconnect_function_; |
325 WlanEnumInterfacesFunction WlanEnumInterfaces_function_; | 347 WlanEnumInterfacesFunction WlanEnumInterfaces_function_; |
326 WlanFreeMemoryFunction WlanFreeMemory_function_; | 348 WlanFreeMemoryFunction WlanFreeMemory_function_; |
327 WlanGetAvailableNetworkListFunction WlanGetAvailableNetworkList_function_; | 349 WlanGetAvailableNetworkListFunction WlanGetAvailableNetworkList_function_; |
328 // WlanGetNetworkBssList function may not be avaiable on Windows XP. | 350 // WlanGetNetworkBssList function may not be avaiable on Windows XP. |
329 WlanGetNetworkBssListFunction WlanGetNetworkBssList_function_; | 351 WlanGetNetworkBssListFunction WlanGetNetworkBssList_function_; |
330 WlanGetProfileFunction WlanGetProfile_function_; | 352 WlanGetProfileFunction WlanGetProfile_function_; |
331 WlanOpenHandleFunction WlanOpenHandle_function_; | 353 WlanOpenHandleFunction WlanOpenHandle_function_; |
354 WlanQueryInterfaceFunction WlanQueryInterface_function_; | |
332 WlanRegisterNotificationFunction WlanRegisterNotification_function_; | 355 WlanRegisterNotificationFunction WlanRegisterNotification_function_; |
333 WlanScanFunction WlanScan_function_; | 356 WlanScanFunction WlanScan_function_; |
334 // WlanSaveTemporaryProfile function may not be avaiable on Windows XP. | 357 // WlanSaveTemporaryProfile function may not be avaiable on Windows XP. |
335 WlanSaveTemporaryProfileFunction WlanSaveTemporaryProfile_function_; | 358 WlanSaveTemporaryProfileFunction WlanSaveTemporaryProfile_function_; |
336 | 359 |
337 // WLAN service handle. | 360 // WLAN service handle. |
338 HANDLE client_; | 361 HANDLE client_; |
339 // GUID of the currently connected interface, if any, otherwise the GUID of | 362 // GUID of the currently connected interface, if any, otherwise the GUID of |
340 // one of the WLAN interfaces. | 363 // one of the WLAN interfaces. |
341 GUID interface_guid_; | 364 GUID interface_guid_; |
365 // Temporary storage of network properties indexed by |network_guid|. Persist | |
366 // only in memory. | |
367 DictionaryValue connect_properties_; | |
342 // Preserved WLAN profile xml. | 368 // Preserved WLAN profile xml. |
343 std::map<std::string, std::string> saved_profiles_xml_; | 369 std::map<std::string, std::string> saved_profiles_xml_; |
344 // Observer to get notified when network(s) have changed (e.g. connect). | 370 // Observer to get notified when network(s) have changed (e.g. connect). |
345 NetworkGuidListCallback networks_changed_observer_; | 371 NetworkGuidListCallback networks_changed_observer_; |
346 // Observer to get notified when network list has changed (scan complete). | 372 // Observer to get notified when network list has changed (scan complete). |
347 NetworkGuidListCallback network_list_changed_observer_; | 373 NetworkGuidListCallback network_list_changed_observer_; |
348 // Saved value of network location wizard show value. | 374 // Saved value of network location wizard show value. |
349 scoped_ptr<DWORD> saved_nw_category_wizard_; | 375 scoped_ptr<DWORD> saved_nw_category_wizard_; |
350 // MessageLoopProxy to post events on UI thread. | 376 // MessageLoopProxy to post events on UI thread. |
351 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; | 377 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
412 } | 438 } |
413 } | 439 } |
414 | 440 |
415 CheckError(error_code, kWiFiServiceError, error); | 441 CheckError(error_code, kWiFiServiceError, error); |
416 } | 442 } |
417 | 443 |
418 void WiFiServiceImpl::SetProperties( | 444 void WiFiServiceImpl::SetProperties( |
419 const std::string& network_guid, | 445 const std::string& network_guid, |
420 scoped_ptr<base::DictionaryValue> properties, | 446 scoped_ptr<base::DictionaryValue> properties, |
421 std::string* error) { | 447 std::string* error) { |
422 // This method is not implemented in first version as it is not used by | 448 // Temporary preserve WiFi properties (desired frequency, wifi password) to |
423 // Google Cast extension. | 449 // use in StartConnect. |
424 CheckError(ERROR_CALL_NOT_IMPLEMENTED, kWiFiServiceError, error); | 450 DCHECK(properties.get()); |
451 if (!properties->HasKey(onc::network_type::kWiFi)) { | |
452 DVLOG(0) << "Missing WiFi properties:" << *properties; | |
453 *error = kWiFiServiceError; | |
454 return; | |
455 } | |
456 connect_properties_.SetWithoutPathExpansion(network_guid, | |
457 properties.release()); | |
425 } | 458 } |
426 | 459 |
427 void WiFiServiceImpl::GetVisibleNetworks(ListValue* network_list) { | 460 void WiFiServiceImpl::GetVisibleNetworks(ListValue* network_list) { |
428 DWORD error = EnsureInitialized(); | 461 DWORD error = EnsureInitialized(); |
429 | 462 |
430 if (error == ERROR_SUCCESS) { | 463 if (error == ERROR_SUCCESS) { |
431 NetworkList networks; | 464 NetworkList networks; |
432 error = GetVisibleNetworkList(&networks); | 465 error = GetVisibleNetworkList(&networks); |
433 if (error == ERROR_SUCCESS && !networks.empty()) { | 466 if (error == ERROR_SUCCESS && !networks.empty()) { |
434 SortNetworks(&networks); | 467 SortNetworks(&networks); |
(...skipping 15 matching lines...) Expand all Loading... | |
450 } | 483 } |
451 | 484 |
452 void WiFiServiceImpl::StartConnect(const std::string& network_guid, | 485 void WiFiServiceImpl::StartConnect(const std::string& network_guid, |
453 std::string* error) { | 486 std::string* error) { |
454 DVLOG(1) << "Start Connect: " << network_guid; | 487 DVLOG(1) << "Start Connect: " << network_guid; |
455 DWORD error_code = EnsureInitialized(); | 488 DWORD error_code = EnsureInitialized(); |
456 if (error_code == ERROR_SUCCESS) { | 489 if (error_code == ERROR_SUCCESS) { |
457 std::string connected_network_guid; | 490 std::string connected_network_guid; |
458 error_code = SaveCurrentConnectedNetwork(&connected_network_guid); | 491 error_code = SaveCurrentConnectedNetwork(&connected_network_guid); |
459 if (error_code == ERROR_SUCCESS) { | 492 if (error_code == ERROR_SUCCESS) { |
460 Frequency frequency = kFrequencyAny; | 493 // Check, if the network is already connected on desired frequency. |
494 bool already_connected = (network_guid == connected_network_guid); | |
495 Frequency frequency = GetFrequencyToConnect(network_guid); | |
496 if (already_connected && frequency != kFrequencyAny) { | |
497 Frequency connected_frequency = GetConnectedFrequency(network_guid); | |
498 already_connected = (frequency == connected_frequency); | |
499 } | |
461 // Connect only if network |network_guid| is not connected already. | 500 // Connect only if network |network_guid| is not connected already. |
462 if (network_guid != connected_network_guid) | 501 if (!already_connected) |
463 error_code = Connect(network_guid, frequency); | 502 error_code = Connect(network_guid, frequency); |
464 if (error_code == ERROR_SUCCESS) { | 503 if (error_code == ERROR_SUCCESS) { |
465 // Notify that previously connected network has changed. | 504 // Notify that previously connected network has changed. |
466 NotifyNetworkChanged(connected_network_guid); | 505 NotifyNetworkChanged(connected_network_guid); |
467 // Start waiting for network connection state change. | 506 // Start waiting for network connection state change. |
468 if (!networks_changed_observer_.is_null()) { | 507 if (!networks_changed_observer_.is_null()) { |
469 DisableNwCategoryWizard(); | 508 DisableNwCategoryWizard(); |
470 // Disable automatic network change notifications as they get fired | 509 // Disable automatic network change notifications as they get fired |
471 // when network is just connected, but not yet accessible (doesn't | 510 // when network is just connected, but not yet accessible (doesn't |
472 // have valid IP address). | 511 // have valid IP address). |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
665 ::GetProcAddress(wlan_api_library_, kWlanGetAvailableNetworkList)); | 704 ::GetProcAddress(wlan_api_library_, kWlanGetAvailableNetworkList)); |
666 WlanGetNetworkBssList_function_ = | 705 WlanGetNetworkBssList_function_ = |
667 reinterpret_cast<WlanGetNetworkBssListFunction>( | 706 reinterpret_cast<WlanGetNetworkBssListFunction>( |
668 ::GetProcAddress(wlan_api_library_, kWlanGetNetworkBssList)); | 707 ::GetProcAddress(wlan_api_library_, kWlanGetNetworkBssList)); |
669 WlanGetProfile_function_ = | 708 WlanGetProfile_function_ = |
670 reinterpret_cast<WlanGetProfileFunction>( | 709 reinterpret_cast<WlanGetProfileFunction>( |
671 ::GetProcAddress(wlan_api_library_, kWlanGetProfile)); | 710 ::GetProcAddress(wlan_api_library_, kWlanGetProfile)); |
672 WlanOpenHandle_function_ = | 711 WlanOpenHandle_function_ = |
673 reinterpret_cast<WlanOpenHandleFunction>( | 712 reinterpret_cast<WlanOpenHandleFunction>( |
674 ::GetProcAddress(wlan_api_library_, kWlanOpenHandle)); | 713 ::GetProcAddress(wlan_api_library_, kWlanOpenHandle)); |
714 WlanQueryInterface_function_ = | |
715 reinterpret_cast<WlanQueryInterfaceFunction>( | |
716 ::GetProcAddress(wlan_api_library_, kWlanQueryInterface)); | |
675 WlanRegisterNotification_function_ = | 717 WlanRegisterNotification_function_ = |
676 reinterpret_cast<WlanRegisterNotificationFunction>( | 718 reinterpret_cast<WlanRegisterNotificationFunction>( |
677 ::GetProcAddress(wlan_api_library_, kWlanRegisterNotification)); | 719 ::GetProcAddress(wlan_api_library_, kWlanRegisterNotification)); |
678 WlanSaveTemporaryProfile_function_ = | 720 WlanSaveTemporaryProfile_function_ = |
679 reinterpret_cast<WlanSaveTemporaryProfileFunction>( | 721 reinterpret_cast<WlanSaveTemporaryProfileFunction>( |
680 ::GetProcAddress(wlan_api_library_, kWlanSaveTemporaryProfile)); | 722 ::GetProcAddress(wlan_api_library_, kWlanSaveTemporaryProfile)); |
681 WlanScan_function_ = | 723 WlanScan_function_ = |
682 reinterpret_cast<WlanScanFunction>( | 724 reinterpret_cast<WlanScanFunction>( |
683 ::GetProcAddress(wlan_api_library_, kWlanScan)); | 725 ::GetProcAddress(wlan_api_library_, kWlanScan)); |
684 | 726 |
685 if (!WlanConnect_function_ || | 727 if (!WlanConnect_function_ || |
686 !WlanCloseHandle_function_ || | 728 !WlanCloseHandle_function_ || |
687 !WlanDisconnect_function_ || | 729 !WlanDisconnect_function_ || |
688 !WlanEnumInterfaces_function_ || | 730 !WlanEnumInterfaces_function_ || |
689 !WlanFreeMemory_function_ || | 731 !WlanFreeMemory_function_ || |
690 !WlanGetAvailableNetworkList_function_ || | 732 !WlanGetAvailableNetworkList_function_ || |
691 !WlanGetProfile_function_ || | 733 !WlanGetProfile_function_ || |
692 !WlanOpenHandle_function_ || | 734 !WlanOpenHandle_function_ || |
735 !WlanQueryInterface_function_ || | |
693 !WlanRegisterNotification_function_ || | 736 !WlanRegisterNotification_function_ || |
694 !WlanScan_function_) { | 737 !WlanScan_function_) { |
695 DLOG(ERROR) << "Unable to find required WlanApi function."; | 738 DLOG(ERROR) << "Unable to find required WlanApi function."; |
696 FreeLibrary(wlan_api_library_); | 739 FreeLibrary(wlan_api_library_); |
697 wlan_api_library_ = NULL; | 740 wlan_api_library_ = NULL; |
698 return ERROR_NOT_FOUND; | 741 return ERROR_NOT_FOUND; |
699 } | 742 } |
700 | 743 |
701 // Some WlanApi functions may not be available on XP. | 744 // Some WlanApi functions may not be available on XP. |
702 if (!WlanGetNetworkBssList_function_ || | 745 if (!WlanGetNetworkBssList_function_ || |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
738 WLAN_NOTIFICATION_SOURCE_ALL, | 781 WLAN_NOTIFICATION_SOURCE_ALL, |
739 FALSE, | 782 FALSE, |
740 OnWlanNotificationCallback, | 783 OnWlanNotificationCallback, |
741 this, | 784 this, |
742 NULL, | 785 NULL, |
743 NULL); | 786 NULL); |
744 } else { | 787 } else { |
745 error = ERROR_NOINTERFACE; | 788 error = ERROR_NOINTERFACE; |
746 } | 789 } |
747 } | 790 } |
748 // Clean up. | 791 // Clean up.. |
749 if (interface_list != NULL) | 792 if (interface_list != NULL) |
750 WlanFreeMemory_function_(interface_list); | 793 WlanFreeMemory_function_(interface_list); |
751 } | 794 } |
752 return error; | 795 return error; |
753 } | 796 } |
754 | 797 |
755 DWORD WiFiServiceImpl::ResetDHCP() { | 798 DWORD WiFiServiceImpl::ResetDHCP() { |
756 IP_ADAPTER_INDEX_MAP adapter_index_map = {0}; | 799 IP_ADAPTER_INDEX_MAP adapter_index_map = {0}; |
757 DWORD error = FindAdapterIndexMapByGUID(interface_guid_, &adapter_index_map); | 800 DWORD error = FindAdapterIndexMapByGUID(interface_guid_, &adapter_index_map); |
758 if (error == ERROR_SUCCESS) { | 801 if (error == ERROR_SUCCESS) { |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
921 properties->name = properties->ssid; | 964 properties->name = properties->ssid; |
922 properties->guid = GUIDFromWLAN(wlan); | 965 properties->guid = GUIDFromWLAN(wlan); |
923 properties->type = onc::network_type::kWiFi; | 966 properties->type = onc::network_type::kWiFi; |
924 | 967 |
925 for (size_t bss = 0; bss < wlan_bss_list.dwNumberOfItems; ++bss) { | 968 for (size_t bss = 0; bss < wlan_bss_list.dwNumberOfItems; ++bss) { |
926 const WLAN_BSS_ENTRY& bss_entry(wlan_bss_list.wlanBssEntries[bss]); | 969 const WLAN_BSS_ENTRY& bss_entry(wlan_bss_list.wlanBssEntries[bss]); |
927 if (bss_entry.dot11Ssid.uSSIDLength == wlan.dot11Ssid.uSSIDLength && | 970 if (bss_entry.dot11Ssid.uSSIDLength == wlan.dot11Ssid.uSSIDLength && |
928 0 == memcmp(bss_entry.dot11Ssid.ucSSID, | 971 0 == memcmp(bss_entry.dot11Ssid.ucSSID, |
929 wlan.dot11Ssid.ucSSID, | 972 wlan.dot11Ssid.ucSSID, |
930 bss_entry.dot11Ssid.uSSIDLength)) { | 973 bss_entry.dot11Ssid.uSSIDLength)) { |
931 if (bss_entry.ulChCenterFrequency < 3000000) | 974 properties->frequency = GetNormalizedFrequency( |
932 properties->frequency = kFrequency2400; | 975 bss_entry.ulChCenterFrequency / 1000); |
933 else | |
934 properties->frequency = kFrequency5000; | |
935 properties->frequency_list.push_back(properties->frequency); | 976 properties->frequency_list.push_back(properties->frequency); |
936 properties->bssid = NetworkProperties::MacAddressAsString( | 977 properties->bssid = NetworkProperties::MacAddressAsString( |
937 bss_entry.dot11Bssid); | 978 bss_entry.dot11Bssid); |
938 } | 979 } |
939 } | 980 } |
940 properties->frequency_list.sort(); | 981 properties->frequency_list.sort(); |
941 properties->frequency_list.unique(); | 982 properties->frequency_list.unique(); |
942 properties->security = | 983 properties->security = |
943 SecurityFromDot11AuthAlg(wlan.dot11DefaultAuthAlgorithm); | 984 SecurityFromDot11AuthAlg(wlan.dot11DefaultAuthAlgorithm); |
944 properties->signal_strength = wlan.wlanSignalQuality; | 985 properties->signal_strength = wlan.wlanSignalQuality; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
997 network_properties.connection_state; | 1038 network_properties.connection_state; |
998 } | 1039 } |
999 } else { | 1040 } else { |
1000 network_list->push_back(network_properties); | 1041 network_list->push_back(network_properties); |
1001 } | 1042 } |
1002 network_guids.insert(network_properties.guid); | 1043 network_guids.insert(network_properties.guid); |
1003 } | 1044 } |
1004 } | 1045 } |
1005 } | 1046 } |
1006 | 1047 |
1007 // clean up | 1048 // Clean up. |
1008 if (available_network_list != NULL) { | 1049 if (available_network_list != NULL) { |
1009 WlanFreeMemory_function_(available_network_list); | 1050 WlanFreeMemory_function_(available_network_list); |
1010 } | 1051 } |
1011 if (bss_list != NULL) { | 1052 if (bss_list != NULL) { |
1012 WlanFreeMemory_function_(bss_list); | 1053 WlanFreeMemory_function_(bss_list); |
1013 } | 1054 } |
1014 return error; | 1055 return error; |
1015 } | 1056 } |
1016 | 1057 |
1017 // Find currently connected network. | 1058 // Find currently connected network. |
(...skipping 12 matching lines...) Expand all Loading... | |
1030 if (error == ERROR_SUCCESS && NULL != available_network_list) { | 1071 if (error == ERROR_SUCCESS && NULL != available_network_list) { |
1031 for (DWORD i = 0; i < available_network_list->dwNumberOfItems; ++i) { | 1072 for (DWORD i = 0; i < available_network_list->dwNumberOfItems; ++i) { |
1032 const WLAN_AVAILABLE_NETWORK& wlan = available_network_list->Network[i]; | 1073 const WLAN_AVAILABLE_NETWORK& wlan = available_network_list->Network[i]; |
1033 if (wlan.dwFlags & WLAN_AVAILABLE_NETWORK_CONNECTED) { | 1074 if (wlan.dwFlags & WLAN_AVAILABLE_NETWORK_CONNECTED) { |
1034 *connected_network_guid = GUIDFromWLAN(wlan); | 1075 *connected_network_guid = GUIDFromWLAN(wlan); |
1035 break; | 1076 break; |
1036 } | 1077 } |
1037 } | 1078 } |
1038 } | 1079 } |
1039 | 1080 |
1040 // clean up | 1081 // Clean up. |
1041 if (available_network_list != NULL) { | 1082 if (available_network_list != NULL) { |
1042 WlanFreeMemory_function_(available_network_list); | 1083 WlanFreeMemory_function_(available_network_list); |
1043 } | 1084 } |
1044 | 1085 |
1045 return error; | 1086 return error; |
1046 } | 1087 } |
1047 | 1088 |
1089 WiFiService::Frequency WiFiServiceImpl::GetConnectedFrequency( | |
1090 const std::string& network_guid) { | |
1091 if (client_ == NULL) { | |
1092 NOTREACHED(); | |
1093 return kFrequencyUnknown; | |
1094 } | |
1095 | |
1096 // TODO(mef): WlanGetNetworkBssList is not available on XP. If XP support is | |
1097 // needed, then different method of getting BSS (e.g. OID query) will have | |
1098 // to be used. | |
1099 if (WlanGetNetworkBssList_function_ == NULL) | |
1100 return kFrequencyUnknown; | |
1101 | |
1102 Frequency frequency = kFrequencyUnknown; | |
1103 DWORD error = ERROR_SUCCESS; | |
1104 DWORD data_size = 0; | |
1105 PWLAN_CONNECTION_ATTRIBUTES wlan_connection_attributes = NULL; | |
1106 PWLAN_BSS_LIST bss_list = NULL; | |
1107 error = WlanQueryInterface_function_( | |
1108 client_, | |
1109 &interface_guid_, | |
1110 wlan_intf_opcode_current_connection, | |
1111 NULL, | |
1112 &data_size, | |
1113 reinterpret_cast<PVOID*>(&wlan_connection_attributes), | |
1114 NULL); | |
1115 if (error == ERROR_SUCCESS && | |
1116 wlan_connection_attributes != NULL && | |
1117 wlan_connection_attributes->isState == wlan_interface_state_connected) { | |
1118 const WLAN_ASSOCIATION_ATTRIBUTES& connected_wlan = | |
1119 wlan_connection_attributes->wlanAssociationAttributes; | |
1120 // Try to find connected frequency based on bss. | |
1121 if (GUIDFromSSID(connected_wlan.dot11Ssid) == network_guid && | |
1122 WlanGetNetworkBssList_function_ != NULL) { | |
1123 error = WlanGetNetworkBssList_function_(client_, | |
1124 &interface_guid_, | |
1125 NULL, | |
afontan
2013/12/03 01:32:34
NULL means no filtering but if you pass the DOT11_
mef
2013/12/03 15:00:25
Theoretically yes, but practically on my machine i
mef
2013/12/03 17:08:11
Done. Specifying correct dot11BssType has fixed th
| |
1126 dot11_BSS_type_any, | |
1127 FALSE, | |
1128 NULL, | |
1129 &bss_list); | |
1130 if (error == ERROR_SUCCESS && NULL != bss_list) { | |
1131 // Go through bss_list and find matching BSSID. | |
1132 for (size_t bss = 0; bss < bss_list->dwNumberOfItems; ++bss) { | |
1133 const WLAN_BSS_ENTRY& bss_entry(bss_list->wlanBssEntries[bss]); | |
1134 if (0 == memcmp(bss_entry.dot11Bssid, | |
1135 connected_wlan.dot11Bssid, | |
1136 sizeof(bss_entry.dot11Bssid))) { | |
1137 frequency = GetNormalizedFrequency( | |
1138 bss_entry.ulChCenterFrequency / 1000); | |
1139 break; | |
1140 } | |
1141 } | |
1142 } | |
1143 } | |
1144 } | |
1145 | |
1146 // Clean up. | |
1147 if (wlan_connection_attributes != NULL) { | |
1148 WlanFreeMemory_function_(wlan_connection_attributes); | |
1149 } | |
1150 | |
1151 if (bss_list != NULL) { | |
1152 WlanFreeMemory_function_(bss_list); | |
1153 } | |
1154 | |
1155 return frequency; | |
1156 } | |
1157 | |
1158 WiFiService::Frequency WiFiServiceImpl::GetFrequencyToConnect( | |
1159 const std::string& network_guid) const { | |
1160 // Check whether desired frequency is set in |connect_properties_|. | |
1161 const DictionaryValue* properties; | |
1162 const DictionaryValue* wifi; | |
1163 int frequency; | |
1164 if (connect_properties_.GetDictionaryWithoutPathExpansion( | |
1165 network_guid, &properties) && | |
1166 properties->GetDictionary(onc::network_type::kWiFi, &wifi) && | |
1167 wifi->GetInteger(onc::wifi::kFrequency, &frequency)) { | |
1168 return GetNormalizedFrequency(frequency); | |
1169 } | |
1170 return kFrequencyAny; | |
1171 } | |
1172 | |
1048 DWORD WiFiServiceImpl::GetDesiredBssList( | 1173 DWORD WiFiServiceImpl::GetDesiredBssList( |
1049 DOT11_SSID& ssid, | 1174 DOT11_SSID& ssid, |
1050 Frequency frequency, | 1175 Frequency frequency, |
1051 scoped_ptr<DOT11_BSSID_LIST>* desired_list) { | 1176 scoped_ptr<DOT11_BSSID_LIST>* desired_list) { |
1052 if (client_ == NULL) { | 1177 if (client_ == NULL) { |
1053 NOTREACHED(); | 1178 NOTREACHED(); |
1054 return ERROR_NOINTERFACE; | 1179 return ERROR_NOINTERFACE; |
1055 } | 1180 } |
1056 | 1181 |
1057 desired_list->reset(); | 1182 desired_list->reset(); |
(...skipping 24 matching lines...) Expand all Loading... | |
1082 | 1207 |
1083 // Go through bss_list and find best quality BSSID with matching frequency. | 1208 // Go through bss_list and find best quality BSSID with matching frequency. |
1084 for (size_t bss = 0; bss < bss_list->dwNumberOfItems; ++bss) { | 1209 for (size_t bss = 0; bss < bss_list->dwNumberOfItems; ++bss) { |
1085 const WLAN_BSS_ENTRY& bss_entry(bss_list->wlanBssEntries[bss]); | 1210 const WLAN_BSS_ENTRY& bss_entry(bss_list->wlanBssEntries[bss]); |
1086 if (bss_entry.dot11Ssid.uSSIDLength != ssid.uSSIDLength || | 1211 if (bss_entry.dot11Ssid.uSSIDLength != ssid.uSSIDLength || |
1087 0 != memcmp(bss_entry.dot11Ssid.ucSSID, | 1212 0 != memcmp(bss_entry.dot11Ssid.ucSSID, |
1088 ssid.ucSSID, | 1213 ssid.ucSSID, |
1089 bss_entry.dot11Ssid.uSSIDLength)) | 1214 bss_entry.dot11Ssid.uSSIDLength)) |
1090 continue; | 1215 continue; |
1091 | 1216 |
1092 if (bss_entry.ulChCenterFrequency < 3000000) | 1217 bss_frequency = GetNormalizedFrequency( |
1093 bss_frequency = kFrequency2400; | 1218 bss_entry.ulChCenterFrequency / 1000); |
1094 else | |
1095 bss_frequency = kFrequency5000; | |
1096 | |
1097 if (bss_frequency == frequency && | 1219 if (bss_frequency == frequency && |
1098 bss_entry.uLinkQuality > best_quality) { | 1220 bss_entry.uLinkQuality > best_quality) { |
1099 best_quality = bss_entry.uLinkQuality; | 1221 best_quality = bss_entry.uLinkQuality; |
1100 best_index = bss; | 1222 best_index = bss; |
1101 } | 1223 } |
1102 } | 1224 } |
1103 | 1225 |
1104 // If any matching BSS were found, prepare the header. | 1226 // If any matching BSS were found, prepare the header. |
1105 if (best_quality > 0) { | 1227 if (best_quality > 0) { |
1106 const WLAN_BSS_ENTRY& bss_entry(bss_list->wlanBssEntries[best_index]); | 1228 const WLAN_BSS_ENTRY& bss_entry(bss_list->wlanBssEntries[best_index]); |
1107 scoped_ptr<DOT11_BSSID_LIST> selected_list(new DOT11_BSSID_LIST); | 1229 scoped_ptr<DOT11_BSSID_LIST> selected_list(new DOT11_BSSID_LIST); |
1108 | 1230 |
1109 selected_list->Header.Revision = DOT11_BSSID_LIST_REVISION_1; | 1231 selected_list->Header.Revision = DOT11_BSSID_LIST_REVISION_1; |
1110 selected_list->Header.Size = sizeof(DOT11_BSSID_LIST); | 1232 selected_list->Header.Size = sizeof(DOT11_BSSID_LIST); |
1111 selected_list->Header.Type = NDIS_OBJECT_TYPE_DEFAULT; | 1233 selected_list->Header.Type = NDIS_OBJECT_TYPE_DEFAULT; |
1112 selected_list->uNumOfEntries = 1; | 1234 selected_list->uNumOfEntries = 1; |
1113 selected_list->uTotalNumOfEntries = 1; | 1235 selected_list->uTotalNumOfEntries = 1; |
1114 std::copy(bss_entry.dot11Bssid, | 1236 std::copy(bss_entry.dot11Bssid, |
1115 bss_entry.dot11Bssid+sizeof(bss_entry.dot11Bssid), | 1237 bss_entry.dot11Bssid+sizeof(bss_entry.dot11Bssid), |
1116 selected_list->BSSIDs[0]); | 1238 selected_list->BSSIDs[0]); |
1117 desired_list->swap(selected_list); | 1239 desired_list->swap(selected_list); |
1118 DVLOG(1) << "Quality: " << best_quality << " BSS: " | 1240 DVLOG(1) << "Quality: " << best_quality << " BSS: " |
1119 << NetworkProperties::MacAddressAsString(bss_entry.dot11Bssid); | 1241 << NetworkProperties::MacAddressAsString(bss_entry.dot11Bssid); |
1120 } else { | 1242 } else { |
1121 error = ERROR_NOT_FOUND; | 1243 error = ERROR_NOT_FOUND; |
1122 } | 1244 } |
1123 } | 1245 } |
1124 | 1246 |
1125 // clean up | 1247 // Clean up. |
1126 if (bss_list != NULL) { | 1248 if (bss_list != NULL) { |
1127 WlanFreeMemory_function_(bss_list); | 1249 WlanFreeMemory_function_(bss_list); |
1128 } | 1250 } |
1129 return error; | 1251 return error; |
1130 } | 1252 } |
1131 | 1253 |
1254 WiFiService::Frequency WiFiServiceImpl::GetNormalizedFrequency( | |
1255 int frequency_in_mhz) const { | |
1256 if (frequency_in_mhz == 0) | |
1257 return kFrequencyAny; | |
1258 if (frequency_in_mhz < 3000) | |
1259 return kFrequency2400; | |
1260 return kFrequency5000; | |
1261 } | |
1132 | 1262 |
1133 DWORD WiFiServiceImpl::Connect(const std::string& network_guid, | 1263 DWORD WiFiServiceImpl::Connect(const std::string& network_guid, |
1134 Frequency frequency) { | 1264 Frequency frequency) { |
1135 if (client_ == NULL) { | 1265 if (client_ == NULL) { |
1136 NOTREACHED(); | 1266 NOTREACHED(); |
1137 return ERROR_NOINTERFACE; | 1267 return ERROR_NOINTERFACE; |
1138 } | 1268 } |
1139 | 1269 |
1140 DWORD error = ERROR_SUCCESS; | 1270 DWORD error = ERROR_SUCCESS; |
1141 DOT11_SSID ssid = SSIDFromGUID(network_guid); | 1271 DOT11_SSID ssid = SSIDFromGUID(network_guid); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1222 &interface_guid_, | 1352 &interface_guid_, |
1223 profile_name.c_str(), | 1353 profile_name.c_str(), |
1224 NULL, | 1354 NULL, |
1225 &str_profile_xml, | 1355 &str_profile_xml, |
1226 NULL, | 1356 NULL, |
1227 NULL); | 1357 NULL); |
1228 | 1358 |
1229 if (error == ERROR_SUCCESS && str_profile_xml != NULL) { | 1359 if (error == ERROR_SUCCESS && str_profile_xml != NULL) { |
1230 *profile_xml = base::UTF16ToUTF8(str_profile_xml); | 1360 *profile_xml = base::UTF16ToUTF8(str_profile_xml); |
1231 } | 1361 } |
1232 // clean up | 1362 // Clean up. |
1233 if (str_profile_xml != NULL) { | 1363 if (str_profile_xml != NULL) { |
1234 WlanFreeMemory_function_(str_profile_xml); | 1364 WlanFreeMemory_function_(str_profile_xml); |
1235 } | 1365 } |
1236 | 1366 |
1237 return error; | 1367 return error; |
1238 } | 1368 } |
1239 | 1369 |
1240 bool WiFiServiceImpl::HaveProfile(const std::string& network_guid) { | 1370 bool WiFiServiceImpl::HaveProfile(const std::string& network_guid) { |
1241 DWORD error = ERROR_SUCCESS; | 1371 DWORD error = ERROR_SUCCESS; |
1242 std::string profile_xml; | 1372 std::string profile_xml; |
(...skipping 22 matching lines...) Expand all Loading... | |
1265 NetworkGuidList changed_networks(1, network_guid); | 1395 NetworkGuidList changed_networks(1, network_guid); |
1266 message_loop_proxy_->PostTask( | 1396 message_loop_proxy_->PostTask( |
1267 FROM_HERE, | 1397 FROM_HERE, |
1268 base::Bind(networks_changed_observer_, changed_networks)); | 1398 base::Bind(networks_changed_observer_, changed_networks)); |
1269 } | 1399 } |
1270 } | 1400 } |
1271 | 1401 |
1272 WiFiService* WiFiService::Create() { return new WiFiServiceImpl(); } | 1402 WiFiService* WiFiService::Create() { return new WiFiServiceImpl(); } |
1273 | 1403 |
1274 } // namespace wifi | 1404 } // namespace wifi |
OLD | NEW |