code:
/*-
 * Copyright (c) 2001-2003
 *	Fraunhofer Institute for Open Communication Systems (FhG Fokus).
 * 	All rights reserved.
 *
 * Author: Hartmut Brandt <harti@freebsd.org>
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * $FreeBSD: release/9.0.0/sys/netgraph/atm/ng_uni.h 139823 2005-01-07 01:45:51Z imp $
 *
 * Netgraph module for UNI 4.0
 */
#ifndef _NETGRAPH_ATM_NG_UNI_H_
#define _NETGRAPH_ATM_NG_UNI_H_

#define NG_UNI_NODE_TYPE "uni"
#define NGM_UNI_COOKIE	981112392

enum {
	NGM_UNI_GETDEBUG,	/* get debug flags */
	NGM_UNI_SETDEBUG,	/* set debug flags */
	NGM_UNI_GET_CONFIG,	/* get configuration */
	NGM_UNI_SET_CONFIG,	/* set configuration */
	NGM_UNI_ENABLE,		/* enable processing */
	NGM_UNI_DISABLE,	/* free resources and disable */
	NGM_UNI_GETSTATE,	/* retrieve coord state */
};

struct ngm_uni_debug {
	uint32_t	level[UNI_MAXFACILITY];
};
#define NGM_UNI_DEBUGLEVEL_INFO {				\
	&ng_parse_uint32_type,					\
	UNI_MAXFACILITY						\
}
#define NGM_UNI_DEBUG_INFO 					\
	{							\
	  { "level",	&ng_uni_debuglevel_type },		\
	  { NULL }						\
	}

#define NGM_UNI_CONFIG_INFO 					\
	{							\
	  { "proto",	&ng_parse_uint32_type },		\
	  { "popt",	&ng_parse_uint32_type },		\
	  { "option",	&ng_parse_uint32_type },		\
	  { "timer301",	&ng_parse_uint32_type },		\
	  { "timer303",	&ng_parse_uint32_type },		\
	  { "init303",	&ng_parse_uint32_type },		\
	  { "timer308",	&ng_parse_uint32_type },		\
	  { "init308",	&ng_parse_uint32_type },		\
	  { "timer309",	&ng_parse_uint32_type },		\
	  { "timer310",	&ng_parse_uint32_type },		\
	  { "timer313",	&ng_parse_uint32_type },		\
	  { "timer316",	&ng_parse_uint32_type },		\
	  { "init316",	&ng_parse_uint32_type },		\
	  { "timer317",	&ng_parse_uint32_type },		\
	  { "timer322",	&ng_parse_uint32_type },		\
	  { "init322",	&ng_parse_uint32_type },		\
	  { "timer397",	&ng_parse_uint32_type },		\
	  { "timer398",	&ng_parse_uint32_type },		\
	  { "timer399",	&ng_parse_uint32_type },		\
	  { NULL }						\
	}

struct ngm_uni_config_mask {
	uint32_t		mask;
	uint32_t		popt_mask;
	uint32_t		option_mask;
};
#define NGM_UNI_CONFIG_MASK_INFO 				\
	{							\
	  { "mask",		&ng_parse_hint32_type },	\
	  { "popt_mask",	&ng_parse_hint32_type },	\
	  { "option_mask",	&ng_parse_hint32_type },	\
	  { NULL }						\
	}

struct ngm_uni_set_config {
	struct uni_config		config;
	struct ngm_uni_config_mask	mask;
};
#define NGM_UNI_SET_CONFIG_INFO 				\
	{							\
	  { "config",		&ng_uni_config_type },		\
	  { "mask",		&ng_uni_config_mask_type },	\
	  { NULL }						\
	}

/*
 * API message
 */
struct uni_arg {
	uint32_t	sig;
	uint32_t	cookie;
	u_char		data[];
};

#endif


code:
/*-
 * Copyright (c) 2001-2003
 *	Fraunhofer Institute for Open Communication Systems (FhG Fokus).
 *	All rights reserved.
 *
 * Author: Harti Brandt <harti@freebsd.org>
 *
 * Redistribution of this software and documentation and use in source and
 * binary forms, with or without modification, are permitted provided that
 * the following conditions are met:
 *
 * 1. Redistributions of source code or documentation must retain the above
 *    copyright notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE AND DOCUMENTATION IS PROVIDED BY FRAUNHOFER FOKUS
 * AND ITS CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
 * FRAUNHOFER FOKUS OR ITS CONTRIBUTORS  BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * $FreeBSD: release/9.0.0/sys/netgraph/atm/ngatmbase.h 139823 2005-01-07 01:45:51Z imp $
 *
 * In-kernel UNI stack message functions.
 */
#ifndef _NETGRAPH_ATM_NGATMBASE_H_
#define	_NETGRAPH_ATM_NGATMBASE_H_

/* forward declarations */
struct mbuf;
struct uni_msg;

struct mbuf *uni_msg_pack_mbuf(struct uni_msg *, void *, size_t);

#ifdef NGATM_DEBUG

struct uni_msg *_uni_msg_alloc(size_t, const char *, int);
struct uni_msg *_uni_msg_build(const char *, int, void *, ...);
void _uni_msg_destroy(struct uni_msg *, const char *, int);
int _uni_msg_unpack_mbuf(struct mbuf *, struct uni_msg **, const char *, int);

#define	uni_msg_alloc(S) _uni_msg_alloc((S), __FILE__, __LINE__)
#define	uni_msg_build(P...) _uni_msg_build(__FILE__, __LINE__, P)
#define	uni_msg_destroy(M) _uni_msg_destroy((M), __FILE__, __LINE__)
#define	uni_msg_unpack_mbuf(M, PP) \
	    _uni_msg_unpack_mbuf((M), (PP), __FILE__, __LINE__)

#else /* !NGATM_DEBUG */

struct uni_msg *uni_msg_alloc(size_t);
struct uni_msg *uni_msg_build(void *, ...);
void uni_msg_destroy(struct uni_msg *);
int uni_msg_unpack_mbuf(struct mbuf *, struct uni_msg **);

#endif
#endif

repo_name: veiledmerc/mira

license: mit


code:
/*
 * bluetooth.h
 */

/*-
 * Copyright (c) 2001-2002 Maksim Yevmenkin <m_evmenkin@yahoo.com>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * $Id: ng_bluetooth.h,v 1.4 2003/04/26 22:32:34 max Exp $
 * $FreeBSD: release/9.0.0/sys/netgraph/bluetooth/include/ng_bluetooth.h 180399 2008-07-10 00:15:29Z emax $
 */

#ifndef _NETGRAPH_BLUETOOTH_H_
#define _NETGRAPH_BLUETOOTH_H_

#include <sys/queue.h>

/*
 * Version of the stack
 */

#define NG_BLUETOOTH_VERSION	1

/*
 * Declare the base of the Bluetooth sysctl hierarchy,
 * but only if this file cares about sysctl's
 */

#ifdef SYSCTL_DECL
SYSCTL_DECL(_net_bluetooth);
SYSCTL_DECL(_net_bluetooth_hci);
SYSCTL_DECL(_net_bluetooth_l2cap);
SYSCTL_DECL(_net_bluetooth_rfcomm);
SYSCTL_DECL(_net_bluetooth_sco);
#endif /* SYSCTL_DECL */

/*
 * Mbuf qeueue and useful mbufq macros. We do not use ifqueue because we
 * do not need mutex and other locking stuff
 */

struct mbuf;

struct ng_bt_mbufq {
	struct mbuf	*head;   /* first item in the queue */
	struct mbuf	*tail;   /* last item in the queue */
	u_int32_t	 len;    /* number of items in the queue */
	u_int32_t	 maxlen; /* maximal number of items in the queue */
	u_int32_t	 drops;	 /* number if dropped items */
};
typedef struct ng_bt_mbufq	ng_bt_mbufq_t;
typedef struct ng_bt_mbufq *	ng_bt_mbufq_p;

#define NG_BT_MBUFQ_INIT(q, _maxlen)			\
	do {						\
		(q)->head = NULL;			\
		(q)->tail = NULL;			\
		(q)->len = 0;				\
		(q)->maxlen = (_maxlen);		\
		(q)->drops = 0;				\
	} while (0)

#define NG_BT_MBUFQ_DESTROY(q)				\
	do {						\
		NG_BT_MBUFQ_DRAIN((q));			\
	} while (0)

