From patchwork Sat Dec 4 00:15:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 520562 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 04B69C433EF for ; Sat, 4 Dec 2021 00:15:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1383639AbhLDATK (ORCPT ); Fri, 3 Dec 2021 19:19:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45340 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1359660AbhLDATJ (ORCPT ); Fri, 3 Dec 2021 19:19:09 -0500 Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 04727C061751 for ; Fri, 3 Dec 2021 16:15:45 -0800 (PST) Received: by mail-pj1-x1029.google.com with SMTP id w33-20020a17090a6ba400b001a722a06212so6124820pjj.0 for ; Fri, 03 Dec 2021 16:15:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=O8rQs8lkXZ7g7WxJLfX1FduNXZk5lXU85QoseCRnv0g=; b=pxM1Bf2rKBR39+mHs1DMbTz3xYFebZpGSUCsIowN2I6TZJimE7uEMTlnTnqBZ3Of/L AMsp1kE3eVpP6MH5XvGBiyZXZLaYtNvRqthiPLYy3pjhYRuIP3pRm85clZhUjTnyQirI JJZjnbV/NImpYzINFFeXqfijPqEkWXhTq66aNbRK60JC/4lW7sYZQDYr50Lm4RlksD+M qIG18doCYpaLn3qrhHLbFsDVPq6hawiUTuxizf3es/cArkAc8haKYljnktaQoL2EY5pt oATbQeAfU1kNpnnOOt6rFpeULi9yEwEojpMbCx042WHaJSmQKiJZJNeub/6LxzRWRYVK SQgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=O8rQs8lkXZ7g7WxJLfX1FduNXZk5lXU85QoseCRnv0g=; b=WY1D5z/ZenV7bmPZPBGhB7Mesolfv53g0+p05c3Suzajm9suA1v1JTPG4eLr9st6e1 wSN3vTZAaR6vrzN04o8uPKCahcbGou5ojnNAyJyc3lQrqGzrnG1IHnAeU8F8wSTeD9pk FtM5WRQZ82WE4AZRxvIFj7rtzKGOmfykUNMY90jd0bEv73uCTnB5sHRJ70OjsFSW6Eau 0hm0BbyAkapx+ywLhgxecd8v1tDGtAlvJ+sMhCRLc0dBDTZ70SgfSK/GHhhXIdRXkZIX HW8veIOgd4NHrc3Duj1rdqD52KZhE5oEvCh0USYnLqohGjyoFWxvUuh2X01tkE3LgvhY u7OA== X-Gm-Message-State: AOAM532OCYPCJRF8zeURpByTrp0gSxDjhFy56FQq4pMFePHGSfePXfgC HmZdBdHgBrbCpKAPZ2AvzmNH03MvDY8= X-Google-Smtp-Source: ABdhPJxV3lCI6OfeBn3U6NQPIpmIcEtm1xOIrgE5QCpycSRDkBcWiDiNbSw2gEJ1FM2V/FM9Gppj8w== X-Received: by 2002:a17:90a:a083:: with SMTP id r3mr17704121pjp.55.1638576944177; Fri, 03 Dec 2021 16:15:44 -0800 (PST) Received: from lvondent-mobl4.. (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id g21sm4381221pfc.95.2021.12.03.16.15.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Dec 2021 16:15:43 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH 1/3] Bluetooth: mgmt: Introduce mgmt_alloc_skb and mgmt_send_event_skb Date: Fri, 3 Dec 2021 16:15:40 -0800 Message-Id: <20211204001542.2404778-1-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.33.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz This introduces mgmt_alloc_skb and mgmt_send_event_skb which are convenient when building MGMT events that have variable length as the likes of skb_put_data can be used to insert portion directly on the skb instead of having to first build an intermediate buffer just to be copied over the skb. Signed-off-by: Luiz Augusto von Dentz --- include/net/bluetooth/bluetooth.h | 6 +++ net/bluetooth/mgmt_util.c | 66 +++++++++++++++++++++++-------- net/bluetooth/mgmt_util.h | 4 ++ 3 files changed, 59 insertions(+), 17 deletions(-) diff --git a/include/net/bluetooth/bluetooth.h b/include/net/bluetooth/bluetooth.h index 2f31e571f34c..77906832353f 100644 --- a/include/net/bluetooth/bluetooth.h +++ b/include/net/bluetooth/bluetooth.h @@ -390,6 +390,11 @@ struct hci_ctrl { }; }; +struct mgmt_ctrl { + struct hci_dev *hdev; + u16 opcode; +}; + struct bt_skb_cb { u8 pkt_type; u8 force_active; @@ -399,6 +404,7 @@ struct bt_skb_cb { struct l2cap_ctrl l2cap; struct sco_ctrl sco; struct hci_ctrl hci; + struct mgmt_ctrl mgmt; }; }; #define bt_cb(skb) ((struct bt_skb_cb *)((skb)->cb)) diff --git a/net/bluetooth/mgmt_util.c b/net/bluetooth/mgmt_util.c index 83875f2a0604..edee60bbc7b4 100644 --- a/net/bluetooth/mgmt_util.c +++ b/net/bluetooth/mgmt_util.c @@ -56,40 +56,72 @@ static struct sk_buff *create_monitor_ctrl_event(__le16 index, u32 cookie, return skb; } -int mgmt_send_event(u16 event, struct hci_dev *hdev, unsigned short channel, - void *data, u16 data_len, int flag, struct sock *skip_sk) +struct sk_buff *mgmt_alloc_skb(struct hci_dev *hdev, u16 opcode, + unsigned int size) { struct sk_buff *skb; - struct mgmt_hdr *hdr; - skb = alloc_skb(sizeof(*hdr) + data_len, GFP_KERNEL); + skb = alloc_skb(sizeof(struct mgmt_hdr) + size, GFP_KERNEL); if (!skb) - return -ENOMEM; + return skb; - hdr = skb_put(skb, sizeof(*hdr)); - hdr->opcode = cpu_to_le16(event); - if (hdev) - hdr->index = cpu_to_le16(hdev->id); - else - hdr->index = cpu_to_le16(MGMT_INDEX_NONE); - hdr->len = cpu_to_le16(data_len); + skb_reserve(skb, sizeof(struct mgmt_hdr)); + bt_cb(skb)->mgmt.hdev = hdev; + bt_cb(skb)->mgmt.opcode = opcode; - if (data) - skb_put_data(skb, data, data_len); + return skb; +} + +int mgmt_send_event_skb(unsigned short channel, struct sk_buff *skb, int flag, + struct sock *skip_sk) +{ + struct hci_dev *hdev; + struct mgmt_hdr *hdr; + int len = skb->len; + + if (!skb) + return -EINVAL; + + hdev = bt_cb(skb)->mgmt.hdev; /* Time stamp */ __net_timestamp(skb); - hci_send_to_channel(channel, skb, flag, skip_sk); - + /* Send just the data, without headers, to the monitor */ if (channel == HCI_CHANNEL_CONTROL) - hci_send_monitor_ctrl_event(hdev, event, data, data_len, + hci_send_monitor_ctrl_event(hdev, bt_cb(skb)->mgmt.opcode, + skb->data, skb->len, skb_get_ktime(skb), flag, skip_sk); + hdr = skb_push(skb, sizeof(*hdr)); + hdr->opcode = cpu_to_le16(bt_cb(skb)->mgmt.opcode); + if (hdev) + hdr->index = cpu_to_le16(hdev->id); + else + hdr->index = cpu_to_le16(MGMT_INDEX_NONE); + hdr->len = cpu_to_le16(len); + + hci_send_to_channel(channel, skb, flag, skip_sk); + kfree_skb(skb); return 0; } +int mgmt_send_event(u16 event, struct hci_dev *hdev, unsigned short channel, + void *data, u16 data_len, int flag, struct sock *skip_sk) +{ + struct sk_buff *skb; + + skb = mgmt_alloc_skb(hdev, event, data_len); + if (!skb) + return -ENOMEM; + + if (data) + skb_put_data(skb, data, data_len); + + return mgmt_send_event_skb(channel, skb, flag, skip_sk); +} + int mgmt_cmd_status(struct sock *sk, u16 index, u16 cmd, u8 status) { struct sk_buff *skb, *mskb; diff --git a/net/bluetooth/mgmt_util.h b/net/bluetooth/mgmt_util.h index 63b965eaaaac..98e40395a383 100644 --- a/net/bluetooth/mgmt_util.h +++ b/net/bluetooth/mgmt_util.h @@ -32,6 +32,10 @@ struct mgmt_pending_cmd { int (*cmd_complete)(struct mgmt_pending_cmd *cmd, u8 status); }; +struct sk_buff *mgmt_alloc_skb(struct hci_dev *hdev, u16 opcode, + unsigned int size); +int mgmt_send_event_skb(unsigned short channel, struct sk_buff *skb, int flag, + struct sock *skip_sk); int mgmt_send_event(u16 event, struct hci_dev *hdev, unsigned short channel, void *data, u16 data_len, int flag, struct sock *skip_sk); int mgmt_cmd_status(struct sock *sk, u16 index, u16 cmd, u8 status); From patchwork Sat Dec 4 00:15:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 521678 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B535BC433F5 for ; Sat, 4 Dec 2021 00:15:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1383641AbhLDATL (ORCPT ); Fri, 3 Dec 2021 19:19:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45346 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1383637AbhLDATK (ORCPT ); Fri, 3 Dec 2021 19:19:10 -0500 Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D816AC061751 for ; Fri, 3 Dec 2021 16:15:45 -0800 (PST) Received: by mail-pj1-x102b.google.com with SMTP id x7so3535726pjn.0 for ; Fri, 03 Dec 2021 16:15:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=cntzzbMuHfFI+CW65xIGMit0hA1h9tWw2PgUkC3i+8Q=; b=KksgsIDmWRkAt7D2dQOjV3/trJDlvgpjbm82U5+ovUzFBt2a6z0b+HBhVmNAzfxKkl IkS9TrCIY5upyGVud9k8dLi5z3bO3wgqi4f0dYTjDJNXgOYLnrll+d1sgh0GihKzU7eS HDuU9lbj5R7aylMEKYS91Oy4lrNfWtDBQyCjBbVH4b/In1cy1dBdcYlt5mOmCN5ZAoIE PVgRakBlEDWJPYYS8VNhxaFWFDX4IDKE5MJlnq1LVzQLPTPcqFT6XVgutXqryNOhtzWC fXnfY3pucWe4pPkTt2DVUn3H5kBcC+uxIgJDx2VHjgyukFH+yfCuSW5AFpj5SzDuxUB1 7tFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=cntzzbMuHfFI+CW65xIGMit0hA1h9tWw2PgUkC3i+8Q=; b=DGqkh1kGsGA+HCriINxFM1awaq8oSCyaB6zPQZ7FdzJApOJ7K2t3MIWuhf9zogZYvv oIGVmcVSUyE1xYZ68B3x5b5visJQ5RmdUo/QTyejFpIGAhs+gthJlKJnLgP/OSdfewdC hQh80p3sriA+7W5I99LxQ7hWxYSIdjWo1VA2NLpCxB7Ht36p4rfmfAnnnh7Rw4XYKC1I Q/oYuhkLiBZ9pGx6mRo/lWqdegtFqJxmwGNXdQpjo58ZDCJW74MxcaM9eCukI4uifTb9 cnjXu4UiHnqF8o0YmIJvtWAFUTGVBPbbki3G9LQagib/kAePRS9Oc07QlrkzJilr/17A MoJw== X-Gm-Message-State: AOAM533xlHN/KWc1HDrTFqI6z7zwtP9oy0s53g5vm5Z7X2Q2kr+bxUWS I5eaFtSAEnx/vibwzyhxDWhtC59Pyv4= X-Google-Smtp-Source: ABdhPJzilvrsd5zmDtROaLKRQJf9JxdNAy87bS9o2bWVtIH5215OYW81A40hcLgkgfIT3pDIKSj6wg== X-Received: by 2002:a17:902:e890:b0:142:f3:7bf7 with SMTP id w16-20020a170902e89000b0014200f37bf7mr26115387plg.87.1638576945085; Fri, 03 Dec 2021 16:15:45 -0800 (PST) Received: from lvondent-mobl4.. (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id g21sm4381221pfc.95.2021.12.03.16.15.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Dec 2021 16:15:44 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH 2/3] Bluetooth: mgmt: Make use of mgmt_send_event_skb in MGMT_EV_DEVICE_FOUND Date: Fri, 3 Dec 2021 16:15:41 -0800 Message-Id: <20211204001542.2404778-2-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211204001542.2404778-1-luiz.dentz@gmail.com> References: <20211204001542.2404778-1-luiz.dentz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz This makes use of mgmt_alloc_skb to build MGMT_EV_DEVICE_FOUND so the data is copied directly to skb that is then sent using mgmt_send_event_skb eliminating the necessity of intermediary buffers. Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/mgmt.c | 52 ++++++++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 21 deletions(-) diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c index 7d3c69c3cf62..8a66f947c543 100644 --- a/net/bluetooth/mgmt.c +++ b/net/bluetooth/mgmt.c @@ -335,6 +335,12 @@ static int mgmt_event(u16 event, struct hci_dev *hdev, void *data, u16 len, HCI_SOCK_TRUSTED, skip_sk); } +static int mgmt_event_skb(struct sk_buff *skb, struct sock *skip_sk) +{ + return mgmt_send_event_skb(HCI_CHANNEL_CONTROL, skb, HCI_SOCK_TRUSTED, + skip_sk); +} + static u8 le_addr_type(u8 mgmt_addr_type) { if (mgmt_addr_type == BDADDR_LE_PUBLIC) @@ -9538,9 +9544,8 @@ void mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, u8 addr_type, u8 *dev_class, s8 rssi, u32 flags, u8 *eir, u16 eir_len, u8 *scan_rsp, u8 scan_rsp_len) { - char buf[512]; - struct mgmt_ev_device_found *ev = (void *)buf; - size_t ev_size; + struct sk_buff *skb; + struct mgmt_ev_device_found *ev; /* Don't send events for a non-kernel initiated discovery. With * LE one exception is if we have pend_le_reports > 0 in which @@ -9575,13 +9580,13 @@ void mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, } } - /* Make sure that the buffer is big enough. The 5 extra bytes - * are for the potential CoD field. - */ - if (sizeof(*ev) + eir_len + scan_rsp_len + 5 > sizeof(buf)) + /* Allocate skb. The 5 extra bytes are for the potential CoD field */ + skb = mgmt_alloc_skb(hdev, MGMT_EV_DEVICE_FOUND, + sizeof(ev) + eir_len + scan_rsp_len + 5); + if (!skb) return; - memset(buf, 0, sizeof(buf)); + ev = skb_put(skb, sizeof(*ev)); /* In case of device discovery with BR/EDR devices (pre 1.2), the * RSSI value was reported as 0 when not available. This behavior @@ -9602,35 +9607,39 @@ void mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, if (eir_len > 0) /* Copy EIR or advertising data into event */ - memcpy(ev->eir, eir, eir_len); + skb_put_data(skb, eir, eir_len); + + if (dev_class && !eir_get_data(eir, eir_len, EIR_CLASS_OF_DEV, NULL)) { + u8 eir_cod[5]; - if (dev_class && !eir_get_data(ev->eir, eir_len, EIR_CLASS_OF_DEV, - NULL)) - eir_len = eir_append_data(ev->eir, eir_len, EIR_CLASS_OF_DEV, - dev_class, 3); + eir_len += eir_append_data(eir_cod, 0, EIR_CLASS_OF_DEV, + dev_class, 3); + skb_put_data(skb, eir_cod, eir_len); + } if (scan_rsp_len > 0) /* Append scan response data to event */ - memcpy(ev->eir + eir_len, scan_rsp, scan_rsp_len); + skb_put_data(skb, scan_rsp, scan_rsp_len); ev->eir_len = cpu_to_le16(eir_len + scan_rsp_len); - ev_size = sizeof(*ev) + eir_len + scan_rsp_len; - mgmt_event(MGMT_EV_DEVICE_FOUND, hdev, ev, ev_size, NULL); + mgmt_event_skb(skb, NULL); } void mgmt_remote_name(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, u8 addr_type, s8 rssi, u8 *name, u8 name_len) { + struct sk_buff *skb; struct mgmt_ev_device_found *ev; - char buf[sizeof(*ev) + HCI_MAX_NAME_LENGTH + 2]; u16 eir_len; u32 flags; - ev = (struct mgmt_ev_device_found *) buf; - - memset(buf, 0, sizeof(buf)); + if (name_len) + skb = mgmt_alloc_skb(hdev, MGMT_EV_DEVICE_FOUND, 2 + name_len); + else + skb = mgmt_alloc_skb(hdev, MGMT_EV_DEVICE_FOUND, 0); + ev = skb_put(skb, sizeof(*ev)); bacpy(&ev->addr.bdaddr, bdaddr); ev->addr.type = link_to_bdaddr(link_type, addr_type); ev->rssi = rssi; @@ -9639,6 +9648,7 @@ void mgmt_remote_name(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, eir_len = eir_append_data(ev->eir, 0, EIR_NAME_COMPLETE, name, name_len); flags = 0; + skb_put(skb, eir_len); } else { eir_len = 0; flags = MGMT_DEV_FOUND_NAME_REQUEST_FAILED; @@ -9647,7 +9657,7 @@ void mgmt_remote_name(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, ev->eir_len = cpu_to_le16(eir_len); ev->flags = cpu_to_le32(flags); - mgmt_event(MGMT_EV_DEVICE_FOUND, hdev, ev, sizeof(*ev) + eir_len, NULL); + mgmt_event_skb(skb, NULL); } void mgmt_discovering(struct hci_dev *hdev, u8 discovering) From patchwork Sat Dec 4 00:15:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 520561 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8074EC433FE for ; Sat, 4 Dec 2021 00:15:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1383644AbhLDATM (ORCPT ); Fri, 3 Dec 2021 19:19:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45348 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1383642AbhLDATL (ORCPT ); Fri, 3 Dec 2021 19:19:11 -0500 Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9C788C061751 for ; Fri, 3 Dec 2021 16:15:46 -0800 (PST) Received: by mail-pj1-x1029.google.com with SMTP id np6-20020a17090b4c4600b001a90b011e06so3800923pjb.5 for ; Fri, 03 Dec 2021 16:15:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=M+jNHxwfLsPyteI00sSbEWzWWAo2qkIuzfSmXBKVTOA=; b=g7q/FXBRr6zko4OnM0m0DiEULYRMO4xUK0gooEVmTlBA/IacmITAWiUQRo5oAvNKal xsnSTTt+fNaUid7qD4YoRWToNhBopeIyOabGMFdkLcbcAPaMI+bVkTKssfVMg6iWk/vr k6WDh8nTqjLDC1N8stR6MN3DA7eKn27OXUJ4uDofLnBF5Rz8IYIrxYMysN7WcqXv7EgD PpmMz73mbGD/NOVZIqFagkYD49f07glSy16cMylBWxkG0oBPhWZo8Ywb9Khg5gV+kVd8 UiffW4622RywdhrdMx+E+NKky/oPfuKIMQ+SvwcXZnKlMhc3Up5VGnvvDCRAnEbnkFZb TG1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=M+jNHxwfLsPyteI00sSbEWzWWAo2qkIuzfSmXBKVTOA=; b=KJO8l0IooKIVlPN521pYbzeYAREk49W2iJm8koPirt6SykUbem660fQnD1DZfcL0WS JxE6WSJ+3uLj7rhSRaQZp/Uczh3YFBSn/iIfP2mCLPMDQhyg4OFEPPDIir/IMgq95aEZ o+ssYmmVKYnQTOllWTHjbQYcVosTLX4ngLxIVrlsp2I5HLRWOxyxhEJHQe0aInBZa9U7 qRPvilcvy/LDQRe3Wd8H9+a7TPzyZt0W2N6/QqweyD3FGOv8lxIBAiv1PSibezXjv4Iw XnMS20Z2LTbh6CG7btCl3qeE4iqqaVuTAMYluD89qoLSw96PkFszJzi5lTq+IG3rl8F6 eoHg== X-Gm-Message-State: AOAM533nRLQCExeRNXMdMcJ8I3uHJAFtncgOjkfA8cyPCqFv474tD5qV nsDXNzHIoyEILpQq06/HsCTWLXpDbtE= X-Google-Smtp-Source: ABdhPJwlZ4kNCloIojRNkFRRn+5iVIBjcgyu68awjYB0cS5XYTNoxzCZl6XYKYdbEJBSHX8m0iUfFQ== X-Received: by 2002:a17:902:e9c6:b0:141:c588:99b2 with SMTP id 6-20020a170902e9c600b00141c58899b2mr26410502plk.63.1638576945881; Fri, 03 Dec 2021 16:15:45 -0800 (PST) Received: from lvondent-mobl4.. (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id g21sm4381221pfc.95.2021.12.03.16.15.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Dec 2021 16:15:45 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH 3/3] Bluetooth: mgmt: Make use of mgmt_send_event_skb in MGMT_EV_DEVICE_CONNECTED Date: Fri, 3 Dec 2021 16:15:42 -0800 Message-Id: <20211204001542.2404778-3-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211204001542.2404778-1-luiz.dentz@gmail.com> References: <20211204001542.2404778-1-luiz.dentz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz This makes use of mgmt_alloc_skb to build MGMT_EV_DEVICE_CONNECTED so the data is copied directly to skb that is then sent using mgmt_send_event_skb eliminating the necessity of intermediary buffers. Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/mgmt.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c index 8a66f947c543..cee771516431 100644 --- a/net/bluetooth/mgmt.c +++ b/net/bluetooth/mgmt.c @@ -9015,11 +9015,19 @@ void mgmt_new_conn_param(struct hci_dev *hdev, bdaddr_t *bdaddr, void mgmt_device_connected(struct hci_dev *hdev, struct hci_conn *conn, u8 *name, u8 name_len) { - char buf[512]; - struct mgmt_ev_device_connected *ev = (void *) buf; + struct sk_buff *skb; + struct mgmt_ev_device_connected *ev; u16 eir_len = 0; u32 flags = 0; + if (conn->le_adv_data_len > 0) + skb = mgmt_alloc_skb(hdev, MGMT_EV_DEVICE_CONNECTED, + conn->le_adv_data_len); + else + skb = mgmt_alloc_skb(hdev, MGMT_EV_DEVICE_CONNECTED, + 2 + name_len + 5); + + ev = skb_put(skb, sizeof(*ev)); bacpy(&ev->addr.bdaddr, &conn->dst); ev->addr.type = link_to_bdaddr(conn->type, conn->dst_type); @@ -9033,24 +9041,26 @@ void mgmt_device_connected(struct hci_dev *hdev, struct hci_conn *conn, * adding any BR/EDR data to the LE adv. */ if (conn->le_adv_data_len > 0) { - memcpy(&ev->eir[eir_len], - conn->le_adv_data, conn->le_adv_data_len); + skb_put_data(skb, conn->le_adv_data, conn->le_adv_data_len); eir_len = conn->le_adv_data_len; } else { - if (name_len > 0) + if (name_len > 0) { eir_len = eir_append_data(ev->eir, 0, EIR_NAME_COMPLETE, name, name_len); + skb_put(skb, eir_len); + } - if (memcmp(conn->dev_class, "\0\0\0", 3) != 0) + if (memcmp(conn->dev_class, "\0\0\0", 3) != 0) { eir_len = eir_append_data(ev->eir, eir_len, EIR_CLASS_OF_DEV, conn->dev_class, 3); + skb_put(skb, 5); + } } ev->eir_len = cpu_to_le16(eir_len); - mgmt_event(MGMT_EV_DEVICE_CONNECTED, hdev, buf, - sizeof(*ev) + eir_len, NULL); + mgmt_event_skb(skb, NULL); } static void disconnect_rsp(struct mgmt_pending_cmd *cmd, void *data)