From aa0ca60f16d213b7736adbe0e04a292305cbac0e Mon Sep 17 00:00:00 2001 From: Ashish Kumar Dhanotiya Date: Wed, 21 Feb 2018 17:42:55 +0530 Subject: [PATCH] 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 --- core/hdd/src/wlan_hdd_hostapd.c | 18 ++++++++++++++++++ core/hdd/src/wlan_hdd_main.c | 18 ++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/core/hdd/src/wlan_hdd_hostapd.c b/core/hdd/src/wlan_hdd_hostapd.c index 85a91ab8522d..c97ad02d08a5 100644 --- a/core/hdd/src/wlan_hdd_hostapd.c +++ b/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; diff --git a/core/hdd/src/wlan_hdd_main.c b/core/hdd/src/wlan_hdd_main.c index d0daf0ede9c5..9cc4f60692af 100644 --- a/core/hdd/src/wlan_hdd_main.c +++ b/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);