Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp14283985pxu; Mon, 4 Jan 2021 19:15:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJx+C0za+k4TLHfLtbN8UU4orr6LFzAMGZ8UDoGV06mlo/ObXGlrigKPsROKU7xiKeNwQDlT X-Received: by 2002:a50:9f4a:: with SMTP id b68mr73022355edf.296.1609816557563; Mon, 04 Jan 2021 19:15:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609816557; cv=none; d=google.com; s=arc-20160816; b=FOlXsPgxr7nURcYpYsSIqdf+o3Gv+UjGJps/H6fMUpPa7qVgOq445CLHs98IGZSflA HVVhPxSSbTPFP5b2Sez1nwElZY1kz1qkUbpBuOuWO0AWpqYPyMc6jcmOyb/BlyYon3TN iuMeXb8wJiHLXaBcfeIr8VoS7DJyeMtBOf79ntd+YRoLtZC07nu6PZkf6npsUyZiPjTd wzBXZtPyChkzHj5WgvOHsf7U25U04g5V4CsbjnPTDjGP0vSE8dNjSnBFbKszapDfeJlI nHYe+aNi+zXKvzG3lcZ2dg5kWSTAD+Q3VvJPs3xrzUSVaGRpceyjgRuObKdAXuTrHNTD aRFA== 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=KK6nLKsHQCELPyl1S4Arx6g2G/0sGXXhy1Tvx8l1irY=; b=E6/M4cE9zKj7w9+N07YUJXhkpajVtOwFLRoLL8bYNjeDu9fhUhGWOpPu0Mwg7hy1aA vK0IZ04Q0gKWgfXi+GMed3nSBJnVgeSj23sXeGMnklO0UiUDpRIR/cIYq+yUeP5PugpL eoyXPCuznorTrkZMg0hkwvBV3Fc4KrAVs9omvke5cY1BBO2TWdPfq3xfOeUr7uEXj1fJ 3BEgkky7olsP9LSBfpTgUD1FBIWN6vVWvlMbzNVxj/VzacnJ622nap42vkDfkI4N7aax MYvKBdZi2E7mSvEC5rZZIxYhzSlQrtY3ddO7VpNtoz/wDfFUKzSU9ZuIoIAZ+DlhMc9+ yopA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=EChvkFSH; 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 u13si33686724edp.96.2021.01.04.19.15.26; Mon, 04 Jan 2021 19:15:57 -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=EChvkFSH; 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 S1728052AbhAEDNs (ORCPT + 99 others); Mon, 4 Jan 2021 22:13:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727716AbhAEDNs (ORCPT ); Mon, 4 Jan 2021 22:13:48 -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 D2237C061795 for ; Mon, 4 Jan 2021 19:13:07 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id e74so54552235ybh.19 for ; Mon, 04 Jan 2021 19:13:07 -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=KK6nLKsHQCELPyl1S4Arx6g2G/0sGXXhy1Tvx8l1irY=; b=EChvkFSH+/hC+LmKY5AT1KfK/ubaXNHvTiNyATxvqZn9i3i0Dh68FkTCeWxMt8yOqq bwupUDv2ffRc/rXg71wfzSZ73UybK6xnBDYzvAl7nlY2Pt2Oz97ZJhRvng1VVwOGzl3B jFIo8sLeLP77aEm+vclJtv253n0L5D4Bv4Zd9qEZmuoHUtdmle/Jvj7bsmJYtcVfc5I4 /7fPlrmQtDCpd9tY4L+FGtUjcdGhSBC99334dNCedbFGybRrIuo+DQNegPDuEJuBWT7F ebwTfESJ/woD9EZc45tBhecEgKaJ1v/puD4JnVh9F13HR2zS0++82O5oLwuxCFh446DI Jv9w== 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=KK6nLKsHQCELPyl1S4Arx6g2G/0sGXXhy1Tvx8l1irY=; b=E3+BpDZaRPjpVElFIBfhC2FMG+UsfUjGJgIwWGUqt5QBnuvRWguWPAhY/WBdV/9KOK nN56XpNL8GaIVd9m2qWGxm9A/6Ek5H8towVrEfgBB0DQxHYikQVVOUfwsyv/YsdXpkNf 7Cev7IHi5UzQM1PtDjesN1faVFMt8doriX9pKYIfQ3UTMsORsC4Yagz/yVcC+t1fLdjh lMTc0JY3vxK3MYxm3xHNnKl4CKqNGuz87JttCn8qqLwkgEpM3G+9XYEUmeYcs+r9KCiQ sKxuss8glVpCkq1U7IuOlHqKi5xllnJ4jv9MOkQFaPfBPCU2vScF7vHerU3qDz8VRMEV wASQ== X-Gm-Message-State: AOAM530nvIJBuJlwwYeXwsxVczQ1E2SDiZUWDrHxxaLH0IbkfvkARYtt 2Y9XmLs5R+P4yFz3pIgDbNXt9T+FYChvterPvhoWRprpvqMZb4DMPXKSIbnt7eOX9H7sqIlNaq6 YERbepf4nQWj2KN1c7tqYyCPy2tv3EVD9UxfgwYPsQUk9gjcUjZ9Ah29msO9a8hpCNf7EpeHgnK 0p59gRQf0cOsw= 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:7789:: with SMTP id s131mr111959638ybc.212.1609816386998; Mon, 04 Jan 2021 19:13:06 -0800 (PST) Date: Tue, 5 Jan 2021 11:12:54 +0800 Message-Id: <20210105111219.Bluez.v4.1.Ie32770d0eed2e7739ce9d17d920766fb6aee8583@changeid> Mime-Version: 1.0 X-Mailer: git-send-email 2.29.2.729.g45daf8777d-goog Subject: [Bluez PATCH v4 1/4] shared/mgmt: Add supports of parsing mgmt tlv list From: Howard Chung To: linux-bluetooth , luiz.dentz@gmail.com Cc: mcchou@chromium.org, apusaka@chromium.org, mmandlik@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 --- Changes in v4: - Simply use free instead of mgmt_tlv_free Changes in v3: - Fix CheckBuild error Changes in v2: - Fix incompatible pointer type error in mgmt_tlv_list_load_from_buf 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..dc8107846668 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 = (struct mgmt_tlv *)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