#define NG_BT_MBUFQ_FIRST(q)	(q)->head

#define NG_BT_MBUFQ_LEN(q)	(q)->len

#define NG_BT_MBUFQ_FULL(q)	((q)->len >= (q)->maxlen)

#define NG_BT_MBUFQ_DROP(q)	(q)->drops ++

#define NG_BT_MBUFQ_ENQUEUE(q, i)			\
	do {						\
		(i)->m_nextpkt = NULL;			\
							\
		if ((q)->tail == NULL)			\
			(q)->head = (i);		\
		else					\
			(q)->tail->m_nextpkt = (i);	\
							\
		(q)->tail = (i);			\
		(q)->len ++;				\
	} while (0)

#define NG_BT_MBUFQ_DEQUEUE(q, i)			\
	do {						\
		(i) = (q)->head;			\
		if ((i) != NULL) {			\
			(q)->head = (q)->head->m_nextpkt; \
			if ((q)->head == NULL)		\
				(q)->tail = NULL;	\
							\
			(q)->len --;			\
			(i)->m_nextpkt = NULL;		\
		} 					\
	} while (0)

#define NG_BT_MBUFQ_PREPEND(q, i)			\
	do {						\
		(i)->m_nextpkt = (q)->head;		\
		if ((q)->tail == NULL)			\
			(q)->tail = (i);		\
							\
		(q)->head = (i);			\
		(q)->len ++;				\
	} while (0)

#define NG_BT_MBUFQ_DRAIN(q)				\
	do { 						\
        	struct mbuf	*m = NULL;		\
							\
		for (;;) { 				\
			NG_BT_MBUFQ_DEQUEUE((q), m);	\
			if (m == NULL) 			\
				break; 			\
							\
			NG_FREE_M(m);	 		\
		} 					\
	} while (0)

/*
 * Netgraph item queue and useful itemq macros
 */

struct ng_item;

struct ng_bt_itemq {
	STAILQ_HEAD(, ng_item)	queue;	/* actually items queue */
	u_int32_t	 len;    /* number of items in the queue */
	u_int32_t	 maxlen; /* maximal number of items in the queue */
	u_int32_t	 drops;  /* number if dropped items */
};
typedef struct ng_bt_itemq	ng_bt_itemq_t;
typedef struct ng_bt_itemq *	ng_bt_itemq_p;

#define NG_BT_ITEMQ_INIT(q, _maxlen)			\
	do {						\
		STAILQ_INIT(&(q)->queue);		\
		(q)->len = 0;				\
		(q)->maxlen = (_maxlen);		\
		(q)->drops = 0;				\
	} while (0)

#define NG_BT_ITEMQ_DESTROY(q)				\
	do {						\
		NG_BT_ITEMQ_DRAIN((q));			\
	} while (0)

#define NG_BT_ITEMQ_FIRST(q)	STAILQ_FIRST(&(q)->queue)

#define NG_BT_ITEMQ_LEN(q)	NG_BT_MBUFQ_LEN((q))

#define NG_BT_ITEMQ_FULL(q)	NG_BT_MBUFQ_FULL((q))

#define NG_BT_ITEMQ_DROP(q)	NG_BT_MBUFQ_DROP((q))

#define NG_BT_ITEMQ_ENQUEUE(q, i)			\
	do {						\
		STAILQ_INSERT_TAIL(&(q)->queue, (i), el_next);	\
		(q)->len ++;				\
	} while (0)

#define NG_BT_ITEMQ_DEQUEUE(q, i)			\
	do {						\
		(i) = STAILQ_FIRST(&(q)->queue);	\
		if ((i) != NULL) {			\
			STAILQ_REMOVE_HEAD(&(q)->queue, el_next);	\
			(q)->len --;			\
		} 					\
	} while (0)

#define NG_BT_ITEMQ_PREPEND(q, i)			\
	do {						\
		STAILQ_INSERT_HEAD(&(q)->queue, (i), el_next);	\
		(q)->len ++;				\
	} while (0)

#define NG_BT_ITEMQ_DRAIN(q)				\
	do { 						\
        	struct ng_item	*i = NULL;		\
							\
		for (;;) { 				\
			NG_BT_ITEMQ_DEQUEUE((q), i);	\
			if (i == NULL) 			\
				break; 			\
							\
			NG_FREE_ITEM(i); 		\
		} 					\
	} while (0)

/*
 * Get Bluetooth stack sysctl globals
 */

u_int32_t	bluetooth_hci_command_timeout	(void);
u_int32_t	bluetooth_hci_connect_timeout	(void);
u_int32_t	bluetooth_hci_max_neighbor_age	(void);
u_int32_t	bluetooth_l2cap_rtx_timeout	(void);
u_int32_t	bluetooth_l2cap_ertx_timeout	(void);
u_int32_t      bluetooth_sco_rtx_timeout       (void);

#endif /* _NETGRAPH_BLUETOOTH_H_ */


code:
/*
 * ng_bt3c.h
 */

/*-
 * Copyright (c) 2001-2002 Maksim Yevmenkin <m_evmenkin@yahoo.com>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * $Id: ng_bt3c.h,v 1.1 2002/11/24 19:47:05 max Exp $
 * $FreeBSD: release/9.0.0/sys/netgraph/bluetooth/include/ng_bt3c.h 139823 2005-01-07 01:45:51Z imp $
 *
 * XXX XXX XX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX
 *
 * Based on information obrained from: Jose Orlando Pereira <jop@di.uminho.pt>
 * and disassembled w2k driver.
 *
 * XXX XXX XX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX
 *
 */

#ifndef _NG_BT3C_H_
#define _NG_BT3C_H_

/**************************************************************************
 **************************************************************************
 **     Netgraph node hook name, type name and type cookie and commands
 **************************************************************************
 **************************************************************************/

#define NG_BT3C_NODE_TYPE	"btccc"	/* XXX can't use bt3c in pccard.conf */
#define NG_BT3C_HOOK		"hook"

#define NGM_BT3C_COOKIE		1014752016

/* Debug levels */
#define NG_BT3C_ALERT_LEVEL	1
#define NG_BT3C_ERR_LEVEL	2
#define NG_BT3C_WARN_LEVEL	3
#define NG_BT3C_INFO_LEVEL	4

/* Node states */
#define NG_BT3C_W4_PKT_IND	1               /* wait for packet indicator */
#define NG_BT3C_W4_PKT_HDR	2               /* wait for packet header */
#define NG_BT3C_W4_PKT_DATA	3               /* wait for packet data */

/**************************************************************************
 **************************************************************************
 **                    BT3C node command/event parameters
 **************************************************************************
 **************************************************************************/

#define NGM_BT3C_NODE_GET_STATE	1		/* get node state */
typedef u_int16_t		ng_bt3c_node_state_ep;

#define NGM_BT3C_NODE_SET_DEBUG	2		/* set debug level */
#define NGM_BT3C_NODE_GET_DEBUG	3		/* get debug level */
typedef u_int16_t		ng_bt3c_node_debug_ep;

#define NGM_BT3C_NODE_GET_QLEN	4		/* get queue length */
#define NGM_BT3C_NODE_SET_QLEN	5		/* set queue length */
typedef struct {
	int32_t	queue;				/* queue index */
#define NGM_BT3C_NODE_IN_QUEUE	1		/* incoming queue */
#define NGM_BT3C_NODE_OUT_QUEUE	2		/* outgoing queue */

	int32_t	qlen;				/* queue length */
} ng_bt3c_node_qlen_ep;

#define NGM_BT3C_NODE_GET_STAT	6		/* get statistic */
typedef struct {
	u_int32_t	pckts_recv;		/* # of packets received */
	u_int32_t	bytes_recv;		/* # of bytes received */
	u_int32_t	pckts_sent;		/* # of packets sent */
	u_int32_t	bytes_sent;		/* # of bytes sent */
	u_int32_t	oerrors;		/* # of output errors */
	u_int32_t	ierrors;		/* # of input errors */
} ng_bt3c_node_stat_ep;

#define NGM_BT3C_NODE_RESET_STAT 7		/* reset statistic */

#define NGM_BT3C_NODE_DOWNLOAD_FIRMWARE	8	/* download firmware */

typedef struct {
	u_int32_t	block_address;
	u_int16_t	block_size;		/* in words */
	u_int16_t	block_alignment;	/* in bytes */
} ng_bt3c_firmware_block_ep;

