2 * Copyright (c) 2012 Broadcom Corporation
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.
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.
16 #include <linux/slab.h>
17 #include <linux/netdevice.h>
18 #include <linux/etherdevice.h>
19 #include <net/cfg80211.h>
21 #include <brcmu_wifi.h>
22 #include <brcmu_utils.h>
27 #include "fwil_types.h"
29 #include "wl_cfg80211.h"
31 /* parameters used for p2p escan */
32 #define P2PAPI_SCAN_NPROBES 1
33 #define P2PAPI_SCAN_DWELL_TIME_MS 80
34 #define P2PAPI_SCAN_SOCIAL_DWELL_TIME_MS 40
35 #define P2PAPI_SCAN_HOME_TIME_MS 60
36 #define P2PAPI_SCAN_NPROBS_TIME_MS 30
37 #define P2PAPI_SCAN_AF_SEARCH_DWELL_TIME_MS 100
38 #define WL_SCAN_CONNECT_DWELL_TIME_MS 200
39 #define WL_SCAN_JOIN_PROBE_INTERVAL_MS 20
41 #define BRCMF_P2P_WILDCARD_SSID "DIRECT-"
42 #define BRCMF_P2P_WILDCARD_SSID_LEN (sizeof(BRCMF_P2P_WILDCARD_SSID) - 1)
44 #define SOCIAL_CHAN_1 1
45 #define SOCIAL_CHAN_2 6
46 #define SOCIAL_CHAN_3 11
47 #define IS_P2P_SOCIAL_CHANNEL(channel) ((channel == SOCIAL_CHAN_1) || \
48 (channel == SOCIAL_CHAN_2) || \
49 (channel == SOCIAL_CHAN_3))
50 #define BRCMF_P2P_TEMP_CHAN SOCIAL_CHAN_3
51 #define SOCIAL_CHAN_CNT 3
52 #define AF_PEER_SEARCH_CNT 2
54 #define BRCMF_SCB_TIMEOUT_VALUE 20
56 #define P2P_VER 9 /* P2P version: 9=WiFi P2P v1.0 */
57 #define P2P_PUB_AF_CATEGORY 0x04
58 #define P2P_PUB_AF_ACTION 0x09
59 #define P2P_AF_CATEGORY 0x7f
60 #define P2P_OUI "\x50\x6F\x9A" /* P2P OUI */
61 #define P2P_OUI_LEN 3 /* P2P OUI length */
63 /* Action Frame Constants */
64 #define DOT11_ACTION_HDR_LEN 2 /* action frame category + action */
65 #define DOT11_ACTION_CAT_OFF 0 /* category offset */
66 #define DOT11_ACTION_ACT_OFF 1 /* action offset */
68 #define P2P_AF_DWELL_TIME 200
69 #define P2P_AF_MIN_DWELL_TIME 100
70 #define P2P_AF_MED_DWELL_TIME 400
71 #define P2P_AF_LONG_DWELL_TIME 1000
72 #define P2P_AF_TX_MAX_RETRY 1
73 #define P2P_AF_MAX_WAIT_TIME 2000
74 #define P2P_INVALID_CHANNEL -1
75 #define P2P_CHANNEL_SYNC_RETRY 5
76 #define P2P_AF_FRM_SCAN_MAX_WAIT 1500
77 #define P2P_DEFAULT_SLEEP_TIME_VSDB 200
79 /* WiFi P2P Public Action Frame OUI Subtypes */
80 #define P2P_PAF_GON_REQ 0 /* Group Owner Negotiation Req */
81 #define P2P_PAF_GON_RSP 1 /* Group Owner Negotiation Rsp */
82 #define P2P_PAF_GON_CONF 2 /* Group Owner Negotiation Confirm */
83 #define P2P_PAF_INVITE_REQ 3 /* P2P Invitation Request */
84 #define P2P_PAF_INVITE_RSP 4 /* P2P Invitation Response */
85 #define P2P_PAF_DEVDIS_REQ 5 /* Device Discoverability Request */
86 #define P2P_PAF_DEVDIS_RSP 6 /* Device Discoverability Response */
87 #define P2P_PAF_PROVDIS_REQ 7 /* Provision Discovery Request */
88 #define P2P_PAF_PROVDIS_RSP 8 /* Provision Discovery Response */
89 #define P2P_PAF_SUBTYPE_INVALID 255 /* Invalid Subtype */
91 /* WiFi P2P Action Frame OUI Subtypes */
92 #define P2P_AF_NOTICE_OF_ABSENCE 0 /* Notice of Absence */
93 #define P2P_AF_PRESENCE_REQ 1 /* P2P Presence Request */
94 #define P2P_AF_PRESENCE_RSP 2 /* P2P Presence Response */
95 #define P2P_AF_GO_DISC_REQ 3 /* GO Discoverability Request */
97 /* P2P Service Discovery related */
98 #define P2PSD_ACTION_CATEGORY 0x04 /* Public action frame */
99 #define P2PSD_ACTION_ID_GAS_IREQ 0x0a /* GAS Initial Request AF */
100 #define P2PSD_ACTION_ID_GAS_IRESP 0x0b /* GAS Initial Response AF */
101 #define P2PSD_ACTION_ID_GAS_CREQ 0x0c /* GAS Comback Request AF */
102 #define P2PSD_ACTION_ID_GAS_CRESP 0x0d /* GAS Comback Response AF */
105 * struct brcmf_p2p_disc_st_le - set discovery state in firmware.
107 * @state: requested discovery state (see enum brcmf_p2p_disc_state).
108 * @chspec: channel parameter for %WL_P2P_DISC_ST_LISTEN state.
109 * @dwell: dwell time in ms for %WL_P2P_DISC_ST_LISTEN state.
111 struct brcmf_p2p_disc_st_le
{
118 * enum brcmf_p2p_disc_state - P2P discovery state values
120 * @WL_P2P_DISC_ST_SCAN: P2P discovery with wildcard SSID and P2P IE.
121 * @WL_P2P_DISC_ST_LISTEN: P2P discovery off-channel for specified time.
122 * @WL_P2P_DISC_ST_SEARCH: P2P discovery with P2P wildcard SSID and P2P IE.
124 enum brcmf_p2p_disc_state
{
126 WL_P2P_DISC_ST_LISTEN
,
127 WL_P2P_DISC_ST_SEARCH
131 * struct brcmf_p2p_scan_le - P2P specific scan request.
133 * @type: type of scan method requested (values: 'E' or 'S').
134 * @reserved: reserved (ignored).
135 * @eparams: parameters used for type 'E'.
136 * @sparams: parameters used for type 'S'.
138 struct brcmf_p2p_scan_le
{
142 struct brcmf_escan_params_le eparams
;
143 struct brcmf_scan_params_le sparams
;
148 * struct brcmf_p2p_pub_act_frame - WiFi P2P Public Action Frame
150 * @category: P2P_PUB_AF_CATEGORY
151 * @action: P2P_PUB_AF_ACTION
153 * @oui_type: OUI type - P2P_VER
154 * @subtype: OUI subtype - P2P_TYPE_*
155 * @dialog_token: nonzero, identifies req/rsp transaction
156 * @elts[1]: Variable length information elements.
158 struct brcmf_p2p_pub_act_frame
{
169 * struct brcmf_p2p_action_frame - WiFi P2P Action Frame
171 * @category: P2P_AF_CATEGORY
172 * @OUI[3]: OUI - P2P_OUI
173 * @type: OUI Type - P2P_VER
174 * @subtype: OUI Subtype - P2P_AF_*
175 * @dialog_token: nonzero, identifies req/resp tranaction
176 * @elts[1]: Variable length information elements.
178 struct brcmf_p2p_action_frame
{
188 * struct brcmf_p2psd_gas_pub_act_frame - Wi-Fi GAS Public Action Frame
190 * @category: 0x04 Public Action Frame
191 * @action: 0x6c Advertisement Protocol
192 * @dialog_token: nonzero, identifies req/rsp transaction
193 * @query_data[1]: Query Data. SD gas ireq SD gas iresp
195 struct brcmf_p2psd_gas_pub_act_frame
{
203 * struct brcmf_config_af_params - Action Frame Parameters for tx.
205 * @mpc_onoff: To make sure to send successfully action frame, we have to
206 * turn off mpc 0: off, 1: on, (-1): do nothing
207 * @search_channel: 1: search peer's channel to send af
208 * extra_listen: keep the dwell time to get af response frame.
210 struct brcmf_config_af_params
{
217 * brcmf_p2p_is_pub_action() - true if p2p public type frame.
219 * @frame: action frame data.
220 * @frame_len: length of action frame data.
222 * Determine if action frame is p2p public action type
224 static bool brcmf_p2p_is_pub_action(void *frame
, u32 frame_len
)
226 struct brcmf_p2p_pub_act_frame
*pact_frm
;
231 pact_frm
= (struct brcmf_p2p_pub_act_frame
*)frame
;
232 if (frame_len
< sizeof(struct brcmf_p2p_pub_act_frame
) - 1)
235 if (pact_frm
->category
== P2P_PUB_AF_CATEGORY
&&
236 pact_frm
->action
== P2P_PUB_AF_ACTION
&&
237 pact_frm
->oui_type
== P2P_VER
&&
238 memcmp(pact_frm
->oui
, P2P_OUI
, P2P_OUI_LEN
) == 0)
245 * brcmf_p2p_is_p2p_action() - true if p2p action type frame.
247 * @frame: action frame data.
248 * @frame_len: length of action frame data.
250 * Determine if action frame is p2p action type
252 static bool brcmf_p2p_is_p2p_action(void *frame
, u32 frame_len
)
254 struct brcmf_p2p_action_frame
*act_frm
;
259 act_frm
= (struct brcmf_p2p_action_frame
*)frame
;
260 if (frame_len
< sizeof(struct brcmf_p2p_action_frame
) - 1)
263 if (act_frm
->category
== P2P_AF_CATEGORY
&&
264 act_frm
->type
== P2P_VER
&&
265 memcmp(act_frm
->oui
, P2P_OUI
, P2P_OUI_LEN
) == 0)
272 * brcmf_p2p_is_gas_action() - true if p2p gas action type frame.
274 * @frame: action frame data.
275 * @frame_len: length of action frame data.
277 * Determine if action frame is p2p gas action type
279 static bool brcmf_p2p_is_gas_action(void *frame
, u32 frame_len
)
281 struct brcmf_p2psd_gas_pub_act_frame
*sd_act_frm
;
286 sd_act_frm
= (struct brcmf_p2psd_gas_pub_act_frame
*)frame
;
287 if (frame_len
< sizeof(struct brcmf_p2psd_gas_pub_act_frame
) - 1)
290 if (sd_act_frm
->category
!= P2PSD_ACTION_CATEGORY
)
293 if (sd_act_frm
->action
== P2PSD_ACTION_ID_GAS_IREQ
||
294 sd_act_frm
->action
== P2PSD_ACTION_ID_GAS_IRESP
||
295 sd_act_frm
->action
== P2PSD_ACTION_ID_GAS_CREQ
||
296 sd_act_frm
->action
== P2PSD_ACTION_ID_GAS_CRESP
)
303 * brcmf_p2p_print_actframe() - debug print routine.
305 * @tx: Received or to be transmitted
306 * @frame: action frame data.
307 * @frame_len: length of action frame data.
309 * Print information about the p2p action frame
314 static void brcmf_p2p_print_actframe(bool tx
, void *frame
, u32 frame_len
)
316 struct brcmf_p2p_pub_act_frame
*pact_frm
;
317 struct brcmf_p2p_action_frame
*act_frm
;
318 struct brcmf_p2psd_gas_pub_act_frame
*sd_act_frm
;
320 if (!frame
|| frame_len
<= 2)
323 if (brcmf_p2p_is_pub_action(frame
, frame_len
)) {
324 pact_frm
= (struct brcmf_p2p_pub_act_frame
*)frame
;
325 switch (pact_frm
->subtype
) {
326 case P2P_PAF_GON_REQ
:
327 brcmf_dbg(TRACE
, "%s P2P Group Owner Negotiation Req Frame\n",
330 case P2P_PAF_GON_RSP
:
331 brcmf_dbg(TRACE
, "%s P2P Group Owner Negotiation Rsp Frame\n",
334 case P2P_PAF_GON_CONF
:
335 brcmf_dbg(TRACE
, "%s P2P Group Owner Negotiation Confirm Frame\n",
338 case P2P_PAF_INVITE_REQ
:
339 brcmf_dbg(TRACE
, "%s P2P Invitation Request Frame\n",
342 case P2P_PAF_INVITE_RSP
:
343 brcmf_dbg(TRACE
, "%s P2P Invitation Response Frame\n",
346 case P2P_PAF_DEVDIS_REQ
:
347 brcmf_dbg(TRACE
, "%s P2P Device Discoverability Request Frame\n",
350 case P2P_PAF_DEVDIS_RSP
:
351 brcmf_dbg(TRACE
, "%s P2P Device Discoverability Response Frame\n",
354 case P2P_PAF_PROVDIS_REQ
:
355 brcmf_dbg(TRACE
, "%s P2P Provision Discovery Request Frame\n",
358 case P2P_PAF_PROVDIS_RSP
:
359 brcmf_dbg(TRACE
, "%s P2P Provision Discovery Response Frame\n",
363 brcmf_dbg(TRACE
, "%s Unknown P2P Public Action Frame\n",
367 } else if (brcmf_p2p_is_p2p_action(frame
, frame_len
)) {
368 act_frm
= (struct brcmf_p2p_action_frame
*)frame
;
369 switch (act_frm
->subtype
) {
370 case P2P_AF_NOTICE_OF_ABSENCE
:
371 brcmf_dbg(TRACE
, "%s P2P Notice of Absence Frame\n",
374 case P2P_AF_PRESENCE_REQ
:
375 brcmf_dbg(TRACE
, "%s P2P Presence Request Frame\n",
378 case P2P_AF_PRESENCE_RSP
:
379 brcmf_dbg(TRACE
, "%s P2P Presence Response Frame\n",
382 case P2P_AF_GO_DISC_REQ
:
383 brcmf_dbg(TRACE
, "%s P2P Discoverability Request Frame\n",
387 brcmf_dbg(TRACE
, "%s Unknown P2P Action Frame\n",
391 } else if (brcmf_p2p_is_gas_action(frame
, frame_len
)) {
392 sd_act_frm
= (struct brcmf_p2psd_gas_pub_act_frame
*)frame
;
393 switch (sd_act_frm
->action
) {
394 case P2PSD_ACTION_ID_GAS_IREQ
:
395 brcmf_dbg(TRACE
, "%s P2P GAS Initial Request\n",
398 case P2PSD_ACTION_ID_GAS_IRESP
:
399 brcmf_dbg(TRACE
, "%s P2P GAS Initial Response\n",
402 case P2PSD_ACTION_ID_GAS_CREQ
:
403 brcmf_dbg(TRACE
, "%s P2P GAS Comback Request\n",
406 case P2PSD_ACTION_ID_GAS_CRESP
:
407 brcmf_dbg(TRACE
, "%s P2P GAS Comback Response\n",
411 brcmf_dbg(TRACE
, "%s Unknown P2P GAS Frame\n",
420 static void brcmf_p2p_print_actframe(bool tx
, void *frame
, u32 frame_len
)
428 * brcmf_p2p_set_firmware() - prepare firmware for peer-to-peer operation.
430 * @ifp: ifp to use for iovars (primary).
431 * @p2p_mac: mac address to configure for p2p_da_override
433 static int brcmf_p2p_set_firmware(struct brcmf_if
*ifp
, u8
*p2p_mac
)
437 brcmf_fil_cmd_int_set(ifp
, BRCMF_C_DOWN
, 1);
438 brcmf_fil_iovar_int_set(ifp
, "apsta", 1);
439 brcmf_fil_cmd_int_set(ifp
, BRCMF_C_UP
, 1);
441 /* In case of COB type, firmware has default mac address
442 * After Initializing firmware, we have to set current mac address to
443 * firmware for P2P device address
445 ret
= brcmf_fil_iovar_data_set(ifp
, "p2p_da_override", p2p_mac
,
448 brcmf_err("failed to update device address ret %d\n", ret
);
454 * brcmf_p2p_generate_bss_mac() - derive mac addresses for P2P.
456 * @p2p: P2P specific data.
457 * @dev_addr: optional device address.
459 * P2P needs mac addresses for P2P device and interface. If no device
460 * address it specified, these are derived from the primary net device, ie.
461 * the permanent ethernet address of the device.
463 static void brcmf_p2p_generate_bss_mac(struct brcmf_p2p_info
*p2p
, u8
*dev_addr
)
465 struct brcmf_if
*pri_ifp
= p2p
->bss_idx
[P2PAPI_BSSCFG_PRIMARY
].vif
->ifp
;
466 bool local_admin
= false;
468 if (!dev_addr
|| is_zero_ether_addr(dev_addr
)) {
469 dev_addr
= pri_ifp
->mac_addr
;
473 /* Generate the P2P Device Address. This consists of the device's
474 * primary MAC address with the locally administered bit set.
476 memcpy(p2p
->dev_addr
, dev_addr
, ETH_ALEN
);
478 p2p
->dev_addr
[0] |= 0x02;
480 /* Generate the P2P Interface Address. If the discovery and connection
481 * BSSCFGs need to simultaneously co-exist, then this address must be
482 * different from the P2P Device Address, but also locally administered.
484 memcpy(p2p
->int_addr
, p2p
->dev_addr
, ETH_ALEN
);
485 p2p
->int_addr
[0] |= 0x02;
486 p2p
->int_addr
[4] ^= 0x80;
490 * brcmf_p2p_scan_is_p2p_request() - is cfg80211 scan request a P2P scan.
492 * @request: the scan request as received from cfg80211.
494 * returns true if one of the ssids in the request matches the
495 * P2P wildcard ssid; otherwise returns false.
497 static bool brcmf_p2p_scan_is_p2p_request(struct cfg80211_scan_request
*request
)
499 struct cfg80211_ssid
*ssids
= request
->ssids
;
502 for (i
= 0; i
< request
->n_ssids
; i
++) {
503 if (ssids
[i
].ssid_len
!= BRCMF_P2P_WILDCARD_SSID_LEN
)
506 brcmf_dbg(INFO
, "comparing ssid \"%s\"", ssids
[i
].ssid
);
507 if (!memcmp(BRCMF_P2P_WILDCARD_SSID
, ssids
[i
].ssid
,
508 BRCMF_P2P_WILDCARD_SSID_LEN
))
515 * brcmf_p2p_set_discover_state - set discover state in firmware.
517 * @ifp: low-level interface object.
518 * @state: discover state to set.
519 * @chanspec: channel parameters (for state @WL_P2P_DISC_ST_LISTEN only).
520 * @listen_ms: duration to listen (for state @WL_P2P_DISC_ST_LISTEN only).
522 static s32
brcmf_p2p_set_discover_state(struct brcmf_if
*ifp
, u8 state
,
523 u16 chanspec
, u16 listen_ms
)
525 struct brcmf_p2p_disc_st_le discover_state
;
527 brcmf_dbg(TRACE
, "enter\n");
529 discover_state
.state
= state
;
530 discover_state
.chspec
= cpu_to_le16(chanspec
);
531 discover_state
.dwell
= cpu_to_le16(listen_ms
);
532 ret
= brcmf_fil_bsscfg_data_set(ifp
, "p2p_state", &discover_state
,
533 sizeof(discover_state
));
538 * brcmf_p2p_deinit_discovery() - disable P2P device discovery.
540 * @p2p: P2P specific data.
542 * Resets the discovery state and disables it in firmware.
544 static s32
brcmf_p2p_deinit_discovery(struct brcmf_p2p_info
*p2p
)
546 struct brcmf_cfg80211_vif
*vif
;
548 brcmf_dbg(TRACE
, "enter\n");
550 /* Set the discovery state to SCAN */
551 vif
= p2p
->bss_idx
[P2PAPI_BSSCFG_DEVICE
].vif
;
552 (void)brcmf_p2p_set_discover_state(vif
->ifp
, WL_P2P_DISC_ST_SCAN
, 0, 0);
554 /* Disable P2P discovery in the firmware */
555 vif
= p2p
->bss_idx
[P2PAPI_BSSCFG_PRIMARY
].vif
;
556 (void)brcmf_fil_iovar_int_set(vif
->ifp
, "p2p_disc", 0);
562 * brcmf_p2p_enable_discovery() - initialize and configure discovery.
564 * @p2p: P2P specific data.
566 * Initializes the discovery device and configure the virtual interface.
568 static int brcmf_p2p_enable_discovery(struct brcmf_p2p_info
*p2p
)
570 struct brcmf_cfg80211_vif
*vif
;
573 brcmf_dbg(TRACE
, "enter\n");
574 vif
= p2p
->bss_idx
[P2PAPI_BSSCFG_DEVICE
].vif
;
576 brcmf_err("P2P config device not available\n");
581 if (test_bit(BRCMF_P2P_STATUS_ENABLED
, &p2p
->status
)) {
582 brcmf_dbg(INFO
, "P2P config device already configured\n");
586 /* Re-initialize P2P Discovery in the firmware */
587 vif
= p2p
->bss_idx
[P2PAPI_BSSCFG_PRIMARY
].vif
;
588 ret
= brcmf_fil_iovar_int_set(vif
->ifp
, "p2p_disc", 1);
590 brcmf_err("set p2p_disc error\n");
593 vif
= p2p
->bss_idx
[P2PAPI_BSSCFG_DEVICE
].vif
;
594 ret
= brcmf_p2p_set_discover_state(vif
->ifp
, WL_P2P_DISC_ST_SCAN
, 0, 0);
596 brcmf_err("unable to set WL_P2P_DISC_ST_SCAN\n");
601 * Set wsec to any non-zero value in the discovery bsscfg
602 * to ensure our P2P probe responses have the privacy bit
603 * set in the 802.11 WPA IE. Some peer devices may not
604 * initiate WPS with us if this bit is not set.
606 ret
= brcmf_fil_bsscfg_int_set(vif
->ifp
, "wsec", AES_ENABLED
);
608 brcmf_err("wsec error %d\n", ret
);
612 set_bit(BRCMF_P2P_STATUS_ENABLED
, &p2p
->status
);
618 * brcmf_p2p_escan() - initiate a P2P scan.
620 * @p2p: P2P specific data.
621 * @num_chans: number of channels to scan.
622 * @chanspecs: channel parameters for @num_chans channels.
623 * @search_state: P2P discover state to use.
624 * @action: scan action to pass to firmware.
625 * @bss_type: type of P2P bss.
627 static s32
brcmf_p2p_escan(struct brcmf_p2p_info
*p2p
, u32 num_chans
,
628 u16 chanspecs
[], s32 search_state
, u16 action
,
629 enum p2p_bss_type bss_type
)
632 s32 memsize
= offsetof(struct brcmf_p2p_scan_le
,
633 eparams
.params_le
.channel_list
);
638 struct brcmf_cfg80211_vif
*vif
;
639 struct brcmf_p2p_scan_le
*p2p_params
;
640 struct brcmf_scan_params_le
*sparams
;
641 struct brcmf_ssid ssid
;
643 memsize
+= num_chans
* sizeof(__le16
);
644 memblk
= kzalloc(memsize
, GFP_KERNEL
);
648 vif
= p2p
->bss_idx
[bss_type
].vif
;
650 brcmf_err("no vif for bss type %d\n", bss_type
);
655 switch (search_state
) {
656 case WL_P2P_DISC_ST_SEARCH
:
658 * If we in SEARCH STATE, we don't need to set SSID explictly
659 * because dongle use P2P WILDCARD internally by default
663 memset(ssid
.SSID
, 0, sizeof(ssid
.SSID
));
665 case WL_P2P_DISC_ST_SCAN
:
667 * wpa_supplicant has p2p_find command with type social or
668 * progressive. For progressive, we need to set the ssid to
669 * P2P WILDCARD because we just do broadcast scan unless
672 ssid
.SSID_len
= BRCMF_P2P_WILDCARD_SSID_LEN
;
673 memcpy(ssid
.SSID
, BRCMF_P2P_WILDCARD_SSID
, ssid
.SSID_len
);
676 brcmf_err(" invalid search state %d\n", search_state
);
681 brcmf_p2p_set_discover_state(vif
->ifp
, search_state
, 0, 0);
684 * set p2p scan parameters.
686 p2p_params
= (struct brcmf_p2p_scan_le
*)memblk
;
687 p2p_params
->type
= 'E';
689 /* determine the scan engine parameters */
690 sparams
= &p2p_params
->eparams
.params_le
;
691 sparams
->bss_type
= DOT11_BSSTYPE_ANY
;
692 if (p2p
->cfg
->active_scan
)
693 sparams
->scan_type
= 0;
695 sparams
->scan_type
= 1;
697 memset(&sparams
->bssid
, 0xFF, ETH_ALEN
);
699 memcpy(sparams
->ssid_le
.SSID
, ssid
.SSID
, ssid
.SSID_len
);
700 sparams
->ssid_le
.SSID_len
= cpu_to_le32(ssid
.SSID_len
);
701 sparams
->home_time
= cpu_to_le32(P2PAPI_SCAN_HOME_TIME_MS
);
704 * SOCIAL_CHAN_CNT + 1 takes care of the Progressive scan
705 * supported by the supplicant.
707 if (num_chans
== SOCIAL_CHAN_CNT
|| num_chans
== (SOCIAL_CHAN_CNT
+ 1))
708 active
= P2PAPI_SCAN_SOCIAL_DWELL_TIME_MS
;
709 else if (num_chans
== AF_PEER_SEARCH_CNT
)
710 active
= P2PAPI_SCAN_AF_SEARCH_DWELL_TIME_MS
;
711 else if (wl_get_vif_state_all(p2p
->cfg
, BRCMF_VIF_STATUS_CONNECTED
))
714 active
= P2PAPI_SCAN_DWELL_TIME_MS
;
716 /* Override scan params to find a peer for a connection */
717 if (num_chans
== 1) {
718 active
= WL_SCAN_CONNECT_DWELL_TIME_MS
;
719 /* WAR to sync with presence period of VSDB GO.
720 * send probe request more frequently
722 nprobes
= active
/ WL_SCAN_JOIN_PROBE_INTERVAL_MS
;
724 nprobes
= active
/ P2PAPI_SCAN_NPROBS_TIME_MS
;
730 brcmf_dbg(INFO
, "nprobes # %d, active_time %d\n", nprobes
, active
);
731 sparams
->active_time
= cpu_to_le32(active
);
732 sparams
->nprobes
= cpu_to_le32(nprobes
);
733 sparams
->passive_time
= cpu_to_le32(-1);
734 sparams
->channel_num
= cpu_to_le32(num_chans
&
735 BRCMF_SCAN_PARAMS_COUNT_MASK
);
736 for (i
= 0; i
< num_chans
; i
++)
737 sparams
->channel_list
[i
] = cpu_to_le16(chanspecs
[i
]);
739 /* set the escan specific parameters */
740 p2p_params
->eparams
.version
= cpu_to_le32(BRCMF_ESCAN_REQ_VERSION
);
741 p2p_params
->eparams
.action
= cpu_to_le16(action
);
742 p2p_params
->eparams
.sync_id
= cpu_to_le16(0x1234);
743 /* perform p2p scan on primary device */
744 ret
= brcmf_fil_bsscfg_data_set(vif
->ifp
, "p2p_scan", memblk
, memsize
);
746 set_bit(BRCMF_SCAN_STATUS_BUSY
, &p2p
->cfg
->scan_status
);
753 * brcmf_p2p_run_escan() - escan callback for peer-to-peer.
755 * @cfg: driver private data for cfg80211 interface.
756 * @ndev: net device for which scan is requested.
757 * @request: scan request from cfg80211.
758 * @action: scan action.
760 * Determines the P2P discovery state based to scan request parameters and
761 * validates the channels in the request.
763 static s32
brcmf_p2p_run_escan(struct brcmf_cfg80211_info
*cfg
,
764 struct brcmf_if
*ifp
,
765 struct cfg80211_scan_request
*request
,
768 struct brcmf_p2p_info
*p2p
= &cfg
->p2p
;
770 s32 search_state
= WL_P2P_DISC_ST_SCAN
;
771 struct brcmf_cfg80211_vif
*vif
;
772 struct net_device
*dev
= NULL
;
773 int i
, num_nodfs
= 0;
776 brcmf_dbg(TRACE
, "enter\n");
783 if (request
->n_channels
) {
784 chanspecs
= kcalloc(request
->n_channels
, sizeof(*chanspecs
),
790 vif
= p2p
->bss_idx
[P2PAPI_BSSCFG_CONNECTION
].vif
;
792 dev
= vif
->wdev
.netdev
;
793 if (request
->n_channels
== 3 &&
794 request
->channels
[0]->hw_value
== SOCIAL_CHAN_1
&&
795 request
->channels
[1]->hw_value
== SOCIAL_CHAN_2
&&
796 request
->channels
[2]->hw_value
== SOCIAL_CHAN_3
) {
797 /* SOCIAL CHANNELS 1, 6, 11 */
798 search_state
= WL_P2P_DISC_ST_SEARCH
;
799 brcmf_dbg(INFO
, "P2P SEARCH PHASE START\n");
800 } else if (dev
!= NULL
&& vif
->mode
== WL_MODE_AP
) {
801 /* If you are already a GO, then do SEARCH only */
802 brcmf_dbg(INFO
, "Already a GO. Do SEARCH Only\n");
803 search_state
= WL_P2P_DISC_ST_SEARCH
;
805 brcmf_dbg(INFO
, "P2P SCAN STATE START\n");
809 * no P2P scanning on passive or DFS channels.
811 for (i
= 0; i
< request
->n_channels
; i
++) {
812 struct ieee80211_channel
*chan
= request
->channels
[i
];
814 if (chan
->flags
& (IEEE80211_CHAN_RADAR
|
815 IEEE80211_CHAN_PASSIVE_SCAN
))
818 chanspecs
[i
] = channel_to_chanspec(&p2p
->cfg
->d11inf
,
820 brcmf_dbg(INFO
, "%d: chan=%d, channel spec=%x\n",
821 num_nodfs
, chan
->hw_value
, chanspecs
[i
]);
824 err
= brcmf_p2p_escan(p2p
, num_nodfs
, chanspecs
, search_state
,
825 action
, P2PAPI_BSSCFG_DEVICE
);
830 brcmf_err("error (%d)\n", err
);
836 * brcmf_p2p_find_listen_channel() - find listen channel in ie string.
838 * @ie: string of information elements.
839 * @ie_len: length of string.
841 * Scan ie for p2p ie and look for attribute 6 channel. If available determine
842 * channel and return it.
844 static s32
brcmf_p2p_find_listen_channel(const u8
*ie
, u32 ie_len
)
850 err
= cfg80211_get_p2p_attr(ie
, ie_len
,
851 IEEE80211_P2P_ATTR_LISTEN_CHANNEL
,
852 channel_ie
, sizeof(channel_ie
));
856 /* listen channel subel length format: */
857 /* 3(country) + 1(op. class) + 1(chan num) */
858 listen_channel
= (s32
)channel_ie
[3 + 1];
860 if (listen_channel
== SOCIAL_CHAN_1
||
861 listen_channel
== SOCIAL_CHAN_2
||
862 listen_channel
== SOCIAL_CHAN_3
) {
863 brcmf_dbg(INFO
, "Found my Listen Channel %d\n", listen_channel
);
864 return listen_channel
;
872 * brcmf_p2p_scan_prep() - prepare scan based on request.
874 * @wiphy: wiphy device.
875 * @request: scan request from cfg80211.
876 * @vif: vif on which scan request is to be executed.
878 * Prepare the scan appropriately for type of scan requested. Overrides the
879 * escan .run() callback for peer-to-peer scanning.
881 int brcmf_p2p_scan_prep(struct wiphy
*wiphy
,
882 struct cfg80211_scan_request
*request
,
883 struct brcmf_cfg80211_vif
*vif
)
885 struct brcmf_cfg80211_info
*cfg
= wiphy_to_cfg(wiphy
);
886 struct brcmf_p2p_info
*p2p
= &cfg
->p2p
;
889 if (brcmf_p2p_scan_is_p2p_request(request
)) {
890 /* find my listen channel */
891 err
= brcmf_p2p_find_listen_channel(request
->ie
,
896 p2p
->afx_hdl
.my_listen_chan
= err
;
898 clear_bit(BRCMF_P2P_STATUS_GO_NEG_PHASE
, &p2p
->status
);
899 brcmf_dbg(INFO
, "P2P: GO_NEG_PHASE status cleared\n");
901 err
= brcmf_p2p_enable_discovery(p2p
);
905 vif
= p2p
->bss_idx
[P2PAPI_BSSCFG_DEVICE
].vif
;
907 /* override .run_escan() callback. */
908 cfg
->escan_info
.run
= brcmf_p2p_run_escan
;
910 err
= brcmf_vif_set_mgmt_ie(vif
, BRCMF_VNDR_IE_PRBREQ_FLAG
,
911 request
->ie
, request
->ie_len
);
917 * brcmf_p2p_discover_listen() - set firmware to discover listen state.
920 * @channel: channel nr for discover listen.
921 * @duration: time in ms to stay on channel.
925 brcmf_p2p_discover_listen(struct brcmf_p2p_info
*p2p
, u16 channel
, u32 duration
)
927 struct brcmf_cfg80211_vif
*vif
;
928 struct brcmu_chan ch
;
931 vif
= p2p
->bss_idx
[P2PAPI_BSSCFG_DEVICE
].vif
;
933 brcmf_err("Discovery is not set, so we have nothing to do\n");
938 if (test_bit(BRCMF_P2P_STATUS_DISCOVER_LISTEN
, &p2p
->status
)) {
939 brcmf_err("Previous LISTEN is not completed yet\n");
940 /* WAR: prevent cookie mismatch in wpa_supplicant return OK */
945 ch
.bw
= BRCMU_CHAN_BW_20
;
946 p2p
->cfg
->d11inf
.encchspec(&ch
);
947 err
= brcmf_p2p_set_discover_state(vif
->ifp
, WL_P2P_DISC_ST_LISTEN
,
948 ch
.chspec
, (u16
)duration
);
950 set_bit(BRCMF_P2P_STATUS_DISCOVER_LISTEN
, &p2p
->status
);
951 p2p
->remain_on_channel_cookie
++;
959 * brcmf_p2p_remain_on_channel() - put device on channel and stay there.
961 * @wiphy: wiphy device.
962 * @channel: channel to stay on.
963 * @duration: time in ms to remain on channel.
966 int brcmf_p2p_remain_on_channel(struct wiphy
*wiphy
, struct wireless_dev
*wdev
,
967 struct ieee80211_channel
*channel
,
968 unsigned int duration
, u64
*cookie
)
970 struct brcmf_cfg80211_info
*cfg
= wiphy_to_cfg(wiphy
);
971 struct brcmf_p2p_info
*p2p
= &cfg
->p2p
;
975 channel_nr
= ieee80211_frequency_to_channel(channel
->center_freq
);
976 brcmf_dbg(TRACE
, "Enter, channel: %d, duration ms (%d)\n", channel_nr
,
979 err
= brcmf_p2p_enable_discovery(p2p
);
982 err
= brcmf_p2p_discover_listen(p2p
, channel_nr
, duration
);
986 memcpy(&p2p
->remain_on_channel
, channel
, sizeof(*channel
));
987 *cookie
= p2p
->remain_on_channel_cookie
;
988 cfg80211_ready_on_channel(wdev
, *cookie
, channel
, duration
, GFP_KERNEL
);
996 * brcmf_p2p_notify_listen_complete() - p2p listen has completed.
998 * @ifp: interfac control.
999 * @e: event message. Not used, to make it usable for fweh event dispatcher.
1000 * @data: payload of message. Not used.
1003 int brcmf_p2p_notify_listen_complete(struct brcmf_if
*ifp
,
1004 const struct brcmf_event_msg
*e
,
1007 struct brcmf_cfg80211_info
*cfg
= ifp
->drvr
->config
;
1008 struct brcmf_p2p_info
*p2p
= &cfg
->p2p
;
1010 brcmf_dbg(TRACE
, "Enter\n");
1011 if (test_and_clear_bit(BRCMF_P2P_STATUS_DISCOVER_LISTEN
,
1013 if (test_and_clear_bit(BRCMF_P2P_STATUS_WAITING_NEXT_AF_LISTEN
,
1015 clear_bit(BRCMF_P2P_STATUS_WAITING_NEXT_ACT_FRAME
,
1017 brcmf_dbg(INFO
, "Listen DONE, wake up wait_next_af\n");
1018 complete(&p2p
->wait_next_af
);
1021 cfg80211_remain_on_channel_expired(&ifp
->vif
->wdev
,
1022 p2p
->remain_on_channel_cookie
,
1023 &p2p
->remain_on_channel
,
1031 * brcmf_p2p_cancel_remain_on_channel() - cancel p2p listen state.
1033 * @ifp: interfac control.
1036 void brcmf_p2p_cancel_remain_on_channel(struct brcmf_if
*ifp
)
1040 brcmf_p2p_set_discover_state(ifp
, WL_P2P_DISC_ST_SCAN
, 0, 0);
1041 brcmf_p2p_notify_listen_complete(ifp
, NULL
, NULL
);
1046 * brcmf_p2p_act_frm_search() - search function for action frame.
1049 * channel: channel on which action frame is to be trasmitted.
1051 * search function to reach at common channel to send action frame. When
1052 * channel is 0 then all social channels will be used to send af
1054 static s32
brcmf_p2p_act_frm_search(struct brcmf_p2p_info
*p2p
, u16 channel
)
1058 u16
*default_chan_list
;
1060 struct brcmu_chan ch
;
1062 brcmf_dbg(TRACE
, "Enter\n");
1065 channel_cnt
= AF_PEER_SEARCH_CNT
;
1067 channel_cnt
= SOCIAL_CHAN_CNT
;
1068 default_chan_list
= kzalloc(channel_cnt
* sizeof(*default_chan_list
),
1070 if (default_chan_list
== NULL
) {
1071 brcmf_err("channel list allocation failed\n");
1075 ch
.bw
= BRCMU_CHAN_BW_20
;
1078 p2p
->cfg
->d11inf
.encchspec(&ch
);
1079 /* insert same channel to the chan_list */
1080 for (i
= 0; i
< channel_cnt
; i
++)
1081 default_chan_list
[i
] = ch
.chspec
;
1083 ch
.chnum
= SOCIAL_CHAN_1
;
1084 p2p
->cfg
->d11inf
.encchspec(&ch
);
1085 default_chan_list
[0] = ch
.chspec
;
1086 ch
.chnum
= SOCIAL_CHAN_2
;
1087 p2p
->cfg
->d11inf
.encchspec(&ch
);
1088 default_chan_list
[1] = ch
.chspec
;
1089 ch
.chnum
= SOCIAL_CHAN_3
;
1090 p2p
->cfg
->d11inf
.encchspec(&ch
);
1091 default_chan_list
[2] = ch
.chspec
;
1093 err
= brcmf_p2p_escan(p2p
, channel_cnt
, default_chan_list
,
1094 WL_P2P_DISC_ST_SEARCH
, WL_ESCAN_ACTION_START
,
1095 P2PAPI_BSSCFG_DEVICE
);
1096 kfree(default_chan_list
);
1103 * brcmf_p2p_afx_handler() - afx worker thread.
1108 static void brcmf_p2p_afx_handler(struct work_struct
*work
)
1110 struct afx_hdl
*afx_hdl
= container_of(work
, struct afx_hdl
, afx_work
);
1111 struct brcmf_p2p_info
*p2p
= container_of(afx_hdl
,
1112 struct brcmf_p2p_info
,
1116 if (!afx_hdl
->is_active
)
1119 if (afx_hdl
->is_listen
&& afx_hdl
->my_listen_chan
)
1121 err
= brcmf_p2p_discover_listen(p2p
, afx_hdl
->my_listen_chan
,
1122 100 * (1 + prandom_u32() % 3));
1124 err
= brcmf_p2p_act_frm_search(p2p
, afx_hdl
->peer_listen_chan
);
1127 brcmf_err("ERROR occurred! value is (%d)\n", err
);
1128 if (test_bit(BRCMF_P2P_STATUS_FINDING_COMMON_CHANNEL
,
1130 complete(&afx_hdl
->act_frm_scan
);
1136 * brcmf_p2p_af_searching_channel() - search channel.
1138 * @p2p: p2p device info struct.
1141 static s32
brcmf_p2p_af_searching_channel(struct brcmf_p2p_info
*p2p
)
1143 struct afx_hdl
*afx_hdl
= &p2p
->afx_hdl
;
1144 struct brcmf_cfg80211_vif
*pri_vif
;
1145 unsigned long duration
;
1148 brcmf_dbg(TRACE
, "Enter\n");
1150 pri_vif
= p2p
->bss_idx
[P2PAPI_BSSCFG_PRIMARY
].vif
;
1152 reinit_completion(&afx_hdl
->act_frm_scan
);
1153 set_bit(BRCMF_P2P_STATUS_FINDING_COMMON_CHANNEL
, &p2p
->status
);
1154 afx_hdl
->is_active
= true;
1155 afx_hdl
->peer_chan
= P2P_INVALID_CHANNEL
;
1157 /* Loop to wait until we find a peer's channel or the
1158 * pending action frame tx is cancelled.
1161 duration
= msecs_to_jiffies(P2P_AF_FRM_SCAN_MAX_WAIT
);
1162 while ((retry
< P2P_CHANNEL_SYNC_RETRY
) &&
1163 (afx_hdl
->peer_chan
== P2P_INVALID_CHANNEL
)) {
1164 afx_hdl
->is_listen
= false;
1165 brcmf_dbg(TRACE
, "Scheduling action frame for sending.. (%d)\n",
1167 /* search peer on peer's listen channel */
1168 schedule_work(&afx_hdl
->afx_work
);
1169 wait_for_completion_timeout(&afx_hdl
->act_frm_scan
, duration
);
1170 if ((afx_hdl
->peer_chan
!= P2P_INVALID_CHANNEL
) ||
1171 (!test_bit(BRCMF_P2P_STATUS_FINDING_COMMON_CHANNEL
,
1175 if (afx_hdl
->my_listen_chan
) {
1176 brcmf_dbg(TRACE
, "Scheduling listen peer, channel=%d\n",
1177 afx_hdl
->my_listen_chan
);
1178 /* listen on my listen channel */
1179 afx_hdl
->is_listen
= true;
1180 schedule_work(&afx_hdl
->afx_work
);
1181 wait_for_completion_timeout(&afx_hdl
->act_frm_scan
,
1184 if ((afx_hdl
->peer_chan
!= P2P_INVALID_CHANNEL
) ||
1185 (!test_bit(BRCMF_P2P_STATUS_FINDING_COMMON_CHANNEL
,
1190 /* if sta is connected or connecting, sleep for a while before
1191 * retry af tx or finding a peer
1193 if (test_bit(BRCMF_VIF_STATUS_CONNECTED
, &pri_vif
->sme_state
) ||
1194 test_bit(BRCMF_VIF_STATUS_CONNECTING
, &pri_vif
->sme_state
))
1195 msleep(P2P_DEFAULT_SLEEP_TIME_VSDB
);
1198 brcmf_dbg(TRACE
, "Completed search/listen peer_chan=%d\n",
1199 afx_hdl
->peer_chan
);
1200 afx_hdl
->is_active
= false;
1202 clear_bit(BRCMF_P2P_STATUS_FINDING_COMMON_CHANNEL
, &p2p
->status
);
1204 return afx_hdl
->peer_chan
;
1209 * brcmf_p2p_scan_finding_common_channel() - was escan used for finding channel
1211 * @cfg: common configuration struct.
1212 * @bi: bss info struct, result from scan.
1215 bool brcmf_p2p_scan_finding_common_channel(struct brcmf_cfg80211_info
*cfg
,
1216 struct brcmf_bss_info_le
*bi
)
1219 struct brcmf_p2p_info
*p2p
= &cfg
->p2p
;
1220 struct afx_hdl
*afx_hdl
= &p2p
->afx_hdl
;
1221 struct brcmu_chan ch
;
1224 u8 p2p_dev_addr
[ETH_ALEN
];
1226 if (!test_bit(BRCMF_P2P_STATUS_FINDING_COMMON_CHANNEL
, &p2p
->status
))
1230 brcmf_dbg(TRACE
, "ACTION FRAME SCAN Done\n");
1231 if (afx_hdl
->peer_chan
== P2P_INVALID_CHANNEL
)
1232 complete(&afx_hdl
->act_frm_scan
);
1236 ie
= ((u8
*)bi
) + le16_to_cpu(bi
->ie_offset
);
1237 memset(p2p_dev_addr
, 0, sizeof(p2p_dev_addr
));
1238 err
= cfg80211_get_p2p_attr(ie
, le32_to_cpu(bi
->ie_length
),
1239 IEEE80211_P2P_ATTR_DEVICE_INFO
,
1240 p2p_dev_addr
, sizeof(p2p_dev_addr
));
1242 err
= cfg80211_get_p2p_attr(ie
, le32_to_cpu(bi
->ie_length
),
1243 IEEE80211_P2P_ATTR_DEVICE_ID
,
1244 p2p_dev_addr
, sizeof(p2p_dev_addr
));
1246 (!memcmp(p2p_dev_addr
, afx_hdl
->tx_dst_addr
, ETH_ALEN
))) {
1248 ch
.chspec
= le16_to_cpu(bi
->chanspec
);
1249 cfg
->d11inf
.decchspec(&ch
);
1250 bi
->ctl_ch
= ch
.chnum
;
1252 afx_hdl
->peer_chan
= bi
->ctl_ch
;
1253 brcmf_dbg(TRACE
, "ACTION FRAME SCAN : Peer %pM found, channel : %d\n",
1254 afx_hdl
->tx_dst_addr
, afx_hdl
->peer_chan
);
1255 complete(&afx_hdl
->act_frm_scan
);
1261 * brcmf_p2p_stop_wait_next_action_frame() - finish scan if af tx complete.
1263 * @cfg: common configuration struct.
1267 brcmf_p2p_stop_wait_next_action_frame(struct brcmf_cfg80211_info
*cfg
)
1269 struct brcmf_p2p_info
*p2p
= &cfg
->p2p
;
1270 struct brcmf_if
*ifp
= cfg
->escan_info
.ifp
;
1272 if (test_bit(BRCMF_P2P_STATUS_SENDING_ACT_FRAME
, &p2p
->status
) &&
1273 (test_bit(BRCMF_P2P_STATUS_ACTION_TX_COMPLETED
, &p2p
->status
) ||
1274 test_bit(BRCMF_P2P_STATUS_ACTION_TX_NOACK
, &p2p
->status
))) {
1275 brcmf_dbg(TRACE
, "*** Wake UP ** abort actframe iovar\n");
1276 /* if channel is not zero, "actfame" uses off channel scan.
1277 * So abort scan for off channel completion.
1279 if (p2p
->af_sent_channel
)
1280 brcmf_notify_escan_complete(cfg
, ifp
, true, true);
1281 } else if (test_bit(BRCMF_P2P_STATUS_WAITING_NEXT_AF_LISTEN
,
1283 brcmf_dbg(TRACE
, "*** Wake UP ** abort listen for next af frame\n");
1284 /* So abort scan to cancel listen */
1285 brcmf_notify_escan_complete(cfg
, ifp
, true, true);
1291 * brcmf_p2p_gon_req_collision() - Check if go negotiaton collission
1293 * @p2p: p2p device info struct.
1295 * return true if recevied action frame is to be dropped.
1298 brcmf_p2p_gon_req_collision(struct brcmf_p2p_info
*p2p
, u8
*mac
)
1300 struct brcmf_cfg80211_info
*cfg
= p2p
->cfg
;
1301 struct brcmf_if
*ifp
;
1303 brcmf_dbg(TRACE
, "Enter\n");
1305 if (!test_bit(BRCMF_P2P_STATUS_WAITING_NEXT_ACT_FRAME
, &p2p
->status
) ||
1306 !p2p
->gon_req_action
)
1309 brcmf_dbg(TRACE
, "GO Negotiation Request COLLISION !!!\n");
1310 /* if sa(peer) addr is less than da(my) addr, then this device
1311 * process peer's gon request and block to send gon req.
1312 * if not (sa addr > da addr),
1313 * this device will process gon request and drop gon req of peer.
1315 ifp
= p2p
->bss_idx
[P2PAPI_BSSCFG_DEVICE
].vif
->ifp
;
1316 if (memcmp(mac
, ifp
->mac_addr
, ETH_ALEN
) < 0) {
1317 brcmf_dbg(INFO
, "Block transmit gon req !!!\n");
1318 p2p
->block_gon_req_tx
= true;
1319 /* if we are finding a common channel for sending af,
1320 * do not scan more to block to send current gon req
1322 if (test_and_clear_bit(BRCMF_P2P_STATUS_FINDING_COMMON_CHANNEL
,
1324 complete(&p2p
->afx_hdl
.act_frm_scan
);
1325 if (test_and_clear_bit(BRCMF_P2P_STATUS_WAITING_NEXT_ACT_FRAME
,
1327 brcmf_p2p_stop_wait_next_action_frame(cfg
);
1331 /* drop gon request of peer to process gon request by this device. */
1332 brcmf_dbg(INFO
, "Drop received gon req !!!\n");
1339 * brcmf_p2p_notify_action_frame_rx() - received action frame.
1341 * @ifp: interfac control.
1342 * @e: event message. Not used, to make it usable for fweh event dispatcher.
1343 * @data: payload of message, containing action frame data.
1346 int brcmf_p2p_notify_action_frame_rx(struct brcmf_if
*ifp
,
1347 const struct brcmf_event_msg
*e
,
1350 struct brcmf_cfg80211_info
*cfg
= ifp
->drvr
->config
;
1351 struct brcmf_p2p_info
*p2p
= &cfg
->p2p
;
1352 struct afx_hdl
*afx_hdl
= &p2p
->afx_hdl
;
1353 struct wireless_dev
*wdev
;
1354 u32 mgmt_frame_len
= e
->datalen
- sizeof(struct brcmf_rx_mgmt_data
);
1355 struct brcmf_rx_mgmt_data
*rxframe
= (struct brcmf_rx_mgmt_data
*)data
;
1356 u8
*frame
= (u8
*)(rxframe
+ 1);
1357 struct brcmf_p2p_pub_act_frame
*act_frm
;
1358 struct brcmf_p2psd_gas_pub_act_frame
*sd_act_frm
;
1359 struct brcmu_chan ch
;
1360 struct ieee80211_mgmt
*mgmt_frame
;
1365 ch
.chspec
= be16_to_cpu(rxframe
->chanspec
);
1366 cfg
->d11inf
.decchspec(&ch
);
1367 /* Check if wpa_supplicant has registered for this frame */
1368 brcmf_dbg(INFO
, "ifp->vif->mgmt_rx_reg %04x\n", ifp
->vif
->mgmt_rx_reg
);
1369 mgmt_type
= (IEEE80211_STYPE_ACTION
& IEEE80211_FCTL_STYPE
) >> 4;
1370 if ((ifp
->vif
->mgmt_rx_reg
& BIT(mgmt_type
)) == 0)
1373 brcmf_p2p_print_actframe(false, frame
, mgmt_frame_len
);
1375 action
= P2P_PAF_SUBTYPE_INVALID
;
1376 if (brcmf_p2p_is_pub_action(frame
, mgmt_frame_len
)) {
1377 act_frm
= (struct brcmf_p2p_pub_act_frame
*)frame
;
1378 action
= act_frm
->subtype
;
1379 if ((action
== P2P_PAF_GON_REQ
) &&
1380 (brcmf_p2p_gon_req_collision(p2p
, (u8
*)e
->addr
))) {
1381 if (test_bit(BRCMF_P2P_STATUS_FINDING_COMMON_CHANNEL
,
1383 (memcmp(afx_hdl
->tx_dst_addr
, e
->addr
,
1385 afx_hdl
->peer_chan
= ch
.chnum
;
1386 brcmf_dbg(INFO
, "GON request: Peer found, channel=%d\n",
1387 afx_hdl
->peer_chan
);
1388 complete(&afx_hdl
->act_frm_scan
);
1392 /* After complete GO Negotiation, roll back to mpc mode */
1393 if ((action
== P2P_PAF_GON_CONF
) ||
1394 (action
== P2P_PAF_PROVDIS_RSP
))
1395 brcmf_set_mpc(ifp
, 1);
1396 if (action
== P2P_PAF_GON_CONF
) {
1397 brcmf_dbg(TRACE
, "P2P: GO_NEG_PHASE status cleared\n");
1398 clear_bit(BRCMF_P2P_STATUS_GO_NEG_PHASE
, &p2p
->status
);
1400 } else if (brcmf_p2p_is_gas_action(frame
, mgmt_frame_len
)) {
1401 sd_act_frm
= (struct brcmf_p2psd_gas_pub_act_frame
*)frame
;
1402 action
= sd_act_frm
->action
;
1405 if (test_bit(BRCMF_P2P_STATUS_WAITING_NEXT_ACT_FRAME
, &p2p
->status
) &&
1406 (p2p
->next_af_subtype
== action
)) {
1407 brcmf_dbg(TRACE
, "We got a right next frame! (%d)\n", action
);
1408 clear_bit(BRCMF_P2P_STATUS_WAITING_NEXT_ACT_FRAME
,
1410 /* Stop waiting for next AF. */
1411 brcmf_p2p_stop_wait_next_action_frame(cfg
);
1414 mgmt_frame
= kzalloc(offsetof(struct ieee80211_mgmt
, u
) +
1415 mgmt_frame_len
, GFP_KERNEL
);
1417 brcmf_err("No memory available for action frame\n");
1420 memcpy(mgmt_frame
->da
, ifp
->mac_addr
, ETH_ALEN
);
1421 brcmf_fil_cmd_data_get(ifp
, BRCMF_C_GET_BSSID
, mgmt_frame
->bssid
,
1423 memcpy(mgmt_frame
->sa
, e
->addr
, ETH_ALEN
);
1424 mgmt_frame
->frame_control
= cpu_to_le16(IEEE80211_STYPE_ACTION
);
1425 memcpy(&mgmt_frame
->u
, frame
, mgmt_frame_len
);
1426 mgmt_frame_len
+= offsetof(struct ieee80211_mgmt
, u
);
1428 freq
= ieee80211_channel_to_frequency(ch
.chnum
,
1429 ch
.band
== BRCMU_CHAN_BAND_2G
?
1430 IEEE80211_BAND_2GHZ
:
1431 IEEE80211_BAND_5GHZ
);
1433 wdev
= &ifp
->vif
->wdev
;
1434 cfg80211_rx_mgmt(wdev
, freq
, 0, (u8
*)mgmt_frame
, mgmt_frame_len
, 0,
1443 * brcmf_p2p_notify_action_tx_complete() - transmit action frame complete
1445 * @ifp: interfac control.
1446 * @e: event message. Not used, to make it usable for fweh event dispatcher.
1450 int brcmf_p2p_notify_action_tx_complete(struct brcmf_if
*ifp
,
1451 const struct brcmf_event_msg
*e
,
1454 struct brcmf_cfg80211_info
*cfg
= ifp
->drvr
->config
;
1455 struct brcmf_p2p_info
*p2p
= &cfg
->p2p
;
1457 brcmf_dbg(INFO
, "Enter: event %s, status=%d\n",
1458 e
->event_code
== BRCMF_E_ACTION_FRAME_OFF_CHAN_COMPLETE
?
1459 "ACTION_FRAME_OFF_CHAN_COMPLETE" : "ACTION_FRAME_COMPLETE",
1462 if (!test_bit(BRCMF_P2P_STATUS_SENDING_ACT_FRAME
, &p2p
->status
))
1465 if (e
->event_code
== BRCMF_E_ACTION_FRAME_COMPLETE
) {
1466 if (e
->status
== BRCMF_E_STATUS_SUCCESS
)
1467 set_bit(BRCMF_P2P_STATUS_ACTION_TX_COMPLETED
,
1470 set_bit(BRCMF_P2P_STATUS_ACTION_TX_NOACK
, &p2p
->status
);
1471 /* If there is no ack, we don't need to wait for
1472 * WLC_E_ACTION_FRAME_OFFCHAN_COMPLETE event
1474 brcmf_p2p_stop_wait_next_action_frame(cfg
);
1478 complete(&p2p
->send_af_done
);
1485 * brcmf_p2p_tx_action_frame() - send action frame over fil.
1487 * @p2p: p2p info struct for vif.
1488 * @af_params: action frame data/info.
1490 * Send an action frame immediately without doing channel synchronization.
1492 * This function waits for a completion event before returning.
1493 * The WLC_E_ACTION_FRAME_COMPLETE event will be received when the action
1494 * frame is transmitted.
1496 static s32
brcmf_p2p_tx_action_frame(struct brcmf_p2p_info
*p2p
,
1497 struct brcmf_fil_af_params_le
*af_params
)
1499 struct brcmf_cfg80211_vif
*vif
;
1503 brcmf_dbg(TRACE
, "Enter\n");
1505 reinit_completion(&p2p
->send_af_done
);
1506 clear_bit(BRCMF_P2P_STATUS_ACTION_TX_COMPLETED
, &p2p
->status
);
1507 clear_bit(BRCMF_P2P_STATUS_ACTION_TX_NOACK
, &p2p
->status
);
1509 vif
= p2p
->bss_idx
[P2PAPI_BSSCFG_DEVICE
].vif
;
1510 err
= brcmf_fil_bsscfg_data_set(vif
->ifp
, "actframe", af_params
,
1511 sizeof(*af_params
));
1513 brcmf_err(" sending action frame has failed\n");
1517 p2p
->af_sent_channel
= le32_to_cpu(af_params
->channel
);
1518 p2p
->af_tx_sent_jiffies
= jiffies
;
1520 timeout
= wait_for_completion_timeout(&p2p
->send_af_done
,
1521 msecs_to_jiffies(P2P_AF_MAX_WAIT_TIME
));
1523 if (test_bit(BRCMF_P2P_STATUS_ACTION_TX_COMPLETED
, &p2p
->status
)) {
1524 brcmf_dbg(TRACE
, "TX action frame operation is success\n");
1527 brcmf_dbg(TRACE
, "TX action frame operation has failed\n");
1529 /* clear status bit for action tx */
1530 clear_bit(BRCMF_P2P_STATUS_ACTION_TX_COMPLETED
, &p2p
->status
);
1531 clear_bit(BRCMF_P2P_STATUS_ACTION_TX_NOACK
, &p2p
->status
);
1539 * brcmf_p2p_pub_af_tx() - public action frame tx routine.
1541 * @cfg: driver private data for cfg80211 interface.
1542 * @af_params: action frame data/info.
1543 * @config_af_params: configuration data for action frame.
1545 * routine which transmits ation frame public type.
1547 static s32
brcmf_p2p_pub_af_tx(struct brcmf_cfg80211_info
*cfg
,
1548 struct brcmf_fil_af_params_le
*af_params
,
1549 struct brcmf_config_af_params
*config_af_params
)
1551 struct brcmf_p2p_info
*p2p
= &cfg
->p2p
;
1552 struct brcmf_fil_action_frame_le
*action_frame
;
1553 struct brcmf_p2p_pub_act_frame
*act_frm
;
1557 action_frame
= &af_params
->action_frame
;
1558 act_frm
= (struct brcmf_p2p_pub_act_frame
*)(action_frame
->data
);
1560 config_af_params
->extra_listen
= true;
1562 switch (act_frm
->subtype
) {
1563 case P2P_PAF_GON_REQ
:
1564 brcmf_dbg(TRACE
, "P2P: GO_NEG_PHASE status set\n");
1565 set_bit(BRCMF_P2P_STATUS_GO_NEG_PHASE
, &p2p
->status
);
1566 config_af_params
->mpc_onoff
= 0;
1567 config_af_params
->search_channel
= true;
1568 p2p
->next_af_subtype
= act_frm
->subtype
+ 1;
1569 p2p
->gon_req_action
= true;
1570 /* increase dwell time to wait for RESP frame */
1571 af_params
->dwell_time
= cpu_to_le32(P2P_AF_MED_DWELL_TIME
);
1573 case P2P_PAF_GON_RSP
:
1574 p2p
->next_af_subtype
= act_frm
->subtype
+ 1;
1575 /* increase dwell time to wait for CONF frame */
1576 af_params
->dwell_time
= cpu_to_le32(P2P_AF_MED_DWELL_TIME
);
1578 case P2P_PAF_GON_CONF
:
1579 /* If we reached till GO Neg confirmation reset the filter */
1580 brcmf_dbg(TRACE
, "P2P: GO_NEG_PHASE status cleared\n");
1581 clear_bit(BRCMF_P2P_STATUS_GO_NEG_PHASE
, &p2p
->status
);
1582 /* turn on mpc again if go nego is done */
1583 config_af_params
->mpc_onoff
= 1;
1584 /* minimize dwell time */
1585 af_params
->dwell_time
= cpu_to_le32(P2P_AF_MIN_DWELL_TIME
);
1586 config_af_params
->extra_listen
= false;
1588 case P2P_PAF_INVITE_REQ
:
1589 config_af_params
->search_channel
= true;
1590 p2p
->next_af_subtype
= act_frm
->subtype
+ 1;
1591 /* increase dwell time */
1592 af_params
->dwell_time
= cpu_to_le32(P2P_AF_MED_DWELL_TIME
);
1594 case P2P_PAF_INVITE_RSP
:
1595 /* minimize dwell time */
1596 af_params
->dwell_time
= cpu_to_le32(P2P_AF_MIN_DWELL_TIME
);
1597 config_af_params
->extra_listen
= false;
1599 case P2P_PAF_DEVDIS_REQ
:
1600 config_af_params
->search_channel
= true;
1601 p2p
->next_af_subtype
= act_frm
->subtype
+ 1;
1602 /* maximize dwell time to wait for RESP frame */
1603 af_params
->dwell_time
= cpu_to_le32(P2P_AF_LONG_DWELL_TIME
);
1605 case P2P_PAF_DEVDIS_RSP
:
1606 /* minimize dwell time */
1607 af_params
->dwell_time
= cpu_to_le32(P2P_AF_MIN_DWELL_TIME
);
1608 config_af_params
->extra_listen
= false;
1610 case P2P_PAF_PROVDIS_REQ
:
1611 ie_len
= le16_to_cpu(action_frame
->len
) -
1612 offsetof(struct brcmf_p2p_pub_act_frame
, elts
);
1613 if (cfg80211_get_p2p_attr(&act_frm
->elts
[0], ie_len
,
1614 IEEE80211_P2P_ATTR_GROUP_ID
,
1616 config_af_params
->search_channel
= true;
1617 config_af_params
->mpc_onoff
= 0;
1618 p2p
->next_af_subtype
= act_frm
->subtype
+ 1;
1619 /* increase dwell time to wait for RESP frame */
1620 af_params
->dwell_time
= cpu_to_le32(P2P_AF_MED_DWELL_TIME
);
1622 case P2P_PAF_PROVDIS_RSP
:
1623 /* wpa_supplicant send go nego req right after prov disc */
1624 p2p
->next_af_subtype
= P2P_PAF_GON_REQ
;
1625 /* increase dwell time to MED level */
1626 af_params
->dwell_time
= cpu_to_le32(P2P_AF_MED_DWELL_TIME
);
1627 config_af_params
->extra_listen
= false;
1630 brcmf_err("Unknown p2p pub act frame subtype: %d\n",
1638 * brcmf_p2p_send_action_frame() - send action frame .
1640 * @cfg: driver private data for cfg80211 interface.
1641 * @ndev: net device to transmit on.
1642 * @af_params: configuration data for action frame.
1644 bool brcmf_p2p_send_action_frame(struct brcmf_cfg80211_info
*cfg
,
1645 struct net_device
*ndev
,
1646 struct brcmf_fil_af_params_le
*af_params
)
1648 struct brcmf_p2p_info
*p2p
= &cfg
->p2p
;
1649 struct brcmf_if
*ifp
= netdev_priv(ndev
);
1650 struct brcmf_fil_action_frame_le
*action_frame
;
1651 struct brcmf_config_af_params config_af_params
;
1652 struct afx_hdl
*afx_hdl
= &p2p
->afx_hdl
;
1653 u16 action_frame_len
;
1658 s32 extra_listen_time
;
1661 action_frame
= &af_params
->action_frame
;
1662 action_frame_len
= le16_to_cpu(action_frame
->len
);
1664 brcmf_p2p_print_actframe(true, action_frame
->data
, action_frame_len
);
1666 /* Add the default dwell time. Dwell time to stay off-channel */
1667 /* to wait for a response action frame after transmitting an */
1668 /* GO Negotiation action frame */
1669 af_params
->dwell_time
= cpu_to_le32(P2P_AF_DWELL_TIME
);
1671 category
= action_frame
->data
[DOT11_ACTION_CAT_OFF
];
1672 action
= action_frame
->data
[DOT11_ACTION_ACT_OFF
];
1674 /* initialize variables */
1675 p2p
->next_af_subtype
= P2P_PAF_SUBTYPE_INVALID
;
1676 p2p
->gon_req_action
= false;
1678 /* config parameters */
1679 config_af_params
.mpc_onoff
= -1;
1680 config_af_params
.search_channel
= false;
1681 config_af_params
.extra_listen
= false;
1683 if (brcmf_p2p_is_pub_action(action_frame
->data
, action_frame_len
)) {
1684 /* p2p public action frame process */
1685 if (brcmf_p2p_pub_af_tx(cfg
, af_params
, &config_af_params
)) {
1686 /* Just send unknown subtype frame with */
1687 /* default parameters. */
1688 brcmf_err("P2P Public action frame, unknown subtype.\n");
1690 } else if (brcmf_p2p_is_gas_action(action_frame
->data
,
1691 action_frame_len
)) {
1692 /* service discovery process */
1693 if (action
== P2PSD_ACTION_ID_GAS_IREQ
||
1694 action
== P2PSD_ACTION_ID_GAS_CREQ
) {
1695 /* configure service discovery query frame */
1696 config_af_params
.search_channel
= true;
1698 /* save next af suptype to cancel */
1699 /* remaining dwell time */
1700 p2p
->next_af_subtype
= action
+ 1;
1702 af_params
->dwell_time
=
1703 cpu_to_le32(P2P_AF_MED_DWELL_TIME
);
1704 } else if (action
== P2PSD_ACTION_ID_GAS_IRESP
||
1705 action
== P2PSD_ACTION_ID_GAS_CRESP
) {
1706 /* configure service discovery response frame */
1707 af_params
->dwell_time
=
1708 cpu_to_le32(P2P_AF_MIN_DWELL_TIME
);
1710 brcmf_err("Unknown action type: %d\n", action
);
1713 } else if (brcmf_p2p_is_p2p_action(action_frame
->data
,
1714 action_frame_len
)) {
1715 /* do not configure anything. it will be */
1716 /* sent with a default configuration */
1718 brcmf_err("Unknown Frame: category 0x%x, action 0x%x\n",
1723 /* if connecting on primary iface, sleep for a while before sending
1726 if (test_bit(BRCMF_VIF_STATUS_CONNECTING
,
1727 &p2p
->bss_idx
[P2PAPI_BSSCFG_PRIMARY
].vif
->sme_state
))
1730 /* if scan is ongoing, abort current scan. */
1731 if (test_bit(BRCMF_SCAN_STATUS_BUSY
, &cfg
->scan_status
))
1732 brcmf_abort_scanning(cfg
);
1734 memcpy(afx_hdl
->tx_dst_addr
, action_frame
->da
, ETH_ALEN
);
1736 /* To make sure to send successfully action frame, turn off mpc */
1737 if (config_af_params
.mpc_onoff
== 0)
1738 brcmf_set_mpc(ifp
, 0);
1740 /* set status and destination address before sending af */
1741 if (p2p
->next_af_subtype
!= P2P_PAF_SUBTYPE_INVALID
) {
1742 /* set status to cancel the remained dwell time in rx process */
1743 set_bit(BRCMF_P2P_STATUS_WAITING_NEXT_ACT_FRAME
, &p2p
->status
);
1746 p2p
->af_sent_channel
= 0;
1747 set_bit(BRCMF_P2P_STATUS_SENDING_ACT_FRAME
, &p2p
->status
);
1748 /* validate channel and p2p ies */
1749 if (config_af_params
.search_channel
&&
1750 IS_P2P_SOCIAL_CHANNEL(le32_to_cpu(af_params
->channel
)) &&
1751 p2p
->bss_idx
[P2PAPI_BSSCFG_DEVICE
].vif
->saved_ie
.probe_req_ie_len
) {
1752 afx_hdl
= &p2p
->afx_hdl
;
1753 afx_hdl
->peer_listen_chan
= le32_to_cpu(af_params
->channel
);
1755 if (brcmf_p2p_af_searching_channel(p2p
) ==
1756 P2P_INVALID_CHANNEL
) {
1757 brcmf_err("Couldn't find peer's channel.\n");
1761 /* Abort scan even for VSDB scenarios. Scan gets aborted in
1762 * firmware but after the check of piggyback algorithm. To take
1763 * care of current piggback algo, lets abort the scan here
1766 brcmf_notify_escan_complete(cfg
, ifp
, true, true);
1768 /* update channel */
1769 af_params
->channel
= cpu_to_le32(afx_hdl
->peer_chan
);
1773 while (!p2p
->block_gon_req_tx
&&
1774 (ack
== false) && (tx_retry
< P2P_AF_TX_MAX_RETRY
)) {
1775 ack
= !brcmf_p2p_tx_action_frame(p2p
, af_params
);
1779 brcmf_err("Failed to send Action Frame(retry %d)\n", tx_retry
);
1780 clear_bit(BRCMF_P2P_STATUS_GO_NEG_PHASE
, &p2p
->status
);
1784 clear_bit(BRCMF_P2P_STATUS_SENDING_ACT_FRAME
, &p2p
->status
);
1786 /* WAR: sometimes dongle does not keep the dwell time of 'actframe'.
1787 * if we coundn't get the next action response frame and dongle does
1788 * not keep the dwell time, go to listen state again to get next action
1791 if (ack
&& config_af_params
.extra_listen
&& !p2p
->block_gon_req_tx
&&
1792 test_bit(BRCMF_P2P_STATUS_WAITING_NEXT_ACT_FRAME
, &p2p
->status
) &&
1793 p2p
->af_sent_channel
== afx_hdl
->my_listen_chan
) {
1794 delta_ms
= jiffies_to_msecs(jiffies
- p2p
->af_tx_sent_jiffies
);
1795 if (le32_to_cpu(af_params
->dwell_time
) > delta_ms
)
1796 extra_listen_time
= le32_to_cpu(af_params
->dwell_time
) -
1799 extra_listen_time
= 0;
1800 if (extra_listen_time
> 50) {
1801 set_bit(BRCMF_P2P_STATUS_WAITING_NEXT_AF_LISTEN
,
1803 brcmf_dbg(INFO
, "Wait more time! actual af time:%d, calculated extra listen:%d\n",
1804 le32_to_cpu(af_params
->dwell_time
),
1806 extra_listen_time
+= 100;
1807 if (!brcmf_p2p_discover_listen(p2p
,
1808 p2p
->af_sent_channel
,
1809 extra_listen_time
)) {
1810 unsigned long duration
;
1812 extra_listen_time
+= 100;
1813 duration
= msecs_to_jiffies(extra_listen_time
);
1814 wait_for_completion_timeout(&p2p
->wait_next_af
,
1817 clear_bit(BRCMF_P2P_STATUS_WAITING_NEXT_AF_LISTEN
,
1822 if (p2p
->block_gon_req_tx
) {
1823 /* if ack is true, supplicant will wait more time(100ms).
1824 * so we will return it as a success to get more time .
1826 p2p
->block_gon_req_tx
= false;
1830 clear_bit(BRCMF_P2P_STATUS_WAITING_NEXT_ACT_FRAME
, &p2p
->status
);
1831 /* if all done, turn mpc on again */
1832 if (config_af_params
.mpc_onoff
== 1)
1833 brcmf_set_mpc(ifp
, 1);
1839 * brcmf_p2p_notify_rx_mgmt_p2p_probereq() - Event handler for p2p probe req.
1841 * @ifp: interface pointer for which event was received.
1843 * @data: payload of event message (probe request).
1845 s32
brcmf_p2p_notify_rx_mgmt_p2p_probereq(struct brcmf_if
*ifp
,
1846 const struct brcmf_event_msg
*e
,
1849 struct brcmf_cfg80211_info
*cfg
= ifp
->drvr
->config
;
1850 struct brcmf_p2p_info
*p2p
= &cfg
->p2p
;
1851 struct afx_hdl
*afx_hdl
= &p2p
->afx_hdl
;
1852 struct brcmf_cfg80211_vif
*vif
= ifp
->vif
;
1853 struct brcmf_rx_mgmt_data
*rxframe
= (struct brcmf_rx_mgmt_data
*)data
;
1854 u16 chanspec
= be16_to_cpu(rxframe
->chanspec
);
1855 struct brcmu_chan ch
;
1861 brcmf_dbg(INFO
, "Enter: event %d reason %d\n", e
->event_code
,
1864 ch
.chspec
= be16_to_cpu(rxframe
->chanspec
);
1865 cfg
->d11inf
.decchspec(&ch
);
1867 if (test_bit(BRCMF_P2P_STATUS_FINDING_COMMON_CHANNEL
, &p2p
->status
) &&
1868 (memcmp(afx_hdl
->tx_dst_addr
, e
->addr
, ETH_ALEN
) == 0)) {
1869 afx_hdl
->peer_chan
= ch
.chnum
;
1870 brcmf_dbg(INFO
, "PROBE REQUEST: Peer found, channel=%d\n",
1871 afx_hdl
->peer_chan
);
1872 complete(&afx_hdl
->act_frm_scan
);
1875 /* Firmware sends us two proberesponses for each idx one. At the */
1876 /* moment anything but bsscfgidx 0 is passed up to supplicant */
1877 if (e
->bsscfgidx
== 0)
1880 /* Filter any P2P probe reqs arriving during the GO-NEG Phase */
1881 if (test_bit(BRCMF_P2P_STATUS_GO_NEG_PHASE
, &p2p
->status
)) {
1882 brcmf_dbg(INFO
, "Filtering P2P probe_req in GO-NEG phase\n");
1886 /* Check if wpa_supplicant has registered for this frame */
1887 brcmf_dbg(INFO
, "vif->mgmt_rx_reg %04x\n", vif
->mgmt_rx_reg
);
1888 mgmt_type
= (IEEE80211_STYPE_PROBE_REQ
& IEEE80211_FCTL_STYPE
) >> 4;
1889 if ((vif
->mgmt_rx_reg
& BIT(mgmt_type
)) == 0)
1892 mgmt_frame
= (u8
*)(rxframe
+ 1);
1893 mgmt_frame_len
= e
->datalen
- sizeof(*rxframe
);
1894 freq
= ieee80211_channel_to_frequency(ch
.chnum
,
1895 ch
.band
== BRCMU_CHAN_BAND_2G
?
1896 IEEE80211_BAND_2GHZ
:
1897 IEEE80211_BAND_5GHZ
);
1899 cfg80211_rx_mgmt(&vif
->wdev
, freq
, 0, mgmt_frame
, mgmt_frame_len
, 0,
1902 brcmf_dbg(INFO
, "mgmt_frame_len (%d) , e->datalen (%d), chanspec (%04x), freq (%d)\n",
1903 mgmt_frame_len
, e
->datalen
, chanspec
, freq
);
1910 * brcmf_p2p_attach() - attach for P2P.
1912 * @cfg: driver private data for cfg80211 interface.
1914 s32
brcmf_p2p_attach(struct brcmf_cfg80211_info
*cfg
)
1916 struct brcmf_if
*pri_ifp
;
1917 struct brcmf_if
*p2p_ifp
;
1918 struct brcmf_cfg80211_vif
*p2p_vif
;
1919 struct brcmf_p2p_info
*p2p
;
1920 struct brcmf_pub
*drvr
;
1929 pri_ifp
= drvr
->iflist
[0];
1930 p2p_ifp
= drvr
->iflist
[1];
1932 p2p
->bss_idx
[P2PAPI_BSSCFG_PRIMARY
].vif
= pri_ifp
->vif
;
1935 p2p_vif
= brcmf_alloc_vif(cfg
, NL80211_IFTYPE_P2P_DEVICE
,
1937 if (IS_ERR(p2p_vif
)) {
1938 brcmf_err("could not create discovery vif\n");
1943 p2p_vif
->ifp
= p2p_ifp
;
1944 p2p_ifp
->vif
= p2p_vif
;
1945 p2p_vif
->wdev
.netdev
= p2p_ifp
->ndev
;
1946 p2p_ifp
->ndev
->ieee80211_ptr
= &p2p_vif
->wdev
;
1947 SET_NETDEV_DEV(p2p_ifp
->ndev
, wiphy_dev(cfg
->wiphy
));
1949 p2p
->bss_idx
[P2PAPI_BSSCFG_DEVICE
].vif
= p2p_vif
;
1951 brcmf_p2p_generate_bss_mac(p2p
, NULL
);
1952 memcpy(p2p_ifp
->mac_addr
, p2p
->dev_addr
, ETH_ALEN
);
1953 brcmf_p2p_set_firmware(pri_ifp
, p2p
->dev_addr
);
1955 /* Initialize P2P Discovery in the firmware */
1956 err
= brcmf_fil_iovar_int_set(pri_ifp
, "p2p_disc", 1);
1958 brcmf_err("set p2p_disc error\n");
1959 brcmf_free_vif(cfg
, p2p_vif
);
1962 /* obtain bsscfg index for P2P discovery */
1963 err
= brcmf_fil_iovar_int_get(pri_ifp
, "p2p_dev", &bssidx
);
1965 brcmf_err("retrieving discover bsscfg index failed\n");
1966 brcmf_free_vif(cfg
, p2p_vif
);
1969 /* Verify that firmware uses same bssidx as driver !! */
1970 if (p2p_ifp
->bssidx
!= bssidx
) {
1971 brcmf_err("Incorrect bssidx=%d, compared to p2p_ifp->bssidx=%d\n",
1972 bssidx
, p2p_ifp
->bssidx
);
1973 brcmf_free_vif(cfg
, p2p_vif
);
1977 init_completion(&p2p
->send_af_done
);
1978 INIT_WORK(&p2p
->afx_hdl
.afx_work
, brcmf_p2p_afx_handler
);
1979 init_completion(&p2p
->afx_hdl
.act_frm_scan
);
1980 init_completion(&p2p
->wait_next_af
);
1988 * brcmf_p2p_detach() - detach P2P.
1990 * @p2p: P2P specific data.
1992 void brcmf_p2p_detach(struct brcmf_p2p_info
*p2p
)
1994 struct brcmf_cfg80211_vif
*vif
;
1996 vif
= p2p
->bss_idx
[P2PAPI_BSSCFG_DEVICE
].vif
;
1998 brcmf_p2p_cancel_remain_on_channel(vif
->ifp
);
1999 brcmf_p2p_deinit_discovery(p2p
);
2000 /* remove discovery interface */
2001 brcmf_free_vif(p2p
->cfg
, vif
);
2002 p2p
->bss_idx
[P2PAPI_BSSCFG_DEVICE
].vif
= NULL
;
2004 /* just set it all to zero */
2005 memset(p2p
, 0, sizeof(*p2p
));
2009 * brcmf_p2p_get_current_chanspec() - Get current operation channel.
2011 * @p2p: P2P specific data.
2012 * @chanspec: chanspec to be returned.
2014 static void brcmf_p2p_get_current_chanspec(struct brcmf_p2p_info
*p2p
,
2017 struct brcmf_if
*ifp
;
2018 u8 mac_addr
[ETH_ALEN
];
2019 struct brcmu_chan ch
;
2020 struct brcmf_bss_info_le
*bi
;
2023 ifp
= p2p
->bss_idx
[P2PAPI_BSSCFG_PRIMARY
].vif
->ifp
;
2025 if (brcmf_fil_cmd_data_get(ifp
, BRCMF_C_GET_BSSID
, mac_addr
,
2027 buf
= kzalloc(WL_BSS_INFO_MAX
, GFP_KERNEL
);
2029 *(__le32
*)buf
= cpu_to_le32(WL_BSS_INFO_MAX
);
2030 if (brcmf_fil_cmd_data_get(ifp
, BRCMF_C_GET_BSS_INFO
,
2031 buf
, WL_BSS_INFO_MAX
) == 0) {
2032 bi
= (struct brcmf_bss_info_le
*)(buf
+ 4);
2033 *chanspec
= le16_to_cpu(bi
->chanspec
);
2040 /* Use default channel for P2P */
2041 ch
.chnum
= BRCMF_P2P_TEMP_CHAN
;
2042 ch
.bw
= BRCMU_CHAN_BW_20
;
2043 p2p
->cfg
->d11inf
.encchspec(&ch
);
2044 *chanspec
= ch
.chspec
;
2048 * Change a P2P Role.
2050 * @mac: MAC address of the BSS to change a role
2051 * Returns 0 if success.
2053 int brcmf_p2p_ifchange(struct brcmf_cfg80211_info
*cfg
,
2054 enum brcmf_fil_p2p_if_types if_type
)
2056 struct brcmf_p2p_info
*p2p
= &cfg
->p2p
;
2057 struct brcmf_cfg80211_vif
*vif
;
2058 struct brcmf_fil_p2p_if_le if_request
;
2062 brcmf_dbg(TRACE
, "Enter\n");
2064 vif
= p2p
->bss_idx
[P2PAPI_BSSCFG_PRIMARY
].vif
;
2066 brcmf_err("vif for P2PAPI_BSSCFG_PRIMARY does not exist\n");
2069 brcmf_notify_escan_complete(cfg
, vif
->ifp
, true, true);
2070 vif
= p2p
->bss_idx
[P2PAPI_BSSCFG_CONNECTION
].vif
;
2072 brcmf_err("vif for P2PAPI_BSSCFG_CONNECTION does not exist\n");
2075 brcmf_set_mpc(vif
->ifp
, 0);
2077 /* In concurrency case, STA may be already associated in a particular */
2078 /* channel. so retrieve the current channel of primary interface and */
2079 /* then start the virtual interface on that. */
2080 brcmf_p2p_get_current_chanspec(p2p
, &chanspec
);
2082 if_request
.type
= cpu_to_le16((u16
)if_type
);
2083 if_request
.chspec
= cpu_to_le16(chanspec
);
2084 memcpy(if_request
.addr
, p2p
->int_addr
, sizeof(if_request
.addr
));
2086 brcmf_cfg80211_arm_vif_event(cfg
, vif
);
2087 err
= brcmf_fil_iovar_data_set(vif
->ifp
, "p2p_ifupd", &if_request
,
2088 sizeof(if_request
));
2090 brcmf_err("p2p_ifupd FAILED, err=%d\n", err
);
2091 brcmf_cfg80211_arm_vif_event(cfg
, NULL
);
2094 err
= brcmf_cfg80211_wait_vif_event_timeout(cfg
, BRCMF_E_IF_CHANGE
,
2095 msecs_to_jiffies(1500));
2096 brcmf_cfg80211_arm_vif_event(cfg
, NULL
);
2098 brcmf_err("No BRCMF_E_IF_CHANGE event received\n");
2102 err
= brcmf_fil_cmd_int_set(vif
->ifp
, BRCMF_C_SET_SCB_TIMEOUT
,
2103 BRCMF_SCB_TIMEOUT_VALUE
);
2108 static int brcmf_p2p_request_p2p_if(struct brcmf_p2p_info
*p2p
,
2109 struct brcmf_if
*ifp
, u8 ea
[ETH_ALEN
],
2110 enum brcmf_fil_p2p_if_types iftype
)
2112 struct brcmf_fil_p2p_if_le if_request
;
2116 /* we need a default channel */
2117 brcmf_p2p_get_current_chanspec(p2p
, &chanspec
);
2119 /* fill the firmware request */
2120 memcpy(if_request
.addr
, ea
, ETH_ALEN
);
2121 if_request
.type
= cpu_to_le16((u16
)iftype
);
2122 if_request
.chspec
= cpu_to_le16(chanspec
);
2124 err
= brcmf_fil_iovar_data_set(ifp
, "p2p_ifadd", &if_request
,
2125 sizeof(if_request
));
2132 static int brcmf_p2p_disable_p2p_if(struct brcmf_cfg80211_vif
*vif
)
2134 struct brcmf_cfg80211_info
*cfg
= wdev_to_cfg(&vif
->wdev
);
2135 struct net_device
*pri_ndev
= cfg_to_ndev(cfg
);
2136 struct brcmf_if
*ifp
= netdev_priv(pri_ndev
);
2137 u8
*addr
= vif
->wdev
.netdev
->dev_addr
;
2139 return brcmf_fil_iovar_data_set(ifp
, "p2p_ifdis", addr
, ETH_ALEN
);
2142 static int brcmf_p2p_release_p2p_if(struct brcmf_cfg80211_vif
*vif
)
2144 struct brcmf_cfg80211_info
*cfg
= wdev_to_cfg(&vif
->wdev
);
2145 struct net_device
*pri_ndev
= cfg_to_ndev(cfg
);
2146 struct brcmf_if
*ifp
= netdev_priv(pri_ndev
);
2147 u8
*addr
= vif
->wdev
.netdev
->dev_addr
;
2149 return brcmf_fil_iovar_data_set(ifp
, "p2p_ifdel", addr
, ETH_ALEN
);
2153 * brcmf_p2p_create_p2pdev() - create a P2P_DEVICE virtual interface.
2155 * @p2p: P2P specific data.
2156 * @wiphy: wiphy device of new interface.
2157 * @addr: mac address for this new interface.
2159 static struct wireless_dev
*brcmf_p2p_create_p2pdev(struct brcmf_p2p_info
*p2p
,
2160 struct wiphy
*wiphy
,
2163 struct brcmf_cfg80211_vif
*p2p_vif
;
2164 struct brcmf_if
*p2p_ifp
;
2165 struct brcmf_if
*pri_ifp
;
2169 if (p2p
->bss_idx
[P2PAPI_BSSCFG_DEVICE
].vif
)
2170 return ERR_PTR(-ENOSPC
);
2172 p2p_vif
= brcmf_alloc_vif(p2p
->cfg
, NL80211_IFTYPE_P2P_DEVICE
,
2174 if (IS_ERR(p2p_vif
)) {
2175 brcmf_err("could not create discovery vif\n");
2176 return (struct wireless_dev
*)p2p_vif
;
2179 pri_ifp
= p2p
->bss_idx
[P2PAPI_BSSCFG_PRIMARY
].vif
->ifp
;
2180 brcmf_p2p_generate_bss_mac(p2p
, addr
);
2181 brcmf_p2p_set_firmware(pri_ifp
, p2p
->dev_addr
);
2183 brcmf_cfg80211_arm_vif_event(p2p
->cfg
, p2p_vif
);
2185 /* Initialize P2P Discovery in the firmware */
2186 err
= brcmf_fil_iovar_int_set(pri_ifp
, "p2p_disc", 1);
2188 brcmf_err("set p2p_disc error\n");
2189 brcmf_cfg80211_arm_vif_event(p2p
->cfg
, NULL
);
2193 /* wait for firmware event */
2194 err
= brcmf_cfg80211_wait_vif_event_timeout(p2p
->cfg
, BRCMF_E_IF_ADD
,
2195 msecs_to_jiffies(1500));
2196 brcmf_cfg80211_arm_vif_event(p2p
->cfg
, NULL
);
2198 brcmf_err("timeout occurred\n");
2203 /* discovery interface created */
2204 p2p_ifp
= p2p_vif
->ifp
;
2205 p2p
->bss_idx
[P2PAPI_BSSCFG_DEVICE
].vif
= p2p_vif
;
2206 memcpy(p2p_ifp
->mac_addr
, p2p
->dev_addr
, ETH_ALEN
);
2207 memcpy(&p2p_vif
->wdev
.address
, p2p
->dev_addr
, sizeof(p2p
->dev_addr
));
2209 /* verify bsscfg index for P2P discovery */
2210 err
= brcmf_fil_iovar_int_get(pri_ifp
, "p2p_dev", &bssidx
);
2212 brcmf_err("retrieving discover bsscfg index failed\n");
2216 WARN_ON(p2p_ifp
->bssidx
!= bssidx
);
2218 init_completion(&p2p
->send_af_done
);
2219 INIT_WORK(&p2p
->afx_hdl
.afx_work
, brcmf_p2p_afx_handler
);
2220 init_completion(&p2p
->afx_hdl
.act_frm_scan
);
2221 init_completion(&p2p
->wait_next_af
);
2223 return &p2p_vif
->wdev
;
2226 brcmf_free_vif(p2p
->cfg
, p2p_vif
);
2227 return ERR_PTR(err
);
2231 * brcmf_p2p_delete_p2pdev() - delete P2P_DEVICE virtual interface.
2233 * @vif: virtual interface object to delete.
2235 static void brcmf_p2p_delete_p2pdev(struct brcmf_cfg80211_info
*cfg
,
2236 struct brcmf_cfg80211_vif
*vif
)
2238 cfg80211_unregister_wdev(&vif
->wdev
);
2239 cfg
->p2p
.bss_idx
[P2PAPI_BSSCFG_DEVICE
].vif
= NULL
;
2240 brcmf_free_vif(cfg
, vif
);
2244 * brcmf_p2p_free_p2p_if() - free up net device related data.
2246 * @ndev: net device that needs to be freed.
2248 static void brcmf_p2p_free_p2p_if(struct net_device
*ndev
)
2250 struct brcmf_cfg80211_info
*cfg
;
2251 struct brcmf_cfg80211_vif
*vif
;
2252 struct brcmf_if
*ifp
;
2254 ifp
= netdev_priv(ndev
);
2255 cfg
= ifp
->drvr
->config
;
2258 brcmf_free_vif(cfg
, vif
);
2259 free_netdev(ifp
->ndev
);
2263 * brcmf_p2p_add_vif() - create a new P2P virtual interface.
2265 * @wiphy: wiphy device of new interface.
2266 * @name: name of the new interface.
2267 * @type: nl80211 interface type.
2269 * @params: contains mac address for P2P device.
2271 struct wireless_dev
*brcmf_p2p_add_vif(struct wiphy
*wiphy
, const char *name
,
2272 enum nl80211_iftype type
, u32
*flags
,
2273 struct vif_params
*params
)
2275 struct brcmf_cfg80211_info
*cfg
= wiphy_to_cfg(wiphy
);
2276 struct brcmf_if
*ifp
= netdev_priv(cfg_to_ndev(cfg
));
2277 struct brcmf_cfg80211_vif
*vif
;
2278 enum brcmf_fil_p2p_if_types iftype
;
2282 if (brcmf_cfg80211_vif_event_armed(cfg
))
2283 return ERR_PTR(-EBUSY
);
2285 brcmf_dbg(INFO
, "adding vif \"%s\" (type=%d)\n", name
, type
);
2288 case NL80211_IFTYPE_P2P_CLIENT
:
2289 iftype
= BRCMF_FIL_P2P_IF_CLIENT
;
2292 case NL80211_IFTYPE_P2P_GO
:
2293 iftype
= BRCMF_FIL_P2P_IF_GO
;
2296 case NL80211_IFTYPE_P2P_DEVICE
:
2297 return brcmf_p2p_create_p2pdev(&cfg
->p2p
, wiphy
,
2300 return ERR_PTR(-EOPNOTSUPP
);
2303 vif
= brcmf_alloc_vif(cfg
, type
, false);
2305 return (struct wireless_dev
*)vif
;
2306 brcmf_cfg80211_arm_vif_event(cfg
, vif
);
2308 err
= brcmf_p2p_request_p2p_if(&cfg
->p2p
, ifp
, cfg
->p2p
.int_addr
,
2311 brcmf_cfg80211_arm_vif_event(cfg
, NULL
);
2315 /* wait for firmware event */
2316 err
= brcmf_cfg80211_wait_vif_event_timeout(cfg
, BRCMF_E_IF_ADD
,
2317 msecs_to_jiffies(1500));
2318 brcmf_cfg80211_arm_vif_event(cfg
, NULL
);
2320 brcmf_err("timeout occurred\n");
2325 /* interface created in firmware */
2328 brcmf_err("no if pointer provided\n");
2333 strncpy(ifp
->ndev
->name
, name
, sizeof(ifp
->ndev
->name
) - 1);
2334 err
= brcmf_net_attach(ifp
, true);
2336 brcmf_err("Registering netdevice failed\n");
2339 /* override destructor */
2340 ifp
->ndev
->destructor
= brcmf_p2p_free_p2p_if
;
2342 cfg
->p2p
.bss_idx
[P2PAPI_BSSCFG_CONNECTION
].vif
= vif
;
2343 /* Disable firmware roaming for P2P interface */
2344 brcmf_fil_iovar_int_set(ifp
, "roam_off", 1);
2345 if (iftype
== BRCMF_FIL_P2P_IF_GO
) {
2346 /* set station timeout for p2p */
2347 brcmf_fil_cmd_int_set(ifp
, BRCMF_C_SET_SCB_TIMEOUT
,
2348 BRCMF_SCB_TIMEOUT_VALUE
);
2350 return &ifp
->vif
->wdev
;
2353 brcmf_free_vif(cfg
, vif
);
2354 return ERR_PTR(err
);
2358 * brcmf_p2p_del_vif() - delete a P2P virtual interface.
2360 * @wiphy: wiphy device of interface.
2361 * @wdev: wireless device of interface.
2363 * TODO: not yet supported.
2365 int brcmf_p2p_del_vif(struct wiphy
*wiphy
, struct wireless_dev
*wdev
)
2367 struct brcmf_cfg80211_info
*cfg
= wiphy_priv(wiphy
);
2368 struct brcmf_p2p_info
*p2p
= &cfg
->p2p
;
2369 struct brcmf_cfg80211_vif
*vif
;
2370 unsigned long jiffie_timeout
= msecs_to_jiffies(1500);
2371 bool wait_for_disable
= false;
2374 brcmf_dbg(TRACE
, "delete P2P vif\n");
2375 vif
= container_of(wdev
, struct brcmf_cfg80211_vif
, wdev
);
2377 switch (vif
->wdev
.iftype
) {
2378 case NL80211_IFTYPE_P2P_CLIENT
:
2379 if (test_bit(BRCMF_VIF_STATUS_DISCONNECTING
, &vif
->sme_state
))
2380 wait_for_disable
= true;
2383 case NL80211_IFTYPE_P2P_GO
:
2384 if (!brcmf_p2p_disable_p2p_if(vif
))
2385 wait_for_disable
= true;
2388 case NL80211_IFTYPE_P2P_DEVICE
:
2389 brcmf_p2p_delete_p2pdev(cfg
, vif
);
2396 clear_bit(BRCMF_P2P_STATUS_GO_NEG_PHASE
, &p2p
->status
);
2397 brcmf_dbg(INFO
, "P2P: GO_NEG_PHASE status cleared\n");
2399 if (wait_for_disable
)
2400 wait_for_completion_timeout(&cfg
->vif_disabled
,
2401 msecs_to_jiffies(500));
2403 brcmf_vif_clear_mgmt_ies(vif
);
2405 brcmf_cfg80211_arm_vif_event(cfg
, vif
);
2406 err
= brcmf_p2p_release_p2p_if(vif
);
2408 /* wait for firmware event */
2409 err
= brcmf_cfg80211_wait_vif_event_timeout(cfg
, BRCMF_E_IF_DEL
,
2416 brcmf_cfg80211_arm_vif_event(cfg
, NULL
);
2417 p2p
->bss_idx
[P2PAPI_BSSCFG_CONNECTION
].vif
= NULL
;
2422 int brcmf_p2p_start_device(struct wiphy
*wiphy
, struct wireless_dev
*wdev
)
2424 struct brcmf_cfg80211_info
*cfg
= wiphy_to_cfg(wiphy
);
2425 struct brcmf_p2p_info
*p2p
= &cfg
->p2p
;
2426 struct brcmf_cfg80211_vif
*vif
;
2429 vif
= container_of(wdev
, struct brcmf_cfg80211_vif
, wdev
);
2430 mutex_lock(&cfg
->usr_sync
);
2431 err
= brcmf_p2p_enable_discovery(p2p
);
2433 set_bit(BRCMF_VIF_STATUS_READY
, &vif
->sme_state
);
2434 mutex_unlock(&cfg
->usr_sync
);
2438 void brcmf_p2p_stop_device(struct wiphy
*wiphy
, struct wireless_dev
*wdev
)
2440 struct brcmf_cfg80211_info
*cfg
= wiphy_to_cfg(wiphy
);
2441 struct brcmf_p2p_info
*p2p
= &cfg
->p2p
;
2442 struct brcmf_cfg80211_vif
*vif
;
2444 vif
= container_of(wdev
, struct brcmf_cfg80211_vif
, wdev
);
2445 mutex_lock(&cfg
->usr_sync
);
2446 (void)brcmf_p2p_deinit_discovery(p2p
);
2447 brcmf_abort_scanning(cfg
);
2448 clear_bit(BRCMF_VIF_STATUS_READY
, &vif
->sme_state
);
2449 mutex_unlock(&cfg
->usr_sync
);