[PATCH] android/hal-gatt: Add skeleton for GATT HAL

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This adds skeleton with stubs and proper build system entries.
---
 android/Android.mk      |   1 +
 android/Makefile.am     |   1 +
 android/hal-bluetooth.c |   3 +
 android/hal-gatt.c      | 563 ++++++++++++++++++++++++++++++++++++++++++++++++
 android/hal.h           |   4 +
 5 files changed, 572 insertions(+)
 create mode 100644 android/hal-gatt.c

diff --git a/android/Android.mk b/android/Android.mk
index 56b86ba..6fd0f94 100644
--- a/android/Android.mk
+++ b/android/Android.mk
@@ -118,6 +118,7 @@ LOCAL_SRC_FILES := \
 	bluez/android/hal-a2dp.c \
 	bluez/android/hal-avrcp.c \
 	bluez/android/hal-handsfree.c \
+	bluez/android/hal-gatt.c \
 	bluez/android/hal-utils.c \
 
 LOCAL_C_INCLUDES += \
diff --git a/android/Makefile.am b/android/Makefile.am
index 31f905c..8abfff4 100644
--- a/android/Makefile.am
+++ b/android/Makefile.am
@@ -55,6 +55,7 @@ android_bluetooth_default_la_SOURCES = android/hal.h android/hal-bluetooth.c \
 					android/hal-a2dp.c \
 					android/hal-avrcp.c \
 					android/hal-handsfree.c \
+					android/hal-gatt.c \
 					android/hardware/bluetooth.h \
 					android/hardware/bt_av.h \
 					android/hardware/bt_gatt.h \
diff --git a/android/hal-bluetooth.c b/android/hal-bluetooth.c
index 6871f5d..f58f72c 100644
--- a/android/hal-bluetooth.c
+++ b/android/hal-bluetooth.c
@@ -773,6 +773,9 @@ static const void *get_profile_interface(const char *profile_id)
 	if (!strcmp(profile_id, BT_PROFILE_HANDSFREE_ID))
 		return bt_get_handsfree_interface();
 
+	if (!strcmp(profile_id, BT_PROFILE_GATT_ID))
+		return bt_get_gatt_interface();
+
 	return NULL;
 }
 
