4 * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Ankit Jogi <ankit.jogi@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.
27 #include <core_object.h>
33 #include <user_request.h>
41 #define ID_RESERVED_AT 0x0229
43 #define SWAPBYTES16(x) \
45 unsigned short int data = *(unsigned short int *) &(x); \
46 data = ((data & 0xff00) >> 8) | \
47 ((data & 0x00ff) << 8); \
48 *(unsigned short int *) &(x) = data; \
51 enum s_sim_file_type_e {
52 SIM_FTYPE_DEDICATED = 0x00, /**< Dedicated */
53 SIM_FTYPE_TRANSPARENT = 0x01, /**< Transparent -binary type*/
54 SIM_FTYPE_LINEAR_FIXED = 0x02, /**< Linear fixed - record type*/
55 SIM_FTYPE_CYCLIC = 0x04, /**< Cyclic - record type*/
56 SIM_FTYPE_INVALID_TYPE = 0xFF /**< Invalid type */
71 SEC_PIN2_DISABLE, // 10
92 SEC_SIM_UNKNOWN = 0xff
95 struct s_sim_property {
96 gboolean b_valid; /**< Valid or not */
97 enum tel_sim_file_id file_id; /**< File identifier */
98 enum s_sim_file_type_e file_type; /**< File type and structure */
99 int rec_length; /**< Length of one record in file */
100 int rec_count; /**< Number of records in file */
101 int data_size; /**< File size */
102 int current_index; /**< current index to read */
103 enum s_sim_sec_op_e current_sec_op; /**< current index to read */
104 struct tel_sim_mbi_list mbi_list;
105 struct tel_sim_mb_number mb_list[SIM_MSP_CNT_MAX*5];
106 struct tresp_sim_read files;
109 static void _next_from_get_file_info(CoreObject *o, UserRequest *ur, enum tel_sim_file_id ef, enum tel_sim_access_result rt);
110 static void _next_from_get_file_data(CoreObject *o, UserRequest *ur, enum tel_sim_access_result rt, int decode_ret);
111 static gboolean _get_sim_type(CoreObject *o);
112 static TReturn _get_file_info(CoreObject *o, UserRequest *ur, const enum tel_sim_file_id ef);
113 static gboolean _get_file_data(CoreObject *o, UserRequest *ur, const enum tel_sim_file_id ef, const int offset, const int length);
114 static gboolean _get_file_record(CoreObject *o, UserRequest *ur, const enum tel_sim_file_id ef, const int index, const int length);
115 static void _sim_status_update(CoreObject *o, enum tel_sim_status sim_status);
116 extern gboolean util_byte_to_hex(const char *byte_pdu, char *hex_pdu, int num_bytes);
118 static void sim_prepare_and_send_pending_request(CoreObject *co, const char *at_cmd, const char *prefix, enum tcore_at_command_type at_cmd_type, TcorePendingResponseCallback callback)
120 TcoreATRequest *req = NULL;
121 TcoreHal *hal = NULL;
122 TcorePending *pending = NULL;
126 hal = tcore_object_get_hal(co);
129 pending = tcore_pending_new(co, 0);
131 dbg("Pending is NULL");
132 req = tcore_at_request_new(at_cmd, prefix, at_cmd_type);
134 dbg("cmd : %s, prefix(if any) :%s, cmd_len : %d", req->cmd, req->prefix, strlen(req->cmd));
136 tcore_pending_set_request_data(pending, 0, req);
137 tcore_pending_set_response_callback(pending, callback, NULL);
138 tcore_pending_link_user_request(pending, NULL); // set user request to NULL - this is internal request
139 ret = tcore_hal_send_request(hal, pending);
144 static enum tcore_response_command _find_resp_command(UserRequest *ur)
146 enum tcore_request_command command;
148 command = tcore_user_request_get_command(ur);
150 case TREQ_SIM_VERIFY_PINS:
151 return TRESP_SIM_VERIFY_PINS;
154 case TREQ_SIM_VERIFY_PUKS:
155 return TRESP_SIM_VERIFY_PUKS;
158 case TREQ_SIM_CHANGE_PINS:
159 return TRESP_SIM_CHANGE_PINS;
162 case TREQ_SIM_GET_FACILITY_STATUS:
163 return TRESP_SIM_GET_FACILITY_STATUS;
166 case TREQ_SIM_DISABLE_FACILITY:
167 return TRESP_SIM_DISABLE_FACILITY;
170 case TREQ_SIM_ENABLE_FACILITY:
171 return TRESP_SIM_ENABLE_FACILITY;
174 case TREQ_SIM_GET_LOCK_INFO:
175 return TRESP_SIM_GET_LOCK_INFO;
178 case TREQ_SIM_TRANSMIT_APDU:
179 return TRESP_SIM_TRANSMIT_APDU;
182 case TREQ_SIM_GET_ATR:
183 return TRESP_SIM_GET_ATR;
186 case TREQ_SIM_GET_ECC:
187 return TRESP_SIM_GET_ECC;
190 case TREQ_SIM_GET_LANGUAGE:
191 return TRESP_SIM_GET_LANGUAGE;
194 case TREQ_SIM_SET_LANGUAGE:
195 return TRESP_SIM_SET_LANGUAGE;
198 case TREQ_SIM_GET_ICCID:
199 return TRESP_SIM_GET_ICCID;
202 case TREQ_SIM_GET_MAILBOX:
203 return TRESP_SIM_GET_MAILBOX;
206 case TREQ_SIM_GET_CALLFORWARDING:
207 return TRESP_SIM_GET_CALLFORWARDING;
210 case TREQ_SIM_SET_CALLFORWARDING:
211 return TRESP_SIM_SET_CALLFORWARDING;
214 case TREQ_SIM_GET_MESSAGEWAITING:
215 return TRESP_SIM_GET_MESSAGEWAITING;
218 case TREQ_SIM_GET_CPHS_INFO:
219 return TRESP_SIM_GET_CPHS_INFO;
222 case TREQ_SIM_GET_MSISDN:
223 return TRESP_SIM_GET_MSISDN;
226 case TREQ_SIM_GET_SPN:
227 return TRESP_SIM_GET_SPN;
230 case TREQ_SIM_GET_SPDI:
231 return TRESP_SIM_GET_SPDI;
234 case TREQ_SIM_GET_OPL:
235 return TRESP_SIM_GET_OPL;
238 case TREQ_SIM_GET_PNN:
239 return TRESP_SIM_GET_PNN;
242 case TREQ_SIM_GET_CPHS_NETNAME:
243 return TRESP_SIM_GET_CPHS_NETNAME;
246 case TREQ_SIM_GET_OPLMNWACT:
247 return TRESP_SIM_GET_OPLMNWACT;
250 case TREQ_SIM_REQ_AUTHENTICATION:
251 return TRESP_SIM_REQ_AUTHENTICATION;
257 return TRESP_UNKNOWN;
260 static int _sim_get_current_pin_facility(enum s_sim_sec_op_e op)
264 dbg("current sec_op[%d]", op);
267 case SEC_PIN1_VERIFY:
268 case SEC_PIN1_CHANGE:
269 ret_type = SIM_PTYPE_PIN1;
272 case SEC_PIN2_VERIFY:
273 case SEC_PIN2_CHANGE:
274 ret_type = SIM_PTYPE_PIN2;
277 case SEC_PUK1_VERIFY:
278 ret_type = SIM_PTYPE_PUK1;
281 case SEC_PUK2_VERIFY:
282 ret_type = SIM_PTYPE_PUK2;
286 ret_type = SIM_PTYPE_SIM;
290 ret_type = SIM_PTYPE_ADM;
293 case SEC_PIN1_ENABLE:
294 case SEC_PIN1_DISABLE:
295 case SEC_PIN1_STATUS:
296 ret_type = SIM_FACILITY_SC;
300 case SEC_SIM_DISABLE:
302 ret_type = SIM_FACILITY_PS;
306 case SEC_NET_DISABLE:
308 ret_type = SIM_FACILITY_PN;
314 ret_type = SIM_FACILITY_PU;
320 ret_type = SIM_FACILITY_PP;
326 ret_type = SIM_FACILITY_PC;
330 case SEC_FDN_DISABLE:
332 ret_type = SIM_FACILITY_FD;
336 dbg("not handled current sec op[%d]", op)
342 static enum tel_sim_access_result _decode_status_word(unsigned short status_word1, unsigned short status_word2)
344 enum tel_sim_access_result rst = SIM_ACCESS_FAILED;
346 if (status_word1 == 0x93 && status_word2 == 0x00) {
347 rst = SIM_ACCESS_FAILED;
348 /*Failed SIM request command*/
349 dbg(" error - SIM application toolkit busy [%x][%x]", status_word1, status_word2);
350 } else if (status_word1 == 0x94 && status_word2 == 0x00) {
351 rst = SIM_ACCESS_FAILED;
352 /*Failed SIM request command*/
353 dbg(" error - No EF Selected [%x][%x]", status_word1, status_word2);
354 } else if (status_word1 == 0x94 && status_word2 == 0x02) {
355 rst = SIM_ACCESS_FAILED;
356 /*Failed SIM request command*/
357 dbg("error - Out of Range - Invalid address or record number[%x][%x]",
358 status_word1, status_word2);
359 } else if (status_word1 == 0x94 && status_word2 == 0x04) {
360 rst = SIM_ACCESS_FILE_NOT_FOUND;
361 /*Failed SIM request command*/
362 dbg(" error - File ID not found [%x][%x]", status_word1, status_word2);
363 } else if (status_word1 == 0x94 && status_word2 == 0x08) {
364 rst = SIM_ACCESS_FAILED; /* MOdem not support */
365 /*Failed SIM request command*/
366 dbg(" error - File is inconsistent with command - Modem not support or USE IPC [%x][%x]",
367 status_word1, status_word2);
368 } else if (status_word1 == 0x98 && status_word2 == 0x02) {
369 rst = SIM_ACCESS_CONDITION_NOT_SATISFIED;
370 /*Failed SIM request command*/
371 dbg(" error - CHV not initialized [%x][%x]", status_word1, status_word2);
372 } else if (status_word1 == 0x98 && status_word2 == 0x04) {
373 rst = SIM_ACCESS_CONDITION_NOT_SATISFIED;
374 /*Failed SIM request command*/
375 dbg(" error - Access condition not fullfilled [%x][%x]", status_word1, status_word2);
376 dbg(" error -Unsuccessful CHV verification - at least one attempt left [%x][%x]",
377 status_word1, status_word2);
378 dbg(" error - Unsuccessful Unblock CHV - at least one attempt left [%x][%x]",
379 status_word1, status_word2);
380 dbg(" error - Authentication failure [%x][%x]", status_word1, status_word2);
381 } else if (status_word1 == 0x98 && status_word2 == 0x08) {
382 rst = SIM_ACCESS_CONDITION_NOT_SATISFIED;
383 /*Failed SIM request command*/
384 dbg(" error - Contradiction with CHV status [%x][%x]", status_word1, status_word2);
385 } else if (status_word1 == 0x98 && status_word2 == 0x10) {
386 rst = SIM_ACCESS_CONDITION_NOT_SATISFIED;
387 /*Failed SIM request command*/
388 dbg(" error - Contradiction with invalidation status [%x][%x]",
389 status_word1, status_word2);
390 } else if (status_word1 == 0x98 && status_word2 == 0x40) {
391 rst = SIM_ACCESS_CONDITION_NOT_SATISFIED;
392 /*Failed SIM request command*/
393 dbg(" error -Unsuccessful CHV verification - no attempt left [%x][%x]",
394 status_word1, status_word2);
395 dbg(" error - Unsuccessful Unblock CHV - no attempt left [%x][%x]",
396 status_word1, status_word2);
397 dbg(" error - CHV blocked [%x][%x]", status_word1, status_word2);
398 } else if (status_word1 == 0x67 && status_word2 == 0x00) {
399 rst = SIM_ACCESS_FAILED;
400 dbg(" error -Incorrect Parameter 3 [%x][%x]", status_word1, status_word2);
401 } else if (status_word1 == 0x6B && status_word2 == 0x00) {
402 rst = SIM_ACCESS_FAILED;
403 dbg(" error -Incorrect Parameter 1 or 2 [%x][%x]", status_word1, status_word2);
404 } else if (status_word1 == 0x6D && status_word2 == 0x00) {
405 rst = SIM_ACCESS_CONDITION_NOT_SATISFIED;
406 dbg(" error -Unknown instruction given as command [%x][%x]", status_word1, status_word2);
407 } else if (status_word1 == 0x6E && status_word2 == 0x00) {
408 rst = SIM_ACCESS_CONDITION_NOT_SATISFIED;
409 dbg(" error -Unknown instruction given as command [%x][%x]", status_word1, status_word2);
410 } else if (status_word1 == 0x69 && status_word2 == 0x82) {
411 rst = SIM_ACCESS_CONDITION_NOT_SATISFIED;
412 dbg(" error -Access denied [%x][%x]", status_word1, status_word2);
413 } else if (status_word1 == 0x6A && status_word2 == 0x87) {
414 rst = SIM_ACCESS_FAILED;
415 dbg(" error -Incorrect parameters [%x][%x]", status_word1, status_word2);
416 } else if (status_word1 == 0x6A && status_word2 == 0x82) {
417 rst = SIM_ACCESS_FILE_NOT_FOUND; // not sure of the SW1 and SW2 meaning here
418 dbg(" error -File Not found [%x][%x]", status_word1, status_word2);
419 } else if (status_word1 == 0x6A && status_word2 == 0x83) {
420 rst = SIM_ACCESS_FILE_NOT_FOUND; // not sure of the SW1 and SW2 meaning here
421 dbg(" error -Record Not found [%x][%x]", status_word1, status_word2);
423 rst = SIM_ACCESS_CARD_ERROR;
424 dbg(" error -Unknown state [%x][%x]", status_word1, status_word2);
429 static gboolean _sim_check_identity(CoreObject *o, struct tel_sim_imsi *imsi)
432 Storage *strg = NULL;
433 char *old_imsi = NULL;
434 char new_imsi[15 + 1] = {0, };
436 s = tcore_plugin_ref_server(tcore_object_ref_plugin(o));
438 dbg("there is no valid server at this point");
441 strg = (Storage *) tcore_server_find_storage(s, "vconf");
443 dbg("there is no valid storage plugin");
446 memcpy(&new_imsi, imsi->plmn, strlen(imsi->plmn));
447 memcpy(&new_imsi[strlen(imsi->plmn)], imsi->msin, strlen(imsi->msin));
448 new_imsi[strlen(imsi->plmn) + strlen(imsi->msin)] = '\0';
450 old_imsi = tcore_storage_get_string(strg, STORAGE_KEY_TELEPHONY_IMSI);
451 dbg("old_imsi[%s],newImsi[%s]", old_imsi, new_imsi);
453 if (old_imsi != NULL) {
454 if (strncmp(old_imsi, new_imsi, 15) != 0) {
456 if (tcore_storage_set_string(strg, STORAGE_KEY_TELEPHONY_IMSI, (const char *) &new_imsi) == FALSE) {
457 dbg("[FAIL] UPDATE STORAGE_KEY_TELEPHONY_IMSI");
459 tcore_sim_set_identification(o, TRUE);
462 tcore_sim_set_identification(o, FALSE);
465 dbg("OLD SIM VALUE IS NULL. NEW SIM");
466 if (tcore_storage_set_string(strg, STORAGE_KEY_TELEPHONY_IMSI, (const char *) &new_imsi) == FALSE) {
467 dbg("[FAIL] UPDATE STORAGE_KEY_TELEPHONY_IMSI");
469 tcore_sim_set_identification(o, TRUE);
474 static void _next_from_get_file_info(CoreObject *o, UserRequest *ur, enum tel_sim_file_id ef, enum tel_sim_access_result rt)
476 struct tresp_sim_read resp = {0, };
477 struct s_sim_property *file_meta = NULL;
479 dbg("EF[0x%x] access Result[%d]", ef, rt);
482 memset(&resp.data, 0x00, sizeof(resp.data));
483 file_meta = (struct s_sim_property *) tcore_user_request_ref_metainfo(ur, NULL);
485 if ((ef != SIM_EF_ELP && ef != SIM_EF_LP && ef != SIM_EF_USIM_PL && ef != SIM_EF_CPHS_CPHS_INFO)
486 && (rt != SIM_ACCESS_SUCCESS)) {
487 tcore_user_request_send_response(ur, _find_resp_command(ur), sizeof(struct tresp_sim_read), &resp);
493 if (rt == SIM_ACCESS_SUCCESS) {
494 dbg("[SIM DATA] exist EFELP/PL(0x2F05)");
495 /* if (po->language_file == 0x00)
496 po->language_file = SIM_EF_ELP;*/
497 _get_file_data(o, ur, ef, 0, file_meta->data_size);
499 if (tcore_sim_get_type(o) == SIM_TYPE_GSM) {
500 dbg(" [SIM DATA]SIM_EF_ELP(2F05) access fail. Request SIM_EF_LP(0x6F05) info");
501 /* The ME requests the Language Preference (EFLP) if EFELP is not available */
502 _get_file_info(o, ur, SIM_EF_LP);
503 } else if (tcore_sim_get_type(o) == SIM_TYPE_USIM) {
505 " [SIM DATA]fail to get Language information in USIM(EF-LI(6F05),EF-PL(2F05)). Request SIM_EF_ECC(0x6FB7) info");
506 /* EFELPand EFLI not present at this point. */
507 /* po->language.lang_cnt = 0;*/
508 tcore_user_request_send_response(ur, _find_resp_command(ur),
509 sizeof(struct tresp_sim_read), &resp);
515 case SIM_EF_LP: // same with SIM_EF_USIM_LI
516 if (rt == SIM_ACCESS_SUCCESS) {
517 dbg("[SIM DATA] exist EFLP/LI(0x6F05)");
518 _get_file_data(o, ur, ef, 0, file_meta->data_size);
520 dbg("[SIM DATA]SIM_EF_LP/LI(6F05) access fail. Current CardType[%d]",
521 tcore_sim_get_type(o));
522 if (tcore_sim_get_type(o) == SIM_TYPE_GSM) {
523 tcore_user_request_send_response(ur, _find_resp_command(ur),
524 sizeof(struct tresp_sim_read), &resp);
527 /* if EFLI is not present, then the language selection shall be as defined in EFPL at the MF level */
528 else if (tcore_sim_get_type(o) == SIM_TYPE_USIM) {
529 dbg("[SIM DATA] try USIM EFPL(0x2F05)");
530 _get_file_info(o, ur, SIM_EF_ELP);
536 if (rt == SIM_ACCESS_SUCCESS) {
537 dbg("[SIM DATA] exist EFELP/PL(0x2F05)");
538 _get_file_data(o, ur, SIM_EF_ELP, 0, file_meta->data_size);
540 /* EFELIand EFPL not present, so set language count as zero and select ECC */
542 " [SIM DATA]SIM_EF_USIM_PL(2A05) access fail. Request SIM_EF_ECC(0x6FB7) info");
543 tcore_user_request_send_response(ur, _find_resp_command(ur),
544 sizeof(struct tresp_sim_read), &resp);
550 if (tcore_sim_get_type(o) == SIM_TYPE_GSM) {
551 _get_file_data(o, ur, ef, 0, file_meta->data_size);
552 } else if (tcore_sim_get_type(o) == SIM_TYPE_USIM) {
553 if (file_meta->rec_count > SIM_ECC_RECORD_CNT_MAX) {
554 file_meta->rec_count = SIM_ECC_RECORD_CNT_MAX;
557 file_meta->current_index++;
558 _get_file_record(o, ur, ef, file_meta->current_index, file_meta->rec_length);
567 case SIM_EF_CPHS_CALL_FORWARD_FLAGS:
568 case SIM_EF_CPHS_VOICE_MSG_WAITING:
569 case SIM_EF_CPHS_OPERATOR_NAME_STRING:
570 case SIM_EF_CPHS_OPERATOR_NAME_SHORT_FORM_STRING:
571 case SIM_EF_CPHS_DYNAMICFLAGS:
572 case SIM_EF_CPHS_DYNAMIC2FLAG:
573 case SIM_EF_CPHS_CUSTOMER_SERVICE_PROFILE:
574 case SIM_EF_CPHS_CUSTOMER_SERVICE_PROFILE_LINE2:
575 _get_file_data(o, ur, ef, 0, file_meta->data_size);
578 case SIM_EF_CPHS_CPHS_INFO:
579 if (rt == SIM_ACCESS_SUCCESS) {
580 tcore_sim_set_cphs_status(o, TRUE);
581 if (!tcore_user_request_ref_communicator(ur)) {
582 dbg("internal CPHS INFO request before sim status update");
583 _sim_status_update(o, SIM_STATUS_INIT_COMPLETED);
585 dbg("external CPHS INFO request");
586 _get_file_data(o, ur, ef, 0, file_meta->data_size);
589 tcore_sim_set_cphs_status(o, FALSE);
590 if (!tcore_user_request_ref_communicator(ur)) {
591 dbg("internal CPHS INFO request before sim status update");
592 _sim_status_update(o, SIM_STATUS_INIT_COMPLETED);
594 dbg("external CPHS INFO request");
595 tcore_user_request_send_response(ur, _find_resp_command(ur),
596 sizeof(struct tresp_sim_read), &resp);
602 case SIM_EF_USIM_CFIS:
603 if (file_meta->rec_count > SIM_CF_RECORD_CNT_MAX) {
604 file_meta->rec_count = SIM_CF_RECORD_CNT_MAX;
606 file_meta->current_index++;
607 _get_file_record(o, ur, ef, file_meta->current_index, file_meta->rec_length);
612 case SIM_EF_USIM_MWIS:
613 case SIM_EF_USIM_MBI:
615 case SIM_EF_CPHS_MAILBOX_NUMBERS:
616 case SIM_EF_CPHS_INFORMATION_NUMBERS:
618 file_meta->current_index++;
619 _get_file_record(o, ur, ef, file_meta->current_index, file_meta->rec_length);
623 dbg("error - File id for get file info [0x%x]", ef);
629 static void _next_from_get_file_data(CoreObject *o, UserRequest *ur, enum tel_sim_access_result rt, int decode_ret)
631 struct s_sim_property *file_meta = NULL;
635 file_meta = (struct s_sim_property *) tcore_user_request_ref_metainfo(ur, NULL);
636 dbg("[SIM]EF[0x%x] read rt[%d] Decode rt[%d]", file_meta->file_id, rt, decode_ret);
637 switch (file_meta->file_id) {
642 if (decode_ret == TRUE) {
643 if (file_meta->file_id == SIM_EF_LP || file_meta->file_id == SIM_EF_USIM_LI) {
644 /* po->language_file = SIM_EF_LP;*/
645 } else if (file_meta->file_id == SIM_EF_ELP || file_meta->file_id == SIM_EF_USIM_PL) {
646 /* po->language_file = SIM_EF_ELP;*/
648 tcore_user_request_send_response(ur, _find_resp_command(ur), sizeof(struct tresp_sim_read), &file_meta->files);
651 /* The ME requests the Extended Language Preference. The ME only requests the Language Preference (EFLP) if at least one of the following conditions holds:
652 - EFELP is not available;
653 - EFELP does not contain an entry corresponding to a language specified in ISO 639[30];
654 - the ME does not support any of the languages in EFELP.
657 /* The ME only requests the Language Preference (EFPL) if at least one of the following conditions holds:
658 - if the EFLI has the value 'FFFF' in its highest priority position
659 - if the ME does not support any of the language codes indicated in EFLI , or if EFLI is not present
661 if (tcore_sim_get_type(o) == SIM_TYPE_GSM) {
662 if (file_meta->file_id == SIM_EF_LP) {
663 tcore_user_request_send_response(ur, _find_resp_command(ur), sizeof(struct tresp_sim_read), &file_meta->files);
665 _get_file_info(o, ur, SIM_EF_LP);
667 } else if (tcore_sim_get_type(o) == SIM_TYPE_USIM) {
668 if (file_meta->file_id == SIM_EF_LP || file_meta->file_id == SIM_EF_USIM_LI) {
669 _get_file_info(o, ur, SIM_EF_ELP);
671 tcore_user_request_send_response(ur, _find_resp_command(ur), sizeof(struct tresp_sim_read), &file_meta->files);
678 if (tcore_sim_get_type(o) == SIM_TYPE_USIM) {
679 if (file_meta->current_index == file_meta->rec_count) {
680 tcore_user_request_send_response(ur, _find_resp_command(ur), sizeof(struct tresp_sim_read), &file_meta->files);
682 file_meta->current_index++;
683 _get_file_record(o, ur, file_meta->file_id, file_meta->current_index, file_meta->rec_length);
685 } else if (tcore_sim_get_type(o) == SIM_TYPE_GSM) {
686 tcore_user_request_send_response(ur, _find_resp_command(ur), sizeof(struct tresp_sim_read), &file_meta->files);
688 dbg("[SIM DATA]Invalid CardType[%d] Unable to handle", tcore_sim_get_type(o));
693 ur = tcore_user_request_new(NULL, NULL); // this is for using ur metainfo set/ref functionality.
694 _get_file_info(o, ur, SIM_EF_CPHS_CPHS_INFO);
698 if (file_meta->current_index == file_meta->rec_count) {
699 tcore_user_request_send_response(ur, _find_resp_command(ur), sizeof(struct tresp_sim_read), &file_meta->files);
701 file_meta->current_index++;
702 _get_file_record(o, ur, file_meta->file_id, file_meta->current_index, file_meta->rec_length);
707 if (file_meta->current_index == file_meta->rec_count) {
708 tcore_user_request_send_response(ur, _find_resp_command(ur), sizeof(struct tresp_sim_read), &file_meta->files);
710 file_meta->current_index++;
711 _get_file_record(o, ur, file_meta->file_id, file_meta->current_index, file_meta->rec_length);
716 if (file_meta->current_index == file_meta->rec_count) {
717 tcore_user_request_send_response(ur, _find_resp_command(ur), sizeof(struct tresp_sim_read), &file_meta->files);
719 file_meta->current_index++;
720 _get_file_record(o, ur, file_meta->file_id, file_meta->current_index, file_meta->rec_length);
724 case SIM_EF_USIM_CFIS:
725 case SIM_EF_USIM_MWIS:
726 case SIM_EF_USIM_MBI:
728 case SIM_EF_CPHS_MAILBOX_NUMBERS:
729 case SIM_EF_CPHS_INFORMATION_NUMBERS:
730 if (file_meta->current_index == file_meta->rec_count) {
731 tcore_user_request_send_response(ur, _find_resp_command(ur), sizeof(struct tresp_sim_read), &file_meta->files);
733 file_meta->current_index++;
734 _get_file_record(o, ur, file_meta->file_id, file_meta->current_index, file_meta->rec_length);
738 case SIM_EF_CPHS_OPERATOR_NAME_STRING:
739 file_meta->files.result = rt;
740 if (decode_ret == TRUE && rt == SIM_ACCESS_SUCCESS) {
741 memcpy(file_meta->files.data.cphs_net.full_name, file_meta->files.data.cphs_net.full_name, strlen((char *) file_meta->files.data.cphs_net.full_name));
743 _get_file_info(o, ur, SIM_EF_CPHS_OPERATOR_NAME_SHORT_FORM_STRING);
746 case SIM_EF_CPHS_OPERATOR_NAME_SHORT_FORM_STRING:
747 if (file_meta->files.result == SIM_ACCESS_SUCCESS || file_meta->files.result == SIM_ACCESS_SUCCESS) {
748 file_meta->files.result = SIM_ACCESS_SUCCESS;
750 if (strlen((char *) file_meta->files.data.cphs_net.full_name)) {
751 memcpy(&file_meta->files.data.cphs_net.full_name, &file_meta->files.data.cphs_net.full_name, strlen((char *) file_meta->files.data.cphs_net.full_name));
753 tcore_user_request_send_response(ur, _find_resp_command(ur), sizeof(struct tresp_sim_read), &file_meta->files);
760 case SIM_EF_OPLMN_ACT:
761 case SIM_EF_CPHS_CPHS_INFO:
762 case SIM_EF_CPHS_CALL_FORWARD_FLAGS:
763 case SIM_EF_CPHS_VOICE_MSG_WAITING:
764 case SIM_EF_CPHS_DYNAMICFLAGS:
765 case SIM_EF_CPHS_DYNAMIC2FLAG:
766 case SIM_EF_CPHS_CUSTOMER_SERVICE_PROFILE:
767 case SIM_EF_CPHS_CUSTOMER_SERVICE_PROFILE_LINE2:
768 tcore_user_request_send_response(ur, _find_resp_command(ur), sizeof(struct tresp_sim_read), &file_meta->files);
772 dbg("File id not handled [0x%x]", file_meta->file_id);
777 static void _sim_status_update(CoreObject *o, enum tel_sim_status sim_status)
779 struct tnoti_sim_status noti_data = {0, };
781 dbg("tcore_sim_set_status and send noti w/ [%d]", sim_status);
782 tcore_sim_set_status(o, sim_status);
783 noti_data.sim_status = sim_status;
784 tcore_server_send_notification(tcore_plugin_ref_server(tcore_object_ref_plugin(o)), o, TNOTI_SIM_STATUS,
785 sizeof(struct tnoti_sim_status), ¬i_data);
788 static void _response_get_sim_type(TcorePending *p, int data_len, const void *data, void *user_data)
790 const TcoreATResponse *resp = data;
791 UserRequest *ur = NULL;
792 CoreObject *co_sim = NULL;
793 struct s_sim_property *sp = NULL;
794 GSList *tokens = NULL;
795 enum tel_sim_type sim_type = SIM_TYPE_UNKNOWN;
799 dbg(" Function entry ");
801 co_sim = tcore_pending_ref_core_object(p);
802 sp = tcore_sim_ref_userdata(co_sim);
803 ur = tcore_pending_ref_user_request(p);
805 if (resp->success > 0) {
808 line = (const char *) resp->lines->data;
809 tokens = tcore_at_tok_new(line);
810 if (g_slist_length(tokens) != 1) {
811 msg("invalid message");
812 tcore_at_tok_free(tokens);
816 state = atoi(g_slist_nth_data(tokens, 0));
817 dbg("SIM Type is %d", state);
820 sim_type = SIM_TYPE_GSM;
821 } else if (state == 1) {
822 sim_type = SIM_TYPE_USIM;
824 sim_type = SIM_TYPE_UNKNOWN;
828 sim_type = SIM_TYPE_UNKNOWN;
831 tcore_sim_set_type(co_sim, sim_type);
833 if (sim_type != SIM_TYPE_UNKNOWN) {
834 /* set user request for using ur metainfo set/ref functionality */
835 ur = tcore_user_request_new(NULL, NULL);
836 _get_file_info(co_sim, ur, SIM_EF_IMSI);
839 tcore_at_tok_free(tokens);
840 dbg(" Function exit");
843 static void _response_get_file_info(TcorePending *p, int data_len, const void *data, void *user_data)
845 const TcoreATResponse *resp = data;
846 UserRequest *ur = NULL;
847 CoreObject *co_sim = NULL;
848 struct s_sim_property *file_meta = NULL;
849 GSList *tokens = NULL;
850 enum tel_sim_access_result rt;
851 const char *line = NULL;
855 dbg(" Function entry ");
857 co_sim = tcore_pending_ref_core_object(p);
858 ur = tcore_pending_ref_user_request(p);
859 file_meta = (struct s_sim_property *) tcore_user_request_ref_metainfo(ur, NULL);
861 if (resp->success > 0) {
864 line = (const char *) resp->lines->data;
865 tokens = tcore_at_tok_new(line);
866 if (g_slist_length(tokens) < 2) {
867 err("invalid message");
868 tcore_at_tok_free(tokens);
872 sw1 = atoi(g_slist_nth_data(tokens, 0));
873 sw2 = atoi(g_slist_nth_data(tokens, 1));
875 /*1. SIM access success case*/
876 if ((sw1 == 0x90 && sw2 == 0x00) || sw1 == 0x91) {
877 unsigned char tag_len = 0; /* 1 or 2 bytes ??? */
878 unsigned short record_len = 0;
879 char num_of_records = 0;
880 unsigned char file_id_len = 0;
881 unsigned short file_id = 0;
882 unsigned short file_size = 0;
883 unsigned short file_type = 0;
884 unsigned short arr_file_id = 0;
885 int arr_file_id_rec_num = 0;
887 /* handling only last 3 bits */
888 unsigned char file_type_tag = 0x07;
889 unsigned char *ptr_data;
893 char *recordData = NULL;
894 hexData = g_slist_nth_data(tokens, 2);
895 dbg("hexData: %s", hexData);
896 dbg("hexData: %s", hexData + 1);
898 tmp = util_removeQuotes(hexData);
899 recordData = util_hexStringToBytes(tmp);
900 util_hex_dump(" ", strlen(hexData) / 2, recordData);
903 ptr_data = (unsigned char *) recordData;
904 if (tcore_sim_get_type(co_sim) == SIM_TYPE_USIM) {
906 ETSI TS 102 221 v7.9.0
908 '62' FCP template tag
910 '82' M File Descriptor
911 '83' M File Identifier
912 'A5' O Proprietary information
913 '8A' M Life Cycle Status Integer
914 '8B', '8C' or 'AB' C1 Security attributes
916 '81' O Total file size
917 '88' O Short File Identifier (SFI)
920 /* rsim.res_len has complete data length received */
922 /* FCP template tag - File Control Parameters tag*/
923 if (*ptr_data == 0x62) {
924 /* parse complete FCP tag*/
925 /* increment to next byte */
927 tag_len = *ptr_data++;
928 dbg("tag_len: %02x", tag_len);
929 /* FCP file descriptor - file type, accessibility, DF, ADF etc*/
930 if (*ptr_data == 0x82) {
931 /* increment to next byte */
935 /* unsigned char file_desc_len = *ptr_data++;*/
936 /* dbg("file descriptor length: [%d]", file_desc_len);*/
937 /* TBD: currently capture only file type : ignore sharable, non sharable, working, internal etc*/
938 /* consider only last 3 bits*/
939 dbg("file_type_tag: %02x", file_type_tag);
940 file_type_tag = file_type_tag & (*ptr_data);
941 dbg("file_type_tag: %02x", file_type_tag);
943 switch (file_type_tag) {
944 /* increment to next byte */
947 dbg("Getting FileType: [Transparent file type]");
948 file_type = SIM_FTYPE_TRANSPARENT;
950 /* increment to next byte */
952 /* increment to next byte */
957 dbg("Getting FileType: [Linear fixed file type]");
958 /* increment to next byte */
960 /* data coding byte - value 21 */
963 memcpy(&record_len, ptr_data, 2);
965 SWAPBYTES16(record_len);
966 ptr_data = ptr_data + 2;
967 num_of_records = *ptr_data++;
968 /* Data lossy conversation from enum (int) to unsigned char */
969 file_type = SIM_FTYPE_LINEAR_FIXED;
973 dbg(" Cyclic fixed file type");
974 /* increment to next byte */
976 /* data coding byte - value 21 */
979 memcpy(&record_len, ptr_data, 2);
981 SWAPBYTES16(record_len);
982 ptr_data = ptr_data + 2;
983 num_of_records = *ptr_data++;
984 file_type = SIM_FTYPE_CYCLIC;
988 dbg("not handled file type [0x%x]", *ptr_data);
992 dbg("INVALID FCP received - DEbug!");
993 tcore_at_tok_free(tokens);
998 /*File identifier - file id?? */ // 0x84,0x85,0x86 etc are currently ignored and not handled
999 if (*ptr_data == 0x83) {
1000 /* increment to next byte */
1002 file_id_len = *ptr_data++;
1003 dbg("file_id_len: %02x", file_id_len);
1005 memcpy(&file_id, ptr_data, file_id_len);
1006 dbg("file_id: %x", file_id);
1009 SWAPBYTES16(file_id);
1010 dbg("file_id: %x", file_id);
1012 ptr_data = ptr_data + 2;
1013 dbg("Getting FileID=[0x%x]", file_id);
1015 dbg("INVALID FCP received - DEbug!");
1016 tcore_at_tok_free(tokens);
1021 /* proprietary information */
1022 if (*ptr_data == 0xA5) {
1023 unsigned short prop_len;
1024 /* increment to next byte */
1028 prop_len = *ptr_data;
1029 dbg("prop_len: %02x", prop_len);
1032 ptr_data = ptr_data + prop_len + 1;
1034 dbg("INVALID FCP received - DEbug!");
1037 /* life cycle status integer [8A][length:0x01][status]*/
1040 00000000 : No information given
1041 00000001 : creation state
1042 00000011 : initialization state
1043 000001-1 : operation state -activated
1044 000001-0 : operation state -deactivated
1045 000011-- : Termination state
1046 b8~b5 !=0, b4~b1=X : Proprietary
1047 Any other value : RFU
1049 if (*ptr_data == 0x8A) {
1050 /* increment to next byte */
1052 /* length - value 1 */
1055 switch (*ptr_data) {
1058 dbg("<RX> operation state -deactivated");
1064 dbg("<RX> operation state -activated");
1069 dbg("<RX> DEBUG! LIFE CYCLE STATUS =[0x%x]", *ptr_data);
1075 /* related to security attributes : currently not handled*/
1076 if (*ptr_data == 0x86 || *ptr_data == 0x8B || *ptr_data == 0x8C || *ptr_data == 0xAB) {
1077 /* increment to next byte */
1079 /* if tag length is 3 */
1080 if (*ptr_data == 0x03) {
1081 /* increment to next byte */
1084 memcpy(&arr_file_id, ptr_data, 2);
1086 SWAPBYTES16(arr_file_id);
1087 ptr_data = ptr_data + 2;
1088 arr_file_id_rec_num = *ptr_data++;
1090 /* if tag length is not 3 */
1091 /* ignoring bytes */
1092 // ptr_data = ptr_data + 4;
1093 dbg("Useless security attributes, so jump to next tag");
1094 ptr_data = ptr_data + (*ptr_data + 1);
1097 dbg("INVALID FCP received[0x%x] - DEbug!", *ptr_data);
1098 tcore_at_tok_free(tokens);
1103 dbg("Current ptr_data value is [%x]", *ptr_data);
1105 /* file size excluding structural info*/
1106 if (*ptr_data == 0x80) {
1107 /* for EF file size is body of file and for Linear or cyclic it is
1108 * number of recXsizeof(one record)
1110 /* increment to next byte */
1112 /* length is 1 byte - value is 2 bytes or more */
1114 memcpy(&file_size, ptr_data, 2);
1116 SWAPBYTES16(file_size);
1117 ptr_data = ptr_data + 2;
1119 dbg("INVALID FCP received - DEbug!");
1120 tcore_at_tok_free(tokens);
1125 /* total file size including structural info*/
1126 if (*ptr_data == 0x81) {
1128 /* increment to next byte */
1133 ptr_data = ptr_data + 3;
1135 dbg("INVALID FCP received - DEbug!");
1136 /* 0x81 is optional tag?? check out! so do not return -1 from here! */
1139 /*short file identifier ignored*/
1140 if (*ptr_data == 0x88) {
1141 dbg("0x88: Do Nothing");
1145 dbg("INVALID FCP received - DEbug!");
1146 tcore_at_tok_free(tokens);
1150 } else if (tcore_sim_get_type(co_sim) == SIM_TYPE_GSM) {
1151 unsigned char gsm_specific_file_data_len = 0;
1152 /* ignore RFU byte1 and byte2 */
1156 // file_size = p_info->response_len;
1157 memcpy(&file_size, ptr_data, 2);
1159 SWAPBYTES16(file_size);
1160 /* parsed file size */
1161 ptr_data = ptr_data + 2;
1163 memcpy(&file_id, ptr_data, 2);
1164 SWAPBYTES16(file_id);
1165 dbg(" FILE id --> [%x]", file_id);
1166 ptr_data = ptr_data + 2;
1167 /* save file type - transparent, linear fixed or cyclic */
1168 file_type_tag = (*(ptr_data + 7));
1170 switch (*ptr_data) {
1173 dbg(" RFU file type- not handled - Debug!");
1178 dbg(" MF file type - not handled - Debug!");
1183 dbg(" DF file type - not handled - Debug!");
1188 dbg(" EF file type [%d] ", file_type_tag);
1189 /* increment to next byte */
1192 if (file_type_tag == 0x00 || file_type_tag == 0x01) {
1193 /* increament to next byte as this byte is RFU */
1196 (file_type_tag == 0x00) ? SIM_FTYPE_TRANSPARENT : SIM_FTYPE_LINEAR_FIXED;
1198 /* increment to next byte */
1200 /* For a cyclic EF all bits except bit 7 are RFU; b7=1 indicates that */
1201 /* the INCREASE command is allowed on the selected cyclic file. */
1202 file_type = SIM_FTYPE_CYCLIC;
1204 /* bytes 9 to 11 give SIM file access conditions */
1206 /* byte 10 has one nibble that is RF U and another for INCREASE which is not used currently */
1208 /* byte 11 is invalidate and rehabilate nibbles */
1210 /* byte 12 - file status */
1212 /* byte 13 - GSM specific data */
1213 gsm_specific_file_data_len = *ptr_data;
1215 /* byte 14 - structure of EF - transparent or linear or cyclic , already saved above */
1217 /* byte 15 - length of record for linear and cyclic , for transparent it is set to 0x00. */
1218 record_len = *ptr_data;
1219 dbg("record length[%d], file size[%d]", record_len, file_size);
1221 if (record_len != 0)
1222 num_of_records = (file_size / record_len);
1224 dbg("Number of records [%d]", num_of_records);
1228 dbg(" not handled file type");
1232 dbg(" Card Type - UNKNOWN [%d]", tcore_sim_get_type(co_sim));
1235 dbg("req ef[0x%x] resp ef[0x%x] size[%ld] Type[0x%x] NumOfRecords[%ld] RecordLen[%ld]",
1236 file_meta->file_id, file_id, file_size, file_type, num_of_records, record_len);
1238 file_meta->file_type = file_type;
1239 file_meta->data_size = file_size;
1240 file_meta->rec_length = record_len;
1241 file_meta->rec_count = num_of_records;
1242 file_meta->current_index = 0; // reset for new record type EF
1243 rt = SIM_ACCESS_SUCCESS;
1246 /*2. SIM access fail case*/
1247 dbg("error to get ef[0x%x]", file_meta->file_id);
1248 dbg("error to get ef[0x%x] (file_meta->file_id) ", file_meta->file_id);
1249 rt = _decode_status_word(sw1, sw2);
1251 ur = tcore_user_request_ref(ur);
1253 dbg("Calling _next_from_get_file_info");
1254 _next_from_get_file_info(co_sim, ur, file_meta->file_id, rt);
1255 tcore_at_tok_free(tokens);
1257 dbg("RESPONSE NOK");
1258 dbg("error to get ef[0x%x]", file_meta->file_id);
1259 dbg("error to get ef[0x%x] (file_meta->file_id) ", file_meta->file_id);
1260 rt = SIM_ACCESS_FAILED;
1262 ur = tcore_user_request_ref(ur);
1263 _next_from_get_file_info(co_sim, ur, file_meta->file_id, rt);
1265 dbg(" Function exit");
1268 static void _response_get_file_data(TcorePending *p, int data_len, const void *data, void *user_data)
1270 const TcoreATResponse *resp = data;
1271 UserRequest *ur = NULL;
1272 CoreObject *co_sim = NULL;
1273 struct s_sim_property *file_meta = NULL;
1274 GSList *tokens = NULL;
1275 enum tel_sim_access_result rt;
1276 struct tel_sim_imsi *imsi = NULL;
1277 struct tel_sim_service_table *svct = NULL;
1278 struct tel_sim_ecc *ecc = NULL;
1279 struct tel_sim_msisdn *msisdn = NULL;
1280 struct tel_sim_opl *opl = NULL;
1281 struct tel_sim_pnn *pnn = NULL;
1282 struct tel_sim_cfis *cf = NULL;
1283 struct tel_sim_mbi *mbi = NULL;
1284 struct tel_sim_mw *mw = NULL;
1285 gboolean dr = FALSE;
1286 const char *line = NULL;
1293 dbg(" Function entry ");
1295 co_sim = tcore_pending_ref_core_object(p);
1296 ur = tcore_pending_ref_user_request(p);
1297 file_meta = (struct s_sim_property *) tcore_user_request_ref_metainfo(ur, NULL);
1299 if (resp->success > 0) {
1302 line = (const char *) resp->lines->data;
1303 tokens = tcore_at_tok_new(line);
1304 if (g_slist_length(tokens) != 3) {
1305 msg("invalid message");
1306 tcore_at_tok_free(tokens);
1310 sw1 = atoi(g_slist_nth_data(tokens, 0));
1311 sw2 = atoi(g_slist_nth_data(tokens, 1));
1312 res = g_slist_nth_data(tokens, 2);
1314 tmp = util_removeQuotes(res);
1315 res = util_hexStringToBytes(tmp);
1316 res_len = strlen((const char *) res);
1317 dbg("res: %s res_len: %d", res, res_len);
1319 if ((sw1 == 0x90 && sw2 == 0x00) || sw1 == 0x91) {
1320 rt = SIM_ACCESS_SUCCESS;
1321 file_meta->files.result = rt;
1322 dbg("file_meta->file_id : %x", file_meta->file_id);
1324 switch (file_meta->file_id) {
1327 dbg("res: %s", res);
1328 imsi = calloc(sizeof(struct tel_sim_imsi),1);
1329 dr = tcore_sim_decode_imsi(imsi, (unsigned char *) res, res_len);
1331 dbg("imsi decoding failed");
1333 _sim_check_identity(co_sim, imsi);
1334 tcore_sim_set_imsi(co_sim, imsi);
1342 dr = tcore_sim_decode_iccid(&file_meta->files.data.iccid, (unsigned char *) res, res_len);
1345 case SIM_EF_ELP: /* 2G EF - 2 bytes decoding*/
1346 case SIM_EF_USIM_LI: /* 3G EF - 2 bytes decoding*/
1347 case SIM_EF_USIM_PL: /* 3G EF - same as EFELP, so 2 byte decoding*/
1348 case SIM_EF_LP: /* 1 byte encoding*/
1349 if (tcore_sim_get_type(co_sim) == SIM_TYPE_GSM && file_meta->file_id == SIM_EF_LP) {
1350 /*2G LP(0x6F05) has 1 byte for each language*/
1351 dr = tcore_sim_decode_lp(&file_meta->files.data.language, (unsigned char *) res, res_len);
1353 /*3G LI(0x6F05)/PL(0x2F05), 2G ELP(0x2F05) has 2 bytes for each language*/
1354 dr = tcore_sim_decode_li(file_meta->file_id, &file_meta->files.data.language, (unsigned char *) res, res_len);
1359 dr = tcore_sim_decode_spn(&file_meta->files.data.spn, (unsigned char *) res, res_len);
1363 dr = tcore_sim_decode_spdi(&file_meta->files.data.spdi, (unsigned char *) res, res_len);
1366 case SIM_EF_SST: //EF UST has same address
1367 svct = calloc(sizeof(struct tel_sim_service_table),1);
1368 if(tcore_sim_get_type(co_sim) == SIM_TYPE_GSM) {
1369 dr = tcore_sim_decode_sst(&svct->sst , (unsigned char *) res, res_len);
1370 }else if(tcore_sim_get_type(co_sim) == SIM_TYPE_USIM) {
1371 dr = tcore_sim_decode_ust(&svct->ust , (unsigned char *) res, res_len);
1373 dbg("err not handled tcore_sim_get_type(o)[%d] in here",tcore_sim_get_type(co_sim));
1376 dbg("SST/UST decoding failed");
1378 tcore_sim_set_service_table(co_sim, svct);
1385 if (tcore_sim_get_type(co_sim) == SIM_TYPE_GSM) {
1386 dr = tcore_sim_decode_ecc(&file_meta->files.data.ecc, (unsigned char *) res, res_len);
1387 } else if (tcore_sim_get_type(co_sim) == SIM_TYPE_USIM) {
1388 ecc = calloc(sizeof(struct tel_sim_ecc),1);
1389 dbg("decode w/ index [%d]", file_meta->current_index);
1390 dr = tcore_sim_decode_uecc(ecc, (unsigned char *) res, res_len);
1392 memcpy(&file_meta->files.data.ecc.ecc[file_meta->files.data.ecc.ecc_count], ecc, sizeof(struct tel_sim_ecc));
1393 file_meta->files.data.ecc.ecc_count++;
1398 dbg("err not handled tcore_sim_get_type(o)[%d] in here", tcore_sim_get_type(co_sim));
1403 dbg("decode w/ index [%d]", file_meta->current_index);
1404 msisdn = calloc(sizeof(struct tel_sim_msisdn),1);
1405 dr = tcore_sim_decode_msisdn(msisdn, (unsigned char *) res, res_len);
1407 memcpy(&file_meta->files.data.msisdn_list.msisdn[file_meta->files.data.msisdn_list.count], msisdn, sizeof(struct tel_sim_msisdn));
1408 file_meta->files.data.msisdn_list.count++;
1415 dbg("decode w/ index [%d]", file_meta->current_index);
1416 opl = calloc(sizeof(struct tel_sim_opl),1);
1417 dr = tcore_sim_decode_opl(opl, (unsigned char *) res, res_len);
1419 memcpy(&file_meta->files.data.opl.opl[file_meta->files.data.opl.opl_count], opl, sizeof(struct tel_sim_opl));
1420 file_meta->files.data.opl.opl_count++;
1425 dbg("decode w/ index [%d]", file_meta->current_index);
1426 pnn = calloc(sizeof(struct tel_sim_pnn),1);
1427 dr = tcore_sim_decode_pnn(pnn, (unsigned char *) res, res_len);
1429 memcpy(&file_meta->files.data.pnn.pnn[file_meta->files.data.pnn.pnn_count], pnn, sizeof(struct tel_sim_pnn));
1430 file_meta->files.data.pnn.pnn_count++;
1436 case SIM_EF_OPLMN_ACT:
1437 dr = tcore_sim_decode_oplmnwact(&file_meta->files.data.opwa, (unsigned char *) res, res_len);
1440 case SIM_EF_CPHS_CUSTOMER_SERVICE_PROFILE:
1441 /* dr = tcore_sim_decode_csp(&po->p_cphs->csp, p_data->response, p_data->response_len);*/
1444 case SIM_EF_USIM_MBI: //linear type
1445 mbi = calloc(sizeof(struct tel_sim_mbi),1);
1446 dr = tcore_sim_decode_mbi(mbi, (unsigned char *) res, res_len);
1448 memcpy( &file_meta->mbi_list.mbi[file_meta->mbi_list.profile_count], mbi, sizeof(struct tel_sim_mbi) );
1449 file_meta->mbi_list.profile_count++;
1450 dbg("mbi count[%d]", file_meta->mbi_list.profile_count);
1451 dbg("voice_index[%d]", file_meta->mbi_list.mbi[file_meta->mbi_list.profile_count -1].voice_index);
1452 dbg("fax_index[%d]", file_meta->mbi_list.mbi[file_meta->mbi_list.profile_count -1].fax_index);
1453 dbg("email_index[%d]", file_meta->mbi_list.mbi[file_meta->mbi_list.profile_count -1].email_index);
1454 dbg("other_index[%d]", file_meta->mbi_list.mbi[file_meta->mbi_list.profile_count -1].other_index);
1455 dbg("video_index[%d]", file_meta->mbi_list.mbi[file_meta->mbi_list.profile_count -1].video_index);
1461 case SIM_EF_CPHS_MAILBOX_NUMBERS: // linear type
1462 case SIM_EF_MBDN: //linear type
1463 dr = tcore_sim_decode_xdn(&file_meta->mb_list[file_meta->current_index-1].number_info, (unsigned char *) res, res_len);
1464 file_meta->mb_list[file_meta->current_index-1].rec_index = file_meta->current_index;
1467 case SIM_EF_CPHS_VOICE_MSG_WAITING: // transparent type
1468 dr = tcore_sim_decode_vmwf(&file_meta->files.data.mw.cphs_mw, (unsigned char *) res, res_len);
1471 case SIM_EF_USIM_MWIS: //linear type
1472 mw = calloc(sizeof(struct tel_sim_mw),1);
1473 dr = tcore_sim_decode_mwis(mw, (unsigned char *) res, res_len);
1475 memcpy( &file_meta->files.data.mw.mw_list.mw[file_meta->files.data.mw.mw_list.profile_count], mw, sizeof(struct tel_sim_mw) );
1476 file_meta->files.data.mw.mw_list.mw[file_meta->files.data.mw.mw_list.profile_count].rec_index = file_meta->current_index;
1477 file_meta->files.data.mw.mw_list.profile_count++;
1483 case SIM_EF_CPHS_CALL_FORWARD_FLAGS: //transparent type
1484 dr = tcore_sim_decode_cff(&file_meta->files.data.cf.cphs_cf, (unsigned char *) res, res_len);
1487 case SIM_EF_USIM_CFIS: //linear type
1488 cf = calloc(sizeof(struct tel_sim_cfis),1);
1489 dr = tcore_sim_decode_cfis(cf, (unsigned char *) res, res_len);
1491 memcpy( &file_meta->files.data.cf.cf_list.cf[file_meta->files.data.cf.cf_list.profile_count], cf, sizeof(struct tel_sim_cfis) );
1492 file_meta->files.data.cf.cf_list.cf[file_meta->files.data.cf.cf_list.profile_count].rec_index = file_meta->current_index;
1493 file_meta->files.data.cf.cf_list.profile_count++;
1499 case SIM_EF_CPHS_SERVICE_STRING_TABLE:
1500 dbg(" not handled -SIM_EF_CPHS_SERVICE_STRING_TABLE ");
1503 case SIM_EF_CPHS_OPERATOR_NAME_STRING:
1504 dr = tcore_sim_decode_ons((unsigned char*)&file_meta->files.data.cphs_net.full_name, (unsigned char *) res, res_len);
1505 dbg(" file_meta->files.result[%d],file_meta->files.data.cphs_net.full_name[%s]", file_meta->files.result, file_meta->files.data.cphs_net.full_name);
1508 case SIM_EF_CPHS_DYNAMICFLAGS:
1509 /* dr = tcore_sim_decode_dynamic_flag(&po->p_cphs->dflagsinfo, p_data->response, p_data->response_len);*/
1512 case SIM_EF_CPHS_DYNAMIC2FLAG:
1513 /* dr = tcore_sim_decode_dynamic2_flag(&po->p_cphs->d2flagsinfo, p_data->response, p_data->response_len);*/
1516 case SIM_EF_CPHS_CPHS_INFO:
1517 dr = tcore_sim_decode_cphs_info(&file_meta->files.data.cphs, (unsigned char *) res, res_len);
1520 case SIM_EF_CPHS_OPERATOR_NAME_SHORT_FORM_STRING:
1521 dr = tcore_sim_decode_short_ons((unsigned char*)&file_meta->files.data.cphs_net.short_name, (unsigned char *) res, res_len);
1524 case SIM_EF_CPHS_INFORMATION_NUMBERS:
1525 /* dr = tcore_sim_decode_information_number(&po->p_cphs->infn, p_data->response, p_data->response_len);*/
1529 dbg("File Decoding Failed - not handled File[0x%x]", file_meta->file_id);
1534 rt = _decode_status_word(sw1, sw2);
1535 file_meta->files.result = rt;
1539 tcore_at_tok_free(tokens);
1541 dbg("RESPONSE NOK");
1542 dbg("error to get ef[0x%x]", file_meta->file_id);
1543 rt = SIM_ACCESS_FAILED;
1545 ur = tcore_user_request_ref(ur);
1547 dbg("Calling _next_from_get_file_data");
1548 _next_from_get_file_data(tcore_pending_ref_core_object(p), ur, rt, dr);
1549 dbg(" Function exit");
1552 static void _on_response_get_retry_count(TcorePending *p, int data_len, const void *data, void *user_data)
1554 const TcoreATResponse *resp = data;
1555 UserRequest *ur = NULL;
1556 CoreObject *co_sim = NULL;
1557 struct s_sim_property *sp = NULL;
1558 GSList *tokens = NULL;
1559 const char *line = NULL;
1560 struct tresp_sim_verify_pins v_pin = {0, };
1561 struct tresp_sim_verify_puks v_puk = {0, };
1562 struct tresp_sim_change_pins change_pin = {0, };
1563 struct tresp_sim_disable_facility dis_facility = {0, };
1564 struct tresp_sim_enable_facility en_facility = {0, };
1566 int attempts_left = 0;
1567 int time_penalty = 0;
1569 dbg(" Function entry ");
1571 co_sim = tcore_pending_ref_core_object(p);
1572 sp = tcore_sim_ref_userdata(co_sim);
1573 ur = tcore_pending_ref_user_request(p);
1575 if (resp->success > 0) {
1578 line = (const char *) resp->lines->data;
1579 tokens = tcore_at_tok_new(line);
1580 if (g_slist_length(tokens) < 3) {
1581 msg("invalid message");
1582 tcore_at_tok_free(tokens);
1586 lock_type = atoi(g_slist_nth_data(tokens, 0));
1587 attempts_left = atoi(g_slist_nth_data(tokens, 1));
1588 time_penalty = atoi(g_slist_nth_data(tokens, 2));
1590 dbg("lock_type = %d, attempts_left = %d, time_penalty = %d",
1591 lock_type, attempts_left, time_penalty);
1593 switch (sp->current_sec_op) {
1594 case SEC_PIN1_VERIFY:
1595 case SEC_PIN2_VERIFY:
1596 case SEC_SIM_VERIFY:
1597 case SEC_ADM_VERIFY:
1598 v_pin.result = SIM_INCORRECT_PASSWORD;
1599 v_pin.pin_type = _sim_get_current_pin_facility(sp->current_sec_op);
1600 v_pin.retry_count = attempts_left;
1601 tcore_user_request_send_response(ur, _find_resp_command(ur),
1602 sizeof(struct tresp_sim_verify_pins), &v_pin);
1605 case SEC_PUK1_VERIFY:
1606 case SEC_PUK2_VERIFY:
1607 v_puk.result = SIM_INCORRECT_PASSWORD;
1608 v_puk.pin_type = _sim_get_current_pin_facility(sp->current_sec_op);
1609 v_puk.retry_count = attempts_left;
1610 tcore_user_request_send_response(ur, _find_resp_command(ur),
1611 sizeof(struct tresp_sim_verify_puks), &v_puk);
1614 case SEC_PIN1_CHANGE:
1615 case SEC_PIN2_CHANGE:
1616 change_pin.result = SIM_INCORRECT_PASSWORD;
1617 change_pin.pin_type = _sim_get_current_pin_facility(sp->current_sec_op);
1618 change_pin.retry_count = attempts_left;
1619 tcore_user_request_send_response(ur, _find_resp_command(ur),
1620 sizeof(struct tresp_sim_change_pins), &change_pin);
1623 case SEC_PIN1_DISABLE:
1624 case SEC_PIN2_DISABLE:
1625 case SEC_FDN_DISABLE:
1626 case SEC_SIM_DISABLE:
1627 case SEC_NET_DISABLE:
1628 case SEC_NS_DISABLE:
1629 case SEC_SP_DISABLE:
1630 case SEC_CP_DISABLE:
1631 dis_facility.result = SIM_INCORRECT_PASSWORD;
1632 dis_facility.type = _sim_get_current_pin_facility(sp->current_sec_op);
1633 dis_facility.retry_count = attempts_left;
1634 tcore_user_request_send_response(ur, _find_resp_command(ur),
1635 sizeof(struct tresp_sim_disable_facility), &dis_facility);
1638 case SEC_PIN1_ENABLE:
1639 case SEC_PIN2_ENABLE:
1640 case SEC_FDN_ENABLE:
1641 case SEC_SIM_ENABLE:
1642 case SEC_NET_ENABLE:
1646 en_facility.result = SIM_INCORRECT_PASSWORD;
1647 en_facility.type = _sim_get_current_pin_facility(sp->current_sec_op);
1648 en_facility.retry_count = attempts_left;
1649 tcore_user_request_send_response(ur, _find_resp_command(ur),
1650 sizeof(struct tresp_sim_enable_facility), &en_facility);
1654 dbg("not handled sec op[%d]", sp->current_sec_op);
1657 tcore_at_tok_free(tokens);
1659 dbg(" Function exit");
1662 static gboolean _get_sim_type(CoreObject *o)
1664 TcoreHal *hal = NULL;
1665 TcoreATRequest *req = NULL;
1666 TcorePending *pending = NULL;
1667 UserRequest *ur = NULL;
1668 char *cmd_str = NULL;
1670 dbg(" Function entry ");
1672 hal = tcore_object_get_hal(o);
1673 pending = tcore_pending_new(o, 0);
1675 cmd_str = g_strdup_printf("AT+XUICC?");
1676 req = tcore_at_request_new(cmd_str, "+XUICC:", TCORE_AT_SINGLELINE);
1678 dbg("cmd : %s, prefix(if any) :%s, cmd_len : %d", req->cmd, req->prefix, strlen(req->cmd));
1680 tcore_pending_set_request_data(pending, 0, req);
1681 tcore_pending_set_response_callback(pending, _response_get_sim_type, hal);
1682 tcore_pending_link_user_request(pending, ur);
1683 tcore_hal_send_request(hal, pending);
1686 dbg(" Function exit");
1690 static TReturn _get_file_info(CoreObject *o, UserRequest *ur, const enum tel_sim_file_id ef)
1692 TcoreHal *hal = NULL;
1693 TcorePending *pending = NULL;
1694 struct s_sim_property file_meta = {0, };
1695 char *cmd_str = NULL;
1696 TReturn ret = TCORE_RETURN_FAILURE;
1699 dbg(" Function entry ");
1701 file_meta.file_id = ef;
1702 dbg("file_meta.file_id: %d", file_meta.file_id);
1703 hal = tcore_object_get_hal(o);
1704 dbg("hal: %x", hal);
1706 trt = tcore_user_request_set_metainfo(ur, sizeof(struct s_sim_property), &file_meta);
1707 dbg("trt[%d]", trt);
1708 cmd_str = g_strdup_printf("AT+CRSM=192, %d", ef); /*command - 192 : GET RESPONSE*/
1709 dbg("cmd_str: %s", cmd_str);
1711 pending = tcore_at_pending_new(o, cmd_str, "+CRSM:", TCORE_AT_SINGLELINE, _response_get_file_info, NULL);
1712 tcore_pending_link_user_request(pending, ur);
1713 ret = tcore_hal_send_request(hal, pending);
1714 if (TCORE_RETURN_SUCCESS != ret) {
1715 tcore_user_request_free(ur);
1718 dbg(" Function exit");
1719 return TCORE_RETURN_SUCCESS;
1722 static gboolean _get_file_data(CoreObject *o, UserRequest *ur, const enum tel_sim_file_id ef, const int offset, const int length)
1724 TcoreHal *hal = NULL;
1725 TcoreATRequest *req = NULL;
1726 TcorePending *pending = NULL;
1727 char *cmd_str = NULL;
1732 dbg(" Function entry ");
1733 hal = tcore_object_get_hal(o);
1734 pending = tcore_pending_new(o, 0);
1736 dbg("file_id: %x", ef);
1738 p1 = (unsigned char) (offset & 0xFF00) >> 8;
1739 p2 = (unsigned char) offset & 0x00FF; // offset low
1740 p3 = (unsigned char) length;
1742 cmd_str = g_strdup_printf("AT+CRSM=176, %d, %d, %d, %d", ef, p1, p2, p3); /*command - 176 : READ BINARY*/
1744 req = tcore_at_request_new(cmd_str, "+CRSM:", TCORE_AT_SINGLELINE);
1746 dbg("cmd : %s, prefix(if any) :%s, cmd_len : %d", req->cmd, req->prefix, strlen(req->cmd));
1748 tcore_pending_set_request_data(pending, 0, req);
1749 tcore_pending_set_response_callback(pending, _response_get_file_data, hal);
1750 tcore_pending_link_user_request(pending, ur);
1751 tcore_hal_send_request(hal, pending);
1754 dbg(" Function exit");
1758 static gboolean _get_file_record(CoreObject *o, UserRequest *ur, const enum tel_sim_file_id ef, const int index, const int length)
1760 TcoreHal *hal = NULL;
1761 TcoreATRequest *req = NULL;
1762 TcorePending *pending = NULL;
1763 char *cmd_str = NULL;
1768 dbg(" Function entry ");
1770 hal = tcore_object_get_hal(o);
1771 pending = tcore_pending_new(o, 0);
1773 p1 = (unsigned char) index;
1774 p2 = (unsigned char) 0x04; /* 0x4 for absolute mode */
1775 p3 = (unsigned char) length;
1777 cmd_str = g_strdup_printf("AT+CRSM=178, %d, %d, %d, %d", ef, p1, p2, p3); /*command - 178 : READ RECORD*/
1779 req = tcore_at_request_new(cmd_str, "+CRSM:", TCORE_AT_SINGLELINE);
1781 dbg("cmd : %s, prefix(if any) :%s, cmd_len : %d", req->cmd, req->prefix, strlen(req->cmd));
1783 tcore_pending_set_request_data(pending, 0, req);
1784 tcore_pending_set_response_callback(pending, _response_get_file_data, hal);
1785 tcore_pending_link_user_request(pending, ur);
1786 tcore_hal_send_request(hal, pending);
1789 dbg(" Function exit");
1793 static TReturn _get_retry_count(CoreObject *o, UserRequest *ur)
1795 TcoreHal *hal = NULL;
1796 TcoreATRequest *req = NULL;
1797 TcorePending *pending = NULL;
1798 char *cmd_str = NULL;
1800 struct s_sim_property *sp = NULL;
1801 const struct treq_sim_get_lock_info *req_data = NULL;
1803 dbg(" Function entry ");
1805 hal = tcore_object_get_hal(o);
1806 pending = tcore_pending_new(o, 0);
1807 req_data = tcore_user_request_ref_data(ur, NULL);
1808 sp = tcore_sim_ref_userdata(o);
1810 switch (sp->current_sec_op) {
1811 case SEC_PIN1_VERIFY:
1812 case SEC_PIN1_CHANGE:
1813 case SEC_PIN1_ENABLE:
1814 case SEC_PIN1_DISABLE:
1818 case SEC_PIN2_VERIFY:
1819 case SEC_PIN2_CHANGE:
1820 case SEC_PIN2_ENABLE:
1821 case SEC_PIN2_DISABLE:
1822 case SEC_FDN_ENABLE:
1823 case SEC_FDN_DISABLE:
1827 case SEC_PUK1_VERIFY:
1831 case SEC_PUK2_VERIFY:
1835 case SEC_NET_ENABLE:
1836 case SEC_NET_DISABLE:
1841 case SEC_NS_DISABLE:
1846 case SEC_SP_DISABLE:
1851 case SEC_CP_DISABLE:
1855 case SEC_ADM_VERIFY:
1863 cmd_str = g_strdup_printf("AT+XPINCNT=%d", lock_type);
1864 req = tcore_at_request_new(cmd_str, "+XPINCNT:", TCORE_AT_SINGLELINE);
1865 dbg("cmd : %s, prefix(if any) :%s, cmd_len : %d", req->cmd, req->prefix, strlen(req->cmd));
1867 tcore_pending_set_request_data(pending, 0, req);
1868 tcore_pending_set_response_callback(pending, _on_response_get_retry_count, hal);
1869 tcore_pending_link_user_request(pending, ur);
1870 tcore_hal_send_request(hal, pending);
1873 dbg(" Function exit");
1874 return TCORE_RETURN_SUCCESS;
1878 static gboolean on_event_facility_lock_status(CoreObject *o, const void *event_info, void *user_data)
1880 struct s_sim_property *sp = NULL;
1882 GSList *tokens = NULL;
1883 GSList *lines = NULL;
1885 dbg("Function entry");
1888 sp = tcore_sim_ref_userdata(o);
1889 lines = (GSList *) event_info;
1890 if (1 != g_slist_length(lines)) {
1891 dbg("unsolicited msg but multiple line");
1894 line = (char *) (lines->data);
1895 tokens = tcore_at_tok_new(line);
1896 if (g_slist_length(tokens) != 1) {
1897 msg("invalid message");
1898 tcore_at_tok_free(tokens);
1903 dbg(" Function exit");
1905 tcore_at_tok_free(tokens);
1910 static gboolean on_event_pin_status(CoreObject *o, const void *event_info, void *user_data)
1913 struct s_sim_property *sp = NULL;
1914 enum tel_sim_status sim_status = SIM_STATUS_INITIALIZING;
1915 GSList *tokens = NULL;
1916 GSList *lines = NULL;
1917 const char *line = NULL;
1921 dbg(" Function entry ");
1923 sp = tcore_sim_ref_userdata(o);
1925 lines = (GSList *) event_info;
1926 if (1 != g_slist_length(lines)) {
1927 dbg("unsolicited msg but multiple line");
1930 line = (char *) (lines->data);
1932 tokens = tcore_at_tok_new(line);
1934 if (g_slist_length(tokens) == 4) {
1935 sim_state = atoi(g_slist_nth_data(tokens, 1));
1936 sms_state = atoi(g_slist_nth_data(tokens, 3));
1937 } else if (g_slist_length(tokens) == 1)
1938 sim_state = atoi(g_slist_nth_data(tokens, 0));
1940 msg("invalid message");
1941 tcore_at_tok_free(tokens);
1945 switch (sim_state) {
1946 case 0: // sim state = SIM not present
1947 sim_status = SIM_STATUS_CARD_NOT_PRESENT;
1951 case 1: // sim state = PIN verification needed
1952 sim_status = SIM_STATUS_PIN_REQUIRED;
1953 dbg(" PIN required");
1956 case 2: // sim state = PIN verification not needed \96 Ready
1957 case 3: // sim state = PIN verified \96 Ready
1958 sim_status = SIM_STATUS_INITIALIZING;
1959 dbg(" Inside PIN disabled at BOOT UP");
1962 case 4: // sim state = PUK verification needed
1963 sim_status = SIM_STATUS_PUK_REQUIRED;
1964 dbg(" PUK required");
1967 case 5: // sim state = SIM permanently blocked
1968 sim_status = SIM_STATUS_CARD_BLOCKED;
1969 dbg(" Card permanently blocked");
1972 case 6: // sim state = SIM error
1973 sim_status = SIM_STATUS_CARD_ERROR;
1974 dbg("SIM card error ");
1977 case 7: // sim state = ready for attach (+COPS)
1978 sim_status = SIM_STATUS_INIT_COMPLETED;
1979 dbg("Modem init completed");
1982 case 8: // sim state = SIM Technical Problem
1983 sim_status = SIM_STATUS_CARD_ERROR;
1984 dbg("SIM unavailable");
1987 case 9: // sim state = SIM removed
1988 sim_status = SIM_STATUS_CARD_REMOVED;
1992 case 99: // sim state = SIM State Unknown
1993 sim_status = SIM_STATUS_UNKNOWN;
1994 dbg("SIM State Unknown");
1998 dbg("SIM Status : %d", sim_status);
2002 dbg(" not handled SEC lock type ");
2006 switch (sim_status) {
2007 case SIM_STATUS_INIT_COMPLETED:
2008 if (tcore_sim_get_type(o) == SIM_TYPE_UNKNOWN)
2011 _sim_status_update(o, sim_status);
2014 struct tnoti_sms_ready_status readyStatusInfo = {0, };
2016 TcorePlugin *plugin;
2019 readyStatusInfo.status = TRUE;
2020 plugin = tcore_object_ref_plugin(o);
2021 sms = tcore_plugin_ref_core_object(plugin, CORE_OBJECT_TYPE_SMS);
2022 tcore_sms_set_ready_status(sms, readyStatusInfo.status);
2024 tcore_server_send_notification(tcore_plugin_ref_server(plugin), sms, TNOTI_SMS_DEVICE_READY, sizeof(struct tnoti_sms_ready_status), &readyStatusInfo);
2028 case SIM_STATUS_INITIALIZING:
2029 case SIM_STATUS_PIN_REQUIRED:
2030 case SIM_STATUS_PUK_REQUIRED:
2031 case SIM_STATUS_CARD_BLOCKED:
2032 case SIM_STATUS_NCK_REQUIRED:
2033 case SIM_STATUS_NSCK_REQUIRED:
2034 case SIM_STATUS_SPCK_REQUIRED:
2035 case SIM_STATUS_CCK_REQUIRED:
2036 case SIM_STATUS_LOCK_REQUIRED:
2037 _sim_status_update(o, sim_status);
2040 case SIM_STATUS_CARD_REMOVED:
2041 case SIM_STATUS_CARD_NOT_PRESENT:
2042 case SIM_STATUS_CARD_ERROR:
2043 if (sim_status == SIM_STATUS_CARD_NOT_PRESENT && tcore_sim_get_status(o) != SIM_STATUS_UNKNOWN) {
2044 dbg("[SIM]SIM CARD REMOVED!!");
2045 sim_status = SIM_STATUS_CARD_REMOVED;
2048 tcore_sim_set_type(o, SIM_TYPE_UNKNOWN);
2049 _sim_status_update(o, sim_status);
2053 dbg("not handled status[%d]", sim_status);
2058 dbg(" Function exit");
2060 tcore_at_tok_free(tokens);
2064 static void on_response_get_sim_status(TcorePending *p, int data_len, const void *data, void *user_data)
2066 const TcoreATResponse *resp = data;
2067 CoreObject *co_sim = NULL;
2069 dbg(" Function entry ");
2071 co_sim = tcore_pending_ref_core_object(p);
2073 if (resp->success > 0) {
2076 on_event_pin_status(co_sim, resp->lines, NULL);
2078 dbg("RESPONSE NOK");
2081 dbg(" Function exit");
2084 static enum tcore_hook_return on_hook_modem_power(Server *s, CoreObject *source, enum tcore_notification_command command,
2085 unsigned int data_len, void *data, void *user_data)
2087 TcorePlugin *plugin = tcore_object_ref_plugin(source);
2088 CoreObject *co_sim = tcore_plugin_ref_core_object(plugin, CORE_OBJECT_TYPE_SIM);
2091 return TCORE_HOOK_RETURN_CONTINUE;
2093 dbg("Get SIM status");
2095 sim_prepare_and_send_pending_request(co_sim, "AT+XSIMSTATE?", "+XSIMSTATE:", TCORE_AT_SINGLELINE, on_response_get_sim_status);
2097 return TCORE_HOOK_RETURN_CONTINUE;
2100 static void on_response_verify_pins(TcorePending *p, int data_len, const void *data, void *user_data)
2102 const TcoreATResponse *resp = data;
2103 UserRequest *ur = NULL;
2104 CoreObject *co_sim = NULL;
2105 struct s_sim_property *sp = NULL;
2106 GSList *tokens = NULL;
2107 struct tresp_sim_verify_pins res;
2108 GQueue *queue = NULL;
2112 dbg(" Function entry ");
2114 co_sim = tcore_pending_ref_core_object(p);
2115 sp = tcore_sim_ref_userdata(co_sim);
2116 ur = tcore_pending_ref_user_request(p);
2118 memset(&res, 0, sizeof(struct tresp_sim_verify_pins));
2120 if (resp->success > 0) {
2122 res.result = SIM_PIN_OPERATION_SUCCESS;
2123 res.pin_type = _sim_get_current_pin_facility(sp->current_sec_op);
2124 if (res.pin_type == SIM_PTYPE_PIN1 || res.pin_type == SIM_PTYPE_SIM) {
2125 if (tcore_sim_get_status(co_sim) != SIM_STATUS_INIT_COMPLETED)
2126 _sim_status_update(co_sim, SIM_STATUS_INITIALIZING);
2128 tcore_user_request_send_response(ur, _find_resp_command(ur), sizeof(struct tresp_sim_verify_pins), &res);
2130 dbg("RESPONSE NOK");
2131 line = (const char *) resp->final_response;
2132 tokens = tcore_at_tok_new(line);
2133 if (g_slist_length(tokens) < 1) {
2134 dbg("err cause not specified or string corrupted");
2135 res.result = TCORE_RETURN_3GPP_ERROR;
2136 tcore_user_request_send_response(ur, _find_resp_command(ur), sizeof(struct tresp_sim_verify_pins), &res);
2138 err = atoi(g_slist_nth_data(tokens, 0));
2139 dbg("on_response_verify_pins: err = %d", err);
2140 queue = tcore_object_ref_user_data(co_sim);
2141 ur = tcore_user_request_ref(ur);
2142 _get_retry_count(co_sim, ur);
2144 tcore_at_tok_free(tokens);
2146 dbg(" Function exit");
2149 static void on_response_verify_puks(TcorePending *p, int data_len, const void *data, void *user_data)
2151 const TcoreATResponse *resp = data;
2152 UserRequest *ur = NULL;
2153 CoreObject *co_sim = NULL;
2154 struct s_sim_property *sp = NULL;
2155 GSList *tokens = NULL;
2156 struct tresp_sim_verify_puks res;
2157 GQueue *queue = NULL;
2161 dbg(" Function entry ");
2163 co_sim = tcore_pending_ref_core_object(p);
2164 sp = tcore_sim_ref_userdata(co_sim);
2165 ur = tcore_pending_ref_user_request(p);
2167 memset(&res, 0, sizeof(struct tresp_sim_verify_pins));
2169 if (resp->success > 0) {
2171 res.result = SIM_PIN_OPERATION_SUCCESS;
2172 res.pin_type = _sim_get_current_pin_facility(sp->current_sec_op);
2173 tcore_user_request_send_response(ur, _find_resp_command(ur), sizeof(struct tresp_sim_verify_pins), &res);
2175 dbg("RESPONSE NOK");
2176 line = (const char *) resp->final_response;
2177 tokens = tcore_at_tok_new(line);
2179 if (g_slist_length(tokens) < 1) {
2180 dbg("err cause not specified or string corrupted");
2181 res.result = TCORE_RETURN_3GPP_ERROR;
2182 tcore_user_request_send_response(ur, _find_resp_command(ur), sizeof(struct tresp_sim_verify_pins), &res);
2184 err = atoi(g_slist_nth_data(tokens, 0));
2185 queue = tcore_object_ref_user_data(co_sim);
2186 ur = tcore_user_request_ref(ur);
2187 _get_retry_count(co_sim, ur);
2189 tcore_at_tok_free(tokens);
2191 dbg(" Function exit");
2194 static void on_response_change_pins(TcorePending *p, int data_len, const void *data, void *user_data)
2196 const TcoreATResponse *resp = data;
2197 UserRequest *ur = NULL;
2198 CoreObject *co_sim = NULL;
2199 struct s_sim_property *sp = NULL;
2200 GSList *tokens = NULL;
2201 struct tresp_sim_change_pins res;
2206 dbg(" Function entry ");
2208 co_sim = tcore_pending_ref_core_object(p);
2209 sp = tcore_sim_ref_userdata(co_sim);
2210 ur = tcore_pending_ref_user_request(p);
2212 memset(&res, 0, sizeof(struct tresp_sim_change_pins));
2214 if (resp->success > 0) {
2216 res.result = SIM_PIN_OPERATION_SUCCESS;
2217 res.pin_type = _sim_get_current_pin_facility(sp->current_sec_op);
2218 tcore_user_request_send_response(ur, _find_resp_command(ur), sizeof(struct tresp_sim_change_pins), &res);
2220 dbg("RESPONSE NOK");
2221 line = (const char *) resp->final_response;
2222 tokens = tcore_at_tok_new(line);
2224 if (g_slist_length(tokens) < 1) {
2225 dbg("err cause not specified or string corrupted");
2226 res.result = TCORE_RETURN_3GPP_ERROR;
2227 tcore_user_request_send_response(ur, _find_resp_command(ur), sizeof(struct tresp_sim_change_pins), &res);
2229 err = atoi(g_slist_nth_data(tokens, 0));
2230 queue = tcore_object_ref_user_data(co_sim);
2231 ur = tcore_user_request_ref(ur);
2232 _get_retry_count(co_sim, ur);
2234 tcore_at_tok_free(tokens);
2236 dbg(" Function exit");
2239 static void on_response_get_facility_status(TcorePending *p, int data_len, const void *data, void *user_data)
2241 const TcoreATResponse *resp = data;
2242 UserRequest *ur = NULL;
2243 GSList *tokens = NULL;
2244 struct tresp_sim_get_facility_status *res = user_data;
2247 dbg(" Function entry ");
2249 ur = tcore_pending_ref_user_request(p);
2251 res->result = SIM_PIN_OPERATION_SUCCESS;
2253 if (resp->success > 0) {
2256 line = (const char *) resp->lines->data;
2257 tokens = tcore_at_tok_new(line);
2258 if (g_slist_length(tokens) != 1) {
2259 msg("invalid message");
2260 tcore_at_tok_free(tokens);
2264 res->b_enable = atoi(g_slist_nth_data(tokens, 0));
2266 dbg("RESPONSE NOK");
2267 res->result = SIM_INCOMPATIBLE_PIN_OPERATION;
2271 tcore_user_request_send_response(ur, _find_resp_command(ur),
2272 sizeof(struct tresp_sim_get_facility_status), res);
2274 tcore_at_tok_free(tokens);
2276 dbg(" Function exit");
2279 static void on_response_enable_facility(TcorePending *p, int data_len, const void *data, void *user_data)
2281 const TcoreATResponse *resp = data;
2282 UserRequest *ur = NULL;
2283 CoreObject *co_sim = NULL;
2284 struct s_sim_property *sp = NULL;
2285 GSList *tokens = NULL;
2286 struct tresp_sim_enable_facility res;
2290 dbg(" Function entry ");
2292 co_sim = tcore_pending_ref_core_object(p);
2293 sp = tcore_sim_ref_userdata(co_sim);
2294 ur = tcore_pending_ref_user_request(p);
2296 memset(&res, 0, sizeof(struct tresp_sim_enable_facility));
2298 res.result = SIM_CARD_ERROR;
2299 res.type = _sim_get_current_pin_facility(sp->current_sec_op);
2301 if (resp->success > 0) {
2304 line = (const char *) resp->lines->data;
2305 tokens = tcore_at_tok_new(line);
2306 if (g_slist_length(tokens) != 1) {
2307 msg("invalid message");
2308 tcore_user_request_send_response(ur, _find_resp_command(ur),
2309 sizeof(struct tresp_sim_enable_facility), &res);
2310 tcore_at_tok_free(tokens);
2314 res.result = SIM_PIN_OPERATION_SUCCESS;
2316 tcore_user_request_send_response(ur, _find_resp_command(ur),
2317 sizeof(struct tresp_sim_enable_facility), &res);
2319 tcore_at_tok_free(tokens);
2321 dbg("RESPONSE NOK");
2322 queue = tcore_object_ref_user_data(co_sim);
2323 ur = tcore_user_request_ref(ur);
2324 _get_retry_count(co_sim, ur);
2326 dbg(" Function exit");
2329 static void on_response_disable_facility(TcorePending *p, int data_len, const void *data, void *user_data)
2331 const TcoreATResponse *resp = data;
2332 UserRequest *ur = NULL;
2333 CoreObject *co_sim = NULL;
2334 struct s_sim_property *sp = NULL;
2335 GSList *tokens = NULL;
2336 struct tresp_sim_disable_facility res;
2340 dbg(" Function entry ");
2342 co_sim = tcore_pending_ref_core_object(p);
2343 sp = tcore_sim_ref_userdata(co_sim);
2344 ur = tcore_pending_ref_user_request(p);
2346 memset(&res, 0, sizeof(struct tresp_sim_disable_facility));
2348 res.result = SIM_CARD_ERROR;
2349 res.type = _sim_get_current_pin_facility(sp->current_sec_op);
2351 if (resp->success > 0) {
2354 line = (const char *) resp->lines->data;
2355 tokens = tcore_at_tok_new(line);
2356 if (g_slist_length(tokens) != 1) {
2357 msg("invalid message");
2358 tcore_user_request_send_response(ur, _find_resp_command(ur),
2359 sizeof(struct tresp_sim_disable_facility), &res);
2360 tcore_at_tok_free(tokens);
2364 res.result = SIM_PIN_OPERATION_SUCCESS;
2366 tcore_user_request_send_response(ur, _find_resp_command(ur),
2367 sizeof(struct tresp_sim_disable_facility), &res);
2369 tcore_at_tok_free(tokens);
2371 dbg("RESPONSE NOK");
2372 queue = tcore_object_ref_user_data(co_sim);
2373 ur = tcore_user_request_ref(ur);
2374 _get_retry_count(co_sim, ur);
2376 dbg(" Function exit");
2379 static void on_response_get_lock_info(TcorePending *p, int data_len, const void *data, void *user_data)
2381 const TcoreATResponse *resp = data;
2382 UserRequest *ur = NULL;
2383 CoreObject *co_sim = NULL;
2384 struct s_sim_property *sp = NULL;
2385 GSList *tokens = NULL;
2387 struct tresp_sim_verify_pins v_pin = {0, };
2388 struct tresp_sim_verify_puks v_puk = {0, };
2389 struct tresp_sim_change_pins change_pin = {0, };
2390 struct tresp_sim_disable_facility dis_facility = {0, };
2391 struct tresp_sim_enable_facility en_facility = {0, };
2393 int attempts_left = 0;
2394 int time_penalty = 0;
2396 dbg(" Function entry ");
2398 co_sim = tcore_pending_ref_core_object(p);
2399 sp = tcore_sim_ref_userdata(co_sim);
2400 ur = tcore_pending_ref_user_request(p);
2402 if (resp->success > 0) {
2405 line = (const char *) resp->lines->data;
2406 tokens = tcore_at_tok_new(line);
2407 if (g_slist_length(tokens) != 3) {
2408 msg("invalid message");
2409 tcore_at_tok_free(tokens);
2413 lock_type = atoi(g_slist_nth_data(tokens, 0));
2414 attempts_left = atoi(g_slist_nth_data(tokens, 1));
2415 time_penalty = atoi(g_slist_nth_data(tokens, 2));
2417 switch (sp->current_sec_op) {
2418 case SEC_PIN1_VERIFY:
2419 case SEC_PIN2_VERIFY:
2420 case SEC_SIM_VERIFY:
2421 case SEC_ADM_VERIFY:
2422 v_pin.result = SIM_INCORRECT_PASSWORD;
2423 v_pin.pin_type = _sim_get_current_pin_facility(sp->current_sec_op);
2424 v_pin.retry_count = attempts_left;
2425 tcore_user_request_send_response(ur, _find_resp_command(ur),
2426 sizeof(struct tresp_sim_verify_pins), &v_pin);
2429 case SEC_PUK1_VERIFY:
2430 case SEC_PUK2_VERIFY:
2431 v_puk.result = SIM_INCORRECT_PASSWORD;
2432 v_puk.pin_type = _sim_get_current_pin_facility(sp->current_sec_op);
2433 v_puk.retry_count = attempts_left;
2434 tcore_user_request_send_response(ur, _find_resp_command(ur),
2435 sizeof(struct tresp_sim_verify_puks), &v_puk);
2438 case SEC_PIN1_CHANGE:
2439 case SEC_PIN2_CHANGE:
2440 change_pin.result = SIM_INCORRECT_PASSWORD;
2441 change_pin.pin_type = _sim_get_current_pin_facility(sp->current_sec_op);
2442 change_pin.retry_count = attempts_left;
2443 tcore_user_request_send_response(ur, _find_resp_command(ur),
2444 sizeof(struct tresp_sim_change_pins), &change_pin);
2447 case SEC_PIN1_DISABLE:
2448 case SEC_PIN2_DISABLE:
2449 case SEC_FDN_DISABLE:
2450 case SEC_SIM_DISABLE:
2451 case SEC_NET_DISABLE:
2452 case SEC_NS_DISABLE:
2453 case SEC_SP_DISABLE:
2454 case SEC_CP_DISABLE:
2455 dis_facility.result = SIM_INCORRECT_PASSWORD;
2456 dis_facility.type = _sim_get_current_pin_facility(sp->current_sec_op);
2457 dis_facility.retry_count = attempts_left;
2458 tcore_user_request_send_response(ur, _find_resp_command(ur),
2459 sizeof(struct tresp_sim_disable_facility), &dis_facility);
2462 case SEC_PIN1_ENABLE:
2463 case SEC_PIN2_ENABLE:
2464 case SEC_FDN_ENABLE:
2465 case SEC_SIM_ENABLE:
2466 case SEC_NET_ENABLE:
2470 en_facility.result = SIM_INCORRECT_PASSWORD;
2471 en_facility.type = _sim_get_current_pin_facility(sp->current_sec_op);
2472 en_facility.retry_count = attempts_left;
2473 tcore_user_request_send_response(ur, _find_resp_command(ur),
2474 sizeof(struct tresp_sim_enable_facility), &en_facility);
2478 dbg("not handled sec op[%d]", sp->current_sec_op);
2481 tcore_at_tok_free(tokens);
2483 dbg(" Function exit");
2486 static void on_response_update_file(TcorePending *p, int data_len, const void *data, void *user_data)
2488 const TcoreATResponse *resp = data;
2489 UserRequest *ur = NULL;
2490 CoreObject *co_sim = NULL;
2491 struct tresp_sim_set_data resp_cf = {0, };
2492 struct tresp_sim_set_data resp_language = {0, };
2493 struct s_sim_property *sp = NULL;
2494 GSList *tokens = NULL;
2495 enum tel_sim_access_result result = SIM_CARD_ERROR;
2500 dbg(" Function entry ");
2502 co_sim = tcore_pending_ref_core_object(p);
2503 ur = tcore_pending_ref_user_request(p);
2504 sp = (struct s_sim_property *) tcore_user_request_ref_metainfo(ur, NULL);
2506 if (resp->success > 0) {
2509 line = (const char *) resp->lines->data;
2510 tokens = tcore_at_tok_new(line);
2511 if (g_slist_length(tokens) != 2) {
2512 msg("invalid message");
2516 sw1 = atoi(g_slist_nth_data(tokens, 0));
2517 sw2 = atoi(g_slist_nth_data(tokens, 1));
2519 if ((sw1 == 0x90 && sw2 == 0x00) || sw1 == 0x91) {
2520 result = SIM_ACCESS_SUCCESS;
2522 result = _decode_status_word(sw1, sw2);
2525 dbg("RESPONSE NOK");
2526 result = SIM_ACCESS_FAILED;
2529 switch (sp->file_id) {
2530 case SIM_EF_CPHS_CALL_FORWARD_FLAGS:
2531 case SIM_EF_USIM_CFIS:
2532 resp_cf.result = result;
2533 tcore_user_request_send_response(ur, _find_resp_command(ur), sizeof(struct tresp_sim_set_data), &resp_cf);
2538 case SIM_EF_USIM_LI:
2539 case SIM_EF_USIM_PL:
2540 resp_language.result = result;
2541 tcore_user_request_send_response(ur, _find_resp_command(ur), sizeof(struct tresp_sim_set_data), &resp_language);
2545 dbg("Invalid File ID - %d", sp->file_id)
2548 tcore_at_tok_free(tokens);
2549 dbg(" Function exit");
2552 static void on_response_transmit_apdu(TcorePending *p, int data_len, const void *data, void *user_data)
2554 const TcoreATResponse *resp = data;
2555 UserRequest *ur = NULL;
2556 CoreObject *co_sim = NULL;
2557 GSList *tokens = NULL;
2558 struct tresp_sim_transmit_apdu res;
2561 dbg(" Function entry ");
2563 co_sim = tcore_pending_ref_core_object(p);
2564 ur = tcore_pending_ref_user_request(p);
2566 memset(&res, 0, sizeof(struct tresp_sim_transmit_apdu));
2567 res.result = SIM_ACCESS_FAILED;
2569 if (resp->success > 0) {
2573 char *decoded_data = NULL;
2574 line = (const char *) resp->lines->data;
2575 tokens = tcore_at_tok_new(line);
2576 if (g_slist_length(tokens) != 2) {
2577 msg("invalid message");
2580 res.apdu_resp_length = atoi(g_slist_nth_data(tokens, 0)) / 2;
2582 tmp = util_removeQuotes(g_slist_nth_data(tokens, 1));
2583 decoded_data = util_hexStringToBytes(tmp);
2585 memcpy((char *) res.apdu_resp, decoded_data, res.apdu_resp_length);
2588 res.result = SIM_ACCESS_SUCCESS;
2591 dbg("RESPONSE NOK");
2595 tcore_user_request_send_response(ur, _find_resp_command(ur), sizeof(struct tresp_sim_transmit_apdu), &res);
2597 tcore_at_tok_free(tokens);
2598 dbg(" Function exit");
2601 static void on_response_get_atr(TcorePending *p, int data_len, const void *data, void *user_data)
2603 const TcoreATResponse *resp = data;
2604 UserRequest *ur = NULL;
2605 GSList *tokens = NULL;
2606 struct tresp_sim_get_atr res;
2609 dbg(" Function entry ");
2611 memset(&res, 0, sizeof(struct tresp_sim_get_atr));
2612 ur = tcore_pending_ref_user_request(p);
2614 res.result = SIM_ACCESS_FAILED;
2615 if (resp->success > 0) {
2619 char *decoded_data = NULL;
2620 line = (const char *) resp->lines->data;
2621 tokens = tcore_at_tok_new(line);
2622 if (g_slist_length(tokens) < 1) {
2623 msg("invalid message");
2627 tmp = util_removeQuotes(g_slist_nth_data(tokens, 0));
2628 decoded_data = util_hexStringToBytes(tmp);
2630 res.atr_length = strlen(decoded_data);
2631 memcpy((char *) res.atr, decoded_data, res.atr_length);
2634 res.result = SIM_ACCESS_SUCCESS;
2637 dbg("RESPONSE NOK");
2642 tcore_user_request_send_response(ur, _find_resp_command(ur), sizeof(struct tresp_sim_get_atr), &res);
2644 tcore_at_tok_free(tokens);
2645 dbg(" Function exit");
2648 static TReturn s_verify_pins(CoreObject *o, UserRequest *ur)
2650 TcoreHal *hal = NULL;
2651 TcoreATRequest *req = NULL;
2652 TcorePending *pending = NULL;
2653 char *cmd_str = NULL;
2654 const struct treq_sim_verify_pins *req_data = NULL;
2655 struct s_sim_property *sp = NULL;
2656 TReturn ret = TCORE_RETURN_FAILURE;
2658 dbg(" Function entry ");
2661 return TCORE_RETURN_EINVAL;
2663 hal = tcore_object_get_hal(o);
2664 if(FALSE == tcore_hal_get_power_state(hal)){
2665 dbg("cp not ready/n");
2666 return TCORE_RETURN_ENOSYS;
2669 sp = tcore_sim_ref_userdata(o);
2670 pending = tcore_pending_new(o, 0);
2671 req_data = tcore_user_request_ref_data(ur, NULL);
2673 if (req_data->pin_type == SIM_PTYPE_PIN1) {
2674 sp->current_sec_op = SEC_PIN1_VERIFY;
2675 cmd_str = g_strdup_printf("AT+CPIN=\"%s\"", req_data->pin);
2676 } else if (req_data->pin_type == SIM_PTYPE_PIN2) {
2677 sp->current_sec_op = SEC_PIN2_VERIFY;
2678 cmd_str = g_strdup_printf("AT+CPIN2=\"%s\"", req_data->pin);
2679 } else if (req_data->pin_type == SIM_PTYPE_SIM) {
2680 sp->current_sec_op = SEC_SIM_VERIFY;
2681 cmd_str = g_strdup_printf("AT+CPIN=\"%s\"", req_data->pin);
2682 } else if (req_data->pin_type == SIM_PTYPE_ADM) {
2683 sp->current_sec_op = SEC_ADM_VERIFY;
2684 cmd_str = g_strdup_printf("AT+CPIN=\"%s\"", req_data->pin);
2686 return TCORE_RETURN_EINVAL;
2689 req = tcore_at_request_new(cmd_str, NULL, TCORE_AT_NO_RESULT);
2691 dbg("cmd : %s, prefix(if any) :%s, cmd_len : %d", req->cmd, req->prefix, strlen(req->cmd));
2693 tcore_pending_set_request_data(pending, 0, req);
2694 tcore_pending_set_response_callback(pending, on_response_verify_pins, hal);
2695 tcore_pending_link_user_request(pending, ur);
2696 ret = tcore_hal_send_request(hal, pending);
2699 dbg(" Function exit");
2703 static TReturn s_verify_puks(CoreObject *o, UserRequest *ur)
2705 TcoreHal *hal = NULL;
2706 TcoreATRequest *req = NULL;
2707 TcorePending *pending = NULL;
2708 char *cmd_str = NULL;
2709 const struct treq_sim_verify_puks *req_data;
2710 struct s_sim_property *sp = NULL;
2711 TReturn ret = TCORE_RETURN_FAILURE;
2713 dbg(" Function entry ");
2716 return TCORE_RETURN_EINVAL;
2718 hal = tcore_object_get_hal(o);
2719 if(FALSE == tcore_hal_get_power_state(hal)){
2720 dbg("cp not ready/n");
2721 return TCORE_RETURN_ENOSYS;
2724 sp = tcore_sim_ref_userdata(o);
2725 pending = tcore_pending_new(o, 0);
2726 req_data = tcore_user_request_ref_data(ur, NULL);
2728 if (req_data->puk_type == SIM_PTYPE_PUK1) {
2729 sp->current_sec_op = SEC_PUK1_VERIFY;
2730 cmd_str = g_strdup_printf("AT+CPIN=\"%s\", \"%s\"", req_data->puk, req_data->pin);
2731 } else if (req_data->puk_type == SIM_PTYPE_PUK2) {
2732 sp->current_sec_op = SEC_PUK2_VERIFY;
2733 cmd_str = g_strdup_printf("AT+CPIN2=\"%s\", \"%s\"", req_data->puk, req_data->pin);
2735 return TCORE_RETURN_EINVAL;
2737 req = tcore_at_request_new(cmd_str, NULL, TCORE_AT_NO_RESULT);
2739 dbg("cmd : %s, prefix(if any) :%s, cmd_len : %d", req->cmd, req->prefix, strlen(req->cmd));
2741 tcore_pending_set_request_data(pending, 0, req);
2742 tcore_pending_set_response_callback(pending, on_response_verify_puks, hal);
2743 tcore_pending_link_user_request(pending, ur);
2744 ret = tcore_hal_send_request(hal, pending);
2747 dbg(" Function exit");
2751 static TReturn s_change_pins(CoreObject *o, UserRequest *ur)
2753 TcoreHal *hal = NULL;
2754 TcoreATRequest *req = NULL;
2755 TcorePending *pending = NULL;
2756 char *cmd_str = NULL;
2757 const struct treq_sim_change_pins *req_data;
2758 struct s_sim_property *sp = NULL;
2761 TReturn ret = TCORE_RETURN_FAILURE;
2763 dbg(" Function entry ");
2766 return TCORE_RETURN_EINVAL;
2768 hal = tcore_object_get_hal(o);
2769 if(FALSE == tcore_hal_get_power_state(hal)){
2770 dbg("cp not ready/n");
2771 return TCORE_RETURN_ENOSYS;
2774 sp = tcore_sim_ref_userdata(o);
2775 pending = tcore_pending_new(o, 0);
2776 req_data = tcore_user_request_ref_data(ur, NULL);
2778 if (req_data->type == SIM_PTYPE_PIN1) {
2779 sp->current_sec_op = SEC_PIN1_CHANGE;
2780 cmd_str = g_strdup_printf("AT+CPWD=\"%s\",\"%s\",\"%s\"", pin1, req_data->old_pin, req_data->new_pin);
2781 } else if (req_data->type == SIM_PTYPE_PIN2) {
2782 sp->current_sec_op = SEC_PIN2_CHANGE;
2783 cmd_str = g_strdup_printf("AT+CPWD=\"%s\",\"%s\",\"%s\"", pin2, req_data->old_pin, req_data->new_pin);
2785 return TCORE_RETURN_EINVAL;
2787 req = tcore_at_request_new(cmd_str, NULL, TCORE_AT_NO_RESULT);
2789 dbg("cmd : %s, prefix(if any) :%s, cmd_len : %d", req->cmd, req->prefix, strlen(req->cmd));
2791 tcore_pending_set_request_data(pending, 0, req);
2792 tcore_pending_set_response_callback(pending, on_response_change_pins, hal);
2793 tcore_pending_link_user_request(pending, ur);
2794 ret = tcore_hal_send_request(hal, pending);
2797 dbg(" Function exit");
2801 static TReturn s_get_facility_status(CoreObject *o, UserRequest *ur)
2803 TcoreHal *hal = NULL;
2804 TcoreATRequest *req = NULL;
2805 TcorePending *pending = NULL;
2806 char *cmd_str = NULL;
2807 const struct treq_sim_get_facility_status *req_data;
2808 struct tresp_sim_get_facility_status *res;
2810 int mode = 2; /* 0:unlock, 1:lock, 2:query*/
2811 TReturn ret = TCORE_RETURN_FAILURE;
2813 dbg(" Function entry ");
2816 return TCORE_RETURN_EINVAL;
2818 hal = tcore_object_get_hal(o);
2819 if(FALSE == tcore_hal_get_power_state(hal)){
2820 dbg("cp not ready/n");
2821 return TCORE_RETURN_ENOSYS;
2824 pending = tcore_pending_new(o, 0);
2825 req_data = tcore_user_request_ref_data(ur, NULL);
2827 res = g_try_new0(struct tresp_sim_get_facility_status, 1);
2829 return TCORE_RETURN_ENOMEM;
2831 res->type = req_data->type;
2833 if (req_data->type == SIM_FACILITY_PS) {
2834 fac = "PS"; /*PH-SIM, Lock PHone to SIM/UICC card*/
2835 } else if (req_data->type == SIM_FACILITY_SC) {
2836 fac = "SC"; /*Lock SIM/UICC card, simply PIN1*/
2837 } else if (req_data->type == SIM_FACILITY_FD) {
2838 fac = "FD"; /*Fixed Dialing Number feature, need PIN2*/
2839 } else if (req_data->type == SIM_FACILITY_PN) {
2840 fac = "PN"; /*Network Personalization*/
2841 } else if (req_data->type == SIM_FACILITY_PU) {
2842 fac = "PU"; /*network sUbset Personalization*/
2843 } else if (req_data->type == SIM_FACILITY_PP) {
2844 fac = "PP"; /*service Provider Personalization*/
2845 } else if (req_data->type == SIM_FACILITY_PC) {
2846 fac = "PC"; /*Corporate Personalization*/
2848 return TCORE_RETURN_EINVAL;
2850 cmd_str = g_strdup_printf("AT+CLCK=\"%s\", %d", fac, mode);
2851 req = tcore_at_request_new(cmd_str, "+CLCK:", TCORE_AT_SINGLELINE);
2853 dbg("cmd : %s, prefix(if any) :%s, cmd_len : %d", req->cmd, req->prefix, strlen(req->cmd));
2855 tcore_pending_set_request_data(pending, 0, req);
2856 tcore_pending_set_response_callback(pending, on_response_get_facility_status, res);
2857 tcore_pending_link_user_request(pending, ur);
2858 ret = tcore_hal_send_request(hal, pending);
2861 dbg(" Function exit");
2865 static TReturn s_enable_facility(CoreObject *o, UserRequest *ur)
2867 TcoreHal *hal = NULL;
2868 TcoreATRequest *req = NULL;
2869 TcorePending *pending = NULL;
2870 char *cmd_str = NULL;
2871 const struct treq_sim_enable_facility *req_data;
2872 struct s_sim_property *sp = NULL;
2874 int mode = 1; /* 0:unlock, 1:lock, 2:query*/
2875 TReturn ret = TCORE_RETURN_FAILURE;
2877 dbg(" Function entry ");
2880 return TCORE_RETURN_EINVAL;
2882 hal = tcore_object_get_hal(o);
2883 if(FALSE == tcore_hal_get_power_state(hal)){
2884 dbg("cp not ready/n");
2885 return TCORE_RETURN_ENOSYS;
2888 sp = tcore_sim_ref_userdata(o);
2889 pending = tcore_pending_new(o, 0);
2890 req_data = tcore_user_request_ref_data(ur, NULL);
2892 if (req_data->type == SIM_FACILITY_PS) {
2893 fac = "PS"; /*PH-SIM, Lock PHone to SIM/UICC card*/
2894 sp->current_sec_op = SEC_SIM_ENABLE;
2895 } else if (req_data->type == SIM_FACILITY_SC) {
2896 fac = "SC"; /*Lock SIM/UICC card, simply PIN1*/
2897 sp->current_sec_op = SEC_PIN1_ENABLE;
2898 } else if (req_data->type == SIM_FACILITY_FD) {
2899 fac = "FD"; /*Fixed Dialing Number feature, need PIN2*/
2900 sp->current_sec_op = SEC_FDN_ENABLE;
2901 } else if (req_data->type == SIM_FACILITY_PN) {
2902 fac = "PN"; /*Network Personalization*/
2903 sp->current_sec_op = SEC_NET_ENABLE;
2904 } else if (req_data->type == SIM_FACILITY_PU) {
2905 fac = "PU"; /*network sUbset Personalization*/
2906 sp->current_sec_op = SEC_NS_ENABLE;
2907 } else if (req_data->type == SIM_FACILITY_PP) {
2908 fac = "PP"; /*service Provider Personalization*/
2909 sp->current_sec_op = SEC_SP_ENABLE;
2910 } else if (req_data->type == SIM_FACILITY_PC) {
2911 fac = "PC"; /*Corporate Personalization*/
2912 sp->current_sec_op = SEC_CP_ENABLE;
2914 return TCORE_RETURN_EINVAL;
2916 cmd_str = g_strdup_printf("AT+CLCK=\"%s\", %d, \"%s\"", fac, mode, req_data->password);
2917 req = tcore_at_request_new(cmd_str, "+CLCK:", TCORE_AT_SINGLELINE);
2919 dbg("cmd : %s, prefix(if any) :%s, cmd_len : %d", req->cmd, req->prefix, strlen(req->cmd));
2921 tcore_pending_set_request_data(pending, 0, req);
2922 tcore_pending_set_response_callback(pending, on_response_enable_facility, hal);
2923 tcore_pending_link_user_request(pending, ur);
2924 ret = tcore_hal_send_request(hal, pending);
2927 dbg(" Function exit");
2931 static TReturn s_disable_facility(CoreObject *o, UserRequest *ur)
2934 TcoreATRequest *req;
2935 TcorePending *pending = NULL;
2936 char *cmd_str = NULL;
2937 const struct treq_sim_enable_facility *req_data;
2938 struct s_sim_property *sp = NULL;
2940 int mode = 0; /* 0:unlock, 1:lock, 2:query*/
2941 TReturn ret = TCORE_RETURN_FAILURE;
2943 dbg(" Function entry ");
2946 return TCORE_RETURN_EINVAL;
2948 hal = tcore_object_get_hal(o);
2949 if(FALSE == tcore_hal_get_power_state(hal)){
2950 dbg("cp not ready/n");
2951 return TCORE_RETURN_ENOSYS;
2954 sp = tcore_sim_ref_userdata(o);
2955 pending = tcore_pending_new(o, 0);
2956 req_data = tcore_user_request_ref_data(ur, NULL);
2958 if (req_data->type == SIM_FACILITY_PS) {
2959 fac = "PS"; /*PH-SIM, Lock PHone to SIM/UICC card*/
2960 sp->current_sec_op = SEC_SIM_DISABLE;
2961 } else if (req_data->type == SIM_FACILITY_SC) {
2962 fac = "SC"; /*Lock SIM/UICC card, simply PIN1*/
2963 sp->current_sec_op = SEC_PIN1_DISABLE;
2964 } else if (req_data->type == SIM_FACILITY_FD) {
2965 fac = "FD"; /*Fixed Dialing Number feature, need PIN2*/
2966 sp->current_sec_op = SEC_FDN_DISABLE;
2967 } else if (req_data->type == SIM_FACILITY_PN) {
2968 fac = "PN"; /*Network Personalization*/
2969 sp->current_sec_op = SEC_NET_DISABLE;
2970 } else if (req_data->type == SIM_FACILITY_PU) {
2971 fac = "PU"; /*network sUbset Personalization*/
2972 sp->current_sec_op = SEC_NS_DISABLE;
2973 } else if (req_data->type == SIM_FACILITY_PP) {
2974 fac = "PP"; /*service Provider Personalization*/
2975 sp->current_sec_op = SEC_SP_DISABLE;
2976 } else if (req_data->type == SIM_FACILITY_PC) {
2977 fac = "PC"; /*Corporate Personalization*/
2978 sp->current_sec_op = SEC_CP_DISABLE;
2980 return TCORE_RETURN_EINVAL;
2982 cmd_str = g_strdup_printf("AT+CLCK=\"%s\", %d, \"%s\"", fac, mode, req_data->password);
2983 req = tcore_at_request_new(cmd_str, "+CLCK:", TCORE_AT_SINGLELINE);
2985 dbg("cmd : %s, prefix(if any) :%s, cmd_len : %d", req->cmd, req->prefix, strlen(req->cmd));
2987 tcore_pending_set_request_data(pending, 0, req);
2988 tcore_pending_set_response_callback(pending, on_response_disable_facility, hal);
2989 tcore_pending_link_user_request(pending, ur);
2990 ret = tcore_hal_send_request(hal, pending);
2993 dbg(" Function exit");
2997 static TReturn s_get_lock_info_n(CoreObject *o, UserRequest *ur)
2999 TcoreHal *hal = NULL;
3000 TcoreATRequest *req = NULL;
3001 TcorePending *pending = NULL;
3002 char *cmd_str = NULL;
3004 const struct treq_sim_get_lock_info *req_data;
3005 struct s_sim_property *sp = NULL;
3007 dbg(" Function entry ");
3009 hal = tcore_object_get_hal(o);
3011 sp = tcore_sim_ref_userdata(o);
3012 pending = tcore_pending_new(o, 0);
3013 req_data = tcore_user_request_ref_data(ur, NULL);
3016 return TCORE_RETURN_EINVAL;
3018 switch (req_data->type) {
3019 case SIM_FACILITY_PS:
3020 lock_type = 9; // IMSI lock
3023 case SIM_FACILITY_SC:
3027 case SIM_FACILITY_FD:
3031 case SIM_FACILITY_PN:
3035 case SIM_FACILITY_PU:
3039 case SIM_FACILITY_PP:
3043 case SIM_FACILITY_PC:
3050 cmd_str = g_strdup_printf("AT+XPINCNT =%d", lock_type);
3051 req = tcore_at_request_new(cmd_str, "+XPINCNT:", TCORE_AT_SINGLELINE);
3053 dbg("cmd : %s, prefix(if any) :%s, cmd_len : %d", req->cmd, req->prefix, strlen(req->cmd));
3055 tcore_pending_set_request_data(pending, 0, req);
3056 tcore_pending_set_response_callback(pending, on_response_get_lock_info, hal);
3057 tcore_pending_link_user_request(pending, ur);
3058 tcore_hal_send_request(hal, pending);
3061 dbg(" Function exit");
3062 return TCORE_RETURN_SUCCESS;
3065 static TReturn s_get_lock_info_str(CoreObject *o, UserRequest *ur)
3067 TcoreHal *hal = NULL;
3068 TcoreATRequest *req = NULL;
3069 TcorePending *pending = NULL;
3070 char *cmd_str = NULL;
3071 char *lock_type = NULL;
3072 const struct treq_sim_get_lock_info *req_data;
3073 TReturn ret = TCORE_RETURN_FAILURE;
3075 dbg(" Function entry ");
3078 return TCORE_RETURN_EINVAL;
3080 hal = tcore_object_get_hal(o);
3082 pending = tcore_pending_new(o, 0);
3083 req_data = tcore_user_request_ref_data(ur, NULL);
3085 switch (req_data->type) {
3086 case SIM_FACILITY_PS:
3090 case SIM_FACILITY_SC:
3094 case SIM_FACILITY_FD:
3098 case SIM_FACILITY_PN:
3102 case SIM_FACILITY_PU:
3106 case SIM_FACILITY_PP:
3110 case SIM_FACILITY_PC:
3117 cmd_str = g_strdup_printf("AT+XPINCNT =\"%s\"", lock_type);
3118 req = tcore_at_request_new(cmd_str, "+XPINCNT:", TCORE_AT_SINGLELINE);
3120 dbg("cmd : %s, prefix(if any) :%s, cmd_len : %d", req->cmd, req->prefix, strlen(req->cmd));
3122 tcore_pending_set_request_data(pending, 0, req);
3123 tcore_pending_set_response_callback(pending, on_response_get_lock_info, hal);
3124 tcore_pending_link_user_request(pending, ur);
3125 ret = tcore_hal_send_request(hal, pending);
3128 dbg(" Function exit");
3132 static TReturn s_get_lock_info(CoreObject *o, UserRequest *ur)
3134 TcorePlugin *plugin = tcore_object_ref_plugin(o);
3135 const char *cpname = tcore_server_get_cp_name_by_plugin(plugin);
3137 if (g_str_has_prefix(cpname, "mfld_blackbay") == TRUE)
3138 return s_get_lock_info_n(o, ur);
3140 return s_get_lock_info_str(o, ur);
3143 static TReturn s_read_file(CoreObject *o, UserRequest *ur)
3145 TReturn api_ret = TCORE_RETURN_SUCCESS;
3146 enum tcore_request_command command;
3148 dbg(" Function entry ");
3151 return TCORE_RETURN_EINVAL;
3153 command = tcore_user_request_get_command(ur);
3154 if(FALSE == tcore_hal_get_power_state(tcore_object_get_hal(o))){
3155 dbg("cp not ready/n");
3156 return TCORE_RETURN_ENOSYS;
3160 case TREQ_SIM_GET_ECC:
3161 api_ret = _get_file_info(o, ur, SIM_EF_ECC);
3164 case TREQ_SIM_GET_LANGUAGE:
3165 if (tcore_sim_get_type(o) == SIM_TYPE_GSM)
3166 api_ret = _get_file_info(o, ur, SIM_EF_ELP);
3167 else if (tcore_sim_get_type(o) == SIM_TYPE_USIM)
3168 api_ret = _get_file_info(o, ur, SIM_EF_LP);
3170 api_ret = TCORE_RETURN_ENOSYS;
3173 case TREQ_SIM_GET_ICCID:
3174 api_ret = _get_file_info(o, ur, SIM_EF_ICCID);
3177 case TREQ_SIM_GET_MAILBOX:
3178 if (tcore_sim_get_cphs_status(o))
3179 api_ret = _get_file_info(o, ur, SIM_EF_CPHS_MAILBOX_NUMBERS);
3181 api_ret = _get_file_info(o, ur, SIM_EF_MBDN);
3184 case TREQ_SIM_GET_CALLFORWARDING:
3185 if (tcore_sim_get_cphs_status(o))
3186 api_ret = _get_file_info(o, ur, SIM_EF_CPHS_CALL_FORWARD_FLAGS);
3188 api_ret = _get_file_info(o, ur, SIM_EF_USIM_CFIS);
3191 case TREQ_SIM_GET_MESSAGEWAITING:
3192 if (tcore_sim_get_cphs_status(o))
3193 api_ret = _get_file_info(o, ur, SIM_EF_CPHS_VOICE_MSG_WAITING);
3195 api_ret = _get_file_info(o, ur, SIM_EF_USIM_MWIS);
3198 case TREQ_SIM_GET_CPHS_INFO:
3199 api_ret = _get_file_info(o, ur, SIM_EF_CPHS_CPHS_INFO);
3202 case TREQ_SIM_GET_MSISDN:
3203 api_ret = _get_file_info(o, ur, SIM_EF_MSISDN);
3206 case TREQ_SIM_GET_SPN:
3207 dbg("enter case SPN");
3208 api_ret = _get_file_info(o, ur, SIM_EF_SPN);
3211 case TREQ_SIM_GET_SPDI:
3212 api_ret = _get_file_info(o, ur, SIM_EF_SPDI);
3215 case TREQ_SIM_GET_OPL:
3216 api_ret = _get_file_info(o, ur, SIM_EF_OPL);
3219 case TREQ_SIM_GET_PNN:
3220 api_ret = _get_file_info(o, ur, SIM_EF_PNN);
3223 case TREQ_SIM_GET_CPHS_NETNAME:
3224 api_ret = _get_file_info(o, ur, SIM_EF_CPHS_OPERATOR_NAME_STRING);
3227 case TREQ_SIM_GET_OPLMNWACT:
3228 api_ret = _get_file_info(o, ur, SIM_EF_OPLMN_ACT);
3232 dbg("error - not handled read treq command[%d]", command);
3233 api_ret = TCORE_RETURN_EINVAL;
3236 dbg(" Function exit");
3240 static TReturn s_update_file(CoreObject *o, UserRequest *ur)
3243 TcoreATRequest *req;
3244 TcorePending *pending = NULL;
3245 char *cmd_str = NULL;
3246 TReturn ret = TCORE_RETURN_SUCCESS;
3247 char *encoded_data = NULL;
3248 int encoded_len = 0;
3249 enum tcore_request_command command;
3250 enum tel_sim_file_id ef = SIM_EF_INVALID;
3251 const struct treq_sim_set_callforwarding *cf;
3252 const struct treq_sim_set_language *cl;
3253 struct s_sim_property file_meta = {0, };
3260 struct tel_sim_language sim_language;
3264 command = tcore_user_request_get_command(ur);
3266 dbg(" Function entry ");
3269 return TCORE_RETURN_EINVAL;
3272 hal = tcore_object_get_hal(o);
3273 if(FALSE == tcore_hal_get_power_state(hal)){
3274 dbg("cp not ready/n");
3275 return TCORE_RETURN_ENOSYS;
3278 pending = tcore_pending_new(o, 0);
3281 case TREQ_SIM_SET_LANGUAGE:
3282 cl = tcore_user_request_ref_data(ur, NULL);
3283 memset(&sim_language, 0x00, sizeof(struct tel_sim_language));
3286 sim_language.language_count = 1;
3287 sim_language.language[0] = cl->language;
3288 dbg("language %d", cl->language);
3290 if (tcore_sim_get_type(o) == SIM_TYPE_GSM) {
3293 tmp = tcore_sim_encode_lp(&out_length, &sim_language);
3295 encoded_data = (char *) malloc(2 * (sim_language.language_count) + 1);
3296 memset(encoded_data, 0x00, (2 * sim_language.language_count) + 1);
3297 result = util_byte_to_hex(tmp, encoded_data, out_length);
3302 dbg("encoded_data - %s ---", encoded_data);
3303 dbg("out_length - %d ---", out_length);
3304 } else if (tcore_sim_get_type(o) == SIM_TYPE_USIM) {
3307 tmp = tcore_sim_encode_li(&out_length, &sim_language);
3309 encoded_data = (char *) malloc(2 * (out_length) + 1);
3310 memset(encoded_data, 0x00, (2 * out_length) + 1);
3311 result = util_byte_to_hex(tmp, encoded_data, out_length);
3316 dbg("encoded_data - %s ---", encoded_data);
3317 dbg("out_length - %d ---", out_length);
3319 ret = TCORE_RETURN_ENOSYS;
3323 case TREQ_SIM_SET_CALLFORWARDING:
3324 cf = tcore_user_request_ref_data(ur, NULL);
3325 if (tcore_sim_get_cphs_status(o)) {
3326 tmp = tcore_sim_encode_cff((const struct tel_sim_cphs_cf*)&cf->cphs_cf);
3327 ef = SIM_EF_CPHS_CALL_FORWARD_FLAGS;
3331 encoded_data = (char *) malloc(2 * (p3) + 1);
3332 memset(encoded_data, 0x00, (2 *p3) + 1);
3333 result = util_byte_to_hex(tmp, encoded_data, p3);
3334 cmd = 214; /*command - 214 : UPDATE BINARY*/
3336 tmp = tcore_sim_encode_cfis(&encoded_len, (const struct tel_sim_cfis*)&cf->cf);
3337 ef = SIM_EF_USIM_CFIS;
3341 encoded_data = (char *) malloc(2 * (encoded_len) + 1);
3342 memset(encoded_data, 0x00, (2 * encoded_len) + 1);
3343 result = util_byte_to_hex(tmp, encoded_data, encoded_len);
3344 cmd = 220; /*command - 220 : UPDATE RECORD*/
3349 dbg("error - not handled update treq command[%d]", command);
3350 ret = TCORE_RETURN_EINVAL;
3353 file_meta.file_id = ef;
3354 dbg("file_meta.file_id: %d", file_meta.file_id);
3356 trt = tcore_user_request_set_metainfo(ur, sizeof(struct s_sim_property), &file_meta);
3357 dbg("trt[%d]", trt);
3359 cmd_str = g_strdup_printf("AT+CRSM=%d,%d,%d,%d,%d,\"%s\"", cmd, ef, p1, p2, p3, encoded_data);
3360 req = tcore_at_request_new(cmd_str, "+CRSM:", TCORE_AT_SINGLELINE);
3362 dbg("cmd : %s, prefix(if any) :%s, cmd_len : %d", req->cmd, req->prefix, strlen(req->cmd));
3364 tcore_pending_set_request_data(pending, 0, req);
3365 tcore_pending_set_response_callback(pending, on_response_update_file, hal);
3366 tcore_pending_link_user_request(pending, ur);
3367 ret = tcore_hal_send_request(hal, pending);
3369 if (NULL != encoded_data) {
3370 g_free(encoded_data);
3378 dbg(" Function exit");
3382 static TReturn s_transmit_apdu(CoreObject *o, UserRequest *ur)
3384 TcoreHal *hal = NULL;
3385 TcoreATRequest *req = NULL;
3386 TcorePending *pending = NULL;
3387 char *cmd_str = NULL;
3391 const struct treq_sim_transmit_apdu *req_data;
3392 TReturn ret = TCORE_RETURN_FAILURE;
3394 dbg(" Function entry ");
3397 return TCORE_RETURN_EINVAL;
3399 hal = tcore_object_get_hal(o);
3400 if(FALSE == tcore_hal_get_power_state(hal)){
3401 dbg("cp not ready/n");
3402 return TCORE_RETURN_ENOSYS;
3405 pending = tcore_pending_new(o, 0);
3406 req_data = tcore_user_request_ref_data(ur, NULL);
3408 apdu = (char *) malloc((2 * req_data->apdu_length) + 1);
3409 memset(apdu, 0x00, (2 * req_data->apdu_length) + 1);
3410 result = util_byte_to_hex((const char *) req_data->apdu, apdu, req_data->apdu_length);
3411 apdu_len = strlen(apdu);
3412 cmd_str = g_strdup_printf("AT+CSIM=%d,\"%s\"", apdu_len, apdu);
3413 req = tcore_at_request_new(cmd_str, "+CSIM:", TCORE_AT_SINGLELINE);
3414 dbg("cmd : %s, prefix(if any) :%s, cmd_len : %d", req->cmd, req->prefix, strlen(req->cmd));
3416 tcore_pending_set_request_data(pending, 0, req);
3417 tcore_pending_set_response_callback(pending, on_response_transmit_apdu, hal);
3418 tcore_pending_link_user_request(pending, ur);
3419 ret = tcore_hal_send_request(hal, pending);
3423 dbg(" Function exit");
3427 static TReturn s_get_atr(CoreObject *o, UserRequest *ur)
3429 TcoreHal *hal = NULL;
3430 TcoreATRequest *req = NULL;
3431 TcorePending *pending = NULL;
3432 char *cmd_str = NULL;
3433 TReturn ret = TCORE_RETURN_FAILURE;
3435 dbg(" Function entry ");
3438 return TCORE_RETURN_EINVAL;
3440 hal = tcore_object_get_hal(o);
3441 if(FALSE == tcore_hal_get_power_state(hal)) {
3442 dbg("cp not ready/n");
3443 return TCORE_RETURN_ENOSYS;
3445 pending = tcore_pending_new(o, 0);
3447 cmd_str = g_strdup_printf("AT+XGATR");
3448 req = tcore_at_request_new(cmd_str, "+XGATR:", TCORE_AT_SINGLELINE);
3449 dbg("cmd : %s, prefix(if any) :%s, cmd_len : %d", req->cmd, req->prefix, strlen(req->cmd));
3451 tcore_pending_set_request_data(pending, 0, req);
3452 tcore_pending_set_response_callback(pending, on_response_get_atr, hal);
3453 tcore_pending_link_user_request(pending, ur);
3454 ret = tcore_hal_send_request(hal, pending);
3457 dbg(" Function exit");
3461 static struct tcore_sim_operations sim_ops = {
3462 .verify_pins = s_verify_pins,
3463 .verify_puks = s_verify_puks,
3464 .change_pins = s_change_pins,
3465 .get_facility_status = s_get_facility_status,
3466 .enable_facility = s_enable_facility,
3467 .disable_facility = s_disable_facility,
3468 .get_lock_info = s_get_lock_info,
3469 .read_file = s_read_file,
3470 .update_file = s_update_file,
3471 .transmit_apdu = s_transmit_apdu,
3472 .get_atr = s_get_atr,
3473 .req_authentication = NULL,
3476 gboolean s_sim_init(TcorePlugin *cp, CoreObject *co_sim)
3478 struct s_sim_property *file_meta;
3482 tcore_sim_override_ops(co_sim, &sim_ops);
3484 file_meta = g_try_new0(struct s_sim_property, 1);
3488 tcore_sim_link_userdata(co_sim, file_meta);
3490 tcore_object_override_callback(co_sim, "+XLOCK", on_event_facility_lock_status, NULL);
3491 tcore_object_override_callback(co_sim, "+XSIM", on_event_pin_status, NULL);
3493 tcore_server_add_notification_hook(tcore_plugin_ref_server(cp), TNOTI_MODEM_POWER, on_hook_modem_power, co_sim);
3500 void s_sim_exit(TcorePlugin *cp, CoreObject *co_sim)
3502 struct s_sim_property *file_meta;
3504 file_meta = tcore_sim_ref_userdata(co_sim);