Exemple #1
0
static void ril_query_passwd_state_cb(struct ril_msg *message, gpointer user_data)
{
	struct cb_data *cbd = user_data;
	struct ofono_sim *sim = cbd->user;
	struct sim_data *sd = ofono_sim_get_data(sim);
	ofono_sim_passwd_cb_t cb = cbd->cb;
	void *data = cbd->data;
	struct sim_app *apps[MAX_UICC_APPS];
	struct sim_status status;
	guint i = 0;
	guint search_index = -1;
	gint state = ofono_sim_get_state(sim);

	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;
			}
		}
		ril_util_free_sim_apps(apps, status.num_apps);
	}
	DBG("passwd_state %u", sd->passwd_state);

	/*
	 * To prevent double call to sim_initialize_after_pin from
	 * sim_pin_query_cb we must prevent calling sim_pin_query_cb
	 * when !OFONO_SIM_STATE_READY && OFONO_SIM_PASSWORD_NONE
	*/
	if ((state == OFONO_SIM_STATE_READY) || (sd->initialized == FALSE) ||
				(sd->passwd_state != OFONO_SIM_PASSWORD_NONE)){

		if (sd->passwd_state == OFONO_SIM_PASSWORD_NONE)
			sd->initialized = TRUE;

		if (state == OFONO_SIM_STATE_LOCKED_OUT)
			sd->initialized = FALSE;

		if (sd->passwd_state == OFONO_SIM_PASSWORD_INVALID)
			CALLBACK_WITH_FAILURE(cb, -1, data);
		else
			CALLBACK_WITH_SUCCESS(cb, sd->passwd_state, data);
	}

}
Exemple #2
0
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);
}
Exemple #3
0
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. */
}