FreeCalypso > hg > tcs211-c139
changeset 27:a0605a6290e1
cl_imei.c: changed to FreeCalypso version, using /etc/IMEISV now
author | Mychaela Falconia <falcon@ivan.Harhan.ORG> |
---|---|
date | Sun, 01 Nov 2015 15:57:46 +0000 |
parents | c42227c9bc62 |
children | fcaacf995636 |
files | g23m/__out__/gsm_ac_gp_fd_pu_em_cph_ds_vc_cal35_ri_36_amd8_ts0/bin/str2ind.tab g23m/__out__/gsm_ac_gp_fd_pu_em_cph_ds_vc_cal35_ri_36_amd8_ts0/trace/str2ind.c g23m/condat/com/src/comlib/cl_imei.c |
diffstat | 3 files changed, 91 insertions(+), 196 deletions(-) [+] |
line wrap: on
line diff
--- a/g23m/__out__/gsm_ac_gp_fd_pu_em_cph_ds_vc_cal35_ri_36_amd8_ts0/bin/str2ind.tab Sun Nov 01 15:36:19 2015 +0000 +++ b/g23m/__out__/gsm_ac_gp_fd_pu_em_cph_ds_vc_cal35_ri_36_amd8_ts0/bin/str2ind.tab Sun Nov 01 15:57:46 2015 +0000 @@ -1,5 +1,5 @@ -1433141163 - 8913 +1446393298 + 8914 0,,setatPercentSATC 1,,tesatPercentSATC 2,,queatPercentSATC @@ -8913,3 +8913,4 @@ 8910,i,[DBG] ati_src_rvt_line_state_cb (): ATI_LINE_STATE_DCD = %d 8911,i,[DBG] ati_src_rvt_line_state_cb (): ATI_LINE_STATE_RNG = %d 8912,i,[WRN] ati_src_rvt_line_state_cb (): UNKNOWN line_state_type = %d + 8913,,CL IMEI FATAL ERROR: IMEI not available!
--- a/g23m/__out__/gsm_ac_gp_fd_pu_em_cph_ds_vc_cal35_ri_36_amd8_ts0/trace/str2ind.c Sun Nov 01 15:36:19 2015 +0000 +++ b/g23m/__out__/gsm_ac_gp_fd_pu_em_cph_ds_vc_cal35_ri_36_amd8_ts0/trace/str2ind.c Sun Nov 01 15:57:46 2015 +0000 @@ -4,4 +4,4 @@ /* !!! DO NOT MODIFY - Generated by STR2IND: !!! */ -char * str2ind_version = "&1433141163"; +char * str2ind_version = "&1446393298";
--- a/g23m/condat/com/src/comlib/cl_imei.c Sun Nov 01 15:36:19 2015 +0000 +++ b/g23m/condat/com/src/comlib/cl_imei.c Sun Nov 01 15:57:46 2015 +0000 @@ -48,32 +48,19 @@ #include "cl_des.h" #include <string.h> -#if defined(CL_IMEI_CALYPSO_PLUS_PLATFORM) && defined(FF_PROTECTED_IMEI) -#include "secure_rom/secure_rom.h" -#endif - static UBYTE stored_imei[CL_IMEI_SIZE]; /* when the imei is read once, the value is stored in this buffer */ static UBYTE imei_flag = 0; /* this flag indicates, if IMEI was successful read and is stored in the stored_imei buffer */ -#if !defined (CL_IMEI_CALYPSO_PLUS_PLATFORM) /* Default IMEISV for D-Sample 00440000-350-111-20 */ const UBYTE C_DEFAULT_IMEISV_DSAMPLE[CL_IMEI_SIZE] = {0x00, 0x44, 0x00, 0x00, 0x35, 0x01, 0x11, 0x20}; -#define CL_IMEI_FFS_PATH "/gsm/imei.enc" -#endif /* CL_IMEI_CALYPSO_PLATFORM */ - -#ifdef CL_IMEI_CALYPSO_PLUS_PLATFORM -/* Default IMEISV for E-Sample 00440000-351-222-30 */ -const UBYTE C_DEFAULT_IMEISV_ESAMPLE[CL_IMEI_SIZE] = - {0x00, 0x44, 0x00, 0x00, 0x35, 0x12, 0x22, 0x30}; -#endif /* CL_IMEI_CALYPSO_PLUS_PLATFORM */ +#define CL_IMEI_FFS_PATH "/etc/IMEISV" /*==== FUNCTIONS ==================================================*/ -#ifdef FF_PROTECTED_IMEI -#ifdef CL_IMEI_CALYPSO_PLATFORM +#if CONFIG_TARGET_PIRELLI /* +------------------------------------------------------------------------------ | Function : get_dieID @@ -106,11 +93,17 @@ } } +extern int pirelli_read_factory_record(uint32 offset, void *userbuf, + T_FFS_SIZE size, int has_chksum); + +#define PIRELLI_IMEI_OFFSET 0x504 + /* +------------------------------------------------------------------------------ -| Function : ffs_get_imeisv +| Function : pirelli_get_imeisv +------------------------------------------------------------------------------ -| Description : the function reads IMEI from FFS +| Description : This function attempts to read and decrypt a valid IMEISV +| record from Pirelli's factory data block. | | Parameters : inBufSize - size of buffer where to store IMEI, min. 8 BYTE | *outBufPtr - pointer to buffer where to store the IMEI @@ -118,15 +111,14 @@ | <0 - ERROR +------------------------------------------------------------------------------ */ -LOCAL BYTE ffs_get_imeisv (USHORT inBufSize, UBYTE *outBufPtr) +LOCAL BYTE pirelli_get_imeisv (USHORT inBufSize, UBYTE *outBufPtr) { - UBYTE i; UBYTE isdid_buf[CL_IMEI_ISDID_SIZE]; UBYTE r_dieId[CL_DES_KEY_SIZE]; /* read Die ID */ UBYTE d_dieId[CL_DES_KEY_SIZE]; /* deciphered Die ID */ SHORT ret; - TRACE_FUNCTION("ffs_get_imeisv()"); + TRACE_FUNCTION("pirelli_get_imeisv()"); if(inBufSize < CL_IMEI_SIZE){ TRACE_ERROR("CL IMEI ERROR: buffer size for IMEI to short!"); @@ -135,8 +127,10 @@ /* * Read ISDID(enciphered IMEISV+DieID) from FFS. + * (changed to read from Pirelli's factory data block instead) */ - if((ret = ffs_file_read(CL_IMEI_FFS_PATH, isdid_buf, CL_IMEI_ISDID_SIZE)) >= EFFS_OK) + if((ret = pirelli_read_factory_record(PIRELLI_IMEI_OFFSET, isdid_buf, + CL_IMEI_ISDID_SIZE, 0)) >= EFFS_OK) { /* * Read Die ID for using as DES key @@ -171,107 +165,11 @@ ret = CL_IMEI_READ_IMEI_FAILED; } - return ret; - -}/* ffs_get_imeisv() */ -#endif /* CL_IMEI_CALYPSO_PLATFORM */ - - -#ifdef CL_IMEI_CALYPSO_PLUS_PLATFORM -/* -+------------------------------------------------------------------------------ -| Function : securerom_get_imeisv -+------------------------------------------------------------------------------ -| Description : the function reads IMEI from Secure ROM -| -| Parameters : inBufSize - size of buffer where to store IMEI, min. 8 BYTE -| *outBufPtr - pointer to buffer where to store the IMEI -| Return : 0 - OK -| <0 - ERROR -+------------------------------------------------------------------------------ -*/ -LOCAL BYTE securerom_get_imeisv (USHORT inBufSize, UBYTE *outBufPtr) -{ - BYTE ret; - - TRACE_FUNCTION("securerom_get_imeisv()"); - - if((ret = securerom_drv(inBufSize, outBufPtr)) == CL_IMEI_OK){ - return CL_IMEI_OK; - } else { - return CL_IMEI_READ_IMEI_FAILED; - } -} -#endif /* CL_IMEI_CALYPSO_PLUS_PLATFORM */ + return ret; -/* -+------------------------------------------------------------------------------ -| Function : get_secure_imeisv -+------------------------------------------------------------------------------ -| Description : the function reads IMEI either from FFS or from Secure ROM of -| from other locations depended on hardware platform -| -| Parameters : inBufSize - size of buffer where to store IMEI, min. 8 BYTE -| *outBufPtr - pointer to buffer where to store the IMEI -| Return : 0 - OK -| negative value - ERROR -+------------------------------------------------------------------------------ -*/ -LOCAL BYTE get_secure_imeisv(USHORT inBufSize, UBYTE *outBufPtr) -{ - BYTE ret = 0; - UBYTE chipset = CHIPSET; - UBYTE board = BOARD; - - TRACE_FUNCTION("get_secure_imeisv()"); +}/* pirelli_get_imeisv() */ +#endif /* CONFIG_TARGET_PIRELLI */ -/* - * SW is running on Calypso platform (D-Sample) - */ -#ifdef CL_IMEI_CALYPSO_PLATFORM - /* - * Read IMEI from FFS inclusive deciphering with DES. - */ - if((ret = ffs_get_imeisv (inBufSize, outBufPtr)) == CL_IMEI_OK) - { - /* store IMEI */ - memcpy(stored_imei, outBufPtr, CL_IMEI_SIZE); - imei_flag = 1; - return CL_IMEI_OK; - } -#else /* CL_IMEI_CALYPSO_PLATFORM */ -/* - * SW is running on Calypso plus platform (E-Sample) - */ -#ifdef CL_IMEI_CALYPSO_PLUS_PLATFORM - if((ret = securerom_get_imeisv (inBufSize, outBufPtr)) == CL_IMEI_OK) - { - /* store IMEI */ - memcpy(stored_imei, outBufPtr, CL_IMEI_SIZE); - imei_flag = 1; - return CL_IMEI_OK; - } -#else /* CL_IMEI_CALYPSO_PLUS_PLATFORM */ -/* - * SW is running on an other platform (neither Calypso nor Calypso plus) - */ -#ifdef CL_IMEI_OTHER_PLATFORM - { - TRACE_EVENT_P2("CL IMEI WARNING: unknown hardware: board=%d, chipset=%d, return default imei", - board, chipset); - memcpy(outBufPtr, C_DEFAULT_IMEISV_DSAMPLE, CL_IMEI_SIZE); - return CL_IMEI_OK; - } -#endif /* CL_IMEI_OTHER_PLATFORM */ -#endif /* CL_IMEI_CALYPSO_PLUS_PLATFORM */ -#endif /* CL_IMEI_CALYPSO_PLATFORM */ - - return ret; /* get_secure_imeisv is failed, return error code */ - -} /* get_secure_imeisv() */ - - -#endif /* FF_PROTECTED_IMEI */ /* +------------------------------------------------------------------------------ @@ -296,16 +194,16 @@ */ extern BYTE cl_get_imeisv(USHORT imeiBufSize, UBYTE *imeiBufPtr, UBYTE imeiType) { - BYTE ret = 0; +#if CONFIG_MOKOFFS + USHORT ret; + UBYTE version; + UBYTE buf[SIZE_EF_IMEI]; +#else + BYTE ret; +#endif TRACE_FUNCTION("cl_get_imeisv()"); -#ifdef _SIMULATION_ - memcpy(imeiBufPtr, C_DEFAULT_IMEISV_DSAMPLE, CL_IMEI_SIZE); - return CL_IMEI_OK; -#else /* _SIMULATION_ */ - -#ifdef FF_PROTECTED_IMEI /* * The user has required a stored IMEI. If it has been already read * and stored, so return stored IMEI @@ -315,76 +213,72 @@ return CL_IMEI_OK; } /* - * The user has required a secure IMEI. Read IMEI from FFS or from Secure ROM + * The user has required a "secure" IMEI. How we get it depends on what + * platform we are running on. + */ + +#if CONFIG_MOKOFFS + /* + * Running on Openmoko GTA0x and using the original FFS. + * Get the nibble-swapped IMEI record from PCM. */ - if((ret = get_secure_imeisv(imeiBufSize, imeiBufPtr)) == CL_IMEI_OK) - { + 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{ + /* + * pcm_ReadFile() can't really fail, as it merely reads out of a + * RAM buffer that was filled earlier, either from FFS or from + * compiled-in defaults. But TI's original code had the following + * error handling clause, so I kept it. + */ + TRACE_EVENT("CL IMEI INFO: return default IMEI-SV number"); + memcpy(imeiBufPtr, C_DEFAULT_IMEISV_DSAMPLE, CL_IMEI_SIZE); + } + return CL_IMEI_OK; +#else + + /* + * Regular FreeCalypso configuration, not MokoFFS. + * We try to get the IMEISV from the following sources, in this order: + * + * /etc/IMEISV (sensible nibble order, not encrypted) + * Pirelli's encrypted IMEI record (Pirelli target only) + * hard-coded fallback and error indication + */ + + if (ffs_file_read(CL_IMEI_FFS_PATH, imeiBufPtr, CL_IMEI_SIZE) >= EFFS_OK) { + memcpy(stored_imei, imeiBufPtr, CL_IMEI_SIZE); + imei_flag = 1; return CL_IMEI_OK; - } else { - TRACE_ERROR("CL IMEI FATAL ERROR: IMEI not available!"); - /* - * Notify the Frame entity about FATAL ERROR, but not in the case, - * if ACI is checking IMEI, because ACI will take trouble about it. - */ - if (imeiType != CL_IMEI_CONTROL_IMEI){ - TRACE_ASSERT(ret == CL_IMEI_OK); - } + } +#if CONFIG_TARGET_PIRELLI + ret = pirelli_get_imeisv (imeiBufSize, imeiBufPtr); + if (ret == CL_IMEI_OK) { + imei_flag = 1; return ret; } -/* - * The feature flag FF_PROTECTED_IMEI is not enabled. - */ -#else /* FF_PROTECTED_IMEI */ - -/* - * Return default CALYPSO+ IMEISV value - */ -#ifdef CL_IMEI_CALYPSO_PLUS_PLATFORM - - TRACE_EVENT("CL IMEI INFO: return default IMEI-SV number"); - memcpy(imeiBufPtr, C_DEFAULT_IMEISV_ESAMPLE, CL_IMEI_SIZE); - -/* - * 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); - } - } -#endif /* CL_IMEI_CALYPSO_PLUS_PLATFORM */ - - return CL_IMEI_OK; - -#endif /* FF_PROTECTED_IMEI */ -#endif /* _SIMULATION_ */ +#else + ret = CL_IMEI_READ_IMEI_FAILED; +#endif + TRACE_ERROR("CL IMEI FATAL ERROR: IMEI not available!"); + memcpy(imeiBufPtr, C_DEFAULT_IMEISV_DSAMPLE, CL_IMEI_SIZE); + return ret; +#endif /* CONFIG_MOKOFFS */ } - #endif /* CL_IMEI_C */