From 8006f5393e21750558a01c780641831d925382ee Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Wed, 13 Feb 2019 22:23:13 +0100 Subject: TLV: Add one-shot TLV encoder So far, the TLV code contained two types of functions * tlp_parse() to parse all TLVs according to definition into tlvp_parsed * various helper functions to encode individual TLVs during message generation This patch implements the inverse of tlv_parse(): tlv_encode(), which takes a full 'struct tlv_pared' and encodes all IEs found in it. The order of IEs is in numerically ascending order of the tag. As many protocols have different IE/TLV ordering requirements, let's add a tlv_encode_ordered() function where the caller can specify the TLV ordering during the one-shot encode. Change-Id: I761a30bf20355a9f80a4a8e0c60b0b0f78515efe --- include/osmocom/gsm/tlv.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'include/osmocom/gsm') diff --git a/include/osmocom/gsm/tlv.h b/include/osmocom/gsm/tlv.h index d0c95522..bb0e8fc9 100644 --- a/include/osmocom/gsm/tlv.h +++ b/include/osmocom/gsm/tlv.h @@ -457,6 +457,12 @@ int tlv_parse2(struct tlv_parsed *dec, int dec_multiples, /* take a master (src) tlv def and fill up all empty slots in 'dst' */ void tlv_def_patch(struct tlv_definition *dst, const struct tlv_definition *src); +int tlv_encode_one(struct msgb *msg, enum tlv_type type, uint8_t tag, + unsigned int len, const uint8_t *val); +int tlv_encode(struct msgb *msg, const struct tlv_definition *def, const struct tlv_parsed *tp); +int tlv_encode_ordered(struct msgb *msg, const struct tlv_definition *def, const struct tlv_parsed *tp, + const uint8_t *tag_order, unsigned int tag_order_len); + #define TLVP_PRESENT(x, y) ((x)->lv[y].val) #define TLVP_LEN(x, y) (x)->lv[y].len #define TLVP_VAL(x, y) (x)->lv[y].val -- cgit v1.2.3