Contiki-NG
snmp-api.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 public API
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 * \addtogroup SNMPAPI SNMP Public API
53 * @{
54 *
55 * This group contains all the functions that can be used outside the OS level.
56 */
57
58/**
59 * @brief The MIB resource handler typedef
60 *
61 * @param varbind The varbind that is being changed
62 * @param oid The oid from the resource
63 */
65
66/**
67 * @brief The MIB Resource struct
68 */
70
71/**
72 * @brief Initializes statically an oid with the "null" terminator
73 *
74 * @remarks This should be used inside handlers when declaring an oid
75 *
76 * @param name A name for the oid
77 * @param ... The Oid (comma-separeted)
78 */
79#define OID(name, ...) \
80 static snmp_oid_t name = { \
81 .data = { __VA_ARGS__ }, \
82 .length = (sizeof((uint32_t[]){ __VA_ARGS__ }) / sizeof(uint32_t)) \
83 };
84
85/**
86 * @brief Declare a MIB resource
87 *
88 * @param name A name for the MIB resource
89 * @param handler The handler function for this resource
90 * @param ... The OID (comma-separated)
91 */
92#define MIB_RESOURCE(name, handler, ...) \
93 snmp_mib_resource_t name = { \
94 NULL, \
95 { \
96 .data = { __VA_ARGS__ }, \
97 .length = (sizeof((uint32_t[]){ __VA_ARGS__ }) / sizeof(uint32_t)) \
98 }, \
99 handler \
100 };
101
102/**
103 * @brief Function to set a varbind with a string
104 *
105 * This function should be used inside a handler to set the varbind correctly
106 *
107 * @param varbind The varbind from the handler
108 * @param oid The oid from the handler
109 * @param string The string
110 */
111void
112snmp_api_set_string(snmp_varbind_t *varbind, snmp_oid_t *oid, char *string);
113
114/**
115 * @brief Function to set a varbind with a time tick
116 *
117 * This function should be used inside a handler to set the varbind correctly
118 *
119 * @param varbind The varbind from the handler
120 * @param oid The oid from the handler
121 * @param integer The time tick value
122 */
123void
124snmp_api_set_time_ticks(snmp_varbind_t *varbind, snmp_oid_t *oid, uint32_t integer);
125
126/**
127 * @brief Function to set a varbind with a oid
128 *
129 * This function should be used inside a handler to set the varbind correctly
130 *
131 * @param varbind The varbind from the handler
132 * @param oid The oid from the handler
133 * @param ret_oid The oid value
134 */
135void
137
138/**
139 * @brief Function to add a new resource
140 *
141 * @param new_resource The resource
142 */
143void
145
146/** @}*/
147
148#endif /* SNMP_API_H_ */
149/** @} */
void snmp_api_set_string(snmp_varbind_t *varbind, snmp_oid_t *oid, char *string)
Function to set a varbind with a string.
Definition: snmp-api.c:49
void snmp_api_set_time_ticks(snmp_varbind_t *varbind, snmp_oid_t *oid, uint32_t integer)
Function to set a varbind with a time tick.
Definition: snmp-api.c:58
void snmp_api_add_resource(snmp_mib_resource_t *new_resource)
Function to add a new resource.
Definition: snmp-api.c:74
void snmp_api_set_oid(snmp_varbind_t *varbind, snmp_oid_t *oid, snmp_oid_t *ret_oid)
Function to set a varbind with a oid.
Definition: snmp-api.c:66
void(* snmp_mib_resource_handler_t)(snmp_varbind_t *varbind, snmp_oid_t *oid)
The MIB resource handler typedef.
Definition: snmp-api.h:64
SNMP Implementation of the MIB.
SNMP Implementation of the process.
The MIB Resource struct.
Definition: snmp-mib.h:75
snmp_oid_t oid
A OID struct.
Definition: snmp-mib.h:85
The OID struct.
Definition: snmp.h:144
The varbind struct.
Definition: snmp.h:159