wl_cfg80211.h 13 KB

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