All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH 1/2] Add basic Telit UC864-G support:
@ 2011-05-19 10:40 Bernhard.Guillon
  2011-05-19 10:40 ` [RFC PATCH 2/2] network-registration.c: implement CIND for Telit UC864-G Bernhard.Guillon
  2011-05-19 17:48 ` [RFC PATCH 1/2] Add basic Telit UC864-G support: Marcel Holtmann
  0 siblings, 2 replies; 6+ messages in thread
From: Bernhard.Guillon @ 2011-05-19 10:40 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 14929 bytes --]

From: Bernhard Guillon <Bernhard.Guillon@hale.at>

*add a basic plugin based on different ofono plugins
*use Telit specific QSS for SIM-state
*add verry basic GPS support (usable with gypsy)
*add udev support and rules
*update Makefile

Co-authored-by: Christopher Vogl <Christopher.Vogl@hale.at>
Signed-off-by: Bernhard Guillon <Bernhard.Guillon@hale.at>
---
 Makefile.am              |    3 +
 drivers/atmodem/vendor.h |    1 +
 plugins/ofono.rules      |   16 ++-
 plugins/telit.c          |  387 ++++++++++++++++++++++++++++++++++++++++++++++
 plugins/udev.c           |   40 +++++
 5 files changed, 446 insertions(+), 1 deletions(-)
 create mode 100644 plugins/telit.c

diff --git a/Makefile.am b/Makefile.am
index a413a47..6197cf6 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -326,6 +326,9 @@ builtin_sources += plugins/nokiacdma.c
 builtin_modules += linktop
 builtin_sources += plugins/linktop.c
 
+builtin_modules += telit
+builtin_sources += plugins/telit.c
+
 if BLUETOOTH
 builtin_modules += bluetooth
 builtin_sources += plugins/bluetooth.c plugins/bluetooth.h
diff --git a/drivers/atmodem/vendor.h b/drivers/atmodem/vendor.h
index 3898fa8..412bc76 100644
--- a/drivers/atmodem/vendor.h
+++ b/drivers/atmodem/vendor.h
@@ -35,4 +35,5 @@ enum ofono_vendor {
 	OFONO_VENDOR_WAVECOM,
 	OFONO_VENDOR_NOKIA,
 	OFONO_VENDOR_PHONESIM,
+	OFONO_VENDOR_TELIT,
 };
diff --git a/plugins/ofono.rules b/plugins/ofono.rules
index 5a36380..c0c4360 100644
--- a/plugins/ofono.rules
+++ b/plugins/ofono.rules
@@ -306,7 +306,7 @@ ATTRS{idVendor}=="12d1", ATTRS{idProduct}=="1479", ENV{OFONO_IFACE_NUM}=="00", E
 ATTRS{idVendor}=="12d1", ATTRS{idProduct}=="1479", ENV{OFONO_IFACE_NUM}=="04", ENV{OFONO_HUAWEI_TYPE}="Pcui"
 
 ATTRS{idVendor}=="12d1", ATTRS{idProduct}=="147a", ENV{OFONO_IFACE_NUM}=="00", ENV{OFONO_HUAWEI_TYPE}="Modem"
-ATTRS{idVendor}=="12d1", ATTRS{idProduct}=="147a", ENV{OFONO_IFACE_NUM}=="04", ENV{OFONO_HUAWEI_TYPE}="Pcui"
+	ATTRS{idVendor}=="12d1", ATTRS{idProduct}=="147a", ENV{OFONO_IFACE_NUM}=="04", ENV{OFONO_HUAWEI_TYPE}="Pcui"
 
 ATTRS{idVendor}=="12d1", ATTRS{idProduct}=="147b", ENV{OFONO_IFACE_NUM}=="00", ENV{OFONO_HUAWEI_TYPE}="Modem"
 ATTRS{idVendor}=="12d1", ATTRS{idProduct}=="147b", ENV{OFONO_IFACE_NUM}=="04", ENV{OFONO_HUAWEI_TYPE}="Pcui"
@@ -346,6 +346,20 @@ ATTRS{idVendor}=="12d1", ATTRS{idProduct}=="1486", ENV{OFONO_IFACE_NUM}=="02", E
 
 LABEL="ofono_tty_end"
 
+#Telit
+#This modem is not in SUBSYSTEM tty but in KERNEL ttyUSB. Therefore it is intended to be
+#after the ofono_tty_end line
+
+#UC864-G
+
+ATTR{idVendor}=="1bc7", ATTR{idProduct}=="1004", ENV{OFONO_IFACE_NUM}=="00", ENV{OFONO_TELIT_TYPE}="modem"
+ATTR{idVendor}=="1bc7", ATTR{idProduct}=="1004", ENV{OFONO_IFACE_NUM}=="01", ENV{OFONO_TELIT_TYPE}="aux"
+ATTR{idVendor}=="1bc7", ATTR{idProduct}=="1004", ENV{OFONO_IFACE_NUM}=="02", ENV{OFONO_TELIT_TYPE}="gps"
+ATTR{idVendor}=="1bc7", ATTR{idProduct}=="1004", ENV{OFONO_IFACE_NUM}=="03", ENV{OFONO_TELIT_TYPE}="uart"
+
+ATTR{idVendor}=="1bc7", ENV{OFONO_DRIVER}="telit"
+ATTR{idVendor}=="1bc7", ATTR{idProduct}=="1004", ENV{OFONO_TELIT_MODEL}="UC864-G"
+
 # ISI/Phonet drivers
 SUBSYSTEM!="net", GOTO="ofono_isi_end"
 ATTRS{type}!="820", GOTO="ofono_isi_end"
diff --git a/plugins/telit.c b/plugins/telit.c
new file mode 100644
index 0000000..d157561
--- /dev/null
+++ b/plugins/telit.c
@@ -0,0 +1,387 @@
+/*
+ *
+ *  oFono - Open Source Telephony
+ *
+ *  Copyright (C) 2008-2010  Intel Corporation. All rights reserved.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <errno.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+
+#include <glib.h>
+#include <gatchat.h>
+#include <gattty.h>
+
+#define OFONO_API_SUBJECT_TO_CHANGE
+#include <ofono/plugin.h>
+#include <ofono/log.h>
+#include <ofono/modem.h>
+#include <ofono/call-barring.h>
+#include <ofono/call-forwarding.h>
+#include <ofono/call-meter.h>
+#include <ofono/call-settings.h>
+#include <ofono/devinfo.h>
+#include <ofono/message-waiting.h>
+#include <ofono/netreg.h>
+#include <ofono/phonebook.h>
+#include <ofono/sim.h>
+#include <ofono/gprs.h>
+#include <ofono/gprs-context.h>
+#include <ofono/sms.h>
+#include <ofono/ussd.h>
+#include <ofono/voicecall.h>
+
+#include <drivers/atmodem/vendor.h>
+#include <drivers/atmodem/atutil.h>
+
+
+static const char *none_prefix[] = { NULL };
+
+
+static int telit_probe(struct ofono_modem *modem)
+{
+	DBG("");
+
+	return 0;
+}
+
+static void telit_remove(struct ofono_modem *modem)
+{
+	GAtChat *chat = ofono_modem_get_data(modem);
+
+	DBG("");
+
+	if (chat) {
+		g_at_chat_unref(chat);
+		ofono_modem_set_data(modem, NULL);
+	}
+}
+
+static void cfun_enable_cb(gboolean ok, GAtResult *result, gpointer user_data)
+{
+	struct ofono_modem *modem = user_data;
+
+	DBG("");
+
+	if (ok)
+		ofono_modem_set_powered(modem, TRUE);
+}
+
+static void cfun_disable_cb(gboolean ok, GAtResult *result, gpointer user_data)
+{
+	struct ofono_modem *modem = user_data;
+	GAtChat *chat = ofono_modem_get_data(modem);
+
+	DBG("");
+
+	g_at_chat_unref(chat);
+	ofono_modem_set_data(modem, NULL);
+
+	if (ok)
+		ofono_modem_set_powered(modem, FALSE);
+}
+
+static void telit_debug(const char *str, void *user_data)
+{
+	const char *prefix = user_data;
+
+	ofono_info("%s%s", prefix, str);
+}
+
+static int telit_enable(struct ofono_modem *modem)
+{
+	GAtChat *chat;
+	GIOChannel *channel;
+	GAtSyntax *syntax;
+	const char *device;
+	GHashTable *options;
+
+	DBG("%p", modem);
+
+	device = ofono_modem_get_string(modem, "Device");
+	if (device == NULL)
+		return -EINVAL;
+
+	options = g_hash_table_new(g_str_hash, g_str_equal);
+
+	if (options == NULL)
+		return -ENOMEM;
+
+	g_hash_table_insert(options, "Baud", "115200");
+	g_hash_table_insert(options, "Parity", "none");
+	g_hash_table_insert(options, "StopBits", "1");
+	g_hash_table_insert(options, "DataBits", "8");
+
+	DBG("IN TELIT: %s", device);
+
+	channel = g_at_tty_open(device, options);
+
+	g_hash_table_destroy(options);
+
+	DBG("channel: %p", channel);
+
+	if (channel == NULL)
+		return -EIO;
+
+	/*
+	 * Could not figure out whether it is fully compliant or not, use
+	 * permissive for now
+	 * */
+	syntax = g_at_syntax_new_gsm_permissive();
+
+	chat = g_at_chat_new(channel, syntax);
+	g_io_channel_unref(channel);
+	g_at_syntax_unref(syntax);
+
+	if (chat == NULL)
+		return -ENOMEM;
+
+	if (getenv("OFONO_AT_DEBUG"))
+		g_at_chat_set_debug(chat, telit_debug, "");
+
+	ofono_modem_set_data(modem, chat);
+
+	/* ATE0: disables command echo.
+	 * +CMEE=1: Enable the Extended Error Result Codes. */
+	g_at_chat_send(chat, "ATE0+CMEE=1", none_prefix, NULL, NULL, NULL);
+
+	/* Set phone functionality:
+	 * +CFUN=1: mobile full functionality with power saving disabled (factory default).
+	 * +CFUN=5: mobile full functionality with power saving enabled.
+	 */
+	g_at_chat_send(chat, "AT+CFUN=1", none_prefix, cfun_enable_cb, modem, NULL);
+
+	return 0;
+}
+
+static int telit_disable(struct ofono_modem *modem)
+{
+	GAtChat *chat = ofono_modem_get_data(modem);
+
+	DBG("%p", modem);
+
+	if (chat == NULL)
+		return 0;
+
+	/* power down modem */
+	g_at_chat_cancel_all(chat);
+	g_at_chat_unregister_all(chat);
+
+	g_at_chat_send(chat, "AT+CFUN=0", NULL, cfun_disable_cb, modem, NULL);
+
+	return -EINPROGRESS;
+}
+
+static void set_online_cb(gboolean ok, GAtResult *result, gpointer user_data)
+{
+	struct cb_data *cbd = user_data;
+	ofono_modem_online_cb_t cb = cbd->cb;
+
+	if (ok)
+		CALLBACK_WITH_SUCCESS(cb, cbd->data);
+	else
+		CALLBACK_WITH_FAILURE(cb, cbd->data);
+}
+
+static void telit_set_online(struct ofono_modem *modem, ofono_bool_t online,
+				ofono_modem_online_cb_t cb, void *user_data)
+{
+	GAtChat *chat = ofono_modem_get_data(modem);
+	struct cb_data *cbd = cb_data_new(cb, user_data);
+
+	char const *command = online ? "AT+CFUN=1" : "AT+CFUN=4";
+
+	DBG("modem %p %s", modem, online ? "online" : "offline");
+
+	if (chat == NULL)
+		goto error;
+
+	if (g_at_chat_send(chat, command, NULL, set_online_cb, cbd, g_free))
+		return;
+
+error:
+	g_free(cbd);
+
+	CALLBACK_WITH_FAILURE(cb, cbd->data);
+}
+
+
+
+static void telit_qss_notify(GAtResult *result, gpointer _sim)
+{
+	int status = 0;
+	GAtResultIter iter;
+	struct ofono_sim *sim = _sim;
+	g_at_result_iter_init(&iter, result);
+
+	if (!g_at_result_iter_next(&iter, "#QSS:"))
+		return;
+
+	g_at_result_iter_next_number(&iter, &status);
+	switch(status)
+	{
+		case 0:
+			DBG("SIM not inserted");
+			ofono_sim_inserted_notify(sim,FALSE);
+			break;
+		case 1:
+			DBG("SIM inserted");
+			/* we need to sleep a bit */
+			sleep(1);
+			ofono_sim_inserted_notify(sim,TRUE);
+			break;
+		case 2:
+			DBG("SIM inserted and PIN unlocked");
+			break;
+		case 3:
+			DBG("SIM inserted and ready");
+			break;
+		default:
+			return;
+	}
+	return;
+}
+
+static void telit_qss_cb(gboolean ok, GAtResult *result, gpointer _sim)
+{
+	int mode = 0;
+	int status = 0;
+	GAtResultIter iter;
+	struct ofono_sim *sim = _sim;
+	g_at_result_iter_init(&iter, result);
+	
+	if (!g_at_result_iter_next(&iter, "#QSS:"))
+		goto error;
+	g_at_result_iter_next_number(&iter, &mode);
+	g_at_result_iter_next_number(&iter, &status);
+	switch(status)
+	{
+		case 0:
+			DBG("SIM not inserted");
+			break;
+		case 1:
+			DBG("SIM inserted");
+			ofono_sim_inserted_notify(sim,TRUE);
+			break;
+		case 2:
+			DBG("SIM inserted and PIN unlocked");
+			break;
+		case 3:
+			DBG("SIM inserted and ready");
+			break;
+		default:
+			goto error;
+	} 
+error:
+	return;
+}
+
+static void telit_pre_sim(struct ofono_modem *modem)
+{
+	GAtChat *chat = ofono_modem_get_data(modem);
+	struct ofono_sim *sim;
+
+	DBG("%p", modem);
+	DBG("CAHT %p", chat);
+
+	ofono_devinfo_create(modem, 0, "atmodem", chat);
+	sim = ofono_sim_create(modem, OFONO_VENDOR_TELIT, "atmodem", chat);
+	ofono_voicecall_create(modem, 0, "atmodem", chat);
+
+	if(sim) {
+		/* enable sim state notification */
+		g_at_chat_send(chat, "AT#QSS=1", NULL, NULL, NULL, NULL);
+		g_at_chat_register(chat, "#QSS:", telit_qss_notify, FALSE, sim, NULL);
+		/* query current sim state */
+		g_at_chat_send(chat, "AT#QSS?", NULL, telit_qss_cb, sim, NULL);
+	}
+}
+
+static void telit_post_sim(struct ofono_modem *modem)
+{
+	GAtChat *chat = ofono_modem_get_data(modem);
+
+	DBG("%p", modem);
+
+	ofono_phonebook_create(modem, 0, "atmodem", chat);
+}
+
+static void telit_post_online(struct ofono_modem *modem)
+{
+	GAtChat *chat = ofono_modem_get_data(modem);
+	struct ofono_message_waiting *mw;
+	struct ofono_gprs *gprs;
+	struct ofono_gprs_context *gc;
+	int gps;
+
+	DBG("%p", modem);
+
+	gps = ofono_modem_get_integer(modem, "GPS");
+
+	if (gps)
+		g_at_chat_send(chat, "AT$GPSP=1", NULL, NULL, NULL, NULL);
+
+	ofono_ussd_create(modem, 0, "atmodem", chat);				// +CUSD - Unstructured Supplementary Service Data
+	ofono_call_forwarding_create(modem, 0, "atmodem", chat);
+	ofono_call_settings_create(modem, 0, "atmodem", chat);
+	ofono_netreg_create(modem, OFONO_VENDOR_TELIT, "atmodem", chat);
+	ofono_call_meter_create(modem, 0, "atmodem", chat);
+	ofono_call_barring_create(modem, 0, "atmodem", chat);
+	//ofono_cbs_create(modem, 0, "atmodem", chat);				//Cell Broadcast Service
+	ofono_sms_create(modem, 0, "atmodem", chat);
+
+	gprs = ofono_gprs_create(modem, 0, "atmodem", chat);
+	gc = ofono_gprs_context_create(modem, 0, "atmodem", chat);
+
+	if (gprs && gc)
+		ofono_gprs_add_context(gprs, gc);
+
+	mw = ofono_message_waiting_create(modem);
+	if (mw)
+		ofono_message_waiting_register(mw);
+}
+
+static struct ofono_modem_driver telit_driver = {
+	.name			= "telit",
+	.probe			= telit_probe,
+	.remove			= telit_remove,
+	.enable			= telit_enable,
+	.disable		= telit_disable,
+	.set_online		= telit_set_online,
+	.pre_sim		= telit_pre_sim,
+	.post_sim		= telit_post_sim,
+	.post_online	= telit_post_online,
+};
+
+static int telit_init(void)
+{
+	return ofono_modem_driver_register(&telit_driver);
+}
+
+static void telit_exit(void)
+{
+	ofono_modem_driver_unregister(&telit_driver);
+}
+
+OFONO_PLUGIN_DEFINE(telit, "telit driver", VERSION,
+		OFONO_PLUGIN_PRIORITY_DEFAULT, telit_init, telit_exit)
diff --git a/plugins/udev.c b/plugins/udev.c
index cbb596d..2913b5b 100644
--- a/plugins/udev.c
+++ b/plugins/udev.c
@@ -588,6 +588,44 @@ static void add_linktop(struct ofono_modem *modem,
 	}
 }
 
