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