yuezonghe | 824eb0c | 2024-06-27 02:32:26 -0700 | [diff] [blame] | 1 | /**
|
| 2 | *
|
| 3 | * @file log_agent_main.c
|
| 4 | * @brief
|
| 5 | * This file is part of ZCAT.
|
| 6 | * log_agentÈë¿ÚÎļþ£¬´¦ÀíNVÊäÈë²ÎÊý£¬¸ù¾Ý²»Í¬ÍâÉèģʽ´¦ÀíÊý¾ÝÁ÷Ïò
|
| 7 | * NV²ÎÊý°üÀ¨:
|
| 8 | * zcat_mode
|
| 9 | * APUSB - Ó¦Óòã²Ù×÷usb¿Ú´«Êälog
|
| 10 | * APTF - Ó¦ÓÃ²ã´æ´¢logµ½TF¿¨
|
| 11 | * APNET - Ó¦Óòã²Ù×÷socket´«Êälog
|
| 12 | * APFS - Ó¦ÓÃ²ã´æ´¢logµ½Îļþϵͳ/var/zcatĿ¼
|
| 13 | * CPUSB - Äں˲ã²Ù×÷usb¿Ú´«Êälog
|
| 14 | * CPTF - ÄÚºË²ã´æ´¢logµ½TF¿¨
|
| 15 | * CPNET - Äں˲ã²Ù×÷socket´«Êälog
|
| 16 | * CPFS - ÄÚºË²ã´æ´¢logµ½Îļþϵͳ/var/zcatĿ¼
|
| 17 | * zcat_usblog
|
| 18 | * Ö¸¶¨log¿Útty·¾¶£¬ÀýÈç: ttyGS2
|
| 19 | *
|
| 20 | * @details
|
| 21 | * @author Tools Team.
|
| 22 | * @email
|
| 23 | * @copyright Copyright (C) 2013 Sanechips Technology Co., Ltd.
|
| 24 | * @warning
|
| 25 | * @date 2019/02/22
|
| 26 | * @version 1.6
|
| 27 | * @pre
|
| 28 | * @post
|
| 29 | *
|
| 30 | * @par
|
| 31 | * Change History :
|
| 32 | * ---------------------------------------------------------------------------
|
| 33 | * date version author description
|
| 34 | * ---------------------------------------------------------------------------
|
| 35 | * 2017/07/17 1.0 hou.bing Create file
|
| 36 | * 2019/01/24 1.1 jiang.fenglin 1.Ìí¼Óusblog¶ÁÐ´Ëø
|
| 37 | * 2.Ìí¼ÓÏß³ÌÃû³Æ
|
| 38 | * 2019/01/25 1.2 jiang.fenglin Ôö¼ÓAPUSBģʽÏÂtty·¾¶ÅäÖù¦ÄÜ
|
| 39 | * 2019/02/02 1.3 jiang.fenglin ÐÞ¸Ä×¢ÊÍ·½Ê½Îªdoxygen,¹æ·¶ÃüÃû
|
| 40 | * 2019/02/02 1.4 jiang.fenglin empty log_agent_usb.c
|
| 41 | * 2019/02/22 1.5 jiang.fenglin ¶¯Ì¬¿ÉÅäÖÃLOG¶Ë¿Ú,log¶Ë¿Ú¶¯Ì¬ÅäÖÃÖ»Õë¶ÔusbÅäÖÃΪÕý³£Ä£Ê½µÄÇé¿ö£¬¹¤³§Ä£Ê½±£³Ö²»±ä
|
| 42 | * 2019/03/04 1.6 jiang.fenglin Çå±àÒ뾯¸æ
|
| 43 | * 2019/07/08 1.7 jiang.fenglin Ôö¼ÓAPFS/CPFSģʽ
|
| 44 | * ---------------------------------------------------------------------------
|
| 45 | *
|
| 46 | *
|
| 47 | */
|
| 48 |
|
| 49 | #include <stdarg.h>
|
| 50 | #include <string.h>
|
| 51 | #include <pthread.h>
|
| 52 | #include <sys/msg.h>
|
| 53 | #include <sys/ioctl.h>
|
| 54 | #include "log_agent.h"
|
| 55 | #include "cfg_api.h"
|
| 56 |
|
| 57 | E_ZCAT_MODE g_log_dir = ZCAT_MODE_CP_USB;
|
| 58 | E_ZCAT_STATE g_log_state = ZCAT_STATE_INIT;
|
| 59 |
|
| 60 | extern pthread_t read_kernellog_thread;
|
| 61 | extern pthread_t read_applog_thread;
|
| 62 | extern pthread_t read_cplog_thread;
|
| 63 | extern pthread_t read_usb_thread;
|
| 64 | extern pthread_t monitor_hotplug_thread;
|
| 65 | extern pthread_t read_wifi_thread;
|
| 66 | extern pthread_t rule_heartbeat_thread;
|
| 67 |
|
| 68 | extern const char* cplog_dev;
|
| 69 | extern const char* applog_dev;
|
| 70 | extern const char* kernellog_dev;
|
| 71 |
|
| 72 | extern int cplog_fd;
|
| 73 | extern int applog_fd;
|
| 74 | extern int kernellog_fd;
|
| 75 |
|
| 76 | extern int init_log_agent_tools();
|
| 77 | extern int init_usblog_mode();
|
| 78 | extern int init_sdcard_mode();
|
| 79 | extern int init_net_mode();
|
| 80 |
|
| 81 | extern void *read_applog(void* args);
|
| 82 | extern void *read_kernellog(void* args);
|
| 83 | extern void *read_cplog(void* args);
|
| 84 |
|
| 85 | extern char g_zcat_usblog[8]; // ´æ´¢usblogµÄttyÉ豸Ãû
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 | /**
|
| 90 | * @brief µ±cp²àÍÂlogʱµÄ³õʼ»¯
|
| 91 | * @param[in] void
|
| 92 | * @return 1 on success, errno otherwise
|
| 93 | * @note
|
| 94 | * @see
|
| 95 | */
|
| 96 | int init_cp_mode()
|
| 97 | {
|
| 98 | return 1;
|
| 99 | }
|
| 100 |
|
| 101 |
|
| 102 | /**
|
| 103 | * @brief zte_log_agentÈë¿Úº¯Êý£¬´¦ÀíNVÊäÈë²ÎÊý£¬¸ù¾Ý²»Í¬Ä£Ê½´¦ÀíÊý¾ÝÁ÷Ïò
|
| 104 | *
|
| 105 | * @return ·µ»ØËµÃ÷
|
| 106 | * -<em>-1</em> fail
|
| 107 | * -<em>0</em> succeed
|
| 108 | */
|
| 109 | int main()
|
| 110 | {
|
| 111 | char zcat_mode[16] = { 0 };
|
| 112 | char zcat_usblog[8] = { 0 };
|
| 113 | int ret = 0;
|
| 114 |
|
| 115 | // 1.»ñÈ¡nvÖµ
|
| 116 | cfg_get_item("zcat_mode", zcat_mode, sizeof(zcat_mode) - 1);
|
| 117 | if (strcmp(zcat_mode, "APTF") == 0)
|
| 118 | {
|
| 119 | g_log_dir = ZCAT_MODE_AP_TF;
|
| 120 | }
|
| 121 | else if (strcmp(zcat_mode, "CPTF") == 0)
|
| 122 | {
|
| 123 | g_log_dir = ZCAT_MODE_CP_TF;
|
| 124 | }
|
| 125 | else if (strcmp(zcat_mode, "APFS") == 0)
|
| 126 | {
|
| 127 | g_log_dir = ZCAT_MODE_AP_FS;
|
| 128 | }
|
| 129 | else if (strcmp(zcat_mode, "CPFS") == 0)
|
| 130 | {
|
| 131 | g_log_dir = ZCAT_MODE_CP_FS;
|
| 132 | }
|
| 133 | else if (strcmp(zcat_mode, "APNET") == 0)
|
| 134 | {
|
| 135 | g_log_dir = ZCAT_MODE_AP_NET;
|
| 136 | }
|
| 137 | else if (strcmp(zcat_mode, "CPNET") == 0)
|
| 138 | {
|
| 139 | g_log_dir = ZCAT_MODE_CP_NET;
|
| 140 | }
|
| 141 | else if (strcmp(zcat_mode, "APUSB") == 0)
|
| 142 | {
|
| 143 | g_log_dir = ZCAT_MODE_AP_USB;
|
| 144 | }
|
| 145 | else
|
| 146 | {
|
| 147 | g_log_dir = ZCAT_MODE_CP_USB;
|
| 148 | }
|
| 149 |
|
| 150 | printf("[zcat] zcat_mode = 0x%x\n", g_log_dir);
|
| 151 |
|
| 152 | if (ZCAT_MODE_AP_USB == g_log_dir || ZCAT_MODE_CP_USB == g_log_dir)
|
| 153 | {
|
| 154 | cfg_get_item("zcat_usblog", zcat_usblog, sizeof(zcat_usblog) - 1);
|
| 155 | if (strlen(zcat_usblog) > 3)
|
| 156 | {
|
| 157 | memcpy(g_zcat_usblog, zcat_usblog, sizeof(zcat_usblog));
|
| 158 | }
|
| 159 | printf("[zcat] zcat_usblog = %s\n", g_zcat_usblog);
|
| 160 | }
|
| 161 |
|
| 162 |
|
| 163 | // 2.³õʼ»¯È«¾Ö±äÁ¿
|
| 164 | init_log_agent_tools();
|
| 165 |
|
| 166 | // 3.¸ù¾Ýģʽ´ò¿ªlogÊý¾ÝÔ´É豸²¢´´½¨µÄ¹¤×÷Ïß³Ì
|
| 167 | // V3E²»ÐèÒª¶ÁÈ¡applogºÍkernellogÉ豸
|
| 168 | cplog_fd = open(cplog_dev, O_RDWR);
|
| 169 | if (cplog_fd < 0) {
|
| 170 | goto __exit;
|
| 171 | }
|
| 172 |
|
| 173 | 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))
|
| 174 | {
|
| 175 | // 3.1 ´ò¿ªÊý¾ÝÔ´É豸
|
| 176 | #if 0
|
| 177 | applog_fd = open(applog_dev, O_RDWR);
|
| 178 | if (applog_fd < 0) {
|
| 179 | goto __exit;
|
| 180 | }
|
| 181 | kernellog_fd = open(kernellog_dev, O_RDWR);
|
| 182 | if (kernellog_fd < 0) {
|
| 183 | goto __exit;
|
| 184 | }
|
| 185 | #endif
|
| 186 |
|
| 187 | // 3.2 ´´½¨Êý¾ÝÔ´É豸µÄ¶ÁдÏß³Ì
|
| 188 | #if 0
|
| 189 | ret = pthread_create(&read_applog_thread, NULL, read_applog, NULL);
|
| 190 | if(ret != 0 ) {
|
| 191 | goto __exit;
|
| 192 | }
|
| 193 | ret = pthread_create(&read_kernellog_thread, NULL, read_kernellog, NULL);
|
| 194 | if(ret != 0) {
|
| 195 | goto __exit;
|
| 196 | }
|
| 197 | #endif
|
| 198 | ret = pthread_create(&read_cplog_thread, NULL, read_cplog, NULL);
|
| 199 | if(ret != 0) {
|
| 200 | goto __exit;
|
| 201 | }
|
| 202 | }
|
| 203 |
|
| 204 | printf("[zcat] init logdev success.\n");
|
| 205 |
|
| 206 | // 4.³õʼ»¯Êý¾ÝÊä³öÍâÉè
|
| 207 | switch(g_log_dir)
|
| 208 | {
|
| 209 | case ZCAT_MODE_AP_USB:
|
| 210 | {
|
| 211 | if(init_usblog_mode() < 0) {
|
| 212 | goto __exit;
|
| 213 | }
|
| 214 | break;
|
| 215 | }
|
| 216 | case ZCAT_MODE_AP_TF:
|
| 217 | case ZCAT_MODE_AP_FS:
|
| 218 | {
|
| 219 | /*
|
| 220 | if(init_sdcard_mode() < 0) {
|
| 221 | goto __exit;
|
| 222 | }*/
|
| 223 | init_sdcard_mode();
|
| 224 | break;
|
| 225 | }
|
| 226 | case ZCAT_MODE_AP_NET:
|
| 227 | {
|
| 228 | if(init_net_mode() < 0) {
|
| 229 | goto __exit;
|
| 230 | }
|
| 231 | break;
|
| 232 | }
|
| 233 | case ZCAT_MODE_CP_USB:
|
| 234 | case ZCAT_MODE_CP_TF:
|
| 235 | case ZCAT_MODE_CP_NET:
|
| 236 | case ZCAT_MODE_CP_FS:
|
| 237 | {
|
| 238 |
|
| 239 | /*
|
| 240 | if(init_cp_mode() < 0) {
|
| 241 | goto __exit;
|
| 242 | }
|
| 243 | */
|
| 244 | init_cp_mode();
|
| 245 | break;
|
| 246 | }
|
| 247 |
|
| 248 | default: {
|
| 249 | goto __exit;
|
| 250 | }
|
| 251 | }
|
| 252 |
|
| 253 | g_log_state = ZCAT_STATE_RUNNING;
|
| 254 |
|
| 255 | // 5.³õʼ»¯Á÷³ÌÍê³É£¬Óëcpͬ²½
|
| 256 | printf("[zcat] init peripheral success.\n");
|
| 257 |
|
| 258 | if(ioctl(cplog_fd, ZCAT_IPC_SET_PERIPHERAL_MODE, g_log_dir)!= 0)
|
| 259 | {
|
| 260 | printf("[zcat]ioctl:ZCAT_IPC_SET_PERIPHERAL_MODE fail!\n");
|
| 261 | }
|
| 262 | if(ioctl(cplog_fd, ZCAT_IPC_SET_TTY, g_zcat_usblog)!= 0)
|
| 263 | {
|
| 264 | printf("[zcat]ioctl:ZCAT_IPC_SET_TTY fail!\n");
|
| 265 | }
|
| 266 | if(ioctl(cplog_fd, ZCAT_IPC_SYN, 0)!=0)
|
| 267 | {
|
| 268 | printf("[zcat]ioctl:ZCAT_IPC_SYN fail!\n");
|
| 269 | }
|
| 270 |
|
| 271 | while(1)
|
| 272 | {
|
| 273 | ret = ioctl(cplog_fd, ZCAT_IPC_ACK, 0);
|
| 274 | if(ret == 0)
|
| 275 | {
|
| 276 | ioctl(cplog_fd, ZCAT_IPC_ESTABLISHED, 0);
|
| 277 | break;
|
| 278 | }
|
| 279 | sleep(1);
|
| 280 | }
|
| 281 |
|
| 282 | __exit:
|
| 283 | // 6. Í˳ö
|
| 284 | if(read_kernellog_thread > 0) pthread_join(read_kernellog_thread, NULL);
|
| 285 | if(read_applog_thread > 0) pthread_join(read_applog_thread, NULL);
|
| 286 | if(read_cplog_thread > 0) pthread_join(read_cplog_thread, NULL);
|
| 287 | if(monitor_hotplug_thread > 0) pthread_join(monitor_hotplug_thread, NULL);
|
| 288 | if(read_usb_thread > 0) pthread_join(read_usb_thread, NULL);
|
| 289 | if(read_wifi_thread > 0) pthread_join(read_wifi_thread, NULL);
|
| 290 | if(rule_heartbeat_thread > 0) pthread_join(rule_heartbeat_thread, NULL);
|
| 291 |
|
| 292 | if(applog_fd >= 0) close(applog_fd);
|
| 293 | if(kernellog_fd >= 0) close(kernellog_fd);
|
| 294 | if(cplog_fd >= 0) close(cplog_fd);
|
| 295 |
|
| 296 | printf("[zcat] zte_log_agent exit.\n");
|
| 297 |
|
| 298 | return 0;
|
| 299 | }
|