Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp8845480pxu; Sun, 27 Dec 2020 22:49:18 -0800 (PST) X-Google-Smtp-Source: ABdhPJwzXETZ2y/KdLIEQxu+FerAveKznIokNaDnDwgMHtSdl9DfO/76cY2HORPVHz8HSCRBZQ0w X-Received: by 2002:a17:906:77ce:: with SMTP id m14mr42169181ejn.10.1609138158493; Sun, 27 Dec 2020 22:49:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609138158; cv=none; d=google.com; s=arc-20160816; b=lkx6O8xE/ygPPOgv0ussiQb3AcJWRDn+SObbSsExecvGgMHyaAa1QLTYsvd1fCGFHV wPpq8oOCeXfEEuoNgMveU4ruuEt40KMC1E5EiMLGAJ69bPrDrsCensKQXlHlt22yoWDY yVxND5zfj0BkEnOTO1BT8Ms+uWZ/ueGLS6w9fdM5JI4XcyI4YvPlA07XlpNR63HmQbL4 feMgWeQ/DTEB5lb9C5VHPoWdv2l3IlXASNLuI5FTUmMPyHhx1IHFY8idGUsnB5Q4N9cc YSYlUqKuk+jyoeKTuJS4WhtqUFynbwcu0MriE3pp0ABnLdO05n6G6LYtTOo/aBKLqoU+ 0gog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:mime-version:message-id:date :sender:dkim-signature; bh=RYhpAf+NP/aVS5zt+P6Vcn8Y/nE+I/qnyuAeKN2+35Y=; b=soNWGiGjc/1fa6QDoeUAMusUR1GFBw8qF9MUiega3ZNT7YEvQ5p1x9Vj0mXTudyXUp 8q/WVBYAhMqETmyAtr1W4wNiT/BNlOMP4nibQHZjyAe6W0Qr1b352JbT2wMuXrhOqxxP WsVdk77gou35UerXhidpE5JnqsfIFoP9QyvSvWuVjaW6k9SDkj7TOOWUj40gxRmJVK2s Jh4LYkdfV41XzWliJYeAmwWGWxQ6Hth2QkJ24VRZdgtRkeSRdTg8DyYbwXQlI/GR8oKD CA+yE9SQ8X76UJuaxByZxGtwA7VUDIoXn2go4IbJBne/n5/IbyBCZcHbwNxMQPd/akVk EhJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=vZRsC6Qk; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b16si1748459ejc.710.2020.12.27.22.48.56; Sun, 27 Dec 2020 22:49:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=vZRsC6Qk; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726268AbgL1GrF (ORCPT + 99 others); Mon, 28 Dec 2020 01:47:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46756 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726200AbgL1GrF (ORCPT ); Mon, 28 Dec 2020 01:47:05 -0500 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BA10FC061794 for ; Sun, 27 Dec 2020 22:46:24 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id g67so16776550ybb.9 for ; Sun, 27 Dec 2020 22:46:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:message-id:mime-version:subject:from:to:cc; bh=RYhpAf+NP/aVS5zt+P6Vcn8Y/nE+I/qnyuAeKN2+35Y=; b=vZRsC6QkLbNN+AO9CHe/roMDBhL0vWFY2XlLhAkFVkjIH67AU/e85XfzNq+j+GTJeN m6XCtXbKuK+i7gl5DIULFg56eTLszZD4r1xO+ISaKYG7YrVdHpAcwWYOWXS5pY67c/f5 AZhccmls5fMiN0K/x96apZpxTLC959q3M7mQcG36+mWZSJh9k8UMeI6fI9tO2eSQ5YQY 5Ox/6MTar6CoM+e5g2/SJNnPyNo2+a27+vKxtbrXWGXInN5SCJon8U+IZp7JuHwqg4Gw fApoI3QJKETvdLw8siMVeTDeuZrWESI972BtsRAh20QYmp/3uNTNtrFMDPCVMqTgxGeX MhoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:message-id:mime-version:subject:from :to:cc; bh=RYhpAf+NP/aVS5zt+P6Vcn8Y/nE+I/qnyuAeKN2+35Y=; b=UJu8/GhNLkL7wD/FLBdGJscE8eEq/tbOC9qrkBVV6Y0DP4J5p0pO4GoxykMjo/8N6Z x3WutkXHjNU7ctdWMpuiwsWGtmKbzDUEEh2TrU0h1Z6cTFBbZy/WdDXctXKHF5EThxIx aBDv0a/mN0+28qMrS7YIrdar12tCERXMeexY70icnkybeDsEDS91NhiW7vGp2Gai9bTW PZJNhFkJfpuKmcSHUJGYBdcUAr2hoV0EkfO66fSM20CSVPMD0PPDpOjip3OroCbk8Nx9 /xKrhpCrogznmVN7bIQYmprtcqZYYbz1neKsI+9/dRFtOjxQER4Z/6FnjrppqgWVqt77 Pa7A== X-Gm-Message-State: AOAM530Dr5G0HXNm5himIeckYubJ/s94kLKTNs3LXAUcCfLgGd11fQKX ACix1+RqJeTZiZw6A7lCjUG3uLW8RHLyKgcQGClFeKP7/aCDOreWBBl+fGv/z8lcwgrbut0Hv9p hPbs2u0nZ/IBgtgw9Hc8G9a1Z/CG3do3iNA52fEjphRK2Br8YwxF5QHhByMFZw6TnGRXsBIWdx0 3+uwZtn8wGDs4= Sender: "howardchung via sendgmr" X-Received: from howardchung-p920.tpe.corp.google.com ([2401:fa00:1:10:f693:9fff:fef4:4e45]) (user=howardchung job=sendgmr) by 2002:a25:3741:: with SMTP id e62mr62070623yba.298.1609137983834; Sun, 27 Dec 2020 22:46:23 -0800 (PST) Date: Mon, 28 Dec 2020 14:46:10 +0800 Message-Id: <20201228144543.Bluez.v1.1.Ie32770d0eed2e7739ce9d17d920766fb6aee8583@changeid> Mime-Version: 1.0 X-Mailer: git-send-email 2.29.2.729.g45daf8777d-goog Subject: [Bluez PATCH v1 1/4] shared/mgmt: Add supports of parsing mgmt tlv list From: Howard Chung To: linux-bluetooth , luiz.dentz@gmail.com Cc: mmandlik@chromium.org, mcchou@chromium.org, apusaka@chromium.org, Howard Chung Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Response from Read System Default Configuration is a list of mgmt_tlv, which requires further processing to get the values of each parameters. This adds APIs for parsing response into mgmt_tlv_list, retrieving parameter from mgmt_tlv_list. Reviewed-by: apusaka@chromium.org --- src/shared/mgmt.c | 38 ++++++++++++++++++++++++++++++++++++++ src/shared/mgmt.h | 6 ++++++ 2 files changed, 44 insertions(+) diff --git a/src/shared/mgmt.c b/src/shared/mgmt.c index 9ea9974f5535..bdc4bdd9e66b 100644 --- a/src/shared/mgmt.c +++ b/src/shared/mgmt.c @@ -626,6 +626,44 @@ static void mgmt_tlv_to_buf(void *data, void *user_data) *buf_ptr += entry_size; } +struct mgmt_tlv_list *mgmt_tlv_list_load_from_buf(const uint8_t *buf, + uint16_t len) +{ + struct mgmt_tlv_list *tlv_list; + const uint8_t *cur = buf; + + if (!len || !buf) + return NULL; + + tlv_list = mgmt_tlv_list_new(); + + while (cur < buf + len) { + struct mgmt_tlv *entry = cur; + + cur += sizeof(*entry) + entry->length; + if (cur > buf + len) + goto failed; + + if (!mgmt_tlv_add(tlv_list, entry->type, entry->length, + entry->value)) { + goto failed; + } + } + + return tlv_list; +failed: + mgmt_tlv_list_free(tlv_list); + + return NULL; +} + +void mgmt_tlv_list_foreach(struct mgmt_tlv_list *tlv_list, + mgmt_tlv_list_foreach_func_t callback, + void *user_data) +{ + queue_foreach(tlv_list->tlv_queue, callback, user_data); +} + unsigned int mgmt_send_tlv(struct mgmt *mgmt, uint16_t opcode, uint16_t index, struct mgmt_tlv_list *tlv_list, mgmt_request_func_t callback, diff --git a/src/shared/mgmt.h b/src/shared/mgmt.h index 319beb62f9eb..808bf4c7ff09 100644 --- a/src/shared/mgmt.h +++ b/src/shared/mgmt.h @@ -41,6 +41,12 @@ bool mgmt_tlv_add(struct mgmt_tlv_list *tlv_list, uint16_t type, uint8_t length, #define mgmt_tlv_add_fixed(_list, _type, _value) \ mgmt_tlv_add(_list, _type, sizeof(*(_value)), _value) +struct mgmt_tlv_list *mgmt_tlv_list_load_from_buf(const uint8_t *buf, + uint16_t len); +typedef void (*mgmt_tlv_list_foreach_func_t)(void *data, void *user_data); +void mgmt_tlv_list_foreach(struct mgmt_tlv_list *tlv_list, + mgmt_tlv_list_foreach_func_t callback, + void *user_data); unsigned int mgmt_send_tlv(struct mgmt *mgmt, uint16_t opcode, uint16_t index, struct mgmt_tlv_list *tlv_list, mgmt_request_func_t callback, -- 2.29.2.729.g45daf8777d-goog