#endif /* ndef _NG_BT3C_H_ */


code:
/*
 * ng_btsocket.h
 */

/*-
 * Copyright (c) 2001-2002 Maksim Yevmenkin <m_evmenkin@yahoo.com>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * $Id: ng_btsocket.h,v 1.8 2003/04/26 22:32:10 max Exp $
 * $FreeBSD: release/9.0.0/sys/netgraph/bluetooth/include/ng_btsocket.h 180399 2008-07-10 00:15:29Z emax $
 */

#ifndef _NETGRAPH_BTSOCKET_H_
#define _NETGRAPH_BTSOCKET_H_

/*
 * Bluetooth protocols
 */

#define BLUETOOTH_PROTO_HCI	134	/* HCI protocol number */
#define BLUETOOTH_PROTO_L2CAP	135	/* L2CAP protocol number */
#define BLUETOOTH_PROTO_RFCOMM	136	/* RFCOMM protocol number */
#define BLUETOOTH_PROTO_SCO	137	/* SCO protocol number */

/*
 * Bluetooth version of struct sockaddr for raw HCI sockets
 */

struct sockaddr_hci {
	u_char		hci_len;	/* total length */
	u_char		hci_family;	/* address family */
	char		hci_node[32];	/* address (size == NG_NODESIZ ) */
};

/* Raw HCI socket options */
#define SOL_HCI_RAW		0x0802	/* socket options level */

#define SO_HCI_RAW_FILTER	1	/* get/set filter on socket */
#define SO_HCI_RAW_DIRECTION	2	/* turn on/off direction info */
#define SCM_HCI_RAW_DIRECTION	SO_HCI_RAW_DIRECTION /* cmsg_type  */

/*
 * Raw HCI socket filter.
 *
 * For packet mask use (1 << (HCI packet indicator - 1))
 * For event mask use (1 << (Event - 1))
 */

struct ng_btsocket_hci_raw_filter {
	bitstr_t	bit_decl(packet_mask, 32);
	bitstr_t	bit_decl(event_mask, (NG_HCI_EVENT_MASK_SIZE * 8));
};

/*
 * Raw HCI sockets ioctl's
 */

/* Get state */
struct ng_btsocket_hci_raw_node_state {
	ng_hci_node_state_ep	state;
};
#define SIOC_HCI_RAW_NODE_GET_STATE \
	_IOWR('b', NGM_HCI_NODE_GET_STATE, \
		struct ng_btsocket_hci_raw_node_state)

/* Initialize */
#define SIOC_HCI_RAW_NODE_INIT \
	_IO('b', NGM_HCI_NODE_INIT)

/* Get/Set debug level */
struct ng_btsocket_hci_raw_node_debug {
	ng_hci_node_debug_ep	debug;
};
#define SIOC_HCI_RAW_NODE_GET_DEBUG \
	_IOWR('b', NGM_HCI_NODE_GET_DEBUG, \
		struct ng_btsocket_hci_raw_node_debug)
#define SIOC_HCI_RAW_NODE_SET_DEBUG \
	_IOWR('b', NGM_HCI_NODE_SET_DEBUG, \
		struct ng_btsocket_hci_raw_node_debug)

/* Get buffer info */
struct ng_btsocket_hci_raw_node_buffer {
	ng_hci_node_buffer_ep	buffer;
};
#define SIOC_HCI_RAW_NODE_GET_BUFFER \
	_IOWR('b', NGM_HCI_NODE_GET_BUFFER, \
		struct ng_btsocket_hci_raw_node_buffer)

/* Get BD_ADDR */
struct ng_btsocket_hci_raw_node_bdaddr {
	bdaddr_t	bdaddr;
};
#define SIOC_HCI_RAW_NODE_GET_BDADDR \
	_IOWR('b', NGM_HCI_NODE_GET_BDADDR, \
		struct ng_btsocket_hci_raw_node_bdaddr)

/* Get features */
struct ng_btsocket_hci_raw_node_features {
	u_int8_t	features[NG_HCI_FEATURES_SIZE];
};
#define SIOC_HCI_RAW_NODE_GET_FEATURES \
	_IOWR('b', NGM_HCI_NODE_GET_FEATURES, \
		struct ng_btsocket_hci_raw_node_features)

/* Get stat */
struct ng_btsocket_hci_raw_node_stat {
	ng_hci_node_stat_ep	stat;
};
#define SIOC_HCI_RAW_NODE_GET_STAT \
	_IOWR('b', NGM_HCI_NODE_GET_STAT, \
		struct ng_btsocket_hci_raw_node_stat)

/* Reset stat */
#define SIOC_HCI_RAW_NODE_RESET_STAT \
	_IO('b', NGM_HCI_NODE_RESET_STAT)

/* Flush neighbor cache */
#define SIOC_HCI_RAW_NODE_FLUSH_NEIGHBOR_CACHE \
	_IO('b', NGM_HCI_NODE_FLUSH_NEIGHBOR_CACHE)

/* Get neighbor cache */
struct ng_btsocket_hci_raw_node_neighbor_cache {
	u_int32_t				 num_entries;
	ng_hci_node_neighbor_cache_entry_ep	*entries;
};
#define SIOC_HCI_RAW_NODE_GET_NEIGHBOR_CACHE \
	_IOWR('b', NGM_HCI_NODE_GET_NEIGHBOR_CACHE, \
		struct ng_btsocket_hci_raw_node_neighbor_cache)

/* Get connection list */
struct ng_btsocket_hci_raw_con_list {
	u_int32_t		 num_connections;
	ng_hci_node_con_ep	*connections;
};
#define SIOC_HCI_RAW_NODE_GET_CON_LIST \
	_IOWR('b', NGM_HCI_NODE_GET_CON_LIST, \
		struct ng_btsocket_hci_raw_con_list)

/* Get/Set link policy settings mask */
struct ng_btsocket_hci_raw_node_link_policy_mask {
	ng_hci_node_link_policy_mask_ep	policy_mask;
};
#define SIOC_HCI_RAW_NODE_GET_LINK_POLICY_MASK \
	_IOWR('b', NGM_HCI_NODE_GET_LINK_POLICY_SETTINGS_MASK, \
		struct ng_btsocket_hci_raw_node_link_policy_mask)
#define SIOC_HCI_RAW_NODE_SET_LINK_POLICY_MASK \
	_IOWR('b', NGM_HCI_NODE_SET_LINK_POLICY_SETTINGS_MASK, \
		struct ng_btsocket_hci_raw_node_link_policy_mask)

/* Get/Set packet mask */
struct ng_btsocket_hci_raw_node_packet_mask {
	ng_hci_node_packet_mask_ep	packet_mask;
};
#define SIOC_HCI_RAW_NODE_GET_PACKET_MASK \
	_IOWR('b', NGM_HCI_NODE_GET_PACKET_MASK, \
		struct ng_btsocket_hci_raw_node_packet_mask)
#define SIOC_HCI_RAW_NODE_SET_PACKET_MASK \
	_IOWR('b', NGM_HCI_NODE_SET_PACKET_MASK, \
		struct ng_btsocket_hci_raw_node_packet_mask)

/* Get/Set role switch */
struct ng_btsocket_hci_raw_node_role_switch {
	ng_hci_node_role_switch_ep	role_switch;
};
#define SIOC_HCI_RAW_NODE_GET_ROLE_SWITCH \
	_IOWR('b', NGM_HCI_NODE_GET_ROLE_SWITCH, \
		struct ng_btsocket_hci_raw_node_role_switch)
#define SIOC_HCI_RAW_NODE_SET_ROLE_SWITCH \
	_IOWR('b', NGM_HCI_NODE_SET_ROLE_SWITCH, \
		struct ng_btsocket_hci_raw_node_role_switch)

/* Get list of HCI node names */
struct ng_btsocket_hci_raw_node_list_names {
	u_int32_t	 num_names;
	struct nodeinfo	*names;
};
#define SIOC_HCI_RAW_NODE_LIST_NAMES \
	_IOWR('b', NGM_HCI_NODE_LIST_NAMES, \
		struct ng_btsocket_hci_raw_node_list_names)

/*
 * XXX FIXME: probably does not belong here
 * Bluetooth version of struct sockaddr for SCO sockets (SEQPACKET)
 */

struct sockaddr_sco {
	u_char		sco_len;	/* total length */
	u_char		sco_family;	/* address family */
	bdaddr_t	sco_bdaddr;	/* address */
};

/* SCO socket options */
#define SOL_SCO		0x0209		/* socket options level */

#define SO_SCO_MTU	1		/* get sockets mtu */
#define SO_SCO_CONNINFO	2		/* get HCI connection handle */

/*
 * XXX FIXME: probably does not belong here
 * Bluetooth version of struct sockaddr for L2CAP sockets (RAW and SEQPACKET)
 */

struct sockaddr_l2cap {
	u_char		l2cap_len;	/* total length */
	u_char		l2cap_family;	/* address family */
	u_int16_t	l2cap_psm;	/* PSM (Protocol/Service Multiplexor) */
	bdaddr_t	l2cap_bdaddr;	/* address */
};

/* L2CAP socket options */
#define SOL_L2CAP		0x1609	/* socket option level */

#define SO_L2CAP_IMTU		1	/* get/set incoming MTU */
#define SO_L2CAP_OMTU		2	/* get outgoing (peer incoming) MTU */
#define SO_L2CAP_IFLOW		3	/* get incoming flow spec. */
#define SO_L2CAP_OFLOW		4	/* get/set outgoing flow spec. */
#define SO_L2CAP_FLUSH		5	/* get/set flush timeout */

/*
 * Raw L2CAP sockets ioctl's
 */

/* Ping */
struct ng_btsocket_l2cap_raw_ping {
	u_int32_t		 result;
	u_int32_t		 echo_size;
	u_int8_t		*echo_data;
};
#define SIOC_L2CAP_L2CA_PING \
	_IOWR('b', NGM_L2CAP_L2CA_PING, \
		struct ng_btsocket_l2cap_raw_ping)

/* Get info */
struct ng_btsocket_l2cap_raw_get_info {
	u_int32_t		 result;
	u_int32_t		 info_type;
	u_int32_t		 info_size;
	u_int8_t		*info_data;
};
#define SIOC_L2CAP_L2CA_GET_INFO \
	_IOWR('b', NGM_L2CAP_L2CA_GET_INFO, \
		struct ng_btsocket_l2cap_raw_get_info)

/* Get flags */
struct ng_btsocket_l2cap_raw_node_flags {
	ng_l2cap_node_flags_ep	flags;
};
#define SIOC_L2CAP_NODE_GET_FLAGS \
	_IOWR('b', NGM_L2CAP_NODE_GET_FLAGS, \
		struct ng_btsocket_l2cap_raw_node_flags)

/* Get/Set debug level */
struct ng_btsocket_l2cap_raw_node_debug {
	ng_l2cap_node_debug_ep	debug;
};
#define SIOC_L2CAP_NODE_GET_DEBUG \
	_IOWR('b', NGM_L2CAP_NODE_GET_DEBUG, \
		struct ng_btsocket_l2cap_raw_node_debug)
#define SIOC_L2CAP_NODE_SET_DEBUG \
	_IOWR('b', NGM_L2CAP_NODE_SET_DEBUG, \
		struct ng_btsocket_l2cap_raw_node_debug)

/* Get connection list */
struct ng_btsocket_l2cap_raw_con_list {
	u_int32_t		 num_connections;
	ng_l2cap_node_con_ep	*connections;
};
#define SIOC_L2CAP_NODE_GET_CON_LIST \
	_IOWR('b', NGM_L2CAP_NODE_GET_CON_LIST, \
		struct ng_btsocket_l2cap_raw_con_list)

/* Get channel list */
struct ng_btsocket_l2cap_raw_chan_list {
	u_int32_t		 num_channels;
	ng_l2cap_node_chan_ep	*channels;
};
#define SIOC_L2CAP_NODE_GET_CHAN_LIST \
	_IOWR('b', NGM_L2CAP_NODE_GET_CHAN_LIST, \
		struct ng_btsocket_l2cap_raw_chan_list)

/* Get/Set auto disconnect timeout */
struct ng_btsocket_l2cap_raw_auto_discon_timo
{
	ng_l2cap_node_auto_discon_ep	timeout;
};
#define SIOC_L2CAP_NODE_GET_AUTO_DISCON_TIMO \
	_IOWR('b', NGM_L2CAP_NODE_GET_AUTO_DISCON_TIMO, \
		struct ng_btsocket_l2cap_raw_auto_discon_timo)
#define SIOC_L2CAP_NODE_SET_AUTO_DISCON_TIMO \
	_IOWR('b', NGM_L2CAP_NODE_SET_AUTO_DISCON_TIMO, \
		struct ng_btsocket_l2cap_raw_auto_discon_timo)

/*
 * XXX FIXME: probably does not belong here
 * Bluetooth version of struct sockaddr for RFCOMM sockets (STREAM)
 */

struct sockaddr_rfcomm {
	u_char		rfcomm_len;	/* total length */
	u_char		rfcomm_family;	/* address family */
	bdaddr_t	rfcomm_bdaddr;	/* address */
	u_int8_t	rfcomm_channel;	/* channel */
};

/* Flow control information */
struct ng_btsocket_rfcomm_fc_info {
	u_int8_t	lmodem;		/* modem signals (local) */
	u_int8_t	rmodem;		/* modem signals (remote) */
	u_int8_t	tx_cred;	/* TX credits */
	u_int8_t	rx_cred;	/* RX credits */
	u_int8_t	cfc;		/* credit flow control */
	u_int8_t	reserved;
};

/* STREAM RFCOMM socket options */
#define SOL_RFCOMM		0x0816	/* socket options level */

#define SO_RFCOMM_MTU		1	/* get channel MTU */
#define SO_RFCOMM_FC_INFO	2	/* get flow control information */

/*
 * Netgraph node type name and cookie
 */

#define	NG_BTSOCKET_HCI_RAW_NODE_TYPE	"btsock_hci_raw"
#define	NG_BTSOCKET_L2CAP_RAW_NODE_TYPE	"btsock_l2c_raw"
#define	NG_BTSOCKET_L2CAP_NODE_TYPE	"btsock_l2c"
#define	NG_BTSOCKET_SCO_NODE_TYPE	"btsock_sco"

/*
 * Debug levels
 */

#define NG_BTSOCKET_ALERT_LEVEL	1
#define NG_BTSOCKET_ERR_LEVEL	2
#define NG_BTSOCKET_WARN_LEVEL	3
#define NG_BTSOCKET_INFO_LEVEL	4

#endif /* _NETGRAPH_BTSOCKET_H_ */


code:
/*
 * ng_btsocket_hci_raw.h
 */

/*-
 * Copyright (c) 2001-2002 Maksim Yevmenkin <m_evmenkin@yahoo.com>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * $Id: ng_btsocket_hci_raw.h,v 1.3 2003/03/25 23:53:32 max Exp $
 * $FreeBSD: release/9.0.0/sys/netgraph/bluetooth/include/ng_btsocket_hci_raw.h 160549 2006-07-21 17:11:15Z rwatson $
 */

#ifndef _NETGRAPH_BTSOCKET_HCI_RAW_H_
#define _NETGRAPH_BTSOCKET_HCI_RAW_H_

#define NG_BTSOCKET_HCI_RAW_SENDSPACE	(4 * 1024)
#define NG_BTSOCKET_HCI_RAW_RECVSPACE	(4 * 1024)

/*
 * Bluetooth raw HCI socket PCB
 */

struct ng_btsocket_hci_raw_pcb {
	struct socket				*so;     /* socket */
	u_int32_t				 flags;  /* flags */
#define NG_BTSOCKET_HCI_RAW_DIRECTION	(1 << 0)
#define NG_BTSOCKET_HCI_RAW_PRIVILEGED	(1 << 1)
	struct sockaddr_hci			 addr;   /* local address */
	struct ng_btsocket_hci_raw_filter	 filter; /* filter */
	u_int32_t				 token;  /* message token */
	struct ng_mesg				*msg;    /* message */
	LIST_ENTRY(ng_btsocket_hci_raw_pcb)	 next;   /* link to next */
	struct mtx				 pcb_mtx; /* pcb mutex */
};
typedef struct ng_btsocket_hci_raw_pcb		ng_btsocket_hci_raw_pcb_t;
typedef struct ng_btsocket_hci_raw_pcb *	ng_btsocket_hci_raw_pcb_p;

#define	so2hci_raw_pcb(so) \
	((struct ng_btsocket_hci_raw_pcb *)((so)->so_pcb))

