snmp_framework_mib_impl.c
Go to the documentation of this file.
1 /**
2  * @file snmp_framework_mib_impl.c
3  * @brief SNMP FRAMEWORK MIB module implementation
4  *
5  * @section License
6  *
7  * Copyright (C) 2010-2018 Oryx Embedded SARL. All rights reserved.
8  *
9  * This file is part of CycloneTCP Open.
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software Foundation,
23  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24  *
25  * @author Oryx Embedded SARL (www.oryx-embedded.com)
26  * @version 1.9.0
27  **/
28 
29 //Switch to the appropriate trace level
30 #define TRACE_LEVEL SNMP_TRACE_LEVEL
31 
32 //Dependencies
33 #include "core/net.h"
34 #include "mibs/mib_common.h"
37 #include "core/crypto.h"
38 #include "encoding/asn1.h"
39 #include "encoding/oid.h"
40 #include "debug.h"
41 
42 //Check TCP/IP stack configuration
43 #if (SNMP_FRAMEWORK_MIB_SUPPORT == ENABLED)
44 
45 
46 /**
47  * @brief SNMP FRAMEWORK MIB module initialization
48  * @return Error code
49  **/
50 
52 {
53  //Debug message
54  TRACE_INFO("Initializing SNMP FRAMEWORK MIB base...\r\n");
55 
56  //Clear SNMP FRAMEWORK MIB base
57  memset(&snmpFrameworkMibBase, 0, sizeof(snmpFrameworkMibBase));
58 
59  //Successful processing
60  return NO_ERROR;
61 }
62 
63 
64 /**
65  * @brief Load SNMP FRAMEWORK MIB module
66  * @param[in] context Pointer to the SNMP agent context
67  * @return Error code
68  **/
69 
71 {
72  //Register SNMP agent context
73  snmpFrameworkMibBase.context = context;
74 
75  //Successful processing
76  return NO_ERROR;
77 }
78 
79 
80 /**
81  * @brief Unload SNMP FRAMEWORK MIB module
82  * @param[in] context Pointer to the SNMP agent context
83  **/
84 
85 void snmpFrameworkMibUnload(void *context)
86 {
87  //Unregister SNMP agent context
89 }
90 
91 
92 /**
93  * @brief Lock SNMP FRAMEWORK MIB base
94  **/
95 
97 {
98 }
99 
100 
101 /**
102  * @brief Unlock SNMP FRAMEWORK MIB base
103  **/
104 
106 {
107 }
108 
109 
110 /**
111  * @brief Get snmpEngineID object value
112  * @param[in] object Pointer to the MIB object descriptor
113  * @param[in] oid Object identifier (object name and instance identifier)
114  * @param[in] oidLen Length of the OID, in bytes
115  * @param[out] value Object value
116  * @param[in,out] valueLen Length of the object value, in bytes
117  * @return Error code
118  **/
119 
121  const uint8_t *oid, size_t oidLen, MibVariant *value, size_t *valueLen)
122 {
123  SnmpAgentContext *context;
124 
125  //Point to the SNMP agent context
127  //Sanity check
128  if(context == NULL)
129  return ERROR_OBJECT_NOT_FOUND;
130 
131  //Make sure the buffer is large enough to hold the entire object
132  if(*valueLen < context->contextEngineLen)
133  return ERROR_BUFFER_OVERFLOW;
134 
135  //Copy object value
136  memcpy(value->octetString, context->contextEngine, context->contextEngineLen);
137  //Return object length
138  *valueLen = context->contextEngineLen;
139 
140  //Return status code
141  return NO_ERROR;
142 }
143 
144 
145 /**
146  * @brief Get snmpEngineBoots object value
147  * @param[in] object Pointer to the MIB object descriptor
148  * @param[in] oid Object identifier (object name and instance identifier)
149  * @param[in] oidLen Length of the OID, in bytes
150  * @param[out] value Object value
151  * @param[in,out] valueLen Length of the object value, in bytes
152  * @return Error code
153  **/
154 
156  const uint8_t *oid, size_t oidLen, MibVariant *value, size_t *valueLen)
157 {
158  SnmpAgentContext *context;
159 
160  //Point to the SNMP agent context
162  //Sanity check
163  if(context == NULL)
164  return ERROR_OBJECT_NOT_FOUND;
165 
166  //Get object value
167  value->integer = context->engineBoots;
168 
169  //Return status code
170  return NO_ERROR;
171 }
172 
173 
174 /**
175  * @brief Get snmpEngineTime object value
176  * @param[in] object Pointer to the MIB object descriptor
177  * @param[in] oid Object identifier (object name and instance identifier)
178  * @param[in] oidLen Length of the OID, in bytes
179  * @param[out] value Object value
180  * @param[in,out] valueLen Length of the object value, in bytes
181  * @return Error code
182  **/
183 
185  const uint8_t *oid, size_t oidLen, MibVariant *value, size_t *valueLen)
186 {
187  SnmpAgentContext *context;
188 
189  //Point to the SNMP agent context
191  //Sanity check
192  if(context == NULL)
193  return ERROR_OBJECT_NOT_FOUND;
194 
195  //Get object value
196  value->integer = context->engineTime;
197 
198  //Return status code
199  return NO_ERROR;
200 }
201 
202 
203 /**
204  * @brief Get snmpEngineMaxMessageSize object value
205  * @param[in] object Pointer to the MIB object descriptor
206  * @param[in] oid Object identifier (object name and instance identifier)
207  * @param[in] oidLen Length of the OID, in bytes
208  * @param[out] value Object value
209  * @param[in,out] valueLen Length of the object value, in bytes
210  * @return Error code
211  **/
212 
214  const uint8_t *oid, size_t oidLen, MibVariant *value, size_t *valueLen)
215 {
216  //Get object value
217  value->integer = SNMP_MAX_MSG_SIZE;
218 
219  //Return status code
220  return NO_ERROR;
221 }
222 
223 #endif
SnmpFrameworkMibBase snmpFrameworkMibBase
SNMP FRAMEWORK MIB base.
TCP/IP stack core.
Debugging facilities.
#define MibObject
Definition: mib_common.h:44
General definitions for cryptographic algorithms.
OID (Object Identifier)
ASN.1 (Abstract Syntax Notation One)
error_t snmpFrameworkMibGetSnmpEngineID(const MibObject *object, const uint8_t *oid, size_t oidLen, MibVariant *value, size_t *valueLen)
Get snmpEngineID object value.
error_t snmpFrameworkMibInit(void)
SNMP FRAMEWORK MIB module initialization.
error_t snmpFrameworkMibGetSnmpEngineBoots(const MibObject *object, const uint8_t *oid, size_t oidLen, MibVariant *value, size_t *valueLen)
Get snmpEngineBoots object value.
#define TRACE_INFO(...)
Definition: debug.h:86
Success.
Definition: error.h:42
void snmpFrameworkMibLock(void)
Lock SNMP FRAMEWORK MIB base.
error_t
Error codes.
Definition: error.h:40
void snmpFrameworkMibUnlock(void)
Unlock SNMP FRAMEWORK MIB base.
void snmpFrameworkMibUnload(void *context)
Unload SNMP FRAMEWORK MIB module.
__start_packed struct @208 MibVariant
Variant data type.
error_t snmpFrameworkMibLoad(void *context)
Load SNMP FRAMEWORK MIB module.
uint8_t value[]
Definition: dtls_misc.h:141
Common definitions for MIB modules.
#define SNMP_MAX_MSG_SIZE
Definition: snmp_common.h:58
#define SnmpAgentContext
Definition: snmp_agent.h:34
error_t snmpFrameworkMibGetSnmpEngineTime(const MibObject *object, const uint8_t *oid, size_t oidLen, MibVariant *value, size_t *valueLen)
Get snmpEngineTime object value.
SNMP FRAMEWORK MIB module implementation.
uint8_t oid[1]
Definition: mib_common.h:184
error_t snmpFrameworkMibGetSnmpEngineMaxMessageSize(const MibObject *object, const uint8_t *oid, size_t oidLen, MibVariant *value, size_t *valueLen)
Get snmpEngineMaxMessageSize object value.
SNMP FRAMEWORK MIB module.