summaryrefslogtreecommitdiff
path: root/include/local_mac_address.h
blob: 5d2fb9d4c2e031aca54ebb11a01c2f7638103bff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/* SPDX-License-Identifier: GPL-2.0-only */
/*
 * Copyright (C) 2012 Jean-Christophe PLAGNIOL-VILLARD <plagnio@jcrosoft.com>
 */

#ifndef __LOCAL_MAC_ADDRESS_H__
#define __LOCAL_MAC_ADDRESS_H__

#include <net.h>

/**
 * local_mac_address_register - use random number with fix
 * OUI provided device to provide an Ethernet address
 * @ethid: ethernet device id
 * @oui: Ethernet OUI (3 bytes)
 *
 * Generate a local Ethernet address (MAC) that is not multicast using a 1-wire id.
 */
static inline int local_mac_address_register(int ethid, char * oui)
{
	char addr[6];
	int nb_oui = 3;
	int i;

	if (!oui)
		return -EINVAL;

	random_ether_addr(addr);

	for (i = 0; i < nb_oui; i++)
		addr[i] = oui[i];

	addr[0] &= 0xfe;	/* clear multicast bit */
	addr[0] |= 0x02;	/* set local assignment bit (IEEE802) */

	eth_register_ethaddr(ethid, addr);

	return 0;
}

#endif /* __LOCAL_MAC_ADDRESS_H__ */