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 | |
8a76f1ee | 115 | #define WL_SCAN_ERSULTS_LAST (WL_SCAN_RESULTS_NO_MEM+1) |
cf2b4488 HP |
116 | #define WL_AP_MAX 256 /* virtually unlimitted as long |
117 | * as kernel memory allows | |
118 | */ | |
119 | #define WL_FILE_NAME_MAX 256 | |
120 | ||
a1e962b6 SS |
121 | #define WL_ROAM_TRIGGER_LEVEL -75 |
122 | #define WL_ROAM_DELTA 20 | |
123 | #define WL_BEACON_TIMEOUT 3 | |
124 | ||
e4dd6325 SS |
125 | #define WL_SCAN_CHANNEL_TIME 40 |
126 | #define WL_SCAN_UNASSOC_TIME 40 | |
127 | #define WL_SCAN_PASSIVE_TIME 120 | |
128 | ||
cf2b4488 HP |
129 | /* dongle status */ |
130 | enum wl_status { | |
131 | WL_STATUS_READY, | |
132 | WL_STATUS_SCANNING, | |
133 | WL_STATUS_SCAN_ABORTING, | |
134 | WL_STATUS_CONNECTING, | |
135 | WL_STATUS_CONNECTED | |
136 | }; | |
137 | ||
138 | /* wi-fi mode */ | |
139 | enum wl_mode { | |
140 | WL_MODE_BSS, | |
141 | WL_MODE_IBSS, | |
142 | WL_MODE_AP | |
143 | }; | |
144 | ||
145 | /* dongle profile list */ | |
146 | enum wl_prof_list { | |
147 | WL_PROF_MODE, | |
148 | WL_PROF_SSID, | |
149 | WL_PROF_SEC, | |
150 | WL_PROF_IBSS, | |
151 | WL_PROF_BAND, | |
152 | WL_PROF_BSSID, | |
1e0645c3 | 153 | WL_PROF_ACT, |
154 | WL_PROF_BEACONINT, | |
155 | WL_PROF_DTIMPERIOD | |
cf2b4488 HP |
156 | }; |
157 | ||
158 | /* dongle iscan state */ | |
159 | enum wl_iscan_state { | |
160 | WL_ISCAN_STATE_IDLE, | |
161 | WL_ISCAN_STATE_SCANING | |
162 | }; | |
163 | ||
164 | /* fw downloading status */ | |
165 | enum wl_fw_status { | |
166 | WL_FW_LOADING_DONE, | |
167 | WL_NVRAM_LOADING_DONE | |
168 | }; | |
169 | ||
c5ca038f | 170 | /* beacon / probe_response */ |
171 | struct beacon_proberesp { | |
172 | __le64 timestamp; | |
173 | __le16 beacon_int; | |
174 | __le16 capab_info; | |
175 | u8 variable[0]; | |
176 | } __attribute__ ((packed)); | |
177 | ||
cf2b4488 HP |
178 | /* dongle configuration */ |
179 | struct wl_conf { | |
66cbd3ab GKH |
180 | u32 mode; /* adhoc , infrastructure or ap */ |
181 | u32 frag_threshold; | |
182 | u32 rts_threshold; | |
183 | u32 retry_short; | |
184 | u32 retry_long; | |
3e26416e | 185 | s32 tx_power; |
cf2b4488 HP |
186 | struct ieee80211_channel channel; |
187 | }; | |
188 | ||
189 | /* cfg80211 main event loop */ | |
190 | struct wl_event_loop { | |
3e26416e | 191 | s32(*handler[WLC_E_LAST]) (struct wl_priv *wl, |
cf2b4488 HP |
192 | struct net_device *ndev, |
193 | const wl_event_msg_t *e, void *data); | |
194 | }; | |
195 | ||
196 | /* representing interface of cfg80211 plane */ | |
197 | struct wl_iface { | |
198 | struct wl_priv *wl; | |
199 | }; | |
200 | ||
201 | struct wl_dev { | |
202 | void *driver_data; /* to store cfg80211 object information */ | |
203 | }; | |
204 | ||
205 | /* bss inform structure for cfg80211 interface */ | |
206 | struct wl_cfg80211_bss_info { | |
7d4df48e GKH |
207 | u16 band; |
208 | u16 channel; | |
e59fe083 | 209 | s16 rssi; |
7d4df48e | 210 | u16 frame_len; |
3fd79f7c | 211 | u8 frame_buf[1]; |
cf2b4488 HP |
212 | }; |
213 | ||
214 | /* basic structure of scan request */ | |
215 | struct wl_scan_req { | |
216 | struct wlc_ssid ssid; | |
217 | }; | |
218 | ||
219 | /* basic structure of information element */ | |
220 | struct wl_ie { | |
7d4df48e | 221 | u16 offset; |
3fd79f7c | 222 | u8 buf[WL_TLV_INFO_MAX]; |
cf2b4488 HP |
223 | }; |
224 | ||
225 | /* event queue for cfg80211 main event */ | |
226 | struct wl_event_q { | |
227 | struct list_head eq_list; | |
66cbd3ab | 228 | u32 etype; |
cf2b4488 | 229 | wl_event_msg_t emsg; |
562c8850 | 230 | s8 edata[1]; |
cf2b4488 HP |
231 | }; |
232 | ||
233 | /* security information with currently associated ap */ | |
234 | struct wl_security { | |
66cbd3ab GKH |
235 | u32 wpa_versions; |
236 | u32 auth_type; | |
237 | u32 cipher_pairwise; | |
238 | u32 cipher_group; | |
239 | u32 wpa_auth; | |
cf2b4488 HP |
240 | }; |
241 | ||
242 | /* ibss information for currently joined ibss network */ | |
243 | struct wl_ibss { | |
3fd79f7c GKH |
244 | u8 beacon_interval; /* in millisecond */ |
245 | u8 atim; /* in millisecond */ | |
562c8850 | 246 | s8 join_only; |
3fd79f7c GKH |
247 | u8 band; |
248 | u8 channel; | |
cf2b4488 HP |
249 | }; |
250 | ||
251 | /* dongle profile */ | |
252 | struct wl_profile { | |
66cbd3ab | 253 | u32 mode; |
cf2b4488 | 254 | struct wlc_ssid ssid; |
b8d63078 | 255 | u8 bssid[ETH_ALEN]; |
1e0645c3 | 256 | u16 beacon_interval; |
257 | u8 dtim_period; | |
cf2b4488 HP |
258 | struct wl_security sec; |
259 | struct wl_ibss ibss; | |
3e26416e | 260 | s32 band; |
cf2b4488 HP |
261 | }; |
262 | ||
263 | /* dongle iscan event loop */ | |
264 | struct wl_iscan_eloop { | |
3e26416e | 265 | s32(*handler[WL_SCAN_ERSULTS_LAST]) (struct wl_priv *wl); |
cf2b4488 HP |
266 | }; |
267 | ||
268 | /* dongle iscan controller */ | |
269 | struct wl_iscan_ctrl { | |
270 | struct net_device *dev; | |
271 | struct timer_list timer; | |
66cbd3ab GKH |
272 | u32 timer_ms; |
273 | u32 timer_on; | |
3e26416e | 274 | s32 state; |
7716314b | 275 | struct task_struct *tsk; |
cf2b4488 | 276 | struct semaphore sync; |
cf2b4488 HP |
277 | struct wl_iscan_eloop el; |
278 | void *data; | |
366bbb3f | 279 | s8 ioctl_buf[BRCMF_C_IOCTL_SMLEN]; |
562c8850 | 280 | s8 scan_buf[WL_ISCAN_BUF_MAX]; |
cf2b4488 HP |
281 | }; |
282 | ||
283 | /* association inform */ | |
284 | struct wl_connect_info { | |
3fd79f7c | 285 | u8 *req_ie; |
3e26416e | 286 | s32 req_ie_len; |
3fd79f7c | 287 | u8 *resp_ie; |
3e26416e | 288 | s32 resp_ie_len; |
cf2b4488 HP |
289 | }; |
290 | ||
291 | /* firmware /nvram downloading controller */ | |
292 | struct wl_fw_ctrl { | |
293 | const struct firmware *fw_entry; | |
3deea904 | 294 | unsigned long status; |
66cbd3ab | 295 | u32 ptr; |
562c8850 GKH |
296 | s8 fw_name[WL_FILE_NAME_MAX]; |
297 | s8 nvram_name[WL_FILE_NAME_MAX]; | |
cf2b4488 HP |
298 | }; |
299 | ||
300 | /* assoc ie length */ | |
301 | struct wl_assoc_ielen { | |
66cbd3ab GKH |
302 | u32 req_len; |
303 | u32 resp_len; | |
cf2b4488 HP |
304 | }; |
305 | ||
306 | /* wpa2 pmk list */ | |
307 | struct wl_pmk_list { | |
308 | pmkid_list_t pmkids; | |
309 | pmkid_t foo[MAXPMKID - 1]; | |
310 | }; | |
311 | ||
312 | /* dongle private data of cfg80211 interface */ | |
313 | struct wl_priv { | |
314 | struct wireless_dev *wdev; /* representing wl cfg80211 device */ | |
315 | struct wl_conf *conf; /* dongle configuration */ | |
316 | struct cfg80211_scan_request *scan_request; /* scan request | |
317 | object */ | |
318 | struct wl_event_loop el; /* main event loop */ | |
319 | struct list_head eq_list; /* used for event queue */ | |
320 | spinlock_t eq_lock; /* for event queue synchronization */ | |
321 | struct mutex usr_sync; /* maily for dongle up/down synchronization */ | |
322 | struct wl_scan_results *bss_list; /* bss_list holding scanned | |
323 | ap information */ | |
324 | struct wl_scan_results *scan_results; | |
325 | struct wl_scan_req *scan_req_int; /* scan request object for | |
326 | internal purpose */ | |
327 | struct wl_cfg80211_bss_info *bss_info; /* bss information for | |
328 | cfg80211 layer */ | |
329 | struct wl_ie ie; /* information element object for | |
330 | internal purpose */ | |
cf2b4488 HP |
331 | struct semaphore event_sync; /* for synchronization of main event |
332 | thread */ | |
cf2b4488 HP |
333 | struct wl_profile *profile; /* holding dongle profile */ |
334 | struct wl_iscan_ctrl *iscan; /* iscan controller */ | |
335 | struct wl_connect_info conn_info; /* association information | |
336 | container */ | |
337 | struct wl_fw_ctrl *fw; /* control firwmare / nvram paramter | |
338 | downloading */ | |
339 | struct wl_pmk_list *pmk_list; /* wpa2 pmk list */ | |
7716314b | 340 | struct task_struct *event_tsk; /* task of main event handler thread */ |
3deea904 | 341 | unsigned long status; /* current dongle status */ |
cf2b4488 | 342 | void *pub; |
66cbd3ab | 343 | u32 channel; /* current channel */ |
cf2b4488 HP |
344 | bool iscan_on; /* iscan on/off switch */ |
345 | bool iscan_kickstart; /* indicate iscan already started */ | |
346 | bool active_scan; /* current scan mode */ | |
347 | bool ibss_starter; /* indicates this sta is ibss starter */ | |
348 | bool link_up; /* link/connection up flag */ | |
349 | bool pwr_save; /* indicate whether dongle to support | |
350 | power save mode */ | |
351 | bool dongle_up; /* indicate whether dongle up or not */ | |
352 | bool roam_on; /* on/off switch for dongle self-roaming */ | |
353 | bool scan_tried; /* indicates if first scan attempted */ | |
3fd79f7c GKH |
354 | u8 *ioctl_buf; /* ioctl buffer */ |
355 | u8 *extra_buf; /* maily to grab assoc information */ | |
cd389a34 | 356 | struct dentry *debugfsdir; |
3fd79f7c | 357 | u8 ci[0] __attribute__ ((__aligned__(NETDEV_ALIGN))); |
cf2b4488 HP |
358 | }; |
359 | ||
360 | #define wl_to_dev(w) (wiphy_dev(wl->wdev->wiphy)) | |
361 | #define wl_to_wiphy(w) (w->wdev->wiphy) | |
362 | #define wiphy_to_wl(w) ((struct wl_priv *)(wiphy_priv(w))) | |
363 | #define wl_to_wdev(w) (w->wdev) | |
364 | #define wdev_to_wl(w) ((struct wl_priv *)(wdev_priv(w))) | |
365 | #define wl_to_ndev(w) (w->wdev->netdev) | |
366 | #define ndev_to_wl(n) (wdev_to_wl(n->ieee80211_ptr)) | |
367 | #define ci_to_wl(c) (ci->wl) | |
368 | #define wl_to_ci(w) (&w->ci) | |
369 | #define wl_to_sr(w) (w->scan_req_int) | |
370 | #define wl_to_ie(w) (&w->ie) | |
371 | #define iscan_to_wl(i) ((struct wl_priv *)(i->data)) | |
372 | #define wl_to_iscan(w) (w->iscan) | |
373 | #define wl_to_conn(w) (&w->conn_info) | |
374 | ||
375 | static inline struct wl_bss_info *next_bss(struct wl_scan_results *list, | |
376 | struct wl_bss_info *bss) | |
377 | { | |
378 | return bss = bss ? | |
f024c48a | 379 | (struct wl_bss_info *)((unsigned long)bss + |
29750b90 SF |
380 | le32_to_cpu(bss->length)) : |
381 | list->bss_info; | |
cf2b4488 HP |
382 | } |
383 | ||
384 | #define for_each_bss(list, bss, __i) \ | |
385 | for (__i = 0; __i < list->count && __i < WL_AP_MAX; __i++, bss = next_bss(list, bss)) | |
386 | ||
3e26416e | 387 | extern s32 wl_cfg80211_attach(struct net_device *ndev, void *data); |
cf2b4488 HP |
388 | extern void wl_cfg80211_detach(void); |
389 | /* event handler from dongle */ | |
390 | extern void wl_cfg80211_event(struct net_device *ndev, const wl_event_msg_t *e, | |
391 | void *data); | |
392 | extern void wl_cfg80211_sdio_func(void *func); /* set sdio function info */ | |
93ad12cf | 393 | extern struct sdio_func *wl_cfg80211_get_sdio_func(void); /* set sdio function info */ |
3e26416e GKH |
394 | extern s32 wl_cfg80211_up(void); /* dongle up */ |
395 | extern s32 wl_cfg80211_down(void); /* dongle down */ | |
66cbd3ab | 396 | extern void wl_cfg80211_dbg_level(u32 level); /* set dongle |
cf2b4488 | 397 | debugging level */ |
562c8850 | 398 | extern void *wl_cfg80211_request_fw(s8 *file_name); /* request fw /nvram |
cf2b4488 | 399 | downloading */ |
3e26416e | 400 | extern s32 wl_cfg80211_read_fw(s8 *buf, u32 size); /* read fw |
cf2b4488 HP |
401 | image */ |
402 | extern void wl_cfg80211_release_fw(void); /* release fw */ | |
562c8850 | 403 | extern s8 *wl_cfg80211_get_fwname(void); /* get firmware name for |
cf2b4488 | 404 | the dongle */ |
562c8850 | 405 | extern s8 *wl_cfg80211_get_nvramname(void); /* get nvram name for |
cf2b4488 | 406 | the dongle */ |
e6e8f894 | 407 | extern void wl_os_wd_timer(struct net_device *ndev, uint wdtick); |
cf2b4488 HP |
408 | |
409 | #endif /* _wl_cfg80211_h_ */ |