Re: [PATCH v6 2/2] Bluetooth: btnxpuart: Add support to set BD address

From: Neeraj Sanjay Kale
Date: Mon Mar 03 2025 - 04:25:08 EST


Hi Luiz,

Thank you for reviewing the patch.

> > @@ -1197,6 +1209,38 @@ static int nxp_set_ind_reset(struct hci_dev
> *hdev, void *data)
> > return hci_recv_frame(hdev, skb); }
> >
> > +static int nxp_set_bdaddr(struct hci_dev *hdev, const bdaddr_t
> > +*bdaddr) {
> > + union nxp_set_bd_addr_payload pcmd;
> > + struct sk_buff *skb;
> > + int err;
> > +
> > + pcmd.data.param_id = 0xfe;
> > + pcmd.data.param_len = 6;
> > + memcpy(pcmd.data.param, bdaddr, 6);
> > +
> > + /* BD address can be assigned only after first reset command. */
> > + skb = __hci_cmd_sync(hdev, HCI_OP_RESET, 0, NULL,
> HCI_INIT_TIMEOUT);
> > + if (IS_ERR(skb)) {
> > + err = PTR_ERR(skb);
> > + bt_dev_err(hdev, "Reset before setting local-bd-addr failed (%ld)",
> > + PTR_ERR(skb));
> > + return err;
> > + }
> > + kfree_skb(skb);
>
> If you don't care about the response, just the status, it is probably better to
> use __hci_cmd_sync_status, also since the hdev->set_bdaddr comes after
> hdev->setup doesn't the later do perform a reset anyway?
> If you end up with 2 resets in a row it problems means you don't need to
> reset again.

Hdev->set_bdaddr comes after hdev->setup, but comes before the first HCI RESET.

With this patch, if Device Tree has a local-bd-addr property, hdev->set_bdaddr will send HCI RESET, followed by 3f22 command, and then HCI RESET again during initialization, along with READ LOCAL FEATURES, READ LOCAL VERSION and READ BD ADDR.

Without local-bd-addr DT property, hdev->set_bdaddr will be skipped and only one HCI RESET will be sent.
>
> > +
> > + skb = __hci_cmd_sync(hdev, HCI_NXP_SET_BD_ADDR, sizeof(pcmd),
> > + pcmd.buf, HCI_CMD_TIMEOUT);
>
> Ditto.
>
> > + if (IS_ERR(skb)) {
> > + err = PTR_ERR(skb);
> > + bt_dev_err(hdev, "Changing device address failed (%d)", err);
> > + return err;
> > + }
> > + kfree_skb(skb);
> > +
> > + return 0;
> > +}
> > +
> > /* NXP protocol */

Thanks,
Neeraj