コード例 #1
0
ファイル: sms.c プロジェクト: Conjuror/ofono
static gboolean check_sim(const GIsiMessage *msg, uint8_t msgid, uint8_t service)
{
	uint8_t type;
	uint8_t cause;

	if (g_isi_msg_error(msg) < 0) {
		DBG("Error: %s", g_isi_msg_strerror(msg));
		return FALSE;
	}

	if (g_isi_msg_id(msg) != msgid) {
		DBG("Unexpected msg: %s", sms_message_id_name(g_isi_msg_id(msg)));
		return FALSE;
	}

	if (!g_isi_msg_data_get_byte(msg, 0, &type))
		return FALSE;

	if (type != service) {
		DBG("Unexpected service type: 0x%02X", type);
		return FALSE;
	}

	if (!g_isi_msg_data_get_byte(msg, 1, &cause))
		return FALSE;

	if (cause != SIM_SERV_OK) {
		DBG("Request failed: %s", sim_isi_cause_name(cause));
		return FALSE;
	}

	return TRUE;
}
コード例 #2
0
ファイル: phonebook.c プロジェクト: yongsu/oFono
static int decode_read_response(const unsigned char *msg, size_t len,
				struct ofono_phonebook *pb)
{
	GIsiSubBlockIter iter;

	char *name = NULL;
	char *number = NULL;
	char *sne = NULL;
	char *anr = NULL;
	char *email = NULL;

	int location = -1;
	guint8 status = 0;

	if (len < 3 || msg[0] != SIM_PB_RESP_SIM_PB_READ)
		goto error;

	if (msg[1] != SIM_PB_READ)
		goto error;

	for (g_isi_sb_iter_init_full(&iter, msg, len, 3, TRUE, msg[2]);
	     g_isi_sb_iter_is_valid(&iter);
	     g_isi_sb_iter_next(&iter)) {

		switch (g_isi_sb_iter_get_id(&iter)) {

		case SIM_PB_ADN: {
			guint16 loc;
			guint8 namelen;
			guint8 numberlen;

			if (!g_isi_sb_iter_get_word(&iter, &loc, 4) ||
				!g_isi_sb_iter_get_byte(&iter, &namelen, 6) ||
				!g_isi_sb_iter_get_byte(&iter, &numberlen, 7))
				goto error;

			if (!g_isi_sb_iter_get_alpha_tag(&iter, &name,
						namelen * 2, 8))
				goto error;

			if (!g_isi_sb_iter_get_alpha_tag(&iter, &number,
						numberlen * 2, 8 + namelen * 2))
				goto error;

			location = loc;
			break;
		}

		case SIM_PB_SNE: {
			guint8 snelen;

			if (!g_isi_sb_iter_get_byte(&iter, &snelen, 6))
				goto error;

			if (!g_isi_sb_iter_get_alpha_tag(&iter, &sne,
						snelen * 2, 8))
				goto error;
			break;
		}

		case SIM_PB_ANR: {
			guint8 anrlen;

			if (!g_isi_sb_iter_get_byte(&iter, &anrlen, 6))
				goto error;

			if (!g_isi_sb_iter_get_alpha_tag(&iter, &anr,
						anrlen * 2, 8))
				goto error;
			break;
		}

		case SIM_PB_EMAIL: {
			guint8 emaillen;

			if (!g_isi_sb_iter_get_byte(&iter, &emaillen, 6))
				goto error;

			if (!g_isi_sb_iter_get_alpha_tag(&iter, &email,
						emaillen * 2, 8))
				goto error;
			break;
		}

		case SIM_PB_STATUS:

			if (!g_isi_sb_iter_get_byte(&iter, &status, 4))
				goto error;

			break;

		default:
			DBG("Skipping sub-block: %s (%zd bytes)",
				sim_subblock_name(g_isi_sb_iter_get_id(&iter)),
				g_isi_sb_iter_get_len(&iter));
			break;
		}
	}

	if (status != SIM_SERV_OK) {
		DBG("Request failed: %s (0x%02X)",
			sim_isi_cause_name(status), status);
		goto error;
	}

	ofono_phonebook_entry(pb, -1, number, -1, name, -1, NULL,
				anr, -1, sne, email, NULL, NULL);

error:
	g_free(name);
	g_free(number);
	g_free(sne);
	g_free(anr);
	g_free(email);

	return location;
}