summaryrefslogtreecommitdiffstats
path: root/src/host/layer23/src/mobile
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <holger@moiji-mobile.com>2018-07-21 22:20:49 +0100
committerHolger Hans Peter Freyther <holger@moiji-mobile.com>2018-07-23 20:55:45 +0100
commit812866daab20dbb9242d7b3a7f417f6d0e1d8a0e (patch)
treee1c46e87d74000766d043e3d2b07731b8104b4d0 /src/host/layer23/src/mobile
parentfd33dcc2023dad960157023b7d5de586612dc5f5 (diff)
Move from libc random() to osmo_get_rand_id (2nd attempt)
When starting multiple mobile in the same second, the libc random number generator will be seeded to exactly the same value. The random bits inside the RACH request(s) will be exactly the same across multiple mobile and when the channel fails they all pick the same randomized back-off timing. Use stronger random numbers and replace all calls to random(2) with osmo_get_rand_id. Add a fallback to try random(). [v2: Add helper to make sure the result is int and between 0 and RAND_MAX] Change-Id: Icdd4be88c62bba1e9d954568e48f0c12a67ac182
Diffstat (limited to 'src/host/layer23/src/mobile')
-rw-r--r--src/host/layer23/src/mobile/gsm322.c4
-rw-r--r--src/host/layer23/src/mobile/gsm48_mm.c3
-rw-r--r--src/host/layer23/src/mobile/gsm48_rr.c3
-rw-r--r--src/host/layer23/src/mobile/settings.c5
4 files changed, 9 insertions, 6 deletions
diff --git a/src/host/layer23/src/mobile/gsm322.c b/src/host/layer23/src/mobile/gsm322.c
index c3485b6a..3bc8b5c8 100644
--- a/src/host/layer23/src/mobile/gsm322.c
+++ b/src/host/layer23/src/mobile/gsm322.c
@@ -31,7 +31,6 @@
#include <osmocom/core/talloc.h>
#include <osmocom/core/utils.h>
#include <osmocom/gsm/gsm48.h>
-#include <osmocom/gsm/gsm_utils.h>
#include <osmocom/core/signal.h>
#include <osmocom/bb/common/logging.h>
@@ -40,6 +39,7 @@
#include <osmocom/bb/common/networks.h>
#include <osmocom/bb/mobile/vty.h>
#include <osmocom/bb/mobile/app_mobile.h>
+#include <osmocom/bb/common/utils.h>
#include <l1ctl_proto.h>
@@ -959,7 +959,7 @@ static int gsm322_sort_list(struct osmocom_ms *ms)
entries++;
}
while(entries) {
- move = random() % entries;
+ move = layer23_random() % entries;
i = 0;
llist_for_each_entry(temp, &temp_list, entry) {
if (rxlev2dbm(temp->rxlev) > -85) {
diff --git a/src/host/layer23/src/mobile/gsm48_mm.c b/src/host/layer23/src/mobile/gsm48_mm.c
index a7af1f5c..02d861e8 100644
--- a/src/host/layer23/src/mobile/gsm48_mm.c
+++ b/src/host/layer23/src/mobile/gsm48_mm.c
@@ -41,6 +41,7 @@
#include <osmocom/bb/mobile/app_mobile.h>
#include <osmocom/bb/mobile/primitives.h>
#include <osmocom/bb/mobile/vty.h>
+#include <osmocom/bb/common/utils.h>
extern void *l23_ctx;
@@ -2099,7 +2100,7 @@ static int gsm48_mm_sysinfo(struct osmocom_ms *ms, struct msgb *msg)
mm->t3212.timeout.tv_sec = current_time.tv_sec
+ (t % s->t3212);
} else {
- uint32_t rand = random();
+ uint32_t rand = layer23_random();
LOGP(DMM, LOGL_INFO, "New T3212 while timer is not "
"running (value %d)\n", s->t3212);
diff --git a/src/host/layer23/src/mobile/gsm48_rr.c b/src/host/layer23/src/mobile/gsm48_rr.c
index dd3fe933..c074323f 100644
--- a/src/host/layer23/src/mobile/gsm48_rr.c
+++ b/src/host/layer23/src/mobile/gsm48_rr.c
@@ -79,6 +79,7 @@
#include <osmocom/bb/common/networks.h>
#include <osmocom/bb/common/l1ctl.h>
#include <osmocom/bb/mobile/vty.h>
+#include <osmocom/bb/common/utils.h>
#include <l1ctl_proto.h>
@@ -1628,7 +1629,7 @@ fail:
}
}
- chan_req = random();
+ chan_req = layer23_random();
chan_req &= rr->chan_req_mask;
chan_req |= rr->chan_req_val;
diff --git a/src/host/layer23/src/mobile/settings.c b/src/host/layer23/src/mobile/settings.c
index 7370b0ab..6a7cd81d 100644
--- a/src/host/layer23/src/mobile/settings.c
+++ b/src/host/layer23/src/mobile/settings.c
@@ -25,6 +25,7 @@
#include <osmocom/core/talloc.h>
#include <osmocom/bb/mobile/app_mobile.h>
+#include <osmocom/bb/common/utils.h>
#include <osmocom/bb/common/logging.h>
#include <osmocom/bb/common/osmocom_data.h>
#include <osmocom/bb/common/networks.h>
@@ -184,8 +185,8 @@ int gsm_random_imei(struct gsm_settings *set)
if (digits > 15)
digits = 15;
- sprintf(rand, "%08ld", random() % 100000000);
- sprintf(rand + 8, "%07ld", random() % 10000000);
+ sprintf(rand, "%08d", layer23_random() % 100000000);
+ sprintf(rand + 8, "%07d", layer23_random() % 10000000);
strcpy(set->imei + 15 - digits, rand + 15 - digits);
strncpy(set->imeisv, set->imei, 15);