NetServices Stack source

Dependents:   HelloWorld ServoInterfaceBoardExample1 4180_Lab4

Files at this revision

API Documentation at this revision

Comitter:
donatien
Date:
Thu Aug 05 14:32:43 2010 +0000
Parent:
8:93fa3cfc0219
Child:
10:d098e9192450
Commit message:

Changed in this revision

api/DNSRequest.cpp Show annotated file Show diff for this revision Revisions of this file
api/DNSRequest.h Show annotated file Show diff for this revision Revisions of this file
api/TCPSocket.cpp Show annotated file Show diff for this revision Revisions of this file
api/TCPSocket.h Show annotated file Show diff for this revision Revisions of this file
api/UDPSocket.cpp Show annotated file Show diff for this revision Revisions of this file
api/UDPSocket.h Show annotated file Show diff for this revision Revisions of this file
core/host.h Show annotated file Show diff for this revision Revisions of this file
core/ipaddr.cpp Show annotated file Show diff for this revision Revisions of this file
core/ipaddr.h Show annotated file Show diff for this revision Revisions of this file
core/net.cpp Show annotated file Show diff for this revision Revisions of this file
core/net.h Show annotated file Show diff for this revision Revisions of this file
core/netservice.cpp Show annotated file Show diff for this revision Revisions of this file
core/netservice.h Show annotated file Show diff for this revision Revisions of this file
drv/gprsmodule/GPRSModule.cpp Show diff for this revision Revisions of this file
drv/gprsmodule/GPRSModule.h Show diff for this revision Revisions of this file
drv/gprsmodule/TelitModule.cpp Show annotated file Show diff for this revision Revisions of this file
drv/gprsmodule/TelitModule.h Show annotated file Show diff for this revision Revisions of this file
drv/serial/buf/SerialBuf.cpp Show annotated file Show diff for this revision Revisions of this file
if/eth/EthernetNetIf.h Show annotated file Show diff for this revision Revisions of this file
if/gprsmodule/GPRSModuleNetIf.cpp Show annotated file Show diff for this revision Revisions of this file
if/gprsmodule/GPRSModuleNetIf.h Show annotated file Show diff for this revision Revisions of this file
if/gprsmodule/HuaweiGTM900NetIf.cpp Show annotated file Show diff for this revision Revisions of this file
if/gprsmodule/HuaweiGTM900NetIf.h Show annotated file Show diff for this revision Revisions of this file
if/gprsmodule/TelitModuleNetIf.cpp Show annotated file Show diff for this revision Revisions of this file
if/gprsmodule/TelitModuleNetIf.h Show annotated file Show diff for this revision Revisions of this file
if/lwip/LwipNetIf.cpp Show annotated file Show diff for this revision Revisions of this file
if/lwip/LwipNetIf.h Show annotated file Show diff for this revision Revisions of this file
if/lwip/lwipNetTcpSocket.h Show annotated file Show diff for this revision Revisions of this file
if/lwip/lwipNetUdpSocket.cpp Show annotated file Show diff for this revision Revisions of this file
if/lwip/lwipNetUdpSocket.h Show annotated file Show diff for this revision Revisions of this file
if/net/host.h Show diff for this revision Revisions of this file
if/net/ipaddr.h Show diff for this revision Revisions of this file
if/net/net.cpp Show diff for this revision Revisions of this file
if/net/net.h Show diff for this revision Revisions of this file
if/net/netdnsrequest.cpp Show annotated file Show diff for this revision Revisions of this file
if/net/netif.cpp Show annotated file Show diff for this revision Revisions of this file
if/net/netif.h Show annotated file Show diff for this revision Revisions of this file
if/net/netservice.cpp Show diff for this revision Revisions of this file
if/net/netservice.h Show diff for this revision Revisions of this file
if/ppp/PPPNetIf.cpp Show annotated file Show diff for this revision Revisions of this file
if/umtsstick/UMTSStickNetIf.h Show annotated file Show diff for this revision Revisions of this file
lwip/lwipopts.h Show annotated file Show diff for this revision Revisions of this file
netCfg.h Show annotated file Show diff for this revision Revisions of this file
services/email/smtp/SMTPClient.h Show annotated file Show diff for this revision Revisions of this file
services/http/client/HTTPClient.cpp Show annotated file Show diff for this revision Revisions of this file
services/http/client/HTTPClient.h Show annotated file Show diff for this revision Revisions of this file
services/http/client/HTTPData.h Show annotated file Show diff for this revision Revisions of this file
services/http/client/data/HTTPFile.cpp Show annotated file Show diff for this revision Revisions of this file
services/http/client/data/HTTPFile.h Show annotated file Show diff for this revision Revisions of this file
services/http/client/data/HTTPMap.h Show annotated file Show diff for this revision Revisions of this file
services/http/client/data/HTTPStream.h Show annotated file Show diff for this revision Revisions of this file
services/http/client/data/HTTPText.h Show annotated file Show diff for this revision Revisions of this file
services/http/server/HTTPRequestDispatcher.cpp Show annotated file Show diff for this revision Revisions of this file
services/http/server/HTTPRequestDispatcher.h Show annotated file Show diff for this revision Revisions of this file
services/http/server/HTTPRequestHandler.cpp Show annotated file Show diff for this revision Revisions of this file
services/http/server/HTTPRequestHandler.h Show annotated file Show diff for this revision Revisions of this file
services/http/server/HTTPServer.h Show annotated file Show diff for this revision Revisions of this file
services/http/util/url.h Show annotated file Show diff for this revision Revisions of this file
services/mysql/MySQLClient.h Show annotated file Show diff for this revision Revisions of this file
services/ntp/NTPClient.h Show annotated file Show diff for this revision Revisions of this file
--- a/api/DNSRequest.cpp	Wed Jul 28 12:45:32 2010 +0000
+++ b/api/DNSRequest.cpp	Thu Aug 05 14:32:43 2010 +0000
@@ -22,6 +22,7 @@
 */
 
 #include "DNSRequest.h"
+#include "if/net/netdnsrequest.h"
 
 DNSRequest::DNSRequest() : m_pNetDnsRequest(NULL), m_pCbItem(NULL), m_pCbMeth(NULL), m_pCb(NULL)
 {
--- a/api/DNSRequest.h	Wed Jul 28 12:45:32 2010 +0000
+++ b/api/DNSRequest.h	Thu Aug 05 14:32:43 2010 +0000
@@ -28,7 +28,9 @@
 #ifndef DNSREQUEST_H
 #define DNSREQUEST_H
 
-#include "if/net/net.h"
+#include "core/net.h"
+#include "core/ipaddr.h"
+#include "core/host.h"
 //Essentially it is a safe interface to NetDnsRequest
 
 ///DNS Request error codes
@@ -54,6 +56,9 @@
   DNS_FOUND,
 };
 
+class NetDnsRequest;
+enum NetDnsReply;
+
 ///This is a simple DNS Request class
 /**
   This class exposes an API to deal with DNS Requests
--- a/api/TCPSocket.cpp	Wed Jul 28 12:45:32 2010 +0000
+++ b/api/TCPSocket.cpp	Thu Aug 05 14:32:43 2010 +0000
@@ -22,6 +22,7 @@
 */
 
 #include "TCPSocket.h"
+#include "if/net/nettcpsocket.h"
 
 TCPSocket::TCPSocket() : m_pNetTcpSocket(NULL), m_pCbItem(NULL), m_pCbMeth(NULL), m_pCb(NULL)
 {
--- a/api/TCPSocket.h	Wed Jul 28 12:45:32 2010 +0000
+++ b/api/TCPSocket.h	Thu Aug 05 14:32:43 2010 +0000
@@ -28,7 +28,8 @@
 #ifndef TCPSOCKET_H
 #define TCPSOCKET_H
 
-#include "if/net/net.h"
+#include "core/net.h"
+#include "core/host.h"
 //Essentially it is a safe interface to NetTcpSocket
 
 ///TCP Socket error codes
@@ -60,6 +61,9 @@
   TCPSOCKET_DISCONNECTED ///<Disconnected
 };
 
+class NetTcpSocket;
+enum NetTcpSocketEvent;
+
 ///This is a simple TCP Socket class
 /**
   This class exposes an API to deal with TCP Sockets
--- a/api/UDPSocket.cpp	Wed Jul 28 12:45:32 2010 +0000
+++ b/api/UDPSocket.cpp	Thu Aug 05 14:32:43 2010 +0000
@@ -22,6 +22,7 @@
 */
 
 #include "UDPSocket.h"
+#include "if/net/netudpsocket.h"
 
 UDPSocket::UDPSocket() : m_pNetUdpSocket(NULL), m_pCbItem(NULL), m_pCbMeth(NULL), m_pCb(NULL)
 {
--- a/api/UDPSocket.h	Wed Jul 28 12:45:32 2010 +0000
+++ b/api/UDPSocket.h	Thu Aug 05 14:32:43 2010 +0000
@@ -28,7 +28,8 @@
 #ifndef UDPSOCKET_H
 #define UDPSOCKET_H
 
-#include "if/net/net.h"
+#include "core/net.h"
+#include "core/host.h"
 //Essentially it is a safe interface to NetUdpSocket
 
 ///UDP Socket error codes
@@ -49,6 +50,9 @@
   UDPSOCKET_READABLE, ///<Data in buf
 };
 
