Page 1 of 1

How to let APDU buffer accept 200 bytes of data

Posted: Sat Oct 17, 2015 2:26 am
by Asineshjil
According to the javadoc:
The APDU class maintains a byte array buffer which is used to transfer incoming APDU header and data bytes as well as outgoing data. The buffer length must be at least 133 bytes ( 5 bytes of header and 128 bytes of data ).

I need the buffer read and store the data with length 200 bytes. But the APDU buffer only accepts the first 128 bytes of the data.

What can I do now to let the buffer accept the rest bytes of data?
What is the specific meaning of this sentence "The buffer length must be at least 133 bytes ( 5 bytes of header and 128 bytes of data )."? Hope someone help me out.

Re: How to let APDU buffer accept 200 bytes of data

Posted: Tue Oct 20, 2015 5:46 am
by Larson
To read incoming data more than 128 bytes you may need to call APDU.receiveBytes() to accept the rest vytes of data.

Similarly, for sending data, APDU.sendBytes() might be needed to send longer data.

Re: How to let APDU buffer accept 200 bytes of data

Posted: Tue Oct 20, 2015 6:26 am
by Bob2002

Code: Select all

     /**
     * Processes an incoming APDU.
     * @see APDU
     * @param apdu the incoming APDU
     * @exception ISOException with the response bytes per ISO 7816-4
     */
    public void process(APDU apdu)
    {
        byte buffer[] = apdu.getBuffer();

        short bytesRead = apdu.setIncomingAndReceive();
        short echoOffset = (short)0;

        while ( bytesRead > 0 ) {
            Util.arrayCopyNonAtomic(buffer, ISO7816.OFFSET_CDATA, echoBytes, echoOffset, bytesRead);
            echoOffset += bytesRead;
            bytesRead = apdu.receiveBytes(ISO7816.OFFSET_CDATA);
        }

        apdu.setOutgoing();
        apdu.setOutgoingLength( (short) (echoOffset + 5) );

        // echo header
        apdu.sendBytes( (short)0, (short) 5);
        // echo data
        apdu.sendBytesLong( echoBytes, (short) 0, echoOffset );
    }


Re: How to let APDU buffer accept 200 bytes of data

Posted: Tue Oct 20, 2015 6:35 am
by Bob2002

Code: Select all

       ...
  byte[] buffer = apdu.getBuffer();
  short bytes_left = (short) buffer[ISO.OFFSET_LC];
  short readCount = apdu.setIncomingAndReceive();
  while (bytes_left > 0) {
  // Process received data in buffer; copy chunk to temp buf.
  Util.arrayCopy(buffer, ISO.OFFSET_CDATA, tbuf, 0, readCount);
  bytes_left -= readCount;
  // Get more data
  readCount = apdu.receiveBytes(ISO.OFFSET_CDDATA);
  }
  ...
  

Re: How to let APDU buffer accept 200 bytes of data

Posted: Thu Oct 22, 2015 5:41 am
by Asineshjil
Use these two methods :receiveBytes() and sendBytes() can solve my problem. I got it. Thanks for all the kind help.

Re: How to let APDU buffer accept 200 bytes of data

Posted: Sat Feb 09, 2019 6:27 am
by Hernrye
Use these two methods :receiveBytes() and sendBytes() can solve my problem. I got it. Thanks for all the kind help.

Re: How to let APDU buffer accept 200 bytes of data

Posted: Sat Feb 09, 2019 6:28 am
by Hernrye
Use these two methods :receiveBytes() and sendBytes() can solve my problem. I got it. Thanks for all the kind help.