4 * Copyright (c) 2001-2002 Maksim Yevmenkin <m_evmenkin@yahoo.com>
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * $Id: ng_h4.c,v 1.10 2005/10/31 17:57:43 max Exp $
31 * $FreeBSD: src/sys/netgraph/bluetooth/drivers/h4/ng_h4.c,v 1.17 2007/08/13 17:19:28 emax Exp $
32 * $DragonFly: src/sys/netgraph7/bluetooth/drivers/h4/ng_h4.c,v 1.2 2008/06/26 23:05:40 dillon Exp $
33 * $DragonFly: src/sys/netgraph7/bluetooth/drivers/h4/ng_h4.c,v 1.2 2008/06/26 23:05:40 dillon Exp $
38 * FreeBSD: src/sys/netgraph/ng_tty.c
39 * Author: Archie Cobbs <archie@freebsd.org>
43 #include <sys/param.h>
44 #include <sys/systm.h>
45 #include <sys/kernel.h>
47 #include <sys/endian.h>
48 #include <sys/errno.h>
49 #include <sys/fcntl.h>
50 #include <sys/malloc.h>
53 #include <sys/socket.h>
55 #include <sys/ttycom.h>
57 #include <net/if_var.h>
58 #include "ng_message.h"
61 #include "bluetooth/include/ng_bluetooth.h"
62 #include "bluetooth/include/ng_hci.h"
63 #include "bluetooth/include/ng_h4.h"
64 #include "bluetooth/drivers/h4/ng_h4_var.h"
65 #include "bluetooth/drivers/h4/ng_h4_prse.h"
67 /*****************************************************************************
68 *****************************************************************************
69 ** This node implements a Bluetooth HCI UART transport layer as per chapter
70 ** H4 of the Bluetooth Specification Book v1.1. It is a terminal line
71 ** discipline that is also a netgraph node. Installing this line discipline
72 ** on a terminal device instantiates a new netgraph node of this type, which
73 ** allows access to the device via the "hook" hook of the node.
75 ** Once the line discipline is installed, you can find out the name of the
76 ** corresponding netgraph node via a NGIOCGINFO ioctl().
77 *****************************************************************************
78 *****************************************************************************/
81 #ifndef NG_SEPARATE_MALLOC
82 MALLOC_DEFINE(M_NETGRAPH_H4, "netgraph_h4", "Netgraph Bluetooth H4 node");
84 #define M_NETGRAPH_H4 M_NETGRAPH
85 #endif /* NG_SEPARATE_MALLOC */
87 /* Line discipline methods */
88 static int ng_h4_open (struct cdev *, struct tty *);
89 static int ng_h4_close (struct tty *, int);
90 static int ng_h4_read (struct tty *, struct uio *, int);
91 static int ng_h4_write (struct tty *, struct uio *, int);
92 static int ng_h4_input (int, struct tty *);
93 static int ng_h4_start (struct tty *);
94 static int ng_h4_ioctl (struct tty *, u_long, caddr_t,
95 int, struct thread *);
97 /* Line discipline descriptor */
98 static struct linesw ng_h4_disc = {
99 ng_h4_open, /* open */
100 ng_h4_close, /* close */
101 ng_h4_read, /* read */
102 ng_h4_write, /* write */
103 ng_h4_ioctl, /* ioctl */
104 ng_h4_input, /* input */
105 ng_h4_start, /* start */
109 /* Netgraph methods */
110 static ng_constructor_t ng_h4_constructor;
111 static ng_rcvmsg_t ng_h4_rcvmsg;
112 static ng_shutdown_t ng_h4_shutdown;
113 static ng_newhook_t ng_h4_newhook;
114 static ng_connect_t ng_h4_connect;
115 static ng_rcvdata_t ng_h4_rcvdata;
116 static ng_disconnect_t ng_h4_disconnect;
119 static void ng_h4_process_timeout (node_p, hook_p, void *, int);
120 static int ng_h4_mod_event (module_t, int, void *);
122 /* Netgraph node type descriptor */
123 static struct ng_type typestruct = {
124 .version = NG_ABI_VERSION,
125 .name = NG_H4_NODE_TYPE,
126 .mod_event = ng_h4_mod_event,
127 .constructor = ng_h4_constructor,
128 .rcvmsg = ng_h4_rcvmsg,
129 .shutdown = ng_h4_shutdown,
130 .newhook = ng_h4_newhook,
131 .connect = ng_h4_connect,
132 .rcvdata = ng_h4_rcvdata,
133 .disconnect = ng_h4_disconnect,
134 .cmdlist = ng_h4_cmdlist
136 NETGRAPH_INIT(h4, &typestruct);
137 MODULE_VERSION(ng_h4, NG_BLUETOOTH_VERSION);
139 static int ng_h4_node = 0;
141 /*****************************************************************************
142 *****************************************************************************
143 ** Line discipline methods
144 *****************************************************************************
145 *****************************************************************************/
148 * Set our line discipline on the tty.
152 ng_h4_open(struct cdev *dev, struct tty *tp)
154 struct thread *td = curthread;
155 char name[NG_NODESIZ];
156 ng_h4_info_p sc = NULL;
159 /* Super-user only */
160 error = priv_check(td, PRIV_NETGRAPH_TTY); /* XXX */
164 /* Initialize private struct */
165 MALLOC(sc, ng_h4_info_p, sizeof(*sc), M_NETGRAPH_H4, M_WAITOK | M_NULLOK | M_ZERO);
169 lwkt_gettoken(&tty_token);
171 sc->debug = NG_H4_WARN_LEVEL;
173 sc->state = NG_H4_W4_PKT_IND;
177 mtx_init(&sc->outq.ifq_mtx, "ng_h4 node+queue", NULL, MTX_DEF);
178 IFQ_SET_MAXLEN(&sc->outq, NG_H4_DEFAULTQLEN);
179 ng_callout_init(&sc->timo);
183 /* Setup netgraph node */
184 error = ng_make_node_common(&typestruct, &sc->node);
188 printf("%s: Unable to create new node!\n", __func__);
190 mtx_destroy(&sc->outq.ifq_mtx);
191 bzero(sc, sizeof(*sc));
192 FREE(sc, M_NETGRAPH_H4);
194 lwkt_reltoken(&tty_token);
198 /* Assign node its name */
199 snprintf(name, sizeof(name), "%s%d", typestruct.name, ng_h4_node ++);
201 error = ng_name_node(sc->node, name);
205 printf("%s: %s - node name exists?\n", __func__, name);
207 NG_NODE_UNREF(sc->node);
208 mtx_destroy(&sc->outq.ifq_mtx);
209 bzero(sc, sizeof(*sc));
210 FREE(sc, M_NETGRAPH_H4);
212 lwkt_reltoken(&tty_token);
216 /* Set back pointers */
217 NG_NODE_SET_PRIVATE(sc->node, sc);
218 tp->t_lsc = (caddr_t) sc;
220 /* The node has to be a WRITER because data can change node status */
221 NG_NODE_FORCE_WRITER(sc->node);
224 * Pre-allocate cblocks to the an appropriate amount.
225 * I'm not sure what is appropriate.
228 ttyflush(tp, FREAD | FWRITE);
229 clist_alloc_cblocks(&tp->t_canq, 0, 0);
230 clist_alloc_cblocks(&tp->t_rawq, 0, 0);
231 clist_alloc_cblocks(&tp->t_outq,
232 MLEN + NG_H4_HIWATER, MLEN + NG_H4_HIWATER);
236 lwkt_reltoken(&tty_token);
241 * Line specific close routine, called from device close routine
242 * and from ttioctl. This causes the node to be destroyed as well.
246 ng_h4_close(struct tty *tp, int flag)
248 ng_h4_info_p sc = (ng_h4_info_p) tp->t_lsc;
250 lwkt_gettoken(&tty_token);
251 ttyflush(tp, FREAD | FWRITE);
252 clist_free_cblocks(&tp->t_outq);
257 if (callout_pending(&sc->timo))
258 ng_uncallout(&sc->timo, sc->node);
265 ng_rmnode_self(sc->node);
268 lwkt_reltoken(&tty_token);
273 * Once the device has been turned into a node, we don't allow reading.
277 ng_h4_read(struct tty *tp, struct uio *uio, int flag)
283 * Once the device has been turned into a node, we don't allow writing.
287 ng_h4_write(struct tty *tp, struct uio *uio, int flag)
293 * We implement the NGIOCGINFO ioctl() defined in ng_message.h.
297 ng_h4_ioctl(struct tty *tp, u_long cmd, caddr_t data, int flag,
300 ng_h4_info_p sc = (ng_h4_info_p) tp->t_lsc;
306 lwkt_gettoken(&tty_token);
312 #define NI(x) ((struct nodeinfo *)(x))
314 bzero(data, sizeof(*NI(data)));
316 if (NG_NODE_HAS_NAME(sc->node))
317 strncpy(NI(data)->name, NG_NODE_NAME(sc->node),
318 sizeof(NI(data)->name) - 1);
320 strncpy(NI(data)->type, sc->node->nd_type->name,
321 sizeof(NI(data)->type) - 1);
323 NI(data)->id = (u_int32_t) ng_node2ID(sc->node);
324 NI(data)->hooks = NG_NODE_NUMHOOKS(sc->node);
334 lwkt_reltoken(&tty_token);
339 * Receive data coming from the device. We get one character at a time, which
344 ng_h4_input(int c, struct tty *tp)
346 ng_h4_info_p sc = (ng_h4_info_p) tp->t_lsc;
348 lwkt_gettoken(&tty_token);
349 if (sc == NULL || tp != sc->tp ||
350 sc->node == NULL || NG_NODE_NOT_VALID(sc->node)) {
351 lwkt_reltoken(&tty_token);
357 /* Check for error conditions */
358 if ((tp->t_state & TS_CONNECTED) == 0) {
359 NG_H4_INFO("%s: %s - no carrier\n", __func__,
360 NG_NODE_NAME(sc->node));
362 sc->state = NG_H4_W4_PKT_IND;
368 lwkt_reltoken(&tty_token);
369 return (0); /* XXX Loss of synchronization here! */
372 /* Check for framing error or overrun on this char */
373 if (c & TTY_ERRORMASK) {
374 NG_H4_ERR("%s: %s - line error %#x, c=%#x\n", __func__,
375 NG_NODE_NAME(sc->node), c & TTY_ERRORMASK,
378 NG_H4_STAT_IERROR(sc->stat);
380 sc->state = NG_H4_W4_PKT_IND;
386 lwkt_reltoken(&tty_token);
387 return (0); /* XXX Loss of synchronization here! */
390 NG_H4_STAT_BYTES_RECV(sc->stat, 1);
392 /* Append char to mbuf */
393 if (sc->got >= sizeof(sc->ibuf)) {
394 NG_H4_ALERT("%s: %s - input buffer overflow, c=%#x, got=%d\n",
395 __func__, NG_NODE_NAME(sc->node), c & TTY_CHARMASK,
398 NG_H4_STAT_IERROR(sc->stat);
400 sc->state = NG_H4_W4_PKT_IND;
406 lwkt_reltoken(&tty_token);
407 return (0); /* XXX Loss of synchronization here! */
410 sc->ibuf[sc->got ++] = (c & TTY_CHARMASK);
412 NG_H4_INFO("%s: %s - got char %#x, want=%d, got=%d\n", __func__,
413 NG_NODE_NAME(sc->node), c, sc->want, sc->got);
415 if (sc->got < sc->want) {
418 lwkt_reltoken(&tty_token);
419 return (0); /* Wait for more */
423 /* Got packet indicator */
424 case NG_H4_W4_PKT_IND:
425 NG_H4_INFO("%s: %s - got packet indicator %#x\n", __func__,
426 NG_NODE_NAME(sc->node), sc->ibuf[0]);
428 sc->state = NG_H4_W4_PKT_HDR;
431 * Since packet indicator included in the packet header
432 * just set sc->want to sizeof(packet header).
435 switch (sc->ibuf[0]) {
436 case NG_HCI_ACL_DATA_PKT:
437 sc->want = sizeof(ng_hci_acldata_pkt_t);
440 case NG_HCI_SCO_DATA_PKT:
441 sc->want = sizeof(ng_hci_scodata_pkt_t);
444 case NG_HCI_EVENT_PKT:
445 sc->want = sizeof(ng_hci_event_pkt_t);
449 NG_H4_WARN("%s: %s - ignoring unknown packet " \
450 "type=%#x\n", __func__, NG_NODE_NAME(sc->node),
453 NG_H4_STAT_IERROR(sc->stat);
455 sc->state = NG_H4_W4_PKT_IND;
462 /* Got packet header */
463 case NG_H4_W4_PKT_HDR:
464 sc->state = NG_H4_W4_PKT_DATA;
466 switch (sc->ibuf[0]) {
467 case NG_HCI_ACL_DATA_PKT:
468 c = le16toh(((ng_hci_acldata_pkt_t *)
469 (sc->ibuf))->length);
472 case NG_HCI_SCO_DATA_PKT:
473 c = ((ng_hci_scodata_pkt_t *)(sc->ibuf))->length;
476 case NG_HCI_EVENT_PKT:
477 c = ((ng_hci_event_pkt_t *)(sc->ibuf))->length;
481 KASSERT((0), ("Invalid packet type=%#x\n",
486 NG_H4_INFO("%s: %s - got packet header, packet type=%#x, " \
487 "packet size=%d, payload size=%d\n", __func__,
488 NG_NODE_NAME(sc->node), sc->ibuf[0], sc->got, c);
494 * Try to prevent possible buffer overrun
496 * XXX I'm *really* confused here. It turns out
497 * that Xircom card sends us packets with length
498 * greater then 512 bytes! This is greater then
499 * our old receive buffer (ibuf) size. In the same
500 * time the card demands from us *not* to send
501 * packets greater then 192 bytes. Weird! How the
502 * hell i should know how big *receive* buffer
503 * should be? For now increase receiving buffer
504 * size to 1K and add the following check.
507 if (sc->want >= sizeof(sc->ibuf)) {
510 NG_H4_ALERT("%s: %s - packet too big for " \
511 "buffer, type=%#x, got=%d, want=%d, " \
512 "length=%d\n", __func__,
513 NG_NODE_NAME(sc->node), sc->ibuf[0],
514 sc->got, sc->want, c);
516 NG_H4_ALERT("Packet header:\n");
517 for (b = 0; b < sc->got; b++)
518 NG_H4_ALERT("%#x ", sc->ibuf[b]);
522 NG_H4_STAT_IERROR(sc->stat);
524 sc->state = NG_H4_W4_PKT_IND;
532 /* else FALLTHROUGH and deliver frame */
533 /* XXX Is this true? Should we deliver empty frame? */
535 /* Got packet data */
536 case NG_H4_W4_PKT_DATA:
537 NG_H4_INFO("%s: %s - got full packet, packet type=%#x, " \
538 "packet size=%d\n", __func__,
539 NG_NODE_NAME(sc->node), sc->ibuf[0], sc->got);
541 if (sc->hook != NULL && NG_HOOK_IS_VALID(sc->hook)) {
542 struct mbuf *m = NULL;
544 MGETHDR(m, MB_DONTWAIT, MT_DATA);
548 /* XXX m_copyback() is stupid */
549 m->m_len = min(MHLEN, sc->got);
551 m_copyback(m, 0, sc->got, sc->ibuf);
552 NG_SEND_DATA_ONLY(c, sc->hook, m);
554 NG_H4_ERR("%s: %s - could not get mbuf\n",
555 __func__, NG_NODE_NAME(sc->node));
557 NG_H4_STAT_IERROR(sc->stat);
561 sc->state = NG_H4_W4_PKT_IND;
565 NG_H4_STAT_PCKTS_RECV(sc->stat);
569 KASSERT((0), ("Invalid H4 node state=%d", sc->state));
575 lwkt_reltoken(&tty_token);
580 * This is called when the device driver is ready for more output. Called from
585 ng_h4_start(struct tty *tp)
587 ng_h4_info_p sc = (ng_h4_info_p) tp->t_lsc;
588 struct mbuf *m = NULL;
591 lwkt_gettoken(&tty_token);
592 if (sc == NULL || tp != sc->tp ||
593 sc->node == NULL || NG_NODE_NOT_VALID(sc->node)) {
594 lwkt_reltoken(&tty_token);
599 while (tp->t_outq.c_cc < NG_H4_HIWATER) { /* XXX 2.2 specific ? */
603 /* Remove first mbuf from queue */
604 IF_DEQUEUE(&sc->outq, m);
608 /* Send as much of it as possible */
610 size = m->m_len - b_to_q(mtod(m, u_char *),
611 m->m_len, &tp->t_outq);
614 NG_H4_STAT_BYTES_SENT(sc->stat, size);
620 break; /* device can't take no more */
625 /* Put remainder of mbuf chain (if any) back on queue */
627 IF_PREPEND(&sc->outq, m);
631 /* Full packet has been sent */
633 NG_H4_STAT_PCKTS_SENT(sc->stat);
638 * Call output process whether or not there is any output. We are
639 * being called in lieu of ttstart and must do what it would.
645 * This timeout is needed for operation on a pseudo-tty, because the
646 * pty code doesn't call pppstart after it has drained the t_outq.
651 if (!IFQ_IS_EMPTY(&sc->outq) && !callout_pending(&sc->timo))
652 ng_callout(&sc->timo, sc->node, NULL, 1,
653 ng_h4_process_timeout, NULL, 0);
657 lwkt_reltoken(&tty_token);
661 /*****************************************************************************
662 *****************************************************************************
663 ** Netgraph node methods
664 *****************************************************************************
665 *****************************************************************************/
668 * Initialize a new node of this type. We only allow nodes to be created as
669 * a result of setting the line discipline on a tty, so always return an error
674 ng_h4_constructor(node_p node)
677 } /* ng_h4_constructor */
680 * Add a new hook. There can only be one.
684 ng_h4_newhook(node_p node, hook_p hook, const char *name)
686 ng_h4_info_p sc = (ng_h4_info_p) NG_NODE_PRIVATE(node);
688 if (strcmp(name, NG_H4_HOOK) != 0)
693 if (sc->hook != NULL) {
702 } /* ng_h4_newhook */
705 * Connect hook. Just say yes.
709 ng_h4_connect(hook_p hook)
711 ng_h4_info_p sc = (ng_h4_info_p) NG_NODE_PRIVATE(NG_HOOK_NODE(hook));
713 if (hook != sc->hook)
714 panic("%s: hook != sc->hook\n", __func__);
716 NG_HOOK_FORCE_QUEUE(NG_HOOK_PEER(hook));
717 NG_HOOK_FORCE_QUEUE(hook);
720 } /* ng_h4_connect */
723 * Disconnect the hook
727 ng_h4_disconnect(hook_p hook)
729 ng_h4_info_p sc = (ng_h4_info_p) NG_NODE_PRIVATE(NG_HOOK_NODE(hook));
732 * We need to check for sc != NULL because we can be called from
733 * ng_h4_close() via ng_rmnode_self()
737 if (hook != sc->hook)
738 panic("%s: hook != sc->hook\n", __func__);
742 /* XXX do we have to untimeout and drain out queue? */
743 if (callout_pending(&sc->timo))
744 ng_uncallout(&sc->timo, sc->node);
746 _IF_DRAIN(&sc->outq);
748 sc->state = NG_H4_W4_PKT_IND;
758 } /* ng_h4_disconnect */
761 * Remove this node. The does the netgraph portion of the shutdown.
762 * This should only be called indirectly from ng_h4_close().
766 ng_h4_shutdown(node_p node)
768 ng_h4_info_p sc = (ng_h4_info_p) NG_NODE_PRIVATE(node);
775 NG_NODE_REVIVE(node); /* we will persist */
782 NG_NODE_SET_PRIVATE(node, NULL);
784 _IF_DRAIN(&sc->outq);
787 mtx_destroy(&sc->outq.ifq_mtx);
788 bzero(sc, sizeof(*sc));
789 FREE(sc, M_NETGRAPH_H4);
792 } /* ng_h4_shutdown */
795 * Receive incoming data from Netgraph system. Put it on our
796 * output queue and start output if necessary.
800 ng_h4_rcvdata(hook_p hook, item_p item)
802 ng_h4_info_p sc = (ng_h4_info_p)NG_NODE_PRIVATE(NG_HOOK_NODE(hook));
803 struct mbuf *m = NULL;
809 if (hook != sc->hook)
810 panic("%s: hook != sc->hook\n", __func__);
817 if (_IF_QFULL(&sc->outq)) {
818 NG_H4_ERR("%s: %s - dropping mbuf, len=%d\n", __func__,
819 NG_NODE_NAME(sc->node), m->m_pkthdr.len);
821 NG_H4_STAT_OERROR(sc->stat);
831 NG_H4_INFO("%s: %s - queue mbuf, len=%d\n", __func__,
832 NG_NODE_NAME(sc->node), m->m_pkthdr.len);
834 _IF_ENQUEUE(&sc->outq, m);
835 qlen = _IF_QLEN(&sc->outq);
840 * If qlen > 1, then we should already have a scheduled callout
850 } /* ng_h4_rcvdata */
853 * Receive control message
857 ng_h4_rcvmsg(node_p node, item_p item, hook_p lasthook)
859 ng_h4_info_p sc = (ng_h4_info_p) NG_NODE_PRIVATE(node);
860 struct ng_mesg *msg = NULL, *resp = NULL;
866 NGI_GET_MSG(item, msg);
869 switch (msg->header.typecookie) {
870 case NGM_GENERIC_COOKIE:
871 switch (msg->header.cmd) {
872 case NGM_TEXT_STATUS:
873 NG_MKRESPONSE(resp, msg, NG_TEXTRESPONSE, M_WAITOK | M_NULLOK);
877 snprintf(resp->data, NG_TEXTRESPONSE,
881 "Queue: [have:%d,max:%d]\n" \
882 "Input: [got:%d,want:%d]",
883 (sc->hook != NULL)? NG_H4_HOOK : "",
899 switch (msg->header.cmd) {
900 case NGM_H4_NODE_RESET:
901 _IF_DRAIN(&sc->outq);
902 sc->state = NG_H4_W4_PKT_IND;
907 case NGM_H4_NODE_GET_STATE:
908 NG_MKRESPONSE(resp, msg, sizeof(ng_h4_node_state_ep),
909 M_WAITOK | M_NULLOK);
913 *((ng_h4_node_state_ep *)(resp->data)) =
917 case NGM_H4_NODE_GET_DEBUG:
918 NG_MKRESPONSE(resp, msg, sizeof(ng_h4_node_debug_ep),
919 M_WAITOK | M_NULLOK);
923 *((ng_h4_node_debug_ep *)(resp->data)) =
927 case NGM_H4_NODE_SET_DEBUG:
928 if (msg->header.arglen != sizeof(ng_h4_node_debug_ep))
932 *((ng_h4_node_debug_ep *)(msg->data));
935 case NGM_H4_NODE_GET_QLEN:
936 NG_MKRESPONSE(resp, msg, sizeof(ng_h4_node_qlen_ep),
937 M_WAITOK | M_NULLOK);
941 *((ng_h4_node_qlen_ep *)(resp->data)) =
945 case NGM_H4_NODE_SET_QLEN:
946 if (msg->header.arglen != sizeof(ng_h4_node_qlen_ep))
948 else if (*((ng_h4_node_qlen_ep *)(msg->data)) <= 0)
951 IFQ_SET_MAXLEN(&sc->outq,
952 *((ng_h4_node_qlen_ep *)(msg->data)));
955 case NGM_H4_NODE_GET_STAT:
956 NG_MKRESPONSE(resp, msg, sizeof(ng_h4_node_stat_ep),
957 M_WAITOK | M_NULLOK);
961 bcopy(&sc->stat, resp->data,
962 sizeof(ng_h4_node_stat_ep));
965 case NGM_H4_NODE_RESET_STAT:
966 NG_H4_STAT_RESET(sc->stat);
982 NG_RESPOND_MSG(error, node, item, resp);
989 * Timeout processing function.
990 * We still have data to output to the device, so try sending more.
994 ng_h4_process_timeout(node_p node, hook_p hook, void *arg1, int arg2)
996 ng_h4_info_p sc = (ng_h4_info_p) NG_NODE_PRIVATE(node);
1001 } /* ng_h4_process_timeout */
1004 * Handle loading and unloading for this node type
1008 ng_h4_mod_event(module_t mod, int event, void *data)
1010 static int ng_h4_ldisc;
1015 /* Register line discipline */
1017 ng_h4_ldisc = ldisc_register(H4DISC, &ng_h4_disc);
1020 if (ng_h4_ldisc < 0) {
1021 printf("%s: can't register H4 line discipline\n",
1028 /* Unregister line discipline */
1030 ldisc_deregister(ng_h4_ldisc);
1040 } /* ng_h4_mod_event */