Skip to content

Commit

Permalink
Bluetooth: btnxpuart: No need to check the received bootloader signature
Browse files Browse the repository at this point in the history
We can never assume the uart will deliver a complete packet to the BT
layer at once, the expected packet may be divided into several parts by
uart as uart doesn't know the received packet size, the received data
count may mismatch with the expected packet size, so here
is_valid_bootloader_signature() check may always return false.

Even we remove the count check in is_valid_bootloader_signature(), then
the first part of the data which includes the packet type can pass the
is_valid_bootloader_signature() check, but the remaining parts don't
have the packet type data still cannot pass the check, here return
directly will cause the data loss.

So need to remove the received bootloader signature check here, the
h4_recv_buf() can help us combine the different data received into one
packet. If any out-of-sync or incomplete bootloader signature is received,
it is safe to ignore and discard it, and process the next bootloader
signature.

Co-developed-by: Sherry Sun <sherry.sun@nxp.com>
Signed-off-by: Sherry Sun <sherry.sun@nxp.com>
Signed-off-by: Neeraj Sanjay Kale <neeraj.sanjaykale@nxp.com>
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
  • Loading branch information
Neeraj Sanjay Kale authored and Vudentz committed Apr 6, 2023
1 parent 3f8dae8 commit b1ff41f
Showing 1 changed file with 3 additions and 16 deletions.
19 changes: 3 additions & 16 deletions drivers/bluetooth/btnxpuart.c
Original file line number Diff line number Diff line change
Expand Up @@ -1199,33 +1199,20 @@ static const struct h4_recv_pkt nxp_recv_pkts[] = {
{ NXP_RECV_FW_REQ_V3, .recv = nxp_recv_fw_req_v3 },
};

static bool is_valid_bootloader_signature(const u8 *data, size_t count)
{
if ((*data == NXP_V1_FW_REQ_PKT && count == sizeof(struct v1_data_req) + 1) ||
(*data == NXP_V3_FW_REQ_PKT && count == sizeof(struct v3_data_req) + 1) ||
(*data == NXP_V3_CHIP_VER_PKT && count == sizeof(struct v3_start_ind) + 1))
return true;
else
return false;
}

static int btnxpuart_receive_buf(struct serdev_device *serdev, const u8 *data,
size_t count)
{
struct btnxpuart_dev *nxpdev = serdev_device_get_drvdata(serdev);

if (is_fw_downloading(nxpdev) && !is_valid_bootloader_signature(data, count)) {
/* Unknown bootloader signature, skip without returning error */
return count;
}

ps_start_timer(nxpdev);

nxpdev->rx_skb = h4_recv_buf(nxpdev->hdev, nxpdev->rx_skb, data, count,
nxp_recv_pkts, ARRAY_SIZE(nxp_recv_pkts));
if (IS_ERR(nxpdev->rx_skb)) {
int err = PTR_ERR(nxpdev->rx_skb);

/* Safe to ignore out-of-sync bootloader signatures */
if (is_fw_downloading(nxpdev))
return count;
bt_dev_err(nxpdev->hdev, "Frame reassembly failed (%d)", err);
nxpdev->rx_skb = NULL;
return err;
Expand Down

0 comments on commit b1ff41f

Please sign in to comment.