From 4011e728d22a9affbe41fb2bfc8e69c14bd706ab Mon Sep 17 00:00:00 2001 From: Max Date: Tue, 5 Jul 2016 15:19:12 +0200 Subject: SGSN: use unique AUTH REQ reference MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The A&C reference number specified in 3GPP TS 24.008 ยง 10.5.5.19 identifies particular request sent by network with the related response sent by MS. The value transparently copied from request to response by MS: the spec do not specify what exactly should be in there so we use rand() to decrease chance for collisions. Note: variable named 'rand' clashes with standard function rand() so it was renamed. Change-Id: I3638821a9b4a0532b28dbbb50faa30c4082579f6 Related: OS#1582 --- openbsc/tests/sgsn/Makefile.am | 1 + openbsc/tests/sgsn/sgsn_test.c | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) (limited to 'openbsc/tests') diff --git a/openbsc/tests/sgsn/Makefile.am b/openbsc/tests/sgsn/Makefile.am index e3cec5086..b6036c75c 100644 --- a/openbsc/tests/sgsn/Makefile.am +++ b/openbsc/tests/sgsn/Makefile.am @@ -7,6 +7,7 @@ noinst_PROGRAMS = sgsn_test sgsn_test_SOURCES = sgsn_test.c sgsn_test_LDFLAGS = \ + -Wl,--wrap=RAND_bytes \ -Wl,--wrap=sgsn_update_subscriber_data \ -Wl,--wrap=gprs_subscr_request_update_location \ -Wl,--wrap=gprs_subscr_request_auth_info \ diff --git a/openbsc/tests/sgsn/sgsn_test.c b/openbsc/tests/sgsn/sgsn_test.c index d568807dd..e8e05f6e9 100644 --- a/openbsc/tests/sgsn/sgsn_test.c +++ b/openbsc/tests/sgsn/sgsn_test.c @@ -101,6 +101,25 @@ int bssgp_tx_dl_ud(struct msgb *msg, uint16_t pdu_lifetime, return 0; } +/* override, requires '-Wl,--wrap=RAND_bytes' */ +int __real_RAND_bytes(unsigned char *buf, int num); +int mock_RAND_bytes(unsigned char *buf, int num); +int (*RAND_bytes_cb)(unsigned char *, int) = + &mock_RAND_bytes; + +int __wrap_RAND_bytes(unsigned char *buf, int num) +{ + return (*RAND_bytes_cb)(buf, num); +} +/* make results of A&C ref predictable */ +int mock_RAND_bytes(unsigned char *buf, int num) +{ + if (num > 1) + return __real_RAND_bytes(buf, num); + buf[0] = 0; + return 1; +} + /* override, requires '-Wl,--wrap=sgsn_update_subscriber_data' */ void __real_sgsn_update_subscriber_data(struct sgsn_mm_ctx *); void (*update_subscriber_data_cb)(struct sgsn_mm_ctx *) = -- cgit v1.2.3