summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2010-05-01 14:25:22 +0200
committerHarald Welte <laforge@gnumonks.org>2010-05-01 14:25:22 +0200
commit35a939463eee58492c88cbe7531288237cdcf454 (patch)
treed03b12f4205760be862df5c67608d6ac1d80fc0f
parentdebf95507461965aa82be2fa2bf34119343cfb0e (diff)
Import gsm48_construct_ra() from openbsc
-rw-r--r--include/osmocore/gsm48.h1
-rw-r--r--src/gsm48.c25
2 files changed, 26 insertions, 0 deletions
diff --git a/include/osmocore/gsm48.h b/include/osmocore/gsm48.h
index a509a096..be9fbbd1 100644
--- a/include/osmocore/gsm48.h
+++ b/include/osmocore/gsm48.h
@@ -29,5 +29,6 @@ int gsm48_mi_to_string(char *string, const int str_len,
/* Parse Routeing Area Identifier */
void gsm48_parse_ra(struct gprs_ra_id *raid, const uint8_t *buf);
+int gsm48_construct_ra(uint8_t *buf, const struct gprs_ra_id *raid);
#endif
diff --git a/src/gsm48.c b/src/gsm48.c
index 7e510664..d957aef6 100644
--- a/src/gsm48.c
+++ b/src/gsm48.c
@@ -326,3 +326,28 @@ void gsm48_parse_ra(struct gprs_ra_id *raid, const uint8_t *buf)
raid->lac = ntohs(*(uint16_t *)(buf + 3));
raid->rac = buf[5];
}
+
+int gsm48_construct_ra(uint8_t *buf, const struct gprs_ra_id *raid)
+{
+ uint16_t mcc = raid->mcc;
+ uint16_t mnc = raid->mnc;
+
+ buf[0] = ((mcc / 100) % 10) | (((mcc / 10) % 10) << 4);
+ buf[1] = (mcc % 10);
+
+ /* I wonder who came up with the stupidity of encoding the MNC
+ * differently depending on how many digits its decimal number has! */
+ if (mnc < 100) {
+ buf[1] |= 0xf0;
+ buf[2] = ((mnc / 10) % 10) | ((mnc % 10) << 4);
+ } else {
+ buf[1] |= (mnc % 10) << 4;
+ buf[2] = ((mnc / 100) % 10) | (((mcc / 10) % 10) << 4);
+ }
+
+ *(uint16_t *)(buf+3) = htons(raid->lac);
+
+ buf[5] = raid->rac;
+
+ return 6;
+}