From: seungku kim Date: Mon, 8 Jun 2015 08:21:53 +0000 (+0900) Subject: 3.0 specific patch: synchronize tizen 2.4 code X-Git-Tag: submit/tizen_mobile/20150609.051101~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F09%2F40709%2F1;p=platform%2Fcore%2Fapi%2Fbluetooth.git 3.0 specific patch: synchronize tizen 2.4 code Enable to build after tizen 2.4 code sync. Change-Id: Ic138fdd9fc60fe9fdb78b17a90621c5fe0549dd7 --- diff --git a/TC/testcase/utc_network_bluetooth_adapter_positive.c b/TC/testcase/utc_network_bluetooth_adapter_positive.c index 6ad6815..7a6ac13 100755 --- a/TC/testcase/utc_network_bluetooth_adapter_positive.c +++ b/TC/testcase/utc_network_bluetooth_adapter_positive.c @@ -153,6 +153,7 @@ int get_value_from_file(void) return 0; } } + fclose(fp); return -1; } diff --git a/TC/testcase/utc_network_bluetooth_audio_positive.c b/TC/testcase/utc_network_bluetooth_audio_positive.c index d1fffbc..186bdb2 100755 --- a/TC/testcase/utc_network_bluetooth_audio_positive.c +++ b/TC/testcase/utc_network_bluetooth_audio_positive.c @@ -148,6 +148,7 @@ int get_value_from_file(void) return 0; } } + fclose(fp); return -1; } diff --git a/TC/testcase/utc_network_bluetooth_device_positive.c b/TC/testcase/utc_network_bluetooth_device_positive.c index 1ee789e..631746e 100755 --- a/TC/testcase/utc_network_bluetooth_device_positive.c +++ b/TC/testcase/utc_network_bluetooth_device_positive.c @@ -135,6 +135,7 @@ int get_value_from_file(void) return 0; } } + fclose(fp); return -1; } diff --git a/TC/testcase/utc_network_bluetooth_gatt_positive.c b/TC/testcase/utc_network_bluetooth_gatt_positive.c index b45ecca..3c4730f 100755 --- a/TC/testcase/utc_network_bluetooth_gatt_positive.c +++ b/TC/testcase/utc_network_bluetooth_gatt_positive.c @@ -105,9 +105,11 @@ int get_value_from_file(void) if (strcasecmp(token, "BT_ADDR_LE") == 0) { token = strtok(NULL, "="); remote_address = strdup(token); + fclose(fp); return 0; } } + fclose(fp); return -1; } diff --git a/TC/testcase/utc_network_bluetooth_opp-client_positive.c b/TC/testcase/utc_network_bluetooth_opp-client_positive.c index b50baea..580a788 100755 --- a/TC/testcase/utc_network_bluetooth_opp-client_positive.c +++ b/TC/testcase/utc_network_bluetooth_opp-client_positive.c @@ -99,6 +99,7 @@ int get_value_from_file(void) return 0; } } + fclose(fp); return -1; } diff --git a/TC/testcase/utc_network_bluetooth_service_search_positive.c b/TC/testcase/utc_network_bluetooth_service_search_positive.c index b0c5e70..e6219b6 100755 --- a/TC/testcase/utc_network_bluetooth_service_search_positive.c +++ b/TC/testcase/utc_network_bluetooth_service_search_positive.c @@ -97,6 +97,7 @@ int get_value_from_file(void) return 0; } } + fclose(fp); return -1; } diff --git a/TC/testcase/utc_network_bluetooth_socket_positive.c b/TC/testcase/utc_network_bluetooth_socket_positive.c index acaf2f9..7c71338 100755 --- a/TC/testcase/utc_network_bluetooth_socket_positive.c +++ b/TC/testcase/utc_network_bluetooth_socket_positive.c @@ -117,6 +117,7 @@ int get_value_from_file(void) return 0; } } + fclose(fp); return -1; } diff --git a/include/bluetooth_private.h b/include/bluetooth_private.h index b600547..768d768 100644 --- a/include/bluetooth_private.h +++ b/include/bluetooth_private.h @@ -103,11 +103,13 @@ typedef enum BT_EVENT_GATT_CLIENT_READ_DESCRIPTOR, /**< GATT descriptor value read callback */ BT_EVENT_GATT_CLIENT_WRITE_DESCRIPTOR, /**< GATT descriptor value write callback */ BT_EVENT_GATT_SERVER_READ_REQUESTED, /**< GATT Characteristic/Descriptor Read Requested callback*/ +#ifdef BT_ENABLE_LEGACY_GATT_CLIENT BT_EVENT_GATT_CLIENT_CHARACTERISTIC_DISCOVERED_LEGACY, /**< GATT characteristic discovered callback */ BT_EVENT_GATT_CLIENT_CHARACTERISTIC_DESCRIPTOR_DISCOVERED_LEGACY, /**< GATT characteristic descriptor discovered callback */ BT_EVENT_GATT_CLIENT_VALUE_CHANGED_LEGACY, /**< GATT characteristic value changed callback */ BT_EVENT_GATT_CLIENT_READ_CHARACTERISTIC_LEGACY, /**< GATT characteristic value read callback */ BT_EVENT_GATT_CLIENT_WRITE_CHARACTERISTIC_LEGACY, /**< GATT characteristic value write callback */ +#endif BT_EVENT_ADVERTISING_STATE_CHANGED, /**< Advertising state changed callback */ BT_EVENT_MANUFACTURER_DATA_CHANGED, /**< Manufacturer data changed callback */ BT_EVENT_CONNECTABLE_CHANGED_EVENT, /**< Adapter connectable changed callback */ @@ -471,12 +473,16 @@ void _bt_hid_event_proxy(int event, hid_event_param_t *param, void *user_data); void _bt_adapter_le_invoke_advertising_state_cb(int handle, int result, bt_adapter_le_advertising_state_e adv_state); +#ifdef BT_ENABLE_LEGACY_GATT_CLIENT bool _bt_gatt_is_legacy_client_mode(void); +#endif const GSList* _bt_gatt_get_client_list(void); const GSList* _bt_gatt_get_server_list(void); +int _bt_gatt_client_update_all(bt_gatt_client_h client); + /* HID device related type */ typedef struct { diff --git a/packaging/capi-network-bluetooth.spec b/packaging/capi-network-bluetooth.spec index a7a7333..66766f6 100644 --- a/packaging/capi-network-bluetooth.spec +++ b/packaging/capi-network-bluetooth.spec @@ -22,7 +22,6 @@ BuildRequires: pkgconfig(privacy-manager-client) BuildRequires: cmake - %description Network Bluetooth Framework diff --git a/src/bluetooth-adapter.c b/src/bluetooth-adapter.c index 317fed7..36ec2f9 100644 --- a/src/bluetooth-adapter.c +++ b/src/bluetooth-adapter.c @@ -760,6 +760,7 @@ int bt_adapter_set_device_discovery_state_changed_cb(bt_adapter_device_discovery return ret; } +#ifndef TIZEN_WEARABLE int bt_adapter_le_set_device_discovery_state_changed_cb(bt_adapter_le_device_discovery_state_changed_cb callback, void *user_data) { BT_CHECK_LE_SUPPORT(); @@ -770,6 +771,7 @@ int bt_adapter_le_set_device_discovery_state_changed_cb(bt_adapter_le_device_dis _bt_set_cb(BT_EVENT_LE_DEVICE_DISCOVERY_STATE_CHANGED, callback, user_data); return BT_ERROR_NONE; } +#endif int bt_adapter_unset_state_changed_cb(void) { @@ -835,6 +837,7 @@ int bt_adapter_unset_device_discovery_state_changed_cb(void) return BT_ERROR_NONE; } +#ifndef TIZEN_WEARABLE int bt_adapter_le_unset_device_discovery_state_changed_cb(void) { BT_CHECK_LE_SUPPORT(); @@ -843,6 +846,7 @@ int bt_adapter_le_unset_device_discovery_state_changed_cb(void) _bt_le_adapter_deinit(); return BT_ERROR_NONE; } +#endif int bt_adapter_start_device_discovery(void) { @@ -889,6 +893,7 @@ int bt_adapter_is_discovering(bool *is_discovering) } } +#ifndef TIZEN_WEARABLE int bt_adapter_le_start_device_discovery(void) { int error_code = BT_ERROR_NONE; @@ -933,6 +938,7 @@ int bt_adapter_le_is_discovering(bool *is_discovering) return ret; } } +#endif int bt_adapter_get_local_oob_data(unsigned char **hash, unsigned char **randomizer, int *hash_len, int *randomizer_len) @@ -1176,11 +1182,13 @@ int bt_adapter_le_destroy_advertiser(bt_advertiser_h advertiser) _bt_unset_cb(BT_EVENT_ADVERTISING_STATE_CHANGED); - error_code = bluetooth_set_advertising(FALSE); + error_code = bluetooth_set_advertising(__adv->handle, FALSE); ret = _bt_get_error_code(error_code); if (ret != BT_ERROR_NONE) BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + advertiser_list = g_slist_remove(advertiser_list, __adv); + /* Free advertising data */ g_free(__adv->adv_data); g_free(__adv->scan_rsp_data); @@ -1874,6 +1882,7 @@ int bt_adapter_le_clear_advertising_data(bt_advertiser_h advertiser, return ret; } +#ifndef TIZEN_WEARABLE int bt_adapter_le_start_advertising(bt_advertiser_h advertiser, bt_adapter_le_advertising_params_s *adv_params, bt_adapter_le_advertising_state_changed_cb cb, void *user_data) @@ -1891,7 +1900,7 @@ int bt_adapter_le_start_advertising(bt_advertiser_h advertiser, if (__adv->adv_data_len > 0 && __adv->adv_data) { memcpy(adv.data, __adv->adv_data, __adv->adv_data_len); - error_code = bluetooth_set_advertising_data(&adv, __adv->adv_data_len); + error_code = bluetooth_set_advertising_data(__adv->handle, &adv, __adv->adv_data_len); ret = _bt_get_error_code(error_code); if (ret != BT_ERROR_NONE) { BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); @@ -1901,7 +1910,7 @@ int bt_adapter_le_start_advertising(bt_advertiser_h advertiser, if (__adv->scan_rsp_data_len > 0 && __adv->scan_rsp_data) { memcpy(resp.data, __adv->scan_rsp_data, __adv->scan_rsp_data_len); - error_code = bluetooth_set_scan_response_data(&resp, __adv->scan_rsp_data_len); + error_code = bluetooth_set_scan_response_data(__adv->handle, &resp, __adv->scan_rsp_data_len); ret = _bt_get_error_code(error_code); if (ret != BT_ERROR_NONE) { BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); @@ -1910,13 +1919,13 @@ int bt_adapter_le_start_advertising(bt_advertiser_h advertiser, } if (adv_params == NULL) { - error_code = bluetooth_set_advertising(TRUE); + error_code = bluetooth_set_advertising(__adv->handle, TRUE); } else { param.interval_min = adv_params->interval_min; param.interval_max = adv_params->interval_max; param.filter_policy = BT_ADAPTER_LE_ADVERTISING_FILTER_DEFAULT; param.type = BT_ADAPTER_LE_ADVERTISING_CONNECTABLE; - error_code = bluetooth_set_custom_advertising(TRUE, ¶m); + error_code = bluetooth_set_custom_advertising(__adv->handle, TRUE, ¶m); } ret = _bt_get_error_code(error_code); @@ -1929,16 +1938,18 @@ int bt_adapter_le_start_advertising(bt_advertiser_h advertiser, return ret; } +#endif int bt_adapter_le_stop_advertising(bt_advertiser_h advertiser) { int ret = BT_ERROR_NONE; + bt_advertiser_s *__adv = (bt_advertiser_s *)advertiser; BT_CHECK_LE_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(advertiser); - ret = _bt_get_error_code(bluetooth_set_advertising(FALSE)); + ret = _bt_get_error_code(bluetooth_set_advertising(__adv->handle, FALSE)); if (ret != BT_ERROR_NONE) { BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); } @@ -1963,7 +1974,7 @@ int bt_adapter_le_start_advertising_new(bt_advertiser_h advertiser, if (__adv->adv_data_len > 0 && __adv->adv_data) { memcpy(adv.data, __adv->adv_data, __adv->adv_data_len); - error_code = bluetooth_set_advertising_data(&adv, __adv->adv_data_len); + error_code = bluetooth_set_advertising_data(__adv->handle, &adv, __adv->adv_data_len); ret = _bt_get_error_code(error_code); if (ret != BT_ERROR_NONE) { BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); @@ -1973,7 +1984,7 @@ int bt_adapter_le_start_advertising_new(bt_advertiser_h advertiser, if (__adv->scan_rsp_data_len > 0 && __adv->scan_rsp_data) { memcpy(resp.data, __adv->scan_rsp_data, __adv->scan_rsp_data_len); - error_code = bluetooth_set_scan_response_data(&resp, __adv->scan_rsp_data_len); + error_code = bluetooth_set_scan_response_data(__adv->handle, &resp, __adv->scan_rsp_data_len); ret = _bt_get_error_code(error_code); if (ret != BT_ERROR_NONE) { BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); @@ -1992,7 +2003,7 @@ int bt_adapter_le_start_advertising_new(bt_advertiser_h advertiser, param.interval_max = interval; param.filter_policy = __adv->adv_params.filter_policy; param.type = __adv->adv_params.type; - error_code = bluetooth_set_custom_advertising(TRUE, ¶m); + error_code = bluetooth_set_custom_advertising(__adv->handle, TRUE, ¶m); ret = _bt_get_error_code(error_code); if (ret != BT_ERROR_NONE) { @@ -2029,37 +2040,78 @@ void _bt_adapter_le_invoke_advertising_state_cb(int handle, int result, bt_adapt int bt_adapter_le_set_advertising_mode(bt_advertiser_h advertiser, bt_adapter_le_advertising_mode_e mode) { + int error_code = BT_ERROR_NONE; + bt_advertiser_s *__adv = (bt_advertiser_s *)advertiser; + BT_CHECK_LE_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(advertiser); - /* Will implement after synch bluetooth-frwk */ - - return BT_ERROR_NOT_SUPPORTED; + if (mode < BT_ADAPTER_LE_ADVERTISING_MODE_BALANCED || + mode > BT_ADAPTER_LE_ADVERTISING_MODE_LOW_ENERGY) + return BT_ERROR_INVALID_PARAMETER; + + error_code = _bt_get_error_code(bluetooth_check_privilege_advertising_parameter()); + if (error_code != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), error_code); + return BT_ERROR_PERMISSION_DENIED; + } + + // TODO : Before set the mode, check the inprogress status + __adv->adv_params.mode = mode; + return error_code; } int bt_adapter_le_set_advertising_filter_policy(bt_advertiser_h advertiser, bt_adapter_le_advertising_filter_policy_e filter_policy) { + int error_code = BT_ERROR_NONE; + bt_advertiser_s *__adv = (bt_advertiser_s *)advertiser; + BT_CHECK_LE_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(advertiser); - /* Will implement after synch bluetooth-frwk */ - - return BT_ERROR_NOT_SUPPORTED; + if (filter_policy < BT_ADAPTER_LE_ADVERTISING_FILTER_DEFAULT || + filter_policy > BT_ADAPTER_LE_ADVERTISING_FILTER_ALLOW_SCAN_CONN_WL) + return BT_ERROR_INVALID_PARAMETER; + + error_code = _bt_get_error_code(bluetooth_check_privilege_advertising_parameter()); + if (error_code != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), error_code); + return BT_ERROR_PERMISSION_DENIED; + } + + // TODO : Before set the filter policy, check the inprogress status + __adv->adv_params.filter_policy = filter_policy; + + return error_code; } int bt_adapter_le_set_advertising_connectable(bt_advertiser_h advertiser, bool connectable) { + int error_code = BT_ERROR_NONE; + bt_advertiser_s *__adv = (bt_advertiser_s *)advertiser; + BT_CHECK_LE_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(advertiser); - /* Will implement after synch bluetooth-frwk */ - - return BT_ERROR_NOT_SUPPORTED; + error_code = _bt_get_error_code(bluetooth_check_privilege_advertising_parameter()); + if (error_code != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), error_code); + return BT_ERROR_PERMISSION_DENIED; + } + + if (connectable) + __adv->adv_params.type = BT_ADAPTER_LE_ADVERTISING_CONNECTABLE; + else + __adv->adv_params.type = BT_ADAPTER_LE_ADVERTISING_SCANNABLE; + + // TODO : Before set the type, check the inprogress status + + return error_code; } int bt_adapter_le_enable_privacy(bool enable_privacy) @@ -2077,7 +2129,7 @@ int bt_adapter_le_enable_privacy(bool enable_privacy) return error_code; } -#if 0 + static void __bt_adapter_le_convert_scan_filter(bluetooth_le_scan_filter_t *dest, bt_le_scan_filter_s *src) { int bit; @@ -2179,7 +2231,6 @@ static void __bt_adapter_le_convert_scan_filter(bluetooth_le_scan_filter_t *dest } } } -#endif int bt_adapter_le_start_scan(bt_adapter_le_scan_result_cb cb, void *user_data) { @@ -2966,32 +3017,64 @@ int bt_adapter_le_scan_filter_set_manufacturer_data_with_mask(bt_scan_filter_h s int bt_adapter_le_register_scan_filter(bt_scan_filter_h scan_filter) { + int error_code = BT_ERROR_NONE; + bt_le_scan_filter_s *__filter = (bt_le_scan_filter_s*)scan_filter; + bluetooth_le_scan_filter_t filter; + BT_CHECK_LE_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(scan_filter); + if (bluetooth_is_le_scanning() == TRUE) { + BT_ERR("NOW_IN_PROGRESS(0x%08x)", BT_ERROR_NOW_IN_PROGRESS); + return BT_ERROR_NOW_IN_PROGRESS; + } + + __bt_adapter_le_convert_scan_filter(&filter, __filter); - /* Will implement after synch bluetooth-frwk */ + error_code = _bt_get_error_code(bluetooth_register_scan_filter(&filter, &__filter->slot_id)); + if (error_code != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), error_code); + } - return BT_ERROR_NOT_SUPPORTED; + return error_code; } int bt_adapter_le_unregister_scan_filter(bt_scan_filter_h scan_filter) { + int error_code = BT_ERROR_NONE; + bt_le_scan_filter_s *__filter = (bt_le_scan_filter_s*)scan_filter; + BT_CHECK_LE_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(scan_filter); + if (bluetooth_is_le_scanning() == TRUE) { + BT_ERR("NOW_IN_PROGRESS(0x%08x)", BT_ERROR_NOW_IN_PROGRESS); + return BT_ERROR_NOW_IN_PROGRESS; + } - /* Will implement after synch bluetooth-frwk */ + error_code = _bt_get_error_code(bluetooth_unregister_scan_filter(__filter->slot_id)); + if (error_code != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), error_code); + } - return BT_ERROR_NOT_SUPPORTED; + return BT_ERROR_NONE; } int bt_adapter_le_unregister_all_scan_filters(void) { + int error_code = BT_ERROR_NONE; + BT_CHECK_LE_SUPPORT(); BT_CHECK_INIT_STATUS(); + if (bluetooth_is_le_scanning() == TRUE) { + BT_ERR("NOW_IN_PROGRESS(0x%08x)", BT_ERROR_NOW_IN_PROGRESS); + return BT_ERROR_NOW_IN_PROGRESS; + } - /* Will implement after synch bluetooth-frwk */ + error_code = _bt_get_error_code(bluetooth_unregister_all_scan_filters()); + if (error_code != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), error_code); + } - return BT_ERROR_NOT_SUPPORTED; + return BT_ERROR_NONE; } diff --git a/src/bluetooth-audio.c b/src/bluetooth-audio.c index f0a8acb..e2cdf63 100644 --- a/src/bluetooth-audio.c +++ b/src/bluetooth-audio.c @@ -132,6 +132,15 @@ int bt_audio_initialize(void) return error; } +#ifdef TIZEN_WEARABLE + error = bluetooth_hf_init(_bt_hf_event_proxy, NULL); + error = _bt_get_error_code(error); + if (BT_ERROR_NONE != error) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); + return error; + } +#endif + #ifndef TELEPHONY_DISABLED /* B2_3G */ error = bluetooth_telephony_init((void *)_bt_telephony_event_proxy, NULL); error = _bt_convert_telephony_error_code(error); @@ -153,6 +162,15 @@ int bt_audio_deinitialize(void) BT_CHECK_INIT_STATUS(); BT_CHECK_AUDIO_INIT_STATUS(); +#ifdef TIZEN_WEARABLE + error = bluetooth_hf_deinit(); + error = _bt_get_error_code(error); + if (BT_ERROR_NONE != error) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); + return error; + } +#endif + error = bluetooth_audio_deinit(); error = _bt_get_error_code(error); if (BT_ERROR_NONE != error) { @@ -211,6 +229,14 @@ int bt_audio_connect(const char *remote_address, bt_audio_profile_type_e type) case BT_AUDIO_PROFILE_TYPE_A2DP: error = bluetooth_av_connect(&addr_hex); break; +#ifdef TIZEN_WEARABLE + case BT_AUDIO_PROFILE_TYPE_AG: + error = bluetooth_hf_connect(&addr_hex); + break; +#endif + case BT_AUDIO_PROFILE_TYPE_A2DP_SINK: + error = bluetooth_av_source_connect(&addr_hex); + break; case BT_AUDIO_PROFILE_TYPE_ALL: default: error = bluetooth_audio_connect(&addr_hex); @@ -253,6 +279,14 @@ int bt_audio_disconnect(const char *remote_address, bt_audio_profile_type_e type case BT_AUDIO_PROFILE_TYPE_A2DP: error = bluetooth_av_disconnect(&addr_hex); break; +#ifdef TIZEN_WEARABLE + case BT_AUDIO_PROFILE_TYPE_AG: + error = bluetooth_hf_disconnect(&addr_hex); + break; +#endif + case BT_AUDIO_PROFILE_TYPE_A2DP_SINK: + error = bluetooth_av_source_disconnect(&addr_hex); + break; case BT_AUDIO_PROFILE_TYPE_ALL: default: error = bluetooth_audio_disconnect(&addr_hex); @@ -618,13 +652,24 @@ int bt_ag_unset_dtmf_transmitted_cb(void) int bt_ag_is_connected(bool *connected) { + int error; + gboolean is_connected = false; + BT_CHECK_HFP_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(connected); - /* Will implement after synch bluetooth-frwk */ + error = bluetooth_telephony_is_connected(&is_connected); + error = _bt_get_error_code(error); + if (error != BT_ERROR_NONE) + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); - return BT_ERROR_NOT_SUPPORTED; + if (is_connected) + *connected = true; + else + *connected = false; + + return error; } int bt_call_list_create(bt_call_list_h *list) diff --git a/src/bluetooth-common.c b/src/bluetooth-common.c index a7283bb..04848d9 100644 --- a/src/bluetooth-common.c +++ b/src/bluetooth-common.c @@ -52,10 +52,8 @@ static int __bt_get_bt_adapter_le_device_scan_info_s(bt_adapter_le_device_scan_r static void __bt_free_bt_adapter_le_device_scan_info_s(bt_adapter_le_device_scan_result_info_s *scan_info); static int __bt_get_bt_adapter_le_device_discovery_info_s(bt_adapter_le_device_discovery_info_s **le_discovery_info, bluetooth_le_device_info_t *source_info); static void __bt_free_bt_adapter_le_device_discovery_info_s(bt_adapter_le_device_discovery_info_s *discovery_info); -#if 0 static int __bt_gatt_client_update_characteristics(bt_gatt_handle_info_t char_handles, bt_gatt_service_s *service); static int __bt_gatt_client_update_descriptors(bt_gatt_handle_info_t desc_handles, bt_gatt_characteristic_s *characteristic); -#endif /* * Public Functions @@ -256,7 +254,7 @@ int _bt_get_bt_device_info_s(bt_device_info_s **dest_dev, bluetooth_device_info_ } (*dest_dev)->service_count = source_dev->service_index; (*dest_dev)->is_bonded = (bool)source_dev->paired; - (*dest_dev)->is_connected = (bool)source_dev->connected; + (*dest_dev)->is_connected = source_dev->connected != BLUETOOTH_CONNECTED_LINK_NONE ? TRUE : FALSE; (*dest_dev)->is_authorized = (bool)source_dev->trust; (*dest_dev)->manufacturer_data_len = source_dev->manufacturer_data.data_len; @@ -488,7 +486,6 @@ static int __bt_get_bt_device_connection_info_s(bt_device_connection_info_s **de return BT_ERROR_NONE; } -#if 0 static bt_gatt_server_read_value_requested_cb __bt_gatt_attribute_get_read_cb( bt_gatt_h service, bt_gatt_h characteristic, void **user_data) { @@ -525,7 +522,6 @@ static bt_gatt_server_read_value_requested_cb __bt_gatt_attribute_get_read_cb( } return NULL; } -#endif static void __bt_free_bt_device_connection_info_s(bt_device_connection_info_s *conn_info) { @@ -549,6 +545,18 @@ void _bt_audio_event_proxy(int event, bt_audio_event_param_t *param, void *user_ __bt_event_proxy(event, &new_param, user_data); } +#ifdef TIZEN_WEARABLE +void _bt_hf_event_proxy(int event, bt_hf_event_param_t *param, void *user_data) +{ + bluetooth_event_param_t new_param; + new_param.event = param->event; + new_param.param_data = param->param_data; + new_param.result = param->result; + new_param.user_data = NULL; + __bt_event_proxy(event, &new_param, user_data); +} +#endif + void _bt_telephony_event_proxy(int event, telephony_event_param_t *param, void *user_data) { bluetooth_event_param_t new_param; @@ -587,6 +595,7 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us int *adv_handle; bluetooth_rfcomm_connection_t *connection_ind = NULL; bluetooth_rfcomm_disconnection_t *disconnection_ind = NULL; + bluetooth_hid_request_t *hid_connection_status = NULL; bt_socket_connection_s rfcomm_connection; bt_device_sdp_info_s *sdp_info = NULL; bt_device_connection_info_s *conn_info = NULL; @@ -599,6 +608,9 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us bluetooth_device_address_t *bd_addr = NULL; telephony_event_callid_t *call_data = NULL; char *device_addr = NULL; +#ifdef TIZEN_WEARABLE + char *phone_number = NULL; +#endif int error_code = BT_ERROR_NONE; int event_index = -1; bluetooth_network_device_info_t *dev_info = NULL; @@ -606,13 +618,38 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us bt_hdp_disconnected_t *hdp_disconn_info = NULL; bt_hdp_data_ind_t *hdp_data_ind = NULL; bt_gatt_char_value_t *char_val = NULL; -#if 0 - bt_gatt_discovered_char_t *svc_char = NULL; - bt_gatt_char_property_t *char_desc = NULL; -#endif + media_metadata_attributes_t *metadata = NULL; event_index = __bt_get_cb_index(event); + if (event == BLUETOOTH_EVENT_GATT_CONNECTED) { + const GSList *clients = NULL; + const GSList *l = NULL; + int ret; + + _bt_convert_address_to_string(&device_addr, + (bluetooth_device_address_t *)(param->param_data)); + + clients = _bt_gatt_get_client_list(); + for (l = clients; l; l = g_slist_next(l)) { + bt_gatt_client_s *client_s = l->data; + + if (!g_strcmp0(client_s->remote_address, device_addr)) { + if (client_s->services_discovered == false) { + BT_INFO("Matched GATT Client is found"); + ret = _bt_gatt_client_update_all((bt_gatt_client_h)l->data); + if (ret != BT_ERROR_NONE) + BT_ERR("bluetooth_gatt_get_primary_services is failed"); + else + client_s->services_discovered = true; + } + break; + } + } + g_free(device_addr); + device_addr = NULL; + } + if (event == BLUETOOTH_EVENT_GATT_SERVER_CHARACTERISTIC_VALUE_CHANGED || event == BLUETOOTH_EVENT_ADVERTISING_STARTED || event == BLUETOOTH_EVENT_ADVERTISING_STOPPED) BT_INFO("NOT use bt_event_slot_container"); @@ -750,6 +787,7 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us if (connection_ind) { rfcomm_connection.socket_fd = connection_ind->socket_fd; rfcomm_connection.local_role = connection_ind->device_role; + rfcomm_connection.server_fd = connection_ind->server_id; if (strlen(connection_ind->uuid) > 0) { rfcomm_connection.service_uuid = strdup(connection_ind->uuid); @@ -1115,6 +1153,20 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us (_bt_get_error_code(param->result), FALSE, device_addr, BT_AUDIO_PROFILE_TYPE_A2DP, bt_event_slot_container[event_index].user_data); break; + case BLUETOOTH_EVENT_AV_SOURCE_CONNECTED: + BT_INFO("BLUETOOTH_EVENT_AV_SOURCE_CONNECTED"); + device_addr = (char *)(param->param_data); + ((bt_audio_connection_state_changed_cb) bt_event_slot_container[event_index].callback) + (_bt_get_error_code(param->result), TRUE, device_addr, BT_AUDIO_PROFILE_TYPE_A2DP_SINK, + bt_event_slot_container[event_index].user_data); + break; + case BLUETOOTH_EVENT_AV_SOURCE_DISCONNECTED: + BT_INFO("BLUETOOTH_EVENT_AV_SOURCE_DISCONNECTED"); + device_addr = (char *)(param->param_data); + ((bt_audio_connection_state_changed_cb) bt_event_slot_container[event_index].callback) + (_bt_get_error_code(param->result), FALSE, device_addr, BT_AUDIO_PROFILE_TYPE_A2DP_SINK, + bt_event_slot_container[event_index].user_data); + break; case BLUETOOTH_EVENT_AVRCP_CONNECTED: BT_INFO("BLUETOOTH_EVENT_AVRCP_CONNECTED "); device_addr = (char *)(param->param_data); @@ -1151,6 +1203,68 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us ((bt_avrcp_scan_mode_changed_cb)bt_event_slot_container[event_index].callback) ((bt_avrcp_scan_mode_e)*avrcp_mode, bt_event_slot_container[event_index].user_data); break; + case BLUETOOTH_EVENT_AVRCP_CONTROL_CONNECTED: + BT_INFO("BLUETOOTH_EVENT_AVRCP_CONTROL_CONNECTED "); + device_addr = (char *)(param->param_data); + ((bt_avrcp_target_connection_state_changed_cb)bt_event_slot_container[event_index].callback) + (TRUE, device_addr, bt_event_slot_container[event_index].user_data); + break; + case BLUETOOTH_EVENT_AVRCP_CONTROL_DISCONNECTED: + BT_INFO("BLUETOOTH_EVENT_AVRCP_CONTROL_DISCONNECTED "); + device_addr = (char *)(param->param_data); + ((bt_avrcp_target_connection_state_changed_cb)bt_event_slot_container[event_index].callback) + (FALSE, device_addr, bt_event_slot_container[event_index].user_data); + break; + case BLUETOOTH_EVENT_AVRCP_CONTROL_SHUFFLE_STATUS: + BT_INFO("BLUETOOTH_EVENT_AVRCP_CONTROL_SHUFFLE_STATUS "); + avrcp_mode = (int *)(param->param_data); + ((bt_avrcp_shuffle_mode_changed_cb)bt_event_slot_container[event_index].callback) + ((bt_avrcp_shuffle_mode_e)*avrcp_mode, bt_event_slot_container[event_index].user_data); + break; + case BLUETOOTH_EVENT_AVRCP_CONTROL_EQUALIZER_STATUS: + BT_INFO("BLUETOOTH_EVENT_AVRCP_CONTROL_EQUALIZER_STATUS "); + avrcp_mode = (int *)(param->param_data); + ((bt_avrcp_equalizer_state_changed_cb)bt_event_slot_container[event_index].callback) + ((bt_avrcp_equalizer_state_e)*avrcp_mode, bt_event_slot_container[event_index].user_data); + break; + case BLUETOOTH_EVENT_AVRCP_CONTROL_REPEAT_STATUS: + BT_INFO("BLUETOOTH_EVENT_AVRCP_CONTROL_REPEAT_STATUS "); + avrcp_mode = (int *)(param->param_data); + ((bt_avrcp_repeat_mode_changed_cb)bt_event_slot_container[event_index].callback) + ((bt_avrcp_repeat_mode_e)*avrcp_mode, bt_event_slot_container[event_index].user_data); + break; + case BLUETOOTH_EVENT_AVRCP_CONTROL_SCAN_STATUS: + BT_INFO("BLUETOOTH_EVENT_AVRCP_CONTROL_SCAN_STATUS "); + avrcp_mode = (int *)(param->param_data); + ((bt_avrcp_scan_mode_changed_cb)bt_event_slot_container[event_index].callback) + ((bt_avrcp_scan_mode_e)*avrcp_mode, bt_event_slot_container[event_index].user_data); + break; + case BLUETOOTH_EVENT_AVRCP_PLAY_STATUS_CHANGED: + BT_INFO("BLUETOOTH_EVENT_AVRCP_PLAY_STATUS_CHANGED "); + avrcp_mode = (int *)(param->param_data); + ((bt_avrcp_play_status_changed_cb)bt_event_slot_container[event_index].callback) + ((bt_avrcp_player_state_e)*avrcp_mode, bt_event_slot_container[event_index].user_data); + break; + case BLUETOOTH_EVENT_AVRCP_SONG_POSITION_STATUS: + BT_INFO("BLUETOOTH_EVENT_AVRCP_SONG_POSITION_STATUS "); + unsigned int *postion = (unsigned int *)(param->param_data); + ((bt_avrcp_song_position_changed_cb)bt_event_slot_container[event_index].callback) + (*postion, bt_event_slot_container[event_index].user_data); + break; + case BLUETOOTH_EVENT_AVRCP_TRACK_CHANGED: + BT_INFO("BLUETOOTH_EVENT_AVRCP_TRACK_CHANGED "); + bt_avrcp_metadata_attributes_info_s meta_info = {0, }; + metadata = (media_metadata_attributes_t *)(param->param_data); + meta_info.title = metadata->title; /* No need to allocate memory*/ + meta_info.artist = metadata->artist; /* No need to allocate memory*/ + meta_info.album = metadata->album; /* No need to allocate memory*/ + meta_info.genre = metadata->genre; /* No need to allocate memory*/ + meta_info.total_tracks = metadata->total_tracks; + meta_info.number = metadata->number; + meta_info.duration = metadata->duration; + ((bt_avrcp_track_info_changed_cb)bt_event_slot_container[event_index].callback) + (&meta_info, bt_event_slot_container[event_index].user_data); + break; case BLUETOOTH_HID_CONNECTED: BT_INFO("BLUETOOTH_HID_CONNECTED"); bd_addr = (bluetooth_device_address_t *)(param->param_data); @@ -1171,6 +1285,31 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us if (device_addr != NULL) free(device_addr); break; + case BLUETOOTH_HID_DEVICE_CONNECTED: + BT_INFO("BLUETOOTH_HID_DEVICE_CONNECTED"); + hid_connection_status = (bluetooth_hid_request_t *)(param->param_data); + _bt_convert_address_to_string(&device_addr, + &(hid_connection_status->device_addr)); + ((bt_hid_device_connection_state_changed_cb)bt_event_slot_container[event_index].callback) + (_bt_get_error_code(param->result), TRUE, device_addr, bt_event_slot_container[event_index].user_data); + + g_free(device_addr); + break; + case BLUETOOTH_HID_DEVICE_DISCONNECTED: + BT_INFO("BLUETOOTH_HID_DEVICE_DISCONNECTED"); + hid_connection_status = (bluetooth_hid_request_t *)(param->param_data); + _bt_convert_address_to_string(&device_addr, + &(hid_connection_status->device_addr)); + ((bt_hid_device_connection_state_changed_cb)bt_event_slot_container[event_index].callback) + (_bt_get_error_code(param->result), FALSE, device_addr, bt_event_slot_container[event_index].user_data); + + g_free(device_addr); + break; + case BLUETOOTH_HID_DEVICE_DATA_RECEIVED: + BT_INFO("HID Device Data"); + ((bt_hid_device_data_received_cb)bt_event_slot_container[event_index].callback) + ((bt_hid_device_received_data_s *)(param->param_data), bt_event_slot_container[event_index].user_data); + break; case BLUETOOTH_EVENT_GATT_CONNECTED: BT_INFO("BLUETOOTH_EVENT_GATT_CONNECTED"); bd_addr = (bluetooth_device_address_t *)(param->param_data); @@ -1187,6 +1326,7 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us (_bt_get_error_code(param->result), FALSE, device_addr, bt_event_slot_container[event_index].user_data); break; +#ifdef BT_ENABLE_LEGACY_GATT_CLIENT case BLUETOOTH_EVENT_GATT_SVC_CHAR_DISCOVERED: { BT_INFO("BLUETOOTH_EVENT_GATT_SVC_CHAR_DISCOVERED"); if (_bt_gatt_is_legacy_client_mode()) { @@ -1204,10 +1344,12 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us } break; } +#endif case BLUETOOTH_EVENT_GATT_CHAR_VAL_CHANGED: BT_INFO("BLUETOOTH_EVENT_GATT_CHAR_VAL_CHANGED"); char_val = (bt_gatt_char_value_t *)(param->param_data); +#ifdef BT_ENABLE_LEGACY_GATT_CLIENT if (_bt_gatt_is_legacy_client_mode()) { bt_gatt_char_value_t *char_val = param->param_data; @@ -1218,7 +1360,7 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us bt_event_slot_container[event_index].user_data); break; } - +#endif if (char_val == NULL) return; @@ -1234,7 +1376,7 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us BT_INFO("BLUETOOTH_EVENT_GATT_READ_CHAR"); - +#ifdef BT_ENABLE_LEGACY_GATT_CLIENT if (_bt_gatt_is_legacy_client_mode()) { bt_gatt_char_value_t *char_val = param->param_data; @@ -1244,7 +1386,7 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us _bt_unset_cb(BT_EVENT_GATT_CLIENT_READ_CHARACTERISTIC_LEGACY); break; } - +#endif _bt_unset_cb(BT_EVENT_GATT_CLIENT_READ_CHARACTERISTIC); ret = _bt_get_error_code(param->result); if (ret == BT_ERROR_NONE) { @@ -1264,6 +1406,7 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us BT_INFO("BLUETOOTH_EVENT_GATT_WRITE_CHAR"); +#ifdef BT_ENABLE_LEGACY_GATT_CLIENT if (_bt_gatt_is_legacy_client_mode()) { ((bt_gatt_characteristic_write_cb)bt_event_slot_container[event_index].callback) (bt_event_slot_container[event_index].user_data); @@ -1271,7 +1414,7 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us _bt_unset_cb(BT_EVENT_GATT_CLIENT_WRITE_CHARACTERISTIC_LEGACY); break; } - +#endif _bt_unset_cb(BT_EVENT_GATT_CLIENT_WRITE_CHARACTERISTIC); ret = _bt_get_error_code(param->result); cb(ret, cb_data->gatt_handle, cb_data->user_data); @@ -1313,20 +1456,39 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us break; } + case BLUETOOTH_EVENT_GATT_SERVER_READ_REQUESTED: { + bt_gatt_read_req_t *read_req = param->param_data; + bt_gatt_server_read_value_requested_cb cb; + void *user_data = NULL; + cb = __bt_gatt_attribute_get_read_cb(read_req->service_handle, + read_req->char_handle, &user_data); + + BT_INFO("BLUETOOTH_EVENT_GATT_SERVER_READ_REQUESTED"); + if (cb == NULL) + return; + + cb(read_req->address, read_req->req_id, read_req->service_handle, + read_req->char_handle, read_req->offset, + user_data); + break; + } +#ifdef BT_ENABLE_LEGACY_GATT_CLIENT case BLUETOOTH_EVENT_GATT_SVC_CHAR_DESC_DISCOVERED: { BT_INFO("BLUETOOTH_EVENT_GATT_SVC_CHAR_DESC_DISCOVERED"); - bt_gatt_char_property_t *char_desc = param->param_data; + if (_bt_gatt_is_legacy_client_mode()) { + bt_gatt_char_property_t *char_desc = param->param_data; - if (char_desc == NULL) - return; - ((bt_gatt_characteristic_descriptor_discovered_cb) - bt_event_slot_container[event_index].callback)(_bt_get_error_code(param->result), - char_desc->format.format, char_desc->val_len, char_desc->description, - bt_event_slot_container[event_index].user_data); - _bt_unset_cb(BT_EVENT_GATT_CLIENT_CHARACTERISTIC_DESCRIPTOR_DISCOVERED_LEGACY); + if (char_desc == NULL) + return; + ((bt_gatt_characteristic_descriptor_discovered_cb) + bt_event_slot_container[event_index].callback)(_bt_get_error_code(param->result), + char_desc->format.format, char_desc->val_len, char_desc->description, + bt_event_slot_container[event_index].user_data); + _bt_unset_cb(BT_EVENT_GATT_CLIENT_CHARACTERISTIC_DESCRIPTOR_DISCOVERED_LEGACY); + } break; } - +#endif case BLUETOOTH_EVENT_GATT_SERVER_CHARACTERISTIC_VALUE_CHANGED: { const GSList *server_list = NULL; BT_INFO("BLUETOOTH_EVENT_GATT_SERVER_CHARACTERISTIC_VALUE_CHANGED"); @@ -1391,14 +1553,232 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us _bt_get_error_code(param->result), BT_ADAPTER_LE_ADVERTISING_STOPPED); break; -/* case BLUETOOTH_EVENT_MANUFACTURER_DATA_CHANGED: + case BLUETOOTH_EVENT_MANUFACTURER_DATA_CHANGED: BT_INFO("BLUETOOTH_EVENT_MANUFACTURER_DATA_CHANGED"); ((bt_adapter_manufacturer_data_changed_cb)bt_event_slot_container[event_index].callback) - (_bt_get_error_code(param->result, NULL, BLUETOOTH_EVENT_MANUFACTURER_DATA_CHANGED, + (param->param_data, param->result, bt_event_slot_container[event_index].user_data); - break;*/ + break; +#ifdef TIZEN_WEARABLE + case BLUETOOTH_PBAP_CONNECTED: { + bt_pbap_enabled_cb cb = bt_event_slot_container[event_index].callback; + void *user_data = bt_event_slot_container[event_index].user_data; + bt_pbap_connected_t *connected = (bt_pbap_connected_t *)param->param_data; + + BT_INFO("BLUETOOTH_PBAP_CONNECTED/DISCONNECTED"); + if (connected->connected == 0) + _bt_unset_cb(BT_EVENT_PBAP_CONNECTION_STATUS); + _bt_convert_address_to_string(&device_addr, &connected->btaddr); + cb(device_addr, connected->connected, user_data); + + if (device_addr != NULL) + free(device_addr); + + break; + } + case BLUETOOTH_PBAP_PHONEBOOK_SIZE: { + bt_pbap_phonebook_size_cb cb = bt_event_slot_container[event_index].callback; + void *user_data = bt_event_slot_container[event_index].user_data; + bt_pbap_phonebook_size_t *pb_size = (bt_pbap_phonebook_size_t *)param->param_data; + + BT_INFO("BLUETOOTH_PBAP_PHONEBOOK_SIZE"); + + _bt_unset_cb(BT_EVENT_PBAP_PHONEBOOK_SIZE); + _bt_convert_address_to_string(&device_addr, &pb_size->btaddr); + cb(device_addr, pb_size->size, user_data); + + if (device_addr != NULL) + free(device_addr); + + break; + } + case BLUETOOTH_PBAP_PHONEBOOK_PULL: { + bt_pbap_phonebook_pull_cb cb = bt_event_slot_container[event_index].callback; + void *user_data = bt_event_slot_container[event_index].user_data; + bt_pbap_phonebook_pull_t *pb_pull = (bt_pbap_phonebook_pull_t *)(param->param_data); + + BT_INFO("BLUETOOTH_PBAP_PHONEBOOK_PULL"); + + _bt_unset_cb(BT_EVENT_PBAP_PHONEBOOK_PULL); + _bt_convert_address_to_string(&device_addr, &pb_pull->btaddr); + cb(device_addr, pb_pull->vcf_file, pb_pull->success, user_data); + + if (device_addr != NULL) + free(device_addr); + + break; + } + case BLUETOOTH_PBAP_VCARD_LIST: { + bt_pbap_list_vcards_cb cb = bt_event_slot_container[event_index].callback; + void *user_data = bt_event_slot_container[event_index].user_data; + bt_pbap_vcard_list_t *vc_list = (bt_pbap_vcard_list_t *)(param->param_data); + + BT_INFO("BLUETOOTH_PBAP_VCARD_LIST"); + + _bt_unset_cb(BT_EVENT_PBAP_VCARD_LIST); + _bt_convert_address_to_string(&device_addr, &vc_list->btaddr); + cb(device_addr, vc_list->vcards, vc_list->length, vc_list->success, user_data); + + if (device_addr != NULL) + free(device_addr); + + break; + } + case BLUETOOTH_PBAP_VCARD_PULL: { + bt_pbap_get_vcard_cb cb = bt_event_slot_container[event_index].callback; + void *user_data = bt_event_slot_container[event_index].user_data; + bt_pbap_vcard_pull_t *vc_pull = (bt_pbap_vcard_pull_t *)(param->param_data); + + BT_INFO("BLUETOOTH_PBAP_VCARD_PULL"); + + _bt_unset_cb(BT_EVENT_PBAP_VCARD_PULL); + _bt_convert_address_to_string(&device_addr, &vc_pull->btaddr); + cb(device_addr, vc_pull->vcf_file, vc_pull->success, user_data); + + if (device_addr != NULL) + free(device_addr); + + break; + } + case BLUETOOTH_PBAP_PHONEBOOK_SEARCH: { + bt_pbap_search_list_cb cb = bt_event_slot_container[event_index].callback; + void *user_data = bt_event_slot_container[event_index].user_data; + bt_pbap_phonebook_search_list_t *vc_list = (bt_pbap_phonebook_search_list_t *)(param->param_data); + + BT_INFO("BLUETOOTH_PBAP_PHONEBOOK_SEARCH"); + + _bt_unset_cb(BT_EVENT_PBAP_PHONEBOOK_SEARCH); + _bt_convert_address_to_string(&device_addr, &vc_list->btaddr); + cb(device_addr, vc_list->vcards, vc_list->length, vc_list->success, user_data); + + if (device_addr != NULL) + free(device_addr); + + break; + } + case BLUETOOTH_EVENT_HF_CONNECTED: + BT_INFO("BLUETOOTH_EVENT_HF_CONNECTED"); + device_addr = (char *)(param->param_data); + ((bt_audio_connection_state_changed_cb)bt_event_slot_container[event_index].callback) + (_bt_get_error_code(param->result), TRUE, device_addr, BT_AUDIO_PROFILE_TYPE_AG, + bt_event_slot_container[event_index].user_data); + break; + case BLUETOOTH_EVENT_HF_DISCONNECTED: + BT_INFO("BLUETOOTH_EVENT_HF_DISCONNECTED"); + device_addr = (char *)(param->param_data); + ((bt_audio_connection_state_changed_cb)bt_event_slot_container[event_index].callback) + (_bt_get_error_code(param->result), FALSE, device_addr, BT_AUDIO_PROFILE_TYPE_AG, + bt_event_slot_container[event_index].user_data); + break; + case BLUETOOTH_EVENT_HF_AUDIO_CONNECTED: + BT_INFO("BLUETOOTH_EVENT_HF_AUDIO_CONNECTED"); + device_addr = (char *)(param->param_data); + ((bt_hf_sco_state_changed_cb)bt_event_slot_container[event_index].callback) + (_bt_get_error_code(param->result), TRUE, + bt_event_slot_container[event_index].user_data); + break; + case BLUETOOTH_EVENT_HF_AUDIO_DISCONNECTED: + BT_INFO("BLUETOOTH_EVENT_HF_AUDIO_DISCONNECTED"); + device_addr = (char *)(param->param_data); + ((bt_hf_sco_state_changed_cb)bt_event_slot_container[event_index].callback) + (_bt_get_error_code(param->result), FALSE, + bt_event_slot_container[event_index].user_data); + break; + case BLUETOOTH_EVENT_HF_RING_INDICATOR: + BT_INFO("BLUETOOTH_EVENT_HF_RING_INDICATOR"); + phone_number = (char *)(param->param_data); + ((bt_hf_call_handling_event_cb)bt_event_slot_container[event_index].callback) + (BT_HF_CALL_HANDLING_EVENT_RING, phone_number, + bt_event_slot_container[event_index].user_data); + break; + case BLUETOOTH_EVENT_HF_CALL_TERMINATED: + BT_INFO("BLUETOOTH_EVENT_HF_CALL_TERMINATED"); + ((bt_hf_call_handling_event_cb)bt_event_slot_container[event_index].callback) + (BT_HF_CALL_HANDLING_EVENT_RELEASE, NULL, + bt_event_slot_container[event_index].user_data); + break; + case BLUETOOTH_EVENT_HF_CALL_STARTED: + BT_INFO("BLUETOOTH_EVENT_HF_CALL_STARTED"); + ((bt_hf_call_handling_event_cb)bt_event_slot_container[event_index].callback) + (BT_HF_CALL_HANDLING_EVENT_CALL_STARTED, NULL, + bt_event_slot_container[event_index].user_data); + break; + case BLUETOOTH_EVENT_HF_CALL_ENDED: + BT_INFO("BLUETOOTH_EVENT_HF_CALL_ENDED"); + ((bt_hf_call_handling_event_cb)bt_event_slot_container[event_index].callback) + (BT_HF_CALL_HANDLING_EVENT_CALL_ENDED, NULL, + bt_event_slot_container[event_index].user_data); + break; + case BLUETOOTH_EVENT_HF_VOICE_RECOGNITION_ENABLED: + BT_INFO("BLUETOOTH_EVENT_HF_VOICE_RECOGNITION_ENABLED"); + ((bt_hf_call_handling_event_cb)bt_event_slot_container[event_index].callback) + (BT_HF_CALL_HANDLING_EVENT_VOICE_RECOGNITION_ENABLED, NULL, + bt_event_slot_container[event_index].user_data); + break; + case BLUETOOTH_EVENT_HF_VOICE_RECOGNITION_DISABLED: + BT_INFO("BLUETOOTH_EVENT_HF_VOICE_RECOGNITION_DISABLED"); + ((bt_hf_call_handling_event_cb)bt_event_slot_container[event_index].callback) + (BT_HF_CALL_HANDLING_EVENT_VOICE_RECOGNITION_DISABLED, NULL, + bt_event_slot_container[event_index].user_data); + break; + case BLUETOOTH_EVENT_HF_CALL_WAITING: + BT_INFO("BLUETOOTH_EVENT_HF_CALL_WAITING"); + phone_number = (char *)(param->param_data); + ((bt_hf_call_handling_event_cb)bt_event_slot_container[event_index].callback) + (BT_HF_CALL_HANDLING_EVENT_WAITING, phone_number, + bt_event_slot_container[event_index].user_data); + break; + case BLUETOOTH_EVENT_HF_CALL_ON_HOLD: + BT_INFO("BLUETOOTH_EVENT_HF_CALL_ON_HOLD"); + ((bt_hf_call_handling_event_cb)bt_event_slot_container[event_index].callback) + (BT_HF_CALL_HANDLING_EVENT_HELD, NULL, + bt_event_slot_container[event_index].user_data); + break; + case BLUETOOTH_EVENT_HF_CALL_UNHOLD: + BT_INFO("BLUETOOTH_EVENT_HF_CALL_UNHOLD"); + ((bt_hf_call_handling_event_cb)bt_event_slot_container[event_index].callback) + (BT_HF_CALL_HANDLING_EVENT_UNHELD, NULL, + bt_event_slot_container[event_index].user_data); + break; + case BLUETOOTH_EVENT_HF_CALL_SWAPPED: + BT_INFO("BLUETOOTH_EVENT_HF_CALL_SWAPPED"); + ((bt_hf_call_handling_event_cb)bt_event_slot_container[event_index].callback) + (BT_HF_CALL_HANDLING_EVENT_SWAPPED, NULL, + bt_event_slot_container[event_index].user_data); + break; + case BLUETOOTH_EVENT_HF_VOLUME_SPEAKER: { + BT_INFO("BLUETOOTH_EVENT_HF_VOLUME_SPEAKER"); + int *spk_gain = (int *)(param->param_data); + ((bt_hf_speaker_gain_changed_cb)bt_event_slot_container[event_index].callback) + (*spk_gain, bt_event_slot_container[event_index].user_data); + break; + } + case BLUETOOTH_EVENT_HF_CALL_STATUS: { + BT_INFO("BLUETOOTH_EVENT_HF_CALL_STATUS"); + bt_hf_call_list_s *handle = (bt_hf_call_list_s *)(param->param_data); + GList *l = NULL; + GSList *call_list = NULL; + + for (l = g_list_first(handle->list); l; l = g_list_next(l)) { + bt_hf_call_status_info_t *hf_call_info = l->data; + bt_hf_call_status_info_s *call_info = NULL; + + call_info = g_malloc0(sizeof(bt_hf_call_status_info_s)); + call_info->number = strdup(hf_call_info->number); + call_info->direction = hf_call_info->direction; + call_info->status = hf_call_info->status; + call_info->multi_party = hf_call_info->mpart; + call_info->index = hf_call_info->idx; + call_list = g_slist_append(call_list, call_info); + } + + ((bt_hf_call_status_updated_event_cb)bt_event_slot_container[event_index].callback) + (call_list, bt_event_slot_container[event_index].user_data); + break; + } +#endif default: break; } @@ -1408,7 +1788,9 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us static void __bt_le_event_proxy(int event, bluetooth_event_param_t *param, void *user_data) { bt_adapter_le_device_scan_result_info_s *scan_info = NULL; +#ifndef TIZEN_WEARABLE bt_adapter_le_device_discovery_info_s *discovery_info = NULL; +#endif int event_index = -1; event_index = __bt_get_cb_index(event); @@ -1428,6 +1810,8 @@ static void __bt_le_event_proxy(int event, bluetooth_event_param_t *param, void ((bt_adapter_le_state_changed_cb) bt_event_slot_container[event_index].callback) (_bt_get_error_code(param->result), BT_ADAPTER_LE_DISABLED, bt_event_slot_container[event_index].user_data); break; + +#ifndef TIZEN_WEARABLE case BLUETOOTH_EVENT_LE_DISCOVERY_STARTED: BT_INFO("BLUETOOTH_EVENT_LE_DISCOVERY_STARTED"); ((bt_adapter_le_device_discovery_state_changed_cb) bt_event_slot_container[event_index].callback) @@ -1438,6 +1822,8 @@ static void __bt_le_event_proxy(int event, bluetooth_event_param_t *param, void ((bt_adapter_le_device_discovery_state_changed_cb)bt_event_slot_container[event_index].callback) (_bt_get_error_code(param->result), BT_ADAPTER_LE_DEVICE_DISCOVERY_FINISHED, NULL, bt_event_slot_container[event_index].user_data); break; +#endif + case BLUETOOTH_EVENT_REMOTE_LE_DEVICE_FOUND: BT_INFO("BLUETOOTH_EVENT_REMOTE_LE_DEVICE_FOUND"); event_index = BT_EVENT_LE_SCAN_RESULT_UPDATED; @@ -1451,7 +1837,7 @@ static void __bt_le_event_proxy(int event, bluetooth_event_param_t *param, void (_bt_get_error_code(param->result), NULL, bt_event_slot_container[event_index].user_data); } } - +#ifndef TIZEN_WEARABLE event_index = BT_EVENT_LE_DEVICE_DISCOVERY_STATE_CHANGED; if (bt_event_slot_container[event_index].callback != NULL) { if (__bt_get_bt_adapter_le_device_discovery_info_s(&discovery_info, (bluetooth_le_device_info_t *)(param->param_data)) == BT_ERROR_NONE) { @@ -1463,6 +1849,7 @@ static void __bt_le_event_proxy(int event, bluetooth_event_param_t *param, void (_bt_get_error_code(param->result), BT_ADAPTER_LE_DEVICE_DISCOVERY_FOUND, NULL, bt_event_slot_container[event_index].user_data); } } +#endif break; default: @@ -1608,6 +1995,7 @@ static void __bt_free_bt_adapter_le_device_scan_info_s(bt_adapter_le_device_scan scan_info = NULL; } +#ifndef TIZEN_WEARABLE static int __bt_get_bt_adapter_le_device_discovery_info_s( bt_adapter_le_device_discovery_info_s **le_discovery_info, bluetooth_le_device_info_t *source_info) @@ -1660,6 +2048,9 @@ static void __bt_free_bt_adapter_le_device_discovery_info_s(bt_adapter_le_device discovery_info = NULL; } +#endif + +#ifdef BT_ENABLE_LEGACY_GATT_CLIENT static int __bt_get_gatt_client_cb_index(int event) { switch (event) { @@ -1682,6 +2073,7 @@ static int __bt_get_gatt_client_cb_index(int event) return -1; } +#endif static int __bt_get_cb_index(int event) { @@ -1791,21 +2183,44 @@ static int __bt_get_cb_index(int event) return BT_EVENT_AUDIO_CONNECTION_STATUS; case BLUETOOTH_EVENT_AV_DISCONNECTED: return BT_EVENT_AUDIO_CONNECTION_STATUS; + case BLUETOOTH_EVENT_AV_SOURCE_CONNECTED: + return BT_EVENT_AUDIO_CONNECTION_STATUS; + case BLUETOOTH_EVENT_AV_SOURCE_DISCONNECTED: + return BT_EVENT_AUDIO_CONNECTION_STATUS; case BLUETOOTH_EVENT_AVRCP_CONNECTED: case BLUETOOTH_EVENT_AVRCP_DISCONNECTED: + case BLUETOOTH_EVENT_AVRCP_CONTROL_CONNECTED: + case BLUETOOTH_EVENT_AVRCP_CONTROL_DISCONNECTED: return BT_EVENT_AVRCP_CONNECTION_STATUS; case BLUETOOTH_EVENT_AVRCP_SETTING_SHUFFLE_STATUS: + case BLUETOOTH_EVENT_AVRCP_CONTROL_SHUFFLE_STATUS: return BT_EVENT_AVRCP_SHUFFLE_MODE_CHANGED; case BLUETOOTH_EVENT_AVRCP_SETTING_EQUALIZER_STATUS: + case BLUETOOTH_EVENT_AVRCP_CONTROL_EQUALIZER_STATUS: return BT_EVENT_AVRCP_EQUALIZER_STATE_CHANGED; case BLUETOOTH_EVENT_AVRCP_SETTING_REPEAT_STATUS: + case BLUETOOTH_EVENT_AVRCP_CONTROL_REPEAT_STATUS: return BT_EVENT_AVRCP_REPEAT_MODE_CHANGED; case BLUETOOTH_EVENT_AVRCP_SETTING_SCAN_STATUS: + case BLUETOOTH_EVENT_AVRCP_CONTROL_SCAN_STATUS: return BT_EVENT_AVRCP_SCAN_MODE_CHANGED; + case BLUETOOTH_EVENT_AVRCP_SONG_POSITION_STATUS: + return BT_EVENT_AVRCP_SONG_POSITION_CHANGED; + case BLUETOOTH_EVENT_AVRCP_PLAY_STATUS_CHANGED: + return BT_EVENT_AVRCP_PLAY_STATUS_CHANGED; + case BLUETOOTH_EVENT_AVRCP_TRACK_CHANGED: + return BT_EVENT_AVRCP_TRACK_INFO_CHANGED; case BLUETOOTH_HID_CONNECTED: return BT_EVENT_HID_CONNECTION_STATUS; case BLUETOOTH_HID_DISCONNECTED: return BT_EVENT_HID_CONNECTION_STATUS; + case BLUETOOTH_HID_DEVICE_CONNECTED: + return BT_EVENT_HID_DEVICE_CONNECTION_STATUS; + case BLUETOOTH_HID_DEVICE_DISCONNECTED: + return BT_EVENT_HID_DEVICE_CONNECTION_STATUS; + case BLUETOOTH_HID_DEVICE_DATA_RECEIVED: + return BT_EVENT_HID_DEVICE_DATA_RECEIVED; +#ifdef BT_ENABLE_LEGACY_GATT_CLIENT case BLUETOOTH_EVENT_GATT_SVC_CHAR_DISCOVERED: return BT_EVENT_GATT_CLIENT_CHARACTERISTIC_DISCOVERED_LEGACY; case BLUETOOTH_EVENT_GATT_SVC_CHAR_DESC_DISCOVERED: @@ -1814,10 +2229,20 @@ static int __bt_get_cb_index(int event) case BLUETOOTH_EVENT_GATT_READ_CHAR: case BLUETOOTH_EVENT_GATT_WRITE_CHAR: return __bt_get_gatt_client_cb_index(event); +#else + case BLUETOOTH_EVENT_GATT_CHAR_VAL_CHANGED: + return BT_EVENT_GATT_CLIENT_VALUE_CHANGED; + case BLUETOOTH_EVENT_GATT_READ_CHAR: + return BT_EVENT_GATT_CLIENT_READ_CHARACTERISTIC; + case BLUETOOTH_EVENT_GATT_WRITE_CHAR: + return BT_EVENT_GATT_CLIENT_WRITE_CHARACTERISTIC; +#endif case BLUETOOTH_EVENT_GATT_READ_DESC: return BT_EVENT_GATT_CLIENT_READ_DESCRIPTOR; case BLUETOOTH_EVENT_GATT_WRITE_DESC: return BT_EVENT_GATT_CLIENT_WRITE_DESCRIPTOR; + case BLUETOOTH_EVENT_GATT_SERVER_READ_REQUESTED: + return BT_EVENT_GATT_SERVER_READ_REQUESTED; case BLUETOOTH_EVENT_ADVERTISING_STARTED: case BLUETOOTH_EVENT_ADVERTISING_STOPPED: return BT_EVENT_ADVERTISING_STATE_CHANGED; @@ -1825,6 +2250,43 @@ static int __bt_get_cb_index(int event) return BT_EVENT_MANUFACTURER_DATA_CHANGED; case BLUETOOTH_EVENT_CONNECTABLE_CHANGED: return BT_EVENT_CONNECTABLE_CHANGED_EVENT; +#ifdef TIZEN_WEARABLE + case BLUETOOTH_PBAP_CONNECTED: + return BT_EVENT_PBAP_CONNECTION_STATUS; + case BLUETOOTH_PBAP_PHONEBOOK_SIZE: + return BT_EVENT_PBAP_PHONEBOOK_SIZE; + case BLUETOOTH_PBAP_PHONEBOOK_PULL: + return BT_EVENT_PBAP_PHONEBOOK_PULL; + case BLUETOOTH_PBAP_VCARD_LIST: + return BT_EVENT_PBAP_VCARD_LIST; + case BLUETOOTH_PBAP_VCARD_PULL: + return BT_EVENT_PBAP_VCARD_PULL; + case BLUETOOTH_PBAP_PHONEBOOK_SEARCH: + return BT_EVENT_PBAP_PHONEBOOK_SEARCH; + case BLUETOOTH_EVENT_HF_CONNECTED: + return BT_EVENT_AUDIO_CONNECTION_STATUS; + case BLUETOOTH_EVENT_HF_DISCONNECTED: + return BT_EVENT_AUDIO_CONNECTION_STATUS; + case BLUETOOTH_EVENT_HF_AUDIO_CONNECTED: + return BT_EVENT_HF_SCO_CONNECTION_STATUS; + case BLUETOOTH_EVENT_HF_AUDIO_DISCONNECTED: + return BT_EVENT_HF_SCO_CONNECTION_STATUS; + case BLUETOOTH_EVENT_HF_RING_INDICATOR: + case BLUETOOTH_EVENT_HF_CALL_TERMINATED: + case BLUETOOTH_EVENT_HF_CALL_STARTED: + case BLUETOOTH_EVENT_HF_CALL_ENDED: + case BLUETOOTH_EVENT_HF_VOICE_RECOGNITION_ENABLED: + case BLUETOOTH_EVENT_HF_VOICE_RECOGNITION_DISABLED: + case BLUETOOTH_EVENT_HF_CALL_WAITING: + case BLUETOOTH_EVENT_HF_CALL_ON_HOLD: + case BLUETOOTH_EVENT_HF_CALL_UNHOLD: + case BLUETOOTH_EVENT_HF_CALL_SWAPPED: + return BT_EVENT_HF_CALL_HANDLING_EVENT; + case BLUETOOTH_EVENT_HF_VOLUME_SPEAKER: + return BT_EVENT_HF_SPEAKER_GAIN_CHANGE; + case BLUETOOTH_EVENT_HF_CALL_STATUS: + return BT_EVENT_HF_CALL_STATUS_UPDATED_EVENT; +#endif default: return -1; } @@ -1842,13 +2304,129 @@ static void __bt_convert_lower_to_upper(char *origin) } } -#if 0 static void bt_gatt_client_handle_destroy(bt_gatt_h gatt_handle) { if (gatt_handle) bt_gatt_destroy(gatt_handle); } +int _bt_gatt_client_update_all(bt_gatt_client_h client) +{ + bt_gatt_client_s *client_s = client; + bluetooth_device_address_t addr_hex = { {0, } }; + bt_gatt_handle_info_t *prim_svc = NULL; + int ret; + int i; + int j; + GSList *svc_list = NULL; + + prim_svc = g_new0(bt_gatt_handle_info_t, 1); + + _bt_convert_address_to_hex(&addr_hex, client_s->remote_address); + ret = bluetooth_gatt_get_primary_services(&addr_hex, prim_svc); + ret = _bt_get_error_code(ret); + if (ret != BT_ERROR_NONE) { + BT_ERR("bluetooth_gatt_get_primary_services is failed"); + return ret; + } + + if (prim_svc->count == 0) + goto done; + + for (i = 0; i < prim_svc->count; i++) { + bt_gatt_service_s *svc = NULL; + bt_gatt_service_property_t property; + + if (prim_svc->handle[i] == NULL) + continue; + BT_DBG("handle: %s", prim_svc->handle[i]); + + memset(&property, 0x00, sizeof(property)); + + ret = bluetooth_gatt_get_service_property( + prim_svc->handle[i], &property); + ret = _bt_get_error_code(ret); + if (ret != BT_ERROR_NONE) { + BT_ERR("bluetooth_gatt_get_service_property is failed"); + continue; + } + + /* Add primary service */ + ret = bt_gatt_service_create(property.uuid, + BT_GATT_SERVICE_TYPE_PRIMARY, + (bt_gatt_h *)&svc); + if (ret != BT_ERROR_NONE) { + BT_ERR("bt_gatt_service_create is failed"); + continue; + } + + svc->role = BT_GATT_ROLE_CLIENT; + svc->parent = (void *)client_s; + svc->path = g_strdup(prim_svc->handle[i]); + + svc_list = g_slist_append(svc_list, svc); + + if (property.include_handles.count != 0 && property.include_handles.handle) { + GSList *include_list = NULL; + /* Add included services */ + for (j = 0; j < property.include_handles.count; j++) { + bt_gatt_service_s *sec_svc = NULL; + bt_gatt_service_property_t sec_property; + + if (property.include_handles.handle[j] == NULL) + continue; + + memset(&sec_property, 0x00, sizeof(sec_property)); + + ret = bluetooth_gatt_get_service_property( + property.include_handles.handle[j], + &sec_property); + ret = _bt_get_error_code(ret); + if (ret != BT_ERROR_NONE) + continue; + + ret = bt_gatt_service_create(sec_property.uuid, + BT_GATT_SERVICE_TYPE_SECONDARY, + (bt_gatt_h *)&sec_svc); + if (ret != BT_ERROR_NONE) + continue; + + sec_svc->role = BT_GATT_ROLE_CLIENT; + sec_svc->parent = (void *)svc; + sec_svc->is_included_service = true; + sec_svc->path = g_strdup(property.include_handles.handle[j]); + + include_list = g_slist_append(include_list, sec_svc); + bluetooth_gatt_free_service_property(&sec_property); + } + + g_slist_free_full(svc->included_services, + bt_gatt_client_handle_destroy); + svc->included_services = include_list; + } + if (property.char_handle.count != 0 && property.char_handle.handle) { + + /* Add characteristics */ + __bt_gatt_client_update_characteristics(property.char_handle, svc); + } + bluetooth_gatt_free_service_property(&property); + } + g_strfreev(prim_svc->handle); + + g_free(prim_svc); + + if (svc_list == NULL) + return BT_ERROR_OPERATION_FAILED; + +done: + g_slist_free_full(client_s->services, + bt_gatt_client_handle_destroy); + + client_s->services = svc_list; + + return BT_ERROR_NONE; +} + static int __bt_gatt_client_update_characteristics(bt_gatt_handle_info_t char_handles, bt_gatt_service_s *service) { @@ -1950,4 +2528,3 @@ next: characteristic->descriptors = desc_list; return BT_ERROR_NONE; } -#endif diff --git a/src/bluetooth-device.c b/src/bluetooth-device.c index 21843dc..99a3806 100644 --- a/src/bluetooth-device.c +++ b/src/bluetooth-device.c @@ -274,14 +274,46 @@ int bt_device_set_service_searched_cb(bt_device_service_searched_cb callback, vo int bt_device_get_connection_state(const char *remote_address, bt_device_connection_link_type_e link_type, bool *connected) { + int ret; + bluetooth_device_address_t addr_hex = { {0,} }; + bluetooth_connected_link_t connected_link = BLUETOOTH_CONNECTED_LINK_NONE; + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(remote_address); BT_CHECK_INPUT_PARAMETER(connected); - /* Will implement after synch bluetooth-frwk */ + if (link_type != BT_DEVICE_CONNECTION_LINK_BREDR && + link_type != BT_DEVICE_CONNECTION_LINK_LE) + return BT_ERROR_INVALID_PARAMETER; + + _bt_convert_address_to_hex(&addr_hex, remote_address); + + ret = _bt_get_error_code(bluetooth_get_connected_link_type(&addr_hex, &connected_link)); + if (ret != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x) : Failed to run function", + _bt_convert_error_to_string(ret), ret); + return ret; + } + + if (connected_link == BLUETOOTH_CONNECTED_LINK_BREDR_LE) { + *connected = true; + return BT_ERROR_NONE; + } - return BT_ERROR_NOT_SUPPORTED; + if (link_type == BT_DEVICE_CONNECTION_LINK_BREDR) { + if (connected_link == BLUETOOTH_CONNECTED_LINK_BREDR) + *connected = true; + else + *connected = false; + } else if (link_type == BT_DEVICE_CONNECTION_LINK_LE) { + if (connected_link == BLUETOOTH_CONNECTED_LINK_LE) + *connected = true; + else + *connected = false; + } + + return BT_ERROR_NONE; } int bt_device_set_connection_state_changed_cb(bt_device_connection_state_changed_cb callback, void *user_data) diff --git a/src/bluetooth-gatt.c b/src/bluetooth-gatt.c index 4cb0c13..8ebffc2 100644 --- a/src/bluetooth-gatt.c +++ b/src/bluetooth-gatt.c @@ -129,6 +129,7 @@ const GSList* _bt_gatt_get_server_list(void) return gatt_server_list; } +#ifdef BT_ENABLE_LEGACY_GATT_CLIENT bool _bt_gatt_is_legacy_client_mode(void) { if (gatt_client_list) { @@ -231,11 +232,17 @@ int bt_gatt_get_service_uuid(bt_gatt_attribute_h service, char **uuid) } else { *uuid = g_strdup(property.uuid); - if (property.handle_info.count != 0 && property.handle_info.handle) { - for (i = 0; i < property.handle_info.count; i++) { - g_free(property.handle_info.handle[i]); + if (property.include_handles.count != 0 && property.include_handles.handle) { + for (i = 0; i < property.include_handles.count; i++) { + g_free(property.include_handles.handle[i]); } - g_free(property.handle_info.handle); + g_free(property.include_handles.handle); + } + if (property.char_handle.count != 0 && property.char_handle.handle) { + for (i = 0; i < property.char_handle.count; i++) { + g_free(property.char_handle.handle[i]); + } + g_free(property.char_handle.handle); } } @@ -263,24 +270,30 @@ int bt_gatt_foreach_included_services(bt_gatt_attribute_h service, if (ret != BT_ERROR_NONE) { BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); } else { - if (property.handle_info.count == 0 || - property.handle_info.handle == NULL) { + if (property.char_handle.count != 0 && property.char_handle.handle) { + for (i = 0; i < property.char_handle.count; i++) { + g_free(property.char_handle.handle[i]); + } + g_free(property.char_handle.handle); + } + if (property.include_handles.count == 0 || + property.include_handles.handle == NULL) { return ret; } - for (i = 0; i < property.handle_info.count; i++) { - if (property.handle_info.handle[i] == NULL) + for (i = 0; i < property.include_handles.count; i++) { + if (property.include_handles.handle[i] == NULL) continue; if (foreach_call == true && - !callback((bt_gatt_attribute_h)property.handle_info.handle[i], + !callback((bt_gatt_attribute_h)property.include_handles.handle[i], user_data)) { foreach_call = false; } - g_free(property.handle_info.handle[i]); + g_free(property.include_handles.handle[i]); } - g_free(property.handle_info.handle); + g_free(property.include_handles.handle); } return ret; } @@ -496,6 +509,7 @@ int bt_gatt_discover_characteristic_descriptor(bt_gatt_attribute_h characteristi return ret; } +#endif int bt_gatt_connect(const char *address, bool auto_connect) { @@ -766,6 +780,15 @@ static int __convert_unsigned_bytes_to_int32(char b0, char b1, char b2, char b3) + (__convert_unsigned_byte_to_int(b2) << 16) + (__convert_unsigned_byte_to_int(b3) << 24); } +static double power(int x, int n) +{ + /* pow() cannot not referenced. */ + if(n == 0) + return 1; + else + return x*power(x,n-1); +} + static float __convert_bytes_to_short_float(char b0, char b1) { int mantissa; @@ -774,7 +797,7 @@ static float __convert_bytes_to_short_float(char b0, char b1) mantissa = __convert_unsigned_to_signed(__convert_unsigned_byte_to_int(b0) + ((__convert_unsigned_byte_to_int(b1) & 0x0F) << 8), 12); exponent = __convert_unsigned_to_signed(__convert_unsigned_byte_to_int(b1) >> 4, 4); - tmp = pow(10, exponent); + tmp = power(10, exponent); return (float)(mantissa * tmp); } @@ -786,7 +809,7 @@ float __convert_bytes_to_float(char b0, char b1, char b2, char b3) mantissa = __convert_unsigned_to_signed(__convert_unsigned_byte_to_int(b0) + (__convert_unsigned_byte_to_int(b1) << 8) + (__convert_unsigned_byte_to_int(b2) << 16), 24); - exponent = pow(10, b3); + exponent = power(10, b3); return (float)(mantissa * exponent); } @@ -1986,12 +2009,20 @@ int bt_gatt_server_unregister_all_services(bt_gatt_server_h server) int bt_gatt_server_send_response(int request_id, int offset, char *value, int value_length) { + int ret = BT_ERROR_NONE; BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(value); - /* Will implement after synch bluetooth-frwk */ - - return BT_ERROR_NOT_SUPPORTED; + if (value_length <= 0) + return BT_ERROR_INVALID_PARAMETER; + + ret = _bt_get_error_code(bluetooth_gatt_send_response(request_id, offset, value, value_length)); + + if (ret != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + } + + return ret; } int bt_gatt_server_notify(bt_gatt_h characteristic, bool need_confirm, @@ -2098,6 +2129,10 @@ int bt_gatt_client_create(const char *remote_address, bt_gatt_client_h *client) *client = (bt_gatt_client_h)client_s; gatt_client_list = g_slist_append(gatt_client_list, client_s); + + if (_bt_gatt_client_update_all(*client) == BT_ERROR_NONE) + client_s->services_discovered = true; + return ret; } @@ -2202,14 +2237,68 @@ int bt_gatt_client_read_value(bt_gatt_h gatt_handle, int bt_gatt_client_write_value(bt_gatt_h gatt_handle, bt_gatt_client_request_completed_cb callback, void *user_data) { + int ret = BT_ERROR_NONE; + bt_gatt_common_s *c = (bt_gatt_common_s *)gatt_handle; + bt_gatt_client_cb_data_s *cb_data; + BT_CHECK_GATT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(gatt_handle); BT_CHECK_INPUT_PARAMETER(callback); - /* Will implement after synch bluetooth-frwk */ - - return BT_ERROR_NOT_SUPPORTED; + if (__bt_gatt_client_is_in_progress()) { + BT_ERR("Operation is in progress"); + return BT_ERROR_NOW_IN_PROGRESS; + } + + cb_data = malloc(sizeof(bt_gatt_client_cb_data_s)); + if (cb_data == NULL) { + BT_ERR("Cannot alloc cb_data"); + return BT_ERROR_OPERATION_FAILED; + } + + cb_data->gatt_handle = gatt_handle; + cb_data->user_data = user_data; + + if (c->type == BT_GATT_TYPE_CHARACTERISTIC) { + bt_gatt_characteristic_s *chr = (bt_gatt_characteristic_s *)gatt_handle; + + BT_DBG("path : %s", chr->path); + if (chr->write_type == BT_GATT_WRITE_TYPE_WRITE) + ret = _bt_get_error_code(bluetooth_gatt_set_characteristics_value_by_type( + chr->path, (guint8 *)chr->value, chr->value_length, + BT_GATT_PROPERTY_WRITE)); + else if (chr->write_type == BT_GATT_WRITE_TYPE_WRITE_NO_RESPONSE) + ret = _bt_get_error_code(bluetooth_gatt_set_characteristics_value_by_type( + chr->path, (guint8 *)chr->value, chr->value_length, + BT_GATT_PROPERTY_WRITE_WITHOUT_RESPONSE)); + else { + BT_ERR("Unknow write type : %d", chr->write_type); + ret = BT_ERROR_OPERATION_FAILED; + } + if (ret != BT_ERROR_NONE) { + g_free(cb_data); + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + } else { + _bt_set_cb(BT_EVENT_GATT_CLIENT_WRITE_CHARACTERISTIC, callback, cb_data); + } + } else if (c->type == BT_GATT_TYPE_DESCRIPTOR) { + bt_gatt_descriptor_s *desc = (bt_gatt_descriptor_s *)gatt_handle; + + ret = _bt_get_error_code(bluetooth_gatt_write_descriptor_value(desc->path, + (guint8 *)desc->value, desc->value_length)); + if (ret != BT_ERROR_NONE) { + g_free(cb_data); + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + } else { + _bt_set_cb(BT_EVENT_GATT_CLIENT_WRITE_DESCRIPTOR, callback, cb_data); + } + } else { + BT_ERR("Invalid handle type for write "); + g_free(cb_data); + } + + return ret; } static const bt_gatt_client_h __find_gatt_client(const char *remote_address) diff --git a/src/bluetooth-hid.c b/src/bluetooth-hid.c index 729275d..c84059e 100644 --- a/src/bluetooth-hid.c +++ b/src/bluetooth-hid.c @@ -148,3 +148,185 @@ int bt_hid_host_disconnect(const char *remote_address) } return error; } + +int bt_hid_device_activate(bt_hid_device_connection_state_changed_cb callback, void * user_data) +{ + int error; + BT_CHECK_HID_DEVICE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(callback); + + error = bluetooth_hid_device_init(_bt_hid_event_proxy, user_data); + error = _bt_get_error_code(error); + if (BT_ERROR_NONE != error) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); + return error; + } + + error = bluetooth_hid_device_activate(); + error = _bt_get_error_code(error); + if (error != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); + return error; + } + + _bt_set_cb(BT_EVENT_HID_DEVICE_CONNECTION_STATUS, callback, user_data); + + return BT_ERROR_NONE; +} + +int bt_hid_device_deactivate(void) +{ + int error; + BT_CHECK_HID_DEVICE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + + error = bluetooth_hid_device_deinit(); + error = _bt_get_error_code(error); + if (BT_ERROR_NONE != error) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); + return error; + } + + error = bluetooth_hid_device_deactivate(); + error = _bt_get_error_code(error); + if (error != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); + return error; + } + + _bt_unset_cb(BT_EVENT_HID_DEVICE_CONNECTION_STATUS); + + return BT_ERROR_NONE; +} + +int bt_hid_device_connect(const char *remote_address) +{ + int error; + BT_CHECK_HID_DEVICE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_DBG("+"); + error = bluetooth_hid_device_connect(remote_address); + error = _bt_get_error_code(error); + if (BT_ERROR_NONE != error) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); + return error; + } + return BT_ERROR_NONE; +} +int bt_hid_device_disconnect(const char *remote_address) +{ + int error; + BT_CHECK_HID_DEVICE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + error = bluetooth_hid_device_disconnect(remote_address); + error = _bt_get_error_code(error); + if (error != BT_ERROR_NONE) + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); + return error; +} + +int bt_hid_device_send_mouse_event(const char *remote_address, + const bt_hid_mouse_data_s *mouse_data) +{ + int ret; + BT_CHECK_HID_DEVICE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + + ret = bluetooth_hid_device_send_mouse_event(remote_address, + *(hid_send_mouse_event_t*)mouse_data); + if (ret <= 0) { + if (ret == -1) { + /* write fail case */ + if (errno == EACCES || errno == EPERM) + set_last_result(BT_ERROR_PERMISSION_DENIED); + else if (errno == EAGAIN || errno == EWOULDBLOCK) + set_last_result(BT_ERROR_AGAIN); + else + set_last_result(BT_ERROR_OPERATION_FAILED); + } else { + ret = _bt_get_error_code(ret); + set_last_result(ret); + } + + BT_ERR("Write failed, ret = %d", ret); + } + + return ret; +} + +int bt_hid_device_send_key_event(const char *remote_address, + const bt_hid_key_data_s *key_data) +{ + int ret; + BT_CHECK_HID_DEVICE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + + ret = bluetooth_hid_device_send_key_event(remote_address, + *(hid_send_key_event_t*)key_data); + if (ret <= 0) { + if (ret == -1) { + /* write fail case */ + if (errno == EACCES || errno == EPERM) + set_last_result(BT_ERROR_PERMISSION_DENIED); + else if (errno == EAGAIN || errno == EWOULDBLOCK) + set_last_result(BT_ERROR_AGAIN); + else + set_last_result(BT_ERROR_OPERATION_FAILED); + } else { + ret = _bt_get_error_code(ret); + set_last_result(ret); + } + + BT_ERR("Write failed, ret = %d", ret); + } + + return ret; +} + +int bt_hid_device_reply_to_report(const char *remote_address, + bluetooth_hid_header_type_t htype, + bluetooth_hid_param_type_t ptype, + const char *data, unsigned int data_len) +{ + int ret; + BT_CHECK_HID_DEVICE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + ret = bluetooth_hid_device_reply_to_report(remote_address, htype, + ptype, data, data_len); + if (ret <= 0) { + if (ret == -1) { + /* write fail case */ + if (errno == EACCES || errno == EPERM) + set_last_result(BT_ERROR_PERMISSION_DENIED); + else if (errno == EAGAIN || errno == EWOULDBLOCK) + set_last_result(BT_ERROR_AGAIN); + else + set_last_result(BT_ERROR_OPERATION_FAILED); + } else { + ret = _bt_get_error_code(ret); + set_last_result(ret); + } + + BT_ERR("Write failed, ret = %d", ret); + } + + return ret; +} + +int bt_hid_device_set_data_received_cb(bt_hid_device_data_received_cb callback, void *user_data) +{ + BT_CHECK_HID_DEVICE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(callback); + _bt_set_cb(BT_EVENT_HID_DEVICE_DATA_RECEIVED, callback, user_data); + return BT_ERROR_NONE; +} + +int bt_hid_device_unset_data_received_cb() +{ + BT_CHECK_HID_DEVICE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + _bt_unset_cb(BT_EVENT_HID_DEVICE_DATA_RECEIVED); + return BT_ERROR_NONE; +} diff --git a/src/bluetooth-socket.c b/src/bluetooth-socket.c index 661f083..52c6a69 100644 --- a/src/bluetooth-socket.c +++ b/src/bluetooth-socket.c @@ -103,12 +103,18 @@ int bt_socket_listen(int socket_fd, int max_pending_connections) int bt_socket_accept(int socket_fd) { + int error_code = BT_ERROR_NONE; + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); - /* Will implement after synch bluetooth-frwk */ + error_code = _bt_get_error_code(bluetooth_rfcomm_accept_connection(socket_fd)); + if (error_code != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), + error_code); + } - return BT_ERROR_NOT_SUPPORTED; + return error_code; } int bt_socket_reject(int socket_fd) @@ -129,39 +135,57 @@ int bt_socket_reject(int socket_fd) int bt_socket_create_rfcomm_ex(const char *uuid, const char *bus_name, const char *object_path) { + int error_code = BT_ERROR_NONE; + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(uuid); BT_CHECK_INPUT_PARAMETER(bus_name); BT_CHECK_INPUT_PARAMETER(object_path); - /* Will implement after synch bluetooth-frwk */ + error_code = bluetooth_rfcomm_create_socket_ex(uuid, bus_name, object_path); + if (error_code != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), + error_code); + } - return BT_ERROR_NOT_SUPPORTED; + return error_code; } int bt_socket_destroy_rfcomm_ex(const char *uuid) { + int error_code = BT_ERROR_NONE; + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(uuid); - /* Will implement after synch bluetooth-frwk */ + error_code = _bt_get_error_code(bluetooth_rfcomm_remove_socket_ex(uuid)); + if (error_code != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), + error_code); + } - return BT_ERROR_NOT_SUPPORTED; + return error_code; } int bt_socket_listen_and_accept_rfcomm_ex(const char *uuid, int max_pending_connections, const char* bus_name, const char *object_path) { + int error_code = BT_ERROR_NONE; + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(uuid); BT_CHECK_INPUT_PARAMETER(bus_name); BT_CHECK_INPUT_PARAMETER(object_path); - /* Will implement after synch bluetooth-frwk */ + error_code = _bt_get_error_code(bluetooth_rfcomm_listen_and_accept_ex(uuid, max_pending_connections, bus_name, object_path)); + if (error_code != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), + error_code); + } - return BT_ERROR_NOT_SUPPORTED; + return error_code; } int bt_socket_connect_rfcomm(const char *remote_address, const char *remote_port_uuid)