117680Spst/*
217680Spst * ng_btsocket.h
317680Spst */
417680Spst
517680Spst/*-
617680Spst * Copyright (c) 2001-2002 Maksim Yevmenkin <m_evmenkin@yahoo.com>
717680Spst * All rights reserved.
817680Spst *
917680Spst * Redistribution and use in source and binary forms, with or without
1017680Spst * modification, are permitted provided that the following conditions
1117680Spst * are met:
1217680Spst * 1. Redistributions of source code must retain the above copyright
1317680Spst *    notice, this list of conditions and the following disclaimer.
1417680Spst * 2. Redistributions in binary form must reproduce the above copyright
1517680Spst *    notice, this list of conditions and the following disclaimer in the
1617680Spst *    documentation and/or other materials provided with the distribution.
1717680Spst *
1817680Spst * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1917680Spst * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2017680Spst * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2117680Spst * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2217680Spst * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2317680Spst * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2417680Spst * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2517680Spst * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2617680Spst * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2717680Spst * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2817680Spst * SUCH DAMAGE.
2917680Spst *
3017680Spst * $Id: ng_btsocket.h,v 1.8 2003/04/26 22:32:10 max Exp $
3117680Spst * $FreeBSD: releng/11.0/sys/netgraph/bluetooth/include/ng_btsocket.h 290038 2015-10-27 03:42:26Z takawata $
3217680Spst */
3317680Spst
3417680Spst#ifndef _NETGRAPH_BTSOCKET_H_
3517680Spst#define _NETGRAPH_BTSOCKET_H_
3617680Spst
3717680Spst/*
3821262Swollman * Bluetooth protocols
3917680Spst */
4017680Spst
4117680Spst#define BLUETOOTH_PROTO_HCI	134	/* HCI protocol number */
4217680Spst#define BLUETOOTH_PROTO_L2CAP	135	/* L2CAP protocol number */
4317680Spst#define BLUETOOTH_PROTO_RFCOMM	136	/* RFCOMM protocol number */
4417680Spst#define BLUETOOTH_PROTO_SCO	137	/* SCO protocol number */
4517680Spst
4617680Spst/*
4717680Spst * Bluetooth version of struct sockaddr for raw HCI sockets
4817680Spst */
4917680Spst
5017680Spststruct sockaddr_hci {
5117680Spst	u_char		hci_len;	/* total length */
5217680Spst	u_char		hci_family;	/* address family */
5317680Spst	char		hci_node[32];	/* address (size == NG_NODESIZ ) */
5417680Spst};
5517680Spst
5617680Spst/* Raw HCI socket options */
5717680Spst#define SOL_HCI_RAW		0x0802	/* socket options level */
5817680Spst
5917680Spst#define SO_HCI_RAW_FILTER	1	/* get/set filter on socket */
6017680Spst#define SO_HCI_RAW_DIRECTION	2	/* turn on/off direction info */
6117680Spst#define SCM_HCI_RAW_DIRECTION	SO_HCI_RAW_DIRECTION /* cmsg_type  */
6217680Spst
6317680Spst/*
6417680Spst * Raw HCI socket filter.
6517680Spst *
6617680Spst * For packet mask use (1 << (HCI packet indicator - 1))
6717680Spst * For event mask use (1 << (Event - 1))
6817680Spst */
6917680Spst
7017680Spststruct ng_btsocket_hci_raw_filter {
7117680Spst	bitstr_t	bit_decl(packet_mask, 32);
7217680Spst	bitstr_t	bit_decl(event_mask, (NG_HCI_EVENT_MASK_SIZE * 8));
7317680Spst};
7417680Spst
7517680Spst/*
7617680Spst * Raw HCI sockets ioctl's
7717680Spst */
7817680Spst
7917680Spst/* Get state */
8017680Spststruct ng_btsocket_hci_raw_node_state {
8117680Spst	ng_hci_node_state_ep	state;
8217680Spst};
8317680Spst#define SIOC_HCI_RAW_NODE_GET_STATE \
8417680Spst	_IOWR('b', NGM_HCI_NODE_GET_STATE, \
8517680Spst		struct ng_btsocket_hci_raw_node_state)
8617680Spst
8717680Spst/* Initialize */
8817680Spst#define SIOC_HCI_RAW_NODE_INIT \
8917680Spst	_IO('b', NGM_HCI_NODE_INIT)
9017680Spst
9117680Spst/* Get/Set debug level */
9217680Spststruct ng_btsocket_hci_raw_node_debug {
9317680Spst	ng_hci_node_debug_ep	debug;
9417680Spst};
9517680Spst#define SIOC_HCI_RAW_NODE_GET_DEBUG \
9617680Spst	_IOWR('b', NGM_HCI_NODE_GET_DEBUG, \
9717680Spst		struct ng_btsocket_hci_raw_node_debug)
9817680Spst#define SIOC_HCI_RAW_NODE_SET_DEBUG \
9917680Spst	_IOWR('b', NGM_HCI_NODE_SET_DEBUG, \
10017680Spst		struct ng_btsocket_hci_raw_node_debug)
10117680Spst
10217680Spst/* Get buffer info */
10317680Spststruct ng_btsocket_hci_raw_node_buffer {
10417680Spst	ng_hci_node_buffer_ep	buffer;
10517680Spst};
10617680Spst#define SIOC_HCI_RAW_NODE_GET_BUFFER \
10717680Spst	_IOWR('b', NGM_HCI_NODE_GET_BUFFER, \
10817680Spst		struct ng_btsocket_hci_raw_node_buffer)
10917680Spst
11017680Spst/* Get BD_ADDR */
11117680Spststruct ng_btsocket_hci_raw_node_bdaddr {
11217680Spst	bdaddr_t	bdaddr;
11317680Spst};
11417680Spst#define SIOC_HCI_RAW_NODE_GET_BDADDR \
11517680Spst	_IOWR('b', NGM_HCI_NODE_GET_BDADDR, \
11617680Spst		struct ng_btsocket_hci_raw_node_bdaddr)
11717680Spst
11817680Spst/* Get features */
11917680Spststruct ng_btsocket_hci_raw_node_features {
12017680Spst	u_int8_t	features[NG_HCI_FEATURES_SIZE];
12117680Spst};
12217680Spst#define SIOC_HCI_RAW_NODE_GET_FEATURES \
12317680Spst	_IOWR('b', NGM_HCI_NODE_GET_FEATURES, \
12417680Spst		struct ng_btsocket_hci_raw_node_features)
12517680Spst
12617680Spst/* Get stat */
12717680Spststruct ng_btsocket_hci_raw_node_stat {
12817680Spst	ng_hci_node_stat_ep	stat;
12917680Spst};
13017680Spst#define SIOC_HCI_RAW_NODE_GET_STAT \
13117680Spst	_IOWR('b', NGM_HCI_NODE_GET_STAT, \
13217680Spst		struct ng_btsocket_hci_raw_node_stat)
13317680Spst
13417680Spst/* Reset stat */
13517680Spst#define SIOC_HCI_RAW_NODE_RESET_STAT \
13617680Spst	_IO('b', NGM_HCI_NODE_RESET_STAT)
13717680Spst
13817680Spst/* Flush neighbor cache */
13917680Spst#define SIOC_HCI_RAW_NODE_FLUSH_NEIGHBOR_CACHE \
14017680Spst	_IO('b', NGM_HCI_NODE_FLUSH_NEIGHBOR_CACHE)
14117680Spst
14217680Spst/* Get neighbor cache */
14317680Spststruct ng_btsocket_hci_raw_node_neighbor_cache {
14417680Spst	u_int32_t				 num_entries;
14517680Spst	ng_hci_node_neighbor_cache_entry_ep	*entries;
14617680Spst};
14717680Spst#define SIOC_HCI_RAW_NODE_GET_NEIGHBOR_CACHE \
14817680Spst	_IOWR('b', NGM_HCI_NODE_GET_NEIGHBOR_CACHE, \
14917680Spst		struct ng_btsocket_hci_raw_node_neighbor_cache)
15017680Spst
15117680Spst/* Get connection list */
15217680Spststruct ng_btsocket_hci_raw_con_list {
15317680Spst	u_int32_t		 num_connections;
15417680Spst	ng_hci_node_con_ep	*connections;
15517680Spst};
15617680Spst#define SIOC_HCI_RAW_NODE_GET_CON_LIST \
15717680Spst	_IOWR('b', NGM_HCI_NODE_GET_CON_LIST, \
15817680Spst		struct ng_btsocket_hci_raw_con_list)
15917680Spst
16017680Spst/* Get/Set link policy settings mask */
16117680Spststruct ng_btsocket_hci_raw_node_link_policy_mask {
16217680Spst	ng_hci_node_link_policy_mask_ep	policy_mask;
16317680Spst};
16417680Spst#define SIOC_HCI_RAW_NODE_GET_LINK_POLICY_MASK \
16517680Spst	_IOWR('b', NGM_HCI_NODE_GET_LINK_POLICY_SETTINGS_MASK, \
16617680Spst		struct ng_btsocket_hci_raw_node_link_policy_mask)
16717680Spst#define SIOC_HCI_RAW_NODE_SET_LINK_POLICY_MASK \
16817680Spst	_IOWR('b', NGM_HCI_NODE_SET_LINK_POLICY_SETTINGS_MASK, \
16917680Spst		struct ng_btsocket_hci_raw_node_link_policy_mask)
17017680Spst
17117680Spst/* Get/Set packet mask */
17217680Spststruct ng_btsocket_hci_raw_node_packet_mask {
17317680Spst	ng_hci_node_packet_mask_ep	packet_mask;
17417680Spst};
17517680Spst#define SIOC_HCI_RAW_NODE_GET_PACKET_MASK \
17617680Spst	_IOWR('b', NGM_HCI_NODE_GET_PACKET_MASK, \
17717680Spst		struct ng_btsocket_hci_raw_node_packet_mask)
17817680Spst#define SIOC_HCI_RAW_NODE_SET_PACKET_MASK \
17917680Spst	_IOWR('b', NGM_HCI_NODE_SET_PACKET_MASK, \
18017680Spst		struct ng_btsocket_hci_raw_node_packet_mask)
18117680Spst
18217680Spst/* Get/Set role switch */
18317680Spststruct ng_btsocket_hci_raw_node_role_switch {
18417680Spst	ng_hci_node_role_switch_ep	role_switch;
18517680Spst};
18617680Spst#define SIOC_HCI_RAW_NODE_GET_ROLE_SWITCH \
18717680Spst	_IOWR('b', NGM_HCI_NODE_GET_ROLE_SWITCH, \
18817680Spst		struct ng_btsocket_hci_raw_node_role_switch)
18917680Spst#define SIOC_HCI_RAW_NODE_SET_ROLE_SWITCH \
19017680Spst	_IOWR('b', NGM_HCI_NODE_SET_ROLE_SWITCH, \
19117680Spst		struct ng_btsocket_hci_raw_node_role_switch)
19217680Spst
19317680Spst/* Get list of HCI node names */
19417680Spststruct ng_btsocket_hci_raw_node_list_names {
19517680Spst	u_int32_t	 num_names;
19617680Spst	struct nodeinfo	*names;
19717680Spst};
19817680Spst#define SIOC_HCI_RAW_NODE_LIST_NAMES \
19917680Spst	_IOWR('b', NGM_HCI_NODE_LIST_NAMES, \
20017680Spst		struct ng_btsocket_hci_raw_node_list_names)
20117680Spst
20217680Spst/*
20317680Spst * XXX FIXME: probably does not belong here
20417680Spst * Bluetooth version of struct sockaddr for SCO sockets (SEQPACKET)
20517680Spst */
20617680Spst
20717680Spststruct sockaddr_sco {
20817680Spst	u_char		sco_len;	/* total length */
20917680Spst	u_char		sco_family;	/* address family */
21017680Spst	bdaddr_t	sco_bdaddr;	/* address */
21117680Spst};
21217680Spst
21317680Spst/* SCO socket options */
21417680Spst#define SOL_SCO		0x0209		/* socket options level */
21517680Spst
21617680Spst#define SO_SCO_MTU	1		/* get sockets mtu */
21717680Spst#define SO_SCO_CONNINFO	2		/* get HCI connection handle */
21817680Spst
21917680Spst/*
22017680Spst * XXX FIXME: probably does not belong here
22117680Spst * Bluetooth version of struct sockaddr for L2CAP sockets (RAW and SEQPACKET)
22217680Spst */
22317680Spst
22417680Spststruct sockaddr_l2cap_compat {
22517680Spst	u_char		l2cap_len;	/* total length */
22617680Spst	u_char		l2cap_family;	/* address family */
22717680Spst	u_int16_t	l2cap_psm;	/* PSM (Protocol/Service Multiplexor) */
22817680Spst	bdaddr_t	l2cap_bdaddr;	/* address */
22917680Spst};
23017680Spst
23117680Spst#define BDADDR_BREDR 0
23217680Spst#define BDADDR_LE_PUBLIC 1
23317680Spst#define BDADDR_LE_RANDOM 2
23417680Spst
23517680Spststruct sockaddr_l2cap {
23617680Spst	u_char		l2cap_len;	/* total length */
23717680Spst	u_char		l2cap_family;	/* address family */
23817680Spst	u_int16_t	l2cap_psm;	/* PSM (Protocol/Service Multiplexor) */
23917680Spst	bdaddr_t	l2cap_bdaddr;	/* address */
24017680Spst	u_int16_t	l2cap_cid;      /*cid*/
24117680Spst	u_int8_t	l2cap_bdaddr_type; /*address type*/
24217680Spst};
24317680Spst
24417680Spst
24517680Spst#if !defined(L2CAP_SOCKET_CHECKED) && !defined(_KERNEL)
24617680Spst#warning "Make sure new member of socket address initialized"
24717680Spst#endif
24817680Spst
24917680Spst
25017680Spst/* L2CAP socket options */
25117680Spst#define SOL_L2CAP		0x1609	/* socket option level */
25217680Spst
25317680Spst#define SO_L2CAP_IMTU		1	/* get/set incoming MTU */
25417680Spst#define SO_L2CAP_OMTU		2	/* get outgoing (peer incoming) MTU */
25517680Spst#define SO_L2CAP_IFLOW		3	/* get incoming flow spec. */
25617680Spst#define SO_L2CAP_OFLOW		4	/* get/set outgoing flow spec. */
25717680Spst#define SO_L2CAP_FLUSH		5	/* get/set flush timeout */
25817680Spst#define SO_L2CAP_ENCRYPTED      6      /* get/set whether wait for encryptin on connect */
25917680Spst/*
26017680Spst * Raw L2CAP sockets ioctl's
26117680Spst */
26217680Spst
26317680Spst/* Ping */
26417680Spststruct ng_btsocket_l2cap_raw_ping {
26517680Spst	u_int32_t		 result;
26617680Spst	u_int32_t		 echo_size;
26717680Spst	u_int8_t		*echo_data;
26817680Spst};
26917680Spst#define SIOC_L2CAP_L2CA_PING \
27017680Spst	_IOWR('b', NGM_L2CAP_L2CA_PING, \
27117680Spst		struct ng_btsocket_l2cap_raw_ping)
27217680Spst
27317680Spst/* Get info */
27417680Spststruct ng_btsocket_l2cap_raw_get_info {
27517680Spst	u_int32_t		 result;
27617680Spst	u_int32_t		 info_type;
27717680Spst	u_int32_t		 info_size;
27817680Spst	u_int8_t		*info_data;
27917680Spst};
28017680Spst#define SIOC_L2CAP_L2CA_GET_INFO \
28117680Spst	_IOWR('b', NGM_L2CAP_L2CA_GET_INFO, \
28217680Spst		struct ng_btsocket_l2cap_raw_get_info)
28317680Spst
28417680Spst/* Get flags */
28517680Spststruct ng_btsocket_l2cap_raw_node_flags {
28617680Spst	ng_l2cap_node_flags_ep	flags;
28717680Spst};
28817680Spst#define SIOC_L2CAP_NODE_GET_FLAGS \
28917680Spst	_IOWR('b', NGM_L2CAP_NODE_GET_FLAGS, \
29017680Spst		struct ng_btsocket_l2cap_raw_node_flags)
29117680Spst
29217680Spst/* Get/Set debug level */
29317680Spststruct ng_btsocket_l2cap_raw_node_debug {
29417680Spst	ng_l2cap_node_debug_ep	debug;
29517680Spst};
29617680Spst#define SIOC_L2CAP_NODE_GET_DEBUG \
29717680Spst	_IOWR('b', NGM_L2CAP_NODE_GET_DEBUG, \
29817680Spst		struct ng_btsocket_l2cap_raw_node_debug)
29917680Spst#define SIOC_L2CAP_NODE_SET_DEBUG \
30017680Spst	_IOWR('b', NGM_L2CAP_NODE_SET_DEBUG, \
30117680Spst		struct ng_btsocket_l2cap_raw_node_debug)
30217680Spst
30317680Spst/* Get connection list */
30417680Spststruct ng_btsocket_l2cap_raw_con_list {
30517680Spst	u_int32_t		 num_connections;
30617680Spst	ng_l2cap_node_con_ep	*connections;
30717680Spst};
30817680Spst#define SIOC_L2CAP_NODE_GET_CON_LIST \
30917680Spst	_IOWR('b', NGM_L2CAP_NODE_GET_CON_LIST, \
31017680Spst		struct ng_btsocket_l2cap_raw_con_list)
31117680Spst
31217680Spst/* Get channel list */
31317680Spststruct ng_btsocket_l2cap_raw_chan_list {
31417680Spst	u_int32_t		 num_channels;
31517680Spst	ng_l2cap_node_chan_ep	*channels;
31617680Spst};
31717680Spst#define SIOC_L2CAP_NODE_GET_CHAN_LIST \
31817680Spst	_IOWR('b', NGM_L2CAP_NODE_GET_CHAN_LIST, \
31917680Spst		struct ng_btsocket_l2cap_raw_chan_list)
32017680Spst
32117680Spst/* Get/Set auto disconnect timeout */
32217680Spststruct ng_btsocket_l2cap_raw_auto_discon_timo
32317680Spst{
32417680Spst	ng_l2cap_node_auto_discon_ep	timeout;
32517680Spst};
32617680Spst#define SIOC_L2CAP_NODE_GET_AUTO_DISCON_TIMO \
32717680Spst	_IOWR('b', NGM_L2CAP_NODE_GET_AUTO_DISCON_TIMO, \
32817680Spst		struct ng_btsocket_l2cap_raw_auto_discon_timo)
32917680Spst#define SIOC_L2CAP_NODE_SET_AUTO_DISCON_TIMO \
33017680Spst	_IOWR('b', NGM_L2CAP_NODE_SET_AUTO_DISCON_TIMO, \
33117680Spst		struct ng_btsocket_l2cap_raw_auto_discon_timo)
33217680Spst
33317680Spst/*
33417680Spst * XXX FIXME: probably does not belong here
33517680Spst * Bluetooth version of struct sockaddr for RFCOMM sockets (STREAM)
33617680Spst */
33717680Spst
33817680Spststruct sockaddr_rfcomm {
33917680Spst	u_char		rfcomm_len;	/* total length */
34017680Spst	u_char		rfcomm_family;	/* address family */
34117680Spst	bdaddr_t	rfcomm_bdaddr;	/* address */
34217680Spst	u_int8_t	rfcomm_channel;	/* channel */
34317680Spst};
34417680Spst
34517680Spst/* Flow control information */
34617680Spststruct ng_btsocket_rfcomm_fc_info {
34717680Spst	u_int8_t	lmodem;		/* modem signals (local) */
34817680Spst	u_int8_t	rmodem;		/* modem signals (remote) */
34917680Spst	u_int8_t	tx_cred;	/* TX credits */
35017680Spst	u_int8_t	rx_cred;	/* RX credits */
35117680Spst	u_int8_t	cfc;		/* credit flow control */
35217680Spst	u_int8_t	reserved;
35317680Spst};
35417680Spst
35517680Spst/* STREAM RFCOMM socket options */
35617680Spst#define SOL_RFCOMM		0x0816	/* socket options level */
35717680Spst
35817680Spst#define SO_RFCOMM_MTU		1	/* get channel MTU */
35917680Spst#define SO_RFCOMM_FC_INFO	2	/* get flow control information */
36017680Spst
36117680Spst/*
36217680Spst * Netgraph node type name and cookie
36317680Spst */
36417680Spst
36517680Spst#define	NG_BTSOCKET_HCI_RAW_NODE_TYPE	"btsock_hci_raw"
36617680Spst#define	NG_BTSOCKET_L2CAP_RAW_NODE_TYPE	"btsock_l2c_raw"
36717680Spst#define	NG_BTSOCKET_L2CAP_NODE_TYPE	"btsock_l2c"
36817680Spst#define	NG_BTSOCKET_SCO_NODE_TYPE	"btsock_sco"
36917680Spst
37017680Spst/*
37117680Spst * Debug levels
37217680Spst */
37317680Spst
37417680Spst#define NG_BTSOCKET_ALERT_LEVEL	1
37517680Spst#define NG_BTSOCKET_ERR_LEVEL	2
37617680Spst#define NG_BTSOCKET_WARN_LEVEL	3
37717680Spst#define NG_BTSOCKET_INFO_LEVEL	4
37817680Spst
37917680Spst#endif /* _NETGRAPH_BTSOCKET_H_ */
38017680Spst
38117680Spst