diff --git a/android/hal-gatt.c b/android/hal-gatt.c
new file mode 100644
index 0000000..00cf888
--- /dev/null
+++ b/android/hal-gatt.c
@@ -0,0 +1,563 @@
+/*
+ * Copyright (C) 2014 Intel Corporation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdbool.h>
+
+#include "hal-log.h"
+#include "hal.h"
+#include "hal-msg.h"
+#include "hal-ipc.h"
+
+static const btgatt_callbacks_t *cbs = NULL;
+
+static bool interface_ready(void)
+{
+	return cbs != NULL;
+}
+
+/* Client Event Handlers */
+
+static void handle_register_client(void *buf, uint16_t len)
+{
+
+}
+
+static void handle_scan_result(void *buf, uint16_t len)
+{
+
+}
+
+static void handle_connect(void *buf, uint16_t len)
+{
+
+}
+
+static void handle_disconnect(void *buf, uint16_t len)
+{
+
+}
+
+static void handle_search_complete(void *buf, uint16_t len)
+{
+
+}
+
+static void handle_search_result(void *buf, uint16_t len)
+{
+
+}
+
+static void handle_get_characteristic(void *buf, uint16_t len)
+{
+
+}
+
+static void handle_get_descriptor(void *buf, uint16_t len)
+{
+
+}
+
+static void handle_get_included_service(void *buf, uint16_t len)
+{
+
+}
+
+static void handle_register_for_notification(void *buf, uint16_t len)
+{
+
+}
+
+static void handle_notify(void *buf, uint16_t len)
+{
+
+}
+
+static void handle_read_characteristic(void *buf, uint16_t len)
+{
+
+}
+
+static void handle_write_characteristic(void *buf, uint16_t len)
+{
+
+}
+
+static void handle_read_descriptor(void *buf, uint16_t len)
+{
+
+}
+
+static void handle_write_descriptor(void *buf, uint16_t len)
+{
+
+}
+
+static void handle_execute_write(void *buf, uint16_t len)
+{
+
+}
+
+static void handle_read_remote_rssi(void *buf, uint16_t len)
+{
+
+}
+
+static void handle_listen(void *buf, uint16_t len)
+{
+
+}
+
+/* Server Event Handlers */
+
+static void handle_register_server(void *buf, uint16_t len)
+{
+
+}
+
+static void handle_connection(void *buf, uint16_t len)
+{
+
+}
+
+static void handle_service_added(void *buf, uint16_t len)
+{
+
+}
+
+static void handle_included_service_added(void *buf, uint16_t len)
+{
+
+}
+
+static void handle_characteristic_added(void *buf, uint16_t len)
+{
+
+}
+
+static void handle_descriptor_added(void *buf, uint16_t len)
+{
+
+}
+
+static void handle_service_started(void *buf, uint16_t len)
+{
+
+}
+
+static void handle_service_stopped(void *buf, uint16_t len)
+{
+
+}
+
+static void handle_service_deleted(void *buf, uint16_t len)
+{
+
+}
+
+static void handle_request_read(void *buf, uint16_t len)
+{
+
+}
+
+static void handle_request_write(void *buf, uint16_t len)
+{
+
+}
+
+static void handle_request_exec_write(void *buf, uint16_t len)
+{
+
+}
+
+static void handle_response_confirmation(void *buf, uint16_t len)
+{
+
+}
+
+/* handlers will be called from notification thread context,
+ * index in table equals to 'opcode - HAL_MINIMUM_EVENT' */
+static const struct hal_ipc_handler ev_handlers[] = {
+	/* Client Event Handlers */
+	{handle_register_client, false,
+			sizeof(struct hal_ev_gatt_client_register_client)},
+	{handle_scan_result, true,
+				sizeof(struct hal_ev_gatt_client_scan_result)},
+	{handle_connect, false, sizeof(struct hal_ev_gatt_client_connect)},
+	{handle_disconnect, false,
+			sizeof(struct hal_ev_gatt_client_disconnect)},
+	{handle_search_complete, false,
+			sizeof(struct hal_ev_gatt_client_search_complete)},
+	{handle_search_result, false,
+			sizeof(struct hal_ev_gatt_client_search_result)},
+	{handle_get_characteristic, false,
+			sizeof(struct hal_ev_gatt_client_get_characteristic)},
+	{handle_get_descriptor, false,
+			sizeof(struct hal_ev_gatt_client_get_descriptor)},
+	{handle_get_included_service, false,
+			sizeof(struct hal_ev_gatt_client_get_inc_service)},
+	{handle_register_for_notification, false,
+			sizeof(struct hal_ev_gatt_client_reg_for_notif)},
+	{handle_notify, true, sizeof(struct hal_ev_gatt_client_notify)},
+	{handle_read_characteristic, true,
+			sizeof(struct hal_ev_gatt_client_read_characteristic)},
+	{handle_write_characteristic, false,
+			sizeof(struct hal_ev_gatt_client_write_characteristic)},
+	{handle_read_descriptor, false,
+			sizeof(struct hal_ev_gatt_client_read_descriptor)},
+	{handle_write_descriptor, false,
+			sizeof(struct hal_ev_gatt_client_write_descriptor)},
+	{handle_execute_write, false,
+				sizeof(struct hal_ev_gatt_client_exec_write)},
+	{handle_read_remote_rssi, false,
+			sizeof(struct hal_ev_gatt_client_read_remote_rssi)},
+	{handle_listen, false, sizeof(struct hal_ev_gatt_client_listen)},
+
+	/* Server Event Handlers */
+	{handle_register_server, false,
+				sizeof(struct hal_ev_gatt_server_register)},
+	{handle_connection, false,
+				sizeof(struct hal_ev_gatt_server_connection)},
+	{handle_service_added, false,
+			sizeof(struct hal_ev_gatt_server_service_added)},
+	{handle_included_service_added, false,
+			sizeof(struct hal_ev_gatt_server_service_added)},
+	{handle_characteristic_added, false,
+			sizeof(struct hal_ev_gatt_server_characteristic_added)},
+	{handle_descriptor_added, false,
+			sizeof(struct hal_ev_gatt_server_descriptor_added)},
+	{handle_service_started, false,
+			sizeof(struct hal_ev_gatt_server_service_started)},
+	{handle_service_stopped, false,
+			sizeof(struct hal_ev_gatt_server_service_stopped)},
+	{handle_service_deleted, false,
+			sizeof(struct hal_ev_gatt_server_service_deleted)},
+	{handle_request_read, false,
+			sizeof(struct hal_ev_gatt_server_request_read)},
+	{handle_request_write, true,
+			sizeof(struct hal_ev_gatt_server_request_write)},
+	{handle_request_exec_write, false,
+			sizeof(struct hal_ev_gatt_server_request_exec_write)},
+	{handle_response_confirmation, false,
+			sizeof(struct hal_ev_gatt_server_rsp_confirmation)},
+};
+
+static bt_status_t init(const btgatt_callbacks_t *callbacks)
+{
+	struct hal_cmd_register_module cmd;
+	int ret;
+
+	DBG("");
+
+	if (interface_ready())
+		return BT_STATUS_DONE;
+
+	cbs = callbacks;
+
+	hal_ipc_register(HAL_SERVICE_ID_GATT, ev_handlers,
+				sizeof(ev_handlers)/sizeof(ev_handlers[0]));
+
+	cmd.service_id = HAL_SERVICE_ID_GATT;
+
+	ret = hal_ipc_cmd(HAL_SERVICE_ID_CORE, HAL_OP_REGISTER_MODULE,
+					sizeof(cmd), &cmd, 0, NULL, NULL);
+
+	if (ret != BT_STATUS_SUCCESS) {
+		cbs = NULL;
+		hal_ipc_unregister(HAL_SERVICE_ID_GATT);
+	}
+
+	return ret;
+}
+
+/* Client API */
+
+static bt_status_t register_client(bt_uuid_t *uuid)
+{
+	return BT_STATUS_UNSUPPORTED;
+}
+
+static bt_status_t unregister_client(int client_if)
+{
+	return BT_STATUS_UNSUPPORTED;
+}
+
+static bt_status_t scan(int client_if, bool start)
+{
+	return BT_STATUS_UNSUPPORTED;
+}
+
+static bt_status_t connect(int client_if, const bt_bdaddr_t *bd_addr,
+								bool is_direct)
+{
+	return BT_STATUS_UNSUPPORTED;
+}
+
+static bt_status_t disconnect(int client_if, const bt_bdaddr_t *bd_addr,
+								int conn_id)
+{
+	return BT_STATUS_UNSUPPORTED;
+}
+
+static bt_status_t listen(int client_if, bool start)
+{
+	return BT_STATUS_UNSUPPORTED;
+}
+
+static bt_status_t refresh(int client_if, const bt_bdaddr_t *bd_addr)
+{
+	return BT_STATUS_UNSUPPORTED;
+}
+
+static bt_status_t search_service(int conn_id, bt_uuid_t *filter_uuid)
+{
+	return BT_STATUS_UNSUPPORTED;
+}
+
+static bt_status_t get_included_service(int conn_id, btgatt_srvc_id_t *srvc_id,
+				     btgatt_srvc_id_t *start_incl_srvc_id)
+{
+	return BT_STATUS_UNSUPPORTED;
+}
+
+static bt_status_t get_characteristic(int conn_id, btgatt_srvc_id_t *srvc_id,
+						btgatt_gatt_id_t *start_char_id)
+{
+	return BT_STATUS_UNSUPPORTED;
+}
+
+static bt_status_t get_descriptor(int conn_id, btgatt_srvc_id_t *srvc_id,
+					btgatt_gatt_id_t *char_id,
+					btgatt_gatt_id_t *start_descr_id)
+{
+	return BT_STATUS_UNSUPPORTED;
+}
+
+static bt_status_t read_characteristic(int conn_id, btgatt_srvc_id_t *srvc_id,
+					btgatt_gatt_id_t *char_id,
+					int auth_req)
+{
+	return BT_STATUS_UNSUPPORTED;
+}
+
+static bt_status_t write_characteristic(int conn_id, btgatt_srvc_id_t *srvc_id,
+				btgatt_gatt_id_t *char_id, int write_type,
+				int len, int auth_req, char *p_value)
+{
+	return BT_STATUS_UNSUPPORTED;
+}
+
+static bt_status_t read_descriptor(int conn_id, btgatt_srvc_id_t *srvc_id,
+				btgatt_gatt_id_t *char_id,
+				btgatt_gatt_id_t *descr_id, int auth_req)
+{
+	return BT_STATUS_UNSUPPORTED;
+}
+
+static bt_status_t write_descriptor(int conn_id, btgatt_srvc_id_t *srvc_id,
+				btgatt_gatt_id_t *char_id,
+				btgatt_gatt_id_t *descr_id, int write_type,
+				int len, int auth_req, char *p_value)
+{
+	return BT_STATUS_UNSUPPORTED;
+}
+
+static bt_status_t execute_write(int conn_id, int execute)
+{
+	return BT_STATUS_UNSUPPORTED;
+}
+
+static bt_status_t register_for_notification(int client_if,
+						const bt_bdaddr_t *bd_addr,
+						btgatt_srvc_id_t *srvc_id,
+						btgatt_gatt_id_t *char_id)
+{
+	return BT_STATUS_UNSUPPORTED;
+}
+
+static bt_status_t deregister_for_notification(int client_if,
+			const bt_bdaddr_t *bd_addr, btgatt_srvc_id_t *srvc_id,
+			btgatt_gatt_id_t *char_id)
+{
+	return BT_STATUS_UNSUPPORTED;
+}
+
+static bt_status_t read_remote_rssi(int client_if, const bt_bdaddr_t *bd_addr)
+{
+	return BT_STATUS_UNSUPPORTED;
+}
+
+static int get_device_type(const bt_bdaddr_t *bd_addr)
+{
+	return 0;
+}
+
+static bt_status_t set_adv_data(int server_if, bool set_scan_rsp,
+			bool include_name, bool include_txpower,
+			int min_interval, int max_interval, int appearance,
+			uint16_t manufacturer_len, char *manufacturer_data)
+{
+	return BT_STATUS_UNSUPPORTED;
+}
+
+static bt_status_t test_command(int command, btgatt_test_params_t *params)
+{
+	return BT_STATUS_UNSUPPORTED;
+}
+
+/* Server API */
+
+static bt_status_t register_server(bt_uuid_t *uuid)
+{
+	return BT_STATUS_UNSUPPORTED;
+}
+
+static bt_status_t unregister_server(int server_if)
+{
+	return BT_STATUS_UNSUPPORTED;
+}
+
+static bt_status_t server_connect(int server_if, const bt_bdaddr_t *bd_addr,
+								bool is_direct)
+{
+	return BT_STATUS_UNSUPPORTED;
+}
+
+static bt_status_t add_service(int server_if, btgatt_srvc_id_t *srvc_id,
+								int num_handles)
+{
+	return BT_STATUS_UNSUPPORTED;
+}
+
+static bt_status_t add_included_service(int server_if, int service_handle,
+						int included_handle)
+{
+	return BT_STATUS_UNSUPPORTED;
+}
+
+static bt_status_t add_characteristic(int server_if, int service_handle,
+						bt_uuid_t *uuid, int properties,
+						int permissions)
+{
+	return BT_STATUS_UNSUPPORTED;
+}
+
+static bt_status_t add_descriptor(int server_if, int service_handle,
+					bt_uuid_t *uuid, int permissions)
+{
+	return BT_STATUS_UNSUPPORTED;
+}
+
+static bt_status_t start_service(int server_if, int service_handle,
+								int transport)
+{
+	return BT_STATUS_UNSUPPORTED;
+}
+
+static bt_status_t stop_service(int server_if, int service_handle)
+{
+	return BT_STATUS_UNSUPPORTED;
+}
+
+static bt_status_t delete_service(int server_if, int service_handle)
+{
+	return BT_STATUS_UNSUPPORTED;
+}
+
+static bt_status_t send_indication(int server_if, int attribute_handle,
+					int conn_id, int len, int confirm,
+					char *p_value)
+{
+	return BT_STATUS_UNSUPPORTED;
+}
+
+static bt_status_t send_response(int conn_id, int trans_id, int status,
+						btgatt_response_t *response)
+{
+	return BT_STATUS_UNSUPPORTED;
+}
+
+static void cleanup(void)
+{
+	struct hal_cmd_unregister_module cmd;
+
+	DBG("");
+
+	if (!interface_ready())
+		return;
+
+	cbs = NULL;
+
+	cmd.service_id = HAL_SERVICE_ID_GATT;
+
+	hal_ipc_cmd(HAL_SERVICE_ID_CORE, HAL_OP_UNREGISTER_MODULE,
+					sizeof(cmd), &cmd, 0, NULL, NULL);
+
+	hal_ipc_unregister(HAL_SERVICE_ID_GATT);
+}
+
+static btgatt_client_interface_t client_iface = {
+	.register_client = register_client,
+	.unregister_client = unregister_client,
+	.scan = scan,
+	.connect = connect,
+	.disconnect = disconnect,
+	.listen = listen,
+	.refresh = refresh,
+	.search_service = search_service,
+	.get_included_service = get_included_service,
+	.get_characteristic = get_characteristic,
+	.get_descriptor = get_descriptor,
+	.read_characteristic = read_characteristic,
+	.write_characteristic = write_characteristic,
+	.read_descriptor = read_descriptor,
+	.write_descriptor = write_descriptor,
+	.execute_write = execute_write,
+	.register_for_notification = register_for_notification,
+	.deregister_for_notification = deregister_for_notification,
+	.read_remote_rssi = read_remote_rssi,
+	.get_device_type = get_device_type,
+	.set_adv_data = set_adv_data,
+	.test_command = test_command,
+};
+
+static btgatt_server_interface_t server_iface = {
+	.register_server = register_server,
+	.unregister_server = unregister_server,
+	.connect = server_connect,
+	.add_service = add_service,
+	.add_included_service = add_included_service,
+	.add_characteristic = add_characteristic,
+	.add_descriptor = add_descriptor,
+	.start_service = start_service,
+	.stop_service = stop_service,
+	.delete_service = delete_service,
+	.send_indication = send_indication,
+	.send_response = send_response,
+};
+
+static btgatt_interface_t iface = {
+	.size = sizeof(iface),
+	.init = init,
+	.cleanup = cleanup,
+	.client = &client_iface,
+	.server = &server_iface,
+};
+
+btgatt_interface_t *bt_get_gatt_interface(void)
+{
+	return &iface;
+}
diff --git a/android/hal.h b/android/hal.h
index 6fd2559..b1c0216 100644
--- a/android/hal.h
+++ b/android/hal.h
@@ -22,6 +22,9 @@
 #include <hardware/bt_av.h>
 #include <hardware/bt_rc.h>
 #include <hardware/bt_hf.h>
+#include <hardware/bt_gatt.h>
+#include <hardware/bt_gatt_client.h>
+#include <hardware/bt_gatt_server.h>
 
 btsock_interface_t *bt_get_socket_interface(void);
 bthh_interface_t *bt_get_hidhost_interface(void);
@@ -29,6 +32,7 @@ btpan_interface_t *bt_get_pan_interface(void);
 btav_interface_t *bt_get_a2dp_interface(void);
 btrc_interface_t *bt_get_avrcp_interface(void);
 bthf_interface_t *bt_get_handsfree_interface(void);
+btgatt_interface_t *bt_get_gatt_interface(void);
 
 void bt_thread_associate(void);
 void bt_thread_disassociate(void);
-- 
1.9.0

--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux