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

[ESP32] Fix the threading issue in nimble #29180

Merged
merged 3 commits into from
Nov 6, 2023
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
6 changes: 6 additions & 0 deletions src/include/platform/CHIPDeviceEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,12 @@ enum InternalEventTypes
kCHIPoBLEUnsubscribe,
kCHIPoBLEWriteReceived,
kCHIPoBLEIndicateConfirm,

/**
* Post this event in case of a BLE connection error. This event should be posted
* if the BLE central disconnects without unsubscribing from the BLE characteristic.
* This event should populate CHIPoBLEConnectionError structure.
*/
kCHIPoBLEConnectionError,
kCHIPoBLENotifyConfirm
};
Expand Down
9 changes: 8 additions & 1 deletion src/platform/ESP32/nimble/BLEManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1273,6 +1273,8 @@ CHIP_ERROR BLEManagerImpl::HandleGAPDisconnect(struct ble_gap_event * gapEvent)
peer_delete(gapEvent->disconnect.conn.conn_handle);
#endif

// There can be a case where the BLE central disconnects without unsubscribing from the BLE characteristic.
// In such situations, it is necessary to clear the subscription and post a connection error event.
if (UnsetSubscribed(gapEvent->disconnect.conn.conn_handle))
{
CHIP_ERROR disconReason;
Expand All @@ -1288,7 +1290,12 @@ CHIP_ERROR BLEManagerImpl::HandleGAPDisconnect(struct ble_gap_event * gapEvent)
disconReason = BLE_ERROR_CHIPOBLE_PROTOCOL_ABORT;
break;
}
HandleConnectionError(gapEvent->disconnect.conn.conn_handle, disconReason);

ChipDeviceEvent connectionErrorEvent;
connectionErrorEvent.Type = DeviceEventType::kCHIPoBLEConnectionError;
connectionErrorEvent.CHIPoBLEConnectionError.ConId = gapEvent->disconnect.conn.conn_handle;
connectionErrorEvent.CHIPoBLEConnectionError.Reason = disconReason;
ReturnErrorOnFailure(PlatformMgr().PostEvent(&connectionErrorEvent));
}

ChipDeviceEvent disconnectEvent;
Expand Down
Loading