Example #1
0
File: wispr.c Project: igaw/connman
static void portal_manage_status(GWebResult *result,
			struct connman_wispr_portal_context *wp_context)
{
	struct connman_service *service = wp_context->service;
	enum connman_ipconfig_type type = wp_context->type;
	const char *str = NULL;

	DBG("");

	/* We currently don't do anything with this info */
	if (g_web_result_get_header(result, "X-ConnMan-Client-IP",
				&str))
		connman_info("Client-IP: %s", str);

	if (g_web_result_get_header(result, "X-ConnMan-Client-Country",
				&str))
		connman_info("Client-Country: %s", str);

	if (g_web_result_get_header(result, "X-ConnMan-Client-Region",
				&str))
		connman_info("Client-Region: %s", str);

	if (g_web_result_get_header(result, "X-ConnMan-Client-Timezone",
				&str))
		connman_info("Client-Timezone: %s", str);

	free_connman_wispr_portal_context(wp_context);

	__connman_service_ipconfig_indicate_state(service,
					CONNMAN_SERVICE_STATE_ONLINE, type);
}
Example #2
0
static void process_newlink(unsigned short type, int index, unsigned flags,
			unsigned change, struct ifinfomsg *msg, int bytes)
{
	struct ether_addr address = {{ 0, 0, 0, 0, 0, 0 }};
	struct ether_addr compare = {{ 0, 0, 0, 0, 0, 0 }};
	struct rtnl_link_stats64 stats;
	unsigned char operstate = 0xff;
	struct interface_data *interface;
	const char *ifname = NULL;
	unsigned int mtu = 0;
	char ident[13], str[18];
	GSList *list;

	memset(&stats, 0, sizeof(stats));
	extract_link(msg, bytes, &address, &ifname, &mtu, &operstate, &stats);

	snprintf(ident, 13, "%02x%02x%02x%02x%02x%02x",
						address.ether_addr_octet[0],
						address.ether_addr_octet[1],
						address.ether_addr_octet[2],
						address.ether_addr_octet[3],
						address.ether_addr_octet[4],
						address.ether_addr_octet[5]);

	snprintf(str, 18, "%02X:%02X:%02X:%02X:%02X:%02X",
						address.ether_addr_octet[0],
						address.ether_addr_octet[1],
						address.ether_addr_octet[2],
						address.ether_addr_octet[3],
						address.ether_addr_octet[4],
						address.ether_addr_octet[5]);

	switch (type) {
	case ARPHRD_ETHER:
	case ARPHRD_LOOPBACK:
	case ARPHDR_PHONET_PIPE:
	case ARPHRD_NONE:
		__vpn_ipconfig_newlink(index, type, flags,
							str, mtu, &stats);
		break;
	}

	if (memcmp(&address, &compare, ETH_ALEN) != 0)
		connman_info("%s {newlink} index %d address %s mtu %u",
						ifname, index, str, mtu);

	if (operstate != 0xff)
		connman_info("%s {newlink} index %d operstate %u <%s>",
						ifname, index, operstate,
						operstate2str(operstate));

	interface = g_hash_table_lookup(interface_list, GINT_TO_POINTER(index));
	if (!interface) {
		interface = g_new0(struct interface_data, 1);
		interface->index = index;
		interface->ident = g_strdup(ident);

		g_hash_table_insert(interface_list,
					GINT_TO_POINTER(index), interface);
	}
Example #3
0
static int setup_hostname(void)
{
	char name[HOST_NAME_MAX + 1];

	memset(system_hostname, 0, sizeof(system_hostname));

	if (gethostname(system_hostname, HOST_NAME_MAX) < 0) {
		connman_error("Failed to get current hostname");
		return -EIO;
	}

	if (strlen(system_hostname) > 0 &&
				strcmp(system_hostname, "(none)") != 0)
		connman_info("System hostname is %s", system_hostname);
	else
		create_hostname();

	memset(name, 0, sizeof(name));

	if (getdomainname(name, HOST_NAME_MAX) < 0) {
		connman_error("Failed to get current domainname");
		return -EIO;
	}

	if (strlen(name) > 0 && strcmp(name, "(none)") != 0)
		connman_info("System domainname is %s", name);

	return 0;
}
void __vpn_ipconfig_newlink(int index, unsigned short type,
				unsigned int flags,
				const char *address,
				unsigned short mtu,
				struct rtnl_link_stats *stats)
{
	struct vpn_ipdevice *ipdevice;
	GString *str;

	if (type == ARPHRD_LOOPBACK)
		return;

	ipdevice = g_hash_table_lookup(ipdevice_hash, GINT_TO_POINTER(index));
	if (ipdevice != NULL)
		goto update;

	ipdevice = g_try_new0(struct vpn_ipdevice, 1);
	if (ipdevice == NULL)
		return;

	ipdevice->index = index;
	ipdevice->ifname = connman_inet_ifname(index);
	ipdevice->type = type;

	ipdevice->address = g_strdup(address);

	g_hash_table_insert(ipdevice_hash, GINT_TO_POINTER(index), ipdevice);

	connman_info("%s {create} index %d type %d <%s>", ipdevice->ifname,
						index, type, type2str(type));

update:
	ipdevice->mtu = mtu;

	if (flags == ipdevice->flags)
		return;

	ipdevice->flags = flags;

	str = g_string_new(NULL);
	if (str == NULL)
		return;

	if (flags & IFF_UP)
		g_string_append(str, "UP");
	else
		g_string_append(str, "DOWN");

	if (flags & IFF_RUNNING)
		g_string_append(str, ",RUNNING");

	if (flags & IFF_LOWER_UP)
		g_string_append(str, ",LOWER_UP");

	connman_info("%s {update} flags %u <%s>", ipdevice->ifname,
							flags, str->str);

	g_string_free(str, TRUE);
}
Example #5
0
static DBusMessage *connect_provider(DBusConnection *conn,
					DBusMessage *msg, void *data)
{
	int err;

	DBG("conn %p", conn);

	if (__connman_session_mode() == TRUE) {
		connman_info("Session mode enabled: "
				"direct provider connect disabled");

		return __connman_error_failed(msg, -EINVAL);
	}

	err = __connman_provider_create_and_connect(msg);
	if (err < 0) {
		if (err == -EINPROGRESS) {
			connman_error("Invalid return code from connect");
			err = -EINVAL;
		}

		return __connman_error_failed(msg, -err);
	}

	return NULL;
}
static void notify_handler(struct inotify_event *event,
                                        const char *filename)
{
	struct policy_file *file;

	DBG("event %x file %s", event->mask, filename);

	if (event->mask & IN_CREATE)
		return;

	if (!is_filename_valid(filename))
		return;

	/*
	 * load_file() will modify the global selinux/uid/gid hash
	 * tables. We need to remove the old entries first before
	 * else the table points to the wrong entries.
	 */
	g_hash_table_remove(file_hash, filename);

	if (event->mask & (IN_DELETE | IN_MOVED_FROM))
		return;

	if (event->mask & (IN_MOVED_TO | IN_MODIFY)) {
		connman_info("Policy update for '%s'", filename);

		file = g_new0(struct policy_file, 1);
		if (load_file(filename, file) < 0) {
			g_free(file);
			return;
		}

		g_hash_table_replace(file_hash, g_strdup(filename), file);
		recheck_sessions();
	}
Example #7
0
static gboolean signal_handler(GIOChannel *channel, GIOCondition cond,
							gpointer user_data)
{
	struct signalfd_siginfo si;
	ssize_t result;
	int fd;

	if (cond & (G_IO_NVAL | G_IO_ERR | G_IO_HUP))
		return FALSE;

	fd = g_io_channel_unix_get_fd(channel);

	result = read(fd, &si, sizeof(si));
	if (result != sizeof(si))
		return FALSE;

	switch (si.ssi_signo) {
	case SIGINT:
	case SIGTERM:
		if (__terminated == 0) {
			connman_info("Terminating");
			g_main_loop_quit(main_loop);
		}

		__terminated = 1;
		break;
	}

	return TRUE;
}
Example #8
0
static int loopback_set_hostname(const char *hostname)
{
	const char *ptr;
	int err, len;

	if (g_strcmp0(hostname, "<hostname>") == 0)
		return 0;

	len = strlen(hostname);

	if (connman_inet_check_hostname(hostname, len) == FALSE)
		return -EINVAL;

	if ((ptr = strstr(hostname, ".")) != NULL)
		len = ptr - hostname;

	if (sethostname(hostname, len) < 0) {
		err = -errno;
		connman_error("Failed to set hostname to %s", hostname);
		return err;
	}

	connman_info("Setting hostname to %s", hostname);

	return 0;
}
Example #9
0
void __connman_technology_remove_interface(enum connman_service_type type,
				int index, const char *name, const char *ident)
{
	struct connman_technology *technology;

	switch (type) {
	case CONNMAN_SERVICE_TYPE_UNKNOWN:
	case CONNMAN_SERVICE_TYPE_SYSTEM:
		return;
	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:
	case CONNMAN_SERVICE_TYPE_GPS:
	case CONNMAN_SERVICE_TYPE_VPN:
	case CONNMAN_SERVICE_TYPE_GADGET:
		break;
	}

	connman_info("Remove interface %s [ %s ]", name,
				__connman_service_type2string(type));

	technology = technology_find(type);

	if (technology == NULL || technology->driver == NULL)
		return;

	if (technology->driver->remove_interface)
		technology->driver->remove_interface(technology, index);

	technology_put(technology);
}
Example #10
0
static gboolean check_plugin(struct connman_plugin_desc *desc,
				const char *pattern, const char *exclude)
{
	if (exclude != NULL &&
			g_pattern_match_simple(exclude, desc->name) == TRUE) {
		connman_info("Excluding %s", desc->description);
		return FALSE;
	}

	if (pattern != NULL &&
			g_pattern_match_simple(pattern, desc->name) == FALSE) {
		connman_info("Ignoring %s", desc->description);
		return FALSE;
	}

	return TRUE;
}
Example #11
0
static void unregister_config(gpointer data)
{
	struct vpn_config *config = data;

	connman_info("Removing configuration %s", config->ident);

	g_hash_table_destroy(config->provider_table);

	g_free(config->description);
	g_free(config->name);
	g_free(config->ident);
	g_free(config);
}
Example #12
0
static gboolean check_kill(gpointer user_data)
{
	pid_t pid = GPOINTER_TO_INT(user_data);
	if (pid > 0) {
		if (kill(pid, 0) == 0) {
			connman_info("pid %d was not killed, "
					"retrying after 2 sec", pid);
			g_timeout_add_seconds(2, kill_timeout,
					GINT_TO_POINTER(pid));
		}
	}

	return FALSE;
}
static void free_ipdevice(gpointer data)
{
	struct vpn_ipdevice *ipdevice = data;

	connman_info("%s {remove} index %d", ipdevice->ifname,
							ipdevice->index);

	g_free(ipdevice->ipv4_gateway);
	g_free(ipdevice->ipv6_gateway);
	g_free(ipdevice->pac);

	g_free(ipdevice->address);

	g_free(ipdevice->ifname);
	g_free(ipdevice);
}
Example #14
0
void __connman_technology_add_interface(enum connman_service_type type,
				int index, const char *name, const char *ident)
{
	struct connman_technology *technology;
	GSList *tech_drivers;
	struct connman_technology_driver *driver;

	switch (type) {
	case CONNMAN_SERVICE_TYPE_UNKNOWN:
	case CONNMAN_SERVICE_TYPE_SYSTEM:
		return;
	case CONNMAN_SERVICE_TYPE_ETHERNET:
	case CONNMAN_SERVICE_TYPE_WIFI:
	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:
		break;
	}

	connman_info("Adding interface %s [ %s ]", name,
				__connman_service_type2string(type));

	technology = technology_find(type);

	if (technology == NULL)
		return;

	for (tech_drivers = technology->driver_list; tech_drivers != NULL;
	     tech_drivers = g_slist_next(tech_drivers)) {
		driver = tech_drivers->data;

		if(driver->add_interface != NULL)
			driver->add_interface(technology, index, name, ident);
	}

	/*
	 * At this point we can try to enable tethering automatically as
	 * now the interfaces are set properly.
	 */
	if (technology->tethering_persistent == TRUE)
		enable_tethering(technology);
}
Example #15
0
static int loopback_set_domainname(const char *domainname)
{
	int err, len;

	len = strlen(domainname);

	if (connman_inet_check_hostname(domainname, len) == FALSE)
		return -EINVAL;

	if (setdomainname(domainname, len) < 0) {
		err = -errno;
		connman_error("Failed to set domainname to %s", domainname);
		return err;
	}

	connman_info("Setting domainname to %s", domainname);

	return 0;
}
Example #16
0
static void scanning(struct supplicant_task *task, DBusMessage *msg)
{
	DBusError error;
	dbus_bool_t scanning;

	dbus_error_init(&error);

	if (dbus_message_get_args(msg, &error, DBUS_TYPE_BOOLEAN, &scanning,
						DBUS_TYPE_INVALID) == FALSE) {
		if (dbus_error_is_set(&error) == TRUE) {
			connman_error("%s", error.message);
			dbus_error_free(&error);
		} else
			connman_error("Wrong arguments for scanning");
		return;
	}

	connman_info("%s scanning %s", task->ifname,
				scanning == TRUE ? "started" : "finished");
}
Example #17
0
static DBusMessage *connect_provider(DBusConnection *conn,
					DBusMessage *msg, void *data)
{
	int err;

	DBG("conn %p", conn);

	if (__connman_session_mode()) {
		connman_info("Session mode enabled: "
				"direct provider connect disabled");

		return __connman_error_failed(msg, EINVAL);
	}

	err = __connman_provider_create_and_connect(msg);
	if (err < 0)
		return __connman_error_failed(msg, -err);

	return NULL;
}
Example #18
0
int __connman_device_set_blocked(struct connman_device *device,
						connman_bool_t blocked)
{
	connman_bool_t powered;

	DBG("device %p blocked %d", device, blocked);

	device->blocked = blocked;

	if (device->offlinemode == TRUE)
		return 0;

	connman_info("%s {rfkill} blocked %d", device->interface, blocked);

	if (blocked == FALSE)
		powered = device->powered_persistent;
	else
		powered = FALSE;

	return set_powered(device, powered);
}
Example #19
0
void __connman_technology_remove_interface(enum connman_service_type type,
				int index, const char *name, const char *ident)
{
	struct connman_technology *technology;
	GSList *tech_drivers;
	struct connman_technology_driver *driver;

	switch (type) {
	case CONNMAN_SERVICE_TYPE_UNKNOWN:
	case CONNMAN_SERVICE_TYPE_SYSTEM:
		return;
	case CONNMAN_SERVICE_TYPE_ETHERNET:
	case CONNMAN_SERVICE_TYPE_WIFI:
	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:
		break;
	}

	connman_info("Remove interface %s [ %s ]", name,
				__connman_service_type2string(type));

	technology = technology_find(type);

	if (technology == NULL)
		return;

	for (tech_drivers = technology->driver_list; tech_drivers != NULL;
	     tech_drivers = g_slist_next(tech_drivers)) {
		driver = tech_drivers->data;

		if(driver->remove_interface != NULL)
			driver->remove_interface(technology, index);
	}
}
Example #20
0
static struct vpn_config *create_config(const char *ident)
{
	struct vpn_config *config;

	DBG("ident %s", ident);

	if (g_hash_table_lookup(config_table, ident) != NULL)
		return NULL;

	config = g_try_new0(struct vpn_config, 1);
	if (config == NULL)
		return NULL;

	config->ident = g_strdup(ident);

	config->provider_table = g_hash_table_new_full(g_str_hash, g_str_equal,
						NULL, unregister_provider);

	g_hash_table_insert(config_table, config->ident, config);

	connman_info("Adding configuration %s", config->ident);

	return config;
}
Example #21
0
static void unregister_provider(gpointer data)
{
	struct vpn_config_provider *config_provider = data;
	struct vpn_provider *provider;
	char *provider_id;

	if (cleanup == TRUE)
		goto free_only;

	provider_id = config_provider->provider_identifier;

	connman_info("Removing provider configuration %s provider %s",
				config_provider->ident, provider_id);

	provider = __vpn_provider_lookup(provider_id);
	if (provider != NULL)
		__vpn_provider_delete(provider);
	else {
		if (__connman_storage_remove_provider(provider_id) == FALSE)
			DBG("Could not remove all files for provider %s",
								provider_id);
	}

free_only:
	g_free(config_provider->ident);
	g_free(config_provider->type);
	g_free(config_provider->name);
	g_free(config_provider->host);
	g_free(config_provider->domain);
	g_free(config_provider->networks);
	g_hash_table_destroy(config_provider->setting_strings);
	g_free(config_provider->provider_identifier);
	g_free(config_provider->config_ident);
	g_free(config_provider->config_entry);
	g_free(config_provider);
}
Example #22
0
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;
}
Example #23
0
static int setup_loopback(void)
{
	struct ifreq ifr;
	struct sockaddr_in addr;
	int sk, err;

	sk = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
	if (sk < 0)
		return -errno;

	memset(&ifr, 0, sizeof(ifr));
	strcpy(ifr.ifr_name, "lo");

	if (ioctl(sk, SIOCGIFFLAGS, &ifr) < 0) {
		err = -errno;
		goto done;
	}

	if (ifr.ifr_flags & IFF_UP) {
		connman_info("Checking loopback interface settings");
		if (valid_loopback(sk, &ifr) == TRUE) {
			err = -EALREADY;
			goto done;
		}

		connman_warn("Correcting wrong lookback settings");
	}

	memset(&addr, 0, sizeof(addr));
	addr.sin_family = AF_INET;
	addr.sin_addr.s_addr = loopback_address;
	memcpy(&ifr.ifr_addr, &addr, sizeof(ifr.ifr_addr));

	err = ioctl(sk, SIOCSIFADDR, &ifr);
	if (err < 0) {
		err = -errno;
		connman_error("Setting address failed (%s)", strerror(-err));
		goto done;
	}

	memset(&addr, 0, sizeof(addr));
	addr.sin_family = AF_INET;
	addr.sin_addr.s_addr = loopback_netmask;
	memcpy(&ifr.ifr_netmask, &addr, sizeof(ifr.ifr_netmask));

	err = ioctl(sk, SIOCSIFNETMASK, &ifr);
	if (err < 0) {
		err = -errno;
		connman_error("Setting netmask failed (%s)", strerror(-err));
		goto done;
	}

	if (ioctl(sk, SIOCGIFFLAGS, &ifr) < 0) {
		err = -errno;
		goto done;
	}

	ifr.ifr_flags |= IFF_UP;

	if (ioctl(sk, SIOCSIFFLAGS, &ifr) < 0) {
		err = -errno;
		connman_error("Activating loopback interface failed (%s)",
							strerror(-err));
		goto done;
	}

done:
	close(sk);

	return err;
}
Example #24
0
static void dhcp_debug(const char *str, void *data)
{
	connman_info("%s: %s", (const char *) data, str);
}
Example #25
0
static void resolv_debug(const char *str, void *data)
{
	connman_info("%s: %s\n", (const char *) data, str);
}
Example #26
0
static void decode_msg(void *base, size_t len, struct timeval *tv,
		struct timespec *mrx_time)
{
	struct ntp_msg *msg = base;
	double m_delta, org, rec, xmt, dst;
	double delay, offset;
	static guint transmit_delay;

	if (len < sizeof(*msg)) {
		connman_error("Invalid response from time server");
		return;
	}

	if (!tv) {
		connman_error("Invalid packet timestamp from time server");
		return;
	}

	DBG("flags      : 0x%02x", msg->flags);
	DBG("stratum    : %u", msg->stratum);
	DBG("poll       : %f seconds (%d)",
				LOGTOD(msg->poll), msg->poll);
	DBG("precision  : %f seconds (%d)",
				LOGTOD(msg->precision), msg->precision);
	DBG("root delay : %u seconds (fraction %u)",
			msg->rootdelay.seconds, msg->rootdelay.fraction);
	DBG("root disp. : %u seconds (fraction %u)",
			msg->rootdisp.seconds, msg->rootdisp.fraction);
	DBG("reference  : 0x%04x", msg->refid);

	transmit_delay = LOGTOD(msg->poll);

	if (NTP_FLAGS_LI_DECODE(msg->flags) == NTP_FLAG_LI_NOTINSYNC) {
		DBG("ignoring unsynchronized peer");
		return;
	}


	if (NTP_FLAGS_VN_DECODE(msg->flags) != NTP_FLAG_VN_VER4) {
		if (NTP_FLAGS_VN_DECODE(msg->flags) == NTP_FLAG_VN_VER3) {
			DBG("requested version %d, accepting version %d",
				NTP_FLAG_VN_VER4, NTP_FLAGS_VN_DECODE(msg->flags));
		} else {
			DBG("unsupported version %d", NTP_FLAGS_VN_DECODE(msg->flags));
			return;
		}
	}

	if (NTP_FLAGS_MD_DECODE(msg->flags) != NTP_FLAG_MD_SERVER) {
		DBG("unsupported mode %d", NTP_FLAGS_MD_DECODE(msg->flags));
		return;
	}

	m_delta = mrx_time->tv_sec - mtx_time.tv_sec +
		1.0e-9 * (mrx_time->tv_nsec - mtx_time.tv_nsec);

	org = tv->tv_sec + (1.0e-6 * tv->tv_usec) - m_delta + OFFSET_1900_1970;
	rec = ntohl(msg->rectime.seconds) +
			((double) ntohl(msg->rectime.fraction) / UINT_MAX);
	xmt = ntohl(msg->xmttime.seconds) +
			((double) ntohl(msg->xmttime.fraction) / UINT_MAX);
	dst = tv->tv_sec + (1.0e-6 * tv->tv_usec) + OFFSET_1900_1970;

	DBG("org=%f rec=%f xmt=%f dst=%f", org, rec, xmt, dst);

	offset = ((rec - org) + (xmt - dst)) / 2;
	delay = (dst - org) - (xmt - rec);

	DBG("offset=%f delay=%f", offset, delay);

	/* Remove the timeout, as timeserver has responded */

	reset_timeout();

	/*
	 * Now poll the server every transmit_delay seconds
	 * for time correction.
	 */
	if (poll_id > 0)
		g_source_remove(poll_id);

	DBG("Timeserver %s, next sync in %d seconds", timeserver, transmit_delay);

	poll_id = g_timeout_add_seconds(transmit_delay, next_poll, NULL);

	connman_info("ntp: time slew %+.6f s", offset);

	if (offset < STEPTIME_MIN_OFFSET && offset > -STEPTIME_MIN_OFFSET) {
		struct timeval adj;

		adj.tv_sec = (long) offset;
		adj.tv_usec = (offset - adj.tv_sec) * 1000000;

		DBG("adjusting time");

		if (adjtime(&adj, &adj) < 0) {
			connman_error("Failed to adjust time");
			return;
		}

		DBG("%lu seconds, %lu msecs", adj.tv_sec, adj.tv_usec);
	} else {
		struct timeval cur;
		double dtime;

		gettimeofday(&cur, NULL);
		dtime = offset + cur.tv_sec + 1.0e-6 * cur.tv_usec;
		cur.tv_sec = (long) dtime;
		cur.tv_usec = (dtime - cur.tv_sec) * 1000000;

		DBG("setting time");

		if (settimeofday(&cur, NULL) < 0) {
			connman_error("Failed to set time");
			return;
		}

		DBG("%lu seconds, %lu msecs", cur.tv_sec, cur.tv_usec);
	}
}
Example #27
0
static void state_change(struct supplicant_task *task, DBusMessage *msg)
{
	DBusError error;
	const char *newstate, *oldstate;
	unsigned char bssid[ETH_ALEN];
	unsigned int bssid_len;
	enum supplicant_state state, ostate;

	dbus_error_init(&error);

	if (dbus_message_get_args(msg, &error, DBUS_TYPE_STRING, &newstate,
						DBUS_TYPE_STRING, &oldstate,
						DBUS_TYPE_INVALID) == FALSE) {
		if (dbus_error_is_set(&error) == TRUE) {
			connman_error("%s", error.message);
			dbus_error_free(&error);
		} else
			connman_error("Wrong arguments for state change");
		return;
	}

	connman_info("%s state change %s -> %s%s", task->ifname,
			oldstate, newstate,
			task->scanning == TRUE ? " (scanning)" : "");

	state = string2state(newstate);
	if (state == WPA_INVALID)
		return;

	if (task->scanning == TRUE && state != WPA_SCANNING) {
		connman_device_set_scanning(task->device, FALSE);
		task->scanning = FALSE;
	}

	ostate = task->state;
	task->state = state;

	if (task->network == NULL)
		return;

	switch (task->state) {
	case WPA_COMPLETED:
		if (ostate != WPA_ASSOCIATED && ostate != WPA_GROUP_HANDSHAKE)
			goto badstate;

		/* reset bg scan reschedule */
		connman_device_reset_scan(task->device);

		if (get_bssid(task->device, bssid, &bssid_len) == 0)
			connman_network_set_address(task->network,
							bssid, bssid_len);

		/* carrier on */
		connman_network_set_connected(task->network, TRUE);
		break;

	case WPA_ASSOCIATING:
		if (ostate != WPA_SCANNING && ostate != WPA_COMPLETED)
			goto badstate;

		if (ostate == WPA_SCANNING)
			connman_network_set_associating(task->network, TRUE);
		break;

	case WPA_INACTIVE:
		if (ostate != WPA_SCANNING && ostate != WPA_DISCONNECTED)
			goto badstate;
		/* fall thru... */
	case WPA_DISCONNECTED:
		/* carrier off */
		connman_network_set_connected(task->network, FALSE);

		if (task->disconnecting == TRUE) {
			connman_network_unref(task->network);
			task->disconnecting = FALSE;

			if (task->pending_network != NULL) {
				task->network = task->pending_network;
				task->pending_network = NULL;
				task_connect(task);
			} else
				task->network = NULL;
		}
		break;

	default:
		connman_network_set_associating(task->network, FALSE);
		break;
	}
	return;
badstate:
	connman_error("%s invalid state change %s -> %s%s", task->ifname,
			oldstate, newstate,
			task->scanning == TRUE ? " (scanning)" : "");
}
Example #28
0
static void sig_term(int sig)
{
	connman_info("Terminating");

	g_main_loop_quit(main_loop);
}
Example #29
0
static int load_provider(GKeyFile *keyfile, const char *group,
				struct vpn_config *config, enum what action)
{
	struct vpn_config_provider *config_provider;
	const char *ident, *host, *domain;
	int err;

	/* Strip off "provider_" prefix */
	ident = group + 9;

	if (strlen(ident) < 1)
		return -EINVAL;

	config_provider = g_hash_table_lookup(config->provider_table, ident);
	if (config_provider != NULL)
		return -EALREADY;

	config_provider = g_try_new0(struct vpn_config_provider, 1);
	if (config_provider == NULL)
		return -ENOMEM;

	config_provider->ident = g_strdup(ident);

	config_provider->setting_strings = g_hash_table_new_full(g_str_hash,
						g_str_equal, g_free, g_free);

	add_keys(config_provider, keyfile, group);

	host = get_string(config_provider, "Host");
	domain = get_string(config_provider, "Domain");
	if (host != NULL && domain != NULL) {
		char *id = __vpn_provider_create_identifier(host, domain);

		struct vpn_provider *provider;
		provider = __vpn_provider_lookup(id);
		if (provider != NULL) {
			if (action == REMOVE) {
				__vpn_provider_delete(provider);
				err = 0;
			} else {
				connman_warn("Provider configuration %s "
						"already exist", id);
				err = -EALREADY;
			}

			g_free(id);
			goto err;
		}

		config_provider->provider_identifier = id;

		DBG("provider identifier %s", id);
	} else {
		DBG("invalid values host %s domain %s", host, domain);
		err = -EINVAL;
		goto err;
	}

	config_provider->config_ident = g_strdup(config->ident);
	config_provider->config_entry = g_strdup_printf("provider_%s",
						config_provider->ident);

	g_hash_table_insert(config->provider_table,
				config_provider->ident,	config_provider);

	err = __vpn_provider_create_from_config(
					config_provider->setting_strings,
					config_provider->config_ident,
					config_provider->config_entry);
	if (err != 0) {
		DBG("Cannot create provider from config file (%d/%s)",
			-err, strerror(-err));
		goto err;
	}

	connman_info("Added provider configuration %s",
						config_provider->ident);
	return 0;

err:
	g_free(config_provider->ident);
	g_free(config_provider->type);
	g_free(config_provider->name);
	g_free(config_provider->host);
	g_free(config_provider->domain);
	g_free(config_provider->networks);
	g_hash_table_destroy(config_provider->setting_strings);
	g_free(config_provider);

	return err;
}