OSDN Git Service

cleanup
[openpts/openpts.git] / src / ir.c
index 2a67148..e456935 100644 (file)
--- a/src/ir.c
+++ b/src/ir.c
@@ -26,7 +26,7 @@
  * \brief Generate Integrity Report from IML
  * @author Seiji Munetoh <munetoh@users.sourceforge.jp>
  * @date 2010-04-01
- * cleanup 2011-07-06 SM
+ * cleanup 2012-01-05 SM
  *
  *  TSS Event Struct -> IR
  *  IML and PCR may not match, since the read them is not an atmic operation
@@ -44,7 +44,7 @@
  *
  *  TOCTOU?
  *
- *
+ *  TODO refine XML error log
  */
 
 #include <sys/stat.h>
@@ -59,8 +59,8 @@
 #include <libxml/parser.h>
 
 #include <openpts.h>
-// #include <log.h>
 
+/* XML */
 enum {
     TEXT_WRITER_START_ELEMENT,
     TEXT_WRITER_WRITE_ATTR,
@@ -85,7 +85,14 @@ void displayXmlError(int errorIndex, int rc) {
         "xmlTextWriterEndDocument",
     };
 
-    ERROR("XML function '%s' returned '%d'\n", xmlFuncStrings[errorIndex], rc);
+    /* check */
+    if (errorIndex >= XML_FUNC_END) {
+        LOG(LOG_ERR, "errorIndex(%d) > XML_FUNC_END(%d)", errorIndex, XML_FUNC_END);
+        return;
+    }
+
+    /* log */
+    LOG(LOG_ERR, "XML function '%s' returned '%d'\n", xmlFuncStrings[errorIndex], rc);
 }
 
 /**
@@ -100,8 +107,14 @@ int freeAllFsm(OPENPTS_CONTEXT *ctx) {
 
     DEBUG_CAL("resetFsm\n");
 
+    /* check */
+    if (ctx == NULL) {
+        LOG(LOG_ERR, "null input");
+        return PTS_FATAL;
+    }
+
     if (ctx->ss_table == NULL) {
-        // DEBUG("resetFsm() - no SS table\n");
+        /* no SS table, skip */
         return PTS_SUCCESS;
     }
 
