Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp8845886pxu; Sun, 27 Dec 2020 22:50:19 -0800 (PST) X-Google-Smtp-Source: ABdhPJzXOQZlAU98hBvI3EEoNw4MYV1T7wiycUEiqGfa5LLcAw4F4CYG3k1BOEkokHNQyF8wmEWs X-Received: by 2002:a17:906:c83b:: with SMTP id dd27mr41252505ejb.356.1609138219743; Sun, 27 Dec 2020 22:50:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609138219; cv=none; d=google.com; s=arc-20160816; b=yA0Ey89EPTKjv4/3SmXqiNo6W0lgJZKkq5pd604ebHZvQym7ra6MRYvmR+i7b+14gd k7UYvynKzGnLcPCOcXXm7Py9iYKpuVSJa9+j2F4j3SJvtMIi9MIJ9zjIuXvGP79PoMPb fKoNXDMiK6Fa690DlQhmIxmcttRGIohyn+fQZhgLxVeLcRcNe9RaZTpGG6aiilgoZoMN aVsfImbVraS4FR0pWxnNMNXF5nj6GllDhCFozrVcihVQPExHemk65U3K7nHlIft7LLKa 2+5V+GNS8ZYf5bhLPQJ30jlRMDC6xFyWQgmS0tOLLX/2fOrGVSHNxEAh1/L/YdRarHuS xqrQ== 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:references:mime-version :message-id:in-reply-to:date:sender:dkim-signature; bh=Ag1yJexuyuOZgLeTCzJRi8FXYTblNlW6uzMyNzlTnww=; b=pMb7l/czXhSHWD8RaX9kGRoPdm4phRx0+Qy9PSrSytJwc3WwibIS/QnQEeldqLu5D5 DHdk8DBd+fPULQTqPGyRj2LiIbVLzfij5tYW9tYIIeY/3w2YZjkGP0c8Tpyx7UbyIN/d f64P0B7QXyQq0W6Iic/bMkyRUiuuPgZnIfgAaR2Z/Mj6xF5HDRIayV4GjC4ZRJ9q80mD 80kIiHIP6FxHIcG4+WccXPOd1m25sYozC7jwiDJFiI+amYSdTbznQFJHvi6FPtx7ZAPt x7PsQYOQVeelAA0Ovra8pE2SLo3762s5oNdOZ2fALOuRz7dD3zJnohjvqRgweT6/NsCi u3wQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=h8X6USyV; 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 hj15si18810991ejb.734.2020.12.27.22.49.57; Sun, 27 Dec 2020 22:50:19 -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=h8X6USyV; 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 S1726354AbgL1GrQ (ORCPT + 99 others); Mon, 28 Dec 2020 01:47:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46790 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726292AbgL1GrQ (ORCPT ); Mon, 28 Dec 2020 01:47:16 -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 D773BC061796 for ; Sun, 27 Dec 2020 22:46:35 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id o9so16741492yba.4 for ; Sun, 27 Dec 2020 22:46:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=Ag1yJexuyuOZgLeTCzJRi8FXYTblNlW6uzMyNzlTnww=; b=h8X6USyV/YZhm4fjNxWFThAs8jOCMDVBObpbnHxJf2KrnKDKt1reJPfsUq2p45UtWz pdmL/MPtEfKS2Gj+yl8oMPm1ODxqjmjg9/ns9jMaTGRJUQ6oO0p85KQQIEd10PQOhrT8 5F2fNsqdszO+SNqvaIblWl5DaWP7Q6qPhe7bjeH0JNA7j8qElc0iCx8SrZ41NTT8khRn yHWh9UCOabamz0LdNstOhEJDT2Ukco1HqKfKPVFYtwJT3NQSA06RPDO6gfJU+e3lfyJJ +NfHYWNMKSHT1JkhqtcySTrn1ldXauJYRuqrurlBqWvn+pV7Q0YVUpGGUnOdHCgKmOtD Y+DA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=Ag1yJexuyuOZgLeTCzJRi8FXYTblNlW6uzMyNzlTnww=; b=Et+FMqOu/dkJz14ZDpTOKum+PDtQ1m5csAg19pFSfkwKV6oJLDP5yzlPTpJboHcsbW MEYj47PHVn5IjI2jwSvxJoHEfB1t7uYb7A/nKbwzkrwSinZIGc+Zc2Bfrgq0ifVnlPR0 FxvCg2Kj5SLqVSJ7P8Mn1F4FY6ztT3fjrJikKLy/9EJ6EI4pbmTVyJf6LGDJ05lS41hj m7qDL9SLqhBzTMHoJgQo3PT468LyTUYWciQGNmGZw5rfC3V7wlOOyKVM8BM+bxYOdrgc OBAXVmDfOWhXF7fvZwOBlc6dadB9ojTIIjT6GuzYKiSyrKa1Qv4p/hCv72ZcUeFJ9dTt yYTA== X-Gm-Message-State: AOAM530LRNNUjKh/+MgrlODvOEOd09OG78pFMKpVvRzAWlHdrrmzK6TM szhCp+MlnsIvdQhjm+ciaUl4MciKN5MXyidBTeeEjFcV2KB55iIVGjX6C7AChLK2KaBWf3zf0WI Emg5I/FsJQQsyW+h7M8XbvWFtwds/f39EoAG+t0xMmFDbtOwtNFFhvNQ0Iq8Q10g2glDl0k9BZd TSs4xXXjSPxTE= 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:9906:: with SMTP id z6mr34353327ybn.238.1609137995074; Sun, 27 Dec 2020 22:46:35 -0800 (PST) Date: Mon, 28 Dec 2020 14:46:12 +0800 In-Reply-To: <20201228144543.Bluez.v1.1.Ie32770d0eed2e7739ce9d17d920766fb6aee8583@changeid> Message-Id: <20201228144543.Bluez.v1.3.Idca009971ca95228a3fa7232ef648f18ff64d185@changeid> Mime-Version: 1.0 References: <20201228144543.Bluez.v1.1.Ie32770d0eed2e7739ce9d17d920766fb6aee8583@changeid> X-Mailer: git-send-email 2.29.2.729.g45daf8777d-goog Subject: [Bluez PATCH v1 3/4] btmgmt: Add command set-sysconfig 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 Add command set-sysconfig in btmgmt Example usage: [mgmt]# set-sysconfig -h Parameters: -v ... e.g.: set-sysconfig -v 001a:2:1234 001f:1:00 [mgmt]# set-sysconfig -v 8:2:abcd 1:02:0100 0016:2:0600 Reviewed-by: apusaka@chromium.org --- tools/btmgmt.c | 109 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) diff --git a/tools/btmgmt.c b/tools/btmgmt.c index c766de862a12..4cc94efe3f1a 100644 --- a/tools/btmgmt.c +++ b/tools/btmgmt.c @@ -1799,6 +1799,113 @@ static void cmd_read_sysconfig(int argc, char **argv) } } +static bool parse_mgmt_tlv(const char *input, uint16_t *type, uint8_t *length, + uint8_t *value) +{ + int i, value_starting_pos; + + if (sscanf(input, "%4hx:%1hhu:%n", type, length, + &value_starting_pos) < 2) { + return false; + } + + input += value_starting_pos; + + if (*length * 2 != strlen(input)) + return false; + + for (i = 0; i < *length; i++) { + if (!sscanf(input + i * 2, "%2hhx", &value[i])) + return false; + } + + return true; +} + +static void set_sysconfig_rsp(uint8_t status, uint16_t len, const void *param, + void *user_data) +{ + if (status != MGMT_STATUS_SUCCESS) { + error("Could not set default system configuration with status " + "0x%02x (%s)", status, mgmt_errstr(status)); + return bt_shell_noninteractive_quit(EXIT_FAILURE); + } + + print("Set default system configuration success"); + + return bt_shell_noninteractive_quit(EXIT_SUCCESS); +} + +static bool set_sysconfig(int argc, char **argv) +{ + struct mgmt_tlv_list *tlv_list = NULL; + int i; + uint16_t index, type; + uint8_t length; + uint8_t value[256] = {}; + bool success = false; + + index = mgmt_index; + if (index == MGMT_INDEX_NONE) + index = 0; + + tlv_list = mgmt_tlv_list_new(); + if (!tlv_list) { + error("tlv_list failed to init"); + goto failed; + } + + for (i = 0; i < argc; i++) { + if (!parse_mgmt_tlv(argv[i], &type, &length, value)) { + error("failed to parse"); + goto failed; + } + + if (!mgmt_tlv_add(tlv_list, type, length, value)) { + error("failed to add"); + goto failed; + } + } + + if (!mgmt_send_tlv(mgmt, MGMT_OP_SET_DEF_SYSTEM_CONFIG, index, + tlv_list, set_sysconfig_rsp, NULL, NULL)) { + error("Failed to send \"Set Default System Configuration\"" + " command"); + goto failed; + } + + success = true; + +failed: + if (tlv_list) + mgmt_tlv_list_free(tlv_list); + + return success; +} + +static void set_sysconfig_usage(void) +{ + bt_shell_usage(); + print("Parameters:\n\t-v ...\n" + "e.g.:\n\tset-sysconfig -v 001a:2:1234 001f:1:00"); +} + +static void cmd_set_sysconfig(int argc, char **argv) +{ + bool success = false; + + if (strcasecmp(argv[1], "-v") == 0 && argc > 2) { + argc -= 2; + argv += 2; + success = set_sysconfig(argc, argv); + } + + if (!success) { + set_sysconfig_usage(); + bt_shell_noninteractive_quit(EXIT_FAILURE); + } +} + static void auto_power_enable_rsp(uint8_t status, uint16_t len, const void *param, void *user_data) { @@ -5079,6 +5186,8 @@ static const struct bt_shell_menu main_menu = { cmd_exp_debug, "Set debug feature" }, { "read-sysconfig", NULL, cmd_read_sysconfig, "Read System Configuration" }, + { "set-sysconfig", "<-v|-h> [options...]", + cmd_set_sysconfig, "Set System Configuration" }, {} }, }; -- 2.29.2.729.g45daf8777d-goog