Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
| docs:guide-developer:mac.address [2019/10/08 14:08] – Add known MAC offset cases adrianschmutzler | docs:guide-developer:mac.address [2021/01/03 21:09] (current) – [Find out about flash locations] . /lib/functions/system.sh sources /lib/functions.sh borromini | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ==== Device Support: MAC address setup ==== | + | ====== Device Support: MAC address setup ====== |
| - | === Retrieve addresses from stock firmware === | + | ===== Retrieve addresses from stock firmware |
| The first step is to find out which addresses are present in stock configuration. | The first step is to find out which addresses are present in stock configuration. | ||
| Line 15: | Line 15: | ||
| </ | </ | ||
| - | === Find out about flash locations === | + | |
| + | ===== Find out about flash locations | ||
| If you already have OpenWrt running on the device, you can try to find out about MAC locations on flash (note that not all devices store addresses there). | If you already have OpenWrt running on the device, you can try to find out about MAC locations on flash (note that not all devices store addresses there). | ||
| Line 37: | Line 38: | ||
| The same should be done for other partitions. Usual suspects are: | The same should be done for other partitions. Usual suspects are: | ||
| - | - factory | + | * factory |
| - | - mac | + | |
| - | - config | + | |
| - | - art | + | |
| - | - u-boot | + | |
| If you are successful, you will have a list of addresses and locations, e.g. | If you are successful, you will have a list of addresses and locations, e.g. | ||
| + | < | ||
| factory 0xe000 *:0A | factory 0xe000 *:0A | ||
| factory 0xe006 *:0B | factory 0xe006 *:0B | ||
| art 0x4 *:0A | art 0x4 *:0A | ||
| + | </ | ||
| You can check your data by using OpenWrt' | You can check your data by using OpenWrt' | ||
| Line 54: | Line 57: | ||
| or by using mtd_get_mac_binary (based on partition label): | or by using mtd_get_mac_binary (based on partition label): | ||
| < | < | ||
| - | . / | ||
| mtd_get_mac_binary art 0x4</ | mtd_get_mac_binary art 0x4</ | ||
| - | === Merge your data === | + | |
| + | ===== Merge your data ===== | ||
| Now, combine data from stock firmware and your research to have a complete list: | Now, combine data from stock firmware and your research to have a complete list: | ||
| Line 72: | Line 75: | ||
| As in the example, it is possible that the same address is present in different locations. In this case, use the location that " | As in the example, it is possible that the same address is present in different locations. In this case, use the location that " | ||
| - | === Set MAC addresses === | + | |
| + | ===== Set MAC addresses | ||
| TBD: mtd_mac_address, | TBD: mtd_mac_address, | ||
| - | == MAC address pulled by driver == | + | |
| + | ==== MAC address pulled by driver | ||
| In several cases, the MAC address is already provided at the correct location for the driver to use it automatically. | In several cases, the MAC address is already provided at the correct location for the driver to use it automatically. | ||
| + | |||
| + | //(This list is incomplete. Please extend it.)// | ||
| Known cases: | Known cases: | ||
| - | ath79: mtd-cal-data: | + | * ath79: |
| - | ramips: mediatek, | + | |
| - | ath10k: offset + 6 | + | * **ath9k**: offset + 2 (mostly) |
| + | * **ath10k**: offset + 6 | ||
| So, if you have MAC location matching those, you do not have to specify the MAC address in DTS or base-files for the particular interface. | So, if you have MAC location matching those, you do not have to specify the MAC address in DTS or base-files for the particular interface. | ||
| - | === Label MAC address === | + | Correct: |
| + | < | ||
| + | &wmac { | ||
| + | status = " | ||
| + | |||
| + | mtd-cal-data = <& | ||
| + | }; | ||
| + | </ | ||
| + | |||
| + | Suboptimal (not precisely wrong): | ||
| + | < | ||
| + | &wmac { | ||
| + | status = " | ||
| + | |||
| + | mtd-cal-data = <& | ||
| + | mtd-mac-address = <& | ||
| + | }; | ||
| + | </ | ||
| + | |||
| + | This can also be exploited for setting the label MAC address (see below) via 02_network. | ||
| + | |||
| + | ===== Label MAC address | ||
| refs: | refs: | ||
| Line 95: | Line 124: | ||
| Many devices bear a label with one or several MAC addresses on it. Those may be used to identify the device in the network and thus represent a valuable additional information about the device. | Many devices bear a label with one or several MAC addresses on it. Those may be used to identify the device in the network and thus represent a valuable additional information about the device. | ||
| - | During | + | When adding |
| There are two options to specify the label MAC address in OpenWrt: | There are two options to specify the label MAC address in OpenWrt: | ||
| - | == label-mac-device DTS file == | + | |
| + | ==== label-mac-device DTS file ==== | ||
| We can refer to the device bearing the label MAC address in DTS. For that purpose, one needs to reference the node with an alias, e.g. | We can refer to the device bearing the label MAC address in DTS. For that purpose, one needs to reference the node with an alias, e.g. | ||
| < | < | ||
| - | label-mac-device = &wifi0; | + | label-mac-device = &wifi0; |
| }</ | }</ | ||
| - | Obviously, this is only valid if the 5 GHz Wifi actually has been named wifi0. | + | Obviously, this is only valid if the 5 GHz Wifi device tree node actually has been named wifi0. |
| - | Attention: Not all interface can be referenced this way. To check whether there actually is a usable MAC address, check the device tree on your router: | + | //Attention: Not all interface can be referenced this way. To check whether there actually is a usable MAC address, check the device tree on your router:// |
| Run | Run | ||
| Line 115: | Line 145: | ||
| on your device. | on your device. | ||
| - | Attention: This will only work if you have already set up MAC addresses correctly based on the information retrieved above. | + | //Attention: This will only work if you have already set up MAC addresses correctly based on the information retrieved above.// |
| It will give you a list like the following: | It will give you a list like the following: | ||
| + | < | ||
| / | / | ||
| / | / | ||
| Line 124: | Line 155: | ||
| / | / | ||
| / | / | ||
| + | </ | ||
| For each of the returned paths (if there are any), retrieve the mac-address, | For each of the returned paths (if there are any), retrieve the mac-address, | ||
| < | < | ||
| - | get_mac_binary "$yourpath" 0</ | + | get_mac_binary "/ |
| - | Valid choices are only mac-address or local-mac-address. There may be one, two or no paths giving the correct address. | + | Valid choices are only '' |
| - | If you find the label MAC address here, check your DTS for the corresponding parent node. The correct node for ''/ | + | If you find the label MAC address here, check your DTS for the corresponding parent node. The correct node for ''/ |
| - | Attention: Note that label MAC address | + | //Attention: Note that label MAC addresses |
| - | == Set label MAC address via 02_network == | + | ==== Set label MAC address via 02_network |
| If device tree does not lead to the relevant MAC address, we can still set it in 02_network. In this case, you need to set label_mac in a similar way as it is already used for lan_mac and wan_mac, e.g. | If device tree does not lead to the relevant MAC address, we can still set it in 02_network. In this case, you need to set label_mac in a similar way as it is already used for lan_mac and wan_mac, e.g. | ||
| Line 142: | Line 174: | ||
| < | < | ||
| wan_mac=$(mtd_get_mac_binary factory 0x2e) | wan_mac=$(mtd_get_mac_binary factory 0x2e) | ||
| - | label_mac=$(cat / | + | label_mac=$(mtd_get_mac_binary factory 0x4) # e.g. on ramips when caldata is read from factory 0x0 |
| belkin, | belkin, | ||
| wan_mac=$(mtd_get_mac_ascii uboot-env HW_WAN_MAC) | wan_mac=$(mtd_get_mac_ascii uboot-env HW_WAN_MAC) | ||
| lan_mac=$(mtd_get_mac_ascii uboot-env HW_LAN_MAC) | lan_mac=$(mtd_get_mac_ascii uboot-env HW_LAN_MAC) | ||
| - | label_mac=$wan_mac</ | + | label_mac=$wan_mac</ |
| This is evaluated below by the line | This is evaluated below by the line | ||
| Line 154: | Line 186: | ||
| If possible, setting the address with the DTS approach is preferred. | If possible, setting the address with the DTS approach is preferred. | ||
| - | === Common MAC locations === | ||
| - | If there is an ART partition, WiFi MAC addresses are typically stored there. | + | ==== Using the label MAC address ==== |
| + | |||
| + | When everything is set up correctly, the label MAC address can be accessed with: | ||
| + | |||
| + | < | ||
| + | . / | ||
| + | . / | ||
| + | label_mac_addr=$(get_mac_label) | ||
| + | </ | ||
| + | ===== Common MAC address locations ===== | ||
| + | |||
| + | If there is an ART partition, WiFi MAC addresses are frequently/typically stored there. | ||
| ath79: | ath79: | ||
| - | - All TP-LINK routers using old tp-link header (those using Device/ | + | * All TP-LINK routers using old tp-link header (those using Device/ |
| ramips: | ramips: | ||
| For ramips, typical locations for ethernet addresses are as follows: | For ramips, typical locations for ethernet addresses are as follows: | ||
| - | - mt7621: lan mac is at factory 0xe000 and wan mac at factory 0xe006. This is the default location for mt7621 boards in MTK's SDK. | + | * mt7621: lan mac is at factory 0xe000 and wan mac at factory 0xe006. This is the default location for mt7621 boards in MTK's SDK. |
| - | - For mt7620/ | + | |
| - | Attention: Those are //typical// addresses. Some vendors mix them, invert them, or even use completely different locations! | + | //Attention: Those are //typical// addresses. Some vendors mix them, invert them, or even use completely different locations!// |