[T106][ZXW-22]7520V3SCV2.01.01.02P42U09_VEC_V0.8_AP_VEC origin source commit

Change-Id: Ic6e05d89ecd62fc34f82b23dcf306c93764aec4b
diff --git a/ap/app/zte_uicc_agt_svr/Makefile b/ap/app/zte_uicc_agt_svr/Makefile
new file mode 100755
index 0000000..8233b1e
--- /dev/null
+++ b/ap/app/zte_uicc_agt_svr/Makefile
@@ -0,0 +1,55 @@
+#*******************************************************************************

+# include ZTE application makefile

+#*******************************************************************************

+include $(zte_app_mak)

+#*******************************************************************************

+# execute

+#*******************************************************************************

+EXEC    = uicc_agt_svr

+

+#*******************************************************************************

+# objects

+#*******************************************************************************

+OBJS    = uicc_agt_svr.o

+		  

+#*******************************************************************************

+# include path

+#*******************************************************************************

+CFLAGS += -I. \

+		  -I./inc \

+		  -I$(zte_app_path)/include \

+		  -I$(zte_lib_path)/libzte_vsim/inc \

+		  -Wall \

+		  -O -Dlinux=1 -DHIGH_SPEED=1 \

+		  -g -Werror=implicit-function-declaration

+		  

+#*******************************************************************************

+# library

+#*******************************************************************************

+LDLIBS += -lpthread

+LDLIBS += -lzte_vsim -L$(zte_lib_path)/libzte_vsim

+LDLIBS += -lsoftap -L$(zte_lib_path)/libsoftap

+LDLIBS += -lsoft_timer_sc -L$(zte_lib_path)/libsoft_timer

+LDLIBS += -lnvram_sc -L$(zte_lib_path)/libnvram

+

+		   

+

+#*******************************************************************************

+# library path

+#*******************************************************************************

+

+#*******************************************************************************

+# targets

+#*******************************************************************************

+all: $(EXEC)

+

+$(EXEC): $(OBJS)

+	$(CC) $(LDFLAGS) -o $@ $(OBJS) -Wl,--start-group $(LDLIBS) -Wl,--end-group

+	@cp $@ $@.elf

+	

+romfs:

+	$(ROMFSINST)  /bin/$(EXEC)

+	

+clean:

+	-rm -f $(EXEC) *.elf *.gdb *.o

+

diff --git a/ap/app/zte_uicc_agt_svr/uicc_agt_svr.c b/ap/app/zte_uicc_agt_svr/uicc_agt_svr.c
new file mode 100755
index 0000000..3642d6c
--- /dev/null
+++ b/ap/app/zte_uicc_agt_svr/uicc_agt_svr.c
@@ -0,0 +1,233 @@
+/*******************************************************************************

+ * Copyright by ZTE Corporation.

+ *

+ * File Name:    uicc_agt_local.c

+ * File Mark:    

+ * Description:  uicc ´úÀí´¦ÀíÏß³Ì

+ * Others:        

+ * Version:       V1.0

+ * Author:        

+ * Date:          

+ * History 1:      

+ *     Date: 

+ *     Version:

+ *     Author: 

+ *     Modification:  

+ * History 2: 

+********************************************************************************/

+ /****************************************************************************

+* 	                                           Include files

+****************************************************************************/

+#include "vsim.h"

+#include <linux/uicc_agt_client.h>

+

+/****************************************************************************

+* 	                                           Local Macros

+****************************************************************************/

+#define VSIM_BIN_AUTH_LEN 520

+

+/****************************************************************************

+* 	                                           Local Types

+****************************************************************************/

+

+/****************************************************************************

+* 	                                           Local Constants

+****************************************************************************/

+

+/****************************************************************************

+* 	                                           Local Function Prototypes

+****************************************************************************/

+

+/****************************************************************************

+* 	                                          Global Constants

+****************************************************************************/

+

+/****************************************************************************

+* 	                                          Global Variables

+****************************************************************************/

+int g_fd = -1;

+

+/****************************************************************************

+* 	                                          Global Function Prototypes

+****************************************************************************/

+

+/****************************************************************************

+* 	                                          Function Definitions

+****************************************************************************/

+int usim_reset_proc(T_UICC_RESET_REQ_MSG *reset_req)

+{

+	VSIM_MSG_BUF stMsg={0};

+	int ret =0;

+	T_UICC_RESET_RSP_MSG *reset_rsp = (T_UICC_RESET_RSP_MSG *)stMsg.aucDataBuf;

+	reset_rsp->card_selector = reset_req->card_selector;

+	reset_rsp->func_resp = zVcard_ResetCard(reset_req->card_selector);

+	if(reset_rsp->func_resp){

+		printf("@vsim@ usim_reset_proc err rsp=%d\n",reset_rsp->func_resp);

+		system("cp -fp /etc_ro/vSim.bin /mnt/userdata/");

+	}

+	stMsg.usMsgCmd=MSG_CMD_USIM_RESET;

+	stMsg.usDataLen=sizeof(T_UICC_RESET_RSP_MSG);

+	ret = write(g_fd, &stMsg, sizeof(stMsg));

+	printf("@vsim@ usim_reset_proc send %d\n",ret);

+	return 1;

+}

+

+int usim_getatr_proc(T_UICC_ATR_REQ_MSG *atr_req)

+{

+	VSIM_MSG_BUF stMsg={0};

+	int ret =0;

+	T_UICC_ATR_RSP_MSG *atr_rsp = (T_UICC_ATR_RSP_MSG *)stMsg.aucDataBuf;

+	atr_rsp->card_selector = atr_req->card_selector;

+	atr_rsp->func_resp = zVcard_GetAtr(atr_req->card_selector,atr_rsp->atr_data);

+	stMsg.usMsgCmd=MSG_CMD_USIM_GETATR;

+	stMsg.usDataLen=sizeof(T_UICC_ATR_RSP_MSG);

+	ret = write(g_fd, &stMsg, sizeof(stMsg));

+	printf("@vsim@ usim_getatr_proc send %d\n",ret);

+	return 1;

+}

+

+int usim_apdu_proc(T_UICC_TRANSPORT_APDU_REQ_MSG *apdu_req)

+{

+	VSIM_MSG_BUF stMsg={0};

+	int ret =0;

+	T_ZDrvUicc_ApduHeader tCApdu;

+	T_UICC_TRANSPORT_APDU_RSP_MSG *apdu_rsp = (T_UICC_TRANSPORT_APDU_RSP_MSG *)stMsg.aucDataBuf;

+	apdu_rsp->card_selector = apdu_req->card_selector;

+	memcpy(&tCApdu, &apdu_req->c_apdu,sizeof(T_ZDrvUicc_ApduHeader));

+	apdu_rsp->func_resp = zVcard_TransportApdu(apdu_req->card_selector, apdu_req->command_case, apdu_req->extended_length, tCApdu, &apdu_rsp->r_apdu_ptr,apdu_req->data_req);

+	memcpy(apdu_rsp->data_rsp,apdu_req->data_req,apdu_rsp->r_apdu_ptr.luicc);

+	stMsg.usMsgCmd=MSG_CMD_USIM_APDU;

+	stMsg.usDataLen=sizeof(T_UICC_TRANSPORT_APDU_RSP_MSG);

+	ret = write(g_fd, &stMsg, sizeof(stMsg));

+	printf("@vsim@ usim_apdu_proc send %d\n",ret);

+	return 1;

+}

+

+int usim_close_proc(T_UICC_CLOSE_REQ_MSG *close_req)

+{

+	VSIM_MSG_BUF stMsg={0};

+	int ret =0;

+	T_UICC_CLOSE_RSP_MSG *close_rsp = (T_UICC_CLOSE_RSP_MSG *)stMsg.aucDataBuf;

+	close_rsp->card_selector = close_req->card_selector;

+	close_rsp->func_resp = zVcard_CloseCard(close_req->card_selector);

+	stMsg.usMsgCmd=MSG_CMD_USIM_CLOSE;

+	stMsg.usDataLen=sizeof(T_UICC_CLOSE_RSP_MSG);

+	ret = write(g_fd, &stMsg, sizeof(stMsg));

+	printf("@vsim@ usim_close_proc send %d\n",ret);

+	return 1;

+}

+

+int rcv_msg_proc(VSIM_MSG_BUF *msg_buf)

+{

+	switch (msg_buf->usMsgCmd)

+    {

+    case MSG_CMD_USIM_RESET:

+		usim_reset_proc((T_UICC_RESET_REQ_MSG *)(msg_buf->aucDataBuf));

+		break;

+	case MSG_CMD_USIM_GETATR:

+		usim_getatr_proc((T_UICC_ATR_REQ_MSG *)(msg_buf->aucDataBuf));

+		break;

+	case MSG_CMD_USIM_APDU:

+		usim_apdu_proc((T_UICC_TRANSPORT_APDU_REQ_MSG *)(msg_buf->aucDataBuf));

+		break;

+	case MSG_CMD_USIM_CLOSE:

+		usim_close_proc((T_UICC_CLOSE_REQ_MSG *)(msg_buf->aucDataBuf));

+		break;

+	default:

+		printf("@vsim@ rcv_msg_proc msgid 0x%x\n",msg_buf->usMsgCmd);

+		break;

+	}

+	return 0;

+}

+

+int check_vsim_bin(int fd)

+{

+	int fd_r = open("/etc_ro/vSim.bin",O_RDONLY);

+	if(fd_r >= 0){

+		unsigned char buf_r[VSIM_BIN_AUTH_LEN] = {0};

+		unsigned char buf[VSIM_BIN_AUTH_LEN] = {0};

+		int read_len = 0;

+		int read_len_r = 0;

+again1:

+		read_len = read(fd, buf, sizeof(buf));

+		if (read_len < 0) {

+			if (errno == EINTR){

+				printf("@vsim@ Read bin, interrupted!\n");

+				goto again1;

+			}else{

+				printf("@vsim@ Read bin fail, error:[%d]%s\n", errno, strerror(errno));

+				goto err_out;

+			}

+		}else if(read_len != sizeof(buf)){

+			printf("@vsim@ Read bin len=%d err\n", read_len);

+			goto err_out;

+		}

+again2:

+		read_len_r = read(fd_r, buf_r, sizeof(buf_r));

+		if (read_len_r < 0) {

+			if (errno == EINTR){

+				printf("@vsim@ Read bin_ro, interrupted!\n");

+				goto again2;

+			}else{

+				printf("@vsim@ Read bin_ro fail, error:[%d]%s\n", errno, strerror(errno));

+				goto err_out;

+			}

+		}else if(read_len_r != sizeof(buf_r)){

+			printf("@vsim@ Read bin_ro len=%d err\n", read_len_r);

+			goto err_out;

+		}

+		close(fd_r);

+		return memcmp(buf_r, buf, sizeof(buf_r));

+	} else {

+		printf("@vsim@ open vsim_ro fail, error:[%d]%s", errno, strerror(errno));

+		return -1;

+	}

+

+err_out:

+	close(fd_r);

+	return -1;

+}

+

+int main(int argc, char* argv[])

+{

+	VSIM_MSG_BUF stMsg;

+	int iRet = 0;

+	g_fd = open("/dev/rpm0",O_RDWR);

+	printf("@vsim@ open rpm0 fd: %d er_no: %d\n", g_fd, errno);

+	//assert(g_fd >= 0);

+	if(g_fd < 0)

+	{

+		exit(0);

+	}

+	{

+		int fd = open("/mnt/userdata/vSim.bin",O_RDONLY);

+		printf("@vsim@ open userdata/vSim.bin fd: %d er_no: %d\n", fd, errno);

+		if(fd >= 0)

+		{

+			if(check_vsim_bin(fd)){

+				printf("@vsim@ check_vsim_bin fail copy form ro\n");

+				system("cp -fp /etc_ro/vSim.bin /mnt/userdata/");

+			}

+			close(fd);

+		}

+		else

+			system("cp -fp /etc_ro/vSim.bin /mnt/userdata/");

+	}

+	while(1)

+    {

+        memset(&stMsg, 0x00, sizeof(VSIM_MSG_BUF));

+

+		iRet = read(g_fd, &stMsg, sizeof(stMsg));

+        if (iRet >= 0)

+        {

+            rcv_msg_proc(&stMsg);            

+        }

+        else

+        {

+            if(errno != EINTR)

+                printf("errno = %d, errmsg = %s\n", errno,strerror(errno));

+        }

+    }

+	

+}

+