EthernetNetIf

Dependents:   XBee_WiFi_EA_LPC4088

Committer:
hmike
Date:
Wed Nov 19 12:00:42 2014 +0000
Revision:
0:62580107d20c
EthernetNetIf

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hmike 0:62580107d20c 1
hmike 0:62580107d20c 2 /*
hmike 0:62580107d20c 3 Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
hmike 0:62580107d20c 4
hmike 0:62580107d20c 5 Permission is hereby granted, free of charge, to any person obtaining a copy
hmike 0:62580107d20c 6 of this software and associated documentation files (the "Software"), to deal
hmike 0:62580107d20c 7 in the Software without restriction, including without limitation the rights
hmike 0:62580107d20c 8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
hmike 0:62580107d20c 9 copies of the Software, and to permit persons to whom the Software is
hmike 0:62580107d20c 10 furnished to do so, subject to the following conditions:
hmike 0:62580107d20c 11
hmike 0:62580107d20c 12 The above copyright notice and this permission notice shall be included in
hmike 0:62580107d20c 13 all copies or substantial portions of the Software.
hmike 0:62580107d20c 14
hmike 0:62580107d20c 15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
hmike 0:62580107d20c 16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
hmike 0:62580107d20c 17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
hmike 0:62580107d20c 18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
hmike 0:62580107d20c 19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
hmike 0:62580107d20c 20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
hmike 0:62580107d20c 21 THE SOFTWARE.
hmike 0:62580107d20c 22 */
hmike 0:62580107d20c 23
hmike 0:62580107d20c 24 #ifndef LWIPNETTCPSOCKET_H
hmike 0:62580107d20c 25 #define LWIPNETTCPSOCKET_H
hmike 0:62580107d20c 26
hmike 0:62580107d20c 27 #define NET_LWIP_STACK 1
hmike 0:62580107d20c 28 #include "if/net/nettcpsocket.h"
hmike 0:62580107d20c 29 #include "LwipNetIf.h"
hmike 0:62580107d20c 30
hmike 0:62580107d20c 31 #include "stdint.h"
hmike 0:62580107d20c 32
hmike 0:62580107d20c 33 //Implements NetTcpSockets over lwIP raw API
hmike 0:62580107d20c 34
hmike 0:62580107d20c 35 struct tcp_pcb; //Represents a Tcp Connection, "Protocol Control Block", see rawapi.txt & tcp.h
hmike 0:62580107d20c 36 struct pbuf; //Lwip Buffer Container
hmike 0:62580107d20c 37
hmike 0:62580107d20c 38 typedef signed char err_t;
hmike 0:62580107d20c 39 typedef uint16_t u16_t;
hmike 0:62580107d20c 40
hmike 0:62580107d20c 41 class LwipNetTcpSocket: public NetTcpSocket
hmike 0:62580107d20c 42 {
hmike 0:62580107d20c 43 public:
hmike 0:62580107d20c 44 LwipNetTcpSocket(tcp_pcb* pPcb = NULL); //Passes a pcb if already created (by an accept req for instance), in that case transfers ownership
hmike 0:62580107d20c 45 virtual ~LwipNetTcpSocket();
hmike 0:62580107d20c 46
hmike 0:62580107d20c 47 virtual NetTcpSocketErr bind(const Host& me);
hmike 0:62580107d20c 48 virtual NetTcpSocketErr listen();
hmike 0:62580107d20c 49 virtual NetTcpSocketErr connect(const Host& host);
hmike 0:62580107d20c 50 virtual NetTcpSocketErr accept(Host* pClient, NetTcpSocket** ppNewNetTcpSocket);
hmike 0:62580107d20c 51
hmike 0:62580107d20c 52 virtual int /*if < 0 : NetTcpSocketErr*/ send(const char* buf, int len);
hmike 0:62580107d20c 53 virtual int /*if < 0 : NetTcpSocketErr*/ recv(char* buf, int len);
hmike 0:62580107d20c 54
hmike 0:62580107d20c 55 virtual NetTcpSocketErr close();
hmike 0:62580107d20c 56
hmike 0:62580107d20c 57 virtual NetTcpSocketErr poll();
hmike 0:62580107d20c 58
hmike 0:62580107d20c 59 protected:
hmike 0:62580107d20c 60 volatile tcp_pcb* m_pPcb;
hmike 0:62580107d20c 61
hmike 0:62580107d20c 62 //Events callbacks from lwIp
hmike 0:62580107d20c 63 err_t acceptCb(tcp_pcb* newpcb, err_t err);
hmike 0:62580107d20c 64 err_t connectedCb(tcp_pcb* tpcb, err_t err);
hmike 0:62580107d20c 65
hmike 0:62580107d20c 66 void errCb(err_t err);
hmike 0:62580107d20c 67
hmike 0:62580107d20c 68 err_t sentCb(tcp_pcb* tpcb, u16_t len);
hmike 0:62580107d20c 69 err_t recvCb(tcp_pcb* tpcb, pbuf *p, err_t err);
hmike 0:62580107d20c 70
hmike 0:62580107d20c 71 private:
hmike 0:62580107d20c 72 void cleanUp(); //Flush input buffer
hmike 0:62580107d20c 73
hmike 0:62580107d20c 74 // queue<tcp_pcb*> m_lpInPcb; //Incoming connections that have not been accepted yet
hmike 0:62580107d20c 75 queue<LwipNetTcpSocket*> m_lpInNetTcpSocket; //Incoming connections that have not been accepted yet
hmike 0:62580107d20c 76
hmike 0:62580107d20c 77 volatile pbuf* m_pReadPbuf; //Ptr to read buffer
hmike 0:62580107d20c 78
hmike 0:62580107d20c 79 //Static callbacks : Transforms into a C++ callback
hmike 0:62580107d20c 80 static err_t sAcceptCb(void *arg, struct tcp_pcb *newpcb, err_t err);
hmike 0:62580107d20c 81 static err_t sConnectedCb(void *arg, struct tcp_pcb *tpcb, err_t err);
hmike 0:62580107d20c 82
hmike 0:62580107d20c 83 static void sErrCb(void *arg, err_t err);
hmike 0:62580107d20c 84
hmike 0:62580107d20c 85 static err_t sSentCb(void *arg, struct tcp_pcb *tpcb, u16_t len);
hmike 0:62580107d20c 86 static err_t sRecvCb(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err);
hmike 0:62580107d20c 87
hmike 0:62580107d20c 88 };
hmike 0:62580107d20c 89
hmike 0:62580107d20c 90 #endif