Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(562)

Side by Side Diff: components/wifi/wifi_service_win.cc

Issue 86123003: Use WiFi.Frequency property to set desired band for networkingPrivateApi.StartConnect() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Separated move of GetVisibleNetworks filtering into https://codereview.chromium.org/88653002 Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | components/wifi/wifi_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 284
285 // Connect to network |network_guid| using previosly stored profile if exists, 285 // Connect to network |network_guid| using previosly stored profile if exists,
286 // or just network sid. If |frequency| is not |kFrequencyUnknown| then 286 // or just network sid. If |frequency| is not |kFrequencyUnknown| then
287 // connects only to BSS which uses that frequency and returns 287 // connects only to BSS which uses that frequency and returns
288 // |ERROR_NOT_FOUND| if such BSS cannot be found. 288 // |ERROR_NOT_FOUND| if such BSS cannot be found.
289 DWORD Connect(const std::string& network_guid, Frequency frequency); 289 DWORD Connect(const std::string& network_guid, Frequency frequency);
290 290
291 // Disconnect from currently connected network if any. 291 // Disconnect from currently connected network if any.
292 DWORD Disconnect(); 292 DWORD Disconnect();
293 293
294 // Get desired connection freqency if it was set using |SetProperties|.
295 // Default to |kFrequencyAny|.
296 Frequency GetDesiredFrequency(const std::string& network_guid);
297
294 // Get DOT11_BSSID_LIST of desired BSSIDs to connect to |ssid| network on 298 // Get DOT11_BSSID_LIST of desired BSSIDs to connect to |ssid| network on
295 // given |frequency|. 299 // given |frequency|.
296 DWORD GetDesiredBssList(DOT11_SSID& ssid, 300 DWORD GetDesiredBssList(DOT11_SSID& ssid,
297 Frequency frequency, 301 Frequency frequency,
298 scoped_ptr<DOT11_BSSID_LIST>* desired_list); 302 scoped_ptr<DOT11_BSSID_LIST>* desired_list);
299 303
300 // Save temporary wireless profile for |network_guid|. 304 // Save temporary wireless profile for |network_guid|.
301 DWORD SaveTempProfile(const std::string& network_guid); 305 DWORD SaveTempProfile(const std::string& network_guid);
302 306
303 // Get previously stored |profile_xml| for |network_guid|. 307 // Get previously stored |profile_xml| for |network_guid|.
(...skipping 28 matching lines...) Expand all
332 WlanRegisterNotificationFunction WlanRegisterNotification_function_; 336 WlanRegisterNotificationFunction WlanRegisterNotification_function_;
333 WlanScanFunction WlanScan_function_; 337 WlanScanFunction WlanScan_function_;
334 // WlanSaveTemporaryProfile function may not be avaiable on Windows XP. 338 // WlanSaveTemporaryProfile function may not be avaiable on Windows XP.
335 WlanSaveTemporaryProfileFunction WlanSaveTemporaryProfile_function_; 339 WlanSaveTemporaryProfileFunction WlanSaveTemporaryProfile_function_;
336 340
337 // WLAN service handle. 341 // WLAN service handle.
338 HANDLE client_; 342 HANDLE client_;
339 // GUID of the currently connected interface, if any, otherwise the GUID of 343 // GUID of the currently connected interface, if any, otherwise the GUID of
340 // one of the WLAN interfaces. 344 // one of the WLAN interfaces.
341 GUID interface_guid_; 345 GUID interface_guid_;
346 // Temporary storage of network properties indexed by |network_guid|.
347 DictionaryValue temporary_network_properties_;
stevenjb 2013/11/26 18:00:34 How about 'connect_properties_' to better describe
mef 2013/11/26 19:00:13 Done.
342 // Preserved WLAN profile xml. 348 // Preserved WLAN profile xml.
343 std::map<std::string, std::string> saved_profiles_xml_; 349 std::map<std::string, std::string> saved_profiles_xml_;
344 // Observer to get notified when network(s) have changed (e.g. connect). 350 // Observer to get notified when network(s) have changed (e.g. connect).
345 NetworkGuidListCallback networks_changed_observer_; 351 NetworkGuidListCallback networks_changed_observer_;
346 // Observer to get notified when network list has changed (scan complete). 352 // Observer to get notified when network list has changed (scan complete).
347 NetworkGuidListCallback network_list_changed_observer_; 353 NetworkGuidListCallback network_list_changed_observer_;
348 // Saved value of network location wizard show value. 354 // Saved value of network location wizard show value.
349 scoped_ptr<DWORD> saved_nw_category_wizard_; 355 scoped_ptr<DWORD> saved_nw_category_wizard_;
350 // MessageLoopProxy to post events on UI thread. 356 // MessageLoopProxy to post events on UI thread.
351 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; 357 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 } 418 }
413 } 419 }
414 420
415 CheckError(error_code, kWiFiServiceError, error); 421 CheckError(error_code, kWiFiServiceError, error);
416 } 422 }
417 423
418 void WiFiServiceImpl::SetProperties( 424 void WiFiServiceImpl::SetProperties(
419 const std::string& network_guid, 425 const std::string& network_guid,
420 scoped_ptr<base::DictionaryValue> properties, 426 scoped_ptr<base::DictionaryValue> properties,
421 std::string* error) { 427 std::string* error) {
422 // This method is not implemented in first version as it is not used by 428 // Temporary preserve WiFi properties (desired frequency, wifi password to use
423 // Google Cast extension. 429 // in StartConnect.
424 CheckError(ERROR_CALL_NOT_IMPLEMENTED, kWiFiServiceError, error); 430 DCHECK(properties->HasKey(onc::network_type::kWiFi));
stevenjb 2013/11/26 18:00:34 This should set |error| instead of CHECK
mef 2013/11/26 19:00:13 Done.
431 temporary_network_properties_.SetWithoutPathExpansion(network_guid,
432 properties.release());
425 } 433 }
426 434
427 void WiFiServiceImpl::GetVisibleNetworks(ListValue* network_list) { 435 void WiFiServiceImpl::GetVisibleNetworks(ListValue* network_list) {
428 DWORD error = EnsureInitialized(); 436 DWORD error = EnsureInitialized();
429 437
430 if (error == ERROR_SUCCESS) { 438 if (error == ERROR_SUCCESS) {
431 NetworkList networks; 439 NetworkList networks;
432 error = GetVisibleNetworkList(&networks); 440 error = GetVisibleNetworkList(&networks);
433 if (error == ERROR_SUCCESS && !networks.empty()) { 441 if (error == ERROR_SUCCESS && !networks.empty()) {
434 SortNetworks(&networks); 442 SortNetworks(&networks);
(...skipping 15 matching lines...) Expand all
450 } 458 }
451 459
452 void WiFiServiceImpl::StartConnect(const std::string& network_guid, 460 void WiFiServiceImpl::StartConnect(const std::string& network_guid,
453 std::string* error) { 461 std::string* error) {
454 DVLOG(1) << "Start Connect: " << network_guid; 462 DVLOG(1) << "Start Connect: " << network_guid;
455 DWORD error_code = EnsureInitialized(); 463 DWORD error_code = EnsureInitialized();
456 if (error_code == ERROR_SUCCESS) { 464 if (error_code == ERROR_SUCCESS) {
457 std::string connected_network_guid; 465 std::string connected_network_guid;
458 error_code = SaveCurrentConnectedNetwork(&connected_network_guid); 466 error_code = SaveCurrentConnectedNetwork(&connected_network_guid);
459 if (error_code == ERROR_SUCCESS) { 467 if (error_code == ERROR_SUCCESS) {
460 Frequency frequency = kFrequencyAny; 468 Frequency frequency = GetDesiredFrequency(network_guid);
461 // Connect only if network |network_guid| is not connected already. 469 // Connect only if network |network_guid| is not connected already.
tbarzic 2013/11/26 19:02:21 is |network_guid| unique for (ssid, frequency) pai
mef 2013/11/27 18:00:03 Good point, done. Currently connected band is not
462 if (network_guid != connected_network_guid) 470 if (network_guid != connected_network_guid)
463 error_code = Connect(network_guid, frequency); 471 error_code = Connect(network_guid, frequency);
464 if (error_code == ERROR_SUCCESS) { 472 if (error_code == ERROR_SUCCESS) {
465 // Notify that previously connected network has changed. 473 // Notify that previously connected network has changed.
466 NotifyNetworkChanged(connected_network_guid); 474 NotifyNetworkChanged(connected_network_guid);
467 // Start waiting for network connection state change. 475 // Start waiting for network connection state change.
468 if (!networks_changed_observer_.is_null()) { 476 if (!networks_changed_observer_.is_null()) {
469 DisableNwCategoryWizard(); 477 DisableNwCategoryWizard();
470 // Disable automatic network change notifications as they get fired 478 // Disable automatic network change notifications as they get fired
471 // when network is just connected, but not yet accessible (doesn't 479 // when network is just connected, but not yet accessible (doesn't
(...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after
1038 } 1046 }
1039 1047
1040 // clean up 1048 // clean up
1041 if (available_network_list != NULL) { 1049 if (available_network_list != NULL) {
1042 WlanFreeMemory_function_(available_network_list); 1050 WlanFreeMemory_function_(available_network_list);
1043 } 1051 }
1044 1052
1045 return error; 1053 return error;
1046 } 1054 }
1047 1055
1056 WiFiService::Frequency WiFiServiceImpl::GetDesiredFrequency(
stevenjb 2013/11/26 18:00:34 GetConnectFrequency or GetFrequencyForConnect?
mef 2013/11/26 19:00:13 Done.
1057 const std::string& network_guid) {
1058 // Check whether desired frequency is set in |temporary_network_properties_|.
1059 DictionaryValue* properties;
1060 DictionaryValue* wifi;
1061 int frequency;
1062 if (temporary_network_properties_.GetDictionaryWithoutPathExpansion(
1063 network_guid,
1064 &properties) &&
stevenjb 2013/11/26 18:00:34 nit: OK (and a little clearer imho) to combine the
mef 2013/11/26 19:00:13 Done.
1065 properties->GetDictionary(onc::network_type::kWiFi, &wifi) &&
1066 wifi->GetInteger(onc::wifi::kFrequency, &frequency)) {
tbarzic 2013/11/26 19:02:21 should frequency be normalized (here or in SetProp
mef 2013/11/27 18:00:03 Done.
1067 return static_cast<Frequency>(frequency);
1068 }
1069 return kFrequencyAny;
1070 }
1071
1048 DWORD WiFiServiceImpl::GetDesiredBssList( 1072 DWORD WiFiServiceImpl::GetDesiredBssList(
1049 DOT11_SSID& ssid, 1073 DOT11_SSID& ssid,
1050 Frequency frequency, 1074 Frequency frequency,
1051 scoped_ptr<DOT11_BSSID_LIST>* desired_list) { 1075 scoped_ptr<DOT11_BSSID_LIST>* desired_list) {
1052 if (client_ == NULL) { 1076 if (client_ == NULL) {
1053 NOTREACHED(); 1077 NOTREACHED();
1054 return ERROR_NOINTERFACE; 1078 return ERROR_NOINTERFACE;
1055 } 1079 }
1056 1080
1057 desired_list->reset(); 1081 desired_list->reset();
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1122 } 1146 }
1123 } 1147 }
1124 1148
1125 // clean up 1149 // clean up
1126 if (bss_list != NULL) { 1150 if (bss_list != NULL) {
1127 WlanFreeMemory_function_(bss_list); 1151 WlanFreeMemory_function_(bss_list);
1128 } 1152 }
1129 return error; 1153 return error;
1130 } 1154 }
1131 1155
1132
1133 DWORD WiFiServiceImpl::Connect(const std::string& network_guid, 1156 DWORD WiFiServiceImpl::Connect(const std::string& network_guid,
1134 Frequency frequency) { 1157 Frequency frequency) {
1135 if (client_ == NULL) { 1158 if (client_ == NULL) {
1136 NOTREACHED(); 1159 NOTREACHED();
1137 return ERROR_NOINTERFACE; 1160 return ERROR_NOINTERFACE;
1138 } 1161 }
1139 1162
1140 DWORD error = ERROR_SUCCESS; 1163 DWORD error = ERROR_SUCCESS;
1141 DOT11_SSID ssid = SSIDFromGUID(network_guid); 1164 DOT11_SSID ssid = SSIDFromGUID(network_guid);
1142 scoped_ptr<DOT11_BSSID_LIST> desired_bss_list; 1165 scoped_ptr<DOT11_BSSID_LIST> desired_bss_list;
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
1265 NetworkGuidList changed_networks(1, network_guid); 1288 NetworkGuidList changed_networks(1, network_guid);
1266 message_loop_proxy_->PostTask( 1289 message_loop_proxy_->PostTask(
1267 FROM_HERE, 1290 FROM_HERE,
1268 base::Bind(networks_changed_observer_, changed_networks)); 1291 base::Bind(networks_changed_observer_, changed_networks));
1269 } 1292 }
1270 } 1293 }
1271 1294
1272 WiFiService* WiFiService::Create() { return new WiFiServiceImpl(); } 1295 WiFiService* WiFiService::Create() { return new WiFiServiceImpl(); }
1273 1296
1274 } // namespace wifi 1297 } // namespace wifi
OLDNEW
« no previous file with comments | « no previous file | components/wifi/wifi_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698