Harald Welte | 0df904d | 2018-12-03 11:00:04 +0100 | [diff] [blame] | 1 | /* (C) 2018-2019 by sysmocom s.f.m.c. GmbH |
| 2 | * All Rights Reserved |
| 3 | * |
| 4 | * Author: Harald Welte, Philipp Maier |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU Affero General Public License as published by |
| 8 | * the Free Software Foundation; either version 3 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU Affero General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU Affero General Public License |
| 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 | * |
| 19 | */ |
| 20 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 21 | #include <errno.h> |
| 22 | |
Harald Welte | 0df904d | 2018-12-03 11:00:04 +0100 | [diff] [blame] | 23 | #include <osmocom/core/utils.h> |
| 24 | #include <osmocom/core/fsm.h> |
| 25 | #include <osmocom/msc/debug.h> |
| 26 | #include <osmocom/msc/vlr.h> |
| 27 | #include <osmocom/msc/vlr_sgs.h> |
| 28 | #include "vlr_sgs_fsm.h" |
| 29 | |
| 30 | const struct value_string sgs_state_timer_names[] = { |
| 31 | {SGS_STATE_TS5, "Ts5"}, |
| 32 | {SGS_STATE_TS6_2, "Ts6-2"}, |
| 33 | {SGS_STATE_TS7, "Ts7"}, |
| 34 | {SGS_STATE_TS11, "Ts11"}, |
| 35 | {SGS_STATE_TS14, "Ts14"}, |
| 36 | {SGS_STATE_TS15, "Ts15"}, |
| 37 | {0, NULL} |
| 38 | }; |
| 39 | |
| 40 | const struct value_string sgs_state_counter_names[] = { |
| 41 | {SGS_STATE_NS7, "Ns7"}, |
| 42 | {SGS_STATE_NS11, "Ns11"}, |
| 43 | {0, NULL} |
| 44 | }; |
| 45 | |
| 46 | /* Reset all SGs-Associations back to zero. |
Martin Hauke | 3f07dac | 2019-11-14 17:49:08 +0100 | [diff] [blame] | 47 | * \param[in] vlr VLR instance. */ |
Harald Welte | 0df904d | 2018-12-03 11:00:04 +0100 | [diff] [blame] | 48 | void vlr_sgs_reset(struct vlr_instance *vlr) |
| 49 | { |
| 50 | struct vlr_subscr *vsub; |
| 51 | |
| 52 | OSMO_ASSERT(vlr); |
| 53 | |
| 54 | LOGP(DVLR, LOGL_INFO, "dropping all SGs associations.\n"); |
| 55 | |
| 56 | llist_for_each_entry(vsub, &vlr->subscribers, list) { |
| 57 | osmo_fsm_inst_dispatch(vsub->sgs_fsm, SGS_UE_E_RX_RESET_FROM_MME, NULL); |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | /*! Perform an SGs location update. |
Martin Hauke | 3f07dac | 2019-11-14 17:49:08 +0100 | [diff] [blame] | 62 | * \param[in] vlr VLR instance. |
Harald Welte | 0df904d | 2018-12-03 11:00:04 +0100 | [diff] [blame] | 63 | * \param[in] cfg SGs interface configuration parameters. |
Martin Hauke | 3f07dac | 2019-11-14 17:49:08 +0100 | [diff] [blame] | 64 | * \param[in] response_cb callback function that is called when LU is done. |
| 65 | * \param[in] paging_cb callback function that is called when LU needs to page. |
| 66 | * \param[in] mminfo_cb callback function that is called to provide MM info to the UE. |
Harald Welte | 0df904d | 2018-12-03 11:00:04 +0100 | [diff] [blame] | 67 | * \param[in] mme_name fqdn of the requesting MME (mme-name). |
| 68 | * \param[in] type location update type (normal or IMSI attach). |
| 69 | * \param[in] imsi mobile identity (IMSI). |
| 70 | * \param[in] new_lai identifier of the new location area. |
Pau Espin Pedrol | 6710670 | 2021-04-27 18:20:15 +0200 | [diff] [blame^] | 71 | * \param[in] last_eutran_plnm_id Last E-UTRAN PLMN ID (can be NULL). |
Harald Welte | 0df904d | 2018-12-03 11:00:04 +0100 | [diff] [blame] | 72 | * \returns 0 in case of success, -EINVAL in case of error. */ |
| 73 | int vlr_sgs_loc_update(struct vlr_instance *vlr, struct vlr_sgs_cfg *cfg, |
| 74 | vlr_sgs_lu_response_cb_t response_cb, vlr_sgs_lu_paging_cb_t paging_cb, |
| 75 | vlr_sgs_lu_mminfo_cb_t mminfo_cb, char *mme_name, enum vlr_lu_type type, const char *imsi, |
Pau Espin Pedrol | 6710670 | 2021-04-27 18:20:15 +0200 | [diff] [blame^] | 76 | struct osmo_location_area_id *new_lai, struct osmo_plmn_id *last_eutran_plmn) |
Harald Welte | 0df904d | 2018-12-03 11:00:04 +0100 | [diff] [blame] | 77 | { |
| 78 | struct vlr_subscr *vsub = NULL; |
| 79 | |
| 80 | OSMO_ASSERT(response_cb); |
| 81 | OSMO_ASSERT(paging_cb); |
| 82 | OSMO_ASSERT(mminfo_cb); |
| 83 | OSMO_ASSERT(cfg); |
| 84 | OSMO_ASSERT(imsi); |
| 85 | |
Neels Hofmeyr | 7c5346c | 2019-02-19 02:36:35 +0100 | [diff] [blame] | 86 | vsub = vlr_subscr_find_or_create_by_imsi(vlr, imsi, VSUB_USE_SGS, NULL); |
Harald Welte | 0df904d | 2018-12-03 11:00:04 +0100 | [diff] [blame] | 87 | if (!vsub) { |
| 88 | LOGP(DSGS, LOGL_ERROR, "VLR subscriber allocation failed\n"); |
| 89 | return -EINVAL; |
| 90 | } |
| 91 | |
| 92 | vsub->sgs.cfg = *cfg; |
| 93 | vsub->sgs.response_cb = response_cb; |
| 94 | vsub->sgs.paging_cb = paging_cb; |
| 95 | vsub->sgs.mminfo_cb = mminfo_cb; |
| 96 | vlr_subscr_set_imsi(vsub, imsi); |
Pau Espin Pedrol | 6710670 | 2021-04-27 18:20:15 +0200 | [diff] [blame^] | 97 | vlr_subscr_set_last_used_eutran_plmn_id(vsub, last_eutran_plmn); |
Harald Welte | 0df904d | 2018-12-03 11:00:04 +0100 | [diff] [blame] | 98 | osmo_strlcpy(vsub->sgs.mme_name, mme_name, sizeof(vsub->sgs.mme_name)); |
| 99 | |
| 100 | osmo_fsm_inst_dispatch(vsub->sgs_fsm, SGS_UE_E_RX_LU_FROM_MME, NULL); |
| 101 | |
| 102 | /* FIXME: Use the "type" type parameter (for what is it useful?) */ |
| 103 | |
| 104 | vsub->sgs.lai = *new_lai; |
| 105 | vsub->cgi.lai = *new_lai; |
| 106 | vsub->cs.lac = vsub->sgs.lai.lac; |
| 107 | |
Philipp Maier | 4826465 | 2019-04-02 16:58:59 +0200 | [diff] [blame] | 108 | /* Subscribers that are created by the SGs location update will not |
| 109 | * expire automatically, however a 2G LU or an implicit IMSI detach |
| 110 | * from EPS services may change this. */ |
| 111 | vsub->expire_lu = VLR_SUBSCRIBER_NO_EXPIRATION; |
| 112 | |
Harald Welte | 0df904d | 2018-12-03 11:00:04 +0100 | [diff] [blame] | 113 | return 0; |
| 114 | } |
| 115 | |
| 116 | /*! Notify that the SGs Location Update accept message has been sent to MME. |
| 117 | * \param[in] vsub VLR subscriber. */ |
| 118 | void vlr_sgs_loc_update_acc_sent(struct vlr_subscr *vsub) |
| 119 | { |
| 120 | osmo_fsm_inst_dispatch(vsub->sgs_fsm, SGS_UE_E_TX_LU_ACCEPT, NULL); |
| 121 | |
| 122 | /* FIXME: At this point we need to check the status of Ts5 and if |
| 123 | * it is still running this means the LU has interrupted the paging, |
| 124 | * and we need to start paging again. 3GPP TS 29.118, |
| 125 | * chapter 5.2.3.2 */ |
| 126 | } |
| 127 | |
| 128 | /*! Notify that the SGs Location Update reject message has been sent to MME. |
| 129 | * \param[in] vsub VLR subscriber. */ |
| 130 | void vlr_sgs_loc_update_rej_sent(struct vlr_subscr *vsub) |
| 131 | { |
| 132 | osmo_fsm_inst_dispatch(vsub->sgs_fsm, SGS_UE_E_TX_LU_REJECT, NULL); |
| 133 | } |
| 134 | |
| 135 | /*! Perform an SGs IMSI detach. |
| 136 | * \param[in] vsub VLR subscriber. |
| 137 | * \param[in] imsi mobile identity (IMSI). |
| 138 | * \param[in] type datach type. */ |
| 139 | void vlr_sgs_imsi_detach(struct vlr_instance *vlr, const char *imsi, enum sgsap_imsi_det_noneps_type type) |
| 140 | { |
| 141 | struct vlr_subscr *vsub; |
| 142 | enum sgs_ue_fsm_event evt; |
Philipp Maier | 0803d88 | 2019-04-02 16:07:13 +0200 | [diff] [blame] | 143 | |
Neels Hofmeyr | 7c5346c | 2019-02-19 02:36:35 +0100 | [diff] [blame] | 144 | vsub = vlr_subscr_find_by_imsi(vlr, imsi, __func__); |
Harald Welte | 0df904d | 2018-12-03 11:00:04 +0100 | [diff] [blame] | 145 | if (!vsub) |
| 146 | return; |
| 147 | |
Philipp Maier | 0803d88 | 2019-04-02 16:07:13 +0200 | [diff] [blame] | 148 | /* See also: 3GPP TS 29.118, 5.6.3 Procedures in the VLR: In case of |
| 149 | * an implicit detach, we are supposed to check if the state of the |
| 150 | * SGs-association, and only when it is not SGs-NULL, we may proceed. */ |
| 151 | if (vsub->sgs_fsm->state == SGS_UE_ST_NULL && type == SGSAP_ID_NONEPS_T_IMPLICIT_UE_EPS_NONEPS) |
| 152 | return; |
| 153 | |
Harald Welte | 0df904d | 2018-12-03 11:00:04 +0100 | [diff] [blame] | 154 | switch (type) { |
| 155 | case SGSAP_ID_NONEPS_T_EXPLICIT_UE_NONEPS: |
| 156 | evt = SGS_UE_E_RX_DETACH_IND_FROM_UE; |
| 157 | break; |
| 158 | case SGSAP_ID_NONEPS_T_COMBINED_UE_EPS_NONEPS: |
| 159 | case SGSAP_ID_NONEPS_T_IMPLICIT_UE_EPS_NONEPS: |
| 160 | /* FIXME: Is that right? */ |
| 161 | evt = SGS_UE_E_RX_DETACH_IND_FROM_MME; |
| 162 | break; |
| 163 | default: |
| 164 | LOGP(DSGS, LOGL_ERROR, "(sub %s) invalid SGS IMSI detach type, detaching anyway...\n", |
| 165 | vlr_subscr_msisdn_or_name(vsub)); |
| 166 | evt = SGS_UE_E_RX_DETACH_IND_FROM_MME; |
| 167 | break; |
| 168 | } |
| 169 | |
| 170 | osmo_fsm_inst_dispatch(vsub->sgs_fsm, evt, NULL); |
Philipp Maier | 0803d88 | 2019-04-02 16:07:13 +0200 | [diff] [blame] | 171 | |
| 172 | /* Detaching from non EPS services essentially means that the |
| 173 | * subscriber is detached from 2G. In any case the VLR will |
| 174 | * get rid of the subscriber. */ |
| 175 | vlr_subscr_expire(vsub); |
Neels Hofmeyr | 7c5346c | 2019-02-19 02:36:35 +0100 | [diff] [blame] | 176 | vlr_subscr_put(vsub, __func__); |
Harald Welte | 0df904d | 2018-12-03 11:00:04 +0100 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | /*! Perform an SGs EPS detach. |
| 180 | * \param[in] vsub VLR subscriber. |
| 181 | * \param[in] imsi mobile identity (IMSI). |
| 182 | * \param[in] type datach type. */ |
| 183 | void vlr_sgs_eps_detach(struct vlr_instance *vlr, const char *imsi, enum sgsap_imsi_det_eps_type type) |
| 184 | { |
| 185 | struct vlr_subscr *vsub; |
| 186 | enum sgs_ue_fsm_event evt; |
Neels Hofmeyr | 7c5346c | 2019-02-19 02:36:35 +0100 | [diff] [blame] | 187 | vsub = vlr_subscr_find_by_imsi(vlr, imsi, __func__); |
Harald Welte | 0df904d | 2018-12-03 11:00:04 +0100 | [diff] [blame] | 188 | if (!vsub) |
| 189 | return; |
| 190 | |
| 191 | switch (type) { |
| 192 | case SGSAP_ID_EPS_T_NETWORK_INITIATED: |
| 193 | evt = SGS_UE_E_RX_DETACH_IND_FROM_MME; |
| 194 | break; |
| 195 | case SGSAP_ID_EPS_T_UE_INITIATED: |
| 196 | evt = SGS_UE_E_RX_DETACH_IND_FROM_UE; |
| 197 | break; |
| 198 | case SGSAP_ID_EPS_T_EPS_NOT_ALLOWED: |
| 199 | evt = SGS_UE_E_RX_DETACH_IND_FROM_MME; |
| 200 | break; |
| 201 | default: |
| 202 | LOGP(DSGS, LOGL_ERROR, "(sub %s) invalid SGS IMSI detach type, detaching anyway...\n", |
| 203 | vlr_subscr_msisdn_or_name(vsub)); |
| 204 | evt = SGS_UE_E_RX_DETACH_IND_FROM_MME; |
| 205 | break; |
| 206 | } |
| 207 | |
| 208 | osmo_fsm_inst_dispatch(vsub->sgs_fsm, evt, NULL); |
Philipp Maier | 4826465 | 2019-04-02 16:58:59 +0200 | [diff] [blame] | 209 | |
| 210 | /* See also 3GPP TS 29.118, 5.4.3 Procedures in the VLR. Detaching from |
| 211 | * EPS services essentially means that the subscriber leaves the 4G RAN |
| 212 | * but continues to live on 2G, this basically turns the subscriber into |
| 213 | * a normal 2G subscriber and we need to make sure that the lu- |
| 214 | * expiration timer is running. */ |
| 215 | if (vsub->expire_lu == VLR_SUBSCRIBER_NO_EXPIRATION) |
| 216 | vlr_subscr_enable_expire_lu(vsub); |
| 217 | |
Neels Hofmeyr | 7c5346c | 2019-02-19 02:36:35 +0100 | [diff] [blame] | 218 | vlr_subscr_put(vsub, __func__); |
Harald Welte | 0df904d | 2018-12-03 11:00:04 +0100 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | /*! Perform an SGs TMSI reallocation complete. |
| 222 | * \param[in] vsub VLR subscriber. |
| 223 | * \param[in] imsi mobile identity (IMSI). */ |
| 224 | void vlr_sgs_tmsi_reall_compl(struct vlr_instance *vlr, const char *imsi) |
| 225 | { |
| 226 | struct vlr_subscr *vsub; |
Neels Hofmeyr | 7c5346c | 2019-02-19 02:36:35 +0100 | [diff] [blame] | 227 | vsub = vlr_subscr_find_by_imsi(vlr, imsi, __func__); |
Harald Welte | 0df904d | 2018-12-03 11:00:04 +0100 | [diff] [blame] | 228 | if (!vsub) |
| 229 | return; |
| 230 | |
| 231 | osmo_fsm_inst_dispatch(vsub->sgs_fsm, SGS_UE_E_RX_TMSI_REALLOC, NULL); |
Neels Hofmeyr | 7c5346c | 2019-02-19 02:36:35 +0100 | [diff] [blame] | 232 | vlr_subscr_put(vsub, __func__); |
Harald Welte | 0df904d | 2018-12-03 11:00:04 +0100 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | /*! Notify that an SGs paging has been rejected by the MME. |
| 236 | * \param[in] vsub VLR subscriber. |
| 237 | * \param[in] imsi mobile identity (IMSI). |
| 238 | * \param[in] cause SGs cause code. */ |
| 239 | void vlr_sgs_pag_rej(struct vlr_instance *vlr, const char *imsi, enum sgsap_sgs_cause cause) |
| 240 | { |
| 241 | struct vlr_subscr *vsub; |
Neels Hofmeyr | 7c5346c | 2019-02-19 02:36:35 +0100 | [diff] [blame] | 242 | vsub = vlr_subscr_find_by_imsi(vlr, imsi, __func__); |
Harald Welte | 0df904d | 2018-12-03 11:00:04 +0100 | [diff] [blame] | 243 | if (!vsub) |
| 244 | return; |
| 245 | |
| 246 | /* On the reception of a paging rej the VLR is supposed to stop Ts5, |
| 247 | also 3GPP TS 29.118, chapter 5.1.2.4 */ |
| 248 | osmo_timer_del(&vsub->sgs.Ts5); |
| 249 | LOGP(DSGS, LOGL_DEBUG, "(sub %s) Paging via SGs interface rejected by MME, %s stopped, cause: %s!\n", |
| 250 | vlr_subscr_msisdn_or_name(vsub), vlr_sgs_state_timer_name(SGS_STATE_TS5), sgsap_sgs_cause_name(cause)); |
| 251 | |
| 252 | osmo_fsm_inst_dispatch(vsub->sgs_fsm, SGS_UE_E_RX_PAGING_FAILURE, &cause); |
Harald Welte | 0df904d | 2018-12-03 11:00:04 +0100 | [diff] [blame] | 253 | /* Balance ref count increment from vlr_sgs_pag() */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 254 | vlr_subscr_put(vsub, VSUB_USE_SGS_PAGING_REQ); |
Neels Hofmeyr | 7c5346c | 2019-02-19 02:36:35 +0100 | [diff] [blame] | 255 | |
| 256 | vlr_subscr_put(vsub, __func__); |
Harald Welte | 0df904d | 2018-12-03 11:00:04 +0100 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | /*! Notify that an SGs paging has been accepted by the MME. |
| 260 | * \param[in] vsub VLR subscriber. |
| 261 | * \param[in] imsi mobile identity (IMSI). */ |
| 262 | void vlr_sgs_pag_ack(struct vlr_instance *vlr, const char *imsi) |
| 263 | { |
| 264 | struct vlr_subscr *vsub; |
Neels Hofmeyr | 7c5346c | 2019-02-19 02:36:35 +0100 | [diff] [blame] | 265 | vsub = vlr_subscr_find_by_imsi(vlr, imsi, __func__); |
Harald Welte | 0df904d | 2018-12-03 11:00:04 +0100 | [diff] [blame] | 266 | if (!vsub) |
| 267 | return; |
| 268 | |
| 269 | /* Stop Ts5 and and consider the paging as successful */ |
| 270 | osmo_timer_del(&vsub->sgs.Ts5); |
Harald Welte | 0df904d | 2018-12-03 11:00:04 +0100 | [diff] [blame] | 271 | /* Balance ref count increment from vlr_sgs_pag() */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 272 | vlr_subscr_put(vsub, VSUB_USE_SGS_PAGING_REQ); |
Neels Hofmeyr | 7c5346c | 2019-02-19 02:36:35 +0100 | [diff] [blame] | 273 | |
| 274 | vlr_subscr_put(vsub, __func__); |
Harald Welte | 0df904d | 2018-12-03 11:00:04 +0100 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | /*! Notify that the UE has been marked as unreachable by the MME. |
| 278 | * \param[in] vsub VLR subscriber. |
| 279 | * \param[in] imsi mobile identity (IMSI). |
| 280 | * \param[in] cause SGs cause code. */ |
| 281 | void vlr_sgs_ue_unr(struct vlr_instance *vlr, const char *imsi, enum sgsap_sgs_cause cause) |
| 282 | { |
| 283 | struct vlr_subscr *vsub; |
Neels Hofmeyr | 7c5346c | 2019-02-19 02:36:35 +0100 | [diff] [blame] | 284 | vsub = vlr_subscr_find_by_imsi(vlr, imsi, __func__); |
Harald Welte | 0df904d | 2018-12-03 11:00:04 +0100 | [diff] [blame] | 285 | if (!vsub) |
| 286 | return; |
| 287 | |
| 288 | /* On the reception of an UE unreachable the VLR is supposed to stop |
| 289 | * Ts5, also 3GPP TS 29.118, chapter 5.1.2.5 */ |
| 290 | osmo_timer_del(&vsub->sgs.Ts5); |
| 291 | LOGP(DSGS, LOGL_DEBUG, |
| 292 | "(sub %s) Paging via SGs interface not possible, UE unreachable, %s stopped, cause: %s\n", |
| 293 | vlr_subscr_msisdn_or_name(vsub), vlr_sgs_state_timer_name(SGS_STATE_TS5), sgsap_sgs_cause_name(cause)); |
| 294 | |
| 295 | osmo_fsm_inst_dispatch(vsub->sgs_fsm, SGS_UE_E_RX_SGSAP_UE_UNREACHABLE, &cause); |
Neels Hofmeyr | 7c5346c | 2019-02-19 02:36:35 +0100 | [diff] [blame] | 296 | vlr_subscr_put(vsub, __func__); |
Harald Welte | 0df904d | 2018-12-03 11:00:04 +0100 | [diff] [blame] | 297 | } |
| 298 | |
| 299 | /* Callback function that is called when an SGs paging request times out */ |
| 300 | static void Ts5_timeout_cb(void *arg) |
| 301 | { |
| 302 | struct vlr_subscr *vsub = arg; |
| 303 | |
Martin Hauke | 3f07dac | 2019-11-14 17:49:08 +0100 | [diff] [blame] | 304 | /* 3GPP TS 29.118 does not specify a specific action that has to happen |
Harald Welte | 0df904d | 2018-12-03 11:00:04 +0100 | [diff] [blame] | 305 | * in case Ts5 times out. The timeout just indicates that the paging |
| 306 | * failed. Other actions may check the status of Ts5 to see if a paging |
| 307 | * is still ongoing or not. */ |
| 308 | |
| 309 | LOGP(DSGS, LOGL_ERROR, "(sub %s) Paging via SGs interface timed out (%s expired)!\n", |
| 310 | vlr_subscr_msisdn_or_name(vsub), vlr_sgs_state_timer_name(SGS_STATE_TS5)); |
| 311 | |
| 312 | /* Balance ref count increment from vlr_sgs_pag() */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 313 | vlr_subscr_put(vsub, VSUB_USE_SGS_PAGING_REQ); |
Harald Welte | 0df904d | 2018-12-03 11:00:04 +0100 | [diff] [blame] | 314 | |
| 315 | return; |
| 316 | } |
| 317 | |
| 318 | /*! Notify that a paging message has been sent and a paging is now in progress. |
| 319 | * \param[in] vsub VLR subscriber. */ |
| 320 | void vlr_sgs_pag(struct vlr_subscr *vsub, enum sgsap_service_ind serv_ind) |
| 321 | { |
| 322 | |
| 323 | /* In cases where we have to respawn a paging after an intermitted LU, |
| 324 | * there may e a Ts5 still running. In those cases we have to remove |
| 325 | * the old timer first */ |
| 326 | if (osmo_timer_pending(&vsub->sgs.Ts5)) |
| 327 | osmo_timer_del(&vsub->sgs.Ts5); |
| 328 | |
| 329 | /* Note: 3GPP TS 29.118, chapter 4.2.2 mentions paging in the FSM |
| 330 | * diagram, but paging never causes a state transition except when |
| 331 | * an explicit failure is indicated (MME actively rejects paging). |
Martin Hauke | 3f07dac | 2019-11-14 17:49:08 +0100 | [diff] [blame] | 332 | * Apparently it is also possible that an LU happens while the paging |
Harald Welte | 0df904d | 2018-12-03 11:00:04 +0100 | [diff] [blame] | 333 | * is still ongoing and Ts5 is running. (chapter 5.1.2.3). This means |
| 334 | * that the paging procedure is intended to run in parallel to the |
| 335 | * SGs FSM and given that the benaviour around Ts5 must be implemented |
| 336 | * also separately, to emphasize this separation Ts5 is implemented |
| 337 | * here in and not in vlr_sgs_fsm.c. */ |
| 338 | osmo_timer_setup(&vsub->sgs.Ts5, Ts5_timeout_cb, vsub); |
| 339 | osmo_timer_schedule(&vsub->sgs.Ts5, vsub->sgs.cfg.timer[SGS_STATE_TS5], 0); |
| 340 | |
| 341 | /* Formally 3GPP TS 29.118 defines the sending of a paging request |
| 342 | * as an event, but as far as the VLR is concerned only Ts5 is |
| 343 | * started. */ |
| 344 | osmo_fsm_inst_dispatch(vsub->sgs_fsm, SGS_UE_E_TX_PAGING, NULL); |
| 345 | |
| 346 | /* Memorize service type in for the case that the paging must be |
| 347 | * respawned after an LU */ |
| 348 | vsub->sgs.paging_serv_ind = serv_ind; |
| 349 | |
| 350 | /* Ensure that the reference count is increased by one while the |
| 351 | * paging is happening. We will balance this again in vlr_sgs_pag_rej() |
| 352 | * and vlr_sgs_pag_ack(); */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 353 | vlr_subscr_get(vsub, VSUB_USE_SGS_PAGING_REQ); |
Harald Welte | 0df904d | 2018-12-03 11:00:04 +0100 | [diff] [blame] | 354 | } |
| 355 | |
| 356 | /*! Check if the SGs interface is currently paging |
| 357 | * \param[in] vsub VLR subscriber. */ |
| 358 | bool vlr_sgs_pag_pend(struct vlr_subscr *vsub) |
| 359 | { |
| 360 | return osmo_timer_pending(&vsub->sgs.Ts5); |
| 361 | } |