Contiki-NG
snmp.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 process
36 * \author
37 * Yago Fontoura do Rosario <yago.rosario@hotmail.com.br
38 */
39
40/**
41 * \addtogroup apps
42 * @{
43 *
44 * \addtogroup snmp An implementation of SNMP
45 * @{
46 *
47 * This is an implementation of the Simple Network Management Protocol
48 */
49
50#ifndef SNMP_H_
51#define SNMP_H_
52
53/**
54 * \addtogroup SNMPInternal SNMP Internal API
55 * @{
56 *
57 * This group contains all the functions that can be used inside the OS level.
58 */
59
60#include "contiki.h"
61
62#include "sys/log.h"
63
64#include "snmp-conf.h"
65
66#include <stdlib.h>
67#include <stdint.h>
68
69/**
70 * \addtogroup SNMPCore SNMP Core
71 * @{
72 *
73 * This group contains the SNMP MIB implementation
74 */
75
76/**
77 * @brief SNMP Version 1 code
78 */
79#define SNMP_VERSION_1 0
80/**
81 * @brief SNMP Version 2c code
82 */
83#define SNMP_VERSION_2C 1
84
85/**
86 * @brief SNMP No Such Name error code
87 */
88#define SNMP_STATUS_NO_SUCH_NAME 2
89
90/**
91 * @brief The SNMP header struct
92 */
93typedef struct snmp_header_s {
94 /**
95 * @brief SNMP Version
96 */
97 uint32_t version;
98 /**
99 * @brief Struct to wrap the community
100 */
102 /**
103 * @brief A pointer to the community
104 *
105 * @remarks This pointer refers to the beginning of the string in the packet
106 */
107 const char *community;
108 /**
109 * @brief The string length
110 *
111 * @remarks Do not use strlen on the community pointer since it is not null terminated
112 */
113 uint32_t length;
114 } community;
115 /**
116 * @brief The PDU type
117 */
118 uint8_t pdu_type;
119 /**
120 * @brief The request ID
121 */
122 uint32_t request_id;
123 /**
124 * @brief The error status
125 */
126 uint32_t error_status;
127 /**
128 * @brief The non repeaters
129 */
131 /**
132 * @brief The error index
133 */
134 uint32_t error_index;
135 /**
136 * @brief The max repetitions
137 */
140
141/**
142 * @brief The OID struct
143 */
144typedef struct snmp_oid_s {
145 /**
146 * @brief The OID
147 */
149 /**
150 * @brief The OID length
151 *
152 */
153 uint8_t length;
155
156/**
157 * @brief The varbind struct
158 */
159typedef struct snmp_varbind_s {
160 /**
161 * @brief The OID
162 */
164 /**
165 * @brief The type in this varbind
166 */
167 uint8_t value_type;
168 /**
169 * @brief A union to represent the value in this varbind
170 *
171 * @remarks A union is used since the varbind can only have one value of one type
172 */
173 union {
174 /**
175 * @brief The integer value
176 */
177 uint32_t integer;
178 /**
179 * @brief A struct that contains the string
180 */
181 struct {
182 /**
183 * @brief A pointer to the string value from this varbind
184 *
185 * @remarks This pointer points to a string that cannot be changed
186 */
187 const char *string;
188 /**
189 * @brief The string length
190 *
191 * @remarks Do not use strlen on the string since it might not be null terminated
192 */
193 uint32_t length;
195 /**
196 * @brief The OID value
197 */
201
202/**
203 * @brief The packet struct
204 *
205 */
206typedef struct {
207 /**
208 * @brief The number of bytes used
209 *
210 */
211 uint16_t used;
212 /**
213 * @brief The maximum number of bytes
214 *
215 */
216 uint16_t max;
217 /**
218 * @brief The pointer used for the incoming packet
219 *
220 */
221 uint8_t *in;
222 /**
223 * @brief The pointer used for the outgoing packet
224 *
225 */
226 uint8_t *out;
228
229/**
230 * @brief Initializes the SNMP engine
231 */
232void
233snmp_init();
234
235/** @}*/
236
237/** @}*/
238
239#endif /* SNMP_H_ */
240
241/** @} */
242
243/** @} */
#define SNMP_MSG_OID_MAX_LEN
Default maximum number of IDs in one OID.
Definition: snmp-conf.h:86
struct snmp_oid_s snmp_oid_t
The OID struct.
struct snmp_header_s snmp_header_t
The SNMP header struct.
struct snmp_varbind_s snmp_varbind_t
The varbind struct.
void snmp_init()
Initializes the SNMP engine.
Definition: snmp.c:57
Header file for the logging system.
SNMP Implementation of the configurable macros.
Struct to wrap the community.
Definition: snmp.h:101
const char * community
A pointer to the community.
Definition: snmp.h:107
uint32_t length
The string length.
Definition: snmp.h:113
The SNMP header struct.
Definition: snmp.h:93
uint32_t request_id
The request ID.
Definition: snmp.h:122
uint8_t pdu_type
The PDU type.
Definition: snmp.h:118
uint32_t error_index
The error index.
Definition: snmp.h:134
uint32_t max_repetitions
The max repetitions.
Definition: snmp.h:138
uint32_t error_status
The error status.
Definition: snmp.h:126
uint32_t version
SNMP Version.
Definition: snmp.h:97
uint32_t non_repeaters
The non repeaters.
Definition: snmp.h:130
The OID struct.
Definition: snmp.h:144
uint8_t length
The OID length.
Definition: snmp.h:153
uint32_t data[SNMP_MSG_OID_MAX_LEN]
The OID.
Definition: snmp.h:148
The packet struct.
Definition: snmp.h:206
uint8_t * in
The pointer used for the incoming packet.
Definition: snmp.h:221
uint8_t * out
The pointer used for the outgoing packet.
Definition: snmp.h:226
uint16_t max
The maximum number of bytes.
Definition: snmp.h:216
uint16_t used
The number of bytes used.
Definition: snmp.h:211
The varbind struct.
Definition: snmp.h:159
uint32_t length
The string length.
Definition: snmp.h:193
uint8_t value_type
The type in this varbind.
Definition: snmp.h:167
union snmp_varbind_s::@41 value
A union to represent the value in this varbind.
snmp_oid_t oid
The OID.
Definition: snmp.h:163
const char * string
A pointer to the string value from this varbind.
Definition: snmp.h:187
uint32_t integer
The integer value.
Definition: snmp.h:177