From: Brian Gix <brian.gix@intel.com>
To: linux-bluetooth@vger.kernel.org
Cc: inga.stotland@intel.com, michal.lowas-rzechonek@silvair.com,
brian.gix@intel.com
Subject: [PATCH BlueZ 2/8] mesh: Fix support for Provisioner Initiator
Date: Wed, 10 Jul 2019 16:07:51 -0700 [thread overview]
Message-ID: <20190710230757.8425-3-brian.gix@intel.com> (raw)
In-Reply-To: <20190710230757.8425-1-brian.gix@intel.com>
---
mesh/pb-adv.c | 54 ++++++++++++++++++++++++++++++++++++------------------
mesh/pb-adv.h | 3 ++-
2 files changed, 38 insertions(+), 19 deletions(-)
diff --git a/mesh/pb-adv.c b/mesh/pb-adv.c
index 8762afd7c..346293bd0 100644
--- a/mesh/pb-adv.c
+++ b/mesh/pb-adv.c
@@ -65,6 +65,8 @@ struct pb_adv_session {
static struct pb_adv_session *pb_session = NULL;
+static const uint8_t filter[1] = { MESH_AD_TYPE_PROVISION };
+
static void send_adv_segs(struct pb_adv_session *session, const uint8_t *data,
uint16_t size)
{
@@ -77,7 +79,7 @@ static void send_adv_segs(struct pb_adv_session *session, const uint8_t *data,
if (!size)
return;
- mesh_send_cancel(buf, 1);
+ mesh_send_cancel(filter, sizeof(filter));
l_put_be32(session->conn_id, buf + 1);
buf[1 + 4] = ++session->local_msg_num;
@@ -103,7 +105,7 @@ static void send_adv_segs(struct pb_adv_session *session, const uint8_t *data,
l_debug("max_seg: %2.2x", max_seg);
l_debug("size: %2.2x, CRC: %2.2x", size, buf[9]);
/* print_packet("PB-TX", buf + 1, init_size + 9); */
- mesh_send_pkt(MESH_IO_TX_COUNT_UNLIMITED, 50, buf, init_size + 10);
+ mesh_send_pkt(MESH_IO_TX_COUNT_UNLIMITED, 200, buf, init_size + 10);
consumed = init_size;
@@ -120,7 +122,7 @@ static void send_adv_segs(struct pb_adv_session *session, const uint8_t *data,
/* print_packet("PB-TX", buf + 1, seg_size + 6); */
- mesh_send_pkt(MESH_IO_TX_COUNT_UNLIMITED, 50,
+ mesh_send_pkt(MESH_IO_TX_COUNT_UNLIMITED, 200,
buf, seg_size + 7);
consumed += seg_size;
@@ -130,7 +132,6 @@ static void send_adv_segs(struct pb_adv_session *session, const uint8_t *data,
static void tx_timeout(struct l_timeout *timeout, void *user_data)
{
struct pb_adv_session *session = user_data;
- uint8_t cancel[] = { MESH_AD_TYPE_PROVISION };
mesh_prov_close_func_t cb;
if (!session || pb_session != session)
@@ -139,7 +140,7 @@ static void tx_timeout(struct l_timeout *timeout, void *user_data)
l_timeout_remove(session->tx_timeout);
session->tx_timeout = NULL;
- mesh_send_cancel(cancel, sizeof(cancel));
+ mesh_send_cancel(filter, sizeof(filter));
l_info("TX timeout");
cb = pb_session->close_cb;
@@ -162,17 +163,29 @@ static void pb_adv_tx(void *user_data, uint8_t *data, uint16_t len)
send_adv_segs(session, data, len);
}
+static void send_open_req(struct pb_adv_session *session)
+{
+ uint8_t open_req[23] = { MESH_AD_TYPE_PROVISION };
+
+ l_put_be32(session->conn_id, open_req + 1);
+ open_req[1 + 4] = 0;
+ open_req[1 + 4 + 1] = PB_ADV_OPEN_REQ;
+ memcpy(open_req + 7, session->uuid, 16);
+
+ mesh_send_cancel(filter, sizeof(filter));
+ mesh_send_pkt(MESH_IO_TX_COUNT_UNLIMITED, 500, open_req,
+ sizeof(open_req));
+}
+
static void send_open_cfm(struct pb_adv_session *session)
{
uint8_t open_cfm[7] = { MESH_AD_TYPE_PROVISION };
l_put_be32(session->conn_id, open_cfm + 1);
open_cfm[1 + 4] = 0;
- open_cfm[1 + 4 + 1] = 0x07; /* OPEN_CFM */
-
- /* print_packet("PB-TX", open_cfm + 1, sizeof(open_cfm) - 1); */
+ open_cfm[1 + 4 + 1] = PB_ADV_OPEN_CFM; /* OPEN_CFM */
- mesh_send_cancel(open_cfm, 1);
+ mesh_send_cancel(filter, sizeof(filter));
mesh_send_pkt(5, 100, open_cfm, sizeof(open_cfm));
}
@@ -182,9 +195,8 @@ static void send_ack(struct pb_adv_session *session, uint8_t msg_num)
l_put_be32(session->conn_id, ack + 1);
ack[1 + 4] = msg_num;
- ack[1 + 4 + 1] = 0x01; /* ACK */
+ ack[1 + 4 + 1] = PB_ADV_ACK;
- /* print_packet("ADV-ACK", ack + 1, sizeof(ack) - 1); */
mesh_send_pkt(1, 100, ack, sizeof(ack));
}
@@ -192,16 +204,16 @@ static void send_close_ind(struct pb_adv_session *session, uint8_t reason)
{
uint8_t close_ind[8] = { MESH_AD_TYPE_PROVISION };
- if (!pb_session || pb_session->user_data != session)
+ if (!pb_session || pb_session != session)
return;
l_put_be32(session->conn_id, close_ind + 1);
close_ind[5] = 0;
- close_ind[6] = PB_ADV_CLOSE; /* CLOSE_IND */
+ close_ind[6] = PB_ADV_CLOSE;
close_ind[7] = reason;
- mesh_send_cancel(close_ind, 1);
- mesh_send_pkt(5, 100, close_ind, sizeof(close_ind));
+ mesh_send_cancel(filter, sizeof(filter));
+ mesh_send_pkt(10, 100, close_ind, sizeof(close_ind));
}
static void pb_adv_packet(void *user_data, const uint8_t *pkt, uint16_t len)
@@ -311,7 +323,7 @@ static void pb_adv_packet(void *user_data, const uint8_t *pkt, uint16_t len)
if (session->local_acked > msg_num)
return;
- l_debug("Got ACK %d", msg_num);
+ mesh_send_cancel(filter, sizeof(filter));
session->local_acked = msg_num;
session->ack_cb(session->user_data, msg_num);
break;
@@ -395,7 +407,8 @@ static void pb_adv_packet(void *user_data, const uint8_t *pkt, uint16_t len)
}
}
-bool pb_adv_reg(mesh_prov_open_func_t open_cb, mesh_prov_close_func_t close_cb,
+bool pb_adv_reg(bool initiator, mesh_prov_open_func_t open_cb,
+ mesh_prov_close_func_t close_cb,
mesh_prov_receive_func_t rx_cb, mesh_prov_ack_func_t ack_cb,
uint8_t uuid[16], void *user_data)
{
@@ -408,11 +421,16 @@ bool pb_adv_reg(mesh_prov_open_func_t open_cb, mesh_prov_close_func_t close_cb,
pb_session->rx_cb = rx_cb;
pb_session->ack_cb = ack_cb;
pb_session->user_data = user_data;
+ pb_session->initiator = initiator;
memcpy(pb_session->uuid, uuid, 16);
- /* TODO: register PB AD type and Start Beaconing ? */
mesh_reg_prov_rx(pb_adv_packet, pb_session);
+ if (initiator) {
+ l_getrandom(&pb_session->conn_id, sizeof(pb_session->conn_id));
+ send_open_req(pb_session);
+ }
+
return true;
}
diff --git a/mesh/pb-adv.h b/mesh/pb-adv.h
index a5870d5a2..80d53d234 100644
--- a/mesh/pb-adv.h
+++ b/mesh/pb-adv.h
@@ -17,7 +17,8 @@
*
*/
-bool pb_adv_reg(mesh_prov_open_func_t open_cb, mesh_prov_close_func_t close_cb,
+bool pb_adv_reg(bool initiator, mesh_prov_open_func_t open_cb,
+ mesh_prov_close_func_t close_cb,
mesh_prov_receive_func_t rx_cb, mesh_prov_ack_func_t ack_cb,
uint8_t uuid[16], void *user_data);
void pb_adv_unreg(void *user_data);
--
2.14.5
next prev parent reply other threads:[~2019-07-10 23:08 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-10 23:07 [PATCH BlueZ 0/8] mesh: Provisioner Initiator added Brian Gix
2019-07-10 23:07 ` [PATCH BlueZ 1/8] doc: Cleanup API Provisioner1 interface Brian Gix
2019-07-10 23:07 ` Brian Gix [this message]
2019-07-11 7:10 ` [PATCH BlueZ 2/8] mesh: Fix support for Provisioner Initiator Michał Lowas-Rzechonek
2019-07-10 23:07 ` [PATCH BlueZ 3/8] mesh: Add special Beacon handler for Provisioning Brian Gix
2019-07-10 23:07 ` [PATCH BlueZ 4/8] mesh: Expose mapping function for D-Bus errors Brian Gix
2019-07-10 23:07 ` [PATCH BlueZ 5/8] mesh: Expose resources needed by Management1 interface Brian Gix
2019-07-10 23:07 ` [PATCH BlueZ 6/8] mesh: Fix implementation of Provisioner Initiator Brian Gix
2019-07-11 7:33 ` Michał Lowas-Rzechonek
2019-07-11 15:48 ` Gix, Brian
2019-07-10 23:07 ` [PATCH BlueZ 7/8] mesh: Implement DBus Provisioning methods Brian Gix
2019-07-10 23:07 ` [PATCH BlueZ 8/8] test: This extends the mesh tool to exercise " Brian Gix
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190710230757.8425-3-brian.gix@intel.com \
--to=brian.gix@intel.com \
--cc=inga.stotland@intel.com \
--cc=linux-bluetooth@vger.kernel.org \
--cc=michal.lowas-rzechonek@silvair.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).