public static TransitIdentity parseTransitIdentity(Card card) {
   String hex = Utils.getHexString(((ClassicCard) card).getSector(0).getBlock(0).getData(), null);
   String id = hex.substring(0, 8);
   return new TransitIdentity("OV-chipkaart", id);
 }
Exemple #2
0
  public Element toXML() throws Exception {
    Element root = super.toXML();

    Document doc = root.getOwnerDocument();

    Element appsElement = doc.createElement("applications");

    for (DesfireApplication app : mApplications) {
      Element appElement = doc.createElement("application");
      appElement.setAttribute("id", String.valueOf(app.getId()));

      Element filesElement = doc.createElement("files");
      for (DesfireFile file : app.getFiles()) {
        Element fileElement = doc.createElement("file");
        fileElement.setAttribute("id", String.valueOf(file.getId()));

        if (file instanceof InvalidDesfireFile) {
          Element fileDataElement = doc.createElement("error");
          fileDataElement.setTextContent(((InvalidDesfireFile) file).getErrorMessage());
          fileElement.appendChild(fileDataElement);
        } else {
          DesfireFileSettings settings = file.getFileSettings();

          Element fileSettingsElement = doc.createElement("settings");

          Element element = doc.createElement("filetype");
          element.setTextContent(String.valueOf(settings.fileType));
          fileSettingsElement.appendChild(element);

          element = doc.createElement("commsetting");
          element.setTextContent(String.valueOf(settings.commSetting));
          fileSettingsElement.appendChild(element);

          element = doc.createElement("accessrights");
          element.setTextContent(Utils.getHexString(settings.accessRights));
          fileSettingsElement.appendChild(element);

          if (settings instanceof DesfireFileSettings.StandardDesfireFileSettings) {
            int fileSize = ((DesfireFileSettings.StandardDesfireFileSettings) settings).fileSize;
            element = doc.createElement("filesize");
            element.setTextContent(String.valueOf(fileSize));
            fileSettingsElement.appendChild(element);
          } else if (settings instanceof DesfireFileSettings.RecordDesfireFileSettings) {
            int recordSize = ((DesfireFileSettings.RecordDesfireFileSettings) settings).recordSize;
            int maxRecords = ((DesfireFileSettings.RecordDesfireFileSettings) settings).maxRecords;
            int curRecords = ((DesfireFileSettings.RecordDesfireFileSettings) settings).curRecords;

            element = doc.createElement("recordsize");
            element.setTextContent(String.valueOf(recordSize));
            fileSettingsElement.appendChild(element);

            element = doc.createElement("maxrecords");
            element.setTextContent(String.valueOf(maxRecords));
            fileSettingsElement.appendChild(element);

            element = doc.createElement("currecords");
            element.setTextContent(String.valueOf(curRecords));
            fileSettingsElement.appendChild(element);
          } else {
            throw new Exception("Unknown file type: " + Integer.toHexString(settings.fileType));
          }

          fileElement.appendChild(fileSettingsElement);

          Element fileDataElement = doc.createElement("data");
          fileDataElement.setTextContent(Base64.encodeToString(file.getData(), Base64.DEFAULT));
          fileElement.appendChild(fileDataElement);
        }

        filesElement.appendChild(fileElement);
      }
      appElement.appendChild(filesElement);

      appsElement.appendChild(appElement);
    }
    root.appendChild(appsElement);

    DesfireManufacturingData manfData = getManufacturingData();

    Element manfDataElement = doc.createElement("manufacturing-data");

    Element element = doc.createElement("hw-vendor-id");
    element.setTextContent(Integer.toString(manfData.hwVendorID));
    manfDataElement.appendChild(element);

    element = doc.createElement("hw-type");
    element.setTextContent(Integer.toString(manfData.hwType));
    manfDataElement.appendChild(element);

    element = doc.createElement("hw-sub-type");
    element.setTextContent(Integer.toString(manfData.hwSubType));
    manfDataElement.appendChild(element);

    element = doc.createElement("hw-major-version");
    element.setTextContent(Integer.toString(manfData.hwMajorVersion));
    manfDataElement.appendChild(element);

    element = doc.createElement("hw-minor-version");
    element.setTextContent(Integer.toString(manfData.hwMinorVersion));
    manfDataElement.appendChild(element);

    element = doc.createElement("hw-storage-size");
    element.setTextContent(Integer.toString(manfData.hwStorageSize));
    manfDataElement.appendChild(element);

    element = doc.createElement("hw-protocol");
    element.setTextContent(Integer.toString(manfData.hwProtocol));
    manfDataElement.appendChild(element);

    element = doc.createElement("sw-vendor-id");
    element.setTextContent(Integer.toString(manfData.swVendorID));
    manfDataElement.appendChild(element);

    element = doc.createElement("sw-type");
    element.setTextContent(Integer.toString(manfData.swType));
    manfDataElement.appendChild(element);

    element = doc.createElement("sw-sub-type");
    element.setTextContent(Integer.toString(manfData.swSubType));
    manfDataElement.appendChild(element);

    element = doc.createElement("sw-major-version");
    element.setTextContent(Integer.toString(manfData.swMajorVersion));
    manfDataElement.appendChild(element);

    element = doc.createElement("sw-minor-version");
    element.setTextContent(Integer.toString(manfData.swMinorVersion));
    manfDataElement.appendChild(element);

    element = doc.createElement("sw-storage-size");
    element.setTextContent(Integer.toString(manfData.swStorageSize));
    manfDataElement.appendChild(element);

    element = doc.createElement("sw-protocol");
    element.setTextContent(Integer.toString(manfData.swProtocol));
    manfDataElement.appendChild(element);

    element = doc.createElement("uid");
    element.setTextContent(Integer.toString(manfData.uid));
    manfDataElement.appendChild(element);

    element = doc.createElement("batch-no");
    element.setTextContent(Integer.toString(manfData.batchNo));
    manfDataElement.appendChild(element);

    element = doc.createElement("week-prod");
    element.setTextContent(Integer.toString(manfData.weekProd));
    manfDataElement.appendChild(element);

    element = doc.createElement("year-prod");
    element.setTextContent(Integer.toString(manfData.yearProd));
    manfDataElement.appendChild(element);

    root.appendChild(manfDataElement);

    return root;
  }