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