Commit | Line | Data |
---|---|---|
cf2b4488 HP |
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 | ||
17 | #ifndef _wl_cfg80211_h_ | |
18 | #define _wl_cfg80211_h_ | |
19 | ||
cf2b4488 HP |
20 | struct wl_conf; |
21 | struct wl_iface; | |
22 | struct wl_priv; | |
23 | struct wl_security; | |
24 | struct wl_ibss; | |
25 | ||
1ce4784e SS |
26 | #define WL_DBG_NONE 0 |
27 | #define WL_DBG_CONN (1 << 5) | |
28 | #define WL_DBG_SCAN (1 << 4) | |
29 | #define WL_DBG_TRACE (1 << 3) | |
30 | #define WL_DBG_INFO (1 << 1) | |
31 | #define WL_DBG_ERR (1 << 0) | |
32 | #define WL_DBG_MASK ((WL_DBG_INFO | WL_DBG_ERR | WL_DBG_TRACE) | \ | |
33 | (WL_DBG_SCAN) | (WL_DBG_CONN)) | |
cf2b4488 | 34 | |
f4528696 JP |
35 | #define WL_ERR(fmt, args...) \ |
36 | do { \ | |
8817f754 | 37 | if (brcmf_dbg_level & WL_DBG_ERR) { \ |
f4528696 JP |
38 | if (net_ratelimit()) { \ |
39 | printk(KERN_ERR "ERROR @%s : " fmt, \ | |
1ce4784e | 40 | __func__, ##args); \ |
f4528696 JP |
41 | } \ |
42 | } \ | |
cf2b4488 | 43 | } while (0) |
f4528696 | 44 | |
1ce4784e | 45 | #if (defined BCMDBG) |
f4528696 JP |
46 | #define WL_INFO(fmt, args...) \ |
47 | do { \ | |
8817f754 | 48 | if (brcmf_dbg_level & WL_DBG_INFO) { \ |
f4528696 JP |
49 | if (net_ratelimit()) { \ |
50 | printk(KERN_ERR "INFO @%s : " fmt, \ | |
1ce4784e | 51 | __func__, ##args); \ |
f4528696 JP |
52 | } \ |
53 | } \ | |
cf2b4488 | 54 | } while (0) |
f4528696 | 55 | |
1ce4784e | 56 | #define WL_TRACE(fmt, args...) \ |
f4528696 | 57 | do { \ |
8817f754 | 58 | if (brcmf_dbg_level & WL_DBG_TRACE) { \ |
1ce4784e SS |
59 | if (net_ratelimit()) { \ |
60 | printk(KERN_ERR "TRACE @%s : " fmt, \ | |
61 | __func__, ##args); \ | |
62 | } \ | |
63 | } \ | |
64 | } while (0) | |
65 | ||
66 | #define WL_SCAN(fmt, args...) \ | |
67 | do { \ | |
8817f754 | 68 | if (brcmf_dbg_level & WL_DBG_SCAN) { \ |
1ce4784e SS |
69 | if (net_ratelimit()) { \ |
70 | printk(KERN_ERR "SCAN @%s : " fmt, \ | |
71 | __func__, ##args); \ | |
72 | } \ | |
f4528696 | 73 | } \ |
cf2b4488 | 74 | } while (0) |
1ce4784e SS |
75 | |
76 | #define WL_CONN(fmt, args...) \ | |
77 | do { \ | |
8817f754 | 78 | if (brcmf_dbg_level & WL_DBG_CONN) { \ |
1ce4784e SS |
79 | if (net_ratelimit()) { \ |
80 | printk(KERN_ERR "CONN @%s : " fmt, \ | |
81 | __func__, ##args); \ | |
82 | } \ | |
83 | } \ | |
84 | } while (0) | |
85 | ||
86 | #else /* (defined BCMDBG) */ | |
87 | #define WL_INFO(fmt, args...) | |
88 | #define WL_TRACE(fmt, args...) | |
89 | #define WL_SCAN(fmt, args...) | |
90 | #define WL_CONN(fmt, args...) | |
91 | #endif /* (defined BCMDBG) */ | |
92 | ||
cf2b4488 HP |
93 | |
94 | #define WL_SCAN_RETRY_MAX 3 /* used for ibss scan */ | |
95 | #define WL_NUM_SCAN_MAX 1 | |
96 | #define WL_NUM_PMKIDS_MAX MAXPMKID /* will be used | |
97 | * for 2.6.33 kernel | |
98 | * or later | |
99 | */ | |
8a76f1ee HP |
100 | #define WL_SCAN_BUF_MAX (1024 * 8) |
101 | #define WL_TLV_INFO_MAX 1024 | |
cf2b4488 HP |
102 | #define WL_BSS_INFO_MAX 2048 |
103 | #define WL_ASSOC_INFO_MAX 512 /* | |
104 | * needs to grab assoc info from dongle to | |
105 | * report it to cfg80211 through "connect" | |
106 | * event | |
107 | */ | |
108 | #define WL_IOCTL_LEN_MAX 1024 | |
109 | #define WL_EXTRA_BUF_MAX 2048 | |
110 | #define WL_ISCAN_BUF_MAX 2048 /* | |
366bbb3f | 111 | * the buf length can be BRCMF_C_IOCTL_MAXLEN |
cf2b4488 HP |
112 | * to reduce iteration |
113 | */ | |
114 | #define WL_ISCAN_TIMER_INTERVAL_MS 3000 | |
40695d1a | 115 | #define WL_SCAN_ERSULTS_LAST (BRCMF_SCAN_RESULTS_NO_MEM+1) |
cf2b4488 HP |
116 | #define WL_AP_MAX 256 /* virtually unlimitted as long |
117 | * as kernel memory allows | |
118 | */ | |
cf2b4488 | 119 | |
a1e962b6 SS |
120 | #define WL_ROAM_TRIGGER_LEVEL -75 |
121 | #define WL_ROAM_DELTA 20 | |
122 | #define WL_BEACON_TIMEOUT 3 | |
123 | ||
e4dd6325 SS |
124 | #define WL_SCAN_CHANNEL_TIME 40 |
125 | #define WL_SCAN_UNASSOC_TIME 40 | |
126 | #define WL_SCAN_PASSIVE_TIME 120 | |
127 | ||
cf2b4488 HP |
128 | /* dongle status */ |
129 | enum wl_status { | |
130 | WL_STATUS_READY, | |
131 | WL_STATUS_SCANNING, | |
132 | WL_STATUS_SCAN_ABORTING, | |
133 | WL_STATUS_CONNECTING, | |
134 | WL_STATUS_CONNECTED | |
135 | }; | |
136 | ||
137 | /* wi-fi mode */ | |
138 | enum wl_mode { | |
139 | WL_MODE_BSS, | |
140 | WL_MODE_IBSS, | |
141 | WL_MODE_AP | |
142 | }; | |
143 | ||
144 | /* dongle profile list */ | |
145 | enum wl_prof_list { | |
146 | WL_PROF_MODE, | |
147 | WL_PROF_SSID, | |
148 | WL_PROF_SEC, | |
149 | WL_PROF_IBSS, | |
150 | WL_PROF_BAND, | |
151 | WL_PROF_BSSID, | |
1e0645c3 | 152 | WL_PROF_ACT, |
153 | WL_PROF_BEACONINT, | |
154 | WL_PROF_DTIMPERIOD | |
cf2b4488 HP |
155 | }; |
156 | ||
157 | /* dongle iscan state */ | |
158 | enum wl_iscan_state { | |
159 | WL_ISCAN_STATE_IDLE, | |
160 | WL_ISCAN_STATE_SCANING | |
161 | }; | |
162 | ||
c5ca038f | 163 | /* beacon / probe_response */ |
164 | struct beacon_proberesp { | |
165 | __le64 timestamp; | |
166 | __le16 beacon_int; | |
167 | __le16 capab_info; | |
168 | u8 variable[0]; | |
169 | } __attribute__ ((packed)); | |
170 | ||
cf2b4488 HP |
171 | /* dongle configuration */ |
172 | struct wl_conf { | |
66cbd3ab GKH |
173 | u32 mode; /* adhoc , infrastructure or ap */ |
174 | u32 frag_threshold; | |
175 | u32 rts_threshold; | |
176 | u32 retry_short; | |
177 | u32 retry_long; | |
3e26416e | 178 | s32 tx_power; |
cf2b4488 HP |
179 | struct ieee80211_channel channel; |
180 | }; | |
181 | ||
182 | /* cfg80211 main event loop */ | |
183 | struct wl_event_loop { | |
05dc0f43 | 184 | s32(*handler[BRCMF_E_LAST]) (struct wl_priv *wl, |
cf2b4488 | 185 | struct net_device *ndev, |
63bec49e RV |
186 | const struct brcmf_event_msg *e, |
187 | void *data); | |
cf2b4488 HP |
188 | }; |
189 | ||
190 | /* representing interface of cfg80211 plane */ | |
191 | struct wl_iface { | |
192 | struct wl_priv *wl; | |
193 | }; | |
194 | ||
195 | struct wl_dev { | |
196 | void *driver_data; /* to store cfg80211 object information */ | |
197 | }; | |
198 | ||
199 | /* bss inform structure for cfg80211 interface */ | |
200 | struct wl_cfg80211_bss_info { | |
7d4df48e GKH |
201 | u16 band; |
202 | u16 channel; | |
e59fe083 | 203 | s16 rssi; |
7d4df48e | 204 | u16 frame_len; |
3fd79f7c | 205 | u8 frame_buf[1]; |
cf2b4488 HP |
206 | }; |
207 | ||
208 | /* basic structure of scan request */ | |
209 | struct wl_scan_req { | |
ec66c6fa | 210 | struct brcmf_ssid ssid; |
cf2b4488 HP |
211 | }; |
212 | ||
213 | /* basic structure of information element */ | |
214 | struct wl_ie { | |
7d4df48e | 215 | u16 offset; |
3fd79f7c | 216 | u8 buf[WL_TLV_INFO_MAX]; |
cf2b4488 HP |
217 | }; |
218 | ||
219 | /* event queue for cfg80211 main event */ | |
220 | struct wl_event_q { | |
221 | struct list_head eq_list; | |
66cbd3ab | 222 | u32 etype; |
63bec49e | 223 | struct brcmf_event_msg emsg; |
562c8850 | 224 | s8 edata[1]; |
cf2b4488 HP |
225 | }; |
226 | ||
227 | /* security information with currently associated ap */ | |
228 | struct wl_security { | |
66cbd3ab GKH |
229 | u32 wpa_versions; |
230 | u32 auth_type; | |
231 | u32 cipher_pairwise; | |
232 | u32 cipher_group; | |
233 | u32 wpa_auth; | |
cf2b4488 HP |
234 | }; |
235 | ||
236 | /* ibss information for currently joined ibss network */ | |
237 | struct wl_ibss { | |
3fd79f7c GKH |
238 | u8 beacon_interval; /* in millisecond */ |
239 | u8 atim; /* in millisecond */ | |
562c8850 | 240 | s8 join_only; |
3fd79f7c GKH |
241 | u8 band; |
242 | u8 channel; | |
cf2b4488 HP |
243 | }; |
244 | ||
245 | /* dongle profile */ | |
246 | struct wl_profile { | |
66cbd3ab | 247 | u32 mode; |
ec66c6fa | 248 | struct brcmf_ssid ssid; |
b8d63078 | 249 | u8 bssid[ETH_ALEN]; |
1e0645c3 | 250 | u16 beacon_interval; |
251 | u8 dtim_period; | |
cf2b4488 HP |
252 | struct wl_security sec; |
253 | struct wl_ibss ibss; | |
3e26416e | 254 | s32 band; |
cf2b4488 HP |
255 | }; |
256 | ||
257 | /* dongle iscan event loop */ | |
258 | struct wl_iscan_eloop { | |
3e26416e | 259 | s32(*handler[WL_SCAN_ERSULTS_LAST]) (struct wl_priv *wl); |
cf2b4488 HP |
260 | }; |
261 | ||
262 | /* dongle iscan controller */ | |
263 | struct wl_iscan_ctrl { | |
264 | struct net_device *dev; | |
265 | struct timer_list timer; | |
66cbd3ab GKH |
266 | u32 timer_ms; |
267 | u32 timer_on; | |
3e26416e | 268 | s32 state; |
7716314b | 269 | struct task_struct *tsk; |
cf2b4488 | 270 | struct semaphore sync; |
cf2b4488 HP |
271 | struct wl_iscan_eloop el; |
272 | void *data; | |
366bbb3f | 273 | s8 ioctl_buf[BRCMF_C_IOCTL_SMLEN]; |
562c8850 | 274 | s8 scan_buf[WL_ISCAN_BUF_MAX]; |
cf2b4488 HP |
275 | }; |
276 | ||
277 | /* association inform */ | |
278 | struct wl_connect_info { | |
3fd79f7c | 279 | u8 *req_ie; |
3e26416e | 280 | s32 req_ie_len; |
3fd79f7c | 281 | u8 *resp_ie; |
3e26416e | 282 | s32 resp_ie_len; |
cf2b4488 HP |
283 | }; |
284 | ||
cf2b4488 HP |
285 | /* assoc ie length */ |
286 | struct wl_assoc_ielen { | |
66cbd3ab GKH |
287 | u32 req_len; |
288 | u32 resp_len; | |
cf2b4488 HP |
289 | }; |
290 | ||
291 | /* wpa2 pmk list */ | |
292 | struct wl_pmk_list { | |
293 | pmkid_list_t pmkids; | |
294 | pmkid_t foo[MAXPMKID - 1]; | |
295 | }; | |
296 | ||
297 | /* dongle private data of cfg80211 interface */ | |
298 | struct wl_priv { | |
299 | struct wireless_dev *wdev; /* representing wl cfg80211 device */ | |
300 | struct wl_conf *conf; /* dongle configuration */ | |
301 | struct cfg80211_scan_request *scan_request; /* scan request | |
302 | object */ | |
303 | struct wl_event_loop el; /* main event loop */ | |
304 | struct list_head eq_list; /* used for event queue */ | |
305 | spinlock_t eq_lock; /* for event queue synchronization */ | |
306 | struct mutex usr_sync; /* maily for dongle up/down synchronization */ | |
ec66c6fa | 307 | struct brcmf_scan_results *bss_list; /* bss_list holding scanned |
cf2b4488 | 308 | ap information */ |
ec66c6fa | 309 | struct brcmf_scan_results *scan_results; |
cf2b4488 HP |
310 | struct wl_scan_req *scan_req_int; /* scan request object for |
311 | internal purpose */ | |
312 | struct wl_cfg80211_bss_info *bss_info; /* bss information for | |
313 | cfg80211 layer */ | |
314 | struct wl_ie ie; /* information element object for | |
315 | internal purpose */ | |
cf2b4488 HP |
316 | struct semaphore event_sync; /* for synchronization of main event |
317 | thread */ | |
cf2b4488 HP |
318 | struct wl_profile *profile; /* holding dongle profile */ |
319 | struct wl_iscan_ctrl *iscan; /* iscan controller */ | |
320 | struct wl_connect_info conn_info; /* association information | |
321 | container */ | |
cf2b4488 | 322 | struct wl_pmk_list *pmk_list; /* wpa2 pmk list */ |
7716314b | 323 | struct task_struct *event_tsk; /* task of main event handler thread */ |
3deea904 | 324 | unsigned long status; /* current dongle status */ |
cf2b4488 | 325 | void *pub; |
66cbd3ab | 326 | u32 channel; /* current channel */ |
cf2b4488 HP |
327 | bool iscan_on; /* iscan on/off switch */ |
328 | bool iscan_kickstart; /* indicate iscan already started */ | |
329 | bool active_scan; /* current scan mode */ | |
330 | bool ibss_starter; /* indicates this sta is ibss starter */ | |
331 | bool link_up; /* link/connection up flag */ | |
332 | bool pwr_save; /* indicate whether dongle to support | |
333 | power save mode */ | |
334 | bool dongle_up; /* indicate whether dongle up or not */ | |
335 | bool roam_on; /* on/off switch for dongle self-roaming */ | |
336 | bool scan_tried; /* indicates if first scan attempted */ | |
3fd79f7c GKH |
337 | u8 *ioctl_buf; /* ioctl buffer */ |
338 | u8 *extra_buf; /* maily to grab assoc information */ | |
cd389a34 | 339 | struct dentry *debugfsdir; |
3fd79f7c | 340 | u8 ci[0] __attribute__ ((__aligned__(NETDEV_ALIGN))); |
cf2b4488 HP |
341 | }; |
342 | ||
343 | #define wl_to_dev(w) (wiphy_dev(wl->wdev->wiphy)) | |
344 | #define wl_to_wiphy(w) (w->wdev->wiphy) | |
345 | #define wiphy_to_wl(w) ((struct wl_priv *)(wiphy_priv(w))) | |
346 | #define wl_to_wdev(w) (w->wdev) | |
347 | #define wdev_to_wl(w) ((struct wl_priv *)(wdev_priv(w))) | |
348 | #define wl_to_ndev(w) (w->wdev->netdev) | |
349 | #define ndev_to_wl(n) (wdev_to_wl(n->ieee80211_ptr)) | |
350 | #define ci_to_wl(c) (ci->wl) | |
351 | #define wl_to_ci(w) (&w->ci) | |
352 | #define wl_to_sr(w) (w->scan_req_int) | |
353 | #define wl_to_ie(w) (&w->ie) | |
354 | #define iscan_to_wl(i) ((struct wl_priv *)(i->data)) | |
355 | #define wl_to_iscan(w) (w->iscan) | |
356 | #define wl_to_conn(w) (&w->conn_info) | |
357 | ||
ec66c6fa AS |
358 | static inline struct brcmf_bss_info *next_bss(struct brcmf_scan_results *list, |
359 | struct brcmf_bss_info *bss) | |
cf2b4488 HP |
360 | { |
361 | return bss = bss ? | |
ec66c6fa | 362 | (struct brcmf_bss_info *)((unsigned long)bss + |
29750b90 SF |
363 | le32_to_cpu(bss->length)) : |
364 | list->bss_info; | |
cf2b4488 HP |
365 | } |
366 | ||
367 | #define for_each_bss(list, bss, __i) \ | |
368 | for (__i = 0; __i < list->count && __i < WL_AP_MAX; __i++, bss = next_bss(list, bss)) | |
369 | ||
3e26416e | 370 | extern s32 wl_cfg80211_attach(struct net_device *ndev, void *data); |
cf2b4488 HP |
371 | extern void wl_cfg80211_detach(void); |
372 | /* event handler from dongle */ | |
05dc0f43 | 373 | extern void wl_cfg80211_event(struct net_device *ndev, |
63bec49e | 374 | const struct brcmf_event_msg *e, void *data); |
cf2b4488 | 375 | extern void wl_cfg80211_sdio_func(void *func); /* set sdio function info */ |
93ad12cf | 376 | extern struct sdio_func *wl_cfg80211_get_sdio_func(void); /* set sdio function info */ |
3e26416e GKH |
377 | extern s32 wl_cfg80211_up(void); /* dongle up */ |
378 | extern s32 wl_cfg80211_down(void); /* dongle down */ | |
66cbd3ab | 379 | extern void wl_cfg80211_dbg_level(u32 level); /* set dongle |
cf2b4488 | 380 | debugging level */ |
cf2b4488 | 381 | #endif /* _wl_cfg80211_h_ */ |