|
34 | 34 |
|
35 | 35 | #include <sys/param.h> |
36 | 36 | #include <sys/systm.h> |
| 37 | +#include <sys/types.h> |
37 | 38 | #include <sys/kernel.h> |
38 | 39 | #include <sys/endian.h> |
39 | 40 | #include <sys/malloc.h> |
40 | 41 | #include <sys/mbuf.h> |
| 42 | +#include <sys/sbuf.h> |
41 | 43 | #include <sys/queue.h> |
| 44 | +#include <sys/devctl.h> |
42 | 45 | #include <netgraph/ng_message.h> |
43 | 46 | #include <netgraph/netgraph.h> |
44 | 47 | #include <netgraph/ng_parse.h> |
@@ -110,6 +113,19 @@ static int ng_hci_linktype_to_addrtype(int linktype) |
110 | 113 | } |
111 | 114 | return BDADDR_BREDR; |
112 | 115 | } |
| 116 | + |
| 117 | +/* |
| 118 | + * Format bdaddr_t as "xx:xx:xx:xx:xx:xx" into buf. |
| 119 | + */ |
| 120 | + |
| 121 | +static void |
| 122 | +ng_hci_bdaddr_to_str(const bdaddr_t *ba, char buf[18]) |
| 123 | +{ |
| 124 | + snprintf(buf, 18, "%02x:%02x:%02x:%02x:%02x:%02x", |
| 125 | + ba->b[5], ba->b[4], ba->b[3], |
| 126 | + ba->b[2], ba->b[1], ba->b[0]); |
| 127 | +} /* ng_hci_bdaddr_to_str */ |
| 128 | + |
113 | 129 | /***************************************************************************** |
114 | 130 | ***************************************************************************** |
115 | 131 | ** Netgraph methods implementation |
@@ -268,6 +284,25 @@ ng_hci_disconnect(hook_p hook) |
268 | 284 | /* Connection terminated by local host */ |
269 | 285 | ng_hci_unit_clean(unit, 0x16); |
270 | 286 | unit->state &= ~(NG_HCI_UNIT_CONNECTED|NG_HCI_UNIT_INITED); |
| 287 | + |
| 288 | + /* Signal power off to devd */ |
| 289 | + { |
| 290 | + char bdstr[18]; |
| 291 | + struct sbuf *sb; |
| 292 | + |
| 293 | + sb = sbuf_new_auto(); |
| 294 | + ng_hci_bdaddr_to_str(&unit->bdaddr, bdstr); |
| 295 | + sbuf_sprintf(sb, "node=%s bdaddr=%s\n", |
| 296 | + NG_NODE_NAME(NG_HOOK_NODE(hook)), bdstr); |
| 297 | + |
| 298 | + if (sbuf_finish(sb) != 0) err(1, "Could not generate sbuf message"); |
| 299 | + |
| 300 | + transmit_msg(sbuf_data(sb), sbuf_len(sb)); |
| 301 | + devctl_notify("BLUETOOTH", "HCI", "POWERED_OFF", sb->buf); |
| 302 | + sbuf_delete(sb); |
| 303 | + } |
| 304 | + |
| 305 | + |
271 | 306 | } else |
272 | 307 | return (EINVAL); |
273 | 308 |
|
@@ -371,6 +406,24 @@ ng_hci_default_rcvmsg(node_p node, item_p item, hook_p lasthook) |
371 | 406 |
|
372 | 407 | ng_hci_node_is_up(unit->node, unit->acl, NULL, 0); |
373 | 408 | ng_hci_node_is_up(unit->node, unit->sco, NULL, 0); |
| 409 | + |
| 410 | + /* Signal init to devd */ |
| 411 | + { |
| 412 | + char bdstr[18]; |
| 413 | + struct sbuf *sb; |
| 414 | + |
| 415 | + sb = sbuf_new_auto(); |
| 416 | + ng_hci_bdaddr_to_str(&unit->bdaddr, bdstr); |
| 417 | + sbuf_sprintf(sb, "node=%s bdaddr=%s\n", |
| 418 | + NG_NODE_NAME(node), bdstr); |
| 419 | + |
| 420 | + if (sbuf_finish(sb) != 0) err(1, "Could not generate sbuf message"); |
| 421 | + |
| 422 | + transmit_msg(sbuf_data(sb), sbuf_len(sb)); |
| 423 | + devctl_notify("BLUETOOTH", "HCI", "INITIALIZED", sb->buf); |
| 424 | + sbuf_delete(sb); |
| 425 | + } |
| 426 | + |
374 | 427 | break; |
375 | 428 |
|
376 | 429 | /* Get node debug level */ |
|
0 commit comments