wl_cfg80211.h 14 KB

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