Merge "[Feature][S300][task-view-1920][app] add S300V2 BJMTN plmn dial lock base"
diff --git a/lynq/S300/BJMTN/ap/app/zte_comm/at_ctl/src/atconfig/ps_pdp.c b/lynq/S300/BJMTN/ap/app/zte_comm/at_ctl/src/atconfig/ps_pdp.c
new file mode 100755
index 0000000..28d7339
--- /dev/null
+++ b/lynq/S300/BJMTN/ap/app/zte_comm/at_ctl/src/atconfig/ps_pdp.c
@@ -0,0 +1,3397 @@
+/*****************************************************************************
+* °æ±¾ËùÓÐ
+* Ä£¿éÃû £º
+* ÎļþÃû £º
+* Îļþ±êʶ£º
+* Ïà¹ØÎļþ£º
+* ʵÏÖ¹¦ÄÜ£º¸ÃÎļþÖ÷ÒªÊÇat_ctlÖÐÓëPDP¼¤»îÏà¹ØµÄʼþʵÏÖºÍÃüÁî´¦Àí½Ó¿Ú£¬°üÀ¨apnÉèÖÃÏà¹ØÃüÁî´¦Àí¡¢¼øÈ¨Ïà¹ØÃüÁî´¦Àí
+ÒÔ¼°¼¤»îÃüÁîµÄ´¦Àí
+
+cidÕ¼ÓÃÔÔò:
+1¡¢Ô¤ÁôCIDÖ±½Óͨ¹ýATÃüÁºÅ(cgact\zgact)
+2¡¢·ÇÔ¤ÁôCID£¬Èç´æÔÚ¼ÓÃÜÈÏÖ¤Ôò¶Àռһ·CID
+3¡¢·ÇÔ¤ÁôCID£¬ÈçapnºÍpdpÀàÐÍÏàͬÔò¹²Ïíһ·CID
+4¡¢ÈôPDP¼¤»îʱ²»Ö¸¶¨APNÔòʹÓÃĬÈÏAPN
+¶ÔÓÚAPºÍCP²»Í¬ÒµÎñ¹²ÏícidµÄʵÏÖ·½Ê½:
+1/ÓÉCP²àͳһ·¢Æðpdp¼¤»î£¬³É¹¦ºó£¬·¢Ëͺ˼äÏûÏ¢MSG_CMD_DATASWITCH_ON_REQ֪ͨAP²à½øÐÐ×éÍø£¬AP²àÒµÎñ½ö¼ì²éÍøÂçÊÇ·ñ¿ÉÓü´¿É£¬ÎÞÐè·¢Æðpdp¼¤»î
+2/AP²àºÍCP²à¸÷×Ô·¢ÆðPDP¼¤»î£¬ÓÉCP²àͳһÖٲã¬Èô·¢ÏÖPDP¼¤»îÇëÇóÖÐЯ´øÁËÏàͬµÄapnºÍip type£¬ÔòÈÏΪÕâЩÇëÇó¿ÉÒÔ
+¹²Ïíͬһcid£¬½«¸ÃapnºÍip typeÒѼ¤»îµÄcid·µ»Ø¸øpdpÇëÇóÔ´£¬²¢Ôö¼Ó¸ÃcidµÄÒýÓüÆÊý£¬Òò´Ë¸Ã·½Ê½ÐèÒª²»Í¬ÒµÎñ¸÷×Ô¹ÜÀí
+×Ô¼ºµÄpdp¼¤»îÁ÷³Ì£¬ÔÚ²»ÔÙʹÓÃcidʱ£¬±ØÐë·¢ÆðpdpÈ¥²¦ºÅ£¬ÊͷŸÃcid¡£
+3/Ö»ÓÐÄ£¿éÄÚ²¿Ê¹ÓõÄPDP¼¤»î£¬²ÅÔÊÐí¹²Ïí£¬Ò»µ©pdp¼¤»î£¬ÊÇΪÁ˸øÄ£¿éÍⲿʹÓã¬Ôò²»ÔÊÐí¹²Ïí
+* ×÷Õß £º
+* °æ±¾ £º
+* Íê³ÉÈÕÆÚ£º
+* ÆäËü˵Ã÷£º
+*****************************************************************************/
+
+#include "at_context.h"
+#include "ps_normal.h"
+#include "ps_pdp.h"
+#include "ppp_dial.h"
+#include "softap_api.h"
+#include "string.h"
+#include "at_zephyr.h"
+#include <asm/unistd.h>
+#include <limits.h>
+
+
+
+#define PDP_CMD_LEN 256 //PDP¼¤»îÏà¹ØµÄATÃüÁ¶È
+
+#define MAX_AT_IPV6_SIZE 64 // ´ÓATÏìÓ¦ÃüÁî»ñÈ¡µÄIPV6µØÖ·³¤¶È
+#define MAX_AT_IPV4V6_SIZE 80 // ´ÓATÏìÓ¦ÃüÁî»ñÈ¡µÄIPV4V6µØÖ·³¤¶È£¬16(IPV4) + 64(IPV6)
+
+enum
+{
+ CID_IDLE = 0,
+ CID_ACTIVING,
+ CID_DEACTIVING,
+ CID_ACTIVE,
+};
+
+struct cid_resource_t{
+ int c_id; //PDPΨһ±êʶ
+ int reserved; //c_id±£Áô±êÖ¾£¬ÖÃλÔò±íʾרÓ㬲»²ÎÓ붯̬»ñÈ¡£¬¿ª»úÅäÖÃ
+ int state; //c_idʹÓÃ״̬, ȡֵΪCID_IDLE£¬CID_ACTIVITINGºÍCID_ACTIVE
+ int ref; //ÓÃÀ´¼Ç¼ÊÇ·ñ¼¤»î½Å±¾Ö´ÐÐÖУ¬Ö´ÐÐÖÐΪ1
+ int auth_type; //¼Ç¼cid µ±Ç°µÄÈÏÖ¤ÀàÐÍ£¬ÓÃÓÚpdp¼¤»îǰÇå³ýÈÏÖ¤
+ char apn[APN_MAX_LEN];
+ char ip_type[IPTYPE_MAX_LEN];//IPÀàÐÍ£¬È¡ÖµÎª×Ö·û´®£¬"IP","IPV6","IPV4V6"£¬×¢ÒâÈ«²¿ÊÇ´óд
+};
+
+typedef struct
+{
+ struct pdp_act_req pdpActInfo; //´æ·Åpdp¼¤»îÏûÏ¢ÄÚÈÝ
+ int pdp_type; //±¾´Îpdp¼¤»îÀàÐÍ
+ int c_id; //±¾´Îpdp¼¤»î»ñÈ¡µÄcid
+ int index; //±¾´Îpdp¼¤»îÔÚCID×ÊÔ´Êý×éµÄϱí
+ int pdp_state; //µ±Ç°pdp¼¤»î״̬£¬0±íʾȥ¼¤»î£¬1±íʾ¼¤»î
+ int auth_state; //µ±Ç°ÈÏ֤״̬£¬PDP_DEL_AUTH±íʾȥ³ýÈÏÖ¤£¬PDP_ADD_AUTH±íʾÌí¼ÓÈÏÖ¤
+}PDP_PRIVATE_INFO;
+
+
+struct defcid_mng_t g_defcid_mng = {0};
+struct pdpinfo_mng_t g_pdpinfo_mng[CID_MAX_NUM] = {0};
+
+
+//ppp²¦ºÅ»ñÈ¡µ½µÄcid
+int ppp_cid = 0;
+
+//extern psnormal_state psinfo;
+//ÓÃÓÚpdp¼¤»îÖ®ºó£¬·¢ËÍÏûϢ֪ͨsmsºÍpbÄ£¿éÆô¶¯³õʼ»¯
+extern int g_smspb_init;
+
+/*ÓÉÓÚppp²¦ºÅ/Ö¸¶¨cid pdp²¦ºÅ»ñÈ¡µ½µÄIPµØÖ·£¬×îÖÕ¶¼»á·ÖÅ䏸PCÖÕ¶Ë£¬Òò´Ë¸Ãcid²»Äܹ²Ïí;
+cid¹²ÏíÔÔò:
+ Ö»ÓÐÄ£¿éÄÚ²¿Ê¹ÓõÄPDP¼¤»î£¬²ÅÔÊÐí¹²Ïí£¬Ò»µ©pdp¼¤»î£¬ÊÇΪÁ˸øÄ£¿éÍⲿʹÓã¬Ôò²»ÔÊÐí¹²Ïí
+*/
+struct cid_resource_t CID_ARRAY[CID_MAX_NUM] = {0};
+
+//cid±£Áôλͼ
+int cid_reserved = 0;
+int default_cur_cid=0;//¼Ç¼µ±Ç°cid
+//cid×ÊÔ´³õʼ»¯±ê¼Ç£¬ÔÚcid×ÊԴδ³õʼ»¯Íê³É֮ǰ£¬¶Ô½ÓÊÕµ½µÄpdp¼¤»îÇëÇ󣬯ô¶¯¶¨Ê±Æ÷£¬´ý³õʼ»¯Íê³Éºó£¬ÔÙ´¦Àí
+//Ò»°ãcpºËÔÚ½ÓÊÕµ½apµÄnvͬ²½ÇëÇó֮ǰ£¬ÓпÉÄÜÒѾ·¢ÆðÁËpdp¼¤»î£¬´ËʱÐèÒªÑӳٵȴý
+int is_cid_init = 0;
+static char *s_pstrIpv6Addr = NULL;/*µ÷ÊÔʱʹÓ㬺óÐø¿É¸ÄΪ¾Ö²¿±äÁ¿*/
+int apn_is_ims = -1;
+static unsigned char def_attach_cid_index = 0;
+
+void set_def_attach_cid(unsigned char cid)
+{
+ if(cid > 0 && cid < CID_MAX_NUM)
+ {
+ def_attach_cid_index = cid - 1;
+ }
+ at_print(AT_ERR,"def_attach_cid=%d now=%d\n",cid,def_attach_cid_index);
+}
+
+int get_is_cid_init()
+{
+ return is_cid_init;
+}
+
+void cid_resource_init()
+{
+ int i = 0;
+ char reservecid[30] = {0};
+ char versionmode[2] = {0};
+
+//¶ÔÓÚtos£¬±ØÐëµÈ´ýAP²àµÄnvͬ²½Ö®ºó£¬²Å»á½«is_cid_initÖÃΪ1£¬²¢½øÐÐcid×ÊÔ´³õʼ»¯
+#if (APP_OS_TYPE != APP_OS_TOS)
+ is_cid_init = 1;
+#endif
+
+#if 1
+ // kw 3 UNREACH.RETURN
+ if(0 == get_is_cid_init())
+ {
+ return;
+ }
+#else
+ if(0 == is_cid_init)
+ return;
+#endif
+ cfg_get_item("cid_reserved",reservecid,sizeof(reservecid));
+
+ at_print(AT_ERR,"start to init cid resource: origin cid_reserved:%d,new resumed:%s\n",cid_reserved,reservecid);
+ if(strlen(reservecid))
+ {
+ cid_reserved = atoi(reservecid);//cid_reservedµÄֵת»¯³É¶þ½øÖÆ£¬Ä³Î»Îª1´ú±ícidΪn(nΪµÚ¼¸Î»)ʱ±£Áô,ÀýÈçcid=1ºÍ3±£Áô£¬Ôòcid_reserved=00000101
+ }
+
+#if (APP_OS_TYPE == APP_OS_TOS)
+ cfg_get_item("version_mode", versionmode, sizeof(versionmode));
+ if(0 == strcmp(versionmode, "1"))
+ cid_reserved = 255;//15;//¶ÔÓÚоƬÈÏÖ¤·ÖÖ§£¬Ä¬ÈÏËùÓÐcid¶¼Ô¤Áô
+#endif
+
+ //¶ÔÓÚmodemËùÔںˣ¬cid×ÊÔ´¹ÜÀíÊý×éϱêÓëcid¹ØÁªÆðÀ´£¬±ãÓÚÎÊÌâ·ÖÎö
+ for(i=0;i<CID_MAX_NUM;i++)
+ {
+ if(CID_IDLE != CID_ARRAY[i].state)
+ {
+ softap_assert("");
+ }
+ memset(&CID_ARRAY[i], 0x00, sizeof(struct cid_resource_t));
+ CID_ARRAY[i].state = CID_IDLE;
+#ifdef HAVE_MODEM_IN_CORE
+ CID_ARRAY[i].c_id = i+1;
+ CID_ARRAY[i].reserved = (cid_reserved & (1<<i)); //reserved²»Îª0ʱ£¬±íʾΪרÓ㬲»²ÎÓ붯̬»ñÈ¡
+#endif
+ //CID_ARRAY[i].ref = 0;
+ }
+ syscall(__NR_set_cidstate,(unsigned char)cid_reserved);
+}
+//ÔÚpdpÈ¥¼¤»îʱÐèÒªÇå¿ÕÏà¹ØcidµÄ¹ÜÀíÐÅÏ¢
+void pdpinfo_reset(int cid)
+{
+ if(g_pdpinfo_mng[cid-1].pdpInfo != NULL)
+ {
+ pdp_deact_proc_for_module(g_pdpinfo_mng[cid-1].pdpInfo);
+ //g_pdpinfo_mng[cid-1].ipflag_down = g_pdpinfo_mng[cid-1].pdpInfo->act_info.ip46flag;
+ free(g_pdpinfo_mng[cid-1].pdpInfo);
+ g_pdpinfo_mng[cid-1].pdpInfo = NULL;
+ if((cid_reserved&(1<<(cid-1))) != 0 && g_pdpinfo_mng[cid-1].fwd_info.cgact_ok && g_pdpinfo_mng[cid-1].fwd_info.zgact_ok)
+ send_zconstat_auto_report(0, cid);
+ }
+
+ memset(&g_pdpinfo_mng[cid-1].fwd_info, 0x00, sizeof(FWD_PDP_INFO));
+
+ if(g_pdpinfo_mng[cid-1].ip6addr != NULL)
+ {
+ free(g_pdpinfo_mng[cid-1].ip6addr);
+ g_pdpinfo_mng[cid-1].ip6addr = NULL;
+ //g_pdpinfo_mng[cid-1].slaac_v6_inform = 0;
+ }
+
+}
+static void pdpinfo_init(int cid)
+{
+ if(g_pdpinfo_mng[cid-1].pdpInfo == NULL)
+ {
+ g_pdpinfo_mng[cid-1].pdpInfo = (struct pdp_active_info *)malloc(sizeof(struct pdp_active_info));
+ if(g_pdpinfo_mng[cid-1].pdpInfo == NULL){softap_assert("");}
+ memset(g_pdpinfo_mng[cid-1].pdpInfo, 0x00, sizeof(struct pdp_active_info));
+ g_pdpinfo_mng[cid-1].pdpInfo->pdp_type = 0;
+ }
+ g_pdpinfo_mng[cid-1].pdpInfo->c_id = cid;
+}
+
+struct pdp_active_info *get_pdpinfo_bycid(int cid)
+{
+ return g_pdpinfo_mng[cid-1].pdpInfo;
+}
+
+
+/*Ìø¹ýIPV6µÄǰ׺*/
+char * skip_first_half_ipv6(char * pstrIpv6)
+{
+ int i = 0;
+
+ s_pstrIpv6Addr = pstrIpv6;
+ for(i=0; i<4; i++)
+ {
+ s_pstrIpv6Addr = strchr(s_pstrIpv6Addr, ':');
+ if(NULL != s_pstrIpv6Addr)
+ {
+ s_pstrIpv6Addr++;
+ }
+ else
+ return NULL;
+ }
+ return s_pstrIpv6Addr;
+}
+
+/*½«»ñÈ¡µ½µÄIPv6µØÖ·´æ·ÅÔÚÈ«¾Ö±äÁ¿g_pdpinfo_mng[cid-1].ip6addrµ±ÖÐ;
+¶ÔÓÚmodemËùÔںˣ¬slaac»ñÈ¡µ½µØÖ·Ê±£¬ÒѾÍê³ÉÁËIPv6µØÖ·µÄ½âÎö£¬½«Ç°×ºÐÅÏ¢´æ·ÅÔÚNVµ±ÖУ»
+¶ÔÓÚ·ÇmodemËùÔںˣ¬Æäµ¥²¥IPv6µØÖ·ÊÇͨ¹ýzpdpactÖ÷¶¯Éϱ¨»òÕߺ˼äÏûÏ¢MSG_CMD_DATASWITCH_ON_REQ´«µÝ¹ýÀ´µÄ£¬Òò´Ë
+ÐèÒª¶ÔIPv6µØÖ·½øÐнâÎö£¬»ñȡǰ׺ÐÅÏ¢£¬²¢´æ·ÅÔÚNVµ±ÖС£
+
+ÔÚµ÷ÓÃpdp_act_proc½Ó¿Ú¼¤»îÍøÂç½Ó¿Úʱ£¬wan_ipv6.sh½Å±¾Öиù¾ÝNVÖÐÊÇ·ñÒѾ±£´æÇ°×ºÐÅÏ¢£¬
+À´È·¶¨ÊÇ·ñÐèÒªÆô¶¯slaacÈ¥»ñÈ¡IPv6ǰ׺ÐÅÏ¢£»
+*/
+static void save_unicast_ip6addr(int cid, char * unicast_ip6addr)
+{
+#ifndef HAVE_MODEM_IN_CORE
+ char nv_pswan[10] = {0};
+ char tmp_ipv6_prefix[IPV6ADDLEN_MAX] = {0};
+ char prefix_nv_cmd[100] = {0};
+
+ strncpy(tmp_ipv6_prefix, unicast_ip6addr,(int)(skip_first_half_ipv6(unicast_ip6addr)-unicast_ip6addr));
+ cfg_get_item("pswan", nv_pswan, sizeof(nv_pswan));
+
+ sprintf(prefix_nv_cmd, "%s%d_ipv6_prefix_info", nv_pswan,cid);
+ cfg_set(prefix_nv_cmd, tmp_ipv6_prefix);
+
+ sprintf(prefix_nv_cmd, "%s%d_ipv6_prefix_len", nv_pswan, cid);
+ cfg_set(prefix_nv_cmd, "64");
+
+ sprintf(prefix_nv_cmd, "%s%d_ipv6_gw", nv_pswan, cid);
+ cfg_set(prefix_nv_cmd,"");
+#endif
+ if(g_pdpinfo_mng[cid-1].ip6addr != NULL)
+ {
+ free(g_pdpinfo_mng[cid-1].ip6addr);
+ g_pdpinfo_mng[cid-1].ip6addr = NULL;
+ }
+
+ g_pdpinfo_mng[cid-1].ip6addr = malloc(IPV6ADDLEN_MAX);
+ memset(g_pdpinfo_mng[cid-1].ip6addr, 0, IPV6ADDLEN_MAX);
+ memcpy(g_pdpinfo_mng[cid-1].ip6addr, unicast_ip6addr, IPV6ADDLEN_MAX);
+}
+
+static void get_unicast_ip6addr(int cid)
+{
+ char nv_pswan[10] = {0};
+ char tmp_ipv6_prefix[IPV6ADDLEN_MAX] = {0};
+ char tmp_postfix[IPV6ADDLEN_MAX] = {0};
+ char nv_cmd[100] = {0};
+
+ cfg_get_item("pswan", nv_pswan, sizeof(nv_pswan));
+
+ sprintf(nv_cmd, "%s%d_ipv6_prefix_info", nv_pswan,cid);
+ cfg_get_item(nv_cmd, tmp_ipv6_prefix, sizeof(tmp_ipv6_prefix));
+
+ sprintf(nv_cmd, "%s%d_ipv6_interface_id",nv_pswan,cid);
+ cfg_get_item(nv_cmd, tmp_postfix, sizeof(tmp_postfix));
+
+ if(g_pdpinfo_mng[cid-1].ip6addr != NULL)
+ {
+ free(g_pdpinfo_mng[cid-1].ip6addr);
+ g_pdpinfo_mng[cid-1].ip6addr = NULL;
+ }
+
+ g_pdpinfo_mng[cid-1].ip6addr = malloc(IPV6ADDLEN_MAX);
+ memset(g_pdpinfo_mng[cid-1].ip6addr, 0, IPV6ADDLEN_MAX);
+ sprintf(g_pdpinfo_mng[cid-1].ip6addr, "%s%s", tmp_ipv6_prefix, tmp_postfix);
+}
+
+#if 0
+int check_slaac_inform(int cid)
+{
+ //Èôµ±Ç°slaacÕýÔÚ»ñÈ¡IPv6µØÖ·£¬Ôò¼ÌÐøµÈ´ý
+ if(V6ADDR_GETTING == g_pdpinfo_mng[cid-1].slaac_v6_inform)
+ {
+ return AT_WAIT_AUTO;
+ }
+ //Èç¹ûslaac»ñÈ¡µØÖ·Ê§°Ü£¬ÔòÖ±½ÓÏòPDP¼¤»î·¢ÆðÔ´Éϱ¨¼¤»îʧ°ÜÏûÏ¢
+ else if(V6ADDR_GET_FAILED == g_pdpinfo_mng[cid-1].slaac_v6_inform)
+ {
+ pdpinfo_reset(cid);
+ return AT_END;
+ }
+ return AT_CONTINUE;
+}
+#endif
+
+/*»ñÈ¡µ±Ç°µÚÒ»¸ö´¦ÓÚidle״̬µÄcidÊý×éϱí
+1¡¢ÓÃÓÚ²»²ÎÓëapn¹²Ïí»ñÈ¡¿ÕÏÐÊý×éϱ꣬µ±Ç°Çé¿öʱÐèÒªÈÏÖ¤µÄpdp¼¤»î£¬²»²ÎÓëapn¹²Ïí£¬µ¥¶ÀÕ¼ÓÃһ·cid;
+2¡¢ÓÃÓÚµ±Ç°pdp¼¤»î apnûÓб»¼¤»îʱ
+*/
+int get_idx_byidle(char flag,char *apn)
+{
+ int i = 0;
+ at_print(AT_ERR,"@@!!@@get_idx_byidle ims=%d,flag=%d,apn=%s\n",apn_is_ims,flag,apn);
+ for(i = 0; i < CID_MAX_NUM; i++)
+ {
+ if(cid_reserved != 255 && CID_ARRAY[i].reserved)//15
+ {
+ //¶ÔÓÚÔ¤ÁôµÄcid£¬²»²ÎÓ붯̬·ÖÅä NVΪ15±íÊ¾ÌØÊâ²úÆ·ÐÎ̬£¬cid¼ÈÔ¤Áô¸øÍⲿ£¬Ò²²ÎÓ붯̬·ÖÅä
+ continue;
+ }
+ if(i != def_attach_cid_index && syscall(__NR_get_cidstate,(unsigned char)(i+1)))
+ continue;
+ if(i == def_attach_cid_index)
+ {
+ if(at_strcmp(apn,"ims")==0 && apn_is_ims == 1 && CID_ARRAY[def_attach_cid_index].state == CID_IDLE)
+ {
+ return def_attach_cid_index;
+ }
+ if(at_strcmp(apn,"ims")!=0 && apn_is_ims == 1)
+ {
+ continue;
+ }
+ if(flag == 0)
+ {
+ continue;
+ }
+ }
+ if(CID_ARRAY[i].state == CID_IDLE)
+ {
+ return i;
+ }
+ }
+ if(apn_is_ims == 1 && CID_ARRAY[def_attach_cid_index].state == CID_IDLE)
+ {
+ apn_is_ims = 0;//Èç¹û³ýims°ó¶¨µÄcidÒѾûÓпÕÏÐCID£¬Ôò½â°ó²¢ÌṩʹÓÃ
+ at_print(AT_ERR,"@@!!@@get_idx_byidle ims_unbind index=%d\n",def_attach_cid_index);
+ return def_attach_cid_index;
+ }
+ //softap_assert("");
+ return -1;
+}
+
+//оƬÈÏÖ¤°æ±¾cp²àÑ¡Ôñ¿ÕÏÐcidÔÔò£ºÏÈÕÒ¿ÕÏеÄÇÒip_typeΪ¿Õ£¨¼´Ã»Óж¨Òå¹ýÉÏÏÂÎÄ£©£¬Èç¹û
+//ûÓÐÂú×ãÌõ¼þµÄÔòÖ±½Ó´ÓÍ·¿ªÊ¼ÕÒµÚÒ»¸ö¿ÕÏеÄcid
+int get_idx_byidle_for_renzhen()
+{
+ int i = 0;
+ for(i = 0; i < CID_MAX_NUM; i++)
+ {
+ if(CID_ARRAY[i].state == CID_IDLE && strlen(CID_ARRAY[i].ip_type) == 0)
+ {
+ return i;
+ }
+ }
+ return get_idx_byidle(1,"");
+}
+
+//ÓÃÓÚapn¹²Ïíʱ£¬Í¨¹ýapnºÍip type»ñÈ¡cid×ÊÔ´Êý×éϱê
+int get_idx_byapn(char *apn, char *ip_type, int *is_setapn, char flag)
+{
+ int i;
+ char versionmode[2] = {0};
+ cfg_get_item("version_mode", versionmode, sizeof(versionmode));
+
+ for(i = 0; i<CID_MAX_NUM; i++)
+ {
+ if(cid_reserved != 255 && CID_ARRAY[i].reserved)//15
+ {
+ //¶ÔÓÚÔ¤ÁôµÄcid£¬²»²ÎÓ붯̬·ÖÅä NVΪ15±íÊ¾ÌØÊâ²úÆ·ÐÎ̬£¬cid¼ÈÔ¤Áô¸øÍⲿ£¬Ò²²ÎÓ붯̬·ÖÅä
+ continue;
+ }
+ //Ö»Óв»ÈÏÖ¤µÄcid£¬apn²ÅÄܱ»¹²Ïí
+ if((0 == strcmp(apn, CID_ARRAY[i].apn)) && (0 == strcmp(ip_type, CID_ARRAY[i].ip_type)) && (NONE_AUTH == CID_ARRAY[i].auth_type))
+ {
+#if 0//ÐÒéÕ»ÒÑÖ§³Ö2-3GÏÂcidÓÃ5-8£¬Ö»Òª×ÜÊý²»³¬¹ý4
+ if(CID_ARRAY[i].state != CID_ACTIVE && i >= 4)
+ {
+ //´óÓÚ5µÄcidÔÚ䲦ºÅµÄ״̬²»Äܸ´Ó㬷ÀÖ¹2-3Gʱѡµ½Ò»Ö±²¦ºÅʧ°Ü
+ continue;
+ }
+#endif
+ if(is_setapn)
+ {
+ *is_setapn = 1;//cid_reserved=255ʱÉÏÏÂÎÄ¿ÉÄܱ»Ð޸쬻¹ÊÇÐèÒªÖØÐ¶¨Òå
+ }
+ return i;
+ }
+ }
+ if(is_setapn)
+ {
+ *is_setapn = 1;
+ }
+#ifdef HAVE_MODEM_IN_CORE
+ //оƬÈÏÖ¤°æ±¾ÌØÊâ´¦Àí
+ if(0 == strcmp(versionmode, "1"))
+ return get_idx_byidle_for_renzhen();
+ else
+ return get_idx_byidle(flag,apn);
+#else
+ return get_idx_byidle(flag,apn);
+#endif
+
+}
+//CP²àµÄcidÊÇidx+1 AP²àcidºÍidx²»¶ÔÓ¦£¬ÐèҪͨ¹ý´Ë½Ó¿Ú²éѯidx
+int get_idx_bycid(int c_id)
+{
+ int i = 0;
+ for(i = 0; i < CID_MAX_NUM; i++)
+ {
+ if(CID_ARRAY[i].c_id == c_id)
+ return i;
+ }
+ return -1;
+}
+
+/*
+ ÓÉÓÚzgipdnsÉϱ¨ÖÐipv6µØÖ·Ò»°ãʱ±¾µØÁ´Â·µØÖ·£¬¼´FE80::¿ªÍ·µÄµØÖ·£¬²»ÄÜÓÃÓÚÍâÍøÍ¨ÐÅ£¬Òò´Ë
+ ÐèҪͨ¹ýslaacÏòºËÐÄÍø»ñȡȫÇòΨһµ¥²¥ipv6µØÖ·£¬²¢´æÔÚg_pdpinfo_mng[c_id-1].ip6addrÖУ¬Òò´Ë
+ ÔÚ¹¹½¨zpdpactÉϱ¨/znetifupÉèÖõIJÎÊýʱ£¬ÐèҪʹÓÃg_pdpinfo_mng[c_id-1].ip6addr×÷ÎªÕæÊµipv6µØÖ·
+*/
+int build_ipdns_param(char *at_str, struct pdp_active_info *info)
+{
+ int offset = 0;
+ offset += sprintf(at_str+offset,"%d,",info->c_id);
+ switch(info->act_info.ip46flag)
+ {
+ case V4_VALID:
+ offset += sprintf(at_str+offset, "\"IP\",");
+ offset += sprintf(at_str+offset,"\"%s\",", info->act_info.ip);
+ offset += sprintf(at_str+offset,"\"%s\",", info->act_info.gateway);
+ offset += sprintf(at_str+offset,"\"%s\",", info->act_info.pri_dns);
+ offset += sprintf(at_str+offset,"\"%s\"", info->act_info.sec_dns);
+ break;
+ case V6_VALID:
+ offset += sprintf(at_str+offset, "\"IPV6\",");
+ offset += sprintf(at_str+offset,"\"%s\",", g_pdpinfo_mng[info->c_id-1].ip6addr);
+ offset += sprintf(at_str+offset,"\"%s\",", info->act_info.gateway6);
+ offset += sprintf(at_str+offset,"\"%s\",", info->act_info.pri_dns6);
+ offset += sprintf(at_str+offset,"\"%s\"", info->act_info.sec_dns6);
+ break;
+ case V46_VALID:
+ {
+ char ps_wan[NV_NAME_LEN] = {0};
+ char psv6_wan[NV_NAME_LEN] = {0};
+ char pswan_state[NV_NAME_LEN] = {0};
+
+ cfg_get_item("pswan", ps_wan, sizeof(ps_wan));
+
+ snprintf(psv6_wan,NV_NAME_LEN, "%s%d_ipv6_state", ps_wan, info->c_id);
+ cfg_get_item(psv6_wan, pswan_state, sizeof(pswan_state));
+ //Èç¹ûV6µØÖ·»ñȡʧ°Ü£¬ÔòÖ»Éϱ¨V4µØÖ·
+ if(strcmp(pswan_state,"dead") == 0)
+ {
+ offset += sprintf(at_str+offset, "\"IP\",");
+ offset += sprintf(at_str+offset,"\"%s\",", info->act_info.ip);
+ offset += sprintf(at_str+offset,"\"%s\",", info->act_info.gateway);
+ offset += sprintf(at_str+offset,"\"%s\",", info->act_info.pri_dns);
+ offset += sprintf(at_str+offset,"\"%s\"", info->act_info.sec_dns);
+ }
+ else
+ {
+ offset += sprintf(at_str+offset, "\"IPV4V6\",");
+ offset += sprintf(at_str+offset,"\"%s\",", info->act_info.ip);
+ offset += sprintf(at_str+offset,"\"%s\",", info->act_info.gateway);
+ offset += sprintf(at_str+offset,"\"%s\",", info->act_info.pri_dns);
+ offset += sprintf(at_str+offset,"\"%s\",", info->act_info.sec_dns);
+ offset += sprintf(at_str+offset,"\"%s\",", g_pdpinfo_mng[info->c_id-1].ip6addr);
+ offset += sprintf(at_str+offset,"\"%s\",", info->act_info.gateway6);
+ offset += sprintf(at_str+offset,"\"%s\",", info->act_info.pri_dns6);
+ offset += sprintf(at_str+offset,"\"%s\"", info->act_info.sec_dns6);
+ }
+ break;
+ }
+ default:
+ softap_assert("");
+ }
+ return offset;
+}
+#if !defined(HAVE_MODEM_IN_CORE) || defined(MULTI_CPU)
+static int parse_ipdns_param(char * at_paras)
+{
+ int cid = 0;
+ char ip_type[10] = {0};
+ char *p[2] = {&cid, ip_type};
+ struct pdp_active_info *pdpinfo = NULL;
+ struct netdev_act_info *act_info = NULL;
+
+ parse_param2("%d,%s",at_paras,p);
+
+ if(cid <= 0 || cid > CID_MAX_NUM)
+ {
+ softap_assert("");
+ return -1;
+ }
+ pdpinfo_init(cid);
+ pdpinfo = g_pdpinfo_mng[cid-1].pdpInfo;
+ act_info= &pdpinfo->act_info;
+
+ if(0 == strcmp("IP", ip_type))
+ {
+ char *p[6] = { &pdpinfo->c_id,
+ ip_type,
+ act_info->ip,
+ act_info->gateway,
+ act_info->pri_dns,
+ act_info->sec_dns,
+ };
+ act_info->ip46flag = V4_VALID;
+
+ parse_param2("%d,%s,%s,%s,%s,%s",at_paras,p);
+
+ }
+ else if(0 == strcmp("IPV6", ip_type))
+ {
+ char *p[6] = { &pdpinfo->c_id,
+ ip_type,
+ act_info->ip6,
+ act_info->gateway6,
+ act_info->pri_dns6,
+ act_info->sec_dns6,
+ };
+
+ act_info->ip46flag = V6_VALID;
+
+ parse_param2("%d,%s,%s,%s,%s,%s",at_paras,p);
+
+ save_unicast_ip6addr(cid, act_info->ip6);
+ }
+ else if(0 == strcmp("IPV4V6",ip_type))
+ {
+ char *p[10] = { &pdpinfo->c_id,
+ ip_type,
+ act_info->ip,
+ act_info->gateway,
+ act_info->pri_dns,
+ act_info->sec_dns,
+ act_info->ip6,
+ act_info->gateway6,
+ act_info->pri_dns6,
+ act_info->sec_dns6,
+ };
+ act_info->ip46flag = V46_VALID;
+ parse_param2("%d,%s,%s,%s,%s,%s,%s,%s,%s,%s",at_paras,p);
+ save_unicast_ip6addr(cid, act_info->ip6);
+ }
+ else
+ {
+
+ act_info->ip46flag = V4V6_INVALID;
+ softap_assert("");
+ }
+ return cid;
+}
+#endif
+char* get_param_by_symbol(char *at_param, char symbol, int num)
+{
+ int i = 0;
+ char * pstrStart = at_param;
+ char * pstrTemp = NULL;
+
+ for(i=0; i<num; i++)
+ {
+ pstrTemp = strchr(pstrStart, symbol);
+ if(NULL == pstrTemp)
+ {
+ return NULL;
+ }
+ pstrStart = pstrTemp + 1;;
+ }
+ return pstrStart;
+}
+
+
+/*zgpidnsÉϱ¨µÄx.x.x.x.x.x.x.x.x.x.x.x.x.x.x.xת³ÉÓÃðºÅµÄ±ê×¼IPV6µØÖ·xxxx:xxxx:xxxx:xxxx*/
+static void get_format_ipv6(char * pstrIpv6, char *s_strIpv6Addr, int v6AddrLen)
+{
+ int i = 0;
+ int iIpv6Item[16] = {0};
+ int flag = 0;
+
+ //at_print(AT_DEBUG,"IPV6 before change == %s\n", pstrIpv6);
+ sscanf(pstrIpv6, "%d.%d.%d.%d.%d.%d.%d.%d.%d.%d.%d.%d.%d.%d.%d.%d",
+ iIpv6Item, iIpv6Item+1, iIpv6Item+2, iIpv6Item+3,
+ iIpv6Item+4, iIpv6Item+5, iIpv6Item+6, iIpv6Item+7,
+ iIpv6Item+8, iIpv6Item+9, iIpv6Item+10, iIpv6Item+11,
+ iIpv6Item+12, iIpv6Item+13, iIpv6Item+14, iIpv6Item+15);
+
+ memset(s_strIpv6Addr, 0, v6AddrLen);
+ for(i=0; i<=15; i++)
+ {
+ if(iIpv6Item[i] != 0)
+ flag++;
+ snprintf(s_strIpv6Addr+strlen(s_strIpv6Addr), v6AddrLen-strlen(s_strIpv6Addr), "%02x", iIpv6Item[i]);
+ if((i%2==1) && (i<15))
+ {
+ snprintf(s_strIpv6Addr+strlen(s_strIpv6Addr), v6AddrLen-strlen(s_strIpv6Addr), ":");
+ }
+ }
+ if(flag == 0){
+ memset(s_strIpv6Addr, 0, v6AddrLen);
+ at_print(AT_ERR,"IPV6 %s is ::\n", s_strIpv6Addr);
+ }
+ //at_print(AT_DEBUG,"IPV6 after change == %s\n", s_strIpv6Addr);
+}
+
+
+//×é³ÉzpdpactÏìÓ¦ATÉϱ¨£¬Èç¹ûÊǹ²ÏíµÄÔòÖ±½ÓÉϱ¨£¬·ñÔò´ý¼¤»îÍê³ÉºóÉϱ¨
+char * zpdpact_ind_build(struct pdp_active_info *info)
+{
+ char *p_ipdns = malloc(512);
+ char *at_str = NULL;
+ if(NULL == p_ipdns) {
+ softap_assert("");
+ return NULL;
+ }
+
+ memset(p_ipdns, 0x00, 512);
+ build_ipdns_param(p_ipdns, info);
+ at_str = at_query_result_build("ZPDPACT", p_ipdns);
+ free(p_ipdns);
+
+ if(NULL == at_str) softap_assert("");
+ at_print(AT_ERR,"zpdpact inform ipdns, at_str is %s\n",at_str);
+ return at_str;
+}
+
+int get_ppp_cid(int modid, int *p_pppcid)
+{
+ if(modid == MODULE_ID_PPPD)
+ {
+ int idx = get_idx_byidle(0,"");
+ if(idx < 0)
+ softap_assert("");
+
+ *p_pppcid = ppp_cid;
+ }
+ return 1;
+}
+
+void get_ppp_apn(struct pdp_act_req *p_setInfo)
+{
+ int idx = get_idx_bycid(p_setInfo->ppp_cid);
+ if(idx < 0)
+ return;
+ char ppp_pdp_type [8] = {0};
+ cfg_get_item("ppp_pdp_type", ppp_pdp_type, sizeof(ppp_pdp_type));
+ strncpy(p_setInfo->comm_info.apn, CID_ARRAY[idx].apn, sizeof(p_setInfo->comm_info.apn)-1);
+ if(strcmp(ppp_pdp_type,"IP") == 0 || strcmp(ppp_pdp_type,"IPV6") == 0 || strcmp(ppp_pdp_type,"IPV4V6") == 0)
+ strcpy(p_setInfo->comm_info.ip_type, ppp_pdp_type);
+ else
+ strcpy(p_setInfo->comm_info.ip_type, "IP");//Õë¶ÔÊ״請úÉϵçûÓÐÉèÖÃapnµÄÇé¿ö£¬¸øip_type¸³³õʼֵ
+}
+
+/*Éú³Épdp¼¤»îµÄatÃüÁmodemËùÔÚºËÖ±½ÓʹÓÃcgact¡¢·ÇmodemËùÔÚºËʹÓÃzpdpact;
+ÓÉÓÚµ±Ç°pdp¼¤»îÇëÇó´¦ÀíÁ÷³ÌÖУ¬Ê×ÏÈ·¢ËÍÁËcgact=0£¬cidÈ¥¼¤»î£¬Òò´Ë¶ÔÓÚCID_ARRAY[idx]µÄ״̬£¬
+±ØÐëÔÚpdp¼¤»îatÃüÁîÏ·¢Ê±£¬ÉèÖÃΪACTIVING£¬²ÅÄܱ£Ö¤pdp¼¤»î״̬ºÍCID_ARRAY״̬һÖÂ
+*/
+char * build_pdpact_cmd(PDP_PRIVATE_INFO *private_info, struct pdp_act_req *p_setInfo)
+{
+ int idx = private_info->index;
+ char *at_str = NULL;
+
+#ifdef HAVE_MODEM_IN_CORE
+ int cid = private_info->c_id;
+ at_print(AT_ERR,"goto build cgact active cmd!!!!!!!!!!!!!!!!\n");
+ at_str = malloc(32);
+ if(at_str == NULL){
+ softap_assert("");
+ return NULL;
+ }
+ memset(at_str, 0, 32);
+ sprintf(at_str, "at+cgact=1,%d\r\n", cid);
+#else
+ int offset = 0;
+ at_print(AT_ERR,"goto build zpdpact cmd!!!!!!!!!!!!!!!!\n");
+ at_str = malloc(PDP_CMD_LEN);
+ if(at_str == NULL){softap_assert("");}
+ memset(at_str, 0, PDP_CMD_LEN);
+
+ offset += sprintf(at_str+offset,"AT+ZPDPACT=%d,\"%s\",\"%s\"",p_setInfo->ext_cid,p_setInfo->comm_info.ip_type, p_setInfo->comm_info.apn);
+ offset += sprintf(at_str+offset,",%d,%d,%d",p_setInfo->volte_param1,p_setInfo->volte_param2,p_setInfo->volte_param3);
+ offset += sprintf(at_str+offset,",%d,\"%s\",\"%s\"",p_setInfo->comm_info.auth_type, p_setInfo->comm_info.username, p_setInfo->comm_info.password);
+ offset += sprintf(at_str+offset,",\"%s\"",p_setInfo->comm_info.challenge);
+ offset += sprintf(at_str+offset,",%d",p_setInfo->ppp_cid);
+ offset += sprintf(at_str+offset,",%d\r\n",p_setInfo->default_flag);
+#endif
+
+ //¼Ç¼±¾´Îpdp¼¤»î״̬Ϊ¼¤»î
+ private_info->pdp_state = 1;
+ CID_ARRAY[idx].state = CID_ACTIVING;
+ return at_str;
+}
+
+//ÅäÖÃĬÈÏAPN£¬iptypeÒ²ÐèÒª¿¼ÂÇ
+void set_default_apn(const char *apn)
+{
+ memset(g_defcid_mng.default_apn, 0x00, sizeof(g_defcid_mng.default_apn));
+ strncpy(g_defcid_mng.default_apn, apn, sizeof(g_defcid_mng.default_apn)-1);
+ cfg_set("default_apn", g_defcid_mng.default_apn);
+ at_print(AT_ERR, "default apn is changed to %s\n", apn);
+}
+//¸ù¾Ýppp_statusÉèÖÃÏà¹Ø×´Ì¬£¬ÌáÈ¡³ÉÒ»¸ö½Ó¿ÚÉèÖ㬱ãÓÚͳһ¹ÜÀíMMI/WEBUIÏÔʾ״̬µÄ
+int set_pppstatus(char * ppp_status)
+{
+ int iConnectStatus = 0;
+ if(0 == strcmp(ppp_status, PPP_DISCONNECTED))
+ {
+ iConnectStatus = 0;
+ }
+ else if(0 == strcmp(ppp_status, PPP_CONNECTED))
+ {
+ iConnectStatus = 1;
+ }
+ else if(0 == strcmp(ppp_status, PPP_CONNECTING))
+ {
+ iConnectStatus = 2;
+ }
+ else if(0 == strcmp(ppp_status, PPP_DISCONNECTING))
+ {
+ iConnectStatus = 3;
+ }
+
+ cfg_set(NV_PPP_STATUS,ppp_status);
+ ipc_send_message(MODULE_ID_AT_CTL,MODULE_ID_MMI,MSG_CMD_CHANNEL_CONNECT_STATUS, sizeof(iConnectStatus), (UCHAR *)&iConnectStatus,0);
+
+ return 0;
+}
+
+void pdp_reconnect_check()
+{
+ char auto_reconnect [20] = {0};
+ cfg_get_item("auto_reconnect", auto_reconnect, sizeof(auto_reconnect));
+ /*Ö»ÓÐÄ£¿éID²»ÊÇatͨµÀºÅ£¬²Å±íÃ÷ĬÈÏapn pdp¼¤»îiÇëÇóµÄ·¢Æð·½ÔÚ±¾ºË£¬¶ÔÓÚÍâºË·¢ÆðµÄ
+ ĬÈÏapnµÄ¼¤»îÇëÇó£¬ÓÉÍâºËµÄat_ctl¿ØÖÆÖØÁ¬²Ù×÷
+ */
+ if((0 == check_is_fd(g_defcid_mng.modid)) && (0 == strcmp("1", auto_reconnect)))
+ {
+ //Æô¶¯¶¨Ê±Æ÷£¬·¢ÆðÖØÐ²¦ºÅ
+ at_timeout_start_pdpreconn_timer();
+ }
+ else
+ {
+ if(g_defcid_mng.set_info)
+ {
+ free(g_defcid_mng.set_info);
+ g_defcid_mng.set_info = NULL;
+ }
+ g_defcid_mng.modid = 0;
+ }
+}
+
+void send_zconstat_auto_report(int state,int cid)
+{
+#ifdef HAVE_MODEM_IN_CORE
+ char *at_str = malloc(PDP_CMD_LEN);
+ if(at_str == NULL){
+ return;
+ }
+ memset(at_str, 0, PDP_CMD_LEN);
+ //if(at_str == NULL){softap_assert("");}//klocwork
+ sprintf(at_str, "\r\n+ZCONSTAT: %d,%d\r\n", state, cid);
+ at_context_write_by_pos(FAR_PS, at_str);
+ free(at_str);
+#endif
+}
+
+#ifdef HAVE_MODEM_IN_CORE //ÔÚ±¾ºËÖк¬ÓÐmodem
+//ÊÇ·ñÐèÒª¿¼ÂÇÇå³ýĬÈÏapn»úÖÆ
+/*int save_default_apn(int at_fd, char *at_paras, void **res_msg, int *res_msglen)
+{
+ char *at_str = NULL;
+ char apn[APN_MAX_LEN] = {0};
+ char *p[1] = {apn};
+
+ if(strlen(at_paras) >= APN_MAX_LEN)
+ {
+ softap_assert("");
+ }
+ parse_param2("%s",at_paras, p);
+ set_default_apn(apn);
+
+ at_str = at_ok_build();
+ if(NULL == at_str) softap_assert("malloc failed for ok cmd");
+ *res_msg = at_str;
+ *res_msglen = strlen(at_str);
+
+ return AT_END;
+}*/
+
+//zgact²éѯ£¬µ±Ç°Ö»Ö§³Ö²é·ÇÔ¤ÁôµÄcid״̬
+int zgact_query_func(int at_fd, char *at_paras,void ** res_msg, int *res_msglen)
+{
+ int i = 0;
+ char *at_str = malloc(PDP_CMD_LEN);
+ if(at_str == NULL){
+ softap_assert("");
+ return AT_END;
+ }
+ memset(at_str, 0, PDP_CMD_LEN);
+
+ for(;i<CID_MAX_NUM;i++)
+ {
+ if((cid_reserved&(1<<(i))) != 0)
+ {
+ if(g_pdpinfo_mng[i].fwd_info.cgact_ok && g_pdpinfo_mng[i].fwd_info.zgact_ok && g_pdpinfo_mng[i].pdpInfo)
+ {
+ sprintf(at_str+strlen(at_str), "\r\n+ZGACT:%d,1\r\n", i+1);
+ }
+ else
+ {
+ sprintf(at_str+strlen(at_str), "\r\n+ZGACT:%d,0\r\n", i+1);
+ }
+ }
+ }
+ strcpy(at_str+strlen(at_str), "\r\nOK\r\n");
+ *res_msg = at_str;
+ *res_msglen = strlen(at_str);
+ return AT_END;
+}
+
+#if 0
+//modemËùÔں˵Äslaac IPv6µØÖ·»ñÈ¡½á¹ûµÄÉϱ¨ÏûÏ¢
+char* v6addrind_act_func(void *msg,struct at_context *context)
+{
+ MSG_BUF *p_msg = (MSG_BUF*)msg;
+ V6ADDR_INFORM *info = (V6ADDR_INFORM *)p_msg->aucDataBuf;
+ int cid = info->cid;
+
+ //˵Ã÷¹ýÔÚipv6µ¥²¥µØÖ·Éϱ¨¹ý³ÌÖУ¬ÒѾ·¢ÉúÁËÈ¥¼¤»î
+ if(0 == g_pdpinfo_mng[cid-1].is_acted)
+ return NULL;
+
+ if(info->result== 0)
+ {
+ at_print(AT_ERR,"slaac failed to get ipv6 addr!\n");
+ g_pdpinfo_mng[cid-1].slaac_v6_inform=V6ADDR_GET_FAILED;
+ }
+ else
+ {
+ at_print(AT_ERR,"v6addrind_act_func: slaac success to get ipv6 addr : %s!\n", info->v6_addr);
+ save_unicast_ip6addr(cid, info->v6_addr);
+ g_pdpinfo_mng[cid-1].slaac_v6_inform=V6ADDR_GET_SUCCESS;
+ }
+
+ return NULL;
+
+}
+#endif
+
+extern int check_linkup_state(int cid);
+//zte_mainctrl½Å±¾Ö´ÐÐÍê³É
+char* linkup_act_func(void *msg,struct at_context *context)
+{
+ MSG_BUF *p_msg = (MSG_BUF*)msg;
+ TScriptMSG *scriptmsg = (TScriptMSG*)p_msg->aucDataBuf;
+ int cid = scriptmsg->cid;
+ if(cid >0 && cid <= CID_MAX_NUM)
+ {
+
+ if(g_pdpinfo_mng[cid-1].ipflag_down == g_pdpinfo_mng[cid-1].linkdown_state)
+ g_pdpinfo_mng[cid-1].linkup_state |= scriptmsg->iptype;
+ at_print(AT_ERR,"$$$$$linkup_act_func: iptype=%d, linkup_state=%d!\n",scriptmsg->iptype, g_pdpinfo_mng[cid-1].linkup_state);
+ CID_ARRAY[cid-1].ref = 0;
+ if(check_linkup_state(cid) == AT_END){
+ ipc_send_message(MODULE_ID_AT_CTL, MODULE_ID_AT_CTL, ATCTL_DELAY_TIMEOUT_MSG, 0, NULL, IPC_NOWAIT);
+ }
+ }
+ return NULL;
+}
+
+char* linkdown_act_func(void *msg,struct at_context *context)
+{
+ MSG_BUF *p_msg = (MSG_BUF*)msg;
+ TScriptMSG *scriptmsg = (TScriptMSG*)p_msg->aucDataBuf;
+ int cid = scriptmsg->cid;
+ if(cid >0 && cid <= CID_MAX_NUM)
+ {
+ g_pdpinfo_mng[cid-1].linkdown_state |= scriptmsg->iptype;
+ g_pdpinfo_mng[cid-1].linkup_state = V4V6_INVALID;
+ at_print(AT_ERR,"$$$$$linkdown_act_func: iptype=%d, linkdown_state=%d!\n",scriptmsg->iptype, g_pdpinfo_mng[cid-1].linkdown_state);
+ }
+ return NULL;
+}
+
+
+#endif
+
+int check_linkup_state(int cid)
+{
+ //ÉÏ´ÎÈ¥¼¤»îÁ÷³Ì»¹Î´×ßÍê
+ if(g_pdpinfo_mng[cid-1].ipflag_down != g_pdpinfo_mng[cid-1].linkdown_state)
+ {
+ return AT_WAIT_AUTO;
+ }
+ //Èôµ±Ç°ÕýÔÚÖ´Ðнű¾£¬Ôò¼ÌÐøµÈ´ý
+ //if(g_pdpinfo_mng[cid-1].ipflag != g_pdpinfo_mng[cid-1].linkup_state)
+ if((g_pdpinfo_mng[cid-1].ipflag & g_pdpinfo_mng[cid-1].linkup_state) != g_pdpinfo_mng[cid-1].ipflag)
+ {
+ return AT_WAIT_AUTO;
+ }
+ //Èç¹ûnet½Å±¾Ö´ÐÐÍê³É£¬ÔòÖ±½ÓÏòPDP¼¤»î·¢ÆðÔ´Éϱ¨¼¤»îʧ°ÜÏûÏ¢
+ else
+ {
+ return AT_END;
+ }
+}
+
+int check_linkdown_state(int cid)
+{
+ //Èôµ±Ç°ÕýÔÚÖ´Ðнű¾£¬Ôò¼ÌÐøµÈ´ý
+ if(g_pdpinfo_mng[cid-1].ipflag_down != g_pdpinfo_mng[cid-1].linkdown_state)
+ {
+ return AT_WAIT_AUTO;
+ }
+ //Èç¹ûnet½Å±¾Ö´ÐÐÍê³É£¬ÔòÖ±½ÓÏòPDP¼¤»î·¢ÆðÔ´Éϱ¨¼¤»îʧ°ÜÏûÏ¢
+ else
+ {
+ return AT_END;
+ }
+}
+
+
+char *get_appointed_chr(char *at_str, char ch, int times)
+{
+ int i_times = 0;
+ char *pstrCur = at_str;
+ for(;*pstrCur != '\0';pstrCur++)
+ {
+ if(i_times < times)
+ {
+ pstrCur = strchr(pstrCur, ch);
+ if(pstrCur == NULL)
+ break;
+ i_times++;
+ }
+ else
+ break;
+ }
+ if(i_times < times)
+ return NULL;
+ else
+ return pstrCur;
+}
+
+//cgev´¦Àí£¬¼à¿Øµ±Ç°¸÷CIDµÄ¼¤»î״̬£¬È¥¼¤»îʱ¶Ï¿ªÍø¿Ú£¬Çå³ý¼¤»î״̬£¬Í¨ÖªBL£¬ºóÐøÐèÔö¼ÓרÓóÐÔØÖ§³Ö
+int cgev_auto_act(char *at_paras ,int is_query_report)
+{
+ int c_id = 0;
+ char *strtemp = NULL;
+ if(strstr(at_paras, "PDN ACT") != NULL)
+ {
+ strtemp = get_appointed_chr(at_paras, ' ', 3);
+ if(strtemp == NULL)
+ return AT_END;
+ c_id = atoi(strtemp);
+ if(c_id <= 0 || c_id > CID_MAX_NUM)
+ return AT_END;
+ g_pdpinfo_mng[c_id-1].cgev_inform = 1;
+
+ }
+ else if(strstr(at_paras, "PDN DEACT") != NULL)
+ {
+ int idx = 0;
+ int is_normal_cid = 0;
+ strtemp = get_appointed_chr(at_paras, ' ', 3);
+ if(strtemp == NULL)
+ return AT_END;
+ c_id = atoi(strtemp);
+ syscall(__NR_set_pdp_state,(unsigned char)c_id, 0);
+ if(c_id <= 0 || c_id > CID_MAX_NUM)
+ return AT_END;
+ g_pdpinfo_mng[c_id-1].cgev_inform = 0;
+
+ pdpinfo_reset(c_id);
+
+ /*1¡¢·Ç±¾ºË·¢ÆðµÄpdp¼¤»î£¬²»Óô¦Àí
+ */
+ idx = get_idx_bycid(c_id);
+
+ if(idx < 0)
+ return AT_END;
+
+ /*
+ CID_IDLE: 1¡¢Ä¬ÈϳÐÔØÃ»ÓÐÓ¦Ó÷¢Æðpdp¼¤»î£¬Òò´Ë²»Óô¦Àí£»2¡¢±¾ºË·¢ÆðµÄpdpÈ¥¼¤»î£¬ok±ÈcgevÏÈÉϱ¨£¬pdpÈ¥¼¤»îÁ÷³ÌÒѾÍê³É
+ CID_ACTIVING: µ±Ç°ÕýÔÚ¼¤»î£¬ÉèÖóÉIDLE״̬£¬ÓÃÓÚcgact ok´¦Àíº¯ÊýÖÐÅжϣ¬ÔڵȴýipdnsµÄ¹ý³ÌÖУ¬ÒѾÒѾ·¢Éú¹ýÈ¥¼¤»î
+ CID_DEACTIVING: µ±Ç°ÕýÔÚÈ¥¼¤»î£¬´ËÊ±Íø²àÖ÷¶¯È¥¼¤»îµÄ¿ÉÄÜÐÔ¼¸ºõΪ0£¬ºöÂÔ²»¿¼ÂÇ£¬¿ÉÒÔÈÏΪÊÇÓÉÓÚÖ÷¶¯·¢ÆðPDP¼¤»îÒýÆðµÄÉϱ¨
+ CID_ACTIVE: ±íÃ÷µ±Ç°CGEVÊÇÍø²àÖ÷¶¯È¥¼¤»î£¬»òÕßat+cfun²Ù×÷µ¼ÖµÄ
+ */
+ if(CID_ARRAY[idx].state == CID_ACTIVE)
+ {
+ CID_ARRAY[idx].state = CID_IDLE;
+ //CID_ARRAY[idx].ref = 0;
+
+ if(c_id == ppp_cid)
+ {
+ //Çå³ýppp¼¤»îÐÅÏ¢
+ ppp_cid = 0;
+ cfg_set("ppp_cid","");
+ /*¶ÔÓÚÍø²àÖ÷¶¯È¥¼¤»î£¬ÉèÖÃpppµÄpdp¼¤»î״̬£¬Í¨Öªppp·¢Æðlcp terminateÇëÇó£¬ÐÉÌÍê³Éºó£¬
+ ֪ͨat_ctl·¢Æðppp¿ìËÙ¶Ï¿ªÁ¬½Ó*/
+ cfg_set("ppp_pdpstate", "dead");
+ }
+ else if(g_defcid_mng.cid == c_id)
+ {
+ at_timeout_reset_pdpreconn_time();
+ pdp_reconnect_check();
+ g_defcid_mng.cid = 0;
+ g_defcid_mng.activing_cid = 0;
+ set_pppstatus(PPP_DISCONNECTED);
+ }
+#ifdef _USE_BL
+ //ÓÉÓÚBLÐèÒª´¥·¢À©Õ¹at¸øAP,½øÐÐpdpÈ¥¼¤»î£¬Èç¹ûbl·¢ÆðµÄpdpÈ¥¼¤»î£¬Ò²Éϱ¨¸ÃÏûÏ¢µÄ»°
+ //BLÊÕµ½¸ÃÏûÏ¢µÄ´¦ÀíÁ÷³ÌÖУ¬»á½«¼Ç¼µÄcidÇå¿Õ£¬µ¼Ö´¥·¢À©Õ¹atʱ£¬À©Õ¹atËùЯ´øµÄcidΪ0
+ ipc_send_message(MODULE_ID_AT_CTL, MODULE_ID_BL, MSG_CMD_PDP_DEACT_IND, sizeof(int), &c_id, 0);
+#endif
+//#ifdef GUODIAN
+ if(g_customer_type == CUSTOMER_GUODIAN || g_customer_type == CUSTOMER_NANDIAN)
+ {
+ //¹úµç±ê×¼ÒªÇóPDPÈ¥¼¤»îʱÖ÷¶¯Éϱ¨
+ send_cgev_deact_info(c_id);
+ }
+//#endif
+ }
+ else if(CID_ARRAY[idx].state == CID_ACTIVING)
+ {
+ //µ±Ç°ÕýÔÚ¼¤»î£¬ÉèÖóÉIDLE״̬£¬ÓÃÓÚcgact ok´¦Àíº¯ÊýÖÐÅжϣ¬ÔڵȴýipdnsµÄ¹ý³ÌÖУ¬ÒѾÒѾ·¢Éú¹ýÈ¥¼¤»î
+ CID_ARRAY[idx].state = CID_IDLE;
+ }
+ CID_ARRAY[idx].ref = 0;//¼¤»î¹ý³ÌÖÐÊÕµ½È¥¼¤»îÖ÷¶¯Éϱ¨±£»¤
+ }
+ else if(strstr(at_paras, "DEACT") != NULL)
+ {
+ //¶þ´ÎרÓóÐÔØÈ¥¼¤»îºó£¬½«¶þ´ÎcidµÄÐÅÏ¢Çå³ý
+ int p_cid = 0, cid = 0, event_type = -1;
+ strtemp = get_appointed_chr(at_paras, ' ', 2);
+ if(strtemp == NULL)
+ return AT_END;
+ void *p[3] = {&p_cid, &cid,&event_type};
+ at_print(AT_DEBUG,"creg_auto_act strtemp = %s, p_cid = %d, cid = %d!\n",strtemp, p_cid, cid);
+ parse_param2("%d,%d,%d", strtemp, p);
+ syscall(__NR_set_pdp_state,(unsigned char)c_id, 0);
+ if(cid > 0 && cid <= CID_MAX_NUM && g_pdpinfo_mng[cid-1].pdpInfo != NULL)
+ {
+ int idx = 0;
+ pdpinfo_reset(cid);
+ idx = get_idx_bycid(cid);
+ if(idx >= 0 && idx < CID_MAX_NUM)
+ {
+ CID_ARRAY[idx].state = CID_IDLE;
+ CID_ARRAY[idx].ref = 0;//¼¤»î¹ý³ÌÖÐÊÕµ½È¥¼¤»îÖ÷¶¯Éϱ¨±£»¤
+ }
+ }
+ }
+ return AT_END;
+}
+//²¦ºÅʧ°Ü´¦Àí£¬ÔÚ²¦ºÅµÄ¸÷»·½ÚÖÐÊÕµ½±¨´í£¬Çå³ýËùÓеÄ״̬ÐÅÏ¢£¬ÏûÏ¢·µ»Ø´íÎóÏûÏ¢£¬Í¨µÀ·µ»Øerror
+void pdpact_failed_proc(char * at_paras, struct at_context *context, int idx, void **next_req, int * next_len)
+{
+ PDP_PRIVATE_INFO *private_info = (PDP_PRIVATE_INFO *)context->app_param;
+
+ at_print(AT_ERR, "pdpact_failed_proc: source is %x, idx is %d, pdp_type is %d\n", context->source, idx, private_info->pdp_type);
+
+ if(idx < 0 || idx >= CID_MAX_NUM)
+ {
+ at_print(AT_ERR, "idx (%d) out of[0, CID_MAX_NUM)\n", idx);
+ return ;
+ }
+ //pdp¼¤»îʧ°Üºó£¬½«cid×ÊÔ´ÉèÖÃΪ¿ÕÏÐ״̬
+ CID_ARRAY[idx].state = CID_IDLE;
+
+ /*//Êͷű£´æµÄpdp¼¤»îÐÅÏ¢
+ if(private_info->pdpActInfo)
+ {
+ free(private_info->pdpActInfo);
+ private_info->pdpActInfo = NULL;
+ }*/
+ if(g_defcid_mng.activing_cid == idx + 1)
+ {
+ g_defcid_mng.activing_cid = 0;
+ }
+ if(private_info->pdp_type == PDP_NORMAL)
+ {
+ if(0 == check_is_fd(context->source))
+ {
+ set_pppstatus(PPP_DISCONNECTED);
+ }
+ /*PDP²¦ºÅʧ°Üºó£¬¸ù¾Ýpdp¼¤»îµÄÇëÇóÄ£¿éÒÔ¼°auto_reconnectµÄnvÖµ£¬È·¶¨ÊÇ·ñÖØÐ·¢Æð²¦ºÅ
+ */
+ pdp_reconnect_check();
+ }
+ {
+
+ AT_PDP_ACT_RSP_INFO *rsp = malloc(sizeof(AT_PDP_ACT_RSP_INFO));
+ if(rsp == NULL)
+ return;
+ memset(rsp, 0x00, sizeof(AT_PDP_ACT_RSP_INFO));
+ rsp->result = AT_RSP_ERR;
+ if(at_paras)
+ {
+ rsp->errcode = atoi(at_paras);
+ }
+ *next_req = rsp;
+ *next_len = sizeof(AT_PDP_ACT_RSP_INFO);
+ }
+
+}
+void pdpact_success_proc(int cid, int pdp_type, struct at_context* context, void **next_req, int *next_len)
+//void pdpact_success_proc(int cid, int pdp_type, struct at_context* context)
+{
+ int idx = get_idx_bycid(cid);
+
+ at_print(AT_ERR, "pdpact_succes_proc: source is %x, idx is %d, cid is %d, pdp_type is %d\n", context->source, idx, cid, pdp_type);
+ if(idx < 0)
+ return;
+ CID_ARRAY[idx].state = CID_ACTIVE;
+
+ /*Ϊ¼Ó¿ìmodem¿ª»úÁªÍøÊ±¼ä£¬ÔÚpdp¼¤»î֮ǰ£¬²»³õʼ»¯smsºÍpbÓ¦Óã¬pdp¼¤»î³É¹¦ºóÖ±½Ó·¢ÏûÏ¢
+ ¸øsmsºÍpbÓ¦ÓÃ֪ͨ½øÐгõʼ»¯£¬²¢ÇÒɾ³ý¶¨Ê±Æ÷*/
+ at_print(AT_NORMAL,"3.sms_pb init flag: %d\n", g_smspb_init);
+ pbsms_init_msg_proc();
+ //ÉèÖÃpdp_normal¼¤»îÀàÐ͵Äcid£¬ÔÚap²àÓÃÓÚwebui¶Ï¿ªÁ¬½ÓʱʹÓã¬ÔÚcp²àÓÃÓÚ·ÓÉÑ¡Ôñ£¬¼´¸Ãcid¼¤»îµÄÍø¿Úµ±×öĬÈÏ·ÓÉ
+ if(pdp_type == PDP_NORMAL)
+ {
+ if(0 == g_defcid_mng.cid)
+ {
+ g_defcid_mng.cid = CID_ARRAY[idx].c_id;
+ }
+ else
+ {
+ //¶ÔÓÚpdp_normalÀàÐÍpdp¼¤»î£¬Ò»¸öcpuºËÄÚ½öÔÊÐíÒ»¸öapn·¢Æð£¬pdp_normalµÄµ±Ç°×÷ÓÃ
+ //ΪÉèÖÃĬÈÏ·ÓɺÍnatת»»£¬²»ÔÊÐí³öÏÖ¶à¸öpdp_normal,·ñÔò»áÒýÆðĬÈÏ·ÓÉ»ìÂÒ
+ if(g_defcid_mng.cid != CID_ARRAY[idx].c_id){softap_assert("");}
+ }
+ //½«×Ô¶¯Öز¥auto_reconnectÉèÖÃΪ1£¬µ±Íø²àÖ÷¶¯È¥¼¤»îʱ£¬×Ô¶¯pdpÖØ²¥
+ //if(context->source > 0)
+ if(0 == check_is_fd(context->source))
+ {
+ set_pppstatus(PPP_CONNECTED);
+ cfg_set("auto_reconnect", "1");
+ }
+ }
+ else if(pdp_type == PDP_PPP)
+ {
+ //±£´æpppÓ¦ÓÃʹÓõÄcid£¬ÓÃÓÚcgevÉϱ¨µÄ´¦Àí
+ if(is_ppp_running()){
+ char temp[2] = {0};
+ ppp_cid = CID_ARRAY[idx].c_id;
+ snprintf(temp,2, "%d", ppp_cid);
+ cfg_set("ppp_cid",temp);
+ if(g_customer_type) //ÁªÇ¿°æ±¾ÌØÊâ¶¨ÖÆ£¬ppp²¦ºÅ³É¹¦ºóÐèҪ֪ͨmmi
+ set_pppstatus(PPP_CONNECTED);
+ }else
+ pdpinfo_reset(CID_ARRAY[idx].c_id);
+ }
+
+ {
+ AT_PDP_ACT_RSP_INFO *rsp = malloc(sizeof(AT_PDP_ACT_RSP_INFO));
+ if(rsp == NULL){
+ softap_assert("malloc failed");
+ return;
+ }
+ rsp->result = AT_RSP_OK;
+ rsp->cid = cid;
+ *next_req = rsp;
+ *next_len = sizeof(AT_PDP_ACT_RSP_INFO);
+
+ }
+
+}
+
+void pdpdeact_success_proc(int cid, struct at_context* context, void ** next_req, int *next_len)
+{
+ int idx = get_idx_bycid(cid);
+ if(idx < 0)
+ return;
+ CID_ARRAY[idx].state = CID_IDLE;
+
+ at_print(AT_ERR,"pdpdeact_success_proc:context->source = %x, cid is %d\n",context->source, cid);
+
+ //pdpÈ¥¼¤»îÖ®ºó£¬Çå¿Õpdp_normalÀàÐ͵Äcid
+ if(cid == g_defcid_mng.cid)
+ {
+ if(0 == check_is_fd(context->source))
+ {
+ set_pppstatus(PPP_DISCONNECTED);
+ }
+ g_defcid_mng.cid = 0;
+ g_defcid_mng.activing_cid = 0;
+ }
+
+ {
+ AT_PDP_DEACT_RSP_INFO *rsp = malloc(sizeof(AT_PDP_DEACT_RSP_INFO));
+ if(rsp == NULL)
+ return;
+ rsp->result = AT_RSP_OK;
+ *next_req = rsp;
+ *next_len = sizeof(AT_PDP_DEACT_RSP_INFO);
+ }
+
+}
+
+//¼¤»îµÄ×îÖÕ´¦Àíº¯Êý£¬»áµ÷ÓÃÍøÂçµÄ¼¤»î½Ó¿Úpdp_act_proc
+void pdp_act_proc_for_module(struct pdp_active_info *p_pdpInfo, int pdp_type)
+{
+ int iResult = 0;
+ int c_id = p_pdpInfo->c_id;
+ p_pdpInfo->pdp_type = pdp_type;
+
+ if(g_pdpinfo_mng[c_id-1].is_acted)
+ {
+ return;
+ }
+ at_print(AT_ERR,"pdp_type == %d\n", p_pdpInfo->pdp_type);
+ at_print(AT_ERR, "c_id == %d\n", p_pdpInfo->c_id);
+ at_print(AT_ERR, "pdp_type == %d\n", p_pdpInfo->pdp_type);
+ at_print(AT_ERR, "ip46flag == %d\n", p_pdpInfo->act_info.ip46flag);
+ at_print(AT_ERR, "ip == %s\n", p_pdpInfo->act_info.ip);
+ at_print(AT_ERR, "gateway == %s\n", p_pdpInfo->act_info.gateway);
+ at_print(AT_ERR, "pri_dns == %s\n", p_pdpInfo->act_info.pri_dns);
+ at_print(AT_ERR, "sec_dns == %s\n", p_pdpInfo->act_info.sec_dns);
+ at_print(AT_ERR, "ip6 == %s\n", p_pdpInfo->act_info.ip6);
+ at_print(AT_ERR, "gateway6 == %s\n", p_pdpInfo->act_info.gateway6);
+ at_print(AT_ERR, "pri_dns6 == %s\n", p_pdpInfo->act_info.pri_dns6);
+ at_print(AT_ERR, "sec_dns6 == %s\n", p_pdpInfo->act_info.sec_dns6);
+ iResult = pdp_act_proc(p_pdpInfo,MODULE_ID_AT_CTL);
+ g_pdpinfo_mng[c_id-1].is_acted = 1;
+ if(iResult == 0)
+ {
+ CID_ARRAY[c_id-1].ref = 1;
+ at_print(AT_ERR,"Call pdp_act_proc success!!\n");
+ if(p_pdpInfo->act_info.ip46flag == V4_VALID){
+ syscall(__NR_set_pdp_state,(unsigned char)c_id, 4);
+ }
+ }
+ else
+ at_print(AT_ERR,"Call pdp_act_proc failed!!\n");
+}
+
+//È¥¼¤»îµÄ×îÖÕ´¦Àíº¯Êý£¬»áµ÷ÓÃÍøÂçµÄÈ¥¼¤»î½Ó¿Úpdp_deact_proc
+void pdp_deact_proc_for_module(struct pdp_active_info *p_pdpInfo)
+{
+ int iResult = 0;
+ int c_id = p_pdpInfo->c_id;
+ if(g_pdpinfo_mng[c_id-1].is_acted !=0 )
+ {
+ at_print(AT_ERR,"begin call pdp_deact_proc_for_module, cid is %d\n",c_id);
+ g_pdpinfo_mng[c_id-1].linkdown_state = V4V6_INVALID;
+ g_pdpinfo_mng[c_id-1].ipflag_down = g_pdpinfo_mng[c_id-1].pdpInfo->act_info.ip46flag;
+ iResult = pdp_deact_proc(p_pdpInfo->c_id, p_pdpInfo->act_info.ip46flag, MODULE_ID_AT_CTL);
+ }
+ g_pdpinfo_mng[c_id-1].is_acted = 0;
+ if(iResult == 0)
+ at_print(AT_ERR,"Call pdp_deact_proc success!!\n");
+ else
+ at_print(AT_ERR,"Call pdp_deact_proc failed!!\n");
+}
+
+int fwd_pdpact_proc(int cid)
+{
+ FWD_PDP_INFO *p_fwd_info = &g_pdpinfo_mng[cid -1].fwd_info;
+ struct pdp_active_info *pdpInfo = g_pdpinfo_mng[cid -1].pdpInfo;
+
+ if(0 == (cid_reserved&(1<<(cid-1))))
+ {
+ softap_assert("");
+ return -1;
+ }
+
+ if(p_fwd_info->cgact_ok && p_fwd_info->zgact_ok && pdpInfo)
+ {
+ char LanEnable[CID_LEN_MAX] = {0};
+ cfg_get_item("LanEnable", LanEnable, sizeof(LanEnable));
+ if(atoi(LanEnable) == 1)
+ pdp_act_proc_for_module(pdpInfo, PDP_NORMAL);
+ else
+ pdp_act_proc_for_module(pdpInfo, PDP_EXT);
+ if(g_pdpinfo_mng[cid-1].fwd_info.zconstat_flag == 0)
+ {
+ send_zconstat_auto_report(1, cid);
+ g_pdpinfo_mng[cid-1].fwd_info.zconstat_flag = 1;
+ }
+ return 0;
+ }
+ return -1;
+
+}
+
+
+//cgactת·¢´¦Àí£¬ÈçÈë²Î´íÎóÖ±½Ó±¨´í£¬±¨´íÐÅÏ¢´ý¸üÐÂ
+int cgact_req_rcv_act(char *at_paras,int at_fd,struct at_context *context)
+{
+ char* err_str = NULL;
+ at_print(AT_DEBUG, "at_str = %s\n", at_paras);
+
+ int iState = 0, c_id = 0;
+ E_AT_PARSE eParseResult = AT_PARSE_SUCCESS;
+
+ eParseResult = get_at_cmd_param_int(at_paras, &iState, &at_paras);
+ at_print(AT_DEBUG, "state == %d\n", iState);
+ if(AT_PARSE_SUCCESS != eParseResult)
+ {
+ err_str = at_err_build(ATERR_PARAM_INVALID);
+ at_write(context->at_channel->at_fd, err_str, strlen(err_str));
+ free(err_str);
+ return AT_END;
+ }
+ eParseResult = move_to_next_param(at_paras, &at_paras);
+ if(AT_PARSE_SUCCESS != eParseResult)
+ {
+ err_str = at_err_build(ATERR_PARAM_INVALID);
+ at_write(context->at_channel->at_fd, err_str, strlen(err_str));
+ free(err_str);
+ return AT_END;
+ }
+ eParseResult = get_at_cmd_param_int(at_paras, &c_id, &at_paras);
+ at_print(AT_DEBUG, "cid == %d\n", c_id);
+ if(AT_PARSE_SUCCESS != eParseResult)
+ {
+ err_str = at_err_build(ATERR_PARAM_INVALID);
+ at_write(context->at_channel->at_fd, err_str, strlen(err_str));
+ free(err_str);
+ return AT_END;
+ }
+ if(!is_at_cmd_end(skip_at_cmd_head_blanks(at_paras)))
+ {
+ err_str = at_err_build(ATERR_PARAM_INVALID);
+ at_write(context->at_channel->at_fd, err_str, strlen(err_str));
+ free(err_str);
+ return AT_END;
+ }
+ if (c_id <= 0 || c_id > CID_MAX_NUM)
+ {
+ err_str = at_err_build(ATERR_PARAM_INVALID);
+ at_write(context->at_channel->at_fd, err_str, strlen(err_str));
+ free(err_str);
+ return AT_END;
+ }
+ if ((cid_reserved & (1<<(c_id-1)))==0)
+ {
+ err_str = at_err_build(ATERR_NOT_ALLOWED);
+ at_write(context->at_channel->at_fd, err_str, strlen(err_str));
+ free(err_str);
+ return AT_END;
+ }
+ context->app_param = (void*)malloc(CID_LEN_MAX+1);
+ if(context->app_param == NULL){
+ softap_assert("");
+ return AT_END;
+ }
+ memset(context->app_param, 0, CID_LEN_MAX+1);//±£´æcidÖµ
+ snprintf(context->app_param,CID_LEN_MAX+1, "%d,%d", iState,c_id);
+
+ return AT_CONTINUE;
+}
+
+//zgactת·¢´¦Àí£¬ÈçÈë²Î´íÎó»òCPδÏÈ·¢cgcat¼¤»îÖ±½Ó±¨´í
+//Èç¹ûÊÇ·¢Æð²¦ºÅ£¬AP²àת·¢(ÆðÍø¿Ú¶¯×÷ÔÚcgactOKÏìÓ¦Àï´¦Àí£¬Ô¤ÁôÔÚzgactokת·¢Àï´¦Àí)£¬CPÖ±½Ó´¦Àí²¢·µ»Ø
+int zgact_req_rcv_act(char *at_paras,int at_fd,struct at_context *context)
+{
+ char* err_str = NULL;
+ at_print(AT_DEBUG, "at_str = %s \n", at_paras);
+
+ int iState = 0, c_id = 0;
+ E_AT_PARSE eParseResult = AT_PARSE_SUCCESS;
+
+ eParseResult = get_at_cmd_param_int(at_paras, &iState, &at_paras);
+ at_print(AT_DEBUG, "state == %d\n", iState);
+ if(AT_PARSE_SUCCESS != eParseResult)
+ {
+ err_str = at_err_build(ATERR_PARAM_INVALID);
+ at_write(context->at_channel->at_fd, err_str, strlen(err_str));
+ free(err_str);
+ return AT_END;
+ }
+ eParseResult = move_to_next_param(at_paras, &at_paras);
+ if(AT_PARSE_SUCCESS != eParseResult)
+ {
+ err_str = at_err_build(ATERR_PARAM_INVALID);
+ at_write(context->at_channel->at_fd, err_str, strlen(err_str));
+ free(err_str);
+ return AT_END;
+ }
+ eParseResult = get_at_cmd_param_int(at_paras, &c_id, &at_paras);
+ at_print(AT_DEBUG, "cid == %d\n", c_id);
+ if(AT_PARSE_SUCCESS != eParseResult)
+ {
+ err_str = at_err_build(ATERR_PARAM_INVALID);
+ at_write(context->at_channel->at_fd, err_str, strlen(err_str));
+ free(err_str);
+ return AT_END;
+ }
+ if(!is_at_cmd_end(skip_at_cmd_head_blanks(at_paras)))
+ {
+ err_str = at_err_build(ATERR_PARAM_INVALID);
+ at_write(context->at_channel->at_fd, err_str, strlen(err_str));
+ free(err_str);
+ return AT_END;
+ }
+ if (c_id <= 0 || c_id > CID_MAX_NUM)
+ {
+ err_str = at_err_build(ATERR_PARAM_INVALID);
+ at_write(context->at_channel->at_fd, err_str, strlen(err_str));
+ free(err_str);
+ return AT_END;
+ }
+ if ((cid_reserved & (1<<(c_id-1)))==0)
+ {
+ err_str = at_err_build(ATERR_NOT_ALLOWED);
+ at_write(context->at_channel->at_fd, err_str, strlen(err_str));
+ free(err_str);
+ return AT_END;
+ }
+#ifdef HAVE_MODEM_IN_CORE
+ if(iState == 1)
+ {
+ //¶ÔÓÚPDP¼¤»î£¬Ö±½Ó»Ø¸´OK£¬¶ÔÓÚPDPÈ¥¼¤»î£¬ÔòÐèÒªµ÷ÓÃpdpÈ¥¼¤»î½Ó¿Ú
+ int idx = get_idx_bycid(c_id);
+ if(idx < 0)
+ return AT_END;
+ if(g_pdpinfo_mng[c_id-1].fwd_info.cgact_ok != 1 || g_pdpinfo_mng[c_id-1].fwd_info.zgact_ok == 1 || CID_ARRAY[idx].state != CID_IDLE)
+ {
+ err_str = at_err_build(ATERR_PROC_FAILED);
+ at_write(context->at_channel->at_fd, err_str, strlen(err_str));
+ free(err_str);
+ return AT_END;
+ }
+ g_pdpinfo_mng[c_id-1].fwd_info.zgact_ok = 1;
+ fwd_pdpact_proc(c_id);
+ at_write(context->at_channel->at_fd, "\r\nOK\r\n", strlen("\r\nOK\r\n"));
+ return AT_END;
+ }
+#endif
+ context->app_param = (void*)malloc(CID_LEN_MAX+1);
+ if(context->app_param == NULL){
+ softap_assert("");
+ return AT_END;
+ }
+ memset(context->app_param, 0, CID_LEN_MAX+1);//±£´æcidÖµ
+ snprintf(context->app_param, CID_LEN_MAX+1,"%d,%d", iState,c_id);
+ return AT_CONTINUE;
+}
+
+int get_pdptype(struct pdp_act_req *p_setInfo)
+{
+ int pdp_type = PDP_LOCAL;
+ memset(g_defcid_mng.default_apn, 0x00, sizeof(g_defcid_mng.default_apn));
+ cfg_get_item("default_apn", g_defcid_mng.default_apn, sizeof(g_defcid_mng.default_apn));
+ //¶ÔÓÚppp²¦ºÅ£¬²ÉÓÃpppµÄ×éÍø·½Ê½
+ //if(modid == MODULE_ID_PPPD)
+ if(p_setInfo->ppp_cid)
+ {
+ pdp_type = PDP_PPP;
+
+ }
+ else if(p_setInfo->ext_cid)
+ {
+ pdp_type = PDP_EXT;
+ }
+//zhangfen for PDP
+#if 0
+ //µ±Ç°½öÔÊÐíwebui¡¢blºÍat_ctl·¢Æðnormal×éÍø·½Ê½£¬ÇÒÿ´Î²¦ºÅǰ¶¼½«Ä¬ÈÏapnͬ²½µ½ÆäËûcpuºË
+ else if(modid == MODULE_ID_WEB_CGI || modid == MODULE_ID_BL || modid == MODULE_ID_AT_CTL)
+ {
+ pdp_type = PDP_NORMAL;
+ set_default_apn(p_setInfo->comm_info.apn);
+ }
+ else
+ {
+ if(0 == strcmp(p_setInfo->comm_info.apn, g_defcid_mng.default_apn))
+ {
+ pdp_type = PDP_NORMAL;
+ }
+ }
+#endif
+ else if(0 == strcmp(p_setInfo->comm_info.apn, g_defcid_mng.default_apn))
+ {
+ pdp_type = PDP_NORMAL;
+ }
+ else
+ {
+ pdp_type = PDP_LOCAL;
+ }
+/*#if (APP_OS_TYPE == APP_OS_TOS)
+ if(p_setInfo->comm_info.auth_type != NONE_AUTH)
+ {
+ //Ϊtos¶¨ÖÆ£¬ÓÉÓÚµ±Ç°pdp_type¸ù¾Ýapn»ñÈ¡£¬Ò»µ©ppp²¦ºÅʹÓõÄapn£¬ºÍĬÈÏapnÒ»Ö£¬Ôòtos»á´æÔÚ¶à¸ö
+ //ĬÈÏ·ÓÉ£¬µ¼Ö·ÓÉ»ìÂÒ£¬Òò´Ëµ±´æÔÚÈÏ֤ʱ£¬Ö±½Ó½«pdp¼¤»îÀàÐÍ£¬ÉèÖÃΪPDP_LOCAL
+ pdp_type = PDP_EXT;
+ }
+#endif*/
+ return pdp_type;
+
+}
+
+int get_idx(struct pdp_act_req *p_setInfo, int *is_setapn)
+{
+ int idx = 0;
+ char versionmode[2] = {0};
+ cfg_get_item("version_mode", versionmode, sizeof(versionmode));
+
+ //¶ÔÓÚppp²¦ºÅ»òÕßÍⲿMCUÖ¸¶¨cid pdp²¦ºÅ£¬Æäcid±ØÐëʱԤÁôcid£¬²»²ÎÓëapn¹²Ïí¹¦ÄÜ
+ if(p_setInfo->ppp_cid != 0 || p_setInfo->ext_cid != 0)
+ {
+#ifdef HAVE_MODEM_IN_CORE
+ if(p_setInfo->ppp_cid)
+ {
+ idx = get_idx_bycid(p_setInfo->ppp_cid);//ÔÚcp²à£¬»ñÈ¡ppp²¦ºÅÖ¸¶¨cidµÄidxÖµ
+ get_ppp_apn(p_setInfo);
+ }
+ else
+ {
+ idx = get_idx_bycid(p_setInfo->ext_cid);//ÔÚcp²à£¬»ñÈ¡ext²¦ºÅÖ¸¶¨cidµÄidxÖµ
+ }
+ if(idx < 0)
+ return -1;
+ if(CID_ARRAY[idx].reserved == 0)//|| CID_ARRAY[idx].state != CID_IDLE)
+ softap_assert("");//ÓÉÓÚppp²¦ºÅʹÓõÄcid±ØÐëÊÇÔ¤Áôcid£¬Òò´ËÈç¹û¸Ãidx²»ÊÇÔ¤Áôcid£¬Ö÷¶¯¶ÏÑÔ
+#else
+ idx = get_idx_byidle(p_setInfo->default_flag,p_setInfo->comm_info.apn);//ÔÚap²àÖ»Òª»ñÈ¡¸ö¿ÕÏеÄidx¼´¿É
+#endif
+ if(is_setapn)
+ *is_setapn = 1;
+ return idx;
+ }
+
+
+ //¶ÔÓÚ·ÇÈÏÖ¤µÄpdp¼¤»î£¬´Ëʱapn¿ÉÒÔ¹²Ïí£¬Òò´ËÊ×Ïȸù¾Ýapn¡¢ip_type²éÕÒÊÇ·ñÒѾ´æÔÚÏàͬapnºÍip_typeµÄcid×ÊÔ´
+ if(p_setInfo->comm_info.auth_type == NONE_AUTH)
+ {
+ idx = get_idx_byapn(p_setInfo->comm_info.apn, p_setInfo->comm_info.ip_type, is_setapn, p_setInfo->default_flag);
+ }
+ else
+ {
+ idx = get_idx_byidle(p_setInfo->default_flag,p_setInfo->comm_info.apn);
+ if(is_setapn)
+ *is_setapn = 1;
+ }
+ return idx;
+}
+
+/*void set_pdp_act_info(AT_PDP_ACT_REQ_INFO *srcInfo, struct pdp_act_req* dstInfo)
+{
+ strncpy(dstInfo->ip_type, srcInfo->ip_type, sizeof(dstInfo->ip_type)-1);
+ strncpy(dstInfo->apn, srcInfo->apn, sizeof(dstInfo->ip_type)-1);
+ strncpy(dstInfo->username, srcInfo->username, sizeof(dstInfo->username)-1);
+ strncpy(dstInfo->password, srcInfo->password, sizeof(dstInfo->password)-1);
+ strncpy(dstInfo->challenge, srcInfo->challenge, sizeof(dstInfo->challenge)-1);
+ dstInfo->auth_type = srcInfo->auth_type;
+}*/
+
+/*¼¤»îµÄÖ÷´¦Àíº¯Êý
+¸ù¾Ýapn¡¢ip_type¡¢ÈÏÖ¤¼ÓÃÜÐÅÏ¢µÃµ½cid×ÊÔ´Êý×éÖÐijһÏ
+
+Èç¹û¸Ãcid×ÊÔ´ÒѾ¼¤»î£¬ÔòÁ¢¼´·µ»Øpdp¼¤»î³É¹¦ÏûÏ¢;
+
+Èç¹û¸Ãcid×ÊÔ´ÕýÔÚ¼¤»î»òÕßÈ¥¼¤»î£¬ÔòÆô¶¯¶¨Ê±Æ÷µÈ´ýÍê³É£¬ÔÙ½øÐÐpdp¼¤»î
+
+Èç¹û¸Ãcid×ÊԴδ¼¤»î:
+ APÖ±½Óת·¢zpdpact£¬×´Ì¬ÉèÖÃΪACTIVING£¬
+ Èç¹ûAPN/ip_typeÏàͬ¡¢CPÖ±½Ó·¢Æðcgact¼¤»îÁ÷³Ì£¬×´Ì¬ÉèÖÃΪACTIVING
+ Èç¹û²»ÏàͬÐèÏȶ¨ÒåÉÏÏÂÎÄ£¬CPÏÈÈ¥¼¤»î£¬ÔÙÈÏÖ¤£¬ÔÙ¶¨ÒåÉÏÏÂÎÄ£¬ÔÙ¼¤»î£¬×´Ì¬ÉèÖÃΪACTIVING¡£
+*/
+char* pdp_act_func(void *msg,struct at_context *context)
+{
+ char *at_str = NULL;
+ MSG_BUF *p_msg = (MSG_BUF *)msg;
+ struct pdp_act_req pdpActReq = {0};
+ PDP_PRIVATE_INFO *private_info = NULL;
+
+ int is_setapn = 0;
+ int cid = 0;
+ int idx = 0;
+ int pdp_type = PDP_LOCAL;
+ char creg_stat[20] = {0};
+ char cereg_stat[20] = {0};
+ char ppp_status[20] = {0};
+
+ cfg_get_item("cgreg_stat", creg_stat, sizeof(creg_stat));
+ cfg_get_item("cereg_stat", cereg_stat, sizeof(cereg_stat));
+ at_print(AT_ERR,"@@!!@@pdp_act_func creg stat=%s,cereg stat=%s ims=%d!\n",creg_stat,cereg_stat,apn_is_ims);
+
+ if(is_cid_init == 0 || ((1 == atoi(cereg_stat) || 5 == atoi(cereg_stat))&&apn_is_ims==-1))
+ {
+ add_one_delayed_msg(msg);
+ return NULL;
+ }
+
+ cfg_get_item(NV_PPP_STATUS, ppp_status, sizeof(ppp_status));
+ //¶ÔÓÚÀ´×ÔÓÚweb ui·¢ÆðµÄpdp¼¤»î£¬Èç¹ûµ±Ç°²¦ºÅ״̬²»ÊÇdisconnected£¬Ò»Âɲ»Ðí²¦ºÅ£¬Ö±½Ó·µ»Ø
+ if((p_msg->src_id == MODULE_ID_WEB_CGI || p_msg->src_id == MODULE_ID_MAIN_CTRL) && (0 != strcmp(PPP_DISCONNECTED, ppp_status)))
+ {
+ AT_PDP_ACT_RSP_INFO rsp = {0};
+ memset(&rsp, 0x00, sizeof(AT_PDP_ACT_RSP_INFO));
+ rsp.result = AT_RSP_ERR;
+ send_rsp_msg(context->source,context->msg_id,MSG_CMD_PDP_ACT_RSP,sizeof(AT_PDP_ACT_RSP_INFO),&rsp);
+
+ at_print(AT_ERR,"reject web ui dial, ppp_status: %s\n",ppp_status);
+ return NULL;
+ }
+
+ //Èç¹ûwebui/bl/ǰһ´Î¼¤»îĬÈÏcidµÄÄ£¿é·¢ÆðÐÂpdp¼¤»î£¬²»ÔÙÐèÒªpdp×Ô¶¯ÖØÐ²¦ºÅ¶¨Ê±Æ÷½øÐÐÖØ²¦
+ if((p_msg->src_id == MODULE_ID_WEB_CGI
+ || p_msg->src_id == MODULE_ID_BL
+ || p_msg->src_id == g_defcid_mng.modid) && (0 ==check_is_fd(g_defcid_mng.modid)))
+ {
+ if(g_defcid_mng.pdpreconnect_timerid)
+ {
+#if (APP_OS_TYPE == APP_OS_LINUX)
+ DeleteSoftTimer(g_defcid_mng.pdpreconnect_timerid);
+#elif (APP_OS_TYPE == APP_OS_TOS)
+ zOss_StopTimer(g_defcid_mng.pdpreconnect_timerid);
+#endif
+ }
+ }
+
+
+ memcpy((void*)&pdpActReq, (void*)(p_msg->aucDataBuf), p_msg->usDataLen);
+
+ /*get_ppp_cid½öÔÚap²àppp²¦ºÅʱºòÓÃÓÚ»ñÈ¡ppp²¦ºÅÖ¸¶¨µÄcid*/
+ get_ppp_cid(p_msg->src_id, &pdpActReq.ppp_cid);
+
+ idx = get_idx(&pdpActReq, &is_setapn);
+ if(idx < 0)
+ {
+ AT_PDP_ACT_RSP_INFO rsp = {0};
+ memset(&rsp, 0x00, sizeof(AT_PDP_ACT_RSP_INFO));
+ rsp.result = AT_RSP_ERR;
+ send_rsp_msg(context->source,context->msg_id,MSG_CMD_PDP_ACT_RSP,sizeof(AT_PDP_ACT_RSP_INFO),&rsp);
+
+ return NULL;
+ }
+ pdp_type = get_pdptype(&pdpActReq);
+
+ /*get_ppp_cid½öÔÚap²àppp²¦ºÅʱºòÓÃÓÚ»ñÈ¡ppp²¦ºÅÖ¸¶¨µÄcid*/
+ //get_ppp_cid(pdp_type, &pdpActReq.ppp_cid);
+ //if(get_ppp_cid(pdp_type, &pdpActReq.ppp_cid) == 0)
+ // return NULL;
+ if(pdp_type == PDP_NORMAL)
+ {
+ if(g_defcid_mng.cid == 0 && g_defcid_mng.activing_cid != 0)
+ {//ÓÐһ·defcidÕýÔÚ¼¤»î¹ý³ÌÖУ¬µÈµÈÔÙÅÜ
+ at_print(AT_ERR,"def cid %d is acting, start timer to wait\n", g_defcid_mng.activing_cid);
+ add_one_delayed_msg(msg);
+ }
+ char flag[4] = {0};
+ cfg_get_item("local_pdp", flag, sizeof(flag)-1);
+ if(atoi(flag) != 0)
+ {//²»½øÐÐNORMAL²¦ºÅ±êÖ¾
+ cfg_set("local_pdp", "");
+ //ÒѾ¼¤»îµÄNORMAL¿ÉÒÔ¸´Ó㬲ÎÊý²»Ò»Ö»òû¼¤»îµÄ¸ÄLOCAL
+ if(g_defcid_mng.cid != idx + 1)
+ {
+ pdp_type = PDP_LOCAL;
+ }
+ }
+ else
+ {
+ if(g_defcid_mng.cid != 0 && g_defcid_mng.cid != idx + 1)
+ {//APNÊÇdefaultµ«PDPÀàÐÍ»òÈÏÖ¤²»ÊÇ£¬µ¼Ö·ÖÅäÁËÁíÍâµÄcid
+ at_print(AT_ERR,"pdp_act_func, PDP_NORMAL redefine %d %d\n",idx+1,g_defcid_mng.cid);
+ if(p_msg->src_id == MODULE_ID_WEB_CGI
+ || p_msg->src_id == MODULE_ID_BL
+ || p_msg->src_id == g_defcid_mng.modid)
+ {//×Ô¶¯²¦ºÅÓ¦Ó㬻¹ÓÃÔÀ´µÄCID£¬È¥¼¤»îÐÞ¸ÄcgdcontÔÙÖØÐ²¦ºÅ
+ idx = g_defcid_mng.cid - 1;
+ is_setapn = 1;
+ CID_ARRAY[idx].state = CID_IDLE;
+ }
+ else
+ {//·Ç×Ô¶¯²¦ºÅÓ¦Óã¬ÓÃLOCAL²¦ºÅ
+ pdp_type = PDP_LOCAL;
+ }
+ }
+ else if(g_defcid_mng.cid == 0)
+ {//APNÊÇdefaultµ«·ÖÅäµÄcidÒѼ¤»î£¬ÇÒ²»ÊÇNORMAL£¬È¥¼¤»îÐÞ¸ÄcgdcontÔÙÖØÐ²¦ºÅ
+ if(CID_ARRAY[idx].state == CID_ACTIVE)
+ {
+ is_setapn = 1;
+ CID_ARRAY[idx].state = CID_IDLE;
+ }
+ if(CID_ARRAY[idx].state == CID_IDLE)
+ {//»º´ædefcid£¬½â¾ö×Ô¶¯²¦ºÅÁ÷³ÌÖÐºÍÆäËû²¦ºÅ²¢·¢ÎÊÌ⣬ÔÚ¼¤»îʧ°Ü¡¢È¥²¦ºÅ¡¢cgevʱÇåÁã
+ g_defcid_mng.activing_cid = idx + 1;
+ }
+ }
+ }
+ }
+
+ at_print(AT_ERR,"pdp_act_func: source is %x, default_apn is %s, apn is %s, ip_type is %s, pdp_type is %d, idx =%d\n",\
+ context->source, g_defcid_mng.default_apn, pdpActReq.comm_info.apn, pdpActReq.comm_info.ip_type, pdp_type, idx);
+ if(CID_ARRAY[idx].state == CID_ACTIVE)
+ {
+ void *next_req = NULL;
+ int next_len = 0;
+ at_print(AT_ERR,"apn %s has been acted ,cid is %d, reply to app directly\n",pdpActReq.comm_info.apn, CID_ARRAY[idx].c_id);
+ pdpact_success_proc(CID_ARRAY[idx].c_id,pdp_type, context, &next_req, &next_len);
+ send_rsp_msg(context->source,context->msg_id,MSG_CMD_PDP_ACT_RSP, sizeof(AT_PDP_ACT_RSP_INFO),(UCHAR *)next_req);
+ free(next_req);
+ return NULL;
+ }
+ else if(CID_ARRAY[idx].state == CID_ACTIVING || CID_ARRAY[idx].state == CID_DEACTIVING)
+ {
+
+ at_print(AT_ERR,"apn %s is acting or deacting ,start timer to wait\n", pdpActReq.comm_info.apn);
+ add_one_delayed_msg(msg);
+ return NULL;
+ }
+ /*µ±Ç°½öÖ§³ÖĬÈÏapnµÄ×Ô¶¯ÖØÁ¬£¬±£´æÄ¬ÈÏapn pdp¼¤»îÇëÇóµÄ·¢Æð·½ºÍpdp¼¤»îÇëÇó
+ ÐÅÏ¢£¬ÓÃÓÚÖØÁ¬Ê±×Ô¶¯²¦ºÅʹÓÃ
+ */
+ if((pdp_type == PDP_NORMAL)&&(0 == check_is_fd(p_msg->src_id)))
+ {
+ g_defcid_mng.modid = p_msg->src_id;
+ if(g_defcid_mng.set_info)
+ {
+ free(g_defcid_mng.set_info);
+ g_defcid_mng.set_info = NULL;
+ }
+ g_defcid_mng.set_info = malloc(sizeof(struct pdp_act_req));
+ if(g_defcid_mng.set_info == NULL)
+ return NULL;
+ memcpy(g_defcid_mng.set_info, &pdpActReq, sizeof(struct pdp_act_req));
+#ifdef MULTI_CPU
+ sync_default_apn(context);
+#endif
+ }
+#if !defined(HAVE_MODEM_IN_CORE)
+ if(g_customer_type == CUSTOMER_SDK)
+ {
+ //CS&EPS¶¼×¢²áʧ°Ü£¬²»½øÐв¦ºÅ£¬Ö±½Ó±¨´í¸ø·¢Æð·½,¼õÉÙ²»±ØÒªµÄ²¦ºÅ²Ù×÷
+ if(1 != atoi(creg_stat) && 5 != atoi(creg_stat) && 1 != atoi(cereg_stat) && 5 != atoi(cereg_stat))
+ {
+ /*Ϊ¼õÉÙ²»±ØÒªµÄ²¦ºÅatÃüÁîÁ÷³Ì£¬Èç¹ûµ±Ç°²»Âú×㲦ºÅÌõ¼þ£¬ÔòÖ±½Ó±¨´í¸øÍø¹ØÓ¦Óã¬
+ ֪ͨÆäµ±Ç°ÎÞ·¨²¦ºÅ*/
+ //send_rsp_msg(context->source,context->msg_id,MSG_CMD_PDP_ACT_RSP,0,0);
+ AT_PDP_ACT_RSP_INFO rsp = {0};
+ memset(&rsp, 0x00, sizeof(AT_PDP_ACT_RSP_INFO));
+ rsp.result = AT_RSP_ERR;
+ if(pdp_type == PDP_NORMAL && 0 == check_is_fd(context->source))
+ {
+ set_pppstatus(PPP_DISCONNECTED);
+ }
+ else if(pdp_type == PDP_PPP)
+ {
+ //¶ÔÓÚPPP²¦ºÅ£¬pdp¼¤»îʧ°Ü»òÕßûÓз¢Æðpdp¼¤»î£¬ÐèÒª·¢Æðppp¿ìËÙ¶Ï¿ª£¬
+ //½«Êý¾Ý̬Çл»³ÉÃüÁî̬£¬²¢·¢ËÍNO CARRIER¸æÖª¶Ô¶Ë
+ at_print(AT_ERR,"no network and ppp_dial failed!!\n");
+ cfg_set("ppp_pdpstate", "dead");
+ MSG_BUF *buf=NULL;
+ buf = normal_getmsg(MODULE_ID_AT_CTL,MODULE_ID_AT_CTL,MSG_CMD_PPP_QUICK_DISCONNECT,0,NULL);//modem³õʼ»¯Íê³Éºó£¬²éѯimeiºÅ
+ rcv_clt_req_msg_proc(buf);
+ free(buf);
+ }
+ send_rsp_msg(context->source,context->msg_id,MSG_CMD_PDP_ACT_RSP,sizeof(AT_PDP_ACT_RSP_INFO),&rsp);
+
+ return NULL;
+ }
+ }
+#endif
+/*
+ if(CID_ARRAY[idx].state == CID_ACTIVE)
+ {
+ void *next_req = NULL;
+ int next_len = 0;
+ at_print(AT_ERR,"apn %s has been acted ,cid is %d, reply to app directly\n",pdpActReq.comm_info.apn, CID_ARRAY[idx].c_id);
+ pdpact_success_proc(CID_ARRAY[idx].c_id,pdp_type, context, &next_req, &next_len);
+ send_rsp_msg(context->source,context->msg_id,MSG_CMD_PDP_ACT_RSP, sizeof(AT_PDP_ACT_RSP_INFO),(UCHAR *)next_req);
+ free(next_req);
+ return NULL;
+ }
+ else if(CID_ARRAY[idx].state == CID_ACTIVING || CID_ARRAY[idx].state == CID_DEACTIVING)
+ {
+
+ at_print(AT_ERR,"apn %s is acting or deacting ,start timer to wait\n", pdpActReq.comm_info.apn);
+ add_one_delayed_msg(msg);
+ return NULL;
+ }
+ else
+*/ {
+ //Ê×ÏȼǼµ±Ç°µÄatͨµÀÔ´Í·£¬ÓÃÓÚpdp¼¤»î³É¹¦ºóÖ±½Ó´ÓatͨµÀ»Ø¸´ÏìÓ¦
+ //context->at_fd = at_fd;
+
+ //¼Ç¼µ±Ç°apnÉèÖÃ
+ strcpy(CID_ARRAY[idx].apn, pdpActReq.comm_info.apn);
+ strcpy(CID_ARRAY[idx].ip_type, pdpActReq.comm_info.ip_type);
+
+ if(pdp_type == PDP_NORMAL && 0 == check_is_fd(context->source))
+ {
+ set_pppstatus(PPP_CONNECTING);
+ }
+
+ private_info = (PDP_PRIVATE_INFO*)malloc(sizeof(PDP_PRIVATE_INFO));
+ context->app_param = private_info;
+ if(private_info == NULL){
+ softap_assert("");
+ return NULL;
+ }
+ memset(private_info, 0, sizeof(PDP_PRIVATE_INFO)); //±£´æcidÖµ
+
+ private_info->pdp_type = pdp_type; //¼Ç¼±¾´Îpdp¼¤»îÀàÐÍ
+ private_info->index = idx; //¼Ç¼±¾´Îpdp¼¤»î¶ÔÓ¦µÄCID×ÊÔ´Êý×éϱê
+
+ //·¢Æðpdp¼¤»î£¬¸ù¾Ý·µ»ØÖµÈ·¶¨ÊÇ·ñÐèÒªÖØÐÂÉèÖÃapn£¬¶ÔÓÚĬÈϳÐÔØ£¬ÔÚPDP¼¤»îʱ£¬ÎÞÐèÔÙÖØÐÂÉèÖÃapnÁË
+#ifdef HAVE_MODEM_IN_CORE
+ cid = CID_ARRAY[idx].c_id;
+ private_info->c_id = cid; //¼Ç¼±¾´ÎµÄpdp¼¤»îcid
+ if(is_setapn)
+ {
+ /*private_info->pdpActInfo = (struct pdp_act_req *)malloc(sizeof(struct pdp_act_req));
+ memset(private_info->pdpActInfo, 0x00, sizeof(struct pdp_act_req));*/
+ memcpy(&private_info->pdpActInfo, &pdpActReq, sizeof(struct pdp_act_req));
+
+ at_str = (char *)malloc(32);
+ if(at_str == NULL){
+ softap_assert("");
+ return NULL;
+ }
+ memset(at_str, 0, 32);
+ at_print(AT_ERR,"need to set apn , goto build cgact deactive cmd\n");
+ sprintf(at_str,"at+cgact=0,%d\r\n",cid);
+ private_info->pdp_state = 0; //¼Ç¼±¾´Îpdp¼¤»î״̬Ϊȥ¼¤»î
+ CID_ARRAY[idx].state = CID_ACTIVING;
+ }
+ else
+#endif
+ {
+ at_str = build_pdpact_cmd(private_info, &pdpActReq);
+ }
+ at_print(AT_DEBUG, "pdp_act_fuc: at_str = %s\n", at_str);
+
+ return at_str;
+ }
+}
+
+
+//È¥¼¤»îµÄÖ÷´¦Àíº¯Êý
+char *pdp_deact_func(void *msg,struct at_context *context)
+{
+ char *at_str = NULL;
+ MSG_BUF *p_msg = (MSG_BUF *)msg;
+ int cur_cid = 0;
+ PDP_PRIVATE_INFO *private_info = NULL;
+
+ AT_PDP_DEACT_RSP_INFO rsp_msg = {0};
+ rsp_msg.result = AT_RSP_ERR;
+
+ int idx = -1;
+ //int at_fd = 0;
+
+ AT_PDP_DEACT_REQ_INFO pdpDeactReq = {0};
+
+ memcpy(&pdpDeactReq, (AT_PDP_DEACT_REQ_INFO*)p_msg->aucDataBuf, sizeof(AT_PDP_DEACT_REQ_INFO));
+ cur_cid = pdpDeactReq.c_id;
+
+
+ at_print(AT_ERR,"pdp_deact_func: source is %x, g_defcid_msg.modid is %x, cid is %d\n",p_msg->src_id, g_defcid_mng.modid, cur_cid);
+ if(context->source == MODULE_ID_PPPD)
+ {
+ //¶ÔÓÚPCÖÕ¶Ë·¢ÆðµÄppp terminate£¬ÔÚÐÉÌÍê³Éºó£¬ppp֪ͨat_ctl·¢ÆðpdpÈ¥¼¤»î
+ if((cur_cid > 0) && (ppp_cid >0) && (cur_cid != ppp_cid))
+ {
+ softap_assert("wrong cid for ppp");
+ }
+ ppp_cid = 0;
+ cfg_set("ppp_cid","");
+ ppp_quick_disconnect();
+ }
+ //at_fd = pdpDeactReq.at_fd;
+ //Èç¹ûÍⲿÖ÷¶¯·¢ÆðpdpÈ¥¼¤»î£¬ÔòÖÕÖ¹×Ô¶¯Á¬½Ó£¬²¢ÊÍ·ÅËùÓÐ×ÊÔ´ÐÅÏ¢
+ if((p_msg->src_id == MODULE_ID_WEB_CGI
+ || p_msg->src_id == MODULE_ID_BL
+ || p_msg->src_id == g_defcid_mng.modid) && (0 == check_is_fd(g_defcid_mng.modid))
+ && (cur_cid == g_defcid_mng.cid || cur_cid == 0))
+ {
+
+ if(g_defcid_mng.pdpreconnect_timerid)
+ {
+#if (APP_OS_TYPE == APP_OS_LINUX)
+ DeleteSoftTimer(g_defcid_mng.pdpreconnect_timerid);
+#else
+ zOss_StopTimer(g_defcid_mng.pdpreconnect_timerid);
+#endif
+ }
+ if(g_defcid_mng.set_info != NULL)
+ {
+ if(g_defcid_mng.cid != 0)
+ {
+ idx = g_defcid_mng.cid - 1;
+ }
+ else
+ {
+ int i;
+ for(i = 0; i<CID_MAX_NUM; i++)
+ {
+ if((0 == strcmp(g_defcid_mng.set_info->comm_info.apn, CID_ARRAY[i].apn))
+ && (0 == strcmp(g_defcid_mng.set_info->comm_info.ip_type, CID_ARRAY[i].ip_type)))
+ {
+ idx = i;
+ }
+ }
+ }
+ if(idx >= 0 || idx < CID_MAX_NUM)
+ {
+ if(CID_ARRAY[idx].state == CID_ACTIVING)
+ {
+ at_print(AT_ERR,"pdp_deac_func:apn %s is acting ,start timer to wait\n", g_defcid_mng.set_info->comm_info.apn);
+ add_one_delayed_msg(msg);
+ return NULL;
+ }
+ else if(CID_ARRAY[idx].state == CID_ACTIVE)
+ {
+ //ÔÚÈ¥¼¤»î֮ǰ£¬Èç¹û·¢Éú¹ýÍø²àÖ÷¶¯¶Ï¿ª£¬´Ëʱpdp×Ô¶¯²¦ºÅ»ñÈ¡µ½µÄcid£¬ÓëÓ¦ÓÃÖ÷¶¯·¢ÆðµÄpdp¼¤»îcidδ±ØÒ»ÖÂ
+ //Èç¹ûÓ¦ÓÃʹÓÃ×Ô¼ºÖ÷¶¯pdp¼¤»î»ñÈ¡µ½µÄcid¶Ï¿ª²¦ºÅʱ£¬½«cidÐÞ¸ÄΪpdp×Ô¶¯²¦ºÅ»ñÈ¡µ½µÄcid
+ at_print(AT_ERR,"pdp_deac_func:now default cid is changed to %d , begin to deact it\n", cur_cid);
+ cur_cid = CID_ARRAY[idx].c_id;
+ }
+ }
+ if(g_defcid_mng.set_info)
+ {
+ free(g_defcid_mng.set_info);
+ g_defcid_mng.set_info = NULL;
+ }
+ }
+ g_defcid_mng.modid = 0;
+ //ÖØÉèpdpÖØÁ¬¶¨Ê±Æ÷ʱ³¤
+ at_timeout_reset_pdpreconn_time();
+ //½«×Ô¶¯ÖØÁ¬nvÉèÖÃΪ0
+ cfg_set("auto_reconnect","0");
+ if(cur_cid == 0)
+ {
+ rsp_msg.result = AT_RSP_OK;
+ }
+ else
+ {
+ g_defcid_mng.cid = cur_cid;
+ set_pppstatus(PPP_DISCONNECTING);
+ }
+
+ }
+
+ if(cur_cid == 0)
+ {
+ send_rsp_msg(context->source,context->msg_id,MSG_CMD_PDP_DEACT_RSP, sizeof(AT_PDP_DEACT_RSP_INFO),(UCHAR *)&rsp_msg);
+ return NULL;
+ }
+ idx = get_idx_bycid(cur_cid);
+ if(idx < 0)
+ {
+ softap_assert("");
+ return NULL;
+ }
+/*
+ if(CID_ARRAY[idx].ref > 1)
+ {
+ CID_ARRAY[idx].ref--;
+ //ÓÉÓÚzpdpact_req_funcÒѾ´¦ÀíÍê³ÉatͨµÀµÄÇëÇó´¦Àí£¬Òò´ËÕâÀï½ö´¦ÀíÕæÕýµÄÏûÏ¢ÇëÇó¼´¿É
+ if(context->source > 0)
+ {
+ AT_PDP_DEACT_RSP_INFO rsp_msg = {0};
+ rsp_msg.result = AT_RSP_OK;
+
+ if(context->source == MODULE_ID_WEB_CGI)
+ {
+ //pdp_normal_cid = 0;
+ cfg_set(NV_PPP_STATUS,PPP_DISCONNECTED);
+ iConnectStatus = 0; //0 disconnected,1 connected,2 connecting,3 disconnecting
+ ipc_send_message(MODULE_ID_AT_CTL,MODULE_ID_MMI,MSG_CMD_CHANNEL_CONNECT_STATUS, sizeof(iConnectStatus), (UCHAR *)&iConnectStatus,0);
+ }
+
+ ipc_send_message(MODULE_ID_AT_CTL, context->source, MSG_CMD_PDP_DEACT_RSP, sizeof(AT_PDP_DEACT_RSP_INFO), &rsp_msg, 0);
+ }
+ else
+ {
+ softap_assert("");
+ }
+ at_print(AT_ERR, "Enter pdp_deact_func 22222222!!!!\n");
+ return NULL;
+ }
+ //ÏûÏ¢ºÍatͨµÀpdpÈ¥¼¤»îÇëÇó¸´ÓÃ
+ else*/
+ {
+ //¼Ç¼atͨµÀ£¬ÓÃÓÚpdpÈ¥¼¤»î½á¹ûÓ¦´ð»Ø¸´
+ //context->at_fd = at_fd;
+
+ at_str = (char *)malloc(PDP_CMD_LEN);
+ if(at_str == NULL){
+ softap_assert("");
+ return NULL;
+ }
+ memset(at_str, 0, PDP_CMD_LEN);
+
+ private_info = (PDP_PRIVATE_INFO*)malloc(sizeof(PDP_PRIVATE_INFO));
+ if(private_info == NULL){
+ softap_assert("");
+ free(at_str);
+ return NULL;
+ }
+ memset(private_info, 0, sizeof(PDP_PRIVATE_INFO));//±£´æcidÖµ
+ context->app_param = private_info;
+
+ private_info->c_id = cur_cid;
+ private_info->index = idx;
+ private_info->pdp_state = 0;
+/*
+ if(context->source == MODULE_ID_PPPD)
+ {
+ //¶ÔÓÚPCÖÕ¶Ë·¢ÆðµÄppp terminate£¬ÔÚÐÉÌÍê³Éºó£¬ppp֪ͨat_ctl·¢ÆðpdpÈ¥¼¤»î
+ if((cur_cid > 0) && (ppp_cid >0) && (cur_cid != ppp_cid))
+ {
+ softap_assert("wrong cid for ppp");
+ }
+ ppp_cid = 0;
+ cfg_set("ppp_cid","");
+ ppp_quick_disconnect();
+ }
+*/
+ CID_ARRAY[idx].state = CID_DEACTIVING;
+#ifdef HAVE_MODEM_IN_CORE
+ sprintf(at_str,"at+zgact=0,%d\r\n", cur_cid);
+#else
+ sprintf(at_str,"AT+ZPDPDEACT=%d\r\n", cur_cid);
+#endif
+ return at_str;
+ }
+}
+
+
+/*
+À©Õ¹at zpdpactµÄÃüÁî¸ñʽ:
+ at+zpdpact=cid,iptype,apn
+
+ ÆäÖÐcid=0£¬±íʾ²»Ö¸¶¨cid£¬ÓÉat_ctl¶¯Ì¬Ñ¡Ôñ¿ÉÓÃcid½øÐÐpdp²¦ºÅ£»
+ cid=1~4£¬±íʾÍⲿָ¶¨cid½øÐÐpdp²¦ºÅ£»
+ iptype±ØÐëÊÇË«ÒýºÅ°üº¬µÄ×Ö·û´®¸ñʽ
+*/
+int get_pdp_set_info(char * at_paras, struct pdp_act_req *info)
+{
+ int state = 0;
+ void * p[12] = { &info->ext_cid,
+ info->comm_info.ip_type,
+ info->comm_info.apn,
+ &(info->volte_param1),
+ &(info->volte_param2),
+ &(info->volte_param3),
+ &(info->comm_info.auth_type),
+ info->comm_info.username,
+ info->comm_info.password,
+ info->comm_info.challenge,
+ &(info->ppp_cid),
+ &(info->default_flag)
+ };
+ parse_param2("%d,%s,%100s,%d,%d,%d,%d,%s,%s,%s,%d,%d",at_paras, p);
+ at_print(AT_DEBUG,"ext_cid is %d, ppp_cid is %d\n",info->ext_cid, info->ppp_cid);
+
+ return 1;
+}
+/*
+int zpdpact_req_func(int at_fd, char *at_paras,void ** res_msg, int *res_msglen)
+{
+ int idx;
+ //int is_setapn;
+
+ if('1' == at_paras[0])
+ {
+ struct pdp_act_req info = {0};
+
+ get_pdp_set_info(at_paras, &info);
+
+ idx = get_idx(&info, NULL);
+ if(info.ppp_cid)
+ {
+ get_ppp_apn(&info);//»ñÈ¡ppp²¦ºÅʱ£¬ÓÃcgdcontÃüÁîÉèÖõÄip_typeºÍapn
+ }
+ //Èç¹ûµ±Ç°ÒѾPDP¼¤»î³É¹¦£¬ÔòÖ±½Ó·µ»Øcid¼´¿É
+ if(CID_ARRAY[idx].state == CID_ACTIVE)
+ {
+ int cid = CID_ARRAY[idx].c_id;
+ //Ö±½Ó·µ»ØÒѾ¼¤»î
+ //CID_ARRAY[idx].ref++;
+ *res_msg = zpdpact_ind_build(g_pdpinfo_mng[cid-1].pdpInfo);
+
+ at_print(AT_ERR,"zpdpact:apn %s is acted ,cid is %d\n",info.comm_info.apn, cid);
+
+ *res_msglen = strlen(*res_msg);
+
+ return AT_END;
+ }
+ else
+ {
+ MSG_BUF *buf=NULL;
+ //ÕâÀォat_fd×÷ΪԴģ¿éid,ÓÉÓÚÄ¿±êÄ£¿éIDÒѾÊÇat_ctl×ÔÉí£¬Òò´ËÎÞÐèÍⲿ·¢ËÍÏûÏ¢£¬Ö±½Ó×é×°ÏûÏ¢£¬µ÷ÓÃÏûÏ¢´¦Àí½Ó¿Ú
+ buf=normal_getmsg(at_fd,MODULE_ID_AT_CTL, MSG_CMD_PDP_ACT_REQ, sizeof(struct pdp_act_req), (unsigned char *)&info);
+ rcv_clt_req_msg_proc(buf);
+ free(buf);
+
+ return AT_CONTINUE;
+ }
+ }
+ else if('0' == at_paras[0])
+ {
+ int state = 0, cur_cid = 0;
+ int idx = 0;
+ void *p[2] = {&state, &cur_cid};
+
+ parse_param2("%d,%d", at_paras, p);
+
+ idx = get_idx_bycid(cur_cid);
+ if(idx < 0)
+ {
+ softap_assert("");
+ }
+
+ //ת»»³ÉÏûÏ¢·½Ê½½øÐд¦Àí£¬ÔÚÏûÏ¢ÄÚÈÝÖÐЯ´øatͨµÀÐÅÏ¢
+ MSG_BUF *buf=NULL;
+ AT_PDP_DEACT_REQ_INFO deact_req = {0};
+ deact_req.c_id = cur_cid;
+ //ÕâÀォat_fd×÷ΪԴģ¿éid
+ buf=normal_getmsg(at_fd,MODULE_ID_AT_CTL,MSG_CMD_PDP_DEACT_REQ, sizeof(AT_PDP_DEACT_REQ_INFO), (unsigned char *)&deact_req);
+ rcv_clt_req_msg_proc(buf);
+ free(buf);
+ return AT_CONTINUE;
+
+ }
+ return AT_END;
+}
+*/
+#ifndef HAVE_MODEM_IN_CORE
+//APÆðÍø¿ÚºÍ¶ÏÍø¿ÚµÄ´¦Àíµã
+int zpdpact_ok_act(char *at_paras,struct at_context *context,void **next_req,int *next_len)
+{
+ int state = 0, cur_cid = 0;
+ int idx = 0;
+ PDP_PRIVATE_INFO *private_info = (PDP_PRIVATE_INFO *)context->app_param;
+
+ state = private_info->pdp_state;
+ cur_cid = private_info->c_id;
+
+ idx = get_idx_bycid(cur_cid);
+
+ if(idx < 0)
+ {
+ softap_assert("");
+ }
+
+ if(state == 1)
+ {
+ if(cur_cid > 0 &&g_pdpinfo_mng[cur_cid-1].pdpInfo!= NULL)
+ {
+
+ pdp_act_proc_for_module(g_pdpinfo_mng[cur_cid-1].pdpInfo, private_info->pdp_type);
+
+ pdpact_success_proc(cur_cid, private_info->pdp_type,context, next_req, next_len);
+
+ return AT_END;
+
+ }
+ else
+ {
+ softap_assert("");
+ }
+
+ }
+
+
+ return AT_END;
+}
+
+int zpdpact_err_act(char *at_paras,struct at_context *context,void **next_req,int *next_len)
+{
+
+ int state = 0;
+ PDP_PRIVATE_INFO *private_info = (PDP_PRIVATE_INFO *)context->app_param;
+
+ state = private_info->pdp_state;
+ if(state == 1)
+ {
+ int idx = private_info->index;
+ //Èç¹ûpdp¼¤»îʧ°Ü£¬Ôò¶ÔÓÚatͨµÀÀ´µÄÇëÇó£¬Ö±½Ó·µ»Øerror;
+ pdpact_failed_proc(at_paras,context, idx, next_req, next_len);
+
+ if(context->source == MODULE_ID_PPPD)
+ {
+ //ÉèÖÃpppµÄpdp¼¤»î״̬£¬Í¨Öªppp·¢Æðlcp terminateÇëÇó
+ //È»ºó·¢Æðppp¿ìËÙ¶Ï¿ª£¬½«Êý¾Ý̬Çл»³ÉÃüÁî̬£¬²¢·¢ËÍNO CARRIER¸æÖª¶Ô¶Ë
+ at_print(AT_ERR,"ppp_dial pdpact failed!!\n");
+ cfg_set("ppp_pdpstate", "dead");
+ MSG_BUF *buf=NULL;
+ buf = normal_getmsg(MODULE_ID_AT_CTL,MODULE_ID_AT_CTL,MSG_CMD_PPP_QUICK_DISCONNECT,0,NULL);//modem³õʼ»¯Íê³Éºó£¬²éѯimeiºÅ
+ rcv_clt_req_msg_proc(buf);
+ free(buf);
+ }
+ }
+ else
+ {
+ //µ±Ç°½ö¿¼ÂÇpdp¼¤»îʧ°ÜµÄÇé¿ö£»
+ softap_assert("");
+ }
+
+ return AT_END;
+}
+
+int zpdpact_auto_act(char *at_paras ,int is_query_report)
+{
+ //¸ù¾Ý±£´æµÄcid×ÊÔ´Êý×éϱ꣬»ñÈ¡µ±Ç°PDP¼¤»îµÄapnºÍiptypeÉèÖÃ
+ struct at_context *context = (struct at_context *)is_query_report;
+ PDP_PRIVATE_INFO *private_info =(PDP_PRIVATE_INFO *)context->app_param;
+ int cid = 0;
+ if(NULL == at_paras)
+ {
+ softap_assert("");
+ return AT_END;
+ }
+ //¸ù¾ÝÖмä½á¹û£¬»ñÈ¡µ±Ç°pdp״̬
+
+ //Èç¹ûµ±Ç°Éϱ¨Îªpdp¼¤»î³É¹¦Éϱ¨
+ {
+ int idx = private_info->index;
+ cid = parse_ipdns_param(at_paras);
+ //save_v6addr(at_paras, &cur_cid);
+ //¼Ç¼µ±Ç°CP²àΪAP²à·ÖÅäµÄcidÐÅÏ¢
+ CID_ARRAY[idx].c_id = cid;
+ private_info->c_id = cid;
+ private_info->pdp_state = 1;
+ }
+ return AT_END;
+}
+
+int zpdpdeact_ok_act(char *at_paras,struct at_context *context,void **next_req,int *next_len)
+{
+ int state = 0, cur_cid = 0;
+ PDP_PRIVATE_INFO *private_info = (PDP_PRIVATE_INFO *)context->app_param;
+
+ state = private_info->pdp_state;
+ cur_cid = private_info->c_id;
+
+ if(state == 0)
+ {
+ if(cur_cid > 0)
+ {
+ pdpinfo_reset(cur_cid);
+ pdpdeact_success_proc(cur_cid, context, next_req, next_len);
+ }
+ }
+ return AT_END;
+
+}
+int zpdpdeact_err_act(char *at_paras,struct at_context *context,void **next_req,int *next_len)
+{
+ //pdpÈ¥¼¤»î²»ÔÊÐí³öÏÖʧ°Ü
+ softap_assert("");
+ return AT_END;
+}
+#endif
+
+//ǿתcontext->paramΪ¶ÔÓ¦µÄ½á¹¹Ì壬¸³ÖµÏÂÒ»¸öATÇëÇóµ½at_strÖÐ
+//CPÆðÍø¿ÚºÍ¶ÏÍø¿ÚµÄ´¦Àíµã
+int cgact_ok_act(char *at_paras,struct at_context *context,void **next_req,int *next_len)
+{
+ int state = 0, cur_cid = 0;
+ int idx = 0;
+ PDP_PRIVATE_INFO *private_info = (PDP_PRIVATE_INFO *)context->app_param;
+ int ret = -1;
+
+ cur_cid = private_info->c_id;
+ state = private_info->pdp_state;
+
+ idx = get_idx_bycid(cur_cid);
+ if(idx < 0)
+ {
+ softap_assert("");
+ return AT_END;
+ }
+ if(state == 1)
+ {
+ if(cur_cid > 0)
+ {
+ //ÕâÀïÍø²àÖ÷¶¯È¥¼¤»îÁË£¬Ö±½Ó·µ»Ø´íÎó£¬Í¨ÖªÊ§°Ü
+ if(CID_IDLE == CID_ARRAY[idx].state)
+ {
+ //ÕâÀïµ±×öpdpʧ°Ü´¦Àí
+ at_print(AT_ERR,"cgev is infromed ref=%d when waiting for ip6 addr\n",CID_ARRAY[idx].ref);
+ if(CID_ARRAY[idx].ref == 1)
+ {
+ return AT_WAIT_AUTO;
+ }
+ else
+ {
+ pdpact_failed_proc(NULL, context, idx, next_req, next_len);
+ return AT_END;
+ }
+ }
+
+ //Èç¹ûûÓ줻î¹ý£¬Èç¹ûûÓлñÈ¡µ½ipµØÖ·Éϱ¨£¬ÔòµÈ´ýÉϱ¨£¬·ñÔòÖ±½Ó¼¤»î
+ if(0 == g_pdpinfo_mng[cur_cid-1].is_acted)
+ {
+ if(g_pdpinfo_mng[cur_cid-1].pdpInfo != NULL)
+ {
+ pdp_act_proc_for_module(g_pdpinfo_mng[cur_cid-1].pdpInfo, private_info->pdp_type);
+ g_pdpinfo_mng[cur_cid-1].ipflag = g_pdpinfo_mng[cur_cid-1].pdpInfo->act_info.ip46flag;
+ g_pdpinfo_mng[cur_cid-1].linkup_state = V4V6_INVALID;
+ //Çå¿Õv6µØÖ·»ñÈ¡Éϱ¨ÐÅÏ¢£¬µÈ´ý½á¹ûÉϱ¨
+ //g_pdpinfo_mng[cur_cid-1].slaac_v6_inform = V6ADDR_GETTING;
+ }
+ else
+ {
+ if(CID_ARRAY[idx].state == CID_ACTIVING)
+ {
+ at_print(AT_ERR,"can not recv zgipdns and send ok again!!!\n");
+ return AT_WAIT_AUTO;
+ }
+ }
+ }
+
+#if 0
+ if((g_pdpinfo_mng[cur_cid-1].pdpInfo->act_info.ip46flag & V6_VALID))
+ {
+ int ret = check_slaac_inform(cur_cid);
+ if(ret == AT_END)
+ {
+ at_print(AT_ERR,"slaac failed to get ipv6 addr, reply pdp act failed to app\n");
+ pdpact_failed_proc(NULL, context, idx, next_req, next_len);
+ return AT_END;
+ }
+ else if(ret == AT_WAIT_AUTO)
+ {
+ return AT_WAIT_AUTO;
+ }
+
+ }
+#endif
+ ret = check_linkup_state(cur_cid);
+ if(ret == AT_WAIT_AUTO)
+ {
+ at_print(AT_ERR,"check_linkup_state == LINK_UPDOWN_START\n");
+ return AT_WAIT_AUTO;
+ }
+ if((g_pdpinfo_mng[cur_cid-1].pdpInfo->act_info.ip46flag & V6_VALID))
+ {
+ get_unicast_ip6addr(cur_cid);
+ }
+
+ //V6µ¥Õ»µØÖ·»ñȡʧ°Ü£¬·µ»Ø´íÎóÂ룬V4V6˫ջÇé¿öÏÂV6µØÖ·»ñȡʧ°Ü£¬ÈÔÈ»·µ»Ø³É¹¦
+ if(g_pdpinfo_mng[cur_cid-1].pdpInfo->act_info.ip46flag == V6_VALID)
+ {
+ char ps_wan[NV_NAME_LEN] = {0};
+ char psv6_wan[NV_NAME_LEN] = {0};
+ char pswan_state[NV_NAME_LEN] = {0};
+
+ cfg_get_item("pswan", ps_wan, sizeof(ps_wan));
+
+ snprintf(psv6_wan,NV_NAME_LEN, "%s%d_ipv6_state", ps_wan, cur_cid);
+ cfg_get_item(psv6_wan, pswan_state, sizeof(pswan_state));
+ if(strcmp(pswan_state,"dead") == 0)
+ {
+ AT_PDP_ACT_RSP_INFO *rsp = malloc(sizeof(AT_PDP_ACT_RSP_INFO));
+ if(rsp == NULL){
+ softap_assert("malloc failed");
+ return AT_END;
+ }
+ at_print(AT_ERR,"get V6addr failed\n");
+ rsp->result = AT_RSP_ERR;
+ rsp->errcode = ATERR_PDP_IPADDR_FAILED;
+ rsp->cid = cur_cid;
+ *next_req = rsp;
+ *next_len = sizeof(AT_PDP_ACT_RSP_INFO);
+
+ cfg_set(NV_PDP_STATUS, "0");
+ CID_ARRAY[idx].state = CID_IDLE;
+ pdpinfo_reset(cur_cid);
+ return AT_END;
+
+ }
+
+ }
+ cfg_set(NV_PDP_STATUS, "1");
+ ipc_send_message(MODULE_ID_AT_CTL, MODULE_ID_ISMS, MSG_CMD_PDP_STATUS_IND, 2, "1", 0);
+ ipc_send_message(MODULE_ID_AT_CTL, MODULE_ID_DMREG, MSG_CMD_PDP_STATUS_IND, 2, "1", 0);
+ ipc_send_message(MODULE_ID_AT_CTL, MODULE_ID_SAFECARE, MSG_CMD_PDP_STATUS_IND, 2, "1", 0);
+
+ at_print(AT_ERR,"check_linkup_state == LINK_UPDOWN_END\n");
+ pdpact_success_proc(cur_cid, private_info->pdp_type,context, next_req, next_len);
+ return AT_END;
+ }
+ }
+ if(state == 0)
+ {
+ if(cur_cid > 0 )
+ {
+ if(context->msg_id == MSG_CMD_PDP_ACT_REQ)
+ {
+ char *at_str = (char *)malloc(AT_CMD_MAX);
+ if(at_str == NULL)
+ return AT_END;
+ memset(at_str, 0x00, AT_CMD_MAX);
+ struct pdp_act_req *p_setInfo = &private_info->pdpActInfo;
+ private_info->auth_state = PDP_DEL_AUTH;
+ sprintf(at_str, "at+cgdcont=%d,\"%s\",\"%s\",,,,,%d,%d,%d\r\n", private_info->c_id, p_setInfo->comm_info.ip_type,
+ p_setInfo->comm_info.apn, p_setInfo->volte_param1, p_setInfo->volte_param2, p_setInfo->volte_param3);
+
+ *next_req = at_str;
+ *next_len = strlen(at_str);
+
+ return AT_CONTINUE;
+ }
+ else if (context->msg_id == MSG_CMD_PDP_DEACT_REQ)
+ {
+ if(1 == g_pdpinfo_mng[cur_cid-1].is_acted)
+ {
+ pdpinfo_reset(cur_cid);
+ return AT_WAIT_AUTO;
+ }
+ else
+ {
+ ret = check_linkdown_state(cur_cid);
+ if(ret == AT_END)
+ {
+ at_print(AT_ERR,"check_linkdown_state == LINK_UPDOWN_END\n");
+ return deact_pdp_act(at_paras,context,next_req,next_len);;
+
+ }
+ else if(ret == AT_WAIT_AUTO)
+ {
+
+ at_print(AT_ERR,"check_linkdown_state == LINK_UPDOWN_START\n");
+ return AT_WAIT_AUTO;
+ }
+
+ }
+ }
+ }
+ }
+ return AT_END;
+}
+
+int zgact_ok_act(char *at_paras,struct at_context *context,void **next_req,int *next_len)
+{
+ int state = 0, cur_cid = 0;
+ int idx = 0;
+ PDP_PRIVATE_INFO *private_info = (PDP_PRIVATE_INFO *)context->app_param;
+ state = private_info->pdp_state;
+ cur_cid = private_info->c_id;
+
+ idx = get_idx_bycid(cur_cid);
+ if(idx < 0)
+ {
+ softap_assert("");
+ }
+ if(state == 0)
+ {
+ if(cur_cid > 0 )
+ {
+ if(context->msg_id == MSG_CMD_PDP_DEACT_REQ)
+ {
+ char *at_str = (char *)malloc(AT_CMD_MAX);
+ if(at_str == NULL)
+ return AT_END;
+ memset(at_str, 0x00, AT_CMD_MAX);
+ private_info->auth_state = PDP_DEL_AUTH;
+ sprintf(at_str, "at+cgact=0,%d\r\n", private_info->c_id);
+
+ *next_req = at_str;
+ *next_len = strlen(at_str);
+
+ return AT_CONTINUE;
+ }
+ }
+ }
+ return AT_END;
+}
+
+//¶ÏÍø¿Ú¹¦ÄÜ£¬ÆðÍø¿ÚÔÚCGACTÀï´¦ÀíÁË
+int deact_pdp_act(char *at_paras,struct at_context *context,void **next_req,int *next_len)
+{
+ int state = 0, cur_cid = 0;
+ int idx = 0;
+ PDP_PRIVATE_INFO *private_info = (PDP_PRIVATE_INFO *)context->app_param;
+
+ state = private_info->pdp_state;
+ cur_cid = private_info->c_id;
+
+ idx = get_idx_bycid(cur_cid);
+ if(idx < 0)
+ {
+ softap_assert("");
+ }
+ if(state == 0)
+ {
+ if(cur_cid > 0 )
+ {
+ //int position = 0;
+ pdpinfo_reset(cur_cid);
+
+ cfg_set(NV_PDP_STATUS, "0");
+ ipc_send_message(MODULE_ID_AT_CTL, MODULE_ID_ISMS, MSG_CMD_PDP_STATUS_IND, 2, "0", 0);
+ ipc_send_message(MODULE_ID_AT_CTL, MODULE_ID_DMREG, MSG_CMD_PDP_STATUS_IND, 2, "0", 0);
+ ipc_send_message(MODULE_ID_AT_CTL, MODULE_ID_SAFECARE, MSG_CMD_PDP_STATUS_IND, 2, "0", 0);
+
+ pdpdeact_success_proc(cur_cid, context, next_req, next_len);
+ }
+ else
+ {
+ softap_assert("");
+ }
+ }
+ return AT_END;
+}
+
+int cgact_err_act(char *at_paras,struct at_context *context,void **next_req,int *next_len)
+{
+ int state = 0, cur_cid = 0;
+ int idx = 0;
+ PDP_PRIVATE_INFO *private_info = (PDP_PRIVATE_INFO *)context->app_param;
+ state = private_info->pdp_state;
+ cur_cid = private_info->c_id;
+
+
+ idx = get_idx_bycid(cur_cid);
+ if(idx < 0)
+ {
+ softap_assert("");
+ }
+ if(state == 0)
+ {
+ if(cur_cid > 0 )
+ {
+ if(context->msg_id == MSG_CMD_PDP_ACT_REQ)
+ {
+ char *at_str = (char *)malloc(AT_CMD_MAX);
+ if(at_str == NULL)
+ return AT_END;
+ memset(at_str, 0x00, AT_CMD_MAX);
+ struct pdp_act_req *p_setInfo = &private_info->pdpActInfo;
+ private_info->auth_state = PDP_DEL_AUTH;
+ sprintf(at_str, "at+cgdcont=%d,\"%s\",\"%s\",,,,,%d,%d,%d\r\n", private_info->c_id, p_setInfo->comm_info.ip_type,
+ p_setInfo->comm_info.apn, p_setInfo->volte_param1, p_setInfo->volte_param2, p_setInfo->volte_param3);
+
+ *next_req = at_str;
+ *next_len = strlen(at_str);
+
+ return AT_CONTINUE;
+ }
+ else if (context->msg_id == MSG_CMD_PDP_DEACT_REQ)
+ {
+
+ char at_cmd[32] = {0};
+ snprintf(at_cmd, sizeof(at_cmd),"\r\n+ZDEFBEARCID: %d\r\n", cur_cid);
+ at_context_write_by_pos(POSITION_VOLTE, at_cmd);
+
+ return deact_pdp_act(at_paras,context,next_req,next_len);
+ }
+ }
+ else
+ {
+ softap_assert("");
+ }
+ }
+ else if(1 == state)
+ {
+ //µ±Ç°½ö¿¼ÂÇpdp¼¤»îʱ³öÏÖʧ°Ü£¬Çå³ýpdp¼¤»îʱ¼Ç¼µÄ״̬ÐÅÏ¢
+ if(context->msg_id == MSG_CMD_PDP_ACT_REQ)
+ {
+ pdpact_failed_proc(at_paras,context,idx, next_req, next_len);
+ }
+ }
+
+ return AT_END;
+
+}
+
+int zgact_err_act(char *at_paras,struct at_context *context,void **next_req,int *next_len)
+{
+ softap_assert("");
+ return AT_END;
+}
+
+//½«¼¤»îÐÅÏ¢´æµ½pdpInfoÈ«¾ÖÀ´ËÈ«¾ÖÒ²ÊÇÅжÏÊÇ·ñÒÑÊÕµ½zgipdnsµÄÌõ¼þ
+//ÓÉÓÚ¶ÁÇý¶¯select»úÖÆ£¬Í¬Ê±Éϱ¨ÊÇÓÐʱznetifupÇëÇó±ÈzgipdnsÉϱ¨Ôçreadµ½£¬´ËʱpdpInfoΪnullÔòÔÚznetifup_req´æÒ»·ÝpdpInfo
+//ÔÚOK±ÈzgipdnsÏÈÉϱ¨Ê±£¬ÓÉ´ËÆðÍø¿Ú£¬°üÀ¨Ô¤Áôcid
+int zgipdns_auto_act(char *at_paras ,int is_query_report)
+{
+ //»ñÈ¡ip¡¢dnsºóÐèÒªmalloc дÈëCID_ARRAY[i].act_info
+
+ int iCidNum = 0, idx = 0, i = 0, cid = 0, comma_num = 0;
+ int len = IPTYPE_MAX_LEN + MAX_AT_IPV4V6_SIZE*4;
+ char *mem = malloc(len);
+ char *type = mem;
+ char *addr = type + IPTYPE_MAX_LEN;
+ char *gw = addr + MAX_AT_IPV4V6_SIZE;
+ char *pri_dns = gw + MAX_AT_IPV4V6_SIZE;
+ char *sec_dns = pri_dns + MAX_AT_IPV4V6_SIZE;
+ char *p[6] = {&cid, type, addr, gw, pri_dns, sec_dns};
+ struct netdev_act_info *act_info = NULL;
+ char *temp = at_paras;
+ at_print(AT_DEBUG, "recv zgipdns_inform ,begin to save ip and dns\n");
+
+ if(NULL == mem)
+ {
+ softap_assert("");
+ return AT_END;
+ }
+
+ iCidNum = temp[0] - '0';
+
+ if(0 == iCidNum)
+ {
+ free(mem);
+ mem = NULL;
+ return AT_END;
+ }
+ else
+ {
+ //µÃµ½µÚÒ»¸öcid pdp¼¤»îÐÅÏ¢µÄÖ¸Õë
+ comma_num = 1;
+ }
+
+
+ for(i=0; i < iCidNum; i++)
+ {
+
+ temp = get_param_by_symbol(temp,',',comma_num);
+ comma_num = 6;
+
+ memset(mem, 0x00, len);
+ if(temp == NULL)
+ return AT_END;
+ parse_param2("%d,%s,%s,%s,%s,%s", temp, p);
+ idx = cid-1;
+ if(idx < 0 || idx > CID_MAX_NUM-1)
+ {
+ softap_assert("");
+ return AT_END;
+ }
+ pdpinfo_init(cid);
+ act_info = &g_pdpinfo_mng[idx].pdpInfo->act_info;
+
+ // ModemÉϱ¨µØÖ·¸ñʽ: 4λ10½øÖÆIPV4£¬ÀýÈç: 4.4.4.4
+ if(strcmp("IP", type) == 0)
+ {
+ int index = 0;
+ char *str_ip[4] = {act_info->ip, act_info->gateway, act_info->pri_dns, act_info->sec_dns};
+ act_info->ip46flag = V4_VALID;
+
+ for(index = 0; index < 4; index++)
+ {
+ memcpy(str_ip[index], p[index+2], IPV4ADDLEN_MAX);
+ }
+ }
+ // ModemÉϱ¨µØÖ·¸ñʽ: 16λ10½øÖÆIPV6£¬ÀýÈç: 16.16.16.16.16.16.16.16.16.16.16.16.16.16.16.16
+ else if(strcmp("IPV6", type) == 0 || strcmp("IPv6", type) == 0)
+ {
+ int index = 0;
+ char *str_ip6[4] = {act_info->ip6, act_info->gateway6, act_info->pri_dns6, act_info->sec_dns6};
+ act_info->ip46flag = V6_VALID;
+
+ for(index = 0; index < 4; index++)
+ {
+ get_format_ipv6(p[index+2], str_ip6[index], IPV6ADDLEN_MAX);
+ }
+ }
+ // ModemÉϱ¨µØÖ·¸ñʽ: 4λ10½øÖÆIPV4.16λ10½øÖÆIPV6¡¾IPV4ÓëIPV6ÓÃ.¸ô¿ª¡¿£¬ÀýÈç: 4.4.4.4.16.16.16.16.16.16.16.16.16.16.16.16.16.16.16.16
+ else if(strcmp("IPV4V6", type) == 0 || strcmp("IPv4v6", type) == 0)
+ {
+ int index = 0;
+ char * v6_start = NULL;
+ char *str_ip[4] = {act_info->ip, act_info->gateway, act_info->pri_dns, act_info->sec_dns};
+ char *str_ip6[4] = {act_info->ip6, act_info->gateway6, act_info->pri_dns6, act_info->sec_dns6};
+ act_info->ip46flag = V46_VALID;
+
+ for(index = 0; index < 4; index++)
+ {
+ v6_start = get_param_by_symbol(p[index+2], '.', 4);
+ memcpy(str_ip[index], p[index+2], (int)(v6_start - p[index+2] -1));
+ get_format_ipv6(v6_start, str_ip6[index], IPV6ADDLEN_MAX);
+ }
+ }
+ else
+ {
+ act_info->ip46flag = V4V6_INVALID;
+ }
+ {
+ if(cid_reserved&(1<<(cid-1)))
+ fwd_pdpact_proc(cid);
+ }
+
+ }
+ free(mem);
+ mem = NULL;
+ return AT_END;
+}
+//ֻʣ¶ÏÍø¿Ú¹¦ÄÜ£¬ÆðÍø¿Ú¹¦ÄÜ×ß²»µ½
+int cgact_fwd_ok_act(char *at_paras, struct at_context *context)
+{
+ int state = 0, cur_cid = 0;
+ char LanEnable[CID_LEN_MAX] = {0};
+ void *p[2] = {&state, &cur_cid};
+
+ parse_param2("%d,%d", (char *)context->app_param, p);
+ at_print(AT_DEBUG,"state: %d, cur_cid = %d\n", state, cur_cid);
+ if(state == 1)
+ {
+ //±íÃ÷µ±Ç°ÒѾ½ÓÊÕµ½OK
+ if(0 == (cid_reserved & (1<<(cur_cid-1))))
+ {
+ softap_assert("");
+ }
+ g_pdpinfo_mng[cur_cid-1].fwd_info.cgact_ok = 1;
+ }
+ else
+ {
+ if(cur_cid > 0 && g_pdpinfo_mng[cur_cid-1].pdpInfo != NULL)
+ {
+ pdpinfo_reset(cur_cid);
+ int idx = get_idx_bycid(cur_cid);
+ if(idx < 0)
+ return AT_END;
+ CID_ARRAY[idx].state = CID_IDLE;
+ }
+ }
+ return AT_END;
+}
+
+int cgact_fwd_err_act(char *at_paras, struct at_context *context)
+{
+ //softap_assert("");
+ return AT_END;
+}
+//Ô¤ÁôCID²¦ºÅ½öÔÚAP²àʹÓã¬CP²àÖ±½Ó½Ø×¡²¢·µ»ØÏê¼ûzgact_req_rcv_act
+int zgact_fwd_ok_act(char *at_paras, struct at_context *context)
+{
+ int state = 0, cur_cid = 0;
+ char LanEnable[CID_LEN_MAX] = {0};
+ void *p[2] = {&state, &cur_cid};
+
+ parse_param2("%d,%d", (char *)context->app_param, p);
+
+ if(state == 1)
+ {
+ //±íÃ÷µ±Ç°ÒѾ½ÓÊÕµ½OK
+ g_pdpinfo_mng[cur_cid-1].fwd_info.zgact_ok = 1;
+ fwd_pdpact_proc(cur_cid);
+ }
+ else
+ {
+ if(cur_cid > 0 && g_pdpinfo_mng[cur_cid-1].pdpInfo != NULL)
+ {
+ pdpinfo_reset(cur_cid);
+ int idx = get_idx_bycid(cur_cid);
+ if(idx < 0)
+ return AT_END;
+ CID_ARRAY[idx].state = CID_IDLE;
+ }
+ else
+ {
+ at_print(AT_DEBUG,"can not deact pdp!!!\n");
+ }
+ }
+ return AT_END;
+}
+
+int zgact_fwd_err_act(char *at_paras, struct at_context *context)
+{
+ return AT_END;
+}
+
+
+int cgdcont_ok_act(char *at_paras,struct at_context *context,void **next_req,int *next_len)
+{
+ //at_print(AT_DEBUG,"cgdcont_ok_act state=%d\n",psinfo.cgdcont_state);
+ char *at_next = NULL;
+ if(context->msg_id == MSG_CMD_PDP_ACT_REQ)
+ {
+ PDP_PRIVATE_INFO *private_info = (PDP_PRIVATE_INFO *)(context->app_param);
+ int auth_type = private_info->pdpActInfo.comm_info.auth_type;
+ //¼Ç¼µ±Ç°ÈÏÖ¤ÐÅÏ¢
+ int idx = get_idx_bycid(private_info->c_id);
+ if(idx < 0)
+ {
+ softap_assert("");
+ return AT_END;
+ }
+ CID_ARRAY[idx].auth_type = auth_type;
+
+ if(private_info->auth_state == PDP_DEL_AUTH)
+ {
+ at_next=(char *)malloc(PDP_CMD_LEN);
+ if(at_next == NULL){
+ softap_assert("");
+ return AT_END;
+ }
+ memset(at_next, 0, PDP_CMD_LEN);
+ sprintf(at_next,"AT+ZGPCOAUTH=%d\r\n",private_info->c_id);
+ }
+ else
+ {
+ at_next = build_pdpact_cmd(private_info,&private_info->pdpActInfo);
+ //free(private_info->pdpActInfo);
+ //private_info->pdpActInfo = NULL;
+ }
+ *next_req = at_next;
+ if(*next_req){
+ *next_len = strlen(*next_req);
+ return AT_CONTINUE;
+ }
+ }
+ else if(context->msg_id == MSG_CMD_APN_SET_REQ)
+ {//ûËѵ½ÍøÔòÒªÁ¢¼´ÅäÖÃAPN£¬autoapnºÍwebuiÅäÖÃʱÓÐЧ
+ *next_req = normal_getzgpcoauthset(1);
+ if(*next_req){
+ *next_len = strlen(*next_req);
+ return AT_CONTINUE;
+ }
+ }
+ else
+ {
+ *next_req = normal_getzgpcoauthset(default_cur_cid);
+ if(*next_req){
+ *next_len = strlen(*next_req);
+ return AT_CONTINUE;
+ }
+ }
+ return AT_END;
+}
+
+int cgdcont_err_act(char *at_paras,struct at_context *context,void **next_req,int *next_len)
+{
+ if(context->msg_id == MSG_CMD_PDP_ACT_REQ)
+ {
+ //pdp¼¤»îÇëÇóÖУ¬Ð¯´øµÄapn²»ºÏ·¨Ê±£¬Ö±½Ó»Ø¸´error
+ int cur_cid = 0;
+ int idx = 0;
+ PDP_PRIVATE_INFO *private_info = (PDP_PRIVATE_INFO *)context->app_param;
+ cur_cid = private_info->c_id;
+
+ idx = get_idx_bycid(cur_cid);
+
+ if(idx < 0)
+ {
+ softap_assert("");
+ return AT_END;
+ }
+ //apnÉèÖóö´í£¬Ôò˵Ã÷µ±Ç°apnÓÐÎÊÌ⣬ÐèÒªÇå³ýµô
+
+ memset(CID_ARRAY[idx].apn ,0x00, APN_MAX_LEN);
+ memset(CID_ARRAY[idx].ip_type, 0x00, IPTYPE_MAX_LEN);
+
+ pdpact_failed_proc(at_paras,context,idx, next_req, next_len);
+ }
+ else if(context->msg_id != MSG_CMD_APN_SET_REQ)
+ {
+ cfg_set(NV_MODEM_MAIN_STATE,"modem_syscfg_exption");
+ *next_req = normal_getzgpcoauthset(default_cur_cid);
+ if(*next_req){
+ *next_len = strlen(*next_req);
+ return AT_CONTINUE;
+ }
+ }
+ return AT_END;
+}
+
+int cgdcont_req_rcv_act(char *at_paras,int at_fd,struct at_context *context)
+{
+ char* err_str = NULL;
+ at_print(AT_DEBUG, "at_paras = %s\n", at_paras);
+
+ int c_id = 0;
+ E_AT_PARSE eParseResult = AT_PARSE_SUCCESS;
+
+ context->app_param= malloc(strlen(at_paras)+1);
+ if(context->app_param == NULL)
+ return AT_END;
+ memset(context->app_param, 0x00, strlen(at_paras)+1);
+ strcpy(context->app_param, at_paras);
+
+ eParseResult = get_at_cmd_param_int(at_paras, &c_id, &at_paras);
+ if(c_id > INT_MAX -1) // KW 3
+ {
+ c_id = INT_MAX;
+ }
+
+ if(AT_PARSE_SUCCESS != eParseResult)
+ {
+ err_str = at_err_build(ATERR_PARAM_INVALID);
+ at_write(context->at_channel->at_fd, err_str, strlen(err_str));
+ free(err_str);
+ return AT_END;
+ }
+ at_print(AT_DEBUG, "c_id == %d\n", c_id);
+#if 1 // cov M BAD_SHIFT
+ if (c_id > 0 && c_id <= CID_MAX_NUM && (cid_reserved & (1<<(c_id-1))) == 0 )
+#else
+ if ((cid_reserved & (1<<(c_id-1))) == 0 && c_id > 0 && c_id <= CID_MAX_NUM)
+#endif
+ {
+ err_str = at_err_build(ATERR_NOT_ALLOWED);
+ at_write(context->at_channel->at_fd, err_str, strlen(err_str));
+ free(err_str);
+ return AT_END;
+ }
+ return AT_CONTINUE;
+}
+
+//¸ù¾Ý×Ö·û´®£¬»ñÈ¡apnºÍiptypeÉèÖÃ,ÔÔòÊÇÖ±½ÓÌáȡǰÁ½¸ö""ÖеÄ×Ö·û´®,µ«ÊÇÈç¹û½öÓÐip_type£¬Ò²ÊÇÕý³£ÃüÁî
+int get_apn_param(char *param, char *apn, int apn_len, char *iptype, int iptype_len)
+{
+ char *apn_start = NULL;
+ char *apn_end = NULL;
+ char *iptype_start = NULL;
+ char *iptype_end = NULL;
+
+ iptype_start = strchr(param, '"');
+ if(NULL == iptype_start)//ûÓÐÕÒµ½Ë«ÒýºÅµÄ»°£¬ËµÃ÷ÊÇcgdcontµÄÈ¡ÏûÉÏÏÂÎÄÃüÁÕâÀï²»×ö¼à¿Ø
+ {
+ return -1;
+ }
+ iptype_end = strchr(iptype_start+1, '"');
+ if(NULL == iptype_end)
+ {
+ return -1;
+ }
+ if((iptype_end - iptype_start) > iptype_len)
+ {
+ return -1;
+ }
+ strncpy(iptype, iptype_start+1, (int)(iptype_end - iptype_start -1));//Ê×ÏȶÔip_type½øÐи³Öµ
+
+ apn_start = strchr(iptype_end+1, '"');
+ if(NULL == apn_start)//ûÓÐÕÒµ½Ë«ÒýºÅµÄ»°£¬ËµÃ÷ÊÇcgdcontÃüÁîÖнö¶Ôip_type½øÐÐÉèÖã¬ÔòapnÊÓΪ¿Õ£¬ÊôÓÚÕý³£Çé¿ö
+ {
+ return 0;
+ }
+ apn_end = strchr(apn_start+1, '"');
+ if(NULL == apn_end)
+ {
+ return -1;
+ }
+ if((apn_end - apn_start) > apn_len)
+ {
+ return -1;
+ }
+ strncpy(apn, apn_start+1, (int)(apn_end - apn_start -1));//¶Ôapn½øÐи³Öµ
+
+ return 0;
+}
+
+//¸üÐÂÁÐ±íµ±ÖеÄapn¼Ç¼£¬±£Ö¤¾ßÓÐmodemºËµÄapn¼Ç¼ʵʱÐÔ£¬Ö§³Ö½öÓÐcidºÍip_typeµÄcgdcontÃüÁ´ËʱapnΪ¿Õ
+int cgdcont_fwd_ok_act(char *at_paras, struct at_context *context)
+{
+ char apn[APN_MAX_LEN] = {0};
+ char ip_type[IPTYPE_MAX_LEN] = {0};
+ char c_id[4] = {0};
+ int idx = 0;
+ char *strch = NULL;
+
+ at_paras = context->app_param;
+
+ at_print(AT_DEBUG, "wzf:Enter cgdcont_fwd_ok_act\n");
+ if(get_apn_param(at_paras,apn,APN_MAX_LEN,ip_type,IPTYPE_MAX_LEN) < 0)
+ {
+#ifdef HAVE_MODEM_IN_CORE
+ int cid = atoi(at_paras);
+ if(cid > 0 && cid <= CID_MAX_NUM)
+ {//È¥¶¨ÒåcgdcontʱÇå³ý
+ if(CID_ARRAY[cid-1].state != CID_IDLE){softap_assert("");}
+ memset(CID_ARRAY[cid-1].apn ,0x00, APN_MAX_LEN);
+ memset(CID_ARRAY[cid-1].ip_type, 0x00, IPTYPE_MAX_LEN);
+ }
+#endif
+ free(at_paras);
+ context->app_param = NULL;
+ return AT_END;
+ }
+
+ strch = strchr(at_paras, ',');
+ if((strch-at_paras)>0&&(strch-at_paras)<4){
+ snprintf(c_id,(int)(strch-at_paras+1),"%s",at_paras);
+ //strncpy(c_id, at_paras, (int)(strch-at_paras));
+ }
+#ifdef HAVE_MODEM_IN_CORE
+ idx= get_idx_bycid(atoi(c_id));
+ at_print(AT_DEBUG, "cid:%d, idx:%d\n", atoi(c_id),idx);
+ if(idx < 0)
+ {
+ free(at_paras);
+ context->app_param = NULL;
+ return AT_END;
+ }
+ at_print(AT_DEBUG, "apn:%s, ip_type:%s, cid:%d\n", apn, ip_type, atoi(c_id));
+
+ if(CID_ARRAY[idx].state != CID_IDLE){softap_assert("");}
+
+ memcpy(CID_ARRAY[idx].apn, apn, APN_MAX_LEN);
+ memcpy(CID_ARRAY[idx].ip_type, ip_type, IPTYPE_MAX_LEN);
+#endif
+ free(at_paras);
+ context->app_param = NULL;
+ return AT_END;
+}
+
+int cgdcont_fwd_err_act(char *at_paras, struct at_context *context)
+{
+ free(context->app_param);
+ context->app_param = NULL;
+ return AT_END;
+}
+
+
+int zgpcoauth_ok_act(char *at_paras,struct at_context *context,void **next_req,int *next_len)
+{
+ at_print(AT_DEBUG,"zgpcoauth_ok_act msg_id=%x\n",context->msg_id);
+ char *at_next = NULL;
+ if(context->msg_id == MSG_CMD_PDP_ACT_REQ)
+ {
+ PDP_PRIVATE_INFO *private_info = (PDP_PRIVATE_INFO *)(context->app_param);
+ struct pdp_act_req *p_setInfo = (struct pdp_act_req *)(&private_info->pdpActInfo);
+ int auth_type = p_setInfo->comm_info.auth_type;
+ //¼Ç¼µ±Ç°ÈÏÖ¤ÐÅÏ¢
+ int idx = get_idx_bycid(private_info->c_id);
+ if(idx < 0)
+ return AT_END;
+ CID_ARRAY[idx].auth_type = auth_type;
+
+ at_next=(char *)malloc(PDP_CMD_LEN);
+ if(at_next == NULL){
+ softap_assert("");
+ return AT_END;
+ }
+ memset(at_next, 0, PDP_CMD_LEN);
+ if(auth_type == NONE_AUTH || PPP_NONE_AUTH == auth_type || private_info->auth_state == PDP_ADD_AUTH)
+ {
+ snprintf(at_next,PDP_CMD_LEN, "at+cgdcont=%d,\"%s\",\"%s\",,,,,%d,%d,%d\r\n", private_info->c_id, p_setInfo->comm_info.ip_type,
+ p_setInfo->comm_info.apn, p_setInfo->volte_param1, p_setInfo->volte_param2, p_setInfo->volte_param3);
+ private_info->auth_state = PDP_ADD_AUTH;
+ }
+ else if((PAP_AUTH == auth_type || CHAP_AUTH == auth_type || PAP_CHAP_AUTH == auth_type) && private_info->auth_state == PDP_DEL_AUTH)
+ {
+ //Ìí¼ÓÈÏÖ¤ÏûÏ¢£¬ÈÏÖ¤³É¹¦ºó£¬½øÐÐcgact²¦ºÅ
+ private_info->auth_state = PDP_ADD_AUTH;
+ snprintf(at_next,PDP_CMD_LEN,"AT+ZGPCOAUTH=%d,\"%s\",\"%s\",%d\r\n", private_info->c_id, p_setInfo->comm_info.username, p_setInfo->comm_info.password, p_setInfo->comm_info.auth_type);
+ }
+ else if(PPP_CHAP_AUTH == auth_type)
+ {
+ char strPwd[66*2] = {0};
+ char strChallenge[60*2] = {0};
+ //Ìí¼ÓÈÏÖ¤ÏûÏ¢£¬ÈÏÖ¤³É¹¦ºó£¬½øÐÐcgact²¦ºÅ
+ private_info->auth_state = PDP_ADD_AUTH;
+ bytes2string((unsigned char*)p_setInfo->comm_info.password,strPwd,strlen(p_setInfo->comm_info.password));
+ bytes2string((unsigned char*)p_setInfo->comm_info.challenge,strChallenge,strlen(p_setInfo->comm_info.challenge));
+ at_print(AT_ERR, "CHAP pw=%s,challenge=%s",strPwd,strChallenge);
+ snprintf(at_next,PDP_CMD_LEN,"AT+ZGPCOCHAP=%d,\"%s\",%s,%s\r\n", private_info->c_id, p_setInfo->comm_info.username, strChallenge, strPwd);
+ }
+ else
+ {
+ softap_assert("");
+ }
+
+ *next_req = at_next;
+ *next_len = strlen(*next_req);
+ return AT_CONTINUE;
+ }
+
+
+ return AT_END;
+}
+
+int zgpcoauth_err_act(char *at_paras,struct at_context *context,void **next_req,int *next_len)
+{
+ switch(context->msg_id)
+ {
+
+ case MSG_CMD_PDP_ACT_REQ:
+ {
+ PDP_PRIVATE_INFO *private_info = (PDP_PRIVATE_INFO *)context->app_param;
+ int idx = get_idx_bycid(private_info->c_id);
+ pdpact_failed_proc(at_paras,context,idx, next_req, next_len);
+ }
+ }
+ return AT_END;
+}
+
+int zgpcochap_ok_act(char *at_paras,struct at_context *context,void **next_req,int *next_len)
+{
+ at_print(AT_DEBUG,"zgpcochap_ok_act msg_id=%x\n",context->msg_id);
+ char *at_next = NULL;
+
+ if(context->msg_id == MSG_CMD_PDP_ACT_REQ)
+ {
+ PDP_PRIVATE_INFO *private = (PDP_PRIVATE_INFO *)(context->app_param);
+ struct pdp_act_req *p_setInfo = (struct pdp_act_req *)(&private->pdpActInfo);
+ int cur_cid = private->c_id;
+ at_next=(char *)malloc(AT_CMD_MAX);
+ if(at_next == NULL){
+ softap_assert("");
+ return AT_END;
+ }
+ memset(at_next, 0, AT_CMD_MAX);
+ if(PDP_ADD_AUTH == private->auth_state)
+ {
+ sprintf(at_next, "at+cgdcont=%d,\"%s\",\"%s\",,,,,%d,%d,%d\r\n", cur_cid, p_setInfo->comm_info.ip_type,
+ p_setInfo->comm_info.apn, p_setInfo->volte_param1, p_setInfo->volte_param2, p_setInfo->volte_param3);
+ }
+ else
+ {
+ softap_assert("");
+ }
+ *next_req = at_next;
+ *next_len = strlen(*next_req);
+ return AT_CONTINUE;
+ }
+
+ return AT_END;
+}
+int zgpcochap_err_act(char *at_paras,struct at_context *context,void **next_req,int *next_len)
+{
+ switch(context->msg_id)
+ {
+ case MSG_CMD_PDP_ACT_REQ:
+ {
+ PDP_PRIVATE_INFO *private_info = (PDP_PRIVATE_INFO *)context->app_param;
+ int idx = get_idx_bycid(private_info->c_id);
+ pdpact_failed_proc(at_paras,context,idx, next_req, next_len);
+ }
+ }
+ return AT_END;
+}
+
+//#if (APP_OS_TYPE == APP_OS_TOS)
+/*char *zphone_dataswitchon_act(void *msg,struct at_context *context)
+{
+ char *at_str = NULL;
+ char *p_ipdns = NULL;
+ char *str = (((MSG_BUF *)msg)->aucDataBuf);
+ int cur_cid = atoi(str);
+ struct pdp_active_info *info = g_pdpinfo_mng[cur_cid-1].pdpInfo;
+ if(info == NULL)
+ {
+ at_print(AT_ERR,"zphone_dataswitchon_act: pdpinfo is null, cid %d is deacted by core network\n");
+ return NULL;
+ }
+
+ p_ipdns = malloc(512);
+ if(NULL == p_ipdns) softap_assert("");
+ memset(p_ipdns, 0x00, 512);
+
+ build_ipdns_param(p_ipdns, info);
+ at_str = at_act_build("ZNETIFUP", p_ipdns);
+
+ free(p_ipdns);
+ if(NULL == at_str) softap_assert("");
+
+ at_print(AT_ERR,"zphone_dataswitchon_act: begin to up AP network, at_str = %s\n", at_str);
+
+ return at_str;
+
+}*/
+/*
+char *zphone_dataswitchoff_act(void *msg,struct at_context *context)
+{
+ char *at_str = NULL;
+ char *str = (((MSG_BUF *)msg)->aucDataBuf);
+ at_str = at_act_build("ZNETIFDOWN", str);
+
+ at_print(AT_ERR,"zphone_dataswitchoff_act: begin to down AP network, at_str = %s\n", at_str);
+ return at_str;
+
+}*/
+/*char *set_defualt_apn_to_other_core(void *msg,struct at_context *context)
+{
+ char *at_str = NULL;
+
+ at_str = (char *)malloc(80);
+ if(at_str == NULL){softap_assert("");}
+ memset(at_str, 0, 80);
+ memset(g_defcid_mng.default_apn, 0, sizeof(g_defcid_mng.default_apn));
+ cfg_get_item("default_apn", g_defcid_mng.default_apn, sizeof(g_defcid_mng.default_apn));
+ //sprintf(at_str, "at+znvset=default_apn,%s\r\n",g_defcid_mng.default_apn);
+ sprintf(at_str, "default_apn,%s",g_defcid_mng.default_apn);
+ send_otherside_atctl_req(FAR_PS, MSG_CMD_SETNV_TO_AP, strlen(at_str), at_str);
+
+ return at_str;
+}*/
+//#endif
+//#if (APP_OS_TYPE == APP_OS_LINUX)
+/*char *set_defualt_apn_to_other_core(void *msg,struct at_context *context)
+{
+ char *at_str = NULL;
+
+ at_str = (char *)malloc(80);
+ if(at_str == NULL){softap_assert("");}
+ memset(at_str, 0, 80);
+ memset(g_defcid_mng.default_apn, 0, sizeof(g_defcid_mng.default_apn));
+ cfg_get_item("default_apn", g_defcid_mng.default_apn, sizeof(g_defcid_mng.default_apn));
+ sprintf(at_str,"AT+ZDEFAULTAPN=\"%s\"\r\n", g_defcid_mng.default_apn);
+ return at_str;
+}*/
+
+//int znetifup_req(int at_fd, char *at_paras,void ** res_msg, int *res_msglen)
+#ifdef MULTI_CPU
+void znetifup_proc(char *at_paras)
+{
+ int cid = 0;
+
+ at_print(AT_DEBUG,"znetifup_req: begin to up network, at_paras = %s\n", at_paras);
+
+ cid = parse_ipdns_param(at_paras);
+ if(cid > 0 && cid<= CID_MAX_NUM)
+ pdp_act_proc_for_module(g_pdpinfo_mng[cid-1].pdpInfo, PDP_NORMAL);
+
+ cfg_set(NV_PDP_STATUS, "1");
+ ipc_send_message(MODULE_ID_AT_CTL, MODULE_ID_ISMS, MSG_CMD_PDP_STATUS_IND, 2, "1", 0);
+ ipc_send_message(MODULE_ID_AT_CTL, MODULE_ID_DMREG, MSG_CMD_PDP_STATUS_IND, 2, "1", 0);
+ ipc_send_message(MODULE_ID_AT_CTL, MODULE_ID_SAFECARE, MSG_CMD_PDP_STATUS_IND, 2, "1", 0);
+}
+
+
+//int znetifdown_req(int at_fd, char *at_paras,void ** res_msg, int *res_msglen)
+void znetifdown_proc(char *at_paras)
+{
+ char temp[2] = {0};
+ temp[0]=at_paras[0];
+
+ int c_id = atoi(temp);
+
+ at_print(AT_DEBUG,"znetifdown_req: begin to down network, at_paras = %d\n", c_id);
+
+ pdpinfo_reset(c_id);
+
+ cfg_set(NV_PDP_STATUS, "0");
+ ipc_send_message(MODULE_ID_AT_CTL, MODULE_ID_ISMS, MSG_CMD_PDP_STATUS_IND, 2, "0", 0);
+ ipc_send_message(MODULE_ID_AT_CTL, MODULE_ID_DMREG, MSG_CMD_PDP_STATUS_IND, 2, "0", 0);
+ ipc_send_message(MODULE_ID_AT_CTL, MODULE_ID_SAFECARE, MSG_CMD_PDP_STATUS_IND, 2, "0", 0);
+}
+#endif
+//#endif
+//ÖØÐ·¢Æðpdp¼¤»î
+int proc_pdpreconnect_req()
+{
+ //MSG_BUF *msg_buf = NULL;
+ //char creg_stat[20] = {0};
+ char ppp_status[20] = {0};
+ //int ret = 0;
+ /*cfg_get_item("creg_stat", creg_stat, sizeof(creg_stat));
+ at_print(AT_DEBUG,"@@@@@@@@@@@@@proc_pdpreconnect_req creg stat=%s!\n",creg_stat);
+ if(1 != atoi(creg_stat) && 5 != atoi(creg_stat))
+ {
+ return 0 ;
+ }*/
+ char creg_stat[20] = {0};
+ char cereg_stat[20] = {0};
+
+ cfg_get_item("cgreg_stat", creg_stat, sizeof(creg_stat));
+ cfg_get_item("cereg_stat", cereg_stat, sizeof(cereg_stat));
+ at_print(AT_DEBUG,"@@@@@@@@@@@@@proc_pdpreconnect_req creg stat=%s, cereg stat=%s!\n",creg_stat,cereg_stat);
+ //zpr 1218 CS&EPS¶¼×¢²áʧ°Ü£¬²»·¢Æð
+ if(1 != atoi(creg_stat) && 5 != atoi(creg_stat) && 1 != atoi(cereg_stat) && 5 != atoi(cereg_stat))
+ {
+ return 0;
+ }
+
+ if((0 == check_is_fd(g_defcid_mng.modid)) && (g_defcid_mng.modid != 0))
+ {
+ cfg_get_item(NV_PPP_STATUS, ppp_status, sizeof(ppp_status));
+ if(0 == strcmp(PPP_DISCONNECTED, ppp_status))
+ {
+ //À´×ÔÓÚweb ui»òÕßÖ÷¿ØµÄpdp¼¤»î£¬ÏûÏ¢ÄÚÈݳ¤¶ÈΪ0£¬ÄÚÈÝΪ¿Õ£¬ÕâÀï×öÌØÊâ¶¨ÖÆ
+ if(g_defcid_mng.modid == MODULE_ID_WEB_CGI || g_defcid_mng.modid == MODULE_ID_MAIN_CTRL)
+ ipc_send_message(g_defcid_mng.modid, MODULE_ID_AT_CTL, MSG_CMD_PDP_ACT_REQ, 0, NULL, IPC_NOWAIT);
+ else
+ ipc_send_message(g_defcid_mng.modid, MODULE_ID_AT_CTL, MSG_CMD_PDP_ACT_REQ, sizeof(struct pdp_act_req), (unsigned char *)g_defcid_mng.set_info, IPC_NOWAIT);
+
+ //free(msg_buf);
+ //msg_buf = NULL;
+ }
+ }
+ return 0;
+
+}
+
+void start_pdp_auto_dial(void)
+{
+ char auto_reconnect [20] = {0};
+ char reconnect_type[20] = {0};
+
+ cfg_get_item("reconnect_type", reconnect_type, sizeof(reconnect_type));
+ cfg_get_item("auto_reconnect", auto_reconnect, sizeof(auto_reconnect));
+ //µ±Ç°Ä¬ÈÏapnµÄpdp¼¤»îÇëÇóÒÑ´æÔÚ£¬Ôò˵Ã÷ĬÈÏapn¿Ï¶¨ÒѾ·¢Æð¹ýpdp¼¤»î
+ at_print(AT_DEBUG,"@@@@@@@@@@@@@start_pdp_auto_dial g_pdp_set_info=0x%p, auto_connect is %s!\n",g_defcid_mng.set_info, auto_reconnect);
+ if((0 == check_is_fd(g_defcid_mng.modid)) && 0 == strcmp(auto_reconnect,"1"))
+ {
+ at_print(AT_DEBUG,"@@@@@@@@@@@@@start_pdp_auto_dial: apn is %s, modid is %x!\n", g_defcid_mng.set_info->comm_info.apn, g_defcid_mng.modid);
+ //ÊÕµ½×¤Íø³É¹¦ºó£¬ÉèÖÃÒ»¸ö5s¶¨Ê±Æ÷£¬³¬Ê±ºó½øÐÐpdp²¦ºÅÇëÇó
+ if(0 == strcmp(reconnect_type,"simple"))
+ {
+ MSG_BUF *msg_buf = NULL;
+ char ppp_status[20] = {0};
+ cfg_get_item(NV_PPP_STATUS, ppp_status, sizeof(ppp_status));
+ if(0 == strcmp(PPP_DISCONNECTED, ppp_status))
+ {
+ set_pppstatus(PPP_CONNECTING);
+ msg_buf=normal_getmsg(g_defcid_mng.modid ,MODULE_ID_AT_CTL,MSG_CMD_PDP_ACT_REQ,sizeof(struct pdp_act_req), (unsigned char *)g_defcid_mng.set_info);
+ rcv_msg_proc(msg_buf);
+ free(msg_buf);
+ msg_buf = NULL;
+ }
+ }
+ else
+ {
+ at_timeout_reset_pdpreconn_time();
+ at_timeout_start_pdpreconn_timer();
+ }
+ }
+}
+//int g_flag =0;
+
+int cgdcont_auto_act(char *at_paras ,int is_query_report)
+{
+ char versionmode[2] = {0};
+ cfg_get_item("version_mode", versionmode, sizeof(versionmode));
+
+ //·ÇоƬÈÏÖ¤°æ±¾£¬¶ÔÓÚat+cgdcont?ÃüÁî²»×ö½âÎö
+ //g_flag++;
+ if(0 == strcmp(versionmode, "0"))
+ return AT_END;
+
+ char apn[APN_MAX_LEN] = {0};
+ char ip_type[IPTYPE_MAX_LEN] = {0};
+ int c_id = 0;
+ int idx = 0;
+ void *p[] = {&c_id,ip_type,apn};
+ //g_flag++;
+
+ int ret = parse_param("%d,%s,%s",at_paras,p);
+ if (ret != AT_PARSE_OK)
+ return AT_END;
+
+ idx= get_idx_bycid(c_id);
+ if(idx < 0)
+ return AT_END;
+ memcpy(CID_ARRAY[idx].apn, apn, APN_MAX_LEN);
+ memcpy(CID_ARRAY[idx].ip_type, ip_type, IPTYPE_MAX_LEN);
+ return AT_END;
+}
+
+char *start_query_cgcontrdp(void *msg,struct at_context *context)
+{
+ char *at_next=NULL;
+ at_next=malloc(64);
+ if(at_next == NULL){
+ softap_assert("");
+ return NULL;
+ }
+ memset(at_next,0,64);
+ sprintf(at_next,"AT+CGCONTRDP=%d\r\n",def_attach_cid_index+1);
+ return at_next;
+}
+
+int cgcontrdp_auto_act(char *at_paras ,int is_query_report)
+{
+ int ret = 0;
+ int cid,bearid;
+ char apn[256]= {0};
+ void *p[3] = {&cid, &bearid, apn};
+ at_print(AT_ERR,"@@!!@@cgcontrdp_auto_act at_paras=%s!\n",at_paras);
+ ret = parse_param("%d,%d,%255s", at_paras, p);
+ if (ret != AT_PARSE_OK)
+ return AT_END;
+ if(at_strstr(apn,"ims") != NULL)
+ {
+ apn_is_ims = 1;
+ }
+ else
+ {
+ apn_is_ims = 0;
+ }
+ at_print(AT_ERR,"@@!!@@cgcontrdp_auto_act ims=%d cid=%d apn=%s!\n",apn_is_ims,cid,apn);
+ return AT_END;
+}
+
+int cgcontrdp_err_act(char *at_str,struct at_context *context,void **next_req,int *next_len)
+{
+ apn_is_ims = 0;
+ return AT_END;
+}
+
+
+
diff --git a/lynq/S300/BJMTN/ap/app/zte_comm/zte_locknet/src/zctrm_locknet_main.c b/lynq/S300/BJMTN/ap/app/zte_comm/zte_locknet/src/zctrm_locknet_main.c
new file mode 100755
index 0000000..ed4968f
--- /dev/null
+++ b/lynq/S300/BJMTN/ap/app/zte_comm/zte_locknet/src/zctrm_locknet_main.c
@@ -0,0 +1,90 @@
+#include <stdio.h>
+#include <unistd.h>
+#include "zctrm_locknet.h"
+
+int sendflag = 0;
+void locknet_msg_proc(MSG_BUF *msg_buf)
+{
+ switch (msg_buf->usMsgCmd) {
+ case MSG_CMD_LOCKLISTAUTH_REQ:
+ zCtrm_LocknetAuthProc(msg_buf);
+ break;
+
+ case MSG_CMD_LOCKNETLIST_SET_REQ:
+ zCtrm_LocknetListSet(msg_buf);
+ break;
+
+ case MSG_CMD_LOCKNETKEY_REQ:
+ zCtrm_LocknetKeyProc(msg_buf);
+ break;
+
+ case MSG_CMD_LOCKNETAMTSTATUS_GET_REQ:
+ zCtrm_LocknetAmtStatus(msg_buf);
+ break;
+
+ case MSG_CMD_LOCKNETDIGEST_GET_REQ:
+ zCtrm_LocknetDigestGet(msg_buf);
+ break;
+
+ case MSG_CMD_LOCKNETSIGN_SET_REQ:
+ zCtrm_LocknetSignSet(msg_buf);
+ break;
+
+ case MSG_CMD_LOCKNETLEVEL_GET_REQ:
+ zCtrm_LocknetLevel(msg_buf);
+ break;
+
+ case MSG_CMD_LOCKNETLIST_GET_REQ:
+ zCtrm_LocknetListGetProc(msg_buf);
+ break;
+
+ case MSG_CMD_LOCKNETAUTH_REQ:
+ sendflag = 1;
+ zCtrm_makeLocknetAuth(msg_buf);
+ break;
+
+ case MSG_CMD_LOCKNETUNLOCKTIMES_GET_REQ:
+ zCtrm_LocknetUnlockTimes(msg_buf);
+ break;
+
+ case MSG_CMD_LOCKNETSTATUS_GET_REQ:
+ zCtrm_LocknetStatus(msg_buf);
+ break;
+
+ case MSG_CMD_LOCKNETUNLOCK_REQ:
+ zCtrm_LocknetUnlock(msg_buf);
+ break;
+ case MSG_CMD_ZURDY_LOCKAUTH_REQ:
+ zCtrm_makeLocknetAuth(msg_buf);
+ break;
+ default:
+ break;
+ }
+}
+
+int zte_locknet_main(int argc, char* argv[])
+{
+ int msg_handle = 0;
+ MSG_BUF msg;
+ LONG msg_size = sizeof(MSG_BUF)-sizeof(LONG);
+ prctl(PR_SET_NAME, "locknet", 0, 0, 0);
+ /* ´´½¨ÏûÏ¢¶ÓÁÐ*/
+ msg_handle = msgget(MODULE_ID_LOCKNET, IPC_CREAT|0600);
+ while(1)
+ {
+ memset(&msg, 0x00, sizeof(MSG_BUF));
+
+ /* »ñÈ¡ÏûÏ¢¶ÓÁÐÏûÏ¢²¢´¦Àí*/
+ if (msgrcv(msg_handle, &msg, msg_size, 0, 0) >= 0)
+ {
+ locknet_msg_proc(&msg);
+ }
+ else
+ {
+ if(errno != EINTR)
+ slog(AT_PRINT,SLOG_ERR,"locknet_main msgrcv errno = %d, errmsg = %s\n", errno,strerror(errno));
+ }
+ }
+
+ return 0;
+}
diff --git a/lynq/S300/BJMTN/ap/app/zte_comm/zte_locknet/src/zctrm_locknet_proc.c b/lynq/S300/BJMTN/ap/app/zte_comm/zte_locknet/src/zctrm_locknet_proc.c
new file mode 100755
index 0000000..8407539
--- /dev/null
+++ b/lynq/S300/BJMTN/ap/app/zte_comm/zte_locknet/src/zctrm_locknet_proc.c
@@ -0,0 +1,2222 @@
+#include "zctrm_locknet.h"
+//#include "drvs_efuse.h"
+#include "zctrm_ln_rsa.h"
+#include "zctrm_ln_md5.h"
+#include "RONvParam_AMT.h"
+//#include "ps_normal.h"
+//#include "ps_wifi.h"
+#include <limits.h>
+
+static BOOL g_IsDigestKeyGot = FALSE;
+static BOOL g_IsSetListKeyGot = FALSE;
+
+static BOOL g_IsSetListAuthSucc = FALSE;
+static BOOL g_NeedSecondList = FALSE;
+static BOOL g_IsKeyExist = FALSE;
+static BOOL g_IsDigestGotSucc = FALSE;
+
+static BOOL g_IsUnlockKeyGot = FALSE;
+static UINT8 g_UnlockKeyPlaint[LOCKNET_KEY_LEN+1] = {0};
+
+static UINT8 g_SetListPlaint[LOCKNET_KEY_LEN+1] = {0};
+
+static T_ZDrvEfuse_Secure g_Efuse_Secure={0};
+
+T_zCtrm_LockListPara simLockListPara = {0};
+T_zCtrm_SIMPara simPara = {0};
+SINT32 g_Sec_Status = ENCRYPT_INITING;
+extern int sendflag;
+
+SINT32 zCtrm_Atohex(CHAR c)
+{
+ SINT32 result = 0;
+
+ if(c >= '0' && c <= '9')
+ {
+ result = c - '0';
+ }
+ else if(c>='a' && c<='f')
+ {
+ result = (c - 'a') + 10;
+ }
+ else if(c>='A' && c<='F')
+ {
+ result = (c - 'A') + 10;
+ }
+ else
+ {
+ at_print(AT_ERR,"zCtrm_Atohex error,can unknown char:%c\n",c);
+ return result;
+ }
+ return result;
+}
+
+static SINT32 zCtrm_Strnicmp(const CHAR * cs,const CHAR * ct,UINT32 count)
+{
+ SINT32 res = 0;
+
+ while (count)
+ {
+ if ((res = toupper(*cs)- toupper(*ct++)) != 0 || !*cs++)
+ break;
+ count--;
+ }
+
+ return res;
+}
+VOID ConvertToBigEndian(unsigned int *data)
+{
+ *data = ((*data & 0xff000000) >> 24)
+ | ((*data & 0x00ff0000) >> 8)
+ | ((*data & 0x0000ff00) << 8)
+ | ((*data & 0x000000ff) << 24) ;
+}
+
+static UINT32 zCtrm_Bytes2String(const UINT8* pSrc, CHAR* pDst, UINT16 srcLength)
+{
+ const UINT8 tab[]="0123456789ABCDEF";
+ int iSrc=0;
+
+#if 1 // cov M srcLength is unsigned
+ if(pSrc == NULL || pDst == NULL )
+ {
+ return -1;
+ }
+
+#else
+ if(pSrc == NULL || pDst == NULL || srcLength < 0)
+ {
+ return -1;
+ }
+#endif
+ for(iSrc=0; iSrc<srcLength; iSrc++)
+ {
+ *pDst++ = tab[*pSrc >> 4];
+ *pDst++ = tab[*pSrc & 0x0f];
+ pSrc++;
+ }
+
+ *pDst = '\0';
+
+ return srcLength * 2;
+}
+
+static UINT32 makeLocknetKeyRandom(VOID)
+{
+ UINT32 val = 0;
+ UINT32 seed = (UINT32)time( NULL );
+ int fd = open("/dev/urandom",O_RDONLY);
+
+ if(fd >= 0)
+ {
+ int i = 0;
+ UINT32 rand = 0;
+ for(i = 0; i < 128; i++)
+ {
+ if(read(fd, &rand, sizeof(rand)) > 0)
+ {
+ if(rand > UINT_MAX-1) // kw 3 cov M
+ {
+ rand = UINT_MAX;
+ }
+ seed += rand;
+ if(seed > UINT_MAX-1) // kw 3 cov M
+ {
+ seed = UINT_MAX;
+ }
+ }
+ }
+ close(fd);
+ }
+
+ srand(seed);
+ val = rand() + (rand() ^ 2) + 1;
+ val %= 100000000;
+
+ return val;
+}
+
+static VOID zCtrm_LocknetKeyGen(UINT8 *plainText, UINT16 len)
+{
+ UINT32 r1 = 0;
+ UINT32 r2 = 0;
+ UINT8 key[LOCKNET_KEY_LEN + 1] = {0};
+
+ r1 = makeLocknetKeyRandom();
+ r2 = makeLocknetKeyRandom();
+ snprintf((char *)key, sizeof(key),"%08ld%08ld", r1, r2);
+ memcpy(plainText, key, len);
+ at_print(AT_ERR,"zCtrm_LocknetKeyGen:plainText = %s\n",plainText);
+}
+
+static UINT32 zCtrm_RsaPublicEncrypt(const UINT8 *plainText, UINT8 *cipherText,const char *rsa_n,const char *rsa_e)
+{
+ rsa_context rsa;
+
+ rsa_init(&rsa, RSA_PKCS_V15, 0);
+
+ rsa.len = KEY_LEN;
+ mpi_read_string(&rsa.N, 16, rsa_n);
+ mpi_read_string(&rsa.E, 16, rsa_e);
+
+ if(rsa_check_pubkey(&rsa) != 0)
+ {
+ at_print(AT_ERR,"Encode check failed\n");
+ return EXT_ERROR;
+ }
+ if(rsa_public(&rsa, plainText, cipherText) != 0)
+ {
+ at_print(AT_ERR,"Encode check failed\n");
+ return EXT_ERROR;
+ }
+ rsa_free(&rsa);
+
+ at_print(AT_ERR,"Encode passed\n");
+ return EXT_SUCCESS;
+}
+
+//½«´ÓefuseÖжÁÈ¡µÄ¹«Ô¿²ÎÊý£¬½øÐдóС¶Ë´æ´¢×ª»»(±¾ÉíΪС¶Ë´æ´¢)
+UINT32 zCtrm_RsaPublicEncryptProc(const UINT8 *plainText, UINT8 *cipherText)
+{
+ UINT32 retCode = EXT_ERROR;
+ unsigned int i;
+ UINT32 pubKeyRsaEOrder[32]={0};
+ UINT32 pubKeyRsaNOrder[32]={0};
+ char pubKeyRsaEtext[KEY_LEN*2+1]={0};
+ char pubKeyRsaNtext[KEY_LEN*2+1]={0};
+ int efuse_fd = -1;
+ int ret = -1;
+
+ memset(&g_Efuse_Secure,0,sizeof(g_Efuse_Secure));
+
+ efuse_fd = open("/dev/efuse", O_RDWR);
+ if (efuse_fd < 0) {
+ at_print(AT_ERR,"zCtrm_RsaPublicEncryptProc: efuse fd_func open fail.\n");
+ return EXT_ERROR;//klocwork
+ }
+
+ ret = ioctl(efuse_fd , EFUSE_GET_DATA, &g_Efuse_Secure);
+
+ at_print(AT_ERR,"[zCtrm_RsaPublicEncryptProc]: pubKeyRsaE[%x] pubKeyRsaN[%x]\n",ret,g_Efuse_Secure.pubKeyRsaE[31],g_Efuse_Secure.pubKeyRsaN[0]);
+ close(efuse_fd);//klocwork
+ /*if(g_Efuse_Secure.pubKeyRsaN ==NULL || g_Efuse_Secure.pubKeyRsaE ==NULL)
+ {
+ at_print(AT_ERR,"Rsa NULL\n");
+ return EXT_ERROR;
+ }*/
+
+ memcpy(pubKeyRsaEOrder,g_Efuse_Secure.pubKeyRsaE,sizeof(g_Efuse_Secure.pubKeyRsaE));
+ for(i=0;i<32;i++)
+ {
+ ConvertToBigEndian(&pubKeyRsaEOrder[i]);
+ }
+ zCtrm_Bytes2String(pubKeyRsaEOrder, pubKeyRsaEtext, KEY_LEN);
+
+ memcpy(pubKeyRsaNOrder,g_Efuse_Secure.pubKeyRsaN,sizeof(g_Efuse_Secure.pubKeyRsaN));
+ for(i=0;i<32;i++)
+ {
+ ConvertToBigEndian(&pubKeyRsaNOrder[i]);
+ }
+ zCtrm_Bytes2String(pubKeyRsaNOrder, pubKeyRsaNtext, KEY_LEN);
+
+ at_print(AT_ERR,"zCtrm_RsaPublicEncryptProc:RsaN = %s\n",pubKeyRsaNtext);
+ at_print(AT_ERR,"zCtrm_RsaPublicEncryptProc:RsaE = %s\n",pubKeyRsaEtext);
+
+ return zCtrm_RsaPublicEncrypt(plainText,cipherText,pubKeyRsaNtext,pubKeyRsaEtext);
+}
+
+static BOOL zCtrm_IsParaNum(UINT8 *data, UINT16 dataLen)
+{
+ UINT16 idata = 0;
+
+ if(*data == '\0')
+ {
+ return TRUE;
+ }
+
+ for(idata = 0; idata < dataLen; idata++)
+ {
+ if(*data < '0' || *data > '9')
+ {
+ at_print(AT_ERR,"zCtrm_IsParaNum error:%c!\n",*data);
+ return FALSE;
+ }
+ data++;
+ }
+ return TRUE;
+}
+
+static UINT32 zCtrm_CheckListPara(UINT8 *data, UINT16 dataLen)
+{
+ UINT8 *pBegin = data;
+ UINT8 *pEnd = NULL;
+ UINT16 subLen = 0;
+ UINT16 iPara = 0;
+
+ for(iPara = 0; iPara < LOCKNET_ITEM_NUM; iPara++)
+ {
+ if(iPara < LOCKNET_ITEM_NUM - 1)
+ {
+ pEnd = strchr(pBegin,',');
+ if (pEnd == NULL)//klocwork
+ return EXT_ERROR;
+ subLen = pEnd - pBegin;
+ }
+ else
+ {
+ subLen = dataLen - (pBegin - data);
+ }
+
+ switch(iPara)
+ {
+ case PARA_MCC:
+ case PARA_MNC:
+ {
+ if(subLen > 3 || FALSE == zCtrm_IsParaNum(pBegin,subLen))
+ {
+ return EXT_ERROR;
+ }
+ break;
+ }
+ case PARA_IMSI6:
+ case PARA_IMSI7:
+ {
+ if(subLen > 1 || FALSE == zCtrm_IsParaNum(pBegin,subLen))
+ {
+ return EXT_ERROR;
+ }
+ break;
+ }
+ case PARA_GID1:
+ case PARA_GID2:
+ {
+ if(subLen > USED_GID_LEN) //one at, need opt
+ {
+ return EXT_ERROR;
+ }
+ break;
+ }
+ default:
+ {
+ return EXT_ERROR;
+ }
+ }
+
+ pBegin = pEnd + 1;
+ }
+
+ return EXT_SUCCESS;
+}
+
+static UINT32 zCtrm_CheckListNum(UINT8 *data, UINT16 dataLen, UINT16 *listnum)
+{
+ UINT8 *pBegin = NULL;
+ UINT8 *pEnd = NULL;
+ UINT16 iData = 0;
+ UINT16 count = 0;
+ UINT16 maxNum = LOCKNET_FIRST_NUM;
+
+ pBegin=data;
+ for(iData = 0; iData < dataLen; iData++)
+ {
+ if(*pBegin == ';')
+ {
+ count++;
+ }
+ pBegin++;
+ }
+
+ if(g_NeedSecondList == TRUE)
+ {
+ maxNum = LOCKNET_MAX_NUM - LOCKNET_FIRST_NUM;
+ }
+
+ if(count < 1 || count > maxNum)
+ {
+ return EXT_ERROR;
+ }
+
+ pEnd=strrchr(data,';');
+ if (pEnd == NULL)//klocwork
+ return EXT_ERROR;
+ if(('\0' == *(char *)(pEnd+1))||(0 == strncmp(pEnd+1,"next",strlen("next")) && count == LOCKNET_FIRST_NUM) )
+ {
+ *listnum = count;
+ at_print(AT_ERR,"zCtrm_CheckListNum pEnd:--%s--\n",pEnd);
+ return EXT_SUCCESS;
+ }
+
+ at_print(AT_ERR,"zCtrm_CheckListNum err:--%s--\n",pEnd);
+ return EXT_ERROR;
+
+}
+
+static VOID zCtrm_GetListPara(UINT8 *data, UINT16 dataLen, T_zCtrm_LockListPara *para)
+{
+ UINT8 *pBegin = data;
+ UINT8 *pEnd = NULL;
+ UINT16 subLen = 0;
+ UINT16 iPara = 0;
+
+ for(iPara = 0; iPara < LOCKNET_ITEM_NUM; iPara++)
+ {
+ if(iPara < LOCKNET_ITEM_NUM -1)
+ {
+ pEnd = strchr(pBegin,',');
+ if (pEnd == NULL)//klocwork
+ return;
+ subLen = pEnd - pBegin;
+ }
+ else
+ {
+ subLen = dataLen - (pBegin - data);
+ }
+
+ switch(iPara)
+ {
+ case PARA_MCC:
+ {
+ if (subLen < sizeof(para->mcc)) {//klocwork
+ memset(para->mcc,0,sizeof(para->mcc));
+ snprintf(para->mcc,subLen+1,"%s",pBegin);
+ //strncpy(para->mcc,pBegin,subLen);
+ }
+ break;
+ }
+ case PARA_MNC:
+ {
+ if (subLen < sizeof(para->mnc)) {
+ memset(para->mnc,0,sizeof(para->mnc));
+ snprintf(para->mnc,subLen+1,"%s",pBegin);
+ //strncpy(para->mnc,pBegin,subLen);
+ }
+ break;
+ }
+ case PARA_IMSI6:
+ {
+ if (subLen < sizeof(para->imsi6)) {
+ memset(para->imsi6,0,sizeof(para->imsi6));
+ snprintf(para->imsi6,subLen+1,"%s",pBegin);
+ //strncpy(para->imsi6,pBegin,subLen);
+ }
+ break;
+ }
+ case PARA_IMSI7:
+ {
+ if (subLen < sizeof(para->imsi7)) {
+ memset(para->imsi7,0,sizeof(para->imsi7));
+ snprintf(para->imsi7,subLen+1,"%s",pBegin);
+ //strncpy(para->imsi7,pBegin,subLen);
+ }
+ break;
+ }
+ case PARA_GID1:
+ {
+ if (subLen < sizeof(para->gid1)) {
+ memset(para->gid1,0,sizeof(para->gid1));
+ snprintf(para->gid1,subLen+1,"%s",pBegin);
+ //strncpy(para->gid1,pBegin,subLen);
+ }
+ break;
+ }
+ case PARA_GID2:
+ {
+ if (subLen < sizeof(para->gid2)) {
+ memset(para->gid2,0,sizeof(para->gid2));
+ snprintf(para->gid2,subLen+1,"%s",pBegin);
+ //strncpy(para->gid2,pBegin,subLen);
+ }
+ break;
+ }
+ default:
+ {
+ break;
+ }
+ }
+
+ pBegin = pEnd + 1;
+ }
+
+}
+
+static UINT32 zCtrm_CleanAmtList(VOID)
+{
+ UINT32 retCode = EXT_ERROR;
+ UINT16 iList = 0;
+ T_zCtrm_LockListPara lockList = {0};
+
+ memset((UINT8 *)&lockList,0xFF,sizeof(lockList));
+ for(iList = 0; iList < LOCKNET_MAX_NUM; iList++)
+ {
+
+
+ cpnv_ChangeNvRoAttr(1);
+ //retCode = zDrvNand_Program(AMT_LOCKNET_LIST + iList*sizeof(lockList), sizeof(lockList), (UINT8 *)&lockList);
+ retCode = cpnv_NvItemWriteNvro(AMT_LOCKNET_LIST + iList*sizeof(lockList), (UINT8 *)&lockList, sizeof(lockList));
+ cpnv_FsGcWait(FS_NVROFS);
+ cpnv_ChangeNvRoAttr(0);
+ if (EXT_SUCCESS != retCode )
+ {
+ return EXT_ERROR;
+ }
+
+ }
+ return EXT_SUCCESS;
+}
+
+static UINT32 zCtrm_WriteLocklist(UINT8 *data, UINT16 dataLen)
+{
+ UINT8 *pBegin = data;
+ UINT8 *pEnd = NULL;
+ UINT8 tStr[LOCKNET_MAX_AT_LEN] = {0};
+ UINT16 listCount = 0;
+ UINT16 iList = 0;
+ UINT16 offset = 0;
+ UINT32 retCode = EXT_ERROR;
+
+ if(EXT_SUCCESS != zCtrm_CheckListNum(data, dataLen, &listCount))
+ {
+ return EXT_ERROR;
+ }
+ at_print(AT_ERR,"zCtrm_WriteLocklist listcount:%d!\n",listCount);
+
+ if(g_NeedSecondList == TRUE)
+ {
+ offset = LOCKNET_FIRST_NUM;
+ }
+ else
+ {
+ if(zCtrm_CleanAmtList() != EXT_SUCCESS)
+ {
+ return EXT_ERROR;
+ }
+ }
+
+ for(iList = 0; iList < listCount; iList++)
+ {
+ T_zCtrm_LockListPara lockList = {0};
+ unsigned int slen = 0;//klocwork
+
+ pEnd=strchr(pBegin,';');
+ if (pEnd == NULL)//klocwork
+ return EXT_ERROR;
+ slen = pEnd-pBegin;
+ if(slen < sizeof(tStr)) {
+ memset(tStr,0,sizeof(tStr));
+ snprintf(tStr,slen+1,"%s",pBegin);
+ //strncpy(tStr,pBegin,slen);
+ } else {
+ return EXT_ERROR;
+ }
+
+ zCtrm_GetListPara(tStr,slen,&lockList);
+
+ cpnv_ChangeNvRoAttr(1);
+ //retCode = zDrvNand_Program(AMT_LOCKNET_LIST + (offset + iList)*sizeof(lockList), sizeof(lockList), (UINT8 *)&lockList);
+ retCode = cpnv_NvItemWriteNvro(AMT_LOCKNET_LIST + (offset + iList)*sizeof(lockList), (UINT8 *)&lockList, sizeof(lockList));
+ cpnv_FsGcWait(FS_NVROFS);
+ cpnv_ChangeNvRoAttr(0);
+ if (EXT_SUCCESS != retCode )
+ {
+ return EXT_ERROR;
+ }
+
+ pBegin = pEnd + 1;
+ }
+
+ return EXT_SUCCESS;
+}
+
+static UINT32 zCtrm_GetUnlockMaxTime(VOID)
+{
+ UINT32 retCode = EXT_ERROR;
+ UINT32 timet = 0;
+ char time[AT_STR_LEN] = {0};
+ //timet = atoi(cfg_get("zunlocktimes"));
+ cfg_get_item("zunlocktimes", time, sizeof(time));
+ timet = atoi(time);
+ at_print(AT_ERR,"zCtrm_GetUnlockMaxTime:%d---\n" ,timet);
+
+ return timet;
+}
+
+static UINT32 zCtrm_LocknetNandSet(UINT8 *plainText, UINT16 len)
+{
+ T_zCtrm_LockLevel lockState = LOCKED;
+ UINT32 times = zCtrm_GetUnlockMaxTime();
+ UINT32 retCode = EXT_ERROR;
+
+ cpnv_ChangeNvRoAttr(1);
+
+ //retCode = zDrvNand_Program(AMT_LOCKNET_TIMES, sizeof(times),(UINT8 *)×);
+ retCode = cpnv_NvItemWriteNvro(AMT_LOCKNET_TIMES, (UINT8 *)×, sizeof(times));
+ if (EXT_SUCCESS != retCode)
+ {
+ cpnv_ChangeNvRoAttr(0);
+ return EXT_ERROR;
+ }
+
+ //retCode = zDrvNand_Program(AMT_LOCKNET_KEY, len, plainText);
+ retCode = cpnv_NvItemWriteNvro(AMT_LOCKNET_KEY, plainText, len);
+ if (EXT_SUCCESS != retCode)
+ {
+ cpnv_ChangeNvRoAttr(0);
+ return EXT_ERROR;
+ }
+
+ //retCode = zDrvNand_Program(AMT_LOCKNET_BASE, sizeof(lockState),(UINT8 *)&lockState);
+ retCode = cpnv_NvItemWriteNvro(AMT_LOCKNET_BASE, (UINT8 *)&lockState, sizeof(lockState));
+ if (EXT_SUCCESS != retCode)
+ {
+ cpnv_ChangeNvRoAttr(0);
+ return EXT_ERROR;
+ }
+ cpnv_FsGcWait(FS_NVROFS);
+ cpnv_ChangeNvRoAttr(0);
+ return EXT_SUCCESS;
+}
+
+static UINT32 zCtrm_LocknetStaticCheck(VOID)
+{
+ T_zCtrm_LockLevel lockState = LOCKFLAG_ERROR;
+ UINT32 retCode = EXT_ERROR;
+
+ //retCode = zDrvNand_Read(AMT_LOCKNET_BASE,sizeof(lockState),(UINT8 *)&lockState); //len=4
+ retCode = cpnv_NvItemRead(AMT_LOCKNET_BASE, (UINT8 *)&lockState, sizeof(lockState));
+ at_print(AT_ERR,"zCtrm_LocknetStaticCheck ret=%d lockstat=%d\n",retCode,lockState);
+ if (EXT_SUCCESS == retCode)
+ {
+ if(lockState == NEVER_LOCKED)
+ {
+ return EXT_SUCCESS;
+ }
+ }
+
+ return EXT_ERROR;
+}
+
+static UINT32 zCtrm_LocknetListCheck(VOID)
+{
+ T_zCtrm_LockListPara lockList = {0};
+ UINT32 retCode = EXT_ERROR;
+
+ //retCode = zDrvNand_Read(AMT_LOCKNET_LIST, sizeof(lockList), (UINT8 *)&lockList);
+ retCode = cpnv_NvItemRead(AMT_LOCKNET_LIST, (UINT8 *)&lockList, sizeof(lockList));
+ if (EXT_SUCCESS != retCode )
+ {
+ return EXT_ERROR;
+ }
+
+ if((lockList.mcc[0] == 0xFF)||(lockList.imsi6[0] == 0xFF)||(lockList.gid1[0] == 0xFF))
+ {
+ at_print(AT_ERR,"zCtrm_LocknetListCheck FF\n");
+ return EXT_ERROR;
+ }
+
+ return EXT_SUCCESS;
+}
+
+static UINT32 zCtrm_CheckLocklist(UINT8 *data, UINT16 dataLen)
+{
+ UINT8 *pBegin = data;
+ UINT8 *pEnd = NULL;
+ UINT16 iItem = 0;
+ UINT8 *pPara = NULL;
+ UINT16 listCount = 0;
+ UINT16 paraCount = 0;
+
+ if(EXT_SUCCESS != zCtrm_CheckListNum(data, dataLen, &listCount))
+ {
+ return EXT_ERROR;
+ }
+ at_print(AT_ERR,"zCtrm_CheckLocklist listCount = %d\n",listCount);
+
+ for(iItem = 0; iItem < listCount; iItem++)
+ {
+ pEnd = strchr(pBegin,';');
+ if (pEnd == NULL)//klocwork
+ return EXT_ERROR;
+ paraCount = 0;
+ for(pPara = pBegin; pPara < pEnd; pPara++)
+ {
+ if(!((*pPara == ',')||(*pPara>='0'&&*pPara<='9')||(*pPara>='a'&&*pPara<='f')||(*pPara>='A'&&*pPara<='F')))
+ {
+ at_print(AT_ERR,"zCtrm_CheckLocklist error:%c!\n",*pPara);
+ return EXT_ERROR;
+ }
+
+ if(*pPara == ',')
+ {
+ paraCount++;
+ }
+ }
+
+ if(paraCount == LOCKNET_ITEM_NUM - 1)
+ {
+ if(EXT_SUCCESS != zCtrm_CheckListPara(pBegin, pEnd - pBegin))
+ {
+ return EXT_ERROR;
+ }
+ pBegin = pEnd + 1;
+ }
+ else
+ {
+ at_print(AT_ERR,"zCtrm_CheckLocklist count:%d!\n",paraCount);
+ return EXT_ERROR;
+ }
+
+ }
+ at_print(AT_ERR,"zCtrm_CheckLocklist succ!\n");
+ return EXT_SUCCESS;
+}
+
+static UINT32 zCtrm_LocknetDigestMD5Hash(char *psDest)
+{
+ md5_ctx stStc;
+ UINT32 retCode = EXT_ERROR;
+ char TmpImei[ZPS_ImeiLen]={0};//imei³¤¶È×î´óÖµ
+ UINT16 iList = 0;
+ char lockList[LIST_LEN] = {0};
+ UINT8 plainText[KEY_LEN] = {0};
+ UINT8 sTempBuf[16];
+ unsigned int i;
+
+ char PTmpImei[ZPS_ImeiLen*2+1]={0};
+ char PlockList[LIST_LEN*2+1]={0};
+ char PplainText[KEY_LEN*2+1]={0};
+
+ md5_init(&stStc);
+
+ //retCode = zPS_NvAMTItemRead(ABIMEI_NVPARAM, (unsigned char *)TmpImei, ZPS_ImeiLen);
+ retCode = cpnv_NvItemRead(OS_FLASH_AMT_COMM_RO_IMEI_ADDRESS, (unsigned char *)TmpImei, OS_FLASH_AMT_COMM_RO_IMEI_SIZE);
+
+ if (CPNV_ERROR == retCode)
+ {
+ return EXT_ERROR;
+ }
+ zCtrm_Bytes2String(TmpImei, PTmpImei, ZPS_ImeiLen);
+ at_print(AT_ERR,"zCtrm_LocknetDigestMD5Hash TmpImei=%s!\n",PTmpImei);
+ md5_update(&stStc, (unsigned char *)TmpImei, ZPS_ImeiLen);
+
+
+ //ËøÍø²ÎÊý
+ for(iList = 0; iList < LOCKNET_MAX_NUM; iList++)
+ {
+ //retCode = zDrvNand_Read(AMT_LOCKNET_LIST + iList*sizeof(lockList), sizeof(lockList), (UINT8 *)lockList);
+ retCode = cpnv_NvItemRead(AMT_LOCKNET_LIST + iList*sizeof(lockList), (UINT8 *)lockList, sizeof(lockList));
+ if (EXT_SUCCESS != retCode )
+ {
+ return EXT_ERROR;
+ }
+ zCtrm_Bytes2String(lockList, PlockList, LIST_LEN);
+ at_print(AT_ERR,"zCtrm_LocknetDigestMD5Hash lockList=%s!\n",PlockList);
+ md5_update(&stStc, (unsigned char *)lockList, LIST_LEN);
+ }
+
+ //½âËøÂëÃÜÎÄ
+ //retCode = zDrvNand_Read(AMT_LOCKNET_KEY, sizeof(plainText), plainText);
+ retCode = cpnv_NvItemRead(AMT_LOCKNET_KEY, plainText, sizeof(plainText));
+ if (EXT_SUCCESS != retCode)
+ {
+ return EXT_ERROR;
+ }
+ zCtrm_Bytes2String(plainText, PplainText, KEY_LEN);
+ at_print(AT_ERR,"zCtrm_LocknetDigestMD5Hash plainText=%s!\n",PplainText);
+ md5_update(&stStc, (unsigned char *)plainText, KEY_LEN);
+
+ md5_final(sTempBuf, &stStc);
+ for(i = 0; i < 16; i++)
+ {
+ snprintf(psDest + 2*i, 3, "%02x", sTempBuf[i]);
+ }
+ return EXT_SUCCESS;
+}
+
+static UINT32 zCtrm_String2Bytes(const CHAR* pSrc, UINT8* pDst, UINT16 srcLength)
+{
+ int i=0;
+
+ //УÑé²ÎÊý
+#if 1 // cov M srcLength is unsigned
+ if(pSrc == NULL || pDst == NULL)
+ {
+ return -1;
+ }
+#else
+ if(pSrc == NULL || pDst == NULL || srcLength < 0)
+ {
+ return -1;
+ }
+
+#endif
+
+ for(i = 0; i < srcLength; i += 2)
+ {
+ // Êä³ö¸ß4λ
+ if(*pSrc >= '0' && *pSrc <= '9')
+ {
+ *pDst = (*pSrc - '0') << 4;
+ }
+ else
+ {
+ *pDst = ((toupper(*pSrc) - 'A') + 10) << 4;
+ }
+
+ pSrc++;
+
+ // Êä³öµÍ4λ
+ if(*pSrc >= '0' && *pSrc <= '9')
+ {
+ *pDst |= *pSrc - '0';
+ }
+ else
+ {
+ *pDst |= (toupper(*pSrc) - 'A') + 10;
+ }
+
+ pSrc++;
+ pDst++;
+ }
+
+ // ·µ»ØÄ¿±êÊý¾Ý³¤¶È
+ return srcLength / 2;
+}
+
+int zCtrm_LocknetAuthList(char *at_paras)
+{
+ UINT8 *pBegin = NULL;
+ UINT8 *pEnd = NULL;
+ UINT16 keyLen = 0;
+ UINT8 keyBuf[LOCKNET_KEY_LEN+1] = {0};
+ UINT8 *pStrAt = NULL;
+ CHAR at_str[AT_STR_LEN] = {0};
+
+ pStrAt = strstr(at_paras,"a,");
+ if(pStrAt != NULL)
+ {
+ if (g_IsSetListKeyGot != TRUE)
+ {
+ at_print(AT_ERR,"zCtrm_LocknetAuthList:KeyGot false\n");
+ snprintf(at_str,AT_STR_LEN,"\r\n+CME ERROR\r\n");
+ goto end;
+ }
+ pEnd = at_paras+strlen(at_paras);
+
+ pBegin = pStrAt + strlen("a,");
+ keyLen = pEnd - pBegin;
+ if (keyLen != LOCKNET_KEY_LEN)
+ {
+ snprintf(at_str,AT_STR_LEN,"\r\n+CME ERROR\r\n");
+ goto end;
+ }
+ memcpy(keyBuf,pBegin,keyLen);
+ if(memcmp(keyBuf,g_SetListPlaint,keyLen) != 0)
+ {
+ at_print(AT_ERR,"zCtrm_LocknetAuthList:Key error\n");
+ snprintf(at_str,AT_STR_LEN,"\r\n+CME ERROR\r\n");
+ goto end;
+ }
+ snprintf(at_str,AT_STR_LEN,"\r\nOK\r\n");
+ g_IsSetListKeyGot = FALSE;
+ g_IsSetListAuthSucc = TRUE;
+ goto end;
+ }
+ else
+ {
+ snprintf(at_str,AT_STR_LEN,"\r\n+CME ERROR\r\n");
+ goto end;
+ }
+end:
+ send_rsp_str_to_farps(MODULE_ID_LOCKNET, at_str, strlen(at_str));
+ return 0;
+}
+
+int zCtrm_LocknetAuthGen()
+{
+ UINT32 retCode = EXT_ERROR;
+ UINT8 plainText[LOCKNET_KEY_LEN+1] = {0};
+ 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};
+
+ if (g_IsSetListKeyGot != FALSE)
+ {
+ snprintf(at_str,AT_STR_LEN,"\r\n+CME ERROR:Already authorized\r\n");
+ goto end;
+ }
+ zCtrm_LocknetKeyGen(plainText, LOCKNET_KEY_LEN);
+ memcpy(plainText128+KEY_LEN-LOCKNET_KEY_LEN, plainText, LOCKNET_KEY_LEN);
+ retCode = zCtrm_RsaPublicEncryptProc(plainText128, cipherText);
+ if (EXT_SUCCESS != retCode )
+ {
+ snprintf(at_str,AT_STR_LEN,"\r\n+CME ERROR\r\n");
+ goto end;
+ }
+ zCtrm_Bytes2String(cipherText, cipherHex, KEY_LEN);
+
+ memset(g_SetListPlaint,0,sizeof(g_SetListPlaint));
+ //memcpy(g_SetListPlaint,plainText,sizeof(g_SetListPlaint)-1);
+ memcpy(g_SetListPlaint, "locknetcode_lynq",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;
+end:
+ send_rsp_str_to_farps(MODULE_ID_LOCKNET, at_str, strlen(at_str));
+ return 0;
+}
+
+int zCtrm_LocknetAuthProc(MSG_BUF *msg)
+{
+ char at_str[AT_STR_LEN] = {0};
+
+ at_print(AT_ERR,"zCtrm_LocknetAuthProc\n");
+ if('g' == (char*)msg->aucDataBuf[0])
+ {
+ zCtrm_LocknetAuthGen();
+ }
+ else if('a' == (char*)msg->aucDataBuf[0])
+ {
+ zCtrm_LocknetAuthList((char*)msg->aucDataBuf);
+ }
+ else
+ {
+ at_print(AT_ERR,"zCtrm_LocknetAuthProc:param error!!!\n");
+ goto error;
+ }
+ return 0;
+error:
+ snprintf(at_str,AT_STR_LEN,"\r\n+CME ERROR\r\n");
+ send_rsp_str_to_farps(MODULE_ID_LOCKNET, at_str, strlen(at_str));
+ return 0;
+
+}
+
+int zCtrm_LocknetListSet(MSG_BUF *msg)
+{
+ UINT32 retCode = EXT_ERROR;
+ UINT16 dataLen = 0;
+ CHAR at_str[AT_STR_LEN] = {0};
+ char *at_paras = NULL; // cov M PW.BRANCH_PAST_INITIALIZATION
+
+ if (g_IsSetListAuthSucc != TRUE)
+ {
+ snprintf(at_str,AT_STR_LEN,"\r\n+CME ERROR:unauthorized\r\n");
+ goto end;
+ }
+ at_paras = (char*)msg->aucDataBuf;
+ dataLen = strlen(at_paras);
+ at_print(AT_ERR,"dataLen = %d\n",dataLen);
+ retCode = zCtrm_CheckLocklist((char*)msg->aucDataBuf, dataLen);
+ if (EXT_SUCCESS != retCode )
+ {
+ snprintf(at_str,AT_STR_LEN,"\r\n+CME ERROR:invalid parameter\r\n");
+ goto end;
+ }
+ retCode = zCtrm_WriteLocklist(at_paras, dataLen);
+ if (EXT_SUCCESS != retCode )
+ {
+ snprintf(at_str,AT_STR_LEN,"\r\n+CME ERROR:flash failed\r\n");
+ goto end;
+ }
+ if(NULL != strstr(at_paras,"next"))
+ {
+ g_NeedSecondList = TRUE;
+ }
+ else
+ {
+ g_NeedSecondList = FALSE;
+ }
+ snprintf(at_str,AT_STR_LEN,"\r\nOK\r\n");
+ goto end;
+end:
+ send_rsp_str_to_farps(MODULE_ID_LOCKNET, at_str, strlen(at_str));
+ return 0;
+}
+
+int zCtrm_LocknetKeyGenerate()
+{
+ UINT32 retCode = EXT_ERROR;
+ UINT8 plainText[LOCKNET_KEY_LEN+1] = {0};
+ UINT8 plainText128[KEY_LEN] = {0};
+ UINT8 cipherText[KEY_LEN] = {0};
+ CHAR at_str[AT_STR_LEN] = {0};
+ //need open
+ retCode = zCtrm_LocknetStaticCheck();
+ if (EXT_SUCCESS != retCode )
+ {
+ snprintf(at_str,AT_STR_LEN,"\r\n+CME ERROR:locknet already exists\r\n");
+ goto end;
+ }
+
+ retCode = zCtrm_LocknetListCheck();
+ if (EXT_SUCCESS != retCode )
+ {
+ snprintf(at_str,AT_STR_LEN,"\r\n+CME ERROR:missing locknet file\r\n");
+ goto end;
+ }
+ zCtrm_LocknetKeyGen(plainText, LOCKNET_KEY_LEN);
+ at_print(AT_ERR,"zCtrm_ExtLocknetKeyGenerate plainText=%s!\n",plainText);
+ memcpy(plainText128+KEY_LEN-LOCKNET_KEY_LEN, plainText, LOCKNET_KEY_LEN);
+ retCode = zCtrm_RsaPublicEncryptProc(plainText128, cipherText);
+ if (EXT_SUCCESS != retCode )
+ {
+ snprintf(at_str,AT_STR_LEN,"\r\n+CME ERROR:Encrypt error\r\n");
+ goto end;
+ }
+ retCode = zCtrm_LocknetNandSet(cipherText, sizeof(cipherText));
+ if (EXT_SUCCESS != retCode )
+ {
+ snprintf(at_str,AT_STR_LEN,"\r\n+CME ERROR:invalid command\r\n");
+ goto end;
+ }
+ snprintf(at_str,AT_STR_LEN,"\r\nOK\r\n");
+ g_IsKeyExist = TRUE;
+ goto end;
+end:
+ send_rsp_str_to_farps(MODULE_ID_LOCKNET, at_str, strlen(at_str));
+ return 0;
+}
+
+int zCtrm_LocknetDelRand()
+{
+ UINT32 retCode = EXT_ERROR;
+ UINT8 pPtr[KEY_LEN*2+64] = {0};
+ UINT8 plainText[LOCKNET_KEY_LEN+1] = {0};
+ 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};
+
+ if (g_IsUnlockKeyGot != FALSE)
+ {
+ snprintf(at_str,AT_STR_LEN,"\r\n+CME ERROR:Already authorized\r\n");
+ goto end;
+ }
+
+ zCtrm_LocknetKeyGen(plainText, LOCKNET_KEY_LEN);
+ memcpy(plainText128+KEY_LEN-LOCKNET_KEY_LEN, plainText, LOCKNET_KEY_LEN);
+ retCode = zCtrm_RsaPublicEncryptProc(plainText128, cipherText);
+ if (EXT_SUCCESS != retCode )
+ {
+ snprintf(at_str,AT_STR_LEN,"\r\n+CME ERROR\r\n");
+ goto end;
+ }
+
+ zCtrm_Bytes2String(cipherText, cipherHex, KEY_LEN);
+
+ memset(g_UnlockKeyPlaint,0,sizeof(g_UnlockKeyPlaint));
+ memcpy(g_UnlockKeyPlaint,plainText,sizeof(g_UnlockKeyPlaint)-1);
+
+ snprintf(at_str,AT_STR_LEN+KEY_LEN*2,"\r\n+UNLOCKKEY:%s\r\nOK\r\n",cipherHex);
+ g_IsUnlockKeyGot = TRUE;
+ goto end;
+end:
+ send_rsp_str_to_farps(MODULE_ID_LOCKNET, at_str, strlen(at_str));
+ return 0;
+
+}
+
+static UINT32 zCtrm_LocknetNandDel(VOID)
+{
+ T_zCtrm_LockLevel lockState = NEVER_LOCKED;
+ UINT8 keyBuf[KEY_LEN] = {0};
+ UINT32 retCode = EXT_ERROR;
+
+ cpnv_ChangeNvRoAttr(1);
+ memset(keyBuf,0xFF,sizeof(keyBuf));
+ //retCode = zDrvNand_Program(AMT_LOCKNET_KEY, sizeof(keyBuf), keyBuf);
+ retCode = cpnv_NvItemWriteNvro(AMT_LOCKNET_KEY, keyBuf, sizeof(keyBuf));
+ if (EXT_SUCCESS != retCode)
+ {
+ cpnv_ChangeNvRoAttr(0);
+ return EXT_ERROR;
+ }
+
+ //retCode = zDrvNand_Program(AMT_LOCKNET_BASE, sizeof(lockState),(UINT8 *)&lockState);
+ retCode = cpnv_NvItemWriteNvro(AMT_LOCKNET_BASE, (UINT8 *)&lockState, sizeof(lockState));
+ if (EXT_SUCCESS != retCode)
+ {
+ cpnv_ChangeNvRoAttr(0);
+ return EXT_ERROR;
+ }
+ cpnv_FsGcWait(FS_NVROFS);
+ cpnv_ChangeNvRoAttr(0);
+ return EXT_SUCCESS;
+}
+
+int zCtrm_LocknetKeyDelete(char *at_paras)
+{
+ UINT32 retCode = EXT_ERROR;
+ UINT8 *pBegin = NULL;
+ UINT8 *pEnd = NULL;
+ UINT16 keyLen = 0;
+ UINT8 keyBuf[LOCKNET_KEY_LEN+1] = {0};
+ UINT8 *pStrAt = NULL;
+ CHAR at_str[AT_STR_LEN] = {0};
+
+ if (g_IsUnlockKeyGot != TRUE)
+ {
+ snprintf(at_str,AT_STR_LEN,"\r\n+CME ERROR\r\n");
+ goto end;
+ }
+ pEnd = at_paras+strlen(at_paras);
+ pBegin = at_paras + strlen("d,");
+ keyLen = pEnd - pBegin;
+ if (keyLen != LOCKNET_KEY_LEN)
+ {
+ snprintf(at_str,AT_STR_LEN,"\r\n+CME ERROR\r\n");
+ goto end;
+ }
+ memcpy(keyBuf,pBegin,keyLen);
+ // if(memcmp(keyBuf,g_UnlockKeyPlaint,keyLen) != 0)
+ if(memcmp(keyBuf,"locknetcode_lynq",keyLen) != 0)
+ {
+ snprintf(at_str,AT_STR_LEN,"\r\n+CME ERROR\r\n");
+ goto end;
+ }
+ retCode = zCtrm_LocknetNandDel();
+ if (EXT_SUCCESS != retCode )
+ {
+ snprintf(at_str,AT_STR_LEN,"\r\n+CME ERROR\r\n");
+ goto end;
+ }
+
+ snprintf(at_str,AT_STR_LEN,"\r\nOK\r\n");
+ g_IsUnlockKeyGot = FALSE;
+ goto end;
+end:
+ send_rsp_str_to_farps(MODULE_ID_LOCKNET, at_str, strlen(at_str));
+ return 0;
+}
+
+int zCtrm_LocknetKeyProc(MSG_BUF *msg)
+{
+ UINT32 retCode = EXT_ERROR;
+ //UINT8 plainText[LOCKNET_KEY_LEN+1] = {0};
+ UINT8 plainText128[KEY_LEN] = {0};
+ UINT8 cipherText[KEY_LEN] = {0};
+
+ char *at_paras = (char*)msg->aucDataBuf;
+ if('g' == at_paras[0])
+ {
+ zCtrm_LocknetKeyGenerate();
+ }
+ if('c' == at_paras[0])
+ {
+ zCtrm_LocknetDelRand();
+ }
+ if('d' == at_paras[0])
+ {
+ zCtrm_LocknetKeyDelete(at_paras);
+ }
+ return 0;
+}
+
+int zCtrm_LocknetAmtStatus(MSG_BUF *msg)
+{
+ UINT32 retCode = EXT_ERROR;
+ UINT8 cipherText[KEY_LEN] = {0};
+ CHAR cipherHex[KEY_LEN*2+1] = {0};
+ UINT8 keyBuf[KEY_LEN] = {0};
+ CHAR at_str[AT_STR_LEN+KEY_LEN*2] = {0};
+
+ //retCode = zDrvNand_Read(AMT_LOCKNET_KEY, sizeof(keyBuf), keyBuf);
+ retCode = cpnv_NvItemRead(AMT_LOCKNET_KEY, keyBuf, sizeof(keyBuf));
+ if (EXT_SUCCESS != retCode || keyBuf[0] == 0xFF)
+ {
+ snprintf(at_str,AT_STR_LEN,"\r\n+CME ERROR:locknet not found\r\n");
+ goto end;
+ }
+ if(g_IsKeyExist != TRUE)
+ {
+ snprintf(at_str,AT_STR_LEN,"\r\n+CME ERROR:illegal command\r\n");
+ goto end;
+ }
+
+ if (g_IsDigestGotSucc != TRUE)
+ {
+ snprintf(at_str,AT_STR_LEN,"\r\n+CME ERROR:undigest\r\n");
+ goto end;
+ }
+ memcpy(cipherText, keyBuf, sizeof(keyBuf));
+ zCtrm_Bytes2String(cipherText, cipherHex, KEY_LEN);
+
+ snprintf(at_str,AT_STR_LEN+KEY_LEN*2,"\r\n+UNLOCKKEY:%s\r\nOK\r\n",cipherHex);
+ g_IsKeyExist = FALSE;
+ goto end;
+end:
+ send_rsp_str_to_farps(MODULE_ID_LOCKNET, at_str, strlen(at_str));
+ return 0;
+}
+
+/*
+*»ñȡժҪÐÅÏ¢
+*·µ»ØÉ豸ID¡¢ËøÍø²ÎÊýE¡¢½âËøÂëÃÜÎÄF¾MD5¼ÆËãºóµÄÕªÒªÐÅÏ¢
+*/
+int zCtrm_LocknetDigestGet(MSG_BUF *msg)
+{
+ char psDest[LOCKNET_KEY_LEN*2+1] = {0};
+ UINT8 pPtr[MAX_AMT_AT_LEN] = {0};
+ UINT32 retCode = EXT_ERROR;
+ CHAR at_str[AT_STR_LEN+LOCKNET_KEY_LEN*2] = {0};
+
+ if (g_IsDigestKeyGot != FALSE)
+ {
+ snprintf(at_str,AT_STR_LEN,"\r\n+CME ERROR:Already Digestget\r\n");
+ goto end;
+ }
+
+ if(g_IsKeyExist != TRUE)
+ {
+ snprintf(at_str,AT_STR_LEN,"\r\n+CME ERROR:illegal command\r\n");
+ goto end;
+ }
+ retCode=zCtrm_LocknetDigestMD5Hash(psDest);
+ if(retCode==EXT_ERROR)
+ {
+ snprintf(at_str,AT_STR_LEN,"\r\n+CME ERROR\r\n");
+ goto end;
+ }
+ snprintf(at_str,AT_STR_LEN+LOCKNET_KEY_LEN*2,"\r\n+LOCKDIGEST: %s\r\nOK\r\n",psDest);
+ g_IsDigestKeyGot = TRUE;
+ goto end;
+end:
+ send_rsp_str_to_farps(MODULE_ID_LOCKNET, at_str, strlen(at_str));
+ return 0;
+
+}
+
+int zCtrm_LocknetSignSet(MSG_BUF *msg)
+{
+ UINT32 retCode = EXT_ERROR;
+ UINT8 *pBegin = NULL;
+ UINT8 *pEnd = NULL;
+ UINT16 keyLen = 0;
+ CHAR keyText[KEY_LEN*2+1]={0};
+ UINT8 keyHex[KEY_LEN] = {0};
+ CHAR at_str[AT_STR_LEN] = {0};
+
+ char *at_paras = NULL;// cov M PW.BRANCH_PAST_INITIALIZATION
+
+ if (g_IsDigestKeyGot != TRUE)
+ {
+ snprintf(at_str,AT_STR_LEN,"\r\n+CME ERROR:NO Digestget\r\n");
+ goto end;
+ }
+ at_paras = (char*)msg->aucDataBuf;
+ pEnd = at_paras+strlen(at_paras);
+
+ pBegin = at_paras;
+ keyLen = pEnd - pBegin;
+ if (keyLen != KEY_LEN*2)
+ {
+ snprintf(at_str,AT_STR_LEN,"\r\n+CME ERROR\r\n");
+ goto end;
+ }
+ memcpy(keyText,pBegin,keyLen);
+ //°Ñ×Ö·û´®×ª³É¶þ½øÖÆÊý´æ½øÈ¥
+ zCtrm_String2Bytes(keyText, keyHex, keyLen);
+ cpnv_ChangeNvRoAttr(1);
+ //retCode = zDrvNand_Program(AMT_LOCKNET_SIGN, KEY_LEN, keyHex);
+ retCode = cpnv_NvItemWriteNvro(AMT_LOCKNET_SIGN, keyHex, KEY_LEN);
+ if (EXT_SUCCESS != retCode)
+ {
+ snprintf(at_str,AT_STR_LEN,"\r\n+CME ERROR\r\n");
+ cpnv_ChangeNvRoAttr(0);
+ goto end;
+ }
+ cpnv_FsGcWait(FS_NVROFS);
+ cpnv_ChangeNvRoAttr(0);
+ snprintf(at_str,AT_STR_LEN,"\r\nOK\r\n");
+ g_IsDigestKeyGot = FALSE;
+ g_IsDigestGotSucc = TRUE;
+ goto end;
+end:
+ send_rsp_str_to_farps(MODULE_ID_LOCKNET, at_str, strlen(at_str));
+ return 0;
+
+}
+
+int zCtrm_LocknetLevel(MSG_BUF *msg)
+{
+ UINT32 retCode = EXT_ERROR;
+ CHAR at_str[AT_STR_LEN] = {0};
+ T_zCtrm_LockLevel lockState = LOCKFLAG_ERROR;
+ //retCode = zDrvNand_Read(AMT_LOCKNET_BASE,sizeof(lockState),(UINT8 *)&lockState); //len=4
+ retCode = cpnv_NvItemRead(AMT_LOCKNET_BASE, (UINT8 *)&lockState, sizeof(lockState));
+ if (EXT_SUCCESS != retCode )
+ {
+ at_print(AT_ERR,"zCtrm_ExtLocknetLevel read err\n");
+ snprintf(at_str,AT_STR_LEN,"\r\n+CME ERROR\r\n");
+ goto end;
+ }
+ if(lockState == ALREADY_UNLOCKED)
+ {
+ snprintf(at_str,AT_STR_LEN,"\r\n+LOCKLEVEL:Already Unlocked\r\nOK\r\n");
+ }
+ else if(lockState == LOCKED)
+ {
+ snprintf(at_str,AT_STR_LEN,"\r\n+LOCKLEVEL:Locked\r\nOK\r\n");
+ }
+ else if(lockState == NEVER_LOCKED)
+ {
+ snprintf(at_str,AT_STR_LEN,"\r\n+LOCKLEVEL:Never Locked\r\nOK\r\n");
+ }
+ else
+ {
+ at_print(AT_ERR,"zCtrm_ExtLocknetLevel err flag:%x\n",lockState);
+ snprintf(at_str,AT_STR_LEN,"\r\n+CME ERROR\r\n");
+ goto end;
+ }
+ goto end;
+end:
+ send_rsp_str_to_farps(MODULE_ID_LOCKNET, at_str, strlen(at_str));
+ return 0;
+}
+
+int zCtrm_LocknetListGet()
+{
+ UINT32 retCode = EXT_ERROR;
+ UINT16 iList = 0;
+ UINT8 pPtr[MAX_AMT_AT_LEN] = {0};
+ CHAR at_str[AT_STR_LEN+MAX_AMT_AT_LEN] = {0};
+
+ T_zCtrm_LockListPara lockList = {0};
+ for(iList = 0; iList < LOCKNET_MAX_NUM; iList++)
+ {
+ memset(&lockList, 0, sizeof(lockList));//cov
+ //retCode = zDrvNand_Read(AMT_LOCKNET_LIST + iList*sizeof(lockList), sizeof(lockList), (UINT8 *)&lockList);
+ retCode = cpnv_NvItemRead(AMT_LOCKNET_LIST + iList*sizeof(lockList), (UINT8 *)&lockList, sizeof(lockList));
+ if (EXT_SUCCESS != retCode )
+ {
+ snprintf(at_str,AT_STR_LEN,"\r\n+CME ERROR\r\n");
+ send_rsp_str_to_farps(MODULE_ID_LOCKNET, at_str, strlen(at_str));
+ return 0;
+ }
+ if((lockList.mcc[0] == 0xFF)||(lockList.imsi6[0] == 0xFF)||(lockList.gid1[0] == 0xFF))
+ {
+ at_print(AT_ERR,"zCtrm_ExtLocknetListGet break iList:[%d]\n",iList);
+ break;
+ }
+ //cov
+ 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';
+ if(iList < LOCKNET_FIRST_NUM)
+ {
+ snprintf(pPtr+strlen(pPtr),sizeof(pPtr)-strlen(pPtr),"%s,%s,%s,%s,%s,%s;",
+ lockList.mcc,lockList.mnc,lockList.imsi6,lockList.imsi7,lockList.gid1,lockList.gid2);
+ }
+ else
+ {
+ strcat((char *)pPtr,"next");
+ break;
+ }
+
+ }
+ snprintf(at_str,AT_STR_LEN+MAX_AMT_AT_LEN,"\r\n+MEPCG:%s\r\nOK\r\n",pPtr);
+ send_rsp_str_to_farps(MODULE_ID_LOCKNET, at_str, strlen(at_str));
+ return 0;
+}
+
+int zCtrm_LocknetListGetNext()
+{
+ UINT32 retCode = EXT_ERROR;
+ UINT16 iList = 0;
+ UINT8 pPtr[MAX_AMT_AT_LEN] = {0};
+ CHAR at_str[AT_STR_LEN+MAX_AMT_AT_LEN] = {0};
+
+ T_zCtrm_LockListPara lockList = {0};
+ for(iList = 0; iList < LOCKNET_MAX_NUM - LOCKNET_FIRST_NUM; iList++)
+ {
+ memset(&lockList, 0, sizeof(lockList));//cov
+ //retCode = zDrvNand_Read(AMT_LOCKNET_LIST + (LOCKNET_FIRST_NUM+iList)*sizeof(lockList), sizeof(lockList), (UINT8 *)&lockList);
+ retCode = cpnv_NvItemRead(AMT_LOCKNET_LIST + (LOCKNET_FIRST_NUM+iList)*sizeof(lockList), (UINT8 *)&lockList, sizeof(lockList));
+ if (EXT_SUCCESS != retCode )
+ {
+ snprintf(at_str,AT_STR_LEN,"\r\n+CME ERROR\r\n");
+ send_rsp_str_to_farps(MODULE_ID_LOCKNET, at_str, strlen(at_str));
+ return 0;
+ }
+ if((lockList.mcc[0] == 0xFF)||(lockList.imsi6[0] == 0xFF)||(lockList.gid1[0] == 0xFF))
+ {
+ at_print(AT_ERR,"zCtrm_ExtLocknetListGetNext break iList:[%d]\n",iList);
+ break;
+ }
+ //cov
+ 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';
+ snprintf(pPtr+strlen(pPtr),sizeof(pPtr)-strlen(pPtr),"%s,%s,%s,%s,%s,%s;",
+ lockList.mcc,lockList.mnc,lockList.imsi6,lockList.imsi7,lockList.gid1,lockList.gid2);
+ }
+ snprintf(at_str,AT_STR_LEN+MAX_AMT_AT_LEN,"\r\n+MEPCG:%s\r\nOK\r\n",pPtr);
+ send_rsp_str_to_farps(MODULE_ID_LOCKNET, at_str, strlen(at_str));
+ return 0;
+}
+
+int zCtrm_LocknetListGetProc(MSG_BUF *msg)
+{
+ CHAR at_str[AT_STR_LEN] = {0};
+ char *at_paras = (char*)msg->aucDataBuf;
+ if(NULL != strstr(at_paras, "all"))
+ {
+ zCtrm_LocknetListGet();
+ }
+ else if(NULL != strstr(at_paras, "next"))
+ {
+ zCtrm_LocknetListGetNext();
+ }
+ else
+ {
+ snprintf(at_str,AT_STR_LEN,"\r\n+CME ERROR\r\n");
+ send_rsp_str_to_farps(MODULE_ID_LOCKNET, at_str, strlen(at_str));
+ }
+ return 0;
+}
+
+//¶ÁÈ¡ËøÍø²ÎÊý¡¢½âËøÂ롢ǩÃû£¬ÅжÏÊÇ·ñ´æÔÚ
+static UINT32 zCtrm_SignExistAuthMutex(VOID)
+{
+ UINT32 retCode=EXT_ERROR;
+ T_zCtrm_LockListPara lockList = {0};
+ T_zCtrm_LockListPara lockListTmp = {0};
+ UINT8 keyBuf[KEY_LEN] = {0};
+ UINT8 signBuf[KEY_LEN] = {0};
+
+ //ËøÍø²ÎÊý
+ //retCode = zDrvNand_Read(AMT_LOCKNET_LIST, sizeof(lockList), (UINT8 *)&lockList);
+ retCode = cpnv_NvItemRead(AMT_LOCKNET_LIST, (UINT8 *)&lockList, sizeof(lockList));
+ if (EXT_SUCCESS != retCode)
+ {
+ return READ_ERROR;
+ }
+ if((lockList.mcc[0] == 0xFF)||(lockList.imsi6[0] == 0xFF)||(lockList.gid1[0] == 0xFF))
+ {
+ return LOCKKEY_ISNULL;
+ }
+ if(memcmp(&lockList,&lockListTmp,sizeof(T_zCtrm_LockListPara)) == 0)
+ {
+ return LOCKKEY_ISNULL;//¹æ±Ünvrowall.binÈ«0µÄÎÊÌâ
+ }
+// ûÉèÖýâËøÂëºÍÇ©Ãû£¬²»ÐèÒªÅжÏ
+#if 0
+ //½âËøÂë
+ //retCode = zDrvNand_Read(AMT_LOCKNET_KEY, sizeof(keyBuf), keyBuf);
+ retCode = cpnv_NvItemRead(AMT_LOCKNET_KEY, keyBuf, sizeof(keyBuf));
+ if (EXT_SUCCESS != retCode)
+ {
+ return READ_ERROR;
+ }
+ if(keyBuf[0] == 0xFF)
+ {
+ return LOCKKEY_ISNULL;
+ }
+
+ //Ç©Ãû
+ //retCode = zDrvNand_Read(AMT_LOCKNET_SIGN, sizeof(signBuf), signBuf);
+ retCode = cpnv_NvItemRead(AMT_LOCKNET_SIGN, signBuf, sizeof(signBuf));
+ if (EXT_SUCCESS != retCode)
+ {
+ return READ_ERROR;
+ }
+ if(signBuf[0] == 0xFF)
+ {
+ return LOCKKEY_ISNULL;
+ }
+#endif
+
+ return READ_SUCCESS;
+
+}
+
+static UINT32 zCtrm_SignAuth(VOID)
+{
+ UINT32 retCode = EXT_ERROR;
+ UINT8 signBuf[KEY_LEN] = {0};
+ UINT8 signHex128[KEY_LEN] = {0};
+ char signtext[LOCKNET_KEY_LEN*2+1] = {0};
+ char psDest[LOCKNET_KEY_LEN*2+1] = {0};
+
+ //Ç©Ãû
+ //retCode = zDrvNand_Read(AMT_LOCKNET_SIGN, sizeof(signBuf), signBuf);
+ retCode = cpnv_NvItemRead(AMT_LOCKNET_SIGN, signBuf, sizeof(signBuf));
+ if (EXT_SUCCESS != retCode)
+ {
+ return RESULT_ERROR;
+ }
+
+ //¹«Ô¿½âÃÜ
+ retCode = zCtrm_RsaPublicEncryptProc(signBuf, signHex128);
+ if (EXT_SUCCESS != retCode)
+ {
+ return RESULT_ERROR;
+ }
+
+ zCtrm_Bytes2String(signHex128+KEY_LEN-LOCKNET_KEY_LEN, signtext, LOCKNET_KEY_LEN);
+
+ //ÕªÒªÓëÇ©Ãû ±È½Ï ÕªÒªÓù«Ô¿½âÃÜ
+ retCode=zCtrm_LocknetDigestMD5Hash(psDest);
+ if (EXT_SUCCESS != retCode)
+ {
+ return RESULT_ERROR;
+ }
+
+ at_print(AT_ERR,"zCtrm_SignAuth signtext=%s,psDest=%s!",signtext,psDest);
+ // ĿǰûÅäÖù«Ô¿ºÍ˽Կ£¬²»Ð£ÑéÕªÒªÓëÇ©Ãû
+#if 0
+ if(0 != strcasecmp(signtext,psDest))
+ {
+ return RESULT_LOCKED;
+ }
+#endif
+ return RESULT_UNLOCKED;
+}
+
+static UINT32 zCtrm_KeyAuth(VOID)
+{
+ UINT32 retCode = EXT_ERROR;
+ UINT8 keyBuf[KEY_LEN] = {0};
+ UINT8 usrkeyBuf[LOCKNET_KEY_LEN] = {0};
+ UINT8 usrkeyBuf128[KEY_LEN] = {0};
+ UINT8 usrKeyText[KEY_LEN] = {0};
+
+ //½âËøÂë
+ //retCode = zDrvNand_Read(AMT_LOCKNET_KEY, sizeof(keyBuf), keyBuf);
+ retCode = cpnv_NvItemRead(AMT_LOCKNET_KEY, keyBuf, sizeof(keyBuf));
+ if (EXT_SUCCESS != retCode || keyBuf[0] == 0xFF)
+ {
+ return RESULT_ERROR;
+ }
+
+ //Óû§½âËøÂë
+ //retCode = zDrvNand_Read(AMT_LOCKNET_USRKEY, sizeof(usrkeyBuf), usrkeyBuf);
+ retCode = cpnv_NvItemRead(AMT_LOCKNET_USRKEY, usrkeyBuf, sizeof(usrkeyBuf));
+ if (EXT_SUCCESS != retCode || usrkeyBuf[0] == 0xFF)
+ {
+ return RESULT_LOCKED;
+ }
+
+ memcpy(usrkeyBuf128+KEY_LEN-LOCKNET_KEY_LEN, usrkeyBuf, LOCKNET_KEY_LEN);
+ retCode = zCtrm_RsaPublicEncryptProc(usrkeyBuf128, usrKeyText);
+ if (EXT_SUCCESS != retCode )
+ {
+ return RESULT_ERROR;
+ }
+
+ //Óû§½âËøÂëÓë½âËøÂë ±È½Ï ¼ÓÃܺó±È½Ï
+ if(memcmp(keyBuf,usrKeyText,KEY_LEN) != 0)
+ {
+ return RESULT_LOCKED;
+ }
+ return RESULT_UNLOCKED;
+}
+
+void zCtrm_DoSimAuth()
+{
+ char crsmrsp[256] = {0};
+ void *p[] = {crsmrsp};
+ UINT8 *pRes = NULL;
+ CHAR fileSize[5] = {0};
+ char at_str[AT_STR_LEN] = {0};
+ int ret = -1;
+
+ snprintf(at_str, AT_STR_LEN, "AT+CRSM=192,%ld,0,0,15,,\"3F007F20\"\r\n", IDENTIFIER_GID1);
+ ret = get_modem_info(at_str, "%s", p);
+ if (ret)
+ {
+ at_print(AT_ERR,"zCtrm_SignExistAuthMutex crsm error!\n");
+ simPara.fileLen = 0;
+ }
+ else
+ {
+ pRes = strstr(crsmrsp, "144,0,");//±íʾÕýÈ·¶ÁÈ¡
+ if(NULL != pRes)
+ {
+ strncpy(fileSize, pRes+strlen("144,0,")+4, 4);
+ simPara.fileLen = zCtrm_Atohex(fileSize[0])*4096 + zCtrm_Atohex(fileSize[1])*256 + zCtrm_Atohex(fileSize[2])*16 + zCtrm_Atohex(fileSize[3]);
+ at_print(AT_ERR,"crsm_ok_act, fileLen1 = %ld \n", simPara.fileLen);
+ }
+ else
+ {
+ simPara.fileLen = 0;
+ }
+ }
+ snprintf(at_str, AT_STR_LEN, "AT+CRSM=176,%ld,0,0,%ld\r\n", IDENTIFIER_GID1, simPara.fileLen);
+ ret = get_modem_info(at_str, "%s", p);
+ if (ret)
+ at_print(AT_ERR,"zCtrm_SignExistAuthMutex crsm error!\n");
+ else
+ {
+ pRes = strstr(crsmrsp, "144,0,");//±íʾÕýÈ·¶ÁÈ¡
+ if(NULL != pRes)
+ {
+ strncpy(simLockListPara.gid1, pRes+strlen("144,0,"), LIST_GID_LEN-1);
+ at_print(AT_ERR,"crsm_ok_act, gid1 = %s \n", simLockListPara.gid1);
+ }
+
+ }
+ snprintf(at_str, AT_STR_LEN, "AT+CRSM=192,%ld,0,0,15,,\"3F007F20\"", IDENTIFIER_GID2);
+ ret = get_modem_info(at_str, "%s", p);
+ if (ret)
+ {
+ at_print(AT_ERR,"zCtrm_SignExistAuthMutex crsm error!\n");
+ simPara.fileLen = 0;
+ }
+ else
+ {
+ pRes = strstr(crsmrsp, "144,0,");//±íʾÕýÈ·¶ÁÈ¡
+ if(NULL != pRes)
+ {
+ strncpy(fileSize, pRes+strlen("144,0,")+4, 4);
+ simPara.fileLen = zCtrm_Atohex(fileSize[0])*4096 + zCtrm_Atohex(fileSize[1])*256 + zCtrm_Atohex(fileSize[2])*16 + zCtrm_Atohex(fileSize[3]);
+ at_print(AT_ERR,"crsm_ok_act, fileLen2 = %ld \n", simPara.fileLen);
+ }
+ else
+ {
+ simPara.fileLen = 0;
+ }
+ }
+ snprintf(at_str, AT_STR_LEN, "AT+CRSM=176,%ld,0,0,%ld\r\n", IDENTIFIER_GID2, simPara.fileLen);
+ ret = get_modem_info(at_str, "%s", p);
+ if (ret)
+ at_print(AT_ERR,"zCtrm_SignExistAuthMutex crsm error!\n");
+ else
+ {
+ pRes = strstr(crsmrsp, "144,0,");//±íʾÕýÈ·¶ÁÈ¡
+ if(NULL != pRes)
+ {
+ strncpy(simLockListPara.gid2, pRes+strlen("144,0,"), LIST_GID_LEN-1);
+ at_print(AT_ERR,"crsm_ok_act, gid2 = %s \n", simLockListPara.gid2);
+ }
+ }
+ ret = get_modem_info("AT+CRSM=176,28589,0,0,4\r\n", "%s", p);
+ if (ret)
+ {
+ simPara.mncLen = 2;
+ at_print(AT_ERR,"crsm_err_act, mncLen = %d \n", simPara.mncLen);
+ }
+ else
+ {
+ pRes = strstr(crsmrsp, "144,0,");//±íʾÕýÈ·¶ÁÈ¡
+ if((NULL != pRes)&&(0 == strcmp("03", pRes+strlen("144,0,")+6))) //use 02 test
+ {
+ simPara.mncLen = 3;
+ }
+ else
+ {
+ simPara.mncLen = 2;
+ }
+ at_print(AT_ERR,"crsm_ok_act, mncLen = %d \n", simPara.mncLen);
+ }
+ return;
+}
+
+void zCtrm_DoUsimAuth()
+{
+ char crsmrsp[256] = {0};
+ void *p[] = {crsmrsp};
+ UINT8 *pRes = NULL;
+ CHAR fileSize[5] = {0};
+ int ret = -1;
+
+ ret = get_modem_info("AT+CRSM=176,28478,0,0,0\r\n", "%s", p);
+ if (ret)
+ at_print(AT_ERR,"cardmode_err_act zCtrm_USimAuth ERROR!\n");
+ else
+ {
+ pRes = strstr(crsmrsp, "144,0,");
+ if(NULL != pRes)
+ {
+ strncpy(simLockListPara.gid1, pRes+strlen("144,0,"), LIST_GID_LEN-1);
+ at_print(AT_ERR,"crsm_ok_act, gid1 = %s \n", simLockListPara.gid1);
+ }
+ }
+ ret = get_modem_info("AT+CRSM=176,28479,0,0,0\r\n", "%s", p);
+ if (ret)
+ at_print(AT_ERR,"cardmode_err_act zCtrm_USimAuth ERROR!\n");
+ else
+ {
+ pRes = strstr(crsmrsp, "144,0,");
+ if(NULL != pRes)
+ {
+ strncpy(simLockListPara.gid2, pRes+strlen("144,0,"), LIST_GID_LEN-1);
+ at_print(AT_ERR,"crsm_ok_act, gid2 = %s \n", simLockListPara.gid2);
+ }
+ }
+ ret = get_modem_info("AT+CRSM=176,28589,0,0,4\r\n", "%s", p);
+ if (ret)
+ {
+ simPara.mncLen = 2;
+ at_print(AT_ERR,"crsm_err_act, mncLen = %d \n", simPara.mncLen);
+ }
+ else
+ {
+ pRes = strstr(crsmrsp, "144,0,");
+ if((NULL != pRes)&&(0 == strcmp("03", pRes+strlen("144,0,")+6))) //use 02 test
+ {
+ simPara.mncLen = 3;
+ }
+ else
+ {
+ simPara.mncLen = 2;
+ }
+ at_print(AT_ERR,"crsm_ok_act, mncLen = %d \n", simPara.mncLen);
+ }
+ return;
+}
+
+VOID zCtrm_SIMPara2Auth(T_zCtrm_LockListPara *fromSim, T_zCtrm_SIMPara simPara)
+{
+ strncpy(fromSim->mcc,simPara.simImsi,3);
+ if (simPara.mncLen < sizeof(fromSim->mnc)) {
+ memset(fromSim->mnc,0,sizeof(fromSim->mnc));
+ snprintf(fromSim->mnc,simPara.mncLen+1,"%s",simPara.simImsi+3);
+ //strncpy(fromSim->mnc,simPara.simImsi+3,simPara.mncLen);
+ }
+ strncpy(fromSim->imsi6,simPara.simImsi+5,1);
+ strncpy(fromSim->imsi7,simPara.simImsi+6,1);
+}
+
+UINT32 zCtrm_AuthSIMPara(T_zCtrm_LockListPara *simPara)
+{
+ UINT32 retCode = EXT_ERROR;
+ UINT32 iNum = 0;
+
+ if(0 == strcmp("001",simPara->mcc) && 0 == strcmp("01",simPara->mnc))
+ //if(0 == strcmp("460",simPara.mcc) && 0 == strcmp("01",simPara.mnc))
+ {
+ at_print(AT_ERR,"sim ex\n");
+ return EXT_SUCCESS;
+ }
+
+ for(iNum = 0; iNum < LOCKNET_MAX_NUM; iNum++)
+ {
+ T_zCtrm_LockListPara lockList = {0};
+ //retCode = zDrvNand_Read(AMT_LOCKNET_LIST + iNum*sizeof(lockList), sizeof(lockList), (UINT8 *)&lockList);
+ retCode = cpnv_NvItemRead(AMT_LOCKNET_LIST + iNum*sizeof(lockList), (UINT8 *)&lockList, sizeof(lockList));
+ if (EXT_SUCCESS != retCode )
+ {
+ at_print(AT_ERR,"zCtrm_AuthSIMPara:zDrvNand_Read error\n");
+ return EXT_ERROR;
+ }
+
+ if((lockList.mcc[0] == 0xFF)||(lockList.imsi6[0] == 0xFF)||(lockList.gid1[0] == 0xFF))
+ {
+ at_print(AT_ERR,"zCtrm_AuthSIMPara: lockList value error\n");
+ return EXT_ERROR;
+ }
+ //cov
+ 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';
+ if( (lockList.mcc[0] == '\0'||0 == strcmp(lockList.mcc,simPara->mcc))
+ &&(lockList.mnc[0] == '\0'||0 == strcmp(lockList.mnc,simPara->mnc))
+ &&(lockList.imsi6[0] == '\0'||0 == strcmp(lockList.imsi6,simPara->imsi6))
+ &&(lockList.imsi7[0] == '\0'||0 == strcmp(lockList.imsi7,simPara->imsi7))
+ &&(lockList.gid1[0] == '\0'||0 == zCtrm_Strnicmp(lockList.gid1,simPara->gid1,USED_GID_LEN))
+ &&(lockList.gid2[0] == '\0'||0 == zCtrm_Strnicmp(lockList.gid2,simPara->gid2,USED_GID_LEN)) )
+ {
+ at_print(AT_ERR,"sim checked\n");
+ return EXT_SUCCESS;
+ }
+ }
+
+ at_print(AT_ERR,"zCtrm_AuthSIMPara: other error\n");
+ return EXT_ERROR;
+}
+
+static UINT32 zCtrm_SimAuth()
+{
+ int ret = -1;
+ int cardmode = 0;
+ void *p1[] = {&cardmode};
+ char imsi[MAX_IMSI_LEN] = {0};
+ void *p2[] = {imsi};
+
+ ret = get_modem_info("AT^CARDMODE\r\n", "%d", p1);
+ if (ret) {
+ simPara.cardMode = CARDMODE_UNKNOW;
+ at_print(AT_ERR,"cardmode_err_act zCtrm_SimAuth ERROR!\n");
+ return RESULT_ERROR;
+ }
+ if(1 == cardmode)
+ {
+ simPara.cardMode = CARDMODE_SIM;
+ zCtrm_DoSimAuth();
+ }
+ else if(2 == cardmode)
+ {
+ simPara.cardMode = CARDMODE_USIM;
+ zCtrm_DoUsimAuth();
+ }
+ else
+ return RESULT_ERROR;
+ ret = get_modem_info("AT+CIMI\r\n", "%s", p2);
+ if (ret)
+ {
+ at_print(AT_ERR,"cimi_err_act zCtrm_SimAuth ERROR!\n");
+ return RESULT_ERROR;
+ }
+ else
+ {
+ strncpy(simPara.simImsi,imsi,sizeof(simPara.simImsi)-1);
+ if(*(simPara.simImsi) == '\0')
+ {
+ at_print(AT_ERR,"cimi_ok_act zCtrm_SimAuth ERROR!\n");
+ return RESULT_ERROR;
+ }
+ zCtrm_SIMPara2Auth(&simLockListPara, simPara);
+ ret = zCtrm_AuthSIMPara(&simLockListPara);
+ if (EXT_SUCCESS != ret)
+ {
+ ret = get_modem_info("AT+CFUN=4;+ZSCHPLMN=0\r\n", NULL, NULL);
+ if (ret)
+ {
+ at_print(AT_ERR,"zCtrm_SimAuth ZSCHPLMN0 error!\n");
+ }
+ return RESULT_LOCKED;
+ }
+ else
+ {
+ ret = get_modem_info("AT+ZSCHPLMN=1\r\n", NULL, NULL);
+ if (ret)
+ {
+ at_print(AT_ERR,"zCtrm_SimAuth ZSCHPLMN1 error!\n");
+ }
+ return RESULT_UNLOCKED;
+ }
+ }
+
+}
+
+int zCtrm_makeLocknetAuth(MSG_BUF *msg)
+{
+ UINT32 readCode = READ_ERROR;//¶ÁÈ¡ËøÍø²ÎÊý¡¢½âËøÂ롢ǩÃûÊÇ·ñ´æÔÚ
+ UINT32 result = RESULT_ERROR;//ÿһ²½µÄÅжϽá¹û
+ char at_str[AT_STR_LEN] = {0};
+ int ret = -1;
+
+ at_print(AT_ERR,"zCtrm_ExtLocknetAuth,status = %d\n",g_Sec_Status);
+ if(g_Sec_Status != ENCRYPT_LOCK && g_Sec_Status != ENCRYPT_UNLOCK_CORRECT)
+ {
+ at_print(AT_ERR,"zCtrm_LocknetAuth, g_Sec_Status:%d\n",g_Sec_Status);
+
+ //ËøÍø²ÎÊý¡¢½âËøÂ롢ǩÃûÊÇ·ñ´æÔÚ
+ readCode = zCtrm_SignExistAuthMutex();
+ if(readCode == READ_ERROR)
+ {
+ g_Sec_Status = ENCRYPT_ERROR;
+ at_print(AT_ERR,"zCtrm_SignExistAuthMutex ERROR!\n");
+ snprintf(at_str,AT_STR_LEN,"\r\n+CME ERROR:149\r\n");
+ goto end;
+ }
+ else if(readCode == LOCKKEY_ISNULL)
+ {
+ ret = get_modem_info("AT+ZSCHPLMN=1\r\n", NULL, NULL);
+ if (ret) {
+ at_print(AT_ERR,"zCtrm_SignExistAuthMutex zschplmn1 error!\n");
+ }
+ g_Sec_Status = ENCRYPT_UNLOCK_CORRECT;
+ at_print(AT_ERR,"zCtrm_SignExistAuthMutex UNLOCK!\n");
+ snprintf(at_str,AT_STR_LEN,"\r\nOK\r\n");
+ goto end;
+ }
+ //²ÎÊý´æÔÚ£¬½øÒ»²½ÅжÏ
+ else
+ {
+// ûÉèÖýâËøÂ롢ǩÃû£¬²»ÐèÒªÅжϣ¬Ö»¶ÔËøÍø²ÎÊý½øÐÐÅжÏ
+#if 0
+ //ÅжÏÕªÒªÓëÇ©ÃûÊÇ·ñÒ»Ö£¬Ç©ÃûÐèÒªÓù«Ô¿½âÃÜ
+ result = zCtrm_SignAuth();
+ if(result == RESULT_ERROR)
+ {
+ g_Sec_Status = ENCRYPT_ERROR;
+ snprintf(at_str,AT_STR_LEN,"\r\n+CME ERROR:149\r\n");
+ goto end;
+ }
+ else if(result == RESULT_LOCKED)
+ {
+ snprintf(at_str,AT_STR_LEN,"AT+CFUN=4;+ZSCHPLMN=0\r\n");
+ ret = get_modem_info(at_str, NULL, NULL);
+ if (ret) {
+ at_print(AT_ERR,"zCtrm_SignExistAuthMutex zschplmn0 error!\n");
+ }
+ g_Sec_Status = ENCRYPT_LOCK;
+ at_print(AT_ERR,"zCtrm_SignAuth LOCK!\n");
+ snprintf(at_str,AT_STR_LEN,"\r\nOK\r\n");
+ goto end;
+ }
+ //½øÒ»²½ÅжÏ
+ else
+ {
+ //ÅжϽâËøÂëÓëÓû§½âËøÂëÊÇ·ñÒ»Ö£¬Óû§½âËøÂëÐèÒªÓù«Ô¿¼ÓÃÜ
+ //½öµ±Óû§½âËøÂë²»´æÔÚ»òÕßÓû§½âËøÂëÓë½âËøÂë²»Ò»Ñùʱ£¬½øÐÐsim¿¨ÅжÏ
+ result = zCtrm_KeyAuth();
+ if(result == RESULT_ERROR)
+ {
+ g_Sec_Status = ENCRYPT_ERROR;
+ at_print(AT_ERR,"zCtrm_KeyAuth ERROR!\n");
+ snprintf(at_str,AT_STR_LEN,"\r\n+CME ERROR:149\r\n");
+ goto end;
+ }
+ else if(result == RESULT_UNLOCKED)
+ {
+ ret = get_modem_info("AT+ZSCHPLMN=1\r\n", NULL, NULL);
+ if (ret) {
+ at_print(AT_ERR,"zCtrm_SignExistAuthMutex zschplmn1 error!\n");
+ }
+ g_Sec_Status = ENCRYPT_UNLOCK_CORRECT;
+ at_print(AT_ERR,"zCtrm_KeyAuth UNLOCK!\n");
+ snprintf(at_str,AT_STR_LEN,"\r\nOK\r\n");
+ goto end;
+ }
+ //½øÒ»²½ÅжÏ
+ else
+ {
+ result = zCtrm_SimAuth();
+ if(RESULT_ERROR == result)
+ {
+ g_Sec_Status = ENCRYPT_ERROR;
+ at_print(AT_ERR,"zCtrm_SimAuth ERROR!\n");
+ snprintf(at_str,AT_STR_LEN,"\r\n+CME ERROR:149\r\n");
+ goto end;
+ }
+ else if(RESULT_LOCKED == result)
+ {
+ g_Sec_Status = ENCRYPT_LOCK;
+ snprintf(at_str,AT_STR_LEN,"\r\nOK\r\n");
+ goto end;
+ }
+ else
+ {
+ g_Sec_Status = ENCRYPT_UNLOCK_CORRECT;
+ snprintf(at_str,AT_STR_LEN,"\r\nOK\r\n");
+ goto end;
+ }
+ }
+
+ }
+#else
+ result = zCtrm_SimAuth();
+ if(RESULT_ERROR == result)
+ {
+ g_Sec_Status = ENCRYPT_ERROR;
+ at_print(AT_ERR,"zCtrm_SimAuth ERROR!\n");
+ snprintf(at_str,AT_STR_LEN,"\r\n+CME ERROR:149\r\n");
+ goto end;
+ }
+ else if(RESULT_LOCKED == result)
+ {
+ g_Sec_Status = ENCRYPT_LOCK;
+ snprintf(at_str,AT_STR_LEN,"\r\nOK\r\n");
+ goto end;
+ }
+ else
+ {
+ g_Sec_Status = ENCRYPT_UNLOCK_CORRECT;
+ snprintf(at_str,AT_STR_LEN,"\r\nOK\r\n");
+ goto end;
+ }
+#endif
+ }
+ /* cov2
+ ret = get_modem_info("AT+ZSCHPLMN=1\r\n", NULL, NULL);
+ if (ret) {
+ at_print(AT_ERR,"zCtrm_SignExistAuthMutex zschplmn1 error!\n");
+ }
+ g_Sec_Status = ENCRYPT_UNLOCK_CORRECT;
+ snprintf(at_str,AT_STR_LEN,"\r\nOK\r\n");
+ goto end;
+ */
+ }
+ snprintf(at_str,AT_STR_LEN,"\r\nOK\r\n");
+ goto end;
+end:
+ if(1 == sendflag)
+ {
+ send_rsp_str_to_farps(MODULE_ID_LOCKNET, at_str, strlen(at_str));//Èç¹ûÊÇzurdy´¥·¢µÄËøÍøÁ÷³Ì£¬²»ÐèÒªÏò´®¿Ú·¢·µ»ØÖµ
+ sendflag = 0;
+ }
+ return 0;
+}
+
+static UINT32 zCtrm_UnlockTimesCheck(UINT32 *curTimes)
+{
+ UINT32 retCode = EXT_ERROR;
+ UINT32 times = 0;
+ UINT32 maxTimes = 0;
+ T_zCtrm_LockLevel lockState = NEVER_LOCKED;
+
+ //retCode = zDrvNand_Read(AMT_LOCKNET_BASE, sizeof(lockState),(UINT8 *)&lockState);
+ retCode = cpnv_NvItemRead(AMT_LOCKNET_BASE,(UINT8 *)&lockState, sizeof(lockState));
+ at_print(AT_ERR,"zCtrm_UnlockCodeCheck lockState=%d,retCode=%d!\n",lockState,retCode);
+ if (EXT_SUCCESS != retCode || lockState != LOCKED)
+ {
+ return EXT_ERROR;
+ }
+
+
+ //retCode = zDrvNand_Read(AMT_LOCKNET_TIMES, sizeof(times),(UINT8 *)×);
+ retCode = cpnv_NvItemRead(AMT_LOCKNET_TIMES,(UINT8 *)×, sizeof(times));
+ at_print(AT_ERR,"zCtrm_UnlockCodeCheck times=%d,retCode=%d!\n",times,retCode);
+ if (EXT_SUCCESS != retCode)
+ {
+ return EXT_ERROR;
+ }
+
+ maxTimes = zCtrm_GetUnlockMaxTime();
+ if(times > 0 && times <= maxTimes)
+ {
+ *curTimes = times;
+ return EXT_SUCCESS;
+ }
+
+ return EXT_ERROR;
+}
+
+//Óû§ÊäÈëµÄ½âËøÂ룬ÐèÒªÓù«Ô¿¼ÓÃܺóÔÙÓë´æÈëROÖеĽâËøÂë±È½Ï¡£
+//(ROÖнâËøÂë128λ)
+static UINT32 zCtrm_UnlockCodeCheck(UINT8 *keyBuf,UINT16 keyLen)
+{
+ UINT32 retCode = EXT_ERROR;
+ UINT8 lockkey[KEY_LEN] = {0};
+ UINT8 keyBufText[KEY_LEN] = {0};//Óû§ÊäÈë½âËøÂë¼ÓÃܺó×Ö·û
+ UINT8 test1[KEY_LEN*2+1]={0};
+ UINT8 test2[KEY_LEN*2+1]={0};
+ UINT8 keyBuf128[KEY_LEN]={0};
+
+
+ //retCode = zDrvNand_Read(AMT_LOCKNET_KEY, sizeof(lockkey), lockkey);
+ retCode = cpnv_NvItemRead(AMT_LOCKNET_KEY,lockkey, sizeof(lockkey));
+ zCtrm_Bytes2String(lockkey, test1, KEY_LEN);
+ at_print(AT_ERR,"zCtrm_UnlockCodeCheck lockkey=%s,len=%d!\n",test1,strlen(test1));
+ if (EXT_SUCCESS != retCode)
+ {
+ return EXT_ERROR;
+ }
+
+
+ memcpy(keyBuf128+KEY_LEN-LOCKNET_KEY_LEN, keyBuf, LOCKNET_KEY_LEN);
+ retCode = zCtrm_RsaPublicEncryptProc(keyBuf128, keyBufText);
+ zCtrm_Bytes2String(keyBufText, test2, KEY_LEN);
+ at_print(AT_ERR,"zCtrm_UnlockCodeCheck keyBufText=%s,len=%d!\n",test2,strlen(test2));
+ if (EXT_SUCCESS != retCode )
+ {
+ return EXT_ERROR;
+ }
+
+ if(memcmp(keyBufText,lockkey,keyLen) != 0)
+ {
+ return EXT_ERROR;
+ }
+
+ return EXT_SUCCESS;
+}
+
+static VOID zCtrm_UnlockTimesUpdate(UINT32 curTimes)
+{
+ UINT32 retCode = EXT_ERROR;
+ UINT32 maxTimes = 0;
+
+ maxTimes = zCtrm_GetUnlockMaxTime();
+ if(curTimes > 0 && curTimes <= maxTimes)
+ {
+ curTimes = curTimes - 1;
+ }
+ else
+ {
+ curTimes = 0;
+ }
+
+ cpnv_ChangeNvRoAttr(1);
+ //retCode = zDrvNand_Program(AMT_LOCKNET_TIMES, sizeof(curTimes),(UINT8 *)&curTimes);
+ retCode = cpnv_NvItemWriteNvro(AMT_LOCKNET_TIMES, (UINT8 *)&curTimes, sizeof(curTimes));
+ if (EXT_SUCCESS != retCode)
+ {
+ //retCode = zDrvNand_Program(AMT_LOCKNET_TIMES, sizeof(curTimes),(UINT8 *)&curTimes);
+ retCode = cpnv_NvItemWriteNvro(AMT_LOCKNET_TIMES, (UINT8 *)&curTimes, sizeof(curTimes));
+ at_print(AT_ERR,"zCtrm_UnlockTimesUpdate: %ld\n",retCode);
+ }
+ cpnv_FsGcWait(FS_NVROFS);
+ cpnv_ChangeNvRoAttr(0);
+ at_print(AT_ERR,"zCtrm_UnlockTimesUpdate cur: %ld\n",curTimes);
+}
+
+static UINT32 zCtrm_UnlockNandSet(UINT8 *keyBuf,UINT16 len)
+{
+ T_zCtrm_LockLevel lockState = ALREADY_UNLOCKED;
+ T_zCtrm_LockLevel lockState_out = ALREADY_UNLOCKED;
+ UINT32 times = zCtrm_GetUnlockMaxTime();
+ UINT32 retCode =EXT_ERROR;
+
+ cpnv_ChangeNvRoAttr(1);
+ //retCode = zDrvNand_Program(AMT_LOCKNET_TIMES, sizeof(times),(UINT8 *)×);
+ retCode = cpnv_NvItemWriteNvro(AMT_LOCKNET_TIMES, (UINT8 *)×, sizeof(times));
+ at_print(AT_ERR,"zCtrm_UnlockNandSet len=%d,times=%d!\n",sizeof(times),times);
+ if (EXT_SUCCESS != retCode)
+ {
+ cpnv_ChangeNvRoAttr(0);
+ return EXT_ERROR;
+ }
+
+ //retCode = zDrvNand_Program(AMT_LOCKNET_USRKEY, len,keyBuf);
+ retCode = cpnv_NvItemWriteNvro(AMT_LOCKNET_USRKEY, keyBuf, len);
+ at_print(AT_ERR,"zCtrm_UnlockNandSet len=%d,keyBuf=%s!\n",len,keyBuf);
+ if (EXT_SUCCESS != retCode)
+ {
+ cpnv_ChangeNvRoAttr(0);
+ return EXT_ERROR;
+ }
+
+ //retCode = zDrvNand_Program(AMT_LOCKNET_BASE, sizeof(lockState),(UINT8 *)&lockState);
+ retCode = cpnv_NvItemWriteNvro(AMT_LOCKNET_BASE, (UINT8 *)&lockState, sizeof(lockState));
+ at_print(AT_ERR,"zCtrm_UnlockNandSet len=%d,lockstate=%d!\n",sizeof(lockState),lockState);
+ if (EXT_SUCCESS != retCode)
+ {
+ cpnv_ChangeNvRoAttr(0);
+ return EXT_ERROR;
+ }
+
+ //zDrvNand_Read(AMT_LOCKNET_BASE, sizeof(lockState_out),(UINT8 *)&lockState_out);
+ retCode = cpnv_NvItemRead(AMT_LOCKNET_BASE,(UINT8 *)&lockState_out, sizeof(lockState_out));
+ at_print(AT_ERR,"zCtrm_UnlockNandSet len=%d,lockState_out=%d!\n",sizeof(lockState_out),lockState_out);
+ cpnv_FsGcWait(FS_NVROFS);
+ cpnv_ChangeNvRoAttr(0);
+
+ return EXT_SUCCESS;
+}
+
+int zCtrm_LocknetUnlock(MSG_BUF *msg)
+{
+ UINT32 retCode = EXT_ERROR;
+ UINT32 retryCount = 0;
+ UINT16 keyLen = 0;
+ MSG_BUF *p_msg = (MSG_BUF *)msg;
+ UINT8 keyBuf[LOCKNET_KEY_LEN+1] = {0};
+ char at_str[AT_STR_LEN] = {0};
+ int ret = -1;
+
+ at_print(AT_ERR,"zCtrm_LocknetUnlock\n");
+ retCode = zCtrm_UnlockTimesCheck(&retryCount);
+ if (EXT_SUCCESS != retCode )
+ {
+ snprintf(at_str,AT_STR_LEN,"\r\n+CME ERROR:3\r\n");
+ goto end;
+ }
+ at_print(AT_ERR,"zCtrm_LocknetUnlock cur: %ld\n",retryCount);
+ keyLen = p_msg->usDataLen;
+ if (keyLen != LOCKNET_KEY_LEN)
+ {
+ snprintf(at_str,AT_STR_LEN,"\r\n+CME ERROR:6004\r\n");
+ goto end;
+ }
+ memcpy(keyBuf,p_msg->aucDataBuf,keyLen);
+ at_print(AT_ERR,"zCtrm_ExtLocknetUnlock keyBuf=%s!\n",keyBuf);
+
+ retCode = zCtrm_UnlockCodeCheck(keyBuf,keyLen);
+ if (EXT_SUCCESS != retCode )
+ {
+ zCtrm_UnlockTimesUpdate(retryCount);
+ snprintf(at_str,AT_STR_LEN,"\r\n+CME ERROR:6004\r\n");
+ goto end;
+ }
+
+ //Ã÷ÎÄ´æÈëÓû§ÊäÈëµÄ½âËøÂë(16λ×Ö·û)
+ retCode = zCtrm_UnlockNandSet(keyBuf,keyLen);
+ if (EXT_SUCCESS != retCode )
+ {
+ zCtrm_UnlockTimesUpdate(retryCount);
+ snprintf(at_str,AT_STR_LEN,"\r\n+CME ERROR:6004\r\n");
+ goto end;
+ }
+ ret = get_modem_info("AT+ZSCHPLMN=1\r\n", NULL, NULL);
+ if (ret) {
+ at_print(AT_ERR,"zCtrm_LocknetUnlock zschplmn1 error!\n");
+ }
+ g_Sec_Status = ENCRYPT_UNLOCK_CORRECT;
+ at_print(AT_ERR,"zCtrm_UnlockModemSet\n");
+ snprintf(at_str,AT_STR_LEN,"\r\nOK\r\n");
+ goto end;
+ end:
+ send_rsp_str_to_farps(MODULE_ID_LOCKNET, at_str, strlen(at_str));
+ return 0;
+}
+
+static UINT32 zCtrm_UnlockTimesGet(UINT32 *curTimes)
+{
+ UINT32 retCode = EXT_ERROR;
+ UINT32 times = 0;
+ UINT32 maxTimes = 0;
+ T_zCtrm_LockLevel lockState = NEVER_LOCKED;
+
+ //retCode = zDrvNand_Read(AMT_LOCKNET_BASE, sizeof(lockState),(UINT8 *)&lockState);
+ retCode = cpnv_NvItemRead(AMT_LOCKNET_BASE,(UINT8 *)&lockState, sizeof(lockState));
+ at_print(AT_ERR,"zCtrm_UnlockTimesGet lockState=%d,retCode=%d!\n",lockState,retCode);
+ if (EXT_SUCCESS != retCode || lockState != LOCKED)
+ {
+ return EXT_ERROR;
+ }
+
+
+ //retCode = zDrvNand_Read(AMT_LOCKNET_TIMES, sizeof(times),(UINT8 *)×);
+ retCode = cpnv_NvItemRead(AMT_LOCKNET_TIMES,(UINT8 *)×, sizeof(times));
+ at_print(AT_ERR,"zCtrm_UnlockTimesGet times=%d,retCode=%d!\n",times,retCode);
+ if (EXT_SUCCESS != retCode)
+ {
+ return EXT_ERROR;
+ }
+
+ maxTimes = zCtrm_GetUnlockMaxTime();
+ if(times <= maxTimes)//klocwork
+ {
+ *curTimes = times;
+ return EXT_SUCCESS;
+ }
+
+ return EXT_ERROR;
+}
+
+int zCtrm_LocknetUnlockTimes(MSG_BUF *msg)
+{
+ UINT32 retCode = EXT_ERROR;
+ UINT32 retryCount = 0;
+ UINT8 pStr[4] = {0};
+ char at_str[AT_STR_LEN] = {0};
+
+ retCode = zCtrm_UnlockTimesGet(&retryCount);
+ if (EXT_SUCCESS != retCode )
+ {
+ snprintf(at_str,AT_STR_LEN,"\r\n+CME ERROR:3\r\n");
+ goto end;
+ }
+ snprintf(at_str,AT_STR_LEN,"\r\n+ZNCK:%d\r\nOK\r\n",retryCount);
+ goto end;
+end:
+ send_rsp_str_to_farps(MODULE_ID_LOCKNET, at_str, strlen(at_str));
+ return 0;
+
+}
+
+int zCtrm_LocknetStatus(MSG_BUF *msg)
+{
+ T_zCtrm_SecItems secItems = NO_ACTION;
+ char at_str[AT_STR_LEN] = {0};
+
+ if(g_Sec_Status == ENCRYPT_LOCK)
+ {
+ secItems = NET_LOCK;
+ }
+ snprintf(at_str,AT_STR_LEN,"\r\n+ZSEC:%d,%d\r\nOK\r\n",g_Sec_Status,secItems);
+ send_rsp_str_to_farps(MODULE_ID_LOCKNET, at_str, strlen(at_str));
+ return 0;
+}
+