Neels Hofmeyr | 17518fe | 2017-06-20 04:35:06 +0200 | [diff] [blame] | 1 | /*! \file gsm_04_08_gprs.c */ |
| 2 | /* |
| 3 | * (C) 2009-2016 by Harald Welte <laforge@gnumonks.org> |
Harald Welte | 64f38c0 | 2016-04-20 17:12:24 +0200 | [diff] [blame] | 4 | * (C) 2010 by On-Waves |
Harald Welte | e08da97 | 2017-11-13 01:00:26 +0900 | [diff] [blame] | 5 | * (C) 2014-2015 by sysmocom - s.f.m.c. GmbH |
Harald Welte | 64f38c0 | 2016-04-20 17:12:24 +0200 | [diff] [blame] | 6 | * |
| 7 | * All Rights Reserved |
| 8 | * |
Harald Welte | e08da97 | 2017-11-13 01:00:26 +0900 | [diff] [blame] | 9 | * SPDX-License-Identifier: GPL-2.0+ |
| 10 | * |
Harald Welte | 64f38c0 | 2016-04-20 17:12:24 +0200 | [diff] [blame] | 11 | * This program is free software; you can redistribute it and/or modify |
Harald Welte | 5e5954d | 2016-12-22 14:57:13 +0100 | [diff] [blame] | 12 | * it under the terms of the GNU General Public License as published by |
| 13 | * the Free Software Foundation; either version 2 of the License, or |
Harald Welte | 64f38c0 | 2016-04-20 17:12:24 +0200 | [diff] [blame] | 14 | * (at your option) any later version. |
| 15 | * |
| 16 | * This program is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
Harald Welte | 5e5954d | 2016-12-22 14:57:13 +0100 | [diff] [blame] | 19 | * GNU General Public License for more details. |
Harald Welte | 64f38c0 | 2016-04-20 17:12:24 +0200 | [diff] [blame] | 20 | * |
Harald Welte | 5e5954d | 2016-12-22 14:57:13 +0100 | [diff] [blame] | 21 | * You should have received a copy of the GNU General Public License |
Harald Welte | 64f38c0 | 2016-04-20 17:12:24 +0200 | [diff] [blame] | 22 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 23 | * |
| 24 | */ |
| 25 | |
| 26 | |
| 27 | #include <osmocom/gsm/protocol/gsm_04_08_gprs.h> |
Max | a337b9c | 2016-06-27 15:51:34 +0200 | [diff] [blame] | 28 | #include <osmocom/crypt/gprs_cipher.h> |
Harald Welte | 64f38c0 | 2016-04-20 17:12:24 +0200 | [diff] [blame] | 29 | #include <osmocom/core/utils.h> |
| 30 | |
Max | a337b9c | 2016-06-27 15:51:34 +0200 | [diff] [blame] | 31 | #include <stdbool.h> |
| 32 | |
Harald Welte | 96e2a00 | 2017-06-12 21:44:18 +0200 | [diff] [blame] | 33 | /*! \addtogroup gsm0408 |
| 34 | * @{ |
| 35 | */ |
Harald Welte | 64f38c0 | 2016-04-20 17:12:24 +0200 | [diff] [blame] | 36 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 37 | /*! 10.5.5.14 GPRS MM Cause / Table 10.5.147 */ |
Harald Welte | 64f38c0 | 2016-04-20 17:12:24 +0200 | [diff] [blame] | 38 | const struct value_string gsm48_gmm_cause_names_[] = { |
| 39 | { GMM_CAUSE_IMSI_UNKNOWN, "IMSI unknown in HLR" }, |
| 40 | { GMM_CAUSE_ILLEGAL_MS, "Illegal MS" }, |
Harald Welte | 82f94ef | 2016-05-05 23:33:27 +0200 | [diff] [blame] | 41 | { GMM_CAUSE_IMEI_NOT_ACCEPTED, "IMEI not accepted" }, |
Harald Welte | 64f38c0 | 2016-04-20 17:12:24 +0200 | [diff] [blame] | 42 | { GMM_CAUSE_ILLEGAL_ME, "Illegal ME" }, |
| 43 | { GMM_CAUSE_GPRS_NOTALLOWED, "GPRS services not allowed" }, |
| 44 | { GMM_CAUSE_GPRS_OTHER_NOTALLOWED, |
| 45 | "GPRS services and non-GPRS services not allowed" }, |
| 46 | { GMM_CAUSE_MS_ID_NOT_DERIVED, |
| 47 | "MS identity cannot be derived by the network" }, |
| 48 | { GMM_CAUSE_IMPL_DETACHED, "Implicitly detached" }, |
| 49 | { GMM_CAUSE_PLMN_NOTALLOWED, "PLMN not allowed" }, |
| 50 | { GMM_CAUSE_LA_NOTALLOWED, "Location Area not allowed" }, |
| 51 | { GMM_CAUSE_ROAMING_NOTALLOWED, |
| 52 | "Roaming not allowed in this location area" }, |
| 53 | { GMM_CAUSE_NO_GPRS_PLMN, |
| 54 | "GPRS services not allowed in this PLMN" }, |
Harald Welte | 82f94ef | 2016-05-05 23:33:27 +0200 | [diff] [blame] | 55 | { GMM_CAUSE_NO_SUIT_CELL_IN_LA, "No suitable cell in LA" }, |
Harald Welte | 64f38c0 | 2016-04-20 17:12:24 +0200 | [diff] [blame] | 56 | { GMM_CAUSE_MSC_TEMP_NOTREACH, "MSC temporarily not reachable" }, |
| 57 | { GMM_CAUSE_NET_FAIL, "Network failure" }, |
Harald Welte | 82f94ef | 2016-05-05 23:33:27 +0200 | [diff] [blame] | 58 | { GMM_CAUSE_MAC_FAIL, "MAC failure" }, |
| 59 | { GMM_CAUSE_SYNC_FAIL, "SYNC failure" }, |
Harald Welte | 64f38c0 | 2016-04-20 17:12:24 +0200 | [diff] [blame] | 60 | { GMM_CAUSE_CONGESTION, "Congestion" }, |
Harald Welte | 82f94ef | 2016-05-05 23:33:27 +0200 | [diff] [blame] | 61 | { GMM_CAUSE_GSM_AUTH_UNACCEPT, "GSM authentication unacceptable" }, |
| 62 | { GMM_CAUSE_NOT_AUTH_FOR_CSG, "Not authorized for this CSG" }, |
| 63 | { GMM_CAUSE_SMS_VIA_GPRS_IN_RA, "SMS provided via GPRS in this RA" }, |
| 64 | { GMM_CAUSE_NO_PDP_ACTIVATED, "No PDP context activated" }, |
Harald Welte | 64f38c0 | 2016-04-20 17:12:24 +0200 | [diff] [blame] | 65 | { GMM_CAUSE_SEM_INCORR_MSG, "Semantically incorrect message" }, |
| 66 | { GMM_CAUSE_INV_MAND_INFO, "Invalid mandatory information" }, |
| 67 | { GMM_CAUSE_MSGT_NOTEXIST_NOTIMPL, |
Vadim Yanitskiy | 65954ba | 2020-10-29 18:08:52 +0700 | [diff] [blame] | 68 | "Message type non-existent or not implemented" }, |
Harald Welte | 64f38c0 | 2016-04-20 17:12:24 +0200 | [diff] [blame] | 69 | { GMM_CAUSE_MSGT_INCOMP_P_STATE, |
| 70 | "Message type not compatible with protocol state" }, |
| 71 | { GMM_CAUSE_IE_NOTEXIST_NOTIMPL, |
| 72 | "Information element non-existent or not implemented" }, |
| 73 | { GMM_CAUSE_COND_IE_ERR, "Conditional IE error" }, |
| 74 | { GMM_CAUSE_MSG_INCOMP_P_STATE, |
| 75 | "Message not compatible with protocol state " }, |
| 76 | { GMM_CAUSE_PROTO_ERR_UNSPEC, "Protocol error, unspecified" }, |
| 77 | { 0, NULL } |
| 78 | }; |
| 79 | |
| 80 | const struct value_string *gsm48_gmm_cause_names = gsm48_gmm_cause_names_; |
| 81 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 82 | /*! 10.5.6.6 SM Cause / Table 10.5.157 */ |
Harald Welte | 64f38c0 | 2016-04-20 17:12:24 +0200 | [diff] [blame] | 83 | const struct value_string gsm48_gsm_cause_names_[] = { |
Daniel Willmann | 6959e3c | 2017-05-12 11:20:53 +0200 | [diff] [blame] | 84 | { GSM_CAUSE_OPER_DET_BARR, "Operator Determined Barring" }, |
| 85 | { GSM_CAUSE_MBMS_CAP_INSUF, "MBMS bearer capabilities insufficient for the service" }, |
| 86 | { GSM_CAUSE_LLC_SNDCP_FAIL, "LLC or SNDCP failure" }, |
Harald Welte | 64f38c0 | 2016-04-20 17:12:24 +0200 | [diff] [blame] | 87 | { GSM_CAUSE_INSUFF_RSRC, "Insufficient resources" }, |
| 88 | { GSM_CAUSE_MISSING_APN, "Missing or unknown APN" }, |
| 89 | { GSM_CAUSE_UNKNOWN_PDP, "Unknown PDP address or PDP type" }, |
| 90 | { GSM_CAUSE_AUTH_FAILED, "User Authentication failed" }, |
| 91 | { GSM_CAUSE_ACT_REJ_GGSN, "Activation rejected by GGSN" }, |
| 92 | { GSM_CAUSE_ACT_REJ_UNSPEC, "Activation rejected, unspecified" }, |
| 93 | { GSM_CAUSE_SERV_OPT_NOTSUPP, "Service option not supported" }, |
| 94 | { GSM_CAUSE_REQ_SERV_OPT_NOTSUB, |
| 95 | "Requested service option not subscribed" }, |
| 96 | { GSM_CAUSE_SERV_OPT_TEMP_OOO, |
| 97 | "Service option temporarily out of order" }, |
| 98 | { GSM_CAUSE_NSAPI_IN_USE, "NSAPI already used" }, |
| 99 | { GSM_CAUSE_DEACT_REGULAR, "Regular deactivation" }, |
| 100 | { GSM_CAUSE_QOS_NOT_ACCEPTED, "QoS not accepted" }, |
| 101 | { GSM_CAUSE_NET_FAIL, "Network Failure" }, |
| 102 | { GSM_CAUSE_REACT_RQD, "Reactivation required" }, |
| 103 | { GSM_CAUSE_FEATURE_NOTSUPP, "Feature not supported " }, |
| 104 | { GSM_CAUSE_INVALID_TRANS_ID, "Invalid transaction identifier" }, |
| 105 | { GSM_CAUSE_SEM_INCORR_MSG, "Semantically incorrect message" }, |
| 106 | { GSM_CAUSE_INV_MAND_INFO, "Invalid mandatory information" }, |
| 107 | { GSM_CAUSE_MSGT_NOTEXIST_NOTIMPL, |
Vadim Yanitskiy | 65954ba | 2020-10-29 18:08:52 +0700 | [diff] [blame] | 108 | "Message type non-existent or not implemented" }, |
Harald Welte | 64f38c0 | 2016-04-20 17:12:24 +0200 | [diff] [blame] | 109 | { GSM_CAUSE_MSGT_INCOMP_P_STATE, |
| 110 | "Message type not compatible with protocol state" }, |
| 111 | { GSM_CAUSE_IE_NOTEXIST_NOTIMPL, |
| 112 | "Information element non-existent or not implemented" }, |
| 113 | { GSM_CAUSE_COND_IE_ERR, "Conditional IE error" }, |
| 114 | { GSM_CAUSE_MSG_INCOMP_P_STATE, |
| 115 | "Message not compatible with protocol state " }, |
| 116 | { GSM_CAUSE_PROTO_ERR_UNSPEC, "Protocol error, unspecified" }, |
| 117 | { 0, NULL } |
| 118 | }; |
| 119 | |
| 120 | const struct value_string *gsm48_gsm_cause_names = gsm48_gsm_cause_names_; |
| 121 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 122 | /*! Check if MS supports particular version of GEA by inspecting |
Max | a337b9c | 2016-06-27 15:51:34 +0200 | [diff] [blame] | 123 | * MS network capability IE specified in 3GPP TS 24.008 |
| 124 | * \param[in] ms_net_cap Buffer with raw MS network capability IE value, |
| 125 | * 3 - 10 bytes |
| 126 | * \param[in] cap_len Length of ms_net_cap, in bytes |
| 127 | * \param[in] gea Version of GEA to check |
| 128 | * \returns true if given version is supported by MS, false otherwise |
| 129 | */ |
| 130 | bool gprs_ms_net_cap_gea_supported(const uint8_t *ms_net_cap, uint8_t cap_len, |
| 131 | enum gprs_ciph_algo gea) |
| 132 | { |
| 133 | switch (gea) { |
| 134 | case GPRS_ALGO_GEA0: |
| 135 | return true; |
| 136 | case GPRS_ALGO_GEA1: /* 1st bit is GEA1: */ |
| 137 | return 0x80 & ms_net_cap[0]; |
| 138 | case GPRS_ALGO_GEA2: /* extended GEA bits start from 2nd bit */ |
| 139 | return 0x40 & ms_net_cap[1]; /* of the next byte */ |
| 140 | case GPRS_ALGO_GEA3: |
| 141 | return 0x20 & ms_net_cap[1]; |
| 142 | case GPRS_ALGO_GEA4: |
| 143 | return 0x10 & ms_net_cap[1]; |
| 144 | default: |
| 145 | return false; |
| 146 | } |
| 147 | } |
| 148 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 149 | /*! String names of GMM message types */ |
Max | f5f773f | 2016-07-05 19:17:19 +0200 | [diff] [blame] | 150 | const struct value_string gprs_msgt_gmm_names[] = { |
| 151 | { GSM48_MT_GMM_ATTACH_REQ, "ATTACH REQUEST" }, |
| 152 | { GSM48_MT_GMM_ATTACH_ACK, "ATTACH ACK" }, |
| 153 | { GSM48_MT_GMM_ATTACH_COMPL, "ATTACH COMPLETE" }, |
| 154 | { GSM48_MT_GMM_ATTACH_REJ, "ATTACH REJECT" }, |
| 155 | { GSM48_MT_GMM_DETACH_REQ, "DETACH REQUEST" }, |
| 156 | { GSM48_MT_GMM_DETACH_ACK, "DETACH ACK" }, |
| 157 | { GSM48_MT_GMM_RA_UPD_REQ, "RA UPDATE REQUEST" }, |
| 158 | { GSM48_MT_GMM_RA_UPD_ACK, "RA UPDATE ACK" }, |
| 159 | { GSM48_MT_GMM_RA_UPD_COMPL, "RA UPDATE COMPLETE" }, |
| 160 | { GSM48_MT_GMM_RA_UPD_REJ, "RA UPDATE REJECT" }, |
| 161 | { GSM48_MT_GMM_PTMSI_REALL_CMD, "PTMSI REALLOC CMD" }, |
| 162 | { GSM48_MT_GMM_PTMSI_REALL_COMPL, "PTMSI REALLOC COMPLETE" }, |
| 163 | { GSM48_MT_GMM_AUTH_CIPH_REQ, "AUTH & CIPHER REQUEST" }, |
| 164 | { GSM48_MT_GMM_AUTH_CIPH_RESP, "AUTH & CIPHER RESPONSE" }, |
| 165 | { GSM48_MT_GMM_AUTH_CIPH_REJ, "AUTH & CIPHER REJECT" }, |
| 166 | { GSM48_MT_GMM_AUTH_CIPH_FAIL, "AUTH & CIPHER FAILURE" }, |
| 167 | { GSM48_MT_GMM_ID_REQ, "IDENTITY REQUEST" }, |
| 168 | { GSM48_MT_GMM_ID_RESP, "IDENTITY RESPONSE" }, |
| 169 | { GSM48_MT_GMM_STATUS, "STATUS" }, |
| 170 | { GSM48_MT_GMM_INFO, "INFO" }, |
| 171 | { 0, NULL } |
| 172 | }; |
| 173 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 174 | /*! String names of GPRS Attach types according to 10.5.5.2 */ |
Harald Welte | 64f38c0 | 2016-04-20 17:12:24 +0200 | [diff] [blame] | 175 | const struct value_string gprs_att_t_strs_[] = { |
| 176 | { GPRS_ATT_T_ATTACH, "GPRS attach" }, |
| 177 | { GPRS_ATT_T_ATT_WHILE_IMSI, "GPRS attach while IMSI attached" }, |
| 178 | { GPRS_ATT_T_COMBINED, "Combined GPRS/IMSI attach" }, |
| 179 | { 0, NULL } |
| 180 | }; |
| 181 | |
| 182 | const struct value_string *gprs_att_t_strs = gprs_att_t_strs_; |
| 183 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 184 | /*! String names of GPRS Location Update Types */ |
Harald Welte | 64f38c0 | 2016-04-20 17:12:24 +0200 | [diff] [blame] | 185 | const struct value_string gprs_upd_t_strs_[] = { |
| 186 | { GPRS_UPD_T_RA, "RA updating" }, |
| 187 | { GPRS_UPD_T_RA_LA, "combined RA/LA updating" }, |
| 188 | { GPRS_UPD_T_RA_LA_IMSI_ATT, "combined RA/LA updating + IMSI attach" }, |
| 189 | { GPRS_UPD_T_PERIODIC, "periodic updating" }, |
| 190 | { 0, NULL } |
| 191 | }; |
| 192 | |
| 193 | const struct value_string *gprs_upd_t_strs = gprs_upd_t_strs_; |
| 194 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 195 | /*! String names of GMM MO Detach Types according to 10.5.5.5 */ |
Harald Welte | 64f38c0 | 2016-04-20 17:12:24 +0200 | [diff] [blame] | 196 | const struct value_string gprs_det_t_mo_strs_[] = { |
| 197 | { GPRS_DET_T_MO_GPRS, "GPRS detach" }, |
| 198 | { GPRS_DET_T_MO_IMSI, "IMSI detach" }, |
| 199 | { GPRS_DET_T_MO_COMBINED, "Combined GPRS/IMSI detach" }, |
| 200 | { 0, NULL } |
| 201 | }; |
| 202 | |
| 203 | const struct value_string *gprs_det_t_mo_strs = gprs_det_t_mo_strs_; |
| 204 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 205 | /*! String names of GMM MT Detach Types according to 10.5.5.5 */ |
Harald Welte | 64f38c0 | 2016-04-20 17:12:24 +0200 | [diff] [blame] | 206 | const struct value_string gprs_det_t_mt_strs_[] = { |
| 207 | { GPRS_DET_T_MT_REATT_REQ, "re-attach required" }, |
| 208 | { GPRS_DET_T_MT_REATT_NOTREQ, "re-attach not required" }, |
| 209 | { GPRS_DET_T_MT_IMSI, "IMSI detach (after VLR failure)" }, |
| 210 | { 0, NULL } |
| 211 | }; |
| 212 | |
| 213 | const struct value_string *gprs_det_t_mt_strs = gprs_det_t_mt_strs_; |
Neels Hofmeyr | 0318f6b | 2016-08-29 13:18:56 +0200 | [diff] [blame] | 214 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 215 | /*! String names of GMM Service Types */ |
Neels Hofmeyr | 0318f6b | 2016-08-29 13:18:56 +0200 | [diff] [blame] | 216 | const struct value_string gprs_service_t_strs_[] = { |
| 217 | { GPRS_SERVICE_T_SIGNALLING, "signalling" }, |
| 218 | { GPRS_SERVICE_T_DATA, "data" }, |
| 219 | { GPRS_SERVICE_T_PAGING_RESP, "paging response" }, |
| 220 | { GPRS_SERVICE_T_MBMS_MC_SERV, "MBMS multicast service" }, |
| 221 | { GPRS_SERVICE_T_MBMS_BC_SERV, "MBMS broadcast service" }, |
| 222 | { 0, NULL } |
| 223 | }; |
| 224 | |
| 225 | const struct value_string *gprs_service_t_strs = gprs_service_t_strs_; |
Harald Welte | 96e2a00 | 2017-06-12 21:44:18 +0200 | [diff] [blame] | 226 | |
| 227 | /*! @} */ |