@@ -50,22 +50,15 @@ extern "C" {
50
50
#include " netif/ppp/ppp.h"
51
51
}
52
52
53
- PPPIPInterface::PPPIPInterface (IOStream* pStream, const char * msisdn ) : LwIPInterface(), m_linkStatusSphre(1 ), m_pppErrCode(0 ), m_pStream(pStream), m_streamAvail(true ), m_pppd(-1 )
53
+ PPPIPInterface::PPPIPInterface (IOStream* pStream) : LwIPInterface(), m_linkStatusSphre(1 ), m_pppErrCode(0 ), m_pStream(pStream), m_streamAvail(true ), m_pppd(-1 )
54
54
{
55
- m_connectCmd = new char [strlen (CONNECT_CMD_PREFIX) + strlen (msisdn) + strlen (CONNECT_CMD_SUFFIX) + 1 ];
56
- sprintf (m_connectCmd, " %s%s%s" , CONNECT_CMD_PREFIX, msisdn, CONNECT_CMD_SUFFIX);
57
- m_expectedResp = new char [strlen (m_connectCmd) + strlen (EXPECTED_RESP_SUFFIX) + 1 ];
58
- sprintf (m_expectedResp, " %s%s" , m_connectCmd, EXPECTED_RESP_SUFFIX);
59
- m_expectedRespDatarate = new char [strlen (m_connectCmd) + strlen (EXPECTED_RESP_DATARATE_SUFFIX) + 1 ];
60
- sprintf (m_expectedRespDatarate, " %s%s" , m_connectCmd, EXPECTED_RESP_DATARATE_SUFFIX);
61
55
m_linkStatusSphre.wait ();
62
56
}
63
57
58
+
59
+
64
60
/* virtual*/ PPPIPInterface::~PPPIPInterface ()
65
61
{
66
- delete m_connectCmd;
67
- delete m_expectedResp;
68
- delete m_expectedRespDatarate;
69
62
}
70
63
71
64
/* virtual*/ int PPPIPInterface::init () // Init PPP-specific stuff, create the right bindings, etc
@@ -78,33 +71,34 @@ PPPIPInterface::PPPIPInterface(IOStream* pStream, const char* msisdn) : LwIPInte
78
71
return OK;
79
72
}
80
73
81
- int PPPIPInterface::setup (const char * user, const char * pw)
74
+ int PPPIPInterface::setup (const char * user, const char * pw, const char * msisdn )
82
75
{
83
76
DBG (" Configuring PPP authentication method" );
84
77
pppSetAuth (PPPAUTHTYPE_ANY, user, pw);
78
+ m_msisdn = msisdn;
85
79
DBG (" Done" );
86
80
return OK;
87
81
}
88
82
89
83
/* virtual*/ int PPPIPInterface::connect ()
90
84
{
91
85
int ret;
86
+ char cmd[32 ];
87
+ int cmdLen;
92
88
char buf[32 ];
93
89
size_t len;
94
90
DBG (" Trying to connect with PPP" );
95
91
96
92
cleanupLink ();
97
93
98
- DBG ( " Sending %s " , m_connectCmd );
99
-
100
- ret = m_pStream->write ((uint8_t *)m_connectCmd, strlen (m_connectCmd) , osWaitForever);
94
+ cmdLen = sprintf (cmd, " %s%s%s " , CONNECT_CMD_PREFIX, m_msisdn, CONNECT_CMD_SUFFIX );
95
+ DBG ( " Sending %s " , cmd);
96
+ ret = m_pStream->write ((uint8_t *)cmd, cmdLen , osWaitForever);
101
97
if ( ret != OK )
102
98
{
103
99
return NET_UNKNOWN;
104
100
}
105
101
106
- DBG (" Expect %s" , m_expectedResp);
107
-
108
102
len = 0 ;
109
103
size_t readLen;
110
104
ret = m_pStream->read ((uint8_t *)buf + len, &readLen, EXPECTED_RESP_MIN_LEN, 10000 );
@@ -128,16 +122,21 @@ int PPPIPInterface::setup(const char* user, const char* pw)
128
122
DBG (" Got %s[len %d]" , buf, len);
129
123
130
124
int datarate = 0 ;
131
- if ( (sscanf (buf, m_expectedRespDatarate, &datarate ) != 1 ) && (strcmp (m_expectedResp, buf) != 0 ) )
125
+ strcpy (&cmd[cmdLen], EXPECTED_RESP_DATARATE_SUFFIX);
126
+ if ( (sscanf (buf, cmd, &datarate ) != 1 ))
132
127
{
133
- // Discard buffer
134
- do // Clear buf
128
+ strcpy (&cmd[cmdLen], EXPECTED_RESP_SUFFIX);
129
+ if ( strcmp (cmd, buf) != 0 )
135
130
{
136
- ret = m_pStream->read ((uint8_t *)buf, &len, 32 , 0 );
137
- } while ( (ret == OK) && (len > 0 ) );
138
- return NET_CONN;
139
- }
140
-
131
+ // Discard buffer
132
+ do // Clear buf
133
+ {
134
+ ret = m_pStream->read ((uint8_t *)buf, &len, 32 , 0 );
135
+ } while ( (ret == OK) && (len > 0 ) );
136
+ return NET_CONN;
137
+ }
138
+ }
139
+
141
140
DBG (" Transport link open" );
142
141
if (datarate != 0 )
143
142
{
0 commit comments