Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BNER support stubs #247

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions asn1c/asn1c.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions asn1c/unber.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

#define ASN_DISABLE_PER_SUPPORT 1
#define ASN_DISABLE_OER_SUPPORT 1
#define ASN_DISABLE_BNER_SUPPORT 1

#include <asn1parser.h> /* For static string tables */

Expand Down
40 changes: 37 additions & 3 deletions libasn1compiler/asn1c_C.c
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -1440,6 +1465,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);
Expand Down Expand Up @@ -2780,11 +2809,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");
Expand Down Expand Up @@ -2976,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",
Expand Down
4 changes: 4 additions & 0 deletions libasn1compiler/asn1c_fdeps.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions libasn1compiler/asn1c_fdeps.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
3 changes: 2 additions & 1 deletion libasn1compiler/asn1c_save.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 ");

Expand Down
5 changes: 5 additions & 0 deletions libasn1compiler/asn1compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

/*
Expand Down
7 changes: 7 additions & 0 deletions skeletons/ANY.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
};
Expand Down
2 changes: 2 additions & 0 deletions skeletons/ANY.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
41 changes: 41 additions & 0 deletions skeletons/ANY_bner.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (c) 2003-2017 Lev Walkin <[email protected]> and contributors.
* All rights reserved.
* Redistribution and modifications are permitted subject to BSD license.
*/
#include <ANY.h>
#include <asn_internal.h>

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;
}
7 changes: 7 additions & 0 deletions skeletons/BIT_STRING.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
};
Expand Down
2 changes: 2 additions & 0 deletions skeletons/BMPString.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
};
Expand Down
7 changes: 7 additions & 0 deletions skeletons/BOOLEAN.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
};
Expand Down
2 changes: 2 additions & 0 deletions skeletons/BOOLEAN.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
42 changes: 42 additions & 0 deletions skeletons/BOOLEAN_bner.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (c) 2003-2017 Lev Walkin <[email protected]> and contributors.
* All rights reserved.
* Redistribution and modifications are permitted subject to BSD license.
*/
#include <BOOLEAN.h>
#include <asn_internal.h>

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;
}
7 changes: 7 additions & 0 deletions skeletons/ENUMERATED.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
};
Expand Down
2 changes: 2 additions & 0 deletions skeletons/GeneralString.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
};
Expand Down
2 changes: 2 additions & 0 deletions skeletons/GeneralizedTime.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
};
Expand Down
2 changes: 2 additions & 0 deletions skeletons/GraphicString.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
};
Expand Down
2 changes: 2 additions & 0 deletions skeletons/IA5String.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
};
Expand Down
7 changes: 7 additions & 0 deletions skeletons/INTEGER.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
};
Expand Down
2 changes: 2 additions & 0 deletions skeletons/INTEGER.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/***********************************
Expand Down
Loading