Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1 | /* GSM Mobile Radio Interface Layer 3 messages on the A-bis interface |
| 2 | * 3GPP TS 04.08 version 7.21.0 Release 1998 / ETSI TS 100 940 V7.21.0 */ |
| 3 | |
Harald Welte | 9f1f3ad | 2010-05-02 12:56:57 +0200 | [diff] [blame] | 4 | /* (C) 2009-2010 by Harald Welte <laforge@gnumonks.org> |
Harald Welte | c2e8cc4 | 2010-05-31 20:23:38 +0200 | [diff] [blame] | 5 | * (C) 2010 by On-Waves |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 6 | * |
| 7 | * All Rights Reserved |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 10 | * it under the terms of the GNU Affero General Public License as published by |
| 11 | * the Free Software Foundation; either version 3 of the License, or |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 12 | * (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 17 | * GNU Affero General Public License for more details. |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 18 | * |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 19 | * You should have received a copy of the GNU Affero General Public License |
| 20 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 21 | * |
| 22 | */ |
| 23 | |
| 24 | #include <stdio.h> |
| 25 | #include <stdlib.h> |
| 26 | #include <string.h> |
Harald Welte | eaa614c | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 27 | #include <stdint.h> |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 28 | #include <errno.h> |
| 29 | |
| 30 | #include <netinet/in.h> |
Harald Welte | 421cba4 | 2010-05-02 23:11:50 +0200 | [diff] [blame] | 31 | #include <arpa/inet.h> |
Holger Hans Peter Freyther | 39c430e | 2015-05-25 12:26:49 +0800 | [diff] [blame] | 32 | #include <netdb.h> |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 33 | |
| 34 | #include <openbsc/db.h> |
Pablo Neira Ayuso | 136f453 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 35 | #include <osmocom/core/msgb.h> |
Harald Welte | d36ff76 | 2011-03-23 18:26:56 +0100 | [diff] [blame] | 36 | #include <osmocom/gsm/tlv.h> |
| 37 | #include <osmocom/gsm/gsm_utils.h> |
Pablo Neira Ayuso | 136f453 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 38 | #include <osmocom/core/signal.h> |
| 39 | #include <osmocom/core/talloc.h> |
| 40 | #include <osmocom/core/rate_ctr.h> |
Holger Hans Peter Freyther | 39c430e | 2015-05-25 12:26:49 +0800 | [diff] [blame] | 41 | #include <osmocom/gsm/apn.h> |
Harald Welte | d605709 | 2010-05-02 12:57:45 +0200 | [diff] [blame] | 42 | |
Harald Welte | ea34a4e | 2012-06-16 14:59:56 +0800 | [diff] [blame] | 43 | #include <osmocom/gprs/gprs_bssgp.h> |
| 44 | |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 45 | #include <openbsc/debug.h> |
| 46 | #include <openbsc/gsm_data.h> |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 47 | #include <openbsc/gsm_subscriber.h> |
| 48 | #include <openbsc/gsm_04_08.h> |
| 49 | #include <openbsc/gsm_04_08_gprs.h> |
| 50 | #include <openbsc/paging.h> |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 51 | #include <openbsc/transaction.h> |
| 52 | #include <openbsc/gprs_llc.h> |
| 53 | #include <openbsc/gprs_sgsn.h> |
Harald Welte | 6abf94e | 2010-05-18 10:35:06 +0200 | [diff] [blame] | 54 | #include <openbsc/gprs_gmm.h> |
Jacob Erlbeck | 8de9c48 | 2015-01-23 11:44:39 +0100 | [diff] [blame] | 55 | #include <openbsc/gprs_utils.h> |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 56 | #include <openbsc/sgsn.h> |
Holger Hans Peter Freyther | b100895 | 2015-05-02 19:55:38 +0200 | [diff] [blame] | 57 | #include <openbsc/signal.h> |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 58 | |
Harald Welte | 6abf94e | 2010-05-18 10:35:06 +0200 | [diff] [blame] | 59 | #include <pdp.h> |
| 60 | |
Harald Welte | c2e8cc4 | 2010-05-31 20:23:38 +0200 | [diff] [blame] | 61 | #define PTMSI_ALLOC |
| 62 | |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 63 | extern struct sgsn_instance *sgsn; |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 64 | |
Harald Welte | 588d44e | 2010-06-09 10:28:29 +0200 | [diff] [blame] | 65 | static const struct tlv_definition gsm48_gmm_att_tlvdef = { |
| 66 | .def = { |
Harald Welte | 4b6ac1e | 2010-07-03 11:09:06 +0200 | [diff] [blame] | 67 | [GSM48_IE_GMM_CIPH_CKSN] = { TLV_TYPE_FIXED, 1 }, |
Harald Welte | 588d44e | 2010-06-09 10:28:29 +0200 | [diff] [blame] | 68 | [GSM48_IE_GMM_TIMER_READY] = { TLV_TYPE_TV, 1 }, |
| 69 | [GSM48_IE_GMM_ALLOC_PTMSI] = { TLV_TYPE_TLV, 0 }, |
Harald Welte | 4b6ac1e | 2010-07-03 11:09:06 +0200 | [diff] [blame] | 70 | [GSM48_IE_GMM_PTMSI_SIG] = { TLV_TYPE_FIXED, 3 }, |
| 71 | [GSM48_IE_GMM_AUTH_RAND] = { TLV_TYPE_FIXED, 16 }, |
| 72 | [GSM48_IE_GMM_AUTH_SRES] = { TLV_TYPE_FIXED, 4 }, |
Harald Welte | 588d44e | 2010-06-09 10:28:29 +0200 | [diff] [blame] | 73 | [GSM48_IE_GMM_IMEISV] = { TLV_TYPE_TLV, 0 }, |
Harald Welte | 4b6ac1e | 2010-07-03 11:09:06 +0200 | [diff] [blame] | 74 | [GSM48_IE_GMM_DRX_PARAM] = { TLV_TYPE_FIXED, 2 }, |
Harald Welte | 588d44e | 2010-06-09 10:28:29 +0200 | [diff] [blame] | 75 | [GSM48_IE_GMM_MS_NET_CAPA] = { TLV_TYPE_TLV, 0 }, |
| 76 | [GSM48_IE_GMM_PDP_CTX_STATUS] = { TLV_TYPE_TLV, 0 }, |
| 77 | [GSM48_IE_GMM_PS_LCS_CAPA] = { TLV_TYPE_TLV, 0 }, |
| 78 | [GSM48_IE_GMM_GMM_MBMS_CTX_ST] = { TLV_TYPE_TLV, 0 }, |
| 79 | }, |
| 80 | }; |
| 81 | |
| 82 | static const struct tlv_definition gsm48_sm_att_tlvdef = { |
| 83 | .def = { |
| 84 | [GSM48_IE_GSM_APN] = { TLV_TYPE_TLV, 0 }, |
| 85 | [GSM48_IE_GSM_PROTO_CONF_OPT] = { TLV_TYPE_TLV, 0 }, |
| 86 | [GSM48_IE_GSM_PDP_ADDR] = { TLV_TYPE_TLV, 0 }, |
| 87 | [GSM48_IE_GSM_AA_TMR] = { TLV_TYPE_TV, 1 }, |
| 88 | [GSM48_IE_GSM_NAME_FULL] = { TLV_TYPE_TLV, 0 }, |
| 89 | [GSM48_IE_GSM_NAME_SHORT] = { TLV_TYPE_TLV, 0 }, |
Harald Welte | 4b6ac1e | 2010-07-03 11:09:06 +0200 | [diff] [blame] | 90 | [GSM48_IE_GSM_TIMEZONE] = { TLV_TYPE_FIXED, 1 }, |
| 91 | [GSM48_IE_GSM_UTC_AND_TZ] = { TLV_TYPE_FIXED, 7 }, |
Harald Welte | 588d44e | 2010-06-09 10:28:29 +0200 | [diff] [blame] | 92 | [GSM48_IE_GSM_LSA_ID] = { TLV_TYPE_TLV, 0 }, |
| 93 | }, |
| 94 | }; |
| 95 | |
Jacob Erlbeck | 4adb136 | 2014-12-02 09:47:26 +0100 | [diff] [blame] | 96 | static int gsm48_gmm_authorize(struct sgsn_mm_ctx *ctx); |
| 97 | |
Harald Welte | 2720e73 | 2010-05-17 00:44:57 +0200 | [diff] [blame] | 98 | /* Our implementation, should be kept in SGSN */ |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 99 | |
Harald Welte | c2e8cc4 | 2010-05-31 20:23:38 +0200 | [diff] [blame] | 100 | static void mmctx_timer_cb(void *_mm); |
| 101 | |
| 102 | static void mmctx_timer_start(struct sgsn_mm_ctx *mm, unsigned int T, |
| 103 | unsigned int seconds) |
| 104 | { |
Pablo Neira Ayuso | bf540cb | 2011-05-06 12:11:06 +0200 | [diff] [blame] | 105 | if (osmo_timer_pending(&mm->timer)) |
Harald Welte | c2e8cc4 | 2010-05-31 20:23:38 +0200 | [diff] [blame] | 106 | LOGP(DMM, LOGL_ERROR, "Starting MM timer %u while old " |
| 107 | "timer %u pending\n", T, mm->T); |
| 108 | mm->T = T; |
| 109 | mm->num_T_exp = 0; |
| 110 | |
| 111 | /* FIXME: we should do this only once ? */ |
| 112 | mm->timer.data = mm; |
| 113 | mm->timer.cb = &mmctx_timer_cb; |
| 114 | |
Pablo Neira Ayuso | bf540cb | 2011-05-06 12:11:06 +0200 | [diff] [blame] | 115 | osmo_timer_schedule(&mm->timer, seconds, 0); |
Harald Welte | c2e8cc4 | 2010-05-31 20:23:38 +0200 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | static void mmctx_timer_stop(struct sgsn_mm_ctx *mm, unsigned int T) |
| 119 | { |
| 120 | if (mm->T != T) |
| 121 | LOGP(DMM, LOGL_ERROR, "Stopping MM timer %u but " |
| 122 | "%u is running\n", T, mm->T); |
Pablo Neira Ayuso | bf540cb | 2011-05-06 12:11:06 +0200 | [diff] [blame] | 123 | osmo_timer_del(&mm->timer); |
Harald Welte | c2e8cc4 | 2010-05-31 20:23:38 +0200 | [diff] [blame] | 124 | } |
| 125 | |
Jacob Erlbeck | 81ffb74 | 2015-01-23 11:33:51 +0100 | [diff] [blame] | 126 | time_t gprs_max_time_to_idle(void) |
| 127 | { |
Harald Welte | 9450882 | 2015-08-15 19:08:21 +0200 | [diff] [blame] | 128 | return sgsn->cfg.timers.T3314 + (sgsn->cfg.timers.T3312 + 4 * 60); |
Jacob Erlbeck | 81ffb74 | 2015-01-23 11:33:51 +0100 | [diff] [blame] | 129 | } |
| 130 | |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 131 | /* Send a message through the underlying layer */ |
Harald Welte | 8acd88f | 2010-05-18 10:57:45 +0200 | [diff] [blame] | 132 | static int gsm48_gmm_sendmsg(struct msgb *msg, int command, |
Holger Hans Peter Freyther | 2b17454 | 2011-10-14 23:31:34 +0200 | [diff] [blame] | 133 | struct sgsn_mm_ctx *mm) |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 134 | { |
Harald Welte | 8acd88f | 2010-05-18 10:57:45 +0200 | [diff] [blame] | 135 | if (mm) |
| 136 | rate_ctr_inc(&mm->ctrg->ctr[GMM_CTR_PKTS_SIG_OUT]); |
| 137 | |
Harald Welte | 11d7c10 | 2010-05-02 11:54:55 +0200 | [diff] [blame] | 138 | /* caller needs to provide TLLI, BVCI and NSEI */ |
Harald Welte | 56a0145 | 2010-05-31 22:12:30 +0200 | [diff] [blame] | 139 | return gprs_llc_tx_ui(msg, GPRS_SAPI_GMM, command, mm); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 140 | } |
| 141 | |
Harald Welte | 11d7c10 | 2010-05-02 11:54:55 +0200 | [diff] [blame] | 142 | /* copy identifiers from old message to new message, this |
| 143 | * is required so lower layers can route it correctly */ |
| 144 | static void gmm_copy_id(struct msgb *msg, const struct msgb *old) |
| 145 | { |
| 146 | msgb_tlli(msg) = msgb_tlli(old); |
| 147 | msgb_bvci(msg) = msgb_bvci(old); |
| 148 | msgb_nsei(msg) = msgb_nsei(old); |
| 149 | } |
| 150 | |
Harald Welte | 6abf94e | 2010-05-18 10:35:06 +0200 | [diff] [blame] | 151 | /* Store BVCI/NSEI in MM context */ |
| 152 | static void msgid2mmctx(struct sgsn_mm_ctx *mm, const struct msgb *msg) |
| 153 | { |
| 154 | mm->bvci = msgb_bvci(msg); |
| 155 | mm->nsei = msgb_nsei(msg); |
| 156 | } |
| 157 | |
| 158 | /* Store BVCI/NSEI in MM context */ |
| 159 | static void mmctx2msgid(struct msgb *msg, const struct sgsn_mm_ctx *mm) |
| 160 | { |
| 161 | msgb_tlli(msg) = mm->tlli; |
| 162 | msgb_bvci(msg) = mm->bvci; |
| 163 | msgb_nsei(msg) = mm->nsei; |
| 164 | } |
| 165 | |
Jacob Erlbeck | 99985b5 | 2014-10-13 10:32:00 +0200 | [diff] [blame] | 166 | static void mm_ctx_cleanup_free(struct sgsn_mm_ctx *ctx, const char *log_text) |
| 167 | { |
Jacob Erlbeck | e671d25 | 2015-01-26 14:43:07 +0100 | [diff] [blame] | 168 | LOGMMCTXP(LOGL_INFO, ctx, "Cleaning MM context due to %s\n", log_text); |
Jacob Erlbeck | 99985b5 | 2014-10-13 10:32:00 +0200 | [diff] [blame] | 169 | |
| 170 | /* Mark MM state as deregistered */ |
| 171 | ctx->mm_state = GMM_DEREGISTERED; |
| 172 | |
Jacob Erlbeck | e671d25 | 2015-01-26 14:43:07 +0100 | [diff] [blame] | 173 | sgsn_mm_ctx_cleanup_free(ctx); |
Jacob Erlbeck | 99985b5 | 2014-10-13 10:32:00 +0200 | [diff] [blame] | 174 | } |
| 175 | |
Harald Welte | f54e7e2 | 2010-06-09 10:51:23 +0200 | [diff] [blame] | 176 | /* Chapter 9.4.18 */ |
| 177 | static int _tx_status(struct msgb *msg, uint8_t cause, |
| 178 | struct sgsn_mm_ctx *mmctx, int sm) |
| 179 | { |
| 180 | struct gsm48_hdr *gh; |
| 181 | |
| 182 | /* MMCTX might be NULL! */ |
| 183 | |
| 184 | DEBUGP(DMM, "<- GPRS MM STATUS (cause: %s)\n", |
Jacob Erlbeck | afcf230 | 2015-01-05 17:30:02 +0100 | [diff] [blame] | 185 | get_value_string(gsm48_gmm_cause_names, cause)); |
Harald Welte | f54e7e2 | 2010-06-09 10:51:23 +0200 | [diff] [blame] | 186 | |
| 187 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 1); |
| 188 | if (sm) { |
| 189 | gh->proto_discr = GSM48_PDISC_SM_GPRS; |
| 190 | gh->msg_type = GSM48_MT_GSM_STATUS; |
| 191 | } else { |
| 192 | gh->proto_discr = GSM48_PDISC_MM_GPRS; |
| 193 | gh->msg_type = GSM48_MT_GMM_STATUS; |
| 194 | } |
| 195 | gh->data[0] = cause; |
| 196 | |
| 197 | return gsm48_gmm_sendmsg(msg, 0, mmctx); |
| 198 | } |
Jacob Erlbeck | 7067142 | 2014-10-29 22:57:30 +0100 | [diff] [blame] | 199 | |
Harald Welte | f54e7e2 | 2010-06-09 10:51:23 +0200 | [diff] [blame] | 200 | static int gsm48_tx_gmm_status(struct sgsn_mm_ctx *mmctx, uint8_t cause) |
| 201 | { |
| 202 | struct msgb *msg = gsm48_msgb_alloc(); |
| 203 | |
| 204 | mmctx2msgid(msg, mmctx); |
| 205 | return _tx_status(msg, cause, mmctx, 0); |
Harald Welte | f54e7e2 | 2010-06-09 10:51:23 +0200 | [diff] [blame] | 206 | } |
Jacob Erlbeck | 7067142 | 2014-10-29 22:57:30 +0100 | [diff] [blame] | 207 | |
Harald Welte | f54e7e2 | 2010-06-09 10:51:23 +0200 | [diff] [blame] | 208 | static int gsm48_tx_sm_status(struct sgsn_mm_ctx *mmctx, uint8_t cause) |
| 209 | { |
| 210 | struct msgb *msg = gsm48_msgb_alloc(); |
| 211 | |
| 212 | mmctx2msgid(msg, mmctx); |
| 213 | return _tx_status(msg, cause, mmctx, 1); |
Harald Welte | f54e7e2 | 2010-06-09 10:51:23 +0200 | [diff] [blame] | 214 | } |
| 215 | |
Jacob Erlbeck | 78ecaf0 | 2014-09-05 14:32:36 +0200 | [diff] [blame] | 216 | static int _tx_detach_req(struct msgb *msg, uint8_t detach_type, uint8_t cause, |
| 217 | struct sgsn_mm_ctx *mmctx) |
| 218 | { |
| 219 | struct gsm48_hdr *gh; |
| 220 | |
| 221 | /* MMCTX might be NULL! */ |
| 222 | |
| 223 | DEBUGP(DMM, "<- GPRS MM DETACH REQ (type: %s, cause: %s)\n", |
| 224 | get_value_string(gprs_det_t_mt_strs, detach_type), |
Jacob Erlbeck | afcf230 | 2015-01-05 17:30:02 +0100 | [diff] [blame] | 225 | get_value_string(gsm48_gmm_cause_names, cause)); |
Jacob Erlbeck | 78ecaf0 | 2014-09-05 14:32:36 +0200 | [diff] [blame] | 226 | |
| 227 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 1); |
| 228 | |
| 229 | gh->proto_discr = GSM48_PDISC_MM_GPRS; |
| 230 | gh->msg_type = GSM48_MT_GMM_DETACH_REQ; |
| 231 | gh->data[0] = detach_type & 0x07; |
| 232 | |
| 233 | msgb_tv_put(msg, GSM48_IE_GMM_CAUSE, cause); |
| 234 | |
| 235 | return gsm48_gmm_sendmsg(msg, 0, mmctx); |
| 236 | } |
| 237 | |
| 238 | static int gsm48_tx_gmm_detach_req(struct sgsn_mm_ctx *mmctx, |
| 239 | uint8_t detach_type, uint8_t cause) |
| 240 | { |
| 241 | struct msgb *msg = gsm48_msgb_alloc(); |
| 242 | |
| 243 | mmctx2msgid(msg, mmctx); |
| 244 | return _tx_detach_req(msg, detach_type, cause, mmctx); |
| 245 | } |
| 246 | |
| 247 | static int gsm48_tx_gmm_detach_req_oldmsg(struct msgb *oldmsg, |
| 248 | uint8_t detach_type, uint8_t cause) |
| 249 | { |
| 250 | struct msgb *msg = gsm48_msgb_alloc(); |
| 251 | |
| 252 | gmm_copy_id(msg, oldmsg); |
| 253 | return _tx_detach_req(msg, detach_type, cause, NULL); |
| 254 | } |
Harald Welte | f54e7e2 | 2010-06-09 10:51:23 +0200 | [diff] [blame] | 255 | |
Harald Welte | 86fda90 | 2010-05-03 10:54:35 +0200 | [diff] [blame] | 256 | static struct gsm48_qos default_qos = { |
| 257 | .delay_class = 4, /* best effort */ |
| 258 | .reliab_class = GSM48_QOS_RC_LLC_UN_RLC_ACK_DATA_PROT, |
| 259 | .peak_tput = GSM48_QOS_PEAK_TPUT_32000bps, |
| 260 | .preced_class = GSM48_QOS_PC_NORMAL, |
| 261 | .mean_tput = GSM48_QOS_MEAN_TPUT_BEST_EFFORT, |
| 262 | .traf_class = GSM48_QOS_TC_INTERACTIVE, |
| 263 | .deliv_order = GSM48_QOS_DO_UNORDERED, |
| 264 | .deliv_err_sdu = GSM48_QOS_ERRSDU_YES, |
| 265 | .max_sdu_size = GSM48_QOS_MAXSDU_1520, |
| 266 | .max_bitrate_up = GSM48_QOS_MBRATE_63k, |
| 267 | .max_bitrate_down = GSM48_QOS_MBRATE_63k, |
| 268 | .resid_ber = GSM48_QOS_RBER_5e_2, |
| 269 | .sdu_err_ratio = GSM48_QOS_SERR_1e_2, |
| 270 | .handling_prio = 3, |
| 271 | .xfer_delay = 0x10, /* 200ms */ |
| 272 | .guar_bitrate_up = GSM48_QOS_MBRATE_0k, |
| 273 | .guar_bitrate_down = GSM48_QOS_MBRATE_0k, |
| 274 | .sig_ind = 0, /* not optimised for signalling */ |
| 275 | .max_bitrate_down_ext = 0, /* use octet 9 */ |
| 276 | .guar_bitrate_down_ext = 0, /* use octet 13 */ |
| 277 | }; |
| 278 | |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 279 | /* Chapter 9.4.2: Attach accept */ |
Harald Welte | 6463c07 | 2010-05-18 17:04:55 +0200 | [diff] [blame] | 280 | static int gsm48_tx_gmm_att_ack(struct sgsn_mm_ctx *mm) |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 281 | { |
| 282 | struct msgb *msg = gsm48_msgb_alloc(); |
| 283 | struct gsm48_hdr *gh; |
| 284 | struct gsm48_attach_ack *aa; |
Holger Hans Peter Freyther | 1768a57 | 2014-04-04 12:40:34 +0200 | [diff] [blame] | 285 | uint8_t *mid; |
| 286 | #if 0 |
| 287 | uint8_t *ptsig; |
| 288 | #endif |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 289 | |
Daniel Willmann | 4655314 | 2014-09-03 17:46:44 +0200 | [diff] [blame] | 290 | LOGMMCTXP(LOGL_INFO, mm, "<- GPRS ATTACH ACCEPT (new P-TMSI=0x%08x)\n", mm->p_tmsi); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 291 | |
Harald Welte | 6463c07 | 2010-05-18 17:04:55 +0200 | [diff] [blame] | 292 | mmctx2msgid(msg, mm); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 293 | |
| 294 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 295 | gh->proto_discr = GSM48_PDISC_MM_GPRS; |
| 296 | gh->msg_type = GSM48_MT_GMM_ATTACH_ACK; |
| 297 | |
| 298 | aa = (struct gsm48_attach_ack *) msgb_put(msg, sizeof(*aa)); |
| 299 | aa->force_stby = 0; /* not indicated */ |
| 300 | aa->att_result = 1; /* GPRS only */ |
Harald Welte | 9450882 | 2015-08-15 19:08:21 +0200 | [diff] [blame] | 301 | aa->ra_upd_timer = gprs_secs_to_tmr_floor(sgsn->cfg.timers.T3312); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 302 | aa->radio_prio = 4; /* lowest */ |
Harald Welte | 6463c07 | 2010-05-18 17:04:55 +0200 | [diff] [blame] | 303 | gsm48_construct_ra(aa->ra_id.digits, &mm->ra); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 304 | |
Harald Welte | ab1d562 | 2010-05-18 19:58:38 +0200 | [diff] [blame] | 305 | #if 0 |
Harald Welte | 6463c07 | 2010-05-18 17:04:55 +0200 | [diff] [blame] | 306 | /* Optional: P-TMSI signature */ |
| 307 | msgb_v_put(msg, GSM48_IE_GMM_PTMSI_SIG); |
| 308 | ptsig = msgb_put(msg, 3); |
| 309 | ptsig[0] = mm->p_tmsi_sig >> 16; |
| 310 | ptsig[1] = mm->p_tmsi_sig >> 8; |
| 311 | ptsig[2] = mm->p_tmsi_sig & 0xff; |
| 312 | |
Harald Welte | c2e8cc4 | 2010-05-31 20:23:38 +0200 | [diff] [blame] | 313 | #endif |
Jacob Erlbeck | 8de9c48 | 2015-01-23 11:44:39 +0100 | [diff] [blame] | 314 | /* Optional: Negotiated Ready timer value |
| 315 | * (fixed 44s, default value, GSM 04.08, table 11.4a) to safely limit |
| 316 | * the inactivity time READY->STANDBY. |
| 317 | */ |
| 318 | msgb_tv_put(msg, GSM48_IE_GMM_TIMER_READY, |
Harald Welte | 9450882 | 2015-08-15 19:08:21 +0200 | [diff] [blame] | 319 | gprs_secs_to_tmr_floor(sgsn->cfg.timers.T3314)); |
Harald Welte | 6463c07 | 2010-05-18 17:04:55 +0200 | [diff] [blame] | 320 | |
Harald Welte | c2e8cc4 | 2010-05-31 20:23:38 +0200 | [diff] [blame] | 321 | #ifdef PTMSI_ALLOC |
Harald Welte | 6463c07 | 2010-05-18 17:04:55 +0200 | [diff] [blame] | 322 | /* Optional: Allocated P-TMSI */ |
Harald Welte | 6463c07 | 2010-05-18 17:04:55 +0200 | [diff] [blame] | 323 | mid = msgb_put(msg, GSM48_MID_TMSI_LEN); |
| 324 | gsm48_generate_mid_from_tmsi(mid, mm->p_tmsi); |
Harald Welte | ab1d562 | 2010-05-18 19:58:38 +0200 | [diff] [blame] | 325 | mid[0] = GSM48_IE_GMM_ALLOC_PTMSI; |
| 326 | #endif |
Harald Welte | c2e8cc4 | 2010-05-31 20:23:38 +0200 | [diff] [blame] | 327 | |
Harald Welte | 6463c07 | 2010-05-18 17:04:55 +0200 | [diff] [blame] | 328 | /* Optional: MS-identity (combined attach) */ |
| 329 | /* Optional: GMM cause (partial attach result for combined attach) */ |
| 330 | |
Harald Welte | 56a0145 | 2010-05-31 22:12:30 +0200 | [diff] [blame] | 331 | return gsm48_gmm_sendmsg(msg, 0, mm); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | /* Chapter 9.4.5: Attach reject */ |
Harald Welte | 6463c07 | 2010-05-18 17:04:55 +0200 | [diff] [blame] | 335 | static int _tx_gmm_att_rej(struct msgb *msg, uint8_t gmm_cause) |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 336 | { |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 337 | struct gsm48_hdr *gh; |
| 338 | |
Jacob Erlbeck | afcf230 | 2015-01-05 17:30:02 +0100 | [diff] [blame] | 339 | LOGP(DMM, LOGL_NOTICE, "<- GPRS ATTACH REJECT: %s\n", get_value_string(gsm48_gmm_cause_names, gmm_cause)); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 340 | |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 341 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 1); |
| 342 | gh->proto_discr = GSM48_PDISC_MM_GPRS; |
| 343 | gh->msg_type = GSM48_MT_GMM_ATTACH_REJ; |
| 344 | gh->data[0] = gmm_cause; |
| 345 | |
Harald Welte | 8acd88f | 2010-05-18 10:57:45 +0200 | [diff] [blame] | 346 | return gsm48_gmm_sendmsg(msg, 0, NULL); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 347 | } |
Harald Welte | 6463c07 | 2010-05-18 17:04:55 +0200 | [diff] [blame] | 348 | static int gsm48_tx_gmm_att_rej_oldmsg(const struct msgb *old_msg, |
| 349 | uint8_t gmm_cause) |
| 350 | { |
| 351 | struct msgb *msg = gsm48_msgb_alloc(); |
| 352 | gmm_copy_id(msg, old_msg); |
| 353 | return _tx_gmm_att_rej(msg, gmm_cause); |
| 354 | } |
| 355 | static int gsm48_tx_gmm_att_rej(struct sgsn_mm_ctx *mm, |
| 356 | uint8_t gmm_cause) |
| 357 | { |
| 358 | struct msgb *msg = gsm48_msgb_alloc(); |
| 359 | mmctx2msgid(msg, mm); |
| 360 | return _tx_gmm_att_rej(msg, gmm_cause); |
| 361 | } |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 362 | |
Harald Welte | 2720e73 | 2010-05-17 00:44:57 +0200 | [diff] [blame] | 363 | /* Chapter 9.4.6.2 Detach accept */ |
Jacob Erlbeck | 5a38f64 | 2014-10-21 13:09:55 +0200 | [diff] [blame] | 364 | static int _tx_detach_ack(struct msgb *msg, uint8_t force_stby, |
| 365 | struct sgsn_mm_ctx *mm) |
Harald Welte | 2720e73 | 2010-05-17 00:44:57 +0200 | [diff] [blame] | 366 | { |
Harald Welte | 2720e73 | 2010-05-17 00:44:57 +0200 | [diff] [blame] | 367 | struct gsm48_hdr *gh; |
| 368 | |
Jacob Erlbeck | 5a38f64 | 2014-10-21 13:09:55 +0200 | [diff] [blame] | 369 | /* MMCTX might be NULL! */ |
Harald Welte | 2720e73 | 2010-05-17 00:44:57 +0200 | [diff] [blame] | 370 | |
Jacob Erlbeck | 5a38f64 | 2014-10-21 13:09:55 +0200 | [diff] [blame] | 371 | DEBUGP(DMM, "<- GPRS MM DETACH ACC (force-standby: %d)\n", force_stby); |
Harald Welte | 6463c07 | 2010-05-18 17:04:55 +0200 | [diff] [blame] | 372 | |
Harald Welte | 2720e73 | 2010-05-17 00:44:57 +0200 | [diff] [blame] | 373 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 1); |
| 374 | gh->proto_discr = GSM48_PDISC_MM_GPRS; |
| 375 | gh->msg_type = GSM48_MT_GMM_DETACH_ACK; |
| 376 | gh->data[0] = force_stby; |
| 377 | |
Harald Welte | 56a0145 | 2010-05-31 22:12:30 +0200 | [diff] [blame] | 378 | return gsm48_gmm_sendmsg(msg, 0, mm); |
Harald Welte | 2720e73 | 2010-05-17 00:44:57 +0200 | [diff] [blame] | 379 | } |
| 380 | |
Jacob Erlbeck | 5a38f64 | 2014-10-21 13:09:55 +0200 | [diff] [blame] | 381 | static int gsm48_tx_gmm_det_ack(struct sgsn_mm_ctx *mm, uint8_t force_stby) |
| 382 | { |
| 383 | struct msgb *msg = gsm48_msgb_alloc(); |
| 384 | |
| 385 | mmctx2msgid(msg, mm); |
| 386 | return _tx_detach_ack(msg, force_stby, mm); |
| 387 | } |
| 388 | |
| 389 | static int gsm48_tx_gmm_det_ack_oldmsg(struct msgb *oldmsg, uint8_t force_stby) |
| 390 | { |
| 391 | struct msgb *msg = gsm48_msgb_alloc(); |
| 392 | |
| 393 | gmm_copy_id(msg, oldmsg); |
| 394 | return _tx_detach_ack(msg, force_stby, NULL); |
| 395 | } |
| 396 | |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 397 | /* Transmit Chapter 9.4.12 Identity Request */ |
Harald Welte | 6463c07 | 2010-05-18 17:04:55 +0200 | [diff] [blame] | 398 | static int gsm48_tx_gmm_id_req(struct sgsn_mm_ctx *mm, uint8_t id_type) |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 399 | { |
| 400 | struct msgb *msg = gsm48_msgb_alloc(); |
| 401 | struct gsm48_hdr *gh; |
| 402 | |
Daniel Willmann | 4655314 | 2014-09-03 17:46:44 +0200 | [diff] [blame] | 403 | LOGMMCTXP(LOGL_DEBUG, mm, "<- GPRS IDENTITY REQUEST: mi_type=%02x\n", id_type); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 404 | |
Harald Welte | 6463c07 | 2010-05-18 17:04:55 +0200 | [diff] [blame] | 405 | mmctx2msgid(msg, mm); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 406 | |
| 407 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 1); |
| 408 | gh->proto_discr = GSM48_PDISC_MM_GPRS; |
| 409 | gh->msg_type = GSM48_MT_GMM_ID_REQ; |
| 410 | /* 10.5.5.9 ID type 2 + identity type and 10.5.5.7 'force to standby' IE */ |
| 411 | gh->data[0] = id_type & 0xf; |
| 412 | |
Harald Welte | dce1255 | 2010-05-31 22:31:04 +0200 | [diff] [blame] | 413 | return gsm48_gmm_sendmsg(msg, 1, mm); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 414 | } |
| 415 | |
Harald Welte | 4b6ac1e | 2010-07-03 11:09:06 +0200 | [diff] [blame] | 416 | /* Section 9.4.9: Authentication and Ciphering Request */ |
| 417 | static int gsm48_tx_gmm_auth_ciph_req(struct sgsn_mm_ctx *mm, uint8_t *rand, |
| 418 | uint8_t key_seq, uint8_t algo) |
| 419 | { |
| 420 | struct msgb *msg = gsm48_msgb_alloc(); |
| 421 | struct gsm48_hdr *gh; |
| 422 | struct gsm48_auth_ciph_req *acreq; |
| 423 | uint8_t *m_rand, *m_cksn; |
| 424 | |
Daniel Willmann | 4655314 | 2014-09-03 17:46:44 +0200 | [diff] [blame] | 425 | LOGMMCTXP(LOGL_INFO, mm, "<- GPRS AUTH AND CIPHERING REQ (rand = %s)\n", |
Pablo Neira Ayuso | c0d17f2 | 2011-05-07 12:12:48 +0200 | [diff] [blame] | 426 | osmo_hexdump(rand, 16)); |
Harald Welte | 4b6ac1e | 2010-07-03 11:09:06 +0200 | [diff] [blame] | 427 | |
| 428 | mmctx2msgid(msg, mm); |
| 429 | |
| 430 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 431 | gh->proto_discr = GSM48_PDISC_MM_GPRS; |
| 432 | gh->msg_type = GSM48_MT_GMM_AUTH_CIPH_REQ; |
| 433 | |
| 434 | acreq = (struct gsm48_auth_ciph_req *) msgb_put(msg, sizeof(*acreq)); |
| 435 | acreq->ciph_alg = algo & 0xf; |
| 436 | acreq->imeisv_req = 0x1; |
| 437 | acreq->force_stby = 0x0; |
| 438 | acreq->ac_ref_nr = 0x0; /* FIXME: increment this? */ |
| 439 | |
| 440 | /* Only if authentication is requested we need to set RAND + CKSN */ |
| 441 | if (rand) { |
| 442 | m_rand = msgb_put(msg, 16+1); |
| 443 | m_rand[0] = GSM48_IE_GMM_AUTH_RAND; |
| 444 | memcpy(m_rand+1, rand, 16); |
| 445 | |
Jacob Erlbeck | 65d8273 | 2014-12-01 10:36:17 +0100 | [diff] [blame] | 446 | m_cksn = msgb_put(msg, 1); |
| 447 | m_cksn[0] = (GSM48_IE_GMM_CIPH_CKSN << 4) | (key_seq & 0x07); |
Harald Welte | 4b6ac1e | 2010-07-03 11:09:06 +0200 | [diff] [blame] | 448 | } |
| 449 | |
Harald Welte | 4b6ac1e | 2010-07-03 11:09:06 +0200 | [diff] [blame] | 450 | /* FIXME: make sure we don't send any other messages to the MS */ |
| 451 | |
| 452 | return gsm48_gmm_sendmsg(msg, 1, mm); |
| 453 | } |
| 454 | |
| 455 | /* Section 9.4.11: Authentication and Ciphering Reject */ |
| 456 | static int gsm48_tx_gmm_auth_ciph_rej(struct sgsn_mm_ctx *mm) |
| 457 | { |
| 458 | struct msgb *msg = gsm48_msgb_alloc(); |
| 459 | struct gsm48_hdr *gh; |
| 460 | |
Daniel Willmann | 4655314 | 2014-09-03 17:46:44 +0200 | [diff] [blame] | 461 | LOGMMCTXP(LOGL_NOTICE, mm, "<- GPRS AUTH AND CIPH REJECT\n"); |
Harald Welte | 4b6ac1e | 2010-07-03 11:09:06 +0200 | [diff] [blame] | 462 | |
| 463 | mmctx2msgid(msg, mm); |
| 464 | |
| 465 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 466 | gh->proto_discr = GSM48_PDISC_MM_GPRS; |
| 467 | gh->msg_type = GSM48_MT_GMM_AUTH_CIPH_REJ; |
| 468 | |
| 469 | return gsm48_gmm_sendmsg(msg, 0, mm); |
| 470 | } |
| 471 | |
| 472 | /* Section 9.4.10: Authentication and Ciphering Response */ |
| 473 | static int gsm48_rx_gmm_auth_ciph_resp(struct sgsn_mm_ctx *ctx, |
| 474 | struct msgb *msg) |
| 475 | { |
| 476 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_gmmh(msg); |
| 477 | struct gsm48_auth_ciph_resp *acr = (struct gsm48_auth_ciph_resp *)gh->data; |
| 478 | struct tlv_parsed tp; |
Jacob Erlbeck | 8ff3fb0 | 2014-12-01 12:44:24 +0100 | [diff] [blame] | 479 | struct gsm_auth_tuple *at; |
| 480 | int rc; |
| 481 | |
| 482 | LOGMMCTXP(LOGL_INFO, ctx, "-> GPRS AUTH AND CIPH RESPONSE\n"); |
| 483 | |
| 484 | if (ctx->auth_triplet.key_seq == GSM_KEY_SEQ_INVAL) { |
| 485 | LOGMMCTXP(LOGL_NOTICE, ctx, |
| 486 | "Unexpected Auth & Ciph Response (ignored)\n"); |
| 487 | return 0; |
| 488 | } |
Harald Welte | 4b6ac1e | 2010-07-03 11:09:06 +0200 | [diff] [blame] | 489 | |
Jacob Erlbeck | bd0cf11 | 2014-12-01 12:33:33 +0100 | [diff] [blame] | 490 | /* Stop T3360 */ |
| 491 | mmctx_timer_stop(ctx, 3360); |
Harald Welte | 4b6ac1e | 2010-07-03 11:09:06 +0200 | [diff] [blame] | 492 | |
Holger Hans Peter Freyther | 1768a57 | 2014-04-04 12:40:34 +0200 | [diff] [blame] | 493 | tlv_parse(&tp, &gsm48_gmm_att_tlvdef, acr->data, |
Harald Welte | 4b6ac1e | 2010-07-03 11:09:06 +0200 | [diff] [blame] | 494 | (msg->data + msg->len) - acr->data, 0, 0); |
| 495 | |
| 496 | /* FIXME: compare ac_ref? */ |
| 497 | |
| 498 | if (!TLVP_PRESENT(&tp, GSM48_IE_GMM_AUTH_SRES) || |
| 499 | !TLVP_PRESENT(&tp, GSM48_IE_GMM_IMEISV)) { |
Jacob Erlbeck | 8ff3fb0 | 2014-12-01 12:44:24 +0100 | [diff] [blame] | 500 | /* TODO: missing mandatory IE, return STATUS or REJ? */ |
| 501 | LOGMMCTXP(LOGL_ERROR, ctx, "Missing mandantory IE\n"); |
| 502 | return -EINVAL; |
Harald Welte | 4b6ac1e | 2010-07-03 11:09:06 +0200 | [diff] [blame] | 503 | } |
| 504 | |
Jacob Erlbeck | 8ff3fb0 | 2014-12-01 12:44:24 +0100 | [diff] [blame] | 505 | /* Compare SRES with what we expected */ |
| 506 | LOGMMCTXP(LOGL_DEBUG, ctx, "checking received auth info, SRES = %s\n", |
| 507 | osmo_hexdump(TLVP_VAL(&tp, GSM48_IE_GMM_AUTH_SRES), |
| 508 | TLVP_LEN(&tp, GSM48_IE_GMM_AUTH_SRES))); |
| 509 | |
| 510 | at = &ctx->auth_triplet; |
| 511 | |
| 512 | if (TLVP_LEN(&tp, GSM48_IE_GMM_AUTH_SRES) != sizeof(at->sres) || |
| 513 | memcmp(TLVP_VAL(&tp, GSM48_IE_GMM_AUTH_SRES), at->sres, |
| 514 | sizeof(at->sres)) != 0) { |
| 515 | |
| 516 | LOGMMCTXP(LOGL_NOTICE, ctx, "Received SRES doesn't match\n"); |
| 517 | rc = gsm48_tx_gmm_auth_ciph_rej(ctx); |
| 518 | mm_ctx_cleanup_free(ctx, "GPRS AUTH AND CIPH REJECT"); |
| 519 | return rc; |
| 520 | } |
| 521 | |
| 522 | ctx->is_authenticated = 1; |
| 523 | |
Harald Welte | 4b6ac1e | 2010-07-03 11:09:06 +0200 | [diff] [blame] | 524 | /* FIXME: enable LLC cipheirng */ |
Jacob Erlbeck | 4adb136 | 2014-12-02 09:47:26 +0100 | [diff] [blame] | 525 | |
| 526 | /* Check if we can let the mobile station enter */ |
| 527 | return gsm48_gmm_authorize(ctx); |
Harald Welte | 4b6ac1e | 2010-07-03 11:09:06 +0200 | [diff] [blame] | 528 | } |
| 529 | |
Holger Hans Peter Freyther | 20de3ae | 2015-05-05 22:52:40 +0200 | [diff] [blame] | 530 | static void extract_subscr_msisdn(struct sgsn_mm_ctx *ctx) |
| 531 | { |
| 532 | struct gsm_mncc_number called; |
| 533 | uint8_t msisdn[sizeof(ctx->subscr->sgsn_data->msisdn) + 1]; |
| 534 | |
| 535 | /* Convert MSISDN from encoded to string.. */ |
| 536 | if (!ctx->subscr) |
| 537 | return; |
| 538 | |
| 539 | if (ctx->subscr->sgsn_data->msisdn_len < 1) |
| 540 | return; |
| 541 | |
| 542 | /* prepare the data for the decoder */ |
| 543 | memset(&called, 0, sizeof(called)); |
| 544 | msisdn[0] = ctx->subscr->sgsn_data->msisdn_len; |
| 545 | memcpy(&msisdn[1], ctx->subscr->sgsn_data->msisdn, |
| 546 | ctx->subscr->sgsn_data->msisdn_len); |
| 547 | |
| 548 | /* decode the string now */ |
| 549 | gsm48_decode_called(&called, msisdn); |
| 550 | |
| 551 | /* Prepend a '+' for international numbers */ |
| 552 | if (called.plan == 1 && called.type == 1) { |
| 553 | ctx->msisdn[0] = '+'; |
| 554 | strncpy(&ctx->msisdn[1], called.number, |
| 555 | sizeof(ctx->msisdn) - 1); |
| 556 | } else { |
| 557 | strncpy(&ctx->msisdn[0], called.number, |
| 558 | sizeof(ctx->msisdn) - 1); |
| 559 | } |
| 560 | } |
| 561 | |
Holger Hans Peter Freyther | 8ee13e2 | 2015-05-18 10:00:03 +0200 | [diff] [blame] | 562 | static void extract_subscr_hlr(struct sgsn_mm_ctx *ctx) |
| 563 | { |
| 564 | struct gsm_mncc_number called; |
| 565 | uint8_t hlr_number[sizeof(ctx->subscr->sgsn_data->hlr) + 1]; |
| 566 | |
| 567 | if (!ctx->subscr) |
| 568 | return; |
| 569 | |
| 570 | if (ctx->subscr->sgsn_data->hlr_len < 1) |
| 571 | return; |
| 572 | |
| 573 | /* prepare the data for the decoder */ |
| 574 | memset(&called, 0, sizeof(called)); |
| 575 | hlr_number[0] = ctx->subscr->sgsn_data->hlr_len; |
| 576 | memcpy(&hlr_number[1], ctx->subscr->sgsn_data->hlr, |
| 577 | ctx->subscr->sgsn_data->hlr_len); |
| 578 | |
| 579 | /* decode the string now */ |
| 580 | gsm48_decode_called(&called, hlr_number); |
| 581 | |
| 582 | if (called.plan != 1) { |
| 583 | LOGMMCTXP(LOGL_ERROR, ctx, |
| 584 | "Numbering plan(%d) not allowed\n", |
| 585 | called.plan); |
| 586 | return; |
| 587 | } |
| 588 | |
| 589 | if (called.type != 1) { |
| 590 | LOGMMCTXP(LOGL_ERROR, ctx, |
| 591 | "Numbering type(%d) not allowed\n", |
| 592 | called.type); |
| 593 | return; |
| 594 | } |
| 595 | |
| 596 | strncpy(&ctx->hlr[0], called.number, sizeof(ctx->hlr) - 1); |
| 597 | } |
| 598 | |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 599 | /* Check if we can already authorize a subscriber */ |
Jacob Erlbeck | 93eae8e | 2014-10-28 12:23:29 +0100 | [diff] [blame] | 600 | static int gsm48_gmm_authorize(struct sgsn_mm_ctx *ctx) |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 601 | { |
Holger Hans Peter Freyther | b100895 | 2015-05-02 19:55:38 +0200 | [diff] [blame] | 602 | #ifndef PTMSI_ALLOC |
| 603 | struct sgsn_signal_data sig_data; |
| 604 | #endif |
| 605 | |
Jacob Erlbeck | 93eae8e | 2014-10-28 12:23:29 +0100 | [diff] [blame] | 606 | /* Request IMSI and IMEI from the MS if they are unknown */ |
Harald Welte | c2e8cc4 | 2010-05-31 20:23:38 +0200 | [diff] [blame] | 607 | if (!strlen(ctx->imei)) { |
Harald Welte | c2e8cc4 | 2010-05-31 20:23:38 +0200 | [diff] [blame] | 608 | ctx->t3370_id_type = GSM_MI_TYPE_IMEI; |
Harald Welte | 9450882 | 2015-08-15 19:08:21 +0200 | [diff] [blame] | 609 | mmctx_timer_start(ctx, 3370, sgsn->cfg.timers.T3370); |
Harald Welte | 6463c07 | 2010-05-18 17:04:55 +0200 | [diff] [blame] | 610 | return gsm48_tx_gmm_id_req(ctx, GSM_MI_TYPE_IMEI); |
Harald Welte | c2e8cc4 | 2010-05-31 20:23:38 +0200 | [diff] [blame] | 611 | } |
Harald Welte | c2e8cc4 | 2010-05-31 20:23:38 +0200 | [diff] [blame] | 612 | if (!strlen(ctx->imsi)) { |
Harald Welte | c2e8cc4 | 2010-05-31 20:23:38 +0200 | [diff] [blame] | 613 | ctx->t3370_id_type = GSM_MI_TYPE_IMSI; |
Harald Welte | 9450882 | 2015-08-15 19:08:21 +0200 | [diff] [blame] | 614 | mmctx_timer_start(ctx, 3370, sgsn->cfg.timers.T3370); |
Harald Welte | 6463c07 | 2010-05-18 17:04:55 +0200 | [diff] [blame] | 615 | return gsm48_tx_gmm_id_req(ctx, GSM_MI_TYPE_IMSI); |
Harald Welte | c2e8cc4 | 2010-05-31 20:23:38 +0200 | [diff] [blame] | 616 | } |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 617 | |
Jacob Erlbeck | 93eae8e | 2014-10-28 12:23:29 +0100 | [diff] [blame] | 618 | /* All information required for authentication is available */ |
Jacob Erlbeck | 93eae8e | 2014-10-28 12:23:29 +0100 | [diff] [blame] | 619 | ctx->t3370_id_type = GSM_MI_TYPE_NONE; |
| 620 | |
Jacob Erlbeck | 423f8bf | 2014-10-24 18:09:54 +0200 | [diff] [blame] | 621 | if (ctx->auth_state == SGSN_AUTH_UNKNOWN) { |
| 622 | /* Request authorization, this leads to a call to |
Jacob Erlbeck | f951a01 | 2014-11-07 14:17:44 +0100 | [diff] [blame] | 623 | * sgsn_auth_update which in turn calls |
Jacob Erlbeck | 423f8bf | 2014-10-24 18:09:54 +0200 | [diff] [blame] | 624 | * gsm0408_gprs_access_granted or gsm0408_gprs_access_denied */ |
| 625 | |
Jacob Erlbeck | a0b6efb | 2014-11-13 10:48:39 +0100 | [diff] [blame] | 626 | sgsn_auth_request(ctx); |
Jacob Erlbeck | 423f8bf | 2014-10-24 18:09:54 +0200 | [diff] [blame] | 627 | /* Note that gsm48_gmm_authorize can be called recursively via |
| 628 | * sgsn_auth_request iff ctx->auth_info changes to AUTH_ACCEPTED |
| 629 | */ |
| 630 | return 0; |
| 631 | } |
| 632 | |
Jacob Erlbeck | 4adb136 | 2014-12-02 09:47:26 +0100 | [diff] [blame] | 633 | if (ctx->auth_state == SGSN_AUTH_AUTHENTICATE && !ctx->is_authenticated) { |
| 634 | struct gsm_auth_tuple *at = &ctx->auth_triplet; |
| 635 | |
Harald Welte | 9450882 | 2015-08-15 19:08:21 +0200 | [diff] [blame] | 636 | mmctx_timer_start(ctx, 3360, sgsn->cfg.timers.T3360); |
Jacob Erlbeck | 4adb136 | 2014-12-02 09:47:26 +0100 | [diff] [blame] | 637 | return gsm48_tx_gmm_auth_ciph_req(ctx, at->rand, at->key_seq, |
| 638 | GPRS_ALGO_GEA0); |
| 639 | } |
| 640 | |
| 641 | if (ctx->auth_state == SGSN_AUTH_AUTHENTICATE && ctx->is_authenticated && |
| 642 | ctx->auth_triplet.key_seq != GSM_KEY_SEQ_INVAL) { |
| 643 | /* Check again for authorization */ |
| 644 | sgsn_auth_request(ctx); |
| 645 | return 0; |
| 646 | } |
| 647 | |
Jacob Erlbeck | 423f8bf | 2014-10-24 18:09:54 +0200 | [diff] [blame] | 648 | if (ctx->auth_state != SGSN_AUTH_ACCEPTED) { |
| 649 | LOGMMCTXP(LOGL_NOTICE, ctx, |
| 650 | "authorization is denied, aborting procedure\n"); |
| 651 | return -EACCES; |
Jacob Erlbeck | 0c06f98 | 2014-10-29 22:12:20 +0100 | [diff] [blame] | 652 | } |
| 653 | |
| 654 | /* The MS is authorized */ |
| 655 | |
Jacob Erlbeck | 93eae8e | 2014-10-28 12:23:29 +0100 | [diff] [blame] | 656 | switch (ctx->pending_req) { |
| 657 | case 0: |
| 658 | LOGMMCTXP(LOGL_INFO, ctx, |
| 659 | "no pending request, authorization completed\n"); |
| 660 | break; |
| 661 | case GSM48_MT_GMM_ATTACH_REQ: |
Holger Hans Peter Freyther | 20de3ae | 2015-05-05 22:52:40 +0200 | [diff] [blame] | 662 | |
| 663 | extract_subscr_msisdn(ctx); |
Holger Hans Peter Freyther | 8ee13e2 | 2015-05-18 10:00:03 +0200 | [diff] [blame] | 664 | extract_subscr_hlr(ctx); |
Jacob Erlbeck | 93eae8e | 2014-10-28 12:23:29 +0100 | [diff] [blame] | 665 | #ifdef PTMSI_ALLOC |
| 666 | /* Start T3350 and re-transmit up to 5 times until ATTACH COMPLETE */ |
Harald Welte | 9450882 | 2015-08-15 19:08:21 +0200 | [diff] [blame] | 667 | mmctx_timer_start(ctx, 3350, sgsn->cfg.timers.T3350); |
Jacob Erlbeck | 93eae8e | 2014-10-28 12:23:29 +0100 | [diff] [blame] | 668 | ctx->t3350_mode = GMM_T3350_MODE_ATT; |
Jacob Erlbeck | 0074a77 | 2014-10-28 16:23:46 +0100 | [diff] [blame] | 669 | #else |
Holger Hans Peter Freyther | b100895 | 2015-05-02 19:55:38 +0200 | [diff] [blame] | 670 | memset(&sig_data, 0, sizeof(sig_data)); |
| 671 | sig_data.mm = mmctx; |
| 672 | osmo_signal_dispatch(SS_SGSN, S_SGSN_ATTACH, &sig_data); |
Jacob Erlbeck | 0074a77 | 2014-10-28 16:23:46 +0100 | [diff] [blame] | 673 | ctx->mm_state = GMM_REGISTERED_NORMAL; |
Jacob Erlbeck | 93eae8e | 2014-10-28 12:23:29 +0100 | [diff] [blame] | 674 | #endif |
| 675 | |
Jacob Erlbeck | 93eae8e | 2014-10-28 12:23:29 +0100 | [diff] [blame] | 676 | return gsm48_tx_gmm_att_ack(ctx); |
| 677 | default: |
| 678 | LOGMMCTXP(LOGL_ERROR, ctx, |
| 679 | "only Attach Request is supported yet, " |
| 680 | "got request type %u\n", ctx->pending_req); |
| 681 | break; |
| 682 | } |
| 683 | |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 684 | return 0; |
| 685 | } |
| 686 | |
Jacob Erlbeck | 4adb136 | 2014-12-02 09:47:26 +0100 | [diff] [blame] | 687 | void gsm0408_gprs_authenticate(struct sgsn_mm_ctx *ctx) |
| 688 | { |
| 689 | ctx->is_authenticated = 0; |
| 690 | |
| 691 | gsm48_gmm_authorize(ctx); |
| 692 | } |
| 693 | |
Jacob Erlbeck | 423f8bf | 2014-10-24 18:09:54 +0200 | [diff] [blame] | 694 | void gsm0408_gprs_access_granted(struct sgsn_mm_ctx *ctx) |
| 695 | { |
| 696 | switch (ctx->mm_state) { |
| 697 | case GMM_COMMON_PROC_INIT: |
| 698 | LOGP(DMM, LOGL_NOTICE, |
| 699 | "Authorized, continuing procedure, IMSI=%s\n", |
| 700 | ctx->imsi); |
| 701 | /* Continue with the authorization */ |
| 702 | gsm48_gmm_authorize(ctx); |
| 703 | break; |
| 704 | default: |
| 705 | LOGP(DMM, LOGL_INFO, |
| 706 | "Authorized, ignored, IMSI=%s\n", |
| 707 | ctx->imsi); |
| 708 | } |
| 709 | } |
| 710 | |
Jacob Erlbeck | af3d5c5 | 2015-01-05 17:51:17 +0100 | [diff] [blame] | 711 | void gsm0408_gprs_access_denied(struct sgsn_mm_ctx *ctx, int gmm_cause) |
Jacob Erlbeck | 423f8bf | 2014-10-24 18:09:54 +0200 | [diff] [blame] | 712 | { |
Jacob Erlbeck | d6267d1 | 2015-01-19 11:10:04 +0100 | [diff] [blame] | 713 | if (gmm_cause == SGSN_ERROR_CAUSE_NONE) |
Jacob Erlbeck | af3d5c5 | 2015-01-05 17:51:17 +0100 | [diff] [blame] | 714 | gmm_cause = GMM_CAUSE_GPRS_NOTALLOWED; |
| 715 | |
Jacob Erlbeck | 423f8bf | 2014-10-24 18:09:54 +0200 | [diff] [blame] | 716 | switch (ctx->mm_state) { |
| 717 | case GMM_COMMON_PROC_INIT: |
Jacob Erlbeck | af3d5c5 | 2015-01-05 17:51:17 +0100 | [diff] [blame] | 718 | LOGMMCTXP(LOGL_NOTICE, ctx, |
| 719 | "Not authorized, rejecting ATTACH REQUEST " |
| 720 | "with cause '%s' (%d)\n", |
| 721 | get_value_string(gsm48_gmm_cause_names, gmm_cause), |
| 722 | gmm_cause); |
| 723 | gsm48_tx_gmm_att_rej(ctx, gmm_cause); |
Jacob Erlbeck | 423f8bf | 2014-10-24 18:09:54 +0200 | [diff] [blame] | 724 | mm_ctx_cleanup_free(ctx, "GPRS ATTACH REJECT"); |
| 725 | break; |
| 726 | case GMM_REGISTERED_NORMAL: |
| 727 | case GMM_REGISTERED_SUSPENDED: |
Jacob Erlbeck | af3d5c5 | 2015-01-05 17:51:17 +0100 | [diff] [blame] | 728 | LOGMMCTXP(LOGL_NOTICE, ctx, |
| 729 | "Authorization lost, detaching " |
| 730 | "with cause '%s' (%d)\n", |
| 731 | get_value_string(gsm48_gmm_cause_names, gmm_cause), |
| 732 | gmm_cause); |
Jacob Erlbeck | 423f8bf | 2014-10-24 18:09:54 +0200 | [diff] [blame] | 733 | gsm48_tx_gmm_detach_req( |
Jacob Erlbeck | af3d5c5 | 2015-01-05 17:51:17 +0100 | [diff] [blame] | 734 | ctx, GPRS_DET_T_MT_REATT_NOTREQ, gmm_cause); |
Jacob Erlbeck | 423f8bf | 2014-10-24 18:09:54 +0200 | [diff] [blame] | 735 | |
| 736 | mm_ctx_cleanup_free(ctx, "auth lost"); |
| 737 | break; |
| 738 | default: |
Jacob Erlbeck | af3d5c5 | 2015-01-05 17:51:17 +0100 | [diff] [blame] | 739 | LOGMMCTXP(LOGL_INFO, ctx, |
| 740 | "Authorization lost, cause is '%s' (%d)\n", |
| 741 | get_value_string(gsm48_gmm_cause_names, gmm_cause), |
| 742 | gmm_cause); |
| 743 | mm_ctx_cleanup_free(ctx, "auth lost"); |
Jacob Erlbeck | 423f8bf | 2014-10-24 18:09:54 +0200 | [diff] [blame] | 744 | } |
| 745 | } |
| 746 | |
Jacob Erlbeck | af3d5c5 | 2015-01-05 17:51:17 +0100 | [diff] [blame] | 747 | void gsm0408_gprs_access_cancelled(struct sgsn_mm_ctx *ctx, int gmm_cause) |
Jacob Erlbeck | 98647ca | 2014-11-11 14:47:38 +0100 | [diff] [blame] | 748 | { |
Jacob Erlbeck | d6267d1 | 2015-01-19 11:10:04 +0100 | [diff] [blame] | 749 | if (gmm_cause != SGSN_ERROR_CAUSE_NONE) { |
Jacob Erlbeck | af3d5c5 | 2015-01-05 17:51:17 +0100 | [diff] [blame] | 750 | LOGMMCTXP(LOGL_INFO, ctx, |
| 751 | "Cancelled with cause '%s' (%d), deleting context\n", |
| 752 | get_value_string(gsm48_gmm_cause_names, gmm_cause), |
| 753 | gmm_cause); |
| 754 | gsm0408_gprs_access_denied(ctx, gmm_cause); |
| 755 | return; |
Jacob Erlbeck | 98647ca | 2014-11-11 14:47:38 +0100 | [diff] [blame] | 756 | } |
Jacob Erlbeck | af3d5c5 | 2015-01-05 17:51:17 +0100 | [diff] [blame] | 757 | |
| 758 | LOGMMCTXP(LOGL_INFO, ctx, "Cancelled, deleting context silently\n"); |
Jacob Erlbeck | 98647ca | 2014-11-11 14:47:38 +0100 | [diff] [blame] | 759 | mm_ctx_cleanup_free(ctx, "access cancelled"); |
| 760 | } |
| 761 | |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 762 | /* Parse Chapter 9.4.13 Identity Response */ |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 763 | static int gsm48_rx_gmm_id_resp(struct sgsn_mm_ctx *ctx, struct msgb *msg) |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 764 | { |
Harald Welte | 943c5bc | 2010-04-30 16:33:12 +0200 | [diff] [blame] | 765 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_gmmh(msg); |
Harald Welte | eaa614c | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 766 | uint8_t mi_type = gh->data[1] & GSM_MI_TYPE_MASK; |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 767 | char mi_string[GSM48_MI_SIZE]; |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 768 | |
| 769 | gsm48_mi_to_string(mi_string, sizeof(mi_string), &gh->data[1], gh->data[0]); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 770 | if (!ctx) { |
Daniel Willmann | 4655314 | 2014-09-03 17:46:44 +0200 | [diff] [blame] | 771 | DEBUGP(DMM, "from unknown TLLI 0x%08x?!? This should not happen\n", msgb_tlli(msg)); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 772 | return -EINVAL; |
| 773 | } |
| 774 | |
Daniel Willmann | f8070f4 | 2014-09-23 18:48:44 +0200 | [diff] [blame] | 775 | LOGMMCTXP(LOGL_DEBUG, ctx, "-> GMM IDENTITY RESPONSE: mi_type=0x%02x MI(%s)\n", |
| 776 | mi_type, mi_string); |
| 777 | |
Jacob Erlbeck | fb26c60 | 2014-10-22 12:20:26 +0200 | [diff] [blame] | 778 | if (ctx->t3370_id_type == GSM_MI_TYPE_NONE) { |
| 779 | LOGMMCTXP(LOGL_NOTICE, ctx, |
| 780 | "Got unexpected IDENTITY RESPONSE: mi_type=0x%02x MI(%s), " |
| 781 | "ignoring message\n", |
| 782 | mi_type, mi_string); |
| 783 | return -EINVAL; |
| 784 | } |
| 785 | |
Harald Welte | c2e8cc4 | 2010-05-31 20:23:38 +0200 | [diff] [blame] | 786 | if (mi_type == ctx->t3370_id_type) |
| 787 | mmctx_timer_stop(ctx, 3370); |
| 788 | |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 789 | switch (mi_type) { |
| 790 | case GSM_MI_TYPE_IMSI: |
| 791 | /* we already have a mm context with current TLLI, but no |
| 792 | * P-TMSI / IMSI yet. What we now need to do is to fill |
| 793 | * this initial context with data from the HLR */ |
Harald Welte | c728eea | 2010-12-24 23:07:18 +0100 | [diff] [blame] | 794 | if (strlen(ctx->imsi) == 0) { |
| 795 | /* Check if we already have a MM context for this IMSI */ |
| 796 | struct sgsn_mm_ctx *ictx; |
| 797 | ictx = sgsn_mm_ctx_by_imsi(mi_string); |
| 798 | if (ictx) { |
Jacob Erlbeck | 99985b5 | 2014-10-13 10:32:00 +0200 | [diff] [blame] | 799 | /* Handle it like in gsm48_rx_gmm_det_req, |
| 800 | * except that no messages are sent to the BSS */ |
| 801 | |
Daniel Willmann | 4655314 | 2014-09-03 17:46:44 +0200 | [diff] [blame] | 802 | LOGMMCTXP(LOGL_NOTICE, ctx, "Deleting old MM Context for same IMSI " |
| 803 | "p_tmsi_old=0x%08x\n", |
| 804 | ictx->p_tmsi); |
Jacob Erlbeck | 99985b5 | 2014-10-13 10:32:00 +0200 | [diff] [blame] | 805 | |
Jacob Erlbeck | 99985b5 | 2014-10-13 10:32:00 +0200 | [diff] [blame] | 806 | mm_ctx_cleanup_free(ictx, "GPRS IMSI re-use"); |
Harald Welte | c728eea | 2010-12-24 23:07:18 +0100 | [diff] [blame] | 807 | } |
| 808 | } |
Jacob Erlbeck | 496aee7 | 2015-01-26 10:38:12 +0100 | [diff] [blame] | 809 | strncpy(ctx->imsi, mi_string, sizeof(ctx->imsi) - 1); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 810 | break; |
| 811 | case GSM_MI_TYPE_IMEI: |
Jacob Erlbeck | 496aee7 | 2015-01-26 10:38:12 +0100 | [diff] [blame] | 812 | strncpy(ctx->imei, mi_string, sizeof(ctx->imei) - 1); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 813 | break; |
| 814 | case GSM_MI_TYPE_IMEISV: |
| 815 | break; |
| 816 | } |
| 817 | |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 818 | /* Check if we can let the mobile station enter */ |
Jacob Erlbeck | 93eae8e | 2014-10-28 12:23:29 +0100 | [diff] [blame] | 819 | return gsm48_gmm_authorize(ctx); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 820 | } |
| 821 | |
| 822 | /* Section 9.4.1 Attach request */ |
Harald Welte | 807a5d8 | 2010-06-01 11:53:01 +0200 | [diff] [blame] | 823 | static int gsm48_rx_gmm_att_req(struct sgsn_mm_ctx *ctx, struct msgb *msg, |
| 824 | struct gprs_llc_llme *llme) |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 825 | { |
Harald Welte | 943c5bc | 2010-04-30 16:33:12 +0200 | [diff] [blame] | 826 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_gmmh(msg); |
Holger Hans Peter Freyther | 1768a57 | 2014-04-04 12:40:34 +0200 | [diff] [blame] | 827 | uint8_t *cur = gh->data, *msnc, *mi, *ms_ra_acc_cap; |
Harald Welte | 56a0145 | 2010-05-31 22:12:30 +0200 | [diff] [blame] | 828 | uint8_t msnc_len, att_type, mi_len, mi_type, ms_ra_acc_cap_len; |
Harald Welte | eaa614c | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 829 | uint16_t drx_par; |
| 830 | uint32_t tmsi; |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 831 | char mi_string[GSM48_MI_SIZE]; |
| 832 | struct gprs_ra_id ra_id; |
Harald Welte | 9f1f3ad | 2010-05-02 12:56:57 +0200 | [diff] [blame] | 833 | uint16_t cid; |
Jacob Erlbeck | 80d07e3 | 2014-11-06 13:43:41 +0100 | [diff] [blame] | 834 | enum gsm48_gmm_cause reject_cause; |
| 835 | int rc; |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 836 | |
Daniel Willmann | 4655314 | 2014-09-03 17:46:44 +0200 | [diff] [blame] | 837 | LOGP(DMM, LOGL_INFO, "-> GMM ATTACH REQUEST "); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 838 | |
| 839 | /* As per TS 04.08 Chapter 4.7.1.4, the attach request arrives either |
| 840 | * with a foreign TLLI (P-TMSI that was allocated to the MS before), |
| 841 | * or with random TLLI. */ |
| 842 | |
Harald Welte | 9f1f3ad | 2010-05-02 12:56:57 +0200 | [diff] [blame] | 843 | cid = bssgp_parse_cell_id(&ra_id, msgb_bcid(msg)); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 844 | |
| 845 | /* MS network capability 10.5.5.12 */ |
| 846 | msnc_len = *cur++; |
| 847 | msnc = cur; |
Alexander Chemeris | 84402c0 | 2013-07-03 10:12:23 +0400 | [diff] [blame] | 848 | if (msnc_len > sizeof(ctx->ms_network_capa.buf)) |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 849 | goto err_inval; |
| 850 | cur += msnc_len; |
| 851 | |
| 852 | /* aTTACH Type 10.5.5.2 */ |
| 853 | att_type = *cur++ & 0x0f; |
| 854 | |
| 855 | /* DRX parameter 10.5.5.6 */ |
Harald Welte | 56a0145 | 2010-05-31 22:12:30 +0200 | [diff] [blame] | 856 | drx_par = *cur++ << 8; |
| 857 | drx_par |= *cur++; |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 858 | |
| 859 | /* Mobile Identity (P-TMSI or IMSI) 10.5.1.4 */ |
| 860 | mi_len = *cur++; |
| 861 | mi = cur; |
| 862 | if (mi_len > 8) |
| 863 | goto err_inval; |
| 864 | mi_type = *mi & GSM_MI_TYPE_MASK; |
| 865 | cur += mi_len; |
| 866 | |
| 867 | gsm48_mi_to_string(mi_string, sizeof(mi_string), mi, mi_len); |
| 868 | |
Harald Welte | 2720e73 | 2010-05-17 00:44:57 +0200 | [diff] [blame] | 869 | DEBUGPC(DMM, "MI(%s) type=\"%s\" ", mi_string, |
| 870 | get_value_string(gprs_att_t_strs, att_type)); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 871 | |
Holger Hans Peter Freyther | 1768a57 | 2014-04-04 12:40:34 +0200 | [diff] [blame] | 872 | /* Old routing area identification 10.5.5.15. Skip it */ |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 873 | cur += 6; |
| 874 | |
| 875 | /* MS Radio Access Capability 10.5.5.12a */ |
Harald Welte | 56a0145 | 2010-05-31 22:12:30 +0200 | [diff] [blame] | 876 | ms_ra_acc_cap_len = *cur++; |
| 877 | ms_ra_acc_cap = cur; |
Alexander Chemeris | 84402c0 | 2013-07-03 10:12:23 +0400 | [diff] [blame] | 878 | if (ms_ra_acc_cap_len > sizeof(ctx->ms_radio_access_capa.buf)) |
Harald Welte | c48ac47 | 2010-07-03 21:20:06 +0200 | [diff] [blame] | 879 | goto err_inval; |
Harald Welte | 4b2ed35 | 2011-07-27 23:35:38 +0200 | [diff] [blame] | 880 | cur += ms_ra_acc_cap_len; |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 881 | |
Daniel Willmann | 4655314 | 2014-09-03 17:46:44 +0200 | [diff] [blame] | 882 | LOGPC(DMM, LOGL_INFO, "\n"); |
| 883 | |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 884 | /* Optional: Old P-TMSI Signature, Requested READY timer, TMSI Status */ |
| 885 | |
| 886 | switch (mi_type) { |
| 887 | case GSM_MI_TYPE_IMSI: |
| 888 | /* Try to find MM context based on IMSI */ |
Harald Welte | 807a5d8 | 2010-06-01 11:53:01 +0200 | [diff] [blame] | 889 | if (!ctx) |
| 890 | ctx = sgsn_mm_ctx_by_imsi(mi_string); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 891 | if (!ctx) { |
| 892 | #if 0 |
| 893 | return gsm48_tx_gmm_att_rej(msg, GMM_CAUSE_IMSI_UNKNOWN); |
| 894 | #else |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 895 | ctx = sgsn_mm_ctx_alloc(0, &ra_id); |
Jacob Erlbeck | 80d07e3 | 2014-11-06 13:43:41 +0100 | [diff] [blame] | 896 | if (!ctx) { |
| 897 | reject_cause = GMM_CAUSE_NET_FAIL; |
| 898 | goto rejected; |
| 899 | } |
Jacob Erlbeck | 496aee7 | 2015-01-26 10:38:12 +0100 | [diff] [blame] | 900 | strncpy(ctx->imsi, mi_string, sizeof(ctx->imsi) - 1); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 901 | #endif |
| 902 | } |
Harald Welte | 943c5bc | 2010-04-30 16:33:12 +0200 | [diff] [blame] | 903 | ctx->tlli = msgb_tlli(msg); |
Harald Welte | 807a5d8 | 2010-06-01 11:53:01 +0200 | [diff] [blame] | 904 | ctx->llme = llme; |
Harald Welte | 68b99a4 | 2010-05-18 12:05:42 +0200 | [diff] [blame] | 905 | msgid2mmctx(ctx, msg); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 906 | break; |
| 907 | case GSM_MI_TYPE_TMSI: |
Harald Welte | ab1d562 | 2010-05-18 19:58:38 +0200 | [diff] [blame] | 908 | memcpy(&tmsi, mi+1, 4); |
| 909 | tmsi = ntohl(tmsi); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 910 | /* Try to find MM context based on P-TMSI */ |
Harald Welte | 807a5d8 | 2010-06-01 11:53:01 +0200 | [diff] [blame] | 911 | if (!ctx) |
| 912 | ctx = sgsn_mm_ctx_by_ptmsi(tmsi); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 913 | if (!ctx) { |
Harald Welte | c728eea | 2010-12-24 23:07:18 +0100 | [diff] [blame] | 914 | /* Allocate a context as most of our code expects one. |
| 915 | * Context will not have an IMSI ultil ID RESP is received */ |
Harald Welte | 943c5bc | 2010-04-30 16:33:12 +0200 | [diff] [blame] | 916 | ctx = sgsn_mm_ctx_alloc(msgb_tlli(msg), &ra_id); |
Harald Welte | 807a5d8 | 2010-06-01 11:53:01 +0200 | [diff] [blame] | 917 | ctx->p_tmsi = tmsi; |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 918 | } |
Harald Welte | 807a5d8 | 2010-06-01 11:53:01 +0200 | [diff] [blame] | 919 | ctx->tlli = msgb_tlli(msg); |
| 920 | ctx->llme = llme; |
| 921 | msgid2mmctx(ctx, msg); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 922 | break; |
| 923 | default: |
Harald Welte | c2e8cc4 | 2010-05-31 20:23:38 +0200 | [diff] [blame] | 924 | LOGP(DMM, LOGL_NOTICE, "Rejecting ATTACH REQUEST with " |
| 925 | "MI type %u\n", mi_type); |
Jacob Erlbeck | 80d07e3 | 2014-11-06 13:43:41 +0100 | [diff] [blame] | 926 | reject_cause = GMM_CAUSE_MS_ID_NOT_DERIVED; |
| 927 | goto rejected; |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 928 | } |
Harald Welte | 9f1f3ad | 2010-05-02 12:56:57 +0200 | [diff] [blame] | 929 | /* Update MM Context with currient RA and Cell ID */ |
| 930 | ctx->ra = ra_id; |
| 931 | ctx->cell_id = cid; |
Harald Welte | 56a0145 | 2010-05-31 22:12:30 +0200 | [diff] [blame] | 932 | /* Update MM Context with other data */ |
| 933 | ctx->drx_parms = drx_par; |
Alexander Chemeris | 84402c0 | 2013-07-03 10:12:23 +0400 | [diff] [blame] | 934 | ctx->ms_radio_access_capa.len = ms_ra_acc_cap_len; |
Harald Welte | 4b2ed35 | 2011-07-27 23:35:38 +0200 | [diff] [blame] | 935 | memcpy(ctx->ms_radio_access_capa.buf, ms_ra_acc_cap, |
| 936 | ctx->ms_radio_access_capa.len); |
Harald Welte | 56a0145 | 2010-05-31 22:12:30 +0200 | [diff] [blame] | 937 | ctx->ms_network_capa.len = msnc_len; |
| 938 | memcpy(ctx->ms_network_capa.buf, msnc, msnc_len); |
| 939 | |
Harald Welte | c2e8cc4 | 2010-05-31 20:23:38 +0200 | [diff] [blame] | 940 | #ifdef PTMSI_ALLOC |
Harald Welte | 807a5d8 | 2010-06-01 11:53:01 +0200 | [diff] [blame] | 941 | /* Allocate a new P-TMSI (+ P-TMSI signature) and update TLLI */ |
Jacob Erlbeck | f6e7d99 | 2014-11-06 15:43:10 +0100 | [diff] [blame] | 942 | /* Don't change the P-TMSI if a P-TMSI re-assignment is under way */ |
| 943 | if (ctx->mm_state != GMM_COMMON_PROC_INIT) { |
| 944 | ctx->p_tmsi_old = ctx->p_tmsi; |
| 945 | ctx->p_tmsi = sgsn_alloc_ptmsi(); |
| 946 | } |
Jacob Erlbeck | 0074a77 | 2014-10-28 16:23:46 +0100 | [diff] [blame] | 947 | ctx->mm_state = GMM_COMMON_PROC_INIT; |
Harald Welte | ab1d562 | 2010-05-18 19:58:38 +0200 | [diff] [blame] | 948 | #endif |
Harald Welte | 807a5d8 | 2010-06-01 11:53:01 +0200 | [diff] [blame] | 949 | /* Even if there is no P-TMSI allocated, the MS will switch from |
| 950 | * foreign TLLI to local TLLI */ |
| 951 | ctx->tlli_new = gprs_tmsi2tlli(ctx->p_tmsi, TLLI_LOCAL); |
| 952 | |
| 953 | /* Inform LLC layer about new TLLI but keep old active */ |
Harald Welte | d6f582b | 2010-06-30 23:18:57 +0200 | [diff] [blame] | 954 | gprs_llgmm_assign(ctx->llme, ctx->tlli, ctx->tlli_new, |
| 955 | GPRS_ALGO_GEA0, NULL); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 956 | |
Jacob Erlbeck | 93eae8e | 2014-10-28 12:23:29 +0100 | [diff] [blame] | 957 | ctx->pending_req = GSM48_MT_GMM_ATTACH_REQ; |
| 958 | return gsm48_gmm_authorize(ctx); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 959 | |
| 960 | err_inval: |
Daniel Willmann | 4655314 | 2014-09-03 17:46:44 +0200 | [diff] [blame] | 961 | LOGPC(DMM, LOGL_INFO, "\n"); |
Jacob Erlbeck | 80d07e3 | 2014-11-06 13:43:41 +0100 | [diff] [blame] | 962 | reject_cause = GMM_CAUSE_SEM_INCORR_MSG; |
| 963 | |
| 964 | rejected: |
| 965 | /* Send ATTACH REJECT */ |
| 966 | LOGMMCTXP(LOGL_NOTICE, ctx, |
| 967 | "Rejecting Attach Request with cause '%s' (%d)\n", |
Jacob Erlbeck | afcf230 | 2015-01-05 17:30:02 +0100 | [diff] [blame] | 968 | get_value_string(gsm48_gmm_cause_names, reject_cause), reject_cause); |
Jacob Erlbeck | 80d07e3 | 2014-11-06 13:43:41 +0100 | [diff] [blame] | 969 | rc = gsm48_tx_gmm_att_rej_oldmsg(msg, reject_cause); |
| 970 | if (ctx) |
| 971 | mm_ctx_cleanup_free(ctx, "GPRS ATTACH REJ"); |
| 972 | else |
| 973 | /* TLLI unassignment */ |
| 974 | gprs_llgmm_assign(llme, llme->tlli, 0xffffffff, GPRS_ALGO_GEA0, NULL); |
| 975 | |
| 976 | return rc; |
| 977 | |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 978 | } |
| 979 | |
Harald Welte | 2720e73 | 2010-05-17 00:44:57 +0200 | [diff] [blame] | 980 | /* Section 4.7.4.1 / 9.4.5.2 MO Detach request */ |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 981 | static int gsm48_rx_gmm_det_req(struct sgsn_mm_ctx *ctx, struct msgb *msg) |
Harald Welte | 2720e73 | 2010-05-17 00:44:57 +0200 | [diff] [blame] | 982 | { |
| 983 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_gmmh(msg); |
Harald Welte | 2720e73 | 2010-05-17 00:44:57 +0200 | [diff] [blame] | 984 | uint8_t detach_type, power_off; |
Jacob Erlbeck | 5a38f64 | 2014-10-21 13:09:55 +0200 | [diff] [blame] | 985 | int rc = 0; |
Harald Welte | 2720e73 | 2010-05-17 00:44:57 +0200 | [diff] [blame] | 986 | |
| 987 | detach_type = gh->data[0] & 0x7; |
| 988 | power_off = gh->data[0] & 0x8; |
| 989 | |
| 990 | /* FIXME: In 24.008 there is an optional P-TMSI and P-TMSI signature IE */ |
| 991 | |
Daniel Willmann | 4655314 | 2014-09-03 17:46:44 +0200 | [diff] [blame] | 992 | LOGMMCTXP(LOGL_INFO, ctx, "-> GMM DETACH REQUEST TLLI=0x%08x type=%s %s\n", |
Harald Welte | 2720e73 | 2010-05-17 00:44:57 +0200 | [diff] [blame] | 993 | msgb_tlli(msg), get_value_string(gprs_det_t_mo_strs, detach_type), |
| 994 | power_off ? "Power-off" : ""); |
| 995 | |
Jacob Erlbeck | 5a38f64 | 2014-10-21 13:09:55 +0200 | [diff] [blame] | 996 | /* Only send the Detach Accept (MO) if power off isn't indicated, |
Jacob Erlbeck | b9ab0d4 | 2014-10-21 09:52:05 +0200 | [diff] [blame] | 997 | * see 04.08, 4.7.4.1.2/3 for details */ |
| 998 | if (!power_off) { |
| 999 | /* force_stby = 0 */ |
Jacob Erlbeck | 5a38f64 | 2014-10-21 13:09:55 +0200 | [diff] [blame] | 1000 | if (ctx) |
| 1001 | rc = gsm48_tx_gmm_det_ack(ctx, 0); |
| 1002 | else |
| 1003 | rc = gsm48_tx_gmm_det_ack_oldmsg(msg, 0); |
Jacob Erlbeck | b9ab0d4 | 2014-10-21 09:52:05 +0200 | [diff] [blame] | 1004 | } |
Harald Welte | bd5c912 | 2010-06-28 22:18:53 +0200 | [diff] [blame] | 1005 | |
Holger Hans Peter Freyther | b100895 | 2015-05-02 19:55:38 +0200 | [diff] [blame] | 1006 | if (ctx) { |
| 1007 | struct sgsn_signal_data sig_data; |
| 1008 | memset(&sig_data, 0, sizeof(sig_data)); |
| 1009 | sig_data.mm = ctx; |
| 1010 | osmo_signal_dispatch(SS_SGSN, S_SGSN_DETACH, &sig_data); |
Jacob Erlbeck | 5a38f64 | 2014-10-21 13:09:55 +0200 | [diff] [blame] | 1011 | mm_ctx_cleanup_free(ctx, "GPRS DETACH REQUEST"); |
Holger Hans Peter Freyther | b100895 | 2015-05-02 19:55:38 +0200 | [diff] [blame] | 1012 | } |
Jacob Erlbeck | 258ce3d | 2014-09-30 13:51:45 +0200 | [diff] [blame] | 1013 | |
Harald Welte | bd5c912 | 2010-06-28 22:18:53 +0200 | [diff] [blame] | 1014 | return rc; |
Harald Welte | 2720e73 | 2010-05-17 00:44:57 +0200 | [diff] [blame] | 1015 | } |
| 1016 | |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1017 | /* Chapter 9.4.15: Routing area update accept */ |
Harald Welte | 6463c07 | 2010-05-18 17:04:55 +0200 | [diff] [blame] | 1018 | static int gsm48_tx_gmm_ra_upd_ack(struct sgsn_mm_ctx *mm) |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1019 | { |
| 1020 | struct msgb *msg = gsm48_msgb_alloc(); |
| 1021 | struct gsm48_hdr *gh; |
| 1022 | struct gsm48_ra_upd_ack *rua; |
Harald Welte | c2e8cc4 | 2010-05-31 20:23:38 +0200 | [diff] [blame] | 1023 | uint8_t *mid; |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1024 | |
Daniel Willmann | 4655314 | 2014-09-03 17:46:44 +0200 | [diff] [blame] | 1025 | LOGMMCTXP(LOGL_INFO, mm, "<- ROUTING AREA UPDATE ACCEPT\n"); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1026 | |
Harald Welte | 6463c07 | 2010-05-18 17:04:55 +0200 | [diff] [blame] | 1027 | mmctx2msgid(msg, mm); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1028 | |
| 1029 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 1030 | gh->proto_discr = GSM48_PDISC_MM_GPRS; |
| 1031 | gh->msg_type = GSM48_MT_GMM_RA_UPD_ACK; |
| 1032 | |
| 1033 | rua = (struct gsm48_ra_upd_ack *) msgb_put(msg, sizeof(*rua)); |
| 1034 | rua->force_stby = 0; /* not indicated */ |
| 1035 | rua->upd_result = 0; /* RA updated */ |
Harald Welte | 9450882 | 2015-08-15 19:08:21 +0200 | [diff] [blame] | 1036 | rua->ra_upd_timer = gprs_secs_to_tmr_floor(sgsn->cfg.timers.T3312); |
Harald Welte | 11d7c10 | 2010-05-02 11:54:55 +0200 | [diff] [blame] | 1037 | |
Harald Welte | 6463c07 | 2010-05-18 17:04:55 +0200 | [diff] [blame] | 1038 | gsm48_construct_ra(rua->ra_id.digits, &mm->ra); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1039 | |
Harald Welte | c2e8cc4 | 2010-05-31 20:23:38 +0200 | [diff] [blame] | 1040 | #if 0 |
| 1041 | /* Optional: P-TMSI signature */ |
| 1042 | msgb_v_put(msg, GSM48_IE_GMM_PTMSI_SIG); |
| 1043 | ptsig = msgb_put(msg, 3); |
| 1044 | ptsig[0] = mm->p_tmsi_sig >> 16; |
| 1045 | ptsig[1] = mm->p_tmsi_sig >> 8; |
| 1046 | ptsig[2] = mm->p_tmsi_sig & 0xff; |
| 1047 | #endif |
| 1048 | |
| 1049 | #ifdef PTMSI_ALLOC |
| 1050 | /* Optional: Allocated P-TMSI */ |
| 1051 | mid = msgb_put(msg, GSM48_MID_TMSI_LEN); |
| 1052 | gsm48_generate_mid_from_tmsi(mid, mm->p_tmsi); |
| 1053 | mid[0] = GSM48_IE_GMM_ALLOC_PTMSI; |
| 1054 | #endif |
| 1055 | |
Jacob Erlbeck | 8de9c48 | 2015-01-23 11:44:39 +0100 | [diff] [blame] | 1056 | /* Optional: Negotiated READY timer value */ |
| 1057 | msgb_tv_put(msg, GSM48_IE_GMM_TIMER_READY, |
Harald Welte | 9450882 | 2015-08-15 19:08:21 +0200 | [diff] [blame] | 1058 | gprs_secs_to_tmr_floor(sgsn->cfg.timers.T3314)); |
Jacob Erlbeck | 8de9c48 | 2015-01-23 11:44:39 +0100 | [diff] [blame] | 1059 | |
Harald Welte | c2e8cc4 | 2010-05-31 20:23:38 +0200 | [diff] [blame] | 1060 | /* Option: MS ID, ... */ |
Harald Welte | 56a0145 | 2010-05-31 22:12:30 +0200 | [diff] [blame] | 1061 | return gsm48_gmm_sendmsg(msg, 0, mm); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1062 | } |
| 1063 | |
| 1064 | /* Chapter 9.4.17: Routing area update reject */ |
Harald Welte | eaa614c | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 1065 | static int gsm48_tx_gmm_ra_upd_rej(struct msgb *old_msg, uint8_t cause) |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1066 | { |
| 1067 | struct msgb *msg = gsm48_msgb_alloc(); |
| 1068 | struct gsm48_hdr *gh; |
| 1069 | |
Daniel Willmann | 4655314 | 2014-09-03 17:46:44 +0200 | [diff] [blame] | 1070 | LOGP(DMM, LOGL_NOTICE, "<- ROUTING AREA UPDATE REJECT\n"); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1071 | |
Harald Welte | 11d7c10 | 2010-05-02 11:54:55 +0200 | [diff] [blame] | 1072 | gmm_copy_id(msg, old_msg); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1073 | |
| 1074 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 2); |
| 1075 | gh->proto_discr = GSM48_PDISC_MM_GPRS; |
| 1076 | gh->msg_type = GSM48_MT_GMM_RA_UPD_REJ; |
| 1077 | gh->data[0] = cause; |
| 1078 | gh->data[1] = 0; /* ? */ |
| 1079 | |
| 1080 | /* Option: P-TMSI signature, allocated P-TMSI, MS ID, ... */ |
Harald Welte | 8acd88f | 2010-05-18 10:57:45 +0200 | [diff] [blame] | 1081 | return gsm48_gmm_sendmsg(msg, 0, NULL); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1082 | } |
| 1083 | |
Harald Welte | 588d44e | 2010-06-09 10:28:29 +0200 | [diff] [blame] | 1084 | static void process_ms_ctx_status(struct sgsn_mm_ctx *mmctx, |
Holger Hans Peter Freyther | 2b17454 | 2011-10-14 23:31:34 +0200 | [diff] [blame] | 1085 | const uint8_t *pdp_status) |
Harald Welte | 588d44e | 2010-06-09 10:28:29 +0200 | [diff] [blame] | 1086 | { |
| 1087 | struct sgsn_pdp_ctx *pdp, *pdp2; |
| 1088 | /* 24.008 4.7.5.1.3: If the PDP context status information element is |
| 1089 | * included in ROUTING AREA UPDATE REQUEST message, then the network |
| 1090 | * shall deactivate all those PDP contexts locally (without peer to |
| 1091 | * peer signalling between the MS and the network), which are not in SM |
| 1092 | * state PDP-INACTIVE on network side but are indicated by the MS as |
| 1093 | * being in state PDP-INACTIVE. */ |
| 1094 | |
| 1095 | llist_for_each_entry_safe(pdp, pdp2, &mmctx->pdp_list, list) { |
Harald Welte | cdf76cf | 2011-08-05 21:23:46 +0200 | [diff] [blame] | 1096 | if (pdp->nsapi < 8) { |
| 1097 | if (!(pdp_status[0] & (1 << pdp->nsapi))) { |
Daniel Willmann | 4655314 | 2014-09-03 17:46:44 +0200 | [diff] [blame] | 1098 | LOGMMCTXP(LOGL_NOTICE, mmctx, "Dropping PDP context for NSAPI=%u " |
Harald Welte | cdf76cf | 2011-08-05 21:23:46 +0200 | [diff] [blame] | 1099 | "due to PDP CTX STATUS IE= 0x%02x%02x\n", |
| 1100 | pdp->nsapi, pdp_status[1], pdp_status[0]); |
| 1101 | sgsn_delete_pdp_ctx(pdp); |
| 1102 | } |
| 1103 | } else { |
| 1104 | if (!(pdp_status[1] & (1 << (pdp->nsapi - 8)))) { |
Daniel Willmann | 4655314 | 2014-09-03 17:46:44 +0200 | [diff] [blame] | 1105 | LOGMMCTXP(LOGL_NOTICE, mmctx, "Dropping PDP context for NSAPI=%u " |
Harald Welte | cdf76cf | 2011-08-05 21:23:46 +0200 | [diff] [blame] | 1106 | "due to PDP CTX STATUS IE= 0x%02x%02x\n", |
| 1107 | pdp->nsapi, pdp_status[1], pdp_status[0]); |
| 1108 | sgsn_delete_pdp_ctx(pdp); |
| 1109 | } |
Harald Welte | 588d44e | 2010-06-09 10:28:29 +0200 | [diff] [blame] | 1110 | } |
| 1111 | } |
| 1112 | } |
| 1113 | |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1114 | /* Chapter 9.4.14: Routing area update request */ |
Harald Welte | 807a5d8 | 2010-06-01 11:53:01 +0200 | [diff] [blame] | 1115 | static int gsm48_rx_gmm_ra_upd_req(struct sgsn_mm_ctx *mmctx, struct msgb *msg, |
| 1116 | struct gprs_llc_llme *llme) |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1117 | { |
Holger Hans Peter Freyther | b100895 | 2015-05-02 19:55:38 +0200 | [diff] [blame] | 1118 | #ifndef PTMSI_ALLOC |
| 1119 | struct sgsn_signal_data sig_data; |
| 1120 | #endif |
Harald Welte | 943c5bc | 2010-04-30 16:33:12 +0200 | [diff] [blame] | 1121 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_gmmh(msg); |
Harald Welte | eaa614c | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 1122 | uint8_t *cur = gh->data; |
Harald Welte | 588d44e | 2010-06-09 10:28:29 +0200 | [diff] [blame] | 1123 | uint8_t ms_ra_acc_cap_len; |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1124 | struct gprs_ra_id old_ra_id; |
Harald Welte | 588d44e | 2010-06-09 10:28:29 +0200 | [diff] [blame] | 1125 | struct tlv_parsed tp; |
Harald Welte | eaa614c | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 1126 | uint8_t upd_type; |
Jacob Erlbeck | 80d07e3 | 2014-11-06 13:43:41 +0100 | [diff] [blame] | 1127 | enum gsm48_gmm_cause reject_cause; |
| 1128 | int rc; |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1129 | |
| 1130 | /* Update Type 10.5.5.18 */ |
| 1131 | upd_type = *cur++ & 0x0f; |
| 1132 | |
Daniel Willmann | 4655314 | 2014-09-03 17:46:44 +0200 | [diff] [blame] | 1133 | LOGP(DMM, LOGL_INFO, "-> GMM RA UPDATE REQUEST type=\"%s\"\n", |
Harald Welte | 2720e73 | 2010-05-17 00:44:57 +0200 | [diff] [blame] | 1134 | get_value_string(gprs_upd_t_strs, upd_type)); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1135 | |
| 1136 | /* Old routing area identification 10.5.5.15 */ |
| 1137 | gsm48_parse_ra(&old_ra_id, cur); |
| 1138 | cur += 6; |
| 1139 | |
| 1140 | /* MS Radio Access Capability 10.5.5.12a */ |
Harald Welte | 588d44e | 2010-06-09 10:28:29 +0200 | [diff] [blame] | 1141 | ms_ra_acc_cap_len = *cur++; |
Jacob Erlbeck | 80d07e3 | 2014-11-06 13:43:41 +0100 | [diff] [blame] | 1142 | if (ms_ra_acc_cap_len > 52) { |
| 1143 | reject_cause = GMM_CAUSE_PROTO_ERR_UNSPEC; |
| 1144 | goto rejected; |
| 1145 | } |
Harald Welte | 4b2ed35 | 2011-07-27 23:35:38 +0200 | [diff] [blame] | 1146 | cur += ms_ra_acc_cap_len; |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1147 | |
| 1148 | /* Optional: Old P-TMSI Signature, Requested READY timer, TMSI Status, |
| 1149 | * DRX parameter, MS network capability */ |
Holger Hans Peter Freyther | 1768a57 | 2014-04-04 12:40:34 +0200 | [diff] [blame] | 1150 | tlv_parse(&tp, &gsm48_gmm_att_tlvdef, cur, |
Harald Welte | 588d44e | 2010-06-09 10:28:29 +0200 | [diff] [blame] | 1151 | (msg->data + msg->len) - cur, 0, 0); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1152 | |
| 1153 | switch (upd_type) { |
| 1154 | case GPRS_UPD_T_RA_LA: |
| 1155 | case GPRS_UPD_T_RA_LA_IMSI_ATT: |
Daniel Willmann | 4655314 | 2014-09-03 17:46:44 +0200 | [diff] [blame] | 1156 | LOGP(DMM, LOGL_NOTICE, "Update type %i unsupported in Mode III, is your SI13 corrupt?\n", upd_type); |
Jacob Erlbeck | 80d07e3 | 2014-11-06 13:43:41 +0100 | [diff] [blame] | 1157 | reject_cause = GMM_CAUSE_PROTO_ERR_UNSPEC; |
| 1158 | goto rejected; |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1159 | case GPRS_UPD_T_RA: |
| 1160 | case GPRS_UPD_T_PERIODIC: |
| 1161 | break; |
| 1162 | } |
| 1163 | |
| 1164 | /* Look-up the MM context based on old RA-ID and TLLI */ |
Harald Welte | f6bd340 | 2010-12-23 23:34:43 +0100 | [diff] [blame] | 1165 | mmctx = sgsn_mm_ctx_by_tlli(msgb_tlli(msg), &old_ra_id); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1166 | if (!mmctx || mmctx->mm_state == GMM_DEREGISTERED) { |
Harald Welte | 2b697a6 | 2011-10-16 18:50:56 +0200 | [diff] [blame] | 1167 | /* send a XID reset to re-set all LLC sequence numbers |
| 1168 | * in the MS */ |
Daniel Willmann | 4655314 | 2014-09-03 17:46:44 +0200 | [diff] [blame] | 1169 | LOGP(DMM, LOGL_NOTICE, "LLC XID RESET\n"); |
Harald Welte | 2b697a6 | 2011-10-16 18:50:56 +0200 | [diff] [blame] | 1170 | gprs_llgmm_reset(llme); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1171 | /* The MS has to perform GPRS attach */ |
Jacob Erlbeck | 78ecaf0 | 2014-09-05 14:32:36 +0200 | [diff] [blame] | 1172 | /* Device is still IMSI attached for CS but initiate GPRS ATTACH, |
| 1173 | * see GSM 04.08, 4.7.5.1.4 and G.6 */ |
Jacob Erlbeck | 80d07e3 | 2014-11-06 13:43:41 +0100 | [diff] [blame] | 1174 | reject_cause = GMM_CAUSE_IMPL_DETACHED; |
| 1175 | goto rejected; |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1176 | } |
| 1177 | |
Harald Welte | f0901f0 | 2010-12-26 10:39:26 +0100 | [diff] [blame] | 1178 | /* Store new BVCI/NSEI in MM context (FIXME: delay until we ack?) */ |
| 1179 | msgid2mmctx(mmctx, msg); |
| 1180 | /* Bump the statistics of received signalling msgs for this MM context */ |
| 1181 | rate_ctr_inc(&mmctx->ctrg->ctr[GMM_CTR_PKTS_SIG_IN]); |
| 1182 | |
Harald Welte | 9f1f3ad | 2010-05-02 12:56:57 +0200 | [diff] [blame] | 1183 | /* Update the MM context with the new RA-ID */ |
| 1184 | bssgp_parse_cell_id(&mmctx->ra, msgb_bcid(msg)); |
Harald Welte | f0901f0 | 2010-12-26 10:39:26 +0100 | [diff] [blame] | 1185 | /* Update the MM context with the new (i.e. foreign) TLLI */ |
Harald Welte | 9f1f3ad | 2010-05-02 12:56:57 +0200 | [diff] [blame] | 1186 | mmctx->tlli = msgb_tlli(msg); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1187 | /* FIXME: Update the MM context with the MS radio acc capabilities */ |
| 1188 | /* FIXME: Update the MM context with the MS network capabilities */ |
| 1189 | |
Harald Welte | 77289c2 | 2010-05-18 14:32:29 +0200 | [diff] [blame] | 1190 | rate_ctr_inc(&mmctx->ctrg->ctr[GMM_CTR_RA_UPDATE]); |
| 1191 | |
Harald Welte | c2e8cc4 | 2010-05-31 20:23:38 +0200 | [diff] [blame] | 1192 | #ifdef PTMSI_ALLOC |
Jacob Erlbeck | f6e7d99 | 2014-11-06 15:43:10 +0100 | [diff] [blame] | 1193 | /* Don't change the P-TMSI if a P-TMSI re-assignment is under way */ |
| 1194 | if (mmctx->mm_state != GMM_COMMON_PROC_INIT) { |
| 1195 | mmctx->p_tmsi_old = mmctx->p_tmsi; |
| 1196 | mmctx->p_tmsi = sgsn_alloc_ptmsi(); |
| 1197 | } |
Harald Welte | c2e8cc4 | 2010-05-31 20:23:38 +0200 | [diff] [blame] | 1198 | /* Start T3350 and re-transmit up to 5 times until ATTACH COMPLETE */ |
| 1199 | mmctx->t3350_mode = GMM_T3350_MODE_RAU; |
Harald Welte | 9450882 | 2015-08-15 19:08:21 +0200 | [diff] [blame] | 1200 | mmctx_timer_start(mmctx, 3350, sgsn->cfg.timers.T3350); |
Jacob Erlbeck | 0074a77 | 2014-10-28 16:23:46 +0100 | [diff] [blame] | 1201 | |
| 1202 | mmctx->mm_state = GMM_COMMON_PROC_INIT; |
| 1203 | #else |
| 1204 | /* Make sure we are NORMAL (i.e. not SUSPENDED anymore) */ |
| 1205 | mmctx->mm_state = GMM_REGISTERED_NORMAL; |
Holger Hans Peter Freyther | b100895 | 2015-05-02 19:55:38 +0200 | [diff] [blame] | 1206 | |
| 1207 | memset(&sig_data, 0, sizeof(sig_data)); |
| 1208 | sig_data.mm = mmctx; |
| 1209 | osmo_signal_dispatch(SS_SGSN, S_SGSN_UPDATE, &sig_data); |
Harald Welte | c2e8cc4 | 2010-05-31 20:23:38 +0200 | [diff] [blame] | 1210 | #endif |
Harald Welte | 807a5d8 | 2010-06-01 11:53:01 +0200 | [diff] [blame] | 1211 | /* Even if there is no P-TMSI allocated, the MS will switch from |
| 1212 | * foreign TLLI to local TLLI */ |
| 1213 | mmctx->tlli_new = gprs_tmsi2tlli(mmctx->p_tmsi, TLLI_LOCAL); |
Harald Welte | c2e8cc4 | 2010-05-31 20:23:38 +0200 | [diff] [blame] | 1214 | |
Harald Welte | 807a5d8 | 2010-06-01 11:53:01 +0200 | [diff] [blame] | 1215 | /* Inform LLC layer about new TLLI but keep old active */ |
Harald Welte | d6f582b | 2010-06-30 23:18:57 +0200 | [diff] [blame] | 1216 | gprs_llgmm_assign(mmctx->llme, mmctx->tlli, mmctx->tlli_new, |
| 1217 | GPRS_ALGO_GEA0, NULL); |
Harald Welte | 807a5d8 | 2010-06-01 11:53:01 +0200 | [diff] [blame] | 1218 | |
Harald Welte | 588d44e | 2010-06-09 10:28:29 +0200 | [diff] [blame] | 1219 | /* Look at PDP Context Status IE and see if MS's view of |
| 1220 | * activated/deactivated NSAPIs agrees with our view */ |
| 1221 | if (TLVP_PRESENT(&tp, GSM48_IE_GMM_PDP_CTX_STATUS)) { |
Holger Hans Peter Freyther | 2b17454 | 2011-10-14 23:31:34 +0200 | [diff] [blame] | 1222 | const uint8_t *pdp_status = TLVP_VAL(&tp, GSM48_IE_GMM_PDP_CTX_STATUS); |
Harald Welte | 588d44e | 2010-06-09 10:28:29 +0200 | [diff] [blame] | 1223 | process_ms_ctx_status(mmctx, pdp_status); |
| 1224 | } |
| 1225 | |
Harald Welte | 807a5d8 | 2010-06-01 11:53:01 +0200 | [diff] [blame] | 1226 | /* Send RA UPDATE ACCEPT */ |
Harald Welte | 6463c07 | 2010-05-18 17:04:55 +0200 | [diff] [blame] | 1227 | return gsm48_tx_gmm_ra_upd_ack(mmctx); |
Jacob Erlbeck | 80d07e3 | 2014-11-06 13:43:41 +0100 | [diff] [blame] | 1228 | |
| 1229 | rejected: |
| 1230 | /* Send RA UPDATE REJECT */ |
| 1231 | LOGMMCTXP(LOGL_NOTICE, mmctx, |
| 1232 | "Rejecting RA Update Request with cause '%s' (%d)\n", |
Jacob Erlbeck | afcf230 | 2015-01-05 17:30:02 +0100 | [diff] [blame] | 1233 | get_value_string(gsm48_gmm_cause_names, reject_cause), reject_cause); |
Jacob Erlbeck | 80d07e3 | 2014-11-06 13:43:41 +0100 | [diff] [blame] | 1234 | rc = gsm48_tx_gmm_ra_upd_rej(msg, reject_cause); |
| 1235 | if (mmctx) |
| 1236 | mm_ctx_cleanup_free(mmctx, "GPRS RA UPDATE REJ"); |
| 1237 | else |
| 1238 | /* TLLI unassignment */ |
| 1239 | gprs_llgmm_assign(llme, llme->tlli, 0xffffffff, GPRS_ALGO_GEA0, |
| 1240 | NULL); |
| 1241 | |
| 1242 | return rc; |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1243 | } |
| 1244 | |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 1245 | static int gsm48_rx_gmm_status(struct sgsn_mm_ctx *mmctx, struct msgb *msg) |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1246 | { |
| 1247 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 1248 | |
Daniel Willmann | 4655314 | 2014-09-03 17:46:44 +0200 | [diff] [blame] | 1249 | LOGMMCTXP(LOGL_INFO, mmctx, "-> GPRS MM STATUS (cause: %s)\n", |
Jacob Erlbeck | afcf230 | 2015-01-05 17:30:02 +0100 | [diff] [blame] | 1250 | get_value_string(gsm48_gmm_cause_names, gh->data[0])); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1251 | |
| 1252 | return 0; |
| 1253 | } |
| 1254 | |
| 1255 | /* GPRS Mobility Management */ |
Harald Welte | 807a5d8 | 2010-06-01 11:53:01 +0200 | [diff] [blame] | 1256 | static int gsm0408_rcv_gmm(struct sgsn_mm_ctx *mmctx, struct msgb *msg, |
| 1257 | struct gprs_llc_llme *llme) |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1258 | { |
Holger Hans Peter Freyther | b100895 | 2015-05-02 19:55:38 +0200 | [diff] [blame] | 1259 | struct sgsn_signal_data sig_data; |
Harald Welte | 943c5bc | 2010-04-30 16:33:12 +0200 | [diff] [blame] | 1260 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_gmmh(msg); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1261 | int rc; |
| 1262 | |
Harald Welte | 807a5d8 | 2010-06-01 11:53:01 +0200 | [diff] [blame] | 1263 | /* MMCTX can be NULL when called */ |
| 1264 | |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 1265 | if (!mmctx && |
| 1266 | gh->msg_type != GSM48_MT_GMM_ATTACH_REQ && |
Harald Welte | c2e8cc4 | 2010-05-31 20:23:38 +0200 | [diff] [blame] | 1267 | gh->msg_type != GSM48_MT_GMM_RA_UPD_REQ) { |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 1268 | LOGP(DMM, LOGL_NOTICE, "Cannot handle GMM for unknown MM CTX\n"); |
Jacob Erlbeck | 78ecaf0 | 2014-09-05 14:32:36 +0200 | [diff] [blame] | 1269 | /* 4.7.10 */ |
Jacob Erlbeck | 14ae582 | 2014-10-28 09:47:03 +0100 | [diff] [blame] | 1270 | if (gh->msg_type == GSM48_MT_GMM_STATUS) { |
| 1271 | /* TLLI unassignment */ |
| 1272 | gprs_llgmm_assign(llme, llme->tlli, 0xffffffff, |
| 1273 | GPRS_ALGO_GEA0, NULL); |
Jacob Erlbeck | 78ecaf0 | 2014-09-05 14:32:36 +0200 | [diff] [blame] | 1274 | return 0; |
Jacob Erlbeck | 14ae582 | 2014-10-28 09:47:03 +0100 | [diff] [blame] | 1275 | } |
Jacob Erlbeck | 78ecaf0 | 2014-09-05 14:32:36 +0200 | [diff] [blame] | 1276 | |
Jacob Erlbeck | 78ecaf0 | 2014-09-05 14:32:36 +0200 | [diff] [blame] | 1277 | /* Don't reply or establish a LLME on DETACH_ACK */ |
| 1278 | if (gh->msg_type == GSM48_MT_GMM_DETACH_ACK) { |
| 1279 | /* TLLI unassignment */ |
| 1280 | return gprs_llgmm_assign(llme, llme->tlli, 0xffffffff, |
| 1281 | GPRS_ALGO_GEA0, NULL); |
| 1282 | } |
| 1283 | |
Jacob Erlbeck | c4f9bf3 | 2014-11-11 08:55:13 +0100 | [diff] [blame] | 1284 | gprs_llgmm_reset(llme); |
| 1285 | |
Jacob Erlbeck | 78ecaf0 | 2014-09-05 14:32:36 +0200 | [diff] [blame] | 1286 | /* Don't force it into re-attachment */ |
| 1287 | if (gh->msg_type == GSM48_MT_GMM_DETACH_REQ) { |
Jacob Erlbeck | 5a38f64 | 2014-10-21 13:09:55 +0200 | [diff] [blame] | 1288 | /* Handle Detach Request */ |
| 1289 | rc = gsm48_rx_gmm_det_req(NULL, msg); |
Jacob Erlbeck | 78ecaf0 | 2014-09-05 14:32:36 +0200 | [diff] [blame] | 1290 | |
| 1291 | /* TLLI unassignment */ |
| 1292 | gprs_llgmm_assign(llme, llme->tlli, 0xffffffff, |
| 1293 | GPRS_ALGO_GEA0, NULL); |
| 1294 | return rc; |
| 1295 | } |
| 1296 | |
| 1297 | /* Force the MS to re-attach */ |
Jacob Erlbeck | b1c074f | 2014-10-31 12:27:11 +0100 | [diff] [blame] | 1298 | rc = sgsn_force_reattach_oldmsg(msg); |
| 1299 | |
| 1300 | /* TLLI unassignment */ |
| 1301 | gprs_llgmm_assign(llme, llme->tlli, 0xffffffff, |
| 1302 | GPRS_ALGO_GEA0, NULL); |
| 1303 | return rc; |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 1304 | } |
| 1305 | |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1306 | switch (gh->msg_type) { |
| 1307 | case GSM48_MT_GMM_RA_UPD_REQ: |
Harald Welte | 807a5d8 | 2010-06-01 11:53:01 +0200 | [diff] [blame] | 1308 | rc = gsm48_rx_gmm_ra_upd_req(mmctx, msg, llme); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1309 | break; |
| 1310 | case GSM48_MT_GMM_ATTACH_REQ: |
Harald Welte | 807a5d8 | 2010-06-01 11:53:01 +0200 | [diff] [blame] | 1311 | rc = gsm48_rx_gmm_att_req(mmctx, msg, llme); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1312 | break; |
Daniel Willmann | 4655314 | 2014-09-03 17:46:44 +0200 | [diff] [blame] | 1313 | /* For all the following types mmctx can not be NULL */ |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1314 | case GSM48_MT_GMM_ID_RESP: |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 1315 | rc = gsm48_rx_gmm_id_resp(mmctx, msg); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1316 | break; |
| 1317 | case GSM48_MT_GMM_STATUS: |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 1318 | rc = gsm48_rx_gmm_status(mmctx, msg); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1319 | break; |
Harald Welte | 2720e73 | 2010-05-17 00:44:57 +0200 | [diff] [blame] | 1320 | case GSM48_MT_GMM_DETACH_REQ: |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 1321 | rc = gsm48_rx_gmm_det_req(mmctx, msg); |
Harald Welte | 2720e73 | 2010-05-17 00:44:57 +0200 | [diff] [blame] | 1322 | break; |
Jacob Erlbeck | 78ecaf0 | 2014-09-05 14:32:36 +0200 | [diff] [blame] | 1323 | case GSM48_MT_GMM_DETACH_ACK: |
| 1324 | LOGMMCTXP(LOGL_INFO, mmctx, "-> DETACH ACK\n"); |
| 1325 | mm_ctx_cleanup_free(mmctx, "GPRS DETACH ACK"); |
| 1326 | rc = 0; |
| 1327 | break; |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1328 | case GSM48_MT_GMM_ATTACH_COMPL: |
| 1329 | /* only in case SGSN offered new P-TMSI */ |
Daniel Willmann | 4655314 | 2014-09-03 17:46:44 +0200 | [diff] [blame] | 1330 | LOGMMCTXP(LOGL_INFO, mmctx, "-> ATTACH COMPLETE\n"); |
Harald Welte | c2e8cc4 | 2010-05-31 20:23:38 +0200 | [diff] [blame] | 1331 | mmctx_timer_stop(mmctx, 3350); |
Jacob Erlbeck | 93eae8e | 2014-10-28 12:23:29 +0100 | [diff] [blame] | 1332 | mmctx->t3350_mode = GMM_T3350_MODE_NONE; |
Harald Welte | c2e8cc4 | 2010-05-31 20:23:38 +0200 | [diff] [blame] | 1333 | mmctx->p_tmsi_old = 0; |
Jacob Erlbeck | 93eae8e | 2014-10-28 12:23:29 +0100 | [diff] [blame] | 1334 | mmctx->pending_req = 0; |
Harald Welte | 807a5d8 | 2010-06-01 11:53:01 +0200 | [diff] [blame] | 1335 | /* Unassign the old TLLI */ |
| 1336 | mmctx->tlli = mmctx->tlli_new; |
Harald Welte | d6f582b | 2010-06-30 23:18:57 +0200 | [diff] [blame] | 1337 | gprs_llgmm_assign(mmctx->llme, 0xffffffff, mmctx->tlli_new, |
| 1338 | GPRS_ALGO_GEA0, NULL); |
Jacob Erlbeck | 0074a77 | 2014-10-28 16:23:46 +0100 | [diff] [blame] | 1339 | mmctx->mm_state = GMM_REGISTERED_NORMAL; |
Holger Hans Peter Freyther | 2b17454 | 2011-10-14 23:31:34 +0200 | [diff] [blame] | 1340 | rc = 0; |
Holger Hans Peter Freyther | b100895 | 2015-05-02 19:55:38 +0200 | [diff] [blame] | 1341 | |
| 1342 | memset(&sig_data, 0, sizeof(sig_data)); |
| 1343 | sig_data.mm = mmctx; |
| 1344 | osmo_signal_dispatch(SS_SGSN, S_SGSN_ATTACH, &sig_data); |
Harald Welte | c2e8cc4 | 2010-05-31 20:23:38 +0200 | [diff] [blame] | 1345 | break; |
Harald Welte | ab1d562 | 2010-05-18 19:58:38 +0200 | [diff] [blame] | 1346 | case GSM48_MT_GMM_RA_UPD_COMPL: |
| 1347 | /* only in case SGSN offered new P-TMSI */ |
Daniel Willmann | 4655314 | 2014-09-03 17:46:44 +0200 | [diff] [blame] | 1348 | LOGMMCTXP(LOGL_INFO, mmctx, "-> ROUTEING AREA UPDATE COMPLETE\n"); |
Harald Welte | c2e8cc4 | 2010-05-31 20:23:38 +0200 | [diff] [blame] | 1349 | mmctx_timer_stop(mmctx, 3350); |
Jacob Erlbeck | 93eae8e | 2014-10-28 12:23:29 +0100 | [diff] [blame] | 1350 | mmctx->t3350_mode = GMM_T3350_MODE_NONE; |
Harald Welte | c2e8cc4 | 2010-05-31 20:23:38 +0200 | [diff] [blame] | 1351 | mmctx->p_tmsi_old = 0; |
Jacob Erlbeck | 93eae8e | 2014-10-28 12:23:29 +0100 | [diff] [blame] | 1352 | mmctx->pending_req = 0; |
Harald Welte | 807a5d8 | 2010-06-01 11:53:01 +0200 | [diff] [blame] | 1353 | /* Unassign the old TLLI */ |
| 1354 | mmctx->tlli = mmctx->tlli_new; |
Harald Welte | d6f582b | 2010-06-30 23:18:57 +0200 | [diff] [blame] | 1355 | gprs_llgmm_assign(mmctx->llme, 0xffffffff, mmctx->tlli_new, |
| 1356 | GPRS_ALGO_GEA0, NULL); |
Jacob Erlbeck | 0074a77 | 2014-10-28 16:23:46 +0100 | [diff] [blame] | 1357 | mmctx->mm_state = GMM_REGISTERED_NORMAL; |
Holger Hans Peter Freyther | 2b17454 | 2011-10-14 23:31:34 +0200 | [diff] [blame] | 1358 | rc = 0; |
Holger Hans Peter Freyther | b100895 | 2015-05-02 19:55:38 +0200 | [diff] [blame] | 1359 | |
| 1360 | memset(&sig_data, 0, sizeof(sig_data)); |
| 1361 | sig_data.mm = mmctx; |
| 1362 | osmo_signal_dispatch(SS_SGSN, S_SGSN_UPDATE, &sig_data); |
Harald Welte | c2e8cc4 | 2010-05-31 20:23:38 +0200 | [diff] [blame] | 1363 | break; |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1364 | case GSM48_MT_GMM_PTMSI_REALL_COMPL: |
Daniel Willmann | 4655314 | 2014-09-03 17:46:44 +0200 | [diff] [blame] | 1365 | LOGMMCTXP(LOGL_INFO, mmctx, "-> PTMSI REALLLICATION COMPLETE\n"); |
Harald Welte | c2e8cc4 | 2010-05-31 20:23:38 +0200 | [diff] [blame] | 1366 | mmctx_timer_stop(mmctx, 3350); |
Jacob Erlbeck | 93eae8e | 2014-10-28 12:23:29 +0100 | [diff] [blame] | 1367 | mmctx->t3350_mode = GMM_T3350_MODE_NONE; |
Harald Welte | c2e8cc4 | 2010-05-31 20:23:38 +0200 | [diff] [blame] | 1368 | mmctx->p_tmsi_old = 0; |
Jacob Erlbeck | 93eae8e | 2014-10-28 12:23:29 +0100 | [diff] [blame] | 1369 | mmctx->pending_req = 0; |
Harald Welte | 807a5d8 | 2010-06-01 11:53:01 +0200 | [diff] [blame] | 1370 | /* Unassign the old TLLI */ |
| 1371 | mmctx->tlli = mmctx->tlli_new; |
Harald Welte | d6f582b | 2010-06-30 23:18:57 +0200 | [diff] [blame] | 1372 | //gprs_llgmm_assign(mmctx->llme, 0xffffffff, mmctx->tlli_new, GPRS_ALGO_GEA0, NULL); |
Holger Hans Peter Freyther | 2b17454 | 2011-10-14 23:31:34 +0200 | [diff] [blame] | 1373 | rc = 0; |
Harald Welte | c2e8cc4 | 2010-05-31 20:23:38 +0200 | [diff] [blame] | 1374 | break; |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1375 | case GSM48_MT_GMM_AUTH_CIPH_RESP: |
Harald Welte | 4b6ac1e | 2010-07-03 11:09:06 +0200 | [diff] [blame] | 1376 | rc = gsm48_rx_gmm_auth_ciph_resp(mmctx, msg); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1377 | break; |
| 1378 | default: |
Daniel Willmann | 4655314 | 2014-09-03 17:46:44 +0200 | [diff] [blame] | 1379 | LOGMMCTXP(LOGL_NOTICE, mmctx, "Unknown GSM 04.08 GMM msg type 0x%02x\n", |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1380 | gh->msg_type); |
Harald Welte | f54e7e2 | 2010-06-09 10:51:23 +0200 | [diff] [blame] | 1381 | rc = gsm48_tx_gmm_status(mmctx, GMM_CAUSE_MSGT_NOTEXIST_NOTIMPL); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1382 | break; |
| 1383 | } |
| 1384 | |
| 1385 | return rc; |
| 1386 | } |
| 1387 | |
Harald Welte | c2e8cc4 | 2010-05-31 20:23:38 +0200 | [diff] [blame] | 1388 | static void mmctx_timer_cb(void *_mm) |
| 1389 | { |
| 1390 | struct sgsn_mm_ctx *mm = _mm; |
Jacob Erlbeck | bd0cf11 | 2014-12-01 12:33:33 +0100 | [diff] [blame] | 1391 | struct gsm_auth_tuple *at; |
Harald Welte | c2e8cc4 | 2010-05-31 20:23:38 +0200 | [diff] [blame] | 1392 | |
| 1393 | mm->num_T_exp++; |
| 1394 | |
| 1395 | switch (mm->T) { |
| 1396 | case 3350: /* waiting for ATTACH COMPLETE */ |
| 1397 | if (mm->num_T_exp >= 5) { |
Daniel Willmann | 4655314 | 2014-09-03 17:46:44 +0200 | [diff] [blame] | 1398 | LOGMMCTXP(LOGL_NOTICE, mm, "T3350 expired >= 5 times\n"); |
Jacob Erlbeck | a790456 | 2014-11-03 10:12:52 +0100 | [diff] [blame] | 1399 | mm_ctx_cleanup_free(mm, "T3350"); |
Harald Welte | c2e8cc4 | 2010-05-31 20:23:38 +0200 | [diff] [blame] | 1400 | /* FIXME: should we return some error? */ |
| 1401 | break; |
| 1402 | } |
| 1403 | /* re-transmit the respective msg and re-start timer */ |
| 1404 | switch (mm->t3350_mode) { |
| 1405 | case GMM_T3350_MODE_ATT: |
| 1406 | gsm48_tx_gmm_att_ack(mm); |
| 1407 | break; |
| 1408 | case GMM_T3350_MODE_RAU: |
| 1409 | gsm48_tx_gmm_ra_upd_ack(mm); |
| 1410 | break; |
| 1411 | case GMM_T3350_MODE_PTMSI_REALL: |
| 1412 | /* FIXME */ |
| 1413 | break; |
Jacob Erlbeck | 93eae8e | 2014-10-28 12:23:29 +0100 | [diff] [blame] | 1414 | case GMM_T3350_MODE_NONE: |
| 1415 | LOGMMCTXP(LOGL_NOTICE, mm, |
| 1416 | "T3350 mode wasn't set, ignoring timeout\n"); |
| 1417 | break; |
Harald Welte | c2e8cc4 | 2010-05-31 20:23:38 +0200 | [diff] [blame] | 1418 | } |
Harald Welte | 9450882 | 2015-08-15 19:08:21 +0200 | [diff] [blame] | 1419 | osmo_timer_schedule(&mm->timer, sgsn->cfg.timers.T3350, 0); |
Harald Welte | c2e8cc4 | 2010-05-31 20:23:38 +0200 | [diff] [blame] | 1420 | break; |
Harald Welte | 4b6ac1e | 2010-07-03 11:09:06 +0200 | [diff] [blame] | 1421 | case 3360: /* waiting for AUTH AND CIPH RESP */ |
| 1422 | if (mm->num_T_exp >= 5) { |
Daniel Willmann | 4655314 | 2014-09-03 17:46:44 +0200 | [diff] [blame] | 1423 | LOGMMCTXP(LOGL_NOTICE, mm, "T3360 expired >= 5 times\n"); |
Jacob Erlbeck | a790456 | 2014-11-03 10:12:52 +0100 | [diff] [blame] | 1424 | mm_ctx_cleanup_free(mm, "T3360"); |
Harald Welte | 4b6ac1e | 2010-07-03 11:09:06 +0200 | [diff] [blame] | 1425 | break; |
| 1426 | } |
Jacob Erlbeck | bd0cf11 | 2014-12-01 12:33:33 +0100 | [diff] [blame] | 1427 | /* Re-transmit the respective msg and re-start timer */ |
| 1428 | if (mm->auth_triplet.key_seq == GSM_KEY_SEQ_INVAL) { |
| 1429 | LOGMMCTXP(LOGL_ERROR, mm, |
| 1430 | "timeout: invalid auth triplet reference\n"); |
| 1431 | mm_ctx_cleanup_free(mm, "T3360"); |
| 1432 | break; |
| 1433 | } |
| 1434 | at = &mm->auth_triplet; |
| 1435 | |
| 1436 | gsm48_tx_gmm_auth_ciph_req(mm, at->rand, at->key_seq, GPRS_ALGO_GEA0); |
Harald Welte | 9450882 | 2015-08-15 19:08:21 +0200 | [diff] [blame] | 1437 | osmo_timer_schedule(&mm->timer, sgsn->cfg.timers.T3360, 0); |
Harald Welte | 4b6ac1e | 2010-07-03 11:09:06 +0200 | [diff] [blame] | 1438 | break; |
Harald Welte | c2e8cc4 | 2010-05-31 20:23:38 +0200 | [diff] [blame] | 1439 | case 3370: /* waiting for IDENTITY RESPONSE */ |
| 1440 | if (mm->num_T_exp >= 5) { |
Daniel Willmann | 4655314 | 2014-09-03 17:46:44 +0200 | [diff] [blame] | 1441 | LOGMMCTXP(LOGL_NOTICE, mm, "T3370 expired >= 5 times\n"); |
Harald Welte | c2e8cc4 | 2010-05-31 20:23:38 +0200 | [diff] [blame] | 1442 | gsm48_tx_gmm_att_rej(mm, GMM_CAUSE_MS_ID_NOT_DERIVED); |
Jacob Erlbeck | a790456 | 2014-11-03 10:12:52 +0100 | [diff] [blame] | 1443 | mm_ctx_cleanup_free(mm, "GPRS ATTACH REJECT (T3370)"); |
Harald Welte | c2e8cc4 | 2010-05-31 20:23:38 +0200 | [diff] [blame] | 1444 | break; |
| 1445 | } |
| 1446 | /* re-tranmit IDENTITY REQUEST and re-start timer */ |
| 1447 | gsm48_tx_gmm_id_req(mm, mm->t3370_id_type); |
Harald Welte | 9450882 | 2015-08-15 19:08:21 +0200 | [diff] [blame] | 1448 | osmo_timer_schedule(&mm->timer, sgsn->cfg.timers.T3370, 0); |
Harald Welte | c2e8cc4 | 2010-05-31 20:23:38 +0200 | [diff] [blame] | 1449 | break; |
| 1450 | default: |
Daniel Willmann | 4655314 | 2014-09-03 17:46:44 +0200 | [diff] [blame] | 1451 | LOGMMCTXP(LOGL_ERROR, mm, "timer expired in unknown mode %u\n", |
Harald Welte | c2e8cc4 | 2010-05-31 20:23:38 +0200 | [diff] [blame] | 1452 | mm->T); |
| 1453 | } |
| 1454 | } |
| 1455 | |
| 1456 | /* GPRS SESSION MANAGEMENT */ |
| 1457 | |
Harald Welte | a9b473a | 2010-12-24 21:13:26 +0100 | [diff] [blame] | 1458 | static void pdpctx_timer_cb(void *_mm); |
| 1459 | |
| 1460 | static void pdpctx_timer_start(struct sgsn_pdp_ctx *pdp, unsigned int T, |
| 1461 | unsigned int seconds) |
| 1462 | { |
Pablo Neira Ayuso | bf540cb | 2011-05-06 12:11:06 +0200 | [diff] [blame] | 1463 | if (osmo_timer_pending(&pdp->timer)) |
Harald Welte | a9b473a | 2010-12-24 21:13:26 +0100 | [diff] [blame] | 1464 | LOGP(DMM, LOGL_ERROR, "Starting MM timer %u while old " |
| 1465 | "timer %u pending\n", T, pdp->T); |
| 1466 | pdp->T = T; |
| 1467 | pdp->num_T_exp = 0; |
| 1468 | |
| 1469 | /* FIXME: we should do this only once ? */ |
| 1470 | pdp->timer.data = pdp; |
| 1471 | pdp->timer.cb = &pdpctx_timer_cb; |
| 1472 | |
Pablo Neira Ayuso | bf540cb | 2011-05-06 12:11:06 +0200 | [diff] [blame] | 1473 | osmo_timer_schedule(&pdp->timer, seconds, 0); |
Harald Welte | a9b473a | 2010-12-24 21:13:26 +0100 | [diff] [blame] | 1474 | } |
| 1475 | |
Holger Hans Peter Freyther | 1768a57 | 2014-04-04 12:40:34 +0200 | [diff] [blame] | 1476 | #if 0 |
Harald Welte | 421cba4 | 2010-05-02 23:11:50 +0200 | [diff] [blame] | 1477 | static void msgb_put_pdp_addr_ipv4(struct msgb *msg, uint32_t ipaddr) |
| 1478 | { |
| 1479 | uint8_t v[6]; |
| 1480 | |
| 1481 | v[0] = PDP_TYPE_ORG_IETF; |
| 1482 | v[1] = PDP_TYPE_N_IETF_IPv4; |
| 1483 | *(uint32_t *)(v+2) = htonl(ipaddr); |
| 1484 | |
| 1485 | msgb_tlv_put(msg, GSM48_IE_GSM_PDP_ADDR, sizeof(v), v); |
| 1486 | } |
| 1487 | |
| 1488 | static void msgb_put_pdp_addr_ppp(struct msgb *msg) |
| 1489 | { |
| 1490 | uint8_t v[2]; |
| 1491 | |
| 1492 | v[0] = PDP_TYPE_ORG_ETSI; |
| 1493 | v[1] = PDP_TYPE_N_ETSI_PPP; |
| 1494 | |
| 1495 | msgb_tlv_put(msg, GSM48_IE_GSM_PDP_ADDR, sizeof(v), v); |
| 1496 | } |
Holger Hans Peter Freyther | 1768a57 | 2014-04-04 12:40:34 +0200 | [diff] [blame] | 1497 | #endif |
Harald Welte | 421cba4 | 2010-05-02 23:11:50 +0200 | [diff] [blame] | 1498 | |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1499 | /* Section 9.5.2: Ativate PDP Context Accept */ |
Harald Welte | 6abf94e | 2010-05-18 10:35:06 +0200 | [diff] [blame] | 1500 | int gsm48_tx_gsm_act_pdp_acc(struct sgsn_pdp_ctx *pdp) |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1501 | { |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1502 | struct msgb *msg = gsm48_msgb_alloc(); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1503 | struct gsm48_hdr *gh; |
Harald Welte | 6abf94e | 2010-05-18 10:35:06 +0200 | [diff] [blame] | 1504 | uint8_t transaction_id = pdp->ti ^ 0x8; /* flip */ |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1505 | |
Daniel Willmann | 4655314 | 2014-09-03 17:46:44 +0200 | [diff] [blame] | 1506 | LOGPDPCTXP(LOGL_INFO, pdp, "<- ACTIVATE PDP CONTEXT ACK\n"); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1507 | |
Harald Welte | 6abf94e | 2010-05-18 10:35:06 +0200 | [diff] [blame] | 1508 | mmctx2msgid(msg, pdp->mm); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1509 | |
| 1510 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 1511 | gh->proto_discr = GSM48_PDISC_SM_GPRS | (transaction_id << 4); |
| 1512 | gh->msg_type = GSM48_MT_GSM_ACT_PDP_ACK; |
Harald Welte | 421cba4 | 2010-05-02 23:11:50 +0200 | [diff] [blame] | 1513 | |
| 1514 | /* Negotiated LLC SAPI */ |
Harald Welte | 6abf94e | 2010-05-18 10:35:06 +0200 | [diff] [blame] | 1515 | msgb_v_put(msg, pdp->sapi); |
Harald Welte | 4e38ac7 | 2010-05-18 14:51:18 +0200 | [diff] [blame] | 1516 | |
Harald Welte | 55e0df7 | 2010-05-18 13:20:08 +0200 | [diff] [blame] | 1517 | /* FIXME: copy QoS parameters from original request */ |
| 1518 | //msgb_lv_put(msg, pdp->lib->qos_neg.l, pdp->lib->qos_neg.v); |
| 1519 | msgb_lv_put(msg, sizeof(default_qos), (uint8_t *)&default_qos); |
Harald Welte | 4e38ac7 | 2010-05-18 14:51:18 +0200 | [diff] [blame] | 1520 | |
Harald Welte | 421cba4 | 2010-05-02 23:11:50 +0200 | [diff] [blame] | 1521 | /* Radio priority 10.5.7.2 */ |
Harald Welte | 6abf94e | 2010-05-18 10:35:06 +0200 | [diff] [blame] | 1522 | msgb_v_put(msg, pdp->lib->radio_pri); |
Harald Welte | 4e38ac7 | 2010-05-18 14:51:18 +0200 | [diff] [blame] | 1523 | |
Harald Welte | 421cba4 | 2010-05-02 23:11:50 +0200 | [diff] [blame] | 1524 | /* PDP address */ |
Harald Welte | 4e38ac7 | 2010-05-18 14:51:18 +0200 | [diff] [blame] | 1525 | /* Highest 4 bits of first byte need to be set to 1, otherwise |
| 1526 | * the IE is identical with the 04.08 PDP Address IE */ |
| 1527 | pdp->lib->eua.v[0] &= ~0xf0; |
Harald Welte | 6abf94e | 2010-05-18 10:35:06 +0200 | [diff] [blame] | 1528 | msgb_tlv_put(msg, GSM48_IE_GSM_PDP_ADDR, |
| 1529 | pdp->lib->eua.l, pdp->lib->eua.v); |
Harald Welte | 4e38ac7 | 2010-05-18 14:51:18 +0200 | [diff] [blame] | 1530 | pdp->lib->eua.v[0] |= 0xf0; |
| 1531 | |
Harald Welte | 77289c2 | 2010-05-18 14:32:29 +0200 | [diff] [blame] | 1532 | /* Optional: Protocol configuration options (FIXME: why 'req') */ |
Holger Hans Peter Freyther | d219507 | 2014-04-04 11:55:21 +0200 | [diff] [blame] | 1533 | if (pdp->lib->pco_req.l) |
Harald Welte | 6abf94e | 2010-05-18 10:35:06 +0200 | [diff] [blame] | 1534 | msgb_tlv_put(msg, GSM48_IE_GSM_PROTO_CONF_OPT, |
Harald Welte | 3c0b9b9 | 2010-05-18 14:36:11 +0200 | [diff] [blame] | 1535 | pdp->lib->pco_req.l, pdp->lib->pco_req.v); |
Harald Welte | 4e38ac7 | 2010-05-18 14:51:18 +0200 | [diff] [blame] | 1536 | |
Harald Welte | 421cba4 | 2010-05-02 23:11:50 +0200 | [diff] [blame] | 1537 | /* Optional: Packet Flow Identifier */ |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1538 | |
Harald Welte | 8acd88f | 2010-05-18 10:57:45 +0200 | [diff] [blame] | 1539 | return gsm48_gmm_sendmsg(msg, 0, pdp->mm); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1540 | } |
| 1541 | |
Harald Welte | 6abf94e | 2010-05-18 10:35:06 +0200 | [diff] [blame] | 1542 | /* Section 9.5.3: Activate PDP Context reject */ |
| 1543 | int gsm48_tx_gsm_act_pdp_rej(struct sgsn_mm_ctx *mm, uint8_t tid, |
| 1544 | uint8_t cause, uint8_t pco_len, uint8_t *pco_v) |
| 1545 | { |
| 1546 | struct msgb *msg = gsm48_msgb_alloc(); |
Harald Welte | 6abf94e | 2010-05-18 10:35:06 +0200 | [diff] [blame] | 1547 | struct gsm48_hdr *gh; |
| 1548 | uint8_t transaction_id = tid ^ 0x8; /* flip */ |
| 1549 | |
Daniel Willmann | 4655314 | 2014-09-03 17:46:44 +0200 | [diff] [blame] | 1550 | LOGMMCTXP(LOGL_NOTICE, mm, "<- ACTIVATE PDP CONTEXT REJ(cause=%u)\n", cause); |
Harald Welte | 6abf94e | 2010-05-18 10:35:06 +0200 | [diff] [blame] | 1551 | |
| 1552 | mmctx2msgid(msg, mm); |
| 1553 | |
| 1554 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 1555 | gh->proto_discr = GSM48_PDISC_SM_GPRS | (transaction_id << 4); |
| 1556 | gh->msg_type = GSM48_MT_GSM_ACT_PDP_REJ; |
| 1557 | |
| 1558 | msgb_v_put(msg, cause); |
| 1559 | if (pco_len && pco_v) |
| 1560 | msgb_tlv_put(msg, GSM48_IE_GSM_PROTO_CONF_OPT, pco_len, pco_v); |
| 1561 | |
Harald Welte | 8acd88f | 2010-05-18 10:57:45 +0200 | [diff] [blame] | 1562 | return gsm48_gmm_sendmsg(msg, 0, mm); |
Harald Welte | 6abf94e | 2010-05-18 10:35:06 +0200 | [diff] [blame] | 1563 | } |
| 1564 | |
Harald Welte | a9b473a | 2010-12-24 21:13:26 +0100 | [diff] [blame] | 1565 | /* Section 9.5.8: Deactivate PDP Context Request */ |
| 1566 | static int _gsm48_tx_gsm_deact_pdp_req(struct sgsn_mm_ctx *mm, uint8_t tid, |
| 1567 | uint8_t sm_cause) |
| 1568 | { |
| 1569 | struct msgb *msg = gsm48_msgb_alloc(); |
| 1570 | struct gsm48_hdr *gh; |
| 1571 | uint8_t transaction_id = tid ^ 0x8; /* flip */ |
| 1572 | |
Daniel Willmann | 4655314 | 2014-09-03 17:46:44 +0200 | [diff] [blame] | 1573 | LOGMMCTXP(LOGL_INFO, mm, "<- DEACTIVATE PDP CONTEXT REQ\n"); |
Harald Welte | a9b473a | 2010-12-24 21:13:26 +0100 | [diff] [blame] | 1574 | |
| 1575 | mmctx2msgid(msg, mm); |
| 1576 | |
| 1577 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 1578 | gh->proto_discr = GSM48_PDISC_SM_GPRS | (transaction_id << 4); |
| 1579 | gh->msg_type = GSM48_MT_GSM_DEACT_PDP_REQ; |
| 1580 | |
| 1581 | msgb_v_put(msg, sm_cause); |
| 1582 | |
| 1583 | return gsm48_gmm_sendmsg(msg, 0, mm); |
| 1584 | } |
| 1585 | int gsm48_tx_gsm_deact_pdp_req(struct sgsn_pdp_ctx *pdp, uint8_t sm_cause) |
| 1586 | { |
Harald Welte | 9450882 | 2015-08-15 19:08:21 +0200 | [diff] [blame] | 1587 | pdpctx_timer_start(pdp, 3395, sgsn->cfg.timers.T3395); |
Harald Welte | a9b473a | 2010-12-24 21:13:26 +0100 | [diff] [blame] | 1588 | |
| 1589 | return _gsm48_tx_gsm_deact_pdp_req(pdp->mm, pdp->ti, sm_cause); |
| 1590 | } |
| 1591 | |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1592 | /* Section 9.5.9: Deactivate PDP Context Accept */ |
Harald Welte | 60ebc02 | 2010-06-08 18:08:59 +0200 | [diff] [blame] | 1593 | static int _gsm48_tx_gsm_deact_pdp_acc(struct sgsn_mm_ctx *mm, uint8_t tid) |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1594 | { |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1595 | struct msgb *msg = gsm48_msgb_alloc(); |
| 1596 | struct gsm48_hdr *gh; |
Harald Welte | 60ebc02 | 2010-06-08 18:08:59 +0200 | [diff] [blame] | 1597 | uint8_t transaction_id = tid ^ 0x8; /* flip */ |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1598 | |
Daniel Willmann | 4655314 | 2014-09-03 17:46:44 +0200 | [diff] [blame] | 1599 | LOGMMCTXP(LOGL_INFO, mm, "<- DEACTIVATE PDP CONTEXT ACK\n"); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1600 | |
Harald Welte | 60ebc02 | 2010-06-08 18:08:59 +0200 | [diff] [blame] | 1601 | mmctx2msgid(msg, mm); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1602 | |
| 1603 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 1604 | gh->proto_discr = GSM48_PDISC_SM_GPRS | (transaction_id << 4); |
| 1605 | gh->msg_type = GSM48_MT_GSM_DEACT_PDP_ACK; |
| 1606 | |
Harald Welte | 60ebc02 | 2010-06-08 18:08:59 +0200 | [diff] [blame] | 1607 | return gsm48_gmm_sendmsg(msg, 0, mm); |
| 1608 | } |
| 1609 | int gsm48_tx_gsm_deact_pdp_acc(struct sgsn_pdp_ctx *pdp) |
| 1610 | { |
| 1611 | return _gsm48_tx_gsm_deact_pdp_acc(pdp->mm, pdp->ti); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1612 | } |
| 1613 | |
Holger Hans Peter Freyther | 7605bdc | 2015-05-24 12:42:26 +0800 | [diff] [blame] | 1614 | static int activate_ggsn(struct sgsn_mm_ctx *mmctx, |
| 1615 | struct sgsn_ggsn_ctx *ggsn, const uint8_t transaction_id, |
| 1616 | const uint8_t req_nsapi, const uint8_t req_llc_sapi, |
Holger Hans Peter Freyther | 39c430e | 2015-05-25 12:26:49 +0800 | [diff] [blame] | 1617 | struct tlv_parsed *tp, int destroy_ggsn) |
Holger Hans Peter Freyther | 7605bdc | 2015-05-24 12:42:26 +0800 | [diff] [blame] | 1618 | { |
| 1619 | struct sgsn_pdp_ctx *pdp; |
| 1620 | |
Holger Hans Peter Freyther | b7ae0b3 | 2015-05-29 15:11:55 +0200 | [diff] [blame] | 1621 | LOGMMCTXP(LOGL_DEBUG, mmctx, "Using GGSN %u\n", ggsn->id); |
Holger Hans Peter Freyther | 7605bdc | 2015-05-24 12:42:26 +0800 | [diff] [blame] | 1622 | ggsn->gsn = sgsn->gsn; |
| 1623 | pdp = sgsn_create_pdp_ctx(ggsn, mmctx, req_nsapi, tp); |
| 1624 | if (!pdp) |
| 1625 | return -1; |
| 1626 | |
| 1627 | /* Store SAPI and Transaction Identifier */ |
| 1628 | pdp->sapi = req_llc_sapi; |
| 1629 | pdp->ti = transaction_id; |
Holger Hans Peter Freyther | 39c430e | 2015-05-25 12:26:49 +0800 | [diff] [blame] | 1630 | pdp->destroy_ggsn = destroy_ggsn; |
Holger Hans Peter Freyther | 7605bdc | 2015-05-24 12:42:26 +0800 | [diff] [blame] | 1631 | |
| 1632 | return 0; |
| 1633 | } |
| 1634 | |
Holger Hans Peter Freyther | 39c430e | 2015-05-25 12:26:49 +0800 | [diff] [blame] | 1635 | static void ggsn_lookup_cb(void *arg, int status, int timeouts, struct hostent *hostent) |
| 1636 | { |
| 1637 | struct sgsn_ggsn_ctx *ggsn; |
| 1638 | struct sgsn_ggsn_lookup *lookup = arg; |
| 1639 | struct in_addr *addr = NULL; |
Holger Hans Peter Freyther | 39c430e | 2015-05-25 12:26:49 +0800 | [diff] [blame] | 1640 | |
| 1641 | /* The context is gone while we made a request */ |
| 1642 | if (!lookup->mmctx) { |
| 1643 | talloc_free(lookup); |
| 1644 | return; |
| 1645 | } |
| 1646 | |
| 1647 | if (status != ARES_SUCCESS) { |
| 1648 | struct sgsn_mm_ctx *mmctx = lookup->mmctx; |
| 1649 | |
| 1650 | LOGMMCTXP(LOGL_ERROR, mmctx, "DNS query failed.\n"); |
| 1651 | |
| 1652 | /* Need to try with three digits now */ |
| 1653 | if (lookup->state == SGSN_GGSN_2DIGIT) { |
| 1654 | char *hostname; |
| 1655 | int rc; |
| 1656 | |
| 1657 | lookup->state = SGSN_GGSN_3DIGIT; |
| 1658 | hostname = osmo_apn_qualify_from_imsi(mmctx->imsi, |
| 1659 | lookup->apn_str, 1); |
| 1660 | LOGMMCTXP(LOGL_DEBUG, mmctx, |
| 1661 | "Going to query %s\n", hostname); |
| 1662 | rc = sgsn_ares_query(sgsn, hostname, |
| 1663 | ggsn_lookup_cb, lookup); |
| 1664 | if (rc != 0) { |
| 1665 | LOGP(DGPRS, LOGL_ERROR, "Couldn't start GGSN\n"); |
| 1666 | goto reject_due_failure; |
| 1667 | } |
| 1668 | return; |
| 1669 | } |
| 1670 | |
| 1671 | LOGMMCTXP(LOGL_ERROR, mmctx, "Couldn't resolve GGSN\n"); |
| 1672 | goto reject_due_failure; |
| 1673 | } |
| 1674 | |
| 1675 | if (hostent->h_length != sizeof(struct in_addr)) { |
| 1676 | LOGMMCTXP(LOGL_ERROR, lookup->mmctx, |
| 1677 | "Wrong addr size(%d)\n", sizeof(struct in_addr)); |
| 1678 | goto reject_due_failure; |
| 1679 | } |
| 1680 | |
Holger Hans Peter Freyther | 0958938 | 2015-06-02 09:38:41 +0200 | [diff] [blame] | 1681 | /* Get the first addr from the list */ |
| 1682 | addr = (struct in_addr *) hostent->h_addr_list[0]; |
Holger Hans Peter Freyther | 39c430e | 2015-05-25 12:26:49 +0800 | [diff] [blame] | 1683 | if (!addr) { |
| 1684 | LOGMMCTXP(LOGL_ERROR, lookup->mmctx, "No host address.\n"); |
| 1685 | goto reject_due_failure; |
| 1686 | } |
| 1687 | |
| 1688 | ggsn = sgsn_ggsn_ctx_alloc(UINT32_MAX); |
| 1689 | if (!ggsn) { |
| 1690 | LOGMMCTXP(LOGL_ERROR, lookup->mmctx, "Failed to create ggsn.\n"); |
| 1691 | goto reject_due_failure; |
| 1692 | } |
| 1693 | ggsn->remote_addr = *addr; |
| 1694 | LOGMMCTXP(LOGL_NOTICE, lookup->mmctx, |
| 1695 | "Selected %s as GGSN.\n", inet_ntoa(*addr)); |
| 1696 | |
| 1697 | /* forget about the ggsn look-up */ |
| 1698 | lookup->mmctx->ggsn_lookup = NULL; |
| 1699 | |
| 1700 | activate_ggsn(lookup->mmctx, ggsn, lookup->ti, lookup->nsapi, |
| 1701 | lookup->sapi, &lookup->tp, 1); |
| 1702 | |
| 1703 | /* Now free it */ |
| 1704 | talloc_free(lookup); |
| 1705 | return; |
| 1706 | |
| 1707 | reject_due_failure: |
| 1708 | gsm48_tx_gsm_act_pdp_rej(lookup->mmctx, lookup->ti, |
| 1709 | GMM_CAUSE_NET_FAIL, 0, NULL); |
| 1710 | lookup->mmctx->ggsn_lookup = NULL; |
| 1711 | talloc_free(lookup); |
| 1712 | } |
Holger Hans Peter Freyther | ccd2312 | 2015-05-24 16:48:22 +0800 | [diff] [blame] | 1713 | |
| 1714 | static int do_act_pdp_req(struct sgsn_mm_ctx *mmctx, struct msgb *msg) |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1715 | { |
Harald Welte | 943c5bc | 2010-04-30 16:33:12 +0200 | [diff] [blame] | 1716 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_gmmh(msg); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1717 | struct gsm48_act_pdp_ctx_req *act_req = (struct gsm48_act_pdp_ctx_req *) gh->data; |
Harald Welte | 0c3eae0 | 2010-05-02 21:07:14 +0200 | [diff] [blame] | 1718 | uint8_t req_qos_len, req_pdpa_len; |
| 1719 | uint8_t *req_qos, *req_pdpa; |
| 1720 | struct tlv_parsed tp; |
Harald Welte | 6abf94e | 2010-05-18 10:35:06 +0200 | [diff] [blame] | 1721 | uint8_t transaction_id = (gh->proto_discr >> 4); |
Harald Welte | 11ff3e8 | 2010-07-02 10:17:24 +0200 | [diff] [blame] | 1722 | struct sgsn_ggsn_ctx *ggsn; |
Harald Welte | 6abf94e | 2010-05-18 10:35:06 +0200 | [diff] [blame] | 1723 | struct sgsn_pdp_ctx *pdp; |
Jacob Erlbeck | 277b71e | 2015-02-02 18:03:05 +0100 | [diff] [blame] | 1724 | enum gsm48_gsm_cause gsm_cause; |
Holger Hans Peter Freyther | 39c430e | 2015-05-25 12:26:49 +0800 | [diff] [blame] | 1725 | char apn_str[GSM_APN_LENGTH] = { 0, }; |
| 1726 | char *hostname; |
| 1727 | int rc; |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1728 | |
Daniel Willmann | 4655314 | 2014-09-03 17:46:44 +0200 | [diff] [blame] | 1729 | LOGMMCTXP(LOGL_INFO, mmctx, "-> ACTIVATE PDP CONTEXT REQ: SAPI=%u NSAPI=%u ", |
Harald Welte | 6abf94e | 2010-05-18 10:35:06 +0200 | [diff] [blame] | 1730 | act_req->req_llc_sapi, act_req->req_nsapi); |
Harald Welte | 8acd88f | 2010-05-18 10:57:45 +0200 | [diff] [blame] | 1731 | |
Harald Welte | 23c1376 | 2010-07-02 22:52:04 +0200 | [diff] [blame] | 1732 | /* FIXME: length checks! */ |
Harald Welte | 0c3eae0 | 2010-05-02 21:07:14 +0200 | [diff] [blame] | 1733 | req_qos_len = act_req->data[0]; |
| 1734 | req_qos = act_req->data + 1; /* 10.5.6.5 */ |
| 1735 | req_pdpa_len = act_req->data[1 + req_qos_len]; |
| 1736 | req_pdpa = act_req->data + 1 + req_qos_len + 1; /* 10.5.6.4 */ |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1737 | |
Harald Welte | 0c3eae0 | 2010-05-02 21:07:14 +0200 | [diff] [blame] | 1738 | switch (req_pdpa[0] & 0xf) { |
| 1739 | case 0x0: |
| 1740 | DEBUGPC(DMM, "ETSI "); |
| 1741 | break; |
| 1742 | case 0x1: |
| 1743 | DEBUGPC(DMM, "IETF "); |
| 1744 | break; |
| 1745 | case 0xf: |
| 1746 | DEBUGPC(DMM, "Empty "); |
| 1747 | break; |
| 1748 | } |
| 1749 | |
| 1750 | switch (req_pdpa[1]) { |
| 1751 | case 0x21: |
| 1752 | DEBUGPC(DMM, "IPv4 "); |
| 1753 | if (req_pdpa_len >= 6) { |
| 1754 | struct in_addr ia; |
| 1755 | ia.s_addr = ntohl(*((uint32_t *) (req_pdpa+2))); |
| 1756 | DEBUGPC(DMM, "%s ", inet_ntoa(ia)); |
| 1757 | } |
| 1758 | break; |
| 1759 | case 0x57: |
| 1760 | DEBUGPC(DMM, "IPv6 "); |
| 1761 | if (req_pdpa_len >= 18) { |
| 1762 | /* FIXME: print IPv6 address */ |
| 1763 | } |
| 1764 | break; |
| 1765 | default: |
| 1766 | DEBUGPC(DMM, "0x%02x ", req_pdpa[1]); |
| 1767 | break; |
| 1768 | } |
| 1769 | |
Daniel Willmann | 4655314 | 2014-09-03 17:46:44 +0200 | [diff] [blame] | 1770 | LOGPC(DMM, LOGL_INFO, "\n"); |
Harald Welte | 77289c2 | 2010-05-18 14:32:29 +0200 | [diff] [blame] | 1771 | |
Harald Welte | 6abf94e | 2010-05-18 10:35:06 +0200 | [diff] [blame] | 1772 | /* Check if NSAPI is out of range (TS 04.65 / 7.2) */ |
| 1773 | if (act_req->req_nsapi < 5 || act_req->req_nsapi > 15) { |
| 1774 | /* Send reject with GSM_CAUSE_INV_MAND_INFO */ |
| 1775 | return gsm48_tx_gsm_act_pdp_rej(mmctx, transaction_id, |
| 1776 | GSM_CAUSE_INV_MAND_INFO, |
| 1777 | 0, NULL); |
| 1778 | } |
| 1779 | |
Holger Hans Peter Freyther | 7605bdc | 2015-05-24 12:42:26 +0800 | [diff] [blame] | 1780 | /* Optional: Access Point Name, Protocol Config Options */ |
| 1781 | if (req_pdpa + req_pdpa_len < msg->data + msg->len) |
| 1782 | tlv_parse(&tp, &gsm48_sm_att_tlvdef, req_pdpa + req_pdpa_len, |
| 1783 | (msg->data + msg->len) - (req_pdpa + req_pdpa_len), 0, 0); |
| 1784 | else |
| 1785 | memset(&tp, 0, sizeof(tp)); |
| 1786 | |
| 1787 | |
| 1788 | /* put the non-TLV elements in the TLV parser structure to |
| 1789 | * pass them on to the SGSN / GTP code */ |
| 1790 | tp.lv[OSMO_IE_GSM_REQ_QOS].len = req_qos_len; |
| 1791 | tp.lv[OSMO_IE_GSM_REQ_QOS].val = req_qos; |
| 1792 | tp.lv[OSMO_IE_GSM_REQ_PDP_ADDR].len = req_pdpa_len; |
| 1793 | tp.lv[OSMO_IE_GSM_REQ_PDP_ADDR].val = req_pdpa; |
| 1794 | |
Harald Welte | 6abf94e | 2010-05-18 10:35:06 +0200 | [diff] [blame] | 1795 | /* Check if NSAPI is already in use */ |
Harald Welte | b37515e | 2010-07-02 10:12:58 +0200 | [diff] [blame] | 1796 | pdp = sgsn_pdp_ctx_by_nsapi(mmctx, act_req->req_nsapi); |
| 1797 | if (pdp) { |
| 1798 | /* We already have a PDP context for this TLLI + NSAPI tuple */ |
| 1799 | if (pdp->sapi == act_req->req_llc_sapi && |
| 1800 | pdp->ti == transaction_id) { |
| 1801 | /* This apparently is a re-transmission of a PDP CTX |
| 1802 | * ACT REQ (our ACT ACK must have got dropped) */ |
| 1803 | return gsm48_tx_gsm_act_pdp_acc(pdp); |
| 1804 | } |
| 1805 | |
| 1806 | /* Send reject with GSM_CAUSE_NSAPI_IN_USE */ |
Harald Welte | 6abf94e | 2010-05-18 10:35:06 +0200 | [diff] [blame] | 1807 | return gsm48_tx_gsm_act_pdp_rej(mmctx, transaction_id, |
| 1808 | GSM_CAUSE_NSAPI_IN_USE, |
| 1809 | 0, NULL); |
| 1810 | } |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1811 | |
Holger Hans Peter Freyther | 39c430e | 2015-05-25 12:26:49 +0800 | [diff] [blame] | 1812 | if (mmctx->ggsn_lookup) { |
| 1813 | if (mmctx->ggsn_lookup->sapi == act_req->req_llc_sapi && |
| 1814 | mmctx->ggsn_lookup->ti == transaction_id) { |
| 1815 | LOGMMCTXP(LOGL_NOTICE, mmctx, |
| 1816 | "Re-transmission while doing look-up. Ignoring.\n"); |
| 1817 | return 0; |
| 1818 | } |
| 1819 | } |
| 1820 | |
Harald Welte | 19f9e30 | 2010-07-02 10:15:49 +0200 | [diff] [blame] | 1821 | /* Only increment counter for a real activation, after we checked |
| 1822 | * for re-transmissions */ |
| 1823 | rate_ctr_inc(&mmctx->ctrg->ctr[GMM_CTR_PDP_CTX_ACT]); |
| 1824 | |
Jacob Erlbeck | 277b71e | 2015-02-02 18:03:05 +0100 | [diff] [blame] | 1825 | /* Determine GGSN based on APN and subscription options */ |
Holger Hans Peter Freyther | 39c430e | 2015-05-25 12:26:49 +0800 | [diff] [blame] | 1826 | ggsn = sgsn_mm_ctx_find_ggsn_ctx(mmctx, &tp, &gsm_cause, apn_str); |
| 1827 | if (ggsn) |
| 1828 | return activate_ggsn(mmctx, ggsn, transaction_id, |
| 1829 | act_req->req_nsapi, act_req->req_llc_sapi, |
| 1830 | &tp, 0); |
| 1831 | |
| 1832 | if (strlen(apn_str) == 0) |
| 1833 | goto no_context; |
| 1834 | if (!sgsn->cfg.dynamic_lookup) |
| 1835 | goto no_context; |
| 1836 | |
| 1837 | /* schedule a dynamic look-up */ |
| 1838 | mmctx->ggsn_lookup = talloc_zero(tall_bsc_ctx, struct sgsn_ggsn_lookup); |
| 1839 | if (!mmctx->ggsn_lookup) |
| 1840 | goto no_context; |
| 1841 | |
| 1842 | mmctx->ggsn_lookup->state = SGSN_GGSN_2DIGIT; |
| 1843 | mmctx->ggsn_lookup->mmctx = mmctx; |
| 1844 | strcpy(mmctx->ggsn_lookup->apn_str, apn_str); |
| 1845 | |
| 1846 | mmctx->ggsn_lookup->orig_msg = msg; |
| 1847 | mmctx->ggsn_lookup->tp = tp; |
| 1848 | |
| 1849 | mmctx->ggsn_lookup->ti = transaction_id; |
| 1850 | mmctx->ggsn_lookup->nsapi = act_req->req_nsapi; |
| 1851 | mmctx->ggsn_lookup->sapi = act_req->req_llc_sapi; |
| 1852 | |
| 1853 | hostname = osmo_apn_qualify_from_imsi(mmctx->imsi, |
| 1854 | mmctx->ggsn_lookup->apn_str, 0); |
| 1855 | |
| 1856 | LOGMMCTXP(LOGL_DEBUG, mmctx, "Going to query %s\n", hostname); |
| 1857 | rc = sgsn_ares_query(sgsn, hostname, |
| 1858 | ggsn_lookup_cb, mmctx->ggsn_lookup); |
| 1859 | if (rc != 0) { |
| 1860 | LOGMMCTXP(LOGL_ERROR, mmctx, "Failed to start ares query.\n"); |
| 1861 | goto no_context; |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 1862 | } |
Harald Welte | 11ff3e8 | 2010-07-02 10:17:24 +0200 | [diff] [blame] | 1863 | |
Holger Hans Peter Freyther | 39c430e | 2015-05-25 12:26:49 +0800 | [diff] [blame] | 1864 | return 0; |
| 1865 | |
| 1866 | no_context: |
| 1867 | LOGP(DGPRS, LOGL_ERROR, "No GGSN context found!\n"); |
| 1868 | return gsm48_tx_gsm_act_pdp_rej(mmctx, transaction_id, |
| 1869 | gsm_cause, 0, NULL); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1870 | } |
| 1871 | |
Holger Hans Peter Freyther | ccd2312 | 2015-05-24 16:48:22 +0800 | [diff] [blame] | 1872 | /* Section 9.5.1: Activate PDP Context Request */ |
| 1873 | static int gsm48_rx_gsm_act_pdp_req(struct sgsn_mm_ctx *mmctx, |
| 1874 | struct msgb *_msg) |
| 1875 | { |
| 1876 | struct msgb *msg; |
| 1877 | int rc; |
| 1878 | |
| 1879 | /* |
| 1880 | * This is painful. We might not have a static GGSN |
| 1881 | * configuration and then would need to copy the msg |
| 1882 | * and re-do most of this routine (or call it again |
| 1883 | * and make sure it only goes through the dynamic |
| 1884 | * resolving. The question is what to optimize for |
| 1885 | * and the dynamic resolution will be the right thing |
| 1886 | * in the long run. |
| 1887 | */ |
| 1888 | msg = gprs_msgb_copy(_msg, __func__); |
| 1889 | if (!msg) { |
| 1890 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_gmmh(_msg); |
| 1891 | uint8_t transaction_id = (gh->proto_discr >> 4); |
| 1892 | |
| 1893 | LOGMMCTXP(LOGL_ERROR, mmctx, "-> ACTIVATE PDP CONTEXT REQ failed copy.\n"); |
| 1894 | /* Send reject with GSM_CAUSE_INV_MAND_INFO */ |
| 1895 | return gsm48_tx_gsm_act_pdp_rej(mmctx, transaction_id, |
| 1896 | GSM_CAUSE_NET_FAIL, |
| 1897 | 0, NULL); |
| 1898 | } |
| 1899 | |
| 1900 | rc = do_act_pdp_req(mmctx, _msg); |
| 1901 | msgb_free(msg); |
| 1902 | return rc; |
| 1903 | } |
| 1904 | |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1905 | /* Section 9.5.8: Deactivate PDP Context Request */ |
Harald Welte | 77289c2 | 2010-05-18 14:32:29 +0200 | [diff] [blame] | 1906 | static int gsm48_rx_gsm_deact_pdp_req(struct sgsn_mm_ctx *mm, struct msgb *msg) |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1907 | { |
Harald Welte | 943c5bc | 2010-04-30 16:33:12 +0200 | [diff] [blame] | 1908 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_gmmh(msg); |
Harald Welte | 77289c2 | 2010-05-18 14:32:29 +0200 | [diff] [blame] | 1909 | uint8_t transaction_id = (gh->proto_discr >> 4); |
| 1910 | struct sgsn_pdp_ctx *pdp; |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1911 | |
Daniel Willmann | 4655314 | 2014-09-03 17:46:44 +0200 | [diff] [blame] | 1912 | LOGMMCTXP(LOGL_INFO, mm, "-> DEACTIVATE PDP CONTEXT REQ (cause: %s)\n", |
Jacob Erlbeck | afcf230 | 2015-01-05 17:30:02 +0100 | [diff] [blame] | 1913 | get_value_string(gsm48_gsm_cause_names, gh->data[0])); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1914 | |
Harald Welte | 77289c2 | 2010-05-18 14:32:29 +0200 | [diff] [blame] | 1915 | pdp = sgsn_pdp_ctx_by_tid(mm, transaction_id); |
| 1916 | if (!pdp) { |
Daniel Willmann | 4655314 | 2014-09-03 17:46:44 +0200 | [diff] [blame] | 1917 | LOGMMCTXP(LOGL_NOTICE, mm, "Deactivate PDP Context Request for " |
Harald Welte | 77289c2 | 2010-05-18 14:32:29 +0200 | [diff] [blame] | 1918 | "non-existing PDP Context (IMSI=%s, TI=%u)\n", |
| 1919 | mm->imsi, transaction_id); |
Harald Welte | 60ebc02 | 2010-06-08 18:08:59 +0200 | [diff] [blame] | 1920 | return _gsm48_tx_gsm_deact_pdp_acc(mm, transaction_id); |
Harald Welte | 77289c2 | 2010-05-18 14:32:29 +0200 | [diff] [blame] | 1921 | } |
| 1922 | |
| 1923 | return sgsn_delete_pdp_ctx(pdp); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1924 | } |
| 1925 | |
Harald Welte | a9b473a | 2010-12-24 21:13:26 +0100 | [diff] [blame] | 1926 | /* Section 9.5.9: Deactivate PDP Context Accept */ |
| 1927 | static int gsm48_rx_gsm_deact_pdp_ack(struct sgsn_mm_ctx *mm, struct msgb *msg) |
| 1928 | { |
| 1929 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_gmmh(msg); |
| 1930 | uint8_t transaction_id = (gh->proto_discr >> 4); |
| 1931 | struct sgsn_pdp_ctx *pdp; |
| 1932 | |
Daniel Willmann | 4655314 | 2014-09-03 17:46:44 +0200 | [diff] [blame] | 1933 | LOGMMCTXP(LOGL_INFO, mm, "-> DEACTIVATE PDP CONTEXT ACK\n"); |
Harald Welte | a9b473a | 2010-12-24 21:13:26 +0100 | [diff] [blame] | 1934 | |
| 1935 | pdp = sgsn_pdp_ctx_by_tid(mm, transaction_id); |
| 1936 | if (!pdp) { |
Daniel Willmann | 4655314 | 2014-09-03 17:46:44 +0200 | [diff] [blame] | 1937 | LOGMMCTXP(LOGL_NOTICE, mm, "Deactivate PDP Context Accept for " |
Harald Welte | a9b473a | 2010-12-24 21:13:26 +0100 | [diff] [blame] | 1938 | "non-existing PDP Context (IMSI=%s, TI=%u)\n", |
| 1939 | mm->imsi, transaction_id); |
| 1940 | return 0; |
| 1941 | } |
| 1942 | |
| 1943 | return sgsn_delete_pdp_ctx(pdp); |
| 1944 | } |
| 1945 | |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 1946 | static int gsm48_rx_gsm_status(struct sgsn_mm_ctx *ctx, struct msgb *msg) |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1947 | { |
| 1948 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 1949 | |
Daniel Willmann | 4655314 | 2014-09-03 17:46:44 +0200 | [diff] [blame] | 1950 | LOGMMCTXP(LOGL_INFO, ctx, "-> GPRS SM STATUS (cause: %s)\n", |
Jacob Erlbeck | afcf230 | 2015-01-05 17:30:02 +0100 | [diff] [blame] | 1951 | get_value_string(gsm48_gsm_cause_names, gh->data[0])); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1952 | |
| 1953 | return 0; |
| 1954 | } |
| 1955 | |
Harald Welte | a9b473a | 2010-12-24 21:13:26 +0100 | [diff] [blame] | 1956 | static void pdpctx_timer_cb(void *_pdp) |
| 1957 | { |
| 1958 | struct sgsn_pdp_ctx *pdp = _pdp; |
| 1959 | |
| 1960 | pdp->num_T_exp++; |
| 1961 | |
| 1962 | switch (pdp->T) { |
| 1963 | case 3395: /* waiting for PDP CTX DEACT ACK */ |
| 1964 | if (pdp->num_T_exp >= 4) { |
Daniel Willmann | 4655314 | 2014-09-03 17:46:44 +0200 | [diff] [blame] | 1965 | LOGPDPCTXP(LOGL_NOTICE, pdp, "T3395 expired >= 5 times\n"); |
Harald Welte | a9b473a | 2010-12-24 21:13:26 +0100 | [diff] [blame] | 1966 | pdp->state = PDP_STATE_INACTIVE; |
| 1967 | sgsn_delete_pdp_ctx(pdp); |
| 1968 | break; |
| 1969 | } |
| 1970 | gsm48_tx_gsm_deact_pdp_req(pdp, GSM_CAUSE_NET_FAIL); |
Harald Welte | 9450882 | 2015-08-15 19:08:21 +0200 | [diff] [blame] | 1971 | osmo_timer_schedule(&pdp->timer, sgsn->cfg.timers.T3395, 0); |
Harald Welte | a9b473a | 2010-12-24 21:13:26 +0100 | [diff] [blame] | 1972 | break; |
| 1973 | default: |
Daniel Willmann | 4655314 | 2014-09-03 17:46:44 +0200 | [diff] [blame] | 1974 | LOGPDPCTXP(LOGL_ERROR, pdp, "timer expired in unknown mode %u\n", |
Harald Welte | a9b473a | 2010-12-24 21:13:26 +0100 | [diff] [blame] | 1975 | pdp->T); |
| 1976 | } |
| 1977 | } |
| 1978 | |
| 1979 | |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1980 | /* GPRS Session Management */ |
Harald Welte | 807a5d8 | 2010-06-01 11:53:01 +0200 | [diff] [blame] | 1981 | static int gsm0408_rcv_gsm(struct sgsn_mm_ctx *mmctx, struct msgb *msg, |
| 1982 | struct gprs_llc_llme *llme) |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1983 | { |
Harald Welte | 943c5bc | 2010-04-30 16:33:12 +0200 | [diff] [blame] | 1984 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_gmmh(msg); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1985 | int rc; |
| 1986 | |
Harald Welte | 807a5d8 | 2010-06-01 11:53:01 +0200 | [diff] [blame] | 1987 | /* MMCTX can be NULL when called */ |
| 1988 | |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 1989 | if (!mmctx) { |
| 1990 | LOGP(DMM, LOGL_NOTICE, "Cannot handle SM for unknown MM CTX\n"); |
Jacob Erlbeck | 78ecaf0 | 2014-09-05 14:32:36 +0200 | [diff] [blame] | 1991 | /* 6.1.3.6 */ |
| 1992 | if (gh->msg_type == GSM48_MT_GSM_STATUS) |
| 1993 | return 0; |
| 1994 | |
| 1995 | return sgsn_force_reattach_oldmsg(msg); |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 1996 | } |
| 1997 | |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1998 | switch (gh->msg_type) { |
| 1999 | case GSM48_MT_GSM_ACT_PDP_REQ: |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 2000 | rc = gsm48_rx_gsm_act_pdp_req(mmctx, msg); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 2001 | break; |
| 2002 | case GSM48_MT_GSM_DEACT_PDP_REQ: |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 2003 | rc = gsm48_rx_gsm_deact_pdp_req(mmctx, msg); |
Harald Welte | 77289c2 | 2010-05-18 14:32:29 +0200 | [diff] [blame] | 2004 | break; |
Harald Welte | a9b473a | 2010-12-24 21:13:26 +0100 | [diff] [blame] | 2005 | case GSM48_MT_GSM_DEACT_PDP_ACK: |
| 2006 | rc = gsm48_rx_gsm_deact_pdp_ack(mmctx, msg); |
| 2007 | break; |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 2008 | case GSM48_MT_GSM_STATUS: |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 2009 | rc = gsm48_rx_gsm_status(mmctx, msg); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 2010 | break; |
| 2011 | case GSM48_MT_GSM_REQ_PDP_ACT_REJ: |
| 2012 | case GSM48_MT_GSM_ACT_AA_PDP_REQ: |
| 2013 | case GSM48_MT_GSM_DEACT_AA_PDP_REQ: |
Harald Welte | 6a19dd0 | 2015-08-16 12:18:13 +0200 | [diff] [blame] | 2014 | LOGMMCTXP(LOGL_NOTICE, mmctx, "Unimplemented GSM 04.08 GSM msg type 0x%02x: %s\n", |
| 2015 | gh->msg_type, osmo_hexdump((uint8_t *)gh, msgb_l3len(msg))); |
Harald Welte | f54e7e2 | 2010-06-09 10:51:23 +0200 | [diff] [blame] | 2016 | rc = gsm48_tx_sm_status(mmctx, GSM_CAUSE_MSGT_NOTEXIST_NOTIMPL); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 2017 | break; |
| 2018 | default: |
Harald Welte | 6a19dd0 | 2015-08-16 12:18:13 +0200 | [diff] [blame] | 2019 | LOGMMCTXP(LOGL_NOTICE, mmctx, "Unknown GSM 04.08 GSM msg type 0x%02x: %s\n", |
| 2020 | gh->msg_type, osmo_hexdump((uint8_t *)gh, msgb_l3len(msg))); |
Harald Welte | f54e7e2 | 2010-06-09 10:51:23 +0200 | [diff] [blame] | 2021 | rc = gsm48_tx_sm_status(mmctx, GSM_CAUSE_MSGT_NOTEXIST_NOTIMPL); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 2022 | break; |
| 2023 | |
| 2024 | } |
| 2025 | |
| 2026 | return rc; |
| 2027 | } |
| 2028 | |
Jacob Erlbeck | abdf02b | 2014-10-31 12:20:49 +0100 | [diff] [blame] | 2029 | int gsm0408_gprs_force_reattach_oldmsg(struct msgb *msg) |
Jacob Erlbeck | 78ecaf0 | 2014-09-05 14:32:36 +0200 | [diff] [blame] | 2030 | { |
Jacob Erlbeck | abdf02b | 2014-10-31 12:20:49 +0100 | [diff] [blame] | 2031 | int rc; |
Jacob Erlbeck | 78ecaf0 | 2014-09-05 14:32:36 +0200 | [diff] [blame] | 2032 | gprs_llgmm_reset_oldmsg(msg, GPRS_SAPI_GMM); |
| 2033 | |
Jacob Erlbeck | abdf02b | 2014-10-31 12:20:49 +0100 | [diff] [blame] | 2034 | rc = gsm48_tx_gmm_detach_req_oldmsg( |
| 2035 | msg, GPRS_DET_T_MT_REATT_REQ, GMM_CAUSE_IMPL_DETACHED); |
Jacob Erlbeck | 78ecaf0 | 2014-09-05 14:32:36 +0200 | [diff] [blame] | 2036 | |
Jacob Erlbeck | abdf02b | 2014-10-31 12:20:49 +0100 | [diff] [blame] | 2037 | return rc; |
| 2038 | } |
| 2039 | |
| 2040 | int gsm0408_gprs_force_reattach(struct sgsn_mm_ctx *mmctx) |
| 2041 | { |
| 2042 | int rc; |
| 2043 | gprs_llgmm_reset(mmctx->llme); |
Jacob Erlbeck | 78ecaf0 | 2014-09-05 14:32:36 +0200 | [diff] [blame] | 2044 | |
Jacob Erlbeck | b1c074f | 2014-10-31 12:27:11 +0100 | [diff] [blame] | 2045 | rc = gsm48_tx_gmm_detach_req( |
| 2046 | mmctx, GPRS_DET_T_MT_REATT_REQ, GMM_CAUSE_IMPL_DETACHED); |
Jacob Erlbeck | 78ecaf0 | 2014-09-05 14:32:36 +0200 | [diff] [blame] | 2047 | |
Jacob Erlbeck | b1c074f | 2014-10-31 12:27:11 +0100 | [diff] [blame] | 2048 | mm_ctx_cleanup_free(mmctx, "forced reattach"); |
Jacob Erlbeck | 78ecaf0 | 2014-09-05 14:32:36 +0200 | [diff] [blame] | 2049 | |
Jacob Erlbeck | b1c074f | 2014-10-31 12:27:11 +0100 | [diff] [blame] | 2050 | return rc; |
Jacob Erlbeck | 78ecaf0 | 2014-09-05 14:32:36 +0200 | [diff] [blame] | 2051 | } |
| 2052 | |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 2053 | /* Main entry point for incoming 04.08 GPRS messages */ |
Harald Welte | 807a5d8 | 2010-06-01 11:53:01 +0200 | [diff] [blame] | 2054 | int gsm0408_gprs_rcvmsg(struct msgb *msg, struct gprs_llc_llme *llme) |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 2055 | { |
Harald Welte | 943c5bc | 2010-04-30 16:33:12 +0200 | [diff] [blame] | 2056 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_gmmh(msg); |
Harald Welte | eaa614c | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 2057 | uint8_t pdisc = gh->proto_discr & 0x0f; |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 2058 | struct sgsn_mm_ctx *mmctx; |
| 2059 | struct gprs_ra_id ra_id; |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 2060 | int rc = -EINVAL; |
| 2061 | |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 2062 | bssgp_parse_cell_id(&ra_id, msgb_bcid(msg)); |
| 2063 | mmctx = sgsn_mm_ctx_by_tlli(msgb_tlli(msg), &ra_id); |
Harald Welte | 8acd88f | 2010-05-18 10:57:45 +0200 | [diff] [blame] | 2064 | if (mmctx) { |
Harald Welte | 6abf94e | 2010-05-18 10:35:06 +0200 | [diff] [blame] | 2065 | msgid2mmctx(mmctx, msg); |
Harald Welte | 8acd88f | 2010-05-18 10:57:45 +0200 | [diff] [blame] | 2066 | rate_ctr_inc(&mmctx->ctrg->ctr[GMM_CTR_PKTS_SIG_IN]); |
Harald Welte | 807a5d8 | 2010-06-01 11:53:01 +0200 | [diff] [blame] | 2067 | mmctx->llme = llme; |
Harald Welte | 8acd88f | 2010-05-18 10:57:45 +0200 | [diff] [blame] | 2068 | } |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 2069 | |
| 2070 | /* MMCTX can be NULL */ |
| 2071 | |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 2072 | switch (pdisc) { |
| 2073 | case GSM48_PDISC_MM_GPRS: |
Harald Welte | 807a5d8 | 2010-06-01 11:53:01 +0200 | [diff] [blame] | 2074 | rc = gsm0408_rcv_gmm(mmctx, msg, llme); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 2075 | break; |
| 2076 | case GSM48_PDISC_SM_GPRS: |
Harald Welte | 807a5d8 | 2010-06-01 11:53:01 +0200 | [diff] [blame] | 2077 | rc = gsm0408_rcv_gsm(mmctx, msg, llme); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 2078 | break; |
| 2079 | default: |
Harald Welte | 6a19dd0 | 2015-08-16 12:18:13 +0200 | [diff] [blame] | 2080 | LOGP(DMM, LOGL_NOTICE, "Unknown GSM 04.08 discriminator 0x%02x: %s\n", |
| 2081 | pdisc, osmo_hexdump((uint8_t *)gh, msgb_l3len(msg))); |
Harald Welte | 6abf94e | 2010-05-18 10:35:06 +0200 | [diff] [blame] | 2082 | /* FIXME: return status message */ |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 2083 | break; |
| 2084 | } |
| 2085 | |
Jacob Erlbeck | 258ce3d | 2014-09-30 13:51:45 +0200 | [diff] [blame] | 2086 | /* MMCTX can be invalid */ |
| 2087 | |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 2088 | return rc; |
| 2089 | } |
Harald Welte | 5bfe499 | 2010-06-09 11:22:47 +0200 | [diff] [blame] | 2090 | |
| 2091 | int gprs_gmm_rx_suspend(struct gprs_ra_id *raid, uint32_t tlli) |
| 2092 | { |
| 2093 | struct sgsn_mm_ctx *mmctx; |
| 2094 | |
| 2095 | mmctx = sgsn_mm_ctx_by_tlli(tlli, raid); |
| 2096 | if (!mmctx) { |
| 2097 | LOGP(DMM, LOGL_NOTICE, "SUSPEND request for unknown " |
| 2098 | "TLLI=%08x\n", tlli); |
| 2099 | return -EINVAL; |
| 2100 | } |
| 2101 | |
Jacob Erlbeck | 7dba11f | 2014-12-22 17:58:18 +0100 | [diff] [blame] | 2102 | if (mmctx->mm_state != GMM_REGISTERED_NORMAL && |
| 2103 | mmctx->mm_state != GMM_REGISTERED_SUSPENDED) { |
Daniel Willmann | 4655314 | 2014-09-03 17:46:44 +0200 | [diff] [blame] | 2104 | LOGMMCTXP(LOGL_NOTICE, mmctx, "SUSPEND request while state " |
Harald Welte | 5bfe499 | 2010-06-09 11:22:47 +0200 | [diff] [blame] | 2105 | "!= REGISTERED (TLLI=%08x)\n", tlli); |
| 2106 | return -EINVAL; |
| 2107 | } |
| 2108 | |
| 2109 | /* Transition from REGISTERED_NORMAL to REGISTERED_SUSPENDED */ |
| 2110 | mmctx->mm_state = GMM_REGISTERED_SUSPENDED; |
| 2111 | return 0; |
| 2112 | } |
| 2113 | |
| 2114 | int gprs_gmm_rx_resume(struct gprs_ra_id *raid, uint32_t tlli, |
| 2115 | uint8_t suspend_ref) |
| 2116 | { |
| 2117 | struct sgsn_mm_ctx *mmctx; |
| 2118 | |
| 2119 | /* FIXME: make use of suspend reference? */ |
| 2120 | |
| 2121 | mmctx = sgsn_mm_ctx_by_tlli(tlli, raid); |
| 2122 | if (!mmctx) { |
| 2123 | LOGP(DMM, LOGL_NOTICE, "RESUME request for unknown " |
| 2124 | "TLLI=%08x\n", tlli); |
| 2125 | return -EINVAL; |
| 2126 | } |
| 2127 | |
Jacob Erlbeck | 7dba11f | 2014-12-22 17:58:18 +0100 | [diff] [blame] | 2128 | if (mmctx->mm_state != GMM_REGISTERED_NORMAL && |
| 2129 | mmctx->mm_state != GMM_REGISTERED_SUSPENDED) { |
Daniel Willmann | 4655314 | 2014-09-03 17:46:44 +0200 | [diff] [blame] | 2130 | LOGMMCTXP(LOGL_NOTICE, mmctx, "RESUME request while state " |
Harald Welte | 5bfe499 | 2010-06-09 11:22:47 +0200 | [diff] [blame] | 2131 | "!= SUSPENDED (TLLI=%08x)\n", tlli); |
| 2132 | /* FIXME: should we not simply ignore it? */ |
| 2133 | return -EINVAL; |
| 2134 | } |
| 2135 | |
| 2136 | /* Transition from SUSPENDED to NORMAL */ |
| 2137 | mmctx->mm_state = GMM_REGISTERED_NORMAL; |
| 2138 | return 0; |
| 2139 | } |