NetSim Source Code Help v14.4
All 13 Components
 
Loading...
Searching...
No Matches
RPL_Message.h
1#pragma once
2/************************************************************************************
3* Copyright (C) 2023 *
4* TETCOS, Bangalore. India *
5* *
6* Tetcos owns the intellectual property rights in the Product and its content. *
7* The copying, redistribution, reselling or publication of any or all of the *
8* Product or its content without express prior written consent of Tetcos is *
9* prohibited. Ownership and / or any other right relating to the software and all *
10* intellectual property rights therein shall remain at all times with Tetcos. *
11* *
12* Author: Shashi Kant Suman *
13* *
14* ---------------------------------------------------------------------------------*/
15
16/************************************************************************************
17https://tools.ietf.org/html/rfc6550
18************************************************************************************/
19
20#define ICMP_TYPE_RPL 0x9B
21
22typedef enum
23{
24 DODAG_Information_Solicitation = 0x00,
25 DODAG_Information_Object = 0x01,
26 Destination_Advertisement_Object = 0x02,
27 Destination_Advertisement_Object_Acknowledgment = 0x03,
28 Secure_DODAG_Information_Solicitation = 0x80,
29 Secure_DODAG_Information_Object = 0x81,
30 Secure_Destination_Advertisement_Object = 0x82,
31 Secure_Destination_Advertisement_Object_Acknowledgment = 0x83,
32 Consistency_Check = 0x8A,
33}RPL_CTRL_MSG_CODE;
34
35#define GET_RPL_CTRL_PACKET_TYPE(code) (NW_PROTOCOL_RPL*100+code)
36#define GET_RPL_CTRL_MSG_CODE(packet) (packet->nControlDataType%100)
37
38
39typedef enum enum_rpl_option_type
40{
41 RPLOPTION_Pad1 = 0x00,
42 RPLOPTION_PadN,
43 RPLOPTION_DAGMetricsContainer,
44 RPLOPTION_RoutingInformation,
45 RPLOPTION_DODAGConfiguration,
46 RPLOPTION_RPLTARGET,
47 RPLOPTION_PrefixInformation = 0x08,
48}RPL_OPTION_TYPE;
49typedef struct stru_rpl_option
50{
51 RPL_OPTION_TYPE type;
52 void* option;
53}RPL_OPTION,*PRPL_OPTION;
54
55/* 6. ICMPv6 RPL Control Message
56
570 1 2 3
580 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
59+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
60| Type | Code | Checksum |
61+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
62| |
63. Base .
64. .
65+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
66| |
67. Option(s) .
68. .
69+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
70
71Figure 6: RPL Control Message
72*/
73
75{
76 UINT8 Type;
77 UINT8 Code;
78 UINT16 Checksum;
79 void* Base;
80 PRPL_OPTION* options;
81 UINT option_count;
82}RPL_CTRL_MSG,*PRPL_CTRL_MSG;
83#define GET_PRPL_CTRL_MSG(packet) ((PRPL_CTRL_MSG)(PACKET_NWDATA(packet)->Packet_RoutingProtocol))
84#define SET_BASE_IN_MSG(packet,b) (GET_PRPL_CTRL_MSG(packet)->Base = b)
85#define GET_BASE_FROM_MSG(packet) (GET_PRPL_CTRL_MSG(packet)->Base)
86#define RPL_CTRL_MSG_SIZE_FIXED 4 //Bytes
87
88
89/*
906.2.1. Format of the DIS Base Object
91
920 1 2
930 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3
94+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
95| Flags | Reserved | Option(s)...
96+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
97
98Figure 13: The DIS Base Object
99*/
100typedef struct stru_rpl_DIS_Base
101{
102 UINT8 Flags;
103 UINT8 Reserved;
104}RPL_DIS_BASE,*PRPL_DIS_BASE;
105#define RPL_DIS_BASE_SIZE 2 //Bytes
106
107
108/*
1096.3.1. Format of the DIO Base Object
110
1110 1 2 3
1120 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
113+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
114| RPLInstanceID |Version Number | Rank |
115+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
116|G|0| MOP | Prf | DTSN | Flags | Reserved |
117+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
118| |
119+ +
120| |
121+ DODAGID +
122| |
123+ +
124| |
125+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
126| Option(s)...
127+-+-+-+-+-+-+-+-+
128
129Figure 14: The DIO Base Object
130*/
131typedef struct stru_rpl_dio_base
132{
133 UINT8 RPLInstanceID;
134 UINT8 Version_Number;
135 UINT16 Rank;
136 UINT G : 1;
137 UINT zero : 1;
138 UINT MOP : 3;
139 UINT Prf : 3;
140 UINT8 DTSN;
141 UINT8 Flags;
142 UINT8 Reserved;
143 NETSIM_IPAddress DODAGID;
144}RPL_DIO_BASE,*PRPL_DIO_BASE;
145#define RPL_DIO_BASE_SIZE 24 //Bytes
146
147/*
1486.4.1. Format of the DAO Base Object
149
1500 1 2 3
1510 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
152+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
153| RPLInstanceID |K|D| Flags | Reserved | DAOSequence |
154+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
155| |
156+ +
157| |
158+ DODAGID* +
159| |
160+ +
161| |
162+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
163| Option(s)...
164+-+-+-+-+-+-+-+-+
165*/
166typedef struct stru_rpl_dao_base
167{
168 UINT8 RPLInstanceID;
169 UINT K : 1;
170 UINT D : 1;
171 UINT Flags : 6;
172 UINT8 Reserved;
173 UINT8 DAOSequence;
174 NETSIM_IPAddress DODAGID;
175}RPL_DAO_BASE, *PRPL_DAO_BASE;
176#define RPL_DAO_BASE_SIZE 20 //Bytes
177
178/*
1796.5.1. Format of the DAO-ACK Base Object
180
1810 1 2 3
1820 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
183+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
184| RPLInstanceID |D| Reserved | DAOSequence | Status |
185+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
186| |
187+ +
188| |
189+ DODAGID* +
190| |
191+ +
192| |
193+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
194| Option(s)...
195+-+-+-+-+-+-+-+-+
196*/
198{
199 UINT8 RPLInstanceID;
200 UINT D : 1;
201 UINT Reserved : 7;
202 UINT8 DAOSequence;
203 UINT8 Status;
204 UINT DODAGID[4];
205}RPL_DAOACK_BASE,*PRPL_DAOACK_BASE;
206#define RPL_DAOACK_BASE_SIZE 20 //Bytes
207
208
209/*
2106.6.1. Format of the CC Base Object
211
212 0 1 2 3
213 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
214 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
215 | RPLInstanceID |R| Flags | CC Nonce |
216 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
217 | |
218 + +
219 | |
220 + DODAGID +
221 | |
222 + +
223 | |
224 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
225 | Destination Counter |
226 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
227 | Option(s)...
228 +-+-+-+-+-+-+-+-+
229
230 Figure 18: The CC Base Object
231*/
232typedef struct stru_rpl_cc_base
233{
234 UINT8 RPLInstanceID;
235 UINT R : 1;
236 UINT Flags : 7;
237 UINT16 CC_Nonce;
238 UINT DODAGID[4];
239 UINT DestinationCounter;
240}RPL_CC_BASE,*PRPL_CC_BASE;
241
242/*
243The DODAG Configuration option MAY be present in DIO messages, and
244its format is as follows:
245
2460 1 2 3
2470 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
248+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
249| Type = 0x04 |Opt Length = 14| Flags |A| PCS | DIOIntDoubl. |
250+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
251| DIOIntMin. | DIORedun. | MaxRankIncrease |
252+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
253| MinHopRankIncrease | OCP |
254+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
255| Reserved | Def. Lifetime | Lifetime Unit |
256+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
257
258Figure 24: Format of the DODAG Configuration Option
259*/
260
262{
263 UINT8 Type;
264 UINT8 OptLength;
265 UINT Flags : 4;
266 UINT A : 1;
267 UINT PCS : 3;
268 UINT8 DIOIntDoubl;
269 UINT8 DIOIntMin;
270 UINT8 DIORedun;
271 UINT16 MaxRankIncrease;
272 UINT16 MinHopRankIncrease;
273 UINT16 OCP;
274 UINT8 Reserved;
275 UINT8 DefLifetime;
276 UINT16 LifetimeUnit;
277}RPL_DODAG_CONFIG_OPTION,*PRPL_DODAG_CONFIG_OPTION;
278#define RPL_DODAG_CONFIG_OPTION_SIZE 16 //Bytes
279
280/*
2816.7.7. RPL Target
282
283The RPL Target option MAY be present in DAO messages, and its format
284is as follows:
285
2860 1 2 3
2870 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
288+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
289| Type = 0x05 | Option Length | Flags | Prefix Length |
290+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
291| |
292+ +
293| Target Prefix (Variable Length) |
294. .
295. .
296+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
297
298Figure 25: Format of the RPL Target Option
299*/
300typedef struct stru_rpl_target
301{
302 UINT8 Type;
303 UINT8 Option_Length;
304 UINT8 Flags;
305 UINT8 Prefix_Length;
306 NETSIM_IPAddress Traget_Prefix;
307}RPL_TARGET_OPTION,*PRPL_TARGET_OPTION;