blob: c196479d693f17fd527eed7eb61a0a674e6bec5e [file] [log] [blame]
/*****************************************************************************
*
* Filename:
* ---------
* custom_sml.h
*
* Project:
* --------
* UMOLYA
*
* Description:
* ------------
* This is the file for SIM ME Lock customization
*
* Author:
* -------
* -------
****************************************************************************/
#ifndef CUSTOM_SML_H
#define CUSTOM_SML_H
#include "kal_general_types.h"
#include "ps_public_enum.h"
#include "sim_ps_enum.h"
#include "mcd_l3_inc_struct.h"
#include "l4_nvram_def.h"
#include "cust_chl_interface.h"
/****************************************************************************
*
* SIM ME Lock
*
****************************************************************************/
#define SML_IMEI_PRINT_LEN 5 // print partial UE IMEI for privacy
extern void sml_mini_trace(const kal_char *title, kal_uint8 *data, kal_uint8 len);
extern sml_key_input_type_enum custom_sml_query_key_input_type(sml_key_algo_enum algo, sml_op_enum op);
#ifdef __SML_PUK__
extern sml_key_input_type_enum custom_sml_query_puk_key_input_type(sml_key_algo_enum algo, sml_puk_key_op_enum op);
#endif
/****************************************************************************
*
* Verizon SIM Lock
*
****************************************************************************/
#define SML_VZW_RSU_TIME_STAMP_LEN 8
#define SML_VZW_RSU_NW_CODE_LEN 6 /* 123-456 */
#define SML_VZW_RSU_NW_LIST_LEN (SML_VZW_RSU_NW_CODE_LEN * 5) /* 5 sets */
#define SML_VZW_RSU_NS_CODE_LEN 8 /* 123-456-78 */
#define SML_VZW_RSU_NS_LIST_LEN (SML_VZW_RSU_NS_CODE_LEN * 5)
#define SML_VZW_RSU_SP_CODE_LEN (7+NUM_GID1) /* 123-456-8-00000000000000000000 */
#define SML_VZW_RSU_SP_LIST_LEN (SML_VZW_RSU_SP_CODE_LEN * 4)
#define SML_VZW_RSU_EHPLMN_CODE_LEN (13+NUM_GID1) /* 123-456-8-00000000000000000000-123-456 */
#define SML_VZW_RSU_EHPLMN_LIST_LEN (SML_VZW_RSU_EHPLMN_CODE_LEN * 5)
#define SML_VZW_RSU_SESSION_ID_LEN 8
#define SML_VZW_RSU_SIZE_OF_MCC_MNC 6
#define SML_VZW_RSU_SIZE_OF_GID 9
#define SML_VZW_RSU_SIZE_OF_EHPLMN 6
#define SML_VZW_RSU_MAX_SUPPORT_MAJOR_VER 1
#define SML_VZW_RSU_MAX_SUPPORT_MINOR_VER 0
typedef struct {
kal_uint8 major_version;
kal_uint8 minor_version;
kal_uint8 protection_algo;
kal_uint8 nw_lock_op;
kal_uint8 timestamp[SML_VZW_RSU_TIME_STAMP_LEN];
kal_uint8 nw_num;
kal_uint8 nw_list[SML_VZW_RSU_NW_LIST_LEN];
kal_uint8 ns_num;
kal_uint8 ns_list[SML_VZW_RSU_NS_LIST_LEN];
kal_uint8 sp_num;
kal_uint8 sp_list[SML_VZW_RSU_SP_LIST_LEN];
kal_uint8 ehplmn_num;
kal_uint8 ehplmn_list[SML_VZW_RSU_EHPLMN_LIST_LEN];
kal_uint8 session_id[SML_VZW_RSU_SESSION_ID_LEN];
} sml_vzw_sim_lock_context_struct;
typedef sml_vzw_sim_lock_context_struct nvram_sml_vzw_sim_lock_context_struct;
typedef struct {
kal_uint8 device_key[32]; //a unique 32-byte Device Key, which is used to calculate HMAC of a Network Lock Request message
} sml_vzw_sim_lock_device_key_struct;
typedef sml_vzw_sim_lock_device_key_struct nvram_sml_vzw_sim_lock_device_key_struct;
typedef struct {
kal_uint16 delay_timer; //ranging from 0-10 minutes, default is 2 minutes
} sml_vzw_rsu_delay_timer_struct;
typedef sml_vzw_rsu_delay_timer_struct nvram_sml_vzw_rsu_delay_timer_struct;
typedef enum {
SML_VZW_RSU_MSG_TYPE_INVALID = 0,
SML_VZW_RSU_MSG_TYPE_REQUEST = 1,
SML_VZW_RSU_MSG_TYPE_STATUS = 2,
} sml_vzw_rsu_msg_type_enum;
typedef enum {
SML_VZW_LOCK_STATE_LOCK = 0,
SML_VZW_LOCK_STATE_UNLOCK = 1,
SML_VZW_LOCK_STATE_TEMP_UNLOCK = 2,
} sml_vzw_lock_state_enum;
typedef enum {
SML_VZW_CAT_NONE,
SML_VZW_CAT_N,
SML_VZW_CAT_NS,
SML_VZW_CAT_SP,
SML_VZW_CAT_EHPLMN,
SML_VZW_CAT_SIZE
} sml_vzw_cat_enum;
typedef enum {
SML_VZW_RSU_STATUS_SUCCESS = 0,
SML_VZW_RSU_STATUS_GENERIC_ERROR = 1,
SML_VZW_RSU_STATUS_BLOB_TOO_SHORT = 2,
SML_VZW_RSU_STATUS_SIGNATURE_FAILED = 3,
SML_VZW_RSU_STATUS_RESERVE = 4,
SML_VZW_RSU_STATUS_IMEI_FAILED = 5,
SML_VZW_RSU_STATUS_BLOB_FRESHNESS_CHECK_FAILED = 6,
} sml_vzw_rsu_status_enum;
typedef struct {
void * pObj;
void (* give)(void * /* pLidToObj */, kal_uint8);
void (* take)(void * /* pObjToLid */, kal_uint8);
void (* destory)(kal_uint8);
void * (* getItem)(sml_vzw_cat_enum,sml_ctx_enum,kal_uint16 * /* length */, kal_uint8);
void (* putItem)(sml_vzw_cat_enum,sml_ctx_enum,void * /* pItem */, kal_uint16 * /* plen */, kal_uint8);
} nvram_ef_sml_vzw_sim_lock_obj_struct;
extern void sml_clean_vzw_cntxt(void);
extern kal_bool custom_sml_vzw_is_test_purpose(void);
extern kal_uint16 sml_vzw_Load( void *pLid, kal_uint8 source );
extern kal_uint16 sml_vzw_Save( void *pLid, kal_uint8 source );
extern kal_bool sml_vzw_Check( sml_vzw_cat_enum cat,
kal_uint8 *imsi,
kal_uint8 *gid1,
kal_uint16 ehplmn_num,
kal_uint8 *ehplmn,
kal_uint8 sim_mnc_len,
kal_uint8 source);
extern kal_uint8 sml_vzw_get_major_version(kal_uint8 source);
extern kal_uint8 sml_vzw_get_minor_version(kal_uint8 source);
extern kal_uint8 sml_vzw_get_max_support_major_version();
extern kal_uint8 sml_vzw_get_max_support_minor_version();
extern kal_bool sml_vzw_update_int_data(kal_uint8 source, sml_vzw_cat_enum cat, sml_ctx_enum type, kal_uint8 data);
extern kal_bool sml_vzw_get_int_data(kal_uint8 source, sml_vzw_cat_enum cat, sml_ctx_enum type, kal_uint8* pData);
extern kal_bool sml_vzw_update_array_data(kal_uint8 source, sml_vzw_cat_enum cat, sml_ctx_enum type, kal_uint8* data, kal_uint16 data_len);
extern kal_bool sml_vzw_get_array_data(kal_uint8 source, sml_vzw_cat_enum cat, sml_ctx_enum type, kal_uint8* data, kal_uint16* data_len);
extern kal_bool sml_vzw_reset_rsu_data(kal_uint8 source);
extern void sml_vzw_give( void * pLidToObj, kal_uint8 source );
extern void sml_vzw_take( void * pObjToLid, kal_uint8 source );
extern void sml_vzw_destory( kal_uint8 source );
extern void *sml_vzw_getItem(sml_vzw_cat_enum cat,
sml_ctx_enum item,
kal_uint16 * plength,
kal_uint8 source);
extern void sml_vzw_putItem( sml_vzw_cat_enum cat,
sml_ctx_enum item,
void * pItem,
kal_uint16 * plength,
kal_uint8 source);
extern nvram_ef_sml_vzw_sim_lock_obj_struct *pSMLVZWg;
extern void custom_vzw_rsu_get_pub_key_handle(kal_uint8 index,
TYPE_CUST_CHL_KEY *key);
/****************************************************************************
*
* TMO SIM Lock with Movial Solution
*
****************************************************************************/
#define SML_TMO_MOVIAL_BLOB_IMEI_SIZE 15
#define SML_TMO_MOVIAL_BLOB_TIME_STAMP_SIZE 8
#define SML_TMO_MOVIAL_SIZE_OF_START_TIME 8
#define SML_TMO_MOVIAL_SIZE_OF_UNLOCK_DURATION 4
#define SML_TMO_MOVIAL_BLOB_LENGTH_SIZE 2
#define SML_TMO_MOVIAL_BLOB_CONFIG_SUPPORT_CAT_SIZE 3
/* Length of each CAT Codes */
#define SML_TMO_MOVIAL_BLOB_SIZE_OF_CAT_N 6 /* MCC/MNC */
#define SML_TMO_MOVIAL_BLOB_SIZE_OF_CAT_NS 8 /* MCC/MNC + HLR */
#define SML_TMO_MOVIAL_BLOB_SIZE_OF_CAT_SP 7 /* MCC/MNC + GID1 */
/* Define the maximum suppot categories */
#define SML_TMO_MOVIAL_BLOB_MAX_SUPPORT_CAT_N 15
#define SML_TMO_MOVIAL_BLOB_MAX_SUPPORT_CAT_NS 10
#define SML_TMO_MOVIAL_BLOB_MAX_SUPPORT_CAT_SP 10
/* Define the total size of each category */
#define SML_TMO_MOVIAL_BLOB_CAT_N_SIZE (SML_TMO_MOVIAL_BLOB_SIZE_OF_CAT_N * SML_TMO_MOVIAL_BLOB_MAX_SUPPORT_CAT_N)
#define SML_TMO_MOVIAL_BLOB_CAT_NS_SIZE (SML_TMO_MOVIAL_BLOB_SIZE_OF_CAT_NS * SML_TMO_MOVIAL_BLOB_MAX_SUPPORT_CAT_NS)
#define SML_TMO_MOVIAL_BLOB_CAT_SP_SIZE (SML_TMO_MOVIAL_BLOB_SIZE_OF_CAT_SP * SML_TMO_MOVIAL_BLOB_MAX_SUPPORT_CAT_SP)
#define SML_TMO_MOVIAL_BLOB_ITERATION_COUNT_SIZE 4
#define SML_TMO_MOVIAL_BLOB_SALT_SIZE 16
#define SML_TMO_MOVIAL_BLOB_HCK_SIZE 32
#define SML_TMO_MOVIAL_BLOB_SIZE_OF_SIGNATURE 256
#define SML_TMO_MOVIAL_SIZE_OF_UNLOCK_TIME 4
#define SML_TMO_MOVIAL_TIMEOUT_PERIODIC_CHECK (KAL_TICKS_1_SEC*10)//(12*60*KAL_TICKS_1_MIN) /* 12 hours */
#define SML_TMO_MOVIAL_TIMER_INDEX_PERIODIC_CHECK 0x05
#define SML_TMO_MOVIAL_SLB_ERR_SUCCESS 0x00
#define SML_TMO_MOVIAL_SLB_ERR_GENERIC 0x01
#define SML_TMO_MOVIAL_SLB_ERR_BLOB_TOO_SHORT 0x02
#define SML_TMO_MOVIAL_SLB_ERR_VERIFY_FAIL 0x03
#define SML_TMO_MOVIAL_SLB_ERR_GET_TIME_OP_FAIL 0x04
#define SML_TMO_MOVIAL_SLB_ERR_IMEI_MISMATCH 0x05
#define SML_TMO_MOVIAL_SLB_ERR_BLOB_FRESH_CHECK_FAIL 0x06
#define SML_TMO_MOVIAL_NVRAM_ACCESS_ID_UPDATE_CAT_LOCK 0xDA
#define SML_TMO_MOVIAL_NVRAM_ACCESS_ID_UPDATE_SLB 0xDB
#define SML_TMO_MOVIAL_NVRAM_ACCESS_ID_UNLOCK_EXPIRE 0xDC
#define SML_TMO_MOVIAL_NVRAM_ACCESS_ID_UPDATE_CORR 0xDD
#define SML_TMO_MOVIAL_NVRAM_ACCESS_ID_RESTORE_LOCK 0xDE
typedef enum {
SML_TMO_MOVIAL_CAT_LOCKED,
SML_TMO_MOVIAL_CAT_UNLOCKED,
} sml_tmo_movial_cat_lock_enum;
typedef struct {
kal_uint8 change_flag;
kal_uint8 num; /* num of valid sets */
sml_tmo_movial_cat_lock_enum cat_lock;
} sml_tmo_movial_blob_meta_struct;
typedef struct {
kal_uint8 iteration_count[SML_TMO_MOVIAL_BLOB_ITERATION_COUNT_SIZE]; /* 4 */
kal_uint8 salt[SML_TMO_MOVIAL_BLOB_SALT_SIZE]; /* 16 */
kal_uint8 hck[SML_TMO_MOVIAL_BLOB_HCK_SIZE]; /* 32 */
} sml_tmo_movial_blob_key_struct;
typedef struct {
kal_uint8 major_version;
kal_uint8 minor_version;
kal_uint8 protection_algorithm;
kal_uint8 lock_operation;
kal_uint8 imei[SML_TMO_MOVIAL_BLOB_IMEI_SIZE]; /* 15 */
kal_uint8 time_stamp[SML_TMO_MOVIAL_BLOB_TIME_STAMP_SIZE]; /* 8 */
kal_uint8 start_time[SML_TMO_MOVIAL_SIZE_OF_START_TIME]; /* 8 */
kal_uint8 unlock_duration[SML_TMO_MOVIAL_SIZE_OF_UNLOCK_DURATION]; /* 4 */
kal_uint8 length[SML_TMO_MOVIAL_BLOB_LENGTH_SIZE]; /* 2 */
sml_tmo_movial_blob_meta_struct cat[SML_TMO_MOVIAL_BLOB_CONFIG_SUPPORT_CAT_SIZE]; /* (3 * ?) */
sml_tmo_movial_blob_key_struct key[SML_TMO_MOVIAL_BLOB_CONFIG_SUPPORT_CAT_SIZE]; /* (3 * 52) */
kal_uint8 code_cat_n[SML_TMO_MOVIAL_BLOB_CAT_N_SIZE]; /* (30 * 6)*/
kal_uint8 code_cat_ns[SML_TMO_MOVIAL_BLOB_CAT_NS_SIZE]; /* (10 * 8)*/
kal_uint8 code_cat_sp[SML_TMO_MOVIAL_BLOB_CAT_SP_SIZE]; /* (10 * 7)*/
kal_uint8 signature[SML_TMO_MOVIAL_BLOB_SIZE_OF_SIGNATURE]; /* 256 */
kal_uint8 unlock_time[SML_TMO_MOVIAL_SIZE_OF_UNLOCK_TIME]; /* 4 */
} sml_tmo_movial_sim_lock_context_struct;
typedef sml_tmo_movial_sim_lock_context_struct nvram_sml_tmo_movial_sim_lock_context_struct;
#define SML_TMO_MOVIAL_MAX_BLOB_SIZE NVRAM_EF_L4_SML_TMO_MOVIAL_SIM_LOCK_SIZE
typedef struct {
kal_uint64 correlation_id;
} sml_tmo_movial_corr_id_struct;
typedef sml_tmo_movial_corr_id_struct nvram_sml_tmo_movial_corr_id_struct;
typedef enum {
SML_TMO_MOVIAL_CAT_BEGIN,
SML_TMO_MOVIAL_CAT_N = SML_TMO_MOVIAL_CAT_BEGIN,
SML_TMO_MOVIAL_CAT_NS,
SML_TMO_MOVIAL_CAT_SP,
SML_TMO_MOVIAL_CAT_SIZE,
SML_TMO_MOVIAL_CAT_NULL
} sml_tmo_movial_cat_enum;
typedef struct {
void * pObj;
void (* give)(void * /* pLidToObj */, kal_uint8);
void (* take)(void * /* pObjToLid */, kal_uint8);
void (* destory)(kal_uint8);
void * (* getItem)(sml_tmo_movial_cat_enum,sml_ctx_enum,kal_uint16 * /* length */, kal_uint8);
void (* putItem)(sml_tmo_movial_cat_enum,sml_ctx_enum,void * /* pItem */, kal_uint16 * /* plen */, kal_uint8);
} nvram_ef_sml_tmo_movial_sim_lock_obj_struct;
extern void sml_clean_tmo_movial_cntxt(void);
extern void sml_tmo_movial_give( void *pLidToObj, kal_uint8 source );
extern void sml_tmo_movial_take( void *pObjToLid, kal_uint8 source );
extern void sml_tmo_movial_destory(kal_uint8 source);
extern void *sml_tmo_movial_getItem( sml_tmo_movial_cat_enum category,
sml_ctx_enum item,
kal_uint16 *plength,
kal_uint8 source);
extern void sml_tmo_movial_putItem( sml_tmo_movial_cat_enum cat,
sml_ctx_enum item,
void *pItem,
kal_uint16 *plength,
kal_uint8 source);
extern kal_bool sml_tmo_movial_ValidateIMEI(kal_uint8 *imei, kal_bool is_bypass_default, kal_uint8 source);
extern kal_bool sml_tmo_movial_ValidateTimeStamp(kal_uint8 *new_time_stamp, kal_uint8 source);
extern kal_bool sml_tmo_movial_ValidateConfigData(sml_tmo_movial_sim_lock_context_struct *pBlob);
extern kal_uint8 *sml_tmo_movial_ConstructBlob(kal_uint8 *pObj, kal_uint16 slb_len, kal_uint8 *error_cause, kal_uint8 source);
extern kal_uint8 *sml_tmo_movial_ConstructSmlBlob(sml_tmo_movial_sim_lock_context_struct *pObj, kal_uint8 source);
extern kal_uint8 *sml_tmo_movial_ReconstructBlob(sml_tmo_movial_sim_lock_context_struct *pObj, kal_uint32 *pLen, kal_uint8 *error_cause);
extern kal_bool sml_tmo_movial_checkValidity(void *pObj, kal_uint8 source, kal_uint8 *error_cause);
extern void sml_tmo_movial_Load(void *pLid, kal_uint8 source);
extern void sml_tmo_movial_FirstLoad(void *pLid, kal_uint8 source);
extern kal_uint16 sml_tmo_movial_Save(void *pLid, kal_uint8 source);
extern kal_bool sml_tmo_movial_CheckTempUnlock(kal_uint8 source);
extern kal_uint8 sml_tmo_movial_Catcode(sml_tmo_movial_cat_enum cat,
kal_uint8 *imsi,
kal_uint8 *gid1,
kal_uint8 mnc_len,
kal_uint8 *code);
extern kal_uint8 sml_tmo_movial_GetCode( sml_tmo_movial_cat_enum cat,
kal_uint8 * imsi,
kal_uint8 * gid1,
kal_uint8 sim_mnc_len,
kal_uint8 * pdata,
kal_uint8 * code);
extern kal_bool sml_tmo_movial_Check(sml_tmo_movial_cat_enum cat,
kal_uint8 *imsi,
kal_uint8 *gid1,
kal_uint8 sim_mnc_len,
kal_uint8 source);
extern kal_bool sml_tmo_movial_UpdateNwTimeAndCheckTempLock(kal_uint8 source,
kal_uint8 nw_time_zone,
nw_time_zone_time_struct *nw_time);
extern kal_bool sml_tmo_movial_Verify(sml_tmo_movial_cat_enum cat,
kal_uint8 * key,
kal_uint8 len,
kal_uint8 source);
extern kal_uint8 sml_tmo_movial_update_slb(void *blob, kal_uint8 source);
extern kal_uint8 *sml_tmo_movial_ConstructFirstBlob(kal_uint8 *pObj, kal_uint16 slb_len, kal_uint8 source);
extern nvram_ef_sml_tmo_movial_sim_lock_obj_struct* pSMLTMMg;
extern kal_uint32 sml_tmo_movial_seconds_to_expire;
extern void sml_tmm_GetLockState(kal_uint8 *lock_state, kal_uint8 source);
extern kal_uint32 sml_tmm_GetUnlockTimeLeft(kal_uint8 source);
extern kal_bool custom_check_is_default_imei(kal_uint8 *imei);
extern void custom_tmo_movial_rsu_get_pub_key_handle(kal_uint8 index,
TYPE_CUST_CHL_KEY *key1, TYPE_CUST_CHL_KEY *key2);
#endif /* CUSTOM_SML_H */