From ee95e3eee6f058c4214748b47784c2137aa9a646 Mon Sep 17 00:00:00 2001 From: "injun.yang" Date: Mon, 1 Jul 2019 17:01:09 +0900 Subject: [PATCH] Implement MTU changed callback for GATT server [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 Signed-off-by: DoHyun Pyun --- bt-api/bt-event-handler.c | 23 ++++++++++++ bt-oal/bluez_hal/inc/bt-hal-msg.h | 6 +++ bt-oal/bluez_hal/src/bt-hal-event-receiver.c | 37 +++++++++++++++++++ bt-oal/bluez_hal/src/bt-hal-gatt-server.c | 18 +++++++++ bt-oal/bluez_hal/src/bt-hal-gatt-server.h | 2 + bt-oal/bluez_hal/src/bt-hal-gatt.c | 14 +++++++ bt-oal/oal-gatt.c | 2 +- .../services/bt-service-event-sender.c | 3 ++ bt-service/bt-service-event-receiver.c | 24 +++++++++++- include/bluetooth-api.h | 1 + include/bt-internal-types.h | 1 + 11 files changed, 129 insertions(+), 2 deletions(-) diff --git a/bt-api/bt-event-handler.c b/bt-api/bt-event-handler.c index 39cb6547..3afa0608 100644 --- a/bt-api/bt-event-handler.c +++ b/bt-api/bt-event-handler.c @@ -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 diff --git a/bt-oal/bluez_hal/inc/bt-hal-msg.h b/bt-oal/bluez_hal/inc/bt-hal-msg.h index c8c34781..e87c1fa9 100644 --- a/bt-oal/bluez_hal/inc/bt-hal-msg.h +++ b/bt-oal/bluez_hal/inc/bt-hal-msg.h @@ -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_ diff --git a/bt-oal/bluez_hal/src/bt-hal-event-receiver.c b/bt-oal/bluez_hal/src/bt-hal-event-receiver.c index 6e6a1d69..49b4ed4c 100644 --- a/bt-oal/bluez_hal/src/bt-hal-event-receiver.c +++ b/bt-oal/bluez_hal/src/bt-hal-event-receiver.c @@ -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) { diff --git a/bt-oal/bluez_hal/src/bt-hal-gatt-server.c b/bt-oal/bluez_hal/src/bt-hal-gatt-server.c index 447da05b..4f108516 100644 --- a/bt-oal/bluez_hal/src/bt-hal-gatt-server.c +++ b/bt-oal/bluez_hal/src/bt-hal-gatt-server.c @@ -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; diff --git a/bt-oal/bluez_hal/src/bt-hal-gatt-server.h b/bt-oal/bluez_hal/src/bt-hal-gatt-server.h index 97f48e82..2422b786 100644 --- a/bt-oal/bluez_hal/src/bt-hal-gatt-server.h +++ b/bt-oal/bluez_hal/src/bt-hal-gatt-server.h @@ -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 */ diff --git a/bt-oal/bluez_hal/src/bt-hal-gatt.c b/bt-oal/bluez_hal/src/bt-hal-gatt.c index dbeed8cb..f756a2f5 100644 --- a/bt-oal/bluez_hal/src/bt-hal-gatt.c +++ b/bt-oal/bluez_hal/src/bt-hal-gatt.c @@ -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!!"); diff --git a/bt-oal/oal-gatt.c b/bt-oal/oal-gatt.c index 9b01f228..6d5d203c 100644 --- a/bt-oal/oal-gatt.c +++ b/bt-oal/oal-gatt.c @@ -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 */ diff --git a/bt-service-adaptation/services/bt-service-event-sender.c b/bt-service-adaptation/services/bt-service-event-sender.c index f3fb614e..bbc0f7b3 100644 --- a/bt-service-adaptation/services/bt-service-event-sender.c +++ b/bt-service-adaptation/services/bt-service-event-sender.c @@ -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; diff --git a/bt-service/bt-service-event-receiver.c b/bt-service/bt-service-event-receiver.c index 51cd09f6..fc97873f 100644 --- a/bt-service/bt-service-event-receiver.c +++ b/bt-service/bt-service-event-receiver.c @@ -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; diff --git a/include/bluetooth-api.h b/include/bluetooth-api.h index 84036655..f79c3754 100644 --- a/include/bluetooth-api.h +++ b/include/bluetooth-api.h @@ -819,6 +819,7 @@ typedef enum { BLUETOOTH_EVENT_GATT_DISCONNECTED, /**