Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance Zephyr bluetooth GAP #7

Merged
merged 12 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
148 changes: 148 additions & 0 deletions include/zephyr/bluetooth/classic/classic.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,154 @@
*/
int bt_br_set_connectable(bool enable);

/**
* @brief Set controller page scan activity.
*
* Page Scan is only performed when Page_Scan is enabled.
*
* @param interval Page scan interval in 0.625 ms units
* Range: 0x0012 to 0x1000; only even values are valid.
* @param window Page scan window in 0.625 ms units
* Range: 0x0011 to 0x1000.
*
* @return Negative if fail set to requested state or requested state has been
* already set. Zero if done successfully.
*/
int bt_br_write_page_scan_activity(uint16_t interval, uint16_t window);

/**
* @brief Set controller inquiry scan activity.
*
* Inquiry Scan is only performed when Inquiry_Scan is enabled.
*
* @param interval Inquiry scan interval in 0.625 ms units
* Range: 0x0012 to 0x1000; only even values are valid.
* @param window Inquiry scan window in 0.625 ms units
* Range: 0x0011 to 0x1000.
*
* @return Negative if fail set to requested state or requested state has been
* already set. Zero if done successfully.
*/
int bt_br_write_inquiry_scan_activity(uint16_t interval, uint16_t window);

/**
* @brief Set the inquiry Scan Type configuration parameter of the local
* BR/EDR Controller.
*
* @param type Inquiry scan type.
* 0x00: Standard scan (default)

Check warning on line 234 in include/zephyr/bluetooth/classic/classic.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

SPACE_BEFORE_TAB

include/zephyr/bluetooth/classic/classic.h:234 please, no space before tabs
* 0x01: Interlaced scan

Check warning on line 235 in include/zephyr/bluetooth/classic/classic.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

SPACE_BEFORE_TAB

include/zephyr/bluetooth/classic/classic.h:235 please, no space before tabs
*
* @return Negative if fail set to requested state or requested state has been
* already set. Zero if done successfully.
*/
int bt_br_write_inquiry_scan_type(uint8_t type);

/**
* @brief Set the page Scan Type configuration parameter of the local
* BR/EDR Controller.
*
* @param type Page scan type.
* 0x00: Standard scan (default)
* 0x01: Interlaced scan
*
* @return Negative if fail set to requested state or requested state has been
* already set. Zero if done successfully.
*/
int bt_br_write_page_scan_type(uint8_t type);

/**
* @brief Set the Class of Device configuration parameter of the local
* BR/EDR Controller.
*
* @param local_cod Class of Device value.
*
* @return Negative if fail set to requested state or requested state has been
* already set. Zero if done successfully.
*/
int bt_br_set_class_of_device(uint32_t local_cod);

/**
* @brief Set the local name of the BR/EDR Controller.
*
* @param name Local name of the BR/EDR Controller.
*
* @return Negative if fail set to requested state or requested state has been
* already set. Zero if done successfully.
*/
int bt_br_write_local_name(const char *name);

/** Information about a br/edr bond with a remote device. */
struct bt_bond_info_br {
bt_addr_t addr;
uint8_t key_type;
uint8_t key[16];
};

Check notice on line 281 in include/zephyr/bluetooth/classic/classic.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

include/zephyr/bluetooth/classic/classic.h:281 - uint8_t key_type; - uint8_t key[16]; + uint8_t key_type; + uint8_t key[16];

/**
* @brief Callback for iterating over all BR/EDR bond information.
*
* @param info Bond information.
* @param user_data Data passed to the iterator.
*/
void bt_foreach_bond_br(void (*func)(const struct bt_bond_info_br *info, void *user_data),
void *user_data);

/**
* @brief Set BR/EDR bond information.
*
* @param info Bond information.
*
* @return Zero on success or error code otherwise, positive in case
* of protocol error or negative (POSIX) in case of stack internal error.
*/
int bt_set_bond_info_br(const struct bt_bond_info_br *info);

/**
* @brief Get BR/EDR bond information.
*
* @param bdaddr Address of the remote device.
* @param info Bond information.
*
* @return Zero on success or error code otherwise, positive in case
* of protocol error or negative (POSIX) in case of stack internal error.
*/
int bt_get_bond_info_br(const bt_addr_t* bdaddr, struct bt_bond_info_br *info);

Check failure on line 311 in include/zephyr/bluetooth/classic/classic.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

POINTER_LOCATION

include/zephyr/bluetooth/classic/classic.h:311 "foo* bar" should be "foo *bar"

Check notice on line 312 in include/zephyr/bluetooth/classic/classic.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

include/zephyr/bluetooth/classic/classic.h:312 -int bt_get_bond_info_br(const bt_addr_t* bdaddr, struct bt_bond_info_br *info); +int bt_get_bond_info_br(const bt_addr_t *bdaddr, struct bt_bond_info_br *info);
/**
* @brief Request remote device name callback.
*
* @param bdaddr Remote device address.
* @param name Remote device name.
* @param status Status of the request.
*/
typedef void (*bt_br_remote_name_req_cb_t)(const bt_addr_t *bdaddr, const char *name, uint8_t status);

Check warning on line 320 in include/zephyr/bluetooth/classic/classic.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LONG_LINE

include/zephyr/bluetooth/classic/classic.h:320 line length of 102 exceeds 100 columns

Check notice on line 321 in include/zephyr/bluetooth/classic/classic.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

include/zephyr/bluetooth/classic/classic.h:321 -typedef void (*bt_br_remote_name_req_cb_t)(const bt_addr_t *bdaddr, const char *name, uint8_t status); +typedef void (*bt_br_remote_name_req_cb_t)(const bt_addr_t *bdaddr, const char *name, + uint8_t status);
/**
* @brief Request remote device name.
*
* Remote Name Request is used to find out the name of the remote
* device without requiring an explicit ACL connection
*
* @param addr Remote device address.
* @param cb Callback to notify about remote device name.
*
* @return 0 on success or negative error value on failure.
*/
int bt_br_remote_name_request(const bt_addr_t *addr, bt_br_remote_name_req_cb_t cb);

/**
* @brief Unpair with a br remote device.
*
* remove the bond information with the remote device in controller
* or settings.
*
* @param bdaddr Remote device address.
*
* @return 0 on success or negative error value on failure.
*/
int bt_br_unpair(bt_addr_t *bdaddr);

/**
* @}
*/
Expand Down
181 changes: 181 additions & 0 deletions include/zephyr/bluetooth/conn.h
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,29 @@
*/
const bt_addr_le_t *bt_conn_get_dst(const struct bt_conn *conn);

#if defined(CONFIG_BT_CLASSIC)
/** @brief Look up an existing BREDR acl connection by address.
*
* Look up an existing connection based on the remote address.
*
* The caller gets a new reference to the connection object which must be
* released with bt_conn_unref() once done using the object.
*
* @param peer Remote address.
*
* @return Connection object or NULL if not found.
*/
struct bt_conn *bt_conn_lookup_addr_br(const bt_addr_t *peer);

/** @brief Get destination (peer) address of a br or sco connection.
*
* @param conn Connection object.
*
* @return Destination address.
*/
const bt_addr_t *bt_conn_get_dst_br(const struct bt_conn *conn);
#endif /* CONFIG_BT_CLASSIC */

