Skip to content

Commit a112d3c

Browse files
jhovoldVudentz
authored andcommitted
Bluetooth: qca: fix NVM configuration parsing
The NVM configuration files used by WCN3988 and WCN3990/1/8 have two sets of configuration tags that are enclosed by a type-length header of type four which the current parser fails to account for. Instead the driver happily parses random data as if it were valid tags, something which can lead to the configuration data being corrupted if it ever encounters the words 0x0011 or 0x001b. As is clear from commit b638825 ("Bluetooth: btqca: Fix the NVM baudrate tag offcet for wcn3991") the intention has always been to process the configuration data also for WCN3991 and WCN3998 which encodes the baud rate at a different offset. Fix the parser so that it can handle the WCN3xxx configuration files, which has an enclosing type-length header of type four and two sets of TLV tags enclosed by a type-length header of type two and three, respectively. Note that only the first set, which contains the tags the driver is currently looking for, will be parsed for now. With the parser fixed, the software in-band sleep bit will now be set for WCN3991 and WCN3998 (as it is for later controllers) and the default baud rate 3200000 may be updated by the driver also for WCN3xxx controllers. Notably the deep-sleep feature bit is already set by default in all configuration files in linux-firmware. Fixes: 4219d46 ("Bluetooth: btqca: Add wcn3990 firmware download support.") Cc: [email protected] # 4.19 Cc: Matthias Kaehlcke <[email protected]> Signed-off-by: Johan Hovold <[email protected]> Signed-off-by: Luiz Augusto von Dentz <[email protected]>
1 parent 2e4edfa commit a112d3c

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

drivers/bluetooth/btqca.c

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ static int qca_tlv_check_data(struct hci_dev *hdev,
281281
struct tlv_type_patch *tlv_patch;
282282
struct tlv_type_nvm *tlv_nvm;
283283
uint8_t nvm_baud_rate = config->user_baud_rate;
284+
u8 type;
284285

285286
config->dnld_mode = QCA_SKIP_EVT_NONE;
286287
config->dnld_type = QCA_SKIP_EVT_NONE;
@@ -346,11 +347,30 @@ static int qca_tlv_check_data(struct hci_dev *hdev,
346347
tlv = (struct tlv_type_hdr *)fw_data;
347348

348349
type_len = le32_to_cpu(tlv->type_len);
349-
length = (type_len >> 8) & 0x00ffffff;
350+
length = type_len >> 8;
351+
type = type_len & 0xff;
350352

351-
BT_DBG("TLV Type\t\t : 0x%x", type_len & 0x000000ff);
353+
/* Some NVM files have more than one set of tags, only parse
354+
* the first set when it has type 2 for now. When there is
355+
* more than one set there is an enclosing header of type 4.
356+
*/
357+
if (type == 4) {
358+
if (fw_size < 2 * sizeof(struct tlv_type_hdr))
359+
return -EINVAL;
360+
361+
tlv++;
362+
363+
type_len = le32_to_cpu(tlv->type_len);
364+
length = type_len >> 8;
365+
type = type_len & 0xff;
366+
}
367+
368+
BT_DBG("TLV Type\t\t : 0x%x", type);
352369
BT_DBG("Length\t\t : %d bytes", length);
353370

371+
if (type != 2)
372+
break;
373+
354374
if (fw_size < length + (tlv->data - fw_data))
355375
return -EINVAL;
356376

0 commit comments

Comments
 (0)