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(1500)
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 the primary net device, ie.
466 * the permanent ethernet address of the device.
468 static void brcmf_p2p_generate_bss_mac(struct brcmf_p2p_info
*p2p
, u8
*dev_addr
)
470 struct brcmf_if
*pri_ifp
= p2p
->bss_idx
[P2PAPI_BSSCFG_PRIMARY
].vif
->ifp
;
471 bool local_admin
= false;
473 if (!dev_addr
|| is_zero_ether_addr(dev_addr
)) {
474 dev_addr
= pri_ifp
->mac_addr
;
478 /* Generate the P2P Device Address. This consists of the device's
479 * primary MAC address with the locally administered bit set.
481 memcpy(p2p
->dev_addr
, dev_addr
, ETH_ALEN
);
483 p2p
->dev_addr
[0] |= 0x02;
485 /* Generate the P2P Interface Address. If the discovery and connection
486 * BSSCFGs need to simultaneously co-exist, then this address must be
487 * different from the P2P Device Address, but also locally administered.
489 memcpy(p2p
->int_addr
, p2p
->dev_addr
, ETH_ALEN
);
490 p2p
->int_addr
[0] |= 0x02;
491 p2p
->int_addr
[4] ^= 0x80;
495 * brcmf_p2p_scan_is_p2p_request() - is cfg80211 scan request a P2P scan.
497 * @request: the scan request as received from cfg80211.
499 * returns true if one of the ssids in the request matches the
500 * P2P wildcard ssid; otherwise returns false.
502 static bool brcmf_p2p_scan_is_p2p_request(struct cfg80211_scan_request
*request
)
504 struct cfg80211_ssid
*ssids
= request
->ssids
;
507 for (i
= 0; i
< request
->n_ssids
; i
++) {
508 if (ssids
[i
].ssid_len
!= BRCMF_P2P_WILDCARD_SSID_LEN
)
511 brcmf_dbg(INFO
, "comparing ssid \"%s\"", ssids
[i
].ssid
);
512 if (!memcmp(BRCMF_P2P_WILDCARD_SSID
, ssids
[i
].ssid
,
513 BRCMF_P2P_WILDCARD_SSID_LEN
))
520 * brcmf_p2p_set_discover_state - set discover state in firmware.
522 * @ifp: low-level interface object.
523 * @state: discover state to set.
524 * @chanspec: channel parameters (for state @WL_P2P_DISC_ST_LISTEN only).
525 * @listen_ms: duration to listen (for state @WL_P2P_DISC_ST_LISTEN only).
527 static s32
brcmf_p2p_set_discover_state(struct brcmf_if
*ifp
, u8 state
,
528 u16 chanspec
, u16 listen_ms
)
530 struct brcmf_p2p_disc_st_le discover_state
;
532 brcmf_dbg(TRACE
, "enter\n");
534 discover_state
.state
= state
;
535 discover_state
.chspec
= cpu_to_le16(chanspec
);
536 discover_state
.dwell
= cpu_to_le16(listen_ms
);
537 ret
= brcmf_fil_bsscfg_data_set(ifp
, "p2p_state", &discover_state
,
538 sizeof(discover_state
));
543 * brcmf_p2p_deinit_discovery() - disable P2P device discovery.
545 * @p2p: P2P specific data.
547 * Resets the discovery state and disables it in firmware.
549 static s32
brcmf_p2p_deinit_discovery(struct brcmf_p2p_info
*p2p
)
551 struct brcmf_cfg80211_vif
*vif
;
553 brcmf_dbg(TRACE
, "enter\n");
555 /* Set the discovery state to SCAN */
556 vif
= p2p
->bss_idx
[P2PAPI_BSSCFG_DEVICE
].vif
;
557 (void)brcmf_p2p_set_discover_state(vif
->ifp
, WL_P2P_DISC_ST_SCAN
, 0, 0);
559 /* Disable P2P discovery in the firmware */
560 vif
= p2p
->bss_idx
[P2PAPI_BSSCFG_PRIMARY
].vif
;
561 (void)brcmf_fil_iovar_int_set(vif
->ifp
, "p2p_disc", 0);
567 * brcmf_p2p_enable_discovery() - initialize and configure discovery.
569 * @p2p: P2P specific data.
571 * Initializes the discovery device and configure the virtual interface.
573 static int brcmf_p2p_enable_discovery(struct brcmf_p2p_info
*p2p
)
575 struct brcmf_cfg80211_vif
*vif
;
578 brcmf_dbg(TRACE
, "enter\n");
579 vif
= p2p
->bss_idx
[P2PAPI_BSSCFG_DEVICE
].vif
;
581 brcmf_err("P2P config device not available\n");
586 if (test_bit(BRCMF_P2P_STATUS_ENABLED
, &p2p
->status
)) {
587 brcmf_dbg(INFO
, "P2P config device already configured\n");
591 /* Re-initialize P2P Discovery in the firmware */
592 vif
= p2p
->bss_idx
[P2PAPI_BSSCFG_PRIMARY
].vif
;
593 ret
= brcmf_fil_iovar_int_set(vif
->ifp
, "p2p_disc", 1);
595 brcmf_err("set p2p_disc error\n");
598 vif
= p2p
->bss_idx
[P2PAPI_BSSCFG_DEVICE
].vif
;
599 ret
= brcmf_p2p_set_discover_state(vif
->ifp
, WL_P2P_DISC_ST_SCAN
, 0, 0);
601 brcmf_err("unable to set WL_P2P_DISC_ST_SCAN\n");
606 * Set wsec to any non-zero value in the discovery bsscfg
607 * to ensure our P2P probe responses have the privacy bit
608 * set in the 802.11 WPA IE. Some peer devices may not
609 * initiate WPS with us if this bit is not set.
611 ret
= brcmf_fil_bsscfg_int_set(vif
->ifp
, "wsec", AES_ENABLED
);
613 brcmf_err("wsec error %d\n", ret
);
617 set_bit(BRCMF_P2P_STATUS_ENABLED
, &p2p
->status
);
623 * brcmf_p2p_escan() - initiate a P2P scan.
625 * @p2p: P2P specific data.
626 * @num_chans: number of channels to scan.
627 * @chanspecs: channel parameters for @num_chans channels.
628 * @search_state: P2P discover state to use.
629 * @bss_type: type of P2P bss.
631 static s32
brcmf_p2p_escan(struct brcmf_p2p_info
*p2p
, u32 num_chans
,
632 u16 chanspecs
[], s32 search_state
,
633 enum p2p_bss_type bss_type
)
636 s32 memsize
= offsetof(struct brcmf_p2p_scan_le
,
637 eparams
.params_le
.channel_list
);
642 struct brcmf_cfg80211_vif
*vif
;
643 struct brcmf_p2p_scan_le
*p2p_params
;
644 struct brcmf_scan_params_le
*sparams
;
646 memsize
+= num_chans
* sizeof(__le16
);
647 memblk
= kzalloc(memsize
, GFP_KERNEL
);
651 vif
= p2p
->bss_idx
[bss_type
].vif
;
653 brcmf_err("no vif for bss type %d\n", bss_type
);
657 p2p_params
= (struct brcmf_p2p_scan_le
*)memblk
;
658 sparams
= &p2p_params
->eparams
.params_le
;
660 switch (search_state
) {
661 case WL_P2P_DISC_ST_SEARCH
:
663 * If we in SEARCH STATE, we don't need to set SSID explictly
664 * because dongle use P2P WILDCARD internally by default, use
665 * null ssid, which it is already due to kzalloc.
668 case WL_P2P_DISC_ST_SCAN
:
670 * wpa_supplicant has p2p_find command with type social or
671 * progressive. For progressive, we need to set the ssid to
672 * P2P WILDCARD because we just do broadcast scan unless
675 sparams
->ssid_le
.SSID_len
=
676 cpu_to_le32(BRCMF_P2P_WILDCARD_SSID_LEN
);
677 memcpy(sparams
->ssid_le
.SSID
, BRCMF_P2P_WILDCARD_SSID
,
678 BRCMF_P2P_WILDCARD_SSID_LEN
);
681 brcmf_err(" invalid search state %d\n", search_state
);
686 brcmf_p2p_set_discover_state(vif
->ifp
, search_state
, 0, 0);
689 * set p2p scan parameters.
691 p2p_params
->type
= 'E';
693 /* determine the scan engine parameters */
694 sparams
->bss_type
= DOT11_BSSTYPE_ANY
;
695 if (p2p
->cfg
->active_scan
)
696 sparams
->scan_type
= 0;
698 sparams
->scan_type
= 1;
700 eth_broadcast_addr(sparams
->bssid
);
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 (brcmf_get_vif_state_any(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(WL_ESCAN_ACTION_START
);
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
)
767 struct brcmf_p2p_info
*p2p
= &cfg
->p2p
;
769 s32 search_state
= WL_P2P_DISC_ST_SCAN
;
770 struct brcmf_cfg80211_vif
*vif
;
771 struct net_device
*dev
= NULL
;
772 int i
, num_nodfs
= 0;
775 brcmf_dbg(TRACE
, "enter\n");
782 if (request
->n_channels
) {
783 chanspecs
= kcalloc(request
->n_channels
, sizeof(*chanspecs
),
789 vif
= p2p
->bss_idx
[P2PAPI_BSSCFG_CONNECTION
].vif
;
791 dev
= vif
->wdev
.netdev
;
792 if (request
->n_channels
== 3 &&
793 request
->channels
[0]->hw_value
== SOCIAL_CHAN_1
&&
794 request
->channels
[1]->hw_value
== SOCIAL_CHAN_2
&&
795 request
->channels
[2]->hw_value
== SOCIAL_CHAN_3
) {
796 /* SOCIAL CHANNELS 1, 6, 11 */
797 search_state
= WL_P2P_DISC_ST_SEARCH
;
798 brcmf_dbg(INFO
, "P2P SEARCH PHASE START\n");
799 } else if (dev
!= NULL
&&
800 vif
->wdev
.iftype
== NL80211_IFTYPE_P2P_GO
) {
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_NO_IR
))
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 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
, P2PAPI_BSSCFG_DEVICE
);
1095 kfree(default_chan_list
);
1102 * brcmf_p2p_afx_handler() - afx worker thread.
1107 static void brcmf_p2p_afx_handler(struct work_struct
*work
)
1109 struct afx_hdl
*afx_hdl
= container_of(work
, struct afx_hdl
, afx_work
);
1110 struct brcmf_p2p_info
*p2p
= container_of(afx_hdl
,
1111 struct brcmf_p2p_info
,
1115 if (!afx_hdl
->is_active
)
1118 if (afx_hdl
->is_listen
&& afx_hdl
->my_listen_chan
)
1120 err
= brcmf_p2p_discover_listen(p2p
, afx_hdl
->my_listen_chan
,
1121 100 * (1 + prandom_u32() % 3));
1123 err
= brcmf_p2p_act_frm_search(p2p
, afx_hdl
->peer_listen_chan
);
1126 brcmf_err("ERROR occurred! value is (%d)\n", err
);
1127 if (test_bit(BRCMF_P2P_STATUS_FINDING_COMMON_CHANNEL
,
1129 complete(&afx_hdl
->act_frm_scan
);
1135 * brcmf_p2p_af_searching_channel() - search channel.
1137 * @p2p: p2p device info struct.
1140 static s32
brcmf_p2p_af_searching_channel(struct brcmf_p2p_info
*p2p
)
1142 struct afx_hdl
*afx_hdl
= &p2p
->afx_hdl
;
1143 struct brcmf_cfg80211_vif
*pri_vif
;
1144 unsigned long duration
;
1147 brcmf_dbg(TRACE
, "Enter\n");
1149 pri_vif
= p2p
->bss_idx
[P2PAPI_BSSCFG_PRIMARY
].vif
;
1151 reinit_completion(&afx_hdl
->act_frm_scan
);
1152 set_bit(BRCMF_P2P_STATUS_FINDING_COMMON_CHANNEL
, &p2p
->status
);
1153 afx_hdl
->is_active
= true;
1154 afx_hdl
->peer_chan
= P2P_INVALID_CHANNEL
;
1156 /* Loop to wait until we find a peer's channel or the
1157 * pending action frame tx is cancelled.
1160 duration
= msecs_to_jiffies(P2P_AF_FRM_SCAN_MAX_WAIT
);
1161 while ((retry
< P2P_CHANNEL_SYNC_RETRY
) &&
1162 (afx_hdl
->peer_chan
== P2P_INVALID_CHANNEL
)) {
1163 afx_hdl
->is_listen
= false;
1164 brcmf_dbg(TRACE
, "Scheduling action frame for sending.. (%d)\n",
1166 /* search peer on peer's listen channel */
1167 schedule_work(&afx_hdl
->afx_work
);
1168 wait_for_completion_timeout(&afx_hdl
->act_frm_scan
, duration
);
1169 if ((afx_hdl
->peer_chan
!= P2P_INVALID_CHANNEL
) ||
1170 (!test_bit(BRCMF_P2P_STATUS_FINDING_COMMON_CHANNEL
,
1174 if (afx_hdl
->my_listen_chan
) {
1175 brcmf_dbg(TRACE
, "Scheduling listen peer, channel=%d\n",
1176 afx_hdl
->my_listen_chan
);
1177 /* listen on my listen channel */
1178 afx_hdl
->is_listen
= true;
1179 schedule_work(&afx_hdl
->afx_work
);
1180 wait_for_completion_timeout(&afx_hdl
->act_frm_scan
,
1183 if ((afx_hdl
->peer_chan
!= P2P_INVALID_CHANNEL
) ||
1184 (!test_bit(BRCMF_P2P_STATUS_FINDING_COMMON_CHANNEL
,
1189 /* if sta is connected or connecting, sleep for a while before
1190 * retry af tx or finding a peer
1192 if (test_bit(BRCMF_VIF_STATUS_CONNECTED
, &pri_vif
->sme_state
) ||
1193 test_bit(BRCMF_VIF_STATUS_CONNECTING
, &pri_vif
->sme_state
))
1194 msleep(P2P_DEFAULT_SLEEP_TIME_VSDB
);
1197 brcmf_dbg(TRACE
, "Completed search/listen peer_chan=%d\n",
1198 afx_hdl
->peer_chan
);
1199 afx_hdl
->is_active
= false;
1201 clear_bit(BRCMF_P2P_STATUS_FINDING_COMMON_CHANNEL
, &p2p
->status
);
1203 return afx_hdl
->peer_chan
;
1208 * brcmf_p2p_scan_finding_common_channel() - was escan used for finding channel
1210 * @cfg: common configuration struct.
1211 * @bi: bss info struct, result from scan.
1214 bool brcmf_p2p_scan_finding_common_channel(struct brcmf_cfg80211_info
*cfg
,
1215 struct brcmf_bss_info_le
*bi
)
1218 struct brcmf_p2p_info
*p2p
= &cfg
->p2p
;
1219 struct afx_hdl
*afx_hdl
= &p2p
->afx_hdl
;
1220 struct brcmu_chan ch
;
1223 u8 p2p_dev_addr
[ETH_ALEN
];
1225 if (!test_bit(BRCMF_P2P_STATUS_FINDING_COMMON_CHANNEL
, &p2p
->status
))
1229 brcmf_dbg(TRACE
, "ACTION FRAME SCAN Done\n");
1230 if (afx_hdl
->peer_chan
== P2P_INVALID_CHANNEL
)
1231 complete(&afx_hdl
->act_frm_scan
);
1235 ie
= ((u8
*)bi
) + le16_to_cpu(bi
->ie_offset
);
1236 memset(p2p_dev_addr
, 0, sizeof(p2p_dev_addr
));
1237 err
= cfg80211_get_p2p_attr(ie
, le32_to_cpu(bi
->ie_length
),
1238 IEEE80211_P2P_ATTR_DEVICE_INFO
,
1239 p2p_dev_addr
, sizeof(p2p_dev_addr
));
1241 err
= cfg80211_get_p2p_attr(ie
, le32_to_cpu(bi
->ie_length
),
1242 IEEE80211_P2P_ATTR_DEVICE_ID
,
1243 p2p_dev_addr
, sizeof(p2p_dev_addr
));
1245 (ether_addr_equal(p2p_dev_addr
, afx_hdl
->tx_dst_addr
))) {
1247 ch
.chspec
= le16_to_cpu(bi
->chanspec
);
1248 cfg
->d11inf
.decchspec(&ch
);
1249 bi
->ctl_ch
= ch
.control_ch_num
;
1251 afx_hdl
->peer_chan
= bi
->ctl_ch
;
1252 brcmf_dbg(TRACE
, "ACTION FRAME SCAN : Peer %pM found, channel : %d\n",
1253 afx_hdl
->tx_dst_addr
, afx_hdl
->peer_chan
);
1254 complete(&afx_hdl
->act_frm_scan
);
1260 * brcmf_p2p_stop_wait_next_action_frame() - finish scan if af tx complete.
1262 * @cfg: common configuration struct.
1266 brcmf_p2p_stop_wait_next_action_frame(struct brcmf_cfg80211_info
*cfg
)
1268 struct brcmf_p2p_info
*p2p
= &cfg
->p2p
;
1269 struct brcmf_if
*ifp
= p2p
->bss_idx
[P2PAPI_BSSCFG_PRIMARY
].vif
->ifp
;
1271 if (test_bit(BRCMF_P2P_STATUS_SENDING_ACT_FRAME
, &p2p
->status
) &&
1272 (test_bit(BRCMF_P2P_STATUS_ACTION_TX_COMPLETED
, &p2p
->status
) ||
1273 test_bit(BRCMF_P2P_STATUS_ACTION_TX_NOACK
, &p2p
->status
))) {
1274 brcmf_dbg(TRACE
, "*** Wake UP ** abort actframe iovar\n");
1275 /* if channel is not zero, "actfame" uses off channel scan.
1276 * So abort scan for off channel completion.
1278 if (p2p
->af_sent_channel
)
1279 brcmf_notify_escan_complete(cfg
, ifp
, true, true);
1280 } else if (test_bit(BRCMF_P2P_STATUS_WAITING_NEXT_AF_LISTEN
,
1282 brcmf_dbg(TRACE
, "*** Wake UP ** abort listen for next af frame\n");
1283 /* So abort scan to cancel listen */
1284 brcmf_notify_escan_complete(cfg
, ifp
, true, true);
1290 * brcmf_p2p_gon_req_collision() - Check if go negotiaton collission
1292 * @p2p: p2p device info struct.
1294 * return true if recevied action frame is to be dropped.
1297 brcmf_p2p_gon_req_collision(struct brcmf_p2p_info
*p2p
, u8
*mac
)
1299 struct brcmf_cfg80211_info
*cfg
= p2p
->cfg
;
1300 struct brcmf_if
*ifp
;
1302 brcmf_dbg(TRACE
, "Enter\n");
1304 if (!test_bit(BRCMF_P2P_STATUS_WAITING_NEXT_ACT_FRAME
, &p2p
->status
) ||
1305 !p2p
->gon_req_action
)
1308 brcmf_dbg(TRACE
, "GO Negotiation Request COLLISION !!!\n");
1309 /* if sa(peer) addr is less than da(my) addr, then this device
1310 * process peer's gon request and block to send gon req.
1311 * if not (sa addr > da addr),
1312 * this device will process gon request and drop gon req of peer.
1314 ifp
= p2p
->bss_idx
[P2PAPI_BSSCFG_DEVICE
].vif
->ifp
;
1315 if (memcmp(mac
, ifp
->mac_addr
, ETH_ALEN
) < 0) {
1316 brcmf_dbg(INFO
, "Block transmit gon req !!!\n");
1317 p2p
->block_gon_req_tx
= true;
1318 /* if we are finding a common channel for sending af,
1319 * do not scan more to block to send current gon req
1321 if (test_and_clear_bit(BRCMF_P2P_STATUS_FINDING_COMMON_CHANNEL
,
1323 complete(&p2p
->afx_hdl
.act_frm_scan
);
1324 if (test_and_clear_bit(BRCMF_P2P_STATUS_WAITING_NEXT_ACT_FRAME
,
1326 brcmf_p2p_stop_wait_next_action_frame(cfg
);
1330 /* drop gon request of peer to process gon request by this device. */
1331 brcmf_dbg(INFO
, "Drop received gon req !!!\n");
1338 * brcmf_p2p_notify_action_frame_rx() - received action frame.
1340 * @ifp: interfac control.
1341 * @e: event message. Not used, to make it usable for fweh event dispatcher.
1342 * @data: payload of message, containing action frame data.
1345 int brcmf_p2p_notify_action_frame_rx(struct brcmf_if
*ifp
,
1346 const struct brcmf_event_msg
*e
,
1349 struct brcmf_cfg80211_info
*cfg
= ifp
->drvr
->config
;
1350 struct brcmf_p2p_info
*p2p
= &cfg
->p2p
;
1351 struct afx_hdl
*afx_hdl
= &p2p
->afx_hdl
;
1352 struct wireless_dev
*wdev
;
1353 u32 mgmt_frame_len
= e
->datalen
- sizeof(struct brcmf_rx_mgmt_data
);
1354 struct brcmf_rx_mgmt_data
*rxframe
= (struct brcmf_rx_mgmt_data
*)data
;
1355 u8
*frame
= (u8
*)(rxframe
+ 1);
1356 struct brcmf_p2p_pub_act_frame
*act_frm
;
1357 struct brcmf_p2psd_gas_pub_act_frame
*sd_act_frm
;
1358 struct brcmu_chan ch
;
1359 struct ieee80211_mgmt
*mgmt_frame
;
1364 if (e
->datalen
< sizeof(*rxframe
)) {
1365 brcmf_dbg(SCAN
, "Event data to small. Ignore\n");
1369 ch
.chspec
= be16_to_cpu(rxframe
->chanspec
);
1370 cfg
->d11inf
.decchspec(&ch
);
1371 /* Check if wpa_supplicant has registered for this frame */
1372 brcmf_dbg(INFO
, "ifp->vif->mgmt_rx_reg %04x\n", ifp
->vif
->mgmt_rx_reg
);
1373 mgmt_type
= (IEEE80211_STYPE_ACTION
& IEEE80211_FCTL_STYPE
) >> 4;
1374 if ((ifp
->vif
->mgmt_rx_reg
& BIT(mgmt_type
)) == 0)
1377 brcmf_p2p_print_actframe(false, frame
, mgmt_frame_len
);
1379 action
= P2P_PAF_SUBTYPE_INVALID
;
1380 if (brcmf_p2p_is_pub_action(frame
, mgmt_frame_len
)) {
1381 act_frm
= (struct brcmf_p2p_pub_act_frame
*)frame
;
1382 action
= act_frm
->subtype
;
1383 if ((action
== P2P_PAF_GON_REQ
) &&
1384 (brcmf_p2p_gon_req_collision(p2p
, (u8
*)e
->addr
))) {
1385 if (test_bit(BRCMF_P2P_STATUS_FINDING_COMMON_CHANNEL
,
1387 (ether_addr_equal(afx_hdl
->tx_dst_addr
, e
->addr
))) {
1388 afx_hdl
->peer_chan
= ch
.control_ch_num
;
1389 brcmf_dbg(INFO
, "GON request: Peer found, channel=%d\n",
1390 afx_hdl
->peer_chan
);
1391 complete(&afx_hdl
->act_frm_scan
);
1395 /* After complete GO Negotiation, roll back to mpc mode */
1396 if ((action
== P2P_PAF_GON_CONF
) ||
1397 (action
== P2P_PAF_PROVDIS_RSP
))
1398 brcmf_set_mpc(ifp
, 1);
1399 if (action
== P2P_PAF_GON_CONF
) {
1400 brcmf_dbg(TRACE
, "P2P: GO_NEG_PHASE status cleared\n");
1401 clear_bit(BRCMF_P2P_STATUS_GO_NEG_PHASE
, &p2p
->status
);
1403 } else if (brcmf_p2p_is_gas_action(frame
, mgmt_frame_len
)) {
1404 sd_act_frm
= (struct brcmf_p2psd_gas_pub_act_frame
*)frame
;
1405 action
= sd_act_frm
->action
;
1408 if (test_bit(BRCMF_P2P_STATUS_WAITING_NEXT_ACT_FRAME
, &p2p
->status
) &&
1409 (p2p
->next_af_subtype
== action
)) {
1410 brcmf_dbg(TRACE
, "We got a right next frame! (%d)\n", action
);
1411 clear_bit(BRCMF_P2P_STATUS_WAITING_NEXT_ACT_FRAME
,
1413 /* Stop waiting for next AF. */
1414 brcmf_p2p_stop_wait_next_action_frame(cfg
);
1417 mgmt_frame
= kzalloc(offsetof(struct ieee80211_mgmt
, u
) +
1418 mgmt_frame_len
, GFP_KERNEL
);
1420 brcmf_err("No memory available for action frame\n");
1423 memcpy(mgmt_frame
->da
, ifp
->mac_addr
, ETH_ALEN
);
1424 brcmf_fil_cmd_data_get(ifp
, BRCMF_C_GET_BSSID
, mgmt_frame
->bssid
,
1426 memcpy(mgmt_frame
->sa
, e
->addr
, ETH_ALEN
);
1427 mgmt_frame
->frame_control
= cpu_to_le16(IEEE80211_STYPE_ACTION
);
1428 memcpy(&mgmt_frame
->u
, frame
, mgmt_frame_len
);
1429 mgmt_frame_len
+= offsetof(struct ieee80211_mgmt
, u
);
1431 freq
= ieee80211_channel_to_frequency(ch
.control_ch_num
,
1432 ch
.band
== BRCMU_CHAN_BAND_2G
?
1436 wdev
= &ifp
->vif
->wdev
;
1437 cfg80211_rx_mgmt(wdev
, freq
, 0, (u8
*)mgmt_frame
, mgmt_frame_len
, 0);
1445 * brcmf_p2p_notify_action_tx_complete() - transmit action frame complete
1447 * @ifp: interfac control.
1448 * @e: event message. Not used, to make it usable for fweh event dispatcher.
1452 int brcmf_p2p_notify_action_tx_complete(struct brcmf_if
*ifp
,
1453 const struct brcmf_event_msg
*e
,
1456 struct brcmf_cfg80211_info
*cfg
= ifp
->drvr
->config
;
1457 struct brcmf_p2p_info
*p2p
= &cfg
->p2p
;
1459 brcmf_dbg(INFO
, "Enter: event %s, status=%d\n",
1460 e
->event_code
== BRCMF_E_ACTION_FRAME_OFF_CHAN_COMPLETE
?
1461 "ACTION_FRAME_OFF_CHAN_COMPLETE" : "ACTION_FRAME_COMPLETE",
1464 if (!test_bit(BRCMF_P2P_STATUS_SENDING_ACT_FRAME
, &p2p
->status
))
1467 if (e
->event_code
== BRCMF_E_ACTION_FRAME_COMPLETE
) {
1468 if (e
->status
== BRCMF_E_STATUS_SUCCESS
)
1469 set_bit(BRCMF_P2P_STATUS_ACTION_TX_COMPLETED
,
1472 set_bit(BRCMF_P2P_STATUS_ACTION_TX_NOACK
, &p2p
->status
);
1473 /* If there is no ack, we don't need to wait for
1474 * WLC_E_ACTION_FRAME_OFFCHAN_COMPLETE event
1476 brcmf_p2p_stop_wait_next_action_frame(cfg
);
1480 complete(&p2p
->send_af_done
);
1487 * brcmf_p2p_tx_action_frame() - send action frame over fil.
1489 * @p2p: p2p info struct for vif.
1490 * @af_params: action frame data/info.
1492 * Send an action frame immediately without doing channel synchronization.
1494 * This function waits for a completion event before returning.
1495 * The WLC_E_ACTION_FRAME_COMPLETE event will be received when the action
1496 * frame is transmitted.
1498 static s32
brcmf_p2p_tx_action_frame(struct brcmf_p2p_info
*p2p
,
1499 struct brcmf_fil_af_params_le
*af_params
)
1501 struct brcmf_cfg80211_vif
*vif
;
1505 brcmf_dbg(TRACE
, "Enter\n");
1507 reinit_completion(&p2p
->send_af_done
);
1508 clear_bit(BRCMF_P2P_STATUS_ACTION_TX_COMPLETED
, &p2p
->status
);
1509 clear_bit(BRCMF_P2P_STATUS_ACTION_TX_NOACK
, &p2p
->status
);
1511 vif
= p2p
->bss_idx
[P2PAPI_BSSCFG_DEVICE
].vif
;
1512 err
= brcmf_fil_bsscfg_data_set(vif
->ifp
, "actframe", af_params
,
1513 sizeof(*af_params
));
1515 brcmf_err(" sending action frame has failed\n");
1519 p2p
->af_sent_channel
= le32_to_cpu(af_params
->channel
);
1520 p2p
->af_tx_sent_jiffies
= jiffies
;
1522 timeout
= wait_for_completion_timeout(&p2p
->send_af_done
,
1523 P2P_AF_MAX_WAIT_TIME
);
1525 if (test_bit(BRCMF_P2P_STATUS_ACTION_TX_COMPLETED
, &p2p
->status
)) {
1526 brcmf_dbg(TRACE
, "TX action frame operation is success\n");
1529 brcmf_dbg(TRACE
, "TX action frame operation has failed\n");
1531 /* clear status bit for action tx */
1532 clear_bit(BRCMF_P2P_STATUS_ACTION_TX_COMPLETED
, &p2p
->status
);
1533 clear_bit(BRCMF_P2P_STATUS_ACTION_TX_NOACK
, &p2p
->status
);
1541 * brcmf_p2p_pub_af_tx() - public action frame tx routine.
1543 * @cfg: driver private data for cfg80211 interface.
1544 * @af_params: action frame data/info.
1545 * @config_af_params: configuration data for action frame.
1547 * routine which transmits ation frame public type.
1549 static s32
brcmf_p2p_pub_af_tx(struct brcmf_cfg80211_info
*cfg
,
1550 struct brcmf_fil_af_params_le
*af_params
,
1551 struct brcmf_config_af_params
*config_af_params
)
1553 struct brcmf_p2p_info
*p2p
= &cfg
->p2p
;
1554 struct brcmf_fil_action_frame_le
*action_frame
;
1555 struct brcmf_p2p_pub_act_frame
*act_frm
;
1559 action_frame
= &af_params
->action_frame
;
1560 act_frm
= (struct brcmf_p2p_pub_act_frame
*)(action_frame
->data
);
1562 config_af_params
->extra_listen
= true;
1564 switch (act_frm
->subtype
) {
1565 case P2P_PAF_GON_REQ
:
1566 brcmf_dbg(TRACE
, "P2P: GO_NEG_PHASE status set\n");
1567 set_bit(BRCMF_P2P_STATUS_GO_NEG_PHASE
, &p2p
->status
);
1568 config_af_params
->mpc_onoff
= 0;
1569 config_af_params
->search_channel
= true;
1570 p2p
->next_af_subtype
= act_frm
->subtype
+ 1;
1571 p2p
->gon_req_action
= true;
1572 /* increase dwell time to wait for RESP frame */
1573 af_params
->dwell_time
= cpu_to_le32(P2P_AF_MED_DWELL_TIME
);
1575 case P2P_PAF_GON_RSP
:
1576 p2p
->next_af_subtype
= act_frm
->subtype
+ 1;
1577 /* increase dwell time to wait for CONF frame */
1578 af_params
->dwell_time
= cpu_to_le32(P2P_AF_MED_DWELL_TIME
);
1580 case P2P_PAF_GON_CONF
:
1581 /* If we reached till GO Neg confirmation reset the filter */
1582 brcmf_dbg(TRACE
, "P2P: GO_NEG_PHASE status cleared\n");
1583 clear_bit(BRCMF_P2P_STATUS_GO_NEG_PHASE
, &p2p
->status
);
1584 /* turn on mpc again if go nego is done */
1585 config_af_params
->mpc_onoff
= 1;
1586 /* minimize dwell time */
1587 af_params
->dwell_time
= cpu_to_le32(P2P_AF_MIN_DWELL_TIME
);
1588 config_af_params
->extra_listen
= false;
1590 case P2P_PAF_INVITE_REQ
:
1591 config_af_params
->search_channel
= true;
1592 p2p
->next_af_subtype
= act_frm
->subtype
+ 1;
1593 /* increase dwell time */
1594 af_params
->dwell_time
= cpu_to_le32(P2P_AF_MED_DWELL_TIME
);
1596 case P2P_PAF_INVITE_RSP
:
1597 /* minimize dwell time */
1598 af_params
->dwell_time
= cpu_to_le32(P2P_AF_MIN_DWELL_TIME
);
1599 config_af_params
->extra_listen
= false;
1601 case P2P_PAF_DEVDIS_REQ
:
1602 config_af_params
->search_channel
= true;
1603 p2p
->next_af_subtype
= act_frm
->subtype
+ 1;
1604 /* maximize dwell time to wait for RESP frame */
1605 af_params
->dwell_time
= cpu_to_le32(P2P_AF_LONG_DWELL_TIME
);
1607 case P2P_PAF_DEVDIS_RSP
:
1608 /* minimize dwell time */
1609 af_params
->dwell_time
= cpu_to_le32(P2P_AF_MIN_DWELL_TIME
);
1610 config_af_params
->extra_listen
= false;
1612 case P2P_PAF_PROVDIS_REQ
:
1613 ie_len
= le16_to_cpu(action_frame
->len
) -
1614 offsetof(struct brcmf_p2p_pub_act_frame
, elts
);
1615 if (cfg80211_get_p2p_attr(&act_frm
->elts
[0], ie_len
,
1616 IEEE80211_P2P_ATTR_GROUP_ID
,
1618 config_af_params
->search_channel
= true;
1619 config_af_params
->mpc_onoff
= 0;
1620 p2p
->next_af_subtype
= act_frm
->subtype
+ 1;
1621 /* increase dwell time to wait for RESP frame */
1622 af_params
->dwell_time
= cpu_to_le32(P2P_AF_MED_DWELL_TIME
);
1624 case P2P_PAF_PROVDIS_RSP
:
1625 /* wpa_supplicant send go nego req right after prov disc */
1626 p2p
->next_af_subtype
= P2P_PAF_GON_REQ
;
1627 /* increase dwell time to MED level */
1628 af_params
->dwell_time
= cpu_to_le32(P2P_AF_MED_DWELL_TIME
);
1629 config_af_params
->extra_listen
= false;
1632 brcmf_err("Unknown p2p pub act frame subtype: %d\n",
1640 * brcmf_p2p_send_action_frame() - send action frame .
1642 * @cfg: driver private data for cfg80211 interface.
1643 * @ndev: net device to transmit on.
1644 * @af_params: configuration data for action frame.
1646 bool brcmf_p2p_send_action_frame(struct brcmf_cfg80211_info
*cfg
,
1647 struct net_device
*ndev
,
1648 struct brcmf_fil_af_params_le
*af_params
)
1650 struct brcmf_p2p_info
*p2p
= &cfg
->p2p
;
1651 struct brcmf_if
*ifp
= netdev_priv(ndev
);
1652 struct brcmf_fil_action_frame_le
*action_frame
;
1653 struct brcmf_config_af_params config_af_params
;
1654 struct afx_hdl
*afx_hdl
= &p2p
->afx_hdl
;
1655 u16 action_frame_len
;
1660 s32 extra_listen_time
;
1663 action_frame
= &af_params
->action_frame
;
1664 action_frame_len
= le16_to_cpu(action_frame
->len
);
1666 brcmf_p2p_print_actframe(true, action_frame
->data
, action_frame_len
);
1668 /* Add the default dwell time. Dwell time to stay off-channel */
1669 /* to wait for a response action frame after transmitting an */
1670 /* GO Negotiation action frame */
1671 af_params
->dwell_time
= cpu_to_le32(P2P_AF_DWELL_TIME
);
1673 category
= action_frame
->data
[DOT11_ACTION_CAT_OFF
];
1674 action
= action_frame
->data
[DOT11_ACTION_ACT_OFF
];
1676 /* initialize variables */
1677 p2p
->next_af_subtype
= P2P_PAF_SUBTYPE_INVALID
;
1678 p2p
->gon_req_action
= false;
1680 /* config parameters */
1681 config_af_params
.mpc_onoff
= -1;
1682 config_af_params
.search_channel
= false;
1683 config_af_params
.extra_listen
= false;
1685 if (brcmf_p2p_is_pub_action(action_frame
->data
, action_frame_len
)) {
1686 /* p2p public action frame process */
1687 if (brcmf_p2p_pub_af_tx(cfg
, af_params
, &config_af_params
)) {
1688 /* Just send unknown subtype frame with */
1689 /* default parameters. */
1690 brcmf_err("P2P Public action frame, unknown subtype.\n");
1692 } else if (brcmf_p2p_is_gas_action(action_frame
->data
,
1693 action_frame_len
)) {
1694 /* service discovery process */
1695 if (action
== P2PSD_ACTION_ID_GAS_IREQ
||
1696 action
== P2PSD_ACTION_ID_GAS_CREQ
) {
1697 /* configure service discovery query frame */
1698 config_af_params
.search_channel
= true;
1700 /* save next af suptype to cancel */
1701 /* remaining dwell time */
1702 p2p
->next_af_subtype
= action
+ 1;
1704 af_params
->dwell_time
=
1705 cpu_to_le32(P2P_AF_MED_DWELL_TIME
);
1706 } else if (action
== P2PSD_ACTION_ID_GAS_IRESP
||
1707 action
== P2PSD_ACTION_ID_GAS_CRESP
) {
1708 /* configure service discovery response frame */
1709 af_params
->dwell_time
=
1710 cpu_to_le32(P2P_AF_MIN_DWELL_TIME
);
1712 brcmf_err("Unknown action type: %d\n", action
);
1715 } else if (brcmf_p2p_is_p2p_action(action_frame
->data
,
1716 action_frame_len
)) {
1717 /* do not configure anything. it will be */
1718 /* sent with a default configuration */
1720 brcmf_err("Unknown Frame: category 0x%x, action 0x%x\n",
1725 /* if connecting on primary iface, sleep for a while before sending
1728 if (test_bit(BRCMF_VIF_STATUS_CONNECTING
,
1729 &p2p
->bss_idx
[P2PAPI_BSSCFG_PRIMARY
].vif
->sme_state
))
1732 /* if scan is ongoing, abort current scan. */
1733 if (test_bit(BRCMF_SCAN_STATUS_BUSY
, &cfg
->scan_status
))
1734 brcmf_abort_scanning(cfg
);
1736 memcpy(afx_hdl
->tx_dst_addr
, action_frame
->da
, ETH_ALEN
);
1738 /* To make sure to send successfully action frame, turn off mpc */
1739 if (config_af_params
.mpc_onoff
== 0)
1740 brcmf_set_mpc(ifp
, 0);
1742 /* set status and destination address before sending af */
1743 if (p2p
->next_af_subtype
!= P2P_PAF_SUBTYPE_INVALID
) {
1744 /* set status to cancel the remained dwell time in rx process */
1745 set_bit(BRCMF_P2P_STATUS_WAITING_NEXT_ACT_FRAME
, &p2p
->status
);
1748 p2p
->af_sent_channel
= 0;
1749 set_bit(BRCMF_P2P_STATUS_SENDING_ACT_FRAME
, &p2p
->status
);
1750 /* validate channel and p2p ies */
1751 if (config_af_params
.search_channel
&&
1752 IS_P2P_SOCIAL_CHANNEL(le32_to_cpu(af_params
->channel
)) &&
1753 p2p
->bss_idx
[P2PAPI_BSSCFG_DEVICE
].vif
->saved_ie
.probe_req_ie_len
) {
1754 afx_hdl
= &p2p
->afx_hdl
;
1755 afx_hdl
->peer_listen_chan
= le32_to_cpu(af_params
->channel
);
1757 if (brcmf_p2p_af_searching_channel(p2p
) ==
1758 P2P_INVALID_CHANNEL
) {
1759 brcmf_err("Couldn't find peer's channel.\n");
1763 /* Abort scan even for VSDB scenarios. Scan gets aborted in
1764 * firmware but after the check of piggyback algorithm. To take
1765 * care of current piggback algo, lets abort the scan here
1768 brcmf_notify_escan_complete(cfg
, ifp
, true, true);
1770 /* update channel */
1771 af_params
->channel
= cpu_to_le32(afx_hdl
->peer_chan
);
1775 while (!p2p
->block_gon_req_tx
&&
1776 (ack
== false) && (tx_retry
< P2P_AF_TX_MAX_RETRY
)) {
1777 ack
= !brcmf_p2p_tx_action_frame(p2p
, af_params
);
1781 brcmf_err("Failed to send Action Frame(retry %d)\n", tx_retry
);
1782 clear_bit(BRCMF_P2P_STATUS_GO_NEG_PHASE
, &p2p
->status
);
1786 clear_bit(BRCMF_P2P_STATUS_SENDING_ACT_FRAME
, &p2p
->status
);
1788 /* WAR: sometimes dongle does not keep the dwell time of 'actframe'.
1789 * if we coundn't get the next action response frame and dongle does
1790 * not keep the dwell time, go to listen state again to get next action
1793 if (ack
&& config_af_params
.extra_listen
&& !p2p
->block_gon_req_tx
&&
1794 test_bit(BRCMF_P2P_STATUS_WAITING_NEXT_ACT_FRAME
, &p2p
->status
) &&
1795 p2p
->af_sent_channel
== afx_hdl
->my_listen_chan
) {
1796 delta_ms
= jiffies_to_msecs(jiffies
- p2p
->af_tx_sent_jiffies
);
1797 if (le32_to_cpu(af_params
->dwell_time
) > delta_ms
)
1798 extra_listen_time
= le32_to_cpu(af_params
->dwell_time
) -
1801 extra_listen_time
= 0;
1802 if (extra_listen_time
> 50) {
1803 set_bit(BRCMF_P2P_STATUS_WAITING_NEXT_AF_LISTEN
,
1805 brcmf_dbg(INFO
, "Wait more time! actual af time:%d, calculated extra listen:%d\n",
1806 le32_to_cpu(af_params
->dwell_time
),
1808 extra_listen_time
+= 100;
1809 if (!brcmf_p2p_discover_listen(p2p
,
1810 p2p
->af_sent_channel
,
1811 extra_listen_time
)) {
1812 unsigned long duration
;
1814 extra_listen_time
+= 100;
1815 duration
= msecs_to_jiffies(extra_listen_time
);
1816 wait_for_completion_timeout(&p2p
->wait_next_af
,
1819 clear_bit(BRCMF_P2P_STATUS_WAITING_NEXT_AF_LISTEN
,
1824 if (p2p
->block_gon_req_tx
) {
1825 /* if ack is true, supplicant will wait more time(100ms).
1826 * so we will return it as a success to get more time .
1828 p2p
->block_gon_req_tx
= false;
1832 clear_bit(BRCMF_P2P_STATUS_WAITING_NEXT_ACT_FRAME
, &p2p
->status
);
1833 /* if all done, turn mpc on again */
1834 if (config_af_params
.mpc_onoff
== 1)
1835 brcmf_set_mpc(ifp
, 1);
1841 * brcmf_p2p_notify_rx_mgmt_p2p_probereq() - Event handler for p2p probe req.
1843 * @ifp: interface pointer for which event was received.
1845 * @data: payload of event message (probe request).
1847 s32
brcmf_p2p_notify_rx_mgmt_p2p_probereq(struct brcmf_if
*ifp
,
1848 const struct brcmf_event_msg
*e
,
1851 struct brcmf_cfg80211_info
*cfg
= ifp
->drvr
->config
;
1852 struct brcmf_p2p_info
*p2p
= &cfg
->p2p
;
1853 struct afx_hdl
*afx_hdl
= &p2p
->afx_hdl
;
1854 struct brcmf_cfg80211_vif
*vif
= ifp
->vif
;
1855 struct brcmf_rx_mgmt_data
*rxframe
= (struct brcmf_rx_mgmt_data
*)data
;
1856 u16 chanspec
= be16_to_cpu(rxframe
->chanspec
);
1857 struct brcmu_chan ch
;
1863 brcmf_dbg(INFO
, "Enter: event %d reason %d\n", e
->event_code
,
1866 if (e
->datalen
< sizeof(*rxframe
)) {
1867 brcmf_dbg(SCAN
, "Event data to small. Ignore\n");
1871 ch
.chspec
= be16_to_cpu(rxframe
->chanspec
);
1872 cfg
->d11inf
.decchspec(&ch
);
1874 if (test_bit(BRCMF_P2P_STATUS_FINDING_COMMON_CHANNEL
, &p2p
->status
) &&
1875 (ether_addr_equal(afx_hdl
->tx_dst_addr
, e
->addr
))) {
1876 afx_hdl
->peer_chan
= ch
.control_ch_num
;
1877 brcmf_dbg(INFO
, "PROBE REQUEST: Peer found, channel=%d\n",
1878 afx_hdl
->peer_chan
);
1879 complete(&afx_hdl
->act_frm_scan
);
1882 /* Firmware sends us two proberesponses for each idx one. At the */
1883 /* moment anything but bsscfgidx 0 is passed up to supplicant */
1884 if (e
->bsscfgidx
== 0)
1887 /* Filter any P2P probe reqs arriving during the GO-NEG Phase */
1888 if (test_bit(BRCMF_P2P_STATUS_GO_NEG_PHASE
, &p2p
->status
)) {
1889 brcmf_dbg(INFO
, "Filtering P2P probe_req in GO-NEG phase\n");
1893 /* Check if wpa_supplicant has registered for this frame */
1894 brcmf_dbg(INFO
, "vif->mgmt_rx_reg %04x\n", vif
->mgmt_rx_reg
);
1895 mgmt_type
= (IEEE80211_STYPE_PROBE_REQ
& IEEE80211_FCTL_STYPE
) >> 4;
1896 if ((vif
->mgmt_rx_reg
& BIT(mgmt_type
)) == 0)
1899 mgmt_frame
= (u8
*)(rxframe
+ 1);
1900 mgmt_frame_len
= e
->datalen
- sizeof(*rxframe
);
1901 freq
= ieee80211_channel_to_frequency(ch
.control_ch_num
,
1902 ch
.band
== BRCMU_CHAN_BAND_2G
?
1906 cfg80211_rx_mgmt(&vif
->wdev
, freq
, 0, mgmt_frame
, mgmt_frame_len
, 0);
1908 brcmf_dbg(INFO
, "mgmt_frame_len (%d) , e->datalen (%d), chanspec (%04x), freq (%d)\n",
1909 mgmt_frame_len
, e
->datalen
, chanspec
, freq
);
1916 * brcmf_p2p_get_current_chanspec() - Get current operation channel.
1918 * @p2p: P2P specific data.
1919 * @chanspec: chanspec to be returned.
1921 static void brcmf_p2p_get_current_chanspec(struct brcmf_p2p_info
*p2p
,
1924 struct brcmf_if
*ifp
;
1925 u8 mac_addr
[ETH_ALEN
];
1926 struct brcmu_chan ch
;
1927 struct brcmf_bss_info_le
*bi
;
1930 ifp
= p2p
->bss_idx
[P2PAPI_BSSCFG_PRIMARY
].vif
->ifp
;
1932 if (brcmf_fil_cmd_data_get(ifp
, BRCMF_C_GET_BSSID
, mac_addr
,
1934 buf
= kzalloc(WL_BSS_INFO_MAX
, GFP_KERNEL
);
1936 *(__le32
*)buf
= cpu_to_le32(WL_BSS_INFO_MAX
);
1937 if (brcmf_fil_cmd_data_get(ifp
, BRCMF_C_GET_BSS_INFO
,
1938 buf
, WL_BSS_INFO_MAX
) == 0) {
1939 bi
= (struct brcmf_bss_info_le
*)(buf
+ 4);
1940 *chanspec
= le16_to_cpu(bi
->chanspec
);
1947 /* Use default channel for P2P */
1948 ch
.chnum
= BRCMF_P2P_TEMP_CHAN
;
1949 ch
.bw
= BRCMU_CHAN_BW_20
;
1950 p2p
->cfg
->d11inf
.encchspec(&ch
);
1951 *chanspec
= ch
.chspec
;
1955 * Change a P2P Role.
1957 * @mac: MAC address of the BSS to change a role
1958 * Returns 0 if success.
1960 int brcmf_p2p_ifchange(struct brcmf_cfg80211_info
*cfg
,
1961 enum brcmf_fil_p2p_if_types if_type
)
1963 struct brcmf_p2p_info
*p2p
= &cfg
->p2p
;
1964 struct brcmf_cfg80211_vif
*vif
;
1965 struct brcmf_fil_p2p_if_le if_request
;
1969 brcmf_dbg(TRACE
, "Enter\n");
1971 vif
= p2p
->bss_idx
[P2PAPI_BSSCFG_PRIMARY
].vif
;
1973 brcmf_err("vif for P2PAPI_BSSCFG_PRIMARY does not exist\n");
1976 brcmf_notify_escan_complete(cfg
, vif
->ifp
, true, true);
1977 vif
= p2p
->bss_idx
[P2PAPI_BSSCFG_CONNECTION
].vif
;
1979 brcmf_err("vif for P2PAPI_BSSCFG_CONNECTION does not exist\n");
1982 brcmf_set_mpc(vif
->ifp
, 0);
1984 /* In concurrency case, STA may be already associated in a particular */
1985 /* channel. so retrieve the current channel of primary interface and */
1986 /* then start the virtual interface on that. */
1987 brcmf_p2p_get_current_chanspec(p2p
, &chanspec
);
1989 if_request
.type
= cpu_to_le16((u16
)if_type
);
1990 if_request
.chspec
= cpu_to_le16(chanspec
);
1991 memcpy(if_request
.addr
, p2p
->int_addr
, sizeof(if_request
.addr
));
1993 brcmf_cfg80211_arm_vif_event(cfg
, vif
);
1994 err
= brcmf_fil_iovar_data_set(vif
->ifp
, "p2p_ifupd", &if_request
,
1995 sizeof(if_request
));
1997 brcmf_err("p2p_ifupd FAILED, err=%d\n", err
);
1998 brcmf_cfg80211_arm_vif_event(cfg
, NULL
);
2001 err
= brcmf_cfg80211_wait_vif_event(cfg
, BRCMF_E_IF_CHANGE
,
2002 BRCMF_VIF_EVENT_TIMEOUT
);
2003 brcmf_cfg80211_arm_vif_event(cfg
, NULL
);
2005 brcmf_err("No BRCMF_E_IF_CHANGE event received\n");
2009 err
= brcmf_fil_cmd_int_set(vif
->ifp
, BRCMF_C_SET_SCB_TIMEOUT
,
2010 BRCMF_SCB_TIMEOUT_VALUE
);
2015 static int brcmf_p2p_request_p2p_if(struct brcmf_p2p_info
*p2p
,
2016 struct brcmf_if
*ifp
, u8 ea
[ETH_ALEN
],
2017 enum brcmf_fil_p2p_if_types iftype
)
2019 struct brcmf_fil_p2p_if_le if_request
;
2023 /* we need a default channel */
2024 brcmf_p2p_get_current_chanspec(p2p
, &chanspec
);
2026 /* fill the firmware request */
2027 memcpy(if_request
.addr
, ea
, ETH_ALEN
);
2028 if_request
.type
= cpu_to_le16((u16
)iftype
);
2029 if_request
.chspec
= cpu_to_le16(chanspec
);
2031 err
= brcmf_fil_iovar_data_set(ifp
, "p2p_ifadd", &if_request
,
2032 sizeof(if_request
));
2037 static int brcmf_p2p_disable_p2p_if(struct brcmf_cfg80211_vif
*vif
)
2039 struct brcmf_cfg80211_info
*cfg
= wdev_to_cfg(&vif
->wdev
);
2040 struct net_device
*pri_ndev
= cfg_to_ndev(cfg
);
2041 struct brcmf_if
*ifp
= netdev_priv(pri_ndev
);
2042 u8
*addr
= vif
->wdev
.netdev
->dev_addr
;
2044 return brcmf_fil_iovar_data_set(ifp
, "p2p_ifdis", addr
, ETH_ALEN
);
2047 static int brcmf_p2p_release_p2p_if(struct brcmf_cfg80211_vif
*vif
)
2049 struct brcmf_cfg80211_info
*cfg
= wdev_to_cfg(&vif
->wdev
);
2050 struct net_device
*pri_ndev
= cfg_to_ndev(cfg
);
2051 struct brcmf_if
*ifp
= netdev_priv(pri_ndev
);
2052 u8
*addr
= vif
->wdev
.netdev
->dev_addr
;
2054 return brcmf_fil_iovar_data_set(ifp
, "p2p_ifdel", addr
, ETH_ALEN
);
2058 * brcmf_p2p_create_p2pdev() - create a P2P_DEVICE virtual interface.
2060 * @p2p: P2P specific data.
2061 * @wiphy: wiphy device of new interface.
2062 * @addr: mac address for this new interface.
2064 static struct wireless_dev
*brcmf_p2p_create_p2pdev(struct brcmf_p2p_info
*p2p
,
2065 struct wiphy
*wiphy
,
2068 struct brcmf_cfg80211_vif
*p2p_vif
;
2069 struct brcmf_if
*p2p_ifp
;
2070 struct brcmf_if
*pri_ifp
;
2074 if (p2p
->bss_idx
[P2PAPI_BSSCFG_DEVICE
].vif
)
2075 return ERR_PTR(-ENOSPC
);
2077 p2p_vif
= brcmf_alloc_vif(p2p
->cfg
, NL80211_IFTYPE_P2P_DEVICE
);
2078 if (IS_ERR(p2p_vif
)) {
2079 brcmf_err("could not create discovery vif\n");
2080 return (struct wireless_dev
*)p2p_vif
;
2083 pri_ifp
= p2p
->bss_idx
[P2PAPI_BSSCFG_PRIMARY
].vif
->ifp
;
2084 brcmf_p2p_generate_bss_mac(p2p
, addr
);
2085 brcmf_p2p_set_firmware(pri_ifp
, p2p
->dev_addr
);
2087 brcmf_cfg80211_arm_vif_event(p2p
->cfg
, p2p_vif
);
2088 brcmf_fweh_p2pdev_setup(pri_ifp
, true);
2090 /* Initialize P2P Discovery in the firmware */
2091 err
= brcmf_fil_iovar_int_set(pri_ifp
, "p2p_disc", 1);
2093 brcmf_err("set p2p_disc error\n");
2094 brcmf_fweh_p2pdev_setup(pri_ifp
, false);
2095 brcmf_cfg80211_arm_vif_event(p2p
->cfg
, NULL
);
2099 /* wait for firmware event */
2100 err
= brcmf_cfg80211_wait_vif_event(p2p
->cfg
, BRCMF_E_IF_ADD
,
2101 BRCMF_VIF_EVENT_TIMEOUT
);
2102 brcmf_cfg80211_arm_vif_event(p2p
->cfg
, NULL
);
2103 brcmf_fweh_p2pdev_setup(pri_ifp
, false);
2105 brcmf_err("timeout occurred\n");
2110 /* discovery interface created */
2111 p2p_ifp
= p2p_vif
->ifp
;
2112 p2p
->bss_idx
[P2PAPI_BSSCFG_DEVICE
].vif
= p2p_vif
;
2113 memcpy(p2p_ifp
->mac_addr
, p2p
->dev_addr
, ETH_ALEN
);
2114 memcpy(&p2p_vif
->wdev
.address
, p2p
->dev_addr
, sizeof(p2p
->dev_addr
));
2116 /* verify bsscfg index for P2P discovery */
2117 err
= brcmf_fil_iovar_int_get(pri_ifp
, "p2p_dev", &bsscfgidx
);
2119 brcmf_err("retrieving discover bsscfg index failed\n");
2123 WARN_ON(p2p_ifp
->bsscfgidx
!= bsscfgidx
);
2125 init_completion(&p2p
->send_af_done
);
2126 INIT_WORK(&p2p
->afx_hdl
.afx_work
, brcmf_p2p_afx_handler
);
2127 init_completion(&p2p
->afx_hdl
.act_frm_scan
);
2128 init_completion(&p2p
->wait_next_af
);
2130 return &p2p_vif
->wdev
;
2133 brcmf_free_vif(p2p_vif
);
2134 return ERR_PTR(err
);
2138 * brcmf_p2p_add_vif() - create a new P2P virtual interface.
2140 * @wiphy: wiphy device of new interface.
2141 * @name: name of the new interface.
2142 * @name_assign_type: origin of the interface name
2143 * @type: nl80211 interface type.
2145 * @params: contains mac address for P2P device.
2147 struct wireless_dev
*brcmf_p2p_add_vif(struct wiphy
*wiphy
, const char *name
,
2148 unsigned char name_assign_type
,
2149 enum nl80211_iftype type
, u32
*flags
,
2150 struct vif_params
*params
)
2152 struct brcmf_cfg80211_info
*cfg
= wiphy_to_cfg(wiphy
);
2153 struct brcmf_if
*ifp
= netdev_priv(cfg_to_ndev(cfg
));
2154 struct brcmf_cfg80211_vif
*vif
;
2155 enum brcmf_fil_p2p_if_types iftype
;
2158 if (brcmf_cfg80211_vif_event_armed(cfg
))
2159 return ERR_PTR(-EBUSY
);
2161 brcmf_dbg(INFO
, "adding vif \"%s\" (type=%d)\n", name
, type
);
2164 case NL80211_IFTYPE_P2P_CLIENT
:
2165 iftype
= BRCMF_FIL_P2P_IF_CLIENT
;
2167 case NL80211_IFTYPE_P2P_GO
:
2168 iftype
= BRCMF_FIL_P2P_IF_GO
;
2170 case NL80211_IFTYPE_P2P_DEVICE
:
2171 return brcmf_p2p_create_p2pdev(&cfg
->p2p
, wiphy
,
2174 return ERR_PTR(-EOPNOTSUPP
);
2177 vif
= brcmf_alloc_vif(cfg
, type
);
2179 return (struct wireless_dev
*)vif
;
2180 brcmf_cfg80211_arm_vif_event(cfg
, vif
);
2182 err
= brcmf_p2p_request_p2p_if(&cfg
->p2p
, ifp
, cfg
->p2p
.int_addr
,
2185 brcmf_cfg80211_arm_vif_event(cfg
, NULL
);
2189 /* wait for firmware event */
2190 err
= brcmf_cfg80211_wait_vif_event(cfg
, BRCMF_E_IF_ADD
,
2191 BRCMF_VIF_EVENT_TIMEOUT
);
2192 brcmf_cfg80211_arm_vif_event(cfg
, NULL
);
2194 brcmf_err("timeout occurred\n");
2199 /* interface created in firmware */
2202 brcmf_err("no if pointer provided\n");
2207 strncpy(ifp
->ndev
->name
, name
, sizeof(ifp
->ndev
->name
) - 1);
2208 ifp
->ndev
->name_assign_type
= name_assign_type
;
2209 err
= brcmf_net_attach(ifp
, true);
2211 brcmf_err("Registering netdevice failed\n");
2215 cfg
->p2p
.bss_idx
[P2PAPI_BSSCFG_CONNECTION
].vif
= vif
;
2216 /* Disable firmware roaming for P2P interface */
2217 brcmf_fil_iovar_int_set(ifp
, "roam_off", 1);
2218 if (iftype
== BRCMF_FIL_P2P_IF_GO
) {
2219 /* set station timeout for p2p */
2220 brcmf_fil_cmd_int_set(ifp
, BRCMF_C_SET_SCB_TIMEOUT
,
2221 BRCMF_SCB_TIMEOUT_VALUE
);
2223 return &ifp
->vif
->wdev
;
2226 brcmf_free_vif(vif
);
2227 return ERR_PTR(err
);
2231 * brcmf_p2p_del_vif() - delete a P2P virtual interface.
2233 * @wiphy: wiphy device of interface.
2234 * @wdev: wireless device of interface.
2236 int brcmf_p2p_del_vif(struct wiphy
*wiphy
, struct wireless_dev
*wdev
)
2238 struct brcmf_cfg80211_info
*cfg
= wiphy_priv(wiphy
);
2239 struct brcmf_p2p_info
*p2p
= &cfg
->p2p
;
2240 struct brcmf_cfg80211_vif
*vif
;
2241 bool wait_for_disable
= false;
2244 brcmf_dbg(TRACE
, "delete P2P vif\n");
2245 vif
= container_of(wdev
, struct brcmf_cfg80211_vif
, wdev
);
2247 brcmf_cfg80211_arm_vif_event(cfg
, vif
);
2248 switch (vif
->wdev
.iftype
) {
2249 case NL80211_IFTYPE_P2P_CLIENT
:
2250 if (test_bit(BRCMF_VIF_STATUS_DISCONNECTING
, &vif
->sme_state
))
2251 wait_for_disable
= true;
2254 case NL80211_IFTYPE_P2P_GO
:
2255 if (!brcmf_p2p_disable_p2p_if(vif
))
2256 wait_for_disable
= true;
2259 case NL80211_IFTYPE_P2P_DEVICE
:
2260 if (!p2p
->bss_idx
[P2PAPI_BSSCFG_DEVICE
].vif
)
2262 brcmf_p2p_cancel_remain_on_channel(vif
->ifp
);
2263 brcmf_p2p_deinit_discovery(p2p
);
2270 clear_bit(BRCMF_P2P_STATUS_GO_NEG_PHASE
, &p2p
->status
);
2271 brcmf_dbg(INFO
, "P2P: GO_NEG_PHASE status cleared\n");
2273 if (wait_for_disable
)
2274 wait_for_completion_timeout(&cfg
->vif_disabled
,
2275 BRCMF_P2P_DISABLE_TIMEOUT
);
2278 if (vif
->wdev
.iftype
!= NL80211_IFTYPE_P2P_DEVICE
) {
2279 brcmf_vif_clear_mgmt_ies(vif
);
2280 err
= brcmf_p2p_release_p2p_if(vif
);
2283 /* wait for firmware event */
2284 err
= brcmf_cfg80211_wait_vif_event(cfg
, BRCMF_E_IF_DEL
,
2285 BRCMF_VIF_EVENT_TIMEOUT
);
2291 brcmf_remove_interface(vif
->ifp
, true);
2293 brcmf_cfg80211_arm_vif_event(cfg
, NULL
);
2294 if (vif
->wdev
.iftype
!= NL80211_IFTYPE_P2P_DEVICE
)
2295 p2p
->bss_idx
[P2PAPI_BSSCFG_CONNECTION
].vif
= NULL
;
2300 void brcmf_p2p_ifp_removed(struct brcmf_if
*ifp
)
2302 struct brcmf_cfg80211_info
*cfg
;
2303 struct brcmf_cfg80211_vif
*vif
;
2305 brcmf_dbg(INFO
, "P2P: device interface removed\n");
2307 cfg
= wdev_to_cfg(&vif
->wdev
);
2308 cfg
->p2p
.bss_idx
[P2PAPI_BSSCFG_DEVICE
].vif
= NULL
;
2310 cfg80211_unregister_wdev(&vif
->wdev
);
2312 brcmf_free_vif(vif
);
2315 int brcmf_p2p_start_device(struct wiphy
*wiphy
, struct wireless_dev
*wdev
)
2317 struct brcmf_cfg80211_info
*cfg
= wiphy_to_cfg(wiphy
);
2318 struct brcmf_p2p_info
*p2p
= &cfg
->p2p
;
2319 struct brcmf_cfg80211_vif
*vif
;
2322 vif
= container_of(wdev
, struct brcmf_cfg80211_vif
, wdev
);
2323 mutex_lock(&cfg
->usr_sync
);
2324 err
= brcmf_p2p_enable_discovery(p2p
);
2326 set_bit(BRCMF_VIF_STATUS_READY
, &vif
->sme_state
);
2327 mutex_unlock(&cfg
->usr_sync
);
2331 void brcmf_p2p_stop_device(struct wiphy
*wiphy
, struct wireless_dev
*wdev
)
2333 struct brcmf_cfg80211_info
*cfg
= wiphy_to_cfg(wiphy
);
2334 struct brcmf_p2p_info
*p2p
= &cfg
->p2p
;
2335 struct brcmf_cfg80211_vif
*vif
;
2337 vif
= container_of(wdev
, struct brcmf_cfg80211_vif
, wdev
);
2338 /* This call can be result of the unregister_wdev call. In that case
2339 * we dont want to do anything anymore. Just return. The config vif
2340 * will have been cleared at this point.
2342 if (p2p
->bss_idx
[P2PAPI_BSSCFG_DEVICE
].vif
== vif
) {
2343 mutex_lock(&cfg
->usr_sync
);
2344 /* Set the discovery state to SCAN */
2345 (void)brcmf_p2p_set_discover_state(vif
->ifp
,
2346 WL_P2P_DISC_ST_SCAN
, 0, 0);
2347 brcmf_abort_scanning(cfg
);
2348 clear_bit(BRCMF_VIF_STATUS_READY
, &vif
->sme_state
);
2349 mutex_unlock(&cfg
->usr_sync
);
2354 * brcmf_p2p_attach() - attach for P2P.
2356 * @cfg: driver private data for cfg80211 interface.
2357 * @p2pdev_forced: create p2p device interface at attach.
2359 s32
brcmf_p2p_attach(struct brcmf_cfg80211_info
*cfg
, bool p2pdev_forced
)
2361 struct brcmf_p2p_info
*p2p
;
2362 struct brcmf_if
*pri_ifp
;
2369 pri_ifp
= brcmf_get_ifp(cfg
->pub
, 0);
2370 p2p
->bss_idx
[P2PAPI_BSSCFG_PRIMARY
].vif
= pri_ifp
->vif
;
2372 if (p2pdev_forced
) {
2373 err_ptr
= brcmf_p2p_create_p2pdev(p2p
, NULL
, NULL
);
2374 if (IS_ERR(err_ptr
)) {
2375 brcmf_err("P2P device creation failed.\n");
2376 err
= PTR_ERR(err_ptr
);
2379 p2p
->p2pdev_dynamically
= true;
2385 * brcmf_p2p_detach() - detach P2P.
2387 * @p2p: P2P specific data.
2389 void brcmf_p2p_detach(struct brcmf_p2p_info
*p2p
)
2391 struct brcmf_cfg80211_vif
*vif
;
2393 vif
= p2p
->bss_idx
[P2PAPI_BSSCFG_DEVICE
].vif
;
2395 brcmf_p2p_cancel_remain_on_channel(vif
->ifp
);
2396 brcmf_p2p_deinit_discovery(p2p
);
2397 brcmf_remove_interface(vif
->ifp
, false);
2399 /* just set it all to zero */
2400 memset(p2p
, 0, sizeof(*p2p
));