Skip to contentSkip to conversation

Add AT driver for STK atom.

PATCH In review Andrzej Zaborowski 3 participants 8 messages Apr 9, 2010 – Apr 20, 2010 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 7/8 Add AT driver for STK atom.

---
 Makefile.am               |    1 +
 drivers/atmodem/atmodem.c |    2 +
 drivers/atmodem/atmodem.h |    3 +
 drivers/atmodem/stk.c     |  258 +++++++++++++++++++++++++++++++++++++++++++++
 plugins/atgen.c           |    2 +
 plugins/phonesim.c        |    3 +
 6 files changed, 269 insertions(+), 0 deletions(-)
 create mode 100644 drivers/atmodem/stk.c
Makefile.am +1 -0
index 7a18c41..a506dba 100644
@@ -124,6 +124,7 @@ builtin_sources += $(gatchat_sources) \
 				drivers/atmodem/call-meter.c \
 				drivers/atmodem/network-registration.c \
 				drivers/atmodem/sim.c \
+				drivers/atmodem/stk.c \
 				drivers/atmodem/ussd.c \
 				drivers/atmodem/voicecall.c \
 				drivers/atmodem/call-barring.c \
drivers/atmodem/atmodem.c +2 -0
index 0ac8182..c88f6b2 100644
@@ -45,6 +45,7 @@ static int atmodem_init(void)
 	at_ussd_init();
 	at_sms_init();
 	at_sim_init();
+	at_stk_init();
 	at_netreg_init();
 	at_cbs_init();
 	at_call_volume_init();
@@ -56,6 +57,7 @@ static int atmodem_init(void)
 
 static void atmodem_exit(void)
 {
+	at_stk_exit();
 	at_sim_exit();
 	at_sms_exit();
 	at_ussd_exit();
drivers/atmodem/atmodem.h +3 -0
index 1fb4bfa..2ee47f5 100644
@@ -45,6 +45,9 @@ extern void at_call_barring_exit();
 extern void at_sim_init();
 extern void at_sim_exit();
 
+extern void at_stk_init();
+extern void at_stk_exit();
+
 extern void at_sms_init();
 extern void at_sms_exit();
 
drivers/atmodem/stk.c new file +258 -0

258 lines not on this page · raw message

plugins/atgen.c +2 -0
index ed963c2..262d32f 100644
@@ -43,6 +43,7 @@
 #include <ofono/netreg.h>
 #include <ofono/phonebook.h>
 #include <ofono/sim.h>
+#include <ofono/stk.h>
 #include <ofono/sms.h>
 #include <ofono/ssn.h>
 #include <ofono/ussd.h>
@@ -163,6 +164,7 @@ static void atgen_pre_sim(struct ofono_modem *modem)
 	ofono_devinfo_create(modem, 0, "atmodem", chat);
 	sim = ofono_sim_create(modem, 0, "atmodem", chat);
 	ofono_voicecall_create(modem, 0, "atmodem", chat);
+	ofono_stk_create(modem, 0, "atmodem", chat);
 
 	if (sim)
 		ofono_sim_inserted_notify(sim, TRUE);
plugins/phonesim.c +3 -0
index 4c3b3ce..9153e1b 100644
@@ -50,6 +50,7 @@
 #include <ofono/netreg.h>
 #include <ofono/phonebook.h>
 #include <ofono/sim.h>
+#include <ofono/stk.h>
 #include <ofono/sms.h>
 #include <ofono/ssn.h>
 #include <ofono/ussd.h>
@@ -289,6 +290,8 @@ static void phonesim_pre_sim(struct ofono_modem *modem)
 	else
 		ofono_voicecall_create(modem, 0, "atmodem", data->chat);
 
+	ofono_stk_create(modem, 0, "atmodem", data->chat);
+
 	if (sim)
 		ofono_sim_inserted_notify(sim, TRUE);
 }
Signature · 1 line
1.6.1
#1 lore raw

Hi Andrew,

Quoted 10 lines
---
 Makefile.am               |    1 +
 drivers/atmodem/atmodem.c |    2 +
 drivers/atmodem/atmodem.h |    3 +
 drivers/atmodem/stk.c     |  258
 +++++++++++++++++++++++++++++++++++++++++++++ plugins/atgen.c           | 
   2 +
 plugins/phonesim.c        |    3 +
 6 files changed, 269 insertions(+), 0 deletions(-)
 create mode 100644 drivers/atmodem/stk.c

I did apply the patch, however I have a question:

The terminal response goes something like this:

drivers/atmodem/stk.c line 192

Quoted 7 lines
drivers/atmodem/stk.c new file +7 -0
+
+	len = sprintf(buf, "AT+CSIM=%i,A0140000%02hhX",
+			10 + length * 2, length);
+
+	for (; length; length--)
+		len += sprintf(buf + len, "%02hhX", *value++);
+

In the new stk envelope code it goes something like this:

drivers/atmodem/stk.c line 110

