Implement MTU changed callback for GATT server 63/213863/1
authorinjun.yang <injun.yang@samsung.com>
Mon, 1 Jul 2019 08:01:09 +0000 (17:01 +0900)
committerDoHyun Pyun <dh79.pyun@samsung.com>
Mon, 16 Sep 2019 04:00:39 +0000 (13:00 +0900)
[Model] All
[BinType] AP
[Customer] OPEN

[Issue#] N/A
[Request] Internal
[Occurrence Version] N/A

[Problem] Unable to notice MTU changed event to application
[Cause & Measure] Implement MTU changed callback for GATT server
[Checking Method] n/a

[Team] Convergence BT
[Developer] Injun Yang
[Solution company] Samsung
[Change Type] Specification change

Change-Id: I57a539cadf7ab83931a40eaed573de9f9cecbd9c
Signed-off-by: injun.yang <injun.yang@samsung.com>
Signed-off-by: DoHyun Pyun <dh79.pyun@samsung.com>
bt-api/bt-event-handler.c
bt-oal/bluez_hal/inc/bt-hal-msg.h
bt-oal/bluez_hal/src/bt-hal-event-receiver.c
bt-oal/bluez_hal/src/bt-hal-gatt-server.c
bt-oal/bluez_hal/src/bt-hal-gatt-server.h
bt-oal/bluez_hal/src/bt-hal-gatt.c
bt-oal/oal-gatt.c
bt-service-adaptation/services/bt-service-event-sender.c
bt-service/bt-service-event-receiver.c
include/bluetooth-api.h
include/bt-internal-types.h

index 39cb654..3afa060 100644 (file)
@@ -3919,8 +3919,31 @@ static void __bt_gatt_server_event_filter(GDBusConnection *connection,
                _bt_gatt_server_event_cb(BLUETOOTH_EVENT_GATT_SERVER_NOTIFICATION_STATE_CHANGED,
                                result, &info,
                                event_info->cb, event_info->user_data);
+       } else if (strcasecmp(signal_name, BT_GATT_SERVER_ATT_MTU_CHANGED) == 0) {
+               const char *address = NULL;
+               bluetooth_device_address_t dev_address = { {0} };
+               bluetooth_le_att_mtu_info_t att_mtu_info;
+               guint16 mtu;
+               guint8 status;
+               BT_DBG("BT_GATT_SERVER_ATT_MTU_CHANGED");
+               g_variant_get(parameters, "(i&sqy)", &result, &address, &mtu, &status);
+
+               _bt_convert_addr_string_to_type(dev_address.addr, address);
+
+               memset(&att_mtu_info, 0x00, sizeof(bluetooth_le_att_mtu_info_t));
+               memcpy(att_mtu_info.device_address.addr,
+                                       dev_address.addr,
+                                       BLUETOOTH_ADDRESS_LENGTH);
+
+               att_mtu_info.mtu = mtu;
+               att_mtu_info.status = status;
+
+               _bt_common_event_cb(BLUETOOTH_EVENT_GATT_SERVER_ATT_MTU_CHANGED,
+                               result, &att_mtu_info,
+                               event_info->cb, event_info->user_data);
        }
 
+
        BT_INFO("GATT Server event handler Exit <<");
 }
 #endif
index c8c3478..e87c1fa 100644 (file)
@@ -760,4 +760,10 @@ struct hal_ev_gatt_client_notify_changed_value {
        uint8_t is_notify;
 } __attribute__((packed));
 
+#define HAL_EV_GATT_SERVER_MTU_CHANGED 0XCC
+struct hal_ev_gatt_server_mtu_changed {
+       int32_t conn_id;
+       int32_t mtu;
+} __attribute__((packed));
+
 #endif //_BT_HAL_MSG_H_
