mikroSDK Reference Manual
snmp_agent.h
Go to the documentation of this file.
1
31#ifndef _SNMP_AGENT_H
32#define _SNMP_AGENT_H
33
34//Forward declaration of SnmpAgentContext structure
36#define SnmpAgentContext struct _SnmpAgentContext
37
38//Dependencies
39#include "core/net.h"
40#include "snmp/snmp_common.h"
41#include "snmp/snmp_agent_message.h"
44#include "snmp/snmp_agent_usm.h"
46#include "mibs/mib_common.h"
47
48//SNMP agent support
49#ifndef SNMP_AGENT_SUPPORT
50 #define SNMP_AGENT_SUPPORT DISABLED
51#elif (SNMP_AGENT_SUPPORT != ENABLED && SNMP_AGENT_SUPPORT != DISABLED)
52 #error SNMP_AGENT_SUPPORT parameter is not valid
53#endif
54
55//Stack size required to run the SNMP agent
56#ifndef SNMP_AGENT_STACK_SIZE
57 #define SNMP_AGENT_STACK_SIZE 550
58#elif (SNMP_AGENT_STACK_SIZE < 1)
59 #error SNMP_AGENT_STACK_SIZE parameter is not valid
60#endif
61
62//Priority at which the SNMP agent should run
63#ifndef SNMP_AGENT_PRIORITY
64 #define SNMP_AGENT_PRIORITY OS_TASK_PRIORITY_NORMAL
65#endif
66
67//Maximum number of MIBs
68#ifndef SNMP_AGENT_MAX_MIBS
69 #define SNMP_AGENT_MAX_MIBS 8
70#elif (SNMP_AGENT_MAX_MIBS < 1)
71 #error SNMP_AGENT_MAX_MIBS parameter is not valid
72#endif
73
74//Maximum number of community strings
75#ifndef SNMP_AGENT_MAX_COMMUNITIES
76 #define SNMP_AGENT_MAX_COMMUNITIES 3
77#elif (SNMP_AGENT_MAX_COMMUNITIES < 1)
78 #error SNMP_AGENT_MAX_COMMUNITIES parameter is not valid
79#endif
80
81//Maximum number of users
82#ifndef SNMP_AGENT_MAX_USERS
83 #define SNMP_AGENT_MAX_USERS 8
84#elif (SNMP_AGENT_MAX_USERS < 1)
85 #error SNMP_AGENT_MAX_USERS parameter is not valid
86#endif
87
88//Size of the group table
89#ifndef SNMP_AGENT_GROUP_TABLE_SIZE
90 #define SNMP_AGENT_GROUP_TABLE_SIZE 8
91#elif (SNMP_AGENT_GROUP_TABLE_SIZE < 1)
92 #error SNMP_AGENT_GROUP_TABLE_SIZE parameter is not valid
93#endif
94
95//Size of the access table
96#ifndef SNMP_AGENT_ACCESS_TABLE_SIZE
97 #define SNMP_AGENT_ACCESS_TABLE_SIZE 8
98#elif (SNMP_AGENT_ACCESS_TABLE_SIZE < 1)
99 #error SNMP_AGENT_ACCESS_TABLE_SIZE parameter is not valid
100#endif
101
102//Size of the view table
103#ifndef SNMP_AGENT_VIEW_TABLE_SIZE
104 #define SNMP_AGENT_VIEW_TABLE_SIZE 8
105#elif (SNMP_AGENT_VIEW_TABLE_SIZE < 1)
106 #error SNMP_AGENT_VIEW_TABLE_SIZE parameter is not valid
107#endif
108
109//Application specific context
110#ifndef SNMP_AGENT_PRIVATE_CONTEXT
111 #define SNMP_AGENT_PRIVATE_CONTEXT
112#endif
113
114//C++ guard
115#ifdef __cplusplus
116extern "C" {
117#endif
118
119
124typedef error_t (*SnmpAgentRandCallback)(uint8_t *data, size_t length);
125
126
140
141
147{
149 bool_t running;
150 bool_t stop;
154#if (OS_STATIC_TASK_SUPPORT == ENABLED)
155 OsTaskTcb taskTcb;
156 OsStackType taskStack[SNMP_AGENT_STACK_SIZE];
157#endif
158 uint8_t enterpriseOid[SNMP_MAX_OID_SIZE];
160 const MibModule *mibTable[SNMP_AGENT_MAX_MIBS];
161#if (SNMP_V1_SUPPORT == ENABLED || SNMP_V2C_SUPPORT == ENABLED)
162 SnmpUserEntry communityTable[SNMP_AGENT_MAX_COMMUNITIES];
163#endif
164#if (SNMP_V3_SUPPORT == ENABLED)
165 SnmpUserEntry userTable[SNMP_AGENT_MAX_USERS];
166#endif
167#if (SNMP_AGENT_VACM_SUPPORT == ENABLED)
168 SnmpGroupEntry groupTable[SNMP_AGENT_GROUP_TABLE_SIZE];
169 SnmpAccessEntry accessTable[SNMP_AGENT_ACCESS_TABLE_SIZE];
170 SnmpViewEntry viewTable[SNMP_AGENT_VIEW_TABLE_SIZE];
171#endif
172 Socket *socket;
173 NetInterface *localInterface;
176 uint16_t remotePort;
177 int32_t requestId;
181#if (SNMP_V3_SUPPORT == ENABLED)
182 uint8_t contextEngine[SNMP_MAX_CONTEXT_ENGINE_SIZE];
184 char_t contextName[SNMP_MAX_CONTEXT_NAME_LEN + 1];
186 int32_t engineBoots;
187 int32_t engineTime;
188 int32_t msgId;
189 uint64_t salt;
190 uint8_t privParameters[8];
191#endif
192#if (SNMP_AGENT_INFORM_SUPPORT == ENABLED)
198#if (SNMP_V3_SUPPORT == ENABLED)
199 uint8_t informContextEngine[SNMP_MAX_CONTEXT_ENGINE_SIZE];
203 int32_t informMsgId;
204#endif
205#endif
206 SNMP_AGENT_PRIVATE_CONTEXT
207};
208
209
210//SNMP agent related functions
211void snmpAgentGetDefaultSettings(SnmpAgentSettings *settings);
212
213error_t snmpAgentInit(SnmpAgentContext *context,
214 const SnmpAgentSettings *settings);
215
216error_t snmpAgentStart(SnmpAgentContext *context);
217error_t snmpAgentStop(SnmpAgentContext *context);
218
219error_t snmpAgentLoadMib(SnmpAgentContext *context, const MibModule *module);
220error_t snmpAgentUnloadMib(SnmpAgentContext *context, const MibModule *module);
221
222error_t snmpAgentSetVersion(SnmpAgentContext *context,
223 SnmpVersion versionMin, SnmpVersion versionMax);
224
225error_t snmpAgentSetEngineBoots(SnmpAgentContext *context, int32_t engineBoots);
226error_t snmpAgentGetEngineBoots(SnmpAgentContext *context, int32_t *engineBoots);
227
228error_t snmpAgentSetEnterpriseOid(SnmpAgentContext *context,
229 const uint8_t *enterpriseOid, size_t enterpriseOidLen);
230
231error_t snmpAgentSetContextEngine(SnmpAgentContext *context,
232 const void *contextEngine, size_t contextEngineLen);
233
234error_t snmpAgentSetContextName(SnmpAgentContext *context,
235 const char_t *contextName);
236
237error_t snmpAgentCreateCommunity(SnmpAgentContext *context,
238 const char_t *community, SnmpAccess mode);
239
240error_t snmpAgentDeleteCommunity(SnmpAgentContext *context,
241 const char_t *community);
242
243error_t snmpAgentCreateUser(SnmpAgentContext *context,
244 const char_t *userName, SnmpAccess mode, SnmpKeyFormat keyFormat,
245 SnmpAuthProtocol authProtocol, const void *authKey,
246 SnmpPrivProtocol privProtocol, const void *privKey);
247
248error_t snmpAgentDeleteUser(SnmpAgentContext *context, const char_t *userName);
249
250error_t snmpAgentJoinGroup(SnmpAgentContext *context, const char_t *userName,
251 SnmpSecurityModel securityModel, const char_t *groupName);
252
253error_t snmpAgentLeaveGroup(SnmpAgentContext *context,
254 const char_t *userName, SnmpSecurityModel securityModel);
255
256error_t snmpAgentCreateAccess(SnmpAgentContext *context,
257 const char_t *groupName, SnmpSecurityModel securityModel,
258 SnmpSecurityLevel securityLevel, const char_t *contextPrefix,
259 SnmpContextMatch contextMatch, const char_t *readViewName,
260 const char_t *writeViewName, const char_t *notifyViewName);
261
262error_t snmpAgentDeleteAccess(SnmpAgentContext *context,
263 const char_t *groupName, SnmpSecurityModel securityModel,
264 SnmpSecurityLevel securityLevel, const char_t *contextPrefix);
265
266error_t snmpAgentCreateView(SnmpAgentContext *context,
267 const char_t *viewName, const uint8_t *subtree, size_t subtreeLen,
268 const uint8_t *mask, size_t maskLen, SnmpViewType type);
269
270error_t snmpAgentDeleteView(SnmpAgentContext *context,
271 const char_t *viewName, const uint8_t *subtree, size_t subtreeLen);
272
273error_t snmpAgentSendTrap(SnmpAgentContext *context,
274 const IpAddr *destIpAddr, SnmpVersion version, const char_t *userName,
275 uint_t genericTrapType, uint_t specificTrapCode,
276 const SnmpTrapObject *objectList, uint_t objectListSize);
277
278error_t snmpAgentSendInform(SnmpAgentContext *context,
279 const IpAddr *destIpAddr, SnmpVersion version, const char_t *userName,
280 uint_t genericTrapType, uint_t specificTrapCode,
281 const SnmpTrapObject *objectList, uint_t objectListSize);
282
283void snmpAgentTask(SnmpAgentContext *context);
284
285void snmpAgentDeinit(SnmpAgentContext *context);
286
287//C++ guard
288#ifdef __cplusplus
289}
290#endif
291
292#endif
error_t
Error codes.
Definition error.h:43
Common definitions for MIB modules.
TCP/IP stack core.
uint_t OsMutex
Mutex object.
Definition os_port_none.h:118
uint_t OsEvent
Event object.
Definition os_port_none.h:104
uint_t OsTaskId
Task identifier.
Definition os_port_none.h:97
uint32_t systime_t
System time.
Definition os_port_none.h:90
error_t(* SnmpAgentRandCallback)(uint8_t *data, size_t length)
Random data generation callback function.
Definition snmp_agent.h:124
SNMP inform notifications.
SnmpAgentState
State of the inform sending process.
Definition snmp_agent_inform.h:70
SNMP trap notifications.
User-based Security Model (USM) for SNMPv3.
SnmpAuthProtocol
Definition snmp_agent_usm.h:244
SnmpKeyFormat
SNMP key format.
Definition snmp_agent_usm.h:272
SnmpAccess
Access modes.
Definition snmp_agent_usm.h:231
SnmpSecurityLevel
Security levels.
Definition snmp_agent_usm.h:219
SnmpSecurityModel
Security models.
Definition snmp_agent_usm.h:205
SnmpPrivProtocol
Definition snmp_agent_usm.h:260
View-based Access Control Model (VACM) for SNMP.
SnmpContextMatch
Context match.
Definition snmp_agent_vacm.h:58
SnmpViewType
View type.
Definition snmp_agent_vacm.h:70
Definitions common to SNMP agent and SNMP manager.
SnmpVersion
SNMP version identifiers.
Definition snmp_common.h:137
IP network address.
Definition ip.h:72
MIB module.
Definition mib_common.h:288
Access table entry.
Definition snmp_agent_vacm.h:95
SNMP agent settings.
Definition snmp_agent.h:132
SnmpAgentRandCallback randCallback
Random data generation callback function.
Definition snmp_agent.h:138
uint16_t port
SNMP port number.
Definition snmp_agent.h:136
SnmpVersion versionMax
Maximum version accepted by the SNMP agent.
Definition snmp_agent.h:135
uint16_t trapPort
SNMP trap port number.
Definition snmp_agent.h:137
NetInterface * interface
Network interface to configure.
Definition snmp_agent.h:133
SnmpVersion versionMin
Minimum version accepted by the SNMP agent.
Definition snmp_agent.h:134
Group table entry.
Definition snmp_agent_vacm.h:82
SNMP message.
Definition snmp_agent_message.h:56
Object descriptor for trap notifications.
Definition snmp_agent_trap.h:56
User table entry.
Definition snmp_agent_usm.h:295
View table entry.
Definition snmp_agent_vacm.h:113
SNMP agent context.
Definition snmp_agent.h:147
int32_t requestId
Request identifier.
Definition snmp_agent.h:177
SnmpAccessEntry accessTable[SNMP_AGENT_ACCESS_TABLE_SIZE]
Access rights for groups.
Definition snmp_agent.h:169
OsEvent informEvent
Event object.
Definition snmp_agent.h:197
OsEvent event
Event object used to poll the underlying socket.
Definition snmp_agent.h:152
uint8_t privParameters[8]
Privacy parameters.
Definition snmp_agent.h:190
size_t contextEngineLen
Length of the context engine identifier.
Definition snmp_agent.h:183
uint8_t informContextEngine[SNMP_MAX_CONTEXT_ENGINE_SIZE]
Context engine identifier of the remote application.
Definition snmp_agent.h:199
int32_t engineTime
SNMP engine time.
Definition snmp_agent.h:187
bool_t running
Operational state of the SNMP agent.
Definition snmp_agent.h:149
IpAddr remoteIpAddr
Source IP address of the received SNMP request.
Definition snmp_agent.h:175
int32_t engineBoots
Number of times that the SNMP engine has rebooted.
Definition snmp_agent.h:186
SnmpAgentSettings settings
SNMP agent settings.
Definition snmp_agent.h:148
OsStackType taskStack[SNMP_AGENT_STACK_SIZE]
Task stack.
Definition snmp_agent.h:156
SnmpMessage response
SNMP response message.
Definition snmp_agent.h:179
OsTaskTcb taskTcb
Task control block.
Definition snmp_agent.h:155
SnmpUserEntry userTable[SNMP_AGENT_MAX_USERS]
List of users.
Definition snmp_agent.h:165
size_t enterpriseOidLen
Length of the enterprise OID.
Definition snmp_agent.h:159
NetInterface * localInterface
Network interface the SNMP request was received on.
Definition snmp_agent.h:173
uint_t informRetransmitCount
Retransmission counter.
Definition snmp_agent.h:196
bool_t stop
Stop request.
Definition snmp_agent.h:150
SnmpMessage request
SNMP request message.
Definition snmp_agent.h:178
int32_t informRequestId
Inform request identifier.
Definition snmp_agent.h:194
Socket * socket
Underlying socket.
Definition snmp_agent.h:172
char_t contextName[SNMP_MAX_CONTEXT_NAME_LEN+1]
Context name.
Definition snmp_agent.h:184
uint64_t salt
Integer initialized to a random value at boot time.
Definition snmp_agent.h:189
SnmpUserEntry communityTable[SNMP_AGENT_MAX_COMMUNITIES]
Community strings.
Definition snmp_agent.h:162
SnmpUserEntry user
Security profile of current user.
Definition snmp_agent.h:180
uint8_t enterpriseOid[SNMP_MAX_OID_SIZE]
Enterprise OID.
Definition snmp_agent.h:158
OsMutex mutex
Mutex preventing simultaneous access to SNMP agent context.
Definition snmp_agent.h:151
SnmpAgentState informState
State of the inform sending process.
Definition snmp_agent.h:193
IpAddr localIpAddr
Destination IP address of the received SNMP request.
Definition snmp_agent.h:174
systime_t informTimestamp
Timestamp to manage retransmissions.
Definition snmp_agent.h:195
const MibModule * mibTable[SNMP_AGENT_MAX_MIBS]
MIB modules.
Definition snmp_agent.h:160
OsTaskId taskId
Task identifier.
Definition snmp_agent.h:153
size_t informContextEngineLen
Length of the context engine identifier.
Definition snmp_agent.h:200
uint8_t contextEngine[SNMP_MAX_CONTEXT_ENGINE_SIZE]
Context engine identifier.
Definition snmp_agent.h:182
systime_t systemTime
System time.
Definition snmp_agent.h:185
int32_t informMsgId
Message identifier.
Definition snmp_agent.h:203
SnmpGroupEntry groupTable[SNMP_AGENT_GROUP_TABLE_SIZE]
List of groups.
Definition snmp_agent.h:168
uint16_t remotePort
Source port of the received SNMP request.
Definition snmp_agent.h:176
int32_t informEngineTime
SNMP engine time of the remote application.
Definition snmp_agent.h:202
int32_t msgId
Message identifier.
Definition snmp_agent.h:188
SnmpViewEntry viewTable[SNMP_AGENT_VIEW_TABLE_SIZE]
Families of subtrees within MIB views.
Definition snmp_agent.h:170
int32_t informEngineBoots
Number of times that the remote SNMP engine has rebooted.
Definition snmp_agent.h:201