-struct connman_device *__connman_element_get_device(struct connman_element *element)
-{
- if (element->type == CONNMAN_ELEMENT_TYPE_DEVICE &&
- element->device != NULL)
- return element->device;
-
- if (element->parent == NULL)
- return NULL;
-
- return __connman_element_get_device(element->parent);
-}
-
-struct find_data {
- enum connman_service_type type;
- struct connman_device *device;
- connman_bool_t error;
-};
-
-static gboolean find_device(GNode *node, gpointer user_data)
-{
- struct connman_element *element = node->data;
- struct find_data *data = user_data;
-
- if (element->type != CONNMAN_ELEMENT_TYPE_DEVICE)
- return FALSE;
-
- if (element->device == NULL)
- return FALSE;
-
- if (data->type != __connman_device_get_service_type(element->device))
- return FALSE;
-
- data->device = element->device;
-
- return TRUE;
-}
-
-struct connman_device *__connman_element_find_device(enum connman_service_type type)
-{
- struct find_data data = { .type = type, .device = NULL };
-
- g_node_traverse(element_root, G_PRE_ORDER,
- G_TRAVERSE_ALL, -1, find_device, &data);
-
- return data.device;
-}
-
-static gboolean request_scan(GNode *node, gpointer user_data)
-{
- struct connman_element *element = node->data;
- struct find_data *data = user_data;
- enum connman_service_type type;
-
- if (element->type != CONNMAN_ELEMENT_TYPE_DEVICE)
- return FALSE;
-
- if (element->device == NULL)
- return FALSE;
-
- type = __connman_device_get_service_type(element->device);
-
- switch (type) {
- case CONNMAN_SERVICE_TYPE_UNKNOWN:
- case CONNMAN_SERVICE_TYPE_SYSTEM:
- case CONNMAN_SERVICE_TYPE_ETHERNET:
- case CONNMAN_SERVICE_TYPE_BLUETOOTH:
- case CONNMAN_SERVICE_TYPE_CELLULAR:
- case CONNMAN_SERVICE_TYPE_GPS:
- case CONNMAN_SERVICE_TYPE_VPN:
- case CONNMAN_SERVICE_TYPE_GADGET:
- return FALSE;
- case CONNMAN_SERVICE_TYPE_WIFI:
- case CONNMAN_SERVICE_TYPE_WIMAX:
- if (data->type != CONNMAN_SERVICE_TYPE_UNKNOWN &&
- data->type != type)
- return FALSE;
- break;
- }
-
- __connman_device_scan(element->device);
-
- return FALSE;
-}
-
-int __connman_element_request_scan(enum connman_service_type type)
-{
- struct find_data data = { .type = type, .device = NULL };
-
- g_node_traverse(element_root, G_PRE_ORDER,
- G_TRAVERSE_ALL, -1, request_scan, &data);
-
- return 0;
-}
-
-static gboolean enable_technology(GNode *node, gpointer user_data)
-{
- struct connman_element *element = node->data;
- struct find_data *data = user_data;
- enum connman_service_type type;
- int err;
-
- if (element->type != CONNMAN_ELEMENT_TYPE_DEVICE)
- return FALSE;
-
- if (element->device == NULL)
- return FALSE;
-
- type = __connman_device_get_service_type(element->device);
-
- switch (type) {
- case CONNMAN_SERVICE_TYPE_UNKNOWN:
- case CONNMAN_SERVICE_TYPE_SYSTEM:
- case CONNMAN_SERVICE_TYPE_GPS:
- case CONNMAN_SERVICE_TYPE_VPN:
- case CONNMAN_SERVICE_TYPE_GADGET:
- return FALSE;
- case CONNMAN_SERVICE_TYPE_ETHERNET:
- case CONNMAN_SERVICE_TYPE_WIFI:
- case CONNMAN_SERVICE_TYPE_WIMAX:
- case CONNMAN_SERVICE_TYPE_BLUETOOTH:
- case CONNMAN_SERVICE_TYPE_CELLULAR:
- if (data->type != CONNMAN_SERVICE_TYPE_UNKNOWN &&
- data->type != type)
- return FALSE;
- break;
- }
-
- err = __connman_device_enable_persistent(element->device);
- if (err == 0 || (err < 0 && err == -EINPROGRESS))
- data->error = FALSE;
-
- return FALSE;
-}
-
-int __connman_element_enable_technology(enum connman_service_type type)
-{
- struct find_data data = { .type = type, .device = NULL, .error = TRUE };
-
- g_node_traverse(element_root, G_PRE_ORDER,
- G_TRAVERSE_ALL, -1, enable_technology, &data);
-
- if (data.error == TRUE)
- return -ENODEV;
-
- return 0;
-}
-
-static gboolean disable_technology(GNode *node, gpointer user_data)
-{
- struct connman_element *element = node->data;
- struct find_data *data = user_data;
- enum connman_service_type type;
- int err;
-
- if (element->type != CONNMAN_ELEMENT_TYPE_DEVICE)
- return FALSE;
-
- if (element->device == NULL)
- return FALSE;
-
- type = __connman_device_get_service_type(element->device);
-
- switch (type) {
- case CONNMAN_SERVICE_TYPE_UNKNOWN:
- case CONNMAN_SERVICE_TYPE_SYSTEM:
- case CONNMAN_SERVICE_TYPE_GPS:
- case CONNMAN_SERVICE_TYPE_VPN:
- case CONNMAN_SERVICE_TYPE_GADGET:
- return FALSE;
- case CONNMAN_SERVICE_TYPE_ETHERNET:
- case CONNMAN_SERVICE_TYPE_WIFI:
- case CONNMAN_SERVICE_TYPE_WIMAX:
- case CONNMAN_SERVICE_TYPE_BLUETOOTH:
- case CONNMAN_SERVICE_TYPE_CELLULAR:
- if (data->type != CONNMAN_SERVICE_TYPE_UNKNOWN &&
- data->type != type)
- return FALSE;
- break;
- }
-
- err = __connman_device_disable_persistent(element->device);
- if (err == 0 || (err < 0 && err == -EINPROGRESS))
- data->error = FALSE;
-
- return FALSE;
-}
-
-int __connman_element_disable_technology(enum connman_service_type type)
-{
- struct find_data data = { .type = type, .device = NULL, .error = TRUE };
-
- g_node_traverse(element_root, G_PRE_ORDER,
- G_TRAVERSE_ALL, -1, disable_technology, &data);
-
- if (data.error == TRUE)
- return -ENODEV;
-
- return 0;
-}
-