changeset 370:076d533f840d

fcup-smsend: implemented automatic concat SMS refno generation
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 08 Mar 2018 17:47:58 +0000
parents 06cf82710cca
children 0bd06f481223
files uptools/atcmd/Makefile uptools/atcmd/smsend_concat.c uptools/atcmd/smsend_main.c
diffstat 3 files changed, 72 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/uptools/atcmd/Makefile	Thu Mar 08 16:41:57 2018 +0000
+++ b/uptools/atcmd/Makefile	Thu Mar 08 17:47:58 2018 +0000
@@ -9,8 +9,8 @@
 
 SMDUMP_OBJS=	atinterf.o resp_parse.o smdump.o ${LIBCODING}
 
-SMSEND_OBJS=	atinterf.o resp_parse.o smsend_cmgw.o smsend_main.o \
-		smsend_pdu.o smsend_text.o ${LIBCODING}
+SMSEND_OBJS=	atinterf.o resp_parse.o smsend_cmgw.o smsend_concat.o \
+		smsend_main.o smsend_pdu.o smsend_text.o ${LIBCODING}
 
 all:	${PROGS}
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/uptools/atcmd/smsend_concat.c	Thu Mar 08 17:47:58 2018 +0000
@@ -0,0 +1,61 @@
+/*
+ * This module contains the messy code for automatic generation and
+ * increment of concat SMS reference numbers.
+ */
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/file.h>
+#include <sys/time.h>
+#include <ctype.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include "../../rvinterf/include/exitcodes.h"
+
+static int
+initial_seed()
+{
+	struct timeval tv;
+	u_char refno, *cp, *endp;
+
+	gettimeofday(&tv, 0);
+	cp = (u_char *) &tv;
+	endp = cp + sizeof(struct timeval);
+	refno = 0;
+	while (cp < endp)
+		refno ^= *cp++;
+	return refno;
+}
+
+get_concsms_refno_from_host_fs()
+{
+	char *homedir, statefile[MAXPATHLEN];
+	int fd, cc;
+	char buf[6];
+	u_char refno;
+
+	homedir = getenv("HOME");
+	if (!homedir) {
+		fprintf(stderr,
+		"error: no HOME= defined, needed for concat SMS refno\n");
+		exit(ERROR_UNIX);
+	}
+	sprintf(statefile, "%s/.concat_sms_refno", homedir);
+	fd = open(statefile, O_RDWR|O_CREAT, 0666);
+	if (fd < 0) {
+		perror(statefile);
+		exit(ERROR_UNIX);
+	}
+	cc = read(fd, buf, 5);
+	if (cc == 5 && buf[0] == '0' && buf[1] == 'x' && isxdigit(buf[2]) &&
+	    isxdigit(buf[3]) && buf[4] == '\n')
+		refno = strtoul(buf, 0, 16) + 1;
+	else
+		refno = initial_seed();
+	sprintf(buf, "0x%02X\n", refno);
+	lseek(fd, 0, SEEK_SET);
+	write(fd, buf, 5);
+	close(fd);
+	return refno;
+}
--- a/uptools/atcmd/smsend_main.c	Thu Mar 08 16:41:57 2018 +0000
+++ b/uptools/atcmd/smsend_main.c	Thu Mar 08 17:47:58 2018 +0000
@@ -12,7 +12,8 @@
 
 #define	MAX_MSG_CHARS	(153*255)
 
-int sms_write_mode, text_mode, utf8_input, concat_enable, quiet;
+int sms_write_mode, text_mode, utf8_input, quiet;
+int concat_enable, concat_refno_set;
 u_char dest_addr[12];
 char msgtext[MAX_MSG_CHARS*2+2];
 u_char msgtext_gsm7[MAX_MSG_CHARS];
@@ -26,13 +27,17 @@
 	extern int optind;
 	extern char *optarg;
 
-	while ((c = getopt(argc, argv, "B:C:np:qRtuwWX:")) != EOF) {
+	while ((c = getopt(argc, argv, "B:cC:np:qRtuwWX:")) != EOF) {
 		if (atinterf_cmdline_opt(c))
 			continue;
 		switch (c) {
+		case 'c':
+			concat_enable = 1;
+			continue;
 		case 'C':
 			concat_enable = 1;
 			concat_refno = strtoul(optarg, 0, 0);
+			concat_refno_set = 1;
 			continue;
 		case 'q':
 			quiet = 1;
@@ -186,6 +191,8 @@
 	}
 	if (!concat_enable)
 		goto too_long_for_one_sms;
+	if (!concat_refno_set)
+		concat_refno = get_concsms_refno_from_host_fs();
 	nparts = (msgtext_gsmlen + 152) / 153;
 	udh[0] = 0x00;
 	udh[1] = 0x03;