Skip to content

Commit 3b7237e

Browse files
Jordan Yatescarlescufi
authored andcommitted
net: wifi: shell: update SSID argument format
Instead of providing a comma seperated list of SSIDs, provide the SSIDs individually. This substantially simplifies the implementation. Signed-off-by: Jordan Yates <[email protected]>
1 parent a32e7aa commit 3b7237e

File tree

3 files changed

+19
-36
lines changed

3 files changed

+19
-36
lines changed

include/zephyr/net/wifi_utils.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,15 @@ int wifi_utils_parse_scan_bands(char *scan_bands_str, uint8_t *band_map);
6363
* as a comma separated string and convert it to an array.
6464
*
6565
* @param scan_ssids_str List of SSIDs expressed as a comma separated list.
66-
* @param ssids Pointer to an array where the parsed SSIDs are to be stored.
66+
* @param ssids Pointer to an array where the SSIDs pointers are to be stored.
67+
* @param num_ssids Maximum number of SSIDs that can be stored.
6768
*
6869
* @retval 0 on success.
6970
* @retval -errno value in case of failure.
7071
*/
7172
int wifi_utils_parse_scan_ssids(char *scan_ssids_str,
72-
char ssids[][WIFI_SSID_MAX_LEN + 1]);
73+
const char *ssids[],
74+
uint8_t num_ssids);
7375

7476

7577
/**

subsys/net/l2/wifi/wifi_shell.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ static int wifi_scan_args_to_params(const struct shell *sh,
480480
{"bands", required_argument, 0, 'b'},
481481
{"dwell_time_active", required_argument, 0, 'a'},
482482
{"dwell_time_passive", required_argument, 0, 'p'},
483-
{"ssids", required_argument, 0, 's'},
483+
{"ssid", required_argument, 0, 's'},
484484
{"max_bss", required_argument, 0, 'm'},
485485
{"chans", required_argument, 0, 'c'},
486486
{"help", no_argument, 0, 'h'},
@@ -537,7 +537,9 @@ static int wifi_scan_args_to_params(const struct shell *sh,
537537
opt_num++;
538538
break;
539539
case 's':
540-
if (wifi_utils_parse_scan_ssids(optarg, params->ssids)) {
540+
if (wifi_utils_parse_scan_ssids(optarg,
541+
params->ssids,
542+
ARRAY_SIZE(params->ssids))) {
541543
shell_fprintf(sh, SHELL_ERROR, "Invalid SSID(s)\n");
542544
return -ENOEXEC;
543545
}
@@ -1653,7 +1655,7 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands,
16531655
"[-b, --bands <Comma separated list of band values (2/5/6)>] : Bands to be scanned where 2: 2.4 GHz, 5: 5 GHz, 6: 6 GHz.\n"
16541656
"[-a, --dwell_time_active <val_in_ms>] : Active scan dwell time (in ms) on a channel. Range 5 ms to 1000 ms.\n"
16551657
"[-p, --dwell_time_passive <val_in_ms>] : Passive scan dwell time (in ms) on a channel. Range 10 ms to 1000 ms.\n"
1656-
"[-s, --ssids <Comma separate list of SSIDs>] : SSID list to scan for.\n"
1658+
"[-s, --ssid : SSID to scan for. Can be provided multiple times.\n"
16571659
"[-m, --max_bss <val>] : Maximum BSSes to scan for. Range 1 - 65535.\n"
16581660
"[-c, --chans <Comma separated list of channel ranges>] : Channels to be scanned. The channels must be specified in the form band1:chan1,chan2_band2:chan3,..etc. band1, band2 must be valid band values and chan1, chan2, chan3 must be specified as a list of comma separated values where each value is either a single channel or a channel range specified as chan_start-chan_end. Each band channel set has to be separated by a _. For example, a valid channel specification can be 2:1,6-11,14_5:36,149-165,44\n"
16591661
"[-h, --help] : Print out the help for the scan command.",

subsys/net/l2/wifi/wifi_utils.c

Lines changed: 10 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -263,54 +263,33 @@ int wifi_utils_parse_scan_bands(char *scan_bands_str, uint8_t *band_map)
263263
}
264264

265265
int wifi_utils_parse_scan_ssids(char *scan_ssids_str,
266-
char ssids[][WIFI_SSID_MAX_LEN + 1])
266+
const char *ssids[],
267+
uint8_t num_ssids)
267268
{
268-
char parse_str[(WIFI_MGMT_SCAN_SSID_FILT_MAX * (WIFI_SSID_MAX_LEN + 1)) + 1];
269-
char *ssid = NULL;
270-
char *ctx = NULL;
271-
uint8_t i = 0;
272269
int len;
273270

274271
if (!scan_ssids_str) {
275272
return -EINVAL;
276273
}
277274

278275
len = strlen(scan_ssids_str);
279-
280-
if (len > (WIFI_MGMT_SCAN_SSID_FILT_MAX * (WIFI_SSID_MAX_LEN + 1))) {
276+
if (len > WIFI_SSID_MAX_LEN) {
281277
NET_ERR("SSID string (%s) size (%d) exceeds maximum allowed value (%d)",
282278
scan_ssids_str,
283279
len,
284-
(WIFI_MGMT_SCAN_SSID_FILT_MAX * (WIFI_SSID_MAX_LEN + 1)));
280+
WIFI_SSID_MAX_LEN);
285281
return -EINVAL;
286282
}
287283

288-
strncpy(parse_str, scan_ssids_str, len);
289-
parse_str[len] = '\0';
290-
291-
ssid = strtok_r(parse_str, ",", &ctx);
292-
293-
while (ssid) {
294-
if (strlen(ssid) > WIFI_SSID_MAX_LEN) {
295-
NET_ERR("SSID length (%zu) exceeds maximum value (%d) for SSID %s",
296-
strlen(ssid),
297-
WIFI_SSID_MAX_LEN,
298-
ssid);
299-
return -EINVAL;
300-
}
301-
302-
if (i >= WIFI_MGMT_SCAN_SSID_FILT_MAX) {
303-
NET_WARN("Exceeded maximum allowed (%d) SSIDs. Ignoring SSIDs %s onwards",
304-
WIFI_MGMT_SCAN_SSID_FILT_MAX,
305-
ssid);
306-
break;
284+
for (int i = 0; i < num_ssids; i++) {
285+
if (ssids[i] != NULL) {
286+
continue;
307287
}
308-
309-
strcpy(&ssids[i++][0], ssid);
310-
311-
ssid = strtok_r(NULL, ",", &ctx);
288+
ssids[i] = scan_ssids_str;
289+
return 0;
312290
}
313291

292+
NET_WARN("Exceeded maximum allowed SSIDs (%d)", num_ssids);
314293
return 0;
315294
}
316295

0 commit comments

Comments
 (0)