diff options
author | Uwe Stuehler <uwe@cvs.openbsd.org> | 2008-02-24 21:34:49 +0000 |
---|---|---|
committer | Uwe Stuehler <uwe@cvs.openbsd.org> | 2008-02-24 21:34:49 +0000 |
commit | 0f57bfa559ae850def03153006105883b91d362e (patch) | |
tree | a7fb0a4d79aacf2db2bdf4eef6f744e5a9ecbf61 /sys/netbt/hci_link.c | |
parent | 98450358fa8b17b64cdf2ba62762e40965362f3c (diff) |
Sync sys/netbt with NetBSD
ok deraadt@
Diffstat (limited to 'sys/netbt/hci_link.c')
-rw-r--r-- | sys/netbt/hci_link.c | 92 |
1 files changed, 55 insertions, 37 deletions
diff --git a/sys/netbt/hci_link.c b/sys/netbt/hci_link.c index 65efaf2f120..642d87af21d 100644 --- a/sys/netbt/hci_link.c +++ b/sys/netbt/hci_link.c @@ -1,5 +1,5 @@ -/* $OpenBSD: hci_link.c,v 1.6 2007/09/17 01:33:33 krw Exp $ */ -/* $NetBSD: hci_link.c,v 1.11 2007/04/21 06:15:23 plunky Exp $ */ +/* $OpenBSD: hci_link.c,v 1.7 2008/02/24 21:34:48 uwe Exp $ */ +/* $NetBSD: hci_link.c,v 1.16 2007/11/10 23:12:22 plunky Exp $ */ /*- * Copyright (c) 2005 Iain Hibbert. @@ -31,8 +31,6 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#include <sys/cdefs.h> - #include <sys/param.h> #include <sys/kernel.h> #include <sys/malloc.h> @@ -96,9 +94,9 @@ hci_acl_open(struct hci_unit *unit, bdaddr_t *bdaddr) memo = hci_memo_find(unit, bdaddr); if (memo != NULL) { - cp.page_scan_rep_mode = memo->response.page_scan_rep_mode; - cp.page_scan_mode = memo->response.page_scan_mode; - cp.clock_offset = htole16(memo->response.clock_offset); + cp.page_scan_rep_mode = memo->page_scan_rep_mode; + cp.page_scan_mode = memo->page_scan_mode; + cp.clock_offset = memo->clock_offset; } if (unit->hci_link_policy & HCI_LINK_POLICY_ENABLE_ROLE_SWITCH) @@ -257,8 +255,8 @@ hci_acl_setmode(struct hci_link *link) && !(link->hl_flags & HCI_LINK_AUTH)) { hci_auth_req_cp cp; - DPRINTF("requesting auth for handle #%d\n", - link->hl_handle); + DPRINTF("(%s) requesting auth for handle #%d\n", + device_xname(link->hl_unit->hci_dev), link->hl_handle); link->hl_state = HCI_LINK_WAIT_AUTH; cp.con_handle = htole16(link->hl_handle); @@ -274,8 +272,8 @@ hci_acl_setmode(struct hci_link *link) /* XXX we should check features for encryption capability */ - DPRINTF("requesting encryption for handle #%d\n", - link->hl_handle); + DPRINTF("(%s) requesting encryption for handle #%d\n", + device_xname(link->hl_unit->hci_dev), link->hl_handle); link->hl_state = HCI_LINK_WAIT_ENCRYPT; cp.con_handle = htole16(link->hl_handle); @@ -293,8 +291,8 @@ hci_acl_setmode(struct hci_link *link) /* always change link key for SECURE requests */ link->hl_flags &= ~HCI_LINK_SECURE; - DPRINTF("changing link key for handle #%d\n", - link->hl_handle); + DPRINTF("(%s) changing link key for handle #%d\n", + device_xname(link->hl_unit->hci_dev), link->hl_handle); link->hl_state = HCI_LINK_WAIT_SECURE; cp.con_handle = htole16(link->hl_handle); @@ -320,11 +318,11 @@ hci_acl_linkmode(struct hci_link *link) struct l2cap_channel *chan, *next; int err, mode = 0; - DPRINTF("handle #%d, auth %s, encrypt %s, secure %s\n", - link->hl_handle, - (link->hl_flags & HCI_LINK_AUTH ? "on" : "off"), - (link->hl_flags & HCI_LINK_ENCRYPT ? "on" : "off"), - (link->hl_flags & HCI_LINK_SECURE ? "on" : "off")); + DPRINTF("(%s) handle #%d, auth %s, encrypt %s, secure %s\n", + device_xname(link->hl_unit->hci_dev), link->hl_handle, + (link->hl_flags & HCI_LINK_AUTH ? "on" : "off"), + (link->hl_flags & HCI_LINK_ENCRYPT ? "on" : "off"), + (link->hl_flags & HCI_LINK_SECURE ? "on" : "off")); if (link->hl_flags & HCI_LINK_AUTH) mode |= L2CAP_LM_AUTH; @@ -424,13 +422,15 @@ hci_acl_recv(struct mbuf *m, struct hci_unit *unit) #ifdef DIAGNOSTIC if (hdr.type != HCI_ACL_DATA_PKT) { - printf("%s: bad ACL packet type\n", unit->hci_devname); + printf("%s: bad ACL packet type\n", + device_xname(unit->hci_dev)); goto bad; } if (m->m_pkthdr.len != letoh16(hdr.length)) { printf("%s: bad ACL packet length (%d != %d)\n", - unit->hci_devname, m->m_pkthdr.len, letoh16(hdr.length)); + device_xname(unit->hci_dev), m->m_pkthdr.len, + letoh16(hdr.length)); goto bad; } #endif @@ -445,7 +445,7 @@ hci_acl_recv(struct mbuf *m, struct hci_unit *unit) hci_discon_cp cp; DPRINTF("%s: dumping packet for unknown handle #%d\n", - unit->hci_devname, handle); + device_xname(unit->hci_dev), handle); /* * There is no way to find out what this connection handle is @@ -463,11 +463,11 @@ hci_acl_recv(struct mbuf *m, struct hci_unit *unit) case HCI_PACKET_START: if (link->hl_rxp != NULL) printf("%s: dropped incomplete ACL packet\n", - unit->hci_devname); + device_xname(unit->hci_dev)); if (m->m_pkthdr.len < sizeof(l2cap_hdr_t)) { printf("%s: short ACL packet\n", - unit->hci_devname); + device_xname(unit->hci_dev)); goto bad; } @@ -479,7 +479,7 @@ hci_acl_recv(struct mbuf *m, struct hci_unit *unit) case HCI_PACKET_FRAGMENT: if (link->hl_rxp == NULL) { printf("%s: unexpected packet fragment\n", - unit->hci_devname); + device_xname(unit->hci_dev)); goto bad; } @@ -492,7 +492,7 @@ hci_acl_recv(struct mbuf *m, struct hci_unit *unit) default: printf("%s: unknown packet type\n", - unit->hci_devname); + device_xname(unit->hci_dev)); goto bad; } @@ -552,7 +552,7 @@ hci_acl_send(struct mbuf *m, struct hci_link *link, mlen = link->hl_unit->hci_max_acl_size; DPRINTFN(5, "%s: handle #%d, plen = %d, max = %d\n", - link->hl_unit->hci_devname, link->hl_handle, plen, mlen); + device_xname(link->hl_unit->hci_dev), link->hl_handle, plen, mlen); while (plen > 0) { if (plen > mlen) { @@ -566,7 +566,8 @@ hci_acl_send(struct mbuf *m, struct hci_link *link, if (num++ == 0) m->m_flags |= M_PROTO1; /* tag first fragment */ - DPRINTFN(10, "chunk of %d (plen = %d) bytes\n", mlen, plen); + DPRINTFN(10, "(%s) chunk of %d (plen = %d) bytes\n", + device_xname(link->hl_unit->hci_dev), mlen, plen); IF_ENQUEUE(&pdu->lp_data, m); m = n; plen -= mlen; @@ -700,15 +701,16 @@ hci_acl_complete(struct hci_link *link, int num) struct l2cap_pdu *pdu; struct l2cap_channel *chan; - DPRINTFN(5, "handle #%d (%d)\n", link->hl_handle, num); + DPRINTFN(5, "(%s) handle #%d (%d)\n", + device_xname(link->hl_unit->hci_dev), link->hl_handle, num); while (num > 0) { pdu = TAILQ_FIRST(&link->hl_txq); if (pdu == NULL) { printf("%s: %d packets completed on handle #%x " - "but none pending!\n", - link->hl_unit->hci_devname, num, - link->hl_handle); + "but none pending!\n", + device_xname(link->hl_unit->hci_dev), num, + link->hl_handle); return; } @@ -829,13 +831,14 @@ hci_sco_recv(struct mbuf *m, struct hci_unit *unit) #ifdef DIAGNOSTIC if (hdr.type != HCI_SCO_DATA_PKT) { - printf("%s: bad SCO packet type\n", unit->hci_devname); + printf("%s: bad SCO packet type\n", + device_xname(unit->hci_dev)); goto bad; } if (m->m_pkthdr.len != hdr.length) { printf("%s: bad SCO packet length (%d != %d)\n", - unit->hci_devname, m->m_pkthdr.len, hdr.length); + device_xname(unit->hci_dev), m->m_pkthdr.len, hdr.length); goto bad; } #endif @@ -846,7 +849,7 @@ hci_sco_recv(struct mbuf *m, struct hci_unit *unit) link = hci_link_lookup_handle(unit, handle); if (link == NULL || link->hl_type == HCI_LINK_ACL) { DPRINTF("%s: dumping packet for unknown handle #%d\n", - unit->hci_devname, handle); + device_xname(unit->hci_dev), handle); goto bad; } @@ -904,6 +907,9 @@ hci_link_alloc(struct hci_unit *unit) link->hl_mtu = L2CAP_MTU_DEFAULT; /* L2CAP signal mtu */ link->hl_flush = L2CAP_FLUSH_TIMO_DEFAULT; /* flush timeout */ + /* init SCO portion */ + /* &link->hl_data is already zero-initialized. */ + /* attach to unit */ TAILQ_INSERT_HEAD(&unit->hci_links, link, hl_next); return link; @@ -918,9 +924,9 @@ hci_link_free(struct hci_link *link, int err) KASSERT(link != NULL); - DPRINTF("#%d, type = %d, state = %d, refcnt = %d\n", - link->hl_handle, link->hl_type, - link->hl_state, link->hl_refcnt); + DPRINTF("(%s) #%d, type = %d, state = %d, refcnt = %d\n", + device_xname(link->hl_unit->hci_dev), link->hl_handle, + link->hl_type, link->hl_state, link->hl_refcnt); /* ACL reference count */ if (link->hl_refcnt > 0) { @@ -986,6 +992,18 @@ hci_link_free(struct hci_link *link, int err) if (timeout_triggered(&link->hl_expire)) return; + /* + * If we made a note of clock offset, keep it in a memo + * to facilitate reconnections to this device + */ + if (link->hl_clock != 0) { + struct hci_memo *memo; + + memo = hci_memo_new(link->hl_unit, &link->hl_bdaddr); + if (memo != NULL) + memo->clock_offset = link->hl_clock; + } + TAILQ_REMOVE(&link->hl_unit->hci_links, link, hl_next); free(link, M_BLUETOOTH); } |