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/.
Harald Welte gerrit-no-reply at lists.osmocom.orgHarald Welte has submitted this change and it was merged. ( https://gerrit.osmocom.org/11679 ) Change subject: Move msgb_push helpers to public header ...................................................................... Move msgb_push helpers to public header The msgb_wrap_with_TL() is generally useful so it make sense to make it public to facilitate code re-use. Other helpers can be implemented as trivial wrappers over existing tlv.h functions. Update headers and code accordingly. Change-Id: I37e91d031fba28cf1c6735b8069b0265746f55e6 --- M include/osmocom/core/msgb.h M include/osmocom/gsm/tlv.h M src/gsm/gsm0480.c 3 files changed, 25 insertions(+), 39 deletions(-) Approvals: Harald Welte: Looks good to me, approved Jenkins Builder: Verified diff --git a/include/osmocom/core/msgb.h b/include/osmocom/core/msgb.h index 8843db0..2449151 100644 --- a/include/osmocom/core/msgb.h +++ b/include/osmocom/core/msgb.h @@ -366,6 +366,15 @@ osmo_store32be(word, space); } +static inline unsigned char *msgb_wrap_with_TL(struct msgb *msgb, uint8_t tag) +{ + uint8_t *data = msgb_push(msgb, 2); + + data[0] = tag; + data[1] = msgb->len - 2; + return data; +} + /*! remove (pull) a header from the front of the message buffer * \param[in] msgb message buffer * \param[in] len number of octets to be pulled diff --git a/include/osmocom/gsm/tlv.h b/include/osmocom/gsm/tlv.h index 84fd511..1ab964a 100644 --- a/include/osmocom/gsm/tlv.h +++ b/include/osmocom/gsm/tlv.h @@ -341,6 +341,12 @@ return buf; } +/*! push 1-byte tagged value */ +static inline uint8_t *msgb_tlv1_push(struct msgb *msg, uint8_t tag, uint8_t val) +{ + return msgb_tlv_push(msg, tag, 1, &val); +} + /*! push (prepend) a TV field to a \ref msgb * \returns pointer to first byte of newly-pushed information */ static inline uint8_t *msgb_tv_push(struct msgb *msg, uint8_t tag, uint8_t val) diff --git a/src/gsm/gsm0480.c b/src/gsm/gsm0480.c index 7756ecb..021db62 100644 --- a/src/gsm/gsm0480.c +++ b/src/gsm/gsm0480.c @@ -68,35 +68,6 @@ { 0, NULL } }; -static inline unsigned char *msgb_wrap_with_TL(struct msgb *msgb, uint8_t tag) -{ - uint8_t *data = msgb_push(msgb, 2); - - data[0] = tag; - data[1] = msgb->len - 2; - return data; -} - -static inline unsigned char *msgb_push_TLV1(struct msgb *msgb, uint8_t tag, - uint8_t value) -{ - uint8_t *data = msgb_push(msgb, 3); - - data[0] = tag; - data[1] = 1; - data[2] = value; - return data; -} - -static inline unsigned char *msgb_push_NULL(struct msgb *msgb) -{ - uint8_t *data = msgb_push(msgb, 2); - - data[0] = ASN1_NULL_TYPE_TAG; - data[1] = 0; - return data; -} - /* wrap an invoke around it... the other way around * * 1.) Invoke Component tag @@ -107,10 +78,10 @@ int gsm0480_wrap_invoke(struct msgb *msg, int op, int link_id) { /* 3. operation */ - msgb_push_TLV1(msg, GSM0480_OPERATION_CODE, op); + msgb_tlv1_push(msg, GSM0480_OPERATION_CODE, op); /* 2. invoke id tag */ - msgb_push_TLV1(msg, GSM0480_COMPIDTAG_INVOKE_ID, link_id); + msgb_tlv1_push(msg, GSM0480_COMPIDTAG_INVOKE_ID, link_id); /* 1. component tag */ msgb_wrap_with_TL(msg, GSM0480_CTYPE_INVOKE); @@ -825,20 +796,20 @@ msgb_wrap_with_TL(msg, ASN1_OCTET_STRING_TAG); /* Pre-pend the DCS octet string */ - msgb_push_TLV1(msg, ASN1_OCTET_STRING_TAG, 0x0F); + msgb_tlv1_push(msg, ASN1_OCTET_STRING_TAG, 0x0F); /* Then wrap these as a Sequence */ msgb_wrap_with_TL(msg, GSM_0480_SEQUENCE_TAG); /* Pre-pend the operation code */ - msgb_push_TLV1(msg, GSM0480_OPERATION_CODE, + msgb_tlv1_push(msg, GSM0480_OPERATION_CODE, GSM0480_OP_CODE_PROCESS_USS_REQ); /* Wrap the operation code and IA5 string as a sequence */ msgb_wrap_with_TL(msg, GSM_0480_SEQUENCE_TAG); /* Pre-pend the invoke ID */ - msgb_push_TLV1(msg, GSM0480_COMPIDTAG_INVOKE_ID, invoke_id); + msgb_tlv1_push(msg, GSM0480_COMPIDTAG_INVOKE_ID, invoke_id); /* Wrap this up as a Return Result component */ msgb_wrap_with_TL(msg, GSM0480_CTYPE_RETURN_RESULT); @@ -889,10 +860,10 @@ return NULL; /* First insert the problem code */ - msgb_push_TLV1(msg, GSM_0480_ERROR_CODE_TAG, error_code); + msgb_tlv1_push(msg, GSM_0480_ERROR_CODE_TAG, error_code); /* Before it, insert the invoke ID */ - msgb_push_TLV1(msg, GSM0480_COMPIDTAG_INVOKE_ID, invoke_id); + msgb_tlv1_push(msg, GSM0480_COMPIDTAG_INVOKE_ID, invoke_id); /* Wrap this up as a Reject component */ msgb_wrap_with_TL(msg, GSM0480_CTYPE_RETURN_ERROR); @@ -919,13 +890,13 @@ return NULL; /* First insert the problem code */ - msgb_push_TLV1(msg, problem_tag, problem_code); + msgb_tlv1_push(msg, problem_tag, problem_code); /* If the Invoke ID is not available, Universal NULL (table 3.9) with length=0 shall be used */ if (invoke_id < 0 || invoke_id > 255) - msgb_push_NULL(msg); + msgb_tv_push(msg, ASN1_NULL_TYPE_TAG, 0); else - msgb_push_TLV1(msg, GSM0480_COMPIDTAG_INVOKE_ID, invoke_id); + msgb_tlv1_push(msg, GSM0480_COMPIDTAG_INVOKE_ID, invoke_id); /* Wrap this up as a Reject component */ msgb_wrap_with_TL(msg, GSM0480_CTYPE_REJECT); -- To view, visit https://gerrit.osmocom.org/11679 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-MessageType: merged Gerrit-Change-Id: I37e91d031fba28cf1c6735b8069b0265746f55e6 Gerrit-Change-Number: 11679 Gerrit-PatchSet: 3 Gerrit-Owner: Max <msuraev at sysmocom.de> Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org> Gerrit-Reviewer: Jenkins Builder (1000002) -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20181119/04cfa85f/attachment.htm>