+static void add_telit(struct ofono_modem *modem,
+					struct udev_device *udev_device)
+{
+	struct udev_list_entry *entry;
+	const char *devnode;
+	gboolean found = FALSE;
+	gboolean gps = FALSE;
+
+	DBG("modem %p", modem);
+
+	entry = udev_device_get_properties_list_entry(udev_device);
+	while (entry) {
+		const char *name = udev_list_entry_get_name(entry);
+		const char *value = udev_list_entry_get_value(entry);
+
+		if (g_str_equal(name, "OFONO_TELIT_TYPE") == TRUE &&
+					g_str_equal(value, "modem") == TRUE) {
+			found = TRUE;
+		}
+		if (g_str_equal(name, "OFONO_TELIT_MODEL") == TRUE &&
+					g_str_equal(value, "UC864-G") == TRUE) {
+			gps = TRUE;
+		}
+		entry = udev_list_entry_get_next(entry);
+	}
+
+	if (found == FALSE)
+		return;
+
+	devnode = udev_device_get_devnode(udev_device);
+	ofono_modem_set_string(modem, "Device", devnode);
+
+	if(gps)
+		ofono_modem_set_integer(modem, "GPS", 1);
+
+	ofono_modem_register(modem);
+}
+
 static void add_modem(struct udev_device *udev_device)
 {
 	struct ofono_modem *modem;
@@ -682,6 +720,8 @@ done:
 		add_calypso(modem, udev_device);
 	else if (g_strcmp0(driver, "tc65") == 0)
 		add_tc65(modem, udev_device);
+	else if (g_strcmp0(driver, "telit") == 0)
+		add_telit(modem, udev_device);
 	else if (g_strcmp0(driver, "nokiacdma") == 0)
 		add_nokiacdma(modem, udev_device);
         else if (g_strcmp0(driver, "linktop") == 0)
-- 
1.7.0.4



--
Scanned by MailScanner.


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [RFC PATCH 2/2] network-registration.c: implement CIND for Telit UC864-G
  2011-05-19 10:40 [RFC PATCH 1/2] Add basic Telit UC864-G support: Bernhard.Guillon
@ 2011-05-19 10:40 ` Bernhard.Guillon
  2011-05-19 17:51   ` Marcel Holtmann
  2011-05-19 17:48 ` [RFC PATCH 1/2] Add basic Telit UC864-G support: Marcel Holtmann
  1 sibling, 1 reply; 6+ messages in thread
From: Bernhard.Guillon @ 2011-05-19 10:40 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 3110 bytes --]

From: Bernhard Guillon <Bernhard.Guillon@hale.at>

*UC864 has a incompatible CIND
*use specific constants for a KISS callback function
*add a Telit specific check for "not measurable" strength

Co-authored-by: Christopher Vogl <Christopher.Vogl@hale.at>
Signed-off-by: Bernhard Guillon <Bernhard.Guillon@hale.at>
---
 drivers/atmodem/network-registration.c |   38 +++++++++++++++++++++++++++++--
 1 files changed, 35 insertions(+), 3 deletions(-)

diff --git a/drivers/atmodem/network-registration.c b/drivers/atmodem/network-registration.c
index b3aa511..616faa2 100644
--- a/drivers/atmodem/network-registration.c
+++ b/drivers/atmodem/network-registration.c
@@ -48,6 +48,10 @@ static const char *cops_prefix[] = { "+COPS:", NULL };
 static const char *csq_prefix[] = { "+CSQ:", NULL };
 static const char *cind_prefix[] = { "+CIND:", NULL };
 static const char *option_tech_prefix[] = { "_OCTI:", "_OUWCTI:", NULL };
+static const int telit_signal_not_measurable = 99;
+static const int telit_signal_index = 9;
+static const int telit_signal_min = 0;
+static const int telit_signal_max = 5;
 
 struct netreg_data {
 	GAtChat *chat;
@@ -666,7 +670,16 @@ static void ciev_notify(GAtResult *result, gpointer user_data)
 	if (!g_at_result_iter_next_number(&iter, &strength))
 		return;
 
-	strength = (strength * 100) / (nd->signal_max - nd->signal_min);
+	switch (nd->vendor) {
+		case OFONO_VENDOR_TELIT:
+			if (strength == telit_signal_not_measurable)
+				strength = 0;
+			else
+				strength = (strength * 100) / (nd->signal_max - nd->signal_min);
+			break;
+		default:
+			strength = (strength * 100) / (nd->signal_max - nd->signal_min);
+	}
 	ofono_netreg_strength_notify(netreg, strength);
 }
 
@@ -798,8 +811,16 @@ static void cind_cb(gboolean ok, GAtResult *result, gpointer user_data)
 
 	g_at_result_iter_next_number(&iter, &strength);
 
-	strength = (strength * 100) / (nd->signal_max - nd->signal_min);
-
+	switch (nd->vendor) {
+		case OFONO_VENDOR_TELIT:
+			if (strength == telit_signal_not_measurable)
+				strength = 0;
+			else
+				strength = (strength * 100) / (nd->signal_max - nd->signal_min);
+			break;
+		default:
+			strength = (strength * 100) / (nd->signal_max - nd->signal_min);
+	}
 	cb(&error, strength, cbd->data);
 }
 
@@ -1302,6 +1323,17 @@ static void at_creg_set_cb(gboolean ok, GAtResult *result, gpointer user_data)
 	case OFONO_VENDOR_NOKIA:
 		/* Signal strength reporting via CIND is not supported */
 		break;
+	case OFONO_VENDOR_TELIT:
+		// FIXME: We use RSSI instead of signal.
+		// FIXME: Consider reading signal index from modem.
+		nd->signal_index = telit_signal_index;
+		nd->signal_min = telit_signal_min;
+		nd->signal_max = telit_signal_max;
+		g_at_chat_send(nd->chat, "AT+CIND=1", cind_prefix,
+								NULL, NULL, NULL);
+		g_at_chat_register(nd->chat, "+CIEV:",
+						ciev_notify, FALSE, netreg, NULL);
+		break;
 	default:
 		g_at_chat_send(nd->chat, "AT+CIND=?", cind_prefix,
 				cind_support_cb, netreg, NULL);
-- 
1.7.0.4



--
Scanned by MailScanner.


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [RFC PATCH 1/2] Add basic Telit UC864-G support:
  2011-05-19 10:40 [RFC PATCH 1/2] Add basic Telit UC864-G support: Bernhard.Guillon
  2011-05-19 10:40 ` [RFC PATCH 2/2] network-registration.c: implement CIND for Telit UC864-G Bernhard.Guillon
@ 2011-05-19 17:48 ` Marcel Holtmann
  2011-05-25 13:01   ` Bernhard Guillon
  1 sibling, 1 reply; 6+ messages in thread
From: Marcel Holtmann @ 2011-05-19 17:48 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 17737 bytes --]

Hi Bernhard,

> *add a basic plugin based on different ofono plugins
> *use Telit specific QSS for SIM-state
> *add verry basic GPS support (usable with gypsy)
> *add udev support and rules
> *update Makefile
> 
> Co-authored-by: Christopher Vogl <Christopher.Vogl@hale.at>
> Signed-off-by: Bernhard Guillon <Bernhard.Guillon@hale.at>

we are not using Signed-off-by for our commits.

> ---
>  Makefile.am              |    3 +
>  drivers/atmodem/vendor.h |    1 +
>  plugins/ofono.rules      |   16 ++-
>  plugins/telit.c          |  387 ++++++++++++++++++++++++++++++++++++++++++++++
>  plugins/udev.c           |   40 +++++
>  5 files changed, 446 insertions(+), 1 deletions(-)
>  create mode 100644 plugins/telit.c

please split changes into three patches. One for drivers, one for udev
(including the rules) and one for the telit modem plugin.

