/******************************************************************************* ** ** Function RFCOMM_PortNegReq ** ** Description This function is called by the user app to start ** Remote Port parameter negotiation. Port emulation can ** send this request before actually establishing the DLC. ** In this case the function will allocate RFCOMM connection ** control block. ** *******************************************************************************/ 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; } /* Send Parameter Negotiation Command UIH frame */ 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) ; }
/******************************************************************************* ** ** Function rfc_process_rpn ** ** Description This function handles Remote DLC parameter negotiation ** command/response. Pass command to the user. ** *******************************************************************************/ void rfc_process_rpn (tRFC_MCB *p_mcb, BOOLEAN is_command, BOOLEAN is_request, MX_FRAME *p_frame) { tPORT_STATE port_pars; tPORT *p_port; if ((p_port = port_find_mcb_dlci_port (p_mcb, p_frame->dlci)) == NULL) { /* This is the first command on the port */ if (is_command) { memset(&port_pars, 0, sizeof(tPORT_STATE)); rfc_set_port_state(&port_pars, p_frame); PORT_PortNegInd(p_mcb, p_frame->dlci, &port_pars, p_frame->u.rpn.param_mask); } return; } if (is_command && is_request) { /* This is the special situation when peer just request local pars */ port_pars = p_port->peer_port_pars; rfc_send_rpn (p_mcb, p_frame->dlci, FALSE, &p_port->peer_port_pars, 0); return; } port_pars = p_port->peer_port_pars; rfc_set_port_state(&port_pars, p_frame); if (is_command) { PORT_PortNegInd (p_mcb, p_frame->dlci, &port_pars, p_frame->u.rpn.param_mask); return; } /* If we are not awaiting response just ignore it */ p_port = port_find_mcb_dlci_port (p_mcb, p_frame->dlci); if ((p_port == NULL) || !(p_port->rfc.expected_rsp & (RFC_RSP_RPN | RFC_RSP_RPN_REPLY))) { return; } /* If we sent a request for port parameters to the peer he is replying with */ /* mask 0. */ rfc_port_timer_stop (p_port); if (p_port->rfc.expected_rsp & RFC_RSP_RPN_REPLY) { p_port->rfc.expected_rsp &= ~RFC_RSP_RPN_REPLY; p_port->peer_port_pars = port_pars; if ((port_pars.fc_type == (RFCOMM_FC_RTR_ON_INPUT | RFCOMM_FC_RTR_ON_OUTPUT)) || (port_pars.fc_type == (RFCOMM_FC_RTC_ON_INPUT | RFCOMM_FC_RTC_ON_OUTPUT))) { /* This is satisfactory port parameters. Set mask as it was Ok */ p_frame->u.rpn.param_mask = RFCOMM_RPN_PM_MASK; } else { /* Current peer parameters are not good, try to fix them */ p_port->peer_port_pars.fc_type = (RFCOMM_FC_RTR_ON_INPUT | RFCOMM_FC_RTR_ON_OUTPUT); p_port->rfc.expected_rsp |= RFC_RSP_RPN; rfc_send_rpn (p_mcb, p_frame->dlci, TRUE, &p_port->peer_port_pars, RFCOMM_RPN_PM_RTR_ON_INPUT | RFCOMM_RPN_PM_RTR_ON_OUTPUT); rfc_port_timer_start (p_port, RFC_T2_TIMEOUT) ; return; } } else { p_port->rfc.expected_rsp &= ~RFC_RSP_RPN; } /* Check if all suggested parameters were accepted */ if (((p_frame->u.rpn.param_mask & (RFCOMM_RPN_PM_RTR_ON_INPUT | RFCOMM_RPN_PM_RTR_ON_OUTPUT)) == (RFCOMM_RPN_PM_RTR_ON_INPUT | RFCOMM_RPN_PM_RTR_ON_OUTPUT)) || ((p_frame->u.rpn.param_mask & (RFCOMM_RPN_PM_RTC_ON_INPUT | RFCOMM_RPN_PM_RTC_ON_OUTPUT)) == (RFCOMM_RPN_PM_RTC_ON_INPUT | RFCOMM_RPN_PM_RTC_ON_OUTPUT))) { PORT_PortNegCnf (p_mcb, p_port->dlci, &port_pars, RFCOMM_SUCCESS); return; } /* If we were proposing RTR flow control try RTC flow control */ /* If we were proposing RTC flow control try no flow control */ /* otherwise drop the connection */ if (p_port->peer_port_pars.fc_type == (RFCOMM_FC_RTR_ON_INPUT | RFCOMM_FC_RTR_ON_OUTPUT)) { /* Current peer parameters are not good, try to fix them */ p_port->peer_port_pars.fc_type = (RFCOMM_FC_RTC_ON_INPUT | RFCOMM_FC_RTC_ON_OUTPUT); p_port->rfc.expected_rsp |= RFC_RSP_RPN; rfc_send_rpn (p_mcb, p_frame->dlci, TRUE, &p_port->peer_port_pars, RFCOMM_RPN_PM_RTC_ON_INPUT | RFCOMM_RPN_PM_RTC_ON_OUTPUT); rfc_port_timer_start (p_port, RFC_T2_TIMEOUT) ; return; } /* Other side does not support flow control */ if (p_port->peer_port_pars.fc_type == (RFCOMM_FC_RTC_ON_INPUT | RFCOMM_FC_RTC_ON_OUTPUT)) { p_port->peer_port_pars.fc_type = RFCOMM_FC_OFF; PORT_PortNegCnf (p_mcb, p_port->dlci, &port_pars, RFCOMM_SUCCESS); } }