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 #ifdef CONFIG_WIFI_NM_HOSTAPD_AP 23 #include "hostapd.h" 24 #endif 25 26 #define __WPA_SUPP_PKD __attribute__((__packed__)) 27 28 struct wpa_supp_event_channel { 29 #define WPA_SUPP_CHAN_FLAG_FREQUENCY_ATTR_NO_IR (1 << 0) 30 #define WPA_SUPP_CHAN_FLAG_FREQUENCY_ATTR_NO_IBSS (1 << 1) 31 #define WPA_SUPP_CHAN_FLAG_FREQUENCY_ATTR_RADAR (1 << 2) 32 #define WPA_SUPP_CHAN_FLAG_FREQUENCY_ATTR_NO_HT40_MINUS (1 << 3) 33 #define WPA_SUPP_CHAN_FLAG_FREQUENCY_ATTR_NO_HT40_PLUS (1 << 4) 34 #define WPA_SUPP_CHAN_FLAG_FREQUENCY_ATTR_NO_80MHZ (1 << 5) 35 #define WPA_SUPP_CHAN_FLAG_FREQUENCY_ATTR_NO_160MHZ (1 << 6) 36 #define WPA_SUPP_CHAN_FLAG_FREQUENCY_ATTR_INDOOR_ONLY (1 << 7) 37 #define WPA_SUPP_CHAN_FLAG_FREQUENCY_ATTR_GO_CONCURRENT (1 << 8) 38 #define WPA_SUPP_CHAN_FLAG_FREQUENCY_ATTR_NO_20MHZ (1 << 9) 39 #define WPA_SUPP_CHAN_FLAG_FREQUENCY_ATTR_NO_10MHZ (1 << 10) 40 #define WPA_SUPP_CHAN_FLAG_FREQUENCY_DISABLED (1 << 11) 41 42 #define WPA_SUPP_CHAN_DFS_VALID (1 << 12) 43 #define WPA_SUPP_CHAN_DFS_CAC_TIME_VALID (1 << 13) 44 unsigned short wpa_supp_flags; 45 signed int wpa_supp_max_power; 46 unsigned int wpa_supp_time; 47 unsigned int dfs_cac_msec; 48 signed char ch_valid; 49 unsigned short center_frequency; 50 signed char dfs_state; 51 } __WPA_SUPP_PKD; 52 53 struct wpa_supp_event_rate { 54 #define WPA_SUPP_EVENT_GET_WIPHY_FLAG_RATE_SHORT_PREAMBLE (1 << 0) 55 unsigned short wpa_supp_flags; 56 unsigned short wpa_supp_bitrate; 57 } __WPA_SUPP_PKD; 58 59 struct wpa_supp_event_mcs_info { 60 #define WPA_SUPP_HT_MCS_MASK_LEN 10 61 #define WPA_SUPP_HT_MCS_RES_LEN 3 62 unsigned short wpa_supp_rx_highest; 63 unsigned char wpa_supp_rx_mask[WPA_SUPP_HT_MCS_MASK_LEN]; 64 unsigned char wpa_supp_tx_params; 65 unsigned char wpa_supp_reserved[WPA_SUPP_HT_MCS_RES_LEN]; 66 } __WPA_SUPP_PKD; 67 68 struct wpa_supp_event_sta_ht_cap { 69 signed int wpa_supp_ht_supported; 70 unsigned short wpa_supp_cap; 71 struct wpa_supp_event_mcs_info mcs; 72 #define WPA_SUPP_AMPDU_FACTOR_MASK 0x03 73 #define WPA_SUPP_AMPDU_DENSITY_SHIFT 2 74 unsigned char wpa_supp_ampdu_factor; 75 unsigned char wpa_supp_ampdu_density; 76 } __WPA_SUPP_PKD; 77 78 struct wpa_supp_event_vht_mcs_info { 79 unsigned short rx_mcs_map; 80 unsigned short rx_highest; 81 unsigned short tx_mcs_map; 82 unsigned short tx_highest; 83 } __WPA_SUPP_PKD; 84 85 struct wpa_supp_event_sta_vht_cap { 86 signed char wpa_supp_vht_supported; 87 unsigned int wpa_supp_cap; 88 struct wpa_supp_event_vht_mcs_info vht_mcs; 89 } __WPA_SUPP_PKD; 90 91 struct wpa_supp_event_sta_he_cap { 92 signed char wpa_supp_he_supported; 93 unsigned char phy_cap[HE_MAX_PHY_CAPAB_SIZE]; 94 unsigned char mac_cap[HE_MAX_MAC_CAPAB_SIZE]; 95 unsigned char mcs[HE_MAX_MCS_CAPAB_SIZE]; 96 unsigned char ppet[HE_MAX_PPET_CAPAB_SIZE]; 97 unsigned short he_6ghz_capa; 98 } __WPA_SUPP_PKD; 99 100 struct wpa_supp_event_supported_band { 101 unsigned short wpa_supp_n_channels; 102 unsigned short wpa_supp_n_bitrates; 103 #define WPA_SUPP_SBAND_MAX_CHANNELS 29 104 #define WPA_SUPP_SBAND_MAX_RATES 13 105 struct wpa_supp_event_channel channels[WPA_SUPP_SBAND_MAX_CHANNELS]; 106 struct wpa_supp_event_rate bitrates[WPA_SUPP_SBAND_MAX_RATES]; 107 struct wpa_supp_event_sta_ht_cap ht_cap; 108 struct wpa_supp_event_sta_vht_cap vht_cap; 109 struct wpa_supp_event_sta_he_cap he_cap; 110 signed char band; 111 } __WPA_SUPP_PKD; 112 113 struct wpa_bss; 114 115 struct zep_wpa_supp_mbox_msg_data { 116 void *ctx; 117 enum wpa_event_type event; 118 void *data; 119 }; 120 121 122 struct zep_drv_ctx { 123 void *supp_ctx; 124 }; 125 126 127 struct zep_drv_if_ctx { 128 struct zep_drv_ctx *drv_ctx; 129 void *supp_if_ctx; 130 struct net_if *iface; 131 const struct device *dev_ctx; 132 void *dev_priv; 133 #if defined(__ZEPHYR__) 134 struct k_sem drv_resp_sem; 135 #endif 136 137 struct wpa_scan_results *scan_res2; 138 bool scan_res2_get_in_prog; 139 140 bool ft_roaming; 141 bool roaming; 142 143 unsigned int freq; 144 unsigned char ssid[SSID_MAX_LEN]; 145 size_t ssid_len; 146 unsigned char bssid[6]; 147 bool associated; 148 void *phy_info_arg; 149 struct wpa_driver_capa capa; 150 151 unsigned char prev_bssid[6]; 152 unsigned char auth_bssid[6]; 153 unsigned char auth_attempt_bssid[6]; 154 bool beacon_set; 155 #ifdef CONFIG_WIFI_NM_HOSTAPD_AP 156 struct zep_wpa_supp_dev_ops *dev_ops; 157 struct hostapd_data *hapd; 158 int is_ap; 159 bool survey_res_get_in_prog; 160 union wpa_event_data *data; 161 #endif 162 }; 163 164 165 struct zep_wpa_supp_dev_callbk_fns { 166 void (*scan_start)(struct zep_drv_if_ctx *if_ctx); 167 168 void (*scan_done)(struct zep_drv_if_ctx *if_ctx, 169 union wpa_event_data *event); 170 171 void (*scan_res)(struct zep_drv_if_ctx *if_ctx, struct wpa_scan_res *r, 172 bool more_res); 173 174 void (*auth_resp)(struct zep_drv_if_ctx *if_ctx, 175 union wpa_event_data *event); 176 177 void (*assoc_resp)(struct zep_drv_if_ctx *if_ctx, 178 union wpa_event_data *event, unsigned int status); 179 180 void (*deauth)(struct zep_drv_if_ctx *if_ctx, 181 union wpa_event_data *event, const struct ieee80211_mgmt *mgmt); 182 183 void (*disassoc)(struct zep_drv_if_ctx *if_ctx, 184 union wpa_event_data *event); 185 void (*mgmt_tx_status)(struct zep_drv_if_ctx *if_ctx, 186 const u8 *frame, size_t len, bool ack); 187 188 void (*unprot_deauth)(struct zep_drv_if_ctx *if_ctx, 189 union wpa_event_data *event); 190 191 void (*unprot_disassoc)(struct zep_drv_if_ctx *if_ctx, 192 union wpa_event_data *event); 193 194 void (*get_wiphy_res)(struct zep_drv_if_ctx *if_ctx, 195 void *band); 196 197 void (*mgmt_rx)(struct zep_drv_if_ctx *if_ctx, 198 char *frame, int frame_len, int frequency, int rx_signal_dbm); 199 200 void (*chan_list_changed)(struct zep_drv_if_ctx *if_ctx, 201 union wpa_event_data *event); 202 203 void (*mac_changed)(struct zep_drv_if_ctx *if_ctx); 204 205 void (*ecsa_complete)(struct zep_drv_if_ctx *if_ctx, 206 union wpa_event_data *event); 207 208 void (*dfs_cac_started)(struct zep_drv_if_ctx *if_ctx, 209 union wpa_event_data *event); 210 211 void (*dfs_cac_finished)(struct zep_drv_if_ctx *if_ctx, 212 union wpa_event_data *event); 213 214 void (*signal_change)(struct zep_drv_if_ctx *if_ctx, 215 union wpa_event_data *event); 216 }; 217 218 struct zep_hostapd_dev_callbk_fns 219 { 220 void (*mac_changed)(struct zep_drv_if_ctx *if_ctx); 221 222 void (*chan_list_changed)(struct zep_drv_if_ctx *if_ctx, 223 union wpa_event_data *event); 224 225 void (*scan_done)(struct zep_drv_if_ctx *if_ctx, 226 union wpa_event_data *event); 227 228 void (*survey_res)(struct zep_drv_if_ctx *if_ctx, 229 struct freq_survey *survey, bool more_res); 230 231 void (*acs_channel_sel)(struct zep_drv_if_ctx *if_ctx, 232 union wpa_event_data *event); 233 234 void (*mgmt_rx)(struct zep_drv_if_ctx *if_ctx, 235 char *frame, int frame_len, int frequency, int rx_signal_dbm); 236 237 void (*eapol_rx)(struct zep_drv_if_ctx *if_ctx, 238 union wpa_event_data *event); 239 240 void (*mgmt_tx_status)(struct zep_drv_if_ctx *if_ctx, 241 const u8 *frame, size_t len, bool ack); 242 243 void (*ecsa_complete)(struct zep_drv_if_ctx *if_ctx, 244 union wpa_event_data *event); 245 246 void (*dfs_cac_started)(struct zep_drv_if_ctx *if_ctx, 247 union wpa_event_data *event); 248 249 void (*dfs_cac_finished)(struct zep_drv_if_ctx *if_ctx, 250 union wpa_event_data *event); 251 252 void (*get_wiphy_res)(struct zep_drv_if_ctx *if_ctx, 253 void *band); 254 }; 255 256 struct zep_wpa_supp_dev_ops { 257 void *(*init)(void *supp_drv_if_ctx, 258 const char *iface_name, 259 struct zep_wpa_supp_dev_callbk_fns *callbk_fns); 260 void (*deinit)(void *if_priv); 261 int (*scan2)(void *if_priv, 262 struct wpa_driver_scan_params *params); 263 int (*scan_abort)(void *if_priv); 264 int (*get_scan_results2)(void *if_priv); 265 int (*deauthenticate)(void *if_priv, 266 const char *addr, 267 unsigned short reason_code); 268 int (*authenticate)(void *if_priv, 269 struct wpa_driver_auth_params *params, 270 struct wpa_bss *curr_bss); 271 int (*associate)(void *if_priv, 272 struct wpa_driver_associate_params *params); 273 int (*set_key)(void *if_priv, 274 const unsigned char *ifname, 275 enum wpa_alg alg, 276 const unsigned char *addr, 277 int key_idx, 278 int set_tx, 279 const unsigned char *seq, 280 size_t seq_len, 281 const unsigned char *key, 282 size_t key_len, 283 enum key_flag key_flag); 284 int (*set_supp_port)(void *if_priv, 285 int authorized, 286 char *bssid); 287 int (*signal_poll)(void *if_priv, struct wpa_signal_info *si, 288 unsigned char *bssid); 289 int (*send_mlme)(void *if_priv, const u8 *data, 290 size_t data_len, int noack, 291 unsigned int freq, int no_cck, 292 int offchanok, 293 unsigned int wait_time, 294 int cookie); 295 int (*get_wiphy)(void *if_priv); 296 297 int (*register_frame)(void *if_priv, 298 u16 type, const u8 *match, size_t match_len, 299 bool multicast); 300 301 int (*get_capa)(void *if_priv, 302 struct wpa_driver_capa *capa); 303 304 int (*get_conn_info)(void *if_priv, 305 struct wpa_conn_info *info); 306 307 int (*set_country)(void *priv, const char *alpha2); 308 309 int (*get_country)(void *priv, char *alpha2); 310 311 /* AP mode (shared headers, so, skip compile time flags protection)*/ 312 void *(*hapd_init)(void *hapd_drv_if_ctx, const char *iface_name, 313 struct zep_hostapd_dev_callbk_fns *hostapd_callbk_fns); 314 315 void (*hapd_deinit)(void *priv); 316 317 int (*set_ap)(void *priv, int beacon_set, 318 struct wpa_driver_ap_params *params); 319 320 int (*do_acs)(void *priv, struct drv_acs_params *params); 321 322 int (*init_ap)(void *if_priv, 323 struct wpa_driver_associate_params *params); 324 325 int (*start_ap)(void *if_priv, 326 struct wpa_driver_ap_params *params); 327 328 int (*change_beacon)(void *if_priv, 329 struct wpa_driver_ap_params *params); 330 331 int (*stop_ap)(void *if_priv); 332 333 int (*deinit_ap)(void *if_priv); 334 335 int (*sta_add)(void *if_priv, 336 struct hostapd_sta_add_params *params); 337 338 int (*sta_remove)(void *if_priv, const u8 *addr); 339 340 int (*sta_set_flags)(void *if_priv, const u8 *addr, 341 unsigned int total_flags, unsigned int flags_or, 342 unsigned int flags_and); 343 344 int (*sta_clear_stats)(void *if_priv, const u8 *addr); 345 346 int (*register_mgmt_frame)(void *if_priv, u16 frame_type, 347 size_t match_len, const u8 *match); 348 349 int (*dpp_listen)(void *priv, bool enable); 350 int (*remain_on_channel)(void *priv, unsigned int freq, unsigned int duration); 351 int (*cancel_remain_on_channel)(void *priv); 352 int (*get_inact_sec)(void *if_priv, const u8 *addr); 353 void (*send_action_cancel_wait)(void *priv); 354 }; 355 356 #endif /* DRIVER_ZEPHYR_H */ 357