Browse Source

qcacld-3.0: Reject invalid MAC address during dynamic MAC change

Currently when the MAC address is changed dynamically, invalid MAC
(Broadcast, Multicast and 00:00:00:00:00:00) are getting accepted
and interface is getting up on these invalid addresses because
of this device is trying to connect to AP with the configured
invalid address.

To address this issue reject all invalid MAC addresses
when MAC is dynamically getting configured.

Change-Id: If2530b213b5ffc2ddf0bc728138e1f3200f33286
CRs-Fixed: 2190468
Ashish Kumar Dhanotiya 7 years ago
parent
commit
aa0ca60f16
2 changed files with 36 additions and 0 deletions
  1. 18 0
      core/hdd/src/wlan_hdd_hostapd.c
  2. 18 0
      core/hdd/src/wlan_hdd_main.c

+ 18 - 0
core/hdd/src/wlan_hdd_hostapd.c

@@ -675,6 +675,7 @@ static int __hdd_hostapd_set_mac_address(struct net_device *dev, void *addr)
 	struct hdd_adapter *adapter;
 	struct hdd_context *hdd_ctx;
 	int ret = 0;
+	struct qdf_mac_addr mac_addr;
 
 	ENTER_DEV(dev);
 
@@ -684,6 +685,23 @@ static int __hdd_hostapd_set_mac_address(struct net_device *dev, void *addr)
 	if (0 != ret)
 		return ret;
 
+	qdf_mem_copy(&mac_addr, psta_mac_addr->sa_data, sizeof(mac_addr));
+
+	if (qdf_is_macaddr_zero(&mac_addr)) {
+		hdd_err("MAC is all zero");
+		return -EINVAL;
+	}
+
+	if (qdf_is_macaddr_broadcast(&mac_addr)) {
+		hdd_err("MAC is Broadcast");
+		return -EINVAL;
+	}
+
+	if (ETHER_IS_MULTICAST(psta_mac_addr->sa_data)) {
+		hdd_err("MAC is Multicast");
+		return -EINVAL;
+	}
+
 	memcpy(dev->dev_addr, psta_mac_addr->sa_data, ETH_ALEN);
 	EXIT();
 	return 0;

+ 18 - 0
core/hdd/src/wlan_hdd_main.c

@@ -3162,6 +3162,7 @@ static int __hdd_set_mac_address(struct net_device *dev, void *addr)
 	struct sockaddr *psta_mac_addr = addr;
 	QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
 	int ret;
+	struct qdf_mac_addr mac_addr;
 
 	ENTER_DEV(dev);
 
@@ -3170,6 +3171,23 @@ static int __hdd_set_mac_address(struct net_device *dev, void *addr)
 	if (0 != ret)
 		return ret;
 
+	qdf_mem_copy(&mac_addr, psta_mac_addr->sa_data, sizeof(mac_addr));
+
+	if (qdf_is_macaddr_zero(&mac_addr)) {
+		hdd_err("MAC is all zero");
+		return -EINVAL;
+	}
+
+	if (qdf_is_macaddr_broadcast(&mac_addr)) {
+		hdd_err("MAC is Broadcast");
+		return -EINVAL;
+	}
+
+	if (ETHER_IS_MULTICAST(psta_mac_addr->sa_data)) {
+		hdd_err("MAC is Multicast");
+		return -EINVAL;
+	}
+
 	memcpy(&adapter->mac_addr, psta_mac_addr->sa_data, ETH_ALEN);
 	memcpy(dev->dev_addr, psta_mac_addr->sa_data, ETH_ALEN);