> diff --git a/Makefile.am b/Makefile.am
> index a413a47..6197cf6 100644
> --- a/Makefile.am
> +++ b/Makefile.am
> @@ -326,6 +326,9 @@ builtin_sources += plugins/nokiacdma.c
>  builtin_modules += linktop
>  builtin_sources += plugins/linktop.c
>  
> +builtin_modules += telit
> +builtin_sources += plugins/telit.c
> +
>  if BLUETOOTH
>  builtin_modules += bluetooth
>  builtin_sources += plugins/bluetooth.c plugins/bluetooth.h
> diff --git a/drivers/atmodem/vendor.h b/drivers/atmodem/vendor.h
> index 3898fa8..412bc76 100644
> --- a/drivers/atmodem/vendor.h
> +++ b/drivers/atmodem/vendor.h
> @@ -35,4 +35,5 @@ enum ofono_vendor {
>  	OFONO_VENDOR_WAVECOM,
>  	OFONO_VENDOR_NOKIA,
>  	OFONO_VENDOR_PHONESIM,
> +	OFONO_VENDOR_TELIT,
>  };
> diff --git a/plugins/ofono.rules b/plugins/ofono.rules
> index 5a36380..c0c4360 100644
> --- a/plugins/ofono.rules
> +++ b/plugins/ofono.rules
> @@ -306,7 +306,7 @@ ATTRS{idVendor}=="12d1", ATTRS{idProduct}=="1479", ENV{OFONO_IFACE_NUM}=="00", E
>  ATTRS{idVendor}=="12d1", ATTRS{idProduct}=="1479", ENV{OFONO_IFACE_NUM}=="04", ENV{OFONO_HUAWEI_TYPE}="Pcui"
>  
>  ATTRS{idVendor}=="12d1", ATTRS{idProduct}=="147a", ENV{OFONO_IFACE_NUM}=="00", ENV{OFONO_HUAWEI_TYPE}="Modem"
> -ATTRS{idVendor}=="12d1", ATTRS{idProduct}=="147a", ENV{OFONO_IFACE_NUM}=="04", ENV{OFONO_HUAWEI_TYPE}="Pcui"
> +	ATTRS{idVendor}=="12d1", ATTRS{idProduct}=="147a", ENV{OFONO_IFACE_NUM}=="04", ENV{OFONO_HUAWEI_TYPE}="Pcui"

You are messing with already existing rules here. Please don't.
 
>  ATTRS{idVendor}=="12d1", ATTRS{idProduct}=="147b", ENV{OFONO_IFACE_NUM}=="00", ENV{OFONO_HUAWEI_TYPE}="Modem"
>  ATTRS{idVendor}=="12d1", ATTRS{idProduct}=="147b", ENV{OFONO_IFACE_NUM}=="04", ENV{OFONO_HUAWEI_TYPE}="Pcui"
> @@ -346,6 +346,20 @@ ATTRS{idVendor}=="12d1", ATTRS{idProduct}=="1486", ENV{OFONO_IFACE_NUM}=="02", E
>  
>  LABEL="ofono_tty_end"
>  
> +#Telit
> +#This modem is not in SUBSYSTEM tty but in KERNEL ttyUSB. Therefore it is intended to be
> +#after the ofono_tty_end line

Why is that. What kernel driver is claiming this modem?

> +#UC864-G
> +
> +ATTR{idVendor}=="1bc7", ATTR{idProduct}=="1004", ENV{OFONO_IFACE_NUM}=="00", ENV{OFONO_TELIT_TYPE}="modem"
> +ATTR{idVendor}=="1bc7", ATTR{idProduct}=="1004", ENV{OFONO_IFACE_NUM}=="01", ENV{OFONO_TELIT_TYPE}="aux"
> +ATTR{idVendor}=="1bc7", ATTR{idProduct}=="1004", ENV{OFONO_IFACE_NUM}=="02", ENV{OFONO_TELIT_TYPE}="gps"
> +ATTR{idVendor}=="1bc7", ATTR{idProduct}=="1004", ENV{OFONO_IFACE_NUM}=="03", ENV{OFONO_TELIT_TYPE}="uart"
> +
> +ATTR{idVendor}=="1bc7", ENV{OFONO_DRIVER}="telit"
> +ATTR{idVendor}=="1bc7", ATTR{idProduct}=="1004", ENV{OFONO_TELIT_MODEL}="UC864-G"

Do you really need this model number?

> +
>  # ISI/Phonet drivers
>  SUBSYSTEM!="net", GOTO="ofono_isi_end"
>  ATTRS{type}!="820", GOTO="ofono_isi_end"
> diff --git a/plugins/telit.c b/plugins/telit.c
> new file mode 100644
> index 0000000..d157561
> --- /dev/null
> +++ b/plugins/telit.c
> @@ -0,0 +1,387 @@
> +/*
> + *
> + *  oFono - Open Source Telephony
> + *
> + *  Copyright (C) 2008-2010  Intel Corporation. All rights reserved.
> + *
> + *  This program is free software; you can redistribute it and/or modify
> + *  it under the terms of the GNU General Public License version 2 as
> + *  published by the Free Software Foundation.
> + *
> + *  This program is distributed in the hope that it will be useful,
> + *  but WITHOUT ANY WARRANTY; without even the implied warranty of
> + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + *  GNU General Public License for more details.
> + *
> + *  You should have received a copy of the GNU General Public License
> + *  along with this program; if not, write to the Free Software
> + *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
> + *
> + */
> +
> +#ifdef HAVE_CONFIG_H
> +#include <config.h>
> +#endif
> +
> +#include <errno.h>
> +#include <stdlib.h>
> +#include <stdio.h>
> +#include <unistd.h>
> +
> +#include <glib.h>
> +#include <gatchat.h>
> +#include <gattty.h>
> +
> +#define OFONO_API_SUBJECT_TO_CHANGE
> +#include <ofono/plugin.h>
> +#include <ofono/log.h>
> +#include <ofono/modem.h>
> +#include <ofono/call-barring.h>
> +#include <ofono/call-forwarding.h>
> +#include <ofono/call-meter.h>
> +#include <ofono/call-settings.h>
> +#include <ofono/devinfo.h>
> +#include <ofono/message-waiting.h>
> +#include <ofono/netreg.h>
> +#include <ofono/phonebook.h>
> +#include <ofono/sim.h>
> +#include <ofono/gprs.h>
> +#include <ofono/gprs-context.h>
> +#include <ofono/sms.h>
> +#include <ofono/ussd.h>
> +#include <ofono/voicecall.h>
> +
> +#include <drivers/atmodem/vendor.h>
> +#include <drivers/atmodem/atutil.h>
> +
> +
> +static const char *none_prefix[] = { NULL };
> +
> +

No double empty lines please.

> +static int telit_probe(struct ofono_modem *modem)
> +{
> +	DBG("");
> +
> +	return 0;
> +}
> +
> +static void telit_remove(struct ofono_modem *modem)
> +{
> +	GAtChat *chat = ofono_modem_get_data(modem);
> +
> +	DBG("");
> +
> +	if (chat) {
> +		g_at_chat_unref(chat);
> +		ofono_modem_set_data(modem, NULL);
> +	}
> +}

Please create a struct telit_data and allocate it in probe. Similar to
what all other drivers do. It is better than just trying to stick the
GAtChat object in the user data.

