Exemple #1
0
static void ril_cops_cb(struct ril_msg *message, gpointer user_data)
{
	struct cb_data *cbd = user_data;
	ofono_netreg_operator_cb_t cb = cbd->cb;
	struct netreg_data *nd = cbd->user;
	struct reply_operator *reply;
	struct ofono_network_operator op;

	if (message->error != RIL_E_SUCCESS) {
		ofono_error("%s: failed to retrive the current operator",
				__func__);
		goto error;
	}

	if ((reply = g_ril_reply_parse_operator(nd->ril, message)) == NULL)
		goto error;

	set_oper_name(reply, &op);

	extract_mcc_mnc(reply->numeric, op.mcc, op.mnc);

	/* Set to current */
	op.status = OPERATOR_STATUS_CURRENT;
	op.tech = ril_tech_to_access_tech(nd->tech);

	CALLBACK_WITH_SUCCESS(cb, &op, cbd->data);

	g_ril_reply_free_operator(reply);

	return;

error:
	CALLBACK_WITH_FAILURE(cb, NULL, cbd->data);
}
static void ril_cops_list_cb(struct ril_msg *message, gpointer user_data)
{
	struct cb_data *cbd = user_data;
	ofono_netreg_operator_list_cb_t cb = cbd->cb;
	struct netreg_data *nd = cbd->user;
	struct reply_avail_ops *reply = NULL;
	struct ofono_network_operator *ops;
	struct reply_operator *operator;
	GSList *l;
	unsigned int i = 0;

	if (message->error != RIL_E_SUCCESS) {
		ofono_error("%s: failed to retrive the list of operators",
				__func__);
		goto error;
	}

	reply = g_ril_reply_parse_avail_ops(nd->ril, message);
	if (reply == NULL)
		goto error;

	ops = g_try_new0(struct ofono_network_operator, reply->num_ops);
	if (ops == NULL) {
		ofono_error("%s: can't allocate ofono_network_operator",
				__func__);

		goto error;
	}

	for (l = reply->list; l; l = l->next) {
		operator = l->data;

		set_oper_name(operator, &ops[i]);

		extract_mcc_mnc(operator->numeric, ops[i].mcc, ops[i].mnc);

		ops[i].tech = ril_tech_to_access_tech(operator->tech);

		/* Set the proper status  */
		if (!strcmp(operator->status, "unknown"))
			ops[i].status = OPERATOR_STATUS_UNKNOWN;
		else if (!strcmp(operator->status, "available"))
			ops[i].status = OPERATOR_STATUS_AVAILABLE;
		else if (!strcmp(operator->status, "current"))
			ops[i].status = OPERATOR_STATUS_CURRENT;
		else if (!strcmp(operator->status, "forbidden"))
			ops[i].status = OPERATOR_STATUS_FORBIDDEN;

		i++;
	}

	CALLBACK_WITH_SUCCESS(cb, reply->num_ops, ops, cbd->data);
	g_ril_reply_free_avail_ops(reply);

	return;

error:
	CALLBACK_WITH_FAILURE(cb, 0, NULL, cbd->data);
	g_ril_reply_free_avail_ops(reply);
}
Exemple #3
0
static void ril_cops_cb(struct ril_msg *message, gpointer user_data)
{
	struct cb_data *cbd = user_data;
	ofono_netreg_operator_cb_t cb = cbd->cb;
	struct netreg_data *nd = cbd->user;
	struct ofono_error error;
	struct parcel rilp;
	struct ofono_network_operator op;
	gchar *lalpha, *salpha, *numeric;

	if (message->error == RIL_E_SUCCESS) {
		decode_ril_error(&error, "OK");
	} else {
		ofono_error("Failed to retrive the current operator");
		goto error;
	}

	ril_util_init_parcel(message, &rilp);

	/* Size of char ** */
	if (parcel_r_int32(&rilp) == 0)
		goto error;

	lalpha = parcel_r_string(&rilp);
	salpha = parcel_r_string(&rilp);
	numeric = parcel_r_string(&rilp);

	/* Try to use long by default */
	if (lalpha)
		strncpy(op.name, lalpha, OFONO_MAX_OPERATOR_NAME_LENGTH);
	else if (salpha)
		strncpy(op.name, salpha, OFONO_MAX_OPERATOR_NAME_LENGTH);
	else
		goto error;

	extract_mcc_mnc(numeric, op.mcc, op.mnc);

	/* Set to current */
	op.status = OPERATOR_STATUS_CURRENT;
	op.tech = nd->tech;

	g_ril_append_print_buf(nd->ril,
				"(lalpha=%s, salpha=%s, numeric=%s, %s, mcc=%s, mnc=%s, %s)",
				lalpha, salpha, numeric,
				op.name, op.mcc, op.mnc,
				registration_tech_to_string(op.tech));
	g_ril_print_response(nd->ril, message);

	g_free(lalpha);
	g_free(salpha);
	g_free(numeric);

	cb(&error, &op, cbd->data);

	return;

error:
	CALLBACK_WITH_FAILURE(cb, NULL, cbd->data);
}
static void cops_numeric_cb(gboolean ok, GAtResult *result, gpointer user_data)
{
	struct cb_data *cbd = user_data;
	struct netreg_data *nd = ofono_netreg_get_data(cbd->user);
	ofono_netreg_operator_cb_t cb = cbd->cb;
	GAtResultIter iter;
	const char *str;
	int format;
	int len;
	struct ofono_error error;

	decode_at_error(&error, g_at_result_final_response(result));

	if (!ok)
		goto error;

	g_at_result_iter_init(&iter, result);

	if (!g_at_result_iter_next(&iter, "+COPS:"))
		goto error;

	g_at_result_iter_skip_next(&iter);

	ok = g_at_result_iter_next_number(&iter, &format);

	if (ok == FALSE || format != 2)
		goto error;

	if (g_at_result_iter_next_string(&iter, &str) == FALSE)
		goto error;

	len = strspn(str, "0123456789");

	if (len != 5 && len != 6)
		goto error;

	extract_mcc_mnc(str, nd->mcc, nd->mnc);

	DBG("Cops numeric got mcc: %s, mnc: %s", nd->mcc, nd->mnc);

	ok = g_at_chat_send(nd->chat, "AT+COPS=3,0", none_prefix,
					NULL, NULL, NULL);

	if (ok)
		ok = g_at_chat_send(nd->chat, "AT+COPS?", cops_prefix,
					cops_cb, cbd, NULL);

	if (ok)
		return;

error:
	cb(&error, NULL, cbd->data);
	g_free(cbd);
}
Exemple #5
0
static void ril_cops_list_cb(struct ril_msg *message, gpointer user_data)
{
	struct cb_data *cbd = user_data;
	ofono_netreg_operator_list_cb_t cb = cbd->cb;
	struct netreg_data *nd = cbd->user;
	struct ofono_network_operator *list;
	struct ofono_error error;
	struct parcel rilp;
	int noperators, i;
	gchar *lalpha, *salpha, *numeric, *status;

	if (message->error == RIL_E_SUCCESS) {
		decode_ril_error(&error, "OK");
	} else {
		ofono_error("Failed to retrive the list of operators");
		goto error;
	}

	ril_util_init_parcel(message, &rilp);

	g_ril_append_print_buf(nd->ril, "{");

	/* Number of operators at the list (4 strings for every operator) */
	noperators = parcel_r_int32(&rilp) / 4;
	DBG("noperators = %d", noperators);

	list = g_try_new0(struct ofono_network_operator, noperators);
	if (list == NULL)
		goto error;

	for (i = 0; i < noperators; i++) {
		lalpha = parcel_r_string(&rilp);
		salpha = parcel_r_string(&rilp);
		numeric = parcel_r_string(&rilp);
		status = parcel_r_string(&rilp);

		/* Try to use long by default */
		if (lalpha) {
			strncpy(list[i].name, lalpha,
					OFONO_MAX_OPERATOR_NAME_LENGTH);
		} else {
			strncpy(list[i].name, salpha,
					OFONO_MAX_OPERATOR_NAME_LENGTH);
		}

		extract_mcc_mnc(numeric, list[i].mcc, list[i].mnc);

		/* FIXME: need to fix this for CDMA */
		/* Use GSM as default, as RIL doesn't pass that info to us */
		list[i].tech = ACCESS_TECHNOLOGY_GSM;

		/* Set the proper status  */
		if (!strcmp(status, "unknown"))
			list[i].status = OPERATOR_STATUS_UNKNOWN;
		else if (!strcmp(status, "available"))
			list[i].status = OPERATOR_STATUS_AVAILABLE;
		else if (!strcmp(status, "current"))
			list[i].status = OPERATOR_STATUS_CURRENT;
		else if (!strcmp(status, "forbidden"))
			list[i].status = OPERATOR_STATUS_FORBIDDEN;

		g_ril_append_print_buf(nd->ril,
					"%s [operator=%s, %s, %s, status: %s]",
					print_buf,
					list[i].name, list[i].mcc,
					list[i].mnc, status);

		g_free(lalpha);
		g_free(salpha);
		g_free(numeric);
		g_free(status);
	}

	g_ril_append_print_buf(nd->ril, "%s}", print_buf);
	g_ril_print_response(nd->ril, message);

	cb(&error, noperators, list, cbd->data);

	return;

error:
	CALLBACK_WITH_FAILURE(cb, 0, NULL, cbd->data);
}
static void cops_list_cb(gboolean ok, GAtResult *result, gpointer user_data)
{
	struct cb_data *cbd = user_data;
	ofono_netreg_operator_list_cb_t cb = cbd->cb;
	struct ofono_network_operator *list;
	GAtResultIter iter;
	int num = 0;
	struct ofono_error error;

	decode_at_error(&error, g_at_result_final_response(result));

	if (!ok) {
		cb(&error, 0, NULL, cbd->data);
		return;
	}

	g_at_result_iter_init(&iter, result);

	while (g_at_result_iter_next(&iter, "+COPS:")) {
		while (g_at_result_iter_skip_next(&iter))
			num += 1;
	}

	DBG("Got %d elements", num);

	list = g_try_new0(struct ofono_network_operator, num);
	if (list == NULL) {
		CALLBACK_WITH_FAILURE(cb, 0, NULL, cbd->data);
		return;
	}

	num = 0;
	g_at_result_iter_init(&iter, result);

	while (g_at_result_iter_next(&iter, "+COPS:")) {
		int status, tech, plmn;
		const char *l, *s, *n;
		gboolean have_long = FALSE;

		while (1) {
			if (!g_at_result_iter_open_list(&iter))
				break;

			if (!g_at_result_iter_next_number(&iter, &status))
				break;

			list[num].status = status;

			if (!g_at_result_iter_next_string(&iter, &l))
				break;

			if (strlen(l) > 0) {
				have_long = TRUE;
				strncpy(list[num].name, l,
					OFONO_MAX_OPERATOR_NAME_LENGTH);
			}

			if (!g_at_result_iter_next_string(&iter, &s))
				break;

			if (strlen(s) > 0 && !have_long)
				strncpy(list[num].name, s,
					OFONO_MAX_OPERATOR_NAME_LENGTH);

			list[num].name[OFONO_MAX_OPERATOR_NAME_LENGTH] = '\0';

			if (!g_at_result_iter_next_string(&iter, &n))
				break;

			extract_mcc_mnc(n, list[num].mcc, list[num].mnc);

			if (!g_at_result_iter_next_number(&iter, &tech))
				tech = ACCESS_TECHNOLOGY_GSM;

			list[num].tech = tech;

			if (!g_at_result_iter_next_number(&iter, &plmn))
				plmn = 0;

			if (!g_at_result_iter_close_list(&iter))
				break;

			num += 1;
		}
	}

	DBG("Got %d operators", num);

{
	int i = 0;

	for (; i < num; i++) {
		DBG("Operator: %s, %s, %s, status: %d, %d",
			list[i].name, list[i].mcc, list[i].mnc,
			list[i].status, list[i].tech);
	}
}

	cb(&error, num, list, cbd->data);

	g_free(list);
}