[FL-378] Update usb descriptor to display unique flipper name (#373)
* update usb descriptor to display unique flipper name * added flip_ prefix for usb descriptor, updated manufacturer string * include name in ApiHalVersionOTP struct, update assets.py Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
parent
f002f117fd
commit
fc12f91a64
@ -6,6 +6,7 @@ import subprocess
|
|||||||
import io
|
import io
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
import re
|
||||||
import struct
|
import struct
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
@ -79,6 +80,7 @@ class Assets:
|
|||||||
self.parser_otp.add_argument(
|
self.parser_otp.add_argument(
|
||||||
"--connect", type=int, help="Connect", required=True
|
"--connect", type=int, help="Connect", required=True
|
||||||
)
|
)
|
||||||
|
self.parser_otp.add_argument("--name", type=str, help="Name", required=True)
|
||||||
self.parser_otp.add_argument("file", help="Output file")
|
self.parser_otp.add_argument("file", help="Output file")
|
||||||
self.parser_otp.set_defaults(func=self.otp)
|
self.parser_otp.set_defaults(func=self.otp)
|
||||||
# logging
|
# logging
|
||||||
@ -101,13 +103,34 @@ class Assets:
|
|||||||
|
|
||||||
def otp(self):
|
def otp(self):
|
||||||
self.logger.debug(f"Generating OTP")
|
self.logger.debug(f"Generating OTP")
|
||||||
|
|
||||||
|
if self.args.name:
|
||||||
|
name = re.sub(
|
||||||
|
"[^a-zA-Z0-9.]", "", self.args.name
|
||||||
|
) # Filter all special characters
|
||||||
|
name = list(
|
||||||
|
map(str, map(ord, name[0:8]))
|
||||||
|
) # Strip to 8 chars and map to ascii codes
|
||||||
|
while len(name) < 8:
|
||||||
|
name.append("0")
|
||||||
|
|
||||||
|
n1, n2, n3, n4, n5, n6, n7, n8 = map(int, name)
|
||||||
|
|
||||||
data = struct.pack(
|
data = struct.pack(
|
||||||
"<BBBBL",
|
"<BBBBLBBBBBBBB",
|
||||||
self.args.version,
|
self.args.version,
|
||||||
self.args.firmware,
|
self.args.firmware,
|
||||||
self.args.body,
|
self.args.body,
|
||||||
self.args.connect,
|
self.args.connect,
|
||||||
int(datetime.datetime.now().timestamp()),
|
int(datetime.datetime.now().timestamp()),
|
||||||
|
n1,
|
||||||
|
n2,
|
||||||
|
n3,
|
||||||
|
n4,
|
||||||
|
n5,
|
||||||
|
n6,
|
||||||
|
n7,
|
||||||
|
n8,
|
||||||
)
|
)
|
||||||
open(self.args.file, "wb").write(data)
|
open(self.args.file, "wb").write(data)
|
||||||
|
|
||||||
|
@ -20,6 +20,8 @@ const uint8_t api_hal_version_get_hw_connect();
|
|||||||
|
|
||||||
const uint32_t api_hal_version_get_hw_timestamp();
|
const uint32_t api_hal_version_get_hw_timestamp();
|
||||||
|
|
||||||
|
const char * api_hal_version_get_name_ptr();
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -51,7 +51,7 @@
|
|||||||
#define DEVICE_ID2 (UID_BASE + 0x4)
|
#define DEVICE_ID2 (UID_BASE + 0x4)
|
||||||
#define DEVICE_ID3 (UID_BASE + 0x8)
|
#define DEVICE_ID3 (UID_BASE + 0x8)
|
||||||
|
|
||||||
#define USB_SIZ_STRING_SERIAL 0x1A
|
#define USB_SIZ_STRING_SERIAL 0x1E
|
||||||
|
|
||||||
/* USER CODE BEGIN EXPORTED_CONSTANTS */
|
/* USER CODE BEGIN EXPORTED_CONSTANTS */
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
#include "usbd_core.h"
|
#include "usbd_core.h"
|
||||||
#include "usbd_desc.h"
|
#include "usbd_desc.h"
|
||||||
#include "usbd_conf.h"
|
#include "usbd_conf.h"
|
||||||
|
#include "api-hal-version.h"
|
||||||
/* USER CODE BEGIN INCLUDE */
|
/* USER CODE BEGIN INCLUDE */
|
||||||
|
|
||||||
/* USER CODE END INCLUDE */
|
/* USER CODE END INCLUDE */
|
||||||
@ -65,12 +65,11 @@
|
|||||||
|
|
||||||
#define USBD_VID 1155
|
#define USBD_VID 1155
|
||||||
#define USBD_LANGID_STRING 1033
|
#define USBD_LANGID_STRING 1033
|
||||||
#define USBD_MANUFACTURER_STRING "Flipper"
|
#define USBD_MANUFACTURER_STRING "Flipper Devices Inc."
|
||||||
#define USBD_PID 22336
|
#define USBD_PID 22336
|
||||||
#define USBD_PRODUCT_STRING "Flipper Control Virtual ComPort"
|
#define USBD_PRODUCT_STRING "Flipper Control Virtual ComPort"
|
||||||
#define USBD_CONFIGURATION_STRING "CDC Config"
|
#define USBD_CONFIGURATION_STRING "CDC Config"
|
||||||
#define USBD_INTERFACE_STRING "CDC Interface"
|
#define USBD_INTERFACE_STRING "CDC Interface"
|
||||||
|
|
||||||
/* USER CODE BEGIN PRIVATE_DEFINES */
|
/* USER CODE BEGIN PRIVATE_DEFINES */
|
||||||
|
|
||||||
/* USER CODE END PRIVATE_DEFINES */
|
/* USER CODE END PRIVATE_DEFINES */
|
||||||
@ -285,8 +284,13 @@ uint8_t * USBD_CDC_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length
|
|||||||
|
|
||||||
/* Update the serial number string descriptor with the data from the unique
|
/* Update the serial number string descriptor with the data from the unique
|
||||||
* ID */
|
* ID */
|
||||||
|
if(api_hal_version_get_name_ptr()){
|
||||||
|
char buffer[14] = "flip_";
|
||||||
|
strncat(buffer, api_hal_version_get_name_ptr(), 8);
|
||||||
|
USBD_GetString((uint8_t*) buffer, USBD_StringSerial, length);
|
||||||
|
} else {
|
||||||
Get_SerialNum();
|
Get_SerialNum();
|
||||||
|
}
|
||||||
/* USER CODE BEGIN USBD_CDC_SerialStrDescriptor */
|
/* USER CODE BEGIN USBD_CDC_SerialStrDescriptor */
|
||||||
|
|
||||||
/* USER CODE END USBD_CDC_SerialStrDescriptor */
|
/* USER CODE END USBD_CDC_SerialStrDescriptor */
|
||||||
|
@ -7,6 +7,7 @@ typedef struct {
|
|||||||
uint8_t body;
|
uint8_t body;
|
||||||
uint8_t connect;
|
uint8_t connect;
|
||||||
uint32_t timestamp;
|
uint32_t timestamp;
|
||||||
|
char name[8];
|
||||||
} ApiHalVersionOTP;
|
} ApiHalVersionOTP;
|
||||||
|
|
||||||
bool api_hal_version_do_i_belong_here() {
|
bool api_hal_version_do_i_belong_here() {
|
||||||
@ -32,3 +33,8 @@ const uint8_t api_hal_version_get_hw_connect() {
|
|||||||
const uint32_t api_hal_version_get_hw_timestamp() {
|
const uint32_t api_hal_version_get_hw_timestamp() {
|
||||||
return ((ApiHalVersionOTP*)OTP_AREA_BASE)->timestamp;
|
return ((ApiHalVersionOTP*)OTP_AREA_BASE)->timestamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char * api_hal_version_get_name_ptr() {
|
||||||
|
char * name = ((ApiHalVersionOTP*)OTP_AREA_BASE)->name;
|
||||||
|
return *name == 0xFFU ? NULL : name;
|
||||||
|
}
|
||||||
|
@ -51,7 +51,7 @@
|
|||||||
#define DEVICE_ID2 (UID_BASE + 0x4)
|
#define DEVICE_ID2 (UID_BASE + 0x4)
|
||||||
#define DEVICE_ID3 (UID_BASE + 0x8)
|
#define DEVICE_ID3 (UID_BASE + 0x8)
|
||||||
|
|
||||||
#define USB_SIZ_STRING_SERIAL 0x1A
|
#define USB_SIZ_STRING_SERIAL 0x1E
|
||||||
|
|
||||||
/* USER CODE BEGIN EXPORTED_CONSTANTS */
|
/* USER CODE BEGIN EXPORTED_CONSTANTS */
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
#include "usbd_core.h"
|
#include "usbd_core.h"
|
||||||
#include "usbd_desc.h"
|
#include "usbd_desc.h"
|
||||||
#include "usbd_conf.h"
|
#include "usbd_conf.h"
|
||||||
|
#include "api-hal-version.h"
|
||||||
/* USER CODE BEGIN INCLUDE */
|
/* USER CODE BEGIN INCLUDE */
|
||||||
|
|
||||||
/* USER CODE END INCLUDE */
|
/* USER CODE END INCLUDE */
|
||||||
@ -65,12 +65,11 @@
|
|||||||
|
|
||||||
#define USBD_VID 1155
|
#define USBD_VID 1155
|
||||||
#define USBD_LANGID_STRING 1033
|
#define USBD_LANGID_STRING 1033
|
||||||
#define USBD_MANUFACTURER_STRING "Flipper"
|
#define USBD_MANUFACTURER_STRING "Flipper Devices Inc."
|
||||||
#define USBD_PID 22336
|
#define USBD_PID 22336
|
||||||
#define USBD_PRODUCT_STRING "Flipper Control Virtual ComPort"
|
#define USBD_PRODUCT_STRING "Flipper Control Virtual ComPort"
|
||||||
#define USBD_CONFIGURATION_STRING "CDC Config"
|
#define USBD_CONFIGURATION_STRING "CDC Config"
|
||||||
#define USBD_INTERFACE_STRING "CDC Interface"
|
#define USBD_INTERFACE_STRING "CDC Interface"
|
||||||
|
|
||||||
/* USER CODE BEGIN PRIVATE_DEFINES */
|
/* USER CODE BEGIN PRIVATE_DEFINES */
|
||||||
|
|
||||||
/* USER CODE END PRIVATE_DEFINES */
|
/* USER CODE END PRIVATE_DEFINES */
|
||||||
@ -285,8 +284,13 @@ uint8_t * USBD_CDC_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length
|
|||||||
|
|
||||||
/* Update the serial number string descriptor with the data from the unique
|
/* Update the serial number string descriptor with the data from the unique
|
||||||
* ID */
|
* ID */
|
||||||
|
if(api_hal_version_get_name_ptr()){
|
||||||
|
char buffer[14] = "flip_";
|
||||||
|
strncat(buffer, api_hal_version_get_name_ptr(), 8);
|
||||||
|
USBD_GetString((uint8_t*) buffer, USBD_StringSerial, length);
|
||||||
|
} else {
|
||||||
Get_SerialNum();
|
Get_SerialNum();
|
||||||
|
}
|
||||||
/* USER CODE BEGIN USBD_CDC_SerialStrDescriptor */
|
/* USER CODE BEGIN USBD_CDC_SerialStrDescriptor */
|
||||||
|
|
||||||
/* USER CODE END USBD_CDC_SerialStrDescriptor */
|
/* USER CODE END USBD_CDC_SerialStrDescriptor */
|
||||||
|
@ -7,6 +7,7 @@ typedef struct {
|
|||||||
uint8_t body;
|
uint8_t body;
|
||||||
uint8_t connect;
|
uint8_t connect;
|
||||||
uint32_t timestamp;
|
uint32_t timestamp;
|
||||||
|
char name[8];
|
||||||
} ApiHalVersionOTP;
|
} ApiHalVersionOTP;
|
||||||
|
|
||||||
bool api_hal_version_do_i_belong_here() {
|
bool api_hal_version_do_i_belong_here() {
|
||||||
@ -32,3 +33,8 @@ const uint8_t api_hal_version_get_hw_connect() {
|
|||||||
const uint32_t api_hal_version_get_hw_timestamp() {
|
const uint32_t api_hal_version_get_hw_timestamp() {
|
||||||
return ((ApiHalVersionOTP*)OTP_AREA_BASE)->timestamp;
|
return ((ApiHalVersionOTP*)OTP_AREA_BASE)->timestamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char * api_hal_version_get_name_ptr() {
|
||||||
|
char * name = ((ApiHalVersionOTP*)OTP_AREA_BASE)->name;
|
||||||
|
return *name == 0xFFU ? NULL : name;
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user