Contiki-NG
snmp-api.c
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 #include "contiki.h"
41 
42 #include "snmp-api.h"
43 
44 #include "snmp-message.h"
45 #include "snmp-ber.h"
46 #include "snmp-oid.h"
47 
48 static void
49 snmp_api_replace_oid(snmp_varbind_t *varbind, uint32_t *oid)
50 {
51  uint8_t i;
52 
53  i = 0;
54  while(oid[i] != ((uint32_t)-1)) {
55  varbind->oid[i] = oid[i];
56  i++;
57  }
58  varbind->oid[i] = ((uint32_t)-1);
59 }
60 /*---------------------------------------------------------------------------*/
61 void
62 snmp_api_set_string(snmp_varbind_t *varbind, uint32_t *oid, char *string)
63 {
64 
65  snmp_api_replace_oid(varbind, oid);
66  varbind->value_type = BER_DATA_TYPE_OCTET_STRING;
67  varbind->value.string.string = string;
68  varbind->value.string.length = strlen(string);
69 }
70 /*---------------------------------------------------------------------------*/
71 void
72 snmp_api_set_time_ticks(snmp_varbind_t *varbind, uint32_t *oid, uint32_t integer)
73 {
74 
75  snmp_api_replace_oid(varbind, oid);
76  varbind->value_type = SNMP_DATA_TYPE_TIME_TICKS;
77  varbind->value.integer = integer;
78 }
79 /*---------------------------------------------------------------------------*/
80 void
81 snmp_api_set_oid(snmp_varbind_t *varbind, uint32_t *oid, uint32_t *ret_oid)
82 {
83 
84  snmp_api_replace_oid(varbind, oid);
85  varbind->value_type = BER_DATA_TYPE_OID;
86  varbind->value.oid = ret_oid;
87 }
88 /*---------------------------------------------------------------------------*/
89 void
91 {
92  return snmp_mib_add(new_resource);
93 }
An implementation of the Simple Network Management Protocol (RFC 3411-3418)
The varbind struct.
Definition: snmp.h:157
The MIB Resource struct.
Definition: snmp-mib.h:61
An implementation of the Simple Network Management Protocol (RFC 3411-3418)
uint32_t oid[SNMP_MSG_OID_MAX_LEN]
The OID.
Definition: snmp.h:163
An implementation of the Simple Network Management Protocol (RFC 3411-3418)
const char * string
A pointer to the string value from this varbind.
Definition: snmp.h:187
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
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
The public API for the Contiki-NG SNMP implementation
uint32_t integer
The integer value.
Definition: snmp.h:177
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
void snmp_mib_add(snmp_mib_resource_t *new_resource)
Adds a resource into the linked list.
Definition: snmp-mib.c:84