summaryrefslogtreecommitdiff
path: root/src/atcmd.c
diff options
context:
space:
mode:
authorJames Maki <jmaki@multitech.com>2010-04-28 09:57:12 -0500
committerJames Maki <jmaki@multitech.com>2010-04-28 09:57:12 -0500
commit223246228c5224a91147a98dc394ea60efab81ef (patch)
tree657adf4bbf1c59be35a37cadef783d0a8e1d3567 /src/atcmd.c
parenta2848ad713af4d78cf0326dcf44a36bba3e93e40 (diff)
downloadsms-utils-223246228c5224a91147a98dc394ea60efab81ef.tar.gz
sms-utils-223246228c5224a91147a98dc394ea60efab81ef.tar.bz2
sms-utils-223246228c5224a91147a98dc394ea60efab81ef.zip
optional at command init
Diffstat (limited to 'src/atcmd.c')
-rw-r--r--src/atcmd.c74
1 files changed, 64 insertions, 10 deletions
diff --git a/src/atcmd.c b/src/atcmd.c
index 10470c1..55d2ebc 100644
--- a/src/atcmd.c
+++ b/src/atcmd.c
@@ -566,6 +566,21 @@ int atcmd_e_write(int fd, int mode)
return 0;
}
+int atcmd_v_write(int fd, int mode)
+{
+ char buf[ATCMD_LINE_SIZE];
+ int tmp;
+
+ atcmd_writeline(fd, "ATV%d", mode);
+ tmp = atcmd_expect_line(fd, buf, sizeof(buf), "OK");
+ if (tmp <= 0) {
+ log_debug("expected OK but it was not received");
+ return -1;
+ }
+
+ return 0;
+}
+
int atcmd_plus_cmgf_write(int fd, int mode)
{
char buf[ATCMD_LINE_SIZE];
@@ -1045,30 +1060,39 @@ int atcmd_plus_cpbr_test(int fd, struct phonebook_store *store)
int atcmd_init(int fd, int read_timeout)
{
- char buf[ATCMD_LINE_SIZE];
int tmp;
- tmp = tty_set_read_timeout(fd, read_timeout);
+ tmp = atcmd_v_write(fd, 1);
if (tmp < 0) {
return tmp;
}
- atcmd_writeline(fd, "ATV1");
- tmp = atcmd_expect_line(fd, buf, sizeof(buf), "OK");
- if (tmp <= 0) {
- log_debug("expected OK but it was not received");
- return -1;
- }
-
tmp = atcmd_e_write(fd, 0);
if (tmp < 0) {
return tmp;
}
+ return 0;
+}
+
+static int sms_atcmd_init(int fd)
+{
+ int tmp;
+
struct msg_store read_store;
struct msg_store send_store;
struct msg_store new_store;
+ tmp = atcmd_init(fd, Global.core.read_timeout);
+ if (tmp < 0) {
+ return -1;
+ }
+
+ tmp = atcmd_plus_cmgf_write(fd, SMS_PDU_MODE);
+ if (tmp < 0) {
+ return -1;
+ }
+
memset(&read_store, 0, sizeof(read_store));
memset(&send_store, 0, sizeof(send_store));
memset(&new_store, 0, sizeof(new_store));
@@ -1079,9 +1103,39 @@ int atcmd_init(int fd, int read_timeout)
&send_store.selected, &new_store.selected);
if (Global.core.msg_store_read && Global.core.msg_store_send &&
Global.core.msg_store_new) {
- atcmd_plus_cpms_write(fd, Global.core.msg_store_read,
+ tmp = atcmd_plus_cpms_write(fd, Global.core.msg_store_read,
Global.core.msg_store_send, Global.core.msg_store_new);
+ if (tmp < 0) {
+ return -1;
+ }
}
return 0;
}
+
+int sms_device_open(void)
+{
+ int fd;
+ int tmp;
+
+ fd = tty_open(Global.core.device, Global.core.baud_rate);
+ if (fd < 0) {
+ return -1;
+ }
+
+ tmp = tty_set_read_timeout(fd, Global.core.read_timeout);
+ if (tmp < 0) {
+ close(fd);
+ return tmp;
+ }
+
+ if (Global.core.sms_init) {
+ tmp = sms_atcmd_init(fd);
+ if (tmp < 0) {
+ close(fd);
+ return tmp;
+ }
+ }
+
+ return fd;
+}