cfg80211.h 14 KB

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