123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918 |
- #include <string.h>
- #include "bt_common.h"
- #include "bt_target.h"
- #include "bt_utils.h"
- #include "btm_api.h"
- #include "btm_int.h"
- #include "osi/include/osi.h"
- #include "port_api.h"
- #include "port_int.h"
- #include "rfc_int.h"
- #include "rfcdefs.h"
- #include <set>
- #include "hci/include/btsnoop.h"
- static const std::set<uint16_t> uuid_logging_whitelist = {
- UUID_SERVCLASS_HEADSET_AUDIO_GATEWAY,
- UUID_SERVCLASS_AG_HANDSFREE,
- };
- static void rfc_port_sm_state_closed(tPORT* p_port, uint16_t event,
- void* p_data);
- static void rfc_port_sm_sabme_wait_ua(tPORT* p_port, uint16_t event,
- void* p_data);
- static void rfc_port_sm_opened(tPORT* p_port, uint16_t event, void* p_data);
- static void rfc_port_sm_orig_wait_sec_check(tPORT* p_port, uint16_t event,
- void* p_data);
- static void rfc_port_sm_term_wait_sec_check(tPORT* p_port, uint16_t event,
- void* p_data);
- static void rfc_port_sm_disc_wait_ua(tPORT* p_port, uint16_t event,
- void* p_data);
- static void rfc_port_uplink_data(tPORT* p_port, BT_HDR* p_buf);
- static void rfc_set_port_state(tPORT_STATE* port_pars, MX_FRAME* p_frame);
- void rfc_port_sm_execute(tPORT* p_port, uint16_t event, void* p_data) {
- CHECK(p_port != nullptr) << __func__ << ": NULL port event " << event;
- VLOG(1) << __func__ << ": BD_ADDR=" << p_port->bd_addr
- << ", PORT=" << std::to_string(p_port->handle)
- << ", STATE=" << std::to_string(p_port->rfc.state)
- << ", EVENT=" << event;
- switch (p_port->rfc.state) {
- case RFC_STATE_CLOSED:
- rfc_port_sm_state_closed(p_port, event, p_data);
- break;
- case RFC_STATE_SABME_WAIT_UA:
- rfc_port_sm_sabme_wait_ua(p_port, event, p_data);
- break;
- case RFC_STATE_ORIG_WAIT_SEC_CHECK:
- rfc_port_sm_orig_wait_sec_check(p_port, event, p_data);
- break;
- case RFC_STATE_TERM_WAIT_SEC_CHECK:
- rfc_port_sm_term_wait_sec_check(p_port, event, p_data);
- break;
- case RFC_STATE_OPENED:
- rfc_port_sm_opened(p_port, event, p_data);
- break;
- case RFC_STATE_DISC_WAIT_UA:
- rfc_port_sm_disc_wait_ua(p_port, event, p_data);
- break;
- }
- }
- void rfc_port_sm_state_closed(tPORT* p_port, uint16_t event, void* p_data) {
- switch (event) {
- case RFC_EVENT_OPEN:
- p_port->rfc.state = RFC_STATE_ORIG_WAIT_SEC_CHECK;
- btm_sec_mx_access_request(
- p_port->rfc.p_mcb->bd_addr, BT_PSM_RFCOMM, true, BTM_SEC_PROTO_RFCOMM,
- (uint32_t)(p_port->dlci / 2), &rfc_sec_check_complete, p_port);
- return;
- case RFC_EVENT_CLOSE:
- break;
- case RFC_EVENT_CLEAR:
- return;
- case RFC_EVENT_DATA:
- osi_free(p_data);
- break;
- case RFC_EVENT_SABME:
-
- rfc_timer_stop(p_port->rfc.p_mcb);
-
- p_port->rfc.state = RFC_STATE_TERM_WAIT_SEC_CHECK;
- btm_sec_mx_access_request(p_port->rfc.p_mcb->bd_addr, BT_PSM_RFCOMM,
- false, BTM_SEC_PROTO_RFCOMM,
- (uint32_t)(p_port->dlci / 2),
- &rfc_sec_check_complete, p_port);
- return;
- case RFC_EVENT_UA:
- return;
- case RFC_EVENT_DM:
- RFCOMM_TRACE_WARNING("%s, RFC_EVENT_DM, index=%d", __func__,
- p_port->handle);
- rfc_port_closed(p_port);
- return;
- case RFC_EVENT_UIH:
- osi_free(p_data);
- rfc_send_dm(p_port->rfc.p_mcb, p_port->dlci, false);
- return;
- case RFC_EVENT_DISC:
- rfc_send_dm(p_port->rfc.p_mcb, p_port->dlci, false);
- return;
- case RFC_EVENT_TIMEOUT:
- Port_TimeOutCloseMux(p_port->rfc.p_mcb);
- RFCOMM_TRACE_ERROR("Port error state %d event %d", p_port->rfc.state,
- event);
- return;
- }
- RFCOMM_TRACE_WARNING("Port state closed Event ignored %d", event);
- return;
- }
- void rfc_port_sm_sabme_wait_ua(tPORT* p_port, uint16_t event, void* p_data) {
- switch (event) {
- case RFC_EVENT_OPEN:
- case RFC_EVENT_ESTABLISH_RSP:
- RFCOMM_TRACE_ERROR("Port error state %d event %d", p_port->rfc.state,
- event);
- return;
- case RFC_EVENT_CLOSE:
- rfc_port_timer_start(p_port, RFC_DISC_TIMEOUT);
- rfc_send_disc(p_port->rfc.p_mcb, p_port->dlci);
- p_port->rfc.expected_rsp = 0;
- p_port->rfc.state = RFC_STATE_DISC_WAIT_UA;
- return;
- case RFC_EVENT_CLEAR:
- RFCOMM_TRACE_WARNING("%s, RFC_EVENT_CLEAR, index=%d", __func__,
- p_port->handle);
- rfc_port_closed(p_port);
- return;
- case RFC_EVENT_DATA:
- osi_free(p_data);
- break;
- case RFC_EVENT_UA:
- rfc_port_timer_stop(p_port);
- p_port->rfc.state = RFC_STATE_OPENED;
- if (uuid_logging_whitelist.find(p_port->uuid) !=
- uuid_logging_whitelist.end()) {
- btsnoop_get_interface()->whitelist_rfc_dlci(p_port->rfc.p_mcb->lcid,
- p_port->dlci);
- }
- PORT_DlcEstablishCnf(p_port->rfc.p_mcb, p_port->dlci,
- p_port->rfc.p_mcb->peer_l2cap_mtu, RFCOMM_SUCCESS);
- return;
- case RFC_EVENT_DM:
- RFCOMM_TRACE_WARNING("%s, RFC_EVENT_DM, index=%d", __func__,
- p_port->handle);
- p_port->rfc.p_mcb->is_disc_initiator = true;
- PORT_DlcEstablishCnf(p_port->rfc.p_mcb, p_port->dlci,
- p_port->rfc.p_mcb->peer_l2cap_mtu, RFCOMM_ERROR);
- rfc_port_closed(p_port);
- return;
- case RFC_EVENT_DISC:
- RFCOMM_TRACE_WARNING("%s, RFC_EVENT_DISC, index=%d", __func__,
- p_port->handle);
- rfc_send_ua(p_port->rfc.p_mcb, p_port->dlci);
- PORT_DlcEstablishCnf(p_port->rfc.p_mcb, p_port->dlci,
- p_port->rfc.p_mcb->peer_l2cap_mtu, RFCOMM_ERROR);
- rfc_port_closed(p_port);
- return;
- case RFC_EVENT_SABME:
-
- rfc_send_ua(p_port->rfc.p_mcb, p_port->dlci);
- return;
- case RFC_EVENT_UIH:
- osi_free(p_data);
- return;
- case RFC_EVENT_TIMEOUT:
- p_port->rfc.state = RFC_STATE_CLOSED;
- PORT_DlcEstablishCnf(p_port->rfc.p_mcb, p_port->dlci,
- p_port->rfc.p_mcb->peer_l2cap_mtu, RFCOMM_ERROR);
- return;
- }
- RFCOMM_TRACE_WARNING("Port state sabme_wait_ua Event ignored %d", event);
- }
- void rfc_port_sm_term_wait_sec_check(tPORT* p_port, uint16_t event,
- void* p_data) {
- switch (event) {
- case RFC_EVENT_SEC_COMPLETE:
- if (*((uint8_t*)p_data) != BTM_SUCCESS) {
-
-
- if (p_port->rfc.p_mcb) {
- rfc_send_dm(p_port->rfc.p_mcb, p_port->dlci, true);
- p_port->rfc.p_mcb->is_disc_initiator = true;
- port_rfc_closed(p_port, PORT_SEC_FAILED);
- }
- } else {
- PORT_DlcEstablishInd(p_port->rfc.p_mcb, p_port->dlci,
- p_port->rfc.p_mcb->peer_l2cap_mtu);
- }
- return;
- case RFC_EVENT_OPEN:
- case RFC_EVENT_CLOSE:
- RFCOMM_TRACE_ERROR("Port error state %d event %d", p_port->rfc.state,
- event);
- return;
- case RFC_EVENT_CLEAR:
- RFCOMM_TRACE_WARNING("%s, RFC_EVENT_CLEAR, index=%d", __func__,
- p_port->handle);
- btm_sec_abort_access_req(p_port->rfc.p_mcb->bd_addr);
- rfc_port_closed(p_port);
- return;
- case RFC_EVENT_DATA:
- RFCOMM_TRACE_ERROR("Port error state Term Wait Sec event Data");
- osi_free(p_data);
- return;
- case RFC_EVENT_SABME:
-
- return;
- case RFC_EVENT_DISC:
- btm_sec_abort_access_req(p_port->rfc.p_mcb->bd_addr);
- p_port->rfc.state = RFC_STATE_CLOSED;
- rfc_send_ua(p_port->rfc.p_mcb, p_port->dlci);
- PORT_DlcReleaseInd(p_port->rfc.p_mcb, p_port->dlci);
- return;
- case RFC_EVENT_UIH:
- osi_free(p_data);
- return;
- case RFC_EVENT_ESTABLISH_RSP:
- if (*((uint8_t*)p_data) != RFCOMM_SUCCESS) {
- if (p_port->rfc.p_mcb)
- rfc_send_dm(p_port->rfc.p_mcb, p_port->dlci, true);
- } else {
- rfc_send_ua(p_port->rfc.p_mcb, p_port->dlci);
- p_port->rfc.state = RFC_STATE_OPENED;
- if (uuid_logging_whitelist.find(p_port->uuid) !=
- uuid_logging_whitelist.end()) {
- btsnoop_get_interface()->whitelist_rfc_dlci(p_port->rfc.p_mcb->lcid,
- p_port->dlci);
- }
- }
- return;
- }
- RFCOMM_TRACE_WARNING("Port state term_wait_sec_check Event ignored %d",
- event);
- }
- void rfc_port_sm_orig_wait_sec_check(tPORT* p_port, uint16_t event,
- void* p_data) {
- switch (event) {
- case RFC_EVENT_SEC_COMPLETE:
- if (*((uint8_t*)p_data) != BTM_SUCCESS) {
- RFCOMM_TRACE_ERROR("%s, RFC_EVENT_SEC_COMPLETE, index=%d, result=%d",
- __func__, event, p_port->handle,
- *((uint8_t*)p_data));
- p_port->rfc.p_mcb->is_disc_initiator = true;
- PORT_DlcEstablishCnf(p_port->rfc.p_mcb, p_port->dlci, 0,
- RFCOMM_SECURITY_ERR);
- rfc_port_closed(p_port);
- return;
- }
- rfc_send_sabme(p_port->rfc.p_mcb, p_port->dlci);
- rfc_port_timer_start(p_port, RFC_PORT_T1_TIMEOUT);
- p_port->rfc.state = RFC_STATE_SABME_WAIT_UA;
- return;
- case RFC_EVENT_OPEN:
- case RFC_EVENT_SABME:
- RFCOMM_TRACE_ERROR("Port error state %d event %d", p_port->rfc.state,
- event);
- return;
- case RFC_EVENT_CLOSE:
- RFCOMM_TRACE_WARNING("%s, RFC_EVENT_CLOSE, index=%d", __func__,
- p_port->handle);
- btm_sec_abort_access_req(p_port->rfc.p_mcb->bd_addr);
- rfc_port_closed(p_port);
- return;
- case RFC_EVENT_DATA:
- RFCOMM_TRACE_ERROR("Port error state Orig Wait Sec event Data");
- osi_free(p_data);
- return;
- case RFC_EVENT_UIH:
- osi_free(p_data);
- return;
- }
- RFCOMM_TRACE_WARNING("Port state orig_wait_sec_check Event ignored %d",
- event);
- }
- void rfc_port_sm_opened(tPORT* p_port, uint16_t event, void* p_data) {
- switch (event) {
- case RFC_EVENT_OPEN:
- RFCOMM_TRACE_ERROR("Port error state %d event %d", p_port->rfc.state,
- event);
- return;
- case RFC_EVENT_CLOSE:
- rfc_port_timer_start(p_port, RFC_DISC_TIMEOUT);
- rfc_send_disc(p_port->rfc.p_mcb, p_port->dlci);
- p_port->rfc.expected_rsp = 0;
- p_port->rfc.state = RFC_STATE_DISC_WAIT_UA;
- return;
- case RFC_EVENT_CLEAR:
- RFCOMM_TRACE_WARNING("%s, RFC_EVENT_CLEAR, index=%d", __func__,
- p_port->handle);
- rfc_port_closed(p_port);
- return;
- case RFC_EVENT_DATA:
-
-
-
- if ((p_port->rfc.p_mcb->flow == PORT_FC_CREDIT) &&
- (((BT_HDR*)p_data)->len < p_port->peer_mtu) &&
- (!p_port->rx.user_fc) &&
- (p_port->credit_rx_max > p_port->credit_rx)) {
- ((BT_HDR*)p_data)->layer_specific =
- (uint8_t)(p_port->credit_rx_max - p_port->credit_rx);
- p_port->credit_rx = p_port->credit_rx_max;
- } else {
- ((BT_HDR*)p_data)->layer_specific = 0;
- }
- rfc_send_buf_uih(p_port->rfc.p_mcb, p_port->dlci, (BT_HDR*)p_data);
- rfc_dec_credit(p_port);
- return;
- case RFC_EVENT_UA:
- return;
- case RFC_EVENT_SABME:
- rfc_send_ua(p_port->rfc.p_mcb, p_port->dlci);
- return;
- case RFC_EVENT_DM:
- RFCOMM_TRACE_WARNING("%s, RFC_EVENT_DM, index=%d", __func__,
- p_port->handle);
- PORT_DlcReleaseInd(p_port->rfc.p_mcb, p_port->dlci);
- rfc_port_closed(p_port);
- return;
- case RFC_EVENT_DISC:
- p_port->rfc.state = RFC_STATE_CLOSED;
- rfc_send_ua(p_port->rfc.p_mcb, p_port->dlci);
- if (!fixed_queue_is_empty(p_port->rx.queue)) {
-
- RFCOMM_TRACE_DEBUG("port queue is not empty");
- rfc_port_timer_start(p_port, RFC_DISC_TIMEOUT);
- } else
- PORT_DlcReleaseInd(p_port->rfc.p_mcb, p_port->dlci);
- return;
- case RFC_EVENT_UIH:
- rfc_port_uplink_data(p_port, (BT_HDR*)p_data);
- return;
- case RFC_EVENT_TIMEOUT:
- Port_TimeOutCloseMux(p_port->rfc.p_mcb);
- RFCOMM_TRACE_ERROR("Port error state %d event %d", p_port->rfc.state,
- event);
- return;
- }
- RFCOMM_TRACE_WARNING("Port state opened Event ignored %d", event);
- }
- void rfc_port_sm_disc_wait_ua(tPORT* p_port, uint16_t event, void* p_data) {
- switch (event) {
- case RFC_EVENT_OPEN:
- case RFC_EVENT_ESTABLISH_RSP:
- RFCOMM_TRACE_ERROR("Port error state %d event %d", p_port->rfc.state,
- event);
- return;
- case RFC_EVENT_CLEAR:
- RFCOMM_TRACE_WARNING("%s, RFC_EVENT_CLEAR, index=%d", __func__, event,
- p_port->handle);
- rfc_port_closed(p_port);
- return;
- case RFC_EVENT_DATA:
- osi_free(p_data);
- return;
- case RFC_EVENT_UA:
- p_port->rfc.p_mcb->is_disc_initiator = true;
- FALLTHROUGH_INTENDED;
- case RFC_EVENT_DM:
- RFCOMM_TRACE_WARNING("%s, RFC_EVENT_DM|RFC_EVENT_UA[%d], index=%d",
- __func__, event, p_port->handle);
- rfc_port_closed(p_port);
- return;
- case RFC_EVENT_SABME:
- rfc_send_dm(p_port->rfc.p_mcb, p_port->dlci, true);
- return;
- case RFC_EVENT_DISC:
- rfc_send_dm(p_port->rfc.p_mcb, p_port->dlci, true);
- return;
- case RFC_EVENT_UIH:
- osi_free(p_data);
- rfc_send_dm(p_port->rfc.p_mcb, p_port->dlci, false);
- return;
- case RFC_EVENT_TIMEOUT:
- RFCOMM_TRACE_ERROR("%s, RFC_EVENT_TIMEOUT, index=%d", __func__,
- p_port->handle);
- rfc_port_closed(p_port);
- return;
- }
- RFCOMM_TRACE_WARNING("Port state disc_wait_ua Event ignored %d", event);
- }
- void rfc_port_uplink_data(tPORT* p_port, BT_HDR* p_buf) {
- PORT_DataInd(p_port->rfc.p_mcb, p_port->dlci, p_buf);
- }
- void rfc_process_pn(tRFC_MCB* p_mcb, bool is_command, MX_FRAME* p_frame) {
- RFCOMM_TRACE_DEBUG("%s: is_initiator=%d, is_cmd=%d, state=%d, bd_addr=%s",
- __func__, p_mcb->is_initiator, is_command, p_mcb->state,
- p_mcb->bd_addr.ToString().c_str());
- uint8_t dlci = p_frame->dlci;
- if (is_command) {
-
- if (p_mcb->state != RFC_MX_STATE_DISC_WAIT_UA) {
- PORT_ParNegInd(p_mcb, dlci, p_frame->u.pn.mtu, p_frame->u.pn.conv_layer,
- p_frame->u.pn.k);
- } else {
- LOG(WARNING) << __func__
- << ": MX PN while disconnecting, bd_addr=" << p_mcb->bd_addr
- << ", p_mcb=" << p_mcb;
- rfc_send_dm(p_mcb, dlci, false);
- }
- return;
- }
-
- tPORT* p_port = port_find_mcb_dlci_port(p_mcb, dlci);
- if ((p_port == nullptr) || !(p_port->rfc.expected_rsp & RFC_RSP_PN)) {
- LOG(WARNING) << ": Ignore unwanted response, p_mcb=" << p_mcb
- << ", bd_addr=" << p_mcb->bd_addr
- << ", dlci=" << std::to_string(dlci);
- return;
- }
- p_port->rfc.expected_rsp &= ~RFC_RSP_PN;
- rfc_port_timer_stop(p_port);
- PORT_ParNegCnf(p_mcb, dlci, p_frame->u.pn.mtu, p_frame->u.pn.conv_layer,
- p_frame->u.pn.k);
- }
- void rfc_process_rpn(tRFC_MCB* p_mcb, bool is_command, bool is_request,
- MX_FRAME* p_frame) {
- tPORT_STATE port_pars;
- tPORT* p_port;
- p_port = port_find_mcb_dlci_port(p_mcb, p_frame->dlci);
- if (p_port == nullptr) {
-
- 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) {
-
- 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;
- }
-
- p_port = port_find_mcb_dlci_port(p_mcb, p_frame->dlci);
- if ((p_port == nullptr) ||
- !(p_port->rfc.expected_rsp & (RFC_RSP_RPN | RFC_RSP_RPN_REPLY))) {
- LOG(WARNING) << __func__ << ": ignore DLC parameter negotiation as we are"
- << " not waiting for any";
- return;
- }
-
-
- 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))) {
-
- p_frame->u.rpn.param_mask = RFCOMM_RPN_PM_MASK;
- } else {
-
- 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;
-
- 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 (p_port->peer_port_pars.fc_type ==
- (RFCOMM_FC_RTR_ON_INPUT | RFCOMM_FC_RTR_ON_OUTPUT)) {
-
- 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;
- }
-
- 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);
- }
- }
- void rfc_process_msc(tRFC_MCB* p_mcb, bool is_command, MX_FRAME* p_frame) {
- tPORT_CTRL pars;
- tPORT* p_port;
- uint8_t modem_signals = p_frame->u.msc.signals;
- bool new_peer_fc = false;
- p_port = port_find_mcb_dlci_port(p_mcb, p_frame->dlci);
- if (p_port == NULL) return;
- pars.modem_signal = 0;
- if (modem_signals & RFCOMM_MSC_RTC) pars.modem_signal |= MODEM_SIGNAL_DTRDSR;
- if (modem_signals & RFCOMM_MSC_RTR) pars.modem_signal |= MODEM_SIGNAL_RTSCTS;
- if (modem_signals & RFCOMM_MSC_IC) pars.modem_signal |= MODEM_SIGNAL_RI;
- if (modem_signals & RFCOMM_MSC_DV) pars.modem_signal |= MODEM_SIGNAL_DCD;
- pars.fc = ((modem_signals & RFCOMM_MSC_FC) == RFCOMM_MSC_FC);
- pars.break_signal =
- (p_frame->u.msc.break_present) ? p_frame->u.msc.break_duration : 0;
- pars.discard_buffers = 0;
- pars.break_signal_seq = RFCOMM_CTRL_BREAK_IN_SEQ;
-
- if (is_command) {
- rfc_send_msc(p_mcb, p_frame->dlci, false, &pars);
- if (p_port->rfc.p_mcb->flow != PORT_FC_CREDIT) {
-
- p_port->peer_ctrl.fc = new_peer_fc = pars.fc;
- if (new_peer_fc != p_port->tx.peer_fc)
- PORT_FlowInd(p_mcb, p_frame->dlci, (bool)!new_peer_fc);
- }
- PORT_ControlInd(p_mcb, p_frame->dlci, &pars);
- return;
- }
-
- if (!(p_port->rfc.expected_rsp & RFC_RSP_MSC)) return;
- p_port->rfc.expected_rsp &= ~RFC_RSP_MSC;
- rfc_port_timer_stop(p_port);
- PORT_ControlCnf(p_port->rfc.p_mcb, p_port->dlci, &pars);
- }
- void rfc_process_rls(tRFC_MCB* p_mcb, bool is_command, MX_FRAME* p_frame) {
- tPORT* p_port;
- if (is_command) {
- PORT_LineStatusInd(p_mcb, p_frame->dlci, p_frame->u.rls.line_status);
- rfc_send_rls(p_mcb, p_frame->dlci, false, p_frame->u.rls.line_status);
- } else {
- p_port = port_find_mcb_dlci_port(p_mcb, p_frame->dlci);
-
- if (!p_port || !(p_port->rfc.expected_rsp & RFC_RSP_RLS)) return;
- p_port->rfc.expected_rsp &= ~RFC_RSP_RLS;
- rfc_port_timer_stop(p_port);
- }
- }
- void rfc_process_nsc(UNUSED_ATTR tRFC_MCB* p_mcb,
- UNUSED_ATTR MX_FRAME* p_frame) {}
- void rfc_process_test_rsp(UNUSED_ATTR tRFC_MCB* p_mcb, BT_HDR* p_buf) {
- osi_free(p_buf);
- }
- void rfc_process_fcon(tRFC_MCB* p_mcb, bool is_command) {
- if (is_command) {
- rfc_cb.rfc.peer_rx_disabled = false;
- rfc_send_fcon(p_mcb, false);
- if (!p_mcb->l2cap_congested) PORT_FlowInd(p_mcb, 0, true);
- }
- }
- void rfc_process_fcoff(tRFC_MCB* p_mcb, bool is_command) {
- if (is_command) {
- rfc_cb.rfc.peer_rx_disabled = true;
- if (!p_mcb->l2cap_congested) PORT_FlowInd(p_mcb, 0, false);
- rfc_send_fcoff(p_mcb, false);
- }
- }
- void rfc_process_l2cap_congestion(tRFC_MCB* p_mcb, bool is_congested) {
- p_mcb->l2cap_congested = is_congested;
- if (!is_congested) {
- rfc_check_send_cmd(p_mcb, nullptr);
- }
- if (!rfc_cb.rfc.peer_rx_disabled) {
- PORT_FlowInd(p_mcb, 0, !is_congested);
- }
- }
- void rfc_set_port_state(tPORT_STATE* port_pars, MX_FRAME* p_frame) {
- if (p_frame->u.rpn.param_mask & RFCOMM_RPN_PM_BIT_RATE)
- port_pars->baud_rate = p_frame->u.rpn.baud_rate;
- if (p_frame->u.rpn.param_mask & RFCOMM_RPN_PM_DATA_BITS)
- port_pars->byte_size = p_frame->u.rpn.byte_size;
- if (p_frame->u.rpn.param_mask & RFCOMM_RPN_PM_STOP_BITS)
- port_pars->stop_bits = p_frame->u.rpn.stop_bits;
- if (p_frame->u.rpn.param_mask & RFCOMM_RPN_PM_PARITY)
- port_pars->parity = p_frame->u.rpn.parity;
- if (p_frame->u.rpn.param_mask & RFCOMM_RPN_PM_PARITY_TYPE)
- port_pars->parity_type = p_frame->u.rpn.parity_type;
- if (p_frame->u.rpn.param_mask &
- (RFCOMM_RPN_PM_XONXOFF_ON_INPUT | RFCOMM_RPN_PM_XONXOFF_ON_OUTPUT |
- RFCOMM_RPN_PM_RTR_ON_INPUT | RFCOMM_RPN_PM_RTR_ON_OUTPUT |
- RFCOMM_RPN_PM_RTC_ON_INPUT | RFCOMM_RPN_PM_RTC_ON_OUTPUT))
- port_pars->fc_type = p_frame->u.rpn.fc_type;
- if (p_frame->u.rpn.param_mask & RFCOMM_RPN_PM_XON_CHAR)
- port_pars->xon_char = p_frame->u.rpn.xon_char;
- if (p_frame->u.rpn.param_mask & RFCOMM_RPN_PM_XOFF_CHAR)
- port_pars->xoff_char = p_frame->u.rpn.xoff_char;
- }
|