From 4822c8bc568b46088bffda77c42454df55819481 Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Mon, 17 Dec 2012 10:23:51 +0100 Subject: isup: Make isup CIC parsing/using work on big endian machines as well This is a hot fix to make CIC reading (and later status) work on big endian machines. There might be a more elegant way to do it and I will explore this later. --- include/isup_types.h | 1 + src/isup.c | 15 +++++++++++++++ src/isup_filter.c | 11 +++++++---- tests/isup/isup_parse_test.c | 8 ++++---- 4 files changed, 27 insertions(+), 8 deletions(-) diff --git a/include/isup_types.h b/include/isup_types.h index 083f2bf..c633fdf 100644 --- a/include/isup_types.h +++ b/include/isup_types.h @@ -48,6 +48,7 @@ struct isup_msg_grs { uint8_t pointer_int; }; +uint16_t isup_cic_to_local(const struct isup_msg_hdr *hdr); int mtp_link_set_isup(struct mtp_link_set *set, struct msgb *msg, int sls); int isup_parse_status(const uint8_t *data, uint8_t length); diff --git a/src/isup.c b/src/isup.c index 31b4221..2827f21 100644 --- a/src/isup.c +++ b/src/isup.c @@ -21,10 +21,13 @@ #include #include #include +#include #include #include +#include + static struct msgb *isup_status_alloc(int cic, int msg_type, uint8_t *extra, int range, int val) { struct isup_msg_hdr *hdr; @@ -260,3 +263,15 @@ int mtp_link_set_isup(struct mtp_link_set *set, struct msgb *msg, int sls) return rc; } + +uint16_t isup_cic_to_local(const struct isup_msg_hdr *hdr) +{ +#if __BYTE_ORDER == __LITTLE_ENDIAN + return hdr->cic; +#elif __BYTE_ORDER == __BIG_ENDIAN + return c_swap_16(hdr->cic); +#else + #error "Unknown endian" +#endif +} + diff --git a/src/isup_filter.c b/src/isup_filter.c index 0e9a10c..b7c8e1a 100644 --- a/src/isup_filter.c +++ b/src/isup_filter.c @@ -61,6 +61,7 @@ int isup_scan_for_reset(struct ss7_application *app, struct msgb *msg) { struct isup_msg_hdr *hdr; int range; + uint16_t cic; /* too small for an isup message? */ if (msgb_l3len(msg) < sizeof(*hdr)) { @@ -76,6 +77,8 @@ int isup_scan_for_reset(struct ss7_application *app, struct msgb *msg) } hdr = (struct isup_msg_hdr *) msg->l3h; + cic = isup_cic_to_local(hdr); + switch (hdr->msg_type) { case ISUP_MSG_GRS: range = isup_parse_status(&hdr->data[0], @@ -88,14 +91,14 @@ int isup_scan_for_reset(struct ss7_application *app, struct msgb *msg) LOGP(DISUP, LOGL_DEBUG, "Going to reset ISUP for app %s, cic %d range %d\n", - app->name, hdr->cic, range); - reset_cics(app, hdr->cic, range); + app->name, cic, range); + reset_cics(app, cic, range); break; case ISUP_MSG_RSC: LOGP(DISUP, LOGL_DEBUG, "Going to reset single CIC %d on app %s\n", - hdr->cic, app->name); - reset_cic(app, hdr->cic); + cic, app->name); + reset_cic(app, cic); break; } diff --git a/tests/isup/isup_parse_test.c b/tests/isup/isup_parse_test.c index 4010fcf..7e116b3 100644 --- a/tests/isup/isup_parse_test.c +++ b/tests/isup/isup_parse_test.c @@ -38,7 +38,7 @@ static void test_cic_parsing() printf("Testing CIC parsing.\n"); hdr = (struct isup_msg_hdr *) isup_grs; - ASSERT(hdr->cic, 3); + ASSERT(isup_cic_to_local(hdr), 3); ASSERT(hdr->msg_type, ISUP_MSG_GRS); } @@ -53,7 +53,7 @@ static void test_grs_parsing() hdr = (struct isup_msg_hdr *) isup_grs; range = isup_parse_status(&hdr->data[0], 3); - ASSERT(hdr->cic, 3); + ASSERT(isup_cic_to_local(hdr), 3); ASSERT(hdr->msg_type, ISUP_MSG_GRS); ASSERT(range, 28); } @@ -70,7 +70,7 @@ static void test_gra_parsing() printf("Testing GRA parsing.\n"); hdr = (struct isup_msg_hdr *) isup_gra; range = isup_parse_status(&hdr->data[0], 3); - ASSERT(hdr->cic, 2); + ASSERT(isup_cic_to_local(hdr), 2); ASSERT(hdr->msg_type, ISUP_MSG_GRA); ASSERT(range, 29); } @@ -82,7 +82,7 @@ static void test_rsc_parsing() printf("Testing RSC parsing.\n"); hdr = (struct isup_msg_hdr *) isup_rsc; - ASSERT(hdr->cic, 1); + ASSERT(isup_cic_to_local(hdr), 1); ASSERT(hdr->msg_type, ISUP_MSG_RSC); } -- cgit v1.2.3