Change in libosmocore[master]: libosmogsm: import hopping sequence generation code

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

fixeria gerrit-no-reply at lists.osmocom.org
Wed May 13 20:30:31 UTC 2020


Hello tnt,

I'd like you to do a code review. Please visit

    https://gerrit.osmocom.org/c/libosmocore/+/18244

to review the following change.


Change subject: libosmogsm: import hopping sequence generation code
......................................................................

libosmogsm: import hopping sequence generation code

This implementation is taken from OsmocomBB, in particular from:

  target/firmware/layer1/rfch.c

Change return type to uint16_t, because neither ARFCN, nor MAI
can be negative. Add prefix 'gsm0502_' to the function's name.

Change-Id: I8aba1578cc9d1bd89d4f5d33a6e8fedc8bea789a
Related: OS#4546
---
M include/osmocom/gsm/gsm0502.h
M src/gsm/gsm0502.c
M src/gsm/libosmogsm.map
3 files changed, 58 insertions(+), 0 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/44/18244/1

diff --git a/include/osmocom/gsm/gsm0502.h b/include/osmocom/gsm/gsm0502.h
index c9901df..cb993dc 100644
--- a/include/osmocom/gsm/gsm0502.h
+++ b/include/osmocom/gsm/gsm0502.h
@@ -47,3 +47,7 @@
 };
 
 uint32_t gsm0502_fn_remap(uint32_t fn, enum gsm0502_fn_remap_channel channel);
+
+uint16_t gsm0502_hop_seq_gen(const struct gsm_time *t,
+			     uint8_t hsn, uint8_t maio,
+			     size_t n, const uint16_t *ma);
diff --git a/src/gsm/gsm0502.c b/src/gsm/gsm0502.c
index 68740dc..7e8dc92 100644
--- a/src/gsm/gsm0502.c
+++ b/src/gsm/gsm0502.c
@@ -2,6 +2,8 @@
  * Paging helper code */
 /*
  * (C) 2009 by Holger Hans Peter Freyther <zecke at selfish.org>
+ * (C) 2010 by Sylvain Munaut <tnt at 246tNt.com>
+ *
  * All Rights Reserved
  *
  * SPDX-License-Identifier: GPL-2.0+
@@ -200,3 +202,54 @@
 
 	return fn_map;
 }
+
+/* Magic numbers (RNTABLE) for pseudo-random hopping sequence generation. */
+static const uint8_t rn_table[114] = {
+	 48,  98,  63,   1,  36,  95,  78, 102,  94,  73,
+	  0,  64,  25,  81,  76,  59, 124,  23, 104, 100,
+	101,  47, 118,  85,  18,  56,  96,  86,  54,   2,
+	 80,  34, 127,  13,   6,  89,  57, 103,  12,  74,
+	 55, 111,  75,  38, 109,  71, 112,  29,  11,  88,
+	 87,  19,   3,  68, 110,  26,  33,  31,   8,  45,
+	 82,  58,  40, 107,  32,   5, 106,  92,  62,  67,
+	 77, 108, 122,  37,  60,  66, 121,  42,  51, 126,
+	117, 114,   4,  90,  43,  52,  53, 113, 120,  72,
+	 16,  49,   7,  79, 119,  61,  22,  84,   9,  97,
+	 91,  15,  21,  24,  46,  39,  93, 105,  65,  70,
+	125,  99,  17, 123,
+};
+
+/*! Hopping sequence generation as per 3GPP TS 45.002, section 6.2.3. */
+uint16_t gsm0502_hop_seq_gen(const struct gsm_time *t,
+			     uint8_t hsn, uint8_t maio,
+			     size_t n, const uint16_t *ma)
+{
+	unsigned int mai;
+
+	if (hsn == 0) {
+		/* cyclic hopping */
+		mai = (t->fn + maio) % n;
+	} else {
+		/* pseudo random hopping */
+		int m, mp, tp, s, pnm;
+
+		pnm = (n >> 0) | (n >> 1)
+		    | (n >> 2) | (n >> 3)
+		    | (n >> 4) | (n >> 5)
+		    | (n >> 6);
+
+		m = t->t2 + rn_table[(hsn ^ (t->t1 & 63)) + t->t3];
+		mp = m & pnm;
+
+		if (mp < n)
+			s = mp;
+		else {
+			tp = t->t3 & pnm;
+			s = (mp + tp) % n;
+		}
+
+		mai = (s + maio) % n;
+	}
+
+	return ma ? ma[mai] : mai;
+}
diff --git a/src/gsm/libosmogsm.map b/src/gsm/libosmogsm.map
index 1ff1286..ce55746 100644
--- a/src/gsm/libosmogsm.map
+++ b/src/gsm/libosmogsm.map
@@ -110,6 +110,7 @@
 
 gsm0502_calc_paging_group;
 gsm0502_fn_remap;
+gsm0502_hop_seq_gen;
 
 gsm0503_xcch;
 gsm0503_rach;

-- 
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/18244
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I8aba1578cc9d1bd89d4f5d33a6e8fedc8bea789a
Gerrit-Change-Number: 18244
Gerrit-PatchSet: 1
Gerrit-Owner: fixeria <axilirator at gmail.com>
Gerrit-Reviewer: tnt <tnt at 246tNt.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20200513/5084d2e4/attachment.htm>


More information about the gerrit-log mailing list