Merge branch develop-3.10 into develop-3.10-next
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / rockchip_wlan / rkwifi / bcmdhd / wl_cfgp2p.h
1 /*
2  * Linux cfgp2p driver
3  *
4  * $Copyright Open Broadcom Corporation$
5  *
6  * $Id: wl_cfgp2p.h 415640 2013-07-31 02:43:28Z $
7  */
8 #ifndef _wl_cfgp2p_h_
9 #define _wl_cfgp2p_h_
10 #include <proto/802.11.h>
11 #include <proto/p2p.h>
12
13 struct wl_priv;
14 extern u32 wl_dbg_level;
15
16 typedef struct wifi_p2p_ie wifi_wfd_ie_t;
17 /* Enumeration of the usages of the BSSCFGs used by the P2P Library.  Do not
18  * confuse this with a bsscfg index.  This value is an index into the
19  * saved_ie[] array of structures which in turn contains a bsscfg index field.
20  */
21 typedef enum {
22         P2PAPI_BSSCFG_PRIMARY, /* maps to driver's primary bsscfg */
23         P2PAPI_BSSCFG_DEVICE, /* maps to driver's P2P device discovery bsscfg */
24         P2PAPI_BSSCFG_CONNECTION, /* maps to driver's P2P connection bsscfg */
25         P2PAPI_BSSCFG_MAX
26 } p2p_bsscfg_type_t;
27
28 typedef enum {
29         P2P_SCAN_PURPOSE_MIN,
30         P2P_SCAN_SOCIAL_CHANNEL, /* scan for social channel */
31         P2P_SCAN_AFX_PEER_NORMAL, /* scan for action frame search */
32         P2P_SCAN_AFX_PEER_REDUCED, /* scan for action frame search with short time */
33         P2P_SCAN_DURING_CONNECTED, /* scan during connected status */
34         P2P_SCAN_CONNECT_TRY, /* scan for connecting */
35         P2P_SCAN_NORMAL, /* scan during not-connected status */
36         P2P_SCAN_PURPOSE_MAX
37 } p2p_scan_purpose_t;
38
39 /* vendor ies max buffer length for probe response or beacon */
40 #define VNDR_IES_MAX_BUF_LEN    1400
41 /* normal vendor ies buffer length */
42 #define VNDR_IES_BUF_LEN                512
43
44 /* Structure to hold all saved P2P and WPS IEs for a BSSCFG */
45 struct p2p_saved_ie {
46         u8  p2p_probe_req_ie[VNDR_IES_BUF_LEN];
47         u8  p2p_probe_res_ie[VNDR_IES_MAX_BUF_LEN];
48         u8  p2p_assoc_req_ie[VNDR_IES_BUF_LEN];
49         u8  p2p_assoc_res_ie[VNDR_IES_BUF_LEN];
50         u8  p2p_beacon_ie[VNDR_IES_MAX_BUF_LEN];
51         u32 p2p_probe_req_ie_len;
52         u32 p2p_probe_res_ie_len;
53         u32 p2p_assoc_req_ie_len;
54         u32 p2p_assoc_res_ie_len;
55         u32 p2p_beacon_ie_len;
56 };
57
58 struct p2p_bss {
59         u32 bssidx;
60         struct net_device *dev;
61         struct p2p_saved_ie saved_ie;
62         void *private_data;
63 };
64
65 struct p2p_info {
66         bool on;    /* p2p on/off switch */
67         bool scan;
68         int16 search_state;
69         bool vif_created;
70         s8 vir_ifname[IFNAMSIZ];
71         unsigned long status;
72         struct ether_addr dev_addr;
73         struct ether_addr int_addr;
74         struct p2p_bss bss[P2PAPI_BSSCFG_MAX];
75         struct timer_list listen_timer;
76         wl_p2p_sched_t noa;
77         wl_p2p_ops_t ops;
78         wlc_ssid_t ssid;
79 };
80
81 #define MAX_VNDR_IE_NUMBER      5
82
83 struct parsed_vndr_ie_info {
84         char *ie_ptr;
85         u32 ie_len;     /* total length including id & length field */
86         vndr_ie_t vndrie;
87 };
88
89 struct parsed_vndr_ies {
90         u32 count;
91         struct parsed_vndr_ie_info ie_info[MAX_VNDR_IE_NUMBER];
92 };
93
94 /* dongle status */
95 enum wl_cfgp2p_status {
96         WLP2P_STATUS_DISCOVERY_ON = 0,
97         WLP2P_STATUS_SEARCH_ENABLED,
98         WLP2P_STATUS_IF_ADD,
99         WLP2P_STATUS_IF_DEL,
100         WLP2P_STATUS_IF_DELETING,
101         WLP2P_STATUS_IF_CHANGING,
102         WLP2P_STATUS_IF_CHANGED,
103         WLP2P_STATUS_LISTEN_EXPIRED,
104         WLP2P_STATUS_ACTION_TX_COMPLETED,
105         WLP2P_STATUS_ACTION_TX_NOACK,
106         WLP2P_STATUS_SCANNING,
107         WLP2P_STATUS_GO_NEG_PHASE,
108         WLP2P_STATUS_DISC_IN_PROGRESS
109 };
110
111
112 #define wl_to_p2p_bss_ndev(wl, type)            ((wl)->p2p->bss[type].dev)
113 #define wl_to_p2p_bss_bssidx(wl, type)          ((wl)->p2p->bss[type].bssidx)
114 #define wl_to_p2p_bss_saved_ie(wl, type)        ((wl)->p2p->bss[type].saved_ie)
115 #define wl_to_p2p_bss_private(wl, type)         ((wl)->p2p->bss[type].private_data)
116 #define wl_to_p2p_bss(wl, type)                 ((wl)->p2p->bss[type])
117 #define wl_get_p2p_status(wl, stat) ((!(wl)->p2p_supported) ? 0 : test_bit(WLP2P_STATUS_ ## stat, \
118                                                                         &(wl)->p2p->status))
119 #define wl_set_p2p_status(wl, stat) ((!(wl)->p2p_supported) ? 0 : set_bit(WLP2P_STATUS_ ## stat, \
120                                                                         &(wl)->p2p->status))
121 #define wl_clr_p2p_status(wl, stat) ((!(wl)->p2p_supported) ? 0 : clear_bit(WLP2P_STATUS_ ## stat, \
122                                                                         &(wl)->p2p->status))
123 #define wl_chg_p2p_status(wl, stat) ((!(wl)->p2p_supported) ? 0:change_bit(WLP2P_STATUS_ ## stat, \
124                                                                         &(wl)->p2p->status))
125 #define p2p_on(wl) ((wl)->p2p->on)
126 #define p2p_scan(wl) ((wl)->p2p->scan)
127 #define p2p_is_on(wl) ((wl)->p2p && (wl)->p2p->on)
128
129 /* dword align allocation */
130 #define WLC_IOCTL_MAXLEN 8192
131
132 #define CFGP2P_ERROR_TEXT               "CFGP2P-ERROR) "
133
134
135 #define CFGP2P_ERR(args)                                                                        \
136         do {                                                                            \
137                 if (wl_dbg_level & WL_DBG_ERR) {                                \
138                         printk(KERN_INFO CFGP2P_ERROR_TEXT "%s : ", __func__);  \
139                         printk args;                                            \
140                 }                                                                       \
141         } while (0)
142 #define CFGP2P_INFO(args)                                                                       \
143         do {                                                                            \
144                 if (wl_dbg_level & WL_DBG_INFO) {                               \
145                         printk(KERN_INFO "CFGP2P-INFO) %s : ", __func__);       \
146                         printk args;                                            \
147                 }                                                                       \
148         } while (0)
149 #define CFGP2P_DBG(args)                                                                \
150         do {                                                                    \
151                 if (wl_dbg_level & WL_DBG_DBG) {                        \
152                         printk(KERN_INFO "CFGP2P-DEBUG) %s :", __func__);       \
153                         printk args;                                                    \
154                 }                                                                       \
155         } while (0)
156
157 #define CFGP2P_ACTION(args)                                                             \
158         do {                                                                    \
159                 if (wl_dbg_level & WL_DBG_P2P_ACTION) {                 \
160                         printk(KERN_INFO "CFGP2P-ACTION) %s :", __func__);      \
161                         printk args;                                                    \
162                 }                                                                       \
163         } while (0)
164 #define INIT_TIMER(timer, func, duration, extra_delay)  \
165         do {                               \
166                 init_timer(timer); \
167                 timer->function = func; \
168                 timer->expires = jiffies + msecs_to_jiffies(duration + extra_delay); \
169                 timer->data = (unsigned long) wl; \
170                 add_timer(timer); \
171         } while (0);
172
173 #if !defined(WL_CFG80211_P2P_DEV_IF) && (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0))
174 #define WL_CFG80211_P2P_DEV_IF
175 #undef WL_ENABLE_P2P_IF
176 #endif /* !WL_CFG80211_P2P_DEV_IF && (LINUX_VERSION >= VERSION(3, 8, 0)) */
177
178 #if defined(WL_ENABLE_P2P_IF) && (defined(WL_CFG80211_P2P_DEV_IF) || \
179         (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0)))
180 #error Disable 'WL_ENABLE_P2P_IF', if 'WL_CFG80211_P2P_DEV_IF' is enabled \
181         or kernel version is 3.8.0 or above
182 #endif /* WL_ENABLE_P2P_IF && (WL_CFG80211_P2P_DEV_IF || (LINUX_VERSION >= VERSION(3, 8, 0))) */
183
184 #if !defined(WLP2P) && (defined(WL_ENABLE_P2P_IF) || defined(WL_CFG80211_P2P_DEV_IF))
185 #error WLP2P not defined
186 #endif /* !WLP2P && (WL_ENABLE_P2P_IF || WL_CFG80211_P2P_DEV_IF) */
187
188 #if defined(WL_CFG80211_P2P_DEV_IF)
189 #define bcm_struct_cfgdev       struct wireless_dev
190 #else
191 #define bcm_struct_cfgdev       struct net_device
192 #endif /* WL_CFG80211_P2P_DEV_IF */
193
194 extern void
195 wl_cfgp2p_listen_expired(unsigned long data);
196 extern bool
197 wl_cfgp2p_is_pub_action(void *frame, u32 frame_len);
198 extern bool
199 wl_cfgp2p_is_p2p_action(void *frame, u32 frame_len);
200 extern bool
201 wl_cfgp2p_is_gas_action(void *frame, u32 frame_len);
202 extern bool
203 wl_cfgp2p_find_gas_subtype(u8 subtype, u8* data, u32 len);
204 extern void
205 wl_cfgp2p_print_actframe(bool tx, void *frame, u32 frame_len, u32 channel);
206 extern s32
207 wl_cfgp2p_init_priv(struct wl_priv *wl);
208 extern void
209 wl_cfgp2p_deinit_priv(struct wl_priv *wl);
210 extern s32
211 wl_cfgp2p_set_firm_p2p(struct wl_priv *wl);
212 extern s32
213 wl_cfgp2p_set_p2p_mode(struct wl_priv *wl, u8 mode,
214             u32 channel, u16 listen_ms, int bssidx);
215 extern s32
216 wl_cfgp2p_ifadd(struct wl_priv *wl, struct ether_addr *mac, u8 if_type,
217             chanspec_t chspec);
218 extern s32
219 wl_cfgp2p_ifdisable(struct wl_priv *wl, struct ether_addr *mac);
220 extern s32
221 wl_cfgp2p_ifdel(struct wl_priv *wl, struct ether_addr *mac);
222 extern s32
223 wl_cfgp2p_ifchange(struct wl_priv *wl, struct ether_addr *mac, u8 if_type, chanspec_t chspec);
224
225 extern s32
226 wl_cfgp2p_ifidx(struct wl_priv *wl, struct ether_addr *mac, s32 *index);
227
228 extern s32
229 wl_cfgp2p_init_discovery(struct wl_priv *wl);
230 extern s32
231 wl_cfgp2p_enable_discovery(struct wl_priv *wl, struct net_device *dev, const u8 *ie, u32 ie_len);
232 extern s32
233 wl_cfgp2p_disable_discovery(struct wl_priv *wl);
234 extern s32
235 wl_cfgp2p_escan(struct wl_priv *wl, struct net_device *dev, u16 active, u32 num_chans,
236         u16 *channels,
237         s32 search_state, u16 action, u32 bssidx, struct ether_addr *tx_dst_addr,
238         p2p_scan_purpose_t p2p_scan_purpose);
239
240 extern s32
241 wl_cfgp2p_act_frm_search(struct wl_priv *wl, struct net_device *ndev,
242         s32 bssidx, s32 channel, struct ether_addr *tx_dst_addr);
243
244 extern wpa_ie_fixed_t *
245 wl_cfgp2p_find_wpaie(u8 *parse, u32 len);
246
247 extern wpa_ie_fixed_t *
248 wl_cfgp2p_find_wpsie(u8 *parse, u32 len);
249
250 extern wifi_p2p_ie_t *
251 wl_cfgp2p_find_p2pie(u8 *parse, u32 len);
252
253 extern wifi_wfd_ie_t *
254 wl_cfgp2p_find_wfdie(u8 *parse, u32 len);
255 extern s32
256 wl_cfgp2p_set_management_ie(struct wl_priv *wl, struct net_device *ndev, s32 bssidx,
257             s32 pktflag, const u8 *vndr_ie, u32 vndr_ie_len);
258 extern s32
259 wl_cfgp2p_clear_management_ie(struct wl_priv *wl, s32 bssidx);
260
261 extern s32
262 wl_cfgp2p_find_idx(struct wl_priv *wl, struct net_device *ndev, s32 *index);
263 extern struct net_device *
264 wl_cfgp2p_find_ndev(struct wl_priv *wl, s32 bssidx);
265 extern s32
266 wl_cfgp2p_find_type(struct wl_priv *wl, s32 bssidx, s32 *type);
267
268
269 extern s32
270 wl_cfgp2p_listen_complete(struct wl_priv *wl, bcm_struct_cfgdev *cfgdev,
271         const wl_event_msg_t *e, void *data);
272 extern s32
273 wl_cfgp2p_discover_listen(struct wl_priv *wl, s32 channel, u32 duration_ms);
274
275 extern s32
276 wl_cfgp2p_discover_enable_search(struct wl_priv *wl, u8 enable);
277
278 extern s32
279 wl_cfgp2p_action_tx_complete(struct wl_priv *wl, bcm_struct_cfgdev *cfgdev,
280         const wl_event_msg_t *e, void *data);
281
282 extern s32
283 wl_cfgp2p_tx_action_frame(struct wl_priv *wl, struct net_device *dev,
284         wl_af_params_t *af_params, s32 bssidx);
285
286 extern void
287 wl_cfgp2p_generate_bss_mac(struct ether_addr *primary_addr, struct ether_addr *out_dev_addr,
288             struct ether_addr *out_int_addr);
289
290 extern void
291 wl_cfg80211_change_ifaddr(u8* buf, struct ether_addr *p2p_int_addr, u8 element_id);
292 extern bool
293 wl_cfgp2p_bss_isup(struct net_device *ndev, int bsscfg_idx);
294
295 extern s32
296 wl_cfgp2p_bss(struct wl_priv *wl, struct net_device *ndev, s32 bsscfg_idx, s32 up);
297
298
299 extern s32
300 wl_cfgp2p_supported(struct wl_priv *wl, struct net_device *ndev);
301
302 extern s32
303 wl_cfgp2p_down(struct wl_priv *wl);
304
305 extern s32
306 wl_cfgp2p_set_p2p_noa(struct wl_priv *wl, struct net_device *ndev, char* buf, int len);
307
308 extern s32
309 wl_cfgp2p_get_p2p_noa(struct wl_priv *wl, struct net_device *ndev, char* buf, int len);
310
311 extern s32
312 wl_cfgp2p_set_p2p_ps(struct wl_priv *wl, struct net_device *ndev, char* buf, int len);
313
314 extern u8 *
315 wl_cfgp2p_retreive_p2pattrib(void *buf, u8 element_id);
316
317 extern u8*
318 wl_cfgp2p_find_attrib_in_all_p2p_Ies(u8 *parse, u32 len, u32 attrib);
319
320 extern u8 *
321 wl_cfgp2p_retreive_p2p_dev_addr(wl_bss_info_t *bi, u32 bi_length);
322
323 extern s32
324 wl_cfgp2p_register_ndev(struct wl_priv *wl);
325
326 extern s32
327 wl_cfgp2p_unregister_ndev(struct wl_priv *wl);
328
329 extern bool
330 wl_cfgp2p_is_ifops(const struct net_device_ops *if_ops);
331
332 #if defined(WL_CFG80211_P2P_DEV_IF)
333 extern struct wireless_dev *
334 wl_cfgp2p_add_p2p_disc_if(void);
335
336 extern int
337 wl_cfgp2p_start_p2p_device(struct wiphy *wiphy, struct wireless_dev *wdev);
338
339 extern void
340 wl_cfgp2p_stop_p2p_device(struct wiphy *wiphy, struct wireless_dev *wdev);
341
342 extern int
343 wl_cfgp2p_del_p2p_disc_if(struct wireless_dev *wdev);
344 #endif /* WL_CFG80211_P2P_DEV_IF */
345
346 /* WiFi Direct */
347 #define SOCIAL_CHAN_1 1
348 #define SOCIAL_CHAN_2 6
349 #define SOCIAL_CHAN_3 11
350 #define IS_P2P_SOCIAL_CHANNEL(channel) ((channel == SOCIAL_CHAN_1) || \
351                                         (channel == SOCIAL_CHAN_2) || \
352                                         (channel == SOCIAL_CHAN_3))
353 #define SOCIAL_CHAN_CNT 3
354 #define AF_PEER_SEARCH_CNT 2
355 #define WL_P2P_WILDCARD_SSID "DIRECT-"
356 #define WL_P2P_WILDCARD_SSID_LEN 7
357 #define WL_P2P_INTERFACE_PREFIX "p2p"
358 #define WL_P2P_TEMP_CHAN 11
359
360 /* If the provision discovery is for JOIN operations,
361  * or the device discoverablity frame is destined to GO
362  * then we need not do an internal scan to find GO.
363  */
364 #define IS_ACTPUB_WITHOUT_GROUP_ID(p2p_ie, len) \
365         (wl_cfgp2p_retreive_p2pattrib(p2p_ie, P2P_SEID_GROUP_ID) == NULL)
366
367 #define IS_GAS_REQ(frame, len) (wl_cfgp2p_is_gas_action(frame, len) && \
368                                         ((frame->action == P2PSD_ACTION_ID_GAS_IREQ) || \
369                                         (frame->action == P2PSD_ACTION_ID_GAS_CREQ)))
370
371 #define IS_P2P_PUB_ACT_RSP_SUBTYPE(subtype) ((subtype == P2P_PAF_GON_RSP) || \
372                                                         ((subtype == P2P_PAF_GON_CONF) || \
373                                                         (subtype == P2P_PAF_INVITE_RSP) || \
374                                                         (subtype == P2P_PAF_PROVDIS_RSP)))
375 #define IS_P2P_SOCIAL(ch) ((ch == SOCIAL_CHAN_1) || (ch == SOCIAL_CHAN_2) || (ch == SOCIAL_CHAN_3))
376 #define IS_P2P_SSID(ssid, len) (!memcmp(ssid, WL_P2P_WILDCARD_SSID, WL_P2P_WILDCARD_SSID_LEN) && \
377                                         (len == WL_P2P_WILDCARD_SSID_LEN))
378 #endif                          /* _wl_cfgp2p_h_ */