From 570027752233bb3016bdaf1658c1f2b5043397fc Mon Sep 17 00:00:00 2001 From: Jon Ringle Date: Tue, 21 Nov 2017 15:47:34 -0500 Subject: [PATCH 01/12] define ASN_TAG_AMBIGUOUS UINT_MAX --- libasn1compiler/asn1c_C.c | 4 ++-- skeletons/ber_tlv_tag.h | 6 +++++- skeletons/constr_CHOICE.c | 2 +- skeletons/constr_SEQUENCE.c | 2 +- skeletons/constr_SET_OF.c | 2 +- 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/libasn1compiler/asn1c_C.c b/libasn1compiler/asn1c_C.c index 53831f918..bdf78f5f5 100644 --- a/libasn1compiler/asn1c_C.c +++ b/libasn1compiler/asn1c_C.c @@ -2780,11 +2780,11 @@ emit_member_table(arg_t *arg, asn1p_expr_t *expr, asn1c_ioc_table_and_objset_t * if(C99_MODE) OUT(".tag = "); if(outmost_tag) { if(outmost_tag->tag_value == -1) - OUT("-1 /* Ambiguous tag (ANY?) */"); + OUT("ASN_TAG_AMBIGUOUS /* Ambiguous tag (ANY?) */"); else _print_tag(arg, outmost_tag); } else { - OUT("-1 /* Ambiguous tag (CHOICE?) */"); + OUT("ASN_TAG_AMBIGUOUS /* Ambiguous tag (CHOICE?) */"); } OUT(",\n"); diff --git a/skeletons/ber_tlv_tag.h b/skeletons/ber_tlv_tag.h index ce227add6..4783e68a1 100644 --- a/skeletons/ber_tlv_tag.h +++ b/skeletons/ber_tlv_tag.h @@ -5,6 +5,8 @@ #ifndef _BER_TLV_TAG_H_ #define _BER_TLV_TAG_H_ +#include + #ifdef __cplusplus extern "C" { #endif @@ -15,7 +17,9 @@ enum asn_tag_class { ASN_TAG_CLASS_CONTEXT = 2, /* 0b10 */ ASN_TAG_CLASS_PRIVATE = 3 /* 0b11 */ }; -typedef unsigned ber_tlv_tag_t; /* BER TAG from Tag-Length-Value */ +typedef unsigned int ber_tlv_tag_t; /* BER TAG from Tag-Length-Value */ + +#define ASN_TAG_AMBIGUOUS UINT_MAX /* * Tag class is encoded together with tag value for optimization purposes. diff --git a/skeletons/constr_CHOICE.c b/skeletons/constr_CHOICE.c index 628979ec2..ac2c525b6 100644 --- a/skeletons/constr_CHOICE.c +++ b/skeletons/constr_CHOICE.c @@ -479,7 +479,7 @@ CHOICE_outmost_tag(const asn_TYPE_descriptor_t *td, const void *ptr, int tag_mod return asn_TYPE_outmost_tag(elm->type, memb_ptr, elm->tag_mode, elm->tag); } else { - return (ber_tlv_tag_t)-1; + return ASN_TAG_AMBIGUOUS; } } diff --git a/skeletons/constr_SEQUENCE.c b/skeletons/constr_SEQUENCE.c index 2fbf97b67..e4abe2c2d 100644 --- a/skeletons/constr_SEQUENCE.c +++ b/skeletons/constr_SEQUENCE.c @@ -293,7 +293,7 @@ SEQUENCE_decode_ber(const asn_codec_ctx_t *opt_codec_ctx, edx = n; ctx->step = 1 + 2 * edx; /* Remember! */ goto microphase2; - } else if(elements[n].tag == (ber_tlv_tag_t)-1) { + } else if(elements[n].tag == ASN_TAG_AMBIGUOUS) { use_bsearch = 1; break; } diff --git a/skeletons/constr_SET_OF.c b/skeletons/constr_SET_OF.c index 96c5c09ea..94d99393e 100644 --- a/skeletons/constr_SET_OF.c +++ b/skeletons/constr_SET_OF.c @@ -183,7 +183,7 @@ SET_OF_decode_ber(const asn_codec_ctx_t *opt_codec_ctx, } /* Outmost tag may be unknown and cannot be fetched/compared */ - if(elm->tag != (ber_tlv_tag_t)-1) { + if(elm->tag != ASN_TAG_AMBIGUOUS) { if(BER_TAGS_EQUAL(tlv_tag, elm->tag)) { /* * The new list member of expected type has arrived. From 43350aaa5c276ca8e3623b9aee57d90f3c5ee252 Mon Sep 17 00:00:00 2001 From: Jon Ringle Date: Wed, 22 Nov 2017 00:31:28 -0500 Subject: [PATCH 02/12] ber_tlv_tag_snprint: Handle printing [AMBIGUOUS] tag --- skeletons/ber_tlv_tag.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/skeletons/ber_tlv_tag.c b/skeletons/ber_tlv_tag.c index 4a7d732f8..291dbeb9c 100644 --- a/skeletons/ber_tlv_tag.c +++ b/skeletons/ber_tlv_tag.c @@ -77,14 +77,19 @@ ber_tlv_tag_snprint(ber_tlv_tag_t tag, char *buf, size_t size) { const char *type = 0; int ret; - switch(tag & 0x3) { - case ASN_TAG_CLASS_UNIVERSAL: type = "UNIVERSAL "; break; - case ASN_TAG_CLASS_APPLICATION: type = "APPLICATION "; break; - case ASN_TAG_CLASS_CONTEXT: type = ""; break; - case ASN_TAG_CLASS_PRIVATE: type = "PRIVATE "; break; + if(tag == ASN_TAG_AMBIGUOUS) { + ret = snprintf(buf, size, "[AMBIGUOUS]"); + } else { + switch(tag & 0x3) { + case ASN_TAG_CLASS_UNIVERSAL: type = "UNIVERSAL "; break; + case ASN_TAG_CLASS_APPLICATION: type = "APPLICATION "; break; + case ASN_TAG_CLASS_CONTEXT: type = ""; break; + case ASN_TAG_CLASS_PRIVATE: type = "PRIVATE "; break; + } + + ret = snprintf(buf, size, "[%s%u]", type, ((unsigned)tag) >> 2); } - ret = snprintf(buf, size, "[%s%u]", type, ((unsigned)tag) >> 2); if(ret <= 0 && size) buf[0] = '\0'; /* against broken libc's */ return ret; From e060632f08ee4ee1b2135fec621f01f9b3a5cf62 Mon Sep 17 00:00:00 2001 From: Jon Ringle Date: Tue, 21 Nov 2017 19:18:21 -0500 Subject: [PATCH 03/12] Regenerate tests-asn1c-compiler --- .../tests-asn1c-compiler/139-component-relation-OK.asn1.-P | 2 +- .../tests-asn1c-compiler/140-component-relation-OK.asn1.-P | 2 +- .../144-ios-parameterization-OK.asn1.-P | 2 +- .../146-ios-parameterization-per-OK.asn1.-Pgen-PER | 2 +- ...5-parameterization-more-than-two-level-OK.asn1.-Pgen-PER | 2 +- tests/tests-asn1c-compiler/156-union-ios-OK.asn1.-Pgen-PER | 2 +- .../31-set-of-OK.asn1.-Pfcompound-names | 2 +- tests/tests-asn1c-compiler/31-set-of-OK.asn1.-Pfwide-types | 2 +- tests/tests-asn1c-compiler/42-real-life-OK.asn1.-PR | 2 +- .../tests-asn1c-compiler/43-recursion-OK.asn1.-Pfwide-types | 2 +- tests/tests-asn1c-compiler/44-choice-in-sequence-OK.asn1.-P | 4 ++-- tests/tests-asn1c-compiler/60-any-OK.asn1.-Pfwide-types | 6 +++--- .../tests-asn1c-compiler/70-xer-test-OK.asn1.-Pfwide-types | 4 ++-- .../72-same-names-OK.asn1.-Pfwide-types | 4 ++-- .../92-circular-loops-OK.asn1.-Pfindirect-choice | 2 +- .../92-circular-loops-OK.asn1.-Pfwide-types | 2 +- .../95-choice-per-order-OK.asn1.-Pfwide-types | 2 +- .../95-choice-per-order-OK.asn1.-Pgen-PER | 2 +- 18 files changed, 23 insertions(+), 23 deletions(-) diff --git a/tests/tests-asn1c-compiler/139-component-relation-OK.asn1.-P b/tests/tests-asn1c-compiler/139-component-relation-OK.asn1.-P index b732a4659..c2631a8a1 100644 --- a/tests/tests-asn1c-compiler/139-component-relation-OK.asn1.-P +++ b/tests/tests-asn1c-compiler/139-component-relation-OK.asn1.-P @@ -185,7 +185,7 @@ static asn_TYPE_member_t asn_MBR_Frame_1[] = { .name = "ident" }, { ATF_OPEN_TYPE | ATF_NOFLAGS, 0, offsetof(struct Frame, value), - .tag = -1 /* Ambiguous tag (ANY?) */, + .tag = ASN_TAG_AMBIGUOUS /* Ambiguous tag (ANY?) */, .tag_mode = 0, .type = &asn_DEF_value_3, .type_selector = select_Frame_value_type, diff --git a/tests/tests-asn1c-compiler/140-component-relation-OK.asn1.-P b/tests/tests-asn1c-compiler/140-component-relation-OK.asn1.-P index b732a4659..c2631a8a1 100644 --- a/tests/tests-asn1c-compiler/140-component-relation-OK.asn1.-P +++ b/tests/tests-asn1c-compiler/140-component-relation-OK.asn1.-P @@ -185,7 +185,7 @@ static asn_TYPE_member_t asn_MBR_Frame_1[] = { .name = "ident" }, { ATF_OPEN_TYPE | ATF_NOFLAGS, 0, offsetof(struct Frame, value), - .tag = -1 /* Ambiguous tag (ANY?) */, + .tag = ASN_TAG_AMBIGUOUS /* Ambiguous tag (ANY?) */, .tag_mode = 0, .type = &asn_DEF_value_3, .type_selector = select_Frame_value_type, diff --git a/tests/tests-asn1c-compiler/144-ios-parameterization-OK.asn1.-P b/tests/tests-asn1c-compiler/144-ios-parameterization-OK.asn1.-P index 89a669992..8e9cbeaf2 100644 --- a/tests/tests-asn1c-compiler/144-ios-parameterization-OK.asn1.-P +++ b/tests/tests-asn1c-compiler/144-ios-parameterization-OK.asn1.-P @@ -244,7 +244,7 @@ asn_TYPE_member_t asn_MBR_SpecializedContent_30P0_1[] = { .name = "id" }, { ATF_OPEN_TYPE | ATF_NOFLAGS, 0, offsetof(struct SpecializedContent_30P0, value), - .tag = -1 /* Ambiguous tag (ANY?) */, + .tag = ASN_TAG_AMBIGUOUS /* Ambiguous tag (ANY?) */, .tag_mode = 0, .type = &asn_DEF_value_3, .type_selector = select_SpecializedContent_30P0_value_type, diff --git a/tests/tests-asn1c-compiler/146-ios-parameterization-per-OK.asn1.-Pgen-PER b/tests/tests-asn1c-compiler/146-ios-parameterization-per-OK.asn1.-Pgen-PER index 5e59610d5..0c252c06f 100644 --- a/tests/tests-asn1c-compiler/146-ios-parameterization-per-OK.asn1.-Pgen-PER +++ b/tests/tests-asn1c-compiler/146-ios-parameterization-per-OK.asn1.-Pgen-PER @@ -260,7 +260,7 @@ asn_TYPE_member_t asn_MBR_SpecializedContent_30P0_1[] = { .name = "id" }, { ATF_OPEN_TYPE | ATF_NOFLAGS, 0, offsetof(struct SpecializedContent_30P0, value), - .tag = -1 /* Ambiguous tag (ANY?) */, + .tag = ASN_TAG_AMBIGUOUS /* Ambiguous tag (ANY?) */, .tag_mode = 0, .type = &asn_DEF_value_3, .type_selector = select_SpecializedContent_30P0_value_type, diff --git a/tests/tests-asn1c-compiler/155-parameterization-more-than-two-level-OK.asn1.-Pgen-PER b/tests/tests-asn1c-compiler/155-parameterization-more-than-two-level-OK.asn1.-Pgen-PER index 1a5121f63..7a7a65c3c 100644 --- a/tests/tests-asn1c-compiler/155-parameterization-more-than-two-level-OK.asn1.-Pgen-PER +++ b/tests/tests-asn1c-compiler/155-parameterization-more-than-two-level-OK.asn1.-Pgen-PER @@ -725,7 +725,7 @@ asn_TYPE_member_t asn_MBR_Packet_51P0_1[] = { .name = "color" }, { ATF_OPEN_TYPE | ATF_NOFLAGS, 0, offsetof(struct Packet_51P0, value), - .tag = -1 /* Ambiguous tag (ANY?) */, + .tag = ASN_TAG_AMBIGUOUS /* Ambiguous tag (ANY?) */, .tag_mode = 0, .type = &asn_DEF_value_4, .type_selector = 0, diff --git a/tests/tests-asn1c-compiler/156-union-ios-OK.asn1.-Pgen-PER b/tests/tests-asn1c-compiler/156-union-ios-OK.asn1.-Pgen-PER index b574e5643..cf47cb467 100644 --- a/tests/tests-asn1c-compiler/156-union-ios-OK.asn1.-Pgen-PER +++ b/tests/tests-asn1c-compiler/156-union-ios-OK.asn1.-Pgen-PER @@ -291,7 +291,7 @@ asn_TYPE_member_t asn_MBR_SpecializedContent_42P0_1[] = { .name = "id" }, { ATF_OPEN_TYPE | ATF_NOFLAGS, 0, offsetof(struct SpecializedContent_42P0, value), - .tag = -1 /* Ambiguous tag (ANY?) */, + .tag = ASN_TAG_AMBIGUOUS /* Ambiguous tag (ANY?) */, .tag_mode = 0, .type = &asn_DEF_value_3, .type_selector = select_SpecializedContent_42P0_value_type, diff --git a/tests/tests-asn1c-compiler/31-set-of-OK.asn1.-Pfcompound-names b/tests/tests-asn1c-compiler/31-set-of-OK.asn1.-Pfcompound-names index fc39f3312..3dc55ff5f 100644 --- a/tests/tests-asn1c-compiler/31-set-of-OK.asn1.-Pfcompound-names +++ b/tests/tests-asn1c-compiler/31-set-of-OK.asn1.-Pfcompound-names @@ -417,7 +417,7 @@ static asn_TYPE_member_t asn_MBR_Stuff_1[] = { .name = "anything" }, { ATF_POINTER, 1, offsetof(struct Stuff, other), - .tag = -1 /* Ambiguous tag (CHOICE?) */, + .tag = ASN_TAG_AMBIGUOUS /* Ambiguous tag (CHOICE?) */, .tag_mode = 0, .type = &asn_DEF_other_9, .type_selector = 0, diff --git a/tests/tests-asn1c-compiler/31-set-of-OK.asn1.-Pfwide-types b/tests/tests-asn1c-compiler/31-set-of-OK.asn1.-Pfwide-types index 2a4cf8f69..9e183972f 100644 --- a/tests/tests-asn1c-compiler/31-set-of-OK.asn1.-Pfwide-types +++ b/tests/tests-asn1c-compiler/31-set-of-OK.asn1.-Pfwide-types @@ -417,7 +417,7 @@ static asn_TYPE_member_t asn_MBR_Stuff_1[] = { .name = "anything" }, { ATF_POINTER, 1, offsetof(struct Stuff, other), - .tag = -1 /* Ambiguous tag (CHOICE?) */, + .tag = ASN_TAG_AMBIGUOUS /* Ambiguous tag (CHOICE?) */, .tag_mode = 0, .type = &asn_DEF_other_9, .type_selector = 0, diff --git a/tests/tests-asn1c-compiler/42-real-life-OK.asn1.-PR b/tests/tests-asn1c-compiler/42-real-life-OK.asn1.-PR index b27e77a1a..b1dfb279c 100644 --- a/tests/tests-asn1c-compiler/42-real-life-OK.asn1.-PR +++ b/tests/tests-asn1c-compiler/42-real-life-OK.asn1.-PR @@ -222,7 +222,7 @@ memb_vparts_constraint_1(const asn_TYPE_descriptor_t *td, const void *sptr, static asn_TYPE_member_t asn_MBR_vparts_2[] = { { ATF_POINTER, 0, 0, - .tag = -1 /* Ambiguous tag (CHOICE?) */, + .tag = ASN_TAG_AMBIGUOUS /* Ambiguous tag (CHOICE?) */, .tag_mode = 0, .type = &asn_DEF_VariablePart, .type_selector = 0, diff --git a/tests/tests-asn1c-compiler/43-recursion-OK.asn1.-Pfwide-types b/tests/tests-asn1c-compiler/43-recursion-OK.asn1.-Pfwide-types index bdf973b37..13e1fb93d 100644 --- a/tests/tests-asn1c-compiler/43-recursion-OK.asn1.-Pfwide-types +++ b/tests/tests-asn1c-compiler/43-recursion-OK.asn1.-Pfwide-types @@ -245,7 +245,7 @@ extern asn_TYPE_member_t asn_MBR_Choice_1_1[4]; static asn_TYPE_member_t asn_MBR_or_3[] = { { ATF_POINTER, 0, 0, - .tag = -1 /* Ambiguous tag (CHOICE?) */, + .tag = ASN_TAG_AMBIGUOUS /* Ambiguous tag (CHOICE?) */, .tag_mode = 0, .type = &asn_DEF_Choice_1, .type_selector = 0, diff --git a/tests/tests-asn1c-compiler/44-choice-in-sequence-OK.asn1.-P b/tests/tests-asn1c-compiler/44-choice-in-sequence-OK.asn1.-P index 003c11a8c..db312586e 100644 --- a/tests/tests-asn1c-compiler/44-choice-in-sequence-OK.asn1.-P +++ b/tests/tests-asn1c-compiler/44-choice-in-sequence-OK.asn1.-P @@ -188,7 +188,7 @@ static asn_TYPE_member_t asn_MBR_b_3[] = { .name = "d" }, { ATF_NOFLAGS, 0, offsetof(struct b, choice.e), - .tag = -1 /* Ambiguous tag (CHOICE?) */, + .tag = ASN_TAG_AMBIGUOUS /* Ambiguous tag (CHOICE?) */, .tag_mode = 0, .type = &asn_DEF_e_6, .type_selector = 0, @@ -249,7 +249,7 @@ static asn_TYPE_member_t asn_MBR_T_1[] = { .name = "a" }, { ATF_NOFLAGS, 0, offsetof(struct T, b), - .tag = -1 /* Ambiguous tag (CHOICE?) */, + .tag = ASN_TAG_AMBIGUOUS /* Ambiguous tag (CHOICE?) */, .tag_mode = 0, .type = &asn_DEF_b_3, .type_selector = 0, diff --git a/tests/tests-asn1c-compiler/60-any-OK.asn1.-Pfwide-types b/tests/tests-asn1c-compiler/60-any-OK.asn1.-Pfwide-types index 5c21afa6d..434c3e927 100644 --- a/tests/tests-asn1c-compiler/60-any-OK.asn1.-Pfwide-types +++ b/tests/tests-asn1c-compiler/60-any-OK.asn1.-Pfwide-types @@ -32,7 +32,7 @@ static asn_TYPE_member_t asn_MBR_T1_1[] = { .name = "i" }, { ATF_ANY_TYPE | ATF_NOFLAGS, 0, offsetof(struct T1, any), - .tag = -1 /* Ambiguous tag (ANY?) */, + .tag = ASN_TAG_AMBIGUOUS /* Ambiguous tag (ANY?) */, .tag_mode = 0, .type = &asn_DEF_ANY, .type_selector = 0, @@ -169,7 +169,7 @@ extern asn_TYPE_descriptor_t asn_DEF_T3; static asn_TYPE_member_t asn_MBR_T3_1[] = { { ATF_ANY_TYPE | ATF_NOFLAGS, 0, offsetof(struct T3, any1), - .tag = -1 /* Ambiguous tag (ANY?) */, + .tag = ASN_TAG_AMBIGUOUS /* Ambiguous tag (ANY?) */, .tag_mode = 0, .type = &asn_DEF_ANY, .type_selector = 0, @@ -178,7 +178,7 @@ static asn_TYPE_member_t asn_MBR_T3_1[] = { .name = "any1" }, { ATF_ANY_TYPE | ATF_NOFLAGS, 0, offsetof(struct T3, any2), - .tag = -1 /* Ambiguous tag (ANY?) */, + .tag = ASN_TAG_AMBIGUOUS /* Ambiguous tag (ANY?) */, .tag_mode = 0, .type = &asn_DEF_ANY, .type_selector = 0, diff --git a/tests/tests-asn1c-compiler/70-xer-test-OK.asn1.-Pfwide-types b/tests/tests-asn1c-compiler/70-xer-test-OK.asn1.-Pfwide-types index 7879a7cba..9477fe64e 100644 --- a/tests/tests-asn1c-compiler/70-xer-test-OK.asn1.-Pfwide-types +++ b/tests/tests-asn1c-compiler/70-xer-test-OK.asn1.-Pfwide-types @@ -1388,7 +1388,7 @@ extern asn_TYPE_member_t asn_MBR_SetOfChoice_1[1]; asn_TYPE_member_t asn_MBR_SetOfChoice_1[] = { { ATF_POINTER, 0, 0, - .tag = -1 /* Ambiguous tag (CHOICE?) */, + .tag = ASN_TAG_AMBIGUOUS /* Ambiguous tag (CHOICE?) */, .tag_mode = 0, .type = &asn_DEF_SimpleChoice, .type_selector = 0, @@ -1454,7 +1454,7 @@ extern asn_TYPE_member_t asn_MBR_NamedSetOfChoice_1[1]; asn_TYPE_member_t asn_MBR_NamedSetOfChoice_1[] = { { ATF_POINTER, 0, 0, - .tag = -1 /* Ambiguous tag (CHOICE?) */, + .tag = ASN_TAG_AMBIGUOUS /* Ambiguous tag (CHOICE?) */, .tag_mode = 0, .type = &asn_DEF_SimpleChoice, .type_selector = 0, diff --git a/tests/tests-asn1c-compiler/72-same-names-OK.asn1.-Pfwide-types b/tests/tests-asn1c-compiler/72-same-names-OK.asn1.-Pfwide-types index 7f53a5195..521a28332 100644 --- a/tests/tests-asn1c-compiler/72-same-names-OK.asn1.-Pfwide-types +++ b/tests/tests-asn1c-compiler/72-same-names-OK.asn1.-Pfwide-types @@ -43,7 +43,7 @@ static asn_TYPE_member_t asn_MBR_Member_2[] = { .name = "t1" }, { ATF_NOFLAGS, 0, offsetof(struct Member, t2), - .tag = -1 /* Ambiguous tag (CHOICE?) */, + .tag = ASN_TAG_AMBIGUOUS /* Ambiguous tag (CHOICE?) */, .tag_mode = 0, .type = &asn_DEF_Type2, .type_selector = 0, @@ -258,7 +258,7 @@ asn_TYPE_descriptor_t asn_DEF_one_name_2 = { asn_TYPE_member_t asn_MBR_Type1_1[] = { { ATF_NOFLAGS, 0, offsetof(struct Type1, one_name), - .tag = -1 /* Ambiguous tag (CHOICE?) */, + .tag = ASN_TAG_AMBIGUOUS /* Ambiguous tag (CHOICE?) */, .tag_mode = 0, .type = &asn_DEF_one_name_2, .type_selector = 0, diff --git a/tests/tests-asn1c-compiler/92-circular-loops-OK.asn1.-Pfindirect-choice b/tests/tests-asn1c-compiler/92-circular-loops-OK.asn1.-Pfindirect-choice index f41738079..c06aa8f1e 100644 --- a/tests/tests-asn1c-compiler/92-circular-loops-OK.asn1.-Pfindirect-choice +++ b/tests/tests-asn1c-compiler/92-circular-loops-OK.asn1.-Pfindirect-choice @@ -475,7 +475,7 @@ asn_TYPE_descriptor_t asn_DEF_a_2 = { static asn_TYPE_member_t asn_MBR_c_5[] = { { ATF_POINTER, 0, 0, - .tag = -1 /* Ambiguous tag (CHOICE?) */, + .tag = ASN_TAG_AMBIGUOUS /* Ambiguous tag (CHOICE?) */, .tag_mode = 0, .type = &asn_DEF_Choice3, .type_selector = 0, diff --git a/tests/tests-asn1c-compiler/92-circular-loops-OK.asn1.-Pfwide-types b/tests/tests-asn1c-compiler/92-circular-loops-OK.asn1.-Pfwide-types index dafb1766f..b9de30c4e 100644 --- a/tests/tests-asn1c-compiler/92-circular-loops-OK.asn1.-Pfwide-types +++ b/tests/tests-asn1c-compiler/92-circular-loops-OK.asn1.-Pfwide-types @@ -474,7 +474,7 @@ asn_TYPE_descriptor_t asn_DEF_a_2 = { static asn_TYPE_member_t asn_MBR_c_5[] = { { ATF_POINTER, 0, 0, - .tag = -1 /* Ambiguous tag (CHOICE?) */, + .tag = ASN_TAG_AMBIGUOUS /* Ambiguous tag (CHOICE?) */, .tag_mode = 0, .type = &asn_DEF_Choice3, .type_selector = 0, diff --git a/tests/tests-asn1c-compiler/95-choice-per-order-OK.asn1.-Pfwide-types b/tests/tests-asn1c-compiler/95-choice-per-order-OK.asn1.-Pfwide-types index c5682cdae..8a51ecc34 100644 --- a/tests/tests-asn1c-compiler/95-choice-per-order-OK.asn1.-Pfwide-types +++ b/tests/tests-asn1c-compiler/95-choice-per-order-OK.asn1.-Pfwide-types @@ -127,7 +127,7 @@ static asn_TYPE_member_t asn_MBR_Choice_1[] = { .name = "bitstr" }, { ATF_NOFLAGS, 0, offsetof(struct Choice, choice.ch), - .tag = -1 /* Ambiguous tag (CHOICE?) */, + .tag = ASN_TAG_AMBIGUOUS /* Ambiguous tag (CHOICE?) */, .tag_mode = 0, .type = &asn_DEF_ch_4, .type_selector = 0, diff --git a/tests/tests-asn1c-compiler/95-choice-per-order-OK.asn1.-Pgen-PER b/tests/tests-asn1c-compiler/95-choice-per-order-OK.asn1.-Pgen-PER index ae45367b8..6b7697f84 100644 --- a/tests/tests-asn1c-compiler/95-choice-per-order-OK.asn1.-Pgen-PER +++ b/tests/tests-asn1c-compiler/95-choice-per-order-OK.asn1.-Pgen-PER @@ -143,7 +143,7 @@ static asn_TYPE_member_t asn_MBR_Choice_1[] = { .name = "bitstr" }, { ATF_NOFLAGS, 0, offsetof(struct Choice, choice.ch), - .tag = -1 /* Ambiguous tag (CHOICE?) */, + .tag = ASN_TAG_AMBIGUOUS /* Ambiguous tag (CHOICE?) */, .tag_mode = 0, .type = &asn_DEF_ch_4, .type_selector = 0, From d5592eae1d72c97e39e1cb90881c71b974621a5b Mon Sep 17 00:00:00 2001 From: Jon Ringle Date: Wed, 29 Nov 2017 01:17:06 -0500 Subject: [PATCH 04/12] BNER support: Add #ifdef'd bner_{de,en}coder to asn_TYPE_operations_t --- skeletons/ANY.c | 7 +++++++ skeletons/ANY.h | 2 ++ skeletons/BIT_STRING.c | 7 +++++++ skeletons/BMPString.c | 2 ++ skeletons/BOOLEAN.c | 7 +++++++ skeletons/BOOLEAN.h | 2 ++ skeletons/ENUMERATED.c | 7 +++++++ skeletons/GeneralString.c | 2 ++ skeletons/GeneralizedTime.c | 2 ++ skeletons/GraphicString.c | 2 ++ skeletons/IA5String.c | 2 ++ skeletons/INTEGER.c | 7 +++++++ skeletons/INTEGER.h | 2 ++ skeletons/ISO646String.c | 2 ++ skeletons/NULL.c | 7 +++++++ skeletons/NULL.h | 2 ++ skeletons/NativeEnumerated.c | 7 +++++++ skeletons/NativeInteger.c | 7 +++++++ skeletons/NativeInteger.h | 3 ++- skeletons/NativeReal.c | 8 +++++++- skeletons/NativeReal.h | 4 ++++ skeletons/NumericString.c | 2 ++ skeletons/OBJECT_IDENTIFIER.c | 2 ++ skeletons/OCTET_STRING.c | 7 +++++++ skeletons/OCTET_STRING.h | 2 ++ skeletons/OPEN_TYPE.c | 2 ++ skeletons/ObjectDescriptor.c | 2 ++ skeletons/PrintableString.c | 2 ++ skeletons/REAL.c | 7 +++++++ skeletons/REAL.h | 2 ++ skeletons/RELATIVE-OID.c | 2 ++ skeletons/T61String.c | 2 ++ skeletons/TeletexString.c | 2 ++ skeletons/UTCTime.c | 2 ++ skeletons/UTF8String.c | 2 ++ skeletons/UniversalString.c | 2 ++ skeletons/VideotexString.c | 2 ++ skeletons/VisibleString.c | 2 ++ skeletons/bner_decoder.h | 30 ++++++++++++++++++++++++++++++ skeletons/bner_encoder.h | 33 +++++++++++++++++++++++++++++++++ skeletons/constr_CHOICE.c | 7 +++++++ skeletons/constr_CHOICE.h | 2 ++ skeletons/constr_SEQUENCE.c | 7 +++++++ skeletons/constr_SEQUENCE.h | 2 ++ skeletons/constr_SEQUENCE_OF.c | 7 +++++++ skeletons/constr_SEQUENCE_OF.h | 2 ++ skeletons/constr_SET.c | 2 ++ skeletons/constr_SET_OF.c | 2 ++ skeletons/constr_TYPE.h | 5 +++++ 49 files changed, 232 insertions(+), 2 deletions(-) create mode 100644 skeletons/bner_decoder.h create mode 100644 skeletons/bner_encoder.h diff --git a/skeletons/ANY.c b/skeletons/ANY.c index 6bd5e67a5..a5ec1cda4 100644 --- a/skeletons/ANY.c +++ b/skeletons/ANY.c @@ -32,6 +32,13 @@ asn_TYPE_operation_t asn_OP_ANY = { ANY_decode_uper, ANY_encode_uper, #endif /* ASN_DISABLE_PER_SUPPORT */ +#ifdef ASN_DISABLE_BNER_SUPPORT + 0, + 0, +#else + ANY_decode_bner, + ANY_encode_bner, +#endif /* ASN_DISABLE_BNER_SUPPORT */ 0, /* Random fill is not defined for ANY type */ 0 /* Use generic outmost tag fetcher */ }; diff --git a/skeletons/ANY.h b/skeletons/ANY.h index 70d42a9e9..127558f1f 100644 --- a/skeletons/ANY.h +++ b/skeletons/ANY.h @@ -29,6 +29,8 @@ der_type_encoder_f ANY_encode_der; xer_type_encoder_f ANY_encode_xer; per_type_decoder_f ANY_decode_uper; per_type_encoder_f ANY_encode_uper; +bner_type_decoder_f ANY_decode_bner; +bner_type_encoder_f ANY_encode_bner; #define ANY_free OCTET_STRING_free #define ANY_print OCTET_STRING_print diff --git a/skeletons/BIT_STRING.c b/skeletons/BIT_STRING.c index 0cff7706f..9cdd8a87f 100644 --- a/skeletons/BIT_STRING.c +++ b/skeletons/BIT_STRING.c @@ -39,6 +39,13 @@ asn_TYPE_operation_t asn_OP_BIT_STRING = { BIT_STRING_decode_uper, /* Unaligned PER decoder */ BIT_STRING_encode_uper, /* Unaligned PER encoder */ #endif /* ASN_DISABLE_PER_SUPPORT */ +#ifdef ASN_DISABLE_BNER_SUPPORT + 0, + 0, +#else + OCTET_STRING_decode_bner, + OCTET_STRING_encode_bner, +#endif /* ASN_DISABLE_BNER_SUPPORT */ BIT_STRING_random_fill, 0 /* Use generic outmost tag fetcher */ }; diff --git a/skeletons/BMPString.c b/skeletons/BMPString.c index 86223fe9f..dde4b10d1 100644 --- a/skeletons/BMPString.c +++ b/skeletons/BMPString.c @@ -45,6 +45,8 @@ asn_TYPE_operation_t asn_OP_BMPString = { OCTET_STRING_decode_uper, OCTET_STRING_encode_uper, #endif /* ASN_DISABLE_PER_SUPPORT */ + 0, /* BNER decode */ + 0, /* BNER encode */ OCTET_STRING_random_fill, 0 /* Use generic outmost tag fetcher */ }; diff --git a/skeletons/BOOLEAN.c b/skeletons/BOOLEAN.c index fd8b80c1e..0f5f6241c 100644 --- a/skeletons/BOOLEAN.c +++ b/skeletons/BOOLEAN.c @@ -34,6 +34,13 @@ asn_TYPE_operation_t asn_OP_BOOLEAN = { BOOLEAN_decode_uper, /* Unaligned PER decoder */ BOOLEAN_encode_uper, /* Unaligned PER encoder */ #endif /* ASN_DISABLE_PER_SUPPORT */ +#ifdef ASN_DISABLE_BNER_SUPPORT + 0, + 0, +#else + BOOLEAN_decode_bner, + BOOLEAN_encode_bner, +#endif /* ASN_DISABLE_BNER_SUPPORT */ BOOLEAN_random_fill, 0 /* Use generic outmost tag fetcher */ }; diff --git a/skeletons/BOOLEAN.h b/skeletons/BOOLEAN.h index 7e6b8fb59..5f55b374e 100644 --- a/skeletons/BOOLEAN.h +++ b/skeletons/BOOLEAN.h @@ -32,6 +32,8 @@ per_type_decoder_f BOOLEAN_decode_uper; per_type_encoder_f BOOLEAN_encode_uper; xer_type_decoder_f BOOLEAN_decode_xer; xer_type_encoder_f BOOLEAN_encode_xer; +bner_type_decoder_f BOOLEAN_decode_bner; +bner_type_encoder_f BOOLEAN_encode_bner; asn_random_fill_f BOOLEAN_random_fill; #define BOOLEAN_constraint asn_generic_no_constraint diff --git a/skeletons/ENUMERATED.c b/skeletons/ENUMERATED.c index c5c197eaa..d8391b524 100644 --- a/skeletons/ENUMERATED.c +++ b/skeletons/ENUMERATED.c @@ -36,6 +36,13 @@ asn_TYPE_operation_t asn_OP_ENUMERATED = { ENUMERATED_decode_uper, /* Unaligned PER decoder */ ENUMERATED_encode_uper, /* Unaligned PER encoder */ #endif /* ASN_DISABLE_PER_SUPPORT */ +#ifdef ASN_DISABLE_BNER_SUPPORT + 0, + 0, +#else + INTEGER_decode_bner, + INTEGER_encode_bner, +#endif /* ASN_DISABLE_BNER_SUPPORT */ ENUMERATED_random_fill, 0 /* Use generic outmost tag fetcher */ }; diff --git a/skeletons/GeneralString.c b/skeletons/GeneralString.c index 16b6f2ff9..38f14df22 100644 --- a/skeletons/GeneralString.c +++ b/skeletons/GeneralString.c @@ -34,6 +34,8 @@ asn_TYPE_operation_t asn_OP_GeneralString = { OCTET_STRING_decode_uper, /* Implemented in terms of OCTET STRING */ OCTET_STRING_encode_uper, #endif /* ASN_DISABLE_PER_SUPPORT */ + 0, /* BNER decode */ + 0, /* BNER encode */ OCTET_STRING_random_fill, 0 /* Use generic outmost tag fetcher */ }; diff --git a/skeletons/GeneralizedTime.c b/skeletons/GeneralizedTime.c index b2d06034b..ca49f0c66 100644 --- a/skeletons/GeneralizedTime.c +++ b/skeletons/GeneralizedTime.c @@ -195,6 +195,8 @@ asn_TYPE_operation_t asn_OP_GeneralizedTime = { OCTET_STRING_decode_uper, OCTET_STRING_encode_uper, #endif /* ASN_DISABLE_PER_SUPPORT */ + 0, /* BNER decode */ + 0, /* BNER encode */ GeneralizedTime_random_fill, 0 /* Use generic outmost tag fetcher */ }; diff --git a/skeletons/GraphicString.c b/skeletons/GraphicString.c index 7ec7945a2..d7a9dcd43 100644 --- a/skeletons/GraphicString.c +++ b/skeletons/GraphicString.c @@ -34,6 +34,8 @@ asn_TYPE_operation_t asn_OP_GraphicString = { OCTET_STRING_decode_uper, /* Implemented in terms of OCTET STRING */ OCTET_STRING_encode_uper, #endif /* ASN_DISABLE_PER_SUPPORT */ + 0, /* BNER decode */ + 0, /* BNER encode */ OCTET_STRING_random_fill, 0 /* Use generic outmost tag fetcher */ }; diff --git a/skeletons/IA5String.c b/skeletons/IA5String.c index 43970416f..ed7352d4a 100644 --- a/skeletons/IA5String.c +++ b/skeletons/IA5String.c @@ -39,6 +39,8 @@ asn_TYPE_operation_t asn_OP_IA5String = { OCTET_STRING_decode_uper, OCTET_STRING_encode_uper, #endif /* ASN_DISABLE_PER_SUPPORT */ + 0, /* BNER decode */ + 0, /* BNER encode */ OCTET_STRING_random_fill, 0 /* Use generic outmost tag fetcher */ }; diff --git a/skeletons/INTEGER.c b/skeletons/INTEGER.c index 73da66592..41633f213 100644 --- a/skeletons/INTEGER.c +++ b/skeletons/INTEGER.c @@ -36,6 +36,13 @@ asn_TYPE_operation_t asn_OP_INTEGER = { INTEGER_decode_uper, /* Unaligned PER decoder */ INTEGER_encode_uper, /* Unaligned PER encoder */ #endif /* ASN_DISABLE_PER_SUPPORT */ +#ifdef ASN_DISABLE_BNER_SUPPORT + 0, + 0, +#else + INTEGER_decode_bner, + INTEGER_encode_bner, +#endif /* ASN_DISABLE_BNER_SUPPORT */ INTEGER_random_fill, 0 /* Use generic outmost tag fetcher */ }; diff --git a/skeletons/INTEGER.h b/skeletons/INTEGER.h index cc760ffa9..f89c24532 100644 --- a/skeletons/INTEGER.h +++ b/skeletons/INTEGER.h @@ -47,6 +47,8 @@ oer_type_decoder_f INTEGER_decode_oer; oer_type_encoder_f INTEGER_encode_oer; per_type_decoder_f INTEGER_decode_uper; per_type_encoder_f INTEGER_encode_uper; +bner_type_decoder_f INTEGER_decode_bner; +bner_type_encoder_f INTEGER_encode_bner; asn_random_fill_f INTEGER_random_fill; /*********************************** diff --git a/skeletons/ISO646String.c b/skeletons/ISO646String.c index 86b128bf2..a0074e0e9 100644 --- a/skeletons/ISO646String.c +++ b/skeletons/ISO646String.c @@ -39,6 +39,8 @@ asn_TYPE_operation_t asn_OP_ISO646String = { OCTET_STRING_decode_uper, OCTET_STRING_encode_uper, #endif /* ASN_DISABLE_PER_SUPPORT */ + 0, /* BNER decode */ + 0, /* BNER encode */ OCTET_STRING_random_fill, 0 /* Use generic outmost tag fetcher */ }; diff --git a/skeletons/NULL.c b/skeletons/NULL.c index a43d412b5..63462fb57 100644 --- a/skeletons/NULL.c +++ b/skeletons/NULL.c @@ -35,6 +35,13 @@ asn_TYPE_operation_t asn_OP_NULL = { NULL_decode_uper, /* Unaligned PER decoder */ NULL_encode_uper, /* Unaligned PER encoder */ #endif /* ASN_DISABLE_PER_SUPPORT */ +#ifdef ASN_DISABLE_BNER_SUPPORT + 0, + 0, +#else + NULL_decode_bner, + NULL_encode_bner, +#endif /* ASN_DISABLE_BNER_SUPPORT */ NULL_random_fill, 0 /* Use generic outmost tag fetcher */ }; diff --git a/skeletons/NULL.h b/skeletons/NULL.h index 50f53ca06..b1ec4a2d0 100644 --- a/skeletons/NULL.h +++ b/skeletons/NULL.h @@ -30,6 +30,8 @@ oer_type_decoder_f NULL_decode_oer; oer_type_encoder_f NULL_encode_oer; per_type_decoder_f NULL_decode_uper; per_type_encoder_f NULL_encode_uper; +bner_type_decoder_f NULL_decode_bner; +bner_type_encoder_f NULL_encode_bner; asn_random_fill_f NULL_random_fill; #define NULL_free BOOLEAN_free diff --git a/skeletons/NativeEnumerated.c b/skeletons/NativeEnumerated.c index 4ed8749d0..7265fec65 100644 --- a/skeletons/NativeEnumerated.c +++ b/skeletons/NativeEnumerated.c @@ -40,6 +40,13 @@ asn_TYPE_operation_t asn_OP_NativeEnumerated = { NativeEnumerated_decode_uper, NativeEnumerated_encode_uper, #endif /* ASN_DISABLE_PER_SUPPORT */ +#ifdef ASN_DISABLE_BNER_SUPPORT + 0, + 0, +#else + NativeInteger_decode_bner, + NativeInteger_encode_bner, +#endif /* ASN_DISABLE_BNER_SUPPORT */ NativeEnumerated_random_fill, 0 /* Use generic outmost tag fetcher */ }; diff --git a/skeletons/NativeInteger.c b/skeletons/NativeInteger.c index f17243753..c45bdc333 100644 --- a/skeletons/NativeInteger.c +++ b/skeletons/NativeInteger.c @@ -41,6 +41,13 @@ asn_TYPE_operation_t asn_OP_NativeInteger = { NativeInteger_decode_uper, /* Unaligned PER decoder */ NativeInteger_encode_uper, /* Unaligned PER encoder */ #endif /* ASN_DISABLE_PER_SUPPORT */ +#ifdef ASN_DISABLE_BNER_SUPPORT + 0, + 0, +#else + NativeInteger_decode_bner, + NativeInteger_encode_bner, +#endif /* ASN_DISABLE_BNER_SUPPORT */ NativeInteger_random_fill, 0 /* Use generic outmost tag fetcher */ }; diff --git a/skeletons/NativeInteger.h b/skeletons/NativeInteger.h index e2741c201..a5ed19b07 100644 --- a/skeletons/NativeInteger.h +++ b/skeletons/NativeInteger.h @@ -33,8 +33,9 @@ oer_type_decoder_f NativeInteger_decode_oer; oer_type_encoder_f NativeInteger_encode_oer; per_type_decoder_f NativeInteger_decode_uper; per_type_encoder_f NativeInteger_encode_uper; +bner_type_decoder_f NativeInteger_decode_bner; +bner_type_encoder_f NativeInteger_encode_bner; asn_random_fill_f NativeInteger_random_fill; - #define NativeInteger_constraint asn_generic_no_constraint #ifdef __cplusplus diff --git a/skeletons/NativeReal.c b/skeletons/NativeReal.c index b1d1a7ede..e55872b13 100644 --- a/skeletons/NativeReal.c +++ b/skeletons/NativeReal.c @@ -62,6 +62,13 @@ asn_TYPE_operation_t asn_OP_NativeReal = { NativeReal_decode_uper, NativeReal_encode_uper, #endif /* ASN_DISABLE_PER_SUPPORT */ +#ifdef ASN_DISABLE_BNER_SUPPORT + 0, + 0, +#else + NativeFloat_decode_bner, + NativeFloat_encode_bner, +#endif /* ASN_DISABLE_BNER_SUPPORT */ NativeReal_random_fill, 0 /* Use generic outmost tag fetcher */ }; @@ -261,7 +268,6 @@ NativeReal_encode_uper(const asn_TYPE_descriptor_t *td, return erval; } - #endif /* ASN_DISABLE_PER_SUPPORT */ #ifndef ASN_DISABLE_OER_SUPPORT diff --git a/skeletons/NativeReal.h b/skeletons/NativeReal.h index b6d16d6c1..402b56aa7 100644 --- a/skeletons/NativeReal.h +++ b/skeletons/NativeReal.h @@ -35,6 +35,10 @@ oer_type_decoder_f NativeReal_decode_oer; oer_type_encoder_f NativeReal_encode_oer; xer_type_decoder_f NativeReal_decode_xer; xer_type_encoder_f NativeReal_encode_xer; +bner_type_decoder_f NativeFloat_decode_bner; +bner_type_encoder_f NativeFloat_encode_bner; +bner_type_decoder_f NativeDouble_decode_bner; +bner_type_encoder_f NativeDouble_encode_bner; asn_random_fill_f NativeReal_random_fill; #define NativeReal_constraint asn_generic_no_constraint diff --git a/skeletons/NumericString.c b/skeletons/NumericString.c index c89597ef9..4bc3d8e8f 100644 --- a/skeletons/NumericString.c +++ b/skeletons/NumericString.c @@ -59,6 +59,8 @@ asn_TYPE_operation_t asn_OP_NumericString = { OCTET_STRING_decode_uper, OCTET_STRING_encode_uper, #endif /* ASN_DISABLE_PER_SUPPORT */ + 0, /* BNER decode */ + 0, /* BNER encode */ OCTET_STRING_random_fill, 0 /* Use generic outmost tag fetcher */ }; diff --git a/skeletons/OBJECT_IDENTIFIER.c b/skeletons/OBJECT_IDENTIFIER.c index 290545d1c..0b91c6d0d 100644 --- a/skeletons/OBJECT_IDENTIFIER.c +++ b/skeletons/OBJECT_IDENTIFIER.c @@ -37,6 +37,8 @@ asn_TYPE_operation_t asn_OP_OBJECT_IDENTIFIER = { OCTET_STRING_decode_uper, OCTET_STRING_encode_uper, #endif /* ASN_DISABLE_PER_SUPPORT */ + 0, /* BNER decode */ + 0, /* BNER encode */ OBJECT_IDENTIFIER_random_fill, 0 /* Use generic outmost tag fetcher */ }; diff --git a/skeletons/OCTET_STRING.c b/skeletons/OCTET_STRING.c index a69285166..cb5029f86 100644 --- a/skeletons/OCTET_STRING.c +++ b/skeletons/OCTET_STRING.c @@ -42,6 +42,13 @@ asn_TYPE_operation_t asn_OP_OCTET_STRING = { OCTET_STRING_decode_uper, /* Unaligned PER decoder */ OCTET_STRING_encode_uper, /* Unaligned PER encoder */ #endif /* ASN_DISABLE_PER_SUPPORT */ +#ifdef ASN_DISABLE_BNER_SUPPORT + 0, + 0, +#else + OCTET_STRING_decode_bner, + OCTET_STRING_encode_bner, +#endif /* ASN_DISABLE_BNER_SUPPORT */ OCTET_STRING_random_fill, 0 /* Use generic outmost tag fetcher */ }; diff --git a/skeletons/OCTET_STRING.h b/skeletons/OCTET_STRING.h index bb06dc62d..e07a1d842 100644 --- a/skeletons/OCTET_STRING.h +++ b/skeletons/OCTET_STRING.h @@ -36,6 +36,8 @@ oer_type_decoder_f OCTET_STRING_decode_oer; oer_type_encoder_f OCTET_STRING_encode_oer; per_type_decoder_f OCTET_STRING_decode_uper; per_type_encoder_f OCTET_STRING_encode_uper; +bner_type_decoder_f OCTET_STRING_decode_bner; +bner_type_encoder_f OCTET_STRING_encode_bner; asn_random_fill_f OCTET_STRING_random_fill; #define OCTET_STRING_constraint asn_generic_no_constraint diff --git a/skeletons/OPEN_TYPE.c b/skeletons/OPEN_TYPE.c index c672992ca..d806fb0d3 100644 --- a/skeletons/OPEN_TYPE.c +++ b/skeletons/OPEN_TYPE.c @@ -23,6 +23,8 @@ asn_TYPE_operation_t asn_OP_OPEN_TYPE = { OPEN_TYPE_decode_uper, OPEN_TYPE_encode_uper, #endif + 0, /* BNER decode */ + 0, /* BNER encode */ 0, /* Random fill is not supported for open type */ 0, /* Use generic outmost tag fetcher */ }; diff --git a/skeletons/ObjectDescriptor.c b/skeletons/ObjectDescriptor.c index 79042c0a6..4035d5fd7 100644 --- a/skeletons/ObjectDescriptor.c +++ b/skeletons/ObjectDescriptor.c @@ -34,6 +34,8 @@ asn_TYPE_operation_t asn_OP_ObjectDescriptor = { OCTET_STRING_decode_uper, OCTET_STRING_encode_uper, #endif /* ASN_DISABLE_PER_SUPPORT */ + 0, /* BNER decode */ + 0, /* BNER encode */ 0, /* Not supported for ObjectDescriptor */ 0 /* Use generic outmost tag fetcher */ }; diff --git a/skeletons/PrintableString.c b/skeletons/PrintableString.c index ffc08b7c0..a1eb339cd 100644 --- a/skeletons/PrintableString.c +++ b/skeletons/PrintableString.c @@ -69,6 +69,8 @@ asn_TYPE_operation_t asn_OP_PrintableString = { OCTET_STRING_decode_uper, OCTET_STRING_encode_uper, #endif /* ASN_DISABLE_PER_SUPPORT */ + 0, /* BNER decode */ + 0, /* BNER encode */ OCTET_STRING_random_fill, 0 /* Use generic outmost tag fetcher */ }; diff --git a/skeletons/REAL.c b/skeletons/REAL.c index f1d06650e..04d9ce4f1 100644 --- a/skeletons/REAL.c +++ b/skeletons/REAL.c @@ -88,6 +88,13 @@ asn_TYPE_operation_t asn_OP_REAL = { REAL_decode_uper, REAL_encode_uper, #endif /* ASN_DISABLE_PER_SUPPORT */ +#ifdef ASN_DISABLE_BNER_SUPPORT + 0, + 0, +#else + REAL_decode_bner, + REAL_encode_bner, +#endif /* ASN_DISABLE_BNER_SUPPORT */ REAL_random_fill, 0 /* Use generic outmost tag fetcher */ }; diff --git a/skeletons/REAL.h b/skeletons/REAL.h index d71147abd..4fc64f54b 100644 --- a/skeletons/REAL.h +++ b/skeletons/REAL.h @@ -25,6 +25,8 @@ per_type_decoder_f REAL_decode_uper; per_type_encoder_f REAL_encode_uper; xer_type_decoder_f REAL_decode_xer; xer_type_encoder_f REAL_encode_xer; +bner_type_decoder_f REAL_decode_bner; +bner_type_encoder_f REAL_encode_bner; asn_random_fill_f REAL_random_fill; #define REAL_free ASN__PRIMITIVE_TYPE_free, diff --git a/skeletons/RELATIVE-OID.c b/skeletons/RELATIVE-OID.c index 2f6295b19..94cd6a628 100644 --- a/skeletons/RELATIVE-OID.c +++ b/skeletons/RELATIVE-OID.c @@ -38,6 +38,8 @@ asn_TYPE_operation_t asn_OP_RELATIVE_OID = { OCTET_STRING_decode_uper, OCTET_STRING_encode_uper, #endif /* ASN_DISABLE_PER_SUPPORT */ + 0, /* BNER decode */ + 0, /* BNER encode */ RELATIVE_OID_random_fill, 0 /* Use generic outmost tag fetcher */ }; diff --git a/skeletons/T61String.c b/skeletons/T61String.c index c7e5f009c..fecb6ce51 100644 --- a/skeletons/T61String.c +++ b/skeletons/T61String.c @@ -34,6 +34,8 @@ asn_TYPE_operation_t asn_OP_T61String = { OCTET_STRING_decode_uper, OCTET_STRING_encode_uper, #endif /* ASN_DISABLE_PER_SUPPORT */ + 0, /* BNER decode */ + 0, /* BNER encode */ OCTET_STRING_random_fill, 0 /* Use generic outmost tag fetcher */ }; diff --git a/skeletons/TeletexString.c b/skeletons/TeletexString.c index 6c13f7346..218d309c3 100644 --- a/skeletons/TeletexString.c +++ b/skeletons/TeletexString.c @@ -34,6 +34,8 @@ asn_TYPE_operation_t asn_OP_TeletexString = { OCTET_STRING_decode_uper, OCTET_STRING_encode_uper, #endif /* ASN_DISABLE_PER_SUPPORT */ + 0, /* BNER decode */ + 0, /* BNER encode */ OCTET_STRING_random_fill, 0 /* Use generic outmost tag fetcher */ }; diff --git a/skeletons/UTCTime.c b/skeletons/UTCTime.c index ffbed58af..45b542d9f 100644 --- a/skeletons/UTCTime.c +++ b/skeletons/UTCTime.c @@ -50,6 +50,8 @@ asn_TYPE_operation_t asn_OP_UTCTime = { OCTET_STRING_decode_uper, OCTET_STRING_encode_uper, #endif /* ASN_DISABLE_PER_SUPPORT */ + 0, /* BNER decode */ + 0, /* BNER encode */ UTCTime_random_fill, 0 /* Use generic outmost tag fetcher */ }; diff --git a/skeletons/UTF8String.c b/skeletons/UTF8String.c index a82da366d..894242bf7 100644 --- a/skeletons/UTF8String.c +++ b/skeletons/UTF8String.c @@ -35,6 +35,8 @@ asn_TYPE_operation_t asn_OP_UTF8String = { OCTET_STRING_decode_uper, OCTET_STRING_encode_uper, #endif /* ASN_DISABLE_PER_SUPPORT */ + 0, /* BNER decode */ + 0, /* BNER encode */ UTF8String_random_fill, 0 /* Use generic outmost tag fetcher */ }; diff --git a/skeletons/UniversalString.c b/skeletons/UniversalString.c index da28874a9..31e16594e 100644 --- a/skeletons/UniversalString.c +++ b/skeletons/UniversalString.c @@ -45,6 +45,8 @@ asn_TYPE_operation_t asn_OP_UniversalString = { OCTET_STRING_decode_uper, OCTET_STRING_encode_uper, #endif /* ASN_DISABLE_PER_SUPPORT */ + 0, /* BNER decode */ + 0, /* BNER encode */ OCTET_STRING_random_fill, 0 /* Use generic outmost tag fetcher */ }; diff --git a/skeletons/VideotexString.c b/skeletons/VideotexString.c index 06fe4a7f7..0cf1370ad 100644 --- a/skeletons/VideotexString.c +++ b/skeletons/VideotexString.c @@ -34,6 +34,8 @@ asn_TYPE_operation_t asn_OP_VideotexString = { OCTET_STRING_decode_uper, /* Implemented in terms of OCTET STRING */ OCTET_STRING_encode_uper, #endif /* ASN_DISABLE_PER_SUPPORT */ + 0, /* BNER decode */ + 0, /* BNER encode */ OCTET_STRING_random_fill, 0 /* Use generic outmost tag fetcher */ }; diff --git a/skeletons/VisibleString.c b/skeletons/VisibleString.c index e163791e5..058a3a852 100644 --- a/skeletons/VisibleString.c +++ b/skeletons/VisibleString.c @@ -39,6 +39,8 @@ asn_TYPE_operation_t asn_OP_VisibleString = { OCTET_STRING_decode_uper, OCTET_STRING_encode_uper, #endif /* ASN_DISABLE_PER_SUPPORT */ + 0, /* BNER decode */ + 0, /* BNER encode */ OCTET_STRING_random_fill, 0 /* Use generic outmost tag fetcher */ }; diff --git a/skeletons/bner_decoder.h b/skeletons/bner_decoder.h new file mode 100644 index 000000000..003ff559a --- /dev/null +++ b/skeletons/bner_decoder.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2003-2017 Lev Walkin and contributors. + * All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#ifndef _BNER_DECODER_H_ +#define _BNER_DECODER_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +struct asn_TYPE_descriptor_s; /* Forward declaration */ +struct asn_codec_ctx_s; /* Forward declaration */ + +/* + * Type of generic function which decodes the byte stream into the structure. + */ +typedef asn_dec_rval_t(bner_type_decoder_f)( + const struct asn_codec_ctx_s *opt_codec_ctx, + const struct asn_TYPE_descriptor_s *td, void **struct_ptr, + const void *buf_ptr, size_t size, ber_tlv_tag_t tag, int tag_mode); + +#ifdef __cplusplus +} +#endif + +#endif /* _BNER_DECODER_H_ */ diff --git a/skeletons/bner_encoder.h b/skeletons/bner_encoder.h new file mode 100644 index 000000000..c8bbe57a5 --- /dev/null +++ b/skeletons/bner_encoder.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2003-2017 Lev Walkin and contributors. + * All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#ifndef _BNER_ENCODER_H_ +#define _BNER_ENCODER_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +struct asn_TYPE_descriptor_s; /* Forward declaration */ +struct asn_codec_ctx_s; /* Forward declaration */ + +/* + * Type of the generic BNER encoder. + */ +typedef asn_enc_rval_t(bner_type_encoder_f)( + const struct asn_TYPE_descriptor_s *td, + const void *struct_ptr, /* Structure to be encoded */ + int tag_mode, /* {-1,0,1}: IMPLICIT, no, EXPLICIT */ + ber_tlv_tag_t tag, asn_app_consume_bytes_f *consume_bytes_cb, /* Callback */ + void *app_key /* Arbitrary callback argument */ + ); + +#ifdef __cplusplus +} +#endif + +#endif /* _BNER_ENCODER_H_ */ diff --git a/skeletons/constr_CHOICE.c b/skeletons/constr_CHOICE.c index ac2c525b6..b1378e2fa 100644 --- a/skeletons/constr_CHOICE.c +++ b/skeletons/constr_CHOICE.c @@ -1335,6 +1335,13 @@ asn_TYPE_operation_t asn_OP_CHOICE = { CHOICE_decode_uper, CHOICE_encode_uper, #endif /* ASN_DISABLE_PER_SUPPORT */ +#ifdef ASN_DISABLE_BNER_SUPPORT + 0, + 0, +#else + CHOICE_decode_bner, + CHOICE_encode_bner, +#endif /* ASN_DISABLE_BNER_SUPPORT */ CHOICE_random_fill, CHOICE_outmost_tag }; diff --git a/skeletons/constr_CHOICE.h b/skeletons/constr_CHOICE.h index 764948094..1d1cac268 100644 --- a/skeletons/constr_CHOICE.h +++ b/skeletons/constr_CHOICE.h @@ -51,6 +51,8 @@ oer_type_decoder_f CHOICE_decode_oer; oer_type_encoder_f CHOICE_encode_oer; per_type_decoder_f CHOICE_decode_uper; per_type_encoder_f CHOICE_encode_uper; +bner_type_decoder_f CHOICE_decode_bner; +bner_type_encoder_f CHOICE_encode_bner; asn_outmost_tag_f CHOICE_outmost_tag; asn_random_fill_f CHOICE_random_fill; extern asn_TYPE_operation_t asn_OP_CHOICE; diff --git a/skeletons/constr_SEQUENCE.c b/skeletons/constr_SEQUENCE.c index e4abe2c2d..ebfe3fd0c 100644 --- a/skeletons/constr_SEQUENCE.c +++ b/skeletons/constr_SEQUENCE.c @@ -1552,6 +1552,13 @@ asn_TYPE_operation_t asn_OP_SEQUENCE = { SEQUENCE_decode_uper, SEQUENCE_encode_uper, #endif /* ASN_DISABLE_PER_SUPPORT */ +#ifdef ASN_DISABLE_BNER_SUPPORT + 0, + 0, +#else + SEQUENCE_decode_bner, + SEQUENCE_encode_bner, +#endif /* ASN_DISABLE_BNER_SUPPORT */ SEQUENCE_random_fill, 0 /* Use generic outmost tag fetcher */ }; diff --git a/skeletons/constr_SEQUENCE.h b/skeletons/constr_SEQUENCE.h index f9dd4e5ef..7dad7353a 100644 --- a/skeletons/constr_SEQUENCE.h +++ b/skeletons/constr_SEQUENCE.h @@ -56,6 +56,8 @@ oer_type_decoder_f SEQUENCE_decode_oer; oer_type_encoder_f SEQUENCE_encode_oer; per_type_decoder_f SEQUENCE_decode_uper; per_type_encoder_f SEQUENCE_encode_uper; +bner_type_decoder_f SEQUENCE_decode_bner; +bner_type_encoder_f SEQUENCE_encode_bner; asn_random_fill_f SEQUENCE_random_fill; extern asn_TYPE_operation_t asn_OP_SEQUENCE; diff --git a/skeletons/constr_SEQUENCE_OF.c b/skeletons/constr_SEQUENCE_OF.c index 2fdc38f2a..aad3da553 100644 --- a/skeletons/constr_SEQUENCE_OF.c +++ b/skeletons/constr_SEQUENCE_OF.c @@ -278,6 +278,13 @@ asn_TYPE_operation_t asn_OP_SEQUENCE_OF = { SEQUENCE_OF_decode_uper, /* Same as SET OF decoder */ SEQUENCE_OF_encode_uper, #endif /* ASN_DISABLE_PER_SUPPORT */ +#ifdef ASN_DISABLE_BNER_SUPPORT + 0, + 0, +#else + SEQUENCE_OF_decode_bner, + SEQUENCE_OF_encode_bner, +#endif /* ASN_DISABLE_BNER_SUPPORT */ SEQUENCE_OF_random_fill, 0 /* Use generic outmost tag fetcher */ }; diff --git a/skeletons/constr_SEQUENCE_OF.h b/skeletons/constr_SEQUENCE_OF.h index f21b91e16..58d8c0dbe 100644 --- a/skeletons/constr_SEQUENCE_OF.h +++ b/skeletons/constr_SEQUENCE_OF.h @@ -30,6 +30,8 @@ extern asn_TYPE_operation_t asn_OP_SEQUENCE_OF; #define SEQUENCE_OF_decode_uper SET_OF_decode_uper #define SEQUENCE_OF_decode_oer SET_OF_decode_oer #define SEQUENCE_OF_encode_oer SET_OF_encode_oer +bner_type_decoder_f SEQUENCE_OF_decode_bner; /* BNER does not use SET OF */ +bner_type_encoder_f SEQUENCE_OF_encode_bner; #define SEQUENCE_OF_random_fill SET_OF_random_fill #ifdef __cplusplus diff --git a/skeletons/constr_SET.c b/skeletons/constr_SET.c index 79b3fa768..131106962 100644 --- a/skeletons/constr_SET.c +++ b/skeletons/constr_SET.c @@ -1073,6 +1073,8 @@ asn_TYPE_operation_t asn_OP_SET = { 0, /* SET_encode_oer */ 0, /* SET_decode_uper */ 0, /* SET_encode_uper */ + 0, /* BNER decode */ + 0, /* BNER encode */ SET_random_fill, 0 /* Use generic outmost tag fetcher */ }; diff --git a/skeletons/constr_SET_OF.c b/skeletons/constr_SET_OF.c index 94d99393e..88a2bc3fc 100644 --- a/skeletons/constr_SET_OF.c +++ b/skeletons/constr_SET_OF.c @@ -1202,6 +1202,8 @@ asn_TYPE_operation_t asn_OP_SET_OF = { SET_OF_decode_uper, SET_OF_encode_uper, #endif /* ASN_DISABLE_PER_SUPPORT */ + 0, /* BNER decode */ + 0, /* BNER encode */ SET_OF_random_fill, 0 /* Use generic outmost tag fetcher */ }; diff --git a/skeletons/constr_TYPE.h b/skeletons/constr_TYPE.h index 31102f55f..41f5c262f 100644 --- a/skeletons/constr_TYPE.h +++ b/skeletons/constr_TYPE.h @@ -52,6 +52,9 @@ typedef void asn_oer_constraints_t; #include /* Octet Encoding Rules encoder */ #endif +#include /* BACnet Encoding Rules decoder */ +#include /* BACnet Encoding Rules encoder */ + /* * Free the structure according to its specification. * Use one of ASN_STRUCT_{FREE,RESET,CONTENTS_ONLY} macros instead. @@ -153,6 +156,8 @@ typedef struct asn_TYPE_operation_s { oer_type_encoder_f *oer_encoder; /* Canonical OER encoder */ per_type_decoder_f *uper_decoder; /* Unaligned PER decoder */ per_type_encoder_f *uper_encoder; /* Unaligned PER encoder */ + bner_type_decoder_f *bner_decoder; /* BACnet Encoding Rules decoder */ + bner_type_encoder_f *bner_encoder; /* BACnet Encoding Rules encoder */ asn_random_fill_f *random_fill; /* Initialize with a random value */ asn_outmost_tag_f *outmost_tag; /* */ } asn_TYPE_operation_t; From 7790229ae714ad224913417df7d7160a6a431dc4 Mon Sep 17 00:00:00 2001 From: Jon Ringle Date: Tue, 21 Nov 2017 08:43:15 -0500 Subject: [PATCH 05/12] BNER support: Add skeletons/*_bner.c with stub functions --- skeletons/ANY_bner.c | 41 +++++++++++++++ skeletons/BOOLEAN_bner.c | 42 +++++++++++++++ skeletons/INTEGER_bner.c | 42 +++++++++++++++ skeletons/Makefile.am | 15 ++++++ skeletons/NULL_bner.c | 42 +++++++++++++++ skeletons/NativeInteger_bner.c | 42 +++++++++++++++ skeletons/NativeReal_bner.c | 79 +++++++++++++++++++++++++++++ skeletons/OCTET_STRING_bner.c | 42 +++++++++++++++ skeletons/REAL_bner.c | 42 +++++++++++++++ skeletons/constr_CHOICE_bner.c | 42 +++++++++++++++ skeletons/constr_SEQUENCE_OF_bner.c | 43 ++++++++++++++++ skeletons/constr_SEQUENCE_bner.c | 42 +++++++++++++++ 12 files changed, 514 insertions(+) create mode 100644 skeletons/ANY_bner.c create mode 100644 skeletons/BOOLEAN_bner.c create mode 100644 skeletons/INTEGER_bner.c create mode 100644 skeletons/NULL_bner.c create mode 100644 skeletons/NativeInteger_bner.c create mode 100644 skeletons/NativeReal_bner.c create mode 100644 skeletons/OCTET_STRING_bner.c create mode 100644 skeletons/REAL_bner.c create mode 100644 skeletons/constr_CHOICE_bner.c create mode 100644 skeletons/constr_SEQUENCE_OF_bner.c create mode 100644 skeletons/constr_SEQUENCE_bner.c diff --git a/skeletons/ANY_bner.c b/skeletons/ANY_bner.c new file mode 100644 index 000000000..9003e30f4 --- /dev/null +++ b/skeletons/ANY_bner.c @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2003-2017 Lev Walkin and contributors. + * All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#include +#include + +asn_dec_rval_t +ANY_decode_bner(const asn_codec_ctx_t *opt_codec_ctx, + const asn_TYPE_descriptor_t *td, void **sptr, + const void *buf_ptr, size_t size, ber_tlv_tag_t tag, + int tag_mode) { + (void)opt_codec_ctx; + (void)td; + (void)sptr; + (void)buf_ptr; + (void)size; + (void)tag; + (void)tag_mode; + + asn_dec_rval_t tmp_error = {RC_FAIL, 0}; + ASN_DEBUG("%s Not yet implemented. Failed to decode %s", __func__, + td->name); + return tmp_error; +} + +asn_enc_rval_t +ANY_encode_bner(const asn_TYPE_descriptor_t *td, const void *sptr, int tag_mode, + ber_tlv_tag_t tag, asn_app_consume_bytes_f *cb, void *app_key) { + (void)td; + (void)sptr; + (void)tag_mode; + (void)tag; + (void)cb; + (void)app_key; + + ASN_DEBUG("%s Not yet implemented. Failed to encode %s", __func__, + td->name); + ASN__ENCODE_FAILED; +} diff --git a/skeletons/BOOLEAN_bner.c b/skeletons/BOOLEAN_bner.c new file mode 100644 index 000000000..9ad341791 --- /dev/null +++ b/skeletons/BOOLEAN_bner.c @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2003-2017 Lev Walkin and contributors. + * All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#include +#include + +asn_dec_rval_t +BOOLEAN_decode_bner(const asn_codec_ctx_t *opt_codec_ctx, + const asn_TYPE_descriptor_t *td, void **bool_value, + const void *buf_ptr, size_t size, ber_tlv_tag_t tag, + int tag_mode) { + (void)opt_codec_ctx; + (void)td; + (void)bool_value; + (void)buf_ptr; + (void)size; + (void)tag; + (void)tag_mode; + + asn_dec_rval_t tmp_error = {RC_FAIL, 0}; + ASN_DEBUG("%s Not yet implemented. Failed to decode %s", __func__, + td->name); + return tmp_error; +} + +asn_enc_rval_t +BOOLEAN_encode_bner(const asn_TYPE_descriptor_t *td, const void *sptr, + int tag_mode, ber_tlv_tag_t tag, + asn_app_consume_bytes_f *cb, void *app_key) { + (void)td; + (void)sptr; + (void)tag_mode; + (void)tag; + (void)cb; + (void)app_key; + + ASN_DEBUG("%s Not yet implemented. Failed to encode %s", __func__, + td->name); + ASN__ENCODE_FAILED; +} diff --git a/skeletons/INTEGER_bner.c b/skeletons/INTEGER_bner.c new file mode 100644 index 000000000..ec053f275 --- /dev/null +++ b/skeletons/INTEGER_bner.c @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2003-2017 Lev Walkin and contributors. + * All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#include +#include + +asn_dec_rval_t +INTEGER_decode_bner(const asn_codec_ctx_t *opt_codec_ctx, + const asn_TYPE_descriptor_t *td, void **struct_ptr, + const void *buf_ptr, size_t size, ber_tlv_tag_t tag, + int tag_mode) { + (void)opt_codec_ctx; + (void)td; + (void)struct_ptr; + (void)buf_ptr; + (void)size; + (void)tag; + (void)tag_mode; + + asn_dec_rval_t tmp_error = {RC_FAIL, 0}; + ASN_DEBUG("%s Not yet implemented. Failed to decode %s", __func__, + td->name); + return tmp_error; +} + +asn_enc_rval_t +INTEGER_encode_bner(const asn_TYPE_descriptor_t *td, const void *sptr, + int tag_mode, ber_tlv_tag_t tag, + asn_app_consume_bytes_f *cb, void *app_key) { + (void)td; + (void)sptr; + (void)tag_mode; + (void)tag; + (void)cb; + (void)app_key; + + ASN_DEBUG("%s Not yet implemented. Failed to encode %s", __func__, + td->name); + ASN__ENCODE_FAILED; +} diff --git a/skeletons/Makefile.am b/skeletons/Makefile.am index efc097d6e..ecddc60c4 100644 --- a/skeletons/Makefile.am +++ b/skeletons/Makefile.am @@ -98,6 +98,21 @@ libasn1cskeletons_la_SOURCES = \ check_PROGRAMS = \ check-converter_example \ check-converter_c89_example + +# BNER Support +libasn1cskeletons_la_SOURCES += \ + constr_CHOICE_bner.c \ + constr_SEQUENCE_bner.c \ + constr_SEQUENCE_OF_bner.c \ + ANY_bner.c \ + BOOLEAN_bner.c \ + INTEGER_bner.c \ + NativeInteger_bner.c \ + NativeReal_bner.c \ + NULL_bner.c \ + OCTET_STRING_bner.c \ + REAL_bner.c + LDADD = -lm check_converter_example_CFLAGS = $(TESTSUITE_CFLAGS) -DNO_ASN_PDU diff --git a/skeletons/NULL_bner.c b/skeletons/NULL_bner.c new file mode 100644 index 000000000..e4a32cd92 --- /dev/null +++ b/skeletons/NULL_bner.c @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2003-2017 Lev Walkin and contributors. + * All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#include +#include + +asn_dec_rval_t +NULL_decode_bner(const asn_codec_ctx_t *opt_codec_ctx, + const asn_TYPE_descriptor_t *td, void **struct_ptr, + const void *buf_ptr, size_t size, ber_tlv_tag_t tag, + int tag_mode) { + (void)opt_codec_ctx; + (void)td; + (void)struct_ptr; + (void)buf_ptr; + (void)size; + (void)tag; + (void)tag_mode; + + asn_dec_rval_t tmp_error = {RC_FAIL, 0}; + ASN_DEBUG("%s Not yet implemented. Failed to decode %s", __func__, + td->name); + return tmp_error; +} + +asn_enc_rval_t +NULL_encode_bner(const asn_TYPE_descriptor_t *td, const void *sptr, + int tag_mode, ber_tlv_tag_t tag, asn_app_consume_bytes_f *cb, + void *app_key) { + (void)td; + (void)sptr; + (void)tag_mode; + (void)tag; + (void)cb; + (void)app_key; + + ASN_DEBUG("%s Not yet implemented. Failed to encode %s", __func__, + td->name); + ASN__ENCODE_FAILED; +} diff --git a/skeletons/NativeInteger_bner.c b/skeletons/NativeInteger_bner.c new file mode 100644 index 000000000..775351e49 --- /dev/null +++ b/skeletons/NativeInteger_bner.c @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2003-2017 Lev Walkin and contributors. + * All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#include +#include + +asn_dec_rval_t +NativeInteger_decode_bner(const asn_codec_ctx_t *opt_codec_ctx, + const asn_TYPE_descriptor_t *td, void **nint_ptr, + const void *buf_ptr, size_t size, ber_tlv_tag_t tag, + int tag_mode) { + (void)opt_codec_ctx; + (void)td; + (void)nint_ptr; + (void)buf_ptr; + (void)size; + (void)tag; + (void)tag_mode; + + asn_dec_rval_t tmp_error = {RC_FAIL, 0}; + ASN_DEBUG("%s Not yet implemented. Failed to decode %s", __func__, + td->name); + return tmp_error; +} + +asn_enc_rval_t +NativeInteger_encode_bner(const asn_TYPE_descriptor_t *td, const void *sptr, + int tag_mode, ber_tlv_tag_t tag, + asn_app_consume_bytes_f *cb, void *app_key) { + (void)td; + (void)sptr; + (void)tag_mode; + (void)tag; + (void)cb; + (void)app_key; + + ASN_DEBUG("%s Not yet implemented. Failed to encode %s", __func__, + td->name); + ASN__ENCODE_FAILED; +} diff --git a/skeletons/NativeReal_bner.c b/skeletons/NativeReal_bner.c new file mode 100644 index 000000000..20a48bb71 --- /dev/null +++ b/skeletons/NativeReal_bner.c @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2003-2017 Lev Walkin and contributors. + * All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#include +#include +#include +#include + +asn_dec_rval_t +NativeFloat_decode_bner(const asn_codec_ctx_t *opt_codec_ctx, + const asn_TYPE_descriptor_t *td, void **float_ptr, + const void *buf_ptr, size_t size, ber_tlv_tag_t tag, + int tag_mode) { + (void)opt_codec_ctx; + (void)td; + (void)float_ptr; + (void)buf_ptr; + (void)size; + (void)tag; + (void)tag_mode; + + asn_dec_rval_t tmp_error = {RC_FAIL, 0}; + ASN_DEBUG("%s Not yet implemented. Failed to decode %s", __func__, + td->name); + return tmp_error; +} + +asn_enc_rval_t +NativeFloat_encode_bner(const asn_TYPE_descriptor_t *td, const void *sptr, + int tag_mode, ber_tlv_tag_t tag, + asn_app_consume_bytes_f *cb, void *app_key) { + (void)td; + (void)sptr; + (void)tag_mode; + (void)tag; + (void)cb; + (void)app_key; + + ASN_DEBUG("%s Not yet implemented. Failed to encode %s", __func__, + td->name); + ASN__ENCODE_FAILED; +} + +asn_dec_rval_t +NativeDouble_decode_bner(const asn_codec_ctx_t *opt_codec_ctx, + const asn_TYPE_descriptor_t *td, void **float_ptr, + const void *buf_ptr, size_t size, ber_tlv_tag_t tag, + int tag_mode) { + (void)opt_codec_ctx; + (void)td; + (void)float_ptr; + (void)buf_ptr; + (void)size; + (void)tag; + (void)tag_mode; + + asn_dec_rval_t tmp_error = {RC_FAIL, 0}; + ASN_DEBUG("%s Not yet implemented. Failed to decode %s", __func__, + td->name); + return tmp_error; +} + +asn_enc_rval_t +NativeDouble_encode_bner(const asn_TYPE_descriptor_t *td, const void *sptr, + int tag_mode, ber_tlv_tag_t tag, + asn_app_consume_bytes_f *cb, void *app_key) { + (void)td; + (void)sptr; + (void)tag_mode; + (void)tag; + (void)cb; + (void)app_key; + + ASN_DEBUG("%s Not yet implemented. Failed to encode %s", __func__, + td->name); + ASN__ENCODE_FAILED; +} diff --git a/skeletons/OCTET_STRING_bner.c b/skeletons/OCTET_STRING_bner.c new file mode 100644 index 000000000..6130c90e8 --- /dev/null +++ b/skeletons/OCTET_STRING_bner.c @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2003-2017 Lev Walkin and contributors. + * All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#include +#include + +asn_dec_rval_t +OCTET_STRING_decode_bner(const asn_codec_ctx_t *opt_codec_ctx, + const asn_TYPE_descriptor_t *td, void **sptr, + const void *buf_ptr, size_t size, ber_tlv_tag_t tag, + int tag_mode) { + (void)opt_codec_ctx; + (void)td; + (void)sptr; + (void)buf_ptr; + (void)size; + (void)tag; + (void)tag_mode; + + asn_dec_rval_t tmp_error = {RC_FAIL, 0}; + ASN_DEBUG("%s Not yet implemented. Failed to decode %s", __func__, + td->name); + return tmp_error; +} + +asn_enc_rval_t +OCTET_STRING_encode_bner(const asn_TYPE_descriptor_t *td, const void *sptr, + int tag_mode, ber_tlv_tag_t tag, + asn_app_consume_bytes_f *cb, void *app_key) { + (void)td; + (void)sptr; + (void)tag_mode; + (void)tag; + (void)cb; + (void)app_key; + + ASN_DEBUG("%s Not yet implemented. Failed to encode %s", __func__, + td->name); + ASN__ENCODE_FAILED; +} diff --git a/skeletons/REAL_bner.c b/skeletons/REAL_bner.c new file mode 100644 index 000000000..50eff73d1 --- /dev/null +++ b/skeletons/REAL_bner.c @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2003-2017 Lev Walkin and contributors. + * All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#include +#include + +asn_dec_rval_t +REAL_decode_bner(const asn_codec_ctx_t *opt_codec_ctx, + const asn_TYPE_descriptor_t *td, void **struct_ptr, + const void *buf_ptr, size_t size, ber_tlv_tag_t tag, + int tag_mode) { + (void)opt_codec_ctx; + (void)td; + (void)struct_ptr; + (void)buf_ptr; + (void)size; + (void)tag; + (void)tag_mode; + + asn_dec_rval_t tmp_error = {RC_FAIL, 0}; + ASN_DEBUG("%s Not yet implemented. Failed to decode %s", __func__, + td->name); + return tmp_error; +} + +asn_enc_rval_t +REAL_encode_bner(const asn_TYPE_descriptor_t *td, const void *sptr, + int tag_mode, ber_tlv_tag_t tag, asn_app_consume_bytes_f *cb, + void *app_key) { + (void)td; + (void)sptr; + (void)tag_mode; + (void)tag; + (void)cb; + (void)app_key; + + ASN_DEBUG("%s Not yet implemented. Failed to encode %s", __func__, + td->name); + ASN__ENCODE_FAILED; +} diff --git a/skeletons/constr_CHOICE_bner.c b/skeletons/constr_CHOICE_bner.c new file mode 100644 index 000000000..11c4bf74e --- /dev/null +++ b/skeletons/constr_CHOICE_bner.c @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2003-2017 Lev Walkin and contributors. + * All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#include +#include + +asn_dec_rval_t +CHOICE_decode_bner(const asn_codec_ctx_t *opt_codec_ctx, + const asn_TYPE_descriptor_t *td, void **struct_ptr, + const void *buf_ptr, size_t size, ber_tlv_tag_t tag, + int tag_mode) { + (void)opt_codec_ctx; + (void)td; + (void)struct_ptr; + (void)buf_ptr; + (void)size; + (void)tag; + (void)tag_mode; + + asn_dec_rval_t tmp_error = {RC_FAIL, 0}; + ASN_DEBUG("%s Not yet implemented. Failed to decode %s", __func__, + td->name); + return tmp_error; +} + +asn_enc_rval_t +CHOICE_encode_bner(const asn_TYPE_descriptor_t *td, const void *sptr, + int tag_mode, ber_tlv_tag_t tag, asn_app_consume_bytes_f *cb, + void *app_key) { + (void)td; + (void)sptr; + (void)tag_mode; + (void)tag; + (void)cb; + (void)app_key; + + ASN_DEBUG("%s Not yet implemented. Failed to encode %s", __func__, + td->name); + ASN__ENCODE_FAILED; +} diff --git a/skeletons/constr_SEQUENCE_OF_bner.c b/skeletons/constr_SEQUENCE_OF_bner.c new file mode 100644 index 000000000..25b8c86ab --- /dev/null +++ b/skeletons/constr_SEQUENCE_OF_bner.c @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2003-2017 Lev Walkin and contributors. + * All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#include +#include +#include + +asn_dec_rval_t +SEQUENCE_OF_decode_bner(const asn_codec_ctx_t *opt_codec_ctx, + const asn_TYPE_descriptor_t *td, void **struct_ptr, + const void *buf_ptr, size_t size, ber_tlv_tag_t tag, + int tag_mode) { + (void)opt_codec_ctx; + (void)td; + (void)struct_ptr; + (void)buf_ptr; + (void)size; + (void)tag; + (void)tag_mode; + + asn_dec_rval_t tmp_error = {RC_FAIL, 0}; + ASN_DEBUG("%s Not yet implemented. Failed to decode %s", __func__, + td->name); + return tmp_error; +} + +asn_enc_rval_t +SEQUENCE_OF_encode_bner(const asn_TYPE_descriptor_t *td, const void *sptr, + int tag_mode, ber_tlv_tag_t tag, + asn_app_consume_bytes_f *cb, void *app_key) { + (void)td; + (void)sptr; + (void)tag_mode; + (void)tag; + (void)cb; + (void)app_key; + + ASN_DEBUG("%s Not yet implemented. Failed to encode %s", __func__, + td->name); + ASN__ENCODE_FAILED; +} diff --git a/skeletons/constr_SEQUENCE_bner.c b/skeletons/constr_SEQUENCE_bner.c new file mode 100644 index 000000000..347c1ca95 --- /dev/null +++ b/skeletons/constr_SEQUENCE_bner.c @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2003-2017 Lev Walkin and contributors. + * All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#include +#include + +asn_dec_rval_t +SEQUENCE_decode_bner(const asn_codec_ctx_t *opt_codec_ctx, + const asn_TYPE_descriptor_t *td, void **struct_ptr, + const void *buf_ptr, size_t size, ber_tlv_tag_t tag, + int tag_mode) { + (void)opt_codec_ctx; + (void)td; + (void)struct_ptr; + (void)buf_ptr; + (void)size; + (void)tag; + (void)tag_mode; + + asn_dec_rval_t tmp_error = {RC_FAIL, 0}; + ASN_DEBUG("%s Not yet implemented. Failed to decode %s", __func__, + td->name); + return tmp_error; +} + +asn_enc_rval_t +SEQUENCE_encode_bner(const asn_TYPE_descriptor_t *td, const void *sptr, + int tag_mode, ber_tlv_tag_t tag, + asn_app_consume_bytes_f *cb, void *app_key) { + (void)td; + (void)sptr; + (void)tag_mode; + (void)tag; + (void)cb; + (void)app_key; + + ASN_DEBUG("%s Not yet implemented. Failed to encode %s", __func__, + td->name); + ASN__ENCODE_FAILED; +} From 16ec6b24efe39cc53c8c084b2bfb227b1422bb8d Mon Sep 17 00:00:00 2001 From: Jon Ringle Date: Wed, 29 Nov 2017 01:13:29 -0500 Subject: [PATCH 06/12] BNER support: Add bner tag {en,de}coding --- skeletons/Makefile.am | 1 + skeletons/bner_support.c | 380 +++++++++++++++++++++++++++++++++++++++ skeletons/bner_support.h | 117 ++++++++++++ 3 files changed, 498 insertions(+) create mode 100644 skeletons/bner_support.c create mode 100644 skeletons/bner_support.h diff --git a/skeletons/Makefile.am b/skeletons/Makefile.am index ecddc60c4..3c089489b 100644 --- a/skeletons/Makefile.am +++ b/skeletons/Makefile.am @@ -101,6 +101,7 @@ check_PROGRAMS = \ # BNER Support libasn1cskeletons_la_SOURCES += \ + bner_support.c bner_support.h \ constr_CHOICE_bner.c \ constr_SEQUENCE_bner.c \ constr_SEQUENCE_OF_bner.c \ diff --git a/skeletons/bner_support.c b/skeletons/bner_support.c new file mode 100644 index 000000000..c74bc9c6c --- /dev/null +++ b/skeletons/bner_support.c @@ -0,0 +1,380 @@ +/* + * Copyright (c) 2003-2017 Lev Walkin and contributors. + * All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#include +#include +#include +#include + +ssize_t +bner_tag_lvt_snprint(const bner_tag_lvt_t *tag_lvt, char *buf, size_t size) { + ssize_t out_size; + + out_size = ber_tlv_tag_snprint(tag_lvt->tag, buf, size); + size -= out_size; + buf += out_size; + + switch(tag_lvt->lvt_type) { + case BNER_LVT_LENGTH: + out_size += snprintf(buf, size, " Length:%d", tag_lvt->u.length); + break; + case BNER_LVT_VALUE: + assert(BER_TAG_CLASS(tag_lvt->tag) == ASN_TAG_CLASS_APPLICATION); + assert(BER_TAG_VALUE(tag_lvt->tag) == BNER_APPLICATION_TAG_BOOLEAN); + assert(tag_lvt->u.value == BNER_FALSE || tag_lvt->u.value == BNER_TRUE); + out_size += + snprintf(buf, size, " Value:%s", + (tag_lvt->u.value == BNER_FALSE) ? "false" : "true"); + break; + case BNER_LVT_TYPE: + assert(BER_TAG_CLASS(tag_lvt->tag) == ASN_TAG_CLASS_CONTEXT); + assert(tag_lvt->u.type == BNER_OPENING_TAG + || tag_lvt->u.type == BNER_CLOSING_TAG); + out_size += snprintf( + buf, size, " Tag:%s", + tag_lvt->u.type == BNER_OPENING_TAG ? "opening" : "closing"); + } + + if(out_size <= 0 && size) buf[0] = '\0'; /* against broken libc's */ + + return out_size; +} + +ssize_t +bner_tag_lvt_fwrite(const bner_tag_lvt_t *tag, FILE *f) { + char buf[sizeof("[APPLICATION ] ") + 32]; + ssize_t ret = bner_tag_lvt_snprint(tag, buf, sizeof(buf)); + if(ret >= (ssize_t)sizeof(buf) || ret < 2) { + errno = EPERM; + return -1; + } + + return fwrite(buf, 1, ret, f); +} + +char * +bner_tag_lvt_string(const bner_tag_lvt_t *tag) { + static char buf[sizeof("[APPLICATION ] ") + 32]; + + (void)bner_tag_lvt_snprint(tag, buf, sizeof(buf)); + + return buf; +} + +/* + * Return a standardized complex structure. + */ +#undef RETURN +#define RETURN(_code) \ + do { \ + rval.code = _code; \ + return rval; \ + } while(0) + +asn_dec_rval_t +bner_fetch_tag_lvt(const void *bufp, size_t size, bner_tag_lvt_t *tag_lvt_r) { + const uint8_t *buf = (const uint8_t *)bufp; + ber_tlv_tag_t tclass; + uint8_t lvt = buf[0] & 0x7; + asn_dec_rval_t rval = {RC_OK, 0}; + + if(size == 0) RETURN(RC_WMORE); + + /* 20.2.1.1 */ + tclass = ((buf[0] >> 3) & 0x1) + 1; + rval.consumed++; + + /* 20.2.1.2 */ + if((buf[0] & 0xF0) != 0xF0) + tag_lvt_r->tag = (((buf[0] >> 4) & 0xF) << 2) | tclass; + else { + if(size < 2) RETURN(RC_WMORE); + + if(buf[1] == 0xff) /* Reserved by ASHRAE for future use. */ + RETURN(RC_FAIL); + + tag_lvt_r->tag = (buf[1] << 2) | tclass; + rval.consumed++; + } + + /* 20.2.1.3 */ + if(BER_TAG_CLASS(tag_lvt_r->tag) == ASN_TAG_CLASS_APPLICATION + && BER_TAG_VALUE(tag_lvt_r->tag) == BNER_APPLICATION_TAG_BOOLEAN) { + tag_lvt_r->lvt_type = BNER_LVT_VALUE; + + /* 20.2.1.3.1 */ + if((lvt != BNER_FALSE) && (lvt != BNER_TRUE)) /* Invalid value */ + RETURN(RC_FAIL); + + tag_lvt_r->u.value = lvt; + + } else if((lvt == BNER_OPENING_TAG) || (lvt == BNER_CLOSING_TAG)) { + /* 20.2.1.3.2 */ + tag_lvt_r->lvt_type = BNER_LVT_TYPE; + tag_lvt_r->u.type = lvt; + + } else { + /* 20.2.1.3.1 */ + tag_lvt_r->lvt_type = BNER_LVT_LENGTH; + if(lvt < 5) + tag_lvt_r->u.length = lvt; + else if(lvt == 5) { + if(buf[rval.consumed] == 254) { + if(size < rval.consumed + 2) RETURN(RC_WMORE); + + tag_lvt_r->u.length = + (buf[rval.consumed + 1] << 8) + buf[rval.consumed + 2]; + rval.consumed += 2; + + } else if(buf[rval.consumed] == 255) { + if(size < rval.consumed + 4) RETURN(RC_WMORE); + + tag_lvt_r->u.length = (buf[rval.consumed + 1] << 24) + + (buf[rval.consumed + 2] << 16) + + (buf[rval.consumed + 3] << 8) + + buf[rval.consumed + 4]; + rval.consumed += 4; + + } else + tag_lvt_r->u.length = buf[rval.consumed]; + + rval.consumed++; + } + } + + RETURN(RC_OK); +} + +size_t +bner_tag_lvt_serialize(bner_tag_lvt_t tag_lvt, void *bufp, size_t size) { + uint8_t *buf = (uint8_t *)bufp; + size_t required_size = 1; + + if(BER_TAG_VALUE(tag_lvt.tag) < 15) { + /* Encoded tag in 1st octet */ + if(size) buf[0] = (BER_TAG_VALUE(tag_lvt.tag) & 0xf) << 4; + } else { + if(size > 1) { + buf[0] = 0xf0; + buf[1] = BER_TAG_VALUE(tag_lvt.tag); + } + required_size++; + } + + if(size) buf[0] |= (BER_TAG_CLASS(tag_lvt.tag) - 1) << 3; + + switch(tag_lvt.lvt_type) { + case BNER_LVT_LENGTH: + if(tag_lvt.u.length < 5) { + /* 0 to 4 */ + if(size) buf[0] |= (tag_lvt.u.length & 0x7); + } else if(tag_lvt.u.length < 254) { + /* 5 to 253 */ + required_size++; + if(size >= required_size) { + buf[0] |= 5; + buf[required_size - 1] = (uint8_t)tag_lvt.u.length; + } + } else if(tag_lvt.u.length < 65536) { + /* 254 to 65535 */ + required_size++; + if(size >= required_size + 2) { + buf[0] |= 5; + buf[required_size - 1] = 254; + buf[required_size + 0] = + (uint8_t)(tag_lvt.u.length >> 8) & 0xff; + buf[required_size + 1] = (uint8_t)tag_lvt.u.length & 0xff; + } + required_size += 2; + } else { + /* 65536 to 2^32-1 */ + required_size++; + if(size >= required_size + 4) { + buf[0] |= 5; + buf[required_size - 1] = 255; + buf[required_size + 0] = + (uint8_t)(tag_lvt.u.length >> 24) & 0xff; + buf[required_size + 1] = + (uint8_t)(tag_lvt.u.length >> 16) & 0xff; + buf[required_size + 2] = + (uint8_t)(tag_lvt.u.length >> 8) & 0xff; + buf[required_size + 3] = (uint8_t)tag_lvt.u.length & 0xff; + } + required_size += 4; + } + break; + case BNER_LVT_VALUE: + if(size) buf[0] |= tag_lvt.u.value; + break; + case BNER_LVT_TYPE: + if(size) buf[0] |= tag_lvt.u.type; + break; + } + + return required_size; +} + +ber_tlv_tag_t +convert_ber_to_bner_tag(ber_tlv_tag_t ber_tag) { + /* + * The asn1c compiler will produce UNIVERSAL tags for primative types + * that need to be translated into APPLICATION tags for BACnet encoding + * rules + */ + + /* clang-format off */ + /* -- ***************** Application Types ******************** + * -- The following productions are the definitions of the Application datatypes. + * -- See Clause 20.2.1.4. + * -- NULL [APPLICATION 0], equivalent to [UNIVERSAL 5] + * -- BOOLEAN [APPLICATION 1], equivalent to [UNIVERSAL 1] + * Unsigned ::= [APPLICATION 2] INTEGER (0..MAX) + * Unsigned8 ::= Unsigned (0..255) + * Unsigned16 ::= Unsigned (0..65535) + * Unsigned32 ::= Unsigned (0..4294967295) + * -- INTEGER [APPLICATION 3], equivalent to [UNIVERSAL 2] + * INTEGER16 ::= INTEGER (-32768..32767) + * -- REAL [APPLICATION 4], equivalent to [UNIVERSAL 9] ANSI/IEEE-754 single precision floating point + * Double ::= [APPLICATION 5] OCTET STRING (SIZE(8)) -- ANSI/IEEE-754 double precision floating point + * -- OCTET STRING [APPLICATION 6], equivalent to [UNIVERSAL 4] + * CharacterString ::= [APPLICATION 7] OCTET STRING -- see Clause 20.2.9 for supported types + * -- BIT STRING [APPLICATION 8], equivalent to [UNIVERSAL 3] + * -- ENUMERATED [APPLICATION 9], equivalent to [UNIVERSAL 10] + * Date ::= [APPLICATION 10] OCTET STRING (SIZE(4)) -- see Clause 20.2.12 + * -- first octet year minus 1900, X'FF' = unspecified + * -- second octet month (1.. 14), 1 = January + * -- 13 = odd months + * -- 14 = even months + * -- X'FF' = unspecified + * -- third octet day of month (1..34), 32 = last day of month + * -- 33 = odd days of month + * -- 34 = even days of month + * -- X'FF' = unspecified + * -- fourth octet day of week (1..7) 1 = Monday + * -- 7 = Sunday + * -- X'FF' = unspecified + * Time ::= [APPLICATION 11] OCTET STRING (SIZE(4)) -- see Clause 20.2.13 + * -- first octet hour (0..23), X'FF' = unspecified + * -- second octet minute (0..59), X'FF' = unspecified + * -- third octet second (0..59), X'FF' = unspecified + * -- fourth octet hundredths (0..99) X'FF' = unspecified + * BACnetObjectIdentifier ::= [APPLICATION 12] OCTET STRING (SIZE(4)) -- see Clause 20.2.14 + */ + /* clang-format on */ + + ber_tlv_tag_t bner_tag; + + if(ber_tag == ASN_TAG_AMBIGUOUS) return ber_tag; /* ANY or CHOICE */ + + switch(BER_TAG_CLASS(ber_tag)) { + case ASN_TAG_CLASS_UNIVERSAL: + switch(BER_TAG_VALUE(ber_tag)) { + case 5: + bner_tag = + (BNER_APPLICATION_TAG_NULL << 2) | ASN_TAG_CLASS_APPLICATION; + break; + case 1: + bner_tag = + (BNER_APPLICATION_TAG_BOOLEAN << 2) | ASN_TAG_CLASS_APPLICATION; + break; + case 2: + bner_tag = + (BNER_APPLICATION_TAG_SIGNED << 2) | ASN_TAG_CLASS_APPLICATION; + break; + case 9: + bner_tag = + (BNER_APPLICATION_TAG_REAL << 2) | ASN_TAG_CLASS_APPLICATION; + break; + case 4: + bner_tag = (BNER_APPLICATION_TAG_OCTET_STR << 2) + | ASN_TAG_CLASS_APPLICATION; + break; + case 3: + bner_tag = + (BNER_APPLICATION_TAG_BIT_STR << 2) | ASN_TAG_CLASS_APPLICATION; + break; + case 10: + bner_tag = (BNER_APPLICATION_TAG_ENUMERATED << 2) + | ASN_TAG_CLASS_APPLICATION; + break; + default: + bner_tag = (255 << 2) | ASN_TAG_CLASS_APPLICATION; /* Invalid */ + break; + } + break; + case ASN_TAG_CLASS_APPLICATION: + case ASN_TAG_CLASS_CONTEXT: + bner_tag = ber_tag; + break; + case ASN_TAG_CLASS_PRIVATE: + default: + bner_tag = (255 << 2) | ASN_TAG_CLASS_APPLICATION; /* Invalid */ + break; + } + + return bner_tag; +} + +/* + * This macro "eats" the part of the buffer which is definitely "consumed", + * i.e. was correctly converted into local representation or rightfully skipped. + */ +#undef ADVANCE +#define ADVANCE(num_bytes) \ + do { \ + size_t num = num_bytes; \ + buf_ptr = ((const char *)buf_ptr) + num; \ + size -= num; \ + consumed_myself += num; \ + } while(0) + +/* + * Return a standardized complex structure. + */ +#undef RETURN +#define RETURN(_code) \ + do { \ + rval.code = _code; \ + rval.consumed = consumed_myself; \ + return rval; \ + } while(0) + +asn_dec_rval_t +bner_skip_construct(ber_tlv_tag_t tag, const void *buf_ptr, size_t size) { + size_t consumed_myself = 0; + bner_tag_lvt_t bner_tag; + asn_dec_rval_t rval = bner_fetch_tag_lvt(buf_ptr, size, &bner_tag); + + if(is_bner_opening_tag_match(bner_tag, tag)) { + ADVANCE(rval.consumed); + } else { + ASN_DEBUG("Expected opening tag: %s, but got %s", + ber_tlv_tag_string(tag), bner_tag_lvt_string(&bner_tag)); + RETURN(RC_FAIL); + } + + while(size > 0) { + rval = bner_fetch_tag_lvt(buf_ptr, size, &bner_tag); + + if(is_bner_closing_tag_match(bner_tag, tag)) { + ADVANCE(rval.consumed); + RETURN(RC_OK); + } + + if(rval.code != RC_OK) return rval; + + if(is_bner_opening_tag(bner_tag)) { + rval = bner_skip_construct(bner_tag.tag, buf_ptr, size); + + if(rval.code != RC_OK) return rval; + } + + ADVANCE(rval.consumed + (bner_tag.lvt_type == BNER_LVT_LENGTH + ? bner_tag.u.length + : 0)); + } + + RETURN(RC_WMORE); +} diff --git a/skeletons/bner_support.h b/skeletons/bner_support.h new file mode 100644 index 000000000..bd7af8fe4 --- /dev/null +++ b/skeletons/bner_support.h @@ -0,0 +1,117 @@ +/* + * Copyright (c) 2003-2017 Lev Walkin and contributors. + * All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#ifndef _BNER_SUPPORT_H_ +#define _BNER_SUPPORT_H_ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +int init_bner(void); +void fini_bner(void); +int is_bner_fixed_pdu(const char *pdu_type_name); + +enum bner_application_tag { + BNER_APPLICATION_TAG_NULL = 0, + BNER_APPLICATION_TAG_BOOLEAN = 1, + BNER_APPLICATION_TAG_UNSIGNED = 2, + BNER_APPLICATION_TAG_SIGNED = 3, + BNER_APPLICATION_TAG_REAL = 4, + BNER_APPLICATION_TAG_DOUBLE = 5, + BNER_APPLICATION_TAG_OCTET_STR = 6, + BNER_APPLICATION_TAG_CHAR_STR = 7, + BNER_APPLICATION_TAG_BIT_STR = 8, + BNER_APPLICATION_TAG_ENUMERATED = 9, + BNER_APPLICATION_TAG_DATE = 10, + BNER_APPLICATION_TAG_TIME = 11, + BNER_APPLICATION_TAG_OBJECT_ID = 12 + /* 13, 14, 15 Reserved for ASHRAE */ +}; + +enum bner_lvt_type { + BNER_LVT_LENGTH = 0, + BNER_LVT_VALUE = 1, + BNER_LVT_TYPE = 2 +}; + +enum bner_boolean { BNER_FALSE = 0, BNER_TRUE = 1 }; + +enum bner_construct_tag { BNER_OPENING_TAG = 6, BNER_CLOSING_TAG = 7 }; + +struct bner_tag_lvt_s { + ber_tlv_tag_t tag; + enum bner_lvt_type lvt_type; + union { + uint32_t length; + enum bner_boolean value; + enum bner_construct_tag type; + } u; +}; + +typedef struct bner_tag_lvt_s bner_tag_lvt_t; + +static inline int +is_bner_opening_tag(bner_tag_lvt_t tag) { + return tag.lvt_type == BNER_LVT_TYPE && tag.u.type == BNER_OPENING_TAG; +} +static inline int +is_bner_opening_tag_match(bner_tag_lvt_t tag, ber_tlv_tag_t tag_match) { + return is_bner_opening_tag(tag) && BER_TAGS_EQUAL(tag.tag, tag_match); +} + +static inline int +is_bner_closing_tag(bner_tag_lvt_t tag) { + return tag.lvt_type == BNER_LVT_TYPE && tag.u.type == BNER_CLOSING_TAG; +} +static inline int +is_bner_closing_tag_match(bner_tag_lvt_t tag, ber_tlv_tag_t tag_match) { + return is_bner_closing_tag(tag) && BER_TAGS_EQUAL(tag.tag, tag_match); +} + +ber_tlv_tag_t convert_ber_to_bner_tag(ber_tlv_tag_t ber_tag); + +/* + * Several functions for printing the TAG in the canonical form + * (i.e. "[APPLICATION 1]"). + * Return values correspond to their libc counterparts (if any). + */ +ssize_t bner_tag_lvt_snprint(const bner_tag_lvt_t *tag_lvt, char *buf, + size_t buflen); +ssize_t bner_tag_lvt_fwrite(const bner_tag_lvt_t *tag, FILE *f); +char *bner_tag_lvt_string(const bner_tag_lvt_t *tag); + + +/* + * This function tries to fetch the tag, lvt and length from the BNER input + *stream. + * RETURN VALUES: + * 0: More data expected than bufptr contains. + * -1: Fatal error deciphering tag. + * >0: Number of bytes used from bufptr. tag_lvt_r will populated. + */ +asn_dec_rval_t bner_fetch_tag_lvt(const void *bufp, size_t size, + bner_tag_lvt_t *tag_lvt_r); + +/* + * This function serializes the tag, lvt and length in BNER format. + * It always returns number of bytes necessary to represent the tag, + * it is a caller's responsibility to check the return value + * against the supplied buffer's size. + */ +size_t bner_tag_lvt_serialize(bner_tag_lvt_t tag_lvt, void *bufptr, + size_t size); + +asn_dec_rval_t bner_skip_construct(ber_tlv_tag_t tag, const void *buf_ptr, + size_t size); + +#ifdef __cplusplus +} +#endif + +#endif /* _BNER_SUPPORT_H_ */ From d1ac6310752f8dea4c175c704a32869db2e415c4 Mon Sep 17 00:00:00 2001 From: Jon Ringle Date: Mon, 20 Nov 2017 13:14:26 -0500 Subject: [PATCH 07/12] BNER support: Add top-level bner {en,de}coding The BNER support in the asn1c compiler will only support the BNER variable encoding rules. The bner_{en,de}code() functions will to see if the PDU being {en,de}coded is one that requires BNER fixed encoding rules (these are "BACnet.*PDU". If it is, then it will call bner_fixed_{en,de}coder() These two functions are declared as weak functions that will return an error. The intent here is that an external project will provide replacement functions for these two functions. --- skeletons/Makefile.am | 2 ++ skeletons/bner_decoder.c | 49 +++++++++++++++++++++++++++++ skeletons/bner_decoder.h | 12 +++++++ skeletons/bner_encoder.c | 68 ++++++++++++++++++++++++++++++++++++++++ skeletons/bner_encoder.h | 16 ++++++++++ 5 files changed, 147 insertions(+) create mode 100644 skeletons/bner_decoder.c create mode 100644 skeletons/bner_encoder.c diff --git a/skeletons/Makefile.am b/skeletons/Makefile.am index 3c089489b..4fd9cdb15 100644 --- a/skeletons/Makefile.am +++ b/skeletons/Makefile.am @@ -101,6 +101,8 @@ check_PROGRAMS = \ # BNER Support libasn1cskeletons_la_SOURCES += \ + bner_decoder.c bner_decoder.h \ + bner_encoder.c bner_encoder.h \ bner_support.c bner_support.h \ constr_CHOICE_bner.c \ constr_SEQUENCE_bner.c \ diff --git a/skeletons/bner_decoder.c b/skeletons/bner_decoder.c new file mode 100644 index 000000000..da20f212f --- /dev/null +++ b/skeletons/bner_decoder.c @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2017 Jon Ringle . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#include +#include +#include + +/* + * The BNER decoder of any type. + */ +asn_dec_rval_t +bner_decode(const asn_codec_ctx_t *opt_codec_ctx, + const asn_TYPE_descriptor_t *td, void **struct_ptr, const void *ptr, + size_t size) { + asn_codec_ctx_t s_codec_ctx; + + if(!td) { + asn_dec_rval_t tmp_error = {RC_FAIL, 0}; + ASN_DEBUG("%s: Failed to decode. type_descriptor NULL", __func__); + return tmp_error; + } + + /* + * Stack checker requires that the codec context + * must be allocated on the stack. + */ + if(opt_codec_ctx) { + if(opt_codec_ctx->max_stack_size) { + s_codec_ctx = *opt_codec_ctx; + opt_codec_ctx = &s_codec_ctx; + } + } else { + /* If context is not given, be security-conscious anyway */ + memset(&s_codec_ctx, 0, sizeof(s_codec_ctx)); + s_codec_ctx.max_stack_size = ASN__DEFAULT_STACK_MAX; + opt_codec_ctx = &s_codec_ctx; + } + + /* + * Invoke type-specific decoder. + */ + return td->op->bner_decoder(opt_codec_ctx, td, + struct_ptr, /* Pointer to the dest struct */ + ptr, size, /* Buffer and its size */ + -1, /* Unknown tag */ + 0 /* Default tag mode is 0 */ + ); +} diff --git a/skeletons/bner_decoder.h b/skeletons/bner_decoder.h index 003ff559a..86a478e5c 100644 --- a/skeletons/bner_decoder.h +++ b/skeletons/bner_decoder.h @@ -7,6 +7,7 @@ #define _BNER_DECODER_H_ #include +#include #ifdef __cplusplus extern "C" { @@ -23,6 +24,17 @@ typedef asn_dec_rval_t(bner_type_decoder_f)( const struct asn_TYPE_descriptor_s *td, void **struct_ptr, const void *buf_ptr, size_t size, ber_tlv_tag_t tag, int tag_mode); +/* + * The BNER decoder of any type. + * This function may be invoked directly from the application. + */ +asn_dec_rval_t bner_decode(const struct asn_codec_ctx_s *opt_codec_ctx, + const struct asn_TYPE_descriptor_s *td, + void **struct_ptr, /* Ptr to target's struct ptr */ + const void *buffer, /* Data to be decoded */ + size_t size /* Size of that buffer */ + ); + #ifdef __cplusplus } #endif diff --git a/skeletons/bner_encoder.c b/skeletons/bner_encoder.c new file mode 100644 index 000000000..23088b48e --- /dev/null +++ b/skeletons/bner_encoder.c @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2017 Jon Ringle . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#include +#include +#include + +/* + * The BNER encoder of any type. + */ +asn_enc_rval_t +bner_encode(const asn_TYPE_descriptor_t *td, const void *sptr, + asn_app_consume_bytes_f *consume_bytes, void *app_key) { + if(!td) ASN__ENCODE_FAILED; + + ASN_DEBUG("BNER encoder invoked for %s", td->name); + + /* + * Invoke type-specific encoder. + */ + return td->op->bner_encoder(td, sptr, 0, 0, consume_bytes, app_key); +} + +/* + * Argument type and callback necessary for bner_encode_to_buffer(). + */ +typedef struct enc_to_buf_arg { + void *buffer; + size_t left; +} enc_to_buf_arg; + +static int +encode_to_buffer_cb(const void *buffer, size_t size, void *key) { + enc_to_buf_arg *arg = (enc_to_buf_arg *)key; + + if(arg->left < size) return -1; /* Data exceeds the available buffer size */ + + memcpy(arg->buffer, buffer, size); + arg->buffer = ((char *)arg->buffer) + size; + arg->left -= size; + + return 0; +} + +/* + * A variant of the bner_encode() which encodes the data into the provided + * buffer + */ +asn_enc_rval_t +bner_encode_to_buffer(const asn_TYPE_descriptor_t *td, const void *struct_ptr, + void *buffer, size_t buffer_size) { + enc_to_buf_arg arg; + asn_enc_rval_t ec; + + arg.buffer = buffer; + arg.left = buffer_size; + + ec = td->op->bner_encoder( + td, struct_ptr, /* Pointer to the destination structure */ + 0, 0, encode_to_buffer_cb, &arg); + + if(ec.encoded != -1) { + assert(ec.encoded == (ssize_t)(buffer_size - arg.left)); + /* Return the encoded contents size */ + } + return ec; +} diff --git a/skeletons/bner_encoder.h b/skeletons/bner_encoder.h index c8bbe57a5..56f86a087 100644 --- a/skeletons/bner_encoder.h +++ b/skeletons/bner_encoder.h @@ -7,6 +7,7 @@ #define _BNER_ENCODER_H_ #include +#include #ifdef __cplusplus extern "C" { @@ -26,6 +27,21 @@ typedef asn_enc_rval_t(bner_type_encoder_f)( void *app_key /* Arbitrary callback argument */ ); +/* + * The BNER encoder of any type. + * This function may be invoked directly by the application. + */ +asn_enc_rval_t bner_encode(const struct asn_TYPE_descriptor_s *td, + const void *struct_ptr, /* Structure to be encoded */ + asn_app_consume_bytes_f *consume_bytes_cb, + void *app_key /* Arbitrary callback argument */ + ); + +/* A variant of bner_encode() which encodes data into a pre-allocated buffer */ +asn_enc_rval_t bner_encode_to_buffer(const struct asn_TYPE_descriptor_s *td, + const void *struct_ptr, void *buffer, + size_t buffer_size); + #ifdef __cplusplus } #endif From 3e69bc95bf7bb9c5a986e09b30bb77e58620da68 Mon Sep 17 00:00:00 2001 From: Jon Ringle Date: Tue, 21 Nov 2017 09:23:33 -0500 Subject: [PATCH 08/12] BNER support: Add -gen-BNER option --- asn1c/asn1c.c | 4 ++++ asn1c/unber.c | 1 + libasn1compiler/asn1c_C.c | 4 ++++ libasn1compiler/asn1c_fdeps.c | 4 ++++ libasn1compiler/asn1c_fdeps.h | 1 + libasn1compiler/asn1c_save.c | 3 ++- libasn1compiler/asn1compiler.h | 5 +++++ skeletons/file-dependencies | 16 ++++++++++++++++ 8 files changed, 37 insertions(+), 1 deletion(-) diff --git a/asn1c/asn1c.c b/asn1c/asn1c.c index b67f9e710..611f36b30 100644 --- a/asn1c/asn1c.c +++ b/asn1c/asn1c.c @@ -155,6 +155,8 @@ main(int ac, char **av) { asn1_compiler_flags |= A1C_GEN_PER; } else if(strcmp(optarg, "en-OER") == 0) { asn1_compiler_flags |= A1C_GEN_OER; + } else if(strcmp(optarg, "en-BNER") == 0) { + asn1_compiler_flags |= A1C_GEN_BNER; } else if(strcmp(optarg, "en-example") == 0) { asn1_compiler_flags |= A1C_GEN_EXAMPLE; } else if(strcmp(optarg, "en-autotools") == 0) { @@ -171,6 +173,8 @@ main(int ac, char **av) { asn1_compiler_flags &= ~A1C_GEN_PER; } else if(strcmp(optarg, "o-gen-OER") == 0) { asn1_compiler_flags &= ~A1C_GEN_OER; + } else if(strcmp(optarg, "o-gen-BNER") == 0) { + asn1_compiler_flags &= ~A1C_GEN_BNER; } else if(strcmp(optarg, "o-gen-example") == 0) { asn1_compiler_flags &= ~A1C_GEN_EXAMPLE; } else if(strcmp(optarg, "o-gen-autotools") == 0) { diff --git a/asn1c/unber.c b/asn1c/unber.c index a34492116..8904c3aba 100644 --- a/asn1c/unber.c +++ b/asn1c/unber.c @@ -29,6 +29,7 @@ #define ASN_DISABLE_PER_SUPPORT 1 #define ASN_DISABLE_OER_SUPPORT 1 +#define ASN_DISABLE_BNER_SUPPORT 1 #include /* For static string tables */ diff --git a/libasn1compiler/asn1c_C.c b/libasn1compiler/asn1c_C.c index bdf78f5f5..3bac8683e 100644 --- a/libasn1compiler/asn1c_C.c +++ b/libasn1compiler/asn1c_C.c @@ -1440,6 +1440,10 @@ asn1c_lang_C_type_SIMPLE_TYPE(arg_t *arg) { OUT("per_type_decoder_f %s_decode_uper;\n", p); OUT("per_type_encoder_f %s_encode_uper;\n", p); } + if(arg->flags & A1C_GEN_BNER) { + OUT("bner_type_decoder_f %s_decode_bner;\n", p); + OUT("bner_type_encoder_f %s_encode_bner;\n", p); + } } REDIR(saved_target); diff --git a/libasn1compiler/asn1c_fdeps.c b/libasn1compiler/asn1c_fdeps.c index 60a52cbb9..d508e4cbc 100644 --- a/libasn1compiler/asn1c_fdeps.c +++ b/libasn1compiler/asn1c_fdeps.c @@ -124,6 +124,10 @@ asn1c_read_file_dependencies(arg_t *arg, const char *datadir) { && strcmp(p, "CODEC-PER:") == 0) { activate = 0; section = FDEP_CODEC_PER; + } else if((arg->flags & A1C_GEN_BNER) + && strcmp(p, "CODEC-BNER:") == 0) { + activate = 1; + section = FDEP_CODEC_BNER; } else { section = FDEP_IGNORE; activate = 0; diff --git a/libasn1compiler/asn1c_fdeps.h b/libasn1compiler/asn1c_fdeps.h index 7b025babb..480fac0ba 100644 --- a/libasn1compiler/asn1c_fdeps.h +++ b/libasn1compiler/asn1c_fdeps.h @@ -29,6 +29,7 @@ typedef struct { FDEP_COMMON_FILES = (1 << 4), /* Section for mandatory dependencies */ FDEP_CODEC_OER = (1 << 5), /* Use contents only if -gen-OER */ FDEP_CODEC_PER = (1 << 6), /* Use contents only if -gen-PER */ + FDEP_CODEC_BNER = (1 << 7), /* Use contents only if -gen-BNER */ } section; /* Some file refers to it */ /* Whether this chain is alive and has to be present in the output */ diff --git a/libasn1compiler/asn1c_save.c b/libasn1compiler/asn1c_save.c index 79f3b244c..a957af59c 100644 --- a/libasn1compiler/asn1c_save.c +++ b/libasn1compiler/asn1c_save.c @@ -145,7 +145,8 @@ asn1c__save_library_makefile(arg_t *arg, const asn1c_dep_chainset *deps, safe_fprintf( mkf, "\n" - "ASN_MODULE_CFLAGS=%s%s", + "ASN_MODULE_CFLAGS=%s%s%s", + (arg->flags & A1C_GEN_BNER) ? "" : "-DASN_DISABLE_BNER_SUPPORT ", (arg->flags & A1C_GEN_OER) ? "" : "-DASN_DISABLE_OER_SUPPORT ", (arg->flags & A1C_GEN_PER) ? "" : "-DASN_DISABLE_PER_SUPPORT "); diff --git a/libasn1compiler/asn1compiler.h b/libasn1compiler/asn1compiler.h index 2901d4079..9337f5984 100644 --- a/libasn1compiler/asn1compiler.h +++ b/libasn1compiler/asn1compiler.h @@ -97,6 +97,11 @@ enum asn1c_flags { * -debug-output-origin-lines */ A1C_DEBUG_OUTPUT_ORIGIN_LINES = 0x400000, + /* + * -gen-BNER + * Generate BACnet Encoding Rules support code + */ + A1C_GEN_BNER = 0x800000, }; /* diff --git a/skeletons/file-dependencies b/skeletons/file-dependencies index 59e2ce68f..5f7564ca5 100644 --- a/skeletons/file-dependencies +++ b/skeletons/file-dependencies @@ -65,6 +65,9 @@ per_support.h per_support.c # PER parsing per_decoder.h per_decoder.c # PER decoding support per_encoder.h per_encoder.c # PER encoding support per_opentype.h per_opentype.c # PER "open type" handling +bner_support.h bner_support.c # BNER tag support +bner_decoder.h bner_decoder.c # BNER decoding support +bner_encoder.h bner_encoder.c # BNER encoding support CONVERTER: # THIS IS A SPECIAL SECTION converter-example.c # A default name for the example transcoder @@ -87,3 +90,16 @@ constr_SEQUENCE.h constr_SEQUENCE_oer.c constr_SET_OF.h constr_SET_OF_oer.c CODEC-PER: # THIS IS A SPECIAL SECTION + +CODEC-BNER: # THIS IS A SPECIAL SECTION +constr_CHOICE.h constr_CHOICE_bner.c +constr_SEQUENCE.h constr_SEQUENCE_bner.c +constr_SEQUENCE_OF.h constr_SEQUENCE_OF_bner.c constr_SET_OF.h asn_SEQUENCE_OF.h asn_SET_OF.h +ANY.h ANY_bner.c +BOOLEAN.h BOOLEAN_bner.c +INTEGER.h INTEGER_bner.c +NativeInteger.h NativeInteger_bner.c +NativeReal.h NativeReal_bner.c +NULL.h NULL_bner.c +OCTET_STRING.h OCTET_STRING_bner.c +REAL.h REAL_bner.c From 8ee5eedd9caa2d8d55fa9a441491c533d4aca765 Mon Sep 17 00:00:00 2001 From: Jon Ringle Date: Tue, 21 Nov 2017 09:39:14 -0500 Subject: [PATCH 09/12] BNER support: converter-example --- skeletons/asn_application.c | 30 ++++++++++++++++++++++++++++++ skeletons/asn_application.h | 7 ++++++- skeletons/converter-example.c | 9 ++++++++- 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/skeletons/asn_application.c b/skeletons/asn_application.c index 8ce0261b8..4c6ef8c2c 100644 --- a/skeletons/asn_application.c +++ b/skeletons/asn_application.c @@ -374,6 +374,28 @@ asn_encode_internal(const asn_codec_ctx_t *opt_codec_ctx, } break; + case ATS_BNER: +#ifdef ASN_DISABLE_BNER_SUPPORT + errno = ENOENT; /* BNER is not defined. */ + ASN__ENCODE_FAILED; + break; +#else + if(td->op->bner_encoder) { + er = bner_encode(td, sptr, callback, callback_key); + if(er.encoded == -1) { + if(er.failed_type && er.failed_type->op->bner_encoder) { + errno = EBADF; /* Structure has incorrect form. */ + } else { + errno = ENOENT; /* BNER is not defined for this type. */ + } + } + } else { + errno = ENOENT; /* Transfer syntax is not defined for this type. */ + ASN__ENCODE_FAILED; + } + break; +#endif /* ASN_DISABLE_BNER_SUPPORT */ + default: errno = ENOENT; ASN__ENCODE_FAILED; @@ -435,6 +457,14 @@ asn_decode(const asn_codec_ctx_t *opt_codec_ctx, case ATS_BASIC_XER: case ATS_CANONICAL_XER: return xer_decode(opt_codec_ctx, td, sptr, buffer, size); + + case ATS_BNER: +#ifdef ASN_DISABLE_BNER_SUPPORT + errno = ENOENT; + ASN__DECODE_FAILED; +#else + return bner_decode(opt_codec_ctx, td, sptr, buffer, size); +#endif } } diff --git a/skeletons/asn_application.h b/skeletons/asn_application.h index 3ca9f138e..2b38f299e 100644 --- a/skeletons/asn_application.h +++ b/skeletons/asn_application.h @@ -57,7 +57,12 @@ enum asn_transfer_syntax { * CANONICAL-XER is a more strict variant of BASIC-XER. */ ATS_BASIC_XER, - ATS_CANONICAL_XER + ATS_CANONICAL_XER, + /* + * ASHRAE 135: + * BNER: BACnet Encoding Rules. + */ + ATS_BNER }; /* diff --git a/skeletons/converter-example.c b/skeletons/converter-example.c index b54045250..b89b96034 100644 --- a/skeletons/converter-example.c +++ b/skeletons/converter-example.c @@ -126,6 +126,8 @@ ats_simple_name(enum asn_transfer_syntax syntax) { case ATS_UNALIGNED_BASIC_PER: case ATS_UNALIGNED_CANONICAL_PER: return "PER"; + case ATS_BNER: + return "BNER"; default: return ""; } @@ -148,6 +150,8 @@ static syntax_selector input_encodings[] = { "Input is in Unaligned PER (Packed Encoding Rules)"}, {"xer", ATS_BASIC_XER, CODEC_OFFSET(xer_decoder), "Input is in XER (XML Encoding Rules)"}, + {"bner", ATS_BNER, CODEC_OFFSET(bner_decoder), + "Input is in BNER (BACnet Encoding Rules)"}, {0, ATS_INVALID, 0, 0}}; static syntax_selector output_encodings[] = { @@ -159,6 +163,8 @@ static syntax_selector output_encodings[] = { "Output as Unaligned PER (Packed Encoding Rules)"}, {"xer", ATS_BASIC_XER, CODEC_OFFSET(xer_encoder), "Output as XER (XML Encoding Rules)"}, + {"bner", ATS_BNER, CODEC_OFFSET(bner_encoder), + "Output as BNER (BACnet Encoding Rules)"}, {"text", ATS_NONSTANDARD_PLAINTEXT, CODEC_OFFSET(print_struct), "Output as plain semi-structured text"}, {"null", ATS_INVALID, CODEC_OFFSET(print_struct), @@ -355,7 +361,8 @@ main(int ac, char *av[]) { fprintf(stderr, "Where options are:\n"); for(sel = input_encodings; sel->name; sel++) { if(ats_by_name(sel->name, anyPduType, sel)) { - fprintf(stderr, " -i%s %s%s\n", sel->name, + fprintf(stderr, " -i%s%s %s%s\n", sel->name, + strlen(sel->name) > 3 ? "" : " ", sel->full_name, (sel->syntax == isyntax) ? " (DEFAULT)" : ""); } From 4b6148e321ba9fc8f1c1ba641cfa95a929469159 Mon Sep 17 00:00:00 2001 From: Jon Ringle Date: Fri, 1 Dec 2017 03:09:19 -0500 Subject: [PATCH 10/12] define CC_WEAK_ALIAS --- skeletons/asn_system.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/skeletons/asn_system.h b/skeletons/asn_system.h index fa8cf1165..6c4e1e459 100644 --- a/skeletons/asn_system.h +++ b/skeletons/asn_system.h @@ -83,8 +83,12 @@ typedef unsigned int uint32_t; #if __GNUC__ >= 3 || defined(__clang__) #define CC_ATTRIBUTE(attr) __attribute__((attr)) +#define CC_WEAK_ALIAS(name, aliasname) _CC_WEAK_ALIAS(name, aliasname) +#define _CC_WEAK_ALIAS(name, aliasname) \ + extern __typeof (name) aliasname __attribute__ ((weak, alias (#name))) #else #define CC_ATTRIBUTE(attr) +#define CC_WEAK_ALIAS(name, aliasname) #endif #define CC_PRINTFLIKE(fmt, var) CC_ATTRIBUTE(format(printf, fmt, var)) #define CC_NOTUSED CC_ATTRIBUTE(unused) From 19e35587133cfb94736a86f9f4c09a9c7caf01c4 Mon Sep 17 00:00:00 2001 From: Jon Ringle Date: Fri, 1 Dec 2017 03:34:22 -0500 Subject: [PATCH 11/12] BNER: Add weak function stubs for BNER fixed encoded PDUs --- libasn1compiler/asn1c_C.c | 32 +- skeletons/Makefile.am | 29 +- skeletons/bner_fixed_stubs.c | 870 +++++++++++++++++++++++++++++++++++ skeletons/bner_fixed_stubs.h | 60 +++ skeletons/constr_TYPE.h | 2 + skeletons/file-dependencies | 1 + 6 files changed, 979 insertions(+), 15 deletions(-) create mode 100644 skeletons/bner_fixed_stubs.c create mode 100644 skeletons/bner_fixed_stubs.h diff --git a/libasn1compiler/asn1c_C.c b/libasn1compiler/asn1c_C.c index 3bac8683e..211a62cbb 100644 --- a/libasn1compiler/asn1c_C.c +++ b/libasn1compiler/asn1c_C.c @@ -75,6 +75,31 @@ enum etd_spec { }; static int emit_type_DEF(arg_t *arg, asn1p_expr_t *expr, enum tvm_compat tv_mode, int tags_count, int all_tags_count, int elements_count, enum etd_spec); +static const char* bner_fixed_encoding_pdus[] = { + "BACnetPDU", + "BACnet-Confirmed-Request-PDU", + "BACnet-Unconfirmed-Request-PDU", + "BACnet-SimpleACK-PDU", + "BACnet-ComplexACK-PDU", + "BACnet-SegmentACK-PDU", + "BACnet-Error-PDU", + "BACnet-Reject-PDU", + "BACnet-Abort-PDU", + "BACnet-Confirmed-Service-Request", + "BACnet-Unconfirmed-Service-Request", + "BACnet-Confirmed-Service-ACK", + "BACnet-Error", + 0 +}; + +static int is_bner_fixed_encoding_pdu(const char *pdu_type_name) { + for (int i = 0; bner_fixed_encoding_pdus[i]; ++i) { + if(!strcmp(bner_fixed_encoding_pdus[i], pdu_type_name)) + return 1; + } + return 0; +} + #define C99_MODE (!(arg->flags & A1C_NO_C99)) #define UNNAMED_UNIONS (arg->flags & A1C_UNNAMED_UNIONS) #define HIDE_INNER_DEFS (arg->embed && !(arg->flags & A1C_ALL_DEFS_GLOBAL)) @@ -2980,7 +3005,12 @@ emit_type_DEF(arg_t *arg, asn1p_expr_t *expr, enum tvm_compat tv_mode, int tags_ if (!p2) p2 = strdup(p); - OUT("&asn_OP_%s,\n", p2); + if(arg->flags & A1C_GEN_BNER + && is_bner_fixed_encoding_pdu(expr->Identifier)) { + OUT("&asn_OP_%s,\n", expr_id); + } else { + OUT("&asn_OP_%s,\n", p2); + } if(tags_count) { OUT("asn_DEF_%s_tags_%d,\n", diff --git a/skeletons/Makefile.am b/skeletons/Makefile.am index 4fd9cdb15..aa6e8eb9e 100644 --- a/skeletons/Makefile.am +++ b/skeletons/Makefile.am @@ -100,20 +100,21 @@ check_PROGRAMS = \ check-converter_c89_example # BNER Support -libasn1cskeletons_la_SOURCES += \ - bner_decoder.c bner_decoder.h \ - bner_encoder.c bner_encoder.h \ - bner_support.c bner_support.h \ - constr_CHOICE_bner.c \ - constr_SEQUENCE_bner.c \ - constr_SEQUENCE_OF_bner.c \ - ANY_bner.c \ - BOOLEAN_bner.c \ - INTEGER_bner.c \ - NativeInteger_bner.c \ - NativeReal_bner.c \ - NULL_bner.c \ - OCTET_STRING_bner.c \ +libasn1cskeletons_la_SOURCES += \ + bner_decoder.c bner_decoder.h \ + bner_encoder.c bner_encoder.h \ + bner_fixed_stubs.c bner_fixed_stubs.h \ + bner_support.c bner_support.h \ + constr_CHOICE_bner.c \ + constr_SEQUENCE_bner.c \ + constr_SEQUENCE_OF_bner.c \ + ANY_bner.c \ + BOOLEAN_bner.c \ + INTEGER_bner.c \ + NativeInteger_bner.c \ + NativeReal_bner.c \ + NULL_bner.c \ + OCTET_STRING_bner.c \ REAL_bner.c LDADD = -lm diff --git a/skeletons/bner_fixed_stubs.c b/skeletons/bner_fixed_stubs.c new file mode 100644 index 000000000..b621ccd68 --- /dev/null +++ b/skeletons/bner_fixed_stubs.c @@ -0,0 +1,870 @@ +/* + * Copyright (c) 2003-2017 Lev Walkin and contributors. + * All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#include +#include +#include +#include + +/* + * BACnet defines two different encodings: + * 1) Fixed encoding (Clause 20.1) + * The fixed encoding is used on the following PDUs: + * BACnetPDU + * BACnet-Confirmed-Request-PDU + * BACnet-Unconfirmed-Request-PDU + * BACnet-SimpleACK-PDU + * BACnet-ComplexACK-PDU + * BACnet-SegmentACK-PDU + * BACnet-Error-PDU + * BACnet-Reject-PDU + * BACnet-Abort-PDU + * BACnet-Confirmed-Service-Request + * BACnet-Unconfirmed-Service-Request + * BACnet-Confirmed-Service-ACK + * BACnet-Error + * + * The fixed encoding is outside the scope of the asn1 compiler, and + * only a weak function that fails encoding/decoding these PDUs is provided here + * + * 2) Variable encoding (Clause 20.2) + * All other BACnet rules are encoded with the BNER variable encoding. + * This encoding is provided for in the asn1 compiler + */ + +asn_TYPE_operation_t asn_OP_BACnetPDU = {CHOICE_free, + CHOICE_print, + CHOICE_compare, + CHOICE_decode_ber, + CHOICE_encode_der, + CHOICE_decode_xer, + CHOICE_encode_xer, +#ifdef ASN_DISABLE_OER_SUPPORT + 0, + 0, +#else + CHOICE_decode_oer, + CHOICE_encode_oer, +#endif /* ASN_DISABLE_OER_SUPPORT */ +#ifdef ASN_DISABLE_PER_SUPPORT + 0, + 0, +#else + CHOICE_decode_uper, + CHOICE_encode_uper, +#endif /* ASN_DISABLE_PER_SUPPORT */ +#ifdef ASN_DISABLE_BNER_SUPPORT + 0, + 0, +#else + CHOICE_decode_BACnetPDU, + CHOICE_encode_BACnetPDU, +#endif /* ASN_DISABLE_BNER_SUPPORT */ + CHOICE_random_fill, + CHOICE_outmost_tag}; + +asn_dec_rval_t +CC_ATTRIBUTE(weak) + CHOICE_decode_BACnetPDU(const struct asn_codec_ctx_s *opt_codec_ctx, + const struct asn_TYPE_descriptor_s *td, + void **struct_ptr, const void *buffer, size_t size, + ber_tlv_tag_t tag, int tag_mode) { + (void)opt_codec_ctx; + (void)td; + (void)struct_ptr; + (void)buffer; + (void)size; + (void)tag; + (void)tag_mode; + ASN_DEBUG("Missing %s", __func__); + ASN__DECODE_FAILED; +} + +asn_enc_rval_t +CC_ATTRIBUTE(weak) + CHOICE_encode_BACnetPDU(const struct asn_TYPE_descriptor_s *td, + const void *sptr, int tag_mode, ber_tlv_tag_t tag, + asn_app_consume_bytes_f *consume_bytes_cb, + void *app_key) { + (void)td; + (void)sptr; + (void)tag_mode; + (void)tag; + (void)consume_bytes_cb; + (void)app_key; + ASN_DEBUG("Missing %s", __func__); + ASN__ENCODE_FAILED; +} + +asn_TYPE_operation_t asn_OP_BACnet_Confirmed_Request_PDU = { + SEQUENCE_free, + SEQUENCE_print, + SEQUENCE_compare, + SEQUENCE_decode_ber, + SEQUENCE_encode_der, + SEQUENCE_decode_xer, + SEQUENCE_encode_xer, +#ifdef ASN_DISABLE_OER_SUPPORT + 0, + 0, +#else + SEQUENCE_decode_oer, + SEQUENCE_encode_oer, +#endif /* ASN_DISABLE_OER_SUPPORT */ +#ifdef ASN_DISABLE_PER_SUPPORT + 0, + 0, +#else + SEQUENCE_decode_uper, + SEQUENCE_encode_uper, +#endif /* ASN_DISABLE_PER_SUPPORT */ +#ifdef ASN_DISABLE_BNER_SUPPORT + 0, + 0, +#else + SEQUENCE_decode_BACnet_Confirmed_Request_PDU, + SEQUENCE_encode_BACnet_Confirmed_Request_PDU, +#endif /* ASN_DISABLE_BNER_SUPPORT */ + SEQUENCE_random_fill, + 0 /* Use generic outmost tag fetcher */ +}; + +asn_dec_rval_t +CC_ATTRIBUTE(weak) SEQUENCE_decode_BACnet_Confirmed_Request_PDU( + const struct asn_codec_ctx_s *opt_codec_ctx, + const struct asn_TYPE_descriptor_s *td, void **struct_ptr, + const void *buffer, size_t size, ber_tlv_tag_t tag, int tag_mode) { + (void)opt_codec_ctx; + (void)td; + (void)struct_ptr; + (void)buffer; + (void)size; + (void)tag; + (void)tag_mode; + ASN_DEBUG("Missing %s", __func__); + ASN__DECODE_FAILED; +} + +asn_enc_rval_t +CC_ATTRIBUTE(weak) SEQUENCE_encode_BACnet_Confirmed_Request_PDU( + const struct asn_TYPE_descriptor_s *td, const void *sptr, int tag_mode, + ber_tlv_tag_t tag, asn_app_consume_bytes_f *consume_bytes_cb, + void *app_key) { + (void)td; + (void)sptr; + (void)tag_mode; + (void)tag; + (void)consume_bytes_cb; + (void)app_key; + ASN_DEBUG("Missing %s", __func__); + ASN__ENCODE_FAILED; +} + +asn_TYPE_operation_t asn_OP_BACnet_Unconfirmed_Request_PDU = { + SEQUENCE_free, + SEQUENCE_print, + SEQUENCE_compare, + SEQUENCE_decode_ber, + SEQUENCE_encode_der, + SEQUENCE_decode_xer, + SEQUENCE_encode_xer, +#ifdef ASN_DISABLE_OER_SUPPORT + 0, + 0, +#else + SEQUENCE_decode_oer, + SEQUENCE_encode_oer, +#endif /* ASN_DISABLE_OER_SUPPORT */ +#ifdef ASN_DISABLE_PER_SUPPORT + 0, + 0, +#else + SEQUENCE_decode_uper, + SEQUENCE_encode_uper, +#endif /* ASN_DISABLE_PER_SUPPORT */ +#ifdef ASN_DISABLE_BNER_SUPPORT + 0, + 0, +#else + SEQUENCE_decode_BACnet_Unconfirmed_Request_PDU, + SEQUENCE_encode_BACnet_Unconfirmed_Request_PDU, +#endif /* ASN_DISABLE_BNER_SUPPORT */ + SEQUENCE_random_fill, + 0 /* Use generic outmost tag fetcher */ +}; + +asn_dec_rval_t +CC_ATTRIBUTE(weak) SEQUENCE_decode_BACnet_Unconfirmed_Request_PDU( + const struct asn_codec_ctx_s *opt_codec_ctx, + const struct asn_TYPE_descriptor_s *td, void **struct_ptr, + const void *buffer, size_t size, ber_tlv_tag_t tag, int tag_mode) { + (void)opt_codec_ctx; + (void)td; + (void)struct_ptr; + (void)buffer; + (void)size; + (void)tag; + (void)tag_mode; + ASN_DEBUG("Missing %s", __func__); + ASN__DECODE_FAILED; +} + +asn_enc_rval_t +CC_ATTRIBUTE(weak) SEQUENCE_encode_BACnet_Unconfirmed_Request_PDU( + const struct asn_TYPE_descriptor_s *td, const void *sptr, int tag_mode, + ber_tlv_tag_t tag, asn_app_consume_bytes_f *consume_bytes_cb, + void *app_key) { + (void)td; + (void)sptr; + (void)tag_mode; + (void)tag; + (void)consume_bytes_cb; + (void)app_key; + ASN_DEBUG("Missing %s", __func__); + ASN__ENCODE_FAILED; +} + +asn_TYPE_operation_t asn_OP_BACnet_SimpleACK_PDU = { + SEQUENCE_free, + SEQUENCE_print, + SEQUENCE_compare, + SEQUENCE_decode_ber, + SEQUENCE_encode_der, + SEQUENCE_decode_xer, + SEQUENCE_encode_xer, +#ifdef ASN_DISABLE_OER_SUPPORT + 0, + 0, +#else + SEQUENCE_decode_oer, + SEQUENCE_encode_oer, +#endif /* ASN_DISABLE_OER_SUPPORT */ +#ifdef ASN_DISABLE_PER_SUPPORT + 0, + 0, +#else + SEQUENCE_decode_uper, + SEQUENCE_encode_uper, +#endif /* ASN_DISABLE_PER_SUPPORT */ +#ifdef ASN_DISABLE_BNER_SUPPORT + 0, + 0, +#else + SEQUENCE_decode_BACnet_SimpleACK_PDU, + SEQUENCE_encode_BACnet_SimpleACK_PDU, +#endif /* ASN_DISABLE_BNER_SUPPORT */ + SEQUENCE_random_fill, + 0 /* Use generic outmost tag fetcher */ +}; + +asn_dec_rval_t +CC_ATTRIBUTE(weak) SEQUENCE_decode_BACnet_SimpleACK_PDU( + const struct asn_codec_ctx_s *opt_codec_ctx, + const struct asn_TYPE_descriptor_s *td, void **struct_ptr, + const void *buffer, size_t size, ber_tlv_tag_t tag, int tag_mode) { + (void)opt_codec_ctx; + (void)td; + (void)struct_ptr; + (void)buffer; + (void)size; + (void)tag; + (void)tag_mode; + ASN_DEBUG("Missing %s", __func__); + ASN__DECODE_FAILED; +} + +asn_enc_rval_t +CC_ATTRIBUTE(weak) SEQUENCE_encode_BACnet_SimpleACK_PDU( + const struct asn_TYPE_descriptor_s *td, const void *sptr, int tag_mode, + ber_tlv_tag_t tag, asn_app_consume_bytes_f *consume_bytes_cb, + void *app_key) { + (void)td; + (void)sptr; + (void)tag_mode; + (void)tag; + (void)consume_bytes_cb; + (void)app_key; + ASN_DEBUG("Missing %s", __func__); + ASN__ENCODE_FAILED; +} + +asn_TYPE_operation_t asn_OP_BACnet_ComplexACK_PDU = { + SEQUENCE_free, + SEQUENCE_print, + SEQUENCE_compare, + SEQUENCE_decode_ber, + SEQUENCE_encode_der, + SEQUENCE_decode_xer, + SEQUENCE_encode_xer, +#ifdef ASN_DISABLE_OER_SUPPORT + 0, + 0, +#else + SEQUENCE_decode_oer, + SEQUENCE_encode_oer, +#endif /* ASN_DISABLE_OER_SUPPORT */ +#ifdef ASN_DISABLE_PER_SUPPORT + 0, + 0, +#else + SEQUENCE_decode_uper, + SEQUENCE_encode_uper, +#endif /* ASN_DISABLE_PER_SUPPORT */ +#ifdef ASN_DISABLE_BNER_SUPPORT + 0, + 0, +#else + SEQUENCE_decode_BACnet_ComplexACK_PDU, + SEQUENCE_encode_BACnet_ComplexACK_PDU, +#endif /* ASN_DISABLE_BNER_SUPPORT */ + SEQUENCE_random_fill, + 0 /* Use generic outmost tag fetcher */ +}; + +asn_dec_rval_t +CC_ATTRIBUTE(weak) SEQUENCE_decode_BACnet_ComplexACK_PDU( + const struct asn_codec_ctx_s *opt_codec_ctx, + const struct asn_TYPE_descriptor_s *td, void **struct_ptr, + const void *buffer, size_t size, ber_tlv_tag_t tag, int tag_mode) { + (void)opt_codec_ctx; + (void)td; + (void)struct_ptr; + (void)buffer; + (void)size; + (void)tag; + (void)tag_mode; + ASN_DEBUG("Missing %s", __func__); + ASN__DECODE_FAILED; +} + +asn_enc_rval_t +CC_ATTRIBUTE(weak) SEQUENCE_encode_BACnet_ComplexACK_PDU( + const struct asn_TYPE_descriptor_s *td, const void *sptr, int tag_mode, + ber_tlv_tag_t tag, asn_app_consume_bytes_f *consume_bytes_cb, + void *app_key) { + (void)td; + (void)sptr; + (void)tag_mode; + (void)tag; + (void)consume_bytes_cb; + (void)app_key; + ASN_DEBUG("Missing %s", __func__); + ASN__ENCODE_FAILED; +} + +asn_TYPE_operation_t asn_OP_BACnet_SegmentACK_PDU = { + SEQUENCE_free, + SEQUENCE_print, + SEQUENCE_compare, + SEQUENCE_decode_ber, + SEQUENCE_encode_der, + SEQUENCE_decode_xer, + SEQUENCE_encode_xer, +#ifdef ASN_DISABLE_OER_SUPPORT + 0, + 0, +#else + SEQUENCE_decode_oer, + SEQUENCE_encode_oer, +#endif /* ASN_DISABLE_OER_SUPPORT */ +#ifdef ASN_DISABLE_PER_SUPPORT + 0, + 0, +#else + SEQUENCE_decode_uper, + SEQUENCE_encode_uper, +#endif /* ASN_DISABLE_PER_SUPPORT */ +#ifdef ASN_DISABLE_BNER_SUPPORT + 0, + 0, +#else + SEQUENCE_decode_BACnet_SegmentACK_PDU, + SEQUENCE_encode_BACnet_SegmentACK_PDU, +#endif /* ASN_DISABLE_BNER_SUPPORT */ + SEQUENCE_random_fill, + 0 /* Use generic outmost tag fetcher */ +}; + +asn_dec_rval_t +CC_ATTRIBUTE(weak) SEQUENCE_decode_BACnet_SegmentACK_PDU( + const struct asn_codec_ctx_s *opt_codec_ctx, + const struct asn_TYPE_descriptor_s *td, void **struct_ptr, + const void *buffer, size_t size, ber_tlv_tag_t tag, int tag_mode) { + (void)opt_codec_ctx; + (void)td; + (void)struct_ptr; + (void)buffer; + (void)size; + (void)tag; + (void)tag_mode; + ASN_DEBUG("Missing %s", __func__); + ASN__DECODE_FAILED; +} + +asn_enc_rval_t +CC_ATTRIBUTE(weak) SEQUENCE_encode_BACnet_SegmentACK_PDU( + const struct asn_TYPE_descriptor_s *td, const void *sptr, int tag_mode, + ber_tlv_tag_t tag, asn_app_consume_bytes_f *consume_bytes_cb, + void *app_key) { + (void)td; + (void)sptr; + (void)tag_mode; + (void)tag; + (void)consume_bytes_cb; + (void)app_key; + ASN_DEBUG("Missing %s", __func__); + ASN__ENCODE_FAILED; +} + +asn_TYPE_operation_t asn_OP_BACnet_Error_PDU = { + SEQUENCE_free, + SEQUENCE_print, + SEQUENCE_compare, + SEQUENCE_decode_ber, + SEQUENCE_encode_der, + SEQUENCE_decode_xer, + SEQUENCE_encode_xer, +#ifdef ASN_DISABLE_OER_SUPPORT + 0, + 0, +#else + SEQUENCE_decode_oer, + SEQUENCE_encode_oer, +#endif /* ASN_DISABLE_OER_SUPPORT */ +#ifdef ASN_DISABLE_PER_SUPPORT + 0, + 0, +#else + SEQUENCE_decode_uper, + SEQUENCE_encode_uper, +#endif /* ASN_DISABLE_PER_SUPPORT */ +#ifdef ASN_DISABLE_BNER_SUPPORT + 0, + 0, +#else + SEQUENCE_decode_BACnet_Error_PDU, + SEQUENCE_encode_BACnet_Error_PDU, +#endif /* ASN_DISABLE_BNER_SUPPORT */ + SEQUENCE_random_fill, + 0 /* Use generic outmost tag fetcher */ +}; + +asn_dec_rval_t +CC_ATTRIBUTE(weak) SEQUENCE_decode_BACnet_Error_PDU( + const struct asn_codec_ctx_s *opt_codec_ctx, + const struct asn_TYPE_descriptor_s *td, void **struct_ptr, + const void *buffer, size_t size, ber_tlv_tag_t tag, int tag_mode) { + (void)opt_codec_ctx; + (void)td; + (void)struct_ptr; + (void)buffer; + (void)size; + (void)tag; + (void)tag_mode; + ASN_DEBUG("Missing %s", __func__); + ASN__DECODE_FAILED; +} + +asn_enc_rval_t +CC_ATTRIBUTE(weak) + SEQUENCE_encode_BACnet_Error_PDU(const struct asn_TYPE_descriptor_s *td, + const void *sptr, int tag_mode, + ber_tlv_tag_t tag, + asn_app_consume_bytes_f *consume_bytes_cb, + void *app_key) { + (void)td; + (void)sptr; + (void)tag_mode; + (void)tag; + (void)consume_bytes_cb; + (void)app_key; + ASN_DEBUG("Missing %s", __func__); + ASN__ENCODE_FAILED; +} + +asn_TYPE_operation_t asn_OP_BACnet_Reject_PDU = { + SEQUENCE_free, + SEQUENCE_print, + SEQUENCE_compare, + SEQUENCE_decode_ber, + SEQUENCE_encode_der, + SEQUENCE_decode_xer, + SEQUENCE_encode_xer, +#ifdef ASN_DISABLE_OER_SUPPORT + 0, + 0, +#else + SEQUENCE_decode_oer, + SEQUENCE_encode_oer, +#endif /* ASN_DISABLE_OER_SUPPORT */ +#ifdef ASN_DISABLE_PER_SUPPORT + 0, + 0, +#else + SEQUENCE_decode_uper, + SEQUENCE_encode_uper, +#endif /* ASN_DISABLE_PER_SUPPORT */ +#ifdef ASN_DISABLE_BNER_SUPPORT + 0, + 0, +#else + SEQUENCE_decode_BACnet_Reject_PDU, + SEQUENCE_encode_BACnet_Reject_PDU, +#endif /* ASN_DISABLE_BNER_SUPPORT */ + SEQUENCE_random_fill, + 0 /* Use generic outmost tag fetcher */ +}; + +asn_dec_rval_t +CC_ATTRIBUTE(weak) SEQUENCE_decode_BACnet_Reject_PDU( + const struct asn_codec_ctx_s *opt_codec_ctx, + const struct asn_TYPE_descriptor_s *td, void **struct_ptr, + const void *buffer, size_t size, ber_tlv_tag_t tag, int tag_mode) { + (void)opt_codec_ctx; + (void)td; + (void)struct_ptr; + (void)buffer; + (void)size; + (void)tag; + (void)tag_mode; + ASN_DEBUG("Missing %s", __func__); + ASN__DECODE_FAILED; +} + +asn_enc_rval_t +CC_ATTRIBUTE(weak) + SEQUENCE_encode_BACnet_Reject_PDU(const struct asn_TYPE_descriptor_s *td, + const void *sptr, int tag_mode, + ber_tlv_tag_t tag, + asn_app_consume_bytes_f *consume_bytes_cb, + void *app_key) { + (void)td; + (void)sptr; + (void)tag_mode; + (void)tag; + (void)consume_bytes_cb; + (void)app_key; + ASN_DEBUG("Missing %s", __func__); + ASN__ENCODE_FAILED; +} + +asn_TYPE_operation_t asn_OP_BACnet_Abort_PDU = { + SEQUENCE_free, + SEQUENCE_print, + SEQUENCE_compare, + SEQUENCE_decode_ber, + SEQUENCE_encode_der, + SEQUENCE_decode_xer, + SEQUENCE_encode_xer, +#ifdef ASN_DISABLE_OER_SUPPORT + 0, + 0, +#else + SEQUENCE_decode_oer, + SEQUENCE_encode_oer, +#endif /* ASN_DISABLE_OER_SUPPORT */ +#ifdef ASN_DISABLE_PER_SUPPORT + 0, + 0, +#else + SEQUENCE_decode_uper, + SEQUENCE_encode_uper, +#endif /* ASN_DISABLE_PER_SUPPORT */ +#ifdef ASN_DISABLE_BNER_SUPPORT + 0, + 0, +#else + SEQUENCE_decode_BACnet_Abort_PDU, + SEQUENCE_encode_BACnet_Abort_PDU, +#endif /* ASN_DISABLE_BNER_SUPPORT */ + SEQUENCE_random_fill, + 0 /* Use generic outmost tag fetcher */ +}; + +asn_dec_rval_t +CC_ATTRIBUTE(weak) SEQUENCE_decode_BACnet_Abort_PDU( + const struct asn_codec_ctx_s *opt_codec_ctx, + const struct asn_TYPE_descriptor_s *td, void **struct_ptr, + const void *buffer, size_t size, ber_tlv_tag_t tag, int tag_mode) { + (void)opt_codec_ctx; + (void)td; + (void)struct_ptr; + (void)buffer; + (void)size; + (void)tag; + (void)tag_mode; + ASN_DEBUG("Missing %s", __func__); + ASN__DECODE_FAILED; +} + +asn_enc_rval_t +CC_ATTRIBUTE(weak) + SEQUENCE_encode_BACnet_Abort_PDU(const struct asn_TYPE_descriptor_s *td, + const void *sptr, int tag_mode, + ber_tlv_tag_t tag, + asn_app_consume_bytes_f *consume_bytes_cb, + void *app_key) { + (void)td; + (void)sptr; + (void)tag_mode; + (void)tag; + (void)consume_bytes_cb; + (void)app_key; + ASN_DEBUG("Missing %s", __func__); + ASN__ENCODE_FAILED; +} + +asn_TYPE_operation_t asn_OP_BACnet_Confirmed_Service_Request = { + CHOICE_free, + CHOICE_print, + CHOICE_compare, + CHOICE_decode_ber, + CHOICE_encode_der, + CHOICE_decode_xer, + CHOICE_encode_xer, +#ifdef ASN_DISABLE_OER_SUPPORT + 0, + 0, +#else + CHOICE_decode_oer, + CHOICE_encode_oer, +#endif /* ASN_DISABLE_OER_SUPPORT */ +#ifdef ASN_DISABLE_PER_SUPPORT + 0, + 0, +#else + CHOICE_decode_uper, + CHOICE_encode_uper, +#endif /* ASN_DISABLE_PER_SUPPORT */ +#ifdef ASN_DISABLE_BNER_SUPPORT + 0, + 0, +#else + CHOICE_decode_BACnet_Confirmed_Service_Request, + CHOICE_encode_BACnet_Confirmed_Service_Request, +#endif /* ASN_DISABLE_BNER_SUPPORT */ + CHOICE_random_fill, + CHOICE_outmost_tag}; + +asn_dec_rval_t +CC_ATTRIBUTE(weak) CHOICE_decode_BACnet_Confirmed_Service_Request( + const struct asn_codec_ctx_s *opt_codec_ctx, + const struct asn_TYPE_descriptor_s *td, void **struct_ptr, + const void *buffer, size_t size, ber_tlv_tag_t tag, int tag_mode) { + (void)opt_codec_ctx; + (void)td; + (void)struct_ptr; + (void)buffer; + (void)size; + (void)tag; + (void)tag_mode; + ASN_DEBUG("Missing %s", __func__); + ASN__DECODE_FAILED; +} + +asn_enc_rval_t +CC_ATTRIBUTE(weak) CHOICE_encode_BACnet_Confirmed_Service_Request( + const struct asn_TYPE_descriptor_s *td, const void *sptr, int tag_mode, + ber_tlv_tag_t tag, asn_app_consume_bytes_f *consume_bytes_cb, + void *app_key) { + (void)td; + (void)sptr; + (void)tag_mode; + (void)tag; + (void)consume_bytes_cb; + (void)app_key; + ASN_DEBUG("Missing %s", __func__); + ASN__ENCODE_FAILED; +} + +asn_TYPE_operation_t asn_OP_BACnet_Unconfirmed_Service_Request = { + CHOICE_free, + CHOICE_print, + CHOICE_compare, + CHOICE_decode_ber, + CHOICE_encode_der, + CHOICE_decode_xer, + CHOICE_encode_xer, +#ifdef ASN_DISABLE_OER_SUPPORT + 0, + 0, +#else + CHOICE_decode_oer, + CHOICE_encode_oer, +#endif /* ASN_DISABLE_OER_SUPPORT */ +#ifdef ASN_DISABLE_PER_SUPPORT + 0, + 0, +#else + CHOICE_decode_uper, + CHOICE_encode_uper, +#endif /* ASN_DISABLE_PER_SUPPORT */ +#ifdef ASN_DISABLE_BNER_SUPPORT + 0, + 0, +#else + CHOICE_decode_BACnet_Unconfirmed_Service_Request, + CHOICE_encode_BACnet_Unconfirmed_Service_Request, +#endif /* ASN_DISABLE_BNER_SUPPORT */ + CHOICE_random_fill, + CHOICE_outmost_tag}; + +asn_dec_rval_t +CC_ATTRIBUTE(weak) CHOICE_decode_BACnet_Unconfirmed_Service_Request( + const struct asn_codec_ctx_s *opt_codec_ctx, + const struct asn_TYPE_descriptor_s *td, void **struct_ptr, + const void *buffer, size_t size, ber_tlv_tag_t tag, int tag_mode) { + (void)opt_codec_ctx; + (void)td; + (void)struct_ptr; + (void)buffer; + (void)size; + (void)tag; + (void)tag_mode; + ASN_DEBUG("Missing %s", __func__); + ASN__DECODE_FAILED; +} + +asn_enc_rval_t +CC_ATTRIBUTE(weak) CHOICE_encode_BACnet_Unconfirmed_Service_Request( + const struct asn_TYPE_descriptor_s *td, const void *sptr, int tag_mode, + ber_tlv_tag_t tag, asn_app_consume_bytes_f *consume_bytes_cb, + void *app_key) { + (void)td; + (void)sptr; + (void)tag_mode; + (void)tag; + (void)consume_bytes_cb; + (void)app_key; + ASN_DEBUG("Missing %s", __func__); + ASN__ENCODE_FAILED; +} + +asn_TYPE_operation_t asn_OP_BACnet_Confirmed_Service_ACK = {CHOICE_free, + CHOICE_print, + CHOICE_compare, + CHOICE_decode_ber, + CHOICE_encode_der, + CHOICE_decode_xer, + CHOICE_encode_xer, +#ifdef ASN_DISABLE_OER_SUPPORT + 0, + 0, +#else + CHOICE_decode_oer, + CHOICE_encode_oer, +#endif /* ASN_DISABLE_OER_SUPPORT */ +#ifdef ASN_DISABLE_PER_SUPPORT + 0, + 0, +#else + CHOICE_decode_uper, + CHOICE_encode_uper, +#endif /* ASN_DISABLE_PER_SUPPORT */ +#ifdef ASN_DISABLE_BNER_SUPPORT + 0, + 0, +#else + CHOICE_decode_BACnet_Confirmed_Service_ACK, + CHOICE_encode_BACnet_Confirmed_Service_ACK, +#endif /* ASN_DISABLE_BNER_SUPPORT */ + CHOICE_random_fill, + CHOICE_outmost_tag}; + +asn_dec_rval_t +CC_ATTRIBUTE(weak) CHOICE_decode_BACnet_Confirmed_Service_ACK( + const struct asn_codec_ctx_s *opt_codec_ctx, + const struct asn_TYPE_descriptor_s *td, void **struct_ptr, + const void *buffer, size_t size, ber_tlv_tag_t tag, int tag_mode) { + (void)opt_codec_ctx; + (void)td; + (void)struct_ptr; + (void)buffer; + (void)size; + (void)tag; + (void)tag_mode; + ASN_DEBUG("Missing %s", __func__); + ASN__DECODE_FAILED; +} + +asn_enc_rval_t +CC_ATTRIBUTE(weak) CHOICE_encode_BACnet_Confirmed_Service_ACK( + const struct asn_TYPE_descriptor_s *td, const void *sptr, int tag_mode, + ber_tlv_tag_t tag, asn_app_consume_bytes_f *consume_bytes_cb, + void *app_key) { + (void)td; + (void)sptr; + (void)tag_mode; + (void)tag; + (void)consume_bytes_cb; + (void)app_key; + ASN_DEBUG("Missing %s", __func__); + ASN__ENCODE_FAILED; +} + +asn_TYPE_operation_t asn_OP_BACnet_Error = {CHOICE_free, + CHOICE_print, + CHOICE_compare, + CHOICE_decode_ber, + CHOICE_encode_der, + CHOICE_decode_xer, + CHOICE_encode_xer, +#ifdef ASN_DISABLE_OER_SUPPORT + 0, + 0, +#else + CHOICE_decode_oer, + CHOICE_encode_oer, +#endif /* ASN_DISABLE_OER_SUPPORT */ +#ifdef ASN_DISABLE_PER_SUPPORT + 0, + 0, +#else + CHOICE_decode_uper, + CHOICE_encode_uper, +#endif /* ASN_DISABLE_PER_SUPPORT */ +#ifdef ASN_DISABLE_BNER_SUPPORT + 0, + 0, +#else + CHOICE_decode_BACnet_Error, + CHOICE_encode_BACnet_Error, +#endif /* ASN_DISABLE_BNER_SUPPORT */ + CHOICE_random_fill, + CHOICE_outmost_tag}; + +asn_dec_rval_t +CC_ATTRIBUTE(weak) + CHOICE_decode_BACnet_Error(const struct asn_codec_ctx_s *opt_codec_ctx, + const struct asn_TYPE_descriptor_s *td, + void **struct_ptr, const void *buffer, + size_t size, ber_tlv_tag_t tag, int tag_mode) { + (void)opt_codec_ctx; + (void)td; + (void)struct_ptr; + (void)buffer; + (void)size; + (void)tag; + (void)tag_mode; + ASN_DEBUG("Missing %s", __func__); + ASN__DECODE_FAILED; +} + +asn_enc_rval_t +CC_ATTRIBUTE(weak) + CHOICE_encode_BACnet_Error(const struct asn_TYPE_descriptor_s *td, + const void *sptr, int tag_mode, + ber_tlv_tag_t tag, + asn_app_consume_bytes_f *consume_bytes_cb, + void *app_key) { + (void)td; + (void)sptr; + (void)tag_mode; + (void)tag; + (void)consume_bytes_cb; + (void)app_key; + ASN_DEBUG("Missing %s", __func__); + ASN__ENCODE_FAILED; +} diff --git a/skeletons/bner_fixed_stubs.h b/skeletons/bner_fixed_stubs.h new file mode 100644 index 000000000..f59af3ea4 --- /dev/null +++ b/skeletons/bner_fixed_stubs.h @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2003-2017 Lev Walkin and contributors. + * All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#ifndef BNER_FIXED_STUBS_H +#define BNER_FIXED_STUBS_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +extern asn_TYPE_operation_t asn_OP_BACnetPDU; +extern asn_TYPE_operation_t asn_OP_BACnet_Confirmed_Request_PDU; +extern asn_TYPE_operation_t asn_OP_BACnet_Unconfirmed_Request_PDU; +extern asn_TYPE_operation_t asn_OP_BACnet_SimpleACK_PDU; +extern asn_TYPE_operation_t asn_OP_BACnet_ComplexACK_PDU; +extern asn_TYPE_operation_t asn_OP_BACnet_SegmentACK_PDU; +extern asn_TYPE_operation_t asn_OP_BACnet_Error_PDU; +extern asn_TYPE_operation_t asn_OP_BACnet_Reject_PDU; +extern asn_TYPE_operation_t asn_OP_BACnet_Abort_PDU; +extern asn_TYPE_operation_t asn_OP_BACnet_Confirmed_Service_Request; +extern asn_TYPE_operation_t asn_OP_BACnet_Unconfirmed_Service_Request; +extern asn_TYPE_operation_t asn_OP_BACnet_Confirmed_Service_ACK; +extern asn_TYPE_operation_t asn_OP_BACnet_Error; + +bner_type_decoder_f CHOICE_decode_BACnetPDU; +bner_type_encoder_f CHOICE_encode_BACnetPDU; +bner_type_decoder_f SEQUENCE_decode_BACnet_Confirmed_Request_PDU; +bner_type_encoder_f SEQUENCE_encode_BACnet_Confirmed_Request_PDU; +bner_type_decoder_f SEQUENCE_decode_BACnet_Unconfirmed_Request_PDU; +bner_type_encoder_f SEQUENCE_encode_BACnet_Unconfirmed_Request_PDU; +bner_type_decoder_f SEQUENCE_decode_BACnet_SimpleACK_PDU; +bner_type_encoder_f SEQUENCE_encode_BACnet_SimpleACK_PDU; +bner_type_decoder_f SEQUENCE_decode_BACnet_ComplexACK_PDU; +bner_type_encoder_f SEQUENCE_encode_BACnet_ComplexACK_PDU; +bner_type_decoder_f SEQUENCE_decode_BACnet_SegmentACK_PDU; +bner_type_encoder_f SEQUENCE_encode_BACnet_SegmentACK_PDU; +bner_type_decoder_f SEQUENCE_decode_BACnet_Error_PDU; +bner_type_encoder_f SEQUENCE_encode_BACnet_Error_PDU; +bner_type_decoder_f SEQUENCE_decode_BACnet_Reject_PDU; +bner_type_encoder_f SEQUENCE_encode_BACnet_Reject_PDU; +bner_type_decoder_f SEQUENCE_decode_BACnet_Abort_PDU; +bner_type_encoder_f SEQUENCE_encode_BACnet_Abort_PDU; +bner_type_decoder_f CHOICE_decode_BACnet_Confirmed_Service_Request; +bner_type_encoder_f CHOICE_encode_BACnet_Confirmed_Service_Request; +bner_type_decoder_f CHOICE_decode_BACnet_Unconfirmed_Service_Request; +bner_type_encoder_f CHOICE_encode_BACnet_Unconfirmed_Service_Request; +bner_type_decoder_f CHOICE_decode_BACnet_Confirmed_Service_ACK; +bner_type_encoder_f CHOICE_encode_BACnet_Confirmed_Service_ACK; +bner_type_decoder_f CHOICE_decode_BACnet_Error; +bner_type_encoder_f CHOICE_encode_BACnet_Error; + +#ifdef __cplusplus +} +#endif + +#endif /* BNER_FIXED_STUBS_H */ diff --git a/skeletons/constr_TYPE.h b/skeletons/constr_TYPE.h index 41f5c262f..9f914cf41 100644 --- a/skeletons/constr_TYPE.h +++ b/skeletons/constr_TYPE.h @@ -262,4 +262,6 @@ int asn_fprint(FILE *stream, /* Destination stream descriptor */ } #endif +#include + #endif /* _CONSTR_TYPE_H_ */ diff --git a/skeletons/file-dependencies b/skeletons/file-dependencies index 5f7564ca5..a45c4b219 100644 --- a/skeletons/file-dependencies +++ b/skeletons/file-dependencies @@ -68,6 +68,7 @@ per_opentype.h per_opentype.c # PER "open type" handling bner_support.h bner_support.c # BNER tag support bner_decoder.h bner_decoder.c # BNER decoding support bner_encoder.h bner_encoder.c # BNER encoding support +bner_fixed_stubs.h bner_fixed_stubs.c constr_CHOICE.h constr_SEQUENCE.h # BNER fixed encoding rules stubs CONVERTER: # THIS IS A SPECIAL SECTION converter-example.c # A default name for the example transcoder From aa626081926c48f0ff475e80f1f0847c26da1b71 Mon Sep 17 00:00:00 2001 From: Jon Ringle Date: Fri, 1 Dec 2017 00:41:09 -0500 Subject: [PATCH 12/12] BNER: Make OCTET_STRING_print a weak function This will allow a bacnet library to override this function and be able to pretty print the BNER primitives: Double CharacterString Date Time BACnetObjectIdentifier --- skeletons/OCTET_STRING.c | 9 +++++---- skeletons/OCTET_STRING.h | 1 + 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/skeletons/OCTET_STRING.c b/skeletons/OCTET_STRING.c index cb5029f86..2a1efdd9c 100644 --- a/skeletons/OCTET_STRING.c +++ b/skeletons/OCTET_STRING.c @@ -160,7 +160,7 @@ OS__add_stack_el(struct _stack *st) { nel = (struct _stack_el *)CALLOC(1, sizeof(struct _stack_el)); if(nel == NULL) return NULL; - + if(st->tail) { /* Increase a subcontainment depth */ nel->cont_level = st->tail->cont_level + 1; @@ -748,7 +748,7 @@ OCTET_STRING__handle_control_chars(void *struct_ptr, const void *chunk_buf, size return 0; } } - + return -1; /* No, it's not */ } @@ -1653,8 +1653,8 @@ OCTET_STRING_encode_uper(const asn_TYPE_descriptor_t *td, #endif /* ASN_DISABLE_PER_SUPPORT */ int -OCTET_STRING_print(const asn_TYPE_descriptor_t *td, const void *sptr, - int ilevel, asn_app_consume_bytes_f *cb, void *app_key) { +__OCTET_STRING_print(const asn_TYPE_descriptor_t *td, const void *sptr, + int ilevel, asn_app_consume_bytes_f *cb, void *app_key) { const char * const h2c = "0123456789ABCDEF"; const OCTET_STRING_t *st = (const OCTET_STRING_t *)sptr; char scratch[16 * 3 + 4]; @@ -1693,6 +1693,7 @@ OCTET_STRING_print(const asn_TYPE_descriptor_t *td, const void *sptr, return 0; } +CC_WEAK_ALIAS(__OCTET_STRING_print, OCTET_STRING_print); int OCTET_STRING_print_utf8(const asn_TYPE_descriptor_t *td, const void *sptr, diff --git a/skeletons/OCTET_STRING.h b/skeletons/OCTET_STRING.h index e07a1d842..ec35906f3 100644 --- a/skeletons/OCTET_STRING.h +++ b/skeletons/OCTET_STRING.h @@ -22,6 +22,7 @@ extern asn_TYPE_descriptor_t asn_DEF_OCTET_STRING; extern asn_TYPE_operation_t asn_OP_OCTET_STRING; asn_struct_free_f OCTET_STRING_free; +asn_struct_print_f __OCTET_STRING_print; asn_struct_print_f OCTET_STRING_print; asn_struct_print_f OCTET_STRING_print_utf8; asn_struct_compare_f OCTET_STRING_compare;