This discussion is archived
1 Reply Latest reply: Nov 12, 2012 8:57 AM by fgrieu RSS

APDU LE byte

966781 Newbie
Currently Being Moderated
Hi,

it seems i do not understand the APDU. i want to send 4byte data and receive 2byte. So i sent:

80 01 00 00 04 10 20 30 40 02

The first 4byte are the header. LC is 4 for 4byte data (10 20 30 40) and then the LE byte follows with 02.

But on the card this does not work:
byte[] buffer = apdu.getBuffer();
short length = apdu.setIncomingAndReceive(); // length = 4, thats right

.
.
.

short expectedOutput = apdu.setOutgoing(); // expectedOutput = 256, why ???
Iam not able to receive the LE byte. But in the ISO7816 this case (LC and LE not null) is one of the four cases which has to work with every card. Whats my fault ? :(
  • 1. Re: APDU LE byte
    fgrieu Newbie
    Currently Being Moderated
    I guess your card is using the T=0 protocol.

    Doc for setOutgoing states: "In T=0 (Case 4S) protocol, this method will return 256 with normal semantics."

    So everything is working as designed (I'm not saying: at is should have been designed).

    There is no problem if you know the expected length of the answer (that is the integer Ne, coded by Le) from the spec of the APDU and its input parameters excluding Le, and 0<Ne<256. In that case just set that Nr=Ne using setOutgoingLength and send Nr data bytes with sendBytes. The card will tell Nr to the reader (as part of a conventional status word), some glue code in the bowels of the Java runtime library or application should issue a Get Response command, and everything will be fine. This might work with Ne=256, coded by Le=00h, but do not bet on that without trying.

    There is no problem either if you are happy with the default behavior of truncating the Nr bytes of outgoing data to Ne coded by Le. Just do as above as if you knew Ne was the maximum it could be, and everything will be fine.

    If your in-card applet really needs (rather than know or assume) Ne, one option is to instead change the spec of the APDU and move Ne to P1,P2, or some of the ingoing data where you can get it.

    Else, well... I'd rather not dive into these messy details if the previous three simple options apply.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points