1#!/bin/sh 2 3# Copyright (c) 2021 Fraunhofer AISEC. See the COPYRIGHT 4# file at the top-level directory of this distribution. 5 6# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or 7# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license 8# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your 9# option. This file may not be copied, modified, or distributed 10# except according to those terms. 11 12# This script converts the cddl models into c source and header files 13 14ZCBOR="../externals/zcbor/zcbor/zcbor.py" 15MODELS_PATH="../cddl_models" 16SRC="../src/cbor" 17INC="../inc/cbor" 18INC_PATH_IN_C_FILES="cbor/" 19 20 21#clean up 22echo clean up... 23rm $INC/*.h 24rm $SRC/*.c 25 26echo Generating CBOR encoding and decoding functions... 27 28# 29# OSCORE 30# 31 32python3 $ZCBOR -c $MODELS_PATH/oscore_aad_array.cddl code -e -t aad_array --oc $SRC/oscore_aad_array.c --include-prefix $INC_PATH_IN_C_FILES --oh $INC/oscore_aad_array.h 33 34python3 $ZCBOR -c $MODELS_PATH/oscore_info.cddl code -e -t oscore_info --oc $SRC/oscore_info.c --include-prefix $INC_PATH_IN_C_FILES --oh $INC/oscore_info.h 35 36python3 $ZCBOR -c $MODELS_PATH/oscore_enc_structure.cddl code -e -t oscore_enc_structure --oc $SRC/oscore_enc_structure.c --include-prefix $INC_PATH_IN_C_FILES --oh $INC/oscore_enc_structure.h 37 38# 39# EDHOC 40# 41 42#encode message 1 43python3 $ZCBOR -c $MODELS_PATH/edhoc_message_1.cddl code -e -t message_1 --oc $SRC/edhoc_encode_message_1.c --include-prefix $INC_PATH_IN_C_FILES --oh $INC/edhoc_encode_message_1.h 44#decode message 1 45python3 $ZCBOR -c $MODELS_PATH/edhoc_message_1.cddl code -d -t message_1 --oc $SRC/edhoc_decode_message_1.c --include-prefix $INC_PATH_IN_C_FILES --oh $INC/edhoc_decode_message_1.h 46 47#encode message 2 48python3 $ZCBOR -c $MODELS_PATH/edhoc_message_2.cddl code -e -t m2 --oc $SRC/edhoc_encode_message_2.c --include-prefix $INC_PATH_IN_C_FILES --oh $INC/edhoc_encode_message_2.h 49#decode message 2 50python3 $ZCBOR -c $MODELS_PATH/edhoc_message_2.cddl code -d -t m2 --oc $SRC/edhoc_decode_message_2.c --include-prefix $INC_PATH_IN_C_FILES --oh $INC/edhoc_decode_message_2.h 51 52#encode message 3 53python3 $ZCBOR -c $MODELS_PATH/edhoc_message_3.cddl code -e -t m3 --oc $SRC/edhoc_encode_message_3.c --include-prefix $INC_PATH_IN_C_FILES --oh $INC/edhoc_encode_message_3.h 54 55#decode message 3 56python3 $ZCBOR -c $MODELS_PATH/edhoc_message_3.cddl code -d -t m3 --oc $SRC/edhoc_decode_message_3.c --include-prefix $INC_PATH_IN_C_FILES --oh $INC/edhoc_decode_message_3.h 57 58# encode error message 59python3 $ZCBOR -c $MODELS_PATH/edhoc_message_error.cddl code -e -t message_error --oc $SRC/edhoc_encode_message_error.c --include-prefix $INC_PATH_IN_C_FILES --oh $INC/edhoc_encode_message_error.h 60 61 62# ### cose ### 63 64python3 $ZCBOR -c $MODELS_PATH/edhoc_cose.cddl code -e -t edhoc_enc_structure --oc $SRC/edhoc_encode_enc_structure.c --include-prefix $INC_PATH_IN_C_FILES --oh $INC/edhoc_encode_enc_structure.h 65 66python3 $ZCBOR -c $MODELS_PATH/edhoc_cose.cddl code -e -t sig_structure --oc $SRC/edhoc_encode_sig_structure.c --include-prefix $INC_PATH_IN_C_FILES --oh $INC/edhoc_encode_sig_structure.h 67 68 69 70### other ### 71 72# encode data_2 73python3 $ZCBOR -c $MODELS_PATH/edhoc_data_2.cddl code -e -t data_2 --oc $SRC/edhoc_encode_data_2.c --include-prefix $INC_PATH_IN_C_FILES --oh $INC/edhoc_encode_data_2.h 74 75# info 76python3 $ZCBOR -c $MODELS_PATH/edhoc_info.cddl code -e -t info --oc $SRC/edhoc_encode_info.c --include-prefix $INC_PATH_IN_C_FILES --oh $INC/edhoc_encode_info.h 77 78# plaintext 79python3 $ZCBOR -c $MODELS_PATH/edhoc_plaintext.cddl code -d -t plaintext --oc $SRC/edhoc_decode_plaintext.c --include-prefix $INC_PATH_IN_C_FILES --oh $INC/edhoc_decode_plaintext.h 80 81# encode ID_CRED_x 82python3 $ZCBOR -c $MODELS_PATH/edhoc_plaintext.cddl code -e -t id_cred_x_map --oc $SRC/edhoc_encode_id_cred_x.c --include-prefix $INC_PATH_IN_C_FILES --oh $INC/edhoc_encode_id_cred_x.h 83 84# decode ID_CRED_x 85python3 $ZCBOR -c $MODELS_PATH/edhoc_plaintext.cddl code -d -t id_cred_x_map --oc $SRC/edhoc_decode_id_cred_x.c --include-prefix $INC_PATH_IN_C_FILES --oh $INC/edhoc_decode_id_cred_x.h 86 87# decode Native CBOR certificate 88python3 $ZCBOR -c $MODELS_PATH/edhoc_cert.cddl code -d -t cert --oc $SRC/edhoc_decode_cert.c --include-prefix $INC_PATH_IN_C_FILES --oh $INC/edhoc_decode_cert.h 89 90# encode th2 91python3 $ZCBOR -c $MODELS_PATH/edhoc_th.cddl code -e -t th2 --oc $SRC/edhoc_encode_th2.c --include-prefix $INC_PATH_IN_C_FILES --oh $INC/edhoc_encode_th2.h 92 93### primitive types ### 94#encode byte_string 95python3 $ZCBOR -c $MODELS_PATH/edhoc_primitive_types.cddl code -e -t bstr_type --oc $SRC/edhoc_encode_bstr_type.c --include-prefix $INC_PATH_IN_C_FILES --oh $INC/edhoc_encode_bstr_type.h 96 97#decode byte_string 98python3 $ZCBOR -c $MODELS_PATH/edhoc_primitive_types.cddl code -d -t bstr_type --oc $SRC/edhoc_decode_bstr_type.c --include-prefix $INC_PATH_IN_C_FILES --oh $INC/edhoc_decode_bstr_type.h 99 100#encode int 101python3 $ZCBOR -c $MODELS_PATH/edhoc_primitive_types.cddl code -e -t int_type --oc $SRC/edhoc_encode_int_type.c --include-prefix $INC_PATH_IN_C_FILES --oh $INC/edhoc_encode_int_type.h 102 103 104#decode int 105python3 $ZCBOR -c $MODELS_PATH/edhoc_primitive_types.cddl code -d -t int_type --oc $SRC/edhoc_decode_int_type.c --include-prefix $INC_PATH_IN_C_FILES --oh $INC/edhoc_decode_int_type.h