Implement set_sms_params to set SCA 69/8469/1
authorwootak.jung <wootak.jung@samsung.com>
Tue, 9 Jul 2013 07:35:13 +0000 (16:35 +0900)
committerwootak.jung <wootak.jung@samsung.com>
Tue, 20 Aug 2013 00:54:33 +0000 (09:54 +0900)
Change-Id: I7bf4630bf9ee0b9ed7695bdee2c170f7e018a2f1

packaging/tel-plugin-atmodem.spec
src/s_common.c
src/s_sms.c

index e83c602645feb544634b4557c503211348dbf96a..44f7e16b72d153a8db90e0fb545dbb49036f723d 100644 (file)
@@ -1,7 +1,7 @@
 #sbs-git:slp/pkgs/t/tel-plugin-atmodem
 Name: tel-plugin-atmodem
 Summary: Telephony AT Modem library
-Version: 0.1.37
+Version: 0.1.38
 Release:    1
 Group:      System/Libraries
 License:    Apache
index 290d20e95d4c3ee9c9b6a53631c5639e7dfd2268..bcb54f96d662c63ddc95338e0815121c9ae62e90 100644 (file)
 
 #include <plugin.h>
 
+#undef MAX
+#define        MAX(a, b)       (((a) > (b)) ? (a) : (b))
+
+#define        bitsize(type) (sizeof(type) * 8)
+
+#define        copymask(type) ((0xffffffff) >> (32 - bitsize(type)))
+
+#define        MASK(width, offset, data) \
+       (((width) == bitsize(data)) ? (data) :   \
+       ((((copymask(data) << (bitsize(data) - ((width) % bitsize(data)))) & copymask(data)) >> (offset)) & (data))) \
+
+
+#define MASK_AND_SHIFT(width, offset, shift, data) \
+       ((((signed) (shift)) < 0) ? \
+       MASK((width), (offset), (data)) << -(shift) : \
+       MASK((width), (offset), (data)) >> (((signed) (shift)))) \
+
+char _util_unpackb(const char *src, int pos, int len);
+char _util_convert_byte_hexChar(char val);
+gboolean util_byte_to_hex(const char *byte_pdu, char *hex_pdu, int num_bytes);
+
+char _util_unpackb(const char *src, int pos, int len)
+{
+       char result = 0;
+       int rshift = 0;
+
+       src += pos / 8;
+       pos %= 8;
+
+       rshift = MAX(8 - (pos + len), 0);
+
+       if (rshift > 0) {
+               result = MASK_AND_SHIFT(len, pos, rshift, (unsigned char)*src);
+       } else {
+               result = MASK(8 - pos, pos, (unsigned char)*src);
+               src++;
+               len -= 8 - pos;
+
+               if (len > 0) result = (result << len) | (*src >> (8 - len));   // if any bits left
+       }
+
+       return result;
+}
+
+char _util_convert_byte_hexChar(char val)
+{
+       char hex_char;
+
+       if (val <= 9) {
+               hex_char = (char) (val + '0');
+       } else if (val >= 10 && val <= 15) {
+               hex_char = (char) (val - 10 + 'A');
+       } else {
+               hex_char = '0';
+}
+
+       return (hex_char);
+}
+
+gboolean util_byte_to_hex(const char *byte_pdu, char *hex_pdu, int num_bytes)
+{
+       int i;
+       char nibble;
+       int buf_pos = 0;
+
+        for (i = 0; i < num_bytes * 2; i++) {
+               nibble = _util_unpackb(byte_pdu, buf_pos, 4);
+               buf_pos += 4;
+               hex_pdu[i] = _util_convert_byte_hexChar(nibble);
+       }
+
+       return TRUE;
+}
 
 void util_hex_dump(char *pad, int size, const void *data)
 {
index 98dcbd48fe904c764b62a2e6826b70238a2b4bbd..d49cdbbe8a7570c86d3c51a8efa765a7da6418f4 100644 (file)
@@ -55,6 +55,8 @@ extern struct ATResponse *sp_response;
 extern char *s_responsePrefix;
 extern enum ATCommandType s_type;
 
+gboolean util_byte_to_hex(const char *byte_pdu, char *hex_pdu, int num_bytes);
+
 static TReturn Send_SmsSubmitTpdu(CoreObject *o, UserRequest *ur);
 
 /************************************************************/
@@ -888,6 +890,49 @@ static void on_response_get_sms_params(TcorePending *p, int data_len, const void
        return;
 }
 
+static void on_response_set_sms_params(TcorePending *p, int data_len,
+                                       const void *data, void *user_data)
+{
+       char *line;
+       int sw1, sw2;
+       int ret;
+       struct tresp_sms_set_params respSetParams;
+       UserRequest *ur = tcore_pending_ref_user_request(p);
+
+       memset(&respSetParams, 0, sizeof(struct tresp_sms_set_params));
+       respSetParams.result = SMS_DEVICE_FAILURE;
+
+       if (sp_response->success != TRUE) {
+               dbg("Response NOK");
+               goto OUT;
+       }
+
+       dbg("Response OK");
+
+       line = sp_response->p_intermediates->line;
+       ret = at_tok_start(&line);
+       if (ret < 0)
+               AT_TOK_ERROR(line);
+
+       ret = at_tok_nextint(&line, &sw1);
+       if (ret < 0)
+               AT_TOK_ERROR(line);
+
+       ret = at_tok_nextint(&line, &sw2);
+       if (ret < 0)
+               AT_TOK_ERROR(line);
+
+       if ((sw1 == 0x90 && sw2 == 0x00) || sw1 == 0x91)
+               respSetParams.result = SMS_SENDSMS_SUCCESS;
+
+OUT:
+       ReleaseResponse();
+       tcore_user_request_send_response(ur, TRESP_SMS_SET_PARAMS,
+                       sizeof(struct tresp_sms_set_params), &respSetParams);
+
+       return;
+}
+
 static void on_response_get_paramcnt(TcorePending *p, int data_len, const void *data, void *user_data)
 {
        UserRequest *ur;
@@ -897,6 +942,8 @@ static void on_response_get_paramcnt(TcorePending *p, int data_len, const void *
        int ret = 0;
        int sw1 = 0;
        int sw2 = 0;
+       int *smsp_record_len;
+       TcorePlugin *plugin = tcore_pending_ref_plugin(p);
 
        ur = tcore_pending_ref_user_request(p);
 
@@ -1262,6 +1309,9 @@ static void on_response_get_paramcnt(TcorePending *p, int data_len, const void *
                        respGetParamCnt.recordCount = num_of_records;
                        respGetParamCnt.result = SMS_SUCCESS;
 
+                       smsp_record_len = tcore_plugin_ref_property(plugin, "SMSPRECORDLEN");
+                       memcpy(smsp_record_len, &record_len, sizeof(int));
+
                        free(recordData);
                }
                else
@@ -1764,8 +1814,56 @@ static TReturn get_sms_params(CoreObject *o, UserRequest *ur)
 
 static TReturn set_sms_params(CoreObject *o, UserRequest *ur)
 {
-       dbg("[tcore_SMS] Not supported");
-       return TCORE_RETURN_ENOSYS;
+       TcorePending *pending;
+       const struct treq_sms_set_params *setSmsParams;
+       struct ATReqMetaInfo metainfo;
+       int *smsp_record_len;
+       int SMSPRecordLen;
+       unsigned char *temp_data;
+       char *encoded_data;
+       int info_len;
+       char *cmd_str;
+       int encoded_data_len;
+       TcorePlugin *plugin = tcore_object_ref_plugin(o);
+       TcoreHal *hal = tcore_object_get_hal(o);
+
+       dbg("Enter");
+
+       setSmsParams = tcore_user_request_ref_data(ur, NULL);
+       smsp_record_len = tcore_plugin_ref_property(plugin, "SMSPRECORDLEN");
+       SMSPRecordLen = *smsp_record_len;
+
+       memset(&metainfo, 0, sizeof(struct ATReqMetaInfo));
+       metainfo.type = SINGLELINE;
+       memcpy(metainfo.responsePrefix, "+CRSM:", strlen("+CRSM:"));
+       info_len = sizeof(struct ATReqMetaInfo);
+       tcore_user_request_set_metainfo(ur, info_len, &metainfo);
+
+       temp_data = calloc(SMSPRecordLen, 1);
+       encoded_data = calloc(SMSPRecordLen * 2 + 1, 1);
+
+       _tcore_util_sms_encode_smsParameters(&(setSmsParams->params),
+                                               temp_data, SMSPRecordLen);
+       util_byte_to_hex((const char *)temp_data,
+                               (char *)encoded_data, SMSPRecordLen);
+
+       encoded_data_len = SMSPRecordLen * 2;
+
+       cmd_str = g_strdup_printf("AT+CRSM=220,28482,%d,4,%d,\"%s%s\"",
+                                       setSmsParams->params.recordIndex + 1,
+                                       SMSPRecordLen, encoded_data, "\r");
+
+       pending = tcore_pending_new(o, ID_RESERVED_AT);
+       tcore_pending_set_request_data(pending, strlen(cmd_str), cmd_str);
+       tcore_pending_set_response_callback(pending, on_response_set_sms_params, NULL);
+       tcore_pending_link_user_request(pending, ur);
+       tcore_pending_set_send_callback(pending, on_confirmation_sms_message_send, NULL);
+
+       free(cmd_str);
+       free(temp_data);
+       free(encoded_data);
+
+       return tcore_hal_send_request(hal, pending);
 }
 
 static TReturn get_paramcnt(CoreObject *o, UserRequest *ur)