CVS commit: src/sys/netbt

2020-02-29 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sat Feb 29 11:40:06 UTC 2020

Modified Files:
src/sys/netbt: l2cap_signal.c rfcomm_session.c

Log Message:
pass the address of the field, instead of relying on it being the first
field of the structure/union, no functional change, discussed with plunky@


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/sys/netbt/l2cap_signal.c
cvs rdiff -u -r1.26 -r1.27 src/sys/netbt/rfcomm_session.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/netbt/l2cap_signal.c
diff -u src/sys/netbt/l2cap_signal.c:1.19 src/sys/netbt/l2cap_signal.c:1.20
--- src/sys/netbt/l2cap_signal.c:1.19	Tue Aug 21 14:59:13 2018
+++ src/sys/netbt/l2cap_signal.c	Sat Feb 29 11:40:06 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: l2cap_signal.c,v 1.19 2018/08/21 14:59:13 plunky Exp $	*/
+/*	$NetBSD: l2cap_signal.c,v 1.20 2020/02/29 11:40:06 maxv Exp $	*/
 
 /*-
  * Copyright (c) 2005 Iain Hibbert.
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: l2cap_signal.c,v 1.19 2018/08/21 14:59:13 plunky Exp $");
+__KERNEL_RCSID(0, "$NetBSD: l2cap_signal.c,v 1.20 2020/02/29 11:40:06 maxv Exp $");
 
 #include 
 #include 
@@ -488,7 +488,7 @@ l2cap_recv_config_req(struct mbuf *m, st
 			if (opt.length != L2CAP_OPT_MTU_SIZE)
 goto reject;
 
-			m_copydata(m, 0, L2CAP_OPT_MTU_SIZE, );
+			m_copydata(m, 0, L2CAP_OPT_MTU_SIZE, );
 			val.mtu = le16toh(val.mtu);
 
 			/*
@@ -539,7 +539,7 @@ l2cap_recv_config_req(struct mbuf *m, st
 			 * config request is merely advising us of their
 			 * outgoing traffic flow, so be nice.
 			 */
