Chromium Code Reviews| 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 <stdio.h> | 5 #include <stdio.h> |
| 6 #include <string> | 6 #include <string> |
| 7 | 7 |
| 8 #include "base/at_exit.h" | 8 #include "base/at_exit.h" |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/cancelable_callback.h" | 10 #include "base/cancelable_callback.h" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 60 base::AtExitManager exit_manager_; | 60 base::AtExitManager exit_manager_; |
| 61 | 61 |
| 62 Result result_; | 62 Result result_; |
| 63 }; | 63 }; |
| 64 | 64 |
| 65 WiFiTest::Result WiFiTest::Main(int argc, const char* argv[]) { | 65 WiFiTest::Result WiFiTest::Main(int argc, const char* argv[]) { |
| 66 if (!ParseCommandLine(argc, argv)) { | 66 if (!ParseCommandLine(argc, argv)) { |
| 67 VLOG(0) << "Usage: " << argv[0] << | 67 VLOG(0) << "Usage: " << argv[0] << |
| 68 " [--list]" | 68 " [--list]" |
| 69 " [--get_properties]" | 69 " [--get_properties]" |
| 70 " [--create]" | |
| 70 " [--connect]" | 71 " [--connect]" |
| 71 " [--disconnect]" | 72 " [--disconnect]" |
| 72 " [--network_guid=<network_guid>]" | 73 " [--network_guid=<network_guid>]" |
| 73 " [--frequency=0|2400|5000]" | 74 " [--frequency=0|2400|5000]" |
| 75 " [--security=none|WEP-PSK|WPA-PSK|WPA2-PSK]" | |
| 76 " [--password=<wifi password>]" | |
| 74 " [<network_guid>]\n"; | 77 " [<network_guid>]\n"; |
| 75 return RESULT_WRONG_USAGE; | 78 return RESULT_WRONG_USAGE; |
| 76 } | 79 } |
| 77 | 80 |
| 78 base::MessageLoopForIO loop; | 81 base::MessageLoopForIO loop; |
| 79 result_ = RESULT_PENDING; | 82 result_ = RESULT_PENDING; |
| 80 | 83 |
| 81 return result_; | 84 return result_; |
| 82 } | 85 } |
| 83 | 86 |
| 84 bool WiFiTest::ParseCommandLine(int argc, const char* argv[]) { | 87 bool WiFiTest::ParseCommandLine(int argc, const char* argv[]) { |
| 85 CommandLine::Init(argc, argv); | 88 CommandLine::Init(argc, argv); |
| 86 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); | 89 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); |
| 87 std::string network_guid = | 90 std::string network_guid = |
| 88 parsed_command_line.GetSwitchValueASCII("network_guid"); | 91 parsed_command_line.GetSwitchValueASCII("network_guid"); |
| 89 std::string frequency = | 92 std::string frequency = |
| 90 parsed_command_line.GetSwitchValueASCII("frequency"); | 93 parsed_command_line.GetSwitchValueASCII("frequency"); |
| 94 std::string password = | |
| 95 parsed_command_line.GetSwitchValueASCII("password"); | |
| 96 std::string security = | |
| 97 parsed_command_line.GetSwitchValueASCII("security"); | |
| 91 | 98 |
| 92 if (parsed_command_line.GetArgs().size() == 1) { | 99 if (parsed_command_line.GetArgs().size() == 1) { |
| 93 #if defined(OS_WIN) | 100 #if defined(OS_WIN) |
| 94 network_guid = WideToASCII(parsed_command_line.GetArgs()[0]); | 101 network_guid = WideToASCII(parsed_command_line.GetArgs()[0]); |
| 95 #else | 102 #else |
| 96 network_guid = parsed_command_line.GetArgs()[0]; | 103 network_guid = parsed_command_line.GetArgs()[0]; |
| 97 #endif | 104 #endif |
| 98 } | 105 } |
| 99 | 106 |
| 100 #if defined(OS_WIN) | 107 #if defined(OS_WIN) |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 120 if (parsed_command_line.HasSwitch("get_properties")) { | 127 if (parsed_command_line.HasSwitch("get_properties")) { |
| 121 if (network_guid.length() > 0) { | 128 if (network_guid.length() > 0) { |
| 122 DictionaryValue properties; | 129 DictionaryValue properties; |
| 123 std::string error; | 130 std::string error; |
| 124 wifi_service->GetProperties(network_guid, &properties, &error); | 131 wifi_service->GetProperties(network_guid, &properties, &error); |
| 125 VLOG(0) << error << ":\n" << properties; | 132 VLOG(0) << error << ":\n" << properties; |
| 126 return true; | 133 return true; |
| 127 } | 134 } |
| 128 } | 135 } |
| 129 | 136 |
| 130 // Optional properties (frequency, password) to use for connect. | 137 // Optional properties (frequency, password) to use for connect or create. |
| 131 scoped_ptr<DictionaryValue> connect_properties(new DictionaryValue()); | 138 scoped_ptr<DictionaryValue> properties(new DictionaryValue()); |
| 132 | 139 |
| 133 if (parsed_command_line.HasSwitch("frequency")) { | 140 if (!frequency.empty()) { |
| 134 int value = 0; | 141 int value = 0; |
| 135 if (!network_guid.empty() && | 142 if (base::StringToInt(frequency, &value)) { |
| 136 !frequency.empty() && | 143 properties->SetInteger("WiFi.Frequency", value); |
| 137 base::StringToInt(frequency, &value)) { | |
| 138 connect_properties->SetInteger("WiFi.Frequency", value); | |
| 139 // fall through to connect. | 144 // fall through to connect. |
| 140 } | 145 } |
| 141 } | 146 } |
| 142 | 147 |
| 148 if (!password.empty()) { | |
|
tbarzic
2013/12/10 19:42:39
nit: you don't need {}
mef
2013/12/10 20:51:43
Done.
| |
| 149 properties->SetString("WiFi.Passphrase", password); | |
| 150 } | |
| 151 | |
| 152 if (!security.empty()) { | |
| 153 properties->SetString("WiFi.Security", security); | |
| 154 } | |
| 155 | |
| 156 if (parsed_command_line.HasSwitch("create")) { | |
| 157 if (!network_guid.empty()) { | |
| 158 std::string error; | |
| 159 std::string new_network_guid; | |
| 160 properties->SetString("WiFi.SSID", network_guid); | |
| 161 VLOG(0) << "Creating Network: " << *properties; | |
| 162 wifi_service->CreateNetwork(false, | |
| 163 properties.Pass(), | |
| 164 &new_network_guid, | |
| 165 &error); | |
| 166 VLOG(0) << error << ":\n" << new_network_guid; | |
| 167 return true; | |
| 168 } | |
| 169 } | |
| 170 | |
| 143 if (parsed_command_line.HasSwitch("connect")) { | 171 if (parsed_command_line.HasSwitch("connect")) { |
| 144 if (network_guid.length() > 0) { | 172 if (!network_guid.empty()) { |
| 145 std::string error; | 173 std::string error; |
| 146 if (!connect_properties->empty()) { | 174 if (!properties->empty()) { |
| 147 VLOG(0) << "Using connect properties: " << *connect_properties; | 175 VLOG(0) << "Using connect properties: " << *properties; |
| 148 wifi_service->SetProperties(network_guid, | 176 wifi_service->SetProperties(network_guid, |
| 149 connect_properties.Pass(), | 177 properties.Pass(), |
| 150 &error); | 178 &error); |
| 151 } | 179 } |
| 152 wifi_service->StartConnect(network_guid, &error); | 180 wifi_service->StartConnect(network_guid, &error); |
| 153 VLOG(0) << error; | 181 VLOG(0) << error; |
| 154 return true; | 182 return true; |
| 155 } | 183 } |
| 156 } | 184 } |
| 157 | 185 |
| 158 if (parsed_command_line.HasSwitch("disconnect")) { | 186 if (parsed_command_line.HasSwitch("disconnect")) { |
| 159 if (network_guid.length() > 0) { | 187 if (network_guid.length() > 0) { |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 171 | 199 |
| 172 int main(int argc, const char* argv[]) { | 200 int main(int argc, const char* argv[]) { |
| 173 CommandLine::Init(argc, argv); | 201 CommandLine::Init(argc, argv); |
| 174 logging::LoggingSettings settings; | 202 logging::LoggingSettings settings; |
| 175 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; | 203 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; |
| 176 logging::InitLogging(settings); | 204 logging::InitLogging(settings); |
| 177 | 205 |
| 178 wifi::WiFiTest wifi_test; | 206 wifi::WiFiTest wifi_test; |
| 179 return wifi_test.Main(argc, argv); | 207 return wifi_test.Main(argc, argv); |
| 180 } | 208 } |
| OLD | NEW |