Lines Matching refs:slot

174   int slot = -1;  in find_rfc_slot_by_pending_sdp()  local
179 slot = i; in find_rfc_slot_by_pending_sdp()
182 return (slot == -1) ? NULL : &rfc_slots[slot]; in find_rfc_slot_by_pending_sdp()
204 rfc_slot_t* slot = find_free_slot(); in alloc_rfc_slot() local
205 if (!slot) { in alloc_rfc_slot()
219 slot->fd = fds[0]; in alloc_rfc_slot()
220 slot->app_fd = fds[1]; in alloc_rfc_slot()
221 slot->security = security; in alloc_rfc_slot()
222 slot->scn = channel; in alloc_rfc_slot()
223 slot->app_uid = -1; in alloc_rfc_slot()
225 slot->is_service_uuid_valid = !uuid.IsEmpty(); in alloc_rfc_slot()
226 slot->service_uuid = uuid; in alloc_rfc_slot()
229 strlcpy(slot->service_name, name, sizeof(slot->service_name)); in alloc_rfc_slot()
231 memset(slot->service_name, 0, sizeof(slot->service_name)); in alloc_rfc_slot()
234 slot->addr = *addr; in alloc_rfc_slot()
236 slot->addr = RawAddress::kEmpty; in alloc_rfc_slot()
238 slot->id = rfc_slot_id; in alloc_rfc_slot()
239 slot->f.server = server; in alloc_rfc_slot()
240 slot->tx_bytes = 0; in alloc_rfc_slot()
241 slot->rx_bytes = 0; in alloc_rfc_slot()
242 return slot; in alloc_rfc_slot()
313 rfc_slot_t* slot = in btsock_rfc_listen() local
315 if (!slot) { in btsock_rfc_listen()
321 BTA_JvGetChannelId(BTA_JV_CONN_TYPE_RFCOMM, slot->id, channel); in btsock_rfc_listen()
322 *sock_fd = slot->app_fd; // Transfer ownership of fd to caller. in btsock_rfc_listen()
331 slot->app_fd = INVALID_FD; // Drop our reference to the fd. in btsock_rfc_listen()
332 slot->app_uid = app_uid; in btsock_rfc_listen()
333 btsock_thread_add_fd(pth, slot->fd, BTSOCK_RFCOMM, SOCK_THREAD_FD_EXCEPTION, in btsock_rfc_listen()
334 slot->id); in btsock_rfc_listen()
355 rfc_slot_t* slot = in btsock_rfc_connect() local
357 if (!slot) { in btsock_rfc_connect()
364 BTA_JvRfcommConnect(slot->security, slot->role, slot->scn, slot->addr, in btsock_rfc_connect()
365 rfcomm_cback, slot->id); in btsock_rfc_connect()
368 cleanup_rfc_slot(slot); in btsock_rfc_connect()
372 if (!send_app_scn(slot)) { in btsock_rfc_connect()
374 cleanup_rfc_slot(slot); in btsock_rfc_connect()
379 BTA_JvStartDiscovery(*bd_addr, 1, service_uuid, slot->id); in btsock_rfc_connect()
380 slot->f.pending_sdp_request = false; in btsock_rfc_connect()
381 slot->f.doing_sdp_request = true; in btsock_rfc_connect()
383 slot->f.pending_sdp_request = true; in btsock_rfc_connect()
384 slot->f.doing_sdp_request = false; in btsock_rfc_connect()
388 *sock_fd = slot->app_fd; // Transfer ownership of fd to caller. in btsock_rfc_connect()
389 slot->app_fd = INVALID_FD; // Drop our reference to the fd. in btsock_rfc_connect()
390 slot->app_uid = app_uid; in btsock_rfc_connect()
391 btsock_thread_add_fd(pth, slot->fd, BTSOCK_RFCOMM, SOCK_THREAD_FD_RD, in btsock_rfc_connect()
392 slot->id); in btsock_rfc_connect()
397 static int create_server_sdp_record(rfc_slot_t* slot) { in create_server_sdp_record() argument
398 if (slot->scn == 0) { in create_server_sdp_record()
401 slot->sdp_handle = in create_server_sdp_record()
402 add_rfc_sdp_rec(slot->service_name, slot->service_uuid, slot->scn); in create_server_sdp_record()
403 return (slot->sdp_handle > 0); in create_server_sdp_record()
406 static void free_rfc_slot_scn(rfc_slot_t* slot) { in free_rfc_slot_scn() argument
407 if (slot->scn <= 0) return; in free_rfc_slot_scn()
409 if (slot->f.server && !slot->f.closing && slot->rfc_handle) { in free_rfc_slot_scn()
410 BTA_JvRfcommStopServer(slot->rfc_handle, slot->id); in free_rfc_slot_scn()
411 slot->rfc_handle = 0; in free_rfc_slot_scn()
414 if (slot->f.server) BTM_FreeSCN(slot->scn); in free_rfc_slot_scn()
415 slot->scn = 0; in free_rfc_slot_scn()
418 static void cleanup_rfc_slot(rfc_slot_t* slot) { in cleanup_rfc_slot() argument
419 if (slot->fd != INVALID_FD) { in cleanup_rfc_slot()
420 shutdown(slot->fd, SHUT_RDWR); in cleanup_rfc_slot()
421 close(slot->fd); in cleanup_rfc_slot()
423 slot->addr, slot->id, BTSOCK_RFCOMM, in cleanup_rfc_slot()
425 slot->tx_bytes, slot->rx_bytes, slot->app_uid, slot->scn, in cleanup_rfc_slot()
426 slot->f.server ? android::bluetooth::SOCKET_ROLE_LISTEN in cleanup_rfc_slot()
428 slot->fd = INVALID_FD; in cleanup_rfc_slot()
431 if (slot->app_fd != INVALID_FD) { in cleanup_rfc_slot()
432 close(slot->app_fd); in cleanup_rfc_slot()
433 slot->app_fd = INVALID_FD; in cleanup_rfc_slot()
436 if (slot->sdp_handle > 0) { in cleanup_rfc_slot()
437 del_rfc_sdp_rec(slot->sdp_handle); in cleanup_rfc_slot()
438 slot->sdp_handle = 0; in cleanup_rfc_slot()
441 if (slot->rfc_handle && !slot->f.closing && !slot->f.server) { in cleanup_rfc_slot()
442 BTA_JvRfcommClose(slot->rfc_handle, slot->id); in cleanup_rfc_slot()
443 slot->rfc_handle = 0; in cleanup_rfc_slot()
446 free_rfc_slot_scn(slot); in cleanup_rfc_slot()
447 list_clear(slot->incoming_queue); in cleanup_rfc_slot()
449 slot->rfc_port_handle = 0; in cleanup_rfc_slot()
450 memset(&slot->f, 0, sizeof(slot->f)); in cleanup_rfc_slot()
451 slot->id = 0; in cleanup_rfc_slot()
452 slot->scn_notified = false; in cleanup_rfc_slot()
453 slot->tx_bytes = 0; in cleanup_rfc_slot()
454 slot->rx_bytes = 0; in cleanup_rfc_slot()
457 static bool send_app_scn(rfc_slot_t* slot) { in send_app_scn() argument
458 if (slot->scn_notified) { in send_app_scn()
462 slot->scn_notified = true; in send_app_scn()
463 return sock_send_all(slot->fd, (const uint8_t*)&slot->scn, in send_app_scn()
464 sizeof(slot->scn)) == sizeof(slot->scn); in send_app_scn()
485 rfc_slot_t* slot = find_rfc_slot_by_id(id); in on_cl_rfc_init() local
486 if (!slot) return; in on_cl_rfc_init()
489 slot->rfc_handle = p_init->handle; in on_cl_rfc_init()
491 cleanup_rfc_slot(slot); in on_cl_rfc_init()
498 rfc_slot_t* slot = find_rfc_slot_by_id(id); in on_srv_rfc_listen_started() local
499 if (!slot) return; in on_srv_rfc_listen_started()
502 slot->rfc_handle = p_start->handle; in on_srv_rfc_listen_started()
504 slot->addr, slot->id, BTSOCK_RFCOMM, in on_srv_rfc_listen_started()
507 0, 0, slot->app_uid, slot->scn, in on_srv_rfc_listen_started()
508 slot->f.server ? android::bluetooth::SOCKET_ROLE_LISTEN in on_srv_rfc_listen_started()
511 cleanup_rfc_slot(slot); in on_srv_rfc_listen_started()
547 rfc_slot_t* slot = find_rfc_slot_by_id(id); in on_cli_rfc_connect() local
548 if (!slot) return; in on_cli_rfc_connect()
551 cleanup_rfc_slot(slot); in on_cli_rfc_connect()
555 slot->rfc_port_handle = BTA_JvRfcommGetPortHdl(p_open->handle); in on_cli_rfc_connect()
556 slot->addr = p_open->rem_bda; in on_cli_rfc_connect()
559 slot->addr, slot->id, BTSOCK_RFCOMM, in on_cli_rfc_connect()
561 slot->app_uid, slot->scn, in on_cli_rfc_connect()
562 slot->f.server ? android::bluetooth::SOCKET_ROLE_LISTEN in on_cli_rfc_connect()
565 if (send_app_connect_signal(slot->fd, &slot->addr, slot->scn, 0, -1)) { in on_cli_rfc_connect()
566 slot->f.connected = true; in on_cli_rfc_connect()
578 rfc_slot_t* slot = find_rfc_slot_by_id(id); in on_rfc_close() local
579 if (slot) { in on_rfc_close()
581 slot->addr, slot->id, BTSOCK_RFCOMM, in on_rfc_close()
583 slot->app_uid, slot->scn, in on_rfc_close()
584 slot->f.server ? android::bluetooth::SOCKET_ROLE_LISTEN in on_rfc_close()
586 cleanup_rfc_slot(slot); in on_rfc_close()
600 rfc_slot_t* slot = find_rfc_slot_by_id(id); in on_rfc_write_done() local
601 if (slot) { in on_rfc_write_done()
602 app_uid = slot->app_uid; in on_rfc_write_done()
603 if (!slot->f.outgoing_congest) { in on_rfc_write_done()
604 btsock_thread_add_fd(pth, slot->fd, BTSOCK_RFCOMM, SOCK_THREAD_FD_RD, in on_rfc_write_done()
605 slot->id); in on_rfc_write_done()
607 slot->tx_bytes += p->len; in on_rfc_write_done()
616 rfc_slot_t* slot = find_rfc_slot_by_id(id); in on_rfc_outgoing_congest() local
617 if (slot) { in on_rfc_outgoing_congest()
618 slot->f.outgoing_congest = p->cong ? 1 : 0; in on_rfc_outgoing_congest()
619 if (!slot->f.outgoing_congest) in on_rfc_outgoing_congest()
620 btsock_thread_add_fd(pth, slot->fd, BTSOCK_RFCOMM, SOCK_THREAD_FD_RD, in on_rfc_outgoing_congest()
621 slot->id); in on_rfc_outgoing_congest()
731 rfc_slot_t* slot = find_rfc_slot_by_id(id); in jv_dm_cback() local
733 if (slot && create_server_sdp_record(slot)) { in jv_dm_cback()
735 BTA_JvRfcommStartServer(slot->security, slot->role, slot->scn, in jv_dm_cback()
736 MAX_RFC_SESSION, rfcomm_cback, slot->id); in jv_dm_cback()
737 } else if (slot) { in jv_dm_cback()
739 slot); in jv_dm_cback()
740 cleanup_rfc_slot(slot); in jv_dm_cback()
747 rfc_slot_t* slot = find_rfc_slot_by_id(id); in jv_dm_cback() local
749 if (slot && slot->f.doing_sdp_request) { in jv_dm_cback()
752 if (BTA_JvRfcommConnect(slot->security, slot->role, in jv_dm_cback()
753 p_data->disc_comp.scn, slot->addr, in jv_dm_cback()
754 rfcomm_cback, slot->id) == BTA_JV_SUCCESS) { in jv_dm_cback()
755 slot->scn = p_data->disc_comp.scn; in jv_dm_cback()
756 slot->f.doing_sdp_request = false; in jv_dm_cback()
757 if (!send_app_scn(slot)) cleanup_rfc_slot(slot); in jv_dm_cback()
759 cleanup_rfc_slot(slot); in jv_dm_cback()
761 } else if (slot) { in jv_dm_cback()
769 } else if (slot) { in jv_dm_cback()
770 cleanup_rfc_slot(slot); in jv_dm_cback()
774 slot = find_rfc_slot_by_pending_sdp(); in jv_dm_cback()
775 if (slot) { in jv_dm_cback()
776 BTA_JvStartDiscovery(slot->addr, 1, &slot->service_uuid, slot->id); in jv_dm_cback()
777 slot->f.pending_sdp_request = false; in jv_dm_cback()
778 slot->f.doing_sdp_request = true; in jv_dm_cback()
819 static bool flush_incoming_que_on_wr_signal(rfc_slot_t* slot) { in flush_incoming_que_on_wr_signal() argument
820 while (!list_is_empty(slot->incoming_queue)) { in flush_incoming_que_on_wr_signal()
821 BT_HDR* p_buf = (BT_HDR*)list_front(slot->incoming_queue); in flush_incoming_que_on_wr_signal()
822 switch (send_data_to_app(slot->fd, p_buf)) { in flush_incoming_que_on_wr_signal()
826 btsock_thread_add_fd(pth, slot->fd, BTSOCK_RFCOMM, SOCK_THREAD_FD_WR, in flush_incoming_que_on_wr_signal()
827 slot->id); in flush_incoming_que_on_wr_signal()
831 list_remove(slot->incoming_queue, p_buf); in flush_incoming_que_on_wr_signal()
835 list_remove(slot->incoming_queue, p_buf); in flush_incoming_que_on_wr_signal()
844 slot->rfc_handle, slot->rfc_port_handle, slot->id); in flush_incoming_que_on_wr_signal()
845 PORT_FlowControl_MaxCredit(slot->rfc_port_handle, true); in flush_incoming_que_on_wr_signal()
852 rfc_slot_t* slot = find_rfc_slot_by_id(user_id); in btsock_rfc_signaled() local
853 if (!slot) return; in btsock_rfc_signaled()
856 if (flags & SOCK_THREAD_FD_RD && !slot->f.server) { in btsock_rfc_signaled()
857 if (slot->f.connected) { in btsock_rfc_signaled()
861 (ioctl(slot->fd, FIONREAD, &size) == 0 && size)) { in btsock_rfc_signaled()
862 BTA_JvRfcommWrite(slot->rfc_handle, slot->id); in btsock_rfc_signaled()
868 __func__, slot->id, slot->scn); in btsock_rfc_signaled()
875 if (!slot->f.connected || !flush_incoming_que_on_wr_signal(slot)) { in btsock_rfc_signaled()
879 __func__, slot->id, slot->scn); in btsock_rfc_signaled()
887 if (need_close || ioctl(slot->fd, FIONREAD, &size) != 0 || !size) in btsock_rfc_signaled()
888 cleanup_rfc_slot(slot); in btsock_rfc_signaled()
897 rfc_slot_t* slot = find_rfc_slot_by_id(id); in bta_co_rfc_data_incoming() local
898 if (!slot) return 0; in bta_co_rfc_data_incoming()
900 app_uid = slot->app_uid; in bta_co_rfc_data_incoming()
903 if (list_is_empty(slot->incoming_queue)) { in bta_co_rfc_data_incoming()
904 switch (send_data_to_app(slot->fd, p_buf)) { in bta_co_rfc_data_incoming()
907 list_append(slot->incoming_queue, p_buf); in bta_co_rfc_data_incoming()
908 btsock_thread_add_fd(pth, slot->fd, BTSOCK_RFCOMM, SOCK_THREAD_FD_WR, in bta_co_rfc_data_incoming()
909 slot->id); in bta_co_rfc_data_incoming()
919 cleanup_rfc_slot(slot); in bta_co_rfc_data_incoming()
923 list_append(slot->incoming_queue, p_buf); in bta_co_rfc_data_incoming()
926 slot->rx_bytes += bytes_rx; in bta_co_rfc_data_incoming()
935 rfc_slot_t* slot = find_rfc_slot_by_id(id); in bta_co_rfc_data_outgoing_size() local
936 if (!slot) return false; in bta_co_rfc_data_outgoing_size()
938 if (ioctl(slot->fd, FIONREAD, size) != 0) { in bta_co_rfc_data_outgoing_size()
940 __func__, slot->fd, strerror(errno)); in bta_co_rfc_data_outgoing_size()
941 cleanup_rfc_slot(slot); in bta_co_rfc_data_outgoing_size()
950 rfc_slot_t* slot = find_rfc_slot_by_id(id); in bta_co_rfc_data_outgoing() local
951 if (!slot) return false; in bta_co_rfc_data_outgoing()
954 OSI_NO_INTR(received = recv(slot->fd, buf, size, 0)); in bta_co_rfc_data_outgoing()
959 cleanup_rfc_slot(slot); in bta_co_rfc_data_outgoing()