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