Skip to content

Instantly share code, notes, and snippets.

@cbalint13
Last active October 21, 2021 08:03
Show Gist options
  • Save cbalint13/1fc06269b2b1c1e460751d7236d0ceea to your computer and use it in GitHub Desktop.
Save cbalint13/1fc06269b2b1c1e460751d7236d0ceea to your computer and use it in GitHub Desktop.
o5gs-debug-tlv-parse.diff
diff --git a/lib/core/ogs-tlv.c b/lib/core/ogs-tlv.c
index a43108f..8be4268 100644
--- a/lib/core/ogs-tlv.c
+++ b/lib/core/ogs-tlv.c
@@ -398,6 +398,31 @@ uint32_t ogs_tlv_render(ogs_tlv_t *root,
return (pos - blk);
}
+
+static void dump_root_tlv_chain(ogs_tlv_t *root)
+{
+ ogs_tlv_t *entry = root;
+
+ printf("---------- BEGIN TLV treee ---------\n");
+ while(entry) {
+ printf("\n");
+ printf(" entry->next=%p\n", entry->next);
+ printf(" entry->type=%i\n", (uint32_t)entry->type);
+ printf(" entry->length=%i\n", (uint32_t)entry->length);
+ printf(" entry->instance=%i\n", (uint8_t)entry->instance);
+ printf(" entry->value=%p\n", entry->value);
+ if (entry->value)
+ ogs_log_hexdump(OGS_LOG_ERROR, entry->value, (uint32_t)entry->length);
+
+ entry = entry->next;
+
+ }
+ printf("---------- END TLV treee ---------\n");
+ printf("\n");
+
+ return;
+}
+
/* ogs_tlv_t parsing functions */
ogs_tlv_t *ogs_tlv_parse_block(uint32_t length, void *data, uint8_t mode)
{
@@ -411,11 +436,18 @@ ogs_tlv_t *ogs_tlv_parse_block(uint32_t length, void *data, uint8_t mode)
root = curr = ogs_tlv_get();
ogs_assert(curr);
+ printf("ogs_tlv_parse_block() data: %p\n", data);
+ #include "ogs-log.h"
+ ogs_log_hexdump(OGS_LOG_ERROR, data, length);
+ printf("\n");
+ printf("tlv_get_element(curr, pos, mode=%i)\n", mode);
pos = tlv_get_element(curr, pos, mode);
-
ogs_assert(pos);
+ // debug
+ dump_root_tlv_chain(root);
+
while(pos - blk < length) {
prev = curr;
@@ -423,12 +455,33 @@ ogs_tlv_t *ogs_tlv_parse_block(uint32_t length, void *data, uint8_t mode)
ogs_assert(curr);
prev->next = curr;
+
+ printf(" pos %p [offset=data+%lu]", pos, (size_t)pos -(size_t)data);
+ ogs_log_hexdump(OGS_LOG_ERROR, pos, 8);
+ printf(" tlv_get_element()\n");
+ uint8_t *origpos = pos;
pos = tlv_get_element(curr, pos, mode);
+ printf(" curr->type=%i\n", (uint32_t)curr->type);
+ printf(" curr->length=%i\n", (uint32_t)curr->length);
+ printf(" curr->instance=%i\n", (uint8_t)curr->instance);
+ printf(" curr->value=%p\n", curr->value);
+ ogs_log_hexdump(OGS_LOG_ERROR, curr->value, (uint32_t)curr->length);
+ printf(" [origpos - pos => %lu]\n", (size_t)pos - (size_t)origpos);
+ printf(" [pos - curr->value => %lu]\n", (size_t)pos - (size_t)curr->value);
+ printf(" [curr->value - origpos => %lu]\n", (size_t)curr->value - (size_t)origpos);
+ printf("\n");
+ printf("\n");
+
ogs_assert(pos);
}
+
+ printf("\n");
ogs_assert(length == (pos - blk));
+ // debug
+ dump_root_tlv_chain(root);
+
return root;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment