FreeCalypso > hg > freecalypso-tools
comparison rvinterf/etmsync/pirimei.c @ 0:e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 11 Jun 2016 00:13:35 +0000 |
parents | |
children | 3d148edb87c2 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:e7502631a0f9 |
---|---|
1 /* | |
2 * Reading and decryption of Pirelli's factory IMEI record | |
3 */ | |
4 | |
5 #include <sys/types.h> | |
6 #include <openssl/des.h> | |
7 #include <stdio.h> | |
8 #include <stdlib.h> | |
9 #include <string.h> | |
10 #include <strings.h> | |
11 #include "exitcodes.h" | |
12 | |
13 u_char pirelli_imeisv[8]; | |
14 | |
15 get_pirelli_imei() | |
16 { | |
17 DES_cblock ciphertext[2], dieid_key, decrypted[2]; | |
18 DES_key_schedule keysched; | |
19 int rc; | |
20 static char failmsg[] = | |
21 "decryption failed: no valid IMEI record or incompatible firmware\n"; | |
22 | |
23 printf("Requesting Calypso die ID\n"); | |
24 rc = do_dieid_read(dieid_key); | |
25 if (rc) | |
26 return(rc); | |
27 printf("Reading IMEI record in Pirelli's factory data block\n"); | |
28 rc = do_memory_read(0x027F0504, ciphertext, 16); | |
29 if (rc) | |
30 return(rc); | |
31 DES_set_key_unchecked(&dieid_key, &keysched); | |
32 DES_ecb_encrypt(&ciphertext[0], &decrypted[0], &keysched, DES_DECRYPT); | |
33 DES_ecb_encrypt(&ciphertext[1], &decrypted[1], &keysched, DES_DECRYPT); | |
34 if (bcmp(decrypted[1], dieid_key, 8)) { | |
35 printf(failmsg); | |
36 return(ERROR_TARGET); | |
37 } | |
38 bcopy(decrypted[0], pirelli_imeisv, 8); | |
39 printf("Factory IMEISV is %02X%02X%02X%02X-%02X%02X%02X-%02X\n", | |
40 pirelli_imeisv[0], pirelli_imeisv[1], pirelli_imeisv[2], | |
41 pirelli_imeisv[3], pirelli_imeisv[4], pirelli_imeisv[5], | |
42 pirelli_imeisv[6], pirelli_imeisv[7]); | |
43 return(0); | |
44 } |