Page 1 of 1

proccess() function isn't receive full apdu command from host?

Posted: Tue Dec 08, 2015 3:03 am
by leonard
The host send the command bellow to applet to select EF file:
apdu : "00 A4 02 00 02 40 01".
The purpose is select EF file with ID = "40 01" which specify in data field of the command. But when I debug at process() function, the buffer of apdu only consist 5 first- bytes "00 A4 02 00 02", data field set to "00 00". So my applet can not select the EF using EF ID.
Could you tell me what is wrong in apdu command above? Many thanks

Re: proccess() function isn't receive full apdu command from host?

Posted: Tue Dec 08, 2015 3:34 am
by predators
Perhaps the protocol you are using is T0.

Generally, you need to call setIncomingAndReceive () function. It will help you get as many bytes as will fit without buffer overflow in the APDU buffer following the header. It gets all the incoming bytes if they fit.

You can check your source code and the using protocol.

Re: proccess() function isn't receive full apdu command from host?

Posted: Tue Dec 08, 2015 4:49 am
by leonard
predators wrote:Perhaps the protocol you are using is T0.

Generally, you need to call setIncomingAndReceive () function. It will help you get as many bytes as will fit without buffer overflow in the APDU buffer following the header. It gets all the incoming bytes if they fit.

You can check your source code and the using protocol.


Thanks for your help!
In process() function, I call apdu.setIncomingAndReceive(). It get as many bytes as fit without buffer as you said. My applet successful select EF.

But could you help me solve one more problem?
After select EF, host send command bellow to read record "0x10" with "0x05" byte length of current EF.
command: 00 B2 10 04 05

Applet suppose to call readRecord() function when receive this command.
But in process() function, applet just run to setIncomingAndReceive() then don't run any more, don't return any SW bytes and also don't call readRecord() function.
When I comment out setIncomingAndReceive() function, it work and execute the readRecord() function.

Re: proccess() function isn't receive full apdu command from host?

Posted: Tue Dec 08, 2015 5:07 am
by UNKNwYSHSA
This method APDU.setIncomingAndReceive() should only be called on a case 3 or case 4 command.
The command "00 B2 10 04 05" is case 2.
So you need not invoke this method in this command processing.

Re: proccess() function isn't receive full apdu command from host?

Posted: Tue Dec 08, 2015 5:13 am
by UNKNwYSHSA
The code is as following:

Code: Select all

byte ins = buf[ISO7816.OFFSET_INS];
switch (ins)
{
    case (byte)0xA4:
    {
        short lc = apdu.setIncomingAndReceive(...);
        // Command processing;
        // ...;
    } break;
    case (byte)0xB2:
    {
        // Command processing;
        // ...;
    } break;

}

Notice: When you coding, you must understand CASE of the APDU command which you are coding for.