From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.41 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796336065; b=F+JAxECdvttyttYvFavH/+82KvmVNuDF3m5Hjy0QjOgAX0hsbAHsXXuVqWQVvgHBd1wy +7lN5QK6fzAUNn8rhj4kSo7/nYdNv04q7/8Hw1EGzOQQpWXXkE9wbMuMaONInUPHIkpwn nl0o4utgncMHSBiTxe8W/vMKi36Pa9N9rQCLUftqGyiPhOi45dTNmIT3PIf6whZ0CKfFY LkPrMDiwHw6TGJNxIrDsf8oXE8xxKJOWydxegKO4V5usFhRUcS73eNCEXllE7aVRpIPsu 1nOOl4G18gDbvlOrqhq8CRvfr7xA7xnKImHJmUZ9RJuLS6qqytC3xEFPwn0cNz2/OwQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796336065; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject: Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=gVDS33dPJzgpDV6ldpVAz3/+Qfx6bhC+GfzzxzL7WPg=; b=tl08zkydfSjaggiVE2V74615oVcn8FJhDMVzxaJxpLixsl43j0S1zsEwcxEQW+kYuWKg LdeHW1KUmfFAKoZ/bv0YnQt+ILYJrsOTs0ZInTcahgTzOVk0YFPsKNBnTflKBfHFkYWTB TwdyfIowHxgmqdyENnBg3kI2tflcMHT/KRPe3bDBDwfmL7XNixgD8Atxf+ONt4/BMwqeP 5OCIgUy0lLl8Z57HDnLprgmCheMDd3TIDHw7/uoP51bAbrjcCw+7Y/IteV/9Ob4fsQ+fU TPrXPPwACrO1jVgK8Ea8JIqDKdm69WGsI+LpwJe97OeD30GvawM3mjVJxR6KBoDkhRQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=nDFmZPY3; arc=none smtp.remote-ip=209.85.128.41 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8A282606A338 for ; Thu, 3 Dec 2026 22:14:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 8A282606A338 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.a=rsa-sha256 header.s=20260707 header.b=nDFmZPY3 Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-4a56e05568aso732395e9.1 for ; Thu, 03 Dec 2026 14:14:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796336064; x=1796940864; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=gVDS33dPJzgpDV6ldpVAz3/+Qfx6bhC+GfzzxzL7WPg=; b=nDFmZPY3DL+YmM/pQexmDOPPmo79pzt9/TWzjyeGI7cKCZrxoVMUk5SDs1Ng2MVS/h p1/QRFRuF/34xduiGafKmxja+eOe1ptBq2nEUiC/cPotpN+Mj7b8tr9DvMEY92As+nva 2NoinpqliC9PlftekA7xhvJj77qUHwSH0e7pvZ1hej/OYRV4ctNdL0V2G6IlWARFf30x UCYCg1C3OsJ4VoGp5hciGeT0USwoQKbijfNwqjhPvueAYNHoynmp48ZhHbHS5emSjtTJ pEN0QIosJBsRVOQXzXsUJpDQ/qwa2Kxs0ytEWHnamLhW2uCvrJbEVZqWo0xMGMqeYY7Q bQog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796336064; x=1796940864; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=gVDS33dPJzgpDV6ldpVAz3/+Qfx6bhC+GfzzxzL7WPg=; b=0jn/HVyfbM6DNTbTQmHKc/B9F3zAG75rHWpx9aCaE03fe0yLl4OuonCkTZrgQrnG0i KlIKcCvzeOUwP0ZttsEgonIiAjUDQTXr7TYWCvV9nCg9Sl0mH8w7MaVWrll6ZvAbM7OE OQYswF4cvcHchRVHz0bjHhurgk6oefxEBPOkF416bOjInERm7ZRREwJSxPveoMyZOzs1 hhlPGobak4b/OfOEvHBO7RLhx10Uj7XVy44caGO3l1a0iG6AIA6+WXZXqhdZmd6Wunhu lD0DDdgqaBbqdrCE+DrDJ/CWIPgP6GEyS7UCuCVW+wy0UUCcORB407grXNcW4uxT+xQR sTag== X-Gm-Message-State: APuU4Z8/MEIOsG451RnCPjfomaGxvK0cN/W1qq4XF9ni6BVDiqSAQN8v mIal5n/u2U4bWt+/crnFoPgZ9xwKFBBbS7fMsnHFpUe0FDsr/UVLf4MS7pw72Uv+ X-Gm-Gg: AZFdTZdxQilCL6o9Q+tdCE8nTA3Rk1A4NxjvgtYoqSWSpJ4eEVoBPEVzgsoJBl3XLsE 1hOrDk7avJeN24+zS8/WqejZ8Z7JAj5/hZdj2FgbAxpznuzFnHa7e3Squ4lmDkBUgjtam01459S 222NN1NPp8ultQf4s4eGTJJjG71IzVnrXb1LCQLBkK+fbANsi4CziPLVy/9HWp1f78mK85qsqZR zxfSKjPELNNOLE8oqM3nrQQPGpdDXcshRb/zbElCN9jpVQ7vRy/HWKznzlo8RpNRZIme6hNb02z CZ/ier0D+TAwu+GFexX36pe/pvjTlyf/70MPvDzSICI9yWkSWYCaF/aGgQEyTPaTpty9v2c6jcg GHIrXWiaVu/wI/IRBUF15hz9THw8ClJkkISEFcZenUpAFfgoiDa9fssnnKBwHFWwo7B0eW44aow WogelJTMcNs27GP3hjhCNTAuzta82pyHQqwQgHHq2zWzfojtkWIQhxVtYuZYmhKsK4DkwXXlhJI cI/RYaIhCQ8aYY4O9DUUO4mpOS2gvIQDSmI5j0Oo9Y4llDtK2cefmY/0YiX/5pKW0f2wXcakFrB VHl9Fu3SGWPeKzr1Nitj/hwD0EEYcXQqSj5pxe0qlzPbJ35ZO0Lm9Gby8dP1NjFq54CyfQ== X-Received: by 2002:a05:600c:4595:b0:4bb:bf7e:e264 with SMTP id 5b1f17b1804b1-4bbeb84f7c6mr725785e9.2.1796336063848; Thu, 03 Dec 2026 14:14:23 -0800 (PST) Received: from schinder.fritz.box ([2001:9e8:b39a:7900:a13b:fe74:8c9c:c788]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bbe00df154sm117266225e9.14.2026.12.03.14.14.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2026 14:14:23 -0800 (PST) From: Roland Schober To: linux-bluetooth@vger.kernel.org Cc: luiz.dentz@gmail.com, Roland Schober Subject: [RFC PATCH v2 5/6] Bluetooth: MGMT: Add Add Periodic Advertising Data command Date: Thu, 3 Dec 2026 23:14:04 +0100 Message-ID: <20261203221405.682222-6-rolandschober1968@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261203221405.682222-1-rolandschober1968@gmail.com> References: <20261203221405.682222-1-rolandschober1968@gmail.com> X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Add a MGMT command which sets the data of the periodic advertising train of an instance made periodic with Add Periodic Advertising Parameters. It can be sent again to change the data while the train runs. The data is limited to what one LE Set Periodic Advertising Data command takes, as the data of a BIG is. An instance with subevents is refused: the controller does not allow the command for it. Assisted-by: Claude:claude-fable-5-2 Signed-off-by: Roland Schober --- include/net/bluetooth/hci_sync.h | 1 + include/net/bluetooth/mgmt.h | 14 +++++ net/bluetooth/hci_sync.c | 2 +- net/bluetooth/mgmt.c | 87 ++++++++++++++++++++++++++++++++ 4 files changed, 103 insertions(+), 1 deletion(-) diff --git a/include/net/bluetooth/hci_sync.h b/include/net/bluetooth/hci_sync.h index 03d7e267af7c..e6d3d3de482e 100644 --- a/include/net/bluetooth/hci_sync.h +++ b/include/net/bluetooth/hci_sync.h @@ -119,6 +119,7 @@ int hci_start_per_adv_sync(struct hci_dev *hdev, u8 instance, u8 sid, int hci_disable_per_advertising_sync(struct hci_dev *hdev, u8 instance); int hci_setup_per_adv_instance_sync(struct hci_dev *hdev, u8 instance); +int hci_set_per_adv_data_sync(struct hci_dev *hdev, u8 instance); int hci_remove_advertising_sync(struct hci_dev *hdev, struct sock *sk, u8 instance, bool force); diff --git a/include/net/bluetooth/mgmt.h b/include/net/bluetooth/mgmt.h index 57b9d8d8b57d..a46e87a9152c 100644 --- a/include/net/bluetooth/mgmt.h +++ b/include/net/bluetooth/mgmt.h @@ -938,6 +938,20 @@ struct mgmt_rp_add_periodic_adv_params { __u8 instance; } __packed; +/* The data of the periodic advertising train of an instance made periodic + * with Add Periodic Advertising Parameters. + */ +#define MGMT_OP_ADD_PERIODIC_ADV_DATA 0x005E +struct mgmt_cp_add_periodic_adv_data { + __u8 instance; + __u8 data_len; + __u8 data[] __counted_by(data_len); +} __packed; +#define MGMT_ADD_PERIODIC_ADV_DATA_SIZE 2 +struct mgmt_rp_add_periodic_adv_data { + __u8 instance; +} __packed; + #define MGMT_EV_CMD_COMPLETE 0x0001 struct mgmt_ev_cmd_complete { __le16 opcode; diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c index 3d8327180c6e..05151cf6f413 100644 --- a/net/bluetooth/hci_sync.c +++ b/net/bluetooth/hci_sync.c @@ -1896,7 +1896,7 @@ static int hci_set_per_adv_params_sync(struct hci_dev *hdev, u8 instance, sizeof(cp), &cp, HCI_CMD_TIMEOUT); } -static int hci_set_per_adv_data_sync(struct hci_dev *hdev, u8 instance) +int hci_set_per_adv_data_sync(struct hci_dev *hdev, u8 instance) __context_unsafe(/* conditional locking */) { DEFINE_FLEX(struct hci_cp_le_set_per_adv_data, pdu, data, length, diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c index 4d9c5f6a05c0..c0e655a189e0 100644 --- a/net/bluetooth/mgmt.c +++ b/net/bluetooth/mgmt.c @@ -131,6 +131,7 @@ static const u16 mgmt_commands[] = { MGMT_OP_MESH_SEND_CANCEL, MGMT_OP_HCI_CMD_SYNC, MGMT_OP_ADD_PERIODIC_ADV_PARAMS, + MGMT_OP_ADD_PERIODIC_ADV_DATA, }; static const u16 mgmt_events[] = { @@ -9929,6 +9930,90 @@ static int add_periodic_adv_params(struct sock *sk, struct hci_dev *hdev, return err; } +static void add_periodic_adv_data_complete(struct hci_dev *hdev, void *data, + int err) +{ + struct mgmt_pending_cmd *cmd = data; + struct mgmt_cp_add_periodic_adv_data *cp = cmd->param; + struct mgmt_rp_add_periodic_adv_data rp; + + bt_dev_dbg(hdev, "err %d", err); + + if (err) { + mgmt_cmd_status(cmd->sk, hdev->id, cmd->opcode, + mgmt_status(err)); + } else { + rp.instance = cp->instance; + mgmt_cmd_complete(cmd->sk, hdev->id, cmd->opcode, + MGMT_STATUS_SUCCESS, &rp, sizeof(rp)); + } + + mgmt_pending_free(cmd); +} + +static int add_periodic_adv_data_sync(struct hci_dev *hdev, void *data) +{ + struct mgmt_pending_cmd *cmd = data; + struct mgmt_cp_add_periodic_adv_data *cp = cmd->param; + + return hci_set_per_adv_data_sync(hdev, cp->instance); +} + +static int add_periodic_adv_data(struct sock *sk, struct hci_dev *hdev, + void *data, u16 data_len) +{ + struct mgmt_cp_add_periodic_adv_data *cp = data; + struct mgmt_pending_cmd *cmd; + struct adv_info *adv; + int err; + + bt_dev_dbg(hdev, "sock %p", sk); + + if (data_len != struct_size(cp, data, cp->data_len) || + cp->data_len > HCI_MAX_PER_AD_LENGTH) + return mgmt_cmd_status(sk, hdev->id, + MGMT_OP_ADD_PERIODIC_ADV_DATA, + MGMT_STATUS_INVALID_PARAMS); + + hci_dev_lock(hdev); + + if (!hdev_is_powered(hdev)) { + err = mgmt_cmd_status(sk, hdev->id, + MGMT_OP_ADD_PERIODIC_ADV_DATA, + MGMT_STATUS_REJECTED); + goto unlock; + } + + /* The data of an instance with subevents is that of its subevents */ + adv = hci_find_adv_instance(hdev, cp->instance); + if (!adv || !adv->periodic || adv->num_subevents) { + err = mgmt_cmd_status(sk, hdev->id, + MGMT_OP_ADD_PERIODIC_ADV_DATA, + MGMT_STATUS_INVALID_PARAMS); + goto unlock; + } + + cmd = mgmt_pending_new(sk, MGMT_OP_ADD_PERIODIC_ADV_DATA, hdev, data, + data_len); + if (!cmd) { + err = -ENOMEM; + goto unlock; + } + + adv->per_adv_data_len = cp->data_len; + memcpy(adv->per_adv_data, cp->data, cp->data_len); + + err = hci_cmd_sync_queue(hdev, add_periodic_adv_data_sync, cmd, + add_periodic_adv_data_complete); + if (err < 0) + mgmt_pending_free(cmd); + +unlock: + hci_dev_unlock(hdev); + + return err; +} + static void remove_advertising_complete(struct hci_dev *hdev, void *data, int err) { @@ -10191,6 +10276,8 @@ static const struct hci_mgmt_handler mgmt_handlers[] = { { load_conn_subrate, MGMT_LOAD_CONN_SUBRATE_SIZE, HCI_MGMT_VAR_LEN }, { add_periodic_adv_params, MGMT_ADD_PERIODIC_ADV_PARAMS_SIZE }, + { add_periodic_adv_data, MGMT_ADD_PERIODIC_ADV_DATA_SIZE, + HCI_MGMT_VAR_LEN }, }; void mgmt_index_added(struct hci_dev *hdev) -- 2.47.3