in common/ipmi/ipmb.c [171:247]
bool find_node(ipmi_msg_cfg *pnode, ipmi_msg *msg, int seq_index, uint8_t index)
{
ipmi_msg_cfg *ptr_start = pnode;
int ret;
ret = k_mutex_lock(&mutex_id[index], K_MSEC(1000));
if (ret) {
printk("find_node: mutex get fail status:%x\n", ret);
return false;
} else {
if (seq_index == 0) { // receive response and find sent request
while ((pnode != NULL && pnode->next != ptr_start) &&
(((pnode->next)->buffer.netfn != (msg->netfn - 1)) ||
((pnode->next)->buffer.cmd != msg->cmd) ||
((pnode->next)->buffer.seq_target != msg->seq_target))) {
pnode = pnode->next;
}
} else {
while ((pnode != NULL && pnode->next != ptr_start) &&
(((pnode->next)->buffer.netfn != msg->netfn) ||
((pnode->next)->buffer.cmd != msg->cmd) ||
((pnode->next)->buffer.seq_source != msg->seq_source))) {
pnode = pnode->next;
}
}
if (pnode == NULL) {
printf("pnode list should be circular, list end found\n");
k_mutex_unlock(&mutex_id[index]);
return false;
}
if (pnode->next == ptr_start) {
printf("no req match recv resp\n");
printf("node netfn: %x,cmd: %x, seq_t: %x\n", (pnode->next)->buffer.netfn,
(pnode->next)->buffer.cmd, (pnode->next)->buffer.seq_target);
printf("msg netfn: %x,cmd: %x, seq_t: %x\n\n", msg->netfn, msg->cmd,
msg->seq_target);
k_mutex_unlock(&mutex_id[index]);
return false;
}
/* Now pointer points to a node and the node next to it has to be removed */
ipmi_msg_cfg *temp;
temp = pnode->next;
if (temp == NULL) {
printf("pnode list should be circular, list end found\n");
k_mutex_unlock(&mutex_id[index]);
return false;
}
/*get the target<->Bridge IC IPMB seq number*/
if (seq_index == 0) {
// find source sequence for responding
msg->seq_source = temp->buffer.seq_source;
unregister_seq(index, temp->buffer.seq_target);
} else {
msg->seq_target = temp->buffer.seq_target;
}
msg->InF_source = temp->buffer.InF_source;
msg->InF_target = temp->buffer.InF_target;
/*temp points to the node which has to be removed*/
pnode->next = temp->next;
/*We removed the node which is next to the pointer (which is also temp) */
/* Beacuse we deleted the node, we no longer require the memory used for it .
free() will deallocate the memory.
*/
free(temp);
seq_current_count[index]--;
k_mutex_unlock(&mutex_id[index]);
return true;
}
}