This is merely a historical archive of years 2008-2021, before the migration to mailman3.
A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.
Max gerrit-no-reply at lists.osmocom.orgReview at https://gerrit.osmocom.org/1518 Add parsed TLV helpers from OsmoBTS Add functions to copy and merge parsed TLV structures from OsmoBTS. Change-Id: Ieaaaed19da9c069fe451faa53d24c5b84d7d5615 --- M include/osmocom/gsm/tlv.h M src/gsm/libosmogsm.map M src/gsm/tlv_parser.c 3 files changed, 63 insertions(+), 0 deletions(-) git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/18/1518/1 diff --git a/include/osmocom/gsm/tlv.h b/include/osmocom/gsm/tlv.h index cf09969..701fe68 100644 --- a/include/osmocom/gsm/tlv.h +++ b/include/osmocom/gsm/tlv.h @@ -436,6 +436,8 @@ return res; } +struct tlv_parsed *osmo_tlvp_copy(const struct tlv_parsed *tp_orig, void *ctx); +int osmo_tlvp_merge(struct tlv_parsed *dst, const struct tlv_parsed *src); int osmo_shift_v_fixed(uint8_t **data, size_t *data_len, size_t len, uint8_t **value); int osmo_match_shift_tv_fixed(uint8_t **data, size_t *data_len, diff --git a/src/gsm/libosmogsm.map b/src/gsm/libosmogsm.map index 199d05a..b84f859 100644 --- a/src/gsm/libosmogsm.map +++ b/src/gsm/libosmogsm.map @@ -324,6 +324,8 @@ tvlv_att_def; vtvlv_gan_att_def; +osmo_tlvp_copy; +osmo_tlvp_merge; osmo_shift_v_fixed; osmo_match_shift_tv_fixed; osmo_shift_tlv; diff --git a/src/gsm/tlv_parser.c b/src/gsm/tlv_parser.c index e84edd9..790534f 100644 --- a/src/gsm/tlv_parser.c +++ b/src/gsm/tlv_parser.c @@ -43,6 +43,65 @@ return 0; } +/*! \brief Copy \ref tlv_parsed using given talloc context + * \param[in] tp_orig Parsed TLV structure + * \param[in] ctx Talloc context for allocations + * \returns NULL on errors, \ref tlv_parsed pointer otherwise + */ +struct tlv_parsed *osmo_tlvp_copy(const struct tlv_parsed *tp_orig, void *ctx) +{ + struct tlv_parsed *tp_out; + size_t i, len; + + tp_out = talloc_zero(ctx, struct tlv_parsed); + if (!tp_out) + return NULL; + + /* if the original is NULL, return empty tlvp */ + if (!tp_orig) + return tp_out; + + for (i = 0; i < ARRAY_SIZE(tp_orig->lv); i++) { + len = tp_orig->lv[i].len; + tp_out->lv[i].len = len; + if (len && tp_out->lv[i].val) { + tp_out->lv[i].val = talloc_zero_size(tp_out, len); + if (!tp_out->lv[i].val) { + talloc_free(tp_out); + return NULL; + } + memcpy((uint8_t *)tp_out->lv[i].val, tp_orig->lv[i].val, + len); + } + } + + return tp_out; +} + +/*! \brief Merge all \ref tlv_parsed attributes of 'src' into 'dst' + * \param[in] dst Parsed TLV structure to merge into + * \param[in] src Parsed TLV structure to merge from + * \returns 0 on success, negative on error + */ +int osmo_tlvp_merge(struct tlv_parsed *dst, const struct tlv_parsed *src) +{ + size_t i, len; + for (i = 0; i < ARRAY_SIZE(dst->lv); i++) { + len = src->lv[i].len; + if (len == 0 || src->lv[i].val == NULL) + continue; + if (dst->lv[i].val) { + talloc_free((uint8_t *) dst->lv[i].val); + dst->lv[i].len = 0; + } + dst->lv[i].val = talloc_zero_size(dst, len); + if (!dst->lv[i].val) + return -ENOMEM; + memcpy((uint8_t *) dst->lv[i].val, src->lv[i].val, len); + } + return 0; +} + /*! \brief Parse a single TLV encoded IE * \param[out] o_tag the tag of the IE that was found * \param[out] o_len length of the IE that was found -- To view, visit https://gerrit.osmocom.org/1518 To unsubscribe, visit https://gerrit.osmocom.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ieaaaed19da9c069fe451faa53d24c5b84d7d5615 Gerrit-PatchSet: 1 Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Owner: Max <msuraev at sysmocom.de>