From 72555281a8318d218aa91eb0368de129cbaa1727 Mon Sep 17 00:00:00 2001 From: kimocoder Date: Thu, 19 Sep 2019 15:49:01 +0000 Subject: [PATCH] Add support for getting mac-address from devicetree --- core/rtw_ieee80211.c | 41 +++++++++++++++++++++++++---------------- include/ieee80211.h | 2 +- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/core/rtw_ieee80211.c b/core/rtw_ieee80211.c index 659b27b..3aad014 100644 --- a/core/rtw_ieee80211.c +++ b/core/rtw_ieee80211.c @@ -1577,10 +1577,13 @@ extern char *rtw_initmac; * @out: buf to store mac address decided * @hw_mac_addr: mac address from efuse/epprom */ -void rtw_macaddr_cfg(u8 *out, const u8 *hw_mac_addr) +void rtw_macaddr_cfg(struct device *dev, u8 *out, const u8 *hw_mac_addr) { #define DEFAULT_RANDOM_MACADDR 1 u8 mac[ETH_ALEN]; + struct device_node *np = dev->of_node; + const unsigned char *addr; + int len; if (out == NULL) { rtw_warn_on(1); @@ -1611,21 +1614,27 @@ void rtw_macaddr_cfg(u8 *out, const u8 *hw_mac_addr) err_chk: if (rtw_check_invalid_mac_address(mac, _TRUE) == _TRUE) { -#if DEFAULT_RANDOM_MACADDR - RTW_ERR("invalid mac addr:"MAC_FMT", assign random MAC\n", MAC_ARG(mac)); - *((u32 *)(&mac[2])) = rtw_random32(); - mac[0] = 0x00; - mac[1] = 0xe0; - mac[2] = 0x4c; -#else - RTW_ERR("invalid mac addr:"MAC_FMT", assign default one\n", MAC_ARG(mac)); - mac[0] = 0x00; - mac[1] = 0xe0; - mac[2] = 0x4c; - mac[3] = 0x87; - mac[4] = 0x00; - mac[5] = 0x00; -#endif + if (np && + (addr = of_get_property(np, "local-mac-address", &len)) && + len == ETH_ALEN) { + memcpy(mac, addr, ETH_ALEN); + } else { + #if DEFAULT_RANDOM_MACADDR + DBG_871X_LEVEL(_drv_err_, "invalid mac addr:"MAC_FMT", assign random MAC\n", MAC_ARG(mac)); + *((u32 *)(&mac[2])) = rtw_random32(); + mac[0] = 0x00; + mac[1] = 0xe0; + mac[2] = 0x4c; + #else + DBG_871X_LEVEL(_drv_err_, "invalid mac addr:"MAC_FMT", assign default one\n", MAC_ARG(mac)); + mac[0] = 0x00; + mac[1] = 0xe0; + mac[2] = 0x4c; + mac[3] = 0x87; + mac[4] = 0x00; + mac[5] = 0x00; + #endif + } } _rtw_memcpy(out, mac, ETH_ALEN); diff --git a/include/ieee80211.h b/include/ieee80211.h index ad3502d..ed66691 100644 --- a/include/ieee80211.h +++ b/include/ieee80211.h @@ -2176,7 +2176,7 @@ uint rtw_get_cckrate_size(u8 *rate,u32 rate_length); int rtw_check_network_type(unsigned char *rate, int ratelen, int channel); u8 rtw_check_invalid_mac_address(u8 *mac_addr, u8 check_local_bit); -void rtw_macaddr_cfg(u8 *out, const u8 *hw_mac_addr); +void rtw_macaddr_cfg(struct device *dev, u8 *out, const u8 *hw_mac_addr); u16 rtw_mcs_rate(u8 rf_type, u8 bw_40MHz, u8 short_GI, unsigned char *MCS_rate); u8 rtw_ht_mcsset_to_nss(u8 *supp_mcs_set);