Commit Graph

806 Commits

Author SHA1 Message Date
Jacob Erlbeck 207f4a5deb sgsn: Add VTY commands to manage subscriber cache
This adds the following commands to the ENABLE node:
  - show subscriber cache
  - update-subscriber imsi IMSI insert authorized (0|1)
  - update-subscriber imsi IMSI cancel
  - update-subscriber imsi IMSI commit

These commands are mainly testing tools and maintenance helpers. The
update commands work asynchronously and can be used to complete a
pending update request or to terminate an existing connection. The
'insert' command just update the subscriber records but does not
notify the GMM layer. Invoke the 'commit' command to continue with
pending procedures.

Note that the subscriber cache is not stored persistently and will
always be empty after an SGSN restart.

Sponsored-by: On-Waves ehf
2014-12-09 10:00:41 +01:00
Jacob Erlbeck 98647ca0ef sgsn: Add gsm0408_gprs_access_cancelled
This function is called to delete an established MM context
silently without invoking a detach procedure.

It is called when a subscriber is cancelled by the HLR. This
generally happens, when an MS has moved to another routing area and
has to use another SGSN.

Sponsored-by: On-Waves ehf
2014-12-09 09:48:25 +01:00
Jacob Erlbeck be2c8d9358 sgsn: Integrate subscriber handling into the SGSN
This commit adds a new authorization policy 'remote' and uses
the subscriber cache for authorization when this policy is being used.

Note that there is no remote backend implemented yet. After the
IMSI/IMEI have been acquired, a request would be sent to the remote
peer. The attach/auth-ciph procedure continues when authorization
info has been received from the peer. This means, that
gprs_subscr_update() must be called then to tell the GMM layer
that it can proceed. A later commit will add VTY commands to do this
manually.

Sponsored-by: On-Waves ehf
2014-12-09 09:27:20 +01:00
Jacob Erlbeck 33b6dadc88 sgsn: Add gprs_subscriber.c
This patch adds GPRS specific functions for gsm_subscriber objects
(allocation, retrieval, deletion) and subscriber data
requests/updates. The sgsn_update_subscriber_data callback is used to
notify the sgsn about updates and is extended by a parameter that
passes a reference to a gsm_subscriber.

Sponsored-by: On-Waves ehf
2014-12-09 09:23:11 +01:00
Jacob Erlbeck 8ff3fb04f2 sgsn: Do authentication based on SRES values
Currently the SRES value in the Auth & Ciph Response is ignored.

This patch checks the SRES value in response against the value stored
in mm->auth_triplet.sres. If they don't match, an Auth & Ciph Reject
message is sent to the MS. If they match, the mm->is_authenticated
flag is set.

Note that the procedure will not be started yet.

Sponsored-by: On-Waves ehf
2014-12-08 10:51:38 +01:00
Jacob Erlbeck bd0cf1190a sgsn: Change Auth&Ciph timer handling
Currently mmctx_timer_start is called from within
gsm48_tx_gmm_auth_ciph_req which differs from the way e.g. the
identification procedure is implemented. It also makes it more
difficult to restart the procedure after timeout, which is not
implemented yet. In addition, the timer is not properly stopped when
an AUTH & CIPH response is received.

This patch removes this timer start from gsm48_tx_gmm_auth_ciph_req,
adds the retransmission of Auth & Ciph requests to the timer callback
function, and properly stops the timer in
gsm48_rx_gmm_auth_ciph_resp.

Sponsored-by: On-Waves ehf
2014-12-08 10:50:52 +01:00
Jacob Erlbeck 65d8273bf3 sgsn: Fix and enable auth/ciph message generation
Currently gsm48_tx_gmm_auth_ciph_req/_rej are commented out. In
addition, gsm48_tx_gmm_auth_ciph_req uses a wrong encoding (two byte TV instead of two nibbles TV) of the CKSN information element.

This patch fixes the encoding of the CKSN IE and enables the
functions mentioned above.

Sponsored-by: On-Waves ehf
2014-12-08 10:49:17 +01:00
Jacob Erlbeck 59ac49dc1f gbproxy: Reset TLLIs when the link_info is found by IMSI/P-TMSI
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-12-02 09:00:09 +01:00
Jacob Erlbeck a0b6efb368 sgsn: Remove explicit sgsn_instance parameters
Currently the function in sgsn_auth.c either have an sgsn_config or
an sgsn_instance parameter. Since then global sgsn variable is
already being used in that file and since other parts of the SGSN
related code also rely on a global sgsn singleton, these parameters
pretend to provide a flexibility that is not really supported.

Therefore this patch removes these parameters except for the ACL
related functions, which do not call code that uses the sgsn
variable.

Sponsored-by: On-Waves ehf
2014-11-14 10:26:06 +01:00
Jacob Erlbeck f951a01bb2 sgsn: Refactor sgsn_auth to separate request and authorization
Currently the authorization is done in sgsn_auth_request for ACL
based authorization. This doesn't match the way remote authorization
would work, so that there is a second call to sgsn_auth_state already
present in sgsn_auth_update.

This patch removes the autorization check completely from
sgsn_auth_request which in turn calls sgsn_auth_update directly now.

Sponsored-by: On-Waves ehf
2014-11-14 10:23:54 +01:00
Jacob Erlbeck f6e7d99d54 sgsn: Don't assign a new P-TMSI if one is pending
Currently every time an RA Update Req or an Attach Req is processed, a
new P-TMSI is allocated. When an MS issues another of these messages
before it has completed the first procedure, old_ptmsi is replaced by
ptmsi (and thus lost) and ptmsi is replaced by the newly allocated
P-TMSI. This can confuse the gbproxy, which can loose track of the
logical link then. At least a Blackberry emits a double set of RA Upd
Req messages from time to time which may be just 20ms apart.

This patch adds a check whether mm->ptmsi or mm->old_ptmsi are set.
If both are set, the P-TMSI is not re-allocated. This is only the
case, when the Complete message has not been received yet, since that
message will reset old_ptmsi.

Sponsored-by: On-Waves ehf
2014-11-14 10:19:29 +01:00
Jacob Erlbeck c4f9bf3142 sgsn: Don't send XID reset after Detach Accept
Currently when a Detach Accept is received for an unknown TLLI (which
is in general the case afer the SGSN has requested the detachment),
an XID reset is sent to the BSS, causing a BSSGP Status message. This
happens in gsm0408_rcv_gmm.

This patch moves the corresponding call to gprs_llgmm_reset downwards
so that it is not being called in that case.

Addresses:
SGSN->BSS TLLI: 0xd75b91d9 SAPI: LLGMM, UI (DTAP) (GMM) Detach Request
BSS->SGSN TLLI: 0xd75b91d9 SAPI: LLGMM, UI (DTAP) (GMM) Detach Accept
SGSN->BSS TLLI: 0xd75b91d9 SAPI: LLGMM, U, XID (Reset, IOV-UI)
BSS->SGSN TLLI: ---        BSSGP STATUS (Unknown MS)

Sponsored-by: On-Waves ehf
2014-11-14 10:12:32 +01:00
Jacob Erlbeck 80d07e30c7 sgsn: Cleanup after RA Update Reject / Attach Reject
Currently, the LLME is not cleaned up after sending an RA Update
Reject. This happens after entering a routing area from outside,
since in that case the SGSN sends an RA Update Reject (implicitly
detached) which causes the MS to restart the attach procedure.
The LLME is also not updated if an Attach Request with message errors
(encoding, invalid MI type) is received or if an MM context cannot be
allocated.

This patch changes gsm48_rx_gmm_ra_upd_req and gsm48_rx_gmm_att_req
to unassign the LLME or free the MM context (if available) after a
Reject message has been sent.

Ticket: OW#1324
Sponsored-by: On-Waves ehf
2014-11-14 10:07:42 +01:00
Jacob Erlbeck 106f547733 sgsn: Add 'acl-only' authentication policy
Currently the VTY 'auth-policy' command results in setting or clearing
the acl_enabled flag. This also enables the matching of the MCC/MNC
prefix of the IMSI.

This patch adds an additional policy 'acl-only' which disables the
MCC/MNC matching and relies on the ACL only.

Sponsored-by: On-Waves ehf
2014-11-14 10:07:28 +01:00
Jacob Erlbeck 423f8bfa02 sgsn: Make authorization asynchronous
Currently the authorization of an IMSI is done by checking ACLs
synchronously which is not feasible when the subscriber data has to
be retrieved from an external source.

This patch changes this by using a callback when the information is
available. This is also done when only ACL are checked, in this case
the callback is invoked from within sgsn_auth_request(). The callback
function sgsn_update_subscriber_data calls sgsn_auth_update which
in turn calls either gsm0408_gprs_access_granted or
gsm0408_gprs_access_denied. gsm48_gmm_authorize is extended by a call
to sgsn_auth_request when IMSI and IMEI are available but the
auth_state is unknown.

The change has been successfully tested with single phones (E71 and
IPhone 5c).

Sponsored-by: On-Waves ehf
2014-11-14 09:58:28 +01:00
Jacob Erlbeck 0c06f98ced sgsn: Move IMSI authorization to gsm48_gmm_authorize
Currently the IMSI is only checked immediately when an Attach Request
is received that contains an IMSI IE. If it contains a P-TMSI
instead, access is always granted.

This commit moves the IMSI check to gsm48_gmm_authorize where it is
applied when IMSI and IMEI have been acquired. This fixes the
authorization when the Attach Accept doesn't contain an IMSI.

Sponsored-by: On-Waves ehf
2014-11-14 09:27:23 +01:00
Jacob Erlbeck b1c074f62c sgsn: Fix LLME leak when forcing a reattach
Currently when forceing a reattach by sending a Detach
Request (reattach), the SGSN waits for the Detach Accept until it
frees the MM context (if present) and the LLME. If that message gets
lost or isn't sent by the MS, the LLME is never freed if it isn't
bound to an MM context.

This patch adds code to free the MM context/LLME when forcing a
reattachment.

Sponsored-by: On-Waves ehf
2014-11-14 09:26:27 +01:00
Jacob Erlbeck abdf02b9b9 sgsn: Split gsm0408_gprs_force_reattach into 2 functions
This patch replaces gsm0408_gprs_force_reattach(msg, mmctx) by two
functions
  - gsm0408_gprs_force_reattach(mmctx)
  - gsm0408_gprs_force_reattach_oldmsg(msg)

The old function basically consists of the code of the two new
functions, where the code path selected depends on mmctx == NULL,
which is harder to maintain, less obvious to use, and not consistent
with many other SGSN functions.

Sponsored-by: On-Waves ehf
2014-11-14 09:23:38 +01:00
Jacob Erlbeck a790456f1b sgsn: Call mm_ctx_cleanup_free to deregister MM context
Currently the MM context isn't always removed when it is
de-registered (mmctx_timer_cb), mm_state is set to GMM_DEREGISTERED
instead. This can lead to left-over MM contexts which are only
cleaned up if the MS reattaches.

This patch replaces all of these assignments by a call to
mm_ctx_cleanup_free.

Ticket: OW#1324
Sponsored-by: On-Waves ehf
2014-11-14 09:16:58 +01:00
Jacob Erlbeck 0074a77424 sgsn: Cleanup GMM state transitions
Currently the GMM state is set to GMM-REGISTERED when an Attach
Accept or a RA Update Accept message is sent, even if a new P-TMSI is
included. In this case 04.08 requires (see 4.7.3.1.3 and 4.7.5.1.3),
that the state is set to GMM-COMMON-PROCEDURE-INITIATED when the
Accept is sent. When the Complete is received, the SGSN shall set
the state to GMM-REGISTERED.

This patch modifies the state updates accordingly.

Sponsored-by: On-Waves ehf
2014-11-14 09:12:10 +01:00
Jacob Erlbeck 93eae8ec78 sgsn: Reorganize and fix gsm48_gmm_authorize
Currently the order of the 'if' clauses in gsm48_gmm_authorize
doesn't match the order in which the conditional parts are entered.
This makes it difficult to maintain. In addition the t3350_mode is
not stored in every path, so that this information is lost when the
identification procedure is started. Since the default value
coincidentally is GMM_T3350_MODE_ATT, this doesn't hurt for Attach
Requests which are the only messages that initially trigger the
authentication yet.

This patch changes the order of the 'if' clause to match the
processing order, it removes the t3350_mode parameter entirely and
introduces a mm->pending_req field. The latter must be set when the
request that causes the authorization before calling
gsm48_gmm_authorize. The gprs_t3350_mode enum is extended by
GMM_T3350_MODE_NONE (value 0, which is the default) to make it
possible to detect related initialisation errors or race conditions.

Sponsored-by: On-Waves ehf
2014-11-14 08:57:50 +01:00
Jacob Erlbeck 4110868029 gbproxy: Honour the BSS TLLI type when creating an SGSN TLLI
Currently gbproxy_make_sgsn_tlli always returns a foreign TLLI when
it uses the (SGSN) P-TMSI to generate one.

This patch changes the implementation to return a SGSN TLLI of the
same type like the BSS TLLI in that case.

Sponsored-by: On-Waves ehf
2014-11-11 22:44:32 +01:00
Jacob Erlbeck de74e721b2 gbproxy: Fixed VTY doc for delete-gbproxy-link
The command definition delete_gb_link_by_id_cmd lacks a description
for the sgsn-nsei token.

This patch adds the missing description.

Addresses:
Verifying src/gprs/osmo-gbproxy -c doc/examples/osmo-gbproxy/osmo-gbproxy.cfg, test verify_doc
Documentation error (missing docs):
<command id='delete-gbproxy-link &lt;0-65534&gt; (tlli|imsi|sgsn-nsei) IDENT'>
        <param name='IDENT' doc='(null)' />

Sponsored-by: On-Waves ehf
2014-11-05 00:24:13 +01:00
Jacob Erlbeck 14ae582064 sgsn: Unassign the LLME after GMM Status without mmctx
Currently the LLME is not deleted when a GMM Status message is
received for which a mmctx cannot be found. This can fill the LLME
list with unneeded entries.

This patch adds code to unassign the LLME in that case.

Ticket: OW#1324
Sponsored-by: On-Waves ehf
2014-11-05 00:24:02 +01:00
Jacob Erlbeck 7067142100 sgsn: Remove unused static functions from gprs_gmm.c
The following functions are not being used:
 - gsm48_tx_gmm_status_oldmsg
 - gsm48_tx_sm_status_oldmsg

This patch removes the function definitions.

Sponsored-by: On-Waves ehf
2014-11-05 00:23:44 +01:00
Jacob Erlbeck 5a38f6470e sgsn: Handle Detach Requests even when there is no mmctx
Currently, when a Detach Request is received with an unknown TLLI,
it is answered by another Detach Request (!), even when a power_off
Type is used.

This patch uses gsm48_rx_gmm_det_req to handle the message instead.
So this function is changed to cope with a NULL mmctx. In that case
it doesn't unassign the llme, so this must be done manually
afterwards.

Sponsored-by: On-Waves ehf
2014-10-27 15:34:14 +01:00
Jacob Erlbeck b9ab0d4f39 sgsn: Only send Detach Accept (MO) if power_off isn't set
Currently, every time the SGSN received a Detach Request from the MS
via an established logical link, it is answered by a Detach Accept.
This violates the specification (GSM 04.08, 4.7.4.1.2 and .3), which
states, that it should only be sent, if "the detach type IE value
indicates that the detach request has not been sent due to switching
off".

This patch adds a conditional to limit the sending of Detach Accept
accordingly.

Sponsored-by: On-Waves ehf
2014-10-27 15:21:31 +01:00
Jacob Erlbeck 3b5d407203 sgsn: Moved IMSI ACL management to sgsn_auth.c
Currently the ACL code is located in sgsn_vty.c.

This commit moves this to a new file sgsn_auth.c as a first step to
make authorization more flexible in order to implement remote
acquisition on subsciber data.

Sponsored-by: On-Waves ehf
2014-10-27 13:06:55 +01:00
Jacob Erlbeck fb26c60a2f sgsn: Avoid duplicated Attach Accept messages
Currently each received Ident Resp triggers an Attach Accept/Reject
if IMSI and IMEI are known. This has led to duplicated Attach Accept
messages when used with the gbproxy (IMSI acquisition active) and
with certain mobile equipment (iOS).

This patch modifies gsm48_rx_gmm_id_resp to discard Ident Resp messages
if all required information (IMEI and IMSI) has been gathered.

Ticket: OW#1322
Sponsored-by: On-Waves ehf
2014-10-27 13:06:55 +01:00
Jacob Erlbeck c37ef6cd0e gbproxy: Patch BSSGP P-TMSI in PAGING PS messages
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-27 11:59:28 +01:00
Jacob Erlbeck 91e9f555b6 gbproxy: Fix P-TMSI generation for repeated Attach Accept messages
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-27 11:17:11 +01:00
Jacob Erlbeck 78ecaf0561 sgsn: Send detach(re-attach) instead of gmm status if TLLI unknown
The osmo-sgsn sends Status messages (or nothing in case of non
GMM/GSM) when the TLLI is unknown. This prevents the MS from
reconnecting.

