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: LOG OAM STATUS MODULE
15 * Author:
16 * Create:
17 */
18
19 #include "securec.h"
20 #include "error_types.h"
21 #include "log_common.h"
22 #include "log_printf.h"
23 #include "log_oam_status.h"
24
25 #define BUFFER_ARRAY_LEN 4
26 #define PRESS_PARAMS_BUFFER0_INDEX 0
27 #define PRESS_PARAMS_BUFFER1_INDEX 1
28 #define PRESS_PARAMS_BUFFER2_INDEX 2
29 #define PRESS_PARAMS_BUFFER3_INDEX 3
30
31
pf_feature_set(uint32_t feature,uint8_t set)32 int32_t pf_feature_set(uint32_t feature, uint8_t set)
33 {
34 UNUSED(feature);
35 UNUSED(set);
36
37 return SUCC;
38 }
39
pf_feature_get(uint32_t feature)40 int32_t pf_feature_get(uint32_t feature)
41 {
42 UNUSED(feature);
43
44 return FEATURE_OFF;
45 }
46
log_oml_status_packet(om_status_data_stru_t * status_entry,uint8_t prime_id,uint16_t msg_id,uint16_t length,const uint8_t * buffer)47 void log_oml_status_packet(om_status_data_stru_t *status_entry, uint8_t prime_id,
48 uint16_t msg_id, uint16_t length, const uint8_t *buffer)
49 {
50 if (status_entry == NULL) {
51 return;
52 }
53 /* Strutc */
54 status_entry->header.frame_start = OM_FRAME_DELIMITER;
55 status_entry->header.func_type = OM_MSG_TYPE_STATUS;
56 status_entry->header.prime_id = prime_id;
57 status_entry->header.arr_reserver[0] = 0;
58 status_entry->header.frame_len = length + OML_STATUS_ADD_LENGTH;
59 status_entry->header.sn = get_log_sn_number();
60 status_entry->msg_id = msg_id;
61 status_entry->data_len = length;
62
63 errno_t sec_ret;
64 sec_ret = memcpy_s(status_entry->data, OM_STATUS_DATA_MAX_SIZE, buffer, length);
65 if (sec_ret != EOK) {
66 return;
67 }
68
69 *(status_entry->data + length) = OM_FRAME_DELIMITER;
70 }
71
log_oml_status_write(uint8_t prime_id,uint16_t msg_id,uint16_t mode,uint16_t length,const uint8_t * buffer)72 uint32_t log_oml_status_write(uint8_t prime_id, uint16_t msg_id, uint16_t mode, uint16_t length, const uint8_t *buffer)
73 {
74 if (log_get_local_log_level() == LOG_LEVEL_NONE) {
75 return SUCC;
76 }
77
78 om_status_data_stru_t om_status_entry;
79
80 /* Check parameters */
81 if (length >= OM_STATUS_DATA_MAX_SIZE || buffer == NULL) {
82 return RET_TYPE_ERROR_IN_PARAMETERS;
83 }
84
85 log_oml_status_packet(&om_status_entry, (uint8_t)(mode | prime_id), msg_id, length, buffer);
86
87 log_event((uint8_t *)&om_status_entry, length + OML_STATUS_ADD_LENGTH);
88
89 return SUCC;
90 }
91
log_oam_status_store_deal(uint8_t prime_id,uint16_t msg_id,uint16_t mode,uint16_t length,const uint32_t * param)92 void log_oam_status_store_deal(uint8_t prime_id, uint16_t msg_id, uint16_t mode, uint16_t length, const uint32_t *param)
93 {
94 uint32_t buffer[BUFFER_ARRAY_LEN] = {0};
95 uint8_t len;
96 uint32_t *param_data = (uint32_t *)param;
97 if (length > BUFFER_ARRAY_LEN) {
98 return;
99 }
100
101 for (len = 0; len < length; len++) {
102 if (param_data != NULL) {
103 buffer[len] = *param_data;
104 param_data++;
105 }
106 }
107
108 #if (USE_COMPRESS_LOG_INSTEAD_OF_SDT_LOG == NO)
109 if (log_oml_status_write(prime_id, msg_id, mode, (uint16_t)(length * sizeof(uint32_t)), (uint8_t *)buffer) !=
110 SUCC) {
111 return;
112 }
113 #else
114 UNUSED(prime_id);
115 UNUSED(mode);
116 compress_printf(msg_id, press_params(BTC_MAGIC_LOG_CODE, LOG_LEVEL_INFO, length),
117 buffer[PRESS_PARAMS_BUFFER0_INDEX],
118 buffer[PRESS_PARAMS_BUFFER1_INDEX],
119 buffer[PRESS_PARAMS_BUFFER2_INDEX],
120 buffer[PRESS_PARAMS_BUFFER3_INDEX]);
121 #endif
122 }
123
log_oam_status_store_init(void)124 void log_oam_status_store_init(void)
125 {
126 log_oam_status_store_register_callback(log_oam_status_store_deal);
127 }
128