Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PW_SID:933394] [BlueZ,v2] btdev: Broadcast EXT_ADV packets based on its interval #2672

Open
wants to merge 2 commits into
base: workflow
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: CI

on: [pull_request]

jobs:
ci:
runs-on: ubuntu-latest
name: CI for Pull Request
steps:
- name: Checkout the source code
uses: actions/checkout@v3
with:
path: src/src

- name: CI
uses: tedd-an/bzcafe@main
with:
task: ci
base_folder: src
space: user
github_token: ${{ secrets.ACTION_TOKEN }}
email_token: ${{ secrets.EMAIL_TOKEN }}
patchwork_token: ${{ secrets.PATCHWORK_TOKEN }}
patchwork_user: ${{ secrets.PATCHWORK_USER }}

26 changes: 26 additions & 0 deletions .github/workflows/code_scan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Code Scan

on:
schedule:
- cron: "40 7 * * FRI"

jobs:
code-scan:
runs-on: ubuntu-latest
steps:
- name: Checkout the source
uses: actions/checkout@v2
with:
fetch-depth: 0
path: src
- name: Code Scan
uses: BluezTestBot/action-code-scan@main
with:
src_path: src
github_token: ${{ secrets.GITHUB_TOKEN }}
email_token: ${{ secrets.EMAIL_TOKEN }}
- uses: actions/upload-artifact@v2
with:
name: scan_report
path: scan_report.tar.gz

43 changes: 43 additions & 0 deletions .github/workflows/sync.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Sync

on:
schedule:
- cron: "*/30 * * * *"

jobs:
sync_repo:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: master

- name: Sync Repo
uses: tedd-an/bzcafe@main
with:
task: sync
upstream_repo: 'https://git.kernel.org/pub/scm/bluetooth/bluez.git'
github_token: ${{ secrets.GITHUB_TOKEN }}

- name: Cleanup PR
uses: tedd-an/bzcafe@main
with:
task: cleanup
github_token: ${{ secrets.ACTION_TOKEN }}

sync_patchwork:
needs: sync_repo
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Sync Patchwork
uses: tedd-an/bzcafe@main
with:
task: patchwork
space: user
github_token: ${{ secrets.ACTION_TOKEN }}
email_token: ${{ secrets.EMAIL_TOKEN }}
patchwork_token: ${{ secrets.PATCHWORK_TOKEN }}
patchwork_user: ${{ secrets.PATCHWORK_USER }}

103 changes: 37 additions & 66 deletions emulator/btdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ struct le_ext_adv {
struct btdev *dev;
uint8_t handle;
uint8_t enable;
uint32_t interval;
uint8_t type; /* evt_properties */
uint8_t own_addr_type; /* own_addr_type */
uint8_t direct_addr_type; /* peer_addr_type */
Expand All @@ -102,7 +103,8 @@ struct le_ext_adv {
uint8_t adv_data_len;
uint8_t scan_data[252];
uint8_t scan_data_len;
unsigned int id;
unsigned int broadcast_id;
unsigned int timeout_id;
};

struct le_per_adv {
Expand Down Expand Up @@ -575,8 +577,10 @@ static void le_ext_adv_free(void *data)
/* Remove to queue */
queue_remove(ext_adv->dev->le_ext_adv, ext_adv);

if (ext_adv->id)
timeout_remove(ext_adv->id);
if (ext_adv->broadcast_id)
timeout_remove(ext_adv->broadcast_id);
if (ext_adv->timeout_id)
timeout_remove(ext_adv->timeout_id);

free(ext_adv);
}
Expand Down Expand Up @@ -4759,9 +4763,13 @@ static void ext_adv_disable(void *data, void *user_data)
if (handle && ext_adv->handle != handle)
return;

if (ext_adv->id) {
timeout_remove(ext_adv->id);
ext_adv->id = 0;
if (ext_adv->broadcast_id) {
timeout_remove(ext_adv->broadcast_id);
ext_adv->broadcast_id = 0;
}
if (ext_adv->timeout_id) {
timeout_remove(ext_adv->timeout_id);
ext_adv->timeout_id = 0;
}

ext_adv->enable = 0x00;
Expand Down Expand Up @@ -4861,6 +4869,7 @@ static int cmd_set_ext_adv_params(struct btdev *dev, const void *data,
return 0;
}

ext_adv->interval = get_le24(cmd->min_interval) * 0.625;
ext_adv->type = le16_to_cpu(cmd->evt_properties);
ext_adv->own_addr_type = cmd->own_addr_type;
ext_adv->direct_addr_type = cmd->peer_addr_type;
Expand Down Expand Up @@ -4978,9 +4987,10 @@ static void send_ext_adv(struct btdev *btdev, const struct btdev *remote,
1 + 24 + meta_event.lear.data_len);
}

static void le_set_ext_adv_enable_complete(struct btdev *btdev,
struct le_ext_adv *ext_adv)
static bool ext_adv_broadcast(void *user_data)
{
struct le_ext_adv *ext_adv = user_data;
struct btdev *btdev = ext_adv->dev;
uint16_t report_type;
int i;

Expand Down Expand Up @@ -5016,7 +5026,10 @@ static void le_set_ext_adv_enable_complete(struct btdev *btdev,
report_type, true);
}
}

