diff gen-pdu/settings.c @ 9:003660a57f99

new program sms-gen-tpdu
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 05 Aug 2023 07:43:45 +0000
parents
children 5854e48d0ef7
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gen-pdu/settings.c	Sat Aug 05 07:43:45 2023 +0000
@@ -0,0 +1,129 @@
+/*
+ * This module implements functions for various settings that come before
+ * msg or msg-udh lines.
+ */
+
+#include <sys/types.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <strings.h>
+#include "error.h"
+
+extern int dir_mo, include_sca;
+extern u_char sc_addr[12], user_addr[12];
+extern u_char mr_byte, pid_byte, dcs_byte;
+extern u_char scts_buf[7];
+extern int is_septet, scts_is_set;
+
+extern int input_lineno;
+
+void
+set_sc_addr(argc, argv)
+	char **argv;
+{
+	int rc;
+
+	if (!include_sca) {
+		fprintf(stderr, ERR_PREFIX
+			"sc-addr is not allowed in bare TPDU mode\n",
+			input_lineno);
+		exit(1);
+	}
+	rc = encode_phone_number_arg(argv[1], sc_addr, 0);
+	if (rc < 0) {
+		fprintf(stderr, ERR_PREFIX "invalid phone number argument\n",
+			input_lineno);
+		exit(1);
+	}
+}
+
+void
+set_user_addr(argc, argv)
+	char **argv;
+{
+	int rc;
+
+	rc = encode_phone_number_arg(argv[1], user_addr, 1);
+	if (rc < 0) {
+		fprintf(stderr, ERR_PREFIX "invalid phone number argument\n",
+			input_lineno);
+		exit(1);
+	}
+}
+
+void
+set_mr_byte(argc, argv)
+	char **argv;
+{
+	char *endp;
+
+	if (!dir_mo) {
+		fprintf(stderr, ERR_PREFIX "mr is not allowed in MT mode\n",
+			input_lineno);
+		exit(1);
+	}
+	mr_byte = strtoul(argv[1], &endp, 0);
+	if (*endp) {
+		fprintf(stderr, ERR_PREFIX "invalid byte value argument\n",
+			input_lineno);
+		exit(1);
+	}
+}
+
+void
+set_pid_byte(argc, argv)
+	char **argv;
+{
+	char *endp;
+
+	pid_byte = strtoul(argv[1], &endp, 0);
+	if (*endp) {
+		fprintf(stderr, ERR_PREFIX "invalid byte value argument\n",
+			input_lineno);
+		exit(1);
+	}
+}
+
+void
+set_dcs(argc, argv)
+	char **argv;
+{
+	char *endp;
+
+	dcs_byte = strtoul(argv[1], &endp, 0);
+	if (*endp) {
+		fprintf(stderr, ERR_PREFIX "invalid byte value argument\n",
+			input_lineno);
+		exit(1);
+	}
+	if (!strcmp(argv[2], "septet"))
+		is_septet = 1;
+	else if (!strcmp(argv[2], "octet"))
+		is_septet = 0;
+	else {
+		fprintf(stderr, ERR_PREFIX "invalid septet/octet mode kw\n",
+			input_lineno);
+		exit(1);
+	}
+}
+
+void
+set_scts(argc, argv)
+	char **argv;
+{
+	int rc;
+
+	if (dir_mo) {
+		fprintf(stderr, ERR_PREFIX "sc-ts is not allowed in MO mode\n",
+			input_lineno);
+		exit(1);
+	}
+	rc = encode_gsm_sms_abstime(argv[1], scts_buf);
+	if (rc < 0) {
+		fprintf(stderr, ERR_PREFIX "invalid timestamp argument\n",
+			input_lineno);
+		exit(1);
+	}
+	scts_is_set = 1;
+}