wl_cfg80211.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492
  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_AP_CREATING: interface configured for AP operation.
  133. * @BRCMF_VIF_STATUS_AP_CREATED: AP operation started.
  134. */
  135. enum brcmf_vif_status {
  136. BRCMF_VIF_STATUS_READY,
  137. BRCMF_VIF_STATUS_CONNECTING,
  138. BRCMF_VIF_STATUS_CONNECTED,
  139. BRCMF_VIF_STATUS_AP_CREATING,
  140. BRCMF_VIF_STATUS_AP_CREATED
  141. };
  142. /**
  143. * struct vif_saved_ie - holds saved IEs for a virtual interface.
  144. *
  145. * @probe_req_ie: IE info for probe request.
  146. * @probe_res_ie: IE info for probe response.
  147. * @beacon_ie: IE info for beacon frame.
  148. * @probe_req_ie_len: IE info length for probe request.
  149. * @probe_res_ie_len: IE info length for probe response.
  150. * @beacon_ie_len: IE info length for beacon frame.
  151. */
  152. struct vif_saved_ie {
  153. u8 probe_req_ie[VNDR_IES_BUF_LEN];
  154. u8 probe_res_ie[IE_MAX_LEN];
  155. u8 beacon_ie[IE_MAX_LEN];
  156. u32 probe_req_ie_len;
  157. u32 probe_res_ie_len;
  158. u32 beacon_ie_len;
  159. };
  160. /**
  161. * struct brcmf_cfg80211_vif - virtual interface specific information.
  162. *
  163. * @ifp: lower layer interface pointer
  164. * @wdev: wireless device.
  165. * @profile: profile information.
  166. * @mode: operating mode.
  167. * @roam_off: roaming state.
  168. * @sme_state: SME state using enum brcmf_vif_status bits.
  169. * @pm_block: power-management blocked.
  170. * @list: linked list.
  171. * @mgmt_rx_reg: registered rx mgmt frame types.
  172. */
  173. struct brcmf_cfg80211_vif {
  174. struct brcmf_if *ifp;
  175. struct wireless_dev wdev;
  176. struct brcmf_cfg80211_profile profile;
  177. s32 mode;
  178. s32 roam_off;
  179. unsigned long sme_state;
  180. bool pm_block;
  181. struct vif_saved_ie saved_ie;
  182. struct list_head list;
  183. u16 mgmt_rx_reg;
  184. };
  185. /* association inform */
  186. struct brcmf_cfg80211_connect_info {
  187. u8 *req_ie;
  188. s32 req_ie_len;
  189. u8 *resp_ie;
  190. s32 resp_ie_len;
  191. };
  192. /* assoc ie length */
  193. struct brcmf_cfg80211_assoc_ielen_le {
  194. __le32 req_len;
  195. __le32 resp_len;
  196. };
  197. /* wpa2 pmk list */
  198. struct brcmf_cfg80211_pmk_list {
  199. struct pmkid_list pmkids;
  200. struct pmkid foo[MAXPMKID - 1];
  201. };
  202. /* dongle escan state */
  203. enum wl_escan_state {
  204. WL_ESCAN_STATE_IDLE,
  205. WL_ESCAN_STATE_SCANNING
  206. };
  207. struct escan_info {
  208. u32 escan_state;
  209. u8 escan_buf[WL_ESCAN_BUF_SIZE];
  210. struct wiphy *wiphy;
  211. struct net_device *ndev;
  212. s32 (*run)(struct brcmf_cfg80211_info *cfg,
  213. struct net_device *ndev,
  214. struct cfg80211_scan_request *request, u16 action);
  215. };
  216. /**
  217. * struct brcmf_pno_param_le - PNO scan configuration parameters
  218. *
  219. * @version: PNO parameters version.
  220. * @scan_freq: scan frequency.
  221. * @lost_network_timeout: #sec. to declare discovered network as lost.
  222. * @flags: Bit field to control features of PFN such as sort criteria auto
  223. * enable switch and background scan.
  224. * @rssi_margin: Margin to avoid jitter for choosing a PFN based on RSSI sort
  225. * criteria.
  226. * @bestn: number of best networks in each scan.
  227. * @mscan: number of scans recorded.
  228. * @repeat: minimum number of scan intervals before scan frequency changes
  229. * in adaptive scan.
  230. * @exp: exponent of 2 for maximum scan interval.
  231. * @slow_freq: slow scan period.
  232. */
  233. struct brcmf_pno_param_le {
  234. __le32 version;
  235. __le32 scan_freq;
  236. __le32 lost_network_timeout;
  237. __le16 flags;
  238. __le16 rssi_margin;
  239. u8 bestn;
  240. u8 mscan;
  241. u8 repeat;
  242. u8 exp;
  243. __le32 slow_freq;
  244. };
  245. /**
  246. * struct brcmf_pno_net_param_le - scan parameters per preferred network.
  247. *
  248. * @ssid: ssid name and its length.
  249. * @flags: bit2: hidden.
  250. * @infra: BSS vs IBSS.
  251. * @auth: Open vs Closed.
  252. * @wpa_auth: WPA type.
  253. * @wsec: wsec value.
  254. */
  255. struct brcmf_pno_net_param_le {
  256. struct brcmf_ssid_le ssid;
  257. __le32 flags;
  258. __le32 infra;
  259. __le32 auth;
  260. __le32 wpa_auth;
  261. __le32 wsec;
  262. };
  263. /**
  264. * struct brcmf_pno_net_info_le - information per found network.
  265. *
  266. * @bssid: BSS network identifier.
  267. * @channel: channel number only.
  268. * @SSID_len: length of ssid.
  269. * @SSID: ssid characters.
  270. * @RSSI: receive signal strength (in dBm).
  271. * @timestamp: age in seconds.
  272. */
  273. struct brcmf_pno_net_info_le {
  274. u8 bssid[ETH_ALEN];
  275. u8 channel;
  276. u8 SSID_len;
  277. u8 SSID[32];
  278. __le16 RSSI;
  279. __le16 timestamp;
  280. };
  281. /**
  282. * struct brcmf_pno_scanresults_le - result returned in PNO NET FOUND event.
  283. *
  284. * @version: PNO version identifier.
  285. * @status: indicates completion status of PNO scan.
  286. * @count: amount of brcmf_pno_net_info_le entries appended.
  287. */
  288. struct brcmf_pno_scanresults_le {
  289. __le32 version;
  290. __le32 status;
  291. __le32 count;
  292. };
  293. /**
  294. * struct brcmf_cfg80211_vif_event - virtual interface event information.
  295. *
  296. * @vif_wq: waitqueue awaiting interface event from firmware.
  297. * @vif_event_lock: protects other members in this structure.
  298. * @vif_complete: completion for net attach.
  299. * @action: either add, change, or delete.
  300. * @vif: virtual interface object related to the event.
  301. */
  302. struct brcmf_cfg80211_vif_event {
  303. wait_queue_head_t vif_wq;
  304. struct mutex vif_event_lock;
  305. struct completion vif_complete;
  306. u8 action;
  307. struct brcmf_cfg80211_vif *vif;
  308. };
  309. /**
  310. * struct brcmf_cfg80211_info - dongle private data of cfg80211 interface
  311. *
  312. * @wiphy: wiphy object for cfg80211 interface.
  313. * @conf: dongle configuration.
  314. * @p2p: peer-to-peer specific information.
  315. * @scan_request: cfg80211 scan request object.
  316. * @usr_sync: mainly for dongle up/down synchronization.
  317. * @bss_list: bss_list holding scanned ap information.
  318. * @scan_req_int: internal scan request object.
  319. * @bss_info: bss information for cfg80211 layer.
  320. * @ie: information element object for internal purpose.
  321. * @conn_info: association info.
  322. * @pmk_list: wpa2 pmk list.
  323. * @scan_status: scan activity on the dongle.
  324. * @pub: common driver information.
  325. * @channel: current channel.
  326. * @active_scan: current scan mode.
  327. * @sched_escan: e-scan for scheduled scan support running.
  328. * @ibss_starter: indicates this sta is ibss starter.
  329. * @pwr_save: indicate whether dongle to support power save mode.
  330. * @dongle_up: indicate whether dongle up or not.
  331. * @roam_on: on/off switch for dongle self-roaming.
  332. * @scan_tried: indicates if first scan attempted.
  333. * @dcmd_buf: dcmd buffer.
  334. * @extra_buf: mainly to grab assoc information.
  335. * @debugfsdir: debugfs folder for this device.
  336. * @escan_info: escan information.
  337. * @escan_timeout: Timer for catch scan timeout.
  338. * @escan_timeout_work: scan timeout worker.
  339. * @escan_ioctl_buf: dongle command buffer for escan commands.
  340. * @vif_list: linked list of vif instances.
  341. * @vif_cnt: number of vif instances.
  342. * @vif_event: vif event signalling.
  343. */
  344. struct brcmf_cfg80211_info {
  345. struct wiphy *wiphy;
  346. struct brcmf_cfg80211_conf *conf;
  347. struct brcmf_p2p_info p2p;
  348. struct cfg80211_scan_request *scan_request;
  349. struct mutex usr_sync;
  350. struct brcmf_scan_results *bss_list;
  351. struct brcmf_cfg80211_scan_req scan_req_int;
  352. struct wl_cfg80211_bss_info *bss_info;
  353. struct brcmf_cfg80211_ie ie;
  354. struct brcmf_cfg80211_connect_info conn_info;
  355. struct brcmf_cfg80211_pmk_list *pmk_list;
  356. unsigned long scan_status;
  357. struct brcmf_pub *pub;
  358. u32 channel;
  359. bool active_scan;
  360. bool sched_escan;
  361. bool ibss_starter;
  362. bool pwr_save;
  363. bool dongle_up;
  364. bool roam_on;
  365. bool scan_tried;
  366. u8 *dcmd_buf;
  367. u8 *extra_buf;
  368. struct dentry *debugfsdir;
  369. struct escan_info escan_info;
  370. struct timer_list escan_timeout;
  371. struct work_struct escan_timeout_work;
  372. u8 *escan_ioctl_buf;
  373. struct list_head vif_list;
  374. u8 vif_cnt;
  375. struct brcmf_cfg80211_vif_event vif_event;
  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. void brcmf_cfg80211_detach(struct brcmf_cfg80211_info *cfg);
  430. s32 brcmf_cfg80211_up(struct net_device *ndev);
  431. s32 brcmf_cfg80211_down(struct net_device *ndev);
  432. struct brcmf_cfg80211_vif *brcmf_alloc_vif(struct brcmf_cfg80211_info *cfg,
  433. enum nl80211_iftype type,
  434. bool pm_block);
  435. void brcmf_free_vif(struct brcmf_cfg80211_vif *vif);
  436. s32 brcmf_vif_set_mgmt_ie(struct brcmf_cfg80211_vif *vif, s32 pktflag,
  437. const u8 *vndr_ie_buf, u32 vndr_ie_len);
  438. struct brcmf_tlv *brcmf_parse_tlvs(void *buf, int buflen, uint key);
  439. u16 channel_to_chanspec(struct ieee80211_channel *ch);
  440. u32 wl_get_vif_state_all(struct brcmf_cfg80211_info *cfg, unsigned long state);
  441. void brcmf_cfg80211_arm_vif_event(struct brcmf_cfg80211_info *cfg,
  442. struct brcmf_cfg80211_vif *vif);
  443. bool brcmf_cfg80211_vif_event_armed(struct brcmf_cfg80211_info *cfg);
  444. int brcmf_cfg80211_wait_vif_event_timeout(struct brcmf_cfg80211_info *cfg,
  445. u8 action, ulong timeout);
  446. void brcmf_cfg80211_vif_complete(struct brcmf_cfg80211_info *info);
  447. #endif /* _wl_cfg80211_h_ */