mwifiex: set different mac address for interfaces with same bss type
authorXinming Hu <huxm@marvell.com>
Tue, 13 Feb 2018 06:10:15 +0000 (14:10 +0800)
committerKalle Valo <kvalo@codeaurora.org>
Tue, 27 Feb 2018 16:20:22 +0000 (18:20 +0200)
Multiple interfaces with same bss type could affect each other if
they are sharing the same mac address. In this patch, different
mac address is assigned to new interface which have same bss type
with exist interfaces.

Signed-off-by: Xinming Hu <huxm@marvell.com>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
drivers/net/wireless/marvell/mwifiex/main.c
drivers/net/wireless/marvell/mwifiex/main.h

index 12e7399..b648458 100644 (file)
@@ -943,13 +943,26 @@ int mwifiex_set_mac_address(struct mwifiex_private *priv,
                            struct net_device *dev)
 {
        int ret;
-       u64 mac_addr;
+       u64 mac_addr, old_mac_addr;
 
-       if (priv->bss_type != MWIFIEX_BSS_TYPE_P2P)
-               goto done;
+       if (priv->bss_type == MWIFIEX_BSS_TYPE_ANY)
+               return -ENOTSUPP;
 
        mac_addr = ether_addr_to_u64(priv->curr_addr);
-       mac_addr |= BIT_ULL(MWIFIEX_MAC_LOCAL_ADMIN_BIT);
+       old_mac_addr = mac_addr;
+
+       if (priv->bss_type == MWIFIEX_BSS_TYPE_P2P)
+               mac_addr |= BIT_ULL(MWIFIEX_MAC_LOCAL_ADMIN_BIT);
+
+       if (mwifiex_get_intf_num(priv->adapter, priv->bss_type) > 1) {
+               /* Set mac address based on bss_type/bss_num */
+               mac_addr ^= BIT_ULL(priv->bss_type + 8);
+               mac_addr += priv->bss_num;
+       }
+
+       if (mac_addr == old_mac_addr)
+               goto done;
+
        u64_to_ether_addr(mac_addr, priv->curr_addr);
 
        /* Send request to firmware */
@@ -957,13 +970,14 @@ int mwifiex_set_mac_address(struct mwifiex_private *priv,
                               HostCmd_ACT_GEN_SET, 0, NULL, true);
 
        if (ret) {
+               u64_to_ether_addr(old_mac_addr, priv->curr_addr);
                mwifiex_dbg(priv->adapter, ERROR,
                            "set mac address failed: ret=%d\n", ret);
                return ret;
        }
 
 done:
-       memcpy(dev->dev_addr, priv->curr_addr, ETH_ALEN);
+       ether_addr_copy(dev->dev_addr, priv->curr_addr);
        return 0;
 }
 
index 6b5539b..58e6ae5 100644 (file)
@@ -1280,6 +1280,19 @@ mwifiex_copy_rates(u8 *dest, u32 pos, u8 *src, int len)
        return pos;
 }
 
+/* This function return interface number with the same bss_type.
+ */
+static inline u8
+mwifiex_get_intf_num(struct mwifiex_adapter *adapter, u8 bss_type)
+{
+       u8 i, num = 0;
+
+       for (i = 0; i < adapter->priv_num; i++)
+               if (adapter->priv[i] && adapter->priv[i]->bss_type == bss_type)
+                       num++;
+       return num;
+}
+
 /*
  * This function returns the correct private structure pointer based
  * upon the BSS type and BSS number.