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