Skip to content

Commit 917ed35

Browse files
authored
Merge pull request #2779 from particle-iot/sc-128198/p2-photon2-names
Display Photon 2 instead of P2, dont allow extended advertising data on rtl platforms
2 parents 8281cdf + 80d4dab commit 917ed35

File tree

15 files changed

+84
-31
lines changed

15 files changed

+84
-31
lines changed

bootloader/src/rtl872x/sources.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ CSRC += $(call target_files,$(BOOTLOADER_MODULE_PATH)/../hal/src/rtl872x/littlef
2424
CPPSRC += $(call target_files,$(BOOTLOADER_MODULE_PATH)/../hal/shared/,filesystem.cpp)
2525
CPPSRC += $(call target_files,$(BOOTLOADER_MODULE_PATH)/../hal/src/rtl872x/,usbd_device.cpp)
2626
CPPSRC += $(call target_files,$(BOOTLOADER_MODULE_PATH)/../hal/src/rtl872x/,usbd_driver.cpp)
27+
CPPSRC += $(call target_files,$(BOOTLOADER_MODULE_PATH)/../hal/src/rtl872x/,device_code.cpp)
2728

2829
LDFLAGS += -T$(BOOTLOADER_SRC_PATH)/linker.ld
2930
LINKER_DEPS += $(BOOTLOADER_SRC_PATH)/linker.ld

hal/inc/device_code.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ int get_device_name(char* buf, size_t size);
5252

5353
int get_device_setup_code(char* code, size_t size);
5454

55+
int get_device_usb_name(char* buf, size_t size);
56+
5557
#ifdef __cplusplus
5658
}
5759
#endif

hal/src/nRF52840/ble_hal_impl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@
8585
#define BLE_MAX_ADV_DATA_LEN_EXT BLE_GAP_SCAN_BUFFER_EXTENDED_MAX_SUPPORTED
8686
#define BLE_MAX_ADV_DATA_LEN_EXT_CONNECTABLE BLE_GAP_ADV_SET_DATA_SIZE_EXTENDED_CONNECTABLE_MAX_SUPPORTED
8787

88+
#define BLE_MAX_SUPPORTED_ADV_DATA_LEN BLE_MAX_ADV_DATA_LEN_EXT
89+
8890
/* Connection Parameters limits */
8991
#define BLE_CONN_PARAMS_SLAVE_LATENCY_ERR 5
9092
#define BLE_CONN_PARAMS_TIMEOUT_ERR 100

hal/src/nRF52840/device_code.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,7 @@ int get_device_name(char* buf, size_t size) {
124124
}
125125
return nameSize;
126126
}
127+
128+
int get_device_usb_name(char* buf, size_t size) {
129+
return SYSTEM_ERROR_NOT_SUPPORTED;
130+
}

hal/src/rtl872x/ble_hal_impl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@
8181
/* Maximum length of advertising and scan response data */
8282
#define BLE_MAX_ADV_DATA_LEN 31
8383

84+
#define BLE_MAX_SUPPORTED_ADV_DATA_LEN BLE_MAX_ADV_DATA_LEN
85+
8486
/* Maximum length of the buffer to store scan report data */
8587
#define BLE_MAX_SCAN_REPORT_BUF_LEN 255 /* Must support extended length for CODED_PHY scanning */
8688

hal/src/rtl872x/device_code.cpp

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,17 @@ bool fetch_or_generate_setup_ssid(device_code_t* code) {
8585
return true;
8686
}
8787

88+
static const char * get_product_series_name(void) {
89+
#if PLATFORM_ID == PLATFORM_P2
90+
uint32_t model, variant = 0;
91+
hal_get_device_hw_model(&model, &variant, nullptr);
92+
if (variant == PLATFORM_P2_PHOTON_2) {
93+
return PRODUCT_SERIES_PHOTON2;
94+
}
95+
#endif
96+
return PRODUCT_SERIES;
97+
}
98+
8899
int get_device_name(char* buf, size_t size) {
89100
char dctName[DEVICE_NAME_DCT_SIZE] = {};
90101
int ret = dct_read_app_data_copy(DEVICE_NAME_DCT_OFFSET, dctName, DEVICE_NAME_DCT_SIZE);
@@ -101,8 +112,8 @@ int get_device_name(char* buf, size_t size) {
101112
return ret;
102113
}
103114
// Get platform name
104-
const char* const platform = PRODUCT_SERIES;
105-
nameSize = sizeof(PRODUCT_SERIES) - 1; // Exclude term. null
115+
const char* const platform = get_product_series_name();
116+
nameSize = strlen(platform); // Exclude term. null
106117
if (nameSize + SETUP_CODE_SIZE + 1 > DEVICE_NAME_MAX_SIZE) { // Reserve 1 character for '-'
107118
nameSize = DEVICE_NAME_MAX_SIZE - SETUP_CODE_SIZE - 1;
108119
}
@@ -122,3 +133,16 @@ int get_device_name(char* buf, size_t size) {
122133
}
123134
return nameSize;
124135
}
136+
137+
int get_device_usb_name(char* buf, size_t size) {
138+
#if PLATFORM_ID == PLATFORM_P2
139+
uint32_t model, variant = 0;
140+
hal_get_device_hw_model(&model, &variant, nullptr);
141+
if (variant == PLATFORM_P2_PHOTON_2) {
142+
snprintf(buf, size, "%s", HAL_PLATFORM_PHOTON2_USB_PRODUCT_STRING);
143+
return 0;
144+
}
145+
#endif
146+
snprintf(buf, size, "%s", HAL_PLATFORM_USB_PRODUCT_STRING);
147+
return 0;
148+
}

