Select one of the symbols to view example projects that use it.
 
Outline
#include <stdio.h>
#include <string.h>
#include "sdkconfig.h"
#include "esp_wifi_types.h"
#include "esp_log.h"
#include "esp_err.h"
#include "esp_idf_version.h"
#include "wifi_cmd.h"
#define APP_TAG
app_wifi_auth_mode_t
wifi_auth_mode_map
#define WIFI_AUTH_TYPE_NUM
wifi_cmd_auth_mode_str2num(const char *)
wifi_cmd_auth_mode_num2str(uint8_t)
app_wifi_interface_str2ifx(const char *)
app_wifi_mode_t
s_wifi_mode_map
#define WIFI_MODE_NUM
app_wifi_mode_str2num(const char *)
app_wifi_mode_num2str(const wifi_mode_t)
wifi_cmd_str2mac(const char *, uint8_t *)
#define MAX_CHANNEL_STR_LEN
wifi_cmd_phy_mode_num2str(wifi_phy_mode_t)
Files
loading...
SourceVuESP-IDF Framework and Examplesiperf samplemanaged_components/esp-qa__wifi-cmd/src/wifi_common.c
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/* * SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 *//* ... */ #include <stdio.h> #include <string.h> #include "sdkconfig.h" #include "esp_wifi_types.h" #include "esp_log.h" #include "esp_err.h" #include "esp_idf_version.h" #include "wifi_cmd.h"8 includes #ifndef APP_TAG #define APP_TAG "WIFI" #endif typedef struct { int8_t value; char *auth_mode; }{ ... } app_wifi_auth_mode_t; static const app_wifi_auth_mode_t wifi_auth_mode_map[] = { {WIFI_AUTH_OPEN, "open"}, {WIFI_AUTH_WEP, "wep"}, {WIFI_AUTH_WPA_PSK, "wpa"}, {WIFI_AUTH_WPA2_PSK, "wpa2"}, {WIFI_AUTH_WPA_WPA2_PSK, "wpa_wpa2"}, {WIFI_AUTH_WPA2_ENTERPRISE, "wpa2_enterprise"}, {WIFI_AUTH_WPA3_PSK, "wpa3"}, {WIFI_AUTH_WPA2_WPA3_PSK, "wpa2_wpa3"}, #ifdef WIFI_AUTH_WAPI_PSK {WIFI_AUTH_WAPI_PSK, "wapi"}, #endif #ifdef WIFI_AUTH_OWE {WIFI_AUTH_OWE, "owe"}, #endif }{...}; #define WIFI_AUTH_TYPE_NUM (sizeof(wifi_auth_mode_map) / sizeof(app_wifi_auth_mode_t)) uint8_t wifi_cmd_auth_mode_str2num(const char *auth_str) { uint8_t auth_mode; for (auth_mode = 0; auth_mode < WIFI_AUTH_TYPE_NUM; auth_mode++) { if (strcmp(wifi_auth_mode_map[auth_mode].auth_mode, auth_str) == 0) { break; }{...} }{...} return wifi_auth_mode_map[auth_mode].value; }{ ... } char *wifi_cmd_auth_mode_num2str(uint8_t value) { uint8_t auth_mode; for (auth_mode = 0; auth_mode < WIFI_AUTH_TYPE_NUM; auth_mode++) { if (wifi_auth_mode_map[auth_mode].value == value) { break; }{...} }{...} assert(auth_mode != WIFI_AUTH_TYPE_NUM); /* If another authmode is added */ return wifi_auth_mode_map[auth_mode].auth_mode; }{ ... } wifi_interface_t app_wifi_interface_str2ifx(const char *interface) { if (!strncmp(interface, "ap", 3)) { return WIFI_IF_AP; }{...} else if (!strncmp(interface, "sta", 4)) { return WIFI_IF_STA; }{...} else { ESP_LOGE(APP_TAG, "Can not get interface from str: %s", interface); /* Do not abort */ #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 1, 0) return WIFI_IF_MAX; #else /* older IDF does not have IF_MAX*/ return WIFI_IF_STA; #endif }{...} return WIFI_IF_STA; }{ ... } typedef struct { char *mode_str; wifi_mode_t mode; }{ ... } app_wifi_mode_t; static const app_wifi_mode_t s_wifi_mode_map[] = { {"null", WIFI_MODE_NULL}, {"ap", WIFI_MODE_AP}, {"sta", WIFI_MODE_STA}, {"apsta", WIFI_MODE_APSTA}, }{...}; #define WIFI_MODE_NUM (sizeof(s_wifi_mode_map) / sizeof(app_wifi_mode_t)) wifi_mode_t app_wifi_mode_str2num(const char *mode_str) { wifi_mode_t mode = 0; int i = 0; for (i = 0; i < WIFI_MODE_NUM; i++) { if (strcmp(s_wifi_mode_map[i].mode_str, mode_str) == 0) { mode = s_wifi_mode_map[i].mode; break; }{...} }{...} if (i == WIFI_MODE_NUM) { ESP_LOGE(APP_TAG, "Can not convert mode %s from str to value.", mode_str); /* Do not abort */ return WIFI_MODE_NULL; }{...} return mode; }{ ... } const char *app_wifi_mode_num2str(const wifi_mode_t mode) { char *mode_str = NULL; int i = 0; for (i = 0; i < WIFI_MODE_NUM; i++) { if (s_wifi_mode_map[i].mode == mode) { mode_str = s_wifi_mode_map[i].mode_str; break; }{...} }{...} if (i == WIFI_MODE_NUM) { ESP_LOGE(APP_TAG, "Can not convert mode %d to str", mode); /* Do not abort */ return "unknown"; }{...} return mode_str; }{ ... } esp_err_t wifi_cmd_str2mac(const char *str, uint8_t *mac_addr) { unsigned int mac_tmp[6]; if (6 != sscanf(str, "%02x:%02x:%02x:%02x:%02x:%02x%*c", &mac_tmp[0], &mac_tmp[1], &mac_tmp[2], &mac_tmp[3], &mac_tmp[4], &mac_tmp[5])) { return ESP_ERR_INVALID_MAC; }{...} for (int i = 0; i < 6; i++) { mac_addr[i] = (uint8_t)mac_tmp[i]; }{...} return ESP_OK; }{ ... } #if CONFIG_SOC_WIFI_SUPPORT_5G #define MAX_CHANNEL_STR_LEN 128 uint32_t wifi_cmd_channel_str2bitmsk(wifi_band_t band, const char *channel_list_str) { char input_copy[MAX_CHANNEL_STR_LEN]; uint32_t channel_bitmap = 0; uint8_t channel = 0; strcpy(input_copy, channel_list_str); char *endptr; char *token = strtok(input_copy, ","); while (token != NULL) { channel = (uint8_t)strtol(token, &endptr, 10); // return 0 if input is not all numbers if (*endptr != '\0') { return 0; }{...} if (band == WIFI_BAND_2G && channel > 14) { return 0; }{...} else if (band == WIFI_BAND_5G && channel < 36) { return 0; }{...} channel_bitmap |= CHANNEL_TO_BIT(channel); token = strtok(NULL, ","); }{...} return channel_bitmap; }{...} const char *wifi_cmd_channel_bitmsk2str(wifi_band_t band, uint32_t bitmap) { static char channel_str[MAX_CHANNEL_STR_LEN]; memset(channel_str, 0, sizeof(channel_str)); int first_channel = 1; for (int bit_number = 0; bit_number < 32; bit_number++) { if (bitmap & (1 << bit_number)) { int channel = BIT_NUMBER_TO_CHANNEL(bit_number, band); if (channel != 0) { if (!first_channel) { strcat(channel_str, ","); }{...} char temp[8]; snprintf(temp, sizeof(temp), "%d", channel); strcat(channel_str, temp); first_channel = 0; }{...} }{...} }{...} if (strlen(channel_str) == 0) { return "UNKNOWN"; }{...} return channel_str; }{...} /* ... */#endif /* CONFIG_SOC_WIFI_SUPPORT_5G */ #if WIFI_PHY_MODE_SUPPORTED const char *wifi_cmd_phy_mode_num2str(wifi_phy_mode_t phymode) { switch (phymode) { case WIFI_PHY_MODE_LR: return "lr";... case WIFI_PHY_MODE_11B: return "b";... case WIFI_PHY_MODE_11G: return "g"; #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 3, 1) /* IDF commit: f0365ba6b5d832a2e5999fda56b89c1f18c02858 */... case WIFI_PHY_MODE_11A: return "a";/* ... */ #endif /* v5.3.1 */ case WIFI_PHY_MODE_HT20: return "ht20";... case WIFI_PHY_MODE_HT40: return "ht40";... case WIFI_PHY_MODE_HE20: return "he20"; #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 3, 1) /* IDF commit: f0365ba6b5d832a2e5999fda56b89c1f18c02858 */... case WIFI_PHY_MODE_VHT20: return "vht20";/* ... */ #endif /* v5.3.1 */ default: return "?";... }{...} return "?"; }{ ... } /* ... */#endif /* WIFI_PHY_MODE_SUPPORTED */
Details
Show:
from
Types: Columns:
This file uses the notable symbols shown below. Click anywhere in the file to view more details.