hc
2024-05-16 8d2a02b24d66aa359e83eebc1ed3c0f85367a1cb
kernel/drivers/net/wireless/broadcom/brcm80211/brcmfmac/p2p.c
....@@ -1,17 +1,6 @@
1
+// SPDX-License-Identifier: ISC
12 /*
23 * Copyright (c) 2012 Broadcom Corporation
3
- *
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.
7
- *
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.
154 */
165 #include <linux/slab.h>
176 #include <linux/netdevice.h>
....@@ -28,6 +17,7 @@
2817 #include "fwil_types.h"
2918 #include "p2p.h"
3019 #include "cfg80211.h"
20
+#include "feature.h"
3121
3222 /* parameters used for p2p escan */
3323 #define P2PAPI_SCAN_NPROBES 1
....@@ -70,12 +60,13 @@
7060 #define P2P_AF_MIN_DWELL_TIME 100
7161 #define P2P_AF_MED_DWELL_TIME 400
7262 #define P2P_AF_LONG_DWELL_TIME 1000
73
-#define P2P_AF_TX_MAX_RETRY 1
63
+#define P2P_AF_TX_MAX_RETRY 5
7464 #define P2P_AF_MAX_WAIT_TIME msecs_to_jiffies(2000)
7565 #define P2P_INVALID_CHANNEL -1
7666 #define P2P_CHANNEL_SYNC_RETRY 5
7767 #define P2P_AF_FRM_SCAN_MAX_WAIT msecs_to_jiffies(450)
7868 #define P2P_DEFAULT_SLEEP_TIME_VSDB 200
69
+#define P2P_AF_RETRY_DELAY_TIME 40
7970
8071 /* WiFi P2P Public Action Frame OUI Subtypes */
8172 #define P2P_PAF_GON_REQ 0 /* Group Owner Negotiation Req */
....@@ -103,6 +94,9 @@
10394 #define P2PSD_ACTION_ID_GAS_CRESP 0x0d /* GAS Comback Response AF */
10495
10596 #define BRCMF_P2P_DISABLE_TIMEOUT msecs_to_jiffies(500)
97
+
98
+/* Mask for retry counter of custom dwell time */
99
+#define CUSTOM_RETRY_MASK 0xff000000
106100 /**
107101 * struct brcmf_p2p_disc_st_le - set discovery state in firmware.
108102 *
....@@ -151,11 +145,11 @@
151145 *
152146 * @category: P2P_PUB_AF_CATEGORY
153147 * @action: P2P_PUB_AF_ACTION
154
- * @oui[3]: P2P_OUI
148
+ * @oui: P2P_OUI
155149 * @oui_type: OUI type - P2P_VER
156150 * @subtype: OUI subtype - P2P_TYPE_*
157151 * @dialog_token: nonzero, identifies req/rsp transaction
158
- * @elts[1]: Variable length information elements.
152
+ * @elts: Variable length information elements.
159153 */
160154 struct brcmf_p2p_pub_act_frame {
161155 u8 category;
....@@ -171,11 +165,11 @@
171165 * struct brcmf_p2p_action_frame - WiFi P2P Action Frame
172166 *
173167 * @category: P2P_AF_CATEGORY
174
- * @OUI[3]: OUI - P2P_OUI
168
+ * @oui: OUI - P2P_OUI
175169 * @type: OUI Type - P2P_VER
176170 * @subtype: OUI Subtype - P2P_AF_*
177171 * @dialog_token: nonzero, identifies req/resp tranaction
178
- * @elts[1]: Variable length information elements.
172
+ * @elts: Variable length information elements.
179173 */
180174 struct brcmf_p2p_action_frame {
181175 u8 category;
....@@ -192,7 +186,7 @@
192186 * @category: 0x04 Public Action Frame
193187 * @action: 0x6c Advertisement Protocol
194188 * @dialog_token: nonzero, identifies req/rsp transaction
195
- * @query_data[1]: Query Data. SD gas ireq SD gas iresp
189
+ * @query_data: Query Data. SD gas ireq SD gas iresp
196190 */
197191 struct brcmf_p2psd_gas_pub_act_frame {
198192 u8 category;
....@@ -207,7 +201,7 @@
207201 * @mpc_onoff: To make sure to send successfully action frame, we have to
208202 * turn off mpc 0: off, 1: on, (-1): do nothing
209203 * @search_channel: 1: search peer's channel to send af
210
- * extra_listen: keep the dwell time to get af response frame.
204
+ * @extra_listen: keep the dwell time to get af response frame.
211205 */
212206 struct brcmf_config_af_params {
213207 s32 mpc_onoff;
....@@ -434,6 +428,7 @@
434428 */
435429 static int brcmf_p2p_set_firmware(struct brcmf_if *ifp, u8 *p2p_mac)
436430 {
431
+ struct brcmf_pub *drvr = ifp->drvr;
437432 s32 ret = 0;
438433
439434 brcmf_fil_cmd_int_set(ifp, BRCMF_C_DOWN, 1);
....@@ -450,7 +445,7 @@
450445 ret = brcmf_fil_iovar_data_set(ifp, "p2p_da_override", p2p_mac,
451446 ETH_ALEN);
452447 if (ret)
453
- brcmf_err("failed to update device address ret %d\n", ret);
448
+ bphy_err(drvr, "failed to update device address ret %d\n", ret);
454449
455450 return ret;
456451 }
....@@ -467,10 +462,21 @@
467462 */
468463 static void brcmf_p2p_generate_bss_mac(struct brcmf_p2p_info *p2p, u8 *dev_addr)
469464 {
465
+ struct brcmf_if *pri_ifp = p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif->ifp;
470466 bool random_addr = false;
467
+ bool local_admin = false;
471468
472
- if (!dev_addr || is_zero_ether_addr(dev_addr))
473
- random_addr = true;
469
+ if (!dev_addr || is_zero_ether_addr(dev_addr)) {
470
+ /* If the primary interface address is already locally
471
+ * administered, create a new random address.
472
+ */
473
+ if (pri_ifp->mac_addr[0] & 0x02) {
474
+ random_addr = true;
475
+ } else {
476
+ dev_addr = pri_ifp->mac_addr;
477
+ local_admin = true;
478
+ }
479
+ }
474480
475481 /* Generate the P2P Device Address obtaining a random ethernet
476482 * address with the locally administered bit set.
....@@ -480,13 +486,20 @@
480486 else
481487 memcpy(p2p->dev_addr, dev_addr, ETH_ALEN);
482488
489
+ if (local_admin)
490
+ p2p->dev_addr[0] |= 0x02;
491
+
483492 /* Generate the P2P Interface Address. If the discovery and connection
484493 * BSSCFGs need to simultaneously co-exist, then this address must be
485494 * different from the P2P Device Address, but also locally administered.
486495 */
487
- memcpy(p2p->int_addr, p2p->dev_addr, ETH_ALEN);
488
- p2p->int_addr[0] |= 0x02;
489
- p2p->int_addr[4] ^= 0x80;
496
+ memcpy(p2p->conn_int_addr, p2p->dev_addr, ETH_ALEN);
497
+ p2p->conn_int_addr[0] |= 0x02;
498
+ p2p->conn_int_addr[4] ^= 0x80;
499
+
500
+ memcpy(p2p->conn2_int_addr, p2p->dev_addr, ETH_ALEN);
501
+ p2p->conn2_int_addr[0] |= 0x02;
502
+ p2p->conn2_int_addr[4] ^= 0x90;
490503 }
491504
492505 /**
....@@ -570,13 +583,14 @@
570583 */
571584 static int brcmf_p2p_enable_discovery(struct brcmf_p2p_info *p2p)
572585 {
586
+ struct brcmf_pub *drvr = p2p->cfg->pub;
573587 struct brcmf_cfg80211_vif *vif;
574588 s32 ret = 0;
575589
576590 brcmf_dbg(TRACE, "enter\n");
577591 vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
578592 if (!vif) {
579
- brcmf_err("P2P config device not available\n");
593
+ bphy_err(drvr, "P2P config device not available\n");
580594 ret = -EPERM;
581595 goto exit;
582596 }
....@@ -590,13 +604,13 @@
590604 vif = p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif;
591605 ret = brcmf_fil_iovar_int_set(vif->ifp, "p2p_disc", 1);
592606 if (ret < 0) {
593
- brcmf_err("set p2p_disc error\n");
607
+ bphy_err(drvr, "set p2p_disc error\n");
594608 goto exit;
595609 }
596610 vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
597611 ret = brcmf_p2p_set_discover_state(vif->ifp, WL_P2P_DISC_ST_SCAN, 0, 0);
598612 if (ret < 0) {
599
- brcmf_err("unable to set WL_P2P_DISC_ST_SCAN\n");
613
+ bphy_err(drvr, "unable to set WL_P2P_DISC_ST_SCAN\n");
600614 goto exit;
601615 }
602616
....@@ -608,7 +622,7 @@
608622 */
609623 ret = brcmf_fil_bsscfg_int_set(vif->ifp, "wsec", AES_ENABLED);
610624 if (ret < 0) {
611
- brcmf_err("wsec error %d\n", ret);
625
+ bphy_err(drvr, "wsec error %d\n", ret);
612626 goto exit;
613627 }
614628
....@@ -630,6 +644,7 @@
630644 u16 chanspecs[], s32 search_state,
631645 enum p2p_bss_type bss_type)
632646 {
647
+ struct brcmf_pub *drvr = p2p->cfg->pub;
633648 s32 ret = 0;
634649 s32 memsize = offsetof(struct brcmf_p2p_scan_le,
635650 eparams.params_le.channel_list);
....@@ -648,7 +663,7 @@
648663
649664 vif = p2p->bss_idx[bss_type].vif;
650665 if (vif == NULL) {
651
- brcmf_err("no vif for bss type %d\n", bss_type);
666
+ bphy_err(drvr, "no vif for bss type %d\n", bss_type);
652667 ret = -EINVAL;
653668 goto exit;
654669 }
....@@ -676,7 +691,7 @@
676691 BRCMF_P2P_WILDCARD_SSID_LEN);
677692 break;
678693 default:
679
- brcmf_err(" invalid search state %d\n", search_state);
694
+ bphy_err(drvr, " invalid search state %d\n", search_state);
680695 ret = -EINVAL;
681696 goto exit;
682697 }
....@@ -748,9 +763,8 @@
748763 * brcmf_p2p_run_escan() - escan callback for peer-to-peer.
749764 *
750765 * @cfg: driver private data for cfg80211 interface.
751
- * @ndev: net device for which scan is requested.
766
+ * @ifp: interface control.
752767 * @request: scan request from cfg80211.
753
- * @action: scan action.
754768 *
755769 * Determines the P2P discovery state based to scan request parameters and
756770 * validates the channels in the request.
....@@ -760,6 +774,7 @@
760774 struct cfg80211_scan_request *request)
761775 {
762776 struct brcmf_p2p_info *p2p = &cfg->p2p;
777
+ struct brcmf_pub *drvr = cfg->pub;
763778 s32 err = 0;
764779 s32 search_state = WL_P2P_DISC_ST_SCAN;
765780 struct brcmf_cfg80211_vif *vif;
....@@ -822,7 +837,7 @@
822837 }
823838 exit:
824839 if (err)
825
- brcmf_err("error (%d)\n", err);
840
+ bphy_err(drvr, "error (%d)\n", err);
826841 return err;
827842 }
828843
....@@ -897,8 +912,6 @@
897912 if (err)
898913 return err;
899914
900
- vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
901
-
902915 /* override .run_escan() callback. */
903916 cfg->escan_info.run = brcmf_p2p_run_escan;
904917 }
....@@ -917,19 +930,20 @@
917930 static s32
918931 brcmf_p2p_discover_listen(struct brcmf_p2p_info *p2p, u16 channel, u32 duration)
919932 {
933
+ struct brcmf_pub *drvr = p2p->cfg->pub;
920934 struct brcmf_cfg80211_vif *vif;
921935 struct brcmu_chan ch;
922936 s32 err = 0;
923937
924938 vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
925939 if (!vif) {
926
- brcmf_err("Discovery is not set, so we have nothing to do\n");
940
+ bphy_err(drvr, "Discovery is not set, so we have nothing to do\n");
927941 err = -EPERM;
928942 goto exit;
929943 }
930944
931945 if (test_bit(BRCMF_P2P_STATUS_DISCOVER_LISTEN, &p2p->status)) {
932
- brcmf_err("Previous LISTEN is not completed yet\n");
946
+ bphy_err(drvr, "Previous LISTEN is not completed yet\n");
933947 /* WAR: prevent cookie mismatch in wpa_supplicant return OK */
934948 goto exit;
935949 }
....@@ -952,9 +966,10 @@
952966 * brcmf_p2p_remain_on_channel() - put device on channel and stay there.
953967 *
954968 * @wiphy: wiphy device.
969
+ * @wdev: wireless device.
955970 * @channel: channel to stay on.
956971 * @duration: time in ms to remain on channel.
957
- *
972
+ * @cookie: cookie.
958973 */
959974 int brcmf_p2p_remain_on_channel(struct wiphy *wiphy, struct wireless_dev *wdev,
960975 struct ieee80211_channel *channel,
....@@ -1039,13 +1054,14 @@
10391054 * brcmf_p2p_act_frm_search() - search function for action frame.
10401055 *
10411056 * @p2p: p2p device.
1042
- * channel: channel on which action frame is to be trasmitted.
1057
+ * @channel: channel on which action frame is to be trasmitted.
10431058 *
10441059 * search function to reach at common channel to send action frame. When
10451060 * channel is 0 then all social channels will be used to send af
10461061 */
10471062 static s32 brcmf_p2p_act_frm_search(struct brcmf_p2p_info *p2p, u16 channel)
10481063 {
1064
+ struct brcmf_pub *drvr = p2p->cfg->pub;
10491065 s32 err;
10501066 u32 channel_cnt;
10511067 u16 *default_chan_list;
....@@ -1061,7 +1077,7 @@
10611077 default_chan_list = kcalloc(channel_cnt, sizeof(*default_chan_list),
10621078 GFP_KERNEL);
10631079 if (default_chan_list == NULL) {
1064
- brcmf_err("channel list allocation failed\n");
1080
+ bphy_err(drvr, "channel list allocation failed\n");
10651081 err = -ENOMEM;
10661082 goto exit;
10671083 }
....@@ -1103,6 +1119,7 @@
11031119 struct brcmf_p2p_info *p2p = container_of(afx_hdl,
11041120 struct brcmf_p2p_info,
11051121 afx_hdl);
1122
+ struct brcmf_pub *drvr = p2p->cfg->pub;
11061123 s32 err;
11071124
11081125 if (!afx_hdl->is_active)
....@@ -1116,7 +1133,7 @@
11161133 err = brcmf_p2p_act_frm_search(p2p, afx_hdl->peer_listen_chan);
11171134
11181135 if (err) {
1119
- brcmf_err("ERROR occurred! value is (%d)\n", err);
1136
+ bphy_err(drvr, "ERROR occurred! value is (%d)\n", err);
11201137 if (test_bit(BRCMF_P2P_STATUS_FINDING_COMMON_CHANNEL,
11211138 &p2p->status))
11221139 complete(&afx_hdl->act_frm_scan);
....@@ -1249,6 +1266,30 @@
12491266 }
12501267
12511268 /**
1269
+ * brcmf_p2p_abort_action_frame() - abort action frame.
1270
+ *
1271
+ * @cfg: common configuration struct.
1272
+ *
1273
+ */
1274
+static s32 brcmf_p2p_abort_action_frame(struct brcmf_cfg80211_info *cfg)
1275
+{
1276
+ struct brcmf_p2p_info *p2p = &cfg->p2p;
1277
+ struct brcmf_cfg80211_vif *vif;
1278
+ s32 err;
1279
+ s32 int_val = 1;
1280
+
1281
+ brcmf_dbg(TRACE, "Enter\n");
1282
+
1283
+ vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
1284
+ err = brcmf_fil_bsscfg_data_set(vif->ifp, "actframe_abort", &int_val,
1285
+ sizeof(s32));
1286
+ if (err)
1287
+ brcmf_err(" aborting action frame has failed (%d)\n", err);
1288
+
1289
+ return err;
1290
+}
1291
+
1292
+/**
12521293 * brcmf_p2p_stop_wait_next_action_frame() - finish scan if af tx complete.
12531294 *
12541295 * @cfg: common configuration struct.
....@@ -1259,6 +1300,7 @@
12591300 {
12601301 struct brcmf_p2p_info *p2p = &cfg->p2p;
12611302 struct brcmf_if *ifp = p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif->ifp;
1303
+ s32 err;
12621304
12631305 if (test_bit(BRCMF_P2P_STATUS_SENDING_ACT_FRAME, &p2p->status) &&
12641306 (test_bit(BRCMF_P2P_STATUS_ACTION_TX_COMPLETED, &p2p->status) ||
....@@ -1267,8 +1309,13 @@
12671309 /* if channel is not zero, "actfame" uses off channel scan.
12681310 * So abort scan for off channel completion.
12691311 */
1270
- if (p2p->af_sent_channel)
1271
- brcmf_notify_escan_complete(cfg, ifp, true, true);
1312
+ if (p2p->af_sent_channel) {
1313
+ /* abort actframe using actframe_abort or abort scan */
1314
+ err = brcmf_p2p_abort_action_frame(cfg);
1315
+ if (err)
1316
+ brcmf_notify_escan_complete(cfg, ifp, true,
1317
+ true);
1318
+ }
12721319 } else if (test_bit(BRCMF_P2P_STATUS_WAITING_NEXT_AF_LISTEN,
12731320 &p2p->status)) {
12741321 brcmf_dbg(TRACE, "*** Wake UP ** abort listen for next af frame\n");
....@@ -1282,6 +1329,7 @@
12821329 * brcmf_p2p_gon_req_collision() - Check if go negotiaton collission
12831330 *
12841331 * @p2p: p2p device info struct.
1332
+ * @mac: MAC address.
12851333 *
12861334 * return true if recevied action frame is to be dropped.
12871335 */
....@@ -1338,7 +1386,8 @@
13381386 const struct brcmf_event_msg *e,
13391387 void *data)
13401388 {
1341
- struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
1389
+ struct brcmf_pub *drvr = ifp->drvr;
1390
+ struct brcmf_cfg80211_info *cfg = drvr->config;
13421391 struct brcmf_p2p_info *p2p = &cfg->p2p;
13431392 struct afx_hdl *afx_hdl = &p2p->afx_hdl;
13441393 struct wireless_dev *wdev;
....@@ -1409,7 +1458,7 @@
14091458 mgmt_frame = kzalloc(offsetof(struct ieee80211_mgmt, u) +
14101459 mgmt_frame_len, GFP_KERNEL);
14111460 if (!mgmt_frame) {
1412
- brcmf_err("No memory available for action frame\n");
1461
+ bphy_err(drvr, "No memory available for action frame\n");
14131462 return -ENOMEM;
14141463 }
14151464 memcpy(mgmt_frame->da, ifp->mac_addr, ETH_ALEN);
....@@ -1492,9 +1541,10 @@
14921541 static s32 brcmf_p2p_tx_action_frame(struct brcmf_p2p_info *p2p,
14931542 struct brcmf_fil_af_params_le *af_params)
14941543 {
1544
+ struct brcmf_pub *drvr = p2p->cfg->pub;
14951545 struct brcmf_cfg80211_vif *vif;
1546
+ struct brcmf_p2p_action_frame *p2p_af;
14961547 s32 err = 0;
1497
- s32 timeout = 0;
14981548
14991549 brcmf_dbg(TRACE, "Enter\n");
15001550
....@@ -1502,11 +1552,17 @@
15021552 clear_bit(BRCMF_P2P_STATUS_ACTION_TX_COMPLETED, &p2p->status);
15031553 clear_bit(BRCMF_P2P_STATUS_ACTION_TX_NOACK, &p2p->status);
15041554
1505
- vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
1555
+ /* check if it is a p2p_presence response */
1556
+ p2p_af = (struct brcmf_p2p_action_frame *)af_params->action_frame.data;
1557
+ if (p2p_af->subtype == P2P_AF_PRESENCE_RSP)
1558
+ vif = p2p->bss_idx[P2PAPI_BSSCFG_CONNECTION].vif;
1559
+ else
1560
+ vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
1561
+
15061562 err = brcmf_fil_bsscfg_data_set(vif->ifp, "actframe", af_params,
15071563 sizeof(*af_params));
15081564 if (err) {
1509
- brcmf_err(" sending action frame has failed\n");
1565
+ bphy_err(drvr, " sending action frame has failed\n");
15101566 goto exit;
15111567 }
15121568
....@@ -1524,8 +1580,7 @@
15241580 (p2p->wait_for_offchan_complete) ?
15251581 "off-channel" : "on-channel");
15261582
1527
- timeout = wait_for_completion_timeout(&p2p->send_af_done,
1528
- P2P_AF_MAX_WAIT_TIME);
1583
+ wait_for_completion_timeout(&p2p->send_af_done, P2P_AF_MAX_WAIT_TIME);
15291584
15301585 if (test_bit(BRCMF_P2P_STATUS_ACTION_TX_COMPLETED, &p2p->status)) {
15311586 brcmf_dbg(TRACE, "TX action frame operation is success\n");
....@@ -1556,6 +1611,7 @@
15561611 struct brcmf_config_af_params *config_af_params)
15571612 {
15581613 struct brcmf_p2p_info *p2p = &cfg->p2p;
1614
+ struct brcmf_pub *drvr = cfg->pub;
15591615 struct brcmf_fil_action_frame_le *action_frame;
15601616 struct brcmf_p2p_pub_act_frame *act_frm;
15611617 s32 err = 0;
....@@ -1634,13 +1690,24 @@
16341690 config_af_params->extra_listen = false;
16351691 break;
16361692 default:
1637
- brcmf_err("Unknown p2p pub act frame subtype: %d\n",
1638
- act_frm->subtype);
1693
+ bphy_err(drvr, "Unknown p2p pub act frame subtype: %d\n",
1694
+ act_frm->subtype);
16391695 err = -EINVAL;
16401696 }
16411697 return err;
16421698 }
16431699
1700
+static bool brcmf_p2p_check_dwell_overflow(u32 requested_dwell,
1701
+ unsigned long dwell_jiffies)
1702
+{
1703
+ if ((requested_dwell & CUSTOM_RETRY_MASK) &&
1704
+ (jiffies_to_msecs(jiffies - dwell_jiffies) >
1705
+ (requested_dwell & ~CUSTOM_RETRY_MASK))) {
1706
+ brcmf_err("Action frame TX retry time over dwell time!\n");
1707
+ return true;
1708
+ }
1709
+ return false;
1710
+}
16441711 /**
16451712 * brcmf_p2p_send_action_frame() - send action frame .
16461713 *
....@@ -1657,6 +1724,7 @@
16571724 struct brcmf_fil_action_frame_le *action_frame;
16581725 struct brcmf_config_af_params config_af_params;
16591726 struct afx_hdl *afx_hdl = &p2p->afx_hdl;
1727
+ struct brcmf_pub *drvr = cfg->pub;
16601728 u16 action_frame_len;
16611729 bool ack = false;
16621730 u8 category;
....@@ -1664,7 +1732,10 @@
16641732 s32 tx_retry;
16651733 s32 extra_listen_time;
16661734 uint delta_ms;
1735
+ unsigned long dwell_jiffies = 0;
1736
+ bool dwell_overflow = false;
16671737
1738
+ u32 requested_dwell = le32_to_cpu(af_params->dwell_time);
16681739 action_frame = &af_params->action_frame;
16691740 action_frame_len = le16_to_cpu(action_frame->len);
16701741
....@@ -1692,7 +1763,7 @@
16921763 if (brcmf_p2p_pub_af_tx(cfg, af_params, &config_af_params)) {
16931764 /* Just send unknown subtype frame with */
16941765 /* default parameters. */
1695
- brcmf_err("P2P Public action frame, unknown subtype.\n");
1766
+ bphy_err(drvr, "P2P Public action frame, unknown subtype.\n");
16961767 }
16971768 } else if (brcmf_p2p_is_gas_action(action_frame->data,
16981769 action_frame_len)) {
....@@ -1714,7 +1785,7 @@
17141785 af_params->dwell_time =
17151786 cpu_to_le32(P2P_AF_MIN_DWELL_TIME);
17161787 } else {
1717
- brcmf_err("Unknown action type: %d\n", action);
1788
+ bphy_err(drvr, "Unknown action type: %d\n", action);
17181789 goto exit;
17191790 }
17201791 } else if (brcmf_p2p_is_p2p_action(action_frame->data,
....@@ -1722,8 +1793,8 @@
17221793 /* do not configure anything. it will be */
17231794 /* sent with a default configuration */
17241795 } else {
1725
- brcmf_err("Unknown Frame: category 0x%x, action 0x%x\n",
1726
- category, action);
1796
+ bphy_err(drvr, "Unknown Frame: category 0x%x, action 0x%x\n",
1797
+ category, action);
17271798 return false;
17281799 }
17291800
....@@ -1761,7 +1832,7 @@
17611832
17621833 if (brcmf_p2p_af_searching_channel(p2p) ==
17631834 P2P_INVALID_CHANNEL) {
1764
- brcmf_err("Couldn't find peer's channel.\n");
1835
+ bphy_err(drvr, "Couldn't find peer's channel.\n");
17651836 goto exit;
17661837 }
17671838
....@@ -1775,15 +1846,25 @@
17751846 /* update channel */
17761847 af_params->channel = cpu_to_le32(afx_hdl->peer_chan);
17771848 }
1849
+ dwell_jiffies = jiffies;
1850
+ dwell_overflow = brcmf_p2p_check_dwell_overflow(requested_dwell,
1851
+ dwell_jiffies);
17781852
17791853 tx_retry = 0;
17801854 while (!p2p->block_gon_req_tx &&
1781
- (ack == false) && (tx_retry < P2P_AF_TX_MAX_RETRY)) {
1855
+ (!ack) && (tx_retry < P2P_AF_TX_MAX_RETRY) &&
1856
+ !dwell_overflow) {
1857
+ if (af_params->channel)
1858
+ msleep(P2P_AF_RETRY_DELAY_TIME);
1859
+
17821860 ack = !brcmf_p2p_tx_action_frame(p2p, af_params);
17831861 tx_retry++;
1862
+ dwell_overflow = brcmf_p2p_check_dwell_overflow(requested_dwell,
1863
+ dwell_jiffies);
17841864 }
1785
- if (ack == false) {
1786
- brcmf_err("Failed to send Action Frame(retry %d)\n", tx_retry);
1865
+ if (!ack) {
1866
+ bphy_err(drvr, "Failed to send Action Frame(retry %d)\n",
1867
+ tx_retry);
17871868 clear_bit(BRCMF_P2P_STATUS_GO_NEG_PHASE, &p2p->status);
17881869 }
17891870
....@@ -1957,14 +2038,15 @@
19572038
19582039 /**
19592040 * Change a P2P Role.
1960
- * Parameters:
1961
- * @mac: MAC address of the BSS to change a role
2041
+ * @cfg: driver private data for cfg80211 interface.
2042
+ * @if_type: interface type.
19622043 * Returns 0 if success.
19632044 */
19642045 int brcmf_p2p_ifchange(struct brcmf_cfg80211_info *cfg,
19652046 enum brcmf_fil_p2p_if_types if_type)
19662047 {
19672048 struct brcmf_p2p_info *p2p = &cfg->p2p;
2049
+ struct brcmf_pub *drvr = cfg->pub;
19682050 struct brcmf_cfg80211_vif *vif;
19692051 struct brcmf_fil_p2p_if_le if_request;
19702052 s32 err;
....@@ -1974,13 +2056,13 @@
19742056
19752057 vif = p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif;
19762058 if (!vif) {
1977
- brcmf_err("vif for P2PAPI_BSSCFG_PRIMARY does not exist\n");
2059
+ bphy_err(drvr, "vif for P2PAPI_BSSCFG_PRIMARY does not exist\n");
19782060 return -EPERM;
19792061 }
19802062 brcmf_notify_escan_complete(cfg, vif->ifp, true, true);
19812063 vif = p2p->bss_idx[P2PAPI_BSSCFG_CONNECTION].vif;
19822064 if (!vif) {
1983
- brcmf_err("vif for P2PAPI_BSSCFG_CONNECTION does not exist\n");
2065
+ bphy_err(drvr, "vif for P2PAPI_BSSCFG_CONNECTION does not exist\n");
19842066 return -EPERM;
19852067 }
19862068 brcmf_set_mpc(vif->ifp, 0);
....@@ -1992,13 +2074,13 @@
19922074
19932075 if_request.type = cpu_to_le16((u16)if_type);
19942076 if_request.chspec = cpu_to_le16(chanspec);
1995
- memcpy(if_request.addr, p2p->int_addr, sizeof(if_request.addr));
2077
+ memcpy(if_request.addr, p2p->conn_int_addr, sizeof(if_request.addr));
19962078
19972079 brcmf_cfg80211_arm_vif_event(cfg, vif);
19982080 err = brcmf_fil_iovar_data_set(vif->ifp, "p2p_ifupd", &if_request,
19992081 sizeof(if_request));
20002082 if (err) {
2001
- brcmf_err("p2p_ifupd FAILED, err=%d\n", err);
2083
+ bphy_err(drvr, "p2p_ifupd FAILED, err=%d\n", err);
20022084 brcmf_cfg80211_arm_vif_event(cfg, NULL);
20032085 return err;
20042086 }
....@@ -2006,7 +2088,7 @@
20062088 BRCMF_VIF_EVENT_TIMEOUT);
20072089 brcmf_cfg80211_arm_vif_event(cfg, NULL);
20082090 if (!err) {
2009
- brcmf_err("No BRCMF_E_IF_CHANGE event received\n");
2091
+ bphy_err(drvr, "No BRCMF_E_IF_CHANGE event received\n");
20102092 return -EIO;
20112093 }
20122094
....@@ -2069,6 +2151,7 @@
20692151 struct wiphy *wiphy,
20702152 u8 *addr)
20712153 {
2154
+ struct brcmf_pub *drvr = p2p->cfg->pub;
20722155 struct brcmf_cfg80211_vif *p2p_vif;
20732156 struct brcmf_if *p2p_ifp;
20742157 struct brcmf_if *pri_ifp;
....@@ -2080,7 +2163,7 @@
20802163
20812164 p2p_vif = brcmf_alloc_vif(p2p->cfg, NL80211_IFTYPE_P2P_DEVICE);
20822165 if (IS_ERR(p2p_vif)) {
2083
- brcmf_err("could not create discovery vif\n");
2166
+ bphy_err(drvr, "could not create discovery vif\n");
20842167 return (struct wireless_dev *)p2p_vif;
20852168 }
20862169
....@@ -2088,8 +2171,9 @@
20882171
20892172 /* firmware requires unique mac address for p2pdev interface */
20902173 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);
2174
+ bphy_err(drvr, "discovery vif must be different from primary interface\n");
2175
+ err = -EINVAL;
2176
+ goto fail;
20932177 }
20942178
20952179 brcmf_p2p_generate_bss_mac(p2p, addr);
....@@ -2101,7 +2185,7 @@
21012185 /* Initialize P2P Discovery in the firmware */
21022186 err = brcmf_fil_iovar_int_set(pri_ifp, "p2p_disc", 1);
21032187 if (err < 0) {
2104
- brcmf_err("set p2p_disc error\n");
2188
+ bphy_err(drvr, "set p2p_disc error\n");
21052189 brcmf_fweh_p2pdev_setup(pri_ifp, false);
21062190 brcmf_cfg80211_arm_vif_event(p2p->cfg, NULL);
21072191 goto fail;
....@@ -2113,7 +2197,7 @@
21132197 brcmf_cfg80211_arm_vif_event(p2p->cfg, NULL);
21142198 brcmf_fweh_p2pdev_setup(pri_ifp, false);
21152199 if (!err) {
2116
- brcmf_err("timeout occurred\n");
2200
+ bphy_err(drvr, "timeout occurred\n");
21172201 err = -EIO;
21182202 goto fail;
21192203 }
....@@ -2127,7 +2211,7 @@
21272211 /* verify bsscfg index for P2P discovery */
21282212 err = brcmf_fil_iovar_int_get(pri_ifp, "p2p_dev", &bsscfgidx);
21292213 if (err < 0) {
2130
- brcmf_err("retrieving discover bsscfg index failed\n");
2214
+ bphy_err(drvr, "retrieving discover bsscfg index failed\n");
21312215 goto fail;
21322216 }
21332217
....@@ -2143,6 +2227,27 @@
21432227 fail:
21442228 brcmf_free_vif(p2p_vif);
21452229 return ERR_PTR(err);
2230
+}
2231
+
2232
+static int brcmf_p2p_get_conn_idx(struct brcmf_cfg80211_info *cfg)
2233
+{
2234
+ int i;
2235
+ struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg));
2236
+
2237
+ if (!ifp)
2238
+ return -ENODEV;
2239
+
2240
+ for (i = P2PAPI_BSSCFG_CONNECTION; i < P2PAPI_BSSCFG_MAX; i++) {
2241
+ if (!cfg->p2p.bss_idx[i].vif) {
2242
+ if (i == P2PAPI_BSSCFG_CONNECTION2 &&
2243
+ !(brcmf_feat_is_enabled(ifp, BRCMF_FEAT_RSDB))) {
2244
+ brcmf_err("Multi p2p not supported");
2245
+ return -EIO;
2246
+ }
2247
+ return i;
2248
+ }
2249
+ }
2250
+ return -EIO;
21462251 }
21472252
21482253 /**
....@@ -2161,9 +2266,12 @@
21612266 {
21622267 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
21632268 struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg));
2269
+ struct brcmf_pub *drvr = cfg->pub;
21642270 struct brcmf_cfg80211_vif *vif;
21652271 enum brcmf_fil_p2p_if_types iftype;
2166
- int err;
2272
+ int err = 0;
2273
+ int connidx;
2274
+ u8 *p2p_intf_addr;
21672275
21682276 if (brcmf_cfg80211_vif_event_armed(cfg))
21692277 return ERR_PTR(-EBUSY);
....@@ -2189,9 +2297,21 @@
21892297 return (struct wireless_dev *)vif;
21902298 brcmf_cfg80211_arm_vif_event(cfg, vif);
21912299
2192
- err = brcmf_p2p_request_p2p_if(&cfg->p2p, ifp, cfg->p2p.int_addr,
2193
- iftype);
2300
+ connidx = brcmf_p2p_get_conn_idx(cfg);
2301
+
2302
+ if (connidx == P2PAPI_BSSCFG_CONNECTION)
2303
+ p2p_intf_addr = cfg->p2p.conn_int_addr;
2304
+ else if (connidx == P2PAPI_BSSCFG_CONNECTION2)
2305
+ p2p_intf_addr = cfg->p2p.conn2_int_addr;
2306
+ else
2307
+ err = -EINVAL;
2308
+
2309
+ if (!err)
2310
+ err = brcmf_p2p_request_p2p_if(&cfg->p2p, ifp,
2311
+ p2p_intf_addr, iftype);
2312
+
21942313 if (err) {
2314
+ brcmf_err("request p2p interface failed\n");
21952315 brcmf_cfg80211_arm_vif_event(cfg, NULL);
21962316 goto fail;
21972317 }
....@@ -2201,7 +2321,7 @@
22012321 BRCMF_VIF_EVENT_TIMEOUT);
22022322 brcmf_cfg80211_arm_vif_event(cfg, NULL);
22032323 if (!err) {
2204
- brcmf_err("timeout occurred\n");
2324
+ bphy_err(drvr, "timeout occurred\n");
22052325 err = -EIO;
22062326 goto fail;
22072327 }
....@@ -2209,7 +2329,7 @@
22092329 /* interface created in firmware */
22102330 ifp = vif->ifp;
22112331 if (!ifp) {
2212
- brcmf_err("no if pointer provided\n");
2332
+ bphy_err(drvr, "no if pointer provided\n");
22132333 err = -ENOENT;
22142334 goto fail;
22152335 }
....@@ -2218,12 +2338,12 @@
22182338 ifp->ndev->name_assign_type = name_assign_type;
22192339 err = brcmf_net_attach(ifp, true);
22202340 if (err) {
2221
- brcmf_err("Registering netdevice failed\n");
2341
+ bphy_err(drvr, "Registering netdevice failed\n");
22222342 free_netdev(ifp->ndev);
22232343 goto fail;
22242344 }
22252345
2226
- cfg->p2p.bss_idx[P2PAPI_BSSCFG_CONNECTION].vif = vif;
2346
+ cfg->p2p.bss_idx[connidx].vif = vif;
22272347 /* Disable firmware roaming for P2P interface */
22282348 brcmf_fil_iovar_int_set(ifp, "roam_off", 1);
22292349 if (iftype == BRCMF_FIL_P2P_IF_GO) {
....@@ -2373,6 +2493,7 @@
23732493 */
23742494 s32 brcmf_p2p_attach(struct brcmf_cfg80211_info *cfg, bool p2pdev_forced)
23752495 {
2496
+ struct brcmf_pub *drvr = cfg->pub;
23762497 struct brcmf_p2p_info *p2p;
23772498 struct brcmf_if *pri_ifp;
23782499 s32 err = 0;
....@@ -2387,7 +2508,7 @@
23872508 if (p2pdev_forced) {
23882509 err_ptr = brcmf_p2p_create_p2pdev(p2p, NULL, NULL);
23892510 if (IS_ERR(err_ptr)) {
2390
- brcmf_err("P2P device creation failed.\n");
2511
+ bphy_err(drvr, "P2P device creation failed.\n");
23912512 err = PTR_ERR(err_ptr);
23922513 }
23932514 } else {