Use libvlr in libmsc (large refactoring)

Original libvlr code is by Harald Welte <laforge@gnumonks.org>,
polished and tweaked by Neels Hofmeyr <nhofmeyr@sysmocom.de>.

This is a long series of trial-and-error development collapsed in one patch.
This may be split in smaller commits if reviewers prefer that. If we can keep
it as one, we have saved ourselves the additional separation work.

SMS:

The SQL based lookup of SMS for attached subscribers no longer works since the
SQL database no longer has the subscriber data. Replace with a round-robin on
the SMS recipient MSISDNs paired with a VLR subscriber RAM lookup whether the
subscriber is currently attached.

If there are many SMS for not-attached subscribers in the SMS database, this
will become inefficient: a DB hit returns a pending SMS, the RAM lookup will
reveal that the subscriber is not attached, after which the DB is hit for the
next SMS. It would become more efficient e.g. by having an MSISDN based hash
list for the VLR subscribers and by marking non-attached SMS recipients in the
SMS database so that they can be excluded with the SQL query already.

There is a sanity limit to do at most 100 db hits per attempt to find a pending
SMS. So if there are more than 100 stored SMS waiting for their recipients to
actually attach to the MSC, it may take more than one SMS queue trigger to
deliver SMS for subscribers that are actually attached.

This is not very beautiful, but is merely intended to carry us over to a time
when we have a proper separate SMSC entity.

Introduce gsm_subscriber_connection ref-counting in libmsc.

Remove/Disable VTY and CTRL commands to create subscribers, which is now a task
of the OsmoHLR. Adjust the python tests accordingly.

Remove VTY cmd subscriber-keep-in-ram.

Use OSMO_GSUP_PORT = 4222 instead of 2222. See
I4222e21686c823985be8ff1f16b1182be8ad6175.

So far use the LAC from conn->bts, will be replaced by conn->lac in
Id3705236350d5f69e447046b0a764bbabc3d493c.

Related: OS#1592 OS#1974
Change-Id: I639544a6cdda77a3aafc4e3446a55393f60e4050
changes/95/3195/10
Harald Welte 7 years ago committed by Neels Hofmeyr
parent b8b85a1b2e
commit 2483f1b050
  1. 3
      configure.ac
  2. 1
      doc/examples/osmo-bsc/osmo-bsc.cfg
  3. 1
      doc/examples/osmo-nitb/rbs2308/openbsc.cfg
  4. 1
      include/openbsc/Makefile.am
  5. 1
      include/openbsc/abis_rsl.h
  6. 4
      include/openbsc/auth.h
  7. 3
      include/openbsc/bsc_api.h
  8. 2
      include/openbsc/chan_alloc.h
  9. 45
      include/openbsc/db.h
  10. 6
      include/openbsc/gsm_04_08.h
  11. 10
      include/openbsc/gsm_04_11.h
  12. 69
      include/openbsc/gsm_data.h
  13. 1
      include/openbsc/gsm_data_shared.h
  14. 92
      include/openbsc/gsm_subscriber.h
  15. 69
      include/openbsc/osmo_msc.h
  16. 4
      include/openbsc/signal.h
  17. 4
      include/openbsc/silent_call.h
  18. 7
      include/openbsc/token_auth.h
  19. 7
      include/openbsc/transaction.h
  20. 3
      include/openbsc/vlr.h
  21. 1
      include/openbsc/vty.h
  22. 3
      src/gprs/sgsn_main.c
  23. 4
      src/libbsc/abis_rsl.c
  24. 10
      src/libbsc/bsc_api.c
  25. 7
      src/libbsc/bsc_init.c
  26. 40
      src/libbsc/bsc_vty.c
  27. 3
      src/libbsc/handover_logic.c
  28. 1
      src/libbsc/paging.c
  29. 12
      src/libcommon-cs/common_cs.c
  30. 27
      src/libcommon-cs/common_cs_vty.c
  31. 23
      src/libcommon/debug.c
  32. 10
      src/libcommon/gsm_data.c
  33. 141
      src/libcommon/gsm_subscriber_base.c
  34. 8
      src/libcommon/gsup_client.c
  35. 2
      src/libcommon/gsup_test_client.c
  36. 2
      src/libmsc/Makefile.am
  37. 115
      src/libmsc/auth.c
  38. 170
      src/libmsc/ctrl_commands.c
  39. 1025
      src/libmsc/db.c
  40. 1301
      src/libmsc/gsm_04_08.c
  41. 57
      src/libmsc/gsm_04_11.c
  42. 313
      src/libmsc/gsm_subscriber.c
  43. 11
      src/libmsc/meas_feed.c
  44. 316
      src/libmsc/osmo_msc.c
  45. 6
      src/libmsc/rrlp.c
  46. 11
      src/libmsc/silent_call.c
  47. 65
      src/libmsc/smpp_openbsc.c
  48. 2
      src/libmsc/smpp_smsc.h
  49. 116
      src/libmsc/sms_queue.c
  50. 191
      src/libmsc/subscr_conn.c
  51. 160
      src/libmsc/token_auth.c
  52. 81
      src/libmsc/transaction.c
  53. 18
      src/libmsc/ussd.c
  54. 561
      src/libmsc/vty_interface_layer3.c
  55. 1
      src/libvlr/vlr_access_req_fsm.c
  56. 18
      src/osmo-nitb/bsc_hack.c
  57. 3
      tests/Makefile.am
  58. 1
      tests/channel/Makefile.am
  59. 74
      tests/channel/channel_test.c
  60. 2
      tests/channel/channel_test.ok
  61. 46
      tests/ctrl_test_runner.py
  62. 7
      tests/db/db_test.c
  63. 37
      tests/mm_auth/Makefile.am
  64. 340
      tests/mm_auth/mm_auth_test.c
  65. 40
      tests/mm_auth/mm_auth_test.ok
  66. 45
      tests/sms_queue/Makefile.am
  67. 215
      tests/sms_queue/sms_queue_test.c
  68. 0
      tests/sms_queue/sms_queue_test.err
  69. 98
      tests/sms_queue/sms_queue_test.ok
  70. 18
      tests/subscr/Makefile.am
  71. 117
      tests/subscr/subscr_test.c
  72. 3
      tests/subscr/subscr_test.ok
  73. 27
      tests/testsuite.at
  74. 166
      tests/vty_test_runner.py

