path: root/tests
AgeCommit message (Collapse)AuthorFilesLines
4 daystlv_parser: Fix various out-of-bounds accessesHarald Welte2-0/+99
The libosmocore TLV parser had a number of insufficient bounds checks leading to reads beyond the end of the respective input buffer. This patch * adds proper out-of-bounds checks to all TLV types * simplifies some of the existing checks * introduces test cases to test all the corner cases where either TAG, or length, or value are not fully contained in the input buffer. Thanks to Ilja Van Sprundel for reporting these problems. Change-Id: I98b02c914c9e3ecf56050af846292aa6979d7508
11 daysAdd inter-thread queueHarald Welte4-0/+145
This adds an inter-thread queue "it_q" to libosmocore. With it_q, one can perform thread-safe enqueing of messages to another thread, who will receive the related messages triggered via an eventfd handled in the usual libosmocore select loop abstraction. Change-Id: Ie7d0c5fec715a2a577fae014b0b8a0e9c38418ef
11 daysgprs_ns2: set transfer cap in NS Status primitiveAlexander Couzens4-1/+192
Related: SYS#5153 OS#4835 Change-Id: Ia1046db9e0d50855bff9de670b612ffc57af9995
2021-01-01gprs_ns2: call python vty testsAlexander Couzens3-1/+30
Also checks vty docs Change-Id: Ia8b77ae5bc3fed835dd1fc2cce0acbc41f199d54
2021-01-01utils: add osmo-ns-dummyAlexander Couzens2-0/+42
A dummy client to do integration tests of the ns2 layer. It drop all unit data. But allows vty tests. Change-Id: I127c178426bc1a3da8de251740eda93853030d6d
2020-12-16gprs_bssgp: add IE parser/generator for RIM Routing InformationPhilipp Maier3-1/+191
The RIM Routing Information IE (see also 3GPP TS 48.018, section 11.3.70) is used to control the flow of BSSGP rim messages at the SGSN. Change-Id: I6f88a9aeeb50a612d32e9efd23040c9740bc4f11 Related: SYS#5103
2020-12-09logging: Introduce DLBSSGP logging constantHarald Welte1-2/+3
Historically, BSSGP uses a non-constant, user-configurable integer varieable for the logging sub-system. Let's replace this with a statically-allocated library logging constant. This is required if we want to use the subsystem number in e.g. static initialized for osmo_fsm.log_subsys. Change-Id: I506190aae9217c0956e4b5764d1a0c0772268e93
2020-11-15tests: Fix tdef_test on 32bit platformsPau Espin Pedrol2-9/+9
100 minutes = 6000000000 microseconds was too big to be stored in an unsigned long in a 32bit platform, making the test print 4294967295 instead. Let's set a smaller value to have the test happy on 32 bits. Change-Id: Ic0d009f00a69cee59f2d3fc0b40ecdc97d81c75c
2020-11-15Revert "tests: Fix tdef_test on 32bit platforms"Pau Espin Pedrol2-6/+6
This was not the issue, see next commit fixing the correct issue. This reverts commit af10e48c1bf7ec40678b9a4387fc50ab0846b467. Change-Id: Ifa1057ac55fcacdeb55ecdaac1ac3ddcca7d6d65
2020-11-12gsm_04_08: add parser for Mobile Station Classmark 3Philipp Maier2-0/+540
3GPP TS 24.008 section describes a Mobile Station Classmark 3 IE, which is encoded as CSN.1 struct. This means that it can not be parsed by just casting a memory location to a struct pointer, so lets add a parser to parse the CM3 IE. This is fixed version of Ic8b2bfd00330235f5bed00771e421588abfaac1f, which got reverted because it used the keyword "class" as struct member, which lead into problems with c++ builds. This is now fixed. Change-Id: Id8732551b33616227609cd6fcf6c3133751a89eb Related: OS#4796 SYS#5114
2020-11-12tests: Fix tdef_test on 32bit platformsPau Espin Pedrol2-6/+6
60 seconds = 6000000000 microseconds was too big to be stored in an unsigned long in a 32bit platform, making the test print 4294967295 instead. Let's set a smaller value to have the test happy on 32 bits. Change-Id: I97d53f6b7b410cef4b3f3fbe3162626fcdd7b05a
2020-11-11Revert "gsm_04_08: add parser for Mobile Station Classmark 3"Harald Welte2-540/+0
This reverts commit a4939dc8461c0a2d8e67aa3bb95bfb73ad9225b7, which caused massive build failures in C++ programs like osmo-pcu - unsurprisingly, as it calls a struct member "class", which is a reserved keyword in C++. Change-Id: Ia43e56385e7b580f492c560aee8ff8b1e8a0e1d8
2020-11-11tdef: Introduce OSMO_TDEF_US unitPau Espin Pedrol2-2/+36
Some applications may need submillisecond timers, such as those interacting with modbus serial lines (RS-485, RTU), which require timers of values around 1.5 char-time (T1.5), where a data char is composed of 11 bits sent on the line: 1 start bit, 8 data bits, 1 stop bit, and and parity bit (or 2nd stop bits if no parity). For instance, for a baudrate of 9600: 1.5 * 11 / 9600 = 1.718 ms = 1718 us So having a granularity of MS is not enough here. Change-Id: I71848d7c1ee0649929ce07680ee7320bb2a42f0e
2020-11-10gsm_04_08: add parser for Mobile Station Classmark 3Philipp Maier2-0/+540
3GPP TS 24.008 section describes a Mobile Station Classmark 3 IE, which is encoded as CSN.1 struct. This means that it can not be parsed by just casting a memory location to a struct pointer, so lets add a parser to parse the CM3 IE. Change-Id: Ic8b2bfd00330235f5bed00771e421588abfaac1f Related: OS#4796 SYS#5114
2020-10-21vty: introduce the expert mode and a command to enable itVadim Yanitskiy2-2/+86
Some VTY commands are intentionally hidden, e.g. because they might by relatively dangerous if used in production operation. We equip such commands with a special attribute - CMD_ATTR_HIDDEN. The problem is that neiter they appear in the XML VTY reference, nor in the online VTY help, so it's a bit tricky to invoke them. This change introduces so-called 'expert' mode, in which hidden (but not deprecated) commands are getting visible. In the (telnet) VTY session, this mode can be activated by passing an additional argument to well-known 'enable' command: OsmoApp> enable ? [expert-mode] Enable the expert mode (show hidden commands) OsmoApp> enable expert-mode OsmoApp# so then hidden commands will appear together with all the other commands. They will be marked with a special '^' flag: OsmoApp# list with-flags ^ ... foo-hidden [expert-mode] . ... foo-regular-one ! ... foo-immediate ^ u.. app-hidden-unbelievable For the XML reference generation, additional API needs to be introduced. This will be implemented in subsequent patches. Change-Id: Ie69c2a19b22fb31d7bd7f6412f0aeac86ea5048f Related: SYS#4910
2020-10-13gsm: Fix make distcheck with parallel makePau Espin Pedrol1-1/+1
Change-Id: I0bab4cfbc82d2b0aa7bd07769000ab8e4968a00b
2020-10-12add osmo_sockaddr_to_str_buf/osmo_sockaddr_to_strAlexander Couzens2-0/+85
Add helper to format osmo_sockaddr into a string. Change-Id: I917f25ebd1239eae5855d973ced15b93731e33a0
2020-10-09bssmap_le/bsslap tests: We must use %td for ptrdiff_t printingHarald Welte2-9/+9
Otherwise we get (valid!) format string warnings like these on 32bit targets: [ 372s] bssmap_le/bssmap_le_test.c: In function 'test_bssmap_le_enc_dec': [ 372s] bssmap_le/bssmap_le_test.c:141:15: warning: format '%ld' expects argument of type 'long int', but argument 2 has type 'int' [-Wformat=] [ 372s] printf("[%ld] %s: ERROR: failed to encode pdu\n", (pdu - bssmap_le_test_pdus), [ 372s] ^ Closes: OS#4786 Change-Id: Ib1c16b8adc5c8c0a2b418db51d12089f9b49a844
2020-10-08command: add library command attribute for libosmo-abisPhilipp Maier1-0/+2
Change-Id: I0efc57f2cb54798ba207ae6fef9af4771d96bfa9 Related: SYS#4937, OS#1601
2020-10-07add BSSMAP-LE coding for Location ServicesNeels Hofmeyr4-0/+199
BSSMAP-LE: add Lb-interface messages between BSC and SMLC: - Reset - Reset Acknowledge - Perform Location Request, possibly containing BSSLAP TA Layer3 - Perform Location Response - Perform Location Abort - Connection Oriented Information containing any BSSLAP APDU Add encoding and decoding tests. Change-Id: I271e59b794bafc0a7ae0eabbf58918f6d7df431d
2020-10-07add BSSLAP coding for Location ServicesNeels Hofmeyr4-0/+121
BSSLAP: there are APDUs transferred in BSSMAP-LE Connection Oriented Information messages on Lb between BSC and SMLC. Add BSSLAP coding for these APDU messages: - TA Layer3 - TA Request - TA Response, possibly containing Location Estimate coded in GAD - Reject - Reset (for intra-BSS handover during TA Request) - Abort (for inter-BSS handover) Add encoding and decoding tests. Change-Id: I6409c4bcac402dc7626a3afce9081c59cd715fe8
2020-10-07add GAD coding for Location ServicesNeels Hofmeyr4-0/+162
GAD, Universal Geographical Area Description: - raw coding for all GAD elements. - SI-units encoding and decoding for Ellipsoid point with uncertainty circle, which I presume is the typical "at most N meters away from cell tower located at X,Y", which corresponds to the TA positioning currently being implemented. - other SI-units GAD element encodings are so far not implemented. Add encoding and decoding tests. In gsm/protocol/gsm_23_032.h are the raw coding structs as defined in 3GPP TS 23.032. In gsm/gad.h are structs carrying consistent units based on meters and degrees, for convenient / less error prone handling of GAD data, and for human readable representations of the GAD data. The separation of the two is desirable because OsmoBSC will receive GAD data from OsmoSMLC on the Lb interface, and pass on this data to the MSC via the A interface. It is better to pass the GAD data as-is without de/encoding. Change-Id: I7a9dd805a91b1ebb6353bde0cd169218acbf223c
2020-10-07add osmo_float_str_to_int() and osmo_int_to_float_str_*()Neels Hofmeyr2-0/+807
This will be useful to handle latitude and longitude numbers for GAD, which is the location estimate representation used for LCS (Location Services). The OsmoSMLC VTY user interface will provide floating-point strings like "23.456" while GAD stores them as micro-degress 23456000. The osmo_gad_to_str* will also convert latitude and longitude to floating-point string. There was code review concerns against adding this API, upon which I tried to use floating point string formats. But I encountered various problems with accuracy and trailing zeros. For global positioning data (latitude and longitude), even inaccuracy on the sixth significant decimal digit causes noticeable positional shift. To achieve sufficient accuracy on the least significant end, I need to use double instead of float. To remove trailing zeros, the idea was to use '%.6g' format, but that can cause rounding. '%.6f' on a double looks ok, but always includes trailing zeros. A test program shows: %.6g of ((double)(int32_t)23230100)/1e6 = "23.2301" <-- good %.6g of ((double)(int32_t)42419993)/1e6 = "42.42" <-- bad rounding %.6g of ((double)(int32_t)23230199)/1e6 = "23.2302" <-- bad rounding %.6f of ((double)(int32_t)23230100)/1e6 = "23.230100" <-- trailing zeros %.6f of ((double)(int32_t)42419993)/1e6 = "42.419993" <-- good %.6f of ((double)(int32_t)23230199)/1e6 = "23.230199" <-- good It looks like when accepting that there will be trailing zeros, using double with '%.6f' would work out, but in the end I am not certain enough that there aren't more hidden rounding / precision glitches. Hence I decided to reinforce the need to add this API: it is glitch free in sufficient precision for latitude and longitude data, because it is based on integer arithmetic. The need for this precision is particular to the (new) OsmoSMLC vty configuration, where reading and writing back user config must not modify the values the user entered. Considering to add these functions to osmo-smlc.git, we might as well add them here to libosmocore utils, and also use them in osmo_gad_to_str_*() functions. Change-Id: Ib9aee749cd331712a4dcdadfb6a2dfa4c26da957
2020-10-07vty/command: restrict the use of '.', '!', and '@' as flagsVadim Yanitskiy2-0/+10
Change-Id: Icb4acbab0a15de2b0ed7b88fb0e227675317146a Related: SYS#4937
2020-10-07vty/command: assign flags to CMD_ATTR_{IMMEDIATE,NODE_EXIT}Vadim Yanitskiy1-11/+9
Change-Id: I77c1ef7ca4c667c769cc53c7ac65c3be5c7e1c86 Related: SYS#4937
2020-10-07tests/vty: verify 'show vty-attributes' / 'list' commandsVadim Yanitskiy2-0/+157
Change-Id: I397cf642b323a9a99b2406aabaa67a7786dc2a50 Related: SYS#4937
2020-10-06vty: check for reserved flags in application specific attributesVadim Yanitskiy2-0/+4
We agreed to reserve uppercase flag letters for libraries. Change-Id: If0c332f7c86ff26a4060a14b947445d194a6702e Related: SYS#4937
2020-10-04vty: check for duplicate flags in application specific attributesVadim Yanitskiy2-0/+20
This would facilitate detecting duplicates on early development stages. Change-Id: I4e27d6e89d3f851b5ea4f00da01e7093afa537b2 Related: SYS#4937
2020-10-04tests: do not ignore stderr of vty_test, also match itVadim Yanitskiy3-2/+64
This change is needed for I4e27d6e89d3f851b5ea4f00da01e7093afa537b2. Change-Id: Ia601ecd2e69aeb6669e0e2e5dd60135a751611e7
2020-09-15Gb: add a second NS implementationAlexander Couzens1-2/+3
Reimplement NS with FSM. Change-Id: I3525beef205588dfab9d3880a34115f1a2676e48
2020-09-14bitXXgen: add osmo_loadXXbe_ext_2() to get right-adjusted valuesNeels Hofmeyr2-2/+79
As shown in the recently added bitgen_test.c, using osmo_loadXXbe_ext() with a smaller n produces results aligned on the most significant bytes, which is cumbersome, since it does not return a previously stored value. This problem exists only for the big-endian functions, the little-endian osmo_loadXXle_ext() properly return values adjusted on the least significant octets. Add osmo_loadXXbe_ext_2() variants that properly right-adjust the returned value. Prominently highlight this behavior in API doc. Test the new functions in bitgen_test.c. For example, this eases handling of 24bit integers (e.g. loaded from buffer to uint32_t, and stored into buffer from uint32_t). Also explicitly show this 24 bit case in bitgen_test.c Change-Id: I2806df6f0f7bf1ad705d52fa386d4525b892b928
2020-09-14bitXXgen: add bitgen_test.cNeels Hofmeyr4-0/+279
The autogenerated bitXXgen.h headers for osmo_load16le_ext() thru osmo_store64_be() are not actually tested at all. Add a test. The test output shows that the osmo_load*be_ext for a shorter len do not return nicely matching results. A practical example showing the difficulty in storing and loading 24bit integer values as/from big-endian: uint8_t buf[4]; memset(buf, 0, sizeof(buf)); osmo_store32be_ext(0x00112233, buf, 3); // stores 11 22 33 printf("%s\n", osmo_hexdump(buf, 4)); uint32_t r = osmo_load32be_ext(buf, 3); // returns 0x11223300, not 0x00112233 printf("0x%x\n", r); output is: 11 22 33 00 0x11223300 In contrast, the little-endian variant properly aligns the loaded bytes on the least significant octet: uint8_t buf[4]; memset(buf, 0, sizeof(buf)); osmo_store32le_ext(0x00112233, buf, 3); // stores 33 22 11 printf("%s\n", osmo_hexdump(buf, 4)); uint32_t r = osmo_load32le_ext(buf, 3); // returns 0x00112233 as expected printf("0x%x\n", r); output for le is: 33 22 11 00 0x112233 Change-Id: I5542ace54376a206aa8574812d4c742c86c293b4
2020-09-02socket: introduce osmo_sock_init_osa & osmo_sock_init_osa_ofdAlexander Couzens3-0/+141
osmo_sock_init_osa() takes osmo_sockaddr* as local and remote endpoints to setup a socket. Change-Id: I1eece543e3241ef0e095eb63bb831f7c15a16794
2020-09-02tests/socket: add testcase test_get_ip_and_portAlexander Couzens2-0/+35
Check if osmo_sock_get_ip_and_port() works correct. Change-Id: I4e69d814367168c05f0da161ec9b705db36ad096
2020-08-31socket: Fix bug in osmo_sock_init2(AF_UNSPEC) matching IP versionsPau Espin Pedrol2-2/+1
See previous commit for a bug description. Fixes: 2c962f5de1eeea119cfac7d9d92db31c570353b9 Change-Id: I59bf4b4b3ed14766a5a5285923d1ffa9fc8b2294
2020-08-31tests: Add test to showcase osmo_sock_init2 bug with AF_UNSPECPau Espin Pedrol3-0/+8
The function is checking for IP version matching between local and remote addresses even if only one is needed based on flags. For example, if user only desired to bind, the remote address should not be used nor checked. Bug was introduced here: 2c962f5de1eeea119cfac7d9d92db31c570353b9 Change-Id: I87afd1db9bd017426abcc959fa515d15784cdf1c
2020-08-31socket: Add support for AF_INET6 in osmo_sockaddr_to_str_and_uint()Pau Espin Pedrol2-16/+110
Related: SYS#4915 Change-Id: I439c7fa52a3a30eebc3d35e78be7f1724fb69294
2020-08-27lapdm: fix SAPI-0/SAPI-3 frame prioritization on DCCHVadim Yanitskiy1-5/+5
According to 3GPP TS 44.005, section 4.2.2 "Priority": a) on DCCH, a SAPI=0 frame always has higher priority than SAPI=3; b) on ACCH, the priority arrangement is more complex: b1) if a SAPI = 3 frame is awaiting transmission, two SAPI=0 frames shall not be sent in consecutive SACCH frames; b2) on the network side (LAPDM_MODE_BTS), it must also be ensured that any SAPI=3 frame is followed by at least one SAPI=0 frame; b3) a SAPI = 0 frame may be repeated in the next SACCH period if the Repeated SACCH is supported (see 3GPP TS 44.006, section 11). We definitely need to extend our testing coverage to ensure that we implement b) correctly, but for now let's focus on DCCH: a) for DCCH, ensure that SAPI=0 frames preceed SAPI=3 ones; b) for ACCH, re-use the existing round-robin implementation. Change-Id: Ia3780bce1222b312ae2fd2d21496a4d6c5ccb6e0 Related: SYS#5047, OS#4731
2020-08-27lapd_test: add a test checking SAPI0/SAPI3 prioritizationVadim Yanitskiy2-0/+87
Recently we've encountered a situation where during MT SMS delivery, the func=SABM for SAPI=3 was sent on Downlink *before* the BTS replied with the func=UA for SAPI=0 (contetion resolution procedure, where we echo the (RR) Paging Response back to the MS). This change adds a unit test reprodicing the problem. Change-Id: Ied0f8bb683de8e37bcfa984c2877aa1cec1c0b4b Related: SYS#5047, OS#4731
2020-08-27lapd_test: fix: print all messages to stdout, not stderrVadim Yanitskiy2-10/+38
We intentionally do not match stderr output because it contains non-deterministic messages (e.g. pointer addresses), so let's make sure that all test specific messages go to stdout. Change-Id: Ia52f8e811cee9d3e1cd5fcda49a9134ccaa31f7f
2020-08-27lapd_test: rename func=UA (RR) CM Service Request: s/ua/ua_cm/Vadim Yanitskiy1-4/+4
This is basically an ACKnowledgement for (RR) CM Service Request, thus it contains a copy of the original Uplink message (cm). Let's rename it to reflect this explicitly. Change-Id: Id497ff4b688528916495387d64915b14396a68f1
2020-08-27lapd_test: fix wrong comment in lapdm_establish()Vadim Yanitskiy1-1/+1
Change-Id: I2d8f191147249d5ec34a2d1aba3f4dbc26a7824f
2020-08-26gsm0808: add gsm0808_create_sapi_reject_cause()Vadim Yanitskiy1-1/+1
This is basically a successor of gsm0808_create_sapi_reject(), but instead of hard-coding GSM0808_CAUSE_BSS_NOT_EQUIPPED, it allows the caller to specify a cause value to be used. The old function is now deprecated and should not be used. Change-Id: Iefe5484d0fa02d5722b628b1dc237d51d3fb1a9b Related: OS#4728
2020-08-25tests: Split SCTP tests to its own file and run them conditionallyPau Espin Pedrol8-207/+282
Some systmes (like the ones available in OBS) don't support creating SCTP sockets, so we need to skip those tests there. Change-Id: I1d16280674625877ec22cc60cbc5deb67868a656
2020-08-24socket: Log proper getaddrinfo() errorPau Espin Pedrol1-2/+2
Drop one of the two log lines since it would be a duplicated and anyway it misses context (return code). Change-Id: I4620bf86f4bcda58ae85209278ac9ae9a0f3012a
2020-08-24socket: multiaddr: Support IPv4 + IPv6 addresses in SCTP associationsPau Espin Pedrol3-0/+208
The function is improved to support AF_INET:v4->v4, AF_INET6:v6->v6 and AF_UNSPEC:v4+v6->v4+v6. Unit tests for the function are added to make sure function behaves correctly in several scenarios. Change-Id: I36d8ab85d92bba4d6adb83bc1875eb61094ed2ef
2020-08-06osmo_sock_init2: improve support for AF_UNSPECAlexander Couzens3-0/+27
osmo_sock_init2 abstract two calls of getaddrinfo into one. While there aren't problems with AF_INET or AF_INET6. When using AF_UNSPEC there are corner cases when this fails. E.g. calling local_host with "" and remote_host with an IPv6 only address results in setting up a local socket with AF_INET while trying to connect from there towards AF_INET6 will most likely fail. To prevent such cases with AF_UNSPEC, search prio calling any syscalls if local and remote site supports AF_INET or AF_INET6. In case both supported, prefer AF_INET6 Change-Id: I397c633931fd00d4f083955a3c49a40fb002d766
2020-08-02i460: Fix bit- and subslots ordering of I.460 mux + demuxHarald Welte2-67/+67
When I wrote the new I.460 mux + demux code, I failed to realize that * bit numbers in relevant ITU specs start with 1 as MSB ... 8 as LSB * sub-slot 0 is bits 1+2, i.e. the two MSBs of a byte * bit-ordering within each sub-slot is also MSB first As a result, the code and test data was broken. Change-Id: I6df7dbf411efbdeaf516e72ac552432bf5a569d0
2020-08-02i460: pass more context to call-back functionsHarald Welte1-1/+2
When calling a user-provided call-back function for the i460 mux or demux, always pass a pointer to the osmo_i460_subchan the callback relates to. This way, the user can walk the i460 data structures to obtain information about which mux/demux instances is calling. Change-Id: Id842c72ce371a67fe5df6694e195c281aaf607ab
2020-07-30vty: Don't match negative values on purely positive rangesPau Espin Pedrol2-3/+2
Without this patch, for instance having a range 0-ULONG_MAX would match if someones types value -3, which would be converted to unsigned but that's clearly what is expected here from user point of view. Change-Id: Ia95f6314a2dd3f94d21fc219cf69bb8d39b8e7f0