bool ActivateConnectionService::activate_connection_cb(ActivateConnection::Request& request, ActivateConnection::Response& response) { const NetworkConnections::ConstPtr connections = m_latest_connections; if (!connections) //haven't yet received any connection data return false; NMDevice * device = nm_client_get_device_by_iface(m_client, request.device_iface.c_str()); if (device == NULL) { ROS_WARN("Could not find device: '%s'", request.device_iface.c_str()); response.message = "Could not find device: '"; response.message += request.device_iface; response.message += "'"; return true; } //get the connection info for this active connection const char* path = NULL; std::vector<NetworkConnection>::const_iterator itr = connections->list.begin(); for (; itr != connections->list.end(); ++itr) { if (itr->name == request.connection_name) { path = itr->path.c_str(); break; } } NMConnection * connection = NULL; if (path != NULL) connection = NM_CONNECTION(nm_remote_settings_get_connection_by_path(m_remote_settings, path)); if (connection == NULL) { ROS_WARN( "Could not find connection: '%s'", request.connection_name.c_str()); response.message = "Could not find connection: '"; response.message += request.connection_name; response.message += "'"; return true; } ROS_INFO( "Activiting Connection: '%s' on %s", request.connection_name.c_str(), request.device_iface.c_str()); nm_client_activate_connection(m_client, connection, device, NULL, NULL, NULL); return true; }
static NMConnection * device_find_connection (NMRemoteSettings *remote_settings, NMDevice *device) { GSList *list, *iterator; NMConnection *connection = NULL; NMActiveConnection *ac; ac = nm_device_get_active_connection (device); if (ac) { return (NMConnection*)nm_remote_settings_get_connection_by_path (remote_settings, nm_active_connection_get_connection (ac)); } /* not found in active connections - check all available connections */ list = valid_connections_for_device (remote_settings, device); if (list != NULL) { /* if list has only one connection, use this connection */ if (g_slist_length (list) == 1) { connection = list->data; goto out; } /* is there connection with the MAC address of the device? */ for (iterator = list; iterator; iterator = iterator->next) { connection = iterator->data; if (compare_mac_device_with_mac_connection (device, connection)) goto out; } } /* no connection found for the given device */ connection = NULL; out: g_slist_free (list); return connection; }