[FL-1409] Flipper name in reports (#507)
* USB CDC descriptor: join product name from two strings * add f5 support * USB CDC descriptor: use constant device name across all device * BLE: use device name in advertising and model * BLE: truncate device name Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
parent
22ffd6204b
commit
5fc533385b
@ -31,7 +31,13 @@ const uint8_t api_hal_version_get_hw_connect();
|
||||
const uint32_t api_hal_version_get_hw_timestamp();
|
||||
|
||||
/** Get pointer to target name */
|
||||
const char * api_hal_version_get_name_ptr();
|
||||
const char* api_hal_version_get_name_ptr();
|
||||
|
||||
/** Get pointer to target device name */
|
||||
const char* api_hal_version_get_device_name_ptr();
|
||||
|
||||
/** Get pointer to target ble local device name */
|
||||
const char* api_hal_version_get_ble_local_device_name_ptr();
|
||||
|
||||
/**
|
||||
* Get address of version structure of bootloader, stored in chip flash.
|
||||
|
@ -67,7 +67,6 @@
|
||||
#define USBD_LANGID_STRING 1033
|
||||
#define USBD_MANUFACTURER_STRING "Flipper Devices Inc."
|
||||
#define USBD_PID 22336
|
||||
#define USBD_PRODUCT_STRING "Flipper Control Virtual ComPort"
|
||||
#define USBD_CONFIGURATION_STRING "CDC Config"
|
||||
#define USBD_INTERFACE_STRING "CDC Interface"
|
||||
/* USER CODE BEGIN PRIVATE_DEFINES */
|
||||
@ -79,7 +78,6 @@
|
||||
*/
|
||||
|
||||
/* USER CODE BEGIN 0 */
|
||||
|
||||
/* USER CODE END 0 */
|
||||
|
||||
/** @defgroup USBD_DESC_Private_Macros USBD_DESC_Private_Macros
|
||||
@ -247,14 +245,7 @@ uint8_t * USBD_CDC_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length
|
||||
*/
|
||||
uint8_t * USBD_CDC_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
||||
{
|
||||
if(speed == 0)
|
||||
{
|
||||
USBD_GetString((uint8_t *)USBD_PRODUCT_STRING, USBD_StrDesc, length);
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_GetString((uint8_t *)USBD_PRODUCT_STRING, USBD_StrDesc, length);
|
||||
}
|
||||
USBD_GetString((uint8_t*)api_hal_version_get_device_name_ptr(), USBD_StrDesc, length);
|
||||
return USBD_StrDesc;
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,10 @@
|
||||
#include <api-hal-version.h>
|
||||
#include <stm32wbxx.h>
|
||||
#include <stm32wbxx_ll_rtc.h>
|
||||
#include <stdio.h>
|
||||
#include "ble.h"
|
||||
|
||||
#define FLIPPER_NAME_LENGTH 8
|
||||
|
||||
typedef struct {
|
||||
uint8_t version;
|
||||
@ -8,15 +12,35 @@ typedef struct {
|
||||
uint8_t body;
|
||||
uint8_t connect;
|
||||
uint32_t timestamp;
|
||||
char name[8];
|
||||
char name[FLIPPER_NAME_LENGTH];
|
||||
} ApiHalVersionOTP;
|
||||
|
||||
#define FLIPPER_ARRAY_NAME_LENGTH (FLIPPER_NAME_LENGTH + 1)
|
||||
// BLE symbol + "Flipper Zero " + name
|
||||
#define FLIPPER_DEVICE_NAME_LENGTH (1 + 8 + FLIPPER_ARRAY_NAME_LENGTH)
|
||||
|
||||
// Initialiazed from OTP, used to guarantee zero terminated C string
|
||||
static char flipper_name[9];
|
||||
static char flipper_name[FLIPPER_ARRAY_NAME_LENGTH];
|
||||
static char flipper_device_name[FLIPPER_DEVICE_NAME_LENGTH];
|
||||
|
||||
void api_hal_version_init() {
|
||||
char* name = ((ApiHalVersionOTP*)OTP_AREA_BASE)->name;
|
||||
strlcpy(flipper_name, name, 9);
|
||||
strlcpy(flipper_name, name, FLIPPER_ARRAY_NAME_LENGTH);
|
||||
|
||||
if(api_hal_version_get_name_ptr() != NULL) {
|
||||
snprintf(
|
||||
flipper_device_name,
|
||||
FLIPPER_DEVICE_NAME_LENGTH,
|
||||
"xFlipper %s",
|
||||
flipper_name);
|
||||
} else {
|
||||
snprintf(
|
||||
flipper_device_name,
|
||||
FLIPPER_DEVICE_NAME_LENGTH,
|
||||
"xFlipper");
|
||||
}
|
||||
|
||||
flipper_device_name[0] = AD_TYPE_COMPLETE_LOCAL_NAME;
|
||||
}
|
||||
|
||||
bool api_hal_version_do_i_belong_here() {
|
||||
@ -43,10 +67,18 @@ const uint32_t api_hal_version_get_hw_timestamp() {
|
||||
return ((ApiHalVersionOTP*)OTP_AREA_BASE)->timestamp;
|
||||
}
|
||||
|
||||
const char * api_hal_version_get_name_ptr() {
|
||||
const char* api_hal_version_get_name_ptr() {
|
||||
return *flipper_name == 0xFFU ? NULL : flipper_name;
|
||||
}
|
||||
|
||||
const char* api_hal_version_get_device_name_ptr() {
|
||||
return flipper_device_name + 1;
|
||||
}
|
||||
|
||||
const char* api_hal_version_get_ble_local_device_name_ptr() {
|
||||
return flipper_device_name;
|
||||
}
|
||||
|
||||
const struct Version* api_hal_version_get_fw_version(void) {
|
||||
return version_get();
|
||||
}
|
||||
@ -56,7 +88,6 @@ const struct Version* api_hal_version_get_boot_version(void) {
|
||||
return 0;
|
||||
#else
|
||||
/* Backup register which points to structure in flash memory */
|
||||
return (const struct Version*) LL_RTC_BAK_GetRegister(RTC, LL_RTC_BKP_DR1);
|
||||
return (const struct Version*)LL_RTC_BAK_GetRegister(RTC, LL_RTC_BKP_DR1);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -74,7 +74,6 @@ PLACE_IN_SECTION("TAG_OTA_START") const uint32_t MagicKeywordAddress = (uint32_t
|
||||
PLACE_IN_SECTION("BLE_APP_CONTEXT") static BleApplicationContext_t BleApplicationContext;
|
||||
PLACE_IN_SECTION("BLE_APP_CONTEXT") static uint16_t AdvIntervalMin, AdvIntervalMax;
|
||||
|
||||
static const char local_name[] = { AD_TYPE_COMPLETE_LOCAL_NAME ,'F','L','I','P','P', 'E', 'R'};
|
||||
uint8_t manuf_data[14] = {
|
||||
sizeof(manuf_data)-1, AD_TYPE_MANUFACTURER_SPECIFIC_DATA,
|
||||
0x01/*SKD version */,
|
||||
@ -539,9 +538,9 @@ static void Ble_Hci_Gap_Gatt_Init() {
|
||||
|
||||
if (role > 0)
|
||||
{
|
||||
const char *name = "Flipper";
|
||||
const char *name = api_hal_version_get_device_name_ptr();
|
||||
aci_gap_init(role, 0,
|
||||
APPBLE_GAP_DEVICE_NAME_LENGTH,
|
||||
strlen(name),
|
||||
&gap_service_handle, &gap_dev_name_char_handle, &gap_appearance_char_handle);
|
||||
|
||||
if (aci_gatt_update_char_value(gap_service_handle, gap_dev_name_char_handle, 0, strlen(name), (uint8_t *) name))
|
||||
@ -640,6 +639,9 @@ static void Adv_Request(APP_BLE_ConnStatus_t New_Status)
|
||||
}
|
||||
|
||||
BleApplicationContext.Device_Connection_Status = New_Status;
|
||||
|
||||
const char* name = api_hal_version_get_ble_local_device_name_ptr();
|
||||
|
||||
/* Start Fast or Low Power Advertising */
|
||||
ret = aci_gap_set_discoverable(
|
||||
ADV_IND,
|
||||
@ -647,8 +649,8 @@ static void Adv_Request(APP_BLE_ConnStatus_t New_Status)
|
||||
Max_Inter,
|
||||
PUBLIC_ADDR,
|
||||
NO_WHITE_LIST_USE, /* use white list */
|
||||
sizeof(local_name),
|
||||
(uint8_t*) &local_name,
|
||||
strlen(name),
|
||||
(uint8_t*)name,
|
||||
BleApplicationContext.BleApplicationContext_legacy.advtServUUIDlen,
|
||||
BleApplicationContext.BleApplicationContext_legacy.advtServUUID,
|
||||
0,
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include "app_common.h"
|
||||
#include "ble.h"
|
||||
#include "dis_app.h"
|
||||
#include <api-hal-version.h>
|
||||
|
||||
#if ((BLE_CFG_DIS_SYSTEM_ID != 0) || (CFG_MENU_DEVICE_INFORMATION != 0))
|
||||
static const uint8_t system_id[BLE_CFG_DIS_SYSTEM_ID_LEN_MAX] = {
|
||||
@ -57,8 +58,9 @@ void DISAPP_Init(void) {
|
||||
* @param pPData
|
||||
* @return
|
||||
*/
|
||||
dis_information_data.pPayload = (uint8_t*)DISAPP_MODEL_NUMBER;
|
||||
dis_information_data.Length = sizeof(DISAPP_MODEL_NUMBER);
|
||||
const char* name = api_hal_version_get_device_name_ptr();
|
||||
dis_information_data.pPayload = (uint8_t*)name;
|
||||
dis_information_data.Length = strlen(name) + 1;
|
||||
DIS_UpdateChar(MODEL_NUMBER_UUID, &dis_information_data);
|
||||
#endif
|
||||
|
||||
|
@ -5,7 +5,7 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
#define DISAPP_MANUFACTURER_NAME "Flipperdevice Inc."
|
||||
#define DISAPP_MODEL_NUMBER "FlipperZero"
|
||||
//#define DISAPP_MODEL_NUMBER "FlipperZero"
|
||||
#define DISAPP_SERIAL_NUMBER "1.0"
|
||||
#define DISAPP_HARDWARE_REVISION_NUMBER "1.0"
|
||||
#define DISAPP_FIRMWARE_REVISION_NUMBER TARGET
|
||||
|
@ -67,7 +67,6 @@
|
||||
#define USBD_LANGID_STRING 1033
|
||||
#define USBD_MANUFACTURER_STRING "Flipper Devices Inc."
|
||||
#define USBD_PID 22336
|
||||
#define USBD_PRODUCT_STRING "Flipper Control Virtual ComPort"
|
||||
#define USBD_CONFIGURATION_STRING "CDC Config"
|
||||
#define USBD_INTERFACE_STRING "CDC Interface"
|
||||
/* USER CODE BEGIN PRIVATE_DEFINES */
|
||||
@ -79,7 +78,6 @@
|
||||
*/
|
||||
|
||||
/* USER CODE BEGIN 0 */
|
||||
|
||||
/* USER CODE END 0 */
|
||||
|
||||
/** @defgroup USBD_DESC_Private_Macros USBD_DESC_Private_Macros
|
||||
@ -247,14 +245,7 @@ uint8_t * USBD_CDC_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length
|
||||
*/
|
||||
uint8_t * USBD_CDC_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
||||
{
|
||||
if(speed == 0)
|
||||
{
|
||||
USBD_GetString((uint8_t *)USBD_PRODUCT_STRING, USBD_StrDesc, length);
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_GetString((uint8_t *)USBD_PRODUCT_STRING, USBD_StrDesc, length);
|
||||
}
|
||||
USBD_GetString((uint8_t*)api_hal_version_get_device_name_ptr(), USBD_StrDesc, length);
|
||||
return USBD_StrDesc;
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,10 @@
|
||||
#include <api-hal-version.h>
|
||||
#include <stm32wbxx.h>
|
||||
#include <stm32wbxx_ll_rtc.h>
|
||||
#include <stdio.h>
|
||||
#include "ble.h"
|
||||
|
||||
#define FLIPPER_NAME_LENGTH 8
|
||||
|
||||
typedef struct {
|
||||
uint8_t version;
|
||||
@ -8,15 +12,35 @@ typedef struct {
|
||||
uint8_t body;
|
||||
uint8_t connect;
|
||||
uint32_t timestamp;
|
||||
char name[8];
|
||||
char name[FLIPPER_NAME_LENGTH];
|
||||
} ApiHalVersionOTP;
|
||||
|
||||
#define FLIPPER_ARRAY_NAME_LENGTH (FLIPPER_NAME_LENGTH + 1)
|
||||
// BLE symbol + "Flipper " + name
|
||||
#define FLIPPER_DEVICE_NAME_LENGTH (1 + 8 + FLIPPER_ARRAY_NAME_LENGTH)
|
||||
|
||||
// Initialiazed from OTP, used to guarantee zero terminated C string
|
||||
static char flipper_name[9];
|
||||
static char flipper_name[FLIPPER_ARRAY_NAME_LENGTH];
|
||||
static char flipper_device_name[FLIPPER_DEVICE_NAME_LENGTH];
|
||||
|
||||
void api_hal_version_init() {
|
||||
char* name = ((ApiHalVersionOTP*)OTP_AREA_BASE)->name;
|
||||
strlcpy(flipper_name, name, 9);
|
||||
strlcpy(flipper_name, name, FLIPPER_ARRAY_NAME_LENGTH);
|
||||
|
||||
if(api_hal_version_get_name_ptr() != NULL) {
|
||||
snprintf(
|
||||
flipper_device_name,
|
||||
FLIPPER_DEVICE_NAME_LENGTH,
|
||||
"xFlipper %s",
|
||||
flipper_name);
|
||||
} else {
|
||||
snprintf(
|
||||
flipper_device_name,
|
||||
FLIPPER_DEVICE_NAME_LENGTH,
|
||||
"xFlipper");
|
||||
}
|
||||
|
||||
flipper_device_name[0] = AD_TYPE_COMPLETE_LOCAL_NAME;
|
||||
}
|
||||
|
||||
bool api_hal_version_do_i_belong_here() {
|
||||
@ -43,10 +67,18 @@ const uint32_t api_hal_version_get_hw_timestamp() {
|
||||
return ((ApiHalVersionOTP*)OTP_AREA_BASE)->timestamp;
|
||||
}
|
||||
|
||||
const char * api_hal_version_get_name_ptr() {
|
||||
const char* api_hal_version_get_name_ptr() {
|
||||
return *flipper_name == 0xFFU ? NULL : flipper_name;
|
||||
}
|
||||
|
||||
const char* api_hal_version_get_device_name_ptr() {
|
||||
return flipper_device_name + 1;
|
||||
}
|
||||
|
||||
const char* api_hal_version_get_ble_local_device_name_ptr() {
|
||||
return flipper_device_name;
|
||||
}
|
||||
|
||||
const struct Version* api_hal_version_get_fw_version(void) {
|
||||
return version_get();
|
||||
}
|
||||
@ -56,7 +88,6 @@ const struct Version* api_hal_version_get_boot_version(void) {
|
||||
return 0;
|
||||
#else
|
||||
/* Backup register which points to structure in flash memory */
|
||||
return (const struct Version*) LL_RTC_BAK_GetRegister(RTC, LL_RTC_BKP_DR1);
|
||||
return (const struct Version*)LL_RTC_BAK_GetRegister(RTC, LL_RTC_BKP_DR1);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -43,7 +43,7 @@ typedef struct {
|
||||
uint8_t Advertising_mgr_timer_Id;
|
||||
} BleApplicationContext_t;
|
||||
|
||||
#define APPBLE_GAP_DEVICE_NAME_LENGTH 7
|
||||
|
||||
#define FAST_ADV_TIMEOUT (30*1000*1000/CFG_TS_TICK_VAL) /**< 30s */
|
||||
#define INITIAL_ADV_TIMEOUT (60*1000*1000/CFG_TS_TICK_VAL) /**< 60s */
|
||||
|
||||
@ -74,7 +74,6 @@ PLACE_IN_SECTION("TAG_OTA_START") const uint32_t MagicKeywordAddress = (uint32_t
|
||||
PLACE_IN_SECTION("BLE_APP_CONTEXT") static BleApplicationContext_t BleApplicationContext;
|
||||
PLACE_IN_SECTION("BLE_APP_CONTEXT") static uint16_t AdvIntervalMin, AdvIntervalMax;
|
||||
|
||||
static const char local_name[] = { AD_TYPE_COMPLETE_LOCAL_NAME ,'F','L','I','P','P', 'E', 'R'};
|
||||
uint8_t manuf_data[14] = {
|
||||
sizeof(manuf_data)-1, AD_TYPE_MANUFACTURER_SPECIFIC_DATA,
|
||||
0x01/*SKD version */,
|
||||
@ -539,9 +538,9 @@ static void Ble_Hci_Gap_Gatt_Init() {
|
||||
|
||||
if (role > 0)
|
||||
{
|
||||
const char *name = "Flipper";
|
||||
const char *name = api_hal_version_get_device_name_ptr();
|
||||
aci_gap_init(role, 0,
|
||||
APPBLE_GAP_DEVICE_NAME_LENGTH,
|
||||
strlen(name),
|
||||
&gap_service_handle, &gap_dev_name_char_handle, &gap_appearance_char_handle);
|
||||
|
||||
if (aci_gatt_update_char_value(gap_service_handle, gap_dev_name_char_handle, 0, strlen(name), (uint8_t *) name))
|
||||
@ -640,6 +639,9 @@ static void Adv_Request(APP_BLE_ConnStatus_t New_Status)
|
||||
}
|
||||
|
||||
BleApplicationContext.Device_Connection_Status = New_Status;
|
||||
|
||||
const char* name = api_hal_version_get_ble_local_device_name_ptr();
|
||||
|
||||
/* Start Fast or Low Power Advertising */
|
||||
ret = aci_gap_set_discoverable(
|
||||
ADV_IND,
|
||||
@ -647,8 +649,8 @@ static void Adv_Request(APP_BLE_ConnStatus_t New_Status)
|
||||
Max_Inter,
|
||||
PUBLIC_ADDR,
|
||||
NO_WHITE_LIST_USE, /* use white list */
|
||||
sizeof(local_name),
|
||||
(uint8_t*) &local_name,
|
||||
strlen(name),
|
||||
(uint8_t*)name,
|
||||
BleApplicationContext.BleApplicationContext_legacy.advtServUUIDlen,
|
||||
BleApplicationContext.BleApplicationContext_legacy.advtServUUID,
|
||||
0,
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include "app_common.h"
|
||||
#include "ble.h"
|
||||
#include "dis_app.h"
|
||||
#include <api-hal-version.h>
|
||||
|
||||
#if ((BLE_CFG_DIS_SYSTEM_ID != 0) || (CFG_MENU_DEVICE_INFORMATION != 0))
|
||||
static const uint8_t system_id[BLE_CFG_DIS_SYSTEM_ID_LEN_MAX] = {
|
||||
@ -57,8 +58,9 @@ void DISAPP_Init(void) {
|
||||
* @param pPData
|
||||
* @return
|
||||
*/
|
||||
dis_information_data.pPayload = (uint8_t*)DISAPP_MODEL_NUMBER;
|
||||
dis_information_data.Length = sizeof(DISAPP_MODEL_NUMBER);
|
||||
const char* name = api_hal_version_get_device_name_ptr();
|
||||
dis_information_data.pPayload = (uint8_t*)name;
|
||||
dis_information_data.Length = strlen(name) + 1;
|
||||
DIS_UpdateChar(MODEL_NUMBER_UUID, &dis_information_data);
|
||||
#endif
|
||||
|
||||
|
@ -5,7 +5,7 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
#define DISAPP_MANUFACTURER_NAME "Flipperdevice Inc."
|
||||
#define DISAPP_MODEL_NUMBER "FlipperZero"
|
||||
//#define DISAPP_MODEL_NUMBER "FlipperZero"
|
||||
#define DISAPP_SERIAL_NUMBER "1.0"
|
||||
#define DISAPP_HARDWARE_REVISION_NUMBER "1.0"
|
||||
#define DISAPP_FIRMWARE_REVISION_NUMBER TARGET
|
||||
|
Loading…
Reference in New Issue
Block a user