Initial commit
[kernel/linux-3.0.git] / drivers / net / wireless / bcmdhd / src / wl / sys / wl_cfgp2p.h
1 /*
2  * Linux cfgp2p driver
3  *
4  * Copyright (C) 1999-2011, Broadcom Corporation
5  *
6  *      Unless you and Broadcom execute a separate written software license
7  * agreement governing use of this software, this software is licensed to you
8  * under the terms of the GNU General Public License version 2 (the "GPL"),
9  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
10  * following added to such license:
11  *
12  *      As a special exception, the copyright holders of this software give you
13  * permission to link this software with independent modules, and to copy and
14  * distribute the resulting executable under terms of your choice, provided that
15  * you also meet, for each linked independent module, the terms and conditions of
16  * the license of that module.  An independent module is a module which is not
17  * derived from this software.  The special exception does not apply to any
18  * modifications of the software.
19  *
20  *      Notwithstanding the above, under no circumstances may you combine this
21  * software in any way with any other Broadcom software provided under a license
22  * other than the GPL, without Broadcom's express prior written consent.
23  *
24  * $Id: wl_cfgp2p.h 307885 2012-01-12 23:30:48Z $
25  */
26 #ifndef _wl_cfgp2p_h_
27 #define _wl_cfgp2p_h_
28 #include <proto/802.11.h>
29 #include <proto/p2p.h>
30
31 struct wl_priv;
32 extern u32 wl_dbg_level;
33
34 typedef struct wifi_p2p_ie wifi_wfd_ie_t;
35 /* Enumeration of the usages of the BSSCFGs used by the P2P Library.  Do not
36  * confuse this with a bsscfg index.  This value is an index into the
37  * saved_ie[] array of structures which in turn contains a bsscfg index field.
38  */
39 typedef enum {
40         P2PAPI_BSSCFG_PRIMARY, /* maps to driver's primary bsscfg */
41         P2PAPI_BSSCFG_DEVICE, /* maps to driver's P2P device discovery bsscfg */
42         P2PAPI_BSSCFG_CONNECTION, /* maps to driver's P2P connection bsscfg */
43         P2PAPI_BSSCFG_MAX
44 } p2p_bsscfg_type_t;
45
46 #define IE_MAX_LEN 300
47 #define P2P_RES_MAX_LEN 1400
48 /* Structure to hold all saved P2P and WPS IEs for a BSSCFG */
49 struct p2p_saved_ie {
50         u8  p2p_probe_req_ie[IE_MAX_LEN];
51         u8  p2p_probe_res_ie[P2P_RES_MAX_LEN];
52         u8  p2p_assoc_req_ie[IE_MAX_LEN];
53         u8  p2p_assoc_res_ie[IE_MAX_LEN];
54         u8  p2p_beacon_ie[IE_MAX_LEN];
55         u32 p2p_probe_req_ie_len;
56         u32 p2p_probe_res_ie_len;
57         u32 p2p_assoc_req_ie_len;
58         u32 p2p_assoc_res_ie_len;
59         u32 p2p_beacon_ie_len;
60 };
61
62 struct p2p_bss {
63         u32 bssidx;
64         struct net_device *dev;
65         struct p2p_saved_ie saved_ie;
66         void *private_data;
67 };
68
69 struct p2p_info {
70         bool on;    /* p2p on/off switch */
71         bool scan;
72         bool vif_created;
73         s8 vir_ifname[IFNAMSIZ];
74         unsigned long status;
75         struct ether_addr dev_addr;
76         struct ether_addr int_addr;
77         struct p2p_bss bss_idx[P2PAPI_BSSCFG_MAX];
78         struct timer_list listen_timer;
79         wl_p2p_sched_t noa;
80         wl_p2p_ops_t ops;
81         wlc_ssid_t ssid;
82         spinlock_t timer_lock;
83 };
84
85 /* dongle status */
86 enum wl_cfgp2p_status {
87         WLP2P_STATUS_DISCOVERY_ON = 0,
88         WLP2P_STATUS_SEARCH_ENABLED,
89         WLP2P_STATUS_IF_ADD,
90         WLP2P_STATUS_IF_DEL,
91         WLP2P_STATUS_IF_DELETING,
92         WLP2P_STATUS_IF_CHANGING,
93         WLP2P_STATUS_IF_CHANGED,
94         WLP2P_STATUS_LISTEN_EXPIRED,
95         WLP2P_STATUS_ACTION_TX_COMPLETED,
96         WLP2P_STATUS_ACTION_TX_NOACK,
97         WLP2P_STATUS_SCANNING
98 };
99
100
101 #define wl_to_p2p_bss_ndev(w, type)     ((wl)->p2p->bss_idx[type].dev)
102 #define wl_to_p2p_bss_bssidx(w, type)   ((wl)->p2p->bss_idx[type].bssidx)
103 #define wl_to_p2p_bss_saved_ie(w, type)         ((wl)->p2p->bss_idx[type].saved_ie)
104 #define wl_to_p2p_bss_private(w, type)  ((wl)->p2p->bss_idx[type].private_data)
105 #define wl_to_p2p_bss(wl, type) ((wl)->p2p->bss_idx[type])
106 #define wl_get_p2p_status(wl, stat) ((!(wl)->p2p_supported) ? 0 : test_bit(WLP2P_STATUS_ ## stat, \
107                                                                         &(wl)->p2p->status))
108 #define wl_set_p2p_status(wl, stat) ((!(wl)->p2p_supported) ? 0 : set_bit(WLP2P_STATUS_ ## stat, \
109                                                                         &(wl)->p2p->status))
110 #define wl_clr_p2p_status(wl, stat) ((!(wl)->p2p_supported) ? 0 : clear_bit(WLP2P_STATUS_ ## stat, \
111                                                                         &(wl)->p2p->status))
112 #define wl_chg_p2p_status(wl, stat) ((!(wl)->p2p_supported) ? 0:change_bit(WLP2P_STATUS_ ## stat, \
113                                                                         &(wl)->p2p->status))
114 #define p2p_on(wl) ((wl)->p2p->on)
115 #define p2p_scan(wl) ((wl)->p2p->scan)
116 #define p2p_is_on(wl) ((wl)->p2p && (wl)->p2p->on)
117
118 /* dword align allocation */
119 #define WLC_IOCTL_MAXLEN 8192
120 #define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5]
121 #define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x"
122
123 #define CFGP2P_ERR(args)                                                                        \
124         do {                                                                            \
125                 if (wl_dbg_level & WL_DBG_ERR) {                                \
126                         printk(KERN_INFO "CFGP2P-INFO2) %s : ", __func__);      \
127                         printk args;                                            \
128                 }                                                                       \
129         } while (0)
130 #define CFGP2P_INFO(args)                                                                       \
131         do {                                                                            \
132                 if (wl_dbg_level & WL_DBG_INFO) {                               \
133                         printk(KERN_INFO "CFGP2P-INFO) %s : ", __func__);       \
134                         printk args;                                            \
135                 }                                                                       \
136         } while (0)
137 #define CFGP2P_DBG(args)                                                                \
138         do {                                                                    \
139                 if (wl_dbg_level & WL_DBG_DBG) {                        \
140                         printk(KERN_DEBUG "CFGP2P-DEBUG) %s :", __func__);      \
141                         printk args;                                                    \
142                 }                                                                       \
143         } while (0)
144 #define INIT_TIMER(timer, func, duration, extra_delay)  \
145         do {                               \
146                 init_timer(timer); \
147                 timer->function = func; \
148                 timer->expires = jiffies + msecs_to_jiffies(duration + extra_delay); \
149                 timer->data = (unsigned long) wl; \
150                 add_timer(timer); \
151         } while (0);
152 extern void
153 wl_cfgp2p_listen_expired(unsigned long data);
154 extern bool
155 wl_cfgp2p_is_pub_action(void *frame, u32 frame_len);
156 extern bool
157 wl_cfgp2p_is_p2p_action(void *frame, u32 frame_len);
158 extern bool
159 wl_cfgp2p_is_gas_action(void *frame, u32 frame_len);
160 extern void
161 wl_cfgp2p_print_actframe(bool tx, void *frame, u32 frame_len);
162 extern s32
163 wl_cfgp2p_init_priv(struct wl_priv *wl);
164 extern void
165 wl_cfgp2p_deinit_priv(struct wl_priv *wl);
166 extern s32
167 wl_cfgp2p_set_firm_p2p(struct wl_priv *wl);
168 extern s32
169 wl_cfgp2p_set_p2p_mode(struct wl_priv *wl, u8 mode,
170             u32 channel, u16 listen_ms, int bssidx);
171 extern s32
172 wl_cfgp2p_ifadd(struct wl_priv *wl, struct ether_addr *mac, u8 if_type,
173             chanspec_t chspec);
174 extern s32
175 wl_cfgp2p_ifdisable(struct wl_priv *wl, struct ether_addr *mac);
176 extern s32
177 wl_cfgp2p_ifdel(struct wl_priv *wl, struct ether_addr *mac);
178 extern s32
179 wl_cfgp2p_ifchange(struct wl_priv *wl, struct ether_addr *mac, u8 if_type, chanspec_t chspec);
180
181 extern s32
182 wl_cfgp2p_ifidx(struct wl_priv *wl, struct ether_addr *mac, s32 *index);
183
184 extern s32
185 wl_cfgp2p_init_discovery(struct wl_priv *wl);
186 extern s32
187 wl_cfgp2p_enable_discovery(struct wl_priv *wl, struct net_device *dev, const u8 *ie, u32 ie_len);
188 extern s32
189 wl_cfgp2p_disable_discovery(struct wl_priv *wl);
190 extern s32
191 wl_cfgp2p_escan(struct wl_priv *wl, struct net_device *dev, u16 active, u32 num_chans,
192         u16 *channels,
193         s32 search_state, u16 action, u32 bssidx);
194
195 extern s32
196 wl_cfgp2p_act_frm_search(struct wl_priv *wl, struct net_device *ndev,
197         s32 bssidx, s32 channel);
198
199 extern wpa_ie_fixed_t *
200 wl_cfgp2p_find_wpaie(u8 *parse, u32 len);
201
202 extern wpa_ie_fixed_t *
203 wl_cfgp2p_find_wpsie(u8 *parse, u32 len);
204
205 extern wifi_p2p_ie_t *
206 wl_cfgp2p_find_customer_ie(u8 *parse, u32 *len);
207
208 extern wifi_p2p_ie_t *
209 wl_cfgp2p_find_p2pie(u8 *parse, u32 len);
210
211 extern wifi_wfd_ie_t *
212 wl_cfgp2p_find_wfdie(u8 *parse, u32 len);
213 extern s32
214 wl_cfgp2p_set_management_ie(struct wl_priv *wl, struct net_device *ndev, s32 bssidx,
215             s32 pktflag, const u8 *vndr_ie, u32 vndr_ie_len);
216 extern s32
217 wl_cfgp2p_clear_management_ie(struct wl_priv *wl, s32 bssidx);
218
219 extern s32
220 wl_cfgp2p_find_idx(struct wl_priv *wl, struct net_device *ndev);
221
222
223 extern s32
224 wl_cfgp2p_p2p_listen_suspend(void);
225 extern s32
226 wl_cfgp2p_listen_complete(struct wl_priv *wl, struct net_device *ndev,
227             const wl_event_msg_t *e, void *data);
228 extern s32
229 wl_cfgp2p_discover_listen(struct wl_priv *wl, s32 channel, u32 duration_ms);
230
231 extern s32
232 wl_cfgp2p_discover_enable_search(struct wl_priv *wl, u8 enable);
233
234 extern s32
235 wl_cfgp2p_action_tx_complete(struct wl_priv *wl, struct net_device *ndev,
236             const wl_event_msg_t *e, void *data);
237 extern s32
238 wl_cfgp2p_tx_action_frame(struct wl_priv *wl, struct net_device *dev,
239         wl_af_params_t *af_params, s32 bssidx);
240
241 extern void
242 wl_cfgp2p_generate_bss_mac(struct ether_addr *primary_addr, struct ether_addr *out_dev_addr,
243             struct ether_addr *out_int_addr);
244
245 extern void
246 wl_cfg80211_change_ifaddr(u8* buf, struct ether_addr *p2p_int_addr, u8 element_id);
247 extern bool
248 wl_cfgp2p_bss_isup(struct net_device *ndev, int bsscfg_idx);
249
250 extern s32
251 wl_cfgp2p_bss(struct wl_priv *wl, struct net_device *ndev, s32 bsscfg_idx, s32 up);
252
253
254 extern s32
255 wl_cfgp2p_supported(struct wl_priv *wl, struct net_device *ndev);
256
257 extern s32
258 wl_cfgp2p_down(struct wl_priv *wl);
259
260 extern s32
261 wl_cfgp2p_set_p2p_noa(struct wl_priv *wl, struct net_device *ndev, char* buf, int len);
262
263 extern s32
264 wl_cfgp2p_get_p2p_noa(struct wl_priv *wl, struct net_device *ndev, char* buf, int len);
265
266 extern s32
267 wl_cfgp2p_set_p2p_ps(struct wl_priv *wl, struct net_device *ndev, char* buf, int len);
268
269 extern u8 *
270 wl_cfgp2p_retreive_p2pattrib(void *buf, u8 element_id);
271
272 extern u8 *
273 wl_cfgp2p_retreive_p2p_dev_addr(wl_bss_info_t *bi, u32 bi_length);
274
275 extern s32
276 wl_cfgp2p_register_ndev(struct wl_priv *wl);
277
278 extern s32
279 wl_cfgp2p_unregister_ndev(struct wl_priv *wl);
280
281 /* WiFi Direct */
282 #define SOCIAL_CHAN_1 1
283 #define SOCIAL_CHAN_2 6
284 #define SOCIAL_CHAN_3 11
285 #define SOCIAL_CHAN_CNT 3
286 #define AF_PEER_SEARCH_CNT 2
287 #define WL_P2P_WILDCARD_SSID "DIRECT-"
288 #define WL_P2P_WILDCARD_SSID_LEN 7
289 #define WL_P2P_INTERFACE_PREFIX "p2p"
290 #define WL_P2P_TEMP_CHAN "11"
291
292
293 #define IS_GAS_REQ(frame, len) (wl_cfgp2p_is_gas_action(frame, len) && \
294                                         ((frame->action == P2PSD_ACTION_ID_GAS_IREQ) || \
295                                         (frame->action == P2PSD_ACTION_ID_GAS_CREQ)))
296 #define IS_P2P_PUB_ACT_REQ(frame, len) (wl_cfgp2p_is_pub_action(frame, len) && \
297                                                 ((frame->subtype == P2P_PAF_GON_REQ) || \
298                                                 (frame->subtype == P2P_PAF_INVITE_REQ) || \
299                                                 (frame->subtype == P2P_PAF_PROVDIS_REQ)))
300 #define IS_P2P_PUB_ACT_RSP_SUBTYPE(subtype) ((subtype == P2P_PAF_GON_RSP) || \
301                                                         ((subtype == P2P_PAF_GON_CONF) || \
302                                                         (subtype == P2P_PAF_INVITE_RSP) || \
303                                                         (subtype == P2P_PAF_PROVDIS_RSP)))
304 #define IS_P2P_SOCIAL(ch) ((ch == SOCIAL_CHAN_1) || (ch == SOCIAL_CHAN_2) || (ch == SOCIAL_CHAN_3))
305 #define IS_P2P_SSID(ssid, len) (!memcmp(ssid, WL_P2P_WILDCARD_SSID, WL_P2P_WILDCARD_SSID_LEN) && (len == WL_P2P_WILDCARD_SSID_LEN))
306 #endif                          /* _wl_cfgp2p_h_ */