fhub: add bt_adapter_get_hci_address API 71/282271/1
authorAyush Garg <ayush.garg@samsung.com>
Thu, 29 Sep 2022 06:53:42 +0000 (12:23 +0530)
committerAyush Garg <ayush.garg@samsung.com>
Thu, 29 Sep 2022 07:02:30 +0000 (12:32 +0530)
Change-Id: I4b5d35b48e53e031a2f6fc0bfd4e7b4794bb8c97
Signed-off-by: shss-choi <shss.choi@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
include/bluetooth_internal.h
src/bluetooth-adapter.c
tests/test/bt_unit_test.c

index cd3e823..de47431 100644 (file)
@@ -5447,6 +5447,35 @@ int bt_mesh_model_get_publication(bt_mesh_model_h model,
  */
 
 
+/**
+ * @addtogroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE
+ * @{
+ */
+
+/**
+ * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE
+ * @brief Gets the address from hci when adapter is disabled
+ * @since_tizen 7.0
+ * @privlevel platform
+ * @privilege %http://tizen.org/privilege/bluetooth.admin
+ * @remarks The @a address must be released with free() by you.
+ *
+ * @param[out] address The device address of local Bluetooth adapter
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #BT_ERROR_NONE Successful
+ * @retval #BT_ERROR_INVALID_PARAMETER  Invalid parameter
+ * @retval #BT_ERROR_OUT_OF_MEMORY  Out of memory
+ * @retval #BT_ERROR_OPERATION_FAILED Operation failed
+ * @retval #BT_ERROR_NOT_SUPPORTED  Not supported
+ */
+int bt_adapter_get_hci_address(char **address);
+
+/**
+ * @}
+ */
+
+
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */
index b076e28..82f6188 100644 (file)
@@ -41,6 +41,9 @@
        BT_CHECK_SUPPORTED_FEATURE(BT_FEATURE_LE_5_0); \
 }
 
+#define BT_MAC_ADD_LENGTH 17
+#define BT_MAC_ADD_PATH "/sys/class/bluetooth/hci0/address"
+
 
 static bt_scan_filter_h pxp_linkloss_alert_filter;
 static bt_scan_filter_h pxp_immediate_alert_filter;
@@ -230,6 +233,46 @@ int bt_adapter_get_address(char **address)
        return BT_ERROR_NONE;
 }
 
+int bt_adapter_get_hci_address(char **address)
+{
+       BT_CHECK_SUPPORTED_FEATURE(BT_FEATURE_COMMON);
+       BT_CHECK_INPUT_PARAMETER(address);
+
+       if (!TIZEN_FEATURE_FHUB_REFERENCE) {
+               BT_INFO("Not a FHUB device");
+               return BT_ERROR_NOT_SUPPORTED;
+       }
+
+       FILE *fp = NULL;
+       char buf[BT_MAC_ADD_LENGTH +1];
+       if (0 == access(BT_MAC_ADD_PATH, F_OK))
+               fp = fopen(BT_MAC_ADD_PATH, "r");
+
+       if (fp == NULL) {
+               BT_ERR("Failed to open file %s\n", BT_MAC_ADD_PATH);
+               return BT_ERROR_OPERATION_FAILED;
+       }
+
+       if (fgets(buf, sizeof(buf), fp) == NULL) {
+               BT_ERR("Failed to get MAC info from %s\n", BT_MAC_ADD_PATH);
+               fclose(fp);
+               return BT_ERROR_OPERATION_FAILED;
+       }
+
+       BT_DBG("%s : %s", BT_MAC_ADD_PATH, buf);
+       *address = (char *)g_try_malloc0(BT_MAC_ADD_LENGTH + 1);
+       if (*address == NULL) {
+               BT_ERR("malloc() failed");
+               fclose(fp);
+               return BT_ERROR_OUT_OF_MEMORY;
+       }
+
+       g_strlcpy(*address, buf, BT_MAC_ADD_LENGTH + 1);
+       BT_DBG("%s", *address);
+       fclose(fp);
+       return BT_ERROR_NONE;
+}
+
 /* LCOV_EXCL_START */
 int bt_adapter_get_version(char **version)
 {
index 27dbe2a..96ad6ab 100644 (file)
@@ -4713,6 +4713,7 @@ int test_input_callback(void *data)
                        char *firmware = NULL;
                        char *stack_version = NULL;
                        char *profiles = NULL;
+                       char *local_bt_mac = NULL;
 
                        ret = bt_adapter_get_local_info(&chipset, &firmware,
                                &stack_version, &profiles);
@@ -4726,6 +4727,16 @@ int test_input_callback(void *data)
                                g_free(stack_version);
                                g_free(profiles);
                        }
+
+                       if (TIZEN_FEATURE_FHUB_REFERENCE) {
+                               ret = bt_adapter_get_hci_address(&local_bt_mac);
+                               if (ret < BT_ERROR_NONE)
+                                       TC_PRT("get_hci_address : returns %s\n", __bt_get_error_message(ret));
+                               else {
+                                       TC_PRT("Local BT mac: [%s]", local_bt_mac);
+                                       g_free(local_bt_mac);
+                               }
+                       }
                        break;
                }