[Help] Wrong Wlan0 MAC address and unable to generate correct one

Hi all,

I am trying to base all mac addresses off of LAN interface:
for example let's say LAN mac = xx:xx:xx:xx:xx:01

I want

  • 5G mac to be: xx:xx:xx:xx:xx:02
  • 2.4G mac to be: xx:xx:xx:xx:xx:03

Right now 5G is showing
wlan0-ap Link encap:Ethernet HWaddr 22:22:22:22:22:25

Currently, 2.4GHz interface is receiving exactly the same MAC address as eth1, but I want it to have an address of eth1's MAC + 2.

I am trying to figure out how MAC addresses for wlan interfaces are generated?

My device is: CF-E385AC

Any advice?

cat /proc/mtd/

mtd0: 00040000 00010000 "u-boot"
mtd1: 00010000 00010000 "art"
mtd2: 00fa0000 00010000 "firmware"
mtd3: 001a0000 00010000 "kernel"
mtd4: 00e00000 00010000 "rootfs"
mtd5: 00980000 00010000 "rootfs_data"
mtd6: 00010000 00010000 "art-backup"

Need to know the device?

But essentially for ath9/10 if your target is ipq806x;

target/linux/ipq806x/base-files/etc/hotplug.d/firmware/11-ath10k-caldata

see;

For some details

1 Like

https://openwrt.org/toh/hwdata/comfast/comfast_cf-e385ac

are you working within an ath71 or ath79 ( dts ) framework?

I looked in target/linux/ar71xx/base-files/etc/hotplug.d/firmware/11-ath10kcaldata

How can I set the MAC address for ath9K interface within that file?

I am working with ath71xx framework.

I tried to modify this function: https://github.com/openwrt/openwrt/blob/d9593b0809e42e9d75cc3ac4407ec30faaf70b15/target/linux/ar71xx/files/arch/mips/ath79/mach-cf-e316n-v2.c#L689

But I am unable to get the wlan1 to have eth1's MAC + 2 mac address

So I tried this code and I am unable to get it right :frowning:

#define E385AC_WMAC_CALDATA_OFFSET	0x1000
#define E385AC_PCIE_CALDATA_OFFSET	0x5000

static void __init cf_e385ac_setup(void)
{
	u8 *mac = (u8 *) KSEG1ADDR(0x1f040000);
	u8 *art = (u8 *) KSEG1ADDR(0x1f040000);
	u8 tmpmac[ETH_ALEN];
	
	ath79_register_leds_gpio(-1, ARRAY_SIZE(cf_e385ac_leds_gpio),
				 cf_e385ac_leds_gpio);
	cf_e38xac_common_setup(0x40000);

	ath79_init_mac(tmpmac, mac, 2);
	ath79_register_wmac(art + E385AC_WMAC_CALDATA_OFFSET, tmpmac);
	ath79_init_mac(tmpmac, mac, 3);
	ap91_pci_init(art + E385AC_PCIE_CALDATA_OFFSET, tmpmac);

	mdiobus_register_board_info(cf_e385ac_mdio0_info,
				    ARRAY_SIZE(cf_e385ac_mdio0_info));
	ath79_register_mdio(0, 0x0);

	ath79_setup_qca955x_eth_cfg(QCA955X_ETH_CFG_RGMII_EN);

	/* QCA9558 GMAC0 is connected to RMGII interface */
	ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
	ath79_eth0_data.phy_mask = BIT(0);
	ath79_eth0_data.mii_bus_dev = &ath79_mdio0_device.dev;
	ath79_eth0_pll_data.pll_1000 = 0x96000000;
	
	ath79_init_mac(ath79_eth0_data.mac_addr, mac, 0);
	ath79_register_eth(0);

	/* QCA9558 GMAC1 is connected to SGMII interface */
	ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_SGMII;
	ath79_eth1_data.speed = SPEED_1000;
	ath79_eth1_data.duplex = DUPLEX_FULL;
	ath79_eth1_pll_data.pll_1000 = 0x03000101;
	
	ath79_init_mac(ath79_eth1_data.mac_addr, mac, 1);
	ath79_register_eth(1);
}

I am receiving this error:

Wed Jul 17 22:47:58 2019 kern.info kernel: [    0.120296] MIPS: machine is COMFAST CF-E385AC
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.128178] registering PCI controller with io_map_base unset
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.134471] ar724x-pci ar724x-pci.1: PCIe link is down
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.139935] registering PCI controller with io_map_base unset
Wed Jul 17 22:47:58 2019 kern.err kernel: [    0.148944] kobject (80521cf8): tried to init an initialized object, something is seriously wrong.
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.158500] CPU: 0 PID: 1 Comm: swapper Not tainted 4.14.132 #0
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.164787] Stack : 80540000 804f60e0 00000000 00000000 804d0204 8fc23d64 8fc282fc 8051da27
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.173689]         804cc300 00000001 80593800 80587b74 80549304 00000001 8fc23d18 b021bcb8
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.182585]         00000000 00000000 80590000 00000e90 00000000 00000000 00000007 00000000
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.191488]         00000032 d6f33cb0 00000031 00000000 00000000 8053a890 8054bf38 805758a4
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.200384]         00000004 80587b74 80549304 80590000 00000002 80061970 00000000 80590000
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.209287]         ...
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.211885] Call Trace:
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.214483] [<8006c67c>] show_stack+0x58/0x100
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.219233] [<80419498>] kobject_init+0x40/0xbc
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.224079] [<80295244>] device_initialize+0x2c/0xa8
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.229375] [<8029ce3c>] platform_device_register+0x18/0x34
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.235313] [<805530e0>] cf_e385ac_setup+0x48/0x12c
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.240511] [<8054bf74>] ath79_setup+0x3c/0x54
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.245231] [<80060a50>] do_one_initcall+0xd0/0x1a0
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.250424] [<80549d5c>] kernel_init_freeable+0x150/0x210
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.256174] [<8042b480>] kernel_init+0x10/0x104
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.261008] [<80067018>] ret_from_kernel_thread+0x14/0x1c
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.266750] ------------[ cut here ]------------
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.271681] WARNING: CPU: 0 PID: 1 at kernel/resource.c:798 __insert_resource+0x54/0x158
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.280278] Modules linked in:
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.283536] CPU: 0 PID: 1 Comm: swapper Not tainted 4.14.132 #0
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.289820] Stack : 80540000 804f60e0 00000000 00000000 804d0204 8fc23cf4 8fc282fc 8051da27
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.298722]         804cc300 00000001 80593800 0000031e 80521cf0 00000000 8fc23ca8 b021bcb8
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.307619]         00000000 00000000 80590000 00001400 00000000 00000000 00000007 00000000
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.316521]         00000047 afde2916 00000046 00000000 00000000 00000009 00000000 804ce2d4
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.325418]         8008af78 0000031e 80521cf0 80590000 00000002 80061970 00000000 80590000
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.334321]         ...
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.336919] Call Trace:
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.339512] [<8006c67c>] show_stack+0x58/0x100
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.344233] [<80087130>] __warn+0xe4/0x13c
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.348594] [<80087218>] warn_slowpath_null+0x1c/0x34
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.353960] [<8008af78>] __insert_resource+0x54/0x158
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.359337] [<8008b08c>] insert_resource+0x10/0x28
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.364432] [<8029c2e4>] platform_device_add+0x170/0x254
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.370089] [<805530e0>] cf_e385ac_setup+0x48/0x12c
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.375271] [<8054bf74>] ath79_setup+0x3c/0x54
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.379991] [<80060a50>] do_one_initcall+0xd0/0x1a0
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.385184] [<80549d5c>] kernel_init_freeable+0x150/0x210
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.390925] [<8042b480>] kernel_init+0x10/0x104
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.395754] [<80067018>] ret_from_kernel_thread+0x14/0x1c
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.401503] ---[ end trace 911379ae8d9e351d ]---
Wed Jul 17 22:47:58 2019 kern.err kernel: [    0.406425] platform qca955x_wmac: failed to claim resource 0: [mem 0x18100000-0x1811ffff]
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.418030] ------------[ cut here ]------------
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.422949] WARNING: CPU: 0 PID: 1 at fs/sysfs/dir.c:31 sysfs_warn_dup+0x6c/0x88
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.430825] sysfs: cannot create duplicate filename '/devices/platform/ar724x-pci.0'
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.439055] Modules linked in:
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.442313] CPU: 0 PID: 1 Comm: swapper Tainted: G        W       4.14.132 #0
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.449890] Stack : 80540000 804f60e0 00000000 00000000 804d0204 8fc23a94 8fc282fc 8051da27
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.458793]         804cc300 00000001 80593800 0000001f 8fc73010 00000001 8fc23a48 b021bcb8
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.467689]         00000000 00000000 80590000 00001b10 00000000 00000000 00000007 00000000
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.476592]         00000061 bfd53aae 00000060 00000000 00000000 00000009 00000000 804dacac
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.485489]         801cc398 0000001f 8fc73010 00000000 00000000 80061970 00000000 80590000
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.494391]         ...
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.496989] Call Trace:
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.499584] [<8006c67c>] show_stack+0x58/0x100
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.504307] [<80087130>] __warn+0xe4/0x13c
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.508673] [<800871b8>] warn_slowpath_fmt+0x30/0x3c
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.513946] [<801cc398>] sysfs_warn_dup+0x6c/0x88
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.518954] [<801cc4a0>] sysfs_create_dir_ns+0x84/0xb8
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.524434] [<80419ab4>] kobject_add_internal+0xd0/0x2fc
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.530097] [<8041a220>] kobject_add+0x8c/0xb4
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.534823] [<80297928>] device_add+0x144/0x5cc
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.539642] [<8029c32c>] platform_device_add+0x1b8/0x254
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.545300] [<8029cce0>] platform_device_register_full+0xe0/0x14c
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.551783] [<8006203c>] ath79_register_pci_ar724x+0x138/0x16c
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.558000] [<8054d734>] ath79_register_pci+0x144/0x1e8
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.563558] [<8054dbf8>] ap91_pci_init+0x74/0x90
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.568472] [<805530fc>] cf_e385ac_setup+0x64/0x12c
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.573654] [<8054bf74>] ath79_setup+0x3c/0x54
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.578374] [<80060a50>] do_one_initcall+0xd0/0x1a0
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.583567] [<80549d5c>] kernel_init_freeable+0x150/0x210
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.589313] [<8042b480>] kernel_init+0x10/0x104
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.594140] [<80067018>] ret_from_kernel_thread+0x14/0x1c
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.599882] ---[ end trace 911379ae8d9e351e ]---
Wed Jul 17 22:47:58 2019 kern.err kernel: [    0.604793] kobject_add_internal failed for ar724x-pci.0 with -EEXIST, don't try to register things with the same name in the same directory.
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.618337] ------------[ cut here ]------------
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.623254] WARNING: CPU: 0 PID: 1 at fs/sysfs/dir.c:31 sysfs_warn_dup+0x6c/0x88
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.631129] sysfs: cannot create duplicate filename '/devices/platform/ar724x-pci.1'
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.639361] Modules linked in:
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.642620] CPU: 0 PID: 1 Comm: swapper Tainted: G        W       4.14.132 #0
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.650197] Stack : 80540000 804f60e0 00000000 00000000 804d0204 8fc23a94 8fc282fc 8051da27
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.659099]         804cc300 00000001 80593800 0000001f 8fc73010 00000001 8fc23a48 b021bcb8
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.667996]         00000000 00000000 80590000 000023d8 00000000 00000000 00000007 00000000
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.676898]         00000082 8b999a86 00000081 00000000 00000000 00000009 00000000 804dacac
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.685795]         801cc398 0000001f 8fc73010 00000001 00000000 80061970 00000000 80590000
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.694698]         ...
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.697296] Call Trace:
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.699890] [<8006c67c>] show_stack+0x58/0x100
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.704613] [<80087130>] __warn+0xe4/0x13c
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.708980] [<800871b8>] warn_slowpath_fmt+0x30/0x3c
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.714253] [<801cc398>] sysfs_warn_dup+0x6c/0x88
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.719260] [<801cc4a0>] sysfs_create_dir_ns+0x84/0xb8
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.724736] [<80419ab4>] kobject_add_internal+0xd0/0x2fc
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.730394] [<8041a220>] kobject_add+0x8c/0xb4
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.735120] [<80297928>] device_add+0x144/0x5cc
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.739938] [<8029c32c>] platform_device_add+0x1b8/0x254
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.745597] [<8029cce0>] platform_device_register_full+0xe0/0x14c
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.752080] [<8006203c>] ath79_register_pci_ar724x+0x138/0x16c
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.758296] [<8054d764>] ath79_register_pci+0x174/0x1e8
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.763847] [<8054dbf8>] ap91_pci_init+0x74/0x90
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.768761] [<805530fc>] cf_e385ac_setup+0x64/0x12c
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.773944] [<8054bf74>] ath79_setup+0x3c/0x54
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.778664] [<80060a50>] do_one_initcall+0xd0/0x1a0
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.783857] [<80549d5c>] kernel_init_freeable+0x150/0x210
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.789599] [<8042b480>] kernel_init+0x10/0x104
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.794429] [<80067018>] ret_from_kernel_thread+0x14/0x1c
Wed Jul 17 22:47:58 2019 kern.warn kernel: [    0.800171] ---[ end trace 911379ae8d9e351f ]---
Wed Jul 17 22:47:58 2019 kern.err kernel: [    0.805086] kobject_add_internal failed for ar724x-pci.1 with -EEXIST, don't try to register things with the same name in the same directory.
Wed Jul 17 22:47:58 2019 kern.info kernel: [    1.311808] PCI host bridge to bus 0000:00
Wed Jul 17 22:47:58 2019 kern.info kernel: [    1.316172] pci_bus 0000:00: root bus resource [mem 0x10000000-0x11ffffff]

Sorry to bump.

I haven’t figured it out yet. Any help is greatly appreciated :slight_smile:

I’d move to ath79 as ar71xx is dead with no appetite to work on it. You likely shouldn’t have to modify driver code.

"is", i.e. a singular device? If that's nothing you need to deploy automatically and multiple times, you can simply set the MAC addresses in the respective interface (/etc/config/network) or wifi-device (/etc/config/wireless) configurations (option macaddr).

(I have set my home wifi's MACs to OUI 00:22:06 :wink: )

1 Like

Hi @jeff

@takimata
I have more than 10 devices and I like to use MAC addresses to track and it also helps when trying to fix issues.

Thanks!

... that you probably have to go in and configure individually anyway. I'm not trying to argue against trying to understand a process, finding a flaw and fixing it. All I'm saying is that going in and setting a few mac addresses with an option that seems to be there for exactly that purpose might be far less effort.

@takimata Got it. What you said makes sense. I can set the MAC address every time APs boot up.

Once stored in the config, they will be set at every boot.

1 Like

@jeff I was thinking instead of storing in /etc/config/wireless, I could write a init.d script that set's the MAC address every time AP boots. This way I don't have to remember to set the MAC address if I add a new device.

You still only need to set the options once, even if you create a script for that. No need to do that on every boot. But you do you. :slight_smile:

1 Like

your lucky day ( maybe :wink: )

this is some guts ( non functional ) from something i was working on..... some of it may come in handy for you.....

#!/bin/sh
ecmd="echo"
Dd="`date +%Y%m%d`"
macPAYLOAD="ubootset"
macFINDMETHOD="stringsmmc"
macSAVEto="/root/synomacs"
macVERBprint="n"
macSTARTUPrpt="n"
macSTARTUPprint="n"

usage() {
	cat <<EOF
$0
EOF
}

generatenewmacstouboot() {

mac1="${1}"
macENDs="`echo $mac1 | cut -d':' -f6`"
macSTARTs="`echo $mac1 | cut -d':' -f1,2,3,4,5`"

mac2="`echo $macSTARTs`:$(($macENDs + 1))"
mac3="`echo $macSTARTs`:$(($macENDs + 2))"
mac4="`echo $macSTARTs`:$(($macENDs + 3))"
mac5="`echo $macSTARTs`:$(($macENDs + 4))"

echo "mac1-S:eth0-O:eth0.2: $mac1"
echo "mac2-S:eth1-unknown: $mac2 SKIP"
echo "mac3-S:eth2-O:eth1.1: $mac3"
echo "mac4-S:wlan0-: $mac4"
echo "mac5-S:wlan1-: $mac5"

if [ -f /root/synomacs ]; then
	echo "/root/synomacs exists... nohalt"
else	
	echo "macaddrwan $mac1" > /root/synomacs
	echo "macaddrlan $mac3" >> /root/synomacs
	echo "macaddrspare $mac2" >> /root/synomacs
	echo "macaddrwlan0 $mac4" >> /root/synomacs
	echo "macaddrwlan1 $mac5" >> /root/synomacs
fi

nummacs="`cat /root/synomacs | wc -l`"
if [ "$nummacs" -lt 5 ]; then
	echo "there are less than 5 macs in /root/synomacs" && exit 1;
else
	fw_setenv -s /root/synomacs
	touch "/root/.macset"
fi
}


setucimacs() {

ucilanmac="`uci get network.lan_dev.macaddr`"
if [ -z "$ucilanmac" ]; then
	echo "Setting lan_dev macaddr: $macaddrlan"
	uci -q set network.lan_dev.macaddr=$macaddrlan
else
	echo "UCI has macaddrlan: $ucilanmac"
fi

uciwanmac="`uci get network.wan_dev.macaddr`"
if [ -z "$uciwanmac" ]; then
	echo "Setting wan_dev macaddr: $macaddrwan"
	uci -q set network.wan_dev.macaddr=$macaddrwan
else
	echo "UCI has macaddrwan: $uciwanmac"
fi

uciwlan0mac="`uci get wireless.default_radio0.macaddr`"
if [ -z "$uciwlan0mac" ]; then
	echo "Setting wlan0 macaddr: $macaddrwlan0"
	uci -q set network.default_radio0.macaddr=$macaddrwlan0
else
	echo "UCI has macaddrwlan0: $uciwlan0mac"
fi

uciwlan1mac="`uci get wireless.default_radio1.macaddr`"
if [ -z "$uciwlan1mac" ]; then
	echo "Setting wlan1 macaddr: $macaddrwlan1"
	uci -q set network.default_radio1.macaddr=$macaddrwlan1
else
	echo "UCI has macaddrwlan1: $uciwlan1mac"
fi

ucihaschange="`uci changes | wc -l`"
if [ "$ucihaschange" -gt 0 ]; then
	uci commit
fi
}

ucimaccount() {

maccount="`uci show | grep macaddr | wc -l`"
if [ "$maccount" -lt 4 ]; then
	$ecmd "uci-mac-count is:$maccount"
	#exit
else
	$ecmd "uci-mac-count is:$maccount this is ok"
fi
}


ubootmaccount() {
maccount="`cat /tmp/fw_printenv | grep macaddr | wc -l`"
if [ "$maccount" -lt 4 ]; then
	#echo "maccountis: $maccount this is not enough"
	$ecmd "uboot-mac-count is:$maccount"
	#exit
else
	$ecmd "uboot-mac-count is:$maccount this is ok"
	#$echo "uboot-mac-count is:$maccount this is ok"
	#exit
fi
}

setmacvarsfromuboot() {
macaddrwan="`$fwp | grep macaddrwan 2>/dev/null | cut -d'=' -f2`"
macaddrspare="`$fwp | grep macaddrspare 2>/dev/null | cut -d'=' -f2`"
macaddrlan="`$fwp | grep macaddrlan 2>/dev/null | cut -d'=' -f2`"
macaddrwlan0="`$fwp | grep macaddrwlan0 2>/dev/null | cut -d'=' -f2`"
macaddrwlan1="`$fwp | grep macaddrwlan1 2>/dev/null | cut -d'=' -f2`"
}


printmacvars() {
echo "macaddrwan: $macaddrwan"
echo "macaddrspare: $macaddrspare"
echo "macaddrlan: $macaddrlan"
echo "macaddrwlan0: $macaddrwlan0"
echo "macaddrwlan1: $macaddrwlan1"
}

mODEL="`cat /tmp/sysinfo/board_name | cut -d',' -f2`"
if [ "$mODEL" != "rt2600ac" ]; then
	echo "invladmodel: $mODEL"
else
	:
fi



HOSTNAME="unknown"
MODEL=$(cat /etc/board.json | jsonfilter -e '@["model"]["id"]')
case $MODEL in
	tl-*|archer-*)  VENDOR=tplink ;;
	tplink,archer-c5-v2*) echo "MODEL match: tplink,archer-c5-v2"; VENDOR=c5v2 ;;
	cf-*) VENDOR=comfast ;;
	*rt2600ac*) VENDOR=synology ;;
	*nbg6817*) VENDOR=zyxtel ;;
	*) echo "VENDOR unknown MODEL: $MODEL"; VENDOR=ap ;;
