1 /**
2  * Copyright 2023-2024 NXP
3  * SPDX-License-Identifier: Apache-2.0
4  *
5  * @file nxp_wifi_shell.c
6  * Wi-Fi driver shell adapter layer
7  */
8 
9 #include <zephyr/kernel.h>
10 #include <zephyr/shell/shell.h>
11 
12 #include "nxp_wifi_drv.h"
13 
14 static struct nxp_wifi_dev *nxp_wifi;
15 
nxp_wifi_shell_register(struct nxp_wifi_dev * dev)16 void nxp_wifi_shell_register(struct nxp_wifi_dev *dev)
17 {
18 	/* only one instance supported */
19 	if (nxp_wifi) {
20 		return;
21 	}
22 
23 	nxp_wifi = dev;
24 }
25 
nxp_wifi_shell_cmd(const struct shell * sh,size_t argc,char ** argv)26 static int nxp_wifi_shell_cmd(const struct shell *sh, size_t argc, char **argv)
27 {
28 	if (nxp_wifi == NULL) {
29 		shell_print(sh, "no nxp_wifi device registered");
30 		return -ENOEXEC;
31 	}
32 
33 	if (argc < 2) {
34 		shell_help(sh);
35 		return -ENOEXEC;
36 	}
37 
38 	k_mutex_lock(&nxp_wifi->mutex, K_FOREVER);
39 
40 	nxp_wifi_request(argc, argv);
41 
42 	k_mutex_unlock(&nxp_wifi->mutex);
43 
44 	return 0;
45 }
46 
47 SHELL_CMD_ARG_REGISTER(nxp_wifi, NULL, "NXP Wi-Fi commands (Use help)", nxp_wifi_shell_cmd, 2,
48 		       CONFIG_SHELL_ARGC_MAX);
49