static void jv_dm_cback(tBTA_JV_EVT event, tBTA_JV *p_data, void *user_data) { uint32_t id = (uint32_t)user_data; APPL_TRACE_DEBUG("jv_dm_cback: event:%d, slot id:%d", event, id); switch(event) { case BTA_JV_CREATE_RECORD_EVT: { lock_slot(&slot_lock); l2c_slot_t* ls = find_l2c_slot_by_id(id); if(ls && create_server_sdp_record(ls)) { //now start the l2cap server after sdp & channel # assigned BTA_JvL2capStartServer(ls->security, ls->role, ls->psm, 672 , l2cap_cback, (void*)ls->id); } else if(ls) { APPL_TRACE_ERROR("jv_dm_cback: cannot start server, slot found:%p", ls); cleanup_l2c_slot(ls); } unlock_slot(&slot_lock); break; } case BTA_JV_DISCOVERY_COMP_EVT: { l2c_slot_t* ls = NULL; lock_slot(&slot_lock); if(p_data->disc_comp.status == BTA_JV_SUCCESS && p_data->disc_comp.psm) { APPL_TRACE_DEBUG("BTA_JV_DISCOVERY_COMP_EVT, slot id:%d, status:%d, psm:%d", id, p_data->disc_comp.status, p_data->disc_comp.psm); ls = find_l2c_slot_by_id(id); if(ls && ls->f.doing_sdp_request) { if(BTA_JvL2capConnect(ls->security, ls->role, p_data->disc_comp.psm, 672, ls->addr.address, l2cap_cback, (void*)ls->id) == BTA_JV_SUCCESS) { ls->psm = p_data->disc_comp.psm; ls->f.doing_sdp_request = FALSE; if(!send_app_psm(ls)) cleanup_l2c_slot(ls); } else cleanup_l2c_slot(ls); } else if(ls) { APPL_TRACE_ERROR("DISCOVERY_COMP_EVT no pending sdp request, slot id:%d, \ flag sdp pending:%d, flag sdp doing:%d", id, ls->f.pending_sdp_request, ls->f.doing_sdp_request); } } else { APPL_TRACE_ERROR("DISCOVERY_COMP_EVT slot id:%d, failed to find channle, \ status:%d, psm:%d", id, p_data->disc_comp.status, p_data->disc_comp.psm); ls = find_l2c_slot_by_id(id); if(ls) cleanup_l2c_slot(ls); } ls = find_l2c_slot_by_pending_sdp(); if(ls) { APPL_TRACE_DEBUG("BTA_JV_DISCOVERY_COMP_EVT, start another pending psm sdp request"); tSDP_UUID sdp_uuid; sdp_uuid.len = 16; memcpy(sdp_uuid.uu.uuid128, ls->service_uuid, sizeof(sdp_uuid.uu.uuid128)); BTA_JvStartDiscovery((UINT8*)ls->addr.address, 1, &sdp_uuid, (void*)(ls->id)); ls->f.pending_sdp_request = FALSE; ls->f.doing_sdp_request = TRUE; } unlock_slot(&slot_lock); break; }
static void jv_dm_cback(tBTA_JV_EVT event, tBTA_JV *p_data, void *user_data) { uint32_t id = (uint32_t)user_data; APPL_TRACE_DEBUG2("jv_dm_cback: event:%d, slot id:%d", event, id); switch(event) { case BTA_JV_CREATE_RECORD_EVT: { lock_slot(&slot_lock); rfc_slot_t* rs = find_rfc_slot_by_id(id); if(rs && create_server_sdp_record(rs)) { //now start the rfcomm server after sdp & channel # assigned BTA_JvRfcommStartServer(rs->security, rs->role, rs->scn, MAX_RFC_SESSION, rfcomm_cback, (void*)rs->id); } else if(rs) { APPL_TRACE_ERROR1("jv_dm_cback: cannot start server, slot found:%p", rs); cleanup_rfc_slot(rs); } unlock_slot(&slot_lock); break; } case BTA_JV_DISCOVERY_COMP_EVT: { rfc_slot_t* rs = NULL; lock_slot(&slot_lock); if(p_data->disc_comp.status == BTA_JV_SUCCESS && p_data->disc_comp.scn) { APPL_TRACE_DEBUG3("BTA_JV_DISCOVERY_COMP_EVT, slot id:%d, status:%d, scn:%d", id, p_data->disc_comp.status, p_data->disc_comp.scn); rs = find_rfc_slot_by_id(id); if(rs && rs->f.doing_sdp_request) { if(BTA_JvRfcommConnect(rs->security, rs->role, p_data->disc_comp.scn, rs->addr.address, rfcomm_cback, (void*)rs->id) == BTA_JV_SUCCESS) { rs->scn = p_data->disc_comp.scn; rs->f.doing_sdp_request = FALSE; if(!send_app_scn(rs)) cleanup_rfc_slot(rs); } else cleanup_rfc_slot(rs); } else if(rs) { APPL_TRACE_ERROR3("DISCOVERY_COMP_EVT no pending sdp request, slot id:%d, \ flag sdp pending:%d, flag sdp doing:%d", id, rs->f.pending_sdp_request, rs->f.doing_sdp_request); } } else { APPL_TRACE_ERROR3("DISCOVERY_COMP_EVT slot id:%d, failed to find channle, \ status:%d, scn:%d", id, p_data->disc_comp.status, p_data->disc_comp.scn); rs = find_rfc_slot_by_id(id); if(rs) cleanup_rfc_slot(rs); } rs = find_rfc_slot_by_pending_sdp(); if(rs) { APPL_TRACE_DEBUG0("BTA_JV_DISCOVERY_COMP_EVT, start another pending scn sdp request"); tSDP_UUID sdp_uuid; sdp_uuid.len = 16; memcpy(sdp_uuid.uu.uuid128, rs->service_uuid, sizeof(sdp_uuid.uu.uuid128)); BTA_JvStartDiscovery((UINT8*)rs->addr.address, 1, &sdp_uuid, (void*)rs->id); rs->f.pending_sdp_request = FALSE; rs->f.doing_sdp_request = TRUE; } unlock_slot(&slot_lock); break; }
static void jv_dm_cback(tBTA_JV_EVT event, tBTA_JV *p_data, void *user_data) { uint32_t id = PTR_TO_UINT(user_data); switch(event) { case BTA_JV_GET_SCN_EVT: { pthread_mutex_lock(&slot_lock); rfc_slot_t* rs = find_rfc_slot_by_id(id); int new_scn = p_data->scn; if(rs && (new_scn != 0)) { rs->scn = new_scn; /* BTA_JvCreateRecordByUser will only create a record if a UUID is specified, * else it just allocate a RFC channel and start the RFCOMM thread - needed * for the java * layer to get a RFCOMM channel. * If uuid is null the create_sdp_record() will be called from Java when it * has received the RFCOMM and L2CAP channel numbers through the sockets.*/ // Send channel ID to java layer if(!send_app_scn(rs)){ //closed APPL_TRACE_DEBUG("send_app_scn() failed, close rs->id:%d", rs->id); cleanup_rfc_slot(rs); } else { if(rs->is_service_uuid_valid == true) { // We already have data for SDP record, create it (RFC-only profiles) BTA_JvCreateRecordByUser(UINT_TO_PTR(rs->id)); } else { APPL_TRACE_DEBUG("is_service_uuid_valid==false - don't set SDP-record, " "just start the RFCOMM server", rs->id); //now start the rfcomm server after sdp & channel # assigned BTA_JvRfcommStartServer(rs->security, rs->role, rs->scn, MAX_RFC_SESSION, rfcomm_cback, UINT_TO_PTR(rs->id)); } } } else if(rs) { APPL_TRACE_ERROR("jv_dm_cback: Error: allocate channel %d, slot found:%p", rs->scn, rs); cleanup_rfc_slot(rs); } pthread_mutex_unlock(&slot_lock); break; } case BTA_JV_GET_PSM_EVT: { APPL_TRACE_DEBUG("Received PSM: 0x%04x", p_data->psm); on_l2cap_psm_assigned(id, p_data->psm); break; } case BTA_JV_CREATE_RECORD_EVT: { pthread_mutex_lock(&slot_lock); rfc_slot_t *slot = find_rfc_slot_by_id(id); if (slot && create_server_sdp_record(slot)) { // Start the rfcomm server after sdp & channel # assigned. BTA_JvRfcommStartServer(slot->security, slot->role, slot->scn, MAX_RFC_SESSION, rfcomm_cback, (void *)(uintptr_t)slot->id); } else if(slot) { APPL_TRACE_ERROR("jv_dm_cback: cannot start server, slot found:%p", slot); cleanup_rfc_slot(slot); } pthread_mutex_unlock(&slot_lock); break; } case BTA_JV_DISCOVERY_COMP_EVT: { pthread_mutex_lock(&slot_lock); rfc_slot_t *slot = find_rfc_slot_by_id(id); if (p_data->disc_comp.status == BTA_JV_SUCCESS && p_data->disc_comp.scn) { if (slot && slot->f.doing_sdp_request) { // Establish the connection if we successfully looked up a channel number to connect to. if (BTA_JvRfcommConnect(slot->security, slot->role, p_data->disc_comp.scn, slot->addr.address, rfcomm_cback, (void *)(uintptr_t)slot->id) == BTA_JV_SUCCESS) { slot->scn = p_data->disc_comp.scn; slot->f.doing_sdp_request = false; if (!send_app_scn(slot)) cleanup_rfc_slot(slot); } else { cleanup_rfc_slot(slot); } } else if (slot) { // TODO(sharvil): this is really a logic error and we should probably assert. LOG_ERROR(LOG_TAG, "%s SDP response returned but RFCOMM slot %d did not request SDP record.", __func__, id); } } else if (slot) { cleanup_rfc_slot(slot); } // Find the next slot that needs to perform an SDP request and service it. slot = find_rfc_slot_by_pending_sdp(); if (slot) { tSDP_UUID sdp_uuid; sdp_uuid.len = 16; memcpy(sdp_uuid.uu.uuid128, slot->service_uuid, sizeof(sdp_uuid.uu.uuid128)); BTA_JvStartDiscovery((uint8_t *)slot->addr.address, 1, &sdp_uuid, (void *)(uintptr_t)slot->id); slot->f.pending_sdp_request = false; slot->f.doing_sdp_request = true; } pthread_mutex_unlock(&slot_lock); break; } default: APPL_TRACE_DEBUG("unhandled event:%d, slot id:%d", event, id); break; } }