[Feature][T106]ZXW P56U09 code

Only Configure: Yes
Affected branch: master
Affected module: unknow
Is it affected on both ZXIC and MTK: only ZXIC
Self-test: No
Doc Update: No

Change-Id: I3cbd8b420271eb20c2b40ebe5c78f83059cd42f3
diff --git a/ap/app/zte_comm/phonebook/src/pb_main.c b/ap/app/zte_comm/phonebook/src/pb_main.c
new file mode 100755
index 0000000..9442602
--- /dev/null
+++ b/ap/app/zte_comm/phonebook/src/pb_main.c
@@ -0,0 +1,152 @@
+
+#include <errno.h>

+#include <sys/msg.h>

+#include <semaphore.h>

+#include "pb_com.h"

+typedef VOID(*pAtWeb_PbMsgProc)(UINT8*pDatabuf);typedef struct{UINT32 msg_id;
+VOID(*func_ptr)(UINT8*pDatabuf);BOOL need_block;}T_zPbHandleTable;VOID 
+atWeb_AddOneContact(UINT8*pDatabuf);VOID atWeb_DelOneContact(UINT8*pDatabuf);
+VOID atWeb_DelMultiContact(UINT8*pDatabuf);VOID atWeb_DelAllContact(UINT8*
+pDatabuf);T_zPb_optRsp g_PbOptRsp={(0xc13+6886-0x26f9)};sem_t g_Pb_sem_id={
+(0x1aa5+97-0x1b06)};int g_zPb_MsqId=-(0xde9+4652-0x2014);int g_zPb_LocalMsqId=-
+(0x3e8+8013-0x2334);VOID atWeb_AddOneContact(UINT8*pDatabuf){T_zPb_WebContact*
+webPbContact=NULL;if(pDatabuf==NULL){printf(
+"\x5b\x70\x62\x5d\x2c\x20\x61\x74\x57\x65\x62\x5f\x41\x64\x64\x4f\x6e\x65\x43\x6f\x6e\x74\x61\x63\x74\x20\x70\x61\x72\x61\x20\x69\x73\x20\x6e\x75\x6c\x6c" "\n"
+);return;}webPbContact=(T_zPb_WebContact*)pDatabuf;atWeb_AddOnePb(webPbContact,
+g_Pb_sem_id);}VOID atWeb_DelOneContact(UINT8*pDatabuf){T_zPb_DelInfo*delRecord=
+NULL;if(pDatabuf==NULL){printf(
+"\x5b\x70\x62\x5d\x2c\x20\x61\x74\x57\x65\x62\x5f\x44\x65\x6c\x4f\x6e\x65\x43\x6f\x6e\x74\x61\x63\x74\x20\x70\x61\x72\x61\x20\x69\x73\x20\x6e\x75\x6c\x6c" "\n"
+);return;}delRecord=(T_zPb_DelInfo*)pDatabuf;atWeb_DelOnepb(delRecord,
+g_Pb_sem_id);}VOID atWeb_DelMultiContact(UINT8*pDatabuf){T_zPb_DelInfo*delRecord
+=NULL;if(pDatabuf==NULL){printf(
+"\x5b\x70\x62\x5d\x2c\x20\x61\x74\x57\x65\x62\x5f\x44\x65\x6c\x4f\x6e\x65\x43\x6f\x6e\x74\x61\x63\x74\x20\x70\x61\x72\x61\x20\x69\x73\x20\x6e\x75\x6c\x6c" "\n"
+);return;}delRecord=(T_zPb_DelInfo*)pDatabuf;atWeb_DelMultPb(delRecord,
+g_Pb_sem_id);}VOID atWeb_DelAllContact(UINT8*pDatabuf){T_zPb_DelInfo*delRecord=
+NULL;if(pDatabuf==NULL){printf(
+"\x5b\x70\x62\x5d\x2c\x20\x61\x74\x57\x65\x62\x5f\x44\x65\x6c\x4f\x6e\x65\x43\x6f\x6e\x74\x61\x63\x74\x20\x70\x61\x72\x61\x20\x69\x73\x20\x6e\x75\x6c\x6c" "\n"
+);return;}delRecord=(T_zPb_DelInfo*)pDatabuf;atWeb_DelAllpb(delRecord,
+g_Pb_sem_id);}VOID zPb_RecvScpbrInd(UINT8*pDatabuf){T_zPb_AtScpbrTestRes*
+scpbsInd=NULL;if(pDatabuf==NULL){return;}scpbsInd=(T_zPb_AtScpbrTestRes*)
+pDatabuf;atPb_ScpbrTestRsp(scpbsInd);}VOID zPb_RecvScpbrReadInd(UINT8*pDatabuf){
+T_zPb_ScpbrSetRes*scpbsReadInd=NULL;if(pDatabuf==NULL){return;}scpbsReadInd=(
+T_zPb_ScpbrSetRes*)pDatabuf;atPb_ScpbrSetRsp(scpbsReadInd);}VOID zPb_RecvCpmsInd
+(UINT8*pDatabuf){T_zPb_AtCpbsReadRes*cpbsInd=NULL;if(pDatabuf==NULL){return;}
+cpbsInd=(T_zPb_AtCpbsReadRes*)pDatabuf;atPb_RecvCpbsReadRsp(cpbsInd);}VOID 
+zPb_RecvZpbicInd(UINT8*pDatabuf){T_zAt_ZpbicRes*ptPara=ZUFI_NULL;if(pDatabuf==
+NULL){return;}ptPara=(T_zAt_ZpbicRes*)(pDatabuf);printf(
+"\x7a\x50\x62\x5f\x52\x65\x63\x76\x5a\x70\x62\x69\x63\x49\x6e\x64\x20\x70\x61\x72\x61\x2c\x72\x65\x73\x75\x6c\x74\x3a\x25\x64\x2c\x20\x74\x79\x70\x65\x3a\x25\x64" "\n"
+,ptPara->result,ptPara->opertype);if(((0xd24+2346-0x164d)==ptPara->result)&&(
+(0x48b+6771-0x1efd)==ptPara->opertype)){CHAR needPb[(0x6ef+2128-0xf0d)]={
+(0x50a+4142-0x1538)};sc_cfg_get(NV_NEED_SUPPORT_PB,needPb,sizeof(needPb));if(
+(0x2d6+545-0x4f7)!=strcmp(needPb,"\x6e\x6f")){ipc_send_message(MODULE_ID_PB,
+MODULE_ID_AT_CTL,MSG_CMD_PBINIT_REQ,(0x608+7221-0x223d),NULL,
+(0x151d+1227-0x19e8));}}}VOID zPb_RecvZuslotInd(UINT8*pDatabuf){T_zAt_ZuslotRes*
+ptPara=ZUFI_NULL;if(pDatabuf==NULL){return;}ptPara=(T_zAt_ZuslotRes*)(pDatabuf);
+printf(
+"\x7a\x50\x62\x5f\x52\x65\x63\x76\x5a\x70\x62\x69\x63\x49\x6e\x64\x20\x70\x61\x72\x61\x2c\x72\x65\x73\x75\x6c\x74\x3a\x25\x64\x2c\x20\x74\x79\x70\x65\x3a\x25\x64" "\n"
+,ptPara->slot,ptPara->slot_state);if(ptPara->slot_state==(0x141f+4389-0x2544)){
+CHAR needPb[(0x520+322-0x630)]={(0xabb+6947-0x25de)};sc_cfg_get(
+NV_NEED_SUPPORT_PB,needPb,sizeof(needPb));if((0x4d4+5028-0x1878)!=strcmp(needPb,
+"\x6e\x6f")){atPb_CfgPbNvInit();atPb_DelAllRecsSimDb();}}}VOID zPb_RecvPbInitRst
+(UINT8*pDatabuf){int pbReadRet=-(0x120b+4522-0x23b4);memcpy(&g_PbOptRsp,pDatabuf
+,sizeof(T_zPb_optRsp));if(g_PbOptRsp.result==-(0x98a+28-0x9a5)){atPb_IintPbErr(
+NULL);return;}pbReadRet=atPb_SendScpbrSet_repeat(g_Pb_sem_id);printf(
+"\x7a\x50\x62\x5f\x52\x65\x63\x76\x50\x62\x49\x6e\x69\x74\x52\x73\x74\x20\x72\x65\x73\x75\x6c\x74\x3a\x25\x64" "\n"
+,pbReadRet);sc_cfg_set(ZPB_NV_INIT,ZPB_OPERATE_SUC);}void zPbLocalHandleWebMsg(
+MSG_BUF*ptMsgBuf){assert(ptMsgBuf!=NULL);printf(
+"\x50\x62\x20\x72\x65\x63\x76\x20\x77\x65\x62\x20\x6d\x73\x67\x20\x63\x6d\x64\x3a\x25\x64" "\n"
+,ptMsgBuf->usMsgCmd);switch(ptMsgBuf->usMsgCmd){case MSG_CMD_WRITE_PB:
+atWeb_AddOneContact(ptMsgBuf->aucDataBuf);break;case MSG_CMD_DEL_A_PB:
+atWeb_DelOneContact(ptMsgBuf->aucDataBuf);break;case MSG_CMD_DEL_MUTI_PB:
+atWeb_DelMultiContact(ptMsgBuf->aucDataBuf);break;case MSG_CMD_DEL_ALL_PB:
+atWeb_DelAllContact(ptMsgBuf->aucDataBuf);break;default:break;}}void 
+zPbHandleWebMsg(MSG_BUF*ptMsgBuf){assert(ptMsgBuf!=NULL);printf(
+"\x50\x62\x20\x72\x65\x63\x76\x20\x77\x65\x62\x20\x6d\x73\x67\x20\x63\x6d\x64\x3a\x25\x64" "\n"
+,ptMsgBuf->usMsgCmd);switch(ptMsgBuf->usMsgCmd){case MSG_CMD_WRITE_PB:case 
+MSG_CMD_DEL_A_PB:case MSG_CMD_DEL_MUTI_PB:case MSG_CMD_DEL_ALL_PB:
+ipc_send_message(MODULE_ID_PB,MODULE_ID_PB_LOCAL,ptMsgBuf->usMsgCmd,ptMsgBuf->
+usDataLen,(unsigned char*)ptMsgBuf->aucDataBuf,(0xae3+3648-0x1923));break;
+default:break;}}UINT8 zPbMsgCreat(VOID){g_zPb_MsqId=msgget(MODULE_ID_PB,
+IPC_CREAT|(0x4a4+8140-0x22f0));if(g_zPb_MsqId==-(0x1ced+284-0x1e08)){return 
+ZUFI_FAIL;}g_zPb_LocalMsqId=msgget(MODULE_ID_PB_LOCAL,IPC_CREAT|
+(0xb03+2724-0x1427));if(g_zPb_LocalMsqId==-(0xe98+6222-0x26e5)){return ZUFI_FAIL
+;}sem_init(&g_Pb_sem_id,(0x40d+6402-0x1d0f),(0x569+2863-0x1098));return 
+ZUFI_SUCC;}void detect_modem_state(void){CHAR state[(0x12dd+3914-0x21f5)]={
+(0x4d9+1720-0xb91)};sc_cfg_get(
+"\x6d\x6f\x64\x65\x6d\x5f\x6d\x61\x69\x6e\x5f\x73\x74\x61\x74\x65",state,sizeof(
+state));if((0x17f3+2474-0x219d)==strcmp(state,
+"\x6d\x6f\x64\x65\x6d\x5f\x73\x69\x6d\x5f\x75\x6e\x64\x65\x74\x65\x63\x74\x65\x64"
+)||(0xe0f+3886-0x1d3d)==strcmp(state,
+"\x6d\x6f\x64\x65\x6d\x5f\x73\x69\x6d\x5f\x64\x65\x73\x74\x72\x6f\x79")){
+sc_cfg_set("\x70\x62\x6d\x5f\x69\x6e\x69\x74\x5f\x66\x6c\x61\x67","\x30");}}void
+ zPbLocalHandleAtctlMsg(MSG_BUF*ptMsgBuf){assert(ptMsgBuf!=NULL);printf(
+"\x50\x62\x20\x6c\x6f\x63\x61\x6c\x20\x72\x65\x63\x76\x20\x6d\x73\x67\x20\x63\x6d\x64\x3a\x25\x64" "\n"
+,ptMsgBuf->usMsgCmd);switch(ptMsgBuf->usMsgCmd){case MSG_CMD_PBINIT_RSP:
+zPb_RecvPbInitRst(ptMsgBuf->aucDataBuf);break;default:break;}}VOID 
+zPbHandleAtctlMsg(MSG_BUF*ptMsgBuf){assert(ptMsgBuf!=NULL);printf(
+"\x50\x62\x20\x72\x65\x63\x76\x20\x6d\x73\x67\x20\x63\x6d\x64\x3a\x25\x64" "\n",
+ptMsgBuf->usMsgCmd);switch(ptMsgBuf->usMsgCmd){case MSG_CMD_DELETE_PB_RSP:case 
+MSG_CMD_ADD_MODIFY_PB_RSP:case MSG_CMD_READ_PB_RSP:{memcpy(&g_PbOptRsp,ptMsgBuf
+->aucDataBuf,sizeof(T_zPb_optRsp));sem_post(&g_Pb_sem_id);}break;case 
+MSG_CMD_CPBS_IND:zPb_RecvCpmsInd(ptMsgBuf->aucDataBuf);break;case 
+MSG_CMD_SCPBR_IND:zPb_RecvScpbrInd(ptMsgBuf->aucDataBuf);break;case 
+MSG_CMD_SCPBR_READ_IND:zPb_RecvScpbrReadInd(ptMsgBuf->aucDataBuf);break;case 
+MSG_CMD_ZPBIC_IND:zPb_RecvZpbicInd(ptMsgBuf->aucDataBuf);break;case 
+MSG_CMD_ZUSLOT_IND:zPb_RecvZuslotInd(ptMsgBuf->aucDataBuf);break;case 
+MSG_CMD_PBINIT_RSP:ipc_send_message(MODULE_ID_PB,MODULE_ID_PB_LOCAL,ptMsgBuf->
+usMsgCmd,ptMsgBuf->usDataLen,(unsigned char*)ptMsgBuf->aucDataBuf,
+(0x1b1c+2464-0x24bc));break;default:break;}}VOID zPbHandleResetToFactory(){CHAR 
+clearPb[(0x21a0+988-0x254a)]={(0x111d+2882-0x1c5f)};sc_cfg_get(
+NV_CLEAR_PB_WHEN_RESTORE,clearPb,sizeof(clearPb));printf(
+"\x61\x74\x57\x65\x62\x5f\x52\x65\x73\x74\x6f\x72\x65\x46\x61\x63\x74\x6f\x72\x79\x53\x65\x74\x74\x69\x6e\x67\x20\x65\x6e\x74\x65\x72\x65\x64\x21\x20" "\n"
+);printf(
+"\x63\x6c\x65\x61\x72\x5f\x70\x62\x5f\x77\x68\x65\x6e\x5f\x72\x65\x73\x74\x6f\x72\x65\x3d\x25\x73\x20" "\n"
+,clearPb);if(strcmp(clearPb,"\x79\x65\x73")==(0x235+3478-0xfcb)){atPb_DropDb();}
+ipc_send_message(MODULE_ID_PB,MODULE_ID_MAIN_CTRL,MSG_CMD_RESET_RSP,
+(0x103f+2866-0x1b71),NULL,(0x175a+885-0x1acf));}void zPbHandleMainCtrlMsg(
+MSG_BUF*ptMsgBuf){assert(ptMsgBuf!=NULL);printf(
+"\x50\x62\x20\x72\x65\x63\x76\x20\x6d\x61\x69\x6e\x20\x63\x74\x72\x6c\x20\x6d\x73\x67\x20\x63\x6d\x64\x3a\x25\x64" "\n"
+,ptMsgBuf->usMsgCmd);switch(ptMsgBuf->usMsgCmd){case MSG_CMD_RESET_NOTIFY:
+zPbHandleResetToFactory(ptMsgBuf->aucDataBuf);break;default:break;}}void 
+pb_msg_thread_proc(void*arg){int iRet=(0x17ff+3491-0x25a2);MSG_BUF stMsg={
+(0x1105+5001-0x248e)};int msgSize=sizeof(MSG_BUF)-sizeof(SINT32);int queueId=*((
+int*)arg);prctl(PR_SET_NAME,"\x70\x62\x5f\x6c\x6f\x63\x61\x6c",
+(0xf7f+4472-0x20f7),(0x35b+6231-0x1bb2),(0x23a+9284-0x267e));while(
+(0xc4c+2934-0x17c1)){iRet=(0x1bdd+17-0x1bee);memset(&stMsg,(0xff9+649-0x1282),
+sizeof(MSG_BUF));iRet=msgrcv(queueId,&stMsg,msgSize,(0x7b+2412-0x9e7),
+(0x3b5+4689-0x1606));printf(
+"\x70\x62\x5f\x6d\x73\x67\x5f\x74\x68\x72\x65\x61\x64\x5f\x70\x72\x6f\x63\x3a\x25\x78\x2c\x25\x78\x20\x4d\x4f\x44\x55\x4c\x45\x5f\x49\x44\x5f\x41\x54\x5f\x43\x54\x4c\x3d\x25\x78" "\n"
+,stMsg.src_id,stMsg.usMsgCmd,MODULE_ID_AT_CTL);if(iRet>=(0x2041+658-0x22d3)){
+switch(stMsg.src_id){case MODULE_ID_WEB_CGI:{zPbHandleWebMsg(&stMsg);break;}case
+ MODULE_ID_AT_CTL:{zPbHandleAtctlMsg(&stMsg);break;}case MODULE_ID_PB:{
+zPbLocalHandleWebMsg(&stMsg);zPbLocalHandleAtctlMsg(&stMsg);break;}case 
+MODULE_ID_MAIN_CTRL:{zPbHandleMainCtrlMsg(&stMsg);break;}default:{break;}}}else{
+printf(
+"\x5b\x70\x62\x5d\x20\x65\x72\x72\x6e\x6f\x20\x3d\x20\x25\x64\x2c\x20\x65\x72\x72\x6d\x73\x67\x20\x3d\x20\x25\x73" "\n"
+,errno,strerror(errno));}}}int phonebook_main(int argc,char*argv[]){pthread_t 
+recv_thread_tid=(0xc24+2678-0x169a);MSG_BUF msgBuf={(0x184+7485-0x1ec1)};CHAR 
+needPb[(0xadc+4263-0x1b51)]={(0x1f6+3015-0xdbd)};prctl(PR_SET_NAME,
+"\x70\x62\x5f\x6d\x61\x69\x6e",(0xf75+359-0x10dc),(0xe42+4078-0x1e30),
+(0x9c4+1634-0x1026));loglevel_init();sc_cfg_get(NV_NEED_SUPPORT_PB,needPb,sizeof
+(needPb));if((0x23ed+769-0x26ee)!=strcmp(needPb,"\x6e\x6f")){
+#ifdef WEBS_SECURITY

+if(access(ZPB_DB_PATH,F_OK)!=(0x1146+681-0x13ef)){if(access(ZPB_TMP_PATH,F_OK)==
+(0x913+1803-0x101e)){if(remove(ZPB_SEC_PATH)!=(0x15ec+2408-0x1f54)){slog(
+PB_PRINT,SLOG_ERR,
+"\x72\x65\x6d\x6f\x76\x65\x20\x5a\x50\x42\x5f\x53\x45\x43\x5f\x50\x41\x54\x48\x20\x66\x61\x69\x6c"
+);}if(rename(ZPB_TMP_PATH,ZPB_SEC_PATH)!=(0x16f6+3785-0x25bf)){slog(PB_PRINT,
+SLOG_ERR,
+"\x72\x65\x6e\x61\x6d\x65\x20\x5a\x50\x42\x5f\x54\x4d\x50\x5f\x50\x41\x54\x48\x20\x66\x61\x69\x6c"
+);}}if(access(ZPB_SEC_PATH,F_OK)==(0x376+3721-0x11ff)){char rnum_buf[
+(0x12e3+3012-0x1e8f)]={(0x8cd+4648-0x1af5)};char cmd[(0xb36+3206-0x173c)]={
+(0x3d0+7585-0x2171)};sc_cfg_get("\x72\x6e\x75\x6d\x5f\x61\x74",rnum_buf,sizeof(
+rnum_buf));snprintf(cmd,sizeof(cmd),
+"\x2f\x62\x69\x6e\x2f\x6f\x70\x65\x6e\x73\x73\x6c\x20\x65\x6e\x63\x20\x2d\x64\x20\x2d\x61\x65\x73\x32\x35\x36\x20\x2d\x73\x61\x6c\x74\x20\x2d\x69\x6e\x20\x25\x73\x20\x2d\x6f\x75\x74\x20\x25\x73\x20\x2d\x70\x61\x73\x73\x20\x70\x61\x73\x73\x3a\x25\x73"
+,ZPB_SEC_PATH,ZPB_DB_PATH,rnum_buf);zxic_system(cmd);}}
+#endif		

+zPbMsgCreat();atPb_Init();}else{return-(0x50+284-0x16b);}printf(
+"\x50\x62\x20\x61\x70\x70\x20\x69\x6e\x69\x74\x20\x66\x69\x6e\x69\x73\x68\x65\x64\x2c\x20\x77\x69\x6c\x6c\x20\x74\x6f\x20\x72\x65\x63\x65\x69\x76\x65\x20\x6d\x73\x67\x2c\x20\x6d\x73\x67\x69\x64\x3a\x25\x64" "\n"
+,g_zPb_MsqId);if(pthread_create(&recv_thread_tid,NULL,pb_msg_thread_proc,(void*)
+(&g_zPb_LocalMsqId))==-(0x4b5+5588-0x1a88)){assert((0x22c+8869-0x24d1));}
+detect_modem_state();pb_msg_thread_proc(&g_zPb_MsqId);return(0x107a+1824-0x179a)
+;}