@@ -128,14 +128,16 @@ bool
128128BLEPeripheralRole::disconnect ()
129129{
130130 BleStatus status = BLE_STATUS_WRONG_STATE;
131+ int err;
131132
132133 if (BLE_PERIPH_STATE_CONNECTED == _state)
133134 {
134135 struct bt_conn *central_conn = bt_conn_lookup_addr_le (_central.bt_le_address ());
135136 if (NULL != central_conn)
136137 {
137- status = bt_conn_disconnect (central_conn,
138- BT_HCI_ERR_REMOTE_USER_TERM_CONN);
138+ err = bt_conn_disconnect (central_conn,
139+ BT_HCI_ERR_REMOTE_USER_TERM_CONN);
140+ status = errorno_to_ble_status (err);
139141 bt_conn_unref (central_conn);
140142 }
141143 }
@@ -246,6 +248,9 @@ void BLEPeripheralRole::handleConnectEvent(struct bt_conn *conn, uint8_t err)
246248 // Call the CB
247249 if (_event_handlers[BLEConnected])
248250 _event_handlers[BLEConnected](_central);
251+
252+ if (BLE_PERIPH_STATE_ADVERTISING == _state)
253+ _state = BLE_PERIPH_STATE_CONNECTED;
249254}
250255
251256
@@ -263,6 +268,9 @@ void BLEPeripheralRole::handleDisconnectEvent(struct bt_conn *conn, uint8_t reas
263268 {
264269 bt_conn_unref (central_conn);
265270 }
271+
272+ if (BLE_PERIPH_STATE_CONNECTED == _state)
273+ _state = BLE_PERIPH_STATE_ADVERTISING;
266274}
267275
268276void BLEPeripheralRole::handleParamUpdated (struct bt_conn *conn,
0 commit comments