1 #ifndef _RPL_H_
2 
3 /*
4  * NOTE: the contents of this file are an interpretation of RFC6550.
5  *       no copyright is asserted on this file, as it transcribes
6  *       a public specification.
7  *
8  */
9 
10 /*
11  * DIO: Updated to RFC6550, as published in 2012: section 6. (page 30)
12  */
13 
14 #define ND_RPL_MESSAGE 155  /* 0x9B */
15 
16 enum ND_RPL_CODE {
17     ND_RPL_DAG_IS=0x00,
18     ND_RPL_DAG_IO=0x01,
19     ND_RPL_DAO   =0x02,
20     ND_RPL_DAO_ACK=0x03,
21     ND_RPL_SEC_DAG_IS = 0x80,
22     ND_RPL_SEC_DAG_IO = 0x81,
23     ND_RPL_SEC_DAG    = 0x82,
24     ND_RPL_SEC_DAG_ACK= 0x83,
25     ND_RPL_SEC_CONSIST= 0x84,
26 };
27 
28 enum ND_RPL_DIO_FLAGS {
29         ND_RPL_DIO_GROUNDED = 0x80,
30         ND_RPL_DIO_DATRIG   = 0x40,
31         ND_RPL_DIO_DASUPPORT= 0x20,
32         ND_RPL_DIO_RES4     = 0x10,
33         ND_RPL_DIO_RES3     = 0x08,
34         ND_RPL_DIO_PRF_MASK = 0x07,  /* 3-bit preference */
35 };
36 
37 #define DAGID_LEN 16
38 
39 /* section 6 of draft-ietf-roll-rpl-19 */
40 struct nd_rpl_security {
41     uint8_t  rpl_sec_t_reserved;     /* bit 7 is T-bit */
42     uint8_t  rpl_sec_algo;
43     uint16_t rpl_sec_kim_lvl_flags;  /* bit 15/14, KIM */
44                                       /* bit 10-8, LVL, bit 7-0 flags */
45     uint32_t rpl_sec_counter;
46 #if 0
47     uint8_t  rpl_sec_ki[0];          /* depends upon kim */
48 #endif
49 };
50 
51 /* section 6.2.1, DODAG Information Solication (DIS_IS) */
52 struct nd_rpl_dis_is {
53     uint8_t rpl_dis_flags;
54     uint8_t rpl_dis_reserved;
55 #if 0
56     uint8_t rpl_dis_options[0];
57 #endif
58 };
59 
60 /* section 6.3.1, DODAG Information Object (DIO) */
61 struct nd_rpl_dio {
62     uint8_t  rpl_instanceid;
63     uint8_t  rpl_version;
64     uint16_t rpl_dagrank;
65     uint8_t  rpl_mopprf;   /* bit 7=G, 5-3=MOP, 2-0=PRF */
66     uint8_t  rpl_dtsn;     /* Dest. Advertisement Trigger Sequence Number */
67     uint8_t  rpl_flags;    /* no flags defined yet */
68     uint8_t  rpl_resv1;
69     uint8_t  rpl_dagid[DAGID_LEN];
70 };
71 #define RPL_DIO_GROUND_FLAG 0x80
72 #define RPL_DIO_MOP_SHIFT   3
73 #define RPL_DIO_MOP_MASK    (7 << RPL_DIO_MOP_SHIFT)
74 #define RPL_DIO_PRF_SHIFT   0
75 #define RPL_DIO_PRF_MASK    (7 << RPL_DIO_PRF_SHIFT)
76 #define RPL_DIO_GROUNDED(X) ((X)&RPL_DIO_GROUND_FLAG)
77 #define RPL_DIO_MOP(X)      (enum RPL_DIO_MOP)(((X)&RPL_DIO_MOP_MASK) >> RPL_DIO_MOP_SHIFT)
78 #define RPL_DIO_PRF(X)      (((X)&RPL_DIO_PRF_MASK) >> RPL_DIO_PRF_SHIFT)
79 
80 enum RPL_DIO_MOP {
81     RPL_DIO_NONSTORING= 0x0,
82     RPL_DIO_STORING   = 0x1,
83     RPL_DIO_NONSTORING_MULTICAST = 0x2,
84     RPL_DIO_STORING_MULTICAST    = 0x3,
85 };
86 
87 enum RPL_SUBOPT {
88         RPL_OPT_PAD0        = 0,
89         RPL_OPT_PADN        = 1,
90         RPL_DIO_METRICS     = 2,
91         RPL_DIO_ROUTINGINFO = 3,
92         RPL_DIO_CONFIG      = 4,
93         RPL_DAO_RPLTARGET   = 5,
94         RPL_DAO_TRANSITINFO = 6,
95         RPL_DIO_DESTPREFIX  = 8,
96         RPL_DAO_RPLTARGET_DESC=9,
97 };
98 
99 struct rpl_dio_genoption {
100     uint8_t rpl_dio_type;
101     uint8_t rpl_dio_len;        /* suboption length, not including type/len */
102 };
103 #define RPL_DIO_GENOPTION_LEN	2
104 
105 #define RPL_DIO_LIFETIME_INFINITE   0xffffffff
106 #define RPL_DIO_LIFETIME_DISCONNECT 0
107 
108 struct rpl_dio_destprefix {
109     uint8_t rpl_dio_type;
110     uint8_t rpl_dio_len;
111     uint8_t rpl_dio_prefixlen;        /* in bits */
112     uint8_t rpl_dio_prf;              /* flags, including Route Preference */
113     uint32_t rpl_dio_prefixlifetime;  /* in seconds */
114 #if 0
115     uint8_t rpl_dio_prefix[0];        /* variable number of bytes */
116 #endif
117 };
118 
119 /* section 6.4.1, DODAG Information Object (DIO) */
120 struct nd_rpl_dao {
121     uint8_t  rpl_instanceid;
122     uint8_t  rpl_flags;      /* bit 7=K, 6=D */
123     uint8_t  rpl_resv;
124     uint8_t  rpl_daoseq;
125     uint8_t  rpl_dagid[DAGID_LEN];   /* present when D set. */
126 };
127 #define ND_RPL_DAO_MIN_LEN	4	/* length without DAGID */
128 
129 /* indicates if this DAO is to be acK'ed */
130 #define RPL_DAO_K_SHIFT   7
131 #define RPL_DAO_K_MASK    (1 << RPL_DAO_K_SHIFT)
132 #define RPL_DAO_K(X)      (((X)&RPL_DAO_K_MASK) >> RPL_DAO_K_SHIFT)
133 
134 /* indicates if the DAGID is present */
135 #define RPL_DAO_D_SHIFT   6
136 #define RPL_DAO_D_MASK    (1 << RPL_DAO_D_SHIFT)
137 #define RPL_DAO_D(X)      (((X)&RPL_DAO_D_MASK) >> RPL_DAO_D_SHIFT)
138 
139 struct rpl_dao_target {
140     uint8_t rpl_dao_type;
141     uint8_t rpl_dao_len;
142     uint8_t rpl_dao_flags;            /* unused */
143     uint8_t rpl_dao_prefixlen;        /* in bits */
144 #if 0
145     uint8_t rpl_dao_prefix[0];        /* variable number of bytes */
146 #endif
147 };
148 
149 /* section 6.5.1, Destination Advertisement Object Acknowledgement (DAO-ACK) */
150 struct nd_rpl_daoack {
151     uint8_t  rpl_instanceid;
152     uint8_t  rpl_flags;      /* bit 7=D */
153     uint8_t  rpl_daoseq;
154     uint8_t  rpl_status;
155     uint8_t  rpl_dagid[DAGID_LEN];   /* present when D set. */
156 };
157 #define ND_RPL_DAOACK_MIN_LEN	4	/* length without DAGID */
158 /* indicates if the DAGID is present */
159 #define RPL_DAOACK_D_SHIFT   7
160 #define RPL_DAOACK_D_MASK    (1 << RPL_DAOACK_D_SHIFT)
161 #define RPL_DAOACK_D(X)      (((X)&RPL_DAOACK_D_MASK) >> RPL_DAOACK_D_SHIFT)
162 
163 
164 
165 #define _RPL_H_
166 #endif /* _RPL_H_ */
167 
168 /*
169  * Local Variables:
170  * c-basic-offset:4
171  * c-style: whitesmith
172  * End:
173  */
174 
175