0045-ar71xx-WNR2200-fix-for-random-WLAN-MAC.patch 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. From: Matthias Schiffer <mschiffer@universe-factory.net>
  2. Date: Sun, 29 May 2016 11:45:14 +0200
  3. Subject: ar71xx: WNR2200: fix for random WLAN MAC
  4. Fix for invalid/random/duplicate WLAN MAC address in WNR2200.
  5. Permanent platform MAC is calculated and assigned during system startup.
  6. WLAN MAC follows wired Ethernet interface addresses.
  7. Signed-off-by: Michal Cieslakiewicz <michal.cieslakiewicz@wp.pl>
  8. Backport of r49100
  9. diff --git a/target/linux/ar71xx/files/arch/mips/ath79/mach-wnr2200.c b/target/linux/ar71xx/files/arch/mips/ath79/mach-wnr2200.c
  10. index 5d23f21763cd9f4ddafc97f79ff47e819a18f2a6..37ffc4c56be33be96c43078117d7b123679378b3 100644
  11. --- a/target/linux/ar71xx/files/arch/mips/ath79/mach-wnr2200.c
  12. +++ b/target/linux/ar71xx/files/arch/mips/ath79/mach-wnr2200.c
  13. @@ -12,6 +12,7 @@
  14. #include <linux/mtd/mtd.h>
  15. #include <linux/mtd/partitions.h>
  16. +#include <linux/kernel.h> /* for max() macro */
  17. #include <asm/mach-ath79/ath79.h>
  18. @@ -45,6 +46,7 @@
  19. #define WNR2200_MAC0_OFFSET 0
  20. #define WNR2200_MAC1_OFFSET 6
  21. #define WNR2200_PCIE_CALDATA_OFFSET 0x1000
  22. +#define WNR2200_WMAC_OFFSET 0x108c /* wireless MAC is inside ART */
  23. static struct gpio_led wnr2200_leds_gpio[] __initdata = {
  24. {
  25. @@ -102,9 +104,40 @@ static struct gpio_led wnr2200_leds_gpio[] __initdata = {
  26. }
  27. };
  28. +/*
  29. + * For WNR2200 ART flash area used for WLAN MAC is usually empty (0xff)
  30. + * so ath9k driver uses random MAC instead each time module is loaded.
  31. + * OpenWrt's original fix was to copy eth1 address to WLAN interface.
  32. + * New solution does not duplicate hardware addresses and is taken from
  33. + * WNR2000v3 code. It assigns permanent WLAN MAC equal to ethN's MAC
  34. + * plus 1, so network interfaces get sequential addresses.
  35. + * If ART wireless MAC address field has been filled by user, use it.
  36. + */
  37. +static void __init wnr2200_get_wmac(u8 *wmac_gen_addr, int mac0_art_offset,
  38. + int mac1_art_offset, int wmac_art_offset)
  39. +{
  40. + u8 *art = (u8 *) KSEG1ADDR(0x1fff0000);
  41. + u8 *eth0_mac_addr = (u8 *) (art + mac0_art_offset);
  42. + u8 *eth1_mac_addr = (u8 *) (art + mac1_art_offset);
  43. + u8 *wlan_mac_addr = (u8 *) (art + wmac_art_offset);
  44. +
  45. + /* only 0xff if all bits are set - address is invalid, empty area */
  46. + if ((wlan_mac_addr[0] & wlan_mac_addr[1] & wlan_mac_addr[2] &
  47. + wlan_mac_addr[3] & wlan_mac_addr[4] & wlan_mac_addr[5]) == 0xff) {
  48. + memcpy(wmac_gen_addr, eth0_mac_addr, 5);
  49. + wmac_gen_addr[5] = max(eth0_mac_addr[5], eth1_mac_addr[5]) + 1;
  50. +
  51. + /* Avoid potential conflict in case max(0xff,0x00)+1==0x00 */
  52. + if (!wmac_gen_addr[5])
  53. + wmac_gen_addr[5] = 1;
  54. + } else
  55. + memcpy(wmac_gen_addr, wlan_mac_addr, 6);
  56. +}
  57. +
  58. static void __init wnr2200_setup(void)
  59. {
  60. u8 *art = (u8 *) KSEG1ADDR(0x1fff0000);
  61. + u8 wlan_mac_addr[6];
  62. ath79_register_mdio(0, 0x0);
  63. @@ -121,8 +154,10 @@ static void __init wnr2200_setup(void)
  64. ath79_register_eth(1);
  65. ath79_register_m25p80(NULL);
  66. - ap91_pci_init(art + WNR2200_PCIE_CALDATA_OFFSET,
  67. - art + WNR2200_MAC1_OFFSET);
  68. +
  69. + wnr2200_get_wmac(wlan_mac_addr, WNR2200_MAC0_OFFSET,
  70. + WNR2200_MAC1_OFFSET, WNR2200_WMAC_OFFSET);
  71. + ap91_pci_init(art + WNR2200_PCIE_CALDATA_OFFSET, wlan_mac_addr);
  72. ath79_register_leds_gpio(-1, ARRAY_SIZE(wnr2200_leds_gpio),
  73. wnr2200_leds_gpio);