mac address: add user set mac address

add menuconfig for user to set mac address of wifi, bt and ethernet.
This commit is contained in:
XiaXiaotian 2017-03-01 20:42:46 +08:00
parent c025dfbfa7
commit fabe0493c2
7 changed files with 101 additions and 3 deletions

View file

@ -3,6 +3,15 @@ menuconfig BT_ENABLED
help
Select this option to enable Bluetooth stack and show the submenu with Bluetooth configuration choices.
config ESP_MAC_OFFSET_BT
int "MAC address offset value of WiFi station"
depends on BT_ENABLED
range 0 255
default 2
help
The offset value of bluetooth MAC address from the MAC address which is read from efuse.
This offset value must be different from that of WiFi softap, WiFi station and ethernet.
config BTC_TASK_STACK_SIZE
int "Bluetooth event (callback to application) task stack size"
depends on BT_ENABLED

View file

@ -481,6 +481,24 @@ menuconfig WIFI_ENABLED
help
Select this option to enable WiFi stack and show the submenu with WiFi configuration choices.
config ESP_MAC_OFFSET_WIFI_STA
int "MAC address offset value of WiFi station"
depends on WIFI_ENABLED
range 0 255
default 0
help
The offset value of WiFi station MAC address from the MAC address which is read from efuse.
This offset value must be different from that of WiFi softap, bluetooth and ethernet.
config ESP_MAC_OFFSET_WIFI_SOFTAP
int "MAC address offset value of WiFi softap"
depends on WIFI_ENABLED
range 0 255
default 1
help
The offset value of WiFi softap MAC address from the MAC address which is read from efuse.
This offset value must be different from that of WiFi station, bluetooth and ethernet.
config SW_COEXIST_ENABLE
bool "Software controls WiFi/Bluetooth coexistence"
depends on WIFI_ENABLED && BT_ENABLED

View file

@ -24,6 +24,13 @@
extern "C" {
#endif
enum {
ESP_MAC_WIFI_STA,
ESP_MAC_WIFI_SOFTAP,
ESP_MAC_BT,
ESP_MAC_ETH,
};
/**
* @attention application don't need to call this function anymore. It do nothing and will
* be removed in future version.
@ -115,6 +122,19 @@ esp_err_t esp_efuse_read_mac(uint8_t* mac);
*/
esp_err_t system_efuse_read_mac(uint8_t mac[6]) __attribute__ ((deprecated));
/**
* @brief Read hardware MAC address and set MAC address of the interface.
*
* This function first reads hardware MAC address from efuse. Then set the MAC address of the interface
* including wifi station, wifi softap, bluetooth and ethernet according to the offset value in menuconfig.
*
* @param mac MAC address of the interface, length: 6 bytes.
* @param interface interface, 0:wifi station, 1:wifi softap, 2:bluetooth, 3:ethernet.
*
* @return ESP_OK on success
*/
esp_err_t esp_read_mac(uint8_t* mac, int interface);
/**
* Get SDK version
*

@ -1 +1 @@
Subproject commit 7b06303c0fa416aea7f86b7596e84db367189066
Subproject commit e22ec1a5140dca2bb44f9bfb3147911fa4ebb8fe

View file

@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include <string.h>
#include "esp_system.h"
#include "esp_attr.h"
#include "esp_wifi.h"
@ -72,6 +74,47 @@ esp_err_t esp_efuse_read_mac(uint8_t* mac)
esp_err_t system_efuse_read_mac(uint8_t mac[6]) __attribute__((alias("esp_efuse_read_mac")));
esp_err_t esp_read_mac(uint8_t* mac, int interface)
{
uint8_t efuse_mac[6];
if (mac == NULL) {
ESP_LOGE(TAG, "mac address param is NULL");
abort();
}
esp_efuse_read_mac(efuse_mac);
switch (interface) {
#if CONFIG_WIFI_ENABLED
case ESP_MAC_WIFI_STA:
memcpy(mac, efuse_mac, 6);
mac[5] += CONFIG_ESP_MAC_OFFSET_WIFI_STA;
break;
case ESP_MAC_WIFI_SOFTAP:
memcpy(mac, efuse_mac, 6);
mac[5] += CONFIG_ESP_MAC_OFFSET_WIFI_SOFTAP;
break;
#endif
#if CONFIG_BT_ENABLED
case ESP_MAC_BT:
memcpy(mac, efuse_mac, 6);
mac[5] += CONFIG_ESP_MAC_OFFSET_BT;
break;
#endif
#if CONFIG_ETHERNET
case ESP_MAC_ETH:
memcpy(mac, efuse_mac, 6);
mac[5] += CONFIG_ESP_MAC_OFFSET_ETH;
break;
#endif
default:
ESP_LOGW(TAG, "wrong mac type");
break;
}
return ESP_OK;
}
void esp_restart_noos() __attribute__ ((noreturn));

View file

@ -4,6 +4,15 @@ menuconfig ETHERNET
help
Select this option to enable ethernet driver and show the submenu with ethernet features.
config ESP_MAC_OFFSET_ETH
int "MAC address offset value of ethernet"
depends on ETHERNET
range 0 255
default 3
help
The offset value of ethernet MAC address from the MAC address which is read from efuse.
This offset value must be different from that of WiFi softap, bluetooth and WiFi station.
config DMA_RX_BUF_NUM
int "Number of DMA RX buffers"
range 3 20

View file

@ -75,8 +75,7 @@ esp_err_t emac_post(emac_sig_t sig, emac_par_t par);
static void emac_macaddr_init(void)
{
esp_efuse_read_mac(&(emac_config.macaddr[0]));
emac_config.macaddr[5] = emac_config.macaddr[5] + 3;
esp_read_mac(&(emac_config.macaddr[0]), ESP_MAC_ETH);
}
void esp_eth_get_mac(uint8_t mac[6])