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 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 std::string* key_data, | 219 std::string* key_data, |
220 std::string* error) override; | 220 std::string* error) override; |
221 | 221 |
222 virtual void SetEventObservers( | 222 virtual void SetEventObservers( |
223 scoped_refptr<base::MessageLoopProxy> message_loop_proxy, | 223 scoped_refptr<base::MessageLoopProxy> message_loop_proxy, |
224 const NetworkGuidListCallback& networks_changed_observer, | 224 const NetworkGuidListCallback& networks_changed_observer, |
225 const NetworkGuidListCallback& network_list_changed_observer) override; | 225 const NetworkGuidListCallback& network_list_changed_observer) override; |
226 | 226 |
227 virtual void RequestConnectedNetworkUpdate() override {} | 227 virtual void RequestConnectedNetworkUpdate() override {} |
228 | 228 |
| 229 virtual void GetConnectedNetworkSSID(std::string* ssid, |
| 230 std::string* error) override; |
| 231 |
229 private: | 232 private: |
230 typedef int32 EncryptionType; | 233 typedef int32 EncryptionType; |
231 enum EncryptionTypeEnum { | 234 enum EncryptionTypeEnum { |
232 kEncryptionTypeAny = 0, | 235 kEncryptionTypeAny = 0, |
233 kEncryptionTypeAES = 1, | 236 kEncryptionTypeAES = 1, |
234 kEncryptionTypeTKIP = 2 | 237 kEncryptionTypeTKIP = 2 |
235 }; | 238 }; |
236 | 239 |
237 // Static callback for Windows WLAN_NOTIFICATION. Calls OnWlanNotification | 240 // Static callback for Windows WLAN_NOTIFICATION. Calls OnWlanNotification |
238 // on WiFiServiceImpl passed back as |context|. | 241 // on WiFiServiceImpl passed back as |context|. |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 const WLAN_BSS_LIST& wlan_bss_list, | 353 const WLAN_BSS_LIST& wlan_bss_list, |
351 NetworkProperties* properties); | 354 NetworkProperties* properties); |
352 | 355 |
353 // Get the list of visible wireless networks. | 356 // Get the list of visible wireless networks. |
354 DWORD GetVisibleNetworkList(NetworkList* network_list); | 357 DWORD GetVisibleNetworkList(NetworkList* network_list); |
355 | 358 |
356 // Get properties of the network currently used (connected or in transition) | 359 // Get properties of the network currently used (connected or in transition) |
357 // by interface. Populate |current_properties| on success. | 360 // by interface. Populate |current_properties| on success. |
358 DWORD GetCurrentProperties(NetworkProperties* current_properties); | 361 DWORD GetCurrentProperties(NetworkProperties* current_properties); |
359 | 362 |
| 363 // Get the SSID of the network currently used (connected or in transition) |
| 364 // by interface. Populate |ssid| on success. This is a stripped down version |
| 365 // of GetCurrentProperties that doesn't use the BSS list; |
| 366 DWORD GetCurrentSSID(std::string* ssid); |
| 367 |
360 // Connect to network |network_guid| using previosly stored profile if exists, | 368 // Connect to network |network_guid| using previosly stored profile if exists, |
361 // or just network sid. If |frequency| is not |kFrequencyUnknown| then | 369 // or just network sid. If |frequency| is not |kFrequencyUnknown| then |
362 // connects only to BSS which uses that frequency and returns | 370 // connects only to BSS which uses that frequency and returns |
363 // |ERROR_NOT_FOUND| if such BSS cannot be found. | 371 // |ERROR_NOT_FOUND| if such BSS cannot be found. |
364 DWORD Connect(const std::string& network_guid, Frequency frequency); | 372 DWORD Connect(const std::string& network_guid, Frequency frequency); |
365 | 373 |
366 // Disconnect from currently connected network if any. | 374 // Disconnect from currently connected network if any. |
367 DWORD Disconnect(); | 375 DWORD Disconnect(); |
368 | 376 |
369 // Get desired connection freqency if it was set using |SetProperties|. | 377 // Get desired connection freqency if it was set using |SetProperties|. |
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
799 WlanRegisterNotification_function_(client_, | 807 WlanRegisterNotification_function_(client_, |
800 WLAN_NOTIFICATION_SOURCE_ALL, | 808 WLAN_NOTIFICATION_SOURCE_ALL, |
801 FALSE, | 809 FALSE, |
802 OnWlanNotificationCallback, | 810 OnWlanNotificationCallback, |
803 this, | 811 this, |
804 NULL, | 812 NULL, |
805 NULL); | 813 NULL); |
806 } | 814 } |
807 } | 815 } |
808 | 816 |
| 817 void WiFiServiceImpl::GetConnectedNetworkSSID(std::string* ssid, |
| 818 std::string* error) { |
| 819 DWORD error_code = EnsureInitialized(); |
| 820 if (CheckError(error_code, kErrorWiFiService, error)) |
| 821 return; |
| 822 std::string current_ssid; |
| 823 error_code = GetCurrentSSID(¤t_ssid); |
| 824 if (CheckError(error_code, kErrorWiFiService, error)) |
| 825 return; |
| 826 *ssid = current_ssid; |
| 827 } |
| 828 |
809 void WiFiServiceImpl::OnWlanNotificationCallback( | 829 void WiFiServiceImpl::OnWlanNotificationCallback( |
810 PWLAN_NOTIFICATION_DATA wlan_notification_data, | 830 PWLAN_NOTIFICATION_DATA wlan_notification_data, |
811 PVOID context) { | 831 PVOID context) { |
812 WiFiServiceImpl* service = reinterpret_cast<WiFiServiceImpl*>(context); | 832 WiFiServiceImpl* service = reinterpret_cast<WiFiServiceImpl*>(context); |
813 service->OnWlanNotification(wlan_notification_data); | 833 service->OnWlanNotification(wlan_notification_data); |
814 } | 834 } |
815 | 835 |
816 void WiFiServiceImpl::OnWlanNotification( | 836 void WiFiServiceImpl::OnWlanNotification( |
817 PWLAN_NOTIFICATION_DATA wlan_notification_data) { | 837 PWLAN_NOTIFICATION_DATA wlan_notification_data) { |
818 if (message_loop_proxy_.get() == NULL) | 838 if (message_loop_proxy_.get() == NULL) |
(...skipping 636 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1455 // Clean up. | 1475 // Clean up. |
1456 if (wlan_connection_attributes != NULL) | 1476 if (wlan_connection_attributes != NULL) |
1457 WlanFreeMemory_function_(wlan_connection_attributes); | 1477 WlanFreeMemory_function_(wlan_connection_attributes); |
1458 | 1478 |
1459 if (bss_list != NULL) | 1479 if (bss_list != NULL) |
1460 WlanFreeMemory_function_(bss_list); | 1480 WlanFreeMemory_function_(bss_list); |
1461 | 1481 |
1462 return error; | 1482 return error; |
1463 } | 1483 } |
1464 | 1484 |
| 1485 |
| 1486 DWORD WiFiServiceImpl::GetCurrentSSID(std::string* ssid) { |
| 1487 if (client_ == NULL) { |
| 1488 NOTREACHED(); |
| 1489 return ERROR_NOINTERFACE; |
| 1490 } |
| 1491 DWORD error = ERROR_SUCCESS; |
| 1492 DWORD data_size = 0; |
| 1493 PWLAN_CONNECTION_ATTRIBUTES wlan_connection_attributes = NULL; |
| 1494 error = WlanQueryInterface_function_( |
| 1495 client_, |
| 1496 &interface_guid_, |
| 1497 wlan_intf_opcode_current_connection, |
| 1498 NULL, |
| 1499 &data_size, |
| 1500 reinterpret_cast<PVOID*>(&wlan_connection_attributes), |
| 1501 NULL); |
| 1502 if (error == ERROR_SUCCESS && |
| 1503 wlan_connection_attributes != NULL) { |
| 1504 WLAN_ASSOCIATION_ATTRIBUTES& connected_wlan = |
| 1505 wlan_connection_attributes->wlanAssociationAttributes; |
| 1506 *ssid = GUIDFromSSID(connected_wlan.dot11Ssid); |
| 1507 } |
| 1508 |
| 1509 // Clean up. |
| 1510 if (wlan_connection_attributes != NULL) |
| 1511 WlanFreeMemory_function_(wlan_connection_attributes); |
| 1512 |
| 1513 return error; |
| 1514 } |
| 1515 |
1465 Frequency WiFiServiceImpl::GetFrequencyToConnect( | 1516 Frequency WiFiServiceImpl::GetFrequencyToConnect( |
1466 const std::string& network_guid) const { | 1517 const std::string& network_guid) const { |
1467 // Check whether desired frequency is set in |connect_properties_|. | 1518 // Check whether desired frequency is set in |connect_properties_|. |
1468 const base::DictionaryValue* properties; | 1519 const base::DictionaryValue* properties; |
1469 if (connect_properties_.GetDictionaryWithoutPathExpansion(network_guid, | 1520 if (connect_properties_.GetDictionaryWithoutPathExpansion(network_guid, |
1470 &properties)) { | 1521 &properties)) { |
1471 const base::DictionaryValue* wifi; | 1522 const base::DictionaryValue* wifi; |
1472 if (properties->GetDictionary(onc::network_type::kWiFi, &wifi)) { | 1523 if (properties->GetDictionary(onc::network_type::kWiFi, &wifi)) { |
1473 int frequency; | 1524 int frequency; |
1474 if (wifi->GetInteger(onc::wifi::kFrequency, &frequency)) | 1525 if (wifi->GetInteger(onc::wifi::kFrequency, &frequency)) |
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1840 NetworkGuidList changed_networks(1, network_guid); | 1891 NetworkGuidList changed_networks(1, network_guid); |
1841 message_loop_proxy_->PostTask( | 1892 message_loop_proxy_->PostTask( |
1842 FROM_HERE, | 1893 FROM_HERE, |
1843 base::Bind(networks_changed_observer_, changed_networks)); | 1894 base::Bind(networks_changed_observer_, changed_networks)); |
1844 } | 1895 } |
1845 } | 1896 } |
1846 | 1897 |
1847 WiFiService* WiFiService::Create() { return new WiFiServiceImpl(); } | 1898 WiFiService* WiFiService::Create() { return new WiFiServiceImpl(); } |
1848 | 1899 |
1849 } // namespace wifi | 1900 } // namespace wifi |
OLD | NEW |