2 * Copyright (c) 2015, Adrian Chadd <adrian@FreeBSD.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice unmodified, this list of conditions, and the following
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 #include <sys/cdefs.h>
29 __FBSDID("$FreeBSD$");
31 #include <sys/param.h>
32 #include <sys/systm.h>
33 #include <sys/types.h>
34 #include <sys/libkern.h>
36 #include <net/ethernet.h>
38 #include <mips/atheros/ar71xx_macaddr.h>
41 * Some boards don't have a separate MAC address for each individual
42 * device on-board, but instead need to derive them from a single MAC
43 * address stored somewhere.
45 uint8_t ar71xx_board_mac_addr[ETHER_ADDR_LEN];
48 * Initialise a MAC address 'dst' from a MAC address 'src'.
50 * 'offset' is added to the low three bytes to allow for sequential
51 * MAC addresses to be derived from a single one.
53 * 'is_local' is whether this 'dst' should be made a local MAC address.
55 * Returns 0 if it was successfully initialised, -1 on error.
58 ar71xx_mac_addr_init(unsigned char *dst, const unsigned char *src,
59 int offset, int is_local)
63 if (dst == NULL || src == NULL)
66 /* XXX TODO: validate 'src' is a valid MAC address */
68 t = (((uint32_t) src[3]) << 16)
69 + (((uint32_t) src[4]) << 8)
70 + ((uint32_t) src[5]);
72 /* Note: this is handles both positive and negative offsets */
78 dst[3] = (t >> 16) & 0xff;
79 dst[4] = (t >> 8) & 0xff;
85 /* Everything's okay */
90 * Initialise a random MAC address for use by if_arge.c and whatever
93 * Returns 0 on success, -1 on error.
96 ar71xx_mac_addr_random_init(unsigned char *dst)
105 dst[3] = (rnd >> 24) & 0xff;
106 dst[4] = (rnd >> 16) & 0xff;
107 dst[5] = (rnd >> 8) & 0xff;