rjw | 6c1fd8f | 2022-11-30 14:33:01 +0800 | [diff] [blame] | 1 | /***************************************************************************** |
| 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) 2005 |
| 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 | * |
| 38 | * Filename: |
| 39 | * --------- |
| 40 | * custom_nvram_sec.c |
| 41 | * |
| 42 | * Project: |
| 43 | * -------- |
| 44 | * MAUI |
| 45 | * |
| 46 | * Description: |
| 47 | * ------------ |
| 48 | * This file is intends for NVRAM security customization. |
| 49 | * |
| 50 | * Author: |
| 51 | * ------- |
| 52 | * ------- |
| 53 | * |
| 54 | *============================================================================ |
| 55 | * HISTORY |
| 56 | * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!! |
| 57 | *------------------------------------------------------------------------------ |
| 58 | * removed! |
| 59 | * |
| 60 | * removed! |
| 61 | * removed! |
| 62 | * removed! |
| 63 | * removed! |
| 64 | * |
| 65 | * removed! |
| 66 | * removed! |
| 67 | * removed! |
rjw | 8e44aab | 2022-11-30 16:42:16 +0800 | [diff] [blame] | 68 | * removed! |
| 69 | * |
| 70 | * removed! |
| 71 | * removed! |
| 72 | * removed! |
rjw | 6c1fd8f | 2022-11-30 14:33:01 +0800 | [diff] [blame] | 73 | * |
| 74 | * removed! |
| 75 | * removed! |
| 76 | * removed! |
| 77 | * removed! |
| 78 | * removed! |
| 79 | * |
| 80 | * removed! |
| 81 | * removed! |
| 82 | * removed! |
| 83 | * |
| 84 | * removed! |
| 85 | * removed! |
| 86 | * removed! |
| 87 | * removed! |
| 88 | * |
| 89 | * removed! |
| 90 | * removed! |
| 91 | * removed! |
| 92 | * removed! |
| 93 | * |
| 94 | * removed! |
| 95 | * removed! |
| 96 | * removed! |
| 97 | * removed! |
| 98 | * |
| 99 | * removed! |
| 100 | * removed! |
| 101 | * |
| 102 | * removed! |
| 103 | * removed! |
| 104 | * removed! |
| 105 | * removed! |
| 106 | * removed! |
| 107 | * removed! |
| 108 | * removed! |
| 109 | * |
| 110 | * removed! |
| 111 | * removed! |
| 112 | * removed! |
| 113 | * |
| 114 | * removed! |
| 115 | * removed! |
| 116 | * |
| 117 | * removed! |
| 118 | * removed! |
| 119 | * |
| 120 | * removed! |
| 121 | * removed! |
| 122 | * removed! |
| 123 | * |
| 124 | * removed! |
| 125 | * removed! |
| 126 | * removed! |
| 127 | * |
| 128 | * removed! |
| 129 | * removed! |
| 130 | * removed! |
| 131 | * |
| 132 | * removed! |
| 133 | * removed! |
| 134 | * removed! |
| 135 | * removed! |
| 136 | * |
| 137 | * removed! |
| 138 | * removed! |
| 139 | * removed! |
| 140 | * |
| 141 | * removed! |
| 142 | * removed! |
| 143 | * removed! |
| 144 | * |
| 145 | * removed! |
| 146 | * removed! |
| 147 | * removed! |
| 148 | * |
| 149 | * removed! |
| 150 | * removed! |
| 151 | * |
| 152 | * removed! |
| 153 | * removed! |
| 154 | * removed! |
| 155 | * removed! |
| 156 | * |
| 157 | * removed! |
| 158 | * removed! |
| 159 | * removed! |
| 160 | * |
| 161 | * removed! |
| 162 | * removed! |
| 163 | * removed! |
| 164 | * |
| 165 | * removed! |
| 166 | * removed! |
| 167 | * removed! |
| 168 | * |
| 169 | * removed! |
| 170 | * removed! |
| 171 | * removed! |
| 172 | * |
| 173 | * removed! |
| 174 | * removed! |
| 175 | * removed! |
| 176 | * |
| 177 | * removed! |
| 178 | * removed! |
| 179 | * |
| 180 | * removed! |
| 181 | * removed! |
| 182 | * removed! |
| 183 | * removed! |
| 184 | * removed! |
| 185 | * removed! |
| 186 | * removed! |
| 187 | * removed! |
| 188 | * removed! |
| 189 | * removed! |
| 190 | * removed! |
| 191 | * |
| 192 | * removed! |
| 193 | * removed! |
| 194 | * removed! |
| 195 | * |
| 196 | * removed! |
| 197 | * removed! |
| 198 | * removed! |
| 199 | * |
| 200 | * removed! |
| 201 | * removed! |
| 202 | * removed! |
| 203 | * |
| 204 | * removed! |
| 205 | * removed! |
| 206 | * removed! |
| 207 | * |
| 208 | * removed! |
| 209 | * removed! |
| 210 | * removed! |
| 211 | * |
| 212 | * removed! |
| 213 | * removed! |
| 214 | * removed! |
| 215 | * |
| 216 | * removed! |
| 217 | * removed! |
| 218 | * removed! |
| 219 | * |
| 220 | * removed! |
| 221 | * removed! |
| 222 | * removed! |
| 223 | * |
| 224 | * removed! |
| 225 | * removed! |
| 226 | * removed! |
| 227 | * |
| 228 | * removed! |
| 229 | * removed! |
| 230 | * removed! |
| 231 | * |
| 232 | * removed! |
| 233 | * removed! |
| 234 | * removed! |
| 235 | * |
| 236 | * removed! |
| 237 | * removed! |
| 238 | * removed! |
| 239 | * |
| 240 | * removed! |
| 241 | * removed! |
| 242 | * removed! |
| 243 | * |
| 244 | * removed! |
| 245 | * removed! |
| 246 | * removed! |
| 247 | * |
| 248 | * removed! |
| 249 | * removed! |
| 250 | * removed! |
| 251 | * |
| 252 | * removed! |
| 253 | * removed! |
| 254 | * removed! |
| 255 | * |
| 256 | * removed! |
| 257 | * removed! |
| 258 | * removed! |
| 259 | * |
| 260 | * removed! |
| 261 | * removed! |
| 262 | * removed! |
| 263 | * |
| 264 | * removed! |
| 265 | * removed! |
| 266 | * removed! |
| 267 | * |
| 268 | * removed! |
| 269 | * removed! |
| 270 | * removed! |
| 271 | * |
| 272 | * removed! |
| 273 | * removed! |
| 274 | * removed! |
| 275 | * |
| 276 | * removed! |
| 277 | * removed! |
| 278 | * removed! |
| 279 | * |
| 280 | * removed! |
| 281 | * removed! |
| 282 | * removed! |
| 283 | * |
| 284 | * removed! |
| 285 | * removed! |
| 286 | * removed! |
| 287 | * |
| 288 | * removed! |
| 289 | * removed! |
| 290 | * removed! |
| 291 | * |
| 292 | * removed! |
| 293 | * removed! |
| 294 | * removed! |
| 295 | * |
| 296 | * removed! |
| 297 | * removed! |
| 298 | * removed! |
| 299 | * |
| 300 | * removed! |
| 301 | * removed! |
| 302 | * removed! |
| 303 | * |
| 304 | * removed! |
| 305 | * removed! |
| 306 | * removed! |
| 307 | * |
| 308 | * removed! |
| 309 | * removed! |
| 310 | * removed! |
| 311 | * |
| 312 | * removed! |
| 313 | * removed! |
| 314 | * removed! |
| 315 | * |
| 316 | * removed! |
| 317 | * removed! |
| 318 | * removed! |
| 319 | * |
| 320 | * removed! |
| 321 | * removed! |
| 322 | * removed! |
| 323 | * |
| 324 | * removed! |
| 325 | * removed! |
| 326 | * removed! |
| 327 | * |
| 328 | * removed! |
| 329 | * removed! |
| 330 | * removed! |
| 331 | * |
| 332 | * removed! |
| 333 | * removed! |
| 334 | * removed! |
| 335 | * |
| 336 | *------------------------------------------------------------------------------ |
| 337 | * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!! |
| 338 | *============================================================================ |
| 339 | ****************************************************************************/ |
| 340 | #if !defined(NVRAM_NOT_PRESENT) |
| 341 | |
| 342 | #include <string.h> |
| 343 | #include <stdio.h> |
| 344 | |
| 345 | #include "kal_general_types.h" |
| 346 | #include "custom_nvram_sec.h" |
| 347 | |
| 348 | #include "kal_public_api.h" |
| 349 | #include "SST_secure.h" |
| 350 | |
| 351 | #include "nvram_lid_statistics.h" /* NVRAM_SECUPACK_SIZE */ |
| 352 | #include "sml_public_def.h" |
| 353 | #include "cust_chl_interface.h" |
| 354 | #include "che_api.h" |
| 355 | |
| 356 | #ifndef __OPTR_NONE__ |
| 357 | #include "op_custom_nvram_sec.h" |
| 358 | #endif |
| 359 | |
rjw | 8e44aab | 2022-11-30 16:42:16 +0800 | [diff] [blame] | 360 | #include "custom_nvram_extra.h" /* SML_STATE_UNLOCK */ |
| 361 | |
rjw | 6c1fd8f | 2022-11-30 14:33:01 +0800 | [diff] [blame] | 362 | #ifdef NVRAM_AUTO_GEN |
| 363 | // fake API for nvram_auto_gen compile |
| 364 | #define memcpy(...) |
| 365 | #define memset(...) |
| 366 | #endif |
| 367 | |
| 368 | #if defined(NVRAM_AUTO_GEN) |
| 369 | |
rjw | 6c1fd8f | 2022-11-30 14:33:01 +0800 | [diff] [blame] | 370 | |
| 371 | /******************************************************************************** |
| 372 | * This key is used to encrypt (software) the data with NVRAM_ATTR_CONFIDENTIAL |
| 373 | * in NVRAM , we suggest custom must change this key and make it secretly if possible |
| 374 | *************************************************************/ |
| 375 | const kal_uint8 custom_secret_key[NVRAM_SECRET_KEY_SIZE] = {0x31, 0x32, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66}; |
| 376 | |
| 377 | |
| 378 | const kal_uint8 custom_key_seed[NVRAM_CUSTOM_KEY_SEED_SIZE]={0x1,0x2,0x3,0x4,0x5,0x6,0x7,0x8,0x9,0xA,0xB,0xC,0xD,0xE,0xF,0x10,0x11,0x12,013,0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1B,0x1C}; |
| 379 | |
| 380 | const kal_uint8 NVRAM_SECURE_PARA[SEC_RO_PARA_TOTAL] = |
| 381 | { |
| 382 | 0x01 |
| 383 | }; |
| 384 | |
| 385 | /******************************************************************** |
| 386 | * This configuration is used to configure NVRAM checksum algorithm |
| 387 | ********************************************************************/ |
| 388 | /* |
| 389 | * typedef struct |
| 390 | * { |
| 391 | * kal_uint32 enhance_algo_size; |
| 392 | * kal_uint32 enhance_algo_type; |
| 393 | * kal_uint32 default_algo_size; |
| 394 | * kal_uint32 default_algo_type; |
| 395 | * } nvram_checksum_config; |
| 396 | * |
| 397 | */ |
| 398 | |
| 399 | |
| 400 | const nvram_checksum_config CUSTOM_CHK_ALGO_CONFIG = |
| 401 | { |
| 402 | 32, NVRAM_HMAC_SHA256, 16, NVRAM_MD5 |
| 403 | }; |
| 404 | |
| 405 | #ifdef __SECURE_USB_DOWNLOAD__ |
| 406 | const kal_uint8 custom_symmetric_key[NVRAM_SECRET_KEY_MAX_SIZE] = |
| 407 | { |
| 408 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, |
| 409 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, |
| 410 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, |
| 411 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, |
| 412 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, |
| 413 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, |
| 414 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, |
| 415 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F |
| 416 | }; |
| 417 | const T_Customer_Public_Key custom_asymmetric_key = |
| 418 | { |
| 419 | 2, 64, 0x0051, 8, |
| 420 | {0x0001, 0x0001}, |
| 421 | { |
| 422 | 0x002A, 0x178D, 0xBCB4, 0xC985, 0xD21E, 0x2A71, 0xDBE4, 0x1E27, |
| 423 | 0x29CD, 0x2285, 0x65B3, 0x6596, 0x2B4C, 0x8266, 0x057B, 0xB911, |
| 424 | 0x283D, 0x1912, 0xB02D, 0x2B15, 0xB61D, 0x8DB9, 0xC1D9, 0x069C, |
| 425 | 0xA352, 0xD7F6, 0x0EAB, 0x46EB, 0xB0CE, 0xAEC5, 0x842C, 0x92B1, |
| 426 | 0x94FC, 0xD410, 0x60F5, 0x8F2C, 0x186A, 0x9527, 0xF40A, 0x4DF9, |
| 427 | 0xA31D, 0x86C0, 0x7464, 0xB57C, 0x600A, 0xB37A, 0x02FB, 0xD0A6, |
| 428 | 0x6399, 0xB779, 0x96A7, 0x9B5E, 0x2E8D, 0x0247, 0xA844, 0x28EE, |
| 429 | 0x26B6, 0xAF64, 0x7C49, 0xC924, 0xD8DF, 0x5FBA, 0xEBAA, 0xB74F |
| 430 | } |
| 431 | }; |
| 432 | #endif /* __SECURE_USB_DOWNLOAD__ */ |
| 433 | |
rjw | 8e44aab | 2022-11-30 16:42:16 +0800 | [diff] [blame] | 434 | /* --Boundry - Custom SecuPack Default Values-- */ |
| 435 | |
| 436 | /* --Boundry - Custom SecuPack Default Values-- */ |
| 437 | |
| 438 | #else /* NVRAM_AUTO_GEN */ |
| 439 | |
| 440 | #include "nvram_sec.h" |
| 441 | |
| 442 | /* |
| 443 | * Local variable |
| 444 | */ |
| 445 | static int X; |
| 446 | static int hashIndex = 0; |
| 447 | |
| 448 | /***************************************************************************** |
| 449 | * FUNCTION |
| 450 | * custom_nvram_sec_ro_size |
| 451 | * DESCRIPTION |
| 452 | * |
| 453 | * PARAMETERS |
| 454 | * void |
| 455 | * RETURNS |
| 456 | * |
| 457 | *****************************************************************************/ |
| 458 | kal_uint32 custom_nvram_sec_ro_size(void) |
| 459 | { |
| 460 | /*----------------------------------------------------------------*/ |
| 461 | /* Local Variables */ |
| 462 | /*----------------------------------------------------------------*/ |
| 463 | |
| 464 | /*----------------------------------------------------------------*/ |
| 465 | /* Code Body */ |
| 466 | /*----------------------------------------------------------------*/ |
| 467 | return 0; |
| 468 | } |
| 469 | |
| 470 | /***************************************************************************** |
| 471 | * FUNCTION |
| 472 | * custom_nvram_sec_ro_size |
| 473 | * DESCRIPTION |
| 474 | * |
| 475 | * PARAMETERS |
| 476 | * void |
| 477 | * RETURNS |
| 478 | * |
| 479 | *****************************************************************************/ |
| 480 | kal_uint32 custom_nvram_secupack_size(void) |
| 481 | { |
| 482 | /*----------------------------------------------------------------*/ |
| 483 | /* Local Variables */ |
| 484 | /*----------------------------------------------------------------*/ |
| 485 | |
| 486 | /*----------------------------------------------------------------*/ |
| 487 | /* Code Body */ |
| 488 | /*----------------------------------------------------------------*/ |
| 489 | return NVRAM_SECUPACK_SIZE; |
| 490 | } |
| 491 | |
| 492 | /***************************************************************************** |
| 493 | * FUNCTION |
| 494 | * custom_nvram_secupack_total |
| 495 | * DESCRIPTION |
| 496 | * |
| 497 | * PARAMETERS |
| 498 | * void |
| 499 | * RETURNS |
| 500 | * |
| 501 | *****************************************************************************/ |
| 502 | kal_uint32 custom_nvram_secupack_total(void) |
| 503 | { |
| 504 | /*----------------------------------------------------------------*/ |
| 505 | /* Local Variables */ |
| 506 | /*----------------------------------------------------------------*/ |
| 507 | |
| 508 | /*----------------------------------------------------------------*/ |
| 509 | /* Code Body */ |
| 510 | /*----------------------------------------------------------------*/ |
| 511 | return NVRAM_SECUPACK_TOTAL; |
| 512 | } |
| 513 | |
| 514 | |
| 515 | /***************************************************************************** |
| 516 | * FUNCTION |
| 517 | * custom_nvram_sec_ro_size |
| 518 | * DESCRIPTION |
| 519 | * |
| 520 | * PARAMETERS |
| 521 | * void |
| 522 | * RETURNS |
| 523 | * |
| 524 | *****************************************************************************/ |
| 525 | kal_uint32 custom_nvram_key_len(void) |
| 526 | { |
| 527 | /*----------------------------------------------------------------*/ |
| 528 | /* Local Variables */ |
| 529 | /*----------------------------------------------------------------*/ |
| 530 | |
| 531 | /*----------------------------------------------------------------*/ |
| 532 | /* Code Body */ |
| 533 | /*----------------------------------------------------------------*/ |
| 534 | return NVRAM_SECRET_KEY_SIZE; |
| 535 | } |
| 536 | |
| 537 | /***************************************************************************** |
| 538 | * FUNCTION |
| 539 | * IV_generator |
| 540 | * DESCRIPTION |
| 541 | * |
| 542 | * PARAMETERS |
| 543 | * void |
| 544 | * RETURNS |
| 545 | * |
| 546 | *****************************************************************************/ |
| 547 | int custom_nvram_IV_generator(void) |
| 548 | { |
| 549 | /*----------------------------------------------------------------*/ |
| 550 | /* Local Variables */ |
| 551 | /*----------------------------------------------------------------*/ |
| 552 | |
| 553 | /*----------------------------------------------------------------*/ |
| 554 | /* Code Body */ |
| 555 | /*----------------------------------------------------------------*/ |
| 556 | /* |
| 557 | * f(x)=A*|X-B|+C |
| 558 | * if(X>B) |
| 559 | * hashIndex = (A*(X-B)+C)%256; |
| 560 | * else |
| 561 | * hashIndex = (A*(B-X)+C)%256; |
| 562 | */ |
| 563 | return hashIndex; |
| 564 | } |
| 565 | |
| 566 | |
| 567 | /***************************************************************************** |
| 568 | * FUNCTION |
| 569 | * custom_nvram_get_key |
| 570 | * DESCRIPTION |
| 571 | * |
| 572 | * PARAMETERS |
| 573 | * init_key [?] |
| 574 | * keys [?] |
| 575 | * RETURNS |
| 576 | * void |
| 577 | *****************************************************************************/ |
| 578 | void custom_nvram_get_key(char *init_key, unsigned char *keys) |
| 579 | { |
| 580 | /*----------------------------------------------------------------*/ |
| 581 | /* Local Variables */ |
| 582 | /*----------------------------------------------------------------*/ |
| 583 | |
| 584 | /*----------------------------------------------------------------*/ |
| 585 | /* Code Body */ |
| 586 | /*----------------------------------------------------------------*/ |
| 587 | nvram_get_key(init_key, keys); |
| 588 | } |
| 589 | |
| 590 | |
| 591 | /***************************************************************************** |
| 592 | * FUNCTION |
| 593 | * custom_nvram_encrypt |
| 594 | * DESCRIPTION |
| 595 | * |
| 596 | * PARAMETERS |
| 597 | * keys [?] |
| 598 | * buffer [?] |
| 599 | * length [IN] |
| 600 | * scrambleIndex [IN] |
| 601 | * RETURNS |
| 602 | * void |
| 603 | *****************************************************************************/ |
| 604 | void custom_nvram_encrypt(unsigned char const *keys, unsigned char *buffer, unsigned int length, int scrambleIndex) |
| 605 | { |
| 606 | /*----------------------------------------------------------------*/ |
| 607 | /* Local Variables */ |
| 608 | /*----------------------------------------------------------------*/ |
| 609 | |
| 610 | /*----------------------------------------------------------------*/ |
| 611 | /* Code Body */ |
| 612 | /*----------------------------------------------------------------*/ |
| 613 | kal_int32 ret; |
| 614 | kal_uint8 key_buffer[256] = {0}; |
| 615 | ret=SST_Get_NVRAM_SW_Key((void*)key_buffer,256,(void *)NVRAM_CUSTOM_KEY_SEED,NVRAM_CUSTOM_KEY_SEED_SIZE); |
| 616 | if(ret!=GET_NVRAM_KEY_ERROR_NONE ) |
| 617 | { |
| 618 | EXT_ASSERT(KAL_FALSE, ret, 0, 0); |
| 619 | } |
| 620 | X = scrambleIndex; |
| 621 | nvram_encrypt(key_buffer, buffer, length, custom_nvram_IV_generator); |
| 622 | } |
| 623 | void nvram_AES_encrypt(unsigned char *buffer, unsigned int length) |
| 624 | { |
| 625 | /*----------------------------------------------------------------*/ |
| 626 | /* Local Variables */ |
| 627 | /*----------------------------------------------------------------*/ |
| 628 | |
| 629 | /*----------------------------------------------------------------*/ |
| 630 | /* Code Body */ |
| 631 | /*----------------------------------------------------------------*/ |
| 632 | kal_int32 ret; |
| 633 | #if defined(__AES256_SUPPORT__) |
| 634 | kal_uint8 key_buffer[NVRAM_AES_KEY_LEN_256BIT] = {0}; |
| 635 | ret=SST_Get_NVRAM_SW_Key((void*)key_buffer,NVRAM_AES_KEY_LEN_256BIT,(void *)NVRAM_CUSTOM_KEY_SEED,NVRAM_CUSTOM_KEY_SEED_SIZE); |
| 636 | #else |
| 637 | kal_uint8 key_buffer[NVRAM_AES_KEY_LEN_128BIT] = {0}; |
| 638 | ret=SST_Get_NVRAM_SW_Key((void*)key_buffer,NVRAM_AES_KEY_LEN_128BIT,(void *)NVRAM_CUSTOM_KEY_SEED,NVRAM_CUSTOM_KEY_SEED_SIZE); |
| 639 | #endif |
| 640 | if(ret!=GET_NVRAM_KEY_ERROR_NONE ) |
| 641 | { |
| 642 | EXT_ASSERT(KAL_FALSE, ret, 0, 0); |
| 643 | } |
| 644 | #if defined(__AES256_SUPPORT__) |
| 645 | ret=nvram_AES_cipher_encrypt(key_buffer, NVRAM_AES_KEY_LEN_256BIT, buffer, buffer, length); |
| 646 | #else |
| 647 | ret=nvram_AES_cipher_encrypt(key_buffer, NVRAM_AES_KEY_LEN_128BIT, buffer, buffer, length); |
| 648 | #endif |
| 649 | if(ret != NVRAM_AES_ERROR_NONE){ |
| 650 | EXT_ASSERT(KAL_FALSE, ret, 0, 0); |
| 651 | } |
| 652 | } |
| 653 | |
| 654 | /***************************************************************************** |
| 655 | * FUNCTION |
| 656 | * nvram_calculate_checksum |
| 657 | * DESCRIPTION |
| 658 | * |
| 659 | * PARAMETERS |
| 660 | * type [IN] |
| 661 | * source [IN] |
| 662 | * source_length [IN] |
| 663 | * dest [OUT] |
| 664 | * RETURNS |
| 665 | * void |
| 666 | *****************************************************************************/ |
| 667 | void nvram_calculate_checksum(NVRAM_ALGO_TYPE type, kal_uint8 *source, kal_uint32 source_length, kal_uint8 *dest) |
| 668 | { |
| 669 | kal_uint32 ret = 0; |
| 670 | if (source == NULL || dest == NULL) EXT_ASSERT(KAL_FALSE, ret, 0, 0); |
| 671 | kal_uint32 dest_length; |
| 672 | |
| 673 | switch(type) |
| 674 | { |
| 675 | case NVRAM_MD5: |
| 676 | { |
| 677 | ret = che_calculate_exc_ext(CHE_MD5, CHE_MODE_NULL, CHE_HASH, NULL, 0, source, source_length, dest, &dest_length); |
| 678 | if (ret != CHE_NO_ERROR) EXT_ASSERT(KAL_FALSE, ret, 0, 0); |
| 679 | break; |
| 680 | } |
| 681 | case NVRAM_HMAC_SHA256: |
| 682 | { |
| 683 | t_cust_chl_sym_key hmac_key; |
| 684 | ret = CustCHL_Gen_Root_Key(&hmac_key); |
| 685 | if (ret != CUST_CHL_ERROR_NONE) EXT_ASSERT(KAL_FALSE, ret, 0, 0); |
| 686 | ret = che_calculate_exc_ext(CHE_MAC_SHA256, CHE_MODE_NULL, CHE_HASH, hmac_key.m_key, hmac_key.m_key_len, source, source_length, dest, &dest_length); |
| 687 | if (ret != CHE_NO_ERROR) EXT_ASSERT(KAL_FALSE, ret, 0, 0); |
| 688 | break; |
| 689 | } |
| 690 | default: |
| 691 | { |
| 692 | EXT_ASSERT(KAL_FALSE, ret, 0, 0); |
| 693 | break; |
| 694 | } |
| 695 | } |
| 696 | |
| 697 | } |
| 698 | |
| 699 | void nvram_AES_decrypt(unsigned char *buffer, unsigned int length) |
| 700 | { |
| 701 | /*----------------------------------------------------------------*/ |
| 702 | /* Local Variables */ |
| 703 | /*----------------------------------------------------------------*/ |
| 704 | |
| 705 | /*----------------------------------------------------------------*/ |
| 706 | /* Code Body */ |
| 707 | /*----------------------------------------------------------------*/ |
| 708 | kal_int32 ret; |
| 709 | #if defined(__AES256_SUPPORT__) |
| 710 | kal_uint8 key_buffer[NVRAM_AES_KEY_LEN_256BIT] = {0}; |
| 711 | ret=SST_Get_NVRAM_SW_Key((void*)key_buffer,NVRAM_AES_KEY_LEN_256BIT,(void *)NVRAM_CUSTOM_KEY_SEED,NVRAM_CUSTOM_KEY_SEED_SIZE); |
| 712 | #else |
| 713 | kal_uint8 key_buffer[NVRAM_AES_KEY_LEN_128BIT] = {0}; |
| 714 | ret=SST_Get_NVRAM_SW_Key((void*)key_buffer,NVRAM_AES_KEY_LEN_128BIT,(void *)NVRAM_CUSTOM_KEY_SEED,NVRAM_CUSTOM_KEY_SEED_SIZE); |
| 715 | #endif |
| 716 | if(ret!=GET_NVRAM_KEY_ERROR_NONE ) |
| 717 | { |
| 718 | EXT_ASSERT(KAL_FALSE, ret, 0, 0); |
| 719 | } |
| 720 | #if defined(__AES256_SUPPORT__) |
| 721 | ret=nvram_AES_cipher_decrypt(key_buffer, NVRAM_AES_KEY_LEN_256BIT, buffer, buffer, length); |
| 722 | #else |
| 723 | ret=nvram_AES_cipher_decrypt(key_buffer, NVRAM_AES_KEY_LEN_128BIT, buffer, buffer, length); |
| 724 | #endif |
| 725 | if(ret != NVRAM_AES_ERROR_NONE){ |
| 726 | EXT_ASSERT(KAL_FALSE, ret, 0, 0); |
| 727 | } |
| 728 | } |
| 729 | |
| 730 | |
| 731 | /***************************************************************************** |
| 732 | * FUNCTION |
| 733 | * custom_nvram_decrypt |
| 734 | * DESCRIPTION |
| 735 | * |
| 736 | * PARAMETERS |
| 737 | * keys [?] |
| 738 | * buffer [?] |
| 739 | * length [IN] |
| 740 | * scrambleIndex [IN] |
| 741 | * RETURNS |
| 742 | * void |
| 743 | *****************************************************************************/ |
| 744 | void custom_nvram_decrypt(unsigned char const *keys, unsigned char *buffer, unsigned int length, int scrambleIndex) |
| 745 | { |
| 746 | /*----------------------------------------------------------------*/ |
| 747 | /* Local Variables */ |
| 748 | /*----------------------------------------------------------------*/ |
| 749 | |
| 750 | /*----------------------------------------------------------------*/ |
| 751 | /* Code Body */ |
| 752 | /*----------------------------------------------------------------*/ |
| 753 | kal_int32 ret; |
| 754 | kal_uint8 key_buffer[256] = {0}; |
| 755 | ret=SST_Get_NVRAM_SW_Key((void*)key_buffer,256,(void *)NVRAM_CUSTOM_KEY_SEED,NVRAM_CUSTOM_KEY_SEED_SIZE); |
| 756 | if(ret!=GET_NVRAM_KEY_ERROR_NONE ) |
| 757 | { |
| 758 | EXT_ASSERT(KAL_FALSE, ret, 0, 0); |
| 759 | } |
| 760 | X = scrambleIndex; |
| 761 | nvram_decrypt(key_buffer, buffer, length, custom_nvram_IV_generator); |
| 762 | |
| 763 | } |
| 764 | |
| 765 | |
| 766 | /***************************************************************************** |
| 767 | * FUNCTION |
| 768 | * mmi_sml_auto_key_gen_implemetation |
| 769 | * DESCRIPTION |
| 770 | * automatic key generation |
| 771 | * PARAMETERS |
| 772 | * key [IN] |
| 773 | * RETURNS |
| 774 | * void |
| 775 | *****************************************************************************/ |
| 776 | void mmi_sml_auto_key_gen_implemetation(unsigned char *key) |
| 777 | { |
| 778 | /*----------------------------------------------------------------*/ |
| 779 | /* Local Variables */ |
| 780 | /*----------------------------------------------------------------*/ |
| 781 | |
| 782 | /*----------------------------------------------------------------*/ |
| 783 | /* Code Body */ |
| 784 | /*----------------------------------------------------------------*/ |
| 785 | |
| 786 | /* return 1234 as default key */ |
| 787 | /* please implement this function for automatic key generation */ |
| 788 | /* the generated key length should at least 8 digits and also has null-terminator */ |
| 789 | key[0] = 0x31; |
| 790 | key[1] = 0x32; |
| 791 | key[2] = 0x33; |
| 792 | key[3] = 0x34; |
| 793 | key[4] = 0x35; |
| 794 | key[5] = 0x36; |
| 795 | key[6] = 0x37; |
| 796 | key[7] = 0x38; |
| 797 | key[8] = 0; |
| 798 | } |
| 799 | #endif /* NVRAM_AUTO_GEN */ |
| 800 | |
| 801 | |
rjw | 6c1fd8f | 2022-11-30 14:33:01 +0800 | [diff] [blame] | 802 | /* |
| 803 | * typedef struct { |
| 804 | * kal_uint32 magic_head; -> 4 |
| 805 | * sml_category_meta_struct cat[SML_SUPPORT_CAT_SIZE]; -> ( 4 * 7) |
| 806 | * sml_control_key_struct key[SML_SUPPORT_CAT_SIZE]; -> ( 9 * 7) |
| 807 | * kal_uint8 code_cat_n[SML_CFG_CAT_N_SIZE]; -> (30 * 3) |
| 808 | * kal_uint8 code_cat_ns[SML_CFG_CAT_NS_SIZE]; -> (30 * 4) |
| 809 | * kal_uint8 code_cat_sp[SML_CFG_CAT_SP_SIZE]; -> (30 * 4) |
| 810 | * kal_uint8 code_cat_c[SML_CFG_CAT_C_SIZE]; -> (30 * 5) |
| 811 | * kal_uint8 code_cat_sim[SML_CFG_CAT_SIM_SIZE]; -> (30 * 8) |
| 812 | * kal_uint8 code_cat_ns_sp[SML_CFG_CAT_NS_SP_SIZE]; -> ( 5 * 10) |
| 813 | * kal_uint8 code_cat_sim_c[SML_CFG_CAT_SIM_C_SIZE]; -> (10 * 10) |
| 814 | * kal_uint8 range_cat_ns[SML_CAT_NS_RANGE_SIZE]; -> 2 |
| 815 | * kal_uint32 magic_tail; -> 4 |
| 816 | * } sml_context_struct; -> 971 |
| 817 | */ |
| 818 | |
| 819 | const nvram_sml_context_struct NVRAM_EF_SML_DEFAULT = |
| 820 | { |
| 821 | SML_MAGIC_HEAD_VALUE, |
| 822 | #ifdef CUSTOM_SML_DEFAULT |
| 823 | CUSTOM_SML_DEFAULT |
| 824 | #else /* CUSTOM_SML_DEFAULT */ |
| 825 | {{SML_STATE_UNLOCK,SML_RETRY_COUNT_N_CAT,0,0}, /* Category N */ |
| 826 | {SML_STATE_UNLOCK,SML_RETRY_COUNT_NS_CAT ,0,0}, /* Category NS */ |
| 827 | {SML_STATE_UNLOCK,SML_RETRY_COUNT_SP_CAT ,0,0}, /* Category SP */ |
| 828 | {SML_STATE_UNLOCK,SML_RETRY_COUNT_C_CAT ,0,0}, /* Category C */ |
| 829 | {SML_STATE_UNLOCK,SML_RETRY_COUNT_SIM_CAT ,0,0}, /* Category SIM */ |
| 830 | {SML_STATE_UNLOCK,SML_RETRY_COUNT_NS_CAT ,0,0}, /* Link NS-SP */ |
| 831 | {SML_STATE_UNLOCK,SML_RETRY_COUNT_C_CAT ,0,0}}, /* Link SIM-C */ |
| 832 | {{SML_KEY_EMPTY,{0x21,0x43,0x65,0x87,0xFF,0xFF,0xFF,0xFF}}, |
| 833 | {SML_KEY_EMPTY,{0x65,0x87,0x21,0x43,0xFF,0xFF,0xFF,0xFF}}, |
| 834 | {SML_KEY_EMPTY,{0x11,0x11,0x22,0x22,0xFF,0xFF,0xFF,0xFF}}, |
| 835 | {SML_KEY_EMPTY,{0x33,0x33,0x44,0x44,0xFF,0xFF,0xFF,0xFF}}, |
| 836 | {SML_KEY_EMPTY,{0x55,0x55,0x66,0x66,0xFF,0xFF,0xFF,0xFF}}, |
| 837 | {SML_KEY_EMPTY,{0x77,0x77,0x88,0x88,0xFF,0xFF,0xFF,0xFF}}, |
| 838 | {SML_KEY_EMPTY,{0x99,0x99,0x00,0x00,0xFF,0xFF,0xFF,0xFF}}}, |
| 839 | /* Category N code */ |
| 840 | {0xc1,0xc1,0xc1, |
| 841 | 0xFF,0xFF,0xFF, |
| 842 | 0xFF,0xFF,0xFF, |
| 843 | 0xFF,0xFF,0xFF, |
| 844 | 0xFF,0xFF,0xFF, |
| 845 | 0xFF,0xFF,0xFF, |
| 846 | 0xFF,0xFF,0xFF, |
| 847 | 0xFF,0xFF,0xFF, |
| 848 | 0xFF,0xFF,0xFF, |
| 849 | 0xFF,0xFF,0xFF}, |
| 850 | /* Category NS code */ |
| 851 | {0xc2,0xc2,0xc2,0xc2, |
| 852 | 0xFF,0xFF,0xFF,0xFF}, |
| 853 | /* Category SP code */ |
| 854 | {0xc3,0xc3,0xc3,0xc3, |
| 855 | 0xFF,0xFF,0xFF,0xFF}, |
| 856 | /* Category C code */ |
| 857 | {0xc4,0xc4,0xc4,0xc4,0xc4, |
| 858 | 0xFF,0xFF,0xFF,0xFF,0xFF}, |
| 859 | /* Category SIM code */ |
| 860 | {0xc5,0xc5,0xc5,0xc5,0xc5,0xc5,0xc5,0xc5, |
| 861 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}, |
| 862 | /* Link Category NS-SP */ |
| 863 | {0xc6,0xc6,0xc6,0xc6,0xc6, |
| 864 | 0xFF,0xFF,0xFF,0xFF,0xFF}, |
| 865 | /* Link Category SIM-C */ |
| 866 | {0xc7,0xc7,0xc7,0xc7,0xc7,0xc7,0xc7,0xc7,0xc7,0xc7, |
| 867 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}, |
| 868 | /* NS Range size */ |
| 869 | {0xFF,0xFF}, |
| 870 | #endif /* CUSTOM_SML_DEFAULT */ |
| 871 | SML_MAGIC_TAIL_VALUE |
| 872 | }; |
| 873 | |
| 874 | const nvram_sml_tmo_context_struct NVRAM_EF_SML_TMO_DEFAULT = |
| 875 | { |
| 876 | {0x00,0x01,0x00,0x05}, /* version */ |
| 877 | SML_PROTECTION_SCHEME_HMAC_SHA256, /* protection scheme */ |
| 878 | SML_TMO_STATE_PERMANENT_LOCK, /* state */ |
| 879 | {0x00, 0x5C}, /* length (92=42+32+16+2) */ |
| 880 | {0x00, 0x04}, /* num of mcc-mnc */ |
| 881 | {0x31, 0x02, 0x60, 0x00, /* mcc-mnc list */ |
| 882 | 0x31, 0x03, 0x10, 0x00, |
| 883 | 0x31, 0x03, 0x00, 0x00, |
| 884 | 0x00, 0x10, 0x10, 0x00, |
| 885 | 0x00, 0x00, 0x00, 0x00, |
| 886 | 0x00, 0x00, 0x00, 0x00, |
| 887 | 0x00, 0x00, 0x00, 0x00, |
| 888 | 0x00, 0x00, 0x00, 0x00, |
| 889 | 0x00, 0x00, 0x00, 0x00, |
| 890 | 0x00, 0x00, 0x00, 0x00, |
| 891 | }, |
| 892 | {0x00, 0x01}, /* num of gid */ |
| 893 | {0x54, 0x4D, /* gid lst */ |
| 894 | 0x00, 0x00, |
| 895 | 0x00, 0x00, |
| 896 | 0x00, 0x00, |
| 897 | 0x00, 0x00, |
| 898 | 0x00, 0x00, |
| 899 | 0x00, 0x00, |
| 900 | 0x00, 0x00, |
| 901 | 0x00, 0x00, |
| 902 | 0x00, 0x00}, |
| 903 | {0,0}, /* reserved */ |
| 904 | {0,0,0,0,0,0,0,0}, /* start time */ |
| 905 | {0,0,0,0}, /* end time */ |
| 906 | {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* imei */ |
| 907 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, |
| 908 | {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* MAC or signature */ |
| 909 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 910 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 911 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 912 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 913 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 914 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 915 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 916 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 917 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 918 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 919 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 920 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 921 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 922 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 923 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 924 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 925 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 926 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 927 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 928 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 929 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 930 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 931 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 932 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 933 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 934 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 935 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 936 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 937 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 938 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 939 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, |
| 940 | {0,0,0,0} /* unlock time */ |
| 941 | }; |
| 942 | |
| 943 | const nvram_sml_att_context_struct NVRAM_EF_L4_SML_ATT_DEFAULT = |
| 944 | { |
| 945 | {0x00,0x01,0x00,0x05}, /* version */ |
| 946 | SML_PROTECTION_SCHEME_HMAC_SHA256, /* protection scheme */ |
| 947 | SML_ATT_STATE_PERMANENT_LOCK, /* state */ |
| 948 | {0x00, 0x52}, /* length (82) */ |
| 949 | {0x00, 0x02}, /* num of mcc-mnc */ |
| 950 | {0x31, 0x01, 0x50, 0x00, /* mcc-mnc list */ |
| 951 | 0x00, 0x10, 0x10, 0x00, |
| 952 | 0x00, 0x00, 0x00, 0x00, |
| 953 | 0x00, 0x00, 0x00, 0x00, |
| 954 | 0x00, 0x00, 0x00, 0x00, |
| 955 | 0x00, 0x00, 0x00, 0x00, |
| 956 | 0x00, 0x00, 0x00, 0x00, |
| 957 | 0x00, 0x00, 0x00, 0x00, |
| 958 | 0x00, 0x00, 0x00, 0x00, |
| 959 | 0x00, 0x00, 0x00, 0x00, |
| 960 | }, |
| 961 | {0x00, 0x00}, /* num of gid */ |
| 962 | {0x00, 0x00, /* gid lst */ |
| 963 | 0x00, 0x00, |
| 964 | 0x00, 0x00, |
| 965 | 0x00, 0x00, |
| 966 | 0x00, 0x00, |
| 967 | 0x00, 0x00, |
| 968 | 0x00, 0x00, |
| 969 | 0x00, 0x00, |
| 970 | 0x00, 0x00, |
| 971 | 0x00, 0x00}, |
| 972 | {0,0}, /* reserved */ |
| 973 | {0,0,0,0,0,0,0,0}, /* start time */ |
| 974 | {0,0,0,0}, /* end time */ |
| 975 | {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* imei */ |
| 976 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, |
| 977 | {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* MAC or signature */ |
| 978 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 979 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 980 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 981 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 982 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 983 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 984 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 985 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 986 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 987 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 988 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 989 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 990 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 991 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 992 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 993 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 994 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 995 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 996 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 997 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 998 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 999 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1000 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1001 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1002 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1003 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1004 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1005 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1006 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1007 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1008 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, |
| 1009 | {0,0,0,0} /* unlock time */ |
| 1010 | }; |
| 1011 | |
| 1012 | #ifndef __MTK_INTERNAL_ENG_USER__ |
| 1013 | /* --------------------------------------------------------- */ |
| 1014 | /* For customer's project, use hashed control key in default */ |
| 1015 | /* --------------------------------------------------------- */ |
| 1016 | const nvram_sml_context_s_struct NVRAM_EF_SML_S_DEFAULT = |
| 1017 | { |
| 1018 | SML_MAGIC_HEAD_VALUE, |
| 1019 | #ifdef CUSTOM_SML_DEFAULT |
| 1020 | CUSTOM_SML_DEFAULT |
| 1021 | #else /* CUSTOM_SML_DEFAULT */ |
| 1022 | {{SML_STATE_UNLOCK,5,SML_RETRY_COUNT_N_CAT,0,0}, /* Category N */ |
| 1023 | {SML_STATE_UNLOCK,5,SML_RETRY_COUNT_NS_CAT,0,0}, /* Category NS */ |
| 1024 | {SML_STATE_UNLOCK,5,SML_RETRY_COUNT_SP_CAT,0,0}, /* Category SP */ |
| 1025 | {SML_STATE_UNLOCK,5,SML_RETRY_COUNT_C_CAT,0,0}, /* Category C */ |
| 1026 | {SML_STATE_UNLOCK,5,SML_RETRY_COUNT_SIM_CAT,0,0}, /* Category SIM */ |
| 1027 | {SML_STATE_UNLOCK,5,SML_RETRY_COUNT_NS_CAT,0,0}, /* Category NS-SP */ |
| 1028 | {SML_STATE_UNLOCK,5,SML_RETRY_COUNT_C_CAT,0,0}}, /* Category SIM-C */ |
| 1029 | |
| 1030 | /* Category N Key: 12345678 */ |
| 1031 | {{SML_KEY_EMPTY, |
| 1032 | 1, |
| 1033 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 1034 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, |
| 1035 | {0x00,0x00,0x03,0xe8}, |
| 1036 | {0xEB,0xDE,0x3A,0x82,0xC1,0xFD,0xBD,0x6C,0xC9,0xA7,0x8F,0x56,0xD3,0x32,0x30,0xA1, |
| 1037 | 0x1F,0x8B,0x3B,0xE6,0x0B,0x11,0x82,0x63,0xD0,0x79,0xB1,0xD8,0x09,0x06,0x5E,0x12, |
| 1038 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
| 1039 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}}, |
| 1040 | |
| 1041 | /* Category NS Key: 56781234 */ |
| 1042 | {SML_KEY_EMPTY, |
| 1043 | 1, |
| 1044 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 1045 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, |
| 1046 | {0x00,0x00,0x03,0xe8}, |
| 1047 | {0x31,0xB0,0x62,0xB3,0x3D,0x8D,0x1D,0xBC,0x6F,0xF1,0x7E,0x78,0x88,0x02,0x4F,0x71, |
| 1048 | 0x73,0x12,0x55,0x9A,0x6F,0x81,0xDD,0x58,0xF6,0x9D,0x77,0xC0,0x62,0x01,0x84,0x4C, |
| 1049 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
| 1050 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}}, |
| 1051 | |
| 1052 | /* Category SP Key: 11112222 */ |
| 1053 | {SML_KEY_EMPTY, |
| 1054 | 1, |
| 1055 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 1056 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, |
| 1057 | {0x00,0x00,0x03,0xe8}, |
| 1058 | {0xAB,0x60,0x7E,0x6D,0x16,0x59,0xA6,0x03,0x90,0xBC,0x89,0x84,0x69,0xBE,0x98,0xBE, |
| 1059 | 0x32,0xCF,0xA6,0xE3,0x7E,0x87,0x65,0xC8,0xA0,0x4D,0x68,0x14,0x35,0x9D,0xD9,0x10, |
| 1060 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
| 1061 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}}, |
| 1062 | |
| 1063 | /* Category C Key: 33334444 */ |
| 1064 | {SML_KEY_EMPTY, |
| 1065 | 1, |
| 1066 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 1067 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, |
| 1068 | {0x00,0x00,0x03,0xe8}, |
| 1069 | {0x7B,0x31,0x28,0xE9,0x81,0xCE,0x5D,0x8C,0x8F,0xF9,0x29,0x5A,0xA3,0x58,0x8B,0xDC, |
| 1070 | 0xD7,0xFE,0x31,0x27,0x80,0xFB,0x72,0x83,0xFC,0x12,0xD8,0x6D,0x67,0xCC,0xF6,0x30, |
| 1071 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
| 1072 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}}, |
| 1073 | |
| 1074 | /* Category SIM Key: 55556666 */ |
| 1075 | {SML_KEY_EMPTY, |
| 1076 | 1, |
| 1077 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 1078 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, |
| 1079 | {0x00,0x00,0x03,0xe8}, |
| 1080 | {0x1B,0x46,0x92,0x9D,0x8C,0xD3,0x83,0x01,0xD3,0x4E,0x36,0x24,0x1F,0x24,0x00,0x1B, |
| 1081 | 0x03,0x67,0x57,0x88,0x46,0x1A,0x90,0xCC,0xDB,0xFE,0x59,0x1D,0x69,0x63,0x78,0xB5, |
| 1082 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
| 1083 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}}, |
| 1084 | |
| 1085 | /* Category NS-SP Key: 77778888 */ |
| 1086 | {SML_KEY_EMPTY, |
| 1087 | 1, |
| 1088 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 1089 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, |
| 1090 | {0x00,0x00,0x03,0xe8}, |
| 1091 | {0x54,0x87,0x4F,0xD2,0x86,0x21,0xAF,0xE1,0xB4,0xAD,0x88,0xBC,0x26,0x83,0x72,0x43, |
| 1092 | 0x5E,0x79,0x2B,0x25,0x40,0x1A,0x4D,0x86,0x62,0x96,0x3E,0x20,0x53,0x8F,0xA0,0x31, |
| 1093 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
| 1094 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}}, |
| 1095 | |
| 1096 | /* Category SIM-C Key: 99990000 */ |
| 1097 | {SML_KEY_EMPTY, |
| 1098 | 1, |
| 1099 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 1100 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, |
| 1101 | {0x00,0x00,0x03,0xe8}, |
| 1102 | {0x43,0xBE,0x90,0x63,0xB8,0x3A,0xAB,0xD5,0x94,0x8B,0x8B,0x28,0x38,0xA4,0xCD,0x59, |
| 1103 | 0x01,0xE5,0x74,0xCC,0xC1,0x64,0x8D,0xD7,0x44,0x3C,0x49,0xE2,0x16,0x05,0x15,0xE6, |
| 1104 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
| 1105 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}}}, |
| 1106 | |
| 1107 | #if SML_S_LID_VER >= 2 |
| 1108 | /* Category N PUK Key: 12345678 */ |
| 1109 | {{SML_PUK_KEY_DISABLE, 5, 5, |
| 1110 | 1, |
| 1111 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 1112 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, |
| 1113 | {0x00,0x00,0x03,0xe8}, |
| 1114 | {0xEB,0xDE,0x3A,0x82,0xC1,0xFD,0xBD,0x6C,0xC9,0xA7,0x8F,0x56,0xD3,0x32,0x30,0xA1, |
| 1115 | 0x1F,0x8B,0x3B,0xE6,0x0B,0x11,0x82,0x63,0xD0,0x79,0xB1,0xD8,0x09,0x06,0x5E,0x12, |
| 1116 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
| 1117 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}}, |
| 1118 | |
| 1119 | /* Category NS PUK Key: 56781234 */ |
| 1120 | {SML_PUK_KEY_DISABLE, 5, 5, |
| 1121 | 1, |
| 1122 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 1123 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, |
| 1124 | {0x00,0x00,0x03,0xe8}, |
| 1125 | {0x31,0xB0,0x62,0xB3,0x3D,0x8D,0x1D,0xBC,0x6F,0xF1,0x7E,0x78,0x88,0x02,0x4F,0x71, |
| 1126 | 0x73,0x12,0x55,0x9A,0x6F,0x81,0xDD,0x58,0xF6,0x9D,0x77,0xC0,0x62,0x01,0x84,0x4C, |
| 1127 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
| 1128 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}}, |
| 1129 | |
| 1130 | /* Category SP PUK Key: 11112222 */ |
| 1131 | {SML_PUK_KEY_DISABLE, 5, 5, |
| 1132 | 1, |
| 1133 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 1134 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, |
| 1135 | {0x00,0x00,0x03,0xe8}, |
| 1136 | {0xAB,0x60,0x7E,0x6D,0x16,0x59,0xA6,0x03,0x90,0xBC,0x89,0x84,0x69,0xBE,0x98,0xBE, |
| 1137 | 0x32,0xCF,0xA6,0xE3,0x7E,0x87,0x65,0xC8,0xA0,0x4D,0x68,0x14,0x35,0x9D,0xD9,0x10, |
| 1138 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
| 1139 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}}, |
| 1140 | |
| 1141 | /* Category C PUK Key: 33334444 */ |
| 1142 | {SML_PUK_KEY_DISABLE, 5, 5, |
| 1143 | 1, |
| 1144 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 1145 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, |
| 1146 | {0x00,0x00,0x03,0xe8}, |
| 1147 | {0x7B,0x31,0x28,0xE9,0x81,0xCE,0x5D,0x8C,0x8F,0xF9,0x29,0x5A,0xA3,0x58,0x8B,0xDC, |
| 1148 | 0xD7,0xFE,0x31,0x27,0x80,0xFB,0x72,0x83,0xFC,0x12,0xD8,0x6D,0x67,0xCC,0xF6,0x30, |
| 1149 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
| 1150 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}}, |
| 1151 | |
| 1152 | /* Category SIM PUK Key: 55556666 */ |
| 1153 | {SML_PUK_KEY_DISABLE, 5, 5, |
| 1154 | 1, |
| 1155 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 1156 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, |
| 1157 | {0x00,0x00,0x03,0xe8}, |
| 1158 | {0x1B,0x46,0x92,0x9D,0x8C,0xD3,0x83,0x01,0xD3,0x4E,0x36,0x24,0x1F,0x24,0x00,0x1B, |
| 1159 | 0x03,0x67,0x57,0x88,0x46,0x1A,0x90,0xCC,0xDB,0xFE,0x59,0x1D,0x69,0x63,0x78,0xB5, |
| 1160 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
| 1161 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}}, |
| 1162 | |
| 1163 | /* Category NS-SP PUK Key: 77778888 */ |
| 1164 | {SML_PUK_KEY_DISABLE, 5, 5, |
| 1165 | 1, |
| 1166 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 1167 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, |
| 1168 | {0x00,0x00,0x03,0xe8}, |
| 1169 | {0x54,0x87,0x4F,0xD2,0x86,0x21,0xAF,0xE1,0xB4,0xAD,0x88,0xBC,0x26,0x83,0x72,0x43, |
| 1170 | 0x5E,0x79,0x2B,0x25,0x40,0x1A,0x4D,0x86,0x62,0x96,0x3E,0x20,0x53,0x8F,0xA0,0x31, |
| 1171 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
| 1172 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}}, |
| 1173 | |
| 1174 | /* Category SIM-C PUK Key: 99990000 */ |
| 1175 | {SML_PUK_KEY_DISABLE, 5, 5, |
| 1176 | 1, |
| 1177 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 1178 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, |
| 1179 | {0x00,0x00,0x03,0xe8}, |
| 1180 | {0x43,0xBE,0x90,0x63,0xB8,0x3A,0xAB,0xD5,0x94,0x8B,0x8B,0x28,0x38,0xA4,0xCD,0x59, |
| 1181 | 0x01,0xE5,0x74,0xCC,0xC1,0x64,0x8D,0xD7,0x44,0x3C,0x49,0xE2,0x16,0x05,0x15,0xE6, |
| 1182 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
| 1183 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}}}, |
| 1184 | #endif |
| 1185 | |
| 1186 | /* Category N code */ |
| 1187 | {0xc1,0xc1,0xc1, |
| 1188 | 0xFF,0xFF,0xFF, |
| 1189 | 0xFF,0xFF,0xFF, |
| 1190 | 0xFF,0xFF,0xFF, |
| 1191 | 0xFF,0xFF,0xFF, |
| 1192 | 0xFF,0xFF,0xFF, |
| 1193 | 0xFF,0xFF,0xFF, |
| 1194 | 0xFF,0xFF,0xFF, |
| 1195 | 0xFF,0xFF,0xFF, |
| 1196 | 0xFF,0xFF,0xFF}, |
| 1197 | /* Category NS code */ |
| 1198 | {0xc2,0xc2,0xc2,0xc2, |
| 1199 | 0xFF,0xFF,0xFF,0xFF}, |
| 1200 | /* Category SP code */ |
| 1201 | {0xc3,0xc3,0xc3,0xc3, |
| 1202 | 0xFF,0xFF,0xFF,0xFF}, |
| 1203 | /* Category C code */ |
| 1204 | {0xc4,0xc4,0xc4,0xc4,0xc4, |
| 1205 | 0xFF,0xFF,0xFF,0xFF,0xFF}, |
| 1206 | /* Category SIM code */ |
| 1207 | {0xc5,0xc5,0xc5,0xc5,0xc5,0xc5,0xc5,0xc5, |
| 1208 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}, |
| 1209 | /* Category NS-SP */ |
| 1210 | {0xc6,0xc6,0xc6,0xc6,0xc6, |
| 1211 | 0xFF,0xFF,0xFF,0xFF,0xFF}, |
| 1212 | /* Category SIM-C */ |
| 1213 | {0xc7,0xc7,0xc7,0xc7,0xc7,0xc7,0xc7,0xc7,0xc7,0xc7, |
| 1214 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}, |
| 1215 | |
| 1216 | /* NS Range size */ |
| 1217 | {0xFF,0xFF}, |
| 1218 | #endif /* CUSTOM_SML_DEFAULT */ |
| 1219 | SML_MAGIC_TAIL_VALUE |
| 1220 | }; |
| 1221 | |
| 1222 | #else /* not __MTK_INTERNAL_ENG_USER__ */ |
| 1223 | /* --------------------------------------------------------- */ |
| 1224 | /* For MTK internal usage only */ |
| 1225 | /* --------------------------------------------------------- */ |
| 1226 | const nvram_sml_context_s_struct NVRAM_EF_SML_S_DEFAULT = |
| 1227 | { |
| 1228 | SML_MAGIC_HEAD_VALUE, |
| 1229 | |
| 1230 | {{SML_STATE_UNLOCK,5,SML_RETRY_COUNT_N_CAT,0,0}, /* Category N */ |
| 1231 | {SML_STATE_UNLOCK,5,SML_RETRY_COUNT_NS_CAT,0,0}, /* Category NS */ |
| 1232 | {SML_STATE_UNLOCK,5,SML_RETRY_COUNT_SP_CAT,0,0}, /* Category SP */ |
| 1233 | {SML_STATE_UNLOCK,5,SML_RETRY_COUNT_C_CAT,0,0}, /* Category C */ |
| 1234 | {SML_STATE_UNLOCK,5,SML_RETRY_COUNT_SIM_CAT,0,0}, /* Category SIM */ |
| 1235 | {SML_STATE_UNLOCK,5,SML_RETRY_COUNT_NS_CAT,0,0}, /* Category NS-SP */ |
| 1236 | {SML_STATE_UNLOCK,5,SML_RETRY_COUNT_C_CAT,0,0}}, /* Category SIM-C */ |
| 1237 | |
| 1238 | /* Category N Key: 12345678 */ |
| 1239 | {{SML_KEY_EMPTY, |
| 1240 | 0, |
| 1241 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 1242 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, |
| 1243 | {0x00,0x00,0x00,0x00}, |
| 1244 | {0x21,0x43,0x65,0x87,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
| 1245 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
| 1246 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
| 1247 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}}, |
| 1248 | |
| 1249 | /* Category NS Key: 56781234 */ |
| 1250 | {SML_KEY_EMPTY, |
| 1251 | 0, |
| 1252 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 1253 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, |
| 1254 | {0x00,0x00,0x00,0x00}, |
| 1255 | {0x65,0x87,0x21,0x43,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
| 1256 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
| 1257 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
| 1258 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}}, |
| 1259 | |
| 1260 | /* Category SP Key: 11112222 */ |
| 1261 | {SML_KEY_EMPTY, |
| 1262 | 0, |
| 1263 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 1264 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, |
| 1265 | {0x00,0x00,0x00,0x00}, |
| 1266 | {0x11,0x11,0x22,0x22,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
| 1267 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
| 1268 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
| 1269 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}}, |
| 1270 | |
| 1271 | /* Category C Key: 33334444 */ |
| 1272 | {SML_KEY_EMPTY, |
| 1273 | 0, |
| 1274 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 1275 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, |
| 1276 | {0x00,0x00,0x00,0x00}, |
| 1277 | {0x33,0x33,0x44,0x44,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
| 1278 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
| 1279 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
| 1280 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}}, |
| 1281 | |
| 1282 | /* Category SIM Key: 55556666 */ |
| 1283 | {SML_KEY_EMPTY, |
| 1284 | 0, |
| 1285 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 1286 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, |
| 1287 | {0x00,0x00,0x00,0x00}, |
| 1288 | {0x55,0x55,0x66,0x66,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
| 1289 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
| 1290 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
| 1291 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}}, |
| 1292 | |
| 1293 | /* Category NS-SP Key: 77778888 */ |
| 1294 | {SML_KEY_EMPTY, |
| 1295 | 0, |
| 1296 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 1297 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, |
| 1298 | {0x00,0x00,0x00,0x00}, |
| 1299 | {0x77,0x77,0x88,0x88,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
| 1300 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
| 1301 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
| 1302 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}}, |
| 1303 | |
| 1304 | /* Category SIM-C Key: 99990000 */ |
| 1305 | {SML_KEY_EMPTY, |
| 1306 | 0, |
| 1307 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 1308 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, |
| 1309 | {0x00,0x00,0x00,0x00}, |
| 1310 | {0x99,0x99,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
| 1311 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
| 1312 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
| 1313 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}}}, |
| 1314 | |
| 1315 | #if SML_S_LID_VER >= 2 |
| 1316 | /* Category N PUK Key: 12345678 */ |
| 1317 | {{SML_PUK_KEY_DISABLE, 5, 5, |
| 1318 | 0, |
| 1319 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 1320 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, |
| 1321 | {0x00,0x00,0x00,0x00}, |
| 1322 | {0x21,0x43,0x65,0x87,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
| 1323 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
| 1324 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
| 1325 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}}, |
| 1326 | |
| 1327 | /* Category NS PUK Key: 56781234 */ |
| 1328 | {SML_PUK_KEY_DISABLE, 5, 5, |
| 1329 | 0, |
| 1330 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 1331 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, |
| 1332 | {0x00,0x00,0x00,0x00}, |
| 1333 | {0x65,0x87,0x21,0x43,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
| 1334 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
| 1335 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
| 1336 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}}, |
| 1337 | |
| 1338 | /* Category SP PUK Key: 11112222 */ |
| 1339 | {SML_PUK_KEY_DISABLE, 5, 5, |
| 1340 | 0, |
| 1341 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 1342 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, |
| 1343 | {0x00,0x00,0x00,0x00}, |
| 1344 | {0x11,0x11,0x22,0x22,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
| 1345 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
| 1346 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
| 1347 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}}, |
| 1348 | |
| 1349 | /* Category C PUK Key: 33334444 */ |
| 1350 | {SML_PUK_KEY_DISABLE, 5, 5, |
| 1351 | 0, |
| 1352 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 1353 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, |
| 1354 | {0x00,0x00,0x00,0x00}, |
| 1355 | {0x33,0x33,0x44,0x44,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
| 1356 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
| 1357 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
| 1358 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}}, |
| 1359 | |
| 1360 | /* Category SIM PUK Key: 55556666 */ |
| 1361 | {SML_PUK_KEY_DISABLE, 5, 5, |
| 1362 | 0, |
| 1363 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 1364 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, |
| 1365 | {0x00,0x00,0x00,0x00}, |
| 1366 | {0x55,0x55,0x66,0x66,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
| 1367 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
| 1368 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
| 1369 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}}, |
| 1370 | |
| 1371 | /* Category NS-SP PUK Key: 77778888 */ |
| 1372 | {SML_PUK_KEY_DISABLE, 5, 5, |
| 1373 | 0, |
| 1374 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 1375 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, |
| 1376 | {0x00,0x00,0x00,0x00}, |
| 1377 | {0x77,0x77,0x88,0x88,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
| 1378 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
| 1379 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
| 1380 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}}, |
| 1381 | |
| 1382 | /* Category SIM-C PUK Key: 99990000 */ |
| 1383 | {SML_PUK_KEY_DISABLE, 5, 5, |
| 1384 | 0, |
| 1385 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 1386 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, |
| 1387 | {0x00,0x00,0x00,0x00}, |
| 1388 | {0x99,0x99,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
| 1389 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
| 1390 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
| 1391 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}}}, |
| 1392 | #endif |
| 1393 | |
| 1394 | /* Category N code */ |
| 1395 | {0xc1,0xc1,0xc1, |
| 1396 | 0xFF,0xFF,0xFF, |
| 1397 | 0xFF,0xFF,0xFF, |
| 1398 | 0xFF,0xFF,0xFF, |
| 1399 | 0xFF,0xFF,0xFF, |
| 1400 | 0xFF,0xFF,0xFF, |
| 1401 | 0xFF,0xFF,0xFF, |
| 1402 | 0xFF,0xFF,0xFF, |
| 1403 | 0xFF,0xFF,0xFF, |
| 1404 | 0xFF,0xFF,0xFF}, |
| 1405 | /* Category NS code */ |
| 1406 | {0xc2,0xc2,0xc2,0xc2, |
| 1407 | 0xFF,0xFF,0xFF,0xFF}, |
| 1408 | /* Category SP code */ |
| 1409 | {0xc3,0xc3,0xc3,0xc3, |
| 1410 | 0xFF,0xFF,0xFF,0xFF}, |
| 1411 | /* Category C code */ |
| 1412 | {0xc4,0xc4,0xc4,0xc4,0xc4, |
| 1413 | 0xFF,0xFF,0xFF,0xFF,0xFF}, |
| 1414 | /* Category SIM code */ |
| 1415 | {0xc5,0xc5,0xc5,0xc5,0xc5,0xc5,0xc5,0xc5, |
| 1416 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}, |
| 1417 | /* Category NS-SP */ |
| 1418 | {0xc6,0xc6,0xc6,0xc6,0xc6, |
| 1419 | 0xFF,0xFF,0xFF,0xFF,0xFF}, |
| 1420 | /* Category SIM-C */ |
| 1421 | {0xc7,0xc7,0xc7,0xc7,0xc7,0xc7,0xc7,0xc7,0xc7,0xc7, |
| 1422 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}, |
| 1423 | |
| 1424 | /* NS Range size */ |
| 1425 | {0xFF,0xFF}, |
| 1426 | |
| 1427 | SML_MAGIC_TAIL_VALUE |
| 1428 | }; |
| 1429 | #endif /* not __MTK_INTERNAL_ENG_USER__ */ |
| 1430 | |
rjw | 6c1fd8f | 2022-11-30 14:33:01 +0800 | [diff] [blame] | 1431 | /***************************************************************************** |
| 1432 | * FUNCTION |
| 1433 | * nvram_sml_ota_converter |
| 1434 | * DESCRIPTION |
| 1435 | * After LR12A.R1, SML key length is extended to 16. |
| 1436 | * So we have to convert the SML context manually. |
| 1437 | * PARAMETERS |
| 1438 | * |
| 1439 | * RETURNS |
| 1440 | * void |
| 1441 | *****************************************************************************/ |
| 1442 | void nvram_sml_ota_converter(kal_uint8 *old_value_buffer, kal_uint32 ota_hdr_record_size, kal_uint8 *new_value_buffer, kal_uint32 new_record_size) |
| 1443 | { |
| 1444 | kal_bool is_small_to_big; |
| 1445 | kal_uint8 reset_sml_size; |
| 1446 | |
| 1447 | kal_uint32 record_idx, sml_cat_idx; |
| 1448 | |
| 1449 | |
| 1450 | if (ota_hdr_record_size == new_record_size) |
| 1451 | { |
| 1452 | // Same size, just copy whole structure |
| 1453 | memcpy(new_value_buffer, old_value_buffer, NVRAM_EF_SML_TOTAL * ota_hdr_record_size); |
| 1454 | return; |
| 1455 | } |
| 1456 | |
| 1457 | // R1 -> R2, small sml structure -> big sml structure |
| 1458 | if (ota_hdr_record_size < new_record_size) |
| 1459 | { |
| 1460 | is_small_to_big = KAL_TRUE; |
| 1461 | } |
| 1462 | else // R2 -> R1, big sml structure -> small sml structure |
| 1463 | { |
| 1464 | is_small_to_big = KAL_FALSE; |
| 1465 | } |
| 1466 | |
| 1467 | reset_sml_size = is_small_to_big ? 16 : 8; |
| 1468 | |
| 1469 | for (record_idx = 0; record_idx < NVRAM_EF_SML_TOTAL; record_idx++) |
| 1470 | { |
| 1471 | if (is_small_to_big) |
| 1472 | { |
| 1473 | sml_r1_context_struct *old_sml_ptr = (sml_r1_context_struct*) (old_value_buffer + (record_idx * sizeof(sml_r1_context_struct))); |
| 1474 | sml_context_struct *new_sml_ptr = (sml_context_struct*) (new_value_buffer + (record_idx * sizeof(sml_context_struct))); |
| 1475 | |
| 1476 | // Handle different key length |
| 1477 | for (sml_cat_idx = 0; sml_cat_idx < SML_SUPPORT_CAT_SIZE; sml_cat_idx++) |
| 1478 | { |
| 1479 | new_sml_ptr->key[sml_cat_idx].state = old_sml_ptr->key[sml_cat_idx].state; |
| 1480 | memset(new_sml_ptr->key[sml_cat_idx].key, 0xFF, reset_sml_size); |
| 1481 | memcpy(new_sml_ptr->key[sml_cat_idx].key, old_sml_ptr->key[sml_cat_idx].key, 8); |
| 1482 | } |
| 1483 | |
| 1484 | // Copy the same part |
| 1485 | for (sml_cat_idx = 0; sml_cat_idx < SML_SUPPORT_CAT_SIZE; sml_cat_idx++) |
| 1486 | { |
| 1487 | memcpy(&new_sml_ptr->cat[sml_cat_idx], &old_sml_ptr->cat[sml_cat_idx], sizeof(sml_category_meta_struct)); |
| 1488 | } |
| 1489 | |
| 1490 | new_sml_ptr->magic_head = sizeof(sml_context_struct); |
| 1491 | //memcpy(new_sml_ptr->cat, old_sml_ptr->cat, SML_SUPPORT_CAT_SIZE); |
| 1492 | memcpy(new_sml_ptr->code_cat_n, old_sml_ptr->code_cat_n, SML_CFG_CAT_N_SIZE); |
| 1493 | memcpy(new_sml_ptr->code_cat_ns, old_sml_ptr->code_cat_ns, SML_CFG_CAT_NS_SIZE); |
| 1494 | memcpy(new_sml_ptr->code_cat_sp, old_sml_ptr->code_cat_sp, SML_CFG_CAT_SP_SIZE); |
| 1495 | memcpy(new_sml_ptr->code_cat_c, old_sml_ptr->code_cat_c, SML_CFG_CAT_C_SIZE); |
| 1496 | memcpy(new_sml_ptr->code_cat_sim, old_sml_ptr->code_cat_sim, SML_CFG_CAT_SIM_SIZE); |
| 1497 | memcpy(new_sml_ptr->code_cat_ns_sp, old_sml_ptr->code_cat_ns_sp, SML_CFG_CAT_NS_SP_SIZE); |
| 1498 | memcpy(new_sml_ptr->code_cat_sim_c, old_sml_ptr->code_cat_sim_c, SML_CFG_CAT_SIM_C_SIZE); |
| 1499 | memcpy(new_sml_ptr->range_cat_ns, old_sml_ptr->range_cat_ns, SML_CAT_NS_RANGE_SIZE); |
| 1500 | new_sml_ptr->magic_tail = old_sml_ptr->magic_tail; |
| 1501 | } |
| 1502 | else |
| 1503 | { |
| 1504 | sml_context_struct *old_sml_ptr = (sml_context_struct*) (old_value_buffer + record_idx * sizeof(sml_context_struct)); |
| 1505 | sml_r1_context_struct *new_sml_ptr = (sml_r1_context_struct*) (new_value_buffer + record_idx * sizeof(sml_r1_context_struct)); |
| 1506 | |
| 1507 | // Handle different key length |
| 1508 | for (sml_cat_idx = 0; sml_cat_idx < SML_SUPPORT_CAT_SIZE; sml_cat_idx++) |
| 1509 | { |
| 1510 | new_sml_ptr->key[sml_cat_idx].state = old_sml_ptr->key[sml_cat_idx].state; |
| 1511 | memset(new_sml_ptr->key[sml_cat_idx].key, 0xFF, reset_sml_size); |
| 1512 | memcpy(new_sml_ptr->key[sml_cat_idx].key, old_sml_ptr->key[sml_cat_idx].key, 8); |
| 1513 | } |
| 1514 | |
| 1515 | // Copy the same part |
| 1516 | for (sml_cat_idx = 0; sml_cat_idx < SML_SUPPORT_CAT_SIZE; sml_cat_idx++) |
| 1517 | { |
| 1518 | memcpy(&new_sml_ptr->cat[sml_cat_idx], &old_sml_ptr->cat[sml_cat_idx], sizeof(sml_category_meta_struct)); |
| 1519 | } |
| 1520 | |
| 1521 | new_sml_ptr->magic_head = sizeof(sml_r1_context_struct); |
| 1522 | //memcpy(new_sml_ptr->cat, old_sml_ptr->cat, SML_SUPPORT_CAT_SIZE); |
| 1523 | memcpy(new_sml_ptr->code_cat_n, old_sml_ptr->code_cat_n, SML_CFG_CAT_N_SIZE); |
| 1524 | memcpy(new_sml_ptr->code_cat_ns, old_sml_ptr->code_cat_ns, SML_CFG_CAT_NS_SIZE); |
| 1525 | memcpy(new_sml_ptr->code_cat_sp, old_sml_ptr->code_cat_sp, SML_CFG_CAT_SP_SIZE); |
| 1526 | memcpy(new_sml_ptr->code_cat_c, old_sml_ptr->code_cat_c, SML_CFG_CAT_C_SIZE); |
| 1527 | memcpy(new_sml_ptr->code_cat_sim, old_sml_ptr->code_cat_sim, SML_CFG_CAT_SIM_SIZE); |
| 1528 | memcpy(new_sml_ptr->code_cat_ns_sp, old_sml_ptr->code_cat_ns_sp, SML_CFG_CAT_NS_SP_SIZE); |
| 1529 | memcpy(new_sml_ptr->code_cat_sim_c, old_sml_ptr->code_cat_sim_c, SML_CFG_CAT_SIM_C_SIZE); |
| 1530 | memcpy(new_sml_ptr->range_cat_ns, old_sml_ptr->range_cat_ns, SML_CAT_NS_RANGE_SIZE); |
| 1531 | new_sml_ptr->magic_tail = old_sml_ptr->magic_tail; |
| 1532 | |
| 1533 | } |
| 1534 | |
| 1535 | } |
| 1536 | |
| 1537 | } |
| 1538 | |
| 1539 | |
| 1540 | #if defined(__NVRAM_CRITICAL_DATA_SIGN_SUPPORT__) && !defined(NVRAM_AUTO_GEN) |
| 1541 | #include "nvram_interface.h" |
| 1542 | #include "cust_chl_interface.h" |
| 1543 | #include "custom_sec_key.h" |
| 1544 | #include "psw_nvram.h" // For MEID Structure |
| 1545 | #include "c2k_nvram_def.h" // For NVRAM_EF_C2K_MOBILE_ID_LID |
| 1546 | #include "customer_nvram_def.h" |
| 1547 | #include "kal_trace.h" |
| 1548 | #include "ccci_rpc_if.h" |
| 1549 | |
| 1550 | #define EXPONENT_DAT "\x01\x00\x01" |
| 1551 | #define EXPONENT_LEN 3 |
| 1552 | //#define DBG_FIXED_CPUID_AND_PRODUCT |
| 1553 | |
| 1554 | typedef enum { |
| 1555 | OEM_DATA_TAG_CPUID = 1, |
| 1556 | OEM_DATA_TAG_IMEI1 = 2, |
| 1557 | OEM_DATA_TAG_IMEI2 = 3, |
| 1558 | OEM_DATA_TAG_MEID = 4, |
| 1559 | OEM_DATA_WIFI_MAC = 5, |
| 1560 | OEM_DATA_BT_MAC = 6, |
| 1561 | } nvram_oem_data_tag_enum; |
| 1562 | |
| 1563 | static kal_uint8 val_of_hex(kal_char ch) |
| 1564 | { |
| 1565 | if (ch >= '0' && ch <= '9') { |
| 1566 | return ch - '0'; |
| 1567 | } |
| 1568 | |
| 1569 | if (ch >= 'A' && ch <= 'F') { |
| 1570 | ch |= (0x1<<5); // to lower-case |
| 1571 | } |
| 1572 | |
| 1573 | EXT_ASSERT(ch >= 'a' && ch <= 'f', ch, 0, 0); |
| 1574 | |
| 1575 | return ch - 'a' + 10; |
| 1576 | } |
| 1577 | |
| 1578 | static void str_to_mem(kal_char *str, kal_uint8 *mem, kal_uint32 str_len) |
| 1579 | { |
| 1580 | while (str_len > 0) { |
| 1581 | kal_uint8 ch; |
| 1582 | |
| 1583 | ch = (val_of_hex(*str++)<<4); |
| 1584 | ch |= val_of_hex(*str++); |
| 1585 | |
| 1586 | *mem++ = ch; |
| 1587 | |
| 1588 | str_len -= 2; |
| 1589 | } |
| 1590 | } |
| 1591 | |
| 1592 | |
| 1593 | static kal_bool custom_nvram_check_cpuid(kal_uint8 *val, kal_uint8 len) |
| 1594 | { |
| 1595 | kal_uint32 cpuid[4] = {0}; |
| 1596 | kal_uint32 ret; |
| 1597 | kal_uint32 idx; |
| 1598 | kal_uint32 temp; |
| 1599 | |
| 1600 | // Step 1. Read Current CPUID |
| 1601 | ret = SST_Get_HRID(cpuid, sizeof(cpuid)); |
| 1602 | EXT_ASSERT(ret>0, ret, 0, 0); |
| 1603 | |
| 1604 | val += 2; // skip "0x" |
| 1605 | len -= 2; |
| 1606 | |
| 1607 | str_to_mem((kal_char *)val, val, len); |
| 1608 | len /= 2; |
| 1609 | |
| 1610 | // Step 2. Compare |
| 1611 | for (idx = 0; idx < len/4; idx++) { |
| 1612 | temp = *val++; |
| 1613 | temp = (temp<<8)|(*val++); |
| 1614 | temp = (temp<<8)|(*val++); |
| 1615 | temp = (temp<<8)|(*val++); |
| 1616 | |
| 1617 | if (temp != cpuid[idx]) { |
| 1618 | kal_prompt_trace(MOD_NVRAM, "custom_nvram_check_cpuid not identical %x != %x", temp, cpuid[idx]); |
| 1619 | return KAL_FALSE; |
| 1620 | } |
| 1621 | } |
| 1622 | |
| 1623 | return KAL_TRUE; |
| 1624 | } |
| 1625 | |
| 1626 | |
| 1627 | static kal_bool custom_nvram_check_imei(kal_uint32 imei_idx, kal_uint8 *val, kal_uint8 len, kal_bool chk_rd) |
| 1628 | { |
| 1629 | kal_uint8 stored_imei[NVRAM_EF_IMEI_IMEISV_SIZE] = {0}; |
| 1630 | kal_uint8 signed_imei[NVRAM_EF_IMEI_IMEISV_SIZE] = {0}; |
| 1631 | kal_uint8 idx; |
| 1632 | |
| 1633 | if (chk_rd == KAL_FALSE) { |
| 1634 | return KAL_TRUE; // don't check IMEI before for write, only check CPUID |
| 1635 | } |
| 1636 | |
| 1637 | // Step 1. Get MTK Format IMEI from val string |
| 1638 | // For IMEI: 86233702135540 2 ((15 decimal digits)) |
| 1639 | // MTK Format: 0x68 32 73 20 31 55 04 f2 (8 bytes hex digits) |
| 1640 | // API input String Format: "862337021355402" (15 ascii code string) |
| 1641 | EXT_ASSERT(len==15, len, 0, 0); |
| 1642 | |
| 1643 | for (idx = 0; idx < 8; idx ++) { |
| 1644 | signed_imei[idx] = val_of_hex(*val++); // low 4bit first |
| 1645 | if (idx != 7) { |
| 1646 | signed_imei[idx] |= (val_of_hex(*val++)<<4); // High 4bit next |
| 1647 | } |
| 1648 | } |
| 1649 | |
| 1650 | signed_imei[7] |= 0xF0; |
| 1651 | signed_imei[8] = 0; |
| 1652 | signed_imei[9] = 0; |
| 1653 | |
| 1654 | // Step 2. Read Stored IMEI |
| 1655 | nvram_external_read_data(NVRAM_EF_IMEI_IMEISV_LID, imei_idx, stored_imei, sizeof(stored_imei)); |
| 1656 | |
| 1657 | // Step 3. Compare |
| 1658 | if (memcmp(stored_imei, signed_imei, 8) != 0) { |
| 1659 | kal_prompt_trace(MOD_NVRAM, "custom_nvram_check_imei%d not identical", imei_idx); |
| 1660 | if (chk_rd) { |
| 1661 | // Write signed IMEI to replace stored IMEI, only check CPUID |
| 1662 | if (!nvram_secure_write_imei(sizeof(signed_imei), signed_imei, imei_idx, NULL)) { |
| 1663 | kal_prompt_trace(MOD_NVRAM, "custom_nvram_check_imei%d re-write imei fail", imei_idx); |
| 1664 | return KAL_FALSE; |
| 1665 | } else { |
| 1666 | kal_prompt_trace(MOD_NVRAM, "custom_nvram_check_imei%d re-write with signed data", imei_idx); |
| 1667 | return KAL_TRUE; |
| 1668 | } |
| 1669 | } else { |
| 1670 | return KAL_FALSE; |
| 1671 | } |
| 1672 | } |
| 1673 | |
| 1674 | return KAL_TRUE; |
| 1675 | } |
| 1676 | |
| 1677 | |
| 1678 | static kal_bool custom_nvram_check_meid(kal_uint8 *val, kal_uint8 len, kal_bool chk_rd) |
| 1679 | { |
| 1680 | PswMobileIDT stored_meid = {0,0}; |
| 1681 | PswMobileIDT signed_meid = {2,0}; |
| 1682 | kal_uint8 idx; |
| 1683 | |
| 1684 | if (chk_rd == KAL_FALSE) { |
| 1685 | return KAL_TRUE; // don't check MEID before for write |
| 1686 | } |
| 1687 | |
| 1688 | // Step 1. Get MTK Format MEID from val string |
| 1689 | // For MEID: A000007D8E567C ((14 decimal digits)) |
| 1690 | // MTK Format: 0xF2A000007D8E567C (64bit long) |
| 1691 | // Input String Format: "A000007D8E567C" (14 ascii code string) |
| 1692 | EXT_ASSERT(len==14, len, 0, 0); |
| 1693 | |
| 1694 | for (idx = 0; idx < 14; idx ++) { |
| 1695 | signed_meid.value <<= 4; |
| 1696 | signed_meid.value |= val_of_hex(*val++); |
| 1697 | } |
| 1698 | signed_meid.value |= ((kal_uint64)0xF2<<56); |
| 1699 | |
| 1700 | // Step 2. Read Stored MEID |
| 1701 | nvram_external_read_data(NVRAM_EF_C2K_MOBILE_ID_LID, 1, (kal_uint8 *)&stored_meid, sizeof(stored_meid)); |
| 1702 | |
| 1703 | // Step 3. Compare |
| 1704 | if (memcmp(&stored_meid, &signed_meid, sizeof(stored_meid)) != 0) { |
| 1705 | kal_prompt_trace(MOD_NVRAM, "custom_nvram_check_meid not identical"); |
| 1706 | if (chk_rd) { |
| 1707 | // Write signed IMEI to replace stored IMEI |
| 1708 | if (!nvram_external_write_data(NVRAM_EF_C2K_MOBILE_ID_LID, 1, (kal_uint8 *)&signed_meid, sizeof(signed_meid))) { |
| 1709 | kal_prompt_trace(MOD_NVRAM, "custom_nvram_check_meid re-write meid fail"); |
| 1710 | return KAL_FALSE; |
| 1711 | } else { |
| 1712 | kal_prompt_trace(MOD_NVRAM, "custom_nvram_check_meid re-write with signed data"); |
| 1713 | return KAL_TRUE; |
| 1714 | } |
| 1715 | } else { |
| 1716 | return KAL_FALSE; |
| 1717 | } |
| 1718 | } |
| 1719 | |
| 1720 | return KAL_TRUE; |
| 1721 | } |
| 1722 | |
| 1723 | |
| 1724 | static kal_bool custom_nvram_check_critical_item(kal_uint8 tag, kal_uint8 len, kal_uint8 *val, kal_bool chk_rd) |
| 1725 | { |
| 1726 | kal_bool ret = KAL_TRUE; |
| 1727 | switch(tag) { |
| 1728 | case OEM_DATA_TAG_CPUID: |
| 1729 | ret = custom_nvram_check_cpuid(val, len); |
| 1730 | break; |
| 1731 | case OEM_DATA_TAG_IMEI1: |
| 1732 | ret = custom_nvram_check_imei(1, val, len, chk_rd); |
| 1733 | break; |
| 1734 | case OEM_DATA_TAG_IMEI2: |
| 1735 | ret = custom_nvram_check_imei(2, val, len, chk_rd); |
| 1736 | break; |
| 1737 | case OEM_DATA_TAG_MEID: |
| 1738 | ret = custom_nvram_check_meid(val, len, chk_rd); |
| 1739 | break; |
| 1740 | default: |
| 1741 | break; |
| 1742 | } |
| 1743 | |
| 1744 | return ret; |
| 1745 | } |
| 1746 | |
| 1747 | |
| 1748 | static kal_bool custom_nvram_check_critical_data(void *raw_data, kal_uint32 raw_len, kal_bool chk_rd) |
| 1749 | { |
| 1750 | kal_uint8 *ptr = (kal_uint8 *)raw_data; |
| 1751 | kal_uint8 *data_end; |
| 1752 | kal_int16 data_len = 0; // crital data length |
| 1753 | nvram_oem_data_tag_enum tag; |
| 1754 | kal_uint8 len, *val; |
| 1755 | |
| 1756 | // skip ver, 2 bytes |
| 1757 | ptr += 2; |
| 1758 | |
| 1759 | // get length |
| 1760 | data_len = (*ptr++)<<8; // high byte |
| 1761 | data_len |= (*ptr++); // low byte |
| 1762 | |
| 1763 | if (data_len > raw_len-4) { |
| 1764 | return KAL_FALSE; |
| 1765 | } |
| 1766 | |
| 1767 | data_end = ptr + data_len; |
| 1768 | |
| 1769 | while (ptr < data_end) { |
| 1770 | tag = *ptr++; |
| 1771 | len = *ptr++; |
| 1772 | |
| 1773 | val = ptr; |
| 1774 | |
| 1775 | if (custom_nvram_check_critical_item(tag, len, val, chk_rd) == KAL_FALSE) { |
| 1776 | // check fail |
| 1777 | kal_prompt_trace(MOD_NVRAM, "custom_nvram_check_critical_data tag:%d len%d check fail", tag, len); |
| 1778 | return KAL_FALSE; |
| 1779 | } |
| 1780 | |
| 1781 | ptr += len; |
| 1782 | } |
| 1783 | |
| 1784 | return KAL_TRUE; |
| 1785 | } |
| 1786 | |
| 1787 | |
| 1788 | static kal_uint32 custom_nvram_check_sign(t_cust_chl_asym_key *key, void *data, kal_uint32 data_len, void *sign, kal_uint32 sign_len) |
| 1789 | { |
| 1790 | kal_uint32 ret_val; |
| 1791 | |
| 1792 | ret_val = CustCHL_Verify_RSA_Signature(CUST_CHL_ALG_RSA_PKCS1_V15_SHA256, |
| 1793 | data, |
| 1794 | data_len, |
| 1795 | sign, |
| 1796 | sign_len, |
| 1797 | key |
| 1798 | ); |
| 1799 | |
| 1800 | return ret_val; |
| 1801 | } |
| 1802 | |
| 1803 | |
| 1804 | static kal_int32 custom_nvram_get_product_name(kal_char *buff, kal_uint32 len) |
| 1805 | { |
| 1806 | kal_int32 ret = 0; |
| 1807 | kal_char prop_name[] = "ro.product.name"; |
| 1808 | |
| 1809 | memset(buff, 0, len); |
| 1810 | |
| 1811 | ret = IPC_RPC_General_Query(IPC_RPC_QUERY_AP_SYS_PROPERTY, prop_name, sizeof(prop_name), buff, len); |
| 1812 | |
| 1813 | if (ret <= 0) { |
| 1814 | kal_prompt_trace(MOD_NVRAM, "custom_nvram_get_product got error:%d", ret); |
| 1815 | } |
| 1816 | |
| 1817 | EXT_ASSERT(ret>0, ret, 0, 0); |
| 1818 | |
| 1819 | buff[ret]='\0'; |
| 1820 | |
| 1821 | #if defined(DBG_FIXED_CPUID_AND_PRODUCT) |
| 1822 | kal_prompt_trace(MOD_NVRAM, "custom_nvram_get_product get %s", buff); |
| 1823 | strcpy(buff, "cactus"); |
| 1824 | #endif |
| 1825 | |
| 1826 | return ret; |
| 1827 | } |
| 1828 | |
| 1829 | |
| 1830 | static nvram_errno_enum custom_nvram_check_signed_critical_data(kal_uint8 *all_data, kal_uint32 all_data_len, kal_bool chk_rd) |
| 1831 | { |
| 1832 | kal_char *key = NULL; /* 1024-bits 128-bytes 256-hexs */ |
| 1833 | kal_uint32 key_len = 0; |
| 1834 | kal_char *data = NULL; |
| 1835 | kal_uint32 data_len = 0; |
| 1836 | kal_char *sign = NULL; |
| 1837 | kal_uint32 sign_len = 0; |
| 1838 | kal_char *end = NULL; |
| 1839 | kal_uint32 chk_ret = 0; |
| 1840 | t_cust_chl_asym_key *asym_key = NULL; |
| 1841 | kal_uint8 *raw_data = NULL; |
| 1842 | kal_uint8 *raw_sign = NULL; |
| 1843 | kal_uint8 *tmp_buff = NULL; |
| 1844 | nvram_errno_enum final_ret = NVRAM_ERRNO_SUCCESS; |
| 1845 | kal_char product[32] = {0}; |
| 1846 | |
| 1847 | // protect_data: IMEI1+IMEI2+MEID+CPUID+Model |
| 1848 | // NV content: protect_data + signed(protect_data) + Device Type RSA Pub Key + signed(Device Type RSA Pub Key) |
| 1849 | asym_key = get_ctrl_buffer(sizeof(t_cust_chl_asym_key)); |
| 1850 | raw_data = get_ctrl_buffer(NVRAM_EF_CUSTOMER_SIGNED_CRITICAL_DATA_SIZE/2); |
| 1851 | raw_sign = get_ctrl_buffer(NVRAM_EF_CUSTOMER_SIGNED_CRITICAL_DATA_SIZE/2); |
| 1852 | ASSERT(asym_key != NULL); |
| 1853 | ASSERT(raw_data != NULL); |
| 1854 | ASSERT(raw_sign != NULL); |
| 1855 | |
| 1856 | memset(asym_key, 0, sizeof(t_cust_chl_asym_key)); |
| 1857 | |
| 1858 | // Step 1. Check signed(Device Type RSA Pub Key) with ROOT Type RSA Pub Key to get Device Type RSA Pub Key |
| 1859 | ASSERT(cust_sec_get_asym_key(1, asym_key) == 0); // key index is 1 |
| 1860 | |
| 1861 | data = strstr((kal_char *)all_data, "devPubKeyModulus:"); |
| 1862 | if (data == NULL) { |
| 1863 | kal_prompt_trace(MOD_NVRAM, "custom_nvram_check_signed_critical_data devPubKeyModulus not found"); |
| 1864 | final_ret = NVRAM_ERRNO_SIG_CHK_FAIL; |
| 1865 | goto end; |
| 1866 | } |
| 1867 | data += strlen("devPubKeyModulus:"); |
| 1868 | end = strstr(data, "\\n"); |
| 1869 | data_len = end-data; |
| 1870 | |
| 1871 | sign = strstr((kal_char *)all_data, "devPubKeySign:"); |
| 1872 | if (sign == NULL) { |
| 1873 | kal_prompt_trace(MOD_NVRAM, "custom_nvram_check_signed_critical_data devPubKeySign not found"); |
| 1874 | final_ret = NVRAM_ERRNO_SIG_CHK_FAIL; |
| 1875 | goto end; |
| 1876 | } |
| 1877 | sign += strlen("devPubKeySign:"); |
| 1878 | end = strstr(sign, "\\n"); |
| 1879 | sign_len = end-sign; |
| 1880 | |
| 1881 | str_to_mem(sign, raw_sign, sign_len); |
| 1882 | |
| 1883 | // signature = rsa_encrypt(root_priv_key, sha256(exponent+modulus+product)) |
| 1884 | custom_nvram_get_product_name(product, sizeof(product)); |
| 1885 | tmp_buff = get_ctrl_buffer(NVRAM_EF_CUSTOMER_SIGNED_CRITICAL_DATA_SIZE/2); |
| 1886 | |
| 1887 | memcpy(tmp_buff, "10001", 5); // fixed 5 bytes exponent |
| 1888 | memcpy(tmp_buff+5, data, data_len); |
| 1889 | memcpy(tmp_buff+5+data_len, product, strlen(product)); |
| 1890 | chk_ret = custom_nvram_check_sign(asym_key, tmp_buff, 5+data_len+strlen(product), raw_sign, sign_len/2); |
| 1891 | |
| 1892 | free_ctrl_buffer(tmp_buff); |
| 1893 | if (chk_ret != 0) { |
| 1894 | kal_prompt_trace(MOD_NVRAM, "custom_nvram_check_signed_critical_data dev_pub_key verify fail %d", chk_ret); |
| 1895 | final_ret = NVRAM_ERRNO_SIG_CHK_FAIL; |
| 1896 | goto end; |
| 1897 | } |
| 1898 | |
| 1899 | // Step 2. Check signed(protect_data) with Device Type RSA Pub Key to get protect_data |
| 1900 | key = data; |
| 1901 | key_len = data_len; |
| 1902 | |
| 1903 | data = strstr((kal_char *)all_data, "criticalData:"); |
| 1904 | if (data == NULL) { |
| 1905 | kal_prompt_trace(MOD_NVRAM, "custom_nvram_check_signed_critical_data criticalData not found"); |
| 1906 | final_ret = NVRAM_ERRNO_SIG_CHK_FAIL; |
| 1907 | goto end; |
| 1908 | } |
| 1909 | data += strlen("criticalData:"); |
| 1910 | end = strstr(data, "\\n"); |
| 1911 | data_len = end-data; |
| 1912 | |
| 1913 | sign = strstr((kal_char *)all_data, "crticalDataSign:"); |
| 1914 | if (sign == NULL) { |
| 1915 | kal_prompt_trace(MOD_NVRAM, "custom_nvram_check_signed_critical_data criticalDataSign not found"); |
| 1916 | final_ret = NVRAM_ERRNO_SIG_CHK_FAIL; |
| 1917 | goto end; |
| 1918 | } |
| 1919 | sign += strlen("crticalDataSign:"); |
| 1920 | //end = strstr(data, "\\n"); |
| 1921 | //data_len = end-data; |
| 1922 | sign_len = key_len; |
| 1923 | |
| 1924 | memset(asym_key, 0, sizeof(t_cust_chl_asym_key)); |
| 1925 | memcpy(asym_key->m_E_key, EXPONENT_DAT, EXPONENT_LEN); // Exponent is fixed to 10001 |
| 1926 | asym_key->m_E_len = EXPONENT_LEN; |
| 1927 | str_to_mem(key, asym_key->m_N_key, key_len); |
| 1928 | asym_key->m_N_len = key_len/2; |
| 1929 | str_to_mem(data, raw_data, data_len); |
| 1930 | str_to_mem(sign, raw_sign, sign_len); |
| 1931 | |
| 1932 | // signature = rsa_encrypt(dev_priv_key, sha256(nv_data)) |
| 1933 | chk_ret = custom_nvram_check_sign(asym_key, data, data_len, raw_sign, sign_len/2); |
| 1934 | |
| 1935 | if (chk_ret != 0) { |
| 1936 | kal_prompt_trace(MOD_NVRAM, "custom_nvram_check_signed_critical_data ciritical_data verify fail %d", chk_ret); |
| 1937 | final_ret = NVRAM_ERRNO_SIG_CHK_FAIL; |
| 1938 | goto end; |
| 1939 | } |
| 1940 | |
| 1941 | // Step 3. Check protect_data |
| 1942 | if (custom_nvram_check_critical_data(raw_data, data_len/2, chk_rd) == KAL_FALSE) { |
| 1943 | final_ret = NVRAM_ERRNO_SIG_CHK_FAIL; |
| 1944 | goto end; |
| 1945 | } |
| 1946 | |
| 1947 | end: |
| 1948 | free_ctrl_buffer(asym_key); |
| 1949 | free_ctrl_buffer(raw_data); |
| 1950 | free_ctrl_buffer(raw_sign); |
| 1951 | |
| 1952 | kal_prompt_trace(MOD_NVRAM, "custom_nvram_check_signed_critical_data return %d", final_ret); |
| 1953 | |
| 1954 | return final_ret; |
| 1955 | } |
| 1956 | |
| 1957 | |
| 1958 | nvram_lid_enum custom_nvram_get_signed_critical_data_lid() |
| 1959 | { |
| 1960 | return NVRAM_EF_CUSTOMER_SIGNED_CRITICAL_DATA_LID; |
| 1961 | } |
| 1962 | |
| 1963 | |
| 1964 | kal_bool custom_nvram_check_signed_critical_data_before_write(kal_uint8 *wr_dat, kal_uint32 len) |
| 1965 | { |
| 1966 | if (custom_nvram_check_signed_critical_data(wr_dat, len, KAL_FALSE) != 0) { |
| 1967 | return KAL_FALSE; |
| 1968 | } else { |
| 1969 | return KAL_TRUE; |
| 1970 | } |
| 1971 | } |
| 1972 | |
| 1973 | |
| 1974 | kal_bool custom_nvram_read_and_check_signed_critical_data() |
| 1975 | { |
| 1976 | kal_bool ret_val; |
| 1977 | kal_int32 idx = 0, chk_val = 0; |
| 1978 | kal_uint8 *data_buff = get_ctrl_buffer(NVRAM_EF_CUSTOMER_SIGNED_CRITICAL_DATA_SIZE); |
| 1979 | |
| 1980 | ASSERT(data_buff != NULL); |
| 1981 | |
| 1982 | // Only check when IMEI is not empty |
| 1983 | ret_val = nvram_external_read_data(NVRAM_EF_IMEI_IMEISV_LID, 1, data_buff, NVRAM_EF_IMEI_IMEISV_SIZE); |
| 1984 | if (ret_val != KAL_TRUE) { |
| 1985 | free_ctrl_buffer(data_buff); |
| 1986 | kal_prompt_trace(MOD_NVRAM, "custom_nvram_read_and_check_signed_critical_data read imei fail"); |
| 1987 | return KAL_FALSE; |
| 1988 | } |
| 1989 | |
| 1990 | // check if default value, default value is all FF |
| 1991 | chk_val = 0xFF; |
| 1992 | for (idx = 0; idx < NVRAM_EF_IMEI_IMEISV_SIZE; idx++) { |
| 1993 | chk_val &= data_buff[idx]; |
| 1994 | } |
| 1995 | |
| 1996 | if (chk_val == 0xFF) { |
| 1997 | free_ctrl_buffer(data_buff); |
| 1998 | kal_prompt_trace(MOD_NVRAM, "custom_nvram_read_and_check_signed_critical_data imei is default value, bypass check"); |
| 1999 | return KAL_TRUE; |
| 2000 | } |
| 2001 | |
| 2002 | // Read critical data from nvram |
| 2003 | ret_val = nvram_external_read_data(NVRAM_EF_CUSTOMER_SIGNED_CRITICAL_DATA_LID, 1, data_buff, NVRAM_EF_CUSTOMER_SIGNED_CRITICAL_DATA_SIZE); |
| 2004 | if (ret_val != KAL_TRUE) { |
| 2005 | free_ctrl_buffer(data_buff); |
| 2006 | kal_prompt_trace(MOD_NVRAM, "custom_nvram_read_and_check_signed_critical_data read critical data fail"); |
| 2007 | return KAL_FALSE; |
| 2008 | } |
| 2009 | |
| 2010 | // check if default value, default value is all zeros |
| 2011 | chk_val = 0; |
| 2012 | for (idx = 0; idx < NVRAM_EF_CUSTOMER_SIGNED_CRITICAL_DATA_SIZE; idx++) { |
| 2013 | chk_val |= data_buff[idx]; |
| 2014 | } |
| 2015 | |
| 2016 | if (chk_val == 0) { |
| 2017 | free_ctrl_buffer(data_buff); |
| 2018 | kal_prompt_trace(MOD_NVRAM, "custom_nvram_read_and_check_signed_critical_data sign data is default value, check fail"); |
| 2019 | return KAL_FALSE; |
| 2020 | } |
| 2021 | |
| 2022 | // check validation of critical data |
| 2023 | if (custom_nvram_check_signed_critical_data(data_buff, NVRAM_EF_CUSTOMER_SIGNED_CRITICAL_DATA_SIZE, KAL_TRUE) != 0) { |
| 2024 | ret_val = KAL_FALSE; |
| 2025 | } else { |
| 2026 | ret_val = KAL_TRUE; |
| 2027 | } |
| 2028 | free_ctrl_buffer(data_buff); |
| 2029 | |
| 2030 | return ret_val; |
| 2031 | } |
| 2032 | |
| 2033 | #endif |
| 2034 | |
| 2035 | #endif /* !defined(NVRAM_NOT_PRESENT) */ |