Hi folks.
A user reported to me having problems while initializing the modem after a while.
The log shows it gets no "OK" after AT&F. I however realized that it might simply not wait long enough. AT&F resets the modem and this might take a while on some old slow phones. Our default timeout of 3 seconds might simply be too slow for those.
I wrote the attached patch to work around this issue and also to retry the first few commands if it failed. This should make initialization more robust. Before I commit it to CVS I however want to have it tested by a couple of modem users with different types of modems to be sure it doesn't screw up something else.
Andreas Fink Fink Consulting GmbH
--------------------------------------------------------------- Tel: +41-61-6666332 Fax: +41-61-6666331 Mobile: +41-79-2457333 Address: Clarastrasse 3, 4058 Basel, Switzerland E-Mail: [EMAIL PROTECTED] Homepage: http://www.finkconsulting.com ---------------------------------------------------------------
--- gw/smsc/smsc_at.c 17 Sep 2004 22:20:50 -0000 1.17
+++ gw/smsc/smsc_at.c 3 Dec 2004 07:38:53 -0000
@@ -417,20 +417,28 @@
gwthread_sleep(0.10);
/* reset the modem */
- if (at2_send_modem_command(privdata, "ATZ", 0, 0) == -1)
- return -1;
+ if (at2_send_modem_command(privdata, "ATZ", 0, 0) == -1) {
+ error(0, "AT2[%s]: modem doesnt like me :(. I'll ignore it for now",
octstr_get_cstr(privdata->name));
+ }
/* check if the modem responded */
if (at2_send_modem_command(privdata, "AT", 0, 0) == -1) {
- error(0, "AT2[%s]: no answer from modem",
octstr_get_cstr(privdata->name));
- return -1;
+ error(0, "AT2[%s]: Wrong or no answer from modem. Trying again",
octstr_get_cstr(privdata->name));
+ if (at2_send_modem_command(privdata, "AT", 0, 0) == -1) {
+ error(0, "AT2[%s]: No luck. get something more reliable",
octstr_get_cstr(privdata->name));
+ return -1;
+ }
}
at2_flush_buffer(privdata);
- if (at2_send_modem_command(privdata, "AT&F", 0, 0) == -1)
- return -1;
-
+ /* AT&F might need a bit a longer timeout as usual */
+ if (at2_send_modem_command(privdata, "AT&F", 7, 0) == -1) {
+ error(0, "AT2[%s]: Modem didnt like my AT&F. Lets give it a
second try", octstr_get_cstr(privdata->name));
+ if (at2_send_modem_command(privdata, "AT&F", 7, 0) == -1) {
+ return -1;
+ }
+ }
if (at2_send_modem_command(privdata, "ATE0", 0, 0) == -1)
return -1;
@@ -565,9 +573,21 @@
}
+/* at_wait_modem_command waits for the response of a previous
+ sent AT command. The return values are
+ -1: got ERROR
+ 0: got OK
+ 1: got >
+ 2: got SIM PIN
+ the function also handles interceptions like "RING"
+ or incoming SMS and handles them accordingly and transparently
+ timeout is 3 seconds by default
+*/
+
int at2_wait_modem_command(PrivAT2data *privdata, time_t timeout, int gt_flag,
int *output)
{
+
Octstr *line = NULL;
Octstr *line2 = NULL;
Octstr *pdu = NULL;
