Skip to content

Commit

Permalink
Revert "[ESP32] Fix few attributes with fixed quality in DeviceInfoPr…
Browse files Browse the repository at this point in the history
…ovider (project-chip#32893) (project-chip#33138)"

This reverts commit 5b0afc7.

Signed-off-by: Adrian Gielniewski <adrian.gielniewski@nordicsemi.no>
  • Loading branch information
adigie committed Nov 28, 2024
1 parent 9d20537 commit b9902ab
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 345 deletions.
1 change: 0 additions & 1 deletion docs/guides/esp32/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,3 @@ example on ESP32 series of SoCs
- [Matter OTA](ota.md)
- [Generating and Using ESP Secure Cert Partition](secure_cert_partition.md)
- [BLE Settings](ble_settings.md)
- [Providers](providers.md)
10 changes: 7 additions & 3 deletions docs/guides/esp32/factory_data.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,13 @@ Following data can be added to the manufacturing partition using
- Serial Number
- Unique identifier

- Supported modes
- Note: As per spec at max size of label should be 64 and `\0` will be
added at the end.
- Device information
- Fixed Labels
- Supported locales
- Supported calendar types
- Supported modes
- Note: As per spec at max size of label should be 64 and `\0` will be
added at the end.

### Configuration Options

Expand Down
76 changes: 0 additions & 76 deletions docs/guides/esp32/providers.md

This file was deleted.

124 changes: 124 additions & 0 deletions scripts/tools/generate_esp32_chip_factory_bin.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@

import argparse
import base64
import enum
import logging
import os
import sys
from types import SimpleNamespace

import cryptography.x509
from bitarray import bitarray
from bitarray.util import ba2int
from esp_secure_cert.tlv_format import generate_partition_ds, generate_partition_no_ds, tlv_priv_key_t, tlv_priv_key_type_t

CHIP_TOPDIR = os.path.dirname(os.path.realpath(__file__))[:-len(os.path.join('scripts', 'tools'))]
Expand Down Expand Up @@ -149,16 +152,84 @@
'encoding': 'hex2bin',
'value': None,
},
# DeviceInfoProvider
'cal-types': {
'type': 'data',
'encoding': 'u32',
'value': None,
},
'locale-sz': {
'type': 'data',
'encoding': 'u32',
'value': None,
},

# Other device info provider keys are dynamically generated
# in the respective functions.
}


class CalendarTypes(enum.Enum):
Buddhist = 0
Chinese = 1
Coptic = 2
Ethiopian = 3
Gregorian = 4
Hebrew = 5
Indian = 6
Islamic = 7
Japanese = 8
Korean = 9
Persian = 10
Taiwanese = 11


# Supported Calendar types is stored as a bit array in one uint32_t.
def calendar_types_to_uint32(calendar_types):
result = bitarray(32, endian='little')
result.setall(0)
for calendar_type in calendar_types:
try:
result[CalendarTypes[calendar_type].value] = 1
except KeyError:
logging.error('Unknown calendar type: %s', calendar_type)
logging.error('Supported calendar types: %s', ', '.join(CalendarTypes.__members__))
sys.exit(1)
return ba2int(result)


def ishex(s):
try:
_ = int(s, 16)
return True
except ValueError:
return False

# get_fixed_label_dict() converts the list of strings to per endpoint dictionaries.
# example input : ['0/orientation/up', '1/orientation/down', '2/orientation/down']
# example output : {'0': [{'orientation': 'up'}], '1': [{'orientation': 'down'}], '2': [{'orientation': 'down'}]}


def get_fixed_label_dict(fixed_labels):
fl_dict = {}
for fl in fixed_labels:
_l = fl.split('/')

if len(_l) != 3:
logging.error('Invalid fixed label: %s', fl)
sys.exit(1)

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)):
logging.error('Invalid fixed label: %s', fl)
sys.exit(1)

if _l[0] not in fl_dict.keys():
fl_dict[_l[0]] = list()

