aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeon Rinkel <[email protected]>2023-11-09 22:10:20 +0100
committerLeon Rinkel <[email protected]>2023-11-09 22:10:20 +0100
commitf416658a0acec88ba5c5939180e8bcb575701333 (patch)
tree524d0c377f7c23a4c9ef2ff9cf9bb93ec969fb68
parent35d5ed857302c5c3f2c5bcc9b14e74a966171363 (diff)
Set passkey based on HWIDHEADmain
-rw-r--r--app/prj.conf2
-rw-r--r--app/src/main.c23
2 files changed, 24 insertions, 1 deletions
diff --git a/app/prj.conf b/app/prj.conf
index 6148f8c..39a44a4 100644
--- a/app/prj.conf
+++ b/app/prj.conf
@@ -32,6 +32,8 @@ CONFIG_BT_DEVICE_NAME="lumen"
CONFIG_BT_DEVICE_NAME_DYNAMIC=y
CONFIG_BT_DEVICE_NAME_MAX=64
+CONFIG_HWINFO=y
+
# This option enables the MCUmgr support, which is required for the DFU process.
CONFIG_MCUMGR=y
# This option enables the MCUmgr image management handlers, which are required
diff --git a/app/src/main.c b/app/src/main.c
index 92465df..38a586c 100644
--- a/app/src/main.c
+++ b/app/src/main.c
@@ -8,6 +8,7 @@
#include <zephyr/sys_clock.h>
#include <zephyr/device.h>
#include <zephyr/drivers/led_strip.h>
+#include <zephyr/drivers/hwinfo.h>
#include <zephyr/bluetooth/bluetooth.h>
#include <zephyr/bluetooth/conn.h>
#include <zephyr/bluetooth/uuid.h>
@@ -221,6 +222,10 @@ static struct bt_conn_auth_info_cb conn_auth_info_callbacks =
int main(void)
{
int err;
+ const ssize_t device_id_len = 4;
+ uint8_t device_id[device_id_len];
+ ssize_t actual_device_id_len;
+ uint32_t passkey;
int j = 0;
k_timepoint_t till_heartbeat = sys_timepoint_calc(K_NO_WAIT);
@@ -246,7 +251,23 @@ int main(void)
return 0;
}
- unsigned int passkey = 123456;
+ actual_device_id_len =
+ hwinfo_get_device_id(device_id, device_id_len);
+ if (actual_device_id_len < 0)
+ {
+ LOG_ERR("failed to get device id (err %d)\n", err);
+ return 0;
+ }
+
+ passkey = (
+ (uint32_t) (
+ (device_id[3] << 24) |
+ (device_id[2] << 16) |
+ (device_id[1] << 8) |
+ (device_id[0] << 0)
+ )
+ ) % 1000000;
+ LOG_INF("setting passkey to %06u\n", passkey);
bt_passkey_set(passkey);
err = bt_enable(NULL);