2022-01-13 08:50:51 +00:00
|
|
|
# SPDX-FileCopyrightText: 2018-2022 Espressif Systems (Shanghai) CO LTD
|
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
2018-07-30 16:10:10 +00:00
|
|
|
#
|
|
|
|
|
|
|
|
# APIs for interpreting and creating protobuf packets for `custom-config` protocomm endpoint
|
|
|
|
|
|
|
|
from __future__ import print_function
|
|
|
|
|
2021-01-26 02:49:01 +00:00
|
|
|
import utils
|
|
|
|
from future.utils import tobytes
|
2018-07-30 16:10:10 +00:00
|
|
|
|
2018-12-04 12:46:48 +00:00
|
|
|
|
2018-07-30 16:10:10 +00:00
|
|
|
def print_verbose(security_ctx, data):
|
|
|
|
if (security_ctx.verbose):
|
2021-01-26 02:49:01 +00:00
|
|
|
print('++++ ' + data + ' ++++')
|
2018-12-04 12:46:48 +00:00
|
|
|
|
2018-07-30 16:10:10 +00:00
|
|
|
|
2020-01-05 18:06:48 +00:00
|
|
|
def custom_data_request(security_ctx, data):
|
|
|
|
# Encrypt the custom data
|
2020-11-11 03:31:17 +00:00
|
|
|
enc_cmd = security_ctx.encrypt_data(tobytes(data))
|
2021-01-26 02:49:01 +00:00
|
|
|
print_verbose(security_ctx, 'Client -> Device (CustomData cmd) ' + utils.str_to_hexstr(enc_cmd))
|
2020-01-05 18:06:48 +00:00
|
|
|
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 02:49:01 +00:00
|
|
|
print('CustomData response: ' + str(decrypt))
|
2020-01-05 18:06:48 +00:00
|
|
|
return 0
|