changeset 77:3b2d13172b6c

cl_imei.c: implemented new FreeCalypso IMEI finding logic
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 02 Oct 2016 03:48:22 +0000
parents b216b561dcbf
children dce31be2b474
files src/condat2/com/src/comlib/cl_imei.c
diffstat 1 files changed, 43 insertions(+), 41 deletions(-) [+]
line wrap: on
line diff
--- a/src/condat2/com/src/comlib/cl_imei.c	Sun Oct 02 03:12:59 2016 +0000
+++ b/src/condat2/com/src/comlib/cl_imei.c	Sun Oct 02 03:48:22 2016 +0000
@@ -297,6 +297,7 @@
 extern BYTE cl_get_imeisv(USHORT imeiBufSize, UBYTE *imeiBufPtr, UBYTE imeiType)
 {
   BYTE ret = 0;
+  UBYTE buf[CL_IMEI_SIZE];
 
   TRACE_FUNCTION("cl_get_imeisv()");
 
@@ -336,51 +337,52 @@
  */
 #else /* FF_PROTECTED_IMEI */
 
-/*
- * Return default CALYPSO+ IMEISV value
- */
-#ifdef CL_IMEI_CALYPSO_PLUS_PLATFORM
+  /* New FreeCalypso IMEI finding logic */
+
+  /*
+   * The user has required a stored IMEI. If it has been already read
+   * and stored, so return stored IMEI
+   */
+  if((imeiType == CL_IMEI_GET_STORED_IMEI) && (imei_flag == 1)){
+    memcpy(imeiBufPtr, stored_imei, CL_IMEI_SIZE);
+    return CL_IMEI_OK;
+  }
 
-  TRACE_EVENT("CL IMEI INFO: return default IMEI-SV number");
-  memcpy(imeiBufPtr, C_DEFAULT_IMEISV_ESAMPLE, CL_IMEI_SIZE);
+  /*
+   * The user has required a "secure" IMEI.  Look in /etc/IMEISV first,
+   * then in /pcm/IMEI.
+   */
+
+  if (ffs_file_read("/etc/IMEISV", imeiBufPtr, CL_IMEI_SIZE) >= EFFS_OK) {
+    TRACE_EVENT("CL IMEI INFO: return IMEI-SV number from ffs:/etc/IMEISV");
+    memcpy(stored_imei, imeiBufPtr, CL_IMEI_SIZE);
+    imei_flag = 1;
+    return CL_IMEI_OK;
+  }
 
-/*
- * CL_IMEI_CALYPSO_PLATFORM or CL_IMEI_OTHER_PLATFORM is defined.
- * Try to read the IMEI number from the old ffs:/pcm/IMEI file, 
- * if it failes, return default CALYPSO IMEISV value
- */
-#else /* CL_IMEI_CALYPSO_PLUS_PLATFORM */
-  {
-    UBYTE version;
-    USHORT ret;
-    UBYTE buf[SIZE_EF_IMEI];
- 
-    ret = pcm_ReadFile ((UBYTE *)EF_IMEI_ID, SIZE_EF_IMEI, buf, &version);
-    if(ret == PCM_OK){
-      TRACE_EVENT("CL IMEI INFO: return IMEI-SV number from ffs:/pcm/IMEI");
-      /*
-       * swap digits
-       */
-      imeiBufPtr[0] = ((buf[0] & 0xf0) >> 4) | ((buf[0] & 0x0f) << 4);
-      imeiBufPtr[1] = ((buf[1] & 0xf0) >> 4) | ((buf[1] & 0x0f) << 4);
-      imeiBufPtr[2] = ((buf[2] & 0xf0) >> 4) | ((buf[2] & 0x0f) << 4);
-      imeiBufPtr[3] = ((buf[3] & 0xf0) >> 4) | ((buf[3] & 0x0f) << 4);
-      imeiBufPtr[4] = ((buf[4] & 0xf0) >> 4) | ((buf[4] & 0x0f) << 4);
-      imeiBufPtr[5] = ((buf[5] & 0xf0) >> 4) | ((buf[5] & 0x0f) << 4);
-      imeiBufPtr[6] = ((buf[6] & 0xf0) >> 4) | ((buf[6] & 0x0f) << 4);
-      imeiBufPtr[7] = ((buf[7] & 0xf0) >> 4) | ((buf[7] & 0x0f) << 4);
-      /* store IMEI */
-      memcpy(stored_imei, imeiBufPtr, CL_IMEI_SIZE);
-      imei_flag = 1;
-      
-    }else{
-      TRACE_EVENT("CL IMEI INFO: return default IMEI-SV number");
-      memcpy(imeiBufPtr, C_DEFAULT_IMEISV_DSAMPLE, CL_IMEI_SIZE);
-    }
+  if (ffs_file_read("/pcm/IMEI", buf, CL_IMEI_SIZE) >= EFFS_OK) {
+    TRACE_EVENT("CL IMEI INFO: return IMEI-SV number from ffs:/pcm/IMEI");
+    /*
+     * swap digits
+     */
+    imeiBufPtr[0] = ((buf[0] & 0xf0) >> 4) | ((buf[0] & 0x0f) << 4);
+    imeiBufPtr[1] = ((buf[1] & 0xf0) >> 4) | ((buf[1] & 0x0f) << 4);
+    imeiBufPtr[2] = ((buf[2] & 0xf0) >> 4) | ((buf[2] & 0x0f) << 4);
+    imeiBufPtr[3] = ((buf[3] & 0xf0) >> 4) | ((buf[3] & 0x0f) << 4);
+    imeiBufPtr[4] = ((buf[4] & 0xf0) >> 4) | ((buf[4] & 0x0f) << 4);
+    imeiBufPtr[5] = ((buf[5] & 0xf0) >> 4) | ((buf[5] & 0x0f) << 4);
+    imeiBufPtr[6] = ((buf[6] & 0xf0) >> 4) | ((buf[6] & 0x0f) << 4);
+    imeiBufPtr[7] = ((buf[7] & 0xf0) >> 4) | ((buf[7] & 0x0f) << 4);
+    /* store IMEI */
+    memcpy(stored_imei, imeiBufPtr, CL_IMEI_SIZE);
+    imei_flag = 1;
+    return CL_IMEI_OK;
   }
-#endif /* CL_IMEI_CALYPSO_PLUS_PLATFORM */
 
-  return CL_IMEI_OK;
+  ret = CL_IMEI_READ_IMEI_FAILED;
+  TRACE_ERROR("CL IMEI FATAL ERROR: IMEI not available!");
+  memcpy(imeiBufPtr, C_DEFAULT_IMEISV_DSAMPLE, CL_IMEI_SIZE);
+  return ret;
 
 #endif /* FF_PROTECTED_IMEI */
 #endif /* _SIMULATION_ */