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