static void ifx_set_sim_state(struct ifx_data *data, int state) { DBG("state %d", state); switch (state) { case 0: /* SIM not present */ case 6: /* SIM Error */ case 8: /* SIM Technical Problem */ case 9: /* SIM Removed */ ofono_sim_inserted_notify(data->sim, FALSE); break; case 1: /* PIN verification needed */ case 4: /* PUK verification needed */ case 5: /* SIM permanently blocked */ case 7: /* ready for attach (+COPS) */ ofono_sim_inserted_notify(data->sim, TRUE); break; case 2: /* PIN verification not needed – Ready */ case 3: /* PIN verified – Ready */ /* * State 3 is handled in the SIM atom driver * while for state 2 we should be waiting for state 7 */ break; case 10: /* SIM Reactivating */ case 11: /* SIM Reactivated */ case 12: /* SIM SMS Caching Completed */ case 99: /* SIM State Unknown */ ofono_warn("Unhandled SIM state %d received", state); break; default: ofono_warn("Unknown SIM state %d received", state); break; } }
static void switch_sim_state_status(struct ofono_modem *modem, int status) { struct telit_data *data = ofono_modem_get_data(modem); DBG("%p, SIM status: %d", modem, status); switch (status) { case 0: /* SIM not inserted */ if (data->have_sim == TRUE) { ofono_sim_inserted_notify(data->sim, FALSE); data->have_sim = FALSE; data->sms_phonebook_added = FALSE; } break; case 1: /* SIM inserted */ case 2: /* SIM inserted and PIN unlocked */ if (data->have_sim == FALSE) { ofono_sim_inserted_notify(data->sim, TRUE); data->have_sim = TRUE; } break; case 3: /* SIM inserted, SMS and phonebook ready */ if (data->sms_phonebook_added == FALSE) { ofono_phonebook_create(modem, 0, "atmodem", data->chat); ofono_sms_create(modem, 0, "atmodem", data->chat); data->sms_phonebook_added = TRUE; } break; default: ofono_warn("Unknown SIM state %d received", status); break; } }
static void ifx_set_sim_state(struct ifx_data *data, int state) { DBG("state %d", state); switch (state) { case 0: /* SIM not present */ case 9: /* SIM Removed */ if (data->have_sim == TRUE) { ofono_sim_inserted_notify(data->sim, FALSE); data->have_sim = FALSE; } break; case 1: /* PIN verification needed */ case 2: /* PIN verification not needed – Ready */ case 3: /* PIN verified – Ready */ case 4: /* PUK verification needed */ case 5: /* SIM permanently blocked */ case 6: /* SIM Error */ case 7: /* ready for attach (+COPS) */ case 8: /* SIM Technical Problem */ if (data->have_sim == FALSE) { ofono_sim_inserted_notify(data->sim, TRUE); data->have_sim = TRUE; } break; default: ofono_warn("Unknown SIM state %d received", state); break; } }
static void sim_status_cb(struct ril_msg *message, gpointer user_data) { struct ofono_modem *modem = user_data; struct ril_data *ril = ofono_modem_get_data(modem); struct reply_sim_status *status; DBG(""); if (message->error != RIL_E_SUCCESS) { ril->sim_status_retries++; ofono_error("GET_SIM_STATUS request failed: %s; retries: %d", ril_error_to_string(message->error), ril->sim_status_retries); if (ril->sim_status_retries < MAX_SIM_STATUS_RETRIES) g_timeout_add_seconds(2, sim_status_retry, modem); else ofono_error("Max retries for GET_SIM_STATUS exceeded!"); } else { if ((status = g_ril_reply_parse_sim_status(ril->modem, message)) != NULL) { if (status->card_state == RIL_CARDSTATE_PRESENT) { DBG("Card PRESENT; num_apps: %d", status->num_apps); if (!ril->have_sim) { DBG("notify SIM inserted"); ril->have_sim = TRUE; ofono_sim_inserted_notify(ril->sim, TRUE); } } else { ofono_warn("Card NOT_PRESENT."); if (ril->have_sim) { DBG("notify SIM removed"); ril->have_sim = FALSE; ofono_sim_inserted_notify(ril->sim, FALSE); } } g_ril_reply_free_sim_status(status); } } }
static void process_uim_state(struct ofono_sim *sim, uint8_t state) { DBG("UIM state %d", state); switch (state) { case QMI_DMS_UIM_STATE_INIT_COMPLETE: ofono_sim_inserted_notify(sim, TRUE); break; case QMI_DMS_UIM_STATE_INIT_FAILED: case QMI_DMS_UIM_STATE_NOT_PRESENT: case QMI_DMS_UIM_STATE_INVALID: ofono_sim_inserted_notify(sim, FALSE); break; } }
static void switch_sim_state_status(struct ofono_modem *modem, int status) { struct telit_data *data = ofono_modem_get_data(modem); DBG("%p", modem); switch (status) { case 0: DBG("SIM not inserted"); ofono_sim_inserted_notify(data->sim, FALSE); break; case 1: DBG("SIM inserted"); /* We need to sleep a bit */ data->sim_inserted_source = g_timeout_add_seconds(1, sim_inserted_timeout_cb, modem); break; case 2: DBG("SIM inserted and PIN unlocked"); break; case 3: DBG("SIM inserted and ready"); break; } }
static gboolean sim_inserted_timeout_cb(gpointer user_data) { struct ofono_modem *modem = user_data; struct telit_data *data = ofono_modem_get_data(modem); DBG("%p", modem); data->sim_inserted_source = 0; ofono_sim_inserted_notify(data->sim, TRUE); return FALSE; }
static void atgen_pre_sim(struct ofono_modem *modem) { GAtChat *chat = ofono_modem_get_data(modem); struct ofono_sim *sim; DBG("%p", modem); ofono_devinfo_create(modem, 0, "atmodem", chat); sim = ofono_sim_create(modem, 0, "atmodem", chat); ofono_voicecall_create(modem, 0, "atmodem", chat); if (sim) ofono_sim_inserted_notify(sim, TRUE); }
static void sierra_pre_sim(struct ofono_modem *modem) { struct sierra_data *data = ofono_modem_get_data(modem); struct ofono_sim *sim; DBG("%p", modem); ofono_devinfo_create(modem, 0, "atmodem", data->modem); sim = ofono_sim_create(modem, OFONO_VENDOR_SIERRA, "atmodem", data->modem); if (sim) ofono_sim_inserted_notify(sim, TRUE); }
static void phonesim_pre_sim(struct ofono_modem *modem) { struct phonesim_data *data = ofono_modem_get_data(modem); struct ofono_sim *sim; DBG("%p", modem); ofono_devinfo_create(modem, 0, "atmodem", data->chat); sim = ofono_sim_create(modem, 0, "atmodem", data->chat); if (data->calypso) ofono_voicecall_create(modem, 0, "calypsomodem", data->chat); else ofono_voicecall_create(modem, 0, "atmodem", data->chat); if (sim) ofono_sim_inserted_notify(sim, TRUE); }
static void sim_status_cb(struct ril_msg *message, gpointer user_data) { struct ofono_sim *sim = user_data; struct sim_data *sd = ofono_sim_get_data(sim); struct parcel rilp; int card_state; int universal_pin_state; int gsm_umts_app_index; int cdma_app_index; int ims_app_index; int num_apps; int i; int app_state; int perso_substate; DBG(""); g_ril_init_parcel(message, &rilp); card_state = parcel_r_int32(&rilp); /* * NOTE: * * The global pin_status is used for multi-application * UICC cards. For example, there are SIM cards that * can be used in both GSM and CDMA phones. Instead * of managed PINs for both applications, a global PIN * is set instead. It's not clear at this point if * such SIM cards are supported by ofono or RILD. */ universal_pin_state = parcel_r_int32(&rilp); gsm_umts_app_index = parcel_r_int32(&rilp); cdma_app_index = parcel_r_int32(&rilp); ims_app_index = parcel_r_int32(&rilp); num_apps = parcel_r_int32(&rilp); if (rilp.malformed) return; if (gsm_umts_app_index >= num_apps) return; DBG("[%d,%04d]< %s: card_state=%d,universal_pin_state=%d," "gsm_umts_index=%d,cdma_index=%d,ims_index=%d," "num_apps=%d", g_ril_get_slot(sd->ril), message->serial_no, "RIL_REQUEST_GET_SIM_STATUS", card_state, universal_pin_state, gsm_umts_app_index, cdma_app_index, ims_app_index, num_apps); switch (card_state) { case RIL_CARDSTATE_PRESENT: break; case RIL_CARDSTATE_ABSENT: ofono_sim_inserted_notify(sim, FALSE); return; default: ofono_error("%s: bad SIM state (%u)", __func__, card_state); return; } ofono_sim_inserted_notify(sim, TRUE); for (i = 0; i != gsm_umts_app_index; i++) { parcel_r_int32(&rilp); /* AppType */ parcel_r_int32(&rilp); /* AppState */ parcel_r_int32(&rilp); /* PersoSubstate */ parcel_skip_string(&rilp); /* AID */ parcel_skip_string(&rilp); /* App Label */ parcel_r_int32(&rilp); /* PIN1 Replaced */ parcel_r_int32(&rilp); /* PIN1 PinState */ parcel_r_int32(&rilp); /* PIN2 PinState */ if (rilp.malformed) return; } /* * We cache the current password state. Ideally this should be done * by issuing a GET_SIM_STATUS request from ril_query_passwd_state, * which is called by the core after sending a password, but * unfortunately the response to GET_SIM_STATUS is not reliable in mako * when sent just after sending the password. Some time is needed * before the modem refreshes its internal state, and when it does it * sends a SIM_STATUS_CHANGED event. In that moment we retrieve the * status and this function is executed. We call * __ofono_sim_recheck_pin as it is the only way to indicate the core * to call query_passwd_state again. An option that can be explored in * the future is wait before invoking core callback for send_passwd * until we know the real password state. */ sd->app_type = parcel_r_int32(&rilp); /* AppType */ app_state = parcel_r_int32(&rilp); /* AppState */ perso_substate = parcel_r_int32(&rilp); /* PersoSubstate */ switch (app_state) { case RIL_APPSTATE_PIN: sd->passwd_state = OFONO_SIM_PASSWORD_SIM_PIN; break; case RIL_APPSTATE_PUK: sd->passwd_state = OFONO_SIM_PASSWORD_SIM_PUK; break; case RIL_APPSTATE_SUBSCRIPTION_PERSO: switch (perso_substate) { case RIL_PERSOSUBSTATE_SIM_NETWORK: sd->passwd_state = OFONO_SIM_PASSWORD_PHNET_PIN; break; case RIL_PERSOSUBSTATE_SIM_NETWORK_SUBSET: sd->passwd_state = OFONO_SIM_PASSWORD_PHNETSUB_PIN; break; case RIL_PERSOSUBSTATE_SIM_CORPORATE: sd->passwd_state = OFONO_SIM_PASSWORD_PHCORP_PIN; break; case RIL_PERSOSUBSTATE_SIM_SERVICE_PROVIDER: sd->passwd_state = OFONO_SIM_PASSWORD_PHSP_PIN; break; case RIL_PERSOSUBSTATE_SIM_SIM: sd->passwd_state = OFONO_SIM_PASSWORD_PHSIM_PIN; break; case RIL_PERSOSUBSTATE_SIM_NETWORK_PUK: sd->passwd_state = OFONO_SIM_PASSWORD_PHNET_PUK; break; case RIL_PERSOSUBSTATE_SIM_NETWORK_SUBSET_PUK: sd->passwd_state = OFONO_SIM_PASSWORD_PHNETSUB_PUK; break; case RIL_PERSOSUBSTATE_SIM_CORPORATE_PUK: sd->passwd_state = OFONO_SIM_PASSWORD_PHCORP_PUK; break; case RIL_PERSOSUBSTATE_SIM_SERVICE_PROVIDER_PUK: sd->passwd_state = OFONO_SIM_PASSWORD_PHSP_PUK; break; case RIL_PERSOSUBSTATE_SIM_SIM_PUK: sd->passwd_state = OFONO_SIM_PASSWORD_PHFSIM_PUK; break; default: sd->passwd_state = OFONO_SIM_PASSWORD_NONE; break; }; break; case RIL_APPSTATE_READY: sd->passwd_state = OFONO_SIM_PASSWORD_NONE; break; case RIL_APPSTATE_UNKNOWN: case RIL_APPSTATE_DETECTED: default: sd->passwd_state = OFONO_SIM_PASSWORD_INVALID; break; } g_free(sd->aid_str); sd->aid_str = parcel_r_string(&rilp); /* AID */ DBG("[%d,%04d]< app_type: %d, passwd_state: %d, aid_str (AID): %s", g_ril_get_slot(sd->ril), message->serial_no, sd->app_type, sd->passwd_state, sd->aid_str); /* * Note: There doesn't seem to be any other way to force the core SIM * code to recheck the PIN. This call causes the core to call this * atom's query_passwd() function. */ __ofono_sim_recheck_pin(sim); }
static void sim_status_cb(struct ril_msg *message, gpointer user_data) { struct ofono_sim *sim = user_data; struct sim_data *sd = ofono_sim_get_data(sim); struct reply_sim_status *status; guint search_index; status = g_ril_reply_parse_sim_status(sd->ril, message); if (status == NULL) { ofono_error("%s: Cannot parse SIM status reply", __func__); return; } DBG("SIM status is %u", status->card_state); if (status->card_state == RIL_CARDSTATE_PRESENT) ofono_sim_inserted_notify(sim, TRUE); else if (status && status->card_state == RIL_CARDSTATE_ABSENT) ofono_sim_inserted_notify(sim, FALSE); else ofono_error("%s: bad SIM state (%u)", __func__, status->card_state); if (status->card_state == RIL_CARDSTATE_PRESENT) { /* * TODO(CDMA): need some kind of logic * to set the correct app_index */ search_index = status->gsm_umts_index; if (search_index > status->num_apps && sd->vendor == OFONO_RIL_VENDOR_QCOM_MSIM) { /* * On QCOM's multi SIM device, all index will be -1 * (but will wrap up to UINT_MAX because index is uint) * until we send RIL_REQUEST_SET_UICC_SUBSCRIPTION. * So, we need to figure out which app to use * and send that request out. */ search_index = sim_select_uicc_subscription(sim, status); } if (search_index < status->num_apps) { struct reply_sim_app *app = status->apps[search_index]; if (app->app_type != RIL_APPTYPE_UNKNOWN) { /* * We cache the current password state. Ideally * this should be done by issuing a * GET_SIM_STATUS request from * ril_query_passwd_state, which is called by * the core after sending a password, but * unfortunately the response to GET_SIM_STATUS * is not reliable in mako when sent just after * sending the password. Some time is needed * before the modem refreshes its internal * state, and when it does it sends a * SIM_STATUS_CHANGED event. In that moment we * retrieve the status and this function is * executed. We call __ofono_sim_recheck_pin as * it is the only way to indicate the core to * call query_passwd_state again. An option * that can be explored in the future is wait * before invoking core callback for send_passwd * until we know the real password state. */ configure_active_app(sd, app, search_index); DBG("passwd_state: %d", sd->passwd_state); /* * Note: There doesn't seem to be any other way * to force the core SIM code to recheck the * PIN. This call causes the core to call this * atom's query_passwd() function. */ __ofono_sim_recheck_pin(sim); } } } g_ril_reply_free_sim_status(status); }
static void sim_status_cb(struct ril_msg *message, gpointer user_data) { struct ofono_sim *sim = user_data; struct sim_data *sd = ofono_sim_get_data(sim); struct sim_app *apps[MAX_UICC_APPS]; struct sim_status status; guint i = 0; guint search_index = -1; struct parcel rilp; DBG(""); if (ril_util_parse_sim_status(sd->ril, message, &status, apps) && status.num_apps) { DBG("num_apps: %d gsm_umts_index: %d", status.num_apps, status.gsm_umts_index); /* TODO(CDMA): need some kind of logic to * set the correct app_index, */ search_index = status.gsm_umts_index; for (i = 0; i < status.num_apps; i++) { if (i == search_index && apps[i]->app_type != RIL_APPTYPE_UNKNOWN) { current_active_app = apps[i]->app_type; configure_active_app(sd, apps[i], i); set_pin_lock_state(sim, apps[i]); break; } } if (sd->sim_registered == FALSE) { ofono_sim_register(sim); sd->sim_registered = TRUE; } else { /* TODO: There doesn't seem to be any other * way to force the core SIM code to * recheck the PIN. * Wouldn't __ofono_sim_refresh be * more appropriate call here?? * __ofono_sim_refresh(sim, NULL, TRUE, TRUE); */ DBG("sd->card_state:%u", sd->card_state); if (sd->card_state != RIL_CARDSTATE_PRESENT) { ofono_sim_inserted_notify(sim, TRUE); sd->card_state = RIL_CARDSTATE_PRESENT; sd->removed = FALSE; } } if (current_passwd) { if (!strcmp(current_passwd, defaultpasswd)) { __ofono_sim_recheck_pin(sim); } else if (sd->passwd_state != OFONO_SIM_PASSWORD_SIM_PIN) { __ofono_sim_recheck_pin(sim); } else if (sd->passwd_state == OFONO_SIM_PASSWORD_SIM_PIN) { parcel_init(&rilp); parcel_w_int32(&rilp, ENTER_SIM_PIN_PARAMS); parcel_w_string(&rilp, current_passwd); parcel_w_string(&rilp, sd->aid_str); g_ril_send(sd->ril, RIL_REQUEST_ENTER_SIM_PIN, rilp.data, rilp.size, NULL, NULL, g_free); parcel_free(&rilp); } } else { __ofono_sim_recheck_pin(sim); } if (current_online_state == RIL_ONLINE_PREF) { parcel_init(&rilp); parcel_w_int32(&rilp, 1); parcel_w_int32(&rilp, 1); ofono_info("RIL_REQUEST_RADIO_POWER ON"); g_ril_send(sd->ril, RIL_REQUEST_RADIO_POWER, rilp.data, rilp.size, NULL, NULL, g_free); parcel_free(&rilp); current_online_state = RIL_ONLINE; } ril_util_free_sim_apps(apps, status.num_apps); } else { if (current_online_state == RIL_ONLINE) current_online_state = RIL_ONLINE_PREF; if (status.card_state == RIL_CARDSTATE_ABSENT) { DBG("sd->card_state:%u,status.card_state:%u,", sd->card_state, status.card_state); ofono_info("RIL_CARDSTATE_ABSENT"); ofono_sim_inserted_notify(sim, FALSE); if (sd->card_state == RIL_CARDSTATE_PRESENT) sd->removed = TRUE; sd->card_state = RIL_CARDSTATE_ABSENT; if (current_passwd) g_stpcpy(current_passwd, defaultpasswd); sd->initialized = FALSE; } } /* TODO: if no SIM present, handle emergency calling. */ }