/*
 * Bluetooth raw HCI socket methods
 */

#ifdef _KERNEL

void ng_btsocket_hci_raw_init       (void);
void ng_btsocket_hci_raw_abort      (struct socket *);
void ng_btsocket_hci_raw_close      (struct socket *);
int  ng_btsocket_hci_raw_attach     (struct socket *, int, struct thread *);
int  ng_btsocket_hci_raw_bind       (struct socket *, struct sockaddr *,
                                     struct thread *);
int  ng_btsocket_hci_raw_connect    (struct socket *, struct sockaddr *,
                                     struct thread *);
int  ng_btsocket_hci_raw_control    (struct socket *, u_long, caddr_t,
                                     struct ifnet *, struct thread *);
int  ng_btsocket_hci_raw_ctloutput  (struct socket *, struct sockopt *);
void ng_btsocket_hci_raw_detach     (struct socket *);
int  ng_btsocket_hci_raw_disconnect (struct socket *);
int  ng_btsocket_hci_raw_peeraddr   (struct socket *, struct sockaddr **);
int  ng_btsocket_hci_raw_send       (struct socket *, int, struct mbuf *,
                                     struct sockaddr *, struct mbuf *,
                                     struct thread *);
int  ng_btsocket_hci_raw_sockaddr   (struct socket *, struct sockaddr **);

#endif /* _KERNEL */

#endif /* ndef _NETGRAPH_BTSOCKET_HCI_RAW_H_ */


code:
/*
 * ng_btsocket_l2cap.h
 */

/*-
 * Copyright (c) 2001-2002 Maksim Yevmenkin <m_evmenkin@yahoo.com>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * $Id: ng_btsocket_l2cap.h,v 1.4 2003/03/25 23:53:33 max Exp $
 * $FreeBSD: release/9.0.0/sys/netgraph/bluetooth/include/ng_btsocket_l2cap.h 160549 2006-07-21 17:11:15Z rwatson $
 */

#ifndef _NETGRAPH_BTSOCKET_L2CAP_H_
#define _NETGRAPH_BTSOCKET_L2CAP_H_

/*
 * L2CAP routing entry
 */

struct ng_hook;
struct ng_message;

struct ng_btsocket_l2cap_rtentry {
	bdaddr_t				 src;  /* source BD_ADDR */
	struct ng_hook				*hook; /* downstream hook */
	LIST_ENTRY(ng_btsocket_l2cap_rtentry)	 next; /* link to next */
};
typedef struct ng_btsocket_l2cap_rtentry	ng_btsocket_l2cap_rtentry_t;
typedef struct ng_btsocket_l2cap_rtentry *	ng_btsocket_l2cap_rtentry_p;

/*****************************************************************************
 *****************************************************************************
 **                          SOCK_RAW L2CAP sockets                         **
 *****************************************************************************
 *****************************************************************************/

#define NG_BTSOCKET_L2CAP_RAW_SENDSPACE	NG_L2CAP_MTU_DEFAULT
#define NG_BTSOCKET_L2CAP_RAW_RECVSPACE	NG_L2CAP_MTU_DEFAULT

/*
 * Bluetooth raw L2CAP socket PCB
 */

struct ng_btsocket_l2cap_raw_pcb {
	struct socket				*so;	/* socket */

	u_int32_t				 flags; /* flags */
#define NG_BTSOCKET_L2CAP_RAW_PRIVILEGED	(1 << 0)

	bdaddr_t				 src;	/* source address */
	bdaddr_t				 dst;	/* dest address */
	ng_btsocket_l2cap_rtentry_p		 rt;    /* routing info */

	u_int32_t				 token;	/* message token */
	struct ng_mesg				*msg;   /* message */

	struct mtx				 pcb_mtx; /* pcb mutex */

	LIST_ENTRY(ng_btsocket_l2cap_raw_pcb)	 next;  /* link to next PCB */
};
typedef struct ng_btsocket_l2cap_raw_pcb	ng_btsocket_l2cap_raw_pcb_t;
typedef struct ng_btsocket_l2cap_raw_pcb *	ng_btsocket_l2cap_raw_pcb_p;

#define	so2l2cap_raw_pcb(so) \
	((struct ng_btsocket_l2cap_raw_pcb *)((so)->so_pcb))

/*
 * Bluetooth raw L2CAP socket methods
 */

#ifdef _KERNEL

void ng_btsocket_l2cap_raw_init       (void);
void ng_btsocket_l2cap_raw_abort      (struct socket *);
void ng_btsocket_l2cap_raw_close      (struct socket *);
int  ng_btsocket_l2cap_raw_attach     (struct socket *, int, struct thread *);
int  ng_btsocket_l2cap_raw_bind       (struct socket *, struct sockaddr *,
                                       struct thread *);
int  ng_btsocket_l2cap_raw_connect    (struct socket *, struct sockaddr *,
                                       struct thread *);
int  ng_btsocket_l2cap_raw_control    (struct socket *, u_long, caddr_t,
                                       struct ifnet *, struct thread *);
void ng_btsocket_l2cap_raw_detach     (struct socket *);
int  ng_btsocket_l2cap_raw_disconnect (struct socket *);
int  ng_btsocket_l2cap_raw_peeraddr   (struct socket *, struct sockaddr **);
int  ng_btsocket_l2cap_raw_send       (struct socket *, int, struct mbuf *,
                                       struct sockaddr *, struct mbuf *,
                                       struct thread *);
int  ng_btsocket_l2cap_raw_sockaddr   (struct socket *, struct sockaddr **);

#endif /* _KERNEL */

/*****************************************************************************
 *****************************************************************************
 **                    SOCK_SEQPACKET L2CAP sockets                         **
 *****************************************************************************
 *****************************************************************************/

#define NG_BTSOCKET_L2CAP_SENDSPACE	NG_L2CAP_MTU_DEFAULT /* (64 * 1024) */
#define NG_BTSOCKET_L2CAP_RECVSPACE	(64 * 1024)

/*
 * Bluetooth L2CAP socket PCB
 */

struct ng_btsocket_l2cap_pcb {
	struct socket			*so;	     /* Pointer to socket */

	bdaddr_t			 src;	     /* Source address */
	bdaddr_t			 dst;	     /* Destination address */

	u_int16_t			 psm;	     /* PSM */
	u_int16_t			 cid;	     /* Local channel ID */

	u_int16_t			 flags;      /* socket flags */
#define NG_BTSOCKET_L2CAP_CLIENT	(1 << 0)     /* socket is client */
#define NG_BTSOCKET_L2CAP_TIMO		(1 << 1)     /* timeout pending */

	u_int8_t			 state;      /* socket state */
#define NG_BTSOCKET_L2CAP_CLOSED	0            /* socket closed */
#define NG_BTSOCKET_L2CAP_CONNECTING	1            /* wait for connect */
#define NG_BTSOCKET_L2CAP_CONFIGURING	2            /* wait for config */
#define NG_BTSOCKET_L2CAP_OPEN		3            /* socket open */
#define NG_BTSOCKET_L2CAP_DISCONNECTING	4            /* wait for disconnect */

	u_int8_t			 cfg_state;  /* config state */
#define	NG_BTSOCKET_L2CAP_CFG_IN	(1 << 0)     /* incoming path done */
#define	NG_BTSOCKET_L2CAP_CFG_OUT	(1 << 1)     /* outgoing path done */
#define	NG_BTSOCKET_L2CAP_CFG_BOTH \
	(NG_BTSOCKET_L2CAP_CFG_IN | NG_BTSOCKET_L2CAP_CFG_OUT)

#define	NG_BTSOCKET_L2CAP_CFG_IN_SENT	(1 << 2)     /* L2CAP ConfigReq sent */
#define	NG_BTSOCKET_L2CAP_CFG_OUT_SENT	(1 << 3)     /* ---/--- */

	u_int16_t			 imtu;       /* Incoming MTU */
	ng_l2cap_flow_t			 iflow;      /* Input flow spec */

	u_int16_t			 omtu;       /* Outgoing MTU */
	ng_l2cap_flow_t			 oflow;      /* Outgoing flow spec */

	u_int16_t			 flush_timo; /* flush timeout */
	u_int16_t			 link_timo;  /* link timeout */

	struct callout_handle		 timo;       /* timeout */

	u_int32_t			 token;	     /* message token */
	ng_btsocket_l2cap_rtentry_p	 rt;         /* routing info */

	struct mtx			 pcb_mtx;    /* pcb mutex */

	LIST_ENTRY(ng_btsocket_l2cap_pcb) next;      /* link to next PCB */
};
typedef struct ng_btsocket_l2cap_pcb	ng_btsocket_l2cap_pcb_t;
typedef struct ng_btsocket_l2cap_pcb *	ng_btsocket_l2cap_pcb_p;

#define	so2l2cap_pcb(so) \
	((struct ng_btsocket_l2cap_pcb *)((so)->so_pcb))

/*
 * Bluetooth L2CAP socket methods
 */

#ifdef _KERNEL

void ng_btsocket_l2cap_init       (void);
void ng_btsocket_l2cap_abort      (struct socket *);
void ng_btsocket_l2cap_close      (struct socket *);
int  ng_btsocket_l2cap_accept     (struct socket *, struct sockaddr **);
int  ng_btsocket_l2cap_attach     (struct socket *, int, struct thread *);
int  ng_btsocket_l2cap_bind       (struct socket *, struct sockaddr *,
                                   struct thread *);
int  ng_btsocket_l2cap_connect    (struct socket *, struct sockaddr *,
                                   struct thread *);
int  ng_btsocket_l2cap_control    (struct socket *, u_long, caddr_t,
                                   struct ifnet *, struct thread *);
int  ng_btsocket_l2cap_ctloutput  (struct socket *, struct sockopt *);
void ng_btsocket_l2cap_detach     (struct socket *);
int  ng_btsocket_l2cap_disconnect (struct socket *);
int  ng_btsocket_l2cap_listen     (struct socket *, int, struct thread *);
int  ng_btsocket_l2cap_peeraddr   (struct socket *, struct sockaddr **);
int  ng_btsocket_l2cap_send       (struct socket *, int, struct mbuf *,
                                   struct sockaddr *, struct mbuf *,
                                   struct thread *);
int  ng_btsocket_l2cap_sockaddr   (struct socket *, struct sockaddr **);

#endif /* _KERNEL */

#endif /* _NETGRAPH_BTSOCKET_L2CAP_H_ */


code:
/*
 * ng_btsocket_rfcomm.h
 */

/*-
 * Copyright (c) 2001-2003 Maksim Yevmenkin <m_evmenkin@yahoo.com>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * $Id: ng_btsocket_rfcomm.h,v 1.10 2003/03/29 22:27:42 max Exp $
 * $FreeBSD: release/9.0.0/sys/netgraph/bluetooth/include/ng_btsocket_rfcomm.h 197083 2009-09-10 23:30:13Z emax $
 */

#ifndef _NETGRAPH_BTSOCKET_RFCOMM_H_
#define _NETGRAPH_BTSOCKET_RFCOMM_H_

/*****************************************************************************
 *****************************************************************************
 **                              RFCOMM                                     **
 *****************************************************************************
 *****************************************************************************/

/* XXX FIXME this does not belong here */

#define RFCOMM_DEFAULT_MTU		667
#define RFCOMM_MAX_MTU			1024

#define RFCOMM_DEFAULT_CREDITS		7
#define RFCOMM_MAX_CREDITS		40

/* RFCOMM frame types */
#define RFCOMM_FRAME_SABM		0x2f
#define RFCOMM_FRAME_DISC		0x43
#define RFCOMM_FRAME_UA			0x63
#define RFCOMM_FRAME_DM			0x0f
#define RFCOMM_FRAME_UIH		0xef

/* RFCOMM MCC commands */
#define RFCOMM_MCC_TEST			0x08 /* Test */
#define RFCOMM_MCC_FCON			0x28 /* Flow Control on */
#define RFCOMM_MCC_FCOFF		0x18 /* Flow Control off */
#define RFCOMM_MCC_MSC			0x38 /* Modem Status Command */
#define RFCOMM_MCC_RPN			0x24 /* Remote Port Negotiation */
#define RFCOMM_MCC_RLS			0x14 /* Remote Line Status */
#define RFCOMM_MCC_PN			0x20 /* Port Negotiation */
#define RFCOMM_MCC_NSC			0x04 /* Non Supported Command */

/* RFCOMM modem signals */
#define RFCOMM_MODEM_FC			0x02 /* Flow Control asserted */
#define RFCOMM_MODEM_RTC		0x04 /* Ready To Communicate */
#define RFCOMM_MODEM_RTR		0x08 /* Ready To Receive */
#define RFCOMM_MODEM_IC			0x40 /* Incomming Call */
#define RFCOMM_MODEM_DV			0x80 /* Data Valid */

/* RPN parameters - baud rate */
#define RFCOMM_RPN_BR_2400		0x0
#define RFCOMM_RPN_BR_4800		0x1
#define RFCOMM_RPN_BR_7200		0x2
#define RFCOMM_RPN_BR_9600		0x3
#define RFCOMM_RPN_BR_19200		0x4
#define RFCOMM_RPN_BR_38400		0x5
#define RFCOMM_RPN_BR_57600		0x6
#define RFCOMM_RPN_BR_115200		0x7
#define RFCOMM_RPN_BR_230400		0x8

/* RPN parameters - data bits */
#define RFCOMM_RPN_DATA_5		0x0
#define RFCOMM_RPN_DATA_6		0x2
#define RFCOMM_RPN_DATA_7		0x1
#define RFCOMM_RPN_DATA_8		0x3

/* RPN parameters - stop bit */
#define RFCOMM_RPN_STOP_1		0
#define RFCOMM_RPN_STOP_15		1

/* RPN parameters - parity */
#define RFCOMM_RPN_PARITY_NONE		0x0
#define RFCOMM_RPN_PARITY_ODD		0x4
#define RFCOMM_RPN_PARITY_EVEN		0x5
#define RFCOMM_RPN_PARITY_MARK		0x6
#define RFCOMM_RPN_PARITY_SPACE		0x7

/* RPN parameters - flow control */
#define RFCOMM_RPN_FLOW_NONE		0x00
#define RFCOMM_RPN_XON_CHAR		0x11
#define RFCOMM_RPN_XOFF_CHAR		0x13

/* RPN parameters - mask */
#define RFCOMM_RPN_PM_BITRATE		0x0001
#define RFCOMM_RPN_PM_DATA		0x0002
#define RFCOMM_RPN_PM_STOP		0x0004
#define RFCOMM_RPN_PM_PARITY		0x0008
#define RFCOMM_RPN_PM_PARITY_TYPE	0x0010
#define RFCOMM_RPN_PM_XON		0x0020
#define RFCOMM_RPN_PM_XOFF		0x0040
#define RFCOMM_RPN_PM_FLOW		0x3F00
#define RFCOMM_RPN_PM_ALL		0x3F7F

/* RFCOMM frame header */
struct rfcomm_frame_hdr
{
	u_int8_t	address;
	u_int8_t	control;
	u_int8_t	length;	/* Actual size could be 2 bytes */
} __attribute__ ((packed));

/* RFCOMM command frame header */
struct rfcomm_cmd_hdr
{
	u_int8_t	address;
	u_int8_t	control;
	u_int8_t	length;
	u_int8_t	fcs;
} __attribute__ ((packed));

/* RFCOMM MCC command header */
struct rfcomm_mcc_hdr
{
	u_int8_t	type;
	u_int8_t	length; /* XXX FIXME Can actual size be 2 bytes?? */
} __attribute__ ((packed));

/* RFCOMM MSC command */
struct rfcomm_mcc_msc
{
	u_int8_t	address;
	u_int8_t	modem;
} __attribute__ ((packed));

/* RFCOMM RPN command */
struct rfcomm_mcc_rpn
{
	u_int8_t	dlci;
	u_int8_t	bit_rate;
	u_int8_t	line_settings;
	u_int8_t	flow_control;
	u_int8_t	xon_char;
	u_int8_t	xoff_char;
	u_int16_t	param_mask;
} __attribute__ ((packed));

/* RFCOMM RLS command */
struct rfcomm_mcc_rls
{
	u_int8_t	address;
	u_int8_t	status;
} __attribute__ ((packed));

/* RFCOMM PN command */
struct rfcomm_mcc_pn
{
	u_int8_t	dlci;
	u_int8_t	flow_control;
	u_int8_t	priority;
	u_int8_t	ack_timer;
	u_int16_t	mtu;
	u_int8_t	max_retrans;
	u_int8_t	credits;
} __attribute__ ((packed));

