Package org.nfctools.scio

Examples of org.nfctools.scio.Command


    this.apduTag = apduTag;
  }

  @Override
  public void write(byte[] data, int offset, int length) throws IOException {
    Command command = new Command(data, offset, length);
    Response response = apduTag.transmit(command);
    responseData = response.getData();
    if (!response.isSuccess())
      throw new ApduException("Error sending message [" + NfcUtils.convertBinToASCII(data) + "] (" + offset + ","
          + length + ") => [SW1: " + response.getSw1() + ", SW2:" + response.getSw2() + ", Data: "
View Full Code Here


    byte blockNumber;
    loginIntoSector(access);
    MfBlock[] returnBlocks = new Block[access.getBlocksToRead()];
    for (int currentBlock = 0; currentBlock < access.getBlocksToRead(); currentBlock++) {
      blockNumber = (byte)memoryLayout.getBlockNumber(access.getSector(), access.getBlock() + currentBlock);
      Command readBlock = new Command(Apdu.INS_READ_BINARY, 0x00, blockNumber, 16);
      Response readBlockResponse;
      readBlockResponse = apduTag.transmit(readBlock);
      if (!readBlockResponse.isSuccess()) {
        throw new MfException("Reading block failed. Sector: " + access.getSector() + ", Block: "
            + access.getBlock() + " Key: " + access.getKeyValue().getKey().name() + ", Response: "
View Full Code Here

      int blockNumber = memoryLayout.getBlockNumber(access.getSector(), access.getBlock()) + currentBlock;
      if (memoryLayout.isTrailerBlock(access.getSector(), access.getBlock() + currentBlock)) {
        if (!(mfBlock[currentBlock] instanceof TrailerBlock))
          throw new MfException("invalid block for trailer");
      }
      Command writeBlock = new Command(Apdu.INS_UPDATE_BINARY, 0x00, blockNumber, mfBlock[currentBlock].getData());
      Response writeBlockResponse;
      writeBlockResponse = apduTag.transmit(writeBlock);
      if (!writeBlockResponse.isSuccess()) {
        throw new MfException("Writing block failed. Sector: " + access.getSector() + ", Block: "
            + access.getBlock() + " Key: " + access.getKeyValue().getKey().name() + ", Response: "
View Full Code Here

   * @param access
   * @throws IOException
   */
  private int loadAccessKey(MfClassicAccess access) throws IOException {
    int memoryKeyId = loginKeyHandler.getNextKeyPosition();
    Command loadKey = new Command(Apdu.INS_EXTERNAL_AUTHENTICATE, Acs.P1_LOAD_KEY_INTO_VOLATILE_MEM, memoryKeyId,
        access.getKeyValue().getKeyValue());
    Response loadKeyResponse = apduTag.transmit(loadKey);
    if (!loadKeyResponse.isSuccess()) {
      throw new MfLoginException("Loading key failed. Sector: " + access.getSector() + ", Block: "
          + access.getBlock() + " Key: " + access.getKeyValue().getKey().name() + ", Response: "
View Full Code Here

  }

  private void loginIntoSector(MfClassicAccess access, int memoryKeyId) throws IOException {
    byte blockNumber = (byte)memoryLayout.getBlockNumber(access.getSector(), access.getBlock());
    byte keyTypeToUse = access.getKeyValue().getKey() == Key.A ? Acs.KEY_A : Acs.KEY_B;
    Command auth = new Command(Apdu.INS_INTERNAL_AUTHENTICATE_ACS, 0, 0, new byte[] { 0x01, 0x00, blockNumber,
        keyTypeToUse, (byte)memoryKeyId });
    Response authResponse = apduTag.transmit(auth);
    if (!authResponse.isSuccess()) {
      loginKeyHandler.resetCurrentKeys();
      throw new MfLoginException("Login failed. Sector: " + access.getSector() + ", Block: " + access.getBlock()
View Full Code Here

  @Override
  public MfBlock[] readBlock(int startPage, int pagesToRead) throws IOException {
    MfBlock[] returnBlocks = new MfBlock[pagesToRead];
    for (int currentPage = 0; currentPage < pagesToRead; currentPage++) {
      int pageNumber = startPage + currentPage;
      Command readBlock = new Command(Apdu.INS_READ_BINARY, 0x00, pageNumber, 4);
      Response readBlockResponse = tag.transmit(readBlock);
      if (!readBlockResponse.isSuccess()) {
        throw new MfException("Reading block failed. Page: " + pageNumber + ", Response: " + readBlockResponse);
      }
      returnBlocks[currentPage] = new DataBlock(readBlockResponse.getData());
View Full Code Here

  @Override
  public void writeBlock(int startPage, MfBlock... mfBlock) throws IOException {
    for (int currentBlock = 0; currentBlock < mfBlock.length; currentBlock++) {
      int blockNumber = startPage + currentBlock;
      Command writeBlock = new Command(Apdu.INS_UPDATE_BINARY, 0x00, blockNumber, mfBlock[currentBlock].getData());
      Response writeBlockResponse = tag.transmit(writeBlock);
      if (!writeBlockResponse.isSuccess()) {
        throw new MfException("Writing block failed. Page: " + blockNumber + ", Response: "
            + writeBlockResponse);
      }
View Full Code Here

TOP

Related Classes of org.nfctools.scio.Command

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.