FreeCalypso > hg > freecalypso-sw
comparison rvinterf/etmsync/pirimei.c @ 916:8e1c55cf7989
fc-getpirimei implemented, compiles
author | Space Falcon <falcon@ivan.Harhan.ORG> |
---|---|
date | Tue, 08 Sep 2015 18:59:29 +0000 |
parents | |
children | 9b4b0fcddc77 |
comparison
equal
deleted
inserted
replaced
915:7b805007dcfc | 916:8e1c55cf7989 |
---|---|
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[1], 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 } |