Ejemplo n.º 1
0
static void destroy_modem(gpointer data)
{
	struct modem_info *modem = data;
	GSList *list;

	DBG("%s", modem->syspath);

	ofono_modem_remove(modem->modem);

	switch (modem->type) {
	case MODEM_TYPE_USB:
		for (list = modem->devices; list; list = list->next) {
			struct device_info *info = list->data;

			DBG("%s", info->devnode);
			device_info_free(info);
		}

		g_slist_free(modem->devices);
		break;
	case MODEM_TYPE_SERIAL:
		serial_device_info_free(modem->serial);
		break;
	}

	g_free(modem->syspath);
	g_free(modem->devname);
	g_free(modem->driver);
	g_free(modem->vendor);
	g_free(modem->model);
	g_free(modem);
}
Ejemplo n.º 2
0
static void destroy_modem(gpointer data)
{
	struct modem_info *modem = data;
	GSList *list;

	DBG("%s", modem->syspath);

	ofono_modem_remove(modem->modem);

	for (list = modem->devices; list; list = list->next) {
		struct device_info *info = list->data;

		DBG("%s", info->devnode);

		g_free(info->devpath);
		g_free(info->devnode);
		g_free(info->interface);
		g_free(info->number);
		g_free(info->label);
		g_free(info->sysattr);
		g_free(info);

		list->data = NULL;
	}

	g_slist_free(modem->devices);

	g_free(modem->syspath);
	g_free(modem->devname);
	g_free(modem->driver);
	g_free(modem->vendor);
	g_free(modem->model);
	g_free(modem);
}
Ejemplo n.º 3
0
static struct ofono_modem *create_modem(GKeyFile *keyfile, const char *group)
{
	const char *driver = "phonesim";
	struct ofono_modem *modem;
	char *value;

	DBG("group %s", group);

	value = g_key_file_get_string(keyfile, group, "Modem", NULL);

	if (value && g_str_equal(value, "hfp"))
		driver = "localhfp";

	g_free(value);

	modem = ofono_modem_create(group, driver);
	if (modem == NULL)
		return NULL;

	value = g_key_file_get_string(keyfile, group, "Address", NULL);
	if (value == NULL)
		goto error;

	ofono_modem_set_string(modem, "Address", value);
	g_free(value);

	value = g_key_file_get_string(keyfile, group, "Port", NULL);
	if (value == NULL)
		goto error;

	ofono_modem_set_integer(modem, "Port", atoi(value));
	g_free(value);

	value = g_key_file_get_string(keyfile, group, "Modem", NULL);
	if (value) {
		ofono_modem_set_string(modem, "Modem", value);
		g_free(value);
	}

	value = g_key_file_get_string(keyfile, group, "Multiplexer", NULL);
	if (value) {
		ofono_modem_set_string(modem, "Multiplexer", value);
		g_free(value);
	}

	DBG("%p", modem);

	return modem;

error:
	ofono_error("Missing address or port setting for %s", group);

	ofono_modem_remove(modem);

