Skip to content

Commit 31aab5c

Browse files
dwinkler2Johan Hedberg
authored andcommitted
Bluetooth: Add helper to set adv data
We wish to handle advertising data separately from advertising parameters in our new MGMT requests. This change adds a helper that allows the advertising data and scan response to be updated for an existing advertising instance. Reviewed-by: Sonny Sasaka <[email protected]> Signed-off-by: Daniel Winkler <[email protected]> Signed-off-by: Marcel Holtmann <[email protected]> Signed-off-by: Johan Hedberg <[email protected]>
1 parent ef2862a commit 31aab5c

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

include/net/bluetooth/hci_core.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,6 +1302,9 @@ int hci_add_adv_instance(struct hci_dev *hdev, u8 instance, u32 flags,
13021302
u16 adv_data_len, u8 *adv_data,
13031303
u16 scan_rsp_len, u8 *scan_rsp_data,
13041304
u16 timeout, u16 duration);
1305+
int hci_set_adv_instance_data(struct hci_dev *hdev, u8 instance,
1306+
u16 adv_data_len, u8 *adv_data,
1307+
u16 scan_rsp_len, u8 *scan_rsp_data);
13051308
int hci_remove_adv_instance(struct hci_dev *hdev, u8 instance);
13061309
void hci_adv_instances_set_rpa_expired(struct hci_dev *hdev, bool rpa_expired);
13071310

net/bluetooth/hci_core.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3005,6 +3005,37 @@ int hci_add_adv_instance(struct hci_dev *hdev, u8 instance, u32 flags,
30053005
return 0;
30063006
}
30073007

3008+
/* This function requires the caller holds hdev->lock */
3009+
int hci_set_adv_instance_data(struct hci_dev *hdev, u8 instance,
3010+
u16 adv_data_len, u8 *adv_data,
3011+
u16 scan_rsp_len, u8 *scan_rsp_data)
3012+
{
3013+
struct adv_info *adv_instance;
3014+
3015+
adv_instance = hci_find_adv_instance(hdev, instance);
3016+
3017+
/* If advertisement doesn't exist, we can't modify its data */
3018+
if (!adv_instance)
3019+
return -ENOENT;
3020+
3021+
if (adv_data_len) {
3022+
memset(adv_instance->adv_data, 0,
3023+
sizeof(adv_instance->adv_data));
3024+
memcpy(adv_instance->adv_data, adv_data, adv_data_len);
3025+
adv_instance->adv_data_len = adv_data_len;
3026+
}
3027+
3028+
if (scan_rsp_len) {
3029+
memset(adv_instance->scan_rsp_data, 0,
3030+
sizeof(adv_instance->scan_rsp_data));
3031+
memcpy(adv_instance->scan_rsp_data,
3032+
scan_rsp_data, scan_rsp_len);
3033+
adv_instance->scan_rsp_len = scan_rsp_len;
3034+
}
3035+
3036+
return 0;
3037+
}
3038+
30083039
/* This function requires the caller holds hdev->lock */
30093040
void hci_adv_monitors_clear(struct hci_dev *hdev)
30103041
{

0 commit comments

Comments
 (0)