Project

General

Profile

Actions

Bug #1828

closed

"RuntimeError: SW match failed ! Expected 9000 and got 6b00"

Added by neels over 7 years ago. Updated almost 7 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
-
Target version:
-
Start date:
10/19/2016
Due date:
% Done:

100%

Spec Reference:

Description

This commit breaks pysim for at least sysmosim-gr1:
https://cgit.osmocom.org/pysim/commit/pySim/commands.py?id=8c1b33c439fef423c3536e9243035722c52aba4c

The question is, should this be non-default with a command line switch?
Should it be applied depending on the sim card type?

Actions #1

Updated by msuraev over 7 years ago

I think it should be applied based on sim card type: without 8c1b33c439fef423c3536e9243035722c52aba4c programming sysmoUSIM-SJS1 is not working.

Actions #2

Updated by msuraev over 7 years ago

Note: with 8c1b33c439fef423c3536e9243035722c52aba4c programming sysmoUSIM-SJS1 works but reading only works without it.

Actions #3

Updated by laforge about 7 years ago

  • Assignee set to dexter
Actions #4

Updated by dexter about 7 years ago

  • Status changed from New to Feedback
  • % Done changed from 0 to 100

I am not entirely sure what the problem really is. I could not find anything about P2=0x0C. The only resource I managed to find is not really USIM/SIM related:
http://www.cardwerk.com/smartcards/smartcard_standard_ISO7816-4_6_basic_interindustry_commands.aspx#table58

However. sysmo-usim-sjs1 seems to require the selection control parameters to be set to P1=0x00, P2=0x0C when USIM commands (CLA=0x00) are used. For the normal SIM commands (CLA=0xA0), P1=0x00, P2=0x00 works fine (As specified). That is also the reason why reading does not work when 8c1b33c439fef423c3536e9243035722c52aba4c is reverted. Because then P1=0x00, P2=0x0C are still in place, but pysim is using SIM commands (CLA=0xA0) and the old SIM style SELECT seems not to support selection control parameters.

I think Neels Idea is correct and this should be handled on a per-card-type basis. By doing so, we also do not risk to break other card types. I have added a setter method to influence the selection control parameter default of the select command. This is done in the same way as we already do it for the class byte (CLA). The SysmoUSIMSJS1 class is then setting the parameters when executing its constructor.

The fix is still on branch pmaier/fixfci, but I can merge it anytime

Actions #5

Updated by neels about 7 years ago

dexter wrote:

I think Neels Idea is correct

correction: it was Max' idea.

I have added a setter method to influence the selection control parameter default of the select command. This is done in the same way as we already do it for the class byte (CLA). The SysmoUSIMSJS1 class is then setting the parameters when executing its constructor.

The fix is still on branch pmaier/fixfci, but I can merge it anytime

Taken a look, the change looks perfect to me. I haven't verified that it works though.

The patch contains an unrelated cosmetic change, but that's because the last line of the file contained no newline. I don't know any editor that omits a final newline, so it's rather hard to not change that. I've pushed a commit adding a final newline, so if you rebase your branch onto master, this change will vanish.

+1 for merging your branch.

Actions #6

Updated by laforge about 7 years ago

On Tue, Mar 21, 2017 at 11:39:50AM +0000, dexter [REDMINE] wrote:

I am not entirely sure what the problem really is. I could not find
anything about P2=0x0C.

Please see the base specification of all ETSI smart cards (upon which
the USIM application spec builds, and which is also referenced in the
USIM manual as well as the libosmocore/src/sim/* source code: ETSI TS
102 221 Section 11.1.1 (SELECT) Table 11.2 which states 0--011-- (which
means basically 0x0C) for "return FCP template" and the comment below: "

However. sysmo-usim-sjs1 seems to require the selection control
parameters to be set to P1=0x00, P2=0x0C when USIM commands (CLA=0x00)
are used.

From the above spec:

If P1 = '00' and the data field is empty, then P2 shall be set to '0C'
('No data returned'). Then the MF is set as the Current Directory.

So I think the sysmoUSIM-SJS1 expects exactly what the spec states
above.

For the normal SIM commands (CLA=0xA0), P1=0x00, P2=0x00
works fine (As specified). That is also the reason why reading does
not work when 8c1b33c439fef423c3536e9243035722c52aba4c is reverted.
Because then P1=0x00, P2=0x0C are still in place, but pysim is using
SIM commands (CLA=0xA0) and the old SIM style SELECT seems not to
support selection control parameters.

Which (I believe) is also correct. So it appears a pySim bug / spec
violation, and it's pure accident it works on other cards? Do you agree?

The fix is still on branch pmaier/fixfci, but I can merge it anytime

I suggest you submit this for review to the openbsc mailing list using
git send-email - that's what we do with all projects that are not in
gerrit yet.

tnt: Maybe it's time to move pysim to gerrit, too?

Actions #7

Updated by tnt about 7 years ago

Sure.

And honestly if someone wants to take over, be my guest. I originally wrote pysim as a quick tool for me to program the cheap chinese SIM, so spec compliance wasn't exactly my priority there. And I don't even have most of the card supported by it nowadays so I can't even test most of the changes.

Actions #8

Updated by dexter about 7 years ago

The patches are now in the review process:

https://gerrit.osmocom.org/2174 Fix select control parameter
https://gerrit.osmocom.org/2175 fix writing of ICCID for sysmo-usim-sjs1

Actions #9

Updated by dexter about 7 years ago

  • Status changed from Feedback to Resolved
Actions #10

Updated by laforge almost 7 years ago

  • Status changed from Resolved to Closed
Actions

Also available in: Atom PDF

Add picture from clipboard (Maximum size: 48.8 MB)