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