Пример #1
0
/**
 * connman_network_set_string:
 * @network: network structure
 * @key: unique identifier
 * @value: string value
 *
 * Set string value for specific key
 */
int connman_network_set_string(struct connman_network *network,
					const char *key, const char *value)
{
	_DBG_NETWORK("network %p key %s value %s", network, key, value);

	if (g_strcmp0(key, "Name") == 0)
		return connman_network_set_name(network, value);

	if (g_str_equal(key, "Address") == TRUE) {
		g_free(network->address);
		network->address = g_strdup(value);
	} else if (g_str_equal(key, "Node") == TRUE) {
		g_free(network->node);
		network->node = g_strdup(value);
	} else if (g_str_equal(key, "WiFi.Mode") == TRUE) {
		g_free(network->wifi.mode);
		network->wifi.mode = g_strdup(value);
	} else if (g_str_equal(key, "WiFi.Security") == TRUE) {
		g_free(network->wifi.security);
		network->wifi.security = g_strdup(value);
	} else if (g_str_equal(key, "WiFi.Passphrase") == TRUE) {
		g_free(network->wifi.passphrase);
		network->wifi.passphrase = g_strdup(value);
	}

	return connman_element_set_string(&network->element, key, value);
}
Пример #2
0
static void pan_create_nap(struct bluetooth_pan *pan)
{
	struct connman_device *device;
	const char* role;
	const char *adapter;

	role = proxy_get_role(pan->btdevice_proxy);
	if (!role) {
		pan_remove_nap(pan);
		return;
	}

	adapter = proxy_get_string(pan->btdevice_proxy, "Adapter");

	if (!adapter)
		return;

	device = g_hash_table_lookup(devices, adapter);

	if (!device || !connman_device_get_powered(device))
		return;

	if (!pan->network) {
		const char *address;
		char ident[BLUETOOTH_ADDR_LEN * 2 + 1];
		const char *name, *path;

		address = proxy_get_string(pan->btdevice_proxy, "Address");
		if (!address) {
			connman_warn("Bluetooth device address missing");
			return;
		}

		address2ident(address, ident);

		pan->network = connman_network_create(ident,
				CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN);

		name = proxy_get_string(pan->btdevice_proxy, "Alias");
		path = g_dbus_proxy_get_path(pan->btnetwork_proxy);

		DBG("network %p %s %s", pan->network, path, name);

		if (!pan->network) {
			connman_warn("Bluetooth network %s creation failed",
					path);
			return;
		}

		connman_network_set_data(pan->network, pan);
		connman_network_set_name(pan->network, name);
		connman_network_set_group(pan->network, ident);
	}

	pan->pan_role = role;
	connman_device_add_network(device, pan->network);

	if (pan_connect(pan, NULL))
		DBG("network %p already connected", pan->network);
}
Пример #3
0
static void add_network(struct connman_device *device,
                        struct ethernet_data *ethernet)
{
    struct connman_network *network;
    int index;

    network = connman_network_create("carrier",
                                     CONNMAN_NETWORK_TYPE_ETHERNET);
    if (network == NULL)
        return;

    index = connman_device_get_index(device);
    connman_network_set_index(network, index);

    connman_network_set_name(network, "Wired");

    if (connman_device_add_network(device, network) < 0) {
        connman_network_unref(network);
        return;
    }

    connman_network_set_group(network, "cable");

    ethernet->network = network;
}
/**
 * connman_network_set_string:
 * @network: network structure
 * @key: unique identifier
 * @value: string value
 *
 * Set string value for specific key
 */
