Package org.nfctools.mf.mad

Examples of org.nfctools.mf.mad.ApplicationDirectory


    }
  }

  private Application getApplication() {
    try {
      ApplicationDirectory applicationDirectory = readerWriter.getApplicationDirectory(new MadKeyConfig(Key.A,
          writeKey, writeKey));
      Application application = applicationDirectory.openApplication(MfConstants.NDEF_APP_ID);
      return application;
    }
    catch (IOException e) {
      throw new NfcException(e);
    }
View Full Code Here


    formatted = true;
  }

  private Application createNewApplication() {
    try {
      ApplicationDirectory applicationDirectory = readerWriter.createApplicationDirectory(new MadKeyConfig(Key.A,
          MfConstants.TRANSPORT_KEY, writeKey));
      TrailerBlock readWriteTrailerBlock = ClassicHandler.createReadWriteDataTrailerBlock();
      readWriteTrailerBlock.setKey(Key.A, writeKey);
      readWriteTrailerBlock.setKey(Key.B, writeKey);
      Application application = applicationDirectory.createApplication(MfConstants.NDEF_APP_ID,
          applicationDirectory.getMaxContinousSize(), writeKey, readWriteTrailerBlock);
      return application;
    }
    catch (IOException e) {
      throw new NfcException(e);
    }
View Full Code Here

    MfClassicReaderWriter readerWriter = new AcrMfClassicReaderWriter(tag, memoryLayout);
    TagInfo tagInfo = null;
    try {
      tagInfo = readerWriter.getTagInfo();
      if (readerWriter.hasApplicationDirectory()) {
        ApplicationDirectory applicationDirectory = readerWriter.getApplicationDirectory();
        if (applicationDirectory.hasApplication(MfConstants.NDEF_APP_ID)) {
          formatted = true;
          Application application = applicationDirectory.openApplication(MfConstants.NDEF_APP_ID);
          writable = ClassicHandler.isFormattedWritable(application, MfClassicConstants.NDEF_KEY);
        }
        else {
          throw new NfcException("Unknown tag contents");
        }
View Full Code Here

        MemoryLayout.CLASSIC_4K)));
  }

  @Test
  public void testIsFormattedWritable() throws Exception {
    ApplicationDirectory applicationDirectory = ReaderWriterCreator.createReadWriter("mfstd1k_ndef.txt",
        MemoryLayout.CLASSIC_1K).getApplicationDirectory();
    assertTrue(ClassicHandler.isFormattedWritable(applicationDirectory.openApplication(MfConstants.NDEF_APP_ID),
        MfClassicConstants.TRANSPORT_KEY));
    ApplicationDirectory applicationDirectory2 = ReaderWriterCreator.createReadWriter("mfstd4k_ndef.txt",
        MemoryLayout.CLASSIC_4K).getApplicationDirectory();
    assertTrue(ClassicHandler.isFormattedWritable(applicationDirectory2.openApplication(MfConstants.NDEF_APP_ID),
        MfClassicConstants.NDEF_KEY));
  }
View Full Code Here

    writeNdefMessage(card, ndefData);
  }

  private void writeNdefMessage(MfCard card, byte[] ndefData) throws IOException, MfException {
    ApplicationDirectory applicationDirectory = null;

    if (MadUtils.hasApplicationDirectory(card, readerWriter))
      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());

    /*
     * The specs states that the TLV terminator can be left out if the message ends with the available space.
     * One might want to check if the available size on the card is one byte less than the tlv wrapped message. If
     * it is the case the TLV terminator could be removed.
     */
    Application application = applicationDirectory.createApplication(MfNdefConstants.NDEF_APP_ID,
        tlvWrappedNdefData.length, writeKeyValue, trailerBlock);

    if (log.isDebugEnabled())
      log.debug("Length: " + tlvWrappedNdefData.length + " [" + NfcUtils.convertBinToASCII(tlvWrappedNdefData)
          + "]");
View Full Code Here

  public List<Record> readNdefMessage(MfCard card) throws IOException {

    if (!MadUtils.hasApplicationDirectory(card, readerWriter))
      throw new NdefException("unknown service type");

    ApplicationDirectory applicationDirectory = MadUtils.getApplicationDirectory(card, readerWriter);

    if (applicationDirectory.hasApplication(MfNdefConstants.NDEF_APP_ID)) {

      Application application = applicationDirectory.openApplication(MfNdefConstants.NDEF_APP_ID);

      byte[] tlvWrappedNdefMessage = application.read(new KeyValue(Key.A, MfConstants.NDEF_KEY));

      if (log.isDebugEnabled())
        log.debug(NfcUtils.convertBinToASCII(tlvWrappedNdefMessage));
View Full Code Here

TOP

Related Classes of org.nfctools.mf.mad.ApplicationDirectory

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.