First step: AutoIP compiled in and working

Dependencies:   mbed

Committer:
darran
Date:
Fri Jun 18 09:11:35 2010 +0000
Revision:
0:55a05330f8cc

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
darran 0:55a05330f8cc 1
darran 0:55a05330f8cc 2 /*
darran 0:55a05330f8cc 3 Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
darran 0:55a05330f8cc 4
darran 0:55a05330f8cc 5 Permission is hereby granted, free of charge, to any person obtaining a copy
darran 0:55a05330f8cc 6 of this software and associated documentation files (the "Software"), to deal
darran 0:55a05330f8cc 7 in the Software without restriction, including without limitation the rights
darran 0:55a05330f8cc 8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
darran 0:55a05330f8cc 9 copies of the Software, and to permit persons to whom the Software is
darran 0:55a05330f8cc 10 furnished to do so, subject to the following conditions:
darran 0:55a05330f8cc 11
darran 0:55a05330f8cc 12 The above copyright notice and this permission notice shall be included in
darran 0:55a05330f8cc 13 all copies or substantial portions of the Software.
darran 0:55a05330f8cc 14
darran 0:55a05330f8cc 15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
darran 0:55a05330f8cc 16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
darran 0:55a05330f8cc 17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
darran 0:55a05330f8cc 18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
darran 0:55a05330f8cc 19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
darran 0:55a05330f8cc 20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
darran 0:55a05330f8cc 21 THE SOFTWARE.
darran 0:55a05330f8cc 22 */
darran 0:55a05330f8cc 23
darran 0:55a05330f8cc 24 #ifndef NET_H
darran 0:55a05330f8cc 25 #define NET_H
darran 0:55a05330f8cc 26
darran 0:55a05330f8cc 27 class NetIf;
darran 0:55a05330f8cc 28 class NetTcpSocket;
darran 0:55a05330f8cc 29 class NetUdpSocket;
darran 0:55a05330f8cc 30 class NetDnsRequest;
darran 0:55a05330f8cc 31
darran 0:55a05330f8cc 32 #include <list>
darran 0:55a05330f8cc 33 using std::list;
darran 0:55a05330f8cc 34
darran 0:55a05330f8cc 35 #include "host.h"
darran 0:55a05330f8cc 36 #include "ipaddr.h"
darran 0:55a05330f8cc 37 #include "netif.h"
darran 0:55a05330f8cc 38 #include "nettcpsocket.h"
darran 0:55a05330f8cc 39 #include "netudpsocket.h"
darran 0:55a05330f8cc 40 #include "netservice.h"
darran 0:55a05330f8cc 41 #include "netdnsrequest.h"
darran 0:55a05330f8cc 42
darran 0:55a05330f8cc 43 class Net
darran 0:55a05330f8cc 44 {
darran 0:55a05330f8cc 45 private:
darran 0:55a05330f8cc 46 Net();
darran 0:55a05330f8cc 47 ~Net();
darran 0:55a05330f8cc 48 public:
darran 0:55a05330f8cc 49 static void poll(); //Poll every if & socket
darran 0:55a05330f8cc 50
darran 0:55a05330f8cc 51 static NetTcpSocket* tcpSocket(NetIf& netif);
darran 0:55a05330f8cc 52 static NetTcpSocket* tcpSocket(); //Socket on default if
darran 0:55a05330f8cc 53 static void releaseTcpSocket(NetTcpSocket* pNetTcpSocket);
darran 0:55a05330f8cc 54
darran 0:55a05330f8cc 55 static NetUdpSocket* udpSocket(NetIf& netif);
darran 0:55a05330f8cc 56 static NetUdpSocket* udpSocket(); //Socket on default if
darran 0:55a05330f8cc 57 static void releaseUdpSocket(NetUdpSocket* pNetUdpSocket);
darran 0:55a05330f8cc 58
darran 0:55a05330f8cc 59 static NetDnsRequest* dnsRequest(const char* hostname, NetIf& netif);
darran 0:55a05330f8cc 60 static NetDnsRequest* dnsRequest(const char* hostname); //Create a new NetDnsRequest object from default if
darran 0:55a05330f8cc 61
darran 0:55a05330f8cc 62 static NetDnsRequest* dnsRequest(Host* pHost, NetIf& netif);
darran 0:55a05330f8cc 63 static NetDnsRequest* dnsRequest(Host* pHost); //Create a new NetDnsRequest object from default if
darran 0:55a05330f8cc 64
darran 0:55a05330f8cc 65 static void setDefaultIf(NetIf& netif); //Deprecated
darran 0:55a05330f8cc 66 static void setDefaultIf(NetIf* pIf);
darran 0:55a05330f8cc 67 static NetIf* getDefaultIf();
darran 0:55a05330f8cc 68
darran 0:55a05330f8cc 69 //TODO: Factory functions like 'setupEthernet', 'setupPPP', 'setupTelit' ...
darran 0:55a05330f8cc 70 #if 0
darran 0:55a05330f8cc 71 enum NetErr //Generic errors
darran 0:55a05330f8cc 72 {
darran 0:55a05330f8cc 73 __NET_MIN = -0xFFFF;
darran 0:55a05330f8cc 74 NET_OPEN, //Could not open if
darran 0:55a05330f8cc 75 NET_CONNECT, //Could not connect
darran 0:55a05330f8cc 76 NET_AUTH, //Could not auth
darran 0:55a05330f8cc 77 NET_HW, //HW problem
darran 0:55a05330f8cc 78
darran 0:55a05330f8cc 79 NET_OK = 0
darran 0:55a05330f8cc 80 };
darran 0:55a05330f8cc 81
darran 0:55a05330f8cc 82 static NetErr Ethernet();
darran 0:55a05330f8cc 83 static NetErr PPPoverSerial(int Tx, int Rx, const char* apn, const char* user, const char* password);
darran 0:55a05330f8cc 84 static NetErr Telit(int pwrSetPin, int pwrMonPin, int Tx, int Rx);
darran 0:55a05330f8cc 85 #endif
darran 0:55a05330f8cc 86
darran 0:55a05330f8cc 87 protected:
darran 0:55a05330f8cc 88 friend class NetIf;
darran 0:55a05330f8cc 89 friend class NetTcpSocket;
darran 0:55a05330f8cc 90 friend class NetUdpSocket;
darran 0:55a05330f8cc 91
darran 0:55a05330f8cc 92 static void registerIf(NetIf* pIf);
darran 0:55a05330f8cc 93 static void unregisterIf(NetIf* pIf);
darran 0:55a05330f8cc 94
darran 0:55a05330f8cc 95 static void registerNetTcpSocket(NetTcpSocket* pNetTcpSocket);
darran 0:55a05330f8cc 96 static void unregisterNetTcpSocket(NetTcpSocket* pNetTcpSocket);
darran 0:55a05330f8cc 97
darran 0:55a05330f8cc 98 static void registerNetUdpSocket(NetUdpSocket* pNetUdpSocket);
darran 0:55a05330f8cc 99 static void unregisterNetUdpSocket(NetUdpSocket* pNetUdpSocket);
darran 0:55a05330f8cc 100
darran 0:55a05330f8cc 101 private:
darran 0:55a05330f8cc 102 static Net& net(); //Return inst of singleton
darran 0:55a05330f8cc 103
darran 0:55a05330f8cc 104 NetIf* m_defaultIf;
darran 0:55a05330f8cc 105
darran 0:55a05330f8cc 106 list<NetIf*> m_lpIf;
darran 0:55a05330f8cc 107 list<NetTcpSocket*> m_lpNetTcpSocket;
darran 0:55a05330f8cc 108 list<NetUdpSocket*> m_lpNetUdpSocket;
darran 0:55a05330f8cc 109 };
darran 0:55a05330f8cc 110
darran 0:55a05330f8cc 111 #endif