2014-06-26 13:09:05

by Jakub Tyszkowski

[permalink] [raw]
Subject: [PATCH 1/7] android/pts: Change MCAP PIXIT value

Handling single data channel will simplify mcaptest tool.
This can be changed later when mcaptest will be improved.
---
android/pixit-mcap.txt | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/android/pixit-mcap.txt b/android/pixit-mcap.txt
index ee67a1a..81cc6dc 100644
--- a/android/pixit-mcap.txt
+++ b/android/pixit-mcap.txt
@@ -11,7 +11,7 @@ Parameter Name Value
-------------------------------------------------------------------------------
TSPX_bd_addr_iut 112233445566 (*&)
TSPX_delete_link_key FALSE
-TSPX_MCAP_DC_max 2
+TSPX_MCAP_DC_max 1
TSPX_MCAP_l2cap_psm_control 1003
TSPX_MCAP_l2cap_psm_control_B
TSPX_MCAP_l2cap_psm_data 1005
--
2.0.0



2014-06-26 16:08:43

by Szymon Janc

[permalink] [raw]
Subject: Re: [PATCH 1/7] android/pts: Change MCAP PIXIT value

Hi Jakub,

On Thursday 26 of June 2014 15:09:05 Jakub Tyszkowski wrote:
> Handling single data channel will simplify mcaptest tool.
> This can be changed later when mcaptest will be improved.
> ---
> android/pixit-mcap.txt | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/android/pixit-mcap.txt b/android/pixit-mcap.txt
> index ee67a1a..81cc6dc 100644
> --- a/android/pixit-mcap.txt
> +++ b/android/pixit-mcap.txt
> @@ -11,7 +11,7 @@ Parameter Name Value
> -------------------------------------------------------------------------------
> TSPX_bd_addr_iut 112233445566 (*&)
> TSPX_delete_link_key FALSE
> -TSPX_MCAP_DC_max 2
> +TSPX_MCAP_DC_max 1
> TSPX_MCAP_l2cap_psm_control 1003
> TSPX_MCAP_l2cap_psm_control_B
> TSPX_MCAP_l2cap_psm_data 1005
>

All patches applied (with some minor cleanups). Thanks.

--
Best regards,
Szymon Janc

2014-06-26 13:09:11

by Jakub Tyszkowski

[permalink] [raw]
Subject: [PATCH 7/7] android/pts: Update MCAP results

---
android/pts-mcap.txt | 80 ++++++++++++++++++++++++++--------------------------
1 file changed, 40 insertions(+), 40 deletions(-)

diff --git a/android/pts-mcap.txt b/android/pts-mcap.txt
index 9a77839..9542b8c 100644
--- a/android/pts-mcap.txt
+++ b/android/pts-mcap.txt
@@ -1,7 +1,7 @@
PTS test results for MCAP

PTS version: 5.1
-Tested: not tested
+Tested: 26-June-2014
Android version: 4.4.2

