Example #1
0
File: sap.c Project: AndriusA/ofono
static int bluetooth_sap_probe(const char *device, const char *dev_addr,
				const char *adapter_addr, const char *alias)
{
	struct ofono_modem *modem;
	char buf[256];

	if (sap_hw_modem == NULL)
		return -ENODEV;

	/* 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, "sap/");
	bluetooth_create_path(dev_addr, adapter_addr, buf + 4,
						sizeof(buf) - 4);

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

	ofono_modem_set_string(modem, "ServerPath", device);
	ofono_modem_set_name(modem, alias);
	ofono_modem_register(modem);

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

	return 0;
}
Example #2
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;
}
Example #3
0
static void parse_config(void)
{
	GKeyFile *keyfile;
	GError *err = NULL;
	char **modems;
	int i;
	const char *filename;

	char *conf_override = getenv("OFONO_PHONESIM_CONFIG");
	if (conf_override)
		filename = conf_override;
	else
		filename = CONFIGDIR "/phonesim.conf";

	DBG("filename %s", filename);

	keyfile = g_key_file_new();

	g_key_file_set_list_separator(keyfile, ',');

	if (!g_key_file_load_from_file(keyfile, filename, 0, &err)) {
		ofono_warn("Reading of %s failed: %s", filename, err->message);
		g_error_free(err);
		goto done;
	}

	modems = g_key_file_get_groups(keyfile, NULL);

	for (i = 0; modems[i]; i++) {
		struct ofono_modem *modem;

		modem = create_modem(keyfile, modems[i]);
		if (modem == NULL)
			continue;

		modem_list = g_slist_prepend(modem_list, modem);

		ofono_modem_register(modem);
	}

	g_strfreev(modems);

done:
	g_key_file_free(keyfile);
}
Example #4
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);
}
Example #5
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);
}
Example #6
0
static struct ofono_modem *modem_register(const char *device,
				const char *device_address, const char *alias)
{
	struct ofono_modem *modem;
	char *path;

	path = g_strconcat("hfp", device, NULL);

	modem = ofono_modem_create(path, "hfp");

	g_free(path);

	if (modem == NULL)
		return NULL;

	ofono_modem_set_string(modem, "Remote", device_address);
	ofono_modem_set_string(modem, "DevicePath", device);

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

	return modem;
}
Example #7
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;
	}
}