index 6e6a1d6..49b4ed4 100644 (file)
@@ -111,6 +111,8 @@ static void __bt_hal_send_hf_audio_connection_state_event(gboolean connected, co
 static void __bt_hal_send_hf_connection_state_event(gboolean connected, const char *address);
 static void __bt_hal_send_device_trusted_profile_changed_event(uint32_t trust_val, const char *address);
 static void __bt_hal_handle_adv_report(GVariant *msg, const char *path);
+static void __bt_hal_handle_gatts_mtu_changed_event(char *address, int mtu);
+
 
 static gboolean __bt_hal_discovery_finished_cb(gpointer user_data)
 {
@@ -2077,6 +2079,20 @@ static void __bt_hal_handle_device_specific_events(GVariant *msg, const char *me
                }
                g_free(address);
                g_free(profile_uuid);
+       } else if (strcasecmp(member, "AttMtuChanged") == 0) {
+               char *address;
+               guint16 mtu = 0;
+
+               address = g_malloc0(BT_HAL_ADDRESS_STRING_SIZE);
+
+               DBG("Member: [%s]", member);
+
+               _bt_hal_convert_device_path_to_address(path, address);
+               g_variant_get(msg, "(q)", &mtu);
+
+               __bt_hal_handle_gatts_mtu_changed_event(address, mtu);
+
+               g_free(address);
        } else if (strcasecmp(member, "AdvReport") == 0) {
                DBG("Member: [%s]", member);
                __bt_hal_handle_adv_report(msg, path);
@@ -2132,6 +2148,27 @@ static void __bt_hal_handle_adv_report(GVariant *msg, const char *path)
        g_variant_unref(value);
 }
 
+static void __bt_hal_handle_gatts_mtu_changed_event(char *address, int mtu)
+{
+       uint8_t buf[BT_HAL_MAX_PROPERTY_BUF_SIZE];
+       struct hal_ev_gatt_server_mtu_changed *ev = (void *)buf;
+       size_t size = 0;
+
+       if (!gatt_event_cb)
+               return;
+
+       memset(buf, 0, sizeof(buf));
+       size = sizeof(*ev);
+
+       DBG("Address: %s, mtu: %d", address, mtu);
+
+       ev->conn_id = _bt_get_remote_gatt_client_conn_id(address);
+       ev->mtu = mtu;
+
+       DBG("Send GATT server mtu changed event to HAL, size: [%zd]", size);
+       gatt_event_cb(HAL_EV_GATT_SERVER_MTU_CHANGED, buf, size);
+}
+
 /* AVRCP Controller Role(Remote:AVRCP Target) Events */
 static void __bt_hal_send_avrcp_ctrl_connection_state_event(gboolean connected, const char *address)
 {
index 447da05..4f10851 100644 (file)
@@ -374,6 +374,24 @@ static void _bt_hal_update_gatt_service_in_gatt_server(int slot, struct gatt_ser
        }
 }
 
+int _bt_get_remote_gatt_client_conn_id(char *address)
+{
+       GSList *l;
+       struct gatt_client_info_t *info = NULL;
+
+       for (l = gatt_client_info_list; l != NULL; l = g_slist_next(l)) {
+               info = (struct gatt_client_info_t*)l->data;
+               if (info == NULL)
+                       continue;
+
+               if (!g_strcmp0(info->addr, address)) {
+                       INFO("Remote GATT client found addr[%s]", info->addr);
+                       return info->connection_id;
+               }
+       }
+       return 0;
+}
+
 static struct gatt_client_info_t *__bt_find_remote_gatt_client_info(char *address)
 {
        GSList *l;
index 97f48e8..2422b78 100644 (file)
@@ -43,6 +43,8 @@ void _bt_hal_gatt_connected_state_event(gboolean is_connected, char *address);
 
 handle_stack_msg _bt_hal_get_gatt_event(void);
 
+int _bt_get_remote_gatt_client_conn_id(char *address);
+
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */
index dbeed8c..f756a2f 100644 (file)
@@ -276,6 +276,16 @@ static void __bt_hal_handle_gatt_server_indicate_confirmed(void *buf, uint16_t l
 
 }
 
+static void __bt_hal_handle_gatt_server_mtu_changed(void *buf, uint16_t len)
+{
+       struct hal_ev_gatt_server_mtu_changed *ev = buf;
+
+       DBG("GATT Server MTU changed event recived");
+
+       if (bt_gatt_callbacks->server->mtu_changed_cb)
+               bt_gatt_callbacks->server->mtu_changed_cb(ev->conn_id, ev->mtu);
+}
+
 static void __bt_hal_gatt_events(int message, void *buf, uint16_t len)
 {
        DBG("+");
@@ -412,6 +422,10 @@ static void __bt_hal_gatt_events(int message, void *buf, uint16_t len)
                __bt_hal_handle_gatt_server_acquire_notify_requested(buf, len);
                break;
        }
+       case HAL_EV_GATT_SERVER_MTU_CHANGED:{
+               __bt_hal_handle_gatt_server_mtu_changed(buf, len);
+               break;
+       }
 
        default:
                DBG("Event Currently not handled!!");
index 9b01f22..6d5d203 100644 (file)
@@ -192,7 +192,7 @@ static const btgatt_server_callbacks_t btgatt_server_callbacks = {
        .notif_enabled_cb = cb_notifcation_changed,
 #endif
        .request_acquire_write_cb = cb_gatts_acquire_write,
-       .request_acquire_notify_cb = cb_gatts_acquire_notify
+       .request_acquire_notify_cb = cb_gatts_acquire_notify,
 };
 
 /* Forward declaration for GATT client callbacks */
index f3fb614..bbc0f7b 100644 (file)
@@ -469,6 +469,9 @@ int _bt_send_event(int event_type, int event, GVariant *param)
        case BLUETOOTH_EVENT_GATT_ATT_MTU_CHANGED:
                signal = BT_GATT_REQ_ATT_MTU_CHANGED;
                break;
+       case BLUETOOTH_EVENT_GATT_SERVER_ATT_MTU_CHANGED:
+               signal = BT_GATT_SERVER_ATT_MTU_CHANGED;
+               break;
 #ifndef GATT_DIRECT
        case BLUETOOTH_EVENT_GATT_SERVER_VALUE_CHANGED:
                signal = BT_GATT_VALUE_CHANGED;
index 51cd09f..fc97873 100644 (file)
@@ -2245,9 +2245,31 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path
                param = g_variant_new("(iss)", result, address, ifname);
 
                /* Send event to application */
+               _bt_send_event(BT_DEVICE_EVENT, event, param);
+               g_free(address);
+       } else if (strcasecmp(member, "AttMtuChanged") == 0) {
+               int result = BLUETOOTH_ERROR_NONE;
+               guint16 mtu = 0;
+               guint8 status = 0;
+
+               g_variant_get(msg, "(q)", &mtu);
+
+               address = g_malloc0(BT_ADDRESS_STRING_SIZE);
+
+               _bt_convert_device_path_to_address(path, address);
+               BT_DBG("Address : %s Server MTU changed : %d", address, mtu);
+
+               param = g_variant_new("(isqy)",
+                       result,
+                       address,
+                       mtu,
+                       status);
+
+               /* Send the event to application */
                _bt_send_event(BT_DEVICE_EVENT,
-                                               event,
+                       BLUETOOTH_EVENT_GATT_SERVER_ATT_MTU_CHANGED,
                                                param);
+
                g_free(address);
        } else if (strcasecmp(member, "iBeaconReport") == 0) {
                bt_remote_ibeacon_dev_info_t *ibeacon_dev_info = NULL;
index 8403665..f79c375 100644 (file)
@@ -819,6 +819,7 @@ typedef enum {
        BLUETOOTH_EVENT_GATT_DISCONNECTED, /**<Gatt Disconnected event */
 #endif
        BLUETOOTH_EVENT_GATT_ATT_MTU_CHANGED, /**<Attribute protocol MTU changed event */
+       BLUETOOTH_EVENT_GATT_SERVER_ATT_MTU_CHANGED, /**<Attribute protocol Server MTU changed event */
        BLUETOOTH_EVENT_GATT_SERVER_CHARACTERISTIC_VALUE_CHANGED, /**<Gatt Char write callback event */
        BLUETOOTH_EVENT_GATT_SERVER_READ_REQUESTED, /** <GATT Characteristic/Descriptor Read Request event */
        BLUETOOTH_EVENT_GATT_SERVER_VALUE_CHANGED, /** <GATT Characteristic/Descriptor Value change event */
index 6e73e1e..973c0f5 100644 (file)
@@ -634,6 +634,7 @@ typedef struct {
 #endif
 
 #define BT_GATT_REQ_ATT_MTU_CHANGED "GattReqAttMtuChanged"
+#define BT_GATT_SERVER_ATT_MTU_CHANGED "GattServerAttMtuChanged"
 #define BT_GATT_CHAR_VAL_CHANGED "GattCharValueChanged"
 #ifdef GATT_NO_RELAY
 #define BT_GATT_BLUEZ_CHAR_VAL_CHANGED "GattValueChanged"