I have tried using the tcpip_callback to have the tcpip thread context.
I still have the memalloc problem.
This is my new file.
#include "lwip/opt.h"
#if LWIP_SNMP
#include "lwip/inet.h"
#include "lwip/snmp_msg.h"
#include "lwip/snmp_asn1.h"
#include "lwip/tcpip.h"
#include "Printf.h"
#include "private_trap.h"
#define NUM_PRIVATE_TRAP 10
static unsigned char SNMP_TRAP_0_FLAG = 1;
static struct ip_addr SNMP_TRAP_0_ADDR;
extern struct snmp_msg_trap trap_msg;
struct private_trap
{
/* source enterprise ID (sysObjectID) */
struct snmp_obj_id *enterprise;
/* trap ID */
struct snmp_obj_id *trap_oid;
/* specific trap code */
u32_t spc_trap;
/* object value ASN1 type */
u8_t value_type;
/* object value length (in u8_t) */
u8_t value_len;
/* object value */
void *value;
/* indicate that the trap is sent */
u8_t in_use;
};
struct private_trap trap_bank[NUM_PRIVATE_TRAP];
struct private_trap * getNextFreePrivateTrap()
{
u8_t index;
void * result = NULL;
for(index = 0; index < NUM_PRIVATE_TRAP; index++)
{
if(!trap_bank[index].in_use)
{
trap_bank[index].in_use = 1;
result = &trap_bank[index];
break;
}
}
return result;
}
void freePrivateTrap(struct private_trap * trap)
{
trap->enterprise = NULL;
trap->trap_oid = NULL;
trap->value = NULL;
trap->in_use = 0;
}
void vSendTrapCallback( void * parameters )
{
struct private_trap * trapToSend;
struct snmp_varbind * vb;
if( parameters != NULL )
{
trapToSend = (struct private_trap *) parameters;
vb = snmp_varbind_alloc(trapToSend->enterprise,
trapToSend->value_type,
trapToSend->value_len);
vb->value = trapToSend->value;
trap_msg.outvb.head = vb;
trap_msg.outvb.tail = vb;
trap_msg.outvb.count = 1;
snmp_send_trap(SNMP_GENTRAP_ENTERPRISESPC, trapToSend->trap_oid,
trapToSend->spc_trap);
trap_msg.outvb.head = NULL;
trap_msg.outvb.tail = NULL;
trap_msg.outvb.count = 0;
vb->value = NULL;
snmp_varbind_free(vb);
freePrivateTrap(trapToSend);
}
}
void vSNMP_Trap_Init( )
{
/* Set SNMP Trap destination */
IP4_ADDR( &SNMP_TRAP_0_ADDR, 172, 27, 37, 70);
snmp_trap_dst_ip_set(0,&SNMP_TRAP_0_ADDR);
snmp_trap_dst_enable(0,SNMP_TRAP_0_FLAG);
}
void vSendTrapTask( void * pvParameters )
{
portTickType xLastWakeTime;
struct snmp_obj_id objid = {MY_SNMP_SYSOBJID_LEN, MY_SNMP_SYSOBJID};
static unsigned char msg[] = "[email protected]";
static unsigned char msglen= 22;
struct private_trap * trap;
(void) pvParameters;
for ( ;; )
{
xLastWakeTime = xTaskGetTickCount();
trap = getNextFreePrivateTrap();
if(trap != NULL)
{
trap->enterprise = &objid;
trap->trap_oid = &objid;
trap->spc_trap = 1;
trap->value_type = SNMP_ASN1_OPAQUE;
trap->value_len = msglen;
trap->value = &msg;
tcpip_callback(vSendTrapCallback, trap);
}
// Wait for the next cycle.
vTaskDelayUntil( &xLastWakeTime, 10 );
}
}
#endif//LWIP_SNMP
_______________________________________________
lwip-users mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/lwip-users