FreeCalypso > hg > tcs211-l1-reconst
comparison g23m/condat/com/src/comlib/sec_drv_prim.h @ 0:509db1a7b7b8
initial import: leo2moko-r1
author | Space Falcon <falcon@ivan.Harhan.ORG> |
---|---|
date | Mon, 01 Jun 2015 03:24:05 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:509db1a7b7b8 |
---|---|
1 #ifndef _SEC_DRV_PRIM_H_ | |
2 #define _SEC_DRV_PRIM_H_ | |
3 | |
4 | |
5 /******************************************* | |
6 Feature flags & constants | |
7 *******************************************/ | |
8 // TODO: Set properly! | |
9 //#define SEC_TRACES_ENABLED | |
10 #define FFS_MODE_ENABLED /* MEPD file is located in FFS */ | |
11 #define NON_ENCRYPTED_MODE /* MEPD file wont be encrypted */ | |
12 //#define IMEI_FROM_OTP /* IMEI is placed in OTP */ | |
13 //#define FIRSTBOOT_ENABLED | |
14 //#define FIRSTBOOT_FFS_BACKUP_ENABLED /* MEPD backup during firstboot is placed in FFS */ | |
15 //#define FIRSTBOOT_RSA_ENABLED /* RSA Part of external MEPD is decrypted */ | |
16 //#define FIRSTBOOT_DES_ENABLED /* DES encrypted data in external MEPD is decrypted */ | |
17 //#define RSA_FROM_CERT_ENABLED /* Key for RSA is taken from certificate */ | |
18 //#define USE_RSAHEAP_FOR_FLASH /* Use the RSA heap (SEC_DRV_RSA_HEAP) for flash writing algorithm */ | |
19 //#define RSA_HEAP_IS_INTERNAL /* Buffer for RSA heap is allocated as global array! */ | |
20 //#define DSP_DES_KEY_ENABLED /* DES key is taken from the DSP */ | |
21 | |
22 | |
23 /* Flash interface constants */ | |
24 extern volatile const UINT8 d_mepd_data; | |
25 #define SEC_BASE d_mepd_data /* address on secure flash area goes here */ | |
26 #define SEC_DEV_BASE SEC_BASE /* address to offset the flashdrivers from */ | |
27 #define SEC_FLASH_SIZE 8192 /* size of the flash sector */ | |
28 | |
29 | |
30 /* RSA heap or Flash buffer constants */ | |
31 #if defined(FIRSTBOOT_RSA_ENABLED) || (defined(USE_RSAHEAP_FOR_FLASH) && !defined(FFS_MODE_ENABLED)) | |
32 #define RSA_HEAP_SIZE 8192 | |
33 #ifndef RSA_HEAP_IS_INTERNAL | |
34 #error "we need a 8K RAM buffer for heap during RSA decryption" | |
35 #define SEC_DRV_RSA_HEAP xxx /* address from where we can use 8K during firstboot */ | |
36 #else /* RSA_HEAP_IS_INTERNAL */ | |
37 #define SEC_DRV_RSA_HEAP &sec_drv_buffer[0] | |
38 #endif /* RSA_HEAP_IS_INTERNAL */ | |
39 #endif /* defined(FIRSTBOOT_RSA_ENABLED) || defined(USE_RSAHEAP_FOR_FLASH) */ | |
40 | |
41 | |
42 #define SEC_PATTERN_INITIALIZED 0xAA | |
43 #define SEC_PATTERN_UNINITIALIZED 0x55 | |
44 | |
45 #define SEC_DRV_KEY_MAX_LEN 16 | |
46 #define DES_KEY_SIZE 8 | |
47 #define SHA1_SIZE 20 | |
48 #define IMEI_SIZE 8 | |
49 #define CRYPT_BLOCK_SIZE 8 | |
50 | |
51 #define FFS_MEPD_FILENAME "/MEPD_File.bin" | |
52 #define FLASH_BACKUP_NAME "/flash_backup.bin" | |
53 #define BACKUP_BUF_SIZE 128 | |
54 | |
55 | |
56 /******************************************* | |
57 Macros | |
58 *******************************************/ | |
59 #define ALIGN_CRYPT_BLOCK(x) ((x%CRYPT_BLOCK_SIZE)? x+CRYPT_BLOCK_SIZE-(x%CRYPT_BLOCK_SIZE) : x) | |
60 | |
61 #ifdef SEC_TRACES_ENABLED | |
62 #define TRACE(a) test_trace(a) | |
63 #define HEXTRACE(str, data, size) hex_trace(str, data, size) | |
64 extern void test_trace(const char *str); | |
65 extern void hex_trace(const char *str, const void *in, unsigned long int size); | |
66 #else | |
67 #define TRACE(a) ((void)(0)) | |
68 #define HEXTRACE(str, data, size) ((void)(0)) | |
69 #endif | |
70 | |
71 | |
72 /******************************************* | |
73 Type definitions | |
74 *******************************************/ | |
75 typedef struct | |
76 { | |
77 UINT8 firstboot_pattern; | |
78 } T_SEC_DRV_GLOBAL_CONF; | |
79 | |
80 typedef struct | |
81 { | |
82 UINT8 digit[SEC_DRV_KEY_MAX_LEN]; | |
83 } T_SEC_DRV_KEY; | |
84 | |
85 | |
86 /******************************************* | |
87 Prototypes | |
88 *******************************************/ | |
89 extern INT8 sec_drv_fast_write; | |
90 void sec_drv_flash_backup(void); | |
91 void sec_drv_remove_backup(void); | |
92 void sec_drv_erase_flash(void); | |
93 void sec_drv_read_flash(UINT32 offset, void *pDest, UINT32 size); | |
94 void sec_drv_write_flash(UINT32 offset, const void *pSrc, UINT32 size); | |
95 | |
96 extern BOOL sec_prim_get_global_conf(T_SEC_DRV_GLOBAL_CONF *pGlobalConf); | |
97 extern BOOL sec_prim_set_global_conf(const T_SEC_DRV_GLOBAL_CONF *pGlobalConf); | |
98 | |
99 extern BOOL sec_prim_get_configuration(T_SEC_DRV_CONFIGURATION *pConf); | |
100 extern BOOL sec_prim_set_configuration(const T_SEC_DRV_CONFIGURATION *pConf); | |
101 | |
102 extern BOOL sec_prim_get_key(int rec_num, T_SEC_DRV_KEY *pKey); | |
103 extern BOOL sec_prim_set_key(int rec_num, const T_SEC_DRV_KEY *pKey); | |
104 | |
105 extern BOOL sec_prim_get_cat_header(int rec_num, T_SEC_DRV_CAT_HDR *pHdr); | |
106 extern BOOL sec_prim_set_cat_header(int rec_num, const T_SEC_DRV_CAT_HDR *pHdr); | |
107 | |
108 extern BOOL sec_prim_get_cat_body(int rec_num, void *pBody, UINT16 size); | |
109 extern BOOL sec_prim_set_cat_body(int rec_num, const void *pBody, UINT16 size); | |
110 | |
111 #endif /* _SEC_DRV_PRIM_H_ */ |