Kenji Arai / mbed-os_TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers lwip_snmp_mib2_snmp.c Source File

lwip_snmp_mib2_snmp.c

Go to the documentation of this file.
00001 /**
00002  * @file
00003  * Management Information Base II (RFC1213) SNMP objects and functions.
00004  */
00005 
00006 /*
00007  * Copyright (c) 2006 Axon Digital Design B.V., The Netherlands.
00008  * All rights reserved.
00009  *
00010  * Redistribution and use in source and binary forms, with or without modification,
00011  * are permitted provided that the following conditions are met:
00012  *
00013  * 1. Redistributions of source code must retain the above copyright notice,
00014  *    this list of conditions and the following disclaimer.
00015  * 2. Redistributions in binary form must reproduce the above copyright notice,
00016  *    this list of conditions and the following disclaimer in the documentation
00017  *    and/or other materials provided with the distribution.
00018  * 3. The name of the author may not be used to endorse or promote products
00019  *    derived from this software without specific prior written permission.
00020  *
00021  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
00022  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00023  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
00024  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00025  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
00026  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00027  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00028  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
00029  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
00030  * OF SUCH DAMAGE.
00031  *
00032  * Author: Dirk Ziegelmeier <dziegel@gmx.de>
00033  *         Christiaan Simons <christiaan.simons@axon.tv>
00034  */
00035 
00036 #include "lwip/snmp.h"
00037 #include "lwip/apps/snmp.h"
00038 #include "lwip/apps/snmp_core.h"
00039 #include "lwip/apps/snmp_mib2.h"
00040 #include "lwip/apps/snmp_scalar.h"
00041 
00042 #if LWIP_SNMP && SNMP_LWIP_MIB2
00043 
00044 #define MIB2_AUTH_TRAPS_ENABLED  1
00045 #define MIB2_AUTH_TRAPS_DISABLED 2
00046 
00047 /* --- snmp .1.3.6.1.2.1.11 ----------------------------------------------------- */
00048 static s16_t
00049 snmp_get_value(const struct snmp_scalar_array_node_def *node, void *value)
00050 {
00051   u32_t *uint_ptr = (u32_t *)value;
00052   switch (node->oid) {
00053     case 1: /* snmpInPkts */
00054       *uint_ptr = snmp_stats.inpkts;
00055       break;
00056     case 2: /* snmpOutPkts */
00057       *uint_ptr = snmp_stats.outpkts;
00058       break;
00059     case 3: /* snmpInBadVersions */
00060       *uint_ptr = snmp_stats.inbadversions;
00061       break;
00062     case 4: /* snmpInBadCommunityNames */
00063       *uint_ptr = snmp_stats.inbadcommunitynames;
00064       break;
00065     case 5: /* snmpInBadCommunityUses */
00066       *uint_ptr = snmp_stats.inbadcommunityuses;
00067       break;
00068     case 6: /* snmpInASNParseErrs */
00069       *uint_ptr = snmp_stats.inasnparseerrs;
00070       break;
00071     case 8: /* snmpInTooBigs */
00072       *uint_ptr = snmp_stats.intoobigs;
00073       break;
00074     case 9: /* snmpInNoSuchNames */
00075       *uint_ptr = snmp_stats.innosuchnames;
00076       break;
00077     case 10: /* snmpInBadValues */
00078       *uint_ptr = snmp_stats.inbadvalues;
00079       break;
00080     case 11: /* snmpInReadOnlys */
00081       *uint_ptr = snmp_stats.inreadonlys;
00082       break;
00083     case 12: /* snmpInGenErrs */
00084       *uint_ptr = snmp_stats.ingenerrs;
00085       break;
00086     case 13: /* snmpInTotalReqVars */
00087       *uint_ptr = snmp_stats.intotalreqvars;
00088       break;
00089     case 14: /* snmpInTotalSetVars */
00090       *uint_ptr = snmp_stats.intotalsetvars;
00091       break;
00092     case 15: /* snmpInGetRequests */
00093       *uint_ptr = snmp_stats.ingetrequests;
00094       break;
00095     case 16: /* snmpInGetNexts */
00096       *uint_ptr = snmp_stats.ingetnexts;
00097       break;
00098     case 17: /* snmpInSetRequests */
00099       *uint_ptr = snmp_stats.insetrequests;
00100       break;
00101     case 18: /* snmpInGetResponses */
00102       *uint_ptr = snmp_stats.ingetresponses;
00103       break;
00104     case 19: /* snmpInTraps */
00105       *uint_ptr = snmp_stats.intraps;
00106       break;
00107     case 20: /* snmpOutTooBigs */
00108       *uint_ptr = snmp_stats.outtoobigs;
00109       break;
00110     case 21: /* snmpOutNoSuchNames */
00111       *uint_ptr = snmp_stats.outnosuchnames;
00112       break;
00113     case 22: /* snmpOutBadValues */
00114       *uint_ptr = snmp_stats.outbadvalues;
00115       break;
00116     case 24: /* snmpOutGenErrs */
00117       *uint_ptr = snmp_stats.outgenerrs;
00118       break;
00119     case 25: /* snmpOutGetRequests */
00120       *uint_ptr = snmp_stats.outgetrequests;
00121       break;
00122     case 26: /* snmpOutGetNexts */
00123       *uint_ptr = snmp_stats.outgetnexts;
00124       break;
00125     case 27: /* snmpOutSetRequests */
00126       *uint_ptr = snmp_stats.outsetrequests;
00127       break;
00128     case 28: /* snmpOutGetResponses */
00129       *uint_ptr = snmp_stats.outgetresponses;
00130       break;
00131     case 29: /* snmpOutTraps */
00132       *uint_ptr = snmp_stats.outtraps;
00133       break;
00134     case 30: /* snmpEnableAuthenTraps */
00135       if (snmp_get_auth_traps_enabled() == SNMP_AUTH_TRAPS_DISABLED) {
00136         *uint_ptr = MIB2_AUTH_TRAPS_DISABLED;
00137       } else {
00138         *uint_ptr = MIB2_AUTH_TRAPS_ENABLED;
00139       }
00140       break;
00141     case 31: /* snmpSilentDrops */
00142       *uint_ptr = 0; /* not supported */
00143       break;
00144     case 32: /* snmpProxyDrops */
00145       *uint_ptr = 0; /* not supported */
00146       break;
00147     default:
00148       LWIP_DEBUGF(SNMP_MIB_DEBUG, ("snmp_get_value(): unknown id: %"S32_F"\n", node->oid));
00149       return 0;
00150   }
00151 
00152   return sizeof(*uint_ptr);
00153 }
00154 
00155 static snmp_err_t
00156 snmp_set_test(const struct snmp_scalar_array_node_def *node, u16_t len, void *value)
00157 {
00158   snmp_err_t ret = SNMP_ERR_WRONGVALUE;
00159   LWIP_UNUSED_ARG(len);
00160 
00161   if (node->oid == 30) {
00162     /* snmpEnableAuthenTraps */
00163     s32_t *sint_ptr = (s32_t *)value;
00164 
00165     /* we should have writable non-volatile mem here */
00166     if ((*sint_ptr == MIB2_AUTH_TRAPS_DISABLED) || (*sint_ptr == MIB2_AUTH_TRAPS_ENABLED)) {
00167       ret = SNMP_ERR_NOERROR;
00168     }
00169   }
00170   return ret;
00171 }
00172 
00173 static snmp_err_t
00174 snmp_set_value(const struct snmp_scalar_array_node_def *node, u16_t len, void *value)
00175 {
00176   LWIP_UNUSED_ARG(len);
00177 
00178   if (node->oid == 30) {
00179     /* snmpEnableAuthenTraps */
00180     s32_t *sint_ptr = (s32_t *)value;
00181     if (*sint_ptr == MIB2_AUTH_TRAPS_DISABLED) {
00182       snmp_set_auth_traps_enabled(SNMP_AUTH_TRAPS_DISABLED);
00183     } else {
00184       snmp_set_auth_traps_enabled(SNMP_AUTH_TRAPS_ENABLED);
00185     }
00186   }
00187 
00188   return SNMP_ERR_NOERROR;
00189 }
00190 
00191 /* the following nodes access variables in SNMP stack (snmp_stats) from SNMP worker thread -> OK, no sync needed */
00192 static const struct snmp_scalar_array_node_def snmp_nodes[] = {
00193   { 1, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY},  /* snmpInPkts */
00194   { 2, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY},  /* snmpOutPkts */
00195   { 3, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY},  /* snmpInBadVersions */
00196   { 4, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY},  /* snmpInBadCommunityNames */
00197   { 5, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY},  /* snmpInBadCommunityUses */
00198   { 6, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY},  /* snmpInASNParseErrs */
00199   { 8, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY},  /* snmpInTooBigs */
00200   { 9, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY},  /* snmpInNoSuchNames */
00201   {10, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY},  /* snmpInBadValues */
00202   {11, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY},  /* snmpInReadOnlys */
00203   {12, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY},  /* snmpInGenErrs */
00204   {13, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY},  /* snmpInTotalReqVars */
00205   {14, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY},  /* snmpInTotalSetVars */
00206   {15, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY},  /* snmpInGetRequests */
00207   {16, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY},  /* snmpInGetNexts */
00208   {17, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY},  /* snmpInSetRequests */
00209   {18, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY},  /* snmpInGetResponses */
00210   {19, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY},  /* snmpInTraps */
00211   {20, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY},  /* snmpOutTooBigs */
00212   {21, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY},  /* snmpOutNoSuchNames */
00213   {22, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY},  /* snmpOutBadValues */
00214   {24, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY},  /* snmpOutGenErrs */
00215   {25, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY},  /* snmpOutGetRequests */
00216   {26, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY},  /* snmpOutGetNexts */
00217   {27, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY},  /* snmpOutSetRequests */
00218   {28, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY},  /* snmpOutGetResponses */
00219   {29, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY},  /* snmpOutTraps */
00220   {30, SNMP_ASN1_TYPE_INTEGER, SNMP_NODE_INSTANCE_READ_WRITE}, /* snmpEnableAuthenTraps */
00221   {31, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY},  /* snmpSilentDrops */
00222   {32, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY}   /* snmpProxyDrops */
00223 };
00224 
00225 const struct snmp_scalar_array_node snmp_mib2_snmp_root = SNMP_SCALAR_CREATE_ARRAY_NODE(11, snmp_nodes, snmp_get_value, snmp_set_test, snmp_set_value);
00226 
00227 #endif /* LWIP_SNMP && SNMP_LWIP_MIB2 */