Harald Welte | 59b0468 | 2009-06-10 05:40:52 +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 | |
| 4 | /* (C) 2008-2009 by Harald Welte <laforge@gnumonks.org> |
| 5 | * (C) 2008, 2009 by Holger Hans Peter Freyther <zecke@selfish.org> |
| 6 | * |
| 7 | * All Rights Reserved |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License as published by |
| 11 | * the Free Software Foundation; either version 2 of the License, or |
| 12 | * (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License along |
| 20 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 21 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 22 | * |
| 23 | */ |
| 24 | |
| 25 | |
| 26 | #include <stdio.h> |
| 27 | #include <stdlib.h> |
| 28 | #include <string.h> |
| 29 | #include <errno.h> |
| 30 | #include <time.h> |
| 31 | #include <netinet/in.h> |
| 32 | |
| 33 | #include <openbsc/db.h> |
| 34 | #include <openbsc/msgb.h> |
| 35 | #include <openbsc/tlv.h> |
| 36 | #include <openbsc/debug.h> |
| 37 | #include <openbsc/gsm_data.h> |
Daniel Willmann | c818820 | 2009-08-13 03:42:07 +0200 | [diff] [blame] | 38 | #include <openbsc/gsm_utils.h> |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 39 | #include <openbsc/gsm_subscriber.h> |
| 40 | #include <openbsc/gsm_04_11.h> |
| 41 | #include <openbsc/gsm_04_08.h> |
| 42 | #include <openbsc/abis_rsl.h> |
| 43 | #include <openbsc/chan_alloc.h> |
| 44 | #include <openbsc/paging.h> |
| 45 | #include <openbsc/signal.h> |
| 46 | #include <openbsc/trau_frame.h> |
| 47 | #include <openbsc/trau_mux.h> |
Harald Welte | 3c06207 | 2009-07-28 18:25:29 +0200 | [diff] [blame] | 48 | #include <openbsc/rtp_proxy.h> |
Harald Welte | a837977 | 2009-06-20 22:36:41 +0200 | [diff] [blame] | 49 | #include <openbsc/talloc.h> |
Harald Welte | c2189a6 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 50 | #include <openbsc/transaction.h> |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 51 | |
Harald Welte | b8a18b5 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 52 | #define GSM_MAX_FACILITY 128 |
| 53 | #define GSM_MAX_SSVERSION 128 |
| 54 | #define GSM_MAX_USERUSER 128 |
| 55 | |
Harald Welte (local) | 8751ee9 | 2009-08-15 02:30:58 +0200 | [diff] [blame] | 56 | void *tall_locop_ctx; |
Harald Welte | a837977 | 2009-06-20 22:36:41 +0200 | [diff] [blame] | 57 | |
Holger Hans Peter Freyther | 3689710 | 2009-08-01 07:26:59 +0200 | [diff] [blame] | 58 | extern int ipacc_rtp_direct; |
Harald Welte | 3c06207 | 2009-07-28 18:25:29 +0200 | [diff] [blame] | 59 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 60 | static const struct tlv_definition rsl_att_tlvdef = { |
| 61 | .def = { |
| 62 | [GSM48_IE_MOBILE_ID] = { TLV_TYPE_TLV }, |
| 63 | [GSM48_IE_NAME_LONG] = { TLV_TYPE_TLV }, |
| 64 | [GSM48_IE_NAME_SHORT] = { TLV_TYPE_TLV }, |
| 65 | [GSM48_IE_UTC] = { TLV_TYPE_TV }, |
| 66 | [GSM48_IE_NET_TIME_TZ] = { TLV_TYPE_FIXED, 7 }, |
| 67 | [GSM48_IE_LSA_IDENT] = { TLV_TYPE_TLV }, |
| 68 | |
| 69 | [GSM48_IE_BEARER_CAP] = { TLV_TYPE_TLV }, |
| 70 | [GSM48_IE_CAUSE] = { TLV_TYPE_TLV }, |
| 71 | [GSM48_IE_CC_CAP] = { TLV_TYPE_TLV }, |
| 72 | [GSM48_IE_ALERT] = { TLV_TYPE_TLV }, |
| 73 | [GSM48_IE_FACILITY] = { TLV_TYPE_TLV }, |
| 74 | [GSM48_IE_PROGR_IND] = { TLV_TYPE_TLV }, |
| 75 | [GSM48_IE_AUX_STATUS] = { TLV_TYPE_TLV }, |
Harald Welte | b8a18b5 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 76 | [GSM48_IE_NOTIFY] = { TLV_TYPE_TV }, |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 77 | [GSM48_IE_KPD_FACILITY] = { TLV_TYPE_TV }, |
| 78 | [GSM48_IE_SIGNAL] = { TLV_TYPE_TV }, |
Harald Welte | b8a18b5 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 79 | [GSM48_IE_CONN_BCD] = { TLV_TYPE_TLV }, |
| 80 | [GSM48_IE_CONN_SUB] = { TLV_TYPE_TLV }, |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 81 | [GSM48_IE_CALLING_BCD] = { TLV_TYPE_TLV }, |
| 82 | [GSM48_IE_CALLING_SUB] = { TLV_TYPE_TLV }, |
| 83 | [GSM48_IE_CALLED_BCD] = { TLV_TYPE_TLV }, |
| 84 | [GSM48_IE_CALLED_SUB] = { TLV_TYPE_TLV }, |
| 85 | [GSM48_IE_REDIR_BCD] = { TLV_TYPE_TLV }, |
| 86 | [GSM48_IE_REDIR_SUB] = { TLV_TYPE_TLV }, |
| 87 | [GSM48_IE_LOWL_COMPAT] = { TLV_TYPE_TLV }, |
| 88 | [GSM48_IE_HIGHL_COMPAT] = { TLV_TYPE_TLV }, |
| 89 | [GSM48_IE_USER_USER] = { TLV_TYPE_TLV }, |
| 90 | [GSM48_IE_SS_VERS] = { TLV_TYPE_TLV }, |
| 91 | [GSM48_IE_MORE_DATA] = { TLV_TYPE_T }, |
| 92 | [GSM48_IE_CLIR_SUPP] = { TLV_TYPE_T }, |
| 93 | [GSM48_IE_CLIR_INVOC] = { TLV_TYPE_T }, |
| 94 | [GSM48_IE_REV_C_SETUP] = { TLV_TYPE_T }, |
Harald Welte | b8a18b5 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 95 | [GSM48_IE_REPEAT_CIR] = { TLV_TYPE_T }, |
| 96 | [GSM48_IE_REPEAT_SEQ] = { TLV_TYPE_T }, |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 97 | /* FIXME: more elements */ |
| 98 | }, |
| 99 | }; |
| 100 | |
| 101 | static const char *rr_cause_names[] = { |
| 102 | [GSM48_RR_CAUSE_NORMAL] = "Normal event", |
| 103 | [GSM48_RR_CAUSE_ABNORMAL_UNSPEC] = "Abnormal release, unspecified", |
| 104 | [GSM48_RR_CAUSE_ABNORMAL_UNACCT] = "Abnormal release, channel unacceptable", |
| 105 | [GSM48_RR_CAUSE_ABNORMAL_TIMER] = "Abnormal release, timer expired", |
| 106 | [GSM48_RR_CAUSE_ABNORMAL_NOACT] = "Abnormal release, no activity on radio path", |
| 107 | [GSM48_RR_CAUSE_PREMPTIVE_REL] = "Preemptive release", |
| 108 | [GSM48_RR_CAUSE_HNDOVER_IMP] = "Handover impossible, timing advance out of range", |
| 109 | [GSM48_RR_CAUSE_CHAN_MODE_UNACCT] = "Channel mode unacceptable", |
| 110 | [GSM48_RR_CAUSE_FREQ_NOT_IMPL] = "Frequency not implemented", |
| 111 | [GSM48_RR_CAUSE_CALL_CLEARED] = "Call already cleared", |
| 112 | [GSM48_RR_CAUSE_SEMANT_INCORR] = "Semantically incorrect message", |
| 113 | [GSM48_RR_CAUSE_INVALID_MAND_INF] = "Invalid mandatory information", |
| 114 | [GSM48_RR_CAUSE_MSG_TYPE_N] = "Message type non-existant or not implemented", |
| 115 | [GSM48_RR_CAUSE_MSG_TYPE_N_COMPAT] = "Message type not compatible with protocol state", |
| 116 | [GSM48_RR_CAUSE_COND_IE_ERROR] = "Conditional IE error", |
| 117 | [GSM48_RR_CAUSE_NO_CELL_ALLOC_A] = "No cell allocation available", |
| 118 | [GSM48_RR_CAUSE_PROT_ERROR_UNSPC] = "Protocol error unspecified", |
| 119 | }; |
| 120 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 121 | static const char *cc_state_names[] = { |
| 122 | "NULL", |
| 123 | "INITIATED", |
| 124 | "illegal state 2", |
| 125 | "MO_CALL_PROC", |
| 126 | "CALL_DELIVERED", |
| 127 | "illegal state 5", |
| 128 | "CALL_PRESENT", |
| 129 | "CALL_RECEIVED", |
| 130 | "CONNECT_REQUEST", |
| 131 | "MO_TERM_CALL_CONF", |
| 132 | "ACTIVE", |
| 133 | "DISCONNECT_REQ", |
| 134 | "DISCONNECT_IND", |
| 135 | "illegal state 13", |
| 136 | "illegal state 14", |
| 137 | "illegal state 15", |
| 138 | "illegal state 16", |
| 139 | "illegal state 17", |
| 140 | "illegal state 18", |
| 141 | "RELEASE_REQ", |
| 142 | "illegal state 20", |
| 143 | "illegal state 21", |
| 144 | "illegal state 22", |
| 145 | "illegal state 23", |
| 146 | "illegal state 24", |
| 147 | "illegal state 25", |
| 148 | "MO_ORIG_MODIFY", |
| 149 | "MO_TERM_MODIFY", |
| 150 | "CONNECT_IND", |
| 151 | "illegal state 29", |
| 152 | "illegal state 30", |
| 153 | "illegal state 31", |
| 154 | }; |
| 155 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 156 | static char strbuf[64]; |
| 157 | |
| 158 | static const char *rr_cause_name(u_int8_t cause) |
| 159 | { |
| 160 | if (cause < ARRAY_SIZE(rr_cause_names) && |
| 161 | rr_cause_names[cause]) |
| 162 | return rr_cause_names[cause]; |
| 163 | |
| 164 | snprintf(strbuf, sizeof(strbuf), "0x%02x", cause); |
| 165 | return strbuf; |
| 166 | } |
| 167 | |
| 168 | static void parse_meas_rep(struct gsm_meas_rep *rep, const u_int8_t *data, |
| 169 | int len) |
| 170 | { |
| 171 | memset(rep, 0, sizeof(*rep)); |
| 172 | |
| 173 | if (data[0] & 0x80) |
| 174 | rep->flags |= MEAS_REP_F_BA1; |
| 175 | if (data[0] & 0x40) |
| 176 | rep->flags |= MEAS_REP_F_DTX; |
Harald Welte | ba6589d | 2009-07-05 04:05:44 +0200 | [diff] [blame] | 177 | if ((data[1] & 0x40) == 0x00) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 178 | rep->flags |= MEAS_REP_F_VALID; |
| 179 | |
| 180 | rep->rxlev_full = data[0] & 0x3f; |
| 181 | rep->rxlev_sub = data[1] & 0x3f; |
| 182 | rep->rxqual_full = (data[3] >> 4) & 0x7; |
| 183 | rep->rxqual_sub = (data[3] >> 1) & 0x7; |
| 184 | rep->num_cell = data[4] >> 6 | ((data[3] & 0x01) << 2); |
| 185 | if (rep->num_cell < 1) |
| 186 | return; |
| 187 | |
| 188 | /* an encoding nightmare in perfection */ |
| 189 | |
| 190 | rep->cell[0].rxlev = data[4] & 0x3f; |
| 191 | rep->cell[0].bcch_freq = data[5] >> 2; |
| 192 | rep->cell[0].bsic = ((data[5] & 0x03) << 3) | (data[6] >> 5); |
| 193 | if (rep->num_cell < 2) |
| 194 | return; |
| 195 | |
| 196 | rep->cell[1].rxlev = ((data[6] & 0x1f) << 1) | (data[7] >> 7); |
| 197 | rep->cell[1].bcch_freq = (data[7] >> 2) & 0x1f; |
| 198 | rep->cell[1].bsic = ((data[7] & 0x03) << 4) | (data[8] >> 4); |
| 199 | if (rep->num_cell < 3) |
| 200 | return; |
| 201 | |
| 202 | rep->cell[2].rxlev = ((data[8] & 0x0f) << 2) | (data[9] >> 6); |
| 203 | rep->cell[2].bcch_freq = (data[9] >> 1) & 0x1f; |
| 204 | rep->cell[2].bsic = ((data[9] & 0x01) << 6) | (data[10] >> 3); |
| 205 | if (rep->num_cell < 4) |
| 206 | return; |
| 207 | |
| 208 | rep->cell[3].rxlev = ((data[10] & 0x07) << 3) | (data[11] >> 5); |
| 209 | rep->cell[3].bcch_freq = data[11] & 0x1f; |
| 210 | rep->cell[3].bsic = data[12] >> 2; |
| 211 | if (rep->num_cell < 5) |
| 212 | return; |
| 213 | |
| 214 | rep->cell[4].rxlev = ((data[12] & 0x03) << 4) | (data[13] >> 4); |
| 215 | rep->cell[4].bcch_freq = ((data[13] & 0xf) << 1) | (data[14] >> 7); |
| 216 | rep->cell[4].bsic = (data[14] >> 1) & 0x3f; |
| 217 | if (rep->num_cell < 6) |
| 218 | return; |
| 219 | |
| 220 | rep->cell[5].rxlev = ((data[14] & 0x01) << 5) | (data[15] >> 3); |
| 221 | rep->cell[5].bcch_freq = ((data[15] & 0x07) << 2) | (data[16] >> 6); |
| 222 | rep->cell[5].bsic = data[16] & 0x3f; |
| 223 | } |
| 224 | |
| 225 | int gsm0408_loc_upd_acc(struct gsm_lchan *lchan, u_int32_t tmsi); |
| 226 | static int gsm48_tx_simple(struct gsm_lchan *lchan, |
| 227 | u_int8_t pdisc, u_int8_t msg_type); |
| 228 | static void schedule_reject(struct gsm_lchan *lchan); |
| 229 | |
| 230 | struct gsm_lai { |
| 231 | u_int16_t mcc; |
| 232 | u_int16_t mnc; |
| 233 | u_int16_t lac; |
| 234 | }; |
| 235 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 236 | static int reject_cause = 0; |
| 237 | void gsm0408_set_reject_cause(int cause) |
| 238 | { |
| 239 | reject_cause = cause; |
| 240 | } |
| 241 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 242 | static u_int32_t new_callref = 0x80000001; |
| 243 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 244 | static int authorize_subscriber(struct gsm_loc_updating_operation *loc, |
| 245 | struct gsm_subscriber *subscriber) |
| 246 | { |
| 247 | if (!subscriber) |
| 248 | return 0; |
| 249 | |
| 250 | /* |
| 251 | * Do not send accept yet as more information should arrive. Some |
| 252 | * phones will not send us the information and we will have to check |
| 253 | * what we want to do with that. |
| 254 | */ |
| 255 | if (loc && (loc->waiting_for_imsi || loc->waiting_for_imei)) |
| 256 | return 0; |
| 257 | |
Jan Luebbe | 3d6294e | 2009-08-12 12:48:00 +0200 | [diff] [blame] | 258 | switch (subscriber->net->auth_policy) { |
| 259 | case GSM_AUTH_POLICY_CLOSED: |
| 260 | return subscriber->authorized; |
Harald Welte (local) | 16480eb | 2009-08-13 13:49:51 +0200 | [diff] [blame] | 261 | case GSM_AUTH_POLICY_TOKEN: |
Harald Welte (local) | 272f5c7 | 2009-08-13 20:44:23 +0200 | [diff] [blame] | 262 | if (subscriber->authorized) |
| 263 | return subscriber->authorized; |
Harald Welte (local) | 16480eb | 2009-08-13 13:49:51 +0200 | [diff] [blame] | 264 | return (subscriber->flags & GSM_SUBSCRIBER_FIRST_CONTACT); |
Jan Luebbe | 3d6294e | 2009-08-12 12:48:00 +0200 | [diff] [blame] | 265 | case GSM_AUTH_POLICY_ACCEPT_ALL: |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 266 | return 1; |
Jan Luebbe | 3d6294e | 2009-08-12 12:48:00 +0200 | [diff] [blame] | 267 | default: |
| 268 | return 0; |
| 269 | } |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | static void release_loc_updating_req(struct gsm_lchan *lchan) |
| 273 | { |
| 274 | if (!lchan->loc_operation) |
| 275 | return; |
| 276 | |
| 277 | bsc_del_timer(&lchan->loc_operation->updating_timer); |
Harald Welte | a837977 | 2009-06-20 22:36:41 +0200 | [diff] [blame] | 278 | talloc_free(lchan->loc_operation); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 279 | lchan->loc_operation = 0; |
| 280 | put_lchan(lchan); |
| 281 | } |
| 282 | |
| 283 | static void allocate_loc_updating_req(struct gsm_lchan *lchan) |
| 284 | { |
| 285 | use_lchan(lchan); |
| 286 | release_loc_updating_req(lchan); |
| 287 | |
Harald Welte | 857e00d | 2009-06-26 20:25:23 +0200 | [diff] [blame] | 288 | lchan->loc_operation = talloc_zero(tall_locop_ctx, |
| 289 | struct gsm_loc_updating_operation); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | static int gsm0408_authorize(struct gsm_lchan *lchan, struct msgb *msg) |
| 293 | { |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 294 | if (authorize_subscriber(lchan->loc_operation, lchan->subscr)) { |
Harald Welte | 5070e94 | 2009-08-09 19:07:00 +0200 | [diff] [blame] | 295 | int rc; |
| 296 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 297 | db_subscriber_alloc_tmsi(lchan->subscr); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 298 | release_loc_updating_req(lchan); |
Holger Hans Peter Freyther | cd8bacf | 2009-08-19 12:53:57 +0200 | [diff] [blame] | 299 | rc = gsm0408_loc_upd_acc(msg->lchan, lchan->subscr->tmsi); |
Harald Welte | 5070e94 | 2009-08-09 19:07:00 +0200 | [diff] [blame] | 300 | /* call subscr_update after putting the loc_upd_acc |
| 301 | * in the transmit queue, since S_SUBSCR_ATTACHED might |
| 302 | * trigger further action like SMS delivery */ |
| 303 | subscr_update(lchan->subscr, msg->trx->bts, |
| 304 | GSM_SUBSCRIBER_UPDATE_ATTACHED); |
| 305 | return rc; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | return 0; |
| 309 | } |
| 310 | |
| 311 | static int gsm0408_handle_lchan_signal(unsigned int subsys, unsigned int signal, |
| 312 | void *handler_data, void *signal_data) |
| 313 | { |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 314 | struct gsm_trans *trans, *temp; |
| 315 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 316 | if (subsys != SS_LCHAN || signal != S_LCHAN_UNEXPECTED_RELEASE) |
| 317 | return 0; |
| 318 | |
| 319 | /* |
| 320 | * Cancel any outstanding location updating request |
| 321 | * operation taking place on the lchan. |
| 322 | */ |
Harald Welte | 12560da | 2009-07-04 09:35:21 +0200 | [diff] [blame] | 323 | struct gsm_lchan *lchan = (struct gsm_lchan *)signal_data; |
Harald Welte | 1ff81b5 | 2009-06-26 20:17:06 +0200 | [diff] [blame] | 324 | if (!lchan) |
| 325 | return 0; |
| 326 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 327 | release_loc_updating_req(lchan); |
| 328 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 329 | /* Free all transactions that are associated with the released lchan */ |
Harald Welte | c2189a6 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 330 | /* FIXME: this is not neccessarily the right thing to do, we should |
| 331 | * only set trans->lchan to NULL and wait for another lchan to be |
| 332 | * established to the same MM entity (phone/subscriber) */ |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 333 | llist_for_each_entry_safe(trans, temp, &lchan->ts->trx->bts->network->trans_list, entry) { |
| 334 | if (trans->lchan == lchan) |
Harald Welte | c2189a6 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 335 | trans_free(trans); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 336 | } |
| 337 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 338 | return 0; |
| 339 | } |
| 340 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 341 | static const char bcd_num_digits[] = { |
| 342 | '0', '1', '2', '3', '4', '5', '6', '7', |
| 343 | '8', '9', '*', '#', 'a', 'b', 'c', '\0' |
| 344 | }; |
| 345 | |
Harald Welte | b8a18b5 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 346 | /* decode a 'called/calling/connect party BCD number' as in 10.5.4.7 */ |
| 347 | int decode_bcd_number(char *output, int output_len, const u_int8_t *bcd_lv, |
| 348 | int h_len) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 349 | { |
| 350 | u_int8_t in_len = bcd_lv[0]; |
| 351 | int i; |
| 352 | |
Harald Welte | b8a18b5 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 353 | for (i = 1 + h_len; i <= in_len; i++) { |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 354 | /* lower nibble */ |
| 355 | output_len--; |
| 356 | if (output_len <= 1) |
| 357 | break; |
| 358 | *output++ = bcd_num_digits[bcd_lv[i] & 0xf]; |
| 359 | |
| 360 | /* higher nibble */ |
| 361 | output_len--; |
| 362 | if (output_len <= 1) |
| 363 | break; |
| 364 | *output++ = bcd_num_digits[bcd_lv[i] >> 4]; |
| 365 | } |
| 366 | if (output_len >= 1) |
| 367 | *output++ = '\0'; |
| 368 | |
Harald Welte | b8a18b5 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 369 | return 0; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 370 | } |
| 371 | |
| 372 | /* convert a single ASCII character to call-control BCD */ |
| 373 | static int asc_to_bcd(const char asc) |
| 374 | { |
| 375 | int i; |
| 376 | |
| 377 | for (i = 0; i < ARRAY_SIZE(bcd_num_digits); i++) { |
| 378 | if (bcd_num_digits[i] == asc) |
| 379 | return i; |
| 380 | } |
| 381 | return -EINVAL; |
| 382 | } |
| 383 | |
Harald Welte | b8a18b5 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 384 | /* convert a ASCII phone number to 'called/calling/connect party BCD number' */ |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 385 | int encode_bcd_number(u_int8_t *bcd_lv, u_int8_t max_len, |
Harald Welte | b8a18b5 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 386 | int h_len, const char *input) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 387 | { |
| 388 | int in_len = strlen(input); |
| 389 | int i; |
Harald Welte | b8a18b5 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 390 | u_int8_t *bcd_cur = bcd_lv + 1 + h_len; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 391 | |
| 392 | /* two digits per byte, plus type byte */ |
Harald Welte | b8a18b5 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 393 | bcd_lv[0] = in_len/2 + h_len; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 394 | if (in_len % 2) |
| 395 | bcd_lv[0]++; |
| 396 | |
Harald Welte | b8a18b5 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 397 | if (bcd_lv[0] > max_len) |
| 398 | return -EIO; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 399 | |
| 400 | for (i = 0; i < in_len; i++) { |
| 401 | int rc = asc_to_bcd(input[i]); |
| 402 | if (rc < 0) |
| 403 | return rc; |
| 404 | if (i % 2 == 0) |
| 405 | *bcd_cur = rc; |
| 406 | else |
| 407 | *bcd_cur++ |= (rc << 4); |
| 408 | } |
| 409 | /* append padding nibble in case of odd length */ |
| 410 | if (i % 2) |
| 411 | *bcd_cur++ |= 0xf0; |
| 412 | |
| 413 | /* return how many bytes we used */ |
| 414 | return (bcd_cur - bcd_lv); |
| 415 | } |
| 416 | |
Harald Welte | b8a18b5 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 417 | /* decode 'bearer capability' */ |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 418 | static int decode_bearer_cap(struct gsm_mncc_bearer_cap *bcap, |
Harald Welte | b8a18b5 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 419 | const u_int8_t *lv) |
| 420 | { |
| 421 | u_int8_t in_len = lv[0]; |
| 422 | int i, s; |
| 423 | |
| 424 | if (in_len < 1) |
| 425 | return -EINVAL; |
| 426 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 427 | bcap->speech_ver[0] = -1; /* end of list, of maximum 7 values */ |
Harald Welte | b8a18b5 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 428 | |
| 429 | /* octet 3 */ |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 430 | bcap->transfer = lv[1] & 0x07; |
| 431 | bcap->mode = (lv[1] & 0x08) >> 3; |
| 432 | bcap->coding = (lv[1] & 0x10) >> 4; |
| 433 | bcap->radio = (lv[1] & 0x60) >> 5; |
Harald Welte | b8a18b5 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 434 | |
| 435 | i = 1; |
| 436 | s = 0; |
| 437 | while(!(lv[i] & 0x80)) { |
| 438 | i++; /* octet 3a etc */ |
| 439 | if (in_len < i) |
| 440 | return 0; |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 441 | bcap->speech_ver[s++] = lv[i] & 0x0f; |
| 442 | bcap->speech_ver[s] = -1; /* end of list */ |
Harald Welte | b8a18b5 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 443 | if (i == 2) /* octet 3a */ |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 444 | bcap->speech_ctm = (lv[i] & 0x20) >> 5; |
Harald Welte | b8a18b5 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 445 | if (s == 7) /* maximum speech versions + end of list */ |
| 446 | return 0; |
| 447 | } |
| 448 | |
| 449 | return 0; |
| 450 | } |
| 451 | |
| 452 | /* encode 'bearer capability' */ |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 453 | static int encode_bearer_cap(struct msgb *msg, int lv_only, |
| 454 | const struct gsm_mncc_bearer_cap *bcap) |
Harald Welte | b8a18b5 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 455 | { |
| 456 | u_int8_t lv[32 + 1]; |
| 457 | int i, s; |
| 458 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 459 | lv[1] = bcap->transfer; |
| 460 | lv[1] |= bcap->mode << 3; |
| 461 | lv[1] |= bcap->coding << 4; |
| 462 | lv[1] |= bcap->radio << 5; |
Harald Welte | b8a18b5 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 463 | |
| 464 | i = 1; |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 465 | for (s = 0; bcap->speech_ver[s] >= 0; s++) { |
Harald Welte | b8a18b5 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 466 | i++; /* octet 3a etc */ |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 467 | lv[i] = bcap->speech_ver[s]; |
Harald Welte | b8a18b5 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 468 | if (i == 2) /* octet 3a */ |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 469 | lv[i] |= bcap->speech_ctm << 5; |
Harald Welte | b8a18b5 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 470 | } |
| 471 | lv[i] |= 0x80; /* last IE of octet 3 etc */ |
| 472 | |
| 473 | lv[0] = i; |
| 474 | if (lv_only) |
| 475 | msgb_lv_put(msg, lv[0], lv+1); |
| 476 | else |
| 477 | msgb_tlv_put(msg, GSM48_IE_BEARER_CAP, lv[0], lv+1); |
| 478 | |
| 479 | return 0; |
| 480 | } |
| 481 | |
| 482 | /* decode 'call control cap' */ |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 483 | static int decode_cccap(struct gsm_mncc_cccap *ccap, const u_int8_t *lv) |
Harald Welte | b8a18b5 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 484 | { |
| 485 | u_int8_t in_len = lv[0]; |
| 486 | |
| 487 | if (in_len < 1) |
| 488 | return -EINVAL; |
| 489 | |
| 490 | /* octet 3 */ |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 491 | ccap->dtmf = lv[1] & 0x01; |
| 492 | ccap->pcp = (lv[1] & 0x02) >> 1; |
Harald Welte | b8a18b5 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 493 | |
| 494 | return 0; |
| 495 | } |
| 496 | |
| 497 | /* decode 'called party BCD number' */ |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 498 | static int decode_called(struct gsm_mncc_number *called, |
| 499 | const u_int8_t *lv) |
Harald Welte | b8a18b5 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 500 | { |
| 501 | u_int8_t in_len = lv[0]; |
| 502 | |
| 503 | if (in_len < 1) |
| 504 | return -EINVAL; |
| 505 | |
| 506 | /* octet 3 */ |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 507 | called->plan = lv[1] & 0x0f; |
| 508 | called->type = (lv[1] & 0x70) >> 4; |
Harald Welte | b8a18b5 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 509 | |
| 510 | /* octet 4..N */ |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 511 | decode_bcd_number(called->number, sizeof(called->number), lv, 1); |
Harald Welte | b8a18b5 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 512 | |
| 513 | return 0; |
| 514 | } |
| 515 | |
| 516 | /* encode 'called party BCD number' */ |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 517 | static int encode_called(struct msgb *msg, |
| 518 | const struct gsm_mncc_number *called) |
Harald Welte | b8a18b5 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 519 | { |
| 520 | u_int8_t lv[18]; |
| 521 | int ret; |
| 522 | |
| 523 | /* octet 3 */ |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 524 | lv[1] = called->plan; |
| 525 | lv[1] |= called->type << 4; |
Harald Welte | b8a18b5 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 526 | |
| 527 | /* octet 4..N, octet 2 */ |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 528 | ret = encode_bcd_number(lv, sizeof(lv), 1, called->number); |
Harald Welte | b8a18b5 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 529 | if (ret < 0) |
| 530 | return ret; |
| 531 | |
| 532 | msgb_tlv_put(msg, GSM48_IE_CALLED_BCD, lv[0], lv+1); |
| 533 | |
| 534 | return 0; |
| 535 | } |
| 536 | |
| 537 | /* encode callerid of various IEs */ |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 538 | static int encode_callerid(struct msgb *msg, int ie, |
| 539 | const struct gsm_mncc_number *callerid) |
Harald Welte | b8a18b5 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 540 | { |
| 541 | u_int8_t lv[13]; |
| 542 | int h_len = 1; |
| 543 | int ret; |
| 544 | |
| 545 | /* octet 3 */ |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 546 | lv[1] = callerid->plan; |
| 547 | lv[1] |= callerid->type << 4; |
Harald Welte | b8a18b5 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 548 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 549 | if (callerid->present || callerid->screen) { |
Harald Welte | b8a18b5 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 550 | /* octet 3a */ |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 551 | lv[2] = callerid->screen; |
| 552 | lv[2] |= callerid->present << 5; |
Harald Welte | b8a18b5 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 553 | lv[2] |= 0x80; |
| 554 | h_len++; |
| 555 | } else |
| 556 | lv[1] |= 0x80; |
| 557 | |
| 558 | /* octet 4..N, octet 2 */ |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 559 | ret = encode_bcd_number(lv, sizeof(lv), h_len, callerid->number); |
Harald Welte | b8a18b5 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 560 | if (ret < 0) |
| 561 | return ret; |
| 562 | |
| 563 | msgb_tlv_put(msg, ie, lv[0], lv+1); |
| 564 | |
| 565 | return 0; |
| 566 | } |
| 567 | |
| 568 | /* decode 'cause' */ |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 569 | static int decode_cause(struct gsm_mncc_cause *cause, |
Harald Welte | b8a18b5 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 570 | const u_int8_t *lv) |
| 571 | { |
| 572 | u_int8_t in_len = lv[0]; |
| 573 | int i; |
| 574 | |
| 575 | if (in_len < 2) |
| 576 | return -EINVAL; |
| 577 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 578 | cause->diag_len = 0; |
Harald Welte | b8a18b5 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 579 | |
| 580 | /* octet 3 */ |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 581 | cause->location = lv[1] & 0x0f; |
| 582 | cause->coding = (lv[1] & 0x60) >> 5; |
Harald Welte | b8a18b5 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 583 | |
| 584 | i = 1; |
| 585 | if (!(lv[i] & 0x80)) { |
| 586 | i++; /* octet 3a */ |
| 587 | if (in_len < i+1) |
| 588 | return 0; |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 589 | cause->rec = 1; |
| 590 | cause->rec_val = lv[i] & 0x7f; |
Harald Welte | b8a18b5 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 591 | |
| 592 | } |
| 593 | i++; |
| 594 | |
| 595 | /* octet 4 */ |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 596 | cause->value = lv[i] & 0x7f; |
Harald Welte | b8a18b5 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 597 | i++; |
| 598 | |
| 599 | if (in_len < i) /* no diag */ |
| 600 | return 0; |
| 601 | |
| 602 | if (in_len - (i-1) > 32) /* maximum 32 octets */ |
| 603 | return 0; |
| 604 | |
| 605 | /* octet 5-N */ |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 606 | memcpy(cause->diag, lv + i, in_len - (i-1)); |
| 607 | cause->diag_len = in_len - (i-1); |
Harald Welte | b8a18b5 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 608 | |
| 609 | return 0; |
| 610 | } |
| 611 | |
| 612 | /* encode 'cause' */ |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 613 | static int encode_cause(struct msgb *msg, int lv_only, |
| 614 | const struct gsm_mncc_cause *cause) |
Harald Welte | b8a18b5 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 615 | { |
| 616 | u_int8_t lv[32+4]; |
| 617 | int i; |
| 618 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 619 | if (cause->diag_len > 32) |
Harald Welte | b8a18b5 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 620 | return -EINVAL; |
| 621 | |
| 622 | /* octet 3 */ |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 623 | lv[1] = cause->location; |
| 624 | lv[1] |= cause->coding << 5; |
Harald Welte | b8a18b5 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 625 | |
| 626 | i = 1; |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 627 | if (cause->rec) { |
Harald Welte | b8a18b5 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 628 | i++; /* octet 3a */ |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 629 | lv[i] = cause->rec_val; |
Harald Welte | b8a18b5 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 630 | } |
| 631 | lv[i] |= 0x80; /* end of octet 3 */ |
| 632 | |
| 633 | /* octet 4 */ |
| 634 | i++; |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 635 | lv[i] = 0x80 | cause->value; |
Harald Welte | b8a18b5 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 636 | |
| 637 | /* octet 5-N */ |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 638 | if (cause->diag_len) { |
| 639 | memcpy(lv + i, cause->diag, cause->diag_len); |
| 640 | i += cause->diag_len; |
Harald Welte | b8a18b5 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 641 | } |
| 642 | |
| 643 | lv[0] = i; |
| 644 | if (lv_only) |
| 645 | msgb_lv_put(msg, lv[0], lv+1); |
| 646 | else |
| 647 | msgb_tlv_put(msg, GSM48_IE_CAUSE, lv[0], lv+1); |
| 648 | |
| 649 | return 0; |
| 650 | } |
| 651 | |
| 652 | /* encode 'calling number' */ |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 653 | static int encode_calling(struct msgb *msg, |
| 654 | const struct gsm_mncc_number *calling) |
Harald Welte | b8a18b5 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 655 | { |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 656 | return encode_callerid(msg, GSM48_IE_CALLING_BCD, calling); |
Harald Welte | b8a18b5 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 657 | } |
| 658 | |
| 659 | /* encode 'connected number' */ |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 660 | static int encode_connected(struct msgb *msg, |
| 661 | const struct gsm_mncc_number *connected) |
Harald Welte | b8a18b5 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 662 | { |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 663 | return encode_callerid(msg, GSM48_IE_CONN_BCD, connected); |
Harald Welte | b8a18b5 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 664 | } |
| 665 | |
| 666 | /* encode 'redirecting number' */ |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 667 | static int encode_redirecting(struct msgb *msg, |
| 668 | const struct gsm_mncc_number *redirecting) |
Harald Welte | b8a18b5 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 669 | { |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 670 | return encode_callerid(msg, GSM48_IE_REDIR_BCD, redirecting); |
Harald Welte | b8a18b5 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 671 | } |
| 672 | |
| 673 | /* decode 'facility' */ |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 674 | static int decode_facility(struct gsm_mncc_facility *facility, |
Harald Welte | b8a18b5 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 675 | const u_int8_t *lv) |
| 676 | { |
| 677 | u_int8_t in_len = lv[0]; |
| 678 | |
| 679 | if (in_len < 1) |
| 680 | return -EINVAL; |
| 681 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 682 | if (in_len > sizeof(facility->info)) |
Harald Welte | b8a18b5 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 683 | return -EINVAL; |
| 684 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 685 | memcpy(facility->info, lv+1, in_len); |
| 686 | facility->len = in_len; |
Harald Welte | b8a18b5 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 687 | |
| 688 | return 0; |
| 689 | } |
| 690 | |
| 691 | /* encode 'facility' */ |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 692 | static int encode_facility(struct msgb *msg, int lv_only, |
| 693 | const struct gsm_mncc_facility *facility) |
Harald Welte | b8a18b5 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 694 | { |
| 695 | u_int8_t lv[GSM_MAX_FACILITY + 1]; |
| 696 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 697 | if (facility->len < 1 || facility->len > GSM_MAX_FACILITY) |
Harald Welte | b8a18b5 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 698 | return -EINVAL; |
| 699 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 700 | memcpy(lv+1, facility->info, facility->len); |
| 701 | lv[0] = facility->len; |
Harald Welte | b8a18b5 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 702 | if (lv_only) |
| 703 | msgb_lv_put(msg, lv[0], lv+1); |
| 704 | else |
| 705 | msgb_tlv_put(msg, GSM48_IE_FACILITY, lv[0], lv+1); |
| 706 | |
| 707 | return 0; |
| 708 | } |
| 709 | |
| 710 | /* decode 'notify' */ |
| 711 | static int decode_notify(int *notify, const u_int8_t *v) |
| 712 | { |
| 713 | *notify = v[0] & 0x7f; |
| 714 | |
| 715 | return 0; |
| 716 | } |
| 717 | |
| 718 | /* encode 'notify' */ |
| 719 | static int encode_notify(struct msgb *msg, int notify) |
| 720 | { |
| 721 | msgb_v_put(msg, notify | 0x80); |
| 722 | |
| 723 | return 0; |
| 724 | } |
| 725 | |
| 726 | /* encode 'signal' */ |
| 727 | static int encode_signal(struct msgb *msg, int signal) |
| 728 | { |
| 729 | msgb_tv_put(msg, GSM48_IE_SIGNAL, signal); |
| 730 | |
| 731 | return 0; |
| 732 | } |
| 733 | |
| 734 | /* decode 'keypad' */ |
| 735 | static int decode_keypad(int *keypad, const u_int8_t *lv) |
| 736 | { |
| 737 | u_int8_t in_len = lv[0]; |
| 738 | |
| 739 | if (in_len < 1) |
| 740 | return -EINVAL; |
| 741 | |
| 742 | *keypad = lv[1] & 0x7f; |
| 743 | |
| 744 | return 0; |
| 745 | } |
| 746 | |
| 747 | /* encode 'keypad' */ |
| 748 | static int encode_keypad(struct msgb *msg, int keypad) |
| 749 | { |
| 750 | msgb_tv_put(msg, GSM48_IE_KPD_FACILITY, keypad); |
| 751 | |
| 752 | return 0; |
| 753 | } |
| 754 | |
| 755 | /* decode 'progress' */ |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 756 | static int decode_progress(struct gsm_mncc_progress *progress, |
Harald Welte | b8a18b5 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 757 | const u_int8_t *lv) |
| 758 | { |
| 759 | u_int8_t in_len = lv[0]; |
| 760 | |
| 761 | if (in_len < 2) |
| 762 | return -EINVAL; |
| 763 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 764 | progress->coding = (lv[1] & 0x60) >> 5; |
| 765 | progress->location = lv[1] & 0x0f; |
| 766 | progress->descr = lv[2] & 0x7f; |
Harald Welte | b8a18b5 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 767 | |
| 768 | return 0; |
| 769 | } |
| 770 | |
| 771 | /* encode 'progress' */ |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 772 | static int encode_progress(struct msgb *msg, int lv_only, |
| 773 | const struct gsm_mncc_progress *p) |
Harald Welte | b8a18b5 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 774 | { |
| 775 | u_int8_t lv[3]; |
| 776 | |
| 777 | lv[0] = 2; |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 778 | lv[1] = 0x80 | ((p->coding & 0x3) << 5) | (p->location & 0xf); |
| 779 | lv[2] = 0x80 | (p->descr & 0x7f); |
Harald Welte | b8a18b5 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 780 | if (lv_only) |
| 781 | msgb_lv_put(msg, lv[0], lv+1); |
| 782 | else |
| 783 | msgb_tlv_put(msg, GSM48_IE_PROGR_IND, lv[0], lv+1); |
| 784 | |
| 785 | return 0; |
| 786 | } |
| 787 | |
| 788 | /* decode 'user-user' */ |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 789 | static int decode_useruser(struct gsm_mncc_useruser *uu, |
Harald Welte | b8a18b5 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 790 | const u_int8_t *lv) |
| 791 | { |
| 792 | u_int8_t in_len = lv[0]; |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 793 | char *info = uu->info; |
| 794 | int info_len = sizeof(uu->info); |
Harald Welte | b8a18b5 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 795 | int i; |
| 796 | |
| 797 | if (in_len < 1) |
| 798 | return -EINVAL; |
| 799 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 800 | uu->proto = lv[1]; |
Harald Welte | b8a18b5 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 801 | |
| 802 | for (i = 2; i <= in_len; i++) { |
| 803 | info_len--; |
| 804 | if (info_len <= 1) |
| 805 | break; |
| 806 | *info++ = lv[i]; |
| 807 | } |
| 808 | if (info_len >= 1) |
| 809 | *info++ = '\0'; |
| 810 | |
| 811 | return 0; |
| 812 | } |
| 813 | |
| 814 | /* encode 'useruser' */ |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 815 | static int encode_useruser(struct msgb *msg, int lv_only, |
| 816 | const struct gsm_mncc_useruser *uu) |
Harald Welte | b8a18b5 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 817 | { |
| 818 | u_int8_t lv[GSM_MAX_USERUSER + 2]; |
| 819 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 820 | if (strlen(uu->info) > GSM_MAX_USERUSER) |
Harald Welte | b8a18b5 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 821 | return -EINVAL; |
| 822 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 823 | lv[0] = 1 + strlen(uu->info); |
| 824 | lv[1] = uu->proto; |
| 825 | memcpy(lv + 2, uu->info, strlen(uu->info)); |
Harald Welte | b8a18b5 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 826 | if (lv_only) |
| 827 | msgb_lv_put(msg, lv[0], lv+1); |
| 828 | else |
| 829 | msgb_tlv_put(msg, GSM48_IE_USER_USER, lv[0], lv+1); |
| 830 | |
| 831 | return 0; |
| 832 | } |
| 833 | |
| 834 | /* decode 'ss version' */ |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 835 | static int decode_ssversion(struct gsm_mncc_ssversion *ssv, |
Harald Welte | b8a18b5 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 836 | const u_int8_t *lv) |
| 837 | { |
| 838 | u_int8_t in_len = lv[0]; |
| 839 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 840 | if (in_len < 1 || in_len < sizeof(ssv->info)) |
Harald Welte | b8a18b5 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 841 | return -EINVAL; |
| 842 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 843 | memcpy(ssv->info, lv + 1, in_len); |
| 844 | ssv->len = in_len; |
Harald Welte | b8a18b5 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 845 | |
| 846 | return 0; |
| 847 | } |
| 848 | |
| 849 | /* encode 'more data' */ |
| 850 | static int encode_more(struct msgb *msg) |
| 851 | { |
| 852 | u_int8_t *ie; |
| 853 | |
| 854 | ie = msgb_put(msg, 1); |
| 855 | ie[0] = GSM48_IE_MORE_DATA; |
| 856 | |
| 857 | return 0; |
| 858 | } |
| 859 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 860 | /* Chapter 9.2.14 : Send LOCATION UPDATING REJECT */ |
| 861 | int gsm0408_loc_upd_rej(struct gsm_lchan *lchan, u_int8_t cause) |
| 862 | { |
| 863 | struct msgb *msg = gsm48_msgb_alloc(); |
| 864 | struct gsm48_hdr *gh; |
| 865 | |
| 866 | msg->lchan = lchan; |
| 867 | |
| 868 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 1); |
| 869 | gh->proto_discr = GSM48_PDISC_MM; |
| 870 | gh->msg_type = GSM48_MT_MM_LOC_UPD_REJECT; |
| 871 | gh->data[0] = cause; |
| 872 | |
| 873 | DEBUGP(DMM, "-> LOCATION UPDATING REJECT on channel: %d\n", lchan->nr); |
| 874 | |
Harald Welte | 36fe2e8 | 2009-07-23 21:13:03 +0200 | [diff] [blame] | 875 | return gsm48_sendmsg(msg, NULL); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 876 | } |
| 877 | |
| 878 | /* Chapter 9.2.13 : Send LOCATION UPDATE ACCEPT */ |
| 879 | int gsm0408_loc_upd_acc(struct gsm_lchan *lchan, u_int32_t tmsi) |
| 880 | { |
| 881 | struct gsm_bts *bts = lchan->ts->trx->bts; |
| 882 | struct msgb *msg = gsm48_msgb_alloc(); |
| 883 | struct gsm48_hdr *gh; |
| 884 | struct gsm48_loc_area_id *lai; |
| 885 | u_int8_t *mid; |
| 886 | int ret; |
| 887 | |
| 888 | msg->lchan = lchan; |
| 889 | |
| 890 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 891 | gh->proto_discr = GSM48_PDISC_MM; |
| 892 | gh->msg_type = GSM48_MT_MM_LOC_UPD_ACCEPT; |
| 893 | |
| 894 | lai = (struct gsm48_loc_area_id *) msgb_put(msg, sizeof(*lai)); |
| 895 | gsm0408_generate_lai(lai, bts->network->country_code, |
| 896 | bts->network->network_code, bts->location_area_code); |
| 897 | |
Holger Hans Peter Freyther | 3689710 | 2009-08-01 07:26:59 +0200 | [diff] [blame] | 898 | mid = msgb_put(msg, GSM48_MID_TMSI_LEN); |
Holger Hans Peter Freyther | 20a0f32 | 2009-08-20 08:41:24 +0200 | [diff] [blame] | 899 | gsm48_generate_mid_from_tmsi(mid, tmsi); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 900 | |
| 901 | DEBUGP(DMM, "-> LOCATION UPDATE ACCEPT\n"); |
| 902 | |
Harald Welte | 36fe2e8 | 2009-07-23 21:13:03 +0200 | [diff] [blame] | 903 | ret = gsm48_sendmsg(msg, NULL); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 904 | |
Harald Welte | 5070e94 | 2009-08-09 19:07:00 +0200 | [diff] [blame] | 905 | /* send MM INFO with network name */ |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 906 | ret = gsm48_tx_mm_info(lchan); |
| 907 | |
| 908 | return ret; |
| 909 | } |
| 910 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 911 | /* Transmit Chapter 9.2.10 Identity Request */ |
| 912 | static int mm_tx_identity_req(struct gsm_lchan *lchan, u_int8_t id_type) |
| 913 | { |
| 914 | struct msgb *msg = gsm48_msgb_alloc(); |
| 915 | struct gsm48_hdr *gh; |
| 916 | |
| 917 | msg->lchan = lchan; |
| 918 | |
| 919 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 1); |
| 920 | gh->proto_discr = GSM48_PDISC_MM; |
| 921 | gh->msg_type = GSM48_MT_MM_ID_REQ; |
| 922 | gh->data[0] = id_type; |
| 923 | |
Harald Welte | 36fe2e8 | 2009-07-23 21:13:03 +0200 | [diff] [blame] | 924 | return gsm48_sendmsg(msg, NULL); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 925 | } |
| 926 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 927 | |
| 928 | /* Parse Chapter 9.2.11 Identity Response */ |
| 929 | static int mm_rx_id_resp(struct msgb *msg) |
| 930 | { |
| 931 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 932 | struct gsm_lchan *lchan = msg->lchan; |
Harald Welte | 7535041 | 2009-07-23 18:46:00 +0200 | [diff] [blame] | 933 | struct gsm_bts *bts = lchan->ts->trx->bts; |
| 934 | struct gsm_network *net = bts->network; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 935 | u_int8_t mi_type = gh->data[1] & GSM_MI_TYPE_MASK; |
Holger Hans Peter Freyther | 1e6ef9f | 2009-08-19 07:54:59 +0200 | [diff] [blame] | 936 | char mi_string[GSM48_MI_SIZE]; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 937 | |
Holger Hans Peter Freyther | 1e6ef9f | 2009-08-19 07:54:59 +0200 | [diff] [blame] | 938 | gsm48_mi_to_string(mi_string, sizeof(mi_string), &gh->data[1], gh->data[0]); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 939 | DEBUGP(DMM, "IDENTITY RESPONSE: mi_type=0x%02x MI(%s)\n", |
| 940 | mi_type, mi_string); |
| 941 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 942 | switch (mi_type) { |
| 943 | case GSM_MI_TYPE_IMSI: |
Jan Luebbe | 9bdbd62 | 2009-08-12 10:19:34 +0200 | [diff] [blame] | 944 | /* look up subscriber based on IMSI, create if not found */ |
| 945 | if (!lchan->subscr) { |
| 946 | lchan->subscr = subscr_get_by_imsi(net, mi_string); |
Harald Welte (local) | 16480eb | 2009-08-13 13:49:51 +0200 | [diff] [blame] | 947 | if (!lchan->subscr) |
| 948 | lchan->subscr = db_create_subscriber(net, mi_string); |
Jan Luebbe | e297403 | 2009-08-12 10:12:52 +0200 | [diff] [blame] | 949 | } |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 950 | if (lchan->loc_operation) |
| 951 | lchan->loc_operation->waiting_for_imsi = 0; |
| 952 | break; |
| 953 | case GSM_MI_TYPE_IMEI: |
| 954 | case GSM_MI_TYPE_IMEISV: |
| 955 | /* update subscribe <-> IMEI mapping */ |
Harald Welte (local) | ced09ed | 2009-08-17 09:39:55 +0200 | [diff] [blame] | 956 | if (lchan->subscr) { |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 957 | db_subscriber_assoc_imei(lchan->subscr, mi_string); |
Harald Welte (local) | ced09ed | 2009-08-17 09:39:55 +0200 | [diff] [blame] | 958 | db_sync_equipment(&lchan->subscr->equipment); |
| 959 | } |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 960 | if (lchan->loc_operation) |
| 961 | lchan->loc_operation->waiting_for_imei = 0; |
| 962 | break; |
| 963 | } |
| 964 | |
| 965 | /* Check if we can let the mobile station enter */ |
| 966 | return gsm0408_authorize(lchan, msg); |
| 967 | } |
| 968 | |
| 969 | |
| 970 | static void loc_upd_rej_cb(void *data) |
| 971 | { |
| 972 | struct gsm_lchan *lchan = data; |
| 973 | |
| 974 | release_loc_updating_req(lchan); |
| 975 | gsm0408_loc_upd_rej(lchan, reject_cause); |
| 976 | lchan_auto_release(lchan); |
| 977 | } |
| 978 | |
| 979 | static void schedule_reject(struct gsm_lchan *lchan) |
| 980 | { |
| 981 | lchan->loc_operation->updating_timer.cb = loc_upd_rej_cb; |
| 982 | lchan->loc_operation->updating_timer.data = lchan; |
| 983 | bsc_schedule_timer(&lchan->loc_operation->updating_timer, 5, 0); |
| 984 | } |
| 985 | |
| 986 | static const char *lupd_name(u_int8_t type) |
| 987 | { |
| 988 | switch (type) { |
| 989 | case GSM48_LUPD_NORMAL: |
| 990 | return "NORMAL"; |
| 991 | case GSM48_LUPD_PERIODIC: |
| 992 | return "PEROIDOC"; |
| 993 | case GSM48_LUPD_IMSI_ATT: |
| 994 | return "IMSI ATTACH"; |
| 995 | default: |
| 996 | return "UNKNOWN"; |
| 997 | } |
| 998 | } |
| 999 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1000 | /* Chapter 9.2.15: Receive Location Updating Request */ |
| 1001 | static int mm_rx_loc_upd_req(struct msgb *msg) |
| 1002 | { |
| 1003 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 1004 | struct gsm48_loc_upd_req *lu; |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1005 | struct gsm_subscriber *subscr = NULL; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1006 | struct gsm_lchan *lchan = msg->lchan; |
Harald Welte | 7535041 | 2009-07-23 18:46:00 +0200 | [diff] [blame] | 1007 | struct gsm_bts *bts = lchan->ts->trx->bts; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1008 | u_int8_t mi_type; |
Holger Hans Peter Freyther | 1e6ef9f | 2009-08-19 07:54:59 +0200 | [diff] [blame] | 1009 | char mi_string[GSM48_MI_SIZE]; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1010 | int rc; |
| 1011 | |
| 1012 | lu = (struct gsm48_loc_upd_req *) gh->data; |
| 1013 | |
| 1014 | mi_type = lu->mi[0] & GSM_MI_TYPE_MASK; |
| 1015 | |
Holger Hans Peter Freyther | 1e6ef9f | 2009-08-19 07:54:59 +0200 | [diff] [blame] | 1016 | gsm48_mi_to_string(mi_string, sizeof(mi_string), lu->mi, lu->mi_len); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1017 | |
Harald Welte | 7963966 | 2009-06-27 02:58:43 +0200 | [diff] [blame] | 1018 | DEBUGPC(DMM, "mi_type=0x%02x MI(%s) type=%s ", mi_type, mi_string, |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1019 | lupd_name(lu->type)); |
| 1020 | |
| 1021 | /* |
| 1022 | * Pseudo Spoof detection: Just drop a second/concurrent |
| 1023 | * location updating request. |
| 1024 | */ |
| 1025 | if (lchan->loc_operation) { |
Harald Welte | 7963966 | 2009-06-27 02:58:43 +0200 | [diff] [blame] | 1026 | DEBUGPC(DMM, "ignoring request due an existing one: %p.\n", |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1027 | lchan->loc_operation); |
| 1028 | gsm0408_loc_upd_rej(lchan, GSM48_REJECT_PROTOCOL_ERROR); |
| 1029 | return 0; |
| 1030 | } |
| 1031 | |
| 1032 | allocate_loc_updating_req(lchan); |
| 1033 | |
| 1034 | switch (mi_type) { |
| 1035 | case GSM_MI_TYPE_IMSI: |
Harald Welte | 7963966 | 2009-06-27 02:58:43 +0200 | [diff] [blame] | 1036 | DEBUGPC(DMM, "\n"); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1037 | /* we always want the IMEI, too */ |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1038 | rc = mm_tx_identity_req(lchan, GSM_MI_TYPE_IMEI); |
| 1039 | lchan->loc_operation->waiting_for_imei = 1; |
| 1040 | |
Jan Luebbe | 9bdbd62 | 2009-08-12 10:19:34 +0200 | [diff] [blame] | 1041 | /* look up subscriber based on IMSI, create if not found */ |
| 1042 | subscr = subscr_get_by_imsi(bts->network, mi_string); |
| 1043 | if (!subscr) { |
| 1044 | subscr = db_create_subscriber(bts->network, mi_string); |
| 1045 | } |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1046 | break; |
| 1047 | case GSM_MI_TYPE_TMSI: |
Harald Welte | 7963966 | 2009-06-27 02:58:43 +0200 | [diff] [blame] | 1048 | DEBUGPC(DMM, "\n"); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1049 | /* we always want the IMEI, too */ |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1050 | rc = mm_tx_identity_req(lchan, GSM_MI_TYPE_IMEI); |
| 1051 | lchan->loc_operation->waiting_for_imei = 1; |
| 1052 | |
| 1053 | /* look up the subscriber based on TMSI, request IMSI if it fails */ |
Holger Hans Peter Freyther | cd8bacf | 2009-08-19 12:53:57 +0200 | [diff] [blame] | 1054 | subscr = subscr_get_by_tmsi(bts->network, |
| 1055 | tmsi_from_string(mi_string)); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1056 | if (!subscr) { |
| 1057 | /* send IDENTITY REQUEST message to get IMSI */ |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1058 | rc = mm_tx_identity_req(lchan, GSM_MI_TYPE_IMSI); |
| 1059 | lchan->loc_operation->waiting_for_imsi = 1; |
| 1060 | } |
| 1061 | break; |
| 1062 | case GSM_MI_TYPE_IMEI: |
| 1063 | case GSM_MI_TYPE_IMEISV: |
| 1064 | /* no sim card... FIXME: what to do ? */ |
Harald Welte | 7963966 | 2009-06-27 02:58:43 +0200 | [diff] [blame] | 1065 | DEBUGPC(DMM, "unimplemented mobile identity type\n"); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1066 | break; |
| 1067 | default: |
Harald Welte | 7963966 | 2009-06-27 02:58:43 +0200 | [diff] [blame] | 1068 | DEBUGPC(DMM, "unknown mobile identity type\n"); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1069 | break; |
| 1070 | } |
| 1071 | |
Harald Welte | ccd6936 | 2009-07-04 10:18:00 +0200 | [diff] [blame] | 1072 | /* schedule the reject timer */ |
| 1073 | schedule_reject(lchan); |
| 1074 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1075 | if (!subscr) { |
Harald Welte | 7963966 | 2009-06-27 02:58:43 +0200 | [diff] [blame] | 1076 | DEBUGPC(DRR, "<- Can't find any subscriber for this ID\n"); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1077 | /* FIXME: request id? close channel? */ |
| 1078 | return -EINVAL; |
| 1079 | } |
| 1080 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1081 | lchan->subscr = subscr; |
Harald Welte (local) | ced09ed | 2009-08-17 09:39:55 +0200 | [diff] [blame] | 1082 | lchan->subscr->equipment.classmark1 = lu->classmark1; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1083 | |
Harald Welte | ccd6936 | 2009-07-04 10:18:00 +0200 | [diff] [blame] | 1084 | /* check if we can let the subscriber into our network immediately |
| 1085 | * or if we need to wait for identity responses. */ |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1086 | return gsm0408_authorize(lchan, msg); |
| 1087 | } |
| 1088 | |
Harald Welte | ca745e2 | 2009-07-29 12:10:35 +0200 | [diff] [blame] | 1089 | /* 9.1.5 Channel mode modify: Modify the mode on the MS side */ |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1090 | int gsm48_tx_chan_mode_modify(struct gsm_lchan *lchan, u_int8_t mode) |
| 1091 | { |
| 1092 | struct msgb *msg = gsm48_msgb_alloc(); |
| 1093 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 1094 | struct gsm48_chan_mode_modify *cmm = |
| 1095 | (struct gsm48_chan_mode_modify *) msgb_put(msg, sizeof(*cmm)); |
| 1096 | u_int16_t arfcn = lchan->ts->trx->arfcn & 0x3ff; |
| 1097 | |
| 1098 | DEBUGP(DRR, "-> CHANNEL MODE MODIFY mode=0x%02x\n", mode); |
| 1099 | |
| 1100 | lchan->tch_mode = mode; |
| 1101 | msg->lchan = lchan; |
| 1102 | gh->proto_discr = GSM48_PDISC_RR; |
| 1103 | gh->msg_type = GSM48_MT_RR_CHAN_MODE_MODIF; |
| 1104 | |
| 1105 | /* fill the channel information element, this code |
| 1106 | * should probably be shared with rsl_rx_chan_rqd() */ |
| 1107 | cmm->chan_desc.chan_nr = lchan2chan_nr(lchan); |
| 1108 | cmm->chan_desc.h0.tsc = lchan->ts->trx->bts->tsc; |
| 1109 | cmm->chan_desc.h0.h = 0; |
| 1110 | cmm->chan_desc.h0.arfcn_high = arfcn >> 8; |
| 1111 | cmm->chan_desc.h0.arfcn_low = arfcn & 0xff; |
| 1112 | cmm->mode = mode; |
| 1113 | |
Harald Welte | 36fe2e8 | 2009-07-23 21:13:03 +0200 | [diff] [blame] | 1114 | return gsm48_sendmsg(msg, NULL); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1115 | } |
| 1116 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1117 | #if 0 |
| 1118 | static u_int8_t to_bcd8(u_int8_t val) |
| 1119 | { |
| 1120 | return ((val / 10) << 4) | (val % 10); |
| 1121 | } |
| 1122 | #endif |
| 1123 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1124 | /* Section 9.2.15a */ |
| 1125 | int gsm48_tx_mm_info(struct gsm_lchan *lchan) |
| 1126 | { |
| 1127 | struct msgb *msg = gsm48_msgb_alloc(); |
| 1128 | struct gsm48_hdr *gh; |
| 1129 | struct gsm_network *net = lchan->ts->trx->bts->network; |
| 1130 | u_int8_t *ptr8; |
| 1131 | u_int16_t *ptr16; |
Daniel Willmann | c818820 | 2009-08-13 03:42:07 +0200 | [diff] [blame] | 1132 | int name_len, name_pad; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1133 | int i; |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1134 | #if 0 |
| 1135 | time_t cur_t; |
| 1136 | struct tm* cur_time; |
| 1137 | int tz15min; |
| 1138 | #endif |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1139 | |
| 1140 | msg->lchan = lchan; |
| 1141 | |
| 1142 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 1143 | gh->proto_discr = GSM48_PDISC_MM; |
| 1144 | gh->msg_type = GSM48_MT_MM_INFO; |
| 1145 | |
| 1146 | if (net->name_long) { |
Daniel Willmann | c818820 | 2009-08-13 03:42:07 +0200 | [diff] [blame] | 1147 | #if 0 |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1148 | name_len = strlen(net->name_long); |
| 1149 | /* 10.5.3.5a */ |
| 1150 | ptr8 = msgb_put(msg, 3); |
| 1151 | ptr8[0] = GSM48_IE_NAME_LONG; |
| 1152 | ptr8[1] = name_len*2 +1; |
| 1153 | ptr8[2] = 0x90; /* UCS2, no spare bits, no CI */ |
| 1154 | |
| 1155 | ptr16 = (u_int16_t *) msgb_put(msg, name_len*2); |
| 1156 | for (i = 0; i < name_len; i++) |
| 1157 | ptr16[i] = htons(net->name_long[i]); |
| 1158 | |
| 1159 | /* FIXME: Use Cell Broadcast, not UCS-2, since |
| 1160 | * UCS-2 is only supported by later revisions of the spec */ |
Daniel Willmann | c818820 | 2009-08-13 03:42:07 +0200 | [diff] [blame] | 1161 | #endif |
| 1162 | name_len = (strlen(net->name_long)*7)/8; |
| 1163 | name_pad = (8 - strlen(net->name_long)*7)%8; |
| 1164 | if (name_pad > 0) |
| 1165 | name_len++; |
| 1166 | /* 10.5.3.5a */ |
| 1167 | ptr8 = msgb_put(msg, 3); |
| 1168 | ptr8[0] = GSM48_IE_NAME_LONG; |
| 1169 | ptr8[1] = name_len +1; |
| 1170 | ptr8[2] = 0x80 | name_pad; /* Cell Broadcast DCS, no CI */ |
| 1171 | |
| 1172 | ptr8 = msgb_put(msg, name_len); |
| 1173 | gsm_7bit_encode(ptr8, net->name_long); |
| 1174 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1175 | } |
| 1176 | |
| 1177 | if (net->name_short) { |
Daniel Willmann | c818820 | 2009-08-13 03:42:07 +0200 | [diff] [blame] | 1178 | #if 0 |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1179 | name_len = strlen(net->name_short); |
| 1180 | /* 10.5.3.5a */ |
| 1181 | ptr8 = (u_int8_t *) msgb_put(msg, 3); |
Harald Welte | f628471 | 2009-07-19 17:51:36 +0200 | [diff] [blame] | 1182 | ptr8[0] = GSM48_IE_NAME_SHORT; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1183 | ptr8[1] = name_len*2 + 1; |
| 1184 | ptr8[2] = 0x90; /* UCS2, no spare bits, no CI */ |
| 1185 | |
| 1186 | ptr16 = (u_int16_t *) msgb_put(msg, name_len*2); |
| 1187 | for (i = 0; i < name_len; i++) |
| 1188 | ptr16[i] = htons(net->name_short[i]); |
Daniel Willmann | c818820 | 2009-08-13 03:42:07 +0200 | [diff] [blame] | 1189 | #endif |
| 1190 | name_len = (strlen(net->name_short)*7)/8; |
| 1191 | name_pad = (8 - strlen(net->name_short)*7)%8; |
| 1192 | if (name_pad > 0) |
| 1193 | name_len++; |
| 1194 | /* 10.5.3.5a */ |
| 1195 | ptr8 = (u_int8_t *) msgb_put(msg, 3); |
| 1196 | ptr8[0] = GSM48_IE_NAME_SHORT; |
| 1197 | ptr8[1] = name_len +1; |
| 1198 | ptr8[2] = 0x80 | name_pad; /* Cell Broadcast DCS, no CI */ |
| 1199 | |
| 1200 | ptr8 = msgb_put(msg, name_len); |
| 1201 | gsm_7bit_encode(ptr8, net->name_short); |
| 1202 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1203 | } |
| 1204 | |
| 1205 | #if 0 |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1206 | /* Section 10.5.3.9 */ |
| 1207 | cur_t = time(NULL); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1208 | cur_time = gmtime(&cur_t); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1209 | ptr8 = msgb_put(msg, 8); |
| 1210 | ptr8[0] = GSM48_IE_NET_TIME_TZ; |
| 1211 | ptr8[1] = to_bcd8(cur_time->tm_year % 100); |
| 1212 | ptr8[2] = to_bcd8(cur_time->tm_mon); |
| 1213 | ptr8[3] = to_bcd8(cur_time->tm_mday); |
| 1214 | ptr8[4] = to_bcd8(cur_time->tm_hour); |
| 1215 | ptr8[5] = to_bcd8(cur_time->tm_min); |
| 1216 | ptr8[6] = to_bcd8(cur_time->tm_sec); |
| 1217 | /* 02.42: coded as BCD encoded signed value in units of 15 minutes */ |
| 1218 | tz15min = (cur_time->tm_gmtoff)/(60*15); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1219 | ptr8[7] = to_bcd8(tz15min); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1220 | if (tz15min < 0) |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1221 | ptr8[7] |= 0x80; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1222 | #endif |
| 1223 | |
Daniel Willmann | c818820 | 2009-08-13 03:42:07 +0200 | [diff] [blame] | 1224 | DEBUGP(DMM, "-> MM INFO\n"); |
| 1225 | |
Harald Welte | 36fe2e8 | 2009-07-23 21:13:03 +0200 | [diff] [blame] | 1226 | return gsm48_sendmsg(msg, NULL); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1227 | } |
| 1228 | |
Harald Welte | 36970f6 | 2009-08-12 22:56:50 +0200 | [diff] [blame] | 1229 | /* Section 9.2.2 */ |
| 1230 | int gsm48_tx_mm_auth_req(struct gsm_lchan *lchan, u_int8_t *rand) |
| 1231 | { |
| 1232 | struct msgb *msg = gsm48_msgb_alloc(); |
| 1233 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
Sylvain Munaut | 6de6dc1 | 2009-09-27 11:10:17 +0200 | [diff] [blame] | 1234 | struct gsm48_auth_req *ar = (struct gsm48_auth_req *) msgb_put(msg, sizeof(*ar)); |
Harald Welte | 36970f6 | 2009-08-12 22:56:50 +0200 | [diff] [blame] | 1235 | |
| 1236 | DEBUGP(DMM, "-> AUTH REQ\n"); |
| 1237 | |
| 1238 | msg->lchan = lchan; |
| 1239 | gh->proto_discr = GSM48_PDISC_MM; |
| 1240 | gh->msg_type = GSM48_MT_MM_AUTH_REQ; |
| 1241 | |
Sylvain Munaut | 6de6dc1 | 2009-09-27 11:10:17 +0200 | [diff] [blame] | 1242 | /* Key Sequence: FIXME fixed to 0 */ |
| 1243 | ar->key_seq = 0; |
| 1244 | |
Harald Welte | 36970f6 | 2009-08-12 22:56:50 +0200 | [diff] [blame] | 1245 | /* 16 bytes RAND parameters */ |
Harald Welte | 36970f6 | 2009-08-12 22:56:50 +0200 | [diff] [blame] | 1246 | if (rand) |
Sylvain Munaut | 6de6dc1 | 2009-09-27 11:10:17 +0200 | [diff] [blame] | 1247 | memcpy(ar->rand, rand, 16); |
Harald Welte | 36970f6 | 2009-08-12 22:56:50 +0200 | [diff] [blame] | 1248 | |
| 1249 | return gsm48_sendmsg(msg, NULL); |
| 1250 | } |
| 1251 | |
| 1252 | /* Section 9.2.1 */ |
| 1253 | int gsm48_tx_mm_auth_rej(struct gsm_lchan *lchan) |
| 1254 | { |
| 1255 | DEBUGP(DMM, "-> AUTH REJECT\n"); |
| 1256 | return gsm48_tx_simple(lchan, GSM48_PDISC_MM, GSM48_MT_MM_AUTH_REJ); |
| 1257 | } |
| 1258 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1259 | static int gsm48_tx_mm_serv_ack(struct gsm_lchan *lchan) |
| 1260 | { |
| 1261 | DEBUGP(DMM, "-> CM SERVICE ACK\n"); |
| 1262 | return gsm48_tx_simple(lchan, GSM48_PDISC_MM, GSM48_MT_MM_CM_SERV_ACC); |
| 1263 | } |
| 1264 | |
| 1265 | /* 9.2.6 CM service reject */ |
| 1266 | static int gsm48_tx_mm_serv_rej(struct gsm_lchan *lchan, |
| 1267 | enum gsm48_reject_value value) |
| 1268 | { |
| 1269 | struct msgb *msg = gsm48_msgb_alloc(); |
| 1270 | struct gsm48_hdr *gh; |
| 1271 | |
| 1272 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 1); |
| 1273 | |
| 1274 | msg->lchan = lchan; |
| 1275 | use_lchan(lchan); |
| 1276 | |
| 1277 | gh->proto_discr = GSM48_PDISC_MM; |
| 1278 | gh->msg_type = GSM48_MT_MM_CM_SERV_REJ; |
| 1279 | gh->data[0] = value; |
| 1280 | DEBUGP(DMM, "-> CM SERVICE Reject cause: %d\n", value); |
| 1281 | |
Harald Welte | 36fe2e8 | 2009-07-23 21:13:03 +0200 | [diff] [blame] | 1282 | return gsm48_sendmsg(msg, NULL); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1283 | } |
| 1284 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1285 | /* |
| 1286 | * Handle CM Service Requests |
| 1287 | * a) Verify that the packet is long enough to contain the information |
| 1288 | * we require otherwsie reject with INCORRECT_MESSAGE |
| 1289 | * b) Try to parse the TMSI. If we do not have one reject |
| 1290 | * c) Check that we know the subscriber with the TMSI otherwise reject |
| 1291 | * with a HLR cause |
| 1292 | * d) Set the subscriber on the gsm_lchan and accept |
| 1293 | */ |
| 1294 | static int gsm48_rx_mm_serv_req(struct msgb *msg) |
| 1295 | { |
| 1296 | u_int8_t mi_type; |
Holger Hans Peter Freyther | 1e6ef9f | 2009-08-19 07:54:59 +0200 | [diff] [blame] | 1297 | char mi_string[GSM48_MI_SIZE]; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1298 | |
Harald Welte | 7535041 | 2009-07-23 18:46:00 +0200 | [diff] [blame] | 1299 | struct gsm_bts *bts = msg->lchan->ts->trx->bts; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1300 | struct gsm_subscriber *subscr; |
| 1301 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 1302 | struct gsm48_service_request *req = |
| 1303 | (struct gsm48_service_request *)gh->data; |
| 1304 | /* unfortunately in Phase1 the classmar2 length is variable */ |
| 1305 | u_int8_t classmark2_len = gh->data[1]; |
| 1306 | u_int8_t *classmark2 = gh->data+2; |
| 1307 | u_int8_t mi_len = *(classmark2 + classmark2_len); |
| 1308 | u_int8_t *mi = (classmark2 + classmark2_len + 1); |
| 1309 | |
| 1310 | DEBUGP(DMM, "<- CM SERVICE REQUEST "); |
| 1311 | if (msg->data_len < sizeof(struct gsm48_service_request*)) { |
| 1312 | DEBUGPC(DMM, "wrong sized message\n"); |
| 1313 | return gsm48_tx_mm_serv_rej(msg->lchan, |
| 1314 | GSM48_REJECT_INCORRECT_MESSAGE); |
| 1315 | } |
| 1316 | |
| 1317 | if (msg->data_len < req->mi_len + 6) { |
| 1318 | DEBUGPC(DMM, "does not fit in packet\n"); |
| 1319 | return gsm48_tx_mm_serv_rej(msg->lchan, |
| 1320 | GSM48_REJECT_INCORRECT_MESSAGE); |
| 1321 | } |
| 1322 | |
| 1323 | mi_type = mi[0] & GSM_MI_TYPE_MASK; |
| 1324 | if (mi_type != GSM_MI_TYPE_TMSI) { |
| 1325 | DEBUGPC(DMM, "mi_type is not TMSI: %d\n", mi_type); |
| 1326 | return gsm48_tx_mm_serv_rej(msg->lchan, |
| 1327 | GSM48_REJECT_INCORRECT_MESSAGE); |
| 1328 | } |
| 1329 | |
Holger Hans Peter Freyther | 1e6ef9f | 2009-08-19 07:54:59 +0200 | [diff] [blame] | 1330 | gsm48_mi_to_string(mi_string, sizeof(mi_string), mi, mi_len); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1331 | DEBUGPC(DMM, "serv_type=0x%02x mi_type=0x%02x M(%s)\n", |
| 1332 | req->cm_service_type, mi_type, mi_string); |
| 1333 | |
Harald Welte | 583ceaf | 2009-08-10 10:12:45 +0200 | [diff] [blame] | 1334 | if (is_siemens_bts(bts)) |
| 1335 | send_siemens_mrpci(msg->lchan, classmark2-1); |
| 1336 | |
Holger Hans Peter Freyther | cd8bacf | 2009-08-19 12:53:57 +0200 | [diff] [blame] | 1337 | subscr = subscr_get_by_tmsi(bts->network, |
| 1338 | tmsi_from_string(mi_string)); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1339 | |
| 1340 | /* FIXME: if we don't know the TMSI, inquire abit IMSI and allocate new TMSI */ |
| 1341 | if (!subscr) |
| 1342 | return gsm48_tx_mm_serv_rej(msg->lchan, |
| 1343 | GSM48_REJECT_IMSI_UNKNOWN_IN_HLR); |
| 1344 | |
| 1345 | if (!msg->lchan->subscr) |
| 1346 | msg->lchan->subscr = subscr; |
| 1347 | else if (msg->lchan->subscr != subscr) { |
| 1348 | DEBUGP(DMM, "<- CM Channel already owned by someone else?\n"); |
| 1349 | subscr_put(subscr); |
| 1350 | } |
| 1351 | |
Harald Welte | f6845a7 | 2009-07-05 14:08:13 +0200 | [diff] [blame] | 1352 | subscr->equipment.classmark2_len = classmark2_len; |
| 1353 | memcpy(subscr->equipment.classmark2, classmark2, classmark2_len); |
| 1354 | db_sync_equipment(&subscr->equipment); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1355 | |
| 1356 | return gsm48_tx_mm_serv_ack(msg->lchan); |
| 1357 | } |
| 1358 | |
| 1359 | static int gsm48_rx_mm_imsi_detach_ind(struct msgb *msg) |
| 1360 | { |
Harald Welte | 7535041 | 2009-07-23 18:46:00 +0200 | [diff] [blame] | 1361 | struct gsm_bts *bts = msg->lchan->ts->trx->bts; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1362 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 1363 | struct gsm48_imsi_detach_ind *idi = |
| 1364 | (struct gsm48_imsi_detach_ind *) gh->data; |
| 1365 | u_int8_t mi_type = idi->mi[0] & GSM_MI_TYPE_MASK; |
Holger Hans Peter Freyther | 1e6ef9f | 2009-08-19 07:54:59 +0200 | [diff] [blame] | 1366 | char mi_string[GSM48_MI_SIZE]; |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1367 | struct gsm_subscriber *subscr = NULL; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1368 | |
Holger Hans Peter Freyther | 1e6ef9f | 2009-08-19 07:54:59 +0200 | [diff] [blame] | 1369 | gsm48_mi_to_string(mi_string, sizeof(mi_string), idi->mi, idi->mi_len); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1370 | DEBUGP(DMM, "IMSI DETACH INDICATION: mi_type=0x%02x MI(%s): ", |
| 1371 | mi_type, mi_string); |
| 1372 | |
| 1373 | switch (mi_type) { |
| 1374 | case GSM_MI_TYPE_TMSI: |
Holger Hans Peter Freyther | cd8bacf | 2009-08-19 12:53:57 +0200 | [diff] [blame] | 1375 | subscr = subscr_get_by_tmsi(bts->network, |
| 1376 | tmsi_from_string(mi_string)); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1377 | break; |
| 1378 | case GSM_MI_TYPE_IMSI: |
Harald Welte | 7535041 | 2009-07-23 18:46:00 +0200 | [diff] [blame] | 1379 | subscr = subscr_get_by_imsi(bts->network, mi_string); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1380 | break; |
| 1381 | case GSM_MI_TYPE_IMEI: |
| 1382 | case GSM_MI_TYPE_IMEISV: |
| 1383 | /* no sim card... FIXME: what to do ? */ |
| 1384 | DEBUGPC(DMM, "unimplemented mobile identity type\n"); |
| 1385 | break; |
| 1386 | default: |
| 1387 | DEBUGPC(DMM, "unknown mobile identity type\n"); |
| 1388 | break; |
| 1389 | } |
| 1390 | |
| 1391 | if (subscr) { |
| 1392 | subscr_update(subscr, msg->trx->bts, |
| 1393 | GSM_SUBSCRIBER_UPDATE_DETACHED); |
| 1394 | DEBUGP(DMM, "Subscriber: %s\n", |
| 1395 | subscr->name ? subscr->name : subscr->imsi); |
Harald Welte (local) | ced09ed | 2009-08-17 09:39:55 +0200 | [diff] [blame] | 1396 | |
| 1397 | subscr->equipment.classmark1 = idi->classmark1; |
| 1398 | db_sync_equipment(&subscr->equipment); |
| 1399 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1400 | subscr_put(subscr); |
| 1401 | } else |
| 1402 | DEBUGP(DMM, "Unknown Subscriber ?!?\n"); |
| 1403 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1404 | return 0; |
| 1405 | } |
| 1406 | |
| 1407 | static int gsm48_rx_mm_status(struct msgb *msg) |
| 1408 | { |
| 1409 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 1410 | |
| 1411 | DEBUGP(DMM, "MM STATUS (reject cause 0x%02x)\n", gh->data[0]); |
| 1412 | |
| 1413 | return 0; |
| 1414 | } |
| 1415 | |
| 1416 | /* Receive a GSM 04.08 Mobility Management (MM) message */ |
| 1417 | static int gsm0408_rcv_mm(struct msgb *msg) |
| 1418 | { |
| 1419 | struct gsm48_hdr *gh = msgb_l3(msg); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1420 | int rc = 0; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1421 | |
| 1422 | switch (gh->msg_type & 0xbf) { |
| 1423 | case GSM48_MT_MM_LOC_UPD_REQUEST: |
Harald Welte | 7963966 | 2009-06-27 02:58:43 +0200 | [diff] [blame] | 1424 | DEBUGP(DMM, "LOCATION UPDATING REQUEST: "); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1425 | rc = mm_rx_loc_upd_req(msg); |
| 1426 | break; |
| 1427 | case GSM48_MT_MM_ID_RESP: |
| 1428 | rc = mm_rx_id_resp(msg); |
| 1429 | break; |
| 1430 | case GSM48_MT_MM_CM_SERV_REQ: |
| 1431 | rc = gsm48_rx_mm_serv_req(msg); |
| 1432 | break; |
| 1433 | case GSM48_MT_MM_STATUS: |
| 1434 | rc = gsm48_rx_mm_status(msg); |
| 1435 | break; |
| 1436 | case GSM48_MT_MM_TMSI_REALL_COMPL: |
| 1437 | DEBUGP(DMM, "TMSI Reallocation Completed. Subscriber: %s\n", |
| 1438 | msg->lchan->subscr ? |
| 1439 | msg->lchan->subscr->imsi : |
| 1440 | "unknown subscriber"); |
| 1441 | break; |
| 1442 | case GSM48_MT_MM_IMSI_DETACH_IND: |
| 1443 | rc = gsm48_rx_mm_imsi_detach_ind(msg); |
| 1444 | break; |
| 1445 | case GSM48_MT_MM_CM_REEST_REQ: |
| 1446 | DEBUGP(DMM, "CM REESTABLISH REQUEST: Not implemented\n"); |
| 1447 | break; |
| 1448 | case GSM48_MT_MM_AUTH_RESP: |
| 1449 | DEBUGP(DMM, "AUTHENTICATION RESPONSE: Not implemented\n"); |
| 1450 | break; |
| 1451 | default: |
| 1452 | fprintf(stderr, "Unknown GSM 04.08 MM msg type 0x%02x\n", |
| 1453 | gh->msg_type); |
| 1454 | break; |
| 1455 | } |
| 1456 | |
| 1457 | return rc; |
| 1458 | } |
| 1459 | |
| 1460 | /* Receive a PAGING RESPONSE message from the MS */ |
| 1461 | static int gsm48_rr_rx_pag_resp(struct msgb *msg) |
| 1462 | { |
Harald Welte | 7535041 | 2009-07-23 18:46:00 +0200 | [diff] [blame] | 1463 | struct gsm_bts *bts = msg->lchan->ts->trx->bts; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1464 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 1465 | u_int8_t *classmark2_lv = gh->data + 1; |
Holger Hans Peter Freyther | 1e43b8d | 2009-08-21 05:18:21 +0200 | [diff] [blame] | 1466 | u_int8_t mi_type; |
Holger Hans Peter Freyther | 1e6ef9f | 2009-08-19 07:54:59 +0200 | [diff] [blame] | 1467 | char mi_string[GSM48_MI_SIZE]; |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1468 | struct gsm_subscriber *subscr = NULL; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1469 | int rc = 0; |
| 1470 | |
Holger Hans Peter Freyther | 1e43b8d | 2009-08-21 05:18:21 +0200 | [diff] [blame] | 1471 | gsm48_paging_extract_mi(msg, mi_string, &mi_type); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1472 | DEBUGP(DRR, "PAGING RESPONSE: mi_type=0x%02x MI(%s)\n", |
| 1473 | mi_type, mi_string); |
Harald Welte | 583ceaf | 2009-08-10 10:12:45 +0200 | [diff] [blame] | 1474 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1475 | switch (mi_type) { |
| 1476 | case GSM_MI_TYPE_TMSI: |
Holger Hans Peter Freyther | cd8bacf | 2009-08-19 12:53:57 +0200 | [diff] [blame] | 1477 | subscr = subscr_get_by_tmsi(bts->network, |
| 1478 | tmsi_from_string(mi_string)); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1479 | break; |
| 1480 | case GSM_MI_TYPE_IMSI: |
Harald Welte | 7535041 | 2009-07-23 18:46:00 +0200 | [diff] [blame] | 1481 | subscr = subscr_get_by_imsi(bts->network, mi_string); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1482 | break; |
| 1483 | } |
| 1484 | |
| 1485 | if (!subscr) { |
| 1486 | DEBUGP(DRR, "<- Can't find any subscriber for this ID\n"); |
| 1487 | /* FIXME: request id? close channel? */ |
| 1488 | return -EINVAL; |
| 1489 | } |
| 1490 | DEBUGP(DRR, "<- Channel was requested by %s\n", |
Harald Welte | 68b7df2 | 2009-08-08 16:03:15 +0200 | [diff] [blame] | 1491 | subscr->name && strlen(subscr->name) ? subscr->name : subscr->imsi); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1492 | |
Harald Welte | f6845a7 | 2009-07-05 14:08:13 +0200 | [diff] [blame] | 1493 | subscr->equipment.classmark2_len = *classmark2_lv; |
| 1494 | memcpy(subscr->equipment.classmark2, classmark2_lv+1, *classmark2_lv); |
| 1495 | db_sync_equipment(&subscr->equipment); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1496 | |
Holger Hans Peter Freyther | 1e43b8d | 2009-08-21 05:18:21 +0200 | [diff] [blame] | 1497 | rc = gsm48_handle_paging_resp(msg, subscr); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1498 | return rc; |
| 1499 | } |
| 1500 | |
| 1501 | static int gsm48_rx_rr_classmark(struct msgb *msg) |
| 1502 | { |
| 1503 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 1504 | struct gsm_subscriber *subscr = msg->lchan->subscr; |
| 1505 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 1506 | u_int8_t cm2_len, cm3_len = 0; |
| 1507 | u_int8_t *cm2, *cm3 = NULL; |
| 1508 | |
| 1509 | DEBUGP(DRR, "CLASSMARK CHANGE "); |
| 1510 | |
| 1511 | /* classmark 2 */ |
| 1512 | cm2_len = gh->data[0]; |
| 1513 | cm2 = &gh->data[1]; |
| 1514 | DEBUGPC(DRR, "CM2(len=%u) ", cm2_len); |
| 1515 | |
| 1516 | if (payload_len > cm2_len + 1) { |
| 1517 | /* we must have a classmark3 */ |
| 1518 | if (gh->data[cm2_len+1] != 0x20) { |
| 1519 | DEBUGPC(DRR, "ERR CM3 TAG\n"); |
| 1520 | return -EINVAL; |
| 1521 | } |
| 1522 | if (cm2_len > 3) { |
| 1523 | DEBUGPC(DRR, "CM2 too long!\n"); |
| 1524 | return -EINVAL; |
| 1525 | } |
| 1526 | |
| 1527 | cm3_len = gh->data[cm2_len+2]; |
| 1528 | cm3 = &gh->data[cm2_len+3]; |
| 1529 | if (cm3_len > 14) { |
| 1530 | DEBUGPC(DRR, "CM3 len %u too long!\n", cm3_len); |
| 1531 | return -EINVAL; |
| 1532 | } |
| 1533 | DEBUGPC(DRR, "CM3(len=%u)\n", cm3_len); |
| 1534 | } |
| 1535 | if (subscr) { |
Harald Welte | f6845a7 | 2009-07-05 14:08:13 +0200 | [diff] [blame] | 1536 | subscr->equipment.classmark2_len = cm2_len; |
| 1537 | memcpy(subscr->equipment.classmark2, cm2, cm2_len); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1538 | if (cm3) { |
Harald Welte | f6845a7 | 2009-07-05 14:08:13 +0200 | [diff] [blame] | 1539 | subscr->equipment.classmark3_len = cm3_len; |
| 1540 | memcpy(subscr->equipment.classmark3, cm3, cm3_len); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1541 | } |
Harald Welte | f6845a7 | 2009-07-05 14:08:13 +0200 | [diff] [blame] | 1542 | db_sync_equipment(&subscr->equipment); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1543 | } |
| 1544 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1545 | return 0; |
| 1546 | } |
| 1547 | |
| 1548 | static int gsm48_rx_rr_status(struct msgb *msg) |
| 1549 | { |
| 1550 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 1551 | |
| 1552 | DEBUGP(DRR, "STATUS rr_cause = %s\n", |
| 1553 | rr_cause_name(gh->data[0])); |
| 1554 | |
| 1555 | return 0; |
| 1556 | } |
| 1557 | |
| 1558 | static int gsm48_rx_rr_meas_rep(struct msgb *msg) |
| 1559 | { |
| 1560 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 1561 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 1562 | static struct gsm_meas_rep meas_rep; |
| 1563 | |
Harald Welte | 0299368 | 2009-06-27 02:53:10 +0200 | [diff] [blame] | 1564 | DEBUGP(DMEAS, "MEASUREMENT REPORT "); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1565 | parse_meas_rep(&meas_rep, gh->data, payload_len); |
| 1566 | if (meas_rep.flags & MEAS_REP_F_DTX) |
Harald Welte | 0299368 | 2009-06-27 02:53:10 +0200 | [diff] [blame] | 1567 | DEBUGPC(DMEAS, "DTX "); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1568 | if (meas_rep.flags & MEAS_REP_F_BA1) |
Harald Welte | 0299368 | 2009-06-27 02:53:10 +0200 | [diff] [blame] | 1569 | DEBUGPC(DMEAS, "BA1 "); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1570 | if (!(meas_rep.flags & MEAS_REP_F_VALID)) |
Harald Welte | 0299368 | 2009-06-27 02:53:10 +0200 | [diff] [blame] | 1571 | DEBUGPC(DMEAS, "NOT VALID "); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1572 | else |
Harald Welte | 0299368 | 2009-06-27 02:53:10 +0200 | [diff] [blame] | 1573 | DEBUGPC(DMEAS, "FULL(lev=%u, qual=%u) SUB(lev=%u, qual=%u) ", |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1574 | meas_rep.rxlev_full, meas_rep.rxqual_full, meas_rep.rxlev_sub, |
| 1575 | meas_rep.rxqual_sub); |
| 1576 | |
Harald Welte | 0299368 | 2009-06-27 02:53:10 +0200 | [diff] [blame] | 1577 | DEBUGPC(DMEAS, "NUM_NEIGH=%u\n", meas_rep.num_cell); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1578 | |
| 1579 | /* FIXME: put the results somwhere */ |
| 1580 | |
| 1581 | return 0; |
| 1582 | } |
| 1583 | |
Harald Welte (local) | b510392 | 2009-08-15 23:32:44 +0200 | [diff] [blame] | 1584 | static int gsm48_rx_rr_app_info(struct msgb *msg) |
| 1585 | { |
| 1586 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 1587 | u_int8_t apdu_id_flags; |
| 1588 | u_int8_t apdu_len; |
| 1589 | u_int8_t *apdu_data; |
| 1590 | |
| 1591 | apdu_id_flags = gh->data[0]; |
| 1592 | apdu_len = gh->data[1]; |
| 1593 | apdu_data = gh->data+2; |
| 1594 | |
| 1595 | DEBUGP(DNM, "RX APPLICATION INFO id/flags=0x%02x apdu_len=%u apdu=%s", |
| 1596 | apdu_id_flags, apdu_len, hexdump(apdu_data, apdu_len)); |
| 1597 | |
Harald Welte (local) | bd72aa2 | 2009-08-16 10:40:10 +0200 | [diff] [blame] | 1598 | return db_apdu_blob_store(msg->lchan->subscr, apdu_id_flags, apdu_len, apdu_data); |
Harald Welte (local) | b510392 | 2009-08-15 23:32:44 +0200 | [diff] [blame] | 1599 | } |
| 1600 | |
| 1601 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1602 | /* Receive a GSM 04.08 Radio Resource (RR) message */ |
| 1603 | static int gsm0408_rcv_rr(struct msgb *msg) |
| 1604 | { |
| 1605 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 1606 | int rc = 0; |
| 1607 | |
| 1608 | switch (gh->msg_type) { |
| 1609 | case GSM48_MT_RR_CLSM_CHG: |
| 1610 | rc = gsm48_rx_rr_classmark(msg); |
| 1611 | break; |
| 1612 | case GSM48_MT_RR_GPRS_SUSP_REQ: |
| 1613 | DEBUGP(DRR, "GRPS SUSPEND REQUEST\n"); |
| 1614 | break; |
| 1615 | case GSM48_MT_RR_PAG_RESP: |
| 1616 | rc = gsm48_rr_rx_pag_resp(msg); |
| 1617 | break; |
| 1618 | case GSM48_MT_RR_CHAN_MODE_MODIF_ACK: |
| 1619 | DEBUGP(DRR, "CHANNEL MODE MODIFY ACK\n"); |
Harald Welte | ca745e2 | 2009-07-29 12:10:35 +0200 | [diff] [blame] | 1620 | /* We've successfully modified the MS side of the channel, |
| 1621 | * now go on to modify the BTS side of the channel */ |
Harald Welte | 39274f4 | 2009-07-29 15:41:29 +0200 | [diff] [blame] | 1622 | msg->lchan->rsl_cmode = RSL_CMOD_SPD_SPEECH; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1623 | rc = rsl_chan_mode_modify_req(msg->lchan); |
| 1624 | break; |
| 1625 | case GSM48_MT_RR_STATUS: |
| 1626 | rc = gsm48_rx_rr_status(msg); |
| 1627 | break; |
| 1628 | case GSM48_MT_RR_MEAS_REP: |
| 1629 | rc = gsm48_rx_rr_meas_rep(msg); |
| 1630 | break; |
Harald Welte (local) | b510392 | 2009-08-15 23:32:44 +0200 | [diff] [blame] | 1631 | case GSM48_MT_RR_APP_INFO: |
| 1632 | rc = gsm48_rx_rr_app_info(msg); |
| 1633 | break; |
Harald Welte | d2dd9de | 2009-08-30 15:37:11 +0900 | [diff] [blame] | 1634 | case GSM48_MT_RR_CIPH_M_COMPL: |
| 1635 | DEBUGP(DRR, "CIPHERING MODE COMPLETE\n"); |
| 1636 | /* FIXME: check for MI (if any) */ |
| 1637 | break; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1638 | default: |
| 1639 | fprintf(stderr, "Unimplemented GSM 04.08 RR msg type 0x%02x\n", |
| 1640 | gh->msg_type); |
| 1641 | break; |
| 1642 | } |
| 1643 | |
| 1644 | return rc; |
| 1645 | } |
| 1646 | |
Harald Welte | d2dd9de | 2009-08-30 15:37:11 +0900 | [diff] [blame] | 1647 | /* Chapter 9.1.9: Ciphering Mode Command */ |
| 1648 | int gsm48_send_rr_ciph_mode(struct gsm_lchan *lchan) |
| 1649 | { |
| 1650 | struct msgb *msg = gsm48_msgb_alloc(); |
| 1651 | struct gsm48_hdr *gh; |
| 1652 | u_int8_t ciph_mod_set; |
| 1653 | |
| 1654 | msg->lchan = lchan; |
| 1655 | |
| 1656 | DEBUGP(DRR, "TX CIPHERING MODE CMD\n"); |
| 1657 | |
| 1658 | if (lchan->encr.alg_id <= RSL_ENC_ALG_A5(0)) |
| 1659 | ciph_mod_set = 0; |
| 1660 | else |
Sylvain Munaut | a948c11 | 2009-09-27 11:11:41 +0200 | [diff] [blame] | 1661 | ciph_mod_set = (lchan->encr.alg_id-2)<<1 | 1; |
Harald Welte | d2dd9de | 2009-08-30 15:37:11 +0900 | [diff] [blame] | 1662 | |
| 1663 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 1); |
| 1664 | gh->proto_discr = GSM48_PDISC_RR; |
| 1665 | gh->msg_type = GSM48_MT_RR_CIPH_M_CMD; |
| 1666 | gh->data[0] = 0x10 | (ciph_mod_set & 0xf); |
| 1667 | |
| 1668 | return rsl_encryption_cmd(msg); |
| 1669 | } |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1670 | |
Harald Welte (local) | b510392 | 2009-08-15 23:32:44 +0200 | [diff] [blame] | 1671 | int gsm48_send_rr_app_info(struct gsm_lchan *lchan, u_int8_t apdu_id, |
| 1672 | u_int8_t apdu_len, u_int8_t *apdu) |
| 1673 | { |
| 1674 | struct msgb *msg = gsm48_msgb_alloc(); |
| 1675 | struct gsm48_hdr *gh; |
| 1676 | |
| 1677 | msg->lchan = lchan; |
| 1678 | |
| 1679 | DEBUGP(DRR, "TX APPLICATION INFO id=0x%02x, len=%u\n", |
| 1680 | apdu_id, apdu_len); |
| 1681 | |
| 1682 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 2 + apdu_len); |
| 1683 | gh->proto_discr = GSM48_PDISC_RR; |
| 1684 | gh->msg_type = GSM48_MT_RR_APP_INFO; |
| 1685 | gh->data[0] = apdu_id; |
| 1686 | gh->data[1] = apdu_len; |
| 1687 | memcpy(gh->data+2, apdu, apdu_len); |
| 1688 | |
| 1689 | return gsm48_sendmsg(msg, NULL); |
| 1690 | } |
| 1691 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1692 | /* Call Control */ |
| 1693 | |
| 1694 | /* The entire call control code is written in accordance with Figure 7.10c |
| 1695 | * for 'very early assignment', i.e. we allocate a TCH/F during IMMEDIATE |
| 1696 | * ASSIGN, then first use that TCH/F for signalling and later MODE MODIFY |
| 1697 | * it for voice */ |
| 1698 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1699 | static void new_cc_state(struct gsm_trans *trans, int state) |
| 1700 | { |
| 1701 | if (state > 31 || state < 0) |
| 1702 | return; |
| 1703 | |
| 1704 | DEBUGP(DCC, "new state %s -> %s\n", |
Harald Welte | c2189a6 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 1705 | cc_state_names[trans->cc.state], cc_state_names[state]); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1706 | |
Harald Welte | c2189a6 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 1707 | trans->cc.state = state; |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1708 | } |
| 1709 | |
| 1710 | static int gsm48_cc_tx_status(struct gsm_trans *trans, void *arg) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1711 | { |
| 1712 | struct msgb *msg = gsm48_msgb_alloc(); |
| 1713 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 1714 | u_int8_t *cause, *call_state; |
| 1715 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1716 | gh->msg_type = GSM48_MT_CC_STATUS; |
| 1717 | |
| 1718 | cause = msgb_put(msg, 3); |
| 1719 | cause[0] = 2; |
| 1720 | cause[1] = GSM48_CAUSE_CS_GSM | GSM48_CAUSE_LOC_USER; |
| 1721 | cause[2] = 0x80 | 30; /* response to status inquiry */ |
| 1722 | |
| 1723 | call_state = msgb_put(msg, 1); |
| 1724 | call_state[0] = 0xc0 | 0x00; |
| 1725 | |
Harald Welte | 36fe2e8 | 2009-07-23 21:13:03 +0200 | [diff] [blame] | 1726 | return gsm48_sendmsg(msg, trans); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1727 | } |
| 1728 | |
| 1729 | static int gsm48_tx_simple(struct gsm_lchan *lchan, |
| 1730 | u_int8_t pdisc, u_int8_t msg_type) |
| 1731 | { |
| 1732 | struct msgb *msg = gsm48_msgb_alloc(); |
| 1733 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 1734 | |
| 1735 | msg->lchan = lchan; |
| 1736 | |
| 1737 | gh->proto_discr = pdisc; |
| 1738 | gh->msg_type = msg_type; |
| 1739 | |
Harald Welte | 36fe2e8 | 2009-07-23 21:13:03 +0200 | [diff] [blame] | 1740 | return gsm48_sendmsg(msg, NULL); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1741 | } |
| 1742 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1743 | static void gsm48_stop_cc_timer(struct gsm_trans *trans) |
| 1744 | { |
Harald Welte | c2189a6 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 1745 | if (bsc_timer_pending(&trans->cc.timer)) { |
| 1746 | DEBUGP(DCC, "stopping pending timer T%x\n", trans->cc.Tcurrent); |
| 1747 | bsc_del_timer(&trans->cc.timer); |
| 1748 | trans->cc.Tcurrent = 0; |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1749 | } |
| 1750 | } |
| 1751 | |
| 1752 | static int mncc_recvmsg(struct gsm_network *net, struct gsm_trans *trans, |
| 1753 | int msg_type, struct gsm_mncc *mncc) |
| 1754 | { |
| 1755 | struct msgb *msg; |
| 1756 | |
| 1757 | if (trans) |
| 1758 | if (trans->lchan) |
Harald Welte | 4861c82 | 2009-07-23 21:21:14 +0200 | [diff] [blame] | 1759 | DEBUGP(DCC, "(bts %d trx %d ts %d ti %x sub %s) " |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1760 | "Sending '%s' to MNCC.\n", |
| 1761 | trans->lchan->ts->trx->bts->nr, |
| 1762 | trans->lchan->ts->trx->nr, |
| 1763 | trans->lchan->ts->nr, trans->transaction_id, |
| 1764 | (trans->subscr)?(trans->subscr->extension):"-", |
| 1765 | get_mncc_name(msg_type)); |
| 1766 | else |
| 1767 | DEBUGP(DCC, "(bts - trx - ts - ti -- sub %s) " |
| 1768 | "Sending '%s' to MNCC.\n", |
| 1769 | (trans->subscr)?(trans->subscr->extension):"-", |
| 1770 | get_mncc_name(msg_type)); |
| 1771 | else |
| 1772 | DEBUGP(DCC, "(bts - trx - ts - ti -- sub -) " |
| 1773 | "Sending '%s' to MNCC.\n", get_mncc_name(msg_type)); |
| 1774 | |
| 1775 | mncc->msg_type = msg_type; |
| 1776 | |
Harald Welte | 9cfc935 | 2009-06-26 19:39:35 +0200 | [diff] [blame] | 1777 | msg = msgb_alloc(sizeof(struct gsm_mncc), "MNCC"); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1778 | if (!msg) |
| 1779 | return -ENOMEM; |
| 1780 | memcpy(msg->data, mncc, sizeof(struct gsm_mncc)); |
| 1781 | msgb_enqueue(&net->upqueue, msg); |
| 1782 | |
| 1783 | return 0; |
| 1784 | } |
| 1785 | |
| 1786 | int mncc_release_ind(struct gsm_network *net, struct gsm_trans *trans, |
| 1787 | u_int32_t callref, int location, int value) |
| 1788 | { |
| 1789 | struct gsm_mncc rel; |
| 1790 | |
Harald Welte | cb0595f | 2009-06-12 01:54:08 +0800 | [diff] [blame] | 1791 | memset(&rel, 0, sizeof(rel)); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1792 | rel.callref = callref; |
Andreas Eversberg | b992a8a | 2009-06-14 22:14:12 +0800 | [diff] [blame] | 1793 | mncc_set_cause(&rel, location, value); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1794 | return mncc_recvmsg(net, trans, MNCC_REL_IND, &rel); |
| 1795 | } |
| 1796 | |
Harald Welte | c2189a6 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 1797 | /* Call Control Specific transaction release. |
| 1798 | * gets called by trans_free, DO NOT CALL YOURSELF! */ |
| 1799 | void _gsm48_cc_trans_free(struct gsm_trans *trans) |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1800 | { |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1801 | gsm48_stop_cc_timer(trans); |
| 1802 | |
| 1803 | /* send release to L4, if callref still exists */ |
| 1804 | if (trans->callref) { |
| 1805 | /* Ressource unavailable */ |
Harald Welte | 0abe5a6 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 1806 | mncc_release_ind(trans->subscr->net, trans, trans->callref, |
Andreas Eversberg | b992a8a | 2009-06-14 22:14:12 +0800 | [diff] [blame] | 1807 | GSM48_CAUSE_LOC_PRN_S_LU, |
| 1808 | GSM48_CC_CAUSE_RESOURCE_UNAVAIL); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1809 | } |
Harald Welte | c2189a6 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 1810 | if (trans->cc.state != GSM_CSTATE_NULL) |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1811 | new_cc_state(trans, GSM_CSTATE_NULL); |
Harald Welte | c2189a6 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 1812 | if (trans->lchan) |
| 1813 | trau_mux_unmap(&trans->lchan->ts->e1_link, trans->callref); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1814 | } |
| 1815 | |
| 1816 | static int gsm48_cc_tx_setup(struct gsm_trans *trans, void *arg); |
| 1817 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1818 | /* call-back from paging the B-end of the connection */ |
| 1819 | static int setup_trig_pag_evt(unsigned int hooknum, unsigned int event, |
| 1820 | struct msgb *msg, void *_lchan, void *param) |
| 1821 | { |
| 1822 | struct gsm_lchan *lchan = _lchan; |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1823 | struct gsm_subscriber *subscr = param; |
| 1824 | struct gsm_trans *transt, *tmp; |
| 1825 | struct gsm_network *net; |
Harald Welte | 1ff81b5 | 2009-06-26 20:17:06 +0200 | [diff] [blame] | 1826 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1827 | if (hooknum != GSM_HOOK_RR_PAGING) |
| 1828 | return -EINVAL; |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1829 | |
| 1830 | if (!subscr) |
| 1831 | return -EINVAL; |
| 1832 | net = subscr->net; |
| 1833 | if (!net) { |
| 1834 | DEBUGP(DCC, "Error Network not set!\n"); |
| 1835 | return -EINVAL; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1836 | } |
| 1837 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1838 | /* check all tranactions (without lchan) for subscriber */ |
| 1839 | llist_for_each_entry_safe(transt, tmp, &net->trans_list, entry) { |
| 1840 | if (transt->subscr != subscr || transt->lchan) |
| 1841 | continue; |
| 1842 | switch (event) { |
| 1843 | case GSM_PAGING_SUCCEEDED: |
| 1844 | if (!lchan) // paranoid |
| 1845 | break; |
| 1846 | DEBUGP(DCC, "Paging subscr %s succeeded!\n", |
| 1847 | subscr->extension); |
| 1848 | /* Assign lchan */ |
| 1849 | if (!transt->lchan) { |
| 1850 | transt->lchan = lchan; |
| 1851 | use_lchan(lchan); |
| 1852 | } |
| 1853 | /* send SETUP request to called party */ |
Harald Welte | c2189a6 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 1854 | gsm48_cc_tx_setup(transt, &transt->cc.msg); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1855 | break; |
| 1856 | case GSM_PAGING_EXPIRED: |
| 1857 | DEBUGP(DCC, "Paging subscr %s expired!\n", |
| 1858 | subscr->extension); |
| 1859 | /* Temporarily out of order */ |
Harald Welte | 0abe5a6 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 1860 | mncc_release_ind(transt->subscr->net, transt, |
| 1861 | transt->callref, |
Andreas Eversberg | b992a8a | 2009-06-14 22:14:12 +0800 | [diff] [blame] | 1862 | GSM48_CAUSE_LOC_PRN_S_LU, |
| 1863 | GSM48_CC_CAUSE_DEST_OOO); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1864 | transt->callref = 0; |
Harald Welte | c2189a6 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 1865 | trans_free(transt); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1866 | break; |
| 1867 | } |
| 1868 | } |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1869 | return 0; |
| 1870 | } |
| 1871 | |
Harald Welte | 3c06207 | 2009-07-28 18:25:29 +0200 | [diff] [blame] | 1872 | /* some other part of the code sends us a signal */ |
| 1873 | static int handle_abisip_signal(unsigned int subsys, unsigned int signal, |
| 1874 | void *handler_data, void *signal_data) |
| 1875 | { |
| 1876 | struct gsm_lchan *lchan = signal_data; |
| 1877 | struct gsm_bts_trx_ts *ts; |
| 1878 | int rc; |
| 1879 | |
| 1880 | if (subsys != SS_ABISIP) |
| 1881 | return 0; |
| 1882 | |
| 1883 | /* in case we use direct BTS-to-BTS RTP */ |
| 1884 | if (ipacc_rtp_direct) |
| 1885 | return 0; |
| 1886 | |
| 1887 | ts = lchan->ts; |
| 1888 | |
| 1889 | switch (signal) { |
| 1890 | case S_ABISIP_BIND_ACK: |
| 1891 | /* the BTS has successfully bound a TCH to a local ip/port, |
| 1892 | * which means we can connect our UDP socket to it */ |
| 1893 | if (ts->abis_ip.rtp_socket) { |
| 1894 | rtp_socket_free(ts->abis_ip.rtp_socket); |
| 1895 | ts->abis_ip.rtp_socket = NULL; |
| 1896 | } |
| 1897 | |
| 1898 | ts->abis_ip.rtp_socket = rtp_socket_create(); |
| 1899 | if (!ts->abis_ip.rtp_socket) |
| 1900 | goto out_err; |
| 1901 | |
| 1902 | rc = rtp_socket_connect(ts->abis_ip.rtp_socket, |
| 1903 | ts->abis_ip.bound_ip, |
| 1904 | ts->abis_ip.bound_port); |
| 1905 | if (rc < 0) |
| 1906 | goto out_err; |
| 1907 | break; |
| 1908 | case S_ABISIP_DISC_IND: |
| 1909 | /* the BTS tells us a RTP stream has been disconnected */ |
| 1910 | if (ts->abis_ip.rtp_socket) { |
| 1911 | rtp_socket_free(ts->abis_ip.rtp_socket); |
| 1912 | ts->abis_ip.rtp_socket = NULL; |
| 1913 | } |
| 1914 | break; |
| 1915 | } |
| 1916 | |
| 1917 | return 0; |
| 1918 | out_err: |
| 1919 | /* FIXME: do something */ |
| 1920 | return 0; |
| 1921 | } |
| 1922 | |
| 1923 | /* bind rtp proxy to local IP/port and tell BTS to connect to it */ |
| 1924 | static int ipacc_connect_proxy_bind(struct gsm_lchan *lchan) |
| 1925 | { |
| 1926 | struct gsm_bts_trx_ts *ts = lchan->ts; |
| 1927 | struct rtp_socket *rs = ts->abis_ip.rtp_socket; |
| 1928 | int rc; |
| 1929 | |
| 1930 | rc = rsl_ipacc_connect(lchan, ntohl(rs->rtp.sin_local.sin_addr.s_addr), |
| 1931 | ntohs(rs->rtp.sin_local.sin_port), |
| 1932 | ts->abis_ip.conn_id, |
| 1933 | /* FIXME: use RTP payload of bound socket, not BTS*/ |
| 1934 | ts->abis_ip.rtp_payload2); |
| 1935 | |
| 1936 | return rc; |
| 1937 | } |
| 1938 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1939 | /* map two ipaccess RTP streams onto each other */ |
| 1940 | static int tch_map(struct gsm_lchan *lchan, struct gsm_lchan *remote_lchan) |
| 1941 | { |
| 1942 | struct gsm_bts *bts = lchan->ts->trx->bts; |
| 1943 | struct gsm_bts *remote_bts = remote_lchan->ts->trx->bts; |
| 1944 | struct gsm_bts_trx_ts *ts; |
Harald Welte | 3c06207 | 2009-07-28 18:25:29 +0200 | [diff] [blame] | 1945 | int rc; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1946 | |
| 1947 | DEBUGP(DCC, "Setting up TCH map between (bts=%u,trx=%u,ts=%u) and (bts=%u,trx=%u,ts=%u)\n", |
| 1948 | bts->nr, lchan->ts->trx->nr, lchan->ts->nr, |
| 1949 | remote_bts->nr, remote_lchan->ts->trx->nr, remote_lchan->ts->nr); |
| 1950 | |
| 1951 | if (bts->type != remote_bts->type) { |
| 1952 | DEBUGP(DCC, "Cannot switch calls between different BTS types yet\n"); |
| 1953 | return -EINVAL; |
| 1954 | } |
| 1955 | |
| 1956 | switch (bts->type) { |
| 1957 | case GSM_BTS_TYPE_NANOBTS_900: |
| 1958 | case GSM_BTS_TYPE_NANOBTS_1800: |
Harald Welte | 3c06207 | 2009-07-28 18:25:29 +0200 | [diff] [blame] | 1959 | if (!ipacc_rtp_direct) { |
| 1960 | /* connect the TCH's to our RTP proxy */ |
| 1961 | rc = ipacc_connect_proxy_bind(lchan); |
| 1962 | if (rc < 0) |
| 1963 | return rc; |
| 1964 | rc = ipacc_connect_proxy_bind(remote_lchan); |
| 1965 | |
| 1966 | /* connect them with each other */ |
| 1967 | rtp_socket_proxy(lchan->ts->abis_ip.rtp_socket, |
| 1968 | remote_lchan->ts->abis_ip.rtp_socket); |
| 1969 | } else { |
| 1970 | /* directly connect TCH RTP streams to each other */ |
| 1971 | ts = remote_lchan->ts; |
| 1972 | rc = rsl_ipacc_connect(lchan, ts->abis_ip.bound_ip, |
| 1973 | ts->abis_ip.bound_port, |
| 1974 | lchan->ts->abis_ip.conn_id, |
| 1975 | ts->abis_ip.rtp_payload2); |
| 1976 | if (rc < 0) |
| 1977 | return rc; |
| 1978 | ts = lchan->ts; |
| 1979 | rc = rsl_ipacc_connect(remote_lchan, ts->abis_ip.bound_ip, |
| 1980 | ts->abis_ip.bound_port, |
| 1981 | remote_lchan->ts->abis_ip.conn_id, |
| 1982 | ts->abis_ip.rtp_payload2); |
| 1983 | } |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1984 | break; |
| 1985 | case GSM_BTS_TYPE_BS11: |
| 1986 | trau_mux_map_lchan(lchan, remote_lchan); |
| 1987 | break; |
| 1988 | default: |
| 1989 | DEBUGP(DCC, "Unknown BTS type %u\n", bts->type); |
Harald Welte | 3c06207 | 2009-07-28 18:25:29 +0200 | [diff] [blame] | 1990 | rc = -EINVAL; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1991 | break; |
| 1992 | } |
| 1993 | |
| 1994 | return 0; |
| 1995 | } |
| 1996 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1997 | /* bridge channels of two transactions */ |
| 1998 | static int tch_bridge(struct gsm_network *net, u_int32_t *refs) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1999 | { |
Harald Welte | c2189a6 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 2000 | struct gsm_trans *trans1 = trans_find_by_callref(net, refs[0]); |
| 2001 | struct gsm_trans *trans2 = trans_find_by_callref(net, refs[1]); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 2002 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2003 | if (!trans1 || !trans2) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 2004 | return -EIO; |
| 2005 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2006 | if (!trans1->lchan || !trans2->lchan) |
| 2007 | return -EIO; |
| 2008 | |
| 2009 | /* through-connect channel */ |
| 2010 | return tch_map(trans1->lchan, trans2->lchan); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 2011 | } |
| 2012 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2013 | /* enable receive of channels to upqueue */ |
| 2014 | static int tch_recv(struct gsm_network *net, struct gsm_mncc *data, int enable) |
| 2015 | { |
| 2016 | struct gsm_trans *trans; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 2017 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2018 | /* Find callref */ |
Harald Welte | c2189a6 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 2019 | trans = trans_find_by_callref(net, data->callref); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2020 | if (!trans) |
| 2021 | return -EIO; |
| 2022 | if (!trans->lchan) |
| 2023 | return 0; |
| 2024 | |
| 2025 | // todo IPACCESS |
| 2026 | if (enable) |
| 2027 | return trau_recv_lchan(trans->lchan, data->callref); |
| 2028 | return trau_mux_unmap(NULL, data->callref); |
| 2029 | } |
| 2030 | |
| 2031 | /* send a frame to channel */ |
| 2032 | static int tch_frame(struct gsm_network *net, struct gsm_trau_frame *frame) |
| 2033 | { |
| 2034 | struct gsm_trans *trans; |
| 2035 | |
| 2036 | /* Find callref */ |
Harald Welte | c2189a6 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 2037 | trans = trans_find_by_callref(net, frame->callref); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2038 | if (!trans) |
| 2039 | return -EIO; |
| 2040 | if (!trans->lchan) |
| 2041 | return 0; |
| 2042 | if (trans->lchan->type != GSM_LCHAN_TCH_F && |
| 2043 | trans->lchan->type != GSM_LCHAN_TCH_H) |
| 2044 | return 0; |
| 2045 | |
| 2046 | // todo IPACCESS |
| 2047 | return trau_send_lchan(trans->lchan, |
| 2048 | (struct decoded_trau_frame *)frame->data); |
| 2049 | } |
| 2050 | |
| 2051 | |
| 2052 | static int gsm48_cc_rx_status_enq(struct gsm_trans *trans, struct msgb *msg) |
| 2053 | { |
| 2054 | DEBUGP(DCC, "-> STATUS ENQ\n"); |
| 2055 | return gsm48_cc_tx_status(trans, msg); |
| 2056 | } |
| 2057 | |
| 2058 | static int gsm48_cc_tx_release(struct gsm_trans *trans, void *arg); |
| 2059 | static int gsm48_cc_tx_disconnect(struct gsm_trans *trans, void *arg); |
| 2060 | |
| 2061 | static void gsm48_cc_timeout(void *arg) |
| 2062 | { |
| 2063 | struct gsm_trans *trans = arg; |
| 2064 | int disconnect = 0, release = 0; |
Harald Welte | bbc636a | 2009-06-11 14:23:20 +0800 | [diff] [blame] | 2065 | int mo_cause = GSM48_CC_CAUSE_RECOVERY_TIMER; |
| 2066 | int mo_location = GSM48_CAUSE_LOC_USER; |
| 2067 | int l4_cause = GSM48_CC_CAUSE_NORMAL_UNSPEC; |
| 2068 | int l4_location = GSM48_CAUSE_LOC_PRN_S_LU; |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2069 | struct gsm_mncc mo_rel, l4_rel; |
| 2070 | |
| 2071 | memset(&mo_rel, 0, sizeof(struct gsm_mncc)); |
| 2072 | mo_rel.callref = trans->callref; |
| 2073 | memset(&l4_rel, 0, sizeof(struct gsm_mncc)); |
| 2074 | l4_rel.callref = trans->callref; |
| 2075 | |
Harald Welte | c2189a6 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 2076 | switch(trans->cc.Tcurrent) { |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2077 | case 0x303: |
| 2078 | release = 1; |
Harald Welte | bbc636a | 2009-06-11 14:23:20 +0800 | [diff] [blame] | 2079 | l4_cause = GSM48_CC_CAUSE_USER_NOTRESPOND; |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2080 | break; |
| 2081 | case 0x310: |
| 2082 | disconnect = 1; |
Harald Welte | bbc636a | 2009-06-11 14:23:20 +0800 | [diff] [blame] | 2083 | l4_cause = GSM48_CC_CAUSE_USER_NOTRESPOND; |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2084 | break; |
| 2085 | case 0x313: |
| 2086 | disconnect = 1; |
| 2087 | /* unknown, did not find it in the specs */ |
| 2088 | break; |
| 2089 | case 0x301: |
| 2090 | disconnect = 1; |
Harald Welte | bbc636a | 2009-06-11 14:23:20 +0800 | [diff] [blame] | 2091 | l4_cause = GSM48_CC_CAUSE_USER_NOTRESPOND; |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2092 | break; |
| 2093 | case 0x308: |
Harald Welte | c2189a6 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 2094 | if (!trans->cc.T308_second) { |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2095 | /* restart T308 a second time */ |
Harald Welte | c2189a6 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 2096 | gsm48_cc_tx_release(trans, &trans->cc.msg); |
| 2097 | trans->cc.T308_second = 1; |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2098 | break; /* stay in release state */ |
| 2099 | } |
Harald Welte | c2189a6 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 2100 | trans_free(trans); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2101 | return; |
| 2102 | // release = 1; |
| 2103 | // l4_cause = 14; |
| 2104 | // break; |
| 2105 | case 0x306: |
| 2106 | release = 1; |
Harald Welte | c2189a6 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 2107 | mo_cause = trans->cc.msg.cause.value; |
| 2108 | mo_location = trans->cc.msg.cause.location; |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2109 | break; |
| 2110 | case 0x323: |
| 2111 | disconnect = 1; |
| 2112 | break; |
| 2113 | default: |
| 2114 | release = 1; |
| 2115 | } |
| 2116 | |
| 2117 | if (release && trans->callref) { |
| 2118 | /* process release towards layer 4 */ |
Harald Welte | 0abe5a6 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 2119 | mncc_release_ind(trans->subscr->net, trans, trans->callref, |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2120 | l4_location, l4_cause); |
| 2121 | trans->callref = 0; |
| 2122 | } |
| 2123 | |
| 2124 | if (disconnect && trans->callref) { |
| 2125 | /* process disconnect towards layer 4 */ |
| 2126 | mncc_set_cause(&l4_rel, l4_location, l4_cause); |
Harald Welte | 0abe5a6 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 2127 | mncc_recvmsg(trans->subscr->net, trans, MNCC_DISC_IND, &l4_rel); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2128 | } |
| 2129 | |
| 2130 | /* process disconnect towards mobile station */ |
| 2131 | if (disconnect || release) { |
| 2132 | mncc_set_cause(&mo_rel, mo_location, mo_cause); |
Harald Welte | c2189a6 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 2133 | mo_rel.cause.diag[0] = ((trans->cc.Tcurrent & 0xf00) >> 8) + '0'; |
| 2134 | mo_rel.cause.diag[1] = ((trans->cc.Tcurrent & 0x0f0) >> 4) + '0'; |
| 2135 | mo_rel.cause.diag[2] = (trans->cc.Tcurrent & 0x00f) + '0'; |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2136 | mo_rel.cause.diag_len = 3; |
| 2137 | |
| 2138 | if (disconnect) |
| 2139 | gsm48_cc_tx_disconnect(trans, &mo_rel); |
| 2140 | if (release) |
| 2141 | gsm48_cc_tx_release(trans, &mo_rel); |
| 2142 | } |
| 2143 | |
| 2144 | } |
| 2145 | |
| 2146 | static void gsm48_start_cc_timer(struct gsm_trans *trans, int current, |
| 2147 | int sec, int micro) |
| 2148 | { |
| 2149 | DEBUGP(DCC, "starting timer T%x with %d seconds\n", current, sec); |
Harald Welte | c2189a6 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 2150 | trans->cc.timer.cb = gsm48_cc_timeout; |
| 2151 | trans->cc.timer.data = trans; |
| 2152 | bsc_schedule_timer(&trans->cc.timer, sec, micro); |
| 2153 | trans->cc.Tcurrent = current; |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2154 | } |
| 2155 | |
| 2156 | static int gsm48_cc_rx_setup(struct gsm_trans *trans, struct msgb *msg) |
| 2157 | { |
| 2158 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 2159 | u_int8_t msg_type = gh->msg_type & 0xbf; |
| 2160 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 2161 | struct tlv_parsed tp; |
| 2162 | struct gsm_mncc setup; |
| 2163 | |
| 2164 | memset(&setup, 0, sizeof(struct gsm_mncc)); |
| 2165 | setup.callref = trans->callref; |
| 2166 | tlv_parse(&tp, &rsl_att_tlvdef, gh->data, payload_len, 0, 0); |
| 2167 | /* emergency setup is identified by msg_type */ |
| 2168 | if (msg_type == GSM48_MT_CC_EMERG_SETUP) |
| 2169 | setup.emergency = 1; |
| 2170 | |
| 2171 | /* use subscriber as calling party number */ |
| 2172 | if (trans->subscr) { |
| 2173 | setup.fields |= MNCC_F_CALLING; |
| 2174 | strncpy(setup.calling.number, trans->subscr->extension, |
| 2175 | sizeof(setup.calling.number)-1); |
Andreas Eversberg | 9eaa5da | 2009-06-15 23:22:09 +0200 | [diff] [blame] | 2176 | strncpy(setup.imsi, trans->subscr->imsi, |
| 2177 | sizeof(setup.imsi)-1); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2178 | } |
| 2179 | /* bearer capability */ |
| 2180 | if (TLVP_PRESENT(&tp, GSM48_IE_BEARER_CAP)) { |
| 2181 | setup.fields |= MNCC_F_BEARER_CAP; |
| 2182 | decode_bearer_cap(&setup.bearer_cap, |
| 2183 | TLVP_VAL(&tp, GSM48_IE_BEARER_CAP)-1); |
| 2184 | } |
| 2185 | /* facility */ |
| 2186 | if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) { |
| 2187 | setup.fields |= MNCC_F_FACILITY; |
| 2188 | decode_facility(&setup.facility, |
| 2189 | TLVP_VAL(&tp, GSM48_IE_FACILITY)-1); |
| 2190 | } |
| 2191 | /* called party bcd number */ |
| 2192 | if (TLVP_PRESENT(&tp, GSM48_IE_CALLED_BCD)) { |
| 2193 | setup.fields |= MNCC_F_CALLED; |
| 2194 | decode_called(&setup.called, |
| 2195 | TLVP_VAL(&tp, GSM48_IE_CALLED_BCD)-1); |
| 2196 | } |
| 2197 | /* user-user */ |
| 2198 | if (TLVP_PRESENT(&tp, GSM48_IE_USER_USER)) { |
| 2199 | setup.fields |= MNCC_F_USERUSER; |
| 2200 | decode_useruser(&setup.useruser, |
| 2201 | TLVP_VAL(&tp, GSM48_IE_USER_USER)-1); |
| 2202 | } |
| 2203 | /* ss-version */ |
| 2204 | if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) { |
| 2205 | setup.fields |= MNCC_F_SSVERSION; |
| 2206 | decode_ssversion(&setup.ssversion, |
| 2207 | TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1); |
| 2208 | } |
| 2209 | /* CLIR suppression */ |
| 2210 | if (TLVP_PRESENT(&tp, GSM48_IE_CLIR_SUPP)) |
| 2211 | setup.clir.sup = 1; |
| 2212 | /* CLIR invocation */ |
| 2213 | if (TLVP_PRESENT(&tp, GSM48_IE_CLIR_INVOC)) |
| 2214 | setup.clir.inv = 1; |
| 2215 | /* cc cap */ |
| 2216 | if (TLVP_PRESENT(&tp, GSM48_IE_CC_CAP)) { |
| 2217 | setup.fields |= MNCC_F_CCCAP; |
| 2218 | decode_cccap(&setup.cccap, |
| 2219 | TLVP_VAL(&tp, GSM48_IE_CC_CAP)-1); |
| 2220 | } |
| 2221 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2222 | new_cc_state(trans, GSM_CSTATE_INITIATED); |
| 2223 | |
| 2224 | /* indicate setup to MNCC */ |
Harald Welte | 0abe5a6 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 2225 | mncc_recvmsg(trans->subscr->net, trans, MNCC_SETUP_IND, &setup); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2226 | |
Harald Welte | ca745e2 | 2009-07-29 12:10:35 +0200 | [diff] [blame] | 2227 | /* MNCC code will modify the channel asynchronously, we should |
| 2228 | * ipaccess-bind only after the modification has been made to the |
| 2229 | * lchan->tch_mode */ |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2230 | return 0; |
| 2231 | } |
| 2232 | |
| 2233 | static int gsm48_cc_tx_setup(struct gsm_trans *trans, void *arg) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 2234 | { |
| 2235 | struct msgb *msg = gsm48_msgb_alloc(); |
| 2236 | struct gsm48_hdr *gh; |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2237 | struct gsm_mncc *setup = arg; |
Harald Welte | 165fc33 | 2009-07-23 21:36:44 +0200 | [diff] [blame] | 2238 | int rc, trans_id; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 2239 | |
| 2240 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 2241 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2242 | /* transaction id must not be assigned */ |
| 2243 | if (trans->transaction_id != 0xff) { /* unasssigned */ |
| 2244 | DEBUGP(DCC, "TX Setup with assigned transaction. " |
| 2245 | "This is not allowed!\n"); |
| 2246 | /* Temporarily out of order */ |
Harald Welte | 0abe5a6 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 2247 | rc = mncc_release_ind(trans->subscr->net, trans, trans->callref, |
Andreas Eversberg | b992a8a | 2009-06-14 22:14:12 +0800 | [diff] [blame] | 2248 | GSM48_CAUSE_LOC_PRN_S_LU, |
| 2249 | GSM48_CC_CAUSE_RESOURCE_UNAVAIL); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2250 | trans->callref = 0; |
Harald Welte | c2189a6 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 2251 | trans_free(trans); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2252 | return rc; |
| 2253 | } |
| 2254 | |
| 2255 | /* Get free transaction_id */ |
Harald Welte | 165fc33 | 2009-07-23 21:36:44 +0200 | [diff] [blame] | 2256 | trans_id = trans_assign_trans_id(trans->subscr, GSM48_PDISC_CC, 0); |
| 2257 | if (trans_id < 0) { |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2258 | /* no free transaction ID */ |
Harald Welte | 0abe5a6 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 2259 | rc = mncc_release_ind(trans->subscr->net, trans, trans->callref, |
Andreas Eversberg | b992a8a | 2009-06-14 22:14:12 +0800 | [diff] [blame] | 2260 | GSM48_CAUSE_LOC_PRN_S_LU, |
| 2261 | GSM48_CC_CAUSE_RESOURCE_UNAVAIL); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2262 | trans->callref = 0; |
Harald Welte | c2189a6 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 2263 | trans_free(trans); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2264 | return rc; |
| 2265 | } |
Harald Welte | 165fc33 | 2009-07-23 21:36:44 +0200 | [diff] [blame] | 2266 | trans->transaction_id = trans_id; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 2267 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 2268 | gh->msg_type = GSM48_MT_CC_SETUP; |
| 2269 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2270 | gsm48_start_cc_timer(trans, 0x303, GSM48_T303); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 2271 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2272 | /* bearer capability */ |
| 2273 | if (setup->fields & MNCC_F_BEARER_CAP) |
| 2274 | encode_bearer_cap(msg, 0, &setup->bearer_cap); |
| 2275 | /* facility */ |
| 2276 | if (setup->fields & MNCC_F_FACILITY) |
| 2277 | encode_facility(msg, 0, &setup->facility); |
| 2278 | /* progress */ |
| 2279 | if (setup->fields & MNCC_F_PROGRESS) |
| 2280 | encode_progress(msg, 0, &setup->progress); |
| 2281 | /* calling party BCD number */ |
| 2282 | if (setup->fields & MNCC_F_CALLING) |
| 2283 | encode_calling(msg, &setup->calling); |
| 2284 | /* called party BCD number */ |
| 2285 | if (setup->fields & MNCC_F_CALLED) |
| 2286 | encode_called(msg, &setup->called); |
| 2287 | /* user-user */ |
| 2288 | if (setup->fields & MNCC_F_USERUSER) |
| 2289 | encode_useruser(msg, 0, &setup->useruser); |
| 2290 | /* redirecting party BCD number */ |
| 2291 | if (setup->fields & MNCC_F_REDIRECTING) |
| 2292 | encode_redirecting(msg, &setup->redirecting); |
| 2293 | /* signal */ |
| 2294 | if (setup->fields & MNCC_F_SIGNAL) |
| 2295 | encode_signal(msg, setup->signal); |
| 2296 | |
| 2297 | new_cc_state(trans, GSM_CSTATE_CALL_PRESENT); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 2298 | |
Harald Welte | 36fe2e8 | 2009-07-23 21:13:03 +0200 | [diff] [blame] | 2299 | return gsm48_sendmsg(msg, trans); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 2300 | } |
| 2301 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2302 | static int gsm48_cc_rx_call_conf(struct gsm_trans *trans, struct msgb *msg) |
| 2303 | { |
| 2304 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 2305 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 2306 | struct tlv_parsed tp; |
| 2307 | struct gsm_mncc call_conf; |
| 2308 | |
| 2309 | gsm48_stop_cc_timer(trans); |
| 2310 | gsm48_start_cc_timer(trans, 0x310, GSM48_T310); |
| 2311 | |
| 2312 | memset(&call_conf, 0, sizeof(struct gsm_mncc)); |
| 2313 | call_conf.callref = trans->callref; |
| 2314 | tlv_parse(&tp, &rsl_att_tlvdef, gh->data, payload_len, 0, 0); |
| 2315 | #if 0 |
| 2316 | /* repeat */ |
| 2317 | if (TLVP_PRESENT(&tp, GSM48_IE_REPEAT_CIR)) |
| 2318 | call_conf.repeat = 1; |
| 2319 | if (TLVP_PRESENT(&tp, GSM48_IE_REPEAT_SEQ)) |
| 2320 | call_conf.repeat = 2; |
| 2321 | #endif |
| 2322 | /* bearer capability */ |
| 2323 | if (TLVP_PRESENT(&tp, GSM48_IE_BEARER_CAP)) { |
| 2324 | call_conf.fields |= MNCC_F_BEARER_CAP; |
| 2325 | decode_bearer_cap(&call_conf.bearer_cap, |
| 2326 | TLVP_VAL(&tp, GSM48_IE_BEARER_CAP)-1); |
| 2327 | } |
| 2328 | /* cause */ |
| 2329 | if (TLVP_PRESENT(&tp, GSM48_IE_CAUSE)) { |
| 2330 | call_conf.fields |= MNCC_F_CAUSE; |
| 2331 | decode_cause(&call_conf.cause, |
| 2332 | TLVP_VAL(&tp, GSM48_IE_CAUSE)-1); |
| 2333 | } |
| 2334 | /* cc cap */ |
| 2335 | if (TLVP_PRESENT(&tp, GSM48_IE_CC_CAP)) { |
| 2336 | call_conf.fields |= MNCC_F_CCCAP; |
| 2337 | decode_cccap(&call_conf.cccap, |
| 2338 | TLVP_VAL(&tp, GSM48_IE_CC_CAP)-1); |
| 2339 | } |
| 2340 | |
| 2341 | new_cc_state(trans, GSM_CSTATE_MO_TERM_CALL_CONF); |
| 2342 | |
Harald Welte | 0abe5a6 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 2343 | return mncc_recvmsg(trans->subscr->net, trans, MNCC_CALL_CONF_IND, |
| 2344 | &call_conf); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2345 | } |
| 2346 | |
| 2347 | static int gsm48_cc_tx_call_proc(struct gsm_trans *trans, void *arg) |
| 2348 | { |
| 2349 | struct gsm_mncc *proceeding = arg; |
| 2350 | struct msgb *msg = gsm48_msgb_alloc(); |
| 2351 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 2352 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2353 | gh->msg_type = GSM48_MT_CC_CALL_PROC; |
| 2354 | |
| 2355 | new_cc_state(trans, GSM_CSTATE_MO_CALL_PROC); |
| 2356 | |
| 2357 | /* bearer capability */ |
| 2358 | if (proceeding->fields & MNCC_F_BEARER_CAP) |
| 2359 | encode_bearer_cap(msg, 0, &proceeding->bearer_cap); |
| 2360 | /* facility */ |
| 2361 | if (proceeding->fields & MNCC_F_FACILITY) |
| 2362 | encode_facility(msg, 0, &proceeding->facility); |
| 2363 | /* progress */ |
| 2364 | if (proceeding->fields & MNCC_F_PROGRESS) |
| 2365 | encode_progress(msg, 0, &proceeding->progress); |
| 2366 | |
Harald Welte | 36fe2e8 | 2009-07-23 21:13:03 +0200 | [diff] [blame] | 2367 | return gsm48_sendmsg(msg, trans); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2368 | } |
| 2369 | |
| 2370 | static int gsm48_cc_rx_alerting(struct gsm_trans *trans, struct msgb *msg) |
| 2371 | { |
| 2372 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 2373 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 2374 | struct tlv_parsed tp; |
| 2375 | struct gsm_mncc alerting; |
| 2376 | |
| 2377 | gsm48_stop_cc_timer(trans); |
| 2378 | gsm48_start_cc_timer(trans, 0x301, GSM48_T301); |
| 2379 | |
| 2380 | memset(&alerting, 0, sizeof(struct gsm_mncc)); |
| 2381 | alerting.callref = trans->callref; |
| 2382 | tlv_parse(&tp, &rsl_att_tlvdef, gh->data, payload_len, 0, 0); |
| 2383 | /* facility */ |
| 2384 | if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) { |
| 2385 | alerting.fields |= MNCC_F_FACILITY; |
| 2386 | decode_facility(&alerting.facility, |
| 2387 | TLVP_VAL(&tp, GSM48_IE_FACILITY)-1); |
| 2388 | } |
| 2389 | |
| 2390 | /* progress */ |
| 2391 | if (TLVP_PRESENT(&tp, GSM48_IE_PROGR_IND)) { |
| 2392 | alerting.fields |= MNCC_F_PROGRESS; |
| 2393 | decode_progress(&alerting.progress, |
| 2394 | TLVP_VAL(&tp, GSM48_IE_PROGR_IND)-1); |
| 2395 | } |
| 2396 | /* ss-version */ |
| 2397 | if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) { |
| 2398 | alerting.fields |= MNCC_F_SSVERSION; |
| 2399 | decode_ssversion(&alerting.ssversion, |
| 2400 | TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1); |
| 2401 | } |
| 2402 | |
| 2403 | new_cc_state(trans, GSM_CSTATE_CALL_RECEIVED); |
| 2404 | |
Harald Welte | 0abe5a6 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 2405 | return mncc_recvmsg(trans->subscr->net, trans, MNCC_ALERT_IND, |
| 2406 | &alerting); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2407 | } |
| 2408 | |
| 2409 | static int gsm48_cc_tx_alerting(struct gsm_trans *trans, void *arg) |
| 2410 | { |
| 2411 | struct gsm_mncc *alerting = arg; |
| 2412 | struct msgb *msg = gsm48_msgb_alloc(); |
| 2413 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 2414 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2415 | gh->msg_type = GSM48_MT_CC_ALERTING; |
| 2416 | |
| 2417 | /* facility */ |
| 2418 | if (alerting->fields & MNCC_F_FACILITY) |
| 2419 | encode_facility(msg, 0, &alerting->facility); |
| 2420 | /* progress */ |
| 2421 | if (alerting->fields & MNCC_F_PROGRESS) |
| 2422 | encode_progress(msg, 0, &alerting->progress); |
| 2423 | /* user-user */ |
| 2424 | if (alerting->fields & MNCC_F_USERUSER) |
| 2425 | encode_useruser(msg, 0, &alerting->useruser); |
| 2426 | |
| 2427 | new_cc_state(trans, GSM_CSTATE_CALL_DELIVERED); |
| 2428 | |
Harald Welte | 36fe2e8 | 2009-07-23 21:13:03 +0200 | [diff] [blame] | 2429 | return gsm48_sendmsg(msg, trans); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2430 | } |
| 2431 | |
| 2432 | static int gsm48_cc_tx_progress(struct gsm_trans *trans, void *arg) |
| 2433 | { |
| 2434 | struct gsm_mncc *progress = arg; |
| 2435 | struct msgb *msg = gsm48_msgb_alloc(); |
| 2436 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 2437 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2438 | gh->msg_type = GSM48_MT_CC_PROGRESS; |
| 2439 | |
| 2440 | /* progress */ |
| 2441 | encode_progress(msg, 1, &progress->progress); |
| 2442 | /* user-user */ |
| 2443 | if (progress->fields & MNCC_F_USERUSER) |
| 2444 | encode_useruser(msg, 0, &progress->useruser); |
| 2445 | |
Harald Welte | 36fe2e8 | 2009-07-23 21:13:03 +0200 | [diff] [blame] | 2446 | return gsm48_sendmsg(msg, trans); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2447 | } |
| 2448 | |
| 2449 | static int gsm48_cc_tx_connect(struct gsm_trans *trans, void *arg) |
| 2450 | { |
| 2451 | struct gsm_mncc *connect = arg; |
| 2452 | struct msgb *msg = gsm48_msgb_alloc(); |
| 2453 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 2454 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2455 | gh->msg_type = GSM48_MT_CC_CONNECT; |
| 2456 | |
| 2457 | gsm48_stop_cc_timer(trans); |
| 2458 | gsm48_start_cc_timer(trans, 0x313, GSM48_T313); |
| 2459 | |
| 2460 | /* facility */ |
| 2461 | if (connect->fields & MNCC_F_FACILITY) |
| 2462 | encode_facility(msg, 0, &connect->facility); |
| 2463 | /* progress */ |
| 2464 | if (connect->fields & MNCC_F_PROGRESS) |
| 2465 | encode_progress(msg, 0, &connect->progress); |
| 2466 | /* connected number */ |
| 2467 | if (connect->fields & MNCC_F_CONNECTED) |
| 2468 | encode_connected(msg, &connect->connected); |
| 2469 | /* user-user */ |
| 2470 | if (connect->fields & MNCC_F_USERUSER) |
| 2471 | encode_useruser(msg, 0, &connect->useruser); |
| 2472 | |
| 2473 | new_cc_state(trans, GSM_CSTATE_CONNECT_IND); |
| 2474 | |
Harald Welte | 36fe2e8 | 2009-07-23 21:13:03 +0200 | [diff] [blame] | 2475 | return gsm48_sendmsg(msg, trans); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2476 | } |
| 2477 | |
| 2478 | static int gsm48_cc_rx_connect(struct gsm_trans *trans, struct msgb *msg) |
| 2479 | { |
| 2480 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 2481 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 2482 | struct tlv_parsed tp; |
| 2483 | struct gsm_mncc connect; |
| 2484 | |
| 2485 | gsm48_stop_cc_timer(trans); |
| 2486 | |
| 2487 | memset(&connect, 0, sizeof(struct gsm_mncc)); |
| 2488 | connect.callref = trans->callref; |
| 2489 | tlv_parse(&tp, &rsl_att_tlvdef, gh->data, payload_len, 0, 0); |
| 2490 | /* use subscriber as connected party number */ |
| 2491 | if (trans->subscr) { |
| 2492 | connect.fields |= MNCC_F_CONNECTED; |
| 2493 | strncpy(connect.connected.number, trans->subscr->extension, |
| 2494 | sizeof(connect.connected.number)-1); |
Andreas Eversberg | 9eaa5da | 2009-06-15 23:22:09 +0200 | [diff] [blame] | 2495 | strncpy(connect.imsi, trans->subscr->imsi, |
| 2496 | sizeof(connect.imsi)-1); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2497 | } |
| 2498 | /* facility */ |
| 2499 | if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) { |
| 2500 | connect.fields |= MNCC_F_FACILITY; |
| 2501 | decode_facility(&connect.facility, |
| 2502 | TLVP_VAL(&tp, GSM48_IE_FACILITY)-1); |
| 2503 | } |
| 2504 | /* user-user */ |
| 2505 | if (TLVP_PRESENT(&tp, GSM48_IE_USER_USER)) { |
| 2506 | connect.fields |= MNCC_F_USERUSER; |
| 2507 | decode_useruser(&connect.useruser, |
| 2508 | TLVP_VAL(&tp, GSM48_IE_USER_USER)-1); |
| 2509 | } |
| 2510 | /* ss-version */ |
| 2511 | if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) { |
| 2512 | connect.fields |= MNCC_F_SSVERSION; |
| 2513 | decode_ssversion(&connect.ssversion, |
| 2514 | TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1); |
| 2515 | } |
| 2516 | |
| 2517 | new_cc_state(trans, GSM_CSTATE_CONNECT_REQUEST); |
| 2518 | |
Harald Welte | 0abe5a6 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 2519 | return mncc_recvmsg(trans->subscr->net, trans, MNCC_SETUP_CNF, &connect); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2520 | } |
| 2521 | |
| 2522 | |
| 2523 | static int gsm48_cc_rx_connect_ack(struct gsm_trans *trans, struct msgb *msg) |
| 2524 | { |
| 2525 | struct gsm_mncc connect_ack; |
| 2526 | |
| 2527 | gsm48_stop_cc_timer(trans); |
| 2528 | |
| 2529 | new_cc_state(trans, GSM_CSTATE_ACTIVE); |
| 2530 | |
| 2531 | memset(&connect_ack, 0, sizeof(struct gsm_mncc)); |
| 2532 | connect_ack.callref = trans->callref; |
Harald Welte | 0abe5a6 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 2533 | return mncc_recvmsg(trans->subscr->net, trans, MNCC_SETUP_COMPL_IND, |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2534 | &connect_ack); |
| 2535 | } |
| 2536 | |
| 2537 | static int gsm48_cc_tx_connect_ack(struct gsm_trans *trans, void *arg) |
| 2538 | { |
| 2539 | struct msgb *msg = gsm48_msgb_alloc(); |
| 2540 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 2541 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2542 | gh->msg_type = GSM48_MT_CC_CONNECT_ACK; |
| 2543 | |
| 2544 | new_cc_state(trans, GSM_CSTATE_ACTIVE); |
| 2545 | |
Harald Welte | 36fe2e8 | 2009-07-23 21:13:03 +0200 | [diff] [blame] | 2546 | return gsm48_sendmsg(msg, trans); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2547 | } |
| 2548 | |
| 2549 | static int gsm48_cc_rx_disconnect(struct gsm_trans *trans, struct msgb *msg) |
| 2550 | { |
| 2551 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 2552 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 2553 | struct tlv_parsed tp; |
| 2554 | struct gsm_mncc disc; |
| 2555 | |
| 2556 | gsm48_stop_cc_timer(trans); |
| 2557 | |
| 2558 | new_cc_state(trans, GSM_CSTATE_DISCONNECT_REQ); |
| 2559 | |
| 2560 | memset(&disc, 0, sizeof(struct gsm_mncc)); |
| 2561 | disc.callref = trans->callref; |
| 2562 | tlv_parse(&tp, &rsl_att_tlvdef, gh->data, payload_len, GSM48_IE_CAUSE, 0); |
| 2563 | /* cause */ |
| 2564 | if (TLVP_PRESENT(&tp, GSM48_IE_CAUSE)) { |
| 2565 | disc.fields |= MNCC_F_CAUSE; |
| 2566 | decode_cause(&disc.cause, |
| 2567 | TLVP_VAL(&tp, GSM48_IE_CAUSE)-1); |
| 2568 | } |
| 2569 | /* facility */ |
| 2570 | if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) { |
| 2571 | disc.fields |= MNCC_F_FACILITY; |
| 2572 | decode_facility(&disc.facility, |
| 2573 | TLVP_VAL(&tp, GSM48_IE_FACILITY)-1); |
| 2574 | } |
| 2575 | /* user-user */ |
| 2576 | if (TLVP_PRESENT(&tp, GSM48_IE_USER_USER)) { |
| 2577 | disc.fields |= MNCC_F_USERUSER; |
| 2578 | decode_useruser(&disc.useruser, |
| 2579 | TLVP_VAL(&tp, GSM48_IE_USER_USER)-1); |
| 2580 | } |
| 2581 | /* ss-version */ |
| 2582 | if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) { |
| 2583 | disc.fields |= MNCC_F_SSVERSION; |
| 2584 | decode_ssversion(&disc.ssversion, |
| 2585 | TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1); |
| 2586 | } |
| 2587 | |
Harald Welte | 0abe5a6 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 2588 | return mncc_recvmsg(trans->subscr->net, trans, MNCC_DISC_IND, &disc); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2589 | |
| 2590 | } |
| 2591 | |
Harald Welte | bbc636a | 2009-06-11 14:23:20 +0800 | [diff] [blame] | 2592 | static struct gsm_mncc_cause default_cause = { |
| 2593 | .location = GSM48_CAUSE_LOC_PRN_S_LU, |
| 2594 | .coding = 0, |
| 2595 | .rec = 0, |
| 2596 | .rec_val = 0, |
| 2597 | .value = GSM48_CC_CAUSE_NORMAL_UNSPEC, |
| 2598 | .diag_len = 0, |
| 2599 | .diag = { 0 }, |
| 2600 | }; |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2601 | |
| 2602 | static int gsm48_cc_tx_disconnect(struct gsm_trans *trans, void *arg) |
| 2603 | { |
| 2604 | struct gsm_mncc *disc = arg; |
| 2605 | struct msgb *msg = gsm48_msgb_alloc(); |
| 2606 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 2607 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2608 | gh->msg_type = GSM48_MT_CC_DISCONNECT; |
| 2609 | |
| 2610 | gsm48_stop_cc_timer(trans); |
| 2611 | gsm48_start_cc_timer(trans, 0x306, GSM48_T306); |
| 2612 | |
| 2613 | /* cause */ |
| 2614 | if (disc->fields & MNCC_F_CAUSE) |
| 2615 | encode_cause(msg, 1, &disc->cause); |
| 2616 | else |
| 2617 | encode_cause(msg, 1, &default_cause); |
| 2618 | |
| 2619 | /* facility */ |
| 2620 | if (disc->fields & MNCC_F_FACILITY) |
| 2621 | encode_facility(msg, 0, &disc->facility); |
| 2622 | /* progress */ |
| 2623 | if (disc->fields & MNCC_F_PROGRESS) |
| 2624 | encode_progress(msg, 0, &disc->progress); |
| 2625 | /* user-user */ |
| 2626 | if (disc->fields & MNCC_F_USERUSER) |
| 2627 | encode_useruser(msg, 0, &disc->useruser); |
| 2628 | |
| 2629 | /* store disconnect cause for T306 expiry */ |
Harald Welte | c2189a6 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 2630 | memcpy(&trans->cc.msg, disc, sizeof(struct gsm_mncc)); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2631 | |
| 2632 | new_cc_state(trans, GSM_CSTATE_DISCONNECT_IND); |
| 2633 | |
Harald Welte | 36fe2e8 | 2009-07-23 21:13:03 +0200 | [diff] [blame] | 2634 | return gsm48_sendmsg(msg, trans); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2635 | } |
| 2636 | |
| 2637 | static int gsm48_cc_rx_release(struct gsm_trans *trans, struct msgb *msg) |
| 2638 | { |
| 2639 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 2640 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 2641 | struct tlv_parsed tp; |
| 2642 | struct gsm_mncc rel; |
| 2643 | int rc; |
| 2644 | |
| 2645 | gsm48_stop_cc_timer(trans); |
| 2646 | |
| 2647 | memset(&rel, 0, sizeof(struct gsm_mncc)); |
| 2648 | rel.callref = trans->callref; |
| 2649 | tlv_parse(&tp, &rsl_att_tlvdef, gh->data, payload_len, 0, 0); |
| 2650 | /* cause */ |
| 2651 | if (TLVP_PRESENT(&tp, GSM48_IE_CAUSE)) { |
| 2652 | rel.fields |= MNCC_F_CAUSE; |
| 2653 | decode_cause(&rel.cause, |
| 2654 | TLVP_VAL(&tp, GSM48_IE_CAUSE)-1); |
| 2655 | } |
| 2656 | /* facility */ |
| 2657 | if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) { |
| 2658 | rel.fields |= MNCC_F_FACILITY; |
| 2659 | decode_facility(&rel.facility, |
| 2660 | TLVP_VAL(&tp, GSM48_IE_FACILITY)-1); |
| 2661 | } |
| 2662 | /* user-user */ |
| 2663 | if (TLVP_PRESENT(&tp, GSM48_IE_USER_USER)) { |
| 2664 | rel.fields |= MNCC_F_USERUSER; |
| 2665 | decode_useruser(&rel.useruser, |
| 2666 | TLVP_VAL(&tp, GSM48_IE_USER_USER)-1); |
| 2667 | } |
| 2668 | /* ss-version */ |
| 2669 | if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) { |
| 2670 | rel.fields |= MNCC_F_SSVERSION; |
| 2671 | decode_ssversion(&rel.ssversion, |
| 2672 | TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1); |
| 2673 | } |
| 2674 | |
Harald Welte | c2189a6 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 2675 | if (trans->cc.state == GSM_CSTATE_RELEASE_REQ) { |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2676 | /* release collision 5.4.5 */ |
Harald Welte | 0abe5a6 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 2677 | rc = mncc_recvmsg(trans->subscr->net, trans, MNCC_REL_CNF, &rel); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2678 | } else { |
Harald Welte | 0abe5a6 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 2679 | rc = gsm48_tx_simple(msg->lchan, |
Harald Welte | 4861c82 | 2009-07-23 21:21:14 +0200 | [diff] [blame] | 2680 | GSM48_PDISC_CC | (trans->transaction_id << 4), |
Harald Welte | 0abe5a6 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 2681 | GSM48_MT_CC_RELEASE_COMPL); |
| 2682 | rc = mncc_recvmsg(trans->subscr->net, trans, MNCC_REL_IND, &rel); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2683 | } |
| 2684 | |
| 2685 | new_cc_state(trans, GSM_CSTATE_NULL); |
| 2686 | |
| 2687 | trans->callref = 0; |
Harald Welte | c2189a6 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 2688 | trans_free(trans); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2689 | |
| 2690 | return rc; |
| 2691 | } |
| 2692 | |
| 2693 | static int gsm48_cc_tx_release(struct gsm_trans *trans, void *arg) |
| 2694 | { |
| 2695 | struct gsm_mncc *rel = arg; |
| 2696 | struct msgb *msg = gsm48_msgb_alloc(); |
| 2697 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 2698 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2699 | gh->msg_type = GSM48_MT_CC_RELEASE; |
| 2700 | |
| 2701 | trans->callref = 0; |
| 2702 | |
| 2703 | gsm48_stop_cc_timer(trans); |
| 2704 | gsm48_start_cc_timer(trans, 0x308, GSM48_T308); |
| 2705 | |
| 2706 | /* cause */ |
| 2707 | if (rel->fields & MNCC_F_CAUSE) |
| 2708 | encode_cause(msg, 0, &rel->cause); |
| 2709 | /* facility */ |
| 2710 | if (rel->fields & MNCC_F_FACILITY) |
| 2711 | encode_facility(msg, 0, &rel->facility); |
| 2712 | /* user-user */ |
| 2713 | if (rel->fields & MNCC_F_USERUSER) |
| 2714 | encode_useruser(msg, 0, &rel->useruser); |
| 2715 | |
Harald Welte | c2189a6 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 2716 | trans->cc.T308_second = 0; |
| 2717 | memcpy(&trans->cc.msg, rel, sizeof(struct gsm_mncc)); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2718 | |
Harald Welte | c2189a6 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 2719 | if (trans->cc.state != GSM_CSTATE_RELEASE_REQ) |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2720 | new_cc_state(trans, GSM_CSTATE_RELEASE_REQ); |
| 2721 | |
Harald Welte | 36fe2e8 | 2009-07-23 21:13:03 +0200 | [diff] [blame] | 2722 | return gsm48_sendmsg(msg, trans); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2723 | } |
| 2724 | |
| 2725 | static int gsm48_cc_rx_release_compl(struct gsm_trans *trans, struct msgb *msg) |
| 2726 | { |
| 2727 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 2728 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 2729 | struct tlv_parsed tp; |
| 2730 | struct gsm_mncc rel; |
| 2731 | int rc = 0; |
| 2732 | |
| 2733 | gsm48_stop_cc_timer(trans); |
| 2734 | |
| 2735 | memset(&rel, 0, sizeof(struct gsm_mncc)); |
| 2736 | rel.callref = trans->callref; |
| 2737 | tlv_parse(&tp, &rsl_att_tlvdef, gh->data, payload_len, 0, 0); |
| 2738 | /* cause */ |
| 2739 | if (TLVP_PRESENT(&tp, GSM48_IE_CAUSE)) { |
| 2740 | rel.fields |= MNCC_F_CAUSE; |
| 2741 | decode_cause(&rel.cause, |
| 2742 | TLVP_VAL(&tp, GSM48_IE_CAUSE)-1); |
| 2743 | } |
| 2744 | /* facility */ |
| 2745 | if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) { |
| 2746 | rel.fields |= MNCC_F_FACILITY; |
| 2747 | decode_facility(&rel.facility, |
| 2748 | TLVP_VAL(&tp, GSM48_IE_FACILITY)-1); |
| 2749 | } |
| 2750 | /* user-user */ |
| 2751 | if (TLVP_PRESENT(&tp, GSM48_IE_USER_USER)) { |
| 2752 | rel.fields |= MNCC_F_USERUSER; |
| 2753 | decode_useruser(&rel.useruser, |
| 2754 | TLVP_VAL(&tp, GSM48_IE_USER_USER)-1); |
| 2755 | } |
| 2756 | /* ss-version */ |
| 2757 | if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) { |
| 2758 | rel.fields |= MNCC_F_SSVERSION; |
| 2759 | decode_ssversion(&rel.ssversion, |
| 2760 | TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1); |
| 2761 | } |
| 2762 | |
| 2763 | if (trans->callref) { |
Harald Welte | c2189a6 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 2764 | switch (trans->cc.state) { |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2765 | case GSM_CSTATE_CALL_PRESENT: |
Harald Welte | 0abe5a6 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 2766 | rc = mncc_recvmsg(trans->subscr->net, trans, |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2767 | MNCC_REJ_IND, &rel); |
| 2768 | break; |
| 2769 | case GSM_CSTATE_RELEASE_REQ: |
Harald Welte | 0abe5a6 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 2770 | rc = mncc_recvmsg(trans->subscr->net, trans, |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2771 | MNCC_REL_CNF, &rel); |
| 2772 | break; |
| 2773 | default: |
Harald Welte | 0abe5a6 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 2774 | rc = mncc_recvmsg(trans->subscr->net, trans, |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2775 | MNCC_REL_IND, &rel); |
| 2776 | } |
| 2777 | } |
| 2778 | |
| 2779 | trans->callref = 0; |
Harald Welte | c2189a6 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 2780 | trans_free(trans); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2781 | |
| 2782 | return rc; |
| 2783 | } |
| 2784 | |
| 2785 | static int gsm48_cc_tx_release_compl(struct gsm_trans *trans, void *arg) |
| 2786 | { |
| 2787 | struct gsm_mncc *rel = arg; |
| 2788 | struct msgb *msg = gsm48_msgb_alloc(); |
| 2789 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 2790 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2791 | gh->msg_type = GSM48_MT_CC_RELEASE_COMPL; |
| 2792 | |
| 2793 | trans->callref = 0; |
| 2794 | |
| 2795 | gsm48_stop_cc_timer(trans); |
| 2796 | |
| 2797 | /* cause */ |
| 2798 | if (rel->fields & MNCC_F_CAUSE) |
| 2799 | encode_cause(msg, 0, &rel->cause); |
| 2800 | /* facility */ |
| 2801 | if (rel->fields & MNCC_F_FACILITY) |
| 2802 | encode_facility(msg, 0, &rel->facility); |
| 2803 | /* user-user */ |
| 2804 | if (rel->fields & MNCC_F_USERUSER) |
| 2805 | encode_useruser(msg, 0, &rel->useruser); |
| 2806 | |
Harald Welte | c2189a6 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 2807 | trans_free(trans); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2808 | |
Harald Welte | 36fe2e8 | 2009-07-23 21:13:03 +0200 | [diff] [blame] | 2809 | return gsm48_sendmsg(msg, trans); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2810 | } |
| 2811 | |
| 2812 | static int gsm48_cc_rx_facility(struct gsm_trans *trans, struct msgb *msg) |
| 2813 | { |
| 2814 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 2815 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 2816 | struct tlv_parsed tp; |
| 2817 | struct gsm_mncc fac; |
| 2818 | |
| 2819 | memset(&fac, 0, sizeof(struct gsm_mncc)); |
| 2820 | fac.callref = trans->callref; |
| 2821 | tlv_parse(&tp, &rsl_att_tlvdef, gh->data, payload_len, GSM48_IE_FACILITY, 0); |
| 2822 | /* facility */ |
| 2823 | if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) { |
| 2824 | fac.fields |= MNCC_F_FACILITY; |
| 2825 | decode_facility(&fac.facility, |
| 2826 | TLVP_VAL(&tp, GSM48_IE_FACILITY)-1); |
| 2827 | } |
| 2828 | /* ss-version */ |
| 2829 | if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) { |
| 2830 | fac.fields |= MNCC_F_SSVERSION; |
| 2831 | decode_ssversion(&fac.ssversion, |
| 2832 | TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1); |
| 2833 | } |
| 2834 | |
Harald Welte | 0abe5a6 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 2835 | return mncc_recvmsg(trans->subscr->net, trans, MNCC_FACILITY_IND, &fac); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2836 | } |
| 2837 | |
| 2838 | static int gsm48_cc_tx_facility(struct gsm_trans *trans, void *arg) |
| 2839 | { |
| 2840 | struct gsm_mncc *fac = arg; |
| 2841 | struct msgb *msg = gsm48_msgb_alloc(); |
| 2842 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 2843 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2844 | gh->msg_type = GSM48_MT_CC_FACILITY; |
| 2845 | |
| 2846 | /* facility */ |
| 2847 | encode_facility(msg, 1, &fac->facility); |
| 2848 | |
Harald Welte | 36fe2e8 | 2009-07-23 21:13:03 +0200 | [diff] [blame] | 2849 | return gsm48_sendmsg(msg, trans); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2850 | } |
| 2851 | |
| 2852 | static int gsm48_cc_rx_hold(struct gsm_trans *trans, struct msgb *msg) |
| 2853 | { |
| 2854 | struct gsm_mncc hold; |
| 2855 | |
| 2856 | memset(&hold, 0, sizeof(struct gsm_mncc)); |
| 2857 | hold.callref = trans->callref; |
Harald Welte | 0abe5a6 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 2858 | return mncc_recvmsg(trans->subscr->net, trans, MNCC_HOLD_IND, &hold); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2859 | } |
| 2860 | |
| 2861 | static int gsm48_cc_tx_hold_ack(struct gsm_trans *trans, void *arg) |
| 2862 | { |
| 2863 | struct msgb *msg = gsm48_msgb_alloc(); |
| 2864 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 2865 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2866 | gh->msg_type = GSM48_MT_CC_HOLD_ACK; |
| 2867 | |
Harald Welte | 36fe2e8 | 2009-07-23 21:13:03 +0200 | [diff] [blame] | 2868 | return gsm48_sendmsg(msg, trans); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2869 | } |
| 2870 | |
| 2871 | static int gsm48_cc_tx_hold_rej(struct gsm_trans *trans, void *arg) |
| 2872 | { |
| 2873 | struct gsm_mncc *hold_rej = arg; |
| 2874 | struct msgb *msg = gsm48_msgb_alloc(); |
| 2875 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 2876 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2877 | gh->msg_type = GSM48_MT_CC_HOLD_REJ; |
| 2878 | |
| 2879 | /* cause */ |
| 2880 | if (hold_rej->fields & MNCC_F_CAUSE) |
| 2881 | encode_cause(msg, 1, &hold_rej->cause); |
| 2882 | else |
| 2883 | encode_cause(msg, 1, &default_cause); |
| 2884 | |
Harald Welte | 36fe2e8 | 2009-07-23 21:13:03 +0200 | [diff] [blame] | 2885 | return gsm48_sendmsg(msg, trans); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2886 | } |
| 2887 | |
| 2888 | static int gsm48_cc_rx_retrieve(struct gsm_trans *trans, struct msgb *msg) |
| 2889 | { |
| 2890 | struct gsm_mncc retrieve; |
| 2891 | |
| 2892 | memset(&retrieve, 0, sizeof(struct gsm_mncc)); |
| 2893 | retrieve.callref = trans->callref; |
Harald Welte | 0abe5a6 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 2894 | return mncc_recvmsg(trans->subscr->net, trans, MNCC_RETRIEVE_IND, |
| 2895 | &retrieve); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2896 | } |
| 2897 | |
| 2898 | static int gsm48_cc_tx_retrieve_ack(struct gsm_trans *trans, void *arg) |
| 2899 | { |
| 2900 | struct msgb *msg = gsm48_msgb_alloc(); |
| 2901 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 2902 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2903 | gh->msg_type = GSM48_MT_CC_RETR_ACK; |
| 2904 | |
Harald Welte | 36fe2e8 | 2009-07-23 21:13:03 +0200 | [diff] [blame] | 2905 | return gsm48_sendmsg(msg, trans); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2906 | } |
| 2907 | |
| 2908 | static int gsm48_cc_tx_retrieve_rej(struct gsm_trans *trans, void *arg) |
| 2909 | { |
| 2910 | struct gsm_mncc *retrieve_rej = arg; |
| 2911 | struct msgb *msg = gsm48_msgb_alloc(); |
| 2912 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 2913 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2914 | gh->msg_type = GSM48_MT_CC_RETR_REJ; |
| 2915 | |
| 2916 | /* cause */ |
| 2917 | if (retrieve_rej->fields & MNCC_F_CAUSE) |
| 2918 | encode_cause(msg, 1, &retrieve_rej->cause); |
| 2919 | else |
| 2920 | encode_cause(msg, 1, &default_cause); |
| 2921 | |
Harald Welte | 36fe2e8 | 2009-07-23 21:13:03 +0200 | [diff] [blame] | 2922 | return gsm48_sendmsg(msg, trans); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2923 | } |
| 2924 | |
| 2925 | static int gsm48_cc_rx_start_dtmf(struct gsm_trans *trans, struct msgb *msg) |
| 2926 | { |
| 2927 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 2928 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 2929 | struct tlv_parsed tp; |
| 2930 | struct gsm_mncc dtmf; |
| 2931 | |
| 2932 | memset(&dtmf, 0, sizeof(struct gsm_mncc)); |
| 2933 | dtmf.callref = trans->callref; |
| 2934 | tlv_parse(&tp, &rsl_att_tlvdef, gh->data, payload_len, 0, 0); |
| 2935 | /* keypad facility */ |
| 2936 | if (TLVP_PRESENT(&tp, GSM48_IE_KPD_FACILITY)) { |
| 2937 | dtmf.fields |= MNCC_F_KEYPAD; |
| 2938 | decode_keypad(&dtmf.keypad, |
| 2939 | TLVP_VAL(&tp, GSM48_IE_KPD_FACILITY)-1); |
| 2940 | } |
| 2941 | |
Harald Welte | 0abe5a6 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 2942 | return mncc_recvmsg(trans->subscr->net, trans, MNCC_START_DTMF_IND, &dtmf); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2943 | } |
| 2944 | |
| 2945 | static int gsm48_cc_tx_start_dtmf_ack(struct gsm_trans *trans, void *arg) |
| 2946 | { |
| 2947 | struct gsm_mncc *dtmf = arg; |
| 2948 | struct msgb *msg = gsm48_msgb_alloc(); |
| 2949 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 2950 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2951 | gh->msg_type = GSM48_MT_CC_START_DTMF_ACK; |
| 2952 | |
| 2953 | /* keypad */ |
| 2954 | if (dtmf->fields & MNCC_F_KEYPAD) |
| 2955 | encode_keypad(msg, dtmf->keypad); |
| 2956 | |
Harald Welte | 36fe2e8 | 2009-07-23 21:13:03 +0200 | [diff] [blame] | 2957 | return gsm48_sendmsg(msg, trans); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2958 | } |
| 2959 | |
| 2960 | static int gsm48_cc_tx_start_dtmf_rej(struct gsm_trans *trans, void *arg) |
| 2961 | { |
| 2962 | struct gsm_mncc *dtmf = arg; |
| 2963 | struct msgb *msg = gsm48_msgb_alloc(); |
| 2964 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 2965 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2966 | gh->msg_type = GSM48_MT_CC_START_DTMF_REJ; |
| 2967 | |
| 2968 | /* cause */ |
| 2969 | if (dtmf->fields & MNCC_F_CAUSE) |
| 2970 | encode_cause(msg, 1, &dtmf->cause); |
| 2971 | else |
| 2972 | encode_cause(msg, 1, &default_cause); |
| 2973 | |
Harald Welte | 36fe2e8 | 2009-07-23 21:13:03 +0200 | [diff] [blame] | 2974 | return gsm48_sendmsg(msg, trans); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2975 | } |
| 2976 | |
| 2977 | static int gsm48_cc_tx_stop_dtmf_ack(struct gsm_trans *trans, void *arg) |
| 2978 | { |
| 2979 | struct msgb *msg = gsm48_msgb_alloc(); |
| 2980 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 2981 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2982 | gh->msg_type = GSM48_MT_CC_STOP_DTMF_ACK; |
| 2983 | |
Harald Welte | 36fe2e8 | 2009-07-23 21:13:03 +0200 | [diff] [blame] | 2984 | return gsm48_sendmsg(msg, trans); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2985 | } |
| 2986 | |
| 2987 | static int gsm48_cc_rx_stop_dtmf(struct gsm_trans *trans, struct msgb *msg) |
| 2988 | { |
| 2989 | struct gsm_mncc dtmf; |
| 2990 | |
| 2991 | memset(&dtmf, 0, sizeof(struct gsm_mncc)); |
| 2992 | dtmf.callref = trans->callref; |
| 2993 | |
Harald Welte | 0abe5a6 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 2994 | return mncc_recvmsg(trans->subscr->net, trans, MNCC_STOP_DTMF_IND, &dtmf); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2995 | } |
| 2996 | |
| 2997 | static int gsm48_cc_rx_modify(struct gsm_trans *trans, struct msgb *msg) |
| 2998 | { |
| 2999 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 3000 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 3001 | struct tlv_parsed tp; |
| 3002 | struct gsm_mncc modify; |
| 3003 | |
| 3004 | memset(&modify, 0, sizeof(struct gsm_mncc)); |
| 3005 | modify.callref = trans->callref; |
| 3006 | tlv_parse(&tp, &rsl_att_tlvdef, gh->data, payload_len, GSM48_IE_BEARER_CAP, 0); |
| 3007 | /* bearer capability */ |
| 3008 | if (TLVP_PRESENT(&tp, GSM48_IE_BEARER_CAP)) { |
| 3009 | modify.fields |= MNCC_F_BEARER_CAP; |
| 3010 | decode_bearer_cap(&modify.bearer_cap, |
| 3011 | TLVP_VAL(&tp, GSM48_IE_BEARER_CAP)-1); |
| 3012 | } |
| 3013 | |
| 3014 | new_cc_state(trans, GSM_CSTATE_MO_ORIG_MODIFY); |
| 3015 | |
Harald Welte | 0abe5a6 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 3016 | return mncc_recvmsg(trans->subscr->net, trans, MNCC_MODIFY_IND, &modify); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3017 | } |
| 3018 | |
| 3019 | static int gsm48_cc_tx_modify(struct gsm_trans *trans, void *arg) |
| 3020 | { |
| 3021 | struct gsm_mncc *modify = arg; |
| 3022 | struct msgb *msg = gsm48_msgb_alloc(); |
| 3023 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 3024 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3025 | gh->msg_type = GSM48_MT_CC_MODIFY; |
| 3026 | |
| 3027 | gsm48_start_cc_timer(trans, 0x323, GSM48_T323); |
| 3028 | |
| 3029 | /* bearer capability */ |
| 3030 | encode_bearer_cap(msg, 1, &modify->bearer_cap); |
| 3031 | |
| 3032 | new_cc_state(trans, GSM_CSTATE_MO_TERM_MODIFY); |
| 3033 | |
Harald Welte | 36fe2e8 | 2009-07-23 21:13:03 +0200 | [diff] [blame] | 3034 | return gsm48_sendmsg(msg, trans); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3035 | } |
| 3036 | |
| 3037 | static int gsm48_cc_rx_modify_complete(struct gsm_trans *trans, struct msgb *msg) |
| 3038 | { |
| 3039 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 3040 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 3041 | struct tlv_parsed tp; |
| 3042 | struct gsm_mncc modify; |
| 3043 | |
| 3044 | gsm48_stop_cc_timer(trans); |
| 3045 | |
| 3046 | memset(&modify, 0, sizeof(struct gsm_mncc)); |
| 3047 | modify.callref = trans->callref; |
| 3048 | tlv_parse(&tp, &rsl_att_tlvdef, gh->data, payload_len, GSM48_IE_BEARER_CAP, 0); |
| 3049 | /* bearer capability */ |
| 3050 | if (TLVP_PRESENT(&tp, GSM48_IE_BEARER_CAP)) { |
| 3051 | modify.fields |= MNCC_F_BEARER_CAP; |
| 3052 | decode_bearer_cap(&modify.bearer_cap, |
| 3053 | TLVP_VAL(&tp, GSM48_IE_BEARER_CAP)-1); |
| 3054 | } |
| 3055 | |
| 3056 | new_cc_state(trans, GSM_CSTATE_ACTIVE); |
| 3057 | |
Harald Welte | 0abe5a6 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 3058 | return mncc_recvmsg(trans->subscr->net, trans, MNCC_MODIFY_CNF, &modify); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3059 | } |
| 3060 | |
| 3061 | static int gsm48_cc_tx_modify_complete(struct gsm_trans *trans, void *arg) |
| 3062 | { |
| 3063 | struct gsm_mncc *modify = arg; |
| 3064 | struct msgb *msg = gsm48_msgb_alloc(); |
| 3065 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 3066 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3067 | gh->msg_type = GSM48_MT_CC_MODIFY_COMPL; |
| 3068 | |
| 3069 | /* bearer capability */ |
| 3070 | encode_bearer_cap(msg, 1, &modify->bearer_cap); |
| 3071 | |
| 3072 | new_cc_state(trans, GSM_CSTATE_ACTIVE); |
| 3073 | |
Harald Welte | 36fe2e8 | 2009-07-23 21:13:03 +0200 | [diff] [blame] | 3074 | return gsm48_sendmsg(msg, trans); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3075 | } |
| 3076 | |
| 3077 | static int gsm48_cc_rx_modify_reject(struct gsm_trans *trans, struct msgb *msg) |
| 3078 | { |
| 3079 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 3080 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 3081 | struct tlv_parsed tp; |
| 3082 | struct gsm_mncc modify; |
| 3083 | |
| 3084 | gsm48_stop_cc_timer(trans); |
| 3085 | |
| 3086 | memset(&modify, 0, sizeof(struct gsm_mncc)); |
| 3087 | modify.callref = trans->callref; |
| 3088 | tlv_parse(&tp, &rsl_att_tlvdef, gh->data, payload_len, GSM48_IE_BEARER_CAP, GSM48_IE_CAUSE); |
| 3089 | /* bearer capability */ |
| 3090 | if (TLVP_PRESENT(&tp, GSM48_IE_BEARER_CAP)) { |
| 3091 | modify.fields |= GSM48_IE_BEARER_CAP; |
| 3092 | decode_bearer_cap(&modify.bearer_cap, |
| 3093 | TLVP_VAL(&tp, GSM48_IE_BEARER_CAP)-1); |
| 3094 | } |
| 3095 | /* cause */ |
| 3096 | if (TLVP_PRESENT(&tp, GSM48_IE_CAUSE)) { |
| 3097 | modify.fields |= MNCC_F_CAUSE; |
| 3098 | decode_cause(&modify.cause, |
| 3099 | TLVP_VAL(&tp, GSM48_IE_CAUSE)-1); |
| 3100 | } |
| 3101 | |
| 3102 | new_cc_state(trans, GSM_CSTATE_ACTIVE); |
| 3103 | |
Harald Welte | 0abe5a6 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 3104 | return mncc_recvmsg(trans->subscr->net, trans, MNCC_MODIFY_REJ, &modify); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3105 | } |
| 3106 | |
| 3107 | static int gsm48_cc_tx_modify_reject(struct gsm_trans *trans, void *arg) |
| 3108 | { |
| 3109 | struct gsm_mncc *modify = arg; |
| 3110 | struct msgb *msg = gsm48_msgb_alloc(); |
| 3111 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 3112 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3113 | gh->msg_type = GSM48_MT_CC_MODIFY_REJECT; |
| 3114 | |
| 3115 | /* bearer capability */ |
| 3116 | encode_bearer_cap(msg, 1, &modify->bearer_cap); |
| 3117 | /* cause */ |
| 3118 | encode_cause(msg, 1, &modify->cause); |
| 3119 | |
| 3120 | new_cc_state(trans, GSM_CSTATE_ACTIVE); |
| 3121 | |
Harald Welte | 36fe2e8 | 2009-07-23 21:13:03 +0200 | [diff] [blame] | 3122 | return gsm48_sendmsg(msg, trans); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3123 | } |
| 3124 | |
| 3125 | static int gsm48_cc_tx_notify(struct gsm_trans *trans, void *arg) |
| 3126 | { |
| 3127 | struct gsm_mncc *notify = arg; |
| 3128 | struct msgb *msg = gsm48_msgb_alloc(); |
| 3129 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 3130 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3131 | gh->msg_type = GSM48_MT_CC_NOTIFY; |
| 3132 | |
| 3133 | /* notify */ |
| 3134 | encode_notify(msg, notify->notify); |
| 3135 | |
Harald Welte | 36fe2e8 | 2009-07-23 21:13:03 +0200 | [diff] [blame] | 3136 | return gsm48_sendmsg(msg, trans); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3137 | } |
| 3138 | |
| 3139 | static int gsm48_cc_rx_notify(struct gsm_trans *trans, struct msgb *msg) |
| 3140 | { |
| 3141 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 3142 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 3143 | // struct tlv_parsed tp; |
| 3144 | struct gsm_mncc notify; |
| 3145 | |
| 3146 | memset(¬ify, 0, sizeof(struct gsm_mncc)); |
| 3147 | notify.callref = trans->callref; |
| 3148 | // tlv_parse(&tp, &rsl_att_tlvdef, gh->data, payload_len); |
| 3149 | if (payload_len >= 1) |
| 3150 | decode_notify(¬ify.notify, gh->data); |
| 3151 | |
Harald Welte | 0abe5a6 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 3152 | return mncc_recvmsg(trans->subscr->net, trans, MNCC_NOTIFY_IND, ¬ify); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3153 | } |
| 3154 | |
| 3155 | static int gsm48_cc_tx_userinfo(struct gsm_trans *trans, void *arg) |
| 3156 | { |
| 3157 | struct gsm_mncc *user = arg; |
| 3158 | struct msgb *msg = gsm48_msgb_alloc(); |
| 3159 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 3160 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3161 | gh->msg_type = GSM48_MT_CC_USER_INFO; |
| 3162 | |
| 3163 | /* user-user */ |
| 3164 | if (user->fields & MNCC_F_USERUSER) |
| 3165 | encode_useruser(msg, 1, &user->useruser); |
| 3166 | /* more data */ |
| 3167 | if (user->more) |
| 3168 | encode_more(msg); |
| 3169 | |
Harald Welte | 36fe2e8 | 2009-07-23 21:13:03 +0200 | [diff] [blame] | 3170 | return gsm48_sendmsg(msg, trans); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3171 | } |
| 3172 | |
| 3173 | static int gsm48_cc_rx_userinfo(struct gsm_trans *trans, struct msgb *msg) |
| 3174 | { |
| 3175 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 3176 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 3177 | struct tlv_parsed tp; |
| 3178 | struct gsm_mncc user; |
| 3179 | |
| 3180 | memset(&user, 0, sizeof(struct gsm_mncc)); |
| 3181 | user.callref = trans->callref; |
| 3182 | tlv_parse(&tp, &rsl_att_tlvdef, gh->data, payload_len, GSM48_IE_USER_USER, 0); |
| 3183 | /* user-user */ |
| 3184 | if (TLVP_PRESENT(&tp, GSM48_IE_USER_USER)) { |
| 3185 | user.fields |= MNCC_F_USERUSER; |
| 3186 | decode_useruser(&user.useruser, |
| 3187 | TLVP_VAL(&tp, GSM48_IE_USER_USER)-1); |
| 3188 | } |
| 3189 | /* more data */ |
| 3190 | if (TLVP_PRESENT(&tp, GSM48_IE_MORE_DATA)) |
| 3191 | user.more = 1; |
| 3192 | |
Harald Welte | 0abe5a6 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 3193 | return mncc_recvmsg(trans->subscr->net, trans, MNCC_USERINFO_IND, &user); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3194 | } |
| 3195 | |
| 3196 | static int gsm48_lchan_modify(struct gsm_trans *trans, void *arg) |
| 3197 | { |
| 3198 | struct gsm_mncc *mode = arg; |
Harald Welte | ca745e2 | 2009-07-29 12:10:35 +0200 | [diff] [blame] | 3199 | int rc; |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3200 | |
Harald Welte | ca745e2 | 2009-07-29 12:10:35 +0200 | [diff] [blame] | 3201 | rc = gsm48_tx_chan_mode_modify(trans->lchan, mode->lchan_mode); |
| 3202 | if (rc < 0) |
| 3203 | return rc; |
| 3204 | |
| 3205 | /* FIXME: we not only need to do this after mode modify, but |
| 3206 | * also after channel activation */ |
| 3207 | if (is_ipaccess_bts(trans->lchan->ts->trx->bts) && |
| 3208 | mode->lchan_mode != GSM48_CMODE_SIGN) |
| 3209 | rc = rsl_ipacc_bind(trans->lchan); |
| 3210 | |
| 3211 | return rc; |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3212 | } |
| 3213 | |
| 3214 | static struct downstate { |
| 3215 | u_int32_t states; |
| 3216 | int type; |
| 3217 | int (*rout) (struct gsm_trans *trans, void *arg); |
| 3218 | } downstatelist[] = { |
| 3219 | /* mobile originating call establishment */ |
| 3220 | {SBIT(GSM_CSTATE_INITIATED), /* 5.2.1.2 */ |
| 3221 | MNCC_CALL_PROC_REQ, gsm48_cc_tx_call_proc}, |
| 3222 | {SBIT(GSM_CSTATE_INITIATED) | SBIT(GSM_CSTATE_MO_CALL_PROC), /* 5.2.1.2 | 5.2.1.5 */ |
| 3223 | MNCC_ALERT_REQ, gsm48_cc_tx_alerting}, |
| 3224 | {SBIT(GSM_CSTATE_INITIATED) | SBIT(GSM_CSTATE_MO_CALL_PROC) | SBIT(GSM_CSTATE_CALL_DELIVERED), /* 5.2.1.2 | 5.2.1.6 | 5.2.1.6 */ |
| 3225 | MNCC_SETUP_RSP, gsm48_cc_tx_connect}, |
| 3226 | {SBIT(GSM_CSTATE_MO_CALL_PROC), /* 5.2.1.4.2 */ |
| 3227 | MNCC_PROGRESS_REQ, gsm48_cc_tx_progress}, |
| 3228 | /* mobile terminating call establishment */ |
| 3229 | {SBIT(GSM_CSTATE_NULL), /* 5.2.2.1 */ |
| 3230 | MNCC_SETUP_REQ, gsm48_cc_tx_setup}, |
| 3231 | {SBIT(GSM_CSTATE_CONNECT_REQUEST), |
| 3232 | MNCC_SETUP_COMPL_REQ, gsm48_cc_tx_connect_ack}, |
| 3233 | /* signalling during call */ |
| 3234 | {SBIT(GSM_CSTATE_ACTIVE), |
| 3235 | MNCC_NOTIFY_REQ, gsm48_cc_tx_notify}, |
| 3236 | {ALL_STATES - SBIT(GSM_CSTATE_NULL) - SBIT(GSM_CSTATE_RELEASE_REQ), |
| 3237 | MNCC_FACILITY_REQ, gsm48_cc_tx_facility}, |
| 3238 | {ALL_STATES, |
| 3239 | MNCC_START_DTMF_RSP, gsm48_cc_tx_start_dtmf_ack}, |
| 3240 | {ALL_STATES, |
| 3241 | MNCC_START_DTMF_REJ, gsm48_cc_tx_start_dtmf_rej}, |
| 3242 | {ALL_STATES, |
| 3243 | MNCC_STOP_DTMF_RSP, gsm48_cc_tx_stop_dtmf_ack}, |
| 3244 | {SBIT(GSM_CSTATE_ACTIVE), |
| 3245 | MNCC_HOLD_CNF, gsm48_cc_tx_hold_ack}, |
| 3246 | {SBIT(GSM_CSTATE_ACTIVE), |
| 3247 | MNCC_HOLD_REJ, gsm48_cc_tx_hold_rej}, |
| 3248 | {SBIT(GSM_CSTATE_ACTIVE), |
| 3249 | MNCC_RETRIEVE_CNF, gsm48_cc_tx_retrieve_ack}, |
| 3250 | {SBIT(GSM_CSTATE_ACTIVE), |
| 3251 | MNCC_RETRIEVE_REJ, gsm48_cc_tx_retrieve_rej}, |
| 3252 | {SBIT(GSM_CSTATE_ACTIVE), |
| 3253 | MNCC_MODIFY_REQ, gsm48_cc_tx_modify}, |
| 3254 | {SBIT(GSM_CSTATE_MO_ORIG_MODIFY), |
| 3255 | MNCC_MODIFY_RSP, gsm48_cc_tx_modify_complete}, |
| 3256 | {SBIT(GSM_CSTATE_MO_ORIG_MODIFY), |
| 3257 | MNCC_MODIFY_REJ, gsm48_cc_tx_modify_reject}, |
| 3258 | {SBIT(GSM_CSTATE_ACTIVE), |
| 3259 | MNCC_USERINFO_REQ, gsm48_cc_tx_userinfo}, |
| 3260 | /* clearing */ |
| 3261 | {SBIT(GSM_CSTATE_INITIATED), |
| 3262 | MNCC_REJ_REQ, gsm48_cc_tx_release_compl}, |
| 3263 | {ALL_STATES - SBIT(GSM_CSTATE_NULL) - SBIT(GSM_CSTATE_DISCONNECT_IND) - SBIT(GSM_CSTATE_RELEASE_REQ) - SBIT(GSM_CSTATE_DISCONNECT_REQ), /* 5.4.4 */ |
| 3264 | MNCC_DISC_REQ, gsm48_cc_tx_disconnect}, |
| 3265 | {ALL_STATES - SBIT(GSM_CSTATE_NULL) - SBIT(GSM_CSTATE_RELEASE_REQ), /* 5.4.3.2 */ |
| 3266 | MNCC_REL_REQ, gsm48_cc_tx_release}, |
| 3267 | /* special */ |
| 3268 | {ALL_STATES, |
| 3269 | MNCC_LCHAN_MODIFY, gsm48_lchan_modify}, |
| 3270 | }; |
| 3271 | |
| 3272 | #define DOWNSLLEN \ |
| 3273 | (sizeof(downstatelist) / sizeof(struct downstate)) |
| 3274 | |
| 3275 | |
| 3276 | int mncc_send(struct gsm_network *net, int msg_type, void *arg) |
| 3277 | { |
Harald Welte | aa60edb | 2009-08-09 18:52:33 +0200 | [diff] [blame] | 3278 | int i, rc = 0; |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3279 | struct gsm_trans *trans = NULL, *transt; |
| 3280 | struct gsm_subscriber *subscr; |
Harald Welte | aa60edb | 2009-08-09 18:52:33 +0200 | [diff] [blame] | 3281 | struct gsm_lchan *lchan = NULL; |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3282 | struct gsm_bts *bts = NULL; |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3283 | struct gsm_mncc *data = arg, rel; |
| 3284 | |
| 3285 | /* handle special messages */ |
| 3286 | switch(msg_type) { |
| 3287 | case MNCC_BRIDGE: |
| 3288 | return tch_bridge(net, arg); |
| 3289 | case MNCC_FRAME_DROP: |
| 3290 | return tch_recv(net, arg, 0); |
| 3291 | case MNCC_FRAME_RECV: |
| 3292 | return tch_recv(net, arg, 1); |
| 3293 | case GSM_TRAU_FRAME: |
| 3294 | return tch_frame(net, arg); |
| 3295 | } |
| 3296 | |
| 3297 | memset(&rel, 0, sizeof(struct gsm_mncc)); |
| 3298 | rel.callref = data->callref; |
| 3299 | |
| 3300 | /* Find callref */ |
Harald Welte | c2189a6 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 3301 | trans = trans_find_by_callref(net, data->callref); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3302 | |
| 3303 | /* Callref unknown */ |
| 3304 | if (!trans) { |
Harald Welte | 6e1536e | 2009-07-04 10:11:24 +0200 | [diff] [blame] | 3305 | if (msg_type != MNCC_SETUP_REQ) { |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3306 | DEBUGP(DCC, "(bts - trx - ts - ti -- sub %s) " |
| 3307 | "Received '%s' from MNCC with " |
| 3308 | "unknown callref %d\n", data->called.number, |
| 3309 | get_mncc_name(msg_type), data->callref); |
| 3310 | /* Invalid call reference */ |
Andreas Eversberg | b992a8a | 2009-06-14 22:14:12 +0800 | [diff] [blame] | 3311 | return mncc_release_ind(net, NULL, data->callref, |
| 3312 | GSM48_CAUSE_LOC_PRN_S_LU, |
| 3313 | GSM48_CC_CAUSE_INVAL_TRANS_ID); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3314 | } |
Andreas Eversberg | 9eaa5da | 2009-06-15 23:22:09 +0200 | [diff] [blame] | 3315 | if (!data->called.number[0] && !data->imsi[0]) { |
| 3316 | DEBUGP(DCC, "(bts - trx - ts - ti) " |
| 3317 | "Received '%s' from MNCC with " |
| 3318 | "no number or IMSI\n", get_mncc_name(msg_type)); |
| 3319 | /* Invalid number */ |
| 3320 | return mncc_release_ind(net, NULL, data->callref, |
| 3321 | GSM48_CAUSE_LOC_PRN_S_LU, |
| 3322 | GSM48_CC_CAUSE_INV_NR_FORMAT); |
| 3323 | } |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3324 | /* New transaction due to setup, find subscriber */ |
Andreas Eversberg | 9eaa5da | 2009-06-15 23:22:09 +0200 | [diff] [blame] | 3325 | if (data->called.number[0]) |
Harald Welte | 7535041 | 2009-07-23 18:46:00 +0200 | [diff] [blame] | 3326 | subscr = subscr_get_by_extension(net, |
| 3327 | data->called.number); |
Andreas Eversberg | 9eaa5da | 2009-06-15 23:22:09 +0200 | [diff] [blame] | 3328 | else |
Harald Welte | 7535041 | 2009-07-23 18:46:00 +0200 | [diff] [blame] | 3329 | subscr = subscr_get_by_imsi(net, data->imsi); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3330 | /* If subscriber is not found */ |
| 3331 | if (!subscr) { |
| 3332 | DEBUGP(DCC, "(bts - trx - ts - ti -- sub %s) " |
| 3333 | "Received '%s' from MNCC with " |
| 3334 | "unknown subscriber %s\n", data->called.number, |
| 3335 | get_mncc_name(msg_type), data->called.number); |
| 3336 | /* Unknown subscriber */ |
Andreas Eversberg | b992a8a | 2009-06-14 22:14:12 +0800 | [diff] [blame] | 3337 | return mncc_release_ind(net, NULL, data->callref, |
| 3338 | GSM48_CAUSE_LOC_PRN_S_LU, |
| 3339 | GSM48_CC_CAUSE_UNASSIGNED_NR); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3340 | } |
| 3341 | /* If subscriber is not "attached" */ |
| 3342 | if (!subscr->lac) { |
| 3343 | DEBUGP(DCC, "(bts - trx - ts - ti -- sub %s) " |
| 3344 | "Received '%s' from MNCC with " |
| 3345 | "detached subscriber %s\n", data->called.number, |
| 3346 | get_mncc_name(msg_type), data->called.number); |
| 3347 | subscr_put(subscr); |
| 3348 | /* Temporarily out of order */ |
Andreas Eversberg | b992a8a | 2009-06-14 22:14:12 +0800 | [diff] [blame] | 3349 | return mncc_release_ind(net, NULL, data->callref, |
| 3350 | GSM48_CAUSE_LOC_PRN_S_LU, |
| 3351 | GSM48_CC_CAUSE_DEST_OOO); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3352 | } |
| 3353 | /* Create transaction */ |
Harald Welte | c2189a6 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 3354 | trans = trans_alloc(subscr, GSM48_PDISC_CC, 0xff, data->callref); |
| 3355 | if (!trans) { |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3356 | DEBUGP(DCC, "No memory for trans.\n"); |
| 3357 | subscr_put(subscr); |
| 3358 | /* Ressource unavailable */ |
Andreas Eversberg | b992a8a | 2009-06-14 22:14:12 +0800 | [diff] [blame] | 3359 | mncc_release_ind(net, NULL, data->callref, |
| 3360 | GSM48_CAUSE_LOC_PRN_S_LU, |
| 3361 | GSM48_CC_CAUSE_RESOURCE_UNAVAIL); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3362 | return -ENOMEM; |
| 3363 | } |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3364 | /* Find lchan */ |
Harald Welte | aa60edb | 2009-08-09 18:52:33 +0200 | [diff] [blame] | 3365 | lchan = lchan_for_subscr(subscr); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3366 | /* If subscriber has no lchan */ |
| 3367 | if (!lchan) { |
| 3368 | /* find transaction with this subscriber already paging */ |
| 3369 | llist_for_each_entry(transt, &net->trans_list, entry) { |
| 3370 | /* Transaction of our lchan? */ |
| 3371 | if (transt == trans || |
| 3372 | transt->subscr != subscr) |
| 3373 | continue; |
| 3374 | DEBUGP(DCC, "(bts %d trx - ts - ti -- sub %s) " |
| 3375 | "Received '%s' from MNCC with " |
| 3376 | "unallocated channel, paging already " |
| 3377 | "started.\n", bts->nr, |
| 3378 | data->called.number, |
| 3379 | get_mncc_name(msg_type)); |
| 3380 | return 0; |
| 3381 | } |
| 3382 | /* store setup informations until paging was successfull */ |
Harald Welte | c2189a6 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 3383 | memcpy(&trans->cc.msg, data, sizeof(struct gsm_mncc)); |
Harald Welte | 2a3a81b | 2009-08-01 19:31:47 +0200 | [diff] [blame] | 3384 | /* Trigger paging */ |
| 3385 | paging_request(net, subscr, RSL_CHANNEED_TCH_F, |
| 3386 | setup_trig_pag_evt, subscr); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3387 | return 0; |
| 3388 | } |
| 3389 | /* Assign lchan */ |
| 3390 | trans->lchan = lchan; |
| 3391 | use_lchan(lchan); |
| 3392 | } |
| 3393 | lchan = trans->lchan; |
| 3394 | |
| 3395 | /* if paging did not respond yet */ |
| 3396 | if (!lchan) { |
| 3397 | DEBUGP(DCC, "(bts - trx - ts - ti -- sub %s) " |
| 3398 | "Received '%s' from MNCC in paging state\n", |
| 3399 | (trans->subscr)?(trans->subscr->extension):"-", |
| 3400 | get_mncc_name(msg_type)); |
Harald Welte | bbc636a | 2009-06-11 14:23:20 +0800 | [diff] [blame] | 3401 | mncc_set_cause(&rel, GSM48_CAUSE_LOC_PRN_S_LU, |
| 3402 | GSM48_CC_CAUSE_NORM_CALL_CLEAR); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3403 | if (msg_type == MNCC_REL_REQ) |
| 3404 | rc = mncc_recvmsg(net, trans, MNCC_REL_CNF, &rel); |
| 3405 | else |
| 3406 | rc = mncc_recvmsg(net, trans, MNCC_REL_IND, &rel); |
| 3407 | trans->callref = 0; |
Harald Welte | c2189a6 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 3408 | trans_free(trans); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3409 | return rc; |
| 3410 | } |
| 3411 | |
| 3412 | DEBUGP(DCC, "(bts %d trx %d ts %d ti %02x sub %s) " |
| 3413 | "Received '%s' from MNCC in state %d (%s)\n", |
| 3414 | lchan->ts->trx->bts->nr, lchan->ts->trx->nr, lchan->ts->nr, |
| 3415 | trans->transaction_id, |
| 3416 | (lchan->subscr)?(lchan->subscr->extension):"-", |
Harald Welte | c2189a6 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 3417 | get_mncc_name(msg_type), trans->cc.state, |
| 3418 | cc_state_names[trans->cc.state]); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3419 | |
| 3420 | /* Find function for current state and message */ |
| 3421 | for (i = 0; i < DOWNSLLEN; i++) |
| 3422 | if ((msg_type == downstatelist[i].type) |
Harald Welte | c2189a6 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 3423 | && ((1 << trans->cc.state) & downstatelist[i].states)) |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3424 | break; |
| 3425 | if (i == DOWNSLLEN) { |
| 3426 | DEBUGP(DCC, "Message unhandled at this state.\n"); |
| 3427 | return 0; |
| 3428 | } |
| 3429 | |
| 3430 | rc = downstatelist[i].rout(trans, arg); |
| 3431 | |
| 3432 | return rc; |
| 3433 | } |
| 3434 | |
| 3435 | |
| 3436 | static struct datastate { |
| 3437 | u_int32_t states; |
| 3438 | int type; |
| 3439 | int (*rout) (struct gsm_trans *trans, struct msgb *msg); |
| 3440 | } datastatelist[] = { |
| 3441 | /* mobile originating call establishment */ |
| 3442 | {SBIT(GSM_CSTATE_NULL), /* 5.2.1.2 */ |
| 3443 | GSM48_MT_CC_SETUP, gsm48_cc_rx_setup}, |
| 3444 | {SBIT(GSM_CSTATE_NULL), /* 5.2.1.2 */ |
| 3445 | GSM48_MT_CC_EMERG_SETUP, gsm48_cc_rx_setup}, |
| 3446 | {SBIT(GSM_CSTATE_CONNECT_IND), /* 5.2.1.2 */ |
| 3447 | GSM48_MT_CC_CONNECT_ACK, gsm48_cc_rx_connect_ack}, |
| 3448 | /* mobile terminating call establishment */ |
| 3449 | {SBIT(GSM_CSTATE_CALL_PRESENT), /* 5.2.2.3.2 */ |
| 3450 | GSM48_MT_CC_CALL_CONF, gsm48_cc_rx_call_conf}, |
| 3451 | {SBIT(GSM_CSTATE_CALL_PRESENT) | SBIT(GSM_CSTATE_MO_TERM_CALL_CONF), /* ???? | 5.2.2.3.2 */ |
| 3452 | GSM48_MT_CC_ALERTING, gsm48_cc_rx_alerting}, |
| 3453 | {SBIT(GSM_CSTATE_CALL_PRESENT) | SBIT(GSM_CSTATE_MO_TERM_CALL_CONF) | SBIT(GSM_CSTATE_CALL_RECEIVED), /* (5.2.2.6) | 5.2.2.6 | 5.2.2.6 */ |
| 3454 | GSM48_MT_CC_CONNECT, gsm48_cc_rx_connect}, |
| 3455 | /* signalling during call */ |
| 3456 | {ALL_STATES - SBIT(GSM_CSTATE_NULL), |
| 3457 | GSM48_MT_CC_FACILITY, gsm48_cc_rx_facility}, |
| 3458 | {SBIT(GSM_CSTATE_ACTIVE), |
| 3459 | GSM48_MT_CC_NOTIFY, gsm48_cc_rx_notify}, |
| 3460 | {ALL_STATES, |
| 3461 | GSM48_MT_CC_START_DTMF, gsm48_cc_rx_start_dtmf}, |
| 3462 | {ALL_STATES, |
| 3463 | GSM48_MT_CC_STOP_DTMF, gsm48_cc_rx_stop_dtmf}, |
| 3464 | {ALL_STATES, |
| 3465 | GSM48_MT_CC_STATUS_ENQ, gsm48_cc_rx_status_enq}, |
| 3466 | {SBIT(GSM_CSTATE_ACTIVE), |
| 3467 | GSM48_MT_CC_HOLD, gsm48_cc_rx_hold}, |
| 3468 | {SBIT(GSM_CSTATE_ACTIVE), |
| 3469 | GSM48_MT_CC_RETR, gsm48_cc_rx_retrieve}, |
| 3470 | {SBIT(GSM_CSTATE_ACTIVE), |
| 3471 | GSM48_MT_CC_MODIFY, gsm48_cc_rx_modify}, |
| 3472 | {SBIT(GSM_CSTATE_MO_TERM_MODIFY), |
| 3473 | GSM48_MT_CC_MODIFY_COMPL, gsm48_cc_rx_modify_complete}, |
| 3474 | {SBIT(GSM_CSTATE_MO_TERM_MODIFY), |
| 3475 | GSM48_MT_CC_MODIFY_REJECT, gsm48_cc_rx_modify_reject}, |
| 3476 | {SBIT(GSM_CSTATE_ACTIVE), |
| 3477 | GSM48_MT_CC_USER_INFO, gsm48_cc_rx_userinfo}, |
| 3478 | /* clearing */ |
| 3479 | {ALL_STATES - SBIT(GSM_CSTATE_NULL) - SBIT(GSM_CSTATE_RELEASE_REQ), /* 5.4.3.2 */ |
| 3480 | GSM48_MT_CC_DISCONNECT, gsm48_cc_rx_disconnect}, |
| 3481 | {ALL_STATES - SBIT(GSM_CSTATE_NULL), /* 5.4.4.1.2.2 */ |
| 3482 | GSM48_MT_CC_RELEASE, gsm48_cc_rx_release}, |
| 3483 | {ALL_STATES, /* 5.4.3.4 */ |
| 3484 | GSM48_MT_CC_RELEASE_COMPL, gsm48_cc_rx_release_compl}, |
| 3485 | }; |
| 3486 | |
| 3487 | #define DATASLLEN \ |
| 3488 | (sizeof(datastatelist) / sizeof(struct datastate)) |
| 3489 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 3490 | static int gsm0408_rcv_cc(struct msgb *msg) |
| 3491 | { |
| 3492 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 3493 | u_int8_t msg_type = gh->msg_type & 0xbf; |
Harald Welte | 4861c82 | 2009-07-23 21:21:14 +0200 | [diff] [blame] | 3494 | u_int8_t transaction_id = ((gh->proto_discr & 0xf0) ^ 0x80) >> 4; /* flip */ |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3495 | struct gsm_lchan *lchan = msg->lchan; |
Harald Welte | c2189a6 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 3496 | struct gsm_trans *trans = NULL; |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3497 | int i, rc = 0; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 3498 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3499 | if (msg_type & 0x80) { |
| 3500 | DEBUGP(DCC, "MSG 0x%2x not defined for PD error\n", msg_type); |
| 3501 | return -EINVAL; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 3502 | } |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3503 | |
| 3504 | /* Find transaction */ |
Harald Welte | 0d82416 | 2009-07-23 21:58:40 +0200 | [diff] [blame] | 3505 | trans = trans_find_by_id(lchan->subscr, GSM48_PDISC_CC, transaction_id); |
Harald Welte | c2189a6 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 3506 | |
Harald Welte | 4861c82 | 2009-07-23 21:21:14 +0200 | [diff] [blame] | 3507 | DEBUGP(DCC, "(bts %d trx %d ts %d ti %x sub %s) " |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3508 | "Received '%s' from MS in state %d (%s)\n", |
| 3509 | lchan->ts->trx->bts->nr, lchan->ts->trx->nr, lchan->ts->nr, |
| 3510 | transaction_id, (lchan->subscr)?(lchan->subscr->extension):"-", |
Holger Hans Peter Freyther | 3689710 | 2009-08-01 07:26:59 +0200 | [diff] [blame] | 3511 | gsm0408_cc_msg_names[msg_type], trans?(trans->cc.state):0, |
Harald Welte | c2189a6 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 3512 | cc_state_names[trans?(trans->cc.state):0]); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3513 | |
| 3514 | /* Create transaction */ |
| 3515 | if (!trans) { |
Harald Welte | 4861c82 | 2009-07-23 21:21:14 +0200 | [diff] [blame] | 3516 | DEBUGP(DCC, "Unknown transaction ID %x, " |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3517 | "creating new trans.\n", transaction_id); |
| 3518 | /* Create transaction */ |
Harald Welte | c2189a6 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 3519 | trans = trans_alloc(lchan->subscr, GSM48_PDISC_CC, |
| 3520 | transaction_id, new_callref++); |
| 3521 | if (!trans) { |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3522 | DEBUGP(DCC, "No memory for trans.\n"); |
| 3523 | rc = gsm48_tx_simple(msg->lchan, |
Harald Welte | 4861c82 | 2009-07-23 21:21:14 +0200 | [diff] [blame] | 3524 | GSM48_PDISC_CC | (transaction_id << 4), |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3525 | GSM48_MT_CC_RELEASE_COMPL); |
| 3526 | return -ENOMEM; |
| 3527 | } |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3528 | /* Assign transaction */ |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3529 | trans->lchan = lchan; |
| 3530 | use_lchan(lchan); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3531 | } |
| 3532 | |
| 3533 | /* find function for current state and message */ |
| 3534 | for (i = 0; i < DATASLLEN; i++) |
| 3535 | if ((msg_type == datastatelist[i].type) |
Harald Welte | c2189a6 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 3536 | && ((1 << trans->cc.state) & datastatelist[i].states)) |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3537 | break; |
| 3538 | if (i == DATASLLEN) { |
| 3539 | DEBUGP(DCC, "Message unhandled at this state.\n"); |
| 3540 | return 0; |
| 3541 | } |
| 3542 | |
| 3543 | rc = datastatelist[i].rout(trans, msg); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 3544 | |
| 3545 | return rc; |
| 3546 | } |
| 3547 | |
| 3548 | /* here we pass in a msgb from the RSL->RLL. We expect the l3 pointer to be set */ |
Harald Welte (local) | 64994ce | 2009-08-14 11:41:12 +0200 | [diff] [blame] | 3549 | int gsm0408_rcvmsg(struct msgb *msg, u_int8_t link_id) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 3550 | { |
| 3551 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 3552 | u_int8_t pdisc = gh->proto_discr & 0x0f; |
| 3553 | int rc = 0; |
| 3554 | |
| 3555 | switch (pdisc) { |
| 3556 | case GSM48_PDISC_CC: |
| 3557 | rc = gsm0408_rcv_cc(msg); |
| 3558 | break; |
| 3559 | case GSM48_PDISC_MM: |
| 3560 | rc = gsm0408_rcv_mm(msg); |
| 3561 | break; |
| 3562 | case GSM48_PDISC_RR: |
| 3563 | rc = gsm0408_rcv_rr(msg); |
| 3564 | break; |
| 3565 | case GSM48_PDISC_SMS: |
Harald Welte (local) | 64994ce | 2009-08-14 11:41:12 +0200 | [diff] [blame] | 3566 | rc = gsm0411_rcv_sms(msg, link_id); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 3567 | break; |
| 3568 | case GSM48_PDISC_MM_GPRS: |
| 3569 | case GSM48_PDISC_SM_GPRS: |
Mike Haben | 2f8a685 | 2009-09-26 19:00:03 +0200 | [diff] [blame] | 3570 | case GSM48_PDISC_NC_SS: /* mobile-originated USSD */ |
| 3571 | fprintf(stderr, "Unimplemented GSM 04.08 discriminator 0x%02x\n", |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 3572 | pdisc); |
| 3573 | break; |
| 3574 | default: |
Mike Haben | 2f8a685 | 2009-09-26 19:00:03 +0200 | [diff] [blame] | 3575 | fprintf(stderr, "Unknown GSM 04.08 discriminator 0x%02x\n", |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 3576 | pdisc); |
| 3577 | break; |
| 3578 | } |
| 3579 | |
| 3580 | return rc; |
| 3581 | } |
| 3582 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3583 | /* dequeue messages to layer 4 */ |
| 3584 | int bsc_upqueue(struct gsm_network *net) |
| 3585 | { |
| 3586 | struct gsm_mncc *mncc; |
| 3587 | struct msgb *msg; |
| 3588 | int work = 0; |
| 3589 | |
| 3590 | if (net) |
| 3591 | while ((msg = msgb_dequeue(&net->upqueue))) { |
| 3592 | mncc = (struct gsm_mncc *)msg->data; |
| 3593 | if (net->mncc_recv) |
| 3594 | net->mncc_recv(net, mncc->msg_type, mncc); |
| 3595 | work = 1; /* work done */ |
Harald Welte | baf4d3a | 2009-06-26 19:40:48 +0200 | [diff] [blame] | 3596 | talloc_free(msg); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3597 | } |
| 3598 | |
| 3599 | return work; |
| 3600 | } |
Harald Welte | c2189a6 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 3601 | |
Harald Welte | 3c06207 | 2009-07-28 18:25:29 +0200 | [diff] [blame] | 3602 | /* |
| 3603 | * This will be ran by the linker when loading the DSO. We use it to |
| 3604 | * do system initialization, e.g. registration of signal handlers. |
| 3605 | */ |
| 3606 | static __attribute__((constructor)) void on_dso_load_0408(void) |
| 3607 | { |
Harald Welte | 3c06207 | 2009-07-28 18:25:29 +0200 | [diff] [blame] | 3608 | register_signal_handler(SS_LCHAN, gsm0408_handle_lchan_signal, NULL); |
| 3609 | register_signal_handler(SS_ABISIP, handle_abisip_signal, NULL); |
| 3610 | } |