forked from nrfconnect/sdk-wi-fiquicktrack-controlappc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.h
238 lines (211 loc) · 7.11 KB
/
utils.h
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
/* Copyright (c) 2020 Wi-Fi Alliance */
/* Permission to use, copy, modify, and/or distribute this software for any */
/* purpose with or without fee is hereby granted, provided that the above */
/* copyright notice and this permission notice appear in all copies. */
/* THE SOFTWARE IS PROVIDED 'AS IS' AND THE AUTHOR DISCLAIMS ALL */
/* WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED */
/* WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL */
/* THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR */
/* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING */
/* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF */
/* CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT */
/* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS */
/* SOFTWARE. */
#ifndef _INDIGO_UTILS_
#define _INDIGO_UTILS_ 1
#include <stdbool.h>
#define S_BUFFER_LEN 512
#define BUFFER_LEN 1536
#define L_BUFFER_LEN 8192
#define TOOL_POST_PORT 8080
#define HAPD_UPLOAD_API "/upload-platform-hapd-log"
#define WPAS_UPLOAD_API "/upload-platform-wpas-log"
#define ARTIFACTS_UPLOAD_API "/upload-test-artifacts"
#ifdef _DUT_
#define APP_LOG_FILE "controlappc_DUT.log"
#else
#define APP_LOG_FILE "controlappc_tool_platform.log"
#endif
#define UPLOAD_TC_APP_LOG 1
#ifdef CONFIG_ZEPHYR
#define MSG_CONFIRM 0x800
#endif /* CONFIG_ZEPHYR */
#ifndef INADDR_NONE
#define INADDR_NONE 0xffffffff
#endif /* INADDR_NONE */
/* Log */
enum {
LOG_LEVEL_DEBUG_VERBOSE = 0,
LOG_LEVEL_DEBUG = 1,
LOG_LEVEL_INFO = 2,
LOG_LEVEL_NOTICE = 3,
LOG_LEVEL_WARNING = 4,
LOG_LEVEL_ERROR = 5
};
enum {
BAND_24GHZ = 0,
BAND_5GHZ = 1,
BAND_6GHZ = 2
};
enum {
PHYMODE_AUTO = 0,
PHYMODE_11B = 1,
PHYMODE_11BG = 2,
PHYMODE_11BGN = 3,
PHYMODE_11A = 4,
PHYMODE_11NA = 5,
PHYMODE_11AC = 6,
PHYMODE_11AXG = 7,
PHYMODE_11AXA = 8
};
enum {
CHWIDTH_AUTO = 0,
CHWIDTH_20 = 1,
CHWIDTH_40 = 2,
CHWIDTH_80 = 3,
CHWIDTH_80PLUS80 = 4,
CHWIDTH_160 = 5
};
enum {
DATA_TYPE_UDP = 0,
DATA_TYPE_ICMP = 1
};
enum {
OP_CLASS_6G_20 = 131,
OP_CLASS_6G_40 = 132,
OP_CLASS_6G_80 = 133,
OP_CLASS_6G_160 = 134
};
struct sta_platform_config {
int phymode;
int chwidth;
bool phymode_isset;
bool chwidth_isset;
};
struct channel_info {
int channel;
int freq;
};
#define UNUSED_IDENTIFIER -1
struct interface_info {
int identifier; // valid only for multiple VAPs case
int band;
int bssid;
char ifname[16];
char ssid[64];
int mbssid_enable;
int transmitter;
int hapd_bss_id;
char hapd_conf_file[64];
};
struct bss_identifier_info {
int identifier;
int band;
int mbssid_enable;
int transmitter;
};
struct loopback_info {
int sock;
double rate;
int pkt_sent;
int pkt_rcv;
int pkt_type;
int pkt_size;
char target_ip[64];
char message[1600];
};
/* log and file API */
void indigo_logger(int level, const char *fmt, ...);
int pipe_command(char *buffer, int buffer_size, char *cmd, char *parameter[]);
char* read_file(char *fn);
int write_file(char *fn, char *buffer, int len);
int append_file(char *fn, char *buffer, int len);
void open_tc_app_log();
void close_tc_app_log();
/* network interface and loopback API */
int get_mac_address(char *buffer, int size, char *interface);
int set_mac_address(char *ifname, char *mac);
int find_interface_ip(char *ipaddr, int ipaddr_len, char *name);
int loopback_server_start(char *local_ip, char *local_port, int timeout);
int loopback_server_stop();
int loopback_server_status();
int send_udp_data(char *target_ip, int target_port, int packet_count, int packet_size, double rate);
int stop_loopback_data(int *pkt_sent);
int send_broadcast_arp(char *target_ip, int *send_count, int rate);
int send_icmp_data(char *target_ip, int packet_count, int packet_size, double rate);
char* get_wlans_bridge();
int set_wlans_bridge(char* br);
int is_bridge_created();
int create_bridge(char *br);
int add_interface_to_bridge(char *br, char *interface);
int reset_bridge(char *br);
int control_interface(char *ifname, char *op);
int set_interface_ip(char *ifname, char *ip);
int reset_interface_ip(char *ifname);
int add_wireless_interface(char *ifname);
int delete_wireless_interface(char *ifname);
void bridge_init(char *br);
void detect_del_arp_entry(char *ip);
#define DEBUG_LEVEL_DISABLE 0
#define DEBUG_LEVEL_BASIC 1
#define DEBUG_LEVEL_ADVANCED 2
int get_debug_level(int value);
/* hostapd API */
char* get_hapd_exec_file();
int set_hapd_exec_file(char* path);
char* get_hapd_full_exec_path();
int set_hapd_full_exec_path(char* path);
char* get_hapd_ctrl_path_by_id(struct interface_info* wlan);
char* get_hapd_ctrl_path();
int set_hapd_ctrl_path(char* path);
char* get_hapd_global_ctrl_path();
int set_hapd_global_ctrl_path(char* path);
char* get_hapd_conf_file();
int set_hapd_conf_file(char* path);
void set_hostapd_debug_level(int level);
char* get_hostapd_debug_arguments();
/* wpa_supplicant API */
char* get_wpas_exec_file();
int set_wpas_exec_file(char* path);
char* get_wpas_full_exec_path();
int set_wpas_full_exec_path(char* path);
char* get_wpas_ctrl_path();
char* get_wpas_if_ctrl_path(char* if_name);
int set_wpas_ctrl_path(char* path);
char* get_wpas_global_ctrl_path();
int set_wpas_global_ctrl_path(char* path);
char* get_wpas_conf_file();
int set_wpas_conf_file(char* path);
void set_wpas_debug_level(int level);
char* get_wpas_debug_arguments();
/* service and environment API */
char* get_wireless_interface();
int set_wireless_interface(char *name);
int get_service_port();
int set_service_port(int port);
char* get_default_wireless_interface_info();
int clear_interfaces_resource();
char* get_all_hapd_conf_files(int *swap_hostapd);
void parse_bss_identifier(int bss_identifier, struct bss_identifier_info* bss);
struct interface_info* assign_wireless_interface_info(struct bss_identifier_info *bss);
struct interface_info* get_wireless_interface_info(int band, int identifier);
struct interface_info* get_first_configured_wireless_interface_info();
int add_all_wireless_interface_to_bridge(char *br);
void set_default_wireless_interface_info(int channel);
int show_wireless_interface_info();
void iterate_all_wlan_interfaces(void (*callback_fn)(void *));
void get_server_cert_hash(char *pem_file, char *buffer);
int insert_wpa_network_config(char *config);
void remove_pac_file(char *path);
int is_band_enabled(int band);
/* misc */
size_t strlcpy(char *dest, const char *src, size_t siz);
int get_key_value(char *value, char *buffer, char *token);
int verify_band_from_freq(int freq, int band);
int get_center_freq_index(int channel, int width);
int get_6g_center_freq_index(int channel, int width);
int is_ht40plus_chan(int chan);
int is_ht40minus_chan(int chan);
int http_file_post(char *host, int port, char *path, char *file_name);
int file_exists(const char *fname);
#endif