This patch adds the initiation of an MT detach procedure to force a
re-attach to set up a valid LLE context if an LLE or an MM context
cannot be found. Since this can also be triggered by non-GMM SAPI
messages, a GPRS application callback sgsn_force_reattach_oldmsg is
added which in turn calls the GMM layer to generate the GSM 04.08
specific messages.

Note that the MS can be left in REGISTERED state after initially
wanting to detach itself, since it will receive a Detach Req
(re-attach) when sending a DEACT PDP CTX REQ after the SGSN or
gbproxy (P-TMSI patching enabled) has been restarted. This same
behaviour has been observed with another SGSN.

Sponsored-by: On-Waves ehf
2014-10-27 10:50:36 +01:00
Jacob Erlbeck 99985b5ea8 sgsn: Delete PDP contexts properly
Currently the PDP contexts are hard freed (via sgsn_pdp_ctx_free)
at some places in gprs_gmm.c on the reception of a Detach Req and on
re-use of an IMSI that is already associated with an MM context. This
can lead to segfaults when there is a pending request or a data
indication at libgtp.

This patch add a new function sgsn_pdp_ctx_terminate that de-associates
the PTP context from the MM context, deactivates SNDCP, sets pdp->mm
to NULL and then calls sgsn_delete_pdp_ctx. sgsn_libgtp is updated to
check for pdp->mm being non-NULL before dereferencing it. The
sgsn_pdp_ctx_terminate function will be called for each PDP context of
an MM context before this context is going to be deleted via
sgsn_mm_ctx_free. To ensure, that the ctx->llme (which is accessed
during the deactivation of SNDCP) remains valid, the call to
gprs_llgmm_assign is moved after the call to sgsn_mm_ctx_free. The
handling of re-used IMSIs is changed to mimic the processing of a
Detach Req.

Addresses:
<0002> gprs_gmm.c:654 MM(/f6b31ab0) Deleting old MM Context for same
    IMSI p_tmsi_old=0xc6f19134
<000f> gprs_sgsn.c:259 PDP freeing PDP context that still has a
    libgtp handle attached to it, this shouldn't happen!
[...]
SEGFAULT

Ticket: OW#1311
Sponsored-by: On-Waves ehf
2014-10-27 10:25:13 +01:00
Jacob Erlbeck ae20b4b31b sgsn: Cancel pending timer in sgsn_mm_ctx_free
Currently the timer is not stopped before the MM context is freed
which can lead to failure if sgsn_mm_ctx_free is called while timer
protected procedures are active.

This patch add code to cancel the timer if necessary from within
sgsn_mm_ctx_free.

Ticket: OW#1322
Sponsored-by: On-Waves ehf
2014-10-27 10:25:03 +01:00
Holger Hans Peter Freyther 19e990d6a7 gprs: Fix typo in the comment 2014-10-27 10:25:03 +01:00
Jacob Erlbeck 6a1d428f56 gbproxy: Fix segfault for VTY delete-gbproxy-link
Currently the code segfaults when the link shall be deleted by IMSI
when the IMSI has not been set yet.

This patch adds a NULL check to skip the entry before calling
gsm48_mi_to_string,

Adresses:
Program received signal SIGSEGV, Segmentation fault.
0xb693af77 in gsm48_mi_to_string (string=0xbfffe020 "", str_len=200,
mi=0x0, mi_len=0) at gsm48.c:360
    360         mi_type = mi[0] & GSM_MI_TYPE_MASK;
    str_len=200, mi=0x0, mi_len=0) at gsm48.c:360
    self=0x807c9a0 <delete_gb_link_by_id_cmd>, vty=0xb4303c70,
     argc=3, argv=0xbfffe1c0) at gb_proxy_vty.c:670
...

Sponsored-by: On-Waves ehf
2014-10-27 09:47:00 +01:00
Jacob Erlbeck 058ae12135 gbproxy: Discard UL PTP messages with an unknown BVCI
Currently all PTP messages are in general forwarded to the SGSN even
when the BVCI is not known to the gbproxy. Only if message patching
is active and the peer cannot be determined, a log message is
generated, a STATUS message returned, and the message discarded.
The intention for this was to keep the old gbproxy's behaviour if
patching is disabled. But the code gets much more complex this way.
Another drawback is that when the SGSN returns a corresponding STATUS
message, it cannot be routed to the BSS where the original message
came from.

This patch therefore changes the behaviour to reject BSSGP PTP uplink
messages immediately if the BVCI is not known.

Fixes: Coverity CID 1244240
Ticket: OW#1317
Sponsored-by: On-Waves ehf
2014-10-27 09:44:29 +01:00
Holger Hans Peter Freyther f9ffd1fa18 sgsn: Prevent memory leak and double free
This has been re-produced using the "osmo-pcu emulator" code
and a ping to force segmented SNDCP messages. When the NS link
enters the DEAD/BLOCKED state the msgb would be freed twice.
Once inside gprs_ns_sendmsg and once by the caller. Based on the
return one can not see if the parameter has been deleted.

I changed libosmocore/libosmogb to always free the msgb in case
of an error on the way to gprs_ns_sendmsg. Catch up, avoid the
double free and fix some memory leaks. In case the sending fails
assume the entire segmented message is at end and free the
original input data.

This has been tested by posix suspending/resuming the emulator
process to have the GPRS-NS link go to dead/blocked to alive
and unblocked. The ping recovers and "SIGUSR1" to the SGSN does
not show active memory allocations.

The SGSN calls bssgp_tx_dl_ud at the lowest level and has the
following callchains. Most of them allocate the msgb and have
no early return and transfer ownership already:

<- gprs_llc_tx_u
<- gprs_llc_tx_ui
	<- gsm48_gmm_sendmsg (all callers sane)
		<- _tx_status
		<- _tx_detach_req
	<- gprs_llc_tx_xid (all callers sane)
	<- sndcp_unitdata_req
		<- sndcp_send_ud_frag
2014-10-10 17:43:40 +02:00
Jacob Erlbeck b4f0e8089d gbproxy: Log more information on parse errors
To get a clue which message caused the error without having to enable
LOGL_DEBUG, information about how far the parser came (message name,
parsed fields) is logged with LOGL_NOTICE along with a full hexdump
of the message.

Ticket: OW#1307
Sponsored-by: On-Waves ehf
2014-10-09 18:17:06 +02:00
Jacob Erlbeck 1c407aa993 gbproxy: Pass the log level as argument to gprs_gb_log_parse_context
Currently, the log level is always LOGL_DEBUG. In case of errors it
would be helpful to use a higher log level.

This patch adds a log_level parameter to gprs_gb_log_parse_context to
let the caller decide about the level.

Ticket: OW#1307
Sponsored-by: On-Waves ehf
2014-10-09 18:16:22 +02:00
Jacob Erlbeck 9b07135b92 gbproxy: Add gprs_gb_message_name function
This function tries to get an accurate name for the message even if
the parsing has been aborted due to message errors.

The patch also moves the settings of the BSSGP related fields in
parse_ctx from behind to the front of bssgp_tlv_parse, to get more
information in the case of failure. This is now consistent with the
handling of the llc and g48_hdr fields.

Id addition, gprs_gb_log_parse_context now uses the new function to
derive a more accurate message name.

Ticket: OW#1307
Sponsored-by: On-Waves ehf
2014-10-09 18:15:31 +02:00
Jacob Erlbeck cc8856f9d3 gbproxy: Refuse to configure conflicting NSEIs
Currently it is possible to set the secondary SGSN NSEI to the same
value like the (primary) SGSN NSEI. This leads to undefined behaviour
and is hard to recognize.

This patch adds checks to either NSEI configuration command to refuse
conflicting values.

Ticket: OW#1306
Sponsored-by: On-Waves ehf
2014-10-09 18:14:09 +02:00
Jacob Erlbeck 49389178cc gbproxy: Use pointer to PTMSI value instead of MI
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-09 18:12:27 +02:00
Jacob Erlbeck 43b8f9f8a1 gbproxy: Send STATUS(BVCI unknown) to BSS on unknown PTP BVCI
Currently BSSGP PTP messages are silently dropped when the BVCI is
not known and patching is enabled. The nanoBTS will not recognize
this and continue to send messages on the BVCI. If it receives a
STATUS(BVCI unknown) instead, it will start a BVC reset procedure
instead.

This patch modifies gbprox_rx_ptp_from_bss() to return a
STATUS(BVCI unknown) to the BSS instead of dropping the message.

Sponsored-by: On-Waves ehf
2014-10-09 18:09:54 +02:00
Jacob Erlbeck f349baeec8 gbproxy: Replace ';;' by ';'
This patch removes some superfluous ';' from the code.

Sponsored-by: On-Waves ehf
2014-10-09 18:09:27 +02:00
Jacob Erlbeck c9cd15fbc9 gbproxy: Fix parser to accept GSM 24.008 Attach Req messages
Currently the parse expects a 'MS network capability' IE with
2 <= length <= 3 which is compliant to GSM 04.08, 9.4.1  but not to
GSM 24.008, 9.4.1 which specifies 3 <= length <= 9. Thus the parser
rejects messages with a length >= 4 (including length field).

This patch relaxes the length check to accept either range by
requiring 2 <= length <= 9.

Ticket: OW#1258
Sponsored-by: On-Waves ehf
2014-10-09 18:07:10 +02:00
Jacob Erlbeck b36032cb27 gbproxy: Use a separate regexp for routing
Currently one regexp ('patching') is used for all matching.

This patch adds a second category 'routing' which is exclusively used
for SGSN selection. It also adds a corresponding VTY command:

  - match-imsi patching RE : MS related patching (currently APN)
  - match-imsi routing RE  : Select secondary SGSN on match only
  - no match-imsi          : Clear all filter expressions

Ticket: OW#1258
Sponsored-by: On-Waves ehf
2014-10-09 18:06:30 +02:00
Jacob Erlbeck 6c3fdc1091 gbproxy: Extend the match-imsi VTY command to support categories
This patch modifies the match-imsi command to allow for different
match categories (currently only 'patching' is provided).

  - match-imsi patching RE : Filter APN patching and routing
  - no match-imsi          : Clear all filter expressions

Sponsored-by: On-Waves ehf
2014-10-09 18:05:17 +02:00
Jacob Erlbeck 9a83d7af55 gbproxy: Refactor IMSI matching
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-09 18:02:33 +02:00
Jacob Erlbeck 7e31f847af gprs: Fix gprs_msgb_copy pointer computation
Currently the pointers are computed by adding an offset to the new
message's _data pointer even when the original pointer is NULL.
This leads to invalid pointers in the copied msgb.

This patch adds a NULL check to each computation such that NULL
pointers are not adjusted.

Sponsored-by: On-Waves ehf
2014-10-09 18:00:55 +02:00
Jacob Erlbeck 657502812b gbproxy: Refactor local message generation
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-09 17:57:28 +02:00
Jacob Erlbeck d211d1d999 gbproxy: Reset IMSI acquisition within gbproxy_unregister_link_info
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-09 17:56:16 +02:00
Jacob Erlbeck 9c65c8116f gbproxy: Parse Attach Reject messages
That message is currently ignored but should invalidate the TLLI and
de-register the logical link instead.

This patch extends the parser to recognize such messages and to set
the invalidate_tlli flag.

Sponsored-by: On-Waves ehf
2014-10-09 17:48:37 +02:00
Jacob Erlbeck c6807c4405 gbproxy: Use monotonic system time instead of time-of-day
Currently time() is used for age calculations. This time source
may jump either forwards or backwards in time (NTP update, leap
seconds).

This patch replaces the use of time() by using
clock_gettime(CLOCK_MONOTONIC) instead.

Sponsored-by: On-Waves ehf
2014-10-09 17:46:34 +02:00
Jacob Erlbeck ba6267f05a gbproxy: Only search by valid identifiers
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-09 17:46:06 +02:00
Jacob Erlbeck d4c79a458b gbproxy: Replace 'tlli' by 'link' in VTY commands
Since the (former) TLLI list has developed into a logical link list,
related commands are renamed accordingly.

 - tlli-list * -> link-list *
 - delete-gbproxy-tlli * -> delete-gbproxy-link *
 - show gbproxy tllis -> show gbproxy links

Sponsored-by: On-Waves ehf
2014-10-09 17:45:27 +02:00
Jacob Erlbeck f8562e362b gbproxy: Rename the field 'enabled_tllis' to 'logical_links'
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-09 17:45:14 +02:00
Jacob Erlbeck 91d2f8a704 gbproxy: Use the term 'link' instead of 'tlli'
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-09 17:44:57 +02:00
Jacob Erlbeck 9a7b0d5641 gbproxy: Rename functions related to tlli_info
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-09 17:43:53 +02:00
Jacob Erlbeck 9a6b763507 gbproxy: Remove sgsn_nsei parameter
The function gbproxy_imsi_acquisition() has a parameter sgsn_nsei
that is alyways equal to tlli_info->sgsn_nsei (if tlli_info is not
NULL).

This patch removes this parameter from gbproxy_imsi_acquisition() and
gbproxy_flush_stored_messages() and accesses tlli_info->sgsn_nsei
instead within these functions.

Sponsored-by: On-Waves ehf
2014-10-09 17:43:34 +02:00
Jacob Erlbeck 8992f30866 gbproxy: Rename identifiers related to IMSI matching
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-10-09 17:43:12 +02:00
Jacob Erlbeck 08fbeb8fa4 gbproxy/sgsn: Enforce termination when creating a P-TMSI/TLLI
Currently the number of iterations when creating a P-TMSI/TLLI is not
limited. It is nevertheless very unlikely that the loop will not
terminate. On the other hand, the number of iterations of every loop
should have an upper bound (loop variant) which wouldn't be the case
here if an arbitrary random generator was used.

This patch limits the number of iterations to 23 and logs an error if
the creation of the indentifier was aborted due to this limit.

Sponsored-by: On-Waves ehf
2014-10-09 17:42:23 +02:00
Jacob Erlbeck e27ab916d6 gbproxy: Restart IMSI acquisition on RA UDP REQ
Currently the IMSI acquisition is not restarted when a RA Update
Request is received. This leads to repeated N(U) in the generated
Ident Request message, which in turn causes the MS to drop the
second of these message. This is bad, when the first Ident Response
has been lost between MS and gbproxy.

This patch changes gbproxy_imsi_acquisition() to handle RA Update
Request messages like Attach Requests.

Sponsored-by: On-Waves ehf
2014-10-09 17:41:41 +02:00
Jacob Erlbeck 258ce3ded5 sgsn: Free MM context after receiving a Detach Request
On a Detach/Re-attach cycle the Address Sanitizer detected a
use-after-free kind of problem. That is because we tried to
destroy the LLME twice. The first time it is destroyed as part
of the Detach handling ans the second time it is destroyed as
part of destroying the old MM context.

In case the GPRS GMM detach message is lost the SGSN needs
to reply besides not having a MM entry.

The alternative would have been to add NULL checks for all
usages of ctx->llme which would not have helped with the
readability.

Sponsored-by: On-Waves ehf
2014-10-09 17:22:34 +02:00
Holger Hans Peter Freyther 4299c0560f sgsn: Create testcase that verifies that llmes get deleted
On an "unassignment" this code verifies that the LLME will vanish
from the list of LLMEs. We assume that this doesn't create a
memory leak.
2014-10-09 17:22:34 +02:00
Daniel Willmann f8070f4793 gprs: Move log message about mm context after NULL check
Fixes: CID#1240205
2014-09-25 14:24:55 +02:00
Daniel Willmann 465531403c gprs: Improve loglevels and log messages for SGSN
Many log levels were DEBUG without any good reason. Also where possible
the details of the MM or PDP context are now logged with LOGMM/PDPCTXP.
2014-09-22 10:47:11 +02:00
Jacob Erlbeck 25ad52cf6a sgsn: Reset local LLC parameters when sending XID reset
Currently when gprs_llgmm_reset() is invoked an XID reset is sent but
the local LLC parameters (e.g. V(U)) are not cleared (see GSM 04.64,
8.5.3.1). This can lead to discarded messages on the SGSN side.

This patch modifies gprs_llgmm_reset to clear vu_send, vu_recv,
oc_ui_send, oc_ui_recv.

Sponsored-by: On-Waves ehf
2014-09-19 11:55:21 +02:00
Jacob Erlbeck 91a0e8639a gbproxy: Separate SGSN numeric namespaces
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-19 11:21:35 +02:00
Jacob Erlbeck 1a02442f66 gbproxy: Check other tlli_infos for matching TLLI/P-TMSI
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-19 11:21:01 +02:00
Jacob Erlbeck 85e5c8f905 gbproxy: Parse RA_UPD_REJ and invalidate TLLI
Since this message puts the MS into DEREGISTERED state (like a detach
procedure), this message is parsed and the invalidate_tlli field is
set accordingly.

Sponsored-by: On-Waves ehf
2014-09-19 11:20:31 +02:00
Jacob Erlbeck cdd37837b3 gbproxy: Delete and show detached entries via VTY
This commit adds/modifies the following VTY commands:

  - delete-gbproxy-tlli <NSEI> de-registered : Delete all
    de-registered entries
  - show gbproxy tllis : Display 'DE-REGISTERED' when appropriate

In addition, the implementation of the delete-gbproxy-tlli command
has been split into two functions (with and without TLLI/IMSI
value).

