6 * 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.7 2004/08/23 18:08:15 max Exp $
36 * FreeBSD: src/sys/netgraph/ng_tty.c
37 * Author: Archie Cobbs <archie@freebsd.org>
41 #include <sys/param.h>
42 #include <sys/systm.h>
43 #include <sys/kernel.h>
45 #include <sys/endian.h>
46 #include <sys/errno.h>
47 #include <sys/fcntl.h>
48 #include <sys/ioccom.h>
49 #include <sys/malloc.h>
53 #include <sys/ttycom.h>
54 #include <netgraph/ng_message.h>
55 #include <netgraph/netgraph.h>
56 #include <netgraph/ng_parse.h>
57 #include <netgraph/bluetooth/include/ng_bluetooth.h>
58 #include <netgraph/bluetooth/include/ng_hci.h>
59 #include <netgraph/bluetooth/include/ng_h4.h>
60 #include <netgraph/bluetooth/drivers/h4/ng_h4_var.h>
61 #include <netgraph/bluetooth/drivers/h4/ng_h4_prse.h>
63 /*****************************************************************************
64 *****************************************************************************
65 ** This node implements a Bluetooth HCI UART transport layer as per chapter
66 ** H4 of the Bluetooth Specification Book v1.1. It is a terminal line
67 ** discipline that is also a netgraph node. Installing this line discipline
68 ** on a terminal device instantiates a new netgraph node of this type, which
69 ** allows access to the device via the "hook" hook of the node.
71 ** Once the line discipline is installed, you can find out the name of the
72 ** corresponding netgraph node via a NGIOCGINFO ioctl().
73 *****************************************************************************
74 *****************************************************************************/
76 NET_NEEDS_GIANT("ng_h4");
79 #ifndef NG_SEPARATE_MALLOC
80 MALLOC_DEFINE(M_NETGRAPH_H4, "netgraph_h4", "Netgraph Bluetooth H4 node");
82 #define M_NETGRAPH_H4 M_NETGRAPH
83 #endif /* NG_SEPARATE_MALLOC */
85 /* Line discipline methods */
86 static int ng_h4_open (struct cdev *, struct tty *);
87 static int ng_h4_close (struct tty *, int);
88 static int ng_h4_read (struct tty *, struct uio *, int);
89 static int ng_h4_write (struct tty *, struct uio *, int);
90 static int ng_h4_input (int, struct tty *);
91 static int ng_h4_start (struct tty *);
92 static void ng_h4_start2 (node_p, hook_p, void *, int);
93 static int ng_h4_ioctl (struct tty *, u_long, caddr_t,
94 int, struct thread *);
96 /* Line discipline descriptor */
97 static struct linesw ng_h4_disc = {
98 ng_h4_open, /* open */
99 ng_h4_close, /* close */
100 ng_h4_read, /* read */
101 ng_h4_write, /* write */
102 ng_h4_ioctl, /* ioctl */
103 ng_h4_input, /* input */
104 ng_h4_start, /* start */
108 /* Netgraph methods */
109 static ng_constructor_t ng_h4_constructor;
110 static ng_rcvmsg_t ng_h4_rcvmsg;
111 static ng_shutdown_t ng_h4_shutdown;
112 static ng_newhook_t ng_h4_newhook;
113 static ng_connect_t ng_h4_connect;
114 static ng_rcvdata_t ng_h4_rcvdata;
115 static ng_disconnect_t ng_h4_disconnect;
118 static void ng_h4_timeout (node_p);
119 static void ng_h4_untimeout (node_p);
120 static void ng_h4_process_timeout (node_p, hook_p, void *, int);
121 static int ng_h4_mod_event (module_t, int, void *);
123 /* Netgraph node type descriptor */
124 static struct ng_type typestruct = {
125 .version = NG_ABI_VERSION,
126 .name = NG_H4_NODE_TYPE,
127 .mod_event = ng_h4_mod_event,
128 .constructor = ng_h4_constructor,
129 .rcvmsg = ng_h4_rcvmsg,
130 .shutdown = ng_h4_shutdown,
131 .newhook = ng_h4_newhook,
132 .connect = ng_h4_connect,
133 .rcvdata = ng_h4_rcvdata,
134 .disconnect = ng_h4_disconnect,
135 .cmdlist = ng_h4_cmdlist
137 NETGRAPH_INIT(h4, &typestruct);
138 MODULE_VERSION(ng_h4, NG_BLUETOOTH_VERSION);
140 static int ng_h4_node = 0;
142 /*****************************************************************************
143 *****************************************************************************
144 ** Line discipline methods
145 *****************************************************************************
146 *****************************************************************************/
149 * Set our line discipline on the tty.
153 ng_h4_open(struct cdev *dev, struct tty *tp)
155 char name[NG_NODESIZ];
156 ng_h4_info_p sc = NULL;
159 /* Super-user only */
160 error = priv_check(curthread, PRIV_NETGRAPH_TTY); /* XXX */
164 s = splnet(); /* XXX */
167 /* Initialize private struct */
168 MALLOC(sc, ng_h4_info_p, sizeof(*sc), M_NETGRAPH_H4, M_NOWAIT|M_ZERO);
175 sc->debug = NG_H4_WARN_LEVEL;
177 sc->state = NG_H4_W4_PKT_IND;
181 NG_BT_MBUFQ_INIT(&sc->outq, NG_H4_DEFAULTQLEN);
182 ng_callout_init(&sc->timo);
184 /* Setup netgraph node */
185 error = ng_make_node_common(&typestruct, &sc->node);
187 bzero(sc, sizeof(*sc));
188 FREE(sc, M_NETGRAPH_H4);
192 /* Assign node its name */
193 snprintf(name, sizeof(name), "%s%d", typestruct.name, ng_h4_node ++);
195 error = ng_name_node(sc->node, name);
197 NG_H4_ALERT("%s: %s - node name exists?\n", __func__, name);
198 NG_NODE_UNREF(sc->node);
199 bzero(sc, sizeof(*sc));
200 FREE(sc, M_NETGRAPH_H4);
204 /* Set back pointers */
205 NG_NODE_SET_PRIVATE(sc->node, sc);
206 tp->t_lsc = (caddr_t) sc;
208 /* The node has to be a WRITER because data can change node status */
209 NG_NODE_FORCE_WRITER(sc->node);
212 * Pre-allocate cblocks to the an appropriate amount.
213 * I'm not sure what is appropriate.
216 ttyflush(tp, FREAD | FWRITE);
217 clist_alloc_cblocks(&tp->t_canq, 0, 0);
218 clist_alloc_cblocks(&tp->t_rawq, 0, 0);
219 clist_alloc_cblocks(&tp->t_outq,
220 MLEN + NG_H4_HIWATER, MLEN + NG_H4_HIWATER);
228 * Line specific close routine, called from device close routine
229 * and from ttioctl. This causes the node to be destroyed as well.
233 ng_h4_close(struct tty *tp, int flag)
235 ng_h4_info_p sc = (ng_h4_info_p) tp->t_lsc;
238 s = spltty(); /* XXX */
240 ttyflush(tp, FREAD | FWRITE);
241 clist_free_cblocks(&tp->t_outq);
245 if (sc->node != NULL) {
246 if (sc->flags & NG_H4_TIMEOUT)
247 ng_h4_untimeout(sc->node);
249 NG_NODE_SET_PRIVATE(sc->node, NULL);
250 ng_rmnode_self(sc->node);
254 NG_BT_MBUFQ_DESTROY(&sc->outq);
255 bzero(sc, sizeof(*sc));
256 FREE(sc, M_NETGRAPH_H4);
265 * Once the device has been turned into a node, we don't allow reading.
269 ng_h4_read(struct tty *tp, struct uio *uio, int flag)
275 * Once the device has been turned into a node, we don't allow writing.
279 ng_h4_write(struct tty *tp, struct uio *uio, int flag)
285 * We implement the NGIOCGINFO ioctl() defined in ng_message.h.
289 ng_h4_ioctl(struct tty *tp, u_long cmd, caddr_t data, int flag,
292 ng_h4_info_p sc = (ng_h4_info_p) tp->t_lsc;
295 s = spltty(); /* XXX */
300 #define NI(x) ((struct nodeinfo *)(x))
302 bzero(data, sizeof(*NI(data)));
304 if (NG_NODE_HAS_NAME(sc->node))
305 strncpy(NI(data)->name, NG_NODE_NAME(sc->node),
306 sizeof(NI(data)->name) - 1);
308 strncpy(NI(data)->type, sc->node->nd_type->name,
309 sizeof(NI(data)->type) - 1);
311 NI(data)->id = (u_int32_t) ng_node2ID(sc->node);
312 NI(data)->hooks = NG_NODE_NUMHOOKS(sc->node);
326 * Receive data coming from the device. We get one character at a time, which
331 ng_h4_input(int c, struct tty *tp)
333 ng_h4_info_p sc = (ng_h4_info_p) tp->t_lsc;
335 if (sc == NULL || tp != sc->tp ||
336 sc->node == NULL || NG_NODE_NOT_VALID(sc->node))
339 /* Check for error conditions */
340 if ((sc->tp->t_state & TS_CONNECTED) == 0) {
341 NG_H4_INFO("%s: %s - no carrier\n", __func__,
342 NG_NODE_NAME(sc->node));
344 sc->state = NG_H4_W4_PKT_IND;
348 return (0); /* XXX Loss of synchronization here! */
351 /* Check for framing error or overrun on this char */
352 if (c & TTY_ERRORMASK) {
353 NG_H4_ERR("%s: %s - line error %#x, c=%#x\n", __func__,
354 NG_NODE_NAME(sc->node), c & TTY_ERRORMASK,
357 NG_H4_STAT_IERROR(sc->stat);
359 sc->state = NG_H4_W4_PKT_IND;
363 return (0); /* XXX Loss of synchronization here! */
366 NG_H4_STAT_BYTES_RECV(sc->stat, 1);
368 /* Append char to mbuf */
369 if (sc->got >= sizeof(sc->ibuf)) {
370 NG_H4_ALERT("%s: %s - input buffer overflow, c=%#x, got=%d\n",
371 __func__, NG_NODE_NAME(sc->node), c & TTY_CHARMASK,
374 NG_H4_STAT_IERROR(sc->stat);
376 sc->state = NG_H4_W4_PKT_IND;
380 return (0); /* XXX Loss of synchronization here! */
383 sc->ibuf[sc->got ++] = (c & TTY_CHARMASK);
385 NG_H4_INFO("%s: %s - got char %#x, want=%d, got=%d\n", __func__,
386 NG_NODE_NAME(sc->node), c, sc->want, sc->got);
388 if (sc->got < sc->want)
389 return (0); /* Wait for more */
392 /* Got packet indicator */
393 case NG_H4_W4_PKT_IND:
394 NG_H4_INFO("%s: %s - got packet indicator %#x\n", __func__,
395 NG_NODE_NAME(sc->node), sc->ibuf[0]);
397 sc->state = NG_H4_W4_PKT_HDR;
400 * Since packet indicator included in the packet header
401 * just set sc->want to sizeof(packet header).
404 switch (sc->ibuf[0]) {
405 case NG_HCI_ACL_DATA_PKT:
406 sc->want = sizeof(ng_hci_acldata_pkt_t);
409 case NG_HCI_SCO_DATA_PKT:
410 sc->want = sizeof(ng_hci_scodata_pkt_t);
413 case NG_HCI_EVENT_PKT:
414 sc->want = sizeof(ng_hci_event_pkt_t);
418 NG_H4_WARN("%s: %s - ignoring unknown packet " \
419 "type=%#x\n", __func__, NG_NODE_NAME(sc->node),
422 NG_H4_STAT_IERROR(sc->stat);
424 sc->state = NG_H4_W4_PKT_IND;
431 /* Got packet header */
432 case NG_H4_W4_PKT_HDR:
433 sc->state = NG_H4_W4_PKT_DATA;
435 switch (sc->ibuf[0]) {
436 case NG_HCI_ACL_DATA_PKT:
437 c = le16toh(((ng_hci_acldata_pkt_t *)
438 (sc->ibuf))->length);
441 case NG_HCI_SCO_DATA_PKT:
442 c = ((ng_hci_scodata_pkt_t *)(sc->ibuf))->length;
445 case NG_HCI_EVENT_PKT:
446 c = ((ng_hci_event_pkt_t *)(sc->ibuf))->length;
450 KASSERT((0), ("Invalid packet type=%#x\n",
455 NG_H4_INFO("%s: %s - got packet header, packet type=%#x, " \
456 "packet size=%d, payload size=%d\n", __func__,
457 NG_NODE_NAME(sc->node), sc->ibuf[0], sc->got, c);
463 * Try to prevent possible buffer overrun
465 * XXX I'm *really* confused here. It turns out
466 * that Xircom card sends us packets with length
467 * greater then 512 bytes! This is greater then
468 * our old receive buffer (ibuf) size. In the same
469 * time the card demands from us *not* to send
470 * packets greater then 192 bytes. Weird! How the
471 * hell i should know how big *receive* buffer
472 * should be? For now increase receiving buffer
473 * size to 1K and add the following check.
476 if (sc->want >= sizeof(sc->ibuf)) {
479 NG_H4_ALERT("%s: %s - packet too big for " \
480 "buffer, type=%#x, got=%d, want=%d, " \
481 "length=%d\n", __func__,
482 NG_NODE_NAME(sc->node), sc->ibuf[0],
483 sc->got, sc->want, c);
485 NG_H4_ALERT("Packet header:\n");
486 for (b = 0; b < sc->got; b++)
487 NG_H4_ALERT("%#x ", sc->ibuf[b]);
491 NG_H4_STAT_IERROR(sc->stat);
493 sc->state = NG_H4_W4_PKT_IND;
501 /* else FALLTHROUGH and deliver frame */
502 /* XXX Is this true? Should we deliver empty frame? */
504 /* Got packet data */
505 case NG_H4_W4_PKT_DATA:
506 NG_H4_INFO("%s: %s - got full packet, packet type=%#x, " \
507 "packet size=%d\n", __func__,
508 NG_NODE_NAME(sc->node), sc->ibuf[0], sc->got);
510 if (sc->hook != NULL && NG_HOOK_IS_VALID(sc->hook)) {
511 struct mbuf *m = NULL;
513 MGETHDR(m, M_DONTWAIT, MT_DATA);
517 /* XXX m_copyback() is stupid */
518 m->m_len = min(MHLEN, sc->got);
520 m_copyback(m, 0, sc->got, sc->ibuf);
521 NG_SEND_DATA_ONLY(c, sc->hook, m);
523 NG_H4_ERR("%s: %s - could not get mbuf\n",
524 __func__, NG_NODE_NAME(sc->node));
526 NG_H4_STAT_IERROR(sc->stat);
530 sc->state = NG_H4_W4_PKT_IND;
534 NG_H4_STAT_PCKTS_RECV(sc->stat);
538 KASSERT((0), ("Invalid H4 node state=%d", sc->state));
546 * This is called when the device driver is ready for more output. Called from
551 ng_h4_start(struct tty *tp)
553 ng_h4_info_p sc = (ng_h4_info_p) tp->t_lsc;
555 if (sc == NULL || tp != sc->tp ||
556 sc->node == NULL || NG_NODE_NOT_VALID(sc->node))
559 return (ng_send_fn(sc->node, NULL, ng_h4_start2, NULL, 0));
563 * Device driver is ready for more output. Part 2. Called (via ng_send_fn)
564 * ng_h4_start() and from ng_h4_rcvdata() when a new mbuf is available for
569 ng_h4_start2(node_p node, hook_p hook, void *arg1, int arg2)
571 ng_h4_info_p sc = (ng_h4_info_p) NG_NODE_PRIVATE(node);
572 struct mbuf *m = NULL;
575 s = spltty(); /* XXX */
578 while (sc->tp->t_outq.c_cc < NG_H4_HIWATER) { /* XXX 2.2 specific ? */
582 /* Remove first mbuf from queue */
583 NG_BT_MBUFQ_DEQUEUE(&sc->outq, m);
587 /* Send as much of it as possible */
589 size = m->m_len - b_to_q(mtod(m, u_char *),
590 m->m_len, &sc->tp->t_outq);
592 NG_H4_STAT_BYTES_SENT(sc->stat, size);
597 break; /* device can't take no more */
602 /* Put remainder of mbuf chain (if any) back on queue */
604 NG_BT_MBUFQ_PREPEND(&sc->outq, m);
608 /* Full packet has been sent */
609 NG_H4_STAT_PCKTS_SENT(sc->stat);
613 * Call output process whether or not there is any output. We are
614 * being called in lieu of ttstart and must do what it would.
620 * This timeout is needed for operation on a pseudo-tty, because the
621 * pty code doesn't call pppstart after it has drained the t_outq.
624 if (NG_BT_MBUFQ_LEN(&sc->outq) > 0 && (sc->flags & NG_H4_TIMEOUT) == 0)
630 /*****************************************************************************
631 *****************************************************************************
632 ** Netgraph node methods
633 *****************************************************************************
634 *****************************************************************************/
637 * Initialize a new node of this type. We only allow nodes to be created as
638 * a result of setting the line discipline on a tty, so always return an error
643 ng_h4_constructor(node_p node)
646 } /* ng_h4_constructor */
649 * Add a new hook. There can only be one.
653 ng_h4_newhook(node_p node, hook_p hook, const char *name)
655 ng_h4_info_p sc = (ng_h4_info_p) NG_NODE_PRIVATE(node);
657 if (strcmp(name, NG_H4_HOOK) != 0)
660 if (sc->hook != NULL)
666 } /* ng_h4_newhook */
669 * Connect hook. Just say yes.
673 ng_h4_connect(hook_p hook)
675 ng_h4_info_p sc = (ng_h4_info_p) NG_NODE_PRIVATE(NG_HOOK_NODE(hook));
677 if (hook != sc->hook) {
682 NG_HOOK_FORCE_QUEUE(NG_HOOK_PEER(hook));
685 } /* ng_h4_connect */
688 * Disconnect the hook
692 ng_h4_disconnect(hook_p hook)
694 ng_h4_info_p sc = (ng_h4_info_p) NG_NODE_PRIVATE(NG_HOOK_NODE(hook));
697 * We need to check for sc != NULL because we can be called from
698 * ng_h4_clsoe() via ng_rmnode_self()
702 if (hook != sc->hook)
705 /* XXX do we have to untimeout and drain out queue? */
706 if (sc->flags & NG_H4_TIMEOUT)
707 ng_h4_untimeout(NG_HOOK_NODE(hook));
709 NG_BT_MBUFQ_DRAIN(&sc->outq);
710 sc->state = NG_H4_W4_PKT_IND;
718 } /* ng_h4_disconnect */
721 * Remove this node. The does the netgraph portion of the shutdown.
722 * This should only be called indirectly from ng_h4_close().
726 ng_h4_shutdown(node_p node)
728 ng_h4_info_p sc = (ng_h4_info_p) NG_NODE_PRIVATE(node);
729 char name[NG_NODESIZ];
731 /* Let old node go */
732 NG_NODE_SET_PRIVATE(node, NULL);
735 /* Check if device was closed */
739 /* Setup new netgraph node */
740 if (ng_make_node_common(&typestruct, &sc->node) != 0) {
741 printf("%s: Unable to create new node!\n", __func__);
746 /* Assign node its name */
747 snprintf(name, sizeof(name), "%s%d", typestruct.name, ng_h4_node ++);
749 if (ng_name_node(sc->node, name) != 0) {
750 printf("%s: %s - node name exists?\n", __func__, name);
751 NG_NODE_UNREF(sc->node);
756 /* The node has to be a WRITER because data can change node status */
757 NG_NODE_FORCE_WRITER(sc->node);
758 NG_NODE_SET_PRIVATE(sc->node, sc);
761 } /* ng_h4_shutdown */
764 * Receive incoming data from Netgraph system. Put it on our
765 * output queue and start output if necessary.
769 ng_h4_rcvdata(hook_p hook, item_p item)
771 ng_h4_info_p sc = (ng_h4_info_p)NG_NODE_PRIVATE(NG_HOOK_NODE(hook));
773 struct mbuf *m = NULL;
780 if (hook != sc->hook) {
787 if (NG_BT_MBUFQ_FULL(&sc->outq)) {
788 NG_H4_ERR("%s: %s - dropping mbuf, len=%d\n", __func__,
789 NG_NODE_NAME(sc->node), m->m_pkthdr.len);
791 NG_BT_MBUFQ_DROP(&sc->outq);
792 NG_H4_STAT_OERROR(sc->stat);
797 NG_H4_INFO("%s: %s - queue mbuf, len=%d\n", __func__,
798 NG_NODE_NAME(sc->node), m->m_pkthdr.len);
800 NG_BT_MBUFQ_ENQUEUE(&sc->outq, m);
803 * We have lock on the node, so we can call ng_h4_start2()
807 ng_h4_start2(sc->node, NULL, NULL, 0);
813 } /* ng_h4_rcvdata */
816 * Receive control message
820 ng_h4_rcvmsg(node_p node, item_p item, hook_p lasthook)
822 ng_h4_info_p sc = (ng_h4_info_p) NG_NODE_PRIVATE(node);
823 struct ng_mesg *msg = NULL, *resp = NULL;
831 NGI_GET_MSG(item, msg);
833 switch (msg->header.typecookie) {
834 case NGM_GENERIC_COOKIE:
835 switch (msg->header.cmd) {
836 case NGM_TEXT_STATUS:
837 NG_MKRESPONSE(resp, msg, NG_TEXTRESPONSE, M_NOWAIT);
841 snprintf(resp->data, NG_TEXTRESPONSE,
846 "Queue: [have:%d,max:%d]\n" \
847 "Input: [got:%d,want:%d]",
848 (sc->hook != NULL)? NG_H4_HOOK : "",
852 NG_BT_MBUFQ_LEN(&sc->outq),
865 switch (msg->header.cmd) {
866 case NGM_H4_NODE_RESET:
867 NG_BT_MBUFQ_DRAIN(&sc->outq);
868 sc->state = NG_H4_W4_PKT_IND;
873 case NGM_H4_NODE_GET_STATE:
874 NG_MKRESPONSE(resp, msg, sizeof(ng_h4_node_state_ep),
879 *((ng_h4_node_state_ep *)(resp->data)) =
883 case NGM_H4_NODE_GET_DEBUG:
884 NG_MKRESPONSE(resp, msg, sizeof(ng_h4_node_debug_ep),
889 *((ng_h4_node_debug_ep *)(resp->data)) =
893 case NGM_H4_NODE_SET_DEBUG:
894 if (msg->header.arglen != sizeof(ng_h4_node_debug_ep))
898 *((ng_h4_node_debug_ep *)(msg->data));
901 case NGM_H4_NODE_GET_QLEN:
902 NG_MKRESPONSE(resp, msg, sizeof(ng_h4_node_qlen_ep),
907 *((ng_h4_node_qlen_ep *)(resp->data)) =
911 case NGM_H4_NODE_SET_QLEN:
912 if (msg->header.arglen != sizeof(ng_h4_node_qlen_ep))
914 else if (*((ng_h4_node_qlen_ep *)(msg->data)) <= 0)
918 *((ng_h4_node_qlen_ep *)(msg->data));
921 case NGM_H4_NODE_GET_STAT:
922 NG_MKRESPONSE(resp, msg, sizeof(ng_h4_node_stat_ep),
927 bcopy(&sc->stat, resp->data,
928 sizeof(ng_h4_node_stat_ep));
931 case NGM_H4_NODE_RESET_STAT:
932 NG_H4_STAT_RESET(sc->stat);
946 NG_RESPOND_MSG(error, node, item, resp);
957 ng_h4_timeout(node_p node)
959 ng_h4_info_p sc = (ng_h4_info_p) NG_NODE_PRIVATE(node);
961 ng_callout(&sc->timo, node, NULL, 1, ng_h4_process_timeout, NULL, 0);
962 sc->flags |= NG_H4_TIMEOUT;
963 } /* ng_h4_timeout */
970 ng_h4_untimeout(node_p node)
972 ng_h4_info_p sc = (ng_h4_info_p) NG_NODE_PRIVATE(node);
974 sc->flags &= ~NG_H4_TIMEOUT;
975 ng_uncallout(&sc->timo, node);
976 } /* ng_h4_untimeout */
979 * Timeout processing function.
980 * We still have data to output to the device, so try sending more.
984 ng_h4_process_timeout(node_p node, hook_p hook, void *arg1, int arg2)
986 ng_h4_info_p sc = (ng_h4_info_p) NG_NODE_PRIVATE(node);
988 sc->flags &= ~NG_H4_TIMEOUT;
991 * We can call ng_h4_start2() directly here because we have lock
995 ng_h4_start2(node, NULL, NULL, 0);
996 } /* ng_h4_process_timeout */
999 * Handle loading and unloading for this node type
1003 ng_h4_mod_event(module_t mod, int event, void *data)
1005 static int ng_h4_ldisc;
1008 s = spltty(); /* XXX */
1012 /* Register line discipline */
1013 ng_h4_ldisc = ldisc_register(H4DISC, &ng_h4_disc);
1014 if (ng_h4_ldisc < 0) {
1015 printf("%s: can't register H4 line discipline\n",
1022 /* Unregister line discipline */
1023 ldisc_deregister(ng_h4_ldisc);
1034 } /* ng_h4_mod_event */