All of lore.kernel.org
 help / color / mirror / Atom feed
* A way of polling SIM status
@ 2010-10-19 10:41 Zhang, Caiwen
  2010-10-19 11:13 ` Marcel Holtmann
  2010-10-19 18:28 ` Denis Kenzior
  0 siblings, 2 replies; 8+ messages in thread
From: Zhang, Caiwen @ 2010-10-19 10:41 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 2451 bytes --]

Hi, 

Due to some other tasks, it a long time did not take part in the
discussion
Here.  I see there are much discussion about how to polling SIM status. 

Maybe we can start to polling the SIM status with AT+CPIN? when the
probe
 function of SIM atom driver is invoke. If it return  +CME: 10  or +CME:
SIM not
 inserted. It means there is no SIM inserted. If it return other result,
invoke 
ofono_sim_register register the APIs first and then waiting user input
password
(if password is required) or notify SIM is ready(if SIM is ready).

Following are the proposed implementation:

static ofono_bool_t sim_status_poll(void *user_data)
{
	if(!user_data)
		return FALSE;

	struct ofono_sim *sim = user_data;
	struct sim_data *ud = ofono_sim_get_data(sim);
	
	g_at_chat_send(ud->chat, "AT+CPIN?", cpin_prefix,
					sim_status_cb, sim, NULL);
	return FALSE;
}
	
static void sim_status_cb(gboolean ok, GAtResult *result, gpointer
user_data)
{
	struct ofono_sim *sim = user_data;
	GAtResultIter iter;
	struct ofono_error error;
	const char *pin_required;
	
	const char *final = g_at_result_final_response(result);

	decode_at_error(&error, final);
	if(error.type == OFONO_ERROR_TYPE_CME && error.error == 10)
		return;  /* SIM is not inserted */
	
	if (!ok)  {
		g_timeout_add_seconds(5, sim_status_poll, sim);
		return;
	}
	
	g_at_result_iter_init(&iter, result);

	if (!g_at_result_iter_next(&iter, "+CPIN:"))  /* fatal error,
should not occur */
			return;

	g_at_result_iter_next_unquoted_string(&iter, &pin_required);

	ofono_bool_t ready = FALSE;
	if (!strcasecmp(pin_required,
at_sim_name[OFONO_SIM_PASSWORD_NONE].name))
		ready = TRUE;

	if( ofono_sim_get_state(sim) == OFONO_SIM_STATE_NOT_PRESENT)  {
		ofono_sim_register(sim);
		ofono_sim_inserted_notify(sim, TRUE);
	}
	
	if( ready )
		ofono_sim_set_ready(sim);
	else 
		g_timeout_add_seconds(5, sim_status_poll, sim);

}

static int at_sim_probe(struct ofono_sim *sim, unsigned int vendor,
				void *data)
{
	GAtChat *chat = data;
	struct sim_data *ud;

	ud = g_new0(struct sim_data, 1);
	ud->chat = chat;
	ud->vendor = vendor;

	ofono_sim_set_data(sim, ud);

	g_at_chat_send(ud->chat, "AT+CPIN?", cpin_prefix,
					sim_status_cb, sim, NULL);

	return 0;
}

For modem that with SIM status unsolicited indication, should register
And monitor the SIM status at the same time.

Best regards
Caiwen

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2010-10-21  2:39 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-10-19 10:41 A way of polling SIM status Zhang, Caiwen
2010-10-19 11:13 ` Marcel Holtmann
2010-10-19 18:28 ` Denis Kenzior
2010-10-20 13:21   ` Pekka Pessi
2010-10-20 21:36     ` andrzej zaborowski
2010-10-20 21:43       ` Marcel Holtmann
2010-10-20 22:42         ` Denis Kenzior
2010-10-21  2:39       ` Zhang, Caiwen

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.