From: Wootak Jung Date: Thu, 4 Feb 2021 23:30:44 +0000 (+0900) Subject: Add advertising data setting function for TDS AD type X-Git-Tag: accepted/tizen/unified/20210209.124411^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=344f84b6c17877cfffcb7de51baa9aea5501739d;p=platform%2Fcore%2Fapi%2Fbluetooth.git Add advertising data setting function for TDS AD type Change-Id: Ia8567a27457adf75a488a633d0e8833690b80973 Signed-off-by: Wootak Jung --- diff --git a/include/bluetooth_internal.h b/include/bluetooth_internal.h index 433ac5a..93fdbb4 100644 --- a/include/bluetooth_internal.h +++ b/include/bluetooth_internal.h @@ -1148,6 +1148,36 @@ int bt_adapter_le_set_advertising_custom_tx_power_level(bt_advertiser_h advertis int bt_adapter_le_set_advertising_interval(bt_advertiser_h advertiser, int interval_min, int interval_max); /** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Set advertising transport discovery data(TDS) + * @since_tizen 6.5 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * + * @param[in] advertiser The handle of advertiser + * @param[in] pkt_type The packet type + * @param[in] org_id Organization identifier + * @param[in] tds_flags The TDS flags. Table 3.3, TDS Specification + * @param[in] transport_data The transport data + * @param[in] transport_data_len The length of the transport data + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + * @see bt_adapter_le_create_advertiser() + * @see bt_adapter_le_start_advertising_new() + */ +int bt_adapter_le_set_advertising_transport_discovery_data(bt_advertiser_h advertiser, + bt_adapter_le_packet_type_e pkt_type, + bt_tds_transport_e org_id, char tds_flags, + unsigned char *transport_data, unsigned int transport_data_len); + +/** * @internal * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE * @brief Retrieves the address of the devices connected with the specific profile. diff --git a/src/bluetooth-adapter.c b/src/bluetooth-adapter.c index 1fd8423..248aaa4 100644 --- a/src/bluetooth-adapter.c +++ b/src/bluetooth-adapter.c @@ -2485,6 +2485,59 @@ int bt_adapter_le_set_advertising_tx_power_level(bt_advertiser_h advertiser, return ret; } +static unsigned char __bt_tds_set_org_id(bt_tds_transport_e org_id) +{ + BT_INFO("organization id: %d", org_id); + switch (org_id) { + case BT_TDS_TRANSPORT_BT: + return 0x01; + case BT_TDS_TRANSPORT_WIFI_NAN: + return 0x02; + case BT_TDS_TRANSPORT_WIFI_SVC_ADV: + return 0x03; + case BT_TDS_TRANSPORT_CUSTOM: + return 0x04; + default: + BT_ERR("Invalid organization id"); + return 0x00; + } +} + +int bt_adapter_le_set_advertising_transport_discovery_data(bt_advertiser_h advertiser, + bt_adapter_le_packet_type_e pkt_type, + bt_tds_transport_e org_id, char tds_flags, + unsigned char *transport_data, unsigned int transport_data_len) +{ + int ret = BT_ERROR_NONE; + char *data_ptr = NULL; + int data_len; + unsigned char *adv_data = NULL; + + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(advertiser); + + __bt_find_adv_data_type(advertiser, pkt_type, + BT_ADAPTER_LE_ADVERTISING_DATA_TRANSPORT_DISCOVERY, + &data_ptr, &data_len); + if (data_ptr) { + BT_ERR("Aleady existed"); + return BT_ERROR_ALREADY_DONE; + } + + adv_data = g_malloc0(transport_data_len + 3); /* org_id + tds_flags + transport_data_len + transport_data */ + adv_data[0] = __bt_tds_set_org_id(org_id); + adv_data[1] = tds_flags; + adv_data[2] = transport_data_len; + memcpy(adv_data + 3, transport_data, transport_data_len); + + ret = bt_adapter_le_add_advertising_data(advertiser, + pkt_type, BT_ADAPTER_LE_ADVERTISING_DATA_TRANSPORT_DISCOVERY, + adv_data, transport_data_len + 3); + g_free(adv_data); + return ret; +} + int bt_adapter_le_clear_advertising_data(bt_advertiser_h advertiser, bt_adapter_le_packet_type_e pkt_type) { diff --git a/src/bluetooth-tds.c b/src/bluetooth-tds.c index 29b0533..cb23d79 100644 --- a/src/bluetooth-tds.c +++ b/src/bluetooth-tds.c @@ -162,20 +162,17 @@ int bt_tds_provider_create(bt_tds_provider_h *provider, bt_tds_transport_e trans switch (transport) { case BT_TDS_TRANSPORT_BT: - error_code = BT_ERROR_NOT_SUPPORTED; - BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), error_code); - return error_code; + tds_transport = BLUETOOTH_TDS_TRANSPORT_BT; + break; case BT_TDS_TRANSPORT_CUSTOM: tds_transport = BLUETOOTH_TDS_TRANSPORT_CUSTOM; break; case BT_TDS_TRANSPORT_WIFI_NAN: - error_code = BT_ERROR_NOT_SUPPORTED; - BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), error_code); - return error_code; + tds_transport = BLUETOOTH_TDS_TRANSPORT_WIFI_NAN; + break; case BT_TDS_TRANSPORT_WIFI_SVC_ADV: - error_code = BT_ERROR_NOT_SUPPORTED; - BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), error_code); - return error_code; + tds_transport = BLUETOOTH_TDS_TRANSPORT_WIFI_SVC_ADV; + break; default: error_code = BT_ERROR_INVALID_PARAMETER; BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), error_code); @@ -456,6 +453,16 @@ int _bt_tds_parse_transport_blocks(bt_tds_transport_block_list_s **info, /* Get Transport Name */ td->transport = data[index -2]; + if (td->transport == 0x01) + td->transport = BT_TDS_TRANSPORT_BT; + else if (td->transport == 0x02) + td->transport = BT_TDS_TRANSPORT_WIFI_NAN; + else if (td->transport == 0x03) + td->transport = BT_TDS_TRANSPORT_WIFI_SVC_ADV; + else if (td->transport == 0x04) + td->transport = BT_TDS_TRANSPORT_CUSTOM; + else + td->transport = BT_TDS_TRANSPORT_INVALID; /* Get Transport Data Block Incomplete status */ if (flags & 0x04) diff --git a/tests/test/bt_unit_test.c b/tests/test/bt_unit_test.c index 3a33ef7..0966920 100644 --- a/tests/test/bt_unit_test.c +++ b/tests/test/bt_unit_test.c @@ -3619,7 +3619,7 @@ int test_set_params(int test_id, char *param) break; case BT_UNIT_TEST_FUNCTION_ADAPTER_LE_ADD_ADVERTISING_DATA: param_count = 1; - TC_PRT("Select advertising data \n (0 : Service uuid, 1: Service solicitation 2 : Appearance & Tx power, 3 : All, 4 : ANCS, 6: Multiple service data"); + TC_PRT("Select advertising data \n (0 : Service uuid, 1: Service solicitation 2 : Appearance & Tx power, 3 : All, 4 : ANCS, 6: Multiple service data, 7: Transport discovery data"); TC_PRT("\t (Default scan response : Service Data &Local name & Manufacturer data)"); break; case BT_UNIT_TEST_FUNCTION_ADAPTER_LE_SET_ADVERTISING_MODE: @@ -5070,6 +5070,19 @@ int test_input_callback(void *data) TC_PRT("set device name [0x%04x]", ret); return 0; + case 7: { /* Transport Discovery Data */ + unsigned char transport_data[20] = { + 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x08, 0x80, + 0x02, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00, 0x12, 0x10, 0x00}; + + ret = bt_adapter_le_set_advertising_transport_discovery_data(advertiser, + BT_ADAPTER_LE_PACKET_ADVERTISING, + BT_TDS_TRANSPORT_WIFI_NAN, + 0x02, transport_data, sizeof(transport_data)); + if (ret != BT_ERROR_NONE) + TC_PRT("set transport discovery data [0x%04x]", ret); + } + return 0; default: TC_PRT("No adv data"); break;