annotate rvinterf/etmsync/pirimei.c @ 997:c7ca69bf84f3

gsm-fw: trivial support for c11x target
author Mychaela Falconia <falcon@ivan.Harhan.ORG>
date Sat, 05 Mar 2016 05:10:49 +0000
parents 9b4b0fcddc77
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
916
8e1c55cf7989 fc-getpirimei implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
1 /*
8e1c55cf7989 fc-getpirimei implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
2 * Reading and decryption of Pirelli's factory IMEI record
8e1c55cf7989 fc-getpirimei implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
3 */
8e1c55cf7989 fc-getpirimei implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
4
8e1c55cf7989 fc-getpirimei implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
5 #include <sys/types.h>
8e1c55cf7989 fc-getpirimei implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
6 #include <openssl/des.h>
8e1c55cf7989 fc-getpirimei implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
7 #include <stdio.h>
8e1c55cf7989 fc-getpirimei implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
8 #include <stdlib.h>
8e1c55cf7989 fc-getpirimei implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
9 #include <string.h>
8e1c55cf7989 fc-getpirimei implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
10 #include <strings.h>
8e1c55cf7989 fc-getpirimei implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
11 #include "exitcodes.h"
8e1c55cf7989 fc-getpirimei implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
12
8e1c55cf7989 fc-getpirimei implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
13 u_char pirelli_imeisv[8];
8e1c55cf7989 fc-getpirimei implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
14
8e1c55cf7989 fc-getpirimei implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
15 get_pirelli_imei()
8e1c55cf7989 fc-getpirimei implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
16 {
8e1c55cf7989 fc-getpirimei implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
17 DES_cblock ciphertext[2], dieid_key, decrypted[2];
8e1c55cf7989 fc-getpirimei implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
18 DES_key_schedule keysched;
8e1c55cf7989 fc-getpirimei implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
19 int rc;
8e1c55cf7989 fc-getpirimei implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
20 static char failmsg[] =
8e1c55cf7989 fc-getpirimei implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
21 "decryption failed: no valid IMEI record or incompatible firmware\n";
8e1c55cf7989 fc-getpirimei implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
22
8e1c55cf7989 fc-getpirimei implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
23 printf("Requesting Calypso die ID\n");
8e1c55cf7989 fc-getpirimei implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
24 rc = do_dieid_read(dieid_key);
8e1c55cf7989 fc-getpirimei implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
25 if (rc)
8e1c55cf7989 fc-getpirimei implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
26 return(rc);
8e1c55cf7989 fc-getpirimei implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
27 printf("Reading IMEI record in Pirelli's factory data block\n");
8e1c55cf7989 fc-getpirimei implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
28 rc = do_memory_read(0x027F0504, ciphertext, 16);
8e1c55cf7989 fc-getpirimei implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
29 if (rc)
8e1c55cf7989 fc-getpirimei implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
30 return(rc);
8e1c55cf7989 fc-getpirimei implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
31 DES_set_key_unchecked(&dieid_key, &keysched);
8e1c55cf7989 fc-getpirimei implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
32 DES_ecb_encrypt(&ciphertext[0], &decrypted[0], &keysched, DES_DECRYPT);
8e1c55cf7989 fc-getpirimei implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
33 DES_ecb_encrypt(&ciphertext[1], &decrypted[1], &keysched, DES_DECRYPT);
8e1c55cf7989 fc-getpirimei implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
34 if (bcmp(decrypted[1], dieid_key, 8)) {
8e1c55cf7989 fc-getpirimei implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
35 printf(failmsg);
8e1c55cf7989 fc-getpirimei implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
36 return(ERROR_TARGET);
8e1c55cf7989 fc-getpirimei implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
37 }
917
9b4b0fcddc77 fc-getpirimei works
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 916
diff changeset
38 bcopy(decrypted[0], pirelli_imeisv, 8);
916
8e1c55cf7989 fc-getpirimei implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
39 printf("Factory IMEISV is %02X%02X%02X%02X-%02X%02X%02X-%02X\n",
8e1c55cf7989 fc-getpirimei implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
40 pirelli_imeisv[0], pirelli_imeisv[1], pirelli_imeisv[2],
8e1c55cf7989 fc-getpirimei implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
41 pirelli_imeisv[3], pirelli_imeisv[4], pirelli_imeisv[5],
8e1c55cf7989 fc-getpirimei implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
42 pirelli_imeisv[6], pirelli_imeisv[7]);
8e1c55cf7989 fc-getpirimei implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
43 return(0);
8e1c55cf7989 fc-getpirimei implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
44 }