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