Contiki-NG
snmp.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2019 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  * An implementation of the Simple Network Management Protocol (RFC 3411-3418)
36  * \author
37  * Yago Fontoura do Rosario <yago.rosario@hotmail.com.br
38  */
39 
40 /**
41  * \addtogroup apps
42  * @{
43  *
44  * \defgroup snmp SNMP (Simple Network Management Protocol)
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 #include "contiki.h"
54 #include "contiki-net.h"
55 
56 #include "sys/log.h"
57 
58 #include "snmp-conf.h"
59 
60 #include <stdlib.h>
61 #include <stdint.h>
62 
63 /**
64  * \defgroup SNMPDefine SNMP Defines
65  * @{
66  */
67 
68 /**
69  * @brief SNMP Version 1 code
70  */
71 #define SNMP_VERSION_1 0
72 /**
73  * @brief SNMP Version 2c code
74  */
75 #define SNMP_VERSION_2C 1
76 
77 /**
78  * @brief SNMP No Such Name error code
79  */
80 #define SNMP_STATUS_NO_SUCH_NAME 2
81 
82 /** @} */
83 
84 /**
85  * \defgroup SNMPStructs SNMP Structs
86  * @{
87  */
88 
89 /**
90  * @brief The SNMP header struct
91  */
92 typedef struct snmp_header_s {
93  /**
94  * @brief SNMP Version
95  */
96  uint32_t version;
97  /**
98  * @brief Struct to wrap the community
99  */
101  /**
102  * @brief A pointer to the community
103  *
104  * @remarks This pointer refers to the beginning of the string in the packet
105  */
106  const char *community;
107  /**
108  * @brief The string length
109  *
110  * @remarks Do not use strlen on the community pointer since it is not null terminated
111  */
112  uint32_t length;
113  } community;
114  /**
115  * @brief The PDU type
116  */
117  uint8_t pdu_type;
118  /**
119  * @brief The request ID
120  */
121  uint32_t request_id;
122  /**
123  * @brief Union to hold the error status or the non repeaters
124  *
125  * @remarks A union was used since these values cannot co-exist
126  */
128  /**
129  * @brief The error status
130  */
131  uint32_t error_status;
132  /**
133  * @brief The non repeaters
134  */
135  uint32_t non_repeaters;
136  } error_status_non_repeaters;
137  /**
138  * @brief Union to hold the error index or the max repetitions
139  *
140  * @remarks A union was used since these values cannot co-exist
141  */
143  /**
144  * @brief The error index
145  */
146  uint32_t error_index;
147  /**
148  * @brief The max repetitions
149  */
150  uint32_t max_repetitions;
151  } error_index_max_repetitions;
152 } snmp_header_t;
153 
154 /**
155  * @brief The varbind struct
156  */
157 typedef struct snmp_varbind_s {
158  /**
159  * @brief The OID
160  *
161  * @remarks The length is configurable
162  */
163  uint32_t oid[SNMP_MSG_OID_MAX_LEN];
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  */
174  /**
175  * @brief The integer value
176  */
177  uint32_t integer;
178  /**
179  * @brief A struct that contains the string
180  */
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;
194  } string;
195  /**
196  * @brief A pointer to the beggining of a oid array
197  */
198  uint32_t *oid;
199  } value;
201 
202 /** @}*/
203 
204 /**
205  * \defgroup SNMPFunctions SNMP Functions
206  * @{
207  */
208 
209 /**
210  * @brief Initializes the SNMP engine
211  */
212 void
213 snmp_init();
214 
215 /** @}*/
216 
217 #endif /* SNMP_H_ */
218 /** @} */
219 /** @} */
Union to hold the error index or the max repetitions.
Definition: snmp.h:142
uint32_t version
SNMP Version.
Definition: snmp.h:96
const char * community
A pointer to the community.
Definition: snmp.h:106
The varbind struct.
Definition: snmp.h:157
uint32_t error_index
The error index.
Definition: snmp.h:146
uint32_t error_status
The error status.
Definition: snmp.h:131
uint32_t non_repeaters
The non repeaters.
Definition: snmp.h:135
The SNMP header struct.
Definition: snmp.h:92
Struct to wrap the community.
Definition: snmp.h:100
uint8_t pdu_type
The PDU type.
Definition: snmp.h:117
#define SNMP_MSG_OID_MAX_LEN
Default maximum number of IDs in one OID.
Definition: snmp-conf.h:74
const char * string
A pointer to the string value from this varbind.
Definition: snmp.h:187
uint32_t max_repetitions
The max repetitions.
Definition: snmp.h:150
uint8_t value_type
The type in this varbind.
Definition: snmp.h:167
uint32_t * oid
A pointer to the beggining of a oid array.
Definition: snmp.h:198
struct snmp_header_s snmp_header_t
The SNMP header struct.
uint32_t length
The string length.
Definition: snmp.h:112
uint32_t request_id
The request ID.
Definition: snmp.h:121
A union to represent the value in this varbind.
Definition: snmp.h:173
Union to hold the error status or the non repeaters.
Definition: snmp.h:127
uint32_t integer
The integer value.
Definition: snmp.h:177
SNMP Configurable Macros
void snmp_init()
Initializes the SNMP engine.
Definition: snmp.c:86
Header file for the logging system
A struct that contains the string.
Definition: snmp.h:181
struct snmp_varbind_s snmp_varbind_t
The varbind struct.