Source-Changes-HG archive

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

[src/trunk]: src bta2dpd - Bluetooth Advand Audio Distribution (A2DP) Profile...



details:   https://anonhg.NetBSD.org/src/rev/69566c5efeaa
branches:  trunk
changeset: 821203:69566c5efeaa
user:      nat <nat%NetBSD.org@localhost>
date:      Sat Jan 28 16:55:54 2017 +0000

description:
bta2dpd - Bluetooth Advand Audio Distribution (A2DP) Profile Daemon.

bta2dpd allows you to stream audio to and from bluetooth devices.
It features high quality stereo audio and is intended for use with pad(4)
device.

As discussed on current-users@ and tech-userlevel@

diffstat:

 distrib/sets/lists/base/mi              |     3 +-
 distrib/sets/lists/debug/mi             |     3 +-
 distrib/sets/lists/man/mi               |     5 +-
 usr.sbin/Makefile                       |     4 +-
 usr.sbin/bta2dpd/Makefile               |     5 +
 usr.sbin/bta2dpd/bta2dpd/Makefile       |    24 +
 usr.sbin/bta2dpd/bta2dpd/avdtp.c        |   380 ++++++++++
 usr.sbin/bta2dpd/bta2dpd/avdtp_signal.h |   139 +++
 usr.sbin/bta2dpd/bta2dpd/bta2dpd.8      |   278 +++++++
 usr.sbin/bta2dpd/bta2dpd/bta2dpd.c      |  1129 +++++++++++++++++++++++++++++++
 usr.sbin/bta2dpd/bta2dpd/sbc_encode.c   |  1083 +++++++++++++++++++++++++++++
 usr.sbin/bta2dpd/bta2dpd/sbc_encode.h   |    75 ++
 usr.sbin/bta2dpd/cosdata-gen/Makefile   |    11 +
 usr.sbin/bta2dpd/cosdata-gen/cosdata.c  |   202 +++++
 usr.sbin/bta2dpd/sbc_crc-gen/Makefile   |     8 +
 usr.sbin/bta2dpd/sbc_crc-gen/sbc_crc.c  |    71 +
 16 files changed, 3415 insertions(+), 5 deletions(-)

diffs (truncated from 3536 to 300 lines):

diff -r 45dc1095f2e7 -r 69566c5efeaa distrib/sets/lists/base/mi
--- a/distrib/sets/lists/base/mi        Sat Jan 28 16:43:59 2017 +0000
+++ b/distrib/sets/lists/base/mi        Sat Jan 28 16:55:54 2017 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1150 2017/01/13 11:21:47 nonaka Exp $
+# $NetBSD: mi,v 1.1151 2017/01/28 16:55:54 nat Exp $
 #
 # Note:        Don't delete entries from here - mark them as "obsolete" instead,
 #      unless otherwise stated below.
@@ -1591,6 +1591,7 @@
 ./usr/sbin/bootpgw                             base-bootserver-bin
 ./usr/sbin/bootptest                           base-bootserver-bin
 ./usr/sbin/bpm                                 base-obsolete           obsolete
+./usr/sbin/bta2dpd                             base-sysutil-bin
 ./usr/sbin/btattach                            base-sysutil-bin
 ./usr/sbin/btconfig                            base-sysutil-bin
 ./usr/sbin/btcontrol                           base-obsolete           obsolete
diff -r 45dc1095f2e7 -r 69566c5efeaa distrib/sets/lists/debug/mi
--- a/distrib/sets/lists/debug/mi       Sat Jan 28 16:43:59 2017 +0000
+++ b/distrib/sets/lists/debug/mi       Sat Jan 28 16:55:54 2017 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.193 2017/01/27 10:45:11 hannken Exp $
+# $NetBSD: mi,v 1.194 2017/01/28 16:55:54 nat Exp $
 ./etc/mtree/set.debug                           comp-sys-root
 ./usr/lib                                      comp-sys-usr            compatdir
 ./usr/lib/i18n/libBIG5_g.a                     comp-c-debuglib         debuglib,compatfile
@@ -1009,6 +1009,7 @@
 ./usr/libdata/debug/usr/sbin/bootpef.debug     comp-bootserver-debug   debug
 ./usr/libdata/debug/usr/sbin/bootpgw.debug     comp-bootserver-debug   debug
 ./usr/libdata/debug/usr/sbin/bootptest.debug   comp-bootserver-debug   debug
+./usr/libdata/debug/usr/sbin/bta2dpd.debug     comp-sysutil-debug      debug
 ./usr/libdata/debug/usr/sbin/btattach.debug    comp-sysutil-debug      debug
 ./usr/libdata/debug/usr/sbin/btconfig.debug    comp-sysutil-debug      debug
 ./usr/libdata/debug/usr/sbin/btcontrol.debug   comp-obsolete           obsolete
diff -r 45dc1095f2e7 -r 69566c5efeaa distrib/sets/lists/man/mi
--- a/distrib/sets/lists/man/mi Sat Jan 28 16:43:59 2017 +0000
+++ b/distrib/sets/lists/man/mi Sat Jan 28 16:55:54 2017 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1546 2017/01/21 20:21:57 jdolecek Exp $
+# $NetBSD: mi,v 1.1547 2017/01/28 16:55:54 nat Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -2366,6 +2366,7 @@
 ./usr/share/man/cat8/bounce.0                  man-postfix-catman      postfix,.cat
 ./usr/share/man/cat8/bozohttpd.0               man-netutil-catman      .cat
 ./usr/share/man/cat8/brconfig.0                        man-netutil-catman      .cat
+./usr/share/man/cat8/bta2dpd.0                 man-sysutil-catman      .cat
 ./usr/share/man/cat8/btattach.0                        man-sysutil-catman      .cat
 ./usr/share/man/cat8/btconfig.0                        man-sysutil-catman      .cat
 ./usr/share/man/cat8/btcontrol.0               man-obsolete            obsolete
@@ -5339,6 +5340,7 @@
 ./usr/share/man/html8/bounce.html              man-postfix-htmlman     postfix,html
 ./usr/share/man/html8/bozohttpd.html           man-netutil-htmlman     html
 ./usr/share/man/html8/brconfig.html            man-netutil-htmlman     html
+./usr/share/man/html8/bta2dpd.html             man-sysutil-htmlman     html
 ./usr/share/man/html8/btattach.html            man-sysutil-htmlman     html
 ./usr/share/man/html8/btconfig.html            man-sysutil-htmlman     html
 ./usr/share/man/html8/btdevctl.html            man-sysutil-htmlman     html
@@ -8347,6 +8349,7 @@
 ./usr/share/man/man8/bounce.8                  man-postfix-man         postfix,.man
 ./usr/share/man/man8/bozohttpd.8               man-netutil-man         .man
 ./usr/share/man/man8/brconfig.8                        man-netutil-man         .man
+./usr/share/man/man8/bta2dpd.8                 man-sysutil-man         .man
 ./usr/share/man/man8/btattach.8                        man-sysutil-man         .man
 ./usr/share/man/man8/btconfig.8                        man-sysutil-man         .man
 ./usr/share/man/man8/btcontrol.8               man-obsolete            obsolete
diff -r 45dc1095f2e7 -r 69566c5efeaa usr.sbin/Makefile
--- a/usr.sbin/Makefile Sat Jan 28 16:43:59 2017 +0000
+++ b/usr.sbin/Makefile Sat Jan 28 16:55:54 2017 +0000
@@ -1,10 +1,10 @@
-#      $NetBSD: Makefile,v 1.273 2015/12/13 02:26:08 christos Exp $
+#      $NetBSD: Makefile,v 1.274 2017/01/28 16:55:54 nat Exp $
 #      from: @(#)Makefile      5.20 (Berkeley) 6/12/93
 
 .include <bsd.own.mk>
 
 SUBDIR=        ac accton acpitools altq apm apmd arp \
-       bad144 bootp btattach btconfig btdevctl bthcid btpand catman \
+       bad144 bootp bta2dpd btattach btconfig btdevctl bthcid btpand catman \
        chroot cnwctl cpuctl crash \
        dev_mkdb diskpart dumpfs dumplfs \
        edquota eeprom envstat eshconfig etcupdate extattrctl \
diff -r 45dc1095f2e7 -r 69566c5efeaa usr.sbin/bta2dpd/Makefile
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.sbin/bta2dpd/Makefile Sat Jan 28 16:55:54 2017 +0000
@@ -0,0 +1,5 @@
+# $NetBSD: Makefile,v 1.1 2017/01/28 16:55:54 nat Exp $
+
+SUBDIR=                cosdata-gen sbc_crc-gen .WAIT bta2dpd
+
+.include <bsd.subdir.mk>
diff -r 45dc1095f2e7 -r 69566c5efeaa usr.sbin/bta2dpd/bta2dpd/Makefile
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.sbin/bta2dpd/bta2dpd/Makefile Sat Jan 28 16:55:54 2017 +0000
@@ -0,0 +1,24 @@
+# $NetBSD: Makefile,v 1.1 2017/01/28 16:55:54 nat Exp $
+
+WARNS?=                6
+
+PROG=          bta2dpd
+SRCS=          bta2dpd.c avdtp.c sbc_encode.c
+MAN=           bta2dpd.8
+
+CFLAGS+=       -I.
+DPADD+=                ${LIBBLUETOOTH} ${LIBEVENT}
+LDADD+=                -lbluetooth -levent
+CLEANFILES+=   sbc_crc.h sbc_coeffs.h
+
+sbc_encode.c:  sbc_coeffs.h sbc_crc.h
+sbc_coeffs.h:
+       ../cosdata-gen/cosdata > sbc_coeffs.h
+sbc_crc.h:
+       ../sbc_crc-gen/sbc_crc > sbc_crc.h
+
+.if exists(${.CURDIR}/../../Makefile.inc)
+.include "${.CURDIR}/../../Makefile.inc"
+.endif
+
+.include <bsd.prog.mk>
diff -r 45dc1095f2e7 -r 69566c5efeaa usr.sbin/bta2dpd/bta2dpd/avdtp.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.sbin/bta2dpd/bta2dpd/avdtp.c  Sat Jan 28 16:55:54 2017 +0000
@@ -0,0 +1,380 @@
+/* $NetBSD: avdtp.c,v 1.1 2017/01/28 16:55:54 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.
+ */
+
+#include <errno.h>
+#include <malloc.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "avdtp_signal.h"
+#include "sbc_encode.h"
+
+static uint8_t transLabel = 1;
+int
+avdtpSendCommand(int fd, uint8_t command, uint8_t type, uint8_t *data,
+    size_t datasize)
+{
+#define SINGLE_PACKET 0
+#define START_PACKET 1
+#define CONTINUE_PACKET 2
+#define END_PACKET 3
+#define signalID 3
+
+       uint8_t header[64];
+       size_t extra_size = 0;
+       const uint8_t packetType = (SINGLE_PACKET & 3) << 2;
+       const uint8_t messageType = (type & 3);
+
+       transLabel &= 0xf;
+
+       header[0] = (uint8_t)((transLabel << 4) | packetType | messageType);
+       if (command != 0)
+               header[1] = command & 0x3f;
+       else
+               header[1] = signalID & 0x3f; /* Bits 7/6 Reserved */
+
+       transLabel++;
+       if (data != NULL) {
+               extra_size = datasize;
+               memcpy(header + 2, data, extra_size);
+       }
+       write(fd, &header, extra_size + 2);
+
+       return transLabel - 1;
+}
+
+int
+avdtpCheckResponse(int recvfd, bool *isCommand, uint8_t *trans, uint8_t
+    *signalId, uint8_t *pkt_type, uint8_t *data, size_t *datasize, uint8_t *sep)
+{
+       uint8_t buffer[1024];
+       size_t len;
+
+       *isCommand = false;
+       len = (size_t)read(recvfd, buffer, sizeof(buffer));
+
+       if (datasize)
+               *datasize = 0;
+
+       if (len < AVDTP_LEN_SUCCESS)
+               return ENOMEM;
+
+       *trans = (buffer[0] & TRANSACTIONLABEL) >> TRANSACTIONLABEL_S;
+       *signalId = buffer[1] & SIGNALID_MASK;
+       if ((buffer[0] & MESSAGETYPE) == COMMAND) {
+               if (datasize)
+                       *datasize = 0;
+               if (sep && len > 2)
+                       *sep = buffer[2] >> 2;
+               *isCommand = true;
+       }
+
+       if (len == AVDTP_LEN_ERROR)
+               return buffer[2];
+       else if ((len % AVDTP_LEN_SUCCESS) == 0 &&
+           buffer[0] & RESPONSEACCEPT) {
+               if (len == AVDTP_LEN_SUCCESS)
+                       return 0;
+       }
+       if (datasize && data && len > AVDTP_LEN_SUCCESS &&
+           buffer[0] & RESPONSEACCEPT) {
+               memcpy(data, buffer + 2, len - 2);
+               *datasize = len - 2;
+
+               return 0;
+       }
+
+       if (isCommand)
+               return 0;
+
+       return EINVAL;
+}
+       
+int
+avdtpSendCapabilitiesResponseSBC(int fd, int recvfd, int trans, uint8_t mySep,
+    uint8_t bitpool, uint8_t freq, uint8_t mode, uint8_t bands, uint8_t blocks,
+    uint8_t alloc_method)
+{
+       uint8_t data[12], freqmode, blk_len_sb_alloc, freq_dat, mode_dat;
+       uint8_t bands_dat, blocks_dat, alloc_dat;
+
+       
+       freq_dat = (uint8_t)(freq << 4);
+       mode_dat = mode;
+       freqmode = freq_dat | mode_dat;
+
+       blocks_dat = (uint8_t)(blocks << 4);
+       bands_dat = (uint8_t)(bands << 2);
+       alloc_dat = alloc_method;
+       blk_len_sb_alloc = blocks_dat| bands_dat | alloc_dat;
+
+       data[0] = (uint8_t)(trans << 4 | RESPONSEACCEPT);
+       data[1] = AVDTP_GET_CAPABILITIES;
+       data[2] = mediaTransport;
+       data[3] = 0;
+       data[4] = mediaCodec;
+       data[5] = 0x6;
+       data[6] = mediaTypeAudio;
+       data[7] = SBC_CODEC_ID;
+       data[8] = freqmode;
+       data[9] = blk_len_sb_alloc;
+       data[10] = MIN_BITPOOL;
+       if (bitpool > MIN_BITPOOL)
+               data[11] = bitpool;
+       else
+               data[11] = DEFAULT_MAXBPOOL;
+
+       write(fd, data, sizeof(data));
+
+       return 0;
+}
+
+int
+avdtpSendAccept(int fd, int recvfd, uint8_t trans, uint8_t myCommand)
+{
+       uint8_t data[2];
+
+       data[0] = (uint8_t)(trans << 4 | RESPONSEACCEPT);
+       data[1] = myCommand;;
+
+       write(fd, data, sizeof(data));
+
+       return 0;
+}
+
+int
+avdtpSendReject(int fd, int recvfd, uint8_t trans, uint8_t myCommand)



Home | Main Index | Thread Index | Old Index