Quoted 8 lines
drivers/atmodem/stk.c new file +7 -0
+	len = sprintf(buf, "AT+CSIM=%i,A0C20000%02hhX",
+			12 + length * 2, length);
+
+	for (; length; length--)
+		len += sprintf(buf + len, "%02hhX", *command++);
+
+	len += sprintf(buf + len, "FF");

What is the point of this last 'FF'? The code removed from the sim atom driver doesn't have it either...

Regards,
-Denis

#2 lore raw

Hi Denis,

Quoted 13 lines · Denis Kenzior

The terminal response goes something like this:

drivers/atmodem/stk.c line 192

Quoted 7 lines
drivers/atmodem/stk.c new file +7 -0
+
+     len = sprintf(buf, "AT+CSIM=%i,A0140000%02hhX",
+                     10 + length * 2, length);
+
+     for (; length; length--)
+             len += sprintf(buf + len, "%02hhX", *value++);
+

In the new stk envelope code it goes something like this:

Quoted 1 line
Quoted 10 lines

drivers/atmodem/stk.c line 110

Quoted 7 lines

+     len = sprintf(buf, "AT+CSIM=%i,A0C20000%02hhX",
+                     12 + length * 2, length);

drivers/atmodem/stk.c new file +5 -0
+
+     for (; length; length--)
+             len += sprintf(buf + len, "%02hhX", *command++);
+
+     len += sprintf(buf + len, "FF");

What is the point of this last 'FF'?  The code removed from the sim atom driver doesn't have it either...

Rereading the etsi ts102.221 the "Le" field in the Envelope APDU (11.2.2.2) is not explictly defined "not present", instead it says "empty or maximum length of expected data". It doesn't say what the default value is when empty so I conclude it's safer to have the field present or the card may think it's not allowed to send any response at all -- depending on the implementer's interpretation of the spec.

10.1.6 says the field is the maximum respose length expected, but then some commands suggest it should be the exact length wanted and some make the field obligatory.

Regards

#3 lore raw

Hi Andrew,

Quoted 31 lines

Hi Denis,

Quoted 10 lines · Denis Kenzior

The terminal response goes something like this:

drivers/atmodem/stk.c line 192

Quoted 7 lines
drivers/atmodem/stk.c new file +7 -0
+
+     len = sprintf(buf, "AT+CSIM=%i,A0140000%02hhX",
+                     10 + length * 2, length);
+
+     for (; length; length--)
+             len += sprintf(buf + len, "%02hhX", *value++);
+

In the new stk envelope code it goes something like this:

Quoted 10 lines

drivers/atmodem/stk.c line 110

Quoted 7 lines
drivers/atmodem/stk.c new file +7 -0
+     len = sprintf(buf, "AT+CSIM=%i,A0C20000%02hhX",
+                     12 + length * 2, length);
+
+     for (; length; length--)
+             len += sprintf(buf + len, "%02hhX", *command++);
+
+     len += sprintf(buf + len, "FF");

What is the point of this last 'FF'? The code removed from the sim atom driver doesn't have it either...

Rereading the etsi ts102.221 the "Le" field in the Envelope APDU (11.2.2.2) is not explictly defined "not present", instead it says "empty or maximum length of expected data". It doesn't say what the default value is when empty so I conclude it's safer to have the field present or the card may think it's not allowed to send any response at all -- depending on the implementer's interpretation of the spec.

Quoted 3 lines

10.1.6 says the field is the maximum respose length expected, but then some commands suggest it should be the exact length wanted and some make the field obligatory.

So I re-read that part of the spec, and I can see why we might want it. However, this quote seemed rather interesting: "Le set to '00' indicates that the terminal expects to receive at most the maximum number of bytes, i.e. 256, in the response ADPU. The UICC may return any number of bytes in the range 1 to 256."

Shouldn't that 'FF' be changed to '00'? Also, you might want to include the relevant passage or Spec/Section reference in this code so we don't wonder where it came from in the future.

Regards,
-Denis

#4 lore raw

Hi,

Quoted 17 lines · Denis Kenzior
Quoted 10 lines

Rereading the etsi ts102.221 the "Le" field in the Envelope APDU (11.2.2.2) is not explictly defined "not present", instead it says "empty or maximum length of expected data".  It doesn't say what the default value is when empty so I conclude it's safer to have the field present or the card may think it's not allowed to send any response at all -- depending on the implementer's interpretation of the spec.

10.1.6 says the field is the maximum respose length expected, but then some commands suggest it should be the exact length wanted and some make the field obligatory.

So I re-read that part of the spec, and I can see why we might want it. However, this quote seemed rather interesting: "Le set to '00' indicates that the terminal expects to receive at most the maximum number of bytes, i.e. 256, in the response ADPU. The UICC may return any number of bytes in the range 1 to 256."

Quoted 3 lines

Shouldn't that 'FF' be changed to '00'?  Also, you might want to include the relevant passage or Spec/Section reference in this code so we don't wonder where it came from in the future.

Attached patch adds a comment and changes the FF to 00. I guess it is largely theoretical right now. The issue again with "any number of bytes in the range 1 to 256" is that this prohibits an empty response,
which we want to allow too :) Maybe this should be a parameter of
driver->envelope()

