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:680522] Mesh: Fix heartbeat publication/subscription #1430

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 22 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
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@v2
with:
path: src

- name: CI
uses: BluezTestBot/action-ci@master
with:
src_path: src
github_token: ${{ secrets.ACTION_TOKEN }}
email_token: ${{ secrets.EMAIL_TOKEN }}
patchwork_token : ${{ secrets.PATCHWORK_TOKEN }}

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

38 changes: 38 additions & 0 deletions .github/workflows/schedule_work.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Scheduled Work

on:
schedule:
- cron: "10,40 * * * *"

jobs:

manage_repo:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Manage Repo
uses: BluezTestBot/action-manage-repo@master
with:
src_repo: "bluez/bluez"
src_branch: "master"
dest_branch: "master"
workflow_branch: "workflow"
github_token: ${{ secrets.GITHUB_TOKEN }}

create_pr:
needs: manage_repo
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Patchwork to PR
uses: BluezTestBot/action-patchwork-to-pr@master
with:
pw_key_str: "user"
github_token: ${{ secrets.ACTION_TOKEN }}
email_token: ${{ secrets.EMAIL_TOKEN }}
patchwork_token: ${{ secrets.PATCHWORK_TOKEN }}

48 changes: 40 additions & 8 deletions mesh/cfgmod-server.c
Original file line number Diff line number Diff line change
Expand Up @@ -455,22 +455,22 @@ static uint16_t cfg_key_refresh_phase(struct mesh_node *node,
static uint8_t uint32_to_log(uint32_t value)
{
uint32_t val = 1;
uint8_t ret = 1;
uint8_t ret = 0;

if (!value)
return 0;
else if (value > 0x10000)
return 0xff;

while (val < value) {
while (val <= value) {
val <<= 1;
ret++;
}

return ret;
}

static uint16_t hb_subscription_get(struct mesh_node *node, int status)
static uint16_t hb_subscription_status(struct mesh_node *node, int status)
{
struct mesh_net *net = node_get_net(node);
struct mesh_net_heartbeat_sub *sub = mesh_net_get_heartbeat_sub(net);
Expand All @@ -495,13 +495,35 @@ static uint16_t hb_subscription_get(struct mesh_node *node, int status)
l_put_le16(sub->dst, msg + n);
n += 2;
msg[n++] = uint32_to_log(time_now.tv_sec);
msg[n++] = uint32_to_log(sub->count);
msg[n++] = sub->count ? sub->min_hops : 0;
msg[n++] = sub->count != 0xffff ? uint32_to_log(sub->count) : 0xff;
msg[n++] = sub->min_hops;
msg[n++] = sub->max_hops;

return n;
}

static uint16_t hb_subscription_get(struct mesh_node *node, int status)
{
struct mesh_net *net = node_get_net(node);
struct mesh_net_heartbeat_sub *sub = mesh_net_get_heartbeat_sub(net);

/*
* MshPRFv1.0.1 section 4.4.1.2.16, Heartbeat Subscription state:
* If this is a GET request and the source or destination is unassigned,
* all fields shall be set to zero in the status reply.
*/
if (IS_UNASSIGNED(sub->src) || IS_UNASSIGNED(sub->dst)) {
uint16_t n;

n = mesh_model_opcode_set(OP_CONFIG_HEARTBEAT_SUB_STATUS, msg);
memset(msg + n, 0, 9);
n += 9;
return n;
}

return hb_subscription_status(node, status);
}

static uint16_t hb_subscription_set(struct mesh_node *node, const uint8_t *pkt)
{
uint16_t src, dst;
Expand All @@ -525,7 +547,7 @@ static uint16_t hb_subscription_set(struct mesh_node *node, const uint8_t *pkt)

status = mesh_net_set_heartbeat_sub(net, src, dst, period_log);

return hb_subscription_get(node, status);
return hb_subscription_status(node, status);
}

static uint16_t hb_publication_get(struct mesh_node *node, int status)
Expand All @@ -538,7 +560,7 @@ static uint16_t hb_publication_get(struct mesh_node *node, int status)
msg[n++] = status;
l_put_le16(pub->dst, msg + n);
n += 2;
msg[n++] = uint32_to_log(pub->count);
msg[n++] = pub->count != 0xffff ? uint32_to_log(pub->count) : 0xff;
msg[n++] = uint32_to_log(pub->period);
msg[n++] = pub->ttl;
l_put_le16(pub->features, msg + n);
Expand Down Expand Up @@ -575,7 +597,17 @@ static uint16_t hb_publication_set(struct mesh_node *node, const uint8_t *pkt)
status = mesh_net_set_heartbeat_pub(net, dst, features, net_idx, ttl,
count_log, period_log);

return hb_publication_get(node, status);
if (status != MESH_STATUS_SUCCESS) {
uint16_t n;

n = mesh_model_opcode_set(OP_CONFIG_HEARTBEAT_PUB_STATUS, msg);
msg[n++] = status;
memcpy(msg + n, pkt, 9);
n += 9;

return n;
} else
return hb_publication_get(node, status);
}

static void node_reset(void *user_data)
Expand Down
20 changes: 4 additions & 16 deletions mesh/net.c
Original file line number Diff line number Diff line change
Expand Up @@ -3608,24 +3608,14 @@ int mesh_net_set_heartbeat_sub(struct mesh_net *net, uint16_t src, uint16_t dst,
return MESH_STATUS_UNSPECIFIED_ERROR;

/* Check if the subscription should be disabled */
if (IS_UNASSIGNED(src) || IS_UNASSIGNED(dst)) {
if (IS_UNASSIGNED(src) || IS_UNASSIGNED(dst) || !period_log) {
if (IS_GROUP(sub->dst))
mesh_net_dst_unreg(net, sub->dst);

/* Preserve collected data, but disable */
sub->enabled = false;
sub->dst = UNASSIGNED_ADDRESS;
sub->src = UNASSIGNED_ADDRESS;
sub->count = 0;
sub->period = 0;
sub->min_hops = 0;
sub->max_hops = 0;

} else if (!period_log && src == sub->src && dst == sub->dst) {
if (IS_GROUP(sub->dst))
mesh_net_dst_unreg(net, sub->dst);

/* Preserve collected data, but disable */
sub->enabled = false;
sub->period = 0;

} else {
Expand All @@ -3637,12 +3627,12 @@ int mesh_net_set_heartbeat_sub(struct mesh_net *net, uint16_t src, uint16_t dst,
mesh_net_dst_reg(net, dst);
}

sub->enabled = !!period_log;
sub->enabled = true;
sub->src = src;
sub->dst = dst;
sub->count = 0;
sub->period = log_to_uint32(period_log);
sub->min_hops = 0x00;
sub->min_hops = 0x7f;
sub->max_hops = 0x00;
gettimeofday(&time_now, NULL);
sub->start = time_now.tv_sec;
Expand All @@ -3656,8 +3646,6 @@ int mesh_net_set_heartbeat_sub(struct mesh_net *net, uint16_t src, uint16_t dst,
return MESH_STATUS_SUCCESS;
}

sub->min_hops = 0xff;

if (!sub->timer)
sub->timer = l_timeout_create(sub->period, hb_sub_timeout_func,
net, NULL);
Expand Down