in common/mctp/mctp.c [143:227]
static void mctp_rx_task(void *arg, void *dummy0, void *dummy1)
{
ARG_UNUSED(dummy0);
ARG_UNUSED(dummy1);
if (!arg) {
LOG_WRN("mctp_rx_task without mctp_inst!");
return;
}
mctp *mctp_inst = (mctp *)arg;
if (!mctp_inst->read_data) {
LOG_WRN("mctp_rx_task without medium read function!");
return;
}
LOG_INF("mctp_rx_task start %p", mctp_inst);
while (1) {
uint8_t read_buf[256] = { 0 };
mctp_ext_params ext_params;
uint8_t ret = MCTP_ERROR;
memset(&ext_params, 0, sizeof(ext_params));
uint16_t read_len =
mctp_inst->read_data(mctp_inst, read_buf, sizeof(read_buf), &ext_params);
if (!read_len)
continue;
LOG_HEXDUMP_DBG(read_buf, read_len, "mctp receive data");
mctp_hdr *hdr = (mctp_hdr *)read_buf;
LOG_DBG("dest_ep = %x, src_ep = %x, flags = %x\n", hdr->dest_ep, hdr->src_ep,
hdr->flags_seq_to_tag);
/* Set the tranport layer extra parameters */
ext_params.msg_tag = hdr->msg_tag;
/*
* The high-level application won't modify the tag_owner flag, change the
* tag_owner for response if needs
*/
ext_params.tag_owner = 0;
ext_params.ep = hdr->src_ep;
if ((hdr->dest_ep != mctp_inst->endpoint) && (hdr->dest_ep != MCTP_NULL_EID)) {
/* try to bridge this packet */
ret = bridge_msg(mctp_inst, read_buf, read_len);
if (ret == MCTP_ERROR)
LOG_WRN("Bridge to endpoint 0x%x failed ", hdr->dest_ep);
continue;
}
/* handle this packet by self */
/* assembling the mctp message */
if (mctp_pkt_assembling(mctp_inst, read_buf, read_len) == MCTP_ERROR)
LOG_WRN("Packet assemble failed ");
/* if it is not last packet, waiting for the remain data */
if (!hdr->eom)
continue;
if (mctp_inst->rx_cb) {
/* default process read data buffer directly */
uint8_t *p = read_buf + sizeof(hdr);
uint16_t len = read_len - sizeof(hdr);
/* this is assembly message */
if (mctp_inst->temp_msg_buf[hdr->msg_tag].buf) {
p = mctp_inst->temp_msg_buf[hdr->msg_tag].buf;
len = mctp_inst->temp_msg_buf[hdr->msg_tag].offset;
LOG_HEXDUMP_DBG(p, len, "mctp assembly data");
}
/* handle the mctp messsage */
mctp_inst->rx_cb(mctp_inst, p, len, ext_params);
}
if (mctp_inst->temp_msg_buf[hdr->msg_tag].buf) {
free(mctp_inst->temp_msg_buf[hdr->msg_tag].buf);
mctp_inst->temp_msg_buf[hdr->msg_tag].buf = NULL;
mctp_inst->temp_msg_buf[hdr->msg_tag].offset = 0;
}
}
}