@@ -155,12 +168,14 @@ OPENPTS_IR_CONTEXT *newIrContext() {
 
     ctx = (OPENPTS_IR_CONTEXT *) xmalloc(sizeof(OPENPTS_IR_CONTEXT));
     if (ctx == NULL) {
+        LOG(LOG_ERR, "no memory");
         return NULL;
     }
     memset(ctx, 0, sizeof(OPENPTS_IR_CONTEXT));
 
     ctx->buf = xmalloc(EVENTDATA_BUF_SIZE);
     if (ctx->buf == NULL) {
+        LOG(LOG_ERR, "no memory");
         xfree(ctx);
         return NULL;
     }
@@ -176,10 +191,13 @@ OPENPTS_IR_CONTEXT *newIrContext() {
  *
  */
 void freeIrContext(OPENPTS_IR_CONTEXT *ctx) {
+    /* check */
     if (ctx == NULL) {
+        LOG(LOG_ERR, "null input");
         return;
     }
 
+    /* free */
     if (ctx->buf != NULL) {
         xfree(ctx->buf);
     }
@@ -207,6 +225,12 @@ int writeComponentID(
     int rc = PTS_INTERNAL_ERROR;
     char id[256];
 
+    /* check */
+    if (cid == NULL) {
+        LOG(LOG_ERR, "null input");
+        return PTS_FATAL;
+    }
+
     /* get strings */
     BYTE *simpleName = snmalloc2(cid->dataBlock.dataBlock,
                                  cid->simpleName.offset,
@@ -223,7 +247,7 @@ int writeComponentID(
     /* element "core:ComponentID" */
     rc = xmlTextWriterStartElement(writer, BAD_CAST "core:ComponentID");
     if (rc < 0) {
-        displayXmlError(TEXT_WRITER_START_ELEMENT, rc);  // TODO(munetoh) SYSLOG
+        displayXmlError(TEXT_WRITER_START_ELEMENT, rc);
         goto error;
     }
 
@@ -232,7 +256,7 @@ int writeComponentID(
     rc = xmlTextWriterWriteAttribute(
             writer,
             BAD_CAST "Id",
-            BAD_CAST id);  // TODO(munetoh)
+            BAD_CAST id);
     if (rc < 0) {
         displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
         goto error;
@@ -242,7 +266,7 @@ int writeComponentID(
     rc = xmlTextWriterWriteAttribute(
             writer,
             BAD_CAST "ModelSystemClass",
-            BAD_CAST "745749J");  // TODO(munetoh)
+            BAD_CAST "TBD");  // TODO(munetoh)
     if (rc < 0) {
         displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
         goto error;
@@ -252,7 +276,7 @@ int writeComponentID(
     rc = xmlTextWriterWriteAttribute(
             writer,
             BAD_CAST "SimpleName",
-            BAD_CAST simpleName);  // "745749J 6DET58WW (3.08 )");
+            BAD_CAST simpleName);
     if (rc < 0) {
         displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
         goto error;
@@ -262,7 +286,7 @@ int writeComponentID(
     rc = xmlTextWriterWriteAttribute(
             writer,
             BAD_CAST "VersionBuild",
-            BAD_CAST "1250694000000");
+            BAD_CAST "1250694000000");  // TODO(munetoh)
     if (rc < 0) {
         displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
         goto error;
@@ -273,7 +297,7 @@ int writeComponentID(
     rc = xmlTextWriterWriteAttribute(
             writer,
             BAD_CAST "VersionString",
-            BAD_CAST versionString);  // "6DET58WW (3.08 )");
+            BAD_CAST versionString);
     if (rc < 0) {
         displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
         goto error;
@@ -292,7 +316,7 @@ int writeComponentID(
     rc = xmlTextWriterWriteAttribute(
             writer,
             BAD_CAST "Name",
-            BAD_CAST vendor);  // "LENOVO");
+            BAD_CAST vendor);
     if (rc < 0) {
         displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
         goto error;
@@ -312,7 +336,7 @@ int writeComponentID(
     /* element "core:TcgVendorId" */
     rc = xmlTextWriterWriteFormatElement(
             writer,
-            BAD_CAST "core:TcgVendorId", "%s", "DEMO");
+            BAD_CAST "core:TcgVendorId", "%s", "DEMO");  // TODO(munetoh)
     if (rc < 0) {
         displayXmlError(TEXT_WRITER_WRITE_FORMAT_ELEMENT, rc);
         goto error;
@@ -423,8 +447,13 @@ int writeStuffObjects(
     char id[256];  // TODO(munetoh)
     int rc;
 
-    ASSERT(NULL != event, "writeStuffObjects, event == NULL\n");
+    /* check */
+    if (event == NULL) {
+        LOG(LOG_ERR, "null input");
+        return PTS_FATAL;
+    }
 
+    /* ID */
     snprintf(id, sizeof(id), "PCR_%d_LV%d_%d_%d_EVENT",
         event->ulPcrIndex, ss_level, event->eventType, eventindex);
 
@@ -535,7 +564,7 @@ int writeStuffObjects(
             goto error;
         }
     } else {
-        // printf("SM DEBUG no eventdata\n");
+        // no eventdata
     }
 
     /* Close the element named "stuff:Objects". */
@@ -548,7 +577,7 @@ int writeStuffObjects(
     return PTS_SUCCESS;
 
   error:
-    ERROR("writeStuffObjects() XML ERROR\n");
+    LOG(LOG_ERR, "writeStuffObjects() XML ERROR\n");
     return PTS_INTERNAL_ERROR;
 }
 
@@ -567,7 +596,6 @@ int writeStuffObjects(
  * @retval PTS_INTERNAL_ERROR
  *
  */
-
 int writePcrHash(
         xmlTextWriterPtr writer,
         int pcrIndex,
@@ -575,12 +603,22 @@ int writePcrHash(
         BYTE * startHash,
         BYTE * hash,
         int algtype) {
-    // int rc = PTS_SUCCESS;
     char id[256];  // TODO(munetoh) 11+1+1 = 12?
     int rc;
 
     DEBUG_CAL("writePcrHash - PCR[%d] level %d \n", pcrIndex, ss_level);
 
+    /* check */
+    if (startHash == NULL) {
+        LOG(LOG_ERR, "null input");
+        return PTS_FATAL;
+    }
+    if (hash == NULL) {
+        LOG(LOG_ERR, "null input");
+        return PTS_FATAL;
+    }
+
+    /* ID */
     snprintf(id, sizeof(id), "PCR_%d_LV%d_HASH", pcrIndex, ss_level);
 
     /* Start an element named "eventdata" as child of "PcrHash". */
@@ -640,7 +678,6 @@ int writePcrHash(
     /* Write a text */
     rc = xmlTextWriterWriteBase64(writer, (const char *) hash, 0, 20);
     if (rc < 0) {
-        // printf("SM DEBUG ERROR  digest len %d \n", 20);
         displayXmlError(TEXT_WRITER_WRITE_BASE64, rc);
         goto error;
     }
@@ -676,15 +713,28 @@ int writeSnapshot(
     char *str_ir_uuid;
     char id[256];  // TODO 3 + UUID = 3 + 36 = 39
     int level;
+    OPENPTS_PCR_EVENT_WRAPPER *eventWrapper;
 
+    /* check */
+    if (tpm == NULL) {
+        LOG(LOG_ERR, "null input");
+        return PTS_FATAL;
+    }
+    if (cid == NULL) {
+        LOG(LOG_ERR, "null input");
+        return PTS_FATAL;
+    }
+    if (ss == NULL) {
+        LOG(LOG_ERR, "null input");
+        return PTS_FATAL;
+    }
     level = ss->level;
 
-    OPENPTS_PCR_EVENT_WRAPPER *eventWrapper;
 
     /* reset PCR */
     // FSM resetPCR(n) exist
     if (ss->reset_pcr == 1) {
-        TODO("reset PCR[%d]\n", index);
+        LOG(LOG_TODO, "reset PCR[%d]\n", index);
         resetTpmPcr(tpm, index);
     }
 
@@ -706,13 +756,13 @@ int writeSnapshot(
     /* new UUID */
     ir_uuid = newUuid();
     if (ir_uuid == NULL) {
-        ERROR("UUID \n");
+        LOG(LOG_ERR, "UUID \n");
         rc = PTS_INTERNAL_ERROR;
         goto error;
     }
     str_ir_uuid = getStringOfUuid(ir_uuid);
     if (str_ir_uuid == NULL) {
-        ERROR("UUID \n");
+        LOG(LOG_ERR, "UUID \n");
         rc = PTS_INTERNAL_ERROR;
         xfree(ir_uuid);
         goto error;
@@ -770,8 +820,8 @@ int writeSnapshot(
     eventWrapper = ss->start;
 
     if (eventWrapper == NULL) {
-        ERROR("writeSnapshot- eventWrapper is NULL\n");
-        rc = PTS_INTERNAL_ERROR;
+        LOG(LOG_ERR, "writeSnapshot- eventWrapper is NULL\n");
+        rc = PTS_FATAL;
         goto free;
     }
 
@@ -803,14 +853,22 @@ int writeSnapshot(
 
     /* set curr PCR value */
     rc = getTpmPcrValue(tpm, index, ss->curr_pcr);
-    // TODO(munetoh) check with TSS/PCR value
+    if (rc != PTS_SUCCESS) {
+        LOG(LOG_ERR, "getTpmPcrValue() fail");
+        rc = PTS_INTERNAL_ERROR;
+        goto free;
+    }
 
     /* check with TPM value if this is the last snapshot */
-    // TODO(munetoh) copt level0 tpm_pcr to level1
+    // TODO(munetoh) copy level0 tpm_pcr to level1
 
     /* add PcrHash element */
     rc = writePcrHash(writer, index, level, ss->start_pcr, ss->curr_pcr, ALGTYPE_SHA1);
-    // NG rc = writePcrHash(writer, index, level, ss->start_pcr, ss->tpm_pcr, ALGTYPE_SHA1);
+    if (rc != PTS_SUCCESS) {
+        LOG(LOG_ERR, "writePcrHash() fail");
+        rc = PTS_INTERNAL_ERROR;
+        goto free;
+    }
 
     /* Close the element named "SnapshotCollection". */
     rc = xmlTextWriterEndElement(writer);
@@ -876,18 +934,24 @@ int writeQuote(
     BYTE select_byte[3];  // TODO TPM1.2, 24PCRs => 3 bytes
     char tagbuf[128];
 
+    /* check */
+    if (ctx == NULL) {
+        LOG(LOG_ERR, "null input");
+        return PTS_FATAL;
+    }
     if (ctx->pcrs == NULL) {
-        TODO("writeQuote - OPENPTS_PCRS is NULL, SKIP QuoteData\n");
-        return PTS_INTERNAL_ERROR;
+        LOG(LOG_TODO, "writeQuote - OPENPTS_PCRS is NULL, SKIP QuoteData\n");
+        return PTS_FATAL;
     }
     if (ctx->validation_data == NULL) {
-        TODO("writeQuote - TSS_VALIDATION is NULL, SKIP QuoteData\n");
-        return PTS_INTERNAL_ERROR;
+        LOG(LOG_TODO, "writeQuote - TSS_VALIDATION is NULL, SKIP QuoteData\n");
+        return PTS_FATAL;
     }
 
     /* Start an element named "QuoteData" as child of Report. */
     rc = xmlTextWriterStartElement(writer, BAD_CAST "QuoteData");
     if (rc < 0) {
+        LOG(LOG_ERR, "xmlX() fail");
         displayXmlError(TEXT_WRITER_START_ELEMENT, rc);
         return PTS_INTERNAL_ERROR;
     }
@@ -895,6 +959,7 @@ int writeQuote(
     /* Add an attribute with name "ID" */
     rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "ID", BAD_CAST "TBD");
     if (rc < 0) {
+        LOG(LOG_ERR, "xmlX() fail");
         displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
         return PTS_INTERNAL_ERROR;
     }
@@ -902,6 +967,7 @@ int writeQuote(
     /* Start an element named "Quote" as child of QuoteData. */
     rc = xmlTextWriterStartElement(writer, BAD_CAST "Quote");
     if (rc < 0) {
+        LOG(LOG_ERR, "xmlX() fail");
         displayXmlError(TEXT_WRITER_START_ELEMENT, rc);
         return PTS_INTERNAL_ERROR;
     }
@@ -909,6 +975,7 @@ int writeQuote(
     /* Start an element named "PcrComposit" as child of Quote. */
     rc = xmlTextWriterStartElement(writer, BAD_CAST "PcrComposit");
     if (rc < 0) {
+        LOG(LOG_ERR, "xmlX() fail");
         displayXmlError(TEXT_WRITER_START_ELEMENT, rc);
         return PTS_INTERNAL_ERROR;
     }
@@ -935,12 +1002,13 @@ int writeQuote(
         select_byte[2] = select_int & 0xFF;
     } else {
         // TODO
-        ERROR(" PCR NUM != 24\n");
+        LOG(LOG_ERR, " PCR NUM != 24\n");
     }
 
     /* Start an element named "PcrSelection" as child of PcrComposit. */
     rc = xmlTextWriterStartElement(writer, BAD_CAST "PcrSelection");
     if (rc < 0) {
+        LOG(LOG_ERR, "xmlX() fail");
         displayXmlError(TEXT_WRITER_START_ELEMENT, rc);
         return PTS_INTERNAL_ERROR;
     }
@@ -949,6 +1017,7 @@ int writeQuote(
     snprintf(tagbuf, sizeof(tagbuf), "%d", size_of_select);
     rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "SizeOfSelect", BAD_CAST tagbuf);
     if (rc < 0) {
+        LOG(LOG_ERR, "xmlX() fail");
         displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
         return PTS_INTERNAL_ERROR;
     }
@@ -959,12 +1028,12 @@ int writeQuote(
         size_of_select,
         &b64buf_len);
     if (b64buf == NULL) {
-        ERROR("encodeBase64 fail");  // TODO ERROR => displayXmlError
+        LOG(LOG_ERR, "encodeBase64 fail");  // TODO ERROR => displayXmlError
         return PTS_INTERNAL_ERROR;
     }
     rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "PcrSelect", BAD_CAST b64buf);
     if (rc < 0) {
-        // ERROR("Error at xmlTextWriterWriteAttribute\n");
+        LOG(LOG_ERR, "xmlX() fail");
         displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
         return PTS_INTERNAL_ERROR;
     }
@@ -974,7 +1043,7 @@ int writeQuote(
     /* Close the element named "PcrSelection". */
     rc = xmlTextWriterEndElement(writer);
     if (rc < 0) {
-        // ERROR("Error at xmlTextWriterEndElement\n");
+        LOG(LOG_ERR, "xmlX() fail");
         displayXmlError(TEXT_WRITER_END_ELEMENT, rc);
         return PTS_INTERNAL_ERROR;
     }
@@ -984,6 +1053,7 @@ int writeQuote(
     /* Write an element named "ValueSize" as child of PcrComposit */
     rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "ValueSize", "%d", ctx->pcrs->value_size);
     if (rc < 0) {
+        LOG(LOG_ERR, "xmlX() fail");
         displayXmlError(TEXT_WRITER_WRITE_FORMAT_ELEMENT, rc);
         return PTS_INTERNAL_ERROR;
     }
@@ -995,6 +1065,7 @@ int writeQuote(
             /* Start an element named "PcrValue" as child of PcrComposit. */
             rc = xmlTextWriterStartElement(writer, BAD_CAST "PcrValue");
             if (rc < 0) {
+                LOG(LOG_ERR, "xmlTextWriterStartElement() fail");
                 displayXmlError(TEXT_WRITER_START_ELEMENT, rc);
                 return PTS_INTERNAL_ERROR;
             }
@@ -1003,6 +1074,7 @@ int writeQuote(
             rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "PcrNumber", BAD_CAST tagbuf);
             // rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "PcrNumber", BAD_CAST "0");
             if (rc < 0) {
+                LOG(LOG_ERR, "xmlTextWriterWriteAttribute() fail");
                 displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
                 return PTS_INTERNAL_ERROR;
             }
@@ -1014,6 +1086,7 @@ int writeQuote(
                     0,
                     20);  // TODO add length to OPENPTS_PCRS
             if (rc < 0) {
+                LOG(LOG_ERR, "xmlTextWriterWriteBase64() fail");
                 displayXmlError(TEXT_WRITER_WRITE_BASE64, rc);
                 return PTS_INTERNAL_ERROR;
             }
@@ -1021,6 +1094,7 @@ int writeQuote(
             /* Close the element named "PcrValue" */
             rc = xmlTextWriterEndElement(writer);
             if (rc < 0) {
+                LOG(LOG_ERR, "xmlTextWriterEndElement() fail");
                 displayXmlError(TEXT_WRITER_END_ELEMENT, rc);
                 return PTS_INTERNAL_ERROR;
             }
@@ -1030,6 +1104,7 @@ int writeQuote(
     /* Close the element named "PcrComposit". */
     rc = xmlTextWriterEndElement(writer);
     if (rc < 0) {
+        LOG(LOG_ERR, "xmlTextWriterEndElement() fail");
         displayXmlError(TEXT_WRITER_END_ELEMENT, rc);
         return PTS_INTERNAL_ERROR;
     }
@@ -1038,6 +1113,7 @@ int writeQuote(
     /* Start an element named "QuoteInfo" as child of Quote. */
     rc = xmlTextWriterStartElement(writer, BAD_CAST "QuoteInfo");
     if (rc < 0) {
+        LOG(LOG_ERR, "xmlTextWriterStartElement() fail");
         displayXmlError(TEXT_WRITER_START_ELEMENT, rc);
         return PTS_INTERNAL_ERROR;
     }
@@ -1046,7 +1122,7 @@ int writeQuote(
     snprintf(tagbuf, sizeof(tagbuf), "%d", ctx->validation_data->versionInfo.bMajor);
     rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "VersionMajor", BAD_CAST tagbuf);
     if (rc < 0) {
-        // ERROR("Error at xmlTextWriterWriteAttribute\n");
+        LOG(LOG_ERR, "xmlTextWriterWriteAttribute() fail");
         displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
         return PTS_INTERNAL_ERROR;
     }
@@ -1054,7 +1130,7 @@ int writeQuote(
     snprintf(tagbuf, sizeof(tagbuf), "%d", ctx->validation_data->versionInfo.bMinor);
     rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "VersionMinor", BAD_CAST tagbuf);
     if (rc < 0) {
-        // ERROR("Error at xmlTextWriterWriteAttribute\n");
+        LOG(LOG_ERR, "xmlX() fail");
         displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
         return PTS_INTERNAL_ERROR;
     }
@@ -1062,7 +1138,7 @@ int writeQuote(
     snprintf(tagbuf, sizeof(tagbuf), "%d", ctx->validation_data->versionInfo.bRevMajor);
     rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "VersionRevMajor", BAD_CAST tagbuf);
     if (rc < 0) {
-        // ERROR("Error at xmlTextWriterWriteAttribute\n");
+        LOG(LOG_ERR, "xmlX() fail");
         displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
         return PTS_INTERNAL_ERROR;
     }
@@ -1071,7 +1147,7 @@ int writeQuote(
     snprintf(tagbuf, sizeof(tagbuf), "%d", ctx->validation_data->versionInfo.bRevMinor);
     rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "VersionRevMinor", BAD_CAST tagbuf);
     if (rc < 0) {
-        // ERROR("Error at xmlTextWriterWriteAttribute\n");
+        LOG(LOG_ERR, "xmlX() fail");
         displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
         return PTS_INTERNAL_ERROR;
     }
@@ -1079,7 +1155,7 @@ int writeQuote(
     /* Add an attribute with name "Fixed", int */
     rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "Fixed", BAD_CAST "QUOT");
     if (rc < 0) {
-        // ERROR("Error at xmlTextWriterWriteAttribute\n");
+        LOG(LOG_ERR, "xmlX() fail");
         displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
         return -1;
     }
@@ -1090,11 +1166,12 @@ int writeQuote(
         20,
         &b64buf_len);  // ctx->validation_data->ulDataLength);
     if (b64buf == NULL) {
-        ERROR("encodeBase64() fail");
+        LOG(LOG_ERR, "encodeBase64() fail");
         return PTS_INTERNAL_ERROR;
     }
     rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "DigestValue", BAD_CAST b64buf);
     if (rc < 0) {
+        LOG(LOG_ERR, "xmlX() fail");
         displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
         return PTS_INTERNAL_ERROR;
     }
@@ -1109,12 +1186,12 @@ int writeQuote(
         ctx->validation_data->ulExternalDataLength,
         &b64buf_len);
     if (b64buf == NULL) {
-        ERROR("encodeBase64() fail");
+        LOG(LOG_ERR, "encodeBase64() fail");
         return PTS_INTERNAL_ERROR;
     }
     rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "ExternalData", BAD_CAST b64buf);
     if (rc < 0) {
-        // ERROR("Error at xmlTextWriterWriteAttribute\n");
+        LOG(LOG_ERR, "xmlX() fail");
         displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
         return PTS_INTERNAL_ERROR;
     }
@@ -1124,7 +1201,7 @@ int writeQuote(
     /* Close the element named "QuoteInfo". */
     rc = xmlTextWriterEndElement(writer);
     if (rc < 0) {
-        // ERROR("Error at xmlTextWriterEndElement\n");
+        LOG(LOG_ERR, "xmlX() fail");
         displayXmlError(TEXT_WRITER_END_ELEMENT, rc);
         return PTS_INTERNAL_ERROR;
     }
@@ -1132,7 +1209,7 @@ int writeQuote(
     /* Close the element named "Quote". */
     rc = xmlTextWriterEndElement(writer);
     if (rc < 0) {
-        // ERROR("Error at xmlTextWriterEndElement\n");
+        LOG(LOG_ERR, "xmlX() fail");
         displayXmlError(TEXT_WRITER_END_ELEMENT, rc);
         return PTS_INTERNAL_ERROR;
     }
@@ -1142,6 +1219,7 @@ int writeQuote(
     /* Start an element named "TpmSignature" as child of QuoteData. */
     rc = xmlTextWriterStartElement(writer, BAD_CAST "TpmSignature");
     if (rc < 0) {
+        LOG(LOG_ERR, "xmlX() fail");
         displayXmlError(TEXT_WRITER_START_ELEMENT, rc);
         return PTS_INTERNAL_ERROR;
     }
@@ -1151,6 +1229,7 @@ int writeQuote(
     /* Start an element named "SignatureMethod" as child of TpmSignature. */
     rc = xmlTextWriterStartElement(writer, BAD_CAST "SignatureMethod");
     if (rc < 0) {
+        LOG(LOG_ERR, "xmlX() fail");
         displayXmlError(TEXT_WRITER_START_ELEMENT, rc);
         return PTS_INTERNAL_ERROR;
     }
@@ -1159,6 +1238,7 @@ int writeQuote(
             BAD_CAST "Algorithm",
             BAD_CAST "http://www.w3.org/2000/09/xmldsig#rsa-sha1");  // TODO
     if (rc < 0) {
+        LOG(LOG_ERR, "xmlX() fail");
         displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
         return PTS_INTERNAL_ERROR;
     }
@@ -1242,13 +1322,18 @@ int writeQuote2(
     BYTE *composite_hash;
     char tagbuf[128];  // Quote tag
 
+    /* check */
+    if (ctx == NULL) {
+        LOG(LOG_ERR, "null input");
+        return PTS_FATAL;
+    }
     if (ctx->pcrs == NULL) {
-        TODO("writeQuote2 - OPENPTS_PCRS is NULL, SKIP QuoteData\n");
-        return PTS_INTERNAL_ERROR;
+        LOG(LOG_TODO, "writeQuote2 - OPENPTS_PCRS is NULL, SKIP QuoteData\n");
+        return PTS_FATAL;
     }
     if (ctx->validation_data == NULL) {
-        TODO("writeQuote2 - TSS_VALIDATION is NULL, SKIP QuoteData\n");
-        return PTS_INTERNAL_ERROR;
+        LOG(LOG_TODO, "writeQuote2 - TSS_VALIDATION is NULL, SKIP QuoteData\n");
+        return PTS_FATAL;
     }
 
     /* Quote2 - tag [0:1] */
@@ -1311,6 +1396,7 @@ int writeQuote2(
     snprintf(tagbuf, sizeof(tagbuf), "%d", tag);
     rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "Tag", BAD_CAST tagbuf);
     if (rc < 0) {
+        LOG(LOG_ERR, "xmlX() fail");
         displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
         return PTS_INTERNAL_ERROR;
     }
@@ -1318,6 +1404,7 @@ int writeQuote2(
     DEBUG("fixed : %s", fixed);
     rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "Fixed", BAD_CAST fixed);
     if (rc < 0) {
+        LOG(LOG_ERR, "xmlX() fail");
         displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
         return PTS_INTERNAL_ERROR;
     }
@@ -1327,13 +1414,13 @@ int writeQuote2(
         ctx->validation_data->ulExternalDataLength,
         &b64buf_len);
     if (b64buf == NULL) {
-        ERROR("encodeBase64 fail");
+        LOG(LOG_ERR, "encodeBase64 fail");
         return PTS_INTERNAL_ERROR;
     }
     rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "ExternalData", BAD_CAST b64buf);
     free(b64buf);
     if (rc < 0) {
-        // ERROR("Error at xmlTextWriterWriteAttribute\n");
+        LOG(LOG_ERR, "xmlX() fail");
         displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
         return PTS_INTERNAL_ERROR;
     }
@@ -1341,7 +1428,7 @@ int writeQuote2(
     /* PcrInfoShort - start */
     rc = xmlTextWriterStartElement(writer, BAD_CAST "PcrInfoShort");
     if (rc < 0) {
-        // ERROR("Error at xmlTextWriterStartElement\n");
+        LOG(LOG_ERR, "xmlX() fail");
         displayXmlError(TEXT_WRITER_START_ELEMENT, rc);
         return PTS_INTERNAL_ERROR;
     }
@@ -1349,7 +1436,7 @@ int writeQuote2(
     /* PcrSelection - start */
     rc = xmlTextWriterStartElement(writer, BAD_CAST "PcrSelection");
     if (rc < 0) {
-        // ERROR("Error at xmlTextWriterStartElement\n");
+        LOG(LOG_ERR, "xmlX() fail");
         displayXmlError(TEXT_WRITER_START_ELEMENT, rc);
         return PTS_INTERNAL_ERROR;
     }
@@ -1357,7 +1444,7 @@ int writeQuote2(
     snprintf(tagbuf, sizeof(tagbuf), "%d", size_of_select);
     rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "SizeOfSelect", BAD_CAST tagbuf);
     if (rc < 0) {
-        // ERROR("Error at xmlTextWriterWriteAttribute\n");
+        LOG(LOG_ERR, "xmlX() fail");
         displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
         return PTS_INTERNAL_ERROR;
     }
@@ -1367,18 +1454,20 @@ int writeQuote2(
         size_of_select,
         &b64buf_len);
     if (b64buf == NULL) {
-        ERROR("encodeBase64 fail");
+        LOG(LOG_ERR, "encodeBase64 fail");
         return PTS_INTERNAL_ERROR;
     }
     rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "PcrSelect", BAD_CAST b64buf);
     free(b64buf);
     if (rc < 0) {
+        LOG(LOG_ERR, "xmlX() fail");
         displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
         return PTS_INTERNAL_ERROR;
     }
     /* PcrSelection - end */
     rc = xmlTextWriterEndElement(writer);
     if (rc < 0) {
+        LOG(LOG_ERR, "xmlX() fail");
         displayXmlError(TEXT_WRITER_END_ELEMENT, rc);
         return PTS_INTERNAL_ERROR;
     }
@@ -1387,6 +1476,7 @@ int writeQuote2(
     /* LocalityAtRelease - element */
     rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "LocalityAtRelease", "%d", locality);
     if (rc < 0) {
+        LOG(LOG_ERR, "xmlX() fail");
         displayXmlError(TEXT_WRITER_WRITE_FORMAT_ELEMENT, rc);
         return PTS_INTERNAL_ERROR;
     }
@@ -1397,12 +1487,13 @@ int writeQuote2(
         20,
         &b64buf_len);
     if (b64buf == NULL) {
-        ERROR("encodeBase64 fail");
+        LOG(LOG_ERR, "encodeBase64 fail");
         return PTS_INTERNAL_ERROR;
     }
     rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "CompositeHash", "%s", b64buf);
     free(b64buf);
     if (rc < 0) {
+        LOG(LOG_ERR, "xmlX() fail");
         displayXmlError(TEXT_WRITER_WRITE_FORMAT_ELEMENT, rc);
         return PTS_INTERNAL_ERROR;
     }
@@ -1411,7 +1502,7 @@ int writeQuote2(
     /* PcrComposite - start */
     rc = xmlTextWriterStartElement(writer, BAD_CAST "PcrComposit");
     if (rc < 0) {
-        // ERROR("Error at xmlTextWriterStartElement\n");
+        LOG(LOG_ERR, "xmlX() fail");
         displayXmlError(TEXT_WRITER_START_ELEMENT, rc);
         return PTS_INTERNAL_ERROR;
     }
@@ -1419,7 +1510,7 @@ int writeQuote2(
     /* PcrSelection - start */
     rc = xmlTextWriterStartElement(writer, BAD_CAST "PcrSelection");
     if (rc < 0) {
-        // ERROR("Error at xmlTextWriterStartElement\n");
+        LOG(LOG_ERR, "xmlX() fail");
         displayXmlError(TEXT_WRITER_START_ELEMENT, rc);
         return PTS_INTERNAL_ERROR;
     }
@@ -1427,7 +1518,7 @@ int writeQuote2(
     snprintf(tagbuf, sizeof(tagbuf), "%d", size_of_select);
     rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "SizeOfSelect", BAD_CAST tagbuf);
     if (rc < 0) {
-        // ERROR("Error at xmlTextWriterWriteAttribute\n");
+        LOG(LOG_ERR, "xmlX() fail");
         displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
         return PTS_INTERNAL_ERROR;
     }
@@ -1437,25 +1528,28 @@ int writeQuote2(
         size_of_select,
         &b64buf_len);
     if (b64buf == NULL) {
-        ERROR("encodeBase64 fail");
+        LOG(LOG_ERR, "encodeBase64 fail");
         return PTS_INTERNAL_ERROR;
     }
     rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "PcrSelect", BAD_CAST b64buf);
     free(b64buf);
     if (rc < 0) {
+        LOG(LOG_ERR, "xmlX() fail");
         displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
         return PTS_INTERNAL_ERROR;
     }
     /* PcrSelection - end */
     rc = xmlTextWriterEndElement(writer);
     if (rc < 0) {
+        LOG(LOG_ERR, "xmlX() fail");
         displayXmlError(TEXT_WRITER_END_ELEMENT, rc);
         return PTS_INTERNAL_ERROR;
     }
     /* ValueSize - element */
     rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "ValueSize", "%d", ctx->pcrs->value_size);
     if (rc < 0) {
-         displayXmlError(TEXT_WRITER_WRITE_FORMAT_ELEMENT, rc);
+        LOG(LOG_ERR, "xmlX() fail");
+        displayXmlError(TEXT_WRITER_WRITE_FORMAT_ELEMENT, rc);
         return PTS_INTERNAL_ERROR;
     }
     /* PcrValue, loop */
@@ -1464,7 +1558,7 @@ int writeQuote2(
             /* PcrValue - start */
             rc = xmlTextWriterStartElement(writer, BAD_CAST "PcrValue");
             if (rc < 0) {
-                // ERROR("Error at xmlTextWriterStartElement\n");
+                LOG(LOG_ERR, "xmlX() fail");
                 displayXmlError(TEXT_WRITER_START_ELEMENT, rc);
                 return PTS_INTERNAL_ERROR;
             }
@@ -1472,7 +1566,7 @@ int writeQuote2(
             snprintf(tagbuf, sizeof(tagbuf), "%d", i);
             rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "PcrNumber", BAD_CAST tagbuf);
             if (rc < 0) {
-                // ERROR("Error at xmlTextWriterWriteAttribute\n");
+                LOG(LOG_ERR, "xmlX() fail");
                 displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
                 return PTS_INTERNAL_ERROR;
             }
@@ -1485,6 +1579,7 @@ int writeQuote2(
                     0,
                     20);  // TODO add length to OPENPTS_PCRS
             if (rc < 0) {
+                LOG(LOG_ERR, "xmlX() fail");
                 displayXmlError(TEXT_WRITER_WRITE_BASE64, rc);
                 return PTS_INTERNAL_ERROR;
             }
@@ -1492,6 +1587,7 @@ int writeQuote2(
             /* PcrValue - end */
             rc = xmlTextWriterEndElement(writer);
             if (rc < 0) {
+                LOG(LOG_ERR, "xmlX() fail");
                 displayXmlError(TEXT_WRITER_END_ELEMENT, rc);
                 return PTS_INTERNAL_ERROR;
             }
@@ -1500,6 +1596,7 @@ int writeQuote2(
     /* PcrComposite - end */
     rc = xmlTextWriterEndElement(writer);
     if (rc < 0) {
+        LOG(LOG_ERR, "xmlX() fail");
         displayXmlError(TEXT_WRITER_END_ELEMENT, rc);
         return PTS_INTERNAL_ERROR;
     }
@@ -1507,16 +1604,15 @@ int writeQuote2(
     /* PcrInfoShort - end */
     rc = xmlTextWriterEndElement(writer);
     if (rc < 0) {
+        LOG(LOG_ERR, "xmlX() fail");
         displayXmlError(TEXT_WRITER_END_ELEMENT, rc);
         return PTS_INTERNAL_ERROR;
     }
 
-
-
-
     /* QuoteInfo2 - end  */
     rc = xmlTextWriterEndElement(writer);
     if (rc < 0) {
+        LOG(LOG_ERR, "xmlX() fail");
         displayXmlError(TEXT_WRITER_END_ELEMENT, rc);
         return PTS_INTERNAL_ERROR;
     }
@@ -1524,6 +1620,7 @@ int writeQuote2(
     /* Quote2 - end */
     rc = xmlTextWriterEndElement(writer);
     if (rc < 0) {
+        LOG(LOG_ERR, "xmlX() fail");
         displayXmlError(TEXT_WRITER_END_ELEMENT, rc);
         return PTS_INTERNAL_ERROR;
     }
@@ -1533,6 +1630,7 @@ int writeQuote2(
     /* Start an element named "TpmSignature" as child of QuoteData. */
     rc = xmlTextWriterStartElement(writer, BAD_CAST "TpmSignature");
     if (rc < 0) {
+        LOG(LOG_ERR, "xmlX() fail");
         displayXmlError(TEXT_WRITER_START_ELEMENT, rc);
         return PTS_INTERNAL_ERROR;
     }
@@ -1542,6 +1640,7 @@ int writeQuote2(
     /* Start an element named "SignatureMethod" as child of TpmSignature. */
     rc = xmlTextWriterStartElement(writer, BAD_CAST "SignatureMethod");
     if (rc < 0) {
+        LOG(LOG_ERR, "xmlX() fail");
         displayXmlError(TEXT_WRITER_START_ELEMENT, rc);
         return PTS_INTERNAL_ERROR;
     }
@@ -1550,12 +1649,14 @@ int writeQuote2(
             BAD_CAST "Algorithm",
             BAD_CAST "http://www.w3.org/2000/09/xmldsig#rsa-sha1");  // TODO
     if (rc < 0) {
+        LOG(LOG_ERR, "xmlX() fail");
         displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
         return PTS_INTERNAL_ERROR;
     }
     /* Close the element named "SignatureMethod". */
     rc = xmlTextWriterEndElement(writer);
     if (rc < 0) {
+        LOG(LOG_ERR, "xmlX() fail");
         displayXmlError(TEXT_WRITER_END_ELEMENT, rc);
         return PTS_INTERNAL_ERROR;
     }
@@ -1565,6 +1666,7 @@ int writeQuote2(
     /* Start an element named "SignatureValue" as child of TpmSignature. */
     rc = xmlTextWriterStartElement(writer, BAD_CAST "SignatureValue");
     if (rc < 0) {
+        LOG(LOG_ERR, "xmlX() fail");
         displayXmlError(TEXT_WRITER_START_ELEMENT, rc);
         return PTS_INTERNAL_ERROR;
     }
@@ -1575,12 +1677,14 @@ int writeQuote2(
             0,
             ctx->validation_data->ulValidationDataLength);
     if (rc < 0) {
+        LOG(LOG_ERR, "xmlX() fail");
         displayXmlError(TEXT_WRITER_WRITE_BASE64, rc);
         return PTS_INTERNAL_ERROR;
     }
     /* Close the element named "SignatureValue". */
     rc = xmlTextWriterEndElement(writer);
     if (rc < 0) {
+        LOG(LOG_ERR, "xmlX() fail");
         displayXmlError(TEXT_WRITER_END_ELEMENT, rc);
         return PTS_INTERNAL_ERROR;
     }
@@ -1588,6 +1692,7 @@ int writeQuote2(
     /* Close the element named "TpmSignature". */
     rc = xmlTextWriterEndElement(writer);
     if (rc < 0) {
+        LOG(LOG_ERR, "xmlX() fail");
         displayXmlError(TEXT_WRITER_END_ELEMENT, rc);
         return PTS_INTERNAL_ERROR;
     }
@@ -1595,6 +1700,7 @@ int writeQuote2(
     /* Close the element named "QuoteData". */
     rc = xmlTextWriterEndElement(writer);
     if (rc < 0) {
+        LOG(LOG_ERR, "xmlX() fail");
         displayXmlError(TEXT_WRITER_END_ELEMENT, rc);
         return PTS_INTERNAL_ERROR;
     }
@@ -1619,21 +1725,22 @@ int writeQuote2(
  *
  */
 // TODO remove file
-int writeIr(OPENPTS_CONTEXT *ctx, const char *filenameDP, int *savedFd) {
-//int writeIr(OPENPTS_CONTEXT *ctx, int *savedFd) {
+int writeIr(
+    OPENPTS_CONTEXT *ctx,
+    const char *filenameDP,  // in  (set ctx->conf->ir_filename in normal operation)
+    int *savedFd) {          // out
+
     int rc = PTS_SUCCESS;
     int i;
     int irFd;
     int lengthOfIrFile;
     xmlTextWriterPtr writer;
     xmlBufferPtr xmlbuf;
-    // FILE *fp;
     PTS_ComponentId cid;
     OPENPTS_TPM_CONTEXT tpm;  // to calc snapshot PCR
     PTS_UUID *ir_uuid;
     char *str_ir_uuid;
     char *filename = NULL;
-    // char filename[256];  // TODO UUID_UUID.xml
 
     PTS_Byte smbios[12] = { 0x4A, 0x4A, 0x4A, 0x4A, 0x4A,
                             0x4A, 0x4A, 0x4A, 0x4A, 0x4A,
@@ -1646,13 +1753,10 @@ int writeIr(OPENPTS_CONTEXT *ctx, const char *filenameDP, int *savedFd) {
 
     /* check */
     if (ctx == NULL) {
-        ERROR("ctx == NULL");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
-    //if (filename == NULL) {
-    //    ERROR("filename == NULL");
-    //    return PTS_FATAL;
-    //}
+
 
     // TODO(munetoh) dummy data
     cid.vendor.offset = 0;
@@ -1697,7 +1801,7 @@ int writeIr(OPENPTS_CONTEXT *ctx, const char *filenameDP, int *savedFd) {
     /* Create a new XML buffer */
     xmlbuf = xmlBufferCreate();
     if (xmlbuf == NULL) {
-        ERROR("creating the xml buffer fail\n");
+        LOG(LOG_ERR, "creating the xml buffer fail\n");
         rc = PTS_INTERNAL_ERROR;
         goto error;
     }
@@ -1705,7 +1809,7 @@ int writeIr(OPENPTS_CONTEXT *ctx, const char *filenameDP, int *savedFd) {
     /* Create a new XmlWriter for memory */
     writer = xmlNewTextWriterMemory(xmlbuf, 0);
     if (writer == NULL) {
-        ERROR("creating the xml writer fail\n");
+        LOG(LOG_ERR, "creating the xml writer fail\n");
         rc = PTS_INTERNAL_ERROR;
         goto freexml;
     }
@@ -1713,6 +1817,7 @@ int writeIr(OPENPTS_CONTEXT *ctx, const char *filenameDP, int *savedFd) {
     /* Start the document */
     rc = xmlTextWriterStartDocument(writer, "1.0", XML_ENCODING, "no");
     if (rc < 0) {
+        LOG(LOG_ERR, "xmlX() fail");
         displayXmlError(TEXT_WRITER_START_DOC, rc);
         rc = PTS_INTERNAL_ERROR;
         goto freexml;
@@ -1721,13 +1826,12 @@ int writeIr(OPENPTS_CONTEXT *ctx, const char *filenameDP, int *savedFd) {
     /* Start an element named "Report", the root element of the document. */
     rc = xmlTextWriterStartElement(writer, BAD_CAST "Report");
     if (rc < 0) {
+        LOG(LOG_ERR, "xmlX() fail");
         displayXmlError(TEXT_WRITER_START_ELEMENT, rc);
         rc = PTS_INTERNAL_ERROR;
         goto freexml;
     }
 
-
-
     DEBUG_CAL("genIr - uuid done\n");
 
     /* Add an attribute of Schemas */
@@ -1736,6 +1840,7 @@ int writeIr(OPENPTS_CONTEXT *ctx, const char *filenameDP, int *savedFd) {
             BAD_CAST "xmlns:core",
             BAD_CAST XMLNS_CORE);
     if (rc < 0) {
+        LOG(LOG_ERR, "xmlX() fail");
         displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
         rc = PTS_INTERNAL_ERROR;
         goto freexml;
@@ -1746,6 +1851,7 @@ int writeIr(OPENPTS_CONTEXT *ctx, const char *filenameDP, int *savedFd) {
             BAD_CAST "xmlns:stuff",
             BAD_CAST XMLNS_STUFF);
     if (rc < 0) {
+        LOG(LOG_ERR, "xmlX() fail");
         displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
         rc = PTS_INTERNAL_ERROR;
         goto freexml;
@@ -1757,6 +1863,7 @@ int writeIr(OPENPTS_CONTEXT *ctx, const char *filenameDP, int *savedFd) {
             BAD_CAST "xmlns:xsi",
             BAD_CAST "http://www.w3.org/2001/XMLSchema-instance");
     if (rc < 0) {
+        LOG(LOG_ERR, "xmlX() fail");
         displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
         rc = PTS_INTERNAL_ERROR;
         goto freexml;
@@ -1767,6 +1874,7 @@ int writeIr(OPENPTS_CONTEXT *ctx, const char *filenameDP, int *savedFd) {
             BAD_CAST "xmlns",
             BAD_CAST XMLNS_IR);
     if (rc < 0) {
+        LOG(LOG_ERR, "xmlX() fail");
         displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
         rc = PTS_INTERNAL_ERROR;
         goto freexml;
@@ -1775,14 +1883,14 @@ int writeIr(OPENPTS_CONTEXT *ctx, const char *filenameDP, int *savedFd) {
     /* generate UUID */
     ir_uuid = newUuid();
     if (ir_uuid == NULL) {
-        ERROR("fail UUID generation\n");
+        LOG(LOG_ERR, "fail UUID generation\n");
         rc = PTS_INTERNAL_ERROR;
         goto freexml;
     }
 
     str_ir_uuid = getStringOfUuid(ir_uuid);
     if (str_ir_uuid == NULL) {
-        ERROR("fail UUID generation\n");
+        LOG(LOG_ERR, "fail UUID generation\n");
         rc = PTS_INTERNAL_ERROR;
         xfree(ir_uuid);
         goto freexml;
@@ -1793,6 +1901,7 @@ int writeIr(OPENPTS_CONTEXT *ctx, const char *filenameDP, int *savedFd) {
 
     rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "ID", BAD_CAST id);
     if (rc < 0) {
+        LOG(LOG_ERR, "xmlX() fail");
         displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
         rc = PTS_INTERNAL_ERROR;
         goto free;
@@ -1811,13 +1920,13 @@ int writeIr(OPENPTS_CONTEXT *ctx, const char *filenameDP, int *savedFd) {
     /* Quote*/
     if (ctx->conf->iml_mode == 0) {
         if (ctx->conf->ir_without_quote == 1) {
-            TODO("skip TPM_Quote\n");
+            LOG(LOG_TODO, "skip TPM_Quote\n");
         } else {
             if (ctx->conf->tpm_quote_type == 1) {
                 /* Quote */
                 rc = writeQuote(writer, ctx);
                 if (rc < 0) {
-                    ERROR("writeIr - writeQuote() rc = %d\n", rc);
+                    LOG(LOG_ERR, "writeIr - writeQuote() rc = %d\n", rc);
                     rc = PTS_INTERNAL_ERROR;
                     goto free;
                 }
@@ -1825,7 +1934,7 @@ int writeIr(OPENPTS_CONTEXT *ctx, const char *filenameDP, int *savedFd) {
                 /* Quote2 */
                 rc = writeQuote2(writer, ctx);
                 if (rc < 0) {
-                    ERROR("writeIr - writeQuote2() rc = %d\n", rc);
+                    LOG(LOG_ERR, "writeIr - writeQuote2() rc = %d\n", rc);
                     rc = PTS_INTERNAL_ERROR;
                     goto free;
                 }
@@ -1844,8 +1953,7 @@ int writeIr(OPENPTS_CONTEXT *ctx, const char *filenameDP, int *savedFd) {
         if (ss != NULL) {
             if (ss->event_num > 0) {
                 // level 0
-                // printf("DEBUG add level %d snapshot for PCR%d\n",ss->level, i);
-                // ERROR("writeIr PCR[%d] LV0 num=%d\n", i,ss->event_num);
+                // LOG(LOG_ERR, "writeIr PCR[%d] LV0 num=%d\n", i,ss->event_num);
                 writeSnapshot(writer, &tpm, &cid, i, ss);
             }
         }
@@ -1854,7 +1962,7 @@ int writeIr(OPENPTS_CONTEXT *ctx, const char *filenameDP, int *savedFd) {
         ss = getSnapshotFromTable(ctx->ss_table, i, 1);
         if (ss != NULL) {
             if (ss->event_num > 0) {
-                // ERROR("writeIr PCR[%d] LV1 num=%d\n", i,ss->event_num);
+                // LOG(LOG_ERR, "writeIr PCR[%d] LV1 num=%d\n", i,ss->event_num);
                 // writeSnapshot(writer, &tpm, &cid, i, ss);
                 if (i == OPENPTS_PCR_INDEX) {
                     DEBUG("genIr - Not writing snapshot for OPENPTS_PCR_INDEX (%d)\n",
@@ -1876,7 +1984,7 @@ int writeIr(OPENPTS_CONTEXT *ctx, const char *filenameDP, int *savedFd) {
 
     rc = xmlTextWriterFlush(writer);
     if (rc < 0) {
-        // ERROR("writeRm: Error at xmlTextWriterFlush\n");
+        // LOG(LOG_ERR, "writeRm: Error at xmlTextWriterFlush\n");
         displayXmlError(TEXT_WRITER_FLUSH, rc);
         rc = PTS_INTERNAL_ERROR;
         goto free;
@@ -1885,40 +1993,22 @@ int writeIr(OPENPTS_CONTEXT *ctx, const char *filenameDP, int *savedFd) {
     /* Close all elements */
     rc = xmlTextWriterEndDocument(writer);
     if (rc < 0) {
-        ERROR("testXmlwriterMemory: Error at xmlTextWriterEndDocument\n");
+        LOG(LOG_ERR, "testXmlwriterMemory: Error at xmlTextWriterEndDocument\n");
         rc = PTS_INTERNAL_ERROR;
         goto free;
     }
 
-#if 0
-    /* set IR file */
-    if (filename != NULL) {
-        /* use given filename */
-        ctx->conf->ir_filename = smalloc((char *)file);
-    } else {
-        /* use default filename */
-        if (ctx->conf->ir_filename != NULL) {
-            free(ctx->conf->ir_filename);
-        }
-        if (ctx->conf->ir_dir == NULL) {
-            ERROR("Set ir.dir at ptsc.conf. \n");
-            ctx->conf->ir_dir = smalloc("/tmp/.ptsc");
-        }
-        snprintf(filename, sizeof(filename), "%s_%s.xml",
-            ctx->str_uuid,
-            str_ir_uuid);
 
-        ctx->conf->ir_filename = getFullpathName(ctx->conf->ir_dir, filename);
-    }
-#endif
-    if (ctx->ir_filename != NULL) {
+
+    /* check filename */
+    if (filenameDP != NULL) {
         /* use given filename  for the Unit Test*/
-        // filename = smalloc(ctx->conf->ir_filename);        filename = ctx->conf->ir_filename;
     } else {
+        /* create new IR filename, save to ctx->ir_filename */
         char buf[1024];
         /* use default filename */
         if (ctx->conf->ir_dir == NULL) {
-            ERROR("Set ir.dir in %s.\n", ctx->conf->config_file);
+            LOG(LOG_ERR, "Set ir.dir in %s.\n", ctx->conf->config_file);
             ctx->conf->ir_dir = smalloc("/tmp/.ptsc");
         }
         snprintf(buf, sizeof(buf), "%s_%s.xml",
@@ -1926,32 +2016,17 @@ int writeIr(OPENPTS_CONTEXT *ctx, const char *filenameDP, int *savedFd) {
             str_ir_uuid);
 
         ctx->ir_filename = getFullpathName(ctx->conf->ir_dir, buf);
+        filenameDP = ctx->ir_filename;
     }
 
-    filename = ctx->ir_filename;
-    DEBUG("Write Integrity Report (IR)  : %s\n", filename);
+    DEBUG("Write Integrity Report (IR)  : %s\n", filenameDP);
 
     /* write to file */
     xmlFreeTextWriter(writer);
 
-#if 0
-    fp = fopen(ctx->conf->ir_filename, "w");
-    if (fp == NULL) {
-        ERROR("testXmlwriterMemory: Error at fopen, %s\n", ctx->conf->ir_filename);
-        rc = PTS_INTERNAL_ERROR;
-        goto free;
-    }
-
-    fprintf(fp, "%s", (const char *) xmlbuf->content);
-
-    rc = PTS_SUCCESS;  // 0
-
-    fclose(fp);
-#endif
-
-    irFd = open(filename, O_CREAT | O_EXCL | O_RDWR, S_IRUSR | S_IWUSR);
+    irFd = open(filenameDP, O_CREAT | O_EXCL | O_RDWR, S_IRUSR | S_IWUSR);
     if (-1 == irFd) {
-        ERROR("Failed to open ir file '%s' for writing, errno = %d\n", filename, errno);
+        LOG(LOG_ERR, "Failed to open ir file '%s' for writing, errno = %d\n", filename, errno);
         rc = PTS_INTERNAL_ERROR;
         goto free;
     }
@@ -1961,15 +2036,15 @@ int writeIr(OPENPTS_CONTEXT *ctx, const char *filenameDP, int *savedFd) {
        This is most useful during verification when running "ptsc -m". Anyway,
        serious hackers probably wouldn't be deterred by this ... */
     if (NULL != savedFd &&
-        -1 == unlink(filename)) {
-        ERROR("Failed to unlink file '%s', errno = %d\n", filename, errno);
+        -1 == unlink(filenameDP)) {
+        LOG(LOG_ERR, "Failed to unlink file '%s', errno = %d\n", filename, errno);
     }
 
     lengthOfIrFile = xmlbuf->use;
     {
         int writeRc = write(irFd, xmlbuf->content, lengthOfIrFile);
         if ( lengthOfIrFile != writeRc ) {
-            ERROR("Failed to write contents to IR file - rc %d, errno %d\n", writeRc, errno);
+            LOG(LOG_ERR, "Failed to write contents to IR file - rc %d, errno %d\n", writeRc, errno);
             rc = PTS_INTERNAL_ERROR;
             close(irFd);
         } else {
@@ -1986,14 +2061,11 @@ int writeIr(OPENPTS_CONTEXT *ctx, const char *filenameDP, int *savedFd) {
  free:
     xfree(ir_uuid);
     xfree(str_ir_uuid);
-    //if (filename != NULL) xfree(filename);
 
  freexml:
     xmlBufferFree(xmlbuf);
 
  error:
-
-    
     DEBUG_CAL("writeIr - done\n");
 
     return rc;
@@ -2036,6 +2108,12 @@ void  irStartDocument(void * ctx) {
     OPENPTS_CONTEXT * pctx = (OPENPTS_CONTEXT *)ctx;
     OPENPTS_IR_CONTEXT * ir_ctx = pctx->ir_ctx;
 
+    /* check */
+    if (ctx == NULL) {
+        LOG(LOG_ERR, "null input");
+        return;
+    }
+
     ir_ctx->sax_error = 0;
     ir_ctx->event_index = 0;
 
@@ -2047,7 +2125,11 @@ void  irStartDocument(void * ctx) {
  * SAX parser
  */
 void  irEndDocument(void * ctx) {
-    // printf("END DOC \n");
+    /* check */
+    if (ctx == NULL) {
+        LOG(LOG_ERR, "null input");
+        return;
+    }
 }
 
 /* This prevents real world buffer over-run attacks using malformed IRs
@@ -2056,6 +2138,14 @@ void  irEndDocument(void * ctx) {
    wrongly into presenting a valid attestation of a compromised system. */
 static int getPcrIndexFromIR(char *value) {
     unsigned int index = atoi(value);
+
+    /* check */
+    if (value == NULL) {
+        LOG(LOG_ERR, "null input");
+        return -1;
+    }
+
+    index = atoi(value);
     if ( index > MAX_PCRNUM ) {
         return -1;
     } else {
@@ -2067,16 +2157,39 @@ static int getPcrIndexFromIR(char *value) {
  * SAX parser - Start of Element
  */
 void  irStartElement(void* ctx, const xmlChar* name, const xmlChar** atts) {
-    OPENPTS_CONTEXT * pctx = (OPENPTS_CONTEXT *)ctx;
-    OPENPTS_IR_CONTEXT * ir_ctx = pctx->ir_ctx;
-    TSS_VALIDATION *validation_data = pctx->validation_data;
-    OPENPTS_PCRS *pcrs = pctx->pcrs;
+    OPENPTS_CONTEXT * pctx;
+    OPENPTS_IR_CONTEXT * ir_ctx;
+    TSS_VALIDATION *validation_data;
+    OPENPTS_PCRS *pcrs;
     BYTE *b64buf = NULL;
     int b64buf_len;
     int i;
     char *type;
     char *value;
 
+    /* check */
+    if (ctx == NULL) {
+        LOG(LOG_ERR, "null input");
+        return;
+    }
+    pctx = (OPENPTS_CONTEXT *)ctx;
+    ir_ctx = pctx->ir_ctx;
+    if (ir_ctx == NULL) {
+        LOG(LOG_ERR, "null input");
+        return;
+    }
+    pcrs = pctx->pcrs;
+    if (pcrs == NULL) {
+        LOG(LOG_ERR, "null input");
+        return;
+    }
+    if (name == NULL) {
+        LOG(LOG_ERR, "null input");
+        return;
+    }
+    validation_data = pctx->validation_data;  // ckeck later
+
+    /* IR */
     ir_ctx->char_size = 0;
 
     if (!strcmp((char *)name, "Report")) {
@@ -2099,33 +2212,31 @@ void  irStartElement(void* ctx, const xmlChar* name, const xmlChar** atts) {
         //
     } else if (!strcmp((char *)name, "pcrindex")) {
         /* stuff:Hash -> PCR value (base64) */
-        // printf("START ELEMENT [%s]  <<<< HASH HASH \n",name);
+        // DEBUG("START ELEMENT [%s]  <<<< HASH HASH \n",name);
         // ir_ctx->sax_state = IR_SAX_STATE_PCR_INDEX;
 
     } else if (!strcmp((char *)name, "eventtype")) {
-        // printf("START ELEMENT [%s]  <<<< HASH HASH \n",name);
+        // DEBUG("START ELEMENT [%s]  <<<< HASH HASH \n",name);
         // ir_ctx->sax_state = IR_SAX_STATE_EVENT_TYPE;
 
     } else if (!strcmp((char *)name, "stuff:Hash")) {
-        // printf("START ELEMENT [%s]  <<<< DIGEST \n",name);
+        // DEBUG("START ELEMENT [%s]  <<<< DIGEST \n",name);
         // ir_ctx->sax_state = IR_SAX_STATE_DIGEST;
 
     } else if (!strcmp((char *)name, "eventdata")) {
-        // printf("START ELEMENT [%s]  <<<<  EVENT_DATA\n",name);
+        // DEBUG("START ELEMENT [%s]  <<<<  EVENT_DATA\n",name);
         // ir_ctx->sax_state = IR_SAX_STATE_EVENT_DATA;
 
     } else if (!strcmp((char *)name, "PcrHash")) {
-        // printf("START ELEMENT [%s]  <<<<  EVENT_DATA\n",name);
+        // DEBUG("START ELEMENT [%s]  <<<<  EVENT_DATA\n",name);
         // ir_ctx->sax_state = IR_SAX_STATE_PCR;
 
         /* get Number =pcrindex) attribute ( */
         if (atts != NULL) {
             for (i = 0;(atts[i] != NULL);i++) {
                 type = (char *)atts[i++];
-                // printf(", %s='", type);
                 if (atts[i] != NULL) {
                     value= (char *)atts[i];
-                    // printf("%s'", value);
                     if (!strcmp(type, "Number")) {
                         ir_ctx->pcr_index = getPcrIndexFromIR(value);
                     }
@@ -2174,10 +2285,8 @@ void  irStartElement(void* ctx, const xmlChar* name, const xmlChar** atts) {
         if (atts != NULL) {
             for (i = 0;(atts[i] != NULL);i++) {
                 type = (char *)atts[i++];
-                // printf(", %s='", type);
                 if (atts[i] != NULL) {
                     value= (char *)atts[i];
-                    // printf("%s'", value);
                     if (!strcmp(type, "SizeOfSelect")) {
                         /* TPM1.2 - 24 PCRS -> 3 */
                         pcrs->pcr_select_size = atoi(value);
@@ -2187,7 +2296,7 @@ void  irStartElement(void* ctx, const xmlChar* name, const xmlChar** atts) {
                     if (!strcmp(type, "PcrSelect")) {
                         /* used later */
                         if (b64buf != NULL) {
-                            ERROR("bad memory management");
+                            LOG(LOG_ERR, "bad memory management");
                             free(b64buf);
                         }
                         b64buf = (BYTE *) decodeBase64(
@@ -2197,7 +2306,7 @@ void  irStartElement(void* ctx, const xmlChar* name, const xmlChar** atts) {
                         // attr_cnt++;
                         // DEBUG("PcrSelect = 0x%02x %02x %02x \n", buf[0],buf[1],buf[2]);
                         if (b64buf == NULL) {
-                            ERROR("Failed to decode base64 string\n");
+                            LOG(LOG_ERR, "Failed to decode base64 string\n");
                             ir_ctx->sax_error++;
                             pcrs->pcr_select_size = 0;
                         } else {
@@ -2219,14 +2328,14 @@ void  irStartElement(void* ctx, const xmlChar* name, const xmlChar** atts) {
                 if (b64buf != NULL) {
                     memcpy(pcrs->pcr_select_byte, b64buf, pcrs->pcr_select_size);
                 } else {
-                    ERROR("pcr_select_byte is missing");
+                    LOG(LOG_ERR, "pcr_select_byte is missing");
                 }
             } else {
-                ERROR("no memory\n");
+                LOG(LOG_ERR, "no memory\n");
             }
         } else {
             /* BAD IR */
-            ERROR("BAD IR SizeOfSelect or PcrSelect are missing\n");
+            LOG(LOG_ERR, "BAD IR SizeOfSelect or PcrSelect are missing\n");
         }
         /* free Base64 buffer */
         if (b64buf != NULL) {
@@ -2243,10 +2352,8 @@ void  irStartElement(void* ctx, const xmlChar* name, const xmlChar** atts) {
         if (atts != NULL) {
             for (i = 0;(atts[i] != NULL);i++) {
                 type = (char *)atts[i++];
-                // printf(", %s='", type);
                 if (atts[i] != NULL) {
                     value= (char *)atts[i];
-                    // printf("%s'", value);
                     if (!strcmp(type, "PcrNumber")) {
                         ir_ctx->pcr_index = getPcrIndexFromIR(value);
                     }
@@ -2265,16 +2372,18 @@ void  irStartElement(void* ctx, const xmlChar* name, const xmlChar** atts) {
             for (i = 0;(atts[i] != NULL);i++) {
                 type = (char *)atts[i++];
 
+                if (validation_data == NULL) {
+                    LOG(LOG_ERR, "validation_data == NULL");
+                    return;
+                }
                 if (validation_data->rgbData == NULL) {
                     // TODO 1.2 only
                     validation_data->ulDataLength = 48;
                     validation_data->rgbData = xmalloc_assert(48);
                 }
 
-                // printf(", %s='", type);
                 if (atts[i] != NULL) {
                     value= (char *)atts[i];
-                    // printf("%s'", value);
                     if (!strcmp(type, "VersionMajor")) {
                         validation_data->versionInfo.bMajor = atoi(value);
                         validation_data->rgbData[0] = atoi(value);
@@ -2305,14 +2414,14 @@ void  irStartElement(void* ctx, const xmlChar* name, const xmlChar** atts) {
                             strlen(value),
                             &b64buf_len);
                         if (b64buf == NULL) {
-                            ERROR("decodeBase64 fail");
+                            LOG(LOG_ERR, "decodeBase64 fail");
                             ir_ctx->sax_error++;
                             return;  // TODO  return?
                         }
                         if (b64buf_len == 20) {
                             memcpy(&validation_data->rgbData[8], b64buf, 20);
                         } else {
-                            ERROR("size of decodeBase64 out is not 20 but %d", b64buf_len);
+                            LOG(LOG_ERR, "size of decodeBase64 out is not 20 but %d", b64buf_len);
                             ir_ctx->sax_error++;
                             return;  // TODO
                         }
@@ -2325,7 +2434,7 @@ void  irStartElement(void* ctx, const xmlChar* name, const xmlChar** atts) {
                             strlen(value),
                             &b64buf_len);
                         if (b64buf == NULL) {
-                            ERROR("decodeBase64 fail");
+                            LOG(LOG_ERR, "decodeBase64 fail");
                             ir_ctx->sax_error++;
                             return;  // TODO
                         }
@@ -2339,7 +2448,7 @@ void  irStartElement(void* ctx, const xmlChar* name, const xmlChar** atts) {
                             // memcpy(validation_data->rgbExternalData, buf, rc);
                             memcpy(&validation_data->rgbData[28], b64buf, 20);
                         } else {
-                            ERROR("Failed to decode base64 string, len = %d not 20\n", b64buf_len);
+                            LOG(LOG_ERR, "Failed to decode base64 string, len = %d not 20\n", b64buf_len);
                             ir_ctx->sax_error++;
                             return;  // TODO
                         }
@@ -2353,16 +2462,18 @@ void  irStartElement(void* ctx, const xmlChar* name, const xmlChar** atts) {
             for (i = 0;(atts[i] != NULL);i++) {
                 type = (char *)atts[i++];
 
+                if (validation_data == NULL) {
+                    LOG(LOG_ERR, "validation_data == NULL");
+                    return;
+                }
                 if (validation_data->rgbData == NULL) {
                     // TODO 1.2 only
                     validation_data->ulDataLength = 52;
                     validation_data->rgbData = xmalloc_assert(52);
                 }
 
-                // printf(", %s='", type);
                 if (atts[i] != NULL) {
                     value= (char *)atts[i];
-                    // printf("%s'", value);
                     if (!strcmp(type, "Tag")) {
                         int tag = atoi(value);
                         validation_data->rgbData[0] = (tag >> 8) & 0xFF;
@@ -2381,7 +2492,7 @@ void  irStartElement(void* ctx, const xmlChar* name, const xmlChar** atts) {
                             strlen(value),
                             &b64buf_len);
                         if (b64buf == NULL) {
-                            ERROR("decodeBase64 fail");
+                            LOG(LOG_ERR, "decodeBase64 fail");
                             ir_ctx->sax_error++;
                             return;
                         }
@@ -2391,7 +2502,7 @@ void  irStartElement(void* ctx, const xmlChar* name, const xmlChar** atts) {
                             // memcpy(validation_data->rgbExternalData, b64buf, rc);
                             memcpy(&validation_data->rgbData[6], b64buf, 20);
                         } else {
-                            ERROR("Failed to decode base64 string, len = %d not 20\n", b64buf_len);
+                            LOG(LOG_ERR, "Failed to decode base64 string, len = %d not 20\n", b64buf_len);
                             ir_ctx->sax_error++;
                             return;  // TODO
                         }
@@ -2410,13 +2521,13 @@ void  irStartElement(void* ctx, const xmlChar* name, const xmlChar** atts) {
     } else if (!strcmp((char *)name, "SignatureMethod")) {
         // TODO check alg
     } else if (!strcmp((char *)name, "SignatureValue")) {
-        // DONE TODO("get value(base64)\n");
+        // DONE LOG(LOG_TODO, "get value(base64)\n");
     } else if (!strcmp((char *)name, "KeyInfo")) {
         // TODO
     } else if (!strcmp((char *)name, "KeyValue")) {
-        // DONE TODO("get value(base64)\n");
+        // DONE LOG(LOG_TODO, "get value(base64)\n");
     } else { /* Else? */
-        ERROR("START ELEMENT [%s] \n", name);
+        LOG(LOG_ERR, "START ELEMENT [%s] \n", name);
         ir_ctx->sax_state = IR_SAX_STATE_IDOL;
     }
 }
@@ -2425,14 +2536,37 @@ void  irStartElement(void* ctx, const xmlChar* name, const xmlChar** atts) {
  * SAX parser - End of Element
  */
 void irEndElement(void * ctx, const xmlChar * name) {
-    OPENPTS_CONTEXT * pctx = (OPENPTS_CONTEXT *)ctx;
-    OPENPTS_IR_CONTEXT * ir_ctx = pctx->ir_ctx;
-    TSS_VALIDATION *validation_data = pctx->validation_data;
-    OPENPTS_PCRS *pcrs = pctx->pcrs;
+    OPENPTS_CONTEXT * pctx;
+    OPENPTS_IR_CONTEXT * ir_ctx;
+    TSS_VALIDATION *validation_data;
+    OPENPTS_PCRS *pcrs;
     int rc;
     BYTE *b64buf = NULL;
     int b64buf_len;
 
+    /* check */
+    if (ctx == NULL) {
+        LOG(LOG_ERR, "null input");
+        return;
+    }
+    pctx = (OPENPTS_CONTEXT *)ctx;
+    ir_ctx = pctx->ir_ctx;
+    if (ir_ctx == NULL) {
+        LOG(LOG_ERR, "null input");
+        return;
+    }
+    pcrs = pctx->pcrs;
+    if (pcrs == NULL) {
+        LOG(LOG_ERR, "null input");
+        return;
+    }
+    if (name == NULL) {
+        LOG(LOG_ERR, "null input");
+        return;
+    }
+    validation_data = pctx->validation_data;  // ckeck later
+
+    /* END ELEMENT */
     if (!strcmp((char *)name, "stuff:Objects")) {
         int extend = 0;
         int pcr_index = -1;
@@ -2454,7 +2588,7 @@ void irEndElement(void * ctx, const xmlChar * name) {
 
         /* set the event structure */
         if (ir_ctx->event == NULL) {
-            ERROR("internal error\n");
+            LOG(LOG_ERR, "internal error\n");
             ir_ctx->ew_new->event = NULL;
             ir_ctx->sax_error++;
         } else {
@@ -2471,7 +2605,7 @@ void irEndElement(void * ctx, const xmlChar * name) {
         /* map to the snapshot, push FSM  */
         rc = addEventToSnapshotBin(pctx, ir_ctx->ew_new);  // iml.c
         if (rc != PTS_SUCCESS) {
-            // ERROR("validateIr:irStartElement - addEventToSnapshotBin rc = %d\n", rc);
+            // LOG(LOG_ERR, "validateIr:irStartElement - addEventToSnapshotBin rc = %d\n", rc);
             ir_ctx->integrity = OPENPTS_RESULT_INVALID;
             return;
         }
@@ -2493,7 +2627,7 @@ void irEndElement(void * ctx, const xmlChar * name) {
             DEBUG_FSM("irEndElement() -- SS has validation error\n");
             ir_ctx->fsm_error_count++;
         } else if (rc != PTS_SUCCESS) {
-            ERROR("SnapshotCollection -> FSM flash was fail\n");
+            LOG(LOG_ERR, "SnapshotCollection -> FSM flash was fail\n");
             ir_ctx->sax_error++;
             return;
         }
@@ -2509,7 +2643,7 @@ void irEndElement(void * ctx, const xmlChar * name) {
             ir_ctx->char_size,
             &b64buf_len);
         if (ir_ctx->event->rgbPcrValue == NULL) {
-            ERROR("decodeBase64 fail");
+            LOG(LOG_ERR, "decodeBase64 fail");
             ir_ctx->sax_error++;
             return;  // TODO
         } else {
@@ -2526,7 +2660,7 @@ void irEndElement(void * ctx, const xmlChar * name) {
             ir_ctx->char_size,
             &b64buf_len);
         if (ir_ctx->event->rgbEvent == NULL) {
-            ERROR("decodeBase64 fail");
+            LOG(LOG_ERR, "decodeBase64 fail");
             ir_ctx->sax_error++;
             return;  // TODO
         } else {
@@ -2541,12 +2675,12 @@ void irEndElement(void * ctx, const xmlChar * name) {
             ir_ctx->char_size,
             &b64buf_len);
         if (b64buf == NULL) {
-            ERROR("decodeBase64 fail");
+            LOG(LOG_ERR, "decodeBase64 fail");
             ir_ctx->sax_error++;
             return;  // TODO
         }
         if (b64buf_len > MAX_DIGEST_SIZE) {
-            ERROR("decodeBase64 out is too latge, %d > %d",
+            LOG(LOG_ERR, "decodeBase64 out is too latge, %d > %d",
                 b64buf_len, MAX_DIGEST_SIZE);
             ir_ctx->sax_error++;
             return;  // TODO
@@ -2556,8 +2690,8 @@ void irEndElement(void * ctx, const xmlChar * name) {
         free(b64buf);
         /* Check with PCR in TPM */
         rc = checkTpmPcr2(&pctx->tpm, ir_ctx->pcr_index, ir_ctx->pcr);
-        if (rc != 0) {
-            ERROR("ERROR PCR[%d] != IML\n", ir_ctx->pcr_index);
+        if (rc != PTS_SUCCESS) {
+            LOG(LOG_ERR, "ERROR PCR[%d] != IML\n", ir_ctx->pcr_index);
             ir_ctx->sax_error = 1;
             // verbose = DEBUG_FLAG | DEBUG_TPM_FLAG;  // switch DEBUG MODE
             if (isDebugFlagSet(DEBUG_FLAG)) {
@@ -2576,10 +2710,10 @@ void irEndElement(void * ctx, const xmlChar * name) {
             if (pctx->conf->iml_mode == 0) {
                 if (pcrs == NULL) {
                     /* malloc OPENPTS_PCRS */
-                    // ERROR("PCR is not intialized - No QuoteData element\n");
+                    // LOG(LOG_ERR, "PCR is not intialized - No QuoteData element\n");
                     pcrs = xmalloc(sizeof(OPENPTS_PCRS));
                     if (pcrs == NULL) {
-                        ERROR("no memory\n");
+                        LOG(LOG_ERR, "no memory\n");
                         return;
                     }
                     memset(pcrs, 0, sizeof(OPENPTS_PCRS));
@@ -2595,15 +2729,23 @@ void irEndElement(void * ctx, const xmlChar * name) {
         }
     } else if (!strcmp((char *)name, "LocalityAtRelease")) {
         // TODO
+        if (validation_data == NULL) {
+            LOG(LOG_ERR, "validation_data == NULL");
+            return;
+        }
         validation_data->rgbData[31] = atoi(ir_ctx->buf);
     } else if (!strcmp((char *)name, "CompositeHash")) {
         // DEBUG("CompositeHash %s", ir_ctx->buf);
+        if (validation_data == NULL) {
+            LOG(LOG_ERR, "validation_data == NULL");
+            return;
+        }
         b64buf = decodeBase64(
             (char *)ir_ctx->buf,
             ir_ctx->char_size,
             &b64buf_len);
         if (b64buf == NULL) {
-            ERROR("decodeBase64 fail");
+            LOG(LOG_ERR, "decodeBase64 fail");
             ir_ctx->sax_error++;
             return;
         }
@@ -2623,17 +2765,17 @@ void irEndElement(void * ctx, const xmlChar * name) {
             ir_ctx->char_size,
             &b64buf_len);
         if (b64buf == NULL) {
-            ERROR("decodeBase64 fail");
+            LOG(LOG_ERR, "decodeBase64 fail");
             ir_ctx->sax_error++;
             return;
         }
         if (b64buf_len < SHA1_DIGEST_SIZE) {
-            ERROR("decodeBase64 outout is too small, %d < %d", b64buf_len, SHA1_DIGEST_SIZE);
+            LOG(LOG_ERR, "decodeBase64 outout is too small, %d < %d", b64buf_len, SHA1_DIGEST_SIZE);
             ir_ctx->sax_error++;
             return;
         }
         if (b64buf_len > MAX_DIGEST_SIZE) {
-            ERROR("decodeBase64 outout is too large, %d < %d", b64buf_len, MAX_DIGEST_SIZE);
+            LOG(LOG_ERR, "decodeBase64 outout is too large, %d < %d", b64buf_len, MAX_DIGEST_SIZE);
             ir_ctx->sax_error++;
             return;
         }
@@ -2667,8 +2809,12 @@ void irEndElement(void * ctx, const xmlChar * name) {
     } else if (!strcmp((char *)name, "QuoteInfo2")) {
         /* pcr select => validation_data */
         if (pcrs->pcr_select_byte == NULL) {
-            ERROR("pcrs->pcr_select_byte is null");
+            LOG(LOG_ERR, "pcrs->pcr_select_byte is null");
         } else {
+            if (validation_data == NULL) {
+                LOG(LOG_ERR, "validation_data == NULL");
+                return;
+            }
             validation_data->rgbData[26] = 0;
             validation_data->rgbData[27] = pcrs->pcr_select_size;
             validation_data->rgbData[28] = pcrs->pcr_select_byte[0];
@@ -2678,9 +2824,13 @@ void irEndElement(void * ctx, const xmlChar * name) {
     } else if (!strcmp((char *)name, "SignatureValue")) {
         ir_ctx->buf[ir_ctx->char_size] = 0;
         if (ir_ctx->char_size > IR_SAX_BUFFER_SIZE) {  // TODO check buf size
-            ERROR("buf is small %d \n", ir_ctx->char_size);
+            LOG(LOG_ERR, "buf is small %d \n", ir_ctx->char_size);
             ir_ctx->sax_error++;
         } else {
+            if (validation_data == NULL) {
+                LOG(LOG_ERR, "validation_data == NULL");
+                return;
+            }
             if (validation_data->rgbValidationData != NULL) {
                 xfree(validation_data->rgbValidationData);
             }
@@ -2690,7 +2840,7 @@ void irEndElement(void * ctx, const xmlChar * name) {
                 ir_ctx->char_size,
                 &b64buf_len);
             if (validation_data->rgbValidationData == NULL) {
-                ERROR("decodeBase64 fail");
+                LOG(LOG_ERR, "decodeBase64 fail");
                 ir_ctx->sax_error++;
                 return;  // TODO
             }
@@ -2699,14 +2849,14 @@ void irEndElement(void * ctx, const xmlChar * name) {
     } else if (!strcmp((char *)name, "KeyValue")) {
         ir_ctx->buf[ir_ctx->char_size] = 0;
         if (ir_ctx->char_size > IR_SAX_BUFFER_SIZE) {  // TODO check buf size
-            ERROR("buf is small %d \n", ir_ctx->char_size);
+            LOG(LOG_ERR, "buf is small %d \n", ir_ctx->char_size);
         } else {
             pcrs->pubkey = decodeBase64(
                 (char *)ir_ctx->buf,
                 ir_ctx->char_size,
                 &b64buf_len);
             if (pcrs->pubkey == NULL) {
-                ERROR("decodeBase64 fail");
+                LOG(LOG_ERR, "decodeBase64 fail");
                 ir_ctx->sax_error++;
                 return;
             }
@@ -2717,22 +2867,22 @@ void irEndElement(void * ctx, const xmlChar * name) {
         /* Validate QuoteData */
 
         if ( ir_ctx->sax_error > 0 ) {
-            ERROR("Unable to validate quote data due to %d SAX parse errors\n", ir_ctx->sax_error);
+            LOG(LOG_ERR, "Unable to validate quote data due to %d SAX parse errors\n", ir_ctx->sax_error);
         } else {
             rc = validateQuoteData(pcrs, validation_data);
             // DEBUG("validateQuoteData = %d\n", rc);
             if (rc != PTS_SUCCESS) {
-                ERROR("---------------------------------------------------------------------------\n");
-                ERROR("BAD QUOTE DATA!!!  BAD QUOTE DATA!!!  BAD QUOTE DATA!!!  BAD QUOTE DATA!!!\n");
-                ERROR("---------------------------------------------------------------------------\n");
+                LOG(LOG_ERR, "---------------------------------------------------------------------------\n");
+                LOG(LOG_ERR, "BAD QUOTE DATA!!!  BAD QUOTE DATA!!!  BAD QUOTE DATA!!!  BAD QUOTE DATA!!!\n");
+                LOG(LOG_ERR, "---------------------------------------------------------------------------\n");
                 addProperty(pctx, "tpm.quote.signature", "invalid");
                 // TODO set error
                 ir_ctx->bad_quote = 1;
             } else {
 #if 0
-                TODO("---------------------------------------------------------------------------\n");
-                TODO("GOOD QUOTE DATA!!! GOOD QUOTE DATA!!! GOOD QUOTE DATA!!! GOOD QUOTE DATA!!!\n");
-                TODO("---------------------------------------------------------------------------\n");
+                LOG(LOG_TODO, "---------------------------------------------------------------------------\n");
+                LOG(LOG_TODO, "GOOD QUOTE DATA!!! GOOD QUOTE DATA!!! GOOD QUOTE DATA!!! GOOD QUOTE DATA!!!\n");
+                LOG(LOG_TODO, "---------------------------------------------------------------------------\n");
 #endif
                 addProperty(pctx, "tpm.quote.signature", "valid");
             }
@@ -2741,7 +2891,6 @@ void irEndElement(void * ctx, const xmlChar * name) {
         pctx->conf->ir_without_quote = 0;
     } else {
         /* Else? */
-        // printf("END ELEMENT [%s] ",name);
     }
 
     ir_ctx->sax_state = IR_SAX_STATE_IDOL;
@@ -2754,13 +2903,30 @@ void irEndElement(void * ctx, const xmlChar * name) {
  * 
  */
 void irCharacters(void* ctx, const xmlChar * ch, int len) {
-    OPENPTS_CONTEXT * pctx = (OPENPTS_CONTEXT *)ctx;
-    OPENPTS_IR_CONTEXT * ir_ctx = pctx->ir_ctx;
+    OPENPTS_CONTEXT * pctx;
+    OPENPTS_IR_CONTEXT * ir_ctx;
+
+    /* check */
+    if (ctx == NULL) {
+        LOG(LOG_ERR, "null input");
+        return;
+    }
+    pctx = (OPENPTS_CONTEXT *)ctx;
+    ir_ctx = pctx->ir_ctx;
+    if (ir_ctx == NULL) {
+        LOG(LOG_ERR, "null input");
+        return;
+    }
+    if ((len > 0) && (ch == NULL)) {
+        LOG(LOG_ERR, "null input");
+        return;
+    }
+
 
     /* copy to buf at ir_ctx, but check length first, ensuring additional space
        for NULL terminator */
     if ((ir_ctx->char_size + len + 1) > EVENTDATA_BUF_SIZE) {
-        ERROR("Buffer for EVENTDATA is too small, %d + %d > %d\n", ir_ctx->char_size, len, EVENTDATA_BUF_SIZE);
+        LOG(LOG_ERR, "Buffer for EVENTDATA is too small, %d + %d > %d\n", ir_ctx->char_size, len, EVENTDATA_BUF_SIZE);
         return;
     }
     memcpy(&ir_ctx->buf[ir_ctx->char_size], ch, len);
@@ -2808,11 +2974,23 @@ int validateIr(OPENPTS_CONTEXT *ctx) {
     DEBUG("validateIr - start\n");
 
     /* check */
-    ASSERT(NULL != ctx, "ctx == NULL\n");
-    ASSERT(NULL != ctx->target_conf, "ctx->target_conf == NULL\n");
-    ASSERT(NULL != ctx->ir_filename, "ctx->ir_filename == NULL\n");
-
+    if (ctx == NULL) {
+        LOG(LOG_ERR, "null input");
+        return PTS_FATAL;
+    }
+    if (ctx->target_conf == NULL) {
+        LOG(LOG_ERR, "null input");
+        return PTS_FATAL;
+    }
+    if (ctx->ir_filename == NULL) {
+        LOG(LOG_ERR, "null input");
+        return PTS_FATAL;
+    }
     conf = ctx->target_conf;
+    if (conf == NULL) {
+        LOG(LOG_ERR, "null input");
+        return PTS_FATAL;
+    }
 
     /* new */
     if (ctx->pcrs == NULL) {
@@ -2857,7 +3035,7 @@ int validateIr(OPENPTS_CONTEXT *ctx) {
             // DEBUG("loadSQLiteDatabaseFile %s\n", ctx->conf->aide_sqlite_filename);
             rc = loadSQLiteDatabaseFile(ctx->aide_ctx, conf->aide_sqlite_filename);
             if (rc != PTS_SUCCESS) {
-                ERROR("loadSQLiteDatabaseFile fail\n");
+                LOG(LOG_ERR, "loadSQLiteDatabaseFile fail\n");
                 rc = PTS_FATAL;
                 goto free;
             }
@@ -2867,7 +3045,7 @@ int validateIr(OPENPTS_CONTEXT *ctx) {
 #endif
         } else {
             // pre loaded (see iml2aide.c)
-            TODO("AIDE DB pre loaded\n");
+            LOG(LOG_TODO, "AIDE DB pre loaded\n");
         }
 
         if (ctx->conf->aide_ignorelist_filename != NULL) {
@@ -2900,7 +3078,7 @@ int validateIr(OPENPTS_CONTEXT *ctx) {
     }
 
     // DEBUG("validatePcrComposite, ctx->conf->ir_without_quote %d\n", ctx->conf->ir_without_quote);
-    // ERROR("conf->pubkey_length %d\n",conf->pubkey_length);
+    // LOG(LOG_ERR, "conf->pubkey_length %d\n",conf->pubkey_length);
 
     /* validate PCR values by QuoteData */
     if ((conf->iml_mode == 0) && (conf->ir_without_quote == 0)) {
@@ -2939,7 +3117,7 @@ int validateIr(OPENPTS_CONTEXT *ctx) {
                 addProperty(ctx, "tpm.quote.pcrs", "invalid");
             }
         } else {
-            ERROR("PUBKEY is missing\n");
+            LOG(LOG_ERR, "PUBKEY is missing\n");
             addProperty(ctx, "tpm.quote.pcrs", "unknown");
         }
     } else {
@@ -3019,7 +3197,9 @@ int validateIr(OPENPTS_CONTEXT *ctx) {
  * @retval PTS_SUCCESS
  * @retval PTS_INTERNAL_ERROR
  */
-int genIrFromSecurityfs(OPENPTS_CONTEXT *ctx, int *savedFd) {
+int genIrFromSecurityfs(
+    OPENPTS_CONTEXT *ctx,
+    int *savedFd /* out*/ ) {
     int rc;
     /* get IML via securityfs */
 
@@ -3030,6 +3210,12 @@ int genIrFromSecurityfs(OPENPTS_CONTEXT *ctx, int *savedFd) {
     DEBUG("TPM Quote not work with config option iml.mode=securityfs\n");
 #endif
 
+    /* check */
+    if (ctx == NULL) {
+        LOG(LOG_ERR, "null input");
+        return PTS_FATAL;
+    }
+
     /* reset TPM emu */
     resetTpm(&ctx->tpm, ctx->drtm);
 
@@ -3039,14 +3225,14 @@ int genIrFromSecurityfs(OPENPTS_CONTEXT *ctx, int *savedFd) {
     /* setup FSM */
     rc = readFsmFromPropFile(ctx, ctx->conf->config_file);
     if (rc != PTS_SUCCESS) {
-        ERROR("readFsmFromPropFile %s failed\n", ctx->conf->config_file);
+        LOG(LOG_ERR, "readFsmFromPropFile %s failed\n", ctx->conf->config_file);
         return PTS_INTERNAL_ERROR;
     }
 
     /* read BIOS IML */
     rc = readBiosImlFile(ctx, ctx->conf->bios_iml_filename, ctx->conf->iml_endian);
     if (rc != PTS_SUCCESS) {
-        ERROR("fail to load BIOS IML, rc = %d\n", rc);
+        LOG(LOG_ERR, "fail to load BIOS IML, rc = %d\n", rc);
         return PTS_INTERNAL_ERROR;
     }
 
@@ -3056,7 +3242,7 @@ int genIrFromSecurityfs(OPENPTS_CONTEXT *ctx, int *savedFd) {
         rc = readImaImlFile(ctx, ctx->conf->runtime_iml_filename,
                 ctx->conf->runtime_iml_type, 0, &count);  // TODO endian?
         if (rc != PTS_SUCCESS) {
-            ERROR("fail to load IMA IML, rc = %d\n", rc);
+            LOG(LOG_ERR, "fail to load IMA IML, rc = %d\n", rc);
             return PTS_INTERNAL_ERROR;
         }
     }
@@ -3064,21 +3250,22 @@ int genIrFromSecurityfs(OPENPTS_CONTEXT *ctx, int *savedFd) {
     /* read PCRS */
     rc = getPcrBySysfsFile(ctx, ctx->conf->pcrs_filename);
     if (rc < 0) {
-        ERROR("fail to load PCR, rc = %d -- (pcr file is missing)\n", rc);
-        TODO("Get or Create PCR file for this testcase\n");
+        LOG(LOG_ERR, "fail to load PCR, rc = %d -- (pcr file is missing)\n", rc);
+        LOG(LOG_TODO, "Get or Create PCR file for this testcase\n");
         // return -1;
     }
 
     // do not use tempnum,
     // if (ctx->conf->ir_filename != NULL) {
-    //    ERROR("Redefining the IR file location %s", ctx->conf->ir_filename);
+    //    LOG(LOG_ERR, "Redefining the IR file location %s", ctx->conf->ir_filename);
     // }
     // ctx->conf->ir_filename = tempnam(NULL, "ir_");
 
-    /* save IR */
-    rc = writeIr(ctx, ctx->conf->ir_filename, savedFd);
+    /* save IR (new file in tmp dir) */
+    rc = writeIr(ctx, NULL, savedFd);
+    // rc = writeIr(ctx, ctx->ir_filename, savedFd);
     if (rc != 0) {
-        ERROR("fail to write IR, rc = %d\n", rc);
+        LOG(LOG_ERR, "fail to write IR, rc = %d\n", rc);
         return PTS_INTERNAL_ERROR;
     }
 
@@ -3092,9 +3279,17 @@ int genIrFromSecurityfs(OPENPTS_CONTEXT *ctx, int *savedFd) {
  * @retval PTS_SUCCESS
  * @retval PTS_INTERNAL_ERROR 
  */
-int genIrFromTss(OPENPTS_CONTEXT *ctx, int *savedFd) {
+int genIrFromTss(
+    OPENPTS_CONTEXT *ctx,
+    int *savedFd /* out */ ) {
     int rc;
 
+    /* check */
+    if (ctx == NULL) {
+        LOG(LOG_ERR, "null input");
+        return PTS_FATAL;
+    }
+
     /* get IML via securityfs */
 
     /* reset TPM emu */
@@ -3114,7 +3309,7 @@ int genIrFromTss(OPENPTS_CONTEXT *ctx, int *savedFd) {
     // pcrSelect is set at PCR with FSM
     rc = readFsmFromPropFile(ctx, ctx->conf->config_file);  // fsm.c
     if (rc != PTS_SUCCESS) {
-        ERROR("read FSM failed\n");
+        LOG(LOG_ERR, "read FSM failed\n");
         return PTS_INTERNAL_ERROR;
     }
 
@@ -3130,7 +3325,7 @@ int genIrFromTss(OPENPTS_CONTEXT *ctx, int *savedFd) {
         /* copy */
         ctx->validation_data->rgbExternalData = malloc(ctx->nonce->nonce_length);
         if (ctx->validation_data->rgbExternalData == NULL) {
-            ERROR("no memory");
+            LOG(LOG_ERR, "no memory");
             return PTS_FATAL;
         }
         memcpy(
@@ -3138,7 +3333,7 @@ int genIrFromTss(OPENPTS_CONTEXT *ctx, int *savedFd) {
             ctx->nonce->nonce,
             ctx->nonce->nonce_length);
     } else {
-        ERROR("genIrFromTss - nonce is missing, DH-nonce? \n");
+        LOG(LOG_ERR, "genIrFromTss - nonce is missing, DH-nonce? \n");
         ctx->validation_data->ulExternalDataLength = 0;
         ctx->validation_data->rgbExternalData = NULL;
     }
@@ -3151,7 +3346,7 @@ int genIrFromTss(OPENPTS_CONTEXT *ctx, int *savedFd) {
 
 
     if (ctx->conf->ir_without_quote == 1) {
-        TODO("skip TPM_Quote\n");
+        LOG(LOG_TODO, "skip TPM_Quote\n");
     } else {
         /* TPM Quote or TPM Quote2 */
         if (ctx->conf->tpm_quote_type == 1) {
@@ -3176,7 +3371,7 @@ int genIrFromTss(OPENPTS_CONTEXT *ctx, int *savedFd) {
                     ctx->validation_data);  // tss.c
         }
         if (rc != 0) {
-            ERROR("quoteTss fail, rc = 0x%04d\n", rc);
+            LOG(LOG_ERR, "quoteTss fail, rc = 0x%04d\n", rc);
             return PTS_INTERNAL_ERROR;
         }
     }
@@ -3184,27 +3379,25 @@ int genIrFromTss(OPENPTS_CONTEXT *ctx, int *savedFd) {
     /* set PCR to snapshot */
     rc = setPcrsToSnapshot(ctx, ctx->pcrs);  // TODO
     if (rc < 0) {
-        ERROR("fail to load PCR, rc = %d\n", rc);
+        LOG(LOG_ERR, "fail to load PCR, rc = %d\n", rc);
         return PTS_INTERNAL_ERROR;
     }
 
     /* get BIOS/IMA IML */
     rc = getIml(ctx, 0);
     if (rc < 0) {
-        ERROR("fail to load BIOS IML, rc = %d\n", rc);
+        LOG(LOG_ERR, "fail to load BIOS IML, rc = %d\n", rc);
         return PTS_INTERNAL_ERROR;
     }
 
     if (ctx->conf->ir_filename != NULL) {
-        ERROR("Redefining the IR file location %s", ctx->conf->ir_filename);
+        LOG(LOG_ERR, "Redefining the IR file location %s", ctx->conf->ir_filename);
     }
-    //ctx->conf->ir_filename = tempnam(NULL, "ir_");
-    //DEBUG("ctx->conf->ir_filename : %s\n", ctx->conf->ir_filename);
 
-    /* save IR */
-    rc = writeIr(ctx, ctx->conf->ir_filename, savedFd);  // ir.c
+    /* save IR (new file in tmp dir) */
+    rc = writeIr(ctx, NULL, savedFd);
     if (rc != 0) {
-        ERROR("fail to write IR, rc = %d\n", rc);
+        LOG(LOG_ERR, "fail to write IR, rc = %d\n", rc);
         return PTS_INTERNAL_ERROR;
     }
 
@@ -3218,22 +3411,33 @@ int genIrFromTss(OPENPTS_CONTEXT *ctx, int *savedFd) {
  * @retval PTS_SUCCESS
  * @retval PTS_INTERNAL_ERROR
  */
-int genIr(OPENPTS_CONTEXT *ctx, int *savedFd) {
+int genIr(
+    OPENPTS_CONTEXT *ctx,
+    int *savedFd /* out */) {
     int rc = PTS_INTERNAL_ERROR;
+
+    /* check */
+    if (ctx == NULL) {
+        LOG(LOG_ERR, "null input");
+        return PTS_FATAL;
+    }
+
+
+    /* gen */
     if (ctx->conf->iml_mode == 1) {
         rc = genIrFromSecurityfs(ctx, savedFd);
         if (rc != PTS_SUCCESS) {
-            ERROR("writePtsTlvToSock - gen IR failed\n");
+            LOG(LOG_ERR, "writePtsTlvToSock - gen IR failed\n");
             return rc;
         }
     } else {
 #ifdef CONFIG_NO_TSS
-        TODO("OpenPTS was build with --without-tss and config option iml.mode=tssand, skip IR gen.\n");
+        LOG(LOG_TODO, "OpenPTS was build with --without-tss and config option iml.mode=tssand, skip IR gen.\n");
 #else
         // DEBUG("get IML/PCR via TSS is not ready\n");
         rc = genIrFromTss(ctx, savedFd);
         if (rc != PTS_SUCCESS) {
-            ERROR("gen IR failed\n");
+            LOG(LOG_ERR, "gen IR failed\n");
             return rc;
         }
 #endif