summaryrefslogtreecommitdiffstats
path: root/sys/netgraph/bluetooth/l2cap
diff options
context:
space:
mode:
authorjulian <julian@FreeBSD.org>2003-05-10 21:44:42 +0000
committerjulian <julian@FreeBSD.org>2003-05-10 21:44:42 +0000
commitdc5734d94b071df224b65d45b95d9ae7c5d563ab (patch)
treeed7d8caf163274b56933e0b801c52beb10b3260d /sys/netgraph/bluetooth/l2cap
parent9e09746efa5431d5af0baf849575917d37cfdb76 (diff)
downloadFreeBSD-src-dc5734d94b071df224b65d45b95d9ae7c5d563ab.zip
FreeBSD-src-dc5734d94b071df224b65d45b95d9ae7c5d563ab.tar.gz
Part one of undating the bluetooth code to the newest version
Submitted by: Maksim Yevmenkin <m_evmenkin@yahoo.com> Approved by: re@
Diffstat (limited to 'sys/netgraph/bluetooth/l2cap')
-rw-r--r--sys/netgraph/bluetooth/l2cap/TODO2
-rw-r--r--sys/netgraph/bluetooth/l2cap/ng_l2cap_cmds.c2
-rw-r--r--sys/netgraph/bluetooth/l2cap/ng_l2cap_cmds.h14
-rw-r--r--sys/netgraph/bluetooth/l2cap/ng_l2cap_evnt.c11
-rw-r--r--sys/netgraph/bluetooth/l2cap/ng_l2cap_evnt.h2
-rw-r--r--sys/netgraph/bluetooth/l2cap/ng_l2cap_llpi.c64
-rw-r--r--sys/netgraph/bluetooth/l2cap/ng_l2cap_llpi.h25
-rw-r--r--sys/netgraph/bluetooth/l2cap/ng_l2cap_main.c31
-rw-r--r--sys/netgraph/bluetooth/l2cap/ng_l2cap_misc.c124
-rw-r--r--sys/netgraph/bluetooth/l2cap/ng_l2cap_misc.h8
-rw-r--r--sys/netgraph/bluetooth/l2cap/ng_l2cap_prse.h16
-rw-r--r--sys/netgraph/bluetooth/l2cap/ng_l2cap_ulpi.c2
-rw-r--r--sys/netgraph/bluetooth/l2cap/ng_l2cap_ulpi.h2
-rw-r--r--sys/netgraph/bluetooth/l2cap/ng_l2cap_var.h8
14 files changed, 261 insertions, 50 deletions
diff --git a/sys/netgraph/bluetooth/l2cap/TODO b/sys/netgraph/bluetooth/l2cap/TODO
index 98d0440..7c7bb27 100644
--- a/sys/netgraph/bluetooth/l2cap/TODO
+++ b/sys/netgraph/bluetooth/l2cap/TODO
@@ -1,4 +1,4 @@
-$Id: TODO,v 1.8 2002/09/06 21:03:58 max Exp $
+$Id: TODO,v 1.1 2002/11/24 19:47:06 max Exp $
$FreeBSD$
FIXME/TODO list
diff --git a/sys/netgraph/bluetooth/l2cap/ng_l2cap_cmds.c b/sys/netgraph/bluetooth/l2cap/ng_l2cap_cmds.c
index 0d28f1a..844c5a6 100644
--- a/sys/netgraph/bluetooth/l2cap/ng_l2cap_cmds.c
+++ b/sys/netgraph/bluetooth/l2cap/ng_l2cap_cmds.c
@@ -25,7 +25,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: ng_l2cap_cmds.c,v 1.14 2002/09/04 21:38:38 max Exp $
+ * $Id: ng_l2cap_cmds.c,v 1.1 2002/11/24 19:47:06 max Exp $
* $FreeBSD$
*/
diff --git a/sys/netgraph/bluetooth/l2cap/ng_l2cap_cmds.h b/sys/netgraph/bluetooth/l2cap/ng_l2cap_cmds.h
index d107ad6..ed8e84f 100644
--- a/sys/netgraph/bluetooth/l2cap/ng_l2cap_cmds.h
+++ b/sys/netgraph/bluetooth/l2cap/ng_l2cap_cmds.h
@@ -25,7 +25,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: ng_l2cap_cmds.h,v 1.9 2002/04/16 00:43:56 max Exp $
+ * $Id: ng_l2cap_cmds.h,v 1.4 2003/04/01 18:15:26 max Exp $
* $FreeBSD$
*/
@@ -152,9 +152,11 @@ do { \
c->param.dcid = htole16((_dcid)); \
c->param.flags = htole16((_flags)); \
if ((_data) != NULL) { \
+ int l = (_data)->m_pkthdr.len; \
+ \
m_cat((_m), (_data)); \
- c->hdr.length += (_data)->m_pkthdr.len; \
- (_m)->m_pkthdr.len += (_data)->m_pkthdr.len; \
+ c->hdr.length += l; \
+ (_m)->m_pkthdr.len += l; \
} \
\
c->hdr.length = htole16(c->hdr.length); \
@@ -185,9 +187,11 @@ do { \
c->param.flags = htole16((_flags)); \
c->param.result = htole16((_result)); \
if ((_data) != NULL) { \
+ int l = (_data)->m_pkthdr.len; \
+ \
m_cat((_m), (_data)); \
- c->hdr.length += (_data)->m_pkthdr.len; \
- (_m)->m_pkthdr.len += (_data)->m_pkthdr.len; \
+ c->hdr.length += l; \
+ (_m)->m_pkthdr.len += l; \
} \
\
c->hdr.length = htole16(c->hdr.length); \
diff --git a/sys/netgraph/bluetooth/l2cap/ng_l2cap_evnt.c b/sys/netgraph/bluetooth/l2cap/ng_l2cap_evnt.c
index 3779b91..4a9c6fd 100644
--- a/sys/netgraph/bluetooth/l2cap/ng_l2cap_evnt.c
+++ b/sys/netgraph/bluetooth/l2cap/ng_l2cap_evnt.c
@@ -25,7 +25,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: ng_l2cap_evnt.c,v 1.18 2002/09/04 21:38:38 max Exp $
+ * $Id: ng_l2cap_evnt.c,v 1.4 2003/04/01 18:15:26 max Exp $
* $FreeBSD$
*/
@@ -844,7 +844,8 @@ ng_l2cap_process_discon_req(ng_l2cap_con_p con, u_int8_t ident)
}
/* XXX Verify channel state and reject if invalid -- is that true? */
- if (ch->state != NG_L2CAP_OPEN && ch->state != NG_L2CAP_CONFIG) {
+ if (ch->state != NG_L2CAP_OPEN && ch->state != NG_L2CAP_CONFIG &&
+ ch->state != NG_L2CAP_W4_L2CAP_DISCON_RSP) {
NG_L2CAP_ERR(
"%s: %s - unexpected L2CAP_DisconnectReq. " \
"Invalid channel state, cid=%d, state=%d\n",
@@ -869,8 +870,10 @@ ng_l2cap_process_discon_req(ng_l2cap_con_p con, u_int8_t ident)
* with L2CAP_DisconnectRsp.
*/
- ng_l2cap_l2ca_discon_ind(ch); /* do not care about result */
- ng_l2cap_free_chan(ch);
+ if (ch->state != NG_L2CAP_W4_L2CAP_DISCON_RSP) {
+ ng_l2cap_l2ca_discon_ind(ch); /* do not care about result */
+ ng_l2cap_free_chan(ch);
+ }
/* Send L2CAP_DisconnectRsp */
cmd = ng_l2cap_new_cmd(con, NULL, ident, NG_L2CAP_DISCON_RSP, 0);
diff --git a/sys/netgraph/bluetooth/l2cap/ng_l2cap_evnt.h b/sys/netgraph/bluetooth/l2cap/ng_l2cap_evnt.h
index 26fcac5..c7cf8ac 100644
--- a/sys/netgraph/bluetooth/l2cap/ng_l2cap_evnt.h
+++ b/sys/netgraph/bluetooth/l2cap/ng_l2cap_evnt.h
@@ -25,7 +25,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: ng_l2cap_evnt.h,v 1.2 2002/04/16 00:43:56 max Exp $
+ * $Id: ng_l2cap_evnt.h,v 1.1 2002/11/24 19:47:06 max Exp $
* $FreeBSD$
*/
diff --git a/sys/netgraph/bluetooth/l2cap/ng_l2cap_llpi.c b/sys/netgraph/bluetooth/l2cap/ng_l2cap_llpi.c
index f505158..bc110ad 100644
--- a/sys/netgraph/bluetooth/l2cap/ng_l2cap_llpi.c
+++ b/sys/netgraph/bluetooth/l2cap/ng_l2cap_llpi.c
@@ -25,7 +25,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: ng_l2cap_llpi.c,v 1.16 2002/09/04 21:38:38 max Exp $
+ * $Id: ng_l2cap_llpi.c,v 1.4 2003/04/28 21:44:59 max Exp $
* $FreeBSD$
*/
@@ -108,12 +108,15 @@ ng_l2cap_lp_con_req(ng_l2cap_p l2cap, bdaddr_p bdaddr)
bcopy(bdaddr, &ep->bdaddr, sizeof(ep->bdaddr));
ep->link_type = NG_HCI_LINK_ACL;
+ con->flags |= NG_L2CAP_CON_OUTGOING;
con->state = NG_L2CAP_W4_LP_CON_CFM;
ng_l2cap_lp_timeout(con);
NG_SEND_MSG_HOOK(error, l2cap->node, msg, l2cap->hci, NULL);
- if (error != 0)
- ng_l2cap_free_con(con); /* will remove timeout */
+ if (error != 0) {
+ ng_l2cap_lp_untimeout(con);
+ ng_l2cap_free_con(con);
+ }
return (error);
} /* ng_l2cap_lp_con_req */
@@ -174,11 +177,8 @@ ng_l2cap_lp_con_cfm(ng_l2cap_p l2cap, struct ng_mesg *msg)
con->state = NG_L2CAP_CON_OPEN;
con->con_handle = ep->con_handle;
ng_l2cap_lp_deliver(con);
- } else {
- /* Negative confirmation - remove connection descriptor */
- con->state = NG_L2CAP_CON_CLOSED;
+ } else /* Negative confirmation - remove connection descriptor */
ng_l2cap_con_fail(con, ep->status);
- }
out:
return (error);
} /* ng_l2cap_lp_con_cfm */
@@ -258,8 +258,10 @@ ng_l2cap_lp_con_ind(ng_l2cap_p l2cap, struct ng_mesg *msg)
ng_l2cap_lp_timeout(con);
NG_SEND_MSG_HOOK(error, l2cap->node, rsp, l2cap->hci, NULL);
- if (error != 0)
- ng_l2cap_free_con(con); /* will remove timeout */
+ if (error != 0) {
+ ng_l2cap_lp_untimeout(con);
+ ng_l2cap_free_con(con);
+ }
out:
return (error);
} /* ng_hci_lp_con_ind */
@@ -310,7 +312,9 @@ ng_l2cap_lp_discon_ind(ng_l2cap_p l2cap, struct ng_mesg *msg)
}
/* Notify upper layer and remove connection */
- con->state = NG_L2CAP_CON_CLOSED;
+ if (con->flags & NG_L2CAP_CON_AUTO_DISCON_TIMO)
+ ng_l2cap_discon_untimeout(con);
+
ng_l2cap_con_fail(con, ep->reason);
out:
return (error);
@@ -800,7 +804,45 @@ ng_l2cap_process_lp_timeout(node_p node, hook_p hook, void *arg1, int arg2)
* connection, channels and pending commands.
*/
- con->state = NG_L2CAP_CON_CLOSED;
+ con->flags &= ~NG_L2CAP_CON_LP_TIMO;
ng_l2cap_con_fail(con, NG_L2CAP_TIMEOUT);
} /* ng_l2cap_process_lp_timeout */
+/*
+ * Process auto disconnect timeout and send LP_DisconReq event to the
+ * lower layer protocol
+ */
+
+void
+ng_l2cap_process_discon_timeout(node_p node, hook_p hook, void *arg1, int arg2)
+{
+ ng_l2cap_con_p con = (ng_l2cap_con_p) arg1;
+ ng_l2cap_p l2cap = con->l2cap;
+ struct ng_mesg *msg = NULL;
+ ng_hci_lp_discon_req_ep *ep = NULL;
+ int error;
+
+ con->flags &= ~NG_L2CAP_CON_AUTO_DISCON_TIMO;
+
+ /* Check if lower layer protocol is still connected */
+ if (l2cap->hci == NULL || NG_HOOK_NOT_VALID(l2cap->hci)) {
+ NG_L2CAP_ERR(
+"%s: %s - hook \"%s\" is not connected or valid\n",
+ __func__, NG_NODE_NAME(l2cap->node), NG_L2CAP_HOOK_HCI);
+
+ return;
+ }
+
+ /* Create and send LP_DisconReq event */
+ NG_MKMESSAGE(msg, NGM_HCI_COOKIE, NGM_HCI_LP_DISCON_REQ,
+ sizeof(*ep), M_NOWAIT);
+ if (msg == NULL)
+ return;
+
+ ep = (ng_hci_lp_discon_req_ep *) (msg->data);
+ ep->con_handle = con->con_handle;
+ ep->reason = 0x13; /* User Ended Connection */
+
+ NG_SEND_MSG_HOOK(error, l2cap->node, msg, l2cap->hci, NULL);
+} /* ng_l2cap_process_discon_timeout */
+
diff --git a/sys/netgraph/bluetooth/l2cap/ng_l2cap_llpi.h b/sys/netgraph/bluetooth/l2cap/ng_l2cap_llpi.h
index 161761e..9efc835 100644
--- a/sys/netgraph/bluetooth/l2cap/ng_l2cap_llpi.h
+++ b/sys/netgraph/bluetooth/l2cap/ng_l2cap_llpi.h
@@ -25,24 +25,25 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: ng_l2cap_llpi.h,v 1.6 2002/04/16 00:43:57 max Exp $
+ * $Id: ng_l2cap_llpi.h,v 1.2 2003/04/28 21:44:59 max Exp $
* $FreeBSD$
*/
#ifndef _NETGRAPH_L2CAP_LLPI_H_
#define _NETGRAPH_L2CAP_LLPI_H_
-int ng_l2cap_lp_con_req (ng_l2cap_p, bdaddr_p);
-int ng_l2cap_lp_con_cfm (ng_l2cap_p, struct ng_mesg *);
-int ng_l2cap_lp_con_ind (ng_l2cap_p, struct ng_mesg *);
-int ng_l2cap_lp_discon_ind (ng_l2cap_p, struct ng_mesg *);
-int ng_l2cap_lp_qos_req (ng_l2cap_p, u_int16_t, ng_l2cap_flow_p);
-int ng_l2cap_lp_qos_cfm (ng_l2cap_p, struct ng_mesg *);
-int ng_l2cap_lp_qos_ind (ng_l2cap_p, struct ng_mesg *);
-int ng_l2cap_lp_send (ng_l2cap_con_p, u_int16_t,struct mbuf *);
-int ng_l2cap_lp_receive (ng_l2cap_p, struct mbuf *);
-void ng_l2cap_lp_deliver (ng_l2cap_con_p);
-void ng_l2cap_process_lp_timeout (node_p, hook_p, void *, int);
+int ng_l2cap_lp_con_req (ng_l2cap_p, bdaddr_p);
+int ng_l2cap_lp_con_cfm (ng_l2cap_p, struct ng_mesg *);
+int ng_l2cap_lp_con_ind (ng_l2cap_p, struct ng_mesg *);
+int ng_l2cap_lp_discon_ind (ng_l2cap_p, struct ng_mesg *);
+int ng_l2cap_lp_qos_req (ng_l2cap_p, u_int16_t, ng_l2cap_flow_p);
+int ng_l2cap_lp_qos_cfm (ng_l2cap_p, struct ng_mesg *);
+int ng_l2cap_lp_qos_ind (ng_l2cap_p, struct ng_mesg *);
+int ng_l2cap_lp_send (ng_l2cap_con_p, u_int16_t,struct mbuf *);
+int ng_l2cap_lp_receive (ng_l2cap_p, struct mbuf *);
+void ng_l2cap_lp_deliver (ng_l2cap_con_p);
+void ng_l2cap_process_lp_timeout (node_p, hook_p, void *, int);
+void ng_l2cap_process_discon_timeout (node_p, hook_p, void *, int);
#endif /* ndef _NETGRAPH_L2CAP_LLPI_H_ */
diff --git a/sys/netgraph/bluetooth/l2cap/ng_l2cap_main.c b/sys/netgraph/bluetooth/l2cap/ng_l2cap_main.c
index 1dfc4c0..3117c29 100644
--- a/sys/netgraph/bluetooth/l2cap/ng_l2cap_main.c
+++ b/sys/netgraph/bluetooth/l2cap/ng_l2cap_main.c
@@ -25,7 +25,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: ng_l2cap_main.c,v 1.24 2002/09/04 21:38:38 max Exp $
+ * $Id: ng_l2cap_main.c,v 1.2 2003/04/28 21:44:59 max Exp $
* $FreeBSD$
*/
@@ -120,6 +120,7 @@ ng_l2cap_constructor(node_p node)
l2cap->node = node;
l2cap->debug = NG_L2CAP_WARN_LEVEL;
+ l2cap->discon_timo = 5; /* sec */
LIST_INIT(&l2cap->con_list);
LIST_INIT(&l2cap->chan_list);
@@ -574,6 +575,7 @@ ng_l2cap_default_rcvmsg(node_p node, item_p item, hook_p lasthook)
LIST_FOREACH(con, &l2cap->con_list, next) {
e2->state = con->state;
+ e2->flags = con->flags;
if (con->tx_pkt != NULL)
e2->flags |= NG_L2CAP_CON_TX;
if (con->rx_pkt != NULL)
@@ -637,6 +639,26 @@ ng_l2cap_default_rcvmsg(node_p node, item_p item, hook_p lasthook)
}
} break;
+ case NGM_L2CAP_NODE_GET_AUTO_DISCON_TIMO:
+ NG_MKRESPONSE(rsp, msg,
+ sizeof(ng_l2cap_node_auto_discon_ep), M_NOWAIT);
+ if (rsp == NULL)
+ error = ENOMEM;
+ else
+ *((ng_l2cap_node_auto_discon_ep *)(rsp->data)) =
+ l2cap->discon_timo;
+ break;
+
+ case NGM_L2CAP_NODE_SET_AUTO_DISCON_TIMO:
+ if (msg->header.arglen !=
+ sizeof(ng_l2cap_node_auto_discon_ep))
+ error = EMSGSIZE;
+ else
+ l2cap->discon_timo =
+ *((ng_l2cap_node_auto_discon_ep *)
+ (msg->data));
+ break;
+
default:
error = EINVAL;
break;
@@ -714,12 +736,13 @@ ng_l2cap_cleanup(ng_l2cap_p l2cap)
while (!LIST_EMPTY(&l2cap->con_list)) {
con = LIST_FIRST(&l2cap->con_list);
- if (con->state == NG_L2CAP_W4_LP_CON_CFM)
+ if (con->flags & NG_L2CAP_CON_LP_TIMO)
ng_l2cap_lp_untimeout(con);
+ else if (con->flags & NG_L2CAP_CON_AUTO_DISCON_TIMO)
+ ng_l2cap_discon_untimeout(con);
- con->state = NG_L2CAP_CON_CLOSED;
+ /* Connection terminated by local host */
ng_l2cap_con_fail(con, 0x16);
- /* Connection terminated by local host */
}
} /* ng_l2cap_cleanup */
diff --git a/sys/netgraph/bluetooth/l2cap/ng_l2cap_misc.c b/sys/netgraph/bluetooth/l2cap/ng_l2cap_misc.c
index 9fcbc6e..43a6d13 100644
--- a/sys/netgraph/bluetooth/l2cap/ng_l2cap_misc.c
+++ b/sys/netgraph/bluetooth/l2cap/ng_l2cap_misc.c
@@ -25,7 +25,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: ng_l2cap_misc.c,v 1.16 2002/09/04 21:38:38 max Exp $
+ * $Id: ng_l2cap_misc.c,v 1.4 2003/04/28 21:44:59 max Exp $
* $FreeBSD$
*/
@@ -48,6 +48,7 @@
#include "ng_l2cap_misc.h"
static u_int16_t ng_l2cap_get_cid (ng_l2cap_p);
+static void ng_l2cap_queue_discon_timeout (void *);
static void ng_l2cap_queue_lp_timeout (void *);
static void ng_l2cap_queue_command_timeout (void *);
@@ -93,9 +94,8 @@ ng_l2cap_send_hook_info(node_p node, hook_p hook, void *arg1, int arg2)
} /* ng_l2cap_send_hook_info */
/*
- * Create new connection descriptor for the "remote" unit. Will create new
- * connection descriptor and signal channel. Will link both connection and
- * channel to the l2cap node.
+ * Create new connection descriptor for the "remote" unit.
+ * Will link connection descriptor to the l2cap node.
*/
ng_l2cap_con_p
@@ -125,6 +125,104 @@ ng_l2cap_new_con(ng_l2cap_p l2cap, bdaddr_p bdaddr)
} /* ng_l2cap_new_con */
/*
+ * Add reference to the connection descriptor
+ */
+
+void
+ng_l2cap_con_ref(ng_l2cap_con_p con)
+{
+ con->refcnt ++;
+
+ if (con->flags & NG_L2CAP_CON_AUTO_DISCON_TIMO) {
+ if ((con->state != NG_L2CAP_CON_OPEN) ||
+ (con->flags & NG_L2CAP_CON_OUTGOING) == 0)
+ panic("%s: %s - bad auto disconnect timeout\n",
+ __func__, NG_NODE_NAME(con->l2cap->node));
+
+ ng_l2cap_discon_untimeout(con);
+ }
+} /* ng_l2cap_con_ref */
+
+/*
+ * Remove reference from the connection descriptor
+ */
+
+void
+ng_l2cap_con_unref(ng_l2cap_con_p con)
+{
+ con->refcnt --;
+
+ if (con->refcnt < 0)
+ panic("%s: %s - con->refcnt < 0\n",
+ __func__, NG_NODE_NAME(con->l2cap->node));
+
+ /*
+ * Set auto disconnect timer only if the following conditions are met:
+ * 1) we have no reference on the connection
+ * 2) connection is in OPEN state
+ * 3) it is an outgoing connection
+ * 4) disconnect timeout > 0
+ */
+
+ if ((con->refcnt == 0) &&
+ (con->state == NG_L2CAP_CON_OPEN) &&
+ (con->flags & NG_L2CAP_CON_OUTGOING) &&
+ (con->l2cap->discon_timo > 0)) {
+ if (con->flags & NG_L2CAP_CON_AUTO_DISCON_TIMO)
+ panic("%s: %s - duplicated auto disconnect timeout\n",
+ __func__, NG_NODE_NAME(con->l2cap->node));
+
+ ng_l2cap_discon_timeout(con);
+ }
+} /* ng_l2cap_con_unref */
+
+/*
+ * Set auto disconnect timeout
+ */
+
+void
+ng_l2cap_discon_timeout(ng_l2cap_con_p con)
+{
+ if (con->flags & (NG_L2CAP_CON_LP_TIMO|NG_L2CAP_CON_AUTO_DISCON_TIMO))
+ panic("%s: %s - invalid timeout, state=%d, flags=%#x\n",
+ __func__, NG_NODE_NAME(con->l2cap->node),
+ con->state, con->flags);
+
+ NG_NODE_REF(con->l2cap->node);
+ con->flags |= NG_L2CAP_CON_AUTO_DISCON_TIMO;
+ con->con_timo = timeout(ng_l2cap_queue_discon_timeout, con,
+ con->l2cap->discon_timo * hz);
+} /* ng_l2cap_discon_timeout */
+
+/*
+ * Unset auto disconnect timeout
+ */
+
+void
+ng_l2cap_discon_untimeout(ng_l2cap_con_p con)
+{
+ untimeout(ng_l2cap_queue_discon_timeout, con, con->con_timo);
+ con->flags &= ~NG_L2CAP_CON_AUTO_DISCON_TIMO;
+ NG_NODE_UNREF(con->l2cap->node);
+} /* ng_l2cap_discon_untimeout */
+
+/*
+ * Queue auto disconnect timeout
+ */
+
+static void
+ng_l2cap_queue_discon_timeout(void *context)
+{
+ ng_l2cap_con_p con = (ng_l2cap_con_p) context;
+ node_p node = con->l2cap->node;
+
+ if (NG_NODE_IS_VALID(node))
+ ng_send_fn(node,NULL,&ng_l2cap_process_discon_timeout,con,0);
+
+ NG_NODE_UNREF(node);
+} /* ng_l2cap_queue_discon_timeout */
+
+/*
* Free connection descriptor. Will unlink connection and free everything.
*/
@@ -133,8 +231,12 @@ ng_l2cap_free_con(ng_l2cap_con_p con)
{
ng_l2cap_chan_p f = NULL, n = NULL;
- if (con->state == NG_L2CAP_W4_LP_CON_CFM)
+ if (con->flags & NG_L2CAP_CON_LP_TIMO)
ng_l2cap_lp_untimeout(con);
+ else if (con->flags & NG_L2CAP_CON_AUTO_DISCON_TIMO)
+ ng_l2cap_discon_untimeout(con);
+
+ con->state = NG_L2CAP_CON_CLOSED;
if (con->tx_pkt != NULL) {
while (con->tx_pkt != NULL) {
@@ -234,6 +336,8 @@ ng_l2cap_new_chan(ng_l2cap_p l2cap, ng_l2cap_con_p con, u_int16_t psm)
ch->link_timo = NG_L2CAP_LINK_TIMO_DEFAULT;
LIST_INSERT_HEAD(&l2cap->chan_list, ch, next);
+
+ ng_l2cap_con_ref(con);
} else {
bzero(ch, sizeof(*ch));
FREE(ch, M_NETGRAPH_L2CAP);
@@ -281,6 +385,9 @@ ng_l2cap_free_chan(ng_l2cap_chan_p ch)
}
LIST_REMOVE(ch, next);
+
+ ng_l2cap_con_unref(ch->con);
+
bzero(ch, sizeof(*ch));
FREE(ch, M_NETGRAPH_L2CAP);
} /* ng_l2cap_free_chan */
@@ -337,7 +444,13 @@ ng_l2cap_cmd_by_ident(ng_l2cap_con_p con, u_int8_t ident)
void
ng_l2cap_lp_timeout(ng_l2cap_con_p con)
{
+ if (con->flags & (NG_L2CAP_CON_LP_TIMO|NG_L2CAP_CON_AUTO_DISCON_TIMO))
+ panic("%s: %s - invalid timeout, state=%d, flags=%#x\n",
+ __func__, NG_NODE_NAME(con->l2cap->node),
+ con->state, con->flags);
+
NG_NODE_REF(con->l2cap->node);
+ con->flags |= NG_L2CAP_CON_LP_TIMO;
con->con_timo = timeout(ng_l2cap_queue_lp_timeout, con,
bluetooth_hci_connect_timeout());
} /* ng_l2cap_lp_timeout */
@@ -350,6 +463,7 @@ void
ng_l2cap_lp_untimeout(ng_l2cap_con_p con)
{
untimeout(ng_l2cap_queue_lp_timeout, con, con->con_timo);
+ con->flags &= ~NG_L2CAP_CON_LP_TIMO;
NG_NODE_UNREF(con->l2cap->node);
} /* ng_l2cap_lp_untimeout */
diff --git a/sys/netgraph/bluetooth/l2cap/ng_l2cap_misc.h b/sys/netgraph/bluetooth/l2cap/ng_l2cap_misc.h
index f0f72a3..a20d5b9 100644
--- a/sys/netgraph/bluetooth/l2cap/ng_l2cap_misc.h
+++ b/sys/netgraph/bluetooth/l2cap/ng_l2cap_misc.h
@@ -25,7 +25,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: ng_l2cap_misc.h,v 1.6 2002/04/16 00:43:57 max Exp $
+ * $Id: ng_l2cap_misc.h,v 1.2 2003/04/28 21:44:59 max Exp $
* $FreeBSD$
*/
@@ -39,6 +39,8 @@ void ng_l2cap_send_hook_info (node_p, hook_p, void *, int);
*/
ng_l2cap_con_p ng_l2cap_new_con (ng_l2cap_p, bdaddr_p);
+void ng_l2cap_con_ref (ng_l2cap_con_p);
+void ng_l2cap_con_unref (ng_l2cap_con_p);
ng_l2cap_con_p ng_l2cap_con_by_addr (ng_l2cap_p, bdaddr_p);
ng_l2cap_con_p ng_l2cap_con_by_handle (ng_l2cap_p, u_int16_t);
void ng_l2cap_free_con (ng_l2cap_con_p);
@@ -58,11 +60,13 @@ void ng_l2cap_free_chan (ng_l2cap_chan_p);
#define ng_l2cap_link_cmd(con, cmd) \
do { \
TAILQ_INSERT_TAIL(&(con)->cmd_list, (cmd), next); \
+ ng_l2cap_con_ref((con)); \
} while (0)
#define ng_l2cap_unlink_cmd(cmd) \
do { \
TAILQ_REMOVE(&((cmd)->con->cmd_list), (cmd), next); \
+ ng_l2cap_con_unref((cmd)->con); \
} while (0)
#define ng_l2cap_free_cmd(cmd) \
@@ -84,6 +88,8 @@ u_int8_t ng_l2cap_get_ident (ng_l2cap_con_p);
* Timeout
*/
+void ng_l2cap_discon_timeout (ng_l2cap_con_p);
+void ng_l2cap_discon_untimeout (ng_l2cap_con_p);
void ng_l2cap_lp_timeout (ng_l2cap_con_p);
void ng_l2cap_lp_untimeout (ng_l2cap_con_p);
void ng_l2cap_command_timeout (ng_l2cap_cmd_p, int);
diff --git a/sys/netgraph/bluetooth/l2cap/ng_l2cap_prse.h b/sys/netgraph/bluetooth/l2cap/ng_l2cap_prse.h
index 5209c24..7c64e7c 100644
--- a/sys/netgraph/bluetooth/l2cap/ng_l2cap_prse.h
+++ b/sys/netgraph/bluetooth/l2cap/ng_l2cap_prse.h
@@ -25,7 +25,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: ng_l2cap_prse.h,v 1.2 2002/09/04 21:38:38 max Exp $
+ * $Id: ng_l2cap_prse.h,v 1.2 2003/04/28 21:44:59 max Exp $
* $FreeBSD$
*/
@@ -64,6 +64,20 @@ static const struct ng_cmdlist ng_l2cap_cmdlist[] = {
&ng_parse_uint16_type,
NULL
},
+ {
+ NGM_L2CAP_COOKIE,
+ NGM_L2CAP_NODE_GET_AUTO_DISCON_TIMO,
+ "get_disc_timo",
+ NULL,
+ &ng_parse_uint16_type
+ },
+ {
+ NGM_L2CAP_COOKIE,
+ NGM_L2CAP_NODE_SET_AUTO_DISCON_TIMO,
+ "set_disc_timo",
+ &ng_parse_uint16_type,
+ NULL
+ },
{ 0, }
};
diff --git a/sys/netgraph/bluetooth/l2cap/ng_l2cap_ulpi.c b/sys/netgraph/bluetooth/l2cap/ng_l2cap_ulpi.c
index c913d1c..d928805 100644
--- a/sys/netgraph/bluetooth/l2cap/ng_l2cap_ulpi.c
+++ b/sys/netgraph/bluetooth/l2cap/ng_l2cap_ulpi.c
@@ -25,7 +25,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: ng_l2cap_ulpi.c,v 1.22 2002/09/08 23:35:51 max Exp $
+ * $Id: ng_l2cap_ulpi.c,v 1.1 2002/11/24 19:47:06 max Exp $
* $FreeBSD$
*/
diff --git a/sys/netgraph/bluetooth/l2cap/ng_l2cap_ulpi.h b/sys/netgraph/bluetooth/l2cap/ng_l2cap_ulpi.h
index 6c464e6..109b5b7 100644
--- a/sys/netgraph/bluetooth/l2cap/ng_l2cap_ulpi.h
+++ b/sys/netgraph/bluetooth/l2cap/ng_l2cap_ulpi.h
@@ -25,7 +25,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: ng_l2cap_ulpi.h,v 1.5 2002/07/04 21:48:53 max Exp $
+ * $Id: ng_l2cap_ulpi.h,v 1.1 2002/11/24 19:47:06 max Exp $
* $FreeBSD$
*/
diff --git a/sys/netgraph/bluetooth/l2cap/ng_l2cap_var.h b/sys/netgraph/bluetooth/l2cap/ng_l2cap_var.h
index 057fa28..f643b51 100644
--- a/sys/netgraph/bluetooth/l2cap/ng_l2cap_var.h
+++ b/sys/netgraph/bluetooth/l2cap/ng_l2cap_var.h
@@ -25,7 +25,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: ng_l2cap_var.h,v 1.13 2002/09/04 21:38:38 max Exp $
+ * $Id: ng_l2cap_var.h,v 1.2 2003/04/28 21:44:59 max Exp $
* $FreeBSD$
*/
@@ -78,10 +78,11 @@ typedef struct ng_l2cap {
ng_l2cap_node_debug_ep debug; /* debug level */
ng_l2cap_node_flags_ep flags; /* L2CAP node flags */
+ ng_l2cap_node_auto_discon_ep discon_timo; /* auto discon. timeout */
- bdaddr_t bdaddr; /* unit BDADDR */
u_int16_t pkt_size; /* max. ACL packet size */
u_int16_t num_pkts; /* out queue size */
+ bdaddr_t bdaddr; /* unit BDADDR */
hook_p hci; /* HCI downstream hook */
hook_p l2c; /* L2CAP upstream hook */
@@ -104,6 +105,9 @@ typedef struct ng_l2cap_con {
ng_l2cap_p l2cap; /* pointer to L2CAP */
u_int16_t state; /* ACL connection state */
+ u_int16_t flags; /* ACL connection flags */
+
+ int32_t refcnt; /* reference count */
bdaddr_t remote; /* remote unit address */
u_int16_t con_handle; /* ACL connection handle */
OpenPOWER on IntegriCloud