2 * tel-plugin-samsung-atmodem
4 * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Hayoon Ko <hayoon.ko@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
30 #include <core_object.h>
36 #include <user_request.h>
41 #include "atchannel.h"
44 extern struct ATResponse *sp_response;
45 extern char *s_responsePrefix;
46 extern enum ATCommandType s_type;
48 #define SWAPBYTES16(x) \
50 unsigned short int data = *(unsigned short int*)&(x); \
51 data = ((data & 0xff00) >> 8) | \
52 ((data & 0x00ff) << 8); \
53 *(unsigned short int*)&(x) = data ; \
56 enum s_sim_file_type_e {
57 SIM_FTYPE_DEDICATED = 0x00, /**< Dedicated */
58 SIM_FTYPE_TRANSPARENT = 0x01, /**< Transparent -binary type*/
59 SIM_FTYPE_LINEAR_FIXED = 0x02, /**< Linear fixed - record type*/
60 SIM_FTYPE_CYCLIC = 0x04, /**< Cyclic - record type*/
61 SIM_FTYPE_INVALID_TYPE = 0xFF /**< Invalid type */
76 SEC_PIN2_DISABLE, //10
99 struct s_sim_property {
100 gboolean b_valid; /**< Valid or not */
101 enum tel_sim_file_id file_id; /**< File identifier */
102 enum s_sim_file_type_e file_type; /**< File type and structure */
103 int rec_length; /**< Length of one record in file */
104 int rec_count; /**< Number of records in file */
105 int data_size; /**< File size */
106 int current_index; /**< current index to read */
107 enum tel_sim_status first_recv_status;
108 enum s_sim_sec_op_e current_sec_op; /**< current index to read */
109 struct tresp_sim_read files;
110 struct ATReqMetaInfo metainfo;
113 enum s_sim_sec_locktype_e{
114 SEC_LOCK_TYPE_NONE =0,
115 SEC_LOCK_TYPE_READY, /* ME is not locked */
116 SEC_LOCK_TYPE_PS, /* PH-SIM, Lock Phone to SIM/UICC card(MT asks password when other than current SIM/UICC card inserted; MT may remember certain amount of
117 previously used cards thus not requiring password when they are inserted ) */
118 SEC_LOCK_TYPE_PF, /* PH-FSIM, Lock Phone to the very First inserted SIM/UICC card ( MT asks password when other than the first SIM/UICC card is inserted ) */
119 SEC_LOCK_TYPE_SC, /*Lock SIM/UICC card ( SIM asks password in ME power-up and when this command is issued ) */
120 SEC_LOCK_TYPE_FD, /* SIM card or active application in the UICC(GSM or USIM) fixed dialing memory feature */
121 SEC_LOCK_TYPE_PN, /* Network Personalization */
122 SEC_LOCK_TYPE_PU, /* Network subset Personalization */
123 SEC_LOCK_TYPE_PP, /* Service Provider Personalization */
124 SEC_LOCK_TYPE_PC, /* Corporate Personalization */
125 SEC_LOCK_TYPE_SC2, /* Lock PIN2 ( ... ) */
126 SEC_LOCL_TYPE_PUK2, /* Lock PUK2 (... ) */
127 SEC_LOCK_TYPE_ACL, /* ACL */
129 SEC_LOCK_TYPE_NO_SIM, /* SIM is not inserted */
130 SEC_LOCK_TYPE_UNAVAIL, /* SIM is inserted but can not communicate with SIM ( SIM interface error ) */
131 SEC_SIM_INIT_COMPLETED, /* SIM Initialize Completed */
132 SEC_PB_INIT_COMPLETED, /* Phonebook Initialize Completed*/
133 SEC_SIM_INIT_CRASH, /* SIM Crash request from SMC lab*/
138 enum s_sim_sec_lockkey_e{
140 SEC_LOCK_KEY_UNLOCKED, /* Not necessary */
141 SEC_LOCK_KEY_PIN, /* PIN required as a password */
142 SEC_LOCK_KEY_PUK, /* 0PUK required as a password */
143 SEC_LOCK_KEY_PIN2, /* PIN2 required as a password */
144 SEC_LOCK_KEY_PUK2, /* PUK2 required as a password */
145 SEC_LOCK_KEY_PERM_BLOCKED, /* PIN Permanent Blocked */
146 SEC_LOCK_KEY_PIN2_DISABLE, /* PIN2 Lock Disabled*/
152 static void _next_from_get_file_info(CoreObject *o, UserRequest *ur, enum tel_sim_file_id ef, enum tel_sim_access_result rt);
153 static void _next_from_get_file_data(CoreObject *o, UserRequest *ur, enum tel_sim_access_result rt, int decode_ret);
154 static gboolean _get_sim_type(CoreObject *o);
155 static TReturn _get_file_info(CoreObject *o, UserRequest *ur, const enum tel_sim_file_id ef);
156 static gboolean _get_file_data(CoreObject *o, UserRequest *ur, const enum tel_sim_file_id ef, const int offset, const int length);
157 static gboolean _get_file_record(CoreObject *o, UserRequest *ur, const enum tel_sim_file_id ef, const int index, const int length);
158 static void _sim_status_update(CoreObject *o, enum tel_sim_status sim_status);
160 static gboolean _convert_SCPIN_noti(char* line, enum s_sim_sec_locktype_e* lock_type, enum s_sim_sec_lockkey_e* lock_key);
162 static gboolean _convert_SCPIN_noti(char* line, enum s_sim_sec_locktype_e* lock_type, enum s_sim_sec_lockkey_e* lock_key)
164 char *type =NULL, *key = NULL;
169 dbg("incoming string : %s\n", line);
174 // 1. find type string
175 err = at_tok_nextstr(&line, &type);
177 // no type string found.
181 // 2. find key string
182 err = at_tok_nextstr(&line, &key);
189 dbg("type : %s, key : %s\n", type, key);
191 // 3. convert string into enum
194 if(strStartsWith (type, "NO_SIM"))
195 *lock_type = SEC_LOCK_TYPE_NO_SIM;
196 else if(strStartsWith (type, "UNAVAIL"))
197 *lock_type = SEC_LOCK_TYPE_UNAVAIL;
198 else if(strStartsWith (type, "NO_LOCK"))
199 *lock_type = SEC_LOCK_TYPE_READY;
200 else if(strStartsWith (type, "LOCK_PS"))
201 *lock_type = SEC_LOCK_TYPE_PS;
202 else if(strStartsWith (type, "LOCK_PF"))
203 *lock_type = SEC_LOCK_TYPE_PF ;
204 else if(strStartsWith (type, "LOCK_SC"))
205 *lock_type = SEC_LOCK_TYPE_SC;
206 else if(strStartsWith (type, "LOCK_FD"))
207 *lock_type = SEC_LOCK_TYPE_FD;
208 else if(strStartsWith (type, "LOCK_PN"))
209 *lock_type = SEC_LOCK_TYPE_PN ;
210 else if(strStartsWith (type, "LOCK_PU"))
211 *lock_type = SEC_LOCK_TYPE_PU ;
212 else if(strStartsWith (type, "LOCK_PP"))
213 *lock_type = SEC_LOCK_TYPE_PP;
214 else if(strStartsWith (type, "LOCK_PC"))
215 *lock_type = SEC_LOCK_TYPE_PC;
216 else if(strStartsWith (type, "LOCK_SC2"))
217 *lock_type = SEC_LOCK_TYPE_SC2 ;
218 else if(strStartsWith (type, "LOCK_ACL"))
219 *lock_type = SEC_LOCK_TYPE_ACL;
220 else if(strStartsWith (type, "LOCK_PUK2"))
221 *lock_type = SEC_LOCL_TYPE_PUK2;
222 else if(strStartsWith (type, "INIT_COMP"))
223 *lock_type = SEC_SIM_INIT_COMPLETED;
224 else if(strStartsWith (type, "INIT_ERROR"))
225 *lock_type = SEC_SIM_INIT_CRASH;
227 *lock_type = SEC_LOCK_TYPE_NONE;
230 type = SEC_LOCK_TYPE_NONE;
234 if(strStartsWith (type, "PIN"))
235 *lock_key = SEC_LOCK_KEY_PIN;
236 else if(strStartsWith (type, "PUK"))
237 *lock_key = SEC_LOCK_KEY_PUK;
238 else if(strStartsWith (type, "PIN2"))
239 *lock_key = SEC_LOCK_KEY_PIN2;
240 else if(strStartsWith (type, "PUK2"))
241 *lock_key = SEC_LOCK_KEY_PUK2;
242 else if(strStartsWith (type, "BLOCKED"))
243 *lock_key = SEC_LOCK_KEY_PERM_BLOCKED ;
244 else if(strStartsWith (type, "UNLOCKED"))
245 *lock_key = SEC_LOCK_KEY_UNLOCKED ;
246 else if(strStartsWith (type, "PIN2_DISABLE"))
247 *lock_key = SEC_LOCK_KEY_PIN2_DISABLE;
249 *lock_key = SEC_LOCK_KEY_NONE;
252 *lock_key = SEC_LOCK_KEY_NONE;
255 // 4. apply exceptional case.
256 //if type is READY, key has no meanig
257 if(*lock_type == SEC_LOCK_TYPE_READY)
258 *lock_key = SEC_LOCK_KEY_UNLOCKED;
260 // no sim, unvail, init_comp, init_error have no key info
261 if((*lock_type == SEC_LOCK_TYPE_NO_SIM)||(*lock_type == SEC_LOCK_TYPE_UNAVAIL)||
262 (*lock_type == SEC_SIM_INIT_COMPLETED)||(*lock_type == SEC_SIM_INIT_CRASH))
263 *lock_key = SEC_LOCK_KEY_NONE;
265 dbg("type : %d, key : %d\n", *lock_type, *lock_key);
270 static enum tcore_response_command _find_resp_command(UserRequest *ur)
272 enum tcore_request_command command;
273 command = tcore_user_request_get_command(ur);
275 case TREQ_SIM_VERIFY_PINS:
276 return TRESP_SIM_VERIFY_PINS;
278 case TREQ_SIM_VERIFY_PUKS:
279 return TRESP_SIM_VERIFY_PUKS;
281 case TREQ_SIM_CHANGE_PINS:
282 return TRESP_SIM_CHANGE_PINS;
284 case TREQ_SIM_GET_FACILITY_STATUS:
285 return TRESP_SIM_GET_FACILITY_STATUS;
287 case TREQ_SIM_DISABLE_FACILITY:
288 return TRESP_SIM_DISABLE_FACILITY;
290 case TREQ_SIM_ENABLE_FACILITY:
291 return TRESP_SIM_ENABLE_FACILITY;
293 case TREQ_SIM_TRANSMIT_APDU:
294 return TRESP_SIM_TRANSMIT_APDU;
296 case TREQ_SIM_GET_ATR:
297 return TRESP_SIM_GET_ATR;
299 case TREQ_SIM_GET_ECC:
300 return TRESP_SIM_GET_ECC;
302 case TREQ_SIM_GET_LANGUAGE:
303 return TRESP_SIM_GET_LANGUAGE;
305 case TREQ_SIM_SET_LANGUAGE:
306 return TRESP_SIM_SET_LANGUAGE;
308 case TREQ_SIM_GET_ICCID:
309 return TRESP_SIM_GET_ICCID;
311 case TREQ_SIM_GET_MAILBOX:
312 return TRESP_SIM_GET_MAILBOX;
314 case TREQ_SIM_GET_CALLFORWARDING:
315 return TRESP_SIM_GET_CALLFORWARDING;
317 case TREQ_SIM_GET_MESSAGEWAITING:
318 return TRESP_SIM_GET_MESSAGEWAITING;
320 case TREQ_SIM_GET_CPHS_INFO:
321 return TRESP_SIM_GET_CPHS_INFO;
323 case TREQ_SIM_GET_MSISDN:
324 return TRESP_SIM_GET_MSISDN;
326 case TREQ_SIM_GET_SPN:
327 return TRESP_SIM_GET_SPN;
329 case TREQ_SIM_GET_SPDI:
330 return TRESP_SIM_GET_SPDI;
332 case TREQ_SIM_GET_OPL:
333 return TRESP_SIM_GET_OPL;
335 case TREQ_SIM_GET_PNN:
336 return TRESP_SIM_GET_PNN;
338 case TREQ_SIM_GET_CPHS_NETNAME:
339 return TRESP_SIM_GET_CPHS_NETNAME;
341 case TREQ_SIM_GET_OPLMNWACT:
342 return TRESP_SIM_GET_OPLMNWACT;
344 case TREQ_SIM_REQ_AUTHENTICATION:
345 return TRESP_SIM_REQ_AUTHENTICATION;
350 return TRESP_UNKNOWN;
353 static int _sim_get_current_pin_facility(struct s_sim_property *sp)
356 dbg("current sp->current_sec_op[%d]", sp->current_sec_op);
357 switch(sp->current_sec_op){
358 case SEC_PIN1_VERIFY :
359 case SEC_PIN1_CHANGE :
360 ret_type = SIM_PTYPE_PIN1;
362 case SEC_PIN2_VERIFY :
363 case SEC_PIN2_CHANGE :
364 ret_type = SIM_PTYPE_PIN2;
366 case SEC_PUK1_VERIFY :
367 ret_type = SIM_PTYPE_PUK1;
369 case SEC_PUK2_VERIFY :
370 ret_type = SIM_PTYPE_PUK2;
372 case SEC_SIM_VERIFY :
373 ret_type = SIM_PTYPE_SIM;
375 case SEC_ADM_VERIFY :
376 ret_type = SIM_PTYPE_ADM;
379 case SEC_PIN1_ENABLE :
380 case SEC_PIN1_DISABLE :
381 case SEC_PIN1_STATUS :
382 ret_type = SIM_FACILITY_SC;
384 case SEC_SIM_ENABLE :
385 case SEC_SIM_DISABLE :
386 case SEC_SIM_STATUS :
387 ret_type = SIM_FACILITY_PS;
389 case SEC_NET_ENABLE :
390 case SEC_NET_DISABLE :
391 case SEC_NET_STATUS :
392 ret_type = SIM_FACILITY_PN;
395 case SEC_NS_DISABLE :
397 ret_type = SIM_FACILITY_PU;
400 case SEC_SP_DISABLE :
402 ret_type = SIM_FACILITY_PP;
405 case SEC_CP_DISABLE :
407 ret_type = SIM_FACILITY_PC;
409 case SEC_FDN_ENABLE :
410 case SEC_FDN_DISABLE :
411 case SEC_FDN_STATUS :
412 ret_type = SIM_FACILITY_FD;
416 dbg("not handled current op[%d]",sp->current_sec_op )
422 static enum tel_sim_access_result _decode_status_word(unsigned short status_word1, unsigned short status_word2)
424 enum tel_sim_access_result rst = SIM_ACCESS_FAILED;
426 if (status_word1 == 0x93 && status_word2 == 0x00) {
427 rst = SIM_ACCESS_FAILED;
428 /*Failed SIM request command*/
429 dbg(" error - SIM application toolkit busy [%x][%x]", status_word1, status_word2);
431 else if (status_word1 == 0x94 && status_word2 == 0x00) {
432 rst = SIM_ACCESS_FAILED;
433 /*Failed SIM request command*/
434 dbg(" error - No EF Selected [%x][%x]", status_word1, status_word2);
436 else if (status_word1 == 0x94 && status_word2 == 0x02) {
437 rst = SIM_ACCESS_FAILED;
438 /*Failed SIM request command*/
439 dbg("error - Out of Range - Invalid address or record number[%x][%x]",
440 status_word1, status_word2);
442 else if (status_word1 == 0x94 && status_word2 == 0x04) {
443 rst = SIM_ACCESS_FILE_NOT_FOUND;
444 /*Failed SIM request command*/
445 dbg(" error - File ID not found [%x][%x]", status_word1, status_word2);
447 else if (status_word1 == 0x94 && status_word2 == 0x08) {
448 rst = SIM_ACCESS_FAILED; /* MOdem not support */
449 /*Failed SIM request command*/
450 dbg(" error - File is inconsistent with command - Modem not support or USE IPC [%x][%x]",
451 status_word1, status_word2);
453 else if (status_word1 == 0x98 && status_word2 == 0x02) {
454 rst = SIM_ACCESS_CONDITION_NOT_SATISFIED;
455 /*Failed SIM request command*/
456 dbg(" error - CHV not initialized [%x][%x]", status_word1, status_word2);
458 else if (status_word1 == 0x98 && status_word2 == 0x04) {
459 rst = SIM_ACCESS_CONDITION_NOT_SATISFIED;
460 /*Failed SIM request command*/
461 dbg(" error - Access condition not fullfilled [%x][%x]", status_word1, status_word2);
462 dbg(" error -Unsuccessful CHV verification - at least one attempt left [%x][%x]",
463 status_word1, status_word2);
464 dbg(" error - Unsuccessful Unblock CHV - at least one attempt left [%x][%x]",
465 status_word1, status_word2);
466 dbg(" error - Authentication failure [%x][%x]", status_word1, status_word2);
468 else if (status_word1 == 0x98 && status_word2 == 0x08) {
469 rst = SIM_ACCESS_CONDITION_NOT_SATISFIED;
470 /*Failed SIM request command*/
471 dbg(" error - Contradiction with CHV status [%x][%x]", status_word1, status_word2);
473 else if (status_word1 == 0x98 && status_word2 == 0x10) {
474 rst = SIM_ACCESS_CONDITION_NOT_SATISFIED;
475 /*Failed SIM request command*/
476 dbg(" error - Contradiction with invalidation status [%x][%x]",
477 status_word1, status_word2);
479 else if (status_word1 == 0x98 && status_word2 == 0x40) {
480 rst = SIM_ACCESS_CONDITION_NOT_SATISFIED;
481 /*Failed SIM request command*/
482 dbg(" error -Unsuccessful CHV verification - no attempt left [%x][%x]",
483 status_word1, status_word2);
484 dbg(" error - Unsuccessful Unblock CHV - no attempt left [%x][%x]",
485 status_word1, status_word2);
486 dbg(" error - CHV blocked [%x][%x]", status_word1, status_word2);
488 else if (status_word1 == 0x67 && status_word2 == 0x00) {
489 rst = SIM_ACCESS_FAILED;
490 dbg(" error -Incorrect Parameter 3 [%x][%x]", status_word1, status_word2);
492 else if (status_word1 == 0x6B && status_word2 == 0x00) {
493 rst = SIM_ACCESS_FAILED;
494 dbg(" error -Incorrect Parameter 1 or 2 [%x][%x]", status_word1, status_word2);
496 else if (status_word1 == 0x6D && status_word2 == 0x00) {
497 rst = SIM_ACCESS_CONDITION_NOT_SATISFIED;
498 dbg(" error -Unknown instruction given as command [%x][%x]", status_word1, status_word2);
500 else if (status_word1 == 0x6E && status_word2 == 0x00) {
501 rst = SIM_ACCESS_CONDITION_NOT_SATISFIED;
502 dbg(" error -Unknown instruction given as command [%x][%x]", status_word1, status_word2);
504 else if (status_word1 == 0x69 && status_word2 == 0x82) {
505 rst = SIM_ACCESS_CONDITION_NOT_SATISFIED;
506 dbg(" error -Access denied [%x][%x]", status_word1, status_word2);
508 else if (status_word1 == 0x6A && status_word2 == 0x87) {
509 rst = SIM_ACCESS_FAILED;
510 dbg(" error -Incorrect parameters [%x][%x]", status_word1, status_word2);
512 else if (status_word1 == 0x6A && status_word2 == 0x82) {
513 rst = SIM_ACCESS_FAILED; // not sure of the SW1 and SW2 meaning here
514 dbg(" error -File Not found [%x][%x]", status_word1, status_word2);
516 else if (status_word1 == 0x6A && status_word2 == 0x83) {
517 rst = SIM_ACCESS_FAILED; // not sure of the SW1 and SW2 meaning here
518 dbg(" error -Record Not found [%x][%x]", status_word1, status_word2);
521 rst = SIM_ACCESS_CARD_ERROR;
522 dbg(" error -Unknown state [%x][%x]", status_word1, status_word2);
527 static gboolean _sim_check_identity(CoreObject *o, struct tel_sim_imsi *imsi)
530 Storage *strg = NULL;
531 char* old_imsi = NULL;
532 char new_imsi[15+1] = {0,};
534 s = tcore_plugin_ref_server(tcore_object_ref_plugin(o));
536 dbg("there is no valid server at this point");
540 strg = (Storage*)tcore_server_find_storage(s, "vconf");
542 dbg("there is no valid storage plugin");
546 memcpy(&new_imsi, imsi->plmn, strlen(imsi->plmn));
547 memcpy(&new_imsi[strlen(imsi->plmn)], imsi->msin, strlen(imsi->msin));
548 new_imsi[strlen(imsi->plmn)+strlen(imsi->msin)] = '\0';
550 old_imsi = tcore_storage_get_string(strg, STORAGE_KEY_TELEPHONY_IMSI);
551 dbg("old_imsi[%s],newImsi[%s]", old_imsi, new_imsi);
553 if (old_imsi != NULL) {
554 if (strncmp(old_imsi, new_imsi, 15) != 0) {
556 if (tcore_storage_set_string(strg, STORAGE_KEY_TELEPHONY_IMSI, (const char*) &new_imsi) == FALSE )
557 dbg("[FAIL] UPDATE STORAGE_KEY_TELEPHONY_IMSI");
558 tcore_sim_set_identification(o, TRUE);
562 tcore_sim_set_identification(o, FALSE);
566 dbg("OLD SIM VALUE IS NULL. NEW SIM");
567 if (tcore_storage_set_string(strg, STORAGE_KEY_TELEPHONY_IMSI, (const char*) &new_imsi) == FALSE)
568 dbg("[FAIL] UPDATE STORAGE_KEY_TELEPHONY_IMSI");
569 tcore_sim_set_identification(o, TRUE);
574 static void _next_from_get_file_info(CoreObject *o, UserRequest *ur, enum tel_sim_file_id ef, enum tel_sim_access_result rt )
576 struct tresp_sim_read resp = {0,};
577 struct s_sim_property *file_meta = NULL;
579 dbg("EF[0x%x] access Result[%d]", ef, rt);
582 memset(&resp.data, 0x00, sizeof(resp.data));
584 if ((ef != SIM_EF_ELP || ef != SIM_EF_LP || ef != SIM_EF_USIM_PL)
585 && (rt != SIM_ACCESS_SUCCESS)) {
586 tcore_user_request_send_response(ur, _find_resp_command(ur), sizeof(struct tresp_sim_read),
591 file_meta = (struct s_sim_property*)tcore_user_request_ref_metainfo(ur, NULL);
595 if (rt == SIM_ACCESS_SUCCESS) {
596 dbg("[SIM DATA] exist EFELP/PL(0x2F05)");
597 /* if (po->language_file == 0x00)
598 po->language_file = SIM_EF_ELP;*/
599 _get_file_data(o, ur, ef, 0, file_meta->data_size);
602 if (tcore_sim_get_type(o) == SIM_TYPE_GSM) {
603 dbg(" [SIM DATA]SIM_EF_ELP(2F05) access fail. Request SIM_EF_LP(0x6F05) info");
604 /* The ME requests the Language Preference (EFLP) if EFELP is not available */
605 _get_file_info(o, ur, SIM_EF_LP);
607 else if (tcore_sim_get_type(o) == SIM_TYPE_USIM) {
609 " [SIM DATA]fail to get Language information in USIM(EF-LI(6F05),EF-PL(2F05)). Request SIM_EF_ECC(0x6FB7) info");
610 /* EFELPand EFLI not present at this point. */
611 /* po->language.lang_cnt = 0;*/
612 tcore_user_request_send_response(ur, _find_resp_command(ur),
613 sizeof(struct tresp_sim_read), &resp);
619 case SIM_EF_LP: //same with SIM_EF_USIM_LI
620 if (rt == SIM_ACCESS_SUCCESS) {
621 dbg("[SIM DATA] exist EFLP/LI(0x6F05)");
622 /* if (po->language_file == 0x00)
623 po->language_file = SIM_EF_LP;*/
624 _get_file_data(o, ur, ef, 0, file_meta->data_size);
627 dbg("[SIM DATA]SIM_EF_LP/LI(6F05) access fail. Current CardType[%d]",
628 tcore_sim_get_type(o));
629 if (tcore_sim_get_type(o) == SIM_TYPE_GSM) {
630 /* EFELPand EFLP not present at this point.*/
631 /* po->language.lang_cnt = 0;*/
632 tcore_user_request_send_response(ur, _find_resp_command(ur),
633 sizeof(struct tresp_sim_read), &resp);
636 /* if EFLI is not present, then the language selection shall be as defined in EFPL at the MF level */
637 else if (tcore_sim_get_type(o) == SIM_TYPE_USIM) {
638 dbg("[SIM DATA] try USIM EFPL(0x2F05)");
639 _get_file_info(o, ur, SIM_EF_ELP);
645 if (rt == SIM_ACCESS_SUCCESS) {
646 dbg("[SIM DATA] exist EFELP/PL(0x2F05)");
647 /* if (po->language_file == 0x00)
648 po->language_file = SIM_EF_ELP;*/
649 _get_file_data(o, ur, SIM_EF_ELP, 0, file_meta->data_size);
652 /* EFELIand EFPL not present, so set language count as zero and select ECC */
654 " [SIM DATA]SIM_EF_USIM_PL(2A05) access fail. Request SIM_EF_ECC(0x6FB7) info");
655 /* po->language.lang_cnt = 0;*/
656 tcore_user_request_send_response(ur, _find_resp_command(ur),
657 sizeof(struct tresp_sim_read), &resp);
663 if (tcore_sim_get_type(o) == SIM_TYPE_GSM) {
664 _get_file_data(o, ur, ef, 0, file_meta->data_size);
666 else if (tcore_sim_get_type(o) == SIM_TYPE_USIM) {
667 if (file_meta->rec_count > SIM_ECC_RECORD_CNT_MAX)
668 file_meta->rec_count = SIM_ECC_RECORD_CNT_MAX;
670 file_meta->current_index++;
671 _get_file_record(o, ur, ef, file_meta->current_index, file_meta->rec_length);
680 case SIM_EF_CPHS_CPHS_INFO:
681 case SIM_EF_CPHS_CALL_FORWARD_FLAGS:
682 case SIM_EF_CPHS_VOICE_MSG_WAITING:
683 case SIM_EF_CPHS_OPERATOR_NAME_STRING:
684 case SIM_EF_CPHS_OPERATOR_NAME_SHORT_FORM_STRING:
685 case SIM_EF_CPHS_DYNAMICFLAGS:
686 case SIM_EF_CPHS_DYNAMIC2FLAG:
687 case SIM_EF_CPHS_CUSTOMER_SERVICE_PROFILE:
688 case SIM_EF_CPHS_CUSTOMER_SERVICE_PROFILE_LINE2:
689 _get_file_data(o, ur, ef, 0, file_meta->data_size);
692 case SIM_EF_USIM_CFIS:
693 if (file_meta->rec_count > SIM_CF_RECORD_CNT_MAX)
694 file_meta->rec_count = SIM_CF_RECORD_CNT_MAX;
695 file_meta->current_index++;
696 _get_file_record(o, ur, ef, file_meta->current_index, file_meta->rec_length);
701 case SIM_EF_USIM_MWIS:
702 case SIM_EF_USIM_MBI:
704 case SIM_EF_CPHS_MAILBOX_NUMBERS:
705 case SIM_EF_CPHS_INFORMATION_NUMBERS:
706 file_meta->current_index++;
707 _get_file_record(o, ur, ef, file_meta->current_index, file_meta->rec_length);
711 dbg( "error - File id for get file info [0x%x]", ef);
717 static void _next_from_get_file_data(CoreObject *o, UserRequest *ur, enum tel_sim_access_result rt, int decode_ret)
719 struct s_sim_property *file_meta = NULL;
720 file_meta = (struct s_sim_property*)tcore_user_request_ref_metainfo(ur, NULL);
722 dbg("[SIM]EF[0x%x] read rt[%d] Decode rt[%d]", file_meta->file_id, rt, decode_ret);
724 switch (file_meta->file_id) {
729 if (decode_ret == TRUE) {
730 if (file_meta->file_id == SIM_EF_LP || file_meta->file_id == SIM_EF_USIM_LI) {
731 /* po->language_file = SIM_EF_LP;*/
732 } else if (file_meta->file_id == SIM_EF_ELP || file_meta->file_id == SIM_EF_USIM_PL) {
733 /* po->language_file = SIM_EF_ELP;*/
735 tcore_user_request_send_response(ur, _find_resp_command(ur), sizeof(struct tresp_sim_read), &file_meta->files);
738 /* The ME requests the Extended Language Preference. The ME only requests the Language Preference (EFLP) if at least one of the following conditions holds:
739 - EFELP is not available;
740 - EFELP does not contain an entry corresponding to a language specified in ISO 639[30];
741 - the ME does not support any of the languages in EFELP.
744 /* The ME only requests the Language Preference (EFPL) if at least one of the following conditions holds:
745 - if the EFLI has the value 'FFFF' in its highest priority position
746 - if the ME does not support any of the language codes indicated in EFLI , or if EFLI is not present
748 if (tcore_sim_get_type(o) == SIM_TYPE_GSM) {
749 if (file_meta->file_id == SIM_EF_LP)
750 tcore_user_request_send_response(ur, _find_resp_command(ur), sizeof(struct tresp_sim_read), &file_meta->files);
752 _get_file_info(o, ur, SIM_EF_LP);
753 } else if (tcore_sim_get_type(o) == SIM_TYPE_USIM) {
754 if (file_meta->file_id == SIM_EF_LP || file_meta->file_id == SIM_EF_USIM_LI)
755 _get_file_info(o, ur, SIM_EF_ELP);
757 tcore_user_request_send_response(ur, _find_resp_command(ur), sizeof(struct tresp_sim_read), &file_meta->files);
763 if (tcore_sim_get_type(o) == SIM_TYPE_USIM) {
764 file_meta->files.data.ecc.ecc_count++;
765 if (file_meta->current_index == file_meta->rec_count) {
766 tcore_user_request_send_response(ur, _find_resp_command(ur), sizeof(struct tresp_sim_read), &file_meta->files);
768 file_meta->current_index++;
769 _get_file_record(o, ur, file_meta->file_id, file_meta->current_index, file_meta->rec_length );
771 } else if (tcore_sim_get_type(o) == SIM_TYPE_GSM) {
772 tcore_user_request_send_response(ur, _find_resp_command(ur), sizeof(struct tresp_sim_read), &file_meta->files);
774 dbg("[SIM DATA]Invalid CardType[%d] Unable to handle", tcore_sim_get_type(o));
779 _sim_status_update(o, SIM_STATUS_INIT_COMPLETED);
783 file_meta->files.data.opl.opl_count++;
784 dbg("file_meta->files.data.opl.opl_count[%d], current index[%d], rec_cnt[%d]",
785 file_meta->files.data.opl.opl_count, file_meta->current_index,file_meta->rec_count);
786 if (file_meta->current_index == file_meta->rec_count) {
787 tcore_user_request_send_response(ur, _find_resp_command(ur), sizeof(struct tresp_sim_read), &file_meta->files);
789 file_meta->current_index++;
790 _get_file_record(o, ur, file_meta->file_id, file_meta->current_index, file_meta->rec_length );
794 file_meta->files.data.pnn.pnn_count++;
795 if (file_meta->current_index == file_meta->rec_count) {
796 tcore_user_request_send_response(ur, _find_resp_command(ur), sizeof(struct tresp_sim_read), &file_meta->files);
798 file_meta->current_index++;
799 _get_file_record(o, ur, file_meta->file_id, file_meta->current_index, file_meta->rec_length );
802 case SIM_EF_USIM_CFIS:
803 case SIM_EF_USIM_MWIS:
804 case SIM_EF_USIM_MBI:
806 case SIM_EF_CPHS_MAILBOX_NUMBERS:
807 case SIM_EF_CPHS_INFORMATION_NUMBERS:
808 if (file_meta->current_index == file_meta->rec_count) {
809 tcore_user_request_send_response(ur, _find_resp_command(ur), sizeof(struct tresp_sim_read), &file_meta->files);
811 file_meta->current_index++;
812 _get_file_record(o, ur, file_meta->file_id, file_meta->current_index, file_meta->rec_length );
820 case SIM_EF_CPHS_CPHS_INFO:
821 case SIM_EF_CPHS_CALL_FORWARD_FLAGS:
822 case SIM_EF_CPHS_VOICE_MSG_WAITING:
823 case SIM_EF_CPHS_OPERATOR_NAME_STRING:
824 case SIM_EF_CPHS_OPERATOR_NAME_SHORT_FORM_STRING:
825 case SIM_EF_CPHS_DYNAMICFLAGS:
826 case SIM_EF_CPHS_DYNAMIC2FLAG:
827 case SIM_EF_CPHS_CUSTOMER_SERVICE_PROFILE:
828 case SIM_EF_CPHS_CUSTOMER_SERVICE_PROFILE_LINE2:
829 tcore_user_request_send_response(ur, _find_resp_command(ur), sizeof(struct tresp_sim_read), &file_meta->files);
833 dbg("File id not handled [0x%x]", file_meta->file_id);
838 static void _sim_status_update(CoreObject *o, enum tel_sim_status sim_status)
840 struct tnoti_sim_status noti_data = {0,};
842 dbg("tcore_sim_set_status and send noti w/ [%d]", sim_status);
843 tcore_sim_set_status(o, sim_status);
844 noti_data.sim_status = sim_status;
845 tcore_server_send_notification(tcore_plugin_ref_server(tcore_object_ref_plugin(o)), o, TNOTI_SIM_STATUS,
846 sizeof(struct tnoti_sim_status), ¬i_data);
849 static void on_confirmation_sim_message_send( TcorePending *p, gboolean result, void *user_data )
851 UserRequest* ur = NULL;
852 struct ATReqMetaInfo* metainfo = NULL;
853 unsigned int info_len =0;
854 struct s_sim_property *file_meta = NULL;
855 dbg("on_confirmation_sim_message_send - msg out from queue. alloc ATRsp buffer & write rspPrefix if needed\n");
857 //alloc new sp_response
858 ReleaseResponse(); //release leftover
859 //alloc new sp_response
861 sp_response = at_response_new();
863 ur = tcore_pending_ref_user_request(p);
865 dbg("********************************tcore_user_request_get_command[0x%x]", tcore_user_request_get_command(ur));
867 if(tcore_user_request_get_command(ur) == TREQ_CUSTOM)
869 file_meta = (struct s_sim_property *)tcore_user_request_ref_metainfo(ur,&info_len);
870 metainfo = &(file_meta->metainfo);
872 dbg("file_meta->type[%d]", file_meta->metainfo.type);
873 dbg("metainfo->type[%d]", metainfo->type);
877 metainfo = (struct ATReqMetaInfo*)tcore_user_request_ref_metainfo(ur,&info_len);
880 if((metainfo->type == SINGLELINE)||
881 (metainfo->type == MULTILINE))
884 s_responsePrefix = strdup(metainfo->responsePrefix);
885 dbg("duplicating responsePrefix : %s\n", s_responsePrefix);
889 s_responsePrefix = NULL;
892 //set atcmd type into s_type
893 s_type = metainfo->type;
895 if (result == FALSE) {
904 static void _response_get_sim_type(TcorePending *p, int data_len, const void *data, void *user_data)
906 struct s_sim_property *sp = NULL;
907 CoreObject *co_sim = NULL;
908 enum tel_sim_type sim_type = SIM_TYPE_UNKNOWN;
912 if(sp_response->success > 0)
914 line = sp_response->p_intermediates->line;
916 ret = at_tok_start(&line);
920 ret = at_tok_nextint(&line,(int *)&sim_type);
926 sim_type = SIM_TYPE_UNKNOWN;
929 dbg("resp sim type[%d]", sim_type);
933 co_sim = tcore_pending_ref_core_object(p);
934 tcore_sim_set_type(co_sim, sim_type);
935 sp = tcore_sim_ref_userdata(co_sim);
936 _sim_status_update(co_sim, sp->first_recv_status);
939 static void _response_get_file_info(TcorePending *p, int data_len, const void *data, void *user_data)
941 CoreObject *co_sim = NULL;
942 UserRequest *ur = NULL;
943 struct s_sim_property *file_meta = NULL;
944 enum tel_sim_access_result rt;
953 co_sim = tcore_pending_ref_core_object(p);
955 dbg("error - core object is null");
958 ur = tcore_pending_ref_user_request(p);
959 file_meta = (struct s_sim_property*)tcore_user_request_ref_metainfo(ur, NULL);
961 if(sp_response->success > 0)
963 line = sp_response->p_intermediates->line;
964 ret = at_tok_start(&line);
968 ret = at_tok_nextint(&line,&sw1);
971 ret = at_tok_nextint(&line,&sw2);
975 /*1. SIM access success case*/
976 if ((sw1 == 0x90 && sw2 == 0x00) || sw1 == 0x91) {
977 unsigned char tag_len = 0; /* 1 or 2 bytes ??? */
978 unsigned short record_len = 0;
979 char num_of_records = 0;
980 unsigned char file_id_len = 0;
981 unsigned short file_id = 0;
982 unsigned short file_size = 0;
983 unsigned short file_type = 0;
984 unsigned short arr_file_id = 0;
985 int arr_file_id_rec_num = 0;
987 /* handling only last 3 bits */
988 unsigned char file_type_tag = 0x07;
989 unsigned char *ptr_data;
993 ret = at_tok_nextstr(&line,&hexData);
997 recordData = util_hexStringToBytes(hexData);
998 util_hex_dump(" ", strlen(hexData)/2, recordData);
1000 ptr_data = (unsigned char *)recordData;
1001 if (tcore_sim_get_type(co_sim) == SIM_TYPE_USIM) {
1003 ETSI TS 102 221 v7.9.0
1005 '62' FCP template tag
1006 - Response for an EF
1007 '82' M File Descriptor
1008 '83' M File Identifier
1009 'A5' O Proprietary information
1010 '8A' M Life Cycle Status Integer
1011 '8B', '8C' or 'AB' C1 Security attributes
1013 '81' O Total file size
1014 '88' O Short File Identifier (SFI)
1017 /* rsim.res_len has complete data length received */
1019 /* FCP template tag - File Control Parameters tag*/
1020 if (*ptr_data == 0x62) {
1021 /* parse complete FCP tag*/
1022 /* increment to next byte */
1024 tag_len = *ptr_data++;
1025 /* FCP file descriptor - file type, accessibility, DF, ADF etc*/
1026 if (*ptr_data == 0x82) {
1027 /* increment to next byte */
1031 /* unsigned char file_desc_len = *ptr_data++;*/
1032 /* dbg("file descriptor length: [%d]", file_desc_len);*/
1033 /* TBD: currently capture only file type : ignore sharable, non sharable, working, internal etc*/
1034 /* consider only last 3 bits*/
1035 file_type_tag = file_type_tag & (*ptr_data);
1037 switch (file_type_tag) {
1038 /* increment to next byte */
1041 dbg("Getting FileType: [Transparent file type]");
1042 /* increment to next byte */
1044 file_type = SIM_FTYPE_TRANSPARENT;
1045 /* data coding byte - value 21 */
1050 dbg("Getting FileType: [Linear fixed file type]");
1051 /* increment to next byte */
1053 /* data coding byte - value 21 */
1056 memcpy(&record_len, ptr_data, 2);
1058 SWAPBYTES16(record_len);
1059 ptr_data = ptr_data + 2;
1060 num_of_records = *ptr_data++;
1061 /* Data lossy conversation from enum (int) to unsigned char */
1062 file_type = SIM_FTYPE_LINEAR_FIXED;
1066 dbg(" Cyclic fixed file type");
1067 /* increment to next byte */
1069 /* data coding byte - value 21 */
1072 memcpy(&record_len, ptr_data, 2);
1074 SWAPBYTES16(record_len);
1075 ptr_data = ptr_data + 2;
1076 num_of_records = *ptr_data++;
1077 file_type = SIM_FTYPE_CYCLIC;
1081 dbg("not handled file type [0x%x]", *ptr_data);
1085 dbg("INVALID FCP received - DEbug!");
1089 /*File identifier - file id?? */ // 0x84,0x85,0x86 etc are currently ignored and not handled
1090 if (*ptr_data == 0x83) {
1091 /* increment to next byte */
1093 file_id_len = *ptr_data++;
1094 memcpy(&file_id, ptr_data, file_id_len);
1096 SWAPBYTES16(file_id);
1097 ptr_data = ptr_data + 2;
1098 dbg("Getting FileID=[0x%x]", file_id);
1100 dbg("INVALID FCP received - DEbug!");
1106 /* proprietary information */
1107 if (*ptr_data == 0xA5) {
1108 unsigned short prop_len;
1109 /* increment to next byte */
1112 prop_len = *ptr_data;
1114 ptr_data = ptr_data + prop_len + 1;
1116 dbg("INVALID FCP received - DEbug!");
1119 /* life cycle status integer [8A][length:0x01][status]*/
1122 00000000 : No information given
1123 00000001 : creation state
1124 00000011 : initialization state
1125 000001-1 : operation state -activated
1126 000001-0 : operation state -deactivated
1127 000011-- : Termination state
1128 b8~b5 !=0, b4~b1=X : Proprietary
1129 Any other value : RFU
1131 if (*ptr_data == 0x8A) {
1132 /* increment to next byte */
1134 /* length - value 1 */
1137 switch (*ptr_data) {
1140 dbg("<IPC_RX> operation state -deactivated");
1145 dbg("<IPC_RX> operation state -activated");
1149 dbg("<IPC_RX> DEBUG! LIFE CYCLE STATUS =[0x%x]",*ptr_data);
1155 /* related to security attributes : currently not handled*/
1156 if (*ptr_data == 0x86 || *ptr_data == 0x8B || *ptr_data == 0x8C || *ptr_data == 0xAB) {
1157 /* increment to next byte */
1159 /* if tag length is 3 */
1160 if (*ptr_data == 0x03) {
1161 /* increment to next byte */
1164 memcpy(&arr_file_id, ptr_data, 2);
1166 SWAPBYTES16(arr_file_id);
1167 ptr_data = ptr_data + 2;
1168 arr_file_id_rec_num = *ptr_data++;
1170 /* if tag length is not 3 */
1171 /* ignoring bytes */
1172 // ptr_data = ptr_data + 4;
1173 dbg("Useless security attributes, so jump to next tag");
1174 ptr_data = ptr_data + (*ptr_data + 1);
1177 dbg("INVALID FCP received[0x%x] - DEbug!", *ptr_data);
1183 dbg("Current ptr_data value is [%x]", *ptr_data);
1185 /* file size excluding structural info*/
1186 if (*ptr_data == 0x80) {
1187 /* for EF file size is body of file and for Linear or cyclic it is
1188 * number of recXsizeof(one record)
1190 /* increment to next byte */
1192 /* length is 1 byte - value is 2 bytes or more */
1194 memcpy(&file_size, ptr_data, 2);
1196 SWAPBYTES16(file_size);
1197 ptr_data = ptr_data + 2;
1199 dbg("INVALID FCP received - DEbug!");
1205 /* total file size including structural info*/
1206 if (*ptr_data == 0x81) {
1208 /* increment to next byte */
1213 ptr_data = ptr_data + 3;
1215 dbg("INVALID FCP received - DEbug!");
1216 /* 0x81 is optional tag?? check out! so do not return -1 from here! */
1219 /*short file identifier ignored*/
1220 if (*ptr_data == 0x88) {
1221 dbg("0x88: Do Nothing");
1225 dbg("INVALID FCP received - DEbug!");
1230 } else if (tcore_sim_get_type(co_sim) == SIM_TYPE_GSM) {
1231 unsigned char gsm_specific_file_data_len = 0;
1232 /* ignore RFU byte1 and byte2 */
1236 //file_size = p_info->response_len;
1237 memcpy(&file_size, ptr_data, 2);
1239 SWAPBYTES16(file_size);
1240 /* parsed file size */
1241 ptr_data = ptr_data + 2;
1243 memcpy(&file_id, ptr_data, 2);
1244 SWAPBYTES16(file_id);
1245 dbg(" FILE id --> [%x]", file_id);
1246 ptr_data = ptr_data + 2;
1247 /* save file type - transparent, linear fixed or cyclic */
1248 file_type_tag = (*(ptr_data + 7));
1250 switch (*ptr_data) {
1253 dbg(" RFU file type- not handled - Debug!");
1257 dbg(" MF file type - not handled - Debug!");
1261 dbg(" DF file type - not handled - Debug!");
1265 dbg(" EF file type [%d] ", file_type_tag);
1266 /* increment to next byte */
1269 if (file_type_tag == 0x00 || file_type_tag == 0x01) {
1270 /* increament to next byte as this byte is RFU */
1273 (file_type_tag == 0x00) ? SIM_FTYPE_TRANSPARENT : SIM_FTYPE_LINEAR_FIXED;
1275 /* increment to next byte */
1277 /* For a cyclic EF all bits except bit 7 are RFU; b7=1 indicates that */
1278 /* the INCREASE command is allowed on the selected cyclic file. */
1279 file_type = SIM_FTYPE_CYCLIC;
1281 /* bytes 9 to 11 give SIM file access conditions */
1283 /* byte 10 has one nibble that is RF U and another for INCREASE which is not used currently */
1285 /* byte 11 is invalidate and rehabilate nibbles */
1287 /* byte 12 - file status */
1289 /* byte 13 - GSM specific data */
1290 gsm_specific_file_data_len = *ptr_data;
1292 /* byte 14 - structure of EF - transparent or linear or cyclic , already saved above */
1294 /* byte 15 - length of record for linear and cyclic , for transparent it is set to 0x00. */
1295 record_len = *ptr_data;
1296 dbg("record length[%d], file size[%d]", record_len, file_size);
1298 if (record_len != 0)
1299 num_of_records = (file_size / record_len);
1301 dbg("Number of records [%d]", num_of_records);
1305 dbg(" not handled file type");
1311 dbg(" Card Type - UNKNOWN [%d]", tcore_sim_get_type(co_sim));
1314 dbg("req ef[0x%x] resp ef[0x%x] size[%ld] Type[0x%x] NumOfRecords[%ld] RecordLen[%ld]",
1315 file_meta->file_id, file_id, file_size, file_type, num_of_records, record_len);
1317 file_meta->file_type = file_type;
1318 file_meta->data_size = file_size;
1319 file_meta->rec_length = record_len;
1320 file_meta->rec_count = num_of_records;
1321 file_meta->current_index = 0; //reset for new record type EF
1322 rt = SIM_ACCESS_SUCCESS;
1327 /*2. SIM access fail case*/
1328 dbg("error to get ef[0x%x]", file_meta->file_id);
1329 rt = _decode_status_word(sw1, sw2);
1334 ur = tcore_user_request_ref(ur);
1335 _next_from_get_file_info(co_sim, ur, file_meta->file_id, rt);
1340 dbg("error to get ef[0x%x]", file_meta->file_id);
1341 rt = SIM_ACCESS_FAILED;;
1343 ur = tcore_user_request_ref(ur);
1344 _next_from_get_file_info(co_sim, ur, file_meta->file_id, rt);
1348 static void _response_get_file_data(TcorePending *p, int data_len, const void *data, void *user_data)
1350 UserRequest *ur = NULL;
1351 CoreObject *co_sim = NULL;
1352 enum tel_sim_access_result rt;
1353 struct tel_sim_imsi imsi;
1354 struct s_sim_property *file_meta = NULL;
1355 gboolean dr = FALSE;
1362 dbg("[SIM_READ_BINARY] or [SIM_READ_RECORD]");
1364 dbg("sizeof struct tresp_sim_read = [%d]", sizeof(struct tresp_sim_read));
1366 co_sim = tcore_pending_ref_core_object(p);
1368 dbg("error - core object is null");
1371 ur = tcore_pending_ref_user_request(p);
1372 file_meta = (struct s_sim_property*)tcore_user_request_ref_metainfo(ur, NULL);
1374 if(sp_response->success > 0)
1376 line = sp_response->p_intermediates->line;
1378 ret = at_tok_start(&line);
1382 ret = at_tok_nextint(&line,&sw1);
1385 ret = at_tok_nextint(&line,&sw2);
1389 if((sw1 == 0x90 && sw2 == 0x00) || sw1 == 0x91) {
1393 ret = at_tok_nextstr(&line,&hexStr);
1397 fileData = util_hexStringToBytes(hexStr);
1398 util_hex_dump(" ", strlen(hexStr)/2, fileData);
1400 rt = SIM_ACCESS_SUCCESS;
1401 file_meta->files.result = rt;
1403 switch (file_meta->file_id)
1406 dr = tcore_sim_decode_imsi(&imsi, (unsigned char *)fileData, strlen(fileData));
1408 dbg("imsi decoding failed");
1410 _sim_check_identity(co_sim,&imsi);
1411 tcore_sim_set_imsi(co_sim,&imsi);
1416 dr = tcore_sim_decode_iccid(&file_meta->files.data.iccid, (unsigned char *)fileData, strlen(fileData));
1419 case SIM_EF_ELP:/* 2G EF - 2 bytes decoding*/
1420 case SIM_EF_USIM_LI: /* 3G EF - 2 bytes decoding*/
1421 case SIM_EF_USIM_PL:/* 3G EF - same as EFELP, so 2 byte decoding*/
1422 case SIM_EF_LP:/* 1 byte encoding*/
1423 if (tcore_sim_get_type(co_sim) == SIM_TYPE_GSM && file_meta->file_id == SIM_EF_LP) {
1424 /*2G LP(0x6F05) has 1 byte for each language*/
1425 dr = tcore_sim_decode_lp(&file_meta->files.data.language, (unsigned char *)fileData, strlen(fileData));
1427 /*3G LI(0x6F05)/PL(0x2F05), 2G ELP(0x2F05) has 2 bytes for each language*/
1428 dr = tcore_sim_decode_li(file_meta->file_id, &file_meta->files.data.language, (unsigned char *)fileData, strlen(fileData));
1433 dr = tcore_sim_decode_spn(&file_meta->files.data.spn, (unsigned char *)fileData, strlen(fileData));
1437 dr = tcore_sim_decode_spdi(&file_meta->files.data.spdi, (unsigned char *)fileData, strlen(fileData));
1441 /* if(tcore_sim_get_type(o) == SIM_TYPE_GSM)
1442 dr = tcore_sim_decode_sst(&file_meta->files.data , fileData, response_len);
1443 else if(tcore_sim_get_type(o) == SIM_TYPE_USIM)
1444 dr = tcore_sim_decode_ust(&po->st_u.ust, fileData, response_len);
1446 dbg("err not handled tcore_sim_get_type(o)[%d] in here",tcore_sim_get_type(o));
1451 /* dr = tcore_sim_decode_xdn(&file_meta->files.data.mailbox, fileData, strlen(fileData));*/
1455 if(tcore_sim_get_type(co_sim) == SIM_TYPE_GSM) {
1456 dr = tcore_sim_decode_ecc(&file_meta->files.data.ecc, (unsigned char *)fileData, strlen(fileData));
1457 } else if(tcore_sim_get_type(co_sim) == SIM_TYPE_USIM){
1458 dr = tcore_sim_decode_uecc(&file_meta->files.data.ecc.ecc[file_meta->current_index-1], (unsigned char *)fileData, strlen(fileData));
1460 dbg("err not handled tcore_sim_get_type(o)[%d] in here",tcore_sim_get_type(co_sim));
1464 case SIM_EF_USIM_MBI:
1465 /* dr = tcore_sim_decode_mbi(&po->mb_u.mailbox.mbi, fileData, strlen(fileData));*/
1469 dr = tcore_sim_decode_opl(&file_meta->files.data.opl.opl[file_meta->current_index-1], (unsigned char *)fileData, strlen(fileData));
1473 dr = tcore_sim_decode_pnn(&file_meta->files.data.pnn.pnn[file_meta->current_index-1], (unsigned char *)fileData, strlen(fileData));
1476 case SIM_EF_OPLMN_ACT:
1477 dr = tcore_sim_decode_oplmnwact(&file_meta->files.data.opwa, (unsigned char *)fileData, strlen(fileData));
1480 case SIM_EF_CPHS_CALL_FORWARD_FLAGS:
1481 dr = tcore_sim_decode_cff(&file_meta->files.data.cf, (unsigned char *)fileData, strlen(fileData));
1484 case SIM_EF_CPHS_CUSTOMER_SERVICE_PROFILE:
1485 /* dr = tcore_sim_decode_csp(&po->p_cphs->csp, fileData, strlen(fileData));*/
1488 case SIM_EF_CPHS_VOICE_MSG_WAITING:
1489 dr = tcore_sim_decode_vmwf(&file_meta->files.data.mw.mw_data_u.cphs_mw, (unsigned char *)fileData, strlen(fileData));
1492 case SIM_EF_CPHS_MAILBOX_NUMBERS:
1493 /* dbg("[CPHS]decoding SIM_EF_CPHS_MAILBOX_NUMBERS");
1494 if (file_meta->current_index == 1)
1495 dr = tcore_sim_decode_xdn(&po->mb_u.mbn.voice_line1, fileData, strlen(fileData));
1496 else if (file_meta->current_index == 2)
1497 dr = tcore_sim_decode_xdn(&po->mb_u.mbn.voice_line2, fileData, strlen(fileData));
1498 else if (file_meta->current_index == 3)
1499 dr = tcore_sim_decode_xdn(&po->mb_u.mbn.video, fileData, strlen(fileData));
1500 else if (file_meta->current_index == 4)
1501 dr = tcore_sim_decode_xdn(&po->mb_u.mbn.fax, fileData, strlen(fileData));
1503 dbg("[CPHS]wrong EF record index[%d] in here", file_meta->current_index);
1507 case SIM_EF_USIM_MWIS:
1508 dr = tcore_sim_decode_mwis(&file_meta->files.data.mw.mw_data_u.mw, (unsigned char *)fileData, strlen(fileData));
1511 case SIM_EF_USIM_CFIS:
1512 dr = tcore_sim_decode_cfis(&file_meta->files.data.cf, (unsigned char *)fileData, strlen(fileData));
1515 case SIM_EF_CPHS_SERVICE_STRING_TABLE:
1516 dbg(" not handled -SIM_EF_CPHS_SERVICE_STRING_TABLE ");
1519 case SIM_EF_CPHS_OPERATOR_NAME_STRING:
1520 dr = tcore_sim_decode_ons((unsigned char*)&file_meta->files.data.cphs_net.full_name, (unsigned char *)fileData, strlen(fileData));
1523 case SIM_EF_CPHS_DYNAMICFLAGS:
1524 /* dr = tcore_sim_decode_dynamic_flag(&po->p_cphs->dflagsinfo, fileData, strlen(fileData));*/
1527 case SIM_EF_CPHS_DYNAMIC2FLAG:
1528 /* dr = tcore_sim_decode_dynamic2_flag(&po->p_cphs->d2flagsinfo, fileData, strlen(fileData));*/
1531 case SIM_EF_CPHS_CPHS_INFO:
1532 dr = tcore_sim_decode_cphs_info(&file_meta->files.data.cphs, (unsigned char *)fileData, strlen(fileData));
1535 case SIM_EF_CPHS_OPERATOR_NAME_SHORT_FORM_STRING:
1536 dr = tcore_sim_decode_short_ons((unsigned char*)&file_meta->files.data.cphs_net.short_name, (unsigned char *)fileData, strlen(fileData));
1539 case SIM_EF_CPHS_INFORMATION_NUMBERS:
1540 /* dr = tcore_sim_decode_information_number(&po->p_cphs->infn, fileData, strlen(fileData));*/
1544 dbg("File Decoding Failed - not handled File[0x%x]", file_meta->file_id);
1553 rt = _decode_status_word(sw1, sw2);
1554 file_meta->files.result = rt;
1562 rt = SIM_ACCESS_FAILED;;
1563 file_meta->files.result = rt;
1566 ur = tcore_user_request_ref(ur);
1567 _next_from_get_file_data(tcore_pending_ref_core_object(p), ur, rt, dr);
1570 static gboolean _get_sim_type(CoreObject *o)
1572 TcorePlugin *p = NULL;
1574 TcorePending *pending = NULL;
1576 char *cmd_str = NULL;
1577 struct ATReqMetaInfo metainfo;
1579 UserRequest *ur = NULL;
1584 p = tcore_object_ref_plugin(o);
1585 h = tcore_object_get_hal(o);
1587 memset(&metainfo, 0, sizeof(struct ATReqMetaInfo));
1588 metainfo.type = SINGLELINE;
1589 memcpy(metainfo.responsePrefix,"%SCCT:",strlen("%SCCT:"));
1590 info_len = sizeof(struct ATReqMetaInfo);
1592 ur = tcore_user_request_new(NULL, NULL);
1594 tcore_user_request_set_metainfo(ur, info_len, &metainfo);
1596 // AT+CPIN=<pin>[,<newpin>]
1597 cmd_str = g_strdup("AT%SCCT\r");
1599 pending = tcore_pending_new(o, ID_RESERVED_AT);
1600 tcore_pending_set_request_data(pending, strlen(cmd_str), cmd_str);
1601 tcore_pending_set_timeout(pending, 0);
1602 tcore_pending_set_response_callback(pending, _response_get_sim_type, NULL);
1603 tcore_pending_link_user_request(pending, ur);
1605 tcore_pending_set_send_callback(pending, on_confirmation_sim_message_send, NULL);
1607 tcore_hal_send_request(h, pending);
1614 static TReturn _get_file_info(CoreObject *o, UserRequest *ur, const enum tel_sim_file_id ef)
1616 TcorePlugin *p = NULL;
1618 TcorePending *pending = NULL;
1620 struct s_sim_property file_meta={0,};
1623 char *cmd_str = NULL;
1627 return TCORE_RETURN_EINVAL;
1629 p = tcore_object_ref_plugin(o);
1630 h = tcore_object_get_hal(o);
1632 file_meta.file_id = ef;
1633 file_meta.metainfo.type = SINGLELINE;
1634 memcpy(file_meta.metainfo.responsePrefix,"+CRSM:",strlen("+CRSM:"));
1635 info_len = sizeof(struct s_sim_property);
1637 tcore_user_request_set_command(ur, TREQ_CUSTOM);
1639 trt = tcore_user_request_set_metainfo(ur, sizeof(struct s_sim_property), &file_meta);
1642 // AT+CRSM=<command>,<fildid>,<p1>,<p2+C29,<p3>
1643 cmd_str = g_strdup_printf("AT+CRSM=192, %d%s", ef, "\r");
1645 dbg("new pending(IPC_SEC_RSIM_ACCESS GET - SELECT EF[0x%x])",ef);
1646 pending = tcore_pending_new(o, ID_RESERVED_AT);
1647 tcore_pending_set_request_data(pending, strlen(cmd_str), cmd_str);
1648 tcore_pending_set_timeout(pending, 0);
1649 tcore_pending_set_response_callback(pending, _response_get_file_info, NULL);
1650 tcore_pending_link_user_request(pending, ur);
1652 tcore_pending_set_send_callback(pending, on_confirmation_sim_message_send, NULL);
1654 tcore_hal_send_request(h, pending);
1657 return TCORE_RETURN_SUCCESS;
1660 static gboolean _get_file_data(CoreObject *o, UserRequest *ur, const enum tel_sim_file_id ef, const int offset, const int length)
1662 TcorePlugin *p = NULL;
1664 TcorePending *pending = NULL;
1667 char *cmd_str = NULL;
1668 struct ATReqMetaInfo metainfo;
1677 dbg("new pending(IPC_SEC_RSIM_ACCESS GET - READ BIN)");
1679 p = tcore_object_ref_plugin(o);
1680 h = tcore_object_get_hal(o);
1682 // offset for reading the TRANSPARENT data
1683 p1 = (unsigned char)(offset & 0xFF00) >> 8;
1684 p2 = (unsigned char)offset & 0x00FF; //offset low
1685 p3 = (unsigned char)length;
1686 dbg("EF[0x%x]", ef);
1688 memset(&metainfo, 0, sizeof(struct ATReqMetaInfo));
1689 metainfo.type = SINGLELINE;
1690 memcpy(metainfo.responsePrefix,"+CRSM:",strlen("+CRSM:"));
1691 info_len = sizeof(struct ATReqMetaInfo);
1693 // AT+CRSM=<command>,<fildid>,<p1>,<p2+C29,<p3>
1694 cmd_str = g_strdup_printf("AT+CRSM=176, %d%s", ef, "\r");
1696 pending = tcore_pending_new(o, ID_RESERVED_AT);
1697 tcore_pending_set_request_data(pending, strlen(cmd_str), cmd_str);
1698 tcore_pending_set_timeout(pending, 0);
1699 tcore_pending_set_response_callback(pending, _response_get_file_data, NULL);
1700 tcore_pending_link_user_request(pending, ur);
1702 tcore_pending_set_send_callback(pending, on_confirmation_sim_message_send, NULL);
1704 tcore_hal_send_request(h, pending);
1709 static gboolean _get_file_record(CoreObject *o, UserRequest *ur, const enum tel_sim_file_id ef, const int index, const int length)
1711 dbg("need to be implemented to use ATCMD");
1716 static gboolean on_event_pin_status(CoreObject *o, const void *event_info, void *user_data)
1719 char *line = (char *) event_info;
1720 //struct tnoti_sim_status noti_data;
1721 struct s_sim_property *sp = NULL;
1722 enum tel_sim_status sim_status = SIM_STATUS_INITIALIZING;
1723 enum s_sim_sec_locktype_e locktype = SEC_LOCK_TYPE_NONE;
1724 enum s_sim_sec_lockkey_e lockkey = SEC_LOCK_KEY_NONE;
1726 dbg("PIN_STATUS NOTI : %s", line);
1728 _convert_SCPIN_noti(line,&locktype, &lockkey);
1730 sp = tcore_sim_ref_userdata(o);
1734 case SEC_LOCK_TYPE_READY:
1735 if (lockkey == SEC_LOCK_KEY_UNLOCKED) {
1736 sim_status = SIM_STATUS_INITIALIZING;
1737 dbg(" Inside PIN disabled at BOOT UP");
1740 dbg(" not handled case p_status->lock_key[%d]", lockkey);
1744 case SEC_LOCK_TYPE_PS:
1745 sim_status = SIM_STATUS_LOCK_REQUIRED;
1746 dbg( " SIM LOCK required");
1749 case SEC_LOCK_TYPE_PF:
1750 sim_status = SIM_STATUS_CARD_ERROR;
1751 dbg( "PF required ");
1754 case SEC_LOCK_TYPE_SC:
1756 case SEC_LOCK_KEY_UNLOCKED:
1758 case SEC_LOCK_KEY_PIN:
1759 sim_status = SIM_STATUS_PIN_REQUIRED;
1760 dbg( " PIN1 required");
1762 case SEC_LOCK_KEY_PUK:
1763 sim_status = SIM_STATUS_PUK_REQUIRED;
1764 dbg( " PUK required");
1766 case SEC_LOCK_KEY_PERM_BLOCKED:
1767 sim_status = SIM_STATUS_CARD_BLOCKED;
1768 dbg( " Card permanently blocked");
1771 dbg(" SEC_SIM_LOCK_SC -not handled SEC Lock key ");
1776 case SEC_LOCK_TYPE_FD:
1777 dbg(" SEC_LOCK_TYPE_FD -not handled Notification");
1780 case SEC_LOCK_TYPE_PN:
1782 case SEC_LOCK_KEY_PIN:
1783 dbg(" ADMIN-NCK required");
1784 sim_status = SIM_STATUS_NCK_REQUIRED;
1787 dbg(" SIM_LOCK_PN/PU/PP/PC -not handled SEC Lock key =[%d]",
1793 case SEC_LOCK_TYPE_PU:
1794 dbg("Lock Personalization p_status->lock_key =[%d]", lockkey);
1796 case SEC_LOCK_KEY_PIN:
1797 dbg(" ADMIN-NSCK required");
1798 sim_status = SIM_STATUS_NSCK_REQUIRED;
1801 dbg(" SIM_LOCK_PN/PU/PP/PC -not handled SEC Lock key =[%d]",
1807 case SEC_LOCK_TYPE_PP:
1809 dbg("Lock Personalization p_status->lock_key =[%d]", lockkey);
1810 case SEC_LOCK_KEY_PIN:
1811 dbg(" ADMIN-SPCK required");
1812 sim_status = SIM_STATUS_SPCK_REQUIRED;
1815 dbg(" SIM_LOCK_PN/PU/PP/PC -not handled SEC Lock key =[%d]",
1821 case SEC_LOCK_TYPE_PC:
1823 dbg("Lock Personalization p_status->lock_key =[%d]", lockkey);
1824 case SEC_LOCK_KEY_PIN:
1825 dbg(" ADMIN-CCK required");
1826 sim_status = SIM_STATUS_CCK_REQUIRED;
1829 dbg(" SIM_LOCK_PN/PU/PP/PC -not handled SEC Lock key =[%d]",
1835 case SEC_LOCK_TYPE_SC2:
1836 dbg("SEC_LOCK_TYPE_SC2: NOT Handled - Debug");
1839 case SEC_LOCL_TYPE_PUK2:
1840 dbg("SEC_LOCL_TYPE_PUK2: NOT Handled - Debug");
1843 case SEC_LOCK_TYPE_NO_SIM:
1844 sim_status = SIM_STATUS_CARD_NOT_PRESENT;
1848 case SEC_LOCK_TYPE_UNAVAIL:
1849 case SEC_SIM_INIT_CRASH: //SMC Lab requirement
1850 sim_status = SIM_STATUS_CARD_ERROR;
1851 dbg( "SIM unavailable");
1854 case SEC_SIM_INIT_COMPLETED:
1855 dbg( "[SIM DATA] MODEM SIM INIT COMPLETED");
1856 sim_status = SIM_STATUS_INIT_COMPLETED;
1859 case SEC_PB_INIT_COMPLETED:
1860 dbg("[SIM DATA] MODEM SIM PB INIT COMPLETED. not handled here! s_phonebook should handle!");
1865 dbg(" not handled SEC lock type ");
1869 dbg("[SIM]Current co->sim_status[%d] and from modem[0x%x]",tcore_sim_get_status(o), sim_status);
1871 switch (sim_status) {
1872 case SIM_STATUS_INIT_COMPLETED:
1873 ur = tcore_user_request_new(NULL, NULL); //this is for using ur metainfo set/ref functionality.
1874 _get_file_info(o, ur, SIM_EF_IMSI);
1877 case SIM_STATUS_INITIALIZING:
1878 case SIM_STATUS_PIN_REQUIRED:
1879 case SIM_STATUS_PUK_REQUIRED:
1880 case SIM_STATUS_CARD_BLOCKED:
1881 case SIM_STATUS_NCK_REQUIRED:
1882 case SIM_STATUS_NSCK_REQUIRED:
1883 case SIM_STATUS_SPCK_REQUIRED:
1884 case SIM_STATUS_CCK_REQUIRED:
1885 case SIM_STATUS_LOCK_REQUIRED:
1886 if( sp->first_recv_status == SIM_STATUS_UNKNOWN ) {
1887 dbg("first received sim status[%d]",sim_status);
1888 sp->first_recv_status = sim_status;
1893 case SIM_STATUS_CARD_REMOVED:
1894 case SIM_STATUS_CARD_NOT_PRESENT:
1895 case SIM_STATUS_CARD_ERROR:
1896 if (sim_status == SIM_STATUS_CARD_NOT_PRESENT && tcore_sim_get_status(o) != SIM_STATUS_UNKNOWN) {
1897 dbg("[SIM]SIM CARD REMOVED!!");
1898 sim_status = SIM_STATUS_CARD_REMOVED;
1900 _sim_status_update(o,sim_status);
1904 dbg("not handled status[%d]", sim_status);
1911 static void on_response_verify_pins(TcorePending *p, int data_len, const void *data, void *user_data)
1913 UserRequest *ur = NULL;
1914 CoreObject *co_sim = NULL;
1915 struct s_sim_property *sp = NULL;
1916 struct tresp_sim_verify_pins resp = {0,};
1922 co_sim = tcore_pending_ref_core_object(p);
1923 sp = tcore_sim_ref_userdata(co_sim);
1925 ur = tcore_pending_ref_user_request(p);
1927 dbg("error - current ur is NULL");
1931 if(sp_response->success > 0)
1935 resp.result = SIM_PIN_OPERATION_SUCCESS;
1936 resp.pin_type = _sim_get_current_pin_facility(sp);
1937 tcore_user_request_send_response(ur, TRESP_SIM_VERIFY_PINS, sizeof(struct tresp_sim_verify_pins), &resp);
1941 //failure case - consider this later
1942 line = sp_response->finalResponse;
1944 ret = at_tok_start(&line);
1948 ret = at_tok_nextint(&line,&error);
1954 // ur = user_request_dup(ur);
1955 // _get_retry_count(co_sim, ur);
1957 resp.result = SIM_INCORRECT_PASSWORD;
1958 resp.pin_type = _sim_get_current_pin_facility(sp);
1959 resp.retry_count = 3;
1960 tcore_user_request_send_response(ur, TRESP_SIM_VERIFY_PINS, sizeof(struct tresp_sim_verify_pins), &resp);
1965 static void on_response_verify_puks(TcorePending *p, int data_len, const void *data, void *user_data)
1967 UserRequest *ur = NULL;
1968 CoreObject *co_sim = NULL;
1969 struct s_sim_property *sp = NULL;
1970 struct tresp_sim_verify_puks resp = {0,};
1976 co_sim = tcore_pending_ref_core_object(p);
1977 sp = tcore_sim_ref_userdata(co_sim);
1979 ur = tcore_pending_ref_user_request(p);
1981 dbg("error - current ur is NULL");
1985 if(sp_response->success > 0)
1989 resp.result = SIM_PIN_OPERATION_SUCCESS;
1990 resp.pin_type = _sim_get_current_pin_facility(sp);
1991 tcore_user_request_send_response(ur, TRESP_SIM_VERIFY_PINS, sizeof(struct tresp_sim_verify_pins), &resp);
1995 //failure case - consider this later
1996 line = sp_response->finalResponse;
1998 ret = at_tok_start(&line);
2002 ret = at_tok_nextint(&line,&error);
2008 // ur = user_request_dup(ur);
2009 // _get_retry_count(co_sim, ur);
2011 resp.result = SIM_INCORRECT_PASSWORD;
2012 resp.pin_type = _sim_get_current_pin_facility(sp);
2013 tcore_user_request_send_response(ur, TRESP_SIM_VERIFY_PUKS, sizeof(struct tresp_sim_verify_puks), &resp);
2018 static void on_response_change_pins(TcorePending *p, int data_len, const void *data, void *user_data)
2020 UserRequest *ur = NULL;
2021 CoreObject *co_sim = NULL;
2022 struct s_sim_property *sp = NULL;
2023 struct tresp_sim_change_pins resp = {0,};
2029 co_sim = tcore_pending_ref_core_object(p);
2030 sp = tcore_sim_ref_userdata(co_sim);
2032 ur = tcore_pending_ref_user_request(p);
2034 dbg("error - current ur is NULL");
2038 if(sp_response->success > 0)
2042 resp.result = SIM_PIN_OPERATION_SUCCESS;
2043 resp.pin_type = _sim_get_current_pin_facility(sp);
2044 tcore_user_request_send_response(ur, TRESP_SIM_VERIFY_PINS, sizeof(struct tresp_sim_verify_pins), &resp);
2048 //failure case - consider this later
2049 line = sp_response->finalResponse;
2051 ret = at_tok_start(&line);
2055 ret = at_tok_nextint(&line,&error);
2061 // ur = user_request_dup(ur);
2062 // _get_retry_count(co_sim, ur);
2064 resp.result = SIM_INCORRECT_PASSWORD;
2065 resp.pin_type = _sim_get_current_pin_facility(sp);
2066 tcore_user_request_send_response(ur, TRESP_SIM_CHANGE_PINS, sizeof(struct tresp_sim_change_pins), &resp);
2070 static void on_response_get_facility_status(TcorePending *p, int data_len, const void *data, void *user_data)
2072 UserRequest *ur = NULL;
2073 CoreObject *co_sim = NULL;
2074 struct s_sim_property *sec_meta = NULL;
2075 struct tresp_sim_get_facility_status resp = {0,};
2080 co_sim = tcore_pending_ref_core_object(p);
2081 ur = tcore_pending_ref_user_request(p);
2082 sec_meta = (struct s_sim_property*)tcore_user_request_ref_metainfo(ur, NULL);
2084 resp.result = SIM_PIN_OPERATION_SUCCESS;
2085 resp.type = _sim_get_current_pin_facility(sec_meta);
2089 if(sp_response->success > 0)
2091 line = sp_response->p_intermediates->line;
2093 ret = at_tok_start(&line);
2097 ret = at_tok_nextint(&line,(int *)&resp.b_enable);
2103 resp.result = SIM_INCOMPATIBLE_PIN_OPERATION;
2109 tcore_user_request_send_response(ur, TRESP_SIM_GET_FACILITY_STATUS,
2110 sizeof(struct tresp_sim_get_facility_status), &resp);
2114 static void on_response_enable_facility(TcorePending *p, int data_len, const void *data, void *user_data)
2116 UserRequest *ur = NULL;
2117 CoreObject *co_sim = NULL;
2118 struct s_sim_property *sec_meta = NULL;
2119 struct tresp_sim_enable_facility resp = {0,};
2120 struct s_sim_property *sp = NULL;
2125 co_sim = tcore_pending_ref_core_object(p);
2126 ur = tcore_pending_ref_user_request(p);
2127 sp = tcore_sim_ref_userdata(co_sim);
2128 sec_meta = (struct s_sim_property*)tcore_user_request_ref_metainfo(ur, NULL);
2130 resp.result = SIM_PIN_OPERATION_SUCCESS;
2131 resp.type = _sim_get_current_pin_facility(sec_meta);
2135 if(sp_response->success > 0)
2137 line = sp_response->p_intermediates->line;
2139 ret = at_tok_start(&line);
2143 ret = at_tok_nextint(&line,(int *)&resp.result);
2149 resp.result = SIM_INCOMPATIBLE_PIN_OPERATION;
2155 resp.type = _sim_get_current_pin_facility(sp);
2156 tcore_user_request_send_response(ur, _find_resp_command(ur), sizeof(struct tresp_sim_enable_facility), &resp);
2160 static void on_response_disable_facility(TcorePending *p, int data_len, const void *data, void *user_data)
2162 UserRequest *ur = NULL;
2163 CoreObject *co_sim = NULL;
2164 struct s_sim_property *sec_meta = NULL;
2165 struct tresp_sim_disable_facility resp = {0,};
2166 struct s_sim_property *sp = NULL;
2171 co_sim = tcore_pending_ref_core_object(p);
2172 ur = tcore_pending_ref_user_request(p);
2173 sp = tcore_sim_ref_userdata(co_sim);
2174 sec_meta = (struct s_sim_property*)tcore_user_request_ref_metainfo(ur, NULL);
2176 resp.result = SIM_PIN_OPERATION_SUCCESS;
2177 resp.type = _sim_get_current_pin_facility(sec_meta);
2181 if(sp_response->success > 0)
2183 line = sp_response->p_intermediates->line;
2185 ret = at_tok_start(&line);
2189 ret = at_tok_nextint(&line,(int *)&resp.result);
2195 resp.result = SIM_INCOMPATIBLE_PIN_OPERATION;
2201 resp.type = _sim_get_current_pin_facility(sp);
2202 tcore_user_request_send_response(ur, _find_resp_command(ur), sizeof(struct tresp_sim_disable_facility), &resp);
2206 static TReturn s_verify_pins(CoreObject *o, UserRequest *ur)
2208 TcorePlugin *p = NULL;
2210 TcorePending *pending = NULL;
2212 struct s_sim_property *sp = NULL;
2213 const struct treq_sim_verify_pins *req_data;
2215 char *cmd_str = NULL;
2216 struct ATReqMetaInfo metainfo;
2220 return TCORE_RETURN_EINVAL;
2222 p = tcore_object_ref_plugin(o);
2223 h = tcore_object_get_hal(o);
2224 req_data = tcore_user_request_ref_data(ur, NULL);
2225 sp = tcore_sim_ref_userdata(o);
2227 if (req_data->pin_type == SIM_PTYPE_PIN1) {
2228 sp->current_sec_op = SEC_PIN1_VERIFY;
2230 else if (req_data->pin_type == SIM_PTYPE_PIN2) {
2231 sp->current_sec_op = SEC_PIN2_VERIFY;
2233 else if (req_data->pin_type == SIM_PTYPE_SIM) {
2234 sp->current_sec_op = SEC_SIM_VERIFY;
2236 else if (req_data->pin_type == SIM_PTYPE_ADM) {
2237 sp->current_sec_op = SEC_ADM_VERIFY;
2240 return TCORE_RETURN_EINVAL;
2243 memset(&metainfo, 0, sizeof(struct ATReqMetaInfo));
2244 metainfo.type = NO_RESULT;
2245 metainfo.responsePrefix[0] ='\0';
2246 info_len = sizeof(struct ATReqMetaInfo);
2248 tcore_user_request_set_metainfo(ur, info_len, &metainfo);
2250 // AT+CPIN=<pin>[,<newpin>]
2251 cmd_str = g_strdup_printf("AT+CPIN=\"%s\"%s", req_data->pin, "\r");
2252 dbg("new pending(verify - pins), %s", cmd_str);
2254 pending = tcore_pending_new(o,ID_RESERVED_AT);
2255 tcore_pending_set_request_data(pending, strlen(cmd_str), cmd_str);
2256 tcore_pending_set_timeout(pending, 0);
2257 tcore_pending_set_priority(pending, TCORE_PENDING_PRIORITY_DEFAULT);
2258 tcore_pending_set_response_callback(pending, on_response_verify_pins, NULL);
2259 tcore_pending_link_user_request(pending, ur);
2261 tcore_pending_set_send_callback(pending, on_confirmation_sim_message_send, NULL);
2263 tcore_hal_send_request(h, pending);
2267 return TCORE_RETURN_SUCCESS;
2270 static TReturn s_verify_puks(CoreObject *o, UserRequest *ur)
2272 TcorePlugin *p = NULL;
2274 TcorePending *pending = NULL;
2276 const struct treq_sim_verify_puks *req_data;
2277 struct s_sim_property *sp = NULL;
2279 char *cmd_str = NULL;
2280 struct ATReqMetaInfo metainfo;
2284 return TCORE_RETURN_EINVAL;
2286 p = tcore_object_ref_plugin(o);
2287 h = tcore_object_get_hal(o);
2288 req_data = tcore_user_request_ref_data(ur, NULL);
2289 sp = tcore_sim_ref_userdata(o);
2292 if(req_data->puk_type == SIM_PTYPE_PUK1){
2293 sp->current_sec_op = SEC_PUK1_VERIFY;
2295 else if(req_data->puk_type == SIM_PTYPE_PUK2){
2296 sp->current_sec_op = SEC_PUK2_VERIFY;
2299 return TCORE_RETURN_EINVAL;
2302 memset(&metainfo, 0, sizeof(struct ATReqMetaInfo));
2303 metainfo.type = NO_RESULT;
2304 metainfo.responsePrefix[0] ='\0';
2305 info_len = sizeof(struct ATReqMetaInfo);
2307 tcore_user_request_set_metainfo(ur, info_len, &metainfo);
2309 // AT+CPIN=<pin>[,<newpin>]
2310 cmd_str = g_strdup_printf("AT+CPIN=\"%s\", \"%s\"%s", req_data->puk, req_data->pin, "\r");
2312 dbg("new pending(IPC_SEC_PIN_STATUS SET - verify puks)");
2313 pending = tcore_pending_new(o, ID_RESERVED_AT);
2314 tcore_pending_set_request_data(pending, strlen(cmd_str), cmd_str);
2315 tcore_pending_set_timeout(pending, 0);
2316 tcore_pending_set_priority(pending, TCORE_PENDING_PRIORITY_DEFAULT);
2317 tcore_pending_set_response_callback(pending, on_response_verify_puks, NULL);
2318 tcore_pending_link_user_request(pending, ur);
2320 tcore_pending_set_send_callback(pending, on_confirmation_sim_message_send, NULL);
2322 tcore_hal_send_request(h, pending);
2326 return TCORE_RETURN_SUCCESS;
2329 static TReturn s_change_pins(CoreObject *o, UserRequest *ur)
2331 TcorePlugin *p = NULL;
2333 TcorePending *pending = NULL;
2335 const struct treq_sim_change_pins *req_data;
2336 struct s_sim_property *sp = NULL;
2338 char *cmd_str = NULL;
2339 struct ATReqMetaInfo metainfo;
2343 return TCORE_RETURN_EINVAL;
2345 p = tcore_object_ref_plugin(o);
2346 h = tcore_object_get_hal(o);
2347 req_data = tcore_user_request_ref_data(ur, NULL);
2348 sp = tcore_sim_ref_userdata(o);
2350 if(req_data->type == SIM_PTYPE_PIN1) {
2351 sp->current_sec_op = SEC_PIN1_CHANGE;
2353 else if(req_data->type == SIM_PTYPE_PIN2) {
2354 sp->current_sec_op = SEC_PIN2_CHANGE;
2357 return TCORE_RETURN_EINVAL;
2360 memset(&metainfo, 0, sizeof(struct ATReqMetaInfo));
2361 metainfo.type = NO_RESULT;
2362 metainfo.responsePrefix[0] ='\0';
2363 info_len = sizeof(struct ATReqMetaInfo);
2365 tcore_user_request_set_metainfo(ur, info_len, &metainfo);
2367 // AT+CPIN=<pin>[,<newpin>]
2368 cmd_str = g_strdup_printf("AT+CPIN=\"%s\", \"%s\"%s", req_data->old_pin, req_data->new_pin, "\r");
2370 dbg("new pending(IPC_SEC_CHANGE_LOCKING_PW SET)");
2371 pending = tcore_pending_new(o, ID_RESERVED_AT);
2372 tcore_pending_set_request_data(pending, strlen(cmd_str), cmd_str);
2373 tcore_pending_set_timeout(pending, 0);
2374 tcore_pending_set_priority(pending, TCORE_PENDING_PRIORITY_DEFAULT);
2375 tcore_pending_set_response_callback(pending, on_response_change_pins, NULL);
2376 tcore_pending_link_user_request(pending, ur);
2378 tcore_pending_set_send_callback(pending, on_confirmation_sim_message_send, NULL);
2380 tcore_hal_send_request(h, pending);
2384 return TCORE_RETURN_SUCCESS;
2387 static TReturn s_get_facility_status(CoreObject *o, UserRequest *ur)
2389 TcorePlugin *p = NULL;
2391 TcorePending *pending = NULL;
2392 struct s_sim_property sec_meta = {0,};
2395 const struct treq_sim_get_facility_status *req_data;
2397 int mode = 2; // 2:query, 0: unlock, 1:lock
2399 char *cmd_str = NULL;
2400 // struct ATReqMetaInfo metainfo;
2404 return TCORE_RETURN_EINVAL;
2406 p = tcore_object_ref_plugin(o);
2407 h = tcore_object_get_hal(o);
2408 req_data = tcore_user_request_ref_data(ur, NULL);
2410 if(req_data->type == SIM_FACILITY_PS)
2412 else if(req_data->type == SIM_FACILITY_SC)
2414 else if(req_data->type == SIM_FACILITY_FD)
2416 else if(req_data->type == SIM_FACILITY_PN)
2418 else if(req_data->type == SIM_FACILITY_PU)
2420 else if(req_data->type == SIM_FACILITY_PP)
2422 else if(req_data->type == SIM_FACILITY_PC)
2425 return TCORE_RETURN_EINVAL;
2427 sec_meta.current_sec_op = req_data->type;
2428 sec_meta.metainfo.type = SINGLELINE;
2429 memcpy(sec_meta.metainfo.responsePrefix,"+CLCK:",strlen("+CLCK:"));
2430 info_len = sizeof(struct s_sim_property);
2431 tcore_user_request_set_command(ur, TREQ_CUSTOM);
2432 trt = tcore_user_request_set_metainfo(ur, sizeof(struct s_sim_property), &sec_meta);
2435 // AT+CLCK=<fac>,<mode>,<password>
2436 cmd_str = g_strdup_printf("AT+CLCK=\"%s\", %d%s", fac, mode, "\r");
2438 dbg("new pending(IPC_SEC_PHONE_LOCK GET)");
2439 pending = tcore_pending_new(o, ID_RESERVED_AT);
2440 tcore_pending_set_request_data(pending, strlen(cmd_str), cmd_str);
2441 tcore_pending_set_timeout(pending, 0);
2442 tcore_pending_set_priority(pending, TCORE_PENDING_PRIORITY_DEFAULT);
2443 tcore_pending_set_response_callback(pending, on_response_get_facility_status, NULL);
2444 tcore_pending_link_user_request(pending, ur);
2446 tcore_pending_set_send_callback(pending, on_confirmation_sim_message_send, NULL);
2448 tcore_hal_send_request(h, pending);
2452 return TCORE_RETURN_SUCCESS;
2455 static TReturn s_enable_facility(CoreObject *o, UserRequest *ur)
2457 TcorePlugin *p = NULL;
2459 TcorePending *pending = NULL;
2460 struct s_sim_property sec_meta = {0,};
2461 const struct treq_sim_enable_facility *req_data;
2462 struct s_sim_property *sp = NULL;
2464 int mode = 1; // 2:query, 0: unlock, 1:lock
2466 char *cmd_str = NULL;
2467 // struct ATReqMetaInfo metainfo;
2471 return TCORE_RETURN_EINVAL;
2473 p = tcore_object_ref_plugin(o);
2474 h = tcore_object_get_hal(o);
2475 req_data = tcore_user_request_ref_data(ur, NULL);
2476 sp = tcore_sim_ref_userdata(o);
2478 if (req_data->type == SIM_FACILITY_PS)
2480 else if (req_data->type == SIM_FACILITY_SC)
2482 else if (req_data->type == SIM_FACILITY_FD)
2484 else if (req_data->type == SIM_FACILITY_PN)
2486 else if (req_data->type == SIM_FACILITY_PU)
2488 else if (req_data->type == SIM_FACILITY_PP)
2490 else if (req_data->type == SIM_FACILITY_PC)
2493 return TCORE_RETURN_EINVAL;
2495 sp->current_sec_op = SEC_SIM_ENABLE;
2497 sec_meta.current_sec_op = req_data->type;
2498 sec_meta.metainfo.type = SINGLELINE;
2499 memcpy(sec_meta.metainfo.responsePrefix,"+CLCK:",strlen("+CLCK:"));
2500 info_len = sizeof(struct s_sim_property);
2501 tcore_user_request_set_command(ur, TREQ_CUSTOM);
2502 tcore_user_request_set_metainfo(ur, sizeof(struct s_sim_property), &sec_meta);
2504 // AT+CLCK=<fac>,<mode>,<password>
2505 cmd_str = g_strdup_printf("AT+CLCK=\"%s\", %d, %s%s", fac, mode, req_data->password,"\r");
2506 dbg("new pending(enable_facility), %s", cmd_str);
2508 pending = tcore_pending_new(o, ID_RESERVED_AT);
2509 tcore_pending_set_request_data(pending, strlen(cmd_str), cmd_str);
2510 tcore_pending_set_timeout(pending, 0);
2511 tcore_pending_set_priority(pending, TCORE_PENDING_PRIORITY_DEFAULT);
2512 tcore_pending_set_response_callback(pending, on_response_enable_facility, NULL);
2513 tcore_pending_link_user_request(pending, ur);
2515 tcore_pending_set_send_callback(pending, on_confirmation_sim_message_send, NULL);
2517 tcore_hal_send_request(h, pending);
2521 return TCORE_RETURN_SUCCESS;
2524 static TReturn s_disable_facility(CoreObject *o, UserRequest *ur)
2526 TcorePlugin *p = NULL;
2528 TcorePending *pending = NULL;
2529 struct s_sim_property sec_meta = {0,};
2530 const struct treq_sim_enable_facility *req_data;
2531 struct s_sim_property *sp = NULL;
2533 int mode = 0; // 2:query, 0: unlock, 1:lock
2535 char *cmd_str = NULL;
2536 // struct ATReqMetaInfo metainfo;
2540 return TCORE_RETURN_EINVAL;
2542 p = tcore_object_ref_plugin(o);
2543 h = tcore_object_get_hal(o);
2544 req_data = tcore_user_request_ref_data(ur, NULL);
2545 sp = tcore_sim_ref_userdata(o);
2547 if (req_data->type == SIM_FACILITY_PS)
2549 else if (req_data->type == SIM_FACILITY_SC)
2551 else if (req_data->type == SIM_FACILITY_FD)
2553 else if (req_data->type == SIM_FACILITY_PN)
2555 else if (req_data->type == SIM_FACILITY_PU)
2557 else if (req_data->type == SIM_FACILITY_PP)
2559 else if (req_data->type == SIM_FACILITY_PC)
2562 return TCORE_RETURN_EINVAL;
2564 sp->current_sec_op = SEC_SIM_ENABLE;
2566 sec_meta.current_sec_op = req_data->type;
2567 sec_meta.metainfo.type = SINGLELINE;
2568 memcpy(sec_meta.metainfo.responsePrefix,"+CLCK:",strlen("+CLCK:"));
2569 info_len = sizeof(struct s_sim_property);
2570 tcore_user_request_set_command(ur, TREQ_CUSTOM);
2571 tcore_user_request_set_metainfo(ur, sizeof(struct s_sim_property), &sec_meta);
2573 // AT+CLCK=<fac>,<mode>,<password>
2574 cmd_str = g_strdup_printf("AT+CLCK=\"%s\", %d, %s%s", fac, mode, req_data->password,"\r");
2575 dbg("new pending(enable_facility), %s", cmd_str);
2577 pending = tcore_pending_new(o, ID_RESERVED_AT);
2578 tcore_pending_set_request_data(pending, strlen(cmd_str), cmd_str);
2579 tcore_pending_set_timeout(pending, 0);
2580 tcore_pending_set_priority(pending, TCORE_PENDING_PRIORITY_DEFAULT);
2581 tcore_pending_set_response_callback(pending, on_response_disable_facility, NULL);
2582 tcore_pending_link_user_request(pending, ur);
2584 tcore_pending_set_send_callback(pending, on_confirmation_sim_message_send, NULL);
2586 tcore_hal_send_request(h, pending);
2590 return TCORE_RETURN_SUCCESS;
2593 static TReturn s_read_file(CoreObject *o, UserRequest *ur)
2595 TReturn api_ret = TCORE_RETURN_SUCCESS;
2596 enum tcore_request_command command;
2597 command = tcore_user_request_get_command(ur);
2602 case TREQ_SIM_GET_ECC:
2603 api_ret = _get_file_info(o, ur, SIM_EF_ECC);
2606 case TREQ_SIM_GET_LANGUAGE:
2607 if (tcore_sim_get_type(o) == SIM_TYPE_GSM)
2608 api_ret = _get_file_info(o, ur, SIM_EF_ELP);
2609 else if (tcore_sim_get_type(o) == SIM_TYPE_USIM)
2610 api_ret = _get_file_info(o, ur, SIM_EF_LP);
2612 api_ret = TCORE_RETURN_ENOSYS;
2615 case TREQ_SIM_GET_ICCID:
2616 api_ret = _get_file_info(o, ur, SIM_EF_ICCID);
2619 case TREQ_SIM_GET_MAILBOX:
2620 if(tcore_sim_get_cphs_status(o))
2621 api_ret = _get_file_info(o, ur, SIM_EF_CPHS_MAILBOX_NUMBERS);
2623 api_ret = _get_file_info(o, ur, SIM_EF_MBDN);
2626 case TREQ_SIM_GET_CALLFORWARDING:
2627 if(tcore_sim_get_cphs_status(o))
2628 api_ret = _get_file_info(o, ur, SIM_EF_CPHS_CALL_FORWARD_FLAGS);
2630 api_ret = _get_file_info(o, ur, SIM_EF_USIM_CFIS);
2633 case TREQ_SIM_GET_MESSAGEWAITING:
2634 if(tcore_sim_get_cphs_status(o))
2635 api_ret = _get_file_info(o, ur, SIM_EF_CPHS_VOICE_MSG_WAITING);
2637 api_ret = _get_file_info(o, ur, SIM_EF_USIM_MWIS);
2640 case TREQ_SIM_GET_CPHS_INFO:
2641 if(tcore_sim_get_cphs_status(o))
2642 api_ret = _get_file_info(o, ur, SIM_EF_CPHS_CPHS_INFO);
2644 api_ret = TCORE_RETURN_ENOSYS;
2647 case TREQ_SIM_GET_MSISDN:
2648 api_ret = _get_file_info(o, ur, SIM_EF_MSISDN);
2651 case TREQ_SIM_GET_SPN:
2652 dbg("enter case SPN");
2653 api_ret = _get_file_info(o, ur, SIM_EF_SPN);
2656 case TREQ_SIM_GET_SPDI:
2657 api_ret = _get_file_info(o, ur, SIM_EF_SPDI);
2660 case TREQ_SIM_GET_OPL:
2661 api_ret = _get_file_info(o, ur, SIM_EF_OPL);
2664 case TREQ_SIM_GET_PNN:
2665 api_ret = _get_file_info(o, ur, SIM_EF_PNN);
2668 case TREQ_SIM_GET_CPHS_NETNAME:
2669 api_ret = TCORE_RETURN_ENOSYS;
2672 case TREQ_SIM_GET_OPLMNWACT:
2673 api_ret = _get_file_info(o, ur, SIM_EF_OPLMN_ACT);
2677 dbg("error - not handled read treq command[%d]", command);
2678 api_ret = TCORE_RETURN_EINVAL;
2684 static TReturn s_update_file(CoreObject *o, UserRequest *ur)
2686 TReturn api_ret = TCORE_RETURN_ENOSYS;
2690 static TReturn s_transmit_apdu(CoreObject *o, UserRequest *ur)
2692 dbg("need to be implemented to use ATCMD");
2694 return TCORE_RETURN_SUCCESS;
2697 static TReturn s_get_atr(CoreObject *o, UserRequest *ur)
2699 dbg("need to be implemented to use ATCMD");
2701 return TCORE_RETURN_SUCCESS;
2704 static TReturn s_req_authentication(CoreObject *o, UserRequest *ur)
2706 return TCORE_RETURN_SUCCESS;
2709 static struct tcore_sim_operations sim_ops =
2711 .verify_pins = s_verify_pins,
2712 .verify_puks = s_verify_puks,
2713 .change_pins = s_change_pins,
2714 .get_facility_status = s_get_facility_status,
2715 .enable_facility = s_enable_facility,
2716 .disable_facility = s_disable_facility,
2717 .read_file = s_read_file,
2718 .update_file = s_update_file,
2719 .transmit_apdu = s_transmit_apdu,
2720 .get_atr = s_get_atr,
2721 .req_authentication = s_req_authentication
2724 gboolean s_sim_init(TcorePlugin *p, TcoreHal *h)
2727 struct s_sim_property *sp = NULL;
2729 o = tcore_sim_new(p, "sim", &sim_ops, h);
2733 sp = calloc(sizeof(struct s_sim_property),1);
2737 sp->first_recv_status = SIM_STATUS_UNKNOWN;
2738 tcore_sim_link_userdata(o, sp);
2740 tcore_object_add_callback(o, EVENT_SIM_PIN_STATUS, on_event_pin_status, NULL);
2745 void s_sim_exit(TcorePlugin *p)
2749 o = tcore_plugin_ref_core_object(p, "sim");