0

I have a problem that confused me for couple of day. I want to send out a data with size bigger than 255 bytes from smartcard to host application. I saw a block of code in some website. this code is like bellow:

private void sendData(APDU apdu) {
        // work out how many bytes to send this time and how many will be left
        BUF_IN_OFFSET[0] = 0;

        short remain = (short) ((short)372 - BUF_IN_OFFSET[0]);
        boolean chain = remain > MAX_APDU;
        short sendLen = chain ? MAX_APDU : remain;
        Util.arrayCopy(data, (short) 0, apdu.getBuffer(), (short) 0, sendLen);
        // Get ready to send
        apdu.setOutgoing();
        apdu.setOutgoingLength((short)sendLen);
        apdu.sendBytesLong(apdu.getBuffer(), BUF_IN_OFFSET[0], sendLen);

         // Check to see if there are more APDU's to send
        if (chain) {
            BUF_IN_OFFSET[0] += sendLen; // count the bytes sent
            remain -=sendLen;
            ISOException.throwIt((short)((ISO7816.SW_BYTES_REMAINING_00) + remain));

        } else {
            BUF_IN_OFFSET[0] = 0; // no more bytes to send
        }


    }

When i send apdu to the card in netbeans simulator, it send 6100 correctly. but when i send it to real card (smartcafe 3.2) card. it send for me 9000. it means in simulator it works but by real card it doesn't work. I guess it related to protocol T=0 or T=1. I didn't find any code for T=1. above code is for T=0.

thanks in advance.

Mohsen Gorgani
  • 420
  • 4
  • 18
  • Wouldn't it be easier to let the host application keep state about the offset? (I.e. provide a `GET LENGTH` instruction, and a `READ BINARY` instruction with offset parameter.) – martijno Oct 23 '13 at 10:08
  • In some cases your comment is true, for example when you want stream of bytes. but in some cases applet does everything for example reading an object which generated on card. – Mohsen Gorgani Oct 23 '13 at 11:13

1 Answers1

0

'6100' sounds like a contradiction in the terms. It tells the reader to fetch some data, with lengh available being naught. I believe the real card will actually turn this into a 9000 which is the proper execution status code when no data is available.

Toluene
  • 751
  • 3
  • 9
  • thanks for reply takumar. I agree with you if there is no data available in card, but i have more data. according to above code all of data is stored in data variable with length 372 bytes. I read 255 bytes in first command and send (ISO7816.SW_BYTES_REMAINING_00 + remained bytes) to host to say that there is more data and how much it's length. then host send get response commands to read remain data. – Mohsen Gorgani Oct 22 '13 at 19:08
  • Why not simply send the whole data block to the card OS to manage, and let it generate 61xx codes for you ? In my opinion this should not have to be coded at application level, because it is a common transport mechanism. – Toluene Oct 23 '13 at 14:48
  • Do you mean i send whole 372 byte in response apdu follow below code: apdu.setOutgoingLength((short)372); apdu.sendBytesLong(data, (short) 0, (short)372); but I try this before and it didn't work and send 6F00 status word. – Mohsen Gorgani Oct 24 '13 at 08:10