esac
case $MODEL in
	tl-wdr*) NIC=wlan1 ;;
	tplink,archer-c5-v2*)  NIC=eth0 ;; ##br-lan eth0 eth0.1 eth0.2
	archer-*)  NIC=eth1 ;;
	cf-e380ac-v2) NIC=eth0 ;;
	*rt2600ac*) NIC=eth0 ;;
	*nbg6817*) NIC=eth0 ;;
	*) echo "NIC unknown MODEL: $MODEL"; NIC=br-lan ;; #NIC=wlan0 ;;
esac


#checkbasicpackages

$ecmd "############################ Copy /etc/board.json > /etc/board.json.org"
if [ ! -f /etc/board.json.org ]; then
    cp -a /etc/board.json /etc/board.json.org
fi

$ecmd "############################ Dumping current fw_printenv > /tmp/fw_printenv"
which fw_printenv 2>/dev/null 1>/dev/null
if [ $0 -eq 0 ]; then
	fw_printenv > /tmp/fw_printenv
	fwp="cat /tmp/fw_printenv"
	fwpTXT="`cat /tmp/fw_printenv`"
else
	echo "No fw_printenv"
fi


###########################################################################
#macPAYLOAD="ubootset" #uciset #gettotxt #runtimeapply
#case "$macPAYLOAD" in
#    ubootset)
#        ;;
#esac

