Abort NFC initialization if chip type doesn't match to HAL implemetation.

Compare firmware versions on chip and HAL implemetation,
if mismatch, abort nfc initialization.

Change-Id: I3594e7a94ee927155d92a4b56bf4c732a6aff70a
diff --git a/halimpl/pn54x/common/phNfcCommon.h b/halimpl/pn54x/common/phNfcCommon.h
index 8e040d4..c0700b7 100644
--- a/halimpl/pn54x/common/phNfcCommon.h
+++ b/halimpl/pn54x/common/phNfcCommon.h
@@ -53,6 +53,12 @@
 #define PKU_LIB_PATH      FW_DLL_ROOT_DIR "libpn547_fw_pku"      FW_DLL_EXTENSION
 #endif
 
+#if(NFC_NXP_CHIP_TYPE == PN548C2)
+#define COMPILATION_MW "PN548C2"
+#else
+#define COMPILATION_MW "PN547C2"
+#endif
+
 /* HAL Version number (Updated as per release) */
 #define NXP_MW_VERSION_MAJ  (1U)
 #define NXP_MW_VERSION_MIN  (0U)
diff --git a/halimpl/pn54x/hal/phNxpNciHal.c b/halimpl/pn54x/hal/phNxpNciHal.c
index 55e72ec..15f74af 100644
--- a/halimpl/pn54x/hal/phNxpNciHal.c
+++ b/halimpl/pn54x/hal/phNxpNciHal.c
@@ -52,6 +52,9 @@
 uint32_t wFwVerRsp;
 /* External global variable to get FW version */
 extern uint16_t wFwVer;
+
+extern uint16_t fw_maj_ver;
+extern uint16_t rom_version;
 extern int send_to_upper_kovio;
 extern int kovio_detected;
 extern int disable_kovio;
@@ -92,6 +95,7 @@
 static void phNxpNciHal_enable_i2c_fragmentation();
 static NFCSTATUS phNxpNciHal_get_mw_eeprom (void);
 static NFCSTATUS phNxpNciHal_set_mw_eeprom (void);
+static int phNxpNciHal_fw_mw_ver_check ();
 NFCSTATUS phNxpNciHal_check_clock_config(void);
 NFCSTATUS phNxpNciHal_china_tianjin_rf_setting(void);
 #if(NFC_NXP_CHIP_TYPE == PN548C2)
@@ -579,6 +583,11 @@
             status = phNxpNciHal_fw_download();
             if (status != NFCSTATUS_SUCCESS)
             {
+                if (NFCSTATUS_SUCCESS != phNxpNciHal_fw_mw_ver_check ())
+                {
+                    NXPLOG_NCIHAL_D ("Chip Version Middleware Version mismatch!!!!");
+                    goto clean_and_return;
+                }
                 NXPLOG_NCIHAL_E ("FW Download failed - NFCC init will continue");
             }
             else
@@ -625,6 +634,29 @@
 }
 
 /******************************************************************************
+ * Function         phNxpNciHal_fw_mw_check
+ *
+ * Description      This function inform the status of phNxpNciHal_fw_mw_check
+ *                  function to libnfc-nci.
+ *
+ * Returns          int.
+ *
+ ******************************************************************************/
+int phNxpNciHal_fw_mw_ver_check()
+{
+    NFCSTATUS status = NFCSTATUS_FAILED;
+
+    if (!strcmp (COMPILATION_MW, "PN548C2") && (rom_version == 0x10) && (fw_maj_ver == 0x01))
+    {
+        status = NFCSTATUS_SUCCESS;
+    }
+    else if (!strcmp (COMPILATION_MW, "PN547C2") && (rom_version == 0x08) && (fw_maj_ver == 0x01))
+    {
+        status = NFCSTATUS_SUCCESS;
+    }
+    return status;
+}
+/******************************************************************************
  * Function         phNxpNciHal_open_complete
  *
  * Description      This function inform the status of phNxpNciHal_open
diff --git a/halimpl/pn54x/hal/phNxpNciHal_ext.c b/halimpl/pn54x/hal/phNxpNciHal_ext.c
index 8957e44..19ed71f 100644
--- a/halimpl/pn54x/hal/phNxpNciHal_ext.c
+++ b/halimpl/pn54x/hal/phNxpNciHal_ext.c
@@ -50,6 +50,8 @@
 /* External global variable to get FW version from FW file*/
 extern uint16_t wFwVer;
 
+uint16_t fw_maj_ver;
+uint16_t rom_version;
 /* local buffer to store CORE_INIT response */
 static uint32_t bCoreInitRsp[40];
 static uint32_t iCoreInitRspLen;
@@ -351,6 +353,8 @@
         iCoreInitRspLen = *p_len;
         memcpy(bCoreInitRsp, p_ntf, *p_len);
         NXPLOG_NCIHAL_D ("NxpNci> FW Version: %x.%x.%x", p_ntf[len-2], p_ntf[len-1], p_ntf[len]);
+        fw_maj_ver = p_ntf[len-1];
+        rom_version = p_ntf[len-2];
     }
     //4200 02 00 01
     else if(p_ntf[0] == 0x42 && p_ntf[1] == 0x00 && ee_disc_done == 0x01)