mikroSDK Reference Manual
snmp_agent_message.h
1
31#ifndef _SNMP_AGENT_MESSAGE_H
32#define _SNMP_AGENT_MESSAGE_H
33
34//Dependencies
35#include "core/net.h"
36#include "snmp/snmp_agent.h"
37
38//SNMPv1 message header overhead
39#define SNMP_V1_MSG_HEADER_OVERHEAD 48
40//SNMPv2c message header overhead
41#define SNMP_V2C_MSG_HEADER_OVERHEAD 37
42//SNMPv3 message header overhead
43#define SNMP_V3_MSG_HEADER_OVERHEAD 105
44
45//C++ guard
46#ifdef __cplusplus
47extern "C" {
48#endif
49
50
55typedef struct
56{
57 uint8_t buffer[SNMP_MAX_MSG_SIZE];
58 size_t bufferLen;
59 uint8_t *pos;
60 size_t length;
61 int32_t version;
62#if (SNMP_V1_SUPPORT == ENABLED || SNMP_V2C_SUPPORT == ENABLED)
63 const char_t *community;
64 size_t communityLen;
65#endif
66#if (SNMP_V3_SUPPORT == ENABLED)
67 int32_t msgId;
68 int32_t msgMaxSize;
69 uint8_t msgFlags;
71 const uint8_t *msgAuthEngineId;
75 const char_t *msgUserName;
79 const uint8_t *msgPrivParameters;
81 const uint8_t *contextEngineId;
83 const char_t *contextName;
85#endif
87 int32_t requestId;
88 int32_t errorStatus;
89 int32_t errorIndex;
90#if (SNMP_V1_SUPPORT == ENABLED)
91 const uint8_t *enterpriseOid;
96 uint32_t timestamp;
97#endif
98#if (SNMP_V2C_SUPPORT == ENABLED || SNMP_V3_SUPPORT == ENABLED)
99 int32_t nonRepeaters;
101#endif
102 uint8_t *varBindList;
105 size_t oidLen;
107
108
113typedef struct
114{
115 const uint8_t *oid;
116 size_t oidLen;
117 uint_t objClass;
118 uint_t objType;
119 const uint8_t *value;
120 size_t valueLen;
122
123
124//SNMP related functions
125void snmpInitMessage(SnmpMessage *message);
126error_t snmpInitResponse(SnmpAgentContext *context);
127
128error_t snmpComputeMessageOverhead(SnmpMessage *message);
129
130error_t snmpParseMessageHeader(SnmpMessage *message);
131error_t snmpWriteMessageHeader(SnmpMessage *message);
132
133error_t snmpParseCommunity(SnmpMessage *message);
134error_t snmpWriteCommunity(SnmpMessage *message);
135
136error_t snmpParseGlobalData(SnmpMessage *message);
137error_t snmpWriteGlobalData(SnmpMessage *message);
138
139error_t snmpParseSecurityParameters(SnmpMessage *message);
140error_t snmpWriteSecurityParameters(SnmpMessage *message);
141
142error_t snmpParseScopedPdu(SnmpMessage *message);
143error_t snmpWriteScopedPdu(SnmpMessage *message);
144
145error_t snmpParsePduHeader(SnmpMessage *message);
146error_t snmpWritePduHeader(SnmpMessage *message);
147
148error_t snmpEncodeInt32(int32_t value, uint8_t *dest, size_t *length);
149error_t snmpEncodeUnsignedInt32(uint32_t value, uint8_t *dest, size_t *length);
150error_t snmpEncodeUnsignedInt64(uint64_t value, uint8_t *dest, size_t *length);
151
152error_t snmpDecodeInt32(const uint8_t *src, size_t length, int32_t *value);
153error_t snmpDecodeUnsignedInt32(const uint8_t *src, size_t length, uint32_t *value);
154error_t snmpDecodeUnsignedInt64(const uint8_t *src, size_t length, uint64_t *value);
155
156//C++ guard
157#ifdef __cplusplus
158}
159#endif
160
161#endif
error_t
Error codes.
Definition error.h:43
uint32_t Ipv4Addr
IPv4 network address.
Definition ipv4.h:267
TCP/IP stack core.
SNMP agent (Simple Network Management Protocol)
SnmpPduType
SNMP PDU types.
Definition snmp_common.h:149
SNMP message.
Definition snmp_agent_message.h:56
size_t bufferLen
Original length of the message.
Definition snmp_agent_message.h:58
const uint8_t * msgPrivParameters
Privacy parameters.
Definition snmp_agent_message.h:79
const uint8_t * msgAuthEngineId
Authoritative engine identifier.
Definition snmp_agent_message.h:71
int32_t msgMaxSize
Maximum message size supported by the sender.
Definition snmp_agent_message.h:68
uint8_t * pos
Current position.
Definition snmp_agent_message.h:59
int32_t version
SNMP version identifier.
Definition snmp_agent_message.h:61
Ipv4Addr agentAddr
Address of object generating trap.
Definition snmp_agent_message.h:93
int32_t msgAuthEngineTime
Number of seconds since last reboot.
Definition snmp_agent_message.h:74
SnmpPduType pduType
PDU type.
Definition snmp_agent_message.h:86
int32_t requestId
Request identifier.
Definition snmp_agent_message.h:87
int32_t nonRepeaters
GetBulkRequest-PDU specific parameter.
Definition snmp_agent_message.h:99
size_t contextNameLen
Length of the context name.
Definition snmp_agent_message.h:84
int32_t errorIndex
Error index.
Definition snmp_agent_message.h:89
size_t enterpriseOidLen
Length of the enterprise OID.
Definition snmp_agent_message.h:92
const uint8_t * contextEngineId
Context engine identifier.
Definition snmp_agent_message.h:81
size_t msgAuthParametersLen
Length of the authentication parameters.
Definition snmp_agent_message.h:78
uint8_t msgFlags
Bit fields which control processing of the message.
Definition snmp_agent_message.h:69
const uint8_t * enterpriseOid
Type of object generating trap.
Definition snmp_agent_message.h:91
size_t communityLen
Length of the community name.
Definition snmp_agent_message.h:64
const char_t * msgUserName
User name.
Definition snmp_agent_message.h:75
int32_t msgSecurityModel
Security model used by the sender.
Definition snmp_agent_message.h:70
size_t varBindListLen
Length of the list in bytes.
Definition snmp_agent_message.h:103
uint8_t * varBindList
List of variable bindings.
Definition snmp_agent_message.h:102
size_t oidLen
Length of the object identifier.
Definition snmp_agent_message.h:105
size_t varBindListMaxLen
Maximum length of the list in bytes.
Definition snmp_agent_message.h:104
size_t length
Length of the message.
Definition snmp_agent_message.h:60
int32_t msgId
Message identifier.
Definition snmp_agent_message.h:67
const char_t * contextName
Context name.
Definition snmp_agent_message.h:83
size_t msgAuthEngineIdLen
Length of the authoritative engine identifier.
Definition snmp_agent_message.h:72
int32_t genericTrapType
Generic trap type.
Definition snmp_agent_message.h:94
int32_t msgAuthEngineBoots
Number of times the SNMP engine has rebooted.
Definition snmp_agent_message.h:73
uint8_t * msgAuthParameters
Authentication parameters.
Definition snmp_agent_message.h:77
const char_t * community
Community name.
Definition snmp_agent_message.h:63
size_t msgUserNameLen
Length of the user name.
Definition snmp_agent_message.h:76
int32_t specificTrapCode
Specific trap code.
Definition snmp_agent_message.h:95
size_t contextEngineIdLen
Length of the context engine identifier.
Definition snmp_agent_message.h:82
int32_t maxRepetitions
GetBulkRequest-PDU specific parameter.
Definition snmp_agent_message.h:100
int32_t errorStatus
Error status.
Definition snmp_agent_message.h:88
uint32_t timestamp
Timestamp.
Definition snmp_agent_message.h:96
size_t msgPrivParametersLen
Length of the privacy parameters.
Definition snmp_agent_message.h:80
Variable binding.
Definition snmp_agent_message.h:114