This adds stubs for handling GATT Server's attribute database operations.
If attribute database API is accepted in proposed state, we will just need to
trigger db transactions and send proper notifications.
Jakub Tyszkowski (8):
android/gatt: Add find_server_by_id helper
android/gatt: Add Server's add_service stub
android/gatt: Add Server's add_included_service stub
android/gatt: Add Server's add_characteristic stub
android/gatt: Add Server's add_descriptor stub
android/gatt: Add Server's start_service stub
android/gatt: Add Server's stop_service stub
android/gatt: Add Server's delete_service stub
android/gatt.c | 174 +++++++++++++++++++++++++++++++++++++++++++++++++++++----
1 file changed, 164 insertions(+), 10 deletions(-)
--
1.9.1
Hi Jakub,
On Friday 11 of April 2014 15:15:11 Jakub Tyszkowski wrote:
> This adds stubs for handling GATT Server's attribute database operations.
> If attribute database API is accepted in proposed state, we will just need to
> trigger db transactions and send proper notifications.
>
> Jakub Tyszkowski (8):
> android/gatt: Add find_server_by_id helper
> android/gatt: Add Server's add_service stub
> android/gatt: Add Server's add_included_service stub
> android/gatt: Add Server's add_characteristic stub
> android/gatt: Add Server's add_descriptor stub
> android/gatt: Add Server's start_service stub
> android/gatt: Add Server's stop_service stub
> android/gatt: Add Server's delete_service stub
>
> android/gatt.c | 174 +++++++++++++++++++++++++++++++++++++++++++++++++++++----
> 1 file changed, 164 insertions(+), 10 deletions(-)
>
> --
> 1.9.1
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html
All patches applied, thanks.
--
Best regards,
Szymon Janc
---
android/gatt.c | 26 +++++++++++++++++++++++++-
1 file changed, 25 insertions(+), 1 deletion(-)
diff --git a/android/gatt.c b/android/gatt.c
index 0757436..dd9fb42 100644
--- a/android/gatt.c
+++ b/android/gatt.c
@@ -2840,10 +2840,34 @@ failed:
static void handle_server_add_descriptor(const void *buf, uint16_t len)
{
+ const struct hal_cmd_gatt_server_add_descriptor *cmd = buf;
+ char uuidstr[MAX_LEN_UUID_STR];
+ struct gatt_server *server;
+ bt_uuid_t descr_uuid;
+ uint8_t status;
+
DBG("");
+ server = find_server_by_id(cmd->server_if);
+
+ if (!server) {
+ error("gatt: server_if=%d not found", cmd->server_if);
+ status = HAL_STATUS_FAILED;
+ goto failed;
+ }
+
+ android2uuid(cmd->uuid, &descr_uuid);
+ bt_uuid_to_string(&descr_uuid, uuidstr, MAX_LEN_UUID_STR);
+
+ /* TODO: Add descriptor to attribute database */
+ DBG("Add descriptor: server: %d, srvc_hnd: %d, uuid: %s, perm: %d",
+ cmd->server_if, cmd->service_handle, uuidstr, cmd->permissions);
+
+ status = HAL_STATUS_SUCCESS;
+
+failed:
ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_GATT,
- HAL_OP_GATT_SERVER_ADD_DESCRIPTOR, HAL_STATUS_FAILED);
+ HAL_OP_GATT_SERVER_ADD_DESCRIPTOR, status);
}
static void handle_server_start_service(const void *buf, uint16_t len)
--
1.9.1
---
android/gatt.c | 21 ++++++++++++++++++++-
1 file changed, 20 insertions(+), 1 deletion(-)
diff --git a/android/gatt.c b/android/gatt.c
index d227eca..150bccb 100644
--- a/android/gatt.c
+++ b/android/gatt.c
@@ -2900,10 +2900,29 @@ failed:
static void handle_server_stop_service(const void *buf, uint16_t len)
{
+ const struct hal_cmd_gatt_server_stop_service *cmd = buf;
+ struct gatt_server *server;
+ uint8_t status;
+
DBG("");
+ server = find_server_by_id(cmd->server_if);
+
+ if (!server) {
+ error("gatt: server_if=%d not found", cmd->server_if);
+ status = HAL_STATUS_FAILED;
+ goto failed;
+ }
+
+ status = HAL_STATUS_SUCCESS;
+
+ /* TODO: stop service in attribute database */
+ DBG("Stop service: server: %d, srvc_hnd: %d", cmd->server_if,
+ cmd->service_handle);
+
+failed:
ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_GATT,
- HAL_OP_GATT_SERVER_STOP_SERVICE, HAL_STATUS_FAILED);
+ HAL_OP_GATT_SERVER_STOP_SERVICE, status);
}
static void handle_server_delete_service(const void *buf, uint16_t len)
--
1.9.1
This adds helper function analogously to find_client_by_id.
---
android/gatt.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/android/gatt.c b/android/gatt.c
index 13ae340..7b7b399 100644
--- a/android/gatt.c
+++ b/android/gatt.c
@@ -256,6 +256,11 @@ static struct gatt_client *find_client_by_id(int32_t id)
return queue_find(gatt_clients, match_client_by_id, INT_TO_PTR(id));
}
+static struct gatt_server *find_server_by_id(int32_t id)
+{
+ return queue_find(gatt_servers, match_server_by_id, INT_TO_PTR(id));
+}
+
static bool match_by_value(const void *data, const void *user_data)
{
return data == user_data;
@@ -2709,8 +2714,8 @@ static void handle_server_unregister(const void *buf, uint16_t len)
DBG("");
- server = queue_remove_if(gatt_servers, match_server_by_id,
- INT_TO_PTR(cmd->server_if));
+ server = find_server_by_id(cmd->server_if);
+
if (!server) {
error("gatt: server_if=%d not found", cmd->server_if);
status = HAL_STATUS_FAILED;
--
1.9.1
---
android/gatt.c | 22 +++++++++++++++++++++-
1 file changed, 21 insertions(+), 1 deletion(-)
diff --git a/android/gatt.c b/android/gatt.c
index dd9fb42..d227eca 100644
--- a/android/gatt.c
+++ b/android/gatt.c
@@ -2872,10 +2872,30 @@ failed:
static void handle_server_start_service(const void *buf, uint16_t len)
{
+ const struct hal_cmd_gatt_server_start_service *cmd = buf;
+ struct gatt_server *server;
+ uint8_t status;
+
DBG("");
+ server = find_server_by_id(cmd->server_if);
+
+ if (!server) {
+ error("gatt: server_if=%d not found", cmd->server_if);
+ status = HAL_STATUS_FAILED;
+ goto failed;
+ }
+
+ /* TODO: support BR/EDR (cmd->transport) */
+ /* TODO: activate service in attribute database */
+ DBG("Start service: server: %d, srvc_hnd: %d, transport_layer: %d",
+ cmd->server_if, cmd->service_handle, cmd->transport);
+
+ status = HAL_STATUS_SUCCESS;
+
+failed:
ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_GATT,
- HAL_OP_GATT_SERVER_START_SERVICE, HAL_STATUS_FAILED);
+ HAL_OP_GATT_SERVER_START_SERVICE, status);
}
static void handle_server_stop_service(const void *buf, uint16_t len)
--
1.9.1
---
android/gatt.c | 21 ++++++++++++++++++++-
1 file changed, 20 insertions(+), 1 deletion(-)
diff --git a/android/gatt.c b/android/gatt.c
index 150bccb..dc49411 100644
--- a/android/gatt.c
+++ b/android/gatt.c
@@ -2927,10 +2927,29 @@ failed:
static void handle_server_delete_service(const void *buf, uint16_t len)
{
+ const struct hal_cmd_gatt_server_delete_service *cmd = buf;
+ struct gatt_server *server;
+ uint8_t status;
+
DBG("");
+ server = find_server_by_id(cmd->server_if);
+
+ if (!server) {
+ error("gatt: server_if=%d not found", cmd->server_if);
+ status = HAL_STATUS_FAILED;
+ goto failed;
+ }
+
+ /* TODO: delete service from attribute database */
+ DBG("Delete service: server: %d, srvc_hnd: %d", cmd->server_if,
+ cmd->service_handle);
+
+ status = HAL_STATUS_SUCCESS;
+
+failed:
ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_GATT,
- HAL_OP_GATT_SERVER_DELETE_SERVICE, HAL_STATUS_FAILED);
+ HAL_OP_GATT_SERVER_DELETE_SERVICE, status);
}
static void handle_server_send_indication(const void *buf, uint16_t len)
--
1.9.1
---
android/gatt.c | 26 +++++++++++++++++++++++++-
1 file changed, 25 insertions(+), 1 deletion(-)
diff --git a/android/gatt.c b/android/gatt.c
index 7b7b399..bc41f72 100644
--- a/android/gatt.c
+++ b/android/gatt.c
@@ -2748,10 +2748,34 @@ static void handle_server_disconnect(const void *buf, uint16_t len)
static void handle_server_add_service(const void *buf, uint16_t len)
{
+ const struct hal_cmd_gatt_server_add_service *cmd = buf;
+ char uuidstr[MAX_LEN_UUID_STR];
+ struct gatt_server *server;
+ struct element_id srvc_id;
+ uint8_t status;
+
DBG("");
+ server = find_server_by_id(cmd->server_if);
+
+ if (!server) {
+ error("gatt: server_if=%d not found", cmd->server_if);
+ status = HAL_STATUS_FAILED;
+ goto failed;
+ }
+
+ hal_srvc_id_to_element_id(&cmd->srvc_id, &srvc_id);
+ bt_uuid_to_string(&srvc_id.uuid, uuidstr, MAX_LEN_UUID_STR);
+
+ /* TODO: execute attribute database transaction */
+ DBG("Add primary service: server: %d, srvc_uuid: %s, num_handles: %d",
+ cmd->server_if, uuidstr, cmd->num_handles);
+
+ status = HAL_STATUS_SUCCESS;
+
+failed:
ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_GATT,
- HAL_OP_GATT_SERVER_ADD_SERVICE, HAL_STATUS_FAILED);
+ HAL_OP_GATT_SERVER_ADD_SERVICE, status);
}
static void handle_server_add_included_service(const void *buf, uint16_t len)
--
1.9.1
---
android/gatt.c | 21 ++++++++++++++++++++-
1 file changed, 20 insertions(+), 1 deletion(-)
diff --git a/android/gatt.c b/android/gatt.c
index bc41f72..7c81ff2 100644
--- a/android/gatt.c
+++ b/android/gatt.c
@@ -2780,10 +2780,29 @@ failed:
static void handle_server_add_included_service(const void *buf, uint16_t len)
{
+ const struct hal_cmd_gatt_server_add_inc_service *cmd = buf;
+ struct gatt_server *server;
+ uint8_t status;
+
DBG("");
+ server = find_server_by_id(cmd->server_if);
+
+ if (!server) {
+ error("gatt: server_if=%d not found", cmd->server_if);
+ status = HAL_STATUS_FAILED;
+ goto failed;
+ }
+
+ /* TODO: Add included service to attribute database */
+ DBG("Add included service: server: %d, srvc_hnd: %d, incl_hnd: %d",
+ cmd->server_if, cmd->service_handle, cmd->included_handle);
+
+ status = HAL_STATUS_SUCCESS;
+
+failed:
ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_GATT,
- HAL_OP_GATT_SERVER_ADD_INC_SERVICE, HAL_STATUS_FAILED);
+ HAL_OP_GATT_SERVER_ADD_INC_SERVICE, status);
}
static void handle_server_add_characteristic(const void *buf, uint16_t len)
--
1.9.1
---
android/gatt.c | 28 ++++++++++++++++++++++++++--
1 file changed, 26 insertions(+), 2 deletions(-)
diff --git a/android/gatt.c b/android/gatt.c
index 7c81ff2..0757436 100644
--- a/android/gatt.c
+++ b/android/gatt.c
@@ -2807,11 +2807,35 @@ failed:
static void handle_server_add_characteristic(const void *buf, uint16_t len)
{
+ const struct hal_cmd_gatt_server_add_characteristic *cmd = buf;
+ char uuidstr[MAX_LEN_UUID_STR];
+ struct gatt_server *server;
+ bt_uuid_t char_uuid;
+ uint8_t status;
+
DBG("");
+ server = find_server_by_id(cmd->server_if);
+
+ if (!server) {
+ error("gatt: server_if=%d not found", cmd->server_if);
+ status = HAL_STATUS_FAILED;
+ goto failed;
+ }
+
+ android2uuid(cmd->uuid, &char_uuid);
+ bt_uuid_to_string(&char_uuid, uuidstr, MAX_LEN_UUID_STR);
+
+ /* TODO: Add characteristic to database */
+ DBG("Add char: server: %d, uuid: %s, srvc_hnd: %d, prop: %d, perm: %d",
+ cmd->server_if, uuidstr, cmd->service_handle, cmd->properties,
+ cmd->permissions);
+
+ status = HAL_STATUS_SUCCESS;
+
+failed:
ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_GATT,
- HAL_OP_GATT_SERVER_ADD_CHARACTERISTIC,
- HAL_STATUS_FAILED);
+ HAL_OP_GATT_SERVER_ADD_CHARACTERISTIC, status);
}
static void handle_server_add_descriptor(const void *buf, uint16_t len)
--
1.9.1