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