Results:
@@ -13,28 +13,28 @@ N/A test is disabled due to PICS setup
-------------------------------------------------------------------------------
Test Name Result Notes
-------------------------------------------------------------------------------
-TC_MCAP_CE_BV_01_C INC
-TC_MCAP_CE_BV_02_C INC
-TC_MCAP_CE_BV_03_C INC
-TC_MCAP_CE_BV_04_C INC
+TC_MCAP_CE_BV_01_C PASS mcaptest -C 4099 -D 4101 -dc <PTS addr>
+TC_MCAP_CE_BV_02_C PASS mcaptest -C 4099 -D 4101
+TC_MCAP_CE_BV_03_C PASS mcaptest -C 4099 -D 4101 -c <PTS addr>
+TC_MCAP_CE_BV_04_C PASS mcaptest -C 4099 -D 4101 -d
TC_MCAP_CM_ABT_BV_01_C N/A
-TC_MCAP_CM_ABT_BV_02_C INC
+TC_MCAP_CM_ABT_BV_02_C PASS mcaptest -C 4099 -D 4101
TC_MCAP_CM_ABT_BV_03_C N/A
TC_MCAP_CM_DEL_BV_01_C N/A
-TC_MCAP_CM_DEL_BV_02_C INC
+TC_MCAP_CM_DEL_BV_02_C PASS mcaptest -C 4099 -D 4101
TC_MCAP_CM_DEL_BV_02_C N/A
-TC_MCAP_CM_DEL_BV_04_C INC
-TC_MCAP_CM_DIS_BV_01_C INC
-TC_MCAP_CM_DIS_BV_02_C INC
-TC_MCAP_CM_DIS_BV_03_C INC
-TC_MCAP_CM_DIS_BV_04_C INC
-TC_MCAP_CM_DIS_BV_05_C INC
+TC_MCAP_CM_DEL_BV_04_C PASS mcaptest -C 4099 -D 4101
+TC_MCAP_CM_DIS_BV_01_C PASS mcaptest -C 4099 -D 4101 -e 2 -f 2
+TC_MCAP_CM_DIS_BV_02_C PASS mcaptest -C 4099 -D 4101
+TC_MCAP_CM_DIS_BV_03_C PASS mcaptest -C 4099 -D 4101
+TC_MCAP_CM_DIS_BV_04_C PASS mcaptest -C 4099 -D 4101 -e 2 -f 2
+TC_MCAP_CM_DIS_BV_05_C PASS mcaptest -C 4099 -D 4101
TC_MCAP_CM_REC_BV_01_C N/A
-TC_MCAP_CM_REC_BV_02_C INC
+TC_MCAP_CM_REC_BV_02_C PASS mcaptest -C 4099 -D 4101
TC_MCAP_CM_REC_BV_03_C N/A
-TC_MCAP_CM_REC_BV_04_C INC
+TC_MCAP_CM_REC_BV_04_C INC possible PTS issue #12182
TC_MCAP_CM_REC_BV_05_C N/A
-TC_MCAP_CM_REC_BV_06_C INC
+TC_MCAP_CM_REC_BV_06_C PASS mcaptest -C 4099 -D 4101
TC_MCAP_CS_ERR_BI_01_C N/A
TC_MCAP_CS_ERR_BI_02_C N/A
TC_MCAP_CS_ERR_BI_03_C N/A
@@ -47,31 +47,31 @@ TC_MCAP_CS_R_BV_01_I N/A
TC_MCAP_CS_R_BV_02_I N/A
TC_MCAP_CS_R_BV_03_C N/A
TC_MCAP_CS_T_BV_04_C N/A
-TC_MCAP_ERR_BI_01_C INC
-TC_MCAP_ERR_BI_02_C INC
-TC_MCAP_ERR_BI_03_C INC
-TC_MCAP_ERR_BI_04_C INC
-TC_MCAP_ERR_BI_05_C INC
-TC_MCAP_ERR_BI_06_C INC
-TC_MCAP_ERR_BI_07_C INC
-TC_MCAP_ERR_BI_08_C INC
-TC_MCAP_ERR_BI_09_C INC
-TC_MCAP_ERR_BI_10_C INC
-TC_MCAP_ERR_BI_11_C INC
+TC_MCAP_ERR_BI_01_C PASS mcaptest -C 4099 -D 4101
+TC_MCAP_ERR_BI_02_C PASS mcaptest -C 4099 -D 4101 -d
+TC_MCAP_ERR_BI_03_C PASS mcaptest -C 4099 -D 4101
+TC_MCAP_ERR_BI_04_C PASS mcaptest -C 4099 -D 4101 -d
+TC_MCAP_ERR_BI_05_C PASS mcaptest -C 4099 -D 4101
+TC_MCAP_ERR_BI_06_C PASS mcaptest -C 4099 -D 4101 -d
+TC_MCAP_ERR_BI_07_C PASS mcaptest -C 4099 -D 4101
+TC_MCAP_ERR_BI_08_C PASS mcaptest -C 4099 -D 4101 -d
+TC_MCAP_ERR_BI_09_C PASS mcaptest -C 4099 -D 4101
+TC_MCAP_ERR_BI_10_C PASS mcaptest -C 4099 -D 4101
+TC_MCAP_ERR_BI_11_C PASS mcaptest -C 4099 -D 4101 -d
TC_MCAP_ERR_BI_12_C INC
-TC_MCAP_ERR_BI_13_C INC
-TC_MCAP_ERR_BI_14_C INC
-TC_MCAP_ERR_BI_15_C INC
+TC_MCAP_ERR_BI_13_C PASS mcaptest -C 4099 -D 4101
+TC_MCAP_ERR_BI_14_C PASS mcaptest -C 4099 -D 4101
+TC_MCAP_ERR_BI_15_C PASS mcaptest -C 4099 -D 4101 -d
TC_MCAP_ERR_BI_16_C INC
-TC_MCAP_ERR_BI_17_C INC
-TC_MCAP_ERR_BI_18_C INC
-TC_MCAP_ERR_BI_19_C INC
+TC_MCAP_ERR_BI_17_C PASS mcaptest -C 4099 -D 4101 -d
+TC_MCAP_ERR_BI_18_C PASS mcaptest -C 4099 -D 4101 -d
+TC_MCAP_ERR_BI_19_C PASS mcaptest -C 4099 -D 4101
TC_MCAP_ERR_BI_20_C INC
-TC_MCAP_INV_BI_01_C INC
-TC_MCAP_INV_BI_02_C INC
-TC_MCAP_INV_BI_03_C INC
-TC_MCAP_INV_BI_04_C INC
-TC_MCAP_INV_BI_05_C INC
-TC_MCAP_INV_BI_06_C INC
-TC_MCAP_INV_BI_07_C INC
+TC_MCAP_INV_BI_01_C PASS mcaptest -C 4099 -D 4101 -dc <PTS addr>
+TC_MCAP_INV_BI_02_C PASS mcaptest -C 4099 -D 4101 -d
+TC_MCAP_INV_BI_03_C PASS mcaptest -C 4099 -D 4101 -dc <PTS addr>
+TC_MCAP_INV_BI_04_C PASS mcaptest -C 4099 -D 4101 -c <PTS addr>
+TC_MCAP_INV_BI_05_C PASS mcaptest -C 4099 -D 4101
+TC_MCAP_INV_BI_06_C PASS mcaptest -C 4099 -D 4101
+TC_MCAP_INV_BI_07_C PASS mcaptest -C 4099 -D 4101
-------------------------------------------------------------------------------
--
2.0.0


