Lines Matching refs:dlc

221 static void rfcomm_dlc_tx_give_credits(struct bt_rfcomm_dlc *dlc,  in rfcomm_dlc_tx_give_credits()  argument
224 LOG_DBG("dlc %p credits %u", dlc, credits); in rfcomm_dlc_tx_give_credits()
227 k_sem_give(&dlc->tx_credits); in rfcomm_dlc_tx_give_credits()
230 LOG_DBG("dlc %p updated credits %u", dlc, k_sem_count_get(&dlc->tx_credits)); in rfcomm_dlc_tx_give_credits()
233 static void rfcomm_dlc_destroy(struct bt_rfcomm_dlc *dlc) in rfcomm_dlc_destroy() argument
235 LOG_DBG("dlc %p", dlc); in rfcomm_dlc_destroy()
237 k_work_cancel_delayable(&dlc->rtx_work); in rfcomm_dlc_destroy()
238 dlc->state = BT_RFCOMM_STATE_IDLE; in rfcomm_dlc_destroy()
239 dlc->session = NULL; in rfcomm_dlc_destroy()
241 if (dlc->ops && dlc->ops->disconnected) { in rfcomm_dlc_destroy()
242 dlc->ops->disconnected(dlc); in rfcomm_dlc_destroy()
246 static void rfcomm_dlc_disconnect(struct bt_rfcomm_dlc *dlc) in rfcomm_dlc_disconnect() argument
248 uint8_t old_state = dlc->state; in rfcomm_dlc_disconnect()
250 LOG_DBG("dlc %p", dlc); in rfcomm_dlc_disconnect()
252 if (dlc->state == BT_RFCOMM_STATE_DISCONNECTED) { in rfcomm_dlc_disconnect()
256 dlc->state = BT_RFCOMM_STATE_DISCONNECTED; in rfcomm_dlc_disconnect()
263 k_fifo_put(&dlc->tx_queue, net_buf_alloc(&dummy_pool, K_NO_WAIT)); in rfcomm_dlc_disconnect()
268 rfcomm_dlc_tx_give_credits(dlc, 1); in rfcomm_dlc_disconnect()
269 k_sem_give(&dlc->session->fc); in rfcomm_dlc_disconnect()
272 rfcomm_dlc_destroy(dlc); in rfcomm_dlc_disconnect()
279 struct bt_rfcomm_dlc *dlc; in rfcomm_session_disconnected() local
287 for (dlc = session->dlcs; dlc;) { in rfcomm_session_disconnected()
291 next = dlc->_next; in rfcomm_session_disconnected()
292 dlc->_next = NULL; in rfcomm_session_disconnected()
294 rfcomm_dlc_disconnect(dlc); in rfcomm_session_disconnected()
296 dlc = next; in rfcomm_session_disconnected()
436 struct bt_rfcomm_dlc *dlc = DLC_RTX(work); in rfcomm_dlc_rtx_timeout() local
437 struct bt_rfcomm_session *session = dlc->session; in rfcomm_dlc_rtx_timeout()
439 LOG_WRN("dlc %p state %d timeout", dlc, dlc->state); in rfcomm_dlc_rtx_timeout()
441 rfcomm_dlcs_remove_dlci(session->dlcs, dlc->dlci); in rfcomm_dlc_rtx_timeout()
442 rfcomm_dlc_disconnect(dlc); in rfcomm_dlc_rtx_timeout()
446 static void rfcomm_dlc_init(struct bt_rfcomm_dlc *dlc, in rfcomm_dlc_init() argument
451 LOG_DBG("dlc %p", dlc); in rfcomm_dlc_init()
453 dlc->dlci = dlci; in rfcomm_dlc_init()
454 dlc->session = session; in rfcomm_dlc_init()
455 dlc->rx_credit = RFCOMM_DEFAULT_CREDIT; in rfcomm_dlc_init()
456 dlc->state = BT_RFCOMM_STATE_INIT; in rfcomm_dlc_init()
457 dlc->role = role; in rfcomm_dlc_init()
458 k_work_init_delayable(&dlc->rtx_work, rfcomm_dlc_rtx_timeout); in rfcomm_dlc_init()
461 k_work_schedule(&dlc->rtx_work, RFCOMM_CONN_TIMEOUT); in rfcomm_dlc_init()
463 dlc->_next = session->dlcs; in rfcomm_dlc_init()
464 session->dlcs = dlc; in rfcomm_dlc_init()
471 struct bt_rfcomm_dlc *dlc; in rfcomm_dlc_accept() local
481 if (server->accept(session->br_chan.chan.conn, &dlc) < 0) { in rfcomm_dlc_accept()
486 if (!BT_RFCOMM_CHECK_MTU(dlc->mtu)) { in rfcomm_dlc_accept()
487 rfcomm_dlc_destroy(dlc); in rfcomm_dlc_accept()
491 rfcomm_dlc_init(dlc, session, dlci, BT_RFCOMM_ROLE_ACCEPTOR); in rfcomm_dlc_accept()
492 dlc->mtu = MIN(dlc->mtu, session->mtu); in rfcomm_dlc_accept()
494 return dlc; in rfcomm_dlc_accept()
519 static void rfcomm_check_fc(struct bt_rfcomm_dlc *dlc) in rfcomm_check_fc() argument
521 LOG_DBG("%p", dlc); in rfcomm_check_fc()
523 LOG_DBG("Wait for credits or MSC FC %p", dlc); in rfcomm_check_fc()
525 k_sem_take(&dlc->tx_credits, K_FOREVER); in rfcomm_check_fc()
527 if (dlc->session->cfc == BT_RFCOMM_CFC_SUPPORTED) { in rfcomm_check_fc()
531 k_sem_take(&dlc->session->fc, K_FOREVER); in rfcomm_check_fc()
538 k_sem_give(&dlc->session->fc); in rfcomm_check_fc()
539 k_sem_give(&dlc->tx_credits); in rfcomm_check_fc()
542 static void bt_rfcomm_tx_destroy(struct bt_rfcomm_dlc *dlc, struct net_buf *buf) in bt_rfcomm_tx_destroy() argument
544 LOG_DBG("dlc %p, buf %p", dlc, buf); in bt_rfcomm_tx_destroy()
550 if (dlc && dlc->ops && dlc->ops->sent) { in bt_rfcomm_tx_destroy()
551 dlc->ops->sent(dlc, -ESHUTDOWN); in bt_rfcomm_tx_destroy()
557 struct bt_rfcomm_dlc *dlc; in rfcomm_sent() local
565 dlc = (struct bt_rfcomm_dlc *)user_data; in rfcomm_sent()
567 if (dlc && dlc->ops && dlc->ops->sent) { in rfcomm_sent()
568 dlc->ops->sent(dlc, err); in rfcomm_sent()
574 struct bt_rfcomm_dlc *dlc = p1; in rfcomm_dlc_tx_thread() local
578 LOG_DBG("Started for dlc %p", dlc); in rfcomm_dlc_tx_thread()
580 while (dlc->state == BT_RFCOMM_STATE_CONNECTED || in rfcomm_dlc_tx_thread()
581 dlc->state == BT_RFCOMM_STATE_USER_DISCONNECT) { in rfcomm_dlc_tx_thread()
583 LOG_DBG("Wait for buf %p", dlc); in rfcomm_dlc_tx_thread()
584 buf = k_fifo_get(&dlc->tx_queue, timeout); in rfcomm_dlc_tx_thread()
586 if ((dlc->state != BT_RFCOMM_STATE_CONNECTED && in rfcomm_dlc_tx_thread()
587 dlc->state != BT_RFCOMM_STATE_USER_DISCONNECT) || in rfcomm_dlc_tx_thread()
590 bt_rfcomm_tx_destroy(dlc, buf); in rfcomm_dlc_tx_thread()
596 rfcomm_check_fc(dlc); in rfcomm_dlc_tx_thread()
597 if (dlc->state != BT_RFCOMM_STATE_CONNECTED && in rfcomm_dlc_tx_thread()
598 dlc->state != BT_RFCOMM_STATE_USER_DISCONNECT) { in rfcomm_dlc_tx_thread()
599 bt_rfcomm_tx_destroy(dlc, buf); in rfcomm_dlc_tx_thread()
604 if (rfcomm_send_cb(dlc->session, buf, rfcomm_sent, dlc) < 0) { in rfcomm_dlc_tx_thread()
606 dlc->state = BT_RFCOMM_STATE_DISCONNECTED; in rfcomm_dlc_tx_thread()
607 bt_rfcomm_tx_destroy(dlc, buf); in rfcomm_dlc_tx_thread()
611 if (dlc->state == BT_RFCOMM_STATE_USER_DISCONNECT) { in rfcomm_dlc_tx_thread()
616 LOG_DBG("dlc %p disconnected - cleaning up", dlc); in rfcomm_dlc_tx_thread()
619 while ((buf = k_fifo_get(&dlc->tx_queue, K_NO_WAIT))) { in rfcomm_dlc_tx_thread()
620 bt_rfcomm_tx_destroy(dlc, buf); in rfcomm_dlc_tx_thread()
624 if (dlc->state == BT_RFCOMM_STATE_USER_DISCONNECT) { in rfcomm_dlc_tx_thread()
625 dlc->state = BT_RFCOMM_STATE_DISCONNECTING; in rfcomm_dlc_tx_thread()
628 if (dlc->state == BT_RFCOMM_STATE_DISCONNECTING) { in rfcomm_dlc_tx_thread()
629 rfcomm_send_disc(dlc->session, dlc->dlci); in rfcomm_dlc_tx_thread()
630 k_work_reschedule(&dlc->rtx_work, RFCOMM_DISC_TIMEOUT); in rfcomm_dlc_tx_thread()
632 rfcomm_dlc_destroy(dlc); in rfcomm_dlc_tx_thread()
635 LOG_DBG("dlc %p exiting", dlc); in rfcomm_dlc_tx_thread()
658 static int rfcomm_send_msc(struct bt_rfcomm_dlc *dlc, uint8_t cr, in rfcomm_send_msc() argument
665 buf = rfcomm_make_uih_msg(dlc->session, cr, BT_RFCOMM_MSC, in rfcomm_send_msc()
670 msc->dlci = BT_RFCOMM_SET_ADDR(dlc->dlci, 1); in rfcomm_send_msc()
676 return rfcomm_send(dlc->session, buf); in rfcomm_send_msc()
679 static int rfcomm_send_rls(struct bt_rfcomm_dlc *dlc, uint8_t cr, in rfcomm_send_rls() argument
686 buf = rfcomm_make_uih_msg(dlc->session, cr, BT_RFCOMM_RLS, in rfcomm_send_rls()
691 rls->dlci = BT_RFCOMM_SET_ADDR(dlc->dlci, 1); in rfcomm_send_rls()
697 return rfcomm_send(dlc->session, buf); in rfcomm_send_rls()
774 static void rfcomm_dlc_connected(struct bt_rfcomm_dlc *dlc) in rfcomm_dlc_connected() argument
776 dlc->state = BT_RFCOMM_STATE_CONNECTED; in rfcomm_dlc_connected()
778 rfcomm_send_msc(dlc, BT_RFCOMM_MSG_CMD_CR, BT_RFCOMM_DEFAULT_V24_SIG); in rfcomm_dlc_connected()
780 if (dlc->session->cfc == BT_RFCOMM_CFC_UNKNOWN) { in rfcomm_dlc_connected()
784 dlc->session->cfc = BT_RFCOMM_CFC_NOT_SUPPORTED; in rfcomm_dlc_connected()
787 if (dlc->session->cfc == BT_RFCOMM_CFC_NOT_SUPPORTED) { in rfcomm_dlc_connected()
788 LOG_DBG("CFC not supported %p", dlc); in rfcomm_dlc_connected()
789 rfcomm_send_fcon(dlc->session, BT_RFCOMM_MSG_CMD_CR); in rfcomm_dlc_connected()
791 k_sem_init(&dlc->tx_credits, 0, 1); in rfcomm_dlc_connected()
795 k_work_cancel_delayable(&dlc->rtx_work); in rfcomm_dlc_connected()
797 k_fifo_init(&dlc->tx_queue); in rfcomm_dlc_connected()
798 k_thread_create(&dlc->tx_thread, dlc->stack, in rfcomm_dlc_connected()
799 K_KERNEL_STACK_SIZEOF(dlc->stack), in rfcomm_dlc_connected()
800 rfcomm_dlc_tx_thread, dlc, NULL, NULL, K_PRIO_COOP(7), in rfcomm_dlc_connected()
802 k_thread_name_set(&dlc->tx_thread, "BT DLC"); in rfcomm_dlc_connected()
804 if (dlc->ops && dlc->ops->connected) { in rfcomm_dlc_connected()
805 dlc->ops->connected(dlc); in rfcomm_dlc_connected()
815 static enum security_result rfcomm_dlc_security(struct bt_rfcomm_dlc *dlc) in rfcomm_dlc_security() argument
817 struct bt_conn *conn = dlc->session->br_chan.chan.conn; in rfcomm_dlc_security()
819 LOG_DBG("dlc %p", dlc); in rfcomm_dlc_security()
826 if (conn->sec_level >= dlc->required_sec_level) { in rfcomm_dlc_security()
830 if (!bt_conn_set_security(conn, dlc->required_sec_level)) { in rfcomm_dlc_security()
846 static void rfcomm_dlc_drop(struct bt_rfcomm_dlc *dlc) in rfcomm_dlc_drop() argument
848 LOG_DBG("dlc %p", dlc); in rfcomm_dlc_drop()
850 rfcomm_dlcs_remove_dlci(dlc->session->dlcs, dlc->dlci); in rfcomm_dlc_drop()
851 rfcomm_dlc_destroy(dlc); in rfcomm_dlc_drop()
854 static int rfcomm_dlc_close(struct bt_rfcomm_dlc *dlc) in rfcomm_dlc_close() argument
856 LOG_DBG("dlc %p", dlc); in rfcomm_dlc_close()
858 switch (dlc->state) { in rfcomm_dlc_close()
860 if (dlc->role == BT_RFCOMM_ROLE_ACCEPTOR) { in rfcomm_dlc_close()
861 rfcomm_send_dm(dlc->session, dlc->dlci); in rfcomm_dlc_close()
865 rfcomm_dlc_drop(dlc); in rfcomm_dlc_close()
869 dlc->state = BT_RFCOMM_STATE_DISCONNECTING; in rfcomm_dlc_close()
870 rfcomm_send_disc(dlc->session, dlc->dlci); in rfcomm_dlc_close()
871 k_work_reschedule(&dlc->rtx_work, RFCOMM_DISC_TIMEOUT); in rfcomm_dlc_close()
874 dlc->state = BT_RFCOMM_STATE_DISCONNECTING; in rfcomm_dlc_close()
879 k_fifo_put(&dlc->tx_queue, in rfcomm_dlc_close()
885 rfcomm_dlc_tx_give_credits(dlc, 1); in rfcomm_dlc_close()
907 struct bt_rfcomm_dlc *dlc; in rfcomm_handle_sabm() local
910 dlc = rfcomm_dlcs_lookup_dlci(session->dlcs, dlci); in rfcomm_handle_sabm()
911 if (!dlc) { in rfcomm_handle_sabm()
912 dlc = rfcomm_dlc_accept(session, dlci); in rfcomm_handle_sabm()
913 if (!dlc) { in rfcomm_handle_sabm()
919 result = rfcomm_dlc_security(dlc); in rfcomm_handle_sabm()
922 dlc->state = BT_RFCOMM_STATE_SECURITY_PENDING; in rfcomm_handle_sabm()
929 rfcomm_dlc_drop(dlc); in rfcomm_handle_sabm()
940 rfcomm_dlc_connected(dlc); in rfcomm_handle_sabm()
944 static int rfcomm_send_pn(struct bt_rfcomm_dlc *dlc, uint8_t cr) in rfcomm_send_pn() argument
950 buf = rfcomm_make_uih_msg(dlc->session, cr, BT_RFCOMM_PN, sizeof(*pn)); in rfcomm_send_pn()
952 LOG_DBG("mtu %x", dlc->mtu); in rfcomm_send_pn()
955 pn->dlci = dlc->dlci; in rfcomm_send_pn()
956 pn->mtu = sys_cpu_to_le16(dlc->mtu); in rfcomm_send_pn()
957 if (dlc->state == BT_RFCOMM_STATE_CONFIG && in rfcomm_send_pn()
958 (dlc->session->cfc == BT_RFCOMM_CFC_UNKNOWN || in rfcomm_send_pn()
959 dlc->session->cfc == BT_RFCOMM_CFC_SUPPORTED)) { in rfcomm_send_pn()
960 pn->credits = dlc->rx_credit; in rfcomm_send_pn()
980 return rfcomm_send(dlc->session, buf); in rfcomm_send_pn()
983 static int rfcomm_send_credit(struct bt_rfcomm_dlc *dlc, uint8_t credits) in rfcomm_send_credit() argument
989 LOG_DBG("Dlc %p credits %d", dlc, credits); in rfcomm_send_credit()
994 cr = BT_RFCOMM_UIH_CR(dlc->session->role); in rfcomm_send_credit()
995 hdr->address = BT_RFCOMM_SET_ADDR(dlc->dlci, cr); in rfcomm_send_credit()
1003 return rfcomm_send(dlc->session, buf); in rfcomm_send_credit()
1006 static int rfcomm_dlc_start(struct bt_rfcomm_dlc *dlc) in rfcomm_dlc_start() argument
1010 LOG_DBG("dlc %p", dlc); in rfcomm_dlc_start()
1012 result = rfcomm_dlc_security(dlc); in rfcomm_dlc_start()
1015 dlc->mtu = MIN(dlc->mtu, dlc->session->mtu); in rfcomm_dlc_start()
1016 dlc->state = BT_RFCOMM_STATE_CONFIG; in rfcomm_dlc_start()
1017 rfcomm_send_pn(dlc, BT_RFCOMM_MSG_CMD_CR); in rfcomm_dlc_start()
1020 dlc->state = BT_RFCOMM_STATE_SECURITY_PENDING; in rfcomm_dlc_start()
1032 struct bt_rfcomm_dlc *dlc, *next; in rfcomm_handle_ua() local
1039 for (dlc = session->dlcs; dlc; dlc = next) { in rfcomm_handle_ua()
1040 next = dlc->_next; in rfcomm_handle_ua()
1041 if (dlc->role == BT_RFCOMM_ROLE_INITIATOR && in rfcomm_handle_ua()
1042 dlc->state == BT_RFCOMM_STATE_INIT) { in rfcomm_handle_ua()
1043 if (rfcomm_dlc_start(dlc) < 0) { in rfcomm_handle_ua()
1044 rfcomm_dlc_drop(dlc); in rfcomm_handle_ua()
1064 dlc = rfcomm_dlcs_lookup_dlci(session->dlcs, dlci); in rfcomm_handle_ua()
1065 if (!dlc) { in rfcomm_handle_ua()
1069 switch (dlc->state) { in rfcomm_handle_ua()
1071 rfcomm_dlc_connected(dlc); in rfcomm_handle_ua()
1074 rfcomm_dlc_drop(dlc); in rfcomm_handle_ua()
1085 struct bt_rfcomm_dlc *dlc; in rfcomm_handle_dm() local
1089 dlc = rfcomm_dlcs_remove_dlci(session->dlcs, dlci); in rfcomm_handle_dm()
1090 if (!dlc) { in rfcomm_handle_dm()
1094 rfcomm_dlc_disconnect(dlc); in rfcomm_handle_dm()
1102 struct bt_rfcomm_dlc *dlc; in rfcomm_handle_msc() local
1107 dlc = rfcomm_dlcs_lookup_dlci(session->dlcs, dlci); in rfcomm_handle_msc()
1108 if (!dlc) { in rfcomm_handle_msc()
1116 if (dlc->session->cfc == BT_RFCOMM_CFC_NOT_SUPPORTED) { in rfcomm_handle_msc()
1126 k_sem_take(&dlc->tx_credits, K_NO_WAIT); in rfcomm_handle_msc()
1131 k_sem_give(&dlc->tx_credits); in rfcomm_handle_msc()
1135 rfcomm_send_msc(dlc, BT_RFCOMM_MSG_RESP_CR, msc->v24_signal); in rfcomm_handle_msc()
1143 struct bt_rfcomm_dlc *dlc; in rfcomm_handle_rls() local
1152 dlc = rfcomm_dlcs_lookup_dlci(session->dlcs, dlci); in rfcomm_handle_rls()
1153 if (!dlc) { in rfcomm_handle_rls()
1158 rfcomm_send_rls(dlc, BT_RFCOMM_MSG_RESP_CR, rls->line_status); in rfcomm_handle_rls()
1211 struct bt_rfcomm_dlc *dlc; in rfcomm_handle_pn() local
1213 dlc = rfcomm_dlcs_lookup_dlci(session->dlcs, pn->dlci); in rfcomm_handle_pn()
1214 if (!dlc) { in rfcomm_handle_pn()
1226 dlc = rfcomm_dlc_accept(session, pn->dlci); in rfcomm_handle_pn()
1227 if (!dlc) { in rfcomm_handle_pn()
1232 LOG_DBG("Incoming connection accepted dlc %p", dlc); in rfcomm_handle_pn()
1234 dlc->mtu = MIN(dlc->mtu, sys_le16_to_cpu(pn->mtu)); in rfcomm_handle_pn()
1240 k_sem_init(&dlc->tx_credits, 0, K_SEM_MAX_LIMIT); in rfcomm_handle_pn()
1241 rfcomm_dlc_tx_give_credits(dlc, pn->credits); in rfcomm_handle_pn()
1246 dlc->state = BT_RFCOMM_STATE_CONFIG; in rfcomm_handle_pn()
1247 rfcomm_send_pn(dlc, BT_RFCOMM_MSG_RESP_CR); in rfcomm_handle_pn()
1255 rfcomm_dlc_close(dlc); in rfcomm_handle_pn()
1258 dlc->mtu = MIN(dlc->mtu, sys_le16_to_cpu(pn->mtu)); in rfcomm_handle_pn()
1259 rfcomm_send_pn(dlc, BT_RFCOMM_MSG_RESP_CR); in rfcomm_handle_pn()
1261 if (dlc->state != BT_RFCOMM_STATE_CONFIG) { in rfcomm_handle_pn()
1265 dlc->mtu = MIN(dlc->mtu, sys_le16_to_cpu(pn->mtu)); in rfcomm_handle_pn()
1270 k_sem_init(&dlc->tx_credits, 0, K_SEM_MAX_LIMIT); in rfcomm_handle_pn()
1271 rfcomm_dlc_tx_give_credits(dlc, pn->credits); in rfcomm_handle_pn()
1276 dlc->state = BT_RFCOMM_STATE_CONNECTING; in rfcomm_handle_pn()
1277 rfcomm_send_sabm(session, dlc->dlci); in rfcomm_handle_pn()
1284 struct bt_rfcomm_dlc *dlc; in rfcomm_handle_disc() local
1289 dlc = rfcomm_dlcs_remove_dlci(session->dlcs, dlci); in rfcomm_handle_disc()
1290 if (!dlc) { in rfcomm_handle_disc()
1296 rfcomm_dlc_disconnect(dlc); in rfcomm_handle_disc()
1300 k_work_reschedule(&dlc->session->rtx_work, in rfcomm_handle_disc()
1391 static void rfcomm_dlc_update_credits(struct bt_rfcomm_dlc *dlc) in rfcomm_dlc_update_credits() argument
1395 if (dlc->session->cfc == BT_RFCOMM_CFC_NOT_SUPPORTED) { in rfcomm_dlc_update_credits()
1399 LOG_DBG("dlc %p credits %u", dlc, dlc->rx_credit); in rfcomm_dlc_update_credits()
1402 if (dlc->rx_credit > RFCOMM_CREDITS_THRESHOLD) { in rfcomm_dlc_update_credits()
1407 credits = RFCOMM_MAX_CREDITS - dlc->rx_credit; in rfcomm_dlc_update_credits()
1408 dlc->rx_credit += credits; in rfcomm_dlc_update_credits()
1410 rfcomm_send_credit(dlc, credits); in rfcomm_dlc_update_credits()
1417 struct bt_rfcomm_dlc *dlc; in rfcomm_handle_data() local
1421 dlc = rfcomm_dlcs_lookup_dlci(session->dlcs, dlci); in rfcomm_handle_data()
1422 if (!dlc) { in rfcomm_handle_data()
1428 LOG_DBG("dlc %p rx credit %d", dlc, dlc->rx_credit); in rfcomm_handle_data()
1430 if (dlc->state != BT_RFCOMM_STATE_CONNECTED) { in rfcomm_handle_data()
1439 rfcomm_dlc_tx_give_credits(dlc, net_buf_pull_u8(buf)); in rfcomm_handle_data()
1443 if (dlc->session->cfc == BT_RFCOMM_CFC_SUPPORTED && in rfcomm_handle_data()
1444 !dlc->rx_credit) { in rfcomm_handle_data()
1446 rfcomm_dlc_close(dlc); in rfcomm_handle_data()
1452 if (dlc->ops && dlc->ops->recv) { in rfcomm_handle_data()
1453 dlc->ops->recv(dlc, buf); in rfcomm_handle_data()
1456 dlc->rx_credit--; in rfcomm_handle_data()
1457 rfcomm_dlc_update_credits(dlc); in rfcomm_handle_data()
1461 int bt_rfcomm_dlc_send(struct bt_rfcomm_dlc *dlc, struct net_buf *buf) in bt_rfcomm_dlc_send() argument
1469 LOG_DBG("dlc %p tx credit %d", dlc, k_sem_count_get(&dlc->tx_credits)); in bt_rfcomm_dlc_send()
1471 if (dlc->state != BT_RFCOMM_STATE_CONNECTED) { in bt_rfcomm_dlc_send()
1475 if (buf->len > dlc->mtu) { in bt_rfcomm_dlc_send()
1491 cr = BT_RFCOMM_UIH_CR(dlc->session->role); in bt_rfcomm_dlc_send()
1492 net_buf_push_u8(buf, BT_RFCOMM_SET_ADDR(dlc->dlci, cr)); in bt_rfcomm_dlc_send()
1497 k_fifo_put(&dlc->tx_queue, buf); in bt_rfcomm_dlc_send()
1578 struct bt_rfcomm_dlc *dlc, *next; in rfcomm_encrypt_change() local
1582 for (dlc = session->dlcs; dlc; dlc = next) { in rfcomm_encrypt_change()
1583 next = dlc->_next; in rfcomm_encrypt_change()
1585 if (dlc->state != BT_RFCOMM_STATE_SECURITY_PENDING) { in rfcomm_encrypt_change()
1590 conn->sec_level < dlc->required_sec_level) { in rfcomm_encrypt_change()
1591 rfcomm_dlc_close(dlc); in rfcomm_encrypt_change()
1595 if (dlc->role == BT_RFCOMM_ROLE_ACCEPTOR) { in rfcomm_encrypt_change()
1596 rfcomm_send_ua(session, dlc->dlci); in rfcomm_encrypt_change()
1597 rfcomm_dlc_connected(dlc); in rfcomm_encrypt_change()
1599 dlc->mtu = MIN(dlc->mtu, session->mtu); in rfcomm_encrypt_change()
1600 dlc->state = BT_RFCOMM_STATE_CONFIG; in rfcomm_encrypt_change()
1601 rfcomm_send_pn(dlc, BT_RFCOMM_MSG_CMD_CR); in rfcomm_encrypt_change()
1659 int bt_rfcomm_dlc_connect(struct bt_conn *conn, struct bt_rfcomm_dlc *dlc, in bt_rfcomm_dlc_connect() argument
1667 LOG_DBG("conn %p dlc %p channel %d", conn, dlc, channel); in bt_rfcomm_dlc_connect()
1669 if (!dlc) { in bt_rfcomm_dlc_connect()
1681 if (!BT_RFCOMM_CHECK_MTU(dlc->mtu)) { in bt_rfcomm_dlc_connect()
1699 rfcomm_dlc_init(dlc, session, dlci, BT_RFCOMM_ROLE_INITIATOR); in bt_rfcomm_dlc_connect()
1708 BR_CHAN(chan)->required_sec_level = dlc->required_sec_level; in bt_rfcomm_dlc_connect()
1719 ret = rfcomm_dlc_start(dlc); in bt_rfcomm_dlc_connect()
1735 rfcomm_dlcs_remove_dlci(session->dlcs, dlc->dlci); in bt_rfcomm_dlc_connect()
1736 dlc->state = BT_RFCOMM_STATE_IDLE; in bt_rfcomm_dlc_connect()
1737 dlc->session = NULL; in bt_rfcomm_dlc_connect()
1741 int bt_rfcomm_dlc_disconnect(struct bt_rfcomm_dlc *dlc) in bt_rfcomm_dlc_disconnect() argument
1743 LOG_DBG("dlc %p", dlc); in bt_rfcomm_dlc_disconnect()
1745 if (!dlc) { in bt_rfcomm_dlc_disconnect()
1749 if (dlc->state == BT_RFCOMM_STATE_CONNECTED) { in bt_rfcomm_dlc_disconnect()
1755 dlc->state = BT_RFCOMM_STATE_USER_DISCONNECT; in bt_rfcomm_dlc_disconnect()
1756 k_fifo_put(&dlc->tx_queue, in bt_rfcomm_dlc_disconnect()
1759 k_work_reschedule(&dlc->rtx_work, RFCOMM_DISC_TIMEOUT); in bt_rfcomm_dlc_disconnect()
1764 return rfcomm_dlc_close(dlc); in bt_rfcomm_dlc_disconnect()