• 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 pkt
15  * This file should be changed only infrequently and with great care.
16  */
17 #include "diag_pkt.h"
18 #include "diag_adapt_layer.h"
19 #include "diag.h"
20 #include "diag_filter.h"
21 #include "errcode.h"
22 #include "uapi_crc.h"
23 
zdiag_check_mux_pkt(msp_mux_packet_head_stru_t * mux,uint16_t size)24 errcode_t zdiag_check_mux_pkt(msp_mux_packet_head_stru_t *mux, uint16_t size)
25 {
26     uint16_t crc_val;
27     unused(size);
28     if (mux->start_flag != MUX_START_FLAG) {
29         return ERRCODE_FAIL;
30     }
31 
32     crc_val = uapi_crc16(0, mux->puc_packet_data, mux->packet_data_size);
33     if (crc_val != mux->crc16) {
34         return ERRCODE_FAIL;
35     }
36     return ERRCODE_SUCC;
37 }
38 
zdiag_check_hcc_pkt(const uint8_t * data,uint16_t size)39 errcode_t zdiag_check_hcc_pkt(const uint8_t *data, uint16_t size)
40 {
41     unused(data);
42     unused(size);
43 
44     return ERRCODE_SUCC;
45 }
46 
diag_pkt_handle_init(diag_pkt_handle_t * pkt,uint8_t data_cnt)47 void diag_pkt_handle_init(diag_pkt_handle_t *pkt, uint8_t data_cnt)
48 {
49     memset_s(pkt, sizeof(diag_pkt_handle_t), 0, sizeof(diag_pkt_handle_t));
50     pkt->data_cnt = data_cnt;
51 }
52 
diag_pkt_set_critical(diag_pkt_handle_t * pkt)53 void diag_pkt_set_critical(diag_pkt_handle_t *pkt)
54 {
55     pkt->critical = 1;
56 }
57 
diag_pkt_handle_set_data(diag_pkt_handle_t * pkt,uint8_t idx,uint8_t * data,uint16_t data_len,diag_pkt_data_type_t attribute)58 void diag_pkt_handle_set_data(diag_pkt_handle_t *pkt, uint8_t idx, uint8_t *data, uint16_t data_len,
59     diag_pkt_data_type_t attribute)
60 {
61     unused(attribute);
62     pkt->data[idx] = data;
63     pkt->data_len[idx] = data_len;
64 
65     if (((uint32_t)attribute & DIAG_PKT_DATA_ATTRIBUTE_SINGLE_TASK) != 0) {
66         pkt->single_task = true;
67     }
68 
69     if (((uint32_t)attribute & DIAG_PKT_DATA_ATTRIBUTE_DYN_MEM) != 0) {
70         pkt->need_free = true;
71     }
72     return;
73 }
74 
75 
zdiag_mk_log_pkt(diag_cmd_log_layer_ind_stru_t * log_pkt,uint32_t module_id,uint32_t msg_id)76 void zdiag_mk_log_pkt(diag_cmd_log_layer_ind_stru_t *log_pkt, uint32_t module_id, uint32_t msg_id)
77 {
78     STATIC uint32_t msg_sn = 0;
79     log_pkt->module = module_id;
80     log_pkt->dest_mod = diag_adapt_get_local_addr();
81     log_pkt->no = msg_sn++;
82     log_pkt->id = msg_id;
83     log_pkt->time = diag_adapt_get_msg_time();
84 }
85 
zdiag_mk_log_pkt_sn(diag_cmd_log_layer_ind_stru_t * log_pkt,uint32_t module_id,uint32_t msg_id,uint32_t sn)86 void zdiag_mk_log_pkt_sn(diag_cmd_log_layer_ind_stru_t *log_pkt, uint32_t module_id, uint32_t msg_id, uint32_t sn)
87 {
88     log_pkt->module = module_id;
89     log_pkt->dest_mod = diag_adapt_get_local_addr();
90     log_pkt->no = sn;
91     log_pkt->id = msg_id;
92     log_pkt->time = diag_adapt_get_msg_time();
93 }
94 
diag_mk_cnf_header(msp_diag_head_cnf_stru_t * cnf,msp_diag_ack_param_t * ack)95 void diag_mk_cnf_header(msp_diag_head_cnf_stru_t *cnf, msp_diag_ack_param_t *ack)
96 {
97     cnf->sn = ack->sn;     /* cmd sn */
98     cnf->ctrl = ack->ctrl; /* auto ack:0xfe,initiative ack:0 */
99     cnf->pad = ack->pad;
100     cnf->cmd_id = ack->cmd_id;         /* cmd id */
101     cnf->param_size = ack->param_size; /* param size */
102     return;
103 }
104 
diag_mk_req_header(msp_diag_head_req_stru_t * req,uint16_t cmd_id,uint16_t packet_size)105 void diag_mk_req_header(msp_diag_head_req_stru_t *req, uint16_t cmd_id, uint16_t packet_size)
106 {
107     req->cmd_id = cmd_id;
108     req->param_size = packet_size;
109     req->sn = 0;
110     req->crc16 = 0;
111     return;
112 }
113 
diag_mk_ind_header(msp_diag_head_ind_stru_t * ind,uint16_t cmd_id,uint16_t packet_size)114 void diag_mk_ind_header(msp_diag_head_ind_stru_t *ind, uint16_t cmd_id, uint16_t packet_size)
115 {
116     ind->cmd_id = cmd_id;
117     ind->param_size = packet_size;
118     return;
119 }
120 
diag_mk_mux_header_1(msp_mux_packet_head_stru_t * mux,uint8_t type,uint16_t cmd_id,uint16_t pkt_size)121 void diag_mk_mux_header_1(msp_mux_packet_head_stru_t *mux, uint8_t type, uint16_t cmd_id, uint16_t pkt_size)
122 {
123     mux->start_flag = MUX_START_FLAG;
124     mux->type = type;
125     mux->ver = MUX_PKT_VER;
126     mux->crc16 = 0;
127     mux->src = diag_adapt_get_local_addr();
128     mux->cmd_id = cmd_id;
129     mux->packet_data_size = pkt_size;
130     mux->ctrl = 0;
131     mux->pad[0] = 0;
132     return;
133 }
134 
diag_mk_mux_header_2(msp_mux_packet_head_stru_t * mux,diag_addr dst,uint16_t crc16)135 void diag_mk_mux_header_2(msp_mux_packet_head_stru_t *mux, diag_addr dst, uint16_t crc16)
136 {
137     diag_addr dst_tmp = dst;
138     if (dst_tmp == 0) {
139         dst_tmp = zdiag_get_connect_tool_addr();
140     }
141     mux->dst = dst_tmp;
142     mux->crc16 = crc16;
143     return;
144 }