Skip to content

Commit 7c6c02f

Browse files
committed
BNER: Add weak function stubs for BNER fixed encoded PDUs
1 parent 8ee5eed commit 7c6c02f

File tree

6 files changed

+714
-15
lines changed

6 files changed

+714
-15
lines changed

libasn1compiler/asn1c_C.c

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <asn1fix_crange.h> /* constraint groker from libasn1fix */
1414
#include <asn1fix_export.h> /* other exportables from libasn1fix */
1515
#include <asn1parser.h>
16+
#include <regex.h>
1617

1718
typedef struct tag2el_s {
1819
struct asn1p_type_tag_s el_tag;
@@ -75,6 +76,24 @@ enum etd_spec {
7576
};
7677
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);
7778

79+
static int is_bner_pdu_regex_init = 0;
80+
static regex_t bner_pdu_regex;
81+
82+
static int init_bner(void) {
83+
int ret = 0;
84+
85+
if(!is_bner_pdu_regex_init) {
86+
ret = regcomp(&bner_pdu_regex, "BACnet.*PDU", 0);
87+
if(ret == 0) is_bner_pdu_regex_init = 1;
88+
}
89+
90+
return ret;
91+
}
92+
static int is_bner_fixed_pdu(const char *pdu_type_name) {
93+
init_bner();
94+
return (regexec(&bner_pdu_regex, pdu_type_name, 0, NULL, 0) == 0);
95+
}
96+
7897
#define C99_MODE (!(arg->flags & A1C_NO_C99))
7998
#define UNNAMED_UNIONS (arg->flags & A1C_UNNAMED_UNIONS)
8099
#define HIDE_INNER_DEFS (arg->embed && !(arg->flags & A1C_ALL_DEFS_GLOBAL))
@@ -2980,7 +2999,12 @@ emit_type_DEF(arg_t *arg, asn1p_expr_t *expr, enum tvm_compat tv_mode, int tags_
29802999
if (!p2)
29813000
p2 = strdup(p);
29823001

2983-
OUT("&asn_OP_%s,\n", p2);
3002+
if(arg->flags & A1C_GEN_BNER
3003+
&& is_bner_fixed_pdu(expr->Identifier)) {
3004+
OUT("&asn_OP_%s,\n", expr_id);
3005+
} else {
3006+
OUT("&asn_OP_%s,\n", p2);
3007+
}
29843008

29853009
if(tags_count) {
29863010
OUT("asn_DEF_%s_tags_%d,\n",

skeletons/Makefile.am

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -100,20 +100,21 @@ check_PROGRAMS = \
100100
check-converter_c89_example
101101

102102
# BNER Support
103-
libasn1cskeletons_la_SOURCES += \
104-
bner_decoder.c bner_decoder.h \
105-
bner_encoder.c bner_encoder.h \
106-
bner_support.c bner_support.h \
107-
constr_CHOICE_bner.c \
108-
constr_SEQUENCE_bner.c \
109-
constr_SEQUENCE_OF_bner.c \
110-
ANY_bner.c \
111-
BOOLEAN_bner.c \
112-
INTEGER_bner.c \
113-
NativeInteger_bner.c \
114-
NativeReal_bner.c \
115-
NULL_bner.c \
116-
OCTET_STRING_bner.c \
103+
libasn1cskeletons_la_SOURCES += \
104+
bner_decoder.c bner_decoder.h \
105+
bner_encoder.c bner_encoder.h \
106+
bner_fixed_stubs.c bner_fixed_stubs.h \
107+
bner_support.c bner_support.h \
108+
constr_CHOICE_bner.c \
109+
constr_SEQUENCE_bner.c \
110+
constr_SEQUENCE_OF_bner.c \
111+
ANY_bner.c \
112+
BOOLEAN_bner.c \
113+
INTEGER_bner.c \
114+
NativeInteger_bner.c \
115+
NativeReal_bner.c \
116+
NULL_bner.c \
117+
OCTET_STRING_bner.c \
117118
REAL_bner.c
118119

119120
LDADD = -lm

0 commit comments

Comments
 (0)