From f63b4c971f5fb1310f145785c3b2b77651ef129e Mon Sep 17 00:00:00 2001 From: Pali Rohár Date: Fri, 10 Nov 2017 00:38:23 +0100 Subject: wl1251: Update wl->nvs_len after wl->nvs is valid MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If kmemdup fails, then wl->nvs_len will contain invalid non-zero size. Signed-off-by: Pali Rohár Acked-by: Pavel Machek Signed-off-by: Kalle Valo --- drivers/net/wireless/ti/wl1251/main.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'drivers/net/wireless/ti') diff --git a/drivers/net/wireless/ti/wl1251/main.c b/drivers/net/wireless/ti/wl1251/main.c index 037defd10b91..412fbd413003 100644 --- a/drivers/net/wireless/ti/wl1251/main.c +++ b/drivers/net/wireless/ti/wl1251/main.c @@ -122,8 +122,7 @@ static int wl1251_fetch_nvs(struct wl1251 *wl) goto out; } - wl->nvs_len = fw->size; - wl->nvs = kmemdup(fw->data, wl->nvs_len, GFP_KERNEL); + wl->nvs = kmemdup(fw->data, fw->size, GFP_KERNEL); if (!wl->nvs) { wl1251_error("could not allocate memory for the nvs file"); @@ -131,6 +130,8 @@ static int wl1251_fetch_nvs(struct wl1251 *wl) goto out; } + wl->nvs_len = fw->size; + ret = 0; out: -- cgit From 562da3a39cb78ffaba44511ec39d8c245023a02f Mon Sep 17 00:00:00 2001 From: Pali Rohár Date: Fri, 10 Nov 2017 00:38:24 +0100 Subject: wl1251: Generate random MAC address only if driver does not have valid MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this patch, driver generated random MAC address every time it was initialized. After that random MAC address could be overwritten with fixed one, if provided. This patch changes order. First it tries to read fixed MAC address and if it fails then driver generates random MAC address. Signed-off-by: Pali Rohár Acked-by: Pavel Machek Signed-off-by: Kalle Valo --- drivers/net/wireless/ti/wl1251/main.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to 'drivers/net/wireless/ti') diff --git a/drivers/net/wireless/ti/wl1251/main.c b/drivers/net/wireless/ti/wl1251/main.c index 412fbd413003..be07243d590e 100644 --- a/drivers/net/wireless/ti/wl1251/main.c +++ b/drivers/net/wireless/ti/wl1251/main.c @@ -1491,7 +1491,24 @@ int wl1251_init_ieee80211(struct wl1251 *wl) wl->hw->queues = 4; if (wl->use_eeprom) - wl1251_read_eeprom_mac(wl); + ret = wl1251_read_eeprom_mac(wl); + else + ret = -EINVAL; + + if (ret == 0 && !is_valid_ether_addr(wl->mac_addr)) + ret = -EINVAL; + + if (ret < 0) { + /* + * In case our MAC address is not correctly set, + * we use a random but Nokia MAC. + */ + static const u8 nokia_oui[3] = {0x00, 0x1f, 0xdf}; + memcpy(wl->mac_addr, nokia_oui, 3); + get_random_bytes(wl->mac_addr + 3, 3); + wl1251_warning("MAC address in eeprom or nvs data is not valid"); + wl1251_warning("Setting random MAC address: %pM", wl->mac_addr); + } ret = wl1251_register_hw(wl); if (ret) @@ -1512,7 +1529,6 @@ struct ieee80211_hw *wl1251_alloc_hw(void) struct ieee80211_hw *hw; struct wl1251 *wl; int i; - static const u8 nokia_oui[3] = {0x00, 0x1f, 0xdf}; hw = ieee80211_alloc_hw(sizeof(*wl), &wl1251_ops); if (!hw) { @@ -1562,13 +1578,6 @@ struct ieee80211_hw *wl1251_alloc_hw(void) INIT_WORK(&wl->irq_work, wl1251_irq_work); INIT_WORK(&wl->tx_work, wl1251_tx_work); - /* - * In case our MAC address is not correctly set, - * we use a random but Nokia MAC. - */ - memcpy(wl->mac_addr, nokia_oui, 3); - get_random_bytes(wl->mac_addr + 3, 3); - wl->state = WL1251_STATE_OFF; mutex_init(&wl->mutex); spin_lock_init(&wl->wl_lock); -- cgit From 4f507d588d08429126530988f657a7a7ca3e6180 Mon Sep 17 00:00:00 2001 From: Pali Rohár Date: Fri, 10 Nov 2017 00:38:25 +0100 Subject: wl1251: Parse and use MAC address from supplied NVS data MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch implements parsing MAC address from NVS data which are sent to wl1251 chip. Calibration NVS data could contain valid MAC address and it will be used instead of randomly generated one. This patch also moves code for requesting NVS data from userspace to driver initialization code to make sure that NVS data will be there at time when permanent MAC address is needed. Calibration NVS data for wl1251 are device specific. Every device with wl1251 chip should have been calibrated in factory and needs to provide own calibration data. Default example file wl1251-nvs.bin, found in linux-firmware repository, contains MAC address 00:00:20:07:03:09. So this MAC address is marked as invalid as it is not real device specific address, just example one. Format of calibration NVS data can be found at: http://notaz.gp2x.de/misc/pnd/wl1251/nvs_map.txt Signed-off-by: Pali Rohár Signed-off-by: Kalle Valo --- drivers/net/wireless/ti/wl1251/main.c | 55 ++++++++++++++++++++++++++++++----- 1 file changed, 47 insertions(+), 8 deletions(-) (limited to 'drivers/net/wireless/ti') diff --git a/drivers/net/wireless/ti/wl1251/main.c b/drivers/net/wireless/ti/wl1251/main.c index be07243d590e..5ac7965c7d53 100644 --- a/drivers/net/wireless/ti/wl1251/main.c +++ b/drivers/net/wireless/ti/wl1251/main.c @@ -203,13 +203,6 @@ static int wl1251_chip_wakeup(struct wl1251 *wl) goto out; } - if (wl->nvs == NULL && !wl->use_eeprom) { - /* No NVS from netlink, try to get it from the filesystem */ - ret = wl1251_fetch_nvs(wl); - if (ret < 0) - goto out; - } - out: return ret; } @@ -1447,6 +1440,46 @@ static int wl1251_read_eeprom_mac(struct wl1251 *wl) return 0; } +#define NVS_OFF_MAC_LEN 0x19 +#define NVS_OFF_MAC_ADDR_LO 0x1a +#define NVS_OFF_MAC_ADDR_HI 0x1b +#define NVS_OFF_MAC_DATA 0x1c + +static int wl1251_check_nvs_mac(struct wl1251 *wl) +{ + if (wl->nvs_len < 0x24) + return -ENODATA; + + /* length is 2 and data address is 0x546c (ANDed with 0xfffe) */ + if (wl->nvs[NVS_OFF_MAC_LEN] != 2 || + wl->nvs[NVS_OFF_MAC_ADDR_LO] != 0x6d || + wl->nvs[NVS_OFF_MAC_ADDR_HI] != 0x54) + return -EINVAL; + + return 0; +} + +static int wl1251_read_nvs_mac(struct wl1251 *wl) +{ + u8 mac[ETH_ALEN]; + int i, ret; + + ret = wl1251_check_nvs_mac(wl); + if (ret) + return ret; + + /* MAC is stored in reverse order */ + for (i = 0; i < ETH_ALEN; i++) + mac[i] = wl->nvs[NVS_OFF_MAC_DATA + ETH_ALEN - i - 1]; + + /* 00:00:20:07:03:09 is in example file wl1251-nvs.bin, so invalid */ + if (ether_addr_equal_unaligned(mac, "\x00\x00\x20\x07\x03\x09")) + return -EINVAL; + + memcpy(wl->mac_addr, mac, ETH_ALEN); + return 0; +} + static int wl1251_register_hw(struct wl1251 *wl) { int ret; @@ -1490,10 +1523,16 @@ int wl1251_init_ieee80211(struct wl1251 *wl) wl->hw->queues = 4; + if (wl->nvs == NULL && !wl->use_eeprom) { + ret = wl1251_fetch_nvs(wl); + if (ret < 0) + goto out; + } + if (wl->use_eeprom) ret = wl1251_read_eeprom_mac(wl); else - ret = -EINVAL; + ret = wl1251_read_nvs_mac(wl); if (ret == 0 && !is_valid_ether_addr(wl->mac_addr)) ret = -EINVAL; -- cgit From 3142467fc15ba19a327dcedafcf913bc7832f6d1 Mon Sep 17 00:00:00 2001 From: Pali Rohár Date: Fri, 10 Nov 2017 00:38:26 +0100 Subject: wl1251: Set generated MAC address back to NVS data MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In case there is no valid MAC address kernel generates random one. This patch propagate this generated MAC address back to NVS data which will be uploaded to wl1251 chip. So HW would have same MAC address as linux kernel uses. This should not change any functionality, but it is better to tell wl1251 correct mac address since beginning of chip usage. Signed-off-by: Pali Rohár Signed-off-by: Kalle Valo --- drivers/net/wireless/ti/wl1251/main.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'drivers/net/wireless/ti') diff --git a/drivers/net/wireless/ti/wl1251/main.c b/drivers/net/wireless/ti/wl1251/main.c index 5ac7965c7d53..bd8641ad953b 100644 --- a/drivers/net/wireless/ti/wl1251/main.c +++ b/drivers/net/wireless/ti/wl1251/main.c @@ -1480,6 +1480,21 @@ static int wl1251_read_nvs_mac(struct wl1251 *wl) return 0; } +static int wl1251_write_nvs_mac(struct wl1251 *wl) +{ + int i, ret; + + ret = wl1251_check_nvs_mac(wl); + if (ret) + return ret; + + /* MAC is stored in reverse order */ + for (i = 0; i < ETH_ALEN; i++) + wl->nvs[NVS_OFF_MAC_DATA + i] = wl->mac_addr[ETH_ALEN - i - 1]; + + return 0; +} + static int wl1251_register_hw(struct wl1251 *wl) { int ret; @@ -1545,6 +1560,8 @@ int wl1251_init_ieee80211(struct wl1251 *wl) static const u8 nokia_oui[3] = {0x00, 0x1f, 0xdf}; memcpy(wl->mac_addr, nokia_oui, 3); get_random_bytes(wl->mac_addr + 3, 3); + if (!wl->use_eeprom) + wl1251_write_nvs_mac(wl); wl1251_warning("MAC address in eeprom or nvs data is not valid"); wl1251_warning("Setting random MAC address: %pM", wl->mac_addr); } -- cgit From a6cf02e6485a80ec0f708e1f72ee95abc3426b84 Mon Sep 17 00:00:00 2001 From: Randy Dunlap Date: Fri, 2 Mar 2018 18:03:30 -0800 Subject: net/wireless: fix spaces and grammar copy/paste in vendor Kconfig help text Lots of the wireless driver vendor Kconfig symol help text says "questions about cards." (2 spaces between "about" and "cards") Besides dropping one of those spaces, it also needs some other word inserted there. Instead of putting each vendor's name there, I chose to say "these" cards in all of the Kconfig help text. Cc: Kalle Valo Signed-off-by: Randy Dunlap Signed-off-by: Kalle Valo --- drivers/net/wireless/ti/Kconfig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'drivers/net/wireless/ti') diff --git a/drivers/net/wireless/ti/Kconfig b/drivers/net/wireless/ti/Kconfig index 92fbd6597e34..366c687445ad 100644 --- a/drivers/net/wireless/ti/Kconfig +++ b/drivers/net/wireless/ti/Kconfig @@ -5,8 +5,8 @@ config WLAN_VENDOR_TI If you have a wireless card belonging to this class, say Y. Note that the answer to this question doesn't directly affect the - kernel: saying N will just cause the configurator to skip all - the questions about cards. If you say Y, you will be asked for + kernel: saying N will just cause the configurator to skip all the + questions about these cards. If you say Y, you will be asked for your specific card in the following questions. if WLAN_VENDOR_TI -- cgit