Esempio n. 1
0
static int mk3_enable(struct connman_device *device) {

	int err = 0;
	struct mk3_data *mk3 = NULL;

	DBG("device %p", device);

	g_return_val_if_fail(device, -ENODEV);

	mk3 = connman_device_get_data(device);
	if(!mk3) {

		connman_error("No device data available");
		return -ENODEV;
	}

	DBG("device %p data %p", device, mk3);

	err = connman_inet_ifup(mk3->index);
	if(err < 0) {

		connman_error("QMI device could not getting up with ifup");
		return err;
	}

	add_network(mk3);

	return 0;
}
Esempio n. 2
0
/**
* @brief Enable qmi device and add network if modem opened
*/
static int qmi_enable(struct connman_device *device)
{
	int err = 0;
	struct qmi_data *qmi = NULL;

	DBG("device %p", device);

	g_return_val_if_fail(device, -ENODEV);

	qmi = connman_device_get_data(device);
	if(!qmi) {

		connman_error("No device data available");
		return -ENODEV;
	}

	DBG("device %p data %p", device, qmi);

	/* Add new qmi network interface */
	err = connman_inet_ifup(qmi->index);
	if(err < 0) {

		connman_error("QMI device could not getting up with ifup");
		return err;
	}

	if(qmi->modem_opened == TRUE) {

		add_network(qmi);
	}

	return 0;
}
Esempio n. 3
0
static int ethernet_enable(struct connman_device *device)
{
	struct ethernet_data *ethernet = connman_device_get_data(device);

	_DBG_ETHERNET("device %p", device);

	return connman_inet_ifup(ethernet->index);
}
Esempio n. 4
0
static int mbm_enable(struct connman_device *device)
{
	struct mbm_data *data = connman_device_get_data(device);
	const char *devnode;
	GIOChannel *channel;
	struct termios ti;
	int fd, index;

	_DBG_MBM("device %p", device);

	devnode = connman_device_get_control(device);
	if (devnode == NULL)
		return -EIO;

	fd = open(devnode, O_RDWR | O_NOCTTY);
	if (fd < 0)
		return -ENODEV;

	tcflush(fd, TCIOFLUSH);

	/* Switch TTY to raw mode */
	memset(&ti, 0, sizeof(ti));
	cfmakeraw(&ti);

	tcsetattr(fd, TCSANOW, &ti);

	channel = g_io_channel_unix_new(fd);
	if (channel == NULL) {
		close(fd);
		return -ENOMEM;
	}

	data->chat = g_at_chat_new(channel, 0);
	if (data->chat == NULL)
		return -EIO;

	g_io_channel_unref(channel);

	g_at_chat_register(data->chat, "*EMRDY:", notify_callback,
							FALSE, NULL, NULL);
	g_at_chat_register(data->chat, "*EMWI:", notify_callback,
							FALSE, NULL, NULL);
	g_at_chat_register(data->chat, "+PACSP", notify_callback,
							FALSE, NULL, NULL);

	index = connman_device_get_index(device);
	connman_inet_ifup(index);

	g_at_chat_send(data->chat, "AT&F E0 V1 X4 &C1 +CMEE=1", NULL,
					generic_callback, NULL, NULL);

	g_at_chat_send(data->chat, "AT+CFUN?", cfun_prefix,
					cfun_callback, device, NULL);
	g_at_chat_send(data->chat, "AT+CFUN=1", NULL,
					cfun_callback, device, NULL);

	return -EINPROGRESS;
}
Esempio n. 5
0
int __connman_device_enable(struct connman_device *device)
{
	int err;

	DBG("device %p", device);

	if (!device->driver || !device->driver->enable)
		return -EOPNOTSUPP;

	/* There is an ongoing power disable request. */
	if (device->powered_pending == PENDING_DISABLE)
		return -EBUSY;

	if (device->powered_pending == PENDING_ENABLE)
		return -EALREADY;

	if (device->powered_pending == PENDING_NONE && device->powered)
		return -EALREADY;

	if (device->index > 0) {
		err = connman_inet_ifup(device->index);
		if (err < 0 && err != -EALREADY)
			return err;
	}

	device->powered_pending = PENDING_ENABLE;

	err = device->driver->enable(device);
	/*
	 * device gets enabled right away.
	 * Invoke the callback
	 */
	if (err == 0) {
		connman_device_set_powered(device, true);
		goto done;
	}

	if (err == -EALREADY) {
		/* If device is already powered, but connman is not updated */
		connman_device_set_powered(device, true);
		goto done;
	}
	/*
	 * if err == -EINPROGRESS, then the DBus call to the respective daemon
	 * was successful. We set a 4 sec timeout so if the daemon never
	 * returns a reply, we would reset the pending request.
	 */
	if (err == -EINPROGRESS)
		device->pending_timeout = g_timeout_add_seconds(4,
					device_pending_reset, device);
done:
	return err;
}
Esempio n. 6
0
static void enable_tethering(struct connman_technology *technology,
                             const char *bridge)
{
    GList *list;

    for (list = cdc_interface_list; list; list = list->next) {
        int index = GPOINTER_TO_INT(list->data);

        connman_technology_tethering_notify(technology, TRUE);

        connman_inet_ifup(index);

        connman_inet_add_to_bridge(index, bridge);
    }
}
Esempio n. 7
0
static int enable_bridge(const char *name)
{
	int err, index;

	index = connman_inet_ifindex(name);
	if (index < 0)
		return index;

	err = __connman_inet_modify_address(RTM_NEWADDR,
			NLM_F_REPLACE | NLM_F_ACK, index, AF_INET,
					BRIDGE_IP, NULL, 24, BRIDGE_BCAST);
	if (err < 0)
		return err;

	return connman_inet_ifup(index);
}
Esempio n. 8
0
int __connman_bridge_enable(const char *name, const char *gateway,
				const char *broadcast)
{
	int err, index;

	index = connman_inet_ifindex(name);
	if (index < 0)
		return index;

	err = __connman_inet_modify_address(RTM_NEWADDR,
			NLM_F_REPLACE | NLM_F_ACK, index, AF_INET,
					gateway, NULL, 24, broadcast);
	if (err < 0)
		return err;

	return connman_inet_ifup(index);
}
Esempio n. 9
0
static DBusMessage *vpn_notify(struct connman_task *task,
                               DBusMessage *msg, void *user_data)
{
    struct connman_provider *provider = user_data;
    struct vpn_data *data;
    struct vpn_driver_data *vpn_driver_data;
    const char *name;
    int state, index;

    data = connman_provider_get_data(provider);

    name = connman_provider_get_driver_name(provider);
    if (name == NULL)
        return NULL;

    vpn_driver_data = g_hash_table_lookup(driver_hash, name);
    if (vpn_driver_data == NULL)
        return NULL;

    state = vpn_driver_data->vpn_driver->notify(msg, provider);
    switch (state) {
    case VPN_STATE_CONNECT:
    case VPN_STATE_READY:
        index = connman_provider_get_index(provider);
        data->watch = connman_rtnl_add_newlink_watch(index,
                      vpn_newlink, provider);
        connman_inet_ifup(index);
        break;

    case VPN_STATE_UNKNOWN:
    case VPN_STATE_IDLE:
    case VPN_STATE_DISCONNECT:
    case VPN_STATE_FAILURE:
        connman_provider_set_state(provider,
                                   CONNMAN_PROVIDER_STATE_DISCONNECT);
        break;

    case VPN_STATE_AUTH_FAILURE:
        connman_provider_indicate_error(provider,
                                        CONNMAN_PROVIDER_ERROR_AUTH_FAILED);
        break;
    }

    return NULL;
}
Esempio n. 10
0
static void setup_tun_interface(unsigned int flags, unsigned change,
		void *data)
{
	struct connman_private_network *pn = data;
	unsigned char prefixlen;
	DBusMessageIter array, dict;
	int err;

	DBG("index %d flags %d change %d", pn->index,  flags, change);

	if (flags & IFF_UP)
		return;

	prefixlen =
		__connman_ipconfig_netmask_prefix_len(PRIVATE_NETWORK_NETMASK);

	if ((__connman_inet_modify_address(RTM_NEWADDR,
				NLM_F_REPLACE | NLM_F_ACK, pn->index, AF_INET,
				pn->server_ip, pn->peer_ip,
				prefixlen, NULL)) < 0) {
		DBG("address setting failed");
		return;
	}

	connman_inet_ifup(pn->index);

	err = enable_nat(default_interface);
	if (err < 0) {
		connman_error("failed to enable NAT on %s", default_interface);
		goto error;
	}

	dbus_message_iter_init_append(pn->reply, &array);

	dbus_message_iter_append_basic(&array, DBUS_TYPE_OBJECT_PATH,
						&pn->path);

	connman_dbus_dict_open(&array, &dict);

	connman_dbus_dict_append_basic(&dict, "ServerIPv4",
					DBUS_TYPE_STRING, &pn->server_ip);
	connman_dbus_dict_append_basic(&dict, "PeerIPv4",
					DBUS_TYPE_STRING, &pn->peer_ip);
	connman_dbus_dict_append_basic(&dict, "PrimaryDNS",
					DBUS_TYPE_STRING, &pn->primary_dns);
	connman_dbus_dict_append_basic(&dict, "SecondaryDNS",
					DBUS_TYPE_STRING, &pn->secondary_dns);

	connman_dbus_dict_close(&array, &dict);

	dbus_message_iter_append_basic(&array, DBUS_TYPE_UNIX_FD, &pn->fd);

	g_dbus_send_message(connection, pn->reply);

	return;

error:
	pn->reply = __connman_error_failed(pn->msg, -err);
	g_dbus_send_message(connection, pn->reply);

	g_hash_table_remove(pn_hash, pn->path);
}
Esempio n. 11
0
static void setup_tun_interface(unsigned int flags, unsigned change,
		void *data)
{
	struct connman_private_network *pn = data;
	unsigned char prefixlen;
	DBusMessageIter array, dict;
	const char *server_ip;
	const char *peer_ip;
	const char *subnet_mask;
	int err;

	DBG("index %d flags %d change %d", pn->index,  flags, change);

	if (flags & IFF_UP)
		return;

	subnet_mask = __connman_ippool_get_subnet_mask(pn->pool);
	server_ip = __connman_ippool_get_start_ip(pn->pool);
	peer_ip = __connman_ippool_get_end_ip(pn->pool);
	prefixlen = connman_ipaddress_calc_netmask_len(subnet_mask);

	if ((__connman_inet_modify_address(RTM_NEWADDR,
				NLM_F_REPLACE | NLM_F_ACK, pn->index, AF_INET,
				server_ip, peer_ip, prefixlen, NULL)) < 0) {
		DBG("address setting failed");
		return;
	}

	connman_inet_ifup(pn->index);

	err = __connman_nat_enable(BRIDGE_NAME, server_ip, prefixlen);
	if (err < 0) {
		connman_error("failed to enable NAT");
		goto error;
	}

	dbus_message_iter_init_append(pn->reply, &array);

	dbus_message_iter_append_basic(&array, DBUS_TYPE_OBJECT_PATH,
						&pn->path);

	connman_dbus_dict_open(&array, &dict);

	connman_dbus_dict_append_basic(&dict, "ServerIPv4",
					DBUS_TYPE_STRING, &server_ip);
	connman_dbus_dict_append_basic(&dict, "PeerIPv4",
					DBUS_TYPE_STRING, &peer_ip);
	if (pn->primary_dns)
		connman_dbus_dict_append_basic(&dict, "PrimaryDNS",
					DBUS_TYPE_STRING, &pn->primary_dns);

	if (pn->secondary_dns)
		connman_dbus_dict_append_basic(&dict, "SecondaryDNS",
					DBUS_TYPE_STRING, &pn->secondary_dns);

	connman_dbus_dict_close(&array, &dict);

	dbus_message_iter_append_basic(&array, DBUS_TYPE_UNIX_FD, &pn->fd);

	g_dbus_send_message(connection, pn->reply);

	return;

error:
	pn->reply = __connman_error_failed(pn->msg, -err);
	g_dbus_send_message(connection, pn->reply);

	g_hash_table_remove(pn_hash, pn->path);
}
Esempio n. 12
0
static DBusMessage *vpn_notify(struct connman_task *task,
			DBusMessage *msg, void *user_data)
{
	struct vpn_provider *provider = user_data;
	struct vpn_data *data;
	struct vpn_driver_data *vpn_driver_data;
	const char *name;
	int state, index, err;

	data = vpn_provider_get_data(provider);

	name = vpn_provider_get_driver_name(provider);

	if (!name) {
		DBG("Cannot find VPN driver for provider %p", provider);
		vpn_provider_set_state(provider, VPN_PROVIDER_STATE_FAILURE);
		return NULL;
	}

	vpn_driver_data = g_hash_table_lookup(driver_hash, name);
	if (!vpn_driver_data) {
		DBG("Cannot find VPN driver data for name %s", name);
		vpn_provider_set_state(provider, VPN_PROVIDER_STATE_FAILURE);
		return NULL;
	}

	state = vpn_driver_data->vpn_driver->notify(msg, provider);

	DBG("provider %p driver %s state %d", provider, name, state);

	switch (state) {
	case VPN_STATE_CONNECT:
	case VPN_STATE_READY:
		if (data->state == VPN_STATE_READY) {
			/*
			 * This is the restart case, in which case we must
			 * just set the IP address.
			 *
			 * We need to remove first the old address, just
			 * replacing the old address will not work as expected
			 * because the old address will linger in the interface
			 * and not disapper so the clearing is needed here.
			 *
			 * Also the state must change, otherwise the routes
			 * will not be set properly.
			 */
			vpn_provider_set_state(provider,
						VPN_PROVIDER_STATE_CONNECT);

			vpn_provider_clear_address(provider, AF_INET);
			vpn_provider_clear_address(provider, AF_INET6);

			vpn_provider_change_address(provider);
			vpn_provider_set_state(provider,
						VPN_PROVIDER_STATE_READY);
			break;
		}

		index = vpn_provider_get_index(provider);
		vpn_provider_ref(provider);
		data->watch = vpn_rtnl_add_newlink_watch(index,
						     vpn_newlink, provider);
		err = connman_inet_ifup(index);
		if (err < 0) {
			if (err == -EALREADY)
				/*
				 * So the interface is up already, that is just
				 * great. Unfortunately in this case the
				 * newlink watch might not have been called at
				 * all. We must manually call it here so that
				 * the provider can go to ready state and the
				 * routes are setup properly.
				 */
				vpn_newlink(IFF_UP, 0, provider);
			else
				DBG("Cannot take interface %d up err %d/%s",
					index, -err, strerror(-err));
		}
		break;

	case VPN_STATE_UNKNOWN:
	case VPN_STATE_IDLE:
	case VPN_STATE_DISCONNECT:
	case VPN_STATE_FAILURE:
		vpn_provider_set_state(provider,
					VPN_PROVIDER_STATE_DISCONNECT);
		break;

	case VPN_STATE_AUTH_FAILURE:
		vpn_provider_indicate_error(provider,
					VPN_PROVIDER_ERROR_AUTH_FAILED);
		break;
	}

	return NULL;
}