Source-Changes-HG archive

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

[src/bouyer-socketcan]: src/usr.sbin/bta2dpd/bta2dpd 1888342



details:   https://anonhg.NetBSD.org/src/rev/d7cb5100a41b
branches:  bouyer-socketcan
changeset: 820837:d7cb5100a41b
user:      nat <nat%NetBSD.org@localhost>
date:      Sun Feb 12 08:25:32 2017 +0000

description:
1888342

diffstat:

 usr.sbin/bta2dpd/bta2dpd/bta2dpd.c    |  1137 +++++++++++++++++++++++++++++++++
 usr.sbin/bta2dpd/bta2dpd/sbc_encode.c |  1108 ++++++++++++++++++++++++++++++++
 2 files changed, 2245 insertions(+), 0 deletions(-)

diffs (truncated from 2253 to 300 lines):

diff -r 3dc5d5ed3ad4 -r d7cb5100a41b usr.sbin/bta2dpd/bta2dpd/bta2dpd.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.sbin/bta2dpd/bta2dpd/bta2dpd.c        Sun Feb 12 08:25:32 2017 +0000
@@ -0,0 +1,1137 @@
+/* $NetBSD: bta2dpd.c,v 1.2.4.2 2017/02/12 08:25:32 nat Exp $ */
+
+/*-
+ * Copyright (c) 2015 - 2016 Nathanial Sloss <nathanialsloss%yahoo.com.au@localhost>
+ * All rights reserved.
+ *
+ *             This software is dedicated to the memory of -
+ *        Baron James Anlezark (Barry) - 1 Jan 1949 - 13 May 2012.
+ *
+ *             Barry was a man who loved his music.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*-
+ * Copyright (c) 2006 Itronix Inc.
+ * All rights reserved.
+ *
+ * Written by Iain Hibbert for Itronix Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of Itronix Inc. may not be used to endorse
+ *    or promote products derived from this software without specific
+ *    prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY ITRONIX INC. ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL ITRONIX INC. BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* This was based upon bthset.c */
+
+#include <sys/cdefs.h>
+__COPYRIGHT("@(#) Copyright (c) 2006 Itronix, Inc.  All rights reserved.");
+__RCSID("$NetBSD");
+
+#include <sys/ioctl.h>
+#include <sys/types.h>
+#include <sys/time.h>
+
+#include <assert.h>
+#include <bluetooth.h>
+#include <err.h>
+#include <event.h>
+#include <fcntl.h>
+#include <sdp.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+
+#include "avdtp_signal.h"
+#include "sbc_encode.h"
+
+#define A2DP_SINK      0x110b
+
+/* A2DP Audio Source service record */
+static uint8_t source_data[] = {
+       0x09, 0x00, 0x00,       //  uint16      ServiceRecordHandle
+       0x0a, 0x00, 0x00, 0x00, //  uint32      0x00000000
+       0x00,
+
+       0x09, 0x00, 0x01,       //  uint16      ServiceClassIDList
+       0x35, 0x03,             //  seq8(3)
+       0x19, 0x11, 0x0a,       //   uuid16     AudioSource
+
+       0x09, 0x00, 0x04,       //  uint16      ProtocolDescriptorList
+       0x35, 0x10,             //  seq8(16)
+       0x35, 0x06,             //   seq8(6)
+       0x19, 0x01, 0x00,       //    uuid16    L2CAP
+       0x09, 0x00, 0x19,       //    uint16    %src_psm%
+       0x35, 0x06,             //   seq8(6)
+       0x19, 0x00, 0x19,       //    uuid16    AVDTP
+       0x09, 0x01, 0x00,       //    uint16    Ver 1.0
+
+       0x09, 0x00, 0x05,       //  uint16      BrowseGroupList
+       0x35, 0x03,             //  seq8(3)
+       0x19, 0x10, 0x02,       //   uuid16     PublicBrowseGroup
+
+       0x09, 0x00, 0x06,       //  uint16      LanguageBaseAttributeIDList
+       0x35, 0x09,             //  seq8(9)
+       0x09, 0x65, 0x6e,       //   uint16     0x656e  ("en")
+       0x09, 0x00, 0x6a,       //   uint16     106     (UTF-8)
+       0x09, 0x01, 0x00,       //   uint16     PrimaryLanguageBaseID
+
+       0x09, 0x00, 0x09,       //  uint16      BluetoothProfileDescriptorList
+       0x35, 0x08,             //  seq8(8)
+       0x35, 0x06,             //   seq8(6)
+       0x19, 0x11, 0x0d,       //    uuid16    A2DP
+       0x09, 0x01, 0x02,       //    uint16    v1.2
+
+       0x09, 0x01, 0x00,       //  uint16      PrimaryLanguageBaseID +
+                               //                  ServiceNameOffset
+       0x25, 0x09,             //  str8(9)     "Audio SRC"
+       'A', 'u', 'd', 'i', 'o', ' ', 'S', 'R', 'C',
+
+       0x09, 0x01, 0x02,       //  uint16      PrimaryLanguageBaseID +
+                               //                  ProviderName
+       0x25, 0x06,             //  str8(6)     "NetBSD"
+       'N', 'e', 't', 'B', 'S', 'D',
+
+       0x09, 0x03, 0x11,       //  uint16      SupportedFeatures
+       0x09, 0x01, 0x02        //  uint16      Headphone, Speaker
+};
+
+static sdp_data_t source_record =  { source_data + 0, source_data + 103 };
+static sdp_data_t source_psm = { source_data + 26, source_data + 29 };
+
+
+/* A2DP Audio Sink service record */
+static uint8_t sink_data[] = {
+       0x09, 0x00, 0x00,       //  uint16      ServiceRecordHandle
+       0x0a, 0x00, 0x00, 0x00, //  uint32      0x00000000
+       0x00,
+
+       0x09, 0x00, 0x01,       //  uint16      ServiceClassIDList
+       0x35, 0x03,             //  seq8(3)
+       0x19, 0x11, 0x0b,       //   uuid16     AudioSink
+
+       0x09, 0x00, 0x04,       //  uint16      ProtocolDescriptorList
+       0x35, 0x10,             //  seq8(16)
+       0x35, 0x06,             //   seq8(6)
+       0x19, 0x01, 0x00,       //    uuid16    L2CAP
+       0x09, 0x00, 0x19,       //    uint16    %sink_psm%
+       0x35, 0x06,             //   seq8(6)
+       0x19, 0x00, 0x19,       //    uuid16    AVDTP
+       0x09, 0x01, 0x00,       //    uint16    Ver 1.0
+
+       0x09, 0x00, 0x05,       //  uint16      BrowseGroupList
+       0x35, 0x03,             //  seq8(3)
+       0x19, 0x10, 0x02,       //   uuid16     PublicBrowseGroup
+
+       0x09, 0x00, 0x06,       //  uint16      LanguageBaseAttributeIDList
+       0x35, 0x09,             //  seq8(9)
+       0x09, 0x65, 0x6e,       //   uint16     0x656e  ("en")
+       0x09, 0x00, 0x6a,       //   uint16     106     (UTF-8)
+       0x09, 0x01, 0x00,       //   uint16     PrimaryLanguageBaseID
+
+       0x09, 0x00, 0x09,       //  uint16      BluetoothProfileDescriptorList
+       0x35, 0x08,             //  seq8(8)
+       0x35, 0x06,             //   seq8(6)
+       0x19, 0x11, 0x0d,       //    uuid16    A2DP
+       0x09, 0x01, 0x02,       //    uint16    v1.2
+
+       0x09, 0x01, 0x00,       //  uint16      PrimaryLanguageBaseID +
+                               //                  ServiceNameOffset
+       0x25, 0x09,             //  str8(9)     "Audio SNK"
+       'A', 'u', 'd', 'i', 'o', ' ', 'S', 'N', 'K',
+
+       0x09, 0x01, 0x02,       //  uint16      PrimaryLanguageBaseID +
+                               //                  ProviderName
+       0x25, 0x06,             //  str8(6)     "NetBSD"
+       'N', 'e', 't', 'B', 'S', 'D',
+
+       0x09, 0x03, 0x11,       //  uint16      SupportedFeatures
+       0x09, 0x00, 0x03        //  uint16      Headphone, Speaker
+};
+
+static sdp_data_t sink_record =        { sink_data + 0, sink_data + 103 };
+static sdp_data_t sink_psm = { sink_data + 26, sink_data + 29 };
+
+struct l2cap_info {
+       bdaddr_t laddr;
+       bdaddr_t raddr;
+};
+
+__dead static void usage(void);
+
+static int init_server(struct l2cap_info *);
+static int init_client(struct l2cap_info *);
+static void client_query(void);
+static void exit_func(void);
+
+static int sc;         /* avdtp streaming channel */
+static int orighc;     /* avdtp listening socket */
+static int hc;         /* avdtp control/command channel */
+struct event_base *base;
+static struct event interrupt_ev;              /* audio event */
+static struct event recv_ev;                   /* audio sink event */
+static struct event ctl_ev;                    /* avdtp ctl event */
+
+struct l2cap_info      info;
+static bool            asSpeaker;
+static bool            initDiscover;   /* initiate avdtp discover */
+static bool            verbose;        /* copy to stdout */
+static bool            test_mode;      /* copy to stdout */
+static uint8_t         channel_mode = MODE_STEREO;
+static uint8_t         alloc_method = ALLOC_LOUDNESS;
+static uint8_t         frequency = FREQ_44_1K;
+static uint8_t         freqs[4];
+static uint8_t         blocks_config[4];
+static uint8_t         channel_config[4];
+static uint8_t         bands_config[2];
+static uint8_t         alloc_config[2];
+static uint8_t         bitpool = 0;
+static uint8_t         bands = BANDS_8;
+static uint8_t         blocks = BLOCKS_16;
+static int             volume = 0;
+static int             state = 0;
+static uint16_t                l2cap_psm = 0;
+static int             l2cap_mode;
+uint16_t mtu;          
+uint16_t userset_mtu = 1000, service_class = A2DP_SINK;
+static const char* service_type = "A2DP";
+struct avdtp_sepInfo mySepInfo;
+static sdp_session_t ss;       /* SDP server session */
+
+char *files2open[255];
+static int numfiles = 0;
+static int startFileInd = 0;
+int audfile;
+
+static void do_interrupt(int, short, void *);
+static void do_recv(int, short, void *);
+static void do_ctlreq(int, short, void *);
+
+#define log_err(x, ...)                if (verbose) { fprintf (stderr, x "\n",\
+                                               __VA_ARGS__); }
+#define log_info(x, ...)       if (verbose) { fprintf (stderr, x "\n",\
+                                               __VA_ARGS__); }
+
+int
+main(int ac, char *av[])
+{
+       int enc, i, n, m, l, j, k, o, ch, freqnum, blocksnum;
+       u_int tmpbitpool;
+       bdaddr_copy(&info.laddr, BDADDR_ANY);
+
+       sc = hc = -1;
+       verbose = asSpeaker = test_mode = initDiscover = false;
+       n = m = l = i = j = o = 0;
+       freqs[0] = frequency;
+       channel_config[0] = channel_mode;
+       blocks_config[0] = blocks;
+       bands_config[0] = bands;
+       alloc_config[0] = alloc_method;
+       channel_config[0] = channel_mode;
+
+       while ((ch = getopt(ac, av, "A:a:B:b:d:e:f:IKM:m:p:r:tV:v")) != EOF) {
+               switch (ch) {
+               case 'A':
+                       for (k = 0; k < (int)strlen(optarg); k++) {
+                               if (o > 1)
+                                       break;
+                               switch (optarg[k]) {
+                               case '0':
+                                       alloc_config[o++] = ALLOC_ANY;
+                                       break;
+                               case 'S':
+                                       alloc_config[o++] = ALLOC_SNR;
+                                       break;
+                               case 'L':
+                                       alloc_config[o++] = ALLOC_LOUDNESS;
+                                       break;
+                               default:
+                                       usage();
+                               }
+                       }
+                       break;
+               case 'a':



Home | Main Index | Thread Index | Old Index