> +static void cfun_enable_cb(gboolean ok, GAtResult *result, gpointer user_data)
> +{
> +	struct ofono_modem *modem = user_data;
> +
> +	DBG("");
> +
> +	if (ok)
> +		ofono_modem_set_powered(modem, TRUE);
> +}
> +
> +static void cfun_disable_cb(gboolean ok, GAtResult *result, gpointer user_data)
> +{
> +	struct ofono_modem *modem = user_data;
> +	GAtChat *chat = ofono_modem_get_data(modem);
> +
> +	DBG("");
> +
> +	g_at_chat_unref(chat);
> +	ofono_modem_set_data(modem, NULL);

The set_data should only be used on probe() and remove(). Please obey
the lifetime rules of a modem object. They are similar to kernel driver.

> +	if (ok)
> +		ofono_modem_set_powered(modem, FALSE);
> +}
> +
> +static void telit_debug(const char *str, void *user_data)
> +{
> +	const char *prefix = user_data;
> +
> +	ofono_info("%s%s", prefix, str);
> +}
> +
> +static int telit_enable(struct ofono_modem *modem)
> +{
> +	GAtChat *chat;
> +	GIOChannel *channel;
> +	GAtSyntax *syntax;
> +	const char *device;
> +	GHashTable *options;
> +
> +	DBG("%p", modem);
> +
> +	device = ofono_modem_get_string(modem, "Device");
> +	if (device == NULL)
> +		return -EINVAL;
> +
> +	options = g_hash_table_new(g_str_hash, g_str_equal);
> +
> +	if (options == NULL)
> +		return -ENOMEM;
> +
> +	g_hash_table_insert(options, "Baud", "115200");
> +	g_hash_table_insert(options, "Parity", "none");
> +	g_hash_table_insert(options, "StopBits", "1");
> +	g_hash_table_insert(options, "DataBits", "8");

Are these really needed. So far we only needed it for the Calypso modem
which is on a real TTY port. All the other ones were fake TTY ports over
USB or SPI and did not need any extras.

> +
> +	DBG("IN TELIT: %s", device);
> +
> +	channel = g_at_tty_open(device, options);
> +
> +	g_hash_table_destroy(options);
> +
> +	DBG("channel: %p", channel);
> +
> +	if (channel == NULL)
> +		return -EIO;
> +
> +	/*
> +	 * Could not figure out whether it is fully compliant or not, use
> +	 * permissive for now
> +	 * */
> +	syntax = g_at_syntax_new_gsm_permissive();

Use the v1 parser for now. And we see if it is not compliant later.

> +	chat = g_at_chat_new(channel, syntax);
> +	g_io_channel_unref(channel);
> +	g_at_syntax_unref(syntax);
> +
> +	if (chat == NULL)
> +		return -ENOMEM;
> +
> +	if (getenv("OFONO_AT_DEBUG"))
> +		g_at_chat_set_debug(chat, telit_debug, "");
> +
> +	ofono_modem_set_data(modem, chat);

See above comment about struct telit_data and set_data usage.

> +	/* ATE0: disables command echo.
> +	 * +CMEE=1: Enable the Extended Error Result Codes. */
> +	g_at_chat_send(chat, "ATE0+CMEE=1", none_prefix, NULL, NULL, NULL);

Use "ATE0 +CMEE=1" to be a bit more in sync with the other plugins.

> +	/* Set phone functionality:
> +	 * +CFUN=1: mobile full functionality with power saving disabled (factory default).
> +	 * +CFUN=5: mobile full functionality with power saving enabled.
> +	 */
> +	g_at_chat_send(chat, "AT+CFUN=1", none_prefix, cfun_enable_cb, modem, NULL);

If you are supporting online mode, then this is wrong. You need to start
in offline mode. So most likely CFUN=4.

> +
> +	return 0;
> +}
> +
> +static int telit_disable(struct ofono_modem *modem)
> +{
> +	GAtChat *chat = ofono_modem_get_data(modem);
> +
> +	DBG("%p", modem);
> +
> +	if (chat == NULL)
> +		return 0;
> +
> +	/* power down modem */
> +	g_at_chat_cancel_all(chat);
> +	g_at_chat_unregister_all(chat);
> +
> +	g_at_chat_send(chat, "AT+CFUN=0", NULL, cfun_disable_cb, modem, NULL);
> +
> +	return -EINPROGRESS;
> +}
> +
> +static void set_online_cb(gboolean ok, GAtResult *result, gpointer user_data)
> +{
> +	struct cb_data *cbd = user_data;
> +	ofono_modem_online_cb_t cb = cbd->cb;
> +
> +	if (ok)
> +		CALLBACK_WITH_SUCCESS(cb, cbd->data);
> +	else
> +		CALLBACK_WITH_FAILURE(cb, cbd->data);
> +}
> +
> +static void telit_set_online(struct ofono_modem *modem, ofono_bool_t online,
> +				ofono_modem_online_cb_t cb, void *user_data)
> +{
> +	GAtChat *chat = ofono_modem_get_data(modem);
> +	struct cb_data *cbd = cb_data_new(cb, user_data);
> +
> +	char const *command = online ? "AT+CFUN=1" : "AT+CFUN=4";
> +
> +	DBG("modem %p %s", modem, online ? "online" : "offline");
> +
> +	if (chat == NULL)
> +		goto error;
> +
> +	if (g_at_chat_send(chat, command, NULL, set_online_cb, cbd, g_free))
> +		return;
> +
> +error:
> +	g_free(cbd);
> +
> +	CALLBACK_WITH_FAILURE(cb, cbd->data);
> +}
> +
> +
> +
> +static void telit_qss_notify(GAtResult *result, gpointer _sim)
> +{
> +	int status = 0;
> +	GAtResultIter iter;
> +	struct ofono_sim *sim = _sim;
> +	g_at_result_iter_init(&iter, result);
> +
> +	if (!g_at_result_iter_next(&iter, "#QSS:"))
> +		return;
> +
> +	g_at_result_iter_next_number(&iter, &status);
> +	switch(status)
> +	{
> +		case 0:
> +			DBG("SIM not inserted");
> +			ofono_sim_inserted_notify(sim,FALSE);
> +			break;

Please follow the coding style for switch statements here.

> +		case 1:
> +			DBG("SIM inserted");
> +			/* we need to sleep a bit */
> +			sleep(1);
> +			ofono_sim_inserted_notify(sim,TRUE);
> +			break;
> +		case 2:
> +			DBG("SIM inserted and PIN unlocked");
> +			break;
> +		case 3:
> +			DBG("SIM inserted and ready");
> +			break;
> +		default:
> +			return;
> +	}
> +	return;
> +}
> +
> +static void telit_qss_cb(gboolean ok, GAtResult *result, gpointer _sim)
> +{
> +	int mode = 0;
> +	int status = 0;
> +	GAtResultIter iter;
> +	struct ofono_sim *sim = _sim;
> +	g_at_result_iter_init(&iter, result);
> +	
> +	if (!g_at_result_iter_next(&iter, "#QSS:"))
> +		goto error;
> +	g_at_result_iter_next_number(&iter, &mode);
> +	g_at_result_iter_next_number(&iter, &status);
> +	switch(status)
> +	{
> +		case 0:
> +			DBG("SIM not inserted");
> +			break;
> +		case 1:
> +			DBG("SIM inserted");
> +			ofono_sim_inserted_notify(sim,TRUE);
> +			break;
> +		case 2:
> +			DBG("SIM inserted and PIN unlocked");
> +			break;
> +		case 3:
> +			DBG("SIM inserted and ready");
> +			break;
> +		default:
> +			goto error;
> +	} 
> +error:
> +	return;
> +}
> +
> +static void telit_pre_sim(struct ofono_modem *modem)
> +{
> +	GAtChat *chat = ofono_modem_get_data(modem);
> +	struct ofono_sim *sim;
> +
> +	DBG("%p", modem);
> +	DBG("CAHT %p", chat);
> +
> +	ofono_devinfo_create(modem, 0, "atmodem", chat);
> +	sim = ofono_sim_create(modem, OFONO_VENDOR_TELIT, "atmodem", chat);

Why are you using a quirk here?

> +	ofono_voicecall_create(modem, 0, "atmodem", chat);
> +
> +	if(sim) {
> +		/* enable sim state notification */
> +		g_at_chat_send(chat, "AT#QSS=1", NULL, NULL, NULL, NULL);
> +		g_at_chat_register(chat, "#QSS:", telit_qss_notify, FALSE, sim, NULL);
> +		/* query current sim state */
> +		g_at_chat_send(chat, "AT#QSS?", NULL, telit_qss_cb, sim, NULL);

Using NULL for prefix is most likely wrong here. Can you show us some
examples logs with OFONO_AT_DEBUG=1 for this?

> +	}
> +}
> +
> +static void telit_post_sim(struct ofono_modem *modem)
> +{
> +	GAtChat *chat = ofono_modem_get_data(modem);
> +
> +	DBG("%p", modem);
> +
> +	ofono_phonebook_create(modem, 0, "atmodem", chat);
> +}
> +
> +static void telit_post_online(struct ofono_modem *modem)
> +{
> +	GAtChat *chat = ofono_modem_get_data(modem);
> +	struct ofono_message_waiting *mw;
> +	struct ofono_gprs *gprs;
> +	struct ofono_gprs_context *gc;
> +	int gps;
> +
> +	DBG("%p", modem);
> +
> +	gps = ofono_modem_get_integer(modem, "GPS");
> +
> +	if (gps)
> +		g_at_chat_send(chat, "AT$GPSP=1", NULL, NULL, NULL, NULL);

So in general the post_online, pre_sim and post_sim states should only
be used to add atoms and not to send commands.

If you wanna support GPS, then please create a proper atom driver
specific for the Telit modem.

> +
> +	ofono_ussd_create(modem, 0, "atmodem", chat);				// +CUSD - Unstructured Supplementary Service Data

Leave out the comments here.

> +	ofono_call_forwarding_create(modem, 0, "atmodem", chat);
> +	ofono_call_settings_create(modem, 0, "atmodem", chat);
> +	ofono_netreg_create(modem, OFONO_VENDOR_TELIT, "atmodem", chat);
> +	ofono_call_meter_create(modem, 0, "atmodem", chat);
> +	ofono_call_barring_create(modem, 0, "atmodem", chat);
> +	//ofono_cbs_create(modem, 0, "atmodem", chat);				//Cell Broadcast Service

If not used, then leave it out for now.

> +	ofono_sms_create(modem, 0, "atmodem", chat);
> +
> +	gprs = ofono_gprs_create(modem, 0, "atmodem", chat);
> +	gc = ofono_gprs_context_create(modem, 0, "atmodem", chat);
> +
> +	if (gprs && gc)
> +		ofono_gprs_add_context(gprs, gc);
> +
> +	mw = ofono_message_waiting_create(modem);
> +	if (mw)
> +		ofono_message_waiting_register(mw);
> +}
> +
> +static struct ofono_modem_driver telit_driver = {
> +	.name			= "telit",
> +	.probe			= telit_probe,
> +	.remove			= telit_remove,
> +	.enable			= telit_enable,
> +	.disable		= telit_disable,
> +	.set_online		= telit_set_online,
> +	.pre_sim		= telit_pre_sim,
> +	.post_sim		= telit_post_sim,
> +	.post_online	= telit_post_online,
> +};
> +
> +static int telit_init(void)
> +{
> +	return ofono_modem_driver_register(&telit_driver);
> +}
> +
> +static void telit_exit(void)
> +{
> +	ofono_modem_driver_unregister(&telit_driver);
> +}
> +
> +OFONO_PLUGIN_DEFINE(telit, "telit driver", VERSION,
> +		OFONO_PLUGIN_PRIORITY_DEFAULT, telit_init, telit_exit)
> diff --git a/plugins/udev.c b/plugins/udev.c
> index cbb596d..2913b5b 100644
> --- a/plugins/udev.c
> +++ b/plugins/udev.c
> @@ -588,6 +588,44 @@ static void add_linktop(struct ofono_modem *modem,
>  	}
>  }
>  
> +static void add_telit(struct ofono_modem *modem,
> +					struct udev_device *udev_device)
> +{
> +	struct udev_list_entry *entry;
> +	const char *devnode;
> +	gboolean found = FALSE;
> +	gboolean gps = FALSE;
> +
> +	DBG("modem %p", modem);
> +
> +	entry = udev_device_get_properties_list_entry(udev_device);
> +	while (entry) {
> +		const char *name = udev_list_entry_get_name(entry);
> +		const char *value = udev_list_entry_get_value(entry);
> +
> +		if (g_str_equal(name, "OFONO_TELIT_TYPE") == TRUE &&
> +					g_str_equal(value, "modem") == TRUE) {
> +			found = TRUE;
> +		}
> +		if (g_str_equal(name, "OFONO_TELIT_MODEL") == TRUE &&
> +					g_str_equal(value, "UC864-G") == TRUE) {
> +			gps = TRUE;
> +		}
> +		entry = udev_list_entry_get_next(entry);
> +	}
> +
> +	if (found == FALSE)
> +		return;
> +
> +	devnode = udev_device_get_devnode(udev_device);
> +	ofono_modem_set_string(modem, "Device", devnode);
> +
> +	if(gps)
> +		ofono_modem_set_integer(modem, "GPS", 1);
> +
> +	ofono_modem_register(modem);
> +}
> +

