comparison comlib/cl_imei.c @ 34:2fc925048350

comlib/cl_imei.c: new universal FreeCalypso IMEI finding scheme consistent across all targets and all fw versions
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 15 Oct 2016 04:43:35 +0000
parents c0f2d21307d1
children
comparison
equal deleted inserted replaced
33:6a2b09d3b1b4 34:2fc925048350
191 | ERROR - negative values 191 | ERROR - negative values
192 +------------------------------------------------------------------------------ 192 +------------------------------------------------------------------------------
193 */ 193 */
194 extern BYTE cl_get_imeisv(USHORT imeiBufSize, UBYTE *imeiBufPtr, UBYTE imeiType) 194 extern BYTE cl_get_imeisv(USHORT imeiBufSize, UBYTE *imeiBufPtr, UBYTE imeiType)
195 { 195 {
196 #if CONFIG_MOKOFFS
197 USHORT ret;
198 UBYTE version;
199 UBYTE buf[SIZE_EF_IMEI]; 196 UBYTE buf[SIZE_EF_IMEI];
200 #else
201 BYTE ret; 197 BYTE ret;
202 #endif
203 198
204 TRACE_FUNCTION("cl_get_imeisv()"); 199 TRACE_FUNCTION("cl_get_imeisv()");
205 200
206 /* 201 /*
207 * The user has required a stored IMEI. If it has been already read 202 * The user has required a stored IMEI. If it has been already read
209 */ 204 */
210 if((imeiType == CL_IMEI_GET_STORED_IMEI) && (imei_flag == 1)){ 205 if((imeiType == CL_IMEI_GET_STORED_IMEI) && (imei_flag == 1)){
211 memcpy(imeiBufPtr, stored_imei, CL_IMEI_SIZE); 206 memcpy(imeiBufPtr, stored_imei, CL_IMEI_SIZE);
212 return CL_IMEI_OK; 207 return CL_IMEI_OK;
213 } 208 }
209
214 /* 210 /*
215 * The user has required a "secure" IMEI. How we get it depends on what 211 * The user has required a "secure" IMEI. Look in /etc/IMEISV first,
216 * platform we are running on. 212 * then in /pcm/IMEI. And if we are running on the Pirelli target,
213 * try their factory IMEI record last.
217 */ 214 */
218 215
219 #if CONFIG_MOKOFFS 216 if (ffs_file_read(CL_IMEI_FFS_PATH, imeiBufPtr, CL_IMEI_SIZE) >= EFFS_OK) {
220 /* 217 TRACE_EVENT("CL IMEI INFO: return IMEI-SV number from ffs:/etc/IMEISV");
221 * Running on Openmoko GTA0x and using the original FFS. 218 memcpy(stored_imei, imeiBufPtr, CL_IMEI_SIZE);
222 * Get the nibble-swapped IMEI record from PCM. 219 imei_flag = 1;
223 */ 220 return CL_IMEI_OK;
224 ret = pcm_ReadFile ((UBYTE *)EF_IMEI_ID, SIZE_EF_IMEI, buf, &version); 221 }
225 if(ret == PCM_OK){ 222
223 if (ffs_file_read("/pcm/IMEI", buf, CL_IMEI_SIZE) >= EFFS_OK) {
226 TRACE_EVENT("CL IMEI INFO: return IMEI-SV number from ffs:/pcm/IMEI"); 224 TRACE_EVENT("CL IMEI INFO: return IMEI-SV number from ffs:/pcm/IMEI");
227 /* 225 /*
228 * swap digits 226 * swap digits
229 */ 227 */
230 imeiBufPtr[0] = ((buf[0] & 0xf0) >> 4) | ((buf[0] & 0x0f) << 4); 228 imeiBufPtr[0] = ((buf[0] & 0xf0) >> 4) | ((buf[0] & 0x0f) << 4);
236 imeiBufPtr[6] = ((buf[6] & 0xf0) >> 4) | ((buf[6] & 0x0f) << 4); 234 imeiBufPtr[6] = ((buf[6] & 0xf0) >> 4) | ((buf[6] & 0x0f) << 4);
237 imeiBufPtr[7] = ((buf[7] & 0xf0) >> 4) | ((buf[7] & 0x0f) << 4); 235 imeiBufPtr[7] = ((buf[7] & 0xf0) >> 4) | ((buf[7] & 0x0f) << 4);
238 /* store IMEI */ 236 /* store IMEI */
239 memcpy(stored_imei, imeiBufPtr, CL_IMEI_SIZE); 237 memcpy(stored_imei, imeiBufPtr, CL_IMEI_SIZE);
240 imei_flag = 1; 238 imei_flag = 1;
241 }else{
242 /*
243 * pcm_ReadFile() can't really fail, as it merely reads out of a
244 * RAM buffer that was filled earlier, either from FFS or from
245 * compiled-in defaults. But TI's original code had the following
246 * error handling clause, so I kept it.
247 */
248 TRACE_EVENT("CL IMEI INFO: return default IMEI-SV number");
249 memcpy(imeiBufPtr, C_DEFAULT_IMEISV_DSAMPLE, CL_IMEI_SIZE);
250 }
251 return CL_IMEI_OK;
252 #else
253
254 /*
255 * Regular FreeCalypso configuration, not MokoFFS.
256 * We try to get the IMEISV from the following sources, in this order:
257 *
258 * /etc/IMEISV (sensible nibble order, not encrypted)
259 * Pirelli's encrypted IMEI record (Pirelli target only)
260 * hard-coded fallback and error indication
261 */
262
263 if (ffs_file_read(CL_IMEI_FFS_PATH, imeiBufPtr, CL_IMEI_SIZE) >= EFFS_OK) {
264 memcpy(stored_imei, imeiBufPtr, CL_IMEI_SIZE);
265 imei_flag = 1;
266 return CL_IMEI_OK; 239 return CL_IMEI_OK;
267 } 240 }
241
268 #if CONFIG_TARGET_PIRELLI 242 #if CONFIG_TARGET_PIRELLI
269 ret = pirelli_get_imeisv (imeiBufSize, imeiBufPtr); 243 ret = pirelli_get_imeisv (imeiBufSize, imeiBufPtr);
270 if (ret == CL_IMEI_OK) { 244 if (ret == CL_IMEI_OK) {
271 memcpy(stored_imei, imeiBufPtr, CL_IMEI_SIZE); 245 memcpy(stored_imei, imeiBufPtr, CL_IMEI_SIZE);
272 imei_flag = 1; 246 imei_flag = 1;
276 ret = CL_IMEI_READ_IMEI_FAILED; 250 ret = CL_IMEI_READ_IMEI_FAILED;
277 #endif 251 #endif
278 TRACE_ERROR("CL IMEI FATAL ERROR: IMEI not available!"); 252 TRACE_ERROR("CL IMEI FATAL ERROR: IMEI not available!");
279 memcpy(imeiBufPtr, C_DEFAULT_IMEISV_DSAMPLE, CL_IMEI_SIZE); 253 memcpy(imeiBufPtr, C_DEFAULT_IMEISV_DSAMPLE, CL_IMEI_SIZE);
280 return ret; 254 return ret;
281 #endif /* CONFIG_MOKOFFS */
282 } 255 }
283 256
284 #endif /* CL_IMEI_C */ 257 #endif /* CL_IMEI_C */