1 /******************************************************************************
3 * Copyright (C) 1999-2012 Broadcom Corporation
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:
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 ******************************************************************************/
19 /******************************************************************************
21 * This file contains state machine and action routines for a port of the
24 ******************************************************************************/
26 #include "common/bt_target.h"
27 #include "stack/rfcdefs.h"
28 #include "stack/btm_api.h"
30 #include "stack/port_api.h"
33 #include "common/bt_defs.h"
34 #include "osi/allocator.h"
35 #include "osi/mutex.h"
36 #if (defined RFCOMM_INCLUDED && RFCOMM_INCLUDED == TRUE)
38 /********************************************************************************/
39 /* L O C A L F U N C T I O N P R O T O T Y P E S */
40 /********************************************************************************/
41 static void rfc_port_sm_state_closed (tPORT *p_port, UINT16 event, void *p_data);
42 static void rfc_port_sm_sabme_wait_ua (tPORT *p_port, UINT16 event, void *p_data);
43 static void rfc_port_sm_opened (tPORT *p_port, UINT16 event, void *p_data);
44 static void rfc_port_sm_orig_wait_sec_check (tPORT *p_port, UINT16 event, void *p_data);
45 static void rfc_port_sm_term_wait_sec_check (tPORT *p_port, UINT16 event, void *p_data);
46 static void rfc_port_sm_disc_wait_ua (tPORT *p_port, UINT16 event, void *p_data);
48 static void rfc_port_uplink_data (tPORT *p_port, BT_HDR *p_buf);
50 static void rfc_set_port_state(tPORT_STATE *port_pars, MX_FRAME *p_frame);
53 /*******************************************************************************
55 ** Function rfc_port_sm_execute
57 ** Description This function sends port events through the state
62 *******************************************************************************/
63 void rfc_port_sm_execute (tPORT *p_port, UINT16 event, void *p_data)
66 RFCOMM_TRACE_WARNING ("NULL port event %d", event);
70 switch (p_port->rfc.state) {
71 case RFC_STATE_CLOSED:
72 rfc_port_sm_state_closed (p_port, event, p_data);
75 case RFC_STATE_SABME_WAIT_UA:
76 rfc_port_sm_sabme_wait_ua (p_port, event, p_data);
79 case RFC_STATE_ORIG_WAIT_SEC_CHECK:
80 rfc_port_sm_orig_wait_sec_check (p_port, event, p_data);
83 case RFC_STATE_TERM_WAIT_SEC_CHECK:
84 rfc_port_sm_term_wait_sec_check (p_port, event, p_data);
87 case RFC_STATE_OPENED:
88 rfc_port_sm_opened (p_port, event, p_data);
91 case RFC_STATE_DISC_WAIT_UA:
92 rfc_port_sm_disc_wait_ua (p_port, event, p_data);
98 /*******************************************************************************
100 ** Function rfc_port_sm_state_closed
102 ** Description This function handles events when the port is in
103 ** CLOSED state. This state exists when port is
104 ** being initially established.
108 *******************************************************************************/
109 void rfc_port_sm_state_closed (tPORT *p_port, UINT16 event, void *p_data)
113 p_port->rfc.state = RFC_STATE_ORIG_WAIT_SEC_CHECK;
114 btm_sec_mx_access_request (p_port->rfc.p_mcb->bd_addr, BT_PSM_RFCOMM, TRUE,
115 BTM_SEC_PROTO_RFCOMM, (UINT32)(p_port->dlci / 2),
116 &rfc_sec_check_complete, p_port);
119 case RFC_EVENT_CLOSE:
122 case RFC_EVENT_CLEAR:
129 case RFC_EVENT_SABME:
130 /* make sure the multiplexer disconnect timer is not running (reconnect case) */
131 rfc_timer_stop(p_port->rfc.p_mcb );
133 /* Open will be continued after security checks are passed */
134 p_port->rfc.state = RFC_STATE_TERM_WAIT_SEC_CHECK;
135 btm_sec_mx_access_request (p_port->rfc.p_mcb->bd_addr, BT_PSM_RFCOMM, FALSE,
136 BTM_SEC_PROTO_RFCOMM, (UINT32)(p_port->dlci / 2),
137 &rfc_sec_check_complete, p_port);
144 rfc_port_closed (p_port);
149 rfc_send_dm (p_port->rfc.p_mcb, p_port->dlci, FALSE);
153 rfc_send_dm (p_port->rfc.p_mcb, p_port->dlci, FALSE);
156 case RFC_EVENT_TIMEOUT:
157 Port_TimeOutCloseMux( p_port->rfc.p_mcb ) ;
158 RFCOMM_TRACE_ERROR ("Port error state %d event %d", p_port->rfc.state, event);
162 RFCOMM_TRACE_WARNING ("Port state closed Event ignored %d", event);
166 /*******************************************************************************
168 ** Function rfc_port_sm_sabme_wait_ua
170 ** Description This function handles events when SABME on the DLC was
171 ** sent and SM is waiting for UA or DM.
175 *******************************************************************************/
176 void rfc_port_sm_sabme_wait_ua (tPORT *p_port, UINT16 event, void *p_data)
180 case RFC_EVENT_ESTABLISH_RSP:
181 RFCOMM_TRACE_ERROR ("Port error state %d event %d", p_port->rfc.state, event);
184 case RFC_EVENT_CLOSE:
185 rfc_port_timer_start (p_port, RFC_DISC_TIMEOUT);
186 rfc_send_disc (p_port->rfc.p_mcb, p_port->dlci);
187 p_port->rfc.expected_rsp = 0;
188 p_port->rfc.state = RFC_STATE_DISC_WAIT_UA;
191 case RFC_EVENT_CLEAR:
192 rfc_port_closed (p_port);
200 rfc_port_timer_stop (p_port);
201 p_port->rfc.state = RFC_STATE_OPENED;
202 PORT_DlcEstablishCnf (p_port->rfc.p_mcb, p_port->dlci, p_port->rfc.p_mcb->peer_l2cap_mtu, RFCOMM_SUCCESS);
206 p_port->rfc.p_mcb->is_disc_initiator = TRUE;
207 PORT_DlcEstablishCnf (p_port->rfc.p_mcb, p_port->dlci, p_port->rfc.p_mcb->peer_l2cap_mtu, RFCOMM_ERROR);
208 rfc_port_closed (p_port);
212 rfc_send_ua (p_port->rfc.p_mcb, p_port->dlci);
213 PORT_DlcEstablishCnf (p_port->rfc.p_mcb, p_port->dlci, p_port->rfc.p_mcb->peer_l2cap_mtu, RFCOMM_ERROR);
214 rfc_port_closed (p_port);
217 case RFC_EVENT_SABME:
218 /* Continue to wait for the UA the SABME this side sent */
219 rfc_send_ua (p_port->rfc.p_mcb, p_port->dlci);
226 case RFC_EVENT_TIMEOUT:
227 p_port->rfc.state = RFC_STATE_CLOSED;
228 PORT_DlcEstablishCnf (p_port->rfc.p_mcb, p_port->dlci, p_port->rfc.p_mcb->peer_l2cap_mtu, RFCOMM_ERROR);
231 RFCOMM_TRACE_WARNING ("Port state sabme_wait_ua Event ignored %d", event);
235 /*******************************************************************************
237 ** Function rfc_port_sm_term_wait_sec_check
239 ** Description This function handles events for the port in the
240 ** WAIT_SEC_CHECK state. SABME has been received from the
241 ** peer and Security Manager verifes BD_ADDR, before we can
242 ** send ESTABLISH_IND to the Port entity
246 *******************************************************************************/
247 void rfc_port_sm_term_wait_sec_check (tPORT *p_port, UINT16 event, void *p_data)
250 case RFC_EVENT_SEC_COMPLETE:
251 if (*((UINT8 *)p_data) != BTM_SUCCESS) {
252 /* Authentication/authorization failed. If link is still */
253 /* up send DM and check if we need to start inactive timer */
254 if (p_port->rfc.p_mcb) {
255 rfc_send_dm (p_port->rfc.p_mcb, p_port->dlci, TRUE);
256 p_port->rfc.p_mcb->is_disc_initiator = TRUE;
257 port_rfc_closed (p_port, PORT_SEC_FAILED);
260 PORT_DlcEstablishInd (p_port->rfc.p_mcb, p_port->dlci, p_port->rfc.p_mcb->peer_l2cap_mtu);
265 case RFC_EVENT_CLOSE:
266 RFCOMM_TRACE_ERROR ("Port error state %d event %d", p_port->rfc.state, event);
269 case RFC_EVENT_CLEAR:
270 btm_sec_abort_access_req (p_port->rfc.p_mcb->bd_addr);
271 rfc_port_closed (p_port);
275 RFCOMM_TRACE_ERROR ("Port error state Term Wait Sec event Data");
279 case RFC_EVENT_SABME:
280 /* Ignore SABME retransmission if client dares to do so */
284 btm_sec_abort_access_req (p_port->rfc.p_mcb->bd_addr);
285 p_port->rfc.state = RFC_STATE_CLOSED;
286 rfc_send_ua (p_port->rfc.p_mcb, p_port->dlci);
288 PORT_DlcReleaseInd (p_port->rfc.p_mcb, p_port->dlci);
295 case RFC_EVENT_ESTABLISH_RSP:
296 if (*((UINT8 *)p_data) != RFCOMM_SUCCESS) {
297 if (p_port->rfc.p_mcb) {
298 rfc_send_dm (p_port->rfc.p_mcb, p_port->dlci, TRUE);
301 rfc_send_ua (p_port->rfc.p_mcb, p_port->dlci);
302 p_port->rfc.state = RFC_STATE_OPENED;
306 RFCOMM_TRACE_WARNING ("Port state term_wait_sec_check Event ignored %d", event);
310 /*******************************************************************************
312 ** Function rfc_port_sm_orig_wait_sec_check
314 ** Description This function handles events for the port in the
315 ** ORIG_WAIT_SEC_CHECK state. RFCOMM is waiting for Security
316 ** manager to finish before sending SABME to the peer
320 *******************************************************************************/
321 void rfc_port_sm_orig_wait_sec_check (tPORT *p_port, UINT16 event, void *p_data)
324 case RFC_EVENT_SEC_COMPLETE:
325 if (*((UINT8 *)p_data) != BTM_SUCCESS) {
326 p_port->rfc.p_mcb->is_disc_initiator = TRUE;
327 PORT_DlcEstablishCnf (p_port->rfc.p_mcb, p_port->dlci, 0, RFCOMM_SECURITY_ERR);
328 rfc_port_closed (p_port);
331 rfc_send_sabme (p_port->rfc.p_mcb, p_port->dlci);
332 rfc_port_timer_start (p_port, RFC_PORT_T1_TIMEOUT);
333 p_port->rfc.state = RFC_STATE_SABME_WAIT_UA;
337 case RFC_EVENT_SABME: /* Peer should not use the same dlci */
338 RFCOMM_TRACE_ERROR ("Port error state %d event %d", p_port->rfc.state, event);
341 case RFC_EVENT_CLOSE:
342 btm_sec_abort_access_req (p_port->rfc.p_mcb->bd_addr);
343 rfc_port_closed (p_port);
347 RFCOMM_TRACE_ERROR ("Port error state Orig Wait Sec event Data");
355 RFCOMM_TRACE_WARNING ("Port state orig_wait_sec_check Event ignored %d", event);
359 /*******************************************************************************
361 ** Function rfc_port_sm_opened
363 ** Description This function handles events for the port in the OPENED
368 *******************************************************************************/
369 void rfc_port_sm_opened (tPORT *p_port, UINT16 event, void *p_data)
373 RFCOMM_TRACE_ERROR ("Port error state %d event %d", p_port->rfc.state, event);
376 case RFC_EVENT_CLOSE:
377 rfc_port_timer_start (p_port, RFC_DISC_TIMEOUT);
378 rfc_send_disc (p_port->rfc.p_mcb, p_port->dlci);
379 p_port->rfc.expected_rsp = 0;
380 p_port->rfc.state = RFC_STATE_DISC_WAIT_UA;
383 case RFC_EVENT_CLEAR:
384 rfc_port_closed (p_port);
388 /* Send credits in the frame. Pass them in the layer specific member of the hdr. */
389 /* There might be an initial case when we reduced rx_max and credit_rx is still */
390 /* bigger. Make sure that we do not send 255 */
391 if ((p_port->rfc.p_mcb->flow == PORT_FC_CREDIT)
392 && (((BT_HDR *)p_data)->len < p_port->peer_mtu)
393 && (!p_port->rx.user_fc)
394 && (p_port->credit_rx_max > p_port->credit_rx)) {
395 ((BT_HDR *)p_data)->layer_specific = (UINT8) (p_port->credit_rx_max - p_port->credit_rx);
396 p_port->credit_rx = p_port->credit_rx_max;
398 ((BT_HDR *)p_data)->layer_specific = 0;
400 rfc_send_buf_uih (p_port->rfc.p_mcb, p_port->dlci, (BT_HDR *)p_data);
401 rfc_dec_credit (p_port);
407 case RFC_EVENT_SABME:
408 rfc_send_ua (p_port->rfc.p_mcb, p_port->dlci);
412 PORT_DlcReleaseInd (p_port->rfc.p_mcb, p_port->dlci);
413 rfc_port_closed (p_port);
417 p_port->rfc.state = RFC_STATE_CLOSED;
418 rfc_send_ua (p_port->rfc.p_mcb, p_port->dlci);
419 if (! fixed_queue_is_empty(p_port->rx.queue)) {
420 /* give a chance to upper stack to close port properly */
421 RFCOMM_TRACE_DEBUG("port queue is not empty");
422 rfc_port_timer_start (p_port, RFC_DISC_TIMEOUT);
424 PORT_DlcReleaseInd (p_port->rfc.p_mcb, p_port->dlci);
429 rfc_port_uplink_data (p_port, (BT_HDR *)p_data);
432 case RFC_EVENT_TIMEOUT:
433 Port_TimeOutCloseMux( p_port->rfc.p_mcb ) ;
434 RFCOMM_TRACE_ERROR ("Port error state %d event %d", p_port->rfc.state, event);
437 RFCOMM_TRACE_WARNING ("Port state opened Event ignored %d", event);
441 /*******************************************************************************
443 ** Function rfc_port_sm_disc_wait_ua
445 ** Description This function handles events when DISC on the DLC was
446 ** sent and SM is waiting for UA or DM.
450 *******************************************************************************/
451 void rfc_port_sm_disc_wait_ua (tPORT *p_port, UINT16 event, void *p_data)
455 case RFC_EVENT_ESTABLISH_RSP:
456 RFCOMM_TRACE_ERROR ("Port error state %d event %d", p_port->rfc.state, event);
459 case RFC_EVENT_CLEAR:
460 rfc_port_closed (p_port);
468 p_port->rfc.p_mcb->is_disc_initiator = TRUE;
469 /* Case falls through */
472 rfc_port_closed (p_port);
475 case RFC_EVENT_SABME:
476 rfc_send_dm (p_port->rfc.p_mcb, p_port->dlci, TRUE);
480 rfc_send_dm (p_port->rfc.p_mcb, p_port->dlci, TRUE);
485 rfc_send_dm (p_port->rfc.p_mcb, p_port->dlci, FALSE);
488 case RFC_EVENT_TIMEOUT:
489 rfc_port_closed (p_port);
493 RFCOMM_TRACE_WARNING ("Port state disc_wait_ua Event ignored %d", event);
497 /*******************************************************************************
499 ** Function rfc_port_uplink_data
501 ** Description This function handles uplink information data frame.
503 *******************************************************************************/
504 void rfc_port_uplink_data (tPORT *p_port, BT_HDR *p_buf)
506 PORT_DataInd (p_port->rfc.p_mcb, p_port->dlci, p_buf);
510 /*******************************************************************************
512 ** Function rfc_process_pn
514 ** Description This function handles DLC parameter negotiation frame.
515 ** Record MTU and pass indication to the upper layer.
517 *******************************************************************************/
518 void rfc_process_pn (tRFC_MCB *p_mcb, BOOLEAN is_command, MX_FRAME *p_frame)
521 UINT8 dlci = p_frame->dlci;
524 /* Ignore if Multiplexer is being shut down */
525 if (p_mcb->state != RFC_MX_STATE_DISC_WAIT_UA) {
526 PORT_ParNegInd (p_mcb, dlci, p_frame->u.pn.mtu,
527 p_frame->u.pn.conv_layer, p_frame->u.pn.k);
529 rfc_send_dm(p_mcb, dlci, FALSE);
530 RFCOMM_TRACE_WARNING("***** MX PN while disconnecting *****");
535 /* If we are not awaiting response just ignore it */
536 p_port = port_find_mcb_dlci_port (p_mcb, dlci);
537 if ((p_port == NULL) || !(p_port->rfc.expected_rsp & RFC_RSP_PN)) {
541 p_port->rfc.expected_rsp &= ~RFC_RSP_PN;
543 rfc_port_timer_stop (p_port);
545 PORT_ParNegCnf (p_mcb, dlci, p_frame->u.pn.mtu,
546 p_frame->u.pn.conv_layer, p_frame->u.pn.k);
550 /*******************************************************************************
552 ** Function rfc_process_rpn
554 ** Description This function handles Remote DLC parameter negotiation
555 ** command/response. Pass command to the user.
557 *******************************************************************************/
558 void rfc_process_rpn (tRFC_MCB *p_mcb, BOOLEAN is_command,
559 BOOLEAN is_request, MX_FRAME *p_frame)
561 tPORT_STATE port_pars;
564 if ((p_port = port_find_mcb_dlci_port (p_mcb, p_frame->dlci)) == NULL) {
565 /* This is the first command on the port */
568 memset(&port_pars, 0, sizeof(tPORT_STATE));
569 rfc_set_port_state(&port_pars, p_frame);
571 PORT_PortNegInd(p_mcb, p_frame->dlci, &port_pars, p_frame->u.rpn.param_mask);
576 if (is_command && is_request) {
577 /* This is the special situation when peer just request local pars */
578 port_pars = p_port->peer_port_pars;
579 rfc_send_rpn (p_mcb, p_frame->dlci, FALSE, &p_port->peer_port_pars, 0);
583 port_pars = p_port->peer_port_pars;
585 rfc_set_port_state(&port_pars, p_frame);
588 PORT_PortNegInd (p_mcb, p_frame->dlci, &port_pars, p_frame->u.rpn.param_mask);
592 /* If we are not awaiting response just ignore it */
593 p_port = port_find_mcb_dlci_port (p_mcb, p_frame->dlci);
594 if ((p_port == NULL) || !(p_port->rfc.expected_rsp & (RFC_RSP_RPN | RFC_RSP_RPN_REPLY))) {
598 /* If we sent a request for port parameters to the peer he is replying with */
600 rfc_port_timer_stop (p_port);
602 if (p_port->rfc.expected_rsp & RFC_RSP_RPN_REPLY) {
603 p_port->rfc.expected_rsp &= ~RFC_RSP_RPN_REPLY;
605 p_port->peer_port_pars = port_pars;
607 if ((port_pars.fc_type == (RFCOMM_FC_RTR_ON_INPUT | RFCOMM_FC_RTR_ON_OUTPUT))
608 || (port_pars.fc_type == (RFCOMM_FC_RTC_ON_INPUT | RFCOMM_FC_RTC_ON_OUTPUT))) {
609 /* This is satisfactory port parameters. Set mask as it was Ok */
610 p_frame->u.rpn.param_mask = RFCOMM_RPN_PM_MASK;
612 /* Current peer parameters are not good, try to fix them */
613 p_port->peer_port_pars.fc_type = (RFCOMM_FC_RTR_ON_INPUT | RFCOMM_FC_RTR_ON_OUTPUT);
615 p_port->rfc.expected_rsp |= RFC_RSP_RPN;
616 rfc_send_rpn (p_mcb, p_frame->dlci, TRUE, &p_port->peer_port_pars,
617 RFCOMM_RPN_PM_RTR_ON_INPUT | RFCOMM_RPN_PM_RTR_ON_OUTPUT);
618 rfc_port_timer_start (p_port, RFC_T2_TIMEOUT) ;
622 p_port->rfc.expected_rsp &= ~RFC_RSP_RPN;
625 /* Check if all suggested parameters were accepted */
626 if (((p_frame->u.rpn.param_mask & (RFCOMM_RPN_PM_RTR_ON_INPUT | RFCOMM_RPN_PM_RTR_ON_OUTPUT)) ==
627 (RFCOMM_RPN_PM_RTR_ON_INPUT | RFCOMM_RPN_PM_RTR_ON_OUTPUT))
628 || ((p_frame->u.rpn.param_mask & (RFCOMM_RPN_PM_RTC_ON_INPUT | RFCOMM_RPN_PM_RTC_ON_OUTPUT)) ==
629 (RFCOMM_RPN_PM_RTC_ON_INPUT | RFCOMM_RPN_PM_RTC_ON_OUTPUT))) {
630 PORT_PortNegCnf (p_mcb, p_port->dlci, &port_pars, RFCOMM_SUCCESS);
634 /* If we were proposing RTR flow control try RTC flow control */
635 /* If we were proposing RTC flow control try no flow control */
636 /* otherwise drop the connection */
637 if (p_port->peer_port_pars.fc_type == (RFCOMM_FC_RTR_ON_INPUT | RFCOMM_FC_RTR_ON_OUTPUT)) {
638 /* Current peer parameters are not good, try to fix them */
639 p_port->peer_port_pars.fc_type = (RFCOMM_FC_RTC_ON_INPUT | RFCOMM_FC_RTC_ON_OUTPUT);
641 p_port->rfc.expected_rsp |= RFC_RSP_RPN;
643 rfc_send_rpn (p_mcb, p_frame->dlci, TRUE, &p_port->peer_port_pars,
644 RFCOMM_RPN_PM_RTC_ON_INPUT | RFCOMM_RPN_PM_RTC_ON_OUTPUT);
645 rfc_port_timer_start (p_port, RFC_T2_TIMEOUT) ;
649 /* Other side does not support flow control */
650 if (p_port->peer_port_pars.fc_type == (RFCOMM_FC_RTC_ON_INPUT | RFCOMM_FC_RTC_ON_OUTPUT)) {
651 p_port->peer_port_pars.fc_type = RFCOMM_FC_OFF;
652 PORT_PortNegCnf (p_mcb, p_port->dlci, &port_pars, RFCOMM_SUCCESS);
657 /*******************************************************************************
659 ** Function rfc_process_msc
661 ** Description This function handles Modem Status Command.
662 ** Pass command to the user.
664 *******************************************************************************/
665 void rfc_process_msc (tRFC_MCB *p_mcb, BOOLEAN is_command, MX_FRAME *p_frame)
669 UINT8 modem_signals = p_frame->u.msc.signals;
670 BOOLEAN new_peer_fc = FALSE;
672 p_port = port_find_mcb_dlci_port (p_mcb, p_frame->dlci);
673 if (p_port == NULL) {
677 pars.modem_signal = 0;
679 if (modem_signals & RFCOMM_MSC_RTC) {
680 pars.modem_signal |= MODEM_SIGNAL_DTRDSR;
683 if (modem_signals & RFCOMM_MSC_RTR) {
684 pars.modem_signal |= MODEM_SIGNAL_RTSCTS;
687 if (modem_signals & RFCOMM_MSC_IC) {
688 pars.modem_signal |= MODEM_SIGNAL_RI;
691 if (modem_signals & RFCOMM_MSC_DV) {
692 pars.modem_signal |= MODEM_SIGNAL_DCD;
695 pars.fc = ((modem_signals & RFCOMM_MSC_FC) == RFCOMM_MSC_FC);
697 pars.break_signal = (p_frame->u.msc.break_present) ?
698 p_frame->u.msc.break_duration : 0;
699 pars.discard_buffers = 0;
700 pars.break_signal_seq = RFCOMM_CTRL_BREAK_IN_SEQ; /* this is default */
702 /* Check if this command is passed only to indicate flow control */
704 rfc_send_msc (p_mcb, p_frame->dlci, FALSE, &pars);
706 if (p_port->rfc.p_mcb->flow != PORT_FC_CREDIT) {
707 /* Spec 1.1 indicates that only FC bit is used for flow control */
708 p_port->peer_ctrl.fc = new_peer_fc = pars.fc;
710 if (new_peer_fc != p_port->tx.peer_fc) {
711 PORT_FlowInd (p_mcb, p_frame->dlci, (BOOLEAN)!new_peer_fc);
715 PORT_ControlInd (p_mcb, p_frame->dlci, &pars);
720 /* If we are not awaiting response just ignore it */
721 if (!(p_port->rfc.expected_rsp & RFC_RSP_MSC)) {
725 p_port->rfc.expected_rsp &= ~RFC_RSP_MSC;
727 rfc_port_timer_stop (p_port);
729 PORT_ControlCnf (p_port->rfc.p_mcb, p_port->dlci, &pars);
733 /*******************************************************************************
735 ** Function rfc_process_rls
737 ** Description This function handles Remote Line Status command.
738 ** Pass command to the user.
740 *******************************************************************************/
741 void rfc_process_rls (tRFC_MCB *p_mcb, BOOLEAN is_command, MX_FRAME *p_frame)
746 PORT_LineStatusInd (p_mcb, p_frame->dlci, p_frame->u.rls.line_status);
747 rfc_send_rls (p_mcb, p_frame->dlci, FALSE, p_frame->u.rls.line_status);
749 p_port = port_find_mcb_dlci_port (p_mcb, p_frame->dlci);
751 /* If we are not awaiting response just ignore it */
752 if (!p_port || !(p_port->rfc.expected_rsp & RFC_RSP_RLS)) {
756 p_port->rfc.expected_rsp &= ~RFC_RSP_RLS;
758 rfc_port_timer_stop (p_port);
763 /*******************************************************************************
765 ** Function rfc_process_nsc
767 ** Description This function handles None Supported Command frame.
769 *******************************************************************************/
770 void rfc_process_nsc (tRFC_MCB *p_mcb, MX_FRAME *p_frame)
777 /*******************************************************************************
779 ** Function rfc_process_test
781 ** Description This function handles Test frame. If this is a command
782 ** reply to it. Otherwise pass response to the user.
784 *******************************************************************************/
785 void rfc_process_test_rsp (tRFC_MCB *p_mcb, BT_HDR *p_buf)
793 /*******************************************************************************
795 ** Function rfc_process_fcon
797 ** Description This function handles FCON frame. The peer entity is able
798 ** to receive new information
800 *******************************************************************************/
801 void rfc_process_fcon (tRFC_MCB *p_mcb, BOOLEAN is_command)
804 rfc_cb.rfc.peer_rx_disabled = FALSE;
806 rfc_send_fcon (p_mcb, FALSE);
808 if (!p_mcb->l2cap_congested) {
809 PORT_FlowInd (p_mcb, 0, TRUE);
814 /*******************************************************************************
816 ** Function rfc_process_fcoff
818 ** Description This function handles FCOFF frame. The peer entity is unable
819 ** to receive new information
821 *******************************************************************************/
822 void rfc_process_fcoff (tRFC_MCB *p_mcb, BOOLEAN is_command)
825 rfc_cb.rfc.peer_rx_disabled = TRUE;
827 if (!p_mcb->l2cap_congested) {
828 PORT_FlowInd (p_mcb, 0, FALSE);
831 rfc_send_fcoff (p_mcb, FALSE);
836 /*******************************************************************************
838 ** Function rfc_process_l2cap_congestion
840 ** Description This function handles L2CAP congestion messages
842 *******************************************************************************/
843 void rfc_process_l2cap_congestion (tRFC_MCB *p_mcb, BOOLEAN is_congested)
845 p_mcb->l2cap_congested = is_congested;
848 rfc_check_send_cmd(p_mcb, NULL);
851 if (!rfc_cb.rfc.peer_rx_disabled) {
853 PORT_FlowInd (p_mcb, 0, TRUE);
855 PORT_FlowInd (p_mcb, 0, FALSE);
860 /*******************************************************************************
862 ** Function rfc_set_port_pars
864 ** Description This function sets the tPORT_STATE structure given a p_frame.
866 *******************************************************************************/
868 void rfc_set_port_state(tPORT_STATE *port_pars, MX_FRAME *p_frame)
870 if (p_frame->u.rpn.param_mask & RFCOMM_RPN_PM_BIT_RATE) {
871 port_pars->baud_rate = p_frame->u.rpn.baud_rate;
873 if (p_frame->u.rpn.param_mask & RFCOMM_RPN_PM_DATA_BITS) {
874 port_pars->byte_size = p_frame->u.rpn.byte_size;
876 if (p_frame->u.rpn.param_mask & RFCOMM_RPN_PM_STOP_BITS) {
877 port_pars->stop_bits = p_frame->u.rpn.stop_bits;
879 if (p_frame->u.rpn.param_mask & RFCOMM_RPN_PM_PARITY) {
880 port_pars->parity = p_frame->u.rpn.parity;
882 if (p_frame->u.rpn.param_mask & RFCOMM_RPN_PM_PARITY_TYPE) {
883 port_pars->parity_type = p_frame->u.rpn.parity_type;
885 if (p_frame->u.rpn.param_mask & (RFCOMM_RPN_PM_XONXOFF_ON_INPUT |
886 RFCOMM_RPN_PM_XONXOFF_ON_OUTPUT |
887 RFCOMM_RPN_PM_RTR_ON_INPUT |
888 RFCOMM_RPN_PM_RTR_ON_OUTPUT |
889 RFCOMM_RPN_PM_RTC_ON_INPUT |
890 RFCOMM_RPN_PM_RTC_ON_OUTPUT)) {
891 port_pars->fc_type = p_frame->u.rpn.fc_type;
893 if (p_frame->u.rpn.param_mask & RFCOMM_RPN_PM_XON_CHAR) {
894 port_pars->xon_char = p_frame->u.rpn.xon_char;
896 if (p_frame->u.rpn.param_mask & RFCOMM_RPN_PM_XOFF_CHAR) {
897 port_pars->xoff_char = p_frame->u.rpn.xoff_char;
901 #endif ///(defined RFCOMM_INCLUDED && RFCOMM_INCLUDED == TRUE)