Sponsored-by: On-Waves ehf
2014-09-19 10:54:21 +02:00
Jacob Erlbeck d3bde96b36 gbproxy: Replace LOGP by LOGPC for continued lines
gprs_gb_log_parse_context() uses a sequence of LOGP calls to compose
a single message line. This leads to cluttered log output.

This patch replaces all but the first LOGP applications in this
function by applications of LOGPC.

Sponsored-by: On-Waves ehf
2014-09-19 10:49:17 +02:00
Jacob Erlbeck 16a3cd3847 gbproxy: Avoid multiple tlli_info entries with the same IMSI
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-19 10:49:12 +02:00
Jacob Erlbeck 7430da621a gbproxy: Keep tlli_info after detach
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-19 10:46:23 +02:00
Jacob Erlbeck cba4c0cc60 gbproxy: Only patch what has been configured
Currently when patching is basically enabled P-TMSI and TLLI gets
patched even when P-TMSI patching is not enabled. Albeit the result
is correct in this case (the same value is re-written), the counter
shows unexpected results.

This patch adds configuration checks for P-TMSI and TLLI patching. It
also reorders the code of gbproxy_patch_raid to return early if there
is nothing to patch.

Sponsored-by: On-Waves ehf
2014-09-18 13:46:09 +02:00
Jacob Erlbeck a42fe9f61e gbproxy: Remove gbproxy_register_tlli
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-18 13:21:17 +02:00
Jacob Erlbeck 2a5096dfc6 gbproxy: Send DETACH_ACC if the IMSI has not been acquired
If IMSI acquisition is enabled and the gbproxy receives a Detach
request from the MS, it cannot pass it to the SGSN since the
acquisition has not yet been completed.

This patch implements the generation of a Detach Accept message and
for this case and updates the TLLI state accordingly.

Sponsored-by: On-Waves ehf
2014-09-18 13:21:16 +02:00
Jacob Erlbeck 948c07f490 gbproxy: Fixed RAI patching in Attach Request messages
Currently the RAI in the LLC part of the message is not updated if
the message has been taken from the list of stored messages. The
reason is, that old_raid_matches is update in
gbprox_process_bssgp_ul() but not in gbproxy_flush_stored_messages().

This patch moves the check to gprs_gb_parse_bssgp() which is called
at both places and where other fields like parse_ctx->tlli are set,
too.

In addition, old_raid_matches is replaced by old_raid_is_foreign
since this is clearer in the case when there is no old RAI at all.

Several RAI patch counter assertions are also added to
test_gbproxy_ra_patching().

Sponsored-by: On-Waves ehf
2014-09-18 13:20:58 +02:00
Jacob Erlbeck 2fd1ba4c6d gbproxy: Replace 'mi_data' by 'imsi'
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-18 11:22:15 +02:00
Jacob Erlbeck 6bafa4ce0d gbproxy: Rework gbproxy_imsi_acquisition
This commit changes gbproxy_imsi_acquisition as follows:

tlli_info->mi_data_len is used instead of parse_ctx->imsi to check,
whether the IMSI is known already. Since the function is always
called after gbproxy_update_tlli_ul(), the two values are already
synchronized.

Messages are always flushed when the IMSI gets known, if the current
message is IDENT RESP discard it, otherwise continue processing as
usual.

The 'if' clauses are simplified for better readability.

Sponsored-by: On-Waves ehf
2014-09-18 11:21:57 +02:00
Jacob Erlbeck 0b243a106a gbproxy: Refactor gbprox_process_bssgp_ul into smaller functions
gbprox_process_bssgp_ul has grown quite large mainly by the addition
of IMSI acquisition.

This patch moves that code into several smaller functions. In
addition, the peer resolution which is similar to that in
gbprox_process_bssgp_dl is moved into a separate function, too.

Sponsored-by: On-Waves ehf
2014-09-18 08:49:21 +02:00
Jacob Erlbeck 1abfdc218e gbproxy: Remove patch_mode, update initial checks
This patch removes the patch_mode feature including the related VTY
command patch-mode. Where sensible, the other configuration flags are
queried instead.

In addition, this initial checks in gbprox_process_bssgp_dl() and
gbprox_process_bssgp_ul() have been updated.

The patch mode feature has not been used and was increasingly
difficult to maintain.

Sponsored-by: On-Waves ehf
2014-09-09 10:10:25 +02:00
Jacob Erlbeck 31591142e9 gbproxy: Reset IMSI acquisition and free stored messages in tlli_info
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-09 10:10:00 +02:00
Jacob Erlbeck b1ee5cd3b6 gbproxy: Fix P-TMSI reassignment
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-09 10:05:56 +02:00
Jacob Erlbeck 37fda77814 gbproxy: Change creation of tlli_info for SGSN originated messages
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-09 09:47:03 +02:00
Jacob Erlbeck cd9e1c94e5 gbproxy: Reorganize VTY commands
Since the secondary SGSN selection and APN patching can both be
enable/disabled by IMSI matching, this patch introduces a separate
match-imsi command and removes the corresponding variant of the
core-access-point-name command.

P-TMSI patching and IMSI acquisition are enabled/disabled by
match-imsi resp. secondary-sgsn. The patch-ptmsi and acquire-imsi
commands are still available for internal testing but are subject to
being removed.

Sponsored-by: On-Waves ehf
2014-09-08 10:54:20 +02:00
Jacob Erlbeck 146e30736d gbproxy: Show number of stored messages in VTY show
This patch extends the 'show gbproxy tllis' command to display the
number of stored messages per tlli_info if there are any.

Sponsored-by: On-Waves ehf
2014-09-08 10:20:18 +02:00
Jacob Erlbeck 1e65b0e7a1 gbproxy: Forward SGSN originated STATUS messages with BVCI
Currently all STATUS messages coming from the SGSN are just logged
and dropped. This prevents the PCU from recognising that the
(secondary) SGSN doesn't know about a certain BVCI and might require
a reset procedure.

This patch changes gbprox_rx_sig_from_bss() to forward STATUS
messages with cause "Invalid BVCI" containing a BVCI to the BSS.

Note that this will not forward broken "Invalid BVCI"
messages which do not include a BVCI IE.

Sponsored-by: On-Waves ehf
2014-09-08 10:20:18 +02:00
Jacob Erlbeck 17b42b81f0 gbproxy: Make STATUS messages spec compliant
Currently the gbproxy sends STATUS messages that are not compliant to
GSM 08.18, 10.4.14.1: The BVCI must be included if (and only if) the
cause is either "BVCI blocked" or "BVCI unknown".

This patch adds a missing BVCI to UNKNOWN_BVCI and BVCI_BLOCKED
status messages if the BVCI is available. Otherwise, INV_MAND_INF is
used instead.

Sponsored-by: On-Waves ehf
2014-09-08 10:20:18 +02:00
Jacob Erlbeck 18a3787296 gbproxy: Check tlli_info when patching, fix APN patching
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-08 10:20:16 +02:00
Jacob Erlbeck 25f98e618a gbproxy: Add missing commands to VTY write
Currently the new command acquire-imsi and secondary-sgsn are not
included into the write command's output.

This is fixed by this commit.

Sponsored-by: On-Waves ehf
2014-09-08 09:27:41 +02:00
Jacob Erlbeck c1c57d3a26 gbproxy: Copy uplink messages to SGSN 2
Some messages that are related to the BVC itself must be forwarded to
the secondary SGSN, too.

This patch implements this for BVC-RESET (BVCI != 0) and FLOW-CONTROL-BVC
messages. The resulting acknowledgement messages from the secondary
SGSN are silently dropped. The idea behind this is that the primary
SGSN is responsible for setting up and maintaining the BVC whereas
the secondary SGSN is rather passive and just has to accept it.

Ticket: OW#1258
Sponsored-by: On-Waves ehf
2014-09-08 09:27:41 +02:00
Jacob Erlbeck cabd24b33f gbproxy: Use secondary SGSN if IMSI matches
This patch modifies gbprox_process_bssgp_ul() to send the message to
the secondary SGSN if the IMSI has matched and routing to the
secondary SGSN is enabled. The destination for stored messages is
modified accordingly.

Ticket: OW#1261
Sponsored-by: On-Waves ehf
2014-09-08 09:27:36 +02:00
Jacob Erlbeck f4d60c8788 gbproxy: Support a secondary SGSN
This patch refactors SGSN NSEI handling to support a secondary SGSN.

It adds the following VTY commands:
  - secondary-sgsn nsei <0-65534>
  - no secondary-sgsn

Sending messages to the secondary SGSN is not yet implemented, but
received messages from such a SGSN would be forwarded to the BSS
peers.

Sponsored-by: On-Waves ehf
2014-09-08 09:11:59 +02:00
Jacob Erlbeck 5930064700 gbproxy: Add missing gbprox_process_bssgp_ul() return check
This should have been part of the 'Implement IMSI acquisition'
commit, where a similar change has been made for BSS originated PTP
messages.

Sponsored-by: On-Waves ehf
2014-09-08 09:04:01 +02:00
Jacob Erlbeck 1a8dbc4fc9 gbproxy: Fix warnings
This patch fixes the remaining 'unused' warnings.

Sponsored-by: On-Waves ehf
2014-09-07 10:46:10 +02:00
Jacob Erlbeck 5f4ef321a6 gbproxy: Implement IMSI acquisition
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-02 09:53:47 +02:00
Jacob Erlbeck 4b663ac34a gbproxy: Create STATUS message with original PDU
Currently when patching is enabled and an error happens when
receiving a message from the SGSN, the patched message is sent back
with the PDU_IN_ERROR IE.

This patch modifies gbprox_rx_sig_from_sgsn() to copy the message
before it is patched, so that the original message can be used with
the STATUS message. gbprox_rx_ptp_from_sgsn() does all checks before
the message is patched, so copying is not necessary.

Since gbprox_rx_sig_from_sgsn() is not called for BSSGP UNITDATA
messages and the msgb is already been copied in the gbprox_relay2peer
function, the relative performance impact is expected to be low.

Note that the PDU IE of STATUS messages received from an MS and
forwarded to the SGSN will not be patched. STATUS messages from the
SGSN are only logged and not forwarded to the MS.

Sponsored-by: On-Waves ehf
2014-09-02 09:53:38 +02:00
Jacob Erlbeck 46f1d6fddb gbproxy: Move PTP message handling into separate functions
This patch adds gbprox_rx_data_from_sgsn() and
gbprox_rx_ptp_from_bss() which contain the PTP message processing
of gbprox_rcvmsg(). The calls to gbprox_process_bssgp_ul() are moved
from gbprox_relay2sgsn() to gbprox_rx_ptp_from_bss() and
gbprox_rx_sig_from_bss().

The goal is, to do all patching (and calls to gbprox_process_bssgp_*)
from within the gbprox_rx_* functions. Doing the patching from within
gbprox_relay2sgsn has the drawback, that the patching code cannot
call gbprox_relay2sgsn() which is needed if a single message shall
trigger a sequence of messages.

Sponsored-by: On-Waves ehf
2014-09-02 09:53:30 +02:00
Holger Hans Peter Freyther fcc30a3df7 gprs: Document the stale option in delete-gbproxy-tlli 2014-08-29 10:51:44 +02:00
Jacob Erlbeck ecbd56c625 gbproxy: Fix issues found by Coverity
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-29 08:50:40 +02:00
Holger Hans Peter Freyther 5160996d4a gprs: Link gbproxy to -lrt for clock_gettime
On older GNU libc systems we need to link to this library to
use the clock_gettime symbol.
2014-08-25 07:29:15 +02:00
Harald Welte 55dc31e781 Use port number #defines for VTY and CTRL ports
.. as defined in libosmocore
2014-08-24 17:54:49 +02:00
Harald Welte 6e68808247 move GSM_RESERVED_TMSI to libosmocore
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-24 17:38:18 +02:00
Jacob Erlbeck 5f1faa3cd2 gbproxy: Move peer definitions to gb_proxy_peer.c
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-24 16:16:40 +02:00
Jacob Erlbeck 9114bee242 gbproxy: Refactor gb_proxy.c into several files
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-24 16:16:40 +02:00
Jacob Erlbeck 0d37671824 gbproxy: Use different TLLI/P-TMSI for BSS and SGSN
This patch modifies gbprox_make_bss_ptmsi() to generate a new P-TMSI
when patch_ptmsi is set in the configuration instead of using the
P-TMSI assigned by the SGSN. It modifies gbprox_make_sgsn_tlli() to
either use a foreign TLLI based on the SGSN side P-TMSI or (if there
is none) generate a random TLLI if patch_ptmsi is set. Otherwise, the
TLLI used by the BSS is used.

The seeds for the pseudo-random sequences sre set based on time
initially. Note that these are neither cryptographically safe nor
protected against collisions.

Ticket: OW#1259
Sponsored-by: On-Waves ehf
2014-08-24 16:16:40 +02:00
Jacob Erlbeck 643d5228ed gbproxy: Add context info to log messages
This mainly adds the NSEI to the messages, similar to log messages
ogf the existing gbproxy code.

Sponsored-by: On-Waves ehf
2014-08-24 16:16:40 +02:00
Jacob Erlbeck 03ca10e863 gbproxy: Patch TLLI/P-TMSI
This patch adds code to modify TLLIs and P-TMSIs. Related counters
are also added.

Sponsored-by: On-Waves ehf
2014-08-24 16:16:39 +02:00
Jacob Erlbeck e37487e083 gbproxy: Fix TLLI state handling
This patch contains fixes for the TLLI tracking and handling.
It adds and uses gbprox_map_tlli() the map the source TLLI to the
destination TLLI while respecting whether it is current or assigned.
It removes gbprox_register_tlli() from the downlink path. It fixes
TLLI validation and disables the use of the BSSGP TLLI IE.

Sponsored-by: On-Waves ehf
2014-08-24 16:16:39 +02:00
Jacob Erlbeck 3b23d639ab gbproxy: Also handle LLC non UI and LL11 messages
Currently, these messages lead to a parsing error which prevents them
from being processed any further.

This patch sets the return value of gbprox_parse_llc to 1 in these
cases and fixes a segfault which is triggered by any non-04.08
message.

Sponsored-by: On-Waves ehf
2014-08-24 16:16:39 +02:00
Jacob Erlbeck 12496dd7db gbproxy: Refactor gbprox_patch_raid(), use different RAI types properly
Currently gbprox_patch_raid() updates the local MCC/MNC with every
BSS originated message, even if the RAI is an 'old' one.

This patch separates state updating and patching into 2 functions
gbprox_update_current_raid and gbprox_patch_raid. In addition, a
field named old_raid_enc is added to gbproxy_parse_context, which is
used for 'old RAI' IEs in Attach Requests and RA Update Requests.
Only the bssg_raid_enc in BSS originated message is used to update
the BSS side 'local' MCC/MNC.

Sponsored-by: On-Waves ehf
2014-08-24 16:16:39 +02:00
Jacob Erlbeck 311592fc39 gbproxy: Refactor gbprox_get_detached_tlli_info
This patch splits the functionality of gbprox_get_detached_tlli_info
into 2 new functions:
  - gbprox_tlli_info_alloc to allocate an intialized and detached
    tlli_info
  - gbprox_detach_tlli_info to detach an already attached tlli_info

Sponsored-by: On-Waves ehf
2014-08-24 16:16:39 +02:00
Jacob Erlbeck 0d4236be54 gbproxy: Add 'patch-ptmsi' command to enable TLLI/P-TMSI patching
This VTY command add the following commands to the gbproxy node:
  - patch-ptmsi: Enables P-TMSI/TLLI patching
  - no patch-ptmsi: Disables P-TMSI/TLLI patching

Note that using these commands interactively can load to undefined
behavior of existing LLC connections.

Sponsored-by: On-Waves ehf
2014-08-24 16:16:39 +02:00
Jacob Erlbeck 9057bc3c72 gbproxy: Track SGSN and BSS TLLI/PTMSI separately
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-24 16:16:39 +02:00
Jacob Erlbeck 59748e653b gbproxy: Handle old and new P-TMSI/TLLI
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-24 16:16:39 +02:00
Jacob Erlbeck 3c5b40fb75 gbproxy: Update enable_patching flag on existing tlli_info
Currently the enable_patching field in tlli_info is not updated,
when an IMSI is assigned to a TLLI that is already known.

This patch fixes this in gbprox_update_state() after the call to
gbprox_update_tlli_info().

The number of APN increases and the test output file is updated
accordingly.

Sponsored-by: On-Waves ehf
2014-08-24 16:16:39 +02:00
Jacob Erlbeck 3e23ddf88b gbproxy: Parse Detach Request messages
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-24 16:16:39 +02:00
Jacob Erlbeck 29805da6d1 gbproxy: Add gbprox_clear_patch_filter() (Coverity)
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-22 00:21:56 +02:00
Harald Welte 74d4adcbba libctrl: Follow rename of controlif_setup -> ctrl_interface_setup 2014-08-21 15:34:28 +02:00
Harald Welte 02cc2b668a libctrl: Move bulk of node lookup code into libosmocore
Now that the bulk of the control interface node lookup has
no reference to the BSC specific data structures, we are
moving it into libosmocore.

