Skip to content

Commit dd7d447

Browse files
authored
Merge pull request #95 from tmobile/tmo-CFSPDK-1038-Disable-WiFi-Commands-When-RS9116-Is-Off
Disabled wifi commands when wifi chip is off
2 parents 296d550 + 23e740c commit dd7d447

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

samples/tmo_shell/src/tmo_wifi.c

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
#include <zephyr/shell/shell.h>
1313
#include <shell/shell_help.h>
1414

15+
#if CONFIG_PM_DEVICE
16+
#include <zephyr/pm/device.h>
17+
#endif
18+
1519
#include "tmo_shell.h"
1620

1721
#define WIFI_SHELL_MGMT_EVENTS (NET_EVENT_WIFI_SCAN_RESULT | \
@@ -293,6 +297,16 @@ int cmd_wifi_connect(const struct shell *shell, size_t argc,
293297
return -EINVAL;
294298
}
295299

300+
#if CONFIG_PM_DEVICE
301+
enum pm_device_state st;
302+
303+
pm_device_state_get(iface->if_dev->dev, &st);
304+
if (st == PM_DEVICE_STATE_OFF) {
305+
shell_error(shell, "Device %s is off, Command ignored", iface->if_dev->dev->name);
306+
return -EIO;
307+
}
308+
#endif
309+
296310
static struct wifi_connect_req_params cnx_params;
297311

298312
if (__wifi_args_to_params(argc - 2, &argv[2], &cnx_params)) {
@@ -332,6 +346,16 @@ int cmd_wifi_disconnect(const struct shell *shell, size_t argc,
332346
return -EINVAL;
333347
}
334348

349+
#if CONFIG_PM_DEVICE
350+
enum pm_device_state st;
351+
352+
pm_device_state_get(iface->if_dev->dev, &st);
353+
if (st == PM_DEVICE_STATE_OFF) {
354+
shell_error(shell, "Device %s is off, Command ignored", iface->if_dev->dev->name);
355+
return -EIO;
356+
}
357+
#endif
358+
335359
// struct net_if *iface = net_if_get_default();
336360
int status;
337361

@@ -373,6 +397,16 @@ int cmd_wifi_scan(const struct shell *shell, size_t argc, char *argv[])
373397
return -EINVAL;
374398
}
375399

400+
#if CONFIG_PM_DEVICE
401+
enum pm_device_state st;
402+
403+
pm_device_state_get(iface->if_dev->dev, &st);
404+
if (st == PM_DEVICE_STATE_OFF) {
405+
shell_error(shell, "Device %s is off, Command ignored", iface->if_dev->dev->name);
406+
return -EIO;
407+
}
408+
#endif
409+
376410
context.shell = shell;
377411

378412
if (net_mgmt(NET_REQUEST_WIFI_SCAN, iface, NULL, 0)) {
@@ -402,6 +436,16 @@ int cmd_wifi_status(const struct shell *shell, size_t argc, char *argv[])
402436
return -EINVAL;
403437
}
404438

439+
#if CONFIG_PM_DEVICE
440+
enum pm_device_state st;
441+
442+
pm_device_state_get(iface->if_dev->dev, &st);
443+
if (st == PM_DEVICE_STATE_OFF) {
444+
shell_error(shell, "Device %s is off, Command ignored", iface->if_dev->dev->name);
445+
return -EIO;
446+
}
447+
#endif
448+
405449
context.shell = shell;
406450

407451
if (net_mgmt(NET_REQUEST_WIFI_STATUS, iface, NULL, 0)) {
@@ -477,6 +521,17 @@ int cmd_wifi_mac(const struct shell *shell, size_t argc, char *argv[])
477521
shell_error(shell, "Interface %d not found", idx);
478522
return -EINVAL;
479523
}
524+
525+
#if CONFIG_PM_DEVICE
526+
enum pm_device_state st;
527+
528+
pm_device_state_get(iface->if_dev->dev, &st);
529+
if (st == PM_DEVICE_STATE_OFF) {
530+
shell_error(shell, "Device %s is off, Command ignored", iface->if_dev->dev->name);
531+
return -EIO;
532+
}
533+
#endif
534+
480535
#ifdef CONFIG_WIFI_RS9116W
481536
else if (strstr(iface->if_dev->dev->name,"9116")) {
482537
uint8_t mac[6];

0 commit comments

Comments
 (0)