summaryrefslogtreecommitdiff
path: root/src/sms_send.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/sms_send.c')
-rw-r--r--src/sms_send.c82
1 files changed, 55 insertions, 27 deletions
diff --git a/src/sms_send.c b/src/sms_send.c
index 8ed7ebb..72b5a13 100644
--- a/src/sms_send.c
+++ b/src/sms_send.c
@@ -39,14 +39,19 @@
#include "pdu_encode.h"
#include "phonebook.h"
+enum {
+ SEND_MODE_CMGW_CMSS,
+ SEND_MODE_CMGS,
+};
+
struct send_options {
char *file;
int alphabet;
const char *smsc_addr;
- int cmgw_first;
+ int send_mode;
};
-static int auto_fill_smsc(int fd, struct pdu_addr *addr)
+static int auto_fill_smsc(int fd, struct sms_addr *addr)
{
char buf[ATCMD_LINE_SIZE];
char *save;
@@ -97,17 +102,17 @@ static int auto_fill_smsc(int fd, struct pdu_addr *addr)
return -1;
}
- return pdu_addr_fill(addr, addr_str, type);
+ return sms_addr_fill(addr, addr_str, type);
}
static int fill_addr(struct phonebook_list_info *list_info,
- struct pdu_addr *addr, const char *addr_str)
+ struct sms_addr *addr, const char *addr_str)
{
struct phonebook_entry *entry;
int type;
int tmp;
- type = pdu_addr_type_infer(addr_str);
+ type = sms_addr_type_infer(addr_str);
if (type != SMS_ADDR_TEXT) {
goto fill;
}
@@ -130,7 +135,7 @@ static int fill_addr(struct phonebook_list_info *list_info,
fill:
- tmp = pdu_addr_fill(addr, addr_str, SMS_ADDR_UNSPEC);
+ tmp = sms_addr_fill(addr, addr_str, SMS_ADDR_UNSPEC);
if (tmp < 0) {
log_debug("pdu fill failed with addr %s", addr_str);
return -1;
@@ -208,7 +213,7 @@ static int do_send(int fd, struct send_options *options, int argc, char **argv)
pdu.data_coding.general.alphabet = options->alphabet;
if (options->smsc_addr) {
- tmp = pdu_addr_fill(&pdu.smsc_addr, options->smsc_addr, SMS_ADDR_UNSPEC);
+ tmp = sms_addr_fill(&pdu.smsc_addr, options->smsc_addr, SMS_ADDR_UNSPEC);
if (tmp < 0) {
return false;
}
@@ -224,18 +229,25 @@ static int do_send(int fd, struct send_options *options, int argc, char **argv)
printf("preparing for send...\n");
}
- if (options->cmgw_first) {
- tmp = pdu_encode(buf, sizeof(buf), &pdu);
- if (tmp < 0) {
- log_error("pdu encode failed");
- return false;
+ if (options->send_mode == SEND_MODE_CMGW_CMSS) {
+ if (Global.core.sms_mode == SMS_PDU_MODE) {
+ tmp = pdu_encode(buf, sizeof(buf), &pdu);
+ if (tmp < 0) {
+ log_error("pdu encode failed");
+ return false;
+ }
}
if (Global.core.verbose) {
printf("writing message to memory\n");
}
- mem_index = atcmd_plus_cmgw_write(fd, buf, pdu.msg_len);
+ if (Global.core.sms_mode == SMS_TEXT_MODE) {
+ mem_index = atcmd_plus_cmgw_write_text(fd, NULL,
+ SMS_ADDR_UNSPEC, NULL, pdu.user_data, pdu.user_data_len);
+ } else {
+ mem_index = atcmd_plus_cmgw_write(fd, buf, pdu.msg_len);
+ }
if (mem_index < 0) {
log_error("write message to memory failed");
return false;
@@ -266,23 +278,30 @@ static int do_send(int fd, struct send_options *options, int argc, char **argv)
continue;
}
- if (options->cmgw_first) {
+ if (options->send_mode == SEND_MODE_CMGW_CMSS) {
tmp = atcmd_plus_cmss_write(fd, mem_index,
- pdu.addr.addr, SMS_ADDR_UNSPEC);
+ pdu.addr.addr, SMS_ADDR_UNSPEC);
if (tmp < 0) {
printf("sending message to %s failed\n", argv[i]);
failed++;
continue;
}
} else {
- tmp = pdu_encode(buf, sizeof(buf), &pdu);
- if (tmp < 0) {
- printf("sending message to %s failed\n", argv[i]);
- failed++;
- continue;
+ if (Global.core.sms_mode == SMS_PDU_MODE) {
+ tmp = pdu_encode(buf, sizeof(buf), &pdu);
+ if (tmp < 0) {
+ printf("sending message to %s failed\n", argv[i]);
+ failed++;
+ continue;
+ }
}
- tmp = atcmd_plus_cmgs_write(fd, buf, pdu.msg_len);
+ if (Global.core.sms_mode == SMS_TEXT_MODE) {
+ tmp = atcmd_plus_cmgs_write_text(fd, pdu.addr.addr,
+ pdu.user_data, pdu.user_data_len);
+ } else {
+ tmp = atcmd_plus_cmgs_write(fd, buf, pdu.msg_len);
+ }
if (tmp < 0) {
printf("sending message to %s failed\n", argv[i]);
failed++;
@@ -305,7 +324,7 @@ static struct option long_options[] = {
{"alphabet", 1, NULL, CMD_OPT_ALPHABET},
{"file", 1, NULL, CMD_OPT_FILE},
{"smsc-addr", 1, NULL, CMD_OPT_SMSC_ADDR},
- {"cmgw-first", 0, NULL, CMD_OPT_CMGW_FIRST},
+ {"send-mode", 1, NULL, CMD_OPT_SEND_MODE},
{NULL, 0, NULL, 0},
};
@@ -315,7 +334,7 @@ void sms_send_help(FILE *out) {
fprintf(out, " --alphabet { seven-bit | eight-bit } |\n");
fprintf(out, " -f, --file <input-file> |\n");
fprintf(out, " --smsc-addr <smsc-addr> |\n");
- fprintf(out, " --cmgw-first\n");
+ fprintf(out, " --send-mode { cmgw-cmss | cmgs } \n");
fprintf(out, " }\n");
fprintf(out, "\n");
}
@@ -330,9 +349,8 @@ int sms_send(int argc, char **argv)
struct send_options options;
options.alphabet = PDU_ALPHABET_DEFAULT;
options.file = NULL;
- options.cmgw_first = false;
+ options.send_mode = SEND_MODE_CMGS;
options.smsc_addr = NULL;
- options.cmgw_first = false;
while ((i = getopt_long(argc, argv, short_options, long_options, &option_index)) >= 0) {
switch (i) {
@@ -344,6 +362,9 @@ int sms_send(int argc, char **argv)
options.alphabet = PDU_ALPHABET_DEFAULT;
} else if (!strcmp(optarg, "eight-bit")) {
options.alphabet = PDU_ALPHABET_EIGHT;
+ } else {
+ sms_send_help(stderr);
+ return false;
}
break;
@@ -355,8 +376,15 @@ int sms_send(int argc, char **argv)
options.smsc_addr = optarg;
break;
- case CMD_OPT_CMGW_FIRST:
- options.cmgw_first = true;
+ case CMD_OPT_SEND_MODE:
+ if (!strcmp(optarg, "cmgw-cmss")) {
+ options.send_mode = SEND_MODE_CMGW_CMSS;
+ } else if (!strcmp(optarg, "cmgs")) {
+ options.send_mode = SEND_MODE_CMGS;
+ } else {
+ sms_send_help(stderr);
+ return false;
+ }
break;
default: