1 /*
2  * Driver interaction with Zephyr WLAN device drivers.
3  * Copyright (c) 2023, Nordic Semiconductor
4  *
5  * This software may be distributed under the terms of the BSD license.
6  * See README for more details.
7  */
8 
9 #ifndef DRIVER_ZEPHYR_H
10 #define DRIVER_ZEPHYR_H
11 
12 /* Needed when testing sample wifi driver in native_sim board */
13 #if !defined(IGNORE_ZEPHYR_INCLUDES)
14 #include <zephyr/net/wifi_mgmt.h>
15 #include <zephyr/net/ethernet.h>
16 #endif
17 
18 #include "utils/includes.h"
19 #include "driver.h"
20 #include "wpa_supplicant_i.h"
21 #include "bss.h"
22 
23 #define __WPA_SUPP_PKD __attribute__((__packed__))
24 
25 struct wpa_supp_event_channel {
26 #define WPA_SUPP_CHAN_FLAG_FREQUENCY_ATTR_NO_IR (1 << 0)
27 #define WPA_SUPP_CHAN_FLAG_FREQUENCY_ATTR_NO_IBSS (1 << 1)
28 #define WPA_SUPP_CHAN_FLAG_FREQUENCY_ATTR_RADAR (1 << 2)
29 #define WPA_SUPP_CHAN_FLAG_FREQUENCY_ATTR_NO_HT40_MINUS (1 << 3)
30 #define WPA_SUPP_CHAN_FLAG_FREQUENCY_ATTR_NO_HT40_PLUS (1 << 4)
31 #define WPA_SUPP_CHAN_FLAG_FREQUENCY_ATTR_NO_80MHZ (1 << 5)
32 #define WPA_SUPP_CHAN_FLAG_FREQUENCY_ATTR_NO_160MHZ (1 << 6)
33 #define WPA_SUPP_CHAN_FLAG_FREQUENCY_ATTR_INDOOR_ONLY (1 << 7)
34 #define WPA_SUPP_CHAN_FLAG_FREQUENCY_ATTR_GO_CONCURRENT (1 << 8)
35 #define WPA_SUPP_CHAN_FLAG_FREQUENCY_ATTR_NO_20MHZ (1 << 9)
36 #define WPA_SUPP_CHAN_FLAG_FREQUENCY_ATTR_NO_10MHZ (1 << 10)
37 #define WPA_SUPP_CHAN_FLAG_FREQUENCY_DISABLED (1 << 11)
38 
39 #define WPA_SUPP_CHAN_DFS_VALID (1 << 12)
40 #define WPA_SUPP_CHAN_DFS_CAC_TIME_VALID (1 << 13)
41 	unsigned short wpa_supp_flags;
42 	signed int wpa_supp_max_power;
43 	unsigned int wpa_supp_time;
44 	unsigned int dfs_cac_msec;
45 	signed char ch_valid;
46 	unsigned short center_frequency;
47 	signed char dfs_state;
48 } __WPA_SUPP_PKD;
49 
50 struct wpa_supp_event_rate {
51 #define WPA_SUPP_EVENT_GET_WIPHY_FLAG_RATE_SHORT_PREAMBLE (1 << 0)
52 	unsigned short wpa_supp_flags;
53 	unsigned short wpa_supp_bitrate;
54 } __WPA_SUPP_PKD;
55 
56 struct wpa_supp_event_mcs_info {
57 #define WPA_SUPP_HT_MCS_MASK_LEN 10
58 #define WPA_SUPP_HT_MCS_RES_LEN 3
59 	unsigned short wpa_supp_rx_highest;
60 	unsigned char wpa_supp_rx_mask[WPA_SUPP_HT_MCS_MASK_LEN];
61 	unsigned char wpa_supp_tx_params;
62 	unsigned char wpa_supp_reserved[WPA_SUPP_HT_MCS_RES_LEN];
63 } __WPA_SUPP_PKD;
64 
65 struct wpa_supp_event_sta_ht_cap {
66 	signed int wpa_supp_ht_supported;
67 	unsigned short wpa_supp_cap;
68 	struct wpa_supp_event_mcs_info mcs;
69 #define WPA_SUPP_AMPDU_FACTOR_MASK 0x03
70 #define WPA_SUPP_AMPDU_DENSITY_SHIFT 2
71 	unsigned char wpa_supp_ampdu_factor;
72 	unsigned char wpa_supp_ampdu_density;
73 } __WPA_SUPP_PKD;
74 
75 struct wpa_supp_event_vht_mcs_info {
76 	unsigned short rx_mcs_map;
77 	unsigned short rx_highest;
78 	unsigned short tx_mcs_map;
79 	unsigned short tx_highest;
80 } __WPA_SUPP_PKD;
81 
82 struct wpa_supp_event_sta_vht_cap {
83 	signed char wpa_supp_vht_supported;
84 	unsigned int wpa_supp_cap;
85 	struct wpa_supp_event_vht_mcs_info vht_mcs;
86 } __WPA_SUPP_PKD;
87 
88 struct wpa_supp_event_supported_band {
89 	unsigned short wpa_supp_n_channels;
90 	unsigned short wpa_supp_n_bitrates;
91 #define WPA_SUPP_SBAND_MAX_CHANNELS 29
92 #define WPA_SUPP_SBAND_MAX_RATES 13
93 	struct wpa_supp_event_channel channels[WPA_SUPP_SBAND_MAX_CHANNELS];
94 	struct wpa_supp_event_rate bitrates[WPA_SUPP_SBAND_MAX_RATES];
95 	struct wpa_supp_event_sta_ht_cap ht_cap;
96 	struct wpa_supp_event_sta_vht_cap vht_cap;
97 	signed char band;
98 } __WPA_SUPP_PKD;
99 
100 struct wpa_bss;
101 
102 struct zep_wpa_supp_mbox_msg_data {
103 	void *ctx;
104 	enum wpa_event_type event;
105 	void *data;
106 };
107 
108 
109 struct zep_drv_ctx {
110 	void *supp_ctx;
111 };
112 
113 
114 struct zep_drv_if_ctx {
115 	struct zep_drv_ctx *drv_ctx;
116 	void *supp_if_ctx;
117 	struct net_if *iface;
118 	const struct device *dev_ctx;
119 	void *dev_priv;
120 #if defined(__ZEPHYR__)
121 	struct k_sem drv_resp_sem;
122 #endif
123 
124 	struct wpa_scan_results *scan_res2;
125 	bool scan_res2_get_in_prog;
126 
127 	unsigned int freq;
128 	unsigned char ssid[SSID_MAX_LEN];
129 	size_t ssid_len;
130 	unsigned char bssid[6];
131 	bool associated;
132 	void *phy_info_arg;
133 	struct wpa_driver_capa capa;
134 
135 	unsigned char prev_bssid[6];
136 	unsigned char auth_bssid[6];
137 	unsigned char auth_attempt_bssid[6];
138 	bool beacon_set;
139 };
140 
141 
142 struct zep_wpa_supp_dev_callbk_fns {
143 	void (*scan_start)(struct zep_drv_if_ctx *if_ctx);
144 
145 	void (*scan_done)(struct zep_drv_if_ctx *if_ctx,
146 			  union wpa_event_data *event);
147 
148 	void (*scan_res)(struct zep_drv_if_ctx *if_ctx, struct wpa_scan_res *r,
149 			 bool more_res);
150 
151 	void (*auth_resp)(struct zep_drv_if_ctx *if_ctx,
152 			  union wpa_event_data *event);
153 
154 	void (*assoc_resp)(struct zep_drv_if_ctx *if_ctx,
155 			   union wpa_event_data *event, unsigned int status);
156 
157 	void (*deauth)(struct zep_drv_if_ctx *if_ctx,
158 		       union wpa_event_data *event, const struct ieee80211_mgmt *mgmt);
159 
160 	void (*disassoc)(struct zep_drv_if_ctx *if_ctx,
161 			 union wpa_event_data *event);
162 	void (*mgmt_tx_status)(struct zep_drv_if_ctx *if_ctx,
163 			const u8 *frame, size_t len, bool ack);
164 
165 	void (*unprot_deauth)(struct zep_drv_if_ctx *if_ctx,
166 			      union wpa_event_data *event);
167 
168 	void (*unprot_disassoc)(struct zep_drv_if_ctx *if_ctx,
169 				union wpa_event_data *event);
170 
171 	void (*get_wiphy_res)(struct zep_drv_if_ctx *if_ctx,
172 				void *band);
173 
174 	void (*mgmt_rx)(struct zep_drv_if_ctx *if_ctx,
175 			char *frame, int frame_len, int frequency, int rx_signal_dbm);
176 
177 	void (*mac_changed)(struct zep_drv_if_ctx *if_ctx);
178 };
179 
180 
181 struct zep_wpa_supp_dev_ops {
182 	void *(*init)(void *supp_drv_if_ctx,
183 		      const char *iface_name,
184 		      struct zep_wpa_supp_dev_callbk_fns *callbk_fns);
185 	void (*deinit)(void *if_priv);
186 	int (*scan2)(void *if_priv,
187 		     struct wpa_driver_scan_params *params);
188 	int (*scan_abort)(void *if_priv);
189 	int (*get_scan_results2)(void *if_priv);
190 	int (*deauthenticate)(void *if_priv,
191 			      const char *addr,
192 			      unsigned short reason_code);
193 	int (*authenticate)(void *if_priv,
194 			    struct wpa_driver_auth_params *params,
195 			    struct wpa_bss *curr_bss);
196 	int (*associate)(void *if_priv,
197 			 struct wpa_driver_associate_params *params);
198 	int (*set_key)(void *if_priv,
199 		       const unsigned char *ifname,
200 		       enum wpa_alg alg,
201 		       const unsigned char *addr,
202 		       int key_idx,
203 		       int set_tx,
204 		       const unsigned char *seq,
205 		       size_t seq_len,
206 		       const unsigned char *key,
207 		       size_t key_len,
208 		       enum key_flag key_flag);
209 	int (*set_supp_port)(void *if_priv,
210 			     int authorized,
211 			     char *bssid);
212 	int (*signal_poll)(void *if_priv, struct wpa_signal_info *si,
213 			   unsigned char *bssid);
214 	int (*send_mlme)(void *if_priv, const u8 *data,
215 			size_t data_len, int noack,
216 			unsigned int freq, int no_cck,
217 			int offchanok,
218 			unsigned int wait_time,
219 			int cookie);
220 	int (*get_wiphy)(void *if_priv);
221 
222 	int (*register_frame)(void *if_priv,
223 			u16 type, const u8 *match, size_t match_len,
224 			bool multicast);
225 
226 	int (*get_capa)(void *if_priv,
227 			struct wpa_driver_capa *capa);
228 
229 	int (*get_conn_info)(void *if_priv,
230 			struct wpa_conn_info *info);
231 
232 	/* AP mode (shared headers, so, skip compile time flags protection)*/
233 	int (*init_ap)(void *if_priv,
234 			struct wpa_driver_associate_params *params);
235 
236 	int (*start_ap)(void *if_priv,
237 			struct wpa_driver_ap_params *params);
238 
239 	int (*change_beacon)(void *if_priv,
240 			struct wpa_driver_ap_params *params);
241 
242 	int (*stop_ap)(void *if_priv);
243 
244 	int (*deinit_ap)(void *if_priv);
245 
246 	int (*sta_add)(void *if_priv,
247 			struct hostapd_sta_add_params *params);
248 
249 	int (*sta_remove)(void *if_priv, const u8 *addr);
250 
251 	int (*sta_set_flags)(void *if_priv, const u8 *addr,
252 			unsigned int total_flags, unsigned int flags_or,
253 			unsigned int flags_and);
254 
255 	int (*sta_clear_stats)(void *if_priv, const u8 *addr);
256 
257 	int (*register_mgmt_frame)(void *if_priv, u16 frame_type,
258 			size_t match_len, const u8 *match);
259 
260 	int (*dpp_listen)(void *priv, bool enable);
261 	int (*remain_on_channel)(void *priv, unsigned int freq, unsigned int duration);
262 	int (*cancel_remain_on_channel)(void *priv);
263 };
264 
265 #endif /* DRIVER_ZEPHYR_H */
266