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