Zephyr Project API 4.4.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches

Bluetooth HID Host. More...

Data Structures

struct  bt_hid_host_cb
 Callbacks supplied by the HID Host application. More...

Functions

int bt_hid_host_register (const struct bt_hid_host_cb *cb)
 Register HID Host callbacks.
int bt_hid_host_unregister (void)
 Unregister HID Host callbacks.
int bt_hid_host_connect (struct bt_conn *conn, struct bt_hid_host **hid)
 Initiate an HID connection to a remote HID Device.
struct bt_conn * bt_hid_host_get_conn (struct bt_hid_host *hid)
 Get the ACL connection of an HID association.
int bt_hid_host_disconnect (struct bt_hid_host *hid)
 Disconnect an HID association.
int bt_hid_host_get_report (struct bt_hid_host *hid, uint8_t type, uint8_t report_id, uint16_t buffer_size)
 Send a GET_REPORT request to the HID Device.
int bt_hid_host_set_report (struct bt_hid_host *hid, uint8_t type, struct net_buf *buf)
 Send a SET_REPORT request to the HID Device.
int bt_hid_host_get_protocol (struct bt_hid_host *hid)
 Send a GET_PROTOCOL request to the HID Device.
int bt_hid_host_set_protocol (struct bt_hid_host *hid, uint8_t protocol)
 Send a SET_PROTOCOL request to the HID Device.
int bt_hid_host_output_report (struct bt_hid_host *hid, struct net_buf *buf)
 Send an output report on the interrupt channel.
int bt_hid_host_suspend (struct bt_hid_host *hid)
 Send SUSPEND control to the HID Device.
int bt_hid_host_exit_suspend (struct bt_hid_host *hid)
 Send EXIT_SUSPEND control to the HID Device.
int bt_hid_host_virtual_cable_unplug (struct bt_hid_host *hid)
 Send Virtual Cable Unplug to the HID Device.
struct net_buf * bt_hid_host_create_pdu (struct net_buf_pool *pool)
 Allocate a PDU buffer for HID Host transmissions.

Detailed Description

Bluetooth HID Host.

Function Documentation

◆ bt_hid_host_connect()

int bt_hid_host_connect ( struct bt_conn * conn,
struct bt_hid_host ** hid )

#include <hid_host.h>

Initiate an HID connection to a remote HID Device.

Opens the L2CAP control channel and, once it is up, the interrupt channel.

The HID service record is not read here. Applications that need the report descriptor or the device attributes discover them over SDP themselves, which also leaves them free to decide whether to do so on every connection.

Parameters
connACL connection to the remote device.
hidPointer to store the HID Host instance on success.
Returns
0 on success, -ENOTSUP if bt_hid_host_register() has not been called, negative errno on other failures.

◆ bt_hid_host_create_pdu()

struct net_buf * bt_hid_host_create_pdu ( struct net_buf_pool * pool)

#include <hid_host.h>

Allocate a PDU buffer for HID Host transmissions.

The returned buffer already reserves headroom for the HID header, so the profile can prepend it without copying. Callers only append the report payload with net_buf_add_*() and must not consume the headroom themselves.

Parameters
poolBuffer pool to allocate from, or NULL for default.
Returns
net_buf on success, NULL on failure.

◆ bt_hid_host_disconnect()

int bt_hid_host_disconnect ( struct bt_hid_host * hid)

#include <hid_host.h>

Disconnect an HID association.

Tears down the interrupt channel first, then the control channel per HID spec v1.1.2 Section 5.2.2.

Parameters
hidHID Host instance.
Returns
0 on success, negative errno on failure.

◆ bt_hid_host_exit_suspend()

int bt_hid_host_exit_suspend ( struct bt_hid_host * hid)

#include <hid_host.h>

Send EXIT_SUSPEND control to the HID Device.

Informs the device that the host is exiting low-power state.

Parameters
hidHID Host instance.
Returns
0 on success, negative errno on failure.

◆ bt_hid_host_get_conn()

struct bt_conn * bt_hid_host_get_conn ( struct bt_hid_host * hid)

#include <hid_host.h>

Get the ACL connection of an HID association.

Needed by applications that have to act on the peer identity, for example to destroy the bonding after a Virtual Cable Unplug (HID spec v1.1.2 Section 3.1.2.2.3), which the stack leaves to the application.

Parameters
hidHID Host instance.
Returns
New reference to the ACL connection which must be released with bt_conn_unref(), or NULL if the association is no longer established.

◆ bt_hid_host_get_protocol()

int bt_hid_host_get_protocol ( struct bt_hid_host * hid)

#include <hid_host.h>

Send a GET_PROTOCOL request to the HID Device.

The response arrives via the get_protocol callback.

