Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp4458997iob; Sun, 8 May 2022 13:31:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxPHurssbSTh9a+/eEETDAu/NUT4k1TbgkfLoFwSl9v16jpiHMM4Zd3xr/WGbmAHzS8iixu X-Received: by 2002:a17:907:6eac:b0:6f8:61c4:4cb3 with SMTP id sh44-20020a1709076eac00b006f861c44cb3mr6123342ejc.597.1652041909929; Sun, 08 May 2022 13:31:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652041909; cv=none; d=google.com; s=arc-20160816; b=FJonzxFvl/Wk2skMTQSk3MKU8nGST0H5dOokVfTizGTPs4UD12nCdYxVDMzrKqCpv1 2q4WNTp4FqicyASRBMRdJb+k69P/76OH4eN8Uwv7udiB2Fm2qiUWBlZa9q5o5dRomaOt cLcNdnaOf6vA1qodXQuRx8eUVjuKMCmqdkJ8lw0e/us7oiPK26jpfrS7hRE/wbS9qM8F cZKiHGSMohGQdQdhkaO2q/iDdU1o+CaKlppTiUiSUOqMbdKijChUOemtMwbCtZCKNrLE NWWD/SdPFZNakqyGwvV8ORoYZKY41NHOldFAidFgUOBkbLZGcFqDcdNCsjZCiY+Jn+9t 3acw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:to:from:dkim-signature; bh=KCvHkTgUJPXdUl27Xc90pd5nJnvEbH2ygjEL3W2BokQ=; b=iO6/k51P6ChTJbI+qk1YkalzmKvh3Y86JoYYT7r4CZ9U6Lwq062brpkci9QNbezdn3 JUve09z1rKd/FbmdFlqT1nMq3ZqsAcYIbgshvFvZmMU2Zk/2fiyasOF8krOr3MHhFSpH dXYdYL3E0jLzGUyJSIzeU4s/1C29PVX20z76nnzdLvAvr3t6DnD+lKP3w30/t1qndrBj HHs20i0049djSrh+vtw39kvnd3XVasOSn9IX6va1ArsqeqYedQyu3/oAuUiHMUQc3n/B jKs5Ux3/2padShlGQfse8tOhOPVfWBRb13BaYkt/EHAhRb6drvIRpod1gsjUQoTygjpA YYJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=mOzTYD0X; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id fi3-20020a1709073ac300b006e7f6476797si9872288ejc.739.2022.05.08.13.31.08; Sun, 08 May 2022 13:31:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=mOzTYD0X; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355488AbiEFWBd (ORCPT + 99 others); Fri, 6 May 2022 18:01:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49010 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1444626AbiEFWBb (ORCPT ); Fri, 6 May 2022 18:01:31 -0400 Received: from mail-io1-xd35.google.com (mail-io1-xd35.google.com [IPv6:2607:f8b0:4864:20::d35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C17AE3EBA3 for ; Fri, 6 May 2022 14:57:46 -0700 (PDT) Received: by mail-io1-xd35.google.com with SMTP id e15so9504327iob.3 for ; Fri, 06 May 2022 14:57:46 -0700 (PDT) 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=KCvHkTgUJPXdUl27Xc90pd5nJnvEbH2ygjEL3W2BokQ=; b=mOzTYD0XlP+XyZLNWHdDbBr706vcnB7VS9Wnc8cbSK6SaGlyi1IOMxuVeSkJQoMKE/ PbotlYO2Z4AnaCFF1mBo3Uyzl5uKBDnDfxd9s4OP+L4ZTBcJmh8tAUNS95P8Gv6vQVjx 0fzHQ0XQN11p3ZqJ3jGFnRRB+UvA7PzENJZHUcXyPuUS38pnRAgCNfwpyHP7AHTN1Ahv fiqKGm/+UfMNLmN0Mu9tZJ9Ijkuq+pc5zS4xbETLNjJAYRScgMYmyWpIDPjEUS5QMjcH MA7kh57Tmb9vAuJM3MvJT2es4+HkrHoJd3+HcmefG+Ok89HawHVN+Lvy7YYybKNyaME1 jwCQ== 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=KCvHkTgUJPXdUl27Xc90pd5nJnvEbH2ygjEL3W2BokQ=; b=u8q4LjifqkmmtspZbS9xOFVWlLuA0Oc98a4HQNdGoog+5n6j7+SkL1muHWMHPV787M fNjtNEWIn8fgrq7P1EBpXlCawgx7t69djGK2ka/zt+FWqwFpQy7WpnGdREH1RNwXfofm fJigdgUUIpwsW/ERlPh+RuXg5e4QYn67aIwsMpYCY3x9PLYJ3/Pa8iMTLMtLSAc86seg 6AhXOTo16WFF3uAYquVPILBASdXJsc7eUjc+1Q5DRPo2tumoQXt+deQ5Rzzkn76WuG/O VntQr8CjmX8fdXfgUsPDhoY6NM+rgE5bb3zR9Ru9JUSR2aDLsYwpi4ESJffykpqorirI w9hA== X-Gm-Message-State: AOAM531BKaL9sa6TAV7o+iVhxnrG7rWcwU0/iT0csMVCOjMgm39YAi0R CarokeGtmPSJZ7VnL9ST3VKCuPy6ye4= X-Received: by 2002:a02:8605:0:b0:32b:1dd7:fc31 with SMTP id e5-20020a028605000000b0032b1dd7fc31mr2256425jai.174.1651874265733; Fri, 06 May 2022 14:57:45 -0700 (PDT) Received: from lvondent-mobl4.. (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id s14-20020a5e980e000000b0065aab053448sm1572281ioj.21.2022.05.06.14.57.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 May 2022 14:57:44 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH v2 1/8] Bluetooth: eir: Add helpers for managing service data Date: Fri, 6 May 2022 14:57:36 -0700 Message-Id: <20220506215743.3870212-1-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz This adds helpers for accessing and appending service data (0x16) ad type. Signed-off-by: Luiz Augusto von Dentz --- v2: Fixes CI/kernel test robot findings include/net/bluetooth/hci.h | 1 + net/bluetooth/eir.c | 31 +++++++++++++++++++++++++++++++ net/bluetooth/eir.h | 4 ++++ 3 files changed, 36 insertions(+) diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h index 62a9bb022aed..fe7935be7dc4 100644 --- a/include/net/bluetooth/hci.h +++ b/include/net/bluetooth/hci.h @@ -625,6 +625,7 @@ enum { #define EIR_SSP_RAND_R192 0x0F /* Simple Pairing Randomizer R-192 */ #define EIR_DEVICE_ID 0x10 /* device ID */ #define EIR_APPEARANCE 0x19 /* Device appearance */ +#define EIR_SERVICE_DATA 0x16 /* Service Data */ #define EIR_LE_BDADDR 0x1B /* LE Bluetooth device address */ #define EIR_LE_ROLE 0x1C /* LE role */ #define EIR_SSP_HASH_C256 0x1D /* Simple Pairing Hash C-256 */ diff --git a/net/bluetooth/eir.c b/net/bluetooth/eir.c index 7e930f77ecab..7d77fb00c2bf 100644 --- a/net/bluetooth/eir.c +++ b/net/bluetooth/eir.c @@ -55,6 +55,19 @@ u8 eir_append_appearance(struct hci_dev *hdev, u8 *ptr, u8 ad_len) return eir_append_le16(ptr, ad_len, EIR_APPEARANCE, hdev->appearance); } +u8 eir_append_service_data(u8 *eir, u16 eir_len, u16 uuid, u8 *data, + u8 data_len) +{ + eir[eir_len++] = sizeof(u8) + sizeof(uuid) + data_len; + eir[eir_len++] = EIR_SERVICE_DATA; + put_unaligned_le16(uuid, &eir[eir_len]); + eir_len += sizeof(uuid); + memcpy(&eir[eir_len], data, data_len); + eir_len += data_len; + + return eir_len; +} + static u8 *create_uuid16_list(struct hci_dev *hdev, u8 *data, ptrdiff_t len) { u8 *ptr = data, *uuids_start = NULL; @@ -333,3 +346,21 @@ u8 eir_create_scan_rsp(struct hci_dev *hdev, u8 instance, u8 *ptr) return scan_rsp_len; } + +void *eir_get_service_data(u8 *eir, size_t eir_len, u16 uuid, size_t *len) +{ + while ((eir = eir_get_data(eir, eir_len, EIR_SERVICE_DATA, len))) { + u16 value = get_unaligned_le16(eir); + + if (uuid == value) { + if (len) + *len -= 2; + return &eir[2]; + } + + eir += *len; + eir_len -= *len; + } + + return NULL; +} diff --git a/net/bluetooth/eir.h b/net/bluetooth/eir.h index 43f1945bffc5..62f2374078f2 100644 --- a/net/bluetooth/eir.h +++ b/net/bluetooth/eir.h @@ -14,6 +14,8 @@ u8 eir_create_scan_rsp(struct hci_dev *hdev, u8 instance, u8 *ptr); u8 eir_append_local_name(struct hci_dev *hdev, u8 *eir, u8 ad_len); u8 eir_append_appearance(struct hci_dev *hdev, u8 *ptr, u8 ad_len); +u8 eir_append_service_data(u8 *eir, u16 eir_len, u16 uuid, u8 *data, + u8 data_len); static inline u16 eir_precalc_len(u8 data_len) { @@ -92,3 +94,5 @@ static inline void *eir_get_data(u8 *eir, size_t eir_len, u8 type, return NULL; } + +void *eir_get_service_data(u8 *eir, size_t eir_len, u16 uuid, size_t *len); -- 2.35.1