diff --git a/core/hdd/inc/wlan_hdd_main.h b/core/hdd/inc/wlan_hdd_main.h index c1d4d20f09c1..71689cf4ef2f 100644 --- a/core/hdd/inc/wlan_hdd_main.h +++ b/core/hdd/inc/wlan_hdd_main.h @@ -2229,6 +2229,17 @@ bool hdd_is_valid_mac_address(const uint8_t *pMacAddr); QDF_STATUS hdd_issta_p2p_clientconnected(struct hdd_context *hdd_ctx); bool wlan_hdd_validate_modules_state(struct hdd_context *hdd_ctx); +/** + * wlan_hdd_validate_mac_address() - Function to validate mac address + * @mac_addr: input mac address + * + * Return QDF_STATUS + */ +#define wlan_hdd_validate_mac_address(mac_addr) \ + __wlan_hdd_validate_mac_address(mac_addr, __func__) + +QDF_STATUS __wlan_hdd_validate_mac_address(struct qdf_mac_addr *mac_addr, + const char *func); #ifdef MSM_PLATFORM /** * hdd_bus_bw_compute_timer_start() - start the bandwidth timer diff --git a/core/hdd/src/wlan_hdd_main.c b/core/hdd/src/wlan_hdd_main.c index 17f7e5151036..0d929a466208 100644 --- a/core/hdd/src/wlan_hdd_main.c +++ b/core/hdd/src/wlan_hdd_main.c @@ -949,6 +949,32 @@ int __wlan_hdd_validate_session_id(uint8_t session_id, const char *func) return 0; } +QDF_STATUS __wlan_hdd_validate_mac_address(struct qdf_mac_addr *mac_addr, + const char *func) +{ + if (!mac_addr) { + hdd_err("Received NULL mac address (via %s)", func); + return QDF_STATUS_E_INVAL; + } + + if (qdf_is_macaddr_zero(mac_addr)) { + hdd_err("MAC is all zero (via %s)", func); + return QDF_STATUS_E_INVAL; + } + + if (qdf_is_macaddr_broadcast(mac_addr)) { + hdd_err("MAC is Broadcast (via %s)", func); + return QDF_STATUS_E_INVAL; + } + + if (QDF_NET_IS_MAC_MULTICAST(mac_addr->bytes)) { + hdd_err("MAC is Multicast (via %s)", func); + return QDF_STATUS_E_INVAL; + } + + return QDF_STATUS_SUCCESS; +} + /** * wlan_hdd_validate_modules_state() - Check modules status * @hdd_ctx: HDD context pointer @@ -3508,20 +3534,10 @@ static int __hdd_set_mac_address(struct net_device *dev, void *addr) return -EINVAL; } - if (qdf_is_macaddr_zero(&mac_addr)) { - hdd_err("MAC is all zero"); + qdf_ret_status = wlan_hdd_validate_mac_address(&mac_addr); + if (QDF_IS_STATUS_ERROR(qdf_ret_status)) 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; - } hdd_info("Changing MAC to " MAC_ADDRESS_STR " of the interface %s ", MAC_ADDR_ARRAY(mac_addr.bytes), dev->name); @@ -4876,11 +4892,13 @@ struct hdd_adapter *hdd_open_adapter(struct hdd_context *hdd_ctx, uint8_t sessio return NULL; } - if (macAddr == NULL) { + status = wlan_hdd_validate_mac_address((struct qdf_mac_addr *)macAddr); + if (QDF_IS_STATUS_ERROR(status)) { /* Not received valid macAddr */ hdd_err("Unable to add virtual intf: Not able to get valid mac address"); return NULL; } + status = hdd_check_for_existing_macaddr(hdd_ctx, macAddr); if (QDF_STATUS_E_FAILURE == status) { hdd_err("Duplicate MAC addr: " MAC_ADDRESS_STR