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