blob: 82bb0362db7773d6ddcd7a0664b526e92e16b3f5 [file] [log] [blame]
rjw6c1fd8f2022-11-30 14:33:01 +08001/*****************************************************************************
2* Copyright Statement:
3* --------------------
4* This software is protected by Copyright and the information contained
5* herein is confidential. The software may not be copied and the information
6* contained herein may not be used or disclosed except with the written
7* permission of MediaTek Inc. (C) 2018
8*
9* BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
10* THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
11* RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
12* AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
13* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
14* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
15* NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
16* SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
17* SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
18* THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
19* NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
20* SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
21*
22* BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
23* LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
24* AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
25* OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
26* MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
27*
28* THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
29* WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
30* LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
31* RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
32* THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
33*
34*****************************************************************************/
35
36/*******************************************************************************
37 * Filename:
38 * ---------
39 * mcf_custom.c
40 *
41 * Project:
42 * --------
43 * UMOLYA
44 *
45 * Description:
46 * ------------
47 * This file implements MCF customization.
48 *
49 * Author:
50 * -------
51 * -------
52 *
53 *==============================================================================
54 * HISTORY
55 * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
56 *------------------------------------------------------------------------------
57 * removed!
58 *
59 * removed!
60 * removed!
61 * removed!
62 * removed!
63 *
64 * removed!
65 * removed!
66 * removed!
67 * removed!
68 *
69 * removed!
70 * removed!
71 * removed!
72 * removed!
73 *
74 * removed!
75 * removed!
76 * removed!
77 * removed!
78 *
79 * removed!
80 * removed!
81 * removed!
82 * removed!
83 *
84 * removed!
85 * removed!
86 * removed!
87 *
88 * removed!
89 * removed!
90 * removed!
91 *
92 *------------------------------------------------------------------------------
93 * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
94 *==============================================================================
95 *******************************************************************************/
96
97#include "kal_public_api.h"
98#include "mcf_custom.h"
99#include "cust_chl_interface.h"
100#include "mcf_struct.h"
101
102#if defined(__HIF_CCCI_SUPPORT__)
103#include "ccci_rpc_if.h"
104#endif
105
106/*------------------------------------------------------------------------------
107 * Global variables.
108 *----------------------------------------------------------------------------*/
109
110/*------------------------------------------------------------------------------
111 * Public fucntions.
112 *----------------------------------------------------------------------------*/
113/*****************************************************************************
114 * FUNCTION
115 * mcf_get_custom_file_path_name
116 * DESCRIPTION
117 * This function is used to get MCF customized file path and name.
118 * PARAMETERS
119 * path_type [OUT] path type of file path
120 * relative_file_path_name [OUT] relative file path and name
121 *
122 * RETURNS
123 * KAL_TURE : Success
124 * KAL_FALSE : Fail
125 *****************************************************************************/
126kal_bool mcf_get_custom_file_path_name(kal_uint8 *path_type, kal_char *relative_file_path_name)
127{
128#ifdef __MTK_TARGET__
129#if defined(__HIF_CCCI_SUPPORT__)
130 /* CCCI RPC usage should be here */
131#endif
132#endif
133
134 return KAL_FALSE;
135}
136
137/*****************************************************************************
138 * FUNCTION
139 * mcf_get_custom_aes_password
140 * DESCRIPTION
141 * This function is used to get MCF customized AES password.
142 * PARAMETERS
143 * password [OUT] customized AES password
144 * NOTE
145 * For AES128, the key length should be less than 16, for AES256, the key length should be less than 32.
146 *
147 *****************************************************************************/
148void mcf_get_custom_aes_password(kal_char *password)
149{
150#define __MCF_AES_KEY_SCRAMBLE__
151 /* Password must be the same as MCF bin */
152#if !defined(__MCF_AES_KEY_SCRAMBLE__)
153 /* Fill-in plaintext to save password*/
154 kal_char plaintext_password[] = "MTKTEST";
155 strncpy(password, plaintext_password, MCF_MAX_PASSWORD_LEN);
156#else
157 /* Fill-in the reverse password to save it*/
158 /* for example : original passwork is "MTKTEST", fill-in "TSETKTM" */
159 kal_char scrambled_password[] = "TSETKTM";
160
161 // The scramble algorithm is string reverse, customer can design a way in the following code
162 {
163 kal_uint8 i = 0, j = (sizeof(scrambled_password) - 2);
164 for (i = 0 ; i < (sizeof(scrambled_password) - 1)/2 ; i++, j--)
165 {
166 kal_char temp_c = scrambled_password[i];
167 scrambled_password[i] = scrambled_password[j];
168 scrambled_password[j] = temp_c;
169 }
170 }
171
172 strncpy(password, scrambled_password, MCF_MAX_PASSWORD_LEN);
173#endif
174}
175
176/*****************************************************************************
177 * FUNCTION
178 * mcf_get_custom_digest_public_key
179 * DESCRIPTION
180 * This function is used to get MCF digest public key.
181 * PARAMETERS
182 * digest_key_seq [IN] key sequence from OTA file
183 * key [OUT] digest public key of this digest_key_seq
184 *
185 *****************************************************************************/
186kal_bool mcf_get_custom_digest_public_key(kal_uint32 digest_key_seq, t_cust_chl_asym_key *key)
187{
188 // customer defines the mapping between "digest_key_seq from OTA file" and "public key in custom_sec_key.c"
189 if (digest_key_seq == 0)
190 {
191 CustCHL_Get_Asym_Key(CUST_MCF_PUB_KEY1, key);
192 return KAL_TRUE;
193 }
194 else if (digest_key_seq == 1)
195 {
196 CustCHL_Get_Asym_Key(CUST_MCF_PUB_KEY2, key);
197 return KAL_TRUE;
198 }
199 /*
200 else if (digest_key_seq == 2)
201 {
202 CustCHL_Get_Asym_Key(CUST_MCF_PUB_KEY3, key);
203 }
204 */
205 return KAL_FALSE; // key not found
206}
207
208/*****************************************************************************
209 * FUNCTION
210 * mcf_get_custom_operation_mask
211 * DESCRIPTION
212 * This function is used to get MCF customized operation mask.
213 * If OTA file without customized operation mask, MCF won't update OTA file.
214 * PARAMETERS
215 * operation_mask [OUT] customized operation mask
216 *
217 *****************************************************************************/
218kal_uint32 mcf_get_custom_operation_mask()
219{
220 // customer defines the operation mask which file must have
221 kal_uint32 operation_mask = 0;
222
223 /* //If OTA file must with checksum check
224 operation_mask |= MCF_FILE_OP_CHECKSUM;
225 */
226
227 /* //If OTA file must with AES-128 encryption
228 operation_mask |= MCF_FILE_OP_AES_128;
229 */
230
231 /* //If OTA file must with AES-256 encryption
232 operation_mask |= MCF_FILE_OP_AES_256;
233 */
234
235 /* //If OTA file must with SHA-256 and RSA-2048 digital signature
236 operation_mask |= MCF_FILE_OP_SHA256_RSA2048;
237 */
238
239 return operation_mask;
240}
241