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>
327 * the routing table and must schedule cleaning for the routing table. in ng_btsocket_l2cap_node_disconnect()
329 * so we have never added this hook to the routing table and it save in ng_btsocket_l2cap_node_disconnect()
351 if (msg != NULL && msg->header.typecookie == NGM_L2CAP_COOKIE) { in ng_btsocket_l2cap_node_rcvmsg()
420 if (msg->header.arglen != sizeof(*op)) in ng_btsocket_l2cap_process_l2ca_con_req_rsp()
423 op = (ng_l2cap_l2ca_con_op *)(msg->data); in ng_btsocket_l2cap_process_l2ca_con_req_rsp()
428 pcb = ng_btsocket_l2cap_pcb_by_token(msg->header.token); in ng_btsocket_l2cap_process_l2ca_con_req_rsp()
434 mtx_lock(&pcb->pcb_mtx); in ng_btsocket_l2cap_process_l2ca_con_req_rsp()
439 "state=%d\n", __func__, msg->header.token, in ng_btsocket_l2cap_process_l2ca_con_req_rsp()
440 pcb->src.b[5], pcb->src.b[4], pcb->src.b[3], in ng_btsocket_l2cap_process_l2ca_con_req_rsp()
441 pcb->src.b[2], pcb->src.b[1], pcb->src.b[0], in ng_btsocket_l2cap_process_l2ca_con_req_rsp()
442 pcb->dst.b[5], pcb->dst.b[4], pcb->dst.b[3], in ng_btsocket_l2cap_process_l2ca_con_req_rsp()
443 pcb->dst.b[2], pcb->dst.b[1], pcb->dst.b[0], in ng_btsocket_l2cap_process_l2ca_con_req_rsp()
444 pcb->psm, op->lcid, op->result, op->status, in ng_btsocket_l2cap_process_l2ca_con_req_rsp()
445 pcb->state); in ng_btsocket_l2cap_process_l2ca_con_req_rsp()
447 if (pcb->state != NG_BTSOCKET_L2CAP_CONNECTING) { in ng_btsocket_l2cap_process_l2ca_con_req_rsp()
448 mtx_unlock(&pcb->pcb_mtx); in ng_btsocket_l2cap_process_l2ca_con_req_rsp()
456 if (op->result == NG_L2CAP_PENDING) { in ng_btsocket_l2cap_process_l2ca_con_req_rsp()
458 mtx_unlock(&pcb->pcb_mtx); in ng_btsocket_l2cap_process_l2ca_con_req_rsp()
464 if (op->result == NG_L2CAP_SUCCESS){ in ng_btsocket_l2cap_process_l2ca_con_req_rsp()
465 if((pcb->idtype == NG_L2CAP_L2CA_IDTYPE_ATT)|| in ng_btsocket_l2cap_process_l2ca_con_req_rsp()
466 (pcb->idtype == NG_L2CAP_L2CA_IDTYPE_SMP)){ in ng_btsocket_l2cap_process_l2ca_con_req_rsp()
467 pcb->encryption = op->encryption; pcb->cid = op->lcid; in ng_btsocket_l2cap_process_l2ca_con_req_rsp()
468 if(pcb->need_encrypt && !(pcb->encryption)){ in ng_btsocket_l2cap_process_l2ca_con_req_rsp()
470 pcb->state = NG_BTSOCKET_L2CAP_W4_ENC_CHANGE; in ng_btsocket_l2cap_process_l2ca_con_req_rsp()
472 pcb->state = NG_BTSOCKET_L2CAP_OPEN; in ng_btsocket_l2cap_process_l2ca_con_req_rsp()
473 soisconnected(pcb->so); in ng_btsocket_l2cap_process_l2ca_con_req_rsp()
482 pcb->cid = op->lcid; in ng_btsocket_l2cap_process_l2ca_con_req_rsp()
483 pcb->encryption = op->encryption; in ng_btsocket_l2cap_process_l2ca_con_req_rsp()
490 pcb->state = NG_BTSOCKET_L2CAP_CLOSED; in ng_btsocket_l2cap_process_l2ca_con_req_rsp()
491 soisdisconnected(pcb->so); in ng_btsocket_l2cap_process_l2ca_con_req_rsp()
493 pcb->cfg_state = NG_BTSOCKET_L2CAP_CFG_IN_SENT; in ng_btsocket_l2cap_process_l2ca_con_req_rsp()
494 pcb->state = NG_BTSOCKET_L2CAP_CONFIGURING; in ng_btsocket_l2cap_process_l2ca_con_req_rsp()
506 pcb->so->so_error = ng_btsocket_l2cap_result2errno(op->result); in ng_btsocket_l2cap_process_l2ca_con_req_rsp()
507 pcb->state = NG_BTSOCKET_L2CAP_CLOSED; in ng_btsocket_l2cap_process_l2ca_con_req_rsp()
508 soisdisconnected(pcb->so); in ng_btsocket_l2cap_process_l2ca_con_req_rsp()
510 mtx_unlock(&pcb->pcb_mtx); in ng_btsocket_l2cap_process_l2ca_con_req_rsp()
527 if (msg->header.arglen != sizeof(*op)) in ng_btsocket_l2cap_process_l2ca_con_rsp_rsp()
530 op = (ng_l2cap_l2ca_con_rsp_op *)(msg->data); in ng_btsocket_l2cap_process_l2ca_con_rsp_rsp()
535 pcb = ng_btsocket_l2cap_pcb_by_token(msg->header.token); in ng_btsocket_l2cap_process_l2ca_con_rsp_rsp()
541 mtx_lock(&pcb->pcb_mtx); in ng_btsocket_l2cap_process_l2ca_con_rsp_rsp()
546 __func__, msg->header.token, in ng_btsocket_l2cap_process_l2ca_con_rsp_rsp()
547 pcb->src.b[5], pcb->src.b[4], pcb->src.b[3], in ng_btsocket_l2cap_process_l2ca_con_rsp_rsp()
548 pcb->src.b[2], pcb->src.b[1], pcb->src.b[0], in ng_btsocket_l2cap_process_l2ca_con_rsp_rsp()
549 pcb->dst.b[5], pcb->dst.b[4], pcb->dst.b[3], in ng_btsocket_l2cap_process_l2ca_con_rsp_rsp()
550 pcb->dst.b[2], pcb->dst.b[1], pcb->dst.b[0], in ng_btsocket_l2cap_process_l2ca_con_rsp_rsp()
551 pcb->psm, pcb->cid, op->result, pcb->state); in ng_btsocket_l2cap_process_l2ca_con_rsp_rsp()
553 if (pcb->state != NG_BTSOCKET_L2CAP_CONNECTING) { in ng_btsocket_l2cap_process_l2ca_con_rsp_rsp()
554 mtx_unlock(&pcb->pcb_mtx); in ng_btsocket_l2cap_process_l2ca_con_rsp_rsp()
563 if (op->result != NG_L2CAP_SUCCESS) { in ng_btsocket_l2cap_process_l2ca_con_rsp_rsp()
564 /* Close the socket - channel already closed */ in ng_btsocket_l2cap_process_l2ca_con_rsp_rsp()
565 pcb->so->so_error = ng_btsocket_l2cap_result2errno(op->result); in ng_btsocket_l2cap_process_l2ca_con_rsp_rsp()
566 pcb->state = NG_BTSOCKET_L2CAP_CLOSED; in ng_btsocket_l2cap_process_l2ca_con_rsp_rsp()
567 soisdisconnected(pcb->so); in ng_btsocket_l2cap_process_l2ca_con_rsp_rsp()
570 pcb->cfg_state = 0; in ng_btsocket_l2cap_process_l2ca_con_rsp_rsp()
571 pcb->state = NG_BTSOCKET_L2CAP_CONFIGURING; in ng_btsocket_l2cap_process_l2ca_con_rsp_rsp()
575 mtx_unlock(&pcb->pcb_mtx); in ng_btsocket_l2cap_process_l2ca_con_rsp_rsp()
597 if (msg->header.arglen != sizeof(*ip)) in ng_btsocket_l2cap_process_l2ca_con_ind()
600 ip = (ng_l2cap_l2ca_con_ind_ip *)(msg->data); in ng_btsocket_l2cap_process_l2ca_con_ind()
606 rt->src.b[5], rt->src.b[4], rt->src.b[3], in ng_btsocket_l2cap_process_l2ca_con_ind()
607 rt->src.b[2], rt->src.b[1], rt->src.b[0], in ng_btsocket_l2cap_process_l2ca_con_ind()
608 ip->bdaddr.b[5], ip->bdaddr.b[4], ip->bdaddr.b[3], in ng_btsocket_l2cap_process_l2ca_con_ind()
609 ip->bdaddr.b[2], ip->bdaddr.b[1], ip->bdaddr.b[0], in ng_btsocket_l2cap_process_l2ca_con_ind()
610 ip->psm, ip->lcid, ip->ident); in ng_btsocket_l2cap_process_l2ca_con_ind()
614 pcb = ng_btsocket_l2cap_pcb_by_addr(&rt->src, ip->psm); in ng_btsocket_l2cap_process_l2ca_con_ind()
618 mtx_lock(&pcb->pcb_mtx); in ng_btsocket_l2cap_process_l2ca_con_ind()
620 CURVNET_SET(pcb->so->so_vnet); in ng_btsocket_l2cap_process_l2ca_con_ind()
621 so1 = sonewconn(pcb->so, 0); in ng_btsocket_l2cap_process_l2ca_con_ind()
632 * address from hook's routing information. in ng_btsocket_l2cap_process_l2ca_con_ind()
639 mtx_lock(&pcb1->pcb_mtx); in ng_btsocket_l2cap_process_l2ca_con_ind()
641 if (bcmp(&pcb->src, NG_HCI_BDADDR_ANY, sizeof(pcb->src)) != 0) in ng_btsocket_l2cap_process_l2ca_con_ind()
642 bcopy(&pcb->src, &pcb1->src, sizeof(pcb1->src)); in ng_btsocket_l2cap_process_l2ca_con_ind()
644 bcopy(&rt->src, &pcb1->src, sizeof(pcb1->src)); in ng_btsocket_l2cap_process_l2ca_con_ind()
646 pcb1->flags &= ~NG_BTSOCKET_L2CAP_CLIENT; in ng_btsocket_l2cap_process_l2ca_con_ind()
648 bcopy(&ip->bdaddr, &pcb1->dst, sizeof(pcb1->dst)); in ng_btsocket_l2cap_process_l2ca_con_ind()
649 pcb1->psm = ip->psm; in ng_btsocket_l2cap_process_l2ca_con_ind()
650 pcb1->cid = ip->lcid; in ng_btsocket_l2cap_process_l2ca_con_ind()
651 pcb1->rt = rt; in ng_btsocket_l2cap_process_l2ca_con_ind()
654 pcb1->imtu = pcb->imtu; in ng_btsocket_l2cap_process_l2ca_con_ind()
655 bcopy(&pcb->oflow, &pcb1->oflow, sizeof(pcb1->oflow)); in ng_btsocket_l2cap_process_l2ca_con_ind()
656 pcb1->flush_timo = pcb->flush_timo; in ng_btsocket_l2cap_process_l2ca_con_ind()
658 token = pcb1->token; in ng_btsocket_l2cap_process_l2ca_con_ind()
665 &ip->bdaddr, in ng_btsocket_l2cap_process_l2ca_con_ind()
666 ip->ident, ip->lcid, in ng_btsocket_l2cap_process_l2ca_con_ind()
667 result,ip->linktype); in ng_btsocket_l2cap_process_l2ca_con_ind()
670 pcb1->so->so_error = error; in ng_btsocket_l2cap_process_l2ca_con_ind()
671 pcb1->state = NG_BTSOCKET_L2CAP_CLOSED; in ng_btsocket_l2cap_process_l2ca_con_ind()
672 soisdisconnected(pcb1->so); in ng_btsocket_l2cap_process_l2ca_con_ind()
674 pcb1->state = NG_BTSOCKET_L2CAP_CONNECTING; in ng_btsocket_l2cap_process_l2ca_con_ind()
675 soisconnecting(pcb1->so); in ng_btsocket_l2cap_process_l2ca_con_ind()
680 mtx_unlock(&pcb1->pcb_mtx); in ng_btsocket_l2cap_process_l2ca_con_ind()
684 mtx_unlock(&pcb->pcb_mtx); in ng_btsocket_l2cap_process_l2ca_con_ind()
696 if (msg->header.arglen != sizeof(*op)) in ng_btsocket_l2cap_process_l2ca_enc_change()
699 op = (ng_l2cap_l2ca_enc_chg_op *)(msg->data); in ng_btsocket_l2cap_process_l2ca_enc_change()
703 pcb = ng_btsocket_l2cap_pcb_by_cid(&rt->src, op->lcid, in ng_btsocket_l2cap_process_l2ca_enc_change()
704 op->idtype); in ng_btsocket_l2cap_process_l2ca_enc_change()
710 mtx_lock(&pcb->pcb_mtx); in ng_btsocket_l2cap_process_l2ca_enc_change()
711 pcb->encryption = op->result; in ng_btsocket_l2cap_process_l2ca_enc_change()
713 if(pcb->need_encrypt){ in ng_btsocket_l2cap_process_l2ca_enc_change()
715 if(pcb->state != NG_BTSOCKET_L2CAP_W4_ENC_CHANGE){ in ng_btsocket_l2cap_process_l2ca_enc_change()
717 __func__, pcb->state); in ng_btsocket_l2cap_process_l2ca_enc_change()
718 }else if(pcb->encryption){ in ng_btsocket_l2cap_process_l2ca_enc_change()
719 pcb->state = NG_BTSOCKET_L2CAP_OPEN; in ng_btsocket_l2cap_process_l2ca_enc_change()
720 soisconnected(pcb->so); in ng_btsocket_l2cap_process_l2ca_enc_change()
722 pcb->so->so_error = EPERM; in ng_btsocket_l2cap_process_l2ca_enc_change()
724 pcb->state = NG_BTSOCKET_L2CAP_CLOSED; in ng_btsocket_l2cap_process_l2ca_enc_change()
725 soisdisconnected(pcb->so); in ng_btsocket_l2cap_process_l2ca_enc_change()
728 mtx_unlock(&pcb->pcb_mtx); in ng_btsocket_l2cap_process_l2ca_enc_change()
744 if (msg->header.arglen != sizeof(*op)) in ng_btsocket_l2cap_process_l2ca_cfg_req_rsp()
747 op = (ng_l2cap_l2ca_cfg_op *)(msg->data); in ng_btsocket_l2cap_process_l2ca_cfg_req_rsp()
757 pcb = ng_btsocket_l2cap_pcb_by_token(msg->header.token); in ng_btsocket_l2cap_process_l2ca_cfg_req_rsp()
769 mtx_lock(&pcb->pcb_mtx); in ng_btsocket_l2cap_process_l2ca_cfg_req_rsp()
775 __func__, msg->header.token, in ng_btsocket_l2cap_process_l2ca_cfg_req_rsp()
776 pcb->src.b[5], pcb->src.b[4], pcb->src.b[3], in ng_btsocket_l2cap_process_l2ca_cfg_req_rsp()
777 pcb->src.b[2], pcb->src.b[1], pcb->src.b[0], in ng_btsocket_l2cap_process_l2ca_cfg_req_rsp()
778 pcb->dst.b[5], pcb->dst.b[4], pcb->dst.b[3], in ng_btsocket_l2cap_process_l2ca_cfg_req_rsp()
779 pcb->dst.b[2], pcb->dst.b[1], pcb->dst.b[0], in ng_btsocket_l2cap_process_l2ca_cfg_req_rsp()
780 pcb->psm, pcb->cid, op->result, pcb->state, pcb->cfg_state); in ng_btsocket_l2cap_process_l2ca_cfg_req_rsp()
782 if (pcb->state != NG_BTSOCKET_L2CAP_CONFIGURING) { in ng_btsocket_l2cap_process_l2ca_cfg_req_rsp()
783 mtx_unlock(&pcb->pcb_mtx); in ng_btsocket_l2cap_process_l2ca_cfg_req_rsp()
789 if (op->result == NG_L2CAP_SUCCESS) { in ng_btsocket_l2cap_process_l2ca_cfg_req_rsp()
797 pcb->imtu = op->imtu; in ng_btsocket_l2cap_process_l2ca_cfg_req_rsp()
798 bcopy(&op->oflow, &pcb->oflow, sizeof(pcb->oflow)); in ng_btsocket_l2cap_process_l2ca_cfg_req_rsp()
799 pcb->flush_timo = op->flush_timo; in ng_btsocket_l2cap_process_l2ca_cfg_req_rsp()
807 pcb->cfg_state &= ~NG_BTSOCKET_L2CAP_CFG_IN_SENT; in ng_btsocket_l2cap_process_l2ca_cfg_req_rsp()
808 pcb->cfg_state |= NG_BTSOCKET_L2CAP_CFG_IN; in ng_btsocket_l2cap_process_l2ca_cfg_req_rsp()
810 if (pcb->cfg_state == NG_BTSOCKET_L2CAP_CFG_BOTH) { in ng_btsocket_l2cap_process_l2ca_cfg_req_rsp()
811 /* Configuration complete - mark socket as open */ in ng_btsocket_l2cap_process_l2ca_cfg_req_rsp()
813 pcb->state = NG_BTSOCKET_L2CAP_OPEN; in ng_btsocket_l2cap_process_l2ca_cfg_req_rsp()
814 soisconnected(pcb->so); in ng_btsocket_l2cap_process_l2ca_cfg_req_rsp()
825 switch (op->result) { in ng_btsocket_l2cap_process_l2ca_cfg_req_rsp()
828 pcb->so->so_error = EINVAL; in ng_btsocket_l2cap_process_l2ca_cfg_req_rsp()
832 pcb->so->so_error = ECONNRESET; in ng_btsocket_l2cap_process_l2ca_cfg_req_rsp()
840 pcb->state = NG_BTSOCKET_L2CAP_CLOSED; in ng_btsocket_l2cap_process_l2ca_cfg_req_rsp()
841 soisdisconnected(pcb->so); in ng_btsocket_l2cap_process_l2ca_cfg_req_rsp()
844 mtx_unlock(&pcb->pcb_mtx); in ng_btsocket_l2cap_process_l2ca_cfg_req_rsp()
862 if (msg->header.arglen != sizeof(*op)) in ng_btsocket_l2cap_process_l2ca_cfg_rsp_rsp()
865 op = (ng_l2cap_l2ca_cfg_rsp_op *)(msg->data); in ng_btsocket_l2cap_process_l2ca_cfg_rsp_rsp()
870 pcb = ng_btsocket_l2cap_pcb_by_token(msg->header.token); in ng_btsocket_l2cap_process_l2ca_cfg_rsp_rsp()
876 mtx_lock(&pcb->pcb_mtx); in ng_btsocket_l2cap_process_l2ca_cfg_rsp_rsp()
882 __func__, msg->header.token, in ng_btsocket_l2cap_process_l2ca_cfg_rsp_rsp()
883 pcb->src.b[5], pcb->src.b[4], pcb->src.b[3], in ng_btsocket_l2cap_process_l2ca_cfg_rsp_rsp()
884 pcb->src.b[2], pcb->src.b[1], pcb->src.b[0], in ng_btsocket_l2cap_process_l2ca_cfg_rsp_rsp()
885 pcb->dst.b[5], pcb->dst.b[4], pcb->dst.b[3], in ng_btsocket_l2cap_process_l2ca_cfg_rsp_rsp()
886 pcb->dst.b[2], pcb->dst.b[1], pcb->dst.b[0], in ng_btsocket_l2cap_process_l2ca_cfg_rsp_rsp()
887 pcb->psm, pcb->cid, op->result, pcb->state, pcb->cfg_state); in ng_btsocket_l2cap_process_l2ca_cfg_rsp_rsp()
889 if (pcb->state != NG_BTSOCKET_L2CAP_CONFIGURING) { in ng_btsocket_l2cap_process_l2ca_cfg_rsp_rsp()
890 mtx_unlock(&pcb->pcb_mtx); in ng_btsocket_l2cap_process_l2ca_cfg_rsp_rsp()
897 if (op->result != NG_L2CAP_SUCCESS) in ng_btsocket_l2cap_process_l2ca_cfg_rsp_rsp()
905 pcb->cfg_state &= ~NG_BTSOCKET_L2CAP_CFG_OUT_SENT; in ng_btsocket_l2cap_process_l2ca_cfg_rsp_rsp()
906 pcb->cfg_state |= NG_BTSOCKET_L2CAP_CFG_OUT; in ng_btsocket_l2cap_process_l2ca_cfg_rsp_rsp()
908 if (pcb->cfg_state == NG_BTSOCKET_L2CAP_CFG_BOTH) { in ng_btsocket_l2cap_process_l2ca_cfg_rsp_rsp()
909 /* Configuration complete - mask socket as open */ in ng_btsocket_l2cap_process_l2ca_cfg_rsp_rsp()
911 pcb->state = NG_BTSOCKET_L2CAP_OPEN; in ng_btsocket_l2cap_process_l2ca_cfg_rsp_rsp()
912 soisconnected(pcb->so); in ng_btsocket_l2cap_process_l2ca_cfg_rsp_rsp()
914 if (!(pcb->cfg_state & NG_BTSOCKET_L2CAP_CFG_IN_SENT)) { in ng_btsocket_l2cap_process_l2ca_cfg_rsp_rsp()
915 /* Send L2CA_Config request - incoming path */ in ng_btsocket_l2cap_process_l2ca_cfg_rsp_rsp()
920 pcb->cfg_state |= NG_BTSOCKET_L2CAP_CFG_IN_SENT; in ng_btsocket_l2cap_process_l2ca_cfg_rsp_rsp()
924 mtx_unlock(&pcb->pcb_mtx); in ng_btsocket_l2cap_process_l2ca_cfg_rsp_rsp()
936 pcb->state = NG_BTSOCKET_L2CAP_CLOSED; in ng_btsocket_l2cap_process_l2ca_cfg_rsp_rsp()
937 soisdisconnected(pcb->so); in ng_btsocket_l2cap_process_l2ca_cfg_rsp_rsp()
939 mtx_unlock(&pcb->pcb_mtx); in ng_btsocket_l2cap_process_l2ca_cfg_rsp_rsp()
957 if (msg->header.arglen != sizeof(*ip)) in ng_btsocket_l2cap_process_l2ca_cfg_ind()
960 ip = (ng_l2cap_l2ca_cfg_ind_ip *)(msg->data); in ng_btsocket_l2cap_process_l2ca_cfg_ind()
965 pcb = ng_btsocket_l2cap_pcb_by_cid(&rt->src, ip->lcid, in ng_btsocket_l2cap_process_l2ca_cfg_ind()
972 mtx_lock(&pcb->pcb_mtx); in ng_btsocket_l2cap_process_l2ca_cfg_ind()
978 pcb->src.b[5], pcb->src.b[4], pcb->src.b[3], in ng_btsocket_l2cap_process_l2ca_cfg_ind()
979 pcb->src.b[2], pcb->src.b[1], pcb->src.b[0], in ng_btsocket_l2cap_process_l2ca_cfg_ind()
980 pcb->dst.b[5], pcb->dst.b[4], pcb->dst.b[3], in ng_btsocket_l2cap_process_l2ca_cfg_ind()
981 pcb->dst.b[2], pcb->dst.b[1], pcb->dst.b[0], in ng_btsocket_l2cap_process_l2ca_cfg_ind()
982 pcb->psm, pcb->cid, pcb->state, pcb->cfg_state); in ng_btsocket_l2cap_process_l2ca_cfg_ind()
984 /* XXX FIXME re-configuration on open socket */ in ng_btsocket_l2cap_process_l2ca_cfg_ind()
985 if (pcb->state != NG_BTSOCKET_L2CAP_CONFIGURING) { in ng_btsocket_l2cap_process_l2ca_cfg_ind()
986 mtx_unlock(&pcb->pcb_mtx); in ng_btsocket_l2cap_process_l2ca_cfg_ind()
998 pcb->omtu = ip->omtu; in ng_btsocket_l2cap_process_l2ca_cfg_ind()
999 bcopy(&ip->iflow, &pcb->iflow, sizeof(pcb->iflow)); in ng_btsocket_l2cap_process_l2ca_cfg_ind()
1000 pcb->flush_timo = ip->flush_timo; in ng_btsocket_l2cap_process_l2ca_cfg_ind()
1007 if (!(pcb->cfg_state & NG_BTSOCKET_L2CAP_CFG_OUT_SENT)) { in ng_btsocket_l2cap_process_l2ca_cfg_ind()
1012 pcb->so->so_error = error; in ng_btsocket_l2cap_process_l2ca_cfg_ind()
1018 pcb->state = NG_BTSOCKET_L2CAP_CLOSED; in ng_btsocket_l2cap_process_l2ca_cfg_ind()
1019 soisdisconnected(pcb->so); in ng_btsocket_l2cap_process_l2ca_cfg_ind()
1021 pcb->cfg_state |= NG_BTSOCKET_L2CAP_CFG_OUT_SENT; in ng_btsocket_l2cap_process_l2ca_cfg_ind()
1024 mtx_unlock(&pcb->pcb_mtx); in ng_btsocket_l2cap_process_l2ca_cfg_ind()
1042 if (msg->header.arglen != sizeof(*op)) in ng_btsocket_l2cap_process_l2ca_discon_rsp()
1045 op = (ng_l2cap_l2ca_discon_op *)(msg->data); in ng_btsocket_l2cap_process_l2ca_discon_rsp()
1055 pcb = ng_btsocket_l2cap_pcb_by_token(msg->header.token); in ng_btsocket_l2cap_process_l2ca_discon_rsp()
1061 mtx_lock(&pcb->pcb_mtx); in ng_btsocket_l2cap_process_l2ca_discon_rsp()
1063 /* XXX Close socket no matter what op->result says */ in ng_btsocket_l2cap_process_l2ca_discon_rsp()
1064 if (pcb->state != NG_BTSOCKET_L2CAP_CLOSED) { in ng_btsocket_l2cap_process_l2ca_discon_rsp()
1068 __func__, msg->header.token, in ng_btsocket_l2cap_process_l2ca_discon_rsp()
1069 pcb->src.b[5], pcb->src.b[4], pcb->src.b[3], in ng_btsocket_l2cap_process_l2ca_discon_rsp()
1070 pcb->src.b[2], pcb->src.b[1], pcb->src.b[0], in ng_btsocket_l2cap_process_l2ca_discon_rsp()
1071 pcb->dst.b[5], pcb->dst.b[4], pcb->dst.b[3], in ng_btsocket_l2cap_process_l2ca_discon_rsp()
1072 pcb->dst.b[2], pcb->dst.b[1], pcb->dst.b[0], in ng_btsocket_l2cap_process_l2ca_discon_rsp()
1073 pcb->psm, pcb->cid, op->result, pcb->state); in ng_btsocket_l2cap_process_l2ca_discon_rsp()
1077 pcb->state = NG_BTSOCKET_L2CAP_CLOSED; in ng_btsocket_l2cap_process_l2ca_discon_rsp()
1078 soisdisconnected(pcb->so); in ng_btsocket_l2cap_process_l2ca_discon_rsp()
1081 mtx_unlock(&pcb->pcb_mtx); in ng_btsocket_l2cap_process_l2ca_discon_rsp()
1099 if (msg->header.arglen != sizeof(*ip)) in ng_btsocket_l2cap_process_l2ca_discon_ind()
1102 ip = (ng_l2cap_l2ca_discon_ind_ip *)(msg->data); in ng_btsocket_l2cap_process_l2ca_discon_ind()
1107 pcb = ng_btsocket_l2cap_pcb_by_cid(&rt->src, ip->lcid, in ng_btsocket_l2cap_process_l2ca_discon_ind()
1108 ip->idtype); in ng_btsocket_l2cap_process_l2ca_discon_ind()
1120 mtx_lock(&pcb->pcb_mtx); in ng_btsocket_l2cap_process_l2ca_discon_ind()
1126 pcb->src.b[5], pcb->src.b[4], pcb->src.b[3], in ng_btsocket_l2cap_process_l2ca_discon_ind()
1127 pcb->src.b[2], pcb->src.b[1], pcb->src.b[0], in ng_btsocket_l2cap_process_l2ca_discon_ind()
1128 pcb->dst.b[5], pcb->dst.b[4], pcb->dst.b[3], in ng_btsocket_l2cap_process_l2ca_discon_ind()
1129 pcb->dst.b[2], pcb->dst.b[1], pcb->dst.b[0], in ng_btsocket_l2cap_process_l2ca_discon_ind()
1130 pcb->psm, pcb->cid, pcb->state); in ng_btsocket_l2cap_process_l2ca_discon_ind()
1132 if (pcb->flags & NG_BTSOCKET_L2CAP_TIMO) in ng_btsocket_l2cap_process_l2ca_discon_ind()
1135 pcb->state = NG_BTSOCKET_L2CAP_CLOSED; in ng_btsocket_l2cap_process_l2ca_discon_ind()
1136 soisdisconnected(pcb->so); in ng_btsocket_l2cap_process_l2ca_discon_ind()
1138 mtx_unlock(&pcb->pcb_mtx); in ng_btsocket_l2cap_process_l2ca_discon_ind()
1156 if (msg->header.arglen != sizeof(*op)) in ng_btsocket_l2cap_process_l2ca_write_rsp()
1159 op = (ng_l2cap_l2ca_write_op *)(msg->data); in ng_btsocket_l2cap_process_l2ca_write_rsp()
1164 pcb = ng_btsocket_l2cap_pcb_by_token(msg->header.token); in ng_btsocket_l2cap_process_l2ca_write_rsp()
1170 mtx_lock(&pcb->pcb_mtx); in ng_btsocket_l2cap_process_l2ca_write_rsp()
1176 pcb->src.b[5], pcb->src.b[4], pcb->src.b[3], in ng_btsocket_l2cap_process_l2ca_write_rsp()
1177 pcb->src.b[2], pcb->src.b[1], pcb->src.b[0], in ng_btsocket_l2cap_process_l2ca_write_rsp()
1178 pcb->dst.b[5], pcb->dst.b[4], pcb->dst.b[3], in ng_btsocket_l2cap_process_l2ca_write_rsp()
1179 pcb->dst.b[2], pcb->dst.b[1], pcb->dst.b[0], in ng_btsocket_l2cap_process_l2ca_write_rsp()
1180 pcb->psm, pcb->cid, op->result, op->length, in ng_btsocket_l2cap_process_l2ca_write_rsp()
1181 pcb->state); in ng_btsocket_l2cap_process_l2ca_write_rsp()
1183 if (pcb->state != NG_BTSOCKET_L2CAP_OPEN) { in ng_btsocket_l2cap_process_l2ca_write_rsp()
1184 mtx_unlock(&pcb->pcb_mtx); in ng_btsocket_l2cap_process_l2ca_write_rsp()
1195 sbdroprecord(&pcb->so->so_snd); in ng_btsocket_l2cap_process_l2ca_write_rsp()
1196 if (sbavail(&pcb->so->so_snd) > 0) { in ng_btsocket_l2cap_process_l2ca_write_rsp()
1200 sbdroprecord(&pcb->so->so_snd); /* XXX */ in ng_btsocket_l2cap_process_l2ca_write_rsp()
1208 pcb->so->so_error = ng_btsocket_l2cap_result2errno(op->result); in ng_btsocket_l2cap_process_l2ca_write_rsp()
1209 sowwakeup(pcb->so); in ng_btsocket_l2cap_process_l2ca_write_rsp()
1211 mtx_unlock(&pcb->pcb_mtx); in ng_btsocket_l2cap_process_l2ca_write_rsp()
1228 mtx_assert(&pcb->pcb_mtx, MA_OWNED); in ng_btsocket_l2cap_send_l2ca_con_req()
1230 if (pcb->rt == NULL || in ng_btsocket_l2cap_send_l2ca_con_req()
1231 pcb->rt->hook == NULL || NG_HOOK_NOT_VALID(pcb->rt->hook)) in ng_btsocket_l2cap_send_l2ca_con_req()
1239 msg->header.token = pcb->token; in ng_btsocket_l2cap_send_l2ca_con_req()
1241 ip = (ng_l2cap_l2ca_con_ip *)(msg->data); in ng_btsocket_l2cap_send_l2ca_con_req()
1242 bcopy(&pcb->dst, &ip->bdaddr, sizeof(ip->bdaddr)); in ng_btsocket_l2cap_send_l2ca_con_req()
1243 ip->psm = pcb->psm; in ng_btsocket_l2cap_send_l2ca_con_req()
1244 ip->linktype = ng_btsock_l2cap_addrtype_to_linktype(pcb->dsttype); in ng_btsocket_l2cap_send_l2ca_con_req()
1245 ip->idtype = pcb->idtype; in ng_btsocket_l2cap_send_l2ca_con_req()
1246 NG_SEND_MSG_HOOK(error, ng_btsocket_l2cap_node, msg,pcb->rt->hook, 0); in ng_btsocket_l2cap_send_l2ca_con_req()
1264 if (rt == NULL || rt->hook == NULL || NG_HOOK_NOT_VALID(rt->hook)) in ng_btsocket_l2cap_send_l2ca_con_rsp_req()
1272 msg->header.token = token; in ng_btsocket_l2cap_send_l2ca_con_rsp_req()
1274 ip = (ng_l2cap_l2ca_con_rsp_ip *)(msg->data); in ng_btsocket_l2cap_send_l2ca_con_rsp_req()
1275 bcopy(dst, &ip->bdaddr, sizeof(ip->bdaddr)); in ng_btsocket_l2cap_send_l2ca_con_rsp_req()
1276 ip->ident = ident; in ng_btsocket_l2cap_send_l2ca_con_rsp_req()
1277 ip->lcid = lcid; in ng_btsocket_l2cap_send_l2ca_con_rsp_req()
1278 ip->linktype = linktype; in ng_btsocket_l2cap_send_l2ca_con_rsp_req()
1279 ip->result = result; in ng_btsocket_l2cap_send_l2ca_con_rsp_req()
1280 ip->status = 0; in ng_btsocket_l2cap_send_l2ca_con_rsp_req()
1282 NG_SEND_MSG_HOOK(error, ng_btsocket_l2cap_node, msg, rt->hook, 0); in ng_btsocket_l2cap_send_l2ca_con_rsp_req()
1298 mtx_assert(&pcb->pcb_mtx, MA_OWNED); in ng_btsocket_l2cap_send_l2ca_cfg_req()
1300 if (pcb->rt == NULL || in ng_btsocket_l2cap_send_l2ca_cfg_req()
1301 pcb->rt->hook == NULL || NG_HOOK_NOT_VALID(pcb->rt->hook)) in ng_btsocket_l2cap_send_l2ca_cfg_req()
1309 msg->header.token = pcb->token; in ng_btsocket_l2cap_send_l2ca_cfg_req()
1311 ip = (ng_l2cap_l2ca_cfg_ip *)(msg->data); in ng_btsocket_l2cap_send_l2ca_cfg_req()
1312 ip->lcid = pcb->cid; in ng_btsocket_l2cap_send_l2ca_cfg_req()
1313 ip->imtu = pcb->imtu; in ng_btsocket_l2cap_send_l2ca_cfg_req()
1314 bcopy(&pcb->oflow, &ip->oflow, sizeof(ip->oflow)); in ng_btsocket_l2cap_send_l2ca_cfg_req()
1315 ip->flush_timo = pcb->flush_timo; in ng_btsocket_l2cap_send_l2ca_cfg_req()
1316 ip->link_timo = pcb->link_timo; in ng_btsocket_l2cap_send_l2ca_cfg_req()
1318 NG_SEND_MSG_HOOK(error, ng_btsocket_l2cap_node, msg,pcb->rt->hook, 0); in ng_btsocket_l2cap_send_l2ca_cfg_req()
1334 mtx_assert(&pcb->pcb_mtx, MA_OWNED); in ng_btsocket_l2cap_send_l2ca_cfg_rsp()
1336 if (pcb->rt == NULL || in ng_btsocket_l2cap_send_l2ca_cfg_rsp()
1337 pcb->rt->hook == NULL || NG_HOOK_NOT_VALID(pcb->rt->hook)) in ng_btsocket_l2cap_send_l2ca_cfg_rsp()
1345 msg->header.token = pcb->token; in ng_btsocket_l2cap_send_l2ca_cfg_rsp()
1347 ip = (ng_l2cap_l2ca_cfg_rsp_ip *)(msg->data); in ng_btsocket_l2cap_send_l2ca_cfg_rsp()
1348 ip->lcid = pcb->cid; in ng_btsocket_l2cap_send_l2ca_cfg_rsp()
1349 ip->omtu = pcb->omtu; in ng_btsocket_l2cap_send_l2ca_cfg_rsp()
1350 bcopy(&pcb->iflow, &ip->iflow, sizeof(ip->iflow)); in ng_btsocket_l2cap_send_l2ca_cfg_rsp()
1352 NG_SEND_MSG_HOOK(error, ng_btsocket_l2cap_node, msg, pcb->rt->hook, 0); in ng_btsocket_l2cap_send_l2ca_cfg_rsp()
1369 mtx_assert(&pcb->pcb_mtx, MA_OWNED); in ng_btsocket_l2cap_send_l2ca_discon_req()
1371 if (pcb->rt == NULL || in ng_btsocket_l2cap_send_l2ca_discon_req()
1372 pcb->rt->hook == NULL || NG_HOOK_NOT_VALID(pcb->rt->hook)) in ng_btsocket_l2cap_send_l2ca_discon_req()
1380 msg->header.token = token; in ng_btsocket_l2cap_send_l2ca_discon_req()
1382 ip = (ng_l2cap_l2ca_discon_ip *)(msg->data); in ng_btsocket_l2cap_send_l2ca_discon_req()
1383 ip->lcid = pcb->cid; in ng_btsocket_l2cap_send_l2ca_discon_req()
1384 ip->idtype = pcb->idtype; in ng_btsocket_l2cap_send_l2ca_discon_req()
1386 NG_SEND_MSG_HOOK(error, ng_btsocket_l2cap_node, msg,pcb->rt->hook, 0); in ng_btsocket_l2cap_send_l2ca_discon_req()
1428 if (m->m_pkthdr.len < sizeof(*hdr)) { in ng_btsocket_l2cap_data_input()
1430 "%s: L2CAP data packet too small, len=%d\n", __func__, m->m_pkthdr.len); in ng_btsocket_l2cap_data_input()
1434 if (m->m_len < sizeof(*hdr)) { in ng_btsocket_l2cap_data_input()
1444 if (hdr->length != m->m_pkthdr.len) { in ng_btsocket_l2cap_data_input()
1447 __func__, m->m_pkthdr.len, hdr->length); in ng_btsocket_l2cap_data_input()
1466 rt->src.b[5], rt->src.b[4], rt->src.b[3], in ng_btsocket_l2cap_data_input()
1467 rt->src.b[2], rt->src.b[1], rt->src.b[0], in ng_btsocket_l2cap_data_input()
1468 hdr->dcid, hdr->length); in ng_btsocket_l2cap_data_input()
1470 if ((hdr->dcid >= NG_L2CAP_FIRST_CID) || in ng_btsocket_l2cap_data_input()
1477 pcb = ng_btsocket_l2cap_pcb_by_cid(&rt->src, hdr->dcid,idtype); in ng_btsocket_l2cap_data_input()
1483 mtx_lock(&pcb->pcb_mtx); in ng_btsocket_l2cap_data_input()
1485 if (pcb->state != NG_BTSOCKET_L2CAP_OPEN) { in ng_btsocket_l2cap_data_input()
1489 rt->src.b[5], rt->src.b[4], rt->src.b[3], in ng_btsocket_l2cap_data_input()
1490 rt->src.b[2], rt->src.b[1], rt->src.b[0], in ng_btsocket_l2cap_data_input()
1491 hdr->dcid, pcb->state); in ng_btsocket_l2cap_data_input()
1493 mtx_unlock(&pcb->pcb_mtx); in ng_btsocket_l2cap_data_input()
1499 if (hdr->length > pcb->imtu) { in ng_btsocket_l2cap_data_input()
1504 rt->src.b[5], rt->src.b[4], rt->src.b[3], in ng_btsocket_l2cap_data_input()
1505 rt->src.b[2], rt->src.b[1], rt->src.b[0], in ng_btsocket_l2cap_data_input()
1506 hdr->dcid, hdr->length, pcb->imtu); in ng_btsocket_l2cap_data_input()
1508 mtx_unlock(&pcb->pcb_mtx); in ng_btsocket_l2cap_data_input()
1514 if (m->m_pkthdr.len > sbspace(&pcb->so->so_rcv)) { in ng_btsocket_l2cap_data_input()
1526 rt->src.b[5], rt->src.b[4], rt->src.b[3], in ng_btsocket_l2cap_data_input()
1527 rt->src.b[2], rt->src.b[1], rt->src.b[0], in ng_btsocket_l2cap_data_input()
1528 hdr->dcid, m->m_pkthdr.len, in ng_btsocket_l2cap_data_input()
1529 sbspace(&pcb->so->so_rcv)); in ng_btsocket_l2cap_data_input()
1531 mtx_unlock(&pcb->pcb_mtx); in ng_btsocket_l2cap_data_input()
1537 sbappendrecord(&pcb->so->so_rcv, m); in ng_btsocket_l2cap_data_input()
1540 sorwakeup(pcb->so); in ng_btsocket_l2cap_data_input()
1542 mtx_unlock(&pcb->pcb_mtx); in ng_btsocket_l2cap_data_input()
1544 } else if (hdr->dcid == NG_L2CAP_CLT_CID) { in ng_btsocket_l2cap_data_input()
1548 if (hdr->length > NG_L2CAP_MTU_DEFAULT) { in ng_btsocket_l2cap_data_input()
1553 rt->src.b[5], rt->src.b[4], rt->src.b[3], in ng_btsocket_l2cap_data_input()
1554 rt->src.b[2], rt->src.b[1], rt->src.b[0], in ng_btsocket_l2cap_data_input()
1555 hdr->length); in ng_btsocket_l2cap_data_input()
1560 if (m->m_pkthdr.len < sizeof(*clt_hdr)) { in ng_btsocket_l2cap_data_input()
1565 rt->src.b[5], rt->src.b[4], rt->src.b[3], in ng_btsocket_l2cap_data_input()
1566 rt->src.b[2], rt->src.b[1], rt->src.b[0], in ng_btsocket_l2cap_data_input()
1567 hdr->length); in ng_btsocket_l2cap_data_input()
1571 if (m->m_len < sizeof(*clt_hdr)) { in ng_btsocket_l2cap_data_input()
1585 rt->src.b[5], rt->src.b[4], rt->src.b[3], in ng_btsocket_l2cap_data_input()
1586 rt->src.b[2], rt->src.b[1], rt->src.b[0], in ng_btsocket_l2cap_data_input()
1587 clt_hdr->psm, hdr->length); in ng_btsocket_l2cap_data_input()
1594 mtx_lock(&pcb->pcb_mtx); in ng_btsocket_l2cap_data_input()
1596 if (bcmp(&rt->src, &pcb->src, sizeof(pcb->src)) != 0 || in ng_btsocket_l2cap_data_input()
1597 pcb->psm != clt_hdr->psm || in ng_btsocket_l2cap_data_input()
1598 pcb->state != NG_BTSOCKET_L2CAP_OPEN || in ng_btsocket_l2cap_data_input()
1599 (pcb->so->so_options & SO_BROADCAST) == 0 || in ng_btsocket_l2cap_data_input()
1600 m->m_pkthdr.len > sbspace(&pcb->so->so_rcv)) in ng_btsocket_l2cap_data_input()
1605 * socket's queue. If m_dup() failed - no big deal in ng_btsocket_l2cap_data_input()
1611 sbappendrecord(&pcb->so->so_rcv, copy); in ng_btsocket_l2cap_data_input()
1612 sorwakeup(pcb->so); in ng_btsocket_l2cap_data_input()
1615 mtx_unlock(&pcb->pcb_mtx); in ng_btsocket_l2cap_data_input()
1631 switch (msg->header.cmd) { in ng_btsocket_l2cap_default_msg_input()
1635 (ng_l2cap_node_hook_info_ep *)msg->data; in ng_btsocket_l2cap_default_msg_input()
1636 if (hook == NULL || msg->header.arglen != sizeof(*ep)) in ng_btsocket_l2cap_default_msg_input()
1639 if (bcmp(&ep->addr, NG_HCI_BDADDR_ANY, sizeof(bdaddr_t)) == 0) in ng_btsocket_l2cap_default_msg_input()
1658 bcopy(&ep->addr, &rt->src, sizeof(rt->src)); in ng_btsocket_l2cap_default_msg_input()
1659 rt->hook = hook; in ng_btsocket_l2cap_default_msg_input()
1666 rt->src.b[5], rt->src.b[4], rt->src.b[3], in ng_btsocket_l2cap_default_msg_input()
1667 rt->src.b[2], rt->src.b[1], rt->src.b[0]); in ng_btsocket_l2cap_default_msg_input()
1672 "%s: Unknown message, cmd=%d\n", __func__, msg->header.cmd); in ng_btsocket_l2cap_default_msg_input()
1701 switch (msg->header.cmd) { in ng_btsocket_l2cap_l2ca_msg_input()
1745 "%s: Unknown L2CA message, cmd=%d\n", __func__, msg->header.cmd); in ng_btsocket_l2cap_l2ca_msg_input()
1774 switch(item->el_flags & NGQF_TYPE) { in ng_btsocket_l2cap_input()
1787 switch (msg->header.cmd) { in ng_btsocket_l2cap_input()
1810 ("%s: invalid item type=%ld\n", __func__, (item->el_flags & NGQF_TYPE))); in ng_btsocket_l2cap_input()
1840 mtx_lock(&pcb->pcb_mtx); in ng_btsocket_l2cap_rtclean()
1843 if (pcb->rt != NULL && in ng_btsocket_l2cap_rtclean()
1844 pcb->rt->hook != NULL && NG_HOOK_NOT_VALID(pcb->rt->hook)) { in ng_btsocket_l2cap_rtclean()
1845 if (pcb->flags & NG_BTSOCKET_L2CAP_TIMO) in ng_btsocket_l2cap_rtclean()
1848 pcb->so->so_error = ENETDOWN; in ng_btsocket_l2cap_rtclean()
1849 pcb->state = NG_BTSOCKET_L2CAP_CLOSED; in ng_btsocket_l2cap_rtclean()
1850 soisdisconnected(pcb->so); in ng_btsocket_l2cap_rtclean()
1852 pcb->token = 0; in ng_btsocket_l2cap_rtclean()
1853 pcb->cid = 0; in ng_btsocket_l2cap_rtclean()
1854 pcb->rt = NULL; in ng_btsocket_l2cap_rtclean()
1857 mtx_unlock(&pcb->pcb_mtx); in ng_btsocket_l2cap_rtclean()
1862 * Now cleanup routing table in ng_btsocket_l2cap_rtclean()
1868 if (rt->hook != NULL && NG_HOOK_NOT_VALID(rt->hook)) { in ng_btsocket_l2cap_rtclean()
1871 NG_HOOK_SET_PRIVATE(rt->hook, NULL); in ng_btsocket_l2cap_rtclean()
1872 NG_HOOK_UNREF(rt->hook); /* Remove extra reference */ in ng_btsocket_l2cap_rtclean()
1941 /* Routing table */ in ng_btsocket_l2cap_init()
1958 so->so_error = ECONNABORTED; in ng_btsocket_l2cap_abort()
1984 if (so->so_type != SOCK_SEQPACKET) in ng_btsocket_l2cap_attach()
1997 if ((so->so_snd.sb_hiwat == 0) || (so->so_rcv.sb_hiwat == 0)) { in ng_btsocket_l2cap_attach()
2011 so->so_pcb = (caddr_t) pcb; in ng_btsocket_l2cap_attach()
2012 pcb->so = so; in ng_btsocket_l2cap_attach()
2013 pcb->state = NG_BTSOCKET_L2CAP_CLOSED; in ng_btsocket_l2cap_attach()
2016 pcb->imtu = pcb->omtu = NG_L2CAP_MTU_DEFAULT; in ng_btsocket_l2cap_attach()
2019 pcb->iflow.flags = 0x0; in ng_btsocket_l2cap_attach()
2020 pcb->iflow.service_type = NG_HCI_SERVICE_TYPE_BEST_EFFORT; in ng_btsocket_l2cap_attach()
2021 pcb->iflow.token_rate = 0xffffffff; /* maximum */ in ng_btsocket_l2cap_attach()
2022 pcb->iflow.token_bucket_size = 0xffffffff; /* maximum */ in ng_btsocket_l2cap_attach()
2023 pcb->iflow.peak_bandwidth = 0x00000000; /* maximum */ in ng_btsocket_l2cap_attach()
2024 pcb->iflow.latency = 0xffffffff; /* don't care */ in ng_btsocket_l2cap_attach()
2025 pcb->iflow.delay_variation = 0xffffffff; /* don't care */ in ng_btsocket_l2cap_attach()
2027 bcopy(&pcb->iflow, &pcb->oflow, sizeof(pcb->oflow)); in ng_btsocket_l2cap_attach()
2029 pcb->flush_timo = NG_L2CAP_FLUSH_TIMO_DEFAULT; in ng_btsocket_l2cap_attach()
2030 pcb->link_timo = NG_L2CAP_LINK_TIMO_DEFAULT; in ng_btsocket_l2cap_attach()
2039 mtx_init(&pcb->pcb_mtx, "btsocks_l2cap_pcb_mtx", NULL, in ng_btsocket_l2cap_attach()
2041 callout_init_mtx(&pcb->timo, &pcb->pcb_mtx, 0); in ng_btsocket_l2cap_attach()
2071 pcb->token = token; in ng_btsocket_l2cap_attach()
2099 if (sa->l2cap_family != AF_BLUETOOTH) in ng_btsocket_l2cap_bind()
2102 if ((sa->l2cap_len != sizeof(*sa))&& in ng_btsocket_l2cap_bind()
2103 (sa->l2cap_len != sizeof(struct sockaddr_l2cap_compat))) in ng_btsocket_l2cap_bind()
2106 psm = le16toh(sa->l2cap_psm); in ng_btsocket_l2cap_bind()
2119 if (psm != 0 && psm == pcb->psm && in ng_btsocket_l2cap_bind()
2120 bcmp(&pcb->src, &sa->l2cap_bdaddr, sizeof(bdaddr_t)) == 0) in ng_btsocket_l2cap_bind()
2127 bcopy(&sa->l2cap_bdaddr, &pcb->src, sizeof(pcb->src)); in ng_btsocket_l2cap_bind()
2128 pcb->psm = psm; in ng_btsocket_l2cap_bind()
2159 if (pcb->state == NG_BTSOCKET_L2CAP_CONNECTING) in ng_btsocket_l2cap_connect()
2165 if (sa->l2cap_family != AF_BLUETOOTH) in ng_btsocket_l2cap_connect()
2167 if (sa->l2cap_len == sizeof(*sal)){ in ng_btsocket_l2cap_connect()
2170 sa->l2cap_len = sizeof(*sa); in ng_btsocket_l2cap_connect()
2171 sa->l2cap_bdaddr_type = BDADDR_BREDR; in ng_btsocket_l2cap_connect()
2173 if (sa->l2cap_len != sizeof(*sa)) in ng_btsocket_l2cap_connect()
2175 if ((sa->l2cap_psm && sa->l2cap_cid)) in ng_btsocket_l2cap_connect()
2177 if (bcmp(&sa->l2cap_bdaddr, NG_HCI_BDADDR_ANY, sizeof(bdaddr_t)) == 0) in ng_btsocket_l2cap_connect()
2179 if((sa->l2cap_bdaddr_type == BDADDR_BREDR)&& in ng_btsocket_l2cap_connect()
2180 (sa->l2cap_psm == 0)) in ng_btsocket_l2cap_connect()
2182 if(sa->l2cap_bdaddr_type != BDADDR_BREDR){ in ng_btsocket_l2cap_connect()
2183 if(sa->l2cap_cid == NG_L2CAP_ATT_CID){ in ng_btsocket_l2cap_connect()
2185 }else if (sa->l2cap_cid == NG_L2CAP_SMP_CID){ in ng_btsocket_l2cap_connect()
2193 if (pcb->psm != 0 && pcb->psm != le16toh(sa->l2cap_psm)) in ng_btsocket_l2cap_connect()
2196 * Routing. Socket should be bound to some source address. The source in ng_btsocket_l2cap_connect()
2204 mtx_lock(&pcb->pcb_mtx); in ng_btsocket_l2cap_connect()
2207 bcopy(&sa->l2cap_bdaddr, &pcb->dst, sizeof(pcb->dst)); in ng_btsocket_l2cap_connect()
2208 pcb->psm = le16toh(sa->l2cap_psm); in ng_btsocket_l2cap_connect()
2209 pcb->dsttype = sa->l2cap_bdaddr_type; in ng_btsocket_l2cap_connect()
2210 pcb->cid = 0; in ng_btsocket_l2cap_connect()
2211 pcb->idtype = idtype; in ng_btsocket_l2cap_connect()
2212 pcb->rt = NULL; in ng_btsocket_l2cap_connect()
2213 have_src = bcmp(&pcb->src, NG_HCI_BDADDR_ANY, sizeof(pcb->src)); in ng_btsocket_l2cap_connect()
2216 if (rt->hook == NULL || NG_HOOK_NOT_VALID(rt->hook)) in ng_btsocket_l2cap_connect()
2221 if (bcmp(&pcb->src, &rt->src, sizeof(rt->src)) == 0) in ng_btsocket_l2cap_connect()
2224 if (bcmp(&pcb->dst, &rt->src, sizeof(rt->src)) != 0) in ng_btsocket_l2cap_connect()
2230 pcb->rt = rt; in ng_btsocket_l2cap_connect()
2233 bcopy(&rt->src, &pcb->src, sizeof(pcb->src)); in ng_btsocket_l2cap_connect()
2234 pcb->srctype = in ng_btsocket_l2cap_connect()
2235 (sa->l2cap_bdaddr_type == BDADDR_BREDR)? in ng_btsocket_l2cap_connect()
2248 pcb->flags |= NG_BTSOCKET_L2CAP_CLIENT; in ng_btsocket_l2cap_connect()
2249 pcb->state = NG_BTSOCKET_L2CAP_CONNECTING; in ng_btsocket_l2cap_connect()
2250 soisconnecting(pcb->so); in ng_btsocket_l2cap_connect()
2256 mtx_unlock(&pcb->pcb_mtx); in ng_btsocket_l2cap_connect()
2290 if (sopt->sopt_level != SOL_L2CAP) in ng_btsocket_l2cap_ctloutput()
2293 mtx_lock(&pcb->pcb_mtx); in ng_btsocket_l2cap_ctloutput()
2295 switch (sopt->sopt_dir) { in ng_btsocket_l2cap_ctloutput()
2297 switch (sopt->sopt_name) { in ng_btsocket_l2cap_ctloutput()
2299 error = sooptcopyout(sopt, &pcb->imtu, in ng_btsocket_l2cap_ctloutput()
2300 sizeof(pcb->imtu)); in ng_btsocket_l2cap_ctloutput()
2304 error = sooptcopyout(sopt, &pcb->omtu, in ng_btsocket_l2cap_ctloutput()
2305 sizeof(pcb->omtu)); in ng_btsocket_l2cap_ctloutput()
2309 error = sooptcopyout(sopt, &pcb->iflow, in ng_btsocket_l2cap_ctloutput()
2310 sizeof(pcb->iflow)); in ng_btsocket_l2cap_ctloutput()
2314 error = sooptcopyout(sopt, &pcb->oflow, in ng_btsocket_l2cap_ctloutput()
2315 sizeof(pcb->oflow)); in ng_btsocket_l2cap_ctloutput()
2319 error = sooptcopyout(sopt, &pcb->flush_timo, in ng_btsocket_l2cap_ctloutput()
2320 sizeof(pcb->flush_timo)); in ng_btsocket_l2cap_ctloutput()
2323 error = sooptcopyout(sopt, &pcb->need_encrypt, in ng_btsocket_l2cap_ctloutput()
2324 sizeof(pcb->need_encrypt)); in ng_btsocket_l2cap_ctloutput()
2338 * May be this should indicate re-configuration of the open in ng_btsocket_l2cap_ctloutput()
2342 if (pcb->state != NG_BTSOCKET_L2CAP_CLOSED) { in ng_btsocket_l2cap_ctloutput()
2347 switch (sopt->sopt_name) { in ng_btsocket_l2cap_ctloutput()
2351 pcb->imtu = v.mtu; in ng_btsocket_l2cap_ctloutput()
2357 bcopy(&v.flow, &pcb->oflow, sizeof(pcb->oflow)); in ng_btsocket_l2cap_ctloutput()
2364 pcb->flush_timo = v.flush_timo; in ng_btsocket_l2cap_ctloutput()
2367 if((pcb->state != NG_BTSOCKET_L2CAP_OPEN) && in ng_btsocket_l2cap_ctloutput()
2368 (pcb->state != NG_BTSOCKET_L2CAP_W4_ENC_CHANGE)){ in ng_btsocket_l2cap_ctloutput()
2372 pcb->need_encrypt = (v.encryption)?1:0; in ng_btsocket_l2cap_ctloutput()
2388 mtx_unlock(&pcb->pcb_mtx); in ng_btsocket_l2cap_ctloutput()
2408 mtx_lock(&pcb->pcb_mtx); in ng_btsocket_l2cap_detach()
2411 if (pcb->flags & NG_BTSOCKET_L2CAP_TIMO) in ng_btsocket_l2cap_detach()
2414 if (pcb->state != NG_BTSOCKET_L2CAP_CLOSED && in ng_btsocket_l2cap_detach()
2415 pcb->state != NG_BTSOCKET_L2CAP_DISCONNECTING) in ng_btsocket_l2cap_detach()
2419 pcb->state = NG_BTSOCKET_L2CAP_CLOSED; in ng_btsocket_l2cap_detach()
2423 mtx_unlock(&pcb->pcb_mtx); in ng_btsocket_l2cap_detach()
2426 mtx_destroy(&pcb->pcb_mtx); in ng_btsocket_l2cap_detach()
2431 so->so_pcb = NULL; in ng_btsocket_l2cap_detach()
2449 mtx_lock(&pcb->pcb_mtx); in ng_btsocket_l2cap_disconnect()
2451 if (pcb->state == NG_BTSOCKET_L2CAP_DISCONNECTING) { in ng_btsocket_l2cap_disconnect()
2452 mtx_unlock(&pcb->pcb_mtx); in ng_btsocket_l2cap_disconnect()
2456 if (pcb->state != NG_BTSOCKET_L2CAP_CLOSED) { in ng_btsocket_l2cap_disconnect()
2458 if (pcb->flags & NG_BTSOCKET_L2CAP_TIMO) in ng_btsocket_l2cap_disconnect()
2461 error = ng_btsocket_l2cap_send_l2ca_discon_req(pcb->token, pcb); in ng_btsocket_l2cap_disconnect()
2463 pcb->state = NG_BTSOCKET_L2CAP_DISCONNECTING; in ng_btsocket_l2cap_disconnect()
2472 mtx_unlock(&pcb->pcb_mtx); in ng_btsocket_l2cap_disconnect()
2501 if (pcb->psm == 0) { in ng_btsocket_l2cap_listen()
2530 .l2cap_psm = htole16(pcb->psm), in ng_btsocket_l2cap_peeraddr()
2532 bcopy(&pcb->dst, &l2cap->l2cap_bdaddr, sizeof(l2cap->l2cap_bdaddr)); in ng_btsocket_l2cap_peeraddr()
2533 switch(pcb->idtype){ in ng_btsocket_l2cap_peeraddr()
2535 l2cap->l2cap_cid = NG_L2CAP_ATT_CID; in ng_btsocket_l2cap_peeraddr()
2538 l2cap->l2cap_cid = NG_L2CAP_SMP_CID; in ng_btsocket_l2cap_peeraddr()
2541 l2cap->l2cap_cid = 0; in ng_btsocket_l2cap_peeraddr()
2544 l2cap->l2cap_bdaddr_type = pcb->dsttype; in ng_btsocket_l2cap_peeraddr()
2571 mtx_lock(&pcb->pcb_mtx); in ng_btsocket_l2cap_send()
2574 if (pcb->state != NG_BTSOCKET_L2CAP_OPEN) { in ng_btsocket_l2cap_send()
2575 mtx_unlock(&pcb->pcb_mtx); in ng_btsocket_l2cap_send()
2581 if (pcb->rt == NULL || in ng_btsocket_l2cap_send()
2582 pcb->rt->hook == NULL || NG_HOOK_NOT_VALID(pcb->rt->hook)) { in ng_btsocket_l2cap_send()
2583 mtx_unlock(&pcb->pcb_mtx); in ng_btsocket_l2cap_send()
2589 if (m->m_pkthdr.len > pcb->omtu) { in ng_btsocket_l2cap_send()
2591 "%s: Packet too big, len=%d, omtu=%d\n", __func__, m->m_pkthdr.len, pcb->omtu); in ng_btsocket_l2cap_send()
2593 mtx_unlock(&pcb->pcb_mtx); in ng_btsocket_l2cap_send()
2605 sbappendrecord(&pcb->so->so_snd, m); in ng_btsocket_l2cap_send()
2608 if (!(pcb->flags & NG_BTSOCKET_L2CAP_TIMO)) { in ng_btsocket_l2cap_send()
2613 sbdroprecord(&pcb->so->so_snd); /* XXX */ in ng_btsocket_l2cap_send()
2616 mtx_unlock(&pcb->pcb_mtx); in ng_btsocket_l2cap_send()
2635 mtx_assert(&pcb->pcb_mtx, MA_OWNED); in ng_btsocket_l2cap_send2()
2637 if (sbavail(&pcb->so->so_snd) == 0) in ng_btsocket_l2cap_send2()
2640 m = m_dup(pcb->so->so_snd.sb_mb, M_NOWAIT); in ng_btsocket_l2cap_send2()
2647 if (m->m_len < sizeof(*hdr)) in ng_btsocket_l2cap_send2()
2658 hdr->token = pcb->token; in ng_btsocket_l2cap_send2()
2659 hdr->length = m->m_pkthdr.len - sizeof(*hdr); in ng_btsocket_l2cap_send2()
2660 hdr->lcid = pcb->cid; in ng_btsocket_l2cap_send2()
2661 hdr->idtype = pcb->idtype; in ng_btsocket_l2cap_send2()
2664 __func__, m->m_pkthdr.len, hdr->length, hdr->lcid, in ng_btsocket_l2cap_send2()
2665 hdr->token, pcb->state); in ng_btsocket_l2cap_send2()
2672 NG_SEND_DATA_ONLY(error, pcb->rt->hook, m); in ng_btsocket_l2cap_send2()
2694 .l2cap_psm = htole16(pcb->psm), in ng_btsocket_l2cap_sockaddr()
2695 .l2cap_bdaddr_type = pcb->srctype, in ng_btsocket_l2cap_sockaddr()
2697 bcopy(&pcb->src, &l2cap->l2cap_bdaddr, sizeof(l2cap->l2cap_bdaddr)); in ng_btsocket_l2cap_sockaddr()
2721 if (p->so == NULL || !SOLISTENING(p->so) || p->psm != psm) in ng_btsocket_l2cap_pcb_by_addr()
2724 if (bcmp(&p->src, bdaddr, sizeof(p->src)) == 0) in ng_btsocket_l2cap_pcb_by_addr()
2727 if (bcmp(&p->src, NG_HCI_BDADDR_ANY, sizeof(p->src)) == 0) in ng_btsocket_l2cap_pcb_by_addr()
2750 if (p->token == token) in ng_btsocket_l2cap_pcb_by_token()
2769 if (p->cid == cid && in ng_btsocket_l2cap_pcb_by_cid()
2770 bcmp(src, &p->src, sizeof(p->src)) == 0&& in ng_btsocket_l2cap_pcb_by_cid()
2771 p->idtype == idtype) in ng_btsocket_l2cap_pcb_by_cid()
2784 mtx_assert(&pcb->pcb_mtx, MA_OWNED); in ng_btsocket_l2cap_timeout()
2786 if (!(pcb->flags & NG_BTSOCKET_L2CAP_TIMO)) { in ng_btsocket_l2cap_timeout()
2787 pcb->flags |= NG_BTSOCKET_L2CAP_TIMO; in ng_btsocket_l2cap_timeout()
2788 callout_reset(&pcb->timo, bluetooth_l2cap_ertx_timeout(), in ng_btsocket_l2cap_timeout()
2802 mtx_assert(&pcb->pcb_mtx, MA_OWNED); in ng_btsocket_l2cap_untimeout()
2804 if (pcb->flags & NG_BTSOCKET_L2CAP_TIMO) { in ng_btsocket_l2cap_untimeout()
2805 callout_stop(&pcb->timo); in ng_btsocket_l2cap_untimeout()
2806 pcb->flags &= ~NG_BTSOCKET_L2CAP_TIMO; in ng_btsocket_l2cap_untimeout()
2821 mtx_assert(&pcb->pcb_mtx, MA_OWNED); in ng_btsocket_l2cap_process_timeout()
2823 pcb->flags &= ~NG_BTSOCKET_L2CAP_TIMO; in ng_btsocket_l2cap_process_timeout()
2824 pcb->so->so_error = ETIMEDOUT; in ng_btsocket_l2cap_process_timeout()
2826 switch (pcb->state) { in ng_btsocket_l2cap_process_timeout()
2831 if (pcb->cid != 0) in ng_btsocket_l2cap_process_timeout()
2835 pcb->state = NG_BTSOCKET_L2CAP_CLOSED; in ng_btsocket_l2cap_process_timeout()
2836 soisdisconnected(pcb->so); in ng_btsocket_l2cap_process_timeout()
2840 /* Send timeout - drop packet and wakeup sender */ in ng_btsocket_l2cap_process_timeout()
2841 sbdroprecord(&pcb->so->so_snd); in ng_btsocket_l2cap_process_timeout()
2842 sowwakeup(pcb->so); in ng_btsocket_l2cap_process_timeout()
2846 /* Disconnect timeout - disconnect the socket anyway */ in ng_btsocket_l2cap_process_timeout()
2847 pcb->state = NG_BTSOCKET_L2CAP_CLOSED; in ng_btsocket_l2cap_process_timeout()
2848 soisdisconnected(pcb->so); in ng_btsocket_l2cap_process_timeout()
2853 "%s: Invalid socket state=%d\n", __func__, pcb->state); in ng_btsocket_l2cap_process_timeout()
2903 case 0x0a: /* Max number of SCO connections to a unit */ in ng_btsocket_l2cap_result2errno()
2915 case 0x1b: /* SCO offset rejected */ in ng_btsocket_l2cap_result2errno()
2916 case 0x1c: /* SCO interval rejected */ in ng_btsocket_l2cap_result2errno()
2917 case 0x1d: /* SCO air mode rejected */ in ng_btsocket_l2cap_result2errno()