snmp_agent_misc.c
Go to the documentation of this file.
1 /**
2  * @file snmp_agent_misc.c
3  * @brief Helper functions for SNMP agent
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.0
29  **/
30 
31 //Switch to the appropriate trace level
32 #define TRACE_LEVEL SNMP_TRACE_LEVEL
33 
34 //Dependencies
35 #include <limits.h>
36 #include "core/net.h"
37 #include "snmp/snmp_agent.h"
38 #include "snmp/snmp_agent_misc.h"
39 #include "snmp/snmp_agent_object.h"
40 #include "mibs/mib2_module.h"
41 #include "core/crypto.h"
42 #include "encoding/asn1.h"
43 #include "encoding/oid.h"
44 #include "debug.h"
45 
46 //Check TCP/IP stack configuration
47 #if (SNMP_AGENT_SUPPORT == ENABLED)
48 
49 //sysUpTime.0 object (1.3.6.1.2.1.1.3.0)
50 static const uint8_t sysUpTimeObject[] = {43, 6, 1, 2, 1, 1, 3, 0};
51 //snmpTrapOID.0 object (1.3.6.1.6.3.1.1.4.1.0)
52 static const uint8_t snmpTrapOidObject[] = {43, 6, 1, 6, 3, 1, 1, 4, 1, 0};
53 //snmpTraps object (1.3.6.1.6.3.1.1.5)
54 static const uint8_t snmpTrapsObject[] = {43, 6, 1, 6, 3, 1, 1, 5};
55 
56 
57 /**
58  * @brief Lock MIB bases
59  * @param[in] context Pointer to the SNMP agent context
60  **/
61 
63 {
64  uint_t i;
65  bool_t flag;
66 
67  //Initialize flag
68  flag = FALSE;
69 
70  //Loop through MIBs
71  for(i = 0; i < SNMP_AGENT_MAX_MIBS; i++)
72  {
73  //Valid MIB?
74  if(context->mibTable[i] != NULL)
75  {
76  //Any registered callback?
77  if(context->mibTable[i]->lock != NULL)
78  {
79  //Lock access to the MIB
80  context->mibTable[i]->lock();
81  }
82  else
83  {
84  //The MIB does not feature any lock/unlock mechanism
85  flag = TRUE;
86  }
87  }
88  }
89 
90  //Default lock/unlock sequence?
91  if(flag)
92  {
93  //Get exclusive access
95  }
96 }
97 
98 
99 /**
100  * @brief Unlock MIB bases
101  * @param[in] context Pointer to the SNMP agent context
102  **/
103 
105 {
106  uint_t i;
107  bool_t flag;
108 
109  //Initialize flag
110  flag = FALSE;
111 
112  //Loop through MIBs
113  for(i = 0; i < SNMP_AGENT_MAX_MIBS; i++)
114  {
115  //Valid MIB?
116  if(context->mibTable[i] != NULL)
117  {
118  //Any registered callback?
119  if(context->mibTable[i]->unlock != NULL)
120  {
121  //Unlock access to the MIB
122  context->mibTable[i]->unlock();
123  }
124  else
125  {
126  //The MIB does not feature any lock/unlock mechanism
127  flag = TRUE;
128  }
129  }
130  }
131 
132  //Default lock/unlock sequence?
133  if(flag)
134  {
135  //Release exclusive access
137  }
138 }
139 
140 
141 /**
142  * @brief Create a new community entry
143  * @param[in] context Pointer to the SNMP agent context
144  * @return Pointer to the newly created entry
145  **/
146 
148 {
149  SnmpUserEntry *entry;
150 
151  //Initialize pointer
152  entry = NULL;
153 
154 #if (SNMP_V1_SUPPORT == ENABLED || SNMP_V2C_SUPPORT == ENABLED)
155  //Sanity check
156  if(context != NULL)
157  {
158  uint_t i;
159 
160  //Loop through the list of community strings
161  for(i = 0; i < SNMP_AGENT_MAX_COMMUNITIES; i++)
162  {
163  //Check current status
164  if(context->communityTable[i].status == MIB_ROW_STATUS_UNUSED)
165  {
166  //An unused entry has been found
167  entry = &context->communityTable[i];
168  //We are done
169  break;
170  }
171  }
172 
173  //Check whether the table runs out of space
174  if(entry == NULL)
175  {
176  //Loop through the list of community strings
177  for(i = 0; i < SNMP_AGENT_MAX_COMMUNITIES; i++)
178  {
179  //Check current status
180  if(context->communityTable[i].status == MIB_ROW_STATUS_NOT_READY)
181  {
182  //Reuse the current entry
183  entry = &context->communityTable[i];
184  //We are done
185  break;
186  }
187  }
188  }
189  }
190 #endif
191 
192  //Return a pointer to the newly created entry
193  return entry;
194 }
195 
196 
197 /**
198  * @brief Search the community table for a given community string
199  * @param[in] context Pointer to the SNMP agent context
200  * @param[in] community Pointer to the community string
201  * @param[in] length Length of the community string
202  * @return Pointer to the matching entry
203  **/
204 
206  const char_t *community, size_t length)
207 {
208  SnmpUserEntry *entry;
209 
210  //Initialize pointer
211  entry = NULL;
212 
213 #if (SNMP_V1_SUPPORT == ENABLED || SNMP_V2C_SUPPORT == ENABLED)
214  //Sanity check
215  if(context != NULL && community != NULL)
216  {
217  uint_t i;
218 
219  //Loop through the list of community string
220  for(i = 0; i < SNMP_AGENT_MAX_COMMUNITIES; i++)
221  {
222  //Check current status
223  if(context->communityTable[i].status != MIB_ROW_STATUS_UNUSED)
224  {
225  //Check the length of the community string
226  if(osStrlen(context->communityTable[i].name) == length)
227  {
228  //Compare community strings
229  if(!osStrncmp(context->communityTable[i].name, community, length))
230  {
231  //A matching entry has been found
232  entry = &context->communityTable[i];
233  //We are done
234  break;
235  }
236  }
237  }
238  }
239  }
240 #endif
241 
242  //Return a pointer to the matching entry
243  return entry;
244 }
245 
246 
247 /**
248  * @brief Parse variable binding
249  * @param[in] p Input stream where to read the variable binding
250  * @param[in] length Number of bytes available in the input stream
251  * @param[out] var Variable binding
252  * @param[out] consumed Total number of bytes that have been consumed
253  * @return Error code
254  **/
255 
257  size_t length, SnmpVarBind *var, size_t *consumed)
258 {
259  error_t error;
260  Asn1Tag tag;
261 
262  //The variable binding is encapsulated within a sequence
263  error = asn1ReadTag(p, length, &tag);
264  //Failed to decode ASN.1 tag?
265  if(error)
266  return error;
267 
268  //Enforce encoding, class and type
270  //The tag does not match the criteria?
271  if(error)
272  return error;
273 
274  //Total number of bytes that have been consumed
275  *consumed = tag.totalLength;
276 
277  //Point to the first item of the sequence
278  p = tag.value;
279  length = tag.length;
280 
281  //Read object name
282  error = asn1ReadTag(p, length, &tag);
283  //Failed to decode ASN.1 tag?
284  if(error)
285  return error;
286 
287  //Enforce encoding, class and type
289  //The tag does not match the criteria?
290  if(error)
291  return error;
292 
293  //Save object identifier
294  var->oid = tag.value;
295  var->oidLen = tag.length;
296 
297  //Point to the next item
298  p += tag.totalLength;
299  length -= tag.totalLength;
300 
301  //Read object value
302  error = asn1ReadTag(p, length, &tag);
303  //Failed to decode ASN.1 tag?
304  if(error)
305  return error;
306 
307  //Make sure that the tag is valid
308  if(tag.constructed)
309  return ERROR_INVALID_TAG;
310 
311  //Save object class
312  var->objClass = tag.objClass;
313  //Save object type
314  var->objType = tag.objType;
315  //Save object value
316  var->value = tag.value;
317  var->valueLen = tag.length;
318 
319  //Successful processing
320  return NO_ERROR;
321 }
322 
323 
324 /**
325  * @brief Write variable binding
326  * @param[in] context Pointer to the SNMP agent context
327  * @param[in] var Variable binding
328  * @return Error code
329  **/
330 
332 {
333  error_t error;
334  size_t m;
335  size_t n;
336  uint8_t *p;
337  Asn1Tag tag;
338 
339  //The object's name is encoded in ASN.1 format
340  tag.constructed = FALSE;
343  tag.length = var->oidLen;
344  tag.value = var->oid;
345 
346  //Calculate the total length of the ASN.1 tag
347  error = asn1WriteTag(&tag, FALSE, NULL, &m);
348  //Any error to report?
349  if(error)
350  return error;
351 
352  //The object's value is encoded in ASN.1 format
353  tag.constructed = FALSE;
354  tag.objClass = var->objClass;
355  tag.objType = var->objType;
356  tag.length = var->valueLen;
357  tag.value = var->value;
358 
359  //Calculate the total length of the ASN.1 tag
360  error = asn1WriteTag(&tag, FALSE, NULL, &n);
361  //Any error to report?
362  if(error)
363  return error;
364 
365  //The variable binding is encapsulated within a sequence
366  tag.constructed = TRUE;
369  tag.length = m + n;
370  tag.value = NULL;
371 
372  //The first pass computes the total length of the sequence
373  error = asn1WriteTag(&tag, FALSE, NULL, NULL);
374  //Any error to report?
375  if(error)
376  return error;
377 
378  //Make sure the buffer is large enough to hold the whole sequence
379  if((context->response.varBindListLen + tag.totalLength) >
380  context->response.varBindListMaxLen)
381  {
382  //Report an error
383  return ERROR_BUFFER_OVERFLOW;
384  }
385 
386  //The second pass encodes the sequence in reverse order
387  p = context->response.varBindList + context->response.varBindListLen +
388  tag.totalLength;
389 
390  //Encode the object's value using ASN.1
391  tag.constructed = FALSE;
392  tag.objClass = var->objClass;
393  tag.objType = var->objType;
394  tag.length = var->valueLen;
395  tag.value = var->value;
396 
397  //Write the corresponding ASN.1 tag
398  error = asn1WriteTag(&tag, TRUE, p, &m);
399  //Any error to report?
400  if(error)
401  return error;
402 
403  //Move backward
404  p -= m;
405 
406  //Encode the object's name using ASN.1
407  tag.constructed = FALSE;
410  tag.length = var->oidLen;
411  tag.value = var->oid;
412 
413  //Write the corresponding ASN.1 tag
414  error = asn1WriteTag(&tag, TRUE, p, &n);
415  //Any error to report?
416  if(error)
417  return error;
418 
419  //Move backward
420  p -= n;
421 
422  //The variable binding is encapsulated within a sequence
423  tag.constructed = TRUE;
426  tag.length = m + n;
427  tag.value = NULL;
428 
429  //Write the corresponding ASN.1 tag
430  error = asn1WriteTag(&tag, TRUE, p, NULL);
431  //Any error to report?
432  if(error)
433  return error;
434 
435  //Update the length of the list
436  context->response.varBindListLen += tag.totalLength;
437 
438  //Successful processing
439  return NO_ERROR;
440 }
441 
442 
443 /**
444  * @brief Copy the list of variable bindings
445  * @param[in] context Pointer to the SNMP agent context
446  * @return Error code
447  **/
448 
450 {
451  //Sanity check
452  if(context->request.varBindListLen > context->response.varBindListMaxLen)
453  return ERROR_BUFFER_OVERFLOW;
454 
455  //Copy the list of variable bindings to the response buffer
456  osMemcpy(context->response.varBindList, context->request.varBindList,
457  context->request.varBindListLen);
458 
459  //Save the length of the list
460  context->response.varBindListLen = context->request.varBindListLen;
461 
462  //Successful processing
463  return NO_ERROR;
464 }
465 
466 
467 /**
468  * @brief Format the variable binding list for Trap-PDU or SNMPv2-Trap-PDU
469  * @param[in] context Pointer to the SNMP agent context
470  * @param[in] genericTrapType Generic trap type
471  * @param[in] specificTrapCode Specific code
472  * @param[in] objectList List of object names
473  * @param[in] objectListSize Number of entries in the list
474  * @return Error code
475  **/
476 
478  uint_t genericTrapType, uint_t specificTrapCode,
479  const SnmpTrapObject *objectList, uint_t objectListSize)
480 {
481  error_t error;
482  uint_t i;
483  size_t n;
484  systime_t time;
486  SnmpVarBind var;
487 
488  //Point to the SNMP message
489  message = &context->response;
490 
491 #if (SNMP_V2C_SUPPORT == ENABLED || SNMP_V3_SUPPORT == ENABLED)
492  //SNMPv2c or SNMPv3 version?
493  if(message->version == SNMP_VERSION_2C || message->version == SNMP_VERSION_3)
494  {
495  //Get current time
496  time = osGetSystemTime64() / 10;
497 
498  //Encode the object value using ASN.1 rules
499  error = snmpEncodeUnsignedInt32(time, message->buffer, &n);
500  //Any error to report?
501  if(error)
502  return error;
503 
504  //The first two variable bindings in the variable binding list of an
505  //SNMPv2-Trap-PDU are sysUpTime.0 and snmpTrapOID.0 respectively
506  var.oid = sysUpTimeObject;
507  var.oidLen = sizeof(sysUpTimeObject);
510  var.value = message->buffer;
511  var.valueLen = n;
512 
513  //Append sysUpTime.0 to the variable binding list
514  error = snmpWriteVarBinding(context, &var);
515  //Any error to report?
516  if(error)
517  return error;
518 
519  //Generic or enterprise-specific trap?
520  if(genericTrapType < SNMP_TRAP_ENTERPRISE_SPECIFIC)
521  {
522  //Retrieve the length of the snmpTraps OID
523  n = sizeof(snmpTrapsObject);
524  //Copy the OID
525  osMemcpy(message->buffer, snmpTrapsObject, n);
526 
527  //For generic traps, the SNMPv2 snmpTrapOID parameter shall be
528  //the corresponding trap as defined in section 2 of RFC 3418
529  message->buffer[n] = genericTrapType + 1;
530 
531  //Update the length of the snmpTrapOID parameter
532  n++;
533  }
534  else
535  {
536  //Retrieve the length of the enterprise OID
537  n = context->enterpriseOidLen;
538 
539  //For enterprise specific traps, the SNMPv2 snmpTrapOID parameter shall
540  //be the concatenation of the SNMPv1 enterprise OID and two additional
541  //sub-identifiers, '0' and the SNMPv1 specific trap parameter. Refer
542  //to RFC 3584, section 3.1 and RFC 2578, section 8.5
543  osMemcpy(message->buffer, context->enterpriseOid, n);
544 
545  //Concatenate the '0' sub-identifier
546  message->buffer[n++] = 0;
547 
548  //Concatenate the specific trap parameter
549  message->buffer[n] = specificTrapCode % 128;
550 
551  //Loop as long as necessary
552  for(i = 1; specificTrapCode > 128; i++)
553  {
554  //Split the binary representation into 7 bit chunks
555  specificTrapCode /= 128;
556  //Make room for the new chunk
557  osMemmove(message->buffer + n + 1, message->buffer + n, i);
558  //Set the most significant bit in the current chunk
559  message->buffer[n] = OID_MORE_FLAG | (specificTrapCode % 128);
560  }
561 
562  //Update the length of the snmpTrapOID parameter
563  n += i;
564  }
565 
566  //The snmpTrapOID.0 variable occurs as the second variable
567  //binding in every SNMPv2-Trap-PDU
568  var.oid = snmpTrapOidObject;
569  var.oidLen = sizeof(snmpTrapOidObject);
572  var.value = message->buffer;
573  var.valueLen = n;
574 
575  //Append snmpTrapOID.0 to the variable binding list
576  error = snmpWriteVarBinding(context, &var);
577  //Any error to report?
578  if(error)
579  return error;
580  }
581 #endif
582 
583  //Loop through the list of objects
584  for(i = 0; i < objectListSize; i++)
585  {
586  //Get object identifier
587  var.oid = objectList[i].oid;
588  var.oidLen = objectList[i].oidLen;
589 
590  //Retrieve object value
591  error = snmpGetObjectValue(context, message, &var);
592  //Any error to report?
593  if(error)
594  return error;
595 
596  //Append variable binding to the list
597  error = snmpWriteVarBinding(context, &var);
598  //Any error to report?
599  if(error)
600  return error;
601  }
602 
603  //Successful processing
604  return NO_ERROR;
605 }
606 
607 
608 /**
609  * @brief Translate status code
610  * @param[in,out] message Pointer to the outgoing SNMP message
611  * @param[in] status Status code
612  * @param[in] index Index of the variable binding in the list that caused an exception
613  * @return error code
614  **/
615 
617 {
618  //SNMPv1 version?
619  if(message->version == SNMP_VERSION_1)
620  {
621  //Set error-status and error-index fields (refer to RFC 2576, section 4.3)
622  switch(status)
623  {
624  case NO_ERROR:
625  //Return noError status code
626  message->errorStatus = SNMP_ERROR_NONE;
627  message->errorIndex = 0;
628  break;
629 
631  //Return tooBig status code
632  message->errorStatus = SNMP_ERROR_TOO_BIG;
633  message->errorIndex = 0;
634 
635  //Total number of SNMP PDUs which were generated by the SNMP protocol
636  //entity and for which the value of the error-status field is tooBig
637  MIB2_SNMP_INC_COUNTER32(snmpOutTooBigs, 1);
638  break;
639 
642  case ERROR_ACCESS_DENIED:
644  //Return noSuchName status code
645  message->errorStatus = SNMP_ERROR_NO_SUCH_NAME;
646  message->errorIndex = index;
647 
648  //Total number of SNMP PDUs which were generated by the SNMP protocol
649  //entity and for which the value of the error-status field is noSuchName
650  MIB2_SNMP_INC_COUNTER32(snmpOutNoSuchNames, 1);
651  break;
652 
653  case ERROR_WRONG_TYPE:
654  case ERROR_WRONG_LENGTH:
656  case ERROR_WRONG_VALUE:
658  //Return badValue status code
659  message->errorStatus = SNMP_ERROR_BAD_VALUE;
660  message->errorIndex = index;
661 
662  //Total number of SNMP PDUs which were generated by the SNMP protocol
663  //entity and for which the value of the error-status field is badValue
664  MIB2_SNMP_INC_COUNTER32(snmpOutBadValues, 1);
665  break;
666 
667  case ERROR_READ_FAILED:
668  case ERROR_WRITE_FAILED:
669  case ERROR_NOT_WRITABLE:
670  //Return genError status code
671  message->errorStatus = SNMP_ERROR_GENERIC;
672  message->errorIndex = index;
673 
674  //Total number of SNMP PDUs which were generated by the SNMP protocol
675  //entity and for which the value of the error-status field is genError
676  MIB2_SNMP_INC_COUNTER32(snmpOutGenErrs, 1);
677  break;
678 
679  default:
680  //If the parsing of the request fails, the SNMP agent discards
681  //the message and performs no further actions
682  return status;
683  }
684  }
685  //SNMPv2c or SNMPv3 version?
686  else
687  {
688  //Set error-status and error-index fields
689  switch(status)
690  {
691  case NO_ERROR:
692  //Return noError status code
693  message->errorStatus = SNMP_ERROR_NONE;
694  message->errorIndex = 0;
695  break;
696 
698  //Return tooBig status code
699  message->errorStatus = SNMP_ERROR_TOO_BIG;
700  message->errorIndex = 0;
701 
702  //Total number of SNMP PDUs which were generated by the SNMP protocol
703  //entity and for which the value of the error-status field is tooBig
704  MIB2_SNMP_INC_COUNTER32(snmpOutTooBigs, 1);
705  break;
706 
707  case ERROR_READ_FAILED:
708  case ERROR_WRITE_FAILED:
709  //Return genError status code
710  message->errorStatus = SNMP_ERROR_GENERIC;
711  message->errorIndex = index;
712 
713  //Total number of SNMP PDUs which were generated by the SNMP protocol
714  //entity and for which the value of the error-status field is genError
715  MIB2_SNMP_INC_COUNTER32(snmpOutGenErrs, 1);
716  break;
717 
720  case ERROR_ACCESS_DENIED:
721  //Return noAccess status code
722  message->errorStatus = SNMP_ERROR_NO_ACCESS;
723  message->errorIndex = index;
724  break;
725 
726  case ERROR_WRONG_TYPE:
727  //Return wrongType status code
728  message->errorStatus = SNMP_ERROR_WRONG_TYPE;
729  message->errorIndex = index;
730  break;
731 
732  case ERROR_WRONG_LENGTH:
733  //Return wrongLength status code
734  message->errorStatus = SNMP_ERROR_WRONG_LENGTH;
735  message->errorIndex = index;
736  break;
737 
739  //Return wrongEncoding status code
740  message->errorStatus = SNMP_ERROR_WRONG_ENCODING;
741  message->errorIndex = index;
742  break;
743 
744  case ERROR_WRONG_VALUE:
745  //Return wrongValue status code
746  message->errorStatus = SNMP_ERROR_WRONG_VALUE;
747  message->errorIndex = index;
748  break;
749 
751  //Return inconsistentValue status code
752  message->errorStatus = SNMP_ERROR_INCONSISTENT_VALUE;
753  message->errorIndex = index;
754  break;
755 
757  //Return authorizationError status code
758  message->errorStatus = SNMP_ERROR_AUTHORIZATION;
759  message->errorIndex = 0;
760  break;
761 
762  case ERROR_NOT_WRITABLE:
763  //Return notWritable status code
764  message->errorStatus = SNMP_ERROR_NOT_WRITABLE;
765  message->errorIndex = index;
766  break;
767 
768  default:
769  //If the parsing of the request fails, the SNMP agent discards
770  //the message and performs no further actions
771  return status;
772  }
773  }
774 
775  //Successful processing
776  return NO_ERROR;
777 }
778 
779 #endif
error_t asn1ReadTag(const uint8_t *data, size_t length, Asn1Tag *tag)
Read an ASN.1 tag from the input stream.
Definition: asn1.c:52
error_t asn1WriteTag(Asn1Tag *tag, bool_t reverse, uint8_t *data, size_t *written)
Write an ASN.1 tag.
Definition: asn1.c:334
error_t asn1CheckTag(const Asn1Tag *tag, bool_t constructed, uint_t objClass, uint_t objType)
Enforce the type of a specified tag.
Definition: asn1.c:653
ASN.1 (Abstract Syntax Notation One)
@ ASN1_TYPE_OBJECT_IDENTIFIER
Definition: asn1.h:74
@ ASN1_TYPE_SEQUENCE
Definition: asn1.h:80
#define ASN1_CLASS_APPLICATION
Definition: asn1.h:53
#define ASN1_CLASS_UNIVERSAL
Definition: asn1.h:52
uint8_t message[]
Definition: chap.h:154
unsigned int uint_t
Definition: compiler_port.h:50
char char_t
Definition: compiler_port.h:48
int bool_t
Definition: compiler_port.h:53
General definitions for cryptographic algorithms.
Debugging facilities.
uint8_t n
uint32_t time
error_t
Error codes.
Definition: error.h:43
@ ERROR_WRONG_TYPE
Definition: error.h:121
@ ERROR_WRONG_ENCODING
Definition: error.h:122
@ ERROR_WRONG_LENGTH
Definition: error.h:120
@ ERROR_WRITE_FAILED
Definition: error.h:221
@ ERROR_OBJECT_NOT_FOUND
Definition: error.h:255
@ ERROR_INSTANCE_NOT_FOUND
Definition: error.h:256
@ ERROR_NOT_WRITABLE
Definition: error.h:149
@ ERROR_WRONG_VALUE
Definition: error.h:123
@ ERROR_AUTHORIZATION_FAILED
Definition: error.h:266
@ ERROR_ACCESS_DENIED
Definition: error.h:148
@ NO_ERROR
Success.
Definition: error.h:44
@ ERROR_BUFFER_OVERFLOW
Definition: error.h:142
@ ERROR_READ_FAILED
Definition: error.h:222
@ ERROR_INVALID_TAG
Definition: error.h:114
@ ERROR_INCONSISTENT_VALUE
Definition: error.h:124
MIB-II module.
#define MIB2_SNMP_INC_COUNTER32(name, value)
Definition: mib2_module.h:192
@ MIB_ROW_STATUS_UNUSED
Definition: mib_common.h:102
@ MIB_ROW_STATUS_NOT_READY
Definition: mib_common.h:105
@ MIB_TYPE_TIME_TICKS
Definition: mib_common.h:64
uint8_t p
Definition: ndp.h:300
uint8_t m
Definition: ndp.h:304
TCP/IP stack core.
#define netMutex
Definition: net_legacy.h:195
OID (Object Identifier)
#define OID_MORE_FLAG
Definition: oid.h:38
#define osMemmove(dest, src, length)
Definition: os_port.h:147
#define osMemcpy(dest, src, length)
Definition: os_port.h:141
#define osStrlen(s)
Definition: os_port.h:165
#define osStrncmp(s1, s2, length)
Definition: os_port.h:177
#define TRUE
Definition: os_port.h:50
#define FALSE
Definition: os_port.h:46
void osAcquireMutex(OsMutex *mutex)
Acquire ownership of the specified mutex object.
void osReleaseMutex(OsMutex *mutex)
Release ownership of the specified mutex object.
#define osGetSystemTime64()
uint32_t systime_t
System time.
SNMP agent (Simple Network Management Protocol)
#define SnmpAgentContext
Definition: snmp_agent.h:36
#define SNMP_AGENT_MAX_MIBS
Definition: snmp_agent.h:69
#define SNMP_AGENT_MAX_COMMUNITIES
Definition: snmp_agent.h:76
error_t snmpEncodeUnsignedInt32(uint32_t value, uint8_t *dest, size_t *length)
Encode a 32-bit unsigned integer.
void snmpLockMib(SnmpAgentContext *context)
Lock MIB bases.
error_t snmpParseVarBinding(const uint8_t *p, size_t length, SnmpVarBind *var, size_t *consumed)
Parse variable binding.
error_t snmpWriteVarBinding(SnmpAgentContext *context, const SnmpVarBind *var)
Write variable binding.
error_t snmpTranslateStatusCode(SnmpMessage *message, error_t status, uint_t index)
Translate status code.
error_t snmpWriteTrapVarBindingList(SnmpAgentContext *context, uint_t genericTrapType, uint_t specificTrapCode, const SnmpTrapObject *objectList, uint_t objectListSize)
Format the variable binding list for Trap-PDU or SNMPv2-Trap-PDU.
SnmpUserEntry * snmpFindCommunityEntry(SnmpAgentContext *context, const char_t *community, size_t length)
Search the community table for a given community string.
void snmpUnlockMib(SnmpAgentContext *context)
Unlock MIB bases.
SnmpUserEntry * snmpCreateCommunityEntry(SnmpAgentContext *context)
Create a new community entry.
error_t snmpCopyVarBindingList(SnmpAgentContext *context)
Copy the list of variable bindings.
Helper functions for SNMP agent.
error_t snmpGetObjectValue(SnmpAgentContext *context, const SnmpMessage *message, SnmpVarBind *var)
Retrieve object value.
MIB object access.
@ SNMP_VERSION_1
Definition: snmp_common.h:138
@ SNMP_VERSION_3
Definition: snmp_common.h:140
@ SNMP_VERSION_2C
Definition: snmp_common.h:139
@ SNMP_ERROR_INCONSISTENT_VALUE
Definition: snmp_common.h:196
@ SNMP_ERROR_TOO_BIG
Definition: snmp_common.h:185
@ SNMP_ERROR_GENERIC
Definition: snmp_common.h:189
@ SNMP_ERROR_WRONG_VALUE
Definition: snmp_common.h:194
@ SNMP_ERROR_WRONG_TYPE
Definition: snmp_common.h:191
@ SNMP_ERROR_NO_SUCH_NAME
Definition: snmp_common.h:186
@ SNMP_ERROR_WRONG_LENGTH
Definition: snmp_common.h:192
@ SNMP_ERROR_NOT_WRITABLE
Definition: snmp_common.h:201
@ SNMP_ERROR_WRONG_ENCODING
Definition: snmp_common.h:193
@ SNMP_ERROR_NO_ACCESS
Definition: snmp_common.h:190
@ SNMP_ERROR_NONE
Definition: snmp_common.h:184
@ SNMP_ERROR_BAD_VALUE
Definition: snmp_common.h:187
@ SNMP_ERROR_AUTHORIZATION
Definition: snmp_common.h:200
@ SNMP_TRAP_ENTERPRISE_SPECIFIC
Definition: snmp_common.h:174
ASN.1 tag.
Definition: asn1.h:102
size_t totalLength
Definition: asn1.h:108
const uint8_t * value
Definition: asn1.h:107
uint_t objClass
Definition: asn1.h:104
uint_t objType
Definition: asn1.h:105
bool_t constructed
Definition: asn1.h:103
size_t length
Definition: asn1.h:106
SNMP message.
Object descriptor for trap notifications.
uint8_t oid[SNMP_MAX_OID_SIZE]
User table entry.
Variable binding.
const uint8_t * value
const uint8_t * oid
uint8_t length
Definition: tcp.h:368