Skip to content

Commit 36f1883

Browse files
authored
Merge pull request #202 from NordicSemiconductor/improvement/insuf-auth
New disconnection reason: Insufficient Authentication
2 parents 58b621e + a556cc3 commit 36f1883

File tree

2 files changed

+15
-4
lines changed
  • client-android/src/main/java/no/nordicsemi/kotlin/ble/client/android/internal
  • core/src/main/java/no/nordicsemi/kotlin/ble/core

2 files changed

+15
-4
lines changed

client-android/src/main/java/no/nordicsemi/kotlin/ble/client/android/internal/Mapper.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ internal fun Int.toConnectionState(status: Int): ConnectionState = when (this) {
8585
private fun Int.toDisconnectionReason(): ConnectionState.Disconnected.Reason = when (this) {
8686
BluetoothGatt.GATT_SUCCESS -> ConnectionState.Disconnected.Reason.Success
8787
0x08 /* GATT_CONN_TIMEOUT */ -> ConnectionState.Disconnected.Reason.LinkLoss
88+
0x05 /* GATT_INSUFFICIENT_AUTHENTICATION */ -> ConnectionState.Disconnected.Reason.InsufficientAuthentication
8889
0x13 /* GATT_CONN_TERMINATE_PEER_USER */ -> ConnectionState.Disconnected.Reason.TerminatePeerUser
8990
0x16 /* GATT_CONN_TERMINATE_LOCAL_HOST */ -> ConnectionState.Disconnected.Reason.TerminateLocalHost
9091
else -> ConnectionState.Disconnected.Reason.Unknown(this)

core/src/main/java/no/nordicsemi/kotlin/ble/core/ConnectionState.kt

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,11 @@ sealed class ConnectionState {
5050
data object Disconnecting: ConnectionState()
5151

5252
/**
53-
* Device is disconnected.
53+
* Device has disconnected.
5454
*
55-
* @param reason Reason of disconnection, or _null_ if no connection attempt was made.
55+
* This state may be immediately followed by [Closed] state.
56+
*
57+
* @param reason Reason of disconnection.
5658
*/
5759
data class Disconnected(val reason: Reason): ConnectionState() {
5860

@@ -68,8 +70,16 @@ sealed class ConnectionState {
6870
data class Unknown(val status: Int): Reason()
6971
/** The local device initiated disconnection. */
7072
data object TerminateLocalHost: Reason()
71-
/** The remote device initiated graceful disconnection. */
73+
/** The remote device initiated graceful disconnection. */
7274
data object TerminatePeerUser: Reason()
75+
/**
76+
* Insufficient authentication.
77+
*
78+
* This error is returned when the Android device tries to enable security on a
79+
* device that had its bond information removed. Remove bond information on the phone
80+
* and retry.
81+
*/
82+
data object InsufficientAuthentication: Reason()
7383
/** The device got out of range or has turned off. */
7484
data object LinkLoss: Reason()
7585
/** Connection attempt was cancelled. */
@@ -81,7 +91,7 @@ sealed class ConnectionState {
8191
* background connection list. RPA is allowed for direct connection, as such request
8292
* times out after a short period of time.
8393
*
84-
* See: https://cs.android.com/android/platform/superproject/main/+/main:packages/modules/Bluetooth/system/stack/gatt/gatt_api.cc;l=1450
94+
* See: [Source code](https://cs.android.com/android/platform/superproject/main/+/main:packages/modules/Bluetooth/system/stack/gatt/gatt_api.cc;l=1498)
8595
*/
8696
data object UnsupportedAddress: Reason()
8797
/**

0 commit comments

Comments
 (0)