Example #1
0
/*
 * Node constructor
 */
static int
nglmi_constructor(node_p node)
{
	sc_p sc;

	sc = malloc(sizeof(*sc), M_NETGRAPH, M_WAITOK | M_ZERO);

	NG_NODE_SET_PRIVATE(node, sc);
	sc->node = node;

	ng_callout_init(&sc->handle);
	sc->protoname = NAME_NONE;
	sc->liv_per_full = NG_LMI_SEQ_PER_FULL;	/* make this dynamic */
	sc->liv_rate = NG_LMI_KEEPALIVE_RATE;
	return (0);
}
ng_hci_unit_con_p
ng_hci_new_con(ng_hci_unit_p unit, int link_type)
{
	ng_hci_unit_con_p	con = NULL;
	int			num_pkts;
	static int		fake_con_handle = 0x0f00;

	con = malloc(sizeof(*con), M_NETGRAPH_HCI,
		M_NOWAIT | M_ZERO);
	if (con != NULL) {
		con->unit = unit;
		con->state = NG_HCI_CON_CLOSED;

		/*
		 * XXX
		 *
		 * Assign fake connection handle to the connection descriptor.
		 * Bluetooth specification marks 0x0f00 - 0x0fff connection
		 * handles as reserved. We need this fake connection handles
		 * for timeouts. Connection handle will be passed as argument
		 * to timeout so when timeout happens we can find the right
		 * connection descriptor. We can not pass pointers, because
		 * timeouts are external (to Netgraph) events and there might
		 * be a race when node/hook goes down and timeout event already
		 * went into node's queue
		 */

		con->con_handle = fake_con_handle ++;
		if (fake_con_handle > 0x0fff)
			fake_con_handle = 0x0f00;

		con->link_type = link_type;

		if (con->link_type == NG_HCI_LINK_ACL)
			NG_HCI_BUFF_ACL_TOTAL(unit->buffer, num_pkts);
		else
			NG_HCI_BUFF_SCO_TOTAL(unit->buffer, num_pkts);

		NG_BT_ITEMQ_INIT(&con->conq, num_pkts);

		ng_callout_init(&con->con_timo);

		LIST_INSERT_HEAD(&unit->con_list, con, next);
	}

	return (con);
} /* ng_hci_new_con */