Home | History | Annotate | Download | only in src

Lines Matching refs:slot

81   uint32_t id;  // Non-zero indicates a valid (in-use) slot.
162 LOG_ERROR(LOG_TAG, "%s unable to find RFCOMM slot id: %u", __func__, id);
168 int slot = -1;
173 slot = i;
176 return (slot == -1) ? NULL : &rfc_slots[slot];
198 rfc_slot_t* slot = find_free_slot();
199 if (!slot) {
200 LOG_ERROR(LOG_TAG, "%s unable to find free RFCOMM slot.", __func__);
211 // Increment slot id and make sure we don't use id=0.
214 slot->fd = fds[0];
215 slot->app_fd = fds[1];
216 slot->security = security;
217 slot->scn = channel;
218 slot->app_uid = -1;
220 slot->is_service_uuid_valid = !uuid.IsEmpty();
221 slot->service_uuid = uuid;
224 strlcpy(slot->service_name, name, sizeof(slot->service_name));
226 memset(slot->service_name, 0, sizeof(slot->service_name));
228 if (addr) slot->addr = *addr;
230 slot->id = rfc_slot_id;
231 slot->f.server = server;
233 return slot;
243 LOG_ERROR(LOG_TAG, "%s unable to allocate RFCOMM slot.", __func__);
261 // now swap the slot id
304 rfc_slot_t* slot =
306 if (!slot) {
307 LOG_ERROR(LOG_TAG, "%s unable to allocate RFCOMM slot.", __func__);
312 BTA_JvGetChannelId(BTA_JV_CONN_TYPE_RFCOMM, slot->id, channel);
313 *sock_fd = slot->app_fd; // Transfer ownership of fd to caller.
322 slot->app_fd = INVALID_FD; // Drop our reference to the fd.
323 slot->app_uid = app_uid;
324 btsock_thread_add_fd(pth, slot->fd, BTSOCK_RFCOMM, SOCK_THREAD_FD_EXCEPTION,
325 slot->id);
346 rfc_slot_t* slot =
348 if (!slot) {
349 LOG_ERROR(LOG_TAG, "%s unable to allocate RFCOMM slot.", __func__);
355 BTA_JvRfcommConnect(slot->security, slot->role, slot->scn, slot->addr,
356 rfcomm_cback, slot->id);
360 cleanup_rfc_slot(slot);
364 if (!send_app_scn(slot)) {
366 cleanup_rfc_slot(slot);
371 BTA_JvStartDiscovery(*bd_addr, 1, service_uuid, slot->id);
372 slot->f.pending_sdp_request = false;
373 slot->f.doing_sdp_request = true;
375 slot->f.pending_sdp_request = true;
376 slot->f.doing_sdp_request = false;
380 *sock_fd = slot->app_fd; // Transfer ownership of fd to caller.
381 slot->app_fd = INVALID_FD; // Drop our reference to the fd.
382 slot->app_uid = app_uid;
383 btsock_thread_add_fd(pth, slot->fd, BTSOCK_RFCOMM, SOCK_THREAD_FD_RD,
384 slot->id);
389 static int create_server_sdp_record(rfc_slot_t* slot) {
390 if (slot->scn == 0) {
393 slot->sdp_handle =
394 add_rfc_sdp_rec(slot->service_name, slot->service_uuid, slot->scn);
395 return (slot->sdp_handle > 0);
398 static void free_rfc_slot_scn(rfc_slot_t* slot) {
399 if (slot->scn <= 0) return;
401 if (slot->f.server && !slot->f.closing && slot->rfc_handle) {
402 BTA_JvRfcommStopServer(slot->rfc_handle, slot->id);
403 slot->rfc_handle = 0;
406 if (slot->f.server) BTM_FreeSCN(slot->scn);
407 slot->scn = 0;
410 static void cleanup_rfc_slot(rfc_slot_t* slot) {
411 if (slot->fd != INVALID_FD) {
412 shutdown(slot->fd, SHUT_RDWR);
413 close(slot->fd);
414 slot->fd = INVALID_FD;
417 if (slot->app_fd != INVALID_FD) {
418 close(slot->app_fd);
419 slot->app_fd = INVALID_FD;
422 if (slot->sdp_handle > 0) {
423 del_rfc_sdp_rec(slot->sdp_handle);
424 slot->sdp_handle = 0;
427 if (slot->rfc_handle && !slot->f.closing && !slot->f.server) {
428 BTA_JvRfcommClose(slot->rfc_handle, slot->id);
429 slot->rfc_handle = 0;
432 free_rfc_slot_scn(slot);
433 list_clear(slot->incoming_queue);
435 slot->rfc_port_handle = 0;
436 memset(&slot->f, 0, sizeof(slot->f));
437 slot->id = 0;
438 slot->scn_notified = false;
441 static bool send_app_scn(rfc_slot_t* slot) {
442 if (slot->scn_notified) {
446 slot->scn_notified = true;
447 return sock_send_all(slot->fd, (const uint8_t*)&slot->scn,
448 sizeof(slot->scn)) == sizeof(slot->scn);
469 rfc_slot_t* slot = find_rfc_slot_by_id(id);
470 if (!slot) return;
473 slot->rfc_handle = p_init->handle;
475 cleanup_rfc_slot(slot);
482 rfc_slot_t* slot = find_rfc_slot_by_id(id);
483 if (!slot) return;
486 slot->rfc_handle = p_start->handle;
488 cleanup_rfc_slot(slot);
517 rfc_slot_t* slot = find_rfc_slot_by_id(id);
518 if (!slot) return;
521 cleanup_rfc_slot(slot);
525 slot->rfc_port_handle = BTA_JvRfcommGetPortHdl(p_open->handle);
526 slot
528 if (send_app_connect_signal(slot->fd, &slot->addr, slot->scn, 0, -1)) {
529 slot->f.connected = true;
541 rfc_slot_t* slot = find_rfc_slot_by_id(id);
542 if (slot) cleanup_rfc_slot(slot);
547 LOG_ERROR(LOG_TAG, "%s error writing to RFCOMM socket with slot %u.",
555 rfc_slot_t* slot = find_rfc_slot_by_id(id);
556 if (slot) {
557 app_uid = slot->app_uid;
558 if (!slot->f.outgoing_congest) {
559 btsock_thread_add_fd(pth, slot->fd, BTSOCK_RFCOMM, SOCK_THREAD_FD_RD,
560 slot->id);
570 rfc_slot_t* slot = find_rfc_slot_by_id(id);
571 if (slot) {
572 slot->f.outgoing_congest = p->cong ? 1 : 0;
573 if (!slot->f.outgoing_congest)
574 btsock_thread_add_fd(pth, slot->fd, BTSOCK_RFCOMM, SOCK_THREAD_FD_RD,
575 slot->id);
623 LOG_ERROR(LOG_TAG, "%s unhandled event %d, slot id: %u", __func__, event,
672 "jv_dm_cback: Error: allocate channel %d, slot found:%p", rs->scn,
685 rfc_slot_t* slot = find_rfc_slot_by_id(id);
687 if (slot && create_server_sdp_record(slot)) {
689 BTA_JvRfcommStartServer(slot->security, slot->role, slot->scn,
690 MAX_RFC_SESSION, rfcomm_cback, slot->id);
691 } else if (slot) {
692 APPL_TRACE_ERROR("jv_dm_cback: cannot start server, slot found:%p",
693 slot);
694 cleanup_rfc_slot(slot);
701 rfc_slot_t* slot = find_rfc_slot_by_id(id);
703 if (slot && slot->f.doing_sdp_request) {
706 if (BTA_JvRfcommConnect(slot->security, slot->role,
707 p_data->disc_comp.scn, slot->addr,
708 rfcomm_cback, slot->id) == BTA_JV_SUCCESS) {
709 slot->scn = p_data->disc_comp.scn;
710 slot->f.doing_sdp_request = false;
711 if (!send_app_scn(slot)) cleanup_rfc_slot(slot);
713 cleanup_rfc_slot(slot);
715 } else if (slot) {
719 "%s SDP response returned but RFCOMM slot %d did not "
723 } else if (slot) {
724 cleanup_rfc_slot(slot);
727 // Find the next slot that needs to perform an SDP request and service it.
728 slot = find_rfc_slot_by_pending_sdp();
729 if (slot) {
730 BTA_JvStartDiscovery(slot->addr, 1, &slot->service_uuid, slot->id);
731 slot->f.pending_sdp_request = false;
732 slot->f.doing_sdp_request = true;
738 APPL_TRACE_DEBUG("unhandled event:%d, slot id:%d", event, id);
773 static bool flush_incoming_que_on_wr_signal(rfc_slot_t* slot) {
774 while (!list_is_empty(slot->incoming_queue)) {
775 BT_HDR* p_buf = (BT_HDR*)list_front(slot->incoming_queue);
776 switch (send_data_to_app(slot->fd, p_buf)) {
780 btsock_thread_add_fd(pth, slot->fd, BTSOCK_RFCOMM, SOCK_THREAD_FD_WR,
781 slot->id);
785 list_remove(slot->incoming_queue, p_buf);
789 list_remove(slot->incoming_queue, p_buf);
798 slot->rfc_handle, slot->rfc_port_handle, slot->id);
799 PORT_FlowControl_MaxCredit(slot->rfc_port_handle, true);
806 rfc_slot_t* slot = find_rfc_slot_by_id(user_id);
807 if (!slot) return;
810 if (flags & SOCK_THREAD_FD_RD && !slot->f.server) {
811 if (slot->f.connected) {
815 (ioctl(slot->fd, FIONREAD, &size) == 0 && size)) {
816 BTA_JvRfcommWrite(slot->rfc_handle, slot->id);
820 "%s socket signaled for read while disconnected, slot: %d, "
822 __func__, slot->id, slot->scn);
829 if (!slot->f.connected || !flush_incoming_que_on_wr_signal(slot)) {
832 "failure), slot: %d, channel: %d",
833 __func__, slot->id, slot->scn);
841 if (need_close || ioctl(slot->fd, FIONREAD, &size) != 0 || !size)
842 cleanup_rfc_slot(slot);
851 rfc_slot_t* slot = find_rfc_slot_by_id(id);
852 if (!slot) return 0;
854 app_uid = slot->app_uid;
857 if (list_is_empty(slot->incoming_queue)) {
858 switch (send_data_to_app(slot->fd, p_buf)) {
861 list_append(slot->incoming_queue, p_buf);
862 btsock_thread_add_fd(pth, slot->fd, BTSOCK_RFCOMM, SOCK_THREAD_FD_WR,
863 slot->id);
873 cleanup_rfc_slot(slot);
877 list_append(slot->incoming_queue, p_buf);
888 rfc_slot_t* slot = find_rfc_slot_by_id(id);
889 if (!slot) return false;
891 if (ioctl(slot->fd, FIONREAD, size) != 0) {
894 __func__, slot->fd, strerror(errno));
895 cleanup_rfc_slot(slot);
904 rfc_slot_t* slot = find_rfc_slot_by_id(id);
905 if (!slot) return false;
908 OSI_NO_INTR(received = recv(slot->fd, buf, size, 0));
913 cleanup_rfc_slot(slot);