Home | History | Annotate | Line # | Download | only in netbt
rfcomm.h revision 1.1.4.2
      1  1.1.4.2  chap /*	$NetBSD: rfcomm.h,v 1.1.4.2 2006/06/22 03:39:50 chap Exp $	*/
      2  1.1.4.2  chap 
      3  1.1.4.2  chap /*-
      4  1.1.4.2  chap  * Copyright (c) 2006 Itronix Inc.
      5  1.1.4.2  chap  * All rights reserved.
      6  1.1.4.2  chap  *
      7  1.1.4.2  chap  * Written by Iain Hibbert for Itronix Inc.
      8  1.1.4.2  chap  *
      9  1.1.4.2  chap  * Redistribution and use in source and binary forms, with or without
     10  1.1.4.2  chap  * modification, are permitted provided that the following conditions
     11  1.1.4.2  chap  * are met:
     12  1.1.4.2  chap  * 1. Redistributions of source code must retain the above copyright
     13  1.1.4.2  chap  *    notice, this list of conditions and the following disclaimer.
     14  1.1.4.2  chap  * 2. Redistributions in binary form must reproduce the above copyright
     15  1.1.4.2  chap  *    notice, this list of conditions and the following disclaimer in the
     16  1.1.4.2  chap  *    documentation and/or other materials provided with the distribution.
     17  1.1.4.2  chap  * 3. The name of Itronix Inc. may not be used to endorse
     18  1.1.4.2  chap  *    or promote products derived from this software without specific
     19  1.1.4.2  chap  *    prior written permission.
     20  1.1.4.2  chap  *
     21  1.1.4.2  chap  * THIS SOFTWARE IS PROVIDED BY ITRONIX INC. ``AS IS'' AND
     22  1.1.4.2  chap  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     23  1.1.4.2  chap  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     24  1.1.4.2  chap  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL ITRONIX INC. BE LIABLE FOR ANY
     25  1.1.4.2  chap  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     26  1.1.4.2  chap  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     27  1.1.4.2  chap  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
     28  1.1.4.2  chap  * ON ANY THEORY OF LIABILITY, WHETHER IN
     29  1.1.4.2  chap  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     30  1.1.4.2  chap  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     31  1.1.4.2  chap  * POSSIBILITY OF SUCH DAMAGE.
     32  1.1.4.2  chap  */
     33  1.1.4.2  chap /*-
     34  1.1.4.2  chap  * Copyright (c) 2001-2003 Maksim Yevmenkin <m_evmenkin (at) yahoo.com>
     35  1.1.4.2  chap  * All rights reserved.
     36  1.1.4.2  chap  *
     37  1.1.4.2  chap  * Redistribution and use in source and binary forms, with or without
     38  1.1.4.2  chap  * modification, are permitted provided that the following conditions
     39  1.1.4.2  chap  * are met:
     40  1.1.4.2  chap  * 1. Redistributions of source code must retain the above copyright
     41  1.1.4.2  chap  *    notice, this list of conditions and the following disclaimer.
     42  1.1.4.2  chap  * 2. Redistributions in binary form must reproduce the above copyright
     43  1.1.4.2  chap  *    notice, this list of conditions and the following disclaimer in the
     44  1.1.4.2  chap  *    documentation and/or other materials provided with the distribution.
     45  1.1.4.2  chap  *
     46  1.1.4.2  chap  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     47  1.1.4.2  chap  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     48  1.1.4.2  chap  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     49  1.1.4.2  chap  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     50  1.1.4.2  chap  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     51  1.1.4.2  chap  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     52  1.1.4.2  chap  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     53  1.1.4.2  chap  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     54  1.1.4.2  chap  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     55  1.1.4.2  chap  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     56  1.1.4.2  chap  * SUCH DAMAGE.
     57  1.1.4.2  chap  *
     58  1.1.4.2  chap  * $Id: rfcomm.h,v 1.1.4.2 2006/06/22 03:39:50 chap Exp $
     59  1.1.4.2  chap  * $FreeBSD: src/sys/netgraph/bluetooth/include/ng_btsocket_rfcomm.h,v 1.4 2005/01/11 01:39:53 emax Exp $
     60  1.1.4.2  chap  */
     61  1.1.4.2  chap 
     62  1.1.4.2  chap #ifndef _NETBT_RFCOMM_H_
     63  1.1.4.2  chap #define _NETBT_RFCOMM_H_
     64  1.1.4.2  chap 
     65  1.1.4.2  chap /*************************************************************************
     66  1.1.4.2  chap  *************************************************************************
     67  1.1.4.2  chap  **				RFCOMM					**
     68  1.1.4.2  chap  *************************************************************************
     69  1.1.4.2  chap  *************************************************************************/
     70  1.1.4.2  chap 
     71  1.1.4.2  chap #define RFCOMM_MTU_MAX			32767
     72  1.1.4.2  chap #define RFCOMM_MTU_MIN			23
     73  1.1.4.2  chap #define RFCOMM_MTU_DEFAULT		127
     74  1.1.4.2  chap 
     75  1.1.4.2  chap #define RFCOMM_CREDITS_MAX		255	/* in any single packet */
     76  1.1.4.2  chap #define RFCOMM_CREDITS_DEFAULT		7	/* default initial value */
     77  1.1.4.2  chap 
     78  1.1.4.2  chap #define RFCOMM_CHANNEL_MIN		1
     79  1.1.4.2  chap #define RFCOMM_CHANNEL_MAX		30
     80  1.1.4.2  chap 
     81  1.1.4.2  chap /* RFCOMM frame types */
     82  1.1.4.2  chap #define RFCOMM_FRAME_SABM		0x2f
     83  1.1.4.2  chap #define RFCOMM_FRAME_DISC		0x43
     84  1.1.4.2  chap #define RFCOMM_FRAME_UA			0x63
     85  1.1.4.2  chap #define RFCOMM_FRAME_DM			0x0f
     86  1.1.4.2  chap #define RFCOMM_FRAME_UIH		0xef
     87  1.1.4.2  chap 
     88  1.1.4.2  chap /* RFCOMM MCC commands */
     89  1.1.4.2  chap #define RFCOMM_MCC_TEST			0x08	/* Test */
     90  1.1.4.2  chap #define RFCOMM_MCC_FCON			0x28	/* Flow Control on */
     91  1.1.4.2  chap #define RFCOMM_MCC_FCOFF		0x18	/* Flow Control off */
     92  1.1.4.2  chap #define RFCOMM_MCC_MSC			0x38	/* Modem Status Command */
     93  1.1.4.2  chap #define RFCOMM_MCC_RPN			0x24	/* Remote Port Negotiation */
     94  1.1.4.2  chap #define RFCOMM_MCC_RLS			0x14	/* Remote Line Status */
     95  1.1.4.2  chap #define RFCOMM_MCC_PN			0x20	/* Port Negotiation */
     96  1.1.4.2  chap #define RFCOMM_MCC_NSC			0x04	/* Non Supported Command */
     97  1.1.4.2  chap 
     98  1.1.4.2  chap /* RFCOMM modem signals */
     99  1.1.4.2  chap #define RFCOMM_MSC_FC			0x02	/* Flow Control asserted */
    100  1.1.4.2  chap #define RFCOMM_MSC_RTC			0x04	/* Ready To Communicate */
    101  1.1.4.2  chap #define RFCOMM_MSC_RTR			0x08	/* Ready To Receive */
    102  1.1.4.2  chap #define RFCOMM_MSC_IC			0x40	/* Incomming Call (RING) */
    103  1.1.4.2  chap #define RFCOMM_MSC_DV			0x80	/* Data Valid */
    104  1.1.4.2  chap 
    105  1.1.4.2  chap /* RPN parameters - baud rate */
    106  1.1.4.2  chap #define RFCOMM_RPN_BR_2400		0x0
    107  1.1.4.2  chap #define RFCOMM_RPN_BR_4800		0x1
    108  1.1.4.2  chap #define RFCOMM_RPN_BR_7200		0x2
    109  1.1.4.2  chap #define RFCOMM_RPN_BR_9600		0x3
    110  1.1.4.2  chap #define RFCOMM_RPN_BR_19200		0x4
    111  1.1.4.2  chap #define RFCOMM_RPN_BR_38400		0x5
    112  1.1.4.2  chap #define RFCOMM_RPN_BR_57600		0x6
    113  1.1.4.2  chap #define RFCOMM_RPN_BR_115200		0x7
    114  1.1.4.2  chap #define RFCOMM_RPN_BR_230400		0x8
    115  1.1.4.2  chap 
    116  1.1.4.2  chap /* RPN parameters - data bits */
    117  1.1.4.2  chap #define RFCOMM_RPN_DATA_5		0x0
    118  1.1.4.2  chap #define RFCOMM_RPN_DATA_6		0x1
    119  1.1.4.2  chap #define RFCOMM_RPN_DATA_7		0x2
    120  1.1.4.2  chap #define RFCOMM_RPN_DATA_8		0x3
    121  1.1.4.2  chap 
    122  1.1.4.2  chap /* RPN parameters - stop bit */
    123  1.1.4.2  chap #define RFCOMM_RPN_STOP_1		0
    124  1.1.4.2  chap #define RFCOMM_RPN_STOP_15		1
    125  1.1.4.2  chap 
    126  1.1.4.2  chap /* RPN parameters - parity enable */
    127  1.1.4.2  chap #define RFCOMM_RPN_PARITY_NONE		0x0
    128  1.1.4.2  chap 
    129  1.1.4.2  chap /* RPN parameters - parity type */
    130  1.1.4.2  chap #define RFCOMM_RPN_PARITY_ODD		0x0
    131  1.1.4.2  chap #define RFCOMM_RPN_PARITY_EVEN		0x1
    132  1.1.4.2  chap #define RFCOMM_RPN_PARITY_MARK		0x2
    133  1.1.4.2  chap #define RFCOMM_RPN_PARITY_SPACE		0x3
    134  1.1.4.2  chap 
    135  1.1.4.2  chap /* RPN parameters - default line_setting */
    136  1.1.4.2  chap #define RFCOMM_RPN_8_N_1		0x03
    137  1.1.4.2  chap 
    138  1.1.4.2  chap /* RPN parameters - flow control */
    139  1.1.4.2  chap #define RFCOMM_RPN_XON_CHAR		0x11
    140  1.1.4.2  chap #define RFCOMM_RPN_XOFF_CHAR		0x13
    141  1.1.4.2  chap #define RFCOMM_RPN_FLOW_NONE		0x00
    142  1.1.4.2  chap 
    143  1.1.4.2  chap /* RPN parameters - mask */
    144  1.1.4.2  chap #define RFCOMM_RPN_PM_RATE		0x0001
    145  1.1.4.2  chap #define RFCOMM_RPN_PM_DATA		0x0002
    146  1.1.4.2  chap #define RFCOMM_RPN_PM_STOP		0x0004
    147  1.1.4.2  chap #define RFCOMM_RPN_PM_PARITY		0x0008
    148  1.1.4.2  chap #define RFCOMM_RPN_PM_PTYPE		0x0010
    149  1.1.4.2  chap #define RFCOMM_RPN_PM_XON		0x0020
    150  1.1.4.2  chap #define RFCOMM_RPN_PM_XOFF		0x0040
    151  1.1.4.2  chap 
    152  1.1.4.2  chap #define RFCOMM_RPN_PM_FLOW		0x3f00
    153  1.1.4.2  chap 
    154  1.1.4.2  chap #define RFCOMM_RPN_PM_ALL		0x3f7f
    155  1.1.4.2  chap 
    156  1.1.4.2  chap /* RFCOMM command frame header */
    157  1.1.4.2  chap struct rfcomm_cmd_hdr
    158  1.1.4.2  chap {
    159  1.1.4.2  chap 	uint8_t		address;
    160  1.1.4.2  chap 	uint8_t		control;
    161  1.1.4.2  chap 	uint8_t		length;
    162  1.1.4.2  chap 	uint8_t		fcs;
    163  1.1.4.2  chap } __attribute__ ((__packed__));
    164  1.1.4.2  chap 
    165  1.1.4.2  chap /* RFCOMM MSC command */
    166  1.1.4.2  chap struct rfcomm_mcc_msc
    167  1.1.4.2  chap {
    168  1.1.4.2  chap 	uint8_t		address;
    169  1.1.4.2  chap 	uint8_t		modem;
    170  1.1.4.2  chap 	uint8_t		brk;
    171  1.1.4.2  chap } __attribute__ ((__packed__));
    172  1.1.4.2  chap 
    173  1.1.4.2  chap /* RFCOMM RPN command */
    174  1.1.4.2  chap struct rfcomm_mcc_rpn
    175  1.1.4.2  chap {
    176  1.1.4.2  chap 	uint8_t		dlci;
    177  1.1.4.2  chap 	uint8_t		bit_rate;
    178  1.1.4.2  chap 	uint8_t		line_settings;
    179  1.1.4.2  chap 	uint8_t		flow_control;
    180  1.1.4.2  chap 	uint8_t		xon_char;
    181  1.1.4.2  chap 	uint8_t		xoff_char;
    182  1.1.4.2  chap 	uint16_t	param_mask;
    183  1.1.4.2  chap } __attribute__ ((__packed__));
    184  1.1.4.2  chap 
    185  1.1.4.2  chap /* RFCOMM RLS command */
    186  1.1.4.2  chap struct rfcomm_mcc_rls
    187  1.1.4.2  chap {
    188  1.1.4.2  chap 	uint8_t		address;
    189  1.1.4.2  chap 	uint8_t		status;
    190  1.1.4.2  chap } __attribute__ ((__packed__));
    191  1.1.4.2  chap 
    192  1.1.4.2  chap /* RFCOMM PN command */
    193  1.1.4.2  chap struct rfcomm_mcc_pn
    194  1.1.4.2  chap {
    195  1.1.4.2  chap 	uint8_t		dlci;
    196  1.1.4.2  chap 	uint8_t		flow_control;
    197  1.1.4.2  chap 	uint8_t		priority;
    198  1.1.4.2  chap 	uint8_t		ack_timer;
    199  1.1.4.2  chap 	uint16_t	mtu;
    200  1.1.4.2  chap 	uint8_t		max_retrans;
    201  1.1.4.2  chap 	uint8_t		credits;
    202  1.1.4.2  chap } __attribute__ ((__packed__));
    203  1.1.4.2  chap 
    204  1.1.4.2  chap /* RFCOMM frame parsing macros */
    205  1.1.4.2  chap #define RFCOMM_DLCI(b)			(((b) & 0xfc) >> 2)
    206  1.1.4.2  chap #define RFCOMM_TYPE(b)			(((b) & 0xef))
    207  1.1.4.2  chap 
    208  1.1.4.2  chap #define RFCOMM_EA(b)			(((b) & 0x01))
    209  1.1.4.2  chap #define RFCOMM_CR(b)			(((b) & 0x02) >> 1)
    210  1.1.4.2  chap #define RFCOMM_PF(b)			(((b) & 0x10) >> 4)
    211  1.1.4.2  chap 
    212  1.1.4.2  chap #define RFCOMM_CHANNEL(dlci)		(((dlci) >> 1) & 0x2f)
    213  1.1.4.2  chap #define RFCOMM_DIRECTION(dlci)		((dlci) & 0x1)
    214  1.1.4.2  chap 
    215  1.1.4.2  chap #define RFCOMM_MKADDRESS(cr, dlci) \
    216  1.1.4.2  chap 	((((dlci) & 0x3f) << 2) | ((cr) << 1) | 0x01)
    217  1.1.4.2  chap 
    218  1.1.4.2  chap #define RFCOMM_MKCONTROL(type, pf)	((((type) & 0xef) | ((pf) << 4)))
    219  1.1.4.2  chap #define RFCOMM_MKDLCI(dir, channel)	((((channel) & 0x1f) << 1) | (dir))
    220  1.1.4.2  chap 
    221  1.1.4.2  chap /* RFCOMM MCC macros */
    222  1.1.4.2  chap #define RFCOMM_MCC_TYPE(b)		(((b) & 0xfc) >> 2)
    223  1.1.4.2  chap #define RFCOMM_MCC_LENGTH(b)		(((b) & 0xfe) >> 1)
    224  1.1.4.2  chap #define RFCOMM_MKMCC_TYPE(cr, type)	((((type) << 2) | ((cr) << 1) | 0x01))
    225  1.1.4.2  chap 
    226  1.1.4.2  chap /* RPN macros */
    227  1.1.4.2  chap #define RFCOMM_RPN_DATA_BITS(line)	((line) & 0x3)
    228  1.1.4.2  chap #define RFCOMM_RPN_STOP_BITS(line)	(((line) >> 2) & 0x1)
    229  1.1.4.2  chap #define RFCOMM_RPN_PARITY(line)		(((line) >> 3) & 0x1)
    230  1.1.4.2  chap 
    231  1.1.4.2  chap /*************************************************************************
    232  1.1.4.2  chap  *************************************************************************
    233  1.1.4.2  chap  **			SOCK_STREAM RFCOMM sockets			**
    234  1.1.4.2  chap  *************************************************************************
    235  1.1.4.2  chap  *************************************************************************/
    236  1.1.4.2  chap 
    237  1.1.4.2  chap #define SO_RFCOMM_MTU		1	/* mtu */
    238  1.1.4.2  chap #define SO_RFCOMM_FC_INFO	2	/* flow control info (below) */
    239  1.1.4.2  chap 
    240  1.1.4.2  chap /* Flow control information */
    241  1.1.4.2  chap struct rfcomm_fc_info {
    242  1.1.4.2  chap 	uint8_t		lmodem;		/* modem signals (local) */
    243  1.1.4.2  chap 	uint8_t		rmodem;		/* modem signals (remote) */
    244  1.1.4.2  chap 	uint8_t		tx_cred;	/* TX credits */
    245  1.1.4.2  chap 	uint8_t		rx_cred;	/* RX credits */
    246  1.1.4.2  chap 	uint8_t		cfc;		/* credit flow control */
    247  1.1.4.2  chap 	uint8_t		reserved;
    248  1.1.4.2  chap };
    249  1.1.4.2  chap 
    250  1.1.4.2  chap #ifdef _KERNEL
    251  1.1.4.2  chap 
    252  1.1.4.2  chap /* sysctl variables */
    253  1.1.4.2  chap extern int rfcomm_sendspace;
    254  1.1.4.2  chap extern int rfcomm_recvspace;
    255  1.1.4.2  chap extern int rfcomm_mtu_default;
    256  1.1.4.2  chap extern int rfcomm_ack_timeout;
    257  1.1.4.2  chap extern int rfcomm_mcc_timeout;
    258  1.1.4.2  chap 
    259  1.1.4.2  chap /*
    260  1.1.4.2  chap  * Bluetooth RFCOMM session data
    261  1.1.4.2  chap  * One L2CAP connection == one RFCOMM session
    262  1.1.4.2  chap  */
    263  1.1.4.2  chap 
    264  1.1.4.2  chap /* Credit note */
    265  1.1.4.2  chap struct rfcomm_credit {
    266  1.1.4.2  chap 	struct rfcomm_dlc		*rc_dlc;	/* owner */
    267  1.1.4.2  chap 	uint16_t			 rc_len;	/* length */
    268  1.1.4.2  chap 	SIMPLEQ_ENTRY(rfcomm_credit)	 rc_next;	/* next credit */
    269  1.1.4.2  chap };
    270  1.1.4.2  chap 
    271  1.1.4.2  chap /* RFCOMM session data (one L2CAP channel) */
    272  1.1.4.2  chap struct rfcomm_session {
    273  1.1.4.2  chap 	struct l2cap_channel		*rs_l2cap;	/* L2CAP pointer */
    274  1.1.4.2  chap 	uint16_t			 rs_flags;	/* session flags */
    275  1.1.4.2  chap 	uint16_t			 rs_state;	/* session state */
    276  1.1.4.2  chap 	uint16_t			 rs_mtu;	/* default MTU */
    277  1.1.4.2  chap 
    278  1.1.4.2  chap 	SIMPLEQ_HEAD(,rfcomm_credit)	 rs_credits;	/* credit notes */
    279  1.1.4.2  chap 	LIST_HEAD(,rfcomm_dlc)		 rs_dlcs;	/* DLC list */
    280  1.1.4.2  chap 
    281  1.1.4.2  chap 	struct callout			 rs_timeout;	/* timeout */
    282  1.1.4.2  chap 
    283  1.1.4.2  chap 	LIST_ENTRY(rfcomm_session)	 rs_next;	/* next session */
    284  1.1.4.2  chap };
    285  1.1.4.2  chap 
    286  1.1.4.2  chap LIST_HEAD(rfcomm_session_list, rfcomm_session);
    287  1.1.4.2  chap extern struct rfcomm_session_list rfcomm_session_active;
    288  1.1.4.2  chap extern struct rfcomm_session_list rfcomm_session_listen;
    289  1.1.4.2  chap 
    290  1.1.4.2  chap /* Session state */
    291  1.1.4.2  chap #define RFCOMM_SESSION_CLOSED		0
    292  1.1.4.2  chap #define RFCOMM_SESSION_WAIT_CONNECT	1
    293  1.1.4.2  chap #define RFCOMM_SESSION_OPEN		2
    294  1.1.4.2  chap #define RFCOMM_SESSION_WAIT_DISCONNECT	3
    295  1.1.4.2  chap #define RFCOMM_SESSION_LISTEN		4
    296  1.1.4.2  chap 
    297  1.1.4.2  chap /* Session flags */
    298  1.1.4.2  chap #define RFCOMM_SESSION_INITIATOR	(1 << 0) /* we are initiator */
    299  1.1.4.2  chap #define RFCOMM_SESSION_CFC		(1 << 1) /* credit flow control */
    300  1.1.4.2  chap #define RFCOMM_SESSION_LFC		(1 << 2) /* local flow control */
    301  1.1.4.2  chap #define RFCOMM_SESSION_RFC		(1 << 3) /* remote flow control */
    302  1.1.4.2  chap #define RFCOMM_SESSION_FREE		(1 << 4) /* self lock out for free */
    303  1.1.4.2  chap 
    304  1.1.4.2  chap #define IS_INITIATOR(rs)	((rs)->rs_flags & RFCOMM_SESSION_INITIATOR)
    305  1.1.4.2  chap 
    306  1.1.4.2  chap /* Bluetooth RFCOMM DLC data (connection) */
    307  1.1.4.2  chap struct rfcomm_dlc {
    308  1.1.4.2  chap 	struct rfcomm_session	*rd_session; /* RFCOMM session */
    309  1.1.4.2  chap 	uint8_t			 rd_dlci;    /* RFCOMM DLCI */
    310  1.1.4.2  chap 
    311  1.1.4.2  chap 	uint16_t		 rd_flags;   /* DLC flags */
    312  1.1.4.2  chap 	uint16_t		 rd_state;   /* DLC state */
    313  1.1.4.2  chap 	uint16_t		 rd_mtu;     /* MTU */
    314  1.1.4.2  chap 
    315  1.1.4.2  chap 	struct sockaddr_bt	 rd_laddr;   /* local address */
    316  1.1.4.2  chap 	struct sockaddr_bt	 rd_raddr;   /* remote address */
    317  1.1.4.2  chap 
    318  1.1.4.2  chap 	uint8_t			 rd_lmodem;  /* local modem signls */
    319  1.1.4.2  chap 	uint8_t			 rd_rmodem;  /* remote modem signals */
    320  1.1.4.2  chap 
    321  1.1.4.2  chap 	int			 rd_rxcred;  /* receive credits (sent) */
    322  1.1.4.2  chap 	size_t			 rd_rxsize;  /* receive buffer (bytes, avail) */
    323  1.1.4.2  chap 	int			 rd_txcred;  /* transmit credits (unused) */
    324  1.1.4.2  chap 	int			 rd_pending; /* packets sent but not complete */
    325  1.1.4.2  chap 
    326  1.1.4.2  chap 	struct callout		 rd_timeout; /* timeout */
    327  1.1.4.2  chap 	struct mbuf		*rd_txbuf;   /* transmit buffer */
    328  1.1.4.2  chap 
    329  1.1.4.2  chap 	const struct btproto	*rd_proto;   /* upper layer callbacks */
    330  1.1.4.2  chap 	void			*rd_upper;   /* upper layer argument */
    331  1.1.4.2  chap 
    332  1.1.4.2  chap 	LIST_ENTRY(rfcomm_dlc)	 rd_next;    /* next dlc on session */
    333  1.1.4.2  chap };
    334  1.1.4.2  chap 
    335  1.1.4.2  chap /*
    336  1.1.4.2  chap  * Credit Flow Control works in the following way.
    337  1.1.4.2  chap  *
    338  1.1.4.2  chap  * txcred is how many packets we can send. Received credit
    339  1.1.4.2  chap  * is added to this value, and it is decremented each time
    340  1.1.4.2  chap  * we send a packet.
    341  1.1.4.2  chap  *
    342  1.1.4.2  chap  * rxsize is the number of bytes that are available in the
    343  1.1.4.2  chap  * upstream receive buffer.
    344  1.1.4.2  chap  *
    345  1.1.4.2  chap  * rxcred is the number of credits that we have previously
    346  1.1.4.2  chap  * sent that are still unused. This value will be decreased
    347  1.1.4.2  chap  * for each packet we receive and we will add to it when we
    348  1.1.4.2  chap  * send credits. We calculate the amount of credits to send
    349  1.1.4.2  chap  * by the cunning formula "(space / mtu) - sent" so that if
    350  1.1.4.2  chap  * we get a bunch of small packets, we can continue sending
    351  1.1.4.2  chap  * credits without risking buffer overflow.
    352  1.1.4.2  chap  */
    353  1.1.4.2  chap 
    354  1.1.4.2  chap /* DLC flags */
    355  1.1.4.2  chap #define RFCOMM_DLC_DETACH		(1 << 0) /* DLC to be detached */
    356  1.1.4.2  chap #define RFCOMM_DLC_SHUTDOWN		(1 << 1) /* DLC to be shutdown */
    357  1.1.4.2  chap 
    358  1.1.4.2  chap /* DLC state */
    359  1.1.4.2  chap #define RFCOMM_DLC_CLOSED		0	/* no session */
    360  1.1.4.2  chap #define RFCOMM_DLC_WAIT_SESSION		1	/* waiting for session */
    361  1.1.4.2  chap #define RFCOMM_DLC_WAIT_CONNECT		2	/* waiting for connect */
    362  1.1.4.2  chap #define RFCOMM_DLC_OPEN			3	/* can send/receive */
    363  1.1.4.2  chap #define RFCOMM_DLC_WAIT_DISCONNECT	4	/* waiting for disconnect */
    364  1.1.4.2  chap #define RFCOMM_DLC_LISTEN		5	/* listening DLC */
    365  1.1.4.2  chap 
    366  1.1.4.2  chap /*
    367  1.1.4.2  chap  * Bluetooth RFCOMM socket kernel prototypes
    368  1.1.4.2  chap  */
    369  1.1.4.2  chap 
    370  1.1.4.2  chap struct socket;
    371  1.1.4.2  chap 
    372  1.1.4.2  chap /* rfcomm_dlc.c */
    373  1.1.4.2  chap struct rfcomm_dlc *rfcomm_dlc_lookup(struct rfcomm_session *, int);
    374  1.1.4.2  chap struct rfcomm_dlc *rfcomm_dlc_newconn(struct rfcomm_session *, int);
    375  1.1.4.2  chap void rfcomm_dlc_close(struct rfcomm_dlc *, int);
    376  1.1.4.2  chap void rfcomm_dlc_timeout(void *);
    377  1.1.4.2  chap int rfcomm_dlc_connect(struct rfcomm_dlc *);
    378  1.1.4.2  chap void rfcomm_dlc_start(struct rfcomm_dlc *);
    379  1.1.4.2  chap 
    380  1.1.4.2  chap /* rfcomm_session.c */
    381  1.1.4.2  chap struct rfcomm_session *rfcomm_session_alloc(struct rfcomm_session_list *, struct sockaddr_bt *);
    382  1.1.4.2  chap struct rfcomm_session *rfcomm_session_lookup(struct sockaddr_bt *, struct sockaddr_bt *);
    383  1.1.4.2  chap void rfcomm_session_free(struct rfcomm_session *);
    384  1.1.4.2  chap int rfcomm_session_send_frame(struct rfcomm_session *, int, int);
    385  1.1.4.2  chap int rfcomm_session_send_uih(struct rfcomm_session *, struct rfcomm_dlc *, int, struct mbuf *);
    386  1.1.4.2  chap int rfcomm_session_send_mcc(struct rfcomm_session *, int, uint8_t, void *, int);
    387  1.1.4.2  chap 
    388  1.1.4.2  chap /* rfcomm_socket.c */
    389  1.1.4.2  chap int rfcomm_usrreq(struct socket *, int, struct mbuf *, struct mbuf *, struct mbuf *, struct lwp *);
    390  1.1.4.2  chap int rfcomm_ctloutput(int, struct socket *, int, int, struct mbuf **);
    391  1.1.4.2  chap 
    392  1.1.4.2  chap /* rfcomm_upper.c */
    393  1.1.4.2  chap int rfcomm_attach(struct rfcomm_dlc **, const struct btproto *, void *);
    394  1.1.4.2  chap int rfcomm_bind(struct rfcomm_dlc *, struct sockaddr_bt *);
    395  1.1.4.2  chap int rfcomm_sockaddr(struct rfcomm_dlc *, struct sockaddr_bt *);
    396  1.1.4.2  chap int rfcomm_connect(struct rfcomm_dlc *, struct sockaddr_bt *);
    397  1.1.4.2  chap int rfcomm_peeraddr(struct rfcomm_dlc *, struct sockaddr_bt *);
    398  1.1.4.2  chap int rfcomm_disconnect(struct rfcomm_dlc *, int);
    399  1.1.4.2  chap int rfcomm_detach(struct rfcomm_dlc **);
    400  1.1.4.2  chap int rfcomm_listen(struct rfcomm_dlc *);
    401  1.1.4.2  chap int rfcomm_send(struct rfcomm_dlc *, struct mbuf *);
    402  1.1.4.2  chap int rfcomm_rcvd(struct rfcomm_dlc *, size_t);
    403  1.1.4.2  chap int rfcomm_setopt(struct rfcomm_dlc *, int, void *);
    404  1.1.4.2  chap int rfcomm_getopt(struct rfcomm_dlc *, int, void *);
    405  1.1.4.2  chap 
    406  1.1.4.2  chap #endif /* _KERNEL */
    407  1.1.4.2  chap 
    408  1.1.4.2  chap #endif /* _NETBT_RFCOMM_H_ */
    409