1 /******************************************************************************
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 state machine and action routines for multiplexer
22 * channel of the RFCOMM unit
23 *
24 ******************************************************************************/
25 #include <string.h>
26 #include "gki.h"
27 #include "bt_types.h"
28 #include "rfcdefs.h"
29 #include "l2cdefs.h"
30 #include "port_api.h"
31 #include "port_int.h"
32 #include "l2c_api.h"
33 #include "rfc_int.h"
34 #include "bt_utils.h"
35
36 #define L2CAP_SUCCESS 0
37 #define L2CAP_ERROR 1
38
39
40 /********************************************************************************/
41 /* L O C A L F U N C T I O N P R O T O T Y P E S */
42 /********************************************************************************/
43 static void rfc_mx_sm_state_idle (tRFC_MCB *p_mcb, UINT16 event, void *p_data);
44 static void rfc_mx_sm_state_wait_conn_cnf (tRFC_MCB *p_mcb, UINT16 event, void *p_data);
45 static void rfc_mx_sm_state_configure (tRFC_MCB *p_mcb, UINT16 event, void *p_data);
46 static void rfc_mx_sm_sabme_wait_ua (tRFC_MCB *p_mcb, UINT16 event, void *p_data);
47 static void rfc_mx_sm_state_wait_sabme (tRFC_MCB *p_mcb, UINT16 event, void *p_data);
48 static void rfc_mx_sm_state_connected (tRFC_MCB *p_mcb, UINT16 event, void *p_data);
49 static void rfc_mx_sm_state_disc_wait_ua (tRFC_MCB *p_mcb, UINT16 event, void *p_data);
50
51 static void rfc_mx_send_config_req (tRFC_MCB *p_mcb);
52 static void rfc_mx_conf_ind (tRFC_MCB *p_mcb, tL2CAP_CFG_INFO *p_cfg);
53 static void rfc_mx_conf_cnf (tRFC_MCB *p_mcb, tL2CAP_CFG_INFO *p_cfg);
54
55
56
57 /*******************************************************************************
58 **
59 ** Function rfc_mx_sm_execute
60 **
61 ** Description This function sends multiplexor events through the state
62 ** machine.
63 **
64 ** Returns void
65 **
66 *******************************************************************************/
rfc_mx_sm_execute(tRFC_MCB * p_mcb,UINT16 event,void * p_data)67 void rfc_mx_sm_execute (tRFC_MCB *p_mcb, UINT16 event, void *p_data)
68 {
69 switch (p_mcb->state)
70 {
71 case RFC_MX_STATE_IDLE:
72 rfc_mx_sm_state_idle (p_mcb, event, p_data);
73 break;
74
75 case RFC_MX_STATE_WAIT_CONN_CNF:
76 rfc_mx_sm_state_wait_conn_cnf (p_mcb, event, p_data);
77 break;
78
79 case RFC_MX_STATE_CONFIGURE:
80 rfc_mx_sm_state_configure (p_mcb, event, p_data);
81 break;
82
83 case RFC_MX_STATE_SABME_WAIT_UA:
84 rfc_mx_sm_sabme_wait_ua (p_mcb, event, p_data);
85 break;
86
87 case RFC_MX_STATE_WAIT_SABME:
88 rfc_mx_sm_state_wait_sabme (p_mcb, event, p_data);
89 break;
90
91 case RFC_MX_STATE_CONNECTED:
92 rfc_mx_sm_state_connected (p_mcb, event, p_data);
93 break;
94
95 case RFC_MX_STATE_DISC_WAIT_UA:
96 rfc_mx_sm_state_disc_wait_ua (p_mcb, event, p_data);
97 break;
98
99 }
100 }
101
102
103 /*******************************************************************************
104 **
105 ** Function rfc_mx_sm_state_idle
106 **
107 ** Description This function handles events when the multiplexer is in
108 ** IDLE state. This state exists when connection is being
109 ** initially established.
110 **
111 ** Returns void
112 **
113 *******************************************************************************/
rfc_mx_sm_state_idle(tRFC_MCB * p_mcb,UINT16 event,void * p_data)114 void rfc_mx_sm_state_idle (tRFC_MCB *p_mcb, UINT16 event, void *p_data)
115 {
116 RFCOMM_TRACE_EVENT ("rfc_mx_sm_state_idle - evt:%d", event);
117 switch (event)
118 {
119 case RFC_MX_EVENT_START_REQ:
120
121 /* Initialize L2CAP MTU */
122 p_mcb->peer_l2cap_mtu = L2CAP_DEFAULT_MTU - RFCOMM_MIN_OFFSET - 1;
123
124 if ((p_mcb->lcid = L2CA_ConnectReq (BT_PSM_RFCOMM, p_mcb->bd_addr)) == 0)
125 {
126 PORT_StartCnf (p_mcb, RFCOMM_ERROR);
127 return;
128 }
129 /* Save entry for quicker access to mcb based on the LCID */
130 rfc_save_lcid_mcb (p_mcb, p_mcb->lcid);
131
132 p_mcb->state = RFC_MX_STATE_WAIT_CONN_CNF;
133 return;
134
135 case RFC_MX_EVENT_START_RSP:
136 case RFC_MX_EVENT_CONN_CNF:
137 case RFC_MX_EVENT_CONF_IND:
138 case RFC_MX_EVENT_CONF_CNF:
139 RFCOMM_TRACE_ERROR ("Mx error state %d event %d", p_mcb->state, event);
140 return;
141
142 case RFC_MX_EVENT_CONN_IND:
143
144 rfc_timer_start (p_mcb, RFCOMM_CONN_TIMEOUT);
145 L2CA_ConnectRsp (p_mcb->bd_addr, *((UINT8 *)p_data), p_mcb->lcid, L2CAP_CONN_OK, 0);
146
147 rfc_mx_send_config_req (p_mcb);
148
149 p_mcb->state = RFC_MX_STATE_CONFIGURE;
150 return;
151
152 case RFC_EVENT_SABME:
153 break;
154
155 case RFC_EVENT_UA:
156 case RFC_EVENT_DM:
157 return;
158
159 case RFC_EVENT_DISC:
160 rfc_send_dm (p_mcb, RFCOMM_MX_DLCI, TRUE);
161 return;
162
163 case RFC_EVENT_UIH:
164 rfc_send_dm (p_mcb, RFCOMM_MX_DLCI, FALSE);
165 return;
166 }
167 RFCOMM_TRACE_EVENT ("RFCOMM MX ignored - evt:%d in state:%d", event, p_mcb->state);
168 }
169
170
171 /*******************************************************************************
172 **
173 ** Function rfc_mx_sm_state_wait_conn_cnf
174 **
175 ** Description This function handles events when the multiplexer is
176 ** waiting for Connection Confirm from L2CAP.
177 **
178 ** Returns void
179 **
180 *******************************************************************************/
rfc_mx_sm_state_wait_conn_cnf(tRFC_MCB * p_mcb,UINT16 event,void * p_data)181 void rfc_mx_sm_state_wait_conn_cnf (tRFC_MCB *p_mcb, UINT16 event, void *p_data)
182 {
183 RFCOMM_TRACE_EVENT ("rfc_mx_sm_state_wait_conn_cnf - evt:%d", event);
184 switch (event)
185 {
186 case RFC_MX_EVENT_START_REQ:
187 RFCOMM_TRACE_ERROR ("Mx error state %d event %d", p_mcb->state, event);
188 return;
189
190 /* There is some new timing so that Config Ind comes before security is completed
191 so we are still waiting fo the confirmation. */
192 case RFC_MX_EVENT_CONF_IND:
193 rfc_mx_conf_ind (p_mcb, (tL2CAP_CFG_INFO *)p_data);
194 return;
195
196 case RFC_MX_EVENT_CONN_CNF:
197 if (*((UINT16 *)p_data) != L2CAP_SUCCESS)
198 {
199 p_mcb->state = RFC_MX_STATE_IDLE;
200
201 PORT_StartCnf (p_mcb, *((UINT16 *)p_data));
202 return;
203 }
204 p_mcb->state = RFC_MX_STATE_CONFIGURE;
205 rfc_mx_send_config_req (p_mcb);
206 return;
207
208 case RFC_MX_EVENT_DISC_IND:
209 p_mcb->state = RFC_MX_STATE_IDLE;
210 PORT_CloseInd (p_mcb);
211 return;
212
213 case RFC_EVENT_TIMEOUT:
214 p_mcb->state = RFC_MX_STATE_IDLE;
215 L2CA_DisconnectReq (p_mcb->lcid);
216
217 /* we gave up outgoing connection request then try peer's request */
218 if (p_mcb->pending_lcid)
219 {
220 UINT16 i;
221 UINT8 idx;
222
223 RFCOMM_TRACE_DEBUG ("RFCOMM MX retry as acceptor in collision case - evt:%d in state:%d", event, p_mcb->state);
224
225 rfc_save_lcid_mcb (NULL, p_mcb->lcid);
226 p_mcb->lcid = p_mcb->pending_lcid;
227 rfc_save_lcid_mcb (p_mcb, p_mcb->lcid);
228
229 p_mcb->is_initiator = FALSE;
230
231 /* update direction bit */
232 for (i = 0; i < RFCOMM_MAX_DLCI; i += 2)
233 {
234 if ((idx = p_mcb->port_inx[i]) != 0)
235 {
236 p_mcb->port_inx[i] = 0;
237 p_mcb->port_inx[i+1] = idx;
238 rfc_cb.port.port[idx - 1].dlci += 1;
239 RFCOMM_TRACE_DEBUG ("RFCOMM MX - DLCI:%d -> %d", i, rfc_cb.port.port[idx - 1].dlci);
240 }
241 }
242
243 rfc_mx_sm_execute (p_mcb, RFC_MX_EVENT_CONN_IND, &(p_mcb->pending_id));
244 }
245 else
246 {
247 PORT_CloseInd (p_mcb);
248 }
249 return;
250 }
251 RFCOMM_TRACE_EVENT ("RFCOMM MX ignored - evt:%d in state:%d", event, p_mcb->state);
252 }
253
254
255 /*******************************************************************************
256 **
257 ** Function rfc_mx_sm_state_configure
258 **
259 ** Description This function handles events when the multiplexer in the
260 ** configuration state.
261 **
262 ** Returns void
263 **
264 *******************************************************************************/
rfc_mx_sm_state_configure(tRFC_MCB * p_mcb,UINT16 event,void * p_data)265 void rfc_mx_sm_state_configure (tRFC_MCB *p_mcb, UINT16 event, void *p_data)
266 {
267 RFCOMM_TRACE_EVENT ("rfc_mx_sm_state_configure - evt:%d", event);
268 switch (event)
269 {
270 case RFC_MX_EVENT_START_REQ:
271 case RFC_MX_EVENT_CONN_CNF:
272
273 RFCOMM_TRACE_ERROR ("Mx error state %d event %d", p_mcb->state, event);
274 return;
275
276 case RFC_MX_EVENT_CONF_IND:
277 rfc_mx_conf_ind (p_mcb, (tL2CAP_CFG_INFO *)p_data);
278 return;
279
280 case RFC_MX_EVENT_CONF_CNF:
281 rfc_mx_conf_cnf (p_mcb, (tL2CAP_CFG_INFO *)p_data);
282 return;
283
284 case RFC_MX_EVENT_DISC_IND:
285 p_mcb->state = RFC_MX_STATE_IDLE;
286 PORT_CloseInd (p_mcb);
287 return;
288
289 case RFC_EVENT_TIMEOUT:
290 p_mcb->state = RFC_MX_STATE_IDLE;
291 L2CA_DisconnectReq (p_mcb->lcid);
292
293 PORT_StartCnf (p_mcb, RFCOMM_ERROR);
294 return;
295 }
296 RFCOMM_TRACE_EVENT ("RFCOMM MX ignored - evt:%d in state:%d", event, p_mcb->state);
297 }
298
299
300 /*******************************************************************************
301 **
302 ** Function rfc_mx_sm_sabme_wait_ua
303 **
304 ** Description This function handles events when the multiplexer sent
305 ** SABME and is waiting for UA reply.
306 **
307 ** Returns void
308 **
309 *******************************************************************************/
rfc_mx_sm_sabme_wait_ua(tRFC_MCB * p_mcb,UINT16 event,void * p_data)310 void rfc_mx_sm_sabme_wait_ua (tRFC_MCB *p_mcb, UINT16 event, void *p_data)
311 {
312 UNUSED(p_data);
313
314 RFCOMM_TRACE_EVENT ("rfc_mx_sm_sabme_wait_ua - evt:%d", event);
315 switch (event)
316 {
317 case RFC_MX_EVENT_START_REQ:
318 case RFC_MX_EVENT_CONN_CNF:
319 RFCOMM_TRACE_ERROR ("Mx error state %d event %d", p_mcb->state, event);
320 return;
321
322 /* workaround: we don't support reconfig */
323 /* commented out until we support reconfig
324 case RFC_MX_EVENT_CONF_IND:
325 rfc_mx_conf_ind (p_mcb, (tL2CAP_CFG_INFO *)p_data);
326 return;
327
328 case RFC_MX_EVENT_CONF_CNF:
329 rfc_mx_conf_cnf (p_mcb, (tL2CAP_CFG_INFO *)p_data);
330 return;
331 */
332
333 case RFC_MX_EVENT_DISC_IND:
334 p_mcb->state = RFC_MX_STATE_IDLE;
335 PORT_CloseInd (p_mcb);
336 return;
337
338 case RFC_EVENT_UA:
339 rfc_timer_stop (p_mcb);
340
341 p_mcb->state = RFC_MX_STATE_CONNECTED;
342 p_mcb->peer_ready = TRUE;
343
344 PORT_StartCnf (p_mcb, RFCOMM_SUCCESS);
345 return;
346
347 case RFC_EVENT_DM:
348 rfc_timer_stop (p_mcb);
349 /* Case falls through */
350
351 case RFC_MX_EVENT_CONF_IND: /* workaround: we don't support reconfig */
352 case RFC_MX_EVENT_CONF_CNF: /* workaround: we don't support reconfig */
353 case RFC_EVENT_TIMEOUT:
354 p_mcb->state = RFC_MX_STATE_IDLE;
355 L2CA_DisconnectReq (p_mcb->lcid);
356
357 PORT_StartCnf (p_mcb, RFCOMM_ERROR);
358 return;
359 }
360 RFCOMM_TRACE_EVENT ("RFCOMM MX ignored - evt:%d in state:%d", event, p_mcb->state);
361 }
362
363 /*******************************************************************************
364 **
365 ** Function rfc_mx_sm_state_wait_sabme
366 **
367 ** Description This function handles events when the multiplexer is
368 ** waiting for SABME on the acceptor side after configuration
369 **
370 ** Returns void
371 **
372 *******************************************************************************/
rfc_mx_sm_state_wait_sabme(tRFC_MCB * p_mcb,UINT16 event,void * p_data)373 void rfc_mx_sm_state_wait_sabme (tRFC_MCB *p_mcb, UINT16 event, void *p_data)
374 {
375 RFCOMM_TRACE_EVENT ("rfc_mx_sm_state_wait_sabme - evt:%d", event);
376 switch (event)
377 {
378 case RFC_MX_EVENT_DISC_IND:
379 p_mcb->state = RFC_MX_STATE_IDLE;
380 PORT_CloseInd (p_mcb);
381 return;
382
383 case RFC_EVENT_SABME:
384 /* if we gave up outgoing connection request */
385 if (p_mcb->pending_lcid)
386 {
387 p_mcb->pending_lcid = 0;
388
389 rfc_send_ua (p_mcb, RFCOMM_MX_DLCI);
390
391 rfc_timer_stop (p_mcb);
392 p_mcb->state = RFC_MX_STATE_CONNECTED;
393 p_mcb->peer_ready = TRUE;
394
395 /* MX channel collision has been resolved, continue to open ports */
396 PORT_StartCnf (p_mcb, RFCOMM_SUCCESS);
397 }
398 else
399 {
400 rfc_timer_stop (p_mcb);
401 PORT_StartInd (p_mcb);
402 }
403 return;
404
405 case RFC_MX_EVENT_START_RSP:
406 if (*((UINT16 *)p_data) != RFCOMM_SUCCESS)
407 rfc_send_dm (p_mcb, RFCOMM_MX_DLCI, TRUE);
408 else
409 {
410 rfc_send_ua (p_mcb, RFCOMM_MX_DLCI);
411
412 p_mcb->state = RFC_MX_STATE_CONNECTED;
413 p_mcb->peer_ready = TRUE;
414 }
415 return;
416
417 case RFC_MX_EVENT_CONF_IND: /* workaround: we don't support reconfig */
418 case RFC_MX_EVENT_CONF_CNF: /* workaround: we don't support reconfig */
419 case RFC_EVENT_TIMEOUT:
420 p_mcb->state = RFC_MX_STATE_IDLE;
421 L2CA_DisconnectReq (p_mcb->lcid);
422
423 PORT_CloseInd (p_mcb);
424 return;
425 }
426 RFCOMM_TRACE_EVENT ("RFCOMM MX ignored - evt:%d in state:%d", event, p_mcb->state);
427 }
428
429
430 /*******************************************************************************
431 **
432 ** Function rfc_mx_sm_state_connected
433 **
434 ** Description This function handles events when the multiplexer is
435 ** in the CONNECTED state
436 **
437 ** Returns void
438 **
439 *******************************************************************************/
rfc_mx_sm_state_connected(tRFC_MCB * p_mcb,UINT16 event,void * p_data)440 void rfc_mx_sm_state_connected (tRFC_MCB *p_mcb, UINT16 event, void *p_data)
441 {
442 UNUSED(p_data);
443
444 RFCOMM_TRACE_EVENT ("rfc_mx_sm_state_connected - evt:%d", event);
445
446 switch (event)
447 {
448 case RFC_EVENT_TIMEOUT:
449 case RFC_MX_EVENT_CLOSE_REQ:
450 rfc_timer_start (p_mcb, RFC_DISC_TIMEOUT);
451 p_mcb->state = RFC_MX_STATE_DISC_WAIT_UA;
452 rfc_send_disc (p_mcb, RFCOMM_MX_DLCI);
453 return;
454
455 case RFC_MX_EVENT_DISC_IND:
456 p_mcb->state = RFC_MX_STATE_IDLE;
457 PORT_CloseInd (p_mcb);
458 return;
459
460 case RFC_EVENT_DISC:
461 /* Reply with UA. If initiator bring down L2CAP connection */
462 /* If server wait for some time if client decide to reinitiate channel */
463 rfc_send_ua (p_mcb, RFCOMM_MX_DLCI);
464 if (p_mcb->is_initiator)
465 {
466 L2CA_DisconnectReq (p_mcb->lcid);
467 }
468 /* notify all ports that connection is gone */
469 PORT_CloseInd (p_mcb);
470 return;
471 }
472 RFCOMM_TRACE_EVENT ("RFCOMM MX ignored - evt:%d in state:%d", event, p_mcb->state);
473 }
474
475
476 /*******************************************************************************
477 **
478 ** Function rfc_mx_sm_state_disc_wait_ua
479 **
480 ** Description This function handles events when the multiplexer sent
481 ** DISC and is waiting for UA reply.
482 **
483 ** Returns void
484 **
485 *******************************************************************************/
rfc_mx_sm_state_disc_wait_ua(tRFC_MCB * p_mcb,UINT16 event,void * p_data)486 void rfc_mx_sm_state_disc_wait_ua (tRFC_MCB *p_mcb, UINT16 event, void *p_data)
487 {
488 BT_HDR *p_buf;
489
490 RFCOMM_TRACE_EVENT ("rfc_mx_sm_state_disc_wait_ua - evt:%d", event);
491 switch (event)
492 {
493 case RFC_EVENT_UA:
494 case RFC_EVENT_DM:
495 case RFC_EVENT_TIMEOUT:
496 L2CA_DisconnectReq (p_mcb->lcid);
497
498 if (p_mcb->restart_required)
499 {
500 /* Start Request was received while disconnecting. Execute it again */
501 if ((p_mcb->lcid = L2CA_ConnectReq (BT_PSM_RFCOMM, p_mcb->bd_addr)) == 0)
502 {
503 PORT_StartCnf (p_mcb, RFCOMM_ERROR);
504 return;
505 }
506 /* Save entry for quicker access to mcb based on the LCID */
507 rfc_save_lcid_mcb (p_mcb, p_mcb->lcid);
508
509 /* clean up before reuse it */
510 while ((p_buf = (BT_HDR *)GKI_dequeue(&p_mcb->cmd_q)) != NULL)
511 GKI_freebuf(p_buf);
512
513 rfc_timer_start (p_mcb, RFC_MCB_INIT_INACT_TIMER);
514
515 p_mcb->is_initiator = TRUE;
516 p_mcb->restart_required = FALSE;
517 p_mcb->local_cfg_sent = FALSE;
518 p_mcb->peer_cfg_rcvd = FALSE;
519
520 p_mcb->state = RFC_MX_STATE_WAIT_CONN_CNF;
521 return;
522 }
523 rfc_release_multiplexer_channel (p_mcb);
524 return;
525
526 case RFC_EVENT_DISC:
527 rfc_send_ua (p_mcb, RFCOMM_MX_DLCI);
528 return;
529
530 case RFC_EVENT_UIH:
531 GKI_freebuf (p_data);
532 rfc_send_dm (p_mcb, RFCOMM_MX_DLCI, FALSE);
533 return;
534
535 case RFC_MX_EVENT_START_REQ:
536 p_mcb->restart_required = TRUE;
537 return;
538
539 case RFC_MX_EVENT_DISC_IND:
540 p_mcb->state = RFC_MX_STATE_IDLE;
541 PORT_CloseInd (p_mcb);
542 return;
543
544 case RFC_MX_EVENT_CLOSE_REQ:
545 return;
546
547 case RFC_MX_EVENT_QOS_VIOLATION_IND:
548 break;
549 }
550 RFCOMM_TRACE_EVENT ("RFCOMM MX ignored - evt:%d in state:%d", event, p_mcb->state);
551 }
552
553
554 /*******************************************************************************
555 **
556 ** Function rfc_mx_send_config_req
557 **
558 ** Description This function handles L2CA_ConnectInd message from the
559 ** L2CAP. Accept connection.
560 **
561 *******************************************************************************/
rfc_mx_send_config_req(tRFC_MCB * p_mcb)562 static void rfc_mx_send_config_req (tRFC_MCB *p_mcb)
563 {
564 tL2CAP_CFG_INFO cfg;
565
566 RFCOMM_TRACE_EVENT ("rfc_mx_send_config_req");
567
568 memset (&cfg, 0, sizeof (tL2CAP_CFG_INFO));
569
570 cfg.mtu_present = TRUE;
571 cfg.mtu = L2CAP_MTU_SIZE;
572
573 /* Defaults set by memset
574 cfg.flush_to_present = FALSE;
575 cfg.qos_present = FALSE;
576 cfg.fcr_present = FALSE;
577 cfg.fcr.mode = L2CAP_FCR_BASIC_MODE;
578 cfg.fcs_present = FALSE;
579 cfg.fcs = N/A when fcs_present is FALSE;
580 */
581 L2CA_ConfigReq (p_mcb->lcid, &cfg);
582 }
583
584
585 /*******************************************************************************
586 **
587 ** Function rfc_mx_conf_cnf
588 **
589 ** Description This function handles L2CA_ConfigCnf message from the
590 ** L2CAP. If result is not success tell upper layer that
591 ** start has not been accepted. If initiator send SABME
592 ** on DLCI 0. T1 is still running.
593 **
594 *******************************************************************************/
rfc_mx_conf_cnf(tRFC_MCB * p_mcb,tL2CAP_CFG_INFO * p_cfg)595 static void rfc_mx_conf_cnf (tRFC_MCB *p_mcb, tL2CAP_CFG_INFO *p_cfg)
596 {
597 RFCOMM_TRACE_EVENT ("rfc_mx_conf_cnf p_cfg:%08x res:%d ", p_cfg, (p_cfg) ? p_cfg->result : 0);
598
599 if (p_cfg->result != L2CAP_CFG_OK)
600 {
601 if (p_mcb->is_initiator)
602 {
603 PORT_StartCnf (p_mcb, p_cfg->result);
604 L2CA_DisconnectReq (p_mcb->lcid);
605 }
606 rfc_release_multiplexer_channel (p_mcb);
607 return;
608 }
609
610 p_mcb->local_cfg_sent = TRUE;
611 if ((p_mcb->state == RFC_MX_STATE_CONFIGURE) && p_mcb->peer_cfg_rcvd)
612 {
613 if (p_mcb->is_initiator)
614 {
615 p_mcb->state = RFC_MX_STATE_SABME_WAIT_UA;
616 rfc_send_sabme (p_mcb, RFCOMM_MX_DLCI);
617 rfc_timer_start (p_mcb, RFC_T1_TIMEOUT);
618 }
619 else
620 {
621 p_mcb->state = RFC_MX_STATE_WAIT_SABME;
622 rfc_timer_start (p_mcb, RFCOMM_CONN_TIMEOUT); /* - increased from T2=20 to CONN=120
623 to allow the user more than 10 sec to type in the
624 pin which can be e.g. 16 digits */
625 }
626 }
627 }
628
629
630 /*******************************************************************************
631 **
632 ** Function rfc_mx_conf_ind
633 **
634 ** Description This function handles L2CA_ConfigInd message from the
635 ** L2CAP. Send the L2CA_ConfigRsp message.
636 **
637 *******************************************************************************/
rfc_mx_conf_ind(tRFC_MCB * p_mcb,tL2CAP_CFG_INFO * p_cfg)638 static void rfc_mx_conf_ind (tRFC_MCB *p_mcb, tL2CAP_CFG_INFO *p_cfg)
639 {
640 /* Save peer L2CAP MTU if present */
641 /* RFCOMM adds 3-4 bytes in the beginning and 1 bytes FCS */
642 if (p_cfg->mtu_present)
643 p_mcb->peer_l2cap_mtu = p_cfg->mtu - RFCOMM_MIN_OFFSET - 1;
644 else
645 p_mcb->peer_l2cap_mtu = L2CAP_DEFAULT_MTU - RFCOMM_MIN_OFFSET - 1;
646
647 p_cfg->mtu_present = FALSE;
648 p_cfg->flush_to_present = FALSE;
649 p_cfg->qos_present = FALSE;
650
651 p_cfg->result = L2CAP_CFG_OK;
652
653 L2CA_ConfigRsp (p_mcb->lcid, p_cfg);
654
655 p_mcb->peer_cfg_rcvd = TRUE;
656 if ((p_mcb->state == RFC_MX_STATE_CONFIGURE) && p_mcb->local_cfg_sent)
657 {
658 if (p_mcb->is_initiator)
659 {
660 p_mcb->state = RFC_MX_STATE_SABME_WAIT_UA;
661 rfc_send_sabme (p_mcb, RFCOMM_MX_DLCI);
662 rfc_timer_start (p_mcb, RFC_T1_TIMEOUT);
663 }
664 else
665 {
666 p_mcb->state = RFC_MX_STATE_WAIT_SABME;
667 rfc_timer_start (p_mcb, RFCOMM_CONN_TIMEOUT); /* - increased from T2=20 to CONN=120
668 to allow the user more than 10 sec to type in the
669 pin which can be e.g. 16 digits */
670 }
671 }
672 }
673