• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  * Description: zdiag msg
15  * This file should be changed only infrequently and with great care.
16  */
17 
18 #include "diag_msg.h"
19 #include "zdiag_pkt_router.h"
20 #include "dfx_adapt_layer.h"
21 #include "errcode.h"
22 #include "log_file.h"
23 #include "debug_print.h"
24 
25 static bool g_offline_log_enable = false;
26 
uapi_zdiag_set_offline_log_enable(bool enable)27 void uapi_zdiag_set_offline_log_enable(bool enable)
28 {
29 #if CONFIG_DFX_SUPPORT_OFFLINE_LOG_FILE == DFX_YES
30     if (g_offline_log_enable == enable) {
31         return;
32     }
33 
34     if (enable) {
35         store_file_cfg_t cfg = {0};
36         errcode_t ret;
37 
38         cfg.mult_files = DFX_OFFLINE_LOG_MUTI_FILE_NUM;
39         cfg.cache_size = DFX_OFFLINE_LOG_CACHE_SIZE;
40         cfg.enable_cache = DFX_OFFLINE_LOG_CACHE_ENABLE;
41         cfg.file_size = DFX_OFFLINE_LOG_FILE_SIZE;
42         cfg.path = DFX_OFFLINE_LOG_PATH;
43         cfg.name = DFX_OFFLINE_LOG_NAME;
44 
45         ret = uapi_logfile_open(STORE_DIAG, (const store_file_cfg_t *)&cfg);
46         if (ret != ERRCODE_SUCC && ret != ERRCODE_DFX_LOGFILE_ALREADY_OPEN) {
47             dfx_log_err("open logfile %s failed. ret = 0x%x\r\n", cfg.name, ret);
48             return;
49         }
50     } else {
51         (void)uapi_logfile_close(STORE_DIAG);
52     }
53     g_offline_log_enable = enable;
54 #else
55     unused(enable);
56     g_offline_log_enable = false;
57 #endif
58 }
59 
uapi_zdiag_offline_log_is_enable(void)60 bool uapi_zdiag_offline_log_is_enable(void)
61 {
62 #if CONFIG_DFX_SUPPORT_OFFLINE_LOG_FILE == DFX_YES
63     return g_offline_log_enable;
64 #else
65     return false;
66 #endif
67 }
68 
diag_msg_proc(uint16_t msg_id,uint8_t * msg,uint32_t msg_len)69 errcode_t diag_msg_proc(uint16_t msg_id, uint8_t *msg, uint32_t msg_len)
70 {
71     switch (msg_id) {
72         case DFX_MSG_ID_DIAG_PKT:
73             diag_pkt_msg_proc(msg_id, msg, (uint32_t)msg_len);
74             return ERRCODE_SUCC;
75         default:
76             return ERRCODE_NOT_SUPPORT;
77     }
78 }