rjw | 1f88458 | 2022-01-06 17:20:42 +0800 | [diff] [blame^] | 1 | /* Copyright Statement: |
| 2 | * |
| 3 | * This software/firmware and related documentation ("MediaTek Software") are |
| 4 | * protected under relevant copyright laws. The information contained herein |
| 5 | * is confidential and proprietary to MediaTek Inc. and/or its licensors. |
| 6 | * Without the prior written permission of MediaTek inc. and/or its licensors, |
| 7 | * any reproduction, modification, use or disclosure of MediaTek Software, |
| 8 | * and information contained herein, in whole or in part, shall be strictly prohibited. |
| 9 | */ |
| 10 | /* MediaTek Inc. (C) 2010. All rights reserved. |
| 11 | * |
| 12 | * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES |
| 13 | * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE") |
| 14 | * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON |
| 15 | * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES, |
| 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF |
| 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT. |
| 18 | * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE |
| 19 | * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR |
| 20 | * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH |
| 21 | * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES |
| 22 | * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES |
| 23 | * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK |
| 24 | * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR |
| 25 | * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND |
| 26 | * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE, |
| 27 | * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE, |
| 28 | * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO |
| 29 | * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. |
| 30 | * |
| 31 | * The following software/firmware and/or related documentation ("MediaTek Software") |
| 32 | * have been modified by MediaTek Inc. All revisions are subject to any receiver's |
| 33 | * applicable license agreements with MediaTek Inc. |
| 34 | */ |
| 35 | #include "sms/sms.h" |
| 36 | |
| 37 | #include <stdlib.h> |
| 38 | #include <binder/Parcel.h> |
| 39 | |
| 40 | #include "sms/gsm/sms_pdu.h" |
| 41 | #include "sms/cdma/sms_pdu_cdma.h" |
| 42 | #include "common.h" |
| 43 | #include "ecall/eCall.h" |
| 44 | #include "util/utils.h" |
| 45 | |
| 46 | #define GSM_PHONE 1 |
| 47 | |
| 48 | #undef LOG_TAG |
| 49 | #define LOG_TAG "DEMO_SMS" |
| 50 | |
| 51 | #define PROP_ECALL_NUM "vendor.gost.ecall.ecall_sms_fallback_number" |
| 52 | |
| 53 | static void constructGsmSendSmsRilRequest (android::Parcel &p, char *smscPDU, char *pdu) { |
| 54 | p.writeInt32(2); |
| 55 | writeStringToParcel(p, (const char *)smscPDU); |
| 56 | writeStringToParcel(p, (const char *)pdu); |
| 57 | } |
| 58 | |
| 59 | //RIL_REQUEST_SEND_SMS |
| 60 | int sendSMS(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI){ |
| 61 | char smscPDU[30]= {0}; |
| 62 | char **pdu; |
| 63 | char smsc[4] = {0}; |
| 64 | kal_int32 msg_num = 0; |
| 65 | kal_int32 msg_len = 0; |
| 66 | kal_int32 status = MDAPI_RET_ERROR; |
| 67 | kal_int32 index = 0; |
| 68 | |
| 69 | status = _mdapi_sms_get_msg_num(argv[3], atoi(argv[2]), &msg_num, &msg_len); |
| 70 | RLOGD("%s, %s, %d, msg_len = [%d] ,msg_num=[%d]", __FILE__, __FUNCTION__, __LINE__, msg_len, msg_num); |
| 71 | if(status == MDAPI_RET_ERROR){ |
| 72 | RLOGD("get message number failed"); |
| 73 | }else { |
| 74 | //allocate memory for **pdu |
| 75 | pdu = (char **)malloc(sizeof(char *) * msg_num); |
| 76 | if(pdu == NULL){ |
| 77 | RLOGD("%s, %s, %d, allocate memory for pdu failed", __FILE__, __FUNCTION__, __LINE__); |
| 78 | } else { |
| 79 | for(index = 0; index < msg_num; index++){ |
| 80 | pdu[index] = (char *)malloc(sizeof(char)*MAX_PDU_SIZE); |
| 81 | if(pdu[index] == NULL){ |
| 82 | for(int i = 0; i < index; i++){ |
| 83 | free(pdu[i]); |
| 84 | } |
| 85 | free(pdu); |
| 86 | pdu = NULL; |
| 87 | if(pRI != NULL) |
| 88 | { |
| 89 | free(pRI); |
| 90 | } |
| 91 | RLOGD("%s, %s, %d, allocate memory for pdu[%d] failed", __FILE__, __FUNCTION__, __LINE__,index); |
| 92 | return 0; |
| 93 | }else { |
| 94 | memset(pdu[index], 0, MAX_PDU_SIZE); |
| 95 | RLOGD("%s, %s, %d, pdu[%d} init value is: %s ", __FILE__, __FUNCTION__, __LINE__, index, pdu[index]); |
| 96 | } |
| 97 | } |
| 98 | } |
| 99 | //allocate memory for **pdu success |
| 100 | if(index == msg_num){ |
| 101 | if(argc < 5){ |
| 102 | smsPduEncode(smsc, argv[1], argv[3], atoi(argv[2]), smscPDU, pdu); |
| 103 | } else { |
| 104 | smsPduEncode(argv[4], argv[1], argv[3], atoi(argv[2]), smscPDU, pdu); |
| 105 | } |
| 106 | for (index = 0; index < msg_num; index++) { |
| 107 | RLOGD("%s, %s, %d, smscPDU: %s, pdu: %s",__FILE__, __FUNCTION__, __LINE__, smscPDU, pdu[index]); |
| 108 | android::Parcel p; |
| 109 | size_t pos = p.dataPosition(); |
| 110 | RequestInfo *pRI_backup = (RequestInfo *)calloc(1, sizeof(RequestInfo)); |
| 111 | pRI_backup->token = pRI->token; |
| 112 | pRI_backup->pCI = pRI->pCI; |
| 113 | pRI_backup->socket_id = pRI->socket_id; |
| 114 | pRI_backup->p_next = pRI->p_next; |
| 115 | constructGsmSendSmsRilRequest(p, smscPDU, pdu[index]); |
| 116 | p.setDataPosition(pos); |
| 117 | pRI->pCI->dispatchFunction(p, pRI_backup); |
| 118 | } |
| 119 | for(index = 0; index < msg_num; index++){ |
| 120 | free(pdu[index]); |
| 121 | } |
| 122 | |
| 123 | free(pdu); |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | //for auto save sms to sim |
| 128 | if(argc < 5){ |
| 129 | saveSendedSmsInfo(atoi(argv[2]), argv[1], argv[3], smsc); |
| 130 | } else { |
| 131 | saveSendedSmsInfo(atoi(argv[2]), argv[1], argv[3], argv[4]); |
| 132 | } |
| 133 | |
| 134 | if(pRI != NULL) |
| 135 | { |
| 136 | free(pRI); |
| 137 | } |
| 138 | |
| 139 | return 0; |
| 140 | } |
| 141 | |
| 142 | |
| 143 | //RIL_REQUEST_SEND_SMS_EXPECT_MORE |
| 144 | int sendSMSExpectMore(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI){ |
| 145 | char smscPDU[512]= {0}; |
| 146 | char **pdu; |
| 147 | char smsc[4] = {0}; |
| 148 | smsc[0] = '\0'; |
| 149 | kal_int32 msg_num = 0; |
| 150 | kal_int32 msg_len = 0; |
| 151 | kal_int32 status = MDAPI_RET_ERROR; |
| 152 | kal_int32 index = 0; |
| 153 | |
| 154 | status = _mdapi_sms_get_msg_num(argv[3], atoi(argv[2]), &msg_num, &msg_len); |
| 155 | RLOGD("%s, %s, %d, msg_len = [%d] ,msg_num=[%d]", __FILE__, __FUNCTION__, __LINE__, msg_len, msg_num); |
| 156 | if(status == MDAPI_RET_ERROR){ |
| 157 | RLOGD("get message number failed"); |
| 158 | } else { |
| 159 | //allocate memory for **pdu |
| 160 | pdu = (char **)malloc(sizeof(char *) * msg_num); |
| 161 | if(pdu == NULL){ |
| 162 | RLOGD("%s, %s, %d, allocate memory for pdu failed", __FILE__, __FUNCTION__, __LINE__); |
| 163 | } else { |
| 164 | for(index = 0; index < msg_num; index++){ |
| 165 | pdu[index] = (char *)malloc(sizeof(char)*MAX_PDU_SIZE); |
| 166 | if(pdu[index] == NULL){ |
| 167 | for(int i = 0; i < index; i++){ |
| 168 | free(pdu[i]); |
| 169 | } |
| 170 | free(pdu); |
| 171 | pdu = NULL; |
| 172 | if(pRI != NULL) |
| 173 | { |
| 174 | free(pRI); |
| 175 | } |
| 176 | RLOGD("%s, %s, %d, allocate memory for pdu[%d] failed", __FILE__, __FUNCTION__, __LINE__,index); |
| 177 | return 0; |
| 178 | } else { |
| 179 | memset(pdu[index], 0, MAX_PDU_SIZE); |
| 180 | RLOGD("%s, %s, %d, pdu[%d} init value is: %s ", __FILE__, __FUNCTION__, __LINE__, index, pdu[index]); |
| 181 | } |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | //allocate memory for **pdu success |
| 186 | if(index == msg_num){ |
| 187 | if(argc < 5){ |
| 188 | smsPduEncode(smsc, argv[1], argv[3], atoi(argv[2]), smscPDU, pdu); |
| 189 | } else { |
| 190 | smsPduEncode(argv[4], argv[1], argv[3], atoi(argv[2]), smscPDU, pdu); |
| 191 | } |
| 192 | for (index = 0; index < msg_num; index++) { |
| 193 | RLOGD("%s, %s, %d, smscPDU: %s, pdu: %s",__FILE__, __FUNCTION__, __LINE__, smscPDU, pdu[index]); |
| 194 | android::Parcel p; |
| 195 | size_t pos = p.dataPosition(); |
| 196 | RequestInfo *pRI_backup = (RequestInfo *)calloc(1, sizeof(RequestInfo)); |
| 197 | pRI_backup->token = pRI->token; |
| 198 | pRI_backup->pCI = pRI->pCI; |
| 199 | pRI_backup->socket_id = pRI->socket_id; |
| 200 | pRI_backup->p_next = pRI->p_next; |
| 201 | constructGsmSendSmsRilRequest(p, smscPDU, pdu[index]); |
| 202 | p.setDataPosition(pos); |
| 203 | pRI->pCI->dispatchFunction(p, pRI_backup); |
| 204 | } |
| 205 | |
| 206 | for(index = 0; index < msg_num; index++){ |
| 207 | free(pdu[index]); |
| 208 | } |
| 209 | |
| 210 | free(pdu); |
| 211 | pdu = NULL; |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | if(pRI != NULL) |
| 216 | { |
| 217 | free(pRI); |
| 218 | } |
| 219 | |
| 220 | //for auto save sms to sim |
| 221 | if(argc < 5){ |
| 222 | saveSendedSmsInfo(atoi(argv[2]), argv[1], argv[3], smsc); |
| 223 | } else { |
| 224 | saveSendedSmsInfo(atoi(argv[2]), argv[1], argv[3], argv[4]); |
| 225 | } |
| 226 | |
| 227 | return 0; |
| 228 | } |
| 229 | |
| 230 | //RIL_REQUEST_IMS_SEND_SMS |
| 231 | int sendImsGsmSms(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI){ |
| 232 | char smscPDU[30]= {0}; |
| 233 | char **pdu; |
| 234 | char smsc[4] = {0}; |
| 235 | kal_int32 msg_num = 0; |
| 236 | kal_int32 msg_len = 0; |
| 237 | kal_int32 status = MDAPI_RET_ERROR; |
| 238 | kal_int32 index = 0; |
| 239 | uint8_t retry = atoi(argv[4]); |
| 240 | int32_t messageRef = atoi(argv[5]); |
| 241 | |
| 242 | status = _mdapi_sms_get_msg_num(argv[3], atoi(argv[2]), &msg_num, &msg_len); |
| 243 | RLOGD("%s, %s, %d, msg_len = [%d] ,msg_num=[%d]", __FILE__, __FUNCTION__, __LINE__, msg_len, msg_num); |
| 244 | if(status == MDAPI_RET_ERROR){ |
| 245 | RLOGD("get message number failed"); |
| 246 | } else { |
| 247 | //allocate memory for **pdu |
| 248 | pdu = (char **)malloc(sizeof(char *) * msg_num); |
| 249 | if(pdu == NULL){ |
| 250 | RLOGD("%s, %s, %d, allocate memory for pdu failed", __FILE__, __FUNCTION__, __LINE__); |
| 251 | } else { |
| 252 | for(index = 0; index < msg_num; index++){ |
| 253 | pdu[index] = (char *)malloc(sizeof(char)*MAX_PDU_SIZE); |
| 254 | if(pdu[index] == NULL){ |
| 255 | for(int i = 0; i < index; i++){ |
| 256 | free(pdu[i]); |
| 257 | } |
| 258 | free(pdu); |
| 259 | pdu = NULL; |
| 260 | if(pRI != NULL) |
| 261 | { |
| 262 | free(pRI); |
| 263 | } |
| 264 | RLOGD("%s, %s, %d, allocate memory for pdu[%d] failed", __FILE__, __FUNCTION__, __LINE__,index); |
| 265 | return 0; |
| 266 | } else { |
| 267 | memset(pdu[index], 0, MAX_PDU_SIZE); |
| 268 | RLOGD("%s, %s, %d, pdu[%d} init value is: %s ", __FILE__, __FUNCTION__, __LINE__, index, pdu[index]); |
| 269 | } |
| 270 | } |
| 271 | } |
| 272 | |
| 273 | //allocate memory for **pdu success |
| 274 | if(index == msg_num){ |
| 275 | if(argc < 7){ |
| 276 | smsPduEncode(smsc, argv[1], argv[3], atoi(argv[2]), smscPDU, pdu); |
| 277 | } else { |
| 278 | smsPduEncode(argv[6], argv[1], argv[3], atoi(argv[2]), smscPDU, pdu); |
| 279 | } |
| 280 | for (index = 0; index < msg_num; index++) { |
| 281 | RLOGD("%s, %s, %d, smscPDU: %s, pdu: %s",__FILE__, __FUNCTION__, __LINE__, smscPDU, pdu[index]); |
| 282 | android::Parcel p; |
| 283 | size_t pos = p.dataPosition(); |
| 284 | RequestInfo *pRI_backup = (RequestInfo *)calloc(1, sizeof(RequestInfo)); |
| 285 | pRI_backup->token = pRI->token; |
| 286 | pRI_backup->pCI = pRI->pCI; |
| 287 | pRI_backup->socket_id = pRI->socket_id; |
| 288 | pRI_backup->p_next = pRI->p_next; |
| 289 | p.writeInt32(RADIO_TECH_3GPP); |
| 290 | p.write(&retry, sizeof(retry)); |
| 291 | p.write(&messageRef, sizeof(messageRef)); |
| 292 | constructGsmSendSmsRilRequest(p, smscPDU, pdu[index]); |
| 293 | p.setDataPosition(pos); |
| 294 | pRI->pCI->dispatchFunction(p, pRI_backup); |
| 295 | } |
| 296 | |
| 297 | for(index = 0; index < msg_num; index++){ |
| 298 | free(pdu[index]); |
| 299 | } |
| 300 | |
| 301 | free(pdu); |
| 302 | pdu = NULL; |
| 303 | } |
| 304 | } |
| 305 | |
| 306 | if(pRI != NULL) |
| 307 | { |
| 308 | free(pRI); |
| 309 | pRI = NULL; |
| 310 | } |
| 311 | |
| 312 | //for auto save sms to sim |
| 313 | if(argc < 7){ |
| 314 | saveSendedSmsInfo(atoi(argv[2]), argv[1], argv[3], smsc); |
| 315 | } else { |
| 316 | saveSendedSmsInfo(atoi(argv[2]), argv[1], argv[3], argv[6]); |
| 317 | } |
| 318 | |
| 319 | return 0; |
| 320 | } |
| 321 | |
| 322 | int sendImsCdmaSms(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI) { |
| 323 | uint8_t retry = atoi(argv[1]); |
| 324 | int32_t messageRef = atoi(argv[2]); |
| 325 | char* destAddr = argv[3]; |
| 326 | char* message = argv[4]; |
| 327 | createCdmaMessage(pRI,destAddr,message, false, retry, messageRef); |
| 328 | return 0; |
| 329 | } |
| 330 | |
| 331 | //RIL_REQUEST_WRITE_SMS_TO_SIM |
| 332 | int writeSmsToSim(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI){ |
| 333 | char smscPDU[30]= {0}; |
| 334 | char **pdu; |
| 335 | char smsc[4] = {0}; |
| 336 | kal_int32 msg_num = 0; |
| 337 | kal_int32 msg_len = 0; |
| 338 | kal_int32 status = MDAPI_RET_ERROR; |
| 339 | kal_int32 index = 0; |
| 340 | |
| 341 | status = _mdapi_sms_get_msg_num(argv[4], atoi(argv[3]), &msg_num, &msg_len); |
| 342 | RLOGD("%s, %s, %d, msg_len = [%d] ,msg_num=[%d]", __FILE__, __FUNCTION__, __LINE__, msg_len, msg_num); |
| 343 | if(status == MDAPI_RET_ERROR){ |
| 344 | RLOGD("get message number failed"); |
| 345 | } else { |
| 346 | //allocate memory for **pdu |
| 347 | pdu = (char **)malloc(sizeof(char *) * msg_num); |
| 348 | if(pdu == NULL){ |
| 349 | RLOGD("%s, %s, %d, allocate memory for pdu failed", __FILE__, __FUNCTION__, __LINE__); |
| 350 | } else { |
| 351 | for(index = 0; index < msg_num; index++){ |
| 352 | pdu[index] = (char *)malloc(sizeof(char)*MAX_PDU_SIZE); |
| 353 | if(pdu[index] == NULL){ |
| 354 | for(int i = 0; i < index; i++){ |
| 355 | free(pdu[i]); |
| 356 | } |
| 357 | free(pdu); |
| 358 | pdu = NULL; |
| 359 | if(pRI != NULL) |
| 360 | { |
| 361 | free(pRI); |
| 362 | } |
| 363 | RLOGD("%s, %s, %d, allocate memory for pdu[%d] failed", __FILE__, __FUNCTION__, __LINE__,index); |
| 364 | return 0; |
| 365 | } else { |
| 366 | memset(pdu[index], 0, MAX_PDU_SIZE); |
| 367 | RLOGD("%s, %s, %d, pdu[%d} init value is: %s ", __FILE__, __FUNCTION__, __LINE__, index, pdu[index]); |
| 368 | } |
| 369 | } |
| 370 | } |
| 371 | //allocate memory for **pdu success |
| 372 | if(index == msg_num){ |
| 373 | if(argc < 6){ |
| 374 | smsPduEncode(smsc, argv[2], argv[4], atoi(argv[3]), smscPDU, pdu); |
| 375 | } else { |
| 376 | smsPduEncode(argv[5], argv[2], argv[4], atoi(argv[3]), smscPDU, pdu); |
| 377 | } |
| 378 | for (index = 0; index < msg_num; index++) { |
| 379 | RLOGD("%s, %s, %d, smscPDU: %s, pdu: %s",__FILE__, __FUNCTION__, __LINE__, smscPDU, pdu[index]); |
| 380 | android::Parcel p; |
| 381 | size_t pos = p.dataPosition(); |
| 382 | RequestInfo *pRI_backup = (RequestInfo *)calloc(1, sizeof(RequestInfo)); |
| 383 | pRI_backup->token = pRI->token; |
| 384 | pRI_backup->pCI = pRI->pCI; |
| 385 | pRI_backup->socket_id = pRI->socket_id; |
| 386 | pRI_backup->p_next = pRI->p_next; |
| 387 | p.writeInt32(atoi(argv[1])); |
| 388 | writeStringToParcel(p, (const char *)pdu[index]); |
| 389 | writeStringToParcel(p, (const char *)smscPDU); |
| 390 | p.setDataPosition(pos); |
| 391 | pRI->pCI->dispatchFunction(p, pRI_backup); |
| 392 | } |
| 393 | |
| 394 | for(index = 0; index < msg_num; index++){ |
| 395 | free(pdu[index]); |
| 396 | } |
| 397 | |
| 398 | free(pdu); |
| 399 | pdu = NULL; |
| 400 | } |
| 401 | } |
| 402 | if(pRI != NULL) |
| 403 | { |
| 404 | free(pRI); |
| 405 | } |
| 406 | |
| 407 | return 0; |
| 408 | } |
| 409 | |
| 410 | //RIL_REQUEST_DELETE_SMS_ON_SIM |
| 411 | int deleteSmsOnSim(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI){ |
| 412 | android::Parcel p; |
| 413 | size_t pos = p.dataPosition(); |
| 414 | |
| 415 | p.writeInt32(1); |
| 416 | p.writeInt32(atoi(argv[1])); |
| 417 | |
| 418 | p.setDataPosition(pos); |
| 419 | pRI->pCI->dispatchFunction(p, pRI); |
| 420 | |
| 421 | return 0; |
| 422 | } |
| 423 | |
| 424 | //RIL_REQUEST_SMS_ACKNOWLEDGE |
| 425 | int acknowledgeLastIncomingGsmSms(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI){ |
| 426 | android::Parcel p; |
| 427 | size_t pos = p.dataPosition(); |
| 428 | |
| 429 | p.writeInt32(2); |
| 430 | p.writeInt32(atoi(argv[1]) ? 1 : 0); |
| 431 | p.writeInt32(atoi(argv[2])); |
| 432 | |
| 433 | p.setDataPosition(pos); |
| 434 | pRI->pCI->dispatchFunction(p, pRI); |
| 435 | |
| 436 | return 0; |
| 437 | } |
| 438 | |
| 439 | //RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU |
| 440 | int acknowledgeIncomingGsmSmsWithPdu(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI){ |
| 441 | android::Parcel p; |
| 442 | size_t pos = p.dataPosition(); |
| 443 | |
| 444 | p.writeInt32(2); |
| 445 | p.writeInt32(atoi(argv[1])); |
| 446 | p.writeInt32(atoi(argv[2])); |
| 447 | |
| 448 | p.setDataPosition(pos); |
| 449 | pRI->pCI->dispatchFunction(p, pRI); |
| 450 | |
| 451 | return 0; |
| 452 | } |
| 453 | |
| 454 | //RIL_REQUEST_REPORT_SMS_MEMORY_STATUS |
| 455 | int reportSmsMemoryStatus(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI){ |
| 456 | android::Parcel p; |
| 457 | size_t pos = p.dataPosition(); |
| 458 | |
| 459 | p.writeInt32(1); |
| 460 | p.writeInt32(atoi(argv[1]) ? 1 : 0); |
| 461 | |
| 462 | p.setDataPosition(pos); |
| 463 | pRI->pCI->dispatchFunction(p, pRI); |
| 464 | |
| 465 | return 0; |
| 466 | } |
| 467 | |
| 468 | //RIL_REQUEST_SET_SMSC_ADDRESS |
| 469 | int setSmscAddress(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI){ |
| 470 | android::Parcel p; |
| 471 | size_t pos = p.dataPosition(); |
| 472 | |
| 473 | writeStringToParcel(p, (const char *)argv[1]); |
| 474 | |
| 475 | p.setDataPosition(pos); |
| 476 | pRI->pCI->dispatchFunction(p, pRI); |
| 477 | |
| 478 | return 0; |
| 479 | } |
| 480 | //RIL_REQUEST_GET_SMSC_ADDRESS |
| 481 | int getSmscAddress(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI){ |
| 482 | android::Parcel p; |
| 483 | size_t pos = p.dataPosition(); |
| 484 | |
| 485 | p.setDataPosition(pos); |
| 486 | pRI->pCI->dispatchFunction(p, pRI); |
| 487 | |
| 488 | return 0; |
| 489 | } |
| 490 | |
| 491 | void sendSMSACK(RIL_SOCKET_ID soc_id) |
| 492 | { |
| 493 | sendSmsMsg(soc_id); //for power manager test. |
| 494 | android::requestSMSACKNOWLEDGE(soc_id); |
| 495 | return; |
| 496 | } |
| 497 | |
| 498 | int responseNewSMS(const char *data, size_t datalen, int soc_id,int32_t unsol){ |
| 499 | char smsc[512] = {0}; |
| 500 | char msg[512] = {0}; |
| 501 | char num[512] = {0}; |
| 502 | int charset = 0; |
| 503 | RLOGD("slot: %d, len: %d, sms: %s",soc_id, datalen, data); |
| 504 | smsPduDecode(data, datalen, num, smsc, msg, &charset); |
| 505 | if(s_Env) |
| 506 | { |
| 507 | s_Env->recive_new_sms_cb(soc_id,num,smsc,msg,charset); |
| 508 | } |
| 509 | printf("[EVENT][MT_SMS][SIM%d]PDU decode:smsc: %s, phone number: %s , charset: %d, msg_len: %d, message content: %s\n", soc_id, smsc, num, charset, strlen(msg), msg); |
| 510 | RLOGD("[EVENT][MT_SMS][SIM%d]PDU decode:smsc: %s, phone number: %s , charset: %d, msg_len: %d, message content: %s", soc_id, smsc, num, charset, strlen(msg), msg); |
| 511 | if(isGostEcall() && (MDAPI_SMS_CHARSET_GSM_8BIT == charset)) |
| 512 | { |
| 513 | gostParseSmsHandle(soc_id, num, msg); |
| 514 | } |
| 515 | |
| 516 | return 0; |
| 517 | } |
| 518 | |
| 519 | #ifdef C2K_SUPPORT |
| 520 | //RIL_REQUEST_CDMA_GET_BROADCAST_SMS_CONFIG |
| 521 | int getCdmaBroadcastConfig(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI){ |
| 522 | printf("test function is %s\n", __func__); |
| 523 | android::Parcel p; |
| 524 | pRI->pCI->dispatchFunction(p, pRI); |
| 525 | return 0; |
| 526 | } |
| 527 | |
| 528 | //RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM |
| 529 | int deleteSmsOnRUIM(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI) { |
| 530 | if(argc < 2) { |
| 531 | RLOGE("%s parameter error!",__func__); |
| 532 | free(pRI); |
| 533 | return -1; |
| 534 | } |
| 535 | printf("test function is %s\n", __func__); |
| 536 | android::Parcel p; |
| 537 | size_t pos = p.dataPosition(); |
| 538 | |
| 539 | p.writeInt32(1); |
| 540 | p.writeInt32(atoi(argv[1])); |
| 541 | |
| 542 | p.setDataPosition(pos); |
| 543 | pRI->pCI->dispatchFunction(p, pRI); |
| 544 | |
| 545 | return 0; |
| 546 | } |
| 547 | |
| 548 | //RIL_REQUEST_CDMA_SET_BROADCAST_SMS_CONFIG |
| 549 | int setCdmaBroadcastConfig(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI){ |
| 550 | if(argc < 5) { |
| 551 | RLOGE("%s parameter error!",__func__); |
| 552 | free(pRI); |
| 553 | return -1; |
| 554 | } |
| 555 | int from = atoi(argv[1]); |
| 556 | int to = atoi(argv[2]); |
| 557 | if (from < 0 || to < 0 || from > to) { |
| 558 | RLOGE("%s parameter error: from > to !",__func__); |
| 559 | free(pRI); |
| 560 | return -1; |
| 561 | } |
| 562 | int num = (to - from) + 1; |
| 563 | int language = atoi(argv[3]); |
| 564 | int selected = atoi(argv[4]); |
| 565 | if (selected > 0) { |
| 566 | selected = 1; |
| 567 | } else { |
| 568 | selected = 0; |
| 569 | } |
| 570 | android::Parcel p; |
| 571 | size_t pos = p.dataPosition(); |
| 572 | p.writeInt32(num); |
| 573 | for(int index = from; index <= to ; index++){ |
| 574 | p.writeInt32(index); |
| 575 | p.writeInt32(language); |
| 576 | p.writeInt32(selected); |
| 577 | } |
| 578 | p.setDataPosition(pos); |
| 579 | pRI->pCI->dispatchFunction(p, pRI); |
| 580 | return 0; |
| 581 | } |
| 582 | |
| 583 | //RIL_REQUEST_CDMA_SMS_BROADCAST_ACTIVATION |
| 584 | int setCdmaBroadcastActivation(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI){ |
| 585 | //printf("test function is %s\n", __func__); |
| 586 | if(argc < 2) { |
| 587 | RLOGE("%s parameter error!",__func__); |
| 588 | free(pRI); |
| 589 | return -1; |
| 590 | } |
| 591 | android::Parcel p; |
| 592 | size_t pos = p.dataPosition(); |
| 593 | p.writeInt32(1); |
| 594 | p.writeInt32(atoi(argv[1])? 1 : 0); |
| 595 | p.setDataPosition(pos); |
| 596 | pRI->pCI->dispatchFunction(p, pRI); |
| 597 | |
| 598 | return 0; |
| 599 | } |
| 600 | |
| 601 | //RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM |
| 602 | int writeSmsToRuim(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI){ |
| 603 | printf("test function is %s\n", __func__); |
| 604 | char* destAddr = argv[1]; |
| 605 | char* message = argv[2]; |
| 606 | if(argc < 3 || destAddr == NULL || message == NULL ) { |
| 607 | RLOGE("%s parameter error!",__func__); |
| 608 | free(pRI); |
| 609 | return -1; |
| 610 | } |
| 611 | createCdmaMessage(pRI,destAddr,message, true, 0 ,0); |
| 612 | return 0; |
| 613 | } |
| 614 | |
| 615 | //RIL_REQUEST_CDMA_SEND_SMS |
| 616 | int sendCdmaSms(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI){ |
| 617 | if(argc != 3) { |
| 618 | RLOGE("%s parameter num error!",__func__); |
| 619 | free(pRI); |
| 620 | return -1; |
| 621 | } |
| 622 | char* destAddr = argv[1]; |
| 623 | char* message = argv[2]; |
| 624 | if(destAddr == NULL || message == NULL ) { |
| 625 | RLOGE("%s parameter error!",__func__); |
| 626 | free(pRI); |
| 627 | return -1; |
| 628 | } |
| 629 | createCdmaMessage(pRI,destAddr,message, false, 0 ,0); |
| 630 | return 0; |
| 631 | } |
| 632 | |
| 633 | //RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE |
| 634 | int acknowledgeLastIncomingCdmaSms(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI){ |
| 635 | //printf("test function is %s\n", __func__); |
| 636 | android::Parcel p; |
| 637 | size_t pos = p.dataPosition(); |
| 638 | p.writeInt32(0); |
| 639 | p.writeInt32(1); |
| 640 | p.setDataPosition(pos); |
| 641 | pRI->pCI->dispatchFunction(p, pRI); |
| 642 | return 0; |
| 643 | } |
| 644 | #endif /*C2K_SUPPORT*/ |
| 645 | |
| 646 | //RIL_REQUEST_GSM_GET_BROADCAST_SMS_CONFIG |
| 647 | int getGsmBroadcastConfig(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI){ |
| 648 | android::Parcel p; |
| 649 | pRI->pCI->dispatchFunction(p, pRI); |
| 650 | return 0; |
| 651 | } |
| 652 | |
| 653 | //RIL_REQUEST_GSM_SET_BROADCAST_SMS_CONFIG |
| 654 | int setGsmBroadcastConfig(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI) { |
| 655 | if(argc != 6) { |
| 656 | RLOGE("%s parameter error!",__func__); |
| 657 | free(pRI); |
| 658 | return -1; |
| 659 | } |
| 660 | android::Parcel p; |
| 661 | size_t pos = p.dataPosition(); |
| 662 | p.writeInt32(1); |
| 663 | p.writeInt32(atoi(argv[1])); |
| 664 | p.writeInt32(atoi(argv[2])); |
| 665 | p.writeInt32(atoi(argv[3])); |
| 666 | p.writeInt32(atoi(argv[4])); |
| 667 | p.writeInt32(atoi(argv[5])); |
| 668 | p.setDataPosition(pos); |
| 669 | pRI->pCI->dispatchFunction(p, pRI); |
| 670 | return 0; |
| 671 | } |
| 672 | |
| 673 | //RIL_REQUEST_GSM_SMS_BROADCAST_ACTIVATION |
| 674 | int setGsmBroadcastActivation(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI) { |
| 675 | if(argc != 2) { |
| 676 | RLOGE("%s parameter error!",__func__); |
| 677 | free(pRI); |
| 678 | return -1; |
| 679 | } |
| 680 | android::Parcel p; |
| 681 | size_t pos = p.dataPosition(); |
| 682 | p.writeInt32(1); |
| 683 | p.writeInt32(atoi(argv[1])); |
| 684 | p.setDataPosition(pos); |
| 685 | pRI->pCI->dispatchFunction(p, pRI); |
| 686 | return 0; |
| 687 | } |
| 688 | |
| 689 | int getSmsSimMemStatus(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI){ |
| 690 | android::Parcel p; |
| 691 | size_t pos = p.dataPosition(); |
| 692 | |
| 693 | p.setDataPosition(pos); |
| 694 | pRI->pCI->dispatchFunction(p, pRI); |
| 695 | |
| 696 | return 0; |
| 697 | } |
| 698 | |
| 699 | static bool auto_save_sms_to_sim = false; |
| 700 | static bool Sim_sms_storage_full = false; |
| 701 | static smsSaveInfo* psmsSaveInfo = NULL; |
| 702 | |
| 703 | int setAutoSaveSmsToSimFlag(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI){ |
| 704 | if(argc != 2) { |
| 705 | RLOGE("%s parameter error!",__func__); |
| 706 | free(pRI); |
| 707 | return -1; |
| 708 | } |
| 709 | |
| 710 | int enable = atoi(argv[1]); |
| 711 | if(enable) |
| 712 | { |
| 713 | auto_save_sms_to_sim = true; |
| 714 | } |
| 715 | else |
| 716 | { |
| 717 | auto_save_sms_to_sim = false; |
| 718 | } |
| 719 | RLOGE("%s:%d", __FUNCTION__, auto_save_sms_to_sim); |
| 720 | return 0; |
| 721 | } |
| 722 | |
| 723 | int setSimSmsStorageFullFlag(bool enable) |
| 724 | { |
| 725 | Sim_sms_storage_full = enable; |
| 726 | RLOGE("%s:%d", __FUNCTION__, Sim_sms_storage_full); |
| 727 | return 0; |
| 728 | } |
| 729 | |
| 730 | //sent status save |
| 731 | int saveSendedSmsInfo(int charset, char* num, char* msg, char* smsc) |
| 732 | { |
| 733 | if(psmsSaveInfo == NULL) |
| 734 | { |
| 735 | psmsSaveInfo = (smsSaveInfo*)malloc(sizeof(smsSaveInfo)); |
| 736 | } |
| 737 | memset(psmsSaveInfo, 0, sizeof(psmsSaveInfo)); |
| 738 | |
| 739 | psmsSaveInfo->charset = charset; |
| 740 | psmsSaveInfo->sendStatus = 3; //UnRead|Read|UnSent|Sent |
| 741 | strcpy(psmsSaveInfo->num, num); |
| 742 | strcpy(psmsSaveInfo->sms, msg); |
| 743 | strcpy(psmsSaveInfo->smsc, smsc); |
| 744 | RLOGE("%s:send sms saved", __FUNCTION__); |
| 745 | |
| 746 | return 0; |
| 747 | } |
| 748 | |
| 749 | int sendStatusWriteSmsToSim(int socket_id) |
| 750 | { |
| 751 | if(psmsSaveInfo == NULL) |
| 752 | { |
| 753 | RLOGE("%s error psmsSaveInfo is null",__func__); |
| 754 | return 0; |
| 755 | } |
| 756 | autoWriteSmsToSim(psmsSaveInfo, socket_id); |
| 757 | free(psmsSaveInfo); |
| 758 | psmsSaveInfo = NULL; |
| 759 | return 0; |
| 760 | } |
| 761 | |
| 762 | int autoWriteSmsToSim(smsSaveInfo *smsInfo, int id) |
| 763 | { |
| 764 | int argc = 6; |
| 765 | char *argv[6]; |
| 766 | RIL_SOCKET_ID socket_id; |
| 767 | char charset[4] = {0}; |
| 768 | char status[4] = {0}; |
| 769 | |
| 770 | if((true == auto_save_sms_to_sim)&&(false == Sim_sms_storage_full)) |
| 771 | { |
| 772 | RequestInfo *pRI = creatRILInfoAndInit(RIL_REQUEST_WRITE_SMS_TO_SIM, UDP, (RIL_SOCKET_ID)(id)); |
| 773 | if(pRI == NULL) |
| 774 | { |
| 775 | RLOGE("error PRI is NULL"); |
| 776 | return 0; |
| 777 | } |
| 778 | sprintf(charset, "%d", smsInfo->charset); |
| 779 | argv[3] = charset; |
| 780 | |
| 781 | argv[0] = "RIL_REQUEST_WRITE_SMS_TO_SIM"; |
| 782 | sprintf(status, "%d", smsInfo->sendStatus); |
| 783 | argv[1] = status; |
| 784 | argv[2] = smsInfo->num; |
| 785 | argv[4] = smsInfo->sms; |
| 786 | argv[5] = smsInfo->smsc; |
| 787 | |
| 788 | RLOGE("%s status:%s, num:%s, sms:%s, charset:%s, sms:%s",__func__, |
| 789 | argv[1],argv[2],argv[3],argv[5],argv[4]); |
| 790 | |
| 791 | writeSmsToSim(argc, argv, pRI->socket_id, pRI); |
| 792 | } |
| 793 | return 0; |
| 794 | } |
| 795 | |
| 796 | int unreadStatusWriteSMSToSim(const char *data, size_t datalen, int soc_id) |
| 797 | { |
| 798 | char smscPDU[30]= {0}; |
| 799 | char pdu[MAX_PDU_SIZE] = {0}; |
| 800 | int32_t status = 0; |
| 801 | RLOGD("%s:slot: %d, len: %d, sms: %s",__FUNCTION__, soc_id, datalen, data); |
| 802 | |
| 803 | if((true == auto_save_sms_to_sim)&&(false == Sim_sms_storage_full)) |
| 804 | { |
| 805 | RequestInfo *pRI = creatRILInfoAndInit(RIL_REQUEST_WRITE_SMS_TO_SIM, UDP, (RIL_SOCKET_ID)(soc_id)); |
| 806 | if(pRI == NULL) |
| 807 | { |
| 808 | RLOGE("error PRI is NULL"); |
| 809 | return 0; |
| 810 | } |
| 811 | if(getNewSmsPduAndSmsc(data, datalen, smscPDU, pdu) < 0) |
| 812 | { |
| 813 | if(pRI != NULL) |
| 814 | { |
| 815 | free(pRI); |
| 816 | pRI = NULL; |
| 817 | } |
| 818 | RLOGD("%s, %s, %d, smsc: ERR",__FILE__, __FUNCTION__, __LINE__); |
| 819 | return 0; |
| 820 | } |
| 821 | RLOGD("%s, %s, %d, smsc: %s, msg: %s",__FILE__, __FUNCTION__, __LINE__, smscPDU, pdu); |
| 822 | |
| 823 | android::Parcel p; |
| 824 | size_t pos = p.dataPosition(); |
| 825 | RequestInfo *pRI_backup = (RequestInfo *)calloc(1, sizeof(RequestInfo)); |
| 826 | pRI_backup->token = pRI->token; |
| 827 | pRI_backup->pCI = pRI->pCI; |
| 828 | pRI_backup->socket_id = pRI->socket_id; |
| 829 | pRI_backup->p_next = pRI->p_next; |
| 830 | p.writeInt32(status); |
| 831 | writeStringToParcel(p, (const char *)pdu); |
| 832 | writeStringToParcel(p, (const char *)smscPDU); |
| 833 | p.setDataPosition(pos); |
| 834 | pRI->pCI->dispatchFunction(p, pRI_backup); |
| 835 | |
| 836 | if(pRI != NULL) |
| 837 | { |
| 838 | free(pRI); |
| 839 | pRI = NULL; |
| 840 | } |
| 841 | } |
| 842 | return 0; |
| 843 | } |
| 844 | |
| 845 | int gostSendSmsForMsd(int id, char *num, char *msd) |
| 846 | { |
| 847 | int argc = 4; |
| 848 | char *argv[5]; |
| 849 | char charset[4] = {0}; |
| 850 | |
| 851 | RequestInfo *pRI = creatRILInfoAndInit(RIL_REQUEST_SEND_SMS, UDP, (RIL_SOCKET_ID)(id)); |
| 852 | if(pRI == NULL) |
| 853 | { |
| 854 | RLOGE("error PRI is NULL"); |
| 855 | return 0; |
| 856 | } |
| 857 | char configNum[140]= {0}; |
| 858 | utils::mtk_property_get(PROP_ECALL_NUM, configNum, "112"); |
| 859 | |
| 860 | sprintf(charset, "%d", MDAPI_SMS_CHARSET_GSM_8BIT); |
| 861 | argv[2] = charset; |
| 862 | |
| 863 | argv[0] = "RIL_REQUEST_SEND_SMS"; |
| 864 | argv[1] = configNum; |
| 865 | argv[3] = msd; |
| 866 | gostSaveSmsData(argc, argv, (RIL_SOCKET_ID)(id)); |
| 867 | sendSMS(argc, argv, pRI->socket_id, pRI); |
| 868 | |
| 869 | return 0; |
| 870 | } |
| 871 | |
| 872 | int getGsmBroadcastLanguage(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI){ |
| 873 | android::Parcel p; |
| 874 | pRI->pCI->dispatchFunction(p, pRI); |
| 875 | return 0; |
| 876 | } |
| 877 | |
| 878 | int setGsmBroadcastLanguage(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI) { |
| 879 | if(argc != 2) { |
| 880 | RLOGE("%s parameter error!",__func__); |
| 881 | free(pRI); |
| 882 | return -1; |
| 883 | } |
| 884 | android::Parcel p; |
| 885 | size_t pos = p.dataPosition(); |
| 886 | |
| 887 | writeStringToParcel(p, (const char *)argv[1]); |
| 888 | |
| 889 | p.setDataPosition(pos); |
| 890 | pRI->pCI->dispatchFunction(p, pRI); |
| 891 | return 0; |
| 892 | } |
| 893 | |