A control interface user now only registers an optional small
node lookup function like bsc_ctrl_node_lookup()
2014-08-21 15:34:28 +02:00
Harald Welte ba874b82be move libctrl from openbsc to libosmoctrl (libosmocore.git) 2014-08-21 15:34:28 +02:00
Jacob Erlbeck 5e68ecf3b2 gbproxy: Pass tlli_info around
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-13 11:14:08 +02:00
Jacob Erlbeck 2dec9851bd gbproxy: Optimize gbprox_remove_stale_tllis
The current implementation of this function is O(N), where N is the
number of entries.

The new implementation is O(D), where D is the number of entries that
are going to be deleted.

Sponsored-by: On-Waves ehf
2014-08-13 10:42:27 +02:00
Jacob Erlbeck 7b821d031a gbproxy: Don't call time() in TLLI related functions
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-13 10:42:27 +02:00
Jacob Erlbeck aad32bccc0 gbproxy: Don't remove stale TLLI automatically
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-13 10:42:26 +02:00
Jacob Erlbeck 12828c1b30 gbproxy: Move parse_ctx logging into separate function
Sponsored-by: On-Waves ehf
2014-08-13 10:42:26 +02:00
Jacob Erlbeck c812882dbf gbproxy: Refactor gbproxy_patch_bssgp_message
This patch refactors that function by separating the actual patch
code into a new function gbproxy_patch_bssgp(), similar to
gbproxy_patch_llc(). The remaining function is renamed to
gbproxy_process_bssgp_message. The existing function
gbproxy_parse_bssgp_message() is renamed to
gbproxy_process_bssgp_message to match gbproxy_parse_llc.

Sponsored-by: On-Waves ehf
2014-08-13 10:42:26 +02:00
Jacob Erlbeck 291f0508c5 gbproxy: Test and fix IMSI/TMSI matching
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-13 10:41:23 +02:00
Jacob Erlbeck 89d3d343d1 gbproxy: Track TLLI even when the IMSI is not known
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-13 10:29:09 +02:00
Jacob Erlbeck 58da91d5d0 gbproxy: Make pointers to MI const in parse/check functions
The encoded mobile identity will never be modified in
is_mi_tmsi/is_mi_imsi/parse_mi_tmsi, thus the pointer is made const.

Sponsored-by: On-Waves ehf
2014-08-13 09:57:26 +02:00
Jacob Erlbeck fb22ac52b0 gbproxy: Explicitly convert PTMSI to TLLI
This patch modifies the new_ptmsi handling by setting its two most
significant bits before using it as TLLI.

Sponsored-by: On-Waves ehf
2014-08-13 09:57:25 +02:00
Jacob Erlbeck 690768a171 gbproxy: Parse additional IMSI/PTMSI/TLLI fields
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-13 09:55:27 +02:00
Jacob Erlbeck 2db2512f4d gbproxy: Separate BSSGP parsing from patching
This adds a gbprox_parse_bssgp_message() function that contains the
parsing part of the former gbprox_patch_bssgp_message(). This
includes a call to gbprox_parse_llc().

The calls to gbprox_patch_llc(), gbprox_update_state() and
gbprox_update_state_after() have therefore been moved to
gbprox_patch_bssgp_message().

Sponsored-by: On-Waves ehf
2014-08-12 19:32:26 +02:00
Jacob Erlbeck 2bdd253d54 gbproxy: Unify TLLI tracking
This patch unifies the TLLI tracking for all LLC messages. The TLLI
state handling is moved into separate functions.

Only Detach Accept messages are taken into account to release a TLLI,
which is safe but not optimal.

Sponsored-by: On-Waves ehf
2014-08-12 19:30:48 +02:00
Jacob Erlbeck 0cee7ad2bf gbproxy: Move patching code out of the 04.08 specific functions
Currently, parsing and optionally patching is done in the same
functions (e.g. gbprox_patch_gmm_attach_req()).

This patch moves the patching code out of these functions into
gbprox_patch_llc() and just stores pointers to the relevant data
areas into parse_ctx. Consequently the len_change parameter is
removed and the _patch_ in the function's names is renamed to
_parse_. In addition, the patching_is_enabled checks and counter
increments are moved out of these functions, too.

Sponsored-by: On-Waves ehf
2014-08-12 19:29:12 +02:00
Jacob Erlbeck 477c69a9c5 gbproxy: Track all TLLIs (not only LOCAL)
This patch removes all checks for the TLLI type.

Sponsored-by: On-Waves ehf
2014-08-08 08:50:14 +02:00
Holger Hans Peter Freyther b773fbf335 sgsn: Make P-TMSI a local TLLI to avoid clash
Some broken equipment does not convert the P-TMSI to a Local TLLI.
This leads to the SGSN ignoring the GPRS Attach Complete message
from the phone. Proprietary SGSNs and some documentation we found
state that one should always set the two highest bits of a P-TMSI
to one. This will help broken equipment and will avoid a potential
P-TMSI/TLLI clash. The P-TMSI/Local TLLI mapping is now bijective.
2014-08-05 15:20:23 +02:00
Jacob Erlbeck 58cf664d28 gprs: Refactor gbprox_register_tlli()
Currently gbprox_register_tlli() is a rather complex function.

This patch splits it into several smaller functions to ease reviewing
and maintaining it.

Sponsored-by: On-Waves ehf
2014-08-05 15:11:11 +02:00
Holger Hans Peter Freyther 0196c9936c gbproxy/test: Test TLLI expiry
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-05 15:02:06 +02:00
Jacob Erlbeck d8a7e22709 gbproxy: Remove broken TLLI comparison
This comparison bit-ored the TLLI with 0xc000 instead of 0xc000000.

Since this has never worked properly yet and since normalizing to
local TLLIs doesn't seem sensible here, the comparison is removed
entirely.

Sponsored-by: On-Waves ehf
2014-08-04 17:13:17 +02:00
Holger Hans Peter Freyther 3fa26448d1 gbproxy: Kill the global gbprox_global_patch_state struct
Move this patching state into the gbproxy_config as well.

Done by Jacob
2014-08-04 16:27:11 +02:00
Holger Hans Peter Freyther 3748ada073 gbproxy: Add a hint to the compiler that all parameters are not NULL
In these functions we assume that peer is not NULL. Add a compiler
attribute in the hope that either coverity or GCC/Clang will help
us to find a misusage.

Done with Jacob
2014-08-04 16:06:20 +02:00
Holger Hans Peter Freyther eece627799 gbproxy: Remove global state from the gbproxy
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-04 16:01:12 +02:00
Holger Hans Peter Freyther ce1b22e817 gprs: Add testcases for the APN string/octet conversion and fix it
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-04 15:00:54 +02:00
Holger Hans Peter Freyther 4d9fc422d2 gbproxy: Use gbprox_delete_tlli if possible
Make use of the delete routine in more places and get test coverage
for it.

Done with Jacob
2014-08-04 12:18:07 +02:00
Holger Hans Peter Freyther 7127b0295e gprs: Create a gprs_utils file and move to be shared code in there
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-04 11:52:52 +02:00
Holger Hans Peter Freyther 1ddd9e518e gbproxy: Use gbproxy_ for all structures
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-04 11:37:50 +02:00
Holger Hans Peter Freyther b900459e96 gbproxy: The dump routines are only used by the test, move it there
Done with Jacob
2014-08-04 11:37:47 +02:00
Holger Hans Peter Freyther 16f30b5373 gbproxy: Have a clear namespace for the public functions
Done with Jacob
2014-08-04 11:37:45 +02:00
Holger Hans Peter Freyther a7027a04dd gbproxy: Remove the global rate counter and place it in the config
Move the global data into the struct and use it. gbprox_reset will
first free data and then re-initialize the structure. This code is
used by the unit test.

Done with Jacob
2014-08-04 11:37:40 +02:00
Holger Hans Peter Freyther d4d36f22ee gbproxy: Correct the method name. We work on TLLIs
Done with Jacob
2014-08-04 11:37:33 +02:00
Holger Hans Peter Freyther 18739ea32d gbproxy: Move the VTY code into the vty file and create public API
Create public accessors to the core of the peer to allow to
simplify the test and separate concerns.

Done with Jacob.
2014-08-04 11:37:28 +02:00
Jacob Erlbeck 03551e5f3c gprs: Move LLC IE length fix to BSSGP level
This commit moves the fixing code of the length field of the LLC
information element to the BSSGP patching level since that is not a
part of LLC itself.

Sponsored-by: On-Waves ehf
2014-07-22 17:13:32 +02:00
Jacob Erlbeck 2e2650f8f3 gprs: Parse PTMSI and update TLLI accordingly
This commit adds code to parse the PTMSI in network originated
messages

  - Attach Accept,
  - Routing Area Update Accept, and
  - P-TMSI Reallocation Command (see below)

to keep track of the TLLI identifying the LLC connection.

The P_TMSI Realloc Command specific code is not being tested yet, so
a corresponding notice is logged when such a message will be
received.

NOTE:
  The gbproxy will lose the TLLI when the MS doesn't receive/use
  the message (normally the SGSN remembers the old TLLI for some time
  to avoid this kind of problem). If this happens the MS will
  probably restart the procedure and the network will have to answer
  again eventually using one of the above messages which will
  re-associate the IMSI with the TLLI before the MS can send a
  PDP Context Request message.

Ticket: OW#1192
Sponsored-by: On-Waves ehf
2014-07-22 17:11:57 +02:00
Jacob Erlbeck 35cc03f97d gprs: Use struct to pass context information
Add a struct containing context information from the parts of the
message that have been parsed already. A pointer to this (temporary)
struct is passed to parse/patch functions.

Sponsored-by: On-Waves ehf
2014-07-22 17:10:51 +02:00
Jacob Erlbeck aefaf92d1a gprs: Use shift functions instead of manual parsing
Currently the patching code directly accesses the single bytes to
parse the LLC/DTAP messages.

This patch uses the shift functions instead to parse tlv and similar
structures.

Sponsored-by: On-Waves ehf
2014-07-22 17:08:28 +02:00
Jacob Erlbeck b138106423 gprs: Add TLV parse functions
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-22 17:08:10 +02:00
Jacob Erlbeck 040b4012a7 gprs: Fix TLLI cache size computation
Currently the enabled_tllis_count field isn't always decremented when
an element is removed from the TLLI cache list.

This patch adds the missing update and also adjusts the counter
accordingly.

Sponsored-by: On-Waves ehf
2014-07-22 17:05:16 +02:00
Jacob Erlbeck aa3e334608 gprs/test: Rearrange for PTMSI parsing
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-22 17:03:23 +02:00
Jacob Erlbeck 25049b93b1 gprs: Add counters related to LLC layer patching
This commit adds the following counters:

  - attach-reqs:   Number of Attach Request messages
  - attach-rejs:   Number of Attach Reject messages
  - tlli-cache:    Size of the TLLI cache

Sponsored-by: On-Waves ehf
2014-07-22 17:02:43 +02:00
Jacob Erlbeck 7dd498de64 gprs/vty: Add commands to manage the TLLI list
These commands manage the TLLI list used to decide whether an APN
shall be patched or not. Note that this list is (currently) only
maintained if IMSI matching is used.

VTY commands (enable node):
  show gbproxy tllis                   show all TLLI entries
  delete-gbproxy-tlli NSEI stale       purge all stale entries
  delete-gbproxy-tlli NSEI imsi IMSI   purge entry with the IMSI given
  delete-gbproxy-tlli NSEI tlli TLLI   purge entry with the TLLI given

Sponsored-by: On-Waves ehf
2014-07-22 17:02:34 +02:00
Jacob Erlbeck 7c101d922e gprs: Track IMSI/TLLI to control APN patching
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-22 16:56:33 +02:00
Jacob Erlbeck 006c038212 gprs: Store gbproxy patching state per peer
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-22 16:53:41 +02:00
Jacob Erlbeck 736852825a gprs: Add APN patch support for LLC/GSM messages
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-22 16:07:01 +02:00
Jacob Erlbeck 91fb680236 gprs: Add MCC/MNC patch support for LLC/GMM messages
This patch extends the BSSGP patch code to also patch LLC information
elements along with MCC/MNC patching support for the following messages:

- Attach Request
- Attach Accept
- Routing Area Update Request
- Routing Area Update Accept
- P-TMSI reallocation command

Note that encrypted packets will not be patched.

Ticket: OW#1185
Sponsored-by: On-Waves ehf
2014-07-22 16:05:59 +02:00
Jacob Erlbeck 67a4445675 gprs: Implement BSSGP MCC/MNC patching
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-22 16:04:54 +02:00
Jacob Erlbeck fd636aed1e gprs: Use imsi field instead of imei
The wrong field has been use for the field length computation. This
hadn't any impact so far, since
  sizeof(ctx->imei) == sizeof(ctx->imsi)

This patch fixes the computation to use the right field.

Sponsored-by: On-Waves ehf
2014-07-22 15:51:55 +02:00
Daniel Willmann 46d13268b8 gprs_llc: Prevent llme_alloc/lle_init from reading invalid memory
Make the llc_default_params structure from which data is initialized
large enough. Otherwise address sanitizer complains with out-of-bounds
reads.

Only SAPIs 1, 2, 3, 5, 7, 8, 9, 11 are defined for GPRS but the
struct gprs_llc_llme includes NUM_SAPIS lle's and they are populated
from the llc_default_params structure.
2014-07-07 19:17:54 +02:00
Jacob Erlbeck b32d3c041b gprs/test: Remove verbose parameter of gbprox_dump_* functions
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-07-07 15:05:59 +02:00
Jacob Erlbeck 8f50359ebf gprs: Use area terms LAI/RAI as defined in GSM 03.03
Currently the terms 'Routing area code' (RAC) and 'Location area
code' (LAC) are used in several places where 'Routing area
identification' (RAI) or 'Location area identification' (LAI) are
meant in fact.

This patch replaces RAC/LAC by RAI/LAI and 'code' by 'identification'
at these places.

Note that RAI := MCC MNC LAC RAC, and LAI := MCC MNC LAC (see GSM
03.03, sections 4.1 and 4.2).

Sponsored-by: On-Waves ehf
2014-06-15 19:23:38 +02:00
Jacob Erlbeck b492d39177 gprs: Separate LLC parsing from LLC state handling
Currently LLC parsing is part of gprs_llc.c which needs large parts
of the SGSN code parsing to fulfill its link dependencies.

This patch moves the functions that just do plain parsing, dumping,
and FCS computation to a different file to avoid these dependencies
if LLC stateful processing is not needed. It also exposes
struct gprs_llc_hdr_parsed and enum gprs_llc_cmd publically.

Sponsored-by: On-Waves ehf
2014-06-04 16:29:30 +02:00
Holger Hans Peter Freyther 5a1b329a9e gprs: Fix compiler warnings ini gprs_sndcp_vty.c
CC       gprs_sndcp_vty.o
gprs_sndcp_vty.c: In function ‘vty_dump_sne’:
gprs_sndcp_vty.c:46:15: warning: unused variable ‘i’ [-Wunused-variable]
  unsigned int i;
2014-04-04 12:49:38 +02:00
Holger Hans Peter Freyther 65762e0455 gprs: Fix compiler warnings in sgsn_libgtp.c
CC       sgsn_libgtp.o
sgsn_libgtp.c: In function ‘create_pdp_conf’:
sgsn_libgtp.c:262:6: warning: variable ‘rc’ set but not used [-Wunused-but-set-variable]
  int rc;
      ^
sgsn_libgtp.c: In function ‘cb_data_ind’:
sgsn_libgtp.c:432:6: warning: variable ‘rc’ set but not used [-Wunused-but-set-variable]
  int rc;
