1/* 2 * Linux cfg80211 driver 3 * 4 * Copyright (C) 1999-2012, Broadcom Corporation 5 * 6 * Unless you and Broadcom execute a separate written software license 7 * agreement governing use of this software, this software is licensed to you 8 * under the terms of the GNU General Public License version 2 (the "GPL"), 9 * available at http://www.broadcom.com/licenses/GPLv2.php, with the 10 * following added to such license: 11 * 12 * As a special exception, the copyright holders of this software give you 13 * permission to link this software with independent modules, and to copy and 14 * distribute the resulting executable under terms of your choice, provided that 15 * you also meet, for each linked independent module, the terms and conditions of 16 * the license of that module. An independent module is a module which is not 17 * derived from this software. The special exception does not apply to any 18 * modifications of the software. 19 * 20 * Notwithstanding the above, under no circumstances may you combine this 21 * software in any way with any other Broadcom software provided under a license 22 * other than the GPL, without Broadcom's express prior written consent. 23 * 24 * $Id: wl_cfg80211.h 307885 2012-01-12 23:30:48Z $ 25 */ 26 27#ifndef _wl_cfg80211_h_ 28#define _wl_cfg80211_h_ 29 30#include <linux/wireless.h> 31#include <typedefs.h> 32#include <proto/ethernet.h> 33#include <wlioctl.h> 34#include <linux/wireless.h> 35#include <net/cfg80211.h> 36#include <linux/rfkill.h> 37 38#include <wl_cfgp2p.h> 39 40struct wl_conf; 41struct wl_iface; 42struct wl_priv; 43struct wl_security; 44struct wl_ibss; 45 46 47#define htod32(i) i 48#define htod16(i) i 49#define dtoh32(i) i 50#define dtoh16(i) i 51#define htodchanspec(i) i 52#define dtohchanspec(i) i 53 54#define WL_DBG_NONE 0 55#define WL_DBG_TRACE (1 << 4) 56#define WL_DBG_SCAN (1 << 3) 57#define WL_DBG_DBG (1 << 2) 58#define WL_DBG_INFO (1 << 1) 59#define WL_DBG_ERR (1 << 0) 60 61/* 0 invalidates all debug messages. default is 1 */ 62#define WL_DBG_LEVEL 0xFF 63 64#define WL_ERR(args) \ 65do { \ 66 if (wl_dbg_level & WL_DBG_ERR) { \ 67 printk(KERN_ERR "CFG80211-ERROR) %s : ", __func__); \ 68 printk args; \ 69 } \ 70} while (0) 71#ifdef WL_INFO 72#undef WL_INFO 73#endif 74#define WL_INFO(args) \ 75do { \ 76 if (wl_dbg_level & WL_DBG_INFO) { \ 77 printk(KERN_ERR "CFG80211-INFO) %s : ", __func__); \ 78 printk args; \ 79 } \ 80} while (0) 81#ifdef WL_SCAN 82#undef WL_SCAN 83#endif 84#define WL_SCAN(args) \ 85do { \ 86 if (wl_dbg_level & WL_DBG_SCAN) { \ 87 printk(KERN_ERR "CFG80211-SCAN) %s :", __func__); \ 88 printk args; \ 89 } \ 90} while (0) 91#ifdef WL_TRACE 92#undef WL_TRACE 93#endif 94#define WL_TRACE(args) \ 95do { \ 96 if (wl_dbg_level & WL_DBG_TRACE) { \ 97 printk(KERN_ERR "CFG80211-TRACE) %s :", __func__); \ 98 printk args; \ 99 } \ 100} while (0) 101#if (WL_DBG_LEVEL > 0) 102#define WL_DBG(args) \ 103do { \ 104 if (wl_dbg_level & WL_DBG_DBG) { \ 105 printk(KERN_ERR "CFG80211-DEBUG) %s :", __func__); \ 106 printk args; \ 107 } \ 108} while (0) 109#else /* !(WL_DBG_LEVEL > 0) */ 110#define WL_DBG(args) 111#endif /* (WL_DBG_LEVEL > 0) */ 112 113 114#define WL_SCAN_RETRY_MAX 3 115#define WL_NUM_PMKIDS_MAX MAXPMKID 116#define WL_SCAN_BUF_MAX (1024 * 8) 117#define WL_TLV_INFO_MAX 1024 118#define WL_SCAN_IE_LEN_MAX 2048 119#define WL_BSS_INFO_MAX 2048 120#define WL_ASSOC_INFO_MAX 512 121#define WL_IOCTL_LEN_MAX 1024 122#define WL_EXTRA_BUF_MAX 2048 123#define WL_ISCAN_BUF_MAX 2048 124#define WL_ISCAN_TIMER_INTERVAL_MS 3000 125#define WL_SCAN_ERSULTS_LAST (WL_SCAN_RESULTS_NO_MEM+1) 126#define WL_AP_MAX 256 127#define WL_FILE_NAME_MAX 256 128#define WL_DWELL_TIME 200 129#define WL_MED_DWELL_TIME 400 130#define WL_LONG_DWELL_TIME 1000 131#define IFACE_MAX_CNT 2 132 133#define WL_SCAN_TIMER_INTERVAL_MS 8000 /* Scan timeout */ 134#define WL_CHANNEL_SYNC_RETRY 5 135#define WL_INVALID -1 136 137/* driver status */ 138enum wl_status { 139 WL_STATUS_READY = 0, 140 WL_STATUS_SCANNING, 141 WL_STATUS_SCAN_ABORTING, 142 WL_STATUS_CONNECTING, 143 WL_STATUS_CONNECTED, 144 WL_STATUS_DISCONNECTING, 145 WL_STATUS_AP_CREATING, 146 WL_STATUS_AP_CREATED, 147 WL_STATUS_SENDING_ACT_FRM 148}; 149 150/* wi-fi mode */ 151enum wl_mode { 152 WL_MODE_BSS, 153 WL_MODE_IBSS, 154 WL_MODE_AP 155}; 156 157/* driver profile list */ 158enum wl_prof_list { 159 WL_PROF_MODE, 160 WL_PROF_SSID, 161 WL_PROF_SEC, 162 WL_PROF_IBSS, 163 WL_PROF_BAND, 164 WL_PROF_BSSID, 165 WL_PROF_ACT, 166 WL_PROF_BEACONINT, 167 WL_PROF_DTIMPERIOD 168}; 169 170/* driver iscan state */ 171enum wl_iscan_state { 172 WL_ISCAN_STATE_IDLE, 173 WL_ISCAN_STATE_SCANING 174}; 175 176/* donlge escan state */ 177enum wl_escan_state { 178 WL_ESCAN_STATE_IDLE, 179 WL_ESCAN_STATE_SCANING 180}; 181/* fw downloading status */ 182enum wl_fw_status { 183 WL_FW_LOADING_DONE, 184 WL_NVRAM_LOADING_DONE 185}; 186 187enum wl_management_type { 188 WL_BEACON = 0x1, 189 WL_PROBE_RESP = 0x2, 190 WL_ASSOC_RESP = 0x4 191}; 192/* beacon / probe_response */ 193struct beacon_proberesp { 194 __le64 timestamp; 195 __le16 beacon_int; 196 __le16 capab_info; 197 u8 variable[0]; 198} __attribute__ ((packed)); 199 200/* driver configuration */ 201struct wl_conf { 202 u32 frag_threshold; 203 u32 rts_threshold; 204 u32 retry_short; 205 u32 retry_long; 206 s32 tx_power; 207 struct ieee80211_channel channel; 208}; 209 210typedef s32(*EVENT_HANDLER) (struct wl_priv *wl, 211 struct net_device *ndev, const wl_event_msg_t *e, void *data); 212 213/* bss inform structure for cfg80211 interface */ 214struct wl_cfg80211_bss_info { 215 u16 band; 216 u16 channel; 217 s16 rssi; 218 u16 frame_len; 219 u8 frame_buf[1]; 220}; 221 222/* basic structure of scan request */ 223struct wl_scan_req { 224 struct wlc_ssid ssid; 225}; 226 227/* basic structure of information element */ 228struct wl_ie { 229 u16 offset; 230 u8 buf[WL_TLV_INFO_MAX]; 231}; 232 233/* event queue for cfg80211 main event */ 234struct wl_event_q { 235 struct list_head eq_list; 236 u32 etype; 237 wl_event_msg_t emsg; 238 s8 edata[1]; 239}; 240 241/* security information with currently associated ap */ 242struct wl_security { 243 u32 wpa_versions; 244 u32 auth_type; 245 u32 cipher_pairwise; 246 u32 cipher_group; 247 u32 wpa_auth; 248}; 249 250/* ibss information for currently joined ibss network */ 251struct wl_ibss { 252 u8 beacon_interval; /* in millisecond */ 253 u8 atim; /* in millisecond */ 254 s8 join_only; 255 u8 band; 256 u8 channel; 257}; 258 259/* wl driver profile */ 260struct wl_profile { 261 u32 mode; 262 s32 band; 263 struct wlc_ssid ssid; 264 struct wl_security sec; 265 struct wl_ibss ibss; 266 u8 bssid[ETHER_ADDR_LEN]; 267 u16 beacon_interval; 268 u8 dtim_period; 269 bool active; 270}; 271 272struct net_info { 273 struct net_device *ndev; 274 struct wireless_dev *wdev; 275 struct wl_profile profile; 276 s32 mode; 277 unsigned long sme_state; 278 struct list_head list; /* list of all net_info structure */ 279}; 280typedef s32(*ISCAN_HANDLER) (struct wl_priv *wl); 281 282/* iscan controller */ 283struct wl_iscan_ctrl { 284 struct net_device *dev; 285 struct timer_list timer; 286 u32 timer_ms; 287 u32 timer_on; 288 s32 state; 289 struct task_struct *tsk; 290 struct semaphore sync; 291 ISCAN_HANDLER iscan_handler[WL_SCAN_ERSULTS_LAST]; 292 void *data; 293 s8 ioctl_buf[WLC_IOCTL_SMLEN]; 294 s8 scan_buf[WL_ISCAN_BUF_MAX]; 295}; 296 297/* association inform */ 298#define MAX_REQ_LINE 1024 299struct wl_connect_info { 300 u8 req_ie[MAX_REQ_LINE]; 301 s32 req_ie_len; 302 u8 resp_ie[MAX_REQ_LINE]; 303 s32 resp_ie_len; 304}; 305 306/* firmware /nvram downloading controller */ 307struct wl_fw_ctrl { 308 const struct firmware *fw_entry; 309 unsigned long status; 310 u32 ptr; 311 s8 fw_name[WL_FILE_NAME_MAX]; 312 s8 nvram_name[WL_FILE_NAME_MAX]; 313}; 314 315/* assoc ie length */ 316struct wl_assoc_ielen { 317 u32 req_len; 318 u32 resp_len; 319}; 320 321/* wpa2 pmk list */ 322struct wl_pmk_list { 323 pmkid_list_t pmkids; 324 pmkid_t foo[MAXPMKID - 1]; 325}; 326 327 328#define ESCAN_BUF_SIZE (64 * 1024) 329 330struct escan_info { 331 u32 escan_state; 332 u8 escan_buf[ESCAN_BUF_SIZE]; 333 struct wiphy *wiphy; 334 struct net_device *ndev; 335}; 336 337struct ap_info { 338/* Structure to hold WPS, WPA IEs for a AP */ 339 u8 probe_res_ie[IE_MAX_LEN]; 340 u8 beacon_ie[IE_MAX_LEN]; 341 u32 probe_res_ie_len; 342 u32 beacon_ie_len; 343 u8 *wpa_ie; 344 u8 *rsn_ie; 345 u8 *wps_ie; 346 bool security_mode; 347}; 348struct btcoex_info { 349 struct timer_list timer; 350 u32 timer_ms; 351 u32 timer_on; 352 u32 ts_dhcp_start; /* ms ts ecord time stats */ 353 u32 ts_dhcp_ok; /* ms ts ecord time stats */ 354 bool dhcp_done; /* flag, indicates that host done with 355 * dhcp before t1/t2 expiration 356 */ 357 s32 bt_state; 358 struct work_struct work; 359 struct net_device *dev; 360}; 361 362struct sta_info { 363 /* Structure to hold WPS IE for a STA */ 364 u8 probe_req_ie[IE_MAX_LEN]; 365 u8 assoc_req_ie[IE_MAX_LEN]; 366 u32 probe_req_ie_len; 367 u32 assoc_req_ie_len; 368}; 369 370struct afx_hdl { 371 wl_af_params_t *pending_tx_act_frm; 372 struct ether_addr pending_tx_dst_addr; 373 struct net_device *dev; 374 struct work_struct work; 375 u32 bssidx; 376 u32 retry; 377 s32 peer_chan; 378 bool ack_recv; 379}; 380 381/* private data of cfg80211 interface */ 382struct wl_priv { 383 struct wireless_dev *wdev; /* representing wl cfg80211 device */ 384 385 struct wireless_dev *p2p_wdev; /* representing wl cfg80211 device for P2P */ 386 struct net_device *p2p_net; /* reference to p2p0 interface */ 387 388 struct wl_conf *conf; 389 struct cfg80211_scan_request *scan_request; /* scan request object */ 390 EVENT_HANDLER evt_handler[WLC_E_LAST]; 391 struct list_head eq_list; /* used for event queue */ 392 struct list_head net_list; /* used for struct net_info */ 393 spinlock_t eq_lock; /* for event queue synchronization */ 394 spinlock_t cfgdrv_lock; /* to protect scan status (and others if needed) */ 395 struct completion act_frm_scan; 396 struct mutex usr_sync; /* maily for up/down synchronization */ 397 struct wl_scan_results *bss_list; 398 struct wl_scan_results *scan_results; 399 400 /* scan request object for internal purpose */ 401 struct wl_scan_req *scan_req_int; 402 /* information element object for internal purpose */ 403 struct wl_ie ie; 404 struct wl_iscan_ctrl *iscan; /* iscan controller */ 405 406 /* association information container */ 407 struct wl_connect_info conn_info; 408 409 struct wl_pmk_list *pmk_list; /* wpa2 pmk list */ 410 tsk_ctl_t event_tsk; /* task of main event handler thread */ 411 void *pub; 412 u32 iface_cnt; 413 u32 channel; /* current channel */ 414 bool iscan_on; /* iscan on/off switch */ 415 bool iscan_kickstart; /* indicate iscan already started */ 416 bool escan_on; /* escan on/off switch */ 417 struct escan_info escan_info; /* escan information */ 418 bool active_scan; /* current scan mode */ 419 bool ibss_starter; /* indicates this sta is ibss starter */ 420 bool link_up; /* link/connection up flag */ 421 422 /* indicate whether chip to support power save mode */ 423 bool pwr_save; 424 bool roam_on; /* on/off switch for self-roaming */ 425 bool scan_tried; /* indicates if first scan attempted */ 426 u8 *ioctl_buf; /* ioctl buffer */ 427 struct mutex ioctl_buf_sync; 428 u8 *escan_ioctl_buf; 429 u8 *extra_buf; /* maily to grab assoc information */ 430 struct dentry *debugfsdir; 431 struct rfkill *rfkill; 432 bool rf_blocked; 433 struct ieee80211_channel remain_on_chan; 434 enum nl80211_channel_type remain_on_chan_type; 435 u64 send_action_id; 436 u64 last_roc_id; 437 wait_queue_head_t netif_change_event; 438 struct afx_hdl *afx_hdl; 439 struct ap_info *ap_info; 440 struct sta_info *sta_info; 441 struct p2p_info *p2p; 442 bool p2p_supported; 443 struct btcoex_info *btcoex_info; 444 struct timer_list scan_timeout; /* Timer for catch scan event timeout */ 445}; 446 447 448static inline struct wl_bss_info *next_bss(struct wl_scan_results *list, struct wl_bss_info *bss) 449{ 450 return bss = bss ? 451 (struct wl_bss_info *)((uintptr) bss + dtoh32(bss->length)) : list->bss_info; 452} 453static inline s32 454wl_alloc_netinfo(struct wl_priv *wl, struct net_device *ndev, 455 struct wireless_dev * wdev, s32 mode) 456{ 457 struct net_info *_net_info; 458 s32 err = 0; 459 if (wl->iface_cnt == IFACE_MAX_CNT) 460 return -ENOMEM; 461 _net_info = kzalloc(sizeof(struct net_info), GFP_KERNEL); 462 if (!_net_info) 463 err = -ENOMEM; 464 else { 465 _net_info->mode = mode; 466 _net_info->ndev = ndev; 467 _net_info->wdev = wdev; 468 wl->iface_cnt++; 469 list_add(&_net_info->list, &wl->net_list); 470 } 471 return err; 472} 473static inline void 474wl_dealloc_netinfo(struct wl_priv *wl, struct net_device *ndev) 475{ 476 struct net_info *_net_info, *next; 477 478 list_for_each_entry_safe(_net_info, next, &wl->net_list, list) { 479 if (ndev && (_net_info->ndev == ndev)) { 480 list_del(&_net_info->list); 481 wl->iface_cnt--; 482 if (_net_info->wdev) { 483 kfree(_net_info->wdev); 484 ndev->ieee80211_ptr = NULL; 485 } 486 kfree(_net_info); 487 } 488 } 489 490} 491static inline void 492wl_delete_all_netinfo(struct wl_priv *wl) 493{ 494 struct net_info *_net_info, *next; 495 496 list_for_each_entry_safe(_net_info, next, &wl->net_list, list) { 497 list_del(&_net_info->list); 498 if (_net_info->wdev) 499 kfree(_net_info->wdev); 500 kfree(_net_info); 501 } 502 wl->iface_cnt = 0; 503} 504static inline bool 505wl_get_status_all(struct wl_priv *wl, s32 status) 506 507{ 508 struct net_info *_net_info, *next; 509 u32 cnt = 0; 510 list_for_each_entry_safe(_net_info, next, &wl->net_list, list) { 511 if (_net_info->ndev && 512 test_bit(status, &_net_info->sme_state)) 513 cnt++; 514 } 515 return cnt? true: false; 516} 517static inline void 518wl_set_status_by_netdev(struct wl_priv *wl, s32 status, 519 struct net_device *ndev, u32 op) 520{ 521 522 struct net_info *_net_info, *next; 523 524 list_for_each_entry_safe(_net_info, next, &wl->net_list, list) { 525 if (ndev && (_net_info->ndev == ndev)) { 526 switch (op) { 527 case 1: 528 set_bit(status, &_net_info->sme_state); 529 break; 530 case 2: 531 clear_bit(status, &_net_info->sme_state); 532 break; 533 case 4: 534 change_bit(status, &_net_info->sme_state); 535 break; 536 } 537 } 538 539 } 540 541} 542 543static inline u32 544wl_get_status_by_netdev(struct wl_priv *wl, s32 status, 545 struct net_device *ndev) 546{ 547 struct net_info *_net_info, *next; 548 549 list_for_each_entry_safe(_net_info, next, &wl->net_list, list) { 550 if (ndev && (_net_info->ndev == ndev)) 551 return test_bit(status, &_net_info->sme_state); 552 } 553 return 0; 554} 555 556static inline s32 557wl_get_mode_by_netdev(struct wl_priv *wl, struct net_device *ndev) 558{ 559 struct net_info *_net_info, *next; 560 561 list_for_each_entry_safe(_net_info, next, &wl->net_list, list) { 562 if (ndev && (_net_info->ndev == ndev)) 563 return _net_info->mode; 564 } 565 return -1; 566} 567 568 569static inline void 570wl_set_mode_by_netdev(struct wl_priv *wl, struct net_device *ndev, 571 s32 mode) 572{ 573 struct net_info *_net_info, *next; 574 575 list_for_each_entry_safe(_net_info, next, &wl->net_list, list) { 576 if (ndev && (_net_info->ndev == ndev)) 577 _net_info->mode = mode; 578 } 579} 580static inline struct wl_profile * 581wl_get_profile_by_netdev(struct wl_priv *wl, struct net_device *ndev) 582{ 583 struct net_info *_net_info, *next; 584 585 list_for_each_entry_safe(_net_info, next, &wl->net_list, list) { 586 if (ndev && (_net_info->ndev == ndev)) 587 return &_net_info->profile; 588 } 589 return NULL; 590} 591#define wl_to_wiphy(w) (w->wdev->wiphy) 592#define wl_to_prmry_ndev(w) (w->wdev->netdev) 593#define ndev_to_wl(n) (wdev_to_wl(n->ieee80211_ptr)) 594#define wl_to_sr(w) (w->scan_req_int) 595#define wl_to_ie(w) (&w->ie) 596#define iscan_to_wl(i) ((struct wl_priv *)(i->data)) 597#define wl_to_iscan(w) (w->iscan) 598#define wl_to_conn(w) (&w->conn_info) 599#define wiphy_from_scan(w) (w->escan_info.wiphy) 600#define wl_get_drv_status_all(wl, stat) \ 601 (wl_get_status_all(wl, WL_STATUS_ ## stat)) 602#define wl_get_drv_status(wl, stat, ndev) \ 603 (wl_get_status_by_netdev(wl, WL_STATUS_ ## stat, ndev)) 604#define wl_set_drv_status(wl, stat, ndev) \ 605 (wl_set_status_by_netdev(wl, WL_STATUS_ ## stat, ndev, 1)) 606#define wl_clr_drv_status(wl, stat, ndev) \ 607 (wl_set_status_by_netdev(wl, WL_STATUS_ ## stat, ndev, 2)) 608#define wl_chg_drv_status(wl, stat, ndev) \ 609 (wl_set_status_by_netdev(wl, WL_STATUS_ ## stat, ndev, 4)) 610 611#define for_each_bss(list, bss, __i) \ 612 for (__i = 0; __i < list->count && __i < WL_AP_MAX; __i++, bss = next_bss(list, bss)) 613 614#define for_each_ndev(wl, iter, next) \ 615 list_for_each_entry_safe(iter, next, &wl->net_list, list) 616 617 618/* In case of WPS from wpa_supplicant, pairwise siute and group suite is 0. 619 * In addtion to that, wpa_version is WPA_VERSION_1 620 */ 621#define is_wps_conn(_sme) \ 622 ((wl_cfgp2p_find_wpsie((u8 *)_sme->ie, _sme->ie_len) != NULL) && \ 623 (!_sme->crypto.n_ciphers_pairwise) && \ 624 (!_sme->crypto.cipher_group)) 625extern s32 wl_cfg80211_attach(struct net_device *ndev, void *data); 626extern s32 wl_cfg80211_attach_post(struct net_device *ndev); 627extern void wl_cfg80211_detach(void *para); 628 629extern void wl_cfg80211_event(struct net_device *ndev, const wl_event_msg_t *e, 630 void *data); 631void wl_cfg80211_set_parent_dev(void *dev); 632struct device *wl_cfg80211_get_parent_dev(void); 633 634extern s32 wl_cfg80211_up(void *para); 635extern s32 wl_cfg80211_down(void *para); 636extern s32 wl_cfg80211_notify_ifadd(struct net_device *net, s32 idx, s32 bssidx, void* _net_attach); 637extern s32 wl_cfg80211_ifdel_ops(struct net_device *net); 638extern s32 wl_cfg80211_notify_ifdel(struct net_device *ndev); 639extern s32 wl_cfg80211_is_progress_ifadd(void); 640extern s32 wl_cfg80211_is_progress_ifchange(void); 641extern s32 wl_cfg80211_is_progress_ifadd(void); 642extern s32 wl_cfg80211_notify_ifchange(void); 643extern void wl_cfg80211_dbg_level(u32 level); 644extern s32 wl_cfg80211_get_p2p_dev_addr(struct net_device *net, struct ether_addr *p2pdev_addr); 645extern s32 wl_cfg80211_set_p2p_noa(struct net_device *net, char* buf, int len); 646extern s32 wl_cfg80211_get_p2p_noa(struct net_device *net, char* buf, int len); 647extern s32 wl_cfg80211_set_wps_p2p_ie(struct net_device *net, char *buf, int len, 648 enum wl_management_type type); 649extern s32 wl_cfg80211_set_p2p_ps(struct net_device *net, char* buf, int len); 650extern int wl_cfg80211_hang(struct net_device *dev, u16 reason); 651extern s32 wl_mode_to_nl80211_iftype(s32 mode); 652 653/* do scan abort */ 654extern s32 wl_cfg80211_scan_abort(struct wl_priv *wl, struct net_device *ndev); 655 656extern s32 wl_cfg80211_if_is_group_owner(void); 657#endif /* _wl_cfg80211_h_ */ 658