1 /* 2 * Copyright (c) 2010 Broadcom Corporation 3 * 4 * Permission to use, copy, modify, and/or distribute this software for any 5 * purpose with or without fee is hereby granted, provided that the above 6 * copyright notice and this permission notice appear in all copies. 7 * 8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 11 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION 13 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 */ 16 17 #ifndef BRCMFMAC_CFG80211_H 18 #define BRCMFMAC_CFG80211_H 19 20 /* for brcmu_d11inf */ 21 #include <brcmu_d11.h> 22 23 #define WL_NUM_SCAN_MAX 10 24 #define WL_TLV_INFO_MAX 1024 25 #define WL_BSS_INFO_MAX 2048 26 #define WL_ASSOC_INFO_MAX 512 /* assoc related fil max buf */ 27 #define WL_EXTRA_BUF_MAX 2048 28 #define WL_ROAM_TRIGGER_LEVEL -75 29 #define WL_ROAM_DELTA 20 30 31 #define WL_ESCAN_BUF_SIZE (1024 * 64) 32 #define WL_ESCAN_TIMER_INTERVAL_MS 10000 /* E-Scan timeout */ 33 34 #define WL_ESCAN_ACTION_START 1 35 #define WL_ESCAN_ACTION_CONTINUE 2 36 #define WL_ESCAN_ACTION_ABORT 3 37 38 #define WL_AUTH_SHARED_KEY 1 /* d11 shared authentication */ 39 #define IE_MAX_LEN 512 40 41 /* IE TLV processing */ 42 #define TLV_LEN_OFF 1 /* length offset */ 43 #define TLV_HDR_LEN 2 /* header length */ 44 #define TLV_BODY_OFF 2 /* body offset */ 45 #define TLV_OUI_LEN 3 /* oui id length */ 46 47 /* 802.11 Mgmt Packet flags */ 48 #define BRCMF_VNDR_IE_BEACON_FLAG 0x1 49 #define BRCMF_VNDR_IE_PRBRSP_FLAG 0x2 50 #define BRCMF_VNDR_IE_ASSOCRSP_FLAG 0x4 51 #define BRCMF_VNDR_IE_AUTHRSP_FLAG 0x8 52 #define BRCMF_VNDR_IE_PRBREQ_FLAG 0x10 53 #define BRCMF_VNDR_IE_ASSOCREQ_FLAG 0x20 54 /* vendor IE in IW advertisement protocol ID field */ 55 #define BRCMF_VNDR_IE_IWAPID_FLAG 0x40 56 /* allow custom IE id */ 57 #define BRCMF_VNDR_IE_CUSTOM_FLAG 0x100 58 59 /* P2P Action Frames flags (spec ordered) */ 60 #define BRCMF_VNDR_IE_GONREQ_FLAG 0x001000 61 #define BRCMF_VNDR_IE_GONRSP_FLAG 0x002000 62 #define BRCMF_VNDR_IE_GONCFM_FLAG 0x004000 63 #define BRCMF_VNDR_IE_INVREQ_FLAG 0x008000 64 #define BRCMF_VNDR_IE_INVRSP_FLAG 0x010000 65 #define BRCMF_VNDR_IE_DISREQ_FLAG 0x020000 66 #define BRCMF_VNDR_IE_DISRSP_FLAG 0x040000 67 #define BRCMF_VNDR_IE_PRDREQ_FLAG 0x080000 68 #define BRCMF_VNDR_IE_PRDRSP_FLAG 0x100000 69 70 #define BRCMF_VNDR_IE_P2PAF_SHIFT 12 71 72 #define BRCMF_MAX_DEFAULT_KEYS 4 73 74 /* beacon loss timeout defaults */ 75 #define BRCMF_DEFAULT_BCN_TIMEOUT_ROAM_ON 2 76 #define BRCMF_DEFAULT_BCN_TIMEOUT_ROAM_OFF 4 77 78 #define BRCMF_VIF_EVENT_TIMEOUT msecs_to_jiffies(1500) 79 80 /** 81 * enum brcmf_scan_status - scan engine status 82 * 83 * @BRCMF_SCAN_STATUS_BUSY: scanning in progress on dongle. 84 * @BRCMF_SCAN_STATUS_ABORT: scan being aborted on dongle. 85 * @BRCMF_SCAN_STATUS_SUPPRESS: scanning is suppressed in driver. 86 */ 87 enum brcmf_scan_status { 88 BRCMF_SCAN_STATUS_BUSY, 89 BRCMF_SCAN_STATUS_ABORT, 90 BRCMF_SCAN_STATUS_SUPPRESS, 91 }; 92 93 /* dongle configuration */ 94 struct brcmf_cfg80211_conf { 95 u32 frag_threshold; 96 u32 rts_threshold; 97 u32 retry_short; 98 u32 retry_long; 99 }; 100 101 /* security information with currently associated ap */ 102 struct brcmf_cfg80211_security { 103 u32 wpa_versions; 104 u32 auth_type; 105 u32 cipher_pairwise; 106 u32 cipher_group; 107 u32 wpa_auth; 108 }; 109 110 /** 111 * struct brcmf_cfg80211_profile - profile information. 112 * 113 * @bssid: bssid of joined/joining ibss. 114 * @sec: security information. 115 * @key: key information 116 */ 117 struct brcmf_cfg80211_profile { 118 u8 bssid[ETH_ALEN]; 119 struct brcmf_cfg80211_security sec; 120 struct brcmf_wsec_key key[BRCMF_MAX_DEFAULT_KEYS]; 121 }; 122 123 /** 124 * enum brcmf_vif_status - bit indices for vif status. 125 * 126 * @BRCMF_VIF_STATUS_READY: ready for operation. 127 * @BRCMF_VIF_STATUS_CONNECTING: connect/join in progress. 128 * @BRCMF_VIF_STATUS_CONNECTED: connected/joined succesfully. 129 * @BRCMF_VIF_STATUS_DISCONNECTING: disconnect/disable in progress. 130 * @BRCMF_VIF_STATUS_AP_CREATED: AP operation started. 131 */ 132 enum brcmf_vif_status { 133 BRCMF_VIF_STATUS_READY, 134 BRCMF_VIF_STATUS_CONNECTING, 135 BRCMF_VIF_STATUS_CONNECTED, 136 BRCMF_VIF_STATUS_DISCONNECTING, 137 BRCMF_VIF_STATUS_AP_CREATED 138 }; 139 140 /** 141 * struct vif_saved_ie - holds saved IEs for a virtual interface. 142 * 143 * @probe_req_ie: IE info for probe request. 144 * @probe_res_ie: IE info for probe response. 145 * @beacon_ie: IE info for beacon frame. 146 * @probe_req_ie_len: IE info length for probe request. 147 * @probe_res_ie_len: IE info length for probe response. 148 * @beacon_ie_len: IE info length for beacon frame. 149 */ 150 struct vif_saved_ie { 151 u8 probe_req_ie[IE_MAX_LEN]; 152 u8 probe_res_ie[IE_MAX_LEN]; 153 u8 beacon_ie[IE_MAX_LEN]; 154 u8 assoc_req_ie[IE_MAX_LEN]; 155 u32 probe_req_ie_len; 156 u32 probe_res_ie_len; 157 u32 beacon_ie_len; 158 u32 assoc_req_ie_len; 159 }; 160 161 /** 162 * struct brcmf_cfg80211_vif - virtual interface specific information. 163 * 164 * @ifp: lower layer interface pointer 165 * @wdev: wireless device. 166 * @profile: profile information. 167 * @sme_state: SME state using enum brcmf_vif_status bits. 168 * @pm_block: power-management blocked. 169 * @list: linked list. 170 * @mgmt_rx_reg: registered rx mgmt frame types. 171 * @mbss: Multiple BSS type, set if not first AP (not relevant for P2P). 172 */ 173 struct brcmf_cfg80211_vif { 174 struct brcmf_if *ifp; 175 struct wireless_dev wdev; 176 struct brcmf_cfg80211_profile profile; 177 unsigned long sme_state; 178 bool pm_block; 179 struct vif_saved_ie saved_ie; 180 struct list_head list; 181 u16 mgmt_rx_reg; 182 bool mbss; 183 int is_11d; 184 }; 185 186 /* association inform */ 187 struct brcmf_cfg80211_connect_info { 188 u8 *req_ie; 189 s32 req_ie_len; 190 u8 *resp_ie; 191 s32 resp_ie_len; 192 }; 193 194 /* assoc ie length */ 195 struct brcmf_cfg80211_assoc_ielen_le { 196 __le32 req_len; 197 __le32 resp_len; 198 }; 199 200 /* dongle escan state */ 201 enum wl_escan_state { 202 WL_ESCAN_STATE_IDLE, 203 WL_ESCAN_STATE_SCANNING 204 }; 205 206 struct escan_info { 207 u32 escan_state; 208 u8 escan_buf[WL_ESCAN_BUF_SIZE]; 209 struct wiphy *wiphy; 210 struct brcmf_if *ifp; 211 s32 (*run)(struct brcmf_cfg80211_info *cfg, struct brcmf_if *ifp, 212 struct cfg80211_scan_request *request); 213 }; 214 215 /** 216 * struct brcmf_cfg80211_vif_event - virtual interface event information. 217 * 218 * @vif_wq: waitqueue awaiting interface event from firmware. 219 * @vif_event_lock: protects other members in this structure. 220 * @vif_complete: completion for net attach. 221 * @action: either add, change, or delete. 222 * @vif: virtual interface object related to the event. 223 */ 224 struct brcmf_cfg80211_vif_event { 225 wait_queue_head_t vif_wq; 226 struct mutex vif_event_lock; 227 u8 action; 228 struct brcmf_cfg80211_vif *vif; 229 }; 230 231 /** 232 * struct brcmf_cfg80211_wowl - wowl related information. 233 * 234 * @active: set on suspend, cleared on resume. 235 * @pre_pmmode: firmware PM mode at entering suspend. 236 * @nd: net dectect data. 237 * @nd_info: helper struct to pass to cfg80211. 238 * @nd_data_wait: wait queue to sync net detect data. 239 * @nd_data_completed: completion for net detect data. 240 * @nd_enabled: net detect enabled. 241 */ 242 struct brcmf_cfg80211_wowl { 243 bool active; 244 u32 pre_pmmode; 245 struct cfg80211_wowlan_nd_match *nd; 246 struct cfg80211_wowlan_nd_info *nd_info; 247 wait_queue_head_t nd_data_wait; 248 bool nd_data_completed; 249 bool nd_enabled; 250 }; 251 252 /** 253 * struct brcmf_cfg80211_info - dongle private data of cfg80211 interface 254 * 255 * @wiphy: wiphy object for cfg80211 interface. 256 * @conf: dongle configuration. 257 * @p2p: peer-to-peer specific information. 258 * @btcoex: Bluetooth coexistence information. 259 * @scan_request: cfg80211 scan request object. 260 * @usr_sync: mainly for dongle up/down synchronization. 261 * @bss_list: bss_list holding scanned ap information. 262 * @bss_info: bss information for cfg80211 layer. 263 * @conn_info: association info. 264 * @pmk_list: wpa2 pmk list. 265 * @scan_status: scan activity on the dongle. 266 * @pub: common driver information. 267 * @channel: current channel. 268 * @active_scan: current scan mode. 269 * @sched_escan: e-scan for scheduled scan support running. 270 * @ibss_starter: indicates this sta is ibss starter. 271 * @pwr_save: indicate whether dongle to support power save mode. 272 * @dongle_up: indicate whether dongle up or not. 273 * @roam_on: on/off switch for dongle self-roaming. 274 * @scan_tried: indicates if first scan attempted. 275 * @dcmd_buf: dcmd buffer. 276 * @extra_buf: mainly to grab assoc information. 277 * @debugfsdir: debugfs folder for this device. 278 * @escan_info: escan information. 279 * @escan_timeout: Timer for catch scan timeout. 280 * @escan_timeout_work: scan timeout worker. 281 * @escan_ioctl_buf: dongle command buffer for escan commands. 282 * @vif_list: linked list of vif instances. 283 * @vif_cnt: number of vif instances. 284 * @vif_event: vif event signalling. 285 * @wowl: wowl related information. 286 */ 287 struct brcmf_cfg80211_info { 288 struct wiphy *wiphy; 289 struct brcmf_cfg80211_conf *conf; 290 struct brcmf_p2p_info p2p; 291 struct brcmf_btcoex_info *btcoex; 292 struct cfg80211_scan_request *scan_request; 293 struct mutex usr_sync; 294 struct wl_cfg80211_bss_info *bss_info; 295 struct brcmf_cfg80211_connect_info conn_info; 296 struct brcmf_pmk_list_le pmk_list; 297 unsigned long scan_status; 298 struct brcmf_pub *pub; 299 u32 channel; 300 bool active_scan; 301 bool sched_escan; 302 bool ibss_starter; 303 bool pwr_save; 304 bool dongle_up; 305 bool scan_tried; 306 u8 *dcmd_buf; 307 u8 *extra_buf; 308 struct dentry *debugfsdir; 309 struct escan_info escan_info; 310 struct timer_list escan_timeout; 311 struct work_struct escan_timeout_work; 312 u8 *escan_ioctl_buf; 313 struct list_head vif_list; 314 struct brcmf_cfg80211_vif_event vif_event; 315 struct completion vif_disabled; 316 struct brcmu_d11inf d11inf; 317 struct brcmf_assoclist_le assoclist; 318 struct brcmf_cfg80211_wowl wowl; 319 }; 320 321 /** 322 * struct brcmf_tlv - tag_ID/length/value_buffer tuple. 323 * 324 * @id: tag identifier. 325 * @len: number of bytes in value buffer. 326 * @data: value buffer. 327 */ 328 struct brcmf_tlv { 329 u8 id; 330 u8 len; 331 u8 data[1]; 332 }; 333 334 static inline struct wiphy *cfg_to_wiphy(struct brcmf_cfg80211_info *cfg) 335 { 336 return cfg->wiphy; 337 } 338 339 static inline struct brcmf_cfg80211_info *wiphy_to_cfg(struct wiphy *w) 340 { 341 return (struct brcmf_cfg80211_info *)(wiphy_priv(w)); 342 } 343 344 static inline struct brcmf_cfg80211_info *wdev_to_cfg(struct wireless_dev *wd) 345 { 346 return (struct brcmf_cfg80211_info *)(wdev_priv(wd)); 347 } 348 349 static inline 350 struct net_device *cfg_to_ndev(struct brcmf_cfg80211_info *cfg) 351 { 352 struct brcmf_cfg80211_vif *vif; 353 vif = list_first_entry(&cfg->vif_list, struct brcmf_cfg80211_vif, list); 354 return vif->wdev.netdev; 355 } 356 357 static inline struct brcmf_cfg80211_info *ndev_to_cfg(struct net_device *ndev) 358 { 359 return wdev_to_cfg(ndev->ieee80211_ptr); 360 } 361 362 static inline struct brcmf_cfg80211_profile *ndev_to_prof(struct net_device *nd) 363 { 364 struct brcmf_if *ifp = netdev_priv(nd); 365 return &ifp->vif->profile; 366 } 367 368 static inline struct brcmf_cfg80211_vif *ndev_to_vif(struct net_device *ndev) 369 { 370 struct brcmf_if *ifp = netdev_priv(ndev); 371 return ifp->vif; 372 } 373 374 static inline struct 375 brcmf_cfg80211_connect_info *cfg_to_conn(struct brcmf_cfg80211_info *cfg) 376 { 377 return &cfg->conn_info; 378 } 379 380 struct brcmf_cfg80211_info *brcmf_cfg80211_attach(struct brcmf_pub *drvr, 381 struct device *busdev, 382 bool p2pdev_forced); 383 void brcmf_cfg80211_detach(struct brcmf_cfg80211_info *cfg); 384 s32 brcmf_cfg80211_up(struct net_device *ndev); 385 s32 brcmf_cfg80211_down(struct net_device *ndev); 386 enum nl80211_iftype brcmf_cfg80211_get_iftype(struct brcmf_if *ifp); 387 388 struct brcmf_cfg80211_vif *brcmf_alloc_vif(struct brcmf_cfg80211_info *cfg, 389 enum nl80211_iftype type, 390 bool pm_block); 391 void brcmf_free_vif(struct brcmf_cfg80211_vif *vif); 392 393 s32 brcmf_vif_set_mgmt_ie(struct brcmf_cfg80211_vif *vif, s32 pktflag, 394 const u8 *vndr_ie_buf, u32 vndr_ie_len); 395 s32 brcmf_vif_clear_mgmt_ies(struct brcmf_cfg80211_vif *vif); 396 const struct brcmf_tlv * 397 brcmf_parse_tlvs(const void *buf, int buflen, uint key); 398 u16 channel_to_chanspec(struct brcmu_d11inf *d11inf, 399 struct ieee80211_channel *ch); 400 bool brcmf_get_vif_state_any(struct brcmf_cfg80211_info *cfg, 401 unsigned long state); 402 void brcmf_cfg80211_arm_vif_event(struct brcmf_cfg80211_info *cfg, 403 struct brcmf_cfg80211_vif *vif); 404 bool brcmf_cfg80211_vif_event_armed(struct brcmf_cfg80211_info *cfg); 405 int brcmf_cfg80211_wait_vif_event_timeout(struct brcmf_cfg80211_info *cfg, 406 u8 action, ulong timeout); 407 s32 brcmf_notify_escan_complete(struct brcmf_cfg80211_info *cfg, 408 struct brcmf_if *ifp, bool aborted, 409 bool fw_abort); 410 void brcmf_set_mpc(struct brcmf_if *ndev, int mpc); 411 void brcmf_abort_scanning(struct brcmf_cfg80211_info *cfg); 412 void brcmf_cfg80211_free_netdev(struct net_device *ndev); 413 414 #endif /* BRCMFMAC_CFG80211_H */ 415