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