1 #ifdef BRCM_SNMP_SUPPORT
3 #include <net-snmp/net-snmp-config.h>
12 #include <net-snmp/net-snmp-includes.h>
13 #include <net-snmp/agent/net-snmp-agent-includes.h>
15 #include <net-snmp/agent/scalar.h>
16 #include <net-snmp/agent/instance.h>
17 #include <net-snmp/agent/serialize.h>
18 #include <net-snmp/agent/read_only.h>
24 /** @defgroup scalar scalar: process scalars easily.
29 netsnmp_get_scalar_handler(void)
31 return netsnmp_create_handler("scalar",
32 netsnmp_scalar_helper_handler);
36 netsnmp_register_scalar(netsnmp_handler_registration *reginfo)
39 * Extend the registered OID with space for the instance subid
40 * (but don't extend the length just yet!)
42 reginfo->rootoid = realloc(reginfo->rootoid,
43 (reginfo->rootoid_len+1) * sizeof(oid) );
44 reginfo->rootoid[ reginfo->rootoid_len ] = 0;
46 netsnmp_inject_handler(reginfo, netsnmp_get_instance_handler());
47 netsnmp_inject_handler(reginfo, netsnmp_get_scalar_handler());
48 return netsnmp_register_serialize(reginfo);
52 netsnmp_register_read_only_scalar(netsnmp_handler_registration *reginfo)
55 * Extend the registered OID with space for the instance subid
56 * (but don't extend the length just yet!)
58 reginfo->rootoid = realloc(reginfo->rootoid,
59 (reginfo->rootoid_len+1) * sizeof(oid) );
60 reginfo->rootoid[ reginfo->rootoid_len ] = 0;
62 netsnmp_inject_handler(reginfo, netsnmp_get_instance_handler());
63 netsnmp_inject_handler(reginfo, netsnmp_get_scalar_handler());
64 netsnmp_inject_handler(reginfo, netsnmp_get_read_only_handler());
65 return netsnmp_register_serialize(reginfo);
71 netsnmp_scalar_helper_handler(netsnmp_mib_handler *handler,
72 netsnmp_handler_registration *reginfo,
73 netsnmp_agent_request_info *reqinfo,
74 netsnmp_request_info *requests)
77 netsnmp_variable_list *var = requests->requestvb;
82 DEBUGMSGTL(("helper:scalar", "Got request:\n"));
83 namelen = SNMP_MIN(requests->requestvb->name_length,
84 reginfo->rootoid_len);
85 cmp = snmp_oid_compare(requests->requestvb->name, namelen,
86 reginfo->rootoid, reginfo->rootoid_len);
88 DEBUGMSGTL(("helper:scalar", " oid:", cmp));
89 DEBUGMSGOID(("helper:scalar", var->name, var->name_length));
90 DEBUGMSG(("helper:scalar", "\n"));
92 switch (reqinfo->mode) {
95 netsnmp_set_request_error(reqinfo, requests,
97 return SNMP_ERR_NOERROR;
99 reginfo->rootoid_len++;
100 ret = netsnmp_call_next_handler(handler, reginfo, reqinfo,
102 reginfo->rootoid_len--;
107 case MODE_SET_RESERVE1:
108 case MODE_SET_RESERVE2:
109 case MODE_SET_ACTION:
110 case MODE_SET_COMMIT:
114 netsnmp_set_request_error(reqinfo, requests,
115 SNMP_ERR_NOCREATION);
116 return SNMP_ERR_NOERROR;
118 reginfo->rootoid_len++;
119 ret = netsnmp_call_next_handler(handler, reginfo, reqinfo,
121 reginfo->rootoid_len--;
127 reginfo->rootoid_len++;
128 ret = netsnmp_call_next_handler(handler, reginfo, reqinfo, requests);
129 reginfo->rootoid_len--;
133 * got here only if illegal mode found
135 return SNMP_ERR_GENERR;
141 #endif /* BRCM_SNMP_SUPPORT */