@@ -107,7 +107,7 @@ static CHIP_ERROR WiFiModeHandler(int argc, char ** argv)
107
107
return SetWiFiMode (argv[0 ]);
108
108
}
109
109
110
- static CHIP_ERROR WifiAddNetwork ( char * ssid , char * password )
110
+ static CHIP_ERROR WiFiConnectHandler ( int argc , char ** argv )
111
111
{
112
112
CHIP_ERROR error = CHIP_NO_ERROR;
113
113
uint8_t networkIndex;
@@ -117,78 +117,28 @@ static CHIP_ERROR WifiAddNetwork(char * ssid, char * password)
117
117
118
118
VerifyOrReturnError (GetWiFiDriver () != nullptr , error = CHIP_ERROR_NOT_IMPLEMENTED);
119
119
120
- ssidSpan = ByteSpan (reinterpret_cast <const uint8_t *>(ssid), strlen (ssid));
121
- passwordSpan = ByteSpan (reinterpret_cast <const uint8_t *>(password), strlen (password));
120
+ /* Command accepts running with SSID and password as parameters */
121
+ VerifyOrReturnError ((argc == 2 ), error = CHIP_ERROR_INVALID_ARGUMENT);
122
+
123
+ ssidSpan = ByteSpan (reinterpret_cast <const uint8_t *>(argv[0 ]), strlen (argv[0 ]));
124
+ passwordSpan = ByteSpan (reinterpret_cast <const uint8_t *>(argv[1 ]), strlen (argv[1 ]));
122
125
123
126
if (IsSpanUsable (ssidSpan) && IsSpanUsable (passwordSpan))
124
127
{
125
128
ChipLogProgress (DeviceLayer, " [Shell] Adding/Updating network %s" , ssidSpan.data ());
126
129
127
130
/* AddOrUpdateNetwork() checks ssid length and password length. The network info is not persistent. */
128
131
GetWiFiDriver ()->AddOrUpdateNetwork (ssidSpan, passwordSpan, debugText, networkIndex);
129
- }
130
- else
131
- {
132
- error = CHIP_ERROR_INVALID_ARGUMENT;
133
- }
134
-
135
- return error;
136
- }
137
-
138
- static CHIP_ERROR WiFiConnectHandler (int argc, char ** argv)
139
- {
140
- CHIP_ERROR error = CHIP_NO_ERROR;
141
- bool connectToNetwork = false ;
142
- ByteSpan ssidSpan;
143
-
144
- VerifyOrReturnError (GetWiFiDriver () != nullptr , error = CHIP_ERROR_NOT_IMPLEMENTED);
145
-
146
- /* Command accepts running either without arguments or either with SSID and password */
147
- /* Running without arguments implies that "wifi add ssid password" was executed before */
148
- VerifyOrReturnError ((argc == 0 ) || (argc == 2 ), error = CHIP_ERROR_INVALID_ARGUMENT);
149
-
150
- if (argc == 0 )
151
- {
152
- /* Retrieve previously added SSID */
153
- char ssid[DeviceLayer::Internal::kMaxWiFiSSIDLength + 1 ] = { 0 };
154
- MutableCharSpan ssidMutableSpan (ssid);
155
-
156
- VerifyOrReturnError (ConnectivityMgr ().GetNetworkSSID (ssidMutableSpan) == CHIP_NO_ERROR, error = CHIP_ERROR_BUFFER_TOO_SMALL);
157
-
158
- if (IsSpanUsable (ssidMutableSpan))
159
- {
160
- connectToNetwork = true ;
161
- ssidSpan = ByteSpan (reinterpret_cast <const uint8_t *>(ssidMutableSpan.data ()), ssidMutableSpan.size ());
162
- }
163
- else
164
- {
165
- ChipLogError (
166
- DeviceLayer,
167
- " [Shell] No network credentials found! Please add using <wifi add ssid password> or <wifi connect ssid password>" );
168
- error = CHIP_ERROR_INVALID_ARGUMENT;
169
- }
170
- }
171
- else if (argc == 2 )
172
- {
173
- ssidSpan = ByteSpan (reinterpret_cast <const uint8_t *>(argv[0 ]), strlen (argv[0 ]));
174
-
175
- if ((IsSpanUsable (ssidSpan)) && (WifiAddNetwork (argv[0 ], argv[1 ]) == CHIP_NO_ERROR))
176
- {
177
- connectToNetwork = true ;
178
- }
179
- else
180
- {
181
- ChipLogError (DeviceLayer, " [Shell] Failed to add network credentials!" );
182
- error = CHIP_ERROR_INVALID_ARGUMENT;
183
- }
184
- }
185
132
186
- if (connectToNetwork == true )
187
- {
188
133
ChipLogProgress (DeviceLayer, " [Shell] Progress: Connecting to network" );
189
134
/* Connection event will be returned in OnWiFiConnectivityChange from DeviceCallbacks.cpp */
190
135
GetWiFiDriver ()->ConnectNetwork (ssidSpan, nullptr );
191
136
}
137
+ else
138
+ {
139
+ ChipLogError (DeviceLayer, " [Shell] Failed to add network credentials!" );
140
+ error = CHIP_ERROR_INVALID_ARGUMENT;
141
+ }
192
142
193
143
return error;
194
144
}
@@ -200,38 +150,6 @@ static CHIP_ERROR WiFiDisconnectHandler(int argc, char ** argv)
200
150
return ConnectivityMgr ().DisconnectNetwork ();
201
151
}
202
152
203
- static CHIP_ERROR WiFiAddNwkHandler (int argc, char ** argv)
204
- {
205
- VerifyOrReturnError ((argc == 2 ), CHIP_ERROR_INVALID_ARGUMENT);
206
-
207
- return WifiAddNetwork (argv[0 ], argv[1 ]);
208
- }
209
-
210
- static CHIP_ERROR WiFiRemoveNwkHandler (int argc, char ** argv)
211
- {
212
- VerifyOrReturnError (GetWiFiDriver () != nullptr , CHIP_ERROR_NOT_IMPLEMENTED);
213
-
214
- DeviceLayer::NetworkCommissioning::Status status;
215
- uint8_t networkIndex;
216
- ByteSpan ssidSpan;
217
- char ssid[DeviceLayer::Internal::kMaxWiFiSSIDLength + 1 ] = { 0 };
218
- MutableCharSpan debugText;
219
- MutableCharSpan ssidMutableSpan (ssid);
220
-
221
- VerifyOrReturnError (ConnectivityMgr ().GetNetworkSSID (ssidMutableSpan) == CHIP_NO_ERROR, CHIP_ERROR_BUFFER_TOO_SMALL);
222
-
223
- ssidSpan = ByteSpan (reinterpret_cast <const uint8_t *>(ssidMutableSpan.data ()), ssidMutableSpan.size ());
224
-
225
- status = GetWiFiDriver ()->RemoveNetwork (ssidSpan, debugText, networkIndex);
226
-
227
- if (status != DeviceLayer::NetworkCommissioning::Status::kSuccess )
228
- {
229
- ChipLogError (DeviceLayer, " [Shell] Error: RemoveNetwork: %u" , (uint8_t ) status);
230
- }
231
-
232
- return CHIP_NO_ERROR;
233
- }
234
-
235
153
static CHIP_ERROR WiFiScanHandler (int argc, char ** argv)
236
154
{
237
155
ByteSpan ssidSpan;
@@ -281,11 +199,9 @@ void RegisterWiFiCommands()
281
199
static const shell_command_t sWiFiSubCommands [] = {
282
200
{ &WiFiHelpHandler, " help" , " " },
283
201
{ &WiFiModeHandler, " mode" , " Get/Set wifi mode. Usage: wifi mode [disable|ap|sta]" },
284
- { &WiFiConnectHandler, " connect" , " Connect to AP. Usage: wifi connect <ssid> <psk>. ssid and psk are optional. " },
202
+ { &WiFiConnectHandler, " connect" , " Connect to AP. Usage: wifi connect <ssid> <psk>" },
285
203
{ &WiFiDisconnectHandler, " disconnect" , " Disconnect device from AP. Usage: wifi disconnect" },
286
- { &WiFiAddNwkHandler, " add" , " Add credentials for Wi-Fi network. Usage: wifi add <ssid> <psk>" },
287
- { &WiFiRemoveNwkHandler, " remove" , " Remove credentials for Wi-Fi network. Usage: wifi remove <ssid>" },
288
- { &WiFiScanHandler, " scan" , " Scan for Wi-Fi networks. Usage: wifi scan <ssid>. ssid is optional." },
204
+ { &WiFiScanHandler, " scan" , " Scan for Wi-Fi networks. Usage: wifi scan <ssid>. ssid is optional" },
289
205
};
290
206
static const shell_command_t sWiFiCommand = { &WiFiDispatch, " wifi" , " Usage: wifi <subcommand>" };
291
207
0 commit comments