wl_cfg80211.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493
  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. #ifndef _wl_cfg80211_h_
  17. #define _wl_cfg80211_h_
  18. /* for brcmu_d11inf */
  19. #include <brcmu_d11.h>
  20. #define WL_NUM_SCAN_MAX 10
  21. #define WL_NUM_PMKIDS_MAX MAXPMKID
  22. #define WL_TLV_INFO_MAX 1024
  23. #define WL_BSS_INFO_MAX 2048
  24. #define WL_ASSOC_INFO_MAX 512 /* assoc related fil max buf */
  25. #define WL_EXTRA_BUF_MAX 2048
  26. #define WL_ROAM_TRIGGER_LEVEL -75
  27. #define WL_ROAM_DELTA 20
  28. #define WL_BEACON_TIMEOUT 3
  29. #define WL_SCAN_CHANNEL_TIME 40
  30. #define WL_SCAN_UNASSOC_TIME 40
  31. #define WL_SCAN_PASSIVE_TIME 120
  32. #define WL_ESCAN_BUF_SIZE (1024 * 64)
  33. #define WL_ESCAN_TIMER_INTERVAL_MS 8000 /* E-Scan timeout */
  34. #define WL_ESCAN_ACTION_START 1
  35. #define WL_ESCAN_ACTION_CONTINUE 2
  36. #define WL_ESCAN_ACTION_ABORT 3
  37. #define WL_AUTH_SHARED_KEY 1 /* d11 shared authentication */
  38. #define IE_MAX_LEN 512
  39. /* IE TLV processing */
  40. #define TLV_LEN_OFF 1 /* length offset */
  41. #define TLV_HDR_LEN 2 /* header length */
  42. #define TLV_BODY_OFF 2 /* body offset */
  43. #define TLV_OUI_LEN 3 /* oui id length */
  44. /* 802.11 Mgmt Packet flags */
  45. #define BRCMF_VNDR_IE_BEACON_FLAG 0x1
  46. #define BRCMF_VNDR_IE_PRBRSP_FLAG 0x2
  47. #define BRCMF_VNDR_IE_ASSOCRSP_FLAG 0x4
  48. #define BRCMF_VNDR_IE_AUTHRSP_FLAG 0x8
  49. #define BRCMF_VNDR_IE_PRBREQ_FLAG 0x10
  50. #define BRCMF_VNDR_IE_ASSOCREQ_FLAG 0x20
  51. /* vendor IE in IW advertisement protocol ID field */
  52. #define BRCMF_VNDR_IE_IWAPID_FLAG 0x40
  53. /* allow custom IE id */
  54. #define BRCMF_VNDR_IE_CUSTOM_FLAG 0x100
  55. /* P2P Action Frames flags (spec ordered) */
  56. #define BRCMF_VNDR_IE_GONREQ_FLAG 0x001000
  57. #define BRCMF_VNDR_IE_GONRSP_FLAG 0x002000
  58. #define BRCMF_VNDR_IE_GONCFM_FLAG 0x004000
  59. #define BRCMF_VNDR_IE_INVREQ_FLAG 0x008000
  60. #define BRCMF_VNDR_IE_INVRSP_FLAG 0x010000
  61. #define BRCMF_VNDR_IE_DISREQ_FLAG 0x020000
  62. #define BRCMF_VNDR_IE_DISRSP_FLAG 0x040000
  63. #define BRCMF_VNDR_IE_PRDREQ_FLAG 0x080000
  64. #define BRCMF_VNDR_IE_PRDRSP_FLAG 0x100000
  65. #define BRCMF_VNDR_IE_P2PAF_SHIFT 12
  66. /**
  67. * enum brcmf_scan_status - scan engine status
  68. *
  69. * @BRCMF_SCAN_STATUS_BUSY: scanning in progress on dongle.
  70. * @BRCMF_SCAN_STATUS_ABORT: scan being aborted on dongle.
  71. * @BRCMF_SCAN_STATUS_SUPPRESS: scanning is suppressed in driver.
  72. */
  73. enum brcmf_scan_status {
  74. BRCMF_SCAN_STATUS_BUSY,
  75. BRCMF_SCAN_STATUS_ABORT,
  76. BRCMF_SCAN_STATUS_SUPPRESS,
  77. };
  78. /* dongle configuration */
  79. struct brcmf_cfg80211_conf {
  80. u32 frag_threshold;
  81. u32 rts_threshold;
  82. u32 retry_short;
  83. u32 retry_long;
  84. s32 tx_power;
  85. struct ieee80211_channel channel;
  86. };
  87. /* basic structure of scan request */
  88. struct brcmf_cfg80211_scan_req {
  89. struct brcmf_ssid_le ssid_le;
  90. };
  91. /* basic structure of information element */
  92. struct brcmf_cfg80211_ie {
  93. u16 offset;
  94. u8 buf[WL_TLV_INFO_MAX];
  95. };
  96. /* security information with currently associated ap */
  97. struct brcmf_cfg80211_security {
  98. u32 wpa_versions;
  99. u32 auth_type;
  100. u32 cipher_pairwise;
  101. u32 cipher_group;
  102. u32 wpa_auth;
  103. };
  104. /**
  105. * struct brcmf_cfg80211_profile - profile information.
  106. *
  107. * @ssid: ssid of associated/associating ap.
  108. * @bssid: bssid of joined/joining ibss.
  109. * @sec: security information.
  110. */
  111. struct brcmf_cfg80211_profile {
  112. struct brcmf_ssid ssid;
  113. u8 bssid[ETH_ALEN];
  114. struct brcmf_cfg80211_security sec;
  115. };
  116. /**
  117. * enum brcmf_vif_status - bit indices for vif status.
  118. *
  119. * @BRCMF_VIF_STATUS_READY: ready for operation.
  120. * @BRCMF_VIF_STATUS_CONNECTING: connect/join in progress.
  121. * @BRCMF_VIF_STATUS_CONNECTED: connected/joined succesfully.
  122. * @BRCMF_VIF_STATUS_DISCONNECTING: disconnect/disable in progress.
  123. * @BRCMF_VIF_STATUS_AP_CREATING: interface configured for AP operation.
  124. * @BRCMF_VIF_STATUS_AP_CREATED: AP operation started.
  125. */
  126. enum brcmf_vif_status {
  127. BRCMF_VIF_STATUS_READY,
  128. BRCMF_VIF_STATUS_CONNECTING,
  129. BRCMF_VIF_STATUS_CONNECTED,
  130. BRCMF_VIF_STATUS_DISCONNECTING,
  131. BRCMF_VIF_STATUS_AP_CREATING,
  132. BRCMF_VIF_STATUS_AP_CREATED
  133. };
  134. /**
  135. * struct vif_saved_ie - holds saved IEs for a virtual interface.
  136. *
  137. * @probe_req_ie: IE info for probe request.
  138. * @probe_res_ie: IE info for probe response.
  139. * @beacon_ie: IE info for beacon frame.
  140. * @probe_req_ie_len: IE info length for probe request.
  141. * @probe_res_ie_len: IE info length for probe response.
  142. * @beacon_ie_len: IE info length for beacon frame.
  143. */
  144. struct vif_saved_ie {
  145. u8 probe_req_ie[IE_MAX_LEN];
  146. u8 probe_res_ie[IE_MAX_LEN];
  147. u8 beacon_ie[IE_MAX_LEN];
  148. u8 assoc_req_ie[IE_MAX_LEN];
  149. u32 probe_req_ie_len;
  150. u32 probe_res_ie_len;
  151. u32 beacon_ie_len;
  152. u32 assoc_req_ie_len;
  153. };
  154. /**
  155. * struct brcmf_cfg80211_vif - virtual interface specific information.
  156. *
  157. * @ifp: lower layer interface pointer
  158. * @wdev: wireless device.
  159. * @profile: profile information.
  160. * @roam_off: roaming state.
  161. * @sme_state: SME state using enum brcmf_vif_status bits.
  162. * @pm_block: power-management blocked.
  163. * @list: linked list.
  164. * @mgmt_rx_reg: registered rx mgmt frame types.
  165. */
  166. struct brcmf_cfg80211_vif {
  167. struct brcmf_if *ifp;
  168. struct wireless_dev wdev;
  169. struct brcmf_cfg80211_profile profile;
  170. s32 roam_off;
  171. unsigned long sme_state;
  172. bool pm_block;
  173. struct vif_saved_ie saved_ie;
  174. struct list_head list;
  175. u16 mgmt_rx_reg;
  176. };
  177. /* association inform */
  178. struct brcmf_cfg80211_connect_info {
  179. u8 *req_ie;
  180. s32 req_ie_len;
  181. u8 *resp_ie;
  182. s32 resp_ie_len;
  183. };
  184. /* assoc ie length */
  185. struct brcmf_cfg80211_assoc_ielen_le {
  186. __le32 req_len;
  187. __le32 resp_len;
  188. };
  189. /* wpa2 pmk list */
  190. struct brcmf_cfg80211_pmk_list {
  191. struct pmkid_list pmkids;
  192. struct pmkid foo[MAXPMKID - 1];
  193. };
  194. /* dongle escan state */
  195. enum wl_escan_state {
  196. WL_ESCAN_STATE_IDLE,
  197. WL_ESCAN_STATE_SCANNING
  198. };
  199. struct escan_info {
  200. u32 escan_state;
  201. u8 escan_buf[WL_ESCAN_BUF_SIZE];
  202. struct wiphy *wiphy;
  203. struct brcmf_if *ifp;
  204. s32 (*run)(struct brcmf_cfg80211_info *cfg, struct brcmf_if *ifp,
  205. struct cfg80211_scan_request *request, u16 action);
  206. };
  207. /**
  208. * struct brcmf_pno_param_le - PNO scan configuration parameters
  209. *
  210. * @version: PNO parameters version.
  211. * @scan_freq: scan frequency.
  212. * @lost_network_timeout: #sec. to declare discovered network as lost.
  213. * @flags: Bit field to control features of PFN such as sort criteria auto
  214. * enable switch and background scan.
  215. * @rssi_margin: Margin to avoid jitter for choosing a PFN based on RSSI sort
  216. * criteria.
  217. * @bestn: number of best networks in each scan.
  218. * @mscan: number of scans recorded.
  219. * @repeat: minimum number of scan intervals before scan frequency changes
  220. * in adaptive scan.
  221. * @exp: exponent of 2 for maximum scan interval.
  222. * @slow_freq: slow scan period.
  223. */
  224. struct brcmf_pno_param_le {
  225. __le32 version;
  226. __le32 scan_freq;
  227. __le32 lost_network_timeout;
  228. __le16 flags;
  229. __le16 rssi_margin;
  230. u8 bestn;
  231. u8 mscan;
  232. u8 repeat;
  233. u8 exp;
  234. __le32 slow_freq;
  235. };
  236. /**
  237. * struct brcmf_pno_net_param_le - scan parameters per preferred network.
  238. *
  239. * @ssid: ssid name and its length.
  240. * @flags: bit2: hidden.
  241. * @infra: BSS vs IBSS.
  242. * @auth: Open vs Closed.
  243. * @wpa_auth: WPA type.
  244. * @wsec: wsec value.
  245. */
  246. struct brcmf_pno_net_param_le {
  247. struct brcmf_ssid_le ssid;
  248. __le32 flags;
  249. __le32 infra;
  250. __le32 auth;
  251. __le32 wpa_auth;
  252. __le32 wsec;
  253. };
  254. /**
  255. * struct brcmf_pno_net_info_le - information per found network.
  256. *
  257. * @bssid: BSS network identifier.
  258. * @channel: channel number only.
  259. * @SSID_len: length of ssid.
  260. * @SSID: ssid characters.
  261. * @RSSI: receive signal strength (in dBm).
  262. * @timestamp: age in seconds.
  263. */
  264. struct brcmf_pno_net_info_le {
  265. u8 bssid[ETH_ALEN];
  266. u8 channel;
  267. u8 SSID_len;
  268. u8 SSID[32];
  269. __le16 RSSI;
  270. __le16 timestamp;
  271. };
  272. /**
  273. * struct brcmf_pno_scanresults_le - result returned in PNO NET FOUND event.
  274. *
  275. * @version: PNO version identifier.
  276. * @status: indicates completion status of PNO scan.
  277. * @count: amount of brcmf_pno_net_info_le entries appended.
  278. */
  279. struct brcmf_pno_scanresults_le {
  280. __le32 version;
  281. __le32 status;
  282. __le32 count;
  283. };
  284. /**
  285. * struct brcmf_cfg80211_vif_event - virtual interface event information.
  286. *
  287. * @vif_wq: waitqueue awaiting interface event from firmware.
  288. * @vif_event_lock: protects other members in this structure.
  289. * @vif_complete: completion for net attach.
  290. * @action: either add, change, or delete.
  291. * @vif: virtual interface object related to the event.
  292. */
  293. struct brcmf_cfg80211_vif_event {
  294. wait_queue_head_t vif_wq;
  295. struct mutex vif_event_lock;
  296. u8 action;
  297. struct brcmf_cfg80211_vif *vif;
  298. };
  299. /**
  300. * struct brcmf_cfg80211_info - dongle private data of cfg80211 interface
  301. *
  302. * @wiphy: wiphy object for cfg80211 interface.
  303. * @conf: dongle configuration.
  304. * @p2p: peer-to-peer specific information.
  305. * @btcoex: Bluetooth coexistence information.
  306. * @scan_request: cfg80211 scan request object.
  307. * @usr_sync: mainly for dongle up/down synchronization.
  308. * @bss_list: bss_list holding scanned ap information.
  309. * @scan_req_int: internal scan request object.
  310. * @bss_info: bss information for cfg80211 layer.
  311. * @ie: information element object for internal purpose.
  312. * @conn_info: association info.
  313. * @pmk_list: wpa2 pmk list.
  314. * @scan_status: scan activity on the dongle.
  315. * @pub: common driver information.
  316. * @channel: current channel.
  317. * @active_scan: current scan mode.
  318. * @sched_escan: e-scan for scheduled scan support running.
  319. * @ibss_starter: indicates this sta is ibss starter.
  320. * @pwr_save: indicate whether dongle to support power save mode.
  321. * @dongle_up: indicate whether dongle up or not.
  322. * @roam_on: on/off switch for dongle self-roaming.
  323. * @scan_tried: indicates if first scan attempted.
  324. * @dcmd_buf: dcmd buffer.
  325. * @extra_buf: mainly to grab assoc information.
  326. * @debugfsdir: debugfs folder for this device.
  327. * @escan_info: escan information.
  328. * @escan_timeout: Timer for catch scan timeout.
  329. * @escan_timeout_work: scan timeout worker.
  330. * @escan_ioctl_buf: dongle command buffer for escan commands.
  331. * @vif_list: linked list of vif instances.
  332. * @vif_cnt: number of vif instances.
  333. * @vif_event: vif event signalling.
  334. */
  335. struct brcmf_cfg80211_info {
  336. struct wiphy *wiphy;
  337. struct brcmf_cfg80211_conf *conf;
  338. struct brcmf_p2p_info p2p;
  339. struct brcmf_btcoex_info *btcoex;
  340. struct cfg80211_scan_request *scan_request;
  341. struct mutex usr_sync;
  342. struct brcmf_scan_results *bss_list;
  343. struct brcmf_cfg80211_scan_req scan_req_int;
  344. struct wl_cfg80211_bss_info *bss_info;
  345. struct brcmf_cfg80211_ie ie;
  346. struct brcmf_cfg80211_connect_info conn_info;
  347. struct brcmf_cfg80211_pmk_list *pmk_list;
  348. unsigned long scan_status;
  349. struct brcmf_pub *pub;
  350. u32 channel;
  351. bool active_scan;
  352. bool sched_escan;
  353. bool ibss_starter;
  354. bool pwr_save;
  355. bool dongle_up;
  356. bool scan_tried;
  357. u8 *dcmd_buf;
  358. u8 *extra_buf;
  359. struct dentry *debugfsdir;
  360. struct escan_info escan_info;
  361. struct timer_list escan_timeout;
  362. struct work_struct escan_timeout_work;
  363. u8 *escan_ioctl_buf;
  364. struct list_head vif_list;
  365. struct brcmf_cfg80211_vif_event vif_event;
  366. struct completion vif_disabled;
  367. struct brcmu_d11inf d11inf;
  368. };
  369. /**
  370. * struct brcmf_tlv - tag_ID/length/value_buffer tuple.
  371. *
  372. * @id: tag identifier.
  373. * @len: number of bytes in value buffer.
  374. * @data: value buffer.
  375. */
  376. struct brcmf_tlv {
  377. u8 id;
  378. u8 len;
  379. u8 data[1];
  380. };
  381. static inline struct wiphy *cfg_to_wiphy(struct brcmf_cfg80211_info *cfg)
  382. {
  383. return cfg->wiphy;
  384. }
  385. static inline struct brcmf_cfg80211_info *wiphy_to_cfg(struct wiphy *w)
  386. {
  387. return (struct brcmf_cfg80211_info *)(wiphy_priv(w));
  388. }
  389. static inline struct brcmf_cfg80211_info *wdev_to_cfg(struct wireless_dev *wd)
  390. {
  391. return (struct brcmf_cfg80211_info *)(wdev_priv(wd));
  392. }
  393. static inline
  394. struct net_device *cfg_to_ndev(struct brcmf_cfg80211_info *cfg)
  395. {
  396. struct brcmf_cfg80211_vif *vif;
  397. vif = list_first_entry(&cfg->vif_list, struct brcmf_cfg80211_vif, list);
  398. return vif->wdev.netdev;
  399. }
  400. static inline struct brcmf_cfg80211_info *ndev_to_cfg(struct net_device *ndev)
  401. {
  402. return wdev_to_cfg(ndev->ieee80211_ptr);
  403. }
  404. static inline struct brcmf_cfg80211_profile *ndev_to_prof(struct net_device *nd)
  405. {
  406. struct brcmf_if *ifp = netdev_priv(nd);
  407. return &ifp->vif->profile;
  408. }
  409. static inline struct brcmf_cfg80211_vif *ndev_to_vif(struct net_device *ndev)
  410. {
  411. struct brcmf_if *ifp = netdev_priv(ndev);
  412. return ifp->vif;
  413. }
  414. static inline struct
  415. brcmf_cfg80211_connect_info *cfg_to_conn(struct brcmf_cfg80211_info *cfg)
  416. {
  417. return &cfg->conn_info;
  418. }
  419. struct brcmf_cfg80211_info *brcmf_cfg80211_attach(struct brcmf_pub *drvr,
  420. struct device *busdev);
  421. void brcmf_cfg80211_detach(struct brcmf_cfg80211_info *cfg);
  422. s32 brcmf_cfg80211_up(struct net_device *ndev);
  423. s32 brcmf_cfg80211_down(struct net_device *ndev);
  424. enum nl80211_iftype brcmf_cfg80211_get_iftype(struct brcmf_if *ifp);
  425. struct brcmf_cfg80211_vif *brcmf_alloc_vif(struct brcmf_cfg80211_info *cfg,
  426. enum nl80211_iftype type,
  427. bool pm_block);
  428. void brcmf_free_vif(struct brcmf_cfg80211_vif *vif);
  429. s32 brcmf_vif_set_mgmt_ie(struct brcmf_cfg80211_vif *vif, s32 pktflag,
  430. const u8 *vndr_ie_buf, u32 vndr_ie_len);
  431. s32 brcmf_vif_clear_mgmt_ies(struct brcmf_cfg80211_vif *vif);
  432. const struct brcmf_tlv *
  433. brcmf_parse_tlvs(const void *buf, int buflen, uint key);
  434. u16 channel_to_chanspec(struct brcmu_d11inf *d11inf,
  435. struct ieee80211_channel *ch);
  436. u32 wl_get_vif_state_all(struct brcmf_cfg80211_info *cfg, unsigned long state);
  437. void brcmf_cfg80211_arm_vif_event(struct brcmf_cfg80211_info *cfg,
  438. struct brcmf_cfg80211_vif *vif);
  439. bool brcmf_cfg80211_vif_event_armed(struct brcmf_cfg80211_info *cfg);
  440. int brcmf_cfg80211_wait_vif_event_timeout(struct brcmf_cfg80211_info *cfg,
  441. u8 action, ulong timeout);
  442. s32 brcmf_notify_escan_complete(struct brcmf_cfg80211_info *cfg,
  443. struct brcmf_if *ifp, bool aborted,
  444. bool fw_abort);
  445. void brcmf_set_mpc(struct brcmf_if *ndev, int mpc);
  446. void brcmf_abort_scanning(struct brcmf_cfg80211_info *cfg);
  447. void brcmf_cfg80211_free_netdev(struct net_device *ndev);
  448. #endif /* _wl_cfg80211_h_ */