Topics

[RFCv2 2/2] Bluetooth: SMP: Make use of sys_timer API


Luiz Augusto von Dentz
 

From: Luiz Augusto von Dentz <luiz.von.dentz(a)intel.com>

This replaces use of delayed fiber with sys_timer which shares a common
fiber and stack with other timers.

Change-Id: Ie8f0ea778d7a415a61bd326da70cfae4131156af
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz(a)intel.com>
---
net/bluetooth/smp.c | 40 +++++++++++++++++-----------------------
1 file changed, 17 insertions(+), 23 deletions(-)

diff --git a/net/bluetooth/smp.c b/net/bluetooth/smp.c
index 42f6ecf..53614f9 100644
--- a/net/bluetooth/smp.c
+++ b/net/bluetooth/smp.c
@@ -28,6 +28,7 @@
#include <misc/util.h>
#include <misc/byteorder.h>
#include <misc/stack.h>
+#include <misc/timer.h>

#include <net/buf.h>
#include <bluetooth/log.h>
@@ -101,9 +102,6 @@ struct bt_smp {
/* The channel this context is associated with */
struct bt_l2cap_chan chan;

- /* SMP Timeout fiber handle */
- nano_thread_id_t timeout;
-
/* Commands that remote is allowed to send */
atomic_t allowed_cmds;

@@ -155,8 +153,8 @@ struct bt_smp {
/* Remote key distribution */
uint8_t remote_dist;

- /* stack for timeout fiber */
- BT_STACK(stack, 128);
+ /* Timeout timer */
+ struct sys_timer timer;
};

/* based on table 2.8 Core Spec 2.3.5.1 Vol. 3 Part H */
@@ -571,12 +569,9 @@ static void smp_reset(struct bt_smp *smp)
{
struct bt_conn *conn = smp->chan.conn;

- if (smp->timeout) {
- fiber_fiber_delayed_start_cancel(smp->timeout);
- smp->timeout = NULL;
-
- stack_analyze("smp timeout stack", smp->stack,
- sizeof(smp->stack));
+ if (smp->timer.func) {
+ sys_timer_cancel(&smp->timer);
+ smp->timer.func = NULL;
}

smp->method = JUST_WORKS;
@@ -601,15 +596,13 @@ static void smp_reset(struct bt_smp *smp)
#endif /* CONFIG_BLUETOOTH_PERIPHERAL */
}

-static void smp_timeout(int arg1, int arg2)
+static void smp_timeout(void *user_data)
{
- struct bt_smp *smp = (struct bt_smp *)arg1;
-
- ARG_UNUSED(arg2);
+ struct bt_smp *smp = user_data;

BT_ERR("SMP Timeout");

- smp->timeout = NULL;
+ smp->timer.func = NULL;

/*
* If SMP timeout occurred during key distribution we should assume
@@ -627,13 +620,13 @@ static void smp_timeout(int arg1, int arg2)

static void smp_restart_timer(struct bt_smp *smp)
{
- if (smp->timeout) {
- fiber_fiber_delayed_start_cancel(smp->timeout);
+ if (smp->timer.func) {
+ sys_timer_cancel(&smp->timer);
+ } else {
+ sys_timer_init(&smp->timer, smp_timeout, smp);
}

- smp->timeout = fiber_delayed_start(smp->stack, sizeof(smp->stack),
- smp_timeout, (int)smp, 0, 7, 0,
- SMP_TIMEOUT);
+ sys_timer_add(&smp->timer, SMP_TIMEOUT);
}

static struct net_buf *smp_create_pdu(struct bt_conn *conn, uint8_t op,
@@ -2626,8 +2619,9 @@ static void bt_smp_disconnected(struct bt_l2cap_chan *chan)

BT_DBG("chan %p cid 0x%04x", chan, chan->tx.cid);

- if (smp->timeout) {
- fiber_fiber_delayed_start_cancel(smp->timeout);
+ if (smp->timer.func) {
+ sys_timer_cancel(&smp->timer);
+ smp->timer.func = NULL;
}

if (keys) {
--
2.5.5