hal/src/rtl872x/usbd_cdc.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,13 @@
2828
#include <algorithm>
2929
#include <mutex>
3030
#include "service_debug.h"
31+
#include "device_code.h"
3132

3233
using namespace particle::usbd;
3334

3435
namespace {
3536

36-
const char DEFAULT_NAME[] = HAL_PLATFORM_USB_PRODUCT_STRING " " "USB Serial";
37+
const char DEFAULT_NAME_SUFFIX[] = "USB Serial";
3738
const uint8_t DUMMY_IN_EP = 0x8a;
3839

3940
} // anonymous
@@ -378,7 +379,12 @@ int CdcClassDriver::getString(unsigned id, uint16_t langId, uint8_t* buf, size_t
378379
if (name_) {
379380
return dev_->getUnicodeString(name_, strlen(name_), buf, length);
380381
}
381-
return dev_->getUnicodeString(DEFAULT_NAME, sizeof(DEFAULT_NAME) - 1, buf, length);
382+
383+
char usbName[64] = {};
384+
char strBuffer[256] = {};
385+
get_device_usb_name(usbName, sizeof(usbName));
386+
snprintf(strBuffer, sizeof(strBuffer), "%s %s", usbName, DEFAULT_NAME_SUFFIX);
387+
return dev_->getUnicodeString(strBuffer, strlen(strBuffer), buf, length);
382388
}
383389
return SYSTEM_ERROR_NOT_FOUND;
384390
}

hal/src/rtl872x/usbd_control.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@
1818
#include "usbd_control.h"
1919
#include <cstring>
2020
#include <algorithm>
21+
#include <cstdio>
2122
#include "usbd_wcid.h"
2223
#include "appender.h"
2324
#include "check.h"
25+
#include "device_code.h"
2426

2527
using namespace particle::usbd;
2628

@@ -217,8 +219,11 @@ int ControlInterfaceClassDriver::getConfigurationDescriptor(uint8_t* buf, size_t
217219

218220
int ControlInterfaceClassDriver::getString(unsigned id, uint16_t langId, uint8_t* buf, size_t length) {
219221
if (id == stringBase_) {
220-
const char str[] = HAL_PLATFORM_USB_PRODUCT_STRING " " "Control Interface";
221-
return dev_->getUnicodeString(str, strlen(str), buf, length);
222+
char usbName[64] = {};
223+
char strBuffer[256] = {};
224+
get_device_usb_name(usbName, sizeof(usbName));
225+
snprintf(strBuffer, sizeof(strBuffer), "%s %s", usbName, "Control Interface");
226+
return dev_->getUnicodeString(strBuffer, strlen(strBuffer), buf, length);
222227
}
223228
return SYSTEM_ERROR_NOT_FOUND;
224229
}

hal/src/rtl872x/usbd_device.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "usbd_wcid.h"
2626
#include <algorithm>
2727
#include "appender.h"
28+
#include "device_code.h"
2829

2930
using namespace particle::usbd;
3031

@@ -341,14 +342,18 @@ int Device::getString(unsigned id, uint16_t langId, uint8_t* buf, size_t len) {
341342
return getUnicodeString(HAL_PLATFORM_USB_MANUFACTURER_STRING, sizeof(HAL_PLATFORM_USB_MANUFACTURER_STRING) - 1, buf, len);
342343
}
343344
case STRING_IDX_PRODUCT: {
344-
return getUnicodeString(HAL_PLATFORM_USB_PRODUCT_STRING, sizeof(HAL_PLATFORM_USB_PRODUCT_STRING) - 1, buf, len);
345+
char usbName[64] = {};
346+
get_device_usb_name(usbName, sizeof(usbName));
347+
return getUnicodeString(usbName, strlen(usbName), buf, len);
345348
}
346349
case STRING_IDX_SERIAL: {
347350
char deviceid[HAL_DEVICE_ID_SIZE * 2] = {};
348351
return getUnicodeString(device_id_as_string(deviceid), sizeof(deviceid), buf, len);
349352
}
350353
case STRING_IDX_CONFIG: {
351-
return getUnicodeString(HAL_PLATFORM_USB_CONFIGURATION_STRING, sizeof(HAL_PLATFORM_USB_CONFIGURATION_STRING) - 1, buf, len);
354+
char usbName[64] = {};
355+
get_device_usb_name(usbName, sizeof(usbName));
356+
return getUnicodeString(usbName, strlen(usbName), buf, len);
352357
}
353358
case STRING_IDX_MSFT: {
354359
return getRawString((const char*)MSFT_STR_DESC, sizeof(MSFT_STR_DESC), buf, len);

hal/src/tron/hal_platform_config.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,14 @@
3030

3131
#if defined(MODULE_FUNCTION) && MODULE_FUNCTION != 2 // MOD_FUNC_BOOTLOADER
3232
#define HAL_PLATFORM_USB_PRODUCT_STRING "P2"
33+
#define HAL_PLATFORM_PHOTON2_USB_PRODUCT_STRING "Photon 2"
3334
#else
3435
#define HAL_PLATFORM_USB_PRODUCT_STRING "P2 DFU Mode"
36+
#define HAL_PLATFORM_PHOTON2_USB_PRODUCT_STRING "Photon 2 DFU Mode"
3537
#endif // defined(MODULE_FUNCTION) && MODULE_FUNCTION != 2 // MOD_FUNC_BOOTLOADER
3638

3739
#define PRODUCT_SERIES "P2"
40+
#define PRODUCT_SERIES_PHOTON2 "Photon 2"
3841

3942
#define PLATFORM_P2_MODEL_BARE_SOM_DEFAULT (0xffff)
4043
#define PLATFORM_P2_PHOTON_2 (0x0001)

0 commit comments

Comments
 (0)