aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDenis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>2022-04-26 02:45:30 +0200
committerDenis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>2022-05-25 03:03:47 +0200
commitc3ca4328aac0440fb90cfce53eafea80aa276c58 (patch)
tree375700012c2d950c88455a565058d8070b04afb3
parent1e5d8f00611a011bb83816d448f89b13f58f8ea7 (diff)
downloadhardware_replicant_libsamsung-ipc-c3ca4328aac0440fb90cfce53eafea80aa276c58.tar.gz
hardware_replicant_libsamsung-ipc-c3ca4328aac0440fb90cfce53eafea80aa276c58.tar.bz2
hardware_replicant_libsamsung-ipc-c3ca4328aac0440fb90cfce53eafea80aa276c58.zip
revert sc address changes
TODO: fix the code We need to revert temporarily to test Guix changes to Valgrind (to get a working Valgrind on ARM since Parabola armv7h's valgrind doesn't work) Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
-rw-r--r--tools/ipc-modem/ipc-modem-sms.c141
-rw-r--r--tools/ipc-modem/ipc-modem-sms.h11
-rw-r--r--tools/ipc-modem/ipc-modem.c16
-rw-r--r--tools/ipc-modem/tests/ipc-modem-sms-test.c20
4 files changed, 75 insertions, 113 deletions
diff --git a/tools/ipc-modem/ipc-modem-sms.c b/tools/ipc-modem/ipc-modem-sms.c
index 07357b2..543de10 100644
--- a/tools/ipc-modem/ipc-modem-sms.c
+++ b/tools/ipc-modem/ipc-modem-sms.c
@@ -27,25 +27,9 @@
#include "ipc-modem-log.h"
#include "ipc-modem-sms.h"
-/* SC address:
- * +------------+---------------------------------------------------+
- * | Size | Content |
- * +------------+---------------------------------------------------+
- * | 1 byte | SC address number of digits |
- * | 1 byte | Flags (Extension, type of number, numbering plan) |
- * | 0+ bytes | SC number |
- * +------------+---------------------------------------------------+
- */
-struct sc_address_header_1 {
- uint8_t length;
- uint8_t flags;
-};
-
/*
* M: Mandatory, O: Optional
- * +------------+---+----------------------------------------------+
* | Size | | Content |
- * +------------+---+----------------------------------------------+
* | 1 byte | M | TP-RP, TP-UDHI, TP-SRI TP-LP, TP-MMS, TP-MTI |
* | 1 byte | M | TP-OA length |
* | 1 byte | M | TP-OA flags |
@@ -55,8 +39,8 @@ struct sc_address_header_1 {
* | 7 bytes | M | TP-SCTS |
* | 1 byte | M | TP-UDL |
* | | O | TP-UD |
- * +------------+---+----------------------------------------------+
*/
+
struct sms_header_1 {
/* TP-RP, TP-UDHI, TP-SRI TP-LP, TP-MMS, TP-MTI */
uint8_t tp_flags;
@@ -73,66 +57,63 @@ struct sms_header_2 {
uint8_t tp_udl;
};
+size_t ipc_modem_sc_address_size_extract(struct ipc_modem_data *data,
+ const char *raw_pdu)
+{
+ return 7;
+}
+
+// TODO: handle memcpy / free
+void *ipc_modem_ts_03_40_pdu_extract(struct ipc_modem_data *data,
+ const char *raw_pdu)
+{
+ size_t sc_address_size;
+
+ sc_address_size = ipc_modem_sc_address_size_extract(data, raw_pdu);
+
+ return (void*)(raw_pdu + 1 + sc_address_size);
+}
+
+size_t *ipc_modem_ts_03_40_pdu_size_extract(struct ipc_modem_data *data,
+ const char *raw_pdu)
+{
+ // return raw_pdu size (sc_address_size + 1);
+}
+
int ipc_modem_parse_sms_pdu(struct ipc_modem_data *data,
- const char *raw_pdu, size_t raw_pdu_size,
+ const char *ts_03_40_pdu, size_t ts_03_40_pdu_size,
struct sms_header **sms_header,
char **sms_text)
{
- size_t tp_oa_len;
- struct sc_address_header_1 *sc_address_header_1;
struct sms_header_1 *header_1;
struct sms_header_2 *header_2;
char *_sms_text;
struct sms_header *_sms_header;
- size_t ts_03_40_pdu_size;
-
uint8_t *tp_ud;
ssize_t pdu_min_header_size;
- size_t offset = 0;
+ ssize_t tp_oa_len;
+ size_t offset;
int rc;
int i;
- if (sms_header) {
- _sms_header = calloc(1, sizeof(struct sms_header));
- /* TODO: check */
- }
-
- sc_address_header_1 = (void*)raw_pdu;
if (sms_header)
- _sms_header->sc_address_length = sc_address_header_1->length;
- offset += 1;
+ _sms_header = calloc(1, sizeof(struct sms_header));
- _sms_header->sc_address_flags = sc_address_header_1->flags;
- offset += 1;
+ pdu_min_header_size = sizeof(struct sms_header_1) +
+ sizeof(struct sms_header_2);
- if (sms_header && sc_address_header_1->length > 0) {
- memcpy(_sms_header->sc_address,
- raw_pdu + offset,
- (sc_address_header_1->length > sizeof(_sms_header->sc_address)) ?
- sizeof(_sms_header->sc_address) : sc_address_header_1->length);
- }
- offset += sc_address_header_1->length;
-
- header_1 = (void*)raw_pdu + offset;
- if (sms_header) {
- _sms_header->tp_flags = header_1->tp_flags;
- _sms_header->tp_oa_len = header_1->tp_oa_len;
- _sms_header->tp_oa_flags = header_1->tp_oa_flags;
+ if (ts_03_40_pdu_size < pdu_min_header_size) {
+ ipc_modem_log(data->client, MODEM_LOG_INFO,
+ "%s: SMS PDU size < minimum SMS PDU header size",
+ __func__);
+ return -EINVAL;
}
- offset += 3;
- tp_oa_len = ((header_1->tp_oa_len + 1) / 2);
- if (sms_header) {
- memcpy(_sms_header->tp_oa_address, raw_pdu + offset,
- tp_oa_len > sizeof(_sms_header->tp_oa_address) ?
- sizeof(_sms_header->tp_oa_address) : tp_oa_len);
- }
- offset += tp_oa_len > sizeof(_sms_header->tp_oa_address) ?
- sizeof(_sms_header->tp_oa_address) : tp_oa_len;
-
- header_2 = ((void*)raw_pdu + offset);
+ header_1 = (void*)ts_03_40_pdu;
+ tp_oa_len = ((header_1->tp_oa_len) / 2 + (header_1->tp_oa_len % 2));
+ header_2 = ((void*)ts_03_40_pdu + sizeof(struct sms_header_1) + tp_oa_len);
/* TODO: check encoding */
if (header_2->tp_udl > IPC_MODEM_MAX_SMS_MESSAGE_SIZE) {
@@ -145,34 +126,28 @@ int ipc_modem_parse_sms_pdu(struct ipc_modem_data *data,
}
if (sms_header) {
+ _sms_header->tp_flags = header_1->tp_flags;
+ _sms_header->tp_oa_len = header_1->tp_oa_len;
+ _sms_header->tp_oa_flags = header_1->tp_oa_flags;
+ memcpy(_sms_header->tp_oa_address,
+ ts_03_40_pdu + sizeof(struct sms_header_1) ,tp_oa_len);
_sms_header->tp_pid = header_2->tp_pid;
_sms_header->tp_dcs = header_2->tp_dcs;
- }
- offset += 2;
- assert(sizeof(_sms_header->tp_scts) == sizeof (header_2->tp_scts));
- if (sms_header) {
- memcpy(_sms_header->tp_scts,
- header_2->tp_scts,
- sizeof(_sms_header->tp_scts));
-
- /* TODO: check if we go over sizeof(pdu_raw) */
- }
- offset += sizeof(_sms_header->tp_scts);
+ assert(sizeof(_sms_header->tp_scts)
+ == sizeof (header_2->tp_scts));
+ for (i=0; i< sizeof(_sms_header->tp_scts); i++)
+ _sms_header->tp_scts[i] = header_2->tp_scts[i];
- _sms_header->tp_udl = header_2->tp_udl;
- offset += 1;
+ _sms_header->tp_udl = header_2->tp_udl;
- if (sms_header) {
+ offset = sizeof(struct sms_header_1)
+ + tp_oa_len + sizeof(struct sms_header_2);
memcpy(_sms_header->tp_ud,
- raw_pdu + offset,
- (raw_pdu_size - offset) > IPC_MODEM_MAX_SMS_MESSAGE_SIZE ?
- IPC_MODEM_MAX_SMS_MESSAGE_SIZE : raw_pdu_size - offset);
+ ts_03_40_pdu + offset,
+ ts_03_40_pdu_size - offset);
}
- offset += (raw_pdu_size - offset) > IPC_MODEM_MAX_SMS_MESSAGE_SIZE ?
- IPC_MODEM_MAX_SMS_MESSAGE_SIZE : (raw_pdu_size - offset);
-
_sms_text = calloc(1, IPC_MODEM_MAX_SMS_MESSAGE_SIZE + 1);
if (_sms_text == NULL) {
rc = errno;
@@ -181,7 +156,7 @@ int ipc_modem_parse_sms_pdu(struct ipc_modem_data *data,
return -rc;
}
- tp_ud = (void*)raw_pdu + offset;
+ tp_ud = (void*)ts_03_40_pdu + pdu_min_header_size + tp_oa_len;
/* TODO: see comment about IPC_MODEM_MAX_SMS_MESSAGE_SIZE */
for(i=0; i < header_2->tp_udl; i++) {
@@ -219,7 +194,7 @@ int ipc_modem_parse_sms_pdu(struct ipc_modem_data *data,
}
int ipc_modem_print_sms_pdu(struct ipc_modem_data *data,
- const char *raw_pdu, size_t raw_pdu_size)
+ const char *ts_03_40_pdu, size_t ts_03_40_pdu_size)
{
struct sms_header *header;
ssize_t tp_oa_len;
@@ -228,7 +203,7 @@ int ipc_modem_print_sms_pdu(struct ipc_modem_data *data,
char *sms_text;
int i, rc;
- rc = ipc_modem_parse_sms_pdu(data, raw_pdu, raw_pdu_size,
+ rc = ipc_modem_parse_sms_pdu(data, ts_03_40_pdu, ts_03_40_pdu_size,
&header, &sms_text);
if (rc)
return rc;
@@ -279,9 +254,9 @@ int ipc_modem_print_sms_pdu(struct ipc_modem_data *data,
ipc_client_log(
data->client,
"================================= SMS PDU data =================================");
- ipc_data_dump(data->client, (void *) raw_pdu,
- raw_pdu_size > 0x100 ?
- 0x100 : raw_pdu_size);
+ ipc_data_dump(data->client, (void *) ts_03_40_pdu,
+ ts_03_40_pdu_size > 0x100 ?
+ 0x100 : ts_03_40_pdu_size);
ipc_client_log(
data->client,
"================================================================================");
diff --git a/tools/ipc-modem/ipc-modem-sms.h b/tools/ipc-modem/ipc-modem-sms.h
index 8eb5766..08581a7 100644
--- a/tools/ipc-modem/ipc-modem-sms.h
+++ b/tools/ipc-modem/ipc-modem-sms.h
@@ -25,17 +25,6 @@
#include "ipc-modem-sms.h"
struct sms_header {
- uint8_t sc_address_length;
- uint8_t sc_address_flags;
- /* From https://en.wikipedia.org/wiki/E.164: "Plan-conforming
- * numbers are limited to a maximum of 15 digits, excluding the
- * international call prefix[1].
- *
- * TODO: Some (german) numbers can be longer in practice if I
- * recall well. Reference: one of the osmocom talks.
- */
- uint8_t sc_address[15];
-
/* TP-RP, TP-UDHI, TP-SRI TP-LP, TP-MMS, TP-MTI */
uint8_t tp_flags;
diff --git a/tools/ipc-modem/ipc-modem.c b/tools/ipc-modem/ipc-modem.c
index 462ee38..eaa8d7a 100644
--- a/tools/ipc-modem/ipc-modem.c
+++ b/tools/ipc-modem/ipc-modem.c
@@ -297,7 +297,7 @@ static void modem_response_sms(struct ipc_modem_data *data,
break;
raw_pdu_size = ipc_sms_incoming_msg_pdu_size_extract(resp->data,
- resp->size);
+ resp->size);
ipc_modem_log(
data->client,
MODEM_LOG_INFO,
@@ -318,10 +318,20 @@ static void modem_response_sms(struct ipc_modem_data *data,
if (raw_pdu == NULL)
break;
- ipc_modem_print_sms_pdu(data, raw_pdu, raw_pdu_size);
+ sc_address_size = ipc_modem_sc_address_size_extract(data,
+ raw_pdu);
+
+ if (raw_pdu_size < sc_address_size)
+ break;
+
+ ts_03_40_pdu = ipc_modem_ts_03_40_pdu_extract(data, raw_pdu);
+ ts_03_40_pdu_size = ipc_modem_ts_03_40_pdu_size_extract(data,
+ raw_pdu);
+
+ ipc_modem_print_sms_pdu(data, ts_03_40_pdu, ts_03_40_pdu_size);
rc = ipc_modem_parse_sms_pdu(data,
- raw_pdu, raw_pdu_size,
+ ts_03_40_pdu, ts_03_40_pdu_size,
NULL, &sms_text);
if (rc < 0)
break;
diff --git a/tools/ipc-modem/tests/ipc-modem-sms-test.c b/tools/ipc-modem/tests/ipc-modem-sms-test.c
index bae02bb..d9bfe3c 100644
--- a/tools/ipc-modem/tests/ipc-modem-sms-test.c
+++ b/tools/ipc-modem/tests/ipc-modem-sms-test.c
@@ -101,28 +101,16 @@ int test_gsmtap_osmocombb(struct ipc_modem_data *data)
"Test #2", "01234567890");
}
-static int run_test(struct ipc_modem_data *data,
- int(*test)(struct ipc_modem_data *data),
- char* name)
+static int run_tests(struct ipc_modem_data *data)
{
int rc;
- rc = test(data);
+ rc = test_gsmtap_osmocombb(data);
if (rc)
- printf("[ !! ] %s test failed\n", name);
+ printf("[ !! ] test_gsmtap_osmocombb test failed\n");
else
- printf("[ OK ] %s test succeded\n", name);
-
- return rc;
-}
-
-static int run_tests(struct ipc_modem_data *data)
-{
- int rc;
-
- // rc |= run_test(data, test_gsmtap_osmocombb, "test_gsmtap_osmocombb");
- rc |= run_test(data, test_gammu_pdu_encode, "test_gammu_pdu_encode");
+ printf("[ OK ] test_gsmtap_osmocombb test succeded\n");
return rc;
}