#pragma once #ifdef __cplusplus extern "C" { #endif #include "gtp1_utils.h" #include "gtp2_utils.h" // return GTP version 0 or 1 // return 255 if not GTP static inline uint8_t peek_gtp_version(const char *data, uint16_t len) { if (data == NULL || len == 0) { return 255; } return ((*(uint8_t *)data) >> 5) & 0x07; } static inline uint16_t calc_gtp_hdr_len(const char *data, uint32_t len) { switch (peek_gtp_version(data, len)) { case 1: return calc_gtp1_hdr_len(data, len); case 2: return calc_gtp2_hdr_len(data, len); default: return 0; } } static inline int gtp_hdr_to_str(const char *hdr, uint16_t len, char *buf, size_t size) { switch (peek_gtp_version(hdr, len)) { case 1: return gtp1_hdr_to_str((const struct gtp1_hdr *)hdr, buf, size); case 2: return gtp2_hdr_to_str((const struct gtp2_hdr *)hdr, buf, size); default: return 0; } } #ifdef __cplusplus } #endif