yuezonghe | 824eb0c | 2024-06-27 02:32:26 -0700 | [diff] [blame] | 1 | /**
|
| 2 | *
|
| 3 | * @file log_agent_tool.c
|
| 4 | * @brief
|
| 5 | * This file is part of ZCAT.
|
| 6 | * zcatÓ¦Óòãlog_agent´¦ÀíÊý¾ÝÔ´µÄ°ïÖúº¯Êý
|
| 7 | *
|
| 8 | * @details
|
| 9 | * @author Tools Team.
|
| 10 | * @email
|
| 11 | * @copyright Copyright (C) 2013 Sanechips Technology Co., Ltd.
|
| 12 | * @warning
|
| 13 | * @date 2019/02/02
|
| 14 | * @version 1.2
|
| 15 | * @pre
|
| 16 | * @post
|
| 17 | *
|
| 18 | * @par
|
| 19 | * Change History :
|
| 20 | * ---------------------------------------------------------------------------
|
| 21 | * date version author description
|
| 22 | * ---------------------------------------------------------------------------
|
| 23 | * 2017/07/17 1.0 hou.bing Create file
|
| 24 | * 2019/01/24 1.1 jiang.fenglin 1.Ìí¼Óusblog¶ÁÐ´Ëø
|
| 25 | * 2.Ìí¼ÓÏß³ÌÃû³Æ
|
| 26 | * 2019/02/02 1.2 jiang.fenglin ÐÞ¸Ä×¢ÊÍ·½Ê½Îªdoxygen
|
| 27 | * 2019/07/08 1.3 jiang.fenglin Ôö¼ÓAPFS/CPFSģʽ
|
| 28 | * ---------------------------------------------------------------------------
|
| 29 | *
|
| 30 | *
|
| 31 | */
|
| 32 |
|
| 33 |
|
| 34 | /**
|
| 35 | * Í·Îļþ°üº¬
|
| 36 | */
|
| 37 | #include <string.h>
|
| 38 | #include <signal.h>
|
| 39 | #include <time.h>
|
| 40 | #include <pthread.h>
|
| 41 | #include <sys/time.h>
|
| 42 | #include <sys/ioctl.h>
|
| 43 | #include "log_agent.h"
|
| 44 |
|
| 45 | #define MAX_PACKET_LEN (0x10000)
|
| 46 | #define MAX_ENCODE_PACKET_LEN (MAX_PACKET_LEN * 2)
|
| 47 | #define COMM_MDLNO_ZCAT_FLAG 115
|
| 48 | #define COMM_MDLNO_RAMDUMP_FLAG 119
|
| 49 | #define MAX_AP_LOG_BUFF_LEN 2048
|
| 50 |
|
| 51 | extern E_ZCAT_MODE g_log_dir;
|
| 52 | extern E_ZCAT_STATE g_log_state;
|
| 53 |
|
| 54 | extern int send_message_to_client(unsigned char* buf, int len);
|
| 55 | extern int send_message_to_usblog(unsigned char* buf, int len);
|
| 56 | extern int send_message_to_sdcard(unsigned char* buf, int len);
|
| 57 | extern int init_sdcard_log_dir(E_FLASH_MODE mode);
|
| 58 | extern int init_fs_log_dir();
|
| 59 | extern int zCat_MountSd();
|
| 60 | extern BOOL hdlc_encode(T_HDLC_BUFFER_TYPE *dest, const T_HDLC_BUFFER_TYPE *src);
|
| 61 | extern BOOL hdlc_decode(T_HDLC_BUFFER_TYPE *dest, T_HDLC_BUFFER_TYPE *src);
|
| 62 |
|
| 63 |
|
| 64 | int deal_with_encoded_data(unsigned char* buffer, int buf_len);
|
| 65 |
|
| 66 | int hb_flag = 0;
|
| 67 | int bFirst = 1;
|
| 68 | /*É豸¾ä±ú*/
|
| 69 | extern int ramdump_fd;
|
| 70 | extern int kernellog_fd;
|
| 71 | extern int applog_fd;
|
| 72 | extern int cplog_fd;
|
| 73 |
|
| 74 | /*Ï̻߳¥³âËø*/
|
| 75 | static pthread_mutex_t mutex_AP;
|
| 76 | static pthread_mutex_t mutex_SD;
|
| 77 |
|
| 78 | static T_HDLC_BUFFER_TYPE g_recvBuf = {0};
|
| 79 |
|
| 80 | static unsigned int gCommEncodeBuffer[MAX_ENCODE_PACKET_LEN / 4] = {0};
|
| 81 | static unsigned int gCommDecodeBuffer[MAX_ENCODE_PACKET_LEN / 4] = {0};
|
| 82 | static unsigned int gCommRecvBuffer[MAX_ENCODE_PACKET_LEN / 4] = {0};
|
| 83 |
|
| 84 | BOOL bSDSet = FALSE;
|
| 85 |
|
| 86 | void init_log_agent_tools()
|
| 87 | {
|
| 88 | g_recvBuf.buf = (unsigned char *)gCommRecvBuffer;
|
| 89 | g_recvBuf.bufIndex = 0;
|
| 90 | g_recvBuf.bufSize = 0;
|
| 91 | pthread_mutex_init(&mutex_AP, NULL);
|
| 92 | pthread_mutex_init(&mutex_SD, NULL);
|
| 93 | }
|
| 94 |
|
| 95 | int g_cp_log_count = 0;
|
| 96 | int g_ap_log_count = 0;
|
| 97 |
|
| 98 | /**
|
| 99 | * @brief ´òӡʱ¼äµÄ°ïÖúº¯Êý
|
| 100 | * @param[in] void
|
| 101 | * @return void
|
| 102 | * @note
|
| 103 | * @see
|
| 104 | */
|
| 105 | char* zte_time()
|
| 106 | {
|
| 107 | time_t timep;
|
| 108 | struct tm *p;
|
| 109 | static char buf[22];
|
| 110 | memset(buf, 0, 22);
|
| 111 | time(&timep);
|
| 112 | p =localtime(&timep);
|
| 113 | if(p != NULL)
|
| 114 | snprintf(buf,21,"%4d/%02d/%02d %02d:%02d:%02d ",1900 + p->tm_year,1 + p->tm_mon,p->tm_mday,p->tm_hour,p->tm_min,p->tm_sec);
|
| 115 | return buf;
|
| 116 | }
|
| 117 |
|
| 118 | /**
|
| 119 | * @brief ½«¹æÔòÎļþ¡¢ÐÄÌø°üµÄÏÂÐÐÊý¾Ý·¢Ë͵½cp
|
| 120 | * @param[in] buf ´ý·¢Ë͵ÄÊý¾ÝÖ¸Õë
|
| 121 | * @param[in] len ´ý·¢Ë͵ÄÊý¾Ý³¤¶È
|
| 122 | * @return ʵ¼Ê·¢Ë͵ÄÊý¾Ý³¤¶È
|
| 123 | * @note
|
| 124 | * @see
|
| 125 | */
|
| 126 | int send_log_to_cp(unsigned char *buf, int len)
|
| 127 | {
|
| 128 | int write_len = 0;
|
| 129 | if(buf == NULL || cplog_fd == -1)
|
| 130 | {
|
| 131 | printf("[zcat] send_log_to_cp fail\n");
|
| 132 | return 0;
|
| 133 | }
|
| 134 | write_len = write(cplog_fd, buf, len);
|
| 135 |
|
| 136 | return write_len;
|
| 137 | }
|
| 138 |
|
| 139 | /**
|
| 140 | * @brief ¸ù¾Ýzcat_mode£¬·¢ËÍlogµ½²»Í¬µÄÍâÉ裺usb¡¢Íø¿¨¡¢sd¿¨
|
| 141 | * @param[in] buf ´ý·¢Ë͵ÄÊý¾ÝÖ¸Õë
|
| 142 | * @param[in] len ´ý·¢Ë͵ÄÊý¾Ý³¤¶È
|
| 143 | * @return void
|
| 144 | * @note
|
| 145 | * @see
|
| 146 | */
|
| 147 | void send_log_out(unsigned char* buf, int len)
|
| 148 | {
|
| 149 | if(g_log_state != ZCAT_STATE_RUNNING)
|
| 150 | {
|
| 151 | printf("[zcat] send_log_out fail, state = %d.\n", g_log_state);
|
| 152 | return;
|
| 153 | }
|
| 154 |
|
| 155 | if(g_log_dir == ZCAT_MODE_AP_NET)
|
| 156 | {
|
| 157 | send_message_to_client(buf, len);
|
| 158 | }
|
| 159 | else if(g_log_dir == ZCAT_MODE_AP_USB)
|
| 160 | {
|
| 161 | int i;
|
| 162 | int cnt = len / MAX_AP_LOG_BUFF_LEN;
|
| 163 |
|
| 164 | for(i = 0; i < cnt; i++)
|
| 165 | {
|
| 166 | g_cp_log_count++;
|
| 167 | send_message_to_usblog(buf + i * MAX_AP_LOG_BUFF_LEN, MAX_AP_LOG_BUFF_LEN);
|
| 168 | }
|
| 169 |
|
| 170 | cnt = len % MAX_AP_LOG_BUFF_LEN;
|
| 171 | if(cnt > 0)
|
| 172 | {
|
| 173 | g_cp_log_count++;
|
| 174 | send_message_to_usblog(buf + i * MAX_AP_LOG_BUFF_LEN, cnt);
|
| 175 | }
|
| 176 | }
|
| 177 | else if(g_log_dir == ZCAT_MODE_AP_TF)
|
| 178 | {
|
| 179 | if(bSDSet == FALSE )
|
| 180 | {
|
| 181 | if(zCat_MountSd())
|
| 182 | return;
|
| 183 |
|
| 184 | bSDSet = TRUE;
|
| 185 | if(init_sdcard_log_dir(FLASH_MODE_NOMAL) < 0) //³õʼ»¯cpÊä³öÎļþ¼Ð¼°²ÎÊý
|
| 186 | {
|
| 187 | bSDSet = FALSE;
|
| 188 | return;
|
| 189 | }
|
| 190 | hb_flag = 1;
|
| 191 | return;
|
| 192 | }
|
| 193 | if(bSDSet == TRUE)
|
| 194 | {
|
| 195 | pthread_mutex_lock(&mutex_SD);
|
| 196 | send_message_to_sdcard(buf, len);
|
| 197 | pthread_mutex_unlock(&mutex_SD);
|
| 198 | }
|
| 199 | }
|
| 200 | else if(g_log_dir == ZCAT_MODE_AP_FS)
|
| 201 | {
|
| 202 | if(bSDSet == FALSE )
|
| 203 | {
|
| 204 | bSDSet = TRUE;
|
| 205 | if(init_fs_log_dir() < 0) //³õʼ»¯cpÊä³öÎļþ¼Ð¼°²ÎÊý
|
| 206 | {
|
| 207 | bSDSet = FALSE;
|
| 208 | return;
|
| 209 | }
|
| 210 | hb_flag = 1;
|
| 211 | return;
|
| 212 | }
|
| 213 | if(bSDSet == TRUE)
|
| 214 | {
|
| 215 | pthread_mutex_lock(&mutex_SD);
|
| 216 | send_message_to_sdcard(buf, len);
|
| 217 | pthread_mutex_unlock(&mutex_SD);
|
| 218 | }
|
| 219 | }
|
| 220 | else
|
| 221 | {
|
| 222 | deal_with_encoded_data(buf, len);
|
| 223 | }
|
| 224 | }
|
| 225 |
|
| 226 | /**
|
| 227 | * @brief ½«ap²àprintf¡¢printk²úÉúµÄlogÊý¾Ý·¢ËͳöÈ¥
|
| 228 | * @param[in] commHeader ´ý·¢Ë͵ÄÊý¾Ý
|
| 229 | * @return void
|
| 230 | * @note
|
| 231 | * @see
|
| 232 | */
|
| 233 | static void send_ap_log_out(T_COMM_TYPE *commHeader)
|
| 234 | {
|
| 235 | T_HDLC_BUFFER_TYPE srcBuf = {0};
|
| 236 | //T_ZCAT_HEADER *zcatHeader = (T_ZCAT_HEADER *)(((unsigned char*)commHeader) + sizeof(T_COMM_TYPE));
|
| 237 | T_HDLC_BUFFER_TYPE destBuf = {(unsigned char *)gCommEncodeBuffer, 0, MAX_ENCODE_PACKET_LEN};
|
| 238 | //int cmd_code = zcatHeader->cmd_code;
|
| 239 |
|
| 240 | //UINT16 times = 0;
|
| 241 | //UINT16 ipLast = 0;
|
| 242 |
|
| 243 | srcBuf.buf = (unsigned char *)(commHeader);
|
| 244 | srcBuf.bufIndex = 0;
|
| 245 | srcBuf.bufSize = sizeof(T_COMM_TYPE) + commHeader->buf_len;
|
| 246 | destBuf.bufIndex = 0;
|
| 247 | if(g_log_state != ZCAT_STATE_RUNNING)
|
| 248 | {
|
| 249 | free((void*)commHeader);
|
| 250 | return;
|
| 251 | }
|
| 252 | pthread_mutex_lock(&mutex_AP); // ¼Ó»¥³âËø£¬·Àֹͬʱ²Ù×÷gCommEncodeBuffer
|
| 253 | if (hdlc_encode(&destBuf, &srcBuf)) // ±àÂë
|
| 254 | {
|
| 255 | if(g_log_dir == ZCAT_MODE_CP_USB || g_log_dir == ZCAT_MODE_CP_TF || g_log_dir == ZCAT_MODE_CP_FS)
|
| 256 | {
|
| 257 | send_log_to_cp(destBuf.buf, destBuf.bufIndex);
|
| 258 | }
|
| 259 | else
|
| 260 | {
|
| 261 | send_log_out(destBuf.buf, destBuf.bufIndex);
|
| 262 | }
|
| 263 | }
|
| 264 | pthread_mutex_unlock(&mutex_AP); // ½â³ý»¥³âËø
|
| 265 | free((void*)commHeader);
|
| 266 | }
|
| 267 |
|
| 268 | /**
|
| 269 | * @brief ·¢ËÍÊý¾Ýµ½"ͳһ»º´æ"ÖÐ
|
| 270 | * @param[in] buf ·¢ËÍÊý¾Ý(±ØÐëÊÇÓÉComm_MallocÉêÇëµÄÄÚ´æ!!!)
|
| 271 | * @param[in] buf_len ·¢ËÍÊý¾ÝµÄ³¤¶È
|
| 272 | * @param[in] tgt_mdl_no Ä¿±êÄ£¿éºÅ£¬ÊÖ»ú»òPCµÈ
|
| 273 | * @param[in] tgt_submdl_no Ä¿±ê×ÓÄ£¿éºÅ
|
| 274 | * @param[in] src_submdl_no Ô´×ÓÄ£¿éºÅ
|
| 275 | * @return ³É¹¦·µ»ØZOSS_SUCCESS, ·ñÔò·µ»ØZOSS_ERROR
|
| 276 | * @note
|
| 277 | * @see
|
| 278 | */
|
| 279 | unsigned int zTools_SendData(unsigned char *buf, unsigned int buf_len,
|
| 280 | unsigned char tgt_mdl_no, unsigned char tgt_submdl_no, unsigned char src_submdl_no)
|
| 281 | {
|
| 282 | T_COMM_TYPE *commHeader = NULL;
|
| 283 |
|
| 284 | /* Èë²ÎÅÐ¶Ï */
|
| 285 | if (buf == NULL || buf_len == 0 || tgt_mdl_no == 0 || tgt_submdl_no == 0 || src_submdl_no == 0)
|
| 286 | {
|
| 287 | return -1;
|
| 288 | }
|
| 289 |
|
| 290 | commHeader = (T_COMM_TYPE *)(buf - sizeof(T_COMM_TYPE));
|
| 291 |
|
| 292 | commHeader->msg_type = 1;
|
| 293 | commHeader->pad = 0xAA;
|
| 294 | commHeader->reserved = 0xAAAA;
|
| 295 | commHeader->tgt_mdl_no = tgt_mdl_no; // Ä¿±êÄ£¿é
|
| 296 | commHeader->tgt_submdl_no = tgt_submdl_no; // Ä¿±ê×ÓÄ£¿é
|
| 297 | commHeader->src_mdl_no = MDL_PHONE; // Ô´Ä£¿é
|
| 298 | commHeader->src_submdl_no = src_submdl_no; // Ô´×ÓÄ£¿é
|
| 299 | commHeader->buf_len = buf_len; // Êý¾ÝÇø³¤¶È
|
| 300 |
|
| 301 | send_ap_log_out(commHeader);
|
| 302 | return 0;
|
| 303 | }
|
| 304 |
|
| 305 | /**
|
| 306 | * @brief ZCATÏûϢͷ³õʼ»¯
|
| 307 | * @param[out] zcatHeader ÏûϢͷָÕë
|
| 308 | * @param[in] cmd_code ÏûÏ¢Âë
|
| 309 | * @param[in] len ÏûÏ¢³¤¶È
|
| 310 | * @return N/A
|
| 311 | * @note
|
| 312 | * @see
|
| 313 | */
|
| 314 | VOID zCatAgt_HeaderInit(T_ZCAT_HEADER *zcatHeader, unsigned char cmd_code, unsigned int len)
|
| 315 | {
|
| 316 | struct timeval tmpTimeVal = {0};
|
| 317 |
|
| 318 | zcatHeader->cmd_code = cmd_code;
|
| 319 | zcatHeader->reserved = 0xBBBB;
|
| 320 | zcatHeader->timeStamp[1] = 0;
|
| 321 | zcatHeader->length = len;
|
| 322 | zcatHeader->timeStamp[0] = 0;//corem»ñȡʱ¼ä
|
| 323 | gettimeofday(&tmpTimeVal, NULL);
|
| 324 | zcatHeader->timeStamp[1] = tmpTimeVal.tv_sec;
|
| 325 | }
|
| 326 |
|
| 327 | /**
|
| 328 | * @brief ·¢ËÍZCATÏûÏ¢µ½"ÍâÉè"
|
| 329 | * @param[in] cmd_code ÏûÏ¢Âë
|
| 330 | * @param[in] buf ÏûÏ¢Êý¾ÝÖ¸Õë
|
| 331 | * @param[in] len ÏûÏ¢Êý¾Ý³¤¶È
|
| 332 | * @return ³É¹¦·µ»ØZOSS_SUCCESS, ·ñÔò·µ»ØZOSS_ERROR
|
| 333 | * @note
|
| 334 | * @see
|
| 335 | */
|
| 336 | unsigned int zCatAgt_SendMsg(unsigned char cmd_code, unsigned char *buf, unsigned int len)
|
| 337 | {
|
| 338 | T_ZCAT_HEADER *zcatHeader = (T_ZCAT_HEADER *)(buf - sizeof(T_ZCAT_HEADER));
|
| 339 |
|
| 340 | zCatAgt_HeaderInit(zcatHeader, cmd_code, len);
|
| 341 |
|
| 342 | return zTools_SendData((unsigned char *)zcatHeader, sizeof(T_ZCAT_HEADER) + len, MDL_ZCAT, 1, SUBMDL_ZCATAGT);
|
| 343 | }
|
| 344 |
|
| 345 | /**
|
| 346 | * @brief »ñȡģ¿éºÍµÈ¼¶
|
| 347 | * @param[in] buf ÏûÏ¢Êý¾ÝÖ¸Õë
|
| 348 | * @param[in] bufLen ÏûÏ¢Êý¾Ý³¤¶È
|
| 349 | * @param[in] priority ÏûÏ¢µÈ¼¶
|
| 350 | * @param[in] mod Ä£¿é±àºÅ
|
| 351 | * @return void
|
| 352 | * @note
|
| 353 | * @see
|
| 354 | */
|
| 355 | VOID zCatAgt_Ap_GetModAndPri(unsigned char **buf, unsigned short *bufLen, unsigned char *pPriority, unsigned char *pMod)
|
| 356 | {
|
| 357 | unsigned char *p = *buf;
|
| 358 | unsigned short len = *bufLen;
|
| 359 |
|
| 360 | if (len > 3 && p[0] == '<' && p[1] >= '0' && p[1] <= '7' && p[2] == '>')
|
| 361 | {
|
| 362 | *pPriority = p[1] - '0';
|
| 363 | p += 3;
|
| 364 | len -= 3;
|
| 365 |
|
| 366 | if (len > 3 && p[0] == '<' && p[1] > '0' && p[1] <= '9')
|
| 367 | {
|
| 368 | if (p[2] == '>')
|
| 369 | {
|
| 370 | *pMod = p[1] - '0';
|
| 371 | p += 3;
|
| 372 | len -= 3;
|
| 373 | }
|
| 374 | else if (len > 4 && p[2] >= '0' && p[2] <= '9')
|
| 375 | {
|
| 376 | if (p[3] == '>')
|
| 377 | {
|
| 378 | *pMod = (p[1] - '0') * 10 + (p[2] - '0');
|
| 379 | p += 4;
|
| 380 | len -= 4;
|
| 381 | }
|
| 382 | else if (len > 5 && p[3] >= '0' && p[3] <= '9' && p[4] == '>')
|
| 383 | {
|
| 384 | *pMod = (p[1] - '0') * 100 + (p[2] - '0') * 10 + (p[3] - '0');
|
| 385 | p += 5;
|
| 386 | len -= 5;
|
| 387 | }
|
| 388 | }
|
| 389 | }
|
| 390 | }
|
| 391 |
|
| 392 | *buf = p;
|
| 393 | *bufLen = len;
|
| 394 | }
|
| 395 |
|
| 396 | /**
|
| 397 | * @brief ·¢ËÍAP LOGµ½"ͳһ»º´æ"ÖÐ
|
| 398 | * @param[in] cmd_code ÏûÏ¢Âë
|
| 399 | * @param[in] priority ÏûÏ¢µÈ¼¶
|
| 400 | * @param[in] mod Ä£¿é±àºÅ
|
| 401 | * @param[in] buf ÏûÏ¢Êý¾ÝÖ¸Õë
|
| 402 | * @param[in] len ÏûÏ¢Êý¾Ý³¤¶È
|
| 403 | * @return ³É¹¦·µ»ØZOSS_SUCCESS, ·ñÔò·µ»ØZOSS_ERROR
|
| 404 | * @note
|
| 405 | * @see
|
| 406 | */
|
| 407 | unsigned int zCatAgt_Ap_SendMsg(unsigned char cmd_code, unsigned char priority, unsigned char mod, unsigned char *buf, unsigned int len)
|
| 408 | {
|
| 409 | T_ZCAT_APLOG_HEADER *apHeader = NULL;
|
| 410 | unsigned char *newBuffer = malloc(sizeof(T_ZCAT_APLOG_HEADER) + sizeof(T_ZCAT_HEADER) + sizeof(T_COMM_TYPE) + len);
|
| 411 |
|
| 412 | if(newBuffer == NULL)
|
| 413 | {
|
| 414 | printf("[zcat] malloc buffer failed!\n");
|
| 415 | return -1;
|
| 416 | }
|
| 417 | apHeader = (T_ZCAT_APLOG_HEADER *)(newBuffer + sizeof(T_ZCAT_HEADER) + sizeof(T_COMM_TYPE));
|
| 418 | #if 0
|
| 419 | if (apHeader == NULL)
|
| 420 | {
|
| 421 | printf("[zcat] apHeader is null.\n");
|
| 422 | return -1;
|
| 423 | }
|
| 424 | else
|
| 425 | #endif
|
| 426 | {
|
| 427 | apHeader->priority = priority;
|
| 428 | apHeader->mod = mod;
|
| 429 | apHeader->len = len;
|
| 430 | memcpy(apHeader + 1, buf, len);
|
| 431 | return zCatAgt_SendMsg(cmd_code, (unsigned char *)apHeader, sizeof(T_ZCAT_APLOG_HEADER) + len);
|
| 432 | }
|
| 433 |
|
| 434 | }
|
| 435 |
|
| 436 | /**
|
| 437 | * @brief ·ÖÎöAP LOG£¬°´»»ÐÐÖØÐ·ָî
|
| 438 | * @param[in] src Ô´
|
| 439 | * @param[in] dst Ä¿µÄ
|
| 440 | * @return Èç¹û³É¹¦·µ»ØTRUE, ·ñÔò·µ»ØFALSE
|
| 441 | * @note
|
| 442 | * @see
|
| 443 | */
|
| 444 | BOOL zCatAgt_Ap_ReadBuffer(T_AP_SRC_BUFFER_TYPE *src, T_AP_DEST_BUFFER_TYPE *dest)
|
| 445 | {
|
| 446 | if (src != NULL && src->buf != NULL && src->bufSize > src->beginIndex && dest != NULL )
|
| 447 | {
|
| 448 | unsigned char *src_buf = src->buf + src->beginIndex;
|
| 449 | unsigned int src_length = src->bufSize - src->beginIndex;
|
| 450 | unsigned int buf_length = src_length > AP_LOG_MAX_LENGTH ? AP_LOG_MAX_LENGTH : src_length;
|
| 451 | unsigned int i = 0;
|
| 452 |
|
| 453 | for (; i < buf_length; i++)
|
| 454 | {
|
| 455 | if (src_buf[i] == '\n')
|
| 456 | {
|
| 457 | i++;
|
| 458 | dest->newLine = 1;
|
| 459 | break;
|
| 460 | }
|
| 461 | }
|
| 462 |
|
| 463 | dest->buf = src->buf + src->beginIndex;
|
| 464 | dest->len = i;
|
| 465 | src->beginIndex += i;
|
| 466 |
|
| 467 | return TRUE;
|
| 468 | }
|
| 469 |
|
| 470 | return FALSE;
|
| 471 | }
|
| 472 |
|
| 473 | void timer(int sig)
|
| 474 | {
|
| 475 | hb_flag = 0;
|
| 476 |
|
| 477 | return;
|
| 478 | }
|
| 479 |
|
| 480 | /**
|
| 481 | * @brief ´¦Àíδ±àÂëµÄÊý¾Ý£¬¸ù¾ÝÀàÐÍ·Ö±ð½øÐÐÏàÓ¦´¦Àí
|
| 482 | * @param[in] buffer »º´æÖ¸Õë
|
| 483 | * @param[in] buf_len »º´æ³¤¶È
|
| 484 | * @return ³É¹¦·µ»Ø0£»Ê§°Ü·µ»Ø-1
|
| 485 | * @note
|
| 486 | * @see
|
| 487 | */
|
| 488 | void deal_with_rawdata(unsigned char* buf, unsigned short buf_len)
|
| 489 | {
|
| 490 | T_COMM_TYPE commHeader = {0};
|
| 491 |
|
| 492 | if(buf_len > sizeof(T_COMM_TYPE))
|
| 493 | {
|
| 494 | memcpy(&commHeader, buf, sizeof(T_COMM_TYPE));
|
| 495 | if(commHeader.src_mdl_no == COMM_MDLNO_ZCAT_FLAG) //aplogÏûÏ¢£¬È¥³ýcomÍ·zcatÍ·diagÍ·
|
| 496 | {
|
| 497 | T_ZCAT_HEADER *zcatHeader = (T_ZCAT_HEADER*)(buf+sizeof(T_COMM_TYPE));
|
| 498 | if(zcatHeader->cmd_code >= ZCAT_CMDCODE_MAX)
|
| 499 | {
|
| 500 | printf("[zcat] zcatHeader->cmd_code:%d > ZCAT_CMDCODE_MAX\n", zcatHeader->cmd_code);
|
| 501 | return;
|
| 502 | }
|
| 503 | else if(zcatHeader->cmd_code == ZCAT_DIAG_REPORT)
|
| 504 | {
|
| 505 | hb_flag = 1;
|
| 506 | if(bFirst)
|
| 507 | {
|
| 508 | signal(SIGALRM, timer);
|
| 509 | bFirst = 0;
|
| 510 | }
|
| 511 | alarm(5);
|
| 512 |
|
| 513 | T_ZCAT_DIAG_HEADER *zdiagHeader = (T_ZCAT_DIAG_HEADER*)(buf + sizeof(T_COMM_TYPE)+sizeof(T_ZCAT_HEADER));
|
| 514 | if (zdiagHeader->diag_id == DIAG_FILTER_CONFIG)
|
| 515 | {
|
| 516 | T_ZCAT_DIAG_CONFIG_REQ *diag_config = (T_ZCAT_DIAG_CONFIG_REQ *)(zdiagHeader + 1);
|
| 517 | int headerLen = sizeof(T_COMM_TYPE)+sizeof(T_ZCAT_HEADER)+sizeof(T_ZCAT_DIAG_HEADER);
|
| 518 | if(diag_config->type == ZCAT_AP_APP_TYPE)
|
| 519 | {
|
| 520 | ioctl(applog_fd, 5, buf + headerLen);
|
| 521 | }
|
| 522 | else if(diag_config->type == ZCAT_AP_KERNEL_TYPE)
|
| 523 | {
|
| 524 | ioctl(kernellog_fd, 5, buf + headerLen);
|
| 525 | }
|
| 526 | }
|
| 527 | }
|
| 528 | }
|
| 529 | }
|
| 530 | }
|
| 531 |
|
| 532 | /**
|
| 533 | * @brief ´¦Àí±àÂëºóµÄÊý¾Ý£¬¸ù¾ÝÀàÐÍ·Ö±ð½øÐÐÏàÓ¦´¦Àí
|
| 534 | * @param[in] buffer »º´æÖ¸Õë
|
| 535 | * @param[in] buf_len »º´æ³¤¶È
|
| 536 | * @return ³É¹¦·µ»Ø0£»Ê§°Ü·µ»Ø-1
|
| 537 | * @note
|
| 538 | * @see
|
| 539 | */
|
| 540 | int deal_with_encoded_data(unsigned char* buffer, int buf_len)
|
| 541 | {
|
| 542 | static T_HDLC_BUFFER_TYPE dest = {(unsigned char *)gCommDecodeBuffer, 0, MAX_ENCODE_PACKET_LEN};
|
| 543 | T_HDLC_BUFFER_TYPE *src = &g_recvBuf;
|
| 544 | unsigned int remainLen = 0;
|
| 545 | BOOL ret_decode = FALSE;
|
| 546 |
|
| 547 | if(buffer == NULL)
|
| 548 | {
|
| 549 | printf("[zcat] deal_with_encoded_data input error!\n");
|
| 550 | return -1;
|
| 551 | }
|
| 552 |
|
| 553 | src->bufIndex=0;
|
| 554 |
|
| 555 | // ½«ÐÂÏûÏ¢Êý¾Ý¿½È뻺³åÇø
|
| 556 | if (src->bufSize + buf_len <= MAX_ENCODE_PACKET_LEN)
|
| 557 | {
|
| 558 | memcpy(src->buf + src->bufSize, buffer, buf_len);
|
| 559 | src->bufSize += buf_len;
|
| 560 | }
|
| 561 | else if (buf_len <= MAX_ENCODE_PACKET_LEN)
|
| 562 | {
|
| 563 | memcpy(src->buf, buffer, buf_len);
|
| 564 | src->bufSize = buf_len;
|
| 565 | }
|
| 566 | else
|
| 567 | {
|
| 568 | src->bufSize = 0;
|
| 569 | }
|
| 570 |
|
| 571 | remainLen = src->bufSize - src->bufIndex;
|
| 572 |
|
| 573 | while (remainLen > 0)
|
| 574 | {
|
| 575 | ret_decode = hdlc_decode(&dest, src);
|
| 576 | if(!ret_decode)
|
| 577 | {
|
| 578 | if (dest.bufIndex != 0 || src->bufSize - src->bufIndex == remainLen)
|
| 579 | {
|
| 580 | break;
|
| 581 | }
|
| 582 | }
|
| 583 | else
|
| 584 | {
|
| 585 | deal_with_rawdata(dest.buf, dest.bufIndex);
|
| 586 | dest.bufIndex = 0;
|
| 587 | }
|
| 588 | remainLen = src->bufSize - src->bufIndex;
|
| 589 | }//end while
|
| 590 | if (dest.bufSize <= dest.bufIndex)
|
| 591 | {
|
| 592 | dest.bufIndex = 0;
|
| 593 | }
|
| 594 | if (src->bufSize > src->bufIndex)
|
| 595 | {
|
| 596 | src->bufSize -= src->bufIndex;
|
| 597 | memmove(src->buf, src->buf + src->bufIndex, src->bufSize);
|
| 598 | }
|
| 599 | else
|
| 600 | {
|
| 601 | src->bufSize = 0;
|
| 602 | }
|
| 603 | src->bufIndex = 0;
|
| 604 | return 0;
|
| 605 | }
|