[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:
its your bedtime 2021-03-12 12:18:13 +03:00 committed by GitHub
parent f002f117fd
commit fc12f91a64
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 58 additions and 13 deletions

View file

@ -6,6 +6,7 @@ import subprocess
import io
import os
import sys
import re
import struct
import datetime
@ -79,6 +80,7 @@ class Assets:
self.parser_otp.add_argument(
"--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.set_defaults(func=self.otp)
# logging
@ -101,13 +103,34 @@ class Assets:
def otp(self):
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(
"<BBBBL",
"<BBBBLBBBBBBBB",
self.args.version,
self.args.firmware,
self.args.body,
self.args.connect,
int(datetime.datetime.now().timestamp()),
n1,
n2,
n3,
n4,
n5,
n6,
n7,
n8,
)
open(self.args.file, "wb").write(data)

View file

@ -20,6 +20,8 @@ const uint8_t api_hal_version_get_hw_connect();
const uint32_t api_hal_version_get_hw_timestamp();
const char * api_hal_version_get_name_ptr();
#ifdef __cplusplus
}
#endif

View file

@ -51,7 +51,7 @@
#define DEVICE_ID2 (UID_BASE + 0x4)
#define DEVICE_ID3 (UID_BASE + 0x8)
#define USB_SIZ_STRING_SERIAL 0x1A
#define USB_SIZ_STRING_SERIAL 0x1E
/* USER CODE BEGIN EXPORTED_CONSTANTS */

View file

@ -23,7 +23,7 @@
#include "usbd_core.h"
#include "usbd_desc.h"
#include "usbd_conf.h"
#include "api-hal-version.h"
/* USER CODE BEGIN INCLUDE */
/* USER CODE END INCLUDE */
@ -65,12 +65,11 @@
#define USBD_VID 1155
#define USBD_LANGID_STRING 1033
#define USBD_MANUFACTURER_STRING "Flipper"
#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 */
/* 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
* ID */
Get_SerialNum();
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();
}
/* USER CODE BEGIN USBD_CDC_SerialStrDescriptor */
/* USER CODE END USBD_CDC_SerialStrDescriptor */

View file

@ -7,6 +7,7 @@ typedef struct {
uint8_t body;
uint8_t connect;
uint32_t timestamp;
char name[8];
} ApiHalVersionOTP;
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() {
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;
}

View file

@ -51,7 +51,7 @@
#define DEVICE_ID2 (UID_BASE + 0x4)
#define DEVICE_ID3 (UID_BASE + 0x8)
#define USB_SIZ_STRING_SERIAL 0x1A
#define USB_SIZ_STRING_SERIAL 0x1E
/* USER CODE BEGIN EXPORTED_CONSTANTS */

View file

@ -23,7 +23,7 @@
#include "usbd_core.h"
#include "usbd_desc.h"
#include "usbd_conf.h"
#include "api-hal-version.h"
/* USER CODE BEGIN INCLUDE */
/* USER CODE END INCLUDE */
@ -65,12 +65,11 @@
#define USBD_VID 1155
#define USBD_LANGID_STRING 1033
#define USBD_MANUFACTURER_STRING "Flipper"
#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 */
/* 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
* ID */
Get_SerialNum();
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();
}
/* USER CODE BEGIN USBD_CDC_SerialStrDescriptor */
/* USER CODE END USBD_CDC_SerialStrDescriptor */

View file

@ -7,6 +7,7 @@ typedef struct {
uint8_t body;
uint8_t connect;
uint32_t timestamp;
char name[8];
} ApiHalVersionOTP;
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() {
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;
}