+class NetUdpSocket;
+enum NetUdpSocketEvent;
+
 ///This is a simple UDP Socket class
 /**
   This class exposes an API to deal with UDP Sockets
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/core/host.h	Thu Aug 05 14:32:43 2010 +0000
@@ -0,0 +1,109 @@
+
+/*
+Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
+ 
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+ 
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+ 
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+*/
+
+#ifndef HOST_H
+#define HOST_H
+
+#include "ipaddr.h"
+#include <string.h>
+
+///Host information container
+/**
+This class is a container for data relative to a connection:
+- IP Address
+- Port number
+- Host Name
+*/
+class Host 
+{
+public:
+  ///Initiliazes host with null values
+  Host() : m_ip(0,0,0,0), m_port(0), m_name(NULL)
+  {
+    
+  }
+  
+  ///Initializes host
+  Host(const IpAddr& ip, const int& port, const char* name="" ) : m_ip(ip), m_port(port), m_name(NULL)
+  {
+    setName(name); 
+  }
+  
+  ~Host()
+  {
+    if(m_name)
+    {
+      delete[] m_name;
+    }
+  }
+  
+  ///Returns IP address
+  const IpAddr& getIp() const
+  {
+    return m_ip;
+  }
+  
+  ///Returns port number
+  const int& getPort() const
+  {
+    return m_port;
+  }
+  
+  ///Returns host name
+  const char* getName() const
+  {
+    return m_name;
+  }
+  
+  ///Sets IP address
+  void setIp(const IpAddr& ip)
+  {
+    m_ip = ip;
+  }
+  
+  ///Sets port number
+  void setPort(int port)
+  {
+    m_port = port;
+  }
+  
+  ///Sets host name
+  void setName(const char* name)
+  {
+    if(m_name)
+      delete[] m_name;
+    int len = strlen(name);
+    if(len)
+    {
+      m_name = new char[len+1];
+      strcpy(m_name, name);
+    }
+  }
+  
+private:
+  IpAddr m_ip;
+  int m_port;
+  char* m_name;
+};
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/core/ipaddr.cpp	Thu Aug 05 14:32:43 2010 +0000
@@ -0,0 +1,104 @@
+
+/*
+Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
+ 
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+ 
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+ 
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+*/
+
+#include "ipaddr.h"
+
+#include "netCfg.h"
+#if NET_LWIP_STACK
+#include "lwip/ip_addr.h"
+#endif
+
+
+#if NET_LWIP_STACK
+IpAddr::IpAddr(ip_addr_t* pIp)
+{
+  *((uint32_t*)m_ip) = pIp->addr;
+}
+#endif
+
+///Initializes IP address with provided values
+IpAddr::IpAddr(uint8_t ip0, uint8_t ip1, uint8_t ip2, uint8_t ip3)
+{
+  //We are in LE
+  m_ip[0] = ip0;
+  m_ip[1] = ip1;
+  m_ip[2] = ip2;
+  m_ip[3] = ip3;
+}
+
+///Initializes IP address with null values 
+IpAddr::IpAddr()
+{
+  m_ip[0] = 0;
+  m_ip[1] = 0;
+  m_ip[2] = 0;
+  m_ip[3] = 0;
+}
+
+
+#if NET_LWIP_STACK
+ip_addr_t IpAddr::getStruct() const
+{
+  ip_addr_t ip_struct;
+  ip_struct.addr = *((uint32_t*)m_ip);
+  return ip_struct;
+}
+#endif
+
+uint8_t IpAddr::operator[](unsigned int i) const
+{
+  uint8_t null = 0;
+  if( i > 3 )
+    return null;
+  return m_ip[i];
+}
+
+bool IpAddr::isEq(const IpAddr& b) const
+{
+  return (*((uint32_t*)m_ip) == *((uint32_t*)(b.m_ip)));
+}
+
+bool IpAddr::operator==(const IpAddr& b) const
+{
+  return isEq(b);
+}
+ 
+bool IpAddr::operator!=(const IpAddr& b) const
+{
+  return !(operator==(b));
+}
+
+bool IpAddr::isNull() const
+{
+  return (*((uint32_t*)m_ip) == 0);
+}
+
+bool IpAddr::isBroadcast() const
+{
+  return (*((uint32_t*)m_ip) == 0xFFFFFFFF);
+}
+
+bool IpAddr::isMulticast() const
+{
+  return ((m_ip[0] & 0xF0) == 0xE0);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/core/ipaddr.h	Thu Aug 05 14:32:43 2010 +0000
@@ -0,0 +1,98 @@
+
+/*
+Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
+ 
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+ 
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+ 
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+*/
+
+#ifndef IPADDR_H
+#define IPADDR_H
+
+#include "netCfg.h"
+#if NET_LWIP_STACK
+typedef struct ip_addr ip_addr_t;
+#endif
+
+#include "stdint.h"
+
+///IP Address container
+/**
+This class is a container for an IPv4 address.
+*/
+class IpAddr //Basically a C++ frontend to ip_addr_t
+{
+public:
+  #if NET_LWIP_STACK
+  IpAddr(ip_addr_t* pIp);
+  #endif
+  
+  ///Initializes IP address with provided values
+  IpAddr(uint8_t ip0, uint8_t ip1, uint8_t ip2, uint8_t ip3);
+  
+  ///Initializes IP address with null values 
+  IpAddr();
+
+  #if NET_LWIP_STACK
+  ip_addr_t getStruct() const;
+  #endif
+  
+  ///Returns IP address byte #
+  uint8_t operator[](unsigned int i) const;
+  
+  ///Compares too addresses
+  /**
+  @return true if the two addresses are equal
+  */
+  bool isEq(const IpAddr& b) const;
+  
+  ///Compares too addresses
+  /**
+  @return true if the two addresses are equal
+  */
+  bool operator==(const IpAddr& b) const;
+ 
+  ///Compares too addresses
+  /**
+  @return true if the two addresses are different
+  */ 
+  bool operator!=(const IpAddr& b) const;
+  
+  ///Checks whether the address is null
+  /**
+  @return true if the address is null
+  */
+  bool isNull() const;
+  
+  ///Checks whether the address is a broadcast address
+  /**
+  @return true if the address is a broadcast address
+  */
+  bool isBroadcast() const;
+
+  ///Checks whether the address is a multicast address
+  /**
+  @return true if the address is a multicast address
+  */
+  bool isMulticast() const;
+  
+private:
+  uint8_t m_ip[4];
+};
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/core/net.cpp	Thu Aug 05 14:32:43 2010 +0000
@@ -0,0 +1,229 @@
+
+/*
+Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
+ 
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+ 
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+ 
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+*/
+
+#include "net.h"
+
+#include "host.h"
+#include "ipaddr.h"
+#include "netservice.h"
+#include "if/net/netif.h"
+#include "if/net/nettcpsocket.h"
+#include "if/net/netudpsocket.h"
+#include "if/net/netdnsrequest.h"
+
+//#define __DEBUG
+#include "dbg/dbg.h"
+
+Net::Net() : m_defaultIf(NULL), m_lpIf(), m_lpNetTcpSocket(), m_lpNetUdpSocket()
+{
+
+}
+
+Net::~Net()
+{
+
+}
+
+
+void Net::poll()
+{
+  //DBG("\r\nNet : Services polling\r\n");
+
+  //Poll Services
+  NetService::servicesPoll();  
+  
+  //DBG("\r\nNet : Interfaces polling\r\n");   
+      
+  //Poll Interfaces
+  list<NetIf*>::iterator pIfIt;
+
+  for ( pIfIt = net().m_lpIf.begin() ; pIfIt != net().m_lpIf.end(); pIfIt++ )
+  {
+    (*pIfIt)->poll();
+  }
+  
+  //DBG("\r\nNet : Sockets polling\r\n");
+  
+  //Poll Tcp Sockets
+  list<NetTcpSocket*>::iterator pNetTcpSocketIt;
+
+  for ( pNetTcpSocketIt = net().m_lpNetTcpSocket.begin() ; pNetTcpSocketIt != net().m_lpNetTcpSocket.end(); )
+  {
+    (*pNetTcpSocketIt)->poll();
+    
+    if( (*pNetTcpSocketIt)->m_closed && !((*pNetTcpSocketIt)->m_refs) )
+    {
+      (*pNetTcpSocketIt)->m_removed = true;
+      delete (*pNetTcpSocketIt);
+      (*pNetTcpSocketIt) = NULL;
+      pNetTcpSocketIt = net().m_lpNetTcpSocket.erase(pNetTcpSocketIt);
+    }
+    else
+    {
+      pNetTcpSocketIt++;
+    }
+  }
+  
+  //Poll Udp Sockets
+  list<NetUdpSocket*>::iterator pNetUdpSocketIt;
+
+  for ( pNetUdpSocketIt = net().m_lpNetUdpSocket.begin() ; pNetUdpSocketIt != net().m_lpNetUdpSocket.end(); )
+  {
+    (*pNetUdpSocketIt)->poll();
+    
+    if( (*pNetUdpSocketIt)->m_closed && !((*pNetUdpSocketIt)->m_refs) )
+    {
+      (*pNetUdpSocketIt)->m_removed = true;
+      delete (*pNetUdpSocketIt);
+      (*pNetUdpSocketIt) = NULL;
+      pNetUdpSocketIt = net().m_lpNetUdpSocket.erase(pNetUdpSocketIt);
+    }
+    else
+    {
+      pNetUdpSocketIt++;
+    }
+  }
+
+
+}
+
+NetTcpSocket* Net::tcpSocket(NetIf& netif) {
+  NetTcpSocket* pNetTcpSocket = netif.tcpSocket();
+  pNetTcpSocket->m_refs++;
+  return pNetTcpSocket; 
+}
+
+NetTcpSocket* Net::tcpSocket() { //NetTcpSocket on default if
+ if ( net().m_defaultIf == NULL )
+      return NULL;
+  NetTcpSocket* pNetTcpSocket = net().m_defaultIf->tcpSocket();
+  pNetTcpSocket->m_refs++;
+  return pNetTcpSocket;
+}
+
+void Net::releaseTcpSocket(NetTcpSocket* pNetTcpSocket)
+{
+  pNetTcpSocket->m_refs--;
+  if(!pNetTcpSocket->m_closed && !pNetTcpSocket->m_refs)
+    pNetTcpSocket->close();
+}
+
+NetUdpSocket* Net::udpSocket(NetIf& netif) {
+  NetUdpSocket* pNetUdpSocket = netif.udpSocket();
+  pNetUdpSocket->m_refs++;
+  return pNetUdpSocket; 
+}
+
+NetUdpSocket* Net::udpSocket() { //NetTcpSocket on default if
+ if ( net().m_defaultIf == NULL )
+      return NULL;
+  NetUdpSocket* pNetUdpSocket = net().m_defaultIf->udpSocket();
+  pNetUdpSocket->m_refs++;
+  return pNetUdpSocket;
+}
+
+void Net::releaseUdpSocket(NetUdpSocket* pNetUdpSocket)
+{
+  pNetUdpSocket->m_refs--;
+  if(!pNetUdpSocket->m_closed && !pNetUdpSocket->m_refs)
+    pNetUdpSocket->close();
+}
+
+NetDnsRequest* Net::dnsRequest(const char* hostname, NetIf& netif) {
+  return netif.dnsRequest(hostname);
+}
+
+NetDnsRequest* Net::dnsRequest(const char* hostname) { //Create a new NetDnsRequest object from default if
+  if ( net().m_defaultIf == NULL )
+      return NULL;
+  return net().m_defaultIf->dnsRequest(hostname);
+}
+
+NetDnsRequest* Net::dnsRequest(Host* pHost, NetIf& netif)
+{
+  return netif.dnsRequest(pHost);
+}
+
+NetDnsRequest* Net::dnsRequest(Host* pHost) //Creats a new NetDnsRequest object from default if
+{
+  if ( net().m_defaultIf == NULL )
+      return NULL;
+  return net().m_defaultIf->dnsRequest(pHost);
+}
+
+void Net::setDefaultIf(NetIf& netif) {
+  net().m_defaultIf = &netif;
+}
+
+void Net::setDefaultIf(NetIf* pIf)
+{
+  net().m_defaultIf = pIf;
+}
+
+NetIf* Net::getDefaultIf() {
+  return net().m_defaultIf;
+}
+
+void Net::registerIf(NetIf* pIf)
+{
+  net().m_lpIf.push_back(pIf);
+}
+
+void Net::unregisterIf(NetIf* pIf)
+{
+  if( net().m_defaultIf == pIf )
+    net().m_defaultIf = NULL;
+  net().m_lpIf.remove(pIf);
+}
+
+void Net::registerNetTcpSocket(NetTcpSocket* pNetTcpSocket)
+{
+  net().m_lpNetTcpSocket.push_back(pNetTcpSocket);
+  DBG("\r\nNetTcpSocket [ + %p ] %d\r\n", (void*)pNetTcpSocket, net().m_lpNetTcpSocket.size());
+}
+
+void Net::unregisterNetTcpSocket(NetTcpSocket* pNetTcpSocket)
+{
+  DBG("\r\nNetTcpSocket [ - %p ] %d\r\n", (void*)pNetTcpSocket, net().m_lpNetTcpSocket.size() - 1);
+  if(!pNetTcpSocket->m_removed)
+    net().m_lpNetTcpSocket.remove(pNetTcpSocket);
+}
+
+void Net::registerNetUdpSocket(NetUdpSocket* pNetUdpSocket)
+{
+  net().m_lpNetUdpSocket.push_back(pNetUdpSocket);
+  DBG("\r\nNetUdpSocket [ + %p ] %d\r\n", (void*)pNetUdpSocket, net().m_lpNetUdpSocket.size());
+}
+
+void Net::unregisterNetUdpSocket(NetUdpSocket* pNetUdpSocket)
+{
+  DBG("\r\nNetUdpSocket [ - %p ] %d\r\n", (void*)pNetUdpSocket, net().m_lpNetUdpSocket.size() - 1);
+  if(!pNetUdpSocket->m_removed)
+    net().m_lpNetUdpSocket.remove(pNetUdpSocket);
+}
+
+Net& Net::net()
+{
+  static Net* pInst = new Net(); //Called only once
+  return *pInst;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/core/net.h	Thu Aug 05 14:32:43 2010 +0000
@@ -0,0 +1,101 @@
+
+/*
+Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
+ 
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+ 
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+ 
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+*/
+
+#ifndef NET_H
+#define NET_H
+
+class NetIf;
+class NetTcpSocket;
+class NetUdpSocket;
+class NetDnsRequest;
+
+#include <list>
+using std::list;
+
+/*
+#include "host.h"
+#include "ipaddr.h"
+#include "netservice.h"
+#include "if/net/netif.h"
+#include "if/net/nettcpsocket.h"
+#include "if/net/netudpsocket.h"
+#include "if/net/netdnsrequest.h"
+*/
+
+class Host;
+class NetIf;
+class NetTcpSocket;
+class NetUdpSocket;
+class NetDnsRequest;
+
+class Net
+{
+private:
+  Net();
+  ~Net();
+public:  
+  static void poll(); //Poll every if & socket
+  
+  static NetTcpSocket* tcpSocket(NetIf& netif);
+  static NetTcpSocket* tcpSocket(); //Socket on default if
+  static void releaseTcpSocket(NetTcpSocket* pNetTcpSocket);
+  
+  static NetUdpSocket* udpSocket(NetIf& netif);
+  static NetUdpSocket* udpSocket(); //Socket on default if
+  static void releaseUdpSocket(NetUdpSocket* pNetUdpSocket);
+  
+  static NetDnsRequest* dnsRequest(const char* hostname, NetIf& netif);
+  static NetDnsRequest* dnsRequest(const char* hostname); //Create a new NetDnsRequest object from default if
+
+  static NetDnsRequest* dnsRequest(Host* pHost, NetIf& netif);
+  static NetDnsRequest* dnsRequest(Host* pHost); //Create a new NetDnsRequest object from default if
+  
+  static void setDefaultIf(NetIf& netif); //Deprecated
+  static void setDefaultIf(NetIf* pIf);
+  static NetIf* getDefaultIf();
+  
+protected:
+  friend class NetIf;
+  friend class NetTcpSocket;
+  friend class NetUdpSocket;
+  
+  static void registerIf(NetIf* pIf);
+  static void unregisterIf(NetIf* pIf);
+  
+  static void registerNetTcpSocket(NetTcpSocket* pNetTcpSocket);
+  static void unregisterNetTcpSocket(NetTcpSocket* pNetTcpSocket);  
+  
+  static void registerNetUdpSocket(NetUdpSocket* pNetUdpSocket);
+  static void unregisterNetUdpSocket(NetUdpSocket* pNetUdpSocket);  
+  
+private:
+  static Net& net(); //Return inst of singleton
+
+  NetIf* m_defaultIf;
+  
+  list<NetIf*> m_lpIf;
+  list<NetTcpSocket*> m_lpNetTcpSocket;
+  list<NetUdpSocket*> m_lpNetUdpSocket;
+};
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/core/netservice.cpp	Thu Aug 05 14:32:43 2010 +0000
@@ -0,0 +1,88 @@
+
+/*
+Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
+ 
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+ 
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+ 
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+*/
+
+#include "netservice.h"
+#include "net.h"
+
+//#define __DEBUG
+#include "dbg/dbg.h"
+
+NetService::NetService(bool owned /*= true*/) : m_closed(false), m_removed(false), m_owned(owned)
+{
+  NetService::lpServices().push_back(this);
+  DBG("\r\n[ + %p ] %d\r\n", (void*)this, lpServices().size());
+}
+
+NetService::~NetService()
+{
+ // DBG("\r\nService removed\r\n");
+//  DBG("\r\nNow %d services running\r\n", lpServices().size()-1);
+  DBG("\r\n[ - %p ] %d\r\n", (void*)this, lpServices().size()-1);
+  if((!m_owned) || (!m_removed)) //Destructor was not called by servicesPoll()
+  { 
+    if(m_owned)
+      DBG("\r\nWARN!!!Service removed in dtor!!!\r\n");
+    NetService::lpServices().remove(this);
+  }
+}
+
+void NetService::poll()
+{
+
+}
+  
+void NetService::servicesPoll() //Poll all registered services & destroy closed ones
+{
+  list<NetService*>::iterator it;
+  DBG("\r\nServices polling over %d services\r\n", lpServices().size());
+  for( it = lpServices().begin(); it != lpServices().end();  )
+  {
+    if( (*it)->m_owned && (*it)->m_closed  )
+    {
+      DBG("\r\nService %p is flagged as closed\r\n", (*it));
+      (*it)->m_removed = true;
+      delete (*it);
+      it = lpServices().erase(it);
+    }
+    else
+    {
+      //DBG("Service %p polling start\n", (*it));
+      (*it)->poll();
+      //DBG("Service %p polling end\n", (*it));
+      it++;
+    }
+  }
+  
+}
+
+void NetService::close()
+{
+  DBG("\r\nService %p to be closed (owned = %d)\r\n", this, m_owned);
+  m_closed = true;
+}
+
+list<NetService*>& NetService::lpServices()
+{
+  static list<NetService*>* pInst = new list<NetService*>(); //Called only once
+  return *pInst;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/core/netservice.h	Thu Aug 05 14:32:43 2010 +0000
@@ -0,0 +1,58 @@
+
+/*
+Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
+ 
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+ 
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+ 
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+*/
+
+#ifndef NETSERVICE_H
+#define NETSERVICE_H
+
+//class NetDnsRequest;
+//#include "net.h"
+
+//Each connection-oriented object can register as service (by inheriting this class), so that it is polled regularly
+//It notifies the pool when the connection is terminated so that it can be destroyed
+
+#include <list>
+using std::list;
+
+class NetService
+{
+public:
+  NetService(bool owned = true); //Is owned by the pool?
+  virtual ~NetService();
+
+  virtual void poll();
+ 
+  static void servicesPoll(); //Poll all registered services & destroy closed ones
+
+protected:
+  void close();
+  
+private:
+  bool m_closed;
+  bool m_removed;
+  bool m_owned;
+  
+  static list<NetService*>& lpServices(); //Helper to prevent static initialization fiasco  
+
+};
+
+#endif
--- a/drv/gprsmodule/GPRSModule.cpp	Wed Jul 28 12:45:32 2010 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,100 +0,0 @@
-
-/*
-Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
- 
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
- 
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
- 
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-*/
-
-#include "gprsmodule.h"
-
-#include "mbed.h"
-
-//#define __DEBUG
-#include "dbg/dbg.h"
-
-#include "netCfg.h"
-#if NET_GPRS_MODULE
-
-GPRSModule::GPRSModule(PinName pwrSetPin, PinName pwrMonPin) : m_pwrSetPin(pwrSetPin), m_pwrMonPin(pwrMonPin)
-{
-  //m_pwrSetPin.write(0);
-
-  //m_pwrMonPin.mode(PullDown);
-}
-
-GPRSModule::~GPRSModule() {
-
-}
-
-bool GPRSModule::isOn() //True if on
-{ 
-  return m_pwrMonPin.read();
-}
-
-bool GPRSModule::on() //True if OK
-{ 
-  Timer tmr;
-  if(!m_pwrMonPin.read()){
-    //On
-    DBG("Switching On...\n");
-    m_pwrSetPin.write(1);
-    wait(1.);
-    m_pwrSetPin.write(0);
-       
-    tmr.start();
-    while(!m_pwrMonPin.read())
-    {
-      wait(.001);
-      if(tmr.read() > 2)
-      { 
-         DBG("ERROR - MUST RESET MODULE\n");
-         break;
-      }
-    }
-    tmr.stop();
-  }
-  wait(.1);
-  return m_pwrMonPin.read();
-}
-
-bool GPRSModule::off() { //True if OK
-  Timer tmr;
-  if(m_pwrMonPin.read()){
-    //Off
-    DBG("Switching Off...\n");
-    m_pwrSetPin.write(1);
-    wait(3.);
-    m_pwrSetPin.write(0);
-      DBG("Waiting....\n"); 
-    tmr.start();
-    while(m_pwrMonPin.read())
-    {
-      wait(.001);
-      if(tmr.read() > 15)
-      { 
-         DBG("ERROR - MUST RESET MODULE\n");
-         break;
-      }
-    }
-    tmr.stop();
-  }
-  return !m_pwrMonPin.read();
-}
-
-#endif
--- a/drv/gprsmodule/GPRSModule.h	Wed Jul 28 12:45:32 2010 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,47 +0,0 @@
-
-/*
-Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
- 
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
- 
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
- 
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-*/
-
-#ifndef GPRSMODULE_H
-#define GPRSMODULE_H
-
-#include "mbed.h"
-
-class GPRSModule
-{
-public:
-  GPRSModule(PinName pwrSetPin, PinName pwrMonPin);
-  ~GPRSModule();
-  
-  bool isOn(); //True if on
-  bool on(); //True if OK
-  bool off(); //True if OK
-  
-protected:
- 
-private:
-  DigitalOut m_pwrSetPin;
-  DigitalIn m_pwrMonPin;
-
-};
-
-#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/drv/gprsmodule/TelitModule.cpp	Thu Aug 05 14:32:43 2010 +0000
@@ -0,0 +1,100 @@
+
+/*
+Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
+ 
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+ 
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+ 
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+*/
+
+#include "TelitModule.h"
+
+#include "mbed.h"
+
+//#define __DEBUG
+#include "dbg/dbg.h"
+
+#include "netCfg.h"
+#if NET_GPRS_MODULE
+
+TelitModule::TelitModule(PinName pwrSetPin, PinName pwrMonPin) : m_pwrSetPin(pwrSetPin), m_pwrMonPin(pwrMonPin)
+{
+  //m_pwrSetPin.write(0);
+
+  //m_pwrMonPin.mode(PullDown);
+}
+
+TelitModule::~TelitModule() {
+
+}
+
+bool TelitModule::isOn() //True if on
+{ 
+  return m_pwrMonPin.read();
+}
+
+bool TelitModule::on() //True if OK
+{ 
+  Timer tmr;
+  if(!m_pwrMonPin.read()){
+    //On
+    DBG("Switching On...\n");
+    m_pwrSetPin.write(1);
+    wait(1.);
+    m_pwrSetPin.write(0);
+       
+    tmr.start();
+    while(!m_pwrMonPin.read())
+    {
+      wait(.001);
+      if(tmr.read() > 2)
+      { 
+         DBG("ERROR - MUST RESET MODULE\n");
+         break;
+      }
+    }
+    tmr.stop();
+  }
+  wait(.1);
+  return m_pwrMonPin.read();
+}
+
+bool TelitModule::off() { //True if OK
+  Timer tmr;
+  if(m_pwrMonPin.read()){
+    //Off
+    DBG("Switching Off...\n");
+    m_pwrSetPin.write(1);
+    wait(3.);
+    m_pwrSetPin.write(0);
+      DBG("Waiting....\n"); 
+    tmr.start();
+    while(m_pwrMonPin.read())
+    {
+      wait(.001);
+      if(tmr.read() > 15)
+      { 
+         DBG("ERROR - MUST RESET MODULE\n");
+         break;
+      }
+    }
+    tmr.stop();
+  }
+  return !m_pwrMonPin.read();
+}
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/drv/gprsmodule/TelitModule.h	Thu Aug 05 14:32:43 2010 +0000
@@ -0,0 +1,47 @@
+
+/*
+Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
+ 
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+ 
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+ 
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+*/
+
+#ifndef TELITMODULE_H
+#define TELITMODULE_H
+
+#include "mbed.h"
+
+class TelitModule
+{
+public:
+  TelitModule(PinName pwrSetPin, PinName pwrMonPin);
+  ~TelitModule();
+  
+  bool isOn(); //True if on
+  bool on(); //True if OK
+  bool off(); //True if OK
+  
+protected:
+ 
+private:
+  DigitalOut m_pwrSetPin;
+  DigitalIn m_pwrMonPin;
+
+};
+
+#endif
--- a/drv/serial/buf/SerialBuf.cpp	Wed Jul 28 12:45:32 2010 +0000
+++ b/drv/serial/buf/SerialBuf.cpp	Thu Aug 05 14:32:43 2010 +0000
@@ -190,14 +190,14 @@
 {
   if( !m_rxBuf.len() ) //Fill buf if possible
     onRxInterrupt();
-  return (bool)m_rxBuf.len();
+  return (m_rxBuf.len() > 0);
 }
 
 bool SerialBuf::writeable()
 {
-  if( !m_rxBuf.room() ) //Free buf is possible
+  if( !m_txBuf.room() ) //Free buf is possible
     onTxInterrupt();
-  return (bool)m_txBuf.room();
+  return (m_txBuf.room() > 0);
 }
 
 void SerialBuf::setReadMode(bool readMode) //If true, keeps chars in buf when read, false by default
--- a/if/eth/EthernetNetIf.h	Wed Jul 28 12:45:32 2010 +0000
+++ b/if/eth/EthernetNetIf.h	Thu Aug 05 14:32:43 2010 +0000
@@ -32,7 +32,6 @@
 
 #include "mbed.h"
 
-#include "if/net/net.h"
 #include "if/lwip/LwipNetIf.h"
 
 ///Ethernet network interface return codes
--- a/if/gprsmodule/GPRSModuleNetIf.cpp	Wed Jul 28 12:45:32 2010 +0000
+++ b/if/gprsmodule/GPRSModuleNetIf.cpp	Thu Aug 05 14:32:43 2010 +0000
@@ -29,7 +29,7 @@
 #define __DEBUG
 #include "dbg/dbg.h"
 
-GPRSModuleNetIf::GPRSModuleNetIf(PinName tx, PinName rx, PinName pwrSetPin, PinName pwrMonPin, int baud /*= 115200*/) : PPPNetIf(NULL), m_module(pwrSetPin, pwrMonPin), m_serial(tx, rx)
+GPRSModuleNetIf::GPRSModuleNetIf(PinName tx, PinName rx, int baud /*= 115200*/) : PPPNetIf(NULL), m_serial(tx, rx)
 {
   PPPNetIf::m_pIf = new GPRSModem();
   m_serial.baud(baud);
@@ -42,22 +42,15 @@
   
 PPPErr GPRSModuleNetIf::connect(const char* apn /*= NULL*/, const char* userId /*= NULL*/, const char* password /*= NULL*/) //Connect using GPRS
 {
-  if(m_module.isOn())
-  {
-    DBG("Resetting module...\n");
-    m_module.off(); //Reset module if needed
-  }
-  
-  wait(4);
 
   DBG("Powering on module.\n")
-  if(!m_module.on()) //Could not power on module
+  if(!setOn()) //Could not power on module
   {
     DBG("Could not power on module.\n");
     return PPP_MODEM;
   }
   
-  wait(10); //Wait for module to init.
+  //wait(10); //Wait for module to init.
 
   ATErr atErr;
   for(int i=0; i<3; i++)
@@ -71,7 +64,7 @@
     
   if(atErr)
   {
-    m_module.off();
+    setOff();
     return PPP_MODEM;
   }
     
@@ -89,7 +82,7 @@
   }
   if(pppErr)
   {
-    m_module.off();
+    setOff();
     return pppErr;
   }
     
@@ -108,7 +101,7 @@
   m_pIf->close();
   
   DBG("Powering off module.\n")
-  m_module.off(); //Power off module
+  setOff(); //Power off module
   
   DBG("Off.\n")
   
--- a/if/gprsmodule/GPRSModuleNetIf.h	Wed Jul 28 12:45:32 2010 +0000
+++ b/if/gprsmodule/GPRSModuleNetIf.h	Thu Aug 05 14:32:43 2010 +0000
@@ -26,23 +26,25 @@
 
 #include "mbed.h"
 
-#include "if/net/net.h"
+#include "core/net.h"
 #include "if/ppp/PPPNetIf.h"
 
 #include "drv/gprs/GPRSModem.h"
-#include "drv/gprsmodule/GPRSModule.h"
 
 class GPRSModuleNetIf : protected PPPNetIf
 {
 public:
-  GPRSModuleNetIf(PinName tx, PinName rx, PinName pwrSetPin, PinName pwrMonPin, int baud = 115200); 
+  GPRSModuleNetIf(PinName tx, PinName rx, int baud = 115200); 
   virtual ~GPRSModuleNetIf();
   
   PPPErr connect(const char* apn = NULL, const char* userId = NULL, const char* password = NULL); //Connect using GPRS
   PPPErr disconnect();
   
+protected:
+  virtual bool setOn() = 0; //True on success
+  virtual bool setOff() = 0; //True on success
+  
 private:
-  GPRSModule m_module;
   Serial m_serial;
 
 };
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/if/gprsmodule/HuaweiGTM900NetIf.cpp	Thu Aug 05 14:32:43 2010 +0000
@@ -0,0 +1,55 @@
+
+/*
+Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
+ 
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+ 
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+ 
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+*/
+
+#include "netCfg.h"
+#if NET_GPRS_MODULE
+
+#include "HuaweiGTM900NetIf.h"
+
+#define __DEBUG
+#include "dbg/dbg.h"
+
+HuaweiGTM900NetIf::HuaweiGTM900NetIf(PinName tx, PinName rx, int baud /*= 115200*/) : GPRSModuleNetIf(tx, rx, baud)
+{
+
+}
+
+HuaweiGTM900NetIf::~HuaweiGTM900NetIf()
+{
+
+}
+  
+bool HuaweiGTM900NetIf::setOn()
+{  
+  wait(5); //Wait for module to init.
+
+  return true;
+}
+
+bool HuaweiGTM900NetIf::setOff()
+{
+  return true;
+}
+  
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/if/gprsmodule/HuaweiGTM900NetIf.h	Thu Aug 05 14:32:43 2010 +0000
@@ -0,0 +1,44 @@
+
+/*
+Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
+ 
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+ 
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+ 
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+*/
+
+#ifndef HUAWEIGTM900NETIF_H
+#define HUAWEIGTM900NETIF_H
+
+#include "mbed.h"
+
+#include "GPRSModuleNetIf.h"
+
+class HuaweiGTM900NetIf : public GPRSModuleNetIf
+{
+public:
+  HuaweiGTM900NetIf(PinName tx, PinName rx, int baud = 115200); 
+  virtual ~HuaweiGTM900NetIf();
+
+protected:
+  virtual bool setOn(); //True on success
+  virtual bool setOff(); //True on success  
+
+};
+
+#endif
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/if/gprsmodule/TelitModuleNetIf.cpp	Thu Aug 05 14:32:43 2010 +0000
@@ -0,0 +1,71 @@
+
+/*
+Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
+ 
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+ 
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+ 
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+*/
+
+#include "netCfg.h"
+#if NET_GPRS_MODULE
+
+#include "TelitModuleNetIf.h"
+
+#define __DEBUG
+#include "dbg/dbg.h"
+
+TelitModuleNetIf::TelitModuleNetIf(PinName tx, PinName rx, PinName pwrSetPin, PinName pwrMonPin, int baud /*= 115200*/) : GPRSModuleNetIf(tx, rx, baud), m_module(pwrSetPin, pwrMonPin)
+{
+
+}
+
+TelitModuleNetIf::~TelitModuleNetIf()
+{
+
+}
+  
+bool TelitModuleNetIf::setOn()
+{
+  if(m_module.isOn())
+  {
+    DBG("Resetting module...\n");
+    m_module.off(); //Reset module if needed
+  }
+  
+  wait(4);
+
+  DBG("Powering on module.\n")
+  if(!m_module.on()) //Could not power on module
+  {
+    DBG("Could not power on module.\n");
+    return false;
+  }
+  
+  wait(10); //Wait for module to init.
+
+  return true;
+}
+
+bool TelitModuleNetIf::setOff()
+{
+  DBG("Powering off module.\n")
+  return m_module.off(); //Power off module
+}
+  
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/if/gprsmodule/TelitModuleNetIf.h	Thu Aug 05 14:32:43 2010 +0000
@@ -0,0 +1,49 @@
+
+/*
+Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
+ 
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+ 
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+ 
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+*/
+
+#ifndef TELITMODULENETIF_H
+#define TELITMODULENETIF_H
+
+#include "mbed.h"
+
+#include "GPRSModuleNetIf.h"
+
+#include "drv/gprsmodule/TelitModule.h"
+
+class TelitModuleNetIf : public GPRSModuleNetIf
+{
+public:
+  TelitModuleNetIf(PinName tx, PinName rx, PinName pwrSetPin, PinName pwrMonPin, int baud = 115200); 
+  virtual ~TelitModuleNetIf();
+
+protected:
+  virtual bool setOn(); //True on success
+  virtual bool setOff(); //True on success  
+  
+private:
+  TelitModule m_module;
+
+};
+
+#endif
+
--- a/if/lwip/LwipNetIf.cpp	Wed Jul 28 12:45:32 2010 +0000
+++ b/if/lwip/LwipNetIf.cpp	Thu Aug 05 14:32:43 2010 +0000
@@ -26,6 +26,10 @@
 #include "lwip/tcp_impl.h"
 #include "lwip/dns.h"
 
+#include "lwipNetTcpSocket.h"
+#include "lwipNetUdpSocket.h"
+#include "lwipNetDnsRequest.h"
+
 #include "netCfg.h"
 #if NET_LWIP_STACK
 
--- a/if/lwip/LwipNetIf.h	Wed Jul 28 12:45:32 2010 +0000
+++ b/if/lwip/LwipNetIf.h	Thu Aug 05 14:32:43 2010 +0000
@@ -28,10 +28,13 @@
 #include "mbed.h"
 
 #define NET_LWIP_STACK 1
-#include "if/net/net.h"
+#include "core/net.h"
+#include "if/net/netif.h"
+/*
 #include "lwipNetTcpSocket.h"
 #include "lwipNetUdpSocket.h"
 #include "lwipNetDnsRequest.h"
+*/
 
 class LwipNetIf : public NetIf
 {
--- a/if/lwip/lwipNetTcpSocket.h	Wed Jul 28 12:45:32 2010 +0000
+++ b/if/lwip/lwipNetTcpSocket.h	Thu Aug 05 14:32:43 2010 +0000
@@ -25,16 +25,18 @@
 #define LWIPNETTCPSOCKET_H
 
 #define NET_LWIP_STACK 1
-#include "lwip/ip_addr.h"
-#include "if/net/net.h"
+#include "if/net/nettcpsocket.h"
 #include "LwipNetIf.h"
 
+#include "stdint.h"
+
 //Implements NetTcpSockets over lwIP raw API
 
 struct tcp_pcb; //Represents a Tcp Connection, "Protocol Control Block", see rawapi.txt & tcp.h
 struct pbuf; //Lwip Buffer Container
 
 typedef signed char err_t;
+typedef uint16_t u16_t;
 
 class LwipNetTcpSocket: public NetTcpSocket
 {
--- a/if/lwip/lwipNetUdpSocket.cpp	Wed Jul 28 12:45:32 2010 +0000
+++ b/if/lwip/lwipNetUdpSocket.cpp	Thu Aug 05 14:32:43 2010 +0000
@@ -21,10 +21,12 @@
 THE SOFTWARE.
 */
 
+#include "lwip/ip_addr.h"
 #include "lwipNetUdpSocket.h"
 #include "lwip/udp.h"
 #include "lwip/igmp.h"
 
+
 //#define __DEBUG
 #include "dbg/dbg.h"
 
--- a/if/lwip/lwipNetUdpSocket.h	Wed Jul 28 12:45:32 2010 +0000
+++ b/if/lwip/lwipNetUdpSocket.h	Thu Aug 05 14:32:43 2010 +0000
@@ -25,10 +25,12 @@
 #define LWIPNETUDPSOCKET_H
 
 #define NET_LWIP_STACK 1
-#include "lwip/ip_addr.h"
-#include "if/net/net.h"
+//#include "lwip/ip_addr.h"
+#include "if/net/netudpsocket.h"
 #include "LwipNetIf.h"
 
+#include "stdint.h"
+
 #include <list>
 using std::list;
 
@@ -36,8 +38,10 @@
 
 struct udp_pcb; //Represents a Udp Connection, "Protocol Control Block", see rawapi.txt & udp.h
 struct pbuf; //Lwip Buffer Container
+typedef struct ip_addr ip_addr_t;
 
-typedef signed char err_t;
+//typedef signed char err_t;
+typedef uint16_t u16_t;
 
 class LwipNetUdpSocket: public NetUdpSocket
 {
--- a/if/net/host.h	Wed Jul 28 12:45:32 2010 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,113 +0,0 @@
-
-/*
-Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
- 
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
- 
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
- 
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-*/
-
-#ifndef HOST_H
-#define HOST_H
-
-class NetDnsRequest;
-
-#include "ipaddr.h"
-#include "netdnsrequest.h"
-#include <string.h>
-
-///Host information container
-/**
-This class is a container for data relative to a connection:
-- IP Address
-- Port number
-- Host Name
-*/
-class Host 
-{
-public:
-  ///Initiliazes host with null values
-  Host() : m_ip(0,0,0,0), m_port(0), m_name(NULL)
-  {
-    
-  }
-  
-  ///Initializes host
-  Host(const IpAddr& ip, const int& port, const char* name="" ) : m_ip(ip), m_port(port), m_name(NULL)
-  {
-    setName(name); 
-  }
-  
-  ~Host()
-  {
-    if(m_name)
-    {
-      delete[] m_name;
-    }
-  }
-  
-  ///Returns IP address
-  const IpAddr& getIp() const
-  {
-    return m_ip;
-  }
-  
-  ///Returns port number
-  const int& getPort() const
-  {
-    return m_port;
-  }
-  
-  ///Returns host name
-  const char* getName() const
-  {
-    return m_name;
-  }
-  
-  ///Sets IP address
-  void setIp(const IpAddr& ip)
-  {
-    m_ip = ip;
-  }
-  
-  ///Sets port number
-  void setPort(int port)
-  {
-    m_port = port;
-  }
-  
-  ///Sets host name
-  void setName(const char* name)
-  {
-    if(m_name)
-      delete[] m_name;
-    int len = strlen(name);
-    if(len)
-    {
-      m_name = new char[len+1];
-      strcpy(m_name, name);
-    }
-  }
-  
-private:
-  friend class NetDnsRequest;
-  IpAddr m_ip;
-  int m_port;
-  char* m_name;
-};
-
-#endif
--- a/if/net/ipaddr.h	Wed Jul 28 12:45:32 2010 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,150 +0,0 @@
-
-/*
-Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
- 
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
- 
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
- 
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-*/
-
-#ifndef IPADDR_H
-#define IPADDR_H
-
-#include "mbed.h"
-
-#include "netCfg.h"
-#if NET_LWIP_STACK
-#include "lwip/ip_addr.h"
-
-#ifdef __LWIP_DEBUG
-#undef __LWIP_DEBUG
-#endif
-#endif
-
-class IpAddr;
-
-///IP Address container
-/**
-This class is a container for an IPv4 address.
-*/
-class IpAddr //Basically a C++ frontend to ip_addr_t
-{
-public:
-  #if NET_LWIP_STACK
-  IpAddr(ip_addr_t* pIp)
-  {
-    *((uint32_t*)m_ip) = pIp->addr;
-  }
-  #endif
-  
-  ///Initializes IP address with provided values
-  IpAddr(uint8_t ip0, uint8_t ip1, uint8_t ip2, uint8_t ip3)
-  {
-    //We are in LE
-    m_ip[0] = ip0;
-    m_ip[1] = ip1;
-    m_ip[2] = ip2;
-    m_ip[3] = ip3;
-  }
-  
-  ///Initializes IP address with null values 
-  IpAddr()
-  {
-    m_ip[0] = 0;
-    m_ip[1] = 0;
-    m_ip[2] = 0;
-    m_ip[3] = 0;
-  }
-  
-
-  #if NET_LWIP_STACK
-  ip_addr_t getStruct() const
-  {
-    ip_addr_t ip_struct;
-    ip_struct.addr = *((uint32_t*)m_ip);
-    return ip_struct;
-  }
-  #endif
-  
-  ///Returns IP address byte #
-  uint8_t operator[](unsigned int i) const
-  {
-    uint8_t null = 0;
-    if( i > 3 )
-      return null;
-    return m_ip[i];
-  }
-  
-  ///Compares too addresses
-  /*
-  @return true if the two addresses are equal
-  */
-  bool isEq(const IpAddr& b) const
-  {
-    return (*((uint32_t*)m_ip) == *((uint32_t*)(b.m_ip)));
-  }
-  
-  ///Compares too addresses
-  /*
-  @return true if the two addresses are equal
-  */
-  bool operator==(const IpAddr& b) const
-  {
-    return isEq(b);
-  }
- 
-  ///Compares too addresses
-  /*
-  @return true if the two addresses are different
-  */ 
-  bool operator!=(const IpAddr& b) const
-  {
-    return !(operator==(b));
-  }
-  
-  ///Checks whether the address is null
-  /*
-  @return true if the address is null
-  */
-  bool isNull() const
-  {
-    return (*((uint32_t*)m_ip) == 0);
-  }
-  
-  ///Checks whether the address is a broadcast address
-  /*
-  @return true if the address is a broadcast address
-  */
-  bool isBroadcast() const
-  {
-    return (*((uint32_t*)m_ip) == 0xFFFFFFFF);
-  }
-
-  ///Checks whether the address is a multicast address
-  /*
-  @return true if the address is a multicast address
-  */
-  bool isMulticast() const
-  {
-    return ((m_ip[0] & 0xF0) == 0xE0);
-  }
-  
-private:
-  uint8_t m_ip[4];
-};
-
-#endif
--- a/if/net/net.cpp	Wed Jul 28 12:45:32 2010 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,221 +0,0 @@
-
-/*
-Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
- 
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
- 
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
- 
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-*/
-
-#include "net.h"
-
-//#define __DEBUG
-#include "dbg/dbg.h"
-
-Net::Net() : m_defaultIf(NULL), m_lpIf(), m_lpNetTcpSocket(), m_lpNetUdpSocket()
-{
-
-}
-
-Net::~Net()
-{
-
-}
-
-
-void Net::poll()
-{
-  //DBG("\r\nNet : Services polling\r\n");
-
-  //Poll Services
-  NetService::servicesPoll();  
-  
-  //DBG("\r\nNet : Interfaces polling\r\n");   
-      
-  //Poll Interfaces
-  list<NetIf*>::iterator pIfIt;
-
-  for ( pIfIt = net().m_lpIf.begin() ; pIfIt != net().m_lpIf.end(); pIfIt++ )
-  {
-    (*pIfIt)->poll();
-  }
-  
-  //DBG("\r\nNet : Sockets polling\r\n");
-  
-  //Poll Tcp Sockets
-  list<NetTcpSocket*>::iterator pNetTcpSocketIt;
-
-  for ( pNetTcpSocketIt = net().m_lpNetTcpSocket.begin() ; pNetTcpSocketIt != net().m_lpNetTcpSocket.end(); )
-  {
-    (*pNetTcpSocketIt)->poll();
-    
-    if( (*pNetTcpSocketIt)->m_closed && !((*pNetTcpSocketIt)->m_refs) )
-    {
-      (*pNetTcpSocketIt)->m_removed = true;
-      delete (*pNetTcpSocketIt);
-      (*pNetTcpSocketIt) = NULL;
-      pNetTcpSocketIt = net().m_lpNetTcpSocket.erase(pNetTcpSocketIt);
-    }
-    else
-    {
-      pNetTcpSocketIt++;
-    }
-  }
-  
-  //Poll Udp Sockets
-  list<NetUdpSocket*>::iterator pNetUdpSocketIt;
-
-  for ( pNetUdpSocketIt = net().m_lpNetUdpSocket.begin() ; pNetUdpSocketIt != net().m_lpNetUdpSocket.end(); )
-  {
-    (*pNetUdpSocketIt)->poll();
-    
-    if( (*pNetUdpSocketIt)->m_closed && !((*pNetUdpSocketIt)->m_refs) )
-    {
-      (*pNetUdpSocketIt)->m_removed = true;
-      delete (*pNetUdpSocketIt);
-      (*pNetUdpSocketIt) = NULL;
-      pNetUdpSocketIt = net().m_lpNetUdpSocket.erase(pNetUdpSocketIt);
-    }
-    else
-    {
-      pNetUdpSocketIt++;
-    }
-  }
-
-
-}
-
-NetTcpSocket* Net::tcpSocket(NetIf& netif) {
-  NetTcpSocket* pNetTcpSocket = netif.tcpSocket();
-  pNetTcpSocket->m_refs++;
-  return pNetTcpSocket; 
-}
-
-NetTcpSocket* Net::tcpSocket() { //NetTcpSocket on default if
- if ( net().m_defaultIf == NULL )
-      return NULL;
-  NetTcpSocket* pNetTcpSocket = net().m_defaultIf->tcpSocket();
-  pNetTcpSocket->m_refs++;
-  return pNetTcpSocket;
-}
-
-void Net::releaseTcpSocket(NetTcpSocket* pNetTcpSocket)
-{
-  pNetTcpSocket->m_refs--;
-  if(!pNetTcpSocket->m_closed && !pNetTcpSocket->m_refs)
-    pNetTcpSocket->close();
-}
-
-NetUdpSocket* Net::udpSocket(NetIf& netif) {
-  NetUdpSocket* pNetUdpSocket = netif.udpSocket();
-  pNetUdpSocket->m_refs++;
-  return pNetUdpSocket; 
-}
-
-NetUdpSocket* Net::udpSocket() { //NetTcpSocket on default if
- if ( net().m_defaultIf == NULL )
-      return NULL;
-  NetUdpSocket* pNetUdpSocket = net().m_defaultIf->udpSocket();
-  pNetUdpSocket->m_refs++;
-  return pNetUdpSocket;
-}
-
-void Net::releaseUdpSocket(NetUdpSocket* pNetUdpSocket)
-{
-  pNetUdpSocket->m_refs--;
-  if(!pNetUdpSocket->m_closed && !pNetUdpSocket->m_refs)
-    pNetUdpSocket->close();
-}
-
-NetDnsRequest* Net::dnsRequest(const char* hostname, NetIf& netif) {
-  return netif.dnsRequest(hostname);
-}
-
-NetDnsRequest* Net::dnsRequest(const char* hostname) { //Create a new NetDnsRequest object from default if
-  if ( net().m_defaultIf == NULL )
-      return NULL;
-  return net().m_defaultIf->dnsRequest(hostname);
-}
-
-NetDnsRequest* Net::dnsRequest(Host* pHost, NetIf& netif)
-{
-  return netif.dnsRequest(pHost);
-}
-
-NetDnsRequest* Net::dnsRequest(Host* pHost) //Creats a new NetDnsRequest object from default if
-{
-  if ( net().m_defaultIf == NULL )
-      return NULL;
-  return net().m_defaultIf->dnsRequest(pHost);
-}
-
-void Net::setDefaultIf(NetIf& netif) {
-  net().m_defaultIf = &netif;
-}
-
-void Net::setDefaultIf(NetIf* pIf)
-{
-  net().m_defaultIf = pIf;
-}
-
-NetIf* Net::getDefaultIf() {
-  return net().m_defaultIf;
-}
-
-void Net::registerIf(NetIf* pIf)
-{
-  net().m_lpIf.push_back(pIf);
-}
-
-void Net::unregisterIf(NetIf* pIf)
-{
-  if( net().m_defaultIf == pIf )
-    net().m_defaultIf = NULL;
-  net().m_lpIf.remove(pIf);
-}
-
-void Net::registerNetTcpSocket(NetTcpSocket* pNetTcpSocket)
-{
-  net().m_lpNetTcpSocket.push_back(pNetTcpSocket);
-  DBG("\r\nNetTcpSocket [ + %p ] %d\r\n", (void*)pNetTcpSocket, net().m_lpNetTcpSocket.size());
-}
-
-void Net::unregisterNetTcpSocket(NetTcpSocket* pNetTcpSocket)
-{
-  DBG("\r\nNetTcpSocket [ - %p ] %d\r\n", (void*)pNetTcpSocket, net().m_lpNetTcpSocket.size() - 1);
-  if(!pNetTcpSocket->m_removed)
-    net().m_lpNetTcpSocket.remove(pNetTcpSocket);
-}
-
-void Net::registerNetUdpSocket(NetUdpSocket* pNetUdpSocket)
-{
-  net().m_lpNetUdpSocket.push_back(pNetUdpSocket);
-  DBG("\r\nNetUdpSocket [ + %p ] %d\r\n", (void*)pNetUdpSocket, net().m_lpNetUdpSocket.size());
-}
-
-void Net::unregisterNetUdpSocket(NetUdpSocket* pNetUdpSocket)
-{
-  DBG("\r\nNetUdpSocket [ - %p ] %d\r\n", (void*)pNetUdpSocket, net().m_lpNetUdpSocket.size() - 1);
-  if(!pNetUdpSocket->m_removed)
-    net().m_lpNetUdpSocket.remove(pNetUdpSocket);
-}
-
-Net& Net::net()
-{
-  static Net* pInst = new Net(); //Called only once
-  return *pInst;
-}
--- a/if/net/net.h	Wed Jul 28 12:45:32 2010 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,111 +0,0 @@
-
-/*
-Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
- 
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
- 
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
- 
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-*/
-
-#ifndef NET_H
-#define NET_H
-
-class NetIf;
-class NetTcpSocket;
-class NetUdpSocket;
-class NetDnsRequest;
-
-#include <list>
-using std::list;
-
-#include "host.h"
-#include "ipaddr.h"
-#include "netif.h"
-#include "nettcpsocket.h"
-#include "netudpsocket.h"
-#include "netservice.h"
-#include "netdnsrequest.h"
-
-class Net
-{
-private:
-  Net();
-  ~Net();
-public:  
-  static void poll(); //Poll every if & socket
-  
-  static NetTcpSocket* tcpSocket(NetIf& netif);
-  static NetTcpSocket* tcpSocket(); //Socket on default if
-  static void releaseTcpSocket(NetTcpSocket* pNetTcpSocket);
-  
-  static NetUdpSocket* udpSocket(NetIf& netif);
-  static NetUdpSocket* udpSocket(); //Socket on default if
-  static void releaseUdpSocket(NetUdpSocket* pNetUdpSocket);
-  
-  static NetDnsRequest* dnsRequest(const char* hostname, NetIf& netif);
-  static NetDnsRequest* dnsRequest(const char* hostname); //Create a new NetDnsRequest object from default if
-
-  static NetDnsRequest* dnsRequest(Host* pHost, NetIf& netif);
-  static NetDnsRequest* dnsRequest(Host* pHost); //Create a new NetDnsRequest object from default if
-  
-  static void setDefaultIf(NetIf& netif); //Deprecated
-  static void setDefaultIf(NetIf* pIf);
-  static NetIf* getDefaultIf();
-  
-  //TODO: Factory functions like 'setupEthernet', 'setupPPP', 'setupTelit' ...
-  #if 0
-  enum NetErr //Generic errors
-  {
-    __NET_MIN = -0xFFFF;
-    NET_OPEN, //Could not open if
-    NET_CONNECT, //Could not connect
-    NET_AUTH, //Could not auth
-    NET_HW, //HW problem
-        
-    NET_OK = 0
-  };
-  
-  static NetErr Ethernet();
-  static NetErr PPPoverSerial(int Tx, int Rx, const char* apn, const char* user, const char* password);
-  static NetErr Telit(int pwrSetPin, int pwrMonPin, int Tx, int Rx);
-  #endif
-  
-protected:
-  friend class NetIf;
-  friend class NetTcpSocket;
-  friend class NetUdpSocket;
-  
-  static void registerIf(NetIf* pIf);
-  static void unregisterIf(NetIf* pIf);
-  
-  static void registerNetTcpSocket(NetTcpSocket* pNetTcpSocket);
-  static void unregisterNetTcpSocket(NetTcpSocket* pNetTcpSocket);  
-  
-  static void registerNetUdpSocket(NetUdpSocket* pNetUdpSocket);
-  static void unregisterNetUdpSocket(NetUdpSocket* pNetUdpSocket);  
-  
-private:
-  static Net& net(); //Return inst of singleton
-
-  NetIf* m_defaultIf;
-  
-  list<NetIf*> m_lpIf;
-  list<NetTcpSocket*> m_lpNetTcpSocket;
-  list<NetUdpSocket*> m_lpNetUdpSocket;
-};
-
-#endif
--- a/if/net/netdnsrequest.cpp	Wed Jul 28 12:45:32 2010 +0000
+++ b/if/net/netdnsrequest.cpp	Thu Aug 05 14:32:43 2010 +0000
@@ -60,7 +60,7 @@
 void NetDnsRequest::onReply(NetDnsReply reply) //Must be called by impl when the request completes
 {
   if( m_pHost )
-    m_pHost->m_ip = m_ip;
+    m_pHost->setIp(m_ip);
   if(m_pCbItem && m_pCbMeth)
     (m_pCbItem->*m_pCbMeth)(reply);
 }
--- a/if/net/netif.cpp	Wed Jul 28 12:45:32 2010 +0000
+++ b/if/net/netif.cpp	Thu Aug 05 14:32:43 2010 +0000
@@ -21,8 +21,9 @@
 THE SOFTWARE.
 */
 
+#include "core/host.h"
 #include "netif.h"
-#include "net.h"
+#include "core/net.h"
 
 NetIf::NetIf() : m_ip(0,0,0,0)
 {
--- a/if/net/netif.h	Wed Jul 28 12:45:32 2010 +0000
+++ b/if/net/netif.h	Thu Aug 05 14:32:43 2010 +0000
@@ -24,10 +24,15 @@
 #ifndef NETIF_H
 #define NETIF_H
 
-#include "ipaddr.h"
+#include "core/ipaddr.h"
+/*
 #include "nettcpsocket.h"
 #include "netudpsocket.h"
 #include "netdnsrequest.h"
+*/
+class NetTcpSocket;
+class NetUdpSocket;
+class NetDnsRequest;
 
 #if 0
 enum NetifEvent
--- a/if/net/netservice.cpp	Wed Jul 28 12:45:32 2010 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,88 +0,0 @@
-
-/*
-Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
- 
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
- 
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
- 
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-*/
-
-#include "netservice.h"
-#include "net.h"
-
-//#define __DEBUG
-#include "dbg/dbg.h"
-
-NetService::NetService(bool owned /*= true*/) : m_closed(false), m_removed(false), m_owned(owned)
-{
-  NetService::lpServices().push_back(this);
-  DBG("\r\n[ + %p ] %d\r\n", (void*)this, lpServices().size());
-}
-
-NetService::~NetService()
-{
- // DBG("\r\nService removed\r\n");
-//  DBG("\r\nNow %d services running\r\n", lpServices().size()-1);
-  DBG("\r\n[ - %p ] %d\r\n", (void*)this, lpServices().size()-1);
-  if((!m_owned) || (!m_removed)) //Destructor was not called by servicesPoll()
-  { 
-    if(m_owned)
-      DBG("\r\nWARN!!!Service removed in dtor!!!\r\n");
-    NetService::lpServices().remove(this);
-  }
-}
-
-void NetService::poll()
-{
-
-}
-  
-void NetService::servicesPoll() //Poll all registered services & destroy closed ones
-{
-  list<NetService*>::iterator it;
-  DBG("\r\nServices polling over %d services\r\n", lpServices().size());
-  for( it = lpServices().begin(); it != lpServices().end();  )
-  {
-    if( (*it)->m_owned && (*it)->m_closed  )
-    {
-      DBG("\r\nService %p is flagged as closed\r\n", (*it));
-      (*it)->m_removed = true;
-      delete (*it);
-      it = lpServices().erase(it);
-    }
-    else
-    {
-      //DBG("Service %p polling start\n", (*it));
-      (*it)->poll();
-      //DBG("Service %p polling end\n", (*it));
-      it++;
-    }
-  }
-  
-}
-
-void NetService::close()
-{
-  DBG("\r\nService %p to be closed (owned = %d)\r\n", this, m_owned);
-  m_closed = true;
-}
-
-list<NetService*>& NetService::lpServices()
-{
-  static list<NetService*>* pInst = new list<NetService*>(); //Called only once
-  return *pInst;
-}
--- a/if/net/netservice.h	Wed Jul 28 12:45:32 2010 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,58 +0,0 @@
-
-/*
-Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
- 
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
- 
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
- 
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-*/
-
-#ifndef NETSERVICE_H
-#define NETSERVICE_H
-
-//class NetDnsRequest;
-//#include "net.h"
-
-//Each connection-oriented object can register as service (by inheriting this class), so that it is polled regularly
-//It notifies the pool when the connection is terminated so that it can be destroyed
-
-#include <list>
-using std::list;
-
-class NetService
-{
-public:
-  NetService(bool owned = true); //Is owned by the pool?
-  virtual ~NetService();
-
-  virtual void poll();
- 
-  static void servicesPoll(); //Poll all registered services & destroy closed ones
-
-protected:
-  void close();
-  
-private:
-  bool m_closed;
-  bool m_removed;
-  bool m_owned;
-  
-  static list<NetService*>& lpServices(); //Helper to prevent static initialization fiasco  
-
-};
-
-#endif
--- a/if/ppp/PPPNetIf.cpp	Wed Jul 28 12:45:32 2010 +0000
+++ b/if/ppp/PPPNetIf.cpp	Thu Aug 05 14:32:43 2010 +0000
@@ -35,7 +35,7 @@
 
 #define PPP_TIMEOUT 60000
 
-#define BUF_SIZE 128
+#define BUF_SIZE 256
 
 PPPNetIf::PPPNetIf(GPRSModem* pIf) : LwipNetIf(), m_pIf(pIf),/* m_open(false),*/ m_connected(false), m_status(PPP_DISCONNECTED), m_fd(0) //, m_id(0)
 {
@@ -123,7 +123,6 @@
   
   if( m_status == PPP_DISCONNECTED )
   {
-    
     disconnect();
     return PPP_PROTOCOL;
   }
@@ -140,11 +139,12 @@
 
 PPPErr PPPNetIf::disconnect()
 {
-  pppClose(m_fd); //0 if ok, else should gen a WARN
+  if(m_fd)
+    pppClose(m_fd); //0 if ok, else should gen a WARN
   m_connected = false;
   
   m_pIf->flushBuffer();
-  m_pIf->printf("+++");
+  m_pIf->printf("+++\r\n");
   wait(.5);
   m_pIf->flushBuffer();
   
@@ -191,9 +191,13 @@
     return;
   LwipNetIf::poll();
   //static u8_t buf[128];
-  int len = sio_tryread((sio_fd_t) m_pIf, m_buf, BUF_SIZE);
-  if(len > 0)
-    pppos_input(m_fd, m_buf, len);
+  int len;
+  do
+  {
+    len = sio_tryread((sio_fd_t) m_pIf, m_buf, BUF_SIZE);
+    if(len > 0)
+      pppos_input(m_fd, m_buf, len);
+  } while(len>0);
 }
 
 //Link Callback
--- a/if/umtsstick/UMTSStickNetIf.h	Wed Jul 28 12:45:32 2010 +0000
+++ b/if/umtsstick/UMTSStickNetIf.h	Thu Aug 05 14:32:43 2010 +0000
@@ -30,7 +30,7 @@
 
 #include "mbed.h"
 
-#include "if/net/net.h"
+#include "core/net.h"
 #include "if/ppp/PPPNetIf.h"
 
 #include "drv/umtsstick/UMTSStick.h"
--- a/lwip/lwipopts.h	Wed Jul 28 12:45:32 2010 +0000
+++ b/lwip/lwipopts.h	Thu Aug 05 14:32:43 2010 +0000
@@ -62,16 +62,16 @@
 #define PBUF_DEBUG       LWIP_DBG_OFF
 #define API_LIB_DEBUG    LWIP_DBG_OFF
 #define API_MSG_DEBUG    LWIP_DBG_OFF
-#define TCPIP_DEBUG      LWIP_DBG_ON
-#define NETIF_DEBUG      LWIP_DBG_ON
+#define TCPIP_DEBUG      LWIP_DBG_OFF
+#define NETIF_DEBUG      LWIP_DBG_OFF
 #define SOCKETS_DEBUG    LWIP_DBG_OFF
 #define DEMO_DEBUG       LWIP_DBG_OFF
-#define IP_DEBUG         LWIP_DBG_ON
-#define IP_REASS_DEBUG   LWIP_DBG_ON
+#define IP_DEBUG         LWIP_DBG_OFF
+#define IP_REASS_DEBUG   LWIP_DBG_OFF
 #define RAW_DEBUG        LWIP_DBG_OFF
-#define ICMP_DEBUG       LWIP_DBG_ON
-#define IGMP_DEBUG       LWIP_DBG_ON
-#define UDP_DEBUG        LWIP_DBG_ON
+#define ICMP_DEBUG       LWIP_DBG_OFF
+#define IGMP_DEBUG       LWIP_DBG_OFF
+#define UDP_DEBUG        LWIP_DBG_OFF
 #define TCP_DEBUG        LWIP_DBG_OFF
 #define TCP_INPUT_DEBUG  LWIP_DBG_OFF
 #define TCP_OUTPUT_DEBUG LWIP_DBG_OFF
@@ -81,7 +81,7 @@
 #define TCP_FR_DEBUG     LWIP_DBG_OFF
 #define TCP_QLEN_DEBUG   LWIP_DBG_OFF
 #define TCP_RST_DEBUG    LWIP_DBG_OFF
-#define ETHARP_DEBUG     LWIP_DBG_ON
+#define ETHARP_DEBUG     LWIP_DBG_OFF
 #define DNS_DEBUG        LWIP_DBG_OFF
 
 #endif
--- a/netCfg.h	Wed Jul 28 12:45:32 2010 +0000
+++ b/netCfg.h	Thu Aug 05 14:32:43 2010 +0000
@@ -1,6 +1,8 @@
 #ifndef NET_CFG_H
+#define NET_TELIT_STACK 0
 #define NET_GPRS 1
 #define NET_PPP 1
+#define NET_ZG2100 0
 #define NET_GPRS_MODULE 1
 #define NET_ETH 1
 #define NET_USB_SERIAL 1
--- a/services/email/smtp/SMTPClient.h	Wed Jul 28 12:45:32 2010 +0000
+++ b/services/email/smtp/SMTPClient.h	Thu Aug 05 14:32:43 2010 +0000
@@ -26,7 +26,7 @@
 
 class EmailMessage;
 
-#include "if/net/net.h"
+#include "core/net.h"
 #include "api/TCPSocket.h"
 #include "../emailMessage.h"
 
--- a/services/http/client/HTTPClient.cpp	Wed Jul 28 12:45:32 2010 +0000
+++ b/services/http/client/HTTPClient.cpp	Thu Aug 05 14:32:43 2010 +0000
@@ -21,6 +21,7 @@
 THE SOFTWARE.
 */
 
+#include "core/netservice.h"
 #include "HTTPClient.h"
 #include "../util/base64.h"
 #include "../util/url.h"
@@ -80,7 +81,7 @@
   return HTTP_PROCESSING;
 }
 
-#ifdef __LINKER_BUG_SOLVED__
+#if 0 //For info only
 template<class T> 
 HTTPResult HTTPClient::get(const char* uri, HTTPData* pDataIn, T* pItem, void (T::*pMethod)(HTTPResult)) //Non blocking
 {
@@ -103,7 +104,7 @@
   return HTTP_PROCESSING;
 }
 
-#ifdef __LINKER_BUG_SOLVED__
+#if 0 //For info only
 template<class T> 
 HTTPResult HTTPClient::post(const char* uri, const HTTPData& dataOut, HTTPData* pDataIn, T* pItem, void (T::*pMethod)(HTTPResult)) //Non blocking 
 {
@@ -132,7 +133,7 @@
   m_pCbMeth = NULL;
 }
   
-#ifdef __LINKER_BUG_SOLVED__
+#if 0 //For info only
 template<class T> 
 void HTTPClient::setOnResult( T* pItem, void (T::*pMethod)(NtpResult) )
 {
@@ -304,11 +305,11 @@
     if(m_state == HTTP_READ_DATA_INCOMPLETE) //First try to complete buffer copy
     {
       readLen = m_bufRemainingLen;
-      if (readLen == 0)
+   /*   if (readLen == 0)
       {
         m_state = HTTP_READ_DATA;
         continue;
-      }
+      }*/
     }
     else
     {
@@ -317,16 +318,23 @@
       {
         return readLen;
       }
+      
+      DBG("%d bytes read\n", readLen);
+      
       m_pBufRemaining = m_buf;
     }
-  /*  if (readLen == 0)
+    if (readLen == 0)
     { 
       m_state = HTTP_READ_DATA;
       return len;
-    }*/
+    }
+    
+    DBG("Trying to write %d bytes\n", readLen);
   
     int writtenLen = m_pDataIn->write(m_pBufRemaining, readLen);
     m_dataPos += writtenLen;
+    
+    DBG("%d bytes written\n", writtenLen);
      
     if(writtenLen<readLen) //Data was not completely written
     {
@@ -450,7 +458,7 @@
   {
     //Write chunk header
     char chunkHeader[16];
-    sprintf(chunkHeader, "%d\n", len);
+    sprintf(chunkHeader, "%d\r\n", len);
     int ret = m_pTCPSocket->send(chunkHeader, strlen(chunkHeader));
     if(ret < 0)//Error
     {
@@ -462,7 +470,7 @@
   m_dataPos+=len;
   if( m_dataChunked )
   {
-    m_pTCPSocket->send("", 2); //Chunk terminating CRLF
+    m_pTCPSocket->send("\r\n", 2); //Chunk-terminating CRLF
   }
   if( ( !m_dataChunked && (m_dataPos >= m_dataLen) )
     || ( m_dataChunked && !len ) ) //All Data has been sent
@@ -742,7 +750,7 @@
   const char* HTTP_METH_STR[] = {"GET", "POST", "HEAD"};
   
   //Req
-  sprintf(line, "%s %s HTTP/1.1\r\nHost: %s\n", HTTP_METH_STR[m_meth], m_path.c_str(), m_server.getName()); //Write request
+  sprintf(line, "%s %s HTTP/1.1\r\nHost: %s\r\n", HTTP_METH_STR[m_meth], m_path.c_str(), m_server.getName()); //Write request
   m_pTCPSocket->send(line, strlen(line));
   DBG("Request: %s\n", line);
   
@@ -750,11 +758,11 @@
   map<string,string>::iterator it;
   for( it = m_reqHeaders.begin(); it != m_reqHeaders.end(); it++ )
   {
-    sprintf(line, "%s: %s\n", (*it).first.c_str(), (*it).second.c_str() );
-    DBG("%s", line);
+    sprintf(line, "%s: %s\r\n", (*it).first.c_str(), (*it).second.c_str() );
+    DBG("\r\n%s", line);
     m_pTCPSocket->send(line, strlen(line));
   }
-  m_pTCPSocket->send("",2); //End of head
+  m_pTCPSocket->send("\r\n",2); //End of head
   m_state = HTTP_WRITE_DATA;
   return true;
 }
--- a/services/http/client/HTTPClient.h	Wed Jul 28 12:45:32 2010 +0000
+++ b/services/http/client/HTTPClient.h	Thu Aug 05 14:32:43 2010 +0000
@@ -30,7 +30,7 @@
 
 class HTTPData;
 
-#include "if/net/net.h"
+#include "core/net.h"
 #include "api/TCPSocket.h"
 #include "api/DNSRequest.h"
 #include "HTTPData.h"
@@ -57,6 +57,8 @@
   HTTP_CONN ///<Connection error
 };
 
+#include "core/netservice.h"
+
 ///A simple HTTP Client
 /**
 The HTTPClient is composed of:
--- a/services/http/client/HTTPData.h	Wed Jul 28 12:45:32 2010 +0000
+++ b/services/http/client/HTTPData.h	Thu Aug 05 14:32:43 2010 +0000
@@ -24,7 +24,7 @@
 #ifndef HTTP_DATA_H
 #define HTTP_DATA_H
 
-#include "if/net/net.h"
+#include "core/net.h"
 
 #include <string>
 using std::string;
--- a/services/http/client/data/HTTPFile.cpp	Wed Jul 28 12:45:32 2010 +0000
+++ b/services/http/client/data/HTTPFile.cpp	Thu Aug 05 14:32:43 2010 +0000
@@ -23,6 +23,9 @@
 
 #include "HTTPFile.h"
 
+//#define __DEBUG
+#include "dbg/dbg.h"
+
 HTTPFile::HTTPFile(const char* path) : HTTPData(), m_fp(NULL), m_path(path), m_len(0), m_chunked(false)
 {
 
@@ -57,6 +60,7 @@
   if(!openFile("w")) //File does not exist, or I/O error...
     return 0;
   len = fwrite(buf, 1, len, m_fp);
+  DBG("Written %d bytes in %d\n", len, m_fp);
   if( (!m_chunked && (ftell(m_fp) >= m_len)) ||
       (m_chunked && !len) )
   {
@@ -111,6 +115,8 @@
     fseek(m_fp, 0, SEEK_SET); //Goto SOF
   }
   
+  DBG("fd = %d\n", m_fp);
+  
   if(!m_fp) 
     return false;
     
--- a/services/http/client/data/HTTPFile.h	Wed Jul 28 12:45:32 2010 +0000
+++ b/services/http/client/data/HTTPFile.h	Thu Aug 05 14:32:43 2010 +0000
@@ -21,18 +21,33 @@
 THE SOFTWARE.
 */
 
+/** \file
+HTTP File data source/sink header file
+*/
+
 #ifndef HTTP_FILE_H
 #define HTTP_FILE_H
 
 #include "../HTTPData.h"
 #include "mbed.h"
 
+///HTTP Client data container for files
+/**
+This class provides file access/storage for HTTP requests and responses' data payloads.
+*/
 class HTTPFile : public HTTPData //Read or Write data from a file
 {
 public:
+  ///Instantiates data source/sink with file in param.
+  /**
+  Uses file at path @param path.
+  It will be opened when some data has to be read/written from/to it and closed when this operation is complete or on destruction of the instance.
+  Note that the file will be opened with mode "w" for writing and mode "r" for reading, so the file will be cleared between each request if you are using it for writing.
+  */
   HTTPFile(const char* path);
   virtual ~HTTPFile();
   
+  ///Forces file closure
   virtual void clear();
 
 protected:
--- a/services/http/client/data/HTTPMap.h	Wed Jul 28 12:45:32 2010 +0000
+++ b/services/http/client/data/HTTPMap.h	Thu Aug 05 14:32:43 2010 +0000
@@ -21,6 +21,10 @@
 THE SOFTWARE.
 */
 
+/** \file
+HTTP Map data source/sink header file
+*/
+
 #ifndef HTTP_MAP_H
 #define HTTP_MAP_H
 
@@ -32,9 +36,22 @@
 
 typedef map<string, string> Dictionary;
 
+///HTTP Client data container for key/value pairs
+/**
+This class simplifies the use of key/value pairs requests and responses used widely among web APIs.
+Note that HTTPMap inherits from std::map<std::string,std::string>.
+You can therefore use any public method of that class, including the square brackets operator ( [ ] ) to access a value.
+
+The data is encoded or decoded to/from a key/value pairs-formatted string, after url-encoding/decoding.
+*/
 class HTTPMap : public HTTPData, public Dictionary //Key/Value pairs
 {
 public:
+  ///Instantiates map
+  /**
+  @param keyValueSep Key/Value separator (defaults to "=")
+  @param pairSep Pairs separator (defaults to "&")
+  */
   HTTPMap(const string& keyValueSep = "=", const string& pairSep = "&");
   virtual ~HTTPMap();
   
--- a/services/http/client/data/HTTPStream.h	Wed Jul 28 12:45:32 2010 +0000
+++ b/services/http/client/data/HTTPStream.h	Thu Aug 05 14:32:43 2010 +0000
@@ -27,18 +27,36 @@
 #include "../HTTPData.h"
 #include "mbed.h"
 
+/** \file
+HTTP Stream data source/sink header file
+*/
+
 typedef uint8_t byte;
 
+///HTTP Client Streaming tool
+/**
+This class allows you to stream data from the web using a persisting HTTP connection.
+To use it properly you must use a non-blocking HTTPClient method.
+*/
 class HTTPStream : public HTTPData //Streaming buf
 {
 public:
+  ///Instantiates the object
   HTTPStream();
   virtual ~HTTPStream();
   
+  ///Starts to read into buffer
+  /**
+  Passes a buffer of address @param buf and size @param size to the instance.
+  When it receives data it will be stored in this buffer.
+  When the buffer is full it throttles the client until this function is called again.
+  */
   void readNext(byte* buf, int size);
   
+  ///Returns whether there is data available to read
   bool readable();
   
+  ///Returns the actual length of the payload written in the buffer
   int readLen();
   
   virtual void clear();
--- a/services/http/client/data/HTTPText.h	Wed Jul 28 12:45:32 2010 +0000
+++ b/services/http/client/data/HTTPText.h	Thu Aug 05 14:32:43 2010 +0000
@@ -21,6 +21,10 @@
 THE SOFTWARE.
 */
 
+/** \file
+HTTP Text data source/sink header file
+*/
+
 #ifndef HTTP_TEXT_H
 #define HTTP_TEXT_H
 
@@ -29,18 +33,50 @@
 
 #define DEFAULT_MAX_MEM_ALLOC 512 //Avoid out-of-memory problems
 
+///HTTP Client data container for text
+/**
+This is a simple "Text" data repository for HTTP requests.
+*/
 class HTTPText : public HTTPData //Simple Text I/O
 {
 public:
+  ///Instantiates the object.
+  /**
+  @param encoding encoding of the data, it defaults to text/html.
+  @param maxSize defines the maximum memory size that can be allocated by the object. It defaults to 512 bytes.
+  */
   HTTPText(const string& encoding = "text/html", int maxSize = DEFAULT_MAX_MEM_ALLOC);
   virtual ~HTTPText();
   
+  ///Gets text
+  /**
+  Returns the text in the container as a zero-terminated char*.
+  The array returned points to the internal buffer of the object and remains owned by the object.
+  */
   const char* gets() const;
+  
+  //Puts text
+  /**
+  Sets the text in the container using a zero-terminated char*.
+  */
   void puts(const char* str);
   
+  ///Gets text
+  /**
+  Returns the text in the container as string.
+  */
   string& get();
+  
+  ///Puts text
+  /**
+  Sets the text in the container as string.
+  */
   void set(const string& str);
   
+  ///Clears the content.
+  /**
+  If this container is used as a data sink, it is cleared by the HTTP Client at the beginning of the request.
+  */
   virtual void clear();
   
 protected:
--- a/services/http/server/HTTPRequestDispatcher.cpp	Wed Jul 28 12:45:32 2010 +0000
+++ b/services/http/server/HTTPRequestDispatcher.cpp	Thu Aug 05 14:32:43 2010 +0000
@@ -21,6 +21,7 @@
 THE SOFTWARE.
 */
 
+#include "core/netservice.h"
 #include "HTTPRequestDispatcher.h"
 #include "HTTPRequestHandler.h"
 #include <string.h>
--- a/services/http/server/HTTPRequestDispatcher.h	Wed Jul 28 12:45:32 2010 +0000
+++ b/services/http/server/HTTPRequestDispatcher.h	Thu Aug 05 14:32:43 2010 +0000
@@ -28,6 +28,7 @@
 
 #include "api/TCPSocket.h"
 #include "HTTPServer.h"
+#include "core/netservice.h"
 
 #include "mbed.h"
 
--- a/services/http/server/HTTPRequestHandler.cpp	Wed Jul 28 12:45:32 2010 +0000
+++ b/services/http/server/HTTPRequestHandler.cpp	Thu Aug 05 14:32:43 2010 +0000
@@ -21,6 +21,7 @@
 THE SOFTWARE.
 */
 
+#include "core/netservice.h"
 #include "HTTPRequestHandler.h"
 
 #include <string.h>
--- a/services/http/server/HTTPRequestHandler.h	Wed Jul 28 12:45:32 2010 +0000
+++ b/services/http/server/HTTPRequestHandler.h	Thu Aug 05 14:32:43 2010 +0000
@@ -28,6 +28,7 @@
 //#include "HTTPServer.h"
 
 #include "mbed.h"
+#include "core/netservice.h"
 
 #include <string>
 using std::string;
--- a/services/http/server/HTTPServer.h	Wed Jul 28 12:45:32 2010 +0000
+++ b/services/http/server/HTTPServer.h	Thu Aug 05 14:32:43 2010 +0000
@@ -31,7 +31,7 @@
 class HTTPRequestHandler;
 class HTTPRequestDispatcher;
 
-#include "if/net/net.h"
+#include "core/net.h"
 #include "HTTPRequestHandler.h"
 #include "HTTPRequestDispatcher.h"
 
--- a/services/http/util/url.h	Wed Jul 28 12:45:32 2010 +0000
+++ b/services/http/util/url.h	Thu Aug 05 14:32:43 2010 +0000
@@ -24,7 +24,7 @@
 #ifndef URL_H
 #define URL_H
 
-#include "if/net/ipaddr.h"
+#include "core/ipaddr.h"
 
 #include <string>
 using std::string;
--- a/services/mysql/MySQLClient.h	Wed Jul 28 12:45:32 2010 +0000
+++ b/services/mysql/MySQLClient.h	Thu Aug 05 14:32:43 2010 +0000
@@ -28,7 +28,8 @@
 #ifndef MYSQL_CLIENT_H
 #define MYSQL_CLIENT_H
 
-#include "if/net/net.h"
+#include "core/net.h"
+#include "core/netservice.h"
 #include "api/TCPSocket.h"
 #include "api/DNSRequest.h"
 #include "mbed.h"
--- a/services/ntp/NTPClient.h	Wed Jul 28 12:45:32 2010 +0000
+++ b/services/ntp/NTPClient.h	Thu Aug 05 14:32:43 2010 +0000
@@ -28,7 +28,8 @@
 #ifndef NTP_CLIENT_H
 #define NTP_CLIENT_H
 
-#include "if/net/net.h"
+#include "core/net.h"
+#include "core/netservice.h"
 #include "api/UDPSocket.h"
 #include "api/DNSRequest.h"
 #include "mbed.h"