9
0
Fork 0

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.
This commit is contained in:
Holger Hans Peter Freyther 2012-12-17 10:23:51 +01:00
parent 6808407dcf
commit 4822c8bc56
4 changed files with 27 additions and 8 deletions

View File

@ -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);

View File

@ -21,10 +21,13 @@
#include <isup_types.h>
#include <cellmgr_debug.h>
#include <mtp_data.h>
#include <mtp_level3.h>
#include <osmocom/core/msgb.h>
#include <osmocom/gsm/tlv.h>
#include <endian.h>
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
}

View File

@ -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;
}

View File

@ -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);
}