blob: 5ff7de434ce7cf03a3b868dfddaaab28a93d4a5c [file] [log] [blame]
rjw1f884582022-01-06 17:20:42 +08001/*=============================================================================
2# FileName: lynq_sms.cpp
3# Desc: about sms api
4# Author: MoblieTek
5# Version:
6# LastChange: 2021-01-06
7# History:
8
9=============================================================================*/
10#include <dlfcn.h>
11#include <string.h>
12#include <stdint.h>
13#include <unistd.h>
14#include <fcntl.h>
15#include <cutils/jstring.h>
16#include <cutils/properties.h>
17#include "lynq_sms.h"
18#include "lynq_common.h"
19#include <liblog/lynq_deflog.h>
20#define KERNAL 19
21#define SMS_INDEX_VALUE "persist.sms.memory.index"
22#define SMS_INDEX_FLAG_VALUE "persist.sms.memory.flag"
23#undef LOG_TAG
24#define LOG_TAG "LYNQ_SMS"
25
26int lynq_send_sms(const char *telephonyNumber, const int charset,const char *msg, const char *smsc,smsResponse* smsResp)
27{
28 int lenth = MIN_MSM_PARAM_NUM;
29 char *argv[MAX_LEN];
30 int32_t token=0;
31 RIL_Errno err=-1;
32 lynqQueue *node =NULL;
33 int num = 0;
34 int res = 0;
35 char requestStr[MAX_QUEST_LEN] = {0};
36 sprintf(requestStr, "%d", charset);
37 argv[0] = "RIL_REQUEST_SEND_SMS";
38 argv[1] = telephonyNumber;
39 argv[2] = requestStr;
40 argv[3] = msg;
41 argv[4] = smsc;
42 if(smsc ==NULL)
43 {
44 token = android::getRequestData(argv,4);
45 //RLOGD("token is %d",token);
46 LYDBGLOG("[%s][%d][%s]token:%d\n",__FUNCTION__, __LINE__,__FILE__,token);
47 }
48 else
49 {
50 token = android::getRequestData(argv,5);
51 //RLOGD("token is %d",token);
52 LYDBGLOG("[%s][%d][%s]token:%d\n",__FUNCTION__, __LINE__,__FILE__,token);
53 }
54 smsResp->base.request = RIL_REQUEST_SEND_SMS;
55 smsResp->base.token=token;
56 smsResp->smsResp.messageRef = 0;
57 smsResp->smsResp.errorCode = 0;
58 if(token<0)
59 {
60 smsResp->base.e=err;
61 return -1;
62 }
63 node = commonFindParcelmsg(token, 500, err);
64 smsResp->base.e=err;
65 if (node !=NULL)
66 {
67 node->parcel.readInt32(&num);
68 if(num ==0)
69 {
70 LYDBGLOG("[%s][%d][%s]the call back message is null!\n",__FUNCTION__, __LINE__,__FILE__);
71 if(err==RIL_E_SUCCESS)
72 {
73 smsResp->base.e=-1;
74 }
75 lynqDeQueue(token);
76 return token;
77 }
78 node->parcel.readInt32(&smsResp->smsResp.messageRef);
79 smsResp->smsResp.ackPDU= lynqStrdupReadString(node->parcel);
80 node->parcel.readInt32(&smsResp->smsResp.errorCode);
81 }
82 lynqDeQueue(token);
83 return token;
84}
85int lynq_Ims_send_sms(const char *telephonyNumber, const int charset,const char *msg, const char* retryNum,const char *messageRef, const char *smsc,smsResponse *smsResp)
86{
87 int lenth = MIN_IMS_MSM_PARAM_NUM;
88 char *argv[MAX_LEN];
89 char requestStr[MAX_QUEST_LEN] = {0};
90 int32_t token=0 ;
91 RIL_Errno err=-1;
92 lynqQueue *node =NULL;
93 int num = 0;
94 int res = 0;
95 sprintf(requestStr, "%d", charset);
96 argv[0] = "RIL_REQUEST_IMS_SEND_SMS";
97 argv[1] = telephonyNumber;
98 argv[2] = requestStr;
99 argv[3] = msg;
100 argv[4] = retryNum;
101 argv[5] = messageRef;
102 argv[6] = smsc;
103 if(smsc==NULL)
104 {
105 token = android::getRequestData(argv, 5);
106 //RLOGD("token is %d",token);
107 LYDBGLOG("%s,%d,%s,token:%d\n",__FUNCTION__, __LINE__,__FILE__,token);
108 }
109 else
110 {
111 token = android::getRequestData(argv, 6);
112 //RLOGD("token is %d",token);
113 LYDBGLOG("%s,%d,%s,token:%d\n",__FUNCTION__, __LINE__,__FILE__,token);
114 }
115 smsResp->base.request = RIL_REQUEST_SEND_SMS;
116 smsResp->base.token=token;
117 smsResp->smsResp.messageRef = 0;
118 smsResp->smsResp.errorCode = 0;
119 if(token<0)
120 {
121 smsResp->base.e=err;
122 return -1;
123 }
124 node = commonFindParcelmsg(token, 500, err);
125 smsResp->base.e=err;
126 if (node !=NULL)
127 {
128 node->parcel.readInt32(&num);
129 if(num ==0)
130 {
131 //RLOGD("[%s]the call back message is null!",__FUNCTION__);
132 LYDBGLOG("[%s][%d][%s]the call back message is null!\n",__FUNCTION__, __LINE__,__FILE__);
133 if(err==RIL_E_SUCCESS)
134 {
135 smsResp->base.e=-1;
136 }
137 lynqDeQueue(token);
138 return token;
139 }
140 node->parcel.readInt32(&smsResp->smsResp.messageRef);
141 smsResp->smsResp.ackPDU= lynqStrdupReadString(node->parcel);
142 node->parcel.readInt32(&smsResp->smsResp.errorCode);
143 }
144 lynqDeQueue(token);
145 return token;
146}
147int lynq_write_sms_to_sim(const int smsStatus,const char *recPhonNum,const int charset,const char *msg,const char *smsc,messageStoreInfo *msgstroeInfo)
148{
149 char *argv[MAX_LEN];
150 char smsStatusStr[MAX_QUEST_LEN] = {0};
151 char charsetStr[MAX_QUEST_LEN] = {0};
152 int32_t token=0 ;
153 RIL_Errno err=-1;
154 lynqQueue *node =NULL;
155 int num = 0;
156 int res = 0;
157 sprintf(smsStatusStr, "%d", smsStatus);
158 sprintf(charsetStr, "%d", charset);
159 argv[0] = "RIL_REQUEST_WRITE_SMS_TO_SIM";
160 argv[1] = smsStatusStr;
161 argv[2] = recPhonNum;
162 argv[3] = charsetStr;
163 argv[4] = msg;
164 argv[5] = smsc;
165 if(smsc==NULL)
166 {
167 token = android::getRequestData(argv, 5);
168 //RLOGD("token is %d",token);
169 LYDBGLOG("%s,%d,%s,token:%d\n",__FUNCTION__, __LINE__,__FILE__,token);
170 }
171 else
172 {
173 token = android::getRequestData(argv, 6);
174 //RLOGD("token is %d",token);
175 LYDBGLOG("%s,%d,%s,token:%d\n",__FUNCTION__, __LINE__,__FILE__,token);
176 }
177 msgstroeInfo->base.request = RIL_REQUEST_WRITE_SMS_TO_SIM;
178 msgstroeInfo->base.token=token;
179 msgstroeInfo->msgStoreIndex = 0;
180 if(token<0)
181 {
182 msgstroeInfo->base.e=err;
183 return -1;
184 }
185 node = commonFindParcelmsg(token, 500, err);
186 printf("function = %s, err = %d\n", __FUNCTION__, (int)err);
187 msgstroeInfo->base.e=err;
188 if(node == NULL){
189 printf("node == NULL\n");
190 }
191 if (node !=NULL)
192 {
193 node->parcel.readInt32(&num);
194 if(num ==0)
195 {
196 //RLOGD("[%s]the call back message is null!",__FUNCTION__);
197 LYDBGLOG("[%s][%d][%s]the call back message is null!\n",__FUNCTION__, __LINE__,__FILE__);
198 if(err==RIL_E_SUCCESS)
199 {
200 msgstroeInfo->base.e=-1;
201 }
202 lynqDeQueue(token);
203 return token;
204 }
205 node->parcel.readInt32(&msgstroeInfo->msgStoreIndex);
206 }
207 lynqDeQueue(token);
208 return token;
209}
210
211/**
212RIL_REQUEST_REPORT_SMS_MEMORY_STATUS
213index is Unavailable or Available
214*/
215int lynq_report_sms_memory_status(const int status,lynqBase *base)
216{
217 int32_t token=0 ;
218 RIL_Errno err=-1;
219 lynqQueue *node =NULL;
220 int state = 0;
221 int res = 0;
222 if(status == 0 || status == 1){
223
224 const char requestStr[MAX_LEN] = {"RIL_REQUEST_REPORT_SMS_MEMORY_STATUS"};
225 token = lynqIntParame(requestStr,status);
226 base->request = RIL_REQUEST_REPORT_SMS_MEMORY_STATUS;
227 base->token=token;
228 if(token<0)
229 {
230 base->e=err;
231 return -1;
232 }
233 node = commonFindParcelmsg(token, 500, err);
234 base->e=err;
235 if (node !=NULL)
236 {
237 node->parcel.readInt32(&state);
238 if(state ==0)
239 {
240 //RLOGD("[%s]the call back message is null!",__FUNCTION__);
241 LYDBGLOG("[%s][%d][%s]the call back message is null!\n",__FUNCTION__, __LINE__,__FILE__);
242 if(err==RIL_E_SUCCESS)
243 {
244 base->e=-1;
245 }
246 lynqDeQueue(token);
247 return token;
248 }
249 }
250 lynqDeQueue(token);
251 return token;
252 }
253 else{
254 LYDBGLOG("input status value error");
255 base->e = err;
256 return -1;
257 }
258
259}
260
261/**
262RIL_REQUEST_REPORT_SMS_MEMORY_STATUS
263index is lynqWriteSMSToSim get index
264*/
265int lynq_delet_sms_on_sim(const int index,lynqBase *base)
266{
267 int32_t token=0 ;
268 RIL_Errno err=-1;
269 lynqQueue *node =NULL;
270 int status = 0;
271 int res = 0;
272 const char requestStr[MAX_LEN] = {"RIL_REQUEST_DELETE_SMS_ON_SIM"};
273 token = lynqIntParame(requestStr,index);
274 base->request = RIL_REQUEST_DELETE_SMS_ON_SIM;
275 base->token=token;
276 if(token<0)
277 {
278 base->e=err;
279 return -1;
280 }
281 node = commonFindParcelmsg(token, 500, err);
282 base->e=err;
283 if (node !=NULL)
284 {
285 node->parcel.readInt32(&status);
286 if(status ==0)
287 {
288 //RLOGD("[%s]the call back message is null!",__FUNCTION__);
289 LYDBGLOG("[%s][%d][%s]the call back message is null!\n",__FUNCTION__, __LINE__,__FILE__);
290 if(err==RIL_E_SUCCESS)
291 {
292 base->e=-1;
293 }
294 lynqDeQueue(token);
295 return token;
296 }
297 }
298 lynqDeQueue(token);
299 return token;
300}
301
302int lynq_get_smsc_address(smscCbInfo *smscInfo)
303{
304 int32_t token=0 ;
305 RIL_Errno err=-1;
306 lynqQueue *node =NULL;
307 int num = 0;
308 int res = 0;
309 const char requestStr[MAX_LEN] = {"RIL_REQUEST_GET_SMSC_ADDRESS"};
310 token = lynqNoneParame(requestStr);
311 smscInfo->base.request = RIL_REQUEST_GET_SMSC_ADDRESS;
312 smscInfo->base.token = token;
313 smscInfo->smsc = NULL;
314 if(token<0)
315 {
316 smscInfo->base.e=err;
317 return -1;
318 }
319 node = commonFindParcelmsg(token, 500, err);
320 smscInfo->base.e=err;
321 if (node !=NULL)
322 {
323 node->parcel.readInt32(&num);
324 if(num ==0)
325 {
326 //RLOGD("[%s]the call back message is null!",__FUNCTION__);
327 LYDBGLOG("[%s][%d][%s]the call back message is null!\n",__FUNCTION__, __LINE__,__FILE__);
328 if(err==RIL_E_SUCCESS)
329 {
330 smscInfo->base.e=-1;
331 }
332 lynqDeQueue(token);
333 return token;
334 }
335 smscInfo->smsc =lynqStrdupReadString(node->parcel);
336 }
337 lynqDeQueue(token);
338 return token;
339}
340
341int lynq_set_smsc_address(const char* serviceNumber,lynqBase *base)
342{
343 int32_t token=0 ;
344 RIL_Errno err=-1;
345 lynqQueue *node =NULL;
346 int status = 0;
347 int res = 0;
348 const char requestStr[MAX_LEN] = {"RIL_REQUEST_SET_SMSC_ADDRESS"};
349 token = lynqStringParame(requestStr,serviceNumber);
350 base->request = RIL_REQUEST_SET_SMSC_ADDRESS;
351 base->token=token;
352 if(token<0)
353 {
354 base->e=err;
355 return -1;
356 }
357 node = commonFindParcelmsg(token, 500, err);
358 base->e=err;
359 if (node !=NULL)
360 {
361 node->parcel.readInt32(&status);
362 if(status ==0)
363 {
364 //RLOGD("[%s]the call back message is null!",__FUNCTION__);
365 LYDBGLOG("[%s][%d][%s]the call back message is null!\n",__FUNCTION__, __LINE__,__FILE__);
366 if(err==RIL_E_SUCCESS)
367 {
368 base->e=-1;
369 }
370 lynqDeQueue(token);
371 return token;
372 }
373 }
374 lynqDeQueue(token);
375 return token;
376}
377/*
378void lynq_recive_new_sms_cb(RIL_SOCKET_ID soc_id,char * num, char * smsc, char * msg, int charset)
379{
380 printf("[SIM%d]num is %s,smsc is %s,msg is %s,charset is %d\n",soc_id,num,smsc,msg,charset);
381}*/
382/*Convert the decimal number into hexadecimal and write it into the buffer
383int decToHex(int aa,char *buffer)
384{
385 itoa(aa, buffer, 16);
386 return 0;
387
388}
389*/
390/*Convert the index into string and write it into the buf*/
391int hexToDec(char* s)
392{
393 int t = 0; //t记录临时加的数
394 int sum = 0;
395 for (int i = 0;s[i];i++)
396 {
397 if (s[i] >= '0' && s[i] <= '9')
398 t = s[i] - '0'; //当字符是0~9时保持原数不变
399 if (s[i] >= 'a' && s[i] <= 'z')
400 t = s[i] - 'a' + 10;
401 if (s[i] >= 'A' && s[i] <= 'Z')
402 t = s[i] - 'A' + 10;
403 sum = sum * 16 + t;
404 }
405 //printf("SUM:%d\n", sum);
406 return sum;
407}
408
409int indexToString(int index,char buf[])
410{
411 int smslen = 0;
412 if (index > 0 && index < 10)
413 {
414 snprintf(buf, sizeof(buf), "00%d", index);
415 }
416 else if (index >= 10 && index < 100)
417 {
418 snprintf(buf, sizeof(buf), "0%d", index);
419 }
420 else if (index == 100)
421 {
422 snprintf(buf, sizeof(buf), "%d", index);
423 }
424 else if (index <= 0 ||index > 100)
425 {
426 snprintf(buf, sizeof(buf), "%d", 110);
427 }
428 buf[3] = '\0';
429 return 0;
430}
431/*组装短消息头,并且和短消息实体拼接。
432**储存短消息的头信息格式如下
433**头部的格式:index|status|soc_id|teleNumLen|smslen|
434**index 表示存储索引,占3位
435**status 表示短消息的阅读状态,占1位
436**smslen 表示短消息实体长度,是16进制数0x0000,占6位
437**soc_id 表示卡槽编号,占1位
438**teleNumLen 表示电话号码的长度,占2位。
439**
440*/
441int assembleMsgInfo(FILE* fp,int property,int status,int smslen,RIL_SOCKET_ID soc_id,char * num,char element[],char *sms)
442{
443 char indexString[10] = { 0 };
444 char numBuf[50]={0};
445 char smsBuffer[MSG_MAX_LEN] = { 0 };
446 indexToString(property,indexString);
447 snprintf(element, KERNAL+1, "|%s|%d|0x%04x|%d|%02d|", indexString, status, smslen,soc_id,strlen(num));
448 element[KERNAL] = '\0';//必须加结束符‘\0’.
449 snprintf(numBuf, strlen(num)+1, "%s", num);//加1是因为需要把结束符‘\0’也保存进来。
450 snprintf(smsBuffer, strlen(sms)+1, "%s", sms);
451 strncat(element, numBuf, strlen(num));
452 strncat(element, smsBuffer, smslen);
453 //printf("head %s\n", element);
454 LYDBGLOG("[%s][%d][%s]element sms%s!\n",__FUNCTION__, __LINE__,__FILE__,element);
455 return 0;
456}
457
458int parseHeader(const char *message,int number,storeMessageInfo *SMI[])
459{
460 const char* temp = message;
461 const char* nextP = NULL;
462 char docker[100] = { 0 };
463 char smsbuffer[MSG_MAX_LEN] = {0};
464 char indexbuf[10] = { 0 };
465 char smslenbuf[10] = { 0 };
466 char socIdBuf[10] ={0};
467 char numLenBuf[10] = {0};
468 char numBuf[50] = {0};
469 int count = 0;
470 if (temp == NULL)
471 {
472 LYERRLOG("[%s][%d][%s]input message is null !!\n",__FUNCTION__, __LINE__,__FILE__);
473 return LYNQ_E_NULL_ANONALY;
474 }
475 while (1)
476 {
477 if (*temp == '\0')
478 {
479 break;
480 }
481 nextP = temp + 1;
482 for (int i = 0;i < KERNAL; i++)
483 {
484 docker[i] = *temp;
485 temp++;
486 }
487 if (docker[0] == '|' && docker[4] == '|' && docker[6] == '|' && docker[13] == '|')
488 {
489 for (int i = 0;i < 3;i++)
490 {
491 strncat(indexbuf, &docker[i+1], 1);
492 }
493 indexbuf[3] = '\0';
494 for (int i = 0; i < 4; i++)
495 {
496 strncat(smslenbuf, &docker[i + 9], 1);
497 }
498 smslenbuf[4] = '\0';
499 for(int i=0;i<2;i++)
500 {
501 strncat(numLenBuf,&docker[i+16],1);
502 }
503 SMI[count]->index = atoi(indexbuf);
504 SMI[count]->status = atoi(&docker[5]);
505 SMI[count]->soc_id=atoi(&docker[14]);
506 SMI[count]->numLen = atoi(numLenBuf);
507 SMI[count]->smslen = hexToDec(smslenbuf);
508 int i=0;
509 for(i=0;i<SMI[count]->numLen;i++)
510 {
511 numBuf[i]=*temp;
512 temp++;
513 }
514 numBuf[i + 1]='\0';
515 for (i = 0;i < SMI[count]->smslen;i++)
516 {
517 smsbuffer[i] = *temp;
518 temp++;
519 }
520 smsbuffer[i + 1] = '\0';
521 memcpy(SMI[count]->message, smsbuffer, SMI[count]->smslen + 1);
522 memcpy(SMI[count]->teleNum, numBuf, SMI[count]->numLen + 1);
523 LYDBGLOG("[%s][%d][%s]index:%d,status:%d,smslen:%d,message:%s,soc_id:%d,numberlen:%d,number:%s!!\n",__FUNCTION__,
524 __LINE__,__FILE__,SMI[count]->index,SMI[count]->status,SMI[count]->smslen,SMI[count]->message,
525 SMI[count]->soc_id,SMI[count]->numLen,SMI[count]->numLen);
526 memset(smslenbuf, 0, strlen(smslenbuf));
527 memset(indexbuf, 0, strlen(indexbuf));
528 memset(docker, 0, strlen(docker));
529 memset(smsbuffer, 0, strlen(smsbuffer));
530 memset(socIdBuf,0,strlen(socIdBuf));
531 memset(numLenBuf,0,strlen(numLenBuf));
532 memset(numBuf,0,strlen(numBuf));
533 count += 1;
534 }
535 else
536 {
537 temp = nextP;
538 }
539 }
540 if (count != number||count ==0)
541 {
542 return -1;
543 }
544 return 0;
545}
546storeMessageInfo **getAllMessage(int &smsNum,int index)
547{
548 int result = 0;
549 int property = 0;
550 int flag =0;
551 int len = 0;
552 char indexBuf[10]={ 0 };
553 char flagBuf[10]={0};
554 char buff[MSG_MAX_LEN*100] = { 0 };
555 char element[MSG_MAX_LEN] = { 0 };
556 storeMessageInfo** SMI = NULL;
557 property_get(SMS_INDEX_VALUE,indexBuf,NULL);
558 property_get(SMS_INDEX_FLAG_VALUE,flagBuf,NULL);
559 property = atoi(indexBuf);
560 //printf("property:%d\n",property);
561 flag = atoi(flagBuf);
562 //printf("flag:%d\n",flag);
563 if((property==0)&&(flag==1))
564 {
565 property =100;
566 }
567 if((property==0)&&(flag==0))
568 {
569 LYERRLOG("[%s][%d][%s]not have SMS was store in memory!!\n",__FUNCTION__, __LINE__,__FILE__);
570 return NULL;
571 }
572 if(property<index)
573 {
574 LYERRLOG("[%s][%d][%s]Out of bounds!!\n",__FUNCTION__, __LINE__,__FILE__);
575 return NULL;
576 }
577 FILE* fp = NULL;
578 fp = fopen("/usr/bin/demoscript/SMS_API/custerm_message.txt", "r");
579 if (fp == 0)
580 {
581 LYERRLOG("[%s][%d][%s]Can't open log file!!\n",__FUNCTION__, __LINE__,__FILE__);
582 return NULL;
583 }
584 fseek(fp, 0, SEEK_END); //将文件指针指向文件的结尾;
585 len = ftell(fp); //获取当前文件指针在文件内的位置,单位为byte ,len为文件的长度。
586 fseek(fp, 0, SEEK_SET);
587 fread(buff, len + 1, 1, fp);
588 if ((SMI = (storeMessageInfo**)malloc(sizeof(storeMessageInfo*) * property)) == NULL)
589 {
590 LYERRLOG("[%s][%d][%s]Core dump,malloc fail!!\n",__FUNCTION__, __LINE__,__FILE__);
591 return NULL;
592 }
593 for (int i = 0;i < property;i++)
594 {
595 if (!(SMI[i] = (storeMessageInfo*)malloc(sizeof(storeMessageInfo))))
596 {
597 LYERRLOG("[%s][%d][%s]Core dump,malloc fail!!\n",__FUNCTION__, __LINE__,__FILE__);
598 for (int n = 0;n < i;n++)
599 {
600 free(SMI[n]);
601 }
602 free(SMI);
603 return NULL;
604 }
605 memset(SMI[i], 0, sizeof(storeMessageInfo));
606 }
607 result = parseHeader(buff, property, SMI);
608 fclose(fp);
609 smsNum=property;
610 return SMI;
611}
612int lynq_store_sms_to_memory(RIL_SOCKET_ID soc_id,const int status,char * num,const char* sms,lynqBase *base)
613{
614 int index = 0;
615 int indexflag = 0;
616 int indexlen =0;
617 int headlen = 0;
618 int smslen = 0;
619 int smsNum = 0;
620 FILE* fp = NULL;
621 char smsBuffer[MSG_MAX_LEN] = {0};
622 char enCode[MSG_MAX_LEN] = {0};
623 char buffer[MSG_MAX_LEN*100]={0};
624 char indexBuf[50] = { 0 };
625 char indexflagBuf[50]={0};
626 char teleNumBuf[70]={0};
627 storeMessageInfo ** SMI =NULL;
628 if (sms == NULL)
629 {
630 LYERRLOG("[%s][%d][%s] Message is null!!\n",__FUNCTION__, __LINE__,__FILE__);
631 base->e = LYNQ_E_NULL_ANONALY;
632 return -1;
633 }
634 fp=fopen("/usr/bin/demoscript/SMS_API/custerm_message.txt", "a+");
635 if (fp == 0)
636 {
637 LYERRLOG("[%s][%d][%s] Can't open log file!!\n",__FUNCTION__, __LINE__,__FILE__);
638 return 0;
639 }
640 indexlen = property_get(SMS_INDEX_VALUE,indexBuf,"0");
641 index = atoi(indexBuf);
642 indexlen = property_get(SMS_INDEX_FLAG_VALUE,indexflagBuf,"0");
643 indexflag = atoi(indexflagBuf);
644 smslen = strlen(sms);
645 if(indexflag==1)
646 {
647 SMI = getAllMessage(smsNum, -1);
648 if(SMI==NULL)
649 {
650 base->e= LYNQ_E_NULL_ANONALY;
651 return -1;
652 }
653 for (int i = 0;i < smsNum;i++)
654 {
655 if(index ==0)
656 {
657 index = 1;
658 }
659 if (SMI[i]->index == index)
660 {
661 memset(indexBuf,0,strlen(indexBuf));
662 indexToString(index+1, indexBuf);
663 property_set(SMS_INDEX_VALUE,indexBuf);
664 assembleMsgInfo(fp,index,status,smslen,soc_id,num,enCode,sms);
665 strncat(buffer, enCode, strlen(enCode));
666 memset(enCode,0, strlen(enCode));
667 }
668 else
669 {
670 assembleMsgInfo(fp,SMI[i]->index, SMI[i]->status, SMI[i]->smslen,SMI[i]->soc_id,SMI[i]->teleNum, enCode, SMI[i]->message);
671 strncat(buffer, enCode, strlen(enCode));
672 memset(enCode,0, strlen(enCode));
673 }
674 }
675 fwrite(buffer, strlen(buffer), 1, fp);//将msg对应的字符串append到文件末尾
676 fclose(fp);
677 for(int i=0;i<smsNum;i++)
678 {
679 free(SMI[i]);
680 }
681 free(SMI);
682 base->e= RIL_E_SUCCESS;
683 return 0;
684 }
685 else
686 {
687 index = index+1;
688 if(index==100)
689 {
690 property_set(SMS_INDEX_VALUE,"0");
691 property_set(SMS_INDEX_FLAG_VALUE,"1");
692 assembleMsgInfo(fp,index,status,smslen,soc_id,num,enCode,sms);
693 }
694 else
695 {
696 memset(indexBuf,0,strlen(indexBuf));
697 indexToString(index, indexBuf);
698 property_set(SMS_INDEX_VALUE,indexBuf);
699 assembleMsgInfo(fp,index,status,smslen,soc_id,num,enCode,sms);
700 }
701 fseek(fp, 0, SEEK_END);//定位到文件末尾
702 fwrite(enCode, strlen(enCode), 1, fp);//将msg对应的字符串append到文件末尾
703 fclose(fp);
704 base->e= RIL_E_SUCCESS;
705 return 0;
706 }
707 return -1;
708}
709int lynq_get_sms_from_memory(const int index, storeMessageInfo* sms,lynqBase *base)
710{
711 int smsNum = 0;
712 storeMessageInfo **SMI=NULL;
713 SMI = getAllMessage(smsNum,index);
714 if(SMI==NULL)
715 {
716 base->e= LYNQ_E_NULL_ANONALY;
717 return -1;
718 }
719 /*
720 printf("test sms--001\n");
721 printf("smsNUM%d, index %d\n",smsNum,index-1);
722 sms->index= SMI[index-1]->index;
723 printf("test sms--002\n");
724 sms->numLen= SMI[index-1]->numLen;
725 printf("test sms--003\n");
726 sms->smslen = SMI[index-1]->smslen;
727 printf("test sms--004\n");
728 sms->soc_id= (RIL_SOCKET_ID)SMI[index-1]->soc_id;
729 printf("test sms--005\n");
730 sms->status=SMI[index-1]->status;
731 printf("test sms--006\n");
732 memcpy(sms->message,SMI[index-1]->message,strlen(SMI[index-1]->message)+1);
733 printf("test sms--007\n");
734 memcpy(sms->teleNum,SMI[index-1]->teleNum,strlen(SMI[index-1]->teleNum)+1);
735 printf("test sms--008\n");
736 */
737 for(int i=0;i<smsNum;i++)
738 {
739 if(SMI[i]->index==index)
740 {
741 sms->index= SMI[i]->index;
742 sms->numLen= SMI[i]->numLen;
743 sms->smslen = SMI[i]->smslen;
744 sms->soc_id= SMI[i]->soc_id;
745 sms->status=SMI[i]->status;
746 memcpy(sms->message,SMI[i]->message,strlen(SMI[i]->message)+1);
747 memcpy(sms->teleNum,SMI[i]->teleNum,strlen(SMI[i]->teleNum)+1);
748 for(int i=0;i<smsNum;i++)
749 {
750 free(SMI[i]);
751 }
752 free(SMI);
753 base->e= RIL_E_SUCCESS;
754 return 0;
755 }
756 }
757 for(int i=0;i<smsNum;i++)
758 {
759 free(SMI[i]);
760 }
761 free(SMI);
762 base->e= RIL_E_SUCCESS;
763 return 0;
764}
765// The value range of index is -1, 1-100.
766//-1 means to delete all.
767int lynq_delete_message_from_memory(const int index,lynqBase *base)
768{
769 char buff[MSG_MAX_LEN*100] = { 0 };
770 char element[MSG_MAX_LEN] = {0};
771 char indexBuf[10]={ 0 };
772 char flagBuf[10]={0};
773 int smsNum = 0;
774 int property_Count =0;
775 int property_Flag = 0;
776 int removeflag = 0;
777 FILE *fpW=NULL;
778 storeMessageInfo **SMI=NULL;
779 if(index==(-1))
780 {
781 fpW = fopen("/usr/bin/demoscript/SMS_API/custerm_message.txt", "w+");
782 if (fpW == 0)
783 {
784 LYERRLOG("[%s][%d][%s] Can't open log file!!\n",__FUNCTION__, __LINE__,__FILE__);
785 return -1;
786 }
787 fwrite(buff, strlen(buff), 1, fpW);
788 fclose(fpW);
789 property_set(SMS_INDEX_VALUE,"0");
790 property_set(SMS_INDEX_FLAG_VALUE,"0");
791 base->e= RIL_E_SUCCESS;
792 return 0;
793 }
794 property_get(SMS_INDEX_VALUE,indexBuf,NULL);
795 property_get(SMS_INDEX_FLAG_VALUE,flagBuf,NULL);
796 property_Count = atoi(indexBuf);
797 memset(indexBuf,0,strlen(indexBuf));
798 property_Flag = atoi(flagBuf);
799 SMI = getAllMessage(smsNum,index);
800 if(SMI==NULL)
801 {
802 base->e= LYNQ_E_NULL_ANONALY;
803 return -1;
804 }
805 fpW = fopen("/usr/bin/demoscript/SMS_API/custerm_message.txt", "w+");
806 if (fpW == 0)
807 {
808 LYERRLOG("[%s][%d][%s] Can't open log file!!\n",__FUNCTION__, __LINE__,__FILE__);
809 return -1;
810 }
811 for (int i = 0;i < smsNum;i++)
812 {
813 if (SMI[i]->index == index)
814 {
815 removeflag =1;
816 continue;
817 }
818 assembleMsgInfo(fpW,SMI[i]->index, SMI[i]->status, SMI[i]->smslen,SMI[i]->soc_id,SMI[i]->teleNum, element, SMI[i]->message);
819 strncat(buff, element, SMI[i]->smslen + KERNAL+SMI[i]->numLen);
820 //strncat(buff, SMI[i]->message,SMI[i]->smslen);
821 }
822 if(removeflag==1)
823 {
824 if(property_Flag==1)
825 {
826 snprintf(indexBuf,4, "%03d",99);
827 property_set(SMS_INDEX_VALUE,indexBuf);
828 property_set(SMS_INDEX_FLAG_VALUE,"0");
829
830 }
831 else
832 {
833 snprintf(indexBuf,4, "%03d", property_Count-1);
834 property_set(SMS_INDEX_VALUE,indexBuf);
835 property_set(SMS_INDEX_FLAG_VALUE,"0");
836 }
837 }
838 //printf("%s\n",buff);
839 fwrite(buff, strlen(buff), 1, fpW);//将msg对应的字符串append到文件末尾
840 fclose(fpW);
841 for(int i=0;i<smsNum;i++)
842 {
843 free(SMI[i]);
844 }
845 free(SMI);
846 base->e= RIL_E_SUCCESS;
847 return 0;
848}
849