-			m_copydata(m, 0, L2CAP_OPT_QOS_SIZE, );
+			m_copydata(m, 0, L2CAP_OPT_QOS_SIZE, );
 			switch (val.qos.service_type) {
 			case L2CAP_QOS_NO_TRAFFIC:
 /*
@@ -729,7 +729,7 @@ l2cap_recv_config_rsp(struct mbuf *m, st
 if (opt.length != L2CAP_OPT_MTU_SIZE)
 	goto discon;
 
-m_copydata(m, 0, L2CAP_OPT_MTU_SIZE, );
+m_copydata(m, 0, L2CAP_OPT_MTU_SIZE, );
 chan->lc_imtu = le16toh(val.mtu);
 if (chan->lc_imtu < L2CAP_MTU_MINIMUM)
 	chan->lc_imtu = L2CAP_MTU_DEFAULT;
@@ -759,7 +759,7 @@ l2cap_recv_config_rsp(struct mbuf *m, st
  * We don't support anything, but copy in the
  * parameters if no action is good enough.
  */
-m_copydata(m, 0, L2CAP_OPT_QOS_SIZE, );
+m_copydata(m, 0, L2CAP_OPT_QOS_SIZE, );
 switch (val.qos.service_type) {
 case L2CAP_QOS_NO_TRAFFIC:
 case L2CAP_QOS_BEST_EFFORT:

Index: src/sys/netbt/rfcomm_session.c
diff -u src/sys/netbt/rfcomm_session.c:1.26 src/sys/netbt/rfcomm_session.c:1.27
--- src/sys/netbt/rfcomm_session.c:1.26	Sun Feb 23 20:16:10 2020
+++ src/sys/netbt/rfcomm_session.c	Sat Feb 29 11:40:06 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: rfcomm_session.c,v 1.26 2020/02/23 20:16:10 plunky Exp $	*/
+/*	$NetBSD: rfcomm_session.c,v 1.27 2020/02/29 11:40:06 maxv Exp $	*/
 
 /*-
  * Copyright (c) 2006 Itronix Inc.
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: rfcomm_session.c,v 1.26 2020/02/23 20:16:10 plunky Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rfcomm_session.c,v 1.27 2020/02/29 11:40:06 maxv Exp $");
 
 #include 
 #include 
@@ -1237,7 +1237,7 @@ rfcomm_session_recv_mcc_rpn(struct rfcom
 		rpn.param_mask = le16toh(rpn.param_mask);
 	} else if (m->m_pkthdr.len == 1) {
 		/* current settings request */
-		m_copydata(m, 0, 1, );
+		m_copydata(m, 0, 1, );
 		rpn.param_mask = RFCOMM_RPN_PM_ALL;
 	} else {
 		DPRINTF("Bad RPN length (%d)\n", m->m_pkthdr.len);



CVS commit: src/sys/netbt

2020-02-23 Thread Iain Hibbert
Module Name:src
Committed By:   plunky
Date:   Sun Feb 23 20:16:10 UTC 2020

Modified Files:
src/sys/netbt: rfcomm_session.c

Log Message:
fix reversed logic for Remote Port Negotiation, pointed out by maxv@


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/sys/netbt/rfcomm_session.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/netbt/rfcomm_session.c
diff -u src/sys/netbt/rfcomm_session.c:1.25 src/sys/netbt/rfcomm_session.c:1.26
--- src/sys/netbt/rfcomm_session.c:1.25	Sat Dec 22 14:28:57 2018
+++ src/sys/netbt/rfcomm_session.c	Sun Feb 23 20:16:10 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: rfcomm_session.c,v 1.25 2018/12/22 14:28:57 maxv Exp $	*/
+/*	$NetBSD: rfcomm_session.c,v 1.26 2020/02/23 20:16:10 plunky Exp $	*/
 
 /*-
  * Copyright (c) 2006 Itronix Inc.
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: rfcomm_session.c,v 1.25 2018/12/22 14:28:57 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rfcomm_session.c,v 1.26 2020/02/23 20:16:10 plunky Exp $");
 
 #include 
 #include 
@@ -1232,11 +1232,13 @@ rfcomm_session_recv_mcc_rpn(struct rfcom
 	rpn.xoff_char = RFCOMM_RPN_XOFF_CHAR;
 
 	if (m->m_pkthdr.len == sizeof(rpn)) {
+		/* negotiation request */
 		m_copydata(m, 0, sizeof(rpn), );
-		rpn.param_mask = RFCOMM_RPN_PM_ALL;
+		rpn.param_mask = le16toh(rpn.param_mask);
 	} else if (m->m_pkthdr.len == 1) {
+		/* current settings request */
 		m_copydata(m, 0, 1, );
-		rpn.param_mask = le16toh(rpn.param_mask);
+		rpn.param_mask = RFCOMM_RPN_PM_ALL;
 	} else {
 		DPRINTF("Bad RPN length (%d)\n", m->m_pkthdr.len);
 		return;



CVS commit: src/sys/netbt

2018-09-07 Thread Iain Hibbert
Module Name:src
Committed By:   plunky
Date:   Fri Sep  7 14:47:15 UTC 2018

Modified Files:
src/sys/netbt: hci_link.c

Log Message:
two issues noted by maxv@

1. If an adaptor sends repeated fragments indicating HCI_PACKET_START,
   we would leak mbufs. Fix that by releasing the previous in that case.

2. If an adaptor sends fragments which overflow the expected total
   payload length, it could build up the pending packet to use up system
   mbufs. Fix that by changing the unsigned calculation to a comparison
   and rejecting oversize packets


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/sys/netbt/hci_link.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/netbt/hci_link.c
diff -u src/sys/netbt/hci_link.c:1.24 src/sys/netbt/hci_link.c:1.25
--- src/sys/netbt/hci_link.c:1.24	Tue May 20 18:25:54 2014
+++ src/sys/netbt/hci_link.c	Fri Sep  7 14:47:15 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: hci_link.c,v 1.24 2014/05/20 18:25:54 rmind Exp $	*/
+/*	$NetBSD: hci_link.c,v 1.25 2018/09/07 14:47:15 plunky Exp $	*/
 
 /*-
  * Copyright (c) 2005 Iain Hibbert.
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: hci_link.c,v 1.24 2014/05/20 18:25:54 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: hci_link.c,v 1.25 2018/09/07 14:47:15 plunky Exp $");
 
 #include 
 #include 
@@ -475,12 +475,15 @@ hci_acl_recv(struct mbuf *m, struct hci_
 
 	switch (pb) {
 	case HCI_PACKET_START:
-		if (link->hl_rxp != NULL)
+		if (m->m_pkthdr.len < sizeof(l2cap_hdr_t))
+			goto bad;
+
+		if (link->hl_rxp != NULL) {
 			aprint_error_dev(unit->hci_dev,
 			"dropped incomplete ACL packet\n");
 
-		if (m->m_pkthdr.len < sizeof(l2cap_hdr_t))
-			goto bad;
+			m_freem(link->hl_rxp);
+		}
 
 		link->hl_rxp = m;
 		got = m->m_pkthdr.len;
@@ -508,18 +511,24 @@ hci_acl_recv(struct mbuf *m, struct hci_
 	}
 
 	m_copydata(m, 0, sizeof(want), );
-	want = le16toh(want) + sizeof(l2cap_hdr_t) - got;
+	want = le16toh(want);
+	got -= sizeof(l2cap_hdr_t);
 
-	if (want > 0)
+	if (got < want)		/* wait for more */
 		return;
 
 	link->hl_rxp = NULL;
 
-	if (want == 0) {
-		l2cap_recv_frame(m, link);
-		return;
+	if (got > want) {
+		DPRINTF("%s: packet overflow\n",
+			device_xname(unit->hci_dev));
+
+		goto bad;
 	}
 
+	l2cap_recv_frame(m, link);
+	return;
+
 bad:
 	m_freem(m);
 }



CVS commit: src/sys/netbt

2018-08-21 Thread Iain Hibbert
Module Name:src
Committed By:   plunky
Date:   Tue Aug 21 14:59:13 UTC 2018

Modified Files:
src/sys/netbt: hci_event.c l2cap_signal.c

Log Message:
Result of audit to check that mbuf length is checked before m_copydata()
and that any data supposedly copied out is valid before use.

prompted by maxv@, I have checked every usage of m_copydata() and made
the following corrections

hci_event.c:
hci_event_command_compl()
check that the packet does contain enough data for there to
be a status code before noting possible failures.

hci_event_num_compl_pkts()
check that the packet does contain data to cover the
stated number of handle/num pairs

l2cap_signal.c:
l2cap_recv_signal()
just ignore packets with not enough data rather than
trying to reject them (may not have cmd.ident)

l2cap_recv_command_rej()
check we have a valid reason and/or data before use


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/sys/netbt/hci_event.c
cvs rdiff -u -r1.18 -r1.19 src/sys/netbt/l2cap_signal.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/netbt/hci_event.c
diff -u src/sys/netbt/hci_event.c:1.24 src/sys/netbt/hci_event.c:1.25
--- src/sys/netbt/hci_event.c:1.24	Sat Nov 28 09:04:34 2015
+++ src/sys/netbt/hci_event.c	Tue Aug 21 14:59:13 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: hci_event.c,v 1.24 2015/11/28 09:04:34 plunky Exp $	*/
+/*	$NetBSD: hci_event.c,v 1.25 2018/08/21 14:59:13 plunky Exp $	*/
 
 /*-
  * Copyright (c) 2005 Iain Hibbert.
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: hci_event.c,v 1.24 2015/11/28 09:04:34 plunky Exp $");
+__KERNEL_RCSID(0, "$NetBSD: hci_event.c,v 1.25 2018/08/21 14:59:13 plunky Exp $");
 
 #include 
 #include 
@@ -316,12 +316,14 @@ hci_event_command_compl(struct hci_unit 
 	 * that a command_complete packet will contain the status though most
 	 * do seem to.
 	 */
-	m_copydata(m, 0, sizeof(rp), );
-	if (rp.status > 0)
-		aprint_error_dev(unit->hci_dev,
-		"CommandComplete opcode (%03x|%04x) failed (status=0x%02x)\n",
-		HCI_OGF(le16toh(ep.opcode)), HCI_OCF(le16toh(ep.opcode)),
-		rp.status);
+	if (m->m_pkthdr.len >= sizeof(rp)) {
+		m_copydata(m, 0, sizeof(rp), );
+		if (rp.status > 0)
+			aprint_error_dev(unit->hci_dev,
+			"CommandComplete opcode (%03x|%04x) failed (status=0x%02x)\n",
+			HCI_OGF(le16toh(ep.opcode)), HCI_OCF(le16toh(ep.opcode)),
+			rp.status);
+	}
 
 	/*
 	 * post processing of completed commands
@@ -383,6 +385,9 @@ hci_event_num_compl_pkts(struct hci_unit
 	m_copydata(m, 0, sizeof(ep), );
 	m_adj(m, sizeof(ep));
 
+	if (m->m_pkthdr.len < ep.num_con_handles * (sizeof(handle) + sizeof(num)))
+		return;
+
 	while (ep.num_con_handles--) {
 		m_copydata(m, 0, sizeof(handle), );
 		m_adj(m, sizeof(handle));

Index: src/sys/netbt/l2cap_signal.c
diff -u src/sys/netbt/l2cap_signal.c:1.18 src/sys/netbt/l2cap_signal.c:1.19
--- src/sys/netbt/l2cap_signal.c:1.18	Tue Oct  4 14:13:46 2016
+++ src/sys/netbt/l2cap_signal.c	Tue Aug 21 14:59:13 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: l2cap_signal.c,v 1.18 2016/10/04 14:13:46 joerg Exp $	*/
+/*	$NetBSD: l2cap_signal.c,v 1.19 2018/08/21 14:59:13 plunky Exp $	*/
 
 /*-
  * Copyright (c) 2005 Iain Hibbert.
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: l2cap_signal.c,v 1.18 2016/10/04 14:13:46 joerg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: l2cap_signal.c,v 1.19 2018/08/21 14:59:13 plunky Exp $");
 
 #include 
 #include 
@@ -64,7 +64,8 @@ static void l2cap_qos_htob(void *, l2cap
 
 /*
  * process incoming signal packets (CID 0x0001). Can contain multiple
- * requests/responses.
+ * requests/responses. The signal hander should clear the command from
+ * the mbuf before returning.
  */
 void
 l2cap_recv_signal(struct mbuf *m, struct hci_link *link)
@@ -72,11 +73,8 @@ l2cap_recv_signal(struct mbuf *m, struct
 	l2cap_cmd_hdr_t cmd;
 
 	for(;;) {
-		if (m->m_pkthdr.len == 0)
-			goto finish;
-
 		if (m->m_pkthdr.len < sizeof(cmd))
-			goto reject;
+			goto finish;
 
 		m_copydata(m, 0, sizeof(cmd), );
 		cmd.length = le16toh(cmd.length);
@@ -183,32 +181,42 @@ l2cap_recv_command_rej(struct mbuf *m, s
 
 	cmd.length = le16toh(cmd.length);
 
+	/* The length here must contain the reason (2 octets) plus
+	 * any data (0 or more octets) but we already know it is not
+	 * bigger than l2cap_cmd_rej_cp
+	 */
 	m_copydata(m, 0, cmd.length, );
 	m_adj(m, cmd.length);
 
+	if (cmd.length < 2)
+		return;
+
 	req = l2cap_request_lookup(link, cmd.ident);
 	if (req == NULL)
 		return;
 
 	switch (le16toh(cp.reason)) {
-	case L2CAP_REJ_NOT_UNDERSTOOD:
+	case L2CAP_REJ_NOT_UNDERSTOOD:	/* data length = 0 octets */
 		/*
 		 * I dont know what to do, just move up the timeout
 		 */
 		callout_schedule(>lr_rtx, 0);
 		break;
 
-	case 

CVS commit: src/sys/netbt

2018-07-25 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Wed Jul 25 19:09:38 UTC 2018

Modified Files:
src/sys/netbt: hci.h

Log Message:
Appease GCC in hci_filter_test()

Cast the returned value from hci_filter_test explicitly to int, as
requested by GCC when building with Undefined Behavior Sanitizer.


To generate a diff of this commit:
cvs rdiff -u -r1.44 -r1.45 src/sys/netbt/hci.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/netbt/hci.h
diff -u src/sys/netbt/hci.h:1.44 src/sys/netbt/hci.h:1.45
--- src/sys/netbt/hci.h:1.44	Thu Dec 21 09:30:30 2017
+++ src/sys/netbt/hci.h	Wed Jul 25 19:09:38 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: hci.h,v 1.44 2017/12/21 09:30:30 plunky Exp $	*/
+/*	$NetBSD: hci.h,v 1.45 2018/07/25 19:09:38 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2005 Iain Hibbert.
@@ -54,7 +54,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $Id: hci.h,v 1.44 2017/12/21 09:30:30 plunky Exp $
+ * $Id: hci.h,v 1.45 2018/07/25 19:09:38 kamil Exp $
  * $FreeBSD: src/sys/netgraph/bluetooth/include/ng_hci.h,v 1.6 2005/01/07 01:45:43 imp Exp $
  */
 
@@ -2300,7 +2300,7 @@ hci_filter_test(uint8_t bit, const struc
 	uint8_t off = (uint8_t)((bit - 1) >> 5);
 	uint8_t sh = (uint8_t)((bit - 1) & 0x1f);
 
-	return (filter->mask[off] >> sh) & 1U;
+	return (int)((filter->mask[off] >> sh) & 1U);
 }
 
 /*



CVS commit: src/sys/netbt

2017-12-21 Thread Iain Hibbert
Module Name:src
Committed By:   plunky
Date:   Thu Dec 21 09:30:31 UTC 2017

Modified Files:
src/sys/netbt: hci.h

Log Message:
add HCI_SPEC_50


To generate a diff of this commit:
cvs rdiff -u -r1.43 -r1.44 src/sys/netbt/hci.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/netbt/hci.h
diff -u src/sys/netbt/hci.h:1.43 src/sys/netbt/hci.h:1.44
--- src/sys/netbt/hci.h:1.43	Sat Jan 28 19:19:41 2017
+++ src/sys/netbt/hci.h	Thu Dec 21 09:30:30 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: hci.h,v 1.43 2017/01/28 19:19:41 jakllsch Exp $	*/
+/*	$NetBSD: hci.h,v 1.44 2017/12/21 09:30:30 plunky Exp $	*/
 
 /*-
  * Copyright (c) 2005 Iain Hibbert.
@@ -54,7 +54,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $Id: hci.h,v 1.43 2017/01/28 19:19:41 jakllsch Exp $
+ * $Id: hci.h,v 1.44 2017/12/21 09:30:30 plunky Exp $
  * $FreeBSD: src/sys/netgraph/bluetooth/include/ng_hci.h,v 1.6 2005/01/07 01:45:43 imp Exp $
  */
 
@@ -105,7 +105,8 @@
 #define HCI_SPEC_V40			0x06 /* v4.0 */
 #define HCI_SPEC_V41			0x07 /* v4.1 */
 #define HCI_SPEC_V42			0x08 /* v4.2 */
-/* 0x09 - 0xFF - reserved for future use */
+#define HCI_SPEC_V50			0x09 /* v5.0 */
+/* 0x0A - 0xFF - reserved for future use */
 
 /* LMP features (and page 0 of extended features) */
 /* --- byte 0 */



CVS commit: src/sys/netbt

2017-01-28 Thread Jonathan A. Kollasch
Module Name:src
Committed By:   jakllsch
Date:   Sat Jan 28 19:19:41 UTC 2017

Modified Files:
src/sys/netbt: hci.h

Log Message:
avoid -Werror=sign-conversion


To generate a diff of this commit:
cvs rdiff -u -r1.42 -r1.43 src/sys/netbt/hci.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/netbt/hci.h
diff -u src/sys/netbt/hci.h:1.42 src/sys/netbt/hci.h:1.43
--- src/sys/netbt/hci.h:1.42	Sat Jan 28 19:07:16 2017
+++ src/sys/netbt/hci.h	Sat Jan 28 19:19:41 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: hci.h,v 1.42 2017/01/28 19:07:16 christos Exp $	*/
+/*	$NetBSD: hci.h,v 1.43 2017/01/28 19:19:41 jakllsch Exp $	*/
 
 /*-
  * Copyright (c) 2005 Iain Hibbert.
@@ -54,7 +54,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $Id: hci.h,v 1.42 2017/01/28 19:07:16 christos Exp $
+ * $Id: hci.h,v 1.43 2017/01/28 19:19:41 jakllsch Exp $
  * $FreeBSD: src/sys/netgraph/bluetooth/include/ng_hci.h,v 1.6 2005/01/07 01:45:43 imp Exp $
  */
 
@@ -2281,7 +2281,7 @@ hci_filter_set(uint8_t bit, struct hci_f
 	uint8_t off = (uint8_t)((bit - 1) >> 5);
 	uint8_t sh = (uint8_t)((bit - 1) & 0x1f);
 
-	filter->mask[off] |= 1 << sh;
+	filter->mask[off] |= 1U << sh;
 }
 
 static __inline void
@@ -2290,7 +2290,7 @@ hci_filter_clr(uint8_t bit, struct hci_f
 	uint8_t off = (uint8_t)((bit - 1) >> 5);
 	uint8_t sh = (uint8_t)((bit - 1) & 0x1f);
 
-	filter->mask[off] &= ~(1 << sh);
+	filter->mask[off] &= ~(1U << sh);
 }
 
 static __inline int
@@ -2299,7 +2299,7 @@ hci_filter_test(uint8_t bit, const struc
 	uint8_t off = (uint8_t)((bit - 1) >> 5);
 	uint8_t sh = (uint8_t)((bit - 1) & 0x1f);
 
-	return filter->mask[off] & (1 << sh);
+	return (filter->mask[off] >> sh) & 1U;
 }
 
 /*



CVS commit: src/sys/netbt

2017-01-28 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Jan 28 19:07:16 UTC 2017

Modified Files:
src/sys/netbt: hci.h

Log Message:
factor out common subexpressions.


To generate a diff of this commit:
cvs rdiff -u -r1.41 -r1.42 src/sys/netbt/hci.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/netbt/hci.h
diff -u src/sys/netbt/hci.h:1.41 src/sys/netbt/hci.h:1.42
--- src/sys/netbt/hci.h:1.41	Sat Nov 28 04:04:34 2015
+++ src/sys/netbt/hci.h	Sat Jan 28 14:07:16 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: hci.h,v 1.41 2015/11/28 09:04:34 plunky Exp $	*/
+/*	$NetBSD: hci.h,v 1.42 2017/01/28 19:07:16 christos Exp $	*/
 
 /*-
  * Copyright (c) 2005 Iain Hibbert.
@@ -54,7 +54,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $Id: hci.h,v 1.41 2015/11/28 09:04:34 plunky Exp $
+ * $Id: hci.h,v 1.42 2017/01/28 19:07:16 christos Exp $
  * $FreeBSD: src/sys/netgraph/bluetooth/include/ng_hci.h,v 1.6 2005/01/07 01:45:43 imp Exp $
  */
 
@@ -2278,28 +2278,28 @@ struct hci_filter {
 static __inline void
 hci_filter_set(uint8_t bit, struct hci_filter *filter)
 {
-	uint8_t off = bit - 1;
+	uint8_t off = (uint8_t)((bit - 1) >> 5);
+	uint8_t sh = (uint8_t)((bit - 1) & 0x1f);
 
-	off >>= 5;
-	filter->mask[off] |= (1 << ((bit - 1) & 0x1f));
+	filter->mask[off] |= 1 << sh;
 }
 
 static __inline void
 hci_filter_clr(uint8_t bit, struct hci_filter *filter)
 {
-	uint8_t off = bit - 1;
+	uint8_t off = (uint8_t)((bit - 1) >> 5);
+	uint8_t sh = (uint8_t)((bit - 1) & 0x1f);
 
-	off >>= 5;
-	filter->mask[off] &= ~(1 << ((bit - 1) & 0x1f));
+	filter->mask[off] &= ~(1 << sh);
 }
 
 static __inline int
 hci_filter_test(uint8_t bit, const struct hci_filter *filter)
 {
-	uint8_t off = bit - 1;
+	uint8_t off = (uint8_t)((bit - 1) >> 5);
+	uint8_t sh = (uint8_t)((bit - 1) & 0x1f);
 
-	off >>= 5;
-	return (filter->mask[off] & (1 << ((bit - 1) & 0x1f)));
+	return filter->mask[off] & (1 << sh);
 }
 
 /*



CVS commit: src/sys/netbt

2016-10-04 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Tue Oct  4 14:13:46 UTC 2016

Modified Files:
src/sys/netbt: l2cap_signal.c

Log Message:
The last named argument of a variadic function shall not be default
promoted according to ISO C.


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/sys/netbt/l2cap_signal.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/netbt/l2cap_signal.c
diff -u src/sys/netbt/l2cap_signal.c:1.17 src/sys/netbt/l2cap_signal.c:1.18
--- src/sys/netbt/l2cap_signal.c:1.17	Sat Nov 28 08:57:33 2015
+++ src/sys/netbt/l2cap_signal.c	Tue Oct  4 14:13:46 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: l2cap_signal.c,v 1.17 2015/11/28 08:57:33 plunky Exp $	*/
+/*	$NetBSD: l2cap_signal.c,v 1.18 2016/10/04 14:13:46 joerg Exp $	*/
 
 /*-
  * Copyright (c) 2005 Iain Hibbert.
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: l2cap_signal.c,v 1.17 2015/11/28 08:57:33 plunky Exp $");
+__KERNEL_RCSID(0, "$NetBSD: l2cap_signal.c,v 1.18 2016/10/04 14:13:46 joerg Exp $");
 
 #include 
 #include 
@@ -58,7 +58,7 @@ static void l2cap_recv_disconnect_req(st
 static void l2cap_recv_disconnect_rsp(struct mbuf *, struct hci_link *);
 static void l2cap_recv_info_req(struct mbuf *, struct hci_link *);
 static int l2cap_send_signal(struct hci_link *, uint8_t, uint8_t, uint16_t, void *);
-static int l2cap_send_command_rej(struct hci_link *, uint8_t, uint16_t, ...);
+static int l2cap_send_command_rej(struct hci_link *, uint8_t, int, ...);
 static void l2cap_qos_btoh(l2cap_qos_t *, void *);
 static void l2cap_qos_htob(void *, l2cap_qos_t *);
 
@@ -1049,7 +1049,7 @@ l2cap_send_signal(struct hci_link *link,
  */
 static int
 l2cap_send_command_rej(struct hci_link *link, uint8_t ident,
-			uint16_t reason, ...)
+			int reason, ...)
 {
 	l2cap_cmd_rej_cp cp;
 	int len = 0;



CVS commit: src/sys/netbt

2015-12-22 Thread Iain Hibbert
Module Name:src
Committed By:   plunky
Date:   Tue Dec 22 11:40:07 UTC 2015

Modified Files:
src/sys/netbt: hci_socket.c

Log Message:
there is no longer a reason to have a separate hci_send function now
that the hci_usrreq function is disassembled, so merge hci_send_pcb
back into hci_send()


To generate a diff of this commit:
cvs rdiff -u -r1.44 -r1.45 src/sys/netbt/hci_socket.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/netbt/hci_socket.c
diff -u src/sys/netbt/hci_socket.c:1.44 src/sys/netbt/hci_socket.c:1.45
--- src/sys/netbt/hci_socket.c:1.44	Sat May  2 17:18:03 2015
+++ src/sys/netbt/hci_socket.c	Tue Dec 22 11:40:07 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: hci_socket.c,v 1.44 2015/05/02 17:18:03 rtr Exp $	*/
+/*	$NetBSD: hci_socket.c,v 1.45 2015/12/22 11:40:07 plunky Exp $	*/
 
 /*-
  * Copyright (c) 2005 Iain Hibbert.
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: hci_socket.c,v 1.44 2015/05/02 17:18:03 rtr Exp $");
+__KERNEL_RCSID(0, "$NetBSD: hci_socket.c,v 1.45 2015/12/22 11:40:07 plunky Exp $");
 
 /* load symbolic names */
 #ifdef BLUETOOTH_DEBUG
@@ -348,84 +348,6 @@ hci_cmdwait_flush(struct socket *so)
 	}
 }
 
-/*
- * HCI send packet
- * This came from userland, so check it out.
- */
-static int
-hci_send_pcb(struct hci_pcb *pcb, struct mbuf *m, bdaddr_t *addr)
-{
-	struct hci_unit *unit;
-	struct mbuf *m0;
-	hci_cmd_hdr_t hdr;
-	int err;
-
-	KASSERT(m != NULL);
-	KASSERT(addr != NULL);
-
-	/* wants at least a header to start with */
-	if (m->m_pkthdr.len < sizeof(hdr)) {
-		err = EMSGSIZE;
-		goto bad;
-	}
-	m_copydata(m, 0, sizeof(hdr), );
-	hdr.opcode = le16toh(hdr.opcode);
-
-	/* only allows CMD packets to be sent */
-	if (hdr.type != HCI_CMD_PKT) {
-		err = EINVAL;
-		goto bad;
-	}
-
-	/* validates packet length */
-	if (m->m_pkthdr.len != sizeof(hdr) + hdr.length) {
-		err = EMSGSIZE;
-		goto bad;
-	}
-
-	/* finds destination */
-	unit = hci_unit_lookup(addr);
-	if (unit == NULL) {
-		err = ENETDOWN;
-		goto bad;
-	}
-
-	/* security checks for unprivileged users */
-	if (pcb->hp_cred != NULL
-	&& kauth_authorize_device(pcb->hp_cred,
-	KAUTH_DEVICE_BLUETOOTH_SEND,
-	unit, , NULL, NULL) != 0) {
-		err = EPERM;
-		goto bad;
-	}
-
-	/* makess a copy for precious to keep */
-	m0 = m_copypacket(m, M_DONTWAIT);
-	if (m0 == NULL) {
-		err = ENOMEM;
-		goto bad;
-	}
-	sbappendrecord(>hp_socket->so_snd, m0);
-	M_SETCTX(m, pcb->hp_socket);	/* enable drop callback */
-
-	DPRINTFN(2, "(%s) opcode (%03x|%04x)\n", device_xname(unit->hci_dev),
-		HCI_OGF(hdr.opcode), HCI_OCF(hdr.opcode));
-
-	/* Sendss it */
-	if (unit->hci_num_cmd_pkts == 0)
-		MBUFQ_ENQUEUE(>hci_cmdwait, m);
-	else
-		hci_output_cmd(unit, m);
-
-	return 0;
-
-bad:
-	DPRINTF("packet (%d bytes) not sent (error %d)\n",
-			m->m_pkthdr.len, err);
-	if (m) m_freem(m);
-	return err;
-}
-
 static int
 hci_attach(struct socket *so, int proto)
 {
@@ -669,30 +591,94 @@ hci_send(struct socket *so, struct mbuf 
 struct mbuf *control, struct lwp *l)
 {
 	struct hci_pcb *pcb = so->so_pcb;
-	struct sockaddr_bt * sa = (struct sockaddr_bt *)nam;
+	struct sockaddr_bt *sa = (struct sockaddr_bt *)nam;
+	struct hci_unit *unit;
+	struct mbuf *m0;
+	hci_cmd_hdr_t hdr;
 	int err = 0;
 
 	KASSERT(solocked(so));
 	KASSERT(pcb != NULL);
+	KASSERT(m != NULL);
 
 	if (control) /* have no use for this */
 		m_freem(control);
 
-	if (nam) {
+	if (sa) {
 		if (sa->bt_len != sizeof(struct sockaddr_bt)) {
 			err = EINVAL;
-			goto release;
+			goto bad;
 		}
 
 		if (sa->bt_family != AF_BLUETOOTH) {
 			err = EAFNOSUPPORT;
-			goto release;
+			goto bad;
 		}
 	}
 
-	return hci_send_pcb(pcb, m, (sa ? >bt_bdaddr : >hp_raddr));
+ 	/*
+	 * this came from userland, so we check it out first
+	 */
+
+	/* wants at least a header to start with */
+	if (m->m_pkthdr.len < sizeof(hdr)) {
+		err = EMSGSIZE;
+		goto bad;
+	}
+	m_copydata(m, 0, sizeof(hdr), );
+	hdr.opcode = le16toh(hdr.opcode);
+
+	/* only allows CMD packets to be sent */
+	if (hdr.type != HCI_CMD_PKT) {
+		err = EINVAL;
+		goto bad;
+	}
+
+	/* validates packet length */
+	if (m->m_pkthdr.len != sizeof(hdr) + hdr.length) {
+		err = EMSGSIZE;
+		goto bad;
+	}
+
+	/* finds destination */
+	unit = hci_unit_lookup((sa ? >bt_bdaddr : >hp_raddr));
+	if (unit == NULL) {
+		err = ENETDOWN;
+		goto bad;
+	}
+
+	/* security checks for unprivileged users */
+	if (pcb->hp_cred != NULL
+	&& kauth_authorize_device(pcb->hp_cred,
+	KAUTH_DEVICE_BLUETOOTH_SEND,
+	unit, , NULL, NULL) != 0) {
+		err = EPERM;
+		goto bad;
+	}
+
+	/* makess a copy for precious to keep */
+	m0 = m_copypacket(m, M_DONTWAIT);
+	if (m0 == NULL) {
+		err = ENOMEM;
+		goto bad;
+	}
+	sbappendrecord(>hp_socket->so_snd, m0);
+	M_SETCTX(m, pcb->hp_socket);	/* enable drop callback */
+
+	DPRINTFN(2, "(%s) opcode (%03x|%04x)\n", device_xname(unit->hci_dev),
+		HCI_OGF(hdr.opcode), 

CVS commit: src/sys/netbt

2015-11-28 Thread Iain Hibbert
Module Name:src
Committed By:   plunky
Date:   Sat Nov 28 08:57:33 UTC 2015

Modified Files:
src/sys/netbt: l2cap_signal.c

Log Message:
note recent spec additions to L2CAP Info command regarding fixed channels


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/sys/netbt/l2cap_signal.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/netbt/l2cap_signal.c
diff -u src/sys/netbt/l2cap_signal.c:1.16 src/sys/netbt/l2cap_signal.c:1.17
--- src/sys/netbt/l2cap_signal.c:1.16	Sat Feb  9 01:19:05 2013
+++ src/sys/netbt/l2cap_signal.c	Sat Nov 28 08:57:33 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: l2cap_signal.c,v 1.16 2013/02/09 01:19:05 christos Exp $	*/
+/*	$NetBSD: l2cap_signal.c,v 1.17 2015/11/28 08:57:33 plunky Exp $	*/
 
 /*-
  * Copyright (c) 2005 Iain Hibbert.
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: l2cap_signal.c,v 1.16 2013/02/09 01:19:05 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: l2cap_signal.c,v 1.17 2015/11/28 08:57:33 plunky Exp $");
 
 #include 
 #include 
@@ -974,6 +974,8 @@ l2cap_recv_info_req(struct mbuf *m, stru
 		 *   0   1   0x0001 L2CAP Signalling Channel (SET)
 		 *   0   2   0x0002 Connectionless Reception
 		 *   0   3   0x0003 AMP Manager Protocol Channel
+		 *   0   7   0x0007 BR/EDR Security Manager
+		 *   7   7   0x003f AMP Test Manager
 		 */
 		le16enc(rsp + 0, cp.type);
 		le16enc(rsp + 2, L2CAP_SUCCESS);



CVS commit: src/sys/netbt

2015-11-28 Thread Iain Hibbert
Module Name:src
Committed By:   plunky
Date:   Sat Nov 28 09:04:34 UTC 2015

Modified Files:
src/sys/netbt: hci.h hci_event.c hci_ioctl.c

Log Message:
add version and extended feature flags defined in 4.2 specification,
add cache for page 2 of extended features and return this in
the SIOCGBTFEAT ioctl (no change in size)


To generate a diff of this commit:
cvs rdiff -u -r1.40 -r1.41 src/sys/netbt/hci.h
cvs rdiff -u -r1.23 -r1.24 src/sys/netbt/hci_event.c
cvs rdiff -u -r1.12 -r1.13 src/sys/netbt/hci_ioctl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/netbt/hci.h
diff -u src/sys/netbt/hci.h:1.40 src/sys/netbt/hci.h:1.41
--- src/sys/netbt/hci.h:1.40	Sun Sep  6 06:01:01 2015
+++ src/sys/netbt/hci.h	Sat Nov 28 09:04:34 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: hci.h,v 1.40 2015/09/06 06:01:01 dholland Exp $	*/
+/*	$NetBSD: hci.h,v 1.41 2015/11/28 09:04:34 plunky Exp $	*/
 
 /*-
  * Copyright (c) 2005 Iain Hibbert.
@@ -54,14 +54,15 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $Id: hci.h,v 1.40 2015/09/06 06:01:01 dholland Exp $
+ * $Id: hci.h,v 1.41 2015/11/28 09:04:34 plunky Exp $
  * $FreeBSD: src/sys/netgraph/bluetooth/include/ng_hci.h,v 1.6 2005/01/07 01:45:43 imp Exp $
  */
 
 /*
  * This file contains everything that applications need to know from
  * Host Controller Interface (HCI). Information taken from Bluetooth
- * Core Specifications (v1.1, v2.0 and v2.1)
+ * Core Specifications (v1.1, v2.0, v2.1 + EDR, v3.0 + HS,
+ * v4.0 and v4.2)
  *
  * This file can be included by both kernel and userland applications.
  *
@@ -101,7 +102,10 @@
 #define HCI_SPEC_V20			0x03 /* v2.0 + EDR */
 #define HCI_SPEC_V21			0x04 /* v2.1 + EDR */
 #define HCI_SPEC_V30			0x05 /* v3.0 + HS */
-/* 0x06 - 0xFF - reserved for future use */
+#define HCI_SPEC_V40			0x06 /* v4.0 */
+#define HCI_SPEC_V41			0x07 /* v4.1 */
+#define HCI_SPEC_V42			0x08 /* v4.2 */
+/* 0x09 - 0xFF - reserved for future use */
 
 /* LMP features (and page 0 of extended features) */
 /* --- byte 0 */
@@ -146,8 +150,8 @@
 /* reserved0x04 */
 #define HCI_LMP_AFH_CAPABLE_SLAVE	0x08
 #define HCI_LMP_AFH_CLASS_SLAVE		0x10
-/* reserved0x20 */
-/* reserved0x40 */
+#define HCI_LMP_BR_EDR_UNSUPPORTED	0x20
+#define HCI_LMP_LE_CONTROLLER		0x40
 #define HCI_LMP_3SLOT_EDR_ACL		0x80
 /* --- byte 5 */
 #define HCI_LMP_5SLOT_EDR_ACL		0x01
@@ -160,7 +164,7 @@
 #define HCI_LMP_3SLOT_EDR_eSCO		0x80
 /* --- byte 6 */
 #define HCI_LMP_EXTENDED_INQUIRY	0x01
-/* reserved0x02 */
+#define HCI_LMP_LE_BR_EDR_CONTROLLER	0x02
 /* reserved0x04 */
 #define HCI_LMP_SIMPLE_PAIRING		0x08
 #define HCI_LMP_ENCAPSULATED_PDU	0x10
@@ -176,6 +180,25 @@
 /* page 1 of extended features */
 /* --- byte 0 */
 #define HCI_LMP_SSP			0x01
+#define HCI_LMP_LE_HOST			0x02
+#define HCI_LMP_LE_BR_EDR_HOST		0x04
+#define HCI_LMP_SECURE_CONN_HOST	0x08
+
+/* page 2 of extended features */
+/* --- byte 0 */
+#define HCI_LMP_CONNLESS_MASTER		0x01
+#define HCI_LMP_CONNLESS_SLAVE		0x02
+#define HCI_LMP_SYNC_TRAIN		0x04
+#define HCI_LMP_SYNC_SCAN		0x08
+#define HCI_LMP_INQ_RSP_NOTIFY		0x10
+#define HCI_LMP_INTERLACE_SCAN		0x20
+#define HCI_LMP_COARSE_CLOCK		0x40
+/* reserved0x80 */
+/* --- byte 0 */
+#define HCI_LMP_SECURE_CONN_CONTROLLER	0x01
+#define HCI_LMP_PING			0x02
+/* reserved0x04 */
+#define HCI_LMP_TRAIN_NUDGING		0x08
 
 /* Link types */
 #define HCI_LINK_SCO			0x00 /* Voice */
@@ -2334,6 +2357,7 @@ struct btreq {
 	struct {
 		uint8_t btrf_page0[HCI_FEATURES_SIZE];	/* basic */
 		uint8_t btrf_page1[HCI_FEATURES_SIZE];	/* extended */
+		uint8_t btrf_page2[HCI_FEATURES_SIZE];	/* extended */
 	} btrf;
 	struct bt_stats btrs;   /* unit stats */
 	} btru;
@@ -2352,6 +2376,7 @@ struct btreq {
 #define btr_max_sco	btru.btri.btri_max_sco
 #define btr_features0	btru.btrf.btrf_page0
 #define btr_features1	btru.btrf.btrf_page1
+#define btr_features2	btru.btrf.btrf_page2
 #define btr_stats	btru.btrs
 
 /* hci_unit & btr_flags */
@@ -2496,7 +2521,8 @@ struct hci_unit {
 	uint16_t	 hci_lmp_mask;		/* link policy capabilities */
 
 	uint8_t		 hci_feat0[HCI_FEATURES_SIZE]; /* features mask */
-	uint8_t		 hci_feat1[HCI_FEATURES_SIZE]; /* extended */
+	uint8_t		 hci_feat1[HCI_FEATURES_SIZE]; /* extended page 1 */
+	uint8_t		 hci_feat2[HCI_FEATURES_SIZE]; /* extended page 2 */
 	uint8_t		 hci_cmds[HCI_COMMANDS_SIZE]; /* opcode bitmask */
 
 	/* flow control */

Index: src/sys/netbt/hci_event.c
diff -u src/sys/netbt/hci_event.c:1.23 src/sys/netbt/hci_event.c:1.24
--- src/sys/netbt/hci_event.c:1.23	Wed Jul 27 10:25:09 2011
+++ src/sys/netbt/hci_event.c	Sat Nov 28 09:04:34 2015
@@ -1,4 +1,4 @@
-/*	

CVS commit: src/sys/netbt

2015-11-27 Thread Iain Hibbert
Module Name:src
Committed By:   plunky
Date:   Sat Nov 28 07:50:37 UTC 2015

Modified Files:
src/sys/netbt: l2cap.h

Log Message:
add in PSMs defined in later versions of specification


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/sys/netbt/l2cap.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/netbt/l2cap.h
diff -u src/sys/netbt/l2cap.h:1.18 src/sys/netbt/l2cap.h:1.19
--- src/sys/netbt/l2cap.h:1.18	Tue Aug  5 07:55:31 2014
+++ src/sys/netbt/l2cap.h	Sat Nov 28 07:50:37 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: l2cap.h,v 1.18 2014/08/05 07:55:31 rtr Exp $	*/
+/*	$NetBSD: l2cap.h,v 1.19 2015/11/28 07:50:37 plunky Exp $	*/
 
 /*-
  * Copyright (c) 2005 Iain Hibbert.
@@ -54,7 +54,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $Id: l2cap.h,v 1.18 2014/08/05 07:55:31 rtr Exp $
+ * $Id: l2cap.h,v 1.19 2015/11/28 07:50:37 plunky Exp $
  * $FreeBSD: src/sys/netgraph/bluetooth/include/l2cap.h,v 1.4 2005/08/31 18:13:23 emax Exp $
  */
 
@@ -105,7 +105,7 @@
 #define L2CAP_REJ_INVALID_CID		0x0002
 /* 0x0003 - 0x - reserved for future use */
 
-/* Protocol/Service Multiplexor (PSM) values */
+/* Protocol/Service Multiplexer (PSM) values */
 #define L2CAP_PSM_ANY			0x	/* Any/Invalid PSM */
 #define L2CAP_PSM_SDP			0x0001	/* Service Discovery Protocol */
 #define L2CAP_PSM_RFCOMM		0x0003	/* RFCOMM protocol */
@@ -121,7 +121,13 @@
 		/*	Transport Protocol */
 #define L2CAP_PSM_AVDTP			0x0019	/* Audio/Visual Distribution */
 		/*	Transport Protocol */
-/* 0x0019 - 0x1000 - reserved for future use */
+#define L2CAP_PSM_UDI_C_PLANE		0x001d	/* Unrestricted Digital */
+		/*  Information Profile */
+#define L2CAP_PSM_ATT			0x001f	/* Attribute Protocol */
+#define L2CAP_PSM_3DSP			0x0021	/* 3D Synchronization Profile */
+#define L2CAP_PSM_IPSP			0x0023	/* Internet Protocol */
+		/*  Support Profile */
+/* 0x0025 - 0x1000 - reserved for future use */
 
 #define L2CAP_PSM_INVALID(psm)		(((psm) & 0x0101) != 0x0001)
 
@@ -220,7 +226,7 @@ typedef struct {
 
 /* L2CAP ConnectionLess Traffic		(dcid == L2CAP_CLT_CID) */
 typedef struct {
-	uint16_t	psm; /* Protocol/Service Multiplexor */
+	uint16_t	psm; /* Protocol/Service Multiplexer */
 } __packed l2cap_clt_hdr_t;
 
 #define L2CAP_CLT_MTU_MAXIMUM \
@@ -243,7 +249,7 @@ typedef struct {
 /* L2CAP Connection Request */
 #define L2CAP_CONNECT_REQ			0x02
 typedef struct {
-	uint16_t	psm;  /* Protocol/Service Multiplexor (PSM) */
+	uint16_t	psm;  /* Protocol/Service Multiplexer */
 	uint16_t	scid; /* source channel ID */
 } __packed l2cap_con_req_cp;
 



CVS commit: src/sys/netbt

2014-11-16 Thread Iain Hibbert
Module Name:src
Committed By:   plunky
Date:   Sun Nov 16 21:34:27 UTC 2014

Modified Files:
src/sys/netbt: rfcomm_upper.c

Log Message:
since rfcomm_attach_pcb may be called from (soft) interrupt context
(for incoming connections), use kmem_intr_()


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/sys/netbt/rfcomm_upper.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/netbt/rfcomm_upper.c
diff -u src/sys/netbt/rfcomm_upper.c:1.21 src/sys/netbt/rfcomm_upper.c:1.22
--- src/sys/netbt/rfcomm_upper.c:1.21	Fri Aug  8 03:05:45 2014
+++ src/sys/netbt/rfcomm_upper.c	Sun Nov 16 21:34:27 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: rfcomm_upper.c,v 1.21 2014/08/08 03:05:45 rtr Exp $	*/
+/*	$NetBSD: rfcomm_upper.c,v 1.22 2014/11/16 21:34:27 plunky Exp $	*/
 
 /*-
  * Copyright (c) 2006 Itronix Inc.
@@ -32,7 +32,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: rfcomm_upper.c,v 1.21 2014/08/08 03:05:45 rtr Exp $);
+__KERNEL_RCSID(0, $NetBSD: rfcomm_upper.c,v 1.22 2014/11/16 21:34:27 plunky Exp $);
 
 #include sys/param.h
 #include sys/kernel.h
@@ -70,7 +70,9 @@ rfcomm_attach_pcb(struct rfcomm_dlc **ha
 	KASSERT(proto != NULL);
 	KASSERT(upper != NULL);
 
-	dlc = kmem_zalloc(sizeof(struct rfcomm_dlc), KM_SLEEP);
+	dlc = kmem_intr_zalloc(sizeof(struct rfcomm_dlc), KM_NOSLEEP);
+	if (dlc == NULL)
+		return ENOMEM;
 
 	dlc-rd_state = RFCOMM_DLC_CLOSED;
 	dlc-rd_mtu = rfcomm_mtu_default;
@@ -296,7 +298,7 @@ rfcomm_detach_pcb(struct rfcomm_dlc **ha
 		dlc-rd_flags |= RFCOMM_DLC_DETACH;
 	else {
 		callout_destroy(dlc-rd_timeout);
-		kmem_free(dlc, sizeof(*dlc));
+		kmem_intr_free(dlc, sizeof(*dlc));
 	}
 }
 



CVS commit: src/sys/netbt

2014-07-31 Thread Tyler R. Retzlaff
Module Name:src
Committed By:   rtr
Date:   Thu Jul 31 15:16:06 UTC 2014

Modified Files:
src/sys/netbt: rfcomm_socket.c

Log Message:
release mbuf on failure of PRU_SEND


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/sys/netbt/rfcomm_socket.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/netbt/rfcomm_socket.c
diff -u src/sys/netbt/rfcomm_socket.c:1.28 src/sys/netbt/rfcomm_socket.c:1.29
--- src/sys/netbt/rfcomm_socket.c:1.28	Thu Jul 31 03:39:35 2014
+++ src/sys/netbt/rfcomm_socket.c	Thu Jul 31 15:16:06 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: rfcomm_socket.c,v 1.28 2014/07/31 03:39:35 rtr Exp $	*/
+/*	$NetBSD: rfcomm_socket.c,v 1.29 2014/07/31 15:16:06 rtr Exp $	*/
 
 /*-
  * Copyright (c) 2006 Itronix Inc.
@@ -32,7 +32,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: rfcomm_socket.c,v 1.28 2014/07/31 03:39:35 rtr Exp $);
+__KERNEL_RCSID(0, $NetBSD: rfcomm_socket.c,v 1.29 2014/07/31 15:16:06 rtr Exp $);
 
 /* load symbolic names */
 #ifdef BLUETOOTH_DEBUG
@@ -360,8 +360,10 @@ rfcomm_usrreq(struct socket *up, int req
 			m_freem(ctl);
 
 		m0 = m_copypacket(m, M_DONTWAIT);
-		if (m0 == NULL)
-			return ENOMEM;
+		if (m0 == NULL) {
+			err = ENOMEM;
+			goto release;
+		}
 
 		sbappendstream(up-so_snd, m);
 



CVS commit: src/sys/netbt

2014-05-19 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Mon May 19 15:44:04 UTC 2014

Modified Files:
src/sys/netbt: rfcomm_socket.c sco_socket.c

Log Message:
Make it compile without options DIAGNOSTIC by removing a variable only set
once and only tested once in an assert.


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/sys/netbt/rfcomm_socket.c
cvs rdiff -u -r1.14 -r1.15 src/sys/netbt/sco_socket.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/netbt/rfcomm_socket.c
diff -u src/sys/netbt/rfcomm_socket.c:1.13 src/sys/netbt/rfcomm_socket.c:1.14
--- src/sys/netbt/rfcomm_socket.c:1.13	Mon May 19 02:51:24 2014
+++ src/sys/netbt/rfcomm_socket.c	Mon May 19 15:44:04 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: rfcomm_socket.c,v 1.13 2014/05/19 02:51:24 rmind Exp $	*/
+/*	$NetBSD: rfcomm_socket.c,v 1.14 2014/05/19 15:44:04 martin Exp $	*/
 
 /*-
  * Copyright (c) 2006 Itronix Inc.
@@ -32,7 +32,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: rfcomm_socket.c,v 1.13 2014/05/19 02:51:24 rmind Exp $);
+__KERNEL_RCSID(0, $NetBSD: rfcomm_socket.c,v 1.14 2014/05/19 15:44:04 martin Exp $);
 
 /* load symbolic names */
 #ifdef BLUETOOTH_DEBUG
@@ -119,9 +119,7 @@ rfcomm_attach1(struct socket *so, int pr
 static void
 rfcomm_detach1(struct socket *so)
 {
-	struct rfcomm_dlc *pcb = so-so_pcb;
-
-	KASSERT(pcb != NULL);
+	KASSERT(so-so_pcb != NULL);
 	rfcomm_detach((struct rfcomm_dlc **)so-so_pcb);
 	KASSERT(so-so_pcb == NULL);
 }

Index: src/sys/netbt/sco_socket.c
diff -u src/sys/netbt/sco_socket.c:1.14 src/sys/netbt/sco_socket.c:1.15
--- src/sys/netbt/sco_socket.c:1.14	Mon May 19 02:51:24 2014
+++ src/sys/netbt/sco_socket.c	Mon May 19 15:44:04 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: sco_socket.c,v 1.14 2014/05/19 02:51:24 rmind Exp $	*/
+/*	$NetBSD: sco_socket.c,v 1.15 2014/05/19 15:44:04 martin Exp $	*/
 
 /*-
  * Copyright (c) 2006 Itronix Inc.
@@ -30,7 +30,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: sco_socket.c,v 1.14 2014/05/19 02:51:24 rmind Exp $);
+__KERNEL_RCSID(0, $NetBSD: sco_socket.c,v 1.15 2014/05/19 15:44:04 martin Exp $);
 
 /* load symbolic names */
 #ifdef BLUETOOTH_DEBUG
@@ -102,9 +102,7 @@ sco_attach1(struct socket *so, int proto
 static void
 sco_detach1(struct socket *so)
 {
-	struct sco_pcb *pcb = (struct sco_pcb *)so-so_pcb;
-
-	KASSERT(pcb != NULL);
+	KASSERT(so-so_pcb != NULL);
 	sco_detach((struct sco_pcb **)so-so_pcb);
 	KASSERT(so-so_pcb == NULL);
 }



CVS commit: src/sys/netbt

2014-05-18 Thread Mindaugas Rasiukevicius
Module Name:src
Committed By:   rmind
Date:   Mon May 19 03:18:57 UTC 2014

Modified Files:
src/sys/netbt: l2cap_socket.c

Log Message:
l2cap_detach1: fix gcc warning for non-DIAGNOSTIC case.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/sys/netbt/l2cap_socket.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/netbt/l2cap_socket.c
diff -u src/sys/netbt/l2cap_socket.c:1.12 src/sys/netbt/l2cap_socket.c:1.13
--- src/sys/netbt/l2cap_socket.c:1.12	Mon May 19 02:51:24 2014
+++ src/sys/netbt/l2cap_socket.c	Mon May 19 03:18:57 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: l2cap_socket.c,v 1.12 2014/05/19 02:51:24 rmind Exp $	*/
+/*	$NetBSD: l2cap_socket.c,v 1.13 2014/05/19 03:18:57 rmind Exp $	*/
 
 /*-
  * Copyright (c) 2005 Iain Hibbert.
@@ -31,7 +31,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: l2cap_socket.c,v 1.12 2014/05/19 02:51:24 rmind Exp $);
+__KERNEL_RCSID(0, $NetBSD: l2cap_socket.c,v 1.13 2014/05/19 03:18:57 rmind Exp $);
 
 /* load symbolic names */
 #ifdef BLUETOOTH_DEBUG
@@ -111,9 +111,7 @@ l2cap_attach1(struct socket *so, int pro
 static void
 l2cap_detach1(struct socket *so)
 {
-	struct l2cap_channel *pcb = so-so_pcb;
-
-	KASSERT(pcb != NULL);
+	KASSERT(so-so_pcb != NULL);
 	l2cap_detach((struct l2cap_channel **)so-so_pcb);
 	KASSERT(so-so_pcb == NULL);
 }



CVS commit: src/sys/netbt

2013-02-08 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Feb  9 01:19:05 UTC 2013

Modified Files:
src/sys/netbt: l2cap_signal.c

Log Message:
CID/90001: missing va_end()


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/sys/netbt/l2cap_signal.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/netbt/l2cap_signal.c
diff -u src/sys/netbt/l2cap_signal.c:1.15 src/sys/netbt/l2cap_signal.c:1.16
--- src/sys/netbt/l2cap_signal.c:1.15	Tue Nov 29 08:16:27 2011
+++ src/sys/netbt/l2cap_signal.c	Fri Feb  8 20:19:05 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: l2cap_signal.c,v 1.15 2011/11/29 13:16:27 plunky Exp $	*/
+/*	$NetBSD: l2cap_signal.c,v 1.16 2013/02/09 01:19:05 christos Exp $	*/
 
 /*-
  * Copyright (c) 2005 Iain Hibbert.
@@ -31,7 +31,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: l2cap_signal.c,v 1.15 2011/11/29 13:16:27 plunky Exp $);
+__KERNEL_RCSID(0, $NetBSD: l2cap_signal.c,v 1.16 2013/02/09 01:19:05 christos Exp $);
 
 #include sys/param.h
 #include sys/kernel.h
@@ -1078,6 +1078,7 @@ l2cap_send_command_rej(struct hci_link *
 
 	default:
 		UNKNOWN(reason);
+		va_end(ap);
 		return EINVAL;
 	}
 



CVS commit: src/sys/netbt

2011-11-29 Thread Iain Hibbert
Module Name:src
Committed By:   plunky
Date:   Tue Nov 29 13:16:27 UTC 2011

Modified Files:
src/sys/netbt: l2cap_signal.c

Log Message:
Handle some ``Quality of Service'' configuration options, to
help devices requesting them blindly succeed in connecting.

should fix a problem analysed by Nat Sloss on current-users


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/sys/netbt/l2cap_signal.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/netbt/l2cap_signal.c
diff -u src/sys/netbt/l2cap_signal.c:1.14 src/sys/netbt/l2cap_signal.c:1.15
--- src/sys/netbt/l2cap_signal.c:1.14	Wed Jul 27 10:25:09 2011
+++ src/sys/netbt/l2cap_signal.c	Tue Nov 29 13:16:27 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: l2cap_signal.c,v 1.14 2011/07/27 10:25:09 plunky Exp $	*/
+/*	$NetBSD: l2cap_signal.c,v 1.15 2011/11/29 13:16:27 plunky Exp $	*/
 
 /*-
  * Copyright (c) 2005 Iain Hibbert.
@@ -31,7 +31,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: l2cap_signal.c,v 1.14 2011/07/27 10:25:09 plunky Exp $);
+__KERNEL_RCSID(0, $NetBSD: l2cap_signal.c,v 1.15 2011/11/29 13:16:27 plunky Exp $);
 
 #include sys/param.h
 #include sys/kernel.h
@@ -59,6 +59,8 @@ static void l2cap_recv_disconnect_rsp(st
 static void l2cap_recv_info_req(struct mbuf *, struct hci_link *);
 static int l2cap_send_signal(struct hci_link *, uint8_t, uint8_t, uint16_t, void *);
 static int l2cap_send_command_rej(struct hci_link *, uint8_t, uint16_t, ...);
+static void l2cap_qos_btoh(l2cap_qos_t *, void *);
+static void l2cap_qos_htob(void *, l2cap_qos_t *);
 
 /*
  * process incoming signal packets (CID 0x0001). Can contain multiple
@@ -518,6 +520,57 @@ l2cap_recv_config_req(struct mbuf *m, st
 			break;
 
 		case L2CAP_OPT_QOS:
+			if (rp.result == L2CAP_UNKNOWN_OPTION)
+break;
+
+			if (opt.length != L2CAP_OPT_QOS_SIZE)
+goto reject;
+
+			/*
+			 * We don't actually support QoS, but an incoming
+			 * config request is merely advising us of their
+			 * outgoing traffic flow, so be nice.
+			 */
+			m_copydata(m, 0, L2CAP_OPT_QOS_SIZE, val);
+			switch (val.qos.service_type) {
+			case L2CAP_QOS_NO_TRAFFIC:
+/*
+ * No traffic means they don't plan to send
+ * any data and the fields should be ignored.
+ */
+chan-lc_iqos = l2cap_default_qos;
+chan-lc_iqos.service_type = L2CAP_QOS_NO_TRAFFIC;
+break;
+
+			case L2CAP_QOS_BEST_EFFORT:
+/*
+ * Best effort is the default, and we may
+ * choose to ignore the fields, try to satisfy
+ * the parameters while giving no response, or
+ * respond with the settings we will try to
+ * meet.
+ */
+l2cap_qos_btoh(chan-lc_iqos, val.qos);
+break;
+
+			case L2CAP_QOS_GUARANTEED:
+			default:
+/*
+			 	 * Anything else we don't support, so make a
+ * counter-offer with the current settings.
+ */
+if (len + sizeof(opt) + L2CAP_OPT_QOS_SIZE  sizeof(buf))
+	goto reject;
+
+rp.result = L2CAP_UNACCEPTABLE_PARAMS;
+memcpy(buf + len, opt, sizeof(opt));
+len += sizeof(opt);
+l2cap_qos_htob(buf + len, chan-lc_iqos);
+len += L2CAP_OPT_QOS_SIZE;
+break;
+			}
+			break;
+
 		default:
 			/* ignore hints */
 			if (opt.type  L2CAP_OPT_HINT_BIT)
@@ -688,6 +741,27 @@ l2cap_recv_config_rsp(struct mbuf *m, st
 goto discon;
 
 			case L2CAP_OPT_QOS:
+if (opt.length != L2CAP_OPT_QOS_SIZE)
+	goto discon;
+
+/*
+ * This may happen even if we haven't sent a
+ * QoS request, where they need to state their
+ * preferred incoming traffic flow.
+ * We don't support anything, but copy in the
+ * parameters if no action is good enough.
+ */
+m_copydata(m, 0, L2CAP_OPT_QOS_SIZE, val);
+switch (val.qos.service_type) {
+case L2CAP_QOS_NO_TRAFFIC:
+case L2CAP_QOS_BEST_EFFORT:
+	l2cap_qos_btoh(chan-lc_oqos, val.qos);
+	break;
+
+case L2CAP_QOS_GUARANTEED:
+default:
+	goto discon;
+}
 break;
 
 			default:
@@ -1130,3 +1204,37 @@ l2cap_send_connect_rsp(struct hci_link *
 
 	return l2cap_send_signal(link, L2CAP_CONNECT_RSP, ident, sizeof(cp), cp);
 }
+
+/*
+ * copy in QoS buffer to host
+ */
+static void
+l2cap_qos_btoh(l2cap_qos_t *qos, void *buf)
+{
+	l2cap_qos_t *src = buf;
+
+	qos-flags = src-flags;
+	qos-service_type = src-service_type;
+	qos-token_rate = le32toh(src-token_rate);
+	qos-token_bucket_size = le32toh(src-token_bucket_size);
+	qos-peak_bandwidth = le32toh(src-peak_bandwidth);
+	qos-latency = le32toh(src-latency);
+	qos-delay_variation = le32toh(src-delay_variation);
+}
+
+/*
+ * copy out host QoS to buffer
+ */
+static void
+l2cap_qos_htob(void *buf, l2cap_qos_t *qos)
+{
+	l2cap_qos_t *dst = buf;
+
+	dst-flags = qos-flags;
+	dst-service_type = qos-service_type;
+	dst-token_rate = htole32(qos-token_rate);
+	dst-token_bucket_size = htole32(qos-token_bucket_size);
+	dst-peak_bandwidth = htole32(qos-peak_bandwidth);
+	

CVS commit: src/sys/netbt

2011-09-17 Thread Iain Hibbert
Module Name:src
Committed By:   plunky
Date:   Sat Sep 17 08:23:37 UTC 2011

Modified Files:
src/sys/netbt: hci.h hci_unit.c

Log Message:
const lookup argument


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/sys/netbt/hci.h
cvs rdiff -u -r1.12 -r1.13 src/sys/netbt/hci_unit.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/netbt/hci.h
diff -u src/sys/netbt/hci.h:1.34 src/sys/netbt/hci.h:1.35
--- src/sys/netbt/hci.h:1.34	Mon Nov 22 19:56:51 2010
+++ src/sys/netbt/hci.h	Sat Sep 17 08:23:36 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: hci.h,v 1.34 2010/11/22 19:56:51 plunky Exp $	*/
+/*	$NetBSD: hci.h,v 1.35 2011/09/17 08:23:36 plunky Exp $	*/
 
 /*-
  * Copyright (c) 2005 Iain Hibbert.
@@ -54,7 +54,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $Id: hci.h,v 1.34 2010/11/22 19:56:51 plunky Exp $
+ * $Id: hci.h,v 1.35 2011/09/17 08:23:36 plunky Exp $
  * $FreeBSD: src/sys/netgraph/bluetooth/include/ng_hci.h,v 1.6 2005/01/07 01:45:43 imp Exp $
  */
 
@@ -2576,7 +2576,7 @@
 void hci_detach(struct hci_unit *);
 int hci_enable(struct hci_unit *);
 void hci_disable(struct hci_unit *);
-struct hci_unit *hci_unit_lookup(bdaddr_t *);
+struct hci_unit *hci_unit_lookup(const bdaddr_t *);
 int hci_send_cmd(struct hci_unit *, uint16_t, void *, uint8_t);
 void hci_num_cmds(struct hci_unit *, uint8_t);
 bool hci_input_event(struct hci_unit *, struct mbuf *);

Index: src/sys/netbt/hci_unit.c
diff -u src/sys/netbt/hci_unit.c:1.12 src/sys/netbt/hci_unit.c:1.13
--- src/sys/netbt/hci_unit.c:1.12	Thu Jun 26 14:17:27 2008
+++ src/sys/netbt/hci_unit.c	Sat Sep 17 08:23:37 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: hci_unit.c,v 1.12 2008/06/26 14:17:27 plunky Exp $	*/
+/*	$NetBSD: hci_unit.c,v 1.13 2011/09/17 08:23:37 plunky Exp $	*/
 
 /*-
  * Copyright (c) 2005 Iain Hibbert.
@@ -31,7 +31,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: hci_unit.c,v 1.12 2008/06/26 14:17:27 plunky Exp $);
+__KERNEL_RCSID(0, $NetBSD: hci_unit.c,v 1.13 2011/09/17 08:23:37 plunky Exp $);
 
 #include sys/param.h
 #include sys/conf.h
@@ -266,7 +266,7 @@
 }
 
 struct hci_unit *
-hci_unit_lookup(bdaddr_t *addr)
+hci_unit_lookup(const bdaddr_t *addr)
 {
 	struct hci_unit *unit;
 



CVS commit: src/sys/netbt

2011-08-21 Thread Iain Hibbert
Module Name:src
Committed By:   plunky
Date:   Sun Aug 21 14:20:34 UTC 2011

Modified Files:
src/sys/netbt: rfcomm_dlc.c

Log Message:
fix comment typo


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/netbt/rfcomm_dlc.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/netbt/rfcomm_dlc.c
diff -u src/sys/netbt/rfcomm_dlc.c:1.6 src/sys/netbt/rfcomm_dlc.c:1.7
--- src/sys/netbt/rfcomm_dlc.c:1.6	Wed Aug  6 15:01:24 2008
+++ src/sys/netbt/rfcomm_dlc.c	Sun Aug 21 14:20:34 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: rfcomm_dlc.c,v 1.6 2008/08/06 15:01:24 plunky Exp $	*/
+/*	$NetBSD: rfcomm_dlc.c,v 1.7 2011/08/21 14:20:34 plunky Exp $	*/
 
 /*-
  * Copyright (c) 2006 Itronix Inc.
@@ -32,7 +32,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: rfcomm_dlc.c,v 1.6 2008/08/06 15:01:24 plunky Exp $);
+__KERNEL_RCSID(0, $NetBSD: rfcomm_dlc.c,v 1.7 2011/08/21 14:20:34 plunky Exp $);
 
 #include sys/param.h
 #include sys/kernel.h
@@ -187,7 +187,7 @@
 /*
  * rfcomm_dlc_timeout(dlc)
  *
- * DLC timeout function is schedUled when we sent any of SABM,
+ * DLC timeout function is scheduled when we sent any of SABM,
  * DISC, MCC_MSC, or MCC_PN and should be cancelled when we get
  * the relevant response. There is nothing to do but shut this
  * DLC down.



CVS commit: src/sys/netbt

2011-07-27 Thread Iain Hibbert
Module Name:src
Committed By:   plunky
Date:   Wed Jul 27 10:25:09 UTC 2011

Modified Files:
src/sys/netbt: hci_event.c hci_link.c l2cap_signal.c rfcomm_session.c

Log Message:
cleanup some DIAGNOSTIC and KASSERT code

- remove #ifdef DIAGNOSTIC, so that we won't act
  differently

- handle the cases where a Bluetooth adapter
  sends invalid packet data (I've not seen this,
  but it is not impossible)

- use KASSERT for actual impossible situations
  (to catch bad future development)


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/sys/netbt/hci_event.c src/sys/netbt/hci_link.c
cvs rdiff -u -r1.13 -r1.14 src/sys/netbt/l2cap_signal.c
cvs rdiff -u -r1.17 -r1.18 src/sys/netbt/rfcomm_session.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/netbt/hci_event.c
diff -u src/sys/netbt/hci_event.c:1.22 src/sys/netbt/hci_event.c:1.23
--- src/sys/netbt/hci_event.c:1.22	Mon Nov 22 19:56:51 2010
+++ src/sys/netbt/hci_event.c	Wed Jul 27 10:25:09 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: hci_event.c,v 1.22 2010/11/22 19:56:51 plunky Exp $	*/
+/*	$NetBSD: hci_event.c,v 1.23 2011/07/27 10:25:09 plunky Exp $	*/
 
 /*-
  * Copyright (c) 2005 Iain Hibbert.
@@ -31,7 +31,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: hci_event.c,v 1.22 2010/11/22 19:56:51 plunky Exp $);
+__KERNEL_RCSID(0, $NetBSD: hci_event.c,v 1.23 2011/07/27 10:25:09 plunky Exp $);
 
 #include sys/param.h
 #include sys/kernel.h
@@ -157,8 +157,7 @@
  * process HCI Events
  *
  * We will free the mbuf at the end, no need for any sub
- * functions to handle that. We kind of assume that the
- * device sends us valid events.
+ * functions to handle that.
  */
 void
 hci_event(struct mbuf *m, struct hci_unit *unit)
@@ -167,11 +166,15 @@
 
 	KASSERT(m-m_flags  M_PKTHDR);
 
-	KASSERT(m-m_pkthdr.len = sizeof(hdr));
+	if (m-m_pkthdr.len  sizeof(hdr))
+		goto done;
+
 	m_copydata(m, 0, sizeof(hdr), hdr);
 	m_adj(m, sizeof(hdr));
 
 	KASSERT(hdr.type == HCI_EVENT_PKT);
+	if (m-m_pkthdr.len != hdr.length)
+		goto done;
 
 	DPRINTFN(1, (%s) event %s\n,
 	device_xname(unit-hci_dev), hci_eventstr(hdr.event));
@@ -233,6 +236,7 @@
 		break;
 	}
 
+done:
 	m_freem(m);
 }
 
@@ -246,7 +250,9 @@
 {
 	hci_command_status_ep ep;
 
-	KASSERT(m-m_pkthdr.len = sizeof(ep));
+	if (m-m_pkthdr.len  sizeof(ep))
+		return;
+
 	m_copydata(m, 0, sizeof(ep), ep);
 	m_adj(m, sizeof(ep));
 
@@ -292,7 +298,9 @@
 	hci_command_compl_ep ep;
 	hci_status_rp rp;
 
-	KASSERT(m-m_pkthdr.len = sizeof(ep));
+	if (m-m_pkthdr.len  sizeof(ep))
+		return;
+
 	m_copydata(m, 0, sizeof(ep), ep);
 	m_adj(m, sizeof(ep));
 
@@ -369,7 +377,9 @@
 	uint16_t handle, num;
 	int num_acl = 0, num_sco = 0;
 
-	KASSERT(m-m_pkthdr.len = sizeof(ep));
+	if (m-m_pkthdr.len  sizeof(ep))
+		return;
+
 	m_copydata(m, 0, sizeof(ep), ep);
 	m_adj(m, sizeof(ep));
 
@@ -439,7 +449,9 @@
 	hci_inquiry_response ir;
 	struct hci_memo *memo;
 
-	KASSERT(m-m_pkthdr.len = sizeof(ep));
+	if (m-m_pkthdr.len  sizeof(ep))
+		return;
+
 	m_copydata(m, 0, sizeof(ep), ep);
 	m_adj(m, sizeof(ep));
 
@@ -447,7 +459,9 @@
 (ep.num_responses == 1 ?  : s));
 
 	while(ep.num_responses--) {
-		KASSERT(m-m_pkthdr.len = sizeof(ir));
+		if (m-m_pkthdr.len  sizeof(ir))
+			return;
+
 		m_copydata(m, 0, sizeof(ir), ir);
 		m_adj(m, sizeof(ir));
 
@@ -476,7 +490,9 @@
 	hci_rssi_response rr;
 	struct hci_memo *memo;
 
-	KASSERT(m-m_pkthdr.len = sizeof(ep));
+	if (m-m_pkthdr.len  sizeof(ep))
+		return;
+
 	m_copydata(m, 0, sizeof(ep), ep);
 	m_adj(m, sizeof(ep));
 
@@ -484,7 +500,9 @@
 (ep.num_responses == 1 ?  : s));
 
 	while(ep.num_responses--) {
-		KASSERT(m-m_pkthdr.len = sizeof(rr));
+		if (m-m_pkthdr.len  sizeof(rr))
+			return;
+
 		m_copydata(m, 0, sizeof(rr), rr);
 		m_adj(m, sizeof(rr));
 
@@ -512,7 +530,9 @@
 	hci_extended_result_ep ep;
 	struct hci_memo *memo;
 
-	KASSERT(m-m_pkthdr.len = sizeof(ep));
+	if (m-m_pkthdr.len  sizeof(ep))
+		return;
+
 	m_copydata(m, 0, sizeof(ep), ep);
 	m_adj(m, sizeof(ep));
 
@@ -546,7 +566,9 @@
 	struct hci_link *link;
 	int err;
 
-	KASSERT(m-m_pkthdr.len = sizeof(ep));
+	if (m-m_pkthdr.len  sizeof(ep))
+		return;
+
 	m_copydata(m, 0, sizeof(ep), ep);
 	m_adj(m, sizeof(ep));
 
@@ -641,7 +663,9 @@
 	hci_discon_compl_ep ep;
 	struct hci_link *link;
 
-	KASSERT(m-m_pkthdr.len = sizeof(ep));
+	if (m-m_pkthdr.len  sizeof(ep))
+		return;
+
 	m_copydata(m, 0, sizeof(ep), ep);
 	m_adj(m, sizeof(ep));
 
@@ -668,7 +692,9 @@
 	hci_reject_con_cp rp;
 	struct hci_link *link;
 
-	KASSERT(m-m_pkthdr.len = sizeof(ep));
+	if (m-m_pkthdr.len  sizeof(ep))
+		return;
+
 	m_copydata(m, 0, sizeof(ep), ep);
 	m_adj(m, sizeof(ep));
 
@@ -715,7 +741,9 @@
 	struct hci_link *link;
 	int err;
 
-	KASSERT(m-m_pkthdr.len = sizeof(ep));
+	if (m-m_pkthdr.len  sizeof(ep))
+		return;
+
 	m_copydata(m, 0, sizeof(ep), ep);
 	m_adj(m, sizeof(ep));
 
@@ -757,7 +785,9 @@
 	struct hci_link *link;
 	int 

CVS commit: src/sys/netbt

2011-03-16 Thread Iain Hibbert
Module Name:src
Committed By:   plunky
Date:   Wed Mar 16 21:35:30 UTC 2011

Modified Files:
src/sys/netbt: bluetooth.h

Log Message:
use C99 style for variadic macro arguments


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/netbt/bluetooth.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/netbt/bluetooth.h
diff -u src/sys/netbt/bluetooth.h:1.9 src/sys/netbt/bluetooth.h:1.10
--- src/sys/netbt/bluetooth.h:1.9	Fri Mar 26 18:15:15 2010
+++ src/sys/netbt/bluetooth.h	Wed Mar 16 21:35:30 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: bluetooth.h,v 1.9 2010/03/26 18:15:15 pooka Exp $	*/
+/*	$NetBSD: bluetooth.h,v 1.10 2011/03/16 21:35:30 plunky Exp $	*/
 
 /*-
  * Copyright (c) 2005 Iain Hibbert.
@@ -124,14 +124,18 @@
  */
 #ifdef BLUETOOTH_DEBUG
 extern int bluetooth_debug;
-# define DPRINTF(fmt, args...)	do {			\
-	if (bluetooth_debug)\
-		printf(%s: fmt, __func__ , ##args);	\
+# define DPRINTF(...)	do {			\
+	if (bluetooth_debug) {			\
+		printf(%s: , __func__);	\
+		printf(__VA_ARGS__);		\
+	}	\
 } while (/* CONSTCOND */0)
 
-# define DPRINTFN(n, fmt, args...)	do {		\
-	if (bluetooth_debug  (n))			\
-		printf(%s: fmt, __func__ , ##args);	\
+# define DPRINTFN(n, ...)	do {		\
+	if (bluetooth_debug  (n)) {		\
+		printf(%s: , __func__);	\
+		printf(__VA_ARGS__);		\
+	}	\
 } while (/* CONSTCOND */0)
 
 # define UNKNOWN(value)			\



CVS commit: src/sys/netbt

2011-02-06 Thread Iain Hibbert
Module Name:src
Committed By:   plunky
Date:   Sun Feb  6 18:51:00 UTC 2011

Modified Files:
src/sys/netbt: l2cap.h l2cap_signal.c

Log Message:
respond to L2CAP Information requests


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/netbt/l2cap.h
cvs rdiff -u -r1.11 -r1.12 src/sys/netbt/l2cap_signal.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/netbt/l2cap.h
diff -u src/sys/netbt/l2cap.h:1.9 src/sys/netbt/l2cap.h:1.10
--- src/sys/netbt/l2cap.h:1.9	Sun Sep 13 18:45:11 2009
+++ src/sys/netbt/l2cap.h	Sun Feb  6 18:50:59 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: l2cap.h,v 1.9 2009/09/13 18:45:11 pooka Exp $	*/
+/*	$NetBSD: l2cap.h,v 1.10 2011/02/06 18:50:59 plunky Exp $	*/
 
 /*-
  * Copyright (c) 2005 Iain Hibbert.
@@ -54,7 +54,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $Id: l2cap.h,v 1.9 2009/09/13 18:45:11 pooka Exp $
+ * $Id: l2cap.h,v 1.10 2011/02/06 18:50:59 plunky Exp $
  * $FreeBSD: src/sys/netgraph/bluetooth/include/l2cap.h,v 1.4 2005/08/31 18:13:23 emax Exp $
  */
 
@@ -166,7 +166,8 @@
 /* L2CAP Information request type codes */
 #define L2CAP_CONNLESS_MTU		0x0001
 #define L2CAP_EXTENDED_FEATURES		0x0002
-/* 0x0003 - 0x - reserved for future use */
+#define L2CAP_FIXED_CHANNELS		0x0003
+/* 0x0004 - 0x - reserved for future use */
 
 /* L2CAP Information response codes */
 #define L2CAP_NOT_SUPPORTED		0x0001
@@ -320,17 +321,9 @@
 	uint16_t	type;   /* requested information type */
 	uint16_t	result; /* 0x00 - success */
 /*	uint8_t	info[]  -- info data (depends on type)
- *
- * L2CAP_CONNLESS_MTU - 2 bytes connectionless MTU
  */
 } __packed l2cap_info_rsp_cp;
 
-typedef union {
-	/* L2CAP_CONNLESS_MTU */
-	struct {
-		uint16_t	mtu;
-	} __packed mtu;
-} l2cap_info_rsp_data_t;
 
 /**
  **

Index: src/sys/netbt/l2cap_signal.c
diff -u src/sys/netbt/l2cap_signal.c:1.11 src/sys/netbt/l2cap_signal.c:1.12
--- src/sys/netbt/l2cap_signal.c:1.11	Wed Nov 17 20:19:25 2010
+++ src/sys/netbt/l2cap_signal.c	Sun Feb  6 18:51:00 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: l2cap_signal.c,v 1.11 2010/11/17 20:19:25 plunky Exp $	*/
+/*	$NetBSD: l2cap_signal.c,v 1.12 2011/02/06 18:51:00 plunky Exp $	*/
 
 /*-
  * Copyright (c) 2005 Iain Hibbert.
@@ -31,7 +31,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: l2cap_signal.c,v 1.11 2010/11/17 20:19:25 plunky Exp $);
+__KERNEL_RCSID(0, $NetBSD: l2cap_signal.c,v 1.12 2011/02/06 18:51:00 plunky Exp $);
 
 #include sys/param.h
 #include sys/kernel.h
@@ -857,15 +857,14 @@
 }
 
 /*
- * Process Received Info Request. We must respond but alas dont
- * support anything as yet so thats easy.
+ * Process Received Info Request.
  */
 static void
 l2cap_recv_info_req(struct mbuf *m, struct hci_link *link)
 {
 	l2cap_cmd_hdr_t cmd;
 	l2cap_info_req_cp cp;
-	l2cap_info_rsp_cp rp;
+	uint8_t rsp[12];
 
 	m_copydata(m, 0, sizeof(cmd), cmd);
 	m_adj(m, sizeof(cmd));
@@ -873,15 +872,51 @@
 	m_copydata(m, 0, sizeof(cp), cp);
 	m_adj(m, sizeof(cp));
 
-	switch(le16toh(cp.type)) {
-	case L2CAP_CONNLESS_MTU:
+	cp.type = le16toh(cp.type);
+	switch(cp.type) {
 	case L2CAP_EXTENDED_FEATURES:
-	default:
-		rp.type = cp.type;
-		rp.result = htole16(L2CAP_NOT_SUPPORTED);
+		/*
+		 * 32-bit data field, unused bits set to zero
+		 *
+		 * octet bit feature
+		 *   0   0   Flow control mode
+		 *   0   1   Retransmission mode
+		 *   0   2   Bi-directional QoS
+		 *   0   3   Enhanced retransmission mode
+		 *   0   4   Streaming mode
+		 *   0   5   FCS option
+		 *   0   6   Extended flow specification for BR/EDR
+		 *   0   7   Fixed channels (SET)
+		 *   1   0   Extended window size
+		 *   1   1   Unicast connectionless data reception
+		 */
+		le16enc(rsp + 0, cp.type);
+		le16enc(rsp + 2, L2CAP_SUCCESS);
+		le32enc(rsp + 4, 0x0080);
+		l2cap_send_signal(link, L2CAP_INFO_RSP, cmd.ident, 8, rsp);
+		break;
 
-		l2cap_send_signal(link, L2CAP_INFO_RSP, cmd.ident,
-	sizeof(rp), rp);
+	case L2CAP_FIXED_CHANNELS:
+		/*
+		 * 64-bit data field, unused bits set to zero
+		 *
+		 * octet bit channel
+		 *   0   0   0x Null
+		 *   0   1   0x0001 L2CAP Signalling Channel (SET)
+		 *   0   2   0x0002 Connectionless Reception
+		 *   0   3   0x0003 AMP Manager Protocol Channel
+		 */
+		le16enc(rsp + 0, cp.type);
+		le16enc(rsp + 2, L2CAP_SUCCESS);
+		le64enc(rsp + 4, 0x0002);
+		l2cap_send_signal(link, L2CAP_INFO_RSP, cmd.ident, 12, rsp);
+		break;
+
+	case L2CAP_CONNLESS_MTU:
+	default:
+		le16enc(rsp + 0, cp.type);
+		le16enc(rsp + 2, L2CAP_NOT_SUPPORTED);
+		l2cap_send_signal(link, L2CAP_INFO_RSP, cmd.ident, 4, rsp);
 		break;
 	}
 }



CVS commit: src/sys/netbt

2011-01-30 Thread Iain Hibbert
Module Name:src
Committed By:   plunky
Date:   Sun Jan 30 17:23:23 UTC 2011

Modified Files:
src/sys/netbt: hci_socket.c

Log Message:
add (SOL_SOCKET, SO_TIMESTAMP) messages if requested


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/sys/netbt/hci_socket.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/netbt/hci_socket.c
diff -u src/sys/netbt/hci_socket.c:1.19 src/sys/netbt/hci_socket.c:1.20
--- src/sys/netbt/hci_socket.c:1.19	Mon Aug 10 20:22:06 2009
+++ src/sys/netbt/hci_socket.c	Sun Jan 30 17:23:23 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: hci_socket.c,v 1.19 2009/08/10 20:22:06 plunky Exp $	*/
+/*	$NetBSD: hci_socket.c,v 1.20 2011/01/30 17:23:23 plunky Exp $	*/
 
 /*-
  * Copyright (c) 2005 Iain Hibbert.
@@ -31,7 +31,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: hci_socket.c,v 1.19 2009/08/10 20:22:06 plunky Exp $);
+__KERNEL_RCSID(0, $NetBSD: hci_socket.c,v 1.20 2011/01/30 17:23:23 plunky Exp $);
 
 /* load symbolic names */
 #ifdef BLUETOOTH_DEBUG
@@ -825,6 +825,16 @@
 			if (*ctl != NULL)
 ctl = ((*ctl)-m_next);
 		}
+		if (pcb-hp_socket-so_options  SO_TIMESTAMP) {
+			struct timeval tv;
+
+			microtime(tv);
+			*ctl = sbcreatecontrol(tv, sizeof(tv),
+			SCM_TIMESTAMP, SOL_SOCKET);
+
+			if (*ctl != NULL)
+ctl = ((*ctl)-m_next);
+		}
 
 		/*
 		 * copy to socket



CVS commit: src/sys/netbt

2010-11-22 Thread Iain Hibbert
Module Name:src
Committed By:   plunky
Date:   Mon Nov 22 19:56:52 UTC 2010

Modified Files:
src/sys/netbt: hci.h hci_event.c hci_ioctl.c

Log Message:
upon device initialisation, query and cache the device features,
and cache the maximum ACL/SCO packet buffers.

provide an additional SIOCGBTFEAT ioctl to retrieve the cached
features, and add the max values to the SIOC?BTINFO results.

(btreq does not change size)


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 src/sys/netbt/hci.h
cvs rdiff -u -r1.21 -r1.22 src/sys/netbt/hci_event.c
cvs rdiff -u -r1.9 -r1.10 src/sys/netbt/hci_ioctl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/netbt/hci.h
diff -u src/sys/netbt/hci.h:1.33 src/sys/netbt/hci.h:1.34
--- src/sys/netbt/hci.h:1.33	Fri Sep 11 18:35:50 2009
+++ src/sys/netbt/hci.h	Mon Nov 22 19:56:51 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: hci.h,v 1.33 2009/09/11 18:35:50 plunky Exp $	*/
+/*	$NetBSD: hci.h,v 1.34 2010/11/22 19:56:51 plunky Exp $	*/
 
 /*-
  * Copyright (c) 2005 Iain Hibbert.
@@ -54,7 +54,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $Id: hci.h,v 1.33 2009/09/11 18:35:50 plunky Exp $
+ * $Id: hci.h,v 1.34 2010/11/22 19:56:51 plunky Exp $
  * $FreeBSD: src/sys/netgraph/bluetooth/include/ng_hci.h,v 1.6 2005/01/07 01:45:43 imp Exp $
  */
 
@@ -2297,6 +2297,8 @@
 #define SIOCBTDUMP	 _IOW('b', 13, struct btreq) /* print debug info */
 #define SIOCSBTSCOMTU	_IOWR('b', 17, struct btreq) /* set sco_mtu value */
 
+#define SIOCGBTFEAT	_IOWR('b', 18, struct btreq) /* get unit features */
+
 struct bt_stats {
 	uint32_t	err_tx;
 	uint32_t	err_rx;
@@ -2324,7 +2326,13 @@
 		uint16_t btri_sco_mtu;		/* SCO mtu */
 		uint16_t btri_link_policy;	/* Link Policy */
 		uint16_t btri_packet_type;	/* Packet Type */
+		uint16_t btri_max_acl;		/* max ACL buffers */
+		uint16_t btri_max_sco;		/* max SCO buffers */
 	} btri;
+	struct {
+		uint8_t btrf_page0[HCI_FEATURES_SIZE];	/* basic */
+		uint8_t btrf_page1[HCI_FEATURES_SIZE];	/* extended */
+	} btrf;
 	struct bt_stats btrs;   /* unit stats */
 	} btru;
 };
@@ -2338,6 +2346,10 @@
 #define btr_sco_mtu	btru.btri.btri_sco_mtu
 #define btr_link_policy btru.btri.btri_link_policy
 #define btr_packet_type btru.btri.btri_packet_type
+#define btr_max_acl	btru.btri.btri_max_acl
+#define btr_max_sco	btru.btri.btri_max_sco
+#define btr_features0	btru.btrf.btrf_page0
+#define btr_features1	btru.btrf.btrf_page1
 #define btr_stats	btru.btrs
 
 /* hci_unit  btr_flags */
@@ -2481,14 +2493,18 @@
 	uint16_t	 hci_link_policy;	/* link policy */
 	uint16_t	 hci_lmp_mask;		/* link policy capabilities */
 
+	uint8_t		 hci_feat0[HCI_FEATURES_SIZE]; /* features mask */
+	uint8_t		 hci_feat1[HCI_FEATURES_SIZE]; /* extended */
 	uint8_t		 hci_cmds[HCI_COMMANDS_SIZE]; /* opcode bitmask */
 
 	/* flow control */
 	uint16_t	 hci_max_acl_size;	/* ACL payload mtu */
 	uint16_t	 hci_num_acl_pkts;	/* free ACL packet buffers */
+	uint16_t	 hci_max_acl_pkts;	/* max ACL packet buffers */
 	uint8_t		 hci_num_cmd_pkts;	/* free CMD packet buffers */
 	uint8_t		 hci_max_sco_size;	/* SCO payload mtu */
 	uint16_t	 hci_num_sco_pkts;	/* free SCO packet buffers */
+	uint16_t	 hci_max_sco_pkts;	/* max SCO packet buffers */
 
 	TAILQ_HEAD(,hci_link)	hci_links;	/* list of ACL/SCO links */
 	LIST_HEAD(,hci_memo)	hci_memos;	/* cached memo list */

Index: src/sys/netbt/hci_event.c
diff -u src/sys/netbt/hci_event.c:1.21 src/sys/netbt/hci_event.c:1.22
--- src/sys/netbt/hci_event.c:1.21	Sat Sep 12 18:31:46 2009
+++ src/sys/netbt/hci_event.c	Mon Nov 22 19:56:51 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: hci_event.c,v 1.21 2009/09/12 18:31:46 plunky Exp $	*/
+/*	$NetBSD: hci_event.c,v 1.22 2010/11/22 19:56:51 plunky Exp $	*/
 
 /*-
  * Copyright (c) 2005 Iain Hibbert.
@@ -31,7 +31,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: hci_event.c,v 1.21 2009/09/12 18:31:46 plunky Exp $);
+__KERNEL_RCSID(0, $NetBSD: hci_event.c,v 1.22 2010/11/22 19:56:51 plunky Exp $);
 
 #include sys/param.h
 #include sys/kernel.h
@@ -60,6 +60,7 @@
 static void hci_cmd_read_bdaddr(struct hci_unit *, struct mbuf *);
 static void hci_cmd_read_buffer_size(struct hci_unit *, struct mbuf *);
 static void hci_cmd_read_local_features(struct hci_unit *, struct mbuf *);
+static void hci_cmd_read_local_extended_features(struct hci_unit *, struct mbuf *);
 static void hci_cmd_read_local_ver(struct hci_unit *, struct mbuf *);
 static void hci_cmd_read_local_commands(struct hci_unit *, struct mbuf *);
 static void hci_cmd_reset(struct hci_unit *, struct mbuf *);
@@ -330,6 +331,10 @@
 		hci_cmd_read_local_features(unit, m);
 		break;
 
+	case HCI_CMD_READ_LOCAL_EXTENDED_FEATURES:
+		hci_cmd_read_local_extended_features(unit, m);
+		break;
+
 	case HCI_CMD_READ_LOCAL_VER:
 		hci_cmd_read_local_ver(unit, m);
 		break;
@@ -897,8 +902,10 @@
 
 	

CVS commit: src/sys/netbt

2010-11-17 Thread Iain Hibbert
Module Name:src
Committed By:   plunky
Date:   Wed Nov 17 20:19:25 UTC 2010

Modified Files:
src/sys/netbt: l2cap_signal.c rfcomm_session.c

Log Message:
do not produce an error when connections are closed normally

for L2CAP sockets, this solves an irritating error message from sdpd(8),
which can now differentiate between normal closure and error.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/netbt/l2cap_signal.c
cvs rdiff -u -r1.16 -r1.17 src/sys/netbt/rfcomm_session.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/netbt/l2cap_signal.c
diff -u src/sys/netbt/l2cap_signal.c:1.10 src/sys/netbt/l2cap_signal.c:1.11
--- src/sys/netbt/l2cap_signal.c:1.10	Fri Sep 25 19:44:57 2009
+++ src/sys/netbt/l2cap_signal.c	Wed Nov 17 20:19:25 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: l2cap_signal.c,v 1.10 2009/09/25 19:44:57 plunky Exp $	*/
+/*	$NetBSD: l2cap_signal.c,v 1.11 2010/11/17 20:19:25 plunky Exp $	*/
 
 /*-
  * Copyright (c) 2005 Iain Hibbert.
@@ -31,7 +31,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: l2cap_signal.c,v 1.10 2009/09/25 19:44:57 plunky Exp $);
+__KERNEL_RCSID(0, $NetBSD: l2cap_signal.c,v 1.11 2010/11/17 20:19:25 plunky Exp $);
 
 #include sys/param.h
 #include sys/kernel.h
@@ -814,7 +814,7 @@
 sizeof(rp), rp);
 
 	if (chan-lc_state != L2CAP_CLOSED)
-		l2cap_close(chan, ECONNRESET);
+		l2cap_close(chan, 0);
 }
 
 /*

Index: src/sys/netbt/rfcomm_session.c
diff -u src/sys/netbt/rfcomm_session.c:1.16 src/sys/netbt/rfcomm_session.c:1.17
--- src/sys/netbt/rfcomm_session.c:1.16	Sun Jan  3 16:38:15 2010
+++ src/sys/netbt/rfcomm_session.c	Wed Nov 17 20:19:25 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: rfcomm_session.c,v 1.16 2010/01/03 16:38:15 plunky Exp $	*/
+/*	$NetBSD: rfcomm_session.c,v 1.17 2010/11/17 20:19:25 plunky Exp $	*/
 
 /*-
  * Copyright (c) 2006 Itronix Inc.
@@ -32,7 +32,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: rfcomm_session.c,v 1.16 2010/01/03 16:38:15 plunky Exp $);
+__KERNEL_RCSID(0, $NetBSD: rfcomm_session.c,v 1.17 2010/11/17 20:19:25 plunky Exp $);
 
 #include sys/param.h
 #include sys/kernel.h
@@ -389,6 +389,13 @@
 
 	DPRINTF(Disconnected\n);
 
+	/*
+	 * If we have any DLCs outstanding in the unlikely case that the
+	 * L2CAP channel disconnected normally, close them with an error
+	 */
+	if (err == 0)
+		err = ECONNRESET;
+
 	rs-rs_state = RFCOMM_SESSION_CLOSED;
 
 	while (!LIST_EMPTY(rs-rs_dlcs)) {
@@ -816,7 +823,7 @@
 		return;
 	}
 
-	rfcomm_dlc_close(dlc, ECONNRESET);
+	rfcomm_dlc_close(dlc, 0);
 	rfcomm_session_send_frame(rs, RFCOMM_FRAME_UA, dlci);
 }
 



CVS commit: src/sys/netbt

2010-10-14 Thread Iain Hibbert
Module Name:src
Committed By:   plunky
Date:   Thu Oct 14 07:05:03 UTC 2010

Modified Files:
src/sys/netbt: hci_link.c

Log Message:
Some Broadcom controllers emit empty ACL packets during connection
setup, using the handle that they have not yet told us for the
connection-to-be. Disconnecting can cause problems so just ignore
zero length ACL packets on unknown connection handles.

fixes a problem reported by Nick Hudson


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/sys/netbt/hci_link.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/netbt/hci_link.c
diff -u src/sys/netbt/hci_link.c:1.21 src/sys/netbt/hci_link.c:1.22
--- src/sys/netbt/hci_link.c:1.21	Thu Sep 24 19:35:09 2009
+++ src/sys/netbt/hci_link.c	Thu Oct 14 07:05:03 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: hci_link.c,v 1.21 2009/09/24 19:35:09 plunky Exp $	*/
+/*	$NetBSD: hci_link.c,v 1.22 2010/10/14 07:05:03 plunky Exp $	*/
 
 /*-
  * Copyright (c) 2005 Iain Hibbert.
@@ -31,7 +31,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: hci_link.c,v 1.21 2009/09/24 19:35:09 plunky Exp $);
+__KERNEL_RCSID(0, $NetBSD: hci_link.c,v 1.22 2010/10/14 07:05:03 plunky Exp $);
 
 #include sys/param.h
 #include sys/kernel.h
@@ -467,10 +467,16 @@
 		 * for, just get rid of it. This may happen, if a USB dongle
 		 * is plugged into a self powered hub and does not reset when
 		 * the system is shut down.
+		 *
+		 * This can cause a problem with some Broadcom controllers
+		 * which emit empty ACL packets during connection setup, so
+		 * only disconnect where data is present.
 		 */
-		cp.con_handle = htole16(handle);
-		cp.reason = 0x13; /* Remote User Terminated Connection */
-		hci_send_cmd(unit, HCI_CMD_DISCONNECT, cp, sizeof(cp));
+		if (hdr.length  0) {
+			cp.con_handle = htole16(handle);
+			cp.reason = 0x13;/*Remote User Terminated Connection*/
+			hci_send_cmd(unit, HCI_CMD_DISCONNECT, cp, sizeof(cp));
+		}
 		goto bad;
 	}
 



CVS commit: src/sys/netbt

2010-01-04 Thread Iain Hibbert
Module Name:src
Committed By:   plunky
Date:   Mon Jan  4 19:20:05 UTC 2010

Modified Files:
src/sys/netbt: l2cap_upper.c rfcomm_upper.c sco_upper.c

Log Message:
prevent local socket address from being changed after socket is
in use (connect or listen)


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/netbt/l2cap_upper.c
cvs rdiff -u -r1.12 -r1.13 src/sys/netbt/rfcomm_upper.c
cvs rdiff -u -r1.8 -r1.9 src/sys/netbt/sco_upper.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/netbt/l2cap_upper.c
diff -u src/sys/netbt/l2cap_upper.c:1.10 src/sys/netbt/l2cap_upper.c:1.11
--- src/sys/netbt/l2cap_upper.c:1.10	Fri Sep 25 19:44:57 2009
+++ src/sys/netbt/l2cap_upper.c	Mon Jan  4 19:20:05 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: l2cap_upper.c,v 1.10 2009/09/25 19:44:57 plunky Exp $	*/
+/*	$NetBSD: l2cap_upper.c,v 1.11 2010/01/04 19:20:05 plunky Exp $	*/
 
 /*-
  * Copyright (c) 2005 Iain Hibbert.
@@ -31,7 +31,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: l2cap_upper.c,v 1.10 2009/09/25 19:44:57 plunky Exp $);
+__KERNEL_RCSID(0, $NetBSD: l2cap_upper.c,v 1.11 2010/01/04 19:20:05 plunky Exp $);
 
 #include sys/param.h
 #include sys/kernel.h
@@ -110,6 +110,9 @@
 l2cap_bind(struct l2cap_channel *chan, struct sockaddr_bt *addr)
 {
 
+	if (chan-lc_lcid != L2CAP_NULL_CID)
+		return EINVAL;
+
 	memcpy(chan-lc_laddr, addr, sizeof(struct sockaddr_bt));
 	return 0;
 }

Index: src/sys/netbt/rfcomm_upper.c
diff -u src/sys/netbt/rfcomm_upper.c:1.12 src/sys/netbt/rfcomm_upper.c:1.13
--- src/sys/netbt/rfcomm_upper.c:1.12	Sun Nov 22 19:09:16 2009
+++ src/sys/netbt/rfcomm_upper.c	Mon Jan  4 19:20:05 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: rfcomm_upper.c,v 1.12 2009/11/22 19:09:16 mbalmer Exp $	*/
+/*	$NetBSD: rfcomm_upper.c,v 1.13 2010/01/04 19:20:05 plunky Exp $	*/
 
 /*-
  * Copyright (c) 2006 Itronix Inc.
@@ -32,7 +32,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: rfcomm_upper.c,v 1.12 2009/11/22 19:09:16 mbalmer Exp $);
+__KERNEL_RCSID(0, $NetBSD: rfcomm_upper.c,v 1.13 2010/01/04 19:20:05 plunky Exp $);
 
 #include sys/param.h
 #include sys/kernel.h
@@ -106,6 +106,9 @@
 rfcomm_bind(struct rfcomm_dlc *dlc, struct sockaddr_bt *addr)
 {
 
+	if (dlc-rd_state != RFCOMM_DLC_CLOSED)
+		return EINVAL;
+
 	memcpy(dlc-rd_laddr, addr, sizeof(struct sockaddr_bt));
 	return 0;
 }

Index: src/sys/netbt/sco_upper.c
diff -u src/sys/netbt/sco_upper.c:1.8 src/sys/netbt/sco_upper.c:1.9
--- src/sys/netbt/sco_upper.c:1.8	Wed Aug  6 15:01:24 2008
+++ src/sys/netbt/sco_upper.c	Mon Jan  4 19:20:05 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: sco_upper.c,v 1.8 2008/08/06 15:01:24 plunky Exp $	*/
+/*	$NetBSD: sco_upper.c,v 1.9 2010/01/04 19:20:05 plunky Exp $	*/
 
 /*-
  * Copyright (c) 2006 Itronix Inc.
@@ -32,7 +32,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: sco_upper.c,v 1.8 2008/08/06 15:01:24 plunky Exp $);
+__KERNEL_RCSID(0, $NetBSD: sco_upper.c,v 1.9 2010/01/04 19:20:05 plunky Exp $);
 
 #include sys/param.h
 #include sys/kernel.h
@@ -90,6 +90,9 @@
 sco_bind(struct sco_pcb *pcb, struct sockaddr_bt *addr)
 {
 
+	if (pcb-sp_link != NULL || pcb-sp_flags  SP_LISTENING)
+		return EINVAL;
+
 	bdaddr_copy(pcb-sp_laddr, addr-bt_bdaddr);
 	return 0;
 }



CVS commit: src/sys/netbt

2010-01-03 Thread Iain Hibbert
Module Name:src
Committed By:   plunky
Date:   Sun Jan  3 16:38:15 UTC 2010

Modified Files:
src/sys/netbt: rfcomm_session.c

Log Message:
when receiving a MCC PN response, the max frame size that the remote
party requests must be less than the one we asked for which will not
be greater than the max acceptable value so no need to test for that
but make sure that it is not smaller than minimum acceptable value.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/sys/netbt/rfcomm_session.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/netbt/rfcomm_session.c
diff -u src/sys/netbt/rfcomm_session.c:1.15 src/sys/netbt/rfcomm_session.c:1.16
--- src/sys/netbt/rfcomm_session.c:1.15	Sun Sep 13 18:45:11 2009
+++ src/sys/netbt/rfcomm_session.c	Sun Jan  3 16:38:15 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: rfcomm_session.c,v 1.15 2009/09/13 18:45:11 pooka Exp $	*/
+/*	$NetBSD: rfcomm_session.c,v 1.16 2010/01/03 16:38:15 plunky Exp $	*/
 
 /*-
  * Copyright (c) 2006 Itronix Inc.
@@ -32,7 +32,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: rfcomm_session.c,v 1.15 2009/09/13 18:45:11 pooka Exp $);
+__KERNEL_RCSID(0, $NetBSD: rfcomm_session.c,v 1.16 2010/01/03 16:38:15 plunky Exp $);
 
 #include sys/param.h
 #include sys/kernel.h
@@ -1372,7 +1372,8 @@
 
 		callout_stop(dlc-rd_timeout);
 
-		if (pn.mtu  RFCOMM_MTU_MAX || pn.mtu  dlc-rd_mtu) {
+		/* reject invalid or unacceptable MTU */
+		if (pn.mtu  RFCOMM_MTU_MIN || pn.mtu  dlc-rd_mtu) {
 			dlc-rd_state = RFCOMM_DLC_WAIT_DISCONNECT;
 			err = rfcomm_session_send_frame(rs, RFCOMM_FRAME_DISC,
 			pn.dlci);



CVS commit: src/sys/netbt

2009-09-24 Thread Iain Hibbert
Module Name:src
Committed By:   plunky
Date:   Thu Sep 24 19:35:09 UTC 2009

Modified Files:
src/sys/netbt: hci_link.c

Log Message:
Only accept incoming ACL connections when there is potential
L2CAP listener available.


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/sys/netbt/hci_link.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/netbt/hci_link.c
diff -u src/sys/netbt/hci_link.c:1.20 src/sys/netbt/hci_link.c:1.21
--- src/sys/netbt/hci_link.c:1.20	Thu Apr 24 11:38:37 2008
+++ src/sys/netbt/hci_link.c	Thu Sep 24 19:35:09 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: hci_link.c,v 1.20 2008/04/24 11:38:37 ad Exp $	*/
+/*	$NetBSD: hci_link.c,v 1.21 2009/09/24 19:35:09 plunky Exp $	*/
 
 /*-
  * Copyright (c) 2005 Iain Hibbert.
@@ -31,7 +31,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: hci_link.c,v 1.20 2008/04/24 11:38:37 ad Exp $);
+__KERNEL_RCSID(0, $NetBSD: hci_link.c,v 1.21 2009/09/24 19:35:09 plunky Exp $);
 
 #include sys/param.h
 #include sys/kernel.h
@@ -162,9 +162,8 @@
 /*
  * Incoming ACL connection.
  *
- * For now, we accept all connections but it would be better to check
- * the L2CAP listen list and only accept when there is a listener
- * available.
+ * Check the L2CAP listeners list and only accept when there is a
+ * potential listener available.
  *
  * There should not be a link to the same bdaddr already, we check
  * anyway though its left unhandled for now.
@@ -173,10 +172,28 @@
 hci_acl_newconn(struct hci_unit *unit, bdaddr_t *bdaddr)
 {
 	struct hci_link *link;
+	struct l2cap_channel *chan;
+
+	LIST_FOREACH(chan, l2cap_listen_list, lc_ncid) {
+		if (bdaddr_same(unit-hci_bdaddr, chan-lc_laddr.bt_bdaddr)
+		|| bdaddr_any(chan-lc_laddr.bt_bdaddr))
+			break;
+	}
+
+	if (chan == NULL) {
+		DPRINTF(%s: rejecting connection (no listeners)\n,
+		device_xname(unit-hci_dev));
+
+		return NULL;
+	}
 
 	link = hci_link_lookup_bdaddr(unit, bdaddr, HCI_LINK_ACL);
-	if (link != NULL)
+	if (link != NULL) {
+		DPRINTF(%s: rejecting connection (link exists)\n,
+		device_xname(unit-hci_dev));
+
 		return NULL;
+	}
 
 	link = hci_link_alloc(unit, bdaddr, HCI_LINK_ACL);
 	if (link != NULL) {



CVS commit: src/sys/netbt

2009-09-12 Thread Iain Hibbert
Module Name:src
Committed By:   plunky
Date:   Sat Sep 12 18:31:46 UTC 2009

Modified Files:
src/sys/netbt: hci_event.c

Log Message:
slight reordering, plus only deal with ACL links


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/sys/netbt/hci_event.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/netbt/hci_event.c
diff -u src/sys/netbt/hci_event.c:1.20 src/sys/netbt/hci_event.c:1.21
--- src/sys/netbt/hci_event.c:1.20	Mon Aug 24 20:37:36 2009
+++ src/sys/netbt/hci_event.c	Sat Sep 12 18:31:46 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: hci_event.c,v 1.20 2009/08/24 20:37:36 plunky Exp $	*/
+/*	$NetBSD: hci_event.c,v 1.21 2009/09/12 18:31:46 plunky Exp $	*/
 
 /*-
  * Copyright (c) 2005 Iain Hibbert.
@@ -31,7 +31,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: hci_event.c,v 1.20 2009/08/24 20:37:36 plunky Exp $);
+__KERNEL_RCSID(0, $NetBSD: hci_event.c,v 1.21 2009/09/12 18:31:46 plunky Exp $);
 
 #include sys/param.h
 #include sys/kernel.h
@@ -845,11 +845,11 @@
 
 	ep.con_handle = HCI_CON_HANDLE(le16toh(ep.con_handle));
 	link = hci_link_lookup_handle(unit, ep.con_handle);
-
-	if (ep.status != 0 || link == NULL)
+	if (link == NULL || link-hl_type != HCI_LINK_ACL)
 		return;
 
-	link-hl_clock = ep.clock_offset;
+	if (ep.status == 0)
+		link-hl_clock = ep.clock_offset;
 }
 
 /*



CVS commit: src/sys/netbt

2009-09-11 Thread Iain Hibbert
Module Name:src
Committed By:   plunky
Date:   Fri Sep 11 18:35:50 UTC 2009

Modified Files:
src/sys/netbt: hci.h

Log Message:
add feature bits from 3.0 specification


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 src/sys/netbt/hci.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/netbt/hci.h
diff -u src/sys/netbt/hci.h:1.32 src/sys/netbt/hci.h:1.33
--- src/sys/netbt/hci.h:1.32	Tue Sep  1 18:02:44 2009
+++ src/sys/netbt/hci.h	Fri Sep 11 18:35:50 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: hci.h,v 1.32 2009/09/01 18:02:44 plunky Exp $	*/
+/*	$NetBSD: hci.h,v 1.33 2009/09/11 18:35:50 plunky Exp $	*/
 
 /*-
  * Copyright (c) 2005 Iain Hibbert.
@@ -54,7 +54,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $Id: hci.h,v 1.32 2009/09/01 18:02:44 plunky Exp $
+ * $Id: hci.h,v 1.33 2009/09/11 18:35:50 plunky Exp $
  * $FreeBSD: src/sys/netgraph/bluetooth/include/ng_hci.h,v 1.6 2005/01/07 01:45:43 imp Exp $
  */
 
@@ -168,8 +168,13 @@
 /* --- byte 7 */
 #define HCI_LMP_LINK_SUPERVISION_TO	0x01
 #define HCI_LMP_INQ_RSP_TX_POWER	0x02
+#define HCI_LMP_ENHANCED_POWER_CONTROL	0x04
 #define HCI_LMP_EXTENDED_FEATURES	0x80
 
+/* page 1 of extended features */
+/* --- byte 0 */
+#define HCI_LMP_SSP			0x01
+
 /* Link types */
 #define HCI_LINK_SCO			0x00 /* Voice */
 #define HCI_LINK_ACL			0x01 /* Data */



CVS commit: src/sys/netbt

2009-09-01 Thread Iain Hibbert
Module Name:src
Committed By:   plunky
Date:   Tue Sep  1 18:02:44 UTC 2009

Modified Files:
src/sys/netbt: hci.h

Log Message:
update/correct specification IDs according to recently published
Assigned Numbers documents at www.bluetooth.com


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 src/sys/netbt/hci.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/netbt/hci.h
diff -u src/sys/netbt/hci.h:1.31 src/sys/netbt/hci.h:1.32
--- src/sys/netbt/hci.h:1.31	Thu Aug 20 21:40:59 2009
+++ src/sys/netbt/hci.h	Tue Sep  1 18:02:44 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: hci.h,v 1.31 2009/08/20 21:40:59 plunky Exp $	*/
+/*	$NetBSD: hci.h,v 1.32 2009/09/01 18:02:44 plunky Exp $	*/
 
 /*-
  * Copyright (c) 2005 Iain Hibbert.
@@ -54,7 +54,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $Id: hci.h,v 1.31 2009/08/20 21:40:59 plunky Exp $
+ * $Id: hci.h,v 1.32 2009/09/01 18:02:44 plunky Exp $
  * $FreeBSD: src/sys/netgraph/bluetooth/include/ng_hci.h,v 1.6 2005/01/07 01:45:43 imp Exp $
  */
 
@@ -93,12 +93,13 @@
 #define HCI_COMMANDS_SIZE		64  /* supported commands mask */
 
 /* HCI specification */
-#define HCI_SPEC_V10			0x00 /* v1.0 */
+#define HCI_SPEC_V10			0x00 /* v1.0b */
 #define HCI_SPEC_V11			0x01 /* v1.1 */
 #define HCI_SPEC_V12			0x02 /* v1.2 */
-#define HCI_SPEC_V20			0x03 /* v2.0 */
-#define HCI_SPEC_V21			0x04 /* v2.1 */
-/* 0x05 - 0xFF - reserved for future use */
+#define HCI_SPEC_V20			0x03 /* v2.0 + EDR */
+#define HCI_SPEC_V21			0x04 /* v2.1 + EDR */
+#define HCI_SPEC_V30			0x05 /* v3.0 + HS */
+/* 0x06 - 0xFF - reserved for future use */
 
 /* LMP features (and page 0 of extended features) */
 /* --- byte 0 */



CVS commit: src/sys/netbt

2009-08-24 Thread Iain Hibbert
Module Name:src
Committed By:   plunky
Date:   Mon Aug 24 20:37:36 UTC 2009

Modified Files:
src/sys/netbt: hci_event.c

Log Message:
add devices seen in Extended Inquiry Result to the cache


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/sys/netbt/hci_event.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/netbt/hci_event.c
diff -u src/sys/netbt/hci_event.c:1.19 src/sys/netbt/hci_event.c:1.20
--- src/sys/netbt/hci_event.c:1.19	Thu Aug 20 21:40:59 2009
+++ src/sys/netbt/hci_event.c	Mon Aug 24 20:37:36 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: hci_event.c,v 1.19 2009/08/20 21:40:59 plunky Exp $	*/
+/*	$NetBSD: hci_event.c,v 1.20 2009/08/24 20:37:36 plunky Exp $	*/
 
 /*-
  * Copyright (c) 2005 Iain Hibbert.
@@ -31,7 +31,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: hci_event.c,v 1.19 2009/08/20 21:40:59 plunky Exp $);
+__KERNEL_RCSID(0, $NetBSD: hci_event.c,v 1.20 2009/08/24 20:37:36 plunky Exp $);
 
 #include sys/param.h
 #include sys/kernel.h
@@ -46,6 +46,7 @@
 
 static void hci_event_inquiry_result(struct hci_unit *, struct mbuf *);
 static void hci_event_rssi_result(struct hci_unit *, struct mbuf *);
+static void hci_event_extended_result(struct hci_unit *, struct mbuf *);
 static void hci_event_command_status(struct hci_unit *, struct mbuf *);
 static void hci_event_command_compl(struct hci_unit *, struct mbuf *);
 static void hci_event_con_compl(struct hci_unit *, struct mbuf *);
@@ -195,6 +196,10 @@
 		hci_event_rssi_result(unit, m);
 		break;
 
+	case HCI_EVENT_EXTENDED_RESULT:
+		hci_event_extended_result(unit, m);
+		break;
+
 	case HCI_EVENT_CON_COMPL:
 		hci_event_con_compl(unit, m);
 		break;
@@ -492,6 +497,36 @@
 }
 
 /*
+ * Extended Inquiry Result
+ *
+ * as above but provides only one response and extended service info
+ */
+static void
+hci_event_extended_result(struct hci_unit *unit, struct mbuf *m)
+{
+	hci_extended_result_ep ep;
+	struct hci_memo *memo;
+
+	KASSERT(m-m_pkthdr.len = sizeof(ep));
+	m_copydata(m, 0, sizeof(ep), ep);
+	m_adj(m, sizeof(ep));
+
+	if (ep.num_responses != 1)
+		return;
+
+	DPRINTFN(1, bdaddr %02x:%02x:%02x:%02x:%02x:%02x\n,
+		ep.bdaddr.b[5], ep.bdaddr.b[4], ep.bdaddr.b[3],
+		ep.bdaddr.b[2], ep.bdaddr.b[1], ep.bdaddr.b[0]);
+
+	memo = hci_memo_new(unit, ep.bdaddr);
+	if (memo != NULL) {
+		memo-page_scan_rep_mode = ep.page_scan_rep_mode;
+		memo-page_scan_mode = 0;
+		memo-clock_offset = ep.clock_offset;
+	}
+}
+
+/*
  * Connection Complete
  *
  * Sent to us when a connection is made. If there is no link



CVS commit: src/sys/netbt

2009-05-14 Thread Iain Hibbert
Module Name:src
Committed By:   plunky
Date:   Thu May 14 15:34:38 UTC 2009

Modified Files:
src/sys/netbt: hci.h

Log Message:
add const to unchanged argument


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/sys/netbt/hci.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/netbt/hci.h
diff -u src/sys/netbt/hci.h:1.28 src/sys/netbt/hci.h:1.29
--- src/sys/netbt/hci.h:1.28	Mon Sep  8 23:36:55 2008
+++ src/sys/netbt/hci.h	Thu May 14 15:34:38 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: hci.h,v 1.28 2008/09/08 23:36:55 gmcgarry Exp $	*/
+/*	$NetBSD: hci.h,v 1.29 2009/05/14 15:34:38 plunky Exp $	*/
 
 /*-
  * Copyright (c) 2005 Iain Hibbert.
@@ -54,7 +54,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $Id: hci.h,v 1.28 2008/09/08 23:36:55 gmcgarry Exp $
+ * $Id: hci.h,v 1.29 2009/05/14 15:34:38 plunky Exp $
  * $FreeBSD: src/sys/netgraph/bluetooth/include/ng_hci.h,v 1.6 2005/01/07 01:45:43 imp Exp $
  */
 
@@ -2263,7 +2263,7 @@
 }
 
 static __inline int
-hci_filter_test(uint8_t bit, struct hci_filter *filter)
+hci_filter_test(uint8_t bit, const struct hci_filter *filter)
 {
 	uint8_t off = bit - 1;