Do you happen to have the output of /proc/bus/usb/devices for this
device?

>  static void add_modem(struct udev_device *udev_device)
>  {
>  	struct ofono_modem *modem;
> @@ -682,6 +720,8 @@ done:
>  		add_calypso(modem, udev_device);
>  	else if (g_strcmp0(driver, "tc65") == 0)
>  		add_tc65(modem, udev_device);
> +	else if (g_strcmp0(driver, "telit") == 0)
> +		add_telit(modem, udev_device);
>  	else if (g_strcmp0(driver, "nokiacdma") == 0)
>  		add_nokiacdma(modem, udev_device);
>          else if (g_strcmp0(driver, "linktop") == 0)

Regards

Marcel



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [RFC PATCH 2/2] network-registration.c: implement CIND for Telit UC864-G
  2011-05-19 10:40 ` [RFC PATCH 2/2] network-registration.c: implement CIND for Telit UC864-G Bernhard.Guillon
@ 2011-05-19 17:51   ` Marcel Holtmann
  0 siblings, 0 replies; 6+ messages in thread
From: Marcel Holtmann @ 2011-05-19 17:51 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 3547 bytes --]

Hi Bernhard,

> *UC864 has a incompatible CIND
> *use specific constants for a KISS callback function
> *add a Telit specific check for "not measurable" strength
> 
> Co-authored-by: Christopher Vogl <Christopher.Vogl@hale.at>
> Signed-off-by: Bernhard Guillon <Bernhard.Guillon@hale.at>

no signed-off-by lines please.

> ---
>  drivers/atmodem/network-registration.c |   38 +++++++++++++++++++++++++++++--
>  1 files changed, 35 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/atmodem/network-registration.c b/drivers/atmodem/network-registration.c
> index b3aa511..616faa2 100644
> --- a/drivers/atmodem/network-registration.c
> +++ b/drivers/atmodem/network-registration.c
> @@ -48,6 +48,10 @@ static const char *cops_prefix[] = { "+COPS:", NULL };
>  static const char *csq_prefix[] = { "+CSQ:", NULL };
>  static const char *cind_prefix[] = { "+CIND:", NULL };
>  static const char *option_tech_prefix[] = { "_OCTI:", "_OUWCTI:", NULL };
> +static const int telit_signal_not_measurable = 99;
> +static const int telit_signal_index = 9;
> +static const int telit_signal_min = 0;
> +static const int telit_signal_max = 5;

Please do not add such constants here.
 
>  struct netreg_data {
>  	GAtChat *chat;
> @@ -666,7 +670,16 @@ static void ciev_notify(GAtResult *result, gpointer user_data)
>  	if (!g_at_result_iter_next_number(&iter, &strength))
>  		return;
>  
> -	strength = (strength * 100) / (nd->signal_max - nd->signal_min);
> +	switch (nd->vendor) {
> +		case OFONO_VENDOR_TELIT:

Follow coding style for switch statements please.

> +			if (strength == telit_signal_not_measurable)
> +				strength = 0;
> +			else
> +				strength = (strength * 100) / (nd->signal_max - nd->signal_min);
> +			break;
> +		default:
> +			strength = (strength * 100) / (nd->signal_max - nd->signal_min);

You need to add a break here.

> +	}
>  	ofono_netreg_strength_notify(netreg, strength);
>  }
>  
> @@ -798,8 +811,16 @@ static void cind_cb(gboolean ok, GAtResult *result, gpointer user_data)
>  
>  	g_at_result_iter_next_number(&iter, &strength);
>  
> -	strength = (strength * 100) / (nd->signal_max - nd->signal_min);
> -
> +	switch (nd->vendor) {
> +		case OFONO_VENDOR_TELIT:
> +			if (strength == telit_signal_not_measurable)

Just use plain number 99 here.

> +				strength = 0;
> +			else
> +				strength = (strength * 100) / (nd->signal_max - nd->signal_min);
> +			break;
> +		default:
> +			strength = (strength * 100) / (nd->signal_max - nd->signal_min);
> +	}
>  	cb(&error, strength, cbd->data);
>  }
>  
> @@ -1302,6 +1323,17 @@ static void at_creg_set_cb(gboolean ok, GAtResult *result, gpointer user_data)
>  	case OFONO_VENDOR_NOKIA:
>  		/* Signal strength reporting via CIND is not supported */
>  		break;
> +	case OFONO_VENDOR_TELIT:
> +		// FIXME: We use RSSI instead of signal.
> +		// FIXME: Consider reading signal index from modem.
> +		nd->signal_index = telit_signal_index;
> +		nd->signal_min = telit_signal_min;
> +		nd->signal_max = telit_signal_max;

Fill in the values manually here. And please don't clutter the code with
FIXME. Have a comment that describes the current approach.

> +		g_at_chat_send(nd->chat, "AT+CIND=1", cind_prefix,
> +								NULL, NULL, NULL);
> +		g_at_chat_register(nd->chat, "+CIEV:",
> +						ciev_notify, FALSE, netreg, NULL);
> +		break;
>  	default:
>  		g_at_chat_send(nd->chat, "AT+CIND=?", cind_prefix,
>  				cind_support_cb, netreg, NULL);

Regards

