hc
2024-03-26 e9199a72d842cbda78ac614eee5db7cdaa6f2530
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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
#ifndef __WL_H__
#define __WL_H__
 
#include <stdint.h>
#include <stdbool.h>
 
#define WL_MAX_SSID_LEN                (32)
#define    WL_ETHER_ADDR_LEN            (6)
#define WL_IPV4_ADDR_LEN               (4) 
#define WL_TCPKA_PAYLOAD_SIZE          (100)
#define WL_NUMCHANNELS                (64)
#define WL_INVALID_CHANNEL            (0)
 
#define WL_SCAN_AP_MAX                (64)
#define WL_SCAN_PER_CH_TIME_DEFAULT    (-1)
 
#define WL_WOWL_MAGIC               (1 << 0)
#define WL_WOWL_NET                 (1 << 1)
#define WL_WOWL_DIS                 (1 << 2)
#define WL_WOWL_RETR                (1 << 3)
#define WL_WOWL_BCN                 (1 << 4)
#define WL_WOWL_TST                 (1 << 5)
#define WL_WOWL_TRAFFIC             (1 << 12)
#define WL_WOWL_BCAST               (1 << 15)
#define WL_WOWL_TCPKEEP_TIME         (1 << 17)  /*Wakeup on tcpkeep alive timeout */
#define WL_WOWL_SECURE              (1 << 25)  /* Wakeup if received matched secured pattern */
#define WL_WOWL_NFYSCAN_WAKE        (1 << 28)  /* Wakeup up on nfyscan found the specified SSID */
 
#define WL_TLS_MAX_KEY_LENGTH        (48)
#define WL_TLS_MAX_MAC_KEY_LENGTH    (32)
#define WL_TLS_MAX_IV_LENGTH        (32)
#define WL_TLS_MAX_DEGIST_LENGTH    (32)
#define WL_TLS_MAX_SEQUENCE_LENGTH    (8)
#define WL_TLS_MAX_PAYLOAD_LEN        (10)
 
typedef enum {
   WL_E_OK                     = 0,    /* Success */
   WL_E_ERROR                  = -1,   /* Error generic */
   WL_E_BADARG                 = -2,   /* Bad Argument */
    WL_E_BADOPTION                = -3,   /* Bad option */
    WL_E_NOTUP                  = -4,   /* Not up */
    WL_E_NOTDOWN                = -5,   /* Not down */
    WL_E_NOTAP                  = -6,   /* Not AP */
    WL_E_NOTSTA                 = -7,   /* Not STA  */
    WL_E_BADKEYIDX                = -8,   /* BAD Key Index */
    WL_E_RADIOOFF                 = -9,   /* Radio Off */
    WL_E_NOTBANDLOCKED            = -10,  /* Not  band locked */
    WL_E_NOCLK                    = -11,  /* No Clock */
    WL_E_BADRATESET             = -12,  /* BAD Rate valueset */
    WL_E_BADBAND                = -13,  /* BAD Band */
    WL_E_BUFTOOSHORT            = -14,    /* Buffer too short */
    WL_E_BUFTOOLONG             = -15,  /* Buffer too long */
    WL_E_BUSY                   = -16,    /* Busy */
    WL_E_NOTASSOCIATED          = -17,  /* Not Associated */
    WL_E_BADSSIDLEN             = -18,  /* Bad SSID len */
    WL_E_OUTOFRANGECHAN         = -19,  /* Out of Range Channel */
    WL_E_BADCHAN                = -20,  /* Bad Channel */
    WL_E_BADADDR                = -21,  /* Bad Address */
    WL_E_NORESOURCE             = -22,  /* Not Enough Resources */
    WL_E_UNSUPPORTED            = -23,    /* Unsupported */
    WL_E_BADLEN                 = -24,    /* Bad length */
    WL_E_NOTREADY               = -25,    /* Not Ready */
    WL_E_EPERM                  = -26,    /* Not Permitted */
    WL_E_NOMEM                  = -27,    /* No Memory */
    WL_E_ASSOCIATED             = -28,    /* Associated */
    WL_E_RANGE                  = -29,    /* Not In Range */
    WL_E_NOTFOUND               = -30,    /* Not Found */
    WL_E_WME_NOT_ENABLED        = -31,    /* WME Not Enabled */
    WL_E_TSPEC_NOTFOUND         = -32,    /* TSPEC Not Found */
    WL_E_ACM_NOTSUPPORTED       = -33,    /* ACM Not Supported */
    WL_E_NOT_WME_ASSOCIATION    = -34,  /* Not WME Association */
    WL_E_SDIO_ERROR                = -35,    /* SDIO Bus Error */
    WL_E_DONGLE_DOWN            = -36,    /* Dongle Not Accessible */
    WL_E_VERSION                = -37,     /* Incorrect version */
    WL_E_TXFAIL                 = -38,     /* TX failure */
    WL_E_RXFAIL                 = -39,    /* RX failure */
    WL_E_NODEVICE               = -40,  /* Device not present */
    WL_E_NMODE_DISABLED         = -41,  /* NMODE disabled */
    WL_E_NONRESIDENT            = -42,  /* access to nonresident overlay */
    WL_E_SCANREJECT             = -43,  /* reject scan request */
    WL_E_USAGE_ERROR            = -44,  /* WLCMD usage error */
    WL_E_IOCTL_ERROR            = -45,  /* WLCMD ioctl error */
    WL_E_SERIAL_PORT_ERR        = -46,  /* RWL serial port error */
    WL_E_DISABLED               = -47,  /* Disabled in this build */
    WL_E_DECERR                 = -48,  /* Decrypt error */
    WL_E_ENCERR                 = -49,  /* Encrypt error */
    WL_E_MICERR                 = -50,  /* Integrity/MIC error */
    WL_E_REPLAY                 = -51,  /* Replay */
    WL_E_IE_NOTFOUND            = -52,  /* IE not found */
    WL_E_DATA_NOTFOUND          = -53,  /* Complete data not found in buffer */
    WL_E_TIMEOUT                = -110,    /* Timeout */
    WL_E_NO_NETWORK                = -111,    /* Not Network */
    WL_E_INVALID_KEY            = -112,    /* Invalid key */
    WL_E_LAST                    = -255    /* Invalid key */
} wl_err_t;
 
