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()) |
| 149 properties->SetString("WiFi.Passphrase", password); |
| 150 |
| 151 if (!security.empty()) |
| 152 properties->SetString("WiFi.Security", security); |
| 153 |
| 154 if (parsed_command_line.HasSwitch("create")) { |
| 155 if (!network_guid.empty()) { |
| 156 std::string error; |
| 157 std::string new_network_guid; |
| 158 properties->SetString("WiFi.SSID", network_guid); |
| 159 VLOG(0) << "Creating Network: " << *properties; |
| 160 wifi_service->CreateNetwork(false, |
| 161 properties.Pass(), |
| 162 &new_network_guid, |
| 163 &error); |
| 164 VLOG(0) << error << ":\n" << new_network_guid; |
| 165 return true; |
| 166 } |
| 167 } |
| 168 |
143 if (parsed_command_line.HasSwitch("connect")) { | 169 if (parsed_command_line.HasSwitch("connect")) { |
144 if (network_guid.length() > 0) { | 170 if (!network_guid.empty()) { |
145 std::string error; | 171 std::string error; |
146 if (!connect_properties->empty()) { | 172 if (!properties->empty()) { |
147 VLOG(0) << "Using connect properties: " << *connect_properties; | 173 VLOG(0) << "Using connect properties: " << *properties; |
148 wifi_service->SetProperties(network_guid, | 174 wifi_service->SetProperties(network_guid, |
149 connect_properties.Pass(), | 175 properties.Pass(), |
150 &error); | 176 &error); |
151 } | 177 } |
152 wifi_service->StartConnect(network_guid, &error); | 178 wifi_service->StartConnect(network_guid, &error); |
153 VLOG(0) << error; | 179 VLOG(0) << error; |
154 return true; | 180 return true; |
155 } | 181 } |
156 } | 182 } |
157 | 183 |
158 if (parsed_command_line.HasSwitch("disconnect")) { | 184 if (parsed_command_line.HasSwitch("disconnect")) { |
159 if (network_guid.length() > 0) { | 185 if (network_guid.length() > 0) { |
(...skipping 11 matching lines...) Expand all Loading... |
171 | 197 |
172 int main(int argc, const char* argv[]) { | 198 int main(int argc, const char* argv[]) { |
173 CommandLine::Init(argc, argv); | 199 CommandLine::Init(argc, argv); |
174 logging::LoggingSettings settings; | 200 logging::LoggingSettings settings; |
175 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; | 201 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; |
176 logging::InitLogging(settings); | 202 logging::InitLogging(settings); |
177 | 203 |
178 wifi::WiFiTest wifi_test; | 204 wifi::WiFiTest wifi_test; |
179 return wifi_test.Main(argc, argv); | 205 return wifi_test.Main(argc, argv); |
180 } | 206 } |
OLD | NEW |