2022-01-13 14:20:51 +05:30
|
|
|
# SPDX-FileCopyrightText: 2018-2022 Espressif Systems (Shanghai) CO LTD
|
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
2018-07-30 21:40:10 +05:30
|
|
|
#
|
|
|
|
|
|
|
|
# APIs for interpreting and creating protobuf packets for `custom-config` protocomm endpoint
|
|
|
|
|
|
|
|
from __future__ import print_function
|
|
|
|
|
2021-01-26 10:49:01 +08:00
|
|
|
import utils
|
|
|
|
from future.utils import tobytes
|
2018-07-30 21:40:10 +05:30
|
|
|
|
2018-12-04 13:46:48 +01:00
|
|
|
|
2018-07-30 21:40:10 +05:30
|
|
|
def print_verbose(security_ctx, data):
|
|
|
|
if (security_ctx.verbose):
|
2021-01-26 10:49:01 +08:00
|
|
|
print('++++ ' + data + ' ++++')
|
2018-12-04 13:46:48 +01:00
|
|
|
|
2018-07-30 21:40:10 +05:30
|
|
|
|
2020-01-05 23:36:48 +05:30
|
|
|
def custom_data_request(security_ctx, data):
|
|
|
|
# Encrypt the custom data
|
2020-11-11 11:31:17 +08:00
|
|
|
enc_cmd = security_ctx.encrypt_data(tobytes(data))
|
2021-01-26 10:49:01 +08:00
|
|
|
print_verbose(security_ctx, 'Client -> Device (CustomData cmd) ' + utils.str_to_hexstr(enc_cmd))
|
2020-01-05 23:36:48 +05:30
|
|
|
return enc_cmd
|
|
|
|
|
|
|
|
|
|
|
|
def custom_data_response(security_ctx, response_data):
|
|
|
|
# Decrypt response packet
|
|
|
|
decrypt = security_ctx.decrypt_data(tobytes(response_data))
|
2021-01-26 10:49:01 +08:00
|
|
|
print('CustomData response: ' + str(decrypt))
|
2020-01-05 23:36:48 +05:30
|
|
|
return 0
|