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