• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Winner Microelectronics Co., Ltd. All rights reserved.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef TLS_WIRELESS_H
17 #define TLS_WIRELESS_H
18 
19 #include "tls_common.h"
20 #include "wm_osal.h"
21 #include "list.h"
22 
23 struct tls_wif;
24 struct wpa_supplicant;
25 
26 /* Maximum size of the SSID  */
27 #define IW_SSID_MAX_SIZE    32
28 
29 enum ieee80211_wireless_mode {
30     IEEE80211_MODE_11B = 0,
31     IEEE80211_MODE_11G,
32     IEEE80211_MODE_11NG_HT20,
33     IEEE80211_MODE_11NG_HT40PLUS,
34     IEEE80211_MODE_11NG_HT40MINUS,
35     IEEE80211_MODE_MAX,
36 };
37 
38 #define IW_AUTH_INDEX        0x0FFF
39 #define IW_AUTH_FLAGS        0xF000
40 
41 #define IW_AUTH_WPA_VERSION        0
42 #define IW_AUTH_CIPHER_PAIRWISE        1
43 #define IW_AUTH_CIPHER_GROUP        2
44 #define IW_AUTH_KEY_MGMT        3
45 #define IW_AUTH_TKIP_COUNTERMEASURES    4
46 #define IW_AUTH_DROP_UNENCRYPTED    5
47 #define IW_AUTH_80211_AUTH_ALG        6
48 #define IW_AUTH_WPA_ENABLED        7
49 #define IW_AUTH_RX_UNENCRYPTED_EAPOL    8
50 #define IW_AUTH_ROAMING_CONTROL        9
51 #define IW_AUTH_PRIVACY_INVOKED        10
52 #define IW_AUTH_CIPHER_GROUP_MGMT    11
53 #define IW_AUTH_MFP            12
54 
55 /* IW_AUTH_WPA_VERSION values (bit field) */
56 #define IW_AUTH_WPA_VERSION_DISABLED    0x00000001
57 #define IW_AUTH_WPA_VERSION_WPA        0x00000002
58 #define IW_AUTH_WPA_VERSION_WPA2    0x00000004
59 
60 /* IW_AUTH_PAIRWISE_CIPHER, IW_AUTH_GROUP_CIPHER, and IW_AUTH_CIPHER_GROUP_MGMT
61  * values (bit field) */
62 #define IW_AUTH_CIPHER_NONE    0x00000001
63 #define IW_AUTH_CIPHER_WEP40    0x00000002
64 #define IW_AUTH_CIPHER_TKIP    0x00000004
65 #define IW_AUTH_CIPHER_CCMP    0x00000008
66 #define IW_AUTH_CIPHER_WEP104    0x00000010
67 #define IW_AUTH_CIPHER_AES_CMAC    0x00000020
68 
69 /* IW_AUTH_KEY_MGMT values (bit field) */
70 #define IW_AUTH_KEY_MGMT_802_1X    1
71 #define IW_AUTH_KEY_MGMT_PSK    2
72 
73 /* IW_AUTH_80211_AUTH_ALG values (bit field) */
74 #define IW_AUTH_ALG_OPEN_SYSTEM    0x00000001
75 #define IW_AUTH_ALG_SHARED_KEY    0x00000002
76 #define IW_AUTH_ALG_LEAP    0x00000004
77 
78 #define IW_ENCODE_ALG_NONE    0
79 #define IW_ENCODE_ALG_WEP    1
80 #define IW_ENCODE_ALG_TKIP    2
81 #define IW_ENCODE_ALG_CCMP    3
82 #define IW_ENCODE_ALG_PMK    4
83 #define IW_ENCODE_ALG_AES_CMAC    5
84 
85 #define IW_MAX_FREQUENCIES    32
86 
87 #define IW_SCAN_TYPE_ACTIVE   0
88 #define IW_SCAN_TYPE_PASSIVE  1
89 
90 struct    iw_scan_req {
91     u8        scan_type; /* IW_SCAN_TYPE_{ACTIVE,PASSIVE} */
92     u8 ssid_len;
93     u8        num_channels; /* num entries in channel_list;
94                            * 0 = scan all allowed channels */
95     u8        bssid[ETH_ALEN]; /* ff:ff:ff:ff:ff:ff for broadcast BSSID or
96                               * individual address of a specific BSS */
97 
98     u8        ssid[IW_SSID_MAX_SIZE];
99     u32     extra_ies_len;
100     u8      extra_ies[0];
101 };
102 
103 /**
104  * struct beacon_parameters - beacon parameters
105  *
106  * Used to configure the beacon for an interface.
107  *
108  * @head: head portion of beacon (before TIM IE)
109  *     or %NULL if not changed
110  * @tail: tail portion of beacon (after TIM IE)
111  *     or %NULL if not changed
112  * @interval: beacon interval or zero if not changed
113  * @dtim_period: DTIM period or zero if not changed
114  * @head_len: length of @head
115  * @tail_len: length of @tail
116  */
117 struct iw_beacon_parameters {
118     u8 *head, *tail;
119     int interval, dtim_period;
120     int head_len, tail_len;
121 };
122 
123 struct iw_ssid_params {
124     u8      ssid[IW_SSID_MAX_SIZE];
125     u8      ssid_len;
126     u32     ie_len;
127     u8      *ie;
128 };
129 
130 struct iw_key_params {
131     u8          key[32];
132     u8          tsc[32];
133     u32         key_len;
134     u32         tsc_len;
135     u16         cipher;
136     bool        pairwise;
137     bool        default_key;
138     u32         key_idx;
139     u8          addr[ETH_ALEN];
140 };
141 
142 struct iw_sta_add_params {
143     const u8 *addr;
144     u16 aid;
145     u16 capability;
146     u16 listen_interval;
147     u8  mode;
148     const u8 *supp_rates;
149     u32 supp_rates_len;
150     u32 flags; /* bitmask of WPA_STA_* flags */
151 };
152 
153 /**
154  * struct beacon_parameters - beacon parameters
155  *
156  * Used to configure the beacon for an interface.
157  *
158  * @head: head portion of beacon (before TIM IE)
159  *     or %NULL if not changed
160  * @tail: tail portion of beacon (after TIM IE)
161  *     or %NULL if not changed
162  * @interval: beacon interval or zero if not changed
163  * @dtim_period: DTIM period or zero if not changed
164  * @head_len: length of @head
165  * @tail_len: length of @tail
166  */
167 struct beacon_parameters {
168     u8 *head, *tail;
169     int interval, dtim_period;
170     int head_len, tail_len;
171 };
172 
173 struct wl_event_reload {
174     bool reload;
175 };
176 
177 struct wl_event_join_ibss_info {
178     u8  bssid[ETH_ALEN];
179     u32 freq;
180 };
181 
182 struct wl_event_mic_err {
183     u8 bssid[ETH_ALEN];
184     u8 addr[ETH_ALEN];
185     bool group_mic_err;       /* TRUE: group, FALSE: pairwise */
186 };
187 
188 struct wl_event_rx_eapol {
189     u8 *src_addr;
190     u8 *eapol_body;
191     u32 eapol_body_len;
192 #if TLS_CONFIG_AP
193     u8 mode;
194 #endif
195 };
196 
197 struct wl_event_rx_mgmt {
198     u8 *mgmt;
199     u32 mgmt_len;
200 };
201 
202 struct wl_event_rx_from_unknown {
203     u8 addr[ETH_ALEN];
204 };
205 
206 struct wl_event_assoc_info {
207     /**
208      * reassoc - Flag to indicate association or reassociation
209      */
210     int reassoc;
211 
212     /**
213      * req_ies - (Re)Association Request IEs
214      *
215      * If the driver generates WPA/RSN IE, this event data must be
216      * returned for WPA handshake to have needed information. If
217      * wpa_supplicant-generated WPA/RSN IE is used, this
218      * information event is optional.
219      *
220      * This should start with the first IE (fixed fields before IEs
221      * are not included).
222      */
223     const u8 *req_ies;
224 
225     /**
226      * req_ies_len - Length of req_ies in bytes
227      */
228     u32 req_ies_len;
229 
230     /**
231      * resp_ies - (Re)Association Response IEs
232      *
233      * Optional association data from the driver. This data is not
234      * required WPA, but may be useful for some protocols and as
235      * such, should be reported if this is available to the driver
236      * interface.
237      *
238      * This should start with the first IE (fixed fields before IEs
239      * are not included).
240      */
241     u8 *resp_ies;
242 
243     /**
244      * resp_ies_len - Length of resp_ies in bytes
245      */
246     u32 resp_ies_len;
247 
248     /**
249      * addr - Station address (for AP mode)
250      */
251     u8 *addr;
252 
253     u8 *bssid;
254 
255     /**
256      * freq - Frequency of the operational channel in MHz
257      */
258     unsigned int freq;
259 };
260 
261 struct tls_wl_event_ops {
262     int (*ibss_joined)(struct tls_wif *wif,
263             struct wl_event_join_ibss_info *info);
264     int (*assoc)(struct tls_wif *wif,
265             struct wl_event_assoc_info *info);
266     int (*disassoc)(struct tls_wif *wif);
267     int (*scan_completed)(struct tls_wif *wif);
268     int (*mic_err)(struct tls_wif *wif,
269             struct wl_event_mic_err *info);
270     int (*rx_eapol)(struct tls_wif *wif,
271             struct wl_event_rx_eapol *eapol);
272     int (*rx_mgmt)(struct tls_wif *wif,
273             struct wl_event_rx_mgmt *mgmt);
274     int (*mac_wdg)(struct tls_wif *wif);
275     int (*chip_wakeup)(struct tls_wif *wif);
276 #if TLS_CONFIG_AP_OPT_PS
277     int (*beacon_done)(struct tls_wif *wif);
278     int (*rx_ps)(struct tls_wif *wif,
279             struct wl_event_rx_mgmt *mgmt);
280     int (*rx_pspoll)(struct tls_wif *wif,
281             struct wl_event_rx_from_unknown *rx_pspoll);
282     int (*sta_active)(struct tls_wif *wif,
283             struct wl_event_rx_from_unknown *rx_pspoll);
284 #endif
285     int (*rx_from_unknown_sta)(struct tls_wif *wif,
286             struct wl_event_rx_from_unknown *rx_from_unknown);
287     int (*net_down)(struct tls_wif *wif);
288     int (*net_fail)(struct tls_wif *wif);
289     int (*net_up)(struct tls_wif *wif);
290     int (*update_stat)(struct tls_wif *wif, void *cur_bss); /* struct ieee80211_bss *cur_bss */
291 };
292 
293 /* sk_buff allocated by wlan driver  */
294 struct sk_buff {
295     struct dl_list list;
296     u8   *buf;
297     u32   buf_len;
298     u32   flags;
299 };
300 
301 struct tls_wif {
302     struct ieee80211_if_data *priv;
303     struct wpa_supplicant *wpa_s;
304     struct tls_wl_event_ops *ops;
305 #if TLS_CONFIG_SOFTAP_11N
306     struct hostapd_iface *apif;
307 #endif
308 
309     bool   wlan_create;
310     int (*rx_data_cb)(const u8 *bssid, u8 *buf, u32 buf_len);
311 #if TLS_CONFIG_AP
312     bool   wmm_set;
313     void  *client_event_callback;
314 #if TLS_CONFIG_AP_OPT_FWD
315     int (*rx_ip_cb)(const u8 *bssid, u8 *buf, u32 buf_len);
316 #endif
317 #endif
318 };
319 
320 void tls_wl_print_stats(struct tls_wif *wif);
321 
322 int tls_wl_if_scan(struct tls_wif *wif,
323     struct iw_scan_req *scan_req, u16 size);
324 int tls_wl_if_scan_result2(struct tls_wif *wif,
325     u8 *ssid, u32 ssid_len, u8 *buf, u32 buf_size);
326 int tls_wl_if_scan_result(struct tls_wif *wif,  u8 *buf, u32 buf_size);
327 void tls_wl_if_sta_flush(struct tls_wif *wif, u8 mode);
328 int tls_wl_if_sta_deauth(struct tls_wif *wif, u8 *own_addr,
329     const u8 *addr, int reason);
330 int tls_wl_if_sta_disassoc(struct tls_wif *wif, u8 *own_addr,
331     const u8 *addr, int reason);
332 #if TLS_CONFIG_AP
333 int tls_wl_if_set_tx_queue_params(struct tls_wif *wif, int queue,
334     int aifs, int cw_min, int cw_max, int burst_time);
335 void tls_wl_if_set_sta_flags(struct tls_wif *wif, u8 *addr, u32 flags);
336 int tls_wl_if_send_channel_switch(struct tls_wif *wif, u8 *ownaddr, u8 newch);
337 void tls_wl_if_switch_channel_width(struct tls_wif *wif, u8 *ownaddr);
338 void tls_wl_if_channel_info_updata(struct tls_wif *wif);
339 #if TLS_CONFIG_SOFTAP_11N
340 void tls_wl_if_get_ht_param(struct tls_wif *wif, u16 *cap, u8 *mcs, u8 *mpdu);
341 void tls_wl_if_set_sta_ht_param(struct tls_wif *wif, u8 *mac, u8 *ht);
342 #endif
343 #endif
344 int tls_wl_if_set_mode(struct tls_wif *wif, u16 mode);
345 int tls_wl_if_clear_mode(struct tls_wif *wif, u16 mode);
346 int tls_wl_if_set_bssid(struct tls_wif *wif, const u8 *addr, u32 mode);
347 int tls_wl_if_set_ssid(struct tls_wif *wif, struct iw_ssid_params *params);
348 int tls_wl_if_set_auth(struct tls_wif *wif, u16 flag, u32 value, u8 mode);
349 int tls_wl_if_set_ps_mode(struct tls_wif *wif, int powersave);
350 int tls_wl_if_set_freq(struct tls_wif *wif,
351     int freq);
352 int tls_wl_if_send_eapol(struct tls_wif *wif,
353     u8 *buf, u32 len, bool is_apsta);
354 int tls_wl_if_xmit(struct tls_wif *wif, void *buf, int len, bool is_apsta, bool not_delay);
355 int tls_wl_if_add_key(struct tls_wif *wif,
356     struct iw_key_params *params);
357 int tls_wl_if_remove_key(struct tls_wif *wif,
358                          u32 cipher,
359                          u32 key_idx,
360                          bool pairwise,
361                          u8 *addr);
362 int tls_wl_if_send_mlme(struct tls_wif *wif,
363     u8 *buf, u32 len);
364 int tls_wl_if_set_rate_mode(struct tls_wif *wif,
365     u32 rate_mode);
366 int tls_wl_if_set_beacon(struct tls_wif *wif,
367     struct iw_beacon_parameters *params);
368 int tls_wl_if_del_beacon(struct tls_wif *wif);
369 int tls_wl_if_sta_add(struct tls_wif *wif,
370     struct iw_sta_add_params *params);
371 int tls_wl_if_sta_remove(struct tls_wif *wif, u8 *addr);
372 int tls_wl_if_get_inact_sec(struct tls_wif *wif, const u8 *addr);
373 int tls_wl_if_get_scan_res(struct tls_wif *wif, u8 *buf, u32 buf_size);
374 int tls_wl_if_disconnect(struct tls_wif *wif);
375 int tls_wl_if_tx(struct tls_wif *wif,
376     u8 *buf, u32 buflen, bool last_packet, bool is_apsta, bool not_delay);
377 int tls_wl_if_set_max_rate(struct tls_wif *wif, u8 max_rate_idx);
378 int tls_wl_if_get_max_rate(struct tls_wif *wif, u8 *max_rate_idx);
379 #if TLS_CONFIG_IBSS
380 int tls_wl_if_set_adhoc(struct tls_wif *wif, int adhoc_automode);
381 #endif
382 int tls_wl_if_ps(int wake_up);
383 void tls_wl_if_set_errno(int eno);
384 int  tls_wl_if_get_errno(void);
385 void  tls_wl_if_perror(const char *info);
386 const char *tls_wl_if_get_errinfo(int eno);
387 #endif /* end of TLS_WIRELESS_H */
388