Ejemplo n.º 1
0
static int jolla_gps_init()
{
    DBG("");

    connection = connman_dbus_get_connection();
    if (connection == NULL) {
        connman_warn("Failed to get dbus connection");
        return -EIO;
    }

    watch = g_dbus_add_service_watch(connection, JOLLA_SERVICE, jolla_gps_connect,
                                     jolla_gps_disconnect, NULL, NULL);
    if (watch == 0) {
        connman_warn("Failed to add jolla service watcher");
        dbus_connection_unref(connection);
        return -EIO;
    }

    device_watch = g_dbus_add_signal_watch(connection, JOLLA_SERVICE, JOLLA_DEVICE_PATH,
                                           JOLLA_DEVICE_INTERFACE, PROPERTY_CHANGED,
                                           device_changed, NULL, NULL);
    if (device_watch == 0) {
        connman_warn("Failed to add jolla device property changed signal watcher");
        g_dbus_remove_watch(connection, watch);
        dbus_connection_unref(connection);
        return -EIO;
    }

    if (connman_technology_driver_register(&tech_driver) < 0) {
        connman_warn("Failed to initialize technology for Jolla GPS");
        g_dbus_remove_watch(connection, device_watch);
        g_dbus_remove_watch(connection, watch);
        dbus_connection_unref(connection);
        return -EIO;
    }

    if (connman_device_driver_register(&device_driver) < 0) {
        connman_warn("Failed to initialize device driver for " JOLLA_SERVICE);
        connman_technology_driver_unregister(&tech_driver);
        g_dbus_remove_watch(connection, device_watch);
        g_dbus_remove_watch(connection, watch);
        dbus_connection_unref(connection);
        return -EIO;
    }

    jolla_gps_device = connman_device_create("gps", CONNMAN_DEVICE_TYPE_GPS);
    if (jolla_gps_device == NULL) {
        connman_warn("Failed to creat GPS device");
        return -ENODEV;
    }

    if (connman_device_register(jolla_gps_device) < 0) {
        connman_warn("Failed to register GPS device");
        connman_device_unref(jolla_gps_device);
        jolla_gps_device = NULL;
        return -EIO;
    }

    return 0;
}
Ejemplo n.º 2
0
static int hh2serial_init(void)
{
	connman_device_driver_register(&hh2seial_device_driver);

	hh2serial_device = connman_device_create("hh2serial_gps",
						CONNMAN_DEVICE_TYPE_GPS);
	if (hh2serial_device == NULL)
		return -ENODEV;

	connman_device_register(hh2serial_device);

	return 0;
}
Ejemplo n.º 3
0
static void device_create(GDBusProxy *proxy)
{
	struct connman_device *device = NULL;
	const char *path = g_dbus_proxy_get_path(proxy);
	const char *address;
	char ident[BLUETOOTH_ADDR_LEN * 2 + 1];
	bool powered;

	address = proxy_get_string(proxy, "Address");
	if (!address)
		return;

	address2ident(address, ident);

	device = connman_device_create("bluetooth",
			CONNMAN_DEVICE_TYPE_BLUETOOTH);
	if (!device)
		return;

	connman_device_set_data(device, g_dbus_proxy_ref(proxy));
	connman_device_set_ident(device, ident);

	g_hash_table_replace(devices, g_strdup(path), device);

	DBG("device %p %s device powered %d adapter powered %d", device,
			path, connman_device_get_powered(device),
			proxy_get_bool(proxy, "Powered"));

	if (connman_device_register(device) < 0) {
		g_hash_table_remove(devices, device);
		return;
	}

	g_dbus_proxy_set_property_watch(proxy, adapter_property_change, NULL);

	powered = proxy_get_bool(proxy, "Powered");
	connman_device_set_powered(device, powered);

	if (proxy_get_role(proxy) && !bluetooth_tethering)
		tethering_create(path, NULL, NULL, false);
}
Ejemplo n.º 4
0
static void detect_newlink(unsigned short type, int index,
					unsigned flags, unsigned change)
{
	struct connman_device *device;
	enum connman_device_type devtype;

	DBG("type %d index %d", type, index);

	devtype = __connman_rtnl_get_device_type(index);

	switch (devtype) {
	case CONNMAN_DEVICE_TYPE_UNKNOWN:
	case CONNMAN_DEVICE_TYPE_VENDOR:
	case CONNMAN_DEVICE_TYPE_WIMAX:
	case CONNMAN_DEVICE_TYPE_BLUETOOTH:
	case CONNMAN_DEVICE_TYPE_CELLULAR:
	case CONNMAN_DEVICE_TYPE_GPS:
		return;
	case CONNMAN_DEVICE_TYPE_ETHERNET:
	case CONNMAN_DEVICE_TYPE_WIFI:
	case CONNMAN_DEVICE_TYPE_GADGET:
		break;
	}

	device = find_device(index);
	if (device != NULL)
		return;

	device = connman_inet_create_device(index);
	if (device == NULL)
		return;

	if (connman_device_register(device) < 0) {
		connman_device_unref(device);
		return;
	}

	device_list = g_slist_prepend(device_list, device);
}
Ejemplo n.º 5
0
static int hh2serial_init(void)
{
    int err;

    err = connman_device_driver_register(&hh2serial_device_driver);
    if (err < 0)
        return err;

    hh2serial_device = connman_device_create("hh2serial_gps",
                       CONNMAN_DEVICE_TYPE_GPS);
    if (!hh2serial_device) {
        connman_device_driver_unregister(&hh2serial_device_driver);
        return -ENODEV;
    }

    err = connman_device_register(hh2serial_device);
    if (err < 0) {
        connman_device_unref(hh2serial_device);
        return err;
    }

    return 0;
}
Ejemplo n.º 6
0
static void adapter_properties_reply(DBusPendingCall *call, void *user_data)
{
	char *path = user_data;
	struct connman_device *device;
	DBusMessage *reply;
	DBusMessageIter networks;
	const char *address = NULL, *name = NULL;
	dbus_bool_t powered = FALSE, scanning = FALSE;
	struct ether_addr addr;
	char ident[13];

	DBG("path %s", path);

	reply = dbus_pending_call_steal_reply(call);

	if (path == NULL)
		goto done;

	extract_properties(reply, NULL, &address, &name, NULL,
					&powered, &scanning, NULL, &networks);

	if (address == NULL)
		goto done;

	if (g_strcmp0(address, "00:00:00:00:00:00") == 0)
		goto done;

	device = g_hash_table_lookup(bluetooth_devices, path);
	if (device != NULL)
		goto update;

	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]);

	device = connman_device_create("bluetooth_legacy",
			CONNMAN_DEVICE_TYPE_BLUETOOTH);
	if (device == NULL)
		goto done;

	g_hash_table_insert(bluetooth_devices, g_strdup(path), device);

	connman_device_set_ident(device, ident);

	connman_device_set_string(device, "Path", path);

	if (connman_device_register(device) < 0) {
		connman_device_unref(device);
		g_hash_table_remove(bluetooth_devices, path);
		goto done;
	}

update:
	connman_device_set_string(device, "Address", address);
	connman_device_set_string(device, "Name", name);
	connman_device_set_string(device, "Path", path);

	connman_device_set_powered(device, powered);
	connman_device_set_scanning(device, scanning);

	if (powered == FALSE) {
		remove_device_networks(device);
		add_pending_networks(path, &networks);
	} else
		check_networks(&networks);

done:
	dbus_message_unref(reply);

	dbus_pending_call_unref(call);
}