1 /** @file wlan_basic_cli.c
2 *
3 * @brief This file provides Connection Manager CLI
4 *
5 * Copyright 2008-2024 NXP
6 *
7 * SPDX-License-Identifier: BSD-3-Clause
8 *
9 */
10
11 #include <wlan.h>
12 #include "wifi_shell.h"
13
test_wfa_wlan_version(int argc,char ** argv)14 static void test_wfa_wlan_version(int argc, char **argv)
15 {
16 unsigned char i;
17 char version_str[MLAN_MAX_VER_STR_LEN];
18 char *ext_ver_str = wlan_get_firmware_version_ext();
19 (void)strcpy(version_str, ext_ver_str);
20 for (i = 0; i < strlen(version_str); i++)
21 {
22 if (version_str[i] == '.' && version_str[i + 1U] == 'p')
23 {
24 version_str[i] = '\0';
25 break;
26 }
27 }
28
29 (void)PRINTF("WLAN Version : %s\r\n", version_str);
30 }
31
test_wlan_version(int argc,char ** argv)32 static void test_wlan_version(int argc, char **argv)
33 {
34 char *version_str;
35
36 version_str = wlan_get_firmware_version_ext();
37
38 (void)PRINTF("WLAN Driver Version : %s\r\n", WLAN_DRV_VERSION);
39 (void)PRINTF("WLAN Firmware Version : %s\r\n", version_str);
40 }
41
test_wlan_get_mac_address(int argc,char ** argv)42 static void test_wlan_get_mac_address(int argc, char **argv)
43 {
44 uint8_t sta_mac[MLAN_MAC_ADDR_LENGTH];
45 #if UAP_SUPPORT
46 uint8_t uap_mac[MLAN_MAC_ADDR_LENGTH];
47 #endif
48
49 (void)PRINTF("MAC address\r\n");
50 if (wlan_get_mac_address(sta_mac)
51 #if UAP_SUPPORT
52 || wlan_get_mac_address_uap(uap_mac)
53 #endif
54 )
55 {
56 (void)PRINTF("Error: unable to retrieve MAC address\r\n");
57 }
58 else
59 {
60 (void)PRINTF("STA MAC Address: %02X:%02X:%02X:%02X:%02X:%02X\r\n", sta_mac[0], sta_mac[1], sta_mac[2],
61 sta_mac[3], sta_mac[4], sta_mac[5]);
62 #if UAP_SUPPORT
63 (void)PRINTF("uAP MAC Address: %02X:%02X:%02X:%02X:%02X:%02X\r\n", uap_mac[0], uap_mac[1], uap_mac[2],
64 uap_mac[3], uap_mac[4], uap_mac[5]);
65 #endif
66 }
67 #if CONFIG_P2P
68 (void)PRINTF("P2P MAC address\r\n");
69 if (wlan_get_wfd_mac_address(mac))
70 (void)PRINTF("Error: unable to retrieve P2P MAC address\r\n");
71 else
72 (void)PRINTF("%02X:%02X:%02X:%02X:%02X:%02X\r\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
73 #endif
74 }
75
76 static struct cli_command wlan_wfa_basic_commands[] = {
77 {"wlan-version", NULL, test_wfa_wlan_version},
78 {"wlan-mac", NULL, test_wlan_get_mac_address},
79 };
80
81 static struct cli_command wlan_basic_commands[] = {
82 {"wlan-version", NULL, test_wlan_version},
83 {"wlan-mac", NULL, test_wlan_get_mac_address},
84 };
85
86 static bool wlan_wfa_basic_cli_init_done = false;
87
wlan_wfa_basic_cli_init(void)88 int wlan_wfa_basic_cli_init(void)
89 {
90 unsigned int i;
91
92 for (i = 0; i < sizeof(wlan_wfa_basic_commands) / sizeof(struct cli_command); i++)
93 {
94 if (cli_register_command(&wlan_wfa_basic_commands[i]) != 0)
95 {
96 return WLAN_ERROR_ACTION;
97 }
98 }
99
100 wlan_wfa_basic_cli_init_done = true;
101
102 return WLAN_ERROR_NONE;
103 }
104
wlan_wfa_basic_cli_deinit(void)105 int wlan_wfa_basic_cli_deinit(void)
106 {
107 unsigned int i;
108
109 for (i = 0; i < sizeof(wlan_wfa_basic_commands) / sizeof(struct cli_command); i++)
110 {
111 if (cli_unregister_command(&wlan_wfa_basic_commands[i]) != 0)
112 {
113 return WLAN_ERROR_ACTION;
114 }
115 }
116
117 wlan_wfa_basic_cli_init_done = false;
118
119 return WLAN_ERROR_NONE;
120 }
121
wlan_basic_cli_init(void)122 int wlan_basic_cli_init(void)
123 {
124 unsigned int i;
125
126 if (wlan_wfa_basic_cli_init_done)
127 {
128 return WLAN_ERROR_NONE;
129 }
130
131 for (i = 0; i < sizeof(wlan_basic_commands) / sizeof(struct cli_command); i++)
132 {
133 if (cli_register_command(&wlan_basic_commands[i]) != 0)
134 {
135 return WLAN_ERROR_ACTION;
136 }
137 }
138
139 return WLAN_ERROR_NONE;
140 }
141
wlan_basic_cli_deinit(void)142 int wlan_basic_cli_deinit(void)
143 {
144 unsigned int i;
145
146 for (i = 0; i < sizeof(wlan_basic_commands) / sizeof(struct cli_command); i++)
147 {
148 if (cli_unregister_command(&wlan_basic_commands[i]) != 0)
149 {
150 return WLAN_ERROR_ACTION;
151 }
152 }
153
154 return WLAN_ERROR_NONE;
155 }
156