[Feature][S300][task-view-1920][locknet] Implementation of enhanced network locking scheme
Change-Id: I27b0f4cb34ba8daece8d05a59edd6ebed99bdf65
diff --git a/lynq/S300/BJMTN/ap/project/zx297520v3/prj_mifi_min/fs/normal/rootfs/etc_ro/default/default_parameter_user b/lynq/S300/BJMTN/ap/project/zx297520v3/prj_mifi_min/fs/normal/rootfs/etc_ro/default/default_parameter_user
index e98ba8c..1ecb75c 100755
--- a/lynq/S300/BJMTN/ap/project/zx297520v3/prj_mifi_min/fs/normal/rootfs/etc_ro/default/default_parameter_user
+++ b/lynq/S300/BJMTN/ap/project/zx297520v3/prj_mifi_min/fs/normal/rootfs/etc_ro/default/default_parameter_user
@@ -507,4 +507,5 @@
arms_device_sec=
arms_device_md5=
arms_fota_version=
-#for apparms end
\ No newline at end of file
+#for apparms end
+reserved_value=1
\ No newline at end of file
diff --git a/lynq/S300/ap/app/zte_comm/at_ctl/src/atconfig/ps_normal.c b/lynq/S300/ap/app/zte_comm/at_ctl/src/atconfig/ps_normal.c
index 57944da..67ea375 100755
--- a/lynq/S300/ap/app/zte_comm/at_ctl/src/atconfig/ps_normal.c
+++ b/lynq/S300/ap/app/zte_comm/at_ctl/src/atconfig/ps_normal.c
@@ -88,6 +88,8 @@
#endif
extern struct defcid_mng_t g_defcid_mng;
char imsi[50] = {0};
+extern int is_valid_plmn(char *mcc, char *mnc);
+extern int mccmnc_empty_flag;
//zdm ÇëÕ×·áÈ·ÈÏÊÇ·ñÐèҪͬ²½µ½AP²à
//ºóÐøÓÃËøÍøÌæ´ú£¬ÆÕͨ°æ±¾²»Ëø
char* zurdy_convert_cmd(void *msg,struct at_context *context)
@@ -1977,6 +1979,8 @@
char needCopsNumFormat[10] = {0};
T_zAt_CopsReadRes copsReadPara = {0};
T_zAt_OperatorName operatorName = {0};
+ int ret = 0;
+ char ppp_status[20] = {0};
void *p[5] = {&copsReadPara.mode,&copsReadPara.format,copsReadPara.oper,&copsReadPara.act,&copsReadPara.subact};
at_print(AT_DEBUG,"normal_recvcopsreadrsp at_paras=%s!\n",at_paras);
@@ -2032,6 +2036,21 @@
}
at_print(AT_DEBUG,"normal_recvcopsreadrsp send to mmi MSG_CMD_GET_NET_PROVIDER\n");
ipc_send_message(MODULE_ID_AT_CTL,MODULE_ID_MMI,MSG_CMD_GET_NET_PROVIDER, 0, NULL,0);
+
+ if(1 == mccmnc_empty_flag)
+ {
+ mccmnc_empty_flag = 0;
+ cfg_get_item(NV_PPP_STATUS, ppp_status, sizeof(ppp_status));
+ if(0 == strcmp(PPP_DISCONNECTED, ppp_status))
+ {
+ ret = is_valid_plmn(sMCC, sMNC);
+
+ if(ret)
+ {
+ ipc_send_message(MODULE_ID_WEB_CGI, MODULE_ID_AT_CTL, MSG_CMD_PDP_ACT_REQ, 0, NULL, 0);
+ }
+ }
+ }
}
diff --git a/lynq/S300/ap/app/zte_comm/at_ctl/src/atconfig/ps_pdp.c b/lynq/S300/ap/app/zte_comm/at_ctl/src/atconfig/ps_pdp.c
index 28d7339..4e03944 100755
--- a/lynq/S300/ap/app/zte_comm/at_ctl/src/atconfig/ps_pdp.c
+++ b/lynq/S300/ap/app/zte_comm/at_ctl/src/atconfig/ps_pdp.c
@@ -41,6 +41,9 @@
#define MAX_AT_IPV6_SIZE 64 // ´ÓATÏìÓ¦ÃüÁî»ñÈ¡µÄIPV6µØÖ·³¤¶È
#define MAX_AT_IPV4V6_SIZE 80 // ´ÓATÏìÓ¦ÃüÁî»ñÈ¡µÄIPV4V6µØÖ·³¤¶È£¬16(IPV4) + 64(IPV6)
+int mccmnc_empty_flag = 0;
+extern int is_valid_plmn(char *mcc, char *mnc);
+
enum
{
CID_IDLE = 0,
@@ -1586,6 +1589,19 @@
char creg_stat[20] = {0};
char cereg_stat[20] = {0};
char ppp_status[20] = {0};
+ int ret = 0;
+ char mcc[4] = {0};
+ char mnc[4] = {0};
+
+ cfg_get_item("mcc", mcc, sizeof(mcc));
+ cfg_get_item("mnc", mnc, sizeof(mnc));
+ at_print(AT_DEBUG, "pdp_act_func mcc=%s,mnc=%s\n", mcc, mnc);
+
+ ret = is_valid_plmn(mcc, mnc);
+ if(0 == ret)
+ {
+ return NULL;
+ }
cfg_get_item("cgreg_stat", creg_stat, sizeof(creg_stat));
cfg_get_item("cereg_stat", cereg_stat, sizeof(cereg_stat));
@@ -3289,9 +3305,33 @@
void start_pdp_auto_dial(void)
{
+ int ret = 0;
char auto_reconnect [20] = {0};
char reconnect_type[20] = {0};
+ char mcc[4] = {0};
+ char mnc[4] = {0};
+
+ cfg_get_item("mcc", mcc, sizeof(mcc));
+ cfg_get_item("mnc", mnc, sizeof(mnc));
+ at_print(AT_DEBUG, "start_pdp_auto_dial mcc=%s,mnc=%s\n", mcc, mnc);
+
+ if(strlen(mcc) == 0 || strlen(mnc) == 0)
+ {
+ mccmnc_empty_flag = 1;
+ return;
+ }
+ else
+ {
+ mccmnc_empty_flag = 0;
+ }
+
+ ret = is_valid_plmn(mcc, mnc);
+ if(0 == ret)
+ {
+ return;
+ }
+
cfg_get_item("reconnect_type", reconnect_type, sizeof(reconnect_type));
cfg_get_item("auto_reconnect", auto_reconnect, sizeof(auto_reconnect));
//µ±Ç°Ä¬ÈÏapnµÄpdp¼¤»îÇëÇóÒÑ´æÔÚ£¬Ôò˵Ã÷ĬÈÏapn¿Ï¶¨ÒѾ·¢Æð¹ýpdp¼¤»î
diff --git a/lynq/S300/ap/app/zte_comm/zte_locknet/Makefile b/lynq/S300/ap/app/zte_comm/zte_locknet/Makefile
index b1aed72..ef28b64 100755
--- a/lynq/S300/ap/app/zte_comm/zte_locknet/Makefile
+++ b/lynq/S300/ap/app/zte_comm/zte_locknet/Makefile
@@ -21,12 +21,14 @@
CFLAGS += -O -Dlinux=1 -DHIGH_SPEED=1
CFLAGS += -g
CFLAGS += -g -Werror=implicit-function-declaration
+CFLAGS += -I$(zte_lib_path)/libamt
LDLIBS += -lnvram -L$(zte_lib_path)/libnvram
LDLIBS += -lsoftap -L$(zte_lib_path)/libsoftap
LDLIBS += -latutils -L$(zte_lib_path)/libatutils
LDLIBS += -lsqlite -L$(zte_lib_path)/libsqlite
LDLIBS += -lsoft_timer -L$(zte_lib_path)/libsoft_timer
+LDLIBS += -lamt -L$(zte_lib_path)/libamt
LDLIBS += -lm
LDLIBS += -lpthread -L$(zte_lib_path)/libpthread
diff --git a/lynq/S300/ap/app/zte_comm/zte_locknet/src/zctrm_locknet_main.c b/lynq/S300/ap/app/zte_comm/zte_locknet/src/zctrm_locknet_main.c
index ed4968f..970b9ba 100755
--- a/lynq/S300/ap/app/zte_comm/zte_locknet/src/zctrm_locknet_main.c
+++ b/lynq/S300/ap/app/zte_comm/zte_locknet/src/zctrm_locknet_main.c
@@ -3,6 +3,8 @@
#include "zctrm_locknet.h"
int sendflag = 0;
+extern UINT32 zCtrm_WriteLocklist(UINT8 *data, UINT16 dataLen);
+
void locknet_msg_proc(MSG_BUF *msg_buf)
{
switch (msg_buf->usMsgCmd) {
@@ -62,6 +64,161 @@
}
}
+#define NUM_BASE 52
+static UINT8 s_plmnList_temp_num = 0;
+static T_zCtrm_LockListPara s_plmnList_temp[20] = {0};
+static T_zCtrm_LockListPara s_plmnList[20] = {0};
+static UINT8 s_plmnList_num = 0;
+
+void plmnList_init(void)
+{
+ const char * temp = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
+ memset(s_plmnList, 0, sizeof(s_plmnList));
+ //add china plmn 46000-46011
+ UINT8 i = 0;
+ for(i = 0; i < 12; i++)
+ {
+ s_plmnList[i].mcc[0] = temp[NUM_BASE+4];
+ s_plmnList[i].mcc[1] = temp[NUM_BASE+6];
+ s_plmnList[i].mcc[2] = temp[NUM_BASE+0];
+ if (i < 10)
+ {
+ s_plmnList[i].mnc[0] = temp[NUM_BASE+0];
+ s_plmnList[i].mnc[1] = temp[NUM_BASE+i];
+ }
+ else
+ {
+ s_plmnList[i].mnc[0] = temp[NUM_BASE+1];
+ s_plmnList[i].mnc[1] = temp[NUM_BASE+i-10];
+ }
+ }
+ //add plmn 62120
+ s_plmnList[12].mcc[0] = temp[NUM_BASE+6];
+ s_plmnList[12].mcc[1] = temp[NUM_BASE+2];
+ s_plmnList[12].mcc[2] = temp[NUM_BASE+1];
+ s_plmnList[12].mnc[0] = temp[NUM_BASE+2];
+ s_plmnList[12].mnc[1] = temp[NUM_BASE+0];
+
+ s_plmnList_num = 13;
+}
+
+int is_valid_plmn(char *mcc, char *mnc)
+{
+ if(mcc == NULL || mnc == NULL)
+ {
+ return 0;
+ }
+
+ if(0 == s_plmnList_num)
+ {
+ return 1;
+ }
+
+ UINT8 i = 0;
+ for(i = 0; i < s_plmnList_num; i++)
+ {
+ if(strcmp(mcc, s_plmnList[i].mcc) == 0 && strcmp(mnc, s_plmnList[i].mnc) == 0)
+ {
+ return 1;
+ }
+ }
+ return 0;
+}
+
+int plmnList_get()
+{
+ UINT32 retCode = EXT_ERROR;
+ UINT16 iList = 0;
+ T_zCtrm_LockListPara lockList = {0};
+
+ s_plmnList_temp_num = 0;
+ for(iList = 0; iList < 20; iList++)
+ {
+ memset(&lockList, 0, sizeof(lockList));
+ retCode = cpnv_NvItemRead(AMT_LOCKNET_LIST + iList*sizeof(lockList), (UINT8 *)&lockList, sizeof(lockList));
+ if (EXT_SUCCESS != retCode )
+ {
+ slog(AT_PRINT,SLOG_ERR, "cpnv read error\n");
+ return 0;
+ }
+ if((lockList.mcc[0] == 0xFF)||(lockList.imsi6[0] == 0xFF)||(lockList.gid1[0] == 0xFF))
+ {
+ slog(AT_PRINT,SLOG_ERR, "plmnList_get break iList:[%d]\n",iList);
+ break;
+ }
+
+ lockList.mcc[LIST_MCCMNC_LEN-1] = '\0';
+ lockList.mnc[LIST_MCCMNC_LEN-1] = '\0';
+ lockList.imsi6[LIST_IMSI_LEN-1] = '\0';
+ lockList.imsi7[LIST_IMSI_LEN-1] = '\0';
+ lockList.gid1[LIST_GID_LEN-1] = '\0';
+ lockList.gid2[LIST_GID_LEN-1] = '\0';
+ slog(AT_PRINT,SLOG_ERR, "%s,%s,%s,%s,%s,%s\n",
+ lockList.mcc,lockList.mnc,lockList.imsi6,lockList.imsi7,lockList.gid1,lockList.gid2);
+ s_plmnList_temp[s_plmnList_temp_num++] = lockList;
+ }
+
+ return 1;
+}
+
+int is_plmnlist_same()
+{
+ if(s_plmnList_num == 0)
+ {
+ return 1;
+ }
+
+ if(s_plmnList_num != s_plmnList_temp_num)
+ {
+ return 0;
+ }
+
+ UINT8 i = 0;
+ for(i = 0; i < s_plmnList_num; i++)
+ {
+ if(strcmp(s_plmnList[i].mcc, s_plmnList_temp[i].mcc) != 0 || strcmp(s_plmnList[i].mnc, s_plmnList_temp[i].mnc) != 0)
+ {
+ return 0;
+ }
+ }
+
+ return 1;
+}
+
+void locknet_check()
+{
+ int ret = 0;
+ int i = 0;
+ UINT32 retCode = EXT_ERROR;
+ char locknet_value[512] = {0};
+ char str[64] = {0};
+
+ plmnList_init();
+ if (s_plmnList_num > 0)
+ {
+ plmnList_get();
+ ret = is_plmnlist_same();
+ if (0 == ret)
+ {
+ memset(locknet_value, 0, sizeof(locknet_value));
+ for(i = 0; i < s_plmnList_num; i++)
+ {
+ memset(str, 0, sizeof(str));
+ sprintf(str, "%s,%s,,,,;%d,,,,,;", s_plmnList[i].mcc, s_plmnList[i].mnc, i + 1);
+ strcat(locknet_value, str);
+ slog(AT_PRINT,SLOG_ERR, "locknet_check locknet_value:[%s]\n", locknet_value);
+ }
+ retCode = zCtrm_WriteLocklist(locknet_value, strlen(locknet_value));
+ if (EXT_SUCCESS != retCode )
+ {
+ slog(AT_PRINT,SLOG_ERR, "locknet_check write locknet fail\n");
+ }
+ }
+ }
+
+ return;
+}
+
int zte_locknet_main(int argc, char* argv[])
{
int msg_handle = 0;
@@ -70,6 +227,7 @@
prctl(PR_SET_NAME, "locknet", 0, 0, 0);
/* ´´½¨ÏûÏ¢¶ÓÁÐ*/
msg_handle = msgget(MODULE_ID_LOCKNET, IPC_CREAT|0600);
+ locknet_check();
while(1)
{
memset(&msg, 0x00, sizeof(MSG_BUF));
diff --git a/lynq/S300/ap/app/zte_comm/zte_locknet/src/zctrm_locknet_proc.c b/lynq/S300/ap/app/zte_comm/zte_locknet/src/zctrm_locknet_proc.c
index 8407539..af97271 100755
--- a/lynq/S300/ap/app/zte_comm/zte_locknet/src/zctrm_locknet_proc.c
+++ b/lynq/S300/ap/app/zte_comm/zte_locknet/src/zctrm_locknet_proc.c
@@ -6,6 +6,7 @@
//#include "ps_normal.h"
//#include "ps_wifi.h"
#include <limits.h>
+#include "amtnv.h"
static BOOL g_IsDigestKeyGot = FALSE;
static BOOL g_IsSetListKeyGot = FALSE;
@@ -464,7 +465,7 @@
return EXT_SUCCESS;
}
-static UINT32 zCtrm_WriteLocklist(UINT8 *data, UINT16 dataLen)
+UINT32 zCtrm_WriteLocklist(UINT8 *data, UINT16 dataLen)
{
UINT8 *pBegin = data;
UINT8 *pEnd = NULL;
@@ -520,6 +521,9 @@
{
return EXT_ERROR;
}
+ amt_nvro_user_write(31, 2, "1");
+ cfg_set("reserved_value", "1");
+ cfg_save();
pBegin = pEnd + 1;
}
@@ -838,7 +842,11 @@
UINT8 plainText128[KEY_LEN] = {0};
UINT8 cipherText[KEY_LEN] = {0};
CHAR cipherHex[KEY_LEN*2+1] = {0};
- CHAR at_str[AT_STR_LEN+KEY_LEN*2] = {0};
+ CHAR at_str[AT_STR_LEN+KEY_LEN*2] = {0};
+ const char* temp = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
+ int idx[16] = {28, 8, 15, 7, 4, 17, 42, 20, 0, 17, 0, 13, 19, 8, 13, 4};
+ char locknet_value[64] = {0};
+ int i = 0;
if (g_IsSetListKeyGot != FALSE)
{
@@ -857,7 +865,12 @@
memset(g_SetListPlaint,0,sizeof(g_SetListPlaint));
//memcpy(g_SetListPlaint,plainText,sizeof(g_SetListPlaint)-1);
- memcpy(g_SetListPlaint, "locknetcode_lynq",sizeof(g_SetListPlaint)-1);
+ memset(locknet_value, 0, sizeof(locknet_value));
+ for(i = 0; i < 16; i++)
+ {
+ locknet_value[i] = temp[idx[i]];
+ }
+ memcpy(g_SetListPlaint, locknet_value, sizeof(g_SetListPlaint)-1);
snprintf(at_str,AT_STR_LEN+KEY_LEN*2,"\r\n+LOCKLISTAUTH: %s\r\nOK\r\n",cipherHex);
g_IsSetListKeyGot = TRUE;
goto end;
@@ -869,8 +882,35 @@
int zCtrm_LocknetAuthProc(MSG_BUF *msg)
{
char at_str[AT_STR_LEN] = {0};
-
+ char lock_write_flag[2] = {0};
+ int ret = 0;
+
at_print(AT_ERR,"zCtrm_LocknetAuthProc\n");
+ cfg_get_item("reserved_value", lock_write_flag, sizeof(lock_write_flag));
+ if (1 == atoi(lock_write_flag))
+ {
+ at_print(AT_ERR, "zCtrm_LocknetAuthProc,the parameters have already been written in\n");
+ goto error;
+ }
+ else
+ {
+ memset(lock_write_flag, 0, sizeof(lock_write_flag));
+ ret = amt_nvro_user_read(31, 2, lock_write_flag);
+ if(ret == 0)
+ {
+ at_print(AT_ERR,"zCtrm_LocknetAuthProc, cpvn flag:%s\n", lock_write_flag);
+ if (1 == atoi(lock_write_flag))
+ {
+ at_print(AT_ERR, "**zCtrm_LocknetAuthProc,the parameters have already been written in\n");
+ goto error;
+ }
+ }
+ else
+ {
+ at_print(AT_ERR,"zCtrm_LocknetAuthProc, read cpnv fail\n");
+ }
+ }
+
if('g' == (char*)msg->aucDataBuf[0])
{
zCtrm_LocknetAuthGen();
@@ -906,7 +946,7 @@
}
at_paras = (char*)msg->aucDataBuf;
dataLen = strlen(at_paras);
- at_print(AT_ERR,"dataLen = %d\n",dataLen);
+ at_print(AT_ERR,"******lock value:[%s],dataLen = %d\n", at_paras, dataLen);
retCode = zCtrm_CheckLocklist((char*)msg->aucDataBuf, dataLen);
if (EXT_SUCCESS != retCode )
{
diff --git a/lynq/S300/ap/lib/libatext/ext_locknet.c b/lynq/S300/ap/lib/libatext/ext_locknet.c
index 60fe04c..727d2f2 100755
--- a/lynq/S300/ap/lib/libatext/ext_locknet.c
+++ b/lynq/S300/ap/lib/libatext/ext_locknet.c
@@ -93,16 +93,16 @@
{
register_serv_func("LOCKLISTAUTH=", MODULE_ID_LOCKNET, ext_LocklistAuth_func);
register_serv_func("LOCKNETLIST=", MODULE_ID_LOCKNET, ext_LocknetList_set_func);
- register_serv_func("UNLOCKKEY=", MODULE_ID_LOCKNET, ext_LocknetKey_func);
- register_serv_func("UNLOCKKEY?", MODULE_ID_LOCKNET, ext_LocknetAmtStatus_get_func);
- register_serv_func("LOCKDIGEST?", MODULE_ID_LOCKNET, ext_LocknetDigest_get_func);
- register_serv_func("LOCKSIGN=", MODULE_ID_LOCKNET, ext_LocknetSign_set_func);
+ //register_serv_func("UNLOCKKEY=", MODULE_ID_LOCKNET, ext_LocknetKey_func);
+ //register_serv_func("UNLOCKKEY?", MODULE_ID_LOCKNET, ext_LocknetAmtStatus_get_func);
+ //register_serv_func("LOCKDIGEST?", MODULE_ID_LOCKNET, ext_LocknetDigest_get_func);
+ //register_serv_func("LOCKSIGN=", MODULE_ID_LOCKNET, ext_LocknetSign_set_func);
register_serv_func("LOCKLEVEL?", MODULE_ID_LOCKNET,ext_LocknetLevel_get_func);
register_serv_func("MEPCG=", MODULE_ID_LOCKNET, ext_LocknetList_get_func);
- register_serv_func("LOCKNETAUTH", MODULE_ID_LOCKNET, ext_LocknetAuth_func);
- register_serv_func("ZNCK?", MODULE_ID_LOCKNET, ext_LocknetUnlockTimes_get_func);
- register_serv_func("ZSEC?", MODULE_ID_LOCKNET, ext_LocknetStatus_get_func);
- register_serv_func("ZNCK=", MODULE_ID_LOCKNET, ext_LocknetUnlock_func);
+ //register_serv_func("LOCKNETAUTH", MODULE_ID_LOCKNET, ext_LocknetAuth_func);
+ //register_serv_func("ZNCK?", MODULE_ID_LOCKNET, ext_LocknetUnlockTimes_get_func);
+ //register_serv_func("ZSEC?", MODULE_ID_LOCKNET, ext_LocknetStatus_get_func);
+ //register_serv_func("ZNCK=", MODULE_ID_LOCKNET, ext_LocknetUnlock_func);
register_inform_func("ZURDY",zurdy_auto_act);
}
diff --git a/lynq/S300/ap/project/zx297520v3/prj_mifi_min/fs/normal/rootfs/etc_ro/default/default_parameter_user b/lynq/S300/ap/project/zx297520v3/prj_mifi_min/fs/normal/rootfs/etc_ro/default/default_parameter_user
index 00186dc..476ff65 100755
--- a/lynq/S300/ap/project/zx297520v3/prj_mifi_min/fs/normal/rootfs/etc_ro/default/default_parameter_user
+++ b/lynq/S300/ap/project/zx297520v3/prj_mifi_min/fs/normal/rootfs/etc_ro/default/default_parameter_user
@@ -501,4 +501,4 @@
fsfota_server_url=ftp://ftp:ftp123456@183.67.24.178:6521/FOTA/fsfota
#for fsfota end
SSIDbak=
-locknet_write_flag=0
+reserved_value=1