From patchwork Wed Jul 12 19:38:50 2023 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: 701933 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 B1378EB64DA for ; Wed, 12 Jul 2023 19:39:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232559AbjGLTjB (ORCPT ); Wed, 12 Jul 2023 15:39:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34702 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232512AbjGLTi7 (ORCPT ); Wed, 12 Jul 2023 15:38:59 -0400 Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0763B1FC7 for ; Wed, 12 Jul 2023 12:38:58 -0700 (PDT) Received: by mail-pl1-x632.google.com with SMTP id d9443c01a7336-1b89d47ffb6so39106825ad.2 for ; Wed, 12 Jul 2023 12:38:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689190736; x=1691782736; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=wB0E2E/APImMxF1i4xMgrl3zQnLPKzmkgdmDUSKO/iY=; b=HXcwkboJTT5DhvG/ypMvTPKiXkC8Xn1EGv0hPxUZ6GfYhM7NmDA0fbmDhUE9i1LMvB O0/U1tva/GDN6tfwL9COFoUx39hnCiIWj1zbzJQGL42gh5C/vn5RUAxVajr4YU57321A X12/jIgsloa8NwVZU8P+U3LzrBiXvnxWh6FZlv+YwMvYIKWjRnNzMlE5QF2cZ1KCU423 ZAkCnr4Qz5E5RXe3JOVYl3m9cPOmacDuSxB9GjvdhdGRnmOJVttX4K0TUdTn54X+cDW/ N4i5q+NUOtJN8opzmFh10cAZqGZ14ySJetEoXU1I9oBzXHYbt6b74dmM+IfMEBx//Oue pRVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689190736; x=1691782736; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=wB0E2E/APImMxF1i4xMgrl3zQnLPKzmkgdmDUSKO/iY=; b=eNN6iqUzCKftx9Uv5jAQ8oaDY20hEcc14YDXp9/VBDCVs7UfDnxhVOqAV/FLW690hQ Yplm6ESHcI+lYd1xDrIVrn0mmk9xphlGvLBckfrWkTWJMg2qE+bwTXqmpSXfN5VuINQz JJoHdW5INPbFfY4bH69sjDoidDQqWBzogDbK3FFt+kw3nrHlVAqSrUdvlDPuravfQyyC 2pYEP31Gz4znzxYjYikHRLTGPcnOsaWKUVkps8aLemLHBqIWmAaoEIqh2ytFIs35nS0L 5OkJqO0a0U0SbiA39jRF8NRdHuTQ7wJYmwqUHDZGmL3TTiJ5T0wvfZZSoc+So9T/KIiZ Ll7A== X-Gm-Message-State: ABy/qLbc3T15Fpj8C3pUPCpmd6hf8251FnvOwmP8E/7PPvSPgc0vG0aK JRPI/u8xBJf/YReblkxb4rhzFGxyus0= X-Google-Smtp-Source: APBJJlF/8LTZGELKbbRlb25knzr75OSW6pChERBH0A46oSDL504Xlueuo3DAar16VXB8ynToYLdOSg== X-Received: by 2002:a17:903:41d2:b0:1b8:ab0d:cd5 with SMTP id u18-20020a17090341d200b001b8ab0d0cd5mr19678026ple.49.1689190736210; Wed, 12 Jul 2023 12:38:56 -0700 (PDT) Received: from lvondent-mobl4.. (c-71-236-201-58.hsd1.or.comcast.net. [71.236.201.58]) by smtp.gmail.com with ESMTPSA id ij12-20020a170902ab4c00b001b84cd8814bsm4413264plb.65.2023.07.12.12.38.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jul 2023 12:38:55 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ 1/5] shared/ad: Use util_iov_push_* helpers to generate data Date: Wed, 12 Jul 2023 12:38:50 -0700 Message-Id: <20230712193854.1862996-1-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.40.1 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 util_iov_push_* helpers to generate the data. --- src/shared/ad.c | 163 ++++++++++++++++++++++-------------------------- 1 file changed, 74 insertions(+), 89 deletions(-) diff --git a/src/shared/ad.c b/src/shared/ad.c index 8b3fde2b1dcd..e8bebe70708e 100644 --- a/src/shared/ad.c +++ b/src/shared/ad.c @@ -365,84 +365,80 @@ static size_t calculate_length(struct bt_ad *ad) } static void serialize_uuids(struct queue *uuids, uint8_t uuid_type, - uint8_t ad_type, uint8_t *buf, - uint8_t *pos) + uint8_t ad_type, struct iovec *iov) { const struct queue_entry *entry = queue_get_entries(uuids); - bool added = false; - uint8_t length_pos = 0; + uint8_t *len = NULL; while (entry) { bt_uuid_t *uuid = entry->data; if (uuid->type == uuid_type) { - if (!added) { - length_pos = (*pos)++; - buf[(*pos)++] = ad_type; - added = true; + if (!len) { + len = iov->iov_base + iov->iov_len; + util_iov_push_u8(iov, 1); + util_iov_push_u8(iov, ad_type); } - if (uuid_type != BT_UUID32) - bt_uuid_to_le(uuid, buf + *pos); - else - bt_put_le32(uuid->value.u32, buf + *pos); - - *pos += bt_uuid_len(uuid); + switch (uuid->type) { + case BT_UUID16: + util_iov_push_le16(iov, uuid->value.u16); + *len += 2; + break; + case BT_UUID32: + util_iov_push_le32(iov, uuid->value.u32); + *len += 4; + break; + case BT_UUID128: + bt_uuid_to_le(uuid, util_iov_push(iov, 16)); + *len += 16; + break; + case BT_UUID_UNSPEC: + break; + } } entry = entry->next; } - - if (added) - buf[length_pos] = *pos - length_pos - 1; } -static void serialize_service_uuids(struct queue *uuids, uint8_t *buf, - uint8_t *pos) +static void serialize_service_uuids(struct queue *uuids, struct iovec *iov) { - serialize_uuids(uuids, BT_UUID16, BT_AD_UUID16_ALL, buf, pos); + serialize_uuids(uuids, BT_UUID16, BT_AD_UUID16_ALL, iov); - serialize_uuids(uuids, BT_UUID32, BT_AD_UUID32_ALL, buf, pos); + serialize_uuids(uuids, BT_UUID32, BT_AD_UUID32_ALL, iov); - serialize_uuids(uuids, BT_UUID128, BT_AD_UUID128_ALL, buf, pos); + serialize_uuids(uuids, BT_UUID128, BT_AD_UUID128_ALL, iov); } -static void serialize_solicit_uuids(struct queue *uuids, uint8_t *buf, - uint8_t *pos) +static void serialize_solicit_uuids(struct queue *uuids, struct iovec *iov) { - serialize_uuids(uuids, BT_UUID16, BT_AD_SOLICIT16, buf, pos); + serialize_uuids(uuids, BT_UUID16, BT_AD_SOLICIT16, iov); - serialize_uuids(uuids, BT_UUID32, BT_AD_SOLICIT32, buf, pos); + serialize_uuids(uuids, BT_UUID32, BT_AD_SOLICIT32, iov); - serialize_uuids(uuids, BT_UUID128, BT_AD_SOLICIT128, buf, pos); + serialize_uuids(uuids, BT_UUID128, BT_AD_SOLICIT128, iov); } -static void serialize_manuf_data(struct queue *manuf_data, uint8_t *buf, - uint8_t *pos) +static void serialize_manuf_data(struct queue *manuf_data, struct iovec *iov) { const struct queue_entry *entry = queue_get_entries(manuf_data); while (entry) { struct bt_ad_manufacturer_data *data = entry->data; - buf[(*pos)++] = data->len + 2 + 1; + util_iov_push_u8(iov, data->len + 2 + 1); + util_iov_push_u8(iov, BT_AD_MANUFACTURER_DATA); - buf[(*pos)++] = BT_AD_MANUFACTURER_DATA; - - bt_put_le16(data->manufacturer_id, buf + (*pos)); - - *pos += 2; - - memcpy(buf + *pos, data->data, data->len); - - *pos += data->len; + util_iov_push_le16(iov, data->manufacturer_id); + util_iov_push_mem(iov, data->len, data->data); entry = entry->next; } } -static void serialize_service_data(struct queue *service_data, uint8_t *buf, - uint8_t *pos) +static void serialize_service_data(struct queue *service_data, + struct iovec *iov) { const struct queue_entry *entry = queue_get_entries(service_data); @@ -450,81 +446,69 @@ static void serialize_service_data(struct queue *service_data, uint8_t *buf, struct bt_ad_service_data *data = entry->data; int uuid_len = bt_uuid_len(&data->uuid); - buf[(*pos)++] = uuid_len + data->len + 1; + util_iov_push_u8(iov, data->len + uuid_len + 1); switch (uuid_len) { case 2: - buf[(*pos)++] = BT_AD_SERVICE_DATA16; + util_iov_push_u8(iov, BT_AD_SERVICE_DATA16); + util_iov_push_le16(iov, data->uuid.value.u16); break; case 4: - buf[(*pos)++] = BT_AD_SERVICE_DATA32; + util_iov_push_u8(iov, BT_AD_SERVICE_DATA32); + util_iov_push_le32(iov, data->uuid.value.u32); break; case 16: - buf[(*pos)++] = BT_AD_SERVICE_DATA128; + util_iov_push_u8(iov, BT_AD_SERVICE_DATA128); + bt_uuid_to_le(&data->uuid, + util_iov_push(iov, uuid_len)); break; } - if (uuid_len != 4) - bt_uuid_to_le(&data->uuid, buf + *pos); - else - bt_put_le32(data->uuid.value.u32, buf + *pos); - - *pos += uuid_len; - - memcpy(buf + *pos, data->data, data->len); - - *pos += data->len; + util_iov_push_mem(iov, data->len, data->data); entry = entry->next; } } -static void serialize_name(struct bt_ad *ad, uint8_t *buf, uint8_t *pos) +static void serialize_name(struct bt_ad *ad, struct iovec *iov) { - int len; + size_t len; uint8_t type = BT_AD_NAME_COMPLETE; if (!ad->name) return; len = strlen(ad->name); - if (len > ad->max_len - (*pos + 2)) { + if (len > ad->max_len - (iov->iov_len + 2)) { type = BT_AD_NAME_SHORT; - len = ad->max_len - (*pos + 2); + len = ad->max_len - (iov->iov_len + 2); } - buf[(*pos)++] = len + 1; - buf[(*pos)++] = type; - - memcpy(buf + *pos, ad->name, len); - *pos += len; + util_iov_push_u8(iov, len + 1); + util_iov_push_u8(iov, type); + util_iov_push_mem(iov, len, ad->name); } -static void serialize_appearance(struct bt_ad *ad, uint8_t *buf, uint8_t *pos) +static void serialize_appearance(struct bt_ad *ad, struct iovec *iov) { if (ad->appearance == UINT16_MAX) return; - buf[(*pos)++] = sizeof(ad->appearance) + 1; - buf[(*pos)++] = BT_AD_GAP_APPEARANCE; - - bt_put_le16(ad->appearance, buf + (*pos)); - *pos += 2; + util_iov_push_u8(iov, sizeof(ad->appearance) + 1); + util_iov_push_u8(iov, BT_AD_GAP_APPEARANCE); + util_iov_push_le16(iov, ad->appearance); } -static void serialize_data(struct queue *queue, uint8_t *buf, uint8_t *pos) +static void serialize_data(struct queue *queue, struct iovec *iov) { const struct queue_entry *entry = queue_get_entries(queue); while (entry) { struct bt_ad_data *data = entry->data; - buf[(*pos)++] = data->len + 1; - buf[(*pos)++] = data->type; - - memcpy(buf + *pos, data->data, data->len); - - *pos += data->len; + util_iov_push_u8(iov, data->len + 1); + util_iov_push_u8(iov, data->type); + util_iov_push_mem(iov, data->len, data->data); entry = entry->next; } @@ -532,8 +516,7 @@ static void serialize_data(struct queue *queue, uint8_t *buf, uint8_t *pos) uint8_t *bt_ad_generate(struct bt_ad *ad, size_t *length) { - uint8_t *adv_data; - uint8_t pos = 0; + struct iovec iov; if (!ad) return NULL; @@ -543,25 +526,27 @@ uint8_t *bt_ad_generate(struct bt_ad *ad, size_t *length) if (*length > ad->max_len) return NULL; - adv_data = malloc0(*length); - if (!adv_data) + iov.iov_base = malloc0(*length); + if (!iov.iov_base) return NULL; - serialize_service_uuids(ad->service_uuids, adv_data, &pos); + iov.iov_len = 0; - serialize_solicit_uuids(ad->solicit_uuids, adv_data, &pos); + serialize_service_uuids(ad->service_uuids, &iov); - serialize_manuf_data(ad->manufacturer_data, adv_data, &pos); + serialize_solicit_uuids(ad->solicit_uuids, &iov); - serialize_service_data(ad->service_data, adv_data, &pos); + serialize_manuf_data(ad->manufacturer_data, &iov); - serialize_name(ad, adv_data, &pos); + serialize_service_data(ad->service_data, &iov); - serialize_appearance(ad, adv_data, &pos); + serialize_name(ad, &iov); - serialize_data(ad->data, adv_data, &pos); + serialize_appearance(ad, &iov); - return adv_data; + serialize_data(ad->data, &iov); + + return iov.iov_base; } bool bt_ad_is_empty(struct bt_ad *ad) From patchwork Wed Jul 12 19:38:51 2023 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: 704157 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 3F0E2C0015E for ; Wed, 12 Jul 2023 19:39:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232550AbjGLTjC (ORCPT ); Wed, 12 Jul 2023 15:39:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34740 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232582AbjGLTjB (ORCPT ); Wed, 12 Jul 2023 15:39:01 -0400 Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DA5D71FE4 for ; Wed, 12 Jul 2023 12:38:59 -0700 (PDT) Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-1b8ad356f03so48737935ad.1 for ; Wed, 12 Jul 2023 12:38:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689190738; x=1691782738; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=MyDU1INtuPnC1dvOf6tBCH0BkXwEoWCuMhND3vaDQkk=; b=Sv2E49ihqys/5aLky6sqIyXyZzAHGJoXORtvUhvoGdsbkT/9mY/bfvbfOcYjT7MQ5w CPl7boUI5hZcvJs2eSYjzplWc2G+CpyZWmxw8OoDRFQmvwboIieuDpX9//WU/3QHotMi 744vGw59UoJNQfw2pMlIBW/hRLWQ2HeahUlFlRDbAY4vRCcDUHCEKl2RwtKF7qKpnRDD iJD+f1rQI/Kkd8vgqC5TEpdCokzoGn7oYCwLITmLmGyGI4vpF4cjp9CTZ/tkHWCGymKO fiZ3/qiD/YoKiEVZMxgiZf03Zqp8i3XfcLGEOl3sn2G1tgE17XA5FeLgXe0HKKDrsZoL t+xw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689190738; x=1691782738; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MyDU1INtuPnC1dvOf6tBCH0BkXwEoWCuMhND3vaDQkk=; b=Ffo2AYfr0iuxmwSRW5IlPUucJy4vL/puPw3KkWE7V89TGxz/P92rLrss++lA46gM+k DeyRYB5l9tYE1Hv6MiDtyEdsJ8J5CqwZCNUvRTQwXi6c/1ZCdAyDqAX/MUrTpaNW4Qxh uPC1MxIvtSxPkg73VbYaRur54DWUmH5EdPbnYF7X4n1L0oEEJh2i9ydyLRV+XXJAB02a rzr7ilhTjE4ixPXsxTNgXEPoM1c7DTU83/KFvLPkwUyD/eSsTMVNj801fbOa0mE5PhG4 j4qHPcaHJXqT5ZdBph7UJVzc4asWIu7y8W5+Jppwclh3+S3AjvBflzGJZLDsLRQ+oO2h CF9g== X-Gm-Message-State: ABy/qLYrv3eKzn0ysO/XfA9ZDphOU5/Kjo6K7qLZ4ngdvUmT3j2QtzH3 gSwSo3fT3VUC5n6hAHjVsLmns/aN4mE= X-Google-Smtp-Source: APBJJlFHSMXcKLTui/WhH8zvpDL/uujjTi4b9fPYokfyFl7NpJYinIsU0qaY0U4krvgLAaPXpo3KlQ== X-Received: by 2002:a17:902:e746:b0:1b9:ce7a:8603 with SMTP id p6-20020a170902e74600b001b9ce7a8603mr14032025plf.66.1689190738530; Wed, 12 Jul 2023 12:38:58 -0700 (PDT) Received: from lvondent-mobl4.. (c-71-236-201-58.hsd1.or.comcast.net. [71.236.201.58]) by smtp.gmail.com with ESMTPSA id ij12-20020a170902ab4c00b001b84cd8814bsm4413264plb.65.2023.07.12.12.38.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jul 2023 12:38:56 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ 2/5] main: Remove DEFAULT_SIRK Date: Wed, 12 Jul 2023 12:38:51 -0700 Message-Id: <20230712193854.1862996-2-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230712193854.1862996-1-luiz.dentz@gmail.com> References: <20230712193854.1862996-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 DEFAULT_SIRK is currently not used. --- src/main.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/main.c b/src/main.c index 8dfd2543ba1c..150a5af4cca4 100644 --- a/src/main.c +++ b/src/main.c @@ -61,9 +61,6 @@ #define DEFAULT_TEMPORARY_TIMEOUT 30 /* 30 seconds */ #define DEFAULT_NAME_REQUEST_RETRY_DELAY 300 /* 5 minutes */ -/*CSIP Profile - Server */ -#define DEFAULT_SIRK "761FAE703ED681F0C50B34155B6434FB" - #define SHUTDOWN_GRACE_SECONDS 10 struct btd_opts btd_opts; From patchwork Wed Jul 12 19:38:52 2023 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: 701932 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 2F6E7C001DE for ; Wed, 12 Jul 2023 19:39:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232555AbjGLTjE (ORCPT ); Wed, 12 Jul 2023 15:39:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34746 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232541AbjGLTjC (ORCPT ); Wed, 12 Jul 2023 15:39:02 -0400 Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F0F681FC7 for ; Wed, 12 Jul 2023 12:39:01 -0700 (PDT) Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-1b895a06484so39095005ad.1 for ; Wed, 12 Jul 2023 12:39:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689190740; x=1691782740; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=s/Sp+CYoanXDATUPRoonQHqBB4S+uYRSPpoZ9z/Hp1c=; b=jD1VwpacPc3qdKE7OIiJb0jN1d+SZ117AA6hjgITh67AsJZ9qhmEGBUVAAJXvq+0T2 J2+FeSwjKYo5ckcF9upuNi++sQ7USmIkm+RNB6FbSRqIjKJ2q3J56Ge+hMv6eRA4ovEb L4NenDzPnw+W7V3eP2E++CRpnbfUObImepe86h3clvFFZFS3OOikRCJNxJ6KnbpGTHmQ OmwM6MRBLia12ToLpWpT+covZ1uiBAL0uEsKKMHEwetKrLWcGR/rxf87VztwIqzK10eZ DMpE3piRmx5tOBe6922/mRHA1lv9bn5E99CPK9AITI7gVO1pVmcSQBGmaoWhMnNd0JZx v1uQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689190740; x=1691782740; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=s/Sp+CYoanXDATUPRoonQHqBB4S+uYRSPpoZ9z/Hp1c=; b=RmY+lL1ciEBEqF3PjXRgkF4z4IkbWwUA69T4J2krMV34ZkrzQFDasV4K2o6KDITlp5 gUwsL7w8nvFF7fcQbsviwfyIm5X/+erZSehEB7YYEUpdCj166IK+r+3xrexoRTcW5oZC 2qZ2Noe3eODUg6DssKKTxzoBRM6paEGR2cUuaxlzwayLriTiOF87K1BkIPWl1HGvsd7R BqKIeBh4lQQKjxGaHbFDvGNwMxvH4b8IJSIfur6JSctNn1owKlX4qr0pExV3RaIFwQWL 7wALqPKIiKAhmG1cTr2z7HJ5OtcFneff5kXh8wM7kZvkupZs42TKGSzessTXnkwv7M/d lo9A== X-Gm-Message-State: ABy/qLYUv+z7CpV+vp2GEecnyyWAH02DKylDMI6pO6I65OhKGGpKz0XS mRcflDuUIwV9kOJ7Br/l/f0F0rLTySY= X-Google-Smtp-Source: APBJJlFrcatOGHNFNajKMFW5F2KWZ1pUXImttgvZ07PTwwXC6OuTwR9HpmdCzuOocZ+o7BYTGN+zbg== X-Received: by 2002:a17:902:ea0d:b0:1b6:bced:1dd6 with SMTP id s13-20020a170902ea0d00b001b6bced1dd6mr18089455plg.35.1689190740350; Wed, 12 Jul 2023 12:39:00 -0700 (PDT) Received: from lvondent-mobl4.. (c-71-236-201-58.hsd1.or.comcast.net. [71.236.201.58]) by smtp.gmail.com with ESMTPSA id ij12-20020a170902ab4c00b001b84cd8814bsm4413264plb.65.2023.07.12.12.38.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jul 2023 12:38:59 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ 3/5] shared/util: Introduce strisutf8 Date: Wed, 12 Jul 2023 12:38:52 -0700 Message-Id: <20230712193854.1862996-3-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230712193854.1862996-1-luiz.dentz@gmail.com> References: <20230712193854.1862996-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 introduces strisutf8 which can be used to verify if a string is encoded using UTF-8 format. --- src/shared/util.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++ src/shared/util.h | 3 +++ 2 files changed, 65 insertions(+) diff --git a/src/shared/util.c b/src/shared/util.c index 4d1c0d00545d..e9c1c18f5ea7 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -1705,3 +1705,65 @@ int strsuffix(const char *str, const char *suffix) return strncmp(str + len - suffix_len, suffix, suffix_len); } + +char *strstrip(char *str) +{ + size_t size; + char *end; + + if (!str) + return NULL; + + size = strlen(str); + if (!size) + return str; + + end = str + size - 1; + while (end >= str && isspace(*end)) + end--; + *(end + 1) = '\0'; + + while (*str && isspace(*str)) + str++; + + return str; +} + +bool strisutf8(const char *str, size_t len) +{ + size_t i = 0; + + while (i < len) { + unsigned char c = str[i]; + size_t size = 0; + + /* Check the first byte to determine the number of bytes in the + * UTF-8 character. + */ + if ((c & 0x80) == 0x00) + size = 1; + else if ((c & 0xE0) == 0xC0) + size = 2; + else if ((c & 0xF0) == 0xE0) + size = 3; + else if ((c & 0xF8) == 0xF0) + size = 4; + else + /* Invalid UTF-8 sequence */ + return false; + + /* Check the following bytes to ensure they have the correct + * format. + */ + for (size_t j = 1; j < size; ++j) { + if (i + j > len || (str[i + j] & 0xC0) != 0x80) + /* Invalid UTF-8 sequence */ + return false; + } + + /* Move to the next character */ + i += size; + } + + return true; +} diff --git a/src/shared/util.h b/src/shared/util.h index ce57b53be9ef..c37b0f7296ab 100644 --- a/src/shared/util.h +++ b/src/shared/util.h @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -88,6 +89,8 @@ do { \ char *strdelimit(char *str, char *del, char c); int strsuffix(const char *str, const char *suffix); +char *strstrip(char *str); +bool strisutf8(const char *str, size_t length); void *util_malloc(size_t size); void *util_memdup(const void *src, size_t size); From patchwork Wed Jul 12 19:38:53 2023 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: 704156 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 351F6EB64DA for ; Wed, 12 Jul 2023 19:39:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232558AbjGLTjG (ORCPT ); Wed, 12 Jul 2023 15:39:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34756 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232541AbjGLTjF (ORCPT ); Wed, 12 Jul 2023 15:39:05 -0400 Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AA2C41FC3 for ; Wed, 12 Jul 2023 12:39:03 -0700 (PDT) Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-1b8ad907ba4so39154135ad.0 for ; Wed, 12 Jul 2023 12:39:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689190742; x=1691782742; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=uHqQlIjqOpoJZQVgo7C2eWiI3XEYDViMGpzIq4auRvQ=; b=pO7B7MwoV9Kz0sbvEPuaGuJEQT9Fvp8biM32KNomv52f7GBUG0iJyCVjQUBwHMKR7F S7n7fKpsQsQYTJtydEB2NWADWx+AmI4vurzM2I/ZkhWYZisp1s1AZZA8pUeczA2kqGEh 9aJnl3yr7uI0BzY2660YjXLb+4fDCCrHLR29aIwMM+cQ9bE1sz0OaaS2M3F30JJ5LQPc tpQDC/vtz03X+dUPgfKCE7G8AoWE/S86lEwEt80aribxDHw6KG7gt6Nsdabw/5M35MQm yIfus6TjoJvqjnJRp8vrQBQeB215YM2eWIyVkeXCg9k3IdNyB4XESNFmfVMasuM4T7eI uw/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689190742; x=1691782742; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=uHqQlIjqOpoJZQVgo7C2eWiI3XEYDViMGpzIq4auRvQ=; b=Hf/asolSF7q853FfdeFa3N+E5rdDWrTNe6fPYJivFCC93WOXzIj0yZHQIR8WdcVTwI H++7DOdmZIoK7fmrsRIWkvHLTa85Gin9eSZ/eZ92T5SDS9NQf7prmFkYC9lv02jwR6IJ 6+hUYr1Yhe4YRircLOmVE3nSAKDCue2BvV5HJ25Up5DQnOMochs+JqecWh3Pu6e/0p3X pVODCI6wiub8UqVdZiVyuIrCeI1aXNjHbzkd5dim7T3IsIxjuNxc4RmP3Jd+oafwxRUe ycWfsFMgh8HGTHfSH5iiun+xunsbHxx9VoNVpw8K34+cKaJIjUk1TCS5fAZs5564lQDf c7pQ== X-Gm-Message-State: ABy/qLZmkDVtXKbrahXEJNmME2qlfwk/QH4fhxMR1wsDFHayIKyTi5WM vb6ROsWLhkBT4VM2kGiJDX3uq1sgZBo= X-Google-Smtp-Source: APBJJlFQGDXjikvR62abLvmNyPwoxp8sHZREdKtSxN6zXl3g3PE5hs4WnBBFHN5stmzXACe8B/QDqg== X-Received: by 2002:a17:902:cec3:b0:1b7:e49f:1d with SMTP id d3-20020a170902cec300b001b7e49f001dmr18980887plg.62.1689190742167; Wed, 12 Jul 2023 12:39:02 -0700 (PDT) Received: from lvondent-mobl4.. (c-71-236-201-58.hsd1.or.comcast.net. [71.236.201.58]) by smtp.gmail.com with ESMTPSA id ij12-20020a170902ab4c00b001b84cd8814bsm4413264plb.65.2023.07.12.12.39.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jul 2023 12:39:00 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ 4/5] shared/ad: Make use of util_iov_pull_* to parse data Date: Wed, 12 Jul 2023 12:38:53 -0700 Message-Id: <20230712193854.1862996-4-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230712193854.1862996-1-luiz.dentz@gmail.com> References: <20230712193854.1862996-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 util_iov_pull_* helpers to parse data. --- src/shared/ad.c | 266 ++++++++++++++++++++++++++++++++++++++++++++---- src/shared/ad.h | 10 +- 2 files changed, 253 insertions(+), 23 deletions(-) diff --git a/src/shared/ad.c b/src/shared/ad.c index e8bebe70708e..951c56c604e6 100644 --- a/src/shared/ad.c +++ b/src/shared/ad.c @@ -14,6 +14,11 @@ #define _GNU_SOURCE +#include + +#include "lib/bluetooth.h" +#include "lib/hci.h" + #include "src/shared/ad.h" #include "src/eir.h" @@ -80,7 +85,11 @@ static bool ad_is_type_valid(uint8_t type) struct bt_ad *bt_ad_new_with_data(size_t len, const uint8_t *data) { struct bt_ad *ad; - uint16_t parsed_len = 0; + struct iovec iov = { + .iov_base = (void *)data, + .iov_len = len, + }; + uint8_t elen; if (data == NULL || !len) return NULL; @@ -89,31 +98,29 @@ struct bt_ad *bt_ad_new_with_data(size_t len, const uint8_t *data) if (!ad) return NULL; - while (parsed_len < len - 1) { - uint8_t d_len; - uint8_t d_type; - const uint8_t *d; - uint8_t field_len = data[0]; + bt_ad_set_max_len(ad, len); - if (field_len == 0) + while (util_iov_pull_u8(&iov, &elen)) { + uint8_t type; + void *data; + + if (elen == 0 || elen > iov.iov_len) break; - parsed_len += field_len + 1; - - if (parsed_len > len) - break; - - d = &data[2]; - d_type = data[1]; - d_len = field_len - 1; - - if (!ad_is_type_valid(d_type)) + if (!util_iov_pull_u8(&iov, &type)) goto failed; - if (!ad_replace_data(ad, d_type, d, d_len)) + elen--; + + if (!ad_is_type_valid(type)) goto failed; - data += field_len + 1; + data = util_iov_pull_mem(&iov, elen); + if (!data) + goto failed; + + if (!ad_replace_data(ad, type, data, elen)) + goto failed; } return ad; @@ -203,10 +210,181 @@ static bool data_type_match(const void *data, const void *user_data) return a->type == type; } +static bool ad_replace_uuid16(struct bt_ad *ad, struct iovec *iov) +{ + uint16_t value; + + while ((util_iov_pull_le16(iov, &value))) { + bt_uuid_t uuid; + + if (bt_uuid16_create(&uuid, value)) + return false; + + if (bt_ad_has_service_uuid(ad, &uuid)) + continue; + + if (!bt_ad_add_service_uuid(ad, &uuid)) + return false; + } + + return true; +} + +static bool ad_replace_uuid32(struct bt_ad *ad, struct iovec *iov) +{ + uint32_t value; + + while ((util_iov_pull_le32(iov, &value))) { + bt_uuid_t uuid; + + if (bt_uuid32_create(&uuid, value)) + return false; + + if (bt_ad_has_service_uuid(ad, &uuid)) + continue; + + if (!bt_ad_add_service_uuid(ad, &uuid)) + return false; + } + + return true; +} + +static bool ad_replace_uuid128(struct bt_ad *ad, struct iovec *iov) +{ + void *data; + + while ((data = util_iov_pull_mem(iov, 16))) { + uint128_t value; + bt_uuid_t uuid; + + bswap_128(data, &value); + + if (bt_uuid128_create(&uuid, value)) + return false; + + if (bt_ad_has_service_uuid(ad, &uuid)) + continue; + + if (!bt_ad_add_service_uuid(ad, &uuid)) + return false; + } + + return true; +} + +static bool ad_replace_name(struct bt_ad *ad, struct iovec *iov) +{ + char utf8_name[HCI_MAX_NAME_LENGTH + 2]; + int i; + + memset(utf8_name, 0, sizeof(utf8_name)); + strncpy(utf8_name, (const char *)iov->iov_base, iov->iov_len); + + if (strisutf8(utf8_name, iov->iov_len)) + goto done; + + /* Assume ASCII, and replace all non-ASCII with spaces */ + for (i = 0; utf8_name[i] != '\0'; i++) { + if (!isascii(utf8_name[i])) + utf8_name[i] = ' '; + } + + /* Remove leading and trailing whitespace characters */ + strstrip(utf8_name); + +done: + return bt_ad_add_name(ad, utf8_name); +} + +static bool ad_replace_uuid16_data(struct bt_ad *ad, struct iovec *iov) +{ + uint16_t value; + bt_uuid_t uuid; + + if (!util_iov_pull_le16(iov, &value)) + return false; + + if (bt_uuid16_create(&uuid, value)) + return false; + + return bt_ad_add_service_data(ad, &uuid, iov->iov_base, iov->iov_len); +} + +static bool ad_replace_uuid32_data(struct bt_ad *ad, struct iovec *iov) +{ + uint32_t value; + bt_uuid_t uuid; + + if (!util_iov_pull_le32(iov, &value)) + return false; + + if (bt_uuid32_create(&uuid, value)) + return false; + + return bt_ad_add_service_data(ad, &uuid, iov->iov_base, iov->iov_len); +} + +static bool ad_replace_uuid128_data(struct bt_ad *ad, struct iovec *iov) +{ + void *data; + uint128_t value; + bt_uuid_t uuid; + + data = util_iov_pull_mem(iov, 16); + if (!data) + return false; + + bswap_128(data, &value); + + if (bt_uuid128_create(&uuid, value)) + return false; + + return bt_ad_add_service_data(ad, &uuid, iov->iov_base, iov->iov_len); +} + +static bool ad_replace_manufacturer_data(struct bt_ad *ad, struct iovec *iov) +{ + uint16_t value; + + if (!util_iov_pull_le16(iov, &value)) + return false; + + return bt_ad_add_manufacturer_data(ad, value, iov->iov_base, + iov->iov_len); +} + static bool ad_replace_data(struct bt_ad *ad, uint8_t type, const void *data, size_t len) { struct bt_ad_data *new_data; + struct iovec iov = { + .iov_base = (void *)data, + .iov_len = len, + }; + + switch (type) { + case BT_AD_UUID16_SOME: + case BT_AD_UUID16_ALL: + return ad_replace_uuid16(ad, &iov); + case BT_AD_UUID32_SOME: + case BT_AD_UUID32_ALL: + return ad_replace_uuid32(ad, &iov); + case BT_AD_UUID128_SOME: + case BT_AD_UUID128_ALL: + return ad_replace_uuid128(ad, &iov); + case BT_AD_NAME_SHORT: + case BT_AD_NAME_COMPLETE: + return ad_replace_name(ad, &iov); + case BT_AD_SERVICE_DATA16: + return ad_replace_uuid16_data(ad, &iov); + case BT_AD_SERVICE_DATA32: + return ad_replace_uuid32_data(ad, &iov); + case BT_AD_SERVICE_DATA128: + return ad_replace_uuid128_data(ad, &iov); + case BT_AD_MANUFACTURER_DATA: + return ad_replace_manufacturer_data(ad, &iov); + } new_data = queue_find(ad->data, data_type_match, UINT_TO_PTR(type)); if (new_data) { @@ -220,13 +398,12 @@ static bool ad_replace_data(struct bt_ad *ad, uint8_t type, const void *data, new_data = new0(struct bt_ad_data, 1); new_data->type = type; - new_data->data = malloc(len); + new_data->data = util_memdup(data, len); if (!new_data->data) { free(new_data); return false; } - memcpy(new_data->data, data, len); new_data->len = len; if (queue_push_tail(ad->data, new_data)) @@ -590,7 +767,7 @@ static bool uuid_match(const void *data, const void *elem) const bt_uuid_t *match_uuid = data; const bt_uuid_t *uuid = elem; - return bt_uuid_cmp(match_uuid, uuid); + return !bt_uuid_cmp(match_uuid, uuid); } static bool queue_remove_uuid(struct queue *queue, bt_uuid_t *uuid) @@ -618,6 +795,14 @@ bool bt_ad_add_service_uuid(struct bt_ad *ad, const bt_uuid_t *uuid) return queue_add_uuid(ad->service_uuids, uuid); } +bool bt_ad_has_service_uuid(struct bt_ad *ad, const bt_uuid_t *uuid) +{ + if (!ad) + return false; + + return queue_find(ad->service_uuids, uuid_match, uuid); +} + bool bt_ad_remove_service_uuid(struct bt_ad *ad, bt_uuid_t *uuid) { if (!ad) @@ -894,6 +1079,14 @@ bool bt_ad_add_name(struct bt_ad *ad, const char *name) return true; } +const char *bt_ad_get_name(struct bt_ad *ad) +{ + if (!ad) + return false; + + return ad->name; +} + void bt_ad_clear_name(struct bt_ad *ad) { if (!ad) @@ -933,6 +1126,20 @@ bool bt_ad_add_flags(struct bt_ad *ad, uint8_t *flags, size_t len) return ad_replace_data(ad, BT_AD_FLAGS, flags, len); } +uint8_t bt_ad_get_flags(struct bt_ad *ad) +{ + struct bt_ad_data *data; + + if (!ad) + return 0; + + data = queue_find(ad->data, data_type_match, UINT_TO_PTR(BT_AD_FLAGS)); + if (!data || data->len != 1) + return 0; + + return data->data[0]; +} + bool bt_ad_has_flags(struct bt_ad *ad) { struct bt_ad_data *data; @@ -1077,6 +1284,21 @@ void bt_ad_clear_data(struct bt_ad *ad) queue_remove_all(ad->data, NULL, NULL, data_destroy); } +int8_t bt_ad_get_tx_power(struct bt_ad *ad) +{ + struct bt_ad_data *data; + + if (!ad) + return 0; + + data = queue_find(ad->data, data_type_match, + UINT_TO_PTR(BT_AD_TX_POWER)); + if (!data || data->len != 1) + return 127; + + return data->data[0]; +} + struct bt_ad_pattern *bt_ad_pattern_new(uint8_t type, size_t offset, size_t len, const uint8_t *data) { diff --git a/src/shared/ad.h b/src/shared/ad.h index 93ba1b6cfa0b..87b3401a389d 100644 --- a/src/shared/ad.h +++ b/src/shared/ad.h @@ -112,11 +112,13 @@ bool bt_ad_is_empty(struct bt_ad *ad); bool bt_ad_add_service_uuid(struct bt_ad *ad, const bt_uuid_t *uuid); +bool bt_ad_has_service_uuid(struct bt_ad *ad, const bt_uuid_t *uuid); + bool bt_ad_remove_service_uuid(struct bt_ad *ad, bt_uuid_t *uuid); void bt_ad_clear_service_uuid(struct bt_ad *ad); -bool bt_ad_add_manufacturer_data(struct bt_ad *ad, uint16_t manufacturer_data, +bool bt_ad_add_manufacturer_data(struct bt_ad *ad, uint16_t id, void *data, size_t len); bool bt_ad_has_manufacturer_data(struct bt_ad *ad, @@ -150,6 +152,8 @@ void bt_ad_clear_service_data(struct bt_ad *ad); bool bt_ad_add_name(struct bt_ad *ad, const char *name); +const char *bt_ad_get_name(struct bt_ad *ad); + void bt_ad_clear_name(struct bt_ad *ad); bool bt_ad_add_appearance(struct bt_ad *ad, uint16_t appearance); @@ -160,6 +164,8 @@ bool bt_ad_add_flags(struct bt_ad *ad, uint8_t *flags, size_t len); bool bt_ad_has_flags(struct bt_ad *ad); +uint8_t bt_ad_get_flags(struct bt_ad *ad); + void bt_ad_clear_flags(struct bt_ad *ad); bool bt_ad_add_data(struct bt_ad *ad, uint8_t type, void *data, size_t len); @@ -172,6 +178,8 @@ bool bt_ad_remove_data(struct bt_ad *ad, uint8_t type); void bt_ad_clear_data(struct bt_ad *ad); +int8_t bt_ad_get_tx_power(struct bt_ad *ad); + struct bt_ad_pattern *bt_ad_pattern_new(uint8_t type, size_t offset, size_t len, const uint8_t *data); From patchwork Wed Jul 12 19:38:54 2023 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: 701931 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 40968C0015E for ; Wed, 12 Jul 2023 19:39:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232587AbjGLTjH (ORCPT ); Wed, 12 Jul 2023 15:39:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34764 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232541AbjGLTjG (ORCPT ); Wed, 12 Jul 2023 15:39:06 -0400 Received: from mail-pg1-x536.google.com (mail-pg1-x536.google.com [IPv6:2607:f8b0:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5FD1A1FCC for ; Wed, 12 Jul 2023 12:39:05 -0700 (PDT) Received: by mail-pg1-x536.google.com with SMTP id 41be03b00d2f7-53482b44007so12971a12.2 for ; Wed, 12 Jul 2023 12:39:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689190744; x=1691782744; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=6153T5ieEnaG37eYeGkcbX1K38aAKSTQ2AYPcqQcsRE=; b=aadf56kdHNMP9H3lgiWOx9ZEkE5cbj0eshPjkBbj8GlnwvM4fZSRyFhtnv4TMrE12k 8Li6lzfeSMsyNM2LzFKRFiDSgUwcj7g3QANOVVDhPb5aBeBsKQEyJ9mEWmTajB7fukC4 NfFab8NPoFACnsUDEaIyMu625RlOjqw3lljHGC95MhSP2XkXtsm1UMlQ21plKrVElI5T U9GWNVCDMK+U+tJHQfZniYi0EOsL4bqmZrrS4C+lqbALYE7hM7Vnz5GEQbOHjfDDIRQt 7zu5osmXaFnzBIdAPJivvKfHuqmZvOUvd9b04G7xfnfScOT+cp1O7kmGPTxwqzwXe1Fc 9aBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689190744; x=1691782744; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6153T5ieEnaG37eYeGkcbX1K38aAKSTQ2AYPcqQcsRE=; b=ZskOVQWXFOkT6B5xJqKQxHduK9L4pLmPX5UASjAXIKMJDl/D2h1RiKaPO/DSApYtkx SHUbmLA13CD3cu/zyP64vVxBQYkg1L7CwJngdY72EAu7lZZAzTJZDSi6lQLkWnFXOO/S HZv8XdrPx9/D35sHE5P/CEN25UDWKkJ4HO4af3EDBoZaX2pCBg4Q7BItnuWlszDRrBZ+ rcGrkdYevygkUFucNpzpjy6T7nx+Qe2MMv5iwpXfgY3vJ+3ROBmo2qOghIxVvi7BAWS5 F/0jGNcYkUbrOHaxYMzRgdF+apZv9zsYHUhu0lgAmwEMTmFoSY2aLtkhBdahuwaKmXbI KuLQ== X-Gm-Message-State: ABy/qLYdEh3p7zwWXsg+sMJsFaTR3KL5F64hnogWSgx2HhOwdXaBkhs1 WKyWmUpJbRALH4fm5tRhHynS7/BF870= X-Google-Smtp-Source: APBJJlEIpfejWxX3X2hVqKjekzLOx/oeCHXYOILGZTcLk6BGrHuc9l2ki1vn5a2deuhcoZytN+WzRQ== X-Received: by 2002:a17:902:e74b:b0:1b8:9b5e:a218 with SMTP id p11-20020a170902e74b00b001b89b5ea218mr19590307plf.42.1689190743988; Wed, 12 Jul 2023 12:39:03 -0700 (PDT) Received: from lvondent-mobl4.. (c-71-236-201-58.hsd1.or.comcast.net. [71.236.201.58]) by smtp.gmail.com with ESMTPSA id ij12-20020a170902ab4c00b001b84cd8814bsm4413264plb.65.2023.07.12.12.39.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jul 2023 12:39:02 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ 5/5] test-eir: Run tests using bt_ad Date: Wed, 12 Jul 2023 12:38:54 -0700 Message-Id: <20230712193854.1862996-5-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230712193854.1862996-1-luiz.dentz@gmail.com> References: <20230712193854.1862996-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 enables the same tests done with eir_data using bt_ad. --- unit/test-eir.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/unit/test-eir.c b/unit/test-eir.c index e05a37d01306..49ce65f24bc9 100644 --- a/unit/test-eir.c +++ b/unit/test-eir.c @@ -21,6 +21,7 @@ #include "lib/sdp.h" #include "src/shared/tester.h" #include "src/shared/util.h" +#include "src/shared/ad.h" #include "src/eir.h" struct test_data { @@ -539,6 +540,54 @@ static void print_debug(const char *str, void *user_data) tester_debug("%s%s", prefix, str); } +static void test_ad(const struct test_data *test, struct eir_data *eir) +{ + struct bt_ad *ad; + GSList *list; + + ad = bt_ad_new_with_data(test->eir_size, test->eir_data); + g_assert(ad); + + g_assert_cmpint(bt_ad_get_flags(ad), ==, test->flags); + g_assert_cmpstr(bt_ad_get_name(ad), ==, test->name); + g_assert_cmpint(bt_ad_get_tx_power(ad), ==, test->tx_power); + + if (test->uuid) { + int i; + + for (i = 0; test->uuid[i]; i++) { + bt_uuid_t uuid; + + bt_string_to_uuid(&uuid, test->uuid[i]); + g_assert(bt_ad_has_service_uuid(ad, &uuid)); + } + } + + for (list = eir->msd_list; list; list = list->next) { + struct eir_msd *msd = list->data; + struct bt_ad_manufacturer_data adm; + + adm.manufacturer_id = msd->company; + adm.data = msd->data; + adm.len = msd->data_len; + + g_assert(bt_ad_has_manufacturer_data(ad, &adm)); + } + + for (list = eir->sd_list; list; list = list->next) { + struct eir_sd *sd = list->data; + struct bt_ad_service_data ads; + + bt_string_to_uuid(&ads.uuid, sd->uuid); + ads.data = sd->data; + ads.len = sd->data_len; + + g_assert(bt_ad_has_service_data(ad, &ads)); + } + + bt_ad_unref(ad); +} + static void test_parsing(gconstpointer data) { const struct test_data *test = data; @@ -599,6 +648,8 @@ static void test_parsing(gconstpointer data) "Service Data:"); } + test_ad(data, &eir); + eir_data_free(&eir); tester_test_passed();