From: Szymon Janc <szymon.janc@tieto.com>
To: linux-bluetooth@vger.kernel.org
Subject: Re: [PATCH 1/6] android: Add initial code for AVDTP testing tool
Date: Mon, 01 Sep 2014 16:15:26 +0200 [thread overview]
Message-ID: <1453621.czAvkRCTZy@uw000953> (raw)
In-Reply-To: <1409318278-798-1-git-send-email-szymon.janc@tieto.com>
On Friday 29 of August 2014 15:17:53 Szymon Janc wrote:
> This tools is intended for AVDTP qualification with PTS.
> ---
> .gitignore | 1 +
> android/Android.mk | 33 ++++
> android/Makefile.am | 11 ++
> android/avdtptest.c | 440 ++++++++++++++++++++++++++++++++++++++++++++++++++++
> 4 files changed, 485 insertions(+)
> create mode 100644 android/avdtptest.c
>
> diff --git a/.gitignore b/.gitignore
> index 1ee35e2..b6ccbe3 100644
> --- a/.gitignore
> +++ b/.gitignore
> @@ -125,6 +125,7 @@ doc/btmon.1
>
> android/system-emulator
> android/bluetoothd
> +android/avdtptest
> android/mcaptest
> android/haltest
> android/android-tester
> diff --git a/android/Android.mk b/android/Android.mk
> index 35b8506..b2b55f7 100644
> --- a/android/Android.mk
> +++ b/android/Android.mk
> @@ -223,6 +223,39 @@ LOCAL_MODULE := mcaptest
> include $(BUILD_EXECUTABLE)
>
> #
> +# avdtptest
> +#
> +
> +include $(CLEAR_VARS)
> +
> +LOCAL_SRC_FILES := \
> + bluez/android/avdtptest.c \
> + bluez/android/avdtp.c \
> + bluez/src/log.c \
> + bluez/btio/btio.c \
> + bluez/lib/bluetooth.c \
> + bluez/lib/hci.c \
> +
> +LOCAL_C_INCLUDES += \
> + $(LOCAL_PATH)/bluez \
> + $(call include-path-for, glib) \
> + $(call include-path-for, glib)/glib \
> +
> +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 := avdtptest
> +
> +include $(BUILD_EXECUTABLE)
> +
> +#
> # btmon
> #
>
> diff --git a/android/Makefile.am b/android/Makefile.am
> index 4b93c5b..e93a08b 100644
> --- a/android/Makefile.am
> +++ b/android/Makefile.am
> @@ -109,6 +109,17 @@ android_mcaptest_CFLAGS = $(AM_CFLAGS)
>
> android_mcaptest_LDADD = lib/libbluetooth-internal.la @GLIB_LIBS@
>
> +noinst_PROGRAMS += android/avdtptest
> +
> +android_avdtptest_SOURCES = android/avdtptest.c \
> + src/log.h src/log.c \
> + btio/btio.h btio/btio.c \
> + android/avdtp.h android/avdtp.c
> +
> +android_avdtptest_CFLAGS = $(AM_CFLAGS)
> +
> +android_avdtptest_LDADD = lib/libbluetooth-internal.la @GLIB_LIBS@
> +
> noinst_PROGRAMS += android/haltest
>
> android_haltest_SOURCES = android/client/haltest.c \
> diff --git a/android/avdtptest.c b/android/avdtptest.c
> new file mode 100644
> index 0000000..a986a9b
> --- /dev/null
> +++ b/android/avdtptest.c
> @@ -0,0 +1,440 @@
> +/*
> + *
> + * 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 <unistd.h>
> +#include <stdbool.h>
> +
> +#include <bluetooth/bluetooth.h>
> +#include <bluetooth/hci.h>
> +#include <bluetooth/hci_lib.h>
> +
> +#include <glib.h>
> +
> +#include "btio/btio.h"
> +#include "avdtp.h"
> +
> +static GMainLoop *mainloop = NULL;
> +static int dev_role = AVDTP_SEP_TYPE_SOURCE;
> +static bool initiator = false;
> +static struct avdtp *avdtp = NULL;
> +struct avdtp_stream *avdtp_stream = NULL;
> +struct avdtp_local_sep *local_sep = NULL;
> +static GIOChannel *io = NULL;
> +
> +static void set_configuration_cfm(struct avdtp *session,
> + struct avdtp_local_sep *lsep,
> + struct avdtp_stream *stream,
> + struct avdtp_error *err,
> + void *user_data)
> +{
> + printf("%s\n", __func__);
> +}
> +
> +static void get_configuration_cfm(struct avdtp *session,
> + struct avdtp_local_sep *lsep,
> + struct avdtp_stream *stream,
> + struct avdtp_error *err,
> + void *user_data)
> + {
> + printf("%s\n", __func__);
> +}
> +
> +static void open_cfm(struct avdtp *session, struct avdtp_local_sep *lsep,
> + struct avdtp_stream *stream, struct avdtp_error *err,
> + void *user_data)
> +{
> + printf("%s\n", __func__);
> +}
> +
> +static void start_cfm(struct avdtp *session, struct avdtp_local_sep *lsep,
> + struct avdtp_stream *stream, struct avdtp_error *err,
> + void *user_data)
> +{
> + printf("%s\n", __func__);
> +}
> +
> +static void suspend_cfm(struct avdtp *session, struct avdtp_local_sep *lsep,
> + struct avdtp_stream *stream,
> + struct avdtp_error *err, void *user_data)
> +{
> + printf("%s\n", __func__);
> +}
> +
> +static void close_cfm(struct avdtp *session, struct avdtp_local_sep *lsep,
> + struct avdtp_stream *stream,
> + struct avdtp_error *err, void *user_data)
> +{
> + printf("%s\n", __func__);
> +
> + avdtp_stream = NULL;
> +}
> +
> +static void abort_cfm(struct avdtp *session, struct avdtp_local_sep *lsep,
> + struct avdtp_stream *stream,
> + struct avdtp_error *err, void *user_data)
> +{
> + printf("%s\n", __func__);
> +
> + avdtp_stream = NULL;
> +}
> +
> +static void reconfigure_cfm(struct avdtp *session,
> + struct avdtp_local_sep *lsep,
> + struct avdtp_stream *stream,
> + struct avdtp_error *err, void *user_data)
> +{
> + printf("%s\n", __func__);
> +}
> +
> +static void delay_report_cfm(struct avdtp *session,
> + struct avdtp_local_sep *lsep,
> + struct avdtp_stream *stream,
> + struct avdtp_error *err, void *user_data)
> +{
> + printf("%s\n", __func__);
> +}
> +
> +static struct avdtp_sep_cfm sep_cfm = {
> + .set_configuration = set_configuration_cfm,
> + .get_configuration = get_configuration_cfm,
> + .open = open_cfm,
> + .start = start_cfm,
> + .suspend = suspend_cfm,
> + .close = close_cfm,
> + .abort = abort_cfm,
> + .reconfigure = reconfigure_cfm,
> + .delay_report = delay_report_cfm,
> +};
> +
> +static const char sbc_codec[] = {0x00, 0x00, 0xff, 0xff, 0x02, 0x40};
> +
> +static gboolean get_capability_ind(struct avdtp *session,
> + struct avdtp_local_sep *sep,
> + GSList **caps, uint8_t *err,
> + void *user_data)
> +{
> + struct avdtp_service_capability *service;
> +
> + printf("%s\n", __func__);
> +
> + *caps = NULL;
> +
> + service = avdtp_service_cap_new(AVDTP_MEDIA_TRANSPORT, NULL, 0);
> + *caps = g_slist_append(*caps, service);
> +
> + service = avdtp_service_cap_new(AVDTP_MEDIA_CODEC, sbc_codec,
> + sizeof(sbc_codec));
> + *caps = g_slist_append(*caps, service);
> +
> + return TRUE;
> +}
> +
> +static gboolean set_configuration_ind(struct avdtp *session,
> + struct avdtp_local_sep *lsep,
> + struct avdtp_stream *stream,
> + GSList *caps,
> + avdtp_set_configuration_cb cb,
> + void *user_data)
> +{
> + printf("%s\n", __func__);
> +
> + avdtp_stream = stream;
> +
> + cb(session, stream, NULL);
> +
> + return TRUE;
> +}
> +
> +static gboolean get_configuration_ind(struct avdtp *session,
> + struct avdtp_local_sep *lsep,
> + uint8_t *err, void *user_data)
> +{
> + printf("%s\n", __func__);
> +
> + return FALSE;
> +}
> +
> +static gboolean open_ind(struct avdtp *session, struct avdtp_local_sep *lsep,
> + struct avdtp_stream *stream, uint8_t *err,
> + void *user_data)
> +{
> + printf("%s\n", __func__);
> +
> + return TRUE;
> +}
> +
> +static gboolean start_ind(struct avdtp *session, struct avdtp_local_sep *lsep,
> + struct avdtp_stream *stream, uint8_t *err,
> + void *user_data)
> +{
> + printf("%s\n", __func__);
> +
> + return TRUE;
> +}
> +
> +static gboolean suspend_ind(struct avdtp *session,
> + struct avdtp_local_sep *sep,
> + struct avdtp_stream *stream, uint8_t *err,
> + void *user_data)
> +{
> + printf("%s\n", __func__);
> +
> + return FALSE;
> +}
> +
> +static gboolean close_ind(struct avdtp *session, struct avdtp_local_sep *sep,
> + struct avdtp_stream *stream, uint8_t *err,
> + void *user_data)
> +{
> + printf("%s\n", __func__);
> +
> + return FALSE;
> +}
> +
> +static void abort_ind(struct avdtp *session, struct avdtp_local_sep *sep,
> + struct avdtp_stream *stream, uint8_t *err,
> + void *user_data)
> +{
> + printf("%s\n", __func__);
> +}
> +
> +static gboolean reconfigure_ind(struct avdtp *session,
> + struct avdtp_local_sep *lsep,
> + uint8_t *err, void *user_data)
> +{
> + printf("%s\n", __func__);
> +
> + return FALSE;
> +}
> +
> +static gboolean delayreport_ind(struct avdtp *session,
> + struct avdtp_local_sep *lsep,
> + uint8_t rseid, uint16_t delay,
> + uint8_t *err, void *user_data)
> +{
> + printf("%s\n", __func__);
> +
> + return FALSE;
> +}
> +
> +static struct avdtp_sep_ind sep_ind = {
> + .get_capability = get_capability_ind,
> + .set_configuration = set_configuration_ind,
> + .get_configuration = get_configuration_ind,
> + .open = open_ind,
> + .close = close_ind,
> + .start = start_ind,
> + .suspend = suspend_ind,
> + .abort = abort_ind,
> + .reconfigure = reconfigure_ind,
> + .delayreport = delayreport_ind,
> +};
> +
> +static void disconnect_cb(void *user_data)
> +{
> + printf("Disconnected\n");
> +
> + g_main_loop_quit(mainloop);
> +}
> +
> +static void connect_cb(GIOChannel *chan, GError *err, gpointer user_data)
> +{
> + uint16_t imtu, omtu;
> + GError *gerr = NULL;
> + int fd;
> +
> + if (err) {
> + printf("%s\n", err->message);
> + g_main_loop_quit(mainloop);
> + return;
> + }
> +
> + bt_io_get(chan, &gerr,
> + BT_IO_OPT_IMTU, &imtu,
> + BT_IO_OPT_OMTU, &omtu,
> + BT_IO_OPT_INVALID);
> + if (gerr) {
> + printf("%s\n", gerr->message);
> + g_main_loop_quit(mainloop);
> + return;
> + }
> +
> + fd = g_io_channel_unix_get_fd(chan);
> +
> + if (avdtp && avdtp_stream) {
> + if (!avdtp_stream_set_transport(avdtp_stream, fd, imtu, omtu)) {
> + printf("avdtp_stream_set_transport: failed\n");
> + g_main_loop_quit(mainloop);
> + }
> +
> + g_io_channel_set_close_on_unref(chan, FALSE);
> + return;
> + }
> +
> + /* TODO allow to set version from command line? */
> + avdtp = avdtp_new(fd, imtu, omtu, 0x0103);
> + if (!avdtp) {
> + printf("Failed to create avdtp instance\n");
> + g_main_loop_quit(mainloop);
> + return;
> + }
> +
> + avdtp_add_disconnect_cb(avdtp, disconnect_cb, NULL);
> +
> + /* TODO handle initiator */
> +}
> +
> +static void usage(void)
> +{
> + printf("avdtptest - AVDTP testing ver %s\n", VERSION);
> + printf("Usage:\n"
> + "\tavdtptest [options]\n");
> + printf("options:\n"
> + "\t-d <device_role> SRC (source) or SINK (sink)\n"
> + "\t-s <stream_role> INT (initiator) or ACP (acceptor)\n"
> + "\t-i <hcidev> HCI adapter\n"
> + "\t-c <bdaddr> connect\n"
> + "\t-l listen\n");
> +}
> +
> +static struct option main_options[] = {
> + { "help", 0, 0, 'h' },
> + { "device_role", 1, 0, 'd' },
> + { "stream_role", 1, 0, 's' },
> + { "adapter", 1, 0, 'i' },
> + { "connect", 1, 0, 'c' },
> + { "listen", 0, 0, 'l' },
> + { 0, 0, 0, 0 }
> +};
> +
> +int main(int argc, char *argv[])
> +{
> + GError *err = NULL;
> + bdaddr_t src, dst;
> + int opt;
> +
> + bacpy(&src, BDADDR_ANY);
> + bacpy(&dst, BDADDR_ANY);
> +
> + mainloop = g_main_loop_new(NULL, FALSE);
> + if (!mainloop) {
> + printf("Failed to create main loop\n");
> +
> + exit(1);
> + }
> +
> + while ((opt = getopt_long(argc, argv, "d:hi:s:c:l",
> + 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 'd':
> + if (!strncasecmp(optarg, "SRC", sizeof("SRC"))) {
> + dev_role = AVDTP_SEP_TYPE_SOURCE;
> + } else if (!strncasecmp(optarg, "SINK",
> + sizeof("SINK"))) {
> + dev_role = AVDTP_SEP_TYPE_SINK;
> + } else {
> + usage();
> + exit(0);
> + }
> + break;
> + case 's':
> + if (!strncasecmp(optarg, "INT", sizeof("INT"))) {
> + initiator = true;
> + } else if (!strncasecmp(optarg, "ACP", sizeof("ACP"))) {
> + initiator = false;
> + } else {
> + usage();
> + exit(0);
> + }
> + break;
> + case 'c':
> + if (str2ba(optarg, &dst) < 0) {
> + usage();
> + exit(0);
> + }
> + break;
> + case 'l':
> + bacpy(&dst, BDADDR_ANY);
> + break;
> + case 'h':
> + default:
> + usage();
> + exit(0);
> + }
> + }
> +
> + local_sep = avdtp_register_sep(dev_role, AVDTP_MEDIA_TYPE_AUDIO,
> + 0x00, FALSE, &sep_ind, &sep_cfm, NULL);
> + if (!local_sep) {
> + printf("Failed to register sep\n");
> + exit(0);
> + }
> +
> + if (!bacmp(&dst, BDADDR_ANY)) {
> + printf("Listening...\n");
> + io = bt_io_listen(connect_cb, NULL, NULL, NULL, &err,
> + BT_IO_OPT_SOURCE_BDADDR, &src,
> + BT_IO_OPT_PSM, AVDTP_PSM,
> + BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_LOW,
> + BT_IO_OPT_INVALID);
> + } else {
> + printf("Connecting...\n");
> + io = bt_io_connect(connect_cb, NULL, NULL, &err,
> + BT_IO_OPT_SOURCE_BDADDR, &src,
> + BT_IO_OPT_DEST_BDADDR, &dst,
> + BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_LOW,
> + BT_IO_OPT_PSM, AVDTP_PSM,
> + BT_IO_OPT_INVALID);
> + }
> +
> + if (!io) {
> + printf("Failed: %s\n", err->message);
> + g_error_free(err);
> + exit(0);
> + }
> +
> + g_main_loop_run(mainloop);
> +
> + printf("Done\n");
> +
> + avdtp_unref(avdtp);
> + avdtp = NULL;
> +
> + g_main_loop_unref(mainloop);
> + mainloop = NULL;
> +
> + return 0;
> +}
>
Pushed.
--
Best regards,
Szymon Janc
prev parent reply other threads:[~2014-09-01 14:15 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-29 13:17 [PATCH 1/6] android: Add initial code for AVDTP testing tool Szymon Janc
2014-08-29 13:17 ` [PATCH 2/6] android/avdtptest: Add support for streaming Szymon Janc
2014-08-29 13:17 ` [PATCH 3/6] android/avdtptest: Add option to reject commands Szymon Janc
2014-08-29 13:17 ` [PATCH 4/6] android/avdtptest: Add support for initiator role and discovery Szymon Janc
2014-08-29 13:17 ` [PATCH 5/6] android/avdtptest: Add support for fragmentation Szymon Janc
2014-08-29 13:17 ` [PATCH 6/6] android/avdtptest: Add support for receiving media as SINK Szymon Janc
2014-09-01 14:15 ` Szymon Janc [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1453621.czAvkRCTZy@uw000953 \
--to=szymon.janc@tieto.com \
--cc=linux-bluetooth@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox