mirror of
https://github.com/DarkFlippers/unleashed-firmware
synced 2024-11-23 21:13:16 +00:00
Revert "Temp fix for older iOS v9-14 HID support"
This reverts commit 016abe3273
.
This commit is contained in:
parent
b51b8eb843
commit
2c3b5ca43d
1 changed files with 110 additions and 154 deletions
|
@ -1,22 +1,31 @@
|
|||
#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;
|
||||
uint16_t man_name_char_handle;
|
||||
uint16_t serial_num_char_handle;
|
||||
uint16_t firmware_rev_char_handle;
|
||||
uint16_t software_rev_char_handle;
|
||||
uint16_t rpc_version_char_handle;
|
||||
FlipperGattCharacteristicInstance characteristics[DevInfoSvcGattCharacteristicCount];
|
||||
FuriString* version_string;
|
||||
char hardware_revision[4];
|
||||
char hardware_revision[DEVICE_INFO_HARDWARE_REV_SIZE];
|
||||
} DevInfoSvc;
|
||||
|
||||
static DevInfoSvc* dev_info_svc = NULL;
|
||||
|
@ -25,8 +34,86 @@ 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 const uint8_t dev_info_rpc_version_uuid[] =
|
||||
{0x33, 0xa9, 0xb5, 0x3e, 0x87, 0x5d, 0x1a, 0x8e, 0xc8, 0x47, 0x5e, 0xae, 0x6d, 0x66, 0xf6, 0x03};
|
||||
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 = sizeof(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));
|
||||
|
@ -46,132 +133,22 @@ void dev_info_svc_start() {
|
|||
// 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, 11, &dev_info_svc->service_handle);
|
||||
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);
|
||||
}
|
||||
|
||||
// Add characteristics
|
||||
uuid = MANUFACTURER_NAME_UUID;
|
||||
status = aci_gatt_add_char(
|
||||
for(size_t i = 0; i < DevInfoSvcGattCharacteristicCount; i++) {
|
||||
flipper_gatt_characteristic_init(
|
||||
dev_info_svc->service_handle,
|
||||
UUID_TYPE_16,
|
||||
(Char_UUID_t*)&uuid,
|
||||
strlen(dev_info_man_name),
|
||||
CHAR_PROP_READ,
|
||||
ATTR_PERMISSION_AUTHEN_READ,
|
||||
GATT_DONT_NOTIFY_EVENTS,
|
||||
10,
|
||||
CHAR_VALUE_LEN_CONSTANT,
|
||||
&dev_info_svc->man_name_char_handle);
|
||||
if(status) {
|
||||
FURI_LOG_E(TAG, "Failed to add manufacturer name char: %d", status);
|
||||
}
|
||||
uuid = SERIAL_NUMBER_UUID;
|
||||
status = aci_gatt_add_char(
|
||||
dev_info_svc->service_handle,
|
||||
UUID_TYPE_16,
|
||||
(Char_UUID_t*)&uuid,
|
||||
strlen(dev_info_serial_num),
|
||||
CHAR_PROP_READ,
|
||||
ATTR_PERMISSION_AUTHEN_READ,
|
||||
GATT_DONT_NOTIFY_EVENTS,
|
||||
10,
|
||||
CHAR_VALUE_LEN_CONSTANT,
|
||||
&dev_info_svc->serial_num_char_handle);
|
||||
if(status) {
|
||||
FURI_LOG_E(TAG, "Failed to add serial number char: %d", status);
|
||||
}
|
||||
uuid = FIRMWARE_REVISION_UUID;
|
||||
status = aci_gatt_add_char(
|
||||
dev_info_svc->service_handle,
|
||||
UUID_TYPE_16,
|
||||
(Char_UUID_t*)&uuid,
|
||||
strlen(dev_info_svc->hardware_revision),
|
||||
CHAR_PROP_READ,
|
||||
ATTR_PERMISSION_AUTHEN_READ,
|
||||
GATT_DONT_NOTIFY_EVENTS,
|
||||
10,
|
||||
CHAR_VALUE_LEN_CONSTANT,
|
||||
&dev_info_svc->firmware_rev_char_handle);
|
||||
if(status) {
|
||||
FURI_LOG_E(TAG, "Failed to add firmware revision char: %d", status);
|
||||
}
|
||||
uuid = SOFTWARE_REVISION_UUID;
|
||||
status = aci_gatt_add_char(
|
||||
dev_info_svc->service_handle,
|
||||
UUID_TYPE_16,
|
||||
(Char_UUID_t*)&uuid,
|
||||
furi_string_size(dev_info_svc->version_string),
|
||||
CHAR_PROP_READ,
|
||||
ATTR_PERMISSION_AUTHEN_READ,
|
||||
GATT_DONT_NOTIFY_EVENTS,
|
||||
10,
|
||||
CHAR_VALUE_LEN_CONSTANT,
|
||||
&dev_info_svc->software_rev_char_handle);
|
||||
if(status) {
|
||||
FURI_LOG_E(TAG, "Failed to add software revision char: %d", status);
|
||||
}
|
||||
status = aci_gatt_add_char(
|
||||
dev_info_svc->service_handle,
|
||||
UUID_TYPE_128,
|
||||
(const Char_UUID_t*)dev_info_rpc_version_uuid,
|
||||
strlen(dev_info_rpc_version),
|
||||
CHAR_PROP_READ,
|
||||
ATTR_PERMISSION_AUTHEN_READ,
|
||||
GATT_DONT_NOTIFY_EVENTS,
|
||||
10,
|
||||
CHAR_VALUE_LEN_CONSTANT,
|
||||
&dev_info_svc->rpc_version_char_handle);
|
||||
if(status) {
|
||||
FURI_LOG_E(TAG, "Failed to add rpc version characteristic: %d", status);
|
||||
}
|
||||
|
||||
// Update characteristics
|
||||
status = aci_gatt_update_char_value(
|
||||
dev_info_svc->service_handle,
|
||||
dev_info_svc->man_name_char_handle,
|
||||
0,
|
||||
strlen(dev_info_man_name),
|
||||
(uint8_t*)dev_info_man_name);
|
||||
if(status) {
|
||||
FURI_LOG_E(TAG, "Failed to update manufacturer name char: %d", status);
|
||||
}
|
||||
status = aci_gatt_update_char_value(
|
||||
dev_info_svc->service_handle,
|
||||
dev_info_svc->serial_num_char_handle,
|
||||
0,
|
||||
strlen(dev_info_serial_num),
|
||||
(uint8_t*)dev_info_serial_num);
|
||||
if(status) {
|
||||
FURI_LOG_E(TAG, "Failed to update serial number char: %d", status);
|
||||
}
|
||||
status = aci_gatt_update_char_value(
|
||||
dev_info_svc->service_handle,
|
||||
dev_info_svc->firmware_rev_char_handle,
|
||||
0,
|
||||
strlen(dev_info_svc->hardware_revision),
|
||||
(uint8_t*)dev_info_svc->hardware_revision);
|
||||
if(status) {
|
||||
FURI_LOG_E(TAG, "Failed to update firmware revision char: %d", status);
|
||||
}
|
||||
status = aci_gatt_update_char_value(
|
||||
dev_info_svc->service_handle,
|
||||
dev_info_svc->software_rev_char_handle,
|
||||
0,
|
||||
furi_string_size(dev_info_svc->version_string),
|
||||
(uint8_t*)furi_string_get_cstr(dev_info_svc->version_string));
|
||||
if(status) {
|
||||
FURI_LOG_E(TAG, "Failed to update software revision char: %d", status);
|
||||
}
|
||||
status = aci_gatt_update_char_value(
|
||||
dev_info_svc->service_handle,
|
||||
dev_info_svc->rpc_version_char_handle,
|
||||
0,
|
||||
strlen(dev_info_rpc_version),
|
||||
(uint8_t*)dev_info_rpc_version);
|
||||
if(status) {
|
||||
FURI_LOG_E(TAG, "Failed to update rpc version char: %d", status);
|
||||
&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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -180,30 +157,9 @@ void dev_info_svc_stop() {
|
|||
if(dev_info_svc) {
|
||||
furi_string_free(dev_info_svc->version_string);
|
||||
// Delete service characteristics
|
||||
status =
|
||||
aci_gatt_del_char(dev_info_svc->service_handle, dev_info_svc->man_name_char_handle);
|
||||
if(status) {
|
||||
FURI_LOG_E(TAG, "Failed to delete manufacturer name char: %d", status);
|
||||
}
|
||||
status =
|
||||
aci_gatt_del_char(dev_info_svc->service_handle, dev_info_svc->serial_num_char_handle);
|
||||
if(status) {
|
||||
FURI_LOG_E(TAG, "Failed to delete serial number char: %d", status);
|
||||
}
|
||||
status = aci_gatt_del_char(
|
||||
dev_info_svc->service_handle, dev_info_svc->firmware_rev_char_handle);
|
||||
if(status) {
|
||||
FURI_LOG_E(TAG, "Failed to delete firmware revision char: %d", status);
|
||||
}
|
||||
status = aci_gatt_del_char(
|
||||
dev_info_svc->service_handle, dev_info_svc->software_rev_char_handle);
|
||||
if(status) {
|
||||
FURI_LOG_E(TAG, "Failed to delete software revision char: %d", status);
|
||||
}
|
||||
status =
|
||||
aci_gatt_del_char(dev_info_svc->service_handle, dev_info_svc->rpc_version_char_handle);
|
||||
if(status) {
|
||||
FURI_LOG_E(TAG, "Failed to delete rpc version char: %d", status);
|
||||
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);
|
||||
|
|
Loading…
Reference in a new issue