static int mk3_probe(struct connman_device *device) { struct mk3_data *mk3; gint i; GString *str; DBG("device %p", device); g_return_val_if_fail(device, -ENODEV); mk3 = g_try_new0(struct mk3_data, 1); if(mk3 == NULL) { connman_error("Allocation error, no memory available."); return -ENOMEM; } DBG("device %p data %p", device, mk3); connman_device_set_data(device, mk3); mk3->device = connman_device_ref(device); /* Index of the specific QMI-Device */ mk3->index = connman_device_get_index(device); /* Name of the specific Device tun_mk3 */ mk3->devname = g_strdup(connman_device_get_string(device, "Interface")); mk3->name = g_strdup("car2car"); mk3->group = g_strdup("none"); str = g_string_new(NULL); for(i = 0; i < strlen(mk3->devname); i++) { g_string_append_printf(str, "%02x", mk3->devname[i]); } g_string_append_c(str, '_'); for(i = 0; i < strlen(mk3->name); i++) { g_string_append_printf(str, "%02x", mk3->name[i]); } mk3->ident = g_string_free(str, FALSE); connman_device_set_ident(mk3->device, mk3->ident); return 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); }
struct connman_device *connman_device_create_from_index(int index) { enum connman_device_type type; struct connman_device *device; char *devname, *ident = NULL; char *addr = NULL, *name = NULL; if (index < 0) return NULL; devname = connman_inet_ifname(index); if (devname == NULL) return NULL; if (__connman_device_isfiltered(devname) == TRUE) { connman_info("Ignoring interface %s (filtered)", devname); g_free(devname); return NULL; } type = __connman_rtnl_get_device_type(index); switch (type) { case CONNMAN_DEVICE_TYPE_UNKNOWN: connman_info("Ignoring interface %s (type unknown)", devname); g_free(devname); return NULL; case CONNMAN_DEVICE_TYPE_ETHERNET: case CONNMAN_DEVICE_TYPE_GADGET: case CONNMAN_DEVICE_TYPE_WIFI: case CONNMAN_DEVICE_TYPE_CELLULAR: case CONNMAN_DEVICE_TYPE_QMI: case CONNMAN_DEVICE_TYPE_MK3: name = index2ident(index, ""); addr = index2addr(index); break; case CONNMAN_DEVICE_TYPE_BLUETOOTH: case CONNMAN_DEVICE_TYPE_GPS: case CONNMAN_DEVICE_TYPE_VENDOR: name = g_strdup(devname); break; } device = connman_device_create(name, type); if (device == NULL) goto done; switch (type) { case CONNMAN_DEVICE_TYPE_UNKNOWN: case CONNMAN_DEVICE_TYPE_VENDOR: case CONNMAN_DEVICE_TYPE_GPS: break; case CONNMAN_DEVICE_TYPE_ETHERNET: case CONNMAN_DEVICE_TYPE_GADGET: ident = index2ident(index, NULL); break; case CONNMAN_DEVICE_TYPE_WIFI: ident = index2ident(index, NULL); break; case CONNMAN_DEVICE_TYPE_BLUETOOTH: break; case CONNMAN_DEVICE_TYPE_CELLULAR: ident = index2ident(index, NULL); break; case CONNMAN_DEVICE_TYPE_QMI: case CONNMAN_DEVICE_TYPE_MK3: ident = index2ident(index, NULL); break; } connman_device_set_index(device, index); connman_device_set_interface(device, devname); if (ident != NULL) { connman_device_set_ident(device, ident); g_free(ident); } connman_device_set_string(device, "Address", addr); done: g_free(devname); g_free(name); g_free(addr); return device; }
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); }