]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - drivers/net/wireless/brcm80211/brcmfmac/cfg80211.h
Merge remote-tracking branch 'sound-current/for-linus'
[karo-tx-linux.git] / drivers / net / wireless / brcm80211 / brcmfmac / cfg80211.h
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 BRCMFMAC_CFG80211_H
18 #define BRCMFMAC_CFG80211_H
19
20 /* for brcmu_d11inf */
21 #include <brcmu_d11.h>
22
23 #define WL_NUM_SCAN_MAX                 10
24 #define WL_NUM_PMKIDS_MAX               MAXPMKID
25 #define WL_TLV_INFO_MAX                 1024
26 #define WL_BSS_INFO_MAX                 2048
27 #define WL_ASSOC_INFO_MAX               512     /* assoc related fil max buf */
28 #define WL_EXTRA_BUF_MAX                2048
29 #define WL_ROAM_TRIGGER_LEVEL           -75
30 #define WL_ROAM_DELTA                   20
31 #define WL_BEACON_TIMEOUT               3
32
33 #define WL_SCAN_CHANNEL_TIME            40
34 #define WL_SCAN_UNASSOC_TIME            40
35 #define WL_SCAN_PASSIVE_TIME            120
36
37 #define WL_ESCAN_BUF_SIZE               (1024 * 64)
38 #define WL_ESCAN_TIMER_INTERVAL_MS      10000 /* E-Scan timeout */
39
40 #define WL_ESCAN_ACTION_START           1
41 #define WL_ESCAN_ACTION_CONTINUE        2
42 #define WL_ESCAN_ACTION_ABORT           3
43
44 #define WL_AUTH_SHARED_KEY              1       /* d11 shared authentication */
45 #define IE_MAX_LEN                      512
46
47 /* IE TLV processing */
48 #define TLV_LEN_OFF                     1       /* length offset */
49 #define TLV_HDR_LEN                     2       /* header length */
50 #define TLV_BODY_OFF                    2       /* body offset */
51 #define TLV_OUI_LEN                     3       /* oui id length */
52
53 /* 802.11 Mgmt Packet flags */
54 #define BRCMF_VNDR_IE_BEACON_FLAG       0x1
55 #define BRCMF_VNDR_IE_PRBRSP_FLAG       0x2
56 #define BRCMF_VNDR_IE_ASSOCRSP_FLAG     0x4
57 #define BRCMF_VNDR_IE_AUTHRSP_FLAG      0x8
58 #define BRCMF_VNDR_IE_PRBREQ_FLAG       0x10
59 #define BRCMF_VNDR_IE_ASSOCREQ_FLAG     0x20
60 /* vendor IE in IW advertisement protocol ID field */
61 #define BRCMF_VNDR_IE_IWAPID_FLAG       0x40
62 /* allow custom IE id */
63 #define BRCMF_VNDR_IE_CUSTOM_FLAG       0x100
64
65 /* P2P Action Frames flags (spec ordered) */
66 #define BRCMF_VNDR_IE_GONREQ_FLAG     0x001000
67 #define BRCMF_VNDR_IE_GONRSP_FLAG     0x002000
68 #define BRCMF_VNDR_IE_GONCFM_FLAG     0x004000
69 #define BRCMF_VNDR_IE_INVREQ_FLAG     0x008000
70 #define BRCMF_VNDR_IE_INVRSP_FLAG     0x010000
71 #define BRCMF_VNDR_IE_DISREQ_FLAG     0x020000
72 #define BRCMF_VNDR_IE_DISRSP_FLAG     0x040000
73 #define BRCMF_VNDR_IE_PRDREQ_FLAG     0x080000
74 #define BRCMF_VNDR_IE_PRDRSP_FLAG     0x100000
75
76 #define BRCMF_VNDR_IE_P2PAF_SHIFT       12
77
78 #define BRCMF_MAX_DEFAULT_KEYS          4
79
80
81 /**
82  * enum brcmf_scan_status - scan engine status
83  *
84  * @BRCMF_SCAN_STATUS_BUSY: scanning in progress on dongle.
85  * @BRCMF_SCAN_STATUS_ABORT: scan being aborted on dongle.
86  * @BRCMF_SCAN_STATUS_SUPPRESS: scanning is suppressed in driver.
87  */
88 enum brcmf_scan_status {
89         BRCMF_SCAN_STATUS_BUSY,
90         BRCMF_SCAN_STATUS_ABORT,
91         BRCMF_SCAN_STATUS_SUPPRESS,
92 };
93
94 /* dongle configuration */
95 struct brcmf_cfg80211_conf {
96         u32 frag_threshold;
97         u32 rts_threshold;
98         u32 retry_short;
99         u32 retry_long;
100         s32 tx_power;
101         struct ieee80211_channel channel;
102 };
103
104 /* basic structure of scan request */
105 struct brcmf_cfg80211_scan_req {
106         struct brcmf_ssid_le ssid_le;
107 };
108
109 /* basic structure of information element */
110 struct brcmf_cfg80211_ie {
111         u16 offset;
112         u8 buf[WL_TLV_INFO_MAX];
113 };
114
115 /* security information with currently associated ap */
116 struct brcmf_cfg80211_security {
117         u32 wpa_versions;
118         u32 auth_type;
119         u32 cipher_pairwise;
120         u32 cipher_group;
121         u32 wpa_auth;
122 };
123
124 /**
125  * struct brcmf_cfg80211_profile - profile information.
126  *
127  * @ssid: ssid of associated/associating ap.
128  * @bssid: bssid of joined/joining ibss.
129  * @sec: security information.
130  * @key: key information
131  */
132 struct brcmf_cfg80211_profile {
133         struct brcmf_ssid ssid;
134         u8 bssid[ETH_ALEN];
135         struct brcmf_cfg80211_security sec;
136         struct brcmf_wsec_key key[BRCMF_MAX_DEFAULT_KEYS];
137 };
138
139 /**
140  * enum brcmf_vif_status - bit indices for vif status.
141  *
142  * @BRCMF_VIF_STATUS_READY: ready for operation.
143  * @BRCMF_VIF_STATUS_CONNECTING: connect/join in progress.
144  * @BRCMF_VIF_STATUS_CONNECTED: connected/joined succesfully.
145  * @BRCMF_VIF_STATUS_DISCONNECTING: disconnect/disable in progress.
146  * @BRCMF_VIF_STATUS_AP_CREATED: AP operation started.
147  */
148 enum brcmf_vif_status {
149         BRCMF_VIF_STATUS_READY,
150         BRCMF_VIF_STATUS_CONNECTING,
151         BRCMF_VIF_STATUS_CONNECTED,
152         BRCMF_VIF_STATUS_DISCONNECTING,
153         BRCMF_VIF_STATUS_AP_CREATED
154 };
155
156 /**
157  * struct vif_saved_ie - holds saved IEs for a virtual interface.
158  *
159  * @probe_req_ie: IE info for probe request.
160  * @probe_res_ie: IE info for probe response.
161  * @beacon_ie: IE info for beacon frame.
162  * @probe_req_ie_len: IE info length for probe request.
163  * @probe_res_ie_len: IE info length for probe response.
164  * @beacon_ie_len: IE info length for beacon frame.
165  */
166 struct vif_saved_ie {
167         u8  probe_req_ie[IE_MAX_LEN];
168         u8  probe_res_ie[IE_MAX_LEN];
169         u8  beacon_ie[IE_MAX_LEN];
170         u8  assoc_req_ie[IE_MAX_LEN];
171         u32 probe_req_ie_len;
172         u32 probe_res_ie_len;
173         u32 beacon_ie_len;
174         u32 assoc_req_ie_len;
175 };
176
177 /**
178  * struct brcmf_cfg80211_vif - virtual interface specific information.
179  *
180  * @ifp: lower layer interface pointer
181  * @wdev: wireless device.
182  * @profile: profile information.
183  * @roam_off: roaming state.
184  * @sme_state: SME state using enum brcmf_vif_status bits.
185  * @pm_block: power-management blocked.
186  * @list: linked list.
187  * @mgmt_rx_reg: registered rx mgmt frame types.
188  * @mbss: Multiple BSS type, set if not first AP (not relevant for P2P).
189  */
190 struct brcmf_cfg80211_vif {
191         struct brcmf_if *ifp;
192         struct wireless_dev wdev;
193         struct brcmf_cfg80211_profile profile;
194         s32 roam_off;
195         unsigned long sme_state;
196         bool pm_block;
197         struct vif_saved_ie saved_ie;
198         struct list_head list;
199         u16 mgmt_rx_reg;
200         bool mbss;
201         int is_11d;
202 };
203
204 /* association inform */
205 struct brcmf_cfg80211_connect_info {
206         u8 *req_ie;
207         s32 req_ie_len;
208         u8 *resp_ie;
209         s32 resp_ie_len;
210 };
211
212 /* assoc ie length */
213 struct brcmf_cfg80211_assoc_ielen_le {
214         __le32 req_len;
215         __le32 resp_len;
216 };
217
218 /* wpa2 pmk list */
219 struct brcmf_cfg80211_pmk_list {
220         struct pmkid_list pmkids;
221         struct pmkid foo[MAXPMKID - 1];
222 };
223
224 /* dongle escan state */
225 enum wl_escan_state {
226         WL_ESCAN_STATE_IDLE,
227         WL_ESCAN_STATE_SCANNING
228 };
229
230 struct escan_info {
231         u32 escan_state;
232         u8 escan_buf[WL_ESCAN_BUF_SIZE];
233         struct wiphy *wiphy;
234         struct brcmf_if *ifp;
235         s32 (*run)(struct brcmf_cfg80211_info *cfg, struct brcmf_if *ifp,
236                    struct cfg80211_scan_request *request, u16 action);
237 };
238
239 /**
240  * struct brcmf_pno_param_le - PNO scan configuration parameters
241  *
242  * @version: PNO parameters version.
243  * @scan_freq: scan frequency.
244  * @lost_network_timeout: #sec. to declare discovered network as lost.
245  * @flags: Bit field to control features of PFN such as sort criteria auto
246  *      enable switch and background scan.
247  * @rssi_margin: Margin to avoid jitter for choosing a PFN based on RSSI sort
248  *      criteria.
249  * @bestn: number of best networks in each scan.
250  * @mscan: number of scans recorded.
251  * @repeat: minimum number of scan intervals before scan frequency changes
252  *      in adaptive scan.
253  * @exp: exponent of 2 for maximum scan interval.
254  * @slow_freq: slow scan period.
255  */
256 struct brcmf_pno_param_le {
257         __le32 version;
258         __le32 scan_freq;
259         __le32 lost_network_timeout;
260         __le16 flags;
261         __le16 rssi_margin;
262         u8 bestn;
263         u8 mscan;
264         u8 repeat;
265         u8 exp;
266         __le32 slow_freq;
267 };
268
269 /**
270  * struct brcmf_pno_net_param_le - scan parameters per preferred network.
271  *
272  * @ssid: ssid name and its length.
273  * @flags: bit2: hidden.
274  * @infra: BSS vs IBSS.
275  * @auth: Open vs Closed.
276  * @wpa_auth: WPA type.
277  * @wsec: wsec value.
278  */
279 struct brcmf_pno_net_param_le {
280         struct brcmf_ssid_le ssid;
281         __le32 flags;
282         __le32 infra;
283         __le32 auth;
284         __le32 wpa_auth;
285         __le32 wsec;
286 };
287
288 /**
289  * struct brcmf_pno_net_info_le - information per found network.
290  *
291  * @bssid: BSS network identifier.
292  * @channel: channel number only.
293  * @SSID_len: length of ssid.
294  * @SSID: ssid characters.
295  * @RSSI: receive signal strength (in dBm).
296  * @timestamp: age in seconds.
297  */
298 struct brcmf_pno_net_info_le {
299         u8 bssid[ETH_ALEN];
300         u8 channel;
301         u8 SSID_len;
302         u8 SSID[32];
303         __le16  RSSI;
304         __le16  timestamp;
305 };
306
307 /**
308  * struct brcmf_pno_scanresults_le - result returned in PNO NET FOUND event.
309  *
310  * @version: PNO version identifier.
311  * @status: indicates completion status of PNO scan.
312  * @count: amount of brcmf_pno_net_info_le entries appended.
313  */
314 struct brcmf_pno_scanresults_le {
315         __le32 version;
316         __le32 status;
317         __le32 count;
318 };
319
320 /**
321  * struct brcmf_cfg80211_vif_event - virtual interface event information.
322  *
323  * @vif_wq: waitqueue awaiting interface event from firmware.
324  * @vif_event_lock: protects other members in this structure.
325  * @vif_complete: completion for net attach.
326  * @action: either add, change, or delete.
327  * @vif: virtual interface object related to the event.
328  */
329 struct brcmf_cfg80211_vif_event {
330         wait_queue_head_t vif_wq;
331         struct mutex vif_event_lock;
332         u8 action;
333         struct brcmf_cfg80211_vif *vif;
334 };
335
336 /**
337  * struct brcmf_cfg80211_info - dongle private data of cfg80211 interface
338  *
339  * @wiphy: wiphy object for cfg80211 interface.
340  * @conf: dongle configuration.
341  * @p2p: peer-to-peer specific information.
342  * @btcoex: Bluetooth coexistence information.
343  * @scan_request: cfg80211 scan request object.
344  * @usr_sync: mainly for dongle up/down synchronization.
345  * @bss_list: bss_list holding scanned ap information.
346  * @scan_req_int: internal scan request object.
347  * @bss_info: bss information for cfg80211 layer.
348  * @ie: information element object for internal purpose.
349  * @conn_info: association info.
350  * @pmk_list: wpa2 pmk list.
351  * @scan_status: scan activity on the dongle.
352  * @pub: common driver information.
353  * @channel: current channel.
354  * @active_scan: current scan mode.
355  * @sched_escan: e-scan for scheduled scan support running.
356  * @ibss_starter: indicates this sta is ibss starter.
357  * @pwr_save: indicate whether dongle to support power save mode.
358  * @dongle_up: indicate whether dongle up or not.
359  * @roam_on: on/off switch for dongle self-roaming.
360  * @scan_tried: indicates if first scan attempted.
361  * @dcmd_buf: dcmd buffer.
362  * @extra_buf: mainly to grab assoc information.
363  * @debugfsdir: debugfs folder for this device.
364  * @escan_info: escan information.
365  * @escan_timeout: Timer for catch scan timeout.
366  * @escan_timeout_work: scan timeout worker.
367  * @escan_ioctl_buf: dongle command buffer for escan commands.
368  * @vif_list: linked list of vif instances.
369  * @vif_cnt: number of vif instances.
370  * @vif_event: vif event signalling.
371  * @wowl_enabled; set during suspend, is wowl used.
372  * @pre_wowl_pmmode: intermediate storage of pm mode during wowl.
373  */
374 struct brcmf_cfg80211_info {
375         struct wiphy *wiphy;
376         struct brcmf_cfg80211_conf *conf;
377         struct brcmf_p2p_info p2p;
378         struct brcmf_btcoex_info *btcoex;
379         struct cfg80211_scan_request *scan_request;
380         struct mutex usr_sync;
381         struct brcmf_cfg80211_scan_req scan_req_int;
382         struct wl_cfg80211_bss_info *bss_info;
383         struct brcmf_cfg80211_ie ie;
384         struct brcmf_cfg80211_connect_info conn_info;
385         struct brcmf_cfg80211_pmk_list *pmk_list;
386         unsigned long scan_status;
387         struct brcmf_pub *pub;
388         u32 channel;
389         bool active_scan;
390         bool sched_escan;
391         bool ibss_starter;
392         bool pwr_save;
393         bool dongle_up;
394         bool scan_tried;
395         u8 *dcmd_buf;
396         u8 *extra_buf;
397         struct dentry *debugfsdir;
398         struct escan_info escan_info;
399         struct timer_list escan_timeout;
400         struct work_struct escan_timeout_work;
401         u8 *escan_ioctl_buf;
402         struct list_head vif_list;
403         struct brcmf_cfg80211_vif_event vif_event;
404         struct completion vif_disabled;
405         struct brcmu_d11inf d11inf;
406         bool wowl_enabled;
407         u32 pre_wowl_pmmode;
408         struct brcmf_assoclist_le assoclist;
409 };
410
411 /**
412  * struct brcmf_tlv - tag_ID/length/value_buffer tuple.
413  *
414  * @id: tag identifier.
415  * @len: number of bytes in value buffer.
416  * @data: value buffer.
417  */
418 struct brcmf_tlv {
419         u8 id;
420         u8 len;
421         u8 data[1];
422 };
423
424 static inline struct wiphy *cfg_to_wiphy(struct brcmf_cfg80211_info *cfg)
425 {
426         return cfg->wiphy;
427 }
428
429 static inline struct brcmf_cfg80211_info *wiphy_to_cfg(struct wiphy *w)
430 {
431         return (struct brcmf_cfg80211_info *)(wiphy_priv(w));
432 }
433
434 static inline struct brcmf_cfg80211_info *wdev_to_cfg(struct wireless_dev *wd)
435 {
436         return (struct brcmf_cfg80211_info *)(wdev_priv(wd));
437 }
438
439 static inline
440 struct net_device *cfg_to_ndev(struct brcmf_cfg80211_info *cfg)
441 {
442         struct brcmf_cfg80211_vif *vif;
443         vif = list_first_entry(&cfg->vif_list, struct brcmf_cfg80211_vif, list);
444         return vif->wdev.netdev;
445 }
446
447 static inline struct brcmf_cfg80211_info *ndev_to_cfg(struct net_device *ndev)
448 {
449         return wdev_to_cfg(ndev->ieee80211_ptr);
450 }
451
452 static inline struct brcmf_cfg80211_profile *ndev_to_prof(struct net_device *nd)
453 {
454         struct brcmf_if *ifp = netdev_priv(nd);
455         return &ifp->vif->profile;
456 }
457
458 static inline struct brcmf_cfg80211_vif *ndev_to_vif(struct net_device *ndev)
459 {
460         struct brcmf_if *ifp = netdev_priv(ndev);
461         return ifp->vif;
462 }
463
464 static inline struct
465 brcmf_cfg80211_connect_info *cfg_to_conn(struct brcmf_cfg80211_info *cfg)
466 {
467         return &cfg->conn_info;
468 }
469
470 struct brcmf_cfg80211_info *brcmf_cfg80211_attach(struct brcmf_pub *drvr,
471                                                   struct device *busdev,
472                                                   bool p2pdev_forced);
473 void brcmf_cfg80211_detach(struct brcmf_cfg80211_info *cfg);
474 s32 brcmf_cfg80211_up(struct net_device *ndev);
475 s32 brcmf_cfg80211_down(struct net_device *ndev);
476 enum nl80211_iftype brcmf_cfg80211_get_iftype(struct brcmf_if *ifp);
477
478 struct brcmf_cfg80211_vif *brcmf_alloc_vif(struct brcmf_cfg80211_info *cfg,
479                                            enum nl80211_iftype type,
480                                            bool pm_block);
481 void brcmf_free_vif(struct brcmf_cfg80211_vif *vif);
482
483 s32 brcmf_vif_set_mgmt_ie(struct brcmf_cfg80211_vif *vif, s32 pktflag,
484                           const u8 *vndr_ie_buf, u32 vndr_ie_len);
485 s32 brcmf_vif_clear_mgmt_ies(struct brcmf_cfg80211_vif *vif);
486 const struct brcmf_tlv *
487 brcmf_parse_tlvs(const void *buf, int buflen, uint key);
488 u16 channel_to_chanspec(struct brcmu_d11inf *d11inf,
489                         struct ieee80211_channel *ch);
490 bool brcmf_get_vif_state_any(struct brcmf_cfg80211_info *cfg,
491                              unsigned long state);
492 void brcmf_cfg80211_arm_vif_event(struct brcmf_cfg80211_info *cfg,
493                                   struct brcmf_cfg80211_vif *vif);
494 bool brcmf_cfg80211_vif_event_armed(struct brcmf_cfg80211_info *cfg);
495 int brcmf_cfg80211_wait_vif_event_timeout(struct brcmf_cfg80211_info *cfg,
496                                           u8 action, ulong timeout);
497 s32 brcmf_notify_escan_complete(struct brcmf_cfg80211_info *cfg,
498                                 struct brcmf_if *ifp, bool aborted,
499                                 bool fw_abort);
500 void brcmf_set_mpc(struct brcmf_if *ndev, int mpc);
501 void brcmf_abort_scanning(struct brcmf_cfg80211_info *cfg);
502 void brcmf_cfg80211_free_netdev(struct net_device *ndev);
503
504 #endif /* BRCMFMAC_CFG80211_H */