Marcel



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [RFC PATCH 1/2] Add basic Telit UC864-G support:
  2011-05-19 17:48 ` [RFC PATCH 1/2] Add basic Telit UC864-G support: Marcel Holtmann
@ 2011-05-25 13:01   ` Bernhard Guillon
  2011-05-25 16:12     ` Marcel Holtmann
  0 siblings, 1 reply; 6+ messages in thread
From: Bernhard Guillon @ 2011-05-25 13:01 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 7576 bytes --]

On 19.05.2011 19:48, Marcel Holtmann wrote:

Hi Marcel,
thanks for the fast review :)

> please split changes into three patches. One for drivers, one for udev
> (including the rules) and one for the telit modem plugin.
>

Ok,
I will send the updated patches later today.


>> +#Telit
>> +#This modem is not in SUBSYSTEM tty but in KERNEL ttyUSB. Therefore it is intended to be
>> +#after the ofono_tty_end line
> Why is that. What kernel driver is claiming this modem?
>

This is my fault the kernel driver is usb-serial and tty and I used ATTR 
instead of ATTRS. I used udevadm monitor to get the usb-serial but I 
missed the tty. I fixed this in the new patch.

>> +ATTR{idVendor}=="1bc7", ATTR{idProduct}=="1004", ENV{OFONO_TELIT_MODEL}="UC864-G"
> Do you really need this model number?
>

No, I removed it from the new patch. I used it to gain knowledge about 
GPS but if I use an atom as you suggested I can do it like the other 
plugins are doing it. For now I do not attempt to support GPS.


>> +
>> +	g_hash_table_insert(options, "Baud", "115200");
>> +	g_hash_table_insert(options, "Parity", "none");
>> +	g_hash_table_insert(options, "StopBits", "1");
>> +	g_hash_table_insert(options, "DataBits", "8");
> Are these really needed. So far we only needed it for the Calypso modem
> which is on a real TTY port. All the other ones were fake TTY ports over
> USB or SPI and did not need any extras.
>
No, I just tested it without and updated the patch.

>> +
>> +	DBG("IN TELIT: %s", device);
>> +
>> +	channel = g_at_tty_open(device, options);
>> +
>> +	g_hash_table_destroy(options);
>> +
>> +	DBG("channel: %p", channel);
>> +
>> +	if (channel == NULL)
>> +		return -EIO;
>> +
>> +	/*
>> +	 * Could not figure out whether it is fully compliant or not, use
>> +	 * permissive for now
>> +	 * */
>> +	syntax = g_at_syntax_new_gsm_permissive();
> Use the v1 parser for now. And we see if it is not compliant later.
>
Ok, I switched to v1 and tested it a bit and it works properly.

>
>> +	 * +CFUN=1: mobile full functionality with power saving disabled (factory default).
>> +	 * +CFUN=5: mobile full functionality with power saving enabled.
>> +	 */
>> +	g_at_chat_send(chat, "AT+CFUN=1", none_prefix, cfun_enable_cb, modem, NULL);
> If you are supporting online mode, then this is wrong. You need to start
> in offline mode. So most likely CFUN=4.
>

Ok, I switched it. The only problem about being in state 4 is that #QSS 
returns "sim not inserted". But after test/online-modem everything wakes 
up properly. I was not sure about attaching a full log or not. I can 
upload it to pastebin if you like.

...
ofonod[5796]: src/sim.c:ofono_sim_add_state_watch() 0x9488ad0
ofonod[5796]: Modem: > AT#QSS=1\r
ofonod[5796]: Modem: < \r\nOK\r\n
ofonod[5796]: Modem: > AT#QSS?\r
ofonod[5796]: Modem: < \r\n#QSS: 1,0\r\n\r\nOK\r\n
ofonod[5796]: plugins/telit.c:telit_qss_cb() SIM not inserted
ofonod[5796]: Modem: > AT+CGMI\r
ofonod[5796]: Modem: < \r\nTelit\r\n\r\nOK\r\n
ofonod[5796]: Modem: > AT+CLCC\r
ofonod[5796]: Modem: < \r\n+CME ERROR: 10\r\n
ofonod[5796]: Modem: > AT+CGMM\r
ofonod[5796]: Modem: < \r\nUC864-G\r\n\r\nOK\r\n
ofonod[5796]: Modem: > AT+CGMR\r
ofonod[5796]: Modem: < \r\n08.01.107\r\n\r\nOK\r\n
ofonod[5796]: Modem: > AT+CGSN\r
ofonod[5796]: Modem: < \r\n356265021006068\r\n\r\nOK\r\n
ofonod[5796]: plugins/telit.c:telit_set_online() modem 0x9488438 online
ofonod[5796]: Modem: > AT+CFUN=1\r
ofonod[5796]: Modem: < \r\nOK\r\n
ofonod[5796]: src/modem.c:common_online_cb() Online in PRE SIM state
ofonod[5796]: Modem: < \r\n#QSS: 1\r\n
ofonod[5796]: plugins/telit.c:telit_qss_notify() SIM inserted
ofonod[5796]: Modem: > AT+CRSM=192,28599\r
...

>
>> +		/* enable sim state notification */
>> +		g_at_chat_send(chat, "AT#QSS=1", NULL, NULL, NULL, NULL);
>> +		g_at_chat_register(chat, "#QSS:", telit_qss_notify, FALSE, sim, NULL);
>> +		/* query current sim state */
>> +		g_at_chat_send(chat, "AT#QSS?", NULL, telit_qss_cb, sim, NULL);
> Using NULL for prefix is most likely wrong here. Can you show us some
> examples logs with OFONO_AT_DEBUG=1 for this?
>

ofonod[30582]: drivers/atmodem/voicecall.c:at_voicecall_initialized() 
voicecall_init: registering to notifications
ofonod[30582]: src/sim.c:ofono_sim_add_state_watch() 0x18cb6b0
ofonod[30582]: > AT#QSS=1\r
ofonod[30582]: < \r\nOK\r\n
ofonod[30582]: > AT#QSS?\r
ofonod[30582]: < \r\n#QSS: 1,1\r\n\r\nOK\r\n
ofonod[30582]: plugins/telit.c:telit_qss_cb() SIM inserted
ofonod[30582]: > AT+CGMI\r
ofonod[30582]: < \r\nTelit\r\n\r\nOK\r\n
ofonod[30582]: > AT+CLCC\r
ofonod[30582]: < \r\nOK\r\n

But I followed your adwise and added a prefix for #QSS for the new patch 
(see output above)

>
>> +
>> +	if (gps)
>> +		g_at_chat_send(chat, "AT$GPSP=1", NULL, NULL, NULL, NULL);
> So in general the post_online, pre_sim and post_sim states should only
> be used to add atoms and not to send commands.
>
> If you wanna support GPS, then please create a proper atom driver
> specific for the Telit modem.
>

Ok, I will remove the GPS attempts of the patch and try to support it 
later.

As far as I read the doc a correct implemented GPS atom is opening the 
GPS tty line, so I cannot longer use it with gypsy?

>> +static void add_telit(struct ofono_modem *modem,
>> +					struct udev_device *udev_device)
>> +{
>> +	struct udev_list_entry *entry;
>> +	const char *devnode;
>> +	gboolean found = FALSE;
>> +	gboolean gps = FALSE;
>> +
>> +	DBG("modem %p", modem);
>> +
>> +	entry = udev_device_get_properties_list_entry(udev_device);
>> +	while (entry) {
>> +		const char *name = udev_list_entry_get_name(entry);
>> +		const char *value = udev_list_entry_get_value(entry);
>> +
>> +		if (g_str_equal(name, "OFONO_TELIT_TYPE") == TRUE&&
>> +					g_str_equal(value, "modem") == TRUE) {
>> +			found = TRUE;
>> +		}
>> +		if (g_str_equal(name, "OFONO_TELIT_MODEL") == TRUE&&
>> +					g_str_equal(value, "UC864-G") == TRUE) {
>> +			gps = TRUE;
>> +		}
>> +		entry = udev_list_entry_get_next(entry);
>> +	}
>> +
>> +	if (found == FALSE)
>> +		return;
>> +
>> +	devnode = udev_device_get_devnode(udev_device);
>> +	ofono_modem_set_string(modem, "Device", devnode);
>> +
>> +	if(gps)
>> +		ofono_modem_set_integer(modem, "GPS", 1);
>> +
>> +	ofono_modem_register(modem);
>> +}
>> +
>
> Do you happen to have the output of /proc/bus/usb/devices for this
> device?
>

#uname -a
Linux entw48 2.6.32-28-generic #55-Ubuntu SMP Mon Jan 10 23:42:43 UTC 
2011 x86_64 GNU/Linux

# ls -lah /proc/bus/
total 0
dr-xr-xr-x   4 root root 0 2011-05-25 14:32 .
dr-xr-xr-x 237 root root 0 2011-05-24 10:53 ..
dr-xr-xr-x   2 root root 0 2011-05-25 14:32 input
dr-xr-xr-x   3 root root 0 2011-05-25 14:32 pci


root(a)entw48:~# ls -lah /sys/bus/usb-serial/devices/
total 0
drwxr-xr-x 2 root root 0 2011-05-25 14:33 .
drwxr-xr-x 4 root root 0 2011-05-25 14:32 ..
lrwxrwxrwx 1 root root 0 2011-05-25 14:33 ttyUSB0 -> 
../../../devices/pci0000:00/0000:00:1d.2/usb8/8-2/8-2:1.0/ttyUSB0
lrwxrwxrwx 1 root root 0 2011-05-25 14:33 ttyUSB1 -> 
../../../devices/pci0000:00/0000:00:1d.2/usb8/8-2/8-2:1.1/ttyUSB1
lrwxrwxrwx 1 root root 0 2011-05-25 14:33 ttyUSB2 -> 
../../../devices/pci0000:00/0000:00:1d.2/usb8/8-2/8-2:1.2/ttyUSB2
lrwxrwxrwx 1 root root 0 2011-05-25 14:33 ttyUSB3 -> 
../../../devices/pci0000:00/0000:00:1d.2/usb8/8-2/8-2:1.3/ttyUSB3


Best regards,
Bernhard Guillon


--
Scanned by MailScanner.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [RFC PATCH 1/2] Add basic Telit UC864-G support:
  2011-05-25 13:01   ` Bernhard Guillon
