From fc12f91a64c204711020ace5cb5f1d7e4a085acc Mon Sep 17 00:00:00 2001 From: its your bedtime <23366927+itsyourbedtime@users.noreply.github.com> Date: Fri, 12 Mar 2021 12:18:13 +0300 Subject: [PATCH] [FL-378] Update usb descriptor to display unique flipper name (#373) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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: あく --- assets/assets.py | 25 ++++++++++++++++++- .../targets/api-hal-include/api-hal-version.h | 2 ++ firmware/targets/f4/Inc/usbd_desc.h | 2 +- firmware/targets/f4/Src/usbd_desc.c | 14 +++++++---- firmware/targets/f4/api-hal/api-hal-version.c | 6 +++++ firmware/targets/f5/Inc/usbd_desc.h | 2 +- firmware/targets/f5/Src/usbd_desc.c | 14 +++++++---- firmware/targets/f5/api-hal/api-hal-version.c | 6 +++++ 8 files changed, 58 insertions(+), 13 deletions(-) diff --git a/assets/assets.py b/assets/assets.py index 271734b7..eba1e274 100755 --- a/assets/assets.py +++ b/assets/assets.py @@ -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( - "timestamp; } + +const char * api_hal_version_get_name_ptr() { + char * name = ((ApiHalVersionOTP*)OTP_AREA_BASE)->name; + return *name == 0xFFU ? NULL : name; +} diff --git a/firmware/targets/f5/Inc/usbd_desc.h b/firmware/targets/f5/Inc/usbd_desc.h index 2a5bea5c..d5362ee2 100644 --- a/firmware/targets/f5/Inc/usbd_desc.h +++ b/firmware/targets/f5/Inc/usbd_desc.h @@ -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 */ diff --git a/firmware/targets/f5/Src/usbd_desc.c b/firmware/targets/f5/Src/usbd_desc.c index 821be8ee..745147c2 100644 --- a/firmware/targets/f5/Src/usbd_desc.c +++ b/firmware/targets/f5/Src/usbd_desc.c @@ -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 */ diff --git a/firmware/targets/f5/api-hal/api-hal-version.c b/firmware/targets/f5/api-hal/api-hal-version.c index 4fb1ecfe..1e0b1d31 100644 --- a/firmware/targets/f5/api-hal/api-hal-version.c +++ b/firmware/targets/f5/api-hal/api-hal-version.c @@ -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; +}