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 <linux/rtnetlink.h>
20 #include <net/cfg80211.h>
22 #include <brcmu_wifi.h>
23 #include <brcmu_utils.h>
28 #include "fwil_types.h"
32 /* parameters used for p2p escan */
33 #define P2PAPI_SCAN_NPROBES 1
34 #define P2PAPI_SCAN_DWELL_TIME_MS 80
35 #define P2PAPI_SCAN_SOCIAL_DWELL_TIME_MS 40
36 #define P2PAPI_SCAN_HOME_TIME_MS 60
37 #define P2PAPI_SCAN_NPROBS_TIME_MS 30
38 #define P2PAPI_SCAN_AF_SEARCH_DWELL_TIME_MS 100
39 #define WL_SCAN_CONNECT_DWELL_TIME_MS 200
40 #define WL_SCAN_JOIN_PROBE_INTERVAL_MS 20
42 #define BRCMF_P2P_WILDCARD_SSID "DIRECT-"
43 #define BRCMF_P2P_WILDCARD_SSID_LEN (sizeof(BRCMF_P2P_WILDCARD_SSID) - 1)
45 #define SOCIAL_CHAN_1 1
46 #define SOCIAL_CHAN_2 6
47 #define SOCIAL_CHAN_3 11
48 #define IS_P2P_SOCIAL_CHANNEL(channel) ((channel == SOCIAL_CHAN_1) || \
49 (channel == SOCIAL_CHAN_2) || \
50 (channel == SOCIAL_CHAN_3))
51 #define BRCMF_P2P_TEMP_CHAN SOCIAL_CHAN_3
52 #define SOCIAL_CHAN_CNT 3
53 #define AF_PEER_SEARCH_CNT 2
55 #define BRCMF_SCB_TIMEOUT_VALUE 20
57 #define P2P_VER 9 /* P2P version: 9=WiFi P2P v1.0 */
58 #define P2P_PUB_AF_CATEGORY 0x04
59 #define P2P_PUB_AF_ACTION 0x09
60 #define P2P_AF_CATEGORY 0x7f
61 #define P2P_OUI "\x50\x6F\x9A" /* P2P OUI */
62 #define P2P_OUI_LEN 3 /* P2P OUI length */
64 /* Action Frame Constants */
65 #define DOT11_ACTION_HDR_LEN 2 /* action frame category + action */
66 #define DOT11_ACTION_CAT_OFF 0 /* category offset */
67 #define DOT11_ACTION_ACT_OFF 1 /* action offset */
69 #define P2P_AF_DWELL_TIME 200
70 #define P2P_AF_MIN_DWELL_TIME 100
71 #define P2P_AF_MED_DWELL_TIME 400
72 #define P2P_AF_LONG_DWELL_TIME 1000
73 #define P2P_AF_TX_MAX_RETRY 1
74 #define P2P_AF_MAX_WAIT_TIME msecs_to_jiffies(2000)
75 #define P2P_INVALID_CHANNEL -1
76 #define P2P_CHANNEL_SYNC_RETRY 5
77 #define P2P_AF_FRM_SCAN_MAX_WAIT msecs_to_jiffies(450)
78 #define P2P_DEFAULT_SLEEP_TIME_VSDB 200
80 /* WiFi P2P Public Action Frame OUI Subtypes */
81 #define P2P_PAF_GON_REQ 0 /* Group Owner Negotiation Req */
82 #define P2P_PAF_GON_RSP 1 /* Group Owner Negotiation Rsp */
83 #define P2P_PAF_GON_CONF 2 /* Group Owner Negotiation Confirm */
84 #define P2P_PAF_INVITE_REQ 3 /* P2P Invitation Request */
85 #define P2P_PAF_INVITE_RSP 4 /* P2P Invitation Response */
86 #define P2P_PAF_DEVDIS_REQ 5 /* Device Discoverability Request */
87 #define P2P_PAF_DEVDIS_RSP 6 /* Device Discoverability Response */
88 #define P2P_PAF_PROVDIS_REQ 7 /* Provision Discovery Request */
89 #define P2P_PAF_PROVDIS_RSP 8 /* Provision Discovery Response */
90 #define P2P_PAF_SUBTYPE_INVALID 255 /* Invalid Subtype */
92 /* WiFi P2P Action Frame OUI Subtypes */
93 #define P2P_AF_NOTICE_OF_ABSENCE 0 /* Notice of Absence */
94 #define P2P_AF_PRESENCE_REQ 1 /* P2P Presence Request */
95 #define P2P_AF_PRESENCE_RSP 2 /* P2P Presence Response */
96 #define P2P_AF_GO_DISC_REQ 3 /* GO Discoverability Request */
98 /* P2P Service Discovery related */
99 #define P2PSD_ACTION_CATEGORY 0x04 /* Public action frame */
100 #define P2PSD_ACTION_ID_GAS_IREQ 0x0a /* GAS Initial Request AF */
101 #define P2PSD_ACTION_ID_GAS_IRESP 0x0b /* GAS Initial Response AF */
102 #define P2PSD_ACTION_ID_GAS_CREQ 0x0c /* GAS Comback Request AF */
103 #define P2PSD_ACTION_ID_GAS_CRESP 0x0d /* GAS Comback Response AF */
105 #define BRCMF_P2P_DISABLE_TIMEOUT msecs_to_jiffies(500)
107 * struct brcmf_p2p_disc_st_le - set discovery state in firmware.
109 * @state: requested discovery state (see enum brcmf_p2p_disc_state).
110 * @chspec: channel parameter for %WL_P2P_DISC_ST_LISTEN state.
111 * @dwell: dwell time in ms for %WL_P2P_DISC_ST_LISTEN state.
113 struct brcmf_p2p_disc_st_le
{
120 * enum brcmf_p2p_disc_state - P2P discovery state values
122 * @WL_P2P_DISC_ST_SCAN: P2P discovery with wildcard SSID and P2P IE.
123 * @WL_P2P_DISC_ST_LISTEN: P2P discovery off-channel for specified time.
124 * @WL_P2P_DISC_ST_SEARCH: P2P discovery with P2P wildcard SSID and P2P IE.
126 enum brcmf_p2p_disc_state
{
128 WL_P2P_DISC_ST_LISTEN
,
129 WL_P2P_DISC_ST_SEARCH
133 * struct brcmf_p2p_scan_le - P2P specific scan request.
135 * @type: type of scan method requested (values: 'E' or 'S').
136 * @reserved: reserved (ignored).
137 * @eparams: parameters used for type 'E'.
138 * @sparams: parameters used for type 'S'.
140 struct brcmf_p2p_scan_le
{
144 struct brcmf_escan_params_le eparams
;
145 struct brcmf_scan_params_le sparams
;
150 * struct brcmf_p2p_pub_act_frame - WiFi P2P Public Action Frame
152 * @category: P2P_PUB_AF_CATEGORY
153 * @action: P2P_PUB_AF_ACTION
155 * @oui_type: OUI type - P2P_VER
156 * @subtype: OUI subtype - P2P_TYPE_*
157 * @dialog_token: nonzero, identifies req/rsp transaction
158 * @elts[1]: Variable length information elements.
160 struct brcmf_p2p_pub_act_frame
{
171 * struct brcmf_p2p_action_frame - WiFi P2P Action Frame
173 * @category: P2P_AF_CATEGORY
174 * @OUI[3]: OUI - P2P_OUI
175 * @type: OUI Type - P2P_VER
176 * @subtype: OUI Subtype - P2P_AF_*
177 * @dialog_token: nonzero, identifies req/resp tranaction
178 * @elts[1]: Variable length information elements.
180 struct brcmf_p2p_action_frame
{
190 * struct brcmf_p2psd_gas_pub_act_frame - Wi-Fi GAS Public Action Frame
192 * @category: 0x04 Public Action Frame
193 * @action: 0x6c Advertisement Protocol
194 * @dialog_token: nonzero, identifies req/rsp transaction
195 * @query_data[1]: Query Data. SD gas ireq SD gas iresp
197 struct brcmf_p2psd_gas_pub_act_frame
{
205 * struct brcmf_config_af_params - Action Frame Parameters for tx.
207 * @mpc_onoff: To make sure to send successfully action frame, we have to
208 * turn off mpc 0: off, 1: on, (-1): do nothing
209 * @search_channel: 1: search peer's channel to send af
210 * extra_listen: keep the dwell time to get af response frame.
212 struct brcmf_config_af_params
{
219 * brcmf_p2p_is_pub_action() - true if p2p public type frame.
221 * @frame: action frame data.
222 * @frame_len: length of action frame data.
224 * Determine if action frame is p2p public action type
226 static bool brcmf_p2p_is_pub_action(void *frame
, u32 frame_len
)
228 struct brcmf_p2p_pub_act_frame
*pact_frm
;
233 pact_frm
= (struct brcmf_p2p_pub_act_frame
*)frame
;
234 if (frame_len
< sizeof(struct brcmf_p2p_pub_act_frame
) - 1)
237 if (pact_frm
->category
== P2P_PUB_AF_CATEGORY
&&
238 pact_frm
->action
== P2P_PUB_AF_ACTION
&&
239 pact_frm
->oui_type
== P2P_VER
&&
240 memcmp(pact_frm
->oui
, P2P_OUI
, P2P_OUI_LEN
) == 0)
247 * brcmf_p2p_is_p2p_action() - true if p2p action type frame.
249 * @frame: action frame data.
250 * @frame_len: length of action frame data.
252 * Determine if action frame is p2p action type
254 static bool brcmf_p2p_is_p2p_action(void *frame
, u32 frame_len
)
256 struct brcmf_p2p_action_frame
*act_frm
;
261 act_frm
= (struct brcmf_p2p_action_frame
*)frame
;
262 if (frame_len
< sizeof(struct brcmf_p2p_action_frame
) - 1)
265 if (act_frm
->category
== P2P_AF_CATEGORY
&&
266 act_frm
->type
== P2P_VER
&&
267 memcmp(act_frm
->oui
, P2P_OUI
, P2P_OUI_LEN
) == 0)
274 * brcmf_p2p_is_gas_action() - true if p2p gas action type frame.
276 * @frame: action frame data.
277 * @frame_len: length of action frame data.
279 * Determine if action frame is p2p gas action type
281 static bool brcmf_p2p_is_gas_action(void *frame
, u32 frame_len
)
283 struct brcmf_p2psd_gas_pub_act_frame
*sd_act_frm
;
288 sd_act_frm
= (struct brcmf_p2psd_gas_pub_act_frame
*)frame
;
289 if (frame_len
< sizeof(struct brcmf_p2psd_gas_pub_act_frame
) - 1)
292 if (sd_act_frm
->category
!= P2PSD_ACTION_CATEGORY
)
295 if (sd_act_frm
->action
== P2PSD_ACTION_ID_GAS_IREQ
||
296 sd_act_frm
->action
== P2PSD_ACTION_ID_GAS_IRESP
||
297 sd_act_frm
->action
== P2PSD_ACTION_ID_GAS_CREQ
||
298 sd_act_frm
->action
== P2PSD_ACTION_ID_GAS_CRESP
)
305 * brcmf_p2p_print_actframe() - debug print routine.
307 * @tx: Received or to be transmitted
308 * @frame: action frame data.
309 * @frame_len: length of action frame data.
311 * Print information about the p2p action frame
316 static void brcmf_p2p_print_actframe(bool tx
, void *frame
, u32 frame_len
)
318 struct brcmf_p2p_pub_act_frame
*pact_frm
;
319 struct brcmf_p2p_action_frame
*act_frm
;
320 struct brcmf_p2psd_gas_pub_act_frame
*sd_act_frm
;
322 if (!frame
|| frame_len
<= 2)
325 if (brcmf_p2p_is_pub_action(frame
, frame_len
)) {
326 pact_frm
= (struct brcmf_p2p_pub_act_frame
*)frame
;
327 switch (pact_frm
->subtype
) {
328 case P2P_PAF_GON_REQ
:
329 brcmf_dbg(TRACE
, "%s P2P Group Owner Negotiation Req Frame\n",
332 case P2P_PAF_GON_RSP
:
333 brcmf_dbg(TRACE
, "%s P2P Group Owner Negotiation Rsp Frame\n",
336 case P2P_PAF_GON_CONF
:
337 brcmf_dbg(TRACE
, "%s P2P Group Owner Negotiation Confirm Frame\n",
340 case P2P_PAF_INVITE_REQ
:
341 brcmf_dbg(TRACE
, "%s P2P Invitation Request Frame\n",
344 case P2P_PAF_INVITE_RSP
:
345 brcmf_dbg(TRACE
, "%s P2P Invitation Response Frame\n",
348 case P2P_PAF_DEVDIS_REQ
:
349 brcmf_dbg(TRACE
, "%s P2P Device Discoverability Request Frame\n",
352 case P2P_PAF_DEVDIS_RSP
:
353 brcmf_dbg(TRACE
, "%s P2P Device Discoverability Response Frame\n",
356 case P2P_PAF_PROVDIS_REQ
:
357 brcmf_dbg(TRACE
, "%s P2P Provision Discovery Request Frame\n",
360 case P2P_PAF_PROVDIS_RSP
:
361 brcmf_dbg(TRACE
, "%s P2P Provision Discovery Response Frame\n",
365 brcmf_dbg(TRACE
, "%s Unknown P2P Public Action Frame\n",
369 } else if (brcmf_p2p_is_p2p_action(frame
, frame_len
)) {
370 act_frm
= (struct brcmf_p2p_action_frame
*)frame
;
371 switch (act_frm
->subtype
) {
372 case P2P_AF_NOTICE_OF_ABSENCE
:
373 brcmf_dbg(TRACE
, "%s P2P Notice of Absence Frame\n",
376 case P2P_AF_PRESENCE_REQ
:
377 brcmf_dbg(TRACE
, "%s P2P Presence Request Frame\n",
380 case P2P_AF_PRESENCE_RSP
:
381 brcmf_dbg(TRACE
, "%s P2P Presence Response Frame\n",
384 case P2P_AF_GO_DISC_REQ
:
385 brcmf_dbg(TRACE
, "%s P2P Discoverability Request Frame\n",
389 brcmf_dbg(TRACE
, "%s Unknown P2P Action Frame\n",
393 } else if (brcmf_p2p_is_gas_action(frame
, frame_len
)) {
394 sd_act_frm
= (struct brcmf_p2psd_gas_pub_act_frame
*)frame
;
395 switch (sd_act_frm
->action
) {
396 case P2PSD_ACTION_ID_GAS_IREQ
:
397 brcmf_dbg(TRACE
, "%s P2P GAS Initial Request\n",
400 case P2PSD_ACTION_ID_GAS_IRESP
:
401 brcmf_dbg(TRACE
, "%s P2P GAS Initial Response\n",
404 case P2PSD_ACTION_ID_GAS_CREQ
:
405 brcmf_dbg(TRACE
, "%s P2P GAS Comback Request\n",
408 case P2PSD_ACTION_ID_GAS_CRESP
:
409 brcmf_dbg(TRACE
, "%s P2P GAS Comback Response\n",
413 brcmf_dbg(TRACE
, "%s Unknown P2P GAS Frame\n",
422 static void brcmf_p2p_print_actframe(bool tx
, void *frame
, u32 frame_len
)
430 * brcmf_p2p_set_firmware() - prepare firmware for peer-to-peer operation.
432 * @ifp: ifp to use for iovars (primary).
433 * @p2p_mac: mac address to configure for p2p_da_override
435 static int brcmf_p2p_set_firmware(struct brcmf_if
*ifp
, u8
*p2p_mac
)
439 brcmf_fil_cmd_int_set(ifp
, BRCMF_C_DOWN
, 1);
440 brcmf_fil_iovar_int_set(ifp
, "apsta", 1);
441 brcmf_fil_cmd_int_set(ifp
, BRCMF_C_UP
, 1);
443 /* In case of COB type, firmware has default mac address
444 * After Initializing firmware, we have to set current mac address to
445 * firmware for P2P device address. This must be done with discovery
448 brcmf_fil_iovar_int_set(ifp
, "p2p_disc", 0);
450 ret
= brcmf_fil_iovar_data_set(ifp
, "p2p_da_override", p2p_mac
,
453 brcmf_err("failed to update device address ret %d\n", ret
);
459 * brcmf_p2p_generate_bss_mac() - derive mac addresses for P2P.
461 * @p2p: P2P specific data.
462 * @dev_addr: optional device address.
464 * P2P needs mac addresses for P2P device and interface. If no device
465 * address it specified, these are derived from a random ethernet
468 static void brcmf_p2p_generate_bss_mac(struct brcmf_p2p_info
*p2p
, u8
*dev_addr
)
470 bool random_addr
= false;
472 if (!dev_addr
|| is_zero_ether_addr(dev_addr
))
475 /* Generate the P2P Device Address obtaining a random ethernet
476 * address with the locally administered bit set.
479 eth_random_addr(p2p
->dev_addr
);
481 memcpy(p2p
->dev_addr
, dev_addr
, ETH_ALEN
);
483 /* Generate the P2P Interface Address. If the discovery and connection
484 * BSSCFGs need to simultaneously co-exist, then this address must be
485 * different from the P2P Device Address, but also locally administered.
487 memcpy(p2p
->int_addr
, p2p
->dev_addr
, ETH_ALEN
);
488 p2p
->int_addr
[0] |= 0x02;
489 p2p
->int_addr
[4] ^= 0x80;
493 * brcmf_p2p_scan_is_p2p_request() - is cfg80211 scan request a P2P scan.
495 * @request: the scan request as received from cfg80211.
497 * returns true if one of the ssids in the request matches the
498 * P2P wildcard ssid; otherwise returns false.
500 static bool brcmf_p2p_scan_is_p2p_request(struct cfg80211_scan_request
*request
)
502 struct cfg80211_ssid
*ssids
= request
->ssids
;
505 for (i
= 0; i
< request
->n_ssids
; i
++) {
506 if (ssids
[i
].ssid_len
!= BRCMF_P2P_WILDCARD_SSID_LEN
)
509 brcmf_dbg(INFO
, "comparing ssid \"%s\"", ssids
[i
].ssid
);
510 if (!memcmp(BRCMF_P2P_WILDCARD_SSID
, ssids
[i
].ssid
,
511 BRCMF_P2P_WILDCARD_SSID_LEN
))
518 * brcmf_p2p_set_discover_state - set discover state in firmware.
520 * @ifp: low-level interface object.
521 * @state: discover state to set.
522 * @chanspec: channel parameters (for state @WL_P2P_DISC_ST_LISTEN only).
523 * @listen_ms: duration to listen (for state @WL_P2P_DISC_ST_LISTEN only).
525 static s32
brcmf_p2p_set_discover_state(struct brcmf_if
*ifp
, u8 state
,
526 u16 chanspec
, u16 listen_ms
)
528 struct brcmf_p2p_disc_st_le discover_state
;
530 brcmf_dbg(TRACE
, "enter\n");
532 discover_state
.state
= state
;
533 discover_state
.chspec
= cpu_to_le16(chanspec
);
534 discover_state
.dwell
= cpu_to_le16(listen_ms
);
535 ret
= brcmf_fil_bsscfg_data_set(ifp
, "p2p_state", &discover_state
,
536 sizeof(discover_state
));
541 * brcmf_p2p_deinit_discovery() - disable P2P device discovery.
543 * @p2p: P2P specific data.
545 * Resets the discovery state and disables it in firmware.
547 static s32
brcmf_p2p_deinit_discovery(struct brcmf_p2p_info
*p2p
)
549 struct brcmf_cfg80211_vif
*vif
;
551 brcmf_dbg(TRACE
, "enter\n");
553 /* Set the discovery state to SCAN */
554 vif
= p2p
->bss_idx
[P2PAPI_BSSCFG_DEVICE
].vif
;
555 (void)brcmf_p2p_set_discover_state(vif
->ifp
, WL_P2P_DISC_ST_SCAN
, 0, 0);
557 /* Disable P2P discovery in the firmware */
558 vif
= p2p
->bss_idx
[P2PAPI_BSSCFG_PRIMARY
].vif
;
559 (void)brcmf_fil_iovar_int_set(vif
->ifp
, "p2p_disc", 0);
565 * brcmf_p2p_enable_discovery() - initialize and configure discovery.
567 * @p2p: P2P specific data.
569 * Initializes the discovery device and configure the virtual interface.
571 static int brcmf_p2p_enable_discovery(struct brcmf_p2p_info
*p2p
)
573 struct brcmf_cfg80211_vif
*vif
;
576 brcmf_dbg(TRACE
, "enter\n");
577 vif
= p2p
->bss_idx
[P2PAPI_BSSCFG_DEVICE
].vif
;
579 brcmf_err("P2P config device not available\n");
584 if (test_bit(BRCMF_P2P_STATUS_ENABLED
, &p2p
->status
)) {
585 brcmf_dbg(INFO
, "P2P config device already configured\n");
589 /* Re-initialize P2P Discovery in the firmware */
590 vif
= p2p
->bss_idx
[P2PAPI_BSSCFG_PRIMARY
].vif
;
591 ret
= brcmf_fil_iovar_int_set(vif
->ifp
, "p2p_disc", 1);
593 brcmf_err("set p2p_disc error\n");
596 vif
= p2p
->bss_idx
[P2PAPI_BSSCFG_DEVICE
].vif
;
597 ret
= brcmf_p2p_set_discover_state(vif
->ifp
, WL_P2P_DISC_ST_SCAN
, 0, 0);
599 brcmf_err("unable to set WL_P2P_DISC_ST_SCAN\n");
604 * Set wsec to any non-zero value in the discovery bsscfg
605 * to ensure our P2P probe responses have the privacy bit
606 * set in the 802.11 WPA IE. Some peer devices may not
607 * initiate WPS with us if this bit is not set.
609 ret
= brcmf_fil_bsscfg_int_set(vif
->ifp
, "wsec", AES_ENABLED
);
611 brcmf_err("wsec error %d\n", ret
);
615 set_bit(BRCMF_P2P_STATUS_ENABLED
, &p2p
->status
);
621 * brcmf_p2p_escan() - initiate a P2P scan.
623 * @p2p: P2P specific data.
624 * @num_chans: number of channels to scan.
625 * @chanspecs: channel parameters for @num_chans channels.
626 * @search_state: P2P discover state to use.
627 * @bss_type: type of P2P bss.
629 static s32
brcmf_p2p_escan(struct brcmf_p2p_info
*p2p
, u32 num_chans
,
630 u16 chanspecs
[], s32 search_state
,
631 enum p2p_bss_type bss_type
)
634 s32 memsize
= offsetof(struct brcmf_p2p_scan_le
,
635 eparams
.params_le
.channel_list
);
640 struct brcmf_cfg80211_vif
*vif
;
641 struct brcmf_p2p_scan_le
*p2p_params
;
642 struct brcmf_scan_params_le
*sparams
;
644 memsize
+= num_chans
* sizeof(__le16
);
645 memblk
= kzalloc(memsize
, GFP_KERNEL
);
649 vif
= p2p
->bss_idx
[bss_type
].vif
;
651 brcmf_err("no vif for bss type %d\n", bss_type
);
655 p2p_params
= (struct brcmf_p2p_scan_le
*)memblk
;
656 sparams
= &p2p_params
->eparams
.params_le
;
658 switch (search_state
) {
659 case WL_P2P_DISC_ST_SEARCH
:
661 * If we in SEARCH STATE, we don't need to set SSID explictly
662 * because dongle use P2P WILDCARD internally by default, use
663 * null ssid, which it is already due to kzalloc.
666 case WL_P2P_DISC_ST_SCAN
:
668 * wpa_supplicant has p2p_find command with type social or
669 * progressive. For progressive, we need to set the ssid to
670 * P2P WILDCARD because we just do broadcast scan unless
673 sparams
->ssid_le
.SSID_len
=
674 cpu_to_le32(BRCMF_P2P_WILDCARD_SSID_LEN
);
675 memcpy(sparams
->ssid_le
.SSID
, BRCMF_P2P_WILDCARD_SSID
,
676 BRCMF_P2P_WILDCARD_SSID_LEN
);
679 brcmf_err(" invalid search state %d\n", search_state
);
684 brcmf_p2p_set_discover_state(vif
->ifp
, search_state
, 0, 0);
687 * set p2p scan parameters.
689 p2p_params
->type
= 'E';
691 /* determine the scan engine parameters */
692 sparams
->bss_type
= DOT11_BSSTYPE_ANY
;
693 sparams
->scan_type
= BRCMF_SCANTYPE_ACTIVE
;
695 eth_broadcast_addr(sparams
->bssid
);
696 sparams
->home_time
= cpu_to_le32(P2PAPI_SCAN_HOME_TIME_MS
);
699 * SOCIAL_CHAN_CNT + 1 takes care of the Progressive scan
700 * supported by the supplicant.
702 if (num_chans
== SOCIAL_CHAN_CNT
|| num_chans
== (SOCIAL_CHAN_CNT
+ 1))
703 active
= P2PAPI_SCAN_SOCIAL_DWELL_TIME_MS
;
704 else if (num_chans
== AF_PEER_SEARCH_CNT
)
705 active
= P2PAPI_SCAN_AF_SEARCH_DWELL_TIME_MS
;
706 else if (brcmf_get_vif_state_any(p2p
->cfg
, BRCMF_VIF_STATUS_CONNECTED
))
709 active
= P2PAPI_SCAN_DWELL_TIME_MS
;
711 /* Override scan params to find a peer for a connection */
712 if (num_chans
== 1) {
713 active
= WL_SCAN_CONNECT_DWELL_TIME_MS
;
714 /* WAR to sync with presence period of VSDB GO.
715 * send probe request more frequently
717 nprobes
= active
/ WL_SCAN_JOIN_PROBE_INTERVAL_MS
;
719 nprobes
= active
/ P2PAPI_SCAN_NPROBS_TIME_MS
;
725 brcmf_dbg(INFO
, "nprobes # %d, active_time %d\n", nprobes
, active
);
726 sparams
->active_time
= cpu_to_le32(active
);
727 sparams
->nprobes
= cpu_to_le32(nprobes
);
728 sparams
->passive_time
= cpu_to_le32(-1);
729 sparams
->channel_num
= cpu_to_le32(num_chans
&
730 BRCMF_SCAN_PARAMS_COUNT_MASK
);
731 for (i
= 0; i
< num_chans
; i
++)
732 sparams
->channel_list
[i
] = cpu_to_le16(chanspecs
[i
]);
734 /* set the escan specific parameters */
735 p2p_params
->eparams
.version
= cpu_to_le32(BRCMF_ESCAN_REQ_VERSION
);
736 p2p_params
->eparams
.action
= cpu_to_le16(WL_ESCAN_ACTION_START
);
737 p2p_params
->eparams
.sync_id
= cpu_to_le16(0x1234);
738 /* perform p2p scan on primary device */
739 ret
= brcmf_fil_bsscfg_data_set(vif
->ifp
, "p2p_scan", memblk
, memsize
);
741 set_bit(BRCMF_SCAN_STATUS_BUSY
, &p2p
->cfg
->scan_status
);
748 * brcmf_p2p_run_escan() - escan callback for peer-to-peer.
750 * @cfg: driver private data for cfg80211 interface.
751 * @ndev: net device for which scan is requested.
752 * @request: scan request from cfg80211.
753 * @action: scan action.
755 * Determines the P2P discovery state based to scan request parameters and
756 * validates the channels in the request.
758 static s32
brcmf_p2p_run_escan(struct brcmf_cfg80211_info
*cfg
,
759 struct brcmf_if
*ifp
,
760 struct cfg80211_scan_request
*request
)
762 struct brcmf_p2p_info
*p2p
= &cfg
->p2p
;
764 s32 search_state
= WL_P2P_DISC_ST_SCAN
;
765 struct brcmf_cfg80211_vif
*vif
;
766 struct net_device
*dev
= NULL
;
767 int i
, num_nodfs
= 0;
770 brcmf_dbg(TRACE
, "enter\n");
777 if (request
->n_channels
) {
778 chanspecs
= kcalloc(request
->n_channels
, sizeof(*chanspecs
),
784 vif
= p2p
->bss_idx
[P2PAPI_BSSCFG_CONNECTION
].vif
;
786 dev
= vif
->wdev
.netdev
;
787 if (request
->n_channels
== 3 &&
788 request
->channels
[0]->hw_value
== SOCIAL_CHAN_1
&&
789 request
->channels
[1]->hw_value
== SOCIAL_CHAN_2
&&
790 request
->channels
[2]->hw_value
== SOCIAL_CHAN_3
) {
791 /* SOCIAL CHANNELS 1, 6, 11 */
792 search_state
= WL_P2P_DISC_ST_SEARCH
;
793 brcmf_dbg(INFO
, "P2P SEARCH PHASE START\n");
794 } else if (dev
!= NULL
&&
795 vif
->wdev
.iftype
== NL80211_IFTYPE_P2P_GO
) {
796 /* If you are already a GO, then do SEARCH only */
797 brcmf_dbg(INFO
, "Already a GO. Do SEARCH Only\n");
798 search_state
= WL_P2P_DISC_ST_SEARCH
;
800 brcmf_dbg(INFO
, "P2P SCAN STATE START\n");
804 * no P2P scanning on passive or DFS channels.
806 for (i
= 0; i
< request
->n_channels
; i
++) {
807 struct ieee80211_channel
*chan
= request
->channels
[i
];
809 if (chan
->flags
& (IEEE80211_CHAN_RADAR
|
810 IEEE80211_CHAN_NO_IR
))
813 chanspecs
[i
] = channel_to_chanspec(&p2p
->cfg
->d11inf
,
815 brcmf_dbg(INFO
, "%d: chan=%d, channel spec=%x\n",
816 num_nodfs
, chan
->hw_value
, chanspecs
[i
]);
819 err
= brcmf_p2p_escan(p2p
, num_nodfs
, chanspecs
, search_state
,
820 P2PAPI_BSSCFG_DEVICE
);
825 brcmf_err("error (%d)\n", err
);
831 * brcmf_p2p_find_listen_channel() - find listen channel in ie string.
833 * @ie: string of information elements.
834 * @ie_len: length of string.
836 * Scan ie for p2p ie and look for attribute 6 channel. If available determine
837 * channel and return it.
839 static s32
brcmf_p2p_find_listen_channel(const u8
*ie
, u32 ie_len
)
845 err
= cfg80211_get_p2p_attr(ie
, ie_len
,
846 IEEE80211_P2P_ATTR_LISTEN_CHANNEL
,
847 channel_ie
, sizeof(channel_ie
));
851 /* listen channel subel length format: */
852 /* 3(country) + 1(op. class) + 1(chan num) */
853 listen_channel
= (s32
)channel_ie
[3 + 1];
855 if (listen_channel
== SOCIAL_CHAN_1
||
856 listen_channel
== SOCIAL_CHAN_2
||
857 listen_channel
== SOCIAL_CHAN_3
) {
858 brcmf_dbg(INFO
, "Found my Listen Channel %d\n", listen_channel
);
859 return listen_channel
;
867 * brcmf_p2p_scan_prep() - prepare scan based on request.
869 * @wiphy: wiphy device.
870 * @request: scan request from cfg80211.
871 * @vif: vif on which scan request is to be executed.
873 * Prepare the scan appropriately for type of scan requested. Overrides the
874 * escan .run() callback for peer-to-peer scanning.
876 int brcmf_p2p_scan_prep(struct wiphy
*wiphy
,
877 struct cfg80211_scan_request
*request
,
878 struct brcmf_cfg80211_vif
*vif
)
880 struct brcmf_cfg80211_info
*cfg
= wiphy_to_cfg(wiphy
);
881 struct brcmf_p2p_info
*p2p
= &cfg
->p2p
;
884 if (brcmf_p2p_scan_is_p2p_request(request
)) {
885 /* find my listen channel */
886 err
= brcmf_p2p_find_listen_channel(request
->ie
,
891 p2p
->afx_hdl
.my_listen_chan
= err
;
893 clear_bit(BRCMF_P2P_STATUS_GO_NEG_PHASE
, &p2p
->status
);
894 brcmf_dbg(INFO
, "P2P: GO_NEG_PHASE status cleared\n");
896 err
= brcmf_p2p_enable_discovery(p2p
);
900 vif
= p2p
->bss_idx
[P2PAPI_BSSCFG_DEVICE
].vif
;
902 /* override .run_escan() callback. */
903 cfg
->escan_info
.run
= brcmf_p2p_run_escan
;
910 * brcmf_p2p_discover_listen() - set firmware to discover listen state.
913 * @channel: channel nr for discover listen.
914 * @duration: time in ms to stay on channel.
918 brcmf_p2p_discover_listen(struct brcmf_p2p_info
*p2p
, u16 channel
, u32 duration
)
920 struct brcmf_cfg80211_vif
*vif
;
921 struct brcmu_chan ch
;
924 vif
= p2p
->bss_idx
[P2PAPI_BSSCFG_DEVICE
].vif
;
926 brcmf_err("Discovery is not set, so we have nothing to do\n");
931 if (test_bit(BRCMF_P2P_STATUS_DISCOVER_LISTEN
, &p2p
->status
)) {
932 brcmf_err("Previous LISTEN is not completed yet\n");
933 /* WAR: prevent cookie mismatch in wpa_supplicant return OK */
938 ch
.bw
= BRCMU_CHAN_BW_20
;
939 p2p
->cfg
->d11inf
.encchspec(&ch
);
940 err
= brcmf_p2p_set_discover_state(vif
->ifp
, WL_P2P_DISC_ST_LISTEN
,
941 ch
.chspec
, (u16
)duration
);
943 set_bit(BRCMF_P2P_STATUS_DISCOVER_LISTEN
, &p2p
->status
);
944 p2p
->remain_on_channel_cookie
++;
952 * brcmf_p2p_remain_on_channel() - put device on channel and stay there.
954 * @wiphy: wiphy device.
955 * @channel: channel to stay on.
956 * @duration: time in ms to remain on channel.
959 int brcmf_p2p_remain_on_channel(struct wiphy
*wiphy
, struct wireless_dev
*wdev
,
960 struct ieee80211_channel
*channel
,
961 unsigned int duration
, u64
*cookie
)
963 struct brcmf_cfg80211_info
*cfg
= wiphy_to_cfg(wiphy
);
964 struct brcmf_p2p_info
*p2p
= &cfg
->p2p
;
968 channel_nr
= ieee80211_frequency_to_channel(channel
->center_freq
);
969 brcmf_dbg(TRACE
, "Enter, channel: %d, duration ms (%d)\n", channel_nr
,
972 err
= brcmf_p2p_enable_discovery(p2p
);
975 err
= brcmf_p2p_discover_listen(p2p
, channel_nr
, duration
);
979 memcpy(&p2p
->remain_on_channel
, channel
, sizeof(*channel
));
980 *cookie
= p2p
->remain_on_channel_cookie
;
981 cfg80211_ready_on_channel(wdev
, *cookie
, channel
, duration
, GFP_KERNEL
);
989 * brcmf_p2p_notify_listen_complete() - p2p listen has completed.
991 * @ifp: interfac control.
992 * @e: event message. Not used, to make it usable for fweh event dispatcher.
993 * @data: payload of message. Not used.
996 int brcmf_p2p_notify_listen_complete(struct brcmf_if
*ifp
,
997 const struct brcmf_event_msg
*e
,
1000 struct brcmf_cfg80211_info
*cfg
= ifp
->drvr
->config
;
1001 struct brcmf_p2p_info
*p2p
= &cfg
->p2p
;
1003 brcmf_dbg(TRACE
, "Enter\n");
1004 if (test_and_clear_bit(BRCMF_P2P_STATUS_DISCOVER_LISTEN
,
1006 if (test_and_clear_bit(BRCMF_P2P_STATUS_WAITING_NEXT_AF_LISTEN
,
1008 clear_bit(BRCMF_P2P_STATUS_WAITING_NEXT_ACT_FRAME
,
1010 brcmf_dbg(INFO
, "Listen DONE, wake up wait_next_af\n");
1011 complete(&p2p
->wait_next_af
);
1014 cfg80211_remain_on_channel_expired(&ifp
->vif
->wdev
,
1015 p2p
->remain_on_channel_cookie
,
1016 &p2p
->remain_on_channel
,
1024 * brcmf_p2p_cancel_remain_on_channel() - cancel p2p listen state.
1026 * @ifp: interfac control.
1029 void brcmf_p2p_cancel_remain_on_channel(struct brcmf_if
*ifp
)
1033 brcmf_p2p_set_discover_state(ifp
, WL_P2P_DISC_ST_SCAN
, 0, 0);
1034 brcmf_p2p_notify_listen_complete(ifp
, NULL
, NULL
);
1039 * brcmf_p2p_act_frm_search() - search function for action frame.
1042 * channel: channel on which action frame is to be trasmitted.
1044 * search function to reach at common channel to send action frame. When
1045 * channel is 0 then all social channels will be used to send af
1047 static s32
brcmf_p2p_act_frm_search(struct brcmf_p2p_info
*p2p
, u16 channel
)
1051 u16
*default_chan_list
;
1053 struct brcmu_chan ch
;
1055 brcmf_dbg(TRACE
, "Enter\n");
1058 channel_cnt
= AF_PEER_SEARCH_CNT
;
1060 channel_cnt
= SOCIAL_CHAN_CNT
;
1061 default_chan_list
= kcalloc(channel_cnt
, sizeof(*default_chan_list
),
1063 if (default_chan_list
== NULL
) {
1064 brcmf_err("channel list allocation failed\n");
1068 ch
.bw
= BRCMU_CHAN_BW_20
;
1071 p2p
->cfg
->d11inf
.encchspec(&ch
);
1072 /* insert same channel to the chan_list */
1073 for (i
= 0; i
< channel_cnt
; i
++)
1074 default_chan_list
[i
] = ch
.chspec
;
1076 ch
.chnum
= SOCIAL_CHAN_1
;
1077 p2p
->cfg
->d11inf
.encchspec(&ch
);
1078 default_chan_list
[0] = ch
.chspec
;
1079 ch
.chnum
= SOCIAL_CHAN_2
;
1080 p2p
->cfg
->d11inf
.encchspec(&ch
);
1081 default_chan_list
[1] = ch
.chspec
;
1082 ch
.chnum
= SOCIAL_CHAN_3
;
1083 p2p
->cfg
->d11inf
.encchspec(&ch
);
1084 default_chan_list
[2] = ch
.chspec
;
1086 err
= brcmf_p2p_escan(p2p
, channel_cnt
, default_chan_list
,
1087 WL_P2P_DISC_ST_SEARCH
, P2PAPI_BSSCFG_DEVICE
);
1088 kfree(default_chan_list
);
1095 * brcmf_p2p_afx_handler() - afx worker thread.
1100 static void brcmf_p2p_afx_handler(struct work_struct
*work
)
1102 struct afx_hdl
*afx_hdl
= container_of(work
, struct afx_hdl
, afx_work
);
1103 struct brcmf_p2p_info
*p2p
= container_of(afx_hdl
,
1104 struct brcmf_p2p_info
,
1108 if (!afx_hdl
->is_active
)
1111 if (afx_hdl
->is_listen
&& afx_hdl
->my_listen_chan
)
1113 err
= brcmf_p2p_discover_listen(p2p
, afx_hdl
->my_listen_chan
,
1114 100 * (1 + prandom_u32() % 3));
1116 err
= brcmf_p2p_act_frm_search(p2p
, afx_hdl
->peer_listen_chan
);
1119 brcmf_err("ERROR occurred! value is (%d)\n", err
);
1120 if (test_bit(BRCMF_P2P_STATUS_FINDING_COMMON_CHANNEL
,
1122 complete(&afx_hdl
->act_frm_scan
);
1128 * brcmf_p2p_af_searching_channel() - search channel.
1130 * @p2p: p2p device info struct.
1133 static s32
brcmf_p2p_af_searching_channel(struct brcmf_p2p_info
*p2p
)
1135 struct afx_hdl
*afx_hdl
= &p2p
->afx_hdl
;
1136 struct brcmf_cfg80211_vif
*pri_vif
;
1139 brcmf_dbg(TRACE
, "Enter\n");
1141 pri_vif
= p2p
->bss_idx
[P2PAPI_BSSCFG_PRIMARY
].vif
;
1143 reinit_completion(&afx_hdl
->act_frm_scan
);
1144 set_bit(BRCMF_P2P_STATUS_FINDING_COMMON_CHANNEL
, &p2p
->status
);
1145 afx_hdl
->is_active
= true;
1146 afx_hdl
->peer_chan
= P2P_INVALID_CHANNEL
;
1148 /* Loop to wait until we find a peer's channel or the
1149 * pending action frame tx is cancelled.
1152 while ((retry
< P2P_CHANNEL_SYNC_RETRY
) &&
1153 (afx_hdl
->peer_chan
== P2P_INVALID_CHANNEL
)) {
1154 afx_hdl
->is_listen
= false;
1155 brcmf_dbg(TRACE
, "Scheduling action frame for sending.. (%d)\n",
1157 /* search peer on peer's listen channel */
1158 schedule_work(&afx_hdl
->afx_work
);
1159 wait_for_completion_timeout(&afx_hdl
->act_frm_scan
,
1160 P2P_AF_FRM_SCAN_MAX_WAIT
);
1161 if ((afx_hdl
->peer_chan
!= P2P_INVALID_CHANNEL
) ||
1162 (!test_bit(BRCMF_P2P_STATUS_FINDING_COMMON_CHANNEL
,
1166 if (afx_hdl
->my_listen_chan
) {
1167 brcmf_dbg(TRACE
, "Scheduling listen peer, channel=%d\n",
1168 afx_hdl
->my_listen_chan
);
1169 /* listen on my listen channel */
1170 afx_hdl
->is_listen
= true;
1171 schedule_work(&afx_hdl
->afx_work
);
1172 wait_for_completion_timeout(&afx_hdl
->act_frm_scan
,
1173 P2P_AF_FRM_SCAN_MAX_WAIT
);
1175 if ((afx_hdl
->peer_chan
!= P2P_INVALID_CHANNEL
) ||
1176 (!test_bit(BRCMF_P2P_STATUS_FINDING_COMMON_CHANNEL
,
1181 /* if sta is connected or connecting, sleep for a while before
1182 * retry af tx or finding a peer
1184 if (test_bit(BRCMF_VIF_STATUS_CONNECTED
, &pri_vif
->sme_state
) ||
1185 test_bit(BRCMF_VIF_STATUS_CONNECTING
, &pri_vif
->sme_state
))
1186 msleep(P2P_DEFAULT_SLEEP_TIME_VSDB
);
1189 brcmf_dbg(TRACE
, "Completed search/listen peer_chan=%d\n",
1190 afx_hdl
->peer_chan
);
1191 afx_hdl
->is_active
= false;
1193 clear_bit(BRCMF_P2P_STATUS_FINDING_COMMON_CHANNEL
, &p2p
->status
);
1195 return afx_hdl
->peer_chan
;
1200 * brcmf_p2p_scan_finding_common_channel() - was escan used for finding channel
1202 * @cfg: common configuration struct.
1203 * @bi: bss info struct, result from scan.
1206 bool brcmf_p2p_scan_finding_common_channel(struct brcmf_cfg80211_info
*cfg
,
1207 struct brcmf_bss_info_le
*bi
)
1210 struct brcmf_p2p_info
*p2p
= &cfg
->p2p
;
1211 struct afx_hdl
*afx_hdl
= &p2p
->afx_hdl
;
1212 struct brcmu_chan ch
;
1215 u8 p2p_dev_addr
[ETH_ALEN
];
1217 if (!test_bit(BRCMF_P2P_STATUS_FINDING_COMMON_CHANNEL
, &p2p
->status
))
1221 brcmf_dbg(TRACE
, "ACTION FRAME SCAN Done\n");
1222 if (afx_hdl
->peer_chan
== P2P_INVALID_CHANNEL
)
1223 complete(&afx_hdl
->act_frm_scan
);
1227 ie
= ((u8
*)bi
) + le16_to_cpu(bi
->ie_offset
);
1228 memset(p2p_dev_addr
, 0, sizeof(p2p_dev_addr
));
1229 err
= cfg80211_get_p2p_attr(ie
, le32_to_cpu(bi
->ie_length
),
1230 IEEE80211_P2P_ATTR_DEVICE_INFO
,
1231 p2p_dev_addr
, sizeof(p2p_dev_addr
));
1233 err
= cfg80211_get_p2p_attr(ie
, le32_to_cpu(bi
->ie_length
),
1234 IEEE80211_P2P_ATTR_DEVICE_ID
,
1235 p2p_dev_addr
, sizeof(p2p_dev_addr
));
1237 (ether_addr_equal(p2p_dev_addr
, afx_hdl
->tx_dst_addr
))) {
1239 ch
.chspec
= le16_to_cpu(bi
->chanspec
);
1240 cfg
->d11inf
.decchspec(&ch
);
1241 bi
->ctl_ch
= ch
.control_ch_num
;
1243 afx_hdl
->peer_chan
= bi
->ctl_ch
;
1244 brcmf_dbg(TRACE
, "ACTION FRAME SCAN : Peer %pM found, channel : %d\n",
1245 afx_hdl
->tx_dst_addr
, afx_hdl
->peer_chan
);
1246 complete(&afx_hdl
->act_frm_scan
);
1252 * brcmf_p2p_stop_wait_next_action_frame() - finish scan if af tx complete.
1254 * @cfg: common configuration struct.
1258 brcmf_p2p_stop_wait_next_action_frame(struct brcmf_cfg80211_info
*cfg
)
1260 struct brcmf_p2p_info
*p2p
= &cfg
->p2p
;
1261 struct brcmf_if
*ifp
= p2p
->bss_idx
[P2PAPI_BSSCFG_PRIMARY
].vif
->ifp
;
1263 if (test_bit(BRCMF_P2P_STATUS_SENDING_ACT_FRAME
, &p2p
->status
) &&
1264 (test_bit(BRCMF_P2P_STATUS_ACTION_TX_COMPLETED
, &p2p
->status
) ||
1265 test_bit(BRCMF_P2P_STATUS_ACTION_TX_NOACK
, &p2p
->status
))) {
1266 brcmf_dbg(TRACE
, "*** Wake UP ** abort actframe iovar\n");
1267 /* if channel is not zero, "actfame" uses off channel scan.
1268 * So abort scan for off channel completion.
1270 if (p2p
->af_sent_channel
)
1271 brcmf_notify_escan_complete(cfg
, ifp
, true, true);
1272 } else if (test_bit(BRCMF_P2P_STATUS_WAITING_NEXT_AF_LISTEN
,
1274 brcmf_dbg(TRACE
, "*** Wake UP ** abort listen for next af frame\n");
1275 /* So abort scan to cancel listen */
1276 brcmf_notify_escan_complete(cfg
, ifp
, true, true);
1282 * brcmf_p2p_gon_req_collision() - Check if go negotiaton collission
1284 * @p2p: p2p device info struct.
1286 * return true if recevied action frame is to be dropped.
1289 brcmf_p2p_gon_req_collision(struct brcmf_p2p_info
*p2p
, u8
*mac
)
1291 struct brcmf_cfg80211_info
*cfg
= p2p
->cfg
;
1292 struct brcmf_if
*ifp
;
1294 brcmf_dbg(TRACE
, "Enter\n");
1296 if (!test_bit(BRCMF_P2P_STATUS_WAITING_NEXT_ACT_FRAME
, &p2p
->status
) ||
1297 !p2p
->gon_req_action
)
1300 brcmf_dbg(TRACE
, "GO Negotiation Request COLLISION !!!\n");
1301 /* if sa(peer) addr is less than da(my) addr, then this device
1302 * process peer's gon request and block to send gon req.
1303 * if not (sa addr > da addr),
1304 * this device will process gon request and drop gon req of peer.
1306 ifp
= p2p
->bss_idx
[P2PAPI_BSSCFG_DEVICE
].vif
->ifp
;
1307 if (memcmp(mac
, ifp
->mac_addr
, ETH_ALEN
) < 0) {
1308 brcmf_dbg(INFO
, "Block transmit gon req !!!\n");
1309 p2p
->block_gon_req_tx
= true;
1310 /* if we are finding a common channel for sending af,
1311 * do not scan more to block to send current gon req
1313 if (test_and_clear_bit(BRCMF_P2P_STATUS_FINDING_COMMON_CHANNEL
,
1315 complete(&p2p
->afx_hdl
.act_frm_scan
);
1316 if (test_and_clear_bit(BRCMF_P2P_STATUS_WAITING_NEXT_ACT_FRAME
,
1318 brcmf_p2p_stop_wait_next_action_frame(cfg
);
1322 /* drop gon request of peer to process gon request by this device. */
1323 brcmf_dbg(INFO
, "Drop received gon req !!!\n");
1330 * brcmf_p2p_notify_action_frame_rx() - received action frame.
1332 * @ifp: interfac control.
1333 * @e: event message. Not used, to make it usable for fweh event dispatcher.
1334 * @data: payload of message, containing action frame data.
1337 int brcmf_p2p_notify_action_frame_rx(struct brcmf_if
*ifp
,
1338 const struct brcmf_event_msg
*e
,
1341 struct brcmf_cfg80211_info
*cfg
= ifp
->drvr
->config
;
1342 struct brcmf_p2p_info
*p2p
= &cfg
->p2p
;
1343 struct afx_hdl
*afx_hdl
= &p2p
->afx_hdl
;
1344 struct wireless_dev
*wdev
;
1345 u32 mgmt_frame_len
= e
->datalen
- sizeof(struct brcmf_rx_mgmt_data
);
1346 struct brcmf_rx_mgmt_data
*rxframe
= (struct brcmf_rx_mgmt_data
*)data
;
1347 u8
*frame
= (u8
*)(rxframe
+ 1);
1348 struct brcmf_p2p_pub_act_frame
*act_frm
;
1349 struct brcmf_p2psd_gas_pub_act_frame
*sd_act_frm
;
1350 struct brcmu_chan ch
;
1351 struct ieee80211_mgmt
*mgmt_frame
;
1356 if (e
->datalen
< sizeof(*rxframe
)) {
1357 brcmf_dbg(SCAN
, "Event data to small. Ignore\n");
1361 ch
.chspec
= be16_to_cpu(rxframe
->chanspec
);
1362 cfg
->d11inf
.decchspec(&ch
);
1363 /* Check if wpa_supplicant has registered for this frame */
1364 brcmf_dbg(INFO
, "ifp->vif->mgmt_rx_reg %04x\n", ifp
->vif
->mgmt_rx_reg
);
1365 mgmt_type
= (IEEE80211_STYPE_ACTION
& IEEE80211_FCTL_STYPE
) >> 4;
1366 if ((ifp
->vif
->mgmt_rx_reg
& BIT(mgmt_type
)) == 0)
1369 brcmf_p2p_print_actframe(false, frame
, mgmt_frame_len
);
1371 action
= P2P_PAF_SUBTYPE_INVALID
;
1372 if (brcmf_p2p_is_pub_action(frame
, mgmt_frame_len
)) {
1373 act_frm
= (struct brcmf_p2p_pub_act_frame
*)frame
;
1374 action
= act_frm
->subtype
;
1375 if ((action
== P2P_PAF_GON_REQ
) &&
1376 (brcmf_p2p_gon_req_collision(p2p
, (u8
*)e
->addr
))) {
1377 if (test_bit(BRCMF_P2P_STATUS_FINDING_COMMON_CHANNEL
,
1379 (ether_addr_equal(afx_hdl
->tx_dst_addr
, e
->addr
))) {
1380 afx_hdl
->peer_chan
= ch
.control_ch_num
;
1381 brcmf_dbg(INFO
, "GON request: Peer found, channel=%d\n",
1382 afx_hdl
->peer_chan
);
1383 complete(&afx_hdl
->act_frm_scan
);
1387 /* After complete GO Negotiation, roll back to mpc mode */
1388 if ((action
== P2P_PAF_GON_CONF
) ||
1389 (action
== P2P_PAF_PROVDIS_RSP
))
1390 brcmf_set_mpc(ifp
, 1);
1391 if (action
== P2P_PAF_GON_CONF
) {
1392 brcmf_dbg(TRACE
, "P2P: GO_NEG_PHASE status cleared\n");
1393 clear_bit(BRCMF_P2P_STATUS_GO_NEG_PHASE
, &p2p
->status
);
1395 } else if (brcmf_p2p_is_gas_action(frame
, mgmt_frame_len
)) {
1396 sd_act_frm
= (struct brcmf_p2psd_gas_pub_act_frame
*)frame
;
1397 action
= sd_act_frm
->action
;
1400 if (test_bit(BRCMF_P2P_STATUS_WAITING_NEXT_ACT_FRAME
, &p2p
->status
) &&
1401 (p2p
->next_af_subtype
== action
)) {
1402 brcmf_dbg(TRACE
, "We got a right next frame! (%d)\n", action
);
1403 clear_bit(BRCMF_P2P_STATUS_WAITING_NEXT_ACT_FRAME
,
1405 /* Stop waiting for next AF. */
1406 brcmf_p2p_stop_wait_next_action_frame(cfg
);
1409 mgmt_frame
= kzalloc(offsetof(struct ieee80211_mgmt
, u
) +
1410 mgmt_frame_len
, GFP_KERNEL
);
1412 brcmf_err("No memory available for action frame\n");
1415 memcpy(mgmt_frame
->da
, ifp
->mac_addr
, ETH_ALEN
);
1416 brcmf_fil_cmd_data_get(ifp
, BRCMF_C_GET_BSSID
, mgmt_frame
->bssid
,
1418 memcpy(mgmt_frame
->sa
, e
->addr
, ETH_ALEN
);
1419 mgmt_frame
->frame_control
= cpu_to_le16(IEEE80211_STYPE_ACTION
);
1420 memcpy(&mgmt_frame
->u
, frame
, mgmt_frame_len
);
1421 mgmt_frame_len
+= offsetof(struct ieee80211_mgmt
, u
);
1423 freq
= ieee80211_channel_to_frequency(ch
.control_ch_num
,
1424 ch
.band
== BRCMU_CHAN_BAND_2G
?
1428 wdev
= &ifp
->vif
->wdev
;
1429 cfg80211_rx_mgmt(wdev
, freq
, 0, (u8
*)mgmt_frame
, mgmt_frame_len
, 0);
1437 * brcmf_p2p_notify_action_tx_complete() - transmit action frame complete
1439 * @ifp: interfac control.
1440 * @e: event message. Not used, to make it usable for fweh event dispatcher.
1444 int brcmf_p2p_notify_action_tx_complete(struct brcmf_if
*ifp
,
1445 const struct brcmf_event_msg
*e
,
1448 struct brcmf_cfg80211_info
*cfg
= ifp
->drvr
->config
;
1449 struct brcmf_p2p_info
*p2p
= &cfg
->p2p
;
1451 brcmf_dbg(INFO
, "Enter: event %s, status=%d\n",
1452 e
->event_code
== BRCMF_E_ACTION_FRAME_OFF_CHAN_COMPLETE
?
1453 "ACTION_FRAME_OFF_CHAN_COMPLETE" : "ACTION_FRAME_COMPLETE",
1456 if (!test_bit(BRCMF_P2P_STATUS_SENDING_ACT_FRAME
, &p2p
->status
))
1459 if (e
->event_code
== BRCMF_E_ACTION_FRAME_COMPLETE
) {
1460 if (e
->status
== BRCMF_E_STATUS_SUCCESS
) {
1461 set_bit(BRCMF_P2P_STATUS_ACTION_TX_COMPLETED
,
1463 if (!p2p
->wait_for_offchan_complete
)
1464 complete(&p2p
->send_af_done
);
1466 set_bit(BRCMF_P2P_STATUS_ACTION_TX_NOACK
, &p2p
->status
);
1467 /* If there is no ack, we don't need to wait for
1468 * WLC_E_ACTION_FRAME_OFFCHAN_COMPLETE event
1470 brcmf_p2p_stop_wait_next_action_frame(cfg
);
1474 complete(&p2p
->send_af_done
);
1481 * brcmf_p2p_tx_action_frame() - send action frame over fil.
1483 * @p2p: p2p info struct for vif.
1484 * @af_params: action frame data/info.
1486 * Send an action frame immediately without doing channel synchronization.
1488 * This function waits for a completion event before returning.
1489 * The WLC_E_ACTION_FRAME_COMPLETE event will be received when the action
1490 * frame is transmitted.
1492 static s32
brcmf_p2p_tx_action_frame(struct brcmf_p2p_info
*p2p
,
1493 struct brcmf_fil_af_params_le
*af_params
)
1495 struct brcmf_cfg80211_vif
*vif
;
1499 brcmf_dbg(TRACE
, "Enter\n");
1501 reinit_completion(&p2p
->send_af_done
);
1502 clear_bit(BRCMF_P2P_STATUS_ACTION_TX_COMPLETED
, &p2p
->status
);
1503 clear_bit(BRCMF_P2P_STATUS_ACTION_TX_NOACK
, &p2p
->status
);
1505 vif
= p2p
->bss_idx
[P2PAPI_BSSCFG_DEVICE
].vif
;
1506 err
= brcmf_fil_bsscfg_data_set(vif
->ifp
, "actframe", af_params
,
1507 sizeof(*af_params
));
1509 brcmf_err(" sending action frame has failed\n");
1513 p2p
->af_sent_channel
= le32_to_cpu(af_params
->channel
);
1514 p2p
->af_tx_sent_jiffies
= jiffies
;
1516 if (test_bit(BRCMF_P2P_STATUS_DISCOVER_LISTEN
, &p2p
->status
) &&
1517 p2p
->af_sent_channel
==
1518 ieee80211_frequency_to_channel(p2p
->remain_on_channel
.center_freq
))
1519 p2p
->wait_for_offchan_complete
= false;
1521 p2p
->wait_for_offchan_complete
= true;
1523 brcmf_dbg(TRACE
, "Waiting for %s tx completion event\n",
1524 (p2p
->wait_for_offchan_complete
) ?
1525 "off-channel" : "on-channel");
1527 timeout
= wait_for_completion_timeout(&p2p
->send_af_done
,
1528 P2P_AF_MAX_WAIT_TIME
);
1530 if (test_bit(BRCMF_P2P_STATUS_ACTION_TX_COMPLETED
, &p2p
->status
)) {
1531 brcmf_dbg(TRACE
, "TX action frame operation is success\n");
1534 brcmf_dbg(TRACE
, "TX action frame operation has failed\n");
1536 /* clear status bit for action tx */
1537 clear_bit(BRCMF_P2P_STATUS_ACTION_TX_COMPLETED
, &p2p
->status
);
1538 clear_bit(BRCMF_P2P_STATUS_ACTION_TX_NOACK
, &p2p
->status
);
1546 * brcmf_p2p_pub_af_tx() - public action frame tx routine.
1548 * @cfg: driver private data for cfg80211 interface.
1549 * @af_params: action frame data/info.
1550 * @config_af_params: configuration data for action frame.
1552 * routine which transmits ation frame public type.
1554 static s32
brcmf_p2p_pub_af_tx(struct brcmf_cfg80211_info
*cfg
,
1555 struct brcmf_fil_af_params_le
*af_params
,
1556 struct brcmf_config_af_params
*config_af_params
)
1558 struct brcmf_p2p_info
*p2p
= &cfg
->p2p
;
1559 struct brcmf_fil_action_frame_le
*action_frame
;
1560 struct brcmf_p2p_pub_act_frame
*act_frm
;
1564 action_frame
= &af_params
->action_frame
;
1565 act_frm
= (struct brcmf_p2p_pub_act_frame
*)(action_frame
->data
);
1567 config_af_params
->extra_listen
= true;
1569 switch (act_frm
->subtype
) {
1570 case P2P_PAF_GON_REQ
:
1571 brcmf_dbg(TRACE
, "P2P: GO_NEG_PHASE status set\n");
1572 set_bit(BRCMF_P2P_STATUS_GO_NEG_PHASE
, &p2p
->status
);
1573 config_af_params
->mpc_onoff
= 0;
1574 config_af_params
->search_channel
= true;
1575 p2p
->next_af_subtype
= act_frm
->subtype
+ 1;
1576 p2p
->gon_req_action
= true;
1577 /* increase dwell time to wait for RESP frame */
1578 af_params
->dwell_time
= cpu_to_le32(P2P_AF_MED_DWELL_TIME
);
1580 case P2P_PAF_GON_RSP
:
1581 p2p
->next_af_subtype
= act_frm
->subtype
+ 1;
1582 /* increase dwell time to wait for CONF frame */
1583 af_params
->dwell_time
= cpu_to_le32(P2P_AF_MED_DWELL_TIME
);
1585 case P2P_PAF_GON_CONF
:
1586 /* If we reached till GO Neg confirmation reset the filter */
1587 brcmf_dbg(TRACE
, "P2P: GO_NEG_PHASE status cleared\n");
1588 clear_bit(BRCMF_P2P_STATUS_GO_NEG_PHASE
, &p2p
->status
);
1589 /* turn on mpc again if go nego is done */
1590 config_af_params
->mpc_onoff
= 1;
1591 /* minimize dwell time */
1592 af_params
->dwell_time
= cpu_to_le32(P2P_AF_MIN_DWELL_TIME
);
1593 config_af_params
->extra_listen
= false;
1595 case P2P_PAF_INVITE_REQ
:
1596 config_af_params
->search_channel
= true;
1597 p2p
->next_af_subtype
= act_frm
->subtype
+ 1;
1598 /* increase dwell time */
1599 af_params
->dwell_time
= cpu_to_le32(P2P_AF_MED_DWELL_TIME
);
1601 case P2P_PAF_INVITE_RSP
:
1602 /* minimize dwell time */
1603 af_params
->dwell_time
= cpu_to_le32(P2P_AF_MIN_DWELL_TIME
);
1604 config_af_params
->extra_listen
= false;
1606 case P2P_PAF_DEVDIS_REQ
:
1607 config_af_params
->search_channel
= true;
1608 p2p
->next_af_subtype
= act_frm
->subtype
+ 1;
1609 /* maximize dwell time to wait for RESP frame */
1610 af_params
->dwell_time
= cpu_to_le32(P2P_AF_LONG_DWELL_TIME
);
1612 case P2P_PAF_DEVDIS_RSP
:
1613 /* minimize dwell time */
1614 af_params
->dwell_time
= cpu_to_le32(P2P_AF_MIN_DWELL_TIME
);
1615 config_af_params
->extra_listen
= false;
1617 case P2P_PAF_PROVDIS_REQ
:
1618 ie_len
= le16_to_cpu(action_frame
->len
) -
1619 offsetof(struct brcmf_p2p_pub_act_frame
, elts
);
1620 if (cfg80211_get_p2p_attr(&act_frm
->elts
[0], ie_len
,
1621 IEEE80211_P2P_ATTR_GROUP_ID
,
1623 config_af_params
->search_channel
= true;
1624 config_af_params
->mpc_onoff
= 0;
1625 p2p
->next_af_subtype
= act_frm
->subtype
+ 1;
1626 /* increase dwell time to wait for RESP frame */
1627 af_params
->dwell_time
= cpu_to_le32(P2P_AF_MED_DWELL_TIME
);
1629 case P2P_PAF_PROVDIS_RSP
:
1630 /* wpa_supplicant send go nego req right after prov disc */
1631 p2p
->next_af_subtype
= P2P_PAF_GON_REQ
;
1632 /* increase dwell time to MED level */
1633 af_params
->dwell_time
= cpu_to_le32(P2P_AF_MED_DWELL_TIME
);
1634 config_af_params
->extra_listen
= false;
1637 brcmf_err("Unknown p2p pub act frame subtype: %d\n",
1645 * brcmf_p2p_send_action_frame() - send action frame .
1647 * @cfg: driver private data for cfg80211 interface.
1648 * @ndev: net device to transmit on.
1649 * @af_params: configuration data for action frame.
1651 bool brcmf_p2p_send_action_frame(struct brcmf_cfg80211_info
*cfg
,
1652 struct net_device
*ndev
,
1653 struct brcmf_fil_af_params_le
*af_params
)
1655 struct brcmf_p2p_info
*p2p
= &cfg
->p2p
;
1656 struct brcmf_if
*ifp
= netdev_priv(ndev
);
1657 struct brcmf_fil_action_frame_le
*action_frame
;
1658 struct brcmf_config_af_params config_af_params
;
1659 struct afx_hdl
*afx_hdl
= &p2p
->afx_hdl
;
1660 u16 action_frame_len
;
1665 s32 extra_listen_time
;
1668 action_frame
= &af_params
->action_frame
;
1669 action_frame_len
= le16_to_cpu(action_frame
->len
);
1671 brcmf_p2p_print_actframe(true, action_frame
->data
, action_frame_len
);
1673 /* Add the default dwell time. Dwell time to stay off-channel */
1674 /* to wait for a response action frame after transmitting an */
1675 /* GO Negotiation action frame */
1676 af_params
->dwell_time
= cpu_to_le32(P2P_AF_DWELL_TIME
);
1678 category
= action_frame
->data
[DOT11_ACTION_CAT_OFF
];
1679 action
= action_frame
->data
[DOT11_ACTION_ACT_OFF
];
1681 /* initialize variables */
1682 p2p
->next_af_subtype
= P2P_PAF_SUBTYPE_INVALID
;
1683 p2p
->gon_req_action
= false;
1685 /* config parameters */
1686 config_af_params
.mpc_onoff
= -1;
1687 config_af_params
.search_channel
= false;
1688 config_af_params
.extra_listen
= false;
1690 if (brcmf_p2p_is_pub_action(action_frame
->data
, action_frame_len
)) {
1691 /* p2p public action frame process */
1692 if (brcmf_p2p_pub_af_tx(cfg
, af_params
, &config_af_params
)) {
1693 /* Just send unknown subtype frame with */
1694 /* default parameters. */
1695 brcmf_err("P2P Public action frame, unknown subtype.\n");
1697 } else if (brcmf_p2p_is_gas_action(action_frame
->data
,
1698 action_frame_len
)) {
1699 /* service discovery process */
1700 if (action
== P2PSD_ACTION_ID_GAS_IREQ
||
1701 action
== P2PSD_ACTION_ID_GAS_CREQ
) {
1702 /* configure service discovery query frame */
1703 config_af_params
.search_channel
= true;
1705 /* save next af suptype to cancel */
1706 /* remaining dwell time */
1707 p2p
->next_af_subtype
= action
+ 1;
1709 af_params
->dwell_time
=
1710 cpu_to_le32(P2P_AF_MED_DWELL_TIME
);
1711 } else if (action
== P2PSD_ACTION_ID_GAS_IRESP
||
1712 action
== P2PSD_ACTION_ID_GAS_CRESP
) {
1713 /* configure service discovery response frame */
1714 af_params
->dwell_time
=
1715 cpu_to_le32(P2P_AF_MIN_DWELL_TIME
);
1717 brcmf_err("Unknown action type: %d\n", action
);
1720 } else if (brcmf_p2p_is_p2p_action(action_frame
->data
,
1721 action_frame_len
)) {
1722 /* do not configure anything. it will be */
1723 /* sent with a default configuration */
1725 brcmf_err("Unknown Frame: category 0x%x, action 0x%x\n",
1730 /* if connecting on primary iface, sleep for a while before sending
1733 if (test_bit(BRCMF_VIF_STATUS_CONNECTING
,
1734 &p2p
->bss_idx
[P2PAPI_BSSCFG_PRIMARY
].vif
->sme_state
))
1737 /* if scan is ongoing, abort current scan. */
1738 if (test_bit(BRCMF_SCAN_STATUS_BUSY
, &cfg
->scan_status
))
1739 brcmf_abort_scanning(cfg
);
1741 memcpy(afx_hdl
->tx_dst_addr
, action_frame
->da
, ETH_ALEN
);
1743 /* To make sure to send successfully action frame, turn off mpc */
1744 if (config_af_params
.mpc_onoff
== 0)
1745 brcmf_set_mpc(ifp
, 0);
1747 /* set status and destination address before sending af */
1748 if (p2p
->next_af_subtype
!= P2P_PAF_SUBTYPE_INVALID
) {
1749 /* set status to cancel the remained dwell time in rx process */
1750 set_bit(BRCMF_P2P_STATUS_WAITING_NEXT_ACT_FRAME
, &p2p
->status
);
1753 p2p
->af_sent_channel
= 0;
1754 set_bit(BRCMF_P2P_STATUS_SENDING_ACT_FRAME
, &p2p
->status
);
1755 /* validate channel and p2p ies */
1756 if (config_af_params
.search_channel
&&
1757 IS_P2P_SOCIAL_CHANNEL(le32_to_cpu(af_params
->channel
)) &&
1758 p2p
->bss_idx
[P2PAPI_BSSCFG_DEVICE
].vif
->saved_ie
.probe_req_ie_len
) {
1759 afx_hdl
= &p2p
->afx_hdl
;
1760 afx_hdl
->peer_listen_chan
= le32_to_cpu(af_params
->channel
);
1762 if (brcmf_p2p_af_searching_channel(p2p
) ==
1763 P2P_INVALID_CHANNEL
) {
1764 brcmf_err("Couldn't find peer's channel.\n");
1768 /* Abort scan even for VSDB scenarios. Scan gets aborted in
1769 * firmware but after the check of piggyback algorithm. To take
1770 * care of current piggback algo, lets abort the scan here
1773 brcmf_notify_escan_complete(cfg
, ifp
, true, true);
1775 /* update channel */
1776 af_params
->channel
= cpu_to_le32(afx_hdl
->peer_chan
);
1780 while (!p2p
->block_gon_req_tx
&&
1781 (ack
== false) && (tx_retry
< P2P_AF_TX_MAX_RETRY
)) {
1782 ack
= !brcmf_p2p_tx_action_frame(p2p
, af_params
);
1786 brcmf_err("Failed to send Action Frame(retry %d)\n", tx_retry
);
1787 clear_bit(BRCMF_P2P_STATUS_GO_NEG_PHASE
, &p2p
->status
);
1791 clear_bit(BRCMF_P2P_STATUS_SENDING_ACT_FRAME
, &p2p
->status
);
1793 /* WAR: sometimes dongle does not keep the dwell time of 'actframe'.
1794 * if we coundn't get the next action response frame and dongle does
1795 * not keep the dwell time, go to listen state again to get next action
1798 if (ack
&& config_af_params
.extra_listen
&& !p2p
->block_gon_req_tx
&&
1799 test_bit(BRCMF_P2P_STATUS_WAITING_NEXT_ACT_FRAME
, &p2p
->status
) &&
1800 p2p
->af_sent_channel
== afx_hdl
->my_listen_chan
) {
1801 delta_ms
= jiffies_to_msecs(jiffies
- p2p
->af_tx_sent_jiffies
);
1802 if (le32_to_cpu(af_params
->dwell_time
) > delta_ms
)
1803 extra_listen_time
= le32_to_cpu(af_params
->dwell_time
) -
1806 extra_listen_time
= 0;
1807 if (extra_listen_time
> 50) {
1808 set_bit(BRCMF_P2P_STATUS_WAITING_NEXT_AF_LISTEN
,
1810 brcmf_dbg(INFO
, "Wait more time! actual af time:%d, calculated extra listen:%d\n",
1811 le32_to_cpu(af_params
->dwell_time
),
1813 extra_listen_time
+= 100;
1814 if (!brcmf_p2p_discover_listen(p2p
,
1815 p2p
->af_sent_channel
,
1816 extra_listen_time
)) {
1817 unsigned long duration
;
1819 extra_listen_time
+= 100;
1820 duration
= msecs_to_jiffies(extra_listen_time
);
1821 wait_for_completion_timeout(&p2p
->wait_next_af
,
1824 clear_bit(BRCMF_P2P_STATUS_WAITING_NEXT_AF_LISTEN
,
1829 if (p2p
->block_gon_req_tx
) {
1830 /* if ack is true, supplicant will wait more time(100ms).
1831 * so we will return it as a success to get more time .
1833 p2p
->block_gon_req_tx
= false;
1837 clear_bit(BRCMF_P2P_STATUS_WAITING_NEXT_ACT_FRAME
, &p2p
->status
);
1838 /* if all done, turn mpc on again */
1839 if (config_af_params
.mpc_onoff
== 1)
1840 brcmf_set_mpc(ifp
, 1);
1846 * brcmf_p2p_notify_rx_mgmt_p2p_probereq() - Event handler for p2p probe req.
1848 * @ifp: interface pointer for which event was received.
1850 * @data: payload of event message (probe request).
1852 s32
brcmf_p2p_notify_rx_mgmt_p2p_probereq(struct brcmf_if
*ifp
,
1853 const struct brcmf_event_msg
*e
,
1856 struct brcmf_cfg80211_info
*cfg
= ifp
->drvr
->config
;
1857 struct brcmf_p2p_info
*p2p
= &cfg
->p2p
;
1858 struct afx_hdl
*afx_hdl
= &p2p
->afx_hdl
;
1859 struct brcmf_cfg80211_vif
*vif
= ifp
->vif
;
1860 struct brcmf_rx_mgmt_data
*rxframe
= (struct brcmf_rx_mgmt_data
*)data
;
1861 struct brcmu_chan ch
;
1867 brcmf_dbg(INFO
, "Enter: event %d reason %d\n", e
->event_code
,
1870 if (e
->datalen
< sizeof(*rxframe
)) {
1871 brcmf_dbg(SCAN
, "Event data to small. Ignore\n");
1875 ch
.chspec
= be16_to_cpu(rxframe
->chanspec
);
1876 cfg
->d11inf
.decchspec(&ch
);
1878 if (test_bit(BRCMF_P2P_STATUS_FINDING_COMMON_CHANNEL
, &p2p
->status
) &&
1879 (ether_addr_equal(afx_hdl
->tx_dst_addr
, e
->addr
))) {
1880 afx_hdl
->peer_chan
= ch
.control_ch_num
;
1881 brcmf_dbg(INFO
, "PROBE REQUEST: Peer found, channel=%d\n",
1882 afx_hdl
->peer_chan
);
1883 complete(&afx_hdl
->act_frm_scan
);
1886 /* Firmware sends us two proberesponses for each idx one. At the */
1887 /* moment anything but bsscfgidx 0 is passed up to supplicant */
1888 if (e
->bsscfgidx
== 0)
1891 /* Filter any P2P probe reqs arriving during the GO-NEG Phase */
1892 if (test_bit(BRCMF_P2P_STATUS_GO_NEG_PHASE
, &p2p
->status
)) {
1893 brcmf_dbg(INFO
, "Filtering P2P probe_req in GO-NEG phase\n");
1897 /* Check if wpa_supplicant has registered for this frame */
1898 brcmf_dbg(INFO
, "vif->mgmt_rx_reg %04x\n", vif
->mgmt_rx_reg
);
1899 mgmt_type
= (IEEE80211_STYPE_PROBE_REQ
& IEEE80211_FCTL_STYPE
) >> 4;
1900 if ((vif
->mgmt_rx_reg
& BIT(mgmt_type
)) == 0)
1903 mgmt_frame
= (u8
*)(rxframe
+ 1);
1904 mgmt_frame_len
= e
->datalen
- sizeof(*rxframe
);
1905 freq
= ieee80211_channel_to_frequency(ch
.control_ch_num
,
1906 ch
.band
== BRCMU_CHAN_BAND_2G
?
1910 cfg80211_rx_mgmt(&vif
->wdev
, freq
, 0, mgmt_frame
, mgmt_frame_len
, 0);
1912 brcmf_dbg(INFO
, "mgmt_frame_len (%d) , e->datalen (%d), chanspec (%04x), freq (%d)\n",
1913 mgmt_frame_len
, e
->datalen
, ch
.chspec
, freq
);
1920 * brcmf_p2p_get_current_chanspec() - Get current operation channel.
1922 * @p2p: P2P specific data.
1923 * @chanspec: chanspec to be returned.
1925 static void brcmf_p2p_get_current_chanspec(struct brcmf_p2p_info
*p2p
,
1928 struct brcmf_if
*ifp
;
1929 u8 mac_addr
[ETH_ALEN
];
1930 struct brcmu_chan ch
;
1931 struct brcmf_bss_info_le
*bi
;
1934 ifp
= p2p
->bss_idx
[P2PAPI_BSSCFG_PRIMARY
].vif
->ifp
;
1936 if (brcmf_fil_cmd_data_get(ifp
, BRCMF_C_GET_BSSID
, mac_addr
,
1938 buf
= kzalloc(WL_BSS_INFO_MAX
, GFP_KERNEL
);
1940 *(__le32
*)buf
= cpu_to_le32(WL_BSS_INFO_MAX
);
1941 if (brcmf_fil_cmd_data_get(ifp
, BRCMF_C_GET_BSS_INFO
,
1942 buf
, WL_BSS_INFO_MAX
) == 0) {
1943 bi
= (struct brcmf_bss_info_le
*)(buf
+ 4);
1944 *chanspec
= le16_to_cpu(bi
->chanspec
);
1951 /* Use default channel for P2P */
1952 ch
.chnum
= BRCMF_P2P_TEMP_CHAN
;
1953 ch
.bw
= BRCMU_CHAN_BW_20
;
1954 p2p
->cfg
->d11inf
.encchspec(&ch
);
1955 *chanspec
= ch
.chspec
;
1959 * Change a P2P Role.
1961 * @mac: MAC address of the BSS to change a role
1962 * Returns 0 if success.
1964 int brcmf_p2p_ifchange(struct brcmf_cfg80211_info
*cfg
,
1965 enum brcmf_fil_p2p_if_types if_type
)
1967 struct brcmf_p2p_info
*p2p
= &cfg
->p2p
;
1968 struct brcmf_cfg80211_vif
*vif
;
1969 struct brcmf_fil_p2p_if_le if_request
;
1973 brcmf_dbg(TRACE
, "Enter\n");
1975 vif
= p2p
->bss_idx
[P2PAPI_BSSCFG_PRIMARY
].vif
;
1977 brcmf_err("vif for P2PAPI_BSSCFG_PRIMARY does not exist\n");
1980 brcmf_notify_escan_complete(cfg
, vif
->ifp
, true, true);
1981 vif
= p2p
->bss_idx
[P2PAPI_BSSCFG_CONNECTION
].vif
;
1983 brcmf_err("vif for P2PAPI_BSSCFG_CONNECTION does not exist\n");
1986 brcmf_set_mpc(vif
->ifp
, 0);
1988 /* In concurrency case, STA may be already associated in a particular */
1989 /* channel. so retrieve the current channel of primary interface and */
1990 /* then start the virtual interface on that. */
1991 brcmf_p2p_get_current_chanspec(p2p
, &chanspec
);
1993 if_request
.type
= cpu_to_le16((u16
)if_type
);
1994 if_request
.chspec
= cpu_to_le16(chanspec
);
1995 memcpy(if_request
.addr
, p2p
->int_addr
, sizeof(if_request
.addr
));
1997 brcmf_cfg80211_arm_vif_event(cfg
, vif
);
1998 err
= brcmf_fil_iovar_data_set(vif
->ifp
, "p2p_ifupd", &if_request
,
1999 sizeof(if_request
));
2001 brcmf_err("p2p_ifupd FAILED, err=%d\n", err
);
2002 brcmf_cfg80211_arm_vif_event(cfg
, NULL
);
2005 err
= brcmf_cfg80211_wait_vif_event(cfg
, BRCMF_E_IF_CHANGE
,
2006 BRCMF_VIF_EVENT_TIMEOUT
);
2007 brcmf_cfg80211_arm_vif_event(cfg
, NULL
);
2009 brcmf_err("No BRCMF_E_IF_CHANGE event received\n");
2013 err
= brcmf_fil_cmd_int_set(vif
->ifp
, BRCMF_C_SET_SCB_TIMEOUT
,
2014 BRCMF_SCB_TIMEOUT_VALUE
);
2019 static int brcmf_p2p_request_p2p_if(struct brcmf_p2p_info
*p2p
,
2020 struct brcmf_if
*ifp
, u8 ea
[ETH_ALEN
],
2021 enum brcmf_fil_p2p_if_types iftype
)
2023 struct brcmf_fil_p2p_if_le if_request
;
2027 /* we need a default channel */
2028 brcmf_p2p_get_current_chanspec(p2p
, &chanspec
);
2030 /* fill the firmware request */
2031 memcpy(if_request
.addr
, ea
, ETH_ALEN
);
2032 if_request
.type
= cpu_to_le16((u16
)iftype
);
2033 if_request
.chspec
= cpu_to_le16(chanspec
);
2035 err
= brcmf_fil_iovar_data_set(ifp
, "p2p_ifadd", &if_request
,
2036 sizeof(if_request
));
2041 static int brcmf_p2p_disable_p2p_if(struct brcmf_cfg80211_vif
*vif
)
2043 struct brcmf_cfg80211_info
*cfg
= wdev_to_cfg(&vif
->wdev
);
2044 struct net_device
*pri_ndev
= cfg_to_ndev(cfg
);
2045 struct brcmf_if
*ifp
= netdev_priv(pri_ndev
);
2046 u8
*addr
= vif
->wdev
.netdev
->dev_addr
;
2048 return brcmf_fil_iovar_data_set(ifp
, "p2p_ifdis", addr
, ETH_ALEN
);
2051 static int brcmf_p2p_release_p2p_if(struct brcmf_cfg80211_vif
*vif
)
2053 struct brcmf_cfg80211_info
*cfg
= wdev_to_cfg(&vif
->wdev
);
2054 struct net_device
*pri_ndev
= cfg_to_ndev(cfg
);
2055 struct brcmf_if
*ifp
= netdev_priv(pri_ndev
);
2056 u8
*addr
= vif
->wdev
.netdev
->dev_addr
;
2058 return brcmf_fil_iovar_data_set(ifp
, "p2p_ifdel", addr
, ETH_ALEN
);
2062 * brcmf_p2p_create_p2pdev() - create a P2P_DEVICE virtual interface.
2064 * @p2p: P2P specific data.
2065 * @wiphy: wiphy device of new interface.
2066 * @addr: mac address for this new interface.
2068 static struct wireless_dev
*brcmf_p2p_create_p2pdev(struct brcmf_p2p_info
*p2p
,
2069 struct wiphy
*wiphy
,
2072 struct brcmf_cfg80211_vif
*p2p_vif
;
2073 struct brcmf_if
*p2p_ifp
;
2074 struct brcmf_if
*pri_ifp
;
2078 if (p2p
->bss_idx
[P2PAPI_BSSCFG_DEVICE
].vif
)
2079 return ERR_PTR(-ENOSPC
);
2081 p2p_vif
= brcmf_alloc_vif(p2p
->cfg
, NL80211_IFTYPE_P2P_DEVICE
);
2082 if (IS_ERR(p2p_vif
)) {
2083 brcmf_err("could not create discovery vif\n");
2084 return (struct wireless_dev
*)p2p_vif
;
2087 pri_ifp
= p2p
->bss_idx
[P2PAPI_BSSCFG_PRIMARY
].vif
->ifp
;
2089 /* firmware requires unique mac address for p2pdev interface */
2090 if (addr
&& ether_addr_equal(addr
, pri_ifp
->mac_addr
)) {
2091 brcmf_err("discovery vif must be different from primary interface\n");
2092 return ERR_PTR(-EINVAL
);
2095 brcmf_p2p_generate_bss_mac(p2p
, addr
);
2096 brcmf_p2p_set_firmware(pri_ifp
, p2p
->dev_addr
);
2098 brcmf_cfg80211_arm_vif_event(p2p
->cfg
, p2p_vif
);
2099 brcmf_fweh_p2pdev_setup(pri_ifp
, true);
2101 /* Initialize P2P Discovery in the firmware */
2102 err
= brcmf_fil_iovar_int_set(pri_ifp
, "p2p_disc", 1);
2104 brcmf_err("set p2p_disc error\n");
2105 brcmf_fweh_p2pdev_setup(pri_ifp
, false);
2106 brcmf_cfg80211_arm_vif_event(p2p
->cfg
, NULL
);
2110 /* wait for firmware event */
2111 err
= brcmf_cfg80211_wait_vif_event(p2p
->cfg
, BRCMF_E_IF_ADD
,
2112 BRCMF_VIF_EVENT_TIMEOUT
);
2113 brcmf_cfg80211_arm_vif_event(p2p
->cfg
, NULL
);
2114 brcmf_fweh_p2pdev_setup(pri_ifp
, false);
2116 brcmf_err("timeout occurred\n");
2121 /* discovery interface created */
2122 p2p_ifp
= p2p_vif
->ifp
;
2123 p2p
->bss_idx
[P2PAPI_BSSCFG_DEVICE
].vif
= p2p_vif
;
2124 memcpy(p2p_ifp
->mac_addr
, p2p
->dev_addr
, ETH_ALEN
);
2125 memcpy(&p2p_vif
->wdev
.address
, p2p
->dev_addr
, sizeof(p2p
->dev_addr
));
2127 /* verify bsscfg index for P2P discovery */
2128 err
= brcmf_fil_iovar_int_get(pri_ifp
, "p2p_dev", &bsscfgidx
);
2130 brcmf_err("retrieving discover bsscfg index failed\n");
2134 WARN_ON(p2p_ifp
->bsscfgidx
!= bsscfgidx
);
2136 init_completion(&p2p
->send_af_done
);
2137 INIT_WORK(&p2p
->afx_hdl
.afx_work
, brcmf_p2p_afx_handler
);
2138 init_completion(&p2p
->afx_hdl
.act_frm_scan
);
2139 init_completion(&p2p
->wait_next_af
);
2141 return &p2p_vif
->wdev
;
2144 brcmf_free_vif(p2p_vif
);
2145 return ERR_PTR(err
);
2149 * brcmf_p2p_add_vif() - create a new P2P virtual interface.
2151 * @wiphy: wiphy device of new interface.
2152 * @name: name of the new interface.
2153 * @name_assign_type: origin of the interface name
2154 * @type: nl80211 interface type.
2155 * @params: contains mac address for P2P device.
2157 struct wireless_dev
*brcmf_p2p_add_vif(struct wiphy
*wiphy
, const char *name
,
2158 unsigned char name_assign_type
,
2159 enum nl80211_iftype type
,
2160 struct vif_params
*params
)
2162 struct brcmf_cfg80211_info
*cfg
= wiphy_to_cfg(wiphy
);
2163 struct brcmf_if
*ifp
= netdev_priv(cfg_to_ndev(cfg
));
2164 struct brcmf_cfg80211_vif
*vif
;
2165 enum brcmf_fil_p2p_if_types iftype
;
2168 if (brcmf_cfg80211_vif_event_armed(cfg
))
2169 return ERR_PTR(-EBUSY
);
2171 brcmf_dbg(INFO
, "adding vif \"%s\" (type=%d)\n", name
, type
);
2174 case NL80211_IFTYPE_P2P_CLIENT
:
2175 iftype
= BRCMF_FIL_P2P_IF_CLIENT
;
2177 case NL80211_IFTYPE_P2P_GO
:
2178 iftype
= BRCMF_FIL_P2P_IF_GO
;
2180 case NL80211_IFTYPE_P2P_DEVICE
:
2181 return brcmf_p2p_create_p2pdev(&cfg
->p2p
, wiphy
,
2184 return ERR_PTR(-EOPNOTSUPP
);
2187 vif
= brcmf_alloc_vif(cfg
, type
);
2189 return (struct wireless_dev
*)vif
;
2190 brcmf_cfg80211_arm_vif_event(cfg
, vif
);
2192 err
= brcmf_p2p_request_p2p_if(&cfg
->p2p
, ifp
, cfg
->p2p
.int_addr
,
2195 brcmf_cfg80211_arm_vif_event(cfg
, NULL
);
2199 /* wait for firmware event */
2200 err
= brcmf_cfg80211_wait_vif_event(cfg
, BRCMF_E_IF_ADD
,
2201 BRCMF_VIF_EVENT_TIMEOUT
);
2202 brcmf_cfg80211_arm_vif_event(cfg
, NULL
);
2204 brcmf_err("timeout occurred\n");
2209 /* interface created in firmware */
2212 brcmf_err("no if pointer provided\n");
2217 strncpy(ifp
->ndev
->name
, name
, sizeof(ifp
->ndev
->name
) - 1);
2218 ifp
->ndev
->name_assign_type
= name_assign_type
;
2219 err
= brcmf_net_attach(ifp
, true);
2221 brcmf_err("Registering netdevice failed\n");
2222 free_netdev(ifp
->ndev
);
2226 cfg
->p2p
.bss_idx
[P2PAPI_BSSCFG_CONNECTION
].vif
= vif
;
2227 /* Disable firmware roaming for P2P interface */
2228 brcmf_fil_iovar_int_set(ifp
, "roam_off", 1);
2229 if (iftype
== BRCMF_FIL_P2P_IF_GO
) {
2230 /* set station timeout for p2p */
2231 brcmf_fil_cmd_int_set(ifp
, BRCMF_C_SET_SCB_TIMEOUT
,
2232 BRCMF_SCB_TIMEOUT_VALUE
);
2234 return &ifp
->vif
->wdev
;
2237 brcmf_free_vif(vif
);
2238 return ERR_PTR(err
);
2242 * brcmf_p2p_del_vif() - delete a P2P virtual interface.
2244 * @wiphy: wiphy device of interface.
2245 * @wdev: wireless device of interface.
2247 int brcmf_p2p_del_vif(struct wiphy
*wiphy
, struct wireless_dev
*wdev
)
2249 struct brcmf_cfg80211_info
*cfg
= wiphy_to_cfg(wiphy
);
2250 struct brcmf_p2p_info
*p2p
= &cfg
->p2p
;
2251 struct brcmf_cfg80211_vif
*vif
;
2252 enum nl80211_iftype iftype
;
2253 bool wait_for_disable
= false;
2256 brcmf_dbg(TRACE
, "delete P2P vif\n");
2257 vif
= container_of(wdev
, struct brcmf_cfg80211_vif
, wdev
);
2259 iftype
= vif
->wdev
.iftype
;
2260 brcmf_cfg80211_arm_vif_event(cfg
, vif
);
2262 case NL80211_IFTYPE_P2P_CLIENT
:
2263 if (test_bit(BRCMF_VIF_STATUS_DISCONNECTING
, &vif
->sme_state
))
2264 wait_for_disable
= true;
2267 case NL80211_IFTYPE_P2P_GO
:
2268 if (!brcmf_p2p_disable_p2p_if(vif
))
2269 wait_for_disable
= true;
2272 case NL80211_IFTYPE_P2P_DEVICE
:
2273 if (!p2p
->bss_idx
[P2PAPI_BSSCFG_DEVICE
].vif
)
2275 brcmf_p2p_cancel_remain_on_channel(vif
->ifp
);
2276 brcmf_p2p_deinit_discovery(p2p
);
2283 clear_bit(BRCMF_P2P_STATUS_GO_NEG_PHASE
, &p2p
->status
);
2284 brcmf_dbg(INFO
, "P2P: GO_NEG_PHASE status cleared\n");
2286 if (wait_for_disable
)
2287 wait_for_completion_timeout(&cfg
->vif_disabled
,
2288 BRCMF_P2P_DISABLE_TIMEOUT
);
2291 if (iftype
!= NL80211_IFTYPE_P2P_DEVICE
) {
2292 brcmf_vif_clear_mgmt_ies(vif
);
2293 err
= brcmf_p2p_release_p2p_if(vif
);
2296 /* wait for firmware event */
2297 err
= brcmf_cfg80211_wait_vif_event(cfg
, BRCMF_E_IF_DEL
,
2298 BRCMF_VIF_EVENT_TIMEOUT
);
2304 brcmf_remove_interface(vif
->ifp
, true);
2306 brcmf_cfg80211_arm_vif_event(cfg
, NULL
);
2307 if (iftype
!= NL80211_IFTYPE_P2P_DEVICE
)
2308 p2p
->bss_idx
[P2PAPI_BSSCFG_CONNECTION
].vif
= NULL
;
2313 void brcmf_p2p_ifp_removed(struct brcmf_if
*ifp
, bool rtnl_locked
)
2315 struct brcmf_cfg80211_info
*cfg
;
2316 struct brcmf_cfg80211_vif
*vif
;
2318 brcmf_dbg(INFO
, "P2P: device interface removed\n");
2320 cfg
= wdev_to_cfg(&vif
->wdev
);
2321 cfg
->p2p
.bss_idx
[P2PAPI_BSSCFG_DEVICE
].vif
= NULL
;
2324 cfg80211_unregister_wdev(&vif
->wdev
);
2327 brcmf_free_vif(vif
);
2330 int brcmf_p2p_start_device(struct wiphy
*wiphy
, struct wireless_dev
*wdev
)
2332 struct brcmf_cfg80211_info
*cfg
= wiphy_to_cfg(wiphy
);
2333 struct brcmf_p2p_info
*p2p
= &cfg
->p2p
;
2334 struct brcmf_cfg80211_vif
*vif
;
2337 vif
= container_of(wdev
, struct brcmf_cfg80211_vif
, wdev
);
2338 mutex_lock(&cfg
->usr_sync
);
2339 err
= brcmf_p2p_enable_discovery(p2p
);
2341 set_bit(BRCMF_VIF_STATUS_READY
, &vif
->sme_state
);
2342 mutex_unlock(&cfg
->usr_sync
);
2346 void brcmf_p2p_stop_device(struct wiphy
*wiphy
, struct wireless_dev
*wdev
)
2348 struct brcmf_cfg80211_info
*cfg
= wiphy_to_cfg(wiphy
);
2349 struct brcmf_p2p_info
*p2p
= &cfg
->p2p
;
2350 struct brcmf_cfg80211_vif
*vif
;
2352 vif
= container_of(wdev
, struct brcmf_cfg80211_vif
, wdev
);
2353 /* This call can be result of the unregister_wdev call. In that case
2354 * we dont want to do anything anymore. Just return. The config vif
2355 * will have been cleared at this point.
2357 if (p2p
->bss_idx
[P2PAPI_BSSCFG_DEVICE
].vif
== vif
) {
2358 mutex_lock(&cfg
->usr_sync
);
2359 /* Set the discovery state to SCAN */
2360 (void)brcmf_p2p_set_discover_state(vif
->ifp
,
2361 WL_P2P_DISC_ST_SCAN
, 0, 0);
2362 brcmf_abort_scanning(cfg
);
2363 clear_bit(BRCMF_VIF_STATUS_READY
, &vif
->sme_state
);
2364 mutex_unlock(&cfg
->usr_sync
);
2369 * brcmf_p2p_attach() - attach for P2P.
2371 * @cfg: driver private data for cfg80211 interface.
2372 * @p2pdev_forced: create p2p device interface at attach.
2374 s32
brcmf_p2p_attach(struct brcmf_cfg80211_info
*cfg
, bool p2pdev_forced
)
2376 struct brcmf_p2p_info
*p2p
;
2377 struct brcmf_if
*pri_ifp
;
2384 pri_ifp
= brcmf_get_ifp(cfg
->pub
, 0);
2385 p2p
->bss_idx
[P2PAPI_BSSCFG_PRIMARY
].vif
= pri_ifp
->vif
;
2387 if (p2pdev_forced
) {
2388 err_ptr
= brcmf_p2p_create_p2pdev(p2p
, NULL
, NULL
);
2389 if (IS_ERR(err_ptr
)) {
2390 brcmf_err("P2P device creation failed.\n");
2391 err
= PTR_ERR(err_ptr
);
2394 p2p
->p2pdev_dynamically
= true;
2400 * brcmf_p2p_detach() - detach P2P.
2402 * @p2p: P2P specific data.
2404 void brcmf_p2p_detach(struct brcmf_p2p_info
*p2p
)
2406 struct brcmf_cfg80211_vif
*vif
;
2408 vif
= p2p
->bss_idx
[P2PAPI_BSSCFG_DEVICE
].vif
;
2410 brcmf_p2p_cancel_remain_on_channel(vif
->ifp
);
2411 brcmf_p2p_deinit_discovery(p2p
);
2412 brcmf_remove_interface(vif
->ifp
, false);
2414 /* just set it all to zero */
2415 memset(p2p
, 0, sizeof(*p2p
));