diff options
-rw-r--r-- | src/osmo-bts-sysmo/l1_if.c | 14 | ||||
-rw-r--r-- | src/osmo-bts-sysmo/l1_if.h | 8 | ||||
-rw-r--r-- | tests/sysmobts/Makefile.am | 11 | ||||
-rw-r--r-- | tests/sysmobts/sysmobts_test.c | 70 |
4 files changed, 100 insertions, 3 deletions
diff --git a/src/osmo-bts-sysmo/l1_if.c b/src/osmo-bts-sysmo/l1_if.c index 90d3f426..16e2bc60 100644 --- a/src/osmo-bts-sysmo/l1_if.c +++ b/src/osmo-bts-sysmo/l1_if.c @@ -395,6 +395,20 @@ static inline void check_for_first_ciphrd(struct femtol1_hdl *fl1h, l1if_set_ciphering(fl1h, lchan, 1); } +/* public helpers for the test */ +int bts_check_for_ciph_cmd(struct femtol1_hdl *fl1h, + struct msgb *msg, struct gsm_lchan *lchan) +{ + return check_for_ciph_cmd(fl1h, msg, lchan); +} + +void bts_check_for_first_ciphrd(struct femtol1_hdl *fl1h, + GsmL1_MsgUnitParam_t *msgUnitParam, + struct gsm_lchan *lchan) +{ + return check_for_first_ciphrd(fl1h, msgUnitParam, lchan); +} + static const uint8_t fill_frame[GSM_MACBLOCK_LEN] = { 0x03, 0x03, 0x01, 0x2B, 0x2B, 0x2B, 0x2B, 0x2B, 0x2B, 0x2B, 0x2B, 0x2B, 0x2B, 0x2B, 0x2B, 0x2B, 0x2B, 0x2B, 0x2B, 0x2B, diff --git a/src/osmo-bts-sysmo/l1_if.h b/src/osmo-bts-sysmo/l1_if.h index 1168aeaf..77144931 100644 --- a/src/osmo-bts-sysmo/l1_if.h +++ b/src/osmo-bts-sysmo/l1_if.h @@ -7,6 +7,8 @@ #include <osmocom/core/timer.h> #include <osmocom/gsm/gsm_utils.h> +#include <sysmocom/femtobts/gsml1prim.h> + enum { MQ_SYS_READ, MQ_L1_READ, @@ -124,4 +126,10 @@ int calib_load(struct femtol1_hdl *fl1h); int l1if_rf_clock_info_reset(struct femtol1_hdl *fl1h); int l1if_rf_clock_info_correct(struct femtol1_hdl *fl1h); +/* public helpers for test */ +int bts_check_for_ciph_cmd(struct femtol1_hdl *fl1h, + struct msgb *msg, struct gsm_lchan *lchan); +void bts_check_for_first_ciphrd(struct femtol1_hdl *fl1h, + GsmL1_MsgUnitParam_t *msgUnitParam, + struct gsm_lchan *lchan); #endif /* _FEMTO_L1_H */ diff --git a/tests/sysmobts/Makefile.am b/tests/sysmobts/Makefile.am index 17160ba5..79d13a1e 100644 --- a/tests/sysmobts/Makefile.am +++ b/tests/sysmobts/Makefile.am @@ -6,5 +6,12 @@ noinst_PROGRAMS = sysmobts_test EXTRA_DIST = sysmobts_test.ok sysmobts_test_SOURCES = sysmobts_test.c $(top_srcdir)/src/osmo-bts-sysmo/utils.c \ - $(srcdir)/../stubs.c -sysmobts_test_LDADD = $(LDADD) + $(top_srcdir)/src/osmo-bts-sysmo/l1_if.c \ + $(top_srcdir)/src/osmo-bts-sysmo/oml.c \ + $(top_srcdir)/src/osmo-bts-sysmo/l1_transp_hw.c \ + $(top_srcdir)/src/osmo-bts-sysmo/tch.c \ + $(top_srcdir)/src/osmo-bts-sysmo/calib_file.c \ + $(top_srcdir)/src/osmo-bts-sysmo/calib_fixup.c \ + $(top_srcdir)/src/osmo-bts-sysmo/misc/sysmobts_par.c \ + $(top_srcdir)/src/osmo-bts-sysmo/eeprom.c +sysmobts_test_LDADD = $(top_builddir)/src/common/libbts.a $(LIBOSMOABIS_LIBS) $(LDADD) diff --git a/tests/sysmobts/sysmobts_test.c b/tests/sysmobts/sysmobts_test.c index 291f6da8..acbc09c9 100644 --- a/tests/sysmobts/sysmobts_test.c +++ b/tests/sysmobts/sysmobts_test.c @@ -1,5 +1,5 @@ /* - * (C) 2013 by Holger Hans Peter Freyther + * (C) 2013,2014 by Holger Hans Peter Freyther * * All Rights Reserved * @@ -23,8 +23,12 @@ #include "l1_if.h" #include "utils.h" +#include <sysmocom/femtobts/gsml1prim.h> + #include <stdio.h> +int pcu_direct = 0; + static int direct_map[][3] = { { GSM_BAND_850, GsmL1_FreqBand_850, 128 }, { GSM_BAND_900, GsmL1_FreqBand_900, 1 }, @@ -125,9 +129,73 @@ static void test_sysmobts_auto_band(void) } } +static void test_sysmobts_cipher(void) +{ + static const uint8_t cipher_cmd[] = { + 0x03, 0x00, 0x0d, 0x06, 0x35, 0x11, 0x2b, 0x2b, + 0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b, + 0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b }; + static const uint8_t too_early_classmark[] = { + 0x01, 0x00, 0x4d, 0x06, 0x16, 0x03, 0x30, 0x18, + 0xa2, 0x20, 0x0b, 0x60, 0x14, 0x4c, 0xa7, 0x7b, + 0x29, 0x11, 0xdc, 0x40, 0x04, 0x00, 0x2b }; + static const uint8_t first_ciphered_cipher_cmpl[] = { + 0x01, 0x30, 0x4d, 0x06, 0x16, 0x03, 0x30, 0x18, + 0xa2, 0x20, 0x0b, 0x60, 0x14, 0x4c, 0xa7, 0x7b, + 0x29, 0x11, 0xdc, 0x40, 0x04, 0x00, 0x2b }; + + struct gsm_lchan lchan; + struct femtol1_hdl fl1h; + struct msgb *msg; + GsmL1_MsgUnitParam_t unit; + int rc; + + memset(&lchan, 0, sizeof(lchan)); + memset(&fl1h, 0, sizeof(fl1h)); + + /* Inject the cipher mode command */ + msg = msgb_alloc_headroom(128, 64, "ciphering mode command"); + lchan.ciph_state = LCHAN_CIPH_NONE; + memcpy(msgb_put(msg, ARRAY_SIZE(cipher_cmd)), cipher_cmd, ARRAY_SIZE(cipher_cmd)); + rc = bts_check_for_ciph_cmd(&fl1h, msg, &lchan); + OSMO_ASSERT(rc == 1); + OSMO_ASSERT(lchan.ciph_state == LCHAN_CIPH_RX_REQ); + OSMO_ASSERT(lchan.ciph_ns == 1); + msgb_free(msg); + + /* Move to the confirmed state */ + lchan.ciph_state = LCHAN_CIPH_RX_CONF; + + /* Handle message sent before ciphering was received */ + memcpy(&unit.u8Buffer[0], too_early_classmark, ARRAY_SIZE(too_early_classmark)); + unit.u8Size = ARRAY_SIZE(too_early_classmark); + bts_check_for_first_ciphrd(&fl1h, &unit, &lchan); + OSMO_ASSERT(lchan.ciph_state == LCHAN_CIPH_RX_CONF); + + /* Now send the first ciphered message */ + memcpy(&unit.u8Buffer[0], first_ciphered_cipher_cmpl, ARRAY_SIZE(first_ciphered_cipher_cmpl)); + unit.u8Size = ARRAY_SIZE(first_ciphered_cipher_cmpl); + bts_check_for_first_ciphrd(&fl1h, &unit, &lchan); + OSMO_ASSERT(lchan.ciph_state == LCHAN_CIPH_TXRX_REQ); +} + int main(int argc, char **argv) { printf("Testing sysmobts routines\n"); test_sysmobts_auto_band(); + test_sysmobts_cipher(); return 0; } + + +/* + * some local stubs. We need to pull in a lot more code and can't + * use the generic stubs unless we make all of them weak + */ +void bts_update_status(enum bts_global_status which, int on) +{} + +int bts_model_init(struct gsm_bts *bts) +{ return 0; } +int bts_model_oml_estab(struct gsm_bts *bts) +{ return 0; } |