Skip to content

Commit 23477a9

Browse files
committed
pbdrv/bluetooth: Add cancel & disconnect.
This commit adds support for rfcomm socket disconnection and cancellation. It also unifies some of the error checking in the rfcomm listen and connect functions in btstack.
1 parent 01d55dc commit 23477a9

4 files changed

Lines changed: 176 additions & 111 deletions

File tree

lib/pbio/drv/bluetooth/bluetooth.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,7 @@ void pbdrv_bluetooth_cancel_operation_request(void) {
548548
#if PBDRV_CONFIG_BLUETOOTH_NUM_CLASSIC_CONNECTIONS
549549
// Revisit: Cancel all.
550550
pbdrv_bluetooth_classic_task_context.cancel = true;
551+
pbdrv_bluetooth_rfcomm_cancel_connection();
551552
#endif // PBDRV_CONFIG_BLUETOOTH_NUM_CLASSIC_CONNECTIONS
552553
}
553554

@@ -684,6 +685,8 @@ pbio_error_t pbdrv_bluetooth_close_user_tasks(pbio_os_state_t *state, pbio_os_ti
684685
// Requests peripheral operations to cancel, if they support it.
685686
pbdrv_bluetooth_cancel_operation_request();
686687

688+
pbdrv_bluetooth_rfcomm_disconnect_all();
689+
687690
for (peri_index = 0; peri_index < PBDRV_CONFIG_BLUETOOTH_NUM_PERIPHERALS; peri_index++) {
688691
peri = pbdrv_bluetooth_peripheral_get_by_index(peri_index);
689692

lib/pbio/drv/bluetooth/bluetooth.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,17 @@ typedef struct {
9797

9898
pbio_error_t pbdrv_bluetooth_inquiry_scan_func(pbio_os_state_t *state, void *context);
9999

100+
// The following functions are defined in each Bluetooth implementation that
101+
// supports RFCOMM sockets.
102+
103+
// Cancels all pending connection attempts. Called e.g. when the user interrupts
104+
// execution to drop into the debug REPL.
105+
void pbdrv_bluetooth_rfcomm_cancel_connection();
106+
107+
// Disconnects all active RFCOMM connections and cleans up all sockets. Called
108+
// during user program termination.
109+
void pbdrv_bluetooth_rfcomm_disconnect_all();
110+
100111
#endif // PBDRV_CONFIG_BLUETOOTH
101112

102113
#endif // _INTERNAL_PBDRV_BLUETOOTH_H_

0 commit comments

Comments
 (0)