• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  *
3  *  Copyright 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 #pragma once
26 
27 /*
28  *  Server Channel Numbers (SCN) range between 1 and 30, inclusive
29  */
30 #define RFCOMM_MAX_SCN 30
31 
32 /*
33  * The maximum number of ports supported.
34  */
35 #define MAX_RFC_PORTS 30
36 
37 /*
38  * The maximum simultaneous links to different devices.
39  */
40 #define MAX_BD_CONNECTIONS 16
41 
42 /*
43  *  If nothing is negotiated MTU should be 127
44  */
45 #define RFCOMM_DEFAULT_MTU 127
46 
47 /*
48  *  The minimum allowed MTU should be 23 according to the RFCOMM specs
49  */
50 #define RFCOMM_MIN_MTU 23
51 
52 /*
53  * RFCOMM buffer sizes
54  */
55 #define RFCOMM_CMD_BUF_SIZE BT_SMALL_BUFFER_SIZE     // command packet buffer size
56 #define RFCOMM_DATA_BUF_SIZE BT_DEFAULT_BUFFER_SIZE  // data packet buffer size
57 
58 /*
59  * Define used by RFCOMM TS frame types
60  */
61 #define RFCOMM_SABME 0x2F  // Start Asynchronous Balanced Mode (startup command)
62 #define RFCOMM_UA 0x63     // Unnumbered Acknowledgement (response when connected)
63 #define RFCOMM_DM 0x0F     // Disconnected Mode (response to a command when disconnected)
64 #define RFCOMM_DISC 0x43   // Disconnect (disconnect command)
65 #define RFCOMM_UIH 0xEF    // Unnumbered Information with Header check
66 
67 /*
68  * Defenitions for the TS control frames
69  */
70 #define RFCOMM_CTRL_FRAME_LEN 3
71 #define RFCOMM_MIN_OFFSET 5                          /* ctrl 2 , len 1 or 2 bytes, credit 1 byte */
72 #define RFCOMM_DATA_OVERHEAD (RFCOMM_MIN_OFFSET + 1) /* add 1 for checksum */
73 
74 #define RFCOMM_EA 1
75 #define RFCOMM_EA_MASK 0x01
76 #define RFCOMM_CR_MASK 0x02
77 #define RFCOMM_SHIFT_CR 1
78 #define RFCOMM_SHIFT_DLCI 2
79 #define RFCOMM_SHIFT_DLCI2 6
80 #define RFCOMM_PF 0x10
81 #define RFCOMM_PF_MASK 0x10
82 #define RFCOMM_PF_OFFSET 4
83 #define RFCOMM_SHIFT_LENGTH1 1
84 #define RFCOMM_SHIFT_LENGTH2 7
85 #define RFCOMM_SHIFT_MX_CTRL_TYPE 2
86 
87 #define RFCOMM_INITIATOR_CMD 1
88 #define RFCOMM_INITIATOR_RSP 0
89 #define RFCOMM_RESPONDER_CMD 0
90 #define RFCOMM_RESPONDER_RSP 1
91 
92 #define RFCOMM_PARSE_CTRL_FIELD(ea, cr, dlci, p_data)       \
93   {                                                         \
94     (ea) = *(p_data) & RFCOMM_EA;                           \
95     (cr) = (*(p_data) & RFCOMM_CR_MASK) >> RFCOMM_SHIFT_CR; \
96     (dlci) = *(p_data)++ >> RFCOMM_SHIFT_DLCI;              \
97     if (!(ea))                                              \
98       (dlci) += *(p_data)++ << RFCOMM_SHIFT_DLCI2;          \
99   }
100 
101 #define RFCOMM_FORMAT_CTRL_FIELD(p_data, ea, cr, dlci) \
102   (*(p_data)++ = (ea) | (cr) | ((dlci) << RFCOMM_SHIFT_DLCI))
103 
104 #define RFCOMM_PARSE_TYPE_FIELD(type, pf, p_data)              \
105   {                                                            \
106     (type) = *(p_data) & ~RFCOMM_PF_MASK;                      \
107     (pf) = (*(p_data)++ & RFCOMM_PF_MASK) >> RFCOMM_PF_OFFSET; \
108   }
109 
110 #define RFCOMM_FORMAT_TYPE_FIELD(p_data, type, pf)             \
111   *(p_data)++ = ((type) | ((pf) << RFCOMM_PF_OFFSET)) {        \
112     (type) = *(p_data) & ~RFCOMM_PF_MASK;                      \
113     (pf) = (*(p_data)++ & RFCOMM_PF_MASK) >> RFCOMM_PF_OFFSET; \
114   }
115 
116 #define RFCOMM_FRAME_IS_CMD(initiator, cr) (((initiator) && !(cr)) || (!(initiator) && (cr)))
117 
118 #define RFCOMM_FRAME_IS_RSP(initiator, cr) (((initiator) && (cr)) || (!(initiator) && !(cr)))
119 
120 #define RFCOMM_CR(initiator, is_command) \
121   ((((initiator) && (is_command)) || (!(initiator) && !(is_command))) << 1)
122 
123 #define RFCOMM_I_CR(is_command) ((is_command) ? 0x02 : 0x00)
124 
125 #define RFCOMM_MAX_DLCI 61
126 
127 #define RFCOMM_VALID_DLCI(dlci) (((dlci) == 0) || (((dlci) >= 2) && ((dlci) <= RFCOMM_MAX_DLCI)))
128 
129 /* Port Negotiation (PN) */
130 #define RFCOMM_PN_DLCI_MASK 0x3F
131 
132 #define RFCOMM_PN_FRAM_TYPE_UIH 0x00
133 #define RFCOMM_PN_FRAME_TYPE_MASK 0x0F
134 
135 #define RFCOMM_PN_CONV_LAYER_MASK 0xF0
136 #define RFCOMM_PN_CONV_LAYER_TYPE_1 0
137 #define RFCOMM_PN_CONV_LAYER_CBFC_I 0xF0
138 #define RFCOMM_PN_CONV_LAYER_CBFC_R 0xE0
139 
140 #define RFCOMM_PN_PRIORITY_MASK 0x3F
141 #define RFCOMM_PN_PRIORITY_0 0
142 
143 #define RFCOMM_PN_K_MASK 0x07
144 
145 #define RFCOMM_T1_DSEC 0 /* None negotiable in RFCOMM */
146 #define RFCOMM_N2 0      /* Number of retransmissions */
147 #define RFCOMM_K 0       /* Window size */
148 #define RFCOMM_K_MAX 7   /* Max value of K for credit based flow control */
149 
150 #define RFCOMM_MSC_FC 0x02  /* Flow control*/
151 #define RFCOMM_MSC_RTC 0x04 /* Ready to communicate*/
152 #define RFCOMM_MSC_RTR 0x08 /* Ready to receive*/
153 #define RFCOMM_MSC_IC 0x40  /* Incomming call indicator*/
154 #define RFCOMM_MSC_DV 0x80  /* Data Valid*/
155 
156 #define RFCOMM_MSC_SHIFT_BREAK 4
157 #define RFCOMM_MSC_BREAK_MASK 0xF0
158 #define RFCOMM_MSC_BREAK_PRESENT_MASK 0x02
159 
160 #define RFCOMM_BAUD_RATE_2400 0x00
161 #define RFCOMM_BAUD_RATE_4800 0x01
162 #define RFCOMM_BAUD_RATE_7200 0x02
163 #define RFCOMM_BAUD_RATE_9600 0x03
164 #define RFCOMM_BAUD_RATE_19200 0x04
165 #define RFCOMM_BAUD_RATE_38400 0x05
166 #define RFCOMM_BAUD_RATE_57600 0x06
167 #define RFCOMM_BAUD_RATE_115200 0x07
168 #define RFCOMM_BAUD_RATE_230400 0x08
169 
170 #define RFCOMM_5_BITS 0x00
171 #define RFCOMM_6_BITS 0x01
172 #define RFCOMM_7_BITS 0x02
173 #define RFCOMM_8_BITS 0x03
174 
175 #define RFCOMM_RPN_BITS_MASK 0x03
176 #define RFCOMM_RPN_BITS_SHIFT 0
177 
178 #define RFCOMM_ONESTOPBIT 0x00
179 #define RFCOMM_ONE5STOPBITS 0x01
180 
181 #define RFCOMM_RPN_STOP_BITS_MASK 0x01
182 #define RFCOMM_RPN_STOP_BITS_SHIFT 2
183 
184 #define RFCOMM_PARITY_NO 0x00
185 #define RFCOMM_PARITY_YES 0x01
186 #define RFCOMM_RPN_PARITY_MASK 0x01
187 #define RFCOMM_RPN_PARITY_SHIFT 3
188 
189 #define RFCOMM_ODD_PARITY 0x00
190 #define RFCOMM_EVEN_PARITY 0x01
191 #define RFCOMM_MARK_PARITY 0x02
192 #define RFCOMM_SPACE_PARITY 0x03
193 
194 #define RFCOMM_RPN_PARITY_TYPE_MASK 0x03
195 #define RFCOMM_RPN_PARITY_TYPE_SHIFT 4
196 
197 #define RFCOMM_FC_OFF 0x00
198 #define RFCOMM_FC_XONXOFF_ON_INPUT 0x01
199 #define RFCOMM_FC_XONXOFF_ON_OUTPUT 0x02
200 #define RFCOMM_FC_RTR_ON_INPUT 0x04
201 #define RFCOMM_FC_RTR_ON_OUTPUT 0x08
202 #define RFCOMM_FC_RTC_ON_INPUT 0x10
203 #define RFCOMM_FC_RTC_ON_OUTPUT 0x20
204 #define RFCOMM_FC_MASK 0x3F
205 
206 #define RFCOMM_RPN_PM_BIT_RATE 0x0001
207 #define RFCOMM_RPN_PM_DATA_BITS 0x0002
208 #define RFCOMM_RPN_PM_STOP_BITS 0x0004
209 #define RFCOMM_RPN_PM_PARITY 0x0008
210 #define RFCOMM_RPN_PM_PARITY_TYPE 0x0010
211 #define RFCOMM_RPN_PM_XON_CHAR 0x0020
212 #define RFCOMM_RPN_PM_XOFF_CHAR 0x0040
213 #define RFCOMM_RPN_PM_XONXOFF_ON_INPUT 0x0100
214 #define RFCOMM_RPN_PM_XONXOFF_ON_OUTPUT 0x0200
215 #define RFCOMM_RPN_PM_RTR_ON_INPUT 0x0400
216 #define RFCOMM_RPN_PM_RTR_ON_OUTPUT 0x0800
217 #define RFCOMM_RPN_PM_RTC_ON_INPUT 0x1000
218 #define RFCOMM_RPN_PM_RTC_ON_OUTPUT 0x2000
219 #define RFCOMM_RPN_PM_MASK 0x3F7F
220 
221 #define RFCOMM_RLS_ERROR 0x01
222 #define RFCOMM_RLS_OVERRUN 0x02
223 #define RFCOMM_RLS_PARITY 0x04
224 #define RFCOMM_RLS_FRAMING 0x08
225 
226 /* Multiplexor channel uses DLCI 0 */
227 #define RFCOMM_MX_DLCI 0
228 
229 /*
230  * Define RFCOMM Multiplexer message types
231  */
232 #define RFCOMM_MX_PN 0x80
233 #define RFCOMM_MX_PN_LEN 8
234 
235 #define RFCOMM_MX_CLD 0xC0
236 #define RFCOMM_MX_CLD_LEN 0
237 
238 #define RFCOMM_MX_TEST 0x20
239 
240 #define RFCOMM_MX_FCON 0xA0
241 #define RFCOMM_MX_FCON_LEN 0
242 
243 #define RFCOMM_MX_FCOFF 0x60
244 #define RFCOMM_MX_FCOFF_LEN 0
245 
246 #define RFCOMM_MX_MSC 0xE0
247 #define RFCOMM_MX_MSC_LEN_NO_BREAK 2
248 #define RFCOMM_MX_MSC_LEN_WITH_BREAK 3
249 
250 #define RFCOMM_MX_NSC 0x10
251 #define RFCOMM_MX_NSC_LEN 1
252 
253 #define RFCOMM_MX_RPN 0x90
254 #define RFCOMM_MX_RPN_REQ_LEN 1
255 #define RFCOMM_MX_RPN_LEN 8
256 
257 #define RFCOMM_MX_RLS 0x50
258 #define RFCOMM_MX_RLS_LEN 2
259 
260 /*
261  * Define RFCOMM port rx and tx queue watermarks
262  */
263 // MTU size used to calculate watermark levels
264 #define BTA_RFC_MTU_SIZE (L2CAP_MTU_SIZE - L2CAP_MIN_OFFSET - RFCOMM_DATA_OVERHEAD)
265 
266 // The port receive queue low watermark level, in number of buffers.
267 #define PORT_RX_BUF_LOW_WM 8
268 
269 // The port receive queue high watermark level, in number of buffers.
270 #define PORT_RX_BUF_HIGH_WM 10
271 
272 // The port receive queue critical watermark level, in number of buffers.
273 #define PORT_RX_BUF_CRITICAL_WM 15
274 
275 // The port receive queue low watermark level, in bytes.
276 #define PORT_RX_LOW_WM (BTA_RFC_MTU_SIZE * PORT_RX_BUF_LOW_WM)
277 
278 // The port receive queue high watermark level, in bytes.
279 #define PORT_RX_HIGH_WM (BTA_RFC_MTU_SIZE * PORT_RX_BUF_HIGH_WM)
280 
281 // The port receive queue critical watermark level, in bytes.
282 #define PORT_RX_CRITICAL_WM (BTA_RFC_MTU_SIZE * PORT_RX_BUF_CRITICAL_WM)
283 
284 // The port transmit queue high watermark level, in number of buffers.
285 #define PORT_TX_BUF_HIGH_WM 10
286 
287 // The port transmit queue high watermark level, in number of buffers.
288 #define PORT_TX_BUF_CRITICAL_WM 15
289 
290 // The port transmit queue high watermark level, in bytes.
291 #define PORT_TX_HIGH_WM (BTA_RFC_MTU_SIZE * PORT_TX_BUF_HIGH_WM)
292 
293 // The port transmit queue critical watermark level, in bytes.
294 #define PORT_TX_CRITICAL_WM (BTA_RFC_MTU_SIZE * PORT_TX_BUF_CRITICAL_WM)
295