Re: [PATCH v2 2/4] Bluetooth: Add __hci_cmd_sync() helper function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Johan,

> This patch adds a helper function for sending a single HCI command
> waiting for its completion and then returning back the parameters in the
> resulting command complete event (if there was one).
> 
> The implementation is very similar to that of hci_req_sync() except that
> instead of invocing a callback for sending HCI commands the function
> constructs and sends one itself and after being woken up picks the last
> received event from hdev->recv_evt (if it matches the right criteria)
> and returns it.
> 
> Signed-off-by: Johan Hedberg <johan.hedberg@xxxxxxxxx>
> ---
> include/net/bluetooth/hci_core.h |    3 ++
> net/bluetooth/hci_core.c         |   96 ++++++++++++++++++++++++++++++++++++++
> 2 files changed, 99 insertions(+)
> 
> diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
> index beae2e8..38b653d 100644
> --- a/include/net/bluetooth/hci_core.h
> +++ b/include/net/bluetooth/hci_core.h
> @@ -1056,6 +1056,9 @@ int hci_req_run(struct hci_request *req, hci_req_complete_t complete);
> void hci_req_add(struct hci_request *req, u16 opcode, u32 plen, void *param);
> void hci_req_cmd_complete(struct hci_dev *hdev, u16 opcode, u8 status);
> 
> +struct sk_buff *__hci_cmd_sync(struct hci_dev *hdev, u16 opcode, u32 plen,
> +			       void *param, u32 timeout);
> +
> int hci_send_cmd(struct hci_dev *hdev, __u16 opcode, __u32 plen, void *param);
> void hci_send_acl(struct hci_chan *chan, struct sk_buff *skb, __u16 flags);
> void hci_send_sco(struct hci_conn *conn, struct sk_buff *skb);
> diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
> index 6739cce..d0c12c0 100644
> --- a/net/bluetooth/hci_core.c
> +++ b/net/bluetooth/hci_core.c
> @@ -79,6 +79,102 @@ static void hci_req_cancel(struct hci_dev *hdev, int err)
> 	}
> }
> 
> +struct sk_buff *hci_get_cmd_complete(struct hci_dev *hdev, u16 opcode)
> +{
> +	struct hci_ev_cmd_complete *ev;
> +	struct hci_event_hdr *hdr;
> +	struct sk_buff *skb;
> +
> +	hci_dev_lock(hdev);
> +
> +	skb = hdev->recv_evt;
> +	hdev->recv_evt = NULL;
> +
> +	hci_dev_unlock(hdev);
> +
> +	if (!skb)
> +		return ERR_PTR(-ENODATA);
> +
> +	hdr = (void *) skb->data;
> +	skb_pull(skb, HCI_EVENT_HDR_SIZE);

do we check the event header length earlier and can rely on that it is valid? If not, then lets add another sanity check here.

Otherwise this patch looks fine to me.

Acked-by: Marcel Holtmann <marcel@xxxxxxxxxxxx>

Regards

Marcel

--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux