Esempio n. 1
0
  public static DesfireCard dumpTag(Tag tag) throws Exception {
    List<DesfireApplication> apps = new ArrayList<DesfireApplication>();

    IsoDep tech = IsoDep.get(tag);

    tech.connect();

    DesfireManufacturingData manufData;
    DesfireApplication[] appsArray;

    try {
      DesfireProtocol desfireTag = new DesfireProtocol(tech);

      manufData = desfireTag.getManufacturingData();

      for (int appId : desfireTag.getAppList()) {
        desfireTag.selectApp(appId);

        List<DesfireFile> files = new ArrayList<DesfireFile>();

        for (int fileId : desfireTag.getFileList()) {
          try {
            DesfireFileSettings settings = desfireTag.getFileSettings(fileId);
            byte[] data = null;
            if (settings instanceof DesfireFileSettings.StandardDesfireFileSettings)
              data = desfireTag.readFile(fileId);
            else data = desfireTag.readRecord(fileId);
            files.add(DesfireFile.create(fileId, settings, data));
          } catch (TagLostException ex) {
            throw ex;
          } catch (Exception ex) {
            files.add(new DesfireFile.InvalidDesfireFile(fileId, ex.toString()));
          }
        }

        DesfireFile[] filesArray = new DesfireFile[files.size()];
        files.toArray(filesArray);

        apps.add(new DesfireApplication(appId, filesArray));
      }

      appsArray = new DesfireApplication[apps.size()];
      apps.toArray(appsArray);
    } finally {
      if (tech.isConnected()) tech.close();
    }

    return new DesfireCard(tag.getId(), new Date(), manufData, appsArray);
  }
 @Override
 public void onTagDiscovered(Tag tag) {
   IsoDep isoDep = IsoDep.get(tag);
   IsoDepTransceiver transceiver = new IsoDepTransceiver(isoDep, this);
   Thread thread = new Thread(transceiver);
   thread.start();
 }
Esempio n. 3
0
  private byte[] sendRequest(byte command, byte p1, byte p2, byte lc, byte[] parameters)
      throws CEPASException, IOException {
    ByteArrayOutputStream output = new ByteArrayOutputStream();

    byte[] recvBuffer = mTagTech.transceive(wrapMessage(command, p1, p2, lc, parameters));

    if (recvBuffer[recvBuffer.length - 2] != (byte) 0x90) {
      if (recvBuffer[recvBuffer.length - 2] == 0x6b) {
        throw new CEPASException("File " + p1 + " was an invalid file.");

      } else if (recvBuffer[recvBuffer.length - 2] == 0x67) {
        throw new CEPASException("Got invalid file size response.");
      }

      throw new CEPASException(
          "Got generic invalid response: "
              + Integer.toHexString(((int) recvBuffer[recvBuffer.length - 2]) & 0xff));
    }

    output.write(recvBuffer, 0, recvBuffer.length - 2);

    byte status = recvBuffer[recvBuffer.length - 1];
    if (status == OPERATION_OK) {
      return output.toByteArray();
    } else if (status == PERMISSION_DENIED) {
      throw new CEPASException("Permission denied");
    } else {
      throw new CEPASException("Unknown status code: " + Integer.toHexString(status & 0xFF));
    }
  }
 public byte[] getChallenge() {
   byte[] challengeRequest = {(byte) 0x00, (byte) 0x84, (byte) 0x00, (byte) 0x00, (byte) 0x08};
   byte[] challengeResponse = null;
   try {
     challengeResponse = isoDep.transceive(challengeRequest);
     Log.d("challengeResponse", Util.hexString(challengeResponse));
   } catch (IOException e) {
   }
   return challengeResponse;
 }
 public String getPurseData(String purseRequest) {
   byte[] purseByte = Util.hexStringToByteArray(purseRequest.toString());
   String purseData = null;
   try {
     byte[] purseResponse = isoDep.transceive(purseByte);
     purseData = Util.hexString(purseResponse);
     Log.d("PurseData Response", purseData);
   } catch (IOException e) {
   }
   return purseData;
 }
 public byte[] init() {
   byte[] initByte = new byte[8];
   initByte[1] = -92;
   initByte[4] = 2;
   initByte[5] = 64;
   byte[] initRespose = null;
   try {
     initRespose = isoDep.transceive(initByte);
   } catch (IOException e) {
   }
   return initRespose;
 }
 public String getReceipt(String debitCommand, WebserviceConnection wsConnection) {
   String receiptData = null;
   try {
     debitCommand = "90340000" + debitCommand + "00";
     byte[] debitCommandByte = Util.hexStringToByteArray(debitCommand);
     byte[] receiptResponse = isoDep.transceive(debitCommandByte);
     receiptData = Util.hexString(receiptResponse);
   } catch (IOException e) {
     // wsConnection.uploadReceiptData("", new
     // RecieptReqError(StringConstants.ErrorCode.ERROR_CODE_01,
     // StringConstants.ErrorDecription.DEBIT_COMMAND_SUCCESSFUL_BUT_NO_RESPONSE_FROM_CARD));
   }
   return receiptData;
 }
 public String getPurseData() {
   String purseData = null;
   try {
     //		String terminalRN = Util.getRandomHexString(16);
     terminalRN = "CF549C2B7520389C";
     Log.d("terminalRN", terminalRN);
     purseRequest = "903203000A1403" + terminalRN + "00";
     Log.d("Purse Request", purseRequest);
     byte[] purseByte = Util.hexStringToByteArray(purseRequest.toString());
     byte[] purseResponse = isoDep.transceive(purseByte);
     purseData = Util.hexString(purseResponse);
     Log.d("PurseData Response", purseData);
   } catch (IOException e) {
   }
   return purseData;
 }