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: head/sys/netgraph/bluetooth/drivers/h4/ng_h4.c 243882 2012-12-05 08:04:20Z glebius $
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/malloc.h>
51 #include <sys/socket.h>
53 #include <sys/ttycom.h>
55 #include <net/if_var.h>
56 #include <netgraph7/ng_message.h>
57 #include <netgraph7/netgraph.h>
58 #include <netgraph7/ng_parse.h>
59 #include <netgraph7/bluetooth/include/ng_bluetooth.h>
60 #include <netgraph7/bluetooth/include/ng_hci.h>
61 #include <netgraph7/bluetooth/include/ng_h4.h>
62 #include <netgraph7/bluetooth/drivers/h4/ng_h4_var.h>
63 #include <netgraph7/bluetooth/drivers/h4/ng_h4_prse.h>
65 /*****************************************************************************
66 *****************************************************************************
67 ** This node implements a Bluetooth HCI UART transport layer as per chapter
68 ** H4 of the Bluetooth Specification Book v1.1. It is a terminal line
69 ** discipline that is also a netgraph node. Installing this line discipline
70 ** on a terminal device instantiates a new netgraph node of this type, which
71 ** allows access to the device via the "hook" hook of the node.
73 ** Once the line discipline is installed, you can find out the name of the
74 ** corresponding netgraph node via a NGIOCGINFO ioctl().
75 *****************************************************************************
76 *****************************************************************************/
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 int ng_h4_ioctl (struct tty
*, u_long
, caddr_t
,
95 /* Line discipline descriptor */
96 static struct linesw ng_h4_disc
= {
97 ng_h4_open
, /* open */
98 ng_h4_close
, /* close */
99 ng_h4_read
, /* read */
100 ng_h4_write
, /* write */
101 ng_h4_ioctl
, /* ioctl */
102 ng_h4_input
, /* input */
103 ng_h4_start
, /* start */
107 /* Netgraph methods */
108 static ng_constructor_t ng_h4_constructor
;
109 static ng_rcvmsg_t ng_h4_rcvmsg
;
110 static ng_shutdown_t ng_h4_shutdown
;
111 static ng_newhook_t ng_h4_newhook
;
112 static ng_connect_t ng_h4_connect
;
113 static ng_rcvdata_t ng_h4_rcvdata
;
114 static ng_disconnect_t ng_h4_disconnect
;
117 static void ng_h4_process_timeout (node_p
, hook_p
, void *, int);
118 static int ng_h4_mod_event (module_t
, int, void *);
120 /* Netgraph node type descriptor */
121 static struct ng_type typestruct
= {
122 .version
= NG_ABI_VERSION
,
123 .name
= NG_H4_NODE_TYPE
,
124 .mod_event
= ng_h4_mod_event
,
125 .constructor
= ng_h4_constructor
,
126 .rcvmsg
= ng_h4_rcvmsg
,
127 .shutdown
= ng_h4_shutdown
,
128 .newhook
= ng_h4_newhook
,
129 .connect
= ng_h4_connect
,
130 .rcvdata
= ng_h4_rcvdata
,
131 .disconnect
= ng_h4_disconnect
,
132 .cmdlist
= ng_h4_cmdlist
134 NETGRAPH_INIT(h4
, &typestruct
);
135 MODULE_VERSION(ng_h4
, NG_BLUETOOTH_VERSION
);
137 static int ng_h4_node
= 0;
139 /*****************************************************************************
140 *****************************************************************************
141 ** Line discipline methods
142 *****************************************************************************
143 *****************************************************************************/
146 * Set our line discipline on the tty.
150 ng_h4_open(struct cdev
*dev
, struct tty
*tp
)
152 char name
[NG_NODESIZ
];
153 ng_h4_info_p sc
= NULL
;
156 /* Super-user only */
157 error
= caps_priv_check_self(SYSCAP_NONET_NETGRAPH
);
161 /* Initialize private struct */
162 sc
= kmalloc(sizeof(*sc
), M_NETGRAPH_H4
, M_WAITOK
| M_NULLOK
| M_ZERO
);
166 lwkt_gettoken(&tp
->t_token
);
168 sc
->debug
= NG_H4_WARN_LEVEL
;
170 sc
->state
= NG_H4_W4_PKT_IND
;
174 sc
->outq
.ifq_maxlen
= NG_H4_DEFAULTQLEN
;
175 ng_callout_init(&sc
->timo
);
179 /* Setup netgraph node */
180 error
= ng_make_node_common(&typestruct
, &sc
->node
);
184 kprintf("%s: Unable to create new node!\n", __func__
);
186 bzero(sc
, sizeof(*sc
));
187 kfree(sc
, M_NETGRAPH_H4
);
189 lwkt_reltoken(&tp
->t_token
);
193 /* Assign node its name */
194 ksnprintf(name
, sizeof(name
), "%s%d", typestruct
.name
, ng_h4_node
++);
196 error
= ng_name_node(sc
->node
, name
);
200 kprintf("%s: %s - node name exists?\n", __func__
, name
);
202 NG_NODE_UNREF(sc
->node
);
203 bzero(sc
, sizeof(*sc
));
204 kfree(sc
, M_NETGRAPH_H4
);
206 lwkt_reltoken(&tp
->t_token
);
210 /* Set back pointers */
211 NG_NODE_SET_PRIVATE(sc
->node
, sc
);
212 tp
->t_sc
= (caddr_t
) sc
;
214 /* The node has to be a WRITER because data can change node status */
215 NG_NODE_FORCE_WRITER(sc
->node
);
218 * Pre-allocate cblocks to the an appropriate amount.
219 * I'm not sure what is appropriate.
222 ttyflush(tp
, FREAD
| FWRITE
);
223 clist_alloc_cblocks(&tp
->t_canq
, 0);
224 clist_alloc_cblocks(&tp
->t_rawq
, 0);
225 clist_alloc_cblocks(&tp
->t_outq
, MLEN
+ NG_H4_HIWATER
);
229 lwkt_reltoken(&tp
->t_token
);
234 * Line specific close routine, called from device close routine
235 * and from ttioctl. This causes the node to be destroyed as well.
239 ng_h4_close(struct tty
*tp
, int flag
)
241 ng_h4_info_p sc
= (ng_h4_info_p
) tp
->t_sc
;
243 lwkt_gettoken(&tp
->t_token
);
244 ttyflush(tp
, FREAD
| FWRITE
);
245 clist_free_cblocks(&tp
->t_outq
);
250 if (callout_pending(&sc
->timo
))
251 ng_uncallout(&sc
->timo
, sc
->node
);
258 ng_rmnode_self(sc
->node
);
261 lwkt_reltoken(&tp
->t_token
);
266 * Once the device has been turned into a node, we don't allow reading.
270 ng_h4_read(struct tty
*tp
, struct uio
*uio
, int flag
)
276 * Once the device has been turned into a node, we don't allow writing.
280 ng_h4_write(struct tty
*tp
, struct uio
*uio
, int flag
)
286 * We implement the NGIOCGINFO ioctl() defined in ng_message.h.
290 ng_h4_ioctl(struct tty
*tp
, u_long cmd
, caddr_t data
, int flag
,
293 ng_h4_info_p sc
= (ng_h4_info_p
) tp
->t_sc
;
299 lwkt_gettoken(&tp
->t_token
);
305 #define NI(x) ((struct nodeinfo *)(x))
307 bzero(data
, sizeof(*NI(data
)));
309 if (NG_NODE_HAS_NAME(sc
->node
))
310 strncpy(NI(data
)->name
, NG_NODE_NAME(sc
->node
),
311 sizeof(NI(data
)->name
) - 1);
313 strncpy(NI(data
)->type
, sc
->node
->nd_type
->name
,
314 sizeof(NI(data
)->type
) - 1);
316 NI(data
)->id
= (u_int32_t
) ng_node2ID(sc
->node
);
317 NI(data
)->hooks
= NG_NODE_NUMHOOKS(sc
->node
);
327 lwkt_reltoken(&tp
->t_token
);
332 * Receive data coming from the device. We get one character at a time, which
337 ng_h4_input(int c
, struct tty
*tp
)
339 ng_h4_info_p sc
= (ng_h4_info_p
) tp
->t_sc
;
341 lwkt_gettoken(&tp
->t_token
);
342 if (sc
== NULL
|| tp
!= sc
->tp
||
343 sc
->node
== NULL
|| NG_NODE_NOT_VALID(sc
->node
)) {
344 lwkt_reltoken(&tp
->t_token
);
350 /* Check for error conditions */
351 if ((tp
->t_state
& TS_CONNECTED
) == 0) {
352 NG_H4_INFO("%s: %s - no carrier\n", __func__
,
353 NG_NODE_NAME(sc
->node
));
355 sc
->state
= NG_H4_W4_PKT_IND
;
361 lwkt_reltoken(&tp
->t_token
);
362 return (0); /* XXX Loss of synchronization here! */
365 /* Check for framing error or overrun on this char */
366 if (c
& TTY_ERRORMASK
) {
367 NG_H4_ERR("%s: %s - line error %#x, c=%#x\n", __func__
,
368 NG_NODE_NAME(sc
->node
), c
& TTY_ERRORMASK
,
371 NG_H4_STAT_IERROR(sc
->stat
);
373 sc
->state
= NG_H4_W4_PKT_IND
;
379 lwkt_reltoken(&tp
->t_token
);
380 return (0); /* XXX Loss of synchronization here! */
383 NG_H4_STAT_BYTES_RECV(sc
->stat
, 1);
385 /* Append char to mbuf */
386 if (sc
->got
>= sizeof(sc
->ibuf
)) {
387 NG_H4_ALERT("%s: %s - input buffer overflow, c=%#x, got=%d\n",
388 __func__
, NG_NODE_NAME(sc
->node
), c
& TTY_CHARMASK
,
391 NG_H4_STAT_IERROR(sc
->stat
);
393 sc
->state
= NG_H4_W4_PKT_IND
;
399 lwkt_reltoken(&tp
->t_token
);
400 return (0); /* XXX Loss of synchronization here! */
403 sc
->ibuf
[sc
->got
++] = (c
& TTY_CHARMASK
);
405 NG_H4_INFO("%s: %s - got char %#x, want=%d, got=%d\n", __func__
,
406 NG_NODE_NAME(sc
->node
), c
, sc
->want
, sc
->got
);
408 if (sc
->got
< sc
->want
) {
411 lwkt_reltoken(&tp
->t_token
);
412 return (0); /* Wait for more */
416 /* Got packet indicator */
417 case NG_H4_W4_PKT_IND
:
418 NG_H4_INFO("%s: %s - got packet indicator %#x\n", __func__
,
419 NG_NODE_NAME(sc
->node
), sc
->ibuf
[0]);
421 sc
->state
= NG_H4_W4_PKT_HDR
;
424 * Since packet indicator included in the packet header
425 * just set sc->want to sizeof(packet header).
428 switch (sc
->ibuf
[0]) {
429 case NG_HCI_ACL_DATA_PKT
:
430 sc
->want
= sizeof(ng_hci_acldata_pkt_t
);
433 case NG_HCI_SCO_DATA_PKT
:
434 sc
->want
= sizeof(ng_hci_scodata_pkt_t
);
437 case NG_HCI_EVENT_PKT
:
438 sc
->want
= sizeof(ng_hci_event_pkt_t
);
442 NG_H4_WARN("%s: %s - ignoring unknown packet " \
443 "type=%#x\n", __func__
, NG_NODE_NAME(sc
->node
),
446 NG_H4_STAT_IERROR(sc
->stat
);
448 sc
->state
= NG_H4_W4_PKT_IND
;
455 /* Got packet header */
456 case NG_H4_W4_PKT_HDR
:
457 sc
->state
= NG_H4_W4_PKT_DATA
;
459 switch (sc
->ibuf
[0]) {
460 case NG_HCI_ACL_DATA_PKT
:
461 c
= le16toh(((ng_hci_acldata_pkt_t
*)
462 (sc
->ibuf
))->length
);
465 case NG_HCI_SCO_DATA_PKT
:
466 c
= ((ng_hci_scodata_pkt_t
*)(sc
->ibuf
))->length
;
469 case NG_HCI_EVENT_PKT
:
470 c
= ((ng_hci_event_pkt_t
*)(sc
->ibuf
))->length
;
474 KASSERT((0), ("Invalid packet type=%#x",
479 NG_H4_INFO("%s: %s - got packet header, packet type=%#x, " \
480 "packet size=%d, payload size=%d\n", __func__
,
481 NG_NODE_NAME(sc
->node
), sc
->ibuf
[0], sc
->got
, c
);
487 * Try to prevent possible buffer overrun
489 * XXX I'm *really* confused here. It turns out
490 * that Xircom card sends us packets with length
491 * greater then 512 bytes! This is greater then
492 * our old receive buffer (ibuf) size. In the same
493 * time the card demands from us *not* to send
494 * packets greater then 192 bytes. Weird! How the
495 * hell i should know how big *receive* buffer
496 * should be? For now increase receiving buffer
497 * size to 1K and add the following check.
500 if (sc
->want
>= sizeof(sc
->ibuf
)) {
503 NG_H4_ALERT("%s: %s - packet too big for " \
504 "buffer, type=%#x, got=%d, want=%d, " \
505 "length=%d\n", __func__
,
506 NG_NODE_NAME(sc
->node
), sc
->ibuf
[0],
507 sc
->got
, sc
->want
, c
);
509 NG_H4_ALERT("Packet header:\n");
510 for (b
= 0; b
< sc
->got
; b
++)
511 NG_H4_ALERT("%#x ", sc
->ibuf
[b
]);
515 NG_H4_STAT_IERROR(sc
->stat
);
517 sc
->state
= NG_H4_W4_PKT_IND
;
525 /* else FALLTHROUGH and deliver frame */
526 /* XXX Is this true? Should we deliver empty frame? */
528 /* Got packet data */
529 case NG_H4_W4_PKT_DATA
:
530 NG_H4_INFO("%s: %s - got full packet, packet type=%#x, " \
531 "packet size=%d\n", __func__
,
532 NG_NODE_NAME(sc
->node
), sc
->ibuf
[0], sc
->got
);
534 if (sc
->hook
!= NULL
&& NG_HOOK_IS_VALID(sc
->hook
)) {
535 struct mbuf
*m
= NULL
;
537 MGETHDR(m
, M_NOWAIT
, MT_DATA
);
538 if (m
!= NULL
&& m_copyback2(m
, 0, sc
->got
, sc
->ibuf
,
540 NG_SEND_DATA_ONLY(c
, sc
->hook
, m
);
542 NG_H4_ERR("%s: %s - could not get mbuf\n",
543 __func__
, NG_NODE_NAME(sc
->node
));
544 NG_H4_STAT_IERROR(sc
->stat
);
549 sc
->state
= NG_H4_W4_PKT_IND
;
553 NG_H4_STAT_PCKTS_RECV(sc
->stat
);
557 KASSERT((0), ("Invalid H4 node state=%d", sc
->state
));
563 lwkt_reltoken(&tp
->t_token
);
568 * This is called when the device driver is ready for more output. Called from
573 ng_h4_start(struct tty
*tp
)
575 ng_h4_info_p sc
= (ng_h4_info_p
) tp
->t_sc
;
576 struct mbuf
*m
= NULL
;
579 lwkt_gettoken(&tp
->t_token
);
580 if (sc
== NULL
|| tp
!= sc
->tp
||
581 sc
->node
== NULL
|| NG_NODE_NOT_VALID(sc
->node
)) {
582 lwkt_reltoken(&tp
->t_token
);
587 while (tp
->t_outq
.c_cc
< NG_H4_HIWATER
) { /* XXX 2.2 specific ? */
591 /* Remove first mbuf from queue */
592 IF_DEQUEUE(&sc
->outq
, m
);
596 /* Send as much of it as possible */
598 size
= m
->m_len
- clist_btoq(mtod(m
, u_char
*),
599 m
->m_len
, &tp
->t_outq
);
602 NG_H4_STAT_BYTES_SENT(sc
->stat
, size
);
608 break; /* device can't take no more */
613 /* Put remainder of mbuf chain (if any) back on queue */
615 IF_PREPEND(&sc
->outq
, m
);
619 /* Full packet has been sent */
621 NG_H4_STAT_PCKTS_SENT(sc
->stat
);
626 * Call output process whether or not there is any output. We are
627 * being called in lieu of ttstart and must do what it would.
630 if (tp
->t_oproc
!= NULL
)
634 * This timeout is needed for operation on a pseudo-tty, because the
635 * pty code doesn't call pppstart after it has drained the t_outq.
640 if (!IF_QEMPTY(&sc
->outq
) && !callout_pending(&sc
->timo
))
641 ng_callout(&sc
->timo
, sc
->node
, NULL
, 1,
642 ng_h4_process_timeout
, NULL
, 0);
646 lwkt_reltoken(&tp
->t_token
);
650 /*****************************************************************************
651 *****************************************************************************
652 ** Netgraph node methods
653 *****************************************************************************
654 *****************************************************************************/
657 * Initialize a new node of this type. We only allow nodes to be created as
658 * a result of setting the line discipline on a tty, so always return an error
663 ng_h4_constructor(node_p node
)
666 } /* ng_h4_constructor */
669 * Add a new hook. There can only be one.
673 ng_h4_newhook(node_p node
, hook_p hook
, const char *name
)
675 ng_h4_info_p sc
= (ng_h4_info_p
) NG_NODE_PRIVATE(node
);
677 if (strcmp(name
, NG_H4_HOOK
) != 0)
682 if (sc
->hook
!= NULL
) {
691 } /* ng_h4_newhook */
694 * Connect hook. Just say yes.
698 ng_h4_connect(hook_p hook
)
700 ng_h4_info_p sc
= (ng_h4_info_p
) NG_NODE_PRIVATE(NG_HOOK_NODE(hook
));
702 if (hook
!= sc
->hook
)
703 panic("%s: hook != sc->hook", __func__
);
705 NG_HOOK_FORCE_QUEUE(NG_HOOK_PEER(hook
));
706 NG_HOOK_FORCE_QUEUE(hook
);
709 } /* ng_h4_connect */
712 * Disconnect the hook
716 ng_h4_disconnect(hook_p hook
)
718 ng_h4_info_p sc
= (ng_h4_info_p
) NG_NODE_PRIVATE(NG_HOOK_NODE(hook
));
721 * We need to check for sc != NULL because we can be called from
722 * ng_h4_close() via ng_rmnode_self()
726 if (hook
!= sc
->hook
)
727 panic("%s: hook != sc->hook", __func__
);
731 /* XXX do we have to untimeout and drain out queue? */
732 if (callout_pending(&sc
->timo
))
733 ng_uncallout(&sc
->timo
, sc
->node
);
737 sc
->state
= NG_H4_W4_PKT_IND
;
747 } /* ng_h4_disconnect */
750 * Remove this node. The does the netgraph portion of the shutdown.
751 * This should only be called indirectly from ng_h4_close().
755 ng_h4_shutdown(node_p node
)
757 ng_h4_info_p sc
= (ng_h4_info_p
) NG_NODE_PRIVATE(node
);
764 NG_NODE_REVIVE(node
); /* we will persist */
771 NG_NODE_SET_PRIVATE(node
, NULL
);
776 bzero(sc
, sizeof(*sc
));
777 kfree(sc
, M_NETGRAPH_H4
);
780 } /* ng_h4_shutdown */
783 * Receive incoming data from Netgraph system. Put it on our
784 * output queue and start output if necessary.
788 ng_h4_rcvdata(hook_p hook
, item_p item
)
790 ng_h4_info_p sc
= (ng_h4_info_p
)NG_NODE_PRIVATE(NG_HOOK_NODE(hook
));
791 struct mbuf
*m
= NULL
;
797 if (hook
!= sc
->hook
)
798 panic("%s: hook != sc->hook", __func__
);
805 if (IF_QFULL(&sc
->outq
)) {
806 NG_H4_ERR("%s: %s - dropping mbuf, len=%d\n", __func__
,
807 NG_NODE_NAME(sc
->node
), m
->m_pkthdr
.len
);
809 NG_H4_STAT_OERROR(sc
->stat
);
819 NG_H4_INFO("%s: %s - queue mbuf, len=%d\n", __func__
,
820 NG_NODE_NAME(sc
->node
), m
->m_pkthdr
.len
);
822 IF_ENQUEUE(&sc
->outq
, m
);
823 qlen
= IF_QLEN(&sc
->outq
);
828 * If qlen > 1, then we should already have a scheduled callout
835 } /* ng_h4_rcvdata */
838 * Receive control message
842 ng_h4_rcvmsg(node_p node
, item_p item
, hook_p lasthook
)
844 ng_h4_info_p sc
= (ng_h4_info_p
) NG_NODE_PRIVATE(node
);
845 struct ng_mesg
*msg
= NULL
, *resp
= NULL
;
851 NGI_GET_MSG(item
, msg
);
854 switch (msg
->header
.typecookie
) {
855 case NGM_GENERIC_COOKIE
:
856 switch (msg
->header
.cmd
) {
857 case NGM_TEXT_STATUS
:
858 NG_MKRESPONSE(resp
, msg
, NG_TEXTRESPONSE
, M_WAITOK
| M_NULLOK
);
862 ksnprintf(resp
->data
, NG_TEXTRESPONSE
,
866 "Queue: [have:%d,max:%d]\n" \
867 "Input: [got:%d,want:%d]",
868 (sc
->hook
!= NULL
)? NG_H4_HOOK
: "",
884 switch (msg
->header
.cmd
) {
885 case NGM_H4_NODE_RESET
:
887 sc
->state
= NG_H4_W4_PKT_IND
;
892 case NGM_H4_NODE_GET_STATE
:
893 NG_MKRESPONSE(resp
, msg
, sizeof(ng_h4_node_state_ep
),
894 M_WAITOK
| M_NULLOK
);
898 *((ng_h4_node_state_ep
*)(resp
->data
)) =
902 case NGM_H4_NODE_GET_DEBUG
:
903 NG_MKRESPONSE(resp
, msg
, sizeof(ng_h4_node_debug_ep
),
904 M_WAITOK
| M_NULLOK
);
908 *((ng_h4_node_debug_ep
*)(resp
->data
)) =
912 case NGM_H4_NODE_SET_DEBUG
:
913 if (msg
->header
.arglen
!= sizeof(ng_h4_node_debug_ep
))
917 *((ng_h4_node_debug_ep
*)(msg
->data
));
920 case NGM_H4_NODE_GET_QLEN
:
921 NG_MKRESPONSE(resp
, msg
, sizeof(ng_h4_node_qlen_ep
),
922 M_WAITOK
| M_NULLOK
);
926 *((ng_h4_node_qlen_ep
*)(resp
->data
)) =
930 case NGM_H4_NODE_SET_QLEN
:
931 if (msg
->header
.arglen
!= sizeof(ng_h4_node_qlen_ep
))
933 else if (*((ng_h4_node_qlen_ep
*)(msg
->data
)) <= 0)
936 sc
->outq
.ifq_maxlen
=
937 *((ng_h4_node_qlen_ep
*)(msg
->data
));
940 case NGM_H4_NODE_GET_STAT
:
941 NG_MKRESPONSE(resp
, msg
, sizeof(ng_h4_node_stat_ep
),
942 M_WAITOK
| M_NULLOK
);
946 bcopy(&sc
->stat
, resp
->data
,
947 sizeof(ng_h4_node_stat_ep
));
950 case NGM_H4_NODE_RESET_STAT
:
951 NG_H4_STAT_RESET(sc
->stat
);
967 NG_RESPOND_MSG(error
, node
, item
, resp
);
974 * Timeout processing function.
975 * We still have data to output to the device, so try sending more.
979 ng_h4_process_timeout(node_p node
, hook_p hook
, void *arg1
, int arg2
)
981 ng_h4_info_p sc
= (ng_h4_info_p
) NG_NODE_PRIVATE(node
);
984 } /* ng_h4_process_timeout */
987 * Handle loading and unloading for this node type
991 ng_h4_mod_event(module_t mod
, int event
, void *data
)
993 static int ng_h4_ldisc
;
998 /* Register line discipline */
1000 ng_h4_ldisc
= ldisc_register(BTUARTDISC
, &ng_h4_disc
);
1003 if (ng_h4_ldisc
< 0) {
1004 kprintf("%s: can't register H4 line discipline\n",
1011 /* Unregister line discipline */
1013 ldisc_deregister(ng_h4_ldisc
);
1023 } /* ng_h4_mod_event */