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