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 121 struct wpa_scan_results *scan_res2; 122 bool scan_res2_get_in_prog; 123 124 unsigned int assoc_freq; 125 unsigned char ssid[SSID_MAX_LEN]; 126 size_t ssid_len; 127 unsigned char bssid[6]; 128 bool associated; 129 130 void *phy_info_arg; 131 bool get_wiphy_in_progress; 132 }; 133 134 135 struct zep_wpa_supp_dev_callbk_fns { 136 void (*scan_start)(struct zep_drv_if_ctx *if_ctx); 137 138 void (*scan_done)(struct zep_drv_if_ctx *if_ctx, 139 union wpa_event_data *event); 140 141 void (*scan_res)(struct zep_drv_if_ctx *if_ctx, struct wpa_scan_res *r, 142 bool more_res); 143 144 void (*auth_resp)(struct zep_drv_if_ctx *if_ctx, 145 union wpa_event_data *event); 146 147 void (*assoc_resp)(struct zep_drv_if_ctx *if_ctx, 148 union wpa_event_data *event, unsigned int status); 149 150 void (*deauth)(struct zep_drv_if_ctx *if_ctx, 151 union wpa_event_data *event); 152 153 void (*disassoc)(struct zep_drv_if_ctx *if_ctx, 154 union wpa_event_data *event); 155 156 void (*mgmt_tx_status)(struct zep_drv_if_ctx *if_ctx, 157 const u8 *frame, size_t len, bool ack); 158 159 void (*unprot_deauth)(struct zep_drv_if_ctx *if_ctx, 160 union wpa_event_data *event); 161 162 void (*unprot_disassoc)(struct zep_drv_if_ctx *if_ctx, 163 union wpa_event_data *event); 164 165 void (*get_wiphy_res)(struct zep_drv_if_ctx *if_ctx, 166 void *band); 167 168 void (*mgmt_rx)(struct zep_drv_if_ctx *if_ctx, 169 char *frame, int frame_len, int frequency, int rx_signal_dbm); 170 }; 171 172 173 struct zep_wpa_supp_dev_ops { 174 void *(*init)(void *supp_drv_if_ctx, 175 const char *iface_name, 176 struct zep_wpa_supp_dev_callbk_fns *callbk_fns); 177 void (*deinit)(void *if_priv); 178 int (*scan2)(void *if_priv, 179 struct wpa_driver_scan_params *params); 180 int (*scan_abort)(void *if_priv); 181 int (*get_scan_results2)(void *if_priv); 182 int (*deauthenticate)(void *if_priv, 183 const char *addr, 184 unsigned short reason_code); 185 int (*authenticate)(void *if_priv, 186 struct wpa_driver_auth_params *params, 187 struct wpa_bss *curr_bss); 188 int (*associate)(void *if_priv, 189 struct wpa_driver_associate_params *params); 190 int (*set_key)(void *if_priv, 191 const unsigned char *ifname, 192 enum wpa_alg alg, 193 const unsigned char *addr, 194 int key_idx, 195 int set_tx, 196 const unsigned char *seq, 197 size_t seq_len, 198 const unsigned char *key, 199 size_t key_len); 200 int (*set_supp_port)(void *if_priv, 201 int authorized, 202 char *bssid); 203 int (*signal_poll)(void *if_priv, struct wpa_signal_info *si, 204 unsigned char *bssid); 205 int (*send_mlme)(void *if_priv, const u8 *data, 206 size_t data_len, int noack, 207 unsigned int freq, int no_cck, 208 int offchanok, 209 unsigned int wait_time, 210 int cookie); 211 int (*get_wiphy)(void *if_priv); 212 213 int (*register_frame)(void *if_priv, 214 u16 type, const u8 *match, size_t match_len, 215 bool multicast); 216 217 int (*get_capa)(void *if_priv, 218 struct wpa_driver_capa *capa); 219 220 int (*get_conn_info)(void *if_priv, 221 struct wpa_conn_info *info); 222 }; 223 224 #endif /* DRIVER_ZEPHYR_H */ 225