Skip to content

Commit b9902ab

Browse files
committed
Revert "[ESP32] Fix few attributes with fixed quality in DeviceInfoProvider (project-chip#32893) (project-chip#33138)"
This reverts commit 5b0afc7. Signed-off-by: Adrian Gielniewski <adrian.gielniewski@nordicsemi.no>
1 parent 9d20537 commit b9902ab

7 files changed

+131
-345
lines changed

docs/guides/esp32/README.md

-1
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,3 @@ example on ESP32 series of SoCs
1818
- [Matter OTA](ota.md)
1919
- [Generating and Using ESP Secure Cert Partition](secure_cert_partition.md)
2020
- [BLE Settings](ble_settings.md)
21-
- [Providers](providers.md)

docs/guides/esp32/factory_data.md

+7-3
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,13 @@ Following data can be added to the manufacturing partition using
4444
- Serial Number
4545
- Unique identifier
4646

47-
- Supported modes
48-
- Note: As per spec at max size of label should be 64 and `\0` will be
49-
added at the end.
47+
- Device information
48+
- Fixed Labels
49+
- Supported locales
50+
- Supported calendar types
51+
- Supported modes
52+
- Note: As per spec at max size of label should be 64 and `\0` will be
53+
added at the end.
5054

5155
### Configuration Options
5256

docs/guides/esp32/providers.md

-76
This file was deleted.

scripts/tools/generate_esp32_chip_factory_bin.py

+124
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,15 @@
1818

1919
import argparse
2020
import base64
21+
import enum
2122
import logging
2223
import os
2324
import sys
2425
from types import SimpleNamespace
2526

2627
import cryptography.x509
28+
from bitarray import bitarray
29+
from bitarray.util import ba2int
2730
from esp_secure_cert.tlv_format import generate_partition_ds, generate_partition_no_ds, tlv_priv_key_t, tlv_priv_key_type_t
2831

2932
CHIP_TOPDIR = os.path.dirname(os.path.realpath(__file__))[:-len(os.path.join('scripts', 'tools'))]
@@ -149,16 +152,84 @@
149152
'encoding': 'hex2bin',
150153
'value': None,
151154
},
155+
# DeviceInfoProvider
156+
'cal-types': {
157+
'type': 'data',
158+
'encoding': 'u32',
159+
'value': None,
160+
},
161+
'locale-sz': {
162+
'type': 'data',
163+
'encoding': 'u32',
164+
'value': None,
165+
},
166+
167+
# Other device info provider keys are dynamically generated
168+
# in the respective functions.
152169
}
153170

154171

172+
class CalendarTypes(enum.Enum):
173+
Buddhist = 0
174+
Chinese = 1
175+
Coptic = 2
176+
Ethiopian = 3
177+
Gregorian = 4
178+
Hebrew = 5
179+
Indian = 6
180+
Islamic = 7
181+
Japanese = 8
182+
Korean = 9
183+
Persian = 10
184+
Taiwanese = 11
185+
186+
187+
# Supported Calendar types is stored as a bit array in one uint32_t.
188+
def calendar_types_to_uint32(calendar_types):
189+
result = bitarray(32, endian='little')
190+
result.setall(0)
191+
for calendar_type in calendar_types:
192+
try:
193+
result[CalendarTypes[calendar_type].value] = 1
194+
except KeyError:
195+
logging.error('Unknown calendar type: %s', calendar_type)
196+
logging.error('Supported calendar types: %s', ', '.join(CalendarTypes.__members__))
197+
sys.exit(1)
198+
return ba2int(result)
199+
200+
155201
def ishex(s):
156202
try:
157203
_ = int(s, 16)
158204
return True
159205
except ValueError:
160206
return False
161207

208+
# get_fixed_label_dict() converts the list of strings to per endpoint dictionaries.
209+
# example input : ['0/orientation/up', '1/orientation/down', '2/orientation/down']
210+
# example output : {'0': [{'orientation': 'up'}], '1': [{'orientation': 'down'}], '2': [{'orientation': 'down'}]}
211+
212+
213+
def get_fixed_label_dict(fixed_labels):
214+
fl_dict = {}
215+
for fl in fixed_labels:
216+
_l = fl.split('/')
217+
218+
if len(_l) != 3:
219+
logging.error('Invalid fixed label: %s', fl)
220+
sys.exit(1)
221+
222+
if not (ishex(_l[0]) and (len(_l[1]) > 0 and len(_l[1]) < 16) and (len(_l[2]) > 0 and len(_l[2]) < 16)):
223+
logging.error('Invalid fixed label: %s', fl)
224+
sys.exit(1)
225+
226+
if _l[0] not in fl_dict.keys():
227+
fl_dict[_l[0]] = list()
228+
229+
fl_dict[_l[0]].append({_l[1]: _l[2]})
230+
231+
return fl_dict
232+
162233
# get_supported_modes_dict() converts the list of strings to per endpoint dictionaries.
163234
# example with semantic tags
164235
# input : ['0/label1/1/"1\0x8000, 2\0x8000" 1/label2/1/"1\0x8000, 2\0x8000"']
@@ -302,6 +373,52 @@ def populate_factory_data(args, spake2p_params):
302373
if args.hw_ver_str:
303374
FACTORY_DATA['hw-ver-str']['value'] = args.hw_ver_str
304375

