wl_cfg80211.h 14 KB

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