mirror of
https://github.com/DarkFlippers/unleashed-firmware
synced 2024-12-21 02:03:18 +00:00
917410a0a8
* fbt: reworking targets & assets handling WIP * fbt: dist fixes * fbt: moved SD card resources to owning apps * unit_tests: moved resources to app folder * github: updated unit_tests paths * github: packaging fixes * unit_tests: fixes * fbt: assets: internal cleanup * fbt: reworked assets handling * github: unit_tests: reintroducing fixes * minor cleanup * fbt: naming changes to reflect private nature of scons tools * fbt: resources: fixed dist archive paths * docs: updated paths * docs: updated more paths * docs: included "resources" parameter in app manifest docs; updated assets readme * updated gitignore for assets * github: updated action versions * unit_tests: restored timeout; scripts: assets: logging changes * gh: don't upload desktop animations for unit test run Co-authored-by: あく <alleteam@gmail.com>
178 lines
6.6 KiB
C
178 lines
6.6 KiB
C
#include "dev_info_service.h"
|
|
#include "app_common.h"
|
|
#include "gatt_char.h"
|
|
#include <ble/ble.h>
|
|
|
|
#include <furi.h>
|
|
#include <protobuf_version.h>
|
|
#include <lib/toolbox/version.h>
|
|
|
|
#include "dev_info_service_uuid.inc"
|
|
|
|
#define TAG "BtDevInfoSvc"
|
|
|
|
typedef enum {
|
|
DevInfoSvcGattCharacteristicMfgName = 0,
|
|
DevInfoSvcGattCharacteristicSerial,
|
|
DevInfoSvcGattCharacteristicFirmwareRev,
|
|
DevInfoSvcGattCharacteristicSoftwareRev,
|
|
DevInfoSvcGattCharacteristicRpcVersion,
|
|
DevInfoSvcGattCharacteristicCount,
|
|
} DevInfoSvcGattCharacteristicId;
|
|
|
|
#define DEVICE_INFO_HARDWARE_REV_SIZE 4
|
|
typedef struct {
|
|
uint16_t service_handle;
|
|
FlipperGattCharacteristicInstance characteristics[DevInfoSvcGattCharacteristicCount];
|
|
FuriString* version_string;
|
|
char hardware_revision[DEVICE_INFO_HARDWARE_REV_SIZE];
|
|
} DevInfoSvc;
|
|
|
|
static DevInfoSvc* dev_info_svc = NULL;
|
|
|
|
static const char dev_info_man_name[] = "Flipper Devices Inc.";
|
|
static const char dev_info_serial_num[] = "1.0";
|
|
static const char dev_info_rpc_version[] = TOSTRING(PROTOBUF_MAJOR_VERSION.PROTOBUF_MINOR_VERSION);
|
|
|
|
static bool dev_info_char_firmware_rev_callback(
|
|
const void* context,
|
|
const uint8_t** data,
|
|
uint16_t* data_len) {
|
|
const DevInfoSvc* dev_info_svc = *(DevInfoSvc**)context;
|
|
*data_len = strlen(dev_info_svc->hardware_revision);
|
|
if(data) {
|
|
*data = (const uint8_t*)&dev_info_svc->hardware_revision;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
static bool dev_info_char_software_rev_callback(
|
|
const void* context,
|
|
const uint8_t** data,
|
|
uint16_t* data_len) {
|
|
const DevInfoSvc* dev_info_svc = *(DevInfoSvc**)context;
|
|
*data_len = furi_string_size(dev_info_svc->version_string);
|
|
if(data) {
|
|
*data = (const uint8_t*)furi_string_get_cstr(dev_info_svc->version_string);
|
|
}
|
|
return false;
|
|
}
|
|
|
|
static const FlipperGattCharacteristicParams dev_info_svc_chars[DevInfoSvcGattCharacteristicCount] =
|
|
{[DevInfoSvcGattCharacteristicMfgName] =
|
|
{.name = "Manufacturer Name",
|
|
.data_prop_type = FlipperGattCharacteristicDataFixed,
|
|
.data.fixed.length = sizeof(dev_info_man_name) - 1,
|
|
.data.fixed.ptr = (const uint8_t*)&dev_info_man_name,
|
|
.uuid.Char_UUID_16 = MANUFACTURER_NAME_UUID,
|
|
.uuid_type = UUID_TYPE_16,
|
|
.char_properties = CHAR_PROP_READ,
|
|
.security_permissions = ATTR_PERMISSION_AUTHEN_READ,
|
|
.gatt_evt_mask = GATT_DONT_NOTIFY_EVENTS,
|
|
.is_variable = CHAR_VALUE_LEN_CONSTANT},
|
|
[DevInfoSvcGattCharacteristicSerial] =
|
|
{.name = "Serial Number",
|
|
.data_prop_type = FlipperGattCharacteristicDataFixed,
|
|
.data.fixed.length = sizeof(dev_info_serial_num) - 1,
|
|
.data.fixed.ptr = (const uint8_t*)&dev_info_serial_num,
|
|
.uuid.Char_UUID_16 = SERIAL_NUMBER_UUID,
|
|
.uuid_type = UUID_TYPE_16,
|
|
.char_properties = CHAR_PROP_READ,
|
|
.security_permissions = ATTR_PERMISSION_AUTHEN_READ,
|
|
.gatt_evt_mask = GATT_DONT_NOTIFY_EVENTS,
|
|
.is_variable = CHAR_VALUE_LEN_CONSTANT},
|
|
[DevInfoSvcGattCharacteristicFirmwareRev] =
|
|
{.name = "Firmware Revision",
|
|
.data_prop_type = FlipperGattCharacteristicDataCallback,
|
|
.data.callback.context = &dev_info_svc,
|
|
.data.callback.fn = dev_info_char_firmware_rev_callback,
|
|
.uuid.Char_UUID_16 = FIRMWARE_REVISION_UUID,
|
|
.uuid_type = UUID_TYPE_16,
|
|
.char_properties = CHAR_PROP_READ,
|
|
.security_permissions = ATTR_PERMISSION_AUTHEN_READ,
|
|
.gatt_evt_mask = GATT_DONT_NOTIFY_EVENTS,
|
|
.is_variable = CHAR_VALUE_LEN_CONSTANT},
|
|
[DevInfoSvcGattCharacteristicSoftwareRev] =
|
|
{.name = "Software Revision",
|
|
.data_prop_type = FlipperGattCharacteristicDataCallback,
|
|
.data.callback.context = &dev_info_svc,
|
|
.data.callback.fn = dev_info_char_software_rev_callback,
|
|
.uuid.Char_UUID_16 = SOFTWARE_REVISION_UUID,
|
|
.uuid_type = UUID_TYPE_16,
|
|
.char_properties = CHAR_PROP_READ,
|
|
.security_permissions = ATTR_PERMISSION_AUTHEN_READ,
|
|
.gatt_evt_mask = GATT_DONT_NOTIFY_EVENTS,
|
|
.is_variable = CHAR_VALUE_LEN_CONSTANT},
|
|
[DevInfoSvcGattCharacteristicRpcVersion] = {
|
|
.name = "RPC Version",
|
|
.data_prop_type = FlipperGattCharacteristicDataFixed,
|
|
.data.fixed.length = sizeof(dev_info_rpc_version) - 1,
|
|
.data.fixed.ptr = (const uint8_t*)&dev_info_rpc_version,
|
|
.uuid.Char_UUID_128 = DEV_INVO_RPC_VERSION_UID,
|
|
.uuid_type = UUID_TYPE_128,
|
|
.char_properties = CHAR_PROP_READ,
|
|
.security_permissions = ATTR_PERMISSION_AUTHEN_READ,
|
|
.gatt_evt_mask = GATT_DONT_NOTIFY_EVENTS,
|
|
.is_variable = CHAR_VALUE_LEN_CONSTANT}};
|
|
|
|
void dev_info_svc_start() {
|
|
dev_info_svc = malloc(sizeof(DevInfoSvc));
|
|
dev_info_svc->version_string = furi_string_alloc_printf(
|
|
"%s %s %s %s",
|
|
version_get_githash(NULL),
|
|
version_get_gitbranch(NULL),
|
|
version_get_gitbranchnum(NULL),
|
|
version_get_builddate(NULL));
|
|
snprintf(
|
|
dev_info_svc->hardware_revision,
|
|
sizeof(dev_info_svc->hardware_revision),
|
|
"%d",
|
|
version_get_target(NULL));
|
|
tBleStatus status;
|
|
|
|
// Add Device Information Service
|
|
uint16_t uuid = DEVICE_INFORMATION_SERVICE_UUID;
|
|
status = aci_gatt_add_service(
|
|
UUID_TYPE_16,
|
|
(Service_UUID_t*)&uuid,
|
|
PRIMARY_SERVICE,
|
|
1 + 2 * DevInfoSvcGattCharacteristicCount,
|
|
&dev_info_svc->service_handle);
|
|
if(status) {
|
|
FURI_LOG_E(TAG, "Failed to add Device Information Service: %d", status);
|
|
}
|
|
|
|
for(size_t i = 0; i < DevInfoSvcGattCharacteristicCount; i++) {
|
|
flipper_gatt_characteristic_init(
|
|
dev_info_svc->service_handle,
|
|
&dev_info_svc_chars[i],
|
|
&dev_info_svc->characteristics[i]);
|
|
flipper_gatt_characteristic_update(
|
|
dev_info_svc->service_handle, &dev_info_svc->characteristics[i], NULL);
|
|
}
|
|
}
|
|
|
|
void dev_info_svc_stop() {
|
|
tBleStatus status;
|
|
if(dev_info_svc) {
|
|
// Delete service characteristics
|
|
for(size_t i = 0; i < DevInfoSvcGattCharacteristicCount; i++) {
|
|
flipper_gatt_characteristic_delete(
|
|
dev_info_svc->service_handle, &dev_info_svc->characteristics[i]);
|
|
}
|
|
|
|
// Delete service
|
|
status = aci_gatt_del_service(dev_info_svc->service_handle);
|
|
if(status) {
|
|
FURI_LOG_E(TAG, "Failed to delete device info service: %d", status);
|
|
}
|
|
|
|
furi_string_free(dev_info_svc->version_string);
|
|
free(dev_info_svc);
|
|
dev_info_svc = NULL;
|
|
}
|
|
}
|
|
|
|
bool dev_info_svc_is_started() {
|
|
return dev_info_svc != NULL;
|
|
}
|