/* RFCOMM frame parsing macros */
#define RFCOMM_DLCI(b)			(((b) & 0xfc) >> 2)
#define RFCOMM_CHANNEL(b)		(((b) & 0xf8) >> 3)
#define RFCOMM_DIRECTION(b)		(((b) & 0x04) >> 2)
#define RFCOMM_TYPE(b)			(((b) & 0xef))

#define RFCOMM_EA(b)			(((b) & 0x01))
#define RFCOMM_CR(b)			(((b) & 0x02) >> 1)
#define RFCOMM_PF(b)			(((b) & 0x10) >> 4)

#define RFCOMM_SRVCHANNEL(dlci)		((dlci) >> 1)

#define RFCOMM_MKADDRESS(cr, dlci) \
	((((dlci) & 0x3f) << 2) | ((cr) << 1) | 0x01)

#define RFCOMM_MKCONTROL(type, pf)	((((type) & 0xef) | ((pf) << 4)))
#define RFCOMM_MKDLCI(dir, channel)	((((channel) & 0x1f) << 1) | (dir))

#define RFCOMM_MKLEN8(len)		(((len) << 1) | 1)
#define RFCOMM_MKLEN16(len)		((len) << 1)

/* RFCOMM MCC macros */
#define RFCOMM_MCC_TYPE(b)		(((b) & 0xfc) >> 2)
#define RFCOMM_MCC_LENGTH(b)		(((b) & 0xfe) >> 1)
#define RFCOMM_MKMCC_TYPE(cr, type)	((((type) << 2) | ((cr) << 1) | 0x01))

/* RPN macros */
#define RFCOMM_RPN_DATA_BITS(line)	((line) & 0x3)
#define RFCOMM_RPN_STOP_BITS(line)	(((line) >> 2) & 0x1)
#define RFCOMM_RPN_PARITY(line)		(((line) >> 3) & 0x3)
#define RFCOMM_MKRPN_LINE_SETTINGS(data, stop, parity) \
	(((data) & 0x3) | (((stop) & 0x1) << 2) | (((parity) & 0x3) << 3))

/*****************************************************************************
 *****************************************************************************
 **                      SOCK_STREAM RFCOMM sockets                         **
 *****************************************************************************
 *****************************************************************************/

#define NG_BTSOCKET_RFCOMM_SENDSPACE \
	(RFCOMM_MAX_CREDITS * RFCOMM_DEFAULT_MTU * 2)
#define NG_BTSOCKET_RFCOMM_RECVSPACE \
	(RFCOMM_MAX_CREDITS * RFCOMM_DEFAULT_MTU * 2)

/*
 * Bluetooth RFCOMM session. One L2CAP connection == one RFCOMM session
 */

struct ng_btsocket_rfcomm_pcb;
struct ng_btsocket_rfcomm_session;

struct ng_btsocket_rfcomm_session {
	struct socket				*l2so;	 /* L2CAP socket */

	u_int16_t				 state;  /* session state */
#define NG_BTSOCKET_RFCOMM_SESSION_CLOSED	 0
#define NG_BTSOCKET_RFCOMM_SESSION_LISTENING	 1
#define NG_BTSOCKET_RFCOMM_SESSION_CONNECTING	 2
#define NG_BTSOCKET_RFCOMM_SESSION_CONNECTED	 3
#define NG_BTSOCKET_RFCOMM_SESSION_OPEN		 4
#define NG_BTSOCKET_RFCOMM_SESSION_DISCONNECTING 5

	u_int16_t				 flags;  /* session flags */
#define NG_BTSOCKET_RFCOMM_SESSION_INITIATOR	(1 << 0) /* initiator */
#define NG_BTSOCKET_RFCOMM_SESSION_LFC		(1 << 1) /* local flow */
#define NG_BTSOCKET_RFCOMM_SESSION_RFC		(1 << 2) /* remote flow */

#define INITIATOR(s) \
	(((s)->flags & NG_BTSOCKET_RFCOMM_SESSION_INITIATOR)? 1 : 0)

	u_int16_t				 mtu;    /* default MTU */
	struct ng_bt_mbufq			 outq;   /* outgoing queue */

	struct mtx				 session_mtx; /* session lock */
	LIST_HEAD(, ng_btsocket_rfcomm_pcb)	 dlcs;	 /* active DLC */

	LIST_ENTRY(ng_btsocket_rfcomm_session)	 next;	 /* link to next */
};
typedef struct ng_btsocket_rfcomm_session	ng_btsocket_rfcomm_session_t;
typedef struct ng_btsocket_rfcomm_session *	ng_btsocket_rfcomm_session_p;

/*
 * Bluetooth RFCOMM socket PCB (DLC)
 */

struct ng_btsocket_rfcomm_pcb {
	struct socket				*so;	  /* RFCOMM socket */
	struct ng_btsocket_rfcomm_session	*session; /* RFCOMM session */

	u_int16_t				 flags;   /* DLC flags */
#define NG_BTSOCKET_RFCOMM_DLC_TIMO		(1 << 0)  /* timeout pending */
#define NG_BTSOCKET_RFCOMM_DLC_CFC		(1 << 1)  /* credit flow ctrl */
#define NG_BTSOCKET_RFCOMM_DLC_TIMEDOUT		(1 << 2)  /* timeout happend */
#define NG_BTSOCKET_RFCOMM_DLC_DETACHED		(1 << 3)  /* DLC detached */
#define NG_BTSOCKET_RFCOMM_DLC_SENDING		(1 << 4)  /* send pending */

	u_int16_t				 state;   /* DLC state */
#define NG_BTSOCKET_RFCOMM_DLC_CLOSED		0
#define NG_BTSOCKET_RFCOMM_DLC_W4_CONNECT	1
#define NG_BTSOCKET_RFCOMM_DLC_CONFIGURING	2
#define NG_BTSOCKET_RFCOMM_DLC_CONNECTING	3
#define NG_BTSOCKET_RFCOMM_DLC_CONNECTED	4
#define NG_BTSOCKET_RFCOMM_DLC_DISCONNECTING	5

	bdaddr_t				 src;     /* source address */
	bdaddr_t				 dst;     /* dest. address */

	u_int8_t				 channel; /* RFCOMM channel */
	u_int8_t				 dlci;    /* RFCOMM DLCI */

	u_int8_t				 lmodem;  /* local mdm signls */
	u_int8_t				 rmodem;  /* remote -/- */

	u_int16_t				 mtu;	  /* MTU */
	int16_t					 rx_cred; /* RX credits */
	int16_t					 tx_cred; /* TX credits */

	struct mtx				 pcb_mtx; /* PCB lock */
	struct callout_handle			 timo;    /* timeout */

	LIST_ENTRY(ng_btsocket_rfcomm_pcb)	 session_next;/* link to next */
	LIST_ENTRY(ng_btsocket_rfcomm_pcb)	 next;	  /* link to next */
};
typedef struct ng_btsocket_rfcomm_pcb	ng_btsocket_rfcomm_pcb_t;
typedef struct ng_btsocket_rfcomm_pcb *	ng_btsocket_rfcomm_pcb_p;

#define	so2rfcomm_pcb(so) \
	((struct ng_btsocket_rfcomm_pcb *)((so)->so_pcb))

/*
 * Bluetooth RFCOMM socket methods
 */

#ifdef _KERNEL

void ng_btsocket_rfcomm_init       (void);
void ng_btsocket_rfcomm_abort      (struct socket *);
void ng_btsocket_rfcomm_close      (struct socket *);
int  ng_btsocket_rfcomm_accept     (struct socket *, struct sockaddr **);
int  ng_btsocket_rfcomm_attach     (struct socket *, int, struct thread *);
int  ng_btsocket_rfcomm_bind       (struct socket *, struct sockaddr *,
                                    struct thread *);
int  ng_btsocket_rfcomm_connect    (struct socket *, struct sockaddr *,
                                    struct thread *);
int  ng_btsocket_rfcomm_control    (struct socket *, u_long, caddr_t,
                                    struct ifnet *, struct thread *);