2014-04-04 12:49:00 +02:00
Holger Hans Peter Freyther 744568b569 gprs: Fix compiler warnings in the gprs_llc.c code
CC       gprs_llc.o
gprs_llc.c: In function ‘t200_expired’:
gprs_llc.c:322:2: warning: enumeration value ‘GPRS_LLES_UNASSIGNED’ not handled in switch [-Wswitch]
  switch (lle->state) {
  ^
gprs_llc.c:322:2: warning: enumeration value ‘GPRS_LLES_ASSIGNED_ADM’ not handled in switch [-Wswitch]
gprs_llc.c:322:2: warning: enumeration value ‘GPRS_LLES_REMOTE_EST’ not handled in switch [-Wswitch]
gprs_llc.c:322:2: warning: enumeration value ‘GPRS_LLES_ABM’ not handled in switch [-Wswitch]
gprs_llc.c:322:2: warning: enumeration value ‘GPRS_LLES_TIMER_REC’ not handled in switch [-Wswitch]
gprs_llc.c: In function ‘gprs_llc_hdr_rx’:
gprs_llc.c:564:2: warning: enumeration value ‘GPRS_LLC_NULL’ not handled in switch [-Wswitch]
  switch (gph->cmd) {
  ^
gprs_llc.c:564:2: warning: enumeration value ‘GPRS_LLC_RR’ not handled in switch [-Wswitch]
gprs_llc.c:564:2: warning: enumeration value ‘GPRS_LLC_ACK’ not handled in switch [-Wswitch]
gprs_llc.c:564:2: warning: enumeration value ‘GPRS_LLC_RNR’ not handled in switch [-Wswitch]
gprs_llc.c:564:2: warning: enumeration value ‘GPRS_LLC_SACK’ not handled in switch [-Wswitch]
gprs_llc.c: In function ‘gprs_llc_rcvmsg’:
gprs_llc.c:791:23: warning: unused variable ‘udh’ [-Wunused-variable]
  struct bssgp_ud_hdr *udh = (struct bssgp_ud_hdr *) msgb_bssgph(msg);
                       ^
gprs_llc.c: At top level:
gprs_llc.c:311:13: warning: ‘t200_expired’ defined but not used [-Wunused-function]
 static void t200_expired(void *data)
             ^
gprs_llc.c:337:13: warning: ‘t201_expired’ defined but not used [-Wunused-function]
 static void t201_expired(void *data)
2014-04-04 12:47:32 +02:00
Holger Hans Peter Freyther cfee952e23 gprs: Fix compiler warnings in gprs_sndcp.c
CC       gprs_sndcp.o
gprs_sndcp.c: In function ‘defrag_input’:
gprs_sndcp.c:188:25: warning: variable ‘scomph’ set but not used [-Wunused-but-set-variable]
  struct sndcp_comp_hdr *scomph = NULL;
                         ^
gprs_sndcp.c: In function ‘sndcp_llunitdata_ind’:
gprs_sndcp.c:512:11: warning: variable ‘npdu_num’ set but not used [-Wunused-but-set-variable]
  uint16_t npdu_num;
           ^
gprs_sndcp.c: At top level:
gprs_sndcp.c:565:12: warning: ‘sndcp_ll_reset_ind’ defined but not used [-Wunused-function]
 static int sndcp_ll_reset_ind(struct gprs_sndcp_entity *se)
            ^
gprs_sndcp.c:573:12: warning: ‘sndcp_ll_status_ind’ defined but not used [-Wunused-function]
 static int sndcp_ll_status_ind()
            ^
2014-04-04 12:43:08 +02:00
Holger Hans Peter Freyther 1768a5765d gprs: Reduce the number of compiler warnings in gprs_gmm.c
CC       gprs_gmm.o
gprs_gmm.c: In function ‘gsm48_tx_gmm_att_ack’:
gprs_gmm.c:350:11: warning: unused variable ‘ptsig’ [-Wunused-variable]
  uint8_t *ptsig, *mid;
           ^
gprs_gmm.c: In function ‘gsm48_rx_gmm_auth_ciph_resp’:
gprs_gmm.c:524:6: warning: variable ‘rc’ set but not used [-Wunused-but-set-variable]
  int rc;
      ^
gprs_gmm.c: In function ‘gsm48_rx_gmm_att_req’:
gprs_gmm.c:703:9: warning: implicit declaration of function ‘sgsn_acl_lookup’ [-Wimplicit-function-declaration]
         !sgsn_acl_lookup(mi_string))) {
         ^
gprs_gmm.c:632:40: warning: variable ‘old_ra_info’ set but not used [-Wunused-but-set-variable]
  uint8_t *cur = gh->data, *msnc, *mi, *old_ra_info, *ms_ra_acc_cap;
                                        ^
gprs_gmm.c: In function ‘gsm48_rx_gmm_ra_upd_req’:
gprs_gmm.c:915:6: warning: variable ‘rc’ set but not used [-Wunused-but-set-variable]
  int rc;
      ^
gprs_gmm.c:910:11: warning: variable ‘ms_ra_acc_cap’ set but not used [-Wunused-but-set-variable]
  uint8_t *ms_ra_acc_cap;
           ^
gprs_gmm.c: At top level:
gprs_gmm.c:458:12: warning: ‘gsm48_tx_gmm_auth_ciph_req’ defined but not used [-Wunused-function]
 static int gsm48_tx_gmm_auth_ciph_req(struct sgsn_mm_ctx *mm, uint8_t *rand,
            ^
gprs_gmm.c:501:12: warning: ‘gsm48_tx_gmm_auth_ciph_rej’ defined but not used [-Wunused-function]
 static int gsm48_tx_gmm_auth_ciph_rej(struct sgsn_mm_ctx *mm)
            ^
gprs_gmm.c:1169:13: warning: ‘msgb_put_pdp_addr_ipv4’ defined but not used [-Wunused-function]
 static void msgb_put_pdp_addr_ipv4(struct msgb *msg, uint32_t ipaddr)
             ^
gprs_gmm.c:1180:13: warning: ‘msgb_put_pdp_addr_ppp’ defined but not used [-Wunused-function]
 static void msgb_put_pdp_addr_ppp(struct msgb *msg)
2014-04-04 12:41:03 +02:00
Holger Hans Peter Freyther d219507d63 sgsn: Comparing array to NULL is not useful
.v is a unsigned char array with up-to 255 elements. We do not
need to add a null check here.

Fixes: Coverity CID 1040719
2014-04-04 11:55:21 +02:00
Holger Hans Peter Freyther a27303094a sgsn/ctrl: Add ctrl interface, implement listing subscribers
Add the control interface with no hierachy right now and implement
the first command to list IMSI + Context Address of active sessions.
sgsn_cmd_handle could share more code with bsc variant.

Fixes: SYS#264, SYS#265
2014-03-23 18:34:58 +01:00
Holger Hans Peter Freyther 82e644b572 gbproxy: The "[stats]" option was not documented, document it
Documentation error (missing docs):
<command id='show gbproxy [stats]'>
        <param name='[stats]' doc='(null)' />
2013-11-03 17:34:17 +01:00
Jacob Erlbeck 36722e13da vty: Use vty_install_default() instead of bsc_install_default()
Remove ournode_exit_cmd, ournode_end_cmd, and bsc_install_default()
since this functionality is provided by the current libosmocore.

Replace calls to bsc_install_default() by call to
vty_install_default() with the following semantic patch:

    @rule1@
    expression N;
    @@
    - bsc_install_default(N);
    + vty_install_default(N);

Ticket: OW#952
Sponsored-by: On-Waves ehf
2013-10-30 15:19:00 +01:00
Jacob Erlbeck 64cb924634 gbproxy: Fix handling of NSEI changes
The gbproxy looses NSEI changes on BVC_RESET and then tries to send
later messages to the wrong (not longer existing) destination.

This patch fixes this by updating the peer's nsei field on BVC_RESET.

Ticket: OW#874
Sponsored-by: On-Waves ehf
2013-10-24 18:02:38 +02:00
Jacob Erlbeck 72b401f33d gbproxy: Add test for NSEI and NSVCI changes
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-24 18:02:36 +02:00
Jacob Erlbeck 4211d79cd1 gbproxy/vty: Enhance delete-gbproxy-peer command
This adds the option to delete all BVC peers and/or NS_VC with a
given NSEI with a single command. Static (configured) NS-VC are not
affected. In addition, all connections for this NSEI that can be
deleted by this command can be listed without deleting them by
appending 'dry-run' to the command.

Sponsored-by: On-Waves ehf
2013-10-24 18:02:33 +02:00
Holger Hans Peter Freyther 90267a961c gbproxy: Add a command to delete peers from the GBProxy
This just deletes the peer entry based on NSEI and BVCI. The NS-VC
are not touched.
2013-10-24 08:22:45 +02:00
Jacob Erlbeck 02ca7783ab gbproxy: Fix rate counter group leak in peer_free()
This also frees the counter group pointed to by peer->ctrg when the
peer gets freed.

Sponsored-by: On-Waves ehf
2013-10-24 08:22:45 +02:00
Jacob Erlbeck f0f63a4113 gbproxy: Reject SGSN UNITDATA messages with an invalid BVCI
Currently such messages lead to a creation of a new peer with the
SGSN's NSEI, which results in echoing the message back to the SGSN.

This patch modifies this by sending a STATUS response (invalid BVCI)
instead back to the SGSN.

Sponsored-by: On-Waves ehf
2013-10-19 12:10:24 +02:00
Jacob Erlbeck da890c7733 gbproxy: Test invalid BVCI from SGSN
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-19 12:10:21 +02:00
Jacob Erlbeck bc555742aa gbproxy: Add global and per peer counters
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-19 12:10:19 +02:00
Jacob Erlbeck c5085f9d3d gbproxy: Fix warning and log message
Add the unused attribute to peer_free() that isn't used currently.
Change 'RAC' to 'NSEI' in the log message, since the latter has been
examined before the log message is generated.

Sponsored-by: On-Waves ehf
2013-10-19 12:10:16 +02:00
Jacob Erlbeck e75fec60d0 gbproxy: Replace NS-VC references by NSEI
Currently in most places in gb_proxy.c a reference to a NS-VC object
is used where the peer is meant instead. The patch changes this by
using the NSEI instead in these cases.

Sponsored-by: On-Waves ehf
2013-10-15 15:19:29 +02:00
Jacob Erlbeck 51a869c80c gbproxy: Add test program to test gbproxy message handling
This program tests the gbproxy implementation by passing NS messages
to a modified gbproxy that dumps the resulting messages, signals, and
state.

It focusses on testing abnormal situations like port changes.

Ticket: OW#874
Sponsored-by: On-Waves ehf
2013-10-15 15:10:22 +02:00
Jacob Erlbeck 0ae92a950a vty: Use generic 'end' and 'exit' commands
Add bsc_install_default() and replace all install_default()

This patch adds bsc_install_default() which calls install_default()
and add 'exit' and 'end'. All other calls to install_default() are
replaced by calls to bsc_install_default().

Since 'exit' and 'end' are now added automatically to each node, the
explicit registrations of these commands are removed by this patch,
too.

The related tests succeed now without work-arounds (except for the
'config' node itself which is part of libosmocore).
2013-09-02 20:25:35 +02:00
Holger Hans Peter Freyther aa93bac34b gprs_gmm: Avoid assertion in the sending code during routing area update
Use old and new tlli as specified by the caller.

WIP

<000f> sgsn_libgtp.c:321 Received DELETE PDP CTX CONF, cause=128(Request accepted)
<0013> gprs_sndcp.c:320 SNSM-DEACTIVATE.ind (lle=0x8095d08, TLLI=e3ddd574, SAPI=11, NSAPI=5)
<0011> gprs_bssgp.c:376 BSSGP TLLI=0xe3ddd574 Rx UPLINK-UNITDATA
<0012> gprs_llc.c:551 LLC SAPI=1 C   FCS=0xb85a96CMD=UI DATA
<0011> gprs_bssgp.c:376 BSSGP TLLI=0xe3ddd574 Rx UPLINK-UNITDATA
<0012> gprs_llc.c:551 LLC SAPI=1 C   FCS=0xbe5a96CMD=UI DATA
<0002> gprs_gmm.c:214 Starting MM timer 3350 while old timer 3350 pending
<0012> gprs_llc.c:417 LLC TX: unknown TLLI 0xe3ddd574, creating LLME on the fly
Assert failed msgb_tlli(msg) == mmctx->llme->tlli || msgb_tlli(msg) == mmctx->llme->old_tlli || tlli_foreign2local(msgb_tlli(msg)) == mmctx->llme->tlli || tlli_foreign2local(msgb_tlli(msg)) == mmctx->llme->old_tlli gprs_llc.c:123
backtrace() returned 18 addresses
/home/ich/install/openbsc/lib/libosmocore.so.4(osmo_generate_backtrace+0x16) [0xb7bb6a36]
/home/ich/source/gsm/openbsc/openbsc/src/gprs/osmo-sgsn() [0x805224a]
/home/ich/source/gsm/openbsc/openbsc/src/gprs/osmo-sgsn() [0x804a2f6]
/home/ich/source/gsm/openbsc/openbsc/src/gprs/osmo-sgsn() [0x804b687]
/home/ich/source/gsm/openbsc/openbsc/src/gprs/osmo-sgsn() [0x804bc35]
/home/ich/source/gsm/openbsc/openbsc/src/gprs/osmo-sgsn() [0x804bd4e]
/home/ich/source/gsm/openbsc/openbsc/src/gprs/osmo-sgsn() [0x804d20c]
/home/ich/source/gsm/openbsc/openbsc/src/gprs/osmo-sgsn() [0x8052be4]
/home/ich/source/gsm/openbsc/openbsc/src/gprs/osmo-sgsn(bssgp_prim_cb+0x55) [0x804f5a4]
/home/ich/install/openbsc/lib/libosmogb.so.2(bssgp_rcvmsg+0x3b8) [0xb7b626b8]
/home/ich/source/gsm/openbsc/openbsc/src/gprs/osmo-sgsn() [0x804f4f1]
/home/ich/install/openbsc/lib/libosmogb.so.2(gprs_ns_rcvmsg+0x8c7) [0xb7b5ecf7]
/home/ich/install/openbsc/lib/libosmogb.so.2(+0x4311) [0xb7b5f311]
/home/ich/install/openbsc/lib/libosmocore.so.4(osmo_select_main+0x192) [0xb7bb2ed2]
/home/ich/source/gsm/openbsc/openbsc/src/gprs/osmo-sgsn() [0x804fbcd]
/lib/i386-linux-gnu/i686/cmov/libc.so.6(__libc_start_main+0xf5) [0xb796a8f5]
/home/ich/source/gsm/openbsc/openbsc/src/gprs/osmo-sgsn() [0x8049db1]

Program received signal SIGABRT, Aborted.
0xb7fde424 in __kernel_vsyscall ()
(gdb) bt
 #0  0xb7fde424 in __kernel_vsyscall ()
 #1  0xb797f83f in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56
 #2  0xb7982cf3 in __GI_abort () at abort.c:90
 #3  0x0805224f in _bssgp_tx_dl_ud (mmctx=0x80932d0, msg=0x80963a8) at gprs_llc.c:120
 #4  gprs_llc_tx_ui (msg=0x80963a8, sapi=1 '\001', command=0, mmctx=0x80932d0)
    at gprs_llc.c:496
 #5  0x0804a2f6 in gsm48_gmm_sendmsg (msg=0x80963a8, command=0, mm=0x80932d0) at gprs_gmm.c:241
 #6  0x0804b687 in gsm48_tx_gmm_ra_upd_ack (mm=0x80932d0) at gprs_gmm.c:851
 #7  0x0804bc35 in gsm48_rx_gmm_ra_upd_req (mmctx=0x80932d0, msg=0x8091ce8, llme=0x8095630)
    at gprs_gmm.c:1004
 #8  0x0804bd4e in gsm0408_rcv_gmm (mmctx=0x80932d0, msg=0x8091ce8, llme=0x8095630)
    at gprs_gmm.c:1036
 #9  0x0804d20c in gsm0408_gprs_rcvmsg (msg=msg@entry=0x8091ce8, llme=0x8095630)
    at gprs_gmm.c:1566
 #10 0x08052be4 in gprs_llc_rcvmsg (msg=0x8091ce8, tv=0xbfffdcb0) at gprs_llc.c:882
 #11 0x0804f5a4 in bssgp_prim_cb (oph=oph@entry=0xbfffdc8c, ctx=ctx@entry=0x0)
    at sgsn_main.c:114
 #12 0xb7b626b8 in bssgp_rx_ul_ud (tp=0xbfffdcb0, msg=0x8091ce8, ctx=<optimized out>)
    at gprs_bssgp.c:398
 #13 bssgp_rx_ptp (bctx=0x8091a08, tp=0xbfffdcb0, msg=0x8091ce8) at gprs_bssgp.c:820
 #14 bssgp_rcvmsg (msg=0x8091ce8) at gprs_bssgp.c:1016
 #15 0x0804f4f1 in sgsn_ns_cb (event=GPRS_NS_EVT_UNIT_DATA, nsvc=0x8090740, msg=0x8091ce8,
    bvci=1801) at sgsn_main.c:92
 #16 0xb7b5ecf7 in gprs_ns_rx_unitdata (msg=0x8091ce8, nsvc=0x8090740) at gprs_ns.c:616
 #17 gprs_ns_rcvmsg (nsi=nsi@entry=0x807fd38, msg=msg@entry=0x8091ce8,
    saddr=saddr@entry=0xbfffedc0, ll=ll@entry=GPRS_NS_LL_UDP) at gprs_ns.c:841
 #18 0xb7b5f311 in handle_nsip_read (bfd=0x807fd58) at gprs_ns.c:991
 #19 nsip_fd_cb (bfd=0x807fd58, what=1) at gprs_ns.c:1024
 #20 0xb7bb2ed2 in osmo_select_main (polling=0) at select.c:158
 #21 0x0804fbcd in main (argc=3, argv=0xbffff234) at sgsn_main.c:369
(gdb) frame 5
 #5  0x0804a2f6 in gsm48_gmm_sendmsg (msg=0x80963a8, command=0, mm=0x80932d0) at gprs_gmm.c:241
241		return gprs_llc_tx_ui(msg, GPRS_SAPI_GMM, command, mm);
(gdb) p msgb_tlli(msg)
$1 = 3822966132
(gdb) frame 4
 #4  gprs_llc_tx_ui (msg=0x80963a8, sapi=1 '\001', command=0, mmctx=0x80932d0)
    at gprs_llc.c:496
496		return _bssgp_tx_dl_ud(msg, mmctx);
(gdb) p mmctx
$2 = (void *) 0x80932d0
(gdb) frame 3
 #3  0x0805224f in _bssgp_tx_dl_ud (mmctx=0x80932d0, msg=0x80963a8) at gprs_llc.c:120