int connman_network_set_string(struct connman_network *network,
					const char *key, const char *value)
{
	DBG("network %p key %s value %s", network, key, value);

	if (g_strcmp0(key, "Name") == 0)
		return connman_network_set_name(network, value);

	if (g_str_equal(key, "Path") == TRUE) {
		g_free(network->path);
		network->path = g_strdup(value);
	} else if (g_str_equal(key, "Node") == TRUE) {
		g_free(network->node);
		network->node = g_strdup(value);
	} else if (g_str_equal(key, "WiFi.Mode") == TRUE) {
		g_free(network->wifi.mode);
		network->wifi.mode = g_strdup(value);
	} else if (g_str_equal(key, "WiFi.Security") == TRUE) {
		g_free(network->wifi.security);
		network->wifi.security = g_strdup(value);
	} else if (g_str_equal(key, "WiFi.Passphrase") == TRUE) {
		g_free(network->wifi.passphrase);
		network->wifi.passphrase = g_strdup(value);
	} else if (g_str_equal(key, "WiFi.AgentPassphrase") == TRUE) {
		g_free(network->wifi.agent_passphrase);
		network->wifi.agent_passphrase = g_strdup(value);
	} else if (g_str_equal(key, "WiFi.EAP") == TRUE) {
		g_free(network->wifi.eap);
		network->wifi.eap = g_strdup(value);
	} else if (g_str_equal(key, "WiFi.Identity") == TRUE) {
		g_free(network->wifi.identity);
		network->wifi.identity = g_strdup(value);
	} else if (g_str_equal(key, "WiFi.AgentIdentity") == TRUE) {
		g_free(network->wifi.agent_identity);
		network->wifi.agent_identity = g_strdup(value);
	} else if (g_str_equal(key, "WiFi.CACertFile") == TRUE) {
		g_free(network->wifi.ca_cert_path);
		network->wifi.ca_cert_path = g_strdup(value);
	} else if (g_str_equal(key, "WiFi.ClientCertFile") == TRUE) {
		g_free(network->wifi.client_cert_path);
		network->wifi.client_cert_path = g_strdup(value);
	} else if (g_str_equal(key, "WiFi.PrivateKeyFile") == TRUE) {
		g_free(network->wifi.private_key_path);
		network->wifi.private_key_path = g_strdup(value);
	} else if (g_str_equal(key, "WiFi.PrivateKeyPassphrase") == TRUE) {
		g_free(network->wifi.private_key_passphrase);
		network->wifi.private_key_passphrase = g_strdup(value);
	} else if (g_str_equal(key, "WiFi.Phase2") == TRUE) {
		g_free(network->wifi.phase2_auth);
		network->wifi.phase2_auth = g_strdup(value);
	} else if (g_str_equal(key, "WiFi.PinWPS") == TRUE) {
		g_free(network->wifi.pin_wps);
		network->wifi.pin_wps = g_strdup(value);
	} else {
		return -EINVAL;
	}

	return 0;
}
Пример #5
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;


}
Пример #6
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;
}
Пример #7
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;
	}

}
Пример #8
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);
}
Пример #9
0
static void network_properties_reply(DBusPendingCall *call, void *user_data)
{
	char *path = user_data;
	struct connman_device *device;
	struct connman_network *network;
	DBusMessage *reply;
	DBusMessageIter uuids;
	const char *parent = NULL, *address = NULL, *name = NULL;
	struct ether_addr addr;
	char ident[13];

	reply = dbus_pending_call_steal_reply(call);

	extract_properties(reply, &parent, &address, NULL, &name,
						NULL, NULL, &uuids, NULL);

	if (parent == NULL)
		goto done;

	device = g_hash_table_lookup(bluetooth_devices, parent);
	if (device == NULL)
		goto done;

	if (address == NULL)
		goto done;

	ether_aton_r(address, &addr);

	snprintf(ident, 13, "%02x%02x%02x%02x%02x%02x",
						addr.ether_addr_octet[0],
						addr.ether_addr_octet[1],
						addr.ether_addr_octet[2],
						addr.ether_addr_octet[3],
						addr.ether_addr_octet[4],
						addr.ether_addr_octet[5]);

	if (has_pan(&uuids) == FALSE)
		goto done;

	network = connman_device_get_network(device, ident);
	if (network != NULL)
		goto done;

	network = connman_network_create(ident,
					CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN);
	if (network == NULL)
		goto done;

	connman_network_set_string(network, "Path", path);

	connman_network_set_name(network, name);

	g_hash_table_replace(bluetooth_networks, g_strdup(path), network);

	connman_device_add_network(device, network);

	connman_network_set_group(network, ident);

done:
	dbus_message_unref(reply);

	dbus_pending_call_unref(call);
}