From 912bd03a5cfbe0ec7acb62048cceacd82ff1e757 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Wed, 30 Oct 2019 13:52:41 +1100 Subject: [PATCH] system api: Check if Base MAC is a unicast MAC before setting Closes https://github.com/espressif/esp-idf/issues/4263 Closes IDFGH-2096 --- components/esp32/system_api.c | 6 +++++- components/esp32s2beta/system_api.c | 6 +++++- components/esp_common/include/esp_system.h | 6 ++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/components/esp32/system_api.c b/components/esp32/system_api.c index 4e28dc31e2..9dfb105a8b 100644 --- a/components/esp32/system_api.c +++ b/components/esp32/system_api.c @@ -51,7 +51,11 @@ esp_err_t esp_base_mac_addr_set(uint8_t *mac) { if (mac == NULL) { ESP_LOGE(TAG, "Base MAC address is NULL"); - abort(); + return ESP_ERR_INVALID_ARG; + } + if (mac[0] & 0x01) { + ESP_LOGE(TAG, "Base MAC must be a unicast MAC"); + return ESP_ERR_INVALID_ARG; } memcpy(base_mac_addr, mac, 6); diff --git a/components/esp32s2beta/system_api.c b/components/esp32s2beta/system_api.c index 851bdba5fa..31c9d85b1b 100644 --- a/components/esp32s2beta/system_api.c +++ b/components/esp32s2beta/system_api.c @@ -54,7 +54,11 @@ esp_err_t esp_base_mac_addr_set(uint8_t *mac) { if (mac == NULL) { ESP_LOGE(TAG, "Base MAC address is NULL"); - abort(); + return ESP_ERR_INVALID_ARG; + } + if (mac[0] & 0x01) { + ESP_LOGE(TAG, "Base MAC must be a unicast MAC"); + return ESP_ERR_INVALID_ARG; } memcpy(base_mac_addr, mac, 6); diff --git a/components/esp_common/include/esp_system.h b/components/esp_common/include/esp_system.h index 46c2b88350..9177cc4671 100644 --- a/components/esp_common/include/esp_system.h +++ b/components/esp_common/include/esp_system.h @@ -161,9 +161,15 @@ void esp_fill_random(void *buf, size_t len); * address with the MAC address which is stored in BLK3 of EFUSE or external storage before initializing * WiFi/BT/Ethernet. * + * @note Base MAC must be a unicast MAC (least significant bit of first byte must be zero). + * + * @note If not using a valid OUI, set the "locally administered" bit + * (bit value 0x02 in the first byte) to avoid collisions. + * * @param mac base MAC address, length: 6 bytes. * * @return ESP_OK on success + * ESP_ERR_INVALID_ARG If mac is NULL or is not a unicast MAC */ esp_err_t esp_base_mac_addr_set(uint8_t *mac);