Skip to content

Commit 0140a72

Browse files
[ESP32] Add a configurable device type for commissionable advertising. (#35344)
* add commissionable device type config * Restyled by autopep8 * update the function logic --------- Co-authored-by: Restyled.io <commits@restyled.io>
1 parent c7a0d02 commit 0140a72

5 files changed

+29
-0
lines changed

scripts/tools/generate_esp32_chip_factory_bin.py

+9
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,11 @@ class Product_Color_Enum(Enum):
209209
'encoding': 'string',
210210
'value': None,
211211
},
212+
'device-type': {
213+
'type': 'data',
214+
'encoding': 'u32',
215+
'value': None,
216+
},
212217
}
213218

214219

@@ -372,6 +377,8 @@ def populate_factory_data(args, spake2p_params):
372377
FACTORY_DATA['product-url']['value'] = args.product_url
373378
if args.product_label:
374379
FACTORY_DATA['product-label']['value'] = args.product_label
380+
if args.device_type is not None:
381+
FACTORY_DATA['device-type']['value'] = args.device_type
375382

376383
# SupportedModes are stored as multiple entries
377384
# - sm-sz/<ep> : number of supported modes for the endpoint
@@ -554,6 +561,8 @@ def any_base_int(s): return int(s, 0)
554561
parser.add_argument("--product-label", type=str, help='human readable product label')
555562
parser.add_argument("--product-url", type=str, help='link to product specific web page')
556563

564+
parser.add_argument("--device-type", type=any_base_int, help='commissionable device type')
565+
557566
parser.add_argument('-s', '--size', type=any_base_int, default=0x6000,
558567
help='The size of the partition.bin, default: 0x6000')
559568
parser.add_argument('--target', default='esp32',

src/platform/ESP32/ConfigurationManagerImpl.cpp

+17
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,23 @@ CHIP_ERROR ConfigurationManagerImpl::GetLocationCapability(uint8_t & location)
269269
#endif // CONFIG_ENABLE_ESP32_LOCATIONCAPABILITY
270270
}
271271

272+
CHIP_ERROR ConfigurationManagerImpl::GetDeviceTypeId(uint32_t & deviceType)
273+
{
274+
uint32_t value = 0;
275+
CHIP_ERROR err = ReadConfigValue(ESP32Config::kConfigKey_PrimaryDeviceType, value);
276+
277+
if (err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND)
278+
{
279+
deviceType = CHIP_DEVICE_CONFIG_DEVICE_TYPE;
280+
}
281+
else
282+
{
283+
deviceType = value;
284+
}
285+
286+
return CHIP_NO_ERROR;
287+
}
288+
272289
CHIP_ERROR ConfigurationManagerImpl::StoreCountryCode(const char * code, size_t codeLen)
273290
{
274291
// As per spec, codeLen has to be 2

src/platform/ESP32/ConfigurationManagerImpl.h

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImp
5858
CHIP_ERROR GetSoftwareVersionString(char * buf, size_t bufSize);
5959
CHIP_ERROR GetSoftwareVersion(uint32_t & softwareVer) override;
6060
CHIP_ERROR GetLocationCapability(uint8_t & location) override;
61+
CHIP_ERROR GetDeviceTypeId(uint32_t & deviceType) override;
6162
static ConfigurationManagerImpl & GetDefaultInstance();
6263

6364
// Set the country code to esp_phy layer and also store it to NVS

src/platform/ESP32/ESP32Config.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ const ESP32Config::Key ESP32Config::kConfigKey_ProductFinish = { kConfig
8181
const ESP32Config::Key ESP32Config::kConfigKey_ProductColor = { kConfigNamespace_ChipFactory, "product-color" };
8282
const ESP32Config::Key ESP32Config::kConfigKey_PartNumber = { kConfigNamespace_ChipFactory, "part-number" };
8383
const ESP32Config::Key ESP32Config::kConfigKey_LocationCapability = { kConfigNamespace_ChipFactory, "loc-capability" };
84+
const ESP32Config::Key ESP32Config::kConfigKey_PrimaryDeviceType = { kConfigNamespace_ChipFactory, "device-type" };
8485

8586
// Keys stored in the chip-config namespace
8687
const ESP32Config::Key ESP32Config::kConfigKey_ServiceConfig = { kConfigNamespace_ChipConfig, "service-config" };

src/platform/ESP32/ESP32Config.h

+1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ class ESP32Config
8383
static const Key kConfigKey_ProductFinish;
8484
static const Key kConfigKey_ProductColor;
8585
static const Key kConfigKey_LocationCapability;
86+
static const Key kConfigKey_PrimaryDeviceType;
8687

8788
// CHIP Config keys
8889
static const Key kConfigKey_ServiceConfig;

0 commit comments

Comments
 (0)