int  ng_btsocket_rfcomm_ctloutput  (struct socket *, struct sockopt *);
void ng_btsocket_rfcomm_detach     (struct socket *);
int  ng_btsocket_rfcomm_disconnect (struct socket *);
int  ng_btsocket_rfcomm_listen     (struct socket *, int, struct thread *);
int  ng_btsocket_rfcomm_peeraddr   (struct socket *, struct sockaddr **);
int  ng_btsocket_rfcomm_send       (struct socket *, int, struct mbuf *,
                                    struct sockaddr *, struct mbuf *,
                                    struct thread *);
int  ng_btsocket_rfcomm_sockaddr   (struct socket *, struct sockaddr **);

#endif /* _KERNEL */

#endif /* _NETGRAPH_BTSOCKET_RFCOMM_H_ */


code:
/*
 * ng_btsocket_sco.h
 */

/*-
 * Copyright (c) 2001-2002 Maksim Yevmenkin <m_evmenkin@yahoo.com>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * $Id: ng_btsocket_sco.h,v 1.3 2005/10/31 18:08:52 max Exp $
 * $FreeBSD: release/9.0.0/sys/netgraph/bluetooth/include/ng_btsocket_sco.h 181033 2008-07-30 22:41:23Z emax $
 */

#ifndef _NETGRAPH_BTSOCKET_SCO_H_
#define _NETGRAPH_BTSOCKET_SCO_H_

/*
 * SCO routing entry
 */

struct ng_hook;
struct ng_message;

struct ng_btsocket_sco_rtentry {
	bdaddr_t				 src;  /* source BD_ADDR */
	u_int16_t				 pkt_size; /* mtu */
	u_int16_t				 num_pkts; /* buffer size */
	int32_t					 pending; /* pending packets */
	struct ng_hook				*hook; /* downstream hook */
	LIST_ENTRY(ng_btsocket_sco_rtentry)	 next; /* link to next */
};
typedef struct ng_btsocket_sco_rtentry		ng_btsocket_sco_rtentry_t;
typedef struct ng_btsocket_sco_rtentry *	ng_btsocket_sco_rtentry_p;

/*****************************************************************************
 *****************************************************************************
 **                      SOCK_SEQPACKET SCO sockets                         **
 *****************************************************************************
 *****************************************************************************/

#define NG_BTSOCKET_SCO_SENDSPACE	1024
#define NG_BTSOCKET_SCO_RECVSPACE	(64 * 1024)

/*
 * Bluetooth SCO socket PCB
 */

struct ng_btsocket_sco_pcb {
	struct socket			*so;	     /* Pointer to socket */

	bdaddr_t			 src;	     /* Source address */
	bdaddr_t			 dst;	     /* Destination address */

	u_int16_t			 con_handle; /* connection handle */

	u_int16_t			 flags;      /* socket flags */
#define NG_BTSOCKET_SCO_CLIENT		(1 << 0)     /* socket is client */
#define NG_BTSOCKET_SCO_TIMO		(1 << 1)     /* timeout pending */

	u_int8_t			 state;      /* socket state */
#define NG_BTSOCKET_SCO_CLOSED		0            /* socket closed */
#define NG_BTSOCKET_SCO_CONNECTING	1            /* wait for connect */
#define NG_BTSOCKET_SCO_OPEN		2            /* socket open */
#define NG_BTSOCKET_SCO_DISCONNECTING	3            /* wait for disconnect */

	struct callout			 timo;       /* timeout */

	ng_btsocket_sco_rtentry_p	 rt;         /* routing info */

	struct mtx			 pcb_mtx;    /* pcb mutex */

	LIST_ENTRY(ng_btsocket_sco_pcb)	 next;       /* link to next PCB */
};
typedef struct ng_btsocket_sco_pcb	ng_btsocket_sco_pcb_t;
typedef struct ng_btsocket_sco_pcb *	ng_btsocket_sco_pcb_p;

#define	so2sco_pcb(so) \
	((struct ng_btsocket_sco_pcb *)((so)->so_pcb))

/*
 * Bluetooth SCO socket methods
 */

#ifdef _KERNEL

void ng_btsocket_sco_init       (void);
void ng_btsocket_sco_abort      (struct socket *);
void ng_btsocket_sco_close      (struct socket *);
int  ng_btsocket_sco_accept     (struct socket *, struct sockaddr **);
int  ng_btsocket_sco_attach     (struct socket *, int, struct thread *);
int  ng_btsocket_sco_bind       (struct socket *, struct sockaddr *,
                                   struct thread *);
int  ng_btsocket_sco_connect    (struct socket *, struct sockaddr *,
                                   struct thread *);
int  ng_btsocket_sco_control    (struct socket *, u_long, caddr_t,
                                   struct ifnet *, struct thread *);
int  ng_btsocket_sco_ctloutput  (struct socket *, struct sockopt *);
void ng_btsocket_sco_detach     (struct socket *);
int  ng_btsocket_sco_disconnect (struct socket *);
int  ng_btsocket_sco_listen     (struct socket *, int, struct thread *);
int  ng_btsocket_sco_peeraddr   (struct socket *, struct sockaddr **);
int  ng_btsocket_sco_send       (struct socket *, int, struct mbuf *,
                                   struct sockaddr *, struct mbuf *,
                                   struct thread *);
int  ng_btsocket_sco_sockaddr   (struct socket *, struct sockaddr **);

#endif /* _KERNEL */

#endif /* _NETGRAPH_BTSOCKET_SCO_H_ */


code:
/*
 * ng_h4.h
 */

/*-
 * Copyright (c) 2001-2002 Maksim Yevmenkin <m_evmenkin@yahoo.com>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * $Id: ng_h4.h,v 1.1 2002/11/24 19:47:05 max Exp $
 * $FreeBSD: release/9.0.0/sys/netgraph/bluetooth/include/ng_h4.h 139823 2005-01-07 01:45:51Z imp $
 *
 * Based on:
 * ---------
 *
 * FreeBSD: src/sys/netgraph/ng_tty.h
 * Author: Archie Cobbs <archie@freebsd.org>
 */

/*
 * This file contains everything that application needs to know about
 * Bluetooth HCI UART transport layer as per chapter H4 of the Bluetooth
 * Specification Book v1.1.
 *
 * This file can be included by both kernel and userland applications.
 */

#ifndef _NETGRAPH_H4_H_
#define _NETGRAPH_H4_H_

/**************************************************************************
 **************************************************************************
 **     Netgraph node hook name, type name and type cookie and commands
 **************************************************************************
 **************************************************************************/

/* Hook name */
#define NG_H4_HOOK		"hook"

/* Node type name and magic cookie */
#define NG_H4_NODE_TYPE		"h4"
#define NGM_H4_COOKIE		1013899512

/* Node states */
#define NG_H4_W4_PKT_IND	1	/* Waiting for packet indicator */
#define NG_H4_W4_PKT_HDR	2	/* Waiting for packet header */
#define NG_H4_W4_PKT_DATA	3	/* Waiting for packet data */

/* Debug levels */
#define NG_H4_ALERT_LEVEL	1
#define NG_H4_ERR_LEVEL		2
#define NG_H4_WARN_LEVEL	3
#define NG_H4_INFO_LEVEL	4

/**************************************************************************
 **************************************************************************
 **                    H4 node command/event parameters
 **************************************************************************
 **************************************************************************/

/* Reset node */
#define NGM_H4_NODE_RESET	1

/* Get node state (see states above) */
#define NGM_H4_NODE_GET_STATE	2
typedef u_int16_t	ng_h4_node_state_ep;

/* Get/Set node debug level (see levels above) */
#define NGM_H4_NODE_GET_DEBUG	3
#define NGM_H4_NODE_SET_DEBUG	4
typedef u_int16_t	ng_h4_node_debug_ep;

/* Get/Set max queue length for the node */
#define NGM_H4_NODE_GET_QLEN	5
#define NGM_H4_NODE_SET_QLEN	6
typedef int32_t		ng_h4_node_qlen_ep;

/* Get node statistic */
#define NGM_H4_NODE_GET_STAT	7
typedef struct {
	u_int32_t	pckts_recv; /* # of packets received */
	u_int32_t	bytes_recv; /* # of bytes received */
	u_int32_t	pckts_sent; /* # of packets sent */
	u_int32_t	bytes_sent; /* # of bytes sent */
	u_int32_t	oerrors;    /* # of output errors */
	u_int32_t	ierrors;    /* # of input errors */
} ng_h4_node_stat_ep;

/* Reset node statistic */
#define NGM_H4_NODE_RESET_STAT	8

#endif /* _NETGRAPH_H4_H_ */