fork allowing use of the latest official mbed networking library

Dependents:   SNMPv1UDPExmaple

Fork of Agentbed by Suga koubou

Files at this revision

API Documentation at this revision

Comitter:
jonecm
Date:
Tue Apr 02 19:53:28 2013 +0000
Parent:
2:9e4369522e03
Commit message:
Updated to be compatible with the MBED official networking stack

Changed in this revision

Agentbed.cpp Show annotated file Show diff for this revision Revisions of this file
Agentbed.h Show annotated file Show diff for this revision Revisions of this file
--- a/Agentbed.cpp	Fri Jan 28 09:17:03 2011 +0000
+++ b/Agentbed.cpp	Tue Apr 02 19:53:28 2013 +0000
@@ -28,7 +28,7 @@
 
 #include "Agentbed.h"
 
-SNMP_API_STAT_CODES AgentbedClass::begin(EthernetNetIf *eth)
+SNMP_API_STAT_CODES SNMP::init()
 {
     // set community names
     _getCommName = "public";
@@ -38,15 +38,10 @@
     _setSize = strlen(_setCommName);
     _getSize = strlen(_getCommName);
     //
-    // init UDP socket
-    udpsock = new UDPSocket;
-    udpsock->setOnEvent(this, &AgentbedClass::listen);
-    udpsock->bind(Host(eth->getIp(), SNMP_DEFAULT_PORT));
-    //
     return SNMP_API_STAT_SUCCESS;
 }
 
-SNMP_API_STAT_CODES AgentbedClass::begin(char *getCommName, char *setCommName, uint16_t port, EthernetNetIf *eth)
+SNMP_API_STAT_CODES SNMP::init(char *getCommName, char *setCommName)
 {
     // set community name set/get sizes
     _setSize = strlen(setCommName);
@@ -61,29 +56,11 @@
     _getCommName = getCommName;
     _setCommName = setCommName;
     //
-    // validate session port number
-    if ( port == NULL || port == 0 ) port = SNMP_DEFAULT_PORT;
-    //
-    // init UDP socket
-    udpsock = new UDPSocket;
-    udpsock->setOnEvent(this, &AgentbedClass::listen);
-    udpsock->bind(Host(eth->getIp(), port));
-    //
+    
     return SNMP_API_STAT_SUCCESS;
 }
 
-void AgentbedClass::listen (UDPSocketEvent e)
-{
-    // if bytes available in receive buffer
-    // and pointer to a function (delegate function)
-    // isn't null, trigger the function
-    if (e == UDPSOCKET_READABLE && _callback != NULL ) {
-        (*_callback)();
-    }
-}
-
-
-SNMP_API_STAT_CODES AgentbedClass::requestPdu(SNMP_PDU *pdu)
+SNMP_API_STAT_CODES SNMP::toPdu(SNMP_PDU *pdu,char *_packet,uint16_t _packetSize)
 {
     char *community;
     // sequence length
@@ -102,15 +79,14 @@
     byte obiLen, obiEnd;
     byte __attribute__((__unused__)) valTyp, valLen, valEnd;
     byte i;
-    Host dest;
     //
     // set packet packet size (skip UDP header)
 //    _packetSize = Udp.available()-8;
     //
-    memset(_packet, 0, SNMP_MAX_PACKET_LEN);
+ //   memset(_packet, 0, SNMP_MAX_PACKET_LEN);
     //
     // get UDP packet
-    _packetSize = udpsock->recvfrom((char*)_packet, SNMP_MAX_PACKET_LEN, &_dst);
+ ///  _packetSize = udpsock->recvfrom((char*)_packet, SNMP_MAX_PACKET_LEN, &_dst);
     //
     // validate packet
     if ( _packetSize != 0 && _packetSize > SNMP_MAX_PACKET_LEN ) {
@@ -298,9 +274,10 @@
     return SNMP_API_STAT_SUCCESS;
 }
 
-SNMP_API_STAT_CODES AgentbedClass::responsePdu(SNMP_PDU *pdu)
+uint16_t SNMP::fromPdu(SNMP_PDU *pdu,char *_packet)
 {
     int32_u u;
+    uint16_t _packetSize;
     byte i;
     //
     // Length of entire SNMP packet
@@ -399,21 +376,16 @@
         _packet[_packetPos++] = pdu->VALUE.data[i];
     }
     //
-    udpsock->sendto((char*)_packet, _packetPos, &_dst);
     //
     //SNMP_FREE(_packet);
     //
-    return SNMP_API_STAT_SUCCESS;
+    return _packetSize;
 }
 
 
 
-void AgentbedClass::onPduReceive(onPduReceiveCallback pduReceived)
-{
-    _callback = pduReceived;
-}
 
-void AgentbedClass::freePdu(SNMP_PDU *pdu)
+void SNMP::freePdu(SNMP_PDU *pdu)
 {
     //SNMP_FREE(pdu->OID.oid);
     //SNMP_FREE(pdu->VALUE.value);
@@ -423,4 +395,4 @@
 }
 
 // Create one global object
-//AgentbedClass Agentbed;
+//SNMP Agentbed;
--- a/Agentbed.h	Fri Jan 28 09:17:03 2011 +0000
+++ b/Agentbed.h	Tue Apr 02 19:53:28 2013 +0000
@@ -35,7 +35,6 @@
 //Frees a pointer only if it is !NULL and sets its value to NULL. 
 
 #include "mbed.h"
-#include "EthernetNetIf.h"
 #include "UDPSocket.h"
 #include <stdlib.h>
 
@@ -544,33 +543,26 @@
     SNMP_VALUE VALUE;
 } SNMP_PDU;
 
-class AgentbedClass {
+class SNMP {
 public:
     // Agent functions
-    SNMP_API_STAT_CODES begin(EthernetNetIf *eth);
-    SNMP_API_STAT_CODES begin(char *getCommName, char *setCommName, uint16_t port, EthernetNetIf *eth);
-    void listen(UDPSocketEvent);
-    SNMP_API_STAT_CODES requestPdu(SNMP_PDU *pdu);
-    SNMP_API_STAT_CODES responsePdu(SNMP_PDU *pdu);
-    void onPduReceive(onPduReceiveCallback pduReceived);
+    SNMP_API_STAT_CODES init();
+    SNMP_API_STAT_CODES init(char *getCommName, char *setCommName);
+    SNMP_API_STAT_CODES toPdu(  SNMP_PDU *pdu,char *_packet,uint16_t _packetSize);
+    uint16_t             fromPdu(SNMP_PDU *pdu,char *_packet);
     void freePdu(SNMP_PDU *pdu);
 
     // Helper functions
 
 private:
-    byte _packet[SNMP_MAX_PACKET_LEN];
-    uint16_t _packetSize;
     uint16_t _packetPos;
     SNMP_PDU_TYPES _dstType;
     char *_getCommName;
     size_t _getSize;
     char *_setCommName;
     size_t _setSize;
-    onPduReceiveCallback _callback;
-    UDPSocket *udpsock;
-    Host _dst;
 };
 
-//extern AgentbedClass Agentbed;
+//extern SNMP Agentbed;
 
 #endif