1.\" ng_btsocket.4 2.\" 3.\" Copyright (c) 2001-2002 Maksim Yevmenkin <m_evmenkin@yahoo.com> 4.\" All rights reserved. 5.\" 6.\" Redistribution and use in source and binary forms, with or without 7.\" modification, are permitted provided that the following conditions 8.\" are met: 9.\" 1. Redistributions of source code must retain the above copyright 10.\" notice, this list of conditions and the following disclaimer. 11.\" 2. Redistributions in binary form must reproduce the above copyright 12.\" notice, this list of conditions and the following disclaimer in the 13.\" documentation and/or other materials provided with the distribution. 14.\" 15.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25.\" SUCH DAMAGE. 26.\" 27.\" $Id: ng_btsocket.4,v 1.4 2002/11/12 22:31:39 max Exp $ 28.\" $FreeBSD$ 29.Dd July 8, 2002 30.Dt NG_BTSOCKET 4 31.Os 32.Sh NAME 33.Nm btsocket 34.Nd Bluetooth sockets layer 35.Sh SYNOPSIS 36.In sys/types.h 37.In sys/socket.h 38.In bitstring.h 39.In netgraph.h 40.In ng_hci.h 41.In ng_l2cap.h 42.In ng_btsocket.h 43.Sh DESCRIPTION 44The 45.Nm 46module implements three Netgraph node types. Each type in its turn implements 47one protocol within 48.Dv PF_BLUETOOTH 49domain. 50.Pp 51.Sh BLUETOOTH_PROTO_HCI protocol 52.Ss SOCK_RAW HCI sockets 53Implemented by 54.Cm btsock_hci_raw 55Netgraph type. Raw HCI sockets allow sending of raw HCI command datagrams 56only to correspondents named in 57.Xr send 2 58calls. Raw HCI datagrams (HCI commands, events and data) are generally 59received with 60.Xr recvfrom 2 , 61which returns the next datagram with its return address. Also raw HCI 62sockets can be used to control HCI nodes. 63.Pp 64The Bluetooth raw HCI socket address is defined as follows: 65.Bd -literal -offset indent 66/* Bluetooth version of struct sockaddr for raw HCI sockets */ 67struct sockaddr_hci { 68 u_char hci_len; /* total length */ 69 u_char hci_family; /* address family */ 70 char hci_node[16]; /* HCI node name */ 71}; 72.Ed 73.Pp 74Raw HCI sockets support number of 75.Xr ioctl 2 76requests such as: 77.Bl -tag -width foo 78.It Dv SIOC_HCI_RAW_NODE_GET_STATE 79Returns current state for the HCI node. 80.It Dv SIOC_HCI_RAW_NODE_INIT 81Turn on 82.Dq inited 83bit for the HCI node. 84.It Dv SIOC_HCI_RAW_NODE_GET_DEBUG 85Returns current debug level for the HCI node. 86.It Dv SIOC_HCI_RAW_NODE_SET_DEBUG 87Sets current debug level for the HCI node. 88.It Dv SIOC_HCI_RAW_NODE_GET_BUFFER 89Returns current state of data buffers for the HCI node. 90.It Dv SIOC_HCI_RAW_NODE_GET_BDADDR 91Returns BD_ADDR for the HCI node. 92.It Dv SIOC_HCI_RAW_NODE_GET_FEATURES 93Returns the list of features supported by hardware for the HCI node. 94.It Dv SIOC_HCI_RAW_NODE_GET_STAT 95Returns various statistic counters for the HCI node. 96.It Dv SIOC_HCI_RAW_NODE_RESET_STAT 97Resets all statistic counters for the HCI node to zero. 98.It Dv SIOC_HCI_RAW_NODE_FLUSH_NEIGHBOR_CACHE 99Remove all neighbor cache entries for the HCI node. 100.It Dv SIOC_HCI_RAW_NODE_GET_NEIGHBOR_CACHE 101Returns content of the neighbor cache for the HCI node. 102.It Dv SIOC_HCI_RAW_NODE_GET_CON_LIST 103Returns list of active baseband connections (i.e. ACL and SCO links) for 104the HCI node. 105.It SIOC_HCI_RAW_NODE_GET_LINK_POLICY_MASK 106Returns current link policy settings mask for the HCI node. 107.It SIOC_HCI_RAW_NODE_SET_LINK_POLICY_MASK 108Sets current link policy settings mask for the HCI node. 109.It SIOC_HCI_RAW_NODE_GET_PACKET_MASK 110Returns current packet mask for the HCI node. 111.It SIOC_HCI_RAW_NODE_SET_PACKET_MASK 112Sets current packet mask for the HCI node. 113.El 114.Pp 115Raw HCI sockets support filters. The application can filter certain 116HCI datagram types. For HCI event datagrams the application can set 117additional filter. The raw HCI socket filter defined as follows: 118.Bd -literal -offset indent 119/* 120 * Raw HCI socket filter. 121 * 122 * For packet mask use (1 << (HCI packet indicator - 1)) 123 * For event mask use (1 << (Event - 1)) 124 */ 125 126struct ng_btsocket_hci_raw_filter { 127 bitstr_t bit_decl(packet_mask, 32); 128 bitstr_t bit_decl(event_mask, (NG_HCI_EVENT_MASK_SIZE * 8)); 129}; 130.Ed 131.Pp 132The 133.Dv SO_HCI_RAW_FILTER 134option defined at 135.Dv SOL_HCI_RAW 136level can be used to obtain via 137.Xr getsockopt 2 138or change via 139.Xr setsockopt 2 140raw HCI socket's filter. 141.Pp 142.Sh BLUETOOTH_PROTO_L2CAP protocol 143The Bluetooth L2CAP socket address is defined as follows: 144.Bd -literal -offset indent 145/* Bluetooth version of struct sockaddr for L2CAP sockets */ 146struct sockaddr_l2cap { 147 u_char l2cap_len; /* total length */ 148 u_char l2cap_family; /* address family */ 149 u_int16_t l2cap_psm; /* Protocol/Service Multiplexor */ 150 bdaddr_t l2cap_bdaddr; /* address */ 151}; 152.Ed 153.Pp 154.Ss SOCK_RAW L2CAP sockets 155Implemented by 156.Cm btsock_l2c_raw 157Netgraph type. 158Raw L2CAP sockets do not provide access to raw L2CAP datagrams. These 159sockets used to control L2CAP nodes and to issue special L2CAP requests 160such as ECHO_REQUEST and GET_INFO request. 161.Pp 162Raw L2CAP sockets support number of 163.Xr ioctl 2 164requests such as: 165.Bl -tag -width foo 166.It Dv SIOC_L2CAP_NODE_GET_FLAGS 167Returns current state for the L2CAP node. 168.It Dv SIOC_L2CAP_NODE_GET_DEBUG 169Returns current debug level for the L2CAP node. 170.It Dv SIOC_L2CAP_NODE_SET_DEBUG 171Sets current debug level for the L2CAP node. 172.It Dv SIOC_L2CAP_NODE_GET_CON_LIST 173Returns list of active baseband connections (i.e. ACL links) for the L2CAP 174node. 175.It Dv SIOC_L2CAP_NODE_GET_CHAN_LIST 176Returns list of active channels for the L2CAP node. 177.It Dv SIOC_L2CAP_L2CA_PING 178Issues L2CAP ECHO_REQUEST. 179.It Dv SIOC_L2CAP_L2CA_GET_INFO 180Issues L2CAP GET_INFO request. 181.El 182.Pp 183.Ss SOCK_SEQPACKET L2CAP sockets 184Implemented by 185.Cm btsock_l2c 186Netgraph type. 187L2CAP sockets are either 188.Dq active 189or 190.Dq passive . 191Active sockets initiate connections to passive sockets. By default L2CAP 192sockets are created active; to create a passive socket the 193.Xr listen 2 194system call must be used after binding the socket with the 195.Xr bind 2 196system call. Only passive sockets may use the 197.Xr accept 2 198call to accept incoming connections. Only active sockets may use the 199.Xr connect 2 200call to initiate connections. 201.Pp 202L2CAP sockets supports 203.Dq wildcard addressing . 204In this case socket must be bound to 205.Dv NG_HCI_BDADDR_ANY 206address. Note that PSM (Protocol/Service Multiplexor) filed is always 207required. Once a connection has been established the socket's address is 208fixed by the peer entity's location. The address assigned the socket is 209the address associated with the Bluetooth device through which packets are 210being transmitted and received, and PSM (Protocol/Service Multiplexor). 211.Pp 212L2CAP sockets support number of options defined at 213.Dv SOL_L2CAP 214level which can be set with 215.Xr setsockopt 2 216and tested with 217.Xr getsockopt 2 : 218.Bl -tag -width foo 219.It Dv SO_L2CAP_IMTU 220Get (set) maximum payload size the local socket is capable of accepting. 221.It Dv SO_L2CAP_OMTU 222Get maximum payload size the remote socket is capable of accepting. 223.It Dv SO_L2CAP_IFLOW 224Get incoming flow specification for the socket. 225.Em Not implemented . 226.It Dv SO_L2CAP_OFLOW 227Get (set) outgoing flow specification for the socket. 228.Em Not implemented . 229.It Dv SO_L2CAP_FLUSH 230Get (set) value of the flush timeout. 231.Em Not implemeted . 232.El 233.Sh HOOKS 234This node type supports hooks with arbitrary names (as long as they are 235unique) and always accepts hook connection requests. 236.Sh NETGRAPH CONTROL MESSAGES 237This node type supports the generic control messages. 238.Sh SHUTDOWN 239These nodes are persistent and cannot be shut down. 240.Sh BUGS 241Most likely. Please report if found. 242.Sh SEE ALSO 243.Xr socket 2 , 244.Xr netgraph 4 , 245.Xr ngctl 8 , 246.Xr ng_hci 4 , 247.Xr ng_l2cap 4 , 248.Xr btsockstat 1 249.Sh HISTORY 250The 251.Nm 252node type was implemented in 253.Fx 5.0 . 254.Sh AUTHORS 255.An Maksim Yevmenkin Aq m_evmenkin@yahoo.com 256