From 2d824af836af181ee03bdcded9321a3291ba1581 Mon Sep 17 00:00:00 2001 From: Vladimir K Date: Sat, 15 Apr 2023 14:58:57 -0700 Subject: [PATCH] Add validation ID to BLE --- source/Core/BSP/Pinecilv2/ble_characteristics.h | 3 ++- source/Core/BSP/Pinecilv2/ble_handlers.cpp | 17 ++++++++++++++--- source/Core/BSP/Pinecilv2/ble_peripheral.c | 1 + 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/source/Core/BSP/Pinecilv2/ble_characteristics.h b/source/Core/BSP/Pinecilv2/ble_characteristics.h index 2e24a82d..e6e7ab6a 100644 --- a/source/Core/BSP/Pinecilv2/ble_characteristics.h +++ b/source/Core/BSP/Pinecilv2/ble_characteristics.h @@ -44,7 +44,8 @@ #define BT_UUID_CHAR_BLE_LIVE_BULK_LIVE_DATA BT_UUID_DECLARE_128(BT_UUID_128_ENCODE(0x9eae1001, 0x9d0d, 0x48c5, 0xAA55, 0x33e27f9bc533)) #define BT_UUID_CHAR_BLE_LIVE_ACCEL_NAME BT_UUID_DECLARE_128(BT_UUID_128_ENCODE(0x9eae1002, 0x9d0d, 0x48c5, 0xAA55, 0x33e27f9bc533)) #define BT_UUID_CHAR_BLE_LIVE_BUILD BT_UUID_DECLARE_128(BT_UUID_128_ENCODE(0x9eae1003, 0x9d0d, 0x48c5, 0xAA55, 0x33e27f9bc533)) -#define BT_UUID_CHAR_BLE_LIVE_DEV_ID BT_UUID_DECLARE_128(BT_UUID_128_ENCODE(0x9eae1004, 0x9d0d, 0x48c5, 0xAA55, 0x33e27f9bc533)) +#define BT_UUID_CHAR_BLE_LIVE_DEV_SN BT_UUID_DECLARE_128(BT_UUID_128_ENCODE(0x9eae1004, 0x9d0d, 0x48c5, 0xAA55, 0x33e27f9bc533)) +#define BT_UUID_CHAR_BLE_LIVE_DEV_ID BT_UUID_DECLARE_128(BT_UUID_128_ENCODE(0x9eae1005, 0x9d0d, 0x48c5, 0xAA55, 0x33e27f9bc533)) // Settings diff --git a/source/Core/BSP/Pinecilv2/ble_handlers.cpp b/source/Core/BSP/Pinecilv2/ble_handlers.cpp index 664ce43a..252a778c 100644 --- a/source/Core/BSP/Pinecilv2/ble_handlers.cpp +++ b/source/Core/BSP/Pinecilv2/ble_handlers.cpp @@ -136,6 +136,7 @@ int ble_char_read_status_callback(struct bt_conn *conn, const struct bt_gatt_att MSG((char *)"Unhandled attr read %d | %d\n", (uint32_t)attr->uuid, uuid_value); return 0; } + int ble_char_read_bulk_value_callback(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, u16_t len, u16_t offset) { if (attr == NULL || attr->uuid == NULL) { return 0; @@ -184,13 +185,23 @@ int ble_char_read_bulk_value_callback(struct bt_conn *conn, const struct bt_gatt memcpy(buf, &BUILD_VERSION, sizeof(BUILD_VERSION) - 1); return sizeof(BUILD_VERSION) - 1; case 4: - // Device unique id + // Device serial number. + // Serial number is the ID burned by manufacturer. + // In case of Pinecil V2, device SN = device MAC. { - uint64_t id = getDeviceID(); + uint64_t sn = getDeviceID(); + memcpy(buf, &sn, sizeof(sn)); + return sizeof(sn); + } + break; + case 5: + // Device ID [https://github.com/Ralim/IronOS/issues/1609]. + // ID is a unique key Pine burns at the factory and records in their db. + { + uint32_t id = getDeviceValidation(); memcpy(buf, &id, sizeof(id)); return sizeof(id); } - break; } return 0; } diff --git a/source/Core/BSP/Pinecilv2/ble_peripheral.c b/source/Core/BSP/Pinecilv2/ble_peripheral.c index 51801b7b..cc3a030f 100644 --- a/source/Core/BSP/Pinecilv2/ble_peripheral.c +++ b/source/Core/BSP/Pinecilv2/ble_peripheral.c @@ -164,6 +164,7 @@ static struct bt_gatt_attr ble_attrs_declaration[] = { BT_GATT_CHARACTERISTIC(BT_UUID_CHAR_BLE_LIVE_BULK_LIVE_DATA, BT_GATT_CHRC_READ, BT_GATT_PERM_READ, ble_char_read_bulk_value_callback, NULL, NULL), BT_GATT_CHARACTERISTIC(BT_UUID_CHAR_BLE_LIVE_ACCEL_NAME, BT_GATT_CHRC_READ, BT_GATT_PERM_READ, ble_char_read_bulk_value_callback, NULL, NULL), BT_GATT_CHARACTERISTIC(BT_UUID_CHAR_BLE_LIVE_BUILD, BT_GATT_CHRC_READ, BT_GATT_PERM_READ, ble_char_read_bulk_value_callback, NULL, NULL), + BT_GATT_CHARACTERISTIC(BT_UUID_CHAR_BLE_LIVE_DEV_SN, BT_GATT_CHRC_READ, BT_GATT_PERM_READ, ble_char_read_bulk_value_callback, NULL, NULL), BT_GATT_CHARACTERISTIC(BT_UUID_CHAR_BLE_LIVE_DEV_ID, BT_GATT_CHRC_READ, BT_GATT_PERM_READ, ble_char_read_bulk_value_callback, NULL, NULL), BT_GATT_PRIMARY_SERVICE(BT_UUID_SVC_SETTINGS_DATA),