Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F162320300
D58104.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D58104.diff
View Options
diff --git a/sys/dev/fdt/fdt_common.h b/sys/dev/fdt/fdt_common.h
--- a/sys/dev/fdt/fdt_common.h
+++ b/sys/dev/fdt/fdt_common.h
@@ -33,8 +33,11 @@
#include <sys/sysctl.h>
#include <sys/slicer.h>
+#include <sys/socket.h>
#include <contrib/libfdt/libfdt_env.h>
#include <dev/ofw/ofw_bus.h>
+#include <net/ethernet.h>
+#include <net/if.h>
#define FDT_MEM_REGIONS 64
@@ -70,6 +73,7 @@
int fdt_addrsize_cells(phandle_t, int *, int *);
u_long fdt_data_get(const void *, int);
int fdt_data_to_res(const pcell_t *, int, int, u_long *, u_long *);
+void fdt_ether_get_addr(phandle_t node, struct ifnet *ifp, uint8_t *eaddr);
phandle_t fdt_find_compatible(phandle_t, const char *, int);
phandle_t fdt_depth_search_compatible(phandle_t, const char *, int);
int fdt_foreach_mem_region(fdt_mem_region_cb, void *);
diff --git a/sys/dev/fdt/fdt_common.c b/sys/dev/fdt/fdt_common.c
--- a/sys/dev/fdt/fdt_common.c
+++ b/sys/dev/fdt/fdt_common.c
@@ -553,3 +553,43 @@
return (ENXIO);
return (0);
}
+
+/*
+ * fdt_ether_get_addr - Get ethernet MAC address using FDT properties.
+ * Order:
+ * 1. "mac-address"
+ * 2. "local-mac-address"
+ * 3. Keep pre-initialized value (if valid)
+ * 4. random ether_gen_addr() as last resort
+ */
+void
+fdt_ether_get_addr(phandle_t node, struct ifnet *ifp, uint8_t *eaddr)
+{
+ uint8_t tmp[ETHER_ADDR_LEN];
+ int len;
+
+ /* Firstly try "mac-address" */
+ len = OF_getprop(node, "mac-address", tmp, sizeof(tmp));
+ if (len == ETHER_ADDR_LEN && !ETHER_IS_ZERO(tmp) &&
+ !ETHER_IS_MULTICAST(tmp)) {
+ bcopy(tmp, eaddr, ETHER_ADDR_LEN);
+ return;
+ }
+
+ /* Next use "local-mac-address" */
+ len = OF_getprop(node, "local-mac-address", tmp, sizeof(tmp));
+ if (len == ETHER_ADDR_LEN && !ETHER_IS_ZERO(tmp) &&
+ !ETHER_IS_MULTICAST(tmp)) {
+ bcopy(tmp, eaddr, ETHER_ADDR_LEN);
+ return;
+ }
+
+ /* Next use existing one if set */
+ if (!ETHER_IS_ZERO(eaddr) && !ETHER_IS_MULTICAST(eaddr))
+ return;
+
+ /* Last resort - generate random one */
+ ether_gen_addr(ifp, (struct ether_addr *)eaddr);
+
+ return;
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Jul 13, 12:54 AM (13 h, 36 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
34922684
Default Alt Text
D58104.diff (2 KB)
Attached To
Mode
D58104: FDT: implement fdt_ether_get_addr()
Attached
Detach File
Event Timeline
Log In to Comment