blob: a1fab2f23dd96df3f5e41aea54d77c4c4006d0c3 [file] [log] [blame]
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001#pragma once
2
3#include <osmocom/core/fsm.h>
4#include <osmocom/core/utils.h>
5#include <osmocom/gsm/gsm_utils.h>
6#include <osmocom/gsm/gsup.h>
7
8#include <osmocom/msc/msc_common.h>
9#include <osmocom/msc/ran_infra.h>
10
11/* Each subscriber connection is managed by different roles, as described in 3GPP TS 49.008 '4.3 Roles of MSC-A, MSC-I
12 * and MSC-T':
13 *
14 * MSC-A: subscriber management and control of all transactions (CC, SMS, USSD,...)
15 * MSC-I: "internal": the actual BSSMAP link to the BSS, or RANAP link to the RNC.
16 * MSC-T: "transitory": a new pending RAN link to a BSS or RNC, while handover is in progress.
17 * MSC-T becomes the new MSC-I once handover ends successfully.
18 *
19 * Without inter-MSC handover involved, all of the roles are managed by a single MSC instance. During inter-MSC
20 * handover negotiation, an MSC-T is set up at a remote MSC while MSC-A remains in the original MSC, and when handover
21 * concludes successfully, the remote MSC-T becomes the new remote MSC-I, replacing the local MSC-I role.
22 *
23 * Furthermore, the 3GPP specs use the following terms for naming MSC locations: MSC-A, MSC-B and MSC-B', as well as BSS
24 * or BSS-A, BSS-B and BSS-B':
25 *
26 * MSC-A: the first MSC the subscriber connected to.
27 * MSC-B: a remote MSC (if any).
28 * MSC-B': another remote MSC (if any, during Subsequent Handover).
29 *
30 * The full role assignments are spelled out in 3GPP TS 29.002.
31 *
32 * In Osmocom, the MAP protocol spoken between the MSCs is modeled using GSUP instead.
33 *
34 * Here are some diagrams of the lifecycle of a single subscriber's MSC-A,-I,-T roles at the locations MSC-A, MSC-B and
35 * MSC-B'.
36 *
37 * Initially:
38 *
39 * [MSC-A]
40 * BSS <-> MSC-I
41 *
42 * Then during inter-MSC handover negotiation:
43 *
44 * [MSC-A] <-MAP-> MSC-B
45 * BSS <-> MSC-I MSC-T <-> new BSS
46 *
47 * and when successful:
48 *
49 * [MSC-A] <-MAP-> MSC-B
50 * MSC-I <-> BSS
51 *
52 * Additional subsequent handover:
53 *
54 * [MSC-A] <-MAP-> MSC-B
55 * ^ MSC-I <-> BSS
56 * |
57 * +-------MAP-> MSC-B'
58 * MSC-T <-> new BSS
59 *
60 * (Here, quote, MSC-A "shall act as the target BSS towards the MSC-I and as the MSC towards the MSC-T.")
61 * and when successful:
62 *
63 * [MSC-A]
64 * ^
65 * |
66 * +-------MAP-> MSC-B
67 * MSC-I <-> BSS
68 *
69 * Subsequent handover back to the original MSC:
70 *
71 * [MSC-A] <-MAP-> MSC-B
72 * new BSS <-> MSC-T MSC-I <-> BSS
73 *
74 * and then
75 * [MSC-A]
76 * BSS <-> MSC-I
77 *
78 *
79 * Inter-BSC Handover is just a special case of inter-MSC Handover, where the same MSC-A takes on both MSC-I and MSC-T
80 * roles:
81 *
82 * [MSC-A]
83 * BSS <-> MSC-I
84 * new BSS <-> MSC-T
85 *
86 * The mechanism to take on different roles is implemented by different FSM instances. Each FSM kind has one
87 * implementation that acts locally, and another implementation to forward to a remote MSC. For example, in this
88 * scenario:
89 *
90 * [MSC-A] <-MAP-> MSC-B
91 * MSC-I <-> BSS
92 *
93 * the implementation is
94 *
95 * [MSC-A-----------------] [MSC-B-----------------]
96 * msc_a <-> msc_i_REMOTE <---GSUP---> msc_a_REMOTE <-> msc_i <--BSSMAP--> [BSS]
97 *
98 * MSC-A has a locally acting msc_a FSM implementation. The msc_i FSM implementation at MSC-A receives signals from the
99 * msc_a FSM and "merely" sends the MAP instructions to MSC-B.
100 *
101 * At MSC-B, in turn, the msc_a FSM's "remote" implementation receives the MAP messages and dispatches according events
102 * to the MSC-B's local msc_i FSM instance, which is implemented to directly act towards the BSS.
103 *
104 * To implement single-MSC operation, we have the separate MSC roles' local implementations on the same MSC instance
105 * instead of forwarding.
106 *
107 *
108 * Use of MAP procedures on GSUP towards HLR:
109 *
110 * The MSC <-> VLR communication does still happen locally in the MSC-A only. In other words, there may be MAP message
111 * handling between the MSCs (in the form of GSUP), but no MAP to talk to our internal VLR.
112 *
113 * From the VLR to the HLR, though, we again use GSUP for subscriber related HLR operations such as LU requesting and
114 * retrieving auth tokens.
115 *
116 * To complete the picture, the MSC-A <--GSUP--> MSC-B forwarding happens over the same GSUP connection
117 * as the VLR <--GSUP--> HLR link:
118 *
119 * OsmoMSC
120 * MSC-A <----------E-interface--->+--GSUP--> [IPA routing] ----E--> MSC-B
121 * ^ ^ (in osmo-hlr) \
122 * | (internal API) / \--D--> HLR
123 * v /
124 * VLR <------------D-interface-/
125 */
126
127struct inter_msc_link;
128struct ran_conn;
129
130enum msc_role {
131 MSC_ROLE_A,
132 MSC_ROLE_I,
133 MSC_ROLE_T,
134
135 MSC_ROLES_COUNT
136};
137
138extern const struct value_string msc_role_names[];
139static inline const char *msc_role_name(enum msc_role role)
140{ return get_value_string(msc_role_names, role); }
141
142
143enum msc_common_events {
144 /* Explicitly start with 0 (first real event will be -1 + 1 = 0). */
145 OFFSET_MSC_COMMON_EV = -1,
146
147 MSC_REMOTE_EV_RX_GSUP,
148
149 MSC_EV_CALL_LEG_RTP_LOCAL_ADDR_AVAILABLE,
150 MSC_EV_CALL_LEG_RTP_COMPLETE,
151 MSC_EV_CALL_LEG_RTP_RELEASED,
152 MSC_EV_CALL_LEG_TERM,
153
154 /* MNCC has told us to RTP_CREATE, but local RTP port has not yet been set up.
155 * The MSC role should respond by calling mncc_set_rtp_stream() */
156 MSC_MNCC_EV_NEED_LOCAL_RTP,
157 MSC_MNCC_EV_CALL_PROCEEDING,
158 MSC_MNCC_EV_CALL_COMPLETE,
159 MSC_MNCC_EV_CALL_ENDED,
160
161 LAST_MSC_COMMON_EV,
162};
163
164
165/* The events that the msc_a_local and msc_a_remote FSM implementations can receive,
166 * according to specifications. Not all of these are necessarily implemented. */
167enum msc_a_events {
168 OFFSET_MSC_A_EV = LAST_MSC_COMMON_EV - 1,
169
170 /* Establishing Layer 3 happens only at MSC-A (all-local MSC). To distinguish from the inter-MSC DTAP
171 * forwarding, keep this as a separate event. */
172 MSC_A_EV_FROM_I_COMPLETE_LAYER_3,
173
174 /* In inter-MSC situations, DTAP is forwarded transparently in AN-APDU IEs (formerly named
175 * BSS-APDU); see
176 * - 3GPP TS 49.008 4.2 'Transfer of DTAP and BSSMAP layer 3 messages on the * E-interface',
177 * - 3GPP TS 29.010 4.5.4 'BSSAP Messages transfer on E-Interface',
178 * - 3GPP TS 29.002 8.4.3 MAP_PROCESS_ACCESS_SIGNALLING service, 8.4.4 MAP_FORWARD_ACCESS_SIGNALLING service.
179 *
180 * MSC-B ---DTAP--> MSC-A MAP PROCESS ACCESS SIGNALLING request
181 * MSC-B <--DTAP--- MSC-A MAP FORWARD ACCESS SIGNALLING request
182 * (where neither will receive a "response")
183 *
184 * See 3GPP TS 49.008 6. 'BSSMAP messages transferred on the E-interface'.
185 * Depending on the RAN, the AN-APDU contains a BSSMAP or a RANAP encoded message.
186 * MSC-I to MSC-A:
187 * - Managing attach to one BSC+MSC:
188 * - CLASSMARK_UPDATE,
189 * - CIPHER_MODE_COMPLETE,
190 * - CIPHER_MODE_REJECT,
191 * - ASSIGNMENT_COMPLETE,
192 * - ASSIGNMENT_FAILURE,
193 * - CLEAR_REQUEST,
194 * - Handover related messages:
195 * - HANDOVER_REQUEST,
196 * - HANDOVER_PERFORMED,
197 * - HANDOVER_FAILURE,
198 * - Messages we don't need/support yet:
199 * - CHANNEL_MODIFY_REQUEST (MSC assisted codec changing handover),
200 * - SAPI_N_REJECT,
201 * - CONFUSION,
202 * - BSS_INVOKE_TRACE,
203 * - QUEUING_INDICATION,
204 * - PERFORM_LOCATION_REQUEST (*not* related to a Location Updating, but about passing the MS's geological
205 * position)
206 * - PERFORM_LOCATION_ABORT,
207 * - PERFORM_LOCATION_RESPONSE,
208 * - CONNECTION_ORIENTED_INFORMATION is listed in 48.008 3.2.1.70 as "(void)",
209 */
210 MSC_A_EV_FROM_I_PROCESS_ACCESS_SIGNALLING_REQUEST,
211 MSC_A_EV_FROM_I_PREPARE_SUBSEQUENT_HANDOVER_REQUEST,
212
213 /* See 3GPP TS 29.002 8.4.2 MAP_SEND_END_SIGNAL service. */
214 MSC_A_EV_FROM_I_SEND_END_SIGNAL_REQUEST,
215
216 /* These BSSMAP messages are relevant for MSC-T -> MSC-A, i.e. from the transitory during inter-MSC handover:
217 *
218 * - Handover related messages:
219 * - HANDOVER_REQUEST_ACKNOWLEDGE,
220 * - HANDOVER_COMPLETE,
221 * - HANDOVER_FAILURE,
222 * - HANDOVER_DETECT,
223 * - CLEAR_REQUEST,
224 * - Messages we don't need/support yet:
225 * - CONFUSION,
226 * - QUEUING_INDICATION,
227 */
228 MSC_A_EV_FROM_T_PROCESS_ACCESS_SIGNALLING_REQUEST,
229
230 /* Essentially the HO Request Ack. 3GPP TS 29.002 8.4.1 MAP_PREPARE_HANDOVER service. */
231 MSC_A_EV_FROM_T_PREPARE_HANDOVER_RESPONSE,
232 MSC_A_EV_FROM_T_PREPARE_HANDOVER_FAILURE,
233
234 /* Done establishing the radio link to the MS, for Handover.
235 * See 3GPP TS 29.002 8.4.2 MAP_SEND_END_SIGNAL service.
236 * Not to be confused with the MSC_I_EV_FROM_A_SEND_END_SIGNAL_RESPONSE that tells MSC-B to release. */
237 MSC_A_EV_FROM_T_SEND_END_SIGNAL_REQUEST,
238
239 /* gsm_04_08.c has successfully received a valid Complete Layer 3 message, i.e. Location Updating, CM Service
240 * Request, Paging Reponse or IMSI Detach. */
241 MSC_A_EV_COMPLETE_LAYER_3_OK,
242
243 /* Received a Classmark Update -- during GERAN ciphering, msc_a may have to wait for Classmark information to
244 * determine supported ciphers. */
245 MSC_A_EV_CLASSMARK_UPDATE,
246
247 /* LU or Process Access FSM have determined that the peer has verified its authenticity. */
248 MSC_A_EV_AUTHENTICATED,
249
250 /* A valid request is starting to be processed on the connection. Upon this event, msc_a moves from
251 * MSC_A_ST_AUTHENTICATED to MSC_A_ST_COMMUNICATING, and enters the only state without an expiry timeout. */
252 MSC_A_EV_TRANSACTION_ACCEPTED,
253
254 /* MSC originated close request, e.g. all done, failed authentication, ... */
255 MSC_A_EV_CN_CLOSE,
256
257 /* Subscriber originated close request */
258 MSC_A_EV_MO_CLOSE,
259
260 /* msc_a->use_count has reached a total of zero. */
261 MSC_A_EV_UNUSED,
262
263 MSC_A_EV_HANDOVER_REQUIRED,
264 MSC_A_EV_HANDOVER_END,
265
266 /* indicates nr of MSC_A events, keep this as last enum value */
267 LAST_MSC_A_EV
268};
269osmo_static_assert(LAST_MSC_A_EV <= 32, not_too_many_msc_a_events);
270
271extern const struct value_string msc_a_fsm_event_names[];
272
273enum msc_from_ran_events {
274 OFFSET_MSC_EV_FROM_RAN = LAST_MSC_COMMON_EV - 1,
275
276 MSC_EV_FROM_RAN_COMPLETE_LAYER_3,
277
278 /* A BSSMAP/RANAP message came in on the RAN conn. */
279 MSC_EV_FROM_RAN_UP_L2,
280
281 /* The RAN connection is gone, or busy going. */
282 MSC_EV_FROM_RAN_CONN_RELEASED,
283
284 LAST_MSC_EV_FROM_RAN
285};
286
287/* The events that the msc_i_local and msc_i_remote FSM implementations can receive.
288 * The MSC-I can also receive all msc_common_events and msc_from_ran_events. */
289enum msc_i_events {
290 OFFSET_E_MSC_I = LAST_MSC_EV_FROM_RAN - 1,
291
292 /* BSSMAP/RANAP comes in from MSC-A to be sent out on the RAN conn.
293 * Depending on the RAN, the AN-APDU contains a BSSMAP or a RANAP encoded message.
294 * Relevant BSSMAP procedures, see 3GPP TS 49.008 6. 'BSSMAP messages transferred on the E-interface':
295 * - Managing attach to one BSC+MSC:
296 * - CLASSMARK_REQUEST,
297 * - CIPHER_MODE_COMMAND,
298 * - COMMON_ID,
299 * - ASSIGNMENT_REQUEST,
300 * - Handover related messages:
301 * - HANDOVER_REQUEST_ACKNOWLEDGE,
302 * - HANDOVER_FAILURE,
303 * - Messages we don't need/support yet:
304 * - CONFUSION,
305 * - MSC_INVOKE_TRACE,
306 * - QUEUING_INDICATION,
307 * - LSA_INFORMATION,
308 * - PERFORM_LOCATION_REQUEST, (*not* related to a Location Updating, but about passing the MS's geological position)
309 * - PERFORM_LOCATION_ABORT,
310 * - PERFORM_LOCATION_RESPONSE,
311 * - CONNECTION_ORIENTED_INFORMATION is listed in 48.008 3.2.1.70 as "(void)"
312 */
313 MSC_I_EV_FROM_A_FORWARD_ACCESS_SIGNALLING_REQUEST,
314
315 /* MSC-A tells us to release the RAN connection. */
316 MSC_I_EV_FROM_A_SEND_END_SIGNAL_RESPONSE,
317
318 MSC_I_EV_FROM_A_PREPARE_SUBSEQUENT_HANDOVER_RESULT,
319 MSC_I_EV_FROM_A_PREPARE_SUBSEQUENT_HANDOVER_ERROR,
320
321 LAST_MSC_I_EV
322};
323osmo_static_assert(LAST_MSC_I_EV <= 32, not_too_many_msc_i_events);
324
325extern const struct value_string msc_i_fsm_event_names[];
326
327/* The events that the msc_t_local and msc_t_remote FSM implementations can receive.
328 * The MSC-T can also receive all msc_common_events and msc_from_ran_events. */
329enum msc_t_events {
330 /* sufficient would be to use LAST_MSC_EV_FROM_RAN as offset. But while we have enough numbers
331 * available, it is a good idea to keep MSC-I and MSC-T events separate, to catch errors of
332 * sending wrong event kinds. */
333 OFFSET_MSC_T_EV = LAST_MSC_I_EV - 1,
334
335 /* BSSMAP/RANAP comes in from MSC-A to be sent out on the RAN conn.
336 * Relevant BSSMAP procedures, see 3GPP TS 49.008 6. 'BSSMAP messages transferred on the E-interface':
337 * - Handover related messages:
338 * - HANDOVER_REQUEST,
339 * - CLASSMARK_UPDATE, (?)
340 * - Messages we don't need/support yet:
341 * - CONFUSION,
342 * - MSC_INVOKE_TRACE,
343 * - BSS_INVOKE_TRACE,
344 */
345 MSC_T_EV_FROM_A_PREPARE_HANDOVER_REQUEST,
346 MSC_T_EV_FROM_A_FORWARD_ACCESS_SIGNALLING_REQUEST,
347
348 /* MSC originated close request, e.g. all done, failed handover, ... */
349 MSC_T_EV_CN_CLOSE,
350
351 /* Subscriber originated close request */
352 MSC_T_EV_MO_CLOSE,
353
354 MSC_T_EV_CLEAR_COMPLETE,
355
356 LAST_MSC_T_EV
357};
358osmo_static_assert(LAST_MSC_T_EV <= 32, not_too_many_msc_t_events);
359
360extern const struct value_string msc_t_fsm_event_names[];
361
362/* All MSC role FSM implementations share this at the start of their fi->priv struct.
363 * See struct msc_a, struct msc_i, struct msc_t in their individual headers. */
364struct msc_role_common {
365 enum msc_role role;
366
367 struct osmo_fsm_inst *fi;
368
369 /* For a local implementation, this is NULL. Otherwise, this identifies how to reach the remote
370 * MSC that this "remote" implementation forwards messages to. */
371 struct e_link *remote_to;
372
373 struct msub *msub;
374 struct gsm_network *net;
375 struct ran_infra *ran;
376};
377
378/* AccessNetworkSignalInfo as in 3GPP TS 29.002. */
379struct an_apdu {
380 /* accessNetworkProtocolId */
381 enum osmo_gsup_access_network_protocol an_proto;
382 /* signalInfo */
383 struct msgb *msg;
384 /* If this AN-APDU is sent between MSCs, additional information from the E-interface messaging, like the
385 * Handover Number, will placed/available here. Otherwise may be left NULL. */
386 const struct osmo_gsup_message *e_info;
387};