Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp8941236pxu; Mon, 28 Dec 2020 02:07:46 -0800 (PST) X-Google-Smtp-Source: ABdhPJx6cQk6hHyH8y/IvWK6fIm+sxR2CtinZAI0tGlxkIKvnwQlMDNVwtgU79mJoHCCEOwjUYf+ X-Received: by 2002:aa7:d919:: with SMTP id a25mr40472734edr.81.1609150066446; Mon, 28 Dec 2020 02:07:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609150066; cv=none; d=google.com; s=arc-20160816; b=x8rRgiEjaNbIpXcUWJlNLNHhIo+RdnffGw2H1kfBO4uAJGECXQaN2Yfi1Dmq+Lssrr 7rTs4jrC5DEYnCnr7RxU0/LhvWMHQ/mF8x27WKO9PmndK6b2jqzlBMs57MXdU/efyDxC WHeKtgLIDI0cAltfZxWNISrrl3iXgFkN3ewm1tjUXfdDgS5uuR/uIRsGwaJZFHocJOqg 5bbJrvEVnnQHfBMPHI5qj6ExSXBek0UzObfBRDGYxucfPYaULE9NZ0nKcsXzGiC2oyu6 W+Fh97NKnXJhmnLRlzGorMeic6rKvHr2zZFc29l0brZOpbECp8UisATcz/b9KA6G88v9 JXwQ== 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=5IY1P928LNisrCvz2O0RipAgV64DbONq524mIao+F9M=; b=LOHMhUJvvxcZ6EwbSSSz2rlOYWgPr3v0mHk70Wtkfqb0SKrZBo6FdND4OqsZpP6KoD pntTL7qi6wgfzLa2S+Jsp2EotvXOumS35uxq8htY1Zwk8IY1cpBHcQ4ypPPp3zkFd0t9 j7wyCccbOApQ8mq1nelrii0yP9UH2abjiJBS+NbX5o8A4K32+WNWrUv4FvVCepS3vMG/ 069N7UZ2OYumWTbfIjuyz8XpSpxH3W0cwEf3zQNXCHjBNu0WmVS+72dQd08Rc+gRsfFq imVbsNg+5+rgymTuzHHT/u3z0TnuyNq4XJtnHpnzMwZXHr5UDluS6rRd82RbbaiTFz7f 8yzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=N9G9W+f9; 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 a5si17503553ejj.142.2020.12.28.02.07.04; Mon, 28 Dec 2020 02:07:46 -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=N9G9W+f9; 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 S1727078AbgL1KFs (ORCPT + 99 others); Mon, 28 Dec 2020 05:05:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49048 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727034AbgL1KFr (ORCPT ); Mon, 28 Dec 2020 05:05:47 -0500 Received: from mail-qt1-x84a.google.com (mail-qt1-x84a.google.com [IPv6:2607:f8b0:4864:20::84a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 78100C061794 for ; Mon, 28 Dec 2020 02:05:07 -0800 (PST) Received: by mail-qt1-x84a.google.com with SMTP id v9so5096349qtw.12 for ; Mon, 28 Dec 2020 02:05: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=5IY1P928LNisrCvz2O0RipAgV64DbONq524mIao+F9M=; b=N9G9W+f9J8bK97YqALbb8POIwecntpsDCOiEnWFnrrC9gerAtUNxzwbHz3u3KUN3oW bbkM33uE07ZYHxC1LFLMcQGqQOKI1jqgWCk19J3zXE4Y05PioOaUrjuQTR3TXdsqzYG2 QV4YqUFSTYMt4rVzyJzGVzdHM4+18ds18jEdQEr6zbY8gl/CHZv3iOzwmG6e2aIjjIza UBnG8JpuIL54P9/SJfGZUyHO7nvVN14Va/+JSICoO52rt56qxnWrL2PlCZuyvNZqj9de lv/TkX2a45Rc6xyDnHLIqHEH2r1Zwak9niCSp1bNbNcjBRdILXuG/yVu2zfWm08TKA9q rTBw== 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=5IY1P928LNisrCvz2O0RipAgV64DbONq524mIao+F9M=; b=qxGp64eQakMH67DQ6uF2rvYjOZOx+Y3F31pBuNIPlV7OMycW4DH/noOKKzgW1Xj3rN VCcGpCcSzgpyLSduqcqcf/xeI54vxrfe6n5MZ6527RqM12RdwI2h3sM6DSlw4t2qeqCc z3RX0+OEDuw3cQREJVnqUjrBEhPvE0MWuRqSL7HyhpxiOrs6+HPwsr6Vf+zUNqcQlzLY dsgA9KwLPn9QNyq0OL9DA72kXue2a3jwmsthx94XecMkCtv6C9z7yqBlrwoiZrNer2Am 3s4ntDTevjROPBtHCgA6XxTm4ODhk4FcckqqE0miM1G5CQ8/+iDnrz9KPud4ybJRN3s1 DXWw== X-Gm-Message-State: AOAM533iLkCmyqjdmbEvTMb13vcAyE44TDR9h80VV20oLQEftRKYOBPs MKixjH9seMna/+avBjXzkE2DVGsX3TuR9Cs5BG5RTxBw8RNiVrtbgrnej+zn7sXZa1QEmw1FsjB ipNIjqvFzWHoAjCIQsWUWMzhoCyWnf0eB3TNnuIogzOYL39Tcro1Kuo4hRF/z7fUbFs/KwswUKI 6P1K+FFD6zN3E= 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:ad4:4ee7:: with SMTP id dv7mr46258220qvb.43.1609149906509; Mon, 28 Dec 2020 02:05:06 -0800 (PST) Date: Mon, 28 Dec 2020 18:04:55 +0800 Message-Id: <20201228180429.Bluez.v2.1.Ie32770d0eed2e7739ce9d17d920766fb6aee8583@changeid> Mime-Version: 1.0 X-Mailer: git-send-email 2.29.2.729.g45daf8777d-goog Subject: [Bluez PATCH v2 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, mmandlik@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 --- 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