wl_cfg80211.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511
  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. struct brcmf_cfg80211_conf;
  19. struct brcmf_cfg80211_iface;
  20. struct brcmf_cfg80211_priv;
  21. struct brcmf_cfg80211_security;
  22. struct brcmf_cfg80211_ibss;
  23. #define WL_DBG_NONE 0
  24. #define WL_DBG_CONN (1 << 5)
  25. #define WL_DBG_SCAN (1 << 4)
  26. #define WL_DBG_TRACE (1 << 3)
  27. #define WL_DBG_INFO (1 << 1)
  28. #define WL_DBG_ERR (1 << 0)
  29. #define WL_DBG_MASK ((WL_DBG_INFO | WL_DBG_ERR | WL_DBG_TRACE) | \
  30. (WL_DBG_SCAN) | (WL_DBG_CONN))
  31. #define WL_ERR(fmt, ...) \
  32. do { \
  33. if (brcmf_dbg_level & WL_DBG_ERR) { \
  34. if (net_ratelimit()) { \
  35. pr_err("ERROR @%s : " fmt, \
  36. __func__, ##__VA_ARGS__); \
  37. } \
  38. } \
  39. } while (0)
  40. #if (defined DEBUG)
  41. #define WL_INFO(fmt, ...) \
  42. do { \
  43. if (brcmf_dbg_level & WL_DBG_INFO) { \
  44. if (net_ratelimit()) { \
  45. pr_err("INFO @%s : " fmt, \
  46. __func__, ##__VA_ARGS__); \
  47. } \
  48. } \
  49. } while (0)
  50. #define WL_TRACE(fmt, ...) \
  51. do { \
  52. if (brcmf_dbg_level & WL_DBG_TRACE) { \
  53. if (net_ratelimit()) { \
  54. pr_err("TRACE @%s : " fmt, \
  55. __func__, ##__VA_ARGS__); \
  56. } \
  57. } \
  58. } while (0)
  59. #define WL_SCAN(fmt, ...) \
  60. do { \
  61. if (brcmf_dbg_level & WL_DBG_SCAN) { \
  62. if (net_ratelimit()) { \
  63. pr_err("SCAN @%s : " fmt, \
  64. __func__, ##__VA_ARGS__); \
  65. } \
  66. } \
  67. } while (0)
  68. #define WL_CONN(fmt, ...) \
  69. do { \
  70. if (brcmf_dbg_level & WL_DBG_CONN) { \
  71. if (net_ratelimit()) { \
  72. pr_err("CONN @%s : " fmt, \
  73. __func__, ##__VA_ARGS__); \
  74. } \
  75. } \
  76. } while (0)
  77. #else /* (defined DEBUG) */
  78. #define WL_INFO(fmt, args...)
  79. #define WL_TRACE(fmt, args...)
  80. #define WL_SCAN(fmt, args...)
  81. #define WL_CONN(fmt, args...)
  82. #endif /* (defined DEBUG) */
  83. #define WL_NUM_SCAN_MAX 1
  84. #define WL_NUM_PMKIDS_MAX MAXPMKID /* will be used
  85. * for 2.6.33 kernel
  86. * or later
  87. */
  88. #define WL_SCAN_BUF_MAX (1024 * 8)
  89. #define WL_TLV_INFO_MAX 1024
  90. #define WL_BSS_INFO_MAX 2048
  91. #define WL_ASSOC_INFO_MAX 512 /*
  92. * needs to grab assoc info from dongle to
  93. * report it to cfg80211 through "connect"
  94. * event
  95. */
  96. #define WL_DCMD_LEN_MAX 1024
  97. #define WL_EXTRA_BUF_MAX 2048
  98. #define WL_ISCAN_BUF_MAX 2048 /*
  99. * the buf length can be BRCMF_DCMD_MAXLEN
  100. * to reduce iteration
  101. */
  102. #define WL_ISCAN_TIMER_INTERVAL_MS 3000
  103. #define WL_SCAN_ERSULTS_LAST (BRCMF_SCAN_RESULTS_NO_MEM+1)
  104. #define WL_AP_MAX 256 /* virtually unlimitted as long
  105. * as kernel memory allows
  106. */
  107. #define WL_ROAM_TRIGGER_LEVEL -75
  108. #define WL_ROAM_DELTA 20
  109. #define WL_BEACON_TIMEOUT 3
  110. #define WL_SCAN_CHANNEL_TIME 40
  111. #define WL_SCAN_UNASSOC_TIME 40
  112. #define WL_SCAN_PASSIVE_TIME 120
  113. #define WL_ESCAN_BUF_SIZE (1024 * 64)
  114. #define WL_ESCAN_TIMER_INTERVAL_MS 8000 /* E-Scan timeout */
  115. #define WL_ESCAN_ACTION_START 1
  116. #define WL_ESCAN_ACTION_CONTINUE 2
  117. #define WL_ESCAN_ACTION_ABORT 3
  118. #define WL_AUTH_SHARED_KEY 1 /* d11 shared authentication */
  119. /* dongle status */
  120. enum wl_status {
  121. WL_STATUS_READY,
  122. WL_STATUS_SCANNING,
  123. WL_STATUS_SCAN_ABORTING,
  124. WL_STATUS_CONNECTING,
  125. WL_STATUS_CONNECTED
  126. };
  127. /* wi-fi mode */
  128. enum wl_mode {
  129. WL_MODE_BSS,
  130. WL_MODE_IBSS,
  131. WL_MODE_AP
  132. };
  133. /* dongle profile list */
  134. enum wl_prof_list {
  135. WL_PROF_MODE,
  136. WL_PROF_SSID,
  137. WL_PROF_SEC,
  138. WL_PROF_IBSS,
  139. WL_PROF_BAND,
  140. WL_PROF_BSSID,
  141. WL_PROF_ACT,
  142. WL_PROF_BEACONINT,
  143. WL_PROF_DTIMPERIOD
  144. };
  145. /* dongle iscan state */
  146. enum wl_iscan_state {
  147. WL_ISCAN_STATE_IDLE,
  148. WL_ISCAN_STATE_SCANING
  149. };
  150. /* dongle configuration */
  151. struct brcmf_cfg80211_conf {
  152. u32 mode; /* adhoc , infrastructure or ap */
  153. u32 frag_threshold;
  154. u32 rts_threshold;
  155. u32 retry_short;
  156. u32 retry_long;
  157. s32 tx_power;
  158. struct ieee80211_channel channel;
  159. };
  160. /* cfg80211 main event loop */
  161. struct brcmf_cfg80211_event_loop {
  162. s32(*handler[BRCMF_E_LAST]) (struct brcmf_cfg80211_priv *cfg_priv,
  163. struct net_device *ndev,
  164. const struct brcmf_event_msg *e,
  165. void *data);
  166. };
  167. /* representing interface of cfg80211 plane */
  168. struct brcmf_cfg80211_iface {
  169. struct brcmf_cfg80211_priv *cfg_priv;
  170. };
  171. struct brcmf_cfg80211_dev {
  172. void *driver_data; /* to store cfg80211 object information */
  173. };
  174. /* basic structure of scan request */
  175. struct brcmf_cfg80211_scan_req {
  176. struct brcmf_ssid_le ssid_le;
  177. };
  178. /* basic structure of information element */
  179. struct brcmf_cfg80211_ie {
  180. u16 offset;
  181. u8 buf[WL_TLV_INFO_MAX];
  182. };
  183. /* event queue for cfg80211 main event */
  184. struct brcmf_cfg80211_event_q {
  185. struct list_head evt_q_list;
  186. u32 etype;
  187. struct brcmf_event_msg emsg;
  188. s8 edata[1];
  189. };
  190. /* security information with currently associated ap */
  191. struct brcmf_cfg80211_security {
  192. u32 wpa_versions;
  193. u32 auth_type;
  194. u32 cipher_pairwise;
  195. u32 cipher_group;
  196. u32 wpa_auth;
  197. };
  198. /* ibss information for currently joined ibss network */
  199. struct brcmf_cfg80211_ibss {
  200. u8 beacon_interval; /* in millisecond */
  201. u8 atim; /* in millisecond */
  202. s8 join_only;
  203. u8 band;
  204. u8 channel;
  205. };
  206. /* dongle profile */
  207. struct brcmf_cfg80211_profile {
  208. u32 mode;
  209. struct brcmf_ssid ssid;
  210. u8 bssid[ETH_ALEN];
  211. u16 beacon_interval;
  212. u8 dtim_period;
  213. struct brcmf_cfg80211_security sec;
  214. struct brcmf_cfg80211_ibss ibss;
  215. s32 band;
  216. };
  217. /* dongle iscan event loop */
  218. struct brcmf_cfg80211_iscan_eloop {
  219. s32 (*handler[WL_SCAN_ERSULTS_LAST])
  220. (struct brcmf_cfg80211_priv *cfg_priv);
  221. };
  222. /* dongle iscan controller */
  223. struct brcmf_cfg80211_iscan_ctrl {
  224. struct net_device *ndev;
  225. struct timer_list timer;
  226. u32 timer_ms;
  227. u32 timer_on;
  228. s32 state;
  229. struct work_struct work;
  230. struct brcmf_cfg80211_iscan_eloop el;
  231. void *data;
  232. s8 dcmd_buf[BRCMF_DCMD_SMLEN];
  233. s8 scan_buf[WL_ISCAN_BUF_MAX];
  234. };
  235. /* association inform */
  236. struct brcmf_cfg80211_connect_info {
  237. u8 *req_ie;
  238. s32 req_ie_len;
  239. u8 *resp_ie;
  240. s32 resp_ie_len;
  241. };
  242. /* assoc ie length */
  243. struct brcmf_cfg80211_assoc_ielen_le {
  244. __le32 req_len;
  245. __le32 resp_len;
  246. };
  247. /* wpa2 pmk list */
  248. struct brcmf_cfg80211_pmk_list {
  249. struct pmkid_list pmkids;
  250. struct pmkid foo[MAXPMKID - 1];
  251. };
  252. /* dongle escan state */
  253. enum wl_escan_state {
  254. WL_ESCAN_STATE_IDLE,
  255. WL_ESCAN_STATE_SCANNING
  256. };
  257. struct escan_info {
  258. u32 escan_state;
  259. u8 escan_buf[WL_ESCAN_BUF_SIZE];
  260. struct wiphy *wiphy;
  261. struct net_device *ndev;
  262. };
  263. /**
  264. * struct brcmf_pno_param_le - PNO scan configuration parameters
  265. *
  266. * @version: PNO parameters version.
  267. * @scan_freq: scan frequency.
  268. * @lost_network_timeout: #sec. to declare discovered network as lost.
  269. * @flags: Bit field to control features of PFN such as sort criteria auto
  270. * enable switch and background scan.
  271. * @rssi_margin: Margin to avoid jitter for choosing a PFN based on RSSI sort
  272. * criteria.
  273. * @bestn: number of best networks in each scan.
  274. * @mscan: number of scans recorded.
  275. * @repeat: minimum number of scan intervals before scan frequency changes
  276. * in adaptive scan.
  277. * @exp: exponent of 2 for maximum scan interval.
  278. * @slow_freq: slow scan period.
  279. */
  280. struct brcmf_pno_param_le {
  281. __le32 version;
  282. __le32 scan_freq;
  283. __le32 lost_network_timeout;
  284. __le16 flags;
  285. __le16 rssi_margin;
  286. u8 bestn;
  287. u8 mscan;
  288. u8 repeat;
  289. u8 exp;
  290. __le32 slow_freq;
  291. };
  292. /**
  293. * struct brcmf_pno_net_param_le - scan parameters per preferred network.
  294. *
  295. * @ssid: ssid name and its length.
  296. * @flags: bit2: hidden.
  297. * @infra: BSS vs IBSS.
  298. * @auth: Open vs Closed.
  299. * @wpa_auth: WPA type.
  300. * @wsec: wsec value.
  301. */
  302. struct brcmf_pno_net_param_le {
  303. struct brcmf_ssid_le ssid;
  304. __le32 flags;
  305. __le32 infra;
  306. __le32 auth;
  307. __le32 wpa_auth;
  308. __le32 wsec;
  309. };
  310. /**
  311. * struct brcmf_pno_net_info_le - information per found network.
  312. *
  313. * @bssid: BSS network identifier.
  314. * @channel: channel number only.
  315. * @SSID_len: length of ssid.
  316. * @SSID: ssid characters.
  317. * @RSSI: receive signal strength (in dBm).
  318. * @timestamp: age in seconds.
  319. */
  320. struct brcmf_pno_net_info_le {
  321. u8 bssid[ETH_ALEN];
  322. u8 channel;
  323. u8 SSID_len;
  324. u8 SSID[32];
  325. __le16 RSSI;
  326. __le16 timestamp;
  327. };
  328. /**
  329. * struct brcmf_pno_scanresults_le - result returned in PNO NET FOUND event.
  330. *
  331. * @version: PNO version identifier.
  332. * @status: indicates completion status of PNO scan.
  333. * @count: amount of brcmf_pno_net_info_le entries appended.
  334. */
  335. struct brcmf_pno_scanresults_le {
  336. __le32 version;
  337. __le32 status;
  338. __le32 count;
  339. };
  340. /**
  341. * struct brcmf_cfg80211_priv - dongle private data of cfg80211 interface
  342. *
  343. * @wdev: representing wl cfg80211 device.
  344. * @conf: dongle configuration.
  345. * @scan_request: cfg80211 scan request object.
  346. * @el: main event loop.
  347. * @evt_q_list: used for event queue.
  348. * @evt_q_lock: for event queue synchronization.
  349. * @usr_sync: mainly for dongle up/down synchronization.
  350. * @bss_list: bss_list holding scanned ap information.
  351. * @scan_results: results of the last scan.
  352. * @scan_req_int: internal scan request object.
  353. * @bss_info: bss information for cfg80211 layer.
  354. * @ie: information element object for internal purpose.
  355. * @profile: holding dongle profile.
  356. * @iscan: iscan controller information.
  357. * @conn_info: association info.
  358. * @pmk_list: wpa2 pmk list.
  359. * @event_work: event handler work struct.
  360. * @status: current dongle status.
  361. * @pub: common driver information.
  362. * @channel: current channel.
  363. * @iscan_on: iscan on/off switch.
  364. * @iscan_kickstart: indicate iscan already started.
  365. * @active_scan: current scan mode.
  366. * @sched_escan: e-scan for scheduled scan support running.
  367. * @ibss_starter: indicates this sta is ibss starter.
  368. * @link_up: link/connection up flag.
  369. * @pwr_save: indicate whether dongle to support power save mode.
  370. * @dongle_up: indicate whether dongle up or not.
  371. * @roam_on: on/off switch for dongle self-roaming.
  372. * @scan_tried: indicates if first scan attempted.
  373. * @dcmd_buf: dcmd buffer.
  374. * @extra_buf: mainly to grab assoc information.
  375. * @debugfsdir: debugfs folder for this device.
  376. * @escan_on: escan on/off switch.
  377. * @escan_info: escan information.
  378. * @escan_timeout: Timer for catch scan timeout.
  379. * @escan_timeout_work: scan timeout worker.
  380. * @escan_ioctl_buf: dongle command buffer for escan commands.
  381. * @ci: used to link this structure to netdev private data.
  382. */
  383. struct brcmf_cfg80211_priv {
  384. struct wireless_dev *wdev;
  385. struct brcmf_cfg80211_conf *conf;
  386. struct cfg80211_scan_request *scan_request;
  387. struct brcmf_cfg80211_event_loop el;
  388. struct list_head evt_q_list;
  389. spinlock_t evt_q_lock;
  390. struct mutex usr_sync;
  391. struct brcmf_scan_results *bss_list;
  392. struct brcmf_scan_results *scan_results;
  393. struct brcmf_cfg80211_scan_req *scan_req_int;
  394. struct wl_cfg80211_bss_info *bss_info;
  395. struct brcmf_cfg80211_ie ie;
  396. struct brcmf_cfg80211_profile *profile;
  397. struct brcmf_cfg80211_iscan_ctrl *iscan;
  398. struct brcmf_cfg80211_connect_info conn_info;
  399. struct brcmf_cfg80211_pmk_list *pmk_list;
  400. struct work_struct event_work;
  401. unsigned long status;
  402. struct brcmf_pub *pub;
  403. u32 channel;
  404. bool iscan_on;
  405. bool iscan_kickstart;
  406. bool active_scan;
  407. bool sched_escan;
  408. bool ibss_starter;
  409. bool link_up;
  410. bool pwr_save;
  411. bool dongle_up;
  412. bool roam_on;
  413. bool scan_tried;
  414. u8 *dcmd_buf;
  415. u8 *extra_buf;
  416. struct dentry *debugfsdir;
  417. bool escan_on;
  418. struct escan_info escan_info;
  419. struct timer_list escan_timeout;
  420. struct work_struct escan_timeout_work;
  421. u8 *escan_ioctl_buf;
  422. u8 ci[0] __aligned(NETDEV_ALIGN);
  423. };
  424. static inline struct wiphy *cfg_to_wiphy(struct brcmf_cfg80211_priv *w)
  425. {
  426. return w->wdev->wiphy;
  427. }
  428. static inline struct brcmf_cfg80211_priv *wiphy_to_cfg(struct wiphy *w)
  429. {
  430. return (struct brcmf_cfg80211_priv *)(wiphy_priv(w));
  431. }
  432. static inline struct brcmf_cfg80211_priv *wdev_to_cfg(struct wireless_dev *wd)
  433. {
  434. return (struct brcmf_cfg80211_priv *)(wdev_priv(wd));
  435. }
  436. static inline struct net_device *cfg_to_ndev(struct brcmf_cfg80211_priv *cfg)
  437. {
  438. return cfg->wdev->netdev;
  439. }
  440. static inline struct brcmf_cfg80211_priv *ndev_to_cfg(struct net_device *ndev)
  441. {
  442. return wdev_to_cfg(ndev->ieee80211_ptr);
  443. }
  444. #define iscan_to_cfg(i) ((struct brcmf_cfg80211_priv *)(i->data))
  445. #define cfg_to_iscan(w) (w->iscan)
  446. static inline struct
  447. brcmf_cfg80211_connect_info *cfg_to_conn(struct brcmf_cfg80211_priv *cfg)
  448. {
  449. return &cfg->conn_info;
  450. }
  451. struct brcmf_cfg80211_priv *brcmf_cfg80211_attach(struct net_device *ndev,
  452. struct device *busdev,
  453. struct brcmf_pub *drvr);
  454. void brcmf_cfg80211_detach(struct brcmf_cfg80211_priv *cfg_priv);
  455. /* event handler from dongle */
  456. void brcmf_cfg80211_event(struct net_device *ndev,
  457. const struct brcmf_event_msg *e, void *data);
  458. s32 brcmf_cfg80211_up(struct brcmf_cfg80211_priv *cfg_priv);
  459. s32 brcmf_cfg80211_down(struct brcmf_cfg80211_priv *cfg_priv);
  460. #endif /* _wl_cfg80211_h_ */