Re: USSD Hack
"Donald Jackson" <[email protected]>
| Newsgroups | gmane.comp.mobile.kannel.devel |
|---|---|
| Message-ID | <[email protected]> |
Hey everyone, As requested attached is the patch. It is very rough/incomplete but it might be interesting to someone ;) On Mon, Sep 8, 2008 at 5:44 PM, Stipe Tolj <[email protected]> wrote: > Donald Jackson schrieb: > > Hi everyone, > > > > I have just written a patch to smsc_at to execute USSD commands on a GSM > > modem. Very simply, it will execute the given USSD command at a > > specified interval, and all USSD responses from the modem will be passed > > up to bearerbox as an 'sms' message (source address: USSD). The > > intention of writing this was, to periodically check the balance of a > > prepaid SIM card via USSD and notify me somehow (I used PHP + Growl). > > > > If anyone is interested in this code let me know and I will post it. It > > is strictly *not* an implementation of USSD in Kannel merely just a > gimmick. > > Hi Donald, > > great news. How about posting a 'diff -u' patch against CVS HEAD to the > list, so > everyone in interest can review. > > Stipe > > ------------------------------------------------------------------- > Kölner Landstrasse 419 > 40589 Düsseldorf, NRW, Germany > > tolj.org system architecture Kannel Software Foundation (KSF) > http://www.tolj.org/ http://www.kannel.org/ > > mailto:st_{at}_tolj.org <st_%7Bat%7D_tolj.org> mailto: > stolj_{at}_kannel.org <stolj_%7Bat%7D_kannel.org> > ------------------------------------------------------------------- > -- Donald Jackson http://www.ddj.co.za/ donaldjster(a)gmail.com
ussd.patch
(application/octet-stream, 3.9 KB)
? Kannel
Index: gw/smsc/smsc_at.c
===================================================================
RCS file: /home/cvs/gateway/gw/smsc/smsc_at.c,v
retrieving revision 1.50
diff -u -r1.50 smsc_at.c
--- gw/smsc/smsc_at.c 3 Jul 2008 18:24:24 -0000 1.50
+++ gw/smsc/smsc_at.c 7 Sep 2008 17:03:24 -0000
@@ -787,6 +787,18 @@
at2_write_line(privdata, "ATH0");
continue;
}
+ if (octstr_search(line, octstr_imm("+CUSD:"), 0) != -1) {
+ msg = msg_create(sms);
+ msg->sms.sender = octstr_create("USSD");
+ msg->sms.msgdata = octstr_duplicate(line);
+ msg->sms.time = time(NULL);
+ msg->sms.smsc_id = octstr_duplicate(privdata->conn->id);
+ msg->sms.receiver = octstr_duplicate(privdata->my_number);
+ bb_smscconn_receive(privdata->conn, msg);
+
+ info(0, "AT2[%s]: Got USSD response %s", octstr_get_cstr(privdata->name), octstr_get_cstr(line));
+ continue;
+ }
if (octstr_search(line, octstr_imm("+CPIN: READY"), 0) != -1) {
privdata->pin_ready = 1;
continue;
@@ -1230,7 +1242,7 @@
SMSCConn *conn = arg;
PrivAT2data *privdata = conn->data;
int reconnecting = 0, error_count = 0;
- long idle_timeout, memory_poll_timeout = 0;
+ long idle_timeout, memory_poll_timeout, ussd_timeout = 0;
conn->status = SMSCCONN_CONNECTING;
@@ -1325,6 +1337,7 @@
bb_smscconn_connected(conn);
idle_timeout = 0;
+ ussd_timeout = 0;
while (!privdata->shutdown) {
at2_wait_modem_command(privdata, 1, 0, NULL);
@@ -1346,8 +1359,21 @@
reconnecting = 1;
goto reconnect;
}
+
idle_timeout = time(NULL);
}
+
+ if(privdata->ussd_interval &&
+ ussd_timeout + privdata->ussd_interval < time(NULL)) {
+ if(at2_send_modem_command(privdata,
+ octstr_get_cstr(privdata->ussd_str), 10, 0) < 0)
+ {
+ at2_close_device(privdata);
+ reconnecting = 1;
+ goto reconnect;
+ }
+ ussd_timeout = time(NULL);
+ }
if (privdata->sms_memory_poll_interval &&
memory_poll_timeout + privdata->sms_memory_poll_interval < time(NULL)) {
@@ -1466,6 +1492,7 @@
PrivAT2data *privdata;
Octstr *modem_type_string;
long portno; /* has to be long because of cfg_get_integer */
+ long tmp;
privdata = gw_malloc(sizeof(PrivAT2data));
privdata->outgoing_queue = gw_prioqueue_create(sms_priority_compare);
@@ -1537,6 +1564,16 @@
privdata->login_prompt = cfg_get(cfg, octstr_imm("login-prompt"));
privdata->password_prompt = cfg_get(cfg, octstr_imm("password-prompt"));
modem_type_string = cfg_get(cfg, octstr_imm("modemtype"));
+
+ privdata->ussd_interval = 0;
+ privdata->ussd_str = cfg_get(cfg, octstr_imm("ussd-string"));
+
+ cfg_get_integer(&tmp, cfg, octstr_imm("ussd-interval"));
+ if((tmp > 0) && (privdata->ussd_str != NULL))
+ {
+ privdata->ussd_interval = tmp;
+ }
+
privdata->modem = NULL;
Index: gw/smsc/smsc_at.h
===================================================================
RCS file: /home/cvs/gateway/gw/smsc/smsc_at.h,v
retrieving revision 1.16
diff -u -r1.16 smsc_at.h
--- gw/smsc/smsc_at.h 24 Jun 2008 09:10:04 -0000 1.16
+++ gw/smsc/smsc_at.h 7 Sep 2008 17:03:24 -0000
@@ -139,6 +139,11 @@
Octstr *password;
Octstr *login_prompt;
Octstr *password_prompt;
+
+ Octstr *ussd_str;
+ int ussd_interval;
+
+
int sms_memory_poll_interval;
int sms_memory_capacity;
int sms_memory_usage;
Index: gwlib/cfg.def
===================================================================
RCS file: /home/cvs/gateway/gwlib/cfg.def,v
retrieving revision 1.134
diff -u -r1.134 cfg.def
--- gwlib/cfg.def 26 Jul 2008 09:21:17 -0000 1.134
+++ gwlib/cfg.def 7 Sep 2008 17:03:25 -0000
@@ -385,6 +385,8 @@
OCTSTR(max-sms-octets)
OCTSTR(login-prompt)
OCTSTR(password-prompt)
+ OCTSTR(ussd-interval)
+ OCTSTR(ussd-string)
)