Package org.nfctools.scio

Examples of org.nfctools.scio.Response


      byte[] transmitControlResponse = card.transmitControlCommand(Acs.IOCTL_SMARTCARD_ACR122_ESCAPE_COMMAND,
          commandAPDU.getBytes());
      ResponseAPDU responseAPDU = new ResponseAPDU(transmitControlResponse);
      if (log.isDebugEnabled())
        log.debug("response: " + NfcUtils.convertBinToASCII(responseAPDU.getBytes()));
      return new Response(responseAPDU.getSW1(), responseAPDU.getSW2(), responseAPDU.getData());
    }
    catch (CardException e) {
      throw new NfcException(e);
    }
  }
View Full Code Here


          commandAPDU.getBytes());
      ResponseAPDU responseAPDU = new ResponseAPDU(transmitControlResponse);
      if (log.isDebugEnabled())
        log.debug("response: " + NfcUtils.convertBinToASCII(responseAPDU.getBytes()));

      return new Response(responseAPDU.getSW1(), responseAPDU.getSW2(), responseAPDU.getData());
    }
    catch (CardException e) {
      throw new NfcException(e);
    }
  }
View Full Code Here

  }

  @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: "
          + NfcUtils.convertBinToASCII(responseData) + "]");
  }
View Full Code Here

    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: "
            + readBlockResponse);
      }
      returnBlocks[currentBlock] = BlockResolver.resolveBlock(memoryLayout, access.getSector(), currentBlock
          + access.getBlock(), readBlockResponse.getData());
    }
    return returnBlocks;
  }
View Full Code Here

      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: "
            + writeBlockResponse);
      }
    }
View Full Code Here

   */
  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: "
          + loadKeyResponse);
    }
    loginKeyHandler.rememberKey(access);
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()
          + " Key: " + access.getKeyValue().getKey().name() + ", Response: " + authResponse);
    }
    else {
View Full Code Here

      if (log.isDebugEnabled())
        log.debug("command: " + NfcUtils.convertBinToASCII(commandAPDU.getBytes()));
      ResponseAPDU responseAPDU = cardChannel.transmit(commandAPDU);
      if (log.isDebugEnabled())
        log.debug("response: " + NfcUtils.convertBinToASCII(responseAPDU.getBytes()));
      return new Response(responseAPDU.getSW1(), responseAPDU.getSW2(), responseAPDU.getData());
    }
    catch (CardException e) {
      throw new NfcException(e);
    }
  }
View Full Code Here

  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());
    }
    return returnBlocks;
  }
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.Response

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.