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