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