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