mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] of: of_net: add support to parse ASCII encoded mac-addresses
@ 2023-08-07 17:07 Marco Felsch
  2023-08-08  5:51 ` Sascha Hauer
  2023-08-08  9:36 ` Ahmad Fatoum
  0 siblings, 2 replies; 7+ messages in thread
From: Marco Felsch @ 2023-08-07 17:07 UTC (permalink / raw)
  To: barebox

Some vendors like Polyhex store the MAC address ASCII encoded instead of
using the plain 6-byte MAC address. This commit adds the support to
decode the 12-byte ASCII encoded MAC addresses.

Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
 drivers/of/of_net.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/drivers/of/of_net.c b/drivers/of/of_net.c
index 75a24073da51..4e74986cdda8 100644
--- a/drivers/of/of_net.c
+++ b/drivers/of/of_net.c
@@ -79,6 +79,8 @@ static int of_get_mac_addr(struct device_node *np, const char *name, u8 *addr)
 	return -ENODEV;
 }
 
+#define ETH_ALEN_ASCII	12
+
 int of_get_mac_addr_nvmem(struct device_node *np, u8 *addr)
 {
 	struct nvmem_cell *cell;
@@ -98,6 +100,23 @@ int of_get_mac_addr_nvmem(struct device_node *np, u8 *addr)
 	if (IS_ERR(mac))
 		return PTR_ERR(mac);
 
+	if (len == ETH_ALEN_ASCII) {
+		u8 *mac_new;
+		int ret;
+
+		mac_new = kzalloc(sizeof("xx:xx:xx:xx:xx:xx"), GFP_KERNEL);
+		ret = hex2bin(mac_new, mac, ETH_ALEN);
+		if (ret) {
+			kfree(mac_new);
+			kfree(mac);
+			return ret;
+		}
+
+		kfree(mac);
+		mac = mac_new;
+		len = ETH_ALEN;
+	}
+
 	if (len != ETH_ALEN || !is_valid_ether_addr(mac)) {
 		kfree(mac);
 		return -EINVAL;
-- 
2.39.2




^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-08-08 16:21 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-07 17:07 [PATCH] of: of_net: add support to parse ASCII encoded mac-addresses Marco Felsch
2023-08-08  5:51 ` Sascha Hauer
2023-08-08  7:58   ` Marco Felsch
2023-08-08  9:36 ` Ahmad Fatoum
2023-08-08  9:46   ` Marco Felsch
2023-08-08 10:23     ` Ahmad Fatoum
2023-08-08 16:20       ` Marco Felsch

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox