* [PATCH v2 0/5] android/map-client: Add MAP client daemon implementation
@ 2014-10-14 11:24 Grzegorz Kolodziejczyk
2014-10-14 11:24 ` [PATCH v2 1/5] android/map-client: Add initial files Grzegorz Kolodziejczyk
` (4 more replies)
0 siblings, 5 replies; 8+ messages in thread
From: Grzegorz Kolodziejczyk @ 2014-10-14 11:24 UTC (permalink / raw)
To: linux-bluetooth
v1.
*Add MAP client daemon implementation (skeleton, body)
*Add haltest MAP client support
v2.
*Fix style issue in cmd handler
*Change if-else to if statements for map client instance create
*Check if allocation of cb data has failed
*Set free as destroy callback function for search service
*Fix status overwrite (add fail label)
Grzegorz Kolodziejczyk (5):
android/map-client: Add initial files
android/map-client: Add stubs for MAP client commands handlers
android/map-client: Add support for get remote MAS instances
android/ipc-tester: Add case for MAP client service opcode boundries
android/ipc-tester: Add cases for MAP client msg size
android/Android.mk | 1 +
android/Makefile.am | 1 +
android/ipc-tester.c | 18 +++++
android/main.c | 12 +++
android/map-client.c | 204 +++++++++++++++++++++++++++++++++++++++++++++++++++
android/map-client.h | 26 +++++++
6 files changed, 262 insertions(+)
create mode 100644 android/map-client.c
create mode 100644 android/map-client.h
--
1.9.3
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v2 1/5] android/map-client: Add initial files
2014-10-14 11:24 [PATCH v2 0/5] android/map-client: Add MAP client daemon implementation Grzegorz Kolodziejczyk
@ 2014-10-14 11:24 ` Grzegorz Kolodziejczyk
2014-10-14 11:24 ` [PATCH v2 2/5] android/map-client: Add stubs for MAP client commands handlers Grzegorz Kolodziejczyk
` (3 subsequent siblings)
4 siblings, 0 replies; 8+ messages in thread
From: Grzegorz Kolodziejczyk @ 2014-10-14 11:24 UTC (permalink / raw)
To: linux-bluetooth
This adds initial daemon code for MAP client profile.
---
android/Android.mk | 1 +
android/Makefile.am | 1 +
android/main.c | 12 ++++++++++++
android/map-client.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
android/map-client.h | 26 ++++++++++++++++++++++++++
5 files changed, 84 insertions(+)
create mode 100644 android/map-client.c
create mode 100644 android/map-client.h
diff --git a/android/Android.mk b/android/Android.mk
index 2b59fb8..aefe41c 100644
--- a/android/Android.mk
+++ b/android/Android.mk
@@ -57,6 +57,7 @@ LOCAL_SRC_FILES := \
bluez/android/gatt.c \
bluez/android/health.c \
bluez/profiles/health/mcap.c \
+ bluez/android/map-client.c \
bluez/src/log.c \
bluez/src/shared/mgmt.c \
bluez/src/shared/util.c \
diff --git a/android/Makefile.am b/android/Makefile.am
index b013095..b3eb1c5 100644
--- a/android/Makefile.am
+++ b/android/Makefile.am
@@ -46,6 +46,7 @@ android_bluetoothd_SOURCES = android/main.c \
android/gatt.h android/gatt.c \
android/health.h android/health.c \
profiles/health/mcap.h profiles/health/mcap.c \
+ android/map-client.h android/map-client.c \
attrib/att.c attrib/att.h \
attrib/gatt.c attrib/gatt.h \
attrib/gattrib.c attrib/gattrib.h \
diff --git a/android/main.c b/android/main.c
index 703b3b6..b5f6937 100644
--- a/android/main.c
+++ b/android/main.c
@@ -62,6 +62,7 @@
#include "gatt.h"
#include "health.h"
#include "handsfree-client.h"
+#include "map-client.h"
#include "utils.h"
#define DEFAULT_VENDOR "BlueZ"
@@ -235,6 +236,14 @@ static void service_register(const void *buf, uint16_t len)
}
break;
+ case HAL_SERVICE_ID_MAP_CLIENT:
+ if (!bt_map_client_register(hal_ipc, &adapter_bdaddr,
+ m->mode)) {
+ status = HAL_STATUS_FAILED;
+ goto failed;
+ }
+
+ break;
default:
DBG("service %u not supported", m->service_id);
status = HAL_STATUS_FAILED;
@@ -288,6 +297,9 @@ static bool unregister_service(uint8_t id)
case HAL_SERVICE_ID_HANDSFREE_CLIENT:
bt_hf_client_unregister();
break;
+ case HAL_SERVICE_ID_MAP_CLIENT:
+ bt_map_client_unregister();
+ break;
default:
DBG("service %u not supported", id);
return false;
diff --git a/android/map-client.c b/android/map-client.c
new file mode 100644
index 0000000..4556461
--- /dev/null
+++ b/android/map-client.c
@@ -0,0 +1,44 @@
+/*
+ *
+ * BlueZ - Bluetooth protocol stack for Linux
+ *
+ * Copyright (C) 2014 Intel Corporation. All rights reserved.
+ *
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdbool.h>
+#include <stdlib.h>
+#include <stdint.h>
+
+#include "ipc.h"
+#include "lib/bluetooth.h"
+#include "map-client.h"
+
+bool bt_map_client_register(struct ipc *ipc, const bdaddr_t *addr, uint8_t mode)
+{
+ return false;
+}
+
+void bt_map_client_unregister(void)
+{
+
+}
diff --git a/android/map-client.h b/android/map-client.h
new file mode 100644
index 0000000..0e63072
--- /dev/null
+++ b/android/map-client.h
@@ -0,0 +1,26 @@
+/*
+ *
+ * BlueZ - Bluetooth protocol stack for Linux
+ *
+ * Copyright (C) 2014 Intel Corporation. All rights reserved.
+ *
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+bool bt_map_client_register(struct ipc *ipc, const bdaddr_t *addr,
+ uint8_t mode);
+void bt_map_client_unregister(void);
--
1.9.3
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v2 2/5] android/map-client: Add stubs for MAP client commands handlers
2014-10-14 11:24 [PATCH v2 0/5] android/map-client: Add MAP client daemon implementation Grzegorz Kolodziejczyk
2014-10-14 11:24 ` [PATCH v2 1/5] android/map-client: Add initial files Grzegorz Kolodziejczyk
@ 2014-10-14 11:24 ` Grzegorz Kolodziejczyk
2014-10-14 11:24 ` [PATCH v2 3/5] android/map-client: Add support for get remote MAS instances Grzegorz Kolodziejczyk
` (2 subsequent siblings)
4 siblings, 0 replies; 8+ messages in thread
From: Grzegorz Kolodziejczyk @ 2014-10-14 11:24 UTC (permalink / raw)
To: linux-bluetooth
Add empty handlers for MAP client IPC commands.
---
android/map-client.c | 34 +++++++++++++++++++++++++++++++++-
1 file changed, 33 insertions(+), 1 deletion(-)
diff --git a/android/map-client.c b/android/map-client.c
index 4556461..142c680 100644
--- a/android/map-client.c
+++ b/android/map-client.c
@@ -28,17 +28,49 @@
#include <stdbool.h>
#include <stdlib.h>
#include <stdint.h>
+#include <glib.h>
#include "ipc.h"
#include "lib/bluetooth.h"
#include "map-client.h"
+#include "src/log.h"
+#include "hal-msg.h"
+
+static struct ipc *hal_ipc = NULL;
+static bdaddr_t adapter_addr;
+
+static void handle_get_instances(const void *buf, uint16_t len)
+{
+ DBG("");
+
+ ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_MAP_CLIENT,
+ HAL_OP_MAP_CLIENT_GET_INSTANCES, HAL_STATUS_FAILED);
+}
+
+static const struct ipc_handler cmd_handlers[] = {
+ /* HAL_OP_MAP_CLIENT_GET_INSTANCES */
+ { handle_get_instances, false,
+ sizeof(struct hal_cmd_map_client_get_instances) },
+};
bool bt_map_client_register(struct ipc *ipc, const bdaddr_t *addr, uint8_t mode)
{
- return false;
+ DBG("");
+
+ bacpy(&adapter_addr, addr);
+
+ hal_ipc = ipc;
+
+ ipc_register(hal_ipc, HAL_SERVICE_ID_MAP_CLIENT, cmd_handlers,
+ G_N_ELEMENTS(cmd_handlers));
+
+ return true;
}
void bt_map_client_unregister(void)
{
+ DBG("");
+ ipc_unregister(hal_ipc, HAL_SERVICE_ID_MAP_CLIENT);
+ hal_ipc = NULL;
}
--
1.9.3
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v2 3/5] android/map-client: Add support for get remote MAS instances
2014-10-14 11:24 [PATCH v2 0/5] android/map-client: Add MAP client daemon implementation Grzegorz Kolodziejczyk
2014-10-14 11:24 ` [PATCH v2 1/5] android/map-client: Add initial files Grzegorz Kolodziejczyk
2014-10-14 11:24 ` [PATCH v2 2/5] android/map-client: Add stubs for MAP client commands handlers Grzegorz Kolodziejczyk
@ 2014-10-14 11:24 ` Grzegorz Kolodziejczyk
2014-10-15 14:16 ` Szymon Janc
2014-10-14 11:24 ` [PATCH v2 4/5] android/ipc-tester: Add case for MAP client service opcode boundries Grzegorz Kolodziejczyk
2014-10-14 11:24 ` [PATCH v2 5/5] android/ipc-tester: Add cases for MAP client msg size Grzegorz Kolodziejczyk
4 siblings, 1 reply; 8+ messages in thread
From: Grzegorz Kolodziejczyk @ 2014-10-14 11:24 UTC (permalink / raw)
To: linux-bluetooth
This allows to get remote mas instances. In case of wrong sdp record
fail status will be returned in notification.
---
android/map-client.c | 130 ++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 129 insertions(+), 1 deletion(-)
diff --git a/android/map-client.c b/android/map-client.c
index 142c680..2069fbe 100644
--- a/android/map-client.c
+++ b/android/map-client.c
@@ -30,21 +30,149 @@
#include <stdint.h>
#include <glib.h>
+#include "lib/sdp.h"
+#include "lib/sdp_lib.h"
+#include "src/sdp-client.h"
+
#include "ipc.h"
#include "lib/bluetooth.h"
#include "map-client.h"
#include "src/log.h"
#include "hal-msg.h"
+#include "ipc-common.h"
+#include "utils.h"
+#include "src/shared/util.h"
static struct ipc *hal_ipc = NULL;
static bdaddr_t adapter_addr;
+static int fill_mce_inst(void *buf, int32_t id, int32_t scn, int32_t msg_type,
+ const void *name, uint8_t name_len)
+{
+ struct hal_map_client_mas_instance *inst = buf;
+
+ inst->id = id;
+ inst->scn = scn;
+ inst->msg_types = msg_type;
+ inst->name_len = name_len;
+
+ if (name_len)
+ memcpy(inst->name, name, name_len);
+
+ return sizeof(*inst) + name_len;
+}
+
+static void map_client_sdp_search_cb(sdp_list_t *recs, int err, gpointer data)
+{
+ uint8_t buf[IPC_MTU];
+ struct hal_ev_map_client_remote_mas_instances *ev = (void *) buf;
+ bdaddr_t *dst = data;
+ sdp_list_t *list, *protos;
+ uint8_t status;
+ int32_t id, scn, msg_type, name_len, num_instances = 0;
+ char *name;
+ size_t size;
+
+ size = sizeof(*ev);
+ bdaddr2android(dst, &ev->bdaddr);
+
+ if (err < 0) {
+ error("mce: Unable to get SDP record: %s", strerror(-err));
+ status = HAL_STATUS_FAILED;
+ goto fail;
+ }
+
+ for (list = recs; list != NULL; list = list->next) {
+ sdp_record_t *rec = list->data;
+ sdp_data_t *data;
+
+ data = sdp_data_get(rec, SDP_ATTR_MAS_INSTANCE_ID);
+ if (!data) {
+ error("mce: cannot get mas instance id");
+ continue;
+ }
+
+ id = data->val.uint8;
+
+ data = sdp_data_get(rec, SDP_ATTR_SVCNAME_PRIMARY);
+ if (!data) {
+ error("mce: cannot get mas instance name");
+ continue;
+ }
+
+ name = data->val.str;
+ name_len = data->unitSize;
+
+ data = sdp_data_get(rec, SDP_ATTR_SUPPORTED_MESSAGE_TYPES);
+ if (!data) {
+ error("mce: cannot get mas instance msg type");
+ continue;
+ }
+
+ msg_type = data->val.uint8;
+
+ if (sdp_get_access_protos(rec, &protos)) {
+ error("mce: cannot get mas instance sdp protocol list");
+ continue;
+ }
+
+ scn = sdp_get_proto_port(protos, RFCOMM_UUID);
+ if (scn) {
+ error("mce: cannot get mas instance rfcomm channel");
+ continue;
+ }
+
+ sdp_list_foreach(protos, (sdp_list_func_t) sdp_list_free, NULL);
+ sdp_list_free(protos, NULL);
+
+ size += fill_mce_inst(buf + size, id, scn, msg_type, name,
+ name_len);
+ num_instances++;
+ }
+
+ status = HAL_STATUS_SUCCESS;
+
+fail:
+ ev->num_instances = num_instances;
+ ev->status = status;
+
+ ipc_send_notif(hal_ipc, HAL_SERVICE_ID_MAP_CLIENT,
+ HAL_EV_MAP_CLIENT_REMOTE_MAS_INSTANCES, size, buf);
+
+ free(dst);
+}
+
static void handle_get_instances(const void *buf, uint16_t len)
{
+ const struct hal_cmd_map_client_get_instances *cmd = buf;
+ uint8_t status;
+ bdaddr_t *dst;
+ uuid_t uuid;
+
DBG("");
+ dst = new0(bdaddr_t, 1);
+ if (!dst) {
+ error("mce: Fail to allocate cb data");
+ status = HAL_STATUS_FAILED;
+ goto failed;
+ }
+
+ android2bdaddr(&cmd->bdaddr, dst);
+ sdp_uuid16_create(&uuid, MAP_MSE_SVCLASS_ID);
+
+ if (bt_search_service(&adapter_addr, dst, &uuid,
+ map_client_sdp_search_cb, dst, free, 0)) {
+ error("mce: Failed to search SDP details");
+ status = HAL_STATUS_FAILED;
+ goto failed;
+ }
+
+ status = HAL_STATUS_SUCCESS;
+
+failed:
ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_MAP_CLIENT,
- HAL_OP_MAP_CLIENT_GET_INSTANCES, HAL_STATUS_FAILED);
+ HAL_OP_MAP_CLIENT_GET_INSTANCES, status);
}
static const struct ipc_handler cmd_handlers[] = {
--
1.9.3
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v2 4/5] android/ipc-tester: Add case for MAP client service opcode boundries
2014-10-14 11:24 [PATCH v2 0/5] android/map-client: Add MAP client daemon implementation Grzegorz Kolodziejczyk
` (2 preceding siblings ...)
2014-10-14 11:24 ` [PATCH v2 3/5] android/map-client: Add support for get remote MAS instances Grzegorz Kolodziejczyk
@ 2014-10-14 11:24 ` Grzegorz Kolodziejczyk
2014-10-14 11:24 ` [PATCH v2 5/5] android/ipc-tester: Add cases for MAP client msg size Grzegorz Kolodziejczyk
4 siblings, 0 replies; 8+ messages in thread
From: Grzegorz Kolodziejczyk @ 2014-10-14 11:24 UTC (permalink / raw)
To: linux-bluetooth
This patch adds test sending out of range opcode for service.
---
android/ipc-tester.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/android/ipc-tester.c b/android/ipc-tester.c
index 161777d..7dd25e8 100644
--- a/android/ipc-tester.c
+++ b/android/ipc-tester.c
@@ -940,6 +940,10 @@ int main(int argc, char *argv[])
HAL_SERVICE_ID_BLUETOOTH,
HAL_SERVICE_ID_HANDSFREE_CLIENT);
+ test_opcode_valid("MAP_CLIENT", HAL_SERVICE_ID_MAP_CLIENT, 0x01, 0,
+ HAL_SERVICE_ID_BLUETOOTH,
+ HAL_SERVICE_ID_MAP_CLIENT);
+
/* check for valid data size */
test_datasize_valid("CORE Register+", HAL_SERVICE_ID_CORE,
HAL_OP_REGISTER_MODULE,
--
1.9.3
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v2 5/5] android/ipc-tester: Add cases for MAP client msg size
2014-10-14 11:24 [PATCH v2 0/5] android/map-client: Add MAP client daemon implementation Grzegorz Kolodziejczyk
` (3 preceding siblings ...)
2014-10-14 11:24 ` [PATCH v2 4/5] android/ipc-tester: Add case for MAP client service opcode boundries Grzegorz Kolodziejczyk
@ 2014-10-14 11:24 ` Grzegorz Kolodziejczyk
4 siblings, 0 replies; 8+ messages in thread
From: Grzegorz Kolodziejczyk @ 2014-10-14 11:24 UTC (permalink / raw)
To: linux-bluetooth
Add cases testing message size verification for MAP client opcodes.
---
android/ipc-tester.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/android/ipc-tester.c b/android/ipc-tester.c
index 7dd25e8..357dda9 100644
--- a/android/ipc-tester.c
+++ b/android/ipc-tester.c
@@ -1486,5 +1486,19 @@ int main(int argc, char *argv[])
HAL_SERVICE_ID_BLUETOOTH,
HAL_SERVICE_ID_HANDSFREE_CLIENT);
+ /* check for valid data size for MAP CLIENT */
+ test_datasize_valid("MAP CLIENT Get instances+",
+ HAL_SERVICE_ID_MAP_CLIENT,
+ HAL_OP_MAP_CLIENT_GET_INSTANCES,
+ sizeof(struct hal_cmd_map_client_get_instances),
+ 1, HAL_SERVICE_ID_BLUETOOTH,
+ HAL_SERVICE_ID_MAP_CLIENT);
+ test_datasize_valid("MAP CLIENT Get instances-",
+ HAL_SERVICE_ID_MAP_CLIENT,
+ HAL_OP_MAP_CLIENT_GET_INSTANCES,
+ sizeof(struct hal_cmd_map_client_get_instances),
+ -1, HAL_SERVICE_ID_BLUETOOTH,
+ HAL_SERVICE_ID_MAP_CLIENT);
+
return tester_run();
}
--
1.9.3
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH v2 3/5] android/map-client: Add support for get remote MAS instances
2014-10-14 11:24 ` [PATCH v2 3/5] android/map-client: Add support for get remote MAS instances Grzegorz Kolodziejczyk
@ 2014-10-15 14:16 ` Szymon Janc
2014-10-15 14:22 ` Grzegorz Kolodziejczyk
0 siblings, 1 reply; 8+ messages in thread
From: Szymon Janc @ 2014-10-15 14:16 UTC (permalink / raw)
To: Grzegorz Kolodziejczyk; +Cc: linux-bluetooth
Hi Grzegorz,
On Tuesday 14 of October 2014 13:24:33 Grzegorz Kolodziejczyk wrote:
> This allows to get remote mas instances. In case of wrong sdp record
> fail status will be returned in notification.
> ---
> android/map-client.c | 130
> ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 129
> insertions(+), 1 deletion(-)
>
> diff --git a/android/map-client.c b/android/map-client.c
> index 142c680..2069fbe 100644
> --- a/android/map-client.c
> +++ b/android/map-client.c
> @@ -30,21 +30,149 @@
> #include <stdint.h>
> #include <glib.h>
>
> +#include "lib/sdp.h"
> +#include "lib/sdp_lib.h"
> +#include "src/sdp-client.h"
> +
> #include "ipc.h"
> #include "lib/bluetooth.h"
> #include "map-client.h"
> #include "src/log.h"
> #include "hal-msg.h"
> +#include "ipc-common.h"
> +#include "utils.h"
> +#include "src/shared/util.h"
>
> static struct ipc *hal_ipc = NULL;
> static bdaddr_t adapter_addr;
>
> +static int fill_mce_inst(void *buf, int32_t id, int32_t scn, int32_t
> msg_type, + const void *name, uint8_t name_len)
> +{
> + struct hal_map_client_mas_instance *inst = buf;
> +
> + inst->id = id;
> + inst->scn = scn;
> + inst->msg_types = msg_type;
> + inst->name_len = name_len;
> +
> + if (name_len)
> + memcpy(inst->name, name, name_len);
> +
> + return sizeof(*inst) + name_len;
> +}
> +
> +static void map_client_sdp_search_cb(sdp_list_t *recs, int err, gpointer
> data) +{
> + uint8_t buf[IPC_MTU];
> + struct hal_ev_map_client_remote_mas_instances *ev = (void *) buf;
> + bdaddr_t *dst = data;
> + sdp_list_t *list, *protos;
> + uint8_t status;
> + int32_t id, scn, msg_type, name_len, num_instances = 0;
> + char *name;
> + size_t size;
> +
> + size = sizeof(*ev);
> + bdaddr2android(dst, &ev->bdaddr);
> +
> + if (err < 0) {
> + error("mce: Unable to get SDP record: %s", strerror(-err));
> + status = HAL_STATUS_FAILED;
> + goto fail;
> + }
> +
> + for (list = recs; list != NULL; list = list->next) {
> + sdp_record_t *rec = list->data;
> + sdp_data_t *data;
> +
> + data = sdp_data_get(rec, SDP_ATTR_MAS_INSTANCE_ID);
> + if (!data) {
> + error("mce: cannot get mas instance id");
> + continue;
> + }
> +
> + id = data->val.uint8;
> +
> + data = sdp_data_get(rec, SDP_ATTR_SVCNAME_PRIMARY);
> + if (!data) {
> + error("mce: cannot get mas instance name");
> + continue;
> + }
> +
> + name = data->val.str;
> + name_len = data->unitSize;
> +
> + data = sdp_data_get(rec, SDP_ATTR_SUPPORTED_MESSAGE_TYPES);
> + if (!data) {
> + error("mce: cannot get mas instance msg type");
> + continue;
> + }
> +
> + msg_type = data->val.uint8;
> +
> + if (sdp_get_access_protos(rec, &protos)) {
Please do check this check as '< 0'.
> + error("mce: cannot get mas instance sdp protocol list");
> + continue;
> + }
> +
> + scn = sdp_get_proto_port(protos, RFCOMM_UUID);
> + if (scn) {
Shouldn't this be if (!scn) ...?
> + error("mce: cannot get mas instance rfcomm channel");
> + continue;
This will leak protos. I'd just free those before checking scn.
> + }
> +
> + sdp_list_foreach(protos, (sdp_list_func_t) sdp_list_free, NULL);
> + sdp_list_free(protos, NULL);
> +
> + size += fill_mce_inst(buf + size, id, scn, msg_type, name,
> + name_len);
> + num_instances++;
> + }
> +
> + status = HAL_STATUS_SUCCESS;
> +
> +fail:
> + ev->num_instances = num_instances;
> + ev->status = status;
> +
> + ipc_send_notif(hal_ipc, HAL_SERVICE_ID_MAP_CLIENT,
> + HAL_EV_MAP_CLIENT_REMOTE_MAS_INSTANCES, size, buf);
> +
> + free(dst);
> +}
> +
> static void handle_get_instances(const void *buf, uint16_t len)
> {
> + const struct hal_cmd_map_client_get_instances *cmd = buf;
> + uint8_t status;
> + bdaddr_t *dst;
> + uuid_t uuid;
> +
> DBG("");
>
> + dst = new0(bdaddr_t, 1);
> + if (!dst) {
> + error("mce: Fail to allocate cb data");
> + status = HAL_STATUS_FAILED;
> + goto failed;
> + }
> +
> + android2bdaddr(&cmd->bdaddr, dst);
> + sdp_uuid16_create(&uuid, MAP_MSE_SVCLASS_ID);
> +
> + if (bt_search_service(&adapter_addr, dst, &uuid,
> + map_client_sdp_search_cb, dst, free, 0)) {
> + error("mce: Failed to search SDP details");
> + status = HAL_STATUS_FAILED;
> + goto failed;
> + }
> +
> + status = HAL_STATUS_SUCCESS;
> +
> +failed:
> ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_MAP_CLIENT,
> - HAL_OP_MAP_CLIENT_GET_INSTANCES, HAL_STATUS_FAILED);
> + HAL_OP_MAP_CLIENT_GET_INSTANCES, status);
> }
>
> static const struct ipc_handler cmd_handlers[] = {
--
BR
Szymon Janc
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2 3/5] android/map-client: Add support for get remote MAS instances
2014-10-15 14:16 ` Szymon Janc
@ 2014-10-15 14:22 ` Grzegorz Kolodziejczyk
0 siblings, 0 replies; 8+ messages in thread
From: Grzegorz Kolodziejczyk @ 2014-10-15 14:22 UTC (permalink / raw)
To: Szymon Janc; +Cc: linux-bluetooth
Hi Szymon,
On 15 October 2014 16:16, Szymon Janc <szymon.janc@tieto.com> wrote:
> Hi Grzegorz,
>
> On Tuesday 14 of October 2014 13:24:33 Grzegorz Kolodziejczyk wrote:
>> This allows to get remote mas instances. In case of wrong sdp record
>> fail status will be returned in notification.
>> ---
>> android/map-client.c | 130
>> ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 129
>> insertions(+), 1 deletion(-)
>>
>> diff --git a/android/map-client.c b/android/map-client.c
>> index 142c680..2069fbe 100644
>> --- a/android/map-client.c
>> +++ b/android/map-client.c
>> @@ -30,21 +30,149 @@
>> #include <stdint.h>
>> #include <glib.h>
>>
>> +#include "lib/sdp.h"
>> +#include "lib/sdp_lib.h"
>> +#include "src/sdp-client.h"
>> +
>> #include "ipc.h"
>> #include "lib/bluetooth.h"
>> #include "map-client.h"
>> #include "src/log.h"
>> #include "hal-msg.h"
>> +#include "ipc-common.h"
>> +#include "utils.h"
>> +#include "src/shared/util.h"
>>
>> static struct ipc *hal_ipc = NULL;
>> static bdaddr_t adapter_addr;
>>
>> +static int fill_mce_inst(void *buf, int32_t id, int32_t scn, int32_t
>> msg_type, + const void *name, uint8_t name_len)
>> +{
>> + struct hal_map_client_mas_instance *inst = buf;
>> +
>> + inst->id = id;
>> + inst->scn = scn;
>> + inst->msg_types = msg_type;
>> + inst->name_len = name_len;
>> +
>> + if (name_len)
>> + memcpy(inst->name, name, name_len);
>> +
>> + return sizeof(*inst) + name_len;
>> +}
>> +
>> +static void map_client_sdp_search_cb(sdp_list_t *recs, int err, gpointer
>> data) +{
>> + uint8_t buf[IPC_MTU];
>> + struct hal_ev_map_client_remote_mas_instances *ev = (void *) buf;
>> + bdaddr_t *dst = data;
>> + sdp_list_t *list, *protos;
>> + uint8_t status;
>> + int32_t id, scn, msg_type, name_len, num_instances = 0;
>> + char *name;
>> + size_t size;
>> +
>> + size = sizeof(*ev);
>> + bdaddr2android(dst, &ev->bdaddr);
>> +
>> + if (err < 0) {
>> + error("mce: Unable to get SDP record: %s", strerror(-err));
>> + status = HAL_STATUS_FAILED;
>> + goto fail;
>> + }
>> +
>> + for (list = recs; list != NULL; list = list->next) {
>> + sdp_record_t *rec = list->data;
>> + sdp_data_t *data;
>> +
>> + data = sdp_data_get(rec, SDP_ATTR_MAS_INSTANCE_ID);
>> + if (!data) {
>> + error("mce: cannot get mas instance id");
>> + continue;
>> + }
>> +
>> + id = data->val.uint8;
>> +
>> + data = sdp_data_get(rec, SDP_ATTR_SVCNAME_PRIMARY);
>> + if (!data) {
>> + error("mce: cannot get mas instance name");
>> + continue;
>> + }
>> +
>> + name = data->val.str;
>> + name_len = data->unitSize;
>> +
>> + data = sdp_data_get(rec, SDP_ATTR_SUPPORTED_MESSAGE_TYPES);
>> + if (!data) {
>> + error("mce: cannot get mas instance msg type");
>> + continue;
>> + }
>> +
>> + msg_type = data->val.uint8;
>> +
>> + if (sdp_get_access_protos(rec, &protos)) {
>
> Please do check this check as '< 0'.
>
>> + error("mce: cannot get mas instance sdp protocol list");
>> + continue;
>> + }
>> +
>> + scn = sdp_get_proto_port(protos, RFCOMM_UUID);
>> + if (scn) {
>
> Shouldn't this be if (!scn) ...?
>
>> + error("mce: cannot get mas instance rfcomm channel");
>> + continue;
>
> This will leak protos. I'd just free those before checking scn.
>
>> + }
>> +
>> + sdp_list_foreach(protos, (sdp_list_func_t) sdp_list_free, NULL);
>> + sdp_list_free(protos, NULL);
>> +
>> + size += fill_mce_inst(buf + size, id, scn, msg_type, name,
>> + name_len);
>> + num_instances++;
>> + }
>> +
>> + status = HAL_STATUS_SUCCESS;
>> +
>> +fail:
>> + ev->num_instances = num_instances;
>> + ev->status = status;
>> +
>> + ipc_send_notif(hal_ipc, HAL_SERVICE_ID_MAP_CLIENT,
>> + HAL_EV_MAP_CLIENT_REMOTE_MAS_INSTANCES, size, buf);
>> +
>> + free(dst);
>> +}
>> +
>> static void handle_get_instances(const void *buf, uint16_t len)
>> {
>> + const struct hal_cmd_map_client_get_instances *cmd = buf;
>> + uint8_t status;
>> + bdaddr_t *dst;
>> + uuid_t uuid;
>> +
>> DBG("");
>>
>> + dst = new0(bdaddr_t, 1);
>> + if (!dst) {
>> + error("mce: Fail to allocate cb data");
>> + status = HAL_STATUS_FAILED;
>> + goto failed;
>> + }
>> +
>> + android2bdaddr(&cmd->bdaddr, dst);
>> + sdp_uuid16_create(&uuid, MAP_MSE_SVCLASS_ID);
>> +
>> + if (bt_search_service(&adapter_addr, dst, &uuid,
>> + map_client_sdp_search_cb, dst, free, 0)) {
>> + error("mce: Failed to search SDP details");
>> + status = HAL_STATUS_FAILED;
>> + goto failed;
>> + }
>> +
>> + status = HAL_STATUS_SUCCESS;
>> +
>> +failed:
>> ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_MAP_CLIENT,
>> - HAL_OP_MAP_CLIENT_GET_INSTANCES, HAL_STATUS_FAILED);
>> + HAL_OP_MAP_CLIENT_GET_INSTANCES, status);
>> }
>>
>> static const struct ipc_handler cmd_handlers[] = {
>
> --
> BR
> Szymon Janc
Ok, I'll correct it.
BR,
Grzegorz
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2014-10-15 14:22 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-10-14 11:24 [PATCH v2 0/5] android/map-client: Add MAP client daemon implementation Grzegorz Kolodziejczyk
2014-10-14 11:24 ` [PATCH v2 1/5] android/map-client: Add initial files Grzegorz Kolodziejczyk
2014-10-14 11:24 ` [PATCH v2 2/5] android/map-client: Add stubs for MAP client commands handlers Grzegorz Kolodziejczyk
2014-10-14 11:24 ` [PATCH v2 3/5] android/map-client: Add support for get remote MAS instances Grzegorz Kolodziejczyk
2014-10-15 14:16 ` Szymon Janc
2014-10-15 14:22 ` Grzegorz Kolodziejczyk
2014-10-14 11:24 ` [PATCH v2 4/5] android/ipc-tester: Add case for MAP client service opcode boundries Grzegorz Kolodziejczyk
2014-10-14 11:24 ` [PATCH v2 5/5] android/ipc-tester: Add cases for MAP client msg size Grzegorz Kolodziejczyk
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.