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 <sys/cdefs.h>
-__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);
-	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, &hdr, 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(&pcb->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(&unit->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 ? &sa->bt_bdaddr : &pcb->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);
+	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 ? &sa->bt_bdaddr : &pcb->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, &hdr, 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(&pcb->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));
 
-release:
+	/* Sendss it */
+	if (unit->hci_num_cmd_pkts == 0)
+		MBUFQ_ENQUEUE(&unit->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);
 

Reply via email to