blob: ed9c1b3acf33bf6f902b63c0593145ab311de31e [file] [log] [blame]
b.liu4e243dc2023-11-27 11:20:00 +08001#include "lynq_qser_sms.h"
2#include "mbtk_type.h"
r.xiaodac82562023-12-07 18:22:32 -08003#include "mbtk_pdu_sms.h"
4#include "mbtk_info_api.h"
5#include "lynq_sms.h"
r.xiaoba8483c2024-04-14 18:53:10 -07006#include "mbtk_log.h"
b.liu5fa9e772023-11-23 18:00:55 +08007
r.xiaodac82562023-12-07 18:22:32 -08008
9#include <stdio.h>
10#include <stdlib.h>
11
12
13#define TELEPHONE_NUM_MAX 16
14#define MSM_NUMBER_MAX 1024+1
15#define RES_NUM_MIN 128
16
17
18#define DSC_to_msg(DSC) (DSC == 0 ? "Bit7" : (DSC == 1 ? "Bit8" : "UCS2"))
19
20static mbtk_info_handle_t* sms_info_handle = NULL;
21static char sms_center_address[128] = {0};
22
r.xiaoefee0062023-12-29 19:35:43 -080023typedef struct
24{
25 QSER_SMS_RxMsgHandlerFunc_t handlerPtr;
26 void* contextPtr;
27} lynq_sms_cb_func;
28
29static lynq_sms_cb_func lynq_sms_func_cb_handle;
30
31sms_client_handle_type g_sms_val = -1;
32
r.xiaodac82562023-12-07 18:22:32 -080033
34void lynq_sms_state_change_cb(const void* data, int data_len)
35{
36 LOGV("sms_state_change_cb()----------start\n");
37 uint8 *ptr = (uint8*)data;
r.xiaoefee0062023-12-29 19:35:43 -080038 //printf("3sms_state_change_cb() : %s\n", ptr);
39
40 if (!strncmp("+CMT:", ptr, 5))//丢弃无用消息
41 return ;
r.xiaodac82562023-12-07 18:22:32 -080042
43 struct SMS_Struct s = PDUDecoding(ptr);
r.xiaoefee0062023-12-29 19:35:43 -080044 /*
r.xiaodac82562023-12-07 18:22:32 -080045 printf("服务中心地址: %s\n", s.SCA);
46 printf("发送方地址: %s\n", s.OA);
47 printf("服务中心时间戳: %s\n", s.SCTS);
48 printf("消息内容: %s\n", s.UD);
49 printf("数据编码方案: %s\n", DSC_to_msg(s.DCS));
r.xiaoefee0062023-12-29 19:35:43 -080050 */
51 QSER_SMS_Msg_t* tmp_data = NULL;
52
53 tmp_data = (QSER_SMS_Msg_t*)malloc(sizeof(QSER_SMS_Msg_t));
54 memset(tmp_data,0x00, sizeof(QSER_SMS_Msg_t));
55
56 tmp_data->format = s.DCS;
57 //printf("t数据编码方案: %d\n", tmp_data->format);
58 memcpy(tmp_data->src_addr, s.OA, strlen(s.OA));
59 //printf("t发送方地址: %s\n", tmp_data->src_addr);
60 memcpy(tmp_data->timestamp, s.SCTS, strlen(s.SCTS));
61 //printf("t服务中心时间戳: %s\n", tmp_data->timestamp);
62 tmp_data->sms_data_len = strlen(s.UD);
63 //printf("t消息内容长度: %d\n", tmp_data->sms_data_len);
64 memcpy(tmp_data->sms_data, s.UD, strlen(s.UD));
65 //printf("t消息内容: %s\n", tmp_data->sms_data);
66
67 lynq_sms_func_cb_handle.handlerPtr(tmp_data, NULL);
68
69 free(tmp_data);
70
r.xiaodac82562023-12-07 18:22:32 -080071}
72
73
74int qser_sms_client_init(sms_client_handle_type *ph_sms)//out
b.liu5fa9e772023-11-23 18:00:55 +080075{
r.xiaoefee0062023-12-29 19:35:43 -080076 //UNUSED(ph_sms);
b.liu5fa9e772023-11-23 18:00:55 +080077
r.xiaodac82562023-12-07 18:22:32 -080078 if(sms_info_handle == NULL)
79 {
80 sms_info_handle = mbtk_info_handle_get();
81 if(sms_info_handle)
82 {
r.xiaoeb9dba42024-02-07 02:16:13 -080083 LOGI("creat sms_info_handle is success");
r.xiaoefee0062023-12-29 19:35:43 -080084 *ph_sms = sms_info_handle->client_fd;
85 g_sms_val = sms_info_handle->client_fd;
r.xiaodac82562023-12-07 18:22:32 -080086 }
87 else
88 {
r.xiaoeb9dba42024-02-07 02:16:13 -080089 LOGE("creat sms_info_handle is fail");
r.xiaoefee0062023-12-29 19:35:43 -080090 return -1;
r.xiaodac82562023-12-07 18:22:32 -080091 }
92 }
93
r.xiaoefee0062023-12-29 19:35:43 -080094 return 0;
b.liu5fa9e772023-11-23 18:00:55 +080095}
96
r.xiaodac82562023-12-07 18:22:32 -080097int qser_sms_client_deinit(sms_client_handle_type h_sms)//in
b.liu5fa9e772023-11-23 18:00:55 +080098{
r.xiaoefee0062023-12-29 19:35:43 -080099 //UNUSED(h_sms);
100 if (h_sms != g_sms_val || g_sms_val == -1)
101 {
r.xiaoeb9dba42024-02-07 02:16:13 -0800102 LOGE("handle NULL\n");
r.xiaoefee0062023-12-29 19:35:43 -0800103 return -1;
104 }
105
r.xiaofca7c472024-04-24 01:00:23 -0700106 mbtk_sms_state_change_cb_reg(sms_info_handle, NULL);
107
r.xiaodac82562023-12-07 18:22:32 -0800108 if(sms_info_handle)
109 {
r.xiaoefee0062023-12-29 19:35:43 -0800110 mbtk_info_handle_free(&sms_info_handle);
r.xiaoeb9dba42024-02-07 02:16:13 -0800111 LOGI("deinit sms_info_handle is succuess");
r.xiaodac82562023-12-07 18:22:32 -0800112 }
113 else
114 {
r.xiaoeb9dba42024-02-07 02:16:13 -0800115 LOGE("deinit sms_info_handle is fail");
r.xiaoefee0062023-12-29 19:35:43 -0800116 return -1;
r.xiaodac82562023-12-07 18:22:32 -0800117 }
118
r.xiaoefee0062023-12-29 19:35:43 -0800119 return 0;
b.liu5fa9e772023-11-23 18:00:55 +0800120}
121
r.xiaodac82562023-12-07 18:22:32 -0800122int qser_sms_send_sms(sms_client_handle_type h_sms, QSER_sms_info_t *pt_sms_info)//in in 发送短信的内容、目的号码
b.liu5fa9e772023-11-23 18:00:55 +0800123{
r.xiaoefee0062023-12-29 19:35:43 -0800124 //UNUSED(h_sms);
r.xiaodac82562023-12-07 18:22:32 -0800125 //UNUSED(pt_sms_info);
r.xiaoefee0062023-12-29 19:35:43 -0800126 if (h_sms != g_sms_val || g_sms_val == -1)
127 {
r.xiaoeb9dba42024-02-07 02:16:13 -0800128 LOGE("handle NULL");
r.xiaoefee0062023-12-29 19:35:43 -0800129 return -1;
130 }
131
r.xiaoefee0062023-12-29 19:35:43 -0800132 if (pt_sms_info == NULL)
133 {
r.xiaoeb9dba42024-02-07 02:16:13 -0800134 LOGE("QSER_sms_info_t NULL");
r.xiaoefee0062023-12-29 19:35:43 -0800135 return -1;
136 }
b.liu5fa9e772023-11-23 18:00:55 +0800137
r.xiaodac82562023-12-07 18:22:32 -0800138 if(sms_info_handle == NULL)
139 {
r.xiaoeb9dba42024-02-07 02:16:13 -0800140 LOGE("qser_sms_send_sms sms_info_handle NULL");
r.xiaoefee0062023-12-29 19:35:43 -0800141 return -1;
r.xiaodac82562023-12-07 18:22:32 -0800142 }
143
r.xiaoefee0062023-12-29 19:35:43 -0800144 uint8_t *phone_num = NULL, *data = NULL;
145
r.xiaodac82562023-12-07 18:22:32 -0800146 char cmgs[MSM_NUMBER_MAX] = {0};
147 char resp[RES_NUM_MIN] = {0};
148 char pdu_data[512] = {0};
149 char phone_lenth[10] = {0};
r.xiaoe73f8702024-01-06 01:40:03 -0800150 char mem[10] = {0};
r.xiaodac82562023-12-07 18:22:32 -0800151 char *p = pdu_data;
152 int mode = 0;
153 int err = 0;
154 int i = 0;
155
156 data = pt_sms_info->sms_data;
157
158 phone_num = pt_sms_info->src_addr;
159
160 if (pt_sms_info->format == 0)//7
161 mode = 1;
162 else if (pt_sms_info->format == 1)//8
163 return SMS_ERR;
164 else if (pt_sms_info->format == 2)//USC2
165 mode = 0;
166 else
r.xiaoefee0062023-12-29 19:35:43 -0800167 return -1;
r.xiaodac82562023-12-07 18:22:32 -0800168
r.xiaoe73f8702024-01-06 01:40:03 -0800169 //设置存储器
r.xiaod3256ae2024-02-28 23:20:55 -0800170/*
r.xiaoe73f8702024-01-06 01:40:03 -0800171 if (pt_sms_info->storage == 0)
172 {
r.xiaoeb9dba42024-02-07 02:16:13 -0800173 strcpy(mem, "SM");
r.xiaoe73f8702024-01-06 01:40:03 -0800174 }
175 else if (pt_sms_info->storage == 1)
176 {
r.xiaoeb9dba42024-02-07 02:16:13 -0800177 strcpy(mem, "ME");
r.xiaoe73f8702024-01-06 01:40:03 -0800178 }
179 else
180 {
r.xiaoeb9dba42024-02-07 02:16:13 -0800181 LOGE("qser_sms_deletefromstorage storage is no Support");
r.xiaoec113d12024-01-12 02:13:28 -0800182 return -1;
r.xiaoe73f8702024-01-06 01:40:03 -0800183 }
184
185 memset(resp, 0, sizeof(resp));
186 err = mbtk_sms_cpms_set(sms_info_handle, mem, resp);
187 if(err) {
r.xiaoeb9dba42024-02-07 02:16:13 -0800188 LOGE("Error : %d", err);
r.xiaoe73f8702024-01-06 01:40:03 -0800189 } else {
r.xiaoeb9dba42024-02-07 02:16:13 -0800190 LOGI("cpms set success. resp:%s", resp);
r.xiaoe73f8702024-01-06 01:40:03 -0800191 }
r.xiaod3256ae2024-02-28 23:20:55 -0800192*/
r.xiaodac82562023-12-07 18:22:32 -0800193 if(data == NULL)
194 {
r.xiaoeb9dba42024-02-07 02:16:13 -0800195 LOGE("qser_sms_send_sms data NULL");
r.xiaoefee0062023-12-29 19:35:43 -0800196 return -1;
r.xiaodac82562023-12-07 18:22:32 -0800197 }
198
199 if(phone_num == NULL)
200 {
r.xiaoeb9dba42024-02-07 02:16:13 -0800201 LOGE("qser_sms_send_sms phone_num NULL");
r.xiaoefee0062023-12-29 19:35:43 -0800202 return -1;
r.xiaodac82562023-12-07 18:22:32 -0800203 }
204
r.xiaoefee0062023-12-29 19:35:43 -0800205 if(strlen(data) > 512 || strlen(data) == 0 || strlen(phone_num) == 0)
r.xiaodac82562023-12-07 18:22:32 -0800206 {
r.xiaoeb9dba42024-02-07 02:16:13 -0800207 LOGE("strlen(telephony_num):%d", strlen(phone_num));
208 LOGE("strlen(msg):%d", strlen(data));
r.xiaoefee0062023-12-29 19:35:43 -0800209 return -1;
r.xiaodac82562023-12-07 18:22:32 -0800210 }
211
r.xiaodac82562023-12-07 18:22:32 -0800212 if (mode == 0)// PDU
213 {
214#if 1
215 if (sms_center_address[0] == '\0')
216 {
217 memset(sms_center_address, 0, sizeof(sms_center_address));
218 memcpy(sms_center_address, "+8613800280500", strlen("+8613800280500"));
219 }
220
r.xiaoec113d12024-01-12 02:13:28 -0800221 //printf("phone_num:%s\n", phone_num);
222 //printf("sms_center_address:%s\n", sms_center_address);
223 //printf("data:%s\n", data);
r.xiaodac82562023-12-07 18:22:32 -0800224
225 char* pdu = NULL;
226 char* smsc = SCAEncoding(sms_center_address);
227 struct PDUS *pdus = PDUEncoding(sms_center_address,phone_num, data, NULL);
228
229 for (i = 0; i < pdus->count; i++)
230 {
r.xiaoeb9dba42024-02-07 02:16:13 -0800231 LOGI("第 %d 条:", i + 1);
232 LOGI("%s\n", pdus->PDU[i]);
r.xiaodac82562023-12-07 18:22:32 -0800233 pdu = pdus->PDU[i];
234 }
235
236 sprintf(p, "%s",smsc);
r.xiaoeb9dba42024-02-07 02:16:13 -0800237 LOGI("pdu_data:%s", pdu_data);
r.xiaodac82562023-12-07 18:22:32 -0800238 sprintf(p+strlen(p), "%s", pdu);
r.xiaoeb9dba42024-02-07 02:16:13 -0800239 LOGI("pdu_data:%s",pdu_data);
r.xiaodac82562023-12-07 18:22:32 -0800240
241 //sprintf(cmgs,"%d,%s",strlen(pdu_data), pdu_data);
242 int t = strlen(pdu_data);
243 sprintf(cmgs,"%d,%s",(t-18)/2, pdu_data);
r.xiaoeb9dba42024-02-07 02:16:13 -0800244 LOGI("cmgs:%s", cmgs);
r.xiaodac82562023-12-07 18:22:32 -0800245#else
246 char *tmp_t = "0891683108200805F011000D91688189914026F3000800044F60597D";
247 sprintf(cmgs,"%d,%s",19,tmp_t);
248 printf("cmgs:%s\n", cmgs);
249#endif
250
251 memset(resp, 0, sizeof(resp));
252
253 err = mbtk_sms_cmgf_set(sms_info_handle, mode);
254 if(err)
255 {
r.xiaoeb9dba42024-02-07 02:16:13 -0800256 LOGE("cmgf set error : %d", err);
r.xiaodac82562023-12-07 18:22:32 -0800257 }
258 else
259 {
r.xiaoeb9dba42024-02-07 02:16:13 -0800260 LOGI("cmgf set success");
r.xiaodac82562023-12-07 18:22:32 -0800261 }
262
263 err = mbtk_sms_cmgs_set(sms_info_handle, cmgs, resp);
264 if(err)
265 {
r.xiaoeb9dba42024-02-07 02:16:13 -0800266 LOGE("Error : %d", err);
r.xiaoefee0062023-12-29 19:35:43 -0800267 return -1;
r.xiaodac82562023-12-07 18:22:32 -0800268 }
269 else
270 {
r.xiaoeb9dba42024-02-07 02:16:13 -0800271 LOGI("cmgs set success . resp:%s", resp);
r.xiaodac82562023-12-07 18:22:32 -0800272 }
273 }
274 else if (mode == 1) // text
275 {
276 err = mbtk_sms_cmgf_set(sms_info_handle, mode);
277 if(err)
278 {
r.xiaoeb9dba42024-02-07 02:16:13 -0800279 LOGE("cmgf set error : %d", err);
r.xiaodac82562023-12-07 18:22:32 -0800280 }
281 else
282 {
r.xiaoeb9dba42024-02-07 02:16:13 -0800283 LOGI("cmgf set success");
r.xiaodac82562023-12-07 18:22:32 -0800284 }
285
286 sprintf(cmgs,"%s,%s", phone_num, data);
r.xiaoeb9dba42024-02-07 02:16:13 -0800287 LOGI("cmgs:%s", cmgs);
r.xiaodac82562023-12-07 18:22:32 -0800288
289 memset(resp, 0, sizeof(resp));
290
291 err = mbtk_sms_cmgs_set(sms_info_handle, cmgs, resp);
292 if(err)
293 {
r.xiaoeb9dba42024-02-07 02:16:13 -0800294 LOGE("Error : %d", err);
r.xiaoefee0062023-12-29 19:35:43 -0800295 return -1;
r.xiaodac82562023-12-07 18:22:32 -0800296 }
297 else
298 {
r.xiaoeb9dba42024-02-07 02:16:13 -0800299 LOGI("cmgs set success . resp:%s", resp);
r.xiaodac82562023-12-07 18:22:32 -0800300 }
301 }
302 else
303 {
r.xiaoeb9dba42024-02-07 02:16:13 -0800304 LOGE("Error : mode");
r.xiaoefee0062023-12-29 19:35:43 -0800305 return -1;
r.xiaodac82562023-12-07 18:22:32 -0800306 }
r.xiaoefee0062023-12-29 19:35:43 -0800307
308 return 0;
b.liu5fa9e772023-11-23 18:00:55 +0800309}
310
r.xiaodac82562023-12-07 18:22:32 -0800311//注册接收新短信
312int qser_sms_addrxmsghandler(QSER_SMS_RxMsgHandlerFunc_t handlerPtr, void* contextPtr)//in sms电话状态回调函数 in 主要是获取 上报 的内容
b.liu5fa9e772023-11-23 18:00:55 +0800313{
r.xiaoefee0062023-12-29 19:35:43 -0800314 //UNUSED(handlerPtr);
315 //UNUSED(contextPtr);
b.liu5fa9e772023-11-23 18:00:55 +0800316
r.xiaodac82562023-12-07 18:22:32 -0800317 if(sms_info_handle == NULL)
318 {
r.xiaoeb9dba42024-02-07 02:16:13 -0800319 LOGE("qser_sms_addrxmsghandler sms_info_handle NULL");
r.xiaoefee0062023-12-29 19:35:43 -0800320 return -1;
r.xiaodac82562023-12-07 18:22:32 -0800321 }
322
323 int err = mbtk_sms_cnmi_set(sms_info_handle);
324 if(err)
325 {
r.xiaoeb9dba42024-02-07 02:16:13 -0800326 LOGE("set cnmi fail");
r.xiaoefee0062023-12-29 19:35:43 -0800327 return -1;
r.xiaodac82562023-12-07 18:22:32 -0800328 }
329
r.xiaoefee0062023-12-29 19:35:43 -0800330 lynq_sms_func_cb_handle.handlerPtr = handlerPtr;
331 lynq_sms_func_cb_handle.contextPtr = contextPtr;
332
r.xiaodac82562023-12-07 18:22:32 -0800333 mbtk_sms_state_change_cb_reg(sms_info_handle, lynq_sms_state_change_cb);
334
r.xiaoefee0062023-12-29 19:35:43 -0800335 return 0;
b.liu5fa9e772023-11-23 18:00:55 +0800336}
337
r.xiaodac82562023-12-07 18:22:32 -0800338//删除短信
339int qser_sms_deletefromstorage(sms_client_handle_type h_sms, QSER_sms_storage_info_t *pt_sms_storage)//in in 删除短信的信息
b.liu5fa9e772023-11-23 18:00:55 +0800340{
r.xiaoefee0062023-12-29 19:35:43 -0800341 //UNUSED(h_sms);
r.xiaodac82562023-12-07 18:22:32 -0800342 //UNUSED(pt_sms_storage);
343 char cmgd[128] = {0};
344 int err = 0;
r.xiao26cb0692024-05-22 22:47:08 -0700345
r.xiaoe73f8702024-01-06 01:40:03 -0800346 int t_storage = 0;
347 char mem[10] = {0};
348 char resp[RES_NUM_MIN] = {0};
b.liu5fa9e772023-11-23 18:00:55 +0800349
r.xiaoefee0062023-12-29 19:35:43 -0800350 if (h_sms != g_sms_val || g_sms_val == -1)
r.xiaodac82562023-12-07 18:22:32 -0800351 {
r.xiaoeb9dba42024-02-07 02:16:13 -0800352 LOGE("handle NULL");
r.xiaoefee0062023-12-29 19:35:43 -0800353 return -1;
r.xiaodac82562023-12-07 18:22:32 -0800354 }
355
356 if(pt_sms_storage == NULL)
357 {
r.xiaoeb9dba42024-02-07 02:16:13 -0800358 LOGE("qser_sms_deletefromstorage pt_sms_storage NULL");
r.xiaoefee0062023-12-29 19:35:43 -0800359 return -1;
360 }
361
362 if(sms_info_handle == NULL)
363 {
r.xiaoeb9dba42024-02-07 02:16:13 -0800364 LOGE("qser_sms_deletefromstorage sms_info_handle NULL");
r.xiaoefee0062023-12-29 19:35:43 -0800365 return -1;
r.xiaodac82562023-12-07 18:22:32 -0800366 }
r.xiaod3256ae2024-02-28 23:20:55 -0800367/*
r.xiaoe73f8702024-01-06 01:40:03 -0800368 t_storage = pt_sms_storage->storage; //设置存储器
369
370 if (t_storage == 0)
371 {
372 strncpy(mem, "SM", 2);
373 }
374 else if (t_storage == 1)
375 {
376 strncpy(mem, "ME", 2);
377 }
378 else
379 {
r.xiaoeb9dba42024-02-07 02:16:13 -0800380 LOGE("qser_sms_deletefromstorage storage is no Support");
r.xiaoec113d12024-01-12 02:13:28 -0800381 return -1;
r.xiaoe73f8702024-01-06 01:40:03 -0800382 }
383
384 memset(resp, 0, sizeof(resp));
385 err = mbtk_sms_cpms_set(sms_info_handle, mem, resp);
386 if(err) {
r.xiaoeb9dba42024-02-07 02:16:13 -0800387 LOGE("Error : %d", err);
r.xiaoe73f8702024-01-06 01:40:03 -0800388 } else {
r.xiaoeb9dba42024-02-07 02:16:13 -0800389 LOGI("cpms set success. resp:%s", resp);
r.xiaoe73f8702024-01-06 01:40:03 -0800390 }
r.xiaod3256ae2024-02-28 23:20:55 -0800391*/
r.xiao26cb0692024-05-22 22:47:08 -0700392 uint32_t id_x = 0; //若后面其他产品是int类型则用宏控制
r.xiaodac82562023-12-07 18:22:32 -0800393 id_x = pt_sms_storage->storage_idx;//获取idx的值
394
395 if(id_x == -1) //delete all
396 {
r.xiao26cb0692024-05-22 22:47:08 -0700397 memcpy(cmgd, "0,4", strlen("0,4"));
r.xiaodac82562023-12-07 18:22:32 -0800398 }
399 else
400 {
401 sprintf(cmgd,"%d",id_x);
402 }
403
r.xiaoeb9dba42024-02-07 02:16:13 -0800404 LOGI("cmgd:%s", cmgd);
r.xiaodac82562023-12-07 18:22:32 -0800405
406 err = mbtk_sms_cmgd_set(sms_info_handle, cmgd);
407 if(err)
408 {
r.xiaoeb9dba42024-02-07 02:16:13 -0800409 LOGE("qser_sms_deletefromstorage Error : %d", err);
r.xiaoefee0062023-12-29 19:35:43 -0800410 return -1;
r.xiaodac82562023-12-07 18:22:32 -0800411 }
412 else
413 {
r.xiaoeb9dba42024-02-07 02:16:13 -0800414 LOGI("qser_sms_deletefromstorage set success");
r.xiaodac82562023-12-07 18:22:32 -0800415 }
416
r.xiaoefee0062023-12-29 19:35:43 -0800417 return 0;
b.liu5fa9e772023-11-23 18:00:55 +0800418}
419
r.xiaodac82562023-12-07 18:22:32 -0800420//获取短信中心号码
421int qser_sms_getsmscenteraddress( sms_client_handle_type h_sms,QSER_sms_service_center_cfg_t *set_sca_cfg)//in out
b.liu5fa9e772023-11-23 18:00:55 +0800422{
r.xiaoefee0062023-12-29 19:35:43 -0800423 //UNUSED(h_sms);
r.xiaodac82562023-12-07 18:22:32 -0800424 //UNUSED(set_sca_cfg);
425 char sms_center_addree[254] = {0};
426 int len_t;
427 char *p1, *p2 ,*substr;
b.liu5fa9e772023-11-23 18:00:55 +0800428
r.xiaoefee0062023-12-29 19:35:43 -0800429 if (h_sms != g_sms_val || g_sms_val == -1)
430 {
r.xiaoeb9dba42024-02-07 02:16:13 -0800431 LOGE("handle NULL");
r.xiaoefee0062023-12-29 19:35:43 -0800432 return -1;
433 }
434
r.xiaoefee0062023-12-29 19:35:43 -0800435 if (set_sca_cfg == NULL)
436 {
r.xiaoeb9dba42024-02-07 02:16:13 -0800437 LOGE("QSER_sms_service_center_cfg_t NULL");
r.xiaoefee0062023-12-29 19:35:43 -0800438 return -1;
439 }
440
r.xiaodac82562023-12-07 18:22:32 -0800441 if(sms_info_handle == NULL)
442 {
r.xiaoeb9dba42024-02-07 02:16:13 -0800443 LOGE("qser_sms_getsmscenteraddress sms_info_handle NULL");
r.xiaoefee0062023-12-29 19:35:43 -0800444 return -1;
r.xiaodac82562023-12-07 18:22:32 -0800445 }
446
447 int err = mbtk_sms_csca_get(sms_info_handle, sms_center_addree);
448 if(sms_center_addree[0] == '\0')
449 {
r.xiaoeb9dba42024-02-07 02:16:13 -0800450 LOGE("qser_sms_getsmscenteraddress Error : %d", err);
r.xiaoefee0062023-12-29 19:35:43 -0800451 return -1;
r.xiaodac82562023-12-07 18:22:32 -0800452 }
453 else
454 {
r.xiaoeb9dba42024-02-07 02:16:13 -0800455 p1 = strchr(sms_center_addree, '\"');
456 p2 = strrchr(sms_center_addree, '\"');
457 if (p1 && p2 && p2 > p1)
r.xiaodac82562023-12-07 18:22:32 -0800458 {
r.xiaoeb9dba42024-02-07 02:16:13 -0800459 len_t = p2 - p1 - 1;
460 char substr_t[len_t + 1];
461 strncpy(substr_t, p1 + 1, len_t);
462 substr_t[len_t] = '\0';
463
r.xiaodac82562023-12-07 18:22:32 -0800464 substr = substr_t;
465
466 memcpy(set_sca_cfg->service_center_addr, substr, strlen(substr));
467 memcpy(sms_center_address, substr, strlen(substr));
468
r.xiaoeb9dba42024-02-07 02:16:13 -0800469 LOGI("qser_sms_getsmscenteraddress success");
r.xiaodac82562023-12-07 18:22:32 -0800470 }
471 else
472 {
r.xiaoeb9dba42024-02-07 02:16:13 -0800473 LOGE("String inside double quotes not found");
r.xiaoefee0062023-12-29 19:35:43 -0800474 return -1;
r.xiaodac82562023-12-07 18:22:32 -0800475 }
476 }
477
r.xiaoefee0062023-12-29 19:35:43 -0800478 return 0;
b.liu5fa9e772023-11-23 18:00:55 +0800479}
480
r.xiaodac82562023-12-07 18:22:32 -0800481//设置短信中心号码
482int qser_sms_setsmscenteraddress( sms_client_handle_type h_sms, QSER_sms_service_center_cfg_t *get_sca_cfg)//in in
b.liu5fa9e772023-11-23 18:00:55 +0800483{
r.xiaoefee0062023-12-29 19:35:43 -0800484 //UNUSED(h_sms);
r.xiaodac82562023-12-07 18:22:32 -0800485 //UNUSED(get_sca_cfg);
486 char *destNum = NULL;
r.xiaoefee0062023-12-29 19:35:43 -0800487
488 if (h_sms != g_sms_val || g_sms_val == -1)
489 {
r.xiaoeb9dba42024-02-07 02:16:13 -0800490 LOGE("handle NULL");
r.xiaoefee0062023-12-29 19:35:43 -0800491 return -1;
492 }
493
r.xiaodac82562023-12-07 18:22:32 -0800494 if(sms_info_handle == NULL)
495 {
r.xiaoeb9dba42024-02-07 02:16:13 -0800496 LOGE("qser_sms_setsmscenteraddress sms_info_handle NULL");
r.xiaoefee0062023-12-29 19:35:43 -0800497 return -1;
r.xiaodac82562023-12-07 18:22:32 -0800498 }
499
500 if(get_sca_cfg == NULL)
501 {
r.xiaoeb9dba42024-02-07 02:16:13 -0800502 LOGE("qser_sms_setsmscenteraddress get_sca_cfg NULL");
r.xiaoefee0062023-12-29 19:35:43 -0800503 return -1;
r.xiaodac82562023-12-07 18:22:32 -0800504 }
505
506 destNum = get_sca_cfg->service_center_addr;
507
r.xiaoec113d12024-01-12 02:13:28 -0800508 //printf("1destNum:%s\n", destNum);
r.xiaodac82562023-12-07 18:22:32 -0800509 memset(sms_center_address, 0, sizeof(sms_center_address));
510 memcpy(sms_center_address, destNum, strlen(destNum));
511
512 if (destNum == NULL)
513 {
r.xiaoeb9dba42024-02-07 02:16:13 -0800514 LOGE("qser_sms_setsmscenteraddress destNum NULL");
r.xiaoefee0062023-12-29 19:35:43 -0800515 return -1;
r.xiaodac82562023-12-07 18:22:32 -0800516 }
517
518 int err = mbtk_sms_csca_set(sms_info_handle, destNum);
519 if(err)
520 {
r.xiaoeb9dba42024-02-07 02:16:13 -0800521 LOGE("Error : %d", err);
r.xiaoefee0062023-12-29 19:35:43 -0800522 return -1;
r.xiaodac82562023-12-07 18:22:32 -0800523 }
524 else
525 {
526 // memset(sms_center_address, 0, sizeof(sms_center_address));
527 // memcpy(sms_center_address, destNum, strlen(destNum));
r.xiaoec113d12024-01-12 02:13:28 -0800528 //printf("destNum:%s\n", destNum);
r.xiaoeb9dba42024-02-07 02:16:13 -0800529 LOGI("qser_sms_setsmscenteraddress success");
530 }
531
532 return 0;
533}
534
535
536//显示删除列表
537int qser_sms_deletefromstoragelist( sms_client_handle_type h_sms, char* del_list)//in out
538{
539 //UNUSED(h_sms);
540 //UNUSED(get_sca_cfg);
541
542 if (h_sms != g_sms_val || g_sms_val == -1)
543 {
544 LOGE("handle NULL");
545 return -1;
546 }
547
548 if(sms_info_handle == NULL)
549 {
550 LOGE("qser_sms_deletefromstoragelist sms_info_handle NULL");
551 return -1;
552 }
553
554 int err = mbtk_sms_cmgd_get(sms_info_handle, del_list);
555 if(err > 0 && err != 300)//MBTK_INFO_ERR_SUCCESS
556 {
557 LOGE("Error : %d", err);
558 return -1;
r.xiaodac82562023-12-07 18:22:32 -0800559 }
560
r.xiaoefee0062023-12-29 19:35:43 -0800561 return 0;
b.liu5fa9e772023-11-23 18:00:55 +0800562}
563