2014-06-26 13:09:08

by Jakub Tyszkowski

[permalink] [raw]
Subject: [PATCH 4/7] android/mcaptest: Support incomming connections

This adds support for handling incomming Control Link (MCL) and Data
Link (MDL) connections.
---
android/mcaptest.c | 115 ++++++++++++++++++++++++++++++++++++++++++++++-------
1 file changed, 100 insertions(+), 15 deletions(-)

diff --git a/android/mcaptest.c b/android/mcaptest.c
index 0ad51a6..8d30e4d 100644
--- a/android/mcaptest.c
+++ b/android/mcaptest.c
@@ -54,11 +54,47 @@ static struct mcap_mdl *mdl = NULL;
static uint16_t mdlid;

static int control_mode = MODE_LISTEN;
+static int data_mode = MODE_LISTEN;

-static void mcl_connected(struct mcap_mcl *mcl, gpointer data)
+static struct mcap_mcl *mcl = NULL;
+
+static void mdl_connected_cb(struct mcap_mdl *mdl, void *data)
+{
+ /* TODO */
+ printf("%s\n", __func__);
+}
+
+static void mdl_closed_cb(struct mcap_mdl *mdl, void *data)
+{
+ /* TODO */
+ printf("%s\n", __func__);
+}
+
+static void mdl_deleted_cb(struct mcap_mdl *mdl, void *data)
+{
+ /* TODO */
+ printf("%s\n", __func__);
+}
+
+static void mdl_aborted_cb(struct mcap_mdl *mdl, void *data)
{
/* TODO */
- printf("MCL connected unsupported\n");
+ printf("%s\n", __func__);
+}
+
+static uint8_t mdl_conn_req_cb(struct mcap_mcl *mcl, uint8_t mdepid,
+ uint16_t mdlid, uint8_t *conf, void *data)
+{
+ printf("%s\n", __func__);
+
+ return MCAP_SUCCESS;
+}
+
+static uint8_t mdl_reconn_req_cb(struct mcap_mdl *mdl, void *data)
+{
+ printf("%s\n", __func__);
+
+ return MCAP_SUCCESS;
}

static void mcl_reconnected(struct mcap_mcl *mcl, gpointer data)
@@ -109,30 +145,69 @@ static void create_mdl_cb(struct mcap_mdl *mcap_mdl, uint8_t type, GError *gerr,
}
}