@ -241,7 +241,6 @@ AC_OUTPUT(
tests/Makefile
tests/atlocal
tests/gsm0408/Makefile
tests/db/Makefile
tests/channel/Makefile
tests/bsc/Makefile
tests/bsc-nat/Makefile
@ -256,12 +255,12 @@ AC_OUTPUT(
tests/subscr/Makefile
tests/oap/Makefile
tests/gtphub/Makefile
tests/mm_auth/Makefile
tests/xid/Makefile
tests/sndcp_xid/Makefile
tests/slhc/Makefile
tests/v42bis/Makefile
tests/nanobts_omlattr/Makefile
tests/sms_queue/Makefile
doc/Makefile
doc/examples/Makefile
contrib/Makefile

@ -40,7 +40,6 @@ network
timer t3119 0
timer t3122 0
timer t3141 0
subscriber-keep-in-ram 0
bts 0
type nanobts
band DCS1800

@ -37,7 +37,6 @@ network
timer t3119 0
timer t3122 0
timer t3141 0
subscriber-keep-in-ram 0
bts 0
type rbs2000
band GSM900

@ -79,7 +79,6 @@ noinst_HEADERS = \
sms_queue.h \
socket.h \
system_information.h \
token_auth.h \
transaction.h \
trau_mux.h \
trau_upqueue.h \

@ -30,7 +30,6 @@
struct gsm_bts;
struct gsm_lchan;
struct gsm_subscriber;
struct gsm_bts_trx_ts;
#define GSM48_LEN2PLEN(a) (((a) << 2) | 1)

@ -4,7 +4,6 @@
#include <osmocom/core/utils.h>
struct gsm_auth_tuple;
struct gsm_subscriber;
enum auth_action {
AUTH_ERROR = -1, /* Internal error */
@ -20,7 +19,4 @@ static inline const char *auth_action_str(enum auth_action a)
return get_value_string(auth_action_names, a);
}
int auth_get_tuple_for_subscr(struct gsm_auth_tuple *atuple,
struct gsm_subscriber *subscr, int key_seq);
#endif /* _AUTH_H */

@ -41,6 +41,9 @@ struct bsc_api {
*/
void (*mr_config)(struct gsm_subscriber_connection *conn,
struct gsm_lchan *lchan, int full_rate);
/** Callback for additional actions during conn cleanup */
void (*conn_cleanup)(struct gsm_subscriber_connection *conn);
};
int bsc_api_init(struct gsm_network *network, struct bsc_api *api);

@ -25,7 +25,7 @@
struct gsm_subscriber_connection;
/* Find an allocated channel for a specified subscriber */
struct gsm_subscriber_connection *connection_for_subscr(struct gsm_subscriber *subscr);
struct gsm_subscriber_connection *connection_for_subscr(struct vlr_subscr *vsub);
/* Allocate a logical channel (SDCCH, TCH, ...) */
struct gsm_lchan *lchan_alloc(struct gsm_bts *bts, enum gsm_chan_t type, int allow_bigger);

@ -29,53 +29,26 @@ struct gsm_network;
struct gsm_auth_info;
struct gsm_auth_tuple;
struct gsm_sms;
struct gsm_subscriber;
/* one time initialisation */
int db_init(const char *name);
int db_prepare(void);
int db_fini(void);
/* subscriber management */
struct gsm_subscriber *db_create_subscriber(const char *imsi, uint64_t smin,
uint64_t smax, bool alloc_exten);
struct gsm_subscriber *db_get_subscriber(enum gsm_subscriber_field field,
const char *subscr);
int db_sync_subscriber(struct gsm_subscriber *subscriber);
int db_subscriber_expire(void *priv, void (*callback)(void *priv, long long unsigned int id));
int db_subscriber_alloc_tmsi(struct gsm_subscriber *subscriber);
int db_subscriber_alloc_exten(struct gsm_subscriber *subscriber, uint64_t smin,
uint64_t smax);
int db_subscriber_alloc_token(struct gsm_subscriber *subscriber, uint32_t* token);
int db_subscriber_assoc_imei(struct gsm_subscriber *subscriber, char *imei);
int db_subscriber_delete(struct gsm_subscriber *subscriber);
int db_sync_equipment(struct gsm_equipment *equip);
int db_subscriber_update(struct gsm_subscriber *subscriber);
int db_subscriber_list_active(void (*list_cb)(struct gsm_subscriber*,void*), void*);
/* auth info */
int db_get_authinfo_for_subscr(struct gsm_auth_info *ainfo,
struct gsm_subscriber *subscr);
int db_sync_authinfo_for_subscr(struct gsm_auth_info *ainfo,
struct gsm_subscriber *subscr);
int db_get_lastauthtuple_for_subscr(struct gsm_auth_tuple *atuple,
struct gsm_subscriber *subscr);
int db_sync_lastauthtuple_for_subscr(struct gsm_auth_tuple *atuple,
struct gsm_subscriber *subscr);
/* SMS store-and-forward */
int db_sms_store(struct gsm_sms *sms);
struct gsm_sms *db_sms_get(struct gsm_network *net, unsigned long long id);
struct gsm_sms *db_sms_get_unsent(struct gsm_network *net, unsigned long long min_id);
struct gsm_sms *db_sms_get_unsent_by_subscr(struct gsm_network *net, unsigned long long min_subscr_id, unsigned int failed);
struct gsm_sms *db_sms_get_unsent_for_subscr(struct gsm_subscriber *subscr);
struct gsm_sms *db_sms_get_next_unsent(struct gsm_network *net,
unsigned long long min_sms_id,
unsigned int max_failed);
struct gsm_sms *db_sms_get_next_unsent_rr_msisdn(struct gsm_network *net,
const char *last_msisdn,
unsigned int max_failed);
struct gsm_sms *db_sms_get_unsent_for_subscr(struct vlr_subscr *vsub,
unsigned int max_failed);
int db_sms_mark_delivered(struct gsm_sms *sms);
int db_sms_inc_deliver_attempts(struct gsm_sms *sms);
/* APDU blob storage */
int db_apdu_blob_store(struct gsm_subscriber *subscr,
uint8_t apdu_id_flags, uint8_t len,
uint8_t *apdu);
int db_sms_delete_by_msisdn(const char *msisdn);
/* Statistics counter storage */
struct osmo_counter;

@ -9,7 +9,6 @@
struct msgb;
struct gsm_bts;
struct gsm_subscriber;
struct gsm_network;
struct gsm_trans;
struct gsm_subscriber_connection;
@ -26,14 +25,15 @@ static inline struct msgb *gsm48_msgb_alloc_name(const char *name)
name);
}
void cm_service_request_concludes(struct gsm_subscriber_connection *conn,
struct msgb *msg);
/* config options controlling the behaviour of the lower leves */
void gsm0408_allow_everyone(int allow);
void gsm0408_clear_request(struct gsm_subscriber_connection *conn, uint32_t cause);
void gsm0408_clear_all_trans(struct gsm_network *net, int protocol);
int gsm0408_dispatch(struct gsm_subscriber_connection *conn, struct msgb *msg);
int gsm0408_rcvmsg(struct msgb *msg, uint8_t link_id);
int gsm0408_new_conn(struct gsm_subscriber_connection *conn);
enum gsm_chan_t get_ctype_by_chreq(struct gsm_network *bts, uint8_t ra);
/* don't use "enum gsm_chreq_reason_t" to avoid circular dependency */
int get_reason_by_chreq(uint8_t ra, int neci);

@ -3,6 +3,10 @@
#include <osmocom/gsm/protocol/gsm_04_11.h>
struct vlr_subscr;
struct gsm_subscriber_connection;
struct gsm_trans;
#define UM_SAPI_SMS 3 /* See GSM 04.05/04.06 */
/* SMS deliver PDU */
@ -29,10 +33,12 @@ int gsm0411_rcv_sms(struct gsm_subscriber_connection *conn, struct msgb *msg);
struct gsm_sms *sms_alloc(void);
void sms_free(struct gsm_sms *sms);
struct gsm_sms *sms_from_text(struct gsm_subscriber *receiver, struct gsm_subscriber *sender, int dcs, const char *text);
struct gsm_sms *sms_from_text(struct vlr_subscr *receiver,
struct vlr_subscr *sender,
int dcs, const char *text);
void _gsm411_sms_trans_free(struct gsm_trans *trans);
int gsm411_send_sms_subscr(struct gsm_subscriber *subscr,
int gsm411_send_sms_subscr(struct vlr_subscr *vsub,
struct gsm_sms *sms);
int gsm411_send_sms(struct gsm_subscriber_connection *conn,
struct gsm_sms *sms);

@ -24,6 +24,8 @@
struct mncc_sock_state;
struct gsm_subscriber_group;
struct bsc_subscr;
struct vlr_instance;
struct vlr_subscr;
#define OBSC_LINKID_CB(__msgb) (__msgb)->cb[3]
@ -69,20 +71,6 @@ struct gsm_auth_tuple {
};
#define GSM_KEY_SEQ_INVAL 7 /* GSM 04.08 - 10.5.1.2 */
/*
* LOCATION UPDATING REQUEST state
*
* Our current operation is:
* - Get imei/tmsi
* - Accept/Reject according to global policy
*/
struct gsm_loc_updating_operation {
struct osmo_timer_list updating_timer;
unsigned int waiting_for_imsi : 1;
unsigned int waiting_for_imei : 1;
unsigned int key_seq : 4;
};
/*
* AUTHENTICATION/CIPHERING state
*/
@ -120,16 +108,34 @@ enum ran_type {
RAN_UTRAN_IU, /* 3G / Iu-interface (IuCS or IuPS) */
};
struct gsm_classmark {
bool classmark1_set;
struct gsm48_classmark1 classmark1;
uint8_t classmark2_len;
uint8_t classmark2[3];
uint8_t classmark3_len;
uint8_t classmark3[14]; /* if cm3 gets extended by spec, it will be truncated */
};
/* active radio connection of a mobile subscriber */
struct gsm_subscriber_connection {
/* global linked list of subscriber_connections */
struct llist_head entry;
/* To whom we are allocated at the moment */
struct gsm_subscriber *subscr;
/* usage count. If this drops to zero, we start the release
* towards A/Iu */
uint32_t use_count;
/* The MS has opened the conn with a CM Service Request, and we shall
* keep it open for an actual request (or until timeout). */
bool received_cm_service_request;
/* libbsc subscriber information */
/* libbsc subscriber information (if available) */
struct bsc_subscr *bsub;
/* libmsc/libvlr subscriber information (if available) */
struct vlr_subscr *vsub;
/* LU expiration handling */
uint8_t expire_timer_stopped;
/* SMS helpers for libmsc */
@ -138,10 +144,11 @@ struct gsm_subscriber_connection {
/*
* Operations that have a state and might be pending
*/
struct gsm_loc_updating_operation *loc_operation;
struct gsm_security_operation *sec_operation;
struct gsm_anchor_operation *anch_operation;
struct osmo_fsm_inst *conn_fsm;
/* Are we part of a special "silent" call */
int silent_call;
@ -156,7 +163,7 @@ struct gsm_subscriber_connection {
/* back pointers */
struct gsm_network *network;
int in_release;
bool in_release;
struct gsm_lchan *lchan; /* BSC */
struct gsm_lchan *ho_lchan; /* BSC */
struct gsm_bts *bts; /* BSC */
@ -167,6 +174,8 @@ struct gsm_subscriber_connection {
/* connected via 2G or 3G? */
enum ran_type via_ran;
struct gsm_classmark classmark;
};
@ -312,6 +321,7 @@ struct gsm_network {
char *authorized_reg_str;
enum gsm48_reject_value reject_cause;
int a5_encryption;
bool authentication_required;
int neci;
int send_mm_info;
struct {
@ -375,17 +385,8 @@ struct gsm_network {
/* MSC data in case we are a true BSC */
struct osmo_bsc_data *bsc_data;
/* subscriber related features */
bool auto_create_subscr;
bool auto_assign_exten;
uint64_t ext_min;
uint64_t ext_max;
struct gsm_subscriber_group *subscr_group;
struct gsm_sms_queue *sms_queue;
/* nitb related control */
int avoid_tmsi;
/* control interface */
struct ctrl_handle *ctrl;
@ -409,6 +410,12 @@ struct gsm_network {
* not require gsm_data.h). In an MSC-without-BSC environment, this
* pointer is NULL to indicate absence of a bsc_subscribers list. */
struct llist_head *bsc_subscribers;
/* MSC: GSUP server address of the HLR */
const char *gsup_server_addr_str;
uint16_t gsup_server_port;
struct vlr_instance *vlr;
};
struct osmo_esme;
@ -431,7 +438,7 @@ struct gsm_sms_addr {
struct gsm_sms {
unsigned long long id;
struct gsm_subscriber *receiver;
struct vlr_subscr *receiver;
struct gsm_sms_addr src, dst;
enum gsm_sms_source_id source;
@ -582,7 +589,7 @@ extern const struct value_string bts_type_descs[_NUM_GSM_BTS_TYPE+1];
/* control interface handling */
int bsc_base_ctrl_cmds_install(void);
int msc_ctrl_cmds_install(void);
int msc_ctrl_cmds_install(struct gsm_network *net);
/* dependency handling */
void bts_depend_mark(struct gsm_bts *bts, int dep);
@ -593,4 +600,6 @@ int bts_depend_is_depedency(struct gsm_bts *base, struct gsm_bts *other);
int gsm_bts_get_radio_link_timeout(const struct gsm_bts *bts);
void gsm_bts_set_radio_link_timeout(struct gsm_bts *bts, int value);
bool classmark_is_r99(struct gsm_classmark *cm);
#endif /* _GSM_DATA_H */

@ -95,7 +95,6 @@ enum bts_gprs_mode {
};
struct gsm_lchan;
struct gsm_subscriber;
struct gsm_mncc;
struct osmo_rtp_socket;
struct rtp_socket;

@ -19,63 +19,8 @@
#define GSM_SUBSCRIBER_NO_EXPIRATION 0x0
struct vty;
struct sgsn_mm_ctx;
struct sgsn_subscriber_data;
struct subscr_request;
struct gsm_subscriber_group {
struct gsm_network *net;
int keep_subscr;
};
struct gsm_equipment {
long long unsigned int id;
char imei[GSM23003_IMEISV_NUM_DIGITS+1];
char name[GSM_NAME_LENGTH];
struct gsm48_classmark1 classmark1;
uint8_t classmark2_len;
uint8_t classmark2[3];
uint8_t classmark3_len;
uint8_t classmark3[14];
};
struct gsm_subscriber {
struct gsm_subscriber_group *group;
long long unsigned int id;
char imsi[GSM23003_IMSI_MAX_DIGITS+1];
uint32_t tmsi;
uint16_t lac;
char name[GSM_NAME_LENGTH];
char extension[GSM_EXTENSION_LENGTH];
int authorized;
time_t expire_lu;
/* Don't delete subscribers even if group->keep_subscr is not set */
int keep_in_ram;
/* Temporary field which is not stored in the DB/HLR */
uint32_t flags;
/* Every user can only have one equipment in use at any given
* point in time */
struct gsm_equipment equipment;
/* for internal management */
int use_count;
struct llist_head entry;
/* pending requests */
int is_paging;
struct llist_head requests;
/* GPRS/SGSN related fields */
struct sgsn_subscriber_data *sgsn_data;
};
enum gsm_subscriber_field {
GSM_SUBSCRIBER_IMSI,
GSM_SUBSCRIBER_TMSI,
@ -89,42 +34,17 @@ enum gsm_subscriber_update_reason {
GSM_SUBSCRIBER_UPDATE_EQUIPMENT,
};
struct gsm_subscriber *subscr_get(struct gsm_subscriber *subscr);
struct gsm_subscriber *subscr_put(struct gsm_subscriber *subscr);
struct gsm_subscriber *subscr_create_subscriber(struct gsm_subscriber_group *sgrp,
const char *imsi);
struct gsm_subscriber *subscr_get_by_tmsi(struct gsm_subscriber_group *sgrp,
uint32_t tmsi);
struct gsm_subscriber *subscr_get_by_imsi(struct gsm_subscriber_group *sgrp,
const char *imsi);
struct gsm_subscriber *subscr_get_by_extension(struct gsm_subscriber_group *sgrp,
const char *ext);
struct gsm_subscriber *subscr_get_by_id(struct gsm_subscriber_group *sgrp,
unsigned long long id);
struct gsm_subscriber *subscr_get_or_create(struct gsm_subscriber_group *sgrp,
const char *imsi);
int subscr_update(struct gsm_subscriber *s, struct gsm_bts *bts, int reason);
struct gsm_subscriber *subscr_active_by_tmsi(struct gsm_subscriber_group *sgrp,
uint32_t tmsi);
struct gsm_subscriber *subscr_active_by_imsi(struct gsm_subscriber_group *sgrp,
const char *imsi);
char *subscr_name(struct gsm_subscriber *subscr);
int subscr_purge_inactive(struct gsm_subscriber_group *sgrp);
void subscr_update_from_db(struct gsm_subscriber *subscr);
void subscr_expire(struct gsm_subscriber_group *sgrp);
int subscr_update_expire_lu(struct gsm_subscriber *subscr, struct gsm_bts *bts);
int subscr_update(struct vlr_subscr *vsub, struct gsm_bts *bts, int reason);
/*
* Paging handling with authentication
*/
struct subscr_request *subscr_request_channel(struct gsm_subscriber *subscr,
int type, gsm_cbfn *cbfn, void *param);
struct subscr_request *subscr_request_channel(struct vlr_subscr *vsub,
int channel_type,
gsm_cbfn *cbfn, void *param);
void subscr_remove_request(struct subscr_request *req);
/* internal */
struct gsm_subscriber *subscr_alloc(void);
extern struct llist_head active_subscribers;
int subscr_paging_dispatch(unsigned int hooknum, unsigned int event,
struct msgb *msg, void *data, void *param);
#endif /* _GSM_SUBSCR_H */

@ -3,9 +3,76 @@
#ifndef OSMO_MSC_H
#define OSMO_MSC_H
#include <osmocom/core/fsm.h>
#include <osmocom/gsm/gsup.h>
#include <openbsc/gsm_data.h>
#include "bsc_api.h"
#define MSC_HLR_REMOTE_IP_DEFAULT "127.0.0.1"
#define MSC_HLR_REMOTE_PORT_DEFAULT OSMO_GSUP_PORT
enum subscr_conn_fsm_event {
/* Mark 0 as invalid to catch uninitialized vars */
SUBSCR_CONN_E_INVALID = 0,
/* Timeout on connection establishment starts */
SUBSCR_CONN_E_START,
/* LU or Process Access FSM has determined that this conn is good */
SUBSCR_CONN_E_ACCEPTED,
/* received first reply from MS in "real" CC, SMS, USSD communication */
SUBSCR_CONN_E_COMMUNICATING,
/* Some async action has completed, check again whether all is done */
SUBSCR_CONN_E_BUMP,
/* MS/BTS/BSC originated close request */
SUBSCR_CONN_E_MO_CLOSE,
/* MSC originated close request, e.g. failed authentication */
SUBSCR_CONN_E_CN_CLOSE,
};
enum subscr_conn_fsm_state {
SUBSCR_CONN_S_INIT,
SUBSCR_CONN_S_NEW,
SUBSCR_CONN_S_ACCEPTED,
SUBSCR_CONN_S_COMMUNICATING,
SUBSCR_CONN_S_RELEASED,
};
enum subscr_conn_from {
SUBSCR_CONN_FROM_INVALID,
SUBSCR_CONN_FROM_LU,
SUBSCR_CONN_FROM_CM_SERVICE_REQ,
SUBSCR_CONN_FROM_PAGING_RESP,
};
extern const struct value_string subscr_conn_from_names[];
static inline const char *subscr_conn_from_name(enum subscr_conn_from val)
{
return get_value_string(subscr_conn_from_names, val);
}
struct bsc_api *msc_bsc_api();
void msc_release_connection(struct gsm_subscriber_connection *conn);
int msc_create_conn_fsm(struct gsm_subscriber_connection *conn, const char *id);
int msc_vlr_alloc(struct gsm_network *net);
int msc_vlr_start(struct gsm_network *net);
void msc_subscr_conn_init(void);
bool msc_subscr_conn_is_accepted(struct gsm_subscriber_connection *conn);
void msc_subscr_conn_communicating(struct gsm_subscriber_connection *conn);
void msc_subscr_conn_close(struct gsm_subscriber_connection *conn,
uint32_t cause);
#define msc_subscr_conn_get(conn) \
_msc_subscr_conn_get(conn, __BASE_FILE__, __LINE__)
#define msc_subscr_conn_put(conn) \
_msc_subscr_conn_put(conn, __BASE_FILE__, __LINE__)
struct gsm_subscriber_connection *
_msc_subscr_conn_get(struct gsm_subscriber_connection *conn,
const char *file, int line);
void _msc_subscr_conn_put(struct gsm_subscriber_connection *conn,
const char *file, int line);
#endif

@ -138,10 +138,8 @@ enum signal_rf {
S_RF_GRACE,
};
struct gsm_subscriber;
struct paging_signal_data {
struct gsm_subscriber *subscr;
struct vlr_subscr *vsub;
struct gsm_bts *bts;
int paging_result;

@ -3,9 +3,9 @@
struct gsm_subscriber_connection;
extern int gsm_silent_call_start(struct gsm_subscriber *subscr,
extern int gsm_silent_call_start(struct vlr_subscr *vsub,
void *data, int type);
extern int gsm_silent_call_stop(struct gsm_subscriber *subscr);
extern int gsm_silent_call_stop(struct vlr_subscr *vsub);
#if 0
extern int silent_call_rx(struct gsm_subscriber_connection *conn, struct msgb *msg);

@ -1,7 +0,0 @@
#ifndef _TOKEN_AUTH_H
#define _TOKEN_AUTH_H
void on_dso_load_token(void);
#endif /* _TOKEN_AUTH_H */

@ -24,7 +24,7 @@ struct gsm_trans {
uint8_t transaction_id;
/* To whom we belong, unique identifier of remote MM entity */
struct gsm_subscriber *subscr;
struct vlr_subscr *vsub;
/* The associated connection we are using to transmit messages */
struct gsm_subscriber_connection *conn;
@ -67,13 +67,14 @@ struct gsm_trans *trans_find_by_callref(struct gsm_network *net,
uint32_t callref);
struct gsm_trans *trans_alloc(struct gsm_network *net,
struct gsm_subscriber *subscr,
struct vlr_subscr *vsub,
uint8_t protocol, uint8_t trans_id,
uint32_t callref);
void trans_free(struct gsm_trans *trans);
int trans_assign_trans_id(struct gsm_network *net, struct gsm_subscriber *subscr,
int trans_assign_trans_id(struct gsm_network *net, struct vlr_subscr *vsub,
uint8_t protocol, uint8_t ti_flag);
int trans_has_conn(const struct gsm_subscriber_connection *conn);
void trans_conn_closed(struct gsm_subscriber_connection *conn);
#endif

@ -11,6 +11,8 @@
// for GSM_NAME_LENGTH
#include <openbsc/gsm_subscriber.h>
struct log_target;
/* from 3s to 10s */
#define GSM_29002_TIMER_S 10
/* from 15s to 30s */
@ -20,7 +22,6 @@
/* from 28h to 38h */
#define GSM_29002_TIMER_L (32*60*60)
/* VLR subscriber authentication state */
enum vlr_subscr_auth_state {
/* subscriber needs to be autenticated */

@ -38,6 +38,7 @@ enum bsc_vty_node {
SMPP_NODE,
SMPP_ESME_NODE,
GTPHUB_NODE,
HLR_NODE,
};
extern int bsc_vty_is_config_node(struct vty *vty, int node);

@ -40,6 +40,8 @@
#include <osmocom/core/logging.h>
#include <osmocom/core/stats.h>
#include <osmocom/gsm/gsup.h>
#include <osmocom/gprs/gprs_ns.h>
#include <osmocom/gprs/gprs_bssgp.h>
@ -83,6 +85,7 @@ static struct sgsn_instance sgsn_inst = {
.cfg = {
.gtp_statedir = "./",
.auth_policy = SGSN_AUTH_POLICY_CLOSED,
.gsup_server_port = OSMO_GSUP_PORT,
},
};
struct sgsn_instance *sgsn = &sgsn_inst;

@ -160,7 +160,7 @@ static struct gsm_lchan *lchan_lookup(struct gsm_bts_trx *trx, uint8_t chan_nr,
gsm_ts_and_pchan_name(lchan->ts), log_name, chan_nr);
if (lchan->conn)
log_set_context(LOG_CTX_VLR_SUBSCR, lchan->conn->subscr);
log_set_context(LOG_CTX_VLR_SUBSCR, lchan->conn->vsub);
return lchan;
}
@ -1382,8 +1382,6 @@ static void print_meas_rep(struct gsm_lchan *lchan, struct gsm_meas_rep *mr)
if (lchan && lchan->conn) {
if (lchan->conn->bsub)
name = bsc_subscr_name(lchan->conn->bsub);
else if (lchan->conn->subscr)
name = lchan->conn->subscr->imsi;
else
name = lchan->name;
}

@ -32,6 +32,7 @@
#include <openbsc/debug.h>
#include <openbsc/gsm_04_08.h>
#include <openbsc/trau_mux.h>
#include <openbsc/vlr.h>
#include <osmocom/gsm/protocol/gsm_08_08.h>
#include <osmocom/gsm/gsm48.h>
@ -273,13 +274,14 @@ void bsc_subscr_con_free(struct gsm_subscriber_connection *conn)
if (!conn)
return;
if (conn->network->bsc_api->conn_cleanup)
conn->network->bsc_api->conn_cleanup(conn);
if (conn->subscr) {
subscr_put(conn->subscr);
conn->subscr = NULL;
if (conn->vsub) {
LOGP(DNM, LOGL_ERROR, "conn->vsub should have been cleared.\n");
conn->vsub = NULL;
}
if (conn->ho_lchan) {
LOGP(DNM, LOGL_ERROR, "The ho_lchan should have been cleared.\n");
conn->ho_lchan->conn = NULL;

@ -38,6 +38,7 @@
#include <openbsc/e1_config.h>
#include <openbsc/common_bsc.h>
#include <openbsc/pcu_if.h>
#include <openbsc/osmo_msc.h>
#include <limits.h>
/* global pointer to the gsm network data structure */
@ -512,6 +513,12 @@ int bsc_network_alloc(mncc_recv_cb_t mncc_recv)
bsc_gsmnet->name_long = talloc_strdup(bsc_gsmnet, "OpenBSC");
bsc_gsmnet->name_short = talloc_strdup(bsc_gsmnet, "OpenBSC");
/* TODO: move to libmsc when gsm_network is split between libbsc and
* libmsc */
bsc_gsmnet->gsup_server_addr_str = talloc_strdup(bsc_gsmnet,
MSC_HLR_REMOTE_IP_DEFAULT);
bsc_gsmnet->gsup_server_port = MSC_HLR_REMOTE_PORT_DEFAULT;
return 0;
}

@ -54,8 +54,8 @@
#include <openbsc/bsc_msc_data.h>
#include <openbsc/osmo_bsc_rf.h>
#include <openbsc/pcu_if.h>
#include <openbsc/common_cs.h>
#include <openbsc/vlr.h>
#include <inttypes.h>
@ -173,10 +173,6 @@ static void net_dump_vty(struct vty *vty, struct gsm_network *net)
if (net->authorized_reg_str)
vty_out(vty, ", authorized regexp: %s", net->authorized_reg_str);
vty_out(vty, "%s", VTY_NEWLINE);
vty_out(vty, " Auto create subscriber: %s%s",
net->auto_create_subscr ? "yes" : "no", VTY_NEWLINE);
vty_out(vty, " Auto assign extension: %s%s",
net->auto_assign_exten ? "yes" : "no", VTY_NEWLINE);
vty_out(vty, " Location updating reject cause: %u%s",
net->reject_cause, VTY_NEWLINE);
vty_out(vty, " Encryption: A5/%u%s", net->a5_encryption,
@ -801,6 +797,9 @@ static int config_write_net(struct vty *vty)
vty_out(vty, " location updating reject cause %u%s",
gsmnet->reject_cause, VTY_NEWLINE);
vty_out(vty, " encryption a5 %u%s", gsmnet->a5_encryption, VTY_NEWLINE);
vty_out(vty, " authentication %s%s",
gsmnet->authentication_required ? "required" : "optional",
VTY_NEWLINE);
vty_out(vty, " neci %u%s", gsmnet->neci, VTY_NEWLINE);
vty_out(vty, " paging any use tch %d%s", gsmnet->pag_any_tch, VTY_NEWLINE);
vty_out(vty, " rrlp mode %s%s", rrlp_mode_name(gsmnet->rrlp.mode),
@ -833,8 +832,6 @@ static int config_write_net(struct vty *vty)
vty_out(vty, " timer t3141 %u%s", gsmnet->T3141, VTY_NEWLINE);
vty_out(vty, " dyn_ts_allow_tch_f %d%s",
gsmnet->dyn_ts_allow_tch_f ? 1 : 0, VTY_NEWLINE);
vty_out(vty, " subscriber-keep-in-ram %d%s",
gsmnet->subscr_group->keep_subscr, VTY_NEWLINE);
if (gsmnet->tz.override != 0) {
if (gsmnet->tz.dst)
vty_out(vty, " timezone %d %d %d%s",
@ -1018,21 +1015,24 @@ DEFUN(show_ts,
return CMD_SUCCESS;
}
static void subscr_dump_vty(struct vty *vty, struct gsm_subscriber *subscr)
static void subscr_dump_vty(struct vty *vty, struct vlr_subscr *vsub)
{
vty_out(vty, " ID: %llu, Authorized: %d%s", subscr->id,
subscr->authorized, VTY_NEWLINE);
if (strlen(subscr->name))
vty_out(vty, " Name: '%s'%s", subscr->name, VTY_NEWLINE);
if (strlen(subscr->extension))
vty_out(vty, " Extension: %s%s", subscr->extension,
OSMO_ASSERT(vsub);
if (strlen(vsub->name))
vty_out(vty, " Name: '%s'%s", vsub->name, VTY_NEWLINE);
if (strlen(vsub->msisdn))
vty_out(vty, " Extension: %s%s", vsub->msisdn,
VTY_NEWLINE);
if (strlen(vsub->imsi))
vty_out(vty, " IMSI: %s%s", vsub->imsi, VTY_NEWLINE);
if (vsub->tmsi != GSM_RESERVED_TMSI)
vty_out(vty, " TMSI: %08X%s", vsub->tmsi,
VTY_NEWLINE);
vty_out(vty, " IMSI: %s%s", subscr->imsi, VTY_NEWLINE);
if (subscr->tmsi != GSM_RESERVED_TMSI)
vty_out(vty, " TMSI: %08X%s", subscr->tmsi,
if (vsub->tmsi_new != GSM_RESERVED_TMSI)
vty_out(vty, " new TMSI: %08X%s", vsub->tmsi_new,
VTY_NEWLINE);
vty_out(vty, " Use count: %u%s", subscr->use_count, VTY_NEWLINE);
vty_out(vty, " Use count: %u%s", vsub->use_count, VTY_NEWLINE);
}
static void bsc_subscr_dump_vty(struct vty *vty, struct bsc_subscr *bsub)
@ -1160,9 +1160,9 @@ static void lchan_dump_full_vty(struct vty *vty, struct gsm_lchan *lchan)
vty_out(vty, " Channel Mode / Codec: %s%s",
get_value_string(gsm48_cmode_names, lchan->tch_mode),
VTY_NEWLINE);
if (lchan->conn && lchan->conn->subscr) {
if (lchan->conn && lchan->conn->vsub) {
vty_out(vty, " Subscriber:%s", VTY_NEWLINE);
subscr_dump_vty(vty, lchan->conn->subscr);
subscr_dump_vty(vty, lchan->conn->vsub);
} else
vty_out(vty, " No Subscriber%s", VTY_NEWLINE);
if (is_ipaccess_bts(lchan->ts->trx->bts)) {

@ -40,6 +40,7 @@
#include <osmocom/core/talloc.h>
#include <openbsc/transaction.h>
#include <openbsc/trau_mux.h>
#include <openbsc/vlr.h>
struct bsc_handover {
struct llist_head list;
@ -260,7 +261,7 @@ static int ho_gsm48_ho_compl(struct gsm_lchan *new_lchan)
net = new_lchan->ts->trx->bts->network;
LOGP(DHO, LOGL_INFO, "Subscriber %s HO from BTS %u->%u on ARFCN "
"%u->%u\n", subscr_name(ho->old_lchan->conn->subscr),
"%u->%u\n", vlr_subscr_name(ho->old_lchan->conn->vsub),
ho->old_lchan->ts->trx->bts->nr, new_lchan->ts->trx->bts->nr,
ho->old_lchan->ts->trx->arfcn, new_lchan->ts->trx->arfcn);

@ -50,6 +50,7 @@
#include <openbsc/gsm_data.h>
#include <openbsc/chan_alloc.h>
#include <openbsc/bsc_api.h>
#include <openbsc/vlr.h>
void *tall_paging_ctx;

@ -49,20 +49,10 @@ struct gsm_network *gsm_network_init(void *ctx,
if (!net)
return NULL;
net->subscr_group = talloc_zero(net, struct gsm_subscriber_group);
if (!net->subscr_group) {
talloc_free(net);
return NULL;
}
if (gsm_parse_reg(net, &net->authorized_regexp, &net->authorized_reg_str, 1,
&default_regexp) != 0)
return NULL;
net->subscr_group->net = net;
net->auto_create_subscr = true;
net->auto_assign_exten = true;
net->country_code = country_code;
net->network_code = network_code;
@ -78,8 +68,6 @@ struct gsm_network *gsm_network_init(void *ctx,
net->active_calls = osmo_counter_alloc("msc.active_calls");
net->mncc_recv = mncc_recv;
net->ext_min = GSM_MIN_EXTEN;
net->ext_max = GSM_MAX_EXTEN;
net->dyn_ts_allow_tch_f = true;

@ -168,6 +168,20 @@ DEFUN(cfg_net_encryption,
return CMD_SUCCESS;
}
DEFUN(cfg_net_authentication,
cfg_net_authentication_cmd,
"authentication (optional|required)",
"Whether to enforce MS authentication in 2G\n"
"Allow MS to attach via 2G BSC without authentication\n"
"Always do authentication\n")
{
struct gsm_network *gsmnet = gsmnet_from_vty(vty);
gsmnet->authentication_required = (argv[0][0] == 'r') ? true : false;
return CMD_SUCCESS;
}
DEFUN(cfg_net_rrlp_mode, cfg_net_rrlp_mode_cmd,
"rrlp mode (none|ms-based|ms-preferred|ass-preferred)",
"Radio Resource Location Protocol\n"
@ -209,17 +223,6 @@ DEFUN(cfg_net_dyn_ts_allow_tch_f,
return CMD_SUCCESS;
}
DEFUN(cfg_net_subscr_keep,
cfg_net_subscr_keep_cmd,
"subscriber-keep-in-ram (0|1)",
"Keep unused subscribers in RAM.\n"
"Delete unused subscribers\n" "Keep unused subscribers\n")
{
struct gsm_network *gsmnet = gsmnet_from_vty(vty);
gsmnet->subscr_group->keep_subscr = atoi(argv[0]);
return CMD_SUCCESS;
}
DEFUN(cfg_net_timezone,
cfg_net_timezone_cmd,
"timezone <-19-19> (0|15|30|45)",
@ -301,9 +304,9 @@ int common_cs_vty_init(struct gsm_network *network,
install_element(GSMNET_NODE, &cfg_net_authorize_regexp_cmd);
install_element(GSMNET_NODE, &cfg_net_reject_cause_cmd);
install_element(GSMNET_NODE, &cfg_net_encryption_cmd);
install_element(GSMNET_NODE, &cfg_net_authentication_cmd);
install_element(GSMNET_NODE, &cfg_net_rrlp_mode_cmd);
install_element(GSMNET_NODE, &cfg_net_mm_info_cmd);
install_element(GSMNET_NODE, &cfg_net_subscr_keep_cmd);
install_element(GSMNET_NODE, &cfg_net_timezone_cmd);
install_element(GSMNET_NODE, &cfg_net_timezone_dst_cmd);
install_element(GSMNET_NODE, &cfg_net_no_timezone_cmd);

@ -32,7 +32,6 @@
#include <osmocom/core/logging.h>
#include <osmocom/gprs/gprs_msgb.h>
#include <openbsc/gsm_data.h>
#include <openbsc/gsm_subscriber.h>
#include <openbsc/debug.h>
/* default categories */
@ -189,13 +188,13 @@ static const struct log_info_cat default_categories[] = {
static int filter_fn(const struct log_context *ctx, struct log_target *tar)
{
const struct gsm_subscriber *subscr = ctx->ctx[LOG_CTX_VLR_SUBSCR];
const struct vlr_subscr *vsub = ctx->ctx[LOG_CTX_VLR_SUBSCR];
const struct bsc_subscr *bsub = ctx->ctx[LOG_CTX_BSC_SUBSCR];
const struct gprs_nsvc *nsvc = ctx->ctx[LOG_CTX_GB_NSVC];
const struct gprs_nsvc *bvc = ctx->ctx[LOG_CTX_GB_BVC];
if ((tar->filter_map & (1 << LOG_FLT_VLR_SUBSCR)) != 0
&& subscr && subscr == tar->filter_data[LOG_FLT_VLR_SUBSCR])
&& vsub && vsub == tar->filter_data[LOG_FLT_VLR_SUBSCR])
return 1;
if ((tar->filter_map & (1 << LOG_FLT_BSC_SUBSCR)) != 0
@ -220,21 +219,3 @@ const struct log_info log_info = {
.cat = default_categories,
.num_cat = ARRAY_SIZE(default_categories),
};
void log_set_filter_vlr_subscr(struct log_target *target,
struct gsm_subscriber *vlr_subscr)
{
struct gsm_subscriber **fsub = (void*)&target->filter_data[LOG_FLT_VLR_SUBSCR];
/* free the old data */
if (*fsub) {
subscr_put(*fsub);
*fsub = NULL;
}
if (vlr_subscr) {
target->filter_map |= (1 << LOG_FLT_VLR_SUBSCR);
*fsub = subscr_get(vlr_subscr);
} else
target->filter_map &= ~(1 << LOG_FLT_VLR_SUBSCR);
}

@ -471,3 +471,13 @@ void gsm_bts_set_radio_link_timeout(struct gsm_bts *bts, int value)
cell_options->radio_link_timeout = (value >> 2) - 1;
}
}
bool classmark_is_r99(struct gsm_classmark *cm)
{
int rev_lev = 0;
if (cm->classmark1_set)
rev_lev = cm->classmark1.rev_lev;
else if (cm->classmark2_len > 0)
rev_lev = (cm->classmark2[0] >> 5) & 0x3;
return rev_lev >= 2;
}

@ -31,133 +31,34 @@
#include <osmocom/core/utils.h>
#include <openbsc/gsm_subscriber.h>
#include <openbsc/debug.h>
#include <openbsc/vlr.h>
LLIST_HEAD(active_subscribers);
void *tall_subscr_ctx;
/* for the gsm_subscriber.c */
struct llist_head *subscr_bsc_active_subscribers(void)
/* return static buffer with printable name of VLR subscriber */
const char *vlr_subscr_name(struct vlr_subscr *vsub)
{
return &active_subscribers;
}
char *subscr_name(struct gsm_subscriber *subscr)
{
if (!subscr)
static char buf[32];
if (!vsub)
return "unknown";
if (strlen(subscr->name))
return subscr->name;
return subscr->imsi;
}
struct gsm_subscriber *subscr_alloc(void)
{
struct gsm_subscriber *s;
s = talloc_zero(tall_subscr_ctx, struct gsm_subscriber);
if (!s)
return NULL;
llist_add_tail(&s->entry, &active_subscribers);
s->use_count = 1;
s->tmsi = GSM_RESERVED_TMSI;
INIT_LLIST_HEAD(&s->requests);
return s;
}
static void subscr_free(struct gsm_subscriber *subscr)
{
llist_del(&subscr->entry);
talloc_free(subscr);
}
void subscr_direct_free(struct gsm_subscriber *subscr)
{
OSMO_ASSERT(subscr->use_count == 1);
subscr_free(subscr);
}
struct gsm_subscriber *subscr_get(struct gsm_subscriber *subscr)
{
subscr->use_count++;
DEBUGP(DREF, "subscr %s usage increases usage to: %d\n",
subscr->extension, subscr->use_count);
return subscr;
}
struct gsm_subscriber *subscr_put(struct gsm_subscriber *subscr)
{
subscr->use_count--;
DEBUGP(DREF, "subscr %s usage decreased usage to: %d\n",
subscr->extension, subscr->use_count);
if (subscr->use_count <= 0 &&
!((subscr->group && subscr->group->keep_subscr) ||
subscr->keep_in_ram))
subscr_free(subscr);
return NULL;
}
struct gsm_subscriber *subscr_get_or_create(struct gsm_subscriber_group *sgrp,
const char *imsi)
{
struct gsm_subscriber *subscr;
llist_for_each_entry(subscr, subscr_bsc_active_subscribers(), entry) {
if (strcmp(subscr->imsi, imsi) == 0 && subscr->group == sgrp)
return subscr_get(subscr);
}
subscr = subscr_alloc();
if (!subscr)
return NULL;
osmo_strlcpy(subscr->imsi, imsi, sizeof(subscr->imsi));
subscr->group = sgrp;
return subscr;
}
struct gsm_subscriber *subscr_active_by_tmsi(struct gsm_subscriber_group *sgrp,
uint32_t tmsi)
{
struct gsm_subscriber *subscr;
llist_for_each_entry(subscr, subscr_bsc_active_subscribers(), entry) {
if (subscr->tmsi == tmsi && subscr->group == sgrp)
return subscr_get(subscr);
}
return NULL;
}
struct gsm_subscriber *subscr_active_by_imsi(struct gsm_subscriber_group *sgrp,
const char *imsi)
{
struct gsm_subscriber *subscr;
llist_for_each_entry(subscr, subscr_bsc_active_subscribers(), entry) {
if (strcmp(subscr->imsi, imsi) == 0 && subscr->group == sgrp)
return subscr_get(subscr);
}
return NULL;
if (vsub->msisdn[0])
snprintf(buf, sizeof(buf), "MSISDN:%s", vsub->msisdn);
else if (vsub->imsi[0])
snprintf(buf, sizeof(buf), "IMSI:%s", vsub->imsi);
else if (vsub->tmsi != GSM_RESERVED_TMSI)
snprintf(buf, sizeof(buf), "TMSI:0x%08x", vsub->tmsi);
else if (vsub->tmsi_new != GSM_RESERVED_TMSI)
snprintf(buf, sizeof(buf), "TMSI(new):0x%08x", vsub->tmsi_new);
else
return "unknown";
buf[sizeof(buf)-1] = '\0';
return buf;
}