2019-07-08 02:25:52

by Andrii Batyiev

[permalink] [raw]
Subject: [PATCH] Fix endianness bug in hci_core.c

Hello everyone,

I'm using Linux on big endian CPU (one of MIPS-based home routers).
Also, I'm trying to use Cypress CYW20704A2 USB-Bluetooth dongle on it.
However, `hciconfig hci0 up` failed, and `btmon` showed very specific problem:



< HCI Command: LE Write Suggested Default Data Length (0x08|0x0024) plen 4
TX octets: 64256
TX time: 18440
> HCI Event: Command Complete (0x0e) plen 4
LE Write Suggested Default Data Length (0x08|0x0024) ncmd 1
Status: Invalid HCI Command Parameters (0x12)



After comparing with similar log on the Linux desktop (where TX octets
value is `251`), I came to conclusion that it's an endianness problem,
therefore here is a patch that fixes it.

Thanks,
Andrey

--- linux-4.14.104-old/net/bluetooth/hci_core.c 2019-07-07
23:39:44.069862824 +0000
+++ linux-4.14.104/net/bluetooth/hci_core.c 2019-07-07
22:43:21.291838543 +0000
@@ -802,8 +802,8 @@
if (hdev->le_features[0] & HCI_LE_DATA_LEN_EXT) {
struct hci_cp_le_write_def_data_len cp;

- cp.tx_len = hdev->le_max_tx_len;
- cp.tx_time = hdev->le_max_tx_time;
+ cp.tx_len = cpu_to_le16(hdev->le_max_tx_len);
+ cp.tx_time = cpu_to_le16(hdev->le_max_tx_time);
hci_req_add(req, HCI_OP_LE_WRITE_DEF_DATA_LEN, sizeof(cp), &cp);
}


2019-07-08 15:22:15

by Marcel Holtmann

[permalink] [raw]
Subject: Re: [PATCH] Fix endianness bug in hci_core.c

Hi Andrey,

> I'm using Linux on big endian CPU (one of MIPS-based home routers).
> Also, I'm trying to use Cypress CYW20704A2 USB-Bluetooth dongle on it.
> However, `hciconfig hci0 up` failed, and `btmon` showed very specific problem:
>
>
>
> < HCI Command: LE Write Suggested Default Data Length (0x08|0x0024) plen 4
> TX octets: 64256
> TX time: 18440
>> HCI Event: Command Complete (0x0e) plen 4
> LE Write Suggested Default Data Length (0x08|0x0024) ncmd 1
> Status: Invalid HCI Command Parameters (0x12)
>
>
>
> After comparing with similar log on the Linux desktop (where TX octets
> value is `251`), I came to conclusion that it's an endianness problem,
> therefore here is a patch that fixes it.
>
> Thanks,
> Andrey
>
> --- linux-4.14.104-old/net/bluetooth/hci_core.c 2019-07-07
> 23:39:44.069862824 +0000
> +++ linux-4.14.104/net/bluetooth/hci_core.c 2019-07-07
> 22:43:21.291838543 +0000
> @@ -802,8 +802,8 @@
> if (hdev->le_features[0] & HCI_LE_DATA_LEN_EXT) {
> struct hci_cp_le_write_def_data_len cp;
>
> - cp.tx_len = hdev->le_max_tx_len;
> - cp.tx_time = hdev->le_max_tx_time;
> + cp.tx_len = cpu_to_le16(hdev->le_max_tx_len);
> + cp.tx_time = cpu_to_le16(hdev->le_max_tx_time);
> hci_req_add(req, HCI_OP_LE_WRITE_DEF_DATA_LEN, sizeof(cp), &cp);
> }

good catch, but please send a git-format-patch created patch. And following the submitting patches guide. Thanks.

Regards

Marcel