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