376+
if args.calendar_types:
377+
FACTORY_DATA['cal-types']['value'] = calendar_types_to_uint32(args.calendar_types)
378+
379+
# Supported locale is stored as multiple entries, key format: "locale/<index>, example key: "locale/0"
380+
if args.locales:
381+
FACTORY_DATA['locale-sz']['value'] = len(args.locales)
382+
383+
for i in range(len(args.locales)):
384+
_locale = {
385+
'type': 'data',
386+
'encoding': 'string',
387+
'value': args.locales[i]
388+
}
389+
FACTORY_DATA.update({'locale/{:x}'.format(i): _locale})
390+
391+
# Each endpoint can contains the fixed lables
392+
# - fl-sz/<index> : number of fixed labels for the endpoint
393+
# - fl-k/<ep>/<index> : fixed label key for the endpoint and index
394+
# - fl-v/<ep>/<index> : fixed label value for the endpoint and index
395+
if args.fixed_labels:
396+
dict = get_fixed_label_dict(args.fixed_labels)
397+
for key in dict.keys():
398+
_sz = {
399+
'type': 'data',
400+
'encoding': 'u32',
401+
'value': len(dict[key])
402+
}
403+
FACTORY_DATA.update({'fl-sz/{:x}'.format(int(key)): _sz})
404+
405+
for i in range(len(dict[key])):
406+
entry = dict[key][i]
407+
408+
_label_key = {
409+
'type': 'data',
410+
'encoding': 'string',
411+
'value': list(entry.keys())[0]
412+
}
413+
_label_value = {
414+
'type': 'data',
415+
'encoding': 'string',
416+
'value': list(entry.values())[0]
417+
}
418+
419+
FACTORY_DATA.update({'fl-k/{:x}/{:x}'.format(int(key), i): _label_key})
420+
FACTORY_DATA.update({'fl-v/{:x}/{:x}'.format(int(key), i): _label_value})
421+
305422
# SupportedModes are stored as multiple entries
306423
# - sm-sz/<ep> : number of supported modes for the endpoint
307424
# - sm-label/<ep>/<index> : supported modes label key for the endpoint and index
@@ -467,6 +584,13 @@ def any_base_int(s): return int(s, 0)
467584
help=('128-bit unique identifier for generating rotating device identifier, '
468585
'provide 32-byte hex string, e.g. "1234567890abcdef1234567890abcdef"'))
469586

587+
# These will be used by DeviceInfoProvider
588+
parser.add_argument('--calendar-types', nargs='+',
589+
help=('List of supported calendar types.\nSupported Calendar Types: Buddhist, Chinese, Coptic, Ethiopian, '
590+
'Gregorian, Hebrew, Indian, Islamic, Japanese, Korean, Persian, Taiwanese'))
591+
parser.add_argument('--locales', nargs='+', help='List of supported locales, Language Tag as defined by BCP47, eg. en-US en-GB')
592+
parser.add_argument('--fixed-labels', nargs='+',
593+
help='List of fixed labels, eg: "0/orientation/up" "1/orientation/down" "2/orientation/down"')
470594
parser.add_argument('--supported-modes', type=str, nargs='+', required=False,
471595
help='List of supported modes, eg: mode1/label1/ep/"tagValue1\\mfgCode, tagValue2\\mfgCode" mode2/label2/ep/"tagValue1\\mfgCode, tagValue2\\mfgCode" mode3/label3/ep/"tagValue1\\mfgCode, tagValue2\\mfgCode"')
472596

src/platform/ESP32/BUILD.gn

-2
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,6 @@ static_library("ESP32") {
182182
sources += [
183183
"ESP32DeviceInfoProvider.cpp",
184184
"ESP32DeviceInfoProvider.h",
185-
"StaticESP32DeviceInfoProvider.cpp",
186-
"StaticESP32DeviceInfoProvider.h",
187185
]
188186
}
189187

src/platform/ESP32/StaticESP32DeviceInfoProvider.cpp

-122
This file was deleted.

0 commit comments

Comments
 (0)