sms: Create new util API to encode SCA
authorGuillaume Zajac <guillaume.zajac@linux.intel.com>
Tue, 12 Mar 2013 09:56:52 +0000 (10:56 +0100)
committerwootak.jung <wootak.jung@samsung.com>
Sun, 24 Mar 2013 09:03:05 +0000 (18:03 +0900)
Fix issues in sms header.

include/type/sms.h
include/util.h
src/util.c

index eead21d..0165b4a 100644 (file)
@@ -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              /**<Maximum SMS service center address*/
-#define SMS_MAX_INDEX                                          255             /**< Maximum index value for SMS */
+#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                    164     /**< Maximum SMS data size that can be stored*/
+#define SMS_MAX_INDEX                          255     /**< Maximum index value for SMS */
 
-#define SMS_SMSP_PARAMS_MAX_LEN                                28
+#define SMS_SMSP_PARAMS_MAX_LEN                28
 
 // ************************  CDMA Features  **************************//
 #define SMS_PARAM_TELESERVICE_MASK                                     1 << 0  /**< Teleservice parameter bit position */
@@ -313,12 +311,21 @@ enum telephony_sms_3gpp_type {
 
 
 /**
- * This structure defines the fields related to an Sms like SIM index, TPDU  and length
+ * This structure defines the fields related to an Sms like SIM index, TPDU
+ * and length.
  */
 struct telephony_sms_DataPackageInfo {
-       unsigned char   sca[SMS_SMSP_ADDRESS_LEN];                      /* Service Centre address - an optional parameter. If this parameter is not present, then this field will be Null.If present, the valid service centre address information is filled as per 3GPP TS23.040 9.1.2.5 Address fields */
-       int                     msgLength;                                                      /* Size of array szData (which is actual TPDU message) */
-       unsigned char tpduData[SMS_SMDATA_SIZE_MAX + 1];        /* SMS TPDU message */
+       /*
+        * Service Centre address - an optional parameter. If this parameter
+        * is not present, then this field will be Null.If present, the valid
+        * service centre address information is filled as per 3GPP TS23.040
+        * 9.1.2.5 Address fields
+        */
+       unsigned char sca[SMS_ENCODED_SCA_LEN_MAX];
+       /* Size of array szData (which is actual TPDU message) */
+       int msgLength;
+       /* SMS TPDU message */
+       unsigned char tpduData[SMS_SMDATA_SIZE_MAX + 1];
 };
 
 /**
@@ -889,12 +896,10 @@ struct treq_sms_set_params {
 struct treq_sms_get_paramcnt {
 };
 
-/*----------------------------------*/
-/*                Structs of Responses              */
-/*----------------------------------*/
+
+/* Structs of Responses */
 struct tresp_sms_send_umts_msg {
-       struct telephony_sms_DataPackageInfo    dataInfo;
-       int                                                                     result;
+       int result;
 };
 
 struct tresp_sms_read_msg {
@@ -944,7 +949,6 @@ struct tresp_sms_get_pref_bearer {
 };
 
 struct tresp_sms_set_pref_bearer {
-       int     svc;
        int     result;
 };
 
index 5915e9e..f036fd5 100644 (file)
@@ -76,6 +76,11 @@ enum tcore_dcs_type
             tcore_util_get_cbs_coding_scheme(unsigned char encode);
 
 unsigned char* tcore_util_decode_hex(const char *src, int len);
+long tcore_util_encode_hex(const unsigned char *src, long num_bytes,
+                               char *buf);
+
+int tcore_util_pdu_encode(const unsigned char *sca, const unsigned char *tpdu,
+                               int tpdu_len, char *pdu);
 
 unsigned char*         tcore_util_unpack_gsm7bit(const unsigned char *src, unsigned int src_len);
 unsigned char*         tcore_util_pack_gsm7bit(const unsigned char *src, unsigned int src_len);
index 0b10ba5..487a307 100644 (file)
@@ -36,7 +36,6 @@
 #include "tcore.h"
 #include "util.h"
 
-
 #define        tabGsmUniMax2 9
 #define        tabGsmUniMax 42
 
@@ -1153,6 +1152,61 @@ unsigned char *tcore_util_decode_hex(const char *src, int len)
        return buf;
 }
 
+#define convert_to_hex(in, out) (in <= 9) ? \
+       (out = '0' + in) : (out = 'A' + in - 10)
+
+long tcore_util_encode_hex(const unsigned char *src, long num_bytes,
+                               char *buf)
+{
+       long i, j;
+
+       if (num_bytes <= 0)
+               return -1;
+
+       for (i = 0, j = 0; i < num_bytes; i++, j++) {
+               convert_to_hex(((src[i] >> 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;