Contiki-NG
snmp-api.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  * The public API for the Contiki-NG SNMP implementation
36  * \author
37  * Yago Fontoura do Rosario <yago.rosario@hotmail.com.br
38  */
39 
40 /**
41  * \addtogroup snmp
42  * @{
43  */
44 
45 #ifndef SNMP_API_H_
46 #define SNMP_API_H_
47 
48 #include "snmp.h"
49 #include "snmp-mib.h"
50 
51 /**
52  * \defgroup SNMPAPI This is the SNMP Public API
53  * @{
54  *
55  * This group contains all the functions that can be used outside the OS level.
56  * The function outside this header can be changed without notice
57  */
58 
59 /**
60  * @brief The MIB resource handler typedef
61  *
62  * @param varbind The varbind that is being changed
63  * @param oid The oid from the resource
64  */
65 typedef void (*snmp_mib_resource_handler_t)(snmp_varbind_t *varbind, uint32_t *oid);
66 
67 /**
68  * @brief The MIB Resource struct
69  */
71 
72 /**
73  * @brief Initializes statically an oid with the "null" terminator
74  *
75  * @remarks This should be used inside handlers when declaring an oid
76  *
77  * @param name A name for the oid
78  * @param ... The Oid (comma-separeted)
79  */
80 #define OID(name, ...) \
81  static uint32_t name[] = { __VA_ARGS__, -1 };
82 
83 /**
84  * @brief Declare a MIB resource
85  *
86  * @param name A name for the MIB resource
87  * @param handler The handler function for this resource
88  * @param ... The OID (comma-separated)
89  */
90 #define MIB_RESOURCE(name, handler, ...) \
91  uint32_t name##_oid[] = { __VA_ARGS__, -1 }; \
92  snmp_mib_resource_t name = { NULL, name##_oid, handler };
93 
94 /**
95  * @brief Function to set a varbind with a string
96  *
97  * This function should be used inside a handler to set the varbind correctly
98  *
99  * @param varbind The varbind from the handler
100  * @param oid The oid from the handler
101  * @param string The string
102  */
103 void
104 snmp_api_set_string(snmp_varbind_t *varbind, uint32_t *oid, char *string);
105 
106 /**
107  * @brief Function to set a varbind with a time tick
108  *
109  * This function should be used inside a handler to set the varbind correctly
110  *
111  * @param varbind The varbind from the handler
112  * @param oid The oid from the handler
113  * @param integer The time tick value
114  */
115 void
116 snmp_api_set_time_ticks(snmp_varbind_t *varbind, uint32_t *oid, uint32_t integer);
117 
118 /**
119  * @brief Function to set a varbind with a oid
120  *
121  * This function should be used inside a handler to set the varbind correctly
122  *
123  * @param varbind The varbind from the handler
124  * @param oid The oid from the handler
125  * @param ret_oid The oid value
126  */
127 void
128 snmp_api_set_oid(snmp_varbind_t *varbind, uint32_t *oid, uint32_t *ret_oid);
129 
130 /**
131  * @brief Function to add a new resource
132  *
133  * @param new_resource The resource
134  */
135 void
137 
138 /** @}*/
139 
140 #endif /* SNMP_API_H_ */
141 /** @} */
An implementation of the Simple Network Management Protocol (RFC 3411-3418)
The varbind struct.
Definition: snmp.h:157
void(* snmp_mib_resource_handler_t)(snmp_varbind_t *varbind, uint32_t *oid)
The MIB resource handler typedef.
Definition: snmp-api.h:65
The MIB Resource struct.
Definition: snmp-mib.h:61
void snmp_api_set_string(snmp_varbind_t *varbind, uint32_t *oid, char *string)
Function to set a varbind with a string.
Definition: snmp-api.c:62
void snmp_api_add_resource(snmp_mib_resource_t *new_resource)
Function to add a new resource.
Definition: snmp-api.c:90
void snmp_api_set_time_ticks(snmp_varbind_t *varbind, uint32_t *oid, uint32_t integer)
Function to set a varbind with a time tick.
Definition: snmp-api.c:72
uint32_t * oid
A array that represents the OID.
Definition: snmp-mib.h:73
An implementation of the Simple Network Management Protocol (RFC 3411-3418)
void snmp_api_set_oid(snmp_varbind_t *varbind, uint32_t *oid, uint32_t *ret_oid)
Function to set a varbind with a oid.
Definition: snmp-api.c:81