msc: Add net parameter to trans_alloc

The trans_alloc function still uses the subscr object to access the
network object.

This patch adds an explicit net parameter to this function and
removes the access to subscr to obtain it.

Sponsored-by: On-Waves ehf
sgsn: Remove warnings

Remove warnings related to the SGSN specific code.

Sponsored-by: On-Waves ehf
msc: Add per subscriber keep_in_ram flag

Currently the keep_subscr flag in gsm_subscriber_group refers to a
whole group of subscribers which makes it difficult to really delete
single entries if the flag is set.

This patch adds a keep_in_ram field to gsm_subscriber which allows for
keeping subscriber objects in RAM while deleting others.

Note that really deleting an entry requires that both flags
(subscr_group->keep_subscr and subscr->keep_in_ram) are set to 0. So
only the latter should be used if a specification requires the
deletion of a subscriber entry.

Sponsored-by: On-Waves ehf
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
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
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
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
sgsn: Put SGSN related subscriber data into separate struct

There will be an increasing number of SGSN related fields per
subscriber. Instead of extending gsm_subscriber accordingly, a single
struct sgsn_subscriber_data object is assigned to it. The talloc
context used to allocated that object is the subscr object itself.
Therefore it will be freed automatically along with the subscr
object.

Sponsored-by: On-Waves ehf
nat: Fix copy and paste in the test code

The test didn't test that the access-list has been properly
removed. Fix the test to only remove the list once and verify
that it is gone.
sgsn: Do not 'commit' implicitely when executing 'insert'

Currently the gprs_subscr_update function is called when the
'update-subscriber ... insert ...' command is executed. This will
eventually notify the GMM layer which is rather the purpose of the
'commit' command.

This patch removes the call from update_subscr_insert.

Sponsored-by: On-Waves ehf
sgsn: Integrate Auth & Ciph into gsm48_gmm_authorize

Currently the Authentication and Ciphering procedure is not yet
invoked by the GMM layer.

This patch starts this procedure from within gsm48_gmm_authorize when
the mm->auth_state has been set to SGSN_AUTH_AUTHENTICATE and a call
to gsm0408_gprs_authenticate has been issued directly or indirectly
by the call to sgsn_auth_request.

Sponsored-by: On-Waves ehf
sgsn: Support subscriber based authentication

This commit mainly extends sgsn_auth.c to use and support the
auth_state SGSN_AUTH_AUTHENTICATE. It will be activated when IMSI and
IMEI are available, authentication is required
(subscr->sgsn_data->authenticate is set), but the MM context is not
marked as authenticated. If the state has been set to
SGSN_AUTH_AUTHENTICATE and sgsn_auth_update() is called, the GMM
layer will be informed by invoking gsm0408_gprs_authenticate().

Sponsored-by: On-Waves ehf
sgsn: Do not die in _bssgp_tx_dl_ud on TLLI mismatch (TODO)

Currently an OSMO_ASSERT fails, if the message's and the mmctx's
TLLIs do not match.

This commit turns the assertion into an ERROR log message and uses
the default values for IMSI, DRX, and RA CAP instead of the MM
context values in this case.

TODO:
  - find the real source for the problem
  - add test cases derived from what is being described in the ticket

Ticket: OW#1322
Sponsored-by: On-Waves ehf
sgsn: Added TODOs (TODO)

TODO:
  - fix and remove TODOs
  - add test cases for Detach(reattach)
  - add test cases for PDP context deletion (OW#1311)
  - add test cases for Cancel pending timer in sgsn_mm_ctx_free
  - remove this commit

Sponsored-by: On-Waves ehf
sgsn: Add support for authentication triplets (TODO)

TODO:
  - commit message
  - tests

Sponsored-by: On-Waves ehf
sgsn: Work on 2 phase authorization (WIP)

This implements the MAP way of subscriber validation when the MS
tries an Attach Request:
  1. perform authentication (optionally invoke the sendAuthInfo
  procedure), starts the AuthAndCiph procedure
  2. perform update location
  3. insert subscriber data
  4. finish the update location
  5. Attach Accept / Attach Reject

This is currently accessible via the VTY interface.

TODO:
  - Apply this to (periodic) RA Update Req
  - Delete Subscriber Data
  - Improve on procedure collisions (repeated Attach Req is sometimes
    not handled properly)
  - PDP info
  - Commit cleanup

Sponsored-by: On-Waves ehf