From owner-svn-src-head@freebsd.org Sat Nov 7 12:15:04 2015 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 6B850A2867B; Sat, 7 Nov 2015 12:15:04 +0000 (UTC) (envelope-from takawata@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 344F21187; Sat, 7 Nov 2015 12:15:04 +0000 (UTC) (envelope-from takawata@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id tA7CF3JP026282; Sat, 7 Nov 2015 12:15:03 GMT (envelope-from takawata@FreeBSD.org) Received: (from takawata@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id tA7CF3vm026280; Sat, 7 Nov 2015 12:15:03 GMT (envelope-from takawata@FreeBSD.org) Message-Id: <201511071215.tA7CF3vm026280@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: takawata set sender to takawata@FreeBSD.org using -f From: Takanori Watanabe Date: Sat, 7 Nov 2015 12:15:03 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r290491 - in head/sys/netgraph/bluetooth: hci socket X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 07 Nov 2015 12:15:04 -0000 Author: takawata Date: Sat Nov 7 12:15:02 2015 New Revision: 290491 URL: https://svnweb.freebsd.org/changeset/base/290491 Log: Fix encryption error handling. Close l2cap connection on encryption error. Modified: head/sys/netgraph/bluetooth/hci/ng_hci_evnt.c head/sys/netgraph/bluetooth/socket/ng_btsocket_l2cap.c Modified: head/sys/netgraph/bluetooth/hci/ng_hci_evnt.c ============================================================================== --- head/sys/netgraph/bluetooth/hci/ng_hci_evnt.c Sat Nov 7 12:11:17 2015 (r290490) +++ head/sys/netgraph/bluetooth/hci/ng_hci_evnt.c Sat Nov 7 12:15:02 2015 (r290491) @@ -913,17 +913,17 @@ encryption_change(ng_hci_unit_p unit, st ng_hci_encryption_change_ep *ep = NULL; ng_hci_unit_con_p con = NULL; int error = 0; + u_int16_t h; NG_HCI_M_PULLUP(event, sizeof(*ep)); if (event == NULL) return (ENOBUFS); ep = mtod(event, ng_hci_encryption_change_ep *); + h = NG_HCI_CON_HANDLE(le16toh(ep->con_handle)); + con = ng_hci_con_by_handle(unit, h); if (ep->status == 0) { - u_int16_t h = NG_HCI_CON_HANDLE(le16toh(ep->con_handle)); - - con = ng_hci_con_by_handle(unit, h); if (con == NULL) { NG_HCI_ALERT( "%s: %s - invalid connection handle=%d\n", @@ -940,12 +940,14 @@ encryption_change(ng_hci_unit_p unit, st con->encryption_mode = NG_HCI_ENCRYPTION_MODE_P2P; else con->encryption_mode = NG_HCI_ENCRYPTION_MODE_NONE; - ng_hci_lp_enc_change(con, ep->encryption_enable); } else NG_HCI_ERR( "%s: %s - failed to change encryption mode, status=%d\n", __func__, NG_NODE_NAME(unit->node), ep->status); + /*Anyway, propagete encryption status to upper layer*/ + ng_hci_lp_enc_change(con, con->encryption_mode); + NG_FREE_M(event); return (error); Modified: head/sys/netgraph/bluetooth/socket/ng_btsocket_l2cap.c ============================================================================== --- head/sys/netgraph/bluetooth/socket/ng_btsocket_l2cap.c Sat Nov 7 12:11:17 2015 (r290490) +++ head/sys/netgraph/bluetooth/socket/ng_btsocket_l2cap.c Sat Nov 7 12:15:02 2015 (r290491) @@ -467,6 +467,7 @@ ng_btsocket_l2cap_process_l2ca_con_req_r (pcb->idtype == NG_L2CAP_L2CA_IDTYPE_SMP)){ pcb->encryption = op->encryption; pcb->cid = op->lcid; if(pcb->need_encrypt && !(pcb->encryption)){ + ng_btsocket_l2cap_timeout(pcb); pcb->state = NG_BTSOCKET_L2CAP_W4_ENC_CHANGE; }else{ pcb->state = NG_BTSOCKET_L2CAP_OPEN; @@ -713,6 +714,7 @@ static int ng_btsocket_l2cap_process_l2c pcb->encryption = op->result; if(pcb->need_encrypt){ + ng_btsocket_l2cap_untimeout(pcb); if(pcb->state != NG_BTSOCKET_L2CAP_W4_ENC_CHANGE){ NG_BTSOCKET_L2CAP_WARN("%s: Invalid pcb status %d", __func__, pcb->state); @@ -721,6 +723,7 @@ static int ng_btsocket_l2cap_process_l2c soisconnected(pcb->so); }else{ pcb->so->so_error = EPERM; + ng_btsocket_l2cap_send_l2ca_discon_req(0, pcb); pcb->state = NG_BTSOCKET_L2CAP_CLOSED; soisdisconnected(pcb->so); } @@ -2844,6 +2847,7 @@ ng_btsocket_l2cap_process_timeout(void * switch (pcb->state) { case NG_BTSOCKET_L2CAP_CONNECTING: case NG_BTSOCKET_L2CAP_CONFIGURING: + case NG_BTSOCKET_L2CAP_W4_ENC_CHANGE: /* Send disconnect request with "zero" token */ if (pcb->cid != 0) ng_btsocket_l2cap_send_l2ca_discon_req(0, pcb);