-static void create_mcl_cb(struct mcap_mcl *mcl, GError *err, gpointer data)
+static void trigger_mdl_action(int mode)
{
GError *gerr = NULL;
+ gboolean ret;
+
+ ret = mcap_mcl_set_cb(mcl, NULL, &gerr,
+ MCAP_MDL_CB_CONNECTED, mdl_connected_cb,
+ MCAP_MDL_CB_CLOSED, mdl_closed_cb,
+ MCAP_MDL_CB_DELETED, mdl_deleted_cb,
+ MCAP_MDL_CB_ABORTED, mdl_aborted_cb,
+ MCAP_MDL_CB_REMOTE_CONN_REQ, mdl_conn_req_cb,
+ MCAP_MDL_CB_REMOTE_RECONN_REQ, mdl_reconn_req_cb,
+ MCAP_MDL_CB_INVALID);
+
+ if (!ret && gerr) {
+ printf("MCL cannot handle connection %s\n",
+ gerr->message);
+ g_error_free(gerr);
+ }
+
+ if (mode == MODE_CONNECT) {
+ mcap_create_mdl(mcl, 1, 0, create_mdl_cb, NULL, NULL, &gerr);
+ if (gerr) {
+ printf("Could not connect MDL: %s\n", gerr->message);
+ g_error_free(gerr);
+ }
+ }
+}

+static void mcl_connected(struct mcap_mcl *mcap_mcl, gpointer data)
+{
+ printf("%s\n", __func__);
+
+ if (mcl)
+ mcap_mcl_unref(mcl);
+
+ mcl = mcap_mcl_ref(mcap_mcl);
+ trigger_mdl_action(data_mode);
+}
+
+static void create_mcl_cb(struct mcap_mcl *mcap_mcl, GError *err, gpointer data)
+{
if (err) {
printf("Could not connect MCL: %s\n", err->message);

return;
}

- mcap_create_mdl(mcl, 1, 0, create_mdl_cb, NULL, NULL, &gerr);
- if (gerr) {
- printf("Could not connect MDL: %s\n", gerr->message);
- g_error_free(gerr);
- }
-}
+ if (mcl)
+ mcap_mcl_unref(mcl);

