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 | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 5 | * |
| 6 | * All Rights Reserved |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License along |
| 19 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 20 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 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> |
| 34 | #include <osmocore/msgb.h> |
| 35 | #include <osmocore/tlv.h> |
Harald Welte | d605709 | 2010-05-02 12:57:45 +0200 | [diff] [blame] | 36 | #include <osmocore/gsm_utils.h> |
| 37 | #include <osmocore/signal.h> |
| 38 | #include <osmocore/talloc.h> |
Harald Welte | 8acd88f | 2010-05-18 10:57:45 +0200 | [diff] [blame] | 39 | #include <osmocore/rate_ctr.h> |
Harald Welte | d605709 | 2010-05-02 12:57:45 +0200 | [diff] [blame] | 40 | |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 41 | #include <openbsc/debug.h> |
| 42 | #include <openbsc/gsm_data.h> |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 43 | #include <openbsc/gsm_subscriber.h> |
| 44 | #include <openbsc/gsm_04_08.h> |
| 45 | #include <openbsc/gsm_04_08_gprs.h> |
| 46 | #include <openbsc/paging.h> |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 47 | #include <openbsc/transaction.h> |
Harald Welte | 11d7c10 | 2010-05-02 11:54:55 +0200 | [diff] [blame] | 48 | #include <openbsc/gprs_bssgp.h> |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 49 | #include <openbsc/gprs_llc.h> |
| 50 | #include <openbsc/gprs_sgsn.h> |
Harald Welte | 6abf94e | 2010-05-18 10:35:06 +0200 | [diff] [blame] | 51 | #include <openbsc/gprs_gmm.h> |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 52 | #include <openbsc/sgsn.h> |
| 53 | |
Harald Welte | 6abf94e | 2010-05-18 10:35:06 +0200 | [diff] [blame] | 54 | #include <pdp.h> |
| 55 | |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 56 | extern struct sgsn_instance *sgsn; |
Harald Welte | 77289c2 | 2010-05-18 14:32:29 +0200 | [diff] [blame] | 57 | extern struct ggsn_ctx *dummy_ggsn; |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 58 | |
Harald Welte | 2720e73 | 2010-05-17 00:44:57 +0200 | [diff] [blame] | 59 | /* Protocol related stuff, should go into libosmocore */ |
| 60 | |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 61 | /* 10.5.5.14 GPRS MM Cause / Table 10.5.147 */ |
Harald Welte | 2720e73 | 2010-05-17 00:44:57 +0200 | [diff] [blame] | 62 | const struct value_string gmm_cause_names[] = { |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 63 | /* FIXME */ |
| 64 | { GMM_CAUSE_SEM_INCORR_MSG, "Semantically incorrect message" }, |
| 65 | { GMM_CAUSE_INV_MAND_INFO, "Invalid mandatory information" }, |
| 66 | { GMM_CAUSE_MSGT_NOTEXIST_NOTIMPL, |
| 67 | "Message type non-existant or not implemented" }, |
| 68 | { GMM_CAUSE_MSGT_INCOMP_P_STATE, |
| 69 | "Message type not compatible with protocol state" }, |
| 70 | { GMM_CAUSE_IE_NOTEXIST_NOTIMPL, |
| 71 | "Information element non-existent or not implemented" }, |
| 72 | { GMM_CAUSE_COND_IE_ERR, "Conditional IE error" }, |
| 73 | { GMM_CAUSE_MSG_INCOMP_P_STATE, |
| 74 | "Message not compatible with protocol state " }, |
| 75 | { GMM_CAUSE_PROTO_ERR_UNSPEC, "Protocol error, unspecified" }, |
| 76 | { 0, NULL } |
| 77 | }; |
| 78 | |
| 79 | /* 10.5.6.6 SM Cause / Table 10.5.157 */ |
Harald Welte | 2720e73 | 2010-05-17 00:44:57 +0200 | [diff] [blame] | 80 | const struct value_string gsm_cause_names[] = { |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 81 | { GSM_CAUSE_INSUFF_RSRC, "Insufficient resources" }, |
| 82 | { GSM_CAUSE_MISSING_APN, "Missing or unknown APN" }, |
| 83 | { GSM_CAUSE_UNKNOWN_PDP, "Unknown PDP address or PDP type" }, |
| 84 | { GSM_CAUSE_AUTH_FAILED, "User Authentication failed" }, |
| 85 | { GSM_CAUSE_ACT_REJ_GGSN, "Activation rejected by GGSN" }, |
| 86 | { GSM_CAUSE_ACT_REJ_UNSPEC, "Activation rejected, unspecified" }, |
| 87 | { GSM_CAUSE_SERV_OPT_NOTSUPP, "Service option not supported" }, |
| 88 | { GSM_CAUSE_REQ_SERV_OPT_NOTSUB, |
| 89 | "Requested service option not subscribed" }, |
| 90 | { GSM_CAUSE_SERV_OPT_TEMP_OOO, |
| 91 | "Service option temporarily out of order" }, |
| 92 | { GSM_CAUSE_NSAPI_IN_USE, "NSAPI already used" }, |
| 93 | { GSM_CAUSE_DEACT_REGULAR, "Regular deactivation" }, |
| 94 | { GSM_CAUSE_QOS_NOT_ACCEPTED, "QoS not accepted" }, |
| 95 | { GSM_CAUSE_NET_FAIL, "Network Failure" }, |
| 96 | { GSM_CAUSE_REACT_RQD, "Reactivation required" }, |
| 97 | { GSM_CAUSE_FEATURE_NOTSUPP, "Feature not supported " }, |
| 98 | { GSM_CAUSE_INVALID_TRANS_ID, "Invalid transaction identifier" }, |
| 99 | { GSM_CAUSE_SEM_INCORR_MSG, "Semantically incorrect message" }, |
| 100 | { GSM_CAUSE_INV_MAND_INFO, "Invalid mandatory information" }, |
| 101 | { GSM_CAUSE_MSGT_NOTEXIST_NOTIMPL, |
| 102 | "Message type non-existant or not implemented" }, |
| 103 | { GSM_CAUSE_MSGT_INCOMP_P_STATE, |
| 104 | "Message type not compatible with protocol state" }, |
| 105 | { GSM_CAUSE_IE_NOTEXIST_NOTIMPL, |
| 106 | "Information element non-existent or not implemented" }, |
| 107 | { GSM_CAUSE_COND_IE_ERR, "Conditional IE error" }, |
| 108 | { GSM_CAUSE_MSG_INCOMP_P_STATE, |
| 109 | "Message not compatible with protocol state " }, |
| 110 | { GSM_CAUSE_PROTO_ERR_UNSPEC, "Protocol error, unspecified" }, |
| 111 | { 0, NULL } |
| 112 | }; |
| 113 | |
Harald Welte | 2720e73 | 2010-05-17 00:44:57 +0200 | [diff] [blame] | 114 | /* 10.5.5.2 */ |
| 115 | const struct value_string gprs_att_t_strs[] = { |
| 116 | { GPRS_ATT_T_ATTACH, "GPRS attach" }, |
| 117 | { GPRS_ATT_T_ATT_WHILE_IMSI, "GPRS attach while IMSI attached" }, |
| 118 | { GPRS_ATT_T_COMBINED, "Combined GPRS/IMSI attach" }, |
| 119 | { 0, NULL } |
| 120 | }; |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 121 | |
Harald Welte | 2720e73 | 2010-05-17 00:44:57 +0200 | [diff] [blame] | 122 | const struct value_string gprs_upd_t_strs[] = { |
| 123 | { GPRS_UPD_T_RA, "RA updating" }, |
| 124 | { GPRS_UPD_T_RA_LA, "combined RA/LA updating" }, |
| 125 | { GPRS_UPD_T_RA_LA_IMSI_ATT, "combined RA/LA updating + IMSI attach" }, |
| 126 | { GPRS_UPD_T_PERIODIC, "periodic updating" }, |
| 127 | { 0, NULL } |
| 128 | }; |
| 129 | |
| 130 | /* 10.5.5.5 */ |
| 131 | const struct value_string gprs_det_t_mo_strs[] = { |
| 132 | { GPRS_DET_T_MO_GPRS, "GPRS detach" }, |
| 133 | { GPRS_DET_T_MO_IMSI, "IMSI detach" }, |
| 134 | { GPRS_DET_T_MO_COMBINED, "Combined GPRS/IMSI detach" }, |
| 135 | { 0, NULL } |
| 136 | }; |
| 137 | |
| 138 | /* Our implementation, should be kept in SGSN */ |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 139 | |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 140 | /* Send a message through the underlying layer */ |
Harald Welte | 8acd88f | 2010-05-18 10:57:45 +0200 | [diff] [blame] | 141 | static int gsm48_gmm_sendmsg(struct msgb *msg, int command, |
| 142 | const struct sgsn_mm_ctx *mm) |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 143 | { |
Harald Welte | 8acd88f | 2010-05-18 10:57:45 +0200 | [diff] [blame] | 144 | if (mm) |
| 145 | rate_ctr_inc(&mm->ctrg->ctr[GMM_CTR_PKTS_SIG_OUT]); |
| 146 | |
Harald Welte | 11d7c10 | 2010-05-02 11:54:55 +0200 | [diff] [blame] | 147 | /* caller needs to provide TLLI, BVCI and NSEI */ |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 148 | return gprs_llc_tx_ui(msg, GPRS_SAPI_GMM, command); |
| 149 | } |
| 150 | |
Harald Welte | 11d7c10 | 2010-05-02 11:54:55 +0200 | [diff] [blame] | 151 | /* copy identifiers from old message to new message, this |
| 152 | * is required so lower layers can route it correctly */ |
| 153 | static void gmm_copy_id(struct msgb *msg, const struct msgb *old) |
| 154 | { |
| 155 | msgb_tlli(msg) = msgb_tlli(old); |
| 156 | msgb_bvci(msg) = msgb_bvci(old); |
| 157 | msgb_nsei(msg) = msgb_nsei(old); |
| 158 | } |
| 159 | |
Harald Welte | 6abf94e | 2010-05-18 10:35:06 +0200 | [diff] [blame] | 160 | /* Store BVCI/NSEI in MM context */ |
| 161 | static void msgid2mmctx(struct sgsn_mm_ctx *mm, const struct msgb *msg) |
| 162 | { |
| 163 | mm->bvci = msgb_bvci(msg); |
| 164 | mm->nsei = msgb_nsei(msg); |
| 165 | } |
| 166 | |
| 167 | /* Store BVCI/NSEI in MM context */ |
| 168 | static void mmctx2msgid(struct msgb *msg, const struct sgsn_mm_ctx *mm) |
| 169 | { |
| 170 | msgb_tlli(msg) = mm->tlli; |
| 171 | msgb_bvci(msg) = mm->bvci; |
| 172 | msgb_nsei(msg) = mm->nsei; |
| 173 | } |
| 174 | |
Harald Welte | 86fda90 | 2010-05-03 10:54:35 +0200 | [diff] [blame] | 175 | static struct gsm48_qos default_qos = { |
| 176 | .delay_class = 4, /* best effort */ |
| 177 | .reliab_class = GSM48_QOS_RC_LLC_UN_RLC_ACK_DATA_PROT, |
| 178 | .peak_tput = GSM48_QOS_PEAK_TPUT_32000bps, |
| 179 | .preced_class = GSM48_QOS_PC_NORMAL, |
| 180 | .mean_tput = GSM48_QOS_MEAN_TPUT_BEST_EFFORT, |
| 181 | .traf_class = GSM48_QOS_TC_INTERACTIVE, |
| 182 | .deliv_order = GSM48_QOS_DO_UNORDERED, |
| 183 | .deliv_err_sdu = GSM48_QOS_ERRSDU_YES, |
| 184 | .max_sdu_size = GSM48_QOS_MAXSDU_1520, |
| 185 | .max_bitrate_up = GSM48_QOS_MBRATE_63k, |
| 186 | .max_bitrate_down = GSM48_QOS_MBRATE_63k, |
| 187 | .resid_ber = GSM48_QOS_RBER_5e_2, |
| 188 | .sdu_err_ratio = GSM48_QOS_SERR_1e_2, |
| 189 | .handling_prio = 3, |
| 190 | .xfer_delay = 0x10, /* 200ms */ |
| 191 | .guar_bitrate_up = GSM48_QOS_MBRATE_0k, |
| 192 | .guar_bitrate_down = GSM48_QOS_MBRATE_0k, |
| 193 | .sig_ind = 0, /* not optimised for signalling */ |
| 194 | .max_bitrate_down_ext = 0, /* use octet 9 */ |
| 195 | .guar_bitrate_down_ext = 0, /* use octet 13 */ |
| 196 | }; |
| 197 | |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 198 | /* Chapter 9.4.2: Attach accept */ |
| 199 | static int gsm48_tx_gmm_att_ack(struct msgb *old_msg) |
| 200 | { |
| 201 | struct msgb *msg = gsm48_msgb_alloc(); |
| 202 | struct gsm48_hdr *gh; |
| 203 | struct gsm48_attach_ack *aa; |
Harald Welte | 11d7c10 | 2010-05-02 11:54:55 +0200 | [diff] [blame] | 204 | struct gprs_ra_id ra_id; |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 205 | |
| 206 | DEBUGP(DMM, "<- GPRS ATTACH ACCEPT\n"); |
| 207 | |
Harald Welte | 11d7c10 | 2010-05-02 11:54:55 +0200 | [diff] [blame] | 208 | gmm_copy_id(msg, old_msg); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 209 | |
| 210 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 211 | gh->proto_discr = GSM48_PDISC_MM_GPRS; |
| 212 | gh->msg_type = GSM48_MT_GMM_ATTACH_ACK; |
| 213 | |
| 214 | aa = (struct gsm48_attach_ack *) msgb_put(msg, sizeof(*aa)); |
| 215 | aa->force_stby = 0; /* not indicated */ |
| 216 | aa->att_result = 1; /* GPRS only */ |
| 217 | aa->ra_upd_timer = GPRS_TMR_MINUTE | 10; |
| 218 | aa->radio_prio = 4; /* lowest */ |
Harald Welte | ba02110 | 2010-05-02 21:36:36 +0200 | [diff] [blame] | 219 | bssgp_parse_cell_id(&ra_id, msgb_bcid(old_msg)); |
Harald Welte | 11d7c10 | 2010-05-02 11:54:55 +0200 | [diff] [blame] | 220 | gsm48_construct_ra(aa->ra_id.digits, &ra_id); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 221 | |
| 222 | /* Option: P-TMSI signature, allocated P-TMSI, MS ID, ... */ |
Harald Welte | 8acd88f | 2010-05-18 10:57:45 +0200 | [diff] [blame] | 223 | return gsm48_gmm_sendmsg(msg, 0, NULL); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | /* Chapter 9.4.5: Attach reject */ |
Harald Welte | eaa614c | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 227 | static int gsm48_tx_gmm_att_rej(struct msgb *old_msg, uint8_t gmm_cause) |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 228 | { |
| 229 | struct msgb *msg = gsm48_msgb_alloc(); |
| 230 | struct gsm48_hdr *gh; |
| 231 | |
| 232 | DEBUGP(DMM, "<- GPRS ATTACH REJECT\n"); |
| 233 | |
Harald Welte | 11d7c10 | 2010-05-02 11:54:55 +0200 | [diff] [blame] | 234 | gmm_copy_id(msg, old_msg); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 235 | |
| 236 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 1); |
| 237 | gh->proto_discr = GSM48_PDISC_MM_GPRS; |
| 238 | gh->msg_type = GSM48_MT_GMM_ATTACH_REJ; |
| 239 | gh->data[0] = gmm_cause; |
| 240 | |
Harald Welte | 8acd88f | 2010-05-18 10:57:45 +0200 | [diff] [blame] | 241 | return gsm48_gmm_sendmsg(msg, 0, NULL); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 242 | } |
| 243 | |
Harald Welte | 2720e73 | 2010-05-17 00:44:57 +0200 | [diff] [blame] | 244 | /* Chapter 9.4.6.2 Detach accept */ |
| 245 | static gsm48_tx_gmm_det_ack(struct msgb *old_msg, uint8_t force_stby) |
| 246 | { |
| 247 | struct msgb *msg = gsm48_msgb_alloc(); |
| 248 | struct gsm48_hdr *gh; |
| 249 | |
| 250 | DEBUGP(DMM, "<- GPRS DETACH ACCEPT\n"); |
| 251 | |
| 252 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 1); |
| 253 | gh->proto_discr = GSM48_PDISC_MM_GPRS; |
| 254 | gh->msg_type = GSM48_MT_GMM_DETACH_ACK; |
| 255 | gh->data[0] = force_stby; |
| 256 | |
Harald Welte | 8acd88f | 2010-05-18 10:57:45 +0200 | [diff] [blame] | 257 | return gsm48_gmm_sendmsg(msg, 0, NULL); |
Harald Welte | 2720e73 | 2010-05-17 00:44:57 +0200 | [diff] [blame] | 258 | } |
| 259 | |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 260 | /* Transmit Chapter 9.4.12 Identity Request */ |
Harald Welte | eaa614c | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 261 | static int gsm48_tx_gmm_id_req(struct msgb *old_msg, uint8_t id_type) |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 262 | { |
| 263 | struct msgb *msg = gsm48_msgb_alloc(); |
| 264 | struct gsm48_hdr *gh; |
| 265 | |
| 266 | DEBUGP(DMM, "-> GPRS IDENTITY REQUEST: mi_type=%02x\n", id_type); |
| 267 | |
Harald Welte | 11d7c10 | 2010-05-02 11:54:55 +0200 | [diff] [blame] | 268 | gmm_copy_id(msg, old_msg); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 269 | |
| 270 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 1); |
| 271 | gh->proto_discr = GSM48_PDISC_MM_GPRS; |
| 272 | gh->msg_type = GSM48_MT_GMM_ID_REQ; |
| 273 | /* 10.5.5.9 ID type 2 + identity type and 10.5.5.7 'force to standby' IE */ |
| 274 | gh->data[0] = id_type & 0xf; |
| 275 | |
Harald Welte | 8acd88f | 2010-05-18 10:57:45 +0200 | [diff] [blame] | 276 | return gsm48_gmm_sendmsg(msg, 0, NULL); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 277 | } |
| 278 | |
| 279 | /* Check if we can already authorize a subscriber */ |
| 280 | static int gsm48_gmm_authorize(struct sgsn_mm_ctx *ctx, struct msgb *msg) |
| 281 | { |
| 282 | if (strlen(ctx->imei) && strlen(ctx->imsi)) { |
| 283 | ctx->mm_state = GMM_REGISTERED_NORMAL; |
| 284 | return gsm48_tx_gmm_att_ack(msg); |
| 285 | } |
| 286 | if (!strlen(ctx->imei)) |
| 287 | return gsm48_tx_gmm_id_req(msg, GSM_MI_TYPE_IMEI); |
| 288 | |
| 289 | if (!strlen(ctx->imsi)) |
| 290 | return gsm48_tx_gmm_id_req(msg, GSM_MI_TYPE_IMSI); |
| 291 | |
| 292 | return 0; |
| 293 | } |
| 294 | |
| 295 | /* Parse Chapter 9.4.13 Identity Response */ |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 296 | 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] | 297 | { |
Harald Welte | 943c5bc | 2010-04-30 16:33:12 +0200 | [diff] [blame] | 298 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_gmmh(msg); |
Harald Welte | eaa614c | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 299 | uint8_t mi_type = gh->data[1] & GSM_MI_TYPE_MASK; |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 300 | char mi_string[GSM48_MI_SIZE]; |
| 301 | struct gprs_ra_id ra_id; |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 302 | |
| 303 | gsm48_mi_to_string(mi_string, sizeof(mi_string), &gh->data[1], gh->data[0]); |
Harald Welte | 2720e73 | 2010-05-17 00:44:57 +0200 | [diff] [blame] | 304 | DEBUGP(DMM, "-> GMM IDENTITY RESPONSE: mi_type=0x%02x MI(%s) ", |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 305 | mi_type, mi_string); |
| 306 | |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 307 | if (!ctx) { |
Harald Welte | 943c5bc | 2010-04-30 16:33:12 +0200 | [diff] [blame] | 308 | DEBUGP(DMM, "from unknown TLLI 0x%08x?!?\n", msgb_tlli(msg)); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 309 | return -EINVAL; |
| 310 | } |
| 311 | |
| 312 | switch (mi_type) { |
| 313 | case GSM_MI_TYPE_IMSI: |
| 314 | /* we already have a mm context with current TLLI, but no |
| 315 | * P-TMSI / IMSI yet. What we now need to do is to fill |
| 316 | * this initial context with data from the HLR */ |
| 317 | strncpy(ctx->imsi, mi_string, sizeof(ctx->imei)); |
| 318 | break; |
| 319 | case GSM_MI_TYPE_IMEI: |
| 320 | strncpy(ctx->imei, mi_string, sizeof(ctx->imei)); |
| 321 | break; |
| 322 | case GSM_MI_TYPE_IMEISV: |
| 323 | break; |
| 324 | } |
| 325 | |
| 326 | DEBUGPC(DMM, "\n"); |
| 327 | /* Check if we can let the mobile station enter */ |
| 328 | return gsm48_gmm_authorize(ctx, msg); |
| 329 | } |
| 330 | |
| 331 | static void attach_rej_cb(void *data) |
| 332 | { |
| 333 | struct sgsn_mm_ctx *ctx = data; |
| 334 | |
| 335 | /* FIXME: determine through which BTS/TRX to send this */ |
| 336 | //gsm48_tx_gmm_att_rej(ctx->tlli, GMM_CAUSE_MS_ID_NOT_DERIVED); |
| 337 | ctx->mm_state = GMM_DEREGISTERED; |
| 338 | /* FIXME: release the context */ |
| 339 | } |
| 340 | |
| 341 | static void schedule_reject(struct sgsn_mm_ctx *ctx) |
| 342 | { |
| 343 | ctx->T = 3370; |
| 344 | ctx->timer.cb = attach_rej_cb; |
| 345 | ctx->timer.data = ctx; |
| 346 | bsc_schedule_timer(&ctx->timer, 6, 0); |
| 347 | } |
| 348 | |
| 349 | /* Section 9.4.1 Attach request */ |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 350 | static int gsm48_rx_gmm_att_req(struct sgsn_mm_ctx *mmctx, struct msgb *msg) |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 351 | { |
Harald Welte | 943c5bc | 2010-04-30 16:33:12 +0200 | [diff] [blame] | 352 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_gmmh(msg); |
Harald Welte | eaa614c | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 353 | uint8_t *cur = gh->data, *msnc, *mi, *old_ra_info; |
| 354 | uint8_t msnc_len, att_type, mi_len, mi_type; |
| 355 | uint16_t drx_par; |
| 356 | uint32_t tmsi; |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 357 | char mi_string[GSM48_MI_SIZE]; |
| 358 | struct gprs_ra_id ra_id; |
Harald Welte | 9f1f3ad | 2010-05-02 12:56:57 +0200 | [diff] [blame] | 359 | uint16_t cid; |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 360 | struct sgsn_mm_ctx *ctx; |
| 361 | |
Harald Welte | 2720e73 | 2010-05-17 00:44:57 +0200 | [diff] [blame] | 362 | DEBUGP(DMM, "-> GMM ATTACH REQUEST "); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 363 | |
| 364 | /* As per TS 04.08 Chapter 4.7.1.4, the attach request arrives either |
| 365 | * with a foreign TLLI (P-TMSI that was allocated to the MS before), |
| 366 | * or with random TLLI. */ |
| 367 | |
Harald Welte | 9f1f3ad | 2010-05-02 12:56:57 +0200 | [diff] [blame] | 368 | cid = bssgp_parse_cell_id(&ra_id, msgb_bcid(msg)); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 369 | |
| 370 | /* MS network capability 10.5.5.12 */ |
| 371 | msnc_len = *cur++; |
| 372 | msnc = cur; |
| 373 | if (msnc_len > 2) |
| 374 | goto err_inval; |
| 375 | cur += msnc_len; |
| 376 | |
| 377 | /* aTTACH Type 10.5.5.2 */ |
| 378 | att_type = *cur++ & 0x0f; |
| 379 | |
| 380 | /* DRX parameter 10.5.5.6 */ |
| 381 | drx_par = *cur++; |
| 382 | drx_par |= *cur++ << 8; |
| 383 | |
| 384 | /* Mobile Identity (P-TMSI or IMSI) 10.5.1.4 */ |
| 385 | mi_len = *cur++; |
| 386 | mi = cur; |
| 387 | if (mi_len > 8) |
| 388 | goto err_inval; |
| 389 | mi_type = *mi & GSM_MI_TYPE_MASK; |
| 390 | cur += mi_len; |
| 391 | |
| 392 | gsm48_mi_to_string(mi_string, sizeof(mi_string), mi, mi_len); |
| 393 | |
Harald Welte | 2720e73 | 2010-05-17 00:44:57 +0200 | [diff] [blame] | 394 | DEBUGPC(DMM, "MI(%s) type=\"%s\" ", mi_string, |
| 395 | get_value_string(gprs_att_t_strs, att_type)); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 396 | |
| 397 | /* Old routing area identification 10.5.5.15 */ |
| 398 | old_ra_info = cur; |
| 399 | cur += 6; |
| 400 | |
| 401 | /* MS Radio Access Capability 10.5.5.12a */ |
| 402 | |
| 403 | /* Optional: Old P-TMSI Signature, Requested READY timer, TMSI Status */ |
| 404 | |
| 405 | switch (mi_type) { |
| 406 | case GSM_MI_TYPE_IMSI: |
| 407 | /* Try to find MM context based on IMSI */ |
| 408 | ctx = sgsn_mm_ctx_by_imsi(mi_string); |
| 409 | if (!ctx) { |
| 410 | #if 0 |
| 411 | return gsm48_tx_gmm_att_rej(msg, GMM_CAUSE_IMSI_UNKNOWN); |
| 412 | #else |
| 413 | /* As a temorary hack, we simply assume that the IMSI exists */ |
| 414 | ctx = sgsn_mm_ctx_alloc(0, &ra_id); |
| 415 | if (!ctx) |
| 416 | return gsm48_tx_gmm_att_rej(msg, GMM_CAUSE_NET_FAIL); |
| 417 | strncpy(ctx->imsi, mi_string, sizeof(ctx->imsi)); |
| 418 | #endif |
| 419 | } |
| 420 | /* FIXME: Start some timer */ |
| 421 | ctx->mm_state = GMM_COMMON_PROC_INIT; |
Harald Welte | 943c5bc | 2010-04-30 16:33:12 +0200 | [diff] [blame] | 422 | ctx->tlli = msgb_tlli(msg); |
Harald Welte | 68b99a4 | 2010-05-18 12:05:42 +0200 | [diff] [blame] | 423 | msgid2mmctx(ctx, msg); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 424 | break; |
| 425 | case GSM_MI_TYPE_TMSI: |
| 426 | tmsi = strtoul(mi_string, NULL, 10); |
| 427 | /* Try to find MM context based on P-TMSI */ |
| 428 | ctx = sgsn_mm_ctx_by_ptmsi(tmsi); |
| 429 | if (!ctx) { |
Harald Welte | 943c5bc | 2010-04-30 16:33:12 +0200 | [diff] [blame] | 430 | ctx = sgsn_mm_ctx_alloc(msgb_tlli(msg), &ra_id); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 431 | /* FIXME: Start some timer */ |
| 432 | ctx->mm_state = GMM_COMMON_PROC_INIT; |
Harald Welte | 943c5bc | 2010-04-30 16:33:12 +0200 | [diff] [blame] | 433 | ctx->tlli = msgb_tlli(msg); |
Harald Welte | 68b99a4 | 2010-05-18 12:05:42 +0200 | [diff] [blame] | 434 | msgid2mmctx(ctx, msg); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 435 | } |
| 436 | break; |
| 437 | default: |
Harald Welte | 9f1f3ad | 2010-05-02 12:56:57 +0200 | [diff] [blame] | 438 | return 0; |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 439 | } |
Harald Welte | 9f1f3ad | 2010-05-02 12:56:57 +0200 | [diff] [blame] | 440 | /* Update MM Context with currient RA and Cell ID */ |
| 441 | ctx->ra = ra_id; |
| 442 | ctx->cell_id = cid; |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 443 | |
| 444 | /* FIXME: allocate a new P-TMSI (+ P-TMSI signature) */ |
| 445 | /* FIXME: update the TLLI with the new local TLLI based on the P-TMSI */ |
| 446 | |
| 447 | DEBUGPC(DMM, "\n"); |
| 448 | |
| 449 | return ctx ? gsm48_gmm_authorize(ctx, msg) : 0; |
| 450 | |
| 451 | err_inval: |
| 452 | DEBUGPC(DMM, "\n"); |
| 453 | return gsm48_tx_gmm_att_rej(msg, GMM_CAUSE_SEM_INCORR_MSG); |
| 454 | } |
| 455 | |
Harald Welte | 2720e73 | 2010-05-17 00:44:57 +0200 | [diff] [blame] | 456 | /* Section 4.7.4.1 / 9.4.5.2 MO Detach request */ |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 457 | 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] | 458 | { |
| 459 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_gmmh(msg); |
Harald Welte | 2720e73 | 2010-05-17 00:44:57 +0200 | [diff] [blame] | 460 | uint8_t detach_type, power_off; |
Harald Welte | 2720e73 | 2010-05-17 00:44:57 +0200 | [diff] [blame] | 461 | |
| 462 | detach_type = gh->data[0] & 0x7; |
| 463 | power_off = gh->data[0] & 0x8; |
| 464 | |
| 465 | /* FIXME: In 24.008 there is an optional P-TMSI and P-TMSI signature IE */ |
| 466 | |
| 467 | DEBUGP(DMM, "-> GMM DETACH REQUEST TLLI=0x%08x type=%s %s\n", |
| 468 | msgb_tlli(msg), get_value_string(gprs_det_t_mo_strs, detach_type), |
| 469 | power_off ? "Power-off" : ""); |
| 470 | |
| 471 | /* Mark MM state as deregistered */ |
| 472 | ctx->mm_state = GMM_DEREGISTERED; |
| 473 | |
| 474 | /* force_stby = 0 */ |
| 475 | return gsm48_tx_gmm_det_ack(msg, 0); |
| 476 | } |
| 477 | |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 478 | /* Chapter 9.4.15: Routing area update accept */ |
| 479 | static int gsm48_tx_gmm_ra_upd_ack(struct msgb *old_msg) |
| 480 | { |
| 481 | struct msgb *msg = gsm48_msgb_alloc(); |
| 482 | struct gsm48_hdr *gh; |
| 483 | struct gsm48_ra_upd_ack *rua; |
Harald Welte | 11d7c10 | 2010-05-02 11:54:55 +0200 | [diff] [blame] | 484 | struct gprs_ra_id ra_id; |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 485 | |
| 486 | DEBUGP(DMM, "<- ROUTING AREA UPDATE ACCEPT\n"); |
| 487 | |
Harald Welte | 11d7c10 | 2010-05-02 11:54:55 +0200 | [diff] [blame] | 488 | gmm_copy_id(msg, old_msg); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 489 | |
| 490 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 491 | gh->proto_discr = GSM48_PDISC_MM_GPRS; |
| 492 | gh->msg_type = GSM48_MT_GMM_RA_UPD_ACK; |
| 493 | |
| 494 | rua = (struct gsm48_ra_upd_ack *) msgb_put(msg, sizeof(*rua)); |
| 495 | rua->force_stby = 0; /* not indicated */ |
| 496 | rua->upd_result = 0; /* RA updated */ |
| 497 | rua->ra_upd_timer = GPRS_TMR_MINUTE | 10; |
Harald Welte | 11d7c10 | 2010-05-02 11:54:55 +0200 | [diff] [blame] | 498 | |
Harald Welte | ba02110 | 2010-05-02 21:36:36 +0200 | [diff] [blame] | 499 | bssgp_parse_cell_id(&ra_id, msgb_bcid(old_msg)); |
Harald Welte | 11d7c10 | 2010-05-02 11:54:55 +0200 | [diff] [blame] | 500 | gsm48_construct_ra(rua->ra_id.digits, &ra_id); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 501 | |
| 502 | /* Option: P-TMSI signature, allocated P-TMSI, MS ID, ... */ |
Harald Welte | 8acd88f | 2010-05-18 10:57:45 +0200 | [diff] [blame] | 503 | return gsm48_gmm_sendmsg(msg, 0, NULL); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 504 | } |
| 505 | |
| 506 | /* Chapter 9.4.17: Routing area update reject */ |
Harald Welte | eaa614c | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 507 | 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] | 508 | { |
| 509 | struct msgb *msg = gsm48_msgb_alloc(); |
| 510 | struct gsm48_hdr *gh; |
| 511 | |
| 512 | DEBUGP(DMM, "<- ROUTING AREA UPDATE REJECT\n"); |
| 513 | |
Harald Welte | 11d7c10 | 2010-05-02 11:54:55 +0200 | [diff] [blame] | 514 | gmm_copy_id(msg, old_msg); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 515 | |
| 516 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 2); |
| 517 | gh->proto_discr = GSM48_PDISC_MM_GPRS; |
| 518 | gh->msg_type = GSM48_MT_GMM_RA_UPD_REJ; |
| 519 | gh->data[0] = cause; |
| 520 | gh->data[1] = 0; /* ? */ |
| 521 | |
| 522 | /* Option: P-TMSI signature, allocated P-TMSI, MS ID, ... */ |
Harald Welte | 8acd88f | 2010-05-18 10:57:45 +0200 | [diff] [blame] | 523 | return gsm48_gmm_sendmsg(msg, 0, NULL); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 524 | } |
| 525 | |
| 526 | /* Chapter 9.4.14: Routing area update request */ |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 527 | static int gsm48_rx_gmm_ra_upd_req(struct sgsn_mm_ctx *mmctx, struct msgb *msg) |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 528 | { |
Harald Welte | 943c5bc | 2010-04-30 16:33:12 +0200 | [diff] [blame] | 529 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_gmmh(msg); |
Harald Welte | eaa614c | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 530 | uint8_t *cur = gh->data; |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 531 | struct gprs_ra_id old_ra_id; |
Harald Welte | eaa614c | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 532 | uint8_t upd_type; |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 533 | |
| 534 | /* Update Type 10.5.5.18 */ |
| 535 | upd_type = *cur++ & 0x0f; |
| 536 | |
Harald Welte | 2720e73 | 2010-05-17 00:44:57 +0200 | [diff] [blame] | 537 | DEBUGP(DMM, "-> GMM RA UPDATE REQUEST type=\"%s\" ", |
| 538 | get_value_string(gprs_upd_t_strs, upd_type)); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 539 | |
| 540 | /* Old routing area identification 10.5.5.15 */ |
| 541 | gsm48_parse_ra(&old_ra_id, cur); |
| 542 | cur += 6; |
| 543 | |
| 544 | /* MS Radio Access Capability 10.5.5.12a */ |
| 545 | |
| 546 | /* Optional: Old P-TMSI Signature, Requested READY timer, TMSI Status, |
| 547 | * DRX parameter, MS network capability */ |
| 548 | |
| 549 | switch (upd_type) { |
| 550 | case GPRS_UPD_T_RA_LA: |
| 551 | case GPRS_UPD_T_RA_LA_IMSI_ATT: |
| 552 | DEBUGPC(DMM, " unsupported in Mode III, is your SI13 corrupt?\n"); |
| 553 | return gsm48_tx_gmm_ra_upd_rej(msg, GMM_CAUSE_PROTO_ERR_UNSPEC); |
| 554 | break; |
| 555 | case GPRS_UPD_T_RA: |
| 556 | case GPRS_UPD_T_PERIODIC: |
| 557 | break; |
| 558 | } |
| 559 | |
| 560 | /* Look-up the MM context based on old RA-ID and TLLI */ |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 561 | if (!mmctx || mmctx->mm_state == GMM_DEREGISTERED) { |
| 562 | /* The MS has to perform GPRS attach */ |
| 563 | DEBUGPC(DMM, " REJECT\n"); |
| 564 | return gsm48_tx_gmm_ra_upd_rej(msg, GMM_CAUSE_IMPL_DETACHED); |
| 565 | } |
| 566 | |
Harald Welte | 9f1f3ad | 2010-05-02 12:56:57 +0200 | [diff] [blame] | 567 | /* Update the MM context with the new RA-ID */ |
| 568 | bssgp_parse_cell_id(&mmctx->ra, msgb_bcid(msg)); |
| 569 | /* Update the MM context with the new TLLI */ |
| 570 | mmctx->tlli = msgb_tlli(msg); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 571 | /* FIXME: Update the MM context with the MS radio acc capabilities */ |
| 572 | /* FIXME: Update the MM context with the MS network capabilities */ |
| 573 | |
Harald Welte | 77289c2 | 2010-05-18 14:32:29 +0200 | [diff] [blame] | 574 | rate_ctr_inc(&mmctx->ctrg->ctr[GMM_CTR_RA_UPDATE]); |
| 575 | |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 576 | DEBUGPC(DMM, " ACCEPT\n"); |
| 577 | return gsm48_tx_gmm_ra_upd_ack(msg); |
| 578 | } |
| 579 | |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 580 | 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] | 581 | { |
| 582 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 583 | |
Harald Welte | 2720e73 | 2010-05-17 00:44:57 +0200 | [diff] [blame] | 584 | DEBUGP(DMM, "-> GPRS MM STATUS (cause: %s)\n", |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 585 | get_value_string(gmm_cause_names, gh->data[0])); |
| 586 | |
| 587 | return 0; |
| 588 | } |
| 589 | |
| 590 | /* GPRS Mobility Management */ |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 591 | static int gsm0408_rcv_gmm(struct sgsn_mm_ctx *mmctx, struct msgb *msg) |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 592 | { |
Harald Welte | 943c5bc | 2010-04-30 16:33:12 +0200 | [diff] [blame] | 593 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_gmmh(msg); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 594 | int rc; |
| 595 | |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 596 | if (!mmctx && |
| 597 | gh->msg_type != GSM48_MT_GMM_ATTACH_REQ && |
| 598 | gh->msg_type != GSM48_MT_GMM_RA_UPD_REQ) { |
| 599 | LOGP(DMM, LOGL_NOTICE, "Cannot handle GMM for unknown MM CTX\n"); |
Harald Welte | 77289c2 | 2010-05-18 14:32:29 +0200 | [diff] [blame] | 600 | /* FIXME: Send GMM_CAUSE_IMPL_DETACHED */ |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 601 | return -EINVAL; |
| 602 | } |
| 603 | |
| 604 | |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 605 | switch (gh->msg_type) { |
| 606 | case GSM48_MT_GMM_RA_UPD_REQ: |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 607 | rc = gsm48_rx_gmm_ra_upd_req(mmctx, msg); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 608 | break; |
| 609 | case GSM48_MT_GMM_ATTACH_REQ: |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 610 | rc = gsm48_rx_gmm_att_req(mmctx, msg); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 611 | break; |
| 612 | case GSM48_MT_GMM_ID_RESP: |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 613 | rc = gsm48_rx_gmm_id_resp(mmctx, msg); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 614 | break; |
| 615 | case GSM48_MT_GMM_STATUS: |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 616 | rc = gsm48_rx_gmm_status(mmctx, msg); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 617 | break; |
Harald Welte | 2720e73 | 2010-05-17 00:44:57 +0200 | [diff] [blame] | 618 | case GSM48_MT_GMM_DETACH_REQ: |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 619 | rc = gsm48_rx_gmm_det_req(mmctx, msg); |
Harald Welte | 2720e73 | 2010-05-17 00:44:57 +0200 | [diff] [blame] | 620 | break; |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 621 | case GSM48_MT_GMM_RA_UPD_COMPL: |
| 622 | /* only in case SGSN offered new P-TMSI */ |
| 623 | case GSM48_MT_GMM_ATTACH_COMPL: |
| 624 | /* only in case SGSN offered new P-TMSI */ |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 625 | case GSM48_MT_GMM_PTMSI_REALL_COMPL: |
| 626 | case GSM48_MT_GMM_AUTH_CIPH_RESP: |
| 627 | DEBUGP(DMM, "Unimplemented GSM 04.08 GMM msg type 0x%02x\n", |
| 628 | gh->msg_type); |
Harald Welte | 2720e73 | 2010-05-17 00:44:57 +0200 | [diff] [blame] | 629 | /* FIXME: Send GMM_CAUSE_MSGT_NOTEXIST_NOTIMPL */ |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 630 | break; |
| 631 | default: |
| 632 | DEBUGP(DMM, "Unknown GSM 04.08 GMM msg type 0x%02x\n", |
| 633 | gh->msg_type); |
Harald Welte | 2720e73 | 2010-05-17 00:44:57 +0200 | [diff] [blame] | 634 | /* FIXME: Send GMM_CAUSE_MSGT_NOTEXIST_NOTIMPL */ |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 635 | break; |
| 636 | } |
| 637 | |
| 638 | return rc; |
| 639 | } |
| 640 | |
Harald Welte | 421cba4 | 2010-05-02 23:11:50 +0200 | [diff] [blame] | 641 | static void msgb_put_pdp_addr_ipv4(struct msgb *msg, uint32_t ipaddr) |
| 642 | { |
| 643 | uint8_t v[6]; |
| 644 | |
| 645 | v[0] = PDP_TYPE_ORG_IETF; |
| 646 | v[1] = PDP_TYPE_N_IETF_IPv4; |
| 647 | *(uint32_t *)(v+2) = htonl(ipaddr); |
| 648 | |
| 649 | msgb_tlv_put(msg, GSM48_IE_GSM_PDP_ADDR, sizeof(v), v); |
| 650 | } |
| 651 | |
| 652 | static void msgb_put_pdp_addr_ppp(struct msgb *msg) |
| 653 | { |
| 654 | uint8_t v[2]; |
| 655 | |
| 656 | v[0] = PDP_TYPE_ORG_ETSI; |
| 657 | v[1] = PDP_TYPE_N_ETSI_PPP; |
| 658 | |
| 659 | msgb_tlv_put(msg, GSM48_IE_GSM_PDP_ADDR, sizeof(v), v); |
| 660 | } |
| 661 | |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 662 | /* Section 9.5.2: Ativate PDP Context Accept */ |
Harald Welte | 6abf94e | 2010-05-18 10:35:06 +0200 | [diff] [blame] | 663 | int gsm48_tx_gsm_act_pdp_acc(struct sgsn_pdp_ctx *pdp) |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 664 | { |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 665 | struct msgb *msg = gsm48_msgb_alloc(); |
| 666 | struct gsm48_act_pdp_ctx_ack *act_ack; |
| 667 | struct gsm48_hdr *gh; |
Harald Welte | 6abf94e | 2010-05-18 10:35:06 +0200 | [diff] [blame] | 668 | uint8_t transaction_id = pdp->ti ^ 0x8; /* flip */ |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 669 | |
| 670 | DEBUGP(DMM, "<- ACTIVATE PDP CONTEXT ACK\n"); |
| 671 | |
Harald Welte | 6abf94e | 2010-05-18 10:35:06 +0200 | [diff] [blame] | 672 | mmctx2msgid(msg, pdp->mm); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 673 | |
| 674 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 675 | gh->proto_discr = GSM48_PDISC_SM_GPRS | (transaction_id << 4); |
| 676 | gh->msg_type = GSM48_MT_GSM_ACT_PDP_ACK; |
Harald Welte | 421cba4 | 2010-05-02 23:11:50 +0200 | [diff] [blame] | 677 | |
| 678 | /* Negotiated LLC SAPI */ |
Harald Welte | 6abf94e | 2010-05-18 10:35:06 +0200 | [diff] [blame] | 679 | msgb_v_put(msg, pdp->sapi); |
Harald Welte | 55e0df7 | 2010-05-18 13:20:08 +0200 | [diff] [blame] | 680 | /* FIXME: copy QoS parameters from original request */ |
| 681 | //msgb_lv_put(msg, pdp->lib->qos_neg.l, pdp->lib->qos_neg.v); |
| 682 | msgb_lv_put(msg, sizeof(default_qos), (uint8_t *)&default_qos); |
Harald Welte | 421cba4 | 2010-05-02 23:11:50 +0200 | [diff] [blame] | 683 | /* Radio priority 10.5.7.2 */ |
Harald Welte | 6abf94e | 2010-05-18 10:35:06 +0200 | [diff] [blame] | 684 | msgb_v_put(msg, pdp->lib->radio_pri); |
Harald Welte | 421cba4 | 2010-05-02 23:11:50 +0200 | [diff] [blame] | 685 | /* PDP address */ |
Harald Welte | 6abf94e | 2010-05-18 10:35:06 +0200 | [diff] [blame] | 686 | msgb_tlv_put(msg, GSM48_IE_GSM_PDP_ADDR, |
| 687 | pdp->lib->eua.l, pdp->lib->eua.v); |
Harald Welte | 77289c2 | 2010-05-18 14:32:29 +0200 | [diff] [blame] | 688 | /* Optional: Protocol configuration options (FIXME: why 'req') */ |
| 689 | if (pdp->lib->pco_req.l && pdp->lib->pco_req.v) |
Harald Welte | 6abf94e | 2010-05-18 10:35:06 +0200 | [diff] [blame] | 690 | msgb_tlv_put(msg, GSM48_IE_GSM_PROTO_CONF_OPT, |
Harald Welte | 3c0b9b9 | 2010-05-18 14:36:11 +0200 | [diff] [blame^] | 691 | pdp->lib->pco_req.l, pdp->lib->pco_req.v); |
Harald Welte | 421cba4 | 2010-05-02 23:11:50 +0200 | [diff] [blame] | 692 | /* Optional: Packet Flow Identifier */ |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 693 | |
Harald Welte | 8acd88f | 2010-05-18 10:57:45 +0200 | [diff] [blame] | 694 | return gsm48_gmm_sendmsg(msg, 0, pdp->mm); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 695 | } |
| 696 | |
Harald Welte | 6abf94e | 2010-05-18 10:35:06 +0200 | [diff] [blame] | 697 | /* Section 9.5.3: Activate PDP Context reject */ |
| 698 | int gsm48_tx_gsm_act_pdp_rej(struct sgsn_mm_ctx *mm, uint8_t tid, |
| 699 | uint8_t cause, uint8_t pco_len, uint8_t *pco_v) |
| 700 | { |
| 701 | struct msgb *msg = gsm48_msgb_alloc(); |
| 702 | struct gsm48_act_pdp_ctx_ack *act_ack; |
| 703 | struct gsm48_hdr *gh; |
| 704 | uint8_t transaction_id = tid ^ 0x8; /* flip */ |
| 705 | |
Harald Welte | 77289c2 | 2010-05-18 14:32:29 +0200 | [diff] [blame] | 706 | DEBUGP(DMM, "<- ACTIVATE PDP CONTEXT REJ(cause=%u)\n", cause); |
Harald Welte | 6abf94e | 2010-05-18 10:35:06 +0200 | [diff] [blame] | 707 | |
| 708 | mmctx2msgid(msg, mm); |
| 709 | |
| 710 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 711 | gh->proto_discr = GSM48_PDISC_SM_GPRS | (transaction_id << 4); |
| 712 | gh->msg_type = GSM48_MT_GSM_ACT_PDP_REJ; |
| 713 | |
| 714 | msgb_v_put(msg, cause); |
| 715 | if (pco_len && pco_v) |
| 716 | msgb_tlv_put(msg, GSM48_IE_GSM_PROTO_CONF_OPT, pco_len, pco_v); |
| 717 | |
Harald Welte | 8acd88f | 2010-05-18 10:57:45 +0200 | [diff] [blame] | 718 | return gsm48_gmm_sendmsg(msg, 0, mm); |
Harald Welte | 6abf94e | 2010-05-18 10:35:06 +0200 | [diff] [blame] | 719 | } |
| 720 | |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 721 | /* Section 9.5.9: Deactivate PDP Context Accept */ |
Harald Welte | 77289c2 | 2010-05-18 14:32:29 +0200 | [diff] [blame] | 722 | int gsm48_tx_gsm_deact_pdp_acc(struct sgsn_pdp_ctx *pdp) |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 723 | { |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 724 | struct msgb *msg = gsm48_msgb_alloc(); |
| 725 | struct gsm48_hdr *gh; |
Harald Welte | 77289c2 | 2010-05-18 14:32:29 +0200 | [diff] [blame] | 726 | uint8_t transaction_id = pdp->ti ^ 0x8; /* flip */ |
| 727 | int rc; |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 728 | |
| 729 | DEBUGP(DMM, "<- DEACTIVATE PDP CONTEXT ACK\n"); |
| 730 | |
Harald Welte | 77289c2 | 2010-05-18 14:32:29 +0200 | [diff] [blame] | 731 | mmctx2msgid(msg, pdp->mm); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 732 | |
| 733 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 734 | gh->proto_discr = GSM48_PDISC_SM_GPRS | (transaction_id << 4); |
| 735 | gh->msg_type = GSM48_MT_GSM_DEACT_PDP_ACK; |
| 736 | |
Harald Welte | 77289c2 | 2010-05-18 14:32:29 +0200 | [diff] [blame] | 737 | return gsm48_gmm_sendmsg(msg, 0, pdp->mm); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 738 | } |
| 739 | |
| 740 | /* Section 9.5.1: Activate PDP Context Request */ |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 741 | static int gsm48_rx_gsm_act_pdp_req(struct sgsn_mm_ctx *mmctx, |
| 742 | struct msgb *msg) |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 743 | { |
Harald Welte | 943c5bc | 2010-04-30 16:33:12 +0200 | [diff] [blame] | 744 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_gmmh(msg); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 745 | struct gsm48_act_pdp_ctx_req *act_req = (struct gsm48_act_pdp_ctx_req *) gh->data; |
Harald Welte | eaa614c | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 746 | uint8_t *pdp_addr_lv = act_req->data; |
Harald Welte | 0c3eae0 | 2010-05-02 21:07:14 +0200 | [diff] [blame] | 747 | uint8_t req_qos_len, req_pdpa_len; |
| 748 | uint8_t *req_qos, *req_pdpa; |
| 749 | struct tlv_parsed tp; |
Harald Welte | 6abf94e | 2010-05-18 10:35:06 +0200 | [diff] [blame] | 750 | uint8_t transaction_id = (gh->proto_discr >> 4); |
| 751 | struct sgsn_pdp_ctx *pdp; |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 752 | |
Harald Welte | 6abf94e | 2010-05-18 10:35:06 +0200 | [diff] [blame] | 753 | DEBUGP(DMM, "-> ACTIVATE PDP CONTEXT REQ: SAPI=%u NSAPI=%u ", |
| 754 | act_req->req_llc_sapi, act_req->req_nsapi); |
Harald Welte | 8acd88f | 2010-05-18 10:57:45 +0200 | [diff] [blame] | 755 | |
| 756 | rate_ctr_inc(&mmctx->ctrg->ctr[GMM_CTR_PDP_CTX_ACT]); |
| 757 | |
Harald Welte | 0c3eae0 | 2010-05-02 21:07:14 +0200 | [diff] [blame] | 758 | req_qos_len = act_req->data[0]; |
| 759 | req_qos = act_req->data + 1; /* 10.5.6.5 */ |
| 760 | req_pdpa_len = act_req->data[1 + req_qos_len]; |
| 761 | 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] | 762 | |
Harald Welte | 0c3eae0 | 2010-05-02 21:07:14 +0200 | [diff] [blame] | 763 | switch (req_pdpa[0] & 0xf) { |
| 764 | case 0x0: |
| 765 | DEBUGPC(DMM, "ETSI "); |
| 766 | break; |
| 767 | case 0x1: |
| 768 | DEBUGPC(DMM, "IETF "); |
| 769 | break; |
| 770 | case 0xf: |
| 771 | DEBUGPC(DMM, "Empty "); |
| 772 | break; |
| 773 | } |
| 774 | |
| 775 | switch (req_pdpa[1]) { |
| 776 | case 0x21: |
| 777 | DEBUGPC(DMM, "IPv4 "); |
| 778 | if (req_pdpa_len >= 6) { |
| 779 | struct in_addr ia; |
| 780 | ia.s_addr = ntohl(*((uint32_t *) (req_pdpa+2))); |
| 781 | DEBUGPC(DMM, "%s ", inet_ntoa(ia)); |
| 782 | } |
| 783 | break; |
| 784 | case 0x57: |
| 785 | DEBUGPC(DMM, "IPv6 "); |
| 786 | if (req_pdpa_len >= 18) { |
| 787 | /* FIXME: print IPv6 address */ |
| 788 | } |
| 789 | break; |
| 790 | default: |
| 791 | DEBUGPC(DMM, "0x%02x ", req_pdpa[1]); |
| 792 | break; |
| 793 | } |
| 794 | |
Harald Welte | 77289c2 | 2010-05-18 14:32:29 +0200 | [diff] [blame] | 795 | DEBUGPC(DMM, "\n"); |
| 796 | |
Harald Welte | 2720e73 | 2010-05-17 00:44:57 +0200 | [diff] [blame] | 797 | /* put the non-TLV elements in the TLV parser structure to |
| 798 | * pass them on to the SGSN / GTP code */ |
| 799 | tp.lv[OSMO_IE_GSM_REQ_QOS].len = req_qos_len; |
| 800 | tp.lv[OSMO_IE_GSM_REQ_QOS].val = req_qos; |
| 801 | tp.lv[OSMO_IE_GSM_REQ_PDP_ADDR].len = req_pdpa_len; |
| 802 | tp.lv[OSMO_IE_GSM_REQ_PDP_ADDR].val = req_pdpa; |
| 803 | |
Harald Welte | 6abf94e | 2010-05-18 10:35:06 +0200 | [diff] [blame] | 804 | /* FIXME: determine GGSN based on APN and subscription options */ |
Harald Welte | 0c3eae0 | 2010-05-02 21:07:14 +0200 | [diff] [blame] | 805 | if (TLVP_PRESENT(&tp, GSM48_IE_GSM_APN)) {} |
Harald Welte | 6abf94e | 2010-05-18 10:35:06 +0200 | [diff] [blame] | 806 | |
| 807 | /* Check if NSAPI is out of range (TS 04.65 / 7.2) */ |
| 808 | if (act_req->req_nsapi < 5 || act_req->req_nsapi > 15) { |
| 809 | /* Send reject with GSM_CAUSE_INV_MAND_INFO */ |
| 810 | return gsm48_tx_gsm_act_pdp_rej(mmctx, transaction_id, |
| 811 | GSM_CAUSE_INV_MAND_INFO, |
| 812 | 0, NULL); |
| 813 | } |
| 814 | |
| 815 | /* Check if NSAPI is already in use */ |
| 816 | if (sgsn_pdp_ctx_by_nsapi(mmctx, act_req->req_nsapi)) { |
| 817 | /* FIXME: send reject with GSM_CAUSE_NSAPI_IN_USE */ |
| 818 | return gsm48_tx_gsm_act_pdp_rej(mmctx, transaction_id, |
| 819 | GSM_CAUSE_NSAPI_IN_USE, |
| 820 | 0, NULL); |
| 821 | } |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 822 | |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 823 | #if 1 |
| 824 | { |
Harald Welte | 77289c2 | 2010-05-18 14:32:29 +0200 | [diff] [blame] | 825 | pdp = sgsn_create_pdp_ctx(dummy_ggsn, mmctx, act_req->req_nsapi, &tp); |
Harald Welte | 6abf94e | 2010-05-18 10:35:06 +0200 | [diff] [blame] | 826 | if (!pdp) |
| 827 | return -1; |
| 828 | pdp->sapi = act_req->req_llc_sapi; |
| 829 | pdp->ti = transaction_id; |
| 830 | |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 831 | } |
Harald Welte | 2720e73 | 2010-05-17 00:44:57 +0200 | [diff] [blame] | 832 | #else |
Harald Welte | 6abf94e | 2010-05-18 10:35:06 +0200 | [diff] [blame] | 833 | return gsm48_tx_gsm_act_pdp_acc(mmctx, transaction_id, act_req); |
Harald Welte | 2720e73 | 2010-05-17 00:44:57 +0200 | [diff] [blame] | 834 | #endif |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 835 | } |
| 836 | |
| 837 | /* Section 9.5.8: Deactivate PDP Context Request */ |
Harald Welte | 77289c2 | 2010-05-18 14:32:29 +0200 | [diff] [blame] | 838 | 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] | 839 | { |
Harald Welte | 943c5bc | 2010-04-30 16:33:12 +0200 | [diff] [blame] | 840 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_gmmh(msg); |
Harald Welte | 77289c2 | 2010-05-18 14:32:29 +0200 | [diff] [blame] | 841 | uint8_t transaction_id = (gh->proto_discr >> 4); |
| 842 | struct sgsn_pdp_ctx *pdp; |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 843 | |
Harald Welte | 2720e73 | 2010-05-17 00:44:57 +0200 | [diff] [blame] | 844 | DEBUGP(DMM, "-> DEACTIVATE PDP CONTEXT REQ (cause: %s)\n", |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 845 | get_value_string(gsm_cause_names, gh->data[0])); |
| 846 | |
Harald Welte | 77289c2 | 2010-05-18 14:32:29 +0200 | [diff] [blame] | 847 | pdp = sgsn_pdp_ctx_by_tid(mm, transaction_id); |
| 848 | if (!pdp) { |
| 849 | LOGP(DMM, LOGL_NOTICE, "Deactivate PDP Context Request for " |
| 850 | "non-existing PDP Context (IMSI=%s, TI=%u)\n", |
| 851 | mm->imsi, transaction_id); |
| 852 | return -EINVAL; |
| 853 | } |
| 854 | |
| 855 | return sgsn_delete_pdp_ctx(pdp); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 856 | } |
| 857 | |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 858 | 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] | 859 | { |
| 860 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 861 | |
Harald Welte | 2720e73 | 2010-05-17 00:44:57 +0200 | [diff] [blame] | 862 | DEBUGP(DMM, "-> GPRS SM STATUS (cause: %s)\n", |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 863 | get_value_string(gsm_cause_names, gh->data[0])); |
| 864 | |
| 865 | return 0; |
| 866 | } |
| 867 | |
| 868 | /* GPRS Session Management */ |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 869 | static int gsm0408_rcv_gsm(struct sgsn_mm_ctx *mmctx, struct msgb *msg) |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 870 | { |
Harald Welte | 943c5bc | 2010-04-30 16:33:12 +0200 | [diff] [blame] | 871 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_gmmh(msg); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 872 | int rc; |
| 873 | |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 874 | if (!mmctx) { |
| 875 | LOGP(DMM, LOGL_NOTICE, "Cannot handle SM for unknown MM CTX\n"); |
| 876 | return -EINVAL; |
| 877 | } |
| 878 | |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 879 | switch (gh->msg_type) { |
| 880 | case GSM48_MT_GSM_ACT_PDP_REQ: |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 881 | rc = gsm48_rx_gsm_act_pdp_req(mmctx, msg); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 882 | break; |
| 883 | case GSM48_MT_GSM_DEACT_PDP_REQ: |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 884 | rc = gsm48_rx_gsm_deact_pdp_req(mmctx, msg); |
Harald Welte | 77289c2 | 2010-05-18 14:32:29 +0200 | [diff] [blame] | 885 | break; |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 886 | case GSM48_MT_GSM_STATUS: |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 887 | rc = gsm48_rx_gsm_status(mmctx, msg); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 888 | break; |
| 889 | case GSM48_MT_GSM_REQ_PDP_ACT_REJ: |
| 890 | case GSM48_MT_GSM_ACT_AA_PDP_REQ: |
| 891 | case GSM48_MT_GSM_DEACT_AA_PDP_REQ: |
| 892 | DEBUGP(DMM, "Unimplemented GSM 04.08 GSM msg type 0x%02x\n", |
| 893 | gh->msg_type); |
| 894 | break; |
| 895 | default: |
| 896 | DEBUGP(DMM, "Unknown GSM 04.08 GSM msg type 0x%02x\n", |
| 897 | gh->msg_type); |
| 898 | break; |
| 899 | |
| 900 | } |
| 901 | |
| 902 | return rc; |
| 903 | } |
| 904 | |
| 905 | /* Main entry point for incoming 04.08 GPRS messages */ |
| 906 | int gsm0408_gprs_rcvmsg(struct msgb *msg) |
| 907 | { |
Harald Welte | 943c5bc | 2010-04-30 16:33:12 +0200 | [diff] [blame] | 908 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_gmmh(msg); |
Harald Welte | eaa614c | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 909 | uint8_t pdisc = gh->proto_discr & 0x0f; |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 910 | struct sgsn_mm_ctx *mmctx; |
| 911 | struct gprs_ra_id ra_id; |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 912 | int rc = -EINVAL; |
| 913 | |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 914 | bssgp_parse_cell_id(&ra_id, msgb_bcid(msg)); |
| 915 | mmctx = sgsn_mm_ctx_by_tlli(msgb_tlli(msg), &ra_id); |
Harald Welte | 8acd88f | 2010-05-18 10:57:45 +0200 | [diff] [blame] | 916 | if (mmctx) { |
Harald Welte | 6abf94e | 2010-05-18 10:35:06 +0200 | [diff] [blame] | 917 | msgid2mmctx(mmctx, msg); |
Harald Welte | 8acd88f | 2010-05-18 10:57:45 +0200 | [diff] [blame] | 918 | rate_ctr_inc(&mmctx->ctrg->ctr[GMM_CTR_PKTS_SIG_IN]); |
| 919 | } |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 920 | |
| 921 | /* MMCTX can be NULL */ |
| 922 | |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 923 | switch (pdisc) { |
| 924 | case GSM48_PDISC_MM_GPRS: |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 925 | rc = gsm0408_rcv_gmm(mmctx, msg); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 926 | break; |
| 927 | case GSM48_PDISC_SM_GPRS: |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 928 | rc = gsm0408_rcv_gsm(mmctx, msg); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 929 | break; |
| 930 | default: |
| 931 | DEBUGP(DMM, "Unknown GSM 04.08 discriminator 0x%02x\n", |
| 932 | pdisc); |
Harald Welte | 6abf94e | 2010-05-18 10:35:06 +0200 | [diff] [blame] | 933 | /* FIXME: return status message */ |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 934 | break; |
| 935 | } |
| 936 | |
| 937 | return rc; |
| 938 | } |