SIMLock锁卡功能解析
Posted 知不足而奋进
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SIMLock锁卡功能解析相关的知识,希望对你有一定的参考价值。
一、锁卡背景介绍
锁卡即SIMLock,当手机开机启动或者插入SIM卡时,手机modem侧预置在NV项中的配置信息会与SIM卡中的信息做比对,检测是否匹配。若匹配,则SIM卡可以正常使用。若不匹配,则SIM卡相关功能均无法正常使用,例如拨打电话、发送短信及上网等;或者是只能注册2G网,不能注册4G。
锁卡的目的:一些运营商会要求控制某一类卡的使用,从而保护自己的利益(运营商定制机)
SIMLock锁和图案锁,数字密码锁,PIN码锁,PUK锁一样,是Keyguard模块中的一种锁。
二、锁卡的需求
锁卡的需求方式有7种之多,常见的有NP锁,NS锁,CP锁,SP锁等
从安卓机器来看,目前最常用的是SP锁(MCC/MNC),本文将解析SP锁的加锁流程
三、锁卡流程解析
1.首先modem侧检测SIM卡的配置信息并与之作比对,若匹配则继续加载SIM卡,若不匹配,则上报加锁信息
2.RIL层检测到modem上报的加锁信息,然后发送给framework层,最终在AP层监测到事件:
3.AP层显示出锁卡界面,要求用户输入解锁码进行解锁
四、相关流程图
1.加锁流程图
2.解锁流程图
五、代码解析
MTK平台已经支持SIMLock功能,但只能在代码中写固定的MCC/MNC,不能灵活配置。即一套代码只能对应一套对应的锁卡配置信息,对于手机厂商来说,显然不满足需求,发货国家遍布全球,锁卡配置信息均不同,代码版本太多无法管理,故肯定要废弃MTK的这套SIMLock功能。
(1)modem侧客制化
涉及的代码文件:
-
custom/modem/common/ps/custom_nvram_extra.c
-
custom/modem/common/ps/customer_at_command.c
-
custom/service/nvram/custom_nvram_sec.c
-
custom/service/nvram/custom_nvram_sec.h
-
interface/service/nvram/nvram_data_items.h
-
service/nvram/src/nvram_factory_config.c
-
service/nvram/src/nvram_main.c
a.扩展锁卡配置信息的组数
custom_nvram_sec.h
#define SML_MAX_SUPPORT_CAT_N 50
初始化数组的时候,需要添加对应的默认配置信息
-
const nvram_sml_context_struct NVRAM_EF_SML_DEFAULT =
-
SML_MAGIC_HEAD_VALUE,
-
SML_STATE_UNLOCK,SML_RETRY_COUNT_N_CAT,0,0, /* Category N */
-
SML_STATE_UNLOCK,SML_RETRY_COUNT_NS_CAT ,0,0, /* Category NS */
-
SML_STATE_UNLOCK,SML_RETRY_COUNT_SP_CAT ,0,0, /* Category SP */
-
SML_STATE_UNLOCK,SML_RETRY_COUNT_C_CAT ,0,0, /* Category C */
-
SML_STATE_UNLOCK,SML_RETRY_COUNT_SIM_CAT ,0,0, /* Category SIM */
-
SML_STATE_UNLOCK,SML_RETRY_COUNT_NS_CAT ,0,0, /* Link NS-SP */
-
SML_STATE_UNLOCK,SML_RETRY_COUNT_C_CAT ,0,0, /* Link SIM-C */
-
SML_KEY_SET,0x21,0x43,0x65,0x87,0xFF,0xFF,0xFF,0xFF,
-
SML_KEY_SET,0x65,0x87,0x21,0x43,0xFF,0xFF,0xFF,0xFF,
-
SML_KEY_SET,0x11,0x22,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
-
SML_KEY_EMPTY,0x33,0x44,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
-
SML_KEY_EMPTY,0x55,0x66,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
-
SML_KEY_SET,0x77,0x88,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
-
SML_KEY_SET,0x99,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
-
/* Category N code */
-
0x73,0x00,0x1F,0x73,0x00,0x2F,0x73,0x00,0x3F,0x73,0x00,0x4F,0x73,0x00,0x5F,
-
0x73,0x00,0x6F,0x73,0x00,0x7F,0x73,0x00,0x8F,0x73,0x00,0x9F,0x73,0x01,0x0F,
-
0x73,0x01,0x1F,0x73,0x09,0x9F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
-
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF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,0xc7,0xc7,0xc7,0xc7,0xc7,0xc7,0xc7,0xc7,
-
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
-
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
-
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
-
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
-
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
-
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
-
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
-
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
-
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
-
0xFF,0xFF,
-
SML_MAGIC_TAIL_VALUE
-
;
以上是关于SIMLock锁卡功能解析的主要内容,如果未能解决你的问题,请参考以下文章