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