// rfc_slot_t* accept_rs = create_srv_accept_rfc_slot(srv_rs, p_open->rem_bda,p_opne->handle, p_open->new_listen_handle); static inline rfc_slot_t* create_srv_accept_rfc_slot(rfc_slot_t* srv_rs, const bt_bdaddr_t* addr, int open_handle, int new_listen_handle) { rfc_slot_t *accept_rs = alloc_rfc_slot(addr, srv_rs->service_name, srv_rs->service_uuid, srv_rs->scn, 0, FALSE); clear_slot_flag(&accept_rs->f); accept_rs->f.server = FALSE; accept_rs->f.connected = TRUE; accept_rs->security = srv_rs->security; accept_rs->mtu = srv_rs->mtu; accept_rs->role = srv_rs->role; accept_rs->rfc_handle = open_handle; accept_rs->rfc_port_handle = BTA_JvRfcommGetPortHdl(open_handle); //now update listen rfc_handle of server slot srv_rs->rfc_handle = new_listen_handle; srv_rs->rfc_port_handle = BTA_JvRfcommGetPortHdl(new_listen_handle); BTIF_TRACE_DEBUG4("create_srv_accept__rfc_slot(open_handle: 0x%x, new_listen_handle:" "0x%x) accept_rs->rfc_handle:0x%x, srv_rs_listen->rfc_handle:0x%x" ,open_handle, new_listen_handle, accept_rs->rfc_port_handle, srv_rs->rfc_port_handle); asrt(accept_rs->rfc_port_handle != srv_rs->rfc_port_handle); //now swap the slot id uint32_t new_listen_id = accept_rs->id; accept_rs->id = srv_rs->id; srv_rs->id = new_listen_id; return accept_rs; }
static rfc_slot_t *create_srv_accept_rfc_slot(rfc_slot_t *srv_rs, const bt_bdaddr_t *addr, int open_handle, int new_listen_handle) { rfc_slot_t *accept_rs = alloc_rfc_slot(addr, srv_rs->service_name, srv_rs->service_uuid, srv_rs->scn, 0, false); if (!accept_rs) { LOG_ERROR(LOG_TAG, "%s unable to allocate RFCOMM slot.", __func__); return NULL; } accept_rs->f.server = false; accept_rs->f.connected = true; accept_rs->security = srv_rs->security; accept_rs->mtu = srv_rs->mtu; accept_rs->role = srv_rs->role; accept_rs->rfc_handle = open_handle; accept_rs->rfc_port_handle = BTA_JvRfcommGetPortHdl(open_handle); srv_rs->rfc_handle = new_listen_handle; srv_rs->rfc_port_handle = BTA_JvRfcommGetPortHdl(new_listen_handle); assert(accept_rs->rfc_port_handle != srv_rs->rfc_port_handle); // now swap the slot id uint32_t new_listen_id = accept_rs->id; accept_rs->id = srv_rs->id; srv_rs->id = new_listen_id; return accept_rs; }
static void on_cli_rfc_connect(tBTA_JV_RFCOMM_OPEN *p_open, uint32_t id) { pthread_mutex_lock(&slot_lock); rfc_slot_t *slot = find_rfc_slot_by_id(id); if (!slot) goto out; if (p_open->status != BTA_JV_SUCCESS) { cleanup_rfc_slot(slot); goto out; } slot->rfc_port_handle = BTA_JvRfcommGetPortHdl(p_open->handle); memcpy(slot->addr.address, p_open->rem_bda, 6); if (send_app_connect_signal(slot->fd, &slot->addr, slot->scn, 0, -1)) slot->f.connected = true; else LOG_ERROR(LOG_TAG, "%s unable to send connect completion signal to caller.", __func__); out:; pthread_mutex_unlock(&slot_lock); }
static void on_cli_rfc_connect(tBTA_JV_RFCOMM_OPEN *p_open, uint32_t id) { lock_slot(&slot_lock); rfc_slot_t* rs = find_rfc_slot_by_id(id); if(rs && p_open->status == BTA_JV_SUCCESS) { rs->rfc_port_handle = BTA_JvRfcommGetPortHdl(p_open->handle); bd_copy(rs->addr.address, p_open->rem_bda, 0); //notify app rfc is connected APPL_TRACE_DEBUG4("call send_app_connect_signal, slot id:%d, fd:%d, rfc scn:%d, server:%d", rs->id, rs->fd, rs->scn, rs->f.server); if(send_app_connect_signal(rs->fd, &rs->addr, rs->scn, 0, -1)) { //start monitoring the socketpair to get call back when app writing data APPL_TRACE_DEBUG3("on_rfc_connect_ind, connect signal sent, slot id:%d, rfc scn:%d, server:%d", rs->id, rs->scn, rs->f.server); rs->f.connected = TRUE; } else APPL_TRACE_ERROR0("send_app_connect_signal failed"); } else if(rs) cleanup_rfc_slot(rs); unlock_slot(&slot_lock); }