1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
25
26
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
57
58
59
68
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
92
93
94
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
119
120
121
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
153
154
158
159
160
161
162
163
164
165
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
219
220
221
226
227
228
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
257
258
259
260
261
262
263
264
265
266
267
268
269
270
275
276
277
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
308
309
310
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
340
341
342
345
346
347
348
349
350
351
352
353
360
364
365
366
373
377
378
379
/* ... */
/* ... */
#include <string.h>
#include "common/bt_target.h"
#include "stack/rfcdefs.h"
#include "stack/port_api.h"
#include "stack/l2c_api.h"
#include "port_int.h"
#include "rfc_int.h"
#include "common/bt_defs.h"8 includes
#if (defined RFCOMM_INCLUDED && RFCOMM_INCLUDED == TRUE)
#if RFC_DYNAMIC_MEMORY == FALSE
tRFC_CB rfc_cb;
#else
tRFC_CB *rfc_cb_ptr;
#endif
/* ... */
void RFCOMM_StartReq (tRFC_MCB *p_mcb)
{
rfc_mx_sm_execute (p_mcb, RFC_MX_EVENT_START_REQ, NULL);
}{...}
/* ... */
void RFCOMM_StartRsp (tRFC_MCB *p_mcb, UINT16 result)
{
rfc_mx_sm_execute (p_mcb, RFC_MX_EVENT_START_RSP, &result);
}{...}
/* ... */
void RFCOMM_DlcEstablishReq (tRFC_MCB *p_mcb, UINT8 dlci, UINT16 mtu)
{
UNUSED(mtu);
if (p_mcb->state != RFC_MX_STATE_CONNECTED) {
PORT_DlcEstablishCnf (p_mcb, dlci, 0, RFCOMM_ERROR);
return;
}{...}
tPORT *p_port = port_find_mcb_dlci_port(p_mcb, dlci);
if (p_port == NULL) {
RFCOMM_TRACE_WARNING("%s Unable to find DLCI port dlci:%d", __func__,
dlci);
return;
}{...}
rfc_port_sm_execute(p_port, RFC_EVENT_OPEN, NULL);
}{...}
/* ... */
void RFCOMM_DlcEstablishRsp (tRFC_MCB *p_mcb, UINT8 dlci, UINT16 mtu, UINT16 result)
{
UNUSED(mtu);
if ((p_mcb->state != RFC_MX_STATE_CONNECTED) && (result == RFCOMM_SUCCESS)) {
PORT_DlcReleaseInd (p_mcb, dlci);
return;
}{...}
tPORT *p_port = port_find_mcb_dlci_port (p_mcb, dlci);
if (p_port == NULL) {
RFCOMM_TRACE_WARNING("%s Unable to find DLCI port dlci:%d", __func__,
dlci);
return;
}{...}
rfc_port_sm_execute(p_port, RFC_EVENT_ESTABLISH_RSP, &result);
}{...}
/* ... */
void RFCOMM_ParNegReq (tRFC_MCB *p_mcb, UINT8 dlci, UINT16 mtu)
{
UINT8 flow;
UINT8 cl;
UINT8 k;
tPORT *p_port = port_find_mcb_dlci_port(p_mcb, dlci);
if (p_port == NULL) {
RFCOMM_TRACE_WARNING("%s Unable to find DLCI port dlci:%d", __func__,
dlci);
return;
}{...}
if (p_mcb->state != RFC_MX_STATE_CONNECTED) {
p_port->error = PORT_PAR_NEG_FAILED;
return;
}{...}
flow = (p_mcb->flow == PORT_FC_UNDEFINED) ? PORT_FC_DEFAULT : p_mcb->flow;
if (flow == PORT_FC_CREDIT) {
cl = RFCOMM_PN_CONV_LAYER_CBFC_I;
k = (p_port->credit_rx_max < RFCOMM_K_MAX) ? p_port->credit_rx_max : RFCOMM_K_MAX;
p_port->credit_rx = k;
}{...} else {
cl = RFCOMM_PN_CONV_LAYER_TYPE_1;
k = 0;
}{...}
p_port->rfc.expected_rsp |= RFC_RSP_PN;
rfc_send_pn (p_mcb, dlci, TRUE, mtu, cl, k);
rfc_port_timer_start (p_port, RFC_T2_TIMEOUT) ;
}{...}
/* ... */
void RFCOMM_ParNegRsp (tRFC_MCB *p_mcb, UINT8 dlci, UINT16 mtu, UINT8 cl, UINT8 k)
{
if (p_mcb->state != RFC_MX_STATE_CONNECTED) {
return;
}{...}
rfc_send_pn (p_mcb, dlci, FALSE, mtu, cl, k);
}{...}
/* ... */
void RFCOMM_PortNegReq (tRFC_MCB *p_mcb, UINT8 dlci, tPORT_STATE *p_pars)
{
if (p_mcb->state != RFC_MX_STATE_CONNECTED) {
PORT_PortNegCnf (p_mcb, dlci, NULL, RFCOMM_ERROR);
return;
}{...}
tPORT *p_port = port_find_mcb_dlci_port(p_mcb, dlci);
if (p_port == NULL) {
RFCOMM_TRACE_WARNING("%s Unable to find DLCI port dlci:%d", __func__,
dlci);
return;
}{...}
if (!p_pars) {
p_port->rfc.expected_rsp |= RFC_RSP_RPN_REPLY;
}{...} else {
p_port->rfc.expected_rsp |= RFC_RSP_RPN;
}{...}
rfc_send_rpn (p_mcb, dlci, TRUE, p_pars, RFCOMM_RPN_PM_MASK);
rfc_port_timer_start (p_port, RFC_T2_TIMEOUT) ;
}{...}
/* ... */
void RFCOMM_PortNegRsp (tRFC_MCB *p_mcb, UINT8 dlci, tPORT_STATE *p_pars,
UINT16 param_mask)
{
if (p_mcb->state != RFC_MX_STATE_CONNECTED) {
return;
}{...}
rfc_send_rpn (p_mcb, dlci, FALSE, p_pars, param_mask);
}{...}
/* ... */
void RFCOMM_ControlReq (tRFC_MCB *p_mcb, UINT8 dlci, tPORT_CTRL *p_pars)
{
tPORT *p_port = port_find_mcb_dlci_port(p_mcb, dlci);
if (p_port == NULL) {
RFCOMM_TRACE_WARNING("%s Unable to find DLCI port dlci:%d", __func__,
dlci);
return;
}{...}
if ((p_port->state != PORT_STATE_OPENED)
|| (p_port->rfc.state != RFC_STATE_OPENED)) {
return;
}{...}
p_port->port_ctrl |= PORT_CTRL_REQ_SENT;
p_port->rfc.expected_rsp |= RFC_RSP_MSC;
rfc_send_msc (p_mcb, dlci, TRUE, p_pars);
rfc_port_timer_start (p_port, RFC_T2_TIMEOUT) ;
}{...}
/* ... */
void RFCOMM_FlowReq (tRFC_MCB *p_mcb, UINT8 dlci, UINT8 enable)
{
tPORT *p_port = port_find_mcb_dlci_port(p_mcb, dlci);
if (p_port == NULL) {
RFCOMM_TRACE_WARNING("%s Unable to find DLCI port dlci:%d", __func__,
dlci);
return;
}{...}
if ((p_port->state != PORT_STATE_OPENED)
|| (p_port->rfc.state != RFC_STATE_OPENED)) {
return;
}{...}
p_port->local_ctrl.fc = !enable;
p_port->rfc.expected_rsp |= RFC_RSP_MSC;
rfc_send_msc (p_mcb, dlci, TRUE, &p_port->local_ctrl);
rfc_port_timer_start (p_port, RFC_T2_TIMEOUT) ;
}{...}
/* ... */
void RFCOMM_LineStatusReq (tRFC_MCB *p_mcb, UINT8 dlci, UINT8 status)
{
tPORT *p_port = port_find_mcb_dlci_port(p_mcb, dlci);
if (p_port == NULL) {
RFCOMM_TRACE_WARNING("%s Unable to find DLCI port dlci:%d", __func__,
dlci);
return;
}{...}
if ((p_port->state != PORT_STATE_OPENED)
|| (p_port->rfc.state != RFC_STATE_OPENED)) {
return;
}{...}
p_port->rfc.expected_rsp |= RFC_RSP_RLS;
rfc_send_rls (p_mcb, dlci, TRUE, status);
rfc_port_timer_start (p_port, RFC_T2_TIMEOUT);
}{...}
/* ... */
void RFCOMM_DlcReleaseReq (tRFC_MCB *p_mcb, UINT8 dlci)
{
rfc_port_sm_execute(port_find_mcb_dlci_port (p_mcb, dlci), RFC_EVENT_CLOSE, 0);
}{...}
/* ... */
void RFCOMM_DataReq (tRFC_MCB *p_mcb, UINT8 dlci, BT_HDR *p_buf)
{
rfc_port_sm_execute(port_find_mcb_dlci_port (p_mcb, dlci), RFC_EVENT_DATA, p_buf);
}{...}
/* ... */
#endif