• 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 cmd producer
15  * This file should be changed only infrequently and with great care.
16  */
17 
18 
19 #include "zdiag_cmd_src.h"
20 #include "zdiag_mem.h"
21 #include "zdiag_pkt_router.h"
22 #include "zdiag_debug.h"
23 #include "diag_adapt_layer.h"
24 #include "diag_pkt.h"
25 #include "uapi_crc.h"
26 
uapi_diag_run_cmd(uint16_t cmd_id,uint8_t * data,uint16_t data_size,diag_option_t * option)27 errcode_t uapi_diag_run_cmd(uint16_t cmd_id, uint8_t *data, uint16_t data_size, diag_option_t *option)
28 {
29     errcode_t ret;
30     diag_pkt_handle_t pkt;
31     diag_pkt_process_param_t process_param;
32     uint8_t buf[DIAG_MUX_HEADER_SIZE + DIAG_REQ_HEADER_SIZE];
33     msp_mux_packet_head_stru_t *mux = (msp_mux_packet_head_stru_t *)buf;
34     msp_diag_head_req_stru_t *req = (msp_diag_head_req_stru_t *)(buf + DIAG_MUX_HEADER_SIZE);
35     uint16_t crc16 = 0;
36 
37     diag_pkt_handle_set_data(&pkt, DIAG_PKT_DATA_ID_DATA_0, (uint8_t *)mux,
38                              DIAG_MUX_HEADER_SIZE + DIAG_REQ_HEADER_SIZE, DIAG_PKT_DATA_STACK);
39     diag_pkt_handle_set_data(&pkt, DIAG_PKT_DATA_ID_DATA_1, (uint8_t *)data,
40                              data_size, DIAG_PKT_DATA_STACK);
41 
42     diag_mk_req_header(req, cmd_id, data_size);
43     crc16 = uapi_crc16(crc16, (uint8_t*)req, DIAG_REQ_HEADER_SIZE);
44     crc16 = uapi_crc16(crc16, data, data_size);
45     diag_mk_mux_header_1(mux, MUX_PKT_CMD, cmd_id, DIAG_REQ_HEADER_SIZE + data_size);
46     diag_mk_mux_header_2(mux, option->peer_addr, crc16);
47 
48     process_param.cur_proc = DIAG_PKT_PROC_USR_ASYNC_CMD_IND;
49     ret = diag_pkt_router(&pkt, &process_param);
50     return ret;
51 }
52