Changes to support Vodafone K4606
Dependencies: Socket USBHostWANDongle lwip-sys lwip
Fork of VodafoneUSBModem by
Diff: ip/PPPIPInterface.cpp
- Revision:
- 12:66dc2c8eba2d
- Parent:
- 11:565b2ec40dea
- Child:
- 18:1789a11d1892
--- a/ip/PPPIPInterface.cpp Wed Jul 11 12:47:53 2012 +0000 +++ b/ip/PPPIPInterface.cpp Wed Jul 11 21:25:03 2012 +0000 @@ -21,7 +21,13 @@ SOFTWARE. */ -#define __DEBUG__ 2 //Maximum verbosity +#define MSISDN "*99#" + +#define CONNECT_CMD "ATD " MSISDN "\x0D" +#define EXPECTED_RESP CONNECT_CMD "\x0D" "\x0A" "CONNECT" "\x0D" "\x0A" +#define OK_RESP + +#define __DEBUG__ 0 //Maximum verbosity #ifndef __MODULE__ #define __MODULE__ "PPPIPInterface.cpp" #endif @@ -65,7 +71,7 @@ return OK; } -/*virtual*/ int PPPIPInterface::connect(const char* msisdn) +/*virtual*/ int PPPIPInterface::connect() { int ret; char buf[32]; @@ -74,31 +80,41 @@ do //Clear buf { - ret = m_pStream->read(buf, &len, 32, 0) > 0 + ret = m_pStream->read((uint8_t*)buf, &len, 32, 0); } while( (ret == OK) && (len > 0) ); - sprintf(buf, "ATD %16s\x0D"); + DBG("Sending %s", CONNECT_CMD); - ret = m_pStream->write(buf, strlen(buf), osWaitForever); + ret = m_pStream->write((uint8_t*)CONNECT_CMD, strlen(CONNECT_CMD), osWaitForever); if( ret != OK ) { return NET_UNKNOWN; } - const char expected = "\x0D\0x0ACONNECT\x0D\0x0A"; - - ret = m_pStream->read(buf, strlen(expected), &len, 3000); - if( ret != OK ) + DBG("Expect %s [len %d]", EXPECTED_RESP, strlen(EXPECTED_RESP)); + + len = 0; + while(len < strlen(EXPECTED_RESP)) { + size_t readLen; + ret = m_pStream->read((uint8_t*)buf + len, &readLen, strlen(EXPECTED_RESP) - len, 10000); + if( ret != OK ) + { return NET_UNKNOWN; + } + len += readLen; } - if( (len < strlen(expected)) || (memcmp(expected, buf) != 0) ) + buf[len]=0; + + DBG("Got %s[len %d]", buf, len); + + if( memcmp(EXPECTED_RESP, buf, strlen(EXPECTED_RESP)) != 0 ) { //Discard buffer do //Clear buf { - ret = m_pStream->read(buf, &len, 32, 0) > 0 + ret = m_pStream->read((uint8_t*)buf, &len, 32, 0); } while( (ret == OK) && (len > 0) ); return NET_CONN; } @@ -109,7 +125,8 @@ { return NET_INVALID; } - int ret = pppOverSerialOpen(this, PPPIPInterface::linkStatusCb, this); + + ret = pppOverSerialOpen(this, PPPIPInterface::linkStatusCb, this); if(ret < 0) { switch(ret)