#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)
{
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);
/************************************************************/
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;
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);
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
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)