Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/netbt there is no longer a reason to have a separate hci...
details: https://anonhg.NetBSD.org/src/rev/9b89cb238903
branches: trunk
changeset: 342440:9b89cb238903
user: plunky <plunky%NetBSD.org@localhost>
date: Tue Dec 22 11:40:07 2015 +0000
description:
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()
diffstat:
sys/netbt/hci_socket.c | 158 ++++++++++++++++++++++--------------------------
1 files changed, 72 insertions(+), 86 deletions(-)
diffs (204 lines):
diff -r 7b494128a27f -r 9b89cb238903 sys/netbt/hci_socket.c
--- a/sys/netbt/hci_socket.c Tue Dec 22 09:56:06 2015 +0000
+++ b/sys/netbt/hci_socket.c Tue Dec 22 11:40:07 2015 +0000
@@ -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 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 @@
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;
+ }
-release:
+ /* 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);
Home |
Main Index |
Thread Index |
Old Index