Lines Matching +full:sco +full:- +full:routing

5 /*-
6 * SPDX-License-Identifier: BSD-2-Clause
8 * Copyright (c) 2001-2002 Maksim Yevmenkin <m_evmenkin@yahoo.com>
68 "Netgraph Bluetooth SCO sockets");
116 "Bluetooth SEQPACKET SCO sockets family");
120 "Bluetooth SEQPACKET SCO sockets debug level");
124 "Bluetooth SEQPACKET SCO sockets input queue length");
128 "Bluetooth SEQPACKET SCO sockets input queue max. length");
132 "Bluetooth SEQPACKET SCO sockets input queue drops");
292 * the routing table and must schedule cleaning for the routing table. in ng_btsocket_sco_node_disconnect()
294 * so we have never added this hook to the routing table and it save in ng_btsocket_sco_node_disconnect()
316 if (msg != NULL && msg->header.typecookie == NGM_HCI_COOKIE) { in ng_btsocket_sco_node_rcvmsg()
384 if (msg->header.arglen != sizeof(*ep)) in ng_btsocket_sco_process_lp_con_cfm()
387 ep = (ng_hci_lp_con_cfm_ep *)(msg->data); in ng_btsocket_sco_process_lp_con_cfm()
392 pcb = ng_btsocket_sco_pcb_by_addrs(&rt->src, &ep->bdaddr); in ng_btsocket_sco_process_lp_con_cfm()
404 pcb->src.b[5], pcb->src.b[4], pcb->src.b[3], in ng_btsocket_sco_process_lp_con_cfm()
405 pcb->src.b[2], pcb->src.b[1], pcb->src.b[0], in ng_btsocket_sco_process_lp_con_cfm()
406 pcb->dst.b[5], pcb->dst.b[4], pcb->dst.b[3], in ng_btsocket_sco_process_lp_con_cfm()
407 pcb->dst.b[2], pcb->dst.b[1], pcb->dst.b[0], in ng_btsocket_sco_process_lp_con_cfm()
408 ep->status, ep->con_handle, pcb->state); in ng_btsocket_sco_process_lp_con_cfm()
410 if (pcb->state != NG_BTSOCKET_SCO_CONNECTING) { in ng_btsocket_sco_process_lp_con_cfm()
411 mtx_unlock(&pcb->pcb_mtx); in ng_btsocket_sco_process_lp_con_cfm()
419 if (ep->status == 0) { in ng_btsocket_sco_process_lp_con_cfm()
425 pcb->con_handle = ep->con_handle; in ng_btsocket_sco_process_lp_con_cfm()
426 pcb->state = NG_BTSOCKET_SCO_OPEN; in ng_btsocket_sco_process_lp_con_cfm()
427 soisconnected(pcb->so); in ng_btsocket_sco_process_lp_con_cfm()
433 pcb->so->so_error = ECONNREFUSED; /* XXX convert status ??? */ in ng_btsocket_sco_process_lp_con_cfm()
434 pcb->state = NG_BTSOCKET_SCO_CLOSED; in ng_btsocket_sco_process_lp_con_cfm()
435 soisdisconnected(pcb->so); in ng_btsocket_sco_process_lp_con_cfm()
438 mtx_unlock(&pcb->pcb_mtx); in ng_btsocket_sco_process_lp_con_cfm()
458 if (msg->header.arglen != sizeof(*ep)) in ng_btsocket_sco_process_lp_con_ind()
461 ep = (ng_hci_lp_con_ind_ep *)(msg->data); in ng_btsocket_sco_process_lp_con_ind()
467 rt->src.b[5], rt->src.b[4], rt->src.b[3], in ng_btsocket_sco_process_lp_con_ind()
468 rt->src.b[2], rt->src.b[1], rt->src.b[0], in ng_btsocket_sco_process_lp_con_ind()
469 ep->bdaddr.b[5], ep->bdaddr.b[4], ep->bdaddr.b[3], in ng_btsocket_sco_process_lp_con_ind()
470 ep->bdaddr.b[2], ep->bdaddr.b[1], ep->bdaddr.b[0]); in ng_btsocket_sco_process_lp_con_ind()
474 pcb = ng_btsocket_sco_pcb_by_addr(&rt->src); in ng_btsocket_sco_process_lp_con_ind()
480 CURVNET_SET(pcb->so->so_vnet); in ng_btsocket_sco_process_lp_con_ind()
481 so1 = sonewconn(pcb->so, 0); in ng_btsocket_sco_process_lp_con_ind()
493 * address from hook's routing information. in ng_btsocket_sco_process_lp_con_ind()
500 mtx_lock(&pcb1->pcb_mtx); in ng_btsocket_sco_process_lp_con_ind()
502 if (bcmp(&pcb->src, NG_HCI_BDADDR_ANY, sizeof(pcb->src)) != 0) in ng_btsocket_sco_process_lp_con_ind()
503 bcopy(&pcb->src, &pcb1->src, sizeof(pcb1->src)); in ng_btsocket_sco_process_lp_con_ind()
505 bcopy(&rt->src, &pcb1->src, sizeof(pcb1->src)); in ng_btsocket_sco_process_lp_con_ind()
507 pcb1->flags &= ~NG_BTSOCKET_SCO_CLIENT; in ng_btsocket_sco_process_lp_con_ind()
509 bcopy(&ep->bdaddr, &pcb1->dst, sizeof(pcb1->dst)); in ng_btsocket_sco_process_lp_con_ind()
510 pcb1->rt = rt; in ng_btsocket_sco_process_lp_con_ind()
516 error = ng_btsocket_sco_send_lp_con_rsp(rt, &ep->bdaddr, status); in ng_btsocket_sco_process_lp_con_ind()
519 pcb1->so->so_error = error; in ng_btsocket_sco_process_lp_con_ind()
520 pcb1->state = NG_BTSOCKET_SCO_CLOSED; in ng_btsocket_sco_process_lp_con_ind()
521 soisdisconnected(pcb1->so); in ng_btsocket_sco_process_lp_con_ind()
523 pcb1->state = NG_BTSOCKET_SCO_CONNECTING; in ng_btsocket_sco_process_lp_con_ind()
524 soisconnecting(pcb1->so); in ng_btsocket_sco_process_lp_con_ind()
529 mtx_unlock(&pcb1->pcb_mtx); in ng_btsocket_sco_process_lp_con_ind()
533 mtx_unlock(&pcb->pcb_mtx); in ng_btsocket_sco_process_lp_con_ind()
552 if (msg->header.arglen != sizeof(*ep)) in ng_btsocket_sco_process_lp_discon_ind()
555 ep = (ng_hci_lp_discon_ind_ep *)(msg->data); in ng_btsocket_sco_process_lp_discon_ind()
560 pcb = ng_btsocket_sco_pcb_by_handle(&rt->src, ep->con_handle); in ng_btsocket_sco_process_lp_discon_ind()
577 pcb->src.b[5], pcb->src.b[4], pcb->src.b[3], in ng_btsocket_sco_process_lp_discon_ind()
578 pcb->src.b[2], pcb->src.b[1], pcb->src.b[0], in ng_btsocket_sco_process_lp_discon_ind()
579 pcb->dst.b[5], pcb->dst.b[4], pcb->dst.b[3], in ng_btsocket_sco_process_lp_discon_ind()
580 pcb->dst.b[2], pcb->dst.b[1], pcb->dst.b[0], in ng_btsocket_sco_process_lp_discon_ind()
581 pcb->con_handle, pcb->state); in ng_btsocket_sco_process_lp_discon_ind()
583 if (pcb->flags & NG_BTSOCKET_SCO_TIMO) in ng_btsocket_sco_process_lp_discon_ind()
586 pcb->state = NG_BTSOCKET_SCO_CLOSED; in ng_btsocket_sco_process_lp_discon_ind()
587 soisdisconnected(pcb->so); in ng_btsocket_sco_process_lp_discon_ind()
589 mtx_unlock(&pcb->pcb_mtx); in ng_btsocket_sco_process_lp_discon_ind()
606 mtx_assert(&pcb->pcb_mtx, MA_OWNED); in ng_btsocket_sco_send_lp_con_req()
608 if (pcb->rt == NULL || in ng_btsocket_sco_send_lp_con_req()
609 pcb->rt->hook == NULL || NG_HOOK_NOT_VALID(pcb->rt->hook)) in ng_btsocket_sco_send_lp_con_req()
617 ep = (ng_hci_lp_con_req_ep *)(msg->data); in ng_btsocket_sco_send_lp_con_req()
618 ep->link_type = NG_HCI_LINK_SCO; in ng_btsocket_sco_send_lp_con_req()
619 bcopy(&pcb->dst, &ep->bdaddr, sizeof(ep->bdaddr)); in ng_btsocket_sco_send_lp_con_req()
621 NG_SEND_MSG_HOOK(error, ng_btsocket_sco_node, msg, pcb->rt->hook, 0); in ng_btsocket_sco_send_lp_con_req()
637 if (rt == NULL || rt->hook == NULL || NG_HOOK_NOT_VALID(rt->hook)) in ng_btsocket_sco_send_lp_con_rsp()
645 ep = (ng_hci_lp_con_rsp_ep *)(msg->data); in ng_btsocket_sco_send_lp_con_rsp()
646 ep->status = status; in ng_btsocket_sco_send_lp_con_rsp()
647 ep->link_type = NG_HCI_LINK_SCO; in ng_btsocket_sco_send_lp_con_rsp()
648 bcopy(dst, &ep->bdaddr, sizeof(ep->bdaddr)); in ng_btsocket_sco_send_lp_con_rsp()
650 NG_SEND_MSG_HOOK(error, ng_btsocket_sco_node, msg, rt->hook, 0); in ng_btsocket_sco_send_lp_con_rsp()
666 mtx_assert(&pcb->pcb_mtx, MA_OWNED); in ng_btsocket_sco_send_lp_discon_req()
668 if (pcb->rt == NULL || in ng_btsocket_sco_send_lp_discon_req()
669 pcb->rt->hook == NULL || NG_HOOK_NOT_VALID(pcb->rt->hook)) in ng_btsocket_sco_send_lp_discon_req()
677 ep = (ng_hci_lp_discon_req_ep *)(msg->data); in ng_btsocket_sco_send_lp_discon_req()
678 ep->con_handle = pcb->con_handle; in ng_btsocket_sco_send_lp_discon_req()
679 ep->reason = 0x13; /* User Ended Connection */ in ng_btsocket_sco_send_lp_discon_req()
681 NG_SEND_MSG_HOOK(error, ng_btsocket_sco_node, msg, pcb->rt->hook, 0); in ng_btsocket_sco_send_lp_discon_req()
693 * SCO sockets data input routine
706 "%s: Invalid source hook for SCO data packet\n", __func__); in ng_btsocket_sco_data_input()
713 "%s: Could not find out source bdaddr for SCO data packet\n", __func__); in ng_btsocket_sco_data_input()
718 if (m->m_pkthdr.len < sizeof(*hdr)) { in ng_btsocket_sco_data_input()
720 "%s: SCO data packet too small, len=%d\n", __func__, m->m_pkthdr.len); in ng_btsocket_sco_data_input()
724 if (m->m_len < sizeof(*hdr)) { in ng_btsocket_sco_data_input()
730 /* Strip SCO packet header and verify packet length */ in ng_btsocket_sco_data_input()
734 if (hdr->length != m->m_pkthdr.len) { in ng_btsocket_sco_data_input()
736 "%s: Bad SCO data packet length, len=%d, length=%d\n", in ng_btsocket_sco_data_input()
737 __func__, m->m_pkthdr.len, hdr->length); in ng_btsocket_sco_data_input()
745 con_handle = NG_HCI_CON_HANDLE(le16toh(hdr->con_handle)); in ng_btsocket_sco_data_input()
748 "%s: Received SCO data packet: src bdaddr=%x:%x:%x:%x:%x:%x, handle=%d, " \ in ng_btsocket_sco_data_input()
750 rt->src.b[5], rt->src.b[4], rt->src.b[3], in ng_btsocket_sco_data_input()
751 rt->src.b[2], rt->src.b[1], rt->src.b[0], in ng_btsocket_sco_data_input()
752 con_handle, hdr->length); in ng_btsocket_sco_data_input()
757 pcb = ng_btsocket_sco_pcb_by_handle(&rt->src, con_handle); in ng_btsocket_sco_data_input()
765 if (pcb->state != NG_BTSOCKET_SCO_OPEN) { in ng_btsocket_sco_data_input()
769 rt->src.b[5], rt->src.b[4], rt->src.b[3], in ng_btsocket_sco_data_input()
770 rt->src.b[2], rt->src.b[1], rt->src.b[0], in ng_btsocket_sco_data_input()
771 pcb->state); in ng_btsocket_sco_data_input()
773 mtx_unlock(&pcb->pcb_mtx); in ng_btsocket_sco_data_input()
779 if (m->m_pkthdr.len > sbspace(&pcb->so->so_rcv)) { in ng_btsocket_sco_data_input()
781 "%s: Not enough space in socket receive queue. Dropping SCO data packet, " \ in ng_btsocket_sco_data_input()
784 rt->src.b[5], rt->src.b[4], rt->src.b[3], in ng_btsocket_sco_data_input()
785 rt->src.b[2], rt->src.b[1], rt->src.b[0], in ng_btsocket_sco_data_input()
786 m->m_pkthdr.len, in ng_btsocket_sco_data_input()
787 sbspace(&pcb->so->so_rcv)); in ng_btsocket_sco_data_input()
789 mtx_unlock(&pcb->pcb_mtx); in ng_btsocket_sco_data_input()
795 sbappendrecord(&pcb->so->so_rcv, m); in ng_btsocket_sco_data_input()
798 sorwakeup(pcb->so); in ng_btsocket_sco_data_input()
800 mtx_unlock(&pcb->pcb_mtx); in ng_btsocket_sco_data_input()
807 * SCO sockets default message input routine
820 switch (msg->header.cmd) { in ng_btsocket_sco_default_msg_input()
824 if (msg->header.arglen != sizeof(*ep)) in ng_btsocket_sco_default_msg_input()
827 ep = (ng_hci_node_up_ep *)(msg->data); in ng_btsocket_sco_default_msg_input()
828 if (bcmp(&ep->bdaddr, NG_HCI_BDADDR_ANY, sizeof(bdaddr_t)) == 0) in ng_btsocket_sco_default_msg_input()
845 bcopy(&ep->bdaddr, &rt->src, sizeof(rt->src)); in ng_btsocket_sco_default_msg_input()
846 rt->pkt_size = (ep->pkt_size == 0)? 60 : ep->pkt_size; in ng_btsocket_sco_default_msg_input()
847 rt->num_pkts = ep->num_pkts; in ng_btsocket_sco_default_msg_input()
848 rt->hook = hook; in ng_btsocket_sco_default_msg_input()
855 rt->src.b[5], rt->src.b[4], rt->src.b[3], in ng_btsocket_sco_default_msg_input()
856 rt->src.b[2], rt->src.b[1], rt->src.b[0], in ng_btsocket_sco_default_msg_input()
857 rt->pkt_size, rt->num_pkts); in ng_btsocket_sco_default_msg_input()
864 if (rt == NULL || msg->header.arglen != sizeof(*ep)) in ng_btsocket_sco_default_msg_input()
867 ep = (ng_hci_sync_con_queue_ep *)(msg->data); in ng_btsocket_sco_default_msg_input()
869 rt->pending -= ep->completed; in ng_btsocket_sco_default_msg_input()
870 if (rt->pending < 0) { in ng_btsocket_sco_default_msg_input()
875 rt->src.b[5], rt->src.b[4], rt->src.b[3], in ng_btsocket_sco_default_msg_input()
876 rt->src.b[2], rt->src.b[1], rt->src.b[0], in ng_btsocket_sco_default_msg_input()
877 ep->con_handle, rt->pending, in ng_btsocket_sco_default_msg_input()
878 ep->completed); in ng_btsocket_sco_default_msg_input()
880 rt->pending = 0; in ng_btsocket_sco_default_msg_input()
886 pcb = ng_btsocket_sco_pcb_by_handle(&rt->src, ep->con_handle); in ng_btsocket_sco_default_msg_input()
895 if (pcb->state == NG_BTSOCKET_SCO_OPEN) { in ng_btsocket_sco_default_msg_input()
900 for (; ep->completed > 0; ep->completed --) in ng_btsocket_sco_default_msg_input()
901 sbdroprecord(&pcb->so->so_snd); in ng_btsocket_sco_default_msg_input()
904 if (sbavail(&pcb->so->so_snd) > 0) in ng_btsocket_sco_default_msg_input()
909 sowwakeup(pcb->so); in ng_btsocket_sco_default_msg_input()
912 mtx_unlock(&pcb->pcb_mtx); in ng_btsocket_sco_default_msg_input()
918 "%s: Unknown message, cmd=%d\n", __func__, msg->header.cmd); in ng_btsocket_sco_default_msg_input()
926 * SCO sockets LP message input routine
947 switch (msg->header.cmd) { in ng_btsocket_sco_lp_msg_input()
964 "%s: Unknown LP message, cmd=%d\n", __func__, msg->header.cmd); in ng_btsocket_sco_lp_msg_input()
972 * SCO sockets input routine
993 switch(item->el_flags & NGQF_TYPE) { in ng_btsocket_sco_input()
1006 switch (msg->header.cmd) { in ng_btsocket_sco_input()
1022 ("%s: invalid item type=%ld\n", __func__, (item->el_flags & NGQF_TYPE))); in ng_btsocket_sco_input()
1051 mtx_lock(&pcb->pcb_mtx); in ng_btsocket_sco_rtclean()
1054 if (pcb->rt != NULL && in ng_btsocket_sco_rtclean()
1055 pcb->rt->hook != NULL && NG_HOOK_NOT_VALID(pcb->rt->hook)) { in ng_btsocket_sco_rtclean()
1056 if (pcb->flags & NG_BTSOCKET_SCO_TIMO) in ng_btsocket_sco_rtclean()
1059 pcb->rt = NULL; in ng_btsocket_sco_rtclean()
1060 pcb->so->so_error = ENETDOWN; in ng_btsocket_sco_rtclean()
1061 pcb->state = NG_BTSOCKET_SCO_CLOSED; in ng_btsocket_sco_rtclean()
1062 soisdisconnected(pcb->so); in ng_btsocket_sco_rtclean()
1065 mtx_unlock(&pcb->pcb_mtx); in ng_btsocket_sco_rtclean()
1072 * Now cleanup routing table in ng_btsocket_sco_rtclean()
1080 if (rt->hook != NULL && NG_HOOK_NOT_VALID(rt->hook)) { in ng_btsocket_sco_rtclean()
1083 NG_HOOK_SET_PRIVATE(rt->hook, NULL); in ng_btsocket_sco_rtclean()
1084 NG_HOOK_UNREF(rt->hook); /* Remove extra reference */ in ng_btsocket_sco_rtclean()
1151 /* Routing table */ in ng_btsocket_sco_init()
1168 so->so_error = ECONNABORTED; in ng_btsocket_sco_abort()
1192 if (so->so_type != SOCK_SEQPACKET) in ng_btsocket_sco_attach()
1205 if ((so->so_snd.sb_hiwat == 0) || (so->so_rcv.sb_hiwat == 0)) { in ng_btsocket_sco_attach()
1219 so->so_pcb = (caddr_t) pcb; in ng_btsocket_sco_attach()
1220 pcb->so = so; in ng_btsocket_sco_attach()
1221 pcb->state = NG_BTSOCKET_SCO_CLOSED; in ng_btsocket_sco_attach()
1223 callout_init(&pcb->timo, 1); in ng_btsocket_sco_attach()
1227 * the same type" message. When accepting new SCO connection in ng_btsocket_sco_attach()
1232 mtx_init(&pcb->pcb_mtx, "btsocks_sco_pcb_mtx", NULL, in ng_btsocket_sco_attach()
1284 if (sa->sco_family != AF_BLUETOOTH) in ng_btsocket_sco_bind()
1286 if (sa->sco_len != sizeof(*sa)) in ng_btsocket_sco_bind()
1296 if (bcmp(&sa->sco_bdaddr, NG_HCI_BDADDR_ANY, sizeof(sa->sco_bdaddr)) != 0) { in ng_btsocket_sco_bind()
1298 mtx_lock(&pcb->pcb_mtx); in ng_btsocket_sco_bind()
1300 if (bcmp(&pcb->src, &sa->sco_bdaddr, sizeof(bdaddr_t)) == 0) { in ng_btsocket_sco_bind()
1301 mtx_unlock(&pcb->pcb_mtx); in ng_btsocket_sco_bind()
1307 mtx_unlock(&pcb->pcb_mtx); in ng_btsocket_sco_bind()
1317 mtx_lock(&pcb->pcb_mtx); in ng_btsocket_sco_bind()
1318 bcopy(&sa->sco_bdaddr, &pcb->src, sizeof(pcb->src)); in ng_btsocket_sco_bind()
1319 mtx_unlock(&pcb->pcb_mtx); in ng_btsocket_sco_bind()
1348 if (sa->sco_family != AF_BLUETOOTH) in ng_btsocket_sco_connect()
1350 if (sa->sco_len != sizeof(*sa)) in ng_btsocket_sco_connect()
1352 if (bcmp(&sa->sco_bdaddr, NG_HCI_BDADDR_ANY, sizeof(bdaddr_t)) == 0) in ng_btsocket_sco_connect()
1356 * Routing. Socket should be bound to some source address. The source in ng_btsocket_sco_connect()
1363 mtx_lock(&pcb->pcb_mtx); in ng_btsocket_sco_connect()
1365 if (pcb->state == NG_BTSOCKET_SCO_CONNECTING) { in ng_btsocket_sco_connect()
1366 mtx_unlock(&pcb->pcb_mtx); in ng_btsocket_sco_connect()
1372 if (bcmp(&sa->sco_bdaddr, &pcb->src, sizeof(pcb->src)) == 0) { in ng_btsocket_sco_connect()
1373 mtx_unlock(&pcb->pcb_mtx); in ng_btsocket_sco_connect()
1380 bcopy(&sa->sco_bdaddr, &pcb->dst, sizeof(pcb->dst)); in ng_btsocket_sco_connect()
1382 pcb->rt = NULL; in ng_btsocket_sco_connect()
1383 have_src = bcmp(&pcb->src, NG_HCI_BDADDR_ANY, sizeof(pcb->src)); in ng_btsocket_sco_connect()
1386 if (rt->hook == NULL || NG_HOOK_NOT_VALID(rt->hook)) in ng_btsocket_sco_connect()
1391 if (bcmp(&pcb->src, &rt->src, sizeof(rt->src)) == 0) in ng_btsocket_sco_connect()
1394 if (bcmp(&pcb->dst, &rt->src, sizeof(rt->src)) != 0) in ng_btsocket_sco_connect()
1400 pcb->rt = rt; in ng_btsocket_sco_connect()
1403 bcopy(&rt->src, &pcb->src, sizeof(pcb->src)); in ng_btsocket_sco_connect()
1414 pcb->flags |= NG_BTSOCKET_SCO_CLIENT; in ng_btsocket_sco_connect()
1415 pcb->state = NG_BTSOCKET_SCO_CONNECTING; in ng_btsocket_sco_connect()
1416 soisconnecting(pcb->so); in ng_btsocket_sco_connect()
1422 mtx_unlock(&pcb->pcb_mtx); in ng_btsocket_sco_connect()
1454 if (sopt->sopt_level != SOL_SCO) in ng_btsocket_sco_ctloutput()
1457 mtx_lock(&pcb->pcb_mtx); in ng_btsocket_sco_ctloutput()
1459 switch (sopt->sopt_dir) { in ng_btsocket_sco_ctloutput()
1461 if (pcb->state != NG_BTSOCKET_SCO_OPEN) { in ng_btsocket_sco_ctloutput()
1466 switch (sopt->sopt_name) { in ng_btsocket_sco_ctloutput()
1468 tmp = pcb->rt->pkt_size; in ng_btsocket_sco_ctloutput()
1473 tmp = pcb->con_handle; in ng_btsocket_sco_ctloutput()
1492 mtx_unlock(&pcb->pcb_mtx); in ng_btsocket_sco_ctloutput()
1512 mtx_lock(&pcb->pcb_mtx); in ng_btsocket_sco_detach()
1514 if (pcb->flags & NG_BTSOCKET_SCO_TIMO) in ng_btsocket_sco_detach()
1517 if (pcb->state == NG_BTSOCKET_SCO_OPEN) in ng_btsocket_sco_detach()
1520 pcb->state = NG_BTSOCKET_SCO_CLOSED; in ng_btsocket_sco_detach()
1524 mtx_unlock(&pcb->pcb_mtx); in ng_btsocket_sco_detach()
1527 mtx_destroy(&pcb->pcb_mtx); in ng_btsocket_sco_detach()
1532 so->so_pcb = NULL; in ng_btsocket_sco_detach()
1549 mtx_lock(&pcb->pcb_mtx); in ng_btsocket_sco_disconnect()
1551 if (pcb->state == NG_BTSOCKET_SCO_DISCONNECTING) { in ng_btsocket_sco_disconnect()
1552 mtx_unlock(&pcb->pcb_mtx); in ng_btsocket_sco_disconnect()
1557 if (pcb->flags & NG_BTSOCKET_SCO_TIMO) in ng_btsocket_sco_disconnect()
1560 if (pcb->state == NG_BTSOCKET_SCO_OPEN) { in ng_btsocket_sco_disconnect()
1563 pcb->state = NG_BTSOCKET_SCO_DISCONNECTING; in ng_btsocket_sco_disconnect()
1568 pcb->state = NG_BTSOCKET_SCO_CLOSED; in ng_btsocket_sco_disconnect()
1572 mtx_unlock(&pcb->pcb_mtx); in ng_btsocket_sco_disconnect()
1593 mtx_lock(&pcb->pcb_mtx); in ng_btsocket_sco_listen()
1599 if (bcmp(&pcb->src, NG_HCI_BDADDR_ANY, sizeof(bdaddr_t)) == 0) { in ng_btsocket_sco_listen()
1606 mtx_unlock(&pcb->pcb_mtx); in ng_btsocket_sco_listen()
1620 struct sockaddr_sco *sco = (struct sockaddr_sco *)sa; in ng_btsocket_sco_peeraddr() local
1627 *sco = (struct sockaddr_sco ){ in ng_btsocket_sco_peeraddr()
1631 mtx_lock(&pcb->pcb_mtx); in ng_btsocket_sco_peeraddr()
1632 bcopy(&pcb->dst, &sco->sco_bdaddr, sizeof(sco->sco_bdaddr)); in ng_btsocket_sco_peeraddr()
1633 mtx_unlock(&pcb->pcb_mtx); in ng_btsocket_sco_peeraddr()
1660 mtx_lock(&pcb->pcb_mtx); in ng_btsocket_sco_send()
1663 if (pcb->state != NG_BTSOCKET_SCO_OPEN) { in ng_btsocket_sco_send()
1664 mtx_unlock(&pcb->pcb_mtx); in ng_btsocket_sco_send()
1670 if (pcb->rt == NULL || in ng_btsocket_sco_send()
1671 pcb->rt->hook == NULL || NG_HOOK_NOT_VALID(pcb->rt->hook)) { in ng_btsocket_sco_send()
1672 mtx_unlock(&pcb->pcb_mtx); in ng_btsocket_sco_send()
1678 if (m->m_pkthdr.len > pcb->rt->pkt_size) { in ng_btsocket_sco_send()
1681 __func__, m->m_pkthdr.len, pcb->rt->pkt_size); in ng_btsocket_sco_send()
1683 mtx_unlock(&pcb->pcb_mtx); in ng_btsocket_sco_send()
1695 sbappendrecord(&pcb->so->so_snd, m); in ng_btsocket_sco_send()
1698 if (!(pcb->flags & NG_BTSOCKET_SCO_TIMO)) { in ng_btsocket_sco_send()
1703 sbdroprecord(&pcb->so->so_snd); /* XXX */ in ng_btsocket_sco_send()
1706 mtx_unlock(&pcb->pcb_mtx); in ng_btsocket_sco_send()
1715 * Send first packet in the socket queue to the SCO layer
1725 mtx_assert(&pcb->pcb_mtx, MA_OWNED); in ng_btsocket_sco_send2()
1727 while (pcb->rt->pending < pcb->rt->num_pkts && in ng_btsocket_sco_send2()
1728 sbavail(&pcb->so->so_snd) > 0) { in ng_btsocket_sco_send2()
1730 m = m_dup(pcb->so->so_snd.sb_mb, M_NOWAIT); in ng_btsocket_sco_send2()
1736 /* Create SCO packet header */ in ng_btsocket_sco_send2()
1739 if (m->m_len < sizeof(*hdr)) in ng_btsocket_sco_send2()
1749 hdr->type = NG_HCI_SCO_DATA_PKT; in ng_btsocket_sco_send2()
1750 hdr->con_handle = htole16(NG_HCI_MK_CON_HANDLE(pcb->con_handle, 0, 0)); in ng_btsocket_sco_send2()
1751 hdr->length = m->m_pkthdr.len - sizeof(*hdr); in ng_btsocket_sco_send2()
1754 NG_SEND_DATA_ONLY(error, pcb->rt->hook, m); in ng_btsocket_sco_send2()
1758 pcb->rt->pending ++; in ng_btsocket_sco_send2()
1761 return ((pcb->rt->pending > 0)? 0 : error); in ng_btsocket_sco_send2()
1772 struct sockaddr_sco *sco = (struct sockaddr_sco *)sa; in ng_btsocket_sco_sockaddr() local
1779 *sco = (struct sockaddr_sco ){ in ng_btsocket_sco_sockaddr()
1783 mtx_lock(&pcb->pcb_mtx); in ng_btsocket_sco_sockaddr()
1784 bcopy(&pcb->src, &sco->sco_bdaddr, sizeof(sco->sco_bdaddr)); in ng_btsocket_sco_sockaddr()
1785 mtx_unlock(&pcb->pcb_mtx); in ng_btsocket_sco_sockaddr()
1811 mtx_lock(&p->pcb_mtx); in ng_btsocket_sco_pcb_by_addr()
1813 if (p->so == NULL || !SOLISTENING(p->so)) { in ng_btsocket_sco_pcb_by_addr()
1814 mtx_unlock(&p->pcb_mtx); in ng_btsocket_sco_pcb_by_addr()
1818 if (bcmp(&p->src, bdaddr, sizeof(p->src)) == 0) in ng_btsocket_sco_pcb_by_addr()
1821 if (bcmp(&p->src, NG_HCI_BDADDR_ANY, sizeof(p->src)) == 0) in ng_btsocket_sco_pcb_by_addr()
1824 mtx_unlock(&p->pcb_mtx); in ng_btsocket_sco_pcb_by_addr()
1828 mtx_lock(&p1->pcb_mtx); in ng_btsocket_sco_pcb_by_addr()
1847 mtx_lock(&p->pcb_mtx); in ng_btsocket_sco_pcb_by_handle()
1849 if (p->con_handle == con_handle && in ng_btsocket_sco_pcb_by_handle()
1850 bcmp(src, &p->src, sizeof(p->src)) == 0) in ng_btsocket_sco_pcb_by_handle()
1853 mtx_unlock(&p->pcb_mtx); in ng_btsocket_sco_pcb_by_handle()
1873 mtx_lock(&p->pcb_mtx); in ng_btsocket_sco_pcb_by_addrs()
1875 if (p->state == NG_BTSOCKET_SCO_CONNECTING && in ng_btsocket_sco_pcb_by_addrs()
1876 bcmp(src, &p->src, sizeof(p->src)) == 0 && in ng_btsocket_sco_pcb_by_addrs()
1877 bcmp(dst, &p->dst, sizeof(p->dst)) == 0) in ng_btsocket_sco_pcb_by_addrs()
1880 mtx_unlock(&p->pcb_mtx); in ng_btsocket_sco_pcb_by_addrs()
1893 mtx_assert(&pcb->pcb_mtx, MA_OWNED); in ng_btsocket_sco_timeout()
1895 if (!(pcb->flags & NG_BTSOCKET_SCO_TIMO)) { in ng_btsocket_sco_timeout()
1896 pcb->flags |= NG_BTSOCKET_SCO_TIMO; in ng_btsocket_sco_timeout()
1897 callout_reset(&pcb->timo, bluetooth_sco_rtx_timeout(), in ng_btsocket_sco_timeout()
1911 mtx_assert(&pcb->pcb_mtx, MA_OWNED); in ng_btsocket_sco_untimeout()
1913 if (pcb->flags & NG_BTSOCKET_SCO_TIMO) { in ng_btsocket_sco_untimeout()
1914 callout_stop(&pcb->timo); in ng_btsocket_sco_untimeout()
1915 pcb->flags &= ~NG_BTSOCKET_SCO_TIMO; in ng_btsocket_sco_untimeout()
1930 mtx_lock(&pcb->pcb_mtx); in ng_btsocket_sco_process_timeout()
1932 pcb->flags &= ~NG_BTSOCKET_SCO_TIMO; in ng_btsocket_sco_process_timeout()
1933 pcb->so->so_error = ETIMEDOUT; in ng_btsocket_sco_process_timeout()
1935 switch (pcb->state) { in ng_btsocket_sco_process_timeout()
1937 /* Connect timeout - close the socket */ in ng_btsocket_sco_process_timeout()
1938 pcb->state = NG_BTSOCKET_SCO_CLOSED; in ng_btsocket_sco_process_timeout()
1939 soisdisconnected(pcb->so); in ng_btsocket_sco_process_timeout()
1943 /* Send timeout - did not get NGM_HCI_SYNC_CON_QUEUE */ in ng_btsocket_sco_process_timeout()
1944 sbdroprecord(&pcb->so->so_snd); in ng_btsocket_sco_process_timeout()
1945 sowwakeup(pcb->so); in ng_btsocket_sco_process_timeout()
1946 /* XXX FIXME what to do with pcb->rt->pending??? */ in ng_btsocket_sco_process_timeout()
1950 /* Disconnect timeout - disconnect the socket anyway */ in ng_btsocket_sco_process_timeout()
1951 pcb->state = NG_BTSOCKET_SCO_CLOSED; in ng_btsocket_sco_process_timeout()
1952 soisdisconnected(pcb->so); in ng_btsocket_sco_process_timeout()
1957 "%s: Invalid socket state=%d\n", __func__, pcb->state); in ng_btsocket_sco_process_timeout()
1961 mtx_unlock(&pcb->pcb_mtx); in ng_btsocket_sco_process_timeout()