NetServices Stack source

Dependents:   HelloWorld ServoInterfaceBoardExample1 4180_Lab4

Revision:
5:dd63a1e02b1b
Parent:
4:fd826cad83c0
Child:
9:c79fa4034f5b
--- a/if/ppp/PPPNetIf.cpp	Fri Jul 09 14:46:47 2010 +0000
+++ b/if/ppp/PPPNetIf.cpp	Tue Jul 27 15:59:42 2010 +0000
@@ -33,14 +33,13 @@
 #include "netCfg.h"
 #if NET_PPP
 
-#define PPP_TIMEOUT 30000//60000
+#define PPP_TIMEOUT 60000
 
 #define BUF_SIZE 128
 
 PPPNetIf::PPPNetIf(GPRSModem* pIf) : LwipNetIf(), m_pIf(pIf),/* m_open(false),*/ m_connected(false), m_status(PPP_DISCONNECTED), m_fd(0) //, m_id(0)
 {
   //FIXME: Check static refcount
-  pppInit();
   m_buf = new uint8_t[BUF_SIZE];
 }
 
@@ -72,6 +71,7 @@
 PPPErr PPPNetIf::GPRSConnect(const char* apn, const char* userId, const char* password) //Connect using GPRS
 {
   LwipNetIf::init();
+  pppInit();
   //TODO: Tell ATIf that we get ownership of the serial port
     
   GPRSErr gprsErr;
@@ -79,14 +79,14 @@
   if(gprsErr)
     return PPP_NETWORK;
     
-  DBG("\r\nPPPNetIf: If Connected.\r\n");
+  DBG("PPPNetIf: If Connected.\n");
 
   if( userId == NULL )
     pppSetAuth(PPPAUTHTYPE_NONE, NULL, NULL);
   else
     pppSetAuth(PPPAUTHTYPE_PAP, userId, password); //TODO: Allow CHAP as well
     
-  DBG("\r\nPPPNetIf: Set Auth.\r\n");
+  DBG("PPPNetIf: Set Auth.\n");
   
   //wait(1.);
   
@@ -95,14 +95,14 @@
   m_status = PPP_CONNECTING;
   DBG("m_pIf = %p\n", m_pIf);
   int res = pppOverSerialOpen((void*)m_pIf, sPppCallback, (void*)this);
-  DBG("\r\nPPP connected\r\n");
+  DBG("PPP connected\n");
   if(res<0)
   {
     disconnect();
     return PPP_PROTOCOL;
   }
   
-  DBG("\r\nPPPNetIf: PPP Started with res = %d.\r\n", res);
+  DBG("PPPNetIf: PPP Started with res = %d.\n", res);
   
   m_fd = res;
   m_connected = true;
@@ -113,13 +113,13 @@
     poll();
     if(t.read_ms()>PPP_TIMEOUT)
     {
-      DBG("\r\nPPPNetIf: Timeout.\r\n");  
+      DBG("PPPNetIf: Timeout.\n");  
       disconnect();
       return PPP_PROTOCOL;
     }
   }
   
-  DBG("\r\nPPPNetIf: Callback returned.\r\n");
+  DBG("PPPNetIf: Callback returned.\n");
   
   if( m_status == PPP_DISCONNECTED )
   {
@@ -203,11 +203,15 @@
   {
     //No error
     case PPPERR_NONE:
+      {
+        struct ppp_addrs* addrs = (struct ppp_addrs*) arg;
+        m_ip = IpAddr(&(addrs->our_ipaddr)); //Set IP
+      }
       m_status = PPP_CONNECTED;
       break;
     default:
       //Disconnected
-      DBG("\r\nPPPNetIf: Callback errCode = %d.\r\n", errCode);
+      DBG("PPPNetIf: Callback errCode = %d.\n", errCode);
       m_status = PPP_DISCONNECTED;
     break;
   }