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

15 files changed

+84
-31
lines changed

bootloader/src/rtl872x/sources.mk

+1
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

+2
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

+2
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

+4
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

+2
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

+26-2
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

+8-2
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

+7-2
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

+7-2
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

+3
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)

system/src/ble_provisioning_mode_handler.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -129,15 +129,15 @@ int BleProvisioningModeHandler::cacheUserConfigurations() {
129129
LOG_DEBUG(TRACE, "Cache user's BLE configurations.");
130130
CHECK_FALSE(exited_, SYSTEM_ERROR_INVALID_STATE);
131131

132-
Vector<uint8_t> tempAdvData(BLE_MAX_ADV_DATA_LEN);
133-
Vector<uint8_t> tempSrData(BLE_MAX_ADV_DATA_LEN);
132+
Vector<uint8_t> tempAdvData(BLE_MAX_SUPPORTED_ADV_DATA_LEN);
133+
Vector<uint8_t> tempSrData(BLE_MAX_SUPPORTED_ADV_DATA_LEN);
134134

135135
// Advertising data set by user application
136-
size_t len = CHECK(hal_ble_gap_get_advertising_data(tempAdvData.data(), BLE_MAX_ADV_DATA_LEN, nullptr));
136+
size_t len = CHECK(hal_ble_gap_get_advertising_data(tempAdvData.data(), BLE_MAX_SUPPORTED_ADV_DATA_LEN, nullptr));
137137
tempAdvData.resize(len);
138138

139139
// Scan response data set by user application
140-
len = CHECK(hal_ble_gap_get_scan_response_data(tempSrData.data(), BLE_MAX_ADV_DATA_LEN, nullptr));
140+
len = CHECK(hal_ble_gap_get_scan_response_data(tempSrData.data(), BLE_MAX_SUPPORTED_ADV_DATA_LEN, nullptr));
141141
tempSrData.resize(len);
142142

143143
// Advertising and connection parameters set by user application

system/src/system_ble_prov.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@ using namespace particle::system;
3333
int system_ble_prov_mode(bool enabled, void* reserved) {
3434
SYSTEM_THREAD_CONTEXT_SYNC(system_ble_prov_mode(enabled, reserved));
3535
if (!HAL_Feature_Get(FEATURE_DISABLE_LISTENING_MODE)) {
36-
LOG(ERROR, "Listening mode is not disabled. Cannot use prov mode");
37-
return SYSTEM_ERROR_NOT_ALLOWED;
36+
if (enabled) {
37+
LOG(ERROR, "Provisioning mode not enabled, listening mode is not disabled");
38+
}
39+
return SYSTEM_ERROR_NOT_ALLOWED;
3840
}
3941
if (enabled) {
4042
CHECK_FALSE(BleProvisioningModeHandler::instance()->getProvModeStatus(), SYSTEM_ERROR_NONE);

user/applications/tinker/src/burnin_test.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,8 @@ bool BurninTest::testBleScan() {
296296
Log.info("Found %d beacons", count);
297297

298298
for (int ii = 0; ii < count; ii++) {
299-
uint8_t buf[BLE_MAX_ADV_DATA_LEN];
300-
size_t len = scanResults[ii].advertisingData().get(BleAdvertisingDataType::MANUFACTURER_SPECIFIC_DATA, buf, BLE_MAX_ADV_DATA_LEN);
299+
uint8_t buf[BLE_MAX_SUPPORTED_ADV_DATA_LEN];
300+
size_t len = scanResults[ii].advertisingData().get(BleAdvertisingDataType::MANUFACTURER_SPECIFIC_DATA, buf, sizeof(buf));
301301
Log.info("Beacon %d: rssi %d Advertising Data Len %u", ii, scanResults[ii].rssi(), len);
302302
if (len > 0) {
303303
Log.print("Advertising Data: ");

user/applications/tinker/src/fqc_test.cpp

+1-6
Original file line numberDiff line numberDiff line change
@@ -348,13 +348,8 @@ bool FqcTest::ioTest(JSONValue req) {
348348
uint16_t pinB = 0;
349349

350350
// Pick which set of pins to use based on hardware variant
351-
uint32_t model, variant, efuseReadAttempts = 0;
351+
uint32_t model, variant = 0;
352352
int result = hal_get_device_hw_model(&model, &variant, nullptr);
353-
while (result != SYSTEM_ERROR_NONE && efuseReadAttempts < 5) {
354-
Log.warn("Failed to read logical efuse: %d attempt: %lu", result, efuseReadAttempts);
355-
result = hal_get_device_hw_model(&model, &variant, nullptr);
356-
efuseReadAttempts++;
357-
}
358353

359354
if (result != SYSTEM_ERROR_NONE) {
360355
Log.error("Could not read logical efuse");

wiring/src/spark_wiring_ble.cpp

+11-9
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ size_t BleAdvertisingData::set(const uint8_t* buf, size_t len) {
575575
return selfData_.size();
576576
}
577577
selfData_.clear();
578-
len = std::min(len, (size_t)BLE_MAX_ADV_DATA_LEN_EXT);
578+
len = std::min(len, (size_t)BLE_MAX_SUPPORTED_ADV_DATA_LEN);
579579
CHECK_TRUE(selfData_.append(buf, len), 0);
580580
return selfData_.size();
581581
}
@@ -587,7 +587,7 @@ size_t BleAdvertisingData::set(const iBeacon& beacon) {
587587
return selfData_.size();
588588
}
589589

590-
CHECK_TRUE(selfData_.reserve(BLE_MAX_ADV_DATA_LEN), 0);
590+
CHECK_TRUE(selfData_.reserve(BLE_MAX_SUPPORTED_ADV_DATA_LEN), 0);
591591
selfData_.append(0x02);
592592
selfData_.append(BLE_SIG_AD_TYPE_FLAGS);
593593
selfData_.append(BLE_SIG_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE);
@@ -625,7 +625,7 @@ size_t BleAdvertisingData::append(BleAdvertisingDataType type, const uint8_t* bu
625625
size_t adsLen = locate(selfData_.data(), selfData_.size(), type, &offset);
626626
if (!force && adsLen > 0) {
627627
// Update the existing AD structure.
628-
if ((selfData_.size() - adsLen + len + 2) <= BLE_MAX_ADV_DATA_LEN_EXT) {
628+
if ((selfData_.size() - adsLen + len + 2) <= BLE_MAX_SUPPORTED_ADV_DATA_LEN) {
629629
// Firstly, remove the existing AD structure.
630630
selfData_.removeAt(offset, adsLen);
631631
// Secondly, Update the AD structure.
@@ -638,12 +638,14 @@ size_t BleAdvertisingData::append(BleAdvertisingDataType type, const uint8_t* bu
638638
selfData_.insert(offset + 2, buf, len);
639639
}
640640
}
641-
else if ((selfData_.size() + len + 2) <= BLE_MAX_ADV_DATA_LEN_EXT) {
641+
else if ((selfData_.size() + len + 2) <= BLE_MAX_SUPPORTED_ADV_DATA_LEN) {
642642
// Append the AD structure at the and of advertising data.
643643
CHECK_TRUE(selfData_.reserve(selfData_.size() + len + 2), selfData_.size());
644644
selfData_.append(len + 1);
645645
selfData_.append(static_cast<uint8_t>(type));
646646
selfData_.append(buf, len);
647+
} else {
648+
return SYSTEM_ERROR_TOO_LARGE;
647649
}
648650
return selfData_.size();
649651
}
@@ -665,7 +667,7 @@ size_t BleAdvertisingData::appendAppearance(ble_sig_appearance_t appearance) {
665667
}
666668

667669
size_t BleAdvertisingData::resize(size_t size) {
668-
selfData_.resize(std::min(size, (size_t)BLE_MAX_ADV_DATA_LEN_EXT));
670+
selfData_.resize(std::min(size, (size_t)BLE_MAX_SUPPORTED_ADV_DATA_LEN));
669671
return selfData_.size();
670672
}
671673

@@ -726,7 +728,7 @@ size_t BleAdvertisingData::deviceName(char* buf, size_t len) const {
726728

727729
String BleAdvertisingData::deviceName() const {
728730
String name;
729-
char buf[BLE_MAX_ADV_DATA_LEN];
731+
char buf[BLE_MAX_SUPPORTED_ADV_DATA_LEN];
730732
size_t len = deviceName(buf, sizeof(buf));
731733
if (len > 0) {
732734
for (size_t i = 0; i < len; i++) {
@@ -2264,7 +2266,7 @@ ssize_t BleLocalDevice::getScanResponseData(BleAdvertisingData* scanResponse) co
22642266
return SYSTEM_ERROR_INVALID_ARGUMENT;
22652267
}
22662268
scanResponse->clear();
2267-
CHECK_TRUE(scanResponse->resize(BLE_MAX_ADV_DATA_LEN), SYSTEM_ERROR_NO_MEMORY);
2269+
CHECK_TRUE(scanResponse->resize(BLE_MAX_SUPPORTED_ADV_DATA_LEN), SYSTEM_ERROR_NO_MEMORY);
22682270
size_t len = CHECK(hal_ble_gap_get_scan_response_data(scanResponse->data(), scanResponse->length(), nullptr));
22692271
scanResponse->resize(len);
22702272
return len;
@@ -2518,8 +2520,8 @@ class BleScanDelegator {
25182520
size_t filterCustomDatalen;
25192521
const uint8_t* filterCustomData = filter_.customData(&filterCustomDatalen);
25202522
if (filterCustomData != nullptr && filterCustomDatalen > 0) {
2521-
size_t srLen = result.scanResponse().get(BleAdvertisingDataType::MANUFACTURER_SPECIFIC_DATA, nullptr, BLE_MAX_ADV_DATA_LEN);
2522-
size_t advLen = result.advertisingData().get(BleAdvertisingDataType::MANUFACTURER_SPECIFIC_DATA, nullptr, BLE_MAX_ADV_DATA_LEN_EXT);
2523+
size_t srLen = result.scanResponse().get(BleAdvertisingDataType::MANUFACTURER_SPECIFIC_DATA, nullptr, BLE_MAX_SUPPORTED_ADV_DATA_LEN);
2524+
size_t advLen = result.advertisingData().get(BleAdvertisingDataType::MANUFACTURER_SPECIFIC_DATA, nullptr, BLE_MAX_SUPPORTED_ADV_DATA_LEN);
25232525
if (srLen != filterCustomDatalen && advLen != filterCustomDatalen) {
25242526
LOG_DEBUG(TRACE, "Custom data mismatched.");
25252527
return false;

0 commit comments

Comments
 (0)