Contiki-NG
deployment.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018, RISE SICS.
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  */
30 
31 /**
32 * \addtogroup deployment
33 * @{
34 *
35 * \file
36  Per-deployment MAC <-> nodeid mapping
37 * \author Simon Duquennoy <simon.duquennoy@ri.se>
38 *
39 */
40 
41 #ifndef DEPLOYMENT_H_
42 #define DEPLOYMENT_H_
43 
44 #include "contiki-conf.h"
45 #include "sys/node-id.h"
46 #include "net/ipv6/uip.h"
47 #include "net/linkaddr.h"
48 
49 /**
50  * \brief ID<->MAC address mapping structure
51  */
52 struct id_mac {
53  uint16_t id;
54  linkaddr_t mac;
55 };
56 
57 /**
58  * DEPLOYMENT_MAPPING:
59  * A table of struct id_mac that provides ID-MAC mapping for a deployment.
60  * Example with four nodes:
61  * In configuration file:
62  * \#define DEPLOYMENT_MAPPING custom_array
63  * In a .c file:
64  * const struct id_mac custom_array[] = {
65  { 1, {{0x00,0x12,0x4b,0x00,0x06,0x0d,0xb6,0x14}}},
66  { 2, {{0x00,0x12,0x4b,0x00,0x06,0x0d,0xb1,0xe7}}},
67  { 3, {{0x00,0x12,0x4b,0x00,0x06,0x0d,0xb4,0x35}}},
68  { 4, {{0x00,0x12,0x4b,0x00,0x06,0x0d,0xb1,0xcf}}},
69  { 0, {{0}}}
70  };
71  */
72 
73 /**
74  * Initialize the deployment module
75  */
76 void deployment_init(void);
77 
78 /**
79  * Get the number of nodes for the deployment (length of mapping table)
80  *
81  * \return The number of nodes in the deployment
82  */
83 int deployment_node_count(void);
84 
85 /**
86  * Get node ID from a link-layer address, from the deployment mapping table
87  *
88  * \param lladdr The link-layer address to look up for
89  * \return Node ID from a corresponding link-layer address
90  */
91 uint16_t deployment_id_from_lladdr(const linkaddr_t *lladdr);
92 
93 /**
94  * Get node link-layer address from a node ID, from the deployment mapping table
95  *
96  * \param lladdr A pointer where to write the link-layer address
97  * \param id The node ID to look up for
98  */
99 void deployment_lladdr_from_id(linkaddr_t *lladdr, uint16_t id);
100 
101 /**
102  * Get node ID from the IID of an IPv6 address
103  *
104  * \param ipaddr The IPv6 (global or link-local) address that contains the IID
105  * \return Node ID from a corresponding IID
106  */
107 uint16_t deployment_id_from_iid(const uip_ipaddr_t *ipaddr);
108 
109 /**
110  * Get IPv6 IID from node IDs
111  *
112  * \param ipaddr The IPv6 where to write the IID
113  * \param id The node ID
114  */
115 void deployment_iid_from_id(uip_ipaddr_t *ipaddr, uint16_t id);
116 
117 /**
118  * Get node ID from index in mapping table
119  *
120  * \param index The index in the deployment mapping table
121  * \return Node ID at the corresponding index
122  */
123 uint16_t deployment_id_from_index(uint16_t index);
124 
125 #endif /* DEPLOYMENT_H_ */
126 /** @} */
static uip_ipaddr_t ipaddr
Pointer to prefix information option in uip_buf.
Definition: uip-nd6.c:125
Header file for the link-layer address representation
Node-id (simple 16-bit identifiers) handling.
void deployment_iid_from_id(uip_ipaddr_t *ipaddr, uint16_t id)
Get IPv6 IID from node IDs.
Definition: deployment.c:123
ID<->MAC address mapping structure.
Definition: deployment.h:52
void deployment_init(void)
DEPLOYMENT_MAPPING: A table of struct id_mac that provides ID-MAC mapping for a deployment.
Definition: deployment.c:62
int deployment_node_count(void)
Get the number of nodes for the deployment (length of mapping table)
Definition: deployment.c:76
Header file for the uIP TCP/IP stack.
uint16_t deployment_id_from_lladdr(const linkaddr_t *lladdr)
Get node ID from a link-layer address, from the deployment mapping table.
Definition: deployment.c:82
void deployment_lladdr_from_id(linkaddr_t *lladdr, uint16_t id)
Get node link-layer address from a node ID, from the deployment mapping table.
Definition: deployment.c:99
uint16_t deployment_id_from_index(uint16_t index)
Get node ID from index in mapping table.
Definition: deployment.c:131
uint16_t deployment_id_from_iid(const uip_ipaddr_t *ipaddr)
Get node ID from the IID of an IPv6 address.
Definition: deployment.c:115