120			OSMO_ASSERT(msgb_tlli(msg) == mmctx->llme->tlli
(gdb) p mmctx
$3 = (struct sgsn_mm_ctx *) 0x80932d0
(gdb) p *mmctx
$4 = {list = {next = 0x8092e28, prev = 0x805c318 <sgsn_mm_ctxts>},
  imsi = "901700000003094\000", mm_state = GMM_REGISTERED_NORMAL, p_tmsi = 296043751,
  p_tmsi_old = 2075232571, p_tmsi_sig = 0, imei = "353943044782210\000",
  msisdn = '\000' <repeats 14 times>, ra = {mnc = 70, mcc = 901, lac = 1, rac = 0 '\000'},
  cell_id = 0, cell_id_age = 0, sac = 0, sac_age = 0, new_sgsn_addr = 0,
  ciph_algo = GPRS_ALGO_GEA0, ms_radio_access_capa = {len = 11 '\v',
    buf = "4\307\003*\240B|\255\341\030\v", '\000' <repeats 38 times>}, ms_network_capa = {
    len = 2 '\002', buf = "\345\200\000\000\000\000\000"}, drx_parms = 3329, mnrg = 0,
  ngaf = 0, ppf = 0, recovery = 0, radio_prio_sms = 0 '\000', pdp_list = {next = 0x8093390,
    prev = 0x8093390}, llme = 0x8095630, tlli = 3822966132, tlli_new = 3517269223,
  nsei = 1801, bvci = 1801, ctrg = 0x8096048, timer = {node = {rb_parent_color = 3082574944,
      rb_right = 0x0, rb_left = 0x0}, list = {next = 0x80933b8, prev = 0x80933b8}, timeout = {
      tv_sec = 1375260414, tv_usec = 864196}, active = 1, cb = 0x804bfd0 <mmctx_timer_cb>,
    data = 0x80932d0}, T = 3350, num_T_exp = 0, t3350_mode = GMM_T3350_MODE_RAU,
  t3370_id_type = 1 '\001'}
(gdb) p msgb_tlli(msg)
No symbol "msgb_tlli" in current context.
(gdb) frame 5
 #5  0x0804a2f6 in gsm48_gmm_sendmsg (msg=0x80963a8, command=0, mm=0x80932d0) at gprs_gmm.c:241
241		return gprs_llc_tx_ui(msg, GPRS_SAPI_GMM, command, mm);
(gdb) frame 6
 #6  0x0804b687 in gsm48_tx_gmm_ra_upd_ack (mm=0x80932d0) at gprs_gmm.c:851
851		return gsm48_gmm_sendmsg(msg, 0, mm);
(gdb) p msgb_tlli(msg)
$5 = 3822966132
(gdb) p mmctx->tlli
No symbol "mmctx" in current context.
(gdb) p mm->tlli
$6 = 3822966132
(gdb) p mm->tlli_new
$7 = 3517269223
(gdb) p mm->llme->tlli
$8 = 3517269223
(gdb) p mm->llme->tlli_old
There is no member named tlli_old.
(gdb) p mm->llme->old_tlli
$9 = 4222716219
(gdb) bt
 #0  0xb7fde424 in __kernel_vsyscall ()
 #1  0xb797f83f in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56
 #2  0xb7982cf3 in __GI_abort () at abort.c:90
 #3  0x0805224f in _bssgp_tx_dl_ud (mmctx=0x80932d0, msg=0x80963a8) at gprs_llc.c:120
 #4  gprs_llc_tx_ui (msg=0x80963a8, sapi=1 '\001', command=0, mmctx=0x80932d0)
    at gprs_llc.c:496
 #5  0x0804a2f6 in gsm48_gmm_sendmsg (msg=0x80963a8, command=0, mm=0x80932d0) at gprs_gmm.c:241
 #6  0x0804b687 in gsm48_tx_gmm_ra_upd_ack (mm=0x80932d0) at gprs_gmm.c:851
 #7  0x0804bc35 in gsm48_rx_gmm_ra_upd_req (mmctx=0x80932d0, msg=0x8091ce8, llme=0x8095630)
    at gprs_gmm.c:1004
 #8  0x0804bd4e in gsm0408_rcv_gmm (mmctx=0x80932d0, msg=0x8091ce8, llme=0x8095630)
    at gprs_gmm.c:1036
 #9  0x0804d20c in gsm0408_gprs_rcvmsg (msg=msg@entry=0x8091ce8, llme=0x8095630)
    at gprs_gmm.c:1566
 #10 0x08052be4 in gprs_llc_rcvmsg (msg=0x8091ce8, tv=0xbfffdcb0) at gprs_llc.c:882
 #11 0x0804f5a4 in bssgp_prim_cb (oph=oph@entry=0xbfffdc8c, ctx=ctx@entry=0x0)
    at sgsn_main.c:114
 #12 0xb7b626b8 in bssgp_rx_ul_ud (tp=0xbfffdcb0, msg=0x8091ce8, ctx=<optimized out>)
    at gprs_bssgp.c:398
 #13 bssgp_rx_ptp (bctx=0x8091a08, tp=0xbfffdcb0, msg=0x8091ce8) at gprs_bssgp.c:820
 #14 bssgp_rcvmsg (msg=0x8091ce8) at gprs_bssgp.c:1016
 #15 0x0804f4f1 in sgsn_ns_cb (event=GPRS_NS_EVT_UNIT_DATA, nsvc=0x8090740, msg=0x8091ce8,
    bvci=1801) at sgsn_main.c:92
 #16 0xb7b5ecf7 in gprs_ns_rx_unitdata (msg=0x8091ce8, nsvc=0x8090740) at gprs_ns.c:616
 #17 gprs_ns_rcvmsg (nsi=nsi@entry=0x807fd38, msg=msg@entry=0x8091ce8,
    saddr=saddr@entry=0xbfffedc0, ll=ll@entry=GPRS_NS_LL_UDP) at gprs_ns.c:841
 #18 0xb7b5f311 in handle_nsip_read (bfd=0x807fd58) at gprs_ns.c:991
 #19 nsip_fd_cb (bfd=0x807fd58, what=1) at gprs_ns.c:1024
 #20 0xb7bb2ed2 in osmo_select_main (polling=0) at select.c:158
 #21 0x0804fbcd in main (argc=3, argv=0xbffff234) at sgsn_main.c:369
(gdb) frame 3
 #3  0x0805224f in _bssgp_tx_dl_ud (mmctx=0x80932d0, msg=0x80963a8) at gprs_llc.c:120
