laforge has submitted this change. (
https://gerrit.osmocom.org/c/libosmo-gprs/+/33946 )
Change subject: llc: xid: Introduce some helper internal functions to make code easier to
follow
......................................................................
llc: xid: Introduce some helper internal functions to make code easier to follow
Take the chance to fix wrong indentation on related function parameter.
Change-Id: I8c0163583efc2720a4b2675ce93293c184f80d0c
---
M include/osmocom/gprs/llc/llc_private.h
M src/llc/llc_xid.c
2 files changed, 37 insertions(+), 11 deletions(-)
Approvals:
Jenkins Builder: Verified
laforge: Looks good to me, but someone else must approve
osmith: Looks good to me, approved
diff --git a/include/osmocom/gprs/llc/llc_private.h
b/include/osmocom/gprs/llc/llc_private.h
index 44d32e2..b2b9047 100644
--- a/include/osmocom/gprs/llc/llc_private.h
+++ b/include/osmocom/gprs/llc/llc_private.h
@@ -343,8 +343,8 @@
const struct gprs_llc_xid_field *fields,
unsigned int num_fields);
struct gprs_llc_xid_field *gprs_llc_xid_deepcopy(void *ctx,
- const struct gprs_llc_xid_field *src_xid,
- size_t src_xid_len);
+ const struct gprs_llc_xid_field *src_xid,
+ size_t src_xid_len);
/* llc_pdu.c: */
int gprs_llc_pdu_decode(struct gprs_llc_pdu_decoded *pdu,
diff --git a/src/llc/llc_xid.c b/src/llc/llc_xid.c
index deeeaa7..9280416 100644
--- a/src/llc/llc_xid.c
+++ b/src/llc/llc_xid.c
@@ -76,6 +76,24 @@
[OSMO_GPRS_LLC_XID_T_MAC_IOV_UI] = { .len = 4, .min = 0, .max = UINT32_MAX },
};
+static inline bool gprs_llc_xid_type_is_variable_len(enum gprs_llc_xid_type t)
+{
+ return gprs_llc_xid_desc[t].var_len;
+}
+
+static inline bool gprs_llc_xid_type_is_fixed_len(enum gprs_llc_xid_type t)
+{
+ return !gprs_llc_xid_desc[t].var_len;
+}
+
+static inline uint8_t gprs_llc_xid_field_get_len(const struct gprs_llc_xid_field *field)
+{
+ if (gprs_llc_xid_type_is_variable_len(field->type))
+ return field->var.val_len;
+ else
+ return gprs_llc_xid_desc[field->type].len;
+}
+
bool gprs_llc_xid_field_is_valid(const struct gprs_llc_xid_field *field)
{
if (field->type >= ARRAY_SIZE(gprs_llc_xid_desc)) {
@@ -84,7 +102,7 @@
return false;
}
- if (gprs_llc_xid_desc[field->type].var_len)
+ if (gprs_llc_xid_type_is_variable_len(field->type))
return true;
if (field->var.val_len > 0) {
@@ -139,10 +157,7 @@
hdr[0] = (field->type & 0x1f) << 2;
/* XID field length */
- if (gprs_llc_xid_desc[field->type].var_len)
- len = field->var.val_len;
- else
- len = gprs_llc_xid_desc[field->type].len;
+ len = gprs_llc_xid_field_get_len(field);
if (len == 0)
continue;
@@ -158,7 +173,7 @@
}
/* XID field value (variable length) */
- if (gprs_llc_xid_desc[field->type].var_len) {
+ if (gprs_llc_xid_type_is_variable_len(field->type)) {
if (wptr + len - data > data_len)
return -EINVAL;
memcpy(wptr, field->var.val, len);
@@ -240,7 +255,7 @@
data_len -= len;
/* XID field value (variable length) */
- if (gprs_llc_xid_desc[field->type].var_len) {
+ if (gprs_llc_xid_type_is_variable_len(field->type)) {
field->var.val = len ? ptr : NULL;
field->var.val_len = len;
} else {
@@ -285,8 +300,8 @@
/* Return Deep copy of a xid_field array allocated using talloc ctx. */
struct gprs_llc_xid_field *gprs_llc_xid_deepcopy(void *ctx,
- const struct gprs_llc_xid_field *src_xid,
- size_t src_xid_len)
+ const struct gprs_llc_xid_field *src_xid,
+ size_t src_xid_len)
{
size_t bytes_len = sizeof(*src_xid) * src_xid_len;
struct gprs_llc_xid_field *dst_xid;
--
To view, visit
https://gerrit.osmocom.org/c/libosmo-gprs/+/33946
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings
Gerrit-Project: libosmo-gprs
Gerrit-Branch: master
Gerrit-Change-Id: I8c0163583efc2720a4b2675ce93293c184f80d0c
Gerrit-Change-Number: 33946
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pespin(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: osmith <osmith(a)sysmocom.de>
Gerrit-MessageType: merged