Contiki-NG
snmp-api.c
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 #include "contiki.h"
41 
42 #include "snmp-api.h"
43 
44 #include "snmp-message.h"
45 #include "snmp-ber.h"
46 
47 /*---------------------------------------------------------------------------*/
48 void
49 snmp_api_set_string(snmp_varbind_t *varbind, snmp_oid_t *oid, char *string)
50 {
51  memcpy(&varbind->oid, oid, sizeof(snmp_oid_t));
53  varbind->value.string.string = string;
54  varbind->value.string.length = strlen(string);
55 }
56 /*---------------------------------------------------------------------------*/
57 void
58 snmp_api_set_time_ticks(snmp_varbind_t *varbind, snmp_oid_t *oid, uint32_t integer)
59 {
60  memcpy(&varbind->oid, oid, sizeof(snmp_oid_t));
62  varbind->value.integer = integer;
63 }
64 /*---------------------------------------------------------------------------*/
65 void
67 {
68  memcpy(&varbind->oid, oid, sizeof(snmp_oid_t));
70  memcpy(&varbind->value.oid, ret_oid, sizeof(snmp_oid_t));
71 }
72 /*---------------------------------------------------------------------------*/
73 void
75 {
76  return snmp_mib_add(new_resource);
77 }
#define BER_DATA_TYPE_TIMETICKS
TimeTicks.
Definition: snmp-ber.h:102
void snmp_mib_add(snmp_mib_resource_t *new_resource)
Adds a resource into the linked list.
Definition: snmp-mib.c:123
snmp_oid_t oid
The OID.
Definition: snmp.h:163
The varbind struct.
Definition: snmp.h:159
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
uint32_t integer
The integer value.
Definition: snmp.h:177
The MIB Resource struct.
Definition: snmp-mib.h:75
#define BER_DATA_TYPE_OCTET_STRING
Octet String.
Definition: snmp-ber.h:78
union snmp_varbind_s::@67 value
A union to represent the value in this varbind.
const char * string
A pointer to the string value from this varbind.
Definition: snmp.h:187
SNMP Implementation of the BER encoding
The OID struct.
Definition: snmp.h:144
SNMP Implementation of the messages
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_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
uint8_t value_type
The type in this varbind.
Definition: snmp.h:167
void snmp_api_add_resource(snmp_mib_resource_t *new_resource)
Function to add a new resource.
Definition: snmp-api.c:74
#define BER_DATA_TYPE_OBJECT_IDENTIFIER
Object Identifier.
Definition: snmp-ber.h:90
SNMP Implementation of the public API