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)
{
	DBG("error=%d", message->error);
	struct ofono_modem *modem = user_data;
	struct ril_data *ril = ofono_modem_get_data(modem);
	struct sim_status status;
	struct sim_app *apps[MAX_UICC_APPS];

	/*
	 * ril.h claims this should NEVER fail!
	 * However this isn't quite true.  So,
	 * on anything other than SUCCESS, we
	 * log an error, and schedule another
	 * GET_SIM_STATUS request.
	 */

	if (message->error != RIL_E_SUCCESS) {
		ril->sim_status_retries++;

		ofono_error("GET_SIM_STATUS reques failed: %d; retries: %d",
				message->error, ril->sim_status_retries);

		if (ril->sim_status_retries < MAX_SIM_STATUS_RETRIES)
			ril->timer_id = g_timeout_add_seconds(2, (GSourceFunc)
							send_get_sim_status,
							(gpointer) modem);
		else
			ofono_error("Max retries for GET_SIM_STATUS exceeded!");
	} else {
		/* Returns TRUE if cardstate == PRESENT */
		if (ril_util_parse_sim_status(ril->modem, message,
						&status, apps)) {

			if (status.num_apps)
				ril_util_free_sim_apps(apps, status.num_apps);
		} else {
			ofono_warn("No SIM card present.");
		}

		/*
		 * We cannot power on modem, but we need to get
		 * certain interfaces up to be able to make emergency calls
		 * in offline mode and without SIM
		 */
		ofono_modem_set_powered(modem, TRUE);
	}
}
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. */
}