brcmfmac: only generate random p2p address when needed

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
This commit is contained in:
Chi-Hsien Lin 2020-04-27 02:00:02 -05:00 committed by Kalle Valo
parent d524d5ce36
commit 053ac9e143
1 changed files with 16 additions and 2 deletions

View 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.