Ejemplo n.º 1
0
/**
 * connman_network_set_uint8:
 * @network: network structure
 * @key: unique identifier
 * @value: integer value
 *
 * Set integer value for specific key
 */
int connman_network_set_uint8(struct connman_network *network,
					const char *key, connman_uint8_t value)
{
	_DBG_NETWORK("network %p key %s value %d", network, key, value);

	if (g_strcmp0(key, "Strength") == 0)
		return connman_network_set_strength(network, value);

	return connman_element_set_uint8(&network->element, key, value);
}
Ejemplo n.º 2
0
static void add_network(struct mk3_data *mk3) {

	struct connman_network *network = NULL;

	g_return_if_fail(mk3);

	DBG("data %p", mk3);


	if(mk3->network != NULL) {

		DBG("network %p already exists.", mk3->network);
		return;
	}

	network = connman_network_create(mk3->devname,	CONNMAN_NETWORK_TYPE_MK3);
	if(network == NULL) {

		connman_error("Network could not be created.");
		return;

	}

	DBG("network %p", mk3->network);

	connman_network_set_index(network, mk3->index);
	connman_network_set_name(network, mk3->name);
	connman_network_set_data(network, mk3);
	connman_network_set_strength(network, mk3->strength);
	connman_network_set_group(network, mk3->group);

	if(connman_device_add_network(mk3->device, network) < 0) {

		connman_network_unref(network);
		network = NULL;
		return;
	}

	mk3->network = network;


}
Ejemplo n.º 3
0
/**
* @brief Set the newly replied key/ value properties
*/
static gboolean
update_network(struct qmi_data *qmi, DBusMessageIter *entry_iter) {

	DBusMessageIter variant_iter;
	gboolean updating_strength = FALSE;
	gboolean updating_others = FALSE;
	gchar *key;
	gchar *help;



	if(dbus_message_iter_get_arg_type(entry_iter) != DBUS_TYPE_STRING)
		return FALSE;

	dbus_message_iter_get_basic(entry_iter, &key);
	DBG("Property %s", key);
	if(key != NULL) {

		dbus_message_iter_next(entry_iter);

		if(dbus_message_iter_get_arg_type(entry_iter) != DBUS_TYPE_VARIANT)
			return FALSE;

		dbus_message_iter_recurse(entry_iter, &variant_iter);

		if(g_strcmp0(key, "IMSI") == 0) {
			/* Set new IMSI */
			if(dbus_message_iter_get_arg_type(&variant_iter) != DBUS_TYPE_STRING)
				return FALSE;

			dbus_message_iter_get_basic(&variant_iter, &help);
			if(qmi->imsi)
				g_free(qmi->imsi);
			qmi->imsi = g_strdup(help);

		}
		else if(g_strcmp0(key, "RSRQ") == 0) {
			/* Set new RSRQ */
			guint8 help = 0;

			if(qmi->network == NULL)
				return FALSE;

			if(dbus_message_iter_get_arg_type(&variant_iter) != DBUS_TYPE_INT32)
				return FALSE;

			dbus_message_iter_get_basic(&variant_iter, &qmi->rsrq);
			help = calculate_signal_strength(qmi->rsrq);
			if(help != qmi->strength) {

				qmi->strength = help;
				/* Set new calculated strength */

				connman_network_set_strength(qmi->network, qmi->strength);

				updating_strength = TRUE;
			}


		}
		else if(g_strcmp0(key, "PacketStatus") == 0) {
			/* Set new packet status */
			if(qmi->network == NULL)
				return FALSE;

			if(dbus_message_iter_get_arg_type(&variant_iter) != DBUS_TYPE_STRING)
				return FALSE;

			dbus_message_iter_get_basic(&variant_iter, &help);
			if(g_strcmp0(qmi->packet_status, help) != 0) {

				if(qmi->packet_status)
					g_free(qmi->packet_status);
				qmi->packet_status = g_strdup(help);

				/* Check new packet status and change network status if required */
				if(g_strcmp0(qmi->packet_status, "connected") == 0) {

					connman_network_set_connected(qmi->network, TRUE);
				}
				else {

					connman_network_set_connected(qmi->network, FALSE);
				}

			}


		}
		else if(g_strcmp0(key, "NetworkType") == 0) {
			/* Set new network type */
			if(dbus_message_iter_get_arg_type(&variant_iter) != DBUS_TYPE_STRING)
				return FALSE;

			dbus_message_iter_get_basic(&variant_iter, &help);
			if(g_strcmp0(qmi->network_type, help) != 0) {

				if(qmi->network_type)
					g_free(qmi->network_type);
				qmi->network_type = g_strdup(help);

				updating_others = TRUE;

			}


		}
		else if(g_strcmp0(key, "MCC") == 0) {
			/* Set new MCC */
			if(dbus_message_iter_get_arg_type(&variant_iter) != DBUS_TYPE_STRING)
				return FALSE;

			dbus_message_iter_get_basic(&variant_iter, &help);
			if(g_strcmp0(qmi->mcc, help) != 0) {

				if(qmi->mcc)
					g_free(qmi->mcc);
				qmi->mcc = g_strdup(help);

				updating_others = TRUE;

			}


		}
		else if(g_strcmp0(key, "MNC") == 0) {
			/* Set new MNC */
			if(dbus_message_iter_get_arg_type(&variant_iter) != DBUS_TYPE_STRING)
				return FALSE;

			dbus_message_iter_get_basic(&variant_iter, &help);
			if(g_strcmp0(qmi->mnc, help) != 0) {

				if(qmi->mnc)
					g_free(qmi->mnc);
				qmi->mnc = g_strdup(help);

				updating_others = TRUE;

			}


		}
		else if(g_strcmp0(key, "RAT") == 0) {
			/*Set new RAT */
			if(dbus_message_iter_get_arg_type(&variant_iter) != DBUS_TYPE_STRING)
				return FALSE;

			dbus_message_iter_get_basic(&variant_iter, &help);
			if(g_strcmp0(qmi->rat, help) != 0) {

				if(qmi->rat)
					g_free(qmi->rat);
				qmi->rat = g_strdup(help);

				updating_others = TRUE;

			}

		}

		/* Check whether network already exists, because some properties as IMSI or IMEI are set before network is added */
		if(qmi->network) {

			if(updating_strength == TRUE) {
				/* Just update new strength property */
				connman_network_update(qmi->network);
			}
			else if(updating_others == TRUE) {
				/* Build a new network name and update it */
				if(qmi->provider)
					g_free(qmi->provider);

				qmi->provider = g_strdup_printf("%s-%s-%s", qmi->mnc, qmi->mcc, qmi->rat);

				connman_network_set_name(qmi->network, qmi->provider);
				connman_network_update(qmi->network);

			}

		}

	}

	return TRUE;
}
Ejemplo n.º 4
0
/**
* @brief Add the network associated to its qmi device
*/
static void add_network(struct qmi_data *qmi)
{
	struct connman_network *network = NULL;
	int index;
	struct connman_service *service = NULL;

	g_return_if_fail(qmi);

	DBG("data %p", qmi);

	if(qmi->network != NULL) {

		DBG("network %p already exists.", qmi->network);
		return;
	}

	/* Create an new qmi network */
	network = connman_network_create(qmi->devpath, CONNMAN_NETWORK_TYPE_QMI);
	if(network == NULL) {

		connman_error("Network could not be created.");
		return;
	}

	DBG("network %p", qmi->network);

	/* Set network properties */
	index = connman_device_get_index(qmi->device);
	connman_network_set_index(network, index);
	connman_network_set_data(network, qmi);
	connman_network_set_strength(network, qmi->strength);
	connman_network_set_group(network, qmi->group);

	if(qmi->provider)
		g_free(qmi->provider);
	qmi->provider = g_strdup("no-name");
	connman_network_set_name(network, qmi->provider);

	/* Add the created network */
	if (connman_device_add_network(qmi->device, network) < 0) {

		connman_error("Network not added to the device.");
		connman_network_unref(network);
		network = NULL;
		return;
	}

	qmi->network = network;

	/* Get configured values from the created *.config file */
	service = connman_service_lookup_from_network(network);
	DBG("service %p", service);
	if(service == NULL) {

		connman_error("No service available");
		return;
	}

	service = connman_service_ref(service);
	if(qmi->apn)
		g_free(qmi->apn);
	qmi->apn = g_strdup(connman_service_get_string(service, "APN"));

	if(qmi->passphrase)
		g_free(qmi->passphrase);
	qmi->passphrase = g_strdup(connman_service_get_string(service, "Passphrase"));

	if(qmi->username)
		g_free(qmi->username);
	qmi->username = g_strdup(connman_service_get_string(service, "Username"));

	if(qmi->provider)
		g_free(qmi->provider);
	qmi->provider = g_strdup(connman_service_get_string(service, "Provider"));
	if(qmi->provider == NULL)
		qmi->provider = g_strdup("no-name");

	connman_network_set_name(network, qmi->provider);
	connman_network_update(qmi->network);


    DBG("network %p IMSI %s APN %s PW %s Username %s", qmi->network, qmi->imsi, qmi->apn, qmi->passphrase, qmi->username);
	connman_service_unref(service);
	if((qmi->imsi == NULL) || (qmi->apn == NULL) || (qmi->passphrase == NULL)) {

		connman_error("There are not all required parameters available");
		return;
	}

}
Ejemplo n.º 5
0
static void properties_reply(DBusPendingCall *call, void *user_data)
{
	struct supplicant_task *task = user_data;
	struct supplicant_result result;
	struct connman_network *network;
	DBusMessage *reply;
	DBusMessageIter array, dict;
	unsigned char strength;
	unsigned short channel, frequency;
	const char *mode, *security;
	char *group = NULL;

	reply = dbus_pending_call_steal_reply(call);
	if (reply == NULL) {
		_DBG_SUPPLICANT("task %p no reply", task);
		get_properties(task);
		return;
	}

	if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR) {
		_DBG_SUPPLICANT("task %p ERROR", task);
		dbus_message_unref(reply);
		get_properties(task);
		return;
	}

	memset(&result, 0, sizeof(result));
	result.frequency = -1;
	result.quality = -1;
	result.level = 0;
	result.noise = 0;

	dbus_message_iter_init(reply, &array);

	dbus_message_iter_recurse(&array, &dict);

	while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
		DBusMessageIter entry, value;
		const char *key;

		dbus_message_iter_recurse(&dict, &entry);
		dbus_message_iter_get_basic(&entry, &key);

		dbus_message_iter_next(&entry);

		dbus_message_iter_recurse(&entry, &value);

		//type = dbus_message_iter_get_arg_type(&value);
		//dbus_message_iter_get_basic(&value, &val);

		/* 
		 * bssid        : a (97)
		 * ssid         : a (97)
		 * wpaie        : a (97)
		 * rsnie        : a (97)
		 * wpsie        : a (97)
		 * frequency    : i (105)
		 * capabilities : q (113)
		 * quality      : i (105)
		 * noise        : i (105)
		 * level        : i (105)
		 * maxrate      : i (105)
		 */

		if (g_str_equal(key, "bssid") == TRUE)
			extract_addr(&value, &result);
		else if (g_str_equal(key, "ssid") == TRUE)
			extract_ssid(&value, &result);
		else if (g_str_equal(key, "wpaie") == TRUE)
			extract_wpaie(&value, &result);
		else if (g_str_equal(key, "rsnie") == TRUE)
			extract_rsnie(&value, &result);
		else if (g_str_equal(key, "wpsie") == TRUE)
			extract_wpsie(&value, &result);
		else if (g_str_equal(key, "capabilities") == TRUE)
			extract_capabilites(&value, &result);
		else if (g_str_equal(key, "frequency") == TRUE)
			dbus_message_iter_get_basic(&value, &result.frequency);
		else if (g_str_equal(key, "quality") == TRUE)
			dbus_message_iter_get_basic(&value, &result.quality);
		else if (g_str_equal(key, "noise") == TRUE)
			dbus_message_iter_get_basic(&value, &result.noise);
		else if (g_str_equal(key, "level") == TRUE)
			dbus_message_iter_get_basic(&value, &result.level);
		else if (g_str_equal(key, "maxrate") == TRUE)
			dbus_message_iter_get_basic(&value, &result.maxrate);

		dbus_message_iter_next(&dict);
	}

	if (result.path == NULL)
		goto done;

	if (result.path[0] == '\0')
		goto done;

	if (result.frequency > 0 && result.frequency < 14)
		result.frequency = 2407 + (5 * result.frequency);
	else if (result.frequency == 14)
		result.frequency = 2484;

	strength = calculate_strength(task, &result);
	channel  = calculate_channel(&result);

	frequency = (result.frequency < 0) ? 0 : result.frequency;

	if (result.has_rsn == TRUE)
		security = "rsn";
	else if (result.has_wpa == TRUE)
		security = "wpa";
	else if (result.has_wep == TRUE)
		security = "wep";
	else
		security = "none";

	mode = (result.adhoc == TRUE) ? "adhoc" : "managed";

	group = build_group(result.path, result.name,
					result.ssid, result.ssid_len,
							mode, security);

	network = connman_device_get_network(task->device, result.path);
	if (network == NULL) {
		int index;

		network = connman_network_create(result.path,
						CONNMAN_NETWORK_TYPE_WIFI);
		if (network == NULL) {
			_DBG_SUPPLICANT("cannot create network %s",
				result.name);
			goto done;
		}

		index = connman_device_get_index(task->device);
		connman_network_set_index(network, index);

		connman_network_set_protocol(network,
						CONNMAN_NETWORK_PROTOCOL_IP);

		connman_network_set_address(network, result.addr,
							result.addr_len);

		if (connman_device_add_network(task->device, network) < 0) {
			_DBG_SUPPLICANT("cannot add network %s", result.name);
			connman_network_unref(network);
			goto done;
		}

		_DBG_SUPPLICANT("add %s (%s %s) signal %d (%s) freq %u path %s",
				result.name, mode, security, strength,
				(result.has_wps == TRUE) ? "WPS" : "no WPS",
				frequency, result.path);
	}

	connman_network_set_scangen(network, task->scangen);

	if (result.name != NULL && result.name[0] != '\0')
		connman_network_set_name(network, result.name);

	connman_network_set_blob(network, "WiFi.SSID",
						result.ssid, result.ssid_len);

	connman_network_set_string(network, "WiFi.Mode", mode);

	connman_network_set_available(network, TRUE);
	connman_network_set_strength(network, strength);

	connman_network_set_uint16(network, "Frequency", frequency);
	connman_network_set_uint16(network, "WiFi.Channel", channel);
	connman_network_set_string(network, "WiFi.Security", security);

	if (result.ssid != NULL)
		connman_network_set_group(network, group);

done:
	g_free(group);

	g_free(result.path);
	g_free(result.addr);
	g_free(result.name);
	g_free(result.ssid);

	dbus_message_unref(reply);

	get_properties(task);
}