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> |
Harald Welte | 8a035af | 2010-05-18 10:57:45 +0200 | [diff] [blame] | 39 | #include <osmocore/rate_ctr.h> |
Harald Welte | e4cc19a | 2010-05-02 12:57:45 +0200 | [diff] [blame] | 40 | |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 41 | #include <openbsc/debug.h> |
| 42 | #include <openbsc/gsm_data.h> |
Harald Welte | 75bb820 | 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 | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 47 | #include <openbsc/transaction.h> |
Harald Welte | 2351f1f | 2010-05-02 11:54:55 +0200 | [diff] [blame] | 48 | #include <openbsc/gprs_bssgp.h> |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 49 | #include <openbsc/gprs_llc.h> |
| 50 | #include <openbsc/gprs_sgsn.h> |
Harald Welte | 29d838e | 2010-05-18 10:35:06 +0200 | [diff] [blame] | 51 | #include <openbsc/gprs_gmm.h> |
Harald Welte | c1f6bfe | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 52 | #include <openbsc/sgsn.h> |
| 53 | |
Harald Welte | 29d838e | 2010-05-18 10:35:06 +0200 | [diff] [blame] | 54 | #include <pdp.h> |
| 55 | |
Harald Welte | c1f6bfe | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 56 | extern struct sgsn_instance *sgsn; |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 57 | |
Harald Welte | 8f77f19 | 2010-05-17 00:44:57 +0200 | [diff] [blame] | 58 | /* Protocol related stuff, should go into libosmocore */ |
| 59 | |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 60 | /* 10.5.5.14 GPRS MM Cause / Table 10.5.147 */ |
Harald Welte | 8f77f19 | 2010-05-17 00:44:57 +0200 | [diff] [blame] | 61 | const struct value_string gmm_cause_names[] = { |
Harald Welte | 75bb820 | 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 | 8f77f19 | 2010-05-17 00:44:57 +0200 | [diff] [blame] | 79 | const struct value_string gsm_cause_names[] = { |
Harald Welte | 75bb820 | 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 | 8f77f19 | 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 | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 120 | |
Harald Welte | 8f77f19 | 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 | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 138 | |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 139 | /* Send a message through the underlying layer */ |
Harald Welte | 8a035af | 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 | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 142 | { |
Harald Welte | 8a035af | 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 | 2351f1f | 2010-05-02 11:54:55 +0200 | [diff] [blame] | 146 | /* caller needs to provide TLLI, BVCI and NSEI */ |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 147 | return gprs_llc_tx_ui(msg, GPRS_SAPI_GMM, command); |
| 148 | } |
| 149 | |
Harald Welte | 2351f1f | 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 | 29d838e | 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 | 242d172 | 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 | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 197 | /* Chapter 9.4.2: Attach accept */ |
Harald Welte | 64df8ed | 2010-05-18 17:04:55 +0200 | [diff] [blame] | 198 | static int gsm48_tx_gmm_att_ack(struct sgsn_mm_ctx *mm) |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 199 | { |
| 200 | struct msgb *msg = gsm48_msgb_alloc(); |
| 201 | struct gsm48_hdr *gh; |
| 202 | struct gsm48_attach_ack *aa; |
Harald Welte | 50d44fe | 2010-05-18 17:20:49 +0200 | [diff] [blame] | 203 | uint8_t *ptsig, *mid; |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 204 | |
| 205 | DEBUGP(DMM, "<- GPRS ATTACH ACCEPT\n"); |
| 206 | |
Harald Welte | 64df8ed | 2010-05-18 17:04:55 +0200 | [diff] [blame] | 207 | mmctx2msgid(msg, mm); |
Harald Welte | 75bb820 | 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 | 64df8ed | 2010-05-18 17:04:55 +0200 | [diff] [blame] | 218 | gsm48_construct_ra(aa->ra_id.digits, &mm->ra); |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 219 | |
Harald Welte | ebe8a6d | 2010-05-18 19:58:38 +0200 | [diff] [blame] | 220 | #if 0 |
Harald Welte | 64df8ed | 2010-05-18 17:04:55 +0200 | [diff] [blame] | 221 | /* Optional: P-TMSI signature */ |
| 222 | msgb_v_put(msg, GSM48_IE_GMM_PTMSI_SIG); |
| 223 | ptsig = msgb_put(msg, 3); |
| 224 | ptsig[0] = mm->p_tmsi_sig >> 16; |
| 225 | ptsig[1] = mm->p_tmsi_sig >> 8; |
| 226 | ptsig[2] = mm->p_tmsi_sig & 0xff; |
| 227 | |
| 228 | /* Optional: Negotiated Ready timer value */ |
| 229 | |
| 230 | /* Optional: Allocated P-TMSI */ |
Harald Welte | 64df8ed | 2010-05-18 17:04:55 +0200 | [diff] [blame] | 231 | mid = msgb_put(msg, GSM48_MID_TMSI_LEN); |
| 232 | gsm48_generate_mid_from_tmsi(mid, mm->p_tmsi); |
Harald Welte | ebe8a6d | 2010-05-18 19:58:38 +0200 | [diff] [blame] | 233 | mid[0] = GSM48_IE_GMM_ALLOC_PTMSI; |
| 234 | #endif |
Harald Welte | 64df8ed | 2010-05-18 17:04:55 +0200 | [diff] [blame] | 235 | /* Optional: MS-identity (combined attach) */ |
| 236 | /* Optional: GMM cause (partial attach result for combined attach) */ |
| 237 | |
Harald Welte | 8a035af | 2010-05-18 10:57:45 +0200 | [diff] [blame] | 238 | return gsm48_gmm_sendmsg(msg, 0, NULL); |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | /* Chapter 9.4.5: Attach reject */ |
Harald Welte | 64df8ed | 2010-05-18 17:04:55 +0200 | [diff] [blame] | 242 | static int _tx_gmm_att_rej(struct msgb *msg, uint8_t gmm_cause) |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 243 | { |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 244 | struct gsm48_hdr *gh; |
| 245 | |
| 246 | DEBUGP(DMM, "<- GPRS ATTACH REJECT\n"); |
| 247 | |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 248 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 1); |
| 249 | gh->proto_discr = GSM48_PDISC_MM_GPRS; |
| 250 | gh->msg_type = GSM48_MT_GMM_ATTACH_REJ; |
| 251 | gh->data[0] = gmm_cause; |
| 252 | |
Harald Welte | 8a035af | 2010-05-18 10:57:45 +0200 | [diff] [blame] | 253 | return gsm48_gmm_sendmsg(msg, 0, NULL); |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 254 | } |
Harald Welte | 64df8ed | 2010-05-18 17:04:55 +0200 | [diff] [blame] | 255 | static int gsm48_tx_gmm_att_rej_oldmsg(const struct msgb *old_msg, |
| 256 | uint8_t gmm_cause) |
| 257 | { |
| 258 | struct msgb *msg = gsm48_msgb_alloc(); |
| 259 | gmm_copy_id(msg, old_msg); |
| 260 | return _tx_gmm_att_rej(msg, gmm_cause); |
| 261 | } |
| 262 | static int gsm48_tx_gmm_att_rej(struct sgsn_mm_ctx *mm, |
| 263 | uint8_t gmm_cause) |
| 264 | { |
| 265 | struct msgb *msg = gsm48_msgb_alloc(); |
| 266 | mmctx2msgid(msg, mm); |
| 267 | return _tx_gmm_att_rej(msg, gmm_cause); |
| 268 | } |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 269 | |
Harald Welte | 8f77f19 | 2010-05-17 00:44:57 +0200 | [diff] [blame] | 270 | /* Chapter 9.4.6.2 Detach accept */ |
Harald Welte | 50d44fe | 2010-05-18 17:20:49 +0200 | [diff] [blame] | 271 | static int gsm48_tx_gmm_det_ack(struct sgsn_mm_ctx *mm, uint8_t force_stby) |
Harald Welte | 8f77f19 | 2010-05-17 00:44:57 +0200 | [diff] [blame] | 272 | { |
| 273 | struct msgb *msg = gsm48_msgb_alloc(); |
| 274 | struct gsm48_hdr *gh; |
| 275 | |
| 276 | DEBUGP(DMM, "<- GPRS DETACH ACCEPT\n"); |
| 277 | |
Harald Welte | 64df8ed | 2010-05-18 17:04:55 +0200 | [diff] [blame] | 278 | mmctx2msgid(msg, mm); |
| 279 | |
Harald Welte | 8f77f19 | 2010-05-17 00:44:57 +0200 | [diff] [blame] | 280 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 1); |
| 281 | gh->proto_discr = GSM48_PDISC_MM_GPRS; |
| 282 | gh->msg_type = GSM48_MT_GMM_DETACH_ACK; |
| 283 | gh->data[0] = force_stby; |
| 284 | |
Harald Welte | 8a035af | 2010-05-18 10:57:45 +0200 | [diff] [blame] | 285 | return gsm48_gmm_sendmsg(msg, 0, NULL); |
Harald Welte | 8f77f19 | 2010-05-17 00:44:57 +0200 | [diff] [blame] | 286 | } |
| 287 | |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 288 | /* Transmit Chapter 9.4.12 Identity Request */ |
Harald Welte | 64df8ed | 2010-05-18 17:04:55 +0200 | [diff] [blame] | 289 | static int gsm48_tx_gmm_id_req(struct sgsn_mm_ctx *mm, uint8_t id_type) |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 290 | { |
| 291 | struct msgb *msg = gsm48_msgb_alloc(); |
| 292 | struct gsm48_hdr *gh; |
| 293 | |
| 294 | DEBUGP(DMM, "-> GPRS IDENTITY REQUEST: mi_type=%02x\n", id_type); |
| 295 | |
Harald Welte | 64df8ed | 2010-05-18 17:04:55 +0200 | [diff] [blame] | 296 | mmctx2msgid(msg, mm); |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 297 | |
| 298 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 1); |
| 299 | gh->proto_discr = GSM48_PDISC_MM_GPRS; |
| 300 | gh->msg_type = GSM48_MT_GMM_ID_REQ; |
| 301 | /* 10.5.5.9 ID type 2 + identity type and 10.5.5.7 'force to standby' IE */ |
| 302 | gh->data[0] = id_type & 0xf; |
| 303 | |
Harald Welte | 8a035af | 2010-05-18 10:57:45 +0200 | [diff] [blame] | 304 | return gsm48_gmm_sendmsg(msg, 0, NULL); |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | /* Check if we can already authorize a subscriber */ |
Harald Welte | 64df8ed | 2010-05-18 17:04:55 +0200 | [diff] [blame] | 308 | static int gsm48_gmm_authorize(struct sgsn_mm_ctx *ctx) |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 309 | { |
| 310 | if (strlen(ctx->imei) && strlen(ctx->imsi)) { |
| 311 | ctx->mm_state = GMM_REGISTERED_NORMAL; |
Harald Welte | 64df8ed | 2010-05-18 17:04:55 +0200 | [diff] [blame] | 312 | return gsm48_tx_gmm_att_ack(ctx); |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 313 | } |
| 314 | if (!strlen(ctx->imei)) |
Harald Welte | 64df8ed | 2010-05-18 17:04:55 +0200 | [diff] [blame] | 315 | return gsm48_tx_gmm_id_req(ctx, GSM_MI_TYPE_IMEI); |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 316 | |
| 317 | if (!strlen(ctx->imsi)) |
Harald Welte | 64df8ed | 2010-05-18 17:04:55 +0200 | [diff] [blame] | 318 | return gsm48_tx_gmm_id_req(ctx, GSM_MI_TYPE_IMSI); |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 319 | |
| 320 | return 0; |
| 321 | } |
| 322 | |
| 323 | /* Parse Chapter 9.4.13 Identity Response */ |
Harald Welte | c1f6bfe | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 324 | 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] | 325 | { |
Harald Welte | cf3c414 | 2010-04-30 16:33:12 +0200 | [diff] [blame] | 326 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_gmmh(msg); |
Harald Welte | d85d9a9 | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 327 | uint8_t mi_type = gh->data[1] & GSM_MI_TYPE_MASK; |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 328 | char mi_string[GSM48_MI_SIZE]; |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 329 | |
| 330 | 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] | 331 | DEBUGP(DMM, "-> GMM IDENTITY RESPONSE: mi_type=0x%02x MI(%s) ", |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 332 | mi_type, mi_string); |
| 333 | |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 334 | if (!ctx) { |
Harald Welte | cf3c414 | 2010-04-30 16:33:12 +0200 | [diff] [blame] | 335 | DEBUGP(DMM, "from unknown TLLI 0x%08x?!?\n", msgb_tlli(msg)); |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 336 | return -EINVAL; |
| 337 | } |
| 338 | |
| 339 | switch (mi_type) { |
| 340 | case GSM_MI_TYPE_IMSI: |
| 341 | /* we already have a mm context with current TLLI, but no |
| 342 | * P-TMSI / IMSI yet. What we now need to do is to fill |
| 343 | * this initial context with data from the HLR */ |
| 344 | strncpy(ctx->imsi, mi_string, sizeof(ctx->imei)); |
| 345 | break; |
| 346 | case GSM_MI_TYPE_IMEI: |
| 347 | strncpy(ctx->imei, mi_string, sizeof(ctx->imei)); |
| 348 | break; |
| 349 | case GSM_MI_TYPE_IMEISV: |
| 350 | break; |
| 351 | } |
| 352 | |
| 353 | DEBUGPC(DMM, "\n"); |
| 354 | /* Check if we can let the mobile station enter */ |
Harald Welte | 64df8ed | 2010-05-18 17:04:55 +0200 | [diff] [blame] | 355 | return gsm48_gmm_authorize(ctx); |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 356 | } |
| 357 | |
| 358 | static void attach_rej_cb(void *data) |
| 359 | { |
| 360 | struct sgsn_mm_ctx *ctx = data; |
| 361 | |
Harald Welte | 64df8ed | 2010-05-18 17:04:55 +0200 | [diff] [blame] | 362 | gsm48_tx_gmm_att_rej(ctx, GMM_CAUSE_MS_ID_NOT_DERIVED); |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 363 | ctx->mm_state = GMM_DEREGISTERED; |
| 364 | /* FIXME: release the context */ |
| 365 | } |
| 366 | |
| 367 | static void schedule_reject(struct sgsn_mm_ctx *ctx) |
| 368 | { |
| 369 | ctx->T = 3370; |
| 370 | ctx->timer.cb = attach_rej_cb; |
| 371 | ctx->timer.data = ctx; |
| 372 | bsc_schedule_timer(&ctx->timer, 6, 0); |
| 373 | } |
| 374 | |
| 375 | /* Section 9.4.1 Attach request */ |
Harald Welte | c1f6bfe | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 376 | 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] | 377 | { |
Harald Welte | cf3c414 | 2010-04-30 16:33:12 +0200 | [diff] [blame] | 378 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_gmmh(msg); |
Harald Welte | d85d9a9 | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 379 | uint8_t *cur = gh->data, *msnc, *mi, *old_ra_info; |
| 380 | uint8_t msnc_len, att_type, mi_len, mi_type; |
| 381 | uint16_t drx_par; |
| 382 | uint32_t tmsi; |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 383 | char mi_string[GSM48_MI_SIZE]; |
| 384 | struct gprs_ra_id ra_id; |
Harald Welte | de34afa | 2010-05-02 12:56:57 +0200 | [diff] [blame] | 385 | uint16_t cid; |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 386 | struct sgsn_mm_ctx *ctx; |
| 387 | |
Harald Welte | 8f77f19 | 2010-05-17 00:44:57 +0200 | [diff] [blame] | 388 | DEBUGP(DMM, "-> GMM ATTACH REQUEST "); |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 389 | |
| 390 | /* As per TS 04.08 Chapter 4.7.1.4, the attach request arrives either |
| 391 | * with a foreign TLLI (P-TMSI that was allocated to the MS before), |
| 392 | * or with random TLLI. */ |
| 393 | |
Harald Welte | de34afa | 2010-05-02 12:56:57 +0200 | [diff] [blame] | 394 | cid = bssgp_parse_cell_id(&ra_id, msgb_bcid(msg)); |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 395 | |
| 396 | /* MS network capability 10.5.5.12 */ |
| 397 | msnc_len = *cur++; |
| 398 | msnc = cur; |
| 399 | if (msnc_len > 2) |
| 400 | goto err_inval; |
| 401 | cur += msnc_len; |
| 402 | |
| 403 | /* aTTACH Type 10.5.5.2 */ |
| 404 | att_type = *cur++ & 0x0f; |
| 405 | |
| 406 | /* DRX parameter 10.5.5.6 */ |
| 407 | drx_par = *cur++; |
| 408 | drx_par |= *cur++ << 8; |
| 409 | |
| 410 | /* Mobile Identity (P-TMSI or IMSI) 10.5.1.4 */ |
| 411 | mi_len = *cur++; |
| 412 | mi = cur; |
| 413 | if (mi_len > 8) |
| 414 | goto err_inval; |
| 415 | mi_type = *mi & GSM_MI_TYPE_MASK; |
| 416 | cur += mi_len; |
| 417 | |
| 418 | gsm48_mi_to_string(mi_string, sizeof(mi_string), mi, mi_len); |
| 419 | |
Harald Welte | 8f77f19 | 2010-05-17 00:44:57 +0200 | [diff] [blame] | 420 | DEBUGPC(DMM, "MI(%s) type=\"%s\" ", mi_string, |
| 421 | get_value_string(gprs_att_t_strs, att_type)); |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 422 | |
| 423 | /* Old routing area identification 10.5.5.15 */ |
| 424 | old_ra_info = cur; |
| 425 | cur += 6; |
| 426 | |
| 427 | /* MS Radio Access Capability 10.5.5.12a */ |
| 428 | |
| 429 | /* Optional: Old P-TMSI Signature, Requested READY timer, TMSI Status */ |
| 430 | |
| 431 | switch (mi_type) { |
| 432 | case GSM_MI_TYPE_IMSI: |
| 433 | /* Try to find MM context based on IMSI */ |
| 434 | ctx = sgsn_mm_ctx_by_imsi(mi_string); |
| 435 | if (!ctx) { |
| 436 | #if 0 |
| 437 | return gsm48_tx_gmm_att_rej(msg, GMM_CAUSE_IMSI_UNKNOWN); |
| 438 | #else |
| 439 | /* As a temorary hack, we simply assume that the IMSI exists */ |
| 440 | ctx = sgsn_mm_ctx_alloc(0, &ra_id); |
| 441 | if (!ctx) |
Harald Welte | 64df8ed | 2010-05-18 17:04:55 +0200 | [diff] [blame] | 442 | return gsm48_tx_gmm_att_rej_oldmsg(msg, GMM_CAUSE_NET_FAIL); |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 443 | strncpy(ctx->imsi, mi_string, sizeof(ctx->imsi)); |
| 444 | #endif |
| 445 | } |
| 446 | /* FIXME: Start some timer */ |
| 447 | ctx->mm_state = GMM_COMMON_PROC_INIT; |
Harald Welte | cf3c414 | 2010-04-30 16:33:12 +0200 | [diff] [blame] | 448 | ctx->tlli = msgb_tlli(msg); |
Harald Welte | 5c23bfc | 2010-05-18 12:05:42 +0200 | [diff] [blame] | 449 | msgid2mmctx(ctx, msg); |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 450 | break; |
| 451 | case GSM_MI_TYPE_TMSI: |
Harald Welte | ebe8a6d | 2010-05-18 19:58:38 +0200 | [diff] [blame] | 452 | memcpy(&tmsi, mi+1, 4); |
| 453 | tmsi = ntohl(tmsi); |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 454 | /* Try to find MM context based on P-TMSI */ |
| 455 | ctx = sgsn_mm_ctx_by_ptmsi(tmsi); |
| 456 | if (!ctx) { |
Harald Welte | cf3c414 | 2010-04-30 16:33:12 +0200 | [diff] [blame] | 457 | ctx = sgsn_mm_ctx_alloc(msgb_tlli(msg), &ra_id); |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 458 | /* FIXME: Start some timer */ |
| 459 | ctx->mm_state = GMM_COMMON_PROC_INIT; |
Harald Welte | cf3c414 | 2010-04-30 16:33:12 +0200 | [diff] [blame] | 460 | ctx->tlli = msgb_tlli(msg); |
Harald Welte | 5c23bfc | 2010-05-18 12:05:42 +0200 | [diff] [blame] | 461 | msgid2mmctx(ctx, msg); |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 462 | } |
Harald Welte | 64df8ed | 2010-05-18 17:04:55 +0200 | [diff] [blame] | 463 | ctx->p_tmsi = tmsi; |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 464 | break; |
| 465 | default: |
Harald Welte | de34afa | 2010-05-02 12:56:57 +0200 | [diff] [blame] | 466 | return 0; |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 467 | } |
Harald Welte | de34afa | 2010-05-02 12:56:57 +0200 | [diff] [blame] | 468 | /* Update MM Context with currient RA and Cell ID */ |
| 469 | ctx->ra = ra_id; |
| 470 | ctx->cell_id = cid; |
Harald Welte | ebe8a6d | 2010-05-18 19:58:38 +0200 | [diff] [blame] | 471 | #if 0 |
Harald Welte | 64df8ed | 2010-05-18 17:04:55 +0200 | [diff] [blame] | 472 | /* Allocate a new P-TMSI (+ P-TMSI signature) */ |
| 473 | ctx->p_tmsi = sgsn_alloc_ptmsi(); |
Harald Welte | ebe8a6d | 2010-05-18 19:58:38 +0200 | [diff] [blame] | 474 | #endif |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 475 | /* FIXME: update the TLLI with the new local TLLI based on the P-TMSI */ |
| 476 | |
| 477 | DEBUGPC(DMM, "\n"); |
| 478 | |
Harald Welte | 64df8ed | 2010-05-18 17:04:55 +0200 | [diff] [blame] | 479 | return ctx ? gsm48_gmm_authorize(ctx) : 0; |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 480 | |
| 481 | err_inval: |
| 482 | DEBUGPC(DMM, "\n"); |
Harald Welte | 64df8ed | 2010-05-18 17:04:55 +0200 | [diff] [blame] | 483 | return gsm48_tx_gmm_att_rej_oldmsg(msg, GMM_CAUSE_SEM_INCORR_MSG); |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 484 | } |
| 485 | |
Harald Welte | 8f77f19 | 2010-05-17 00:44:57 +0200 | [diff] [blame] | 486 | /* Section 4.7.4.1 / 9.4.5.2 MO Detach request */ |
Harald Welte | c1f6bfe | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 487 | 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] | 488 | { |
| 489 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_gmmh(msg); |
Harald Welte | 8f77f19 | 2010-05-17 00:44:57 +0200 | [diff] [blame] | 490 | uint8_t detach_type, power_off; |
Harald Welte | 8f77f19 | 2010-05-17 00:44:57 +0200 | [diff] [blame] | 491 | |
| 492 | detach_type = gh->data[0] & 0x7; |
| 493 | power_off = gh->data[0] & 0x8; |
| 494 | |
| 495 | /* FIXME: In 24.008 there is an optional P-TMSI and P-TMSI signature IE */ |
| 496 | |
| 497 | DEBUGP(DMM, "-> GMM DETACH REQUEST TLLI=0x%08x type=%s %s\n", |
| 498 | msgb_tlli(msg), get_value_string(gprs_det_t_mo_strs, detach_type), |
| 499 | power_off ? "Power-off" : ""); |
| 500 | |
| 501 | /* Mark MM state as deregistered */ |
| 502 | ctx->mm_state = GMM_DEREGISTERED; |
| 503 | |
| 504 | /* force_stby = 0 */ |
Harald Welte | 64df8ed | 2010-05-18 17:04:55 +0200 | [diff] [blame] | 505 | return gsm48_tx_gmm_det_ack(ctx, 0); |
Harald Welte | 8f77f19 | 2010-05-17 00:44:57 +0200 | [diff] [blame] | 506 | } |
| 507 | |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 508 | /* Chapter 9.4.15: Routing area update accept */ |
Harald Welte | 64df8ed | 2010-05-18 17:04:55 +0200 | [diff] [blame] | 509 | static int gsm48_tx_gmm_ra_upd_ack(struct sgsn_mm_ctx *mm) |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 510 | { |
| 511 | struct msgb *msg = gsm48_msgb_alloc(); |
| 512 | struct gsm48_hdr *gh; |
| 513 | struct gsm48_ra_upd_ack *rua; |
| 514 | |
| 515 | DEBUGP(DMM, "<- ROUTING AREA UPDATE ACCEPT\n"); |
| 516 | |
Harald Welte | 64df8ed | 2010-05-18 17:04:55 +0200 | [diff] [blame] | 517 | mmctx2msgid(msg, mm); |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 518 | |
| 519 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 520 | gh->proto_discr = GSM48_PDISC_MM_GPRS; |
| 521 | gh->msg_type = GSM48_MT_GMM_RA_UPD_ACK; |
| 522 | |
| 523 | rua = (struct gsm48_ra_upd_ack *) msgb_put(msg, sizeof(*rua)); |
| 524 | rua->force_stby = 0; /* not indicated */ |
| 525 | rua->upd_result = 0; /* RA updated */ |
| 526 | rua->ra_upd_timer = GPRS_TMR_MINUTE | 10; |
Harald Welte | 2351f1f | 2010-05-02 11:54:55 +0200 | [diff] [blame] | 527 | |
Harald Welte | 64df8ed | 2010-05-18 17:04:55 +0200 | [diff] [blame] | 528 | gsm48_construct_ra(rua->ra_id.digits, &mm->ra); |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 529 | |
| 530 | /* Option: P-TMSI signature, allocated P-TMSI, MS ID, ... */ |
Harald Welte | 8a035af | 2010-05-18 10:57:45 +0200 | [diff] [blame] | 531 | return gsm48_gmm_sendmsg(msg, 0, NULL); |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 532 | } |
| 533 | |
| 534 | /* Chapter 9.4.17: Routing area update reject */ |
Harald Welte | d85d9a9 | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 535 | 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] | 536 | { |
| 537 | struct msgb *msg = gsm48_msgb_alloc(); |
| 538 | struct gsm48_hdr *gh; |
| 539 | |
| 540 | DEBUGP(DMM, "<- ROUTING AREA UPDATE REJECT\n"); |
| 541 | |
Harald Welte | 2351f1f | 2010-05-02 11:54:55 +0200 | [diff] [blame] | 542 | gmm_copy_id(msg, old_msg); |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 543 | |
| 544 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 2); |
| 545 | gh->proto_discr = GSM48_PDISC_MM_GPRS; |
| 546 | gh->msg_type = GSM48_MT_GMM_RA_UPD_REJ; |
| 547 | gh->data[0] = cause; |
| 548 | gh->data[1] = 0; /* ? */ |
| 549 | |
| 550 | /* Option: P-TMSI signature, allocated P-TMSI, MS ID, ... */ |
Harald Welte | 8a035af | 2010-05-18 10:57:45 +0200 | [diff] [blame] | 551 | return gsm48_gmm_sendmsg(msg, 0, NULL); |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 552 | } |
| 553 | |
| 554 | /* Chapter 9.4.14: Routing area update request */ |
Harald Welte | c1f6bfe | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 555 | 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] | 556 | { |
Harald Welte | cf3c414 | 2010-04-30 16:33:12 +0200 | [diff] [blame] | 557 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_gmmh(msg); |
Harald Welte | d85d9a9 | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 558 | uint8_t *cur = gh->data; |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 559 | struct gprs_ra_id old_ra_id; |
Harald Welte | d85d9a9 | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 560 | uint8_t upd_type; |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 561 | |
| 562 | /* Update Type 10.5.5.18 */ |
| 563 | upd_type = *cur++ & 0x0f; |
| 564 | |
Harald Welte | 8f77f19 | 2010-05-17 00:44:57 +0200 | [diff] [blame] | 565 | DEBUGP(DMM, "-> GMM RA UPDATE REQUEST type=\"%s\" ", |
| 566 | get_value_string(gprs_upd_t_strs, upd_type)); |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 567 | |
| 568 | /* Old routing area identification 10.5.5.15 */ |
| 569 | gsm48_parse_ra(&old_ra_id, cur); |
| 570 | cur += 6; |
| 571 | |
| 572 | /* MS Radio Access Capability 10.5.5.12a */ |
| 573 | |
| 574 | /* Optional: Old P-TMSI Signature, Requested READY timer, TMSI Status, |
| 575 | * DRX parameter, MS network capability */ |
| 576 | |
| 577 | switch (upd_type) { |
| 578 | case GPRS_UPD_T_RA_LA: |
| 579 | case GPRS_UPD_T_RA_LA_IMSI_ATT: |
| 580 | DEBUGPC(DMM, " unsupported in Mode III, is your SI13 corrupt?\n"); |
| 581 | return gsm48_tx_gmm_ra_upd_rej(msg, GMM_CAUSE_PROTO_ERR_UNSPEC); |
| 582 | break; |
| 583 | case GPRS_UPD_T_RA: |
| 584 | case GPRS_UPD_T_PERIODIC: |
| 585 | break; |
| 586 | } |
| 587 | |
| 588 | /* Look-up the MM context based on old RA-ID and TLLI */ |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 589 | if (!mmctx || mmctx->mm_state == GMM_DEREGISTERED) { |
| 590 | /* The MS has to perform GPRS attach */ |
| 591 | DEBUGPC(DMM, " REJECT\n"); |
| 592 | return gsm48_tx_gmm_ra_upd_rej(msg, GMM_CAUSE_IMPL_DETACHED); |
| 593 | } |
| 594 | |
Harald Welte | de34afa | 2010-05-02 12:56:57 +0200 | [diff] [blame] | 595 | /* Update the MM context with the new RA-ID */ |
| 596 | bssgp_parse_cell_id(&mmctx->ra, msgb_bcid(msg)); |
| 597 | /* Update the MM context with the new TLLI */ |
| 598 | mmctx->tlli = msgb_tlli(msg); |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 599 | /* FIXME: Update the MM context with the MS radio acc capabilities */ |
| 600 | /* FIXME: Update the MM context with the MS network capabilities */ |
| 601 | |
Harald Welte | eb471c9 | 2010-05-18 14:32:29 +0200 | [diff] [blame] | 602 | rate_ctr_inc(&mmctx->ctrg->ctr[GMM_CTR_RA_UPDATE]); |
| 603 | |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 604 | DEBUGPC(DMM, " ACCEPT\n"); |
Harald Welte | 64df8ed | 2010-05-18 17:04:55 +0200 | [diff] [blame] | 605 | return gsm48_tx_gmm_ra_upd_ack(mmctx); |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 606 | } |
| 607 | |
Harald Welte | c1f6bfe | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 608 | 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] | 609 | { |
| 610 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 611 | |
Harald Welte | 8f77f19 | 2010-05-17 00:44:57 +0200 | [diff] [blame] | 612 | DEBUGP(DMM, "-> GPRS MM STATUS (cause: %s)\n", |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 613 | get_value_string(gmm_cause_names, gh->data[0])); |
| 614 | |
| 615 | return 0; |
| 616 | } |
| 617 | |
| 618 | /* GPRS Mobility Management */ |
Harald Welte | c1f6bfe | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 619 | 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] | 620 | { |
Harald Welte | cf3c414 | 2010-04-30 16:33:12 +0200 | [diff] [blame] | 621 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_gmmh(msg); |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 622 | int rc; |
| 623 | |
Harald Welte | c1f6bfe | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 624 | if (!mmctx && |
| 625 | gh->msg_type != GSM48_MT_GMM_ATTACH_REQ && |
Harald Welte | ebe8a6d | 2010-05-18 19:58:38 +0200 | [diff] [blame] | 626 | gh->msg_type != GSM48_MT_GMM_RA_UPD_REQ && |
| 627 | gh->msg_type != GSM48_MT_GMM_ATTACH_COMPL && |
| 628 | gh->msg_type != GSM48_MT_GMM_RA_UPD_COMPL) { |
Harald Welte | c1f6bfe | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 629 | LOGP(DMM, LOGL_NOTICE, "Cannot handle GMM for unknown MM CTX\n"); |
Harald Welte | eb471c9 | 2010-05-18 14:32:29 +0200 | [diff] [blame] | 630 | /* FIXME: Send GMM_CAUSE_IMPL_DETACHED */ |
Harald Welte | c1f6bfe | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 631 | return -EINVAL; |
| 632 | } |
| 633 | |
| 634 | |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 635 | switch (gh->msg_type) { |
| 636 | case GSM48_MT_GMM_RA_UPD_REQ: |
Harald Welte | c1f6bfe | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 637 | rc = gsm48_rx_gmm_ra_upd_req(mmctx, msg); |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 638 | break; |
| 639 | case GSM48_MT_GMM_ATTACH_REQ: |
Harald Welte | c1f6bfe | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 640 | rc = gsm48_rx_gmm_att_req(mmctx, msg); |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 641 | break; |
| 642 | case GSM48_MT_GMM_ID_RESP: |
Harald Welte | c1f6bfe | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 643 | rc = gsm48_rx_gmm_id_resp(mmctx, msg); |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 644 | break; |
| 645 | case GSM48_MT_GMM_STATUS: |
Harald Welte | c1f6bfe | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 646 | rc = gsm48_rx_gmm_status(mmctx, msg); |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 647 | break; |
Harald Welte | 8f77f19 | 2010-05-17 00:44:57 +0200 | [diff] [blame] | 648 | case GSM48_MT_GMM_DETACH_REQ: |
Harald Welte | c1f6bfe | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 649 | rc = gsm48_rx_gmm_det_req(mmctx, msg); |
Harald Welte | 8f77f19 | 2010-05-17 00:44:57 +0200 | [diff] [blame] | 650 | break; |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 651 | case GSM48_MT_GMM_ATTACH_COMPL: |
| 652 | /* only in case SGSN offered new P-TMSI */ |
Harald Welte | ebe8a6d | 2010-05-18 19:58:38 +0200 | [diff] [blame] | 653 | case GSM48_MT_GMM_RA_UPD_COMPL: |
| 654 | /* only in case SGSN offered new P-TMSI */ |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 655 | case GSM48_MT_GMM_PTMSI_REALL_COMPL: |
| 656 | case GSM48_MT_GMM_AUTH_CIPH_RESP: |
| 657 | DEBUGP(DMM, "Unimplemented GSM 04.08 GMM msg type 0x%02x\n", |
| 658 | gh->msg_type); |
Harald Welte | 8f77f19 | 2010-05-17 00:44:57 +0200 | [diff] [blame] | 659 | /* FIXME: Send GMM_CAUSE_MSGT_NOTEXIST_NOTIMPL */ |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 660 | break; |
| 661 | default: |
| 662 | DEBUGP(DMM, "Unknown GSM 04.08 GMM msg type 0x%02x\n", |
| 663 | gh->msg_type); |
Harald Welte | 8f77f19 | 2010-05-17 00:44:57 +0200 | [diff] [blame] | 664 | /* FIXME: Send GMM_CAUSE_MSGT_NOTEXIST_NOTIMPL */ |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 665 | break; |
| 666 | } |
| 667 | |
| 668 | return rc; |
| 669 | } |
| 670 | |
Harald Welte | 2aea749 | 2010-05-02 23:11:50 +0200 | [diff] [blame] | 671 | static void msgb_put_pdp_addr_ipv4(struct msgb *msg, uint32_t ipaddr) |
| 672 | { |
| 673 | uint8_t v[6]; |
| 674 | |
| 675 | v[0] = PDP_TYPE_ORG_IETF; |
| 676 | v[1] = PDP_TYPE_N_IETF_IPv4; |
| 677 | *(uint32_t *)(v+2) = htonl(ipaddr); |
| 678 | |
| 679 | msgb_tlv_put(msg, GSM48_IE_GSM_PDP_ADDR, sizeof(v), v); |
| 680 | } |
| 681 | |
| 682 | static void msgb_put_pdp_addr_ppp(struct msgb *msg) |
| 683 | { |
| 684 | uint8_t v[2]; |
| 685 | |
| 686 | v[0] = PDP_TYPE_ORG_ETSI; |
| 687 | v[1] = PDP_TYPE_N_ETSI_PPP; |
| 688 | |
| 689 | msgb_tlv_put(msg, GSM48_IE_GSM_PDP_ADDR, sizeof(v), v); |
| 690 | } |
| 691 | |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 692 | /* Section 9.5.2: Ativate PDP Context Accept */ |
Harald Welte | 29d838e | 2010-05-18 10:35:06 +0200 | [diff] [blame] | 693 | int gsm48_tx_gsm_act_pdp_acc(struct sgsn_pdp_ctx *pdp) |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 694 | { |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 695 | struct msgb *msg = gsm48_msgb_alloc(); |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 696 | struct gsm48_hdr *gh; |
Harald Welte | 29d838e | 2010-05-18 10:35:06 +0200 | [diff] [blame] | 697 | uint8_t transaction_id = pdp->ti ^ 0x8; /* flip */ |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 698 | |
| 699 | DEBUGP(DMM, "<- ACTIVATE PDP CONTEXT ACK\n"); |
| 700 | |
Harald Welte | 29d838e | 2010-05-18 10:35:06 +0200 | [diff] [blame] | 701 | mmctx2msgid(msg, pdp->mm); |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 702 | |
| 703 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 704 | gh->proto_discr = GSM48_PDISC_SM_GPRS | (transaction_id << 4); |
| 705 | gh->msg_type = GSM48_MT_GSM_ACT_PDP_ACK; |
Harald Welte | 2aea749 | 2010-05-02 23:11:50 +0200 | [diff] [blame] | 706 | |
| 707 | /* Negotiated LLC SAPI */ |
Harald Welte | 29d838e | 2010-05-18 10:35:06 +0200 | [diff] [blame] | 708 | msgb_v_put(msg, pdp->sapi); |
Harald Welte | 7d7fd2b | 2010-05-18 14:51:18 +0200 | [diff] [blame] | 709 | |
Harald Welte | 540dcbc | 2010-05-18 13:20:08 +0200 | [diff] [blame] | 710 | /* FIXME: copy QoS parameters from original request */ |
| 711 | //msgb_lv_put(msg, pdp->lib->qos_neg.l, pdp->lib->qos_neg.v); |
| 712 | msgb_lv_put(msg, sizeof(default_qos), (uint8_t *)&default_qos); |
Harald Welte | 7d7fd2b | 2010-05-18 14:51:18 +0200 | [diff] [blame] | 713 | |
Harald Welte | 2aea749 | 2010-05-02 23:11:50 +0200 | [diff] [blame] | 714 | /* Radio priority 10.5.7.2 */ |
Harald Welte | 29d838e | 2010-05-18 10:35:06 +0200 | [diff] [blame] | 715 | msgb_v_put(msg, pdp->lib->radio_pri); |
Harald Welte | 7d7fd2b | 2010-05-18 14:51:18 +0200 | [diff] [blame] | 716 | |
Harald Welte | 2aea749 | 2010-05-02 23:11:50 +0200 | [diff] [blame] | 717 | /* PDP address */ |
Harald Welte | 7d7fd2b | 2010-05-18 14:51:18 +0200 | [diff] [blame] | 718 | /* Highest 4 bits of first byte need to be set to 1, otherwise |
| 719 | * the IE is identical with the 04.08 PDP Address IE */ |
| 720 | pdp->lib->eua.v[0] &= ~0xf0; |
Harald Welte | 29d838e | 2010-05-18 10:35:06 +0200 | [diff] [blame] | 721 | msgb_tlv_put(msg, GSM48_IE_GSM_PDP_ADDR, |
| 722 | pdp->lib->eua.l, pdp->lib->eua.v); |
Harald Welte | 7d7fd2b | 2010-05-18 14:51:18 +0200 | [diff] [blame] | 723 | pdp->lib->eua.v[0] |= 0xf0; |
| 724 | |
Harald Welte | eb471c9 | 2010-05-18 14:32:29 +0200 | [diff] [blame] | 725 | /* Optional: Protocol configuration options (FIXME: why 'req') */ |
| 726 | if (pdp->lib->pco_req.l && pdp->lib->pco_req.v) |
Harald Welte | 29d838e | 2010-05-18 10:35:06 +0200 | [diff] [blame] | 727 | msgb_tlv_put(msg, GSM48_IE_GSM_PROTO_CONF_OPT, |
Harald Welte | f2d6658 | 2010-05-18 14:36:11 +0200 | [diff] [blame] | 728 | pdp->lib->pco_req.l, pdp->lib->pco_req.v); |
Harald Welte | 7d7fd2b | 2010-05-18 14:51:18 +0200 | [diff] [blame] | 729 | |
Harald Welte | 2aea749 | 2010-05-02 23:11:50 +0200 | [diff] [blame] | 730 | /* Optional: Packet Flow Identifier */ |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 731 | |
Harald Welte | 8a035af | 2010-05-18 10:57:45 +0200 | [diff] [blame] | 732 | return gsm48_gmm_sendmsg(msg, 0, pdp->mm); |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 733 | } |
| 734 | |
Harald Welte | 29d838e | 2010-05-18 10:35:06 +0200 | [diff] [blame] | 735 | /* Section 9.5.3: Activate PDP Context reject */ |
| 736 | int gsm48_tx_gsm_act_pdp_rej(struct sgsn_mm_ctx *mm, uint8_t tid, |
| 737 | uint8_t cause, uint8_t pco_len, uint8_t *pco_v) |
| 738 | { |
| 739 | struct msgb *msg = gsm48_msgb_alloc(); |
Harald Welte | 29d838e | 2010-05-18 10:35:06 +0200 | [diff] [blame] | 740 | struct gsm48_hdr *gh; |
| 741 | uint8_t transaction_id = tid ^ 0x8; /* flip */ |
| 742 | |
Harald Welte | eb471c9 | 2010-05-18 14:32:29 +0200 | [diff] [blame] | 743 | DEBUGP(DMM, "<- ACTIVATE PDP CONTEXT REJ(cause=%u)\n", cause); |
Harald Welte | 29d838e | 2010-05-18 10:35:06 +0200 | [diff] [blame] | 744 | |
| 745 | mmctx2msgid(msg, mm); |
| 746 | |
| 747 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 748 | gh->proto_discr = GSM48_PDISC_SM_GPRS | (transaction_id << 4); |
| 749 | gh->msg_type = GSM48_MT_GSM_ACT_PDP_REJ; |
| 750 | |
| 751 | msgb_v_put(msg, cause); |
| 752 | if (pco_len && pco_v) |
| 753 | msgb_tlv_put(msg, GSM48_IE_GSM_PROTO_CONF_OPT, pco_len, pco_v); |
| 754 | |
Harald Welte | 8a035af | 2010-05-18 10:57:45 +0200 | [diff] [blame] | 755 | return gsm48_gmm_sendmsg(msg, 0, mm); |
Harald Welte | 29d838e | 2010-05-18 10:35:06 +0200 | [diff] [blame] | 756 | } |
| 757 | |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 758 | /* Section 9.5.9: Deactivate PDP Context Accept */ |
Harald Welte | eb471c9 | 2010-05-18 14:32:29 +0200 | [diff] [blame] | 759 | int gsm48_tx_gsm_deact_pdp_acc(struct sgsn_pdp_ctx *pdp) |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 760 | { |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 761 | struct msgb *msg = gsm48_msgb_alloc(); |
| 762 | struct gsm48_hdr *gh; |
Harald Welte | eb471c9 | 2010-05-18 14:32:29 +0200 | [diff] [blame] | 763 | uint8_t transaction_id = pdp->ti ^ 0x8; /* flip */ |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 764 | |
| 765 | DEBUGP(DMM, "<- DEACTIVATE PDP CONTEXT ACK\n"); |
| 766 | |
Harald Welte | eb471c9 | 2010-05-18 14:32:29 +0200 | [diff] [blame] | 767 | mmctx2msgid(msg, pdp->mm); |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 768 | |
| 769 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 770 | gh->proto_discr = GSM48_PDISC_SM_GPRS | (transaction_id << 4); |
| 771 | gh->msg_type = GSM48_MT_GSM_DEACT_PDP_ACK; |
| 772 | |
Harald Welte | eb471c9 | 2010-05-18 14:32:29 +0200 | [diff] [blame] | 773 | return gsm48_gmm_sendmsg(msg, 0, pdp->mm); |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 774 | } |
| 775 | |
| 776 | /* Section 9.5.1: Activate PDP Context Request */ |
Harald Welte | c1f6bfe | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 777 | static int gsm48_rx_gsm_act_pdp_req(struct sgsn_mm_ctx *mmctx, |
| 778 | struct msgb *msg) |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 779 | { |
Harald Welte | cf3c414 | 2010-04-30 16:33:12 +0200 | [diff] [blame] | 780 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_gmmh(msg); |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 781 | struct gsm48_act_pdp_ctx_req *act_req = (struct gsm48_act_pdp_ctx_req *) gh->data; |
Harald Welte | b1fd23a | 2010-05-02 21:07:14 +0200 | [diff] [blame] | 782 | uint8_t req_qos_len, req_pdpa_len; |
| 783 | uint8_t *req_qos, *req_pdpa; |
| 784 | struct tlv_parsed tp; |
Harald Welte | 29d838e | 2010-05-18 10:35:06 +0200 | [diff] [blame] | 785 | uint8_t transaction_id = (gh->proto_discr >> 4); |
| 786 | struct sgsn_pdp_ctx *pdp; |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 787 | |
Harald Welte | ebe8a6d | 2010-05-18 19:58:38 +0200 | [diff] [blame] | 788 | memset(&tp, 0, sizeof(tp)); |
| 789 | |
Harald Welte | 29d838e | 2010-05-18 10:35:06 +0200 | [diff] [blame] | 790 | DEBUGP(DMM, "-> ACTIVATE PDP CONTEXT REQ: SAPI=%u NSAPI=%u ", |
| 791 | act_req->req_llc_sapi, act_req->req_nsapi); |
Harald Welte | 8a035af | 2010-05-18 10:57:45 +0200 | [diff] [blame] | 792 | |
| 793 | rate_ctr_inc(&mmctx->ctrg->ctr[GMM_CTR_PDP_CTX_ACT]); |
| 794 | |
Harald Welte | b1fd23a | 2010-05-02 21:07:14 +0200 | [diff] [blame] | 795 | req_qos_len = act_req->data[0]; |
| 796 | req_qos = act_req->data + 1; /* 10.5.6.5 */ |
| 797 | req_pdpa_len = act_req->data[1 + req_qos_len]; |
| 798 | 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] | 799 | |
Harald Welte | b1fd23a | 2010-05-02 21:07:14 +0200 | [diff] [blame] | 800 | switch (req_pdpa[0] & 0xf) { |
| 801 | case 0x0: |
| 802 | DEBUGPC(DMM, "ETSI "); |
| 803 | break; |
| 804 | case 0x1: |
| 805 | DEBUGPC(DMM, "IETF "); |
| 806 | break; |
| 807 | case 0xf: |
| 808 | DEBUGPC(DMM, "Empty "); |
| 809 | break; |
| 810 | } |
| 811 | |
| 812 | switch (req_pdpa[1]) { |
| 813 | case 0x21: |
| 814 | DEBUGPC(DMM, "IPv4 "); |
| 815 | if (req_pdpa_len >= 6) { |
| 816 | struct in_addr ia; |
| 817 | ia.s_addr = ntohl(*((uint32_t *) (req_pdpa+2))); |
| 818 | DEBUGPC(DMM, "%s ", inet_ntoa(ia)); |
| 819 | } |
| 820 | break; |
| 821 | case 0x57: |
| 822 | DEBUGPC(DMM, "IPv6 "); |
| 823 | if (req_pdpa_len >= 18) { |
| 824 | /* FIXME: print IPv6 address */ |
| 825 | } |
| 826 | break; |
| 827 | default: |
| 828 | DEBUGPC(DMM, "0x%02x ", req_pdpa[1]); |
| 829 | break; |
| 830 | } |
| 831 | |
Harald Welte | eb471c9 | 2010-05-18 14:32:29 +0200 | [diff] [blame] | 832 | DEBUGPC(DMM, "\n"); |
| 833 | |
Harald Welte | 8f77f19 | 2010-05-17 00:44:57 +0200 | [diff] [blame] | 834 | /* put the non-TLV elements in the TLV parser structure to |
| 835 | * pass them on to the SGSN / GTP code */ |
| 836 | tp.lv[OSMO_IE_GSM_REQ_QOS].len = req_qos_len; |
| 837 | tp.lv[OSMO_IE_GSM_REQ_QOS].val = req_qos; |
| 838 | tp.lv[OSMO_IE_GSM_REQ_PDP_ADDR].len = req_pdpa_len; |
| 839 | tp.lv[OSMO_IE_GSM_REQ_PDP_ADDR].val = req_pdpa; |
| 840 | |
Harald Welte | 29d838e | 2010-05-18 10:35:06 +0200 | [diff] [blame] | 841 | /* FIXME: determine GGSN based on APN and subscription options */ |
Harald Welte | b1fd23a | 2010-05-02 21:07:14 +0200 | [diff] [blame] | 842 | if (TLVP_PRESENT(&tp, GSM48_IE_GSM_APN)) {} |
Harald Welte | 29d838e | 2010-05-18 10:35:06 +0200 | [diff] [blame] | 843 | |
| 844 | /* Check if NSAPI is out of range (TS 04.65 / 7.2) */ |
| 845 | if (act_req->req_nsapi < 5 || act_req->req_nsapi > 15) { |
| 846 | /* Send reject with GSM_CAUSE_INV_MAND_INFO */ |
| 847 | return gsm48_tx_gsm_act_pdp_rej(mmctx, transaction_id, |
| 848 | GSM_CAUSE_INV_MAND_INFO, |
| 849 | 0, NULL); |
| 850 | } |
| 851 | |
| 852 | /* Check if NSAPI is already in use */ |
| 853 | if (sgsn_pdp_ctx_by_nsapi(mmctx, act_req->req_nsapi)) { |
| 854 | /* FIXME: send reject with GSM_CAUSE_NSAPI_IN_USE */ |
| 855 | return gsm48_tx_gsm_act_pdp_rej(mmctx, transaction_id, |
| 856 | GSM_CAUSE_NSAPI_IN_USE, |
| 857 | 0, NULL); |
| 858 | } |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 859 | |
Harald Welte | c1f6bfe | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 860 | #if 1 |
| 861 | { |
Harald Welte | ebe8a6d | 2010-05-18 19:58:38 +0200 | [diff] [blame] | 862 | struct sgsn_ggsn_ctx *ggsn = sgsn_ggsn_ctx_by_id(0); |
| 863 | if (!ggsn) { |
| 864 | LOGP(DGPRS, LOGL_ERROR, "No GGSN context 0 found!\n"); |
| 865 | return -EIO; |
| 866 | } |
| 867 | ggsn->gsn = sgsn->gsn; |
| 868 | pdp = sgsn_create_pdp_ctx(ggsn, mmctx, act_req->req_nsapi, &tp); |
Harald Welte | 29d838e | 2010-05-18 10:35:06 +0200 | [diff] [blame] | 869 | if (!pdp) |
| 870 | return -1; |
| 871 | pdp->sapi = act_req->req_llc_sapi; |
| 872 | pdp->ti = transaction_id; |
| 873 | |
Harald Welte | c1f6bfe | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 874 | } |
Harald Welte | 64df8ed | 2010-05-18 17:04:55 +0200 | [diff] [blame] | 875 | return 0; |
Harald Welte | 8f77f19 | 2010-05-17 00:44:57 +0200 | [diff] [blame] | 876 | #else |
Harald Welte | 29d838e | 2010-05-18 10:35:06 +0200 | [diff] [blame] | 877 | return gsm48_tx_gsm_act_pdp_acc(mmctx, transaction_id, act_req); |
Harald Welte | 8f77f19 | 2010-05-17 00:44:57 +0200 | [diff] [blame] | 878 | #endif |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 879 | } |
| 880 | |
| 881 | /* Section 9.5.8: Deactivate PDP Context Request */ |
Harald Welte | eb471c9 | 2010-05-18 14:32:29 +0200 | [diff] [blame] | 882 | static int gsm48_rx_gsm_deact_pdp_req(struct sgsn_mm_ctx *mm, struct msgb *msg) |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 883 | { |
Harald Welte | cf3c414 | 2010-04-30 16:33:12 +0200 | [diff] [blame] | 884 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_gmmh(msg); |
Harald Welte | eb471c9 | 2010-05-18 14:32:29 +0200 | [diff] [blame] | 885 | uint8_t transaction_id = (gh->proto_discr >> 4); |
| 886 | struct sgsn_pdp_ctx *pdp; |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 887 | |
Harald Welte | 8f77f19 | 2010-05-17 00:44:57 +0200 | [diff] [blame] | 888 | DEBUGP(DMM, "-> DEACTIVATE PDP CONTEXT REQ (cause: %s)\n", |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 889 | get_value_string(gsm_cause_names, gh->data[0])); |
| 890 | |
Harald Welte | eb471c9 | 2010-05-18 14:32:29 +0200 | [diff] [blame] | 891 | pdp = sgsn_pdp_ctx_by_tid(mm, transaction_id); |
| 892 | if (!pdp) { |
| 893 | LOGP(DMM, LOGL_NOTICE, "Deactivate PDP Context Request for " |
| 894 | "non-existing PDP Context (IMSI=%s, TI=%u)\n", |
| 895 | mm->imsi, transaction_id); |
| 896 | return -EINVAL; |
| 897 | } |
| 898 | |
| 899 | return sgsn_delete_pdp_ctx(pdp); |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 900 | } |
| 901 | |
Harald Welte | c1f6bfe | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 902 | 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] | 903 | { |
| 904 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 905 | |
Harald Welte | 8f77f19 | 2010-05-17 00:44:57 +0200 | [diff] [blame] | 906 | DEBUGP(DMM, "-> GPRS SM STATUS (cause: %s)\n", |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 907 | get_value_string(gsm_cause_names, gh->data[0])); |
| 908 | |
| 909 | return 0; |
| 910 | } |
| 911 | |
| 912 | /* GPRS Session Management */ |
Harald Welte | c1f6bfe | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 913 | 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] | 914 | { |
Harald Welte | cf3c414 | 2010-04-30 16:33:12 +0200 | [diff] [blame] | 915 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_gmmh(msg); |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 916 | int rc; |
| 917 | |
Harald Welte | c1f6bfe | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 918 | if (!mmctx) { |
| 919 | LOGP(DMM, LOGL_NOTICE, "Cannot handle SM for unknown MM CTX\n"); |
Harald Welte | a890573 | 2010-05-30 20:28:22 +0200 | [diff] [blame] | 920 | /* FIXME: return SM / MM STATUS */ |
Harald Welte | c1f6bfe | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 921 | return -EINVAL; |
| 922 | } |
| 923 | |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 924 | switch (gh->msg_type) { |
| 925 | case GSM48_MT_GSM_ACT_PDP_REQ: |
Harald Welte | c1f6bfe | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 926 | rc = gsm48_rx_gsm_act_pdp_req(mmctx, msg); |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 927 | break; |
| 928 | case GSM48_MT_GSM_DEACT_PDP_REQ: |
Harald Welte | c1f6bfe | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 929 | rc = gsm48_rx_gsm_deact_pdp_req(mmctx, msg); |
Harald Welte | eb471c9 | 2010-05-18 14:32:29 +0200 | [diff] [blame] | 930 | break; |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 931 | case GSM48_MT_GSM_STATUS: |
Harald Welte | c1f6bfe | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 932 | rc = gsm48_rx_gsm_status(mmctx, msg); |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 933 | break; |
| 934 | case GSM48_MT_GSM_REQ_PDP_ACT_REJ: |
| 935 | case GSM48_MT_GSM_ACT_AA_PDP_REQ: |
| 936 | case GSM48_MT_GSM_DEACT_AA_PDP_REQ: |
| 937 | DEBUGP(DMM, "Unimplemented GSM 04.08 GSM msg type 0x%02x\n", |
| 938 | gh->msg_type); |
Harald Welte | a890573 | 2010-05-30 20:28:22 +0200 | [diff] [blame] | 939 | /* FIXME: return SM / MM STATUS */ |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 940 | break; |
| 941 | default: |
| 942 | DEBUGP(DMM, "Unknown GSM 04.08 GSM msg type 0x%02x\n", |
| 943 | gh->msg_type); |
Harald Welte | a890573 | 2010-05-30 20:28:22 +0200 | [diff] [blame] | 944 | /* FIXME: return SM / MM STATUS */ |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 945 | break; |
| 946 | |
| 947 | } |
| 948 | |
| 949 | return rc; |
| 950 | } |
| 951 | |
| 952 | /* Main entry point for incoming 04.08 GPRS messages */ |
| 953 | int gsm0408_gprs_rcvmsg(struct msgb *msg) |
| 954 | { |
Harald Welte | cf3c414 | 2010-04-30 16:33:12 +0200 | [diff] [blame] | 955 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_gmmh(msg); |
Harald Welte | d85d9a9 | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 956 | uint8_t pdisc = gh->proto_discr & 0x0f; |
Harald Welte | c1f6bfe | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 957 | struct sgsn_mm_ctx *mmctx; |
| 958 | struct gprs_ra_id ra_id; |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 959 | int rc = -EINVAL; |
| 960 | |
Harald Welte | c1f6bfe | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 961 | bssgp_parse_cell_id(&ra_id, msgb_bcid(msg)); |
| 962 | mmctx = sgsn_mm_ctx_by_tlli(msgb_tlli(msg), &ra_id); |
Harald Welte | 8a035af | 2010-05-18 10:57:45 +0200 | [diff] [blame] | 963 | if (mmctx) { |
Harald Welte | 29d838e | 2010-05-18 10:35:06 +0200 | [diff] [blame] | 964 | msgid2mmctx(mmctx, msg); |
Harald Welte | 8a035af | 2010-05-18 10:57:45 +0200 | [diff] [blame] | 965 | rate_ctr_inc(&mmctx->ctrg->ctr[GMM_CTR_PKTS_SIG_IN]); |
| 966 | } |
Harald Welte | c1f6bfe | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 967 | |
| 968 | /* MMCTX can be NULL */ |
| 969 | |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 970 | switch (pdisc) { |
| 971 | case GSM48_PDISC_MM_GPRS: |
Harald Welte | c1f6bfe | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 972 | rc = gsm0408_rcv_gmm(mmctx, msg); |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 973 | break; |
| 974 | case GSM48_PDISC_SM_GPRS: |
Harald Welte | c1f6bfe | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 975 | rc = gsm0408_rcv_gsm(mmctx, msg); |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 976 | break; |
| 977 | default: |
| 978 | DEBUGP(DMM, "Unknown GSM 04.08 discriminator 0x%02x\n", |
| 979 | pdisc); |
Harald Welte | 29d838e | 2010-05-18 10:35:06 +0200 | [diff] [blame] | 980 | /* FIXME: return status message */ |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 981 | break; |
| 982 | } |
| 983 | |
| 984 | return rc; |
| 985 | } |