120			OSMO_ASSERT(msgb_tlli(msg) == mmctx->llme->tlli
(gdb) p msgb_tlli(msg)
No symbol "msgb_tlli" in current context.
(gdb) frame 4
 #4  gprs_llc_tx_ui (msg=0x80963a8, sapi=1 '\001', command=0, mmctx=0x80932d0)
    at gprs_llc.c:496
496		return _bssgp_tx_dl_ud(msg, mmctx);
(gdb) p msgb_tlli(msg)
No symbol "msgb_tlli" in current context.
(gdb) frame 5
 #5  0x0804a2f6 in gsm48_gmm_sendmsg (msg=0x80963a8, command=0, mm=0x80932d0) at gprs_gmm.c:241
241		return gprs_llc_tx_ui(msg, GPRS_SAPI_GMM, command, mm);
(gdb) p msgb_tlli(msg)
$10 = 3822966132
(gdb) p mm->tlli
$11 = 3822966132
(gdb) p mm->tlli_new
$12 = 3517269223
(gdb) p mm->tlli_new
$13 = 3517269223
(gdb) p mm->llme->tlli
$14 = 3517269223
(gdb) p mm->llme->tlli_old
There is no member named tlli_old.
(gdb) p mm->llme->old_tlli
$15 = 4222716219
(gdb) p mm->llme->state
$16 = GPRS_LLMS_ASSIGNED
(gdb) q
2013-07-31 16:12:02 +02:00
Holger Hans Peter Freyther 7e0fec17ce gprs_llc: Assert that we send frames with either tlli or old_tlli
In case we have access to the context verify that the selected
msgb_tlli is either the old_tlli or the tlli in either local or
foreign format. It is wrong to use any other TLLI.
2013-07-31 14:57:21 +02:00
Holger Hans Peter Freyther 964a9b3e20 gprs_llc: Work on finding the right LLE/LLME in case of routing area update
Attempt to solve what f0901f0067 tried to
solve without breaking the case of someone with a foreign TLLI from a
different network.

Lookup with the foreign TLLI converted to a local one in case we did
not find the TLLI and only then create a LLE/LLME on the fly for the
RX path.
2013-07-31 14:57:21 +02:00
Holger Hans Peter Freyther 012a7eec29 gprs_llc: Lookup lle based on the real TLLI
During the GPRS Attach procedure we might have a foreign tlli and
in the RX create a LLME on the fly for this tlli. The GMM GPRS
Attach handling code will then assign a new TLLI and keep the
foreign tlli as the llme->old_tlli.

When the GMM is sending the identity request the msgb_tlli will
point to the foreign tlli. The GPRS LLC code will then try to find
that foreign tlli but due the conversion this will not be found.
Instead a new ad-hoc LLE/LLME will be created on the fly for
each message (this means there are duplicate LLE/LLMEs in the
list).

Make the code more strict and remove the tlli_foreign2local change
from the look-up routine. This will make the GPRS LLC code find
the right LLE/LLME and the N(U) will be handled correctly.

This partially reverts:
  f0901f0067

Addresses:
  <0012> gprs_llc.c:773 LLC RX: unknown TLLI 0xadf11820, creating LLME on the fly
  ...
  <0012> gprs_llc.c:357 LLC TX: unknown TLLI 0xedf11820, creating LLME on the fly

Reproducable:
  Use pcu_emu (gprs attach) and observe with wireshark.
2013-07-31 14:57:21 +02:00
Holger Hans Peter Freyther 598e7b3cdf gprs_sgsn: In case of a Activate PDP Context timeout we should free pdp
In case of a failure this method didn't set the pctx->lib back to
NULL. In case of a timeout the callback will be made with pdp=NULL
and this would lead to leaking the PDP context. Check for the case
of having a pctx->lib != pdp and free it.

This resolves:
<000f> gprs_sgsn.c:259 freeing PDP context that still has a libgtp handle attached to it, this shouldn't happen!
2013-07-31 14:57:21 +02:00
Holger Hans Peter Freyther 92aa6bb9dc gprs: Fix a typo in the comment 2013-07-28 20:13:01 +02:00
Harald Welte 649e1ff4b3 sgsn: spelling fixes inside comments 2013-07-21 17:41:46 +08:00
Harald Welte 3dfb549a6f sgsn: Add "auth-policy" VTY command to enable/disable ACL 2013-07-21 15:44:28 +08:00
Harald Welte 7f6da485f5 sgsn: add a minimalistic ACL
This adds a minimalistic ACL by which certain, individual roaming IMSIs
can be authorized to use the SGSN.  So you can selectively bypass the
'MCC+MNC == first 5 digits of IMSI' checking for a couple of IMSIs
2013-07-21 15:44:24 +08:00
Holger Hans Peter Freyther aa63d70f39 sgsn: Fix the unimplemented/uninstalled show ggsn command
This is fixing a GCC and Coverity warning.

GCC:
sgsn_vty.c: At top level:
sgsn_vty.c:308:1: warning: ‘show_ggsn_cmd’ defined but not used [-Wunused-variable]

Coverity: CID 1040727
2013-07-04 18:45:31 +02:00
Holger Hans Peter Freyther 80e036560d sgsn_vty: Fix uninitialized variable in the gprs_apn2str method
This is fixing a GCC and Coverity warning:

GCC:
sgsn_vty.c: In function ‘vty_dump_pdp’:
sgsn_vty.c:64:5: warning: ‘i’ may be used uninitialized in this function [-Wmaybe-uninitialized]
sgsn_vty.c:49:15: note: ‘i’ was declared here

Coverity: CID 1040706
2013-07-04 18:44:16 +02:00
Holger Hans Peter Freyther 3a708afe63 sgsn: Fix logically dead code in regard to the osmo_fd_register
The code was written like checking the return value of the
osmo_fd_register but the rc variable was not assigned for the
subsequent calls.

Fixes: Coverity CID 1040741
2013-07-04 18:39:52 +02:00
Alexander Chemeris 84402c0c82 sgsn: Fix lengths of MS Network Capability and MS Radio Access Capability elements.
Original code was inconsistent about lengths and could lead to out
of bounds write. Lengths were also inconsistent with the TS 24.008.

Fixes: Coverity CID 1040714.
2013-07-04 18:34:49 +02:00
Harald Welte abadd54346 GPRS LLC: Add non-standard method of sequence number recovery
In some situations (like MS reboot without prior DETACH or SGSN reboot
without prior MS detach), the LLC sequence numbers for UI mode could
be different on both sides.

The LLC spec unfortunately doesn't permit us to send something like a
FRMR in this case, but instructs us to silently discard the frame.  At
that time the remote LLC entity will re-transmit the frame with the same
seqeunce number over and over again, which we will drop again and again.

The mthod used now will keep track of the last received UI sequence
number.  If that number is retransmitted for three times in a row, then
we accept this sequence number and recover from that point on.
2013-06-21 14:06:18 +02:00
Alexander Huemer a1c09a401d Makefile.am: Use AM_CPPFLAGS
Since automake 1.13 INCLUDES is depricates and causes a warning
2013-06-12 09:16:27 +02:00
Holger Hans Peter Freyther c751cf92cb misc: Fix compilation now that the method is located in libosmocore
These TLV helper functions are now located in libosmocore.
2012-12-19 16:18:44 +01:00
Holger Hans Peter Freyther eff4094950 sms: Use the DLSMS instead of the DSMS category throughout our code 2012-11-21 21:33:03 +01:00
Holger Hans Peter Freyther ffd6856249 gbproxy: Address two unaligned memory access warnings
The lines 461 and 303 were producing unaligned memory access as
the BVCI was not aligned properly. Introduce a tlvp_val16_unal to
read 16bit from the data, use memcpy to the stack to make sure
that it is working in the aligned and unaligned case.
2012-09-11 16:23:31 +02:00
Harald Welte 570ce24deb VTY: improve VTY prompt and make sure exit/end works everywhere
Some nodes below 'config' didn't have ournode_exit / ournode_end,
and thus were not able to properly perform this function.  exit should
always only go back one level, while end drops us back to ENABLE_NODE.

The prompt now represents the nesting level, and there's one consistent
space after the final prompt character (typically #).
2012-08-17 13:16:10 +02:00
Holger Hans Peter Freyther 9b5db287c6 gb: suspend_ref was changed to a plain uint8_t, update the code
Require a 0.5.2+ libosmogb due the change of the suspend_ref type.
2012-08-03 10:08:32 +02:00
Holger Hans Peter Freyther d028807658 misc: Introduce a script tha generates the VTY reference
Update/Move/Create example configuration files for NiTB, BSC,
MGCP, NAT and the GbProxy. Create a script that starts, generates
the vty reference and terminates the application.
2012-07-28 15:30:09 +02:00
Harald Welte fdf453c0a9 SGSN: Code to help debug / fix sgsn crash in cb_data_ind()
A crash was obsserved in cb_data_ind() when mm is dereferenced.

This patch adds some safeguards that try to prevent the library handle
back-pointer to the pdp_ctx to be NULL, and print a stack backtrace in
case we are free() ing the sgsn-side pdp_ctx while there's still a
library handle attached.
2012-07-14 12:18:28 +02:00
Harald Welte 7b022eed2d add some comments regarding the free() / release of pdp contextx
It might be that we're deleting structures instead of properly cleaning
up the attached libgtp handles...
2012-07-14 12:17:42 +02:00
Harald Welte 8c00496e42 GPRS LLC: fix segfault when transmitting downlink unit-data without mmctx 2012-07-04 21:53:12 +02:00
Harald Welte edcba4e307 use new external libosmogb (part of libosmocore.git)
This removes the libgb (GPRS NS/BSSGP) code from the openbsc.git
repository and uses the new version from libosmocore.git instead.
2012-06-17 23:34:34 +08:00
Harald Welte ce95b27b68 libgb: make sure all BSSGP functions have bssgp_ prefix
We change the minority of functions employing the gprs_bssgp_ prefix to
match with the majority without gprs_ in front.
2012-06-17 13:05:48 +08:00
Harald Welte 11461a6457 libgb/gprs: don't use log_info from libcommon anymore 2012-06-17 12:58:46 +08:00
Harald Welte e6599ee180 libgb: prefix all NS related functions with gprs_ 2012-06-17 12:38:07 +08:00
Harald Welte b1fd9022eb libgb: don't call directly into GMM / LLC layer
Instead of direct function calls to individual functions, we now
generate primitives (osmo_prim) and send them to one
application-provided function "bssgp_prim_cb()"
2012-06-17 12:17:22 +08:00
Harald Welte faa70ff2c6 libgb: remove dependency of BSSGP to include sgsn/gmm internal structs 2012-06-17 09:31:16 +08:00
Harald Welte 68d85d5610 libgb: Remove dependency to openbsc/debug.h 2012-06-16 17:53:38 +08:00
Harald Welte fdd8b3b40d libgb: remove dependencies to openbsc/vty.h and openbsc/gsm_data.h
Rather than using openbsc internal data/functions, we now use only
internal and libosmocore-provided ones.
2012-06-16 16:59:50 +08:00
Harald Welte a6a20b4ff6 libgb: Use library SS_L_NS instead lf local SS_NS
which removes some further dependencies of libgb to openbsc internal
code and data.
2012-06-16 16:40:42 +08:00
Harald Welte 8645e101da libgb: move GPRS specific msgb CB definitions to separate header 2012-06-16 16:09:52 +08:00
Harald Welte ea34a4e3a7 split libgb into a separate library for outside use
This also removes the dependency to osmo_sock() inside libcommon and
replaces it with osmo_sock_* from libosmocore
2012-06-16 15:14:00 +08:00
Holger Hans Peter Freyther a8ddb08e05 misc: Use msgb_free for freeing the messages 2012-03-01 20:30:32 +01:00
Holger Hans Peter Freyther 794e8f2649 abis: gsm_data_shared.h includes libosmo-abis header, add abis to cflags
gsm_data_shared.h includes e1_input.h of libosmo-abis, add the
LIBOSMOABIS_CFLAGS to Makefile.am, remove AM_LDFLAGS at the same
time as we only build .a archives.
2012-01-15 17:52:02 +01:00
Holger Hans Peter Freyther faf1f64a2d gprs: Honor GSM 04.64 8.4.2 Receipt of unacknowledged information
GSM 04.64 8.4.2 asks to ignore UI frames if the DLCI is not known,
or if the "(V(UR)- 32) <= N(U) < V(UR)". E.g. if we want to have
V(UR) == 511 and this frame is dropped, we would ignore N(U)'s
0 to 510. Calculate the delta.

The code is based on Jonathan Santos's "LLC UI window" fix but the
issue was discovered independly.
2012-01-06 18:52:05 +01:00
Holger Hans Peter Freyther 1491f2e7a9 sgsn: Make sure each parameter has some sort of documentation 2011-11-06 21:41:51 +01:00
Holger Hans Peter Freyther 2eb6e2c0ad gb_proxy: Make sure each parameter has some sort of documentation 2011-11-06 21:41:51 +01:00
Harald Welte d4c6f8b343 GPRS GMM: When we receive a RA UPD REQ, we are NORMAL even after SUSPEND
There is no explicit BSSGP RESUME in case the MS sends a RA UPD REQ
after being in SUSPEND previously.
2011-10-16 21:35:21 +02:00
Harald Welte 066a0f5c0b GPRS LLC: fix compiler warning 2011-10-16 18:59:20 +02:00
Harald Welte 2b697a6671 GPRS GMM: Send LLGMM-RESET.req when talking to unknown MS
In case a MS (of which we have no MM context) sends us anything but a
GMM ATTACH REQUEST, we need to send it a LLC XID RESET (by means of
issuing LLGMM-RESET.req).  Otherwise the phone will expect us to send a
specific unacknowledged sequence number that we don't know.

Thanks to Holger for pointing this bug out to me.

It seems to commonly occur when a MS is doing network re-selection and
(erroneously) sends a RA UPD REQ instead of an ATTACH REQ.  The RA UPD
REJ that we sent was never seen by the GMM entity in the MS, as the LLC
entity discarded it due to sequence number mis-match.
2011-10-16 18:58:30 +02:00
Harald Welte 0c1a30312d LLC: Add minimal LLGMM-RESET.req implementation
Using LLGMM-RESET.req, the GMM can request the LLC of the MS to reset
all its parameters, particularly the sequence numbers.  We don't yet do
XID RESET retransmissions, and we don't yet generate a LLGMM-RESET.conf
primitive back to GMM.
2011-10-16 18:58:30 +02:00
Holger Hans Peter Freyther 37a63ca34a misc: Linking fixes for Ubuntu 11.10 Compiler
Ubuntu 11.10 has changed some linker/compiler flags. Some fixes for this
can be seen here[1]. In general the to be linked libs need to be moved into
the LDADD section of parameters. This is with the old BFD linker (not gold).

This is likely to end in some ping-pong with other versions of the linker.

[1] https://bugs.launchpad.net/ubuntu/+source/nis/+bug/771034

Errors:
/usr/bin/ld.bfd.real: bsc_hack.o: undefined reference to symbol 'osmo_init_ignore_signals'
/usr/bin/ld.bfd.real: note: 'osmo_init_ignore_signals' is defined in DSO /home/ich/install/openbsc/lib/libosmocore.so so try adding it to the linker command line
/home/ich/install/openbsc/lib/libosmocore.so: could not read symbols: Invalid operation

...
../../src/libbsc/libbsc.a(rest_octets.o):/home/ich/source/gsm/openbsc/openbsc/src/libbsc/rest_octets.c:381: more undefined references to `bitvec_set_bit' follow
../../src/libbsc/libbsc.a(rest_octets.o): In function `rest_octets_si13':
/home/ich/source/gsm/openbsc/openbsc/src/libbsc/rest_octets.c:382: undefined reference to `bitvec_set_uint'
/home/ich/source/gsm/openbsc/openbsc/src/libbsc/rest_octets.c:383: undefined reference to `bitvec_set_uint'
/home/ich/source/gsm/openbsc/openbsc/src/libbsc/rest_octets.c:385: undefined reference to `bitvec_set_bit'
/home/ich/source/gsm/openbsc/openbsc/src/libbsc/rest_octets.c:402: undefined reference to `bitvec_set_bit'
/home/ich/source/gsm/openbsc/openbsc/src/libbsc/rest_octets.c:403: undefined reference to `bitvec_set_uint'
2011-10-16 17:08:51 +02:00
Holger Hans Peter Freyther 3dccda5ef0 gprs: Fix various compiler warnings 2011-10-14 23:42:13 +02:00
Holger Hans Peter Freyther 6142dc407a gprs: Fix compiler warnings in the code 2011-10-14 23:37:27 +02:00
Holger Hans Peter Freyther 2b17454f4a gprs_gmm: Fix various compiler warnings
gprs_gmm.c:240:2: warning: passing argument 4 of ‘gprs_llc_tx_ui’ discards qualifiers from pointer target type
../../include/openbsc/gprs_llc.h:151:5: note: expected ‘void *’ but argument is of type ‘const struct sgsn_mm_ctx *’
gprs_gmm.c:349:11: warning: unused variable ‘ptsig’
gprs_gmm.c:601:5: warning: too many arguments for format
gprs_gmm.c:987:25: warning: initialization discards qualifiers from pointer target type
gprs_gmm.c:1010:6: warning: ‘rc’ may be used uninitialized in this function
2011-10-14 23:31:34 +02:00
Pablo Neira Ayuso ed5cacb240 src: port openBSC over libosmo-abis
This is a big patch that ports openBSC over libosmo-abis.
Sorry, the changes that are included here are all dependent
of libosmo-abis, splitting them into smaller pieces would
leave the repository in some intermediate state, which is
not desired.

The main changes are:

- The directory libabis/ has been removed as it now lives in
  libosmo-abis.

- new configuration file format for nanoBTS and HSL femto, we
  need to define the virtual e1_line and attach it to the OML
  link.

- all the existing BTS drivers (nanoBTS, hsl femto, Nokia site,
  BS11 and rbs2000) now use the new libosmo-abis framework.

- use r232 input driver available in libosmo-abis for bs11_config.

- use ipa_msg_recv instead of old ipaccess_read_msg function.

- delete definition of gsm_e1_subslot and input_signal_data.
  These structures now lives in libosmo-abis.

Most of this patch are deletions of libabis/ which has been
moved to libosmo-abis.

This patch also modifies openBSC to use all the new definitions
available in libosmocore and libosmo-abis. In order to do that,
we have replaced the following:

- DINP, DMI, DMIB and DMUX by their respective DL* correspondences.
- SS_GLOBAL by SS_L_GLOBAL
- SS_INPUT by SS_L_INPUT
- S_GLOBAL_SHUTDOWN by S_L_GLOBAL_SHUTDOWN
- SS_INPUT by SS_L_INPUT
- S_INP_* by S_L_INP_* sub-signals
- E1INP_NODE by L_E1INP_NODE vty node

This patch has been tested with:
- one nanoBTS
- the HSL femto with the examples available under libosmo-abis
- BS11 with both dahdi and misdn drivers.
2011-08-19 22:38:35 +02:00
Harald Welte cdf76cff9f GPRS: Fix the parsing/interpretation of the PDP CTX status IE
The byte ordering is a bit odd:  The least significant byte is ahead of
the most significant byte, different from everything else in GSM that
seems to be big-endian.

Thanks to Seungju Kim <admin@manateeshome.com> for repoerting the bug.
2011-08-05 21:23:46 +02:00
Dieter Spaar 1f447fbef1 LLC: Fix format string 2011-07-27 23:38:46 +02:00
Harald Welte 4b2ed35b8f GPRS: Fix buffer overflow in case of very long MS RA CAP IE
The MS Radio Access Capability IE can be _very_ long in some recent
high-end mobile phones, way beyond the old 14-byte limit.  We increase
our array to 52 bytes, and make sure not to overflow that buffer.
2011-07-27 23:35:38 +02:00
Holger Hans Peter Freyther 95fd72b9f7 misc: Remove the osmocom/core/process.h include
The osmo_daemonize moved from process.h to application.h (that
is already included), remove the process.h include.
2011-07-18 10:40:13 +02:00
Harald Welte 74902c5435 sgsn_libgtp: remove bogus unreached second return statement
found by Smatch
2011-07-16 13:47:37 +02:00
Harald Welte baf7700429 sgsn_main: add comment about exit statement never reached 2011-07-16 13:47:01 +02:00
Harald Welte f6b606f422 gprs_gmm: ctx cannot be null, so remove check
Detected by Smatch:
/home/laforge/projects/git/openbsc/openbsc/src/gprs/gprs_gmm.c +757 gsm48_rx_gmm_att_req(133) warn: variable dereferenced before check 'ctx'
2011-07-16 13:45:57 +02:00
Holger Hans Peter Freyther 67cd75f9fa misc: Use the osmo_init code for signals and logging
Use the libosmocore code to ignore certain signals by
default (e.g. SIGHUP, SIGPIPE) and use the new code to
create a default stderr logging target and initialize
it properly.
2011-05-12 16:11:14 +02:00
Pablo Neira Ayuso c0d17f2266 src: use namespace prefix osmo_* for misc utils
Summary of changes:

s/bcd2char/osmo_bcd2char/g
s/char2bcd/osmo_char2bcd/g
s/hexparse/osmo_hexparse/g
s/hexdump/osmo_hexdump/g
s/hexdump_nospc/osmo_hexdump_nospc/g
s/ubit_dump/osmo_ubit_dump/g
s/static_assert/osmo_static_assert/g
2011-05-07 12:58:59 +02:00
Pablo Neira Ayuso bbc5b99a6b src: use namespace prefix osmo_signal*
Summary of changes:

s/signal_cbfn/osmo_signal_cbfn/g
s/register_signal_handler/osmo_signal_register_handler/g
s/unregister_signal_handler/osmo_signal_unregister_handler/g
s/dispatch_signal/osmo_signal_dispatch/g
2011-05-06 12:12:31 +02:00
Pablo Neira Ayuso 4db9299286 src: use namespace prefix osmo_fd* and osmo_select*
Summary of changes:

s/struct bsc_fd/struct osmo_fd/g
s/bsc_register_fd/osmo_fd_register/g
s/bsc_unregister_fd/osmo_fd_unregister/g
s/bsc_select_main/osmo_select_main/g
2011-05-06 12:11:23 +02:00
Pablo Neira Ayuso bf540cb7c3 src: use namespace prefix osmo_timer* for timer functions
Summary of changes:

s/struct timer_list/struct osmo_timer_list/g
s/bsc_add_timer/osmo_timer_add/g
s/bsc_schedule_timer/osmo_timer_schedule/g
s/bsc_del_timer/osmo_timer_del/g
s/bsc_timer_pending/osmo_timer_pending/g
s/bsc_nearest_timer/osmo_timers_nearest/g
s/bsc_prepare_timers/osmo_timers_prepare/g
s/bsc_update_timers/osmo_timers_update/g
s/bsc_timer_check/osmo_timers_check/g
2011-05-06 12:11:06 +02:00
Holger Hans Peter Freyther a8a09df6a6 misc: Remove sys/types.h includes from the files
These are not needed any more. We used them for u_int
types but we now use uint which comes from stdint.h
2011-04-18 17:31:39 +02:00
Holger Hans Peter Freyther c42ad8b686 misc: Move from u_int to uint types of stdint.h
This was done with sed on the files.
2011-04-18 17:31:39 +02:00
Pablo Neira Ayuso 6110a3f3fa src: include new file osmocom/vty/misc.h for vty_out_rate_ctr_group()
This uses the new include file for vty_out_rate_ctr_group() which
available in libosmocore.
2011-03-28 20:01:03 +02:00
Harald Welte d36ff76f9d Fix build of bsc-nat and GPRS code after include path change
The last patch changed the osmocore include paths, this fixes some build
problems caused by it
2011-03-23 18:33:26 +01:00
Pablo Neira Ayuso 136f453dd2 src: use new library libosmogsm and new path to headers in libosmocore
libosmogsm is a new library that is distributed in the libosmocore.
Now, openbsc depends on it. This patch gets openbsc with this
change.

This patch also rewrites all include path to the new
osmocom/[gsm|core]

Signed-off-by: Pablo Neira Ayuso <pablo@gnumonks.org>
2011-03-23 18:17:56 +01:00
Pablo Neira Ayuso 3848770669 src: fix use of logging_vty_add_cmds() without log_info parameter
This patch fixes:

  CC     gb_proxy_main.o
gb_proxy_main.c: In function ‘main’:
gb_proxy_main.c:224: warning: implicit declaration of function ‘logging_vty_add_cmds’

And a similar problem in osmo-bsc_nat.

This was introduced in by myself in patch:
"bsc: change bsc_vty_init to take logging categories as parameter"

Signed-off-by: Pablo Neira Ayuso <pablo@gnumonks.org>
2011-03-23 09:04:10 +01:00
Harald Welte 89579b4317 prefix sub-directories containing libraries with 'lib'
... and make sure tests work again after restructuring
2011-03-04 13:23:09 +01:00
Harald Welte e5e36af8ae Move 'Gb' protocol stack into its own src/gb subdirectory 2011-03-03 23:45:28 +01:00
Harald Welte 31c00f7d6f re-structure the OpenBSC directory layout
The new structure divides the code into a number of libraries
for the BSC core functionality, MSC core functionality, Abis transport,
TRAU and other bits.

This doesn't introduce any functional code change but simply moves
around files and alters Makefile.am accordingly.

Next step would be to disentangle a lot of the inter-library
dependencies and make the individual bits of code more independent.
2011-03-03 23:29:05 +01:00
Harald Welte ec1921dfa3 Use shorter vty_app_info->name for all apps
... as this is now used as SYSLOG ident
2011-02-24 23:57:06 +01:00
Harald Welte 5ec26fe983 Install programs into $(prefix)/bin, not /sbin
At least in many configurations, there is no need to run any
of our programs as root.  Thus, we shouldn't install them in sbin.
2011-02-19 16:19:19 +09:00
Harald Welte 8dcebd3e7f LOGGING: make sure to make the 'logging filter' compatible with vty log cfg
Recent libosmocore introdues a way how log targets can be configured from
the VTY.

This commit makes the 'log filter (imsi|nsvc|bvc)' compatible with it.
2011-02-18 21:10:05 +01:00
Harald Welte f3956cbb20 [gb_proxy] vty: display the BVC BLOCKED status in 'show gbproxy' 2011-02-06 17:44:14 +01:00
Harald Welte fb9e06f310 [gb_proxy] make sure bssgp cell id is copied correctly
When we copy a msgb, we need to make sure the msgb_cb->bssgp_cell_id
pointer points to data in the new message, not in the old message.

Thanks to Dieter Spaar for spotting this.
2011-02-06 17:17:05 +01:00
Harald Welte c471d3d8a2 [gb proxy] treat BVCI=1 consistently like signalling
1 is reserved for point-to-multipoint data, i.e. not a point-to-point BVCI.
2011-02-06 17:13:12 +01:00
Harald Welte 5e106d7765 [gb_proxy] Convert a NS-BLOCK from BSS into BVC-RESET to SGSN
As we only have one NS-VC between gb_proxy and SGSN, we cannot
forward a NS-BLOCK from the BSS to the SGSN, as it would affect
all other BSS's, too.

Thus, we check if we have an unblocked PTP-BVC in the NSVC to the BSS,
and then issue a BVC-BLOCK towards the SGSN.

This should prevent any further PDU's from the SGSN to be sent to
this BSS.
2011-02-06 16:33:29 +01:00
Harald Welte 36f98d9c53 [gb_proxy] Track the state of blocked/unblocked BVC in the proxy
This allows us to reject any additional messages sent by the SGSN
after the BVC was blocked (+ acknowledged to be blocked)
2011-02-06 13:09:29 +01:00
Harald Welte 7bbaefb349 update gitignore 2011-01-14 14:38:42 +01:00
Harald Welte f0901f0067 [SGSN] Fix processing of RA Update Request regarding TLLI
In case we get a RA UPD REQ on a new cell (both served by the same
SGSN), the LLC stack should not allocate a ne LLE/LLME, as the latter
would reset the V(u)sent / V(u)recv to zero and make the MS discard
our responses.

Instead, whenever the LLC stack sees a foreign TLLI, it should always
convert it to the local TLLI before doing any lookup for a LLE/LLME.
2011-01-01 17:28:29 +01:00
Harald Welte 9af6ddfcec License change: We are now AGPLv3+ instead of GPLv2+
The reason for this is quite simple: We want to make sure anyone
running a customized version of OpenBSC to operate a network will
have to release all custom modifiations to the source code.
2011-01-01 15:39:34 +01:00
Harald Welte c728eeaf9b SGSN: Avoid duplicate MM contexts in case MS and SGSN disagree on P-TMSI 2010-12-26 19:20:07 +01:00
Harald Welte a9b473a3c2 SGSN: Implement network-initiated PDP CTX DEACT when GGSN restarts
If the GGSN restarts, its restart counter will increase.  We can
detect that and accordingly release/delete all PDP contexts for
that GGSN.
2010-12-26 19:20:03 +01:00
Harald Welte 3357add225 SGSN: some more comments 2010-12-26 19:19:56 +01:00
Harald Welte eafe22ca72 SGSN / GMM: Only allow non-roaming IMSIs
As we do not yet use the HLR from the SGSN, we allow all MS to
attach to our GPRS network.  However, if this is running in a public
environment, it could cause service interruption to users of commercial
GPRS networks.

Thus, we now check if the first 5 digits of the IMSI match the MCC/MNC
of the cell that they want to register to.  Thus, any subscribers with
SIM cards from real operators will no longer be accepted.
2010-12-24 15:42:26 +01:00
Harald Welte f6bd340df6 GPRS/GMM: Correctly look up MM Context in RA Update
If a MS changes RA, the RA will arrive in the new cell using the old
TLLI (masked as foreign TLLI).  So we need to look-up the TLLI
in a special way, using the old RA as indicated in the 04.08 GMM
message.

There is still another bug remaining: As we somehow create a new LLC,
the sequence numbers of our responses start from 0 again, which is not
what the MS expects.  This needs to be fixed in a follow-up patch.
2010-12-23 23:38:02 +01:00
Dieter Spaar df30d40b98 Add mandatory routeing area IE to SUSPEND-NACK 2010-12-12 15:46:00 +01:00
Holger Hans Peter Freyther ecd94a4b45 misc: Introduce a --enable-coverage mode to build with gprof coverage
This adds a test coverage build. One can use gcov and lcov on the
resulting data afterwards to see which code paths were executed and
which were not.
2010-11-15 20:06:45 +01:00
Holger Hans Peter Freyther 85531cc60d misc: Once again go from "On Waves" to "On-Waves"..
Try to get the company name of our sponsor right...
2010-10-06 20:38:36 +08:00
Holger Hans Peter Freyther 5f54075a8b vty: Use \r\n in the copyright messages
We should use VTY_NEWLINE but our strings are static, always
use \r\n as unix terminals can handle that as well.
2010-09-11 13:32:30 +08:00
Holger Hans Peter Freyther 81506b4095 vty: Add the config node code to everyone. 2010-09-04 11:00:01 +08:00
Harald Welte 9ae28a128a [gprs] Add option parsing to SGSN 2010-08-27 09:26:44 +02:00
Harald Welte 2c869efcd3 Introduce '-D' commandline option to daemonize processes
This uses the osmo_daemonize() function of libosmocore >= 0.1.18,
and is now implemented for bac_nat, osmo-bsc, bsc_hack, osmo-gbproxy
and bsc_mgcp.  This means only osmo-sgsn is missing, which currently
has no option parsing at all.
2010-08-25 19:43:54 +02:00
Harald Welte 2a90a25c93 Add gprs_sndcp.h to noinst_HEADERS 2010-08-24 13:59:08 +02:00
Harald Welte c1fa794ed5 [GPRS NS] Fix memory leak in gprs_ns_sendmsg() error path
When gprs_ns_sendmsg() succeeds in sending the message, we free()d the
msgb after transmitting it on the socket.  However, if the NS-VC is
blocked or some other error condition exists, we returned an error
code but didn't free the msgb.

This resulted in an error leak which is now being addressed.
2010-08-09 21:15:40 +08:00
Harald Welte d30e087521 [gprs] BSSGP: Fix null pointer dereference
Zecke has found this using "make CC="clang --analyze"
2010-07-23 22:00:45 +02:00
Sylvain Munaut 6f3850fcac gprs/llc: Don't check FCS in gprs_llc_hdr_dump
The FCS isn't computed yet (because of ciphering).

It _will_ be tested and reported as wrong later in the code
so we can just display it here and let the latter code report the
error if any.

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
2010-07-03 22:24:13 +02:00
Harald Welte c48ac4750d [SGSN] Some IEs in ATTACH REQUEST can be longer in 24.008
The original length checks were based on 04.08, but 24.008 allows
longer IEs.
2010-07-03 21:20:06 +02:00
Harald Welte 4b6ac1edb9 [SGSN] Initial work on GMM authentication and ciphering 2010-07-03 11:09:06 +02:00
Harald Welte 3e2e159707 [SGSN] LLC: only copy Kc if algorithm != GPRS_ALGO_GEA0
The caller currently has set the Kc pointer to NULL, this fix avoids
crashing at the callee.
2010-07-02 22:56:55 +02:00
Harald Welte d6f582b352 [SGSN] use GPRS_ALGO_GEA0 instead of '0' 2010-07-02 22:56:55 +02:00
Harald Welte 1b8827ae5b [SGSN] LLC: Make sure we calculate FCS after decryption 2010-07-02 22:55:39 +02:00
Harald Welte d07b4f99ce [SGSN] Use libosmocore GPRS encryption plugins from LLC layer
This adds the bits that call into libosmocore (and its plugins)
to implement GPRS (LLC) encryption.
2010-07-02 22:55:39 +02:00
Harald Welte 496aee463f [SGSN] Call libosmocore helper to load cipher plugins 2010-07-02 22:54:55 +02:00
Harald Welte 6ed4950d5b [SGSN] remove bogus debug statement 2010-07-02 22:52:33 +02:00
Harald Welte 23c13760ca [SGSN] SM: Properly parse APN and PCO Optional IE in PDP CTX ACT REQ 2010-07-02 22:52:04 +02:00
Harald Welte c5d4a0ced1 [SGSN] Print AP name and PDP address of each PDP context 2010-07-02 22:51:16 +02:00
Harald Welte 6add7c2009 [SGSN] Correctly pass IMSI of MM ctx to GTP/GGSN 2010-07-02 22:47:39 +02:00
Harald Welte 3d6815abd1 [SGSN] SNDCP: Subtract SNDCP header from fragment length
We don't want to store too many bytes as we would otherwise create
too large re-assembled packets..
2010-07-02 17:16:07 +02:00
Harald Welte 36f1217f32 [SGSN] SNDCP: SN-PDUs need a 16bit length field
The BSSGP LLC-PDU IE can have up ot 16bit length, so subtracting
the LLC header the SN-PDU can still have almost a length field
close to 0xffff
2010-07-02 16:44:24 +02:00
Harald Welte 8b705f2533 [SGSN] SNDCP: re-set total number of fragment length 2010-07-02 16:18:59 +02:00
Harald Welte 18d1452a92 [SGSN] Send poper SM and GMM STATUS in case we have no MM CTX 2010-07-02 16:18:18 +02:00
Harald Welte ab4094ca6b [SNDCP] some more defragmentation debug statements 2010-07-02 16:01:47 +02:00
Harald Welte 60da7d4f88 [SGSN] SNDCP defrag: use correct length, don't include LLC FCS
The LLC layer tells us the PDU length, and we have to use it
in SNDCP rather than to re-calculate it if we want to avoid copying
the CRC24 into the defrag elements.
2010-07-02 15:45:12 +02:00
Harald Welte 8f0c0a3a3c [SGSN] SNDCP: Actually copy the payload data in the defrag queue entry
Prior to this patch our defragmented messages always consisted of 00-bytes
2010-07-02 10:29:06 +02:00
Harald Welte 11ff3e8ec2 [SGSN] Remove old dead code 2010-07-02 10:17:24 +02:00
Harald Welte 19f9e30eb9 [SGSN] Only increment PDP CTX ACT count after check for retransmission 2010-07-02 10:15:49 +02:00
Harald Welte b37515e86b [SGSN] Account for re-transmitted PDP CTX ACT REQ
In case our PDP CTX ACT ACK gets lost on the Gb or Um link,
the MS re-transmits the PDP CTX ACT REQ.  We have to ACK it
again instead of REJecting it..
2010-07-02 10:12:58 +02:00
Harald Welte 993697c8d2 [SGSN] SNDCP: Fix off-by-one error missing last segment in defrag
When we defragment the segments from the defrage queue, we have
to iterate all the way up to (and including) the last segment number
that we have received.
2010-07-02 10:11:42 +02:00
Harald Welte b87bc86006 [SGSN] SNDCP: more verbose defragmentation debugging 2010-07-01 20:29:20 +02:00
Harald Welte 8911cef81d [SGSN] Fix segfault when passing re-assembled SN-PDU to GMM
sgsn_rx_sndcp_ud_ind() can no longer make the assumption that msgb_bcid() is
valid, as this is only true for an un-fragmented SN-PDU.  So instead,
we now store the RAID in the SNDCP Entity and pass it as an explicit
argument to sgsn_rx_sndcp_ud_ind().
2010-07-01 19:56:19 +02:00
Harald Welte 951a12cf4e [SGSN] SNDCP: fix off-by-one error during defragmentation 2010-07-01 15:09:45 +02:00
Harald Welte 362aea0f4d [SGSN] SNDCP: Initialize defrag list header 2010-07-01 12:31:10 +02:00
Harald Welte fd29a1f6cc [SGSN] GMM: Complete value_string for GMM cause values 2010-07-01 12:26:59 +02:00
Harald Welte 65d96783df [SGSN] SNDCP: use llist_for_each_entry_safe() when cleaning frag queue 2010-07-01 12:19:02 +02:00
Harald Welte 875840c603 [SGSN] Fix TLLI (re)assignments
Once The TLLI (or P-TMSI of which it is derived) change has been
confirmed by the MS, we need to unassign the old TLLI but keep
the new TLLI  _without_ re-setting the LLC entity structure such
as VUsend /VUrecv counters.
2010-07-01 11:54:31 +02:00
Harald Welte 937a9ecfcd [SGSN] Fix segfault when doing PS PAGING
The 'bssgp_paging_info' contains a pointer to the P-TMSI, and not
the P-TMSI itself.  The reason is that it is an optional BSSGP IE.
2010-07-01 11:53:25 +02:00
Harald Welte f78a3b2a22 [SGSN] Add VTY interface for SNDCP 2010-07-01 10:57:44 +02:00
Harald Welte 43ef6483db [SGSN] BSSGP: Print TLLI as hex value like everwhere else 2010-06-30 09:01:35 +02:00
Harald Welte 8fc60f0eb5 [SGSN] Deactivate SNDCP entity on PDP CTX DEACT CONFIRM
Otherwise we will end up leaking memory in the SNDCP layer...
2010-06-28 22:21:57 +02:00
Harald Welte bd5c91276b [SGSN] MM: Properly communicate TLLI changes / unassignment to LLC 2010-06-28 22:18:53 +02:00
Harald Welte f7fef48e1b [SGSN] LLC: properly free LLC entities at TLLI unassignment 2010-06-28 22:18:26 +02:00
Harald Welte c0d59504b4 [SGSN] Deactivate all PDP contexts on GPRS DETACH 2010-06-28 19:11:41 +02:00
Harald Welte 376d5e521e [SGSN] Fix segfault ar PDP CTX DEACT time
We need to call rate_ctr_group_free() on the per-PDPctx-counters
2010-06-28 18:57:21 +02:00
Holger Hans Peter Freyther 2788b96bf4 gprs: Fix LOGP misuse and specify LOGL_NOTICE as region. 2010-06-23 09:48:25 +08:00
Harald Welte 993d06065a [GPRS] Add comment on GTP being defined in 29.060 / 09.060 2010-06-14 17:00:51 +02:00
Sylvain Munaut 644a0cac0c [gprs] bssgp: Fix LLC PDU length encoding in BSSGP.
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
2010-06-10 15:15:42 +02:00
Sylvain Munaut eda125ca51 [gprs] sndcp: Fix call to msgb_alloc_headroom to have both head&tail room
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
2010-06-10 15:15:42 +02:00
Sylvain Munaut 5914bad40b [grps] Fix GTP data_ind call back message creation
We'll need to push data both before and after, so make sure there
is both headroom & tailroom

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
2010-06-10 15:15:42 +02:00
Harald Welte efbdee9a5c [GPSR] SGSN: Keep traffic counters for each PDP context 2010-06-10 15:12:38 +02:00
Harald Welte bb35c45a02 [GPRS] BSSGP/SGSN: Implement Gb-Interface Paging
We now have a function that generates BSSGP PS and CS paging request.

It is called from the libgtp code when we receive a GTP packet from
the GGSN for a MM context that is in SUSPEND state.  We then issue
a PS paging request to the Cell with the BVCI where the last RA update
was being performed.

TODO: We still don't enqueue the GTP packet (and transmit it on paging
complete), and we don't rate-limit the paging requests, i.e. every GTP packet
will trigger another paging request.

We probably also need some kind of logic that marks the phone as UNREGISTERED
if it doesn't respond to paging requests for some time.
2010-06-10 15:12:38 +02:00
Harald Welte bffeff8089 [GPRS] SGSN: fix typo 2010-06-10 15:12:38 +02:00
Harald Welte 5bfe499366 [GPRS] SGSN: Pass BSSGP SUSPEND/RESUME up to GMM and alter MMCTX state 2010-06-09 21:40:45 +08:00
Harald Welte f54e7e2102 [GPRS] GMM/SM: Improve error handling by sending STATUS messages 2010-06-09 21:40:45 +08:00
Harald Welte 588d44ee65 [GPRS] Drop all PDP contexts not present in PDP CTX STATUS IE at RA UPD 2010-06-09 21:40:45 +08:00
Harald Welte 60ebc02ba8 [GPRS] SM: Acknowledge PDP CTX DEACT for non-existing PDP CTX
Some phones (notably a Ericsson Mobile Platform based E-TEN M800)
insist on sending PDP CTX DEACT messages for contexts that have already
been deactivated.  The spec doesn't really say what we should do in
this case. But since there is no "reject", we simply acknowledge it.
2010-06-09 21:40:45 +08:00
Holger Hans Peter Freyther 62d97986a3 GPRS: Copy the content of the msgb instead of creating one that points to the other
Right now the memcpy with the data will copy data to itself as
the new_msg->data and msg->data are the same due the previous
copying of the header which included copying the list entry..

We allocate a message as big as the current one, then we have to
set all pointers by looking of how far they are away from the
msg->_data and add that to the new pointers.

Also copy the OpenBSC/GPRS specific CB data, also do the same
for calculating the offset to the data... At the end we should
end up with a copy...
2010-06-09 21:40:44 +08:00
Holger Hans Peter Freyther 62eaf54e7a GPRS: Fix crash when the peer can not be found...
Use UINT_MAX (or -1) if the peer can not be found.
2010-06-09 21:40:44 +08:00
Holger Hans Peter Freyther 57da4471d1 misc: Fix the return type of the go back vty function...
Without this we will get warnings about incompatible assignments
2010-06-09 21:40:44 +08:00
Holger Hans Peter Freyther 89476f5c8f GPRS: Fix compiler warning that will also lead to a crash at runtime. 2010-06-09 21:40:36 +08:00
Harald Welte 3a7074615f [GPRS] BSSGP: Fix formatting of BSSGP TX STATUS 2010-06-03 21:30:57 +02:00
Harald Welte ce22f92b6c [GPRS] SNDCP: Implement fragmentation of N-PDUs to SN-PDUs in downlink
Using the code of this commit, it was possible to provision GPRS
services and access a website from a G1 phone (Qualcomm MSM7k baseband chipset)
using a nanoBTS, Osmo-SGSN and OpenGGSN.

There is still no fragment re-assembly in the uplink path yet,
despite the (untested) code present in the gprs_sndcp.c file
2010-06-03 21:21:21 +02:00
Harald Welte db2c39f888 [GPRS] SNDCP: Check if SN-PDU is too large and reject it
... since we don't do fragmentation yet
2010-06-03 07:16:04 +02:00
Harald Welte 1d9d944310 [GPRS] LLC: Implement per-SAPI default values for LLC parameters 2010-06-03 07:11:04 +02:00
Harald Welte bb1c805718 [GPRS] implement GTP->SNDCP->LLC downlink user-data path
This only works for packets that are small enough to not need
fragmentation at the SNDCP layer (dns queries, ntp and the like).

It requires libgtp built from OpenGGSN dc3744fda045f9fca83de6881176987335a309a8
or later.  Plain 0.90 will NOT work.

Using this version, I could see bi-directional traffic from various
phones going all the way through BTS, OsmoSGSN, OpenGGSN and being routed
to and from the real internet.  Time to celebrate...
2010-06-03 06:38:38 +02:00
Harald Welte 96df60637a [GPRS] add comments to SGSN header file 2010-06-03 06:38:09 +02:00