fl_dict[_l[0]].append({_l[1]: _l[2]})

return fl_dict

# get_supported_modes_dict() converts the list of strings to per endpoint dictionaries.
# example with semantic tags
# input : ['0/label1/1/"1\0x8000, 2\0x8000" 1/label2/1/"1\0x8000, 2\0x8000"']
Expand Down Expand Up @@ -302,6 +373,52 @@ def populate_factory_data(args, spake2p_params):
if args.hw_ver_str:
FACTORY_DATA['hw-ver-str']['value'] = args.hw_ver_str

if args.calendar_types:
FACTORY_DATA['cal-types']['value'] = calendar_types_to_uint32(args.calendar_types)

# Supported locale is stored as multiple entries, key format: "locale/<index>, example key: "locale/0"
if args.locales:
FACTORY_DATA['locale-sz']['value'] = len(args.locales)

for i in range(len(args.locales)):
_locale = {
'type': 'data',
'encoding': 'string',
'value': args.locales[i]
}
FACTORY_DATA.update({'locale/{:x}'.format(i): _locale})

# Each endpoint can contains the fixed lables
# - fl-sz/<index> : number of fixed labels for the endpoint
# - fl-k/<ep>/<index> : fixed label key for the endpoint and index
# - fl-v/<ep>/<index> : fixed label value for the endpoint and index
if args.fixed_labels:
dict = get_fixed_label_dict(args.fixed_labels)
for key in dict.keys():
_sz = {
'type': 'data',
'encoding': 'u32',
'value': len(dict[key])
}
FACTORY_DATA.update({'fl-sz/{:x}'.format(int(key)): _sz})

for i in range(len(dict[key])):
entry = dict[key][i]

_label_key = {
'type': 'data',
'encoding': 'string',
'value': list(entry.keys())[0]
}
_label_value = {
'type': 'data',
'encoding': 'string',
'value': list(entry.values())[0]
}

FACTORY_DATA.update({'fl-k/{:x}/{:x}'.format(int(key), i): _label_key})
FACTORY_DATA.update({'fl-v/{:x}/{:x}'.format(int(key), i): _label_value})

# SupportedModes are stored as multiple entries
# - sm-sz/<ep> : number of supported modes for the endpoint
# - sm-label/<ep>/<index> : supported modes label key for the endpoint and index
Expand Down Expand Up @@ -467,6 +584,13 @@ def any_base_int(s): return int(s, 0)
help=('128-bit unique identifier for generating rotating device identifier, '
'provide 32-byte hex string, e.g. "1234567890abcdef1234567890abcdef"'))

# These will be used by DeviceInfoProvider
parser.add_argument('--calendar-types', nargs='+',
help=('List of supported calendar types.\nSupported Calendar Types: Buddhist, Chinese, Coptic, Ethiopian, '
'Gregorian, Hebrew, Indian, Islamic, Japanese, Korean, Persian, Taiwanese'))
parser.add_argument('--locales', nargs='+', help='List of supported locales, Language Tag as defined by BCP47, eg. en-US en-GB')
parser.add_argument('--fixed-labels', nargs='+',
help='List of fixed labels, eg: "0/orientation/up" "1/orientation/down" "2/orientation/down"')
parser.add_argument('--supported-modes', type=str, nargs='+', required=False,
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"')

Expand Down
2 changes: 0 additions & 2 deletions src/platform/ESP32/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,6 @@ static_library("ESP32") {
sources += [
"ESP32DeviceInfoProvider.cpp",
"ESP32DeviceInfoProvider.h",
"StaticESP32DeviceInfoProvider.cpp",
"StaticESP32DeviceInfoProvider.h",
]
}

Expand Down
122 changes: 0 additions & 122 deletions src/platform/ESP32/StaticESP32DeviceInfoProvider.cpp

This file was deleted.

Loading

0 comments on commit b9902ab

Please sign in to comment.