Add function for appending range1024 to bitvec
diff mbox

Message ID 1461346089-9218-1-git-send-email-msuraev@sysmocom.de
State New
Headers show

Commit Message

Max April 22, 2016, 5:28 p.m. UTC
From: Max <msuraev@sysmocom.de>

Add convenience function to append range1024 encoded data (see 3GPP TS
44.018 Annex J) to a given bitvec.
---
 include/Makefile.am              |  1 +
 include/osmocom/gsm/bitvec_gsm.h | 13 +++++++++++++
 src/gsm/gsm_utils.c              | 36 ++++++++++++++++++++++++++++++++++++
 src/gsm/libosmogsm.map           |  2 +-
 4 files changed, 51 insertions(+), 1 deletion(-)
 create mode 100644 include/osmocom/gsm/bitvec_gsm.h

Patch
diff mbox

diff --git a/include/Makefile.am b/include/Makefile.am
index 0e5ed74..86aaf72 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -57,6 +57,7 @@  nobase_include_HEADERS = \
                        osmocom/gsm/apn.h \
                        osmocom/gsm/comp128.h \
                        osmocom/gsm/comp128v23.h \
+                       osmocom/gsm/bitvec_gsm.h \
                        osmocom/gsm/gan.h \
                        osmocom/gsm/gsm0341.h \
                        osmocom/gsm/gsm0411_smc.h \
diff --git a/include/osmocom/gsm/bitvec_gsm.h b/include/osmocom/gsm/bitvec_gsm.h
new file mode 100644
index 0000000..20741ef
--- /dev/null
+++ b/include/osmocom/gsm/bitvec_gsm.h
@@ -0,0 +1,13 @@ 
+#pragma once
+
+#include <osmocom/core/bitvec.h>
+#include <osmocom/gsm/protocol/gsm_04_08.h>
+
+/*! \defgroup bitvec helpers for GSM
+ *  @{
+ */
+/*! \file bitvec_gsm.h */
+
+void bitvec_add_range1024(struct bitvec *bv, const struct gsm48_range_1024 *r);
+
+/*! @} */
diff --git a/src/gsm/gsm_utils.c b/src/gsm/gsm_utils.c
index e8e452f..5002947 100644
--- a/src/gsm/gsm_utils.c
+++ b/src/gsm/gsm_utils.c
@@ -64,7 +64,9 @@ 
 
 //#include <openbsc/gsm_data.h>
 #include <osmocom/core/utils.h>
+#include <osmocom/core/bitvec.h>
 #include <osmocom/gsm/gsm_utils.h>
+#include <osmocom/gsm/protocol/gsm_04_08.h>
 
 #include <stdlib.h>
 #include <stdint.h>
@@ -655,6 +657,40 @@  uint32_t gsm_gsmtime2fn(struct gsm_time *time)
 	return (51 * ((time->t3 - time->t2 + 26) % 26) + time->t3 + (26 * 51 * time->t1));
 }
 
+/*! \brief append range1024 encoded data to bit vector */
+void bitvec_add_range1024(struct bitvec *bv, const struct gsm48_range_1024 *r)
+{
+	bitvec_set_uint(bv, r->w1_hi, 2);
+	bitvec_set_uint(bv, r->w1_lo, 8);
+	bitvec_set_uint(bv, r->w2_hi, 8);
+	bitvec_set_uint(bv, r->w2_lo, 1);
+	bitvec_set_uint(bv, r->w3_hi, 7);
+	bitvec_set_uint(bv, r->w3_lo, 2);
+	bitvec_set_uint(bv, r->w4_hi, 6);
+	bitvec_set_uint(bv, r->w4_lo, 2);
+	bitvec_set_uint(bv, r->w5_hi, 6);
+	bitvec_set_uint(bv, r->w5_lo, 2);
+	bitvec_set_uint(bv, r->w6_hi, 6);
+	bitvec_set_uint(bv, r->w6_lo, 2);
+	bitvec_set_uint(bv, r->w7_hi, 6);
+	bitvec_set_uint(bv, r->w7_lo, 2);
+	bitvec_set_uint(bv, r->w8_hi, 6);
+	bitvec_set_uint(bv, r->w8_lo, 1);
+	bitvec_set_uint(bv, r->w9, 7);
+	bitvec_set_uint(bv, r->w10, 7);
+	bitvec_set_uint(bv, r->w11_hi, 1);
+	bitvec_set_uint(bv, r->w11_lo, 6);
+	bitvec_set_uint(bv, r->w12_hi, 2);
+	bitvec_set_uint(bv, r->w12_lo, 5);
+	bitvec_set_uint(bv, r->w13_hi, 3);
+	bitvec_set_uint(bv, r->w13_lo, 4);
+	bitvec_set_uint(bv, r->w14_hi, 4);
+	bitvec_set_uint(bv, r->w14_lo, 3);
+	bitvec_set_uint(bv, r->w15_hi, 5);
+	bitvec_set_uint(bv, r->w15_lo, 2);
+	bitvec_set_uint(bv, r->w16, 6);
+}
+
 /* TS 23.003 Chapter 2.6 */
 int gprs_tlli_type(uint32_t tlli)
 {
diff --git a/src/gsm/libosmogsm.map b/src/gsm/libosmogsm.map
index a526756..f9a8369 100644
--- a/src/gsm/libosmogsm.map
+++ b/src/gsm/libosmogsm.map
@@ -25,7 +25,7 @@  abis_nm_osmo_magic;
 abis_nm_ipa_magic;
 
 osmo_sitype_strs;
-
+bitvec_add_range1024;
 comp128;
 dbm2rxlev;