Contiki-NG
snmp-ber.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2019-2020 Yago Fontoura do Rosario <yago.rosario@hotmail.com.br>
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  *
14  * 3. Neither the name of the copyright holder nor the names of its
15  * contributors may be used to endorse or promote products derived
16  * from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
29  * OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31 /*---------------------------------------------------------------------------*/
32 
33 /**
34  * \file
35  * SNMP Implementation of the BER encoding
36  * \author
37  * Yago Fontoura do Rosario <yago.rosario@hotmail.com.br
38  */
39 
40 /**
41  * \addtogroup snmp
42  * @{
43  */
44 
45 #ifndef SNMP_BER_H_
46 #define SNMP_BER_H_
47 
48 /**
49  * \addtogroup SNMPInternal SNMP Internal API
50  * @{
51  *
52  * This group contains all the functions that can be used inside the OS level.
53  */
54 
55 /**
56  * \addtogroup SNMPBER SNMP BER
57  * @{
58  *
59  * This group contains the BER implementation
60  */
61 
62 /**
63  * @brief End-of-Content
64  *
65  */
66 #define BER_DATA_TYPE_EOC 0x00
67 
68 /**
69  * @brief Integer
70  *
71  */
72 #define BER_DATA_TYPE_INTEGER 0x02
73 
74 /**
75  * @brief Octet String
76  *
77  */
78 #define BER_DATA_TYPE_OCTET_STRING 0x04
79 
80 /**
81  * @brief Null
82  *
83  */
84 #define BER_DATA_TYPE_NULL 0x05
85 
86 /**
87  * @brief Object Identifier
88  *
89  */
90 #define BER_DATA_TYPE_OBJECT_IDENTIFIER 0x06
91 
92 /**
93  * @brief Sequence
94  *
95  */
96 #define BER_DATA_TYPE_SEQUENCE 0x30
97 
98 /**
99  * @brief TimeTicks
100  *
101  */
102 #define BER_DATA_TYPE_TIMETICKS 0x43
103 
104 /**
105  * @brief No Such Instance
106  *
107  */
108 #define BER_DATA_TYPE_NO_SUCH_INSTANCE 0x81
109 
110 /**
111  * @brief End of MIB View
112  *
113  */
114 #define BER_DATA_TYPE_END_OF_MIB_VIEW 0x82
115 
116 /**
117  * @brief PDU Get Request
118  *
119  */
120 #define BER_DATA_TYPE_PDU_GET_REQUEST 0xA0
121 
122 /**
123  * @brief PDU Get Next Request
124  *
125  */
126 #define BER_DATA_TYPE_PDU_GET_NEXT_REQUEST 0xA1
127 
128 /**
129  * @brief PDU Get Reponse
130  *
131  */
132 #define BER_DATA_TYPE_PDU_GET_RESPONSE 0xA2
133 
134 /**
135  * @brief PDU Set Request
136  *
137  */
138 #define BER_DATA_TYPE_PDU_SET_REQUEST 0xA3
139 
140 /**
141  * @brief PDU Trap
142  *
143  */
144 #define BER_DATA_TYPE_PDU_TRAP 0xA4
145 
146 /**
147  * @brief PDU Get Bulk
148  *
149  */
150 #define BER_DATA_TYPE_PDU_GET_BULK 0xA5
151 
152 /**
153  * @brief Encodes a type
154  *
155  * @param snmp_packet A pointer to the snmp packet
156  * @param type A type
157  *
158  * @return 0 if error or 1 if success
159  */
160 int
161 snmp_ber_encode_type(snmp_packet_t *snmp_packet, uint8_t type);
162 
163 /**
164  * @brief Encodes the length
165  *
166  * @param snmp_packet A pointer to the snmp packet
167  * @param length A length
168  *
169  * @return 0 if error or 1 if success
170  */
171 int
172 snmp_ber_encode_length(snmp_packet_t *snmp_packet, uint16_t length);
173 
174 /**
175  * @brief Encodes an integer
176  *
177  * @param snmp_packet A pointer to the snmp packet
178  * @param integer A integer
179  *
180  * @return 0 if error or 1 if success
181  */
182 int
183 snmp_ber_encode_integer(snmp_packet_t *snmp_packet, uint32_t integer);
184 
185 /**
186  * @brief Encodes a timeticks
187  *
188  * @param snmp_packet A pointer to the snmp packet
189  * @param timeticks A TimeTicks
190  *
191  * @return 0 if error or 1 if success
192  */
193 int
194 snmp_ber_encode_timeticks(snmp_packet_t *snmp_packet, uint32_t timeticks);
195 
196 /**
197  * @brief Encodes a string
198  *
199  * @param snmp_packet A pointer to the snmp packet
200  * @param str A string
201  * @param length The string length
202  *
203  * @return 0 if error or 1 if success
204  */
205 int
206 snmp_ber_encode_string_len(snmp_packet_t *snmp_packet, const char *str, uint32_t length);
207 
208 /**
209  * @brief Encodes a Oid
210  *
211  * @param snmp_packet A pointer to the snmp packet
212  * @param oid A OID
213  *
214  * @return 0 if error or 1 if success
215  */
216 int
218 
219 /**
220  * @brief Encodes a null
221  *
222  * @param snmp_packet A pointer to the snmp packet
223  * @param type A type
224  *
225  * @return 0 if error or 1 if success
226  */
227 int
228 snmp_ber_encode_null(snmp_packet_t *snmp_packet, uint8_t type);
229 
230 /**
231  * @brief Decodes a type
232  *
233  * @param snmp_packet A pointer to the snmp packet
234  * @param type A pointer to the type
235  *
236  * @return 0 if error or 1 if success
237  */
238 int
239 snmp_ber_decode_type(snmp_packet_t *snmp_packet, uint8_t *type);
240 
241 /**
242  * @brief Decodes a length
243  *
244  * @param snmp_packet A pointer to the snmp packet
245  * @param length A pointer to the length
246  *
247  * @return 0 if error or 1 if success
248  */
249 int
250 snmp_ber_decode_length(snmp_packet_t *snmp_packet, uint8_t *length);
251 
252 /**
253  * @brief Decodes an integer
254  *
255  * @param snmp_packet A pointer to the snmp packet
256  * @param integer A pointer to the integer
257  *
258  * @return 0 if error or 1 if success
259  */
260 int
261 snmp_ber_decode_integer(snmp_packet_t *snmp_packet, uint32_t *integer);
262 
263 /**
264  * @brief Decodes a timeticks
265  *
266  * @param snmp_packet A pointer to the snmp packet
267  * @param timeticks A pointer to the timeticks
268  *
269  * @return 0 if error or 1 if success
270  */
271 int
272 snmp_ber_decode_timeticks(snmp_packet_t *snmp_packet, uint32_t *timeticks);
273 
274 /**
275  * @brief Decodes a string
276  *
277  * @param snmp_packet A pointer to the snmp packet
278  * @param str A pointer to the string
279  * @param length A pointer to the string length
280  *
281  * @return 0 if error or 1 if success
282  */
283 int
284 snmp_ber_decode_string_len_buffer(snmp_packet_t *snmp_packet, const char **str, uint32_t *length);
285 
286 /**
287  * @brief Decodes a null
288  *
289  * @param snmp_packet A pointer to the snmp packet
290  *
291  * @return 0 if error or 1 if success
292  */
293 int
294 snmp_ber_decode_null(snmp_packet_t *snmp_packet);
295 
296 /**
297  * @brief Decodes an OID
298  *
299  * @param snmp_packet pointer to the snmp packet
300  * @param oid A pointer to the OID
301  *
302  * @return 0 if error or 1 if success
303  */
304 int
306 
307 /** @} */
308 
309 /** @} */
310 
311 #endif /* SNMP_BER_H_ */
312 
313 /** @} */
int snmp_ber_decode_null(snmp_packet_t *snmp_packet)
Decodes a null.
Definition: snmp-ber.c:492
The packet struct.
Definition: snmp.h:206
int snmp_ber_decode_integer(snmp_packet_t *snmp_packet, uint32_t *integer)
Decodes an integer.
Definition: snmp-ber.c:351
int snmp_ber_decode_type(snmp_packet_t *snmp_packet, uint8_t *type)
Decodes a type.
Definition: snmp-ber.c:319
int snmp_ber_encode_integer(snmp_packet_t *snmp_packet, uint32_t integer)
Encodes an integer.
Definition: snmp-ber.c:152
int snmp_ber_encode_timeticks(snmp_packet_t *snmp_packet, uint32_t timeticks)
Encodes a timeticks.
Definition: snmp-ber.c:146
int snmp_ber_encode_type(snmp_packet_t *snmp_packet, uint8_t type)
Encodes a type.
Definition: snmp-ber.c:83
int snmp_ber_decode_length(snmp_packet_t *snmp_packet, uint8_t *length)
Decodes a length.
Definition: snmp-ber.c:332
int snmp_ber_decode_string_len_buffer(snmp_packet_t *snmp_packet, const char **str, uint32_t *length)
Decodes a string.
Definition: snmp-ber.c:357
int snmp_ber_decode_oid(snmp_packet_t *snmp_packet, snmp_oid_t *oid)
Decodes an OID.
Definition: snmp-ber.c:430
int snmp_ber_encode_string_len(snmp_packet_t *snmp_packet, const char *str, uint32_t length)
Encodes a string.
Definition: snmp-ber.c:158
int snmp_ber_encode_oid(snmp_packet_t *snmp_packet, snmp_oid_t *oid)
Encodes a Oid.
Definition: snmp-ber.c:184
The OID struct.
Definition: snmp.h:144
int snmp_ber_encode_length(snmp_packet_t *snmp_packet, uint16_t length)
Encodes the length.
Definition: snmp-ber.c:96
snmp_oid_t oid
A OID struct.
Definition: snmp-mib.h:85
int snmp_ber_encode_null(snmp_packet_t *snmp_packet, uint8_t type)
Encodes a null.
Definition: snmp-ber.c:257
int snmp_ber_decode_timeticks(snmp_packet_t *snmp_packet, uint32_t *timeticks)
Decodes a timeticks.
Definition: snmp-ber.c:345