wl_cfg80211.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  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_DBG_NONE 0
  19. #define WL_DBG_CONN (1 << 5)
  20. #define WL_DBG_SCAN (1 << 4)
  21. #define WL_DBG_TRACE (1 << 3)
  22. #define WL_DBG_INFO (1 << 1)
  23. #define WL_DBG_ERR (1 << 0)
  24. #define WL_DBG_MASK ((WL_DBG_INFO | WL_DBG_ERR | WL_DBG_TRACE) | \
  25. (WL_DBG_SCAN) | (WL_DBG_CONN))
  26. #define WL_ERR(fmt, ...) \
  27. do { \
  28. if (brcmf_dbg_level & WL_DBG_ERR) { \
  29. if (net_ratelimit()) { \
  30. pr_err("ERROR @%s : " fmt, \
  31. __func__, ##__VA_ARGS__); \
  32. } \
  33. } \
  34. } while (0)
  35. #if (defined DEBUG)
  36. #define WL_INFO(fmt, ...) \
  37. do { \
  38. if (brcmf_dbg_level & WL_DBG_INFO) { \
  39. if (net_ratelimit()) { \
  40. pr_err("INFO @%s : " fmt, \
  41. __func__, ##__VA_ARGS__); \
  42. } \
  43. } \
  44. } while (0)
  45. #define WL_TRACE(fmt, ...) \
  46. do { \
  47. if (brcmf_dbg_level & WL_DBG_TRACE) { \
  48. if (net_ratelimit()) { \
  49. pr_err("TRACE @%s : " fmt, \
  50. __func__, ##__VA_ARGS__); \
  51. } \
  52. } \
  53. } while (0)
  54. #define WL_SCAN(fmt, ...) \
  55. do { \
  56. if (brcmf_dbg_level & WL_DBG_SCAN) { \
  57. if (net_ratelimit()) { \
  58. pr_err("SCAN @%s : " fmt, \
  59. __func__, ##__VA_ARGS__); \
  60. } \
  61. } \
  62. } while (0)
  63. #define WL_CONN(fmt, ...) \
  64. do { \
  65. if (brcmf_dbg_level & WL_DBG_CONN) { \
  66. if (net_ratelimit()) { \
  67. pr_err("CONN @%s : " fmt, \
  68. __func__, ##__VA_ARGS__); \
  69. } \
  70. } \
  71. } while (0)
  72. #else /* (defined DEBUG) */
  73. #define WL_INFO(fmt, args...)
  74. #define WL_TRACE(fmt, args...)
  75. #define WL_SCAN(fmt, args...)
  76. #define WL_CONN(fmt, args...)
  77. #endif /* (defined DEBUG) */
  78. #define WL_NUM_SCAN_MAX 10
  79. #define WL_NUM_PMKIDS_MAX MAXPMKID
  80. #define WL_TLV_INFO_MAX 1024
  81. #define WL_BSS_INFO_MAX 2048
  82. #define WL_ASSOC_INFO_MAX 512 /* assoc related fil max buf */
  83. #define WL_EXTRA_BUF_MAX 2048
  84. #define WL_ROAM_TRIGGER_LEVEL -75
  85. #define WL_ROAM_DELTA 20
  86. #define WL_BEACON_TIMEOUT 3
  87. #define WL_SCAN_CHANNEL_TIME 40
  88. #define WL_SCAN_UNASSOC_TIME 40
  89. #define WL_SCAN_PASSIVE_TIME 120
  90. #define WL_ESCAN_BUF_SIZE (1024 * 64)
  91. #define WL_ESCAN_TIMER_INTERVAL_MS 8000 /* E-Scan timeout */
  92. #define WL_ESCAN_ACTION_START 1
  93. #define WL_ESCAN_ACTION_CONTINUE 2
  94. #define WL_ESCAN_ACTION_ABORT 3
  95. #define WL_AUTH_SHARED_KEY 1 /* d11 shared authentication */
  96. #define IE_MAX_LEN 512
  97. /**
  98. * enum brcmf_scan_status - dongle scan status
  99. *
  100. * @BRCMF_SCAN_STATUS_BUSY: scanning in progress on dongle.
  101. * @BRCMF_SCAN_STATUS_ABORT: scan being aborted on dongle.
  102. */
  103. enum brcmf_scan_status {
  104. BRCMF_SCAN_STATUS_BUSY,
  105. BRCMF_SCAN_STATUS_ABORT,
  106. };
  107. /* wi-fi mode */
  108. enum wl_mode {
  109. WL_MODE_BSS,
  110. WL_MODE_IBSS,
  111. WL_MODE_AP
  112. };
  113. /* dongle configuration */
  114. struct brcmf_cfg80211_conf {
  115. u32 mode; /* adhoc , infrastructure or ap */
  116. u32 frag_threshold;
  117. u32 rts_threshold;
  118. u32 retry_short;
  119. u32 retry_long;
  120. s32 tx_power;
  121. struct ieee80211_channel channel;
  122. };
  123. /* basic structure of scan request */
  124. struct brcmf_cfg80211_scan_req {
  125. struct brcmf_ssid_le ssid_le;
  126. };
  127. /* basic structure of information element */
  128. struct brcmf_cfg80211_ie {
  129. u16 offset;
  130. u8 buf[WL_TLV_INFO_MAX];
  131. };
  132. /* security information with currently associated ap */
  133. struct brcmf_cfg80211_security {
  134. u32 wpa_versions;
  135. u32 auth_type;
  136. u32 cipher_pairwise;
  137. u32 cipher_group;
  138. u32 wpa_auth;
  139. };
  140. /**
  141. * struct brcmf_cfg80211_profile - profile information.
  142. *
  143. * @ssid: ssid of associated/associating ap.
  144. * @bssid: bssid of joined/joining ibss.
  145. * @sec: security information.
  146. */
  147. struct brcmf_cfg80211_profile {
  148. struct brcmf_ssid ssid;
  149. u8 bssid[ETH_ALEN];
  150. struct brcmf_cfg80211_security sec;
  151. };
  152. /**
  153. * enum brcmf_vif_status - bit indices for vif status.
  154. *
  155. * @BRCMF_VIF_STATUS_READY: ready for operation.
  156. * @BRCMF_VIF_STATUS_CONNECTING: connect/join in progress.
  157. * @BRCMF_VIF_STATUS_CONNECTED: connected/joined succesfully.
  158. * @BRCMF_VIF_STATUS_AP_CREATING: interface configured for AP operation.
  159. * @BRCMF_VIF_STATUS_AP_CREATED: AP operation started.
  160. */
  161. enum brcmf_vif_status {
  162. BRCMF_VIF_STATUS_READY,
  163. BRCMF_VIF_STATUS_CONNECTING,
  164. BRCMF_VIF_STATUS_CONNECTED,
  165. BRCMF_VIF_STATUS_AP_CREATING,
  166. BRCMF_VIF_STATUS_AP_CREATED
  167. };
  168. /**
  169. * struct vif_saved_ie - holds saved IEs for a virtual interface.
  170. *
  171. * @probe_res_ie: IE info for probe response.
  172. * @beacon_ie: IE info for beacon frame.
  173. * @probe_res_ie_len: IE info length for probe response.
  174. * @beacon_ie_len: IE info length for beacon frame.
  175. */
  176. struct vif_saved_ie {
  177. u8 probe_res_ie[IE_MAX_LEN];
  178. u8 beacon_ie[IE_MAX_LEN];
  179. u32 probe_res_ie_len;
  180. u32 beacon_ie_len;
  181. };
  182. /**
  183. * struct brcmf_cfg80211_vif - virtual interface specific information.
  184. *
  185. * @ifp: lower layer interface pointer
  186. * @wdev: wireless device.
  187. * @profile: profile information.
  188. * @mode: operating mode.
  189. * @roam_off: roaming state.
  190. * @sme_state: SME state using enum brcmf_vif_status bits.
  191. * @pm_block: power-management blocked.
  192. * @list: linked list.
  193. */
  194. struct brcmf_cfg80211_vif {
  195. struct brcmf_if *ifp;
  196. struct wireless_dev wdev;
  197. struct brcmf_cfg80211_profile profile;
  198. s32 mode;
  199. s32 roam_off;
  200. unsigned long sme_state;
  201. bool pm_block;
  202. struct vif_saved_ie saved_ie;
  203. struct list_head list;
  204. };
  205. /* association inform */
  206. struct brcmf_cfg80211_connect_info {
  207. u8 *req_ie;
  208. s32 req_ie_len;
  209. u8 *resp_ie;
  210. s32 resp_ie_len;
  211. };
  212. /* assoc ie length */
  213. struct brcmf_cfg80211_assoc_ielen_le {
  214. __le32 req_len;
  215. __le32 resp_len;
  216. };
  217. /* wpa2 pmk list */
  218. struct brcmf_cfg80211_pmk_list {
  219. struct pmkid_list pmkids;
  220. struct pmkid foo[MAXPMKID - 1];
  221. };
  222. /* dongle escan state */
  223. enum wl_escan_state {
  224. WL_ESCAN_STATE_IDLE,
  225. WL_ESCAN_STATE_SCANNING
  226. };
  227. struct escan_info {
  228. u32 escan_state;
  229. u8 escan_buf[WL_ESCAN_BUF_SIZE];
  230. struct wiphy *wiphy;
  231. struct net_device *ndev;
  232. };
  233. /**
  234. * struct brcmf_pno_param_le - PNO scan configuration parameters
  235. *
  236. * @version: PNO parameters version.
  237. * @scan_freq: scan frequency.
  238. * @lost_network_timeout: #sec. to declare discovered network as lost.
  239. * @flags: Bit field to control features of PFN such as sort criteria auto
  240. * enable switch and background scan.
  241. * @rssi_margin: Margin to avoid jitter for choosing a PFN based on RSSI sort
  242. * criteria.
  243. * @bestn: number of best networks in each scan.
  244. * @mscan: number of scans recorded.
  245. * @repeat: minimum number of scan intervals before scan frequency changes
  246. * in adaptive scan.
  247. * @exp: exponent of 2 for maximum scan interval.
  248. * @slow_freq: slow scan period.
  249. */
  250. struct brcmf_pno_param_le {
  251. __le32 version;
  252. __le32 scan_freq;
  253. __le32 lost_network_timeout;
  254. __le16 flags;
  255. __le16 rssi_margin;
  256. u8 bestn;
  257. u8 mscan;
  258. u8 repeat;
  259. u8 exp;
  260. __le32 slow_freq;
  261. };
  262. /**
  263. * struct brcmf_pno_net_param_le - scan parameters per preferred network.
  264. *
  265. * @ssid: ssid name and its length.
  266. * @flags: bit2: hidden.
  267. * @infra: BSS vs IBSS.
  268. * @auth: Open vs Closed.
  269. * @wpa_auth: WPA type.
  270. * @wsec: wsec value.
  271. */
  272. struct brcmf_pno_net_param_le {
  273. struct brcmf_ssid_le ssid;
  274. __le32 flags;
  275. __le32 infra;
  276. __le32 auth;
  277. __le32 wpa_auth;
  278. __le32 wsec;
  279. };
  280. /**
  281. * struct brcmf_pno_net_info_le - information per found network.
  282. *
  283. * @bssid: BSS network identifier.
  284. * @channel: channel number only.
  285. * @SSID_len: length of ssid.
  286. * @SSID: ssid characters.
  287. * @RSSI: receive signal strength (in dBm).
  288. * @timestamp: age in seconds.
  289. */
  290. struct brcmf_pno_net_info_le {
  291. u8 bssid[ETH_ALEN];
  292. u8 channel;
  293. u8 SSID_len;
  294. u8 SSID[32];
  295. __le16 RSSI;
  296. __le16 timestamp;
  297. };
  298. /**
  299. * struct brcmf_pno_scanresults_le - result returned in PNO NET FOUND event.
  300. *
  301. * @version: PNO version identifier.
  302. * @status: indicates completion status of PNO scan.
  303. * @count: amount of brcmf_pno_net_info_le entries appended.
  304. */
  305. struct brcmf_pno_scanresults_le {
  306. __le32 version;
  307. __le32 status;
  308. __le32 count;
  309. };
  310. /**
  311. * struct brcmf_cfg80211_info - dongle private data of cfg80211 interface
  312. *
  313. * @wiphy: wiphy object for cfg80211 interface.
  314. * @conf: dongle configuration.
  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. * @link_up: link/connection up flag.
  330. * @pwr_save: indicate whether dongle to support power save mode.
  331. * @dongle_up: indicate whether dongle up or not.
  332. * @roam_on: on/off switch for dongle self-roaming.
  333. * @scan_tried: indicates if first scan attempted.
  334. * @dcmd_buf: dcmd buffer.
  335. * @extra_buf: mainly to grab assoc information.
  336. * @debugfsdir: debugfs folder for this device.
  337. * @escan_info: escan information.
  338. * @escan_timeout: Timer for catch scan timeout.
  339. * @escan_timeout_work: scan timeout worker.
  340. * @escan_ioctl_buf: dongle command buffer for escan commands.
  341. * @vif_list: linked list of vif instances.
  342. * @vif_cnt: number of vif instances.
  343. */
  344. struct brcmf_cfg80211_info {
  345. struct wiphy *wiphy;
  346. struct brcmf_cfg80211_conf *conf;
  347. struct cfg80211_scan_request *scan_request;
  348. struct mutex usr_sync;
  349. struct brcmf_scan_results *bss_list;
  350. struct brcmf_cfg80211_scan_req scan_req_int;
  351. struct wl_cfg80211_bss_info *bss_info;
  352. struct brcmf_cfg80211_ie ie;
  353. struct brcmf_cfg80211_connect_info conn_info;
  354. struct brcmf_cfg80211_pmk_list *pmk_list;
  355. unsigned long scan_status;
  356. struct brcmf_pub *pub;
  357. u32 channel;
  358. bool active_scan;
  359. bool sched_escan;
  360. bool ibss_starter;
  361. bool link_up;
  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. };
  376. static inline struct wiphy *cfg_to_wiphy(struct brcmf_cfg80211_info *cfg)
  377. {
  378. return cfg->wiphy;
  379. }
  380. static inline struct brcmf_cfg80211_info *wiphy_to_cfg(struct wiphy *w)
  381. {
  382. return (struct brcmf_cfg80211_info *)(wiphy_priv(w));
  383. }
  384. static inline struct brcmf_cfg80211_info *wdev_to_cfg(struct wireless_dev *wd)
  385. {
  386. return (struct brcmf_cfg80211_info *)(wdev_priv(wd));
  387. }
  388. static inline
  389. struct net_device *cfg_to_ndev(struct brcmf_cfg80211_info *cfg)
  390. {
  391. struct brcmf_cfg80211_vif *vif;
  392. vif = list_first_entry(&cfg->vif_list, struct brcmf_cfg80211_vif, list);
  393. return vif->wdev.netdev;
  394. }
  395. static inline struct brcmf_cfg80211_info *ndev_to_cfg(struct net_device *ndev)
  396. {
  397. return wdev_to_cfg(ndev->ieee80211_ptr);
  398. }
  399. static inline struct brcmf_cfg80211_profile *ndev_to_prof(struct net_device *nd)
  400. {
  401. struct brcmf_if *ifp = netdev_priv(nd);
  402. return &ifp->vif->profile;
  403. }
  404. static inline struct brcmf_cfg80211_vif *ndev_to_vif(struct net_device *ndev)
  405. {
  406. struct brcmf_if *ifp = netdev_priv(ndev);
  407. return ifp->vif;
  408. }
  409. static inline struct
  410. brcmf_cfg80211_connect_info *cfg_to_conn(struct brcmf_cfg80211_info *cfg)
  411. {
  412. return &cfg->conn_info;
  413. }
  414. struct brcmf_cfg80211_info *brcmf_cfg80211_attach(struct brcmf_pub *drvr);
  415. void brcmf_cfg80211_detach(struct brcmf_cfg80211_info *cfg);
  416. s32 brcmf_cfg80211_up(struct net_device *ndev);
  417. s32 brcmf_cfg80211_down(struct net_device *ndev);
  418. #endif /* _wl_cfg80211_h_ */