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