Package org.nfctools.mf.card

Examples of org.nfctools.mf.card.MfCard


    }
  }

  private void handleMfCard(Card card) throws MfException, IOException {
    CardResolver cardResolver = new CardResolver();
    MfCard mfCard = cardResolver.resolvecard(card);
    this.cardDetected(mfCard, mfReaderWriter);
  }
View Full Code Here


  public boolean waitForCard(int timeout) throws CardException, MfException, IOException, InterruptedException {
    if (cardTerminal.waitForCardPresent(timeout)) {
      Card card = cardTerminal.connect("*");
      CardResolver cardResolver = new CardResolver();
      MfCard mfCard = cardResolver.resolvecard(card);
      cardListener.cardDetected(mfCard, readerWriter);
      return true;
    }
    else
      return false;
View Full Code Here

  private MfCardListener cardListener;

  public MfCard loadCardFromFile(String fileName) throws IOException {
    Collection<String> lines = readLinesFromFile(fileName);

    MfCard mfCard = lines.size() == 256 ? new MfCard4k(null, null) : lines.size() == 64 ? new MfCard1k(null, null)
        : null;
    if (mfCard == null)
      throw new MfException("unknown card. lines " + lines.size());

    BlockResolver blockResolver = new BlockResolver();

    Map<Integer, MfBlock> blockMap = new HashMap<Integer, MfBlock>();
    int blockNumber = 0;
    Pattern pattern = Pattern
        .compile("S(.*)\\|B(.*) Key: (............).*\\[(................................)\\]");

    for (String data : lines) {
      Matcher matcher = pattern.matcher(data);
      if (matcher.matches()) {
        int sectorId = Integer.parseInt(matcher.group(1));
        int blockId = Integer.parseInt(matcher.group(2));
        byte[] keyA = NfcUtils.convertASCIIToBin(matcher.group(3));
        byte[] blockData = NfcUtils.convertASCIIToBin(matcher.group(4));

        MfBlock resolvedBlock = blockResolver.resolveBlock(mfCard, sectorId, blockId, blockData);
        if (mfCard.isTrailerBlock(sectorId, blockId))
          System.arraycopy(keyA, 0, blockData, 0, 6);
        blockMap.put(blockNumber, resolvedBlock);
        blockNumber++;
      }
    }
View Full Code Here

  }

  @Override
  public void reselectCard(MfCard card) throws IOException {
    scanForCard();
    MfCard newcard = readCard();
    if (!NfcUtils.isEqualArray(card.getId(), newcard.getId()))
      throw new MfException("New card detected. Id does not match. (Expected: " + card + ", got: " + newcard
          + ")");
  }
View Full Code Here

  @Override
  public void run() {

    log.debug("Polling started");
    MfCard card = null;
    while (!Thread.interrupted()) {
      try {
        if (nfcReaderWriter.hasData()) {
          log.debug("Reader has data");
          try {
View Full Code Here

TOP

Related Classes of org.nfctools.mf.card.MfCard

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.