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