Skip to content

Commit ae6c20d

Browse files
Thalleynashif
authored andcommitted
Bluetooth: BAP: BA: Replace bools with atomic
Replace the boolean values for the BAP Broadcast Assistant with an atomic value. This prevents a rare, but possible, race condition. The busy flag has been replaced with 3 atomic values which provide better granularity in error handling, and allows for some concurrent write and read requests. To describe the new behavior, the return values in the documentation has been updated, and the error handling in the API functions has improved. Signed-off-by: Emil Gydesen <[email protected]>
1 parent 081aa2f commit ae6c20d

File tree

3 files changed

+254
-92
lines changed

3 files changed

+254
-92
lines changed

include/zephyr/bluetooth/audio/bap.h

Lines changed: 53 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2321,7 +2321,13 @@ struct bt_bap_broadcast_assistant_cb {
23212321
* new connection, will delete all previous data.
23222322
*
23232323
* @param conn The connection
2324-
* @return int Error value. 0 on success, GATT error or ERRNO on fail.
2324+
*
2325+
* @retval 0 Success
2326+
* @retval -EINVAL @p conn is NULL
2327+
* @retval -EBUSY Another operation is already in progress for this @p conn
2328+
* @retval -ENOTCONN @p conn is not connected
2329+
* @retval -ENOMEM Could not allocated memory for the request
2330+
* @retval -ENOEXEC Unexpected GATT error
23252331
*/
23262332
int bt_bap_broadcast_assistant_discover(struct bt_conn *conn);
23272333

@@ -2340,7 +2346,14 @@ int bt_bap_broadcast_assistant_discover(struct bt_conn *conn);
23402346
* Used to let the server know that we are scanning.
23412347
* @param start_scan Start scanning if true. If false, the application should
23422348
* enable scan itself.
2343-
* @return int Error value. 0 on success, GATT error or ERRNO on fail.
2349+
2350+
* @retval 0 Success
2351+
* @retval -EINVAL @p conn is NULL of if @p conn has not done discovery
2352+
* @retval -EBUSY Another operation is already in progress for this @p conn
2353+
* @retval -EAGAIN Bluetooth has not been enabled.
2354+
* @retval -ENOTCONN @p conn is not connected
2355+
* @retval -ENOMEM Could not allocated memory for the request
2356+
* @retval -ENOEXEC Unexpected scan or GATT error
23442357
*/
23452358
int bt_bap_broadcast_assistant_scan_start(struct bt_conn *conn,
23462359
bool start_scan);
@@ -2349,7 +2362,14 @@ int bt_bap_broadcast_assistant_scan_start(struct bt_conn *conn,
23492362
* @brief Stop remote scanning for BISes for a server.
23502363
*
23512364
* @param conn Connection to the server.
2352-
* @return int Error value. 0 on success, GATT error or ERRNO on fail.
2365+
2366+
* @retval 0 Success
2367+
* @retval -EINVAL @p conn is NULL of if @p conn has not done discovery
2368+
* @retval -EBUSY Another operation is already in progress for this @p conn
2369+
* @retval -EAGAIN Bluetooth has not been enabled.
2370+
* @retval -ENOTCONN @p conn is not connected
2371+
* @retval -ENOMEM Could not allocated memory for the request
2372+
* @retval -ENOEXEC Unexpected scan or GATT error
23532373
*/
23542374
int bt_bap_broadcast_assistant_scan_stop(struct bt_conn *conn);
23552375

@@ -2410,7 +2430,12 @@ struct bt_bap_broadcast_assistant_add_src_param {
24102430
* @param conn Connection to the server.
24112431
* @param param Parameter struct.
24122432
*
2413-
* @return Error value. 0 on success, GATT error or ERRNO on fail.
2433+
* @retval 0 Success
2434+
* @retval -EINVAL @p conn is NULL or %p conn has not done discovery or if @p param is invalid
2435+
* @retval -EBUSY Another operation is already in progress for this @p conn
2436+
* @retval -ENOTCONN @p conn is not connected
2437+
* @retval -ENOMEM Could not allocated memory for the request
2438+
* @retval -ENOEXEC Unexpected scan or GATT error
24142439
*/
24152440
int bt_bap_broadcast_assistant_add_src(
24162441
struct bt_conn *conn, const struct bt_bap_broadcast_assistant_add_src_param *param);
@@ -2443,7 +2468,12 @@ struct bt_bap_broadcast_assistant_mod_src_param {
24432468
* @param conn Connection to the server.
24442469
* @param param Parameter struct.
24452470
*
2446-
* @return Error value. 0 on success, GATT error or ERRNO on fail.
2471+
* @retval 0 Success
2472+
* @retval -EINVAL @p conn is NULL or %p conn has not done discovery or if @p param is invalid
2473+
* @retval -EBUSY Another operation is already in progress for this @p conn
2474+
* @retval -ENOTCONN @p conn is not connected
2475+
* @retval -ENOMEM Could not allocated memory for the request
2476+
* @retval -ENOEXEC Unexpected scan or GATT error
24472477
*/
24482478
int bt_bap_broadcast_assistant_mod_src(
24492479
struct bt_conn *conn, const struct bt_bap_broadcast_assistant_mod_src_param *param);
@@ -2455,7 +2485,12 @@ int bt_bap_broadcast_assistant_mod_src(
24552485
* @param src_id Source ID of the receive state.
24562486
* @param broadcast_code The broadcast code.
24572487
*
2458-
* @return Error value. 0 on success, GATT error or ERRNO on fail.
2488+
* @retval 0 Success
2489+
* @retval -EINVAL @p conn is NULL or %p conn has not done discovery or @p src_id is invalid
2490+
* @retval -EBUSY Another operation is already in progress for this @p conn
2491+
* @retval -ENOTCONN @p conn is not connected
2492+
* @retval -ENOMEM Could not allocated memory for the request
2493+
* @retval -ENOEXEC Unexpected scan or GATT error
24592494
*/
24602495
int bt_bap_broadcast_assistant_set_broadcast_code(
24612496
struct bt_conn *conn, uint8_t src_id,
@@ -2467,7 +2502,12 @@ int bt_bap_broadcast_assistant_set_broadcast_code(
24672502
* @param conn Connection to the server.
24682503
* @param src_id Source ID of the receive state.
24692504
*
2470-
* @return Error value. 0 on success, GATT error or ERRNO on fail.
2505+
* @retval 0 Success
2506+
* @retval -EINVAL @p conn is NULL or %p conn has not done discovery or @p src_id is invalid
2507+
* @retval -EBUSY Another operation is already in progress for this @p conn
2508+
* @retval -ENOTCONN @p conn is not connected
2509+
* @retval -ENOMEM Could not allocated memory for the request
2510+
* @retval -ENOEXEC Unexpected scan or GATT error
24712511
*/
24722512
int bt_bap_broadcast_assistant_rem_src(struct bt_conn *conn, uint8_t src_id);
24732513

@@ -2478,7 +2518,12 @@ int bt_bap_broadcast_assistant_rem_src(struct bt_conn *conn, uint8_t src_id);
24782518
* @param idx The index of the receive start (0 up to the value from
24792519
* bt_bap_broadcast_assistant_discover_cb)
24802520
*
2481-
* @return Error value. 0 on success, GATT error or ERRNO on fail.
2521+
* @retval 0 Success
2522+
* @retval -EINVAL @p conn is NULL or %p conn has not done discovery or @p src_id is invalid
2523+
* @retval -EBUSY Another operation is already in progress for this @p conn
2524+
* @retval -ENOTCONN @p conn is not connected
2525+
* @retval -ENOMEM Could not allocated memory for the request
2526+
* @retval -ENOEXEC Unexpected scan or GATT error
24822527
*/
24832528
int bt_bap_broadcast_assistant_read_recv_state(struct bt_conn *conn, uint8_t idx);
24842529

0 commit comments

Comments
 (0)