Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp8986134pxu; Mon, 28 Dec 2020 03:37:14 -0800 (PST) X-Google-Smtp-Source: ABdhPJxm4M77RwSUTx11uDcFvpMYo1g8Swt0XFnIEN9RkogQp/H1JnpgMWGfck6fRKSVMXNwb0sW X-Received: by 2002:a17:906:518a:: with SMTP id y10mr42114311ejk.323.1609155433773; Mon, 28 Dec 2020 03:37:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609155433; cv=none; d=google.com; s=arc-20160816; b=qf5AJDCjJm4oCsYudGRF9D0BVdezzkJ8nYpsdAEePW+nDvS+dJ65kF+N+fcHuc/myK xSvVdgELdiQbzyDYd3Sygq6whBx2pCHRycGqumlhV681m4jmMFmQK7eAOWnl28t5TcS+ hveNZY60a4TA2oJERAdhTMzq3UuNMRA4Ny+PsLRDAcqaid8Swa2nY4y//w1vVeBpwDAe 4q1QvbNq6B9pG/xaLID1yLCtnz+IdxZMJJjzejI0oR8AEQgJNMvDkn22kdy0El7lcN94 CXUNkBRPepqN4bhTpW+drjHAjo/TgrrqPfoeBcw9fwHuFuWtXq32Vk2DjADeVBC0qF3B 0UEw== 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=9+Ok8zSmlezPRnyzRhNvndhpVlA8+TsAwmdpm3q9p2A=; b=S6oSiU45nfgfF3TFP6yBbhMaeyvqNdrq+1zFvFD1BuEGPBw+Icisz5yWsUZHusuuMV 6V2iGY9cmAL7PdeSD9sHO6S0gVS2k4Qi8cy16cvVM+h7JMjUdevud17jv2rlivOGihFX Dtt9QJz19DIivDfTWj6LdPb/CmAFfyjJW7Bs7eLJ0V0af4RaZ47HsqdZT5L+C+avZGXx Gn9ikRmcGVrC0BmGvVLvEYd8g+FiATz5NZ93rSd3d6DCqCovkNgmfen1qcOjCteIMFsx h835f9y7oBtwCgXHJBL4Umz53W3aOiQiOEULfCWX2XS42wGlzpTNyEHBoaNqhxgnkPUF nVuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Q66faswx; 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 q8si18298018ejj.24.2020.12.28.03.36.42; Mon, 28 Dec 2020 03:37:13 -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=Q66faswx; 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 S1727330AbgL1LfH (ORCPT + 99 others); Mon, 28 Dec 2020 06:35:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34504 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727326AbgL1LfG (ORCPT ); Mon, 28 Dec 2020 06:35:06 -0500 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 63DE3C061794 for ; Mon, 28 Dec 2020 03:34:26 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id o8so2661216ybq.22 for ; Mon, 28 Dec 2020 03:34:26 -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=9+Ok8zSmlezPRnyzRhNvndhpVlA8+TsAwmdpm3q9p2A=; b=Q66faswxutm9FPnqP/QeVfjxOEsP5VUXAL/eWgXNnftbDuhssGiTe5KMn+tFVn6LpE frk++JLTPNE1yPs3N+l6QIfz6e+2zYtZN0isrXxZuHpt0GZ90r5NvIq2eaOQx0CKzpsB z6YqGLAThfMAcUl0uRK91wskRcwKGeIWSM0Y15vq129MBGGXHN0XQOaYOOhiXtetXJH+ FrfyTq9vDkJQ2OGYTuxvjbzf9IvRbjZh3Qg7sLxgbXIR75E0Qwoj5HQdtULQYIHbQjq9 oCEUBaKDwPn28yXyKZeEq+vjDk/0Sndf6k2pvjLdjR+CeS5BwwqDuIgmVvRKI+DIoH+6 mZ2A== 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=9+Ok8zSmlezPRnyzRhNvndhpVlA8+TsAwmdpm3q9p2A=; b=i41TXSXjVHHHPMRy6D0BF5pQ/qnLubFUhyC6cuRUCC4UcigFG4wSCJH3aQqbWcgKZX NUKm+3HEmrOVvcn0NbX6iKpQsYYrOPqGmauPK16gwTwkR2PEygLMC0PnXmL3hQg1ATKO XdwdibCUvCwmf0B0Mt+OS8t4NG1KQwE4oH2FtvnJTef14M5MUqJtWjDNC7cRVCEz6PA4 E1cSpqPn1Vw9gUm9w+CYWukLO/gsB7uEJ7WOCf75QpptXI/SOtft31Y17LOUqcjdUB6a RxOLehS9vFW0YfdXF6QgqK9Ba4dpktAXLb4z5tH+ny+GgXXrUSGCQJ9ddTSpsFNbsgp4 80wQ== X-Gm-Message-State: AOAM532D5C7ZIaWPG68tzkCAX3pII7J2DAQwF2oLiGQx5DXvsEoDeRKW DBYWygOGkdTulTxOwSxw8Cy6oPpHruLNpHpfRyi4PPV2IRuCybKMAc/nYWTSoMWX75BmcNAYh8D r1ecIi/h2LISB7q92EDRpMmarns0E/FEif88gyQp6Bl6AIaRGi0erInFGqH6XYlnuiVGN9pSvUd 9Y7EhNQ2wUnPc= 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:42cc:: with SMTP id p195mr63071571yba.59.1609155265399; Mon, 28 Dec 2020 03:34:25 -0800 (PST) Date: Mon, 28 Dec 2020 19:34:17 +0800 Message-Id: <20201228193351.Bluez.v3.1.Ie32770d0eed2e7739ce9d17d920766fb6aee8583@changeid> Mime-Version: 1.0 X-Mailer: git-send-email 2.29.2.729.g45daf8777d-goog Subject: [Bluez PATCH v3 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 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