#define WEP_ENABLED                0x0001
#define TKIP_ENABLED               0x0002
#define AES_ENABLED                0x0004
#define SHARED_ENABLED             0x00008000
#define WPA_SECURITY               0x00200000
#define WPA2_SECURITY              0x00400000
#define ENTERPRISE_ENABLED         0x02000000
#define WPS_ENABLED                0x10000000
#define IBSS_ENABLED               0x20000000
 
typedef enum
{
   /* Open security */
    WL_SECURITY_OPEN               = 0,
    /* WEP PSK Security with open authentication */
    WL_SECURITY_WEP_PSK            = WEP_ENABLED,
    /* WEP PSK Security with shared authentication */
    WL_SECURITY_WEP_SHARED         = (WEP_ENABLED | SHARED_ENABLED),
    /* WPA PSK Security with TKIP */
    WL_SECURITY_WPA_TKIP_PSK       = (WPA_SECURITY | TKIP_ENABLED),
    /* WPA PSK Security with AES */
    WL_SECURITY_WPA_AES_PSK        = (WPA_SECURITY | AES_ENABLED),
    /* WPA PSK Security with AES & TKIP */
    WL_SECURITY_WPA_MIXED_PSK      = (WPA_SECURITY | AES_ENABLED | TKIP_ENABLED),
    /* WPA2 PSK Security with AES */
    WL_SECURITY_WPA2_AES_PSK       = (WPA2_SECURITY | AES_ENABLED),
    /* WPA2 PSK Security with TKIP */
    WL_SECURITY_WPA2_TKIP_PSK      = (WPA2_SECURITY | TKIP_ENABLED),
    /* WPA2 PSK Security with AES & TKIP */
    WL_SECURITY_WPA2_MIXED_PSK     = (WPA2_SECURITY | AES_ENABLED | TKIP_ENABLED ),
 
    /* WPA Enterprise Security with TKIP */
    WL_SECURITY_WPA_TKIP_ENT       = (ENTERPRISE_ENABLED | WPA_SECURITY | TKIP_ENABLED),
    /* WPA Enterprise Security with AES */
    WL_SECURITY_WPA_AES_ENT        = (ENTERPRISE_ENABLED | WPA_SECURITY | AES_ENABLED ),
    /* WPA Enterprise Security with AES & TKIP */
    WL_SECURITY_WPA_MIXED_ENT      = (ENTERPRISE_ENABLED | WPA_SECURITY | AES_ENABLED | TKIP_ENABLED),
    /* WPA2 Enterprise Security with TKIP */
    WL_SECURITY_WPA2_TKIP_ENT      = (ENTERPRISE_ENABLED | WPA2_SECURITY | TKIP_ENABLED),
    /* WPA2 Enterprise Security with AES */
    WL_SECURITY_WPA2_AES_ENT       = (ENTERPRISE_ENABLED | WPA2_SECURITY | AES_ENABLED),
    /* WPA2 Enterprise Security with AES & TKIP */
    WL_SECURITY_WPA2_MIXED_ENT     = (ENTERPRISE_ENABLED | WPA2_SECURITY | AES_ENABLED | TKIP_ENABLED),
    /* Open security on IBSS ad-hoc network */
    WL_SECURITY_IBSS_OPEN          = (IBSS_ENABLED),
    /* WPS with open security */
    WL_SECURITY_WPS_OPEN           = (WPS_ENABLED),
    /* WPS with AES security */
    WL_SECURITY_WPS_SECURE         = (WPS_ENABLED | AES_ENABLED),
    WL_SECURITY_UNKNOWN             = -1
} wl_security_t;
 
