Use HCI error code instead of MGMT disconnection reason 62/286562/1 accepted/tizen/unified/20230111.174532
authorDohyun Pyun <dh79.pyun@samsung.com>
Mon, 20 Jun 2022 08:37:27 +0000 (17:37 +0900)
committerWootak Jung <wootak.jung@samsung.com>
Tue, 10 Jan 2023 02:00:37 +0000 (11:00 +0900)
Change-Id: If715b847372b0be82ebdd8404a8b2a39bca01970
Signed-off-by: Dohyun Pyun <dh79.pyun@samsung.com>
src/adapter.c

index e9b11b6..d0d79c6 100644 (file)
@@ -15230,6 +15230,39 @@ static int adapter_unregister(struct btd_adapter *adapter)
        return 0;
 }
 
+#ifdef TIZEN_FEATURE_BLUEZ_MODIFY
+/* ---- HCI Error Codes ---- */
+#define HCI_ERROR_AUTH_FAILURE         0x05
+#define HCI_ERROR_PIN_OR_KEY_MISSING   0x06
+#define HCI_ERROR_MEMORY_EXCEEDED      0x07
+#define HCI_ERROR_CONNECTION_TIMEOUT   0x08
+#define HCI_ERROR_REJ_LIMITED_RESOURCES        0x0d
+#define HCI_ERROR_REJ_BAD_ADDR         0x0f
+#define HCI_ERROR_REMOTE_USER_TERM     0x13
+#define HCI_ERROR_REMOTE_LOW_RESOURCES 0x14
+#define HCI_ERROR_REMOTE_POWER_OFF     0x15
+#define HCI_ERROR_LOCAL_HOST_TERM      0x16
+#define HCI_ERROR_PAIRING_NOT_ALLOWED  0x18
+#define HCI_ERROR_INVALID_LL_PARAMS    0x1e
+#define HCI_ERROR_UNSPECIFIED          0x1f
+#define HCI_ERROR_ADVERTISING_TIMEOUT  0x3c
+
+static uint8_t mgmt_to_hci_reason(uint8_t err)
+{
+       switch (err) {
+       case MGMT_DEV_DISCONN_TIMEOUT:
+               return HCI_ERROR_CONNECTION_TIMEOUT;
+       case MGMT_DEV_DISCONN_REMOTE:
+               return HCI_ERROR_REMOTE_USER_TERM;
+       case MGMT_DEV_DISCONN_LOCAL_HOST:
+               return HCI_ERROR_LOCAL_HOST_TERM;
+       default:
+               error("No match MGMT error");
+               return err;
+       }
+}
+#endif
+
 static void disconnected_callback(uint16_t index, uint16_t length,
                                        const void *param, void *user_data)
 {
@@ -15248,7 +15281,12 @@ static void disconnected_callback(uint16_t index, uint16_t length,
        else
                reason = ev->reason;
 
+#ifdef TIZEN_FEATURE_BLUEZ_MODIFY
+        /* Use HCI error code instead of MGMT disconnection reason */
+       dev_disconnected(adapter, &ev->addr, mgmt_to_hci_reason(reason));
+#else
        dev_disconnected(adapter, &ev->addr, reason);
+#endif
 }
 
 static void connected_callback(uint16_t index, uint16_t length,