ll | 87aa1c6 | 2023-01-19 11:14:23 +0800 | [diff] [blame] | 1 |
|
| 2 | #include <stdio.h>
|
| 3 | #include <sys/types.h>
|
| 4 | #include <sys/socket.h>
|
| 5 | #include <arpa/inet.h>
|
| 6 | #include <fcntl.h>
|
| 7 | #include <string.h>
|
| 8 | #include <stdlib.h>
|
| 9 | #include <unistd.h>
|
| 10 | #include <binder/Parcel.h>
|
| 11 | #include <log/log.h>
|
| 12 | #include <cutils/jstring.h>
|
| 13 | #include <pthread.h>
|
| 14 | #include "liblog/lynq_deflog.h"
|
| 15 | #include <sys/time.h>
|
| 16 | #include <string.h>
|
| 17 | #include <vendor-ril/telephony/ril.h>
|
| 18 | #include <vendor-ril/telephony/mtk_ril_sp.h>
|
| 19 | #include <vendor-ril/telephony/mtk_ril_ivt.h>
|
| 20 | #include "lynq_sms.h"
|
| 21 | #include "lynq_module_common.h"
|
| 22 | #include "lynq_module_socket.h"
|
| 23 |
|
| 24 | #define CALL_OFF (0)
|
| 25 | #define CALL_ON (1)
|
| 26 | #define USER_LOG_TAG "LYNQ_SMS"
|
| 27 |
|
| 28 | using ::android::Parcel;
|
| 29 |
|
ll | 87aa1c6 | 2023-01-19 11:14:23 +0800 | [diff] [blame] | 30 |
|
| 31 | int sms_storage_index = 0;
|
| 32 |
|
| 33 | /**
|
| 34 | * @brief mark call initialization state
|
| 35 | * 0: deinit state
|
| 36 | * 1: init state
|
| 37 | */
|
| 38 | int g_module_init_flag = 0;
|
| 39 |
|
| 40 | //static lynq_call_list_e_t s_call_lists[LYNQ_CALL_MAX]={};
|
| 41 | //static bool s_call_list_loop = 0;
|
| 42 | //static pthread_t s_call_list_loop_tid = -1;
|
| 43 | static pthread_mutex_t s_notice_new_sms_mutex = PTHREAD_MUTEX_INITIALIZER;
|
| 44 | static pthread_cond_t s_notice_new_sms_cond = PTHREAD_COND_INITIALIZER;
|
| 45 |
|
| 46 | //static int s_module_isDial = 0;
|
| 47 | //static pthread_mutex_t call_state_change_mutex = PTHREAD_MUTEX_INITIALIZER;
|
| 48 | //static pthread_cond_t call_state_change_cond = PTHREAD_COND_INITIALIZER;
|
| 49 | //static int s_CallId = 0;
|
| 50 | //static pthread_mutex_t s_call_state_change_mutex = PTHREAD_MUTEX_INITIALIZER;
|
| 51 | //static pthread_cond_t s_call_state_change_cond = PTHREAD_COND_INITIALIZER;
|
| 52 |
|
| 53 |
|
| 54 | static char *strdupReadString(Parcel* &p) {
|
| 55 | size_t stringlen;
|
| 56 | const char16_t *s16;
|
| 57 | s16 = p->readString16Inplace(&stringlen);
|
| 58 | return strndup16to8(s16, stringlen);
|
| 59 | }
|
| 60 |
|
| 61 | void lynqNoticeGetModuleNewSms()
|
| 62 | {
|
| 63 | pthread_mutex_lock(&s_notice_new_sms_mutex);
|
| 64 | pthread_cond_signal(&s_notice_new_sms_cond);
|
| 65 | pthread_mutex_unlock(&s_notice_new_sms_mutex);
|
| 66 |
|
| 67 | }
|
| 68 |
|
| 69 | void lynqNoticeWaitModuleNewSms()
|
| 70 | {
|
| 71 | pthread_mutex_lock(&s_notice_new_sms_mutex);
|
| 72 | pthread_cond_wait(&s_notice_new_sms_cond, &s_notice_new_sms_mutex);
|
| 73 | pthread_mutex_unlock(&s_notice_new_sms_mutex);
|
| 74 | }
|
| 75 |
|
| 76 | int lynq_sms_init(int uToken)
|
| 77 | {
|
q.huang | 292ee5d | 2023-12-08 20:23:56 +0800 | [diff] [blame] | 78 | LYLOGSET(LOG_DEBUG);
|
| 79 | LYLOGEINIT(USER_LOG_TAG);
|
| 80 | LYERRLOG("%s start, parameter is %d", __func__,uToken);
|
| 81 |
|
ll | 87aa1c6 | 2023-01-19 11:14:23 +0800 | [diff] [blame] | 82 | if(g_module_init_flag != MODULE_CLOSED)
|
| 83 | {
|
| 84 | LYERRLOG("module state is %d",g_module_init_flag);
|
| 85 | return LYNQ_E_CONFLICT;
|
| 86 | }
|
| 87 | if(uToken <0){
|
| 88 | LYERRLOG("uToken is less than 0",uToken);
|
| 89 | return LYNQ_E_PARAMETER_ANONALY;
|
| 90 | }
|
| 91 | g_module_init_flag = MODULE_SWITCHING;
|
| 92 |
|
q.huang | 292ee5d | 2023-12-08 20:23:56 +0800 | [diff] [blame] | 93 |
|
ll | 87aa1c6 | 2023-01-19 11:14:23 +0800 | [diff] [blame] | 94 |
|
| 95 | g_module_Global_uToken = uToken;
|
| 96 |
|
| 97 | int ret = lynq_start_all_urc_socket_thread();
|
| 98 | if(ret != RESULT_OK)
|
| 99 | {
|
| 100 | LYERRLOG("init socket urc fail!!!");
|
| 101 | g_module_init_flag = MODULE_CLOSED;
|
| 102 | return LYNQ_E_INNER_ERROR;
|
| 103 | }
|
| 104 |
|
| 105 | ret = lynq_start_all_rc_socket_thread();
|
| 106 | if(ret !=RESULT_OK)
|
| 107 | {
|
| 108 | LYERRLOG("init socket client fail!!!");
|
| 109 | lynq_close_all_urc_socket_thread();
|
| 110 | g_module_init_flag = MODULE_CLOSED;
|
| 111 | return LYNQ_E_INNER_ERROR;
|
| 112 | }
|
| 113 | g_module_init_flag = MODULE_RUNNING;
|
q.huang | 292ee5d | 2023-12-08 20:23:56 +0800 | [diff] [blame] | 114 | LYERRLOG("%s end suc", __func__);
|
ll | 87aa1c6 | 2023-01-19 11:14:23 +0800 | [diff] [blame] | 115 | return RESULT_OK;
|
| 116 | }
|
| 117 |
|
| 118 | /*
|
| 119 | Converts an array to a hexadecimal string
|
| 120 | */
|
| 121 | void ArrayToStr(unsigned char *Buff, unsigned int BuffLen, char *OutputStr)
|
| 122 | {
|
| 123 | int i = 0;
|
xf.li | 7a9a61c | 2023-05-09 22:48:11 -0700 | [diff] [blame] | 124 | char TempBuff[MSG_MAX_LEN * 2 +1] = {0};
|
| 125 | char strBuff[MSG_MAX_LEN * 2 +1] = {0};
|
| 126 |
|
ll | 87aa1c6 | 2023-01-19 11:14:23 +0800 | [diff] [blame] | 127 | for(i = 0; i<BuffLen;i++)
|
| 128 | {
|
| 129 | sprintf(TempBuff,"%02x",(unsigned char)Buff[i]);
|
| 130 | strncat(strBuff,TempBuff,BuffLen*2);
|
| 131 | }
|
| 132 | strncpy(OutputStr, strBuff, BuffLen*2);
|
| 133 | return;
|
| 134 | }
|
| 135 |
|
| 136 | int lynq_send_sms(char telephony_num[TELEPHONE_NUM_LEN], int charset, char *msg, int msglen)
|
| 137 | {
|
xf.li | 7a9a61c | 2023-05-09 22:48:11 -0700 | [diff] [blame] | 138 | LYINFLOG("charset is %d, msglen %d\n", charset, msglen);
|
l.yang | 257cce8 | 2023-07-04 18:35:07 -0700 | [diff] [blame] | 139 | if(msglen > MSG_MAX_LEN || msglen <= 0)
|
xf.li | 7a9a61c | 2023-05-09 22:48:11 -0700 | [diff] [blame] | 140 | {
|
| 141 | LYERRLOG("msglen out of the range");
|
| 142 | return LYNQ_E_SMS_MSGLEN_OUT_OF_RANGE;
|
| 143 | }
|
ll | 87aa1c6 | 2023-01-19 11:14:23 +0800 | [diff] [blame] | 144 | if(g_module_init_flag != MODULE_RUNNING)
|
| 145 | {
|
| 146 | LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
|
| 147 | return LYNQ_E_CONFLICT;
|
| 148 | }
|
| 149 | Parcel* p=NULL;
|
| 150 | if(charset == 1)//means 8 bit
|
| 151 | {
|
| 152 | char msg_e_b[msglen*2+1] = {0};// +1 for end of string.*2:A char array contains two elements of a string for each value
|
| 153 | ArrayToStr(msg, msglen, msg_e_b);
|
xf.li | 7a9a61c | 2023-05-09 22:48:11 -0700 | [diff] [blame] | 154 | LYINFLOG("tel, charset, msg_e_b: %s, %d, %s", telephony_num, charset, msg_e_b);
|
ll | 87aa1c6 | 2023-01-19 11:14:23 +0800 | [diff] [blame] | 155 | int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_SEND_SMS,3,"%s %d %s",telephony_num, charset, msg_e_b);
|
| 156 | if(ret!=RESULT_OK)
|
| 157 | {
|
| 158 | LYERRLOG("%s 8bit send error %d",__func__,__LINE__);
|
| 159 | return ret;
|
| 160 | }
|
| 161 | delete p;
|
| 162 | return RESULT_OK;
|
| 163 | }
|
| 164 | else//other bit
|
| 165 | {
|
| 166 | int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_SEND_SMS,3,"%s %d %s",telephony_num, charset, msg);
|
| 167 | if(ret!=RESULT_OK)
|
| 168 | {
|
| 169 | LYERRLOG("%s 7bit send error %d",__func__,__LINE__);
|
| 170 | return ret;
|
| 171 | }
|
| 172 | delete p;
|
| 173 | return RESULT_OK;
|
| 174 | }
|
| 175 | }
|
| 176 |
|
| 177 | int lynq_read_sms(int index,int *status,int *charset,char smsc[SMSC_MAX_LEN],int *smscLen,int *smslen,char message[MSG_MAX_LEN],char teleNum[TELEPHONE_NUM_LEN],int *numLen,int *current,int *total)
|
| 178 | {
|
| 179 | if(g_module_init_flag != MODULE_RUNNING)
|
| 180 | {
|
| 181 | LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
|
| 182 | return LYNQ_E_CONFLICT;
|
| 183 | }
|
| 184 | Parcel* p=NULL;
|
| 185 | int ret=lynq_send_common_request(p,g_wait_time,LYNQ_REQUEST_READ_SMS_FROM_MEMORY,1,"%d",index);
|
| 186 | if(ret!=0)
|
| 187 | {
|
| 188 | return ret;
|
| 189 | }
|
| 190 | LYDBGLOG("LYNQ_REQUEST_READ_SMS_FROM_MEMORY SUCCESS!");
|
| 191 | p->readInt32(&index);
|
| 192 | p->readInt32(status);
|
| 193 | p->readInt32(charset);
|
| 194 | /*lei add for gws 2022/5/12*/
|
| 195 | p->readInt32(current);
|
| 196 | p->readInt32(total);
|
| 197 | /*lei add for gws 2022/5/12*/
|
| 198 | char *phone_num = NULL;
|
| 199 | phone_num = strdupReadString(p);
|
| 200 | *numLen = strlen(phone_num);
|
| 201 | strcpy(teleNum, phone_num);
|
| 202 | char *smscenter = NULL;
|
| 203 | smscenter = strdupReadString(p);
|
| 204 | *smscLen = strlen(smscenter);
|
| 205 | strcpy(smsc,smscenter);
|
| 206 | char *msg = NULL;
|
| 207 | msg = strdupReadString(p);
|
| 208 | *smslen = strlen(msg);
|
| 209 | strcpy(message,msg);
|
| 210 | free(phone_num);
|
| 211 | free(smscenter);
|
| 212 | free(msg);
|
| 213 | delete p;
|
| 214 | return RESULT_OK;
|
| 215 | }
|
| 216 |
|
| 217 | int lynq_get_smsc_address(char service_num[SMSC_MAX_LEN])
|
| 218 | {
|
| 219 | if(g_module_init_flag != MODULE_RUNNING)
|
| 220 | {
|
| 221 | LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
|
| 222 | return LYNQ_E_CONFLICT;
|
| 223 | }
|
| 224 | Parcel* p=NULL;
|
| 225 | int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_GET_SMSC_ADDRESS,0,"");
|
| 226 | if(ret!=0)
|
| 227 | {
|
| 228 | return ret;
|
| 229 | }
|
| 230 | LYDBGLOG("lynq_get_smsc_address SUCCESS!");
|
| 231 | char *temp = strdupReadString(p);
|
| 232 | strcpy(service_num, temp);
|
| 233 | free(temp);
|
| 234 | delete p;
|
| 235 | return RESULT_OK;
|
| 236 | }
|
| 237 |
|
| 238 | int lynq_wait_receive_new_sms(int *handle)
|
| 239 | {
|
| 240 | if(g_module_init_flag != MODULE_RUNNING)
|
| 241 | {
|
| 242 | LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
|
| 243 | return LYNQ_E_CONFLICT;
|
| 244 | }
|
| 245 | if(handle==NULL)
|
| 246 | {
|
| 247 | LYERRLOG("handle is null!!!");
|
| 248 | return LYNQ_E_NULL_ANONALY;
|
| 249 | }
|
| 250 | lynqNoticeWaitModuleNewSms();
|
| 251 | *handle = sms_storage_index;
|
| 252 | return RESULT_OK;
|
| 253 | }
|
| 254 |
|
| 255 | int lynq_set_smsc_address(const char* service_num)
|
| 256 | {
|
| 257 | if(g_module_init_flag != MODULE_RUNNING)
|
| 258 | {
|
| 259 | LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
|
| 260 | return LYNQ_E_CONFLICT;
|
| 261 | }
|
| 262 | Parcel* p=NULL;
|
| 263 | int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_SET_SMSC_ADDRESS,1,"%s", service_num);
|
| 264 |
|
| 265 | if(ret!=RESULT_OK)
|
| 266 | {
|
| 267 | LYERRLOG("%s 8bit send error %d",__func__,__LINE__);
|
| 268 | return ret;
|
| 269 | }
|
| 270 | LYDBGLOG("lynq_set_smsc_address SUCCESS!");
|
| 271 | delete p;
|
| 272 | return RESULT_OK;
|
| 273 | }
|
| 274 |
|
| 275 | int lynq_list_sms(char index_list[SMS_NUM_MAX])
|
| 276 | {
|
| 277 | if(g_module_init_flag != MODULE_RUNNING)
|
| 278 | {
|
| 279 | LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
|
| 280 | return LYNQ_E_CONFLICT;
|
| 281 | }
|
| 282 | Parcel* p=NULL;
|
| 283 | int ret=lynq_send_common_request(p,g_wait_time,LYNQ_REQUEST_LIST_SMS_FROM_MEMORY,0,"");
|
| 284 | if(ret!=0)
|
| 285 | {
|
| 286 | return ret;
|
| 287 | }
|
| 288 | LYDBGLOG("lynq_list_sms SUCCESS!");
|
| 289 | char *temp = strdupReadString(p);
|
| 290 | strcpy(index_list, temp);
|
| 291 | free(temp);
|
| 292 | delete p;
|
| 293 | return RESULT_OK;
|
| 294 | }
|
| 295 |
|
| 296 | int lynq_delete_sms(int index)
|
| 297 | {
|
| 298 | if(g_module_init_flag != MODULE_RUNNING)
|
| 299 | {
|
| 300 | LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
|
| 301 | return LYNQ_E_CONFLICT;
|
| 302 | }
|
| 303 | Parcel* p=NULL;
|
| 304 | int ret=lynq_send_common_request(p,g_wait_time,LYNQ_REQUEST_DELETE_SMS_FROM_MEMORY,1,"%d", index);
|
| 305 |
|
| 306 | if(ret!=RESULT_OK)
|
| 307 | {
|
| 308 | LYERRLOG("%s 8bit send error %d",__func__,__LINE__);
|
| 309 | return ret;
|
| 310 | }
|
| 311 | LYDBGLOG("lynq_delete_sms SUCCESS!");
|
| 312 | delete p;
|
| 313 | return RESULT_OK;
|
| 314 | }
|
| 315 |
|
| 316 | bool is_support_urc(int urc_id)
|
| 317 | {
|
| 318 | switch(urc_id)
|
| 319 | {
|
| 320 | case RIL_UNSOL_RESPONSE_NEW_SMS:
|
| 321 | return true;
|
| 322 | default:
|
| 323 | return false;
|
| 324 | }
|
| 325 | }
|
| 326 |
|
| 327 | int lynq_sms_deinit(void)
|
| 328 | {
|
q.huang | 292ee5d | 2023-12-08 20:23:56 +0800 | [diff] [blame] | 329 | LYERRLOG("%s start", __func__);
|
| 330 |
|
ll | 87aa1c6 | 2023-01-19 11:14:23 +0800 | [diff] [blame] | 331 | if (g_module_init_flag != MODULE_RUNNING)
|
| 332 | {
|
| 333 | LYERRLOG("module state is %d",g_module_init_flag);
|
| 334 | return LYNQ_E_CONFLICT;
|
| 335 | }
|
| 336 | g_module_init_flag = MODULE_SWITCHING;
|
| 337 | lynq_close_all_urc_socket_thread();
|
| 338 | lynq_close_all_rc_socket_thread();
|
| 339 | g_module_init_flag = MODULE_CLOSED;
|
q.huang | 292ee5d | 2023-12-08 20:23:56 +0800 | [diff] [blame] | 340 |
|
| 341 | LYERRLOG("%s end suc", __func__);
|
ll | 87aa1c6 | 2023-01-19 11:14:23 +0800 | [diff] [blame] | 342 | return RESULT_OK;
|
| 343 | }
|
| 344 |
|
| 345 | void urc_msg_process(Parcel *p)
|
| 346 | {
|
| 347 | int resp_type;
|
| 348 | int urcid;
|
| 349 | int slot_id;
|
| 350 |
|
| 351 | int size=p->dataSize();
|
| 352 | p->readInt32(&resp_type);
|
| 353 | p->readInt32(&urcid);
|
| 354 | p->readInt32(&slot_id);
|
| 355 | LYINFLOG("%s urc id = %d, slot_id = %d, size is %d, msg is %s",__func__, urcid,slot_id,size,requestToString(urcid));
|
| 356 | switch (urcid)
|
| 357 | {
|
| 358 | case RIL_UNSOL_RESPONSE_NEW_SMS://new sms received
|
| 359 | {
|
| 360 | LYINFLOG("**************:resp_type=%d,urcid=%d,slot_id=%d",resp_type,urcid,slot_id);
|
| 361 | char *msg = NULL;
|
| 362 | int index = 0;
|
| 363 | msg = strdupReadString(p);
|
| 364 | p->readInt32(&index);
|
| 365 | sms_storage_index = index;
|
| 366 | lynqNoticeGetModuleNewSms();
|
| 367 | free(msg);
|
| 368 | break;
|
| 369 | }
|
| 370 | default:
|
| 371 | break;
|
| 372 | }
|
| 373 | }
|
| 374 |
|