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