/** * @brief Create a new qmi device, set default values and insert it in the hash table. */ static int qmi_probe(struct connman_device *device) { struct qmi_data *qmi; DBG("device %p", device); g_return_val_if_fail(device, -ENODEV); qmi = g_try_new0(struct qmi_data, 1); if(qmi == NULL) { connman_error("Allocation error, no memory available."); return -ENOMEM; } DBG("device %p data %p", device, qmi); connman_device_set_data(device, qmi); qmi->device = connman_device_ref(device); qmi->network = NULL; qmi->qmi_proxy_device = NULL; qmi->modem_opening = FALSE; qmi->modem_connected = FALSE; qmi->modem_opened = FALSE; qmi->imsi = NULL; qmi->apn = NULL; /* Group has to be "IMSI_qmi" */ qmi->group = NULL; qmi->strength = 0; /* Name of the provider e.g "o2" */ qmi->provider = NULL; /* Name of the specific QMI-Device e.g. wwan0 */ qmi->devname = g_strdup(connman_device_get_string(device, "Interface")); /* Index of the specific QMI-Device */ qmi->index = connman_device_get_index(device); qmi->devpath = get_device_path_from_name(qmi->devname); qmi->object_path = NULL; qmi->qmi_proxy_device = NULL; DBG("device name %s path %s", qmi->devname, qmi->devpath); if(qmi->devpath == NULL) { connman_error("No device path available"); return -ENODEV; } connman_device_set_string(device, "Path", qmi->devpath); g_hash_table_insert(qmi_hash, qmi->devpath, qmi); /* Signal to init thread a new connected modem is available. */ sem_post(&new_device_sem); return 0; }
static void jolla_gps_disconnect(DBusConnection *conn, void *user_data) { (void)conn; (void)user_data; DBG(""); connman_device_set_string(jolla_gps_device, "Path", NULL); }
static void jolla_gps_connect(DBusConnection *conn, void *user_data) { (void)user_data; DBG(""); connman_device_set_string(jolla_gps_device, "Path", JOLLA_DEVICE_PATH); change_powered(conn, connman_device_get_powered(jolla_gps_device)); }
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); }