Пример #1
0
static int telit_sap_enable(struct ofono_modem *modem,
					struct ofono_modem *sap_modem,
					int bt_fd)
{
	struct telit_data *data = ofono_modem_get_data(modem);
	int fd;

	DBG("%p", modem);

	fd = telit_sap_open();
	if (fd < 0)
		goto error;

	data->hw_io = g_io_channel_unix_new(fd);
	if (data->hw_io == NULL) {
		close(fd);
		goto error;
	}

	g_io_channel_set_encoding(data->hw_io, NULL, NULL);
	g_io_channel_set_buffered(data->hw_io, FALSE);
	g_io_channel_set_close_on_unref(data->hw_io, TRUE);

	data->bt_io = g_io_channel_unix_new(bt_fd);
	if (data->bt_io == NULL)
		goto error;

	g_io_channel_set_encoding(data->bt_io, NULL, NULL);
	g_io_channel_set_buffered(data->bt_io, FALSE);
	g_io_channel_set_close_on_unref(data->bt_io, TRUE);

	data->hw_watch = g_io_add_watch_full(data->hw_io, G_PRIORITY_DEFAULT,
				G_IO_HUP | G_IO_ERR | G_IO_NVAL | G_IO_IN,
				hw_event_cb, modem, hw_watch_remove);

	data->bt_watch = g_io_add_watch_full(data->bt_io, G_PRIORITY_DEFAULT,
				G_IO_HUP | G_IO_ERR | G_IO_NVAL | G_IO_IN,
				bt_event_cb, modem, bt_watch_remove);

	data->sap_modem = sap_modem;

	g_at_chat_register(data->chat, "#RSEN:", telit_rsen_notify,
				FALSE, modem, NULL);

	g_at_chat_send(data->chat, "AT#NOPT=0", NULL, NULL, NULL, NULL);

	/* Set SAP functionality */
	g_at_chat_send(data->chat, "AT#RSEN=1,1,0,2,0", rsen_prefix,
				rsen_enable_cb, modem, NULL);

	return -EINPROGRESS;

error:
	shutdown(bt_fd, SHUT_RDWR);
	close(bt_fd);

	sap_close_io(modem);
	return -EINVAL;
}
Пример #2
0
static void rsen_disable_cb(gboolean ok, GAtResult *result, gpointer user_data)
{
	struct ofono_modem *modem = user_data;

	DBG("%p", modem);

	sap_close_io(modem);

	telit_disable(modem);
}
Пример #3
0
static void rsen_enable_cb(gboolean ok, GAtResult *result, gpointer user_data)
{
	struct ofono_modem *modem = user_data;
	struct telit_data *data = ofono_modem_get_data(modem);

	DBG("%p", modem);

	if (!ok) {
		ofono_modem_set_powered(data->sap_modem, FALSE);
		sap_close_io(modem);
		return;
	}
}
Пример #4
0
static void cfun_enable_cb(gboolean ok, GAtResult *result, gpointer user_data)
{
	struct ofono_modem *modem = user_data;
	struct telit_data *data = ofono_modem_get_data(modem);
	struct ofono_modem *m = data->sap_modem ? : modem;

	DBG("%p", modem);

	if (!ok) {
		g_at_chat_unref(data->chat);
		data->chat = NULL;
		ofono_modem_set_powered(m, FALSE);
		sap_close_io(modem);
		return;
	}

	/*
	 * Switch data carrier detect signal off.
	 * When the DCD is disabled the modem does not hangup anymore
	 * after the data connection.
	 */
	g_at_chat_send(data->chat, "AT&C0", NULL, NULL, NULL, NULL);

	data->have_sim = FALSE;
	data->sms_phonebook_added = FALSE;

	ofono_modem_set_powered(m, TRUE);

	/*
	 * Tell the modem not to automatically initiate auto-attach
	 * proceedures on its own.
	 */
	g_at_chat_send(data->chat, "AT#AUTOATT=0", none_prefix,
				NULL, NULL, NULL);

	/* Follow sim state */
	g_at_chat_register(data->chat, "#QSS:", telit_qss_notify,
				FALSE, modem, NULL);

	/* Enable sim state notification */
	g_at_chat_send(data->chat, "AT#QSS=2", none_prefix, NULL, NULL, NULL);
}
Пример #5
0
static void telit_rsen_notify(GAtResult *result, gpointer user_data)
{
	struct ofono_modem *modem = user_data;
	struct telit_data *data = ofono_modem_get_data(modem);
	int status;
	GAtResultIter iter;

	DBG("%p", modem);

	g_at_result_iter_init(&iter, result);

	if (!g_at_result_iter_next(&iter, "#RSEN:"))
		return;

	g_at_result_iter_next_number(&iter, &status);

	if (status == 0) {
		ofono_modem_set_powered(data->sap_modem, FALSE);
		sap_close_io(modem);
		return;
	}

	telit_enable(modem);
}
Пример #6
0
static int telit_sap_enable(struct ofono_modem *modem,
					struct ofono_modem *sap_modem,
					int bt_fd)
{
	struct telit_data *data = ofono_modem_get_data(modem);
	int fd;

	DBG("%p", modem);

	fd = telit_sap_open();
	if (fd < 0)
		goto error;

	data->hw_io = g_io_channel_unix_new(fd);
	if (data->hw_io == NULL) {
		close(fd);
		goto error;
	}

	g_io_channel_set_encoding(data->hw_io, NULL, NULL);
	g_io_channel_set_buffered(data->hw_io, FALSE);
	g_io_channel_set_close_on_unref(data->hw_io, TRUE);

	data->bt_io = g_io_channel_unix_new(bt_fd);
	if (data->bt_io == NULL)
		goto error;

	g_io_channel_set_encoding(data->bt_io, NULL, NULL);
	g_io_channel_set_buffered(data->bt_io, FALSE);
	g_io_channel_set_close_on_unref(data->bt_io, TRUE);

	// DBUS connection to smart card reader daemon
	connection = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL);
	dbProxy = g_dbus_proxy_new_sync(connection, G_DBUS_PROXY_FLAGS_NONE, NULL, "org.smart_e.RSAP","/RSAPServer","org.smart_e.RSAPServer", NULL, NULL);	

	data->hw_watch = g_io_add_watch_full(data->hw_io, G_PRIORITY_DEFAULT,
				G_IO_HUP | G_IO_ERR | G_IO_NVAL | G_IO_IN,
				hw_event_cb, modem, hw_watch_remove);

	data->bt_watch = g_io_add_watch_full(data->bt_io, G_PRIORITY_DEFAULT,
				G_IO_HUP | G_IO_ERR | G_IO_NVAL | G_IO_IN,
				bt_event_cb, modem, bt_watch_remove);

	data->sap_modem = sap_modem;

	g_at_chat_register(data->chat, "#RSEN:", telit_rsen_notify,
				FALSE, modem, NULL);

	g_at_chat_send(data->chat, "AT#NOPT=0", NULL, NULL, NULL, NULL);

	/* Set SAP functionality */
	g_at_chat_send(data->chat, "AT#RSEN=1,1,0,2,0", rsen_prefix,
				rsen_enable_cb, modem, NULL);

	return -EINPROGRESS;

error:
	shutdown(bt_fd, SHUT_RDWR);
	close(bt_fd);

	sap_close_io(modem);
	return -EINVAL;
}