	return NULL;
}
Ejemplo n.º 4
0
static void release_modems(void)
{
	GSList *list;

	for (list = modem_list; list; list = list->next) {
		struct ofono_modem *modem = list->data;

		ofono_modem_remove(modem);
	}

	g_slist_free(modem_list);
	modem_list = NULL;
}
Ejemplo n.º 5
0
static int hfp_hf_probe(const char *device, const char *dev_addr,
				const char *adapter_addr, const char *alias)
{
	struct ofono_modem *modem;
	struct hfp_data *data;
	char buf[256];

	/* We already have this device in our hash, ignore */
	if (g_hash_table_lookup(modem_hash, device) != NULL)
		return -EALREADY;

	ofono_info("Using device: %s, devaddr: %s, adapter: %s",
			device, dev_addr, adapter_addr);

	strcpy(buf, "hfp/");
	bluetooth_create_path(dev_addr, adapter_addr, buf + 4, sizeof(buf) - 4);

	modem = ofono_modem_create(buf, "hfp");
	if (modem == NULL)
		return -ENOMEM;

	data = g_try_new0(struct hfp_data, 1);
	if (data == NULL)
		goto free;

	data->handsfree_path = g_strdup(device);
	if (data->handsfree_path == NULL)
		goto free;

	data->handsfree_address = g_strdup(dev_addr);
	if (data->handsfree_address == NULL)
		goto free;

	ofono_modem_set_data(modem, data);
	ofono_modem_set_name(modem, alias);
	ofono_modem_register(modem);

	g_hash_table_insert(modem_hash, g_strdup(device), modem);

	return 0;

free:
	if (data != NULL)
		g_free(data->handsfree_path);

	g_free(data);
	ofono_modem_remove(modem);

	return -ENOMEM;
}
Ejemplo n.º 6
0
static gboolean hfp_remove_modem(gpointer key, gpointer value,
					gpointer user_data)
{
	struct ofono_modem *modem = value;
	const char *device = key;
	const char *prefix = user_data;

	if (prefix && g_str_has_prefix(device, prefix) == FALSE)
		return FALSE;

	ofono_modem_remove(modem);

	return TRUE;
}
Ejemplo n.º 7
0
static DBusMessage *hfp_agent_release(DBusConnection *conn,
					DBusMessage *msg, void *data)
{
	struct ofono_modem *modem = data;
	struct hfp_data *hfp_data = ofono_modem_get_data(modem);
	const char *obj_path = ofono_modem_get_path(modem);

	g_dbus_unregister_interface(connection, obj_path, HFP_AGENT_INTERFACE);
	hfp_data->agent_registered = FALSE;

	g_hash_table_remove(modem_hash, hfp_data->handsfree_path);
	ofono_modem_remove(modem);

	return dbus_message_new_method_return(msg);
}
Ejemplo n.º 8
0
static DBusMessage *control_add(DBusConnection *conn,
					DBusMessage *msg, void *data)
{
	const char *driver = "phonesim";
	struct ofono_modem *modem;
	DBusMessageIter iter;
	char *name;
	char *address;
	char *port;

	if (!dbus_message_iter_init(msg, &iter))
		return __ofono_error_invalid_args(msg);

	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
		return __ofono_error_invalid_args(msg);

	dbus_message_iter_get_basic(&iter, &name);
	dbus_message_iter_next(&iter);

	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
		return __ofono_error_invalid_args(msg);

	dbus_message_iter_get_basic(&iter, &address);
	dbus_message_iter_next(&iter);

	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
		return __ofono_error_invalid_args(msg);

	dbus_message_iter_get_basic(&iter, &port);

	modem = ofono_modem_create(name, driver);
	if (modem == NULL)
		return NULL;

	ofono_modem_set_string(modem, "Address", address);
	ofono_modem_set_integer(modem, "Port", atoi(port));
	if (ofono_modem_register(modem) != 0) {
		ofono_modem_remove(modem);
		return __ofono_error_invalid_args(msg);
	}
	modem_list = g_slist_prepend(modem_list, modem);

	return dbus_message_new_method_return(msg);
}
Ejemplo n.º 9
0
static void modem_register_from_proxy(GDBusProxy *proxy, const char *path)
{
	const char *alias, *remote;
	DBusMessageIter iter;
	dbus_bool_t paired;
	struct ofono_modem *modem;

	if (g_dbus_proxy_get_property(proxy, "Paired", &iter) == FALSE)
		return;

	dbus_message_iter_get_basic(&iter, &paired);

	if (paired == FALSE) {
		modem = ofono_modem_find(device_path_compare, (void *) path);

		if (modem != NULL) {
			ofono_modem_remove(modem);
			g_dbus_proxy_set_removed_watch(proxy, NULL, NULL);
			g_dbus_proxy_set_property_watch(proxy, NULL, NULL);
		}
		return;
	}

	if (g_dbus_proxy_get_property(proxy, "UUIDs", &iter) == FALSE)
		return;

	if (has_hfp_ag_uuid(&iter) == FALSE)
		return;

	if (g_dbus_proxy_get_property(proxy, "Alias", &iter) == FALSE)
		return;

	dbus_message_iter_get_basic(&iter, &alias);

	if (g_dbus_proxy_get_property(proxy, "Address", &iter) == FALSE)
		return;

	dbus_message_iter_get_basic(&iter, &remote);

	modem = modem_register(path, remote, alias);
	g_dbus_proxy_set_property_watch(proxy, alias_changed, modem);
	g_dbus_proxy_set_removed_watch(proxy, modem_removed, modem);
}
Ejemplo n.º 10
0
Archivo: sap.c Proyecto: AndriusA/ofono
void bluetooth_sap_client_unregister(struct ofono_modem *modem)
{
	GHashTableIter iter;
	gpointer key, value;

	if (sap_hw_modem == NULL)
		return;

	g_hash_table_iter_init(&iter, modem_hash);

	while (g_hash_table_iter_next(&iter, &key, &value)) {
		g_hash_table_iter_remove(&iter);

		ofono_modem_remove(value);
	}

	sap_hw_modem = NULL;
	sap_hw_driver = NULL;
}
Ejemplo n.º 11
0
/*
 * Add or remove isimodems
 * when usbpn* phonet interfaces are added/removed
 */
