brcmfmac: only generate random p2p address when needed
authorChi-Hsien Lin <chi-hsien.lin@cypress.com>
Mon, 27 Apr 2020 07:00:02 +0000 (02:00 -0500)
committerKalle Valo <kvalo@codeaurora.org>
Mon, 4 May 2020 09:48:44 +0000 (12:48 +0300)
P2p spec mentioned that the p2p device address should be the globally
administered address with locally administered bit set. Therefore,
follow this guideline by default.

When the primary interface is set to a locally administered address, the
locally administered bit cannot be set again. Generate a random locally
administered address for this case.

Reviewed-by: Arend van Spriel <arend.vanspriel@broadcom.com>
Signed-off-by: Chi-Hsien Lin <chi-hsien.lin@cypress.com>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
Link: https://lore.kernel.org/r/1587970803-77700-5-git-send-email-chi-hsien.lin@cypress.com
drivers/net/wireless/broadcom/brcm80211/brcmfmac/p2p.c

index c68edb1..f8ece9f 100644 (file)
@@ -457,10 +457,21 @@ static int brcmf_p2p_set_firmware(struct brcmf_if *ifp, u8 *p2p_mac)
  */
 static void brcmf_p2p_generate_bss_mac(struct brcmf_p2p_info *p2p, u8 *dev_addr)
 {
+       struct brcmf_if *pri_ifp = p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif->ifp;
        bool random_addr = false;
+       bool local_admin = false;
 
-       if (!dev_addr || is_zero_ether_addr(dev_addr))
-               random_addr = true;
+       if (!dev_addr || is_zero_ether_addr(dev_addr)) {
+               /* If the primary interface address is already locally
+                * administered, create a new random address.
+                */
+               if (pri_ifp->mac_addr[0] & 0x02) {
+                       random_addr = true;
+               } else {
+                       dev_addr = pri_ifp->mac_addr;
+                       local_admin = true;
+               }
+       }
 
        /* Generate the P2P Device Address obtaining a random ethernet
         * address with the locally administered bit set.
@@ -470,6 +481,9 @@ static void brcmf_p2p_generate_bss_mac(struct brcmf_p2p_info *p2p, u8 *dev_addr)
        else
                memcpy(p2p->dev_addr, dev_addr, ETH_ALEN);
 
+       if (local_admin)
+               p2p->dev_addr[0] |= 0x02;
+
        /* Generate the P2P Interface Address.  If the discovery and connection
         * BSSCFGs need to simultaneously co-exist, then this address must be
         * different from the P2P Device Address, but also locally administered.