Exemplo n.º 1
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_gsmv1();
	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, telit_debug, debug);

	return chat;
}
Exemplo n.º 2
0
Arquivo: ifx.c Projeto: AndriusA/ofono
static int ifx_enable(struct ofono_modem *modem)
{
	struct ifx_data *data = ofono_modem_get_data(modem);
	const char *device, *ldisc;
	GAtSyntax *syntax;
	GAtChat *chat;

	DBG("%p", modem);

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

	DBG("%s", device);

	ldisc = ofono_modem_get_string(modem, "LineDiscipline");
	if (ldisc != NULL) {
		data->mux_ldisc = atoi(ldisc);
		ofono_info("Using multiplexer line discipline %d",
							data->mux_ldisc);
	}

	data->device = g_at_tty_open(device, NULL);
	if (data->device == NULL)
		return -EIO;

	syntax = g_at_syntax_new_gsmv1();
	chat = g_at_chat_new(data->device, syntax);
	g_at_syntax_unref(syntax);

	if (chat == NULL) {
		g_io_channel_unref(data->device);
		return -EIO;
	}

	if (getenv("OFONO_AT_DEBUG"))
		g_at_chat_set_debug(chat, ifx_debug, "Master: ");

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

	/* Enable multiplexer */
	data->frame_size = 1509;

	g_at_chat_send(chat, "AT+CMUX=0,0,,1509,10,3,30,,", NULL,
					mux_setup_cb, modem, NULL);

	data->mux_init_timeout = g_timeout_add_seconds(5, mux_timeout_cb,
								modem);

	data->dlcs[AUX_DLC] = chat;

	return -EINPROGRESS;
}
Exemplo n.º 3
0
static int localhfp_enable(struct ofono_modem *modem)
{
	struct hfp_slc_info *info = ofono_modem_get_data(modem);
	GIOChannel *io;
	GAtSyntax *syntax;
	GAtChat *chat;
	const char *address;
	int sk, port;

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

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

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

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

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

	if (chat == NULL)
		return -ENOMEM;

	if (getenv("OFONO_AT_DEBUG"))
		g_at_chat_set_debug(chat, phonesim_debug, "LocalHfp: ");

	g_at_chat_set_disconnect_function(chat, slc_failed, modem);

	hfp_slc_info_init(info, HFP_VERSION_LATEST);
	info->chat = chat;
	hfp_slc_establish(info, slc_established, slc_failed, modem);

	return -EINPROGRESS;
}
Exemplo n.º 4
0
static int open_ip(void)
{
	int sk, err;
	struct sockaddr_in addr;
	GAtSyntax *syntax;
	GIOChannel *channel;

	sk = socket(PF_INET, SOCK_STREAM, 0);
	if (sk < 0)
		return -EINVAL;

	memset(&addr, 0, sizeof(addr));
	addr.sin_family = AF_INET;
	addr.sin_addr.s_addr = inet_addr(option_ip);
	addr.sin_port = htons(option_port);

	err = connect(sk, (struct sockaddr *) &addr, sizeof(addr));
	if (err < 0) {
		close(sk);
		return err;
	}

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

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

	if (control == NULL)
		return -ENOMEM;

	g_at_chat_ref(control);
	modem = control;
	g_at_chat_set_debug(control, gsmdial_debug, "");

	return 0;
}
Exemplo n.º 5
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);
}
Exemplo n.º 6
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_gsmv1();
	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, telit_debug, debug);

	return chat;
}
Exemplo n.º 7
0
Arquivo: ifx.c Projeto: AndriusA/ofono
static GAtChat *create_chat(GIOChannel *channel, struct ofono_modem *modem,
								char *debug)
{
	GAtSyntax *syntax;
	GAtChat *chat;

	if (channel == NULL)
		return NULL;

	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 == NULL)
		return NULL;

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

	g_at_chat_set_disconnect_function(chat, dlc_disconnect, modem);

	return chat;
}
Exemplo n.º 8
0
Arquivo: atgen.c Projeto: 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;
}
Exemplo n.º 9
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;
}