if [ "$ubootmaccount" -eq 0 ] && [ "$macPAYLOAD" == "ubootset" ]; then
	#dumpsynomacfromtxtrecord
	#printmacvars
fi

if [ "$ucimaccount" -lt 3 ] && [ "$macPAYLOAD" == "uciset" ]; then
	:
	#setucimacs
	#setmacvarsfromuboot
	#printmacvars
fi


#if [ -z "$macaddrlan" ] && [ ! -f "/root/.macset" ]; then
if [ -z "$macaddrlan" ]; then
	echo "Need to dump generate newmacs and save to uboot"
	generatenewmacstouboot "STARTMAC"
	#touch "/root/.macset"
else
	echo "ethaddrlan is set: $ethaddrlan"
	echo "macaddresses are set in uboot"
	#setucimacs
	#setboardjsonmacsingle "lan" "$macaddrlan"
	#setboardjsonmacsingle "wan" "$macaddrwan"
fi


######################################################################
exit





setboardjsonmacsingle() { #1 lan|wan #2 newmac-withcolons #case 1 lan|wan * exit
$ecmd "NOTE: altering /etc/board.json careful on backup restore and manual macchange"
if [ ! -f /etc/board.json.org ]; then
    echo "Creating /etc/board.json.org"
    sleep 2
    cp -a /etc/board.json /etc/board.json.org
fi
MACo="`cat /etc/board.json | jsonfilter -e '@["network"]["${1}"]["macaddr"]'`"
MACn="${2}"
sed -i "s/$MACo/$MACn/g" /etc/board.json

ucimac="`uci get network.${1}_dev.macaddr`"
sed -i "s/$MACo/$MACn/g" /etc/config/network
sed -i "s/$ucimac/$MACn/g" /etc/config/network
}

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.