return true;
}

static void adv_set_terminate(struct btdev *dev, uint8_t status, uint8_t handle,
uint16_t conn_handle, uint8_t num_evts)
{
Expand All @@ -5035,7 +5048,7 @@ static bool ext_adv_timeout(void *user_data)
{
struct le_ext_adv *adv = user_data;

adv->id = 0;
adv->timeout_id = 0;
adv_set_terminate(adv->dev, BT_HCI_ERR_ADV_TIMEOUT, adv->handle,
0x0000, 0x00);
le_ext_adv_free(adv);
Expand Down Expand Up @@ -5120,32 +5133,28 @@ static int cmd_set_ext_adv_enable(struct btdev *dev, const void *data,

if (!cmd->enable)
ext_adv_disable(ext_adv, NULL);
else if (eas->duration)
ext_adv->id = timeout_add(eas->duration * 10,
ext_adv_timeout,
else {
/* Send the first advertising report right away and
* start the timer for continuous advertising.
*/
ext_adv_broadcast(ext_adv);
ext_adv->broadcast_id = timeout_add(ext_adv->interval,
ext_adv_broadcast,
ext_adv, NULL);
if (eas->duration) {
unsigned int duration_ms = eas->duration * 10;
ext_adv->timeout_id = timeout_add(duration_ms,
ext_adv_timeout,
ext_adv, NULL);
}
}

}

exit_complete:
cmd_complete(dev, BT_HCI_CMD_LE_SET_EXT_ADV_ENABLE, &status,
sizeof(status));

if (status == BT_HCI_ERR_SUCCESS && cmd->enable) {
/* Go through each sets and send adv event to peer device */
for (i = 0; i < cmd->num_of_sets; i++) {
const struct bt_hci_cmd_ext_adv_set *eas;
struct le_ext_adv *ext_adv;

eas = data + sizeof(*cmd) + (sizeof(*eas) * i);

ext_adv = queue_find(dev->le_ext_adv,
match_ext_adv_handle,
UINT_TO_PTR(eas->handle));
if (ext_adv)
le_set_ext_adv_enable_complete(dev, ext_adv);
}
}

return 0;
}

Expand Down Expand Up @@ -5495,43 +5504,6 @@ static int cmd_set_ext_scan_enable(struct btdev *dev, const void *data,
return 0;
}

static void scan_ext_adv(struct btdev *dev, struct btdev *remote)
{
const struct queue_entry *entry;

for (entry = queue_get_entries(remote->le_ext_adv); entry;
entry = entry->next) {
struct le_ext_adv *ext_adv = entry->data;
uint16_t report_type;

if (!ext_adv->enable)
continue;

if (!ext_adv_match_addr(dev, ext_adv))
continue;

report_type = get_ext_adv_type(ext_adv->type);
send_ext_adv(dev, remote, ext_adv, report_type, false);

if (dev->le_scan_type != 0x01)
continue;

/* if scannable bit is set the send scan response */
if (ext_adv->type & 0x02) {
if (ext_adv->type == 0x13)
report_type = 0x1b;
else if (ext_adv->type == 0x12)
report_type = 0x1a;
else if (!(ext_adv->type & 0x10))
report_type &= 0x08;
else
continue;

send_ext_adv(dev, remote, ext_adv, report_type, true);
}
}
}

static void scan_pa(struct btdev *dev, struct btdev *remote)
{
struct le_per_adv *per_adv = queue_find(dev->le_per_adv,
Expand Down Expand Up @@ -5560,7 +5532,6 @@ static int cmd_set_ext_scan_enable_complete(struct btdev *dev, const void *data,
if (!btdev_list[i] || btdev_list[i] == dev)
continue;

scan_ext_adv(dev, btdev_list[i]);
scan_pa(dev, btdev_list[i]);
}

Expand Down