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 if (sim_status != tcore_sim_get_status(o)) {
782 dbg("tcore_sim_set_status and send noti w/ [%d]", sim_status);
783 tcore_sim_set_status(o, sim_status);
784 noti_data.sim_status = sim_status;
785 tcore_server_send_notification(tcore_plugin_ref_server(tcore_object_ref_plugin(o)), o, TNOTI_SIM_STATUS,
786 sizeof(struct tnoti_sim_status), ¬i_data);
790 static void _response_get_sim_type(TcorePending *p, int data_len, const void *data, void *user_data)
792 const TcoreATResponse *resp = data;
793 UserRequest *ur = NULL;
794 CoreObject *co_sim = NULL;
795 struct s_sim_property *sp = NULL;
796 GSList *tokens = NULL;
797 enum tel_sim_type sim_type = SIM_TYPE_UNKNOWN;
801 dbg(" Function entry ");
803 co_sim = tcore_pending_ref_core_object(p);
804 sp = tcore_sim_ref_userdata(co_sim);
805 ur = tcore_pending_ref_user_request(p);
807 if (resp->success > 0) {
810 line = (const char *) resp->lines->data;
811 tokens = tcore_at_tok_new(line);
812 if (g_slist_length(tokens) != 1) {
813 msg("invalid message");
814 tcore_at_tok_free(tokens);
818 state = atoi(g_slist_nth_data(tokens, 0));
819 dbg("SIM Type is %d", state);
822 sim_type = SIM_TYPE_GSM;
823 } else if (state == 1) {
824 sim_type = SIM_TYPE_USIM;
826 sim_type = SIM_TYPE_UNKNOWN;
830 sim_type = SIM_TYPE_UNKNOWN;
833 tcore_sim_set_type(co_sim, sim_type);
835 if (sim_type != SIM_TYPE_UNKNOWN) {
836 /* set user request for using ur metainfo set/ref functionality */
837 ur = tcore_user_request_new(NULL, NULL);
838 _get_file_info(co_sim, ur, SIM_EF_IMSI);
841 tcore_at_tok_free(tokens);
842 dbg(" Function exit");
845 static void _response_get_file_info(TcorePending *p, int data_len, const void *data, void *user_data)
847 const TcoreATResponse *resp = data;
848 UserRequest *ur = NULL;
849 CoreObject *co_sim = NULL;
850 struct s_sim_property *file_meta = NULL;
851 GSList *tokens = NULL;
852 enum tel_sim_access_result rt;
853 const char *line = NULL;
857 dbg(" Function entry ");
859 co_sim = tcore_pending_ref_core_object(p);
860 ur = tcore_pending_ref_user_request(p);
861 file_meta = (struct s_sim_property *) tcore_user_request_ref_metainfo(ur, NULL);
863 if (resp->success > 0) {
866 line = (const char *) resp->lines->data;
867 tokens = tcore_at_tok_new(line);
868 if (g_slist_length(tokens) < 2) {
869 err("invalid message");
870 tcore_at_tok_free(tokens);
874 sw1 = atoi(g_slist_nth_data(tokens, 0));
875 sw2 = atoi(g_slist_nth_data(tokens, 1));
877 /*1. SIM access success case*/
878 if ((sw1 == 0x90 && sw2 == 0x00) || sw1 == 0x91) {
879 unsigned char tag_len = 0; /* 1 or 2 bytes ??? */
880 unsigned short record_len = 0;
881 char num_of_records = 0;
882 unsigned char file_id_len = 0;
883 unsigned short file_id = 0;
884 unsigned short file_size = 0;
885 unsigned short file_type = 0;
886 unsigned short arr_file_id = 0;
887 int arr_file_id_rec_num = 0;
889 /* handling only last 3 bits */
890 unsigned char file_type_tag = 0x07;
891 unsigned char *ptr_data;
895 char *recordData = NULL;
896 hexData = g_slist_nth_data(tokens, 2);
897 dbg("hexData: %s", hexData);
898 dbg("hexData: %s", hexData + 1);
900 tmp = util_removeQuotes(hexData);
901 recordData = util_hexStringToBytes(tmp);
902 util_hex_dump(" ", strlen(hexData) / 2, recordData);
905 ptr_data = (unsigned char *) recordData;
906 if (tcore_sim_get_type(co_sim) == SIM_TYPE_USIM) {
908 ETSI TS 102 221 v7.9.0
910 '62' FCP template tag
912 '82' M File Descriptor
913 '83' M File Identifier
914 'A5' O Proprietary information
915 '8A' M Life Cycle Status Integer
916 '8B', '8C' or 'AB' C1 Security attributes
918 '81' O Total file size
919 '88' O Short File Identifier (SFI)
922 /* rsim.res_len has complete data length received */
924 /* FCP template tag - File Control Parameters tag*/
925 if (*ptr_data == 0x62) {
926 /* parse complete FCP tag*/
927 /* increment to next byte */
929 tag_len = *ptr_data++;
930 dbg("tag_len: %02x", tag_len);
931 /* FCP file descriptor - file type, accessibility, DF, ADF etc*/
932 if (*ptr_data == 0x82) {
933 /* increment to next byte */
937 /* unsigned char file_desc_len = *ptr_data++;*/
938 /* dbg("file descriptor length: [%d]", file_desc_len);*/
939 /* TBD: currently capture only file type : ignore sharable, non sharable, working, internal etc*/
940 /* consider only last 3 bits*/
941 dbg("file_type_tag: %02x", file_type_tag);
942 file_type_tag = file_type_tag & (*ptr_data);
943 dbg("file_type_tag: %02x", file_type_tag);
945 switch (file_type_tag) {
946 /* increment to next byte */
949 dbg("Getting FileType: [Transparent file type]");
950 file_type = SIM_FTYPE_TRANSPARENT;
952 /* increment to next byte */
954 /* increment to next byte */
959 dbg("Getting FileType: [Linear fixed file type]");
960 /* increment to next byte */
962 /* data coding byte - value 21 */
965 memcpy(&record_len, ptr_data, 2);
967 SWAPBYTES16(record_len);
968 ptr_data = ptr_data + 2;
969 num_of_records = *ptr_data++;
970 /* Data lossy conversation from enum (int) to unsigned char */
971 file_type = SIM_FTYPE_LINEAR_FIXED;
975 dbg(" Cyclic fixed file type");
976 /* increment to next byte */
978 /* data coding byte - value 21 */
981 memcpy(&record_len, ptr_data, 2);
983 SWAPBYTES16(record_len);
984 ptr_data = ptr_data + 2;
985 num_of_records = *ptr_data++;
986 file_type = SIM_FTYPE_CYCLIC;
990 dbg("not handled file type [0x%x]", *ptr_data);
994 dbg("INVALID FCP received - DEbug!");
995 tcore_at_tok_free(tokens);
1000 /*File identifier - file id?? */ // 0x84,0x85,0x86 etc are currently ignored and not handled
1001 if (*ptr_data == 0x83) {
1002 /* increment to next byte */
1004 file_id_len = *ptr_data++;
1005 dbg("file_id_len: %02x", file_id_len);
1007 memcpy(&file_id, ptr_data, file_id_len);
1008 dbg("file_id: %x", file_id);
1011 SWAPBYTES16(file_id);
1012 dbg("file_id: %x", file_id);
1014 ptr_data = ptr_data + 2;
1015 dbg("Getting FileID=[0x%x]", file_id);
1017 dbg("INVALID FCP received - DEbug!");
1018 tcore_at_tok_free(tokens);
1023 /* proprietary information */
1024 if (*ptr_data == 0xA5) {
1025 unsigned short prop_len;
1026 /* increment to next byte */
1030 prop_len = *ptr_data;
1031 dbg("prop_len: %02x", prop_len);
1034 ptr_data = ptr_data + prop_len + 1;
1036 dbg("INVALID FCP received - DEbug!");
1039 /* life cycle status integer [8A][length:0x01][status]*/
1042 00000000 : No information given
1043 00000001 : creation state
1044 00000011 : initialization state
1045 000001-1 : operation state -activated
1046 000001-0 : operation state -deactivated
1047 000011-- : Termination state
1048 b8~b5 !=0, b4~b1=X : Proprietary
1049 Any other value : RFU
1051 if (*ptr_data == 0x8A) {
1052 /* increment to next byte */
1054 /* length - value 1 */
1057 switch (*ptr_data) {
1060 dbg("<RX> operation state -deactivated");
1066 dbg("<RX> operation state -activated");
1071 dbg("<RX> DEBUG! LIFE CYCLE STATUS =[0x%x]", *ptr_data);
1077 /* related to security attributes : currently not handled*/
1078 if (*ptr_data == 0x86 || *ptr_data == 0x8B || *ptr_data == 0x8C || *ptr_data == 0xAB) {
1079 /* increment to next byte */
1081 /* if tag length is 3 */
1082 if (*ptr_data == 0x03) {
1083 /* increment to next byte */
1086 memcpy(&arr_file_id, ptr_data, 2);
1088 SWAPBYTES16(arr_file_id);
1089 ptr_data = ptr_data + 2;
1090 arr_file_id_rec_num = *ptr_data++;
1092 /* if tag length is not 3 */
1093 /* ignoring bytes */
1094 // ptr_data = ptr_data + 4;
1095 dbg("Useless security attributes, so jump to next tag");
1096 ptr_data = ptr_data + (*ptr_data + 1);
1099 dbg("INVALID FCP received[0x%x] - DEbug!", *ptr_data);
1100 tcore_at_tok_free(tokens);
1105 dbg("Current ptr_data value is [%x]", *ptr_data);
1107 /* file size excluding structural info*/
1108 if (*ptr_data == 0x80) {
1109 /* for EF file size is body of file and for Linear or cyclic it is
1110 * number of recXsizeof(one record)
1112 /* increment to next byte */
1114 /* length is 1 byte - value is 2 bytes or more */
1116 memcpy(&file_size, ptr_data, 2);
1118 SWAPBYTES16(file_size);
1119 ptr_data = ptr_data + 2;
1121 dbg("INVALID FCP received - DEbug!");
1122 tcore_at_tok_free(tokens);
1127 /* total file size including structural info*/
1128 if (*ptr_data == 0x81) {
1130 /* increment to next byte */
1135 ptr_data = ptr_data + 3;
1137 dbg("INVALID FCP received - DEbug!");
1138 /* 0x81 is optional tag?? check out! so do not return -1 from here! */
1141 /*short file identifier ignored*/
1142 if (*ptr_data == 0x88) {
1143 dbg("0x88: Do Nothing");
1147 dbg("INVALID FCP received - DEbug!");
1148 tcore_at_tok_free(tokens);
1152 } else if (tcore_sim_get_type(co_sim) == SIM_TYPE_GSM) {
1153 unsigned char gsm_specific_file_data_len = 0;
1154 /* ignore RFU byte1 and byte2 */
1158 // file_size = p_info->response_len;
1159 memcpy(&file_size, ptr_data, 2);
1161 SWAPBYTES16(file_size);
1162 /* parsed file size */
1163 ptr_data = ptr_data + 2;
1165 memcpy(&file_id, ptr_data, 2);
1166 SWAPBYTES16(file_id);
1167 dbg(" FILE id --> [%x]", file_id);
1168 ptr_data = ptr_data + 2;
1169 /* save file type - transparent, linear fixed or cyclic */
1170 file_type_tag = (*(ptr_data + 7));
1172 switch (*ptr_data) {
1175 dbg(" RFU file type- not handled - Debug!");
1180 dbg(" MF file type - not handled - Debug!");
1185 dbg(" DF file type - not handled - Debug!");
1190 dbg(" EF file type [%d] ", file_type_tag);
1191 /* increment to next byte */
1194 if (file_type_tag == 0x00 || file_type_tag == 0x01) {
1195 /* increament to next byte as this byte is RFU */
1198 (file_type_tag == 0x00) ? SIM_FTYPE_TRANSPARENT : SIM_FTYPE_LINEAR_FIXED;
1200 /* increment to next byte */
1202 /* For a cyclic EF all bits except bit 7 are RFU; b7=1 indicates that */
1203 /* the INCREASE command is allowed on the selected cyclic file. */
1204 file_type = SIM_FTYPE_CYCLIC;
1206 /* bytes 9 to 11 give SIM file access conditions */
1208 /* byte 10 has one nibble that is RF U and another for INCREASE which is not used currently */
1210 /* byte 11 is invalidate and rehabilate nibbles */
1212 /* byte 12 - file status */
1214 /* byte 13 - GSM specific data */
1215 gsm_specific_file_data_len = *ptr_data;
1217 /* byte 14 - structure of EF - transparent or linear or cyclic , already saved above */
1219 /* byte 15 - length of record for linear and cyclic , for transparent it is set to 0x00. */
1220 record_len = *ptr_data;
1221 dbg("record length[%d], file size[%d]", record_len, file_size);
1223 if (record_len != 0)
1224 num_of_records = (file_size / record_len);
1226 dbg("Number of records [%d]", num_of_records);
1230 dbg(" not handled file type");
1234 dbg(" Card Type - UNKNOWN [%d]", tcore_sim_get_type(co_sim));
1237 dbg("req ef[0x%x] resp ef[0x%x] size[%ld] Type[0x%x] NumOfRecords[%ld] RecordLen[%ld]",
1238 file_meta->file_id, file_id, file_size, file_type, num_of_records, record_len);
1240 file_meta->file_type = file_type;
1241 file_meta->data_size = file_size;
1242 file_meta->rec_length = record_len;
1243 file_meta->rec_count = num_of_records;
1244 file_meta->current_index = 0; // reset for new record type EF
1245 rt = SIM_ACCESS_SUCCESS;
1248 /*2. SIM access fail case*/
1249 dbg("error to get ef[0x%x]", file_meta->file_id);
1250 dbg("error to get ef[0x%x] (file_meta->file_id) ", file_meta->file_id);
1251 rt = _decode_status_word(sw1, sw2);
1253 ur = tcore_user_request_ref(ur);
1255 dbg("Calling _next_from_get_file_info");
1256 _next_from_get_file_info(co_sim, ur, file_meta->file_id, rt);
1257 tcore_at_tok_free(tokens);
1259 dbg("RESPONSE NOK");
1260 dbg("error to get ef[0x%x]", file_meta->file_id);
1261 dbg("error to get ef[0x%x] (file_meta->file_id) ", file_meta->file_id);
1262 rt = SIM_ACCESS_FAILED;
1264 ur = tcore_user_request_ref(ur);
1265 _next_from_get_file_info(co_sim, ur, file_meta->file_id, rt);
1267 dbg(" Function exit");
1270 static void _response_get_file_data(TcorePending *p, int data_len, const void *data, void *user_data)
1272 const TcoreATResponse *resp = data;
1273 UserRequest *ur = NULL;
1274 CoreObject *co_sim = NULL;
1275 struct s_sim_property *file_meta = NULL;
1276 GSList *tokens = NULL;
1277 enum tel_sim_access_result rt;
1278 struct tel_sim_imsi *imsi = NULL;
1279 struct tel_sim_service_table *svct = NULL;
1280 struct tel_sim_ecc *ecc = NULL;
1281 struct tel_sim_msisdn *msisdn = NULL;
1282 struct tel_sim_opl *opl = NULL;
1283 struct tel_sim_pnn *pnn = NULL;
1284 struct tel_sim_cfis *cf = NULL;
1285 struct tel_sim_mbi *mbi = NULL;
1286 struct tel_sim_mw *mw = NULL;
1287 gboolean dr = FALSE;
1288 const char *line = NULL;
1295 dbg(" Function entry ");
1297 co_sim = tcore_pending_ref_core_object(p);
1298 ur = tcore_pending_ref_user_request(p);
1299 file_meta = (struct s_sim_property *) tcore_user_request_ref_metainfo(ur, NULL);
1301 if (resp->success > 0) {
1304 line = (const char *) resp->lines->data;
1305 tokens = tcore_at_tok_new(line);
1306 if (g_slist_length(tokens) != 3) {
1307 msg("invalid message");
1308 tcore_at_tok_free(tokens);
1312 sw1 = atoi(g_slist_nth_data(tokens, 0));
1313 sw2 = atoi(g_slist_nth_data(tokens, 1));
1314 res = g_slist_nth_data(tokens, 2);
1316 tmp = util_removeQuotes(res);
1317 res = util_hexStringToBytes(tmp);
1318 res_len = strlen((const char *) res);
1319 dbg("res: %s res_len: %d", res, res_len);
1321 if ((sw1 == 0x90 && sw2 == 0x00) || sw1 == 0x91) {
1322 rt = SIM_ACCESS_SUCCESS;
1323 file_meta->files.result = rt;
1324 dbg("file_meta->file_id : %x", file_meta->file_id);
1326 switch (file_meta->file_id) {
1329 dbg("res: %s", res);
1330 imsi = calloc(sizeof(struct tel_sim_imsi),1);
1331 dr = tcore_sim_decode_imsi(imsi, (unsigned char *) res, res_len);
1333 dbg("imsi decoding failed");
1335 _sim_check_identity(co_sim, imsi);
1336 tcore_sim_set_imsi(co_sim, imsi);
1344 dr = tcore_sim_decode_iccid(&file_meta->files.data.iccid, (unsigned char *) res, res_len);
1347 case SIM_EF_ELP: /* 2G EF - 2 bytes decoding*/
1348 case SIM_EF_USIM_LI: /* 3G EF - 2 bytes decoding*/
1349 case SIM_EF_USIM_PL: /* 3G EF - same as EFELP, so 2 byte decoding*/
1350 case SIM_EF_LP: /* 1 byte encoding*/
1351 if (tcore_sim_get_type(co_sim) == SIM_TYPE_GSM && file_meta->file_id == SIM_EF_LP) {
1352 /*2G LP(0x6F05) has 1 byte for each language*/
1353 dr = tcore_sim_decode_lp(&file_meta->files.data.language, (unsigned char *) res, res_len);
1355 /*3G LI(0x6F05)/PL(0x2F05), 2G ELP(0x2F05) has 2 bytes for each language*/
1356 dr = tcore_sim_decode_li(file_meta->file_id, &file_meta->files.data.language, (unsigned char *) res, res_len);
1361 dr = tcore_sim_decode_spn(&file_meta->files.data.spn, (unsigned char *) res, res_len);
1365 dr = tcore_sim_decode_spdi(&file_meta->files.data.spdi, (unsigned char *) res, res_len);
1368 case SIM_EF_SST: //EF UST has same address
1369 svct = calloc(sizeof(struct tel_sim_service_table),1);
1370 if(tcore_sim_get_type(co_sim) == SIM_TYPE_GSM) {
1371 dr = tcore_sim_decode_sst(&svct->sst , (unsigned char *) res, res_len);
1372 }else if(tcore_sim_get_type(co_sim) == SIM_TYPE_USIM) {
1373 dr = tcore_sim_decode_ust(&svct->ust , (unsigned char *) res, res_len);
1375 dbg("err not handled tcore_sim_get_type(o)[%d] in here",tcore_sim_get_type(co_sim));
1378 dbg("SST/UST decoding failed");
1380 tcore_sim_set_service_table(co_sim, svct);
1387 if (tcore_sim_get_type(co_sim) == SIM_TYPE_GSM) {
1388 dr = tcore_sim_decode_ecc(&file_meta->files.data.ecc, (unsigned char *) res, res_len);
1389 } else if (tcore_sim_get_type(co_sim) == SIM_TYPE_USIM) {
1390 ecc = calloc(sizeof(struct tel_sim_ecc),1);
1391 dbg("decode w/ index [%d]", file_meta->current_index);
1392 dr = tcore_sim_decode_uecc(ecc, (unsigned char *) res, res_len);
1394 memcpy(&file_meta->files.data.ecc.ecc[file_meta->files.data.ecc.ecc_count], ecc, sizeof(struct tel_sim_ecc));
1395 file_meta->files.data.ecc.ecc_count++;
1400 dbg("err not handled tcore_sim_get_type(o)[%d] in here", tcore_sim_get_type(co_sim));
1405 dbg("decode w/ index [%d]", file_meta->current_index);
1406 msisdn = calloc(sizeof(struct tel_sim_msisdn),1);
1407 dr = tcore_sim_decode_msisdn(msisdn, (unsigned char *) res, res_len);
1409 memcpy(&file_meta->files.data.msisdn_list.msisdn[file_meta->files.data.msisdn_list.count], msisdn, sizeof(struct tel_sim_msisdn));
1410 file_meta->files.data.msisdn_list.count++;
1417 dbg("decode w/ index [%d]", file_meta->current_index);
1418 opl = calloc(sizeof(struct tel_sim_opl),1);
1419 dr = tcore_sim_decode_opl(opl, (unsigned char *) res, res_len);
1421 memcpy(&file_meta->files.data.opl.opl[file_meta->files.data.opl.opl_count], opl, sizeof(struct tel_sim_opl));
1422 file_meta->files.data.opl.opl_count++;
1427 dbg("decode w/ index [%d]", file_meta->current_index);
1428 pnn = calloc(sizeof(struct tel_sim_pnn),1);
1429 dr = tcore_sim_decode_pnn(pnn, (unsigned char *) res, res_len);
1431 memcpy(&file_meta->files.data.pnn.pnn[file_meta->files.data.pnn.pnn_count], pnn, sizeof(struct tel_sim_pnn));
1432 file_meta->files.data.pnn.pnn_count++;
1438 case SIM_EF_OPLMN_ACT:
1439 dr = tcore_sim_decode_oplmnwact(&file_meta->files.data.opwa, (unsigned char *) res, res_len);
1442 case SIM_EF_CPHS_CUSTOMER_SERVICE_PROFILE:
1443 /* dr = tcore_sim_decode_csp(&po->p_cphs->csp, p_data->response, p_data->response_len);*/
1446 case SIM_EF_USIM_MBI: //linear type
1447 mbi = calloc(sizeof(struct tel_sim_mbi),1);
1448 dr = tcore_sim_decode_mbi(mbi, (unsigned char *) res, res_len);
1450 memcpy( &file_meta->mbi_list.mbi[file_meta->mbi_list.profile_count], mbi, sizeof(struct tel_sim_mbi) );
1451 file_meta->mbi_list.profile_count++;
1452 dbg("mbi count[%d]", file_meta->mbi_list.profile_count);
1453 dbg("voice_index[%d]", file_meta->mbi_list.mbi[file_meta->mbi_list.profile_count -1].voice_index);
1454 dbg("fax_index[%d]", file_meta->mbi_list.mbi[file_meta->mbi_list.profile_count -1].fax_index);
1455 dbg("email_index[%d]", file_meta->mbi_list.mbi[file_meta->mbi_list.profile_count -1].email_index);
1456 dbg("other_index[%d]", file_meta->mbi_list.mbi[file_meta->mbi_list.profile_count -1].other_index);
1457 dbg("video_index[%d]", file_meta->mbi_list.mbi[file_meta->mbi_list.profile_count -1].video_index);
1463 case SIM_EF_CPHS_MAILBOX_NUMBERS: // linear type
1464 case SIM_EF_MBDN: //linear type
1465 dr = tcore_sim_decode_xdn(&file_meta->mb_list[file_meta->current_index-1].number_info, (unsigned char *) res, res_len);
1466 file_meta->mb_list[file_meta->current_index-1].rec_index = file_meta->current_index;
1469 case SIM_EF_CPHS_VOICE_MSG_WAITING: // transparent type
1470 dr = tcore_sim_decode_vmwf(&file_meta->files.data.mw.cphs_mw, (unsigned char *) res, res_len);
1473 case SIM_EF_USIM_MWIS: //linear type
1474 mw = calloc(sizeof(struct tel_sim_mw),1);
1475 dr = tcore_sim_decode_mwis(mw, (unsigned char *) res, res_len);
1477 memcpy( &file_meta->files.data.mw.mw_list.mw[file_meta->files.data.mw.mw_list.profile_count], mw, sizeof(struct tel_sim_mw) );
1478 file_meta->files.data.mw.mw_list.mw[file_meta->files.data.mw.mw_list.profile_count].rec_index = file_meta->current_index;
1479 file_meta->files.data.mw.mw_list.profile_count++;
1485 case SIM_EF_CPHS_CALL_FORWARD_FLAGS: //transparent type
1486 dr = tcore_sim_decode_cff(&file_meta->files.data.cf.cphs_cf, (unsigned char *) res, res_len);
1489 case SIM_EF_USIM_CFIS: //linear type
1490 cf = calloc(sizeof(struct tel_sim_cfis),1);
1491 dr = tcore_sim_decode_cfis(cf, (unsigned char *) res, res_len);
1493 memcpy( &file_meta->files.data.cf.cf_list.cf[file_meta->files.data.cf.cf_list.profile_count], cf, sizeof(struct tel_sim_cfis) );
1494 file_meta->files.data.cf.cf_list.cf[file_meta->files.data.cf.cf_list.profile_count].rec_index = file_meta->current_index;
1495 file_meta->files.data.cf.cf_list.profile_count++;
1501 case SIM_EF_CPHS_SERVICE_STRING_TABLE:
1502 dbg(" not handled -SIM_EF_CPHS_SERVICE_STRING_TABLE ");
1505 case SIM_EF_CPHS_OPERATOR_NAME_STRING:
1506 dr = tcore_sim_decode_ons((unsigned char*)&file_meta->files.data.cphs_net.full_name, (unsigned char *) res, res_len);
1507 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);
1510 case SIM_EF_CPHS_DYNAMICFLAGS:
1511 /* dr = tcore_sim_decode_dynamic_flag(&po->p_cphs->dflagsinfo, p_data->response, p_data->response_len);*/
1514 case SIM_EF_CPHS_DYNAMIC2FLAG:
1515 /* dr = tcore_sim_decode_dynamic2_flag(&po->p_cphs->d2flagsinfo, p_data->response, p_data->response_len);*/
1518 case SIM_EF_CPHS_CPHS_INFO:
1519 dr = tcore_sim_decode_cphs_info(&file_meta->files.data.cphs, (unsigned char *) res, res_len);
1522 case SIM_EF_CPHS_OPERATOR_NAME_SHORT_FORM_STRING:
1523 dr = tcore_sim_decode_short_ons((unsigned char*)&file_meta->files.data.cphs_net.short_name, (unsigned char *) res, res_len);
1526 case SIM_EF_CPHS_INFORMATION_NUMBERS:
1527 /* dr = tcore_sim_decode_information_number(&po->p_cphs->infn, p_data->response, p_data->response_len);*/
1531 dbg("File Decoding Failed - not handled File[0x%x]", file_meta->file_id);
1536 rt = _decode_status_word(sw1, sw2);
1537 file_meta->files.result = rt;
1541 tcore_at_tok_free(tokens);
1543 dbg("RESPONSE NOK");
1544 dbg("error to get ef[0x%x]", file_meta->file_id);
1545 rt = SIM_ACCESS_FAILED;
1547 ur = tcore_user_request_ref(ur);
1549 dbg("Calling _next_from_get_file_data");
1550 _next_from_get_file_data(tcore_pending_ref_core_object(p), ur, rt, dr);
1551 dbg(" Function exit");
1554 static void _on_response_get_retry_count(TcorePending *p, int data_len, const void *data, void *user_data)
1556 const TcoreATResponse *resp = data;
1557 UserRequest *ur = NULL;
1558 CoreObject *co_sim = NULL;
1559 struct s_sim_property *sp = NULL;
1560 GSList *tokens = NULL;
1561 const char *line = NULL;
1562 struct tresp_sim_verify_pins v_pin = {0, };
1563 struct tresp_sim_verify_puks v_puk = {0, };
1564 struct tresp_sim_change_pins change_pin = {0, };
1565 struct tresp_sim_disable_facility dis_facility = {0, };
1566 struct tresp_sim_enable_facility en_facility = {0, };
1568 int attempts_left = 0;
1569 int time_penalty = 0;
1571 dbg(" Function entry ");
1573 co_sim = tcore_pending_ref_core_object(p);
1574 sp = tcore_sim_ref_userdata(co_sim);
1575 ur = tcore_pending_ref_user_request(p);
1577 if (resp->success > 0) {
1580 line = (const char *) resp->lines->data;
1581 tokens = tcore_at_tok_new(line);
1582 if (g_slist_length(tokens) < 3) {
1583 msg("invalid message");
1584 tcore_at_tok_free(tokens);
1588 lock_type = atoi(g_slist_nth_data(tokens, 0));
1589 attempts_left = atoi(g_slist_nth_data(tokens, 1));
1590 time_penalty = atoi(g_slist_nth_data(tokens, 2));
1592 dbg("lock_type = %d, attempts_left = %d, time_penalty = %d",
1593 lock_type, attempts_left, time_penalty);
1595 switch (sp->current_sec_op) {
1596 case SEC_PIN1_VERIFY:
1597 case SEC_PIN2_VERIFY:
1598 case SEC_SIM_VERIFY:
1599 case SEC_ADM_VERIFY:
1600 v_pin.result = SIM_INCORRECT_PASSWORD;
1601 v_pin.pin_type = _sim_get_current_pin_facility(sp->current_sec_op);
1602 v_pin.retry_count = attempts_left;
1603 tcore_user_request_send_response(ur, _find_resp_command(ur),
1604 sizeof(struct tresp_sim_verify_pins), &v_pin);
1607 case SEC_PUK1_VERIFY:
1608 case SEC_PUK2_VERIFY:
1609 v_puk.result = SIM_INCORRECT_PASSWORD;
1610 v_puk.pin_type = _sim_get_current_pin_facility(sp->current_sec_op);
1611 v_puk.retry_count = attempts_left;
1612 tcore_user_request_send_response(ur, _find_resp_command(ur),
1613 sizeof(struct tresp_sim_verify_puks), &v_puk);
1616 case SEC_PIN1_CHANGE:
1617 case SEC_PIN2_CHANGE:
1618 change_pin.result = SIM_INCORRECT_PASSWORD;
1619 change_pin.pin_type = _sim_get_current_pin_facility(sp->current_sec_op);
1620 change_pin.retry_count = attempts_left;
1621 tcore_user_request_send_response(ur, _find_resp_command(ur),
1622 sizeof(struct tresp_sim_change_pins), &change_pin);
1625 case SEC_PIN1_DISABLE:
1626 case SEC_PIN2_DISABLE:
1627 case SEC_FDN_DISABLE:
1628 case SEC_SIM_DISABLE:
1629 case SEC_NET_DISABLE:
1630 case SEC_NS_DISABLE:
1631 case SEC_SP_DISABLE:
1632 case SEC_CP_DISABLE:
1633 dis_facility.result = SIM_INCORRECT_PASSWORD;
1634 dis_facility.type = _sim_get_current_pin_facility(sp->current_sec_op);
1635 dis_facility.retry_count = attempts_left;
1636 tcore_user_request_send_response(ur, _find_resp_command(ur),
1637 sizeof(struct tresp_sim_disable_facility), &dis_facility);
1640 case SEC_PIN1_ENABLE:
1641 case SEC_PIN2_ENABLE:
1642 case SEC_FDN_ENABLE:
1643 case SEC_SIM_ENABLE:
1644 case SEC_NET_ENABLE:
1648 en_facility.result = SIM_INCORRECT_PASSWORD;
1649 en_facility.type = _sim_get_current_pin_facility(sp->current_sec_op);
1650 en_facility.retry_count = attempts_left;
1651 tcore_user_request_send_response(ur, _find_resp_command(ur),
1652 sizeof(struct tresp_sim_enable_facility), &en_facility);
1656 dbg("not handled sec op[%d]", sp->current_sec_op);
1659 tcore_at_tok_free(tokens);
1661 dbg(" Function exit");
1664 static gboolean _get_sim_type(CoreObject *o)
1666 TcoreHal *hal = NULL;
1667 TcoreATRequest *req = NULL;
1668 TcorePending *pending = NULL;
1669 UserRequest *ur = NULL;
1670 char *cmd_str = NULL;
1672 dbg(" Function entry ");
1674 hal = tcore_object_get_hal(o);
1675 pending = tcore_pending_new(o, 0);
1677 cmd_str = g_strdup_printf("AT+XUICC?");
1678 req = tcore_at_request_new(cmd_str, "+XUICC:", TCORE_AT_SINGLELINE);
1680 dbg("cmd : %s, prefix(if any) :%s, cmd_len : %d", req->cmd, req->prefix, strlen(req->cmd));
1682 tcore_pending_set_request_data(pending, 0, req);
1683 tcore_pending_set_response_callback(pending, _response_get_sim_type, hal);
1684 tcore_pending_link_user_request(pending, ur);
1685 tcore_hal_send_request(hal, pending);
1688 dbg(" Function exit");
1692 static TReturn _get_file_info(CoreObject *o, UserRequest *ur, const enum tel_sim_file_id ef)
1694 TcoreHal *hal = NULL;
1695 TcorePending *pending = NULL;
1696 struct s_sim_property file_meta = {0, };
1697 char *cmd_str = NULL;
1698 TReturn ret = TCORE_RETURN_FAILURE;
1701 dbg(" Function entry ");
1703 file_meta.file_id = ef;
1704 dbg("file_meta.file_id: [0x%02x]", file_meta.file_id);
1705 hal = tcore_object_get_hal(o);
1706 dbg("hal: %x", hal);
1708 trt = tcore_user_request_set_metainfo(ur, sizeof(struct s_sim_property), &file_meta);
1709 dbg("trt[%d]", trt);
1710 cmd_str = g_strdup_printf("AT+CRSM=192, %d", ef); /*command - 192 : GET RESPONSE*/
1711 dbg("cmd_str: %s", cmd_str);
1713 pending = tcore_at_pending_new(o, cmd_str, "+CRSM:", TCORE_AT_SINGLELINE, _response_get_file_info, NULL);
1714 tcore_pending_link_user_request(pending, ur);
1715 ret = tcore_hal_send_request(hal, pending);
1716 if (TCORE_RETURN_SUCCESS != ret) {
1717 tcore_user_request_free(ur);
1720 dbg(" Function exit");
1721 return TCORE_RETURN_SUCCESS;
1724 static gboolean _get_file_data(CoreObject *o, UserRequest *ur, const enum tel_sim_file_id ef, const int offset, const int length)
1726 TcoreHal *hal = NULL;
1727 TcoreATRequest *req = NULL;
1728 TcorePending *pending = NULL;
1729 char *cmd_str = NULL;
1734 dbg(" Function entry ");
1735 hal = tcore_object_get_hal(o);
1736 pending = tcore_pending_new(o, 0);
1738 dbg("file_id: %x", ef);
1740 p1 = (unsigned char) (offset & 0xFF00) >> 8;
1741 p2 = (unsigned char) offset & 0x00FF; // offset low
1742 p3 = (unsigned char) length;
1744 cmd_str = g_strdup_printf("AT+CRSM=176, %d, %d, %d, %d", ef, p1, p2, p3); /*command - 176 : READ BINARY*/
1746 req = tcore_at_request_new(cmd_str, "+CRSM:", TCORE_AT_SINGLELINE);
1748 dbg("cmd : %s, prefix(if any) :%s, cmd_len : %d", req->cmd, req->prefix, strlen(req->cmd));
1750 tcore_pending_set_request_data(pending, 0, req);
1751 tcore_pending_set_response_callback(pending, _response_get_file_data, hal);
1752 tcore_pending_link_user_request(pending, ur);
1753 tcore_hal_send_request(hal, pending);
1756 dbg(" Function exit");
1760 static gboolean _get_file_record(CoreObject *o, UserRequest *ur, const enum tel_sim_file_id ef, const int index, const int length)
1762 TcoreHal *hal = NULL;
1763 TcoreATRequest *req = NULL;
1764 TcorePending *pending = NULL;
1765 char *cmd_str = NULL;
1770 dbg(" Function entry ");
1772 hal = tcore_object_get_hal(o);
1773 pending = tcore_pending_new(o, 0);
1775 p1 = (unsigned char) index;
1776 p2 = (unsigned char) 0x04; /* 0x4 for absolute mode */
1777 p3 = (unsigned char) length;
1779 cmd_str = g_strdup_printf("AT+CRSM=178, %d, %d, %d, %d", ef, p1, p2, p3); /*command - 178 : READ RECORD*/
1781 req = tcore_at_request_new(cmd_str, "+CRSM:", TCORE_AT_SINGLELINE);
1783 dbg("cmd : %s, prefix(if any) :%s, cmd_len : %d", req->cmd, req->prefix, strlen(req->cmd));
1785 tcore_pending_set_request_data(pending, 0, req);
1786 tcore_pending_set_response_callback(pending, _response_get_file_data, hal);
1787 tcore_pending_link_user_request(pending, ur);
1788 tcore_hal_send_request(hal, pending);
1791 dbg(" Function exit");
1795 static TReturn _get_retry_count(CoreObject *o, UserRequest *ur)
1797 TcoreHal *hal = NULL;
1798 TcoreATRequest *req = NULL;
1799 TcorePending *pending = NULL;
1800 char *cmd_str = NULL;
1802 struct s_sim_property *sp = NULL;
1803 const struct treq_sim_get_lock_info *req_data = NULL;
1805 dbg(" Function entry ");
1807 hal = tcore_object_get_hal(o);
1808 pending = tcore_pending_new(o, 0);
1809 req_data = tcore_user_request_ref_data(ur, NULL);
1810 sp = tcore_sim_ref_userdata(o);
1812 switch (sp->current_sec_op) {
1813 case SEC_PIN1_VERIFY:
1814 case SEC_PIN1_CHANGE:
1815 case SEC_PIN1_ENABLE:
1816 case SEC_PIN1_DISABLE:
1820 case SEC_PIN2_VERIFY:
1821 case SEC_PIN2_CHANGE:
1822 case SEC_PIN2_ENABLE:
1823 case SEC_PIN2_DISABLE:
1824 case SEC_FDN_ENABLE:
1825 case SEC_FDN_DISABLE:
1829 case SEC_PUK1_VERIFY:
1833 case SEC_PUK2_VERIFY:
1837 case SEC_NET_ENABLE:
1838 case SEC_NET_DISABLE:
1843 case SEC_NS_DISABLE:
1848 case SEC_SP_DISABLE:
1853 case SEC_CP_DISABLE:
1857 case SEC_ADM_VERIFY:
1865 cmd_str = g_strdup_printf("AT+XPINCNT=%d", lock_type);
1866 req = tcore_at_request_new(cmd_str, "+XPINCNT:", TCORE_AT_SINGLELINE);
1867 dbg("cmd : %s, prefix(if any) :%s, cmd_len : %d", req->cmd, req->prefix, strlen(req->cmd));
1869 tcore_pending_set_request_data(pending, 0, req);
1870 tcore_pending_set_response_callback(pending, _on_response_get_retry_count, hal);
1871 tcore_pending_link_user_request(pending, ur);
1872 tcore_hal_send_request(hal, pending);
1875 dbg(" Function exit");
1876 return TCORE_RETURN_SUCCESS;
1880 static gboolean on_event_facility_lock_status(CoreObject *o, const void *event_info, void *user_data)
1882 struct s_sim_property *sp = NULL;
1884 GSList *tokens = NULL;
1885 GSList *lines = NULL;
1887 dbg("Function entry");
1890 sp = tcore_sim_ref_userdata(o);
1891 lines = (GSList *) event_info;
1892 if (1 != g_slist_length(lines)) {
1893 dbg("unsolicited msg but multiple line");
1896 line = (char *) (lines->data);
1897 tokens = tcore_at_tok_new(line);
1898 if (g_slist_length(tokens) != 1) {
1899 msg("invalid message");
1900 tcore_at_tok_free(tokens);
1905 dbg(" Function exit");
1907 tcore_at_tok_free(tokens);
1912 static gboolean on_event_pin_status(CoreObject *o, const void *event_info, void *user_data)
1915 struct s_sim_property *sp = NULL;
1916 enum tel_sim_status sim_status = SIM_STATUS_INITIALIZING;
1917 GSList *tokens = NULL;
1918 GSList *lines = NULL;
1919 const char *line = NULL;
1923 dbg(" Function entry ");
1925 sp = tcore_sim_ref_userdata(o);
1927 lines = (GSList *) event_info;
1928 if (1 != g_slist_length(lines)) {
1929 dbg("unsolicited msg but multiple line");
1932 line = (char *) (lines->data);
1934 tokens = tcore_at_tok_new(line);
1936 if (g_slist_length(tokens) == 4) {
1937 sim_state = atoi(g_slist_nth_data(tokens, 1));
1938 sms_state = atoi(g_slist_nth_data(tokens, 3));
1939 } else if (g_slist_length(tokens) == 1)
1940 sim_state = atoi(g_slist_nth_data(tokens, 0));
1942 msg("invalid message");
1943 tcore_at_tok_free(tokens);
1947 switch (sim_state) {
1948 case 0: // sim state = SIM not present
1949 sim_status = SIM_STATUS_CARD_NOT_PRESENT;
1953 case 1: // sim state = PIN verification needed
1954 sim_status = SIM_STATUS_PIN_REQUIRED;
1955 dbg(" PIN required");
1958 case 2: // sim state = PIN verification not needed \96 Ready
1959 case 3: // sim state = PIN verified \96 Ready
1960 sim_status = SIM_STATUS_INITIALIZING;
1961 dbg(" Inside PIN disabled at BOOT UP");
1964 case 4: // sim state = PUK verification needed
1965 sim_status = SIM_STATUS_PUK_REQUIRED;
1966 dbg(" PUK required");
1969 case 5: // sim state = SIM permanently blocked
1970 sim_status = SIM_STATUS_CARD_BLOCKED;
1971 dbg(" Card permanently blocked");
1974 case 6: // sim state = SIM error
1975 sim_status = SIM_STATUS_CARD_ERROR;
1976 dbg("SIM card error ");
1979 case 7: // sim state = ready for attach (+COPS)
1980 sim_status = SIM_STATUS_INIT_COMPLETED;
1981 dbg("Modem init completed");
1984 case 8: // sim state = SIM Technical Problem
1985 sim_status = SIM_STATUS_CARD_ERROR;
1986 dbg("SIM unavailable");
1989 case 9: // sim state = SIM removed
1990 sim_status = SIM_STATUS_CARD_REMOVED;
1994 case 99: // sim state = SIM State Unknown
1995 sim_status = SIM_STATUS_UNKNOWN;
1996 dbg("SIM State Unknown");
2000 dbg("SIM Status : %d", sim_status);
2004 dbg(" not handled SEC lock type ");
2008 switch (sim_status) {
2009 case SIM_STATUS_INIT_COMPLETED:
2010 if (tcore_sim_get_type(o) == SIM_TYPE_UNKNOWN)
2013 _sim_status_update(o, sim_status);
2016 struct tnoti_sms_ready_status readyStatusInfo = {0, };
2018 TcorePlugin *plugin;
2021 readyStatusInfo.status = TRUE;
2022 plugin = tcore_object_ref_plugin(o);
2023 sms = tcore_plugin_ref_core_object(plugin, CORE_OBJECT_TYPE_SMS);
2024 tcore_sms_set_ready_status(sms, readyStatusInfo.status);
2026 tcore_server_send_notification(tcore_plugin_ref_server(plugin), sms, TNOTI_SMS_DEVICE_READY, sizeof(struct tnoti_sms_ready_status), &readyStatusInfo);
2030 case SIM_STATUS_INITIALIZING:
2031 case SIM_STATUS_PIN_REQUIRED:
2032 case SIM_STATUS_PUK_REQUIRED:
2033 case SIM_STATUS_CARD_BLOCKED:
2034 case SIM_STATUS_NCK_REQUIRED:
2035 case SIM_STATUS_NSCK_REQUIRED:
2036 case SIM_STATUS_SPCK_REQUIRED:
2037 case SIM_STATUS_CCK_REQUIRED:
2038 case SIM_STATUS_LOCK_REQUIRED:
2039 _sim_status_update(o, sim_status);
2042 case SIM_STATUS_CARD_REMOVED:
2043 case SIM_STATUS_CARD_NOT_PRESENT:
2044 case SIM_STATUS_CARD_ERROR:
2045 if (sim_status == SIM_STATUS_CARD_NOT_PRESENT && tcore_sim_get_status(o) != SIM_STATUS_UNKNOWN) {
2046 dbg("[SIM]SIM CARD REMOVED!!");
2047 sim_status = SIM_STATUS_CARD_REMOVED;
2050 tcore_sim_set_type(o, SIM_TYPE_UNKNOWN);
2051 _sim_status_update(o, sim_status);
2055 dbg("not handled status[%d]", sim_status);
2060 dbg(" Function exit");
2062 tcore_at_tok_free(tokens);
2066 static void on_response_get_sim_status(TcorePending *p, int data_len, const void *data, void *user_data)
2068 const TcoreATResponse *resp = data;
2069 CoreObject *co_sim = NULL;
2071 dbg(" Function entry ");
2073 co_sim = tcore_pending_ref_core_object(p);
2075 if (resp->success > 0) {
2078 on_event_pin_status(co_sim, resp->lines, NULL);
2080 dbg("RESPONSE NOK");
2083 dbg(" Function exit");
2086 static enum tcore_hook_return on_hook_modem_power(Server *s, CoreObject *source, enum tcore_notification_command command,
2087 unsigned int data_len, void *data, void *user_data)
2089 TcorePlugin *plugin = tcore_object_ref_plugin(source);
2090 CoreObject *co_sim = tcore_plugin_ref_core_object(plugin, CORE_OBJECT_TYPE_SIM);
2093 return TCORE_HOOK_RETURN_CONTINUE;
2095 dbg("Get SIM status");
2097 sim_prepare_and_send_pending_request(co_sim, "AT+XSIMSTATE?", "+XSIMSTATE:", TCORE_AT_SINGLELINE, on_response_get_sim_status);
2099 return TCORE_HOOK_RETURN_CONTINUE;
2102 static void on_response_verify_pins(TcorePending *p, int data_len, const void *data, void *user_data)
2104 const TcoreATResponse *resp = data;
2105 UserRequest *ur = NULL;
2106 CoreObject *co_sim = NULL;
2107 struct s_sim_property *sp = NULL;
2108 GSList *tokens = NULL;
2109 struct tresp_sim_verify_pins res;
2110 GQueue *queue = NULL;
2114 dbg(" Function entry ");
2116 co_sim = tcore_pending_ref_core_object(p);
2117 sp = tcore_sim_ref_userdata(co_sim);
2118 ur = tcore_pending_ref_user_request(p);
2120 memset(&res, 0, sizeof(struct tresp_sim_verify_pins));
2122 if (resp->success > 0) {
2124 res.result = SIM_PIN_OPERATION_SUCCESS;
2125 res.pin_type = _sim_get_current_pin_facility(sp->current_sec_op);
2126 if (res.pin_type == SIM_PTYPE_PIN1 || res.pin_type == SIM_PTYPE_SIM) {
2127 if (tcore_sim_get_status(co_sim) != SIM_STATUS_INIT_COMPLETED)
2128 _sim_status_update(co_sim, SIM_STATUS_INITIALIZING);
2130 tcore_user_request_send_response(ur, _find_resp_command(ur), sizeof(struct tresp_sim_verify_pins), &res);
2132 dbg("RESPONSE NOK");
2133 line = (const char *) resp->final_response;
2134 tokens = tcore_at_tok_new(line);
2135 if (g_slist_length(tokens) < 1) {
2136 dbg("err cause not specified or string corrupted");
2137 res.result = TCORE_RETURN_3GPP_ERROR;
2138 tcore_user_request_send_response(ur, _find_resp_command(ur), sizeof(struct tresp_sim_verify_pins), &res);
2140 err = atoi(g_slist_nth_data(tokens, 0));
2141 dbg("on_response_verify_pins: err = %d", err);
2142 queue = tcore_object_ref_user_data(co_sim);
2143 ur = tcore_user_request_ref(ur);
2144 _get_retry_count(co_sim, ur);
2146 tcore_at_tok_free(tokens);
2148 dbg(" Function exit");
2151 static void on_response_verify_puks(TcorePending *p, int data_len, const void *data, void *user_data)
2153 const TcoreATResponse *resp = data;
2154 UserRequest *ur = NULL;
2155 CoreObject *co_sim = NULL;
2156 struct s_sim_property *sp = NULL;
2157 GSList *tokens = NULL;
2158 struct tresp_sim_verify_puks res;
2159 GQueue *queue = NULL;
2163 dbg(" Function entry ");
2165 co_sim = tcore_pending_ref_core_object(p);
2166 sp = tcore_sim_ref_userdata(co_sim);
2167 ur = tcore_pending_ref_user_request(p);
2169 memset(&res, 0, sizeof(struct tresp_sim_verify_pins));
2171 if (resp->success > 0) {
2173 res.result = SIM_PIN_OPERATION_SUCCESS;
2174 res.pin_type = _sim_get_current_pin_facility(sp->current_sec_op);
2175 tcore_user_request_send_response(ur, _find_resp_command(ur), sizeof(struct tresp_sim_verify_pins), &res);
2177 dbg("RESPONSE NOK");
2178 line = (const char *) resp->final_response;
2179 tokens = tcore_at_tok_new(line);
2181 if (g_slist_length(tokens) < 1) {
2182 dbg("err cause not specified or string corrupted");
2183 res.result = TCORE_RETURN_3GPP_ERROR;
2184 tcore_user_request_send_response(ur, _find_resp_command(ur), sizeof(struct tresp_sim_verify_pins), &res);
2186 err = atoi(g_slist_nth_data(tokens, 0));
2187 queue = tcore_object_ref_user_data(co_sim);
2188 ur = tcore_user_request_ref(ur);
2189 _get_retry_count(co_sim, ur);
2191 tcore_at_tok_free(tokens);
2193 dbg(" Function exit");
2196 static void on_response_change_pins(TcorePending *p, int data_len, const void *data, void *user_data)
2198 const TcoreATResponse *resp = data;
2199 UserRequest *ur = NULL;
2200 CoreObject *co_sim = NULL;
2201 struct s_sim_property *sp = NULL;
2202 GSList *tokens = NULL;
2203 struct tresp_sim_change_pins res;
2208 dbg(" Function entry ");
2210 co_sim = tcore_pending_ref_core_object(p);
2211 sp = tcore_sim_ref_userdata(co_sim);
2212 ur = tcore_pending_ref_user_request(p);
2214 memset(&res, 0, sizeof(struct tresp_sim_change_pins));
2216 if (resp->success > 0) {
2218 res.result = SIM_PIN_OPERATION_SUCCESS;
2219 res.pin_type = _sim_get_current_pin_facility(sp->current_sec_op);
2220 tcore_user_request_send_response(ur, _find_resp_command(ur), sizeof(struct tresp_sim_change_pins), &res);
2222 dbg("RESPONSE NOK");
2223 line = (const char *) resp->final_response;
2224 tokens = tcore_at_tok_new(line);
2226 if (g_slist_length(tokens) < 1) {
2227 dbg("err cause not specified or string corrupted");
2228 res.result = TCORE_RETURN_3GPP_ERROR;
2229 tcore_user_request_send_response(ur, _find_resp_command(ur), sizeof(struct tresp_sim_change_pins), &res);
2231 err = atoi(g_slist_nth_data(tokens, 0));
2232 queue = tcore_object_ref_user_data(co_sim);
2233 ur = tcore_user_request_ref(ur);
2234 _get_retry_count(co_sim, ur);
2236 tcore_at_tok_free(tokens);
2238 dbg(" Function exit");
2241 static void on_response_get_facility_status(TcorePending *p, int data_len, const void *data, void *user_data)
2243 const TcoreATResponse *resp = data;
2244 UserRequest *ur = NULL;
2245 GSList *tokens = NULL;
2246 struct tresp_sim_get_facility_status *res = user_data;
2249 dbg(" Function entry ");
2251 ur = tcore_pending_ref_user_request(p);
2253 res->result = SIM_PIN_OPERATION_SUCCESS;
2255 if (resp->success > 0) {
2258 line = (const char *) resp->lines->data;
2259 tokens = tcore_at_tok_new(line);
2260 if (g_slist_length(tokens) != 1) {
2261 msg("invalid message");
2262 tcore_at_tok_free(tokens);
2266 res->b_enable = atoi(g_slist_nth_data(tokens, 0));
2268 dbg("RESPONSE NOK");
2269 res->result = SIM_INCOMPATIBLE_PIN_OPERATION;
2273 tcore_user_request_send_response(ur, _find_resp_command(ur),
2274 sizeof(struct tresp_sim_get_facility_status), res);
2276 tcore_at_tok_free(tokens);
2278 dbg(" Function exit");
2281 static void on_response_enable_facility(TcorePending *p, int data_len, const void *data, void *user_data)
2283 const TcoreATResponse *resp = data;
2284 UserRequest *ur = NULL;
2285 CoreObject *co_sim = NULL;
2286 struct s_sim_property *sp = NULL;
2287 GSList *tokens = NULL;
2288 struct tresp_sim_enable_facility res;
2292 dbg(" Function entry ");
2294 co_sim = tcore_pending_ref_core_object(p);
2295 sp = tcore_sim_ref_userdata(co_sim);
2296 ur = tcore_pending_ref_user_request(p);
2298 memset(&res, 0, sizeof(struct tresp_sim_enable_facility));
2300 res.result = SIM_CARD_ERROR;
2301 res.type = _sim_get_current_pin_facility(sp->current_sec_op);
2303 if (resp->success > 0) {
2306 line = (const char *) resp->lines->data;
2307 tokens = tcore_at_tok_new(line);
2308 if (g_slist_length(tokens) != 1) {
2309 msg("invalid message");
2310 tcore_user_request_send_response(ur, _find_resp_command(ur),
2311 sizeof(struct tresp_sim_enable_facility), &res);
2312 tcore_at_tok_free(tokens);
2316 res.result = SIM_PIN_OPERATION_SUCCESS;
2318 tcore_user_request_send_response(ur, _find_resp_command(ur),
2319 sizeof(struct tresp_sim_enable_facility), &res);
2321 tcore_at_tok_free(tokens);
2323 dbg("RESPONSE NOK");
2324 queue = tcore_object_ref_user_data(co_sim);
2325 ur = tcore_user_request_ref(ur);
2326 _get_retry_count(co_sim, ur);
2328 dbg(" Function exit");
2331 static void on_response_disable_facility(TcorePending *p, int data_len, const void *data, void *user_data)
2333 const TcoreATResponse *resp = data;
2334 UserRequest *ur = NULL;
2335 CoreObject *co_sim = NULL;
2336 struct s_sim_property *sp = NULL;
2337 GSList *tokens = NULL;
2338 struct tresp_sim_disable_facility res;
2342 dbg(" Function entry ");
2344 co_sim = tcore_pending_ref_core_object(p);
2345 sp = tcore_sim_ref_userdata(co_sim);
2346 ur = tcore_pending_ref_user_request(p);
2348 memset(&res, 0, sizeof(struct tresp_sim_disable_facility));
2350 res.result = SIM_CARD_ERROR;
2351 res.type = _sim_get_current_pin_facility(sp->current_sec_op);
2353 if (resp->success > 0) {
2356 line = (const char *) resp->lines->data;
2357 tokens = tcore_at_tok_new(line);
2358 if (g_slist_length(tokens) != 1) {
2359 msg("invalid message");
2360 tcore_user_request_send_response(ur, _find_resp_command(ur),
2361 sizeof(struct tresp_sim_disable_facility), &res);
2362 tcore_at_tok_free(tokens);
2366 res.result = SIM_PIN_OPERATION_SUCCESS;
2368 tcore_user_request_send_response(ur, _find_resp_command(ur),
2369 sizeof(struct tresp_sim_disable_facility), &res);
2371 tcore_at_tok_free(tokens);
2373 dbg("RESPONSE NOK");
2374 queue = tcore_object_ref_user_data(co_sim);
2375 ur = tcore_user_request_ref(ur);
2376 _get_retry_count(co_sim, ur);
2378 dbg(" Function exit");
2381 static void on_response_get_lock_info(TcorePending *p, int data_len, const void *data, void *user_data)
2383 const TcoreATResponse *resp = data;
2384 UserRequest *ur = NULL;
2385 CoreObject *co_sim = NULL;
2386 struct s_sim_property *sp = NULL;
2387 GSList *tokens = NULL;
2389 struct tresp_sim_verify_pins v_pin = {0, };
2390 struct tresp_sim_verify_puks v_puk = {0, };
2391 struct tresp_sim_change_pins change_pin = {0, };
2392 struct tresp_sim_disable_facility dis_facility = {0, };
2393 struct tresp_sim_enable_facility en_facility = {0, };
2395 int attempts_left = 0;
2396 int time_penalty = 0;
2398 dbg(" Function entry ");
2400 co_sim = tcore_pending_ref_core_object(p);
2401 sp = tcore_sim_ref_userdata(co_sim);
2402 ur = tcore_pending_ref_user_request(p);
2404 if (resp->success > 0) {
2407 line = (const char *) resp->lines->data;
2408 tokens = tcore_at_tok_new(line);
2409 if (g_slist_length(tokens) != 3) {
2410 msg("invalid message");
2411 tcore_at_tok_free(tokens);
2415 lock_type = atoi(g_slist_nth_data(tokens, 0));
2416 attempts_left = atoi(g_slist_nth_data(tokens, 1));
2417 time_penalty = atoi(g_slist_nth_data(tokens, 2));
2419 switch (sp->current_sec_op) {
2420 case SEC_PIN1_VERIFY:
2421 case SEC_PIN2_VERIFY:
2422 case SEC_SIM_VERIFY:
2423 case SEC_ADM_VERIFY:
2424 v_pin.result = SIM_INCORRECT_PASSWORD;
2425 v_pin.pin_type = _sim_get_current_pin_facility(sp->current_sec_op);
2426 v_pin.retry_count = attempts_left;
2427 tcore_user_request_send_response(ur, _find_resp_command(ur),
2428 sizeof(struct tresp_sim_verify_pins), &v_pin);
2431 case SEC_PUK1_VERIFY:
2432 case SEC_PUK2_VERIFY:
2433 v_puk.result = SIM_INCORRECT_PASSWORD;
2434 v_puk.pin_type = _sim_get_current_pin_facility(sp->current_sec_op);
2435 v_puk.retry_count = attempts_left;
2436 tcore_user_request_send_response(ur, _find_resp_command(ur),
2437 sizeof(struct tresp_sim_verify_puks), &v_puk);
2440 case SEC_PIN1_CHANGE:
2441 case SEC_PIN2_CHANGE:
2442 change_pin.result = SIM_INCORRECT_PASSWORD;
2443 change_pin.pin_type = _sim_get_current_pin_facility(sp->current_sec_op);
2444 change_pin.retry_count = attempts_left;
2445 tcore_user_request_send_response(ur, _find_resp_command(ur),
2446 sizeof(struct tresp_sim_change_pins), &change_pin);
2449 case SEC_PIN1_DISABLE:
2450 case SEC_PIN2_DISABLE:
2451 case SEC_FDN_DISABLE:
2452 case SEC_SIM_DISABLE:
2453 case SEC_NET_DISABLE:
2454 case SEC_NS_DISABLE:
2455 case SEC_SP_DISABLE:
2456 case SEC_CP_DISABLE:
2457 dis_facility.result = SIM_INCORRECT_PASSWORD;
2458 dis_facility.type = _sim_get_current_pin_facility(sp->current_sec_op);
2459 dis_facility.retry_count = attempts_left;
2460 tcore_user_request_send_response(ur, _find_resp_command(ur),
2461 sizeof(struct tresp_sim_disable_facility), &dis_facility);
2464 case SEC_PIN1_ENABLE:
2465 case SEC_PIN2_ENABLE:
2466 case SEC_FDN_ENABLE:
2467 case SEC_SIM_ENABLE:
2468 case SEC_NET_ENABLE:
2472 en_facility.result = SIM_INCORRECT_PASSWORD;
2473 en_facility.type = _sim_get_current_pin_facility(sp->current_sec_op);
2474 en_facility.retry_count = attempts_left;
2475 tcore_user_request_send_response(ur, _find_resp_command(ur),
2476 sizeof(struct tresp_sim_enable_facility), &en_facility);
2480 dbg("not handled sec op[%d]", sp->current_sec_op);
2483 tcore_at_tok_free(tokens);
2485 dbg(" Function exit");
2488 static void on_response_update_file(TcorePending *p, int data_len, const void *data, void *user_data)
2490 const TcoreATResponse *resp = data;
2491 UserRequest *ur = NULL;
2492 CoreObject *co_sim = NULL;
2493 struct tresp_sim_set_data resp_cf = {0, };
2494 struct tresp_sim_set_data resp_language = {0, };
2495 struct s_sim_property *sp = NULL;
2496 GSList *tokens = NULL;
2497 enum tel_sim_access_result result = SIM_CARD_ERROR;
2502 dbg(" Function entry ");
2504 co_sim = tcore_pending_ref_core_object(p);
2505 ur = tcore_pending_ref_user_request(p);
2506 sp = (struct s_sim_property *) tcore_user_request_ref_metainfo(ur, NULL);
2508 if (resp->success > 0) {
2511 line = (const char *) resp->lines->data;
2512 tokens = tcore_at_tok_new(line);
2513 if (g_slist_length(tokens) != 2) {
2514 msg("invalid message");
2518 sw1 = atoi(g_slist_nth_data(tokens, 0));
2519 sw2 = atoi(g_slist_nth_data(tokens, 1));
2521 if ((sw1 == 0x90 && sw2 == 0x00) || sw1 == 0x91) {
2522 result = SIM_ACCESS_SUCCESS;
2524 result = _decode_status_word(sw1, sw2);
2527 dbg("RESPONSE NOK");
2528 result = SIM_ACCESS_FAILED;
2531 switch (sp->file_id) {
2532 case SIM_EF_CPHS_CALL_FORWARD_FLAGS:
2533 case SIM_EF_USIM_CFIS:
2534 resp_cf.result = result;
2535 tcore_user_request_send_response(ur, _find_resp_command(ur), sizeof(struct tresp_sim_set_data), &resp_cf);
2540 case SIM_EF_USIM_LI:
2541 case SIM_EF_USIM_PL:
2542 resp_language.result = result;
2543 tcore_user_request_send_response(ur, _find_resp_command(ur), sizeof(struct tresp_sim_set_data), &resp_language);
2547 dbg("Invalid File ID - %d", sp->file_id)
2550 tcore_at_tok_free(tokens);
2551 dbg(" Function exit");
2554 static void on_response_transmit_apdu(TcorePending *p, int data_len, const void *data, void *user_data)
2556 const TcoreATResponse *resp = data;
2557 UserRequest *ur = NULL;
2558 CoreObject *co_sim = NULL;
2559 GSList *tokens = NULL;
2560 struct tresp_sim_transmit_apdu res;
2563 dbg(" Function entry ");
2565 co_sim = tcore_pending_ref_core_object(p);
2566 ur = tcore_pending_ref_user_request(p);
2568 memset(&res, 0, sizeof(struct tresp_sim_transmit_apdu));
2569 res.result = SIM_ACCESS_FAILED;
2571 if (resp->success > 0) {
2575 char *decoded_data = NULL;
2576 line = (const char *) resp->lines->data;
2577 tokens = tcore_at_tok_new(line);
2578 if (g_slist_length(tokens) != 2) {
2579 msg("invalid message");
2582 res.apdu_resp_length = atoi(g_slist_nth_data(tokens, 0)) / 2;
2584 tmp = util_removeQuotes(g_slist_nth_data(tokens, 1));
2585 decoded_data = util_hexStringToBytes(tmp);
2587 memcpy((char *) res.apdu_resp, decoded_data, res.apdu_resp_length);
2590 res.result = SIM_ACCESS_SUCCESS;
2593 dbg("RESPONSE NOK");
2597 tcore_user_request_send_response(ur, _find_resp_command(ur), sizeof(struct tresp_sim_transmit_apdu), &res);
2599 tcore_at_tok_free(tokens);
2600 dbg(" Function exit");
2603 static void on_response_get_atr(TcorePending *p, int data_len, const void *data, void *user_data)
2605 const TcoreATResponse *resp = data;
2606 UserRequest *ur = NULL;
2607 GSList *tokens = NULL;
2608 struct tresp_sim_get_atr res;
2611 dbg(" Function entry ");
2613 memset(&res, 0, sizeof(struct tresp_sim_get_atr));
2614 ur = tcore_pending_ref_user_request(p);
2616 res.result = SIM_ACCESS_FAILED;
2617 if (resp->success > 0) {
2621 char *decoded_data = NULL;
2622 line = (const char *) resp->lines->data;
2623 tokens = tcore_at_tok_new(line);
2624 if (g_slist_length(tokens) < 1) {
2625 msg("invalid message");
2629 tmp = util_removeQuotes(g_slist_nth_data(tokens, 0));
2630 decoded_data = util_hexStringToBytes(tmp);
2632 res.atr_length = strlen(decoded_data);
2633 memcpy((char *) res.atr, decoded_data, res.atr_length);
2636 res.result = SIM_ACCESS_SUCCESS;
2639 dbg("RESPONSE NOK");
2644 tcore_user_request_send_response(ur, _find_resp_command(ur), sizeof(struct tresp_sim_get_atr), &res);
2646 tcore_at_tok_free(tokens);
2647 dbg(" Function exit");
2650 static TReturn s_verify_pins(CoreObject *o, UserRequest *ur)
2652 TcoreHal *hal = NULL;
2653 TcoreATRequest *req = NULL;
2654 TcorePending *pending = NULL;
2655 char *cmd_str = NULL;
2656 const struct treq_sim_verify_pins *req_data = NULL;
2657 struct s_sim_property *sp = NULL;
2658 TReturn ret = TCORE_RETURN_FAILURE;
2660 dbg(" Function entry ");
2663 return TCORE_RETURN_EINVAL;
2665 hal = tcore_object_get_hal(o);
2666 if(FALSE == tcore_hal_get_power_state(hal)){
2667 dbg("cp not ready/n");
2668 return TCORE_RETURN_ENOSYS;
2671 sp = tcore_sim_ref_userdata(o);
2672 pending = tcore_pending_new(o, 0);
2673 req_data = tcore_user_request_ref_data(ur, NULL);
2675 if (req_data->pin_type == SIM_PTYPE_PIN1) {
2676 sp->current_sec_op = SEC_PIN1_VERIFY;
2677 cmd_str = g_strdup_printf("AT+CPIN=\"%s\"", req_data->pin);
2678 } else if (req_data->pin_type == SIM_PTYPE_PIN2) {
2679 sp->current_sec_op = SEC_PIN2_VERIFY;
2680 cmd_str = g_strdup_printf("AT+CPIN2=\"%s\"", req_data->pin);
2681 } else if (req_data->pin_type == SIM_PTYPE_SIM) {
2682 sp->current_sec_op = SEC_SIM_VERIFY;
2683 cmd_str = g_strdup_printf("AT+CPIN=\"%s\"", req_data->pin);
2684 } else if (req_data->pin_type == SIM_PTYPE_ADM) {
2685 sp->current_sec_op = SEC_ADM_VERIFY;
2686 cmd_str = g_strdup_printf("AT+CPIN=\"%s\"", req_data->pin);
2688 return TCORE_RETURN_EINVAL;
2691 req = tcore_at_request_new(cmd_str, NULL, TCORE_AT_NO_RESULT);
2693 dbg("cmd : %s, prefix(if any) :%s, cmd_len : %d", req->cmd, req->prefix, strlen(req->cmd));
2695 tcore_pending_set_request_data(pending, 0, req);
2696 tcore_pending_set_response_callback(pending, on_response_verify_pins, hal);
2697 tcore_pending_link_user_request(pending, ur);
2698 ret = tcore_hal_send_request(hal, pending);
2701 dbg(" Function exit");
2705 static TReturn s_verify_puks(CoreObject *o, UserRequest *ur)
2707 TcoreHal *hal = NULL;
2708 TcoreATRequest *req = NULL;
2709 TcorePending *pending = NULL;
2710 char *cmd_str = NULL;
2711 const struct treq_sim_verify_puks *req_data;
2712 struct s_sim_property *sp = NULL;
2713 TReturn ret = TCORE_RETURN_FAILURE;
2715 dbg(" Function entry ");
2718 return TCORE_RETURN_EINVAL;
2720 hal = tcore_object_get_hal(o);
2721 if(FALSE == tcore_hal_get_power_state(hal)){
2722 dbg("cp not ready/n");
2723 return TCORE_RETURN_ENOSYS;
2726 sp = tcore_sim_ref_userdata(o);
2727 pending = tcore_pending_new(o, 0);
2728 req_data = tcore_user_request_ref_data(ur, NULL);
2730 if (req_data->puk_type == SIM_PTYPE_PUK1) {
2731 sp->current_sec_op = SEC_PUK1_VERIFY;
2732 cmd_str = g_strdup_printf("AT+CPIN=\"%s\", \"%s\"", req_data->puk, req_data->pin);
2733 } else if (req_data->puk_type == SIM_PTYPE_PUK2) {
2734 sp->current_sec_op = SEC_PUK2_VERIFY;
2735 cmd_str = g_strdup_printf("AT+CPIN2=\"%s\", \"%s\"", req_data->puk, req_data->pin);
2737 return TCORE_RETURN_EINVAL;
2739 req = tcore_at_request_new(cmd_str, NULL, TCORE_AT_NO_RESULT);
2741 dbg("cmd : %s, prefix(if any) :%s, cmd_len : %d", req->cmd, req->prefix, strlen(req->cmd));
2743 tcore_pending_set_request_data(pending, 0, req);
2744 tcore_pending_set_response_callback(pending, on_response_verify_puks, hal);
2745 tcore_pending_link_user_request(pending, ur);
2746 ret = tcore_hal_send_request(hal, pending);
2749 dbg(" Function exit");
2753 static TReturn s_change_pins(CoreObject *o, UserRequest *ur)
2755 TcoreHal *hal = NULL;
2756 TcoreATRequest *req = NULL;
2757 TcorePending *pending = NULL;
2758 char *cmd_str = NULL;
2759 const struct treq_sim_change_pins *req_data;
2760 struct s_sim_property *sp = NULL;
2763 TReturn ret = TCORE_RETURN_FAILURE;
2765 dbg(" Function entry ");
2768 return TCORE_RETURN_EINVAL;
2770 hal = tcore_object_get_hal(o);
2771 if(FALSE == tcore_hal_get_power_state(hal)){
2772 dbg("cp not ready/n");
2773 return TCORE_RETURN_ENOSYS;
2776 sp = tcore_sim_ref_userdata(o);
2777 pending = tcore_pending_new(o, 0);
2778 req_data = tcore_user_request_ref_data(ur, NULL);
2780 if (req_data->type == SIM_PTYPE_PIN1) {
2781 sp->current_sec_op = SEC_PIN1_CHANGE;
2782 cmd_str = g_strdup_printf("AT+CPWD=\"%s\",\"%s\",\"%s\"", pin1, req_data->old_pin, req_data->new_pin);
2783 } else if (req_data->type == SIM_PTYPE_PIN2) {
2784 sp->current_sec_op = SEC_PIN2_CHANGE;
2785 cmd_str = g_strdup_printf("AT+CPWD=\"%s\",\"%s\",\"%s\"", pin2, req_data->old_pin, req_data->new_pin);
2787 return TCORE_RETURN_EINVAL;
2789 req = tcore_at_request_new(cmd_str, NULL, TCORE_AT_NO_RESULT);
2791 dbg("cmd : %s, prefix(if any) :%s, cmd_len : %d", req->cmd, req->prefix, strlen(req->cmd));
2793 tcore_pending_set_request_data(pending, 0, req);
2794 tcore_pending_set_response_callback(pending, on_response_change_pins, hal);
2795 tcore_pending_link_user_request(pending, ur);
2796 ret = tcore_hal_send_request(hal, pending);
2799 dbg(" Function exit");
2803 static TReturn s_get_facility_status(CoreObject *o, UserRequest *ur)
2805 TcoreHal *hal = NULL;
2806 TcoreATRequest *req = NULL;
2807 TcorePending *pending = NULL;
2808 char *cmd_str = NULL;
2809 const struct treq_sim_get_facility_status *req_data;
2810 struct tresp_sim_get_facility_status *res;
2812 int mode = 2; /* 0:unlock, 1:lock, 2:query*/
2813 TReturn ret = TCORE_RETURN_FAILURE;
2815 dbg(" Function entry ");
2818 return TCORE_RETURN_EINVAL;
2820 hal = tcore_object_get_hal(o);
2821 if(FALSE == tcore_hal_get_power_state(hal)){
2822 dbg("cp not ready/n");
2823 return TCORE_RETURN_ENOSYS;
2826 pending = tcore_pending_new(o, 0);
2827 req_data = tcore_user_request_ref_data(ur, NULL);
2829 res = g_try_new0(struct tresp_sim_get_facility_status, 1);
2831 return TCORE_RETURN_ENOMEM;
2833 res->type = req_data->type;
2835 if (req_data->type == SIM_FACILITY_PS) {
2836 fac = "PS"; /*PH-SIM, Lock PHone to SIM/UICC card*/
2837 } else if (req_data->type == SIM_FACILITY_SC) {
2838 fac = "SC"; /*Lock SIM/UICC card, simply PIN1*/
2839 } else if (req_data->type == SIM_FACILITY_FD) {
2840 fac = "FD"; /*Fixed Dialing Number feature, need PIN2*/
2841 } else if (req_data->type == SIM_FACILITY_PN) {
2842 fac = "PN"; /*Network Personalization*/
2843 } else if (req_data->type == SIM_FACILITY_PU) {
2844 fac = "PU"; /*network sUbset Personalization*/
2845 } else if (req_data->type == SIM_FACILITY_PP) {
2846 fac = "PP"; /*service Provider Personalization*/
2847 } else if (req_data->type == SIM_FACILITY_PC) {
2848 fac = "PC"; /*Corporate Personalization*/
2850 return TCORE_RETURN_EINVAL;
2852 cmd_str = g_strdup_printf("AT+CLCK=\"%s\", %d", fac, mode);
2853 req = tcore_at_request_new(cmd_str, "+CLCK:", TCORE_AT_SINGLELINE);
2855 dbg("cmd : %s, prefix(if any) :%s, cmd_len : %d", req->cmd, req->prefix, strlen(req->cmd));
2857 tcore_pending_set_request_data(pending, 0, req);
2858 tcore_pending_set_response_callback(pending, on_response_get_facility_status, res);
2859 tcore_pending_link_user_request(pending, ur);
2860 ret = tcore_hal_send_request(hal, pending);
2863 dbg(" Function exit");
2867 static TReturn s_enable_facility(CoreObject *o, UserRequest *ur)
2869 TcoreHal *hal = NULL;
2870 TcoreATRequest *req = NULL;
2871 TcorePending *pending = NULL;
2872 char *cmd_str = NULL;
2873 const struct treq_sim_enable_facility *req_data;
2874 struct s_sim_property *sp = NULL;
2876 int mode = 1; /* 0:unlock, 1:lock, 2:query*/
2877 TReturn ret = TCORE_RETURN_FAILURE;
2879 dbg(" Function entry ");
2882 return TCORE_RETURN_EINVAL;
2884 hal = tcore_object_get_hal(o);
2885 if(FALSE == tcore_hal_get_power_state(hal)){
2886 dbg("cp not ready/n");
2887 return TCORE_RETURN_ENOSYS;
2890 sp = tcore_sim_ref_userdata(o);
2891 pending = tcore_pending_new(o, 0);
2892 req_data = tcore_user_request_ref_data(ur, NULL);
2894 if (req_data->type == SIM_FACILITY_PS) {
2895 fac = "PS"; /*PH-SIM, Lock PHone to SIM/UICC card*/
2896 sp->current_sec_op = SEC_SIM_ENABLE;
2897 } else if (req_data->type == SIM_FACILITY_SC) {
2898 fac = "SC"; /*Lock SIM/UICC card, simply PIN1*/
2899 sp->current_sec_op = SEC_PIN1_ENABLE;
2900 } else if (req_data->type == SIM_FACILITY_FD) {
2901 fac = "FD"; /*Fixed Dialing Number feature, need PIN2*/
2902 sp->current_sec_op = SEC_FDN_ENABLE;
2903 } else if (req_data->type == SIM_FACILITY_PN) {
2904 fac = "PN"; /*Network Personalization*/
2905 sp->current_sec_op = SEC_NET_ENABLE;
2906 } else if (req_data->type == SIM_FACILITY_PU) {
2907 fac = "PU"; /*network sUbset Personalization*/
2908 sp->current_sec_op = SEC_NS_ENABLE;
2909 } else if (req_data->type == SIM_FACILITY_PP) {
2910 fac = "PP"; /*service Provider Personalization*/
2911 sp->current_sec_op = SEC_SP_ENABLE;
2912 } else if (req_data->type == SIM_FACILITY_PC) {
2913 fac = "PC"; /*Corporate Personalization*/
2914 sp->current_sec_op = SEC_CP_ENABLE;
2916 return TCORE_RETURN_EINVAL;
2918 cmd_str = g_strdup_printf("AT+CLCK=\"%s\", %d, \"%s\"", fac, mode, req_data->password);
2919 req = tcore_at_request_new(cmd_str, "+CLCK:", TCORE_AT_SINGLELINE);
2921 dbg("cmd : %s, prefix(if any) :%s, cmd_len : %d", req->cmd, req->prefix, strlen(req->cmd));
2923 tcore_pending_set_request_data(pending, 0, req);
2924 tcore_pending_set_response_callback(pending, on_response_enable_facility, hal);
2925 tcore_pending_link_user_request(pending, ur);
2926 ret = tcore_hal_send_request(hal, pending);
2929 dbg(" Function exit");
2933 static TReturn s_disable_facility(CoreObject *o, UserRequest *ur)
2936 TcoreATRequest *req;
2937 TcorePending *pending = NULL;
2938 char *cmd_str = NULL;
2939 const struct treq_sim_enable_facility *req_data;
2940 struct s_sim_property *sp = NULL;
2942 int mode = 0; /* 0:unlock, 1:lock, 2:query*/
2943 TReturn ret = TCORE_RETURN_FAILURE;
2945 dbg(" Function entry ");
2948 return TCORE_RETURN_EINVAL;
2950 hal = tcore_object_get_hal(o);
2951 if(FALSE == tcore_hal_get_power_state(hal)){
2952 dbg("cp not ready/n");
2953 return TCORE_RETURN_ENOSYS;
2956 sp = tcore_sim_ref_userdata(o);
2957 pending = tcore_pending_new(o, 0);
2958 req_data = tcore_user_request_ref_data(ur, NULL);
2960 if (req_data->type == SIM_FACILITY_PS) {
2961 fac = "PS"; /*PH-SIM, Lock PHone to SIM/UICC card*/
2962 sp->current_sec_op = SEC_SIM_DISABLE;
2963 } else if (req_data->type == SIM_FACILITY_SC) {
2964 fac = "SC"; /*Lock SIM/UICC card, simply PIN1*/
2965 sp->current_sec_op = SEC_PIN1_DISABLE;
2966 } else if (req_data->type == SIM_FACILITY_FD) {
2967 fac = "FD"; /*Fixed Dialing Number feature, need PIN2*/
2968 sp->current_sec_op = SEC_FDN_DISABLE;
2969 } else if (req_data->type == SIM_FACILITY_PN) {
2970 fac = "PN"; /*Network Personalization*/
2971 sp->current_sec_op = SEC_NET_DISABLE;
2972 } else if (req_data->type == SIM_FACILITY_PU) {
2973 fac = "PU"; /*network sUbset Personalization*/
2974 sp->current_sec_op = SEC_NS_DISABLE;
2975 } else if (req_data->type == SIM_FACILITY_PP) {
2976 fac = "PP"; /*service Provider Personalization*/
2977 sp->current_sec_op = SEC_SP_DISABLE;
2978 } else if (req_data->type == SIM_FACILITY_PC) {
2979 fac = "PC"; /*Corporate Personalization*/
2980 sp->current_sec_op = SEC_CP_DISABLE;
2982 return TCORE_RETURN_EINVAL;
2984 cmd_str = g_strdup_printf("AT+CLCK=\"%s\", %d, \"%s\"", fac, mode, req_data->password);
2985 req = tcore_at_request_new(cmd_str, "+CLCK:", TCORE_AT_SINGLELINE);
2987 dbg("cmd : %s, prefix(if any) :%s, cmd_len : %d", req->cmd, req->prefix, strlen(req->cmd));
2989 tcore_pending_set_request_data(pending, 0, req);
2990 tcore_pending_set_response_callback(pending, on_response_disable_facility, hal);
2991 tcore_pending_link_user_request(pending, ur);
2992 ret = tcore_hal_send_request(hal, pending);
2995 dbg(" Function exit");
2999 static TReturn s_get_lock_info_n(CoreObject *o, UserRequest *ur)
3001 TcoreHal *hal = NULL;
3002 TcoreATRequest *req = NULL;
3003 TcorePending *pending = NULL;
3004 char *cmd_str = NULL;
3006 const struct treq_sim_get_lock_info *req_data;
3007 struct s_sim_property *sp = NULL;
3009 dbg(" Function entry ");
3011 hal = tcore_object_get_hal(o);
3013 sp = tcore_sim_ref_userdata(o);
3014 pending = tcore_pending_new(o, 0);
3015 req_data = tcore_user_request_ref_data(ur, NULL);
3018 return TCORE_RETURN_EINVAL;
3020 switch (req_data->type) {
3021 case SIM_FACILITY_PS:
3022 lock_type = 9; // IMSI lock
3025 case SIM_FACILITY_SC:
3029 case SIM_FACILITY_FD:
3033 case SIM_FACILITY_PN:
3037 case SIM_FACILITY_PU:
3041 case SIM_FACILITY_PP:
3045 case SIM_FACILITY_PC:
3052 cmd_str = g_strdup_printf("AT+XPINCNT =%d", lock_type);
3053 req = tcore_at_request_new(cmd_str, "+XPINCNT:", TCORE_AT_SINGLELINE);
3055 dbg("cmd : %s, prefix(if any) :%s, cmd_len : %d", req->cmd, req->prefix, strlen(req->cmd));
3057 tcore_pending_set_request_data(pending, 0, req);
3058 tcore_pending_set_response_callback(pending, on_response_get_lock_info, hal);
3059 tcore_pending_link_user_request(pending, ur);
3060 tcore_hal_send_request(hal, pending);
3063 dbg(" Function exit");
3064 return TCORE_RETURN_SUCCESS;
3067 static TReturn s_get_lock_info_str(CoreObject *o, UserRequest *ur)
3069 TcoreHal *hal = NULL;
3070 TcoreATRequest *req = NULL;
3071 TcorePending *pending = NULL;
3072 char *cmd_str = NULL;
3073 char *lock_type = NULL;
3074 const struct treq_sim_get_lock_info *req_data;
3075 TReturn ret = TCORE_RETURN_FAILURE;
3077 dbg(" Function entry ");
3080 return TCORE_RETURN_EINVAL;
3082 hal = tcore_object_get_hal(o);
3084 pending = tcore_pending_new(o, 0);
3085 req_data = tcore_user_request_ref_data(ur, NULL);
3087 switch (req_data->type) {
3088 case SIM_FACILITY_PS:
3092 case SIM_FACILITY_SC:
3096 case SIM_FACILITY_FD:
3100 case SIM_FACILITY_PN:
3104 case SIM_FACILITY_PU:
3108 case SIM_FACILITY_PP:
3112 case SIM_FACILITY_PC:
3119 cmd_str = g_strdup_printf("AT+XPINCNT =\"%s\"", lock_type);
3120 req = tcore_at_request_new(cmd_str, "+XPINCNT:", TCORE_AT_SINGLELINE);
3122 dbg("cmd : %s, prefix(if any) :%s, cmd_len : %d", req->cmd, req->prefix, strlen(req->cmd));
3124 tcore_pending_set_request_data(pending, 0, req);
3125 tcore_pending_set_response_callback(pending, on_response_get_lock_info, hal);
3126 tcore_pending_link_user_request(pending, ur);
3127 ret = tcore_hal_send_request(hal, pending);
3130 dbg(" Function exit");
3134 static TReturn s_get_lock_info(CoreObject *o, UserRequest *ur)
3136 TcorePlugin *plugin = tcore_object_ref_plugin(o);
3137 const char *cpname = tcore_server_get_cp_name_by_plugin(plugin);
3139 if (g_str_has_prefix(cpname, "mfld_blackbay") == TRUE)
3140 return s_get_lock_info_n(o, ur);
3142 return s_get_lock_info_str(o, ur);
3145 static TReturn s_read_file(CoreObject *o, UserRequest *ur)
3147 TReturn api_ret = TCORE_RETURN_SUCCESS;
3148 enum tcore_request_command command;
3150 dbg(" Function entry ");
3153 return TCORE_RETURN_EINVAL;
3155 command = tcore_user_request_get_command(ur);
3156 if(FALSE == tcore_hal_get_power_state(tcore_object_get_hal(o))){
3157 dbg("cp not ready/n");
3158 return TCORE_RETURN_ENOSYS;
3162 case TREQ_SIM_GET_ECC:
3163 api_ret = _get_file_info(o, ur, SIM_EF_ECC);
3166 case TREQ_SIM_GET_LANGUAGE:
3167 if (tcore_sim_get_type(o) == SIM_TYPE_GSM)
3168 api_ret = _get_file_info(o, ur, SIM_EF_ELP);
3169 else if (tcore_sim_get_type(o) == SIM_TYPE_USIM)
3170 api_ret = _get_file_info(o, ur, SIM_EF_LP);
3172 api_ret = TCORE_RETURN_ENOSYS;
3175 case TREQ_SIM_GET_ICCID:
3176 api_ret = _get_file_info(o, ur, SIM_EF_ICCID);
3179 case TREQ_SIM_GET_MAILBOX:
3180 if (tcore_sim_get_cphs_status(o))
3181 api_ret = _get_file_info(o, ur, SIM_EF_CPHS_MAILBOX_NUMBERS);
3183 api_ret = _get_file_info(o, ur, SIM_EF_MBDN);
3186 case TREQ_SIM_GET_CALLFORWARDING:
3187 if (tcore_sim_get_cphs_status(o))
3188 api_ret = _get_file_info(o, ur, SIM_EF_CPHS_CALL_FORWARD_FLAGS);
3190 api_ret = _get_file_info(o, ur, SIM_EF_USIM_CFIS);
3193 case TREQ_SIM_GET_MESSAGEWAITING:
3194 if (tcore_sim_get_cphs_status(o))
3195 api_ret = _get_file_info(o, ur, SIM_EF_CPHS_VOICE_MSG_WAITING);
3197 api_ret = _get_file_info(o, ur, SIM_EF_USIM_MWIS);
3200 case TREQ_SIM_GET_CPHS_INFO:
3201 api_ret = _get_file_info(o, ur, SIM_EF_CPHS_CPHS_INFO);
3204 case TREQ_SIM_GET_MSISDN:
3205 api_ret = _get_file_info(o, ur, SIM_EF_MSISDN);
3208 case TREQ_SIM_GET_SPN:
3209 dbg("enter case SPN");
3210 api_ret = _get_file_info(o, ur, SIM_EF_SPN);
3213 case TREQ_SIM_GET_SPDI:
3214 api_ret = _get_file_info(o, ur, SIM_EF_SPDI);
3217 case TREQ_SIM_GET_OPL:
3218 api_ret = _get_file_info(o, ur, SIM_EF_OPL);
3221 case TREQ_SIM_GET_PNN:
3222 api_ret = _get_file_info(o, ur, SIM_EF_PNN);
3225 case TREQ_SIM_GET_CPHS_NETNAME:
3226 api_ret = _get_file_info(o, ur, SIM_EF_CPHS_OPERATOR_NAME_STRING);
3229 case TREQ_SIM_GET_OPLMNWACT:
3230 api_ret = _get_file_info(o, ur, SIM_EF_OPLMN_ACT);
3234 dbg("error - not handled read treq command[%d]", command);
3235 api_ret = TCORE_RETURN_EINVAL;
3238 dbg(" Function exit");
3242 static TReturn s_update_file(CoreObject *o, UserRequest *ur)
3245 TcoreATRequest *req;
3246 TcorePending *pending = NULL;
3247 char *cmd_str = NULL;
3248 TReturn ret = TCORE_RETURN_SUCCESS;
3249 char *encoded_data = NULL;
3250 int encoded_len = 0;
3251 enum tcore_request_command command;
3252 enum tel_sim_file_id ef = SIM_EF_INVALID;
3253 const struct treq_sim_set_callforwarding *cf;
3254 const struct treq_sim_set_language *cl;
3255 struct s_sim_property file_meta = {0, };
3262 struct tel_sim_language sim_language;
3266 command = tcore_user_request_get_command(ur);
3268 dbg(" Function entry ");
3271 return TCORE_RETURN_EINVAL;
3274 hal = tcore_object_get_hal(o);
3275 if(FALSE == tcore_hal_get_power_state(hal)){
3276 dbg("cp not ready/n");
3277 return TCORE_RETURN_ENOSYS;
3280 pending = tcore_pending_new(o, 0);
3283 case TREQ_SIM_SET_LANGUAGE:
3284 cl = tcore_user_request_ref_data(ur, NULL);
3285 memset(&sim_language, 0x00, sizeof(struct tel_sim_language));
3288 sim_language.language_count = 1;
3289 sim_language.language[0] = cl->language;
3290 dbg("language %d", cl->language);
3292 if (tcore_sim_get_type(o) == SIM_TYPE_GSM) {
3295 tmp = tcore_sim_encode_lp(&out_length, &sim_language);
3297 encoded_data = (char *) malloc(2 * (sim_language.language_count) + 1);
3298 memset(encoded_data, 0x00, (2 * sim_language.language_count) + 1);
3299 result = util_byte_to_hex(tmp, encoded_data, out_length);
3304 dbg("encoded_data - %s ---", encoded_data);
3305 dbg("out_length - %d ---", out_length);
3306 } else if (tcore_sim_get_type(o) == SIM_TYPE_USIM) {
3309 tmp = tcore_sim_encode_li(&out_length, &sim_language);
3311 encoded_data = (char *) malloc(2 * (out_length) + 1);
3312 memset(encoded_data, 0x00, (2 * out_length) + 1);
3313 result = util_byte_to_hex(tmp, encoded_data, out_length);
3318 dbg("encoded_data - %s ---", encoded_data);
3319 dbg("out_length - %d ---", out_length);
3321 ret = TCORE_RETURN_ENOSYS;
3325 case TREQ_SIM_SET_CALLFORWARDING:
3326 cf = tcore_user_request_ref_data(ur, NULL);
3327 if (tcore_sim_get_cphs_status(o)) {
3328 tmp = tcore_sim_encode_cff((const struct tel_sim_cphs_cf*)&cf->cphs_cf);
3329 ef = SIM_EF_CPHS_CALL_FORWARD_FLAGS;
3333 encoded_data = (char *) malloc(2 * (p3) + 1);
3334 memset(encoded_data, 0x00, (2 *p3) + 1);
3335 result = util_byte_to_hex(tmp, encoded_data, p3);
3336 cmd = 214; /*command - 214 : UPDATE BINARY*/
3338 tmp = tcore_sim_encode_cfis(&encoded_len, (const struct tel_sim_cfis*)&cf->cf);
3339 ef = SIM_EF_USIM_CFIS;
3343 encoded_data = (char *) malloc(2 * (encoded_len) + 1);
3344 memset(encoded_data, 0x00, (2 * encoded_len) + 1);
3345 result = util_byte_to_hex(tmp, encoded_data, encoded_len);
3346 cmd = 220; /*command - 220 : UPDATE RECORD*/
3351 dbg("error - not handled update treq command[%d]", command);
3352 ret = TCORE_RETURN_EINVAL;
3355 file_meta.file_id = ef;
3356 dbg("file_meta.file_id: %d", file_meta.file_id);
3358 trt = tcore_user_request_set_metainfo(ur, sizeof(struct s_sim_property), &file_meta);
3359 dbg("trt[%d]", trt);
3361 cmd_str = g_strdup_printf("AT+CRSM=%d,%d,%d,%d,%d,\"%s\"", cmd, ef, p1, p2, p3, encoded_data);
3362 req = tcore_at_request_new(cmd_str, "+CRSM:", TCORE_AT_SINGLELINE);
3364 dbg("cmd : %s, prefix(if any) :%s, cmd_len : %d", req->cmd, req->prefix, strlen(req->cmd));
3366 tcore_pending_set_request_data(pending, 0, req);
3367 tcore_pending_set_response_callback(pending, on_response_update_file, hal);
3368 tcore_pending_link_user_request(pending, ur);
3369 ret = tcore_hal_send_request(hal, pending);
3371 if (NULL != encoded_data) {
3372 g_free(encoded_data);
3380 dbg(" Function exit");
3384 static TReturn s_transmit_apdu(CoreObject *o, UserRequest *ur)
3386 TcoreHal *hal = NULL;
3387 TcoreATRequest *req = NULL;
3388 TcorePending *pending = NULL;
3389 char *cmd_str = NULL;
3393 const struct treq_sim_transmit_apdu *req_data;
3394 TReturn ret = TCORE_RETURN_FAILURE;
3396 dbg(" Function entry ");
3399 return TCORE_RETURN_EINVAL;
3401 hal = tcore_object_get_hal(o);
3402 if(FALSE == tcore_hal_get_power_state(hal)){
3403 dbg("cp not ready/n");
3404 return TCORE_RETURN_ENOSYS;
3407 pending = tcore_pending_new(o, 0);
3408 req_data = tcore_user_request_ref_data(ur, NULL);
3410 apdu = (char *) malloc((2 * req_data->apdu_length) + 1);
3411 memset(apdu, 0x00, (2 * req_data->apdu_length) + 1);
3412 result = util_byte_to_hex((const char *) req_data->apdu, apdu, req_data->apdu_length);
3413 apdu_len = strlen(apdu);
3414 cmd_str = g_strdup_printf("AT+CSIM=%d,\"%s\"", apdu_len, apdu);
3415 req = tcore_at_request_new(cmd_str, "+CSIM:", TCORE_AT_SINGLELINE);
3416 dbg("cmd : %s, prefix(if any) :%s, cmd_len : %d", req->cmd, req->prefix, strlen(req->cmd));
3418 tcore_pending_set_request_data(pending, 0, req);
3419 tcore_pending_set_response_callback(pending, on_response_transmit_apdu, hal);
3420 tcore_pending_link_user_request(pending, ur);
3421 ret = tcore_hal_send_request(hal, pending);
3425 dbg(" Function exit");
3429 static TReturn s_get_atr(CoreObject *o, UserRequest *ur)
3431 TcoreHal *hal = NULL;
3432 TcoreATRequest *req = NULL;
3433 TcorePending *pending = NULL;
3434 char *cmd_str = NULL;
3435 TReturn ret = TCORE_RETURN_FAILURE;
3437 dbg(" Function entry ");
3440 return TCORE_RETURN_EINVAL;
3442 hal = tcore_object_get_hal(o);
3443 if(FALSE == tcore_hal_get_power_state(hal)) {
3444 dbg("cp not ready/n");
3445 return TCORE_RETURN_ENOSYS;
3447 pending = tcore_pending_new(o, 0);
3449 cmd_str = g_strdup_printf("AT+XGATR");
3450 req = tcore_at_request_new(cmd_str, "+XGATR:", TCORE_AT_SINGLELINE);
3451 dbg("cmd : %s, prefix(if any) :%s, cmd_len : %d", req->cmd, req->prefix, strlen(req->cmd));
3453 tcore_pending_set_request_data(pending, 0, req);
3454 tcore_pending_set_response_callback(pending, on_response_get_atr, hal);
3455 tcore_pending_link_user_request(pending, ur);
3456 ret = tcore_hal_send_request(hal, pending);
3459 dbg(" Function exit");
3463 static struct tcore_sim_operations sim_ops = {
3464 .verify_pins = s_verify_pins,
3465 .verify_puks = s_verify_puks,
3466 .change_pins = s_change_pins,
3467 .get_facility_status = s_get_facility_status,
3468 .enable_facility = s_enable_facility,
3469 .disable_facility = s_disable_facility,
3470 .get_lock_info = s_get_lock_info,
3471 .read_file = s_read_file,
3472 .update_file = s_update_file,
3473 .transmit_apdu = s_transmit_apdu,
3474 .get_atr = s_get_atr,
3475 .req_authentication = NULL,
3478 gboolean s_sim_init(TcorePlugin *cp, CoreObject *co_sim)
3480 struct s_sim_property *file_meta;
3484 tcore_sim_override_ops(co_sim, &sim_ops);
3486 file_meta = g_try_new0(struct s_sim_property, 1);
3490 tcore_sim_link_userdata(co_sim, file_meta);
3492 tcore_object_override_callback(co_sim, "+XLOCK", on_event_facility_lock_status, NULL);
3493 tcore_object_override_callback(co_sim, "+XSIM", on_event_pin_status, NULL);
3495 tcore_server_add_notification_hook(tcore_plugin_ref_server(cp), TNOTI_MODEM_POWER, on_hook_modem_power, co_sim);
3502 void s_sim_exit(TcorePlugin *cp, CoreObject *co_sim)
3504 struct s_sim_property *file_meta;
3506 file_meta = tcore_sim_ref_userdata(co_sim);