Best regards

From 78cd3b4882647a6c42f53572de1423d11464e342 Mon Sep 17 00:00:00 2001
From: Andrzej Zaborowski <[email protected]>
Date: Tue, 20 Apr 2010 09:43:40 +0200
Subject: Comment on the Le field in ENVELOPE apdu.

---
 drivers/atmodem/stk.c |   14 +++++++++++++-
 1 files changed, 13 insertions(+), 1 deletions(-)
drivers/atmodem/stk.c +13 -1
index 8cff4a2..cc02a8e 100644
@@ -107,7 +107,19 @@ static void at_stk_envelope(struct ofono_stk *stk, int length,
 	for (; length; length--)
 		len += sprintf(buf + len, "%02hhX", *command++);
 
-	len += sprintf(buf + len, "FF");
+	/* We append the "Le" field.  ETSI ts102.221 is not very clear
+	 * on whether it's mandatory, so stay on the safe side.
+	 * Relevant sections:
+	 * 10.1.6 defines "Le" as optional, doesn't say whether absence
+	 * means no answer is wanted or only that it can have any
+	 * length.  If present the response data should consist of Le bytes.
+	 * Then suggests "00" allows any length between 1 and 256 bytes.
+	 * 11.2.2.2 says "Le" can be "empty" but again doesn't say what
+	 * value is assumed in this case.  If not "empty" the response
+	 * should consist of Le or fewer bytes.  This suggests we should
+	 * use "FF" as the value.
+	 */
+	len += sprintf(buf + len, "00");
 
 	ret = g_at_chat_send(sd->chat, buf, csim_prefix,
 				at_csim_envelope_cb, cbd, g_free);
Signature · 1 line
1.6.1
#5 lore raw

Hi Andrew,

Quoted 10 lines
Quoted 9 lines

So I re-read that part of the spec, and I can see why we might want it. However, this quote seemed rather interesting: "Le set to '00' indicates that the terminal expects to receive at most the maximum number of bytes, i.e. 256, in the response ADPU. The UICC may return any number of bytes in the range 1 to 256."

Shouldn't that 'FF' be changed to '00'? Also, you might want to include the relevant passage or Spec/Section reference in this code so we don't wonder where it came from in the future.

Quoted 5 lines

Attached patch adds a comment and changes the FF to 00. I guess it is largely theoretical right now. The issue again with "any number of bytes in the range 1 to 256" is that this prohibits an empty response,
which we want to allow too :) Maybe this should be a parameter of
driver->envelope()

"The maximum number of bytes expected in the data part of the response APDU is presented in the parameter Le, which is optional. This means that if the terminal does not expect any data in the response APDU Le is absent from the command"

The question really becomes, do we actually want a response and know what to do with it?

Regards,
-Denis

#6 lore raw
Quoted 16 lines · Denis Kenzior
Quoted 10 lines
Quoted 9 lines

So I re-read that part of the spec, and I can see why we might want it. However, this quote seemed rather interesting: "Le set to '00' indicates that the terminal expects to receive at most the maximum number of bytes, i.e. 256, in the response ADPU. The UICC may return any number of bytes in the range 1 to 256."

Shouldn't that 'FF' be changed to '00'?  Also, you might want to include the relevant passage or Spec/Section reference in this code so we don't wonder where it came from in the future.

Quoted 5 lines

Attached patch adds a comment and changes the FF to 00.  I guess it is largely theoretical right now.  The issue again with "any number of bytes in the range 1 to 256" is that this prohibits an empty response, which we want to allow too :)   Maybe this should be a parameter of driver->envelope()

Quoted 4 lines

"The maximum number of bytes expected in the data part of the response APDU is presented in the parameter Le, which is optional. This means that if the terminal does not expect any data in the response APDU Le is absent from the command"

Well, this is an "if" without "only then" so it doesn't tell us the meaning of Le being absent. Additionally the whole passage is later invalidated in 11.2.2.2, so the SIM implementer really has all the possible options.

Quoted 3 lines

The question really becomes, do we actually want a response and know what to do with it?

We only use envelope in CBS data download right now which expects no response, we could indicate that in a parameter.

Best regards

#7 lore raw

Hi Andrew,

Quoted 4 lines

Well, this is an "if" without "only then" so it doesn't tell us the meaning of Le being absent. Additionally the whole passage is later invalidated in 11.2.2.2, so the SIM implementer really has all the possible options.

Hmm, I don't interpret it this way. Le being absent means no response expected. The '00' vs 'FF' is unclear, I agree there.

Quoted 6 lines
Quoted 3 lines

The question really becomes, do we actually want a response and know what to do with it?

We only use envelope in CBS data download right now which expects no response, we could indicate that in a parameter.

I suggest that we mention the Le confusion in the comment block and take out Le altogether since we can't do anything useful with the response data yet. Once we're ready to implement this properly, then we can add Le and figure out wheter 'FF' or '00' or something else is required.

For a hint of what the response can be used for, see 3GPP 31.124. It seems the response from the SIM has to be set into an RP-ERROR message and given back to the network...

Regards,
-Denis