Parameters
hidHID Host instance.
Returns
0 on success, negative errno on failure.

◆ bt_hid_host_get_report()

int bt_hid_host_get_report ( struct bt_hid_host * hid,
uint8_t type,
uint8_t report_id,
uint16_t buffer_size )

#include <hid_host.h>

Send a GET_REPORT request to the HID Device.

The response arrives asynchronously via the get_report callback, or the association is torn down if the device never answers.

The ReportID field is required as soon as the report descriptor declares Report IDs, and in Boot Protocol Mode it is always required (HID spec v1.1.2 Section 3.1.2.3 and Section 3.3.1). Only the application knows the descriptor, so it decides whether the field is sent.

Parameters
hidHID Host instance.
typeReport type (BT_HID_REPORT_TYPE_INPUT/OUTPUT/FEATURE).
report_idReport ID to request, or 0 to omit the field. Report ID 0 is reserved by the USB HID specification, so it cannot identify a report.
buffer_sizeMaximum response payload size (0 = no limit). Must not exceed what the control channel can receive.
Returns
0 on success, negative errno on failure.

◆ bt_hid_host_output_report()

int bt_hid_host_output_report ( struct bt_hid_host * hid,
struct net_buf * buf )

#include <hid_host.h>

Send an output report on the interrupt channel.

This is an asynchronous transfer with no acknowledgment: HID spec v1.1.2 Section 3.1.2.9 leaves interrupt channel transfers unanswered. The buffer must start with the Report ID when the report descriptor declares Report IDs or the device is in Boot Protocol Mode.

Parameters
hidHID Host instance.
bufBuffer containing output report, allocated with bt_hid_host_create_pdu() so the HIDP header fits (consumed on success).
Returns
0 on success, negative errno on failure.

◆ bt_hid_host_register()

int bt_hid_host_register ( const struct bt_hid_host_cb * cb)

#include <hid_host.h>

Register HID Host callbacks.

Registers the application callbacks and sets up L2CAP servers to accept incoming Device-initiated reconnections on PSM 0x0011/0x0013.

Parameters
cbCallback structure. Must remain valid for the lifetime of the HID Host subsystem.
Returns
0 on success, negative errno on failure.

◆ bt_hid_host_set_protocol()

int bt_hid_host_set_protocol ( struct bt_hid_host * hid,
uint8_t protocol )

#include <hid_host.h>

Send a SET_PROTOCOL request to the HID Device.

The response arrives via the set_protocol callback.

Parameters
hidHID Host instance.
protocolTarget protocol (BT_HID_PROTOCOL_BOOT_MODE or BT_HID_PROTOCOL_REPORT_MODE).
Returns
0 on success, negative errno on failure.

◆ bt_hid_host_set_report()

int bt_hid_host_set_report ( struct bt_hid_host * hid,
uint8_t type,
struct net_buf * buf )

#include <hid_host.h>

Send a SET_REPORT request to the HID Device.

The response arrives via the set_report callback. The buffer must start with the Report ID when the report descriptor declares Report IDs or the device is in Boot Protocol Mode.

Parameters
hidHID Host instance.
typeReport type (BT_HID_REPORT_TYPE_INPUT/OUTPUT/FEATURE).
bufBuffer containing report payload, allocated with bt_hid_host_create_pdu(). Retained by the caller on failure.
Returns
0 on success, negative errno on failure.

◆ bt_hid_host_suspend()

int bt_hid_host_suspend ( struct bt_hid_host * hid)

#include <hid_host.h>

Send SUSPEND control to the HID Device.

Informs the device that the host is entering a low-power state.

Parameters
hidHID Host instance.
Returns
0 on success, negative errno on failure.

◆ bt_hid_host_unregister()

int bt_hid_host_unregister ( void )

#include <hid_host.h>

Unregister HID Host callbacks.

Unregisters the L2CAP servers so incoming Device-initiated reconnections are no longer accepted. All HID associations must be disconnected first.

Returns
0 on success, negative errno on other failures.
Return values
-EBUSYif an HID association is still active.
-EALREADYif the HID Host callbacks are not registered.

◆ bt_hid_host_virtual_cable_unplug()

int bt_hid_host_virtual_cable_unplug ( struct bt_hid_host * hid)

#include <hid_host.h>

Send Virtual Cable Unplug to the HID Device.

Sends a VCU control message and waits for the HID Device to acknowledge it by disconnecting the association, per HID spec v1.1.2 Section 3.1.2.2.3. If the peer does not disconnect, the host starts a fallback teardown after the transaction timeout. Destroying the bonding is left to the application, see the vc_unplug callback.

Parameters
hidHID Host instance.
Returns
0 on success, negative errno on failure.