+ mcl = mcap_mcl_ref(mcap_mcl);
+ trigger_mdl_action(data_mode);
+}
static void usage(void)
{
printf("mcaptest - MCAP testing ver %s\n", VERSION);
printf("Usage:\n"
- "\tmcaptest <mode> [options]\n");
- printf("Modes:\n"
- "\t-c connect <dst_addr> (than wait for disconnect)\n");
+ "\tmcaptest <control_mode> <data_mode> [options]\n");
+ printf("Control Link Mode:\n"
+ "\t-c connect <dst_addr>\n");
+ printf("Data Link Mode:\n"
+ "\t-d connect\n");
printf("Options:\n"
"\t-i <hcidev> HCI device\n"
"\t-C <control_ch> Control channel PSM\n"
@@ -142,7 +217,8 @@ static void usage(void)
static struct option main_options[] = {
{ "help", 0, 0, 'h' },
{ "device", 1, 0, 'i' },
- { "connect", 1, 0, 'c' },
+ { "connect_cl", 1, 0, 'c' },
+ { "connect_dl", 0, 0, 'd' },
{ "control_ch", 1, 0, 'C' },
{ "data_ch", 1, 0, 'D' },
{ 0, 0, 0, 0 }
@@ -164,7 +240,7 @@ int main(int argc, char *argv[])
exit(1);
}

- while ((opt = getopt_long(argc, argv, "+i:c:C:D:h",
+ while ((opt = getopt_long(argc, argv, "+i:c:C:D:hd",
main_options, NULL)) != EOF) {
switch (opt) {
case 'i':
@@ -181,6 +257,11 @@ int main(int argc, char *argv[])

break;

+ case 'd':
+ data_mode = MODE_CONNECT;
+
+ break;
+
case 'C':
ccpsm = atoi(optarg);

@@ -198,7 +279,7 @@ int main(int argc, char *argv[])
}
}

- mcap = mcap_create_instance(&src, BT_IO_SEC_MEDIUM, 0, 0,
+ mcap = mcap_create_instance(&src, BT_IO_SEC_MEDIUM, ccpsm, dcpsm,
mcl_connected, mcl_reconnected,
mcl_disconnected, mcl_uncached,
NULL, /* CSP is not used right now */
@@ -228,6 +309,10 @@ int main(int argc, char *argv[])
}

break;
+ case MODE_LISTEN:
+ printf("Listening for control channel connection\n");
+
+ break;
case MODE_NONE:
default:
goto done;
--
2.0.0


2014-06-26 13:09:06

by Jakub Tyszkowski

[permalink] [raw]
Subject: [PATCH 2/7] android/mcaptest: Add skeleton for mcap test tool

This adds skeleton for simple tool for testing mcap library. As mcap-lib
uses bt_io, this tool works in daemon-like mode, by utilizing Glib's main
loop.
---
.gitignore | 1 +
android/Android.mk | 35 ++++++++++
android/Makefile.am | 10 +++
android/mcaptest.c | 184 ++++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 230 insertions(+)
create mode 100644 android/mcaptest.c

diff --git a/.gitignore b/.gitignore
index 2e08c21..d661ba9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -123,6 +123,7 @@ unit/test-*.trs

android/system-emulator
android/bluetoothd
+android/mcaptest
android/haltest
android/android-tester
android/ipc-tester
diff --git a/android/Android.mk b/android/Android.mk
index fc7b59d..ec33944 100644
--- a/android/Android.mk
+++ b/android/Android.mk
@@ -182,6 +182,41 @@ LOCAL_MODULE := haltest
include $(BUILD_EXECUTABLE)

#
+# mcaptest
+#
+
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := \
+ bluez/src/log.c \
+ bluez/btio/btio.c \
+ bluez/lib/bluetooth.c \
+ bluez/lib/hci.c \
+ bluez/android/mcap-lib.c \
+ bluez/android/mcaptest.c \
+
+LOCAL_C_INCLUDES := \
+ $(call include-path-for, glib) \
+ $(call include-path-for, glib)/glib \
+
+LOCAL_C_INCLUDES += \
+ $(LOCAL_PATH)/bluez \
+
+LOCAL_CFLAGS := $(BLUEZ_COMMON_CFLAGS)
+
+LOCAL_SHARED_LIBRARIES := \
+ libglib \
+
+LOCAL_STATIC_LIBRARIES := \
+ bluetooth-headers \
+
+LOCAL_MODULE_PATH := $(TARGET_OUT_OPTIONAL_EXECUTABLES)
+LOCAL_MODULE_TAGS := debug
+LOCAL_MODULE := mcaptest
+
+include $(BUILD_EXECUTABLE)
+
+#
# btmon
#

diff --git a/android/Makefile.am b/android/Makefile.am
index 51c8253..a025a35 100644
--- a/android/Makefile.am
+++ b/android/Makefile.am
@@ -95,6 +95,16 @@ android_bluetooth_default_la_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/android
android_bluetooth_default_la_LDFLAGS = $(AM_LDFLAGS) -module -avoid-version \
-no-undefined

+noinst_PROGRAMS += android/mcaptest
+
+android_mcaptest_SOURCES = android/mcaptest.c \
+ src/log.c btio/btio.c \
+ android/mcap-lib.h android/mcap-lib.c
+
+android_mcaptest_CFLAGS = $(AM_CFLAGS)
+
+android_mcaptest_LDADD = lib/libbluetooth-internal.la @GLIB_LIBS@
+
noinst_PROGRAMS += android/haltest

android_haltest_SOURCES = android/client/haltest.c \
diff --git a/android/mcaptest.c b/android/mcaptest.c
new file mode 100644
index 0000000..cc2d9cd
--- /dev/null
+++ b/android/mcaptest.c
@@ -0,0 +1,184 @@
+/*
+ *
+ * BlueZ - Bluetooth protocol stack for Linux
+ *
+ * Copyright (C) 2014 Intel Corporation
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; 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 <stdio.h>
+#include <stdlib.h>
+#include <getopt.h>
+
+#include <bluetooth/bluetooth.h>
+#include <bluetooth/hci.h>
+#include <bluetooth/hci_lib.h>
+
+#include <glib.h>
+
+#include "btio/btio.h"
+#include "lib/l2cap.h"
+#include "android/mcap-lib.h"
+
+enum {
+ MODE_NONE,
+ MODE_CONNECT,
+ MODE_LISTEN,
+};
+
+static GMainLoop *mloop;
+
+static int ccpsm = 0x1003, dcpsm = 0x1005;
+
+static struct mcap_instance *mcap = NULL;
+
+int control_mode = MODE_LISTEN;
+
+static void mcl_connected(struct mcap_mcl *mcl, gpointer data)
+{
+ /* TODO */
+ printf("MCL connected unsupported\n");
+}
+
+static void mcl_reconnected(struct mcap_mcl *mcl, gpointer data)
+{
+ /* TODO */
+ printf("MCL reconnected unsupported\n");
+}
+
+static void mcl_disconnected(struct mcap_mcl *mcl, gpointer data)
+{
+ /* TODO */
+ printf("MCL disconnected\n");
+}
+
+static void mcl_uncached(struct mcap_mcl *mcl, gpointer data)
+{
+ /* TODO */
+ printf("MCL uncached unsupported\n");
+}
+
+static void usage(void)
+{
+ printf("mcaptest - MCAP testing ver %s\n", VERSION);
+ printf("Usage:\n"
+ "\tmcaptest <mode> [options]\n");
+ printf("Modes:\n"
+ "\t-c connect <dst_addr> (than wait for disconnect)\n");
+ printf("Options:\n"
+ "\t-i <hcidev> HCI device\n"
+ "\t-C <control_ch> Control channel PSM\n"
+ "\t-D <data_ch> Data channel PSM\n");
+}
+
+static struct option main_options[] = {
+ { "help", 0, 0, 'h' },
+ { "device", 1, 0, 'i' },
+ { "connect", 1, 0, 'c' },
+ { "control_ch", 1, 0, 'C' },
+ { "data_ch", 1, 0, 'D' },
+ { 0, 0, 0, 0 }
+};
+
+int main(int argc, char *argv[])
+{
+ GError *err = NULL;
+ bdaddr_t src, dst;
+ int opt;
+
+ hci_devba(0, &src);
+ bacpy(&dst, BDADDR_ANY);
+
+ mloop = g_main_loop_new(NULL, FALSE);
+ if (!mloop) {
+ printf("Cannot create main loop\n");
+
+ exit(1);
+ }
+
+ while ((opt = getopt_long(argc, argv, "+i:c:C:D:h",
+ main_options, NULL)) != EOF) {
+ switch (opt) {
+ case 'i':
+ if (!strncmp(optarg, "hci", 3))
+ hci_devba(atoi(optarg + 3), &src);
+ else
+ str2ba(optarg, &src);
+
+ break;
+
+ case 'c':
+ control_mode = MODE_CONNECT;
+ str2ba(optarg, &dst);
+
+ break;
+
+ case 'C':
+ ccpsm = atoi(optarg);
+
+ break;
+
+ case 'D':
+ dcpsm = atoi(optarg);
+
+ break;
+
+ case 'h':
+ default:
+ usage();
+ exit(0);
+ }
+ }
+
+ mcap = mcap_create_instance(&src, BT_IO_SEC_MEDIUM, 0, 0,
+ mcl_connected, mcl_reconnected,
+ mcl_disconnected, mcl_uncached,
+ NULL, /* CSP is not used right now */
+ NULL, &err);
+
+ if (!mcap) {
+ printf("MCAP instance creation failed %s\n",
+ err->message);
+ g_error_free(err);
+
+ exit(1);
+ }
+
+ switch (control_mode) {
+ case MODE_CONNECT:
+ case MODE_NONE:
+ default:
+ goto done;
+ }
+
+ g_main_loop_run(mloop);
+
+done:
+ printf("Done\n");
+
+ if (mcap)
+ mcap_instance_unref(mcap);
+
+ g_main_loop_unref(mloop);
+
+ return 0;
+}
--
2.0.0


2014-06-26 13:09:09

by Jakub Tyszkowski

[permalink] [raw]
Subject: [PATCH 5/7] android/mcaptest: Support MDL and MCL disconnection

This adds support for MDL disconnection triggered with timeout after the
MDL is connected. It also adds MCL disconnection timeout after the MDL
has been disconnected. If less than 0 is passed as '-e' or '-f' option
parameter, disconnection is not triggered. This is needed to pass some
PTS test cases.
---
android/mcaptest.c | 59 ++++++++++++++++++++++++++++++++++++++++++++----------
1 file changed, 48 insertions(+), 11 deletions(-)

diff --git a/android/mcaptest.c b/android/mcaptest.c
index 8d30e4d..f1f28d9 100644
--- a/android/mcaptest.c
+++ b/android/mcaptest.c
@@ -28,6 +28,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
+#include <unistd.h>

#include <bluetooth/bluetooth.h>
#include <bluetooth/hci.h>
@@ -56,18 +57,38 @@ static uint16_t mdlid;
static int control_mode = MODE_LISTEN;
static int data_mode = MODE_LISTEN;

+static gboolean mcl_disconnect = FALSE;
+static gboolean mdl_disconnect = FALSE;
+static int mcl_disconnect_timeout = -1;
+static int mdl_disconnect_timeout = -1;
+
static struct mcap_mcl *mcl = NULL;

static void mdl_connected_cb(struct mcap_mdl *mdl, void *data)
{
- /* TODO */
+ int fd = -1;
+
printf("%s\n", __func__);
+
+ if (mdl_disconnect && mdl_disconnect_timeout >= 0) {
+ sleep(mdl_disconnect_timeout);
+
+ fd = mcap_mdl_get_fd(mdl);
+
+ if (fd > 0)
+ close(fd);
+ }
}

static void mdl_closed_cb(struct mcap_mdl *mdl, void *data)
{
- /* TODO */
printf("%s\n", __func__);
+
+ if (mcl_disconnect && mcl_disconnect_timeout >= 0) {
+ sleep(mcl_disconnect_timeout);
+
+ mcap_close_mcl(mcl, TRUE);
+ }
}

static void mdl_deleted_cb(struct mcap_mdl *mdl, void *data)
@@ -205,9 +226,11 @@ static void usage(void)
printf("Usage:\n"
"\tmcaptest <control_mode> <data_mode> [options]\n");
printf("Control Link Mode:\n"
- "\t-c connect <dst_addr>\n");
+ "\t-c connect <dst_addr>\n"
+ "\t-e <timeout> disconnect MCL and quit after MDL is closed\n");
printf("Data Link Mode:\n"
- "\t-d connect\n");
+ "\t-d connect\n"
+ "\t-f <timeout> disconnect MDL after it's connected\n");
printf("Options:\n"
"\t-i <hcidev> HCI device\n"
"\t-C <control_ch> Control channel PSM\n"
@@ -215,12 +238,14 @@ static void usage(void)
}

static struct option main_options[] = {
- { "help", 0, 0, 'h' },
- { "device", 1, 0, 'i' },
- { "connect_cl", 1, 0, 'c' },
- { "connect_dl", 0, 0, 'd' },
- { "control_ch", 1, 0, 'C' },
- { "data_ch", 1, 0, 'D' },
+ { "help", 0, 0, 'h' },
+ { "device", 1, 0, 'i' },
+ { "connect_cl", 1, 0, 'c' },
+ { "disconnect_cl", 1, 0, 'e' },
+ { "connect_dl", 0, 0, 'd' },
+ { "disconnect_dl", 1, 0, 'f' },
+ { "control_ch", 1, 0, 'C' },
+ { "data_ch", 1, 0, 'D' },
{ 0, 0, 0, 0 }
};
int main(int argc, char *argv[])
@@ -240,7 +265,7 @@ int main(int argc, char *argv[])
exit(1);
}

- while ((opt = getopt_long(argc, argv, "+i:c:C:D:hd",
+ while ((opt = getopt_long(argc, argv, "+i:c:C:D:e:f:hd",
main_options, NULL)) != EOF) {
switch (opt) {
case 'i':
@@ -262,6 +287,18 @@ int main(int argc, char *argv[])

break;

+ case 'e':
+ mcl_disconnect = TRUE;
+ mcl_disconnect_timeout = atoi(optarg);
+
+ break;
+
+ case 'f':
+ mdl_disconnect = TRUE;
+ mdl_disconnect_timeout = atoi(optarg);
+
+ break;
+
case 'C':
ccpsm = atoi(optarg);

--
2.0.0


2014-06-26 13:09:10

by Jakub Tyszkowski

[permalink] [raw]
Subject: [PATCH 6/7] android/mcaptest: Support MDL reconnection if MCL reconnected

This is needed in some PTS test cases.
---
android/mcaptest.c | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/android/mcaptest.c b/android/mcaptest.c
index f1f28d9..6277b40 100644
--- a/android/mcaptest.c
+++ b/android/mcaptest.c
@@ -118,10 +118,22 @@ static uint8_t mdl_reconn_req_cb(struct mcap_mdl *mdl, void *data)
return MCAP_SUCCESS;
}

+static void create_mdl_cb(struct mcap_mdl *mcap_mdl, uint8_t type, GError *gerr,
+ gpointer data);
+
static void mcl_reconnected(struct mcap_mcl *mcl, gpointer data)
{
- /* TODO */
- printf("MCL reconnected unsupported\n");
+ GError *gerr = NULL;
+
+ printf("%s\n", __func__);
+
+ if (data_mode == MODE_CONNECT) {
+ mcap_create_mdl(mcl, 1, 0, create_mdl_cb, NULL, NULL, &gerr);
+ if (gerr) {
+ printf("Could not connect MDL: %s\n", gerr->message);
+ g_error_free(gerr);
+ }
+ }
}

static void mcl_disconnected(struct mcap_mcl *mcl, gpointer data)
--
2.0.0


2014-06-26 13:09:07

by Jakub Tyszkowski

[permalink] [raw]
Subject: [PATCH 3/7] android/mcaptest: Support connect

This initiates the connection
---
android/mcaptest.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 65 insertions(+), 2 deletions(-)

diff --git a/android/mcaptest.c b/android/mcaptest.c
index cc2d9cd..0ad51a6 100644
--- a/android/mcaptest.c
+++ b/android/mcaptest.c
@@ -50,8 +50,10 @@ static GMainLoop *mloop;
static int ccpsm = 0x1003, dcpsm = 0x1005;

static struct mcap_instance *mcap = NULL;
+static struct mcap_mdl *mdl = NULL;
+static uint16_t mdlid;

-int control_mode = MODE_LISTEN;
+static int control_mode = MODE_LISTEN;

static void mcl_connected(struct mcap_mcl *mcl, gpointer data)
{
@@ -77,6 +79,53 @@ static void mcl_uncached(struct mcap_mcl *mcl, gpointer data)
printf("MCL uncached unsupported\n");
}

+static void connect_mdl_cb(struct mcap_mdl *mdl, GError *gerr, gpointer data)
+{
+ mdlid = mcap_mdl_get_mdlid(mdl);
+
+ printf("MDL %d connected\n", mdlid);
+}
+
+static void create_mdl_cb(struct mcap_mdl *mcap_mdl, uint8_t type, GError *gerr,
+ gpointer data)
+{
+ GError *err = NULL;
+
+ if (gerr) {
+ printf("MDL error: %s\n", gerr->message);
+
+ return;
+ }
+
+ if (mdl)
+ mcap_mdl_unref(mdl);
+
+ mdl = mcap_mdl_ref(mcap_mdl);
+
+ if (!mcap_connect_mdl(mdl, L2CAP_MODE_ERTM, dcpsm, connect_mdl_cb, NULL,
+ NULL, &err)) {
+ printf("Error connecting to mdl: %s\n", err->message);
+ g_error_free(err);
+ }
+}
+
+static void create_mcl_cb(struct mcap_mcl *mcl, GError *err, gpointer data)
+{
+ GError *gerr = NULL;
+
+ if (err) {
+ printf("Could not connect MCL: %s\n", err->message);
+
+ return;
+ }
+
+ mcap_create_mdl(mcl, 1, 0, create_mdl_cb, NULL, NULL, &gerr);
+ if (gerr) {
+ printf("Could not connect MDL: %s\n", gerr->message);
+ g_error_free(gerr);
+ }
+}
+
static void usage(void)
{
printf("mcaptest - MCAP testing ver %s\n", VERSION);
@@ -98,12 +147,12 @@ static struct option main_options[] = {
{ "data_ch", 1, 0, 'D' },
{ 0, 0, 0, 0 }
};
-
int main(int argc, char *argv[])
{
GError *err = NULL;
bdaddr_t src, dst;
int opt;
+ char bdastr[18];

hci_devba(0, &src);
bacpy(&dst, BDADDR_ANY);
@@ -165,6 +214,20 @@ int main(int argc, char *argv[])

switch (control_mode) {
case MODE_CONNECT:
+ ba2str(&dst, bdastr);
+ printf("Connecting to %s\n", bdastr);
+
+ mcap_create_mcl(mcap, &dst, ccpsm, create_mcl_cb, NULL, NULL,
+ &err);
+
+ if (err) {
+ printf("MCAP create error %s\n", err->message);
+ g_error_free(err);
+
+ exit(1);
+ }
+
+ break;
case MODE_NONE:
default:
goto done;
--
2.0.0