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 <stdlib.h> |
| 36 | #include <binder/Parcel.h> |
| 37 | #include <log/log.h> |
| 38 | #include <vendor-ril/telephony/ril.h> |
| 39 | #include <strings.h> |
| 40 | #include <string> |
| 41 | |
| 42 | #include "sim.h" |
| 43 | #include "common.h" |
| 44 | #include "Radio_capability_switch_util.h" |
| 45 | |
| 46 | #undef LOG_TAG |
| 47 | #define LOG_TAG "DEMO_SIM" |
| 48 | |
| 49 | static char* checkParameters(char* para){ |
| 50 | if (strcasecmp(para, "null") == 0) { |
| 51 | return ""; |
| 52 | } else { |
| 53 | return para; |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | int getIccCardStatus(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI) { |
| 58 | if(argc != 1) |
| 59 | { |
| 60 | free(pRI); |
| 61 | RLOGD("the paremeters numbers isn't right , so return"); |
| 62 | return -1; |
| 63 | } |
| 64 | RLOGD("getIccCardStatus %d: " , pRI->pCI->requestNumber); |
| 65 | android::Parcel p; |
| 66 | |
| 67 | pRI->pCI->dispatchFunction(p, pRI); |
| 68 | return 0; |
| 69 | } |
| 70 | |
| 71 | int supplyIccPinForApp(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI) { |
| 72 | if(argc != 2) |
| 73 | { |
| 74 | free(pRI); |
| 75 | RLOGD("the paremeters numbers isn't right , so return"); |
| 76 | return -1; |
| 77 | } |
| 78 | |
| 79 | const char *pin = argv[1]; |
| 80 | android::Parcel p; |
| 81 | size_t pos = p.dataPosition(); |
| 82 | |
| 83 | p.writeInt32(2); |
| 84 | writeStringToParcel(p, pin); |
| 85 | writeStringToParcel(p, getAid(socket_id)); |
| 86 | p.setDataPosition(pos); |
| 87 | pRI->pCI->dispatchFunction(p, pRI); |
| 88 | |
| 89 | return 0; |
| 90 | } |
| 91 | |
| 92 | |
| 93 | int changeIccPinForApp(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI) { |
| 94 | if(argc != 3) |
| 95 | { |
| 96 | free(pRI); |
| 97 | RLOGD("the paremeters numbers isn't right , so return"); |
| 98 | return -1; |
| 99 | } |
| 100 | |
| 101 | const char *oldPin = argv[1]; |
| 102 | const char *newPin = argv[2]; |
| 103 | android::Parcel p; |
| 104 | size_t pos = p.dataPosition(); |
| 105 | p.writeInt32(3); |
| 106 | writeStringToParcel(p, oldPin); |
| 107 | writeStringToParcel(p, newPin); |
| 108 | writeStringToParcel(p, getAid(socket_id)); |
| 109 | p.setDataPosition(pos); |
| 110 | |
| 111 | pRI->pCI->dispatchFunction(p, pRI); |
| 112 | |
| 113 | return 0; |
| 114 | } |
| 115 | |
| 116 | int supplyIccPukForApp(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI) { |
| 117 | if(argc != 3) |
| 118 | { |
| 119 | free(pRI); |
| 120 | RLOGD("the paremeters numbers isn't right , so return"); |
| 121 | return -1; |
| 122 | } |
| 123 | |
| 124 | const char *puk = argv[1]; |
| 125 | const char *newPin = argv[2]; |
| 126 | android::Parcel p; |
| 127 | size_t pos = p.dataPosition(); |
| 128 | // start customize |
| 129 | p.writeInt32(3); |
| 130 | //check |
| 131 | writeStringToParcel(p, puk); |
| 132 | writeStringToParcel(p, newPin); |
| 133 | writeStringToParcel(p, getAid(socket_id)); |
| 134 | p.setDataPosition(pos); |
| 135 | |
| 136 | pRI->pCI->dispatchFunction(p, pRI); |
| 137 | |
| 138 | return 0; |
| 139 | } |
| 140 | |
| 141 | int getIMSIForApp(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI) { |
| 142 | if (argc != 1) { |
| 143 | free(pRI); |
| 144 | RLOGD("the paremeters numbers isn't right , so return"); |
| 145 | return -1; |
| 146 | } |
| 147 | android::Parcel p; |
| 148 | size_t pos = p.dataPosition(); |
| 149 | p.writeInt32(1); |
| 150 | RLOGD("getIMSIForApp, aid: %s", getAid(socket_id)); |
| 151 | writeStringToParcel(p, getAid(socket_id)); |
| 152 | p.setDataPosition(pos); |
| 153 | pRI->pCI->dispatchFunction(p, pRI); |
| 154 | |
| 155 | return 0; |
| 156 | } |
| 157 | |
| 158 | |
| 159 | int queryIccidForApp(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI) { |
| 160 | if(argc != 1) |
| 161 | { |
| 162 | free(pRI); |
| 163 | RLOGD("the paremeters numbers isn't right , so return"); |
| 164 | return -1; |
| 165 | } |
| 166 | RLOGD("queryIccidForApp %d: " , pRI->pCI->requestNumber); |
| 167 | android::Parcel p; |
| 168 | |
| 169 | pRI->pCI->dispatchFunction(p, pRI); |
| 170 | return 0; |
| 171 | } |
| 172 | |
| 173 | bool is_valid(int id){ |
| 174 | RLOGD("is_valid id: %d", id); |
| 175 | return (id == 0)||(id == 1); |
| 176 | } |
| 177 | |
| 178 | //SET_DEFAULT_SIM_ALL |
| 179 | int set_default_sim_all(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI){ |
| 180 | if((argc != 2) || (!is_valid(atoi(argv[1])))) |
| 181 | { |
| 182 | free(pRI); |
| 183 | RLOGD("the paremeters numbers isn't right , so return"); |
| 184 | android::emResultNotify("Set failed.\n"); |
| 185 | return -1; |
| 186 | } |
| 187 | |
| 188 | if(Radio_capability_switch_util::is_sim_inserted(atoi(argv[1]))) { |
| 189 | set_default_sim_all(atoi(argv[1])); |
| 190 | android::emResultNotify("Set successful.\n"); |
| 191 | free(pRI); |
| 192 | } else { |
| 193 | RLOGD("Set default all fail, SIM card absent"); |
| 194 | android::emResultNotify("Set default all fail, SIM card absent.\n"); |
| 195 | free(pRI); |
| 196 | } |
| 197 | |
| 198 | return 0; |
| 199 | } |
| 200 | |
| 201 | //GET_DEFAULT_SIM_ALL |
| 202 | int get_default_sim_all(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI){ |
| 203 | int slot_id = get_default_sim_all(); |
| 204 | std::string str(""); |
| 205 | str = "default SIM(except data): " + std::to_string(get_default_sim_all_except_data()) + "\n"; |
| 206 | str = str + "default data: " + std::to_string(get_default_sim_data()) + "\n"; |
| 207 | str = str + "main capability SIM: " + std::to_string(Radio_capability_switch_util::get_main_capability_phone_id()) + "\n"; |
| 208 | android::emResultNotify(str.c_str()); |
| 209 | free(pRI); |
| 210 | return 0; |
| 211 | } |
| 212 | |
| 213 | //SET_DEFAULT_SIM_VOICE |
| 214 | int set_default_sim_voice(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI){ |
| 215 | if((argc != 2) || (!is_valid(atoi(argv[1])))) |
| 216 | { |
| 217 | free(pRI); |
| 218 | RLOGD("the paremeters numbers isn't right , so return"); |
| 219 | android::emResultNotify("Set failed.\n"); |
| 220 | return -1; |
| 221 | } |
| 222 | set_default_sim_voice(atoi(argv[1])); |
| 223 | android::emResultNotify("Set successful.\n"); |
| 224 | free(pRI); |
| 225 | return 0; |
| 226 | } |
| 227 | |
| 228 | //GET_DEFAULT_SIM_VOICE |
| 229 | int get_default_sim_voice(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI){ |
| 230 | int slot_id = get_default_sim_voice(); |
| 231 | std::string str(""); |
| 232 | if(slot_id == UNSET) { |
| 233 | str = "SIM NOT insert\n"; |
| 234 | } else { |
| 235 | str = "default SIM for voice: " + std::to_string(slot_id) + "\n"; |
| 236 | } |
| 237 | android::emResultNotify(str.c_str()); |
| 238 | free(pRI); |
| 239 | return 0; |
| 240 | } |
| 241 | |
| 242 | //SET_DEFAULT_SIM_DATA |
| 243 | int set_default_sim_data(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI){ |
| 244 | if((argc != 2) || (!is_valid(atoi(argv[1])))) |
| 245 | { |
| 246 | free(pRI); |
| 247 | RLOGD("the paremeters numbers isn't right , so return"); |
| 248 | android::emResultNotify("Set failed.\n"); |
| 249 | return -1; |
| 250 | } |
| 251 | if(Radio_capability_switch_util::is_sim_inserted(atoi(argv[1]))) { |
| 252 | set_default_sim_data(atoi(argv[1])); |
| 253 | android::emResultNotify("Set successful.\n"); |
| 254 | free(pRI); |
| 255 | } else { |
| 256 | RLOGD("Set default data fail, SIM card absent"); |
| 257 | android::emResultNotify("Set default data fail, SIM card absent.\n"); |
| 258 | free(pRI); |
| 259 | } |
| 260 | return 0; |
| 261 | } |
| 262 | |
| 263 | //GET_DEFAULT_SIM_DATA |
| 264 | int get_default_sim_data(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI){ |
| 265 | int slot_id = get_default_sim_data(); |
| 266 | std::string str(""); |
| 267 | if(slot_id == UNSET) { |
| 268 | str = "SIM NOT insert\n"; |
| 269 | } else { |
| 270 | str = "default SIM for data: " + std::to_string(slot_id) + "\n"; |
| 271 | } |
| 272 | android::emResultNotify(str.c_str()); |
| 273 | free(pRI); |
| 274 | return 0; |
| 275 | } |
| 276 | |
| 277 | //GET_MAIN_SIM_CARD |
| 278 | int get_main_sim_card(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI){ |
| 279 | int slot_id = Radio_capability_switch_util::get_main_capability_phone_id(); |
| 280 | std::string str(""); |
| 281 | str = "main capability SIM: " + std::to_string(slot_id) + "\n"; |
| 282 | android::emResultNotify(str.c_str()); |
| 283 | free(pRI); |
| 284 | return 0; |
| 285 | } |
| 286 | |
| 287 | //SET_DEFAULT_SIM_SMS |
| 288 | int set_default_sim_sms(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI){ |
| 289 | if((argc != 2) || (!is_valid(atoi(argv[1])))) |
| 290 | { |
| 291 | free(pRI); |
| 292 | RLOGD("the paremeters numbers isn't right , so return"); |
| 293 | android::emResultNotify("Set failed.\n"); |
| 294 | return -1; |
| 295 | } |
| 296 | set_default_sim_sms(atoi(argv[1])); |
| 297 | android::emResultNotify("Set successful.\n"); |
| 298 | free(pRI); |
| 299 | return 0; |
| 300 | } |
| 301 | |
| 302 | //GET_DEFAULT_SIM_SMS |
| 303 | int get_default_sim_sms(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI){ |
| 304 | int slot_id = get_default_sim_sms(); |
| 305 | std::string str(""); |
| 306 | if(slot_id == UNSET) { |
| 307 | str = "SIM NOT insert\n"; |
| 308 | } else { |
| 309 | str = "default SIM for sms: " + std::to_string(slot_id) + "\n"; |
| 310 | } |
| 311 | android::emResultNotify(str.c_str()); |
| 312 | free(pRI); |
| 313 | return 0; |
| 314 | } |
| 315 | |
| 316 | //SET_DEFAULT_SIM_ALL_EXCEPT_DATA |
| 317 | int set_default_sim_all_except_data(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI){ |
| 318 | if((argc != 2) || (!is_valid(atoi(argv[1])))) |
| 319 | { |
| 320 | free(pRI); |
| 321 | RLOGD("the paremeters numbers isn't right , so return"); |
| 322 | android::emResultNotify("Set failed.\n"); |
| 323 | return -1; |
| 324 | } |
| 325 | |
| 326 | set_default_sim_all_except_data(atoi(argv[1])); |
| 327 | android::emResultNotify("Set successful.\n"); |
| 328 | free(pRI); |
| 329 | return 0; |
| 330 | } |
| 331 | |
| 332 | //GET_DEFAULT_SIM_ALL_EXCEPT_DATA |
| 333 | int get_default_sim_all_except_data(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI){ |
| 334 | int slot_id = get_default_sim_all_except_data(); |
| 335 | std::string str(""); |
| 336 | if(slot_id == UNSET) { |
| 337 | str = "SIM NOT insert\n"; |
| 338 | } else { |
| 339 | str = "default SIM(except data): " + std::to_string(slot_id) + "\n"; |
| 340 | } |
| 341 | android::emResultNotify(str.c_str()); |
| 342 | free(pRI); |
| 343 | return 0; |
| 344 | } |
| 345 | |
| 346 | //RIL_REQUEST_SIM_IO |
| 347 | int iccIOForApp(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI) { |
| 348 | if(argc != 10) |
| 349 | { |
| 350 | free(pRI); |
| 351 | RLOGD("the peremeters numbers isn't right , so return"); |
| 352 | return -1; |
| 353 | } |
| 354 | android::Parcel p; |
| 355 | size_t pos = p.dataPosition(); |
| 356 | p.writeInt32(atoi(argv[1])); |
| 357 | p.writeInt32(atoi(argv[2])); |
| 358 | writeStringToParcel(p, argv[3]); |
| 359 | p.writeInt32(atoi(argv[4])); |
| 360 | p.writeInt32(atoi(argv[5])); |
| 361 | p.writeInt32(atoi(argv[6])); |
| 362 | writeStringToParcel(p, checkParameters(argv[7])); |
| 363 | writeStringToParcel(p, checkParameters(argv[8])); |
| 364 | writeStringToParcel(p, checkParameters(argv[9])); |
| 365 | p.setDataPosition(pos); |
| 366 | pRI->pCI->dispatchFunction(p, pRI); |
| 367 | |
| 368 | return 0; |
| 369 | } |
| 370 | |
| 371 | //RIL_REQUEST_SIM_TRANSMIT_APDU_BASIC |
| 372 | int iccTransmitApduBasicChannel(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI) { |
| 373 | if(argc > 8) |
| 374 | { |
| 375 | free(pRI); |
| 376 | RLOGD("the peremeters numbers isn't right , so return"); |
| 377 | return -1; |
| 378 | } |
| 379 | android::Parcel p; |
| 380 | size_t pos = p.dataPosition(); |
| 381 | p.writeInt32(atoi(argv[1])); |
| 382 | p.writeInt32(atoi(argv[2])); |
| 383 | p.writeInt32(atoi(argv[3])); |
| 384 | p.writeInt32(atoi(argv[4])); |
| 385 | p.writeInt32(atoi(argv[5])); |
| 386 | p.writeInt32(atoi(argv[6])); |
| 387 | writeStringToParcel(p, ((argc == 7) ? "" : argv[7])); |
| 388 | p.setDataPosition(pos); |
| 389 | pRI->pCI->dispatchFunction(p, pRI); |
| 390 | |
| 391 | return 0; |
| 392 | } |
| 393 | |
| 394 | //RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL |
| 395 | int iccTransmitApduLogicalChannel(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI) { |
| 396 | if(argc > 8) |
| 397 | { |
| 398 | free(pRI); |
| 399 | RLOGD("the peremeters numbers isn't right , so return"); |
| 400 | return -1; |
| 401 | } |
| 402 | android::Parcel p; |
| 403 | size_t pos = p.dataPosition(); |
| 404 | p.writeInt32(atoi(argv[1])); |
| 405 | p.writeInt32(atoi(argv[2])); |
| 406 | p.writeInt32(atoi(argv[3])); |
| 407 | p.writeInt32(atoi(argv[4])); |
| 408 | p.writeInt32(atoi(argv[5])); |
| 409 | p.writeInt32(atoi(argv[6])); |
| 410 | writeStringToParcel(p, ((argc == 7) ? "" : argv[7])); |
| 411 | p.setDataPosition(pos); |
| 412 | pRI->pCI->dispatchFunction(p, pRI); |
| 413 | |
| 414 | return 0; |
| 415 | } |
| 416 | |
| 417 | //RIL_REQUEST_SIM_OPEN_CHANNEL |
| 418 | int iccOpenLogicalChannel(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI){ |
| 419 | if(argc != 2) |
| 420 | { |
| 421 | free(pRI); |
| 422 | RLOGD("the peremeters numbers isn't right , so return"); |
| 423 | return -1; |
| 424 | } |
| 425 | android::Parcel p; |
| 426 | size_t pos = p.dataPosition(); |
| 427 | writeStringToParcel(p, (const char *)argv[1]); |
| 428 | p.setDataPosition(pos); |
| 429 | pRI->pCI->dispatchFunction(p, pRI); |
| 430 | return 0; |
| 431 | } |
| 432 | |
| 433 | //RIL_REQUEST_SIM_CLOSE_CHANNEL |
| 434 | int iccCloseLogicalChannel(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI){ |
| 435 | if(argc != 2) |
| 436 | { |
| 437 | free(pRI); |
| 438 | RLOGD("the peremeters numbers isn't right , so return"); |
| 439 | return -1; |
| 440 | } |
| 441 | |
| 442 | android::Parcel p; |
| 443 | size_t pos = p.dataPosition(); |
| 444 | p.writeInt32(1); |
| 445 | p.writeInt32(atoi(argv[1])); |
| 446 | p.setDataPosition(pos); |
| 447 | pRI->pCI->dispatchFunction(p, pRI); |
| 448 | return 0; |
| 449 | } |
| 450 | |
| 451 | //RIL_REQUEST_QUERY_SIM_RETRY_COUNT |
| 452 | int querySimRetryCount(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI) { |
| 453 | if(argc != 1) |
| 454 | { |
| 455 | free(pRI); |
| 456 | RLOGD("the paremeters numbers isn't right , so return"); |
| 457 | return -1; |
| 458 | } |
| 459 | RLOGD("getIccCardStatus %d: " , pRI->pCI->requestNumber); |
| 460 | android::Parcel p; |
| 461 | |
| 462 | pRI->pCI->dispatchFunction(p, pRI); |
| 463 | return 0; |
| 464 | } |
| 465 | |
| 466 | //RIL_REQUEST_QUERY_EID |
| 467 | int queryEid(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI) { |
| 468 | if(argc != 1) |
| 469 | { |
| 470 | free(pRI); |
| 471 | RLOGD("the paremeters numbers isn't right , so return"); |
| 472 | return -1; |
| 473 | } |
| 474 | android::Parcel p; |
| 475 | pRI->pCI->dispatchFunction(p, pRI); |
| 476 | return 0; |
| 477 | } |