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