BT 5.0: Add APIs to support set/read PHYs 05/298105/1
authorAyush Garg <ayush.garg@samsung.com>
Thu, 31 Aug 2023 14:54:37 +0000 (20:24 +0530)
committerAyush Garg <ayush.garg@samsung.com>
Thu, 31 Aug 2023 15:26:40 +0000 (20:56 +0530)
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 <ayush.garg@samsung.com>
12 files changed:
bt-api/bt-common.c
bt-api/bt-event-handler.c
bt-api/bt-gatt-client.c
bt-api/bt-gatt-service.c
bt-oal/include/oal-event.h
bt-service/services/bt-request-handler.c
bt-service/services/bt-service-event-receiver.c
bt-service/services/bt-service-event-sender.c
bt-service/services/gatt/bt-service-gatt.c
bt-service/services/include/bt-service-gatt.h
include/bluetooth-api.h
include/bt-internal-types.h

index 96d7d30..62252e1 100644 (file)
@@ -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"},
index 7b39fde..99f0568 100644 (file)
@@ -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} };
index 404fcda..a370502 100644 (file)
@@ -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;
+}
index 65ab79f..d3812d8 100644 (file)
@@ -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;
+}
index 16b3c0f..7fd4742 100644 (file)
@@ -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;
index 4370d50..bbbf3da 100644 (file)
@@ -2755,6 +2755,68 @@ int __bt_bluez_request(int function_name,
                result = _bt_gatt_server_update_attribute_value(app, instance_id, &param);
                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:
index 74ee664..1e96a82 100644 (file)
@@ -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)
index d16b7b3..5690065 100644 (file)
@@ -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;
index ca91725..250eb08 100644 (file)
@@ -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;
index 169cc1a..fe014e9 100644 (file)
@@ -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
index b892916..30a313c 100644 (file)
@@ -880,6 +880,10 @@ typedef enum {
        BLUETOOTH_EVENT_GATT_CLIENT_SERVICE_CHANGED, /** <GATT Client service change event */
        BLUETOOTH_EVENT_GATT_SERVER_ACQUIRE_WRITE, /** <GATT Characteristic/Descriptor Value change event */
        BLUETOOTH_EVENT_GATT_SERVER_ACQUIRE_NOTIFY,
+       BLUETOOTH_EVENT_GATT_SERVER_PHY_READ, /**<Local Gatt Server PHY Read event */
+       BLUETOOTH_EVENT_GATT_SERVER_PHY_UPDATED, /**<Local Gatt Server PHY Updated event */
+       BLUETOOTH_EVENT_GATT_CLIENT_PHY_READ, /**<Gatt Client PHY Read event */
+       BLUETOOTH_EVENT_GATT_CLIENT_PHY_UPDATED, /**<Gatt Client PHY Updated event */
        BLUETOOTH_EVENT_AG_CONNECTED = BLUETOOTH_EVENT_AUDIO_BASE, /**<AG service connected event*/
        BLUETOOTH_EVENT_AG_DISCONNECTED, /**<AG service disconnected event*/
        BLUETOOTH_EVENT_AG_SPEAKER_GAIN, /**<Speaker gain request event*/
@@ -1361,6 +1365,13 @@ typedef struct {
        unsigned int status; /** < status of the MTU exchange */
 } bluetooth_le_att_mtu_info_t;
 
+typedef struct {
+       bluetooth_device_address_t device_address;      /**< device address */
+       int tx_phy;     /** < tx_phy set for the gatt connection */
+       int rx_phy; /** < rx_phy set for the gatt connection */
+       int status; /** < status of the PHY */
+} bluetooth_le_phy_info_t;
+
 /**
  * structure to hold the paired device information
  */
@@ -6674,6 +6685,88 @@ int bluetooth_get_att_mtu(const bluetooth_device_address_t *device_address,
                                unsigned int *mtu);
 
 /**
+ * @fn int bluetooth_gatt_server_read_phy(const bluetooth_device_address_t *device_address)
+ * @brief Gets the PHY values set for a connection.
+ *
+ * This function is a asynchronous call. The updated PHYs are notified
+ * through callback event.
+ *
+ * @return   BLUETOOTH_ERROR_NONE  - Success \n
+ *           BLUETOOTH_ERROR_INTERNAL - Internal Error \n
+ *           BLUETOOTH_ERROR_INVALID_PARAM - Parameter is not valid \n
+ *
+ * @exception  None
+ * @param[in]  address - remote device address value.
+ *
+ * @remark       None
+ */
+int bluetooth_gatt_server_read_phy(const bluetooth_device_address_t *device_address);
+
+/**
+ * @fn int bluetooth_gatt_server_set_phy(const bluetooth_device_address_t *device_address,
+                               int tx_phy, int rx_phy, int phy_options)
+ * @brief Request a change of the PHY values.
+ *
+ * This function is a asynchronous call. The updated PHYs are notified
+ * through callback event.
+ *
+ * @return      BLUETOOTH_ERROR_NONE  - Success \n
+ *                      BLUETOOTH_ERROR_INTERNAL - Internal Error \n
+ *                      BLUETOOTH_ERROR_INVALID_PARAM - Parameter is not valid \n
+ *
+ * @exception  None
+ * @param[in]  address - remote device address value.
+ * @param[in]  tx_phy The preferred sender PHY
+ * @param[in]  rx_phy The preferred receiver PHY
+ * @param[in]  phy_options The preferred coding to use when transmitting on LE CODED PHY
+ *
+ * @remark              None
+ */
+int bluetooth_gatt_server_set_phy(const bluetooth_device_address_t *device_address,
+                                       int tx_phy, int rx_phy, int phy_options);
+
+/**
+ * @fn int bluetooth_gatt_client_read_phy(const bluetooth_device_address_t *device_address)
+ * @brief Gets the PHY values set for a connection.
+ *
+ * This function is a asynchronous call. The updated PHYs are notified
+ * through callback event.
+ *
+ * @return   BLUETOOTH_ERROR_NONE  - Success \n
+ *           BLUETOOTH_ERROR_INTERNAL - Internal Error \n
+ *           BLUETOOTH_ERROR_INVALID_PARAM - Parameter is not valid \n
+ *
+ * @exception  None
+ * @param[in]  address - remote device address value.
+ *
+ * @remark       None
+ */
+int bluetooth_gatt_client_read_phy(const bluetooth_device_address_t *device_address);
+
+/**
+ * @fn int bluetooth_gatt_client_set_phy(const bluetooth_device_address_t *device_address,
+                               int tx_phy, int rx_phy, int phy_options)
+ * @brief Request a change of the PHY values.
+ *
+ * This function is a asynchronous call. The updated PHYs are notified
+ * through callback event.
+ *
+ * @return      BLUETOOTH_ERROR_NONE  - Success \n
+ *                      BLUETOOTH_ERROR_INTERNAL - Internal Error \n
+ *                      BLUETOOTH_ERROR_INVALID_PARAM - Parameter is not valid \n
+ *
+ * @exception  None
+ * @param[in]  address - remote device address value.
+ * @param[in]  tx_phy The preferred sender PHY
+ * @param[in]  rx_phy The preferred receiver PHY
+ * @param[in]  phy_options The preferred coding to use when transmitting on LE CODED PHY
+ *
+ * @remark              None
+ */
+int bluetooth_gatt_client_set_phy(const bluetooth_device_address_t *device_address,
+                                       int tx_phy, int rx_phy, int phy_options);
+
+/**
  * @fn int bluetooth_get_device_ida(const bluetooth_device_address_t *device_rpa,
  *                                     bluetooth_device_address_t *id_address)
  * @brief Gets the Identity address of remote device.
index a8cf78d..4792296 100644 (file)
@@ -412,6 +412,10 @@ typedef enum {
        BT_GATT_SERVER_SEND_INDICATION,
        BT_GATT_SERVER_UPDATE_VALUE,
        BT_GATT_SERVER_DEREGISTER,
+       BT_GATT_SERVER_READ_PHY,
+       BT_GATT_SERVER_SET_PHY,
+       BT_GATT_CLIENT_READ_PHY,
+       BT_GATT_CLIENT_SET_PHY,
 //#endif
        BT_LE_IPSP_INIT = BT_FUNC_IPSP_BASE,
        BT_LE_IPSP_DEINIT,
@@ -725,6 +729,10 @@ typedef struct {
 
 #define BT_GATT_REQ_ATT_MTU_CHANGED "GattReqAttMtuChanged"
 #define BT_GATT_SERVER_ATT_MTU_CHANGED "GattServerAttMtuChanged"
+#define BT_GATT_SERVER_PHY_UPDATED "GattServerPhyUpdated"
+#define BT_GATT_SERVER_PHY_READ "GattServerPhyRead"
+#define BT_GATT_CLIENT_PHY_UPDATED "GattClientPhyUpdated"
+#define BT_GATT_CLIENT_PHY_READ "GattClientPhyRead"
 #define BT_GATT_CHAR_VAL_CHANGED "GattCharValueChanged"
 #ifdef GATT_NO_RELAY
 #define BT_GATT_BLUEZ_CHAR_VAL_CHANGED "GattValueChanged"