Hi Everybody,
on the ML i read several reports from users who had problems with unkown
erros during sending sms using the AT smsc.
Usually those messages looked like:
2005-09-10 16:35:55 [28941] [6] DEBUG: AT2[/dev/ttyS0]:
TP-Validity-Period: 24.0 hours
2005-09-10 16:35:55 [28941] [6] DEBUG: AT2[/dev/ttyS0]: --> AT+CMGS=18^M
2005-09-10 16:35:55 [28941] [6] DEBUG: AT2[/dev/ttyS0]: <-- >
2005-09-10 16:35:55 [28941] [6] DEBUG: AT2[/dev/ttyS0]: send command
status: 1
2005-09-10 16:35:55 [28941] [6] DEBUG: AT2[/dev/ttyS0]: -->
0011000B811017077731F40000A704F4F29C0E
2005-09-10 16:35:55 [28941] [6] DEBUG: AT2[/dev/ttyS0]: --> ^Z
2005-09-10 16:36:00 [28941] [6] DEBUG: AT2[/dev/ttyS0]: <-- >
2005-09-10 16:56:00 [28941] [6] DEBUG: AT2[/dev/ttyS0]: <-- ERROR
I tried using kannel for a new project in our company and was facing the
same problem. (Using Various Nokia GSM Phones (6210, 6310, 6230, 6100)
which all exposed this problem.)
In manual tests (e.g. using minicom) the problem also occured if i
pasted the whole PDU at once into the terminal. But once i entered it
manualy everything worked as suppoed. After a lot of try&error i found
that all the phones i was using seem to have problems if more than 18
bytes of PDU are written at once (in fact if you turn echo on you can
see that they simply ignore the remainder).
So i hacked up a little patch that chops the PDU code into 18 byte
chunks and sends them one at a time with a 10 ms sleep in between.
Now it works like a charm :)
Perhaps someone more proficient in C would like to polish that patch a
bit, but at least it works for me now.
Bye
Ulrich
Index: gw/smsc/smsc_at.c
===================================================================
RCS file: /home/cvs/gateway/gw/smsc/smsc_at.c,v
retrieving revision 1.24
diff -u -d -r1.24 smsc_at.c
--- gw/smsc/smsc_at.c 6 May 2005 14:50:27 -0000 1.24
+++ gw/smsc/smsc_at.c 13 Sep 2005 14:17:57 -0000
@@ -1864,6 +1864,7 @@
static void at2_send_one_message(PrivAT2data *privdata, Msg *msg)
{
unsigned char command[500];
+ unsigned char chop[20];
int ret = -1;
char sc[3];
int retries = RETRY_SEND;
@@ -1911,10 +1912,28 @@
* ok the > has been see now so we can send the PDU now and a
* control Z but no CR or LF
*/
- sprintf(command, "%s%s", sc, octstr_get_cstr(pdu));
- at2_write(privdata, command);
- at2_write_ctrlz(privdata);
-
+ // include the CTRL-Z in the PDU String
+ sprintf(command, "%s%s%c", sc, octstr_get_cstr(pdu), 0x1A);
+
+ // chop PDU into 18-byte-at-a-time pieces to prevent choking
+ // of certain GSM Phones (e.g. Nokia 6310, 6230 etc.)
+ if (strlen(command) > 18) {
+ int len = strlen(command);
+ int pos = 0;
+ int ret = 18;
+ while (pos < len) {
+ if (pos + ret > len)
+ ret = len - pos;
+ memcpy(chop,command+pos, ret);
+ pos += ret;
+ chop[ret] = '\0';
+ at2_write(privdata, chop);
+ gwthread_sleep((double)10/1000);
+ }
+ } else {
+ at2_write(privdata, command);
+ }
+
/* wait 20 secs for modem command */
ret = at2_wait_modem_command(privdata, 20, 0, &msg_id);
debug("bb.smsc.at2", 0, "AT2[%s]: send command status: %d",