Skip to contentSkip to conversation

Add calypsomodem STK driver.

PATCH In review Andrzej Zaborowski 2 participants 2 messages May 7, 2010 – May 10, 2010 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH v2 6/6 Add calypsomodem STK driver.

There is an issue with the atom drivers not running at the time we issue AT+CFUN=1 so if that triggers an important notification, it'll be lost. It could be fixed properly but with major change to initialisation order, instead I added an extra ugly hack to store the initial %SATI notification, please comment if that it too ugly :)

---
 Makefile.am                         |    3 +-
 drivers/calypsomodem/calypsomodem.c |    2 +
 drivers/calypsomodem/calypsomodem.h |    8 +
 drivers/calypsomodem/stk.c          |  304 +++++++++++++++++++++++++++++++++++
 plugins/phonesim.c                  |  127 +++++++++++++--
 5 files changed, 431 insertions(+), 13 deletions(-)
 create mode 100644 drivers/calypsomodem/stk.c
Makefile.am +2 -1
index 7fd862f..8bf3e86 100644
@@ -161,7 +161,8 @@ builtin_modules += calypsomodem
 builtin_sources += drivers/atmodem/atutil.h \
 			drivers/calypsomodem/calypsomodem.h \
 			drivers/calypsomodem/calypsomodem.c \
-			drivers/calypsomodem/voicecall.c
+			drivers/calypsomodem/voicecall.c \
+			drivers/calypsomodem/stk.c
 
 builtin_modules += hfpmodem
 builtin_sources += drivers/atmodem/atutil.h \
drivers/calypsomodem/calypsomodem.c +2 -0
index 8cd213e..2ae436a 100644
@@ -35,12 +35,14 @@
 static int calypsomodem_init(void)
 {
 	calypso_voicecall_init();
+	calypso_stk_init();
 
 	return 0;
 }
 
 static void calypsomodem_exit(void)
 {
+	calypso_stk_exit();
 	calypso_voicecall_exit();
 }
 
drivers/calypsomodem/calypsomodem.h +8 -0
index 80af134..6e6f3ea 100644
@@ -20,6 +20,14 @@
  */
 
 #include <drivers/atmodem/atutil.h>
+#include <modem.h>
+#include <stk.h>
 
 extern void calypso_voicecall_init();
 extern void calypso_voicecall_exit();
+
+extern void calypso_stk_init();
+extern void calypso_stk_exit();
+
+extern void calypsomodem_stk_sati_notify(struct ofono_stk *stk,
+						const guint8 *pdu, gint len);
drivers/calypsomodem/stk.c new file +304 -0

304 lines not on this page · raw message

plugins/phonesim.c +115 -12

183 lines not on this page · raw message

Signature · 1 line
1.6.1
#1 lore raw

Hi Andrew,

Quoted 5 lines

There is an issue with the atom drivers not running at the time we issue AT+CFUN=1 so if that triggers an important notification, it'll be lost. It could be fixed properly but with major change to initialisation order, instead I added an extra ugly hack to store the initial %SATI notification, please comment if that it too ugly :)

What is the proper way? :) Given that SATI needs to be preserved and the contents stored for future reference I agree your proposal is the best way to do it.

Quoted 26 lines
drivers/calypsomodem/stk.c new file +26 -0
+void calypsomodem_stk_sati_notify(struct ofono_stk *stk,
+		const guint8 *pdu, gint len)
+{
+	struct stk_data *sd = ofono_stk_get_data(stk);
+	int length_bytes;
+
+	ofono_stk_proactive_command_notify(stk, len, pdu);
+
+	/* Check if this is a Set Up Menu command, if so, cache the PDU
+	 * because Calypso sends it only once.  */
+
+	while (len > 0 && (*pdu == 0x00 || *pdu == 0xff))
+		pdu++, len--;
+	if (len < 7)
+		return;
+	if (pdu[0] != 0xd0) /* Command BER-TLV tag */
+		return;
+	if (pdu[1] < 0x80)
+		length_bytes = 1;
+	else
+		length_bytes = pdu[1] - 0x7f;
+	if (len < length_bytes + 6)
+		return;
+	if (pdu[1 + length_bytes] != 0x01) /* Command Details CTLV tag */
+		return;
+	if (pdu[2 + length_bytes] != 0x03) /* Command Details CTLV length */

drivers/calypsomodem/stk.c line 200

Quoted 10 lines
drivers/calypsomodem/stk.c new file +10 -0
+		return;
+	if (pdu[4 + length_bytes] != 0x25) /* Set Up Menu command type */
+		return;
+
+	if (sd->set_up_menu_pdu)
+		g_free(sd->set_up_menu_pdu);
+
+	sd->set_up_menu_pdu = g_memdup(pdu, len);
+	sd->set_up_menu_pdu_len = len;
+}

Can we implement SetUp menu command parser or at least use tlv iterators? This is just too ugly.

Quoted 25 lines

struct phonesim_data {

plugins/phonesim.c +10 -0
 	GAtMux *mux;
 	GAtChat *chat;
 	gboolean calypso;
 	gboolean use_mux;
+	gboolean have_sim;
+
+	guint sati_cb_id;
+	unsigned int stk_watch;
+	guint8 *stk_early_pdu;
+	guint stk_early_pdu_len;
 };
 
