Invoke MTU changed callback 26/110626/1
authorInjun Yang <injun.yang@samsung.com>
Tue, 17 Jan 2017 08:12:57 +0000 (17:12 +0900)
committerInjun Yang <injun.yang@samsung.com>
Tue, 17 Jan 2017 08:12:57 +0000 (17:12 +0900)
[Model] All
[BinType] AP
[Customer] OPEN

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

[Problem] When remote device request mtu exchange,
  mtu changed callback is not invoked on responder
[Cause & Measure] Invoke mtu changed callback
[Checking Method] Request mtu exchange on remote device

[Team] Basic Connection
[Developer] Injun Yang
[Solution company] Samsung
[Change Type] Specification change

Change-Id: Ib9ee0e2c67043cb0384fed59bfc6a2e3e6b467e6
Signed-off-by: Injun Yang <injun.yang@samsung.com>
src/device.c
src/shared/gatt-client.c
src/shared/gatt-server.c
src/shared/gatt-server.h

index 618d5bb..73ae618 100644 (file)
@@ -6355,6 +6355,20 @@ done:
        attio_cleanup(device);
 }
 
+#ifdef TIZEN_FEATURE_BLUEZ_MODIFY
+static void att_mtu_changed(uint16_t mtu, void *user_data)
+{
+       struct btd_device *device = user_data;
+
+       DBG("att mtu changed %d", mtu);
+
+       g_dbus_emit_signal(dbus_conn, device->path,
+               DEVICE_INTERFACE, "AttMtuChanged",
+               DBUS_TYPE_UINT16, &mtu,
+               DBUS_TYPE_INVALID);
+}
+#endif
+
 static void register_gatt_services(struct btd_device *device)
 {
        struct browse_req *req = device->browse;
@@ -6503,6 +6517,15 @@ static void gatt_server_init(struct btd_device *device, struct gatt_db *db)
                error("Failed to initialize bt_gatt_server");
 
        bt_gatt_server_set_debug(device->server, gatt_debug, NULL, NULL);
+
+#ifdef TIZEN_FEATURE_BLUEZ_MODIFY
+       if (!bt_gatt_server_set_mtu_changed(device->server,
+                                               att_mtu_changed,
+                                               device, NULL)) {
+               DBG("Failed to set mtu changed handler");
+               return;
+       }
+#endif
 }
 
 static bool local_counter(uint32_t *sign_cnt, void *user_data)
index 3c6d7a8..9f4e075 100644 (file)
@@ -1181,7 +1181,7 @@ static void exchange_mtu_cb(bool success, uint8_t att_ecode, void *user_data)
        }
 
        util_debug(client->debug_callback, client->debug_data,
-                                       "MTU exchange complete, with MTU: %u",
+                                       "att client MTU exchange complete, with MTU: %u",
                                        bt_att_get_mtu(client->att));
 
 discover:
index e978645..53c60f3 100644 (file)
@@ -110,6 +110,12 @@ struct bt_gatt_server {
        bt_gatt_server_debug_func_t debug_callback;
        bt_gatt_server_destroy_func_t debug_destroy;
        void *debug_data;
+
+#ifdef TIZEN_FEATURE_BLUEZ_MODIFY
+       bt_gatt_server_mtu_changed_callback_t mtu_chngd_callback;
+       bt_gatt_server_destroy_func_t mtu_chngd_destroy;
+       void *mtu_chngd_data;
+#endif
 };
 
 static void bt_gatt_server_free(struct bt_gatt_server *server)
@@ -1304,7 +1310,7 @@ static void exchange_mtu_cb(uint8_t opcode, const void *pdu,
        }
 
        client_rx_mtu = get_le16(pdu);
-#ifndef __TIZEN_PACTH__
+#ifndef TIZEN_FEATURE_BLUEZ_MODIFY
        final_mtu = MAX(MIN(client_rx_mtu, server->mtu), BT_ATT_DEFAULT_LE_MTU);
 
        /* Respond with the server MTU */
@@ -1326,10 +1332,13 @@ static void exchange_mtu_cb(uint8_t opcode, const void *pdu,
        put_le16(server->mtu, rsp_pdu);
        bt_att_send(server->att, BT_ATT_OP_MTU_RSP, rsp_pdu, 2, NULL, NULL,
                                                                        NULL);
+
+       if (server->mtu_chngd_callback)
+               server->mtu_chngd_callback(final_mtu, server->mtu_chngd_data);
 #endif
 
        util_debug(server->debug_callback, server->debug_data,
-                       "MTU exchange complete, with MTU: %u", final_mtu);
+                       "att server MTU exchange complete, with MTU: %u", final_mtu);
 }
 
 static bool gatt_server_register_att_handlers(struct bt_gatt_server *server)
@@ -1581,3 +1590,23 @@ bool bt_gatt_server_send_indication(struct bt_gatt_server *server,
 
        return result;
 }
+
+#ifdef TIZEN_FEATURE_BLUEZ_MODIFY
+bool bt_gatt_server_set_mtu_changed(struct bt_gatt_server *server,
+                       bt_gatt_server_mtu_changed_callback_t callback,
+                       void *user_data,
+                       bt_gatt_server_destroy_func_t destroy)
+{
+       if (!server)
+               return false;
+
+       if (server->mtu_chngd_destroy)
+               server->mtu_chngd_destroy(server->mtu_chngd_data);
+
+       server->mtu_chngd_callback = callback;
+       server->mtu_chngd_destroy = destroy;
+       server->mtu_chngd_data = user_data;
+
+       return true;
+}
+#endif
index 0e480e1..c61eabe 100644 (file)
@@ -50,3 +50,14 @@ bool bt_gatt_server_send_indication(struct bt_gatt_server *server,
                                        bt_gatt_server_conf_func_t callback,
                                        void *user_data,
                                        bt_gatt_server_destroy_func_t destroy);
+
+#ifdef TIZEN_FEATURE_BLUEZ_MODIFY
+typedef void (*bt_gatt_server_mtu_changed_callback_t)(uint16_t mtu,
+                                                       void *user_data);
+
+bool bt_gatt_server_set_mtu_changed(struct bt_gatt_server *server,
+                       bt_gatt_server_mtu_changed_callback_t callback,
+                       void *user_data,
+                       bt_gatt_server_destroy_func_t destroy);
+
+#endif