masa haru / EthernetNetIf

Dependents:   SNMPAgent HTTPServer think_speak_a cyassl-client ... more

Committer:
mamezu
Date:
Thu Dec 09 01:33:56 2010 +0000
Revision:
0:0f6c82fcde82

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mamezu 0:0f6c82fcde82 1
mamezu 0:0f6c82fcde82 2 /*
mamezu 0:0f6c82fcde82 3 Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
mamezu 0:0f6c82fcde82 4
mamezu 0:0f6c82fcde82 5 Permission is hereby granted, free of charge, to any person obtaining a copy
mamezu 0:0f6c82fcde82 6 of this software and associated documentation files (the "Software"), to deal
mamezu 0:0f6c82fcde82 7 in the Software without restriction, including without limitation the rights
mamezu 0:0f6c82fcde82 8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
mamezu 0:0f6c82fcde82 9 copies of the Software, and to permit persons to whom the Software is
mamezu 0:0f6c82fcde82 10 furnished to do so, subject to the following conditions:
mamezu 0:0f6c82fcde82 11
mamezu 0:0f6c82fcde82 12 The above copyright notice and this permission notice shall be included in
mamezu 0:0f6c82fcde82 13 all copies or substantial portions of the Software.
mamezu 0:0f6c82fcde82 14
mamezu 0:0f6c82fcde82 15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
mamezu 0:0f6c82fcde82 16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
mamezu 0:0f6c82fcde82 17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
mamezu 0:0f6c82fcde82 18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
mamezu 0:0f6c82fcde82 19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
mamezu 0:0f6c82fcde82 20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
mamezu 0:0f6c82fcde82 21 THE SOFTWARE.
mamezu 0:0f6c82fcde82 22 */
mamezu 0:0f6c82fcde82 23
mamezu 0:0f6c82fcde82 24 #ifndef LWIPNETUDPSOCKET_H
mamezu 0:0f6c82fcde82 25 #define LWIPNETUDPSOCKET_H
mamezu 0:0f6c82fcde82 26
mamezu 0:0f6c82fcde82 27 #define NET_LWIP_STACK 1
mamezu 0:0f6c82fcde82 28 //#include "lwip/ip_addr.h"
mamezu 0:0f6c82fcde82 29 #include "if/net/netudpsocket.h"
mamezu 0:0f6c82fcde82 30 #include "LwipNetIf.h"
mamezu 0:0f6c82fcde82 31
mamezu 0:0f6c82fcde82 32 #include "stdint.h"
mamezu 0:0f6c82fcde82 33
mamezu 0:0f6c82fcde82 34 #include <list>
mamezu 0:0f6c82fcde82 35 using std::list;
mamezu 0:0f6c82fcde82 36
mamezu 0:0f6c82fcde82 37 //Implements NetUdpSockets over lwIP raw API
mamezu 0:0f6c82fcde82 38
mamezu 0:0f6c82fcde82 39 struct udp_pcb; //Represents a Udp Connection, "Protocol Control Block", see rawapi.txt & udp.h
mamezu 0:0f6c82fcde82 40 struct pbuf; //Lwip Buffer Container
mamezu 0:0f6c82fcde82 41 typedef struct ip_addr ip_addr_t;
mamezu 0:0f6c82fcde82 42
mamezu 0:0f6c82fcde82 43 //typedef signed char err_t;
mamezu 0:0f6c82fcde82 44 typedef uint16_t u16_t;
mamezu 0:0f6c82fcde82 45
mamezu 0:0f6c82fcde82 46 class LwipNetUdpSocket: public NetUdpSocket
mamezu 0:0f6c82fcde82 47 {
mamezu 0:0f6c82fcde82 48 public:
mamezu 0:0f6c82fcde82 49 LwipNetUdpSocket(udp_pcb* pPcb = NULL); //Passes a pcb if already created (by an accept req for instance), in that case transfers ownership
mamezu 0:0f6c82fcde82 50 virtual ~LwipNetUdpSocket();
mamezu 0:0f6c82fcde82 51
mamezu 0:0f6c82fcde82 52 virtual NetUdpSocketErr bind(const Host& me);
mamezu 0:0f6c82fcde82 53
mamezu 0:0f6c82fcde82 54 virtual int /*if < 0 : NetUdpSocketErr*/ sendto(const char* buf, int len, Host* pHost);
mamezu 0:0f6c82fcde82 55 virtual int /*if < 0 : NetUdpSocketErr*/ recvfrom(char* buf, int len, Host* pHost);
mamezu 0:0f6c82fcde82 56
mamezu 0:0f6c82fcde82 57 virtual NetUdpSocketErr close();
mamezu 0:0f6c82fcde82 58
mamezu 0:0f6c82fcde82 59 virtual NetUdpSocketErr poll();
mamezu 0:0f6c82fcde82 60
mamezu 0:0f6c82fcde82 61 protected:
mamezu 0:0f6c82fcde82 62 volatile udp_pcb* m_pPcb;
mamezu 0:0f6c82fcde82 63
mamezu 0:0f6c82fcde82 64 //Event callback from lwIp
mamezu 0:0f6c82fcde82 65 void recvCb(udp_pcb* pcb, struct pbuf* p, ip_addr_t* addr, u16_t port);
mamezu 0:0f6c82fcde82 66
mamezu 0:0f6c82fcde82 67 private:
mamezu 0:0f6c82fcde82 68 void cleanUp(); //Flush input buffer
mamezu 0:0f6c82fcde82 69 struct InPacket
mamezu 0:0f6c82fcde82 70 {
mamezu 0:0f6c82fcde82 71 volatile pbuf* pBuf;
mamezu 0:0f6c82fcde82 72 ip_addr_t addr;
mamezu 0:0f6c82fcde82 73 u16_t port;
mamezu 0:0f6c82fcde82 74 };
mamezu 0:0f6c82fcde82 75
mamezu 0:0f6c82fcde82 76 list<InPacket> m_lInPkt;
mamezu 0:0f6c82fcde82 77 IpAddr m_multicastGroup;
mamezu 0:0f6c82fcde82 78
mamezu 0:0f6c82fcde82 79 //Static callback : Transforms into a C++ callback
mamezu 0:0f6c82fcde82 80 static void sRecvCb(void *arg, struct udp_pcb *pcb, struct pbuf *p, ip_addr_t *addr, u16_t port);
mamezu 0:0f6c82fcde82 81
mamezu 0:0f6c82fcde82 82 };
mamezu 0:0f6c82fcde82 83
mamezu 0:0f6c82fcde82 84 #endif