|
From: | Yigal Hochberg |
Subject: | Re: [lwip-users] LWIP SNMPv1 howto |
Date: | Sun, 23 Jun 2019 11:27:25 -0400 |
_______________________________________________Dear LWIP users,
I’m a new in lwip snmp, but I made my private MIB and private_mib.c
This is very simple lwip example, but doesnot work.
Could you guide to me what’s wrong.
When I check lwip source code , simple application does not exist?
I think that simple example code must be exist.
If any one help us , I will made simple example.
Regards,
Steven.
///////////////////// enet_lwip.c ///////////////////////////
int
main(void)
{
…
udp_init();
//snmp_mib2_set_syscontact_readonly((const u8_t*)"root", NULL);
// snmp_set_sysobjid(&my_object_id);
#if LWIP_SNMP
snmp_init();
#endif
..
}
///////////////////// private_mib.c ///////////////////////////
#ifndef __PRIVATE_MIB_H__
#define __PRIVATE_MIB_H__
#if LWIP_SNMP
extern const struct mib_array_node mib_private;
//void lwip_privmib_init(void);
//#define SNMP_PRIVATE_MIB_INIT() lwip_privmib_init()
#endif
#endif /* PRIVATE_MIB_H_ */
///////////////////// private_mib.c ///////////////////////////
#include "lwipopts.h"
#include "private_mib.h"
#include "lwip/opt.h"
#include "lwip/snmp_msg.h"
#include "lwip/snmp_asn1.h"
#include "lwip/snmp_structs.h"
#include <stdbool.h>
#include <stdint.h>
#include "utils/ustdlib.h"
#include "utils/uartstdio.h"
#define PSU_ENTERPRISE_ID 26390
#define NUM_OF_OUTLETS 4
// returns the definition of the object
void OUTLET_get_obj_def(u8_t id_len, s32_t *id, struct obj_def *rv);
// returns the value of the object
void OUTLET_get_obj_val(struct obj_def *oid, u16_t length, void *value);
/******************************************************************************
* BACON_get_obj_def
* Description: Sets the object definition for the sensors
* Parameters: u8_t id_len - length of branch id being given to us
* s32_t *ident - pointer to array holding the id
struct obj_def *rv - struct we are returning our answer to
* Returns: through *rv, the definition of the object scalar being queried
******************************************************************************/
void OUTLET_get_obj_def(u8_t id_len, s32_t *id, struct obj_def *rv)
{
u8_t oid = 0;
char pcBuf[16];
LWIP_UNUSED_ARG(id);
LWIP_UNUSED_ARG(id_len);
LWIP_UNUSED_ARG(rv);
id_len += 1;
id -= 1;
//LWIP_ASSERT("invalid id", (id[0] >= 0) && (id[0] <= 0xff));
#if 1
oid = (u8_t)id[0];
usprintf(pcBuf, "OUTLET_get_obj_def oid:%d\r\n", oid);
UARTprintf(pcBuf);
rv->id_inst_len = id_len;
rv->id_inst_ptr = id;
rv->instance = MIB_OBJECT_SCALAR;
rv->access = MIB_OBJECT_READ_WRITE;
rv->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);
rv->v_len = sizeof(u32_t);
/*
if (id_len == 2) {
rv->id_inst_len = id_len;
rv->id_inst_ptr = id;
oid = (u8_t)id[0];
LWIP_DEBUGF(SNMP_MIB_DEBUG,("\r\nBACON_get_obj_def: no scalar\r\n"));
usprintf(pcBuf, "id:%d", oid);
UARTprintf(pcBuf);
switch(oid) {
}
}else {
LWIP_DEBUGF(SNMP_MIB_DEBUG,("\r\nBACON_get_obj_def: no scalar\r\n"));
rv->instance = MIB_OBJECT_NONE;
}
*/
#else
LWIP_DEBUGF(SNMP_MIB_DEBUG,("\r\nBACON_get_obj_def: no scalar\r\n"));
rv->instance = MIB_OBJECT_NONE;
#endif
}
/******************************************************************************
* BACON_get_obj_val
* Description: Sets the returned value for the sensors
* Parameters: struct obj_def *od - object found from obj_def
* u16_t length - the length of what we are being asked (in bytes)
* void *value - points to (varbind) space to copy value into
* Returns: in *value
*/
void OUTLET_get_obj_val(struct obj_def *od, u16_t length, void *value)
{
u8_t oid = 0;
u32_t *int_ptr = (u32_t*)value;
char pcBuf[16];
//LWIP_ASSERT("invalid id", (od->id_inst_ptr[0] >=0) && (od->id_inst_ptr[0] <= NUM_OF_OUTLETS));
oid = (u8_t)od->id_inst_ptr[0];
usprintf(pcBuf, "OUTLET_get_obj_val oid:%d\r\n", oid);
UARTprintf(pcBuf);
switch(oid) {
case 1: // OUTLET 1
*int_ptr = 0;
break;
case 2: // OUTLET 2
*int_ptr = 0;
break;
case 3: // OUTLET 3
*int_ptr = 0;
break;
case 4: // OUTLET 4
*int_ptr = 0;
break;
default:
break;
}
}
static u8_t OUTLET_set_test(struct obj_def *od, u16_t length, void *value)
{
u8_t id, set_ok;
char pcBuf[16];
set_ok = 0;
id = od->id_inst_ptr[0];
usprintf(pcBuf, "OUTLET_set_test id:%d\r\n", id);
UARTprintf(pcBuf);
switch(id){
case 1:
case 2:
set_ok = 1;
break;
default:
break;
}
return set_ok;
}
static void OUTLET_set_value(struct obj_def *od, u16_t length, void *value)
{
u8_t id;
u32_t val = *((u32_t *)value);
char pcBuf[16];
id = od->id_inst_ptr[0];
usprintf(pcBuf, "OUTLET_set_value id:%d, val:%d\r\n", id, val);
UARTprintf(pcBuf);
switch(id){
case 1:
break;
case 2:
break;
}
}
/********************************************************************
* MIB structures
*******************************************************************/
// defines the scalars used to return sensor values.
const mib_scalar_node OUTLET_status = {
&OUTLET_get_obj_def,
&OUTLET_get_obj_val,
&OUTLET_set_test,
&OUTLET_set_value,
MIB_NODE_SC,
0
};
// The OIDs for the sensor scalars.
const s32_t OUTLET_status_oids[4] = { 1, 2, 3, 4 };
// The actual structure that holds the nodes.
struct mib_node* const OUTLET_status_nodes[4] = {
(struct mib_node*)&OUTLET_status,
(struct mib_node*)&OUTLET_status,
(struct mib_node*)&OUTLET_status,
(struct mib_node*)&OUTLET_status
};
// performs the linkage to the enterprise branch.
const struct mib_array_node mib_olzetek = {
&noleafs_get_object_def,
&noleafs_get_value,
&noleafs_set_test,
&noleafs_set_value,
MIB_NODE_AR,
4,
OUTLET_status_oids,
OUTLET_status_nodes
};
// 1.3.6.1.4.1.4444
// defines PSU_ENTERPRISE_ID
const s32_t private_oids[1] = { PSU_ENTERPRISE_ID };
struct mib_node* const private_nodes[1] = {(struct mib_node*)&mib_olzetek};
// performs the linkage to the enterprise branch.
const struct mib_array_node mib_enterprise = {
&noleafs_get_object_def,
&noleafs_get_value,
&noleafs_set_test,
&noleafs_set_value,
MIB_NODE_AR,
1,
private_oids,
private_nodes
};
// 1.3.6.1.4.1
// links our mibs to the private branch
const s32_t ent_oids[1] = { 1 };
struct mib_node* const ent_nodes[1] = { (struct mib_node*)&mib_enterprise };
const struct mib_array_node mib_private = {
&noleafs_get_object_def,
&noleafs_get_value,
&noleafs_set_test,
&noleafs_set_value,
MIB_NODE_AR,
1,
ent_oids,
ent_nodes
};
///////////// OLZE.MIB //////
-- MIB created 06/13, by kisung cho
-- olzetek inc
-- This file defines the mib struct of Management in Olzetek Product
----------------------------------------------------------------------
OLZETEK-MIB DEFINITIONS ::= BEGIN
IMPORTS
OBJECT-TYPE, MODULE-IDENTITY, Integer32, enterprises
FROM SNMPv2-SMI
DisplayString
FROM SNMPv2-TC;
olzeMIB MODULE-IDENTITY
LAST-UPDATED "20190613"
ORGANIZATION "olzetek"
CONTACT-INFO "olzetek"
REVISION "20190613"
DESCRIPTION "olzetek mib"
::= { enterprises 26390 }
outlet1Status OBJECT-TYPE
SYNTAX INTEGER { off(1), on(2), pending(3), reboot(4)}
ACCESS read-write
STATUS mandatory
DESCRIPTION
"Display and control outlet 1 status. Can't set pending status."
::= { olzeMIB 1 }
outlet2Status OBJECT-TYPE
SYNTAX INTEGER { off(1), on(2), pending(3), reboot(4)}
ACCESS read-write
STATUS mandatory
DESCRIPTION
"Display and control outlet 2 status. Can't set pending status."
::= { olzeMIB 2 }
outlet3Status OBJECT-TYPE
SYNTAX INTEGER { off(1), on(2), pending(3), reboot(4)}
ACCESS read-write
STATUS mandatory
DESCRIPTION
"Display and control outlet 3 status. Can't set pending status."
::= { olzeMIB 3 }
outlet4Status OBJECT-TYPE
SYNTAX INTEGER { off(1), on(2), pending(3), reboot(4)}
ACCESS read-write
STATUS mandatory
DESCRIPTION
"Display and control outlet 3 status. Can't set pending status."
::= { olzeMIB 4 }
END
lwip-users mailing list
address@hidden
https://lists.nongnu.org/mailman/listinfo/lwip-users
[Prev in Thread] | Current Thread | [Next in Thread] |