Package org.nfctools.mf.block

Examples of org.nfctools.mf.block.TrailerBlock


    ApplicationDirectory applicationDirectory = readerWriter.getApplicationDirectory();
    Application application = applicationDirectory.openApplication(testAppId);
    application.updateTrailer(KEY_VALUE_B, testNdefTrailerBlock);

    TrailerBlock readTrailer = application.readTrailer(KEY_VALUE_B);
    assertArrayEquals(testNdefTrailerBlock.getAccessConditions(), readTrailer.getAccessConditions());

  }
View Full Code Here


      for (int slot = firstSlot; slot <= lastSlot; slot++) {
        int sectorId = mad.getSectorIdForSlot(slot);
        MfClassicAccess access = new MfClassicAccess(keyValue, sectorId,
            memoryLayout.getTrailerBlockNumberForSector(sectorId));

        TrailerBlock block = (TrailerBlock)readerWriter.readBlock(access)[0];
        if (trailerBlock == null) {
          trailerBlock = block;
        }
        else {
          if (!Arrays.equals(block.getAccessConditions(), trailerBlock.getAccessConditions())
              || (block.getGeneralPurposeByte() != trailerBlock.getGeneralPurposeByte()))
            throw new NfcException(
                "Not all trailer blocks are equal for the APP-ID. Somebody tempered with the tag.");
        }

      }
