From 1979fa31d2e9aa7dfe7380327fbddebfffd0cda4 Mon Sep 17 00:00:00 2001 From: Jakub Pawlowski Date: Fri, 16 Jun 2017 10:46:47 -0700 Subject: [PATCH] Replace BD_ADDR with bt_bdaddr_t in RFCOMM related code Test: compilation test Change-Id: I591049f0f4ea9fa60b1b9f0271e1a906a2a06f30 --- bta/ag/bta_ag_act.cc | 7 +++---- bta/ag/bta_ag_rfc.cc | 4 ++-- bta/hf_client/bta_hf_client_act.cc | 7 +++---- bta/hf_client/bta_hf_client_rfc.cc | 7 +++---- bta/jv/bta_jv_act.cc | 13 ++++++------- stack/include/bt_types.h | 4 +++- stack/include/port_api.h | 8 ++++---- stack/rfcomm/port_api.cc | 25 ++++++++++++------------- stack/rfcomm/port_int.h | 10 +++++----- stack/rfcomm/port_rfc.cc | 8 +++----- stack/rfcomm/port_utils.cc | 35 ++++++++++++++--------------------- stack/rfcomm/rfc_int.h | 3 ++- stack/rfcomm/rfc_l2cap_if.cc | 6 +++--- stack/rfcomm/rfc_mx_fsm.cc | 10 ++++------ stack/rfcomm/rfc_port_fsm.cc | 19 +++++++++---------- stack/rfcomm/rfc_utils.cc | 20 ++++++++------------ 16 files changed, 84 insertions(+), 102 deletions(-) diff --git a/bta/ag/bta_ag_act.cc b/bta/ag/bta_ag_act.cc index 146b970e1..4179a57ed 100644 --- a/bta/ag/bta_ag_act.cc +++ b/bta/ag/bta_ag_act.cc @@ -181,7 +181,7 @@ void bta_ag_start_dereg(tBTA_AG_SCB* p_scb, tBTA_AG_DATA* p_data) { * ******************************************************************************/ void bta_ag_start_open(tBTA_AG_SCB* p_scb, tBTA_AG_DATA* p_data) { - BD_ADDR pending_bd_addr; + bt_bdaddr_t pending_bd_addr; /* store parameters */ if (p_data) { @@ -511,9 +511,8 @@ void bta_ag_rfc_acp_open(tBTA_AG_SCB* p_scb, tBTA_AG_DATA* p_data) { p_scb->serv_handle[0], p_scb->serv_handle[1]); /* get bd addr of peer */ - if (PORT_SUCCESS != - (status = PORT_CheckConnection(p_data->rfc.port_handle, - to_BD_ADDR(dev_addr), &lcid))) { + if (PORT_SUCCESS != (status = PORT_CheckConnection(p_data->rfc.port_handle, + dev_addr, &lcid))) { APPL_TRACE_DEBUG( "bta_ag_rfc_acp_open error PORT_CheckConnection returned status %d", status); diff --git a/bta/ag/bta_ag_rfc.cc b/bta/ag/bta_ag_rfc.cc index 5707ec3ef..98d20c4a7 100644 --- a/bta/ag/bta_ag_rfc.cc +++ b/bta/ag/bta_ag_rfc.cc @@ -274,7 +274,7 @@ void bta_ag_start_servers(tBTA_AG_SCB* p_scb, tBTA_SERVICE_MASK services) { bta_ag_port_status = RFCOMM_CreateConnection( bta_ag_uuid[i], bta_ag_cb.profile[i].scn, true, BTA_AG_MTU, - (uint8_t*)bd_addr_any, &(p_scb->serv_handle[i]), + from_BD_ADDR(bd_addr_any), &(p_scb->serv_handle[i]), bta_ag_mgmt_cback_tbl[bta_ag_scb_to_idx(p_scb) - 1]); if (bta_ag_port_status == PORT_SUCCESS) { @@ -350,7 +350,7 @@ void bta_ag_rfc_do_open(tBTA_AG_SCB* p_scb, tBTA_AG_DATA* p_data) { if (RFCOMM_CreateConnection( bta_ag_uuid[p_scb->conn_service], p_scb->peer_scn, false, BTA_AG_MTU, - to_BD_ADDR(p_scb->peer_addr), &(p_scb->conn_handle), + p_scb->peer_addr, &(p_scb->conn_handle), bta_ag_mgmt_cback_tbl[bta_ag_scb_to_idx(p_scb) - 1]) == PORT_SUCCESS) { bta_ag_setup_port(p_scb, p_scb->conn_handle); diff --git a/bta/hf_client/bta_hf_client_act.cc b/bta/hf_client/bta_hf_client_act.cc index 84c8da3ac..cc143aedb 100644 --- a/bta/hf_client/bta_hf_client_act.cc +++ b/bta/hf_client/bta_hf_client_act.cc @@ -104,7 +104,7 @@ void bta_hf_client_start_open(tBTA_HF_CLIENT_DATA* p_data) { /* Check if RFCOMM has any incoming connection to avoid collision. */ bt_bdaddr_t pending_bd_addr; - if (PORT_IsOpening(to_BD_ADDR(pending_bd_addr))) { + if (PORT_IsOpening(pending_bd_addr)) { /* Let the incoming connection goes through. */ /* Issue collision for now. */ /* We will decide what to do when we find incoming connection later.*/ @@ -176,9 +176,8 @@ void bta_hf_client_rfc_acp_open(tBTA_HF_CLIENT_DATA* p_data) { APPL_TRACE_DEBUG("%s: conn_handle %d", __func__, client_cb->conn_handle); /* get bd addr of peer */ - if (PORT_SUCCESS != - (status = PORT_CheckConnection(client_cb->conn_handle, - to_BD_ADDR(dev_addr), &lcid))) { + if (PORT_SUCCESS != (status = PORT_CheckConnection(client_cb->conn_handle, + dev_addr, &lcid))) { APPL_TRACE_DEBUG("%s: error PORT_CheckConnection returned status %d", __func__, status); } diff --git a/bta/hf_client/bta_hf_client_rfc.cc b/bta/hf_client/bta_hf_client_rfc.cc index ea997d2d8..dfb04a31d 100644 --- a/bta/hf_client/bta_hf_client_rfc.cc +++ b/bta/hf_client/bta_hf_client_rfc.cc @@ -100,7 +100,7 @@ static void bta_hf_client_mgmt_cback(uint32_t code, uint16_t port_handle) { // Find the BDADDR of the peer device bt_bdaddr_t peer_addr; uint16_t lcid; - PORT_CheckConnection(port_handle, to_BD_ADDR(peer_addr), &lcid); + PORT_CheckConnection(port_handle, peer_addr, &lcid); // Since we accepted a remote request we should allocate a handle first. uint16_t tmp_handle = -1; @@ -179,7 +179,7 @@ void bta_hf_client_start_server() { port_status = RFCOMM_CreateConnection( UUID_SERVCLASS_HF_HANDSFREE, bta_hf_client_cb_arr.scn, true, - BTA_HF_CLIENT_MTU, (uint8_t*)bd_addr_any, + BTA_HF_CLIENT_MTU, from_BD_ADDR(bd_addr_any), &(bta_hf_client_cb_arr.serv_handle), bta_hf_client_mgmt_cback); APPL_TRACE_DEBUG("%s: started rfcomm server with handle %d", __func__, @@ -238,8 +238,7 @@ void bta_hf_client_rfc_do_open(tBTA_HF_CLIENT_DATA* p_data) { client_cb->cli_sec_mask, BT_PSM_RFCOMM, BTM_SEC_PROTO_RFCOMM, client_cb->peer_scn); if (RFCOMM_CreateConnection(UUID_SERVCLASS_HF_HANDSFREE, client_cb->peer_scn, - false, BTA_HF_CLIENT_MTU, - to_BD_ADDR(client_cb->peer_addr), + false, BTA_HF_CLIENT_MTU, client_cb->peer_addr, &(client_cb->conn_handle), bta_hf_client_mgmt_cback) == PORT_SUCCESS) { bta_hf_client_setup_port(client_cb->conn_handle); diff --git a/bta/jv/bta_jv_act.cc b/bta/jv/bta_jv_act.cc index 959c5f6c6..9c2c4e71f 100644 --- a/bta/jv/bta_jv_act.cc +++ b/bta/jv/bta_jv_act.cc @@ -515,7 +515,7 @@ static tBTA_JV_PM_CB* bta_jv_alloc_set_pm_profile_cb(uint32_t jv_handle, pp_cb = &bta_jv_cb.port_cb[j].p_pm_cb; if (PORT_SUCCESS != PORT_CheckConnection(bta_jv_cb.port_cb[j].port_handle, - to_BD_ADDR(peer_bd_addr), NULL)) + peer_bd_addr, NULL)) i = BTA_JV_PM_MAX_NUM; break; } @@ -1440,7 +1440,7 @@ static void bta_jv_port_mgmt_cl_cback(uint32_t code, uint16_t port_handle) { APPL_TRACE_DEBUG("bta_jv_port_mgmt_cl_cback code=%d port_handle:%d handle:%d", code, port_handle, p_cb->handle); - PORT_CheckConnection(port_handle, to_BD_ADDR(rem_bda), &lcid); + PORT_CheckConnection(port_handle, rem_bda, &lcid); if (code == PORT_SUCCESS) { evt_data.rfc_open.handle = p_cb->handle; @@ -1540,8 +1540,7 @@ void bta_jv_rfcomm_connect(tBTA_JV_MSG* p_data) { if (evt_data.status == BTA_JV_SUCCESS && RFCOMM_CreateConnection(UUID_SERVCLASS_SERIAL_PORT, cc->remote_scn, false, - BTA_JV_DEF_RFC_MTU, to_BD_ADDR(cc->peer_bd_addr), - &handle, + BTA_JV_DEF_RFC_MTU, cc->peer_bd_addr, &handle, bta_jv_port_mgmt_cl_cback) != PORT_SUCCESS) { APPL_TRACE_ERROR("bta_jv_rfcomm_connect, RFCOMM_CreateConnection failed"); evt_data.status = BTA_JV_FAILURE; @@ -1657,7 +1656,7 @@ static void bta_jv_port_mgmt_sr_cback(uint32_t code, uint16_t port_handle) { "p_pcb:%p, user:%d", code, port_handle, p_cb->handle, p_pcb, p_pcb->rfcomm_slot_id); - PORT_CheckConnection(port_handle, to_BD_ADDR(rem_bda), &lcid); + PORT_CheckConnection(port_handle, rem_bda, &lcid); int failed = true; if (code == PORT_SUCCESS) { evt_data.rfc_srv_open.handle = p_pcb->handle; @@ -1787,7 +1786,7 @@ static tBTA_JV_PCB* bta_jv_add_rfc_port(tBTA_JV_RFC_CB* p_cb, if (used < p_cb->max_sess && listen == 1 && si) { si--; if (RFCOMM_CreateConnection(p_cb->sec_id, p_cb->scn, true, - BTA_JV_DEF_RFC_MTU, (uint8_t*)bd_addr_any, + BTA_JV_DEF_RFC_MTU, from_BD_ADDR(bd_addr_any), &(p_cb->rfc_hdl[si]), bta_jv_port_mgmt_sr_cback) == PORT_SUCCESS) { p_cb->curr_sess++; @@ -1860,7 +1859,7 @@ void bta_jv_rfcomm_start_server(tBTA_JV_MSG* p_data) { } if (RFCOMM_CreateConnection(sec_id, rs->local_scn, true, BTA_JV_DEF_RFC_MTU, - (uint8_t*)bd_addr_any, &handle, + from_BD_ADDR(bd_addr_any), &handle, bta_jv_port_mgmt_sr_cback) != PORT_SUCCESS) { APPL_TRACE_ERROR( "bta_jv_rfcomm_start_server, RFCOMM_CreateConnection failed"); diff --git a/stack/include/bt_types.h b/stack/include/bt_types.h index 363718f1c..7970719b0 100644 --- a/stack/include/bt_types.h +++ b/stack/include/bt_types.h @@ -567,7 +567,9 @@ inline std::ostream& operator<<(std::ostream& os, const bt_bdaddr_t& a) { inline uint8_t* to_BD_ADDR(const bt_bdaddr_t& a) { return const_cast((const uint8_t*)a.address); } -inline const bt_bdaddr_t& from_BD_ADDR(BD_ADDR a) { return (bt_bdaddr_t&)*a; } +inline const bt_bdaddr_t& from_BD_ADDR(const BD_ADDR a) { + return (bt_bdaddr_t&)*a; +} #endif diff --git a/stack/include/port_api.h b/stack/include/port_api.h index ac7aeab0f..92ddb2119 100644 --- a/stack/include/port_api.h +++ b/stack/include/port_api.h @@ -196,7 +196,7 @@ typedef void(tPORT_CALLBACK)(uint32_t code, uint16_t port_handle); * the peer device (client). * is_server - true if requesting application is a server * mtu - Maximum frame size the application can accept - * bd_addr - BD_ADDR of the peer (client) + * bd_addr - address of the peer (client) * mask - specifies events to be enabled. A value * of zero disables all events. * p_handle - OUT pointer to the handle. @@ -214,7 +214,7 @@ typedef void(tPORT_CALLBACK)(uint32_t code, uint16_t port_handle); * ******************************************************************************/ extern int RFCOMM_CreateConnection(uint16_t uuid, uint8_t scn, bool is_server, - uint16_t mtu, BD_ADDR bd_addr, + uint16_t mtu, const bt_bdaddr_t& bd_addr, uint16_t* p_handle, tPORT_CALLBACK* p_mgmt_cb); @@ -309,7 +309,7 @@ extern int PORT_SetEventMask(uint16_t port_handle, uint32_t mask); * p_lcid - OUT L2CAP's LCID * ******************************************************************************/ -extern int PORT_CheckConnection(uint16_t handle, BD_ADDR bd_addr, +extern int PORT_CheckConnection(uint16_t handle, bt_bdaddr_t& bd_addr, uint16_t* p_lcid); /******************************************************************************* @@ -323,7 +323,7 @@ extern int PORT_CheckConnection(uint16_t handle, BD_ADDR bd_addr, * bd_addr - bd_addr of the peer * ******************************************************************************/ -extern bool PORT_IsOpening(BD_ADDR bd_addr); +extern bool PORT_IsOpening(bt_bdaddr_t& bd_addr); /******************************************************************************* * diff --git a/stack/rfcomm/port_api.cc b/stack/rfcomm/port_api.cc index de4cf0b1a..6988b2f2a 100644 --- a/stack/rfcomm/port_api.cc +++ b/stack/rfcomm/port_api.cc @@ -24,6 +24,7 @@ #define LOG_TAG "bt_port_api" +#include #include #include "osi/include/log.h" @@ -94,7 +95,7 @@ static const char* result_code_strings[] = {"Success", * the peer device (client). * is_server - true if requesting application is a server * mtu - Maximum frame size the application can accept - * bd_addr - BD_ADDR of the peer (client) + * bd_addr - address of the peer (client) * mask - specifies events to be enabled. A value * of zero disables all events. * p_handle - OUT pointer to the handle. @@ -112,17 +113,14 @@ static const char* result_code_strings[] = {"Success", * ******************************************************************************/ int RFCOMM_CreateConnection(uint16_t uuid, uint8_t scn, bool is_server, - uint16_t mtu, BD_ADDR bd_addr, uint16_t* p_handle, - tPORT_CALLBACK* p_mgmt_cb) { + uint16_t mtu, const bt_bdaddr_t& bd_addr, + uint16_t* p_handle, tPORT_CALLBACK* p_mgmt_cb) { tPORT* p_port; - int i; uint8_t dlci; tRFC_MCB* p_mcb = port_find_mcb(bd_addr); uint16_t rfcomm_mtu; - RFCOMM_TRACE_API( - "RFCOMM_CreateConnection() BDA: %02x-%02x-%02x-%02x-%02x-%02x", - bd_addr[0], bd_addr[1], bd_addr[2], bd_addr[3], bd_addr[4], bd_addr[5]); + VLOG(0) << __func__ << " BDA: " << bd_addr; *p_handle = 0; @@ -228,7 +226,7 @@ int RFCOMM_CreateConnection(uint16_t uuid, uint8_t scn, bool is_server, p_port->p_mgmt_callback = p_mgmt_cb; - for (i = 0; i < BD_ADDR_LEN; i++) p_port->bd_addr[i] = bd_addr[i]; + p_port->bd_addr = bd_addr; /* If this is not initiator of the connection need to just wait */ if (p_port->is_server) { @@ -482,7 +480,8 @@ int PORT_SetEventMask(uint16_t port_handle, uint32_t mask) { * p_lcid - OUT L2CAP's LCID * ******************************************************************************/ -int PORT_CheckConnection(uint16_t handle, BD_ADDR bd_addr, uint16_t* p_lcid) { +int PORT_CheckConnection(uint16_t handle, bt_bdaddr_t& bd_addr, + uint16_t* p_lcid) { tPORT* p_port; RFCOMM_TRACE_API("PORT_CheckConnection() handle:%d", handle); @@ -503,7 +502,7 @@ int PORT_CheckConnection(uint16_t handle, BD_ADDR bd_addr, uint16_t* p_lcid) { return (PORT_LINE_ERR); } - memcpy(bd_addr, p_port->rfc.p_mcb->bd_addr, BD_ADDR_LEN); + bd_addr = p_port->rfc.p_mcb->bd_addr; if (p_lcid) *p_lcid = p_port->rfc.p_mcb->lcid; return (PORT_SUCCESS); @@ -520,7 +519,7 @@ int PORT_CheckConnection(uint16_t handle, BD_ADDR bd_addr, uint16_t* p_lcid) { * bd_addr - bd_addr of the peer * ******************************************************************************/ -bool PORT_IsOpening(BD_ADDR bd_addr) { +bool PORT_IsOpening(bt_bdaddr_t& bd_addr) { uint8_t xx, yy; tRFC_MCB* p_mcb = NULL; tPORT* p_port; @@ -530,7 +529,7 @@ bool PORT_IsOpening(BD_ADDR bd_addr) { for (xx = 0; xx < MAX_BD_CONNECTIONS; xx++) { if ((rfc_cb.port.rfc_mcb[xx].state > RFC_MX_STATE_IDLE) && (rfc_cb.port.rfc_mcb[xx].state < RFC_MX_STATE_CONNECTED)) { - memcpy(bd_addr, rfc_cb.port.rfc_mcb[xx].bd_addr, BD_ADDR_LEN); + bd_addr = rfc_cb.port.rfc_mcb[xx].bd_addr; return true; } @@ -549,7 +548,7 @@ bool PORT_IsOpening(BD_ADDR bd_addr) { if ((!found_port) || (found_port && (p_port->rfc.state < RFC_STATE_OPENED))) { /* Port is not established yet. */ - memcpy(bd_addr, rfc_cb.port.rfc_mcb[xx].bd_addr, BD_ADDR_LEN); + bd_addr = rfc_cb.port.rfc_mcb[xx].bd_addr; return true; } } diff --git a/stack/rfcomm/port_int.h b/stack/rfcomm/port_int.h index 8534e302e..532db430e 100644 --- a/stack/rfcomm/port_int.h +++ b/stack/rfcomm/port_int.h @@ -92,7 +92,7 @@ typedef struct { fixed_queue_t* cmd_q; /* Queue for command messages on this mux */ uint8_t port_inx[RFCOMM_MAX_DLCI + 1]; /* Array for quick access to */ /* tPORT based on dlci */ - BD_ADDR bd_addr; /* BD ADDR of the peer if initiator */ + bt_bdaddr_t bd_addr; /* BD ADDR of the peer if initiator */ uint16_t lcid; /* Local cid used for this channel */ uint16_t peer_l2cap_mtu; /* Max frame that can be sent to peer L2CAP */ uint8_t state; /* Current multiplexer channel state */ @@ -152,7 +152,7 @@ typedef struct { uint8_t scn; /* Service channel number */ uint16_t uuid; /* Service UUID */ - BD_ADDR bd_addr; /* BD ADDR of the device for the multiplexer channel */ + bt_bdaddr_t bd_addr; /* BD ADDR of the device for the multiplexer channel */ bool is_server; /* true if the server application */ uint8_t dlci; /* DLCI of the connection */ @@ -215,14 +215,14 @@ typedef struct { /* * Functions provided by the port_utils.cc */ -extern tPORT* port_allocate_port(uint8_t dlci, BD_ADDR bd_addr); +extern tPORT* port_allocate_port(uint8_t dlci, const bt_bdaddr_t& bd_addr); extern void port_set_defaults(tPORT* p_port); extern void port_select_mtu(tPORT* p_port); extern void port_release_port(tPORT* p_port); extern tPORT* port_find_mcb_dlci_port(tRFC_MCB* p_mcb, uint8_t dlci); -extern tRFC_MCB* port_find_mcb(BD_ADDR bd_addr); +extern tRFC_MCB* port_find_mcb(const bt_bdaddr_t& bd_addr); extern tPORT* port_find_dlci_port(uint8_t dlci); -extern tPORT* port_find_port(uint8_t dlci, BD_ADDR bd_addr); +extern tPORT* port_find_port(uint8_t dlci, const bt_bdaddr_t& bd_addr); extern uint32_t port_get_signal_changes(tPORT* p_port, uint8_t old_signals, uint8_t signal); extern uint32_t port_flow_control_user(tPORT* p_port); diff --git a/stack/rfcomm/port_rfc.cc b/stack/rfcomm/port_rfc.cc index eb80fed25..1bc6568a6 100644 --- a/stack/rfcomm/port_rfc.cc +++ b/stack/rfcomm/port_rfc.cc @@ -22,6 +22,7 @@ * communications * ******************************************************************************/ +#include #include #include "osi/include/mutex.h" @@ -292,7 +293,7 @@ void PORT_ParNegInd(tRFC_MCB* p_mcb, uint8_t dlci, uint16_t mtu, uint8_t cl, p_mcb->port_inx[dlci] = p_port->inx; } - memcpy(p_port->bd_addr, p_mcb->bd_addr, BD_ADDR_LEN); + p_port->bd_addr = p_mcb->bd_addr; /* Connection is up and we know local and remote features, select MTU */ port_select_mtu(p_port); @@ -420,10 +421,7 @@ void PORT_DlcEstablishInd(tRFC_MCB* p_mcb, uint8_t dlci, uint16_t mtu) { RFCOMM_TRACE_DEBUG( "PORT_DlcEstablishInd p_mcb:%p, dlci:%d mtu:%di, p_port:%p", p_mcb, dlci, mtu, p_port); - RFCOMM_TRACE_DEBUG( - "PORT_DlcEstablishInd p_mcb addr:%02x:%02x:%02x:%02x:%02x:%02x", - p_mcb->bd_addr[0], p_mcb->bd_addr[1], p_mcb->bd_addr[2], - p_mcb->bd_addr[3], p_mcb->bd_addr[4], p_mcb->bd_addr[5]); + VLOG(1) << __func__ << " p_mcb addr:" << p_mcb->bd_addr; if (!p_port) { /* This can be a first request for this port */ diff --git a/stack/rfcomm/port_utils.cc b/stack/rfcomm/port_utils.cc index d816cccad..f93e7c7e6 100644 --- a/stack/rfcomm/port_utils.cc +++ b/stack/rfcomm/port_utils.cc @@ -21,6 +21,7 @@ * Port Emulation entity utilities * ******************************************************************************/ +#include #include #include "osi/include/mutex.h" @@ -59,7 +60,7 @@ static const tPORT_STATE default_port_pars = { * Returns Pointer to the PORT or NULL if not found * ******************************************************************************/ -tPORT* port_allocate_port(uint8_t dlci, BD_ADDR bd_addr) { +tPORT* port_allocate_port(uint8_t dlci, const bt_bdaddr_t& bd_addr) { tPORT* p_port = &rfc_cb.port.port[0]; uint8_t xx, yy; @@ -80,14 +81,11 @@ tPORT* port_allocate_port(uint8_t dlci, BD_ADDR bd_addr) { rfc_cb.rfc.last_port = yy; p_port->dlci = dlci; - memcpy(p_port->bd_addr, bd_addr, BD_ADDR_LEN); + p_port->bd_addr = bd_addr; RFCOMM_TRACE_DEBUG("rfc_cb.port.port[%d]:%p allocated, last_port:%d", yy, p_port, rfc_cb.rfc.last_port); - RFCOMM_TRACE_DEBUG( - "port_allocate_port:bd_addr:%02x:%02x:%02x:%02x:%02x:%02x", - bd_addr[0], bd_addr[1], bd_addr[2], bd_addr[3], bd_addr[4], - bd_addr[5]); + VLOG(1) << __func__ << ": bd_addr:" << bd_addr; return (p_port); } } @@ -145,7 +143,7 @@ void port_select_mtu(tPORT* p_port) { /* Will select MTU only if application did not setup something */ if (p_port->mtu == 0) { /* find packet size which connection supports */ - packet_size = btm_get_max_packet_size(from_BD_ADDR(p_port->bd_addr)); + packet_size = btm_get_max_packet_size(p_port->bd_addr); if (packet_size == 0) { /* something is very wrong */ RFCOMM_TRACE_WARNING("port_select_mtu bad packet size"); @@ -257,7 +255,7 @@ void port_release_port(tPORT* p_port) { if (p_port->is_server) p_port->dlci &= 0xfe; p_port->local_ctrl.modem_signal = p_port->default_signal_state; - memcpy(p_port->bd_addr, BT_BD_ANY.address, BD_ADDR_LEN); + p_port->bd_addr = BT_BD_ANY; } else { RFCOMM_TRACE_DEBUG("%s Clean-up handle: %d", __func__, p_port->inx); alarm_free(p_port->rfc.port_timer); @@ -271,29 +269,24 @@ void port_release_port(tPORT* p_port) { * Function port_find_mcb * * Description This function checks if connection exists to device with - * the BD_ADDR. + * the address. * ******************************************************************************/ -tRFC_MCB* port_find_mcb(BD_ADDR bd_addr) { +tRFC_MCB* port_find_mcb(const bt_bdaddr_t& bd_addr) { int i; for (i = 0; i < MAX_BD_CONNECTIONS; i++) { if ((rfc_cb.port.rfc_mcb[i].state != RFC_MX_STATE_IDLE) && - !memcmp(rfc_cb.port.rfc_mcb[i].bd_addr, bd_addr, BD_ADDR_LEN)) { + rfc_cb.port.rfc_mcb[i].bd_addr == bd_addr) { /* Multiplexer channel found do not change anything */ - RFCOMM_TRACE_DEBUG( - "port_find_mcb: found bd_addr:%02x:%02x:%02x:%02x:%02x:%02x", - bd_addr[0], bd_addr[1], bd_addr[2], bd_addr[3], bd_addr[4], - bd_addr[5]); + VLOG(1) << __func__ << ": found bd_addr:" << bd_addr; RFCOMM_TRACE_DEBUG( "port_find_mcb: rfc_cb.port.rfc_mcb:index:%d, %p, lcid:%d", i, &rfc_cb.port.rfc_mcb[i], rfc_cb.port.rfc_mcb[i].lcid); return (&rfc_cb.port.rfc_mcb[i]); } } - RFCOMM_TRACE_DEBUG( - "port_find_mcb: not found, bd_addr:%02x:%02x:%02x:%02x:%02x:%02x", - bd_addr[0], bd_addr[1], bd_addr[2], bd_addr[3], bd_addr[4], bd_addr[5]); + VLOG(1) << __func__ << ": not found, bd_addr:" << bd_addr; return (NULL); } @@ -358,19 +351,19 @@ tPORT* port_find_dlci_port(uint8_t dlci) { * * Function port_find_port * - * Description Find port with DLCI, BD_ADDR + * Description Find port with DLCI, address * * Returns Pointer to the PORT or NULL if not found * ******************************************************************************/ -tPORT* port_find_port(uint8_t dlci, BD_ADDR bd_addr) { +tPORT* port_find_port(uint8_t dlci, const bt_bdaddr_t& bd_addr) { uint16_t i; tPORT* p_port; for (i = 0; i < MAX_RFC_PORTS; i++) { p_port = &rfc_cb.port.port[i]; if (p_port->in_use && (p_port->dlci == dlci) && - !memcmp(p_port->bd_addr, bd_addr, BD_ADDR_LEN)) { + p_port->bd_addr == bd_addr) { return (p_port); } } diff --git a/stack/rfcomm/rfc_int.h b/stack/rfcomm/rfc_int.h index 7aeb3e87b..c9fd29006 100644 --- a/stack/rfcomm/rfc_int.h +++ b/stack/rfcomm/rfc_int.h @@ -295,7 +295,8 @@ extern void rfc_process_l2cap_congestion(tRFC_MCB* p_mcb, bool is_congested); /* * Functions provided by the rfc_utils.cc */ -tRFC_MCB* rfc_alloc_multiplexer_channel(BD_ADDR bd_addr, bool is_initiator); +tRFC_MCB* rfc_alloc_multiplexer_channel(const bt_bdaddr_t& bd_addr, + bool is_initiator); extern void rfc_release_multiplexer_channel(tRFC_MCB* p_rfc_mcb); extern void rfc_timer_start(tRFC_MCB* p_rfc_mcb, uint16_t timeout); extern void rfc_timer_stop(tRFC_MCB* p_rfc_mcb); diff --git a/stack/rfcomm/rfc_l2cap_if.cc b/stack/rfcomm/rfc_l2cap_if.cc index 9d09d32d0..488d52b2d 100644 --- a/stack/rfcomm/rfc_l2cap_if.cc +++ b/stack/rfcomm/rfc_l2cap_if.cc @@ -87,7 +87,7 @@ void rfcomm_l2cap_if_init(void) { ******************************************************************************/ void RFCOMM_ConnectInd(const bt_bdaddr_t& bd_addr, uint16_t lcid, UNUSED_ATTR uint16_t psm, uint8_t id) { - tRFC_MCB* p_mcb = rfc_alloc_multiplexer_channel(to_BD_ADDR(bd_addr), false); + tRFC_MCB* p_mcb = rfc_alloc_multiplexer_channel(bd_addr, false); if ((p_mcb) && (p_mcb->state != RFC_MX_STATE_IDLE)) { /* if this is collision case */ @@ -184,8 +184,8 @@ void RFCOMM_ConnectCnf(uint16_t lcid, uint16_t result) { /* Peer gave up his connection request, make sure cleaning up L2CAP * channel */ - L2CA_ConnectRsp(from_BD_ADDR(p_mcb->bd_addr), p_mcb->pending_id, - p_mcb->pending_lcid, L2CAP_CONN_NO_RESOURCES, 0); + L2CA_ConnectRsp(p_mcb->bd_addr, p_mcb->pending_id, p_mcb->pending_lcid, + L2CAP_CONN_NO_RESOURCES, 0); p_mcb->pending_lcid = 0; } diff --git a/stack/rfcomm/rfc_mx_fsm.cc b/stack/rfcomm/rfc_mx_fsm.cc index 705295586..4f2785e94 100644 --- a/stack/rfcomm/rfc_mx_fsm.cc +++ b/stack/rfcomm/rfc_mx_fsm.cc @@ -118,8 +118,7 @@ void rfc_mx_sm_state_idle(tRFC_MCB* p_mcb, uint16_t event, void* p_data) { /* Initialize L2CAP MTU */ p_mcb->peer_l2cap_mtu = L2CAP_DEFAULT_MTU - RFCOMM_MIN_OFFSET - 1; - uint16_t lcid = - L2CA_ConnectReq(BT_PSM_RFCOMM, from_BD_ADDR(p_mcb->bd_addr)); + uint16_t lcid = L2CA_ConnectReq(BT_PSM_RFCOMM, p_mcb->bd_addr); if (lcid == 0) { rfc_save_lcid_mcb(NULL, p_mcb->lcid); p_mcb->lcid = 0; @@ -144,8 +143,8 @@ void rfc_mx_sm_state_idle(tRFC_MCB* p_mcb, uint16_t event, void* p_data) { case RFC_MX_EVENT_CONN_IND: rfc_timer_start(p_mcb, RFCOMM_CONN_TIMEOUT); - L2CA_ConnectRsp(from_BD_ADDR(p_mcb->bd_addr), *((uint8_t*)p_data), - p_mcb->lcid, L2CAP_CONN_OK, 0); + L2CA_ConnectRsp(p_mcb->bd_addr, *((uint8_t*)p_data), p_mcb->lcid, + L2CAP_CONN_OK, 0); rfc_mx_send_config_req(p_mcb); @@ -485,8 +484,7 @@ void rfc_mx_sm_state_disc_wait_ua(tRFC_MCB* p_mcb, uint16_t event, if (p_mcb->restart_required) { /* Start Request was received while disconnecting. Execute it again */ - uint16_t lcid = - L2CA_ConnectReq(BT_PSM_RFCOMM, from_BD_ADDR(p_mcb->bd_addr)); + uint16_t lcid = L2CA_ConnectReq(BT_PSM_RFCOMM, p_mcb->bd_addr); if (lcid == 0) { rfc_save_lcid_mcb(NULL, p_mcb->lcid); p_mcb->lcid = 0; diff --git a/stack/rfcomm/rfc_port_fsm.cc b/stack/rfcomm/rfc_port_fsm.cc index 60b849386..59d2c70ec 100644 --- a/stack/rfcomm/rfc_port_fsm.cc +++ b/stack/rfcomm/rfc_port_fsm.cc @@ -111,10 +111,9 @@ 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(from_BD_ADDR(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); + 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: @@ -134,8 +133,8 @@ void rfc_port_sm_state_closed(tPORT* p_port, uint16_t event, void* p_data) { /* Open will be continued after security checks are passed */ p_port->rfc.state = RFC_STATE_TERM_WAIT_SEC_CHECK; - btm_sec_mx_access_request(from_BD_ADDR(p_port->rfc.p_mcb->bd_addr), - BT_PSM_RFCOMM, false, BTM_SEC_PROTO_RFCOMM, + 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; @@ -245,7 +244,7 @@ void rfc_port_sm_sabme_wait_ua(tPORT* p_port, uint16_t event, void* p_data) { * * Description This function handles events for the port in the * WAIT_SEC_CHECK state. SABME has been received from the - * peer and Security Manager verifes BD_ADDR, before we can + * peer and Security Manager verifes address, before we can * send ESTABLISH_IND to the Port entity * * Returns void @@ -276,7 +275,7 @@ void rfc_port_sm_term_wait_sec_check(tPORT* p_port, uint16_t event, return; case RFC_EVENT_CLEAR: - btm_sec_abort_access_req(from_BD_ADDR(p_port->rfc.p_mcb->bd_addr)); + btm_sec_abort_access_req(p_port->rfc.p_mcb->bd_addr); rfc_port_closed(p_port); return; @@ -290,7 +289,7 @@ void rfc_port_sm_term_wait_sec_check(tPORT* p_port, uint16_t event, return; case RFC_EVENT_DISC: - btm_sec_abort_access_req(from_BD_ADDR(p_port->rfc.p_mcb->bd_addr)); + 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); @@ -349,7 +348,7 @@ void rfc_port_sm_orig_wait_sec_check(tPORT* p_port, uint16_t event, return; case RFC_EVENT_CLOSE: - btm_sec_abort_access_req(from_BD_ADDR(p_port->rfc.p_mcb->bd_addr)); + btm_sec_abort_access_req(p_port->rfc.p_mcb->bd_addr); rfc_port_closed(p_port); return; diff --git a/stack/rfcomm/rfc_utils.cc b/stack/rfcomm/rfc_utils.cc index d34bd0712..3daa27f1d 100644 --- a/stack/rfcomm/rfc_utils.cc +++ b/stack/rfcomm/rfc_utils.cc @@ -129,15 +129,14 @@ bool rfc_check_fcs(uint16_t len, uint8_t* p, uint8_t received_fcs) { * Function rfc_alloc_multiplexer_channel * * Description This function returns existing or new control block for - * the BD_ADDR. + * the address. * ******************************************************************************/ -tRFC_MCB* rfc_alloc_multiplexer_channel(BD_ADDR bd_addr, bool is_initiator) { +tRFC_MCB* rfc_alloc_multiplexer_channel(const bt_bdaddr_t& bd_addr, + bool is_initiator) { int i, j; tRFC_MCB* p_mcb = NULL; - RFCOMM_TRACE_DEBUG( - "rfc_alloc_multiplexer_channel: bd_addr:%02x:%02x:%02x:%02x:%02x:%02x", - bd_addr[0], bd_addr[1], bd_addr[2], bd_addr[3], bd_addr[4], bd_addr[5]); + VLOG(1) << __func__ << ": bd_addr:" << bd_addr; RFCOMM_TRACE_DEBUG("rfc_alloc_multiplexer_channel:is_initiator:%d", is_initiator); @@ -145,14 +144,11 @@ tRFC_MCB* rfc_alloc_multiplexer_channel(BD_ADDR bd_addr, bool is_initiator) { RFCOMM_TRACE_DEBUG( "rfc_alloc_multiplexer_channel rfc_cb.port.rfc_mcb[%d].state:%d", i, rfc_cb.port.rfc_mcb[i].state); - RFCOMM_TRACE_DEBUG( - "(rfc_cb.port.rfc_mcb[i].bd_addr:%02x:%02x:%02x:%02x:%02x:%02x", - rfc_cb.port.rfc_mcb[i].bd_addr[0], rfc_cb.port.rfc_mcb[i].bd_addr[1], - rfc_cb.port.rfc_mcb[i].bd_addr[2], rfc_cb.port.rfc_mcb[i].bd_addr[3], - rfc_cb.port.rfc_mcb[i].bd_addr[4], rfc_cb.port.rfc_mcb[i].bd_addr[5]); + VLOG(1) << "(rfc_cb.port.rfc_mcb[i].bd_addr:" + << rfc_cb.port.rfc_mcb[i].bd_addr; if ((rfc_cb.port.rfc_mcb[i].state != RFC_MX_STATE_IDLE) && - (!memcmp(rfc_cb.port.rfc_mcb[i].bd_addr, bd_addr, BD_ADDR_LEN))) { + rfc_cb.port.rfc_mcb[i].bd_addr == bd_addr) { /* Multiplexer channel found do not change anything */ /* If there was an inactivity timer running stop it now */ if (rfc_cb.port.rfc_mcb[i].state == RFC_MX_STATE_CONNECTED) @@ -175,7 +171,7 @@ tRFC_MCB* rfc_alloc_multiplexer_channel(BD_ADDR bd_addr, bool is_initiator) { alarm_free(p_mcb->mcb_timer); fixed_queue_free(p_mcb->cmd_q, NULL); memset(p_mcb, 0, sizeof(tRFC_MCB)); - memcpy(p_mcb->bd_addr, bd_addr, BD_ADDR_LEN); + p_mcb->bd_addr = bd_addr; RFCOMM_TRACE_DEBUG( "rfc_alloc_multiplexer_channel:is_initiator:%d, create new p_mcb:%p, " "index:%d", -- 2.11.0