static void usbpn_status_cb(GIsiModem *idx,
				GPhonetLinkState st,
				char const ifname[],
				void *data)
{
	struct ofono_modem *modem;
	int error;

	DBG("Phonet link %s (%u) is %s",
		ifname, g_isi_modem_index(idx),
		st == PN_LINK_REMOVED ? "removed" :
		st == PN_LINK_DOWN ? "down" : "up");

	/* Expect phonet interface name usbpn<idx> */
	if (strncmp(ifname, "usbpn", 5) ||
		ifname[5 + strspn(ifname + 5, "0123456789")])
		return;

	if (st == PN_LINK_REMOVED)
		return;

	if (g_pn_netlink_by_modem(idx)) {
		DBG("Modem for interface %s already exists", ifname);
		return;
	}

	error = g_pn_netlink_set_address(idx, PN_DEV_PC);
	if (error && error != -EEXIST) {
		DBG("g_pn_netlink_set_address: %s\n", strerror(-error));
		return;
	}

	modem = ofono_modem_create(NULL, "isimodem");
	if (!modem)
		return;

	ofono_modem_set_string(modem, "Interface", ifname);

	if (ofono_modem_register(modem) == 0)
		DBG("Done regging modem %s", ofono_modem_get_path(modem));
	else
		ofono_modem_remove(modem);
}
Ejemplo n.º 12
0
Archivo: sap.c Proyecto: AndriusA/ofono
static void bluetooth_sap_remove(const char *prefix)
{
	GHashTableIter iter;
	gpointer key, value;

	DBG("%s", prefix);

	if (modem_hash == NULL)
		return;

	g_hash_table_iter_init(&iter, modem_hash);

	while (g_hash_table_iter_next(&iter, &key, &value)) {
		if (prefix && g_str_has_prefix((char *)key, prefix) == FALSE)
			continue;

		g_hash_table_iter_remove(&iter);

		ofono_modem_remove(value);
	}
}
Ejemplo n.º 13
0
static void modem_removed(GDBusProxy *proxy, void *user_data)
{
	struct ofono_modem *modem = user_data;

	ofono_modem_remove(modem);
}
Ejemplo n.º 14
0
static void state_change(struct ste_modem *stemodem, enum ste_operation op)
{
	switch (stemodem->state) {
	case STE_STATE_OFF:
		/*
		 * The STE Modem is in state OFF and we're waiting for
		 * the Modem Init Daemon to signal that modem is ready
		 * in order to create and register the modem.
		 */
		switch (op) {
		case STE_OP_READY:
			stemodem->modem = ofono_modem_create(stemodem->serial,
								"ste");
			if (stemodem->modem == NULL) {
				ofono_error("Could not create modem %s, %s",
						stemodem->path,
						stemodem->serial);
				return;
			}

			DBG("register modem %s, %s", stemodem->path,
				stemodem->serial);

			if (stemodem->interface != NULL)
				ofono_modem_set_string(stemodem->modem,
							"Interface",
							stemodem->interface);

			ofono_modem_register(stemodem->modem);
			stemodem->state = STE_STATE_READY;
			break;
		case STE_OP_STARTING:
		case STE_OP_RESTART:
		case STE_OP_OFF:
			break;
		}
		break;
	case STE_STATE_READY:
		/*
		 * The STE Modem is ready and the modem has been created
		 * and registered in oFono. In this state two things can
		 * happen: Modem restarts or is turned off. Turning off
		 * the modem is an exceptional situation e.g. high-temperature,
		 * low battery or upgrade. In this scenario we remove the
		 * STE modem from oFono.
		 */
		switch (op) {
		case STE_OP_READY:
			break;
		case STE_OP_STARTING:
		case STE_OP_RESTART:
			DBG("reset ongoing %s", stemodem->path);
			/* Note: Consider to power off modem here? */
			stemodem->state = STE_STATE_RESET;
			break;
		case STE_OP_OFF:
			DBG("STE modem unregistering %s", stemodem->path);
			ofono_modem_remove(stemodem->modem);
			stemodem->modem = NULL;
			stemodem->state = STE_STATE_OFF;
			break;
		}
		break;
	case STE_STATE_RESET:
		/*
		 * The STE Modem is resetting.In this state two things can
		 * happen: Modem restarts succeeds, or modem is turned off.
		 */
		switch (op) {
		case STE_OP_STARTING:
		case STE_OP_RESTART:
			break;
		case STE_OP_READY:
			DBG("STE modem reset complete %s", stemodem->path);
			if (ofono_modem_get_powered(stemodem->modem))
				ofono_modem_reset(stemodem->modem);
			stemodem->state = STE_STATE_READY;
			break;
		case STE_OP_OFF:
			DBG("STE modem unregistering %s", stemodem->path);
			ofono_modem_remove(stemodem->modem);
			stemodem->modem = NULL;
			stemodem->state = STE_STATE_OFF;
			break;
		}
		break;
	}
}