Esempio n. 1
0
static int service_level_connection(struct ofono_modem *modem,
						int fd, guint16 version)
{
	struct hfp *hfp = ofono_modem_get_data(modem);
	struct hfp_slc_info *info = &hfp->info;
	GIOChannel *io;
	GAtSyntax *syntax;
	GAtChat *chat;

	io = g_io_channel_unix_new(fd);

	syntax = g_at_syntax_new_gsm_permissive();
	chat = g_at_chat_new(io, syntax);
	g_at_syntax_unref(syntax);

	g_io_channel_set_close_on_unref(io, TRUE);
	g_io_channel_unref(io);

	if (chat == NULL)
		return -ENOMEM;

	g_at_chat_set_disconnect_function(chat, hfp_disconnected_cb, modem);

	if (getenv("OFONO_AT_DEBUG"))
		g_at_chat_set_debug(chat, hfp_debug, "");

	hfp_slc_info_init(info, version);
	info->chat = chat;

	hfp_slc_establish(info, slc_established, slc_failed, modem);

	return -EINPROGRESS;
}
Esempio n. 2
0
/* either oFono or Phone could request SLC connection */
static int service_level_connection(struct ofono_modem *modem, int fd)
{
	struct hfp_data *data = ofono_modem_get_data(modem);
	GIOChannel *io;
	GAtSyntax *syntax;
	GAtChat *chat;

	io = g_io_channel_unix_new(fd);
	if (io == NULL) {
		ofono_error("Service level connection failed: %s (%d)",
			strerror(errno), errno);
		return -EIO;
	}

	syntax = g_at_syntax_new_gsm_permissive();
	chat = g_at_chat_new(io, syntax);
	g_at_syntax_unref(syntax);
	g_io_channel_unref(io);

	if (chat == NULL)
		return -ENOMEM;

	g_at_chat_set_disconnect_function(chat, hfp_disconnected_cb, modem);

	if (getenv("OFONO_AT_DEBUG"))
		g_at_chat_set_debug(chat, hfp_debug, "");

	data->info.chat = chat;
	hfp_slc_establish(&data->info, slc_established, slc_failed, modem);

	return -EINPROGRESS;
}
Esempio n. 3
0
static GAtChat *open_device(struct ofono_modem *modem,
				const char *key, char *debug)
{
	const char *device;
	GAtSyntax *syntax;
	GIOChannel *channel;
	GAtChat *chat;

	device = ofono_modem_get_string(modem, key);
	if (device == NULL)
		return NULL;

	DBG("%s %s", key, device);

	channel = g_at_tty_open(device, NULL);
	if (channel == NULL)
		return NULL;

	syntax = g_at_syntax_new_gsm_permissive();
	chat = g_at_chat_new(channel, syntax);
	g_at_syntax_unref(syntax);

	g_io_channel_unref(channel);

	if (chat == NULL)
		return NULL;

	if (getenv("OFONO_AT_DEBUG"))
		g_at_chat_set_debug(chat, sierra_debug, debug);

	return chat;
}
Esempio n. 4
0
static int cinterion_enable(struct ofono_modem *modem)
{
	GAtChat *chat;
	GIOChannel *channel;
	GAtSyntax *syntax;
	GHashTable *options;
	const char *device;

	DBG("%p", modem);

	options = g_hash_table_new(g_str_hash, g_str_equal);
	if (options == NULL)
		return -ENOMEM;

	device = ofono_modem_get_string(modem, "Device");
	if (device == NULL)
		return -EINVAL;

	g_hash_table_insert(options, "Baud", "115200");
	g_hash_table_insert(options, "StopBits", "1");
	g_hash_table_insert(options, "DataBits", "8");
	g_hash_table_insert(options, "Parity", "none");
	g_hash_table_insert(options, "XonXoff", "off");
	g_hash_table_insert(options, "RtsCts", "on");
	g_hash_table_insert(options, "Local", "on");
	g_hash_table_insert(options, "Read", "on");

	channel = g_at_tty_open(device, options);
	g_hash_table_destroy(options);

	if (channel == NULL)
		return -EIO;

	/*
         * (Cinterion plugin is based on tc65 plugin. Comment left in but may
         * not be applicable in the general case)
         *
         * TC65 works almost as the 27.007 says. But for example after
	 * AT+CRSM the modem replies with the data in the queried EF and
	 * writes three pairs of <CR><LF> after the data and before OK.
	 */
	syntax = g_at_syntax_new_gsm_permissive();

	chat = g_at_chat_new(channel, syntax);
	g_at_syntax_unref(syntax);
	g_io_channel_unref(channel);

	if (chat == NULL)
		return -ENOMEM;

	if (getenv("OFONO_AT_DEBUG"))
		g_at_chat_set_debug(chat, cinterion_debug, "");

	ofono_modem_set_data(modem, chat);

	return 0;
}
Esempio n. 5
0
static int open_serial(void)
{
	GAtSyntax *syntax;
	GIOChannel *channel;

	channel = g_at_tty_open(option_control, NULL);
	if (channel == NULL)
		return -EIO;

	syntax = g_at_syntax_new_gsm_permissive();
	control = g_at_chat_new(channel, syntax);
	g_io_channel_unref(channel);
	g_at_syntax_unref(syntax);

	if (control == NULL)
		return -EIO;

	if (option_modem == NULL) {
		g_at_chat_ref(control);
		modem = control;
		g_at_chat_set_debug(control, gsmdial_debug, "");
	} else {
		g_at_chat_set_debug(control, gsmdial_debug, "Control");

		channel = g_at_tty_open(option_modem, NULL);
		if (channel == NULL)
			return -EIO;

		syntax = g_at_syntax_new_gsm_permissive();
		modem = g_at_chat_new(channel, syntax);
		g_io_channel_unref(channel);
		g_at_syntax_unref(syntax);

		if (modem == NULL)
			return -EIO;

		g_at_chat_set_debug(modem, gsmdial_debug, "Modem");
	}

	return 0;
}
Esempio n. 6
0
static void mux_setup(GAtMux *mux, gpointer user_data)
{
	struct ofono_modem *modem = user_data;
	struct phonesim_data *data = ofono_modem_get_data(modem);
	GIOChannel *io;
	GAtSyntax *syntax;

	DBG("%p", mux);

	if (mux == NULL) {
		ofono_modem_set_powered(modem, FALSE);
		return;
	}

	data->mux = mux;

	if (getenv("OFONO_AT_DEBUG"))
		g_at_mux_set_debug(data->mux, phonesim_debug, "");

	g_at_mux_start(mux);
	io = g_at_mux_create_channel(mux);

	if (data->calypso)
		syntax = g_at_syntax_new_gsm_permissive();
	else
		syntax = g_at_syntax_new_gsmv1();

	data->chat = g_at_chat_new(io, syntax);
	g_at_syntax_unref(syntax);
	g_io_channel_unref(io);

	if (getenv("OFONO_AT_DEBUG"))
		g_at_chat_set_debug(data->chat, phonesim_debug, "");

	if (data->calypso)
		g_at_chat_set_wakeup_command(data->chat, "AT\r", 500, 5000);

	g_at_chat_send(data->chat, "ATE0", NULL, NULL, NULL, NULL);

	g_at_chat_send(data->chat, "AT+CFUN=1", none_prefix,
					cfun_set_on_cb, modem, NULL);
}
Esempio n. 7
0
static GAtChat *open_device(struct ofono_modem *modem,
				const char *key, char *debug)
{
	const char *device;
	GAtSyntax *syntax;
	GIOChannel *channel;
	GAtChat *chat;
	GHashTable *options;

	device = ofono_modem_get_string(modem, key);
	if (device == NULL)
		return NULL;

	DBG("%s %s", key, device);

	options = g_hash_table_new(g_str_hash, g_str_equal);
	if (options == NULL)
		return NULL;

	g_hash_table_insert(options, "Baud", "115200");
	channel = g_at_tty_open(device, options);
	g_hash_table_destroy(options);

	if (channel == NULL)
		return NULL;

	syntax = g_at_syntax_new_gsm_permissive();
	chat = g_at_chat_new(channel, syntax);
	g_at_syntax_unref(syntax);
	g_io_channel_unref(channel);

	if (chat == NULL)
		return NULL;

	if (getenv("OFONO_AT_DEBUG"))
		g_at_chat_set_debug(chat, he910_debug, debug);

	return chat;
}
Esempio n. 8
0
static void test_connect(gboolean use_socket)
{
	GIOChannel *io;
	GAtChat *chat;
	GAtSyntax *syntax;
	int fd;

	if (use_socket == TRUE)
		fd = do_connect();
	else
		fd = do_open();

	if (fd < 0)
		return;

	io = g_io_channel_unix_new(fd);
	g_io_channel_set_close_on_unref(io, TRUE);

	syntax = g_at_syntax_new_gsm_permissive();
	chat = g_at_chat_new_blocking(io, syntax);
	g_at_syntax_unref(syntax);

	g_io_channel_unref(io);

	if (chat == NULL) {
		g_printerr("Chat creation failed\n");
		return;
	}

	g_at_chat_set_debug(chat, caif_debug, NULL);
	g_at_chat_send(chat, "ATE0 +CMEE=1", NULL, caif_init, chat, NULL);

	mainloop = g_main_loop_new(NULL, FALSE);

	g_main_loop_run(mainloop);
	g_main_loop_unref(mainloop);
}
Esempio n. 9
0
static int device_dial_setup(struct dundee_device *device, int fd)
{
    GAtSyntax *syntax;
    GIOChannel *io;

    io = g_io_channel_unix_new(fd);
    if (io == NULL)
        return -EIO;

    syntax = g_at_syntax_new_gsm_permissive();
    device->chat = g_at_chat_new(io, syntax);
    g_io_channel_unref(io);
    g_at_syntax_unref(syntax);

    if (device->chat == NULL)
        return -EIO;

    g_at_chat_set_debug(device->chat, debug, "Control");

    g_at_chat_send(device->chat, "ATD*99#", none_prefix, dial_cb,
                   device, NULL);

    return 0;
}
Esempio n. 10
0
File: atgen.c Progetto: yongsu/oFono
static int atgen_enable(struct ofono_modem *modem)
{
    GAtChat *chat;
    GIOChannel *channel;
    GAtSyntax *syntax;
    const char *device;
    const char *value;
    GHashTable *options;
    int i;

    DBG("%p", modem);

    device = ofono_modem_get_string(modem, "Device");
    if (!device)
        return -EINVAL;

    options = g_hash_table_new_full(g_str_hash, g_str_equal,
                                    g_free, g_free);
    if (!options)
        return -ENOMEM;

    for (i = 0; tty_opts[i]; i++) {
        value = ofono_modem_get_string(modem, tty_opts[i]);

        if (value == NULL)
            continue;

        g_hash_table_insert(options, g_strdup(tty_opts[i]),
                            g_strdup(value));
    }

    channel = g_at_tty_open(device, options);

    g_hash_table_destroy(options);

    if (!channel) {
        return -EIO;
    }

    value = ofono_modem_get_string(modem, "GsmSyntax");
    if (value) {
        if (g_str_equal(value, "V1"))
            syntax = g_at_syntax_new_gsmv1();
        else if (g_str_equal(value, "Permissive"))
            syntax = g_at_syntax_new_gsm_permissive();
        else
            return -EINVAL;
    } else {
        syntax = g_at_syntax_new_gsmv1();
    }

    chat = g_at_chat_new(channel, syntax);
    g_at_syntax_unref(syntax);
    g_io_channel_unref(channel);

    if (!chat)
        return -ENOMEM;

    if (getenv("OFONO_AT_DEBUG"))
        g_at_chat_set_debug(chat, atgen_debug, NULL);

    ofono_modem_set_data(modem, chat);

    return 0;
}
Esempio n. 11
0
static int phonesim_enable(struct ofono_modem *modem)
{
	struct phonesim_data *data = ofono_modem_get_data(modem);
	GIOChannel *io;
	GAtSyntax *syntax;
	const char *address, *value;
	int sk, port;

	DBG("%p", modem);

	address = ofono_modem_get_string(modem, "Address");
	if (address == NULL)
		return -EINVAL;

	port = ofono_modem_get_integer(modem, "Port");
	if (port < 0)
		return -EINVAL;

	value = ofono_modem_get_string(modem, "Modem");
	if (!g_strcmp0(value, "calypso"))
		data->calypso = TRUE;

	value = ofono_modem_get_string(modem, "Multiplexer");
	if (!g_strcmp0(value, "internal"))
		data->use_mux = TRUE;

	sk = connect_socket(address, port);
	if (sk < 0)
		return sk;

	io = g_io_channel_unix_new(sk);
	if (io == NULL) {
		close(sk);
		return -ENOMEM;
	}

	if (data->calypso)
		syntax = g_at_syntax_new_gsm_permissive();
	else
		syntax = g_at_syntax_new_gsmv1();

	data->chat = g_at_chat_new(io, syntax);

	g_at_syntax_unref(syntax);
	g_io_channel_unref(io);

	if (data->chat == NULL)
		return -ENOMEM;

	if (getenv("OFONO_AT_DEBUG"))
		g_at_chat_set_debug(data->chat, phonesim_debug, "");

	g_at_chat_set_disconnect_function(data->chat,
						phonesim_disconnected, modem);

	if (data->calypso) {
		g_at_chat_set_wakeup_command(data->chat, "AT\r", 500, 5000);

		g_at_chat_send(data->chat, "ATE0", NULL, NULL, NULL, NULL);

		g_at_chat_send(data->chat, "AT%CUNS=0",
				NULL, NULL, NULL, NULL);
	}

	if (data->use_mux) {
		g_at_chat_send(data->chat, "ATE0", NULL, NULL, NULL, NULL);

		g_at_mux_setup_gsm0710(data->chat, mux_setup, modem, NULL);

		g_at_chat_unref(data->chat);
		data->chat = NULL;

		return -EINPROGRESS;
	}

	g_at_chat_send(data->chat, "AT+CSCS=\"GSM\"", none_prefix,
			NULL, NULL, NULL);

	g_at_chat_register(data->chat, "+CRST:",
				crst_notify, FALSE, modem, NULL);

	g_at_chat_register(data->chat, "+CBC:",
				cbc_notify, FALSE, modem, NULL);

	g_at_chat_send(data->chat, "AT+CBC", none_prefix, NULL, NULL, NULL);

	data->hfp_watch = __ofono_modem_add_atom_watch(modem,
					OFONO_ATOM_TYPE_EMULATOR_HFP,
					emulator_hfp_watch, data, NULL);

	return 0;
}