Holger Hans Peter Freyther | 43b0909 | 2010-06-15 11:52:51 +0800 | [diff] [blame] | 1 | /* Routines for the MSC handling */ |
| 2 | |
| 3 | #ifndef OSMO_MSC_H |
| 4 | #define OSMO_MSC_H |
| 5 | |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 6 | #include <osmocom/core/fsm.h> |
| 7 | #include <osmocom/gsm/gsup.h> |
| 8 | |
Neels Hofmeyr | 9084396 | 2017-09-04 15:04:35 +0200 | [diff] [blame] | 9 | #include <osmocom/msc/gsm_data.h> |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 10 | |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 11 | #define MSC_HLR_REMOTE_IP_DEFAULT "127.0.0.1" |
| 12 | #define MSC_HLR_REMOTE_PORT_DEFAULT OSMO_GSUP_PORT |
| 13 | |
| 14 | enum subscr_conn_fsm_event { |
| 15 | /* Mark 0 as invalid to catch uninitialized vars */ |
| 16 | SUBSCR_CONN_E_INVALID = 0, |
Neels Hofmeyr | e3d3dc6 | 2018-03-31 00:02:14 +0200 | [diff] [blame] | 17 | /* Accepted the initial Complete Layer 3 (starting to evaluate Authentication and Ciphering) */ |
| 18 | SUBSCR_CONN_E_COMPLETE_LAYER_3, |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 19 | /* LU or Process Access FSM has determined that this conn is good */ |
| 20 | SUBSCR_CONN_E_ACCEPTED, |
| 21 | /* received first reply from MS in "real" CC, SMS, USSD communication */ |
| 22 | SUBSCR_CONN_E_COMMUNICATING, |
| 23 | /* Some async action has completed, check again whether all is done */ |
Neels Hofmeyr | e9e2f5c | 2018-03-15 13:26:43 +0100 | [diff] [blame] | 24 | SUBSCR_CONN_E_RELEASE_WHEN_UNUSED, |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 25 | /* MS/BTS/BSC originated close request */ |
| 26 | SUBSCR_CONN_E_MO_CLOSE, |
| 27 | /* MSC originated close request, e.g. failed authentication */ |
| 28 | SUBSCR_CONN_E_CN_CLOSE, |
Neels Hofmeyr | e3d3dc6 | 2018-03-31 00:02:14 +0200 | [diff] [blame] | 29 | /* The usage count for the conn has reached zero */ |
| 30 | SUBSCR_CONN_E_UNUSED, |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 31 | }; |
| 32 | |
| 33 | enum subscr_conn_fsm_state { |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 34 | SUBSCR_CONN_S_NEW, |
Neels Hofmeyr | e3d3dc6 | 2018-03-31 00:02:14 +0200 | [diff] [blame] | 35 | SUBSCR_CONN_S_AUTH_CIPH, |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 36 | SUBSCR_CONN_S_ACCEPTED, |
| 37 | SUBSCR_CONN_S_COMMUNICATING, |
Neels Hofmeyr | e3d3dc6 | 2018-03-31 00:02:14 +0200 | [diff] [blame] | 38 | SUBSCR_CONN_S_RELEASING, |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 39 | SUBSCR_CONN_S_RELEASED, |
| 40 | }; |
| 41 | |
Neels Hofmeyr | e2f24d5 | 2017-05-08 15:12:20 +0200 | [diff] [blame] | 42 | enum msc_compl_l3_rc { |
| 43 | MSC_CONN_ACCEPT = 0, |
| 44 | MSC_CONN_REJECT = 1, |
| 45 | }; |
| 46 | |
Neels Hofmeyr | 93c7463 | 2018-04-02 23:10:28 +0200 | [diff] [blame] | 47 | struct gsm_subscriber_connection *msc_subscr_conn_alloc(struct gsm_network *network, |
| 48 | enum ran_type via_ran, uint16_t lac); |
| 49 | |
Neels Hofmeyr | 16c42b5 | 2018-04-02 12:26:16 +0200 | [diff] [blame] | 50 | void msc_subscr_conn_update_id(struct gsm_subscriber_connection *conn, |
| 51 | enum complete_layer3_type from, const char *id); |
Daniel Willmann | 4e825b6 | 2018-02-15 10:33:26 +0100 | [diff] [blame] | 52 | char *msc_subscr_conn_get_conn_id(struct gsm_subscriber_connection *conn); |
Neels Hofmeyr | e3d3dc6 | 2018-03-31 00:02:14 +0200 | [diff] [blame] | 53 | |
| 54 | void msc_subscr_conn_complete_layer_3(struct gsm_subscriber_connection *conn); |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 55 | |
| 56 | int msc_vlr_alloc(struct gsm_network *net); |
| 57 | int msc_vlr_start(struct gsm_network *net); |
| 58 | |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 59 | void msc_sapi_n_reject(struct gsm_subscriber_connection *conn, int dlci); |
| 60 | int msc_clear_request(struct gsm_subscriber_connection *conn, uint32_t cause); |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 61 | int msc_compl_l3(struct gsm_subscriber_connection *conn, |
| 62 | struct msgb *msg, uint16_t chosen_channel); |
| 63 | void msc_dtap(struct gsm_subscriber_connection *conn, uint8_t link_id, |
| 64 | struct msgb *msg); |
| 65 | void msc_cipher_mode_compl(struct gsm_subscriber_connection *conn, |
| 66 | struct msgb *msg, uint8_t alg_id); |
| 67 | void msc_rx_sec_mode_compl(struct gsm_subscriber_connection *conn); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 68 | void msc_classmark_chg(struct gsm_subscriber_connection *conn, |
| 69 | const uint8_t *cm2, uint8_t cm2_len, |
| 70 | const uint8_t *cm3, uint8_t cm3_len); |
| 71 | void msc_assign_fail(struct gsm_subscriber_connection *conn, |
| 72 | uint8_t cause, uint8_t *rr_cause); |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 73 | |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 74 | void msc_subscr_conn_init(void); |
Max | d83b17b | 2018-02-06 16:51:31 +0100 | [diff] [blame] | 75 | bool msc_subscr_conn_is_accepted(const struct gsm_subscriber_connection *conn); |
Neels Hofmeyr | e3d3dc6 | 2018-03-31 00:02:14 +0200 | [diff] [blame] | 76 | bool msc_subscr_conn_is_establishing_auth_ciph(const struct gsm_subscriber_connection *conn); |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 77 | void msc_subscr_conn_communicating(struct gsm_subscriber_connection *conn); |
| 78 | void msc_subscr_conn_close(struct gsm_subscriber_connection *conn, |
| 79 | uint32_t cause); |
Neels Hofmeyr | 4068ab2 | 2018-04-01 20:55:54 +0200 | [diff] [blame] | 80 | void msc_subscr_conn_mo_close(struct gsm_subscriber_connection *conn, uint32_t cause); |
Neels Hofmeyr | e3d3dc6 | 2018-03-31 00:02:14 +0200 | [diff] [blame] | 81 | bool msc_subscr_conn_in_release(struct gsm_subscriber_connection *conn); |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 82 | |
Neels Hofmeyr | 4068ab2 | 2018-04-01 20:55:54 +0200 | [diff] [blame] | 83 | void msc_subscr_conn_rx_bssmap_clear_complete(struct gsm_subscriber_connection *conn); |
| 84 | void msc_subscr_conn_rx_iu_release_complete(struct gsm_subscriber_connection *conn); |
| 85 | |
Neels Hofmeyr | 6166f29 | 2017-11-22 14:33:12 +0100 | [diff] [blame] | 86 | enum msc_subscr_conn_use { |
| 87 | MSC_CONN_USE_UNTRACKED = -1, |
| 88 | MSC_CONN_USE_COMPL_L3, |
| 89 | MSC_CONN_USE_DTAP, |
Neels Hofmeyr | e3d3dc6 | 2018-03-31 00:02:14 +0200 | [diff] [blame] | 90 | MSC_CONN_USE_AUTH_CIPH, |
| 91 | MSC_CONN_USE_CM_SERVICE, |
Neels Hofmeyr | 6166f29 | 2017-11-22 14:33:12 +0100 | [diff] [blame] | 92 | MSC_CONN_USE_TRANS_CC, |
| 93 | MSC_CONN_USE_TRANS_SMS, |
Vadim Yanitskiy | 846efcb | 2018-06-10 22:22:49 +0700 | [diff] [blame] | 94 | MSC_CONN_USE_TRANS_NC_SS, |
Neels Hofmeyr | 6166f29 | 2017-11-22 14:33:12 +0100 | [diff] [blame] | 95 | MSC_CONN_USE_SILENT_CALL, |
Neels Hofmeyr | e3d3dc6 | 2018-03-31 00:02:14 +0200 | [diff] [blame] | 96 | MSC_CONN_USE_RELEASE, |
Neels Hofmeyr | 6166f29 | 2017-11-22 14:33:12 +0100 | [diff] [blame] | 97 | }; |
| 98 | |
| 99 | extern const struct value_string msc_subscr_conn_use_names[]; |
| 100 | static inline const char *msc_subscr_conn_use_name(enum msc_subscr_conn_use val) |
| 101 | { return get_value_string(msc_subscr_conn_use_names, val); } |
| 102 | |
| 103 | #define msc_subscr_conn_get(conn, balance_token) \ |
| 104 | _msc_subscr_conn_get(conn, balance_token, __BASE_FILE__, __LINE__) |
| 105 | #define msc_subscr_conn_put(conn, balance_token) \ |
| 106 | _msc_subscr_conn_put(conn, balance_token, __BASE_FILE__, __LINE__) |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 107 | struct gsm_subscriber_connection * |
| 108 | _msc_subscr_conn_get(struct gsm_subscriber_connection *conn, |
Neels Hofmeyr | 6166f29 | 2017-11-22 14:33:12 +0100 | [diff] [blame] | 109 | enum msc_subscr_conn_use balance_token, |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 110 | const char *file, int line); |
| 111 | void _msc_subscr_conn_put(struct gsm_subscriber_connection *conn, |
Neels Hofmeyr | 6166f29 | 2017-11-22 14:33:12 +0100 | [diff] [blame] | 112 | enum msc_subscr_conn_use balance_token, |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 113 | const char *file, int line); |
Neels Hofmeyr | 4068ab2 | 2018-04-01 20:55:54 +0200 | [diff] [blame] | 114 | bool msc_subscr_conn_used_by(struct gsm_subscriber_connection *conn, |
| 115 | enum msc_subscr_conn_use token); |
Holger Hans Peter Freyther | 43b0909 | 2010-06-15 11:52:51 +0800 | [diff] [blame] | 116 | |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 117 | void msc_stop_paging(struct vlr_subscr *vsub); |
| 118 | |
Holger Hans Peter Freyther | 43b0909 | 2010-06-15 11:52:51 +0800 | [diff] [blame] | 119 | #endif |