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