From 799704e5bb1c7926587c8332b7825aacfdbf2380 Mon Sep 17 00:00:00 2001 From: Guillaume Zajac Date: Tue, 12 Mar 2013 10:56:52 +0100 Subject: [PATCH] sms: Create new util API to encode SCA Fix issues in sms header. --- include/type/sms.h | 54 ++++++++++++++++++++++++++++------------------------ include/util.h | 5 +++++ src/util.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 89 insertions(+), 26 deletions(-) diff --git a/include/type/sms.h b/include/type/sms.h index eead21d..0165b4a 100644 --- a/include/type/sms.h +++ b/include/type/sms.h @@ -58,25 +58,23 @@ __BEGIN_DECLS ==================================================================================================*/ /* NetText */ -#define SMS_SMSP_ADDRESS_LEN 20 /* EF-SMSP digit length */ -#define SMS_SMSP_ALPHA_ID_LEN_MAX 128 /* EF-SMSP alpha id length */ -#define SMS_MAX_EFSMSP_RECORD_LENGTH 156 /* Maximum number of bytes SMSP Record size (Y + 28), y : 0 ~ 128 */ +#define SMS_SMSP_ADDRESS_LEN 20 /* EF-SMSP digit length */ +#define SMS_SMSP_ALPHA_ID_LEN_MAX 128 /* EF-SMSP alpha id length */ +#define SMS_MAX_EFSMSP_RECORD_LENGTH 156 /* Maximum number of bytes SMSP Record size (Y + 28), y : 0 ~ 128 */ -#define SMS_MSG_SIZE_MAX 918 /**< Maximum Message Size */ -#define SMS_CB_SIZE_MAX 93 /** Maximum CB Message Size */ -#define SMS_ETWS_SIZE_MAX 56 /** Maximum ETWS Message Size */ +#define SMS_MSG_SIZE_MAX 918 /**< Maximum Message Size */ +#define SMS_CB_SIZE_MAX 93 /** Maximum CB Message Size */ +#define SMS_ETWS_SIZE_MAX 56 /** Maximum ETWS Message Size */ -#define SMS_ADDRESS_LEN_MAX 20 /* Nettext Address Length */ -#define SMS_SCADDRESS_LEN_MAX 18 /* SC Address Length */ +#define SMS_ENCODED_SCA_LEN_MAX 12 /* Encoded SCA is 12 bytes long maximum */ -#define SMS_CB_PAGE_SIZE_MAX 9 /**< CB maximum page size*/ -#define SMS_GSM_SMS_MSG_NUM_MAX 255 /**< Maximum GSM SMS message number*/ -#define SMS_GSM_SMS_CBMI_LIST_SIZE_MAX 50 /**< Maximum GSM SMS CBMI list size*/ -#define SMS_SMDATA_SIZE_MAX 165 /**< Maximum SMS data size that can be stored*/ -#define SMS_MAX_SMS_SERVICE_CENTER_ADDR 12 /**> 4) & 0xf), buf[j++]); + convert_to_hex((src[i] & 0xf), buf[j]); + } + + buf[j] = '\0'; + + return j; +} + +/* pdu buffer size must be 12 (SCA max length) + 164 (TPDU max length) bytes */ +int tcore_util_pdu_encode(const unsigned char *sca, const unsigned char *tpdu, + int tpdu_len, char *pdu) +{ + int i, sca_len; + unsigned char converted_sca[SMS_ENCODED_SCA_LEN_MAX]; + + if (sca[0] == 0) { + converted_sca[0] = 0; + sca_len = 1; + + goto out; + } + + /* + * For PDU, the SC Address length is the number of packed BCD bytes + * + 1 byte for SC Address type whereas the length given in + * 3GPP 23.040 Address encoding is the number of digits without 1 byte + * for address type. + */ + sca_len = ((sca[0] + 1) / 2) + 1; + + converted_sca[0] = (unsigned char)sca_len; + + for (i = 1; i <= sca_len; i++) + converted_sca[i] = sca[i]; + +out: + memcpy(pdu, converted_sca, sca_len); + memcpy(pdu + sca_len, tpdu, tpdu_len); + + return sca_len + tpdu_len; +} + unsigned char *tcore_util_unpack_gsm7bit(const unsigned char *src, unsigned int src_len) { unsigned char *dest; -- 2.7.4