typedef struct
{
   uint8_t octet[WL_ETHER_ADDR_LEN];
} wl_ether_addr_t;
 
typedef struct
{
    uint8_t addr[WL_IPV4_ADDR_LEN];
} wl_ipv4_addr_t;
 
typedef struct
{
    uint32_t len;
    uint8_t value[WL_MAX_SSID_LEN];
} wl_ssid_t;
 
typedef struct
{
    wl_ssid_t ssid;             /**< Service Set Identification (i.e. Name of Access Point)                    */
    wl_ether_addr_t bssid;       /**< Basic Service Set Identification (i.e. MAC address of Access Point)       */
    uint32_t security;          /**< Security type                                                             */
    uint16_t channel;            /**< Radio channel that the AP beacon was received on                          */
    int16_t rssi;                  /**< Receive Signal Strength Indication in dBm. <-90=Very poor, >-30=Excellent */
} wl_ap_info_t;
 
typedef struct
{
    /* The intervalof send tcp packet for keepalive (keep tcp session), a decimal value, in seconds. */
    uint16_t interval;
    /* The interval of re-send tcp packet, if not receive ACK from server, a decimal value, in seconds. */
    uint16_t retry_interval;
    /* Retry count if not receive ACK from server */
    uint16_t retry_count;
    /* Destination MAC address */
    wl_ether_addr_t dst_mac;
    /* Source (Local) IP address  */
    wl_ipv4_addr_t src_ip;
    /* Destination (Remote) IP address */
    wl_ipv4_addr_t dst_ip;
    /* The starting IP frame identification number */
    uint16_t ipid;
    /* Source port */
    uint16_t srcport;
    /* Destination port */
    uint16_t dstport;
    /* Sequence number of the TCP frame */
    uint32_t seq;
    /* Acknowledge number of the TCP frame */
    uint32_t ack;
    /* TCP Window */
    uint32_t tcpwin;
   /* TCP Option Timestamp  Value */
    uint32_t tsval;
   /* TCP Option Timestamp Echo Replay */
    uint32_t tsecr;
    /* The length of the TCP Payload */
    uint16_t payload_len;
    /* TCP Payload data */
    uint8_t payload[WL_TCPKA_PAYLOAD_SIZE];
} wl_tcpka_param_t;
 
/* add supported cipher suite according rfc5246#appendix-A.5 */
typedef enum
{
   WL_TLS_RSA_WITH_AES_128_CBC_SHA     = 0x002F,
   WL_TLS_RSA_WITH_AES_256_CBC_SHA     = 0x0035
} wl_tls_cipher_suite_t;
 
typedef enum
{
   WL_TLS_COMPRESSIONMETHOD_NULL       = 0
} wl_compression_method_t;
 
typedef enum
{
   WL_TLS_CIPHER_ALGORITHM_NULL,
   WL_TLS_CIPHER_ALGORITHM_RC4,
   WL_TLS_CIPHER_ALGORITHM_3DES,
   WL_TLS_CIPHERALGORITHM_AES
} wl_tls_cipher_algorithm_t;
 
typedef enum
{
   WL_TLS_CIPHER_TYPE_STREAM = 1,
   WL_TLS_CIPHER_TYPE_BLOCK,
   WL_TLS_CIPHERTYPE_AEAD
} wl_cipher_type_t;
 
typedef enum {
   WL_TLS_MAC_ALGORITHM_NULL,
   WL_TLS_MAC_ALGORITHM_MD5,
   WL_TLS_MAC_ALGORITHM_SHA1,
   WL_TLS_MAC_ALGORITHM_SHA256,
   WL_TLS_MAC_ALGORITHM_SHA384,
   WL_TLS_MAC_ALGORITHM_SHA512
} wl_mac_algorithm_t;
 
/* Secured WOWL packet was encrypted, need decrypted before check filter match */
typedef enum
{
   WL_TLS_MODE_SECURE_WOWL,
   WL_TLS_MODE_KEEPALIVE
} wl_wowl_tls_mode_t;
 
typedef struct
{
   uint8_t major;
   uint8_t minor;
} wl_tls_protocol_version_t;
 
