wl_cfg80211.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501
  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 net_device *ndev;
  216. s32 (*run)(struct brcmf_cfg80211_info *cfg,
  217. struct net_device *ndev,
  218. struct cfg80211_scan_request *request, u16 action);
  219. };
  220. /**
  221. * struct brcmf_pno_param_le - PNO scan configuration parameters
  222. *
  223. * @version: PNO parameters version.
  224. * @scan_freq: scan frequency.
  225. * @lost_network_timeout: #sec. to declare discovered network as lost.
  226. * @flags: Bit field to control features of PFN such as sort criteria auto
  227. * enable switch and background scan.
  228. * @rssi_margin: Margin to avoid jitter for choosing a PFN based on RSSI sort
  229. * criteria.
  230. * @bestn: number of best networks in each scan.
  231. * @mscan: number of scans recorded.
  232. * @repeat: minimum number of scan intervals before scan frequency changes
  233. * in adaptive scan.
  234. * @exp: exponent of 2 for maximum scan interval.
  235. * @slow_freq: slow scan period.
  236. */
  237. struct brcmf_pno_param_le {
  238. __le32 version;
  239. __le32 scan_freq;
  240. __le32 lost_network_timeout;
  241. __le16 flags;
  242. __le16 rssi_margin;
  243. u8 bestn;
  244. u8 mscan;
  245. u8 repeat;
  246. u8 exp;
  247. __le32 slow_freq;
  248. };
  249. /**
  250. * struct brcmf_pno_net_param_le - scan parameters per preferred network.
  251. *
  252. * @ssid: ssid name and its length.
  253. * @flags: bit2: hidden.
  254. * @infra: BSS vs IBSS.
  255. * @auth: Open vs Closed.
  256. * @wpa_auth: WPA type.
  257. * @wsec: wsec value.
  258. */
  259. struct brcmf_pno_net_param_le {
  260. struct brcmf_ssid_le ssid;
  261. __le32 flags;
  262. __le32 infra;
  263. __le32 auth;
  264. __le32 wpa_auth;
  265. __le32 wsec;
  266. };
  267. /**
  268. * struct brcmf_pno_net_info_le - information per found network.
  269. *
  270. * @bssid: BSS network identifier.
  271. * @channel: channel number only.
  272. * @SSID_len: length of ssid.
  273. * @SSID: ssid characters.
  274. * @RSSI: receive signal strength (in dBm).
  275. * @timestamp: age in seconds.
  276. */
  277. struct brcmf_pno_net_info_le {
  278. u8 bssid[ETH_ALEN];
  279. u8 channel;
  280. u8 SSID_len;
  281. u8 SSID[32];
  282. __le16 RSSI;
  283. __le16 timestamp;
  284. };
  285. /**
  286. * struct brcmf_pno_scanresults_le - result returned in PNO NET FOUND event.
  287. *
  288. * @version: PNO version identifier.
  289. * @status: indicates completion status of PNO scan.
  290. * @count: amount of brcmf_pno_net_info_le entries appended.
  291. */
  292. struct brcmf_pno_scanresults_le {
  293. __le32 version;
  294. __le32 status;
  295. __le32 count;
  296. };
  297. /**
  298. * struct brcmf_cfg80211_vif_event - virtual interface event information.
  299. *
  300. * @vif_wq: waitqueue awaiting interface event from firmware.
  301. * @vif_event_lock: protects other members in this structure.
  302. * @vif_complete: completion for net attach.
  303. * @action: either add, change, or delete.
  304. * @vif: virtual interface object related to the event.
  305. */
  306. struct brcmf_cfg80211_vif_event {
  307. wait_queue_head_t vif_wq;
  308. struct mutex vif_event_lock;
  309. u8 action;
  310. struct brcmf_cfg80211_vif *vif;
  311. };
  312. /**
  313. * struct brcmf_cfg80211_info - dongle private data of cfg80211 interface
  314. *
  315. * @wiphy: wiphy object for cfg80211 interface.
  316. * @conf: dongle configuration.
  317. * @p2p: peer-to-peer specific information.
  318. * @scan_request: cfg80211 scan request object.
  319. * @usr_sync: mainly for dongle up/down synchronization.
  320. * @bss_list: bss_list holding scanned ap information.
  321. * @scan_req_int: internal scan request object.
  322. * @bss_info: bss information for cfg80211 layer.
  323. * @ie: information element object for internal purpose.
  324. * @conn_info: association info.
  325. * @pmk_list: wpa2 pmk list.
  326. * @scan_status: scan activity on the dongle.
  327. * @pub: common driver information.
  328. * @channel: current channel.
  329. * @active_scan: current scan mode.
  330. * @sched_escan: e-scan for scheduled scan support running.
  331. * @ibss_starter: indicates this sta is ibss starter.
  332. * @pwr_save: indicate whether dongle to support power save mode.
  333. * @dongle_up: indicate whether dongle up or not.
  334. * @roam_on: on/off switch for dongle self-roaming.
  335. * @scan_tried: indicates if first scan attempted.
  336. * @dcmd_buf: dcmd buffer.
  337. * @extra_buf: mainly to grab assoc information.
  338. * @debugfsdir: debugfs folder for this device.
  339. * @escan_info: escan information.
  340. * @escan_timeout: Timer for catch scan timeout.
  341. * @escan_timeout_work: scan timeout worker.
  342. * @escan_ioctl_buf: dongle command buffer for escan commands.
  343. * @vif_list: linked list of vif instances.
  344. * @vif_cnt: number of vif instances.
  345. * @vif_event: vif event signalling.
  346. */
  347. struct brcmf_cfg80211_info {
  348. struct wiphy *wiphy;
  349. struct brcmf_cfg80211_conf *conf;
  350. struct brcmf_p2p_info p2p;
  351. struct cfg80211_scan_request *scan_request;
  352. struct mutex usr_sync;
  353. struct brcmf_scan_results *bss_list;
  354. struct brcmf_cfg80211_scan_req scan_req_int;
  355. struct wl_cfg80211_bss_info *bss_info;
  356. struct brcmf_cfg80211_ie ie;
  357. struct brcmf_cfg80211_connect_info conn_info;
  358. struct brcmf_cfg80211_pmk_list *pmk_list;
  359. unsigned long scan_status;
  360. struct brcmf_pub *pub;
  361. u32 channel;
  362. bool active_scan;
  363. bool sched_escan;
  364. bool ibss_starter;
  365. bool pwr_save;
  366. bool dongle_up;
  367. bool roam_on;
  368. bool scan_tried;
  369. u8 *dcmd_buf;
  370. u8 *extra_buf;
  371. struct dentry *debugfsdir;
  372. struct escan_info escan_info;
  373. struct timer_list escan_timeout;
  374. struct work_struct escan_timeout_work;
  375. u8 *escan_ioctl_buf;
  376. struct list_head vif_list;
  377. u8 vif_cnt;
  378. struct brcmf_cfg80211_vif_event vif_event;
  379. struct completion vif_disabled;
  380. };
  381. /**
  382. * struct brcmf_tlv - tag_ID/length/value_buffer tuple.
  383. *
  384. * @id: tag identifier.
  385. * @len: number of bytes in value buffer.
  386. * @data: value buffer.
  387. */
  388. struct brcmf_tlv {
  389. u8 id;
  390. u8 len;
  391. u8 data[1];
  392. };
  393. static inline struct wiphy *cfg_to_wiphy(struct brcmf_cfg80211_info *cfg)
  394. {
  395. return cfg->wiphy;
  396. }
  397. static inline struct brcmf_cfg80211_info *wiphy_to_cfg(struct wiphy *w)
  398. {
  399. return (struct brcmf_cfg80211_info *)(wiphy_priv(w));
  400. }
  401. static inline struct brcmf_cfg80211_info *wdev_to_cfg(struct wireless_dev *wd)
  402. {
  403. return (struct brcmf_cfg80211_info *)(wdev_priv(wd));
  404. }
  405. static inline
  406. struct net_device *cfg_to_ndev(struct brcmf_cfg80211_info *cfg)
  407. {
  408. struct brcmf_cfg80211_vif *vif;
  409. vif = list_first_entry(&cfg->vif_list, struct brcmf_cfg80211_vif, list);
  410. return vif->wdev.netdev;
  411. }
  412. static inline struct brcmf_cfg80211_info *ndev_to_cfg(struct net_device *ndev)
  413. {
  414. return wdev_to_cfg(ndev->ieee80211_ptr);
  415. }
  416. static inline struct brcmf_cfg80211_profile *ndev_to_prof(struct net_device *nd)
  417. {
  418. struct brcmf_if *ifp = netdev_priv(nd);
  419. return &ifp->vif->profile;
  420. }
  421. static inline struct brcmf_cfg80211_vif *ndev_to_vif(struct net_device *ndev)
  422. {
  423. struct brcmf_if *ifp = netdev_priv(ndev);
  424. return ifp->vif;
  425. }
  426. static inline struct
  427. brcmf_cfg80211_connect_info *cfg_to_conn(struct brcmf_cfg80211_info *cfg)
  428. {
  429. return &cfg->conn_info;
  430. }
  431. struct brcmf_cfg80211_info *brcmf_cfg80211_attach(struct brcmf_pub *drvr,
  432. struct device *busdev);
  433. void brcmf_cfg80211_detach(struct brcmf_cfg80211_info *cfg);
  434. s32 brcmf_cfg80211_up(struct net_device *ndev);
  435. s32 brcmf_cfg80211_down(struct net_device *ndev);
  436. struct brcmf_cfg80211_vif *brcmf_alloc_vif(struct brcmf_cfg80211_info *cfg,
  437. enum nl80211_iftype type,
  438. bool pm_block);
  439. void brcmf_free_vif(struct brcmf_cfg80211_vif *vif);
  440. s32 brcmf_vif_set_mgmt_ie(struct brcmf_cfg80211_vif *vif, s32 pktflag,
  441. const u8 *vndr_ie_buf, u32 vndr_ie_len);
  442. s32 brcmf_vif_clear_mgmt_ies(struct brcmf_cfg80211_vif *vif);
  443. struct brcmf_tlv *brcmf_parse_tlvs(void *buf, int buflen, uint key);
  444. u16 channel_to_chanspec(struct ieee80211_channel *ch);
  445. u32 wl_get_vif_state_all(struct brcmf_cfg80211_info *cfg, unsigned long state);
  446. void brcmf_cfg80211_arm_vif_event(struct brcmf_cfg80211_info *cfg,
  447. struct brcmf_cfg80211_vif *vif);
  448. bool brcmf_cfg80211_vif_event_armed(struct brcmf_cfg80211_info *cfg);
  449. int brcmf_cfg80211_wait_vif_event_timeout(struct brcmf_cfg80211_info *cfg,
  450. u8 action, ulong timeout);
  451. s32 brcmf_notify_escan_complete(struct brcmf_cfg80211_info *cfg,
  452. struct net_device *ndev,
  453. bool aborted, bool fw_abort);
  454. void brcmf_set_mpc(struct net_device *ndev, int mpc);
  455. void brcmf_abort_scanning(struct brcmf_cfg80211_info *cfg);
  456. #endif /* _wl_cfg80211_h_ */