msc: Add and use gsm_subscriber_group

Currently every subcriber object directly refers to the gsm_network
which contains a flag shared by every related subscriber
(keep_subscr). This adds a dependency on gsm_network even if only the
function defined in gsm_subscriber_base.c are used.

This patch adds a new struct gsm_subscriber_group which contains the
keep_subscr flag and a back reference to the network object. The
latter is not dereferenced in gsm_subscriber_base.c, so it can safely
be set to NULL when only that part of the gsm_subscriber API is being
used. It also changes that API to use gsm_subscriber_group instead of
gsm_network parameters.

Since there are some places where a pointer to the gsm_network is
needed but where only a gsm_subscriber is available, a 'net' back
pointer is added to the group struct, too. Nevertheless subscr group
and network could be separated completely, but this is not the topic
of this commit.

Sponsored-by: On-Waves ehf
bsc/test: Add tests for gsm_subscriber base

This commit adds test for the generic part of gsm_subscriber like
reference counting and flag usage.

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

Currently the keep_subscr flag 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 force_no_keep field to gsm_subscriber which allows for
deleting single subscribers even if group->keep_subscr is set.

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 (TODO)

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.

TODO:
 - tests
 - decide, whether 'remote' could be named better, e.g. sth based on
   'subscriber'

Ticket: OW#????
Sponsored-by: On-Waves ehf
sgsn: Add gsm0408_gprs_access_cancelled (TODO)

This function is called to delete an established MM context
without invoking a detach procedure that could disable the GPRS
functionality of the MS until the next power cycle.

It is called when a subscriber is cancelled.

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

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.

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

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: Notify an affected MM context if an ACL rule is removed (TODO)

Currently if an ACL access rule is removed, MS already attached are
not affected until they try to reattach to the SGSN.

This patch adds sgsn_auth_update_all() that iterates through allMM
contexts and calls sgsn_auth_update() on each of them. This function
is then called when 'imsi-acl del IMSI' is executed after the ACL has
been removed.

TODO:
 - decide, whether ito replace that by a dedicated update command in
   the VTY ENABLE node

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: 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
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
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
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: Put SGSN related subscriber data into separate struct (TODO)

TODO:
  - commit message
  - remove _alloc entirely (also in 'Add gprs_subscriber.c' patch)
  - also move mm into this struct

Sponsored-by: On-Waves ehf
gsn: Auth and Ciph (WIP)

TODO:
 - split this commit into several smaller ones (fixes, integration,
   triplet management, ...)
 - 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