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