static uint32_t on_srv_rfc_connect(tBTA_JV_RFCOMM_SRV_OPEN *p_open, uint32_t id) { uint32_t new_listen_slot_id = 0; lock_slot(&slot_lock); rfc_slot_t* srv_rs = find_rfc_slot_by_id(id); if(srv_rs) { rfc_slot_t* accept_rs = create_srv_accept_rfc_slot(srv_rs, (const bt_bdaddr_t*)p_open->rem_bda, p_open->handle, p_open->new_listen_handle); if(accept_rs) { //start monitor the socket btsock_thread_add_fd(pth, srv_rs->fd, BTSOCK_RFCOMM, SOCK_THREAD_FD_EXCEPTION, srv_rs->id); btsock_thread_add_fd(pth, accept_rs->fd, BTSOCK_RFCOMM, SOCK_THREAD_FD_RD, accept_rs->id); APPL_TRACE_DEBUG1("sending connect signal & app fd:%dto app server to accept() the connection", accept_rs->app_fd); APPL_TRACE_DEBUG2("server fd:%d, scn:%d", srv_rs->fd, srv_rs->scn); send_app_connect_signal(srv_rs->fd, &accept_rs->addr, srv_rs->scn, 0, accept_rs->app_fd); accept_rs->app_fd = -1; //the fd is closed after sent to app new_listen_slot_id = srv_rs->id; } } unlock_slot(&slot_lock); return new_listen_slot_id; }
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_l2c_connect(tBTA_JV_L2CAP_OPEN *p_open, uint32_t id) { lock_slot(&slot_lock); l2c_slot_t* ls = find_l2c_slot_by_id(id); if(ls && p_open->status == BTA_JV_SUCCESS) { bd_copy(ls->addr.address, p_open->rem_bda, 0); //notify app l2c is connected APPL_TRACE_DEBUG("call send_app_connect_signal, slot id:%d, fd:%d, l2c psm:%d, server:%d", ls->id, ls->fd, ls->psm, ls->f.server); if(send_app_connect_signal(ls->fd, &ls->addr, ls->psm, 0, -1)) { //start monitoring the socketpair to get call back when app writing data APPL_TRACE_DEBUG("on_l2c_connect_ind, connect signal sent, slot id:%d, l2c psm:%d, server:%d", ls->id, ls->psm, ls->f.server); ls->f.connected = TRUE; } else APPL_TRACE_ERROR("send_app_connect_signal failed"); } else if(ls) cleanup_l2c_slot(ls); unlock_slot(&slot_lock); }
static uint32_t on_srv_rfc_connect(tBTA_JV_RFCOMM_SRV_OPEN *p_open, uint32_t id) { uint32_t new_listen_slot_id = 0; pthread_mutex_lock(&slot_lock); rfc_slot_t *srv_rs = find_rfc_slot_by_id(id); if (!srv_rs) goto out; rfc_slot_t *accept_rs = create_srv_accept_rfc_slot(srv_rs, (const bt_bdaddr_t *)p_open->rem_bda, p_open->handle, p_open->new_listen_handle); if (!accept_rs) goto out; // Start monitoring the socket. btsock_thread_add_fd(pth, srv_rs->fd, BTSOCK_RFCOMM, SOCK_THREAD_FD_EXCEPTION, srv_rs->id); btsock_thread_add_fd(pth, accept_rs->fd, BTSOCK_RFCOMM, SOCK_THREAD_FD_RD, accept_rs->id); send_app_connect_signal(srv_rs->fd, &accept_rs->addr, srv_rs->scn, 0, accept_rs->app_fd); accept_rs->app_fd = INVALID_FD; // Ownership of the application fd has been transferred. new_listen_slot_id = srv_rs->id; out:; pthread_mutex_unlock(&slot_lock); return new_listen_slot_id; }
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); }