aboutsummaryrefslogtreecommitdiffstats
path: root/openbsc/tests/gbproxy/gbproxy_test.c
AgeCommit message (Collapse)AuthorFilesLines
2014-09-02gbproxy: Implement IMSI acquisitionJacob Erlbeck1-2/+18
To modify or route messages based on the IMSI the latter must be known when the action shall take place. This patch modifies the gbproxy to optionally retain and enqueue messages from the MS while initiating an identification procedure. Further message processing of the LLC PTP link towards the SGSN will be done, when the identity of the MS has been acquired. Note that the N(U) of the LLC GMM SAPI are not adjusted, so it is possible that adjacent messages of a single LLC link arriving either at the BSS or the SGSN have the same N(U) and might get discarded, leading to retransmissions and additional delay. Note also that retransmissions and packet loss are not yet handled explicitely. If for instance the generated IDENT REQ gets lost, the gbproxy will not act on its own. In this case, the MS will time out and eventually resend the Attach Request on which the gbproxy will act exactly like before (thus having two Attach Req messages in its queue, which will both be sent after the Ident Resp arrives). This has been tested successfully with an E71, needing one retransmission by the SGSN due to an N(U) collision. Ticket: OW#1261 Sponsored-by: On-Waves ehf
2014-09-02gbproxy/test: Add a test for IMSI acquisitionJacob Erlbeck1-0/+218
This patch copies test_gbproxy_ptmsi_patching to test_gbproxy_imsi_acquisition as a base for a later test for IMSI acquisition (which is not yet implemented). The idea behind this is to make the different behaviour visible in the ok file without compromising the P-TMSI test. Sponsored-by: On-Waves ehf
2014-09-02gbproxy/test: Test patching BSSGP SUSPEND/LLC-DISCARDEDJacob Erlbeck1-10/+78
Currently messages like these with a TLLI IE (BSSGP) are not tested (properly) with TLLI patching. This patch extends the send_bssgp_suspend* functions to accept a TLLI as argument and adds the send_bssgp_llc_discarded function. These are then used in test_gbproxy_ptmsi_patching() with a valid TLLI. Note that the TLLI IE patching doesn't work currently. Sponsored-by: On-Waves ehf
2014-08-24gbproxy: Move peer definitions to gb_proxy_peer.cJacob Erlbeck1-2/+2
This patch moves the peer related definitions from gb_proxy.c to gb_proxy_peer.c and adjusts the prefix of each global symbol to gbproxy_: Peer definitions (prefix adjusted to gbproxy_): peer_ctr_description -> gprs/gb_proxy_peer.c (static) peer_ctrg_desc -> gprs/gb_proxy_peer.c (static) *peer_by_* -> gprs/gb_proxy_peer.c gbproxy_peer_alloc -> gprs/gb_proxy_peer.c gbproxy_peer_free -> gprs/gb_proxy_peer.c gbprox_cleanup_peers -> gprs/gb_proxy_peer.c Sponsored-by: On-Waves ehf
2014-08-24gbproxy: Refactor gb_proxy.c into several filesJacob Erlbeck1-63/+63
This patch moves several functions and declarations out of gb_proxy.c to make them reusable by other components and to separate them by context and task. Counter enums (prefix is changed to gbproxy_): enum gbprox_global_ctr -> gprs/gb_proxy.h enum gbprox_peer_ctr -> gprs/gb_proxy.h Generic Gb parsing (prefix is changed to gprs_gb_): struct gbproxy_parse_context -> openbsc/gprs_gb_parse.h gbprox_parse_dtap() -> gprs/gprs_gb_parse.c gbprox_parse_llc() -> gprs/gprs_gb_parse.c gbprox_parse_bssgp() -> gprs/gprs_gb_parse.c gbprox_log_parse_context() -> gprs/gprs_gb_parse.c *_shift(), *_match() -> gprs/gprs_gb_parse.c (no prefix) gbprox_parse_gmm_* -> gprs/gprs_gb_parse.c (static) gbprox_parse_gsm_* -> gprs/gprs_gb_parse.c (static) MI testing/parsing (prefix gprs_ added): is_mi_tmsi() -> gprs/gprs_utils.c is_mi_imsi() -> gprs/gprs_utils.c parse_mi_tmsi() -> gprs/gprs_utils.c TLLI state handling (prefix is changed to gbproxy_): gbprox_*tlli* -> gprs/gb_proxy_tlli.c (except gbprox_patch_tlli, gbproxy_make_sgsn_tlli) Message patching (prefix is changed to gbproxy_): gbprox_*patch* -> gprs/gb_proxy_patch.c gbprox_check_imsi -> gprs/gb_proxy_patch.c Sponsored-by: On-Waves ehf
2014-08-24gbproxy/test: Add test for TLLI patchingJacob Erlbeck1-0/+238
Add LLC test messages containing XID (SAPI LLGMM, U frame) and IP traffic (SAPI LL11, UI frame). Add a test case containing a complete SGSN session with TLLI/PTMSI patching enabled. Sponsored-by: On-Waves ehf
2014-08-24gbproxy: Track SGSN and BSS TLLI/PTMSI separatelyJacob Erlbeck1-28/+68
This patch separates BSS side from SGSN side TLLI/PTMSI tracking. When TLLI/PTMSI patching is not enabled, the corresponding states shall be identical. The TLLI/PTMSI state has been moved into the struct gbproxy_tlli_state and is used twice in gbproxy_tlli_info. Since the state handling for uplink and downlink messages is diverging, gbprox_update_state() is replaced by two functions gbprox_update_state_dl/gbprox_update_state_ul and gbprox_process_bssgp_message() is replaced by gbprox_process_bssgp_dl/gbprox_process_bssgp_ul. Sponsored-by: On-Waves ehf
2014-08-24gbproxy/test: Generate BSSGP and LLC layer for DTAP messagesJacob Erlbeck1-150/+299
This patch adds the functions send_bssgp_ul_unitdata(), send_bssgp_dl_unitdata(), send_llc_ul_ui(), and send_llc_dl_ui(). They are used instead of send_ns_unitdata() in test_gbproxy_ra_patching(). This make it easier to modify TLLI, N(U), and other parameters. Sponsored-by: On-Waves ehf
2014-08-24gbproxy/test: Fix BSSGP/LLC test messagesJacob Erlbeck1-14/+13
The following parts of the messages have been fixed - Attach Accept: checksum - Attach Complete: checksum - RA Update Accept: Use the same MS Radio Access Capabilities and DRX Parameters like the other messages The N(U) of most messages have not been fixed. Sponsored-by: On-Waves ehf
2014-08-24gbproxy: Handle old and new P-TMSI/TLLIJacob Erlbeck1-4/+53
Don't replace the current TLLI immediately, store it in an additional 'assigned_tlli' field and discard the old TLLI when both sides have used the new one (see GSM 04.08, 4.7.1.5). Add an Attach Complete message to test and check, whether the related field of the corresponding tlli_info struct are set as expected during the local TLLI validation cycle. Sponsored-by: On-Waves ehf
2014-08-24gbproxy: Parse Detach Request messagesJacob Erlbeck1-10/+18
GSM 24.008 also allows a P-TMSI field in Detach request messages. This patch adds gbprox_parse_gmm_detach_req() to parse Detach Request messages which sets the ptmsi field if the IE is present. In addition, when power_off is set to 1 (MO only), the invalidate_tlli field is set, since Detach Request message is expected in this case. The second detach test (see 'RA update') is modified to use power_off instead of relying on a Detach Accept from the network. To make this work, the PTMSI of the RA Update Accept is fixed to match the TLLI of the Detach Request. Sponsored-by: On-Waves ehf
2014-08-22gbproxy: Add gbprox_clear_patch_filter() (Coverity)Jacob Erlbeck1-0/+6
Add a separate function to clear the IMSI filter to be used instead of gbprox_set_patch_filter(cfg, NULL, ...). Albeit it fixes a Coverity issue (Unchecked return value), it is a false positive, since the return value is always 0 in these cases. Nevertheless it is more obvious what happens when an explicit clear function is called. Using NULL as filter argument of gbprox_set_patch_filter still clears the filter. Fixes: Coverity CID 1231255 Sponsored-by: On-Waves ehf
2014-08-13gbproxy: Fix warnings (signed/unsigned)Jacob Erlbeck1-6/+6
Adresses: gbproxy_test.c:1288:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] Sponsored-by: On-Waves ehf
2014-08-13gbproxy: Pass tlli_info aroundJacob Erlbeck1-4/+16
This patch modifies the code to pass a pointer to the tlli_info around once it has been acquired. To achieve this, gbprox_register_tlli() and gbprox_update_state() are modified to return it (if it has been found or created), and gbprox_patch_llc(), gbprox_patch_bssgp(), and gbprox_update_state_after() are modified to take it as parameter. Add a new function gbprox_touch_tlli() to update timestamp and list ordering for existing tlli_infos. The motivation behind this patch is to make the tlli_info available to the patching code and to avoid repeated searches for the same TLLI. Sponsored-by: On-Waves ehf
2014-08-13gbproxy/test: More TLLI expiry testingJacob Erlbeck1-5/+45
This patch adds a combined expiry test to remove one entry by list length and another by age. This patch also modifies the existing age based test to register both TLLI with a different timestamp and to remove only one of the TLLI entries by age based expiration. Sponsored-by: On-Waves ehf
2014-08-13gbproxy: Don't call time() in TLLI related functionsJacob Erlbeck1-46/+47
Currently time() is called at several places to control TLLI aging. Beside calling time() more often than necessary, the decision which timesource is to be used is coded into the TLLI handling, and testing complex aging scenarios is cumbersome. This patch passes the current time as a parameter instead. The call to time() is moved to gbprox_process_bssgp_message(). Sponsored-by: On-Waves ehf
2014-08-13gbproxy: Don't remove stale TLLI automaticallyJacob Erlbeck1-3/+8
This patches removes the call to gbprox_remove_stale_tllis() from gbprox_register_tlli(), so it must be called explicitly now. The call is now done from within gbprox_update_state_after(). In addition, the TLLI cache size counter is also kept in sync when gbprox_remove_stale_tllis is called manually. The call to gbproxy_peer_free() in gbproxy_peer_free() is moved behind the TLLI to allow for counter updates in gbprox_delete_tlli(). Sponsored-by: On-Waves ehf
2014-08-13gbproxy: Test and fix IMSI/TMSI matchingJacob Erlbeck1-0/+72
This adds a test for gbprox_set_patch_filter() and gbprox_check_imsi(). It also fixes the masking of the type field when IMSIs are checked by using GSM_MI_TYPE_MASK (0x07) instead of 0x0f. Sponsored-by: On-Waves ehf
2014-08-13gbproxy: Track TLLI even when the IMSI is not knownJacob Erlbeck1-4/+8
Currently only TLLIs for which it is known that they may be patched are put into the TLLI list. This patch changes this to add TLLIs even when the IMSI is not yet known. A enable_patching flag is added to the gbproxy_tlli_info structure to control patching. Note that this puts every active TLLI into the list where accesses are O(N) currently. Sponsored-by: On-Waves ehf
2014-08-13gbproxy: Parse additional IMSI/PTMSI/TLLI fieldsJacob Erlbeck1-0/+22
This adds parsing support for the following messages: - Attach Request: IMSI/PTMSI - Identity Response: IMSI/PTMSI - BSSGP: Optional TLLI IE - BSSGP/PAGING_PS: PTMSI A new new_ptmsi_enc field is added for newly assigned PTMSI in SGSN->BSS messages (instead of ptmsi_enc). The ptmsi_enc field is now used for informational PTMSI IE in messages. Sponsored-by: On-Waves ehf
2014-08-08gbproxy/test: Fix BSSGP RESET message sizeJacob Erlbeck1-1/+1
The given msg array size doesn't match the initializer's size. Sponsored-by: On-Waves ehf
2014-08-05gbproxy/test: Test TLLI expiryHolger Hans Peter Freyther1-32/+185
This adds a unit test for gbprox_register_tlli() and gbprox_remove_stale_tllis(). The dump_peers() function is extended by a cfg parameter to support a non-global gbproxy_config. Done with Jacob
2014-08-04gbproxy: Kill the global gbprox_global_patch_state structHolger Hans Peter Freyther1-1/+1
Move this patching state into the gbproxy_config as well. Done by Jacob
2014-08-04gbproxy: Remove global state from the gbproxyHolger Hans Peter Freyther1-5/+5
Global state prevents us from writing simple units tests for single routines. Go through the code and add pointers to the gbproxy configuration. Only the vty and the test code remain using the global gbproxy instance.
2014-08-04gprs: Add testcases for the APN string/octet conversion and fix itHolger Hans Peter Freyther1-1/+1
Create a testcase for the gprs_str_to_apn and gprs_apn_to_str routines. While writing the testcase we noticed it is possible to write more bytes than should have been allowed. This is fixed by checking that the max_len is at least 1 (needed to write the first length octet) and to do the size check before writing to the output. Modify the signature of gprs_str_to_apn to put the length/size next to the parameter that requires a size. Done with Jacob
2014-08-04gprs: Create a gprs_utils file and move to be shared code in thereHolger Hans Peter Freyther1-1/+2
We intend to move some of these routines to libosmocore but to avoid a feature symbol clash we are prefixing these routines with gprs_. Done with Jacob
2014-08-04gbproxy: Use gbproxy_ for all structuresHolger Hans Peter Freyther1-3/+3
The application is called gbproxy but the structures and functions were inconsistently named as either gbprox or gbproxy. Rename all structures to use gbproxy. Done with Jacob
2014-08-04gbproxy: The dump routines are only used by the test, move it thereHolger Hans Peter Freyther1-36/+129
Done with Jacob
2014-08-04gbproxy: Move the VTY code into the vty file and create public APIHolger Hans Peter Freyther1-0/+1
Create public accessors to the core of the peer to allow to simplify the test and separate concerns. Done with Jacob.
2014-07-22gprs: Add TLV parse functionsJacob Erlbeck1-0/+236
This adds a set of function that parse a single tlv, lv, tv, or v encoded information element. They are complementary to the *_put functions defined in libosmocore's tlv.h file. The functions update the data and data_len fields unless they are a 'match' function and the tag field doesn't match. Sponsored-by: On-Waves ehf
2014-07-22gprs/test: Rearrange for PTMSI parsingJacob Erlbeck1-7/+33
Add TLLI cache output to gbprox_dump_peers() to include this info into the test output. Separate RA Update Req message handling from Attach Request handling. Note: There is no test case for the P-TMSI Reallocation Command yet. Sponsored-by: On-Waves ehf
2014-07-22gprs: Track IMSI/TLLI to control APN patchingJacob Erlbeck1-1/+10
This patch adds IMSI/TLLI connection tracking and uses it to control APN patching based on the IMSI. TLLI entries can expire based on age and/or by limiting the TLLI list size. VTY config-gbproxy: no core-access-point-name disable APN patching core-access-point-name none remove APN if present core-access-point-name APN replace APN if present core-access-point-name none match-imsi RE remove if IMSI matches core-access-point-name APN match-imsi RE replace if IMSI matches tlli-list max-age SECONDS expire after SECONDS no tlli-list max-age don't expire by age tlli-list max-length N keep N entries only no tlli-list max-length don't limit list length RE is an extended regular expression, e.g. ^12345|^23456 Ticket: OW#1192 Sponsored-by: On-Waves ehf
2014-07-22gprs: Store gbproxy patching state per peerJacob Erlbeck1-2/+2
Currently, all patching state is stored globally in the gbproxy. Thus the feature cannot be used safely with a concentrating gbproxy (NAT). This patch moves the state and relevant counters to the gbprox_peer structure. It adds code to resolve the corresponding peer when packets are received by looking at BVCI, NSEI, and BSSGP IEs (BVCI, RAI/LAI/LAC) when the peer is not passed to the gbprox_patch_bssgp_message() function. Test cases are also added for the SGSN->BSS case including test cases with invalid identifiers. Note that this patch should make it possible to use RAI patching at a NAT gbproxy as long as the messages are not encrypted. Ticket: OW#1185 Sponsored-by: On-Waves ehf
2014-07-22gprs/test: Add Detach messages to testJacob Erlbeck1-0/+34
This patch adds a Detach Request (MO) / Detach Accept sequence to the test, followed by another (here invalid) Act PDP Context Req which should be APN patched. Sponsored-by: On-Waves ehf
2014-07-22gprs/test: Added GMM Info and fixed TLLIJacob Erlbeck1-2/+18
Add a DTAP GMM Information message with an IMSI in the BSSGP header to enable the association between IMSI and TLLI. The TLLI of the Routing Area Update messages is set to foreign. Sponsored-by: On-Waves ehf
2014-07-22gprs: Add APN patch support for LLC/GSM messagesJacob Erlbeck1-1/+4
Patch the APN in every 'Activate PDP Context Request' message to the value given by the 'core-access-point-name' command. If the command is given without an APN, the whole APN IE will be removed. If the command is being prefixed by a 'no', the APN IE remains unmodified. The patch mode 'llc-gsm' is added to selectively enable the patching of LLC session management messages. This is enabled implicitely by the patch mode 'llc'. Note that the patch mode should not be set to a value not enabling the patching of LLC GSM messages ('llc-gsm', 'llc', and 'default' are sufficient to patch 'Activate PDP Context Request' messages). Ticket: OW#1192 Sponsored-by: On-Waves ehf
2014-07-22gprs: Implement BSSGP MCC/MNC patchingJacob Erlbeck1-0/+2
This adds a feature to patch the BSSGP MNC/MCC fields of messages going to and coming from the SGSN. To enable this feature, the gbproxy's VTY commands 'core-mobile-country-code' and/or 'core-mobile-network-code' must be used. All packets to the SGSN are patched to match the configured values. Packets received from the SGSN are patched to the corresponding values as last seen from the BSS side. Note that this will probably not work with a gbproxy used for several BSS simultaneously. Note also, that MCC/MNC contained in a LLC IE will not be patched. Ticket: OW#1185 Sponsored-by: On-Waves ehf
2014-07-22gprs/test: Make test output more readableJacob Erlbeck1-13/+19
This patch makes a few changes to improve readability: - change the sendto() hexdump to start with NS instead of BSSGP - use more specific message descriptions instead of 'UNITDATA' - add a title line per test Sponsored-by: On-Waves ehf
2014-07-07gprs/test: Increase stderr log levelJacob Erlbeck1-4/+20
Enable the generation of more log messages. Sponsored-by: On-Waves ehf
2014-07-07gbproxy_test: Provide enough disabled categories to please valgrindHolger Hans Peter Freyther1-1/+6
An empty log_info is not enough. We need to make sure that at least DLGLOBAL is present. Instead of doing that make sure that we have enough entries. ==26163== Conditional jump or move depends on uninitialised value(s) ==26163== at 0x403B289: osmo_vlogp (logging.c:290) ==26163== by 0x403B3DA: logp2 (logging.c:339) ==26163== by 0x804D027: gbprox_relay2bvci (gb_proxy.c:347) ==26163== by 0x804D3CF: gbprox_rx_sig_from_sgsn (gb_proxy.c:589) ==26163== by 0x804DBFC: gbprox_rcvmsg (gb_proxy.c:685) ==26163== by 0x4052CB0: gprs_ns_process_msg (gprs_ns.c:669) ==26163== by 0x4052F70: gprs_ns_rcvmsg (gprs_ns.c:1053) ==26163== by 0x804BB49: gprs_process_message (gbproxy_test.c:488) ==26163== by 0x804BC4C: send_ns_unitdata (gbproxy_test.c:210) ==26163== by 0x804BDE8: send_bssgp_reset_ack (gbproxy_test.c:243) ==26163== by 0x804B54F: main (gbproxy_test.c:863) ==26163==
2014-07-07gbproxy_test: Reset the gbproxy before we reset GPRS NSHolger Hans Peter Freyther1-3/+3
The peers are (talloc) children of the GPRS NS. This means the peers (and the rate counters) are currently being deleted twice. ==23446== Invalid write of size 4 ==23446== at 0x403C243: rate_ctr_group_alloc (linuxlist.h:66) ==23446== by 0x4050974: gprs_nsvc_create (gprs_ns.c:209) ==23446== by 0x405320D: gprs_ns_instantiate (gprs_ns.c:1330) ==23446== by 0x804ABEB: main (gbproxy_test.c:666) ==23446== Address 0x4300694 is 52 bytes inside a block of size 784 free'd ==23446== at 0x4029DA8: free (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so) ==23446== by 0x4041B9D: _talloc_free (talloc.c:609) ==23446== by 0x4043292: talloc_free (talloc.c:578) ==23446== by 0x40532D3: gprs_ns_destroy (gprs_ns.c:1363) ==23446== by 0x804ABD7: main (gbproxy_test.c:660)
2014-07-07gbproxy_test: Simplify the test setup by sharing codeHolger Hans Peter Freyther1-30/+24
2014-07-07gprs/test: Add additional gbproxy testsJacob Erlbeck1-1/+192
This adds a test case with several messages to test BSSGP patching. New messages: - BSSGP/DTAP Attach Request - BSSGP/DTAP Attach Accept - BSSGP/DTAP Routing Area Update Request - BSSGP/DTAP Routing Area Update Accept - BSSGP/DTAP Activate PDP Context Request - BSSGP SUSPEND - BSSGP SUSPEND ACK Sponsored-by: On-Waves ehf
2014-07-07gprs/test: Add connect_sgsn() functionJacob Erlbeck1-10/+11
This function abstracts identical code sequences that are used at multiple places. Sponsored-by: On-Waves ehf
2014-07-07gprs/test: Remove verbose parameter of gbprox_dump_* functionsJacob Erlbeck1-26/+26
This parameter is not used (the methods are always called with an argument of 1 in the third position). Thus the parameter is removed completely. Sponsored-by: On-Waves ehf
2014-06-04gprs/test: Use valid MCC/MNC for BVC RESETJacob Erlbeck1-2/+2
The code currently uses an encoded sequence of (hex) 10 20 30 40 50 60 as RAI, for which no bijective mapping to the set of representations MCC-MNC-LAC-RAC exists. This patch changes the hard-coded RAI to 11 22 33 40 50 60 which maps to 112-332-16464-96 (and vice-versa). Sponsored-by: On-Waves ehf
2013-10-24gbproxy: Add test for NSEI and NSVCI changesJacob Erlbeck1-2/+151
This checks the behavior of the gbproxy when the BSS peer changes the NSEI and the NSVCI. It also tests BVC_RESET and other UNITDATA messages after these changes between BSS and SGSN and vice versa (via the gbproxy). Ticket: OW#874 Sponsored-by: On-Waves ehf
2013-10-19gbproxy: Test invalid BVCI from SGSNJacob Erlbeck1-0/+8
This adds a test with a UNITDATA SGSN message that is addressed to an invalid (unknown) BVCI. The test shows, that the message is echoed to the SGSN. Sponsored-by: On-Waves ehf
2013-10-19gbproxy: Add global and per peer countersJacob Erlbeck1-12/+12
This adds counters that are incremented when errors are detected. It also modifies the VTY command 'show gbproxy' so that 'show gbproxy stats' shows the counters. Sponsored-by: On-Waves ehf
2013-10-19gbproxy: Extended test program to simulate SGSN, tooJacob Erlbeck1-11/+157
This adds a simulation of the SGSN side of the Gbproxy. The VC is set up correctly and several combinations of BSSGP messages are sent. Sponsored-by: On-Waves ehf