CMTI support in AT2
Alex Judd <[email protected]>
| Newsgroups | gmane.comp.mobile.kannel.devel |
|---|---|
| Message-ID | <[email protected]> |
Andrea/Oded/All Patch attached to add CMTI support to the AT2 driver. You'll need to add a new definition to your configuration file specifying that the init string for the phones you want to use this is AT+CNMI=1,1,0,0,0 rather than 1,2,0,0,0 and then define your smsc. Here's the excerpts from my config file group=smsc smsc=at2 smsc-id=Motorola1 modemtype=motorola_p7389i device=/dev/com1 ... group = modems id = motorola_p7389i name = "Motorola P7389i" detect-string = "960" speed = 57600 init-string = "AT+CNMI=1,1,0,0,0" need-sleep = true I'm running this here (ran out of Wavecom's!) and it is fine however I would appreciate people testing it and giving me feedback. Cheers Alex -- Alex Judd http://www.skywire.co.uk
smsc_at2.c.diff
(text/plain, 4.3 KB)
Index: smsc_at2.c
===================================================================
RCS file: /home/cvs/gateway/gw/smsc_at2.c,v
retrieving revision 1.35
diff -u -r1.35 smsc_at2.c
--- smsc_at2.c 17 Mar 2002 16:03:37 -0000 1.35
+++ smsc_at2.c 30 Apr 2002 14:49:24 -0000
@@ -257,6 +257,7 @@
int count;
fd_set read_fd;
struct timeval tv;
+ int wait = 30;
if(privdata->fd == -1)
{
@@ -279,6 +280,7 @@
if (ret == -1) {
if (! (errno == EINTR || errno == EAGAIN))
error(errno, "AT2[%s]: error on select",octstr_get_cstr(privdata->name));
+ gwthread_sleep(wait);
return;
}
@@ -654,6 +656,7 @@
time_t cur_time;
Msg *msg;
int len;
+ char *buf, *buf2 = NULL;
time(&end_time);
if(timeout == 0)
@@ -743,6 +746,48 @@
}
continue;
}
+ if (-1 != octstr_search(line, octstr_imm("+CMTI:"), 0))
+ {
+ buf = gw_malloc(5);
+ buf2 = gw_malloc(20);
+
+ octstr_get_many_chars(buf, line, octstr_len(line) - 3, 3); /* work out which message to read */
+ buf[3] = '\0';
+ sprintf(buf2, "%s%s", "AT+CMGR=", buf);
+ at2_write_line(privdata, buf2); /* display message contents */
+ line = at2_wait_line(privdata,1,0); /* read header */
+ line2 = at2_wait_line(privdata,1,0); /* read PDU */
+
+ if(line2 == NULL)
+ {
+ error(0,"AT2[%s]: got +CMTI but waiting for next line timed out", octstr_get_cstr(privdata->name));
+ }
+ else
+ {
+ octstr_append_cstr(line,"\n");
+ octstr_append(line,line2);
+ at2_pdu_extract(privdata, &pdu, line);
+
+ if(pdu == NULL)
+ {
+ error(0,"AT2[%s]: got +CMTI but pdu_extract failed", octstr_get_cstr(privdata->name));
+ }
+ else
+ {
+ msg = at2_pdu_decode(pdu, privdata);
+ if(msg != NULL)
+ {
+ msg->sms.smsc_id = octstr_duplicate(privdata->conn->id);
+ bb_smscconn_receive(privdata->conn, msg);
+ }
+ sprintf(buf2, "%s%s", "AT+CMGD=", buf); /* delete SMS */
+ at2_write_line(privdata, buf2);
+ line = at2_wait_line(privdata,1,0); /* read response */
+ }
+ }
+ gw_free(buf);
+ gw_free(buf2);
+ }
if (-1 != octstr_search(line, octstr_imm("ERROR"), 0))
{
@@ -1130,30 +1175,31 @@
Octstr *buffer;
long len = 0;
int pos = 0;
- int tmp;
+ int tmp = 0;
buffer = octstr_duplicate(line);
- /* find the beginning of a message from the modem*/
- pos = octstr_search(buffer, octstr_imm("+CMT:"), 0);
- if(pos == -1)
- goto nomsg;
- pos += 5;
-
- tmp = octstr_search(buffer, octstr_imm(","), pos);
- if(! privdata->modem->broken && tmp == -1)
- goto nomsg;
- if(tmp != -1)
- pos=tmp + 1;
-
- /* The message length is after the comma */
- pos = octstr_parse_long(&len, buffer, pos, 10);
- if(pos == -1)
- goto nomsg;
+
+ if(octstr_search(buffer, octstr_imm("+CMT:"),0) || octstr_search(buffer, octstr_imm("+CMGR:"),0))
+ {
+ /* find the length of the message */
+ while (tmp > -1) {
+ pos = tmp;
+ tmp = octstr_search(buffer, octstr_imm(","), pos + 1);
+ }
+ if(! privdata->modem->broken && pos == -1)
+ goto nomsg;
+ pos = octstr_parse_long(&len, buffer, pos+1, 10);
+ if (pos < 0)
+ goto nomsg;
+
+ } else {
+ goto nomsg;
+ }
/* skip the spaces and line return */
while( isspace(octstr_get_char(buffer, pos)))
- pos++;
-
+ pos++;
+
/* skip the SMSC address on some modem types */
if(! privdata->modem->no_smsc)
{