View Full Code Here

      applicationDirectory = MadUtils.getApplicationDirectory(card, readerWriter, writeKeyValue);
    else
      applicationDirectory = MadUtils.createApplicationDirectory(card, readerWriter, createKey, createKeyValue,
          writeKeyValue);

    TrailerBlock trailerBlock = createNdefTrailerBlock();

    if (applicationDirectory.hasApplication(MfNdefConstants.NDEF_APP_ID)) {
      applicationDirectory.deleteApplication(MfNdefConstants.NDEF_APP_ID, deleteKeyValue, new TrailerBlock());
    }

    byte[] tlvWrappedNdefData = wrapNdefMessageWithTlv(ndefData, applicationDirectory.getMaxContinousSize());

    /*
 
View Full Code Here

    application.write(new KeyValue(Key.B, writeKeyValue), tlvWrappedNdefData);
  }

  private TrailerBlock createNdefTrailerBlock() throws MfException {
    TrailerBlock trailerBlock = new TrailerBlock();
    trailerBlock.setKey(Key.A, MfConstants.NDEF_KEY);
    trailerBlock.setKey(Key.B, writeKeyValue);
    trailerBlock.setAccessConditions(MfConstants.NDEF_READ_WRITE_ACCESS_CONDITIONS);
    trailerBlock.setGeneralPurposeByte(MfConstants.NDEF_GPB_V10_READ_WRITE);
    return trailerBlock;
  }
View Full Code Here

  public static ApplicationDirectory getApplicationDirectory(MfCard card, MfReaderWriter readerWriter,
      byte[] writeKeyValue) throws IOException {

    SimpleMfAccess simpleMfAccess = new SimpleMfAccess(card, Key.A, MadConstants.DEFAULT_MAD_KEY);

    TrailerBlock madTrailer = (TrailerBlock)readerWriter.readBlock(new MfAccess(simpleMfAccess, 0, card
        .getTrailerBlockNumberForSector(0), 1))[0];

    if ((madTrailer.getGeneralPurposeByte() & MadConstants.GPB_MAD_AVAILABLE) != 0) {
      if ((madTrailer.getGeneralPurposeByte() & MadConstants.GPB_MAD_V1) == MadConstants.GPB_MAD_V1) {
        madTrailer.setKey(Key.A, MadConstants.DEFAULT_MAD_KEY);
        if (writeKeyValue != null)
          madTrailer.setKey(Key.B, writeKeyValue);
        Mad1 mad1 = new Mad1(null, null);
        mad1.readMad();
        if (writeKeyValue == null)
          mad1.setReadonly();
        return mad1;
      }
      else if ((madTrailer.getGeneralPurposeByte() & MadConstants.GPB_MAD_V2) == MadConstants.GPB_MAD_V2) {
        madTrailer.setKey(Key.A, MadConstants.DEFAULT_MAD_KEY);
        if (writeKeyValue != null)
          madTrailer.setKey(Key.B, writeKeyValue);
        Mad2 mad = new Mad2(null, null);
        mad.readMad();
        if (writeKeyValue == null)
          mad.setReadonly();
        return mad;
View Full Code Here

  @Override
  public boolean hasApplicationDirectory() throws IOException {
    try {
      MfClassicAccess access = new MfClassicAccess(MfClassicConstants.MAD_KEY, 0,
          memoryLayout.getTrailerBlockNumberForSector(0));
      TrailerBlock madTrailer = (TrailerBlock)readBlock(access)[0];
      return ((madTrailer.getGeneralPurposeByte() & MadConstants.GPB_MAD_AVAILABLE) != 0);
    }
    catch (MfLoginException e) {
      return false;
    }
  }
View Full Code Here

  @Deprecated
  public static boolean hasApplicationDirectory(MfCard card, MfReaderWriter readerWriter) throws IOException {
    try {
      SimpleMfAccess simpleMfAccess = new SimpleMfAccess(card, Key.A, MadConstants.DEFAULT_MAD_KEY);

      TrailerBlock madTrailer = (TrailerBlock)readerWriter.readBlock(new MfAccess(simpleMfAccess, 0, card
          .getTrailerBlockNumberForSector(0), 1))[0];

      return ((madTrailer.getGeneralPurposeByte() & MadConstants.GPB_MAD_AVAILABLE) != 0);
    }
    catch (MfLoginException e) {
      return false;
    }
  }
View Full Code Here

  @Deprecated
  public static ApplicationDirectory createApplicationDirectory(MfCard card, MfReaderWriter readerWriter,
      Key createKey, byte[] createKeyValue, byte[] writeKeyValue) throws IOException {
    if (card instanceof MfCard1k) {
      TrailerBlock trailerBlock = new TrailerBlock();
      trailerBlock.setKey(Key.A, MadConstants.DEFAULT_MAD_KEY);
      trailerBlock.setKey(Key.B, writeKeyValue);
      trailerBlock.setAccessConditions(MadConstants.READ_WRITE_ACCESS_CONDITIONS);
      trailerBlock.setGeneralPurposeByte((byte)(MadConstants.GPB_MAD_AVAILABLE | MadConstants.GPB_MAD_V1));

      MfAccess mfAccess = new MfAccess(card, 0, card.getTrailerBlockNumberForSector(0), createKey, createKeyValue);
      readerWriter.writeBlock(mfAccess, trailerBlock);

      MfAccess mfAccessDataBlock = new MfAccess(card, 0, 1, Key.B, writeKeyValue);
      readerWriter.writeBlock(mfAccessDataBlock, new DataBlock(), new DataBlock());

      Mad1 mad1 = new Mad1(null, null);
      mad1.writeMad();

      return mad1;
    }

    if (card instanceof MfCard4k) {
      TrailerBlock trailerBlock = new TrailerBlock();
      trailerBlock.setKey(Key.A, MadConstants.DEFAULT_MAD_KEY);
      trailerBlock.setKey(Key.B, writeKeyValue);
      trailerBlock.setAccessConditions(MadConstants.READ_WRITE_ACCESS_CONDITIONS);
      trailerBlock.setGeneralPurposeByte((byte)(MadConstants.GPB_MAD_AVAILABLE | MadConstants.GPB_MAD_V2));

      MfAccess mfAccess = new MfAccess(card, 0, card.getTrailerBlockNumberForSector(0), createKey, createKeyValue);
      readerWriter.writeBlock(mfAccess, trailerBlock);

      MfAccess mfAccessDataBlock = new MfAccess(card, 0, 1, Key.B, writeKeyValue);
View Full Code Here

    trailerBlock.setGeneralPurposeByte((byte)(MadConstants.GPB_NDEF_CONFIG | madVersion));
    writeTrailer(mad1SectorId, trailerBlock);
  }

  protected TrailerBlock createTrailer(byte[] writeKeyValue) throws MfException {
    TrailerBlock trailerBlock = new TrailerBlock();
    trailerBlock.setKey(Key.A, MadConstants.DEFAULT_MAD_KEY);
    trailerBlock.setKey(Key.B, writeKeyValue);
    trailerBlock.setAccessConditions(MadConstants.READ_WRITE_ACCESS_CONDITIONS);
    return trailerBlock;
  }
View Full Code Here

TOP

Related Classes of org.nfctools.mf.block.TrailerBlock

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.