+static const char *cpin_prefix[] = { "+CPIN:", NULL };
+static const char *none_prefix[] = { NULL };
+
 static int phonesim_probe(struct ofono_modem *modem)
 {
 	struct phonesim_data *data;
@@ -98,13 +109,32 @@ static void phonesim_debug(const char *str, void
 *user_data) ofono_info("%s", str);
 }
 
+static void cpin_check_cb(gboolean ok, GAtResult *result, gpointer
 user_data) +{

plugins/phonesim.c static void phonesim_debug(const char *str, void · line 123

Quoted 10 lines
plugins/phonesim.c +10 -0
+	struct ofono_modem *modem = user_data;
+	struct phonesim_data *data = ofono_modem_get_data(modem);
+
+	DBG("");
+
+	data->have_sim = ok;
+
+	ofono_modem_set_powered(modem, TRUE);
+}
+

Again, looks like this belongs in a separate patch...

Quoted 25 lines
plugins/phonesim.c +24 -0
+static void cfun_enable(struct phonesim_data *data, struct ofono_modem
 *modem) +{
+	/* It looks like the PROFILE DOWNLOAD is done by the modem
+	 * as part of +CFUN=1.  By default the profile indicates that
+	 * TE supports no Proactive UICC.  We need to enable the
+	 * %SATA and other notifications here for STK support and
+	 * give the modem our profile bits (first N bytes) according
+	 * to ETSI TS 102 223 section 5.2.  The modem seems to AND
+	 * the given value with its own capabilities and OR with some
+	 * minimum value.  The bits are reset to the minimal values
+	 * on +CFUN=0.
+	 *
+	 * Default value is 450F80021F0000A4020000000000000000000000.
+	 * The mask is 4DFF973F7F0200FC0303FF00009FFFE700000000.
+	 */
+	g_at_chat_send(data->chat,
+			"AT%SATC=1,\"19E1FFFF0000FF7FFF03FE\"",
+			none_prefix, NULL, NULL);
+
+	/* The initial %SATI notification should arrive together with
+	 * AT+CFUN=1 response, that may be before the STK driver registers
+	 * the notification.  At the same time with Calypso we can't
+	 * lose this first notification or STK will not be
+	 * functional.  This is a hack to save the PDU and supply it
+	 * to STK driver once it's brought up.

plugins/phonesim.c static void phonesim_disconnected(gpointer user_data) · line 236

Quoted 10 lines
plugins/phonesim.c +10 -0
+	 */
+	data->sati_cb_id = g_at_chat_register(data->chat,
+			"%SATI:", sati_notify, FALSE, modem, NULL);
+	data->stk_watch = __ofono_modem_add_atom_watch(modem,
+			OFONO_ATOM_TYPE_STK, stk_watch, modem, NULL);
+
+	g_at_chat_send(data->chat, "AT+CFUN=1",
+			none_prefix, cfun_set_on_cb, modem);
+}
+

Send this part as a separate patch from calypso stk support and SIM inserted changes.

Quoted 37 lines

static void mux_setup(GAtMux *mux, gpointer user_data) {

plugins/phonesim.c +5 -5
 	struct ofono_modem *modem = user_data;
@@ -163,7 +271,7 @@ static void mux_setup(GAtMux *mux, gpointer user_data)
 	if (data->calypso)
 		g_at_chat_set_wakeup_command(data->chat, "AT\r", 500, 5000);
 
-	g_at_chat_send(data->chat, "AT+CFUN=1", NULL, cfun_set_on_cb, modem);
+	cfun_enable(data, modem);
 }
 
 static int phonesim_enable(struct ofono_modem *modem)
@@ -246,8 +354,7 @@ static int phonesim_enable(struct ofono_modem *modem)
 		g_at_chat_unref(data->chat);
 		data->chat = NULL;
 	} else {
-		g_at_chat_send(data->chat, "AT+CFUN=1", NULL,
-					cfun_set_on_cb, modem);
+		cfun_enable(data, modem);
 	}
 
 	return -EINPROGRESS;
@@ -276,20 +383,16 @@ static void phonesim_pre_sim(struct ofono_modem
 *modem) {
 	struct phonesim_data *data = ofono_modem_get_data(modem);
 	struct ofono_sim *sim;
+	const char *drivername = data->calypso ? "calypsomodem" : "atmodem";
 
 	DBG("%p", modem);
 
 	ofono_devinfo_create(modem, 0, "atmodem", data->chat);
 	sim = ofono_sim_create(modem, 0, "atmodem", data->chat);
+	ofono_voicecall_create(modem, 0, drivername, data->chat);
+	ofono_stk_create(modem, 0, drivername, data->chat);
 
-	if (data->calypso)
-		ofono_voicecall_create(modem, 0, "calypsomodem", data->chat);

plugins/phonesim.c static void phonesim_pre_sim(struct ofono_modem · line 398

Quoted 10 lines
plugins/phonesim.c +1 -6
-	else
-		ofono_voicecall_create(modem, 0, "atmodem", data->chat);
-
-	ofono_stk_create(modem, 0, "atmodem", data->chat);
-
-	if (sim)
+	if (data->have_sim && sim)
 		ofono_sim_inserted_notify(sim, TRUE);
 }
 

Regards,
-Denis