zte's code,first commit
Change-Id: I9a04da59e459a9bc0d67f101f700d9d7dc8d681b
diff --git a/ap/app/zte_log_agent/log_agent_main.c b/ap/app/zte_log_agent/log_agent_main.c
new file mode 100644
index 0000000..9a21cd6
--- /dev/null
+++ b/ap/app/zte_log_agent/log_agent_main.c
@@ -0,0 +1,299 @@
+/**
+ *
+ * @file log_agent_main.c
+ * @brief
+ * This file is part of ZCAT.
+ * log_agentÈë¿ÚÎļþ£¬´¦ÀíNVÊäÈë²ÎÊý£¬¸ù¾Ý²»Í¬ÍâÉèģʽ´¦ÀíÊý¾ÝÁ÷Ïò
+ * NV²ÎÊý°üÀ¨:
+ * zcat_mode
+ * APUSB - Ó¦Óòã²Ù×÷usb¿Ú´«Êälog
+ * APTF - Ó¦ÓÃ²ã´æ´¢logµ½TF¿¨
+ * APNET - Ó¦Óòã²Ù×÷socket´«Êälog
+ * APFS - Ó¦ÓÃ²ã´æ´¢logµ½Îļþϵͳ/var/zcatĿ¼
+ * CPUSB - Äں˲ã²Ù×÷usb¿Ú´«Êälog
+ * CPTF - ÄÚºË²ã´æ´¢logµ½TF¿¨
+ * CPNET - Äں˲ã²Ù×÷socket´«Êälog
+ * CPFS - ÄÚºË²ã´æ´¢logµ½Îļþϵͳ/var/zcatĿ¼
+ * zcat_usblog
+ * Ö¸¶¨log¿Útty·¾¶£¬ÀýÈç: ttyGS2
+ *
+ * @details
+ * @author Tools Team.
+ * @email
+ * @copyright Copyright (C) 2013 Sanechips Technology Co., Ltd.
+ * @warning
+ * @date 2019/02/22
+ * @version 1.6
+ * @pre
+ * @post
+ *
+ * @par
+ * Change History :
+ * ---------------------------------------------------------------------------
+ * date version author description
+ * ---------------------------------------------------------------------------
+ * 2017/07/17 1.0 hou.bing Create file
+ * 2019/01/24 1.1 jiang.fenglin 1.Ìí¼Óusblog¶ÁÐ´Ëø
+ * 2.Ìí¼ÓÏß³ÌÃû³Æ
+ * 2019/01/25 1.2 jiang.fenglin Ôö¼ÓAPUSBģʽÏÂtty·¾¶ÅäÖù¦ÄÜ
+ * 2019/02/02 1.3 jiang.fenglin ÐÞ¸Ä×¢ÊÍ·½Ê½Îªdoxygen,¹æ·¶ÃüÃû
+ * 2019/02/02 1.4 jiang.fenglin empty log_agent_usb.c
+ * 2019/02/22 1.5 jiang.fenglin ¶¯Ì¬¿ÉÅäÖÃLOG¶Ë¿Ú,log¶Ë¿Ú¶¯Ì¬ÅäÖÃÖ»Õë¶ÔusbÅäÖÃΪÕý³£Ä£Ê½µÄÇé¿ö£¬¹¤³§Ä£Ê½±£³Ö²»±ä
+ * 2019/03/04 1.6 jiang.fenglin Çå±àÒ뾯¸æ
+ * 2019/07/08 1.7 jiang.fenglin Ôö¼ÓAPFS/CPFSģʽ
+ * ---------------------------------------------------------------------------
+ *
+ *
+ */
+
+#include <stdarg.h>
+#include <string.h>
+#include <pthread.h>
+#include <sys/msg.h>
+#include <sys/ioctl.h>
+#include "log_agent.h"
+#include "cfg_api.h"
+
+E_ZCAT_MODE g_log_dir = ZCAT_MODE_CP_USB;
+E_ZCAT_STATE g_log_state = ZCAT_STATE_INIT;
+
+extern pthread_t read_kernellog_thread;
+extern pthread_t read_applog_thread;
+extern pthread_t read_cplog_thread;
+extern pthread_t read_usb_thread;
+extern pthread_t monitor_hotplug_thread;
+extern pthread_t read_wifi_thread;
+extern pthread_t rule_heartbeat_thread;
+
+extern const char* cplog_dev;
+extern const char* applog_dev;
+extern const char* kernellog_dev;
+
+extern int cplog_fd;
+extern int applog_fd;
+extern int kernellog_fd;
+
+extern int init_log_agent_tools();
+extern int init_usblog_mode();
+extern int init_sdcard_mode();
+extern int init_net_mode();
+
+extern void *read_applog(void* args);
+extern void *read_kernellog(void* args);
+extern void *read_cplog(void* args);
+
+extern char g_zcat_usblog[8]; // ´æ´¢usblogµÄttyÉ豸Ãû
+
+
+
+/**
+ * @brief µ±cp²àÍÂlogʱµÄ³õʼ»¯
+ * @param[in] void
+ * @return 1 on success, errno otherwise
+ * @note
+ * @see
+ */
+int init_cp_mode()
+{
+ return 1;
+}
+
+
+/**
+ * @brief zte_log_agentÈë¿Úº¯Êý£¬´¦ÀíNVÊäÈë²ÎÊý£¬¸ù¾Ý²»Í¬Ä£Ê½´¦ÀíÊý¾ÝÁ÷Ïò
+ *
+ * @return ·µ»ØËµÃ÷
+ * -<em>-1</em> fail
+ * -<em>0</em> succeed
+ */
+int main()
+{
+ char zcat_mode[16] = { 0 };
+ char zcat_usblog[8] = { 0 };
+ int ret = 0;
+
+ // 1.»ñÈ¡nvÖµ
+ cfg_get_item("zcat_mode", zcat_mode, sizeof(zcat_mode) - 1);
+ if (strcmp(zcat_mode, "APTF") == 0)
+ {
+ g_log_dir = ZCAT_MODE_AP_TF;
+ }
+ else if (strcmp(zcat_mode, "CPTF") == 0)
+ {
+ g_log_dir = ZCAT_MODE_CP_TF;
+ }
+ else if (strcmp(zcat_mode, "APFS") == 0)
+ {
+ g_log_dir = ZCAT_MODE_AP_FS;
+ }
+ else if (strcmp(zcat_mode, "CPFS") == 0)
+ {
+ g_log_dir = ZCAT_MODE_CP_FS;
+ }
+ else if (strcmp(zcat_mode, "APNET") == 0)
+ {
+ g_log_dir = ZCAT_MODE_AP_NET;
+ }
+ else if (strcmp(zcat_mode, "CPNET") == 0)
+ {
+ g_log_dir = ZCAT_MODE_CP_NET;
+ }
+ else if (strcmp(zcat_mode, "APUSB") == 0)
+ {
+ g_log_dir = ZCAT_MODE_AP_USB;
+ }
+ else
+ {
+ g_log_dir = ZCAT_MODE_CP_USB;
+ }
+
+ printf("[zcat] zcat_mode = 0x%x\n", g_log_dir);
+
+ if (ZCAT_MODE_AP_USB == g_log_dir || ZCAT_MODE_CP_USB == g_log_dir)
+ {
+ cfg_get_item("zcat_usblog", zcat_usblog, sizeof(zcat_usblog) - 1);
+ if (strlen(zcat_usblog) > 3)
+ {
+ memcpy(g_zcat_usblog, zcat_usblog, sizeof(zcat_usblog));
+ }
+ printf("[zcat] zcat_usblog = %s\n", g_zcat_usblog);
+ }
+
+
+ // 2.³õʼ»¯È«¾Ö±äÁ¿
+ init_log_agent_tools();
+
+ // 3.¸ù¾Ýģʽ´ò¿ªlogÊý¾ÝÔ´É豸²¢´´½¨µÄ¹¤×÷Ïß³Ì
+ // V3E²»ÐèÒª¶ÁÈ¡applogºÍkernellogÉ豸
+ cplog_fd = open(cplog_dev, O_RDWR);
+ if (cplog_fd < 0) {
+ goto __exit;
+ }
+
+ if((g_log_dir == ZCAT_MODE_AP_USB) || (g_log_dir == ZCAT_MODE_AP_TF) || (g_log_dir == ZCAT_MODE_AP_NET) || (g_log_dir == ZCAT_MODE_AP_FS))
+ {
+ // 3.1 ´ò¿ªÊý¾ÝÔ´É豸
+ #if 0
+ applog_fd = open(applog_dev, O_RDWR);
+ if (applog_fd < 0) {
+ goto __exit;
+ }
+ kernellog_fd = open(kernellog_dev, O_RDWR);
+ if (kernellog_fd < 0) {
+ goto __exit;
+ }
+ #endif
+
+ // 3.2 ´´½¨Êý¾ÝÔ´É豸µÄ¶ÁдÏß³Ì
+ #if 0
+ ret = pthread_create(&read_applog_thread, NULL, read_applog, NULL);
+ if(ret != 0 ) {
+ goto __exit;
+ }
+ ret = pthread_create(&read_kernellog_thread, NULL, read_kernellog, NULL);
+ if(ret != 0) {
+ goto __exit;
+ }
+ #endif
+ ret = pthread_create(&read_cplog_thread, NULL, read_cplog, NULL);
+ if(ret != 0) {
+ goto __exit;
+ }
+ }
+
+ printf("[zcat] init logdev success.\n");
+
+ // 4.³õʼ»¯Êý¾ÝÊä³öÍâÉè
+ switch(g_log_dir)
+ {
+ case ZCAT_MODE_AP_USB:
+ {
+ if(init_usblog_mode() < 0) {
+ goto __exit;
+ }
+ break;
+ }
+ case ZCAT_MODE_AP_TF:
+ case ZCAT_MODE_AP_FS:
+ {
+ /*
+ if(init_sdcard_mode() < 0) {
+ goto __exit;
+ }*/
+ init_sdcard_mode();
+ break;
+ }
+ case ZCAT_MODE_AP_NET:
+ {
+ if(init_net_mode() < 0) {
+ goto __exit;
+ }
+ break;
+ }
+ case ZCAT_MODE_CP_USB:
+ case ZCAT_MODE_CP_TF:
+ case ZCAT_MODE_CP_NET:
+ case ZCAT_MODE_CP_FS:
+ {
+
+ /*
+ if(init_cp_mode() < 0) {
+ goto __exit;
+ }
+ */
+ init_cp_mode();
+ break;
+ }
+
+ default: {
+ goto __exit;
+ }
+ }
+
+ g_log_state = ZCAT_STATE_RUNNING;
+
+ // 5.³õʼ»¯Á÷³ÌÍê³É£¬Óëcpͬ²½
+ printf("[zcat] init peripheral success.\n");
+
+ if(ioctl(cplog_fd, ZCAT_IPC_SET_PERIPHERAL_MODE, g_log_dir)!= 0)
+ {
+ printf("[zcat]ioctl:ZCAT_IPC_SET_PERIPHERAL_MODE fail!\n");
+ }
+ if(ioctl(cplog_fd, ZCAT_IPC_SET_TTY, g_zcat_usblog)!= 0)
+ {
+ printf("[zcat]ioctl:ZCAT_IPC_SET_TTY fail!\n");
+ }
+ if(ioctl(cplog_fd, ZCAT_IPC_SYN, 0)!=0)
+ {
+ printf("[zcat]ioctl:ZCAT_IPC_SYN fail!\n");
+ }
+
+ while(1)
+ {
+ ret = ioctl(cplog_fd, ZCAT_IPC_ACK, 0);
+ if(ret == 0)
+ {
+ ioctl(cplog_fd, ZCAT_IPC_ESTABLISHED, 0);
+ break;
+ }
+ sleep(1);
+ }
+
+__exit:
+ // 6. Í˳ö
+ if(read_kernellog_thread > 0) pthread_join(read_kernellog_thread, NULL);
+ if(read_applog_thread > 0) pthread_join(read_applog_thread, NULL);
+ if(read_cplog_thread > 0) pthread_join(read_cplog_thread, NULL);
+ if(monitor_hotplug_thread > 0) pthread_join(monitor_hotplug_thread, NULL);
+ if(read_usb_thread > 0) pthread_join(read_usb_thread, NULL);
+ if(read_wifi_thread > 0) pthread_join(read_wifi_thread, NULL);
+ if(rule_heartbeat_thread > 0) pthread_join(rule_heartbeat_thread, NULL);
+
+ if(applog_fd >= 0) close(applog_fd);
+ if(kernellog_fd >= 0) close(kernellog_fd);
+ if(cplog_fd >= 0) close(cplog_fd);
+
+ printf("[zcat] zte_log_agent exit.\n");
+
+ return 0;
+}