From 33c7ec91c565fa60c6d79c15036b0317fbfa082b Mon Sep 17 00:00:00 2001 From: Ayush Garg Date: Thu, 31 Aug 2023 20:24:37 +0530 Subject: [PATCH] BT 5.0: Add APIs to support set/read PHYs This patch adds support for the following APIs: 1. bluetooth_gatt_server_read_phy() 2. bluetooth_gatt_server_set_phy() 3. bluetooth_gatt_client_read_phy() 4. bluetooth_gatt_client_set_phy() Change-Id: I641f95954ed88b419bf208a346a8c16c95e4b474 Signed-off-by: Ayush Garg --- bt-api/bt-common.c | 4 + bt-api/bt-event-handler.c | 57 +++++ bt-api/bt-gatt-client.c | 56 +++++ bt-api/bt-gatt-service.c | 56 +++++ bt-oal/include/oal-event.h | 32 +++ bt-service/services/bt-request-handler.c | 66 ++++++ bt-service/services/bt-service-event-receiver.c | 4 + bt-service/services/bt-service-event-sender.c | 16 ++ bt-service/services/gatt/bt-service-gatt.c | 297 ++++++++++++++++++++++-- bt-service/services/include/bt-service-gatt.h | 8 + include/bluetooth-api.h | 93 ++++++++ include/bt-internal-types.h | 8 + 12 files changed, 680 insertions(+), 17 deletions(-) diff --git a/bt-api/bt-common.c b/bt-api/bt-common.c index 96d7d30..62252e1 100644 --- a/bt-api/bt-common.c +++ b/bt-api/bt-common.c @@ -736,6 +736,10 @@ const char *_bt_convert_service_function_to_string(int function) {BT_GATT_REGISTER_APPLICATION, "BT_GATT_REGISTER_APPLICATION"}, {BT_GATT_REGISTER_SERVICE, "BT_GATT_REGISTER_SERVICE"}, {BT_GATT_SEND_RESPONSE, "BT_GATT_SEND_RESPONSE"}, + {BT_GATT_SERVER_READ_PHY, "BT_GATT_SERVER_READ_PHY"}, + {BT_GATT_SERVER_SET_PHY, "BT_GATT_SERVER_SET_PHY"}, + {BT_GATT_CLIENT_READ_PHY, "BT_GATT_CLIENT_READ_PHY"}, + {BT_GATT_CLIENT_SET_PHY, "BT_GATT_CLIENT_SET_PHY"}, {BT_LE_IPSP_INIT, "BT_LE_IPSP_INIT"}, {BT_LE_IPSP_DEINIT, "BT_LE_IPSP_DEINIT"}, {BT_LE_IPSP_CONNECT, "BT_LE_IPSP_CONNECT"}, diff --git a/bt-api/bt-event-handler.c b/bt-api/bt-event-handler.c index 7b39fde..99f0568 100644 --- a/bt-api/bt-event-handler.c +++ b/bt-api/bt-event-handler.c @@ -1246,6 +1246,31 @@ void __bt_adapter_le_event_filter(GDBusConnection *connection, } } +static void _bt_get_phy_info(GVariant *parameters, bluetooth_le_phy_info_t *phy_info, int *result) +{ + const char *address = NULL; + bluetooth_device_address_t dev_address = { {0} }; + int tx_phy; + int rx_phy; + int status; + + BT_DBG("BT_GATT_SERVER_PHY_UPDATED"); + g_variant_get(parameters, "(i&siii)", result, &address, &tx_phy, &rx_phy, &status); + + BT_DBG("Result [%d] Address [%s] TX_PHY [%d] RX_PHY[%d] status [%d]", + *result, address, tx_phy, rx_phy, status); + + _bt_convert_addr_string_to_type(dev_address.addr, address); + + memset(phy_info, 0x00, sizeof(bluetooth_le_phy_info_t)); + memcpy(phy_info->device_address.addr, + dev_address.addr, BLUETOOTH_ADDRESS_LENGTH); + + phy_info->tx_phy = tx_phy; + phy_info->rx_phy = rx_phy; + phy_info->status = status; +} + void __bt_device_event_filter(GDBusConnection *connection, const gchar *sender_name, const gchar *object_path, @@ -1321,6 +1346,38 @@ void __bt_device_event_filter(GDBusConnection *connection, _bt_common_event_cb(BLUETOOTH_EVENT_GATT_CLIENT_DISCONNECTED, result, &dev_address, event_info->cb, event_info->user_data); + } else if (strcasecmp(signal_name, BT_GATT_SERVER_PHY_UPDATED) == 0) { + bluetooth_le_phy_info_t phy_info; + + _bt_get_phy_info(parameters, &phy_info, &result); + + _bt_common_event_cb(BLUETOOTH_EVENT_GATT_SERVER_PHY_UPDATED, + result, &phy_info, + event_info->cb, event_info->user_data); + } else if (strcasecmp(signal_name, BT_GATT_SERVER_PHY_READ) == 0) { + bluetooth_le_phy_info_t phy_info; + + _bt_get_phy_info(parameters, &phy_info, &result); + + _bt_common_event_cb(BLUETOOTH_EVENT_GATT_SERVER_PHY_READ, + result, &phy_info, + event_info->cb, event_info->user_data); + } else if (strcasecmp(signal_name, BT_GATT_CLIENT_PHY_UPDATED) == 0) { + bluetooth_le_phy_info_t phy_info; + + _bt_get_phy_info(parameters, &phy_info, &result); + + _bt_common_event_cb(BLUETOOTH_EVENT_GATT_CLIENT_PHY_UPDATED, + result, &phy_info, + event_info->cb, event_info->user_data); + } else if (strcasecmp(signal_name, BT_GATT_CLIENT_PHY_READ) == 0) { + bluetooth_le_phy_info_t phy_info; + + _bt_get_phy_info(parameters, &phy_info, &result); + + _bt_common_event_cb(BLUETOOTH_EVENT_GATT_CLIENT_PHY_READ, + result, &phy_info, + event_info->cb, event_info->user_data); } else if (strcasecmp(signal_name, BT_GATT_REQ_ATT_MTU_CHANGED) == 0) { const char *address = NULL; bluetooth_device_address_t dev_address = { {0} }; diff --git a/bt-api/bt-gatt-client.c b/bt-api/bt-gatt-client.c index 404fcda..a370502 100644 --- a/bt-api/bt-gatt-client.c +++ b/bt-api/bt-gatt-client.c @@ -2788,3 +2788,59 @@ BT_EXPORT_API int bluetooth_gatt_client_deinit( BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); return result; } + +BT_EXPORT_API int bluetooth_gatt_client_read_phy(const bluetooth_device_address_t *device_address) +{ + int result; + + BT_CHECK_PARAMETER(device_address, return); + BT_CHECK_ENABLED(return); + + BT_INIT_PARAMS(); + BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); + + g_array_append_vals(in_param1, device_address, sizeof(bluetooth_device_address_t)); + + result = _bt_send_request(BT_BLUEZ_SERVICE, BT_GATT_CLIENT_READ_PHY, + in_param1, in_param2, in_param3, in_param4, &out_param); + + if (result != BLUETOOTH_ERROR_NONE) + BT_INFO("GATT Client Read PHY failed result [%d]", result); + else + BT_INFO("GATT Client Read PHY successful"); + + BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); + + return result; +} + +BT_EXPORT_API int bluetooth_gatt_client_set_phy(const bluetooth_device_address_t *device_address, + int tx_phy, int rx_phy, int phy_options) +{ + int result; + + BT_CHECK_PARAMETER(device_address, return); + BT_CHECK_ENABLED(return); + + BT_INFO("Set PHY: Tx[%d], Rx[%d], Phy_options[%d]", tx_phy, rx_phy, phy_options); + + BT_INIT_PARAMS(); + BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); + + g_array_append_vals(in_param1, device_address, sizeof(bluetooth_device_address_t)); + g_array_append_vals(in_param2, &tx_phy, sizeof(int)); + g_array_append_vals(in_param3, &rx_phy, sizeof(int)); + g_array_append_vals(in_param4, &phy_options, sizeof(int)); + + result = _bt_send_request(BT_BLUEZ_SERVICE, BT_GATT_CLIENT_SET_PHY, + in_param1, in_param2, in_param3, in_param4, &out_param); + + if (result != BLUETOOTH_ERROR_NONE) + BT_INFO("GATT Client Set PHY failed result [%d]", result); + else + BT_INFO("GATT Client Set PHY successful"); + + BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); + + return result; +} diff --git a/bt-api/bt-gatt-service.c b/bt-api/bt-gatt-service.c index 65ab79f..d3812d8 100644 --- a/bt-api/bt-gatt-service.c +++ b/bt-api/bt-gatt-service.c @@ -3373,3 +3373,59 @@ void cleanup_gatt_acquire_fd(int handle) bluetooth_characteristic_info_free(chr_info); } } + +BT_EXPORT_API int bluetooth_gatt_server_read_phy(const bluetooth_device_address_t *device_address) +{ + int result; + + BT_CHECK_PARAMETER(device_address, return); + BT_CHECK_ENABLED(return); + + BT_INIT_PARAMS(); + BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); + + g_array_append_vals(in_param1, device_address, sizeof(bluetooth_device_address_t)); + + result = _bt_send_request(BT_BLUEZ_SERVICE, BT_GATT_SERVER_READ_PHY, + in_param1, in_param2, in_param3, in_param4, &out_param); + + if (result != BLUETOOTH_ERROR_NONE) + BT_INFO("GATT Server Read PHY failed result [%d]", result); + else + BT_INFO("GATT Server Read PHY successful"); + + BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); + + return result; +} + +BT_EXPORT_API int bluetooth_gatt_server_set_phy(const bluetooth_device_address_t *device_address, + int tx_phy, int rx_phy, int phy_options) +{ + int result; + + BT_CHECK_PARAMETER(device_address, return); + BT_CHECK_ENABLED(return); + + BT_INFO("Set PHY: Tx[%d], Rx[%d], Phy_options[%d]", tx_phy, rx_phy, phy_options); + + BT_INIT_PARAMS(); + BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); + + g_array_append_vals(in_param1, device_address, sizeof(bluetooth_device_address_t)); + g_array_append_vals(in_param2, &tx_phy, sizeof(int)); + g_array_append_vals(in_param3, &rx_phy, sizeof(int)); + g_array_append_vals(in_param4, &phy_options, sizeof(int)); + + result = _bt_send_request(BT_BLUEZ_SERVICE, BT_GATT_SERVER_SET_PHY, + in_param1, in_param2, in_param3, in_param4, &out_param); + + if (result != BLUETOOTH_ERROR_NONE) + BT_INFO("GATT Server Set PHY failed result [%d]", result); + else + BT_INFO("GATT Server Set PHY successful"); + + BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); + + return result; +} diff --git a/bt-oal/include/oal-event.h b/bt-oal/include/oal-event.h index 16b3c0f..7fd4742 100644 --- a/bt-oal/include/oal-event.h +++ b/bt-oal/include/oal-event.h @@ -165,6 +165,10 @@ extern "C" { EVENT(OAL_EVENT_GATTS_IND_CONFIRM) /* gatts Indiction confirmation from remote client */\ EVENT(OAL_EVENT_GATTS_NOTIFICATION) /* gatts Notification from remote client */\ EVENT(OAL_EVENT_GATTS_MTU_CHANGED) /* gatts MTU changed */\ + EVENT(OAL_EVENT_GATTS_PHY_UPDATED) /* gatts PHY UPDATED event */\ + EVENT(OAL_EVENT_GATTS_PHY_READ) /* gatts PHY READ event */\ + EVENT(OAL_EVENT_GATTC_PHY_UPDATED) /* gattc PHY UPDATED event */\ + EVENT(OAL_EVENT_GATTC_PHY_READ) /* gattc PHY READ event */\ EVENT(OAL_EVENT_GATTC_REGISTRATION) /* gattc Registration Confirmed */\ EVENT(OAL_EVENT_GATTC_CONNECTION_COMPLETED) /* gattc connection completed */\ EVENT(OAL_EVENT_GATTC_DISCONNECTION_COMPLETED) /* gattc disconnection */\ @@ -361,6 +365,34 @@ typedef struct { int mtu_size; } event_gatts_mtu_changed_t; +typedef struct{ + int conn_id; + int tx_phy; + int rx_phy; + int status; +} event_gatts_phy_updated_t; + +typedef struct{ + int conn_id; + int tx_phy; + int rx_phy; + int status; +} event_gatts_phy_read_t; + +typedef struct{ + int conn_id; + int tx_phy; + int rx_phy; + int status; +} event_gattc_phy_updated_t; + +typedef struct{ + int conn_id; + int tx_phy; + int rx_phy; + int status; +} event_gattc_phy_read_t; + typedef struct { int server_inst; } event_ble_adv_status; diff --git a/bt-service/services/bt-request-handler.c b/bt-service/services/bt-request-handler.c index 4370d50..bbbf3da 100644 --- a/bt-service/services/bt-request-handler.c +++ b/bt-service/services/bt-request-handler.c @@ -2755,6 +2755,68 @@ int __bt_bluez_request(int function_name, result = _bt_gatt_server_update_attribute_value(app, instance_id, ¶m); break; } + case BT_GATT_SERVER_READ_PHY: { + bluetooth_device_address_t address = { {0} }; + + sender = (char*)g_dbus_method_invocation_get_sender(context); + + __bt_service_get_parameters(in_param1, + &address, sizeof(bluetooth_device_address_t)); + + result = _bt_gatt_server_read_phy(&address); + break; + } + case BT_GATT_SERVER_SET_PHY: { + bluetooth_device_address_t address = { {0} }; + int tx_phy; + int rx_phy; + int phy_options; + + sender = (char*)g_dbus_method_invocation_get_sender(context); + + __bt_service_get_parameters(in_param1, + &address, sizeof(bluetooth_device_address_t)); + __bt_service_get_parameters(in_param2, + &tx_phy, sizeof(int)); + __bt_service_get_parameters(in_param3, + &rx_phy, sizeof(int)); + __bt_service_get_parameters(in_param4, + &phy_options, sizeof(int)); + + result = _bt_gatt_server_set_phy(&address, tx_phy, rx_phy, phy_options); + break; + } + case BT_GATT_CLIENT_READ_PHY: { + bluetooth_device_address_t address = { {0} }; + + sender = (char*)g_dbus_method_invocation_get_sender(context); + + __bt_service_get_parameters(in_param1, + &address, sizeof(bluetooth_device_address_t)); + + result = _bt_gatt_client_read_phy(&address); + break; + } + case BT_GATT_CLIENT_SET_PHY: { + bluetooth_device_address_t address = { {0} }; + int tx_phy; + int rx_phy; + int phy_options; + + sender = (char*)g_dbus_method_invocation_get_sender(context); + + __bt_service_get_parameters(in_param1, + &address, sizeof(bluetooth_device_address_t)); + __bt_service_get_parameters(in_param2, + &tx_phy, sizeof(int)); + __bt_service_get_parameters(in_param3, + &rx_phy, sizeof(int)); + __bt_service_get_parameters(in_param4, + &phy_options, sizeof(int)); + + result = _bt_gatt_client_set_phy(&address, tx_phy, rx_phy, phy_options); + break; + } case BT_GET_ATT_MTU: { bluetooth_device_address_t address = { {0} }; unsigned int mtu = 0; @@ -5589,6 +5651,10 @@ gboolean __bt_service_check_privilege(int function_name, case BT_GATT_SERVER_UPDATE_VALUE: case BT_GATT_SERVER_DEREGISTER: #endif + case BT_GATT_SERVER_READ_PHY: + case BT_GATT_SERVER_SET_PHY: + case BT_GATT_CLIENT_READ_PHY: + case BT_GATT_CLIENT_SET_PHY: case BT_REQ_ATT_MTU: case BT_PBAP_CONNECT: case BT_PBAP_DISCONNECT: diff --git a/bt-service/services/bt-service-event-receiver.c b/bt-service/services/bt-service-event-receiver.c index 74ee664..1e96a82 100644 --- a/bt-service/services/bt-service-event-receiver.c +++ b/bt-service/services/bt-service-event-receiver.c @@ -376,6 +376,8 @@ static gboolean __bt_handle_oal_events(gpointer data) /* Tizen Platform Specific */ case OAL_EVENT_GATTS_NOTIFICATION: /* gatts Notification changed event */\ case OAL_EVENT_GATTS_MTU_CHANGED: /* gatts MTU changed event */\ + case OAL_EVENT_GATTS_PHY_UPDATED: /* gatts PHY UPDATED event */\ + case OAL_EVENT_GATTS_PHY_READ: /* gatts PHY READ event */\ if (adapter_gatt_cb) adapter_gatt_cb(event_type, event_data); if (adapter_le_cb) @@ -399,6 +401,8 @@ static gboolean __bt_handle_oal_events(gpointer data) case OAL_EVENT_GATTC_NOTIFY_DATA: case OAL_EVENT_GATTC_CONNECTION_COMPLETED: case OAL_EVENT_GATTC_REGISTRATION: + case OAL_EVENT_GATTC_PHY_UPDATED: /* gattc PHY UPDATED event */\ + case OAL_EVENT_GATTC_PHY_READ: /* gattc PHY READ event */\ if (adapter_gatt_cb) adapter_gatt_cb(event_type, event_data); if (adapter_le_cb) diff --git a/bt-service/services/bt-service-event-sender.c b/bt-service/services/bt-service-event-sender.c index d16b7b3..5690065 100644 --- a/bt-service/services/bt-service-event-sender.c +++ b/bt-service/services/bt-service-event-sender.c @@ -478,6 +478,22 @@ int _bt_send_event(int event_type, int event, GVariant *param) case BLUETOOTH_EVENT_GATT_SERVER_ATT_MTU_CHANGED: signal = BT_GATT_SERVER_ATT_MTU_CHANGED; break; + case BLUETOOTH_EVENT_GATT_SERVER_PHY_UPDATED: + signal = BT_GATT_SERVER_PHY_UPDATED; + BT_INFO_C("### PHY UPDATED Event [GATT server]"); + break; + case BLUETOOTH_EVENT_GATT_SERVER_PHY_READ: + signal = BT_GATT_SERVER_PHY_READ; + BT_INFO_C("### PHY READ Event [GATT server]"); + break; + case BLUETOOTH_EVENT_GATT_CLIENT_PHY_UPDATED: + signal = BT_GATT_CLIENT_PHY_UPDATED; + BT_INFO_C("### PHY UPDATED Event [GATT client]"); + break; + case BLUETOOTH_EVENT_GATT_CLIENT_PHY_READ: + signal = BT_GATT_CLIENT_PHY_READ; + BT_INFO_C("### PHY READ Event [GATT client]"); + break; #ifndef GATT_DIRECT case BLUETOOTH_EVENT_GATT_SERVER_VALUE_CHANGED: signal = BT_GATT_VALUE_CHANGED; diff --git a/bt-service/services/gatt/bt-service-gatt.c b/bt-service/services/gatt/bt-service-gatt.c index ca91725..250eb08 100644 --- a/bt-service/services/gatt/bt-service-gatt.c +++ b/bt-service/services/gatt/bt-service-gatt.c @@ -482,6 +482,22 @@ static void __bt_register_default_gatt_client() g_free(uuid_str); } +static struct gatt_server_info_t *__bt_find_remote_gatt_server_info_from_conn_id(int conn_id) +{ + GSList *l; + struct gatt_server_info_t *info = NULL; + + for (l = gatt_server_info_list; l != NULL; l = g_slist_next(l)) { + info = (struct gatt_server_info_t*)l->data; + if (info == NULL) + continue; + + if (info->connection_id == conn_id) + return info; + } + return NULL; +} + int _bt_gatt_init(void) { const char *stack_name = NULL; @@ -2589,6 +2605,118 @@ static void __bt_handle_gatt_mtu_changed_event(event_gatts_mtu_changed_t *event) param); } +static void __bt_handle_gatt_phy_updated_event(event_gatts_phy_updated_t *event) +{ + int result = BLUETOOTH_ERROR_NONE; + struct gatt_client_info_t *conn_info = NULL; + GVariant *param = NULL; + + conn_info = __bt_find_remote_gatt_client_info_from_conn_id(event->conn_id); + if (conn_info == NULL) { + BT_ERR("Can't find connection Information"); + return; + } + + BT_INFO("Got connection Info GATT client:[%s] TX_PHY:[%d], RX_PHY:[%d], Status:[%d]", + conn_info->addr, event->tx_phy, event->rx_phy, event->status); + + param = g_variant_new("(isiii)", + result, + conn_info->addr, + event->tx_phy, + event->rx_phy, + event->status); + + /* Send event to BT-API */ + _bt_send_event(BT_GATT_SERVER_EVENT, + BLUETOOTH_EVENT_GATT_SERVER_PHY_UPDATED, + param); +} + +static void __bt_handle_gatt_phy_read_event(event_gatts_phy_read_t *event) +{ + int result = BLUETOOTH_ERROR_NONE; + struct gatt_client_info_t *conn_info = NULL; + GVariant *param = NULL; + + conn_info = __bt_find_remote_gatt_client_info_from_conn_id(event->conn_id); + if (conn_info == NULL) { + BT_ERR("Cant find connection Information"); + return; + } + + BT_INFO("Got connection Info GATT client:[%s] TX_PHY:[%d], RX_PHY:[%d], Status:[%d]", + conn_info->addr, event->tx_phy, event->rx_phy, event->status); + + param = g_variant_new("(isiii)", + result, + conn_info->addr, + event->tx_phy, + event->rx_phy, + event->status); + + /* Send event to BT-API */ + _bt_send_event(BT_GATT_SERVER_EVENT, + BLUETOOTH_EVENT_GATT_SERVER_PHY_READ, + param); +} + +static void __bt_handle_gatt_client_phy_updated_event(event_gattc_phy_updated_t *event) +{ + int result = BLUETOOTH_ERROR_NONE; + struct gatt_server_info_t *conn_info = NULL; + GVariant *param = NULL; + + conn_info = __bt_find_remote_gatt_server_info_from_conn_id(event->conn_id); + if (conn_info == NULL) { + BT_ERR("Cant find connection Information"); + return; + } + + BT_INFO("Got connection Info GATT client:[%s] TX_PHY:[%d], RX_PHY:[%d], Status:[%d]", + conn_info->addr, event->tx_phy, event->rx_phy, event->status); + + param = g_variant_new("(isiii)", + result, + conn_info->addr, + event->tx_phy, + event->rx_phy, + event->status); + + /* Send event to BT-API */ + _bt_send_event(BT_GATT_CLIENT_EVENT, + BLUETOOTH_EVENT_GATT_CLIENT_PHY_UPDATED, + param); +} + +static void __bt_handle_gatt_client_phy_read_event(event_gattc_phy_read_t *event) +{ + int result = BLUETOOTH_ERROR_NONE; + struct gatt_server_info_t *conn_info = NULL; + GVariant *param = NULL; + + conn_info = __bt_find_remote_gatt_server_info_from_conn_id(event->conn_id); + if (conn_info == NULL) { + BT_ERR("Cant find connection Information"); + return; + } + + BT_INFO("Got connection Info GATT client:[%s] TX_PHY:[%d], RX_PHY:[%d], Status:[%d]", + conn_info->addr, event->tx_phy, event->rx_phy, event->status); + + param = g_variant_new("(isiii)", + result, + conn_info->addr, + event->tx_phy, + event->rx_phy, + event->status); + + /* Send event to BT-API */ + _bt_send_event(BT_GATT_CLIENT_EVENT, + BLUETOOTH_EVENT_GATT_CLIENT_PHY_READ, + param); +} + static void __bt_gatt_event_handler(int event_type, gpointer event_data) { switch (event_type) { @@ -2680,6 +2808,26 @@ static void __bt_gatt_event_handler(int event_type, gpointer event_data) __bt_handle_gatt_mtu_changed_event((event_gatts_mtu_changed_t *)event_data); break; } + case OAL_EVENT_GATTS_PHY_UPDATED: { + BT_INFO("OAL Event: GATT Server PHY Updated event callback"); + __bt_handle_gatt_phy_updated_event((event_gatts_phy_updated_t *)event_data); + break; + } + case OAL_EVENT_GATTS_PHY_READ: { + BT_INFO("OAL Event: GATT Server PHY Read event callback"); + __bt_handle_gatt_phy_read_event((event_gatts_phy_read_t *)event_data); + break; + } + case OAL_EVENT_GATTC_PHY_UPDATED: { + BT_INFO("OAL Event: GATT Client PHY Updated event callback"); + __bt_handle_gatt_client_phy_updated_event((event_gattc_phy_updated_t *)event_data); + break; + } + case OAL_EVENT_GATTC_PHY_READ: { + BT_INFO("OAL Event: GATT Client PHY Read event callback"); + __bt_handle_gatt_client_phy_read_event((event_gattc_phy_read_t *)event_data); + break; + } case OAL_EVENT_GATTC_REGISTRATION: { BT_INFO("OAL Event: GATT Client instance Registered"); __bt_handle_client_instance_registered((event_gattc_register_t *) event_data); @@ -3105,6 +3253,138 @@ int _bt_gatt_server_update_attribute_value(char *sender, int instance_id, return BLUETOOTH_ERROR_NONE; } +int _bt_gatt_server_set_phy(bluetooth_device_address_t *device_address, + int tx_phy, int rx_phy, int phy_options) +{ + struct gatt_client_info_t *conn_info = NULL; + char *addr = NULL; + int ret = OAL_STATUS_SUCCESS; + + BT_INFO("Setting Preferred PHY"); + addr = g_malloc0(sizeof(char) * BT_ADDRESS_STRING_SIZE); + _bt_convert_addr_type_to_string(addr, device_address->addr); + + /* Check if remote GATT Client is connected or not */ + conn_info = _bt_find_remote_gatt_client_info(addr); + if (conn_info == NULL) { + BT_ERR("GATT Client is not yet connected..."); + g_free(addr); + return BLUETOOTH_ERROR_NOT_CONNECTED; + } + + // TODO: This code is commented as currently this API is not supported in OAL + //ret = gatts_set_preferred_phy(conn_info->connection_id, tx_phy, rx_phy, phy_options); + + if (ret != OAL_STATUS_SUCCESS) { + BT_ERR("ret: %d", ret); + g_free(addr); + return BLUETOOTH_ERROR_INTERNAL; + } + + g_free(addr); + return BLUETOOTH_ERROR_NONE; +} + +int _bt_gatt_server_read_phy(bluetooth_device_address_t *address) +{ + struct gatt_client_info_t *conn_info = NULL; + int ret = OAL_STATUS_SUCCESS; + char *addr = NULL; + + BT_CHECK_PARAMETER(address, return); + + addr = g_malloc0(sizeof(char) * BT_ADDRESS_STRING_SIZE); + _bt_convert_addr_type_to_string(addr, address->addr); + + BT_INFO("Read PHY for the server: address:[%s]", addr); + + /* Check if remote GATT client is connected or not */ + conn_info = _bt_find_remote_gatt_client_info(addr); + if (conn_info == NULL) { + BT_ERR("GATT Client is not yet connected.."); + g_free(addr); + return BLUETOOTH_ERROR_NOT_CONNECTED; + } + + // TODO: This code is commented as currently this API is not supported in OAL + //ret = gatts_read_phy(conn_info->connection_id); + + if (ret != OAL_STATUS_SUCCESS) { + BT_ERR("ret: %d", ret); + g_free(addr); + return BLUETOOTH_ERROR_INTERNAL; + } + + g_free(addr); + return BLUETOOTH_ERROR_NONE; +} + +int _bt_gatt_client_set_phy(bluetooth_device_address_t *device_address, + int tx_phy, int rx_phy, int phy_options) +{ + struct gatt_server_info_t *conn_info = NULL; + char *addr = NULL; + int ret = OAL_STATUS_SUCCESS; + + BT_INFO("Setting Preferred PHY"); + addr = g_malloc0(sizeof(char) * BT_ADDRESS_STRING_SIZE); + _bt_convert_addr_type_to_string(addr, device_address->addr); + + /* Check if remote GATT server is connected or not */ + conn_info = _bt_find_remote_gatt_server_info(addr); + if (conn_info == NULL) { + BT_ERR("GATT Server is not yet connected..."); + g_free(addr); + return BLUETOOTH_ERROR_NOT_CONNECTED; + } + + // TODO: This code is commented as currently this API is not supported in OAL + //ret = gattc_set_preferred_phy(conn_info->connection_id, tx_phy, rx_phy, phy_options); + + if (ret != OAL_STATUS_SUCCESS) { + BT_ERR("ret: %d", ret); + g_free(addr); + return BLUETOOTH_ERROR_INTERNAL; + } + + g_free(addr); + return BLUETOOTH_ERROR_NONE; +} + +int _bt_gatt_client_read_phy(bluetooth_device_address_t *address) +{ + struct gatt_server_info_t *conn_info = NULL; + int ret = OAL_STATUS_SUCCESS; + char *addr = NULL; + + BT_CHECK_PARAMETER(address, return); + + addr = g_malloc0(sizeof(char) * BT_ADDRESS_STRING_SIZE); + _bt_convert_addr_type_to_string(addr, address->addr); + + BT_INFO("Read PHY for the server: address:[%s]", addr); + + /* Check if remote GATT server is connected or not */ + conn_info = _bt_find_remote_gatt_server_info(addr); + if (conn_info == NULL) { + BT_ERR("GATT Server is not yet connected.."); + g_free(addr); + return BLUETOOTH_ERROR_NOT_CONNECTED; + } + + // TODO: This code is commented as currently this API is not supported in OAL + //ret = gattc_read_phy(conn_info->connection_id); + + if (ret != OAL_STATUS_SUCCESS) { + BT_ERR("ret: %d", ret); + g_free(addr); + return BLUETOOTH_ERROR_INTERNAL; + } + + g_free(addr); + return BLUETOOTH_ERROR_NONE; +} + int _bt_request_att_mtu(bluetooth_device_address_t *device_address, unsigned int mtu) { @@ -3266,23 +3546,6 @@ static bt_gatt_descriptor_info_t *__bt_find_matching_desc( return NULL; } - -static struct gatt_server_info_t *__bt_find_remote_gatt_server_info_from_conn_id(int conn_id) -{ - GSList *l; - struct gatt_server_info_t *info = NULL; - - for (l = gatt_server_info_list; l != NULL; l = g_slist_next(l)) { - info = (struct gatt_server_info_t*)l->data; - if (info == NULL) - continue; - - if (info->connection_id == conn_id) - return info; - } - return NULL; -} - static bt_gatt_service_info_t* __bt_find_removed_service(bt_gatt_service_info_list_t *svc_list) { GSList *l; diff --git a/bt-service/services/include/bt-service-gatt.h b/bt-service/services/include/bt-service-gatt.h index 169cc1a..fe014e9 100644 --- a/bt-service/services/include/bt-service-gatt.h +++ b/bt-service/services/include/bt-service-gatt.h @@ -166,6 +166,14 @@ int _bt_unregister_gatt_client_instance(const char *sender, int client_id); int _bt_request_att_mtu(bluetooth_device_address_t *device_address, unsigned int mtu); +int _bt_gatt_server_read_phy(bluetooth_device_address_t *address); +int _bt_gatt_server_set_phy(bluetooth_device_address_t *device_address, + int tx_phy, int rx_phy, int phy_options); +int _bt_gatt_client_read_phy(bluetooth_device_address_t *address); +int _bt_gatt_client_set_phy(bluetooth_device_address_t *device_address, + int tx_phy, int rx_phy, int phy_options); + + #ifndef __INTEGRATE_GATT_INFO__ struct gatt_server_info_t *_bt_find_remote_gatt_server_info(char *address); #else diff --git a/include/bluetooth-api.h b/include/bluetooth-api.h index b892916..30a313c 100644 --- a/include/bluetooth-api.h +++ b/include/bluetooth-api.h @@ -880,6 +880,10 @@ typedef enum { BLUETOOTH_EVENT_GATT_CLIENT_SERVICE_CHANGED, /**