/** @brief Get array index of a connection
*
* This function is used to map bt_conn to index of an array of
Expand Down Expand Up @@ -840,6 +863,8 @@

/** Connection Info Structure */
struct bt_conn_info {
/** Connection handle. */
uint16_t handle;
/** Connection Type. */
enum bt_conn_type type;
/** Connection Role. */
Expand Down Expand Up @@ -1613,6 +1638,24 @@
* used for that instance.
*/
struct bt_conn_cb {
#if !defined(CONFIG_BT_CONN_REQ_AUTO_HANDLE)
/** @brief Query to proceed BR/EDR incoming connection or not.
*
* On any incoming connection req this callback will be called for
* the application to decide whether to allow for the connection to
* continue.
*
* As this callback is asynchronous, the application should call
* bt_conn_accept_acl_conn/bt_conn_reject_acl_conn to response value.
*
* @param conn New connection object.
* @param link_type Link type.
* @param cod Device class.
*
*/
void (*connect_req)(struct bt_conn *conn, uint8_t link_type, uint8_t *cod);
#endif /* !defined(CONFIG_BT_CONN_REQ_AUTO_HANDLE) */

/** @brief A new connection has been established.
*
* This callback notifies the application of a new connection.
Expand Down Expand Up @@ -1759,6 +1802,29 @@
struct bt_conn_remote_info *remote_info);
#endif /* defined(CONFIG_BT_REMOTE_INFO) */

#if defined(CONFIG_BT_CLASSIC)
#if defined(CONFIG_BT_POWER_MODE_CONTROL)
/** @brief The connection mode change
*
* This callback notifies the application controller mode changed
*
* @param conn Connection object.
* @param mode Active/Sniff mode.
* @param interval Sniff interval.
*/
void (*mode_changed)(struct bt_conn *conn, uint8_t mode, uint16_t interval);
#endif /* CONFIG_BT_POWER_MODE_CONTROL */

/** @brief The connection role change
*
* This callback notifies the application controller role change
*
* @param conn Connection object.
* @param role New role updated.
*/
void (*role_changed)(struct bt_conn *conn, uint8_t role);
#endif /* CONFIG_BT_CLASSIC */

#if defined(CONFIG_BT_USER_PHY_UPDATE)
/** @brief The PHY of the connection has changed.
*
Expand Down Expand Up @@ -2371,6 +2437,18 @@

/** Authenticated pairing information callback structure */
struct bt_conn_auth_info_cb {
#if defined(CONFIG_BT_CLASSIC)
/** @brief notify that bredr pairing link key generated.
*
* The callback notifies the application that the link key has been
* generated during the pairing procedure.
*
* @param conn Connection object.
* @param key Link key.
* @param key_type Link key type.
*/
void (*link_key_notify)(struct bt_conn *conn, uint8_t *key, uint8_t key_type);
#endif
/** @brief notify that pairing procedure was complete.
*
* This callback notifies the application that the pairing procedure
Expand Down Expand Up @@ -2404,6 +2482,21 @@
sys_snode_t node;
};

/**
* @brief Initiate pairing with a remote device.
*
* This function is used to initiate pairing with a remote device.
* The pairing process is asynchronous and the result of the pairing
* process is reported through the pairing_complete, if the connection
* not exists, setup the connection first.
*
* @param bdaddr Remote device address.
* @param security Security level to use.
*
* @return Valid connection object on success or NULL otherwise.
*/
struct bt_conn *bt_conn_pair_br(bt_addr_t *bdaddr, bt_security_t security);

/** @brief Register authentication callbacks.
*
* Register callbacks to handle authenticated pairing. Passing NULL
Expand Down Expand Up @@ -2569,6 +2662,94 @@
struct bt_conn *bt_conn_create_br(const bt_addr_t *peer,
const struct bt_br_conn_param *param);

#if defined(CONFIG_BT_POWER_MODE_CONTROL)
/** @brief bluetooth conn check and enter sniff mode
*
* This function is used to identify which ACL link connection is to
* be placed in Sniff mode
*
* @param conn bt_conn conn
* @param min_interval Minimum sniff interval.
* @param max_interval Maxmum sniff interval.
* @param attempt Number of Baseband receive slots for sniff attempt.
* @param timeout Number of Baseband receive slots for sniff timeout.
*/
int bt_conn_enter_sniff_mode(struct bt_conn *conn, uint16_t min_interval, uint16_t max_interval,
uint16_t attempt, uint16_t timeout);

/** @brief bluetooth conn check and exit sniff mode
*
* @param conn bt_conn conn
*
* @return Zero for success, non-zero otherwise.
*/
int bt_conn_exit_sniff_mode(struct bt_conn *conn);
#endif /* CONFIG_BT_POWER_MODE_CONTROL */

/** @brief Bt role discovery.
*

Check failure on line 2690 in include/zephyr/bluetooth/conn.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

TRAILING_WHITESPACE

include/zephyr/bluetooth/conn.h:2690 trailing whitespace
* @param conn Connection object.

Check notice on line 2691 in include/zephyr/bluetooth/conn.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

include/zephyr/bluetooth/conn.h:2691 - * + *
* @param role return role.
*
* @return Zero for success, non-zero otherwise.
*/
int bt_conn_role_discovery(struct bt_conn *conn, uint8_t *role);

/** @brief Bt switch role.
*
* @param conn Connection object.
* @param role Switch role.
*
* @return Zero for success, non-zero otherwise.
*/
int bt_conn_switch_role(struct bt_conn *conn, uint8_t role);

/** @brief Set supervision timeout.
*
* Each physical link has a timer that is used for link supervision.
* This timer is used to detect physical link loss caused by devices
* moving out of range, or being blocked by interference, a device’s
* power-down, or other similar failure cases.
*
* @param conn Connection object.
* @param timeout Link supervision timeout, Range: 0x0001 to 0xFFFF
* Time Range: 0.625 ms to 40.9 s.
*
* @return Zero for success, non-zero otherwise.
*/
int bt_conn_set_supervision_timeout(struct bt_conn *conn, uint16_t timeout);

/** @brief Set link policy settings.
*
* This function is used to set the link policy settings for a connection.
*
* @param conn Connection object.
* @param policy Link policy settings.
* Bit 0: Enable role switch.
* Bit 1: Enable hold mode.
* Bit 2: Enable sniff mode.
*
* @return Zero for success, non-zero otherwise.
*/
int bt_conn_set_link_policy_settings(struct bt_conn* conn, uint16_t policy);

Check failure on line 2734 in include/zephyr/bluetooth/conn.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

POINTER_LOCATION

include/zephyr/bluetooth/conn.h:2734 "foo* bar" should be "foo *bar"

Check notice on line 2735 in include/zephyr/bluetooth/conn.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

include/zephyr/bluetooth/conn.h:2735 -int bt_conn_set_link_policy_settings(struct bt_conn* conn, uint16_t policy); +int bt_conn_set_link_policy_settings(struct bt_conn *conn, uint16_t policy);
/** @brief Accept the acl connection.
*
* @param conn The connection of peer device to accept.
*
* @return Zero for success, non-zero otherwise.
*/
int bt_conn_accept_acl_conn(struct bt_conn *conn);

/** @brief Reject the acl connection.
*
* @param conn The connection of peer device to reject.
* @param reason Reject reason.
*
* @return Zero for success, non-zero otherwise.
*/
int bt_conn_reject_acl_conn(struct bt_conn *conn, uint8_t reason);

#ifdef __cplusplus
}
#endif
Expand Down
Loading
Loading