aboutsummaryrefslogtreecommitdiffstats
path: root/openbsc/src/gprs/gb_proxy_tlli.c
AgeCommit message (Collapse)AuthorFilesLines
2014-12-02gbproxy: Reset TLLIs when the link_info is found by IMSI/P-TMSIJacob Erlbeck1-7/+23
Currently when the MS does a re-attach without doing a proper detach first, the gbproxy uses the old local TLLI if patching and the keep mode are enabled. This leads to a failing attachment procedure when TLLI patching is also enabled. This patch changes gbproxy_update_link_state_ul to reset all TLLIs within the link_info if the message contains an unknown TLLI and an MI. This is generally the case with Attach Request messages. The gbproxy_get_link_info_ul gets an additional tlli_is_valid output parameter that is set, when a TLLI was present and found. This flag is then used instead of checking tlli.current == 0 to set TLLI/P-TMSI e.g. Attach Requests when a link_info was already present for the P-TMSI/IMSI used in such a request. Ticket: OW#1324 Sponsored-by: On-Waves ehf
2014-10-27gbproxy: Patch BSSGP P-TMSI in PAGING PS messagesJacob Erlbeck1-3/+25
Currently the P-TMSI IE in PAGING_PS is not patched. This commit adds code to patch BSSGP P-TMSI IE in gbproxy_patch_bssgp independently from the P-TMSI patching at the LLC layer. It also extends gbproxy_update_link_state_dl to use the IMSI to find the link_info if the TLLI is not present in the message. Note that the spec (GSM 08.18, 7.2) requires to use of the P-TMSI instead of the IMSI to select the MS if that IE is available. Nevertheless as long as the IMSI is always present in downlink BSSGP messages and as long as the optional P-TMSI refers to the same MS (which is the case currently), this is not an issue. Sponsored-by: On-Waves ehf
2014-10-27gbproxy: Fix P-TMSI generation for repeated Attach Accept messagesJacob Erlbeck1-2/+7
Currently, when P-TMSI patching is enabled, a new BSS P-TMSI is generated for each Attach Accept. So two duplicated, subsequent Attach Accept messages will be mapped to different BSS side P-TMSI. Because the last one will replace former ones in the link_info struct, the MS will fail to access the SGSN if it uses the former P-TMSI to derive the new TLLI. This patch checks the SGSN P-TMSI already assigned to the link_info and only generates a new BSS P-TMSI on mismatch (or if the BSS P-TMSI hasn't been set yet). Ticket: OW#1322 Sponsored-by: On-Waves ehf
2014-10-09gbproxy: Use pointer to PTMSI value instead of MIJacob Erlbeck1-28/+5
Currently, ptmsi_enc and new_ptmsi_enc point to the beginning of the mobile identity. Since all P-TMSI in 04.08 (MM) are encoded this way (1 byte header + 4 byte P-TMSI value). This is different to the P-TMSI encoding in 08.18 (BSSGP), where the P-TMSI is encoded into 4 byte without MI header. This patch changes the code to use pointers to the P-TMSI value, which is encoded in the same way in both specifications. Sponsored-by: On-Waves ehf
2014-10-09gbproxy: Replace ';;' by ';'Jacob Erlbeck1-3/+3
This patch removes some superfluous ';' from the code. Sponsored-by: On-Waves ehf
2014-10-09gbproxy: Refactor IMSI matchingJacob Erlbeck1-8/+20
The current implementation makes it difficult to add further match expressions. This patch adds a new struct gbproxy_match that contains the fields needed for each match expression. The matches (config) and the results (link_info) are stored in arrays. All related functions are updated to use them. The old fields in the config structure are removed. Sponsored-by: On-Waves ehf
2014-10-09gbproxy: Refactor local message generationJacob Erlbeck1-0/+2
This patch adds und uses the function gbproxy_gsm48_to_peer() which takes a GSM 04.08 message, encapsulates it in BSSGP and LLC, and sends it to the BSS peer. This function increments vu_gen_tx_bss which is now used instead of imsi_acq_retries to set the N(U) of the outgoing message. Since imsi_acq_retries isn't currently incremented before a Detach Accept is generated, this patch also fixes the N(U) of such messages. Sponsored-by: On-Waves ehf
2014-10-09gbproxy: Reset IMSI acquisition within gbproxy_unregister_link_infoJacob Erlbeck1-0/+2
Currently then link_info is not cleaned up completely, when gbproxy_unregister_link_info is called. This patch adds a function gbproxy_reset_link that must be defined externally. This is done in gb_proxy.c, where it resets the IMSI acquisition. Sponsored-by: On-Waves ehf
2014-10-09gbproxy: Only search by valid identifiersJacob Erlbeck1-0/+12
Don't return a link_info if TLLI is 0 resp. P-TMSI is 0xffff. These values are used for uninitialised or cleared fields and can possibly match several entries. Sponsored-by: On-Waves ehf
2014-10-09gbproxy: Rename the field 'enabled_tllis' to 'logical_links'Jacob Erlbeck1-23/+23
This field in struct gbproxy_patch_state has involved and holds a list of all tracked logical links now. Thus the name is modified accordingly. Sponsored-by: On-Waves ehf
2014-10-09gbproxy: Use the term 'link' instead of 'tlli'Jacob Erlbeck1-199/+199
Currently in many places where 'tlli' (Temporary Logical Link Identifier) within identifiers is used, the logical link itself is meant instead. For instance, the tlli_info contain information about an LLC logical link including up to four individual TLLI. To avoid confusion between these concepts, this patch replaces all 'tlli_info' by 'link_info' and a few 'tlli' by 'link'. Sponsored-by: On-Waves ehf
2014-10-09gbproxy: Rename functions related to tlli_infoJacob Erlbeck1-34/+35
This patch replaces 'tlli' by 'tlli_info' within the following function identifiers: - gbproxy_delete_tlli - gbproxy_delete_tllis - gbproxy_remove_stale_tllis - gbproxy_touch_tlli - gbproxy_unregister_tlli - gbproxy_remove_matching_tllis - gbproxy_find_tlli -> gbproxy_tlli_info_by_tlli - gbproxy_find_tlli_by_* -> gbproxy_tlli_info_by_* These functions refer to the whole logical link info rather than to a certain TLLI. So they are renamed to be named consistently with gbproxy_attach_tlli_info and others. Sponsored-by: On-Waves ehf
2014-10-09gbproxy: Rename identifiers related to IMSI matchingJacob Erlbeck1-6/+6
This patch renames gbproxy_check_tlli() to gbproxy_imsi_matches() and struct tlli_info's enable_patching to imsi_matches. It's meant to be more obvious and consistent this way. Sponsored-by: On-Waves ehf
2014-09-19gbproxy: Separate SGSN numeric namespacesJacob Erlbeck1-4/+23
Currently the SGSN side message's TLLI are searched without checking the originating SGSN. This leads to collisions if both SGSN use the same P-TMSI for different MS. With this patch, the SGSN NSEI is stored within the tlli_info and is used in comparisons to separate the namespaces. Note that this type of collision cannot happen with BSS numbers, since the tlli_info are already separated and stored per (BSS) peer. Sponsored-by: On-Waves ehf
2014-09-19gbproxy: Check other tlli_infos for matching TLLI/P-TMSIJacob Erlbeck1-0/+38
Currently it is possible to create serveral entries referring to the same P-TMSI/TLLI by using P-TMSI assigment via Attach Accept or RA Update Accept messages. This can lead to the use of the wrong tlli_info. This patch adds gbproxy_remove_matching_tllis() that removes all conflicting entries. This function is called after the P-TMSIs and the resulting TLLIs has been set up. Sponsored-by: On-Waves ehf
2014-09-19gbproxy: Avoid multiple tlli_info entries with the same IMSIJacob Erlbeck1-22/+37
Currently it is possible to create several tlli_info entries with the same IMSI. This patch disables this by adding a check before the imsi field is updated. Sponsored-by: On-Waves ehf
2014-09-19gbproxy: Keep tlli_info after detachJacob Erlbeck1-14/+70
Currently a tlli_info entry is deleted when the TLLI gets invalidated by a Detach message. This patch introduces the possibility to keep tlli_info entries in the list. Those entries then have cleared TLLI fields, are marked as de-registered, and can only be retrieved by a message containing an IMSI or a P-TMSI. The following VTY configuration commands are added to the gbproxy node: - tlli-list keep-mode never : Don't keep the entries (default) - tlli-list keep-mode re-attach : Only keep them, when a Detach message with re-attach required has been received - tlli-list keep-mode identified : Only keep entries which are associated with an IMSI - tlli-list keep-mode always : Keep all entries Note that at least one of max-length or max-age should be set when this feature is used to limit the number of entries. Sponsored-by: On-Waves ehf
2014-09-18gbproxy: Remove gbproxy_register_tlliJacob Erlbeck1-63/+20
This function is a remainder of the initial implemenation that was not meant for TLLI patching and can be used for the BSS side only. The SGSN side is already using a composition of more flexible single purpose functions. This patch changes the implementation to use a similar approach. The function is moved to gbproxy_test.c and renamed to register_tlli to keep the tests intact. Sponsored-by: On-Waves ehf
2014-09-18gbproxy: Replace 'mi_data' by 'imsi'Jacob Erlbeck1-14/+14
Since at all places where mi_data/mi_data_len is used it will always contain an IMSI. Thus the names of the identifiers have been updated accordingly for clarity. Sponsored-by: On-Waves ehf
2014-09-09gbproxy: Reset IMSI acquisition and free stored messages in tlli_infoJacob Erlbeck1-0/+12
Currently the stored messages are only removed, when IMSI acquisition has succeeded. In addition, receiving two ATTACH_REQ messages in sequence (e.g. due to loss of a Identity Req/Resp message) will not restart the IMSI acquisition procedure. This patch adds gbproxy_tlli_info_discard_messages() to clean up the message list and calls it from gbproxy_delete_tlli() fixing a potential memory leak. It is also called when an Attach Request message has been received. In that case the imsi_acq_pending flag is cleared, too. This would (re-)trigger the IMSI acquisition procedure at each of these messages. If an Ident Response has been lost, resending the Ident Request with the same N(U) will not work. Therefore the N(U) gets incremented on each Ident Request generated by the gbproxy. The first N(U) used is 256 which shouldn't collide with the V(UT) used by the SGSN given that P-TMSI patching is enabled (since a new random TLLI is used initially on every new (no tlli_info) connection and V(U) starts with zero then). Ticket: OW#1261 Sponsored-by: On-Waves ehf
2014-09-09gbproxy: Fix P-TMSI reassignmentJacob Erlbeck1-14/+25
Currently, a new P-TMSI within an Attach Accept or within an RA Update Request is applied to the TLLI mapping (gbproxy_reassign_tlli) _before_ patching is done. This can lead to inconsistent behaviour when the TLLI validation has not been completed, which is the case when subsequent RA UDP REQ are received. The new TLLI must not be applied to the message itself yet, it should only be considered for following messages. This patch moves the TLLI reassignment to gbproxy_update_tlli_state_after() to fix that. It also separates the implementation of the feature that a new tlli_info can be created when such a message is received from the SGSN. This makes sense, when P-TMSI patching is not active and the tlli_info entry has expired. Sponsored-by: On-Waves ehf
2014-09-09gbproxy: Change creation of tlli_info for SGSN originated messagesJacob Erlbeck1-30/+51
Currently tlli_info are created for SGSN originated messages when the SGSN TLLI cannot be found and P-TMSI patching is active. This doesn't make much sense, since the BSS side TLLI is not known in this case. Given that the SGSN is working properly, that can only happen if either the tlli_info has expired or the gbproxy has been restarted. This patch disables the creation of a tlli_info in this case. Note that these messages are passed unmodified to the MS so far. Sponsored-by: On-Waves ehf
2014-09-08gbproxy: Check tlli_info when patching, fix APN patchingJacob Erlbeck1-8/+2
Currently the numeric TLLI or tlli_info's enable_patching flag is used to decide, whether a APN shall be patched or the secondary SGSN shall be used. Using the numeric TLLI imposes a problem, when TLLI/P-TMSI patching is used, since gbproxy_check_tlli uses the BSS side TLLI namespace when trying to get the tlli_info. This patch modifies the gbproxy_check_tlli() function to accept a tlli_info pointer instead of a numeric TLLI. The tlli_info is already available when the function is called. Since this a similar approach has been used by accessing the enable_patching flag directly, this commit unifies checking by always using this function instead of the flag outside of gb_proxy_tlli.c. This fixes the APN patching that doesn't work currently when P-TMSI patching is enabled. Sponsored-by: On-Waves ehf
2014-09-02gbproxy: Implement IMSI acquisitionJacob Erlbeck1-0/+2
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-08-29gbproxy: Fix issues found by CoverityJacob Erlbeck1-1/+1
gbproxy_patch_bssgp: Move a check for tlli_info in front of the first conditional that depends on it, and return immediately if it is NULL. gbproxy_register_tlli: Initialize tlli_already_known to 0. Fixes: Coverity CID 1232691 Fixes: Coverity CID 1232692 Sponsored-by: On-Waves ehf
2014-08-24move GSM_RESERVED_TMSI to libosmocoreHarald Welte1-1/+2
The gb_proxy shouldn't start to open the box of pandora by including the gsm_data_shared.h file, particularly not without defining the BSC role. In any case, as the reserved TMSI is something that's part of the GSM specs, and not specific to the OpenBSC implementation, it should be part of libosmocore.
2014-08-24gbproxy: Refactor gb_proxy.c into several filesJacob Erlbeck1-0/+544
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