Contiki-NG
Loading...
Searching...
No Matches
linkaddr.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2007, Swedish Institute of Computer Science.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the Institute nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * This file is part of the Contiki operating system.
30 *
31 */
32
33/**
34 * \file
35 * Header file for the link-layer address representation
36 * \author
37 * Adam Dunkels <adam@sics.se>
38 */
39
40/**
41 * \addtogroup link-layer
42 * @{
43 */
44
45/**
46 * \defgroup linkaddr Link-layer addresses
47 * @{
48 *
49 * The linkaddr module handles link-layer addresses.
50 *
51 */
52
53#ifndef LINKADDR_H_
54#define LINKADDR_H_
55
56#include "contiki.h"
57
58#ifdef LINKADDR_CONF_SIZE
59#define LINKADDR_SIZE LINKADDR_CONF_SIZE
60#else /* LINKADDR_SIZE */
61#define LINKADDR_SIZE 8
62#endif /* LINKADDR_SIZE */
63
64typedef union {
65 unsigned char u8[LINKADDR_SIZE];
66#if LINKADDR_SIZE == 2
67 uint16_t u16;
68#else
69 uint16_t u16[LINKADDR_SIZE/2];
70#endif /* LINKADDR_SIZE == 2 */
71} linkaddr_t;
72
73/**
74 * \brief Construct a MAC eight-bytes address.
75 * \param addr The linkaddr_t variable to set (must be of type linkaddr_t)
76 *
77 * This macro constructs a MAC address of 8 bytes.
78 * Example:
79 \code
80 linkaddr_t addr;
81 linkaddr_u8(addr, 0x01, 0x02, 0x23, 0x24, 0x25, 0x06, 0x07, 0x08);
82 \endcode
83 *
84 * \hideinitializer
85 */
86#define linkaddr_u8(addr, addr0, addr1, addr2, addr3, addr4, addr5, addr6, addr7) \
87 do { \
88 _Static_assert(LINKADDR_SIZE == 8, \
89 "linkaddr_u8 requires LINKADDR_SIZE == 8"); \
90 (addr).u8[0] = (addr0); \
91 (addr).u8[1] = (addr1); \
92 (addr).u8[2] = (addr2); \
93 (addr).u8[3] = (addr3); \
94 (addr).u8[4] = (addr4); \
95 (addr).u8[5] = (addr5); \
96 (addr).u8[6] = (addr6); \
97 (addr).u8[7] = (addr7); \
98 } while(0)
99
100/**
101 * \brief Copy a link-layer address
102 * \param dest The destination
103 * \param from The source
104 *
105 * This function copies a link-layer address from one location
106 * to another.
107 *
108 */
109void linkaddr_copy(linkaddr_t *dest, const linkaddr_t *from);
110
111/**
112 * \brief Compare two link-layer addresses
113 * \param addr1 The first address
114 * \param addr2 The second address
115 * \return True if the addresses are the same, false if they are different
116 */
117bool linkaddr_cmp(const linkaddr_t *addr1, const linkaddr_t *addr2);
118
119
120/**
121 * \brief The link-layer address of the node
122 *
123 * This variable contains the link-layer address of the
124 * node. This variable should not be changed directly;
125 * rather, the linkaddr_set_node_addr() function should be
126 * used.
127 *
128 */
129extern linkaddr_t linkaddr_node_addr;
130
131/**
132 * \brief The null link-layer address
133 *
134 * This variable contains the null link-layer address. The null
135 * address is used in route tables to indicate that the
136 * table entry is unused. Nodes with no configured address
137 * has the null address. Nodes with their node address set
138 * to the null address will have problems communicating
139 * with other nodes.
140 *
141 */
142extern const linkaddr_t linkaddr_null;
143
144/**
145 * \brief Set the address of the current node
146 * \param addr The address
147 *
148 * This function sets the link-layer address of the node.
149 *
150 */
151static inline void linkaddr_set_node_addr(linkaddr_t *addr)
152{
154}
155
156#endif /* LINKADDR_H_ */
157/** @} */
158/** @} */
linkaddr_t linkaddr_node_addr
The link-layer address of the node.
Definition linkaddr.c:48
void linkaddr_copy(linkaddr_t *dest, const linkaddr_t *src)
Copy a link-layer address.
Definition linkaddr.c:63
bool linkaddr_cmp(const linkaddr_t *addr1, const linkaddr_t *addr2)
Compare two link-layer addresses.
Definition linkaddr.c:69
const linkaddr_t linkaddr_null
The null link-layer address.
static void linkaddr_set_node_addr(linkaddr_t *addr)
Set the address of the current node.
Definition linkaddr.h:151
static uip_ds6_addr_t * addr
Pointer to a nbr cache entry.
Definition uip-nd6.c:107