[En-Nut-Discussion] PPP Retrying when no PPP/GPRS is available
Mike Cornelius
mikec at call-direct.com.au
Wed Sep 24 03:06:51 CEST 2003
Hi Brett,
Second things first, I've not tried interrupting the PPP session whilst
it's going and then going back.
I assume you're thinking something like:
<>PPP[]
>+++
>AT+CSQ?
<+CSQ: ??,??
>ATO
<>PPP[]
But it's certainly an interesting idea and if I get a chance I give it a
whirl and let you know what I find.
On the first point I do things slightly differently and IMHO a little
bit less hackish as folows:-
int fd_ppp = -1;
While (whatever)
{
if (not up and we want to be)
{
if ((fd_ppp != -1) && (pdcb->dcb_ipcp_state !=
PPPS_CLOSED))
{
if (_close(fd_ppp) == 0)
{
ppp_hackup = 0;
fd_ppp = -1;
}
}
DisconnectCall(comm_phone);
if (NutChat(_fileno(comm_phone), confgprs->setup_string)
== 0)
{
if (fd_ppp == -1)
{
fd_ppp = _open("ppp:uart0", _O_RDWR |
_O_BINARY);
ltmp = PHONE_BAUD;
_ioctl(fd_ppp, UART_SETSPEED, <mp);
}
if (NutNetIfConfig("ppp", 0, 0, 0))
{
// If we can't establish PPP 3 times in
a row reboot
ppp_attempts ++;
if (ppp_attempts >= 3)
CDCS_Reboot();
}
else
{
NutDnsConfig2
(0,0,pdcb->dcb_ip_dns1,pdcb->dcb_ip_dns2);
}
}
}
}
Regards,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~
Mike Cornelius Internet: mikec at call-direct.com.au
Call Direct Cellular Solutions Phone: +61 2 9209-4259
Suite 145 FAX: +61 2 9209-4196
National Innovation Centre URL: http://www.call-direct.com.au
Australian Technology Park
Eveleigh NSW 1430
Australia
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~
-----Original Message-----
From: en-nut-discussion-admin at egnite.de
[mailto:en-nut-discussion-admin at egnite.de] On Behalf Of Brett Abbott
Sent: Wednesday, September 24, 2003 10:34 AM
To: en-nut-discussion at egnite.de
Subject: [En-Nut-Discussion] PPP Retrying when no PPP/GPRS is available
Hi
Using the PPP in version 3.3.0, you may find that when a PPP service
(such as a GPRS modem) only partially responds to a Dial command, or the
ifconfig fails, the lcp state engine may time out. Repeated attempts to
redial (atd99*** etc) then seem to fall on deaf ears. A specific
example of this is when the initial chat command is acknowledged (ie.
OK, CONNECT) and then no reponse comes from the PPP engine, it will send
9 retries before going to bed..
Will the kind assistance from Harald, Ive tracked down that in this
timeout scenario, the lcp state is set to STOPPED. When STOPPED, the
subsequent request to perform an "if (NutNetIfConfig("ppp", 0, 0, 0)) "
will not result in any outgoing packets and the ppp thread will remain
STOPPED.
Also, there is a (useful) workaround in place using a the global
variable ppp_hackup. When set to 0, the ppp engine does not attempt to
talk with the interface. We use this to allow chat commands to control
the modem. Note that when set to 1 (when calling NutNetIfConfig), even
if the engine is STOPPED, any characters sent to the interface (like ATD
to reconnect) are absorbed by the ppp engine and rejected as invalid,
never reaching the modem.
The quick fix to this is a two parter.....
First we set the global variable to 0 (ppp_hackup=0), then we tickle the
ppp state machine by setting the lcp_status to STARTING (Using the
lcp_lowerdown function). The ppp_hackup setting stops the newly woken
ppp state machine from saying hi to the modem until we've redone our
dial command. We redial if needed then reprod the engine using "if
(NutNetIfConfig("ppp", 0, 0, 0)) "
Ideally you ought to close the engine and go through a proper
restart/retry but this ought to solve the problem for now. Ive taken
this approach rather than solving it nicely as I know Harald is soon to
modify/improve the way this functionality is to work.
I would like to propose the "ideal" solution but Im still reading the
PPP text book and would greatfully receive thoughts on how it really
ought to be solved.
I include the modified source showing the workaround. Also refer you to
the pppd.c sample in the CVS repository.
Additionally, I am writing commands to pause the PPP interface,
interogate the modem status (ie. go into command mode), execute a
command such as "Signal Strength" and then return to Data Mode (ATO) and
resume PPP. Has anyone else done this? (the ppp_hackup supports this).
Perhaps it is better named "ppp_pause". In the ideal world, I guess
this is done by putting the engine into a known PAUSE state as it is
possible to have more than one PPP interface.
Many Thanks in advance.
Brett
// If the link is lost, it will try to reopen link
if( dcb->dcb_ipcp_state != PPPS_OPENED ) // only proceed if the ppp
isnt opened
{
// Put your code here to ensure the modem is hungup, perhaps :
// sleep 1 second, +++, sleep 1 second, ATH<CR>
// Tell the modem to connect to PPP
if (NutChat(pppcom,"'' 'at+cgdcont=1,\"IP\",\"yourAPN\"' 'OK'
'atd*99***1#' 'CONNECT'") == 0)
{
// attempt to configure the network interface
if (NutNetIfConfig("ppp", 0, 0, 0)) {
fprintf(tcpip1, "PPP failed\r\n");
fflush(tcpip1);
// WORKAROUND CODE STARTS HERE ---- Note ppp_hackup is local
to the ppp code and to work like this you must
// include the library code in
your source or place this code in the library
pppdev = NutDeviceLookup("ppp");
ppp_hackup=0;
rc=NutPppIOCtl(pppdev, LCP_LOWERDOWN, 0);
// WORKAROUND CODE ENDS HERE
NutSleep(5000);
continue; // go back and try again
} else {
// Worked
// * Set name server and default route. Actually the PPP
interface
// * should do this, but the current release doesn't.
dcb = devPpp.dev_dcb;
NutDnsConfig2(0, 0, dcb->dcb_ip_dns1, dcb->dcb_ip_dns2);
NutIpRouteAdd(0, 0, dcb->dcb_remote_ip, &devPpp);
if((rip = NutDnsGetHostByName(INETSERVER)) != 0) {
fprintf(tcpip1, "%s: %s\r\n", INETSERVER,
inet_ntoa(rip));
fflush(tcpip1);
}
}
} else {
// Error with chat
fprintf(tcpip1,"...error in chat \r\n"); fflush(tcpip1);
NutSleep(5000);
continue;
}
}
-----------------------------------------------------------------
Brett Abbott, Managing Director, Digital Telemetry Limited
Email: Brett.Abbott at digital-telemetry.com
PO Box 24 036 Manners Street, Wellington, New Zealand
Phone +64 (4) 5666-860 Mobile +64 (21) 656-144
------------------- Commercial in confidence --------------------
_______________________________________________
En-Nut-Discussion mailing list
En-Nut-Discussion at egnite.de
http://www.egnite.de/mailman/listinfo/en-nut-discussion
More information about the En-Nut-Discussion
mailing list