HCI Host Not enough space in buffer #hci



I have a HCI host and controller setup. When the host starts, and the controller had already been running, it sometimes begins reading in the middle of a HCI message from the controller. It reads the wrong HCI message type and length. This causes the buffer to completely fill where it errors out in h4.c, read_payload(), BT_ERR("Not enough space in buffer"). After this the host application does not recover and a power cycle is needed.

I found a quick fix for this is to remove a line in h4.c read_payload(). I think it was meant to discard the rest of a message data if the buffer is full, but it looks like its assuming rx.remaining is valid. In this case, rx.remaining is invalid because it read the wrong byte as the length when it jumped into the middle of a HCI message.
    if (rx.remaining > net_buf_tailroom(rx.buf)) {
      BT_ERR("Not enough space in buffer");
      //rx.discard = rx.remaining; // fixes issue. it was discarding thousands of bytes
I don't know what other consequences this quick fix will have. Is there a better way to fix this issue? Maybe check the message validity before it fills up the buffer?


Join devel@lists.zephyrproject.org to automatically receive all group messages.