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