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