From patchwork Thu Nov 14 19:25:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 843262 Received: from mail-ua1-f46.google.com (mail-ua1-f46.google.com [209.85.222.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9406E18D65F for ; Thu, 14 Nov 2024 19:25:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731612332; cv=none; b=mUHASWB1TYFZ91aptq5eoCvHJ0eMsMU8ghdXFkZsdti4I+PrwdC64SP5+GJIqw1Zm+DBMcjej6IqEQNosH2amxvzcY7dDkd/JW+KLGu1J2M+1r/+bQERddX5JC4+9TgUwOcZjkxfVjWgDl0/A6ft4h+EptN1xCdI0eo2VaU2qfM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731612332; c=relaxed/simple; bh=mDWDSEQYFNXk8B4+HefqLXLfJVLN4mHgFS2QBTTh/Xs=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=OKE3g2I5o52ILvEoTmRAMv+zPoKDzTjLHg/cvqPsyZUWYcW+2WNznl89d4mpCXziTn+Wr8XVPEMP914okDycXmHkh3Rym5TnD3gxbSLq5SojBqTJ5DO38weGlfcVoi4mfO2l6tOmBCVdr5pU4sUGubpVwDs/+YUoAAxC7vhH4pU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=euvQS9oe; arc=none smtp.client-ip=209.85.222.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="euvQS9oe" Received: by mail-ua1-f46.google.com with SMTP id a1e0cc1a2514c-856dd0bc407so48815241.1 for ; Thu, 14 Nov 2024 11:25:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731612328; x=1732217128; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=ErWN4/9tMrbTdpjrtmmp5ydR9xMupaBtG8ikCNl5fXg=; b=euvQS9oeyLtOXz0rbaeERZEtLdSXdxoJdpKqwvkYng01y/RO5nOcyaim9otMbzt+sX tp/quSNjorOPOOjMJXYdNk8SXd9Tt7kJH4W8wtIEnaEllIwbNRBmKIIZJwVi7kZDhb24 Jc0ZPQQZoXdxmj6ewZXAwe0G2Mmyvks/3RDRfwQL00bgQFAQ0hW2VE6TzzMgWSosq9yH JQOPFmuNQkbOkmbLaD3ZGP0yaTAe8qPEQfEDdvph1Lbin/Lxjpce8cbWOjqER47L1oJQ aIcQPSVxn5/WQ2AqNpauEkqME7bHeN1jcJ/ydEClVNvl/QGMSGaBKrw3zOu+P9kbMBSR 3lLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731612328; x=1732217128; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ErWN4/9tMrbTdpjrtmmp5ydR9xMupaBtG8ikCNl5fXg=; b=m6heaXraSEbb7TLzqxAgFK+iGAu+aetTw4JRCxowcSqIv3HJdy8dADGL6zsygawXLz RwYznkz9moxEa4UQwRUEGACdn8eQqmIhgIVLGiYGROmanVMWctgePQAAxJaVktY298RL Y3QNGgyMLzAV1CYpeaXxyXbt4W2JnqCYp7nxs6s/7Uzhv2cnDSMvgUTwpVZ0jFjzyCRC D/U0Woaec7fIC5WoDlg+iRz0qn0Fsx8tQ0hK8qfoMo1atbbiFL3fBGQSww/KtcI90efr rdRuZWWDAez8/vjR9OgdGgVwz7/geFEvWLKJGej4dGaXlldkCQhmBaXPYUMzxt3KnR1T RI5g== X-Gm-Message-State: AOJu0YyOurXGy3YFbDl26aqGKsqr5QZBdzsZKNvkG40v27/Icu72OODH 3FtDsrGrSn5UXAxXQw49RhMmY95RHGvrKBN5BbpVDyeFkefs+nK6jybhrg== X-Google-Smtp-Source: AGHT+IF0mXaz3gVWt0D+jtCSX+0o61Pj09vKMt+T1B/pu8/21vdB0z0FahQlVjCHZVtD5yHapw6H5w== X-Received: by 2002:a05:6102:26c7:b0:4ad:5b7c:7646 with SMTP id ada2fe7eead31-4ad631caa88mr161483137.26.1731612328334; Thu, 14 Nov 2024 11:25:28 -0800 (PST) Received: from lvondent-mobl5.. (syn-107-146-107-067.res.spectrum.com. [107.146.107.67]) by smtp.gmail.com with ESMTPSA id a1e0cc1a2514c-856ce622853sm213911241.18.2024.11.14.11.25.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2024 11:25:26 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ v2 1/5] mgmt-api: Add Send HCI command and wait for event Command Date: Thu, 14 Nov 2024 14:25:20 -0500 Message-ID: <20241114192524.1856334-1-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.47.0 Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Luiz Augusto von Dentz This adds Send HCI command and wait for event Command initial documentation. --- doc/mgmt-api.txt | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/doc/mgmt-api.txt b/doc/mgmt-api.txt index 01a23526a4ef..b4a5776574f7 100644 --- a/doc/mgmt-api.txt +++ b/doc/mgmt-api.txt @@ -3992,6 +3992,36 @@ Cancel Transmit Mesh Packet Command Possible errors: Failed Invalid Parameters +Send HCI command and wait for event Command +=========================================== + + Command Code: 0x005B + Controller Index: + Command Parameters: Opcode (2 Octets) + Event (1 Octet) + Timeout (1 Octet) + Parameter Length (2 Octets) + Parameter (variable) + Return Parameters: Response (1-variable Octets) + + This command may be used to send a HCI command and wait for an + (optional) event. + + The HCI command is specified by the Opcode, any arbitrary is supported + including vendor commands, but contrary to the like of + Raw/User channel it is run as an HCI command send by the kernel + since it uses its command synchronization thus it is possible to wait + for a specific event as a response. + + Setting event to 0x00 will cause the command to wait for either + HCI Command Status or HCI Command Complete. + + Timeout is specified in seconds, setting it to 0 will cause the + default timeout to be used. + + Possible errors: Failed + Invalid Parameters + Command Complete Event ====================== From patchwork Thu Nov 14 19:25:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 843261 Received: from mail-vk1-f171.google.com (mail-vk1-f171.google.com [209.85.221.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 04B0519E98E for ; Thu, 14 Nov 2024 19:25:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731612337; cv=none; b=OfC/I5tirHt99Lr5xFSggIyWu8GXVqVU2Q9gRHFSQBLpg7MzZDa0R4zSK62cpy7AvSgdo5f2Ex25JjFZePAdpMbuYD2sqRlmpuUt5mMjZT1MNLQDHoP+IKsjRaD5LCaii61urFYmAPrzld/IVrRURYqjP6TlbYAvUb1A7P21oCI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731612337; c=relaxed/simple; bh=PlRXfXGZRXfh/Dg41TphBXFaL6OfVmKKDy1TKlAztjE=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=S8113nHxd1iQuzxgoH9csMPqFSCbkYr7m+UV+j2iAdS20sH2CkTx2bKP59WlFuxEttcB7gwKr3MF54h1epPIai9E46p7JrBJc6ADEzzU8Ir2KkqhNe/LFmWa+TZ8atx/Vt3pUeXMnSionmAwWxvWoCDfBaR7oNu83Txuvgu4Jws= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=JywapLOb; arc=none smtp.client-ip=209.85.221.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="JywapLOb" Received: by mail-vk1-f171.google.com with SMTP id 71dfb90a1353d-50d399891d6so437490e0c.1 for ; Thu, 14 Nov 2024 11:25:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731612334; x=1732217134; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=RThP8lQ4Dz9fNP6z+7ZeWVvRA9F70KZWYAD89OJlzn0=; b=JywapLObtg+e0fxcZLlSAIrP5zSLRgPocONZ20o8Ha8jmR+2zsZkjYjU9MVGT2oXBk wrdjfqNNOiTvzNRyolH8FvCebtLHkmCFQUCtPuDXUvS7QSj9iyP8acKtPNk7dl5ueyun Iw4k7Dc/XnNgmGXvorMv3n3hS2cdMgBWQgFw2X+uq9WiDdmwfh7RcbBe9d/7Cv2hOFQn SsXgUo+lV5SpiraaXTCsRqd3UY5X/WUrl3wPptq/P1noNj/7a3BLHRxkrJyFf1frNjAZ atOVz8B3JU9vVG7jxcXb9uAJCY8QFGDZ2zKq8yDXIYgHcu2oaATHJvIb/vo2Y4rpai1e SkVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731612334; x=1732217134; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RThP8lQ4Dz9fNP6z+7ZeWVvRA9F70KZWYAD89OJlzn0=; b=F94URJ///8+vY88fkqQNX2l861radmm5mDaFTKqmtSGHvCsiXM5GNiNApbjBGTZvET D4vGmf8DYzPUXL1Pvk9WXPIx8b4yDQcYkPf9xXu8lPy8yDs5+gCtYsyBRNz7HwgZ2S/S xrmuFl9OgHR10slAnsBT4XJNZMADgjFKtJZ1xxDAv+92Q4yBjO74ZxezMH7Od8ovwwTk n5YahoBosgiUM4WSoimtJDFoRD7vSaBWp4Pkcrq5Y39Q4Rfw68mCcL8lmyasXvdADYpR YS+dQl1OqhEaJ8hbRvHKHN6KVAGKc5DbmySeode5rqDTK74lk5rV38Js5F47CmGujg81 kVYA== X-Gm-Message-State: AOJu0YyZP9yTwbuuHyttadpclnN3Cpm5PsXxuCFAW44eMd/uEp0IZpYQ i5jZm1JI54FzyYIm/lM9/Yr7Udi017yWWAuFNLKFW8s6aX7ywi/qjb1I+Q== X-Google-Smtp-Source: AGHT+IG8T3lrwIPXtFONaQLcA7kV07qY4TXX7gYfpI0HT/61lAHhqInl2dz0VxWjJJwzktuMYsBI0A== X-Received: by 2002:a05:6122:1d13:b0:50d:160e:de73 with SMTP id 71dfb90a1353d-51477f0ce98mr327510e0c.6.1731612334290; Thu, 14 Nov 2024 11:25:34 -0800 (PST) Received: from lvondent-mobl5.. (syn-107-146-107-067.res.spectrum.com. [107.146.107.67]) by smtp.gmail.com with ESMTPSA id a1e0cc1a2514c-856ce622853sm213911241.18.2024.11.14.11.25.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2024 11:25:32 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ v2 3/5] monitor: Add decoding of MGMT_OP_HCI_CMD_SYNC Date: Thu, 14 Nov 2024 14:25:22 -0500 Message-ID: <20241114192524.1856334-3-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241114192524.1856334-1-luiz.dentz@gmail.com> References: <20241114192524.1856334-1-luiz.dentz@gmail.com> Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Luiz Augusto von Dentz @ MGMT Com..nd (0x005b) plen 6 {0x0002} Opcode: 0xffff Event: 0x00 Timeout: 0 seconds Parameters Length: 0 Parameters[0]: @ MGMT Event: Command Status (0x0002) plen 3 {0x0002} Send HCI command and wait for event (0x005b) Status: Failed (0x03) --- monitor/packet.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/monitor/packet.c b/monitor/packet.c index 6d869ffeadb8..f1a42925a8fc 100644 --- a/monitor/packet.c +++ b/monitor/packet.c @@ -14712,6 +14712,55 @@ static void mgmt_mesh_send_cancel_cmd(const void *data, uint16_t size) print_field("Handle: %d", handle); } +static void mgmt_hci_cmd_sync_cmd(const void *data, uint16_t size) +{ + struct iovec iov = { (void *)data, size }; + uint16_t opcode, len; + uint8_t event; + uint8_t timeout; + + if (!util_iov_pull_le16(&iov, &opcode)) { + print_text(COLOR_ERROR, " invalid opcode"); + return; + } + + print_field("Opcode: 0x%4.4x", opcode); + + if (!util_iov_pull_u8(&iov, &event)) { + print_text(COLOR_ERROR, " invalid event"); + return; + } + + print_field("Event: 0x%2.2x", event); + + if (!util_iov_pull_u8(&iov, &timeout)) { + print_text(COLOR_ERROR, " invalid timeout"); + return; + } + + print_field("Timeout: %d seconds", timeout); + + if (!util_iov_pull_le16(&iov, &len)) { + print_text(COLOR_ERROR, " invalid parameters length"); + return; + } + + print_field("Parameters Length: %d", len); + + if (iov.iov_len != len) { + print_text(COLOR_ERROR, " length mismatch (%zu != %d)", + iov.iov_len, len); + return; + } + + print_hex_field("Parameters", iov.iov_base, iov.iov_len); +} + +static void mgmt_hci_cmd_sync_rsp(const void *data, uint16_t size) +{ + print_hex_field("Response", data, size); +} + struct mgmt_data { uint16_t opcode; const char *str; @@ -14985,6 +15034,9 @@ static const struct mgmt_data mgmt_command_table[] = { { 0x005A, "Mesh Send Cancel", mgmt_mesh_send_cancel_cmd, 1, true, mgmt_null_rsp, 0, true}, + { 0x005B, "Send HCI command and wait for event", + mgmt_hci_cmd_sync_cmd, 6, false, + mgmt_hci_cmd_sync_rsp, 0, false}, { } }; From patchwork Thu Nov 14 19:25:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 843260 Received: from mail-ua1-f42.google.com (mail-ua1-f42.google.com [209.85.222.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 30CE01991CB for ; Thu, 14 Nov 2024 19:25:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731612343; cv=none; b=aWIUVO5k7f/l3JYlxq0ktFytd886qdr0UeASU/iIFUbtHyXjoCCjYxt309Jz9VjVxEQtDdB1Oe6497wH3AK4R/5d/KnunzM4/0c8xzXpNgx9xVE+Gv5pDdi5a992sTbmKPgNAUEHT9ILv5k3ONWHN3xW9zjTKjK7o44lnmIMfXc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731612343; c=relaxed/simple; bh=rRjSjYzmSlQoRZv6OFJRwoa2rYMglZ4crQnGyMkT7eY=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=H0A/fTOS093JpiMKSfvyvbddWEK5E8F5WHsgkZytcvqOMGIpWF8532nXOltoDBVseiRtGDePb6OAUyNNzNismKCodbCOGJ0SO8TFq+z4rAaEg4Iz05uieni8RgcqqPEm6QBT6i8L1CvRAubwoF0e4GBTXgleU6dIfzUITfWHJmI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=g4hxr/Sv; arc=none smtp.client-ip=209.85.222.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="g4hxr/Sv" Received: by mail-ua1-f42.google.com with SMTP id a1e0cc1a2514c-856dd6862bfso51291241.1 for ; Thu, 14 Nov 2024 11:25:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731612340; x=1732217140; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=OirxWHKjdKpWRDBbeAPd2l1jC+J3Pjl0j2pDjl1Tywg=; b=g4hxr/SvhgC4u+6M94CD55ZsYaUQ3a8LOGp6oHTMjy0lX/TQd+AHHvoEODi7mOJMeM +uPponPjKNWH3PqAy6Hnx4hjN7lXgf6N1IZMcZYIc7MfGUU7bGEcutAVhyD6P1LO5Bka mfN5E8wfuUH7IhL3KsxHBdbJWqcs84WdeDIf6whFzlHaRLEvaQLBvswnZda9/qP98bTQ /2wLxgFj/CPWA7goK+ZTBYvPmmqWRMxS06U/wfSNe/4HC7CeZJc2FL56/WBPEhIsKBp/ 37q8yX7uUdeccvIB1Ld0QUtDKFstYDnsGbAWXXQ6U+NT9f7G7O3YI796AsjlOH3cMpjy 3/tg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731612340; x=1732217140; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OirxWHKjdKpWRDBbeAPd2l1jC+J3Pjl0j2pDjl1Tywg=; b=oVynQ0opu2C5U/sf9m7773tltHvxZS2GkUfJPOJjOgTaZzdGe5Cwb3SrzHNx3rgZL5 9csfGOMaF23XEws95kxpBEDiwx8DOeB+q4QgggVd7x0CHDeVql47fDpc8Zwiih78Qzwq BkUUnO48douQHYa70reBOlMhQg1EveZxevTw896srizE/B2HhQh45VIDZuNGYAvF1CrP 3iMiRWQzRfSSx4OG8k0nxS4okL+jVdKUVZ9kwJEG2MXbzEG2VLl55upgddCtib3lHRoc KRoJIpXfMr+L9Z/I9U4t65K7xHhtcA2wflx8x/bbwXGiOgmY7qk2F62Cn7qIDtCkyERQ IcuA== X-Gm-Message-State: AOJu0Yy3OXK5r85uZGQf5OHrM20XHxMsaMju/OocUUYMKR9D7TGCxD/G AseZR7DjRC50oAQcrdZ1N5h7kTbGY+RBvJx9BSZ8OYKbnX7+jwDUgqQraw== X-Google-Smtp-Source: AGHT+IHWTSt4ASa1Ina5jE/Qalob/o0zWUtsDa59FdW+Rbm0WZCutBJQja+A1Wi8W7CmvREFNTETXg== X-Received: by 2002:a05:6102:b04:b0:4a3:d215:427f with SMTP id ada2fe7eead31-4ad62d4b61cmr219751137.23.1731612340437; Thu, 14 Nov 2024 11:25:40 -0800 (PST) Received: from lvondent-mobl5.. (syn-107-146-107-067.res.spectrum.com. [107.146.107.67]) by smtp.gmail.com with ESMTPSA id a1e0cc1a2514c-856ce622853sm213911241.18.2024.11.14.11.25.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2024 11:25:38 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ v2 5/5] client/mgmt: Add hci-cmd command Date: Thu, 14 Nov 2024 14:25:24 -0500 Message-ID: <20241114192524.1856334-5-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241114192524.1856334-1-luiz.dentz@gmail.com> References: <20241114192524.1856334-1-luiz.dentz@gmail.com> Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Luiz Augusto von Dentz This adds hci-cmd command which uses the MGMT_OP_HCI_CMD_SYNC: bluetoothctl> mgmt.hci-send 0xffff bluetoothctl[44]: @ MGMT Com..nd (0x005b) plen 6 {0x0002} Opcode: 0xffff Event: 0x00 Timeout: 0 seconds Parameters Length: 0 Parameters[0]: < HCI Command: Vendor (0x3f|0x03ff) plen 0 > HCI Event: Command Status (0x0f) plen 4 Vendor (0x3f|0x03ff) ncmd 1 Status: Unknown HCI Command (0x01) @ MGMT Event: Command Status (0x0002) plen 3 {0x0002} Send HCI command and wait for event (0x005b) Status: Failed (0x03) --- client/mgmt.c | 111 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) diff --git a/client/mgmt.c b/client/mgmt.c index 602b92228ab8..59dcb3135344 100644 --- a/client/mgmt.c +++ b/client/mgmt.c @@ -2338,6 +2338,115 @@ static void cmd_set_flags(int argc, char **argv) } +static uint8_t *str2bytearray(char *arg, uint8_t *val, long *val_len) +{ + char *entry; + unsigned int i; + + for (i = 0; (entry = strsep(&arg, " \t")) != NULL; i++) { + long v; + char *endptr = NULL; + + if (*entry == '\0') + continue; + + if (i >= *val_len) { + bt_shell_printf("Too much data\n"); + return NULL; + } + + v = strtol(entry, &endptr, 0); + if (!endptr || *endptr != '\0' || v > UINT8_MAX) { + bt_shell_printf("Invalid value at index %d\n", i); + return NULL; + } + + val[i] = v; + } + + *val_len = i; + + return val; +} + +static void hci_cmd_rsp(uint8_t status, uint16_t len, const void *param, + void *user_data) +{ + if (status != 0) { + error("HCI command failed with status 0x%02x (%s)", + status, mgmt_errstr(status)); + bt_shell_noninteractive_quit(EXIT_FAILURE); + } + + if (len > 0) { + bt_shell_printf("Response: "); + bt_shell_hexdump(param, len); + } + + bt_shell_noninteractive_quit(EXIT_SUCCESS); +} + +static void cmd_hci_cmd(int argc, char **argv) +{ + struct { + struct mgmt_cp_hci_cmd_sync cp; + uint8_t data[UINT8_MAX]; + } pkt; + char *endptr = NULL; + long value; + uint16_t index; + + value = strtoul(argv[1], &endptr, 0); + if (!endptr || *endptr != '\0' || value > UINT16_MAX) { + bt_shell_printf("Invalid opcode: %s", argv[1]); + return bt_shell_noninteractive_quit(EXIT_FAILURE); + } + + memset(&pkt, 0, sizeof(pkt)); + pkt.cp.opcode = cpu_to_le16(value); + + if (argc > 2) { + endptr = NULL; + value = strtoul(argv[2], &endptr, 0); + if (!endptr || *endptr != '\0' || value > UINT8_MAX) { + bt_shell_printf("Invalid event: %s", argv[2]); + return bt_shell_noninteractive_quit(EXIT_FAILURE); + } + + pkt.cp.event = value; + } + + if (argc > 3) { + endptr = NULL; + value = strtoul(argv[3], &endptr, 0); + if (!endptr || *endptr != '\0' || value > UINT8_MAX) { + bt_shell_printf("Invalid timeout: %s", argv[2]); + return bt_shell_noninteractive_quit(EXIT_FAILURE); + } + + pkt.cp.timeout = value; + } + + if (argc > 4) { + value = sizeof(pkt.data); + if (!str2bytearray(argv[4], pkt.data, &value)) + return bt_shell_noninteractive_quit(EXIT_FAILURE); + + pkt.cp.params_len = value; + } + + index = mgmt_index; + if (index == MGMT_INDEX_NONE) + index = 0; + + if (mgmt_send(mgmt, MGMT_OP_HCI_CMD_SYNC, index, + sizeof(pkt.cp) + pkt.cp.params_len, &pkt, + hci_cmd_rsp, NULL, NULL) == 0) { + error("Unable to send HCI command"); + return bt_shell_noninteractive_quit(EXIT_FAILURE); + } +} + /* Wrapper to get the index and opcode to the response callback */ struct command_data { uint16_t id; @@ -6016,6 +6125,8 @@ static const struct bt_shell_menu mgmt_menu = { cmd_get_flags, "Get device flags" }, { "set-flags", "[-f flags] [-t type]
", cmd_set_flags, "Set device flags" }, + { "hci-cmd", " [event] [timeout] [param...]", + cmd_hci_cmd, "Send HCI Command and wait for Event" }, {} }, };