@ 2011-05-25 16:12     ` Marcel Holtmann
  0 siblings, 0 replies; 6+ messages in thread
From: Marcel Holtmann @ 2011-05-25 16:12 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 6430 bytes --]

Hi Bernhard,

> >> +	 * +CFUN=1: mobile full functionality with power saving disabled (factory default).
> >> +	 * +CFUN=5: mobile full functionality with power saving enabled.
> >> +	 */
> >> +	g_at_chat_send(chat, "AT+CFUN=1", none_prefix, cfun_enable_cb, modem, NULL);
> > If you are supporting online mode, then this is wrong. You need to start
> > in offline mode. So most likely CFUN=4.
> >
> 
> Ok, I switched it. The only problem about being in state 4 is that #QSS 
> returns "sim not inserted". But after test/online-modem everything wakes 
> up properly. I was not sure about attaching a full log or not. I can 
> upload it to pastebin if you like.
> 
> ...
> ofonod[5796]: src/sim.c:ofono_sim_add_state_watch() 0x9488ad0
> ofonod[5796]: Modem: > AT#QSS=1\r
> ofonod[5796]: Modem: < \r\nOK\r\n
> ofonod[5796]: Modem: > AT#QSS?\r
> ofonod[5796]: Modem: < \r\n#QSS: 1,0\r\n\r\nOK\r\n
> ofonod[5796]: plugins/telit.c:telit_qss_cb() SIM not inserted
> ofonod[5796]: Modem: > AT+CGMI\r
> ofonod[5796]: Modem: < \r\nTelit\r\n\r\nOK\r\n
> ofonod[5796]: Modem: > AT+CLCC\r
> ofonod[5796]: Modem: < \r\n+CME ERROR: 10\r\n
> ofonod[5796]: Modem: > AT+CGMM\r
> ofonod[5796]: Modem: < \r\nUC864-G\r\n\r\nOK\r\n
> ofonod[5796]: Modem: > AT+CGMR\r
> ofonod[5796]: Modem: < \r\n08.01.107\r\n\r\nOK\r\n
> ofonod[5796]: Modem: > AT+CGSN\r
> ofonod[5796]: Modem: < \r\n356265021006068\r\n\r\nOK\r\n
> ofonod[5796]: plugins/telit.c:telit_set_online() modem 0x9488438 online
> ofonod[5796]: Modem: > AT+CFUN=1\r
> ofonod[5796]: Modem: < \r\nOK\r\n
> ofonod[5796]: src/modem.c:common_online_cb() Online in PRE SIM state
> ofonod[5796]: Modem: < \r\n#QSS: 1\r\n
> ofonod[5796]: plugins/telit.c:telit_qss_notify() SIM inserted
> ofonod[5796]: Modem: > AT+CRSM=192,28599\r
> ...

you need to handle SIM hotswap if the modem does support and report it.
Check how other modem plugins do it.

> >> +		/* enable sim state notification */
> >> +		g_at_chat_send(chat, "AT#QSS=1", NULL, NULL, NULL, NULL);
> >> +		g_at_chat_register(chat, "#QSS:", telit_qss_notify, FALSE, sim, NULL);
> >> +		/* query current sim state */
> >> +		g_at_chat_send(chat, "AT#QSS?", NULL, telit_qss_cb, sim, NULL);
> > Using NULL for prefix is most likely wrong here. Can you show us some
> > examples logs with OFONO_AT_DEBUG=1 for this?
> >
> 
> ofonod[30582]: drivers/atmodem/voicecall.c:at_voicecall_initialized() 
> voicecall_init: registering to notifications
> ofonod[30582]: src/sim.c:ofono_sim_add_state_watch() 0x18cb6b0
> ofonod[30582]: > AT#QSS=1\r
> ofonod[30582]: < \r\nOK\r\n
> ofonod[30582]: > AT#QSS?\r
> ofonod[30582]: < \r\n#QSS: 1,1\r\n\r\nOK\r\n
> ofonod[30582]: plugins/telit.c:telit_qss_cb() SIM inserted
> ofonod[30582]: > AT+CGMI\r
> ofonod[30582]: < \r\nTelit\r\n\r\nOK\r\n
> ofonod[30582]: > AT+CLCC\r
> ofonod[30582]: < \r\nOK\r\n
> 
> But I followed your adwise and added a prefix for #QSS for the new patch 
> (see output above)

For AT#QSS=1 you do want to use none_prefix. And for AT#QSS? you want to
use a special qss_prefix.

In case you are using NULL as prefix it would consume all events and
that means that any other unsolicited notification will be missed.

> >> +	if (gps)
> >> +		g_at_chat_send(chat, "AT$GPSP=1", NULL, NULL, NULL, NULL);
> > So in general the post_online, pre_sim and post_sim states should only
> > be used to add atoms and not to send commands.
> >
> > If you wanna support GPS, then please create a proper atom driver
> > specific for the Telit modem.
> >
> 
> Ok, I will remove the GPS attempts of the patch and try to support it 
> later.
> 
> As far as I read the doc a correct implemented GPS atom is opening the 
> GPS tty line, so I cannot longer use it with gypsy?

It does not need to be. You can have multiple TTY and also the location
reporting atoms return a file descriptor via D-Bus. So that would be
easy to use from Gypsy as well. However the TTY is actually owned by
oFono in the end.

> >> +static void add_telit(struct ofono_modem *modem,
> >> +					struct udev_device *udev_device)
> >> +{
> >> +	struct udev_list_entry *entry;
> >> +	const char *devnode;
> >> +	gboolean found = FALSE;
> >> +	gboolean gps = FALSE;
> >> +
> >> +	DBG("modem %p", modem);
> >> +
> >> +	entry = udev_device_get_properties_list_entry(udev_device);
> >> +	while (entry) {
> >> +		const char *name = udev_list_entry_get_name(entry);
> >> +		const char *value = udev_list_entry_get_value(entry);
> >> +
> >> +		if (g_str_equal(name, "OFONO_TELIT_TYPE") == TRUE&&
> >> +					g_str_equal(value, "modem") == TRUE) {
> >> +			found = TRUE;
> >> +		}
> >> +		if (g_str_equal(name, "OFONO_TELIT_MODEL") == TRUE&&
> >> +					g_str_equal(value, "UC864-G") == TRUE) {
> >> +			gps = TRUE;
> >> +		}
> >> +		entry = udev_list_entry_get_next(entry);
> >> +	}
> >> +
> >> +	if (found == FALSE)
> >> +		return;
> >> +
> >> +	devnode = udev_device_get_devnode(udev_device);
> >> +	ofono_modem_set_string(modem, "Device", devnode);
> >> +
> >> +	if(gps)
> >> +		ofono_modem_set_integer(modem, "GPS", 1);
> >> +
> >> +	ofono_modem_register(modem);
> >> +}
> >> +
> >
> > Do you happen to have the output of /proc/bus/usb/devices for this
> > device?
> >
> 
> #uname -a
> Linux entw48 2.6.32-28-generic #55-Ubuntu SMP Mon Jan 10 23:42:43 UTC 
> 2011 x86_64 GNU/Linux
> 
> # ls -lah /proc/bus/
> total 0
> dr-xr-xr-x   4 root root 0 2011-05-25 14:32 .
> dr-xr-xr-x 237 root root 0 2011-05-24 10:53 ..
> dr-xr-xr-x   2 root root 0 2011-05-25 14:32 input
> dr-xr-xr-x   3 root root 0 2011-05-25 14:32 pci
> 
> 
> root(a)entw48:~# ls -lah /sys/bus/usb-serial/devices/
> total 0
> drwxr-xr-x 2 root root 0 2011-05-25 14:33 .
> drwxr-xr-x 4 root root 0 2011-05-25 14:32 ..
> lrwxrwxrwx 1 root root 0 2011-05-25 14:33 ttyUSB0 -> 
> ../../../devices/pci0000:00/0000:00:1d.2/usb8/8-2/8-2:1.0/ttyUSB0
> lrwxrwxrwx 1 root root 0 2011-05-25 14:33 ttyUSB1 -> 
> ../../../devices/pci0000:00/0000:00:1d.2/usb8/8-2/8-2:1.1/ttyUSB1
> lrwxrwxrwx 1 root root 0 2011-05-25 14:33 ttyUSB2 -> 
> ../../../devices/pci0000:00/0000:00:1d.2/usb8/8-2/8-2:1.2/ttyUSB2
> lrwxrwxrwx 1 root root 0 2011-05-25 14:33 ttyUSB3 -> 
> ../../../devices/pci0000:00/0000:00:1d.2/usb8/8-2/8-2:1.3/ttyUSB3

There is a script usbdevices.sh if you do not have usbfs mounted
anymore.

Regards

Marcel



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2011-05-25 16:12 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-05-19 10:40 [RFC PATCH 1/2] Add basic Telit UC864-G support: Bernhard.Guillon
2011-05-19 10:40 ` [RFC PATCH 2/2] network-registration.c: implement CIND for Telit UC864-G Bernhard.Guillon
2011-05-19 17:51   ` Marcel Holtmann
2011-05-19 17:48 ` [RFC PATCH 1/2] Add basic Telit UC864-G support: Marcel Holtmann
2011-05-25 13:01   ` Bernhard Guillon
2011-05-25 16:12     ` Marcel Holtmann

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.