typedef struct
{
   wl_tls_protocol_version_t version;
   wl_compression_method_t compression_algorithm;
   wl_tls_cipher_algorithm_t cipher_algorithm;
   wl_cipher_type_t cipher_type;
   wl_mac_algorithm_t mac_algorithm;
   uint32_t keepalive_interval; /* keepalive interval, in seconds */
   uint8_t read_master_key[WL_TLS_MAX_KEY_LENGTH];
   uint32_t read_master_key_len;
   uint8_t read_iv[WL_TLS_MAX_IV_LENGTH];
   uint32_t read_iv_len;
   uint8_t read_mac_key[WL_TLS_MAX_MAC_KEY_LENGTH];
   uint32_t read_mac_key_len;
   uint8_t read_sequence[WL_TLS_MAX_SEQUENCE_LENGTH];
   uint32_t read_sequence_len;
   uint8_t write_master_key[WL_TLS_MAX_KEY_LENGTH];
   uint32_t write_master_key_len;
   uint8_t write_iv[WL_TLS_MAX_IV_LENGTH];
   uint32_t write_iv_len;
   uint8_t write_mac_key[WL_TLS_MAX_MAC_KEY_LENGTH];
   uint32_t write_mac_key_len;
   uint8_t write_sequence[WL_TLS_MAX_SEQUENCE_LENGTH];
   uint32_t write_sequence_len;
   uint32_t tcp_ack_num;
   uint32_t tcp_seq_num;
   uint8_t local_ip[WL_IPV4_ADDR_LEN];
   uint8_t remote_ip[WL_IPV4_ADDR_LEN];
   uint16_t local_port;
   uint16_t remote_port;
   uint8_t local_mac_addr[WL_ETHER_ADDR_LEN];
   uint8_t remote_mac_addr[WL_ETHER_ADDR_LEN];
   uint32_t app_syncid;
   uint8_t tls_mode;
   uint8_t payload[WL_TLS_MAX_PAYLOAD_LEN];
   uint16_t payload_len;
} wl_tls_param_t;
 
typedef void (*wl_connect_status_cb_t)(bool is_connected, void* user_data);
 
/** Initialize WL API Module
 *
 * @param[in] ifname        : Network interface name, ex. "wlan0".
 
 * @return    WL_E_OK       : Success
 *            Error code    : enum wl_err_t.
 */
extern int wl_init(const char* ifname);
 
/** Deinitialize WL API Module
 *
 * @param[in] ifname        : Network interface name, ex. "wlan0".
 
 * @return    WL_E_OK       : Success
 *            Error code    : enum wl_err_t.
 */
extern int wl_deinit(void);
extern bool wl_is_associated(void);
extern int wl_get_mac_addr(wl_ether_addr_t *mac_addr);
extern int wl_get_bssid(wl_ether_addr_t *bssid);
extern int wl_get_channel(uint32_t* channel);
extern int wl_get_rssi(int32_t* rssi);
extern int wl_join_ap(
               wl_ssid_t* ssid,
               uint32_t security,
               const int8_t* security_key,
               uint8_t key_length);
extern int wl_join_ap_specific(
               wl_ssid_t* ssid,
               uint32_t security,
               const int8_t* security_key,
               uint8_t key_length,
               wl_ether_addr_t* bssid,
               uint16_t channel);
extern int wl_disassoc(void);
extern int wl_scan(
               const wl_ssid_t* ssid,
               const wl_ether_addr_t* bssid,
               const uint16_t* channel_list,
               int32_t channel_num,
               int32_t time_per_channel);
extern int wl_get_scan_results(
                   wl_ap_info_t* ap_info,
                   uint32_t* num,
                   bool* is_completed);
extern int wl_set_powersave(bool enable);
extern int wl_set_hostsleep(bool sleep);
extern int wl_set_deepsleep(bool deepsleep);
extern int wl_wowl_enable(
               uint32_t caps,
               uint32_t match_offset,
               const int8_t* pattern,
               uint32_t pattern_size);
extern int wl_wowl_secure_enable(
                uint32_t caps,
                uint32_t match_offset,
                const int8_t* pattern,
                uint32_t pattern_size,
                wl_tls_param_t *tls_param);
extern int wl_wowl_disable(void);
extern int wl_wowl_get_wakeind(uint32_t *wakeind);
extern int wl_wowl_clear_wakeind(void);
extern int wl_wowl_tcp_rst(void);
extern int wl_tcpka_conn_enable(wl_tcpka_param_t *tcpka_param);
extern int wl_tcpka_conn_disable(void);
extern int wl_set_listen_interval(uint32_t listen_interval);
extern int wl_reset_listen_interval(void);
extern int wl_get_pre_pmk(uint8_t* buf, uint32_t len);
extern int wl_wakeup_by_ssid_start(wl_ssid_t* ssid, uint16_t interval);
extern int wl_wakeup_by_ssid_stop(void);
extern int wl_arp_offload_enable(void);
extern int wl_arp_offload_disable(void);
extern int wl_connect_status_register(wl_connect_status_cb_t callback, void* user_data);
extern int wl_connect_status_deregister(wl_connect_status_cb_t callback);
 
#endif /* __WL_H__ */