blob: 5118ccd06ed2587efe7d6b82f5418e530dc6b541 [file] [log] [blame]
The Android Open Source Project5738f832012-12-12 16:00:35 -08001/******************************************************************************
2 *
3 * Copyright (C) 1999-2012 Broadcom Corporation
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at:
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 ******************************************************************************/
18
19/****************************************************************************
20 *
21 * This file contains definitions for the RFCOMM protocol
22 *
23 ****************************************************************************/
24
25#ifndef RFCDEFS_H
26#define RFCDEFS_H
27
Myles Watson911d1ae2016-11-28 16:44:40 -080028#define PORT_MAX_RFC_PORTS 31
The Android Open Source Project5738f832012-12-12 16:00:35 -080029
30/*
Myles Watsonee96a3c2016-11-23 14:49:54 -080031 * If nothing is negotiated MTU should be 127
The Android Open Source Project5738f832012-12-12 16:00:35 -080032*/
Myles Watson911d1ae2016-11-28 16:44:40 -080033#define RFCOMM_DEFAULT_MTU 127
The Android Open Source Project5738f832012-12-12 16:00:35 -080034
35/*
Myles Watsonee96a3c2016-11-23 14:49:54 -080036 * Define used by RFCOMM TS frame types
The Android Open Source Project5738f832012-12-12 16:00:35 -080037*/
Myles Watson911d1ae2016-11-28 16:44:40 -080038#define RFCOMM_SABME 0x2F
39#define RFCOMM_UA 0x63
40#define RFCOMM_DM 0x0F
41#define RFCOMM_DISC 0x43
42#define RFCOMM_UIH 0xEF
The Android Open Source Project5738f832012-12-12 16:00:35 -080043
44/*
Myles Watsonee96a3c2016-11-23 14:49:54 -080045 * Defenitions for the TS control frames
The Android Open Source Project5738f832012-12-12 16:00:35 -080046*/
Myles Watson911d1ae2016-11-28 16:44:40 -080047#define RFCOMM_CTRL_FRAME_LEN 3
48#define RFCOMM_MIN_OFFSET 5 /* ctrl 2 , len 1 or 2 bytes, credit 1 byte */
49#define RFCOMM_DATA_OVERHEAD (RFCOMM_MIN_OFFSET + 1) /* add 1 for checksum */
The Android Open Source Project5738f832012-12-12 16:00:35 -080050
Myles Watson911d1ae2016-11-28 16:44:40 -080051#define RFCOMM_EA 1
52#define RFCOMM_EA_MASK 0x01
53#define RFCOMM_CR_MASK 0x02
54#define RFCOMM_SHIFT_CR 1
55#define RFCOMM_SHIFT_DLCI 2
56#define RFCOMM_SHIFT_DLCI2 6
57#define RFCOMM_PF 0x10
58#define RFCOMM_PF_MASK 0x10
59#define RFCOMM_PF_OFFSET 4
60#define RFCOMM_SHIFT_LENGTH1 1
61#define RFCOMM_SHIFT_LENGTH2 7
62#define RFCOMM_SHIFT_MX_CTRL_TYPE 2
The Android Open Source Project5738f832012-12-12 16:00:35 -080063
Myles Watson911d1ae2016-11-28 16:44:40 -080064#define RFCOMM_INITIATOR_CMD 1
65#define RFCOMM_INITIATOR_RSP 0
66#define RFCOMM_RESPONDER_CMD 0
67#define RFCOMM_RESPONDER_RSP 1
The Android Open Source Project5738f832012-12-12 16:00:35 -080068
69#define RFCOMM_PARSE_CTRL_FIELD(ea, cr, dlci, p_data) \
Myles Watson911d1ae2016-11-28 16:44:40 -080070 { \
71 (ea) = *(p_data)&RFCOMM_EA; \
72 (cr) = (*(p_data)&RFCOMM_CR_MASK) >> RFCOMM_SHIFT_CR; \
Chih-Hung Hsieh63b05192016-05-20 10:29:31 -070073 (dlci) = *(p_data)++ >> RFCOMM_SHIFT_DLCI; \
74 if (!(ea)) (dlci) += *(p_data)++ << RFCOMM_SHIFT_DLCI2; \
Myles Watson911d1ae2016-11-28 16:44:40 -080075 }
The Android Open Source Project5738f832012-12-12 16:00:35 -080076
Chih-Hung Hsieh63b05192016-05-20 10:29:31 -070077#define RFCOMM_FORMAT_CTRL_FIELD(p_data, ea, cr, dlci) \
Myles Watson911d1ae2016-11-28 16:44:40 -080078 (*(p_data)++ = (ea) | (cr) | ((dlci) << RFCOMM_SHIFT_DLCI))
The Android Open Source Project5738f832012-12-12 16:00:35 -080079
Myles Watson911d1ae2016-11-28 16:44:40 -080080#define RFCOMM_PARSE_TYPE_FIELD(type, pf, p_data) \
81 { \
82 (type) = *(p_data) & ~RFCOMM_PF_MASK; \
83 (pf) = (*(p_data)++ & RFCOMM_PF_MASK) >> RFCOMM_PF_OFFSET; \
84 }
The Android Open Source Project5738f832012-12-12 16:00:35 -080085
Myles Watson911d1ae2016-11-28 16:44:40 -080086#define RFCOMM_FORMAT_TYPE_FIELD(p_data, type, pf) \
87 *(p_data)++ = ((type) | ((pf) << RFCOMM_PF_OFFSET)) { \
88 (type) = *(p_data) & ~RFCOMM_PF_MASK; \
89 (pf) = (*(p_data)++ & RFCOMM_PF_MASK) >> RFCOMM_PF_OFFSET; \
90 }
The Android Open Source Project5738f832012-12-12 16:00:35 -080091
Chih-Hung Hsieh63b05192016-05-20 10:29:31 -070092#define RFCOMM_PARSE_LEN_FIELD(ea, length, p_data) \
Myles Watson911d1ae2016-11-28 16:44:40 -080093 { \
94 (ea) = (*(p_data)&RFCOMM_EA); \
Chih-Hung Hsieh63b05192016-05-20 10:29:31 -070095 (length) = (*(p_data)++ >> RFCOMM_SHIFT_LENGTH1); \
96 if (!(ea)) (length) += (*(p_data)++ << RFCOMM_SHIFT_LENGTH2); \
Myles Watson911d1ae2016-11-28 16:44:40 -080097 }
The Android Open Source Project5738f832012-12-12 16:00:35 -080098
Myles Watson911d1ae2016-11-28 16:44:40 -080099#define RFCOMM_FRAME_IS_CMD(initiator, cr) \
100 (((initiator) && !(cr)) || (!(initiator) && (cr)))
The Android Open Source Project5738f832012-12-12 16:00:35 -0800101
Myles Watson911d1ae2016-11-28 16:44:40 -0800102#define RFCOMM_FRAME_IS_RSP(initiator, cr) \
103 (((initiator) && (cr)) || (!(initiator) && !(cr)))
The Android Open Source Project5738f832012-12-12 16:00:35 -0800104
Myles Watson911d1ae2016-11-28 16:44:40 -0800105#define RFCOMM_CR(initiator, is_command) \
106 ((((initiator) && (is_command)) || (!(initiator) && !(is_command))) << 1)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800107
108#define RFCOMM_I_CR(is_command) ((is_command) ? 0x02 : 0x00)
109
Myles Watson911d1ae2016-11-28 16:44:40 -0800110#define RFCOMM_MAX_DLCI 61
The Android Open Source Project5738f832012-12-12 16:00:35 -0800111
Myles Watson911d1ae2016-11-28 16:44:40 -0800112#define RFCOMM_VALID_DLCI(dlci) \
113 (((dlci) == 0) || (((dlci) >= 2) && ((dlci) <= RFCOMM_MAX_DLCI)))
The Android Open Source Project5738f832012-12-12 16:00:35 -0800114
115/* Port Negotiation (PN) */
Myles Watson911d1ae2016-11-28 16:44:40 -0800116#define RFCOMM_PN_DLCI_MASK 0x3F
The Android Open Source Project5738f832012-12-12 16:00:35 -0800117
Myles Watson911d1ae2016-11-28 16:44:40 -0800118#define RFCOMM_PN_FRAM_TYPE_UIH 0x00
119#define RFCOMM_PN_FRAME_TYPE_MASK 0x0F
The Android Open Source Project5738f832012-12-12 16:00:35 -0800120
Myles Watson911d1ae2016-11-28 16:44:40 -0800121#define RFCOMM_PN_CONV_LAYER_MASK 0xF0
The Android Open Source Project5738f832012-12-12 16:00:35 -0800122#define RFCOMM_PN_CONV_LAYER_TYPE_1 0
123#define RFCOMM_PN_CONV_LAYER_CBFC_I 0xF0
124#define RFCOMM_PN_CONV_LAYER_CBFC_R 0xE0
125
Myles Watson911d1ae2016-11-28 16:44:40 -0800126#define RFCOMM_PN_PRIORITY_MASK 0x3F
127#define RFCOMM_PN_PRIORITY_0 0
The Android Open Source Project5738f832012-12-12 16:00:35 -0800128
Myles Watson911d1ae2016-11-28 16:44:40 -0800129#define RFCOMM_PN_K_MASK 0x07
The Android Open Source Project5738f832012-12-12 16:00:35 -0800130
Myles Watson911d1ae2016-11-28 16:44:40 -0800131#define RFCOMM_T1_DSEC 0 /* None negotiable in RFCOMM */
132#define RFCOMM_N2 0 /* Number of retransmissions */
133#define RFCOMM_K 0 /* Window size */
134#define RFCOMM_K_MAX 7 /* Max value of K for credit based flow control */
The Android Open Source Project5738f832012-12-12 16:00:35 -0800135
Myles Watson911d1ae2016-11-28 16:44:40 -0800136#define RFCOMM_MSC_FC 0x02 /* Flow control*/
137#define RFCOMM_MSC_RTC 0x04 /* Ready to communicate*/
138#define RFCOMM_MSC_RTR 0x08 /* Ready to receive*/
139#define RFCOMM_MSC_IC 0x40 /* Incomming call indicator*/
140#define RFCOMM_MSC_DV 0x80 /* Data Valid*/
The Android Open Source Project5738f832012-12-12 16:00:35 -0800141
Myles Watson911d1ae2016-11-28 16:44:40 -0800142#define RFCOMM_MSC_SHIFT_BREAK 4
143#define RFCOMM_MSC_BREAK_MASK 0xF0
144#define RFCOMM_MSC_BREAK_PRESENT_MASK 0x02
The Android Open Source Project5738f832012-12-12 16:00:35 -0800145
Myles Watson911d1ae2016-11-28 16:44:40 -0800146#define RFCOMM_BAUD_RATE_2400 0x00
147#define RFCOMM_BAUD_RATE_4800 0x01
148#define RFCOMM_BAUD_RATE_7200 0x02
149#define RFCOMM_BAUD_RATE_9600 0x03
150#define RFCOMM_BAUD_RATE_19200 0x04
151#define RFCOMM_BAUD_RATE_38400 0x05
152#define RFCOMM_BAUD_RATE_57600 0x06
153#define RFCOMM_BAUD_RATE_115200 0x07
154#define RFCOMM_BAUD_RATE_230400 0x08
The Android Open Source Project5738f832012-12-12 16:00:35 -0800155
Myles Watson911d1ae2016-11-28 16:44:40 -0800156#define RFCOMM_5_BITS 0x00
157#define RFCOMM_6_BITS 0x01
158#define RFCOMM_7_BITS 0x02
159#define RFCOMM_8_BITS 0x03
The Android Open Source Project5738f832012-12-12 16:00:35 -0800160
Myles Watson911d1ae2016-11-28 16:44:40 -0800161#define RFCOMM_RPN_BITS_MASK 0x03
162#define RFCOMM_RPN_BITS_SHIFT 0
The Android Open Source Project5738f832012-12-12 16:00:35 -0800163
Myles Watson911d1ae2016-11-28 16:44:40 -0800164#define RFCOMM_ONESTOPBIT 0x00
165#define RFCOMM_ONE5STOPBITS 0x01
The Android Open Source Project5738f832012-12-12 16:00:35 -0800166
Myles Watson911d1ae2016-11-28 16:44:40 -0800167#define RFCOMM_RPN_STOP_BITS_MASK 0x01
168#define RFCOMM_RPN_STOP_BITS_SHIFT 2
The Android Open Source Project5738f832012-12-12 16:00:35 -0800169
Myles Watson911d1ae2016-11-28 16:44:40 -0800170#define RFCOMM_PARITY_NO 0x00
171#define RFCOMM_PARITY_YES 0x01
172#define RFCOMM_RPN_PARITY_MASK 0x01
173#define RFCOMM_RPN_PARITY_SHIFT 3
The Android Open Source Project5738f832012-12-12 16:00:35 -0800174
Myles Watson911d1ae2016-11-28 16:44:40 -0800175#define RFCOMM_ODD_PARITY 0x00
176#define RFCOMM_EVEN_PARITY 0x01
177#define RFCOMM_MARK_PARITY 0x02
178#define RFCOMM_SPACE_PARITY 0x03
The Android Open Source Project5738f832012-12-12 16:00:35 -0800179
Myles Watson911d1ae2016-11-28 16:44:40 -0800180#define RFCOMM_RPN_PARITY_TYPE_MASK 0x03
181#define RFCOMM_RPN_PARITY_TYPE_SHIFT 4
The Android Open Source Project5738f832012-12-12 16:00:35 -0800182
Myles Watson911d1ae2016-11-28 16:44:40 -0800183#define RFCOMM_FC_OFF 0x00
184#define RFCOMM_FC_XONXOFF_ON_INPUT 0x01
185#define RFCOMM_FC_XONXOFF_ON_OUTPUT 0x02
186#define RFCOMM_FC_RTR_ON_INPUT 0x04
187#define RFCOMM_FC_RTR_ON_OUTPUT 0x08
188#define RFCOMM_FC_RTC_ON_INPUT 0x10
189#define RFCOMM_FC_RTC_ON_OUTPUT 0x20
190#define RFCOMM_FC_MASK 0x3F
The Android Open Source Project5738f832012-12-12 16:00:35 -0800191
Myles Watson911d1ae2016-11-28 16:44:40 -0800192#define RFCOMM_RPN_PM_BIT_RATE 0x0001
193#define RFCOMM_RPN_PM_DATA_BITS 0x0002
194#define RFCOMM_RPN_PM_STOP_BITS 0x0004
195#define RFCOMM_RPN_PM_PARITY 0x0008
196#define RFCOMM_RPN_PM_PARITY_TYPE 0x0010
197#define RFCOMM_RPN_PM_XON_CHAR 0x0020
198#define RFCOMM_RPN_PM_XOFF_CHAR 0x0040
199#define RFCOMM_RPN_PM_XONXOFF_ON_INPUT 0x0100
The Android Open Source Project5738f832012-12-12 16:00:35 -0800200#define RFCOMM_RPN_PM_XONXOFF_ON_OUTPUT 0x0200
Myles Watson911d1ae2016-11-28 16:44:40 -0800201#define RFCOMM_RPN_PM_RTR_ON_INPUT 0x0400
202#define RFCOMM_RPN_PM_RTR_ON_OUTPUT 0x0800
203#define RFCOMM_RPN_PM_RTC_ON_INPUT 0x1000
204#define RFCOMM_RPN_PM_RTC_ON_OUTPUT 0x2000
205#define RFCOMM_RPN_PM_MASK 0x3F7F
The Android Open Source Project5738f832012-12-12 16:00:35 -0800206
Myles Watson911d1ae2016-11-28 16:44:40 -0800207#define RFCOMM_RLS_ERROR 0x01
208#define RFCOMM_RLS_OVERRUN 0x02
209#define RFCOMM_RLS_PARITY 0x04
210#define RFCOMM_RLS_FRAMING 0x08
The Android Open Source Project5738f832012-12-12 16:00:35 -0800211
212/* Multiplexor channel uses DLCI 0 */
Myles Watson911d1ae2016-11-28 16:44:40 -0800213#define RFCOMM_MX_DLCI 0
The Android Open Source Project5738f832012-12-12 16:00:35 -0800214
215/*
Myles Watsonee96a3c2016-11-23 14:49:54 -0800216 * Define RFCOMM Multiplexer message types
The Android Open Source Project5738f832012-12-12 16:00:35 -0800217*/
Myles Watson911d1ae2016-11-28 16:44:40 -0800218#define RFCOMM_MX_PN 0x80
219#define RFCOMM_MX_PN_LEN 8
The Android Open Source Project5738f832012-12-12 16:00:35 -0800220
Myles Watson911d1ae2016-11-28 16:44:40 -0800221#define RFCOMM_MX_CLD 0xC0
222#define RFCOMM_MX_CLD_LEN 0
The Android Open Source Project5738f832012-12-12 16:00:35 -0800223
Myles Watson911d1ae2016-11-28 16:44:40 -0800224#define RFCOMM_MX_TEST 0x20
The Android Open Source Project5738f832012-12-12 16:00:35 -0800225
Myles Watson911d1ae2016-11-28 16:44:40 -0800226#define RFCOMM_MX_FCON 0xA0
227#define RFCOMM_MX_FCON_LEN 0
The Android Open Source Project5738f832012-12-12 16:00:35 -0800228
Myles Watson911d1ae2016-11-28 16:44:40 -0800229#define RFCOMM_MX_FCOFF 0x60
230#define RFCOMM_MX_FCOFF_LEN 0
The Android Open Source Project5738f832012-12-12 16:00:35 -0800231
Myles Watson911d1ae2016-11-28 16:44:40 -0800232#define RFCOMM_MX_MSC 0xE0
233#define RFCOMM_MX_MSC_LEN_NO_BREAK 2
234#define RFCOMM_MX_MSC_LEN_WITH_BREAK 3
The Android Open Source Project5738f832012-12-12 16:00:35 -0800235
Myles Watson911d1ae2016-11-28 16:44:40 -0800236#define RFCOMM_MX_NSC 0x10
237#define RFCOMM_MX_NSC_LEN 1
The Android Open Source Project5738f832012-12-12 16:00:35 -0800238
Myles Watson911d1ae2016-11-28 16:44:40 -0800239#define RFCOMM_MX_RPN 0x90
240#define RFCOMM_MX_RPN_REQ_LEN 1
241#define RFCOMM_MX_RPN_LEN 8
The Android Open Source Project5738f832012-12-12 16:00:35 -0800242
Myles Watson911d1ae2016-11-28 16:44:40 -0800243#define RFCOMM_MX_RLS 0x50
244#define RFCOMM_MX_RLS_LEN 2
The Android Open Source Project5738f832012-12-12 16:00:35 -0800245#endif