Holger Hans Peter Freyther | ec32b58 | 2010-03-23 07:40:46 +0100 | [diff] [blame] | 1 | /* GSM 08.08 like API for OpenBSC. The bridge from MSC to BSC */ |
| 2 | |
Holger Hans Peter Freyther | 594b322 | 2011-08-06 06:42:00 +0200 | [diff] [blame] | 3 | /* (C) 2010-2011 by Holger Hans Peter Freyther |
| 4 | * (C) 2010-2011 by On-Waves |
Holger Hans Peter Freyther | 2a9285c | 2010-06-14 18:03:06 +0800 | [diff] [blame] | 5 | * (C) 2009 by Harald Welte <laforge@gnumonks.org> |
Holger Hans Peter Freyther | ec32b58 | 2010-03-23 07:40:46 +0100 | [diff] [blame] | 6 | * |
| 7 | * All Rights Reserved |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 10 | * it under the terms of the GNU Affero General Public License as published by |
| 11 | * the Free Software Foundation; either version 3 of the License, or |
Holger Hans Peter Freyther | ec32b58 | 2010-03-23 07:40:46 +0100 | [diff] [blame] | 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 |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 17 | * GNU Affero General Public License for more details. |
Holger Hans Peter Freyther | ec32b58 | 2010-03-23 07:40:46 +0100 | [diff] [blame] | 18 | * |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 19 | * You should have received a copy of the GNU Affero General Public License |
| 20 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
Holger Hans Peter Freyther | ec32b58 | 2010-03-23 07:40:46 +0100 | [diff] [blame] | 21 | * |
| 22 | */ |
| 23 | |
| 24 | #include <openbsc/bsc_api.h> |
Holger Hans Peter Freyther | 9c595b7 | 2010-06-15 11:20:52 +0800 | [diff] [blame] | 25 | #include <openbsc/bsc_rll.h> |
Holger Hans Peter Freyther | abcddf1 | 2010-06-14 18:20:15 +0800 | [diff] [blame] | 26 | #include <openbsc/gsm_data.h> |
Holger Hans Peter Freyther | e2fee35 | 2010-12-22 12:32:56 +0100 | [diff] [blame] | 27 | #include <openbsc/gsm_subscriber.h> |
Holger Hans Peter Freyther | abcddf1 | 2010-06-14 18:20:15 +0800 | [diff] [blame] | 28 | #include <openbsc/signal.h> |
Holger Hans Peter Freyther | ec32b58 | 2010-03-23 07:40:46 +0100 | [diff] [blame] | 29 | #include <openbsc/abis_rsl.h> |
Holger Hans Peter Freyther | 9764331 | 2010-06-17 16:41:25 +0800 | [diff] [blame] | 30 | #include <openbsc/chan_alloc.h> |
Holger Hans Peter Freyther | f2553a6 | 2010-06-30 12:58:14 +0800 | [diff] [blame] | 31 | #include <openbsc/handover.h> |
Holger Hans Peter Freyther | 49ab278 | 2010-07-05 11:38:37 +0800 | [diff] [blame] | 32 | #include <openbsc/debug.h> |
Holger Hans Peter Freyther | 77cd95d | 2010-11-14 16:19:48 +0100 | [diff] [blame] | 33 | #include <openbsc/gsm_04_08.h> |
Andreas Eversberg | dcf38e1 | 2013-12-05 14:37:11 +0100 | [diff] [blame] | 34 | #include <openbsc/trau_mux.h> |
Harald Welte | 9066b74 | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 35 | #include <openbsc/vlr.h> |
Holger Hans Peter Freyther | ec32b58 | 2010-03-23 07:40:46 +0100 | [diff] [blame] | 36 | |
Pablo Neira Ayuso | 136f453 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 37 | #include <osmocom/gsm/protocol/gsm_08_08.h> |
Philipp | d37981e | 2016-10-10 15:11:41 +0200 | [diff] [blame] | 38 | #include <osmocom/gsm/gsm48.h> |
Holger Hans Peter Freyther | 6c199e7 | 2010-11-04 11:18:03 +0100 | [diff] [blame] | 39 | |
Pablo Neira Ayuso | 136f453 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 40 | #include <osmocom/core/talloc.h> |
Holger Hans Peter Freyther | abcddf1 | 2010-06-14 18:20:15 +0800 | [diff] [blame] | 41 | |
Holger Hans Peter Freyther | 77cd95d | 2010-11-14 16:19:48 +0100 | [diff] [blame] | 42 | #define GSM0808_T10_VALUE 6, 0 |
| 43 | |
Holger Hans Peter Freyther | 79f763f | 2010-09-16 00:53:37 +0800 | [diff] [blame] | 44 | |
Holger Hans Peter Freyther | 9c595b7 | 2010-06-15 11:20:52 +0800 | [diff] [blame] | 45 | static void rll_ind_cb(struct gsm_lchan *, uint8_t, void *, enum bsc_rllr_ind); |
| 46 | static void send_sapi_reject(struct gsm_subscriber_connection *conn, int link_id); |
Holger Hans Peter Freyther | f05750c | 2010-11-14 19:29:42 +0100 | [diff] [blame] | 47 | static void handle_release(struct gsm_subscriber_connection *conn, struct bsc_api *bsc, struct gsm_lchan *lchan); |
Holger Hans Peter Freyther | 77cd95d | 2010-11-14 16:19:48 +0100 | [diff] [blame] | 48 | static void handle_chan_ack(struct gsm_subscriber_connection *conn, struct bsc_api *bsc, struct gsm_lchan *lchan); |
| 49 | static void handle_chan_nack(struct gsm_subscriber_connection *conn, struct bsc_api *bsc, struct gsm_lchan *lchan); |
Holger Hans Peter Freyther | 9c595b7 | 2010-06-15 11:20:52 +0800 | [diff] [blame] | 50 | |
Holger Hans Peter Freyther | b094171 | 2010-11-04 12:06:57 +0100 | [diff] [blame] | 51 | /* GSM 08.08 3.2.2.33 */ |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 52 | static uint8_t lchan_to_chosen_channel(struct gsm_lchan *lchan) |
Holger Hans Peter Freyther | b094171 | 2010-11-04 12:06:57 +0100 | [diff] [blame] | 53 | { |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 54 | uint8_t channel_mode = 0, channel = 0; |
Holger Hans Peter Freyther | b094171 | 2010-11-04 12:06:57 +0100 | [diff] [blame] | 55 | |
| 56 | switch (lchan->tch_mode) { |
| 57 | case GSM48_CMODE_SPEECH_V1: |
| 58 | case GSM48_CMODE_SPEECH_EFR: |
| 59 | case GSM48_CMODE_SPEECH_AMR: |
| 60 | channel_mode = 0x9; |
| 61 | break; |
| 62 | case GSM48_CMODE_SIGN: |
| 63 | channel_mode = 0x8; |
| 64 | break; |
| 65 | case GSM48_CMODE_DATA_14k5: |
| 66 | channel_mode = 0xe; |
| 67 | break; |
| 68 | case GSM48_CMODE_DATA_12k0: |
| 69 | channel_mode = 0xb; |
| 70 | break; |
| 71 | case GSM48_CMODE_DATA_6k0: |
| 72 | channel_mode = 0xc; |
| 73 | break; |
| 74 | case GSM48_CMODE_DATA_3k6: |
| 75 | channel_mode = 0xd; |
| 76 | break; |
| 77 | } |
| 78 | |
| 79 | switch (lchan->type) { |
| 80 | case GSM_LCHAN_NONE: |
| 81 | channel = 0x0; |
| 82 | break; |
| 83 | case GSM_LCHAN_SDCCH: |
| 84 | channel = 0x1; |
| 85 | break; |
| 86 | case GSM_LCHAN_TCH_F: |
| 87 | channel = 0x8; |
| 88 | break; |
| 89 | case GSM_LCHAN_TCH_H: |
| 90 | channel = 0x9; |
| 91 | break; |
| 92 | case GSM_LCHAN_UNKNOWN: |
Harald Welte | 7b1d25a | 2015-01-01 12:32:03 +0100 | [diff] [blame] | 93 | default: |
Holger Hans Peter Freyther | b094171 | 2010-11-04 12:06:57 +0100 | [diff] [blame] | 94 | LOGP(DMSC, LOGL_ERROR, "Unknown lchan type: %p\n", lchan); |
| 95 | break; |
| 96 | } |
| 97 | |
| 98 | return channel_mode << 4 | channel; |
| 99 | } |
| 100 | |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 101 | static uint8_t chan_mode_to_speech(struct gsm_lchan *lchan) |
Holger Hans Peter Freyther | b094171 | 2010-11-04 12:06:57 +0100 | [diff] [blame] | 102 | { |
| 103 | int mode = 0; |
| 104 | |
| 105 | switch (lchan->tch_mode) { |
| 106 | case GSM48_CMODE_SPEECH_V1: |
| 107 | mode = 1; |
| 108 | break; |
| 109 | case GSM48_CMODE_SPEECH_EFR: |
| 110 | mode = 0x11; |
| 111 | break; |
| 112 | case GSM48_CMODE_SPEECH_AMR: |
| 113 | mode = 0x21; |
| 114 | break; |
| 115 | case GSM48_CMODE_SIGN: |
| 116 | case GSM48_CMODE_DATA_14k5: |
| 117 | case GSM48_CMODE_DATA_12k0: |
| 118 | case GSM48_CMODE_DATA_6k0: |
| 119 | case GSM48_CMODE_DATA_3k6: |
| 120 | default: |
| 121 | LOGP(DMSC, LOGL_ERROR, "Using non speech mode: %d\n", mode); |
| 122 | return 0; |
| 123 | break; |
| 124 | } |
| 125 | |
| 126 | /* assume to always do AMR HR on any TCH type */ |
| 127 | if (lchan->type == GSM_LCHAN_TCH_H || |
| 128 | lchan->tch_mode == GSM48_CMODE_SPEECH_AMR) |
| 129 | mode |= 0x4; |
| 130 | |
| 131 | return mode; |
| 132 | } |
| 133 | |
Holger Hans Peter Freyther | 77cd95d | 2010-11-14 16:19:48 +0100 | [diff] [blame] | 134 | static void assignment_t10_timeout(void *_conn) |
| 135 | { |
| 136 | struct bsc_api *api; |
| 137 | struct gsm_subscriber_connection *conn = |
| 138 | (struct gsm_subscriber_connection *) _conn; |
| 139 | |
Ruben Undheim | 59d57da | 2016-12-20 17:38:31 +0100 | [diff] [blame] | 140 | LOGP(DMSC, LOGL_ERROR, "Assignment T10 timeout on %p\n", conn); |
Holger Hans Peter Freyther | 77cd95d | 2010-11-14 16:19:48 +0100 | [diff] [blame] | 141 | |
Holger Hans Peter Freyther | cab0d7b | 2011-08-30 19:07:58 +0200 | [diff] [blame] | 142 | /* |
| 143 | * normal release on the secondary channel but only if the |
| 144 | * secondary_channel has not been released by the handle_chan_nack. |
| 145 | */ |
| 146 | if (conn->secondary_lchan) |
Holger Hans Peter Freyther | d66777f | 2012-12-06 12:20:56 +0100 | [diff] [blame] | 147 | lchan_release(conn->secondary_lchan, 0, RSL_REL_LOCAL_END); |
Holger Hans Peter Freyther | 77cd95d | 2010-11-14 16:19:48 +0100 | [diff] [blame] | 148 | conn->secondary_lchan = NULL; |
| 149 | |
| 150 | /* inform them about the failure */ |
Neels Hofmeyr | a9f2bb5 | 2016-05-09 21:09:47 +0200 | [diff] [blame] | 151 | api = conn->network->bsc_api; |
Holger Hans Peter Freyther | 77cd95d | 2010-11-14 16:19:48 +0100 | [diff] [blame] | 152 | api->assign_fail(conn, GSM0808_CAUSE_NO_RADIO_RESOURCE_AVAILABLE, NULL); |
| 153 | } |
| 154 | |
Harald Welte | 0483f33 | 2017-05-27 14:08:20 +0200 | [diff] [blame] | 155 | /*! \brief Determine and apply AMR multi-rate configuration to lchan |
| 156 | * Determine which AMR multi-rate configuration to use and apply it to |
| 157 | * the lchan (so it can be communicated to BTS and MS during channel |
| 158 | * activation. |
| 159 | * \param[in] conn subscriber connection (used to resolve bsc_api) |
| 160 | * \param[out] lchan logical channel to which to apply mr config |
| 161 | * \param[in] full_rate whether to use full-rate (1) or half-rate (0) config |
Holger Hans Peter Freyther | 594b322 | 2011-08-06 06:42:00 +0200 | [diff] [blame] | 162 | */ |
| 163 | static void handle_mr_config(struct gsm_subscriber_connection *conn, |
Andreas Eversberg | 7326652 | 2014-01-19 11:47:44 +0100 | [diff] [blame] | 164 | struct gsm_lchan *lchan, int full_rate) |
Holger Hans Peter Freyther | 594b322 | 2011-08-06 06:42:00 +0200 | [diff] [blame] | 165 | { |
Holger Hans Peter Freyther | 25aa749 | 2011-08-06 07:00:52 +0200 | [diff] [blame] | 166 | struct bsc_api *api; |
Neels Hofmeyr | a9f2bb5 | 2016-05-09 21:09:47 +0200 | [diff] [blame] | 167 | api = conn->network->bsc_api; |
Andreas Eversberg | 7326652 | 2014-01-19 11:47:44 +0100 | [diff] [blame] | 168 | struct amr_multirate_conf *mr; |
| 169 | struct gsm48_multi_rate_conf *mr_conf; |
Holger Hans Peter Freyther | 25aa749 | 2011-08-06 07:00:52 +0200 | [diff] [blame] | 170 | |
Harald Welte | 0483f33 | 2017-05-27 14:08:20 +0200 | [diff] [blame] | 171 | /* BSC api override for this method, used in OsmoBSC mode with |
| 172 | * bsc_mr_config() to use MSC-specific/specified configuration */ |
Holger Hans Peter Freyther | 25aa749 | 2011-08-06 07:00:52 +0200 | [diff] [blame] | 173 | if (api->mr_config) |
Holger Hans Peter Freyther | 7a77d01 | 2015-09-24 16:26:01 +0200 | [diff] [blame] | 174 | return api->mr_config(conn, lchan, full_rate); |
Holger Hans Peter Freyther | 25aa749 | 2011-08-06 07:00:52 +0200 | [diff] [blame] | 175 | |
Harald Welte | 0483f33 | 2017-05-27 14:08:20 +0200 | [diff] [blame] | 176 | /* NITB case: use the BTS-specic multi-rate configuration from |
| 177 | * the vty/configuration file */ |
Andreas Eversberg | 7326652 | 2014-01-19 11:47:44 +0100 | [diff] [blame] | 178 | if (full_rate) |
| 179 | mr = &lchan->ts->trx->bts->mr_full; |
| 180 | else |
| 181 | mr = &lchan->ts->trx->bts->mr_half; |
| 182 | |
| 183 | mr_conf = (struct gsm48_multi_rate_conf *) mr->gsm48_ie; |
| 184 | mr_conf->ver = 1; |
| 185 | |
| 186 | /* default, if no AMR codec defined */ |
| 187 | if (!mr->gsm48_ie[1]) { |
| 188 | mr_conf->icmi = 1; |
| 189 | mr_conf->m5_90 = 1; |
| 190 | } |
Harald Welte | 0483f33 | 2017-05-27 14:08:20 +0200 | [diff] [blame] | 191 | /* store encoded MR config IE lchan for both MS (uplink) and BTS |
| 192 | * (downlink) directions */ |
Holger Hans Peter Freyther | 615ed46 | 2015-09-24 11:30:58 +0200 | [diff] [blame] | 193 | gsm48_multirate_config(lchan->mr_ms_lv, mr, mr->ms_mode); |
| 194 | gsm48_multirate_config(lchan->mr_bts_lv, mr, mr->bts_mode); |
Holger Hans Peter Freyther | 594b322 | 2011-08-06 06:42:00 +0200 | [diff] [blame] | 195 | } |
| 196 | |
Holger Hans Peter Freyther | 77cd95d | 2010-11-14 16:19:48 +0100 | [diff] [blame] | 197 | /* |
| 198 | * Start a new assignment and make sure that it is completed within T10 either |
| 199 | * positively, negatively or by the timeout. |
| 200 | * |
| 201 | * 1.) allocate a new lchan |
| 202 | * 2.) copy the encryption key and other data from the |
| 203 | * old to the new channel. |
| 204 | * 3.) RSL Channel Activate this channel and wait |
| 205 | * |
| 206 | * -> Signal handler for the LCHAN |
| 207 | * 4.) Send GSM 04.08 assignment command to the MS |
| 208 | * |
| 209 | * -> Assignment Complete/Assignment Failure |
| 210 | * 5.) Release the SDCCH, continue signalling on the new link |
| 211 | */ |
| 212 | static int handle_new_assignment(struct gsm_subscriber_connection *conn, int chan_mode, int full_rate) |
| 213 | { |
| 214 | struct gsm_lchan *new_lchan; |
| 215 | int chan_type; |
| 216 | |
| 217 | chan_type = full_rate ? GSM_LCHAN_TCH_F : GSM_LCHAN_TCH_H; |
| 218 | |
| 219 | new_lchan = lchan_alloc(conn->bts, chan_type, 0); |
| 220 | |
| 221 | if (!new_lchan) { |
| 222 | LOGP(DMSC, LOGL_NOTICE, "No free channel.\n"); |
| 223 | return -1; |
| 224 | } |
| 225 | |
| 226 | /* copy old data to the new channel */ |
| 227 | memcpy(&new_lchan->encr, &conn->lchan->encr, sizeof(new_lchan->encr)); |
| 228 | new_lchan->ms_power = conn->lchan->ms_power; |
| 229 | new_lchan->bs_power = conn->lchan->bs_power; |
Andreas Eversberg | 723a751 | 2013-10-11 12:55:35 +0200 | [diff] [blame] | 230 | new_lchan->rqd_ta = conn->lchan->rqd_ta; |
Holger Hans Peter Freyther | 77cd95d | 2010-11-14 16:19:48 +0100 | [diff] [blame] | 231 | |
| 232 | /* copy new data to it */ |
| 233 | new_lchan->tch_mode = chan_mode; |
| 234 | new_lchan->rsl_cmode = RSL_CMOD_SPD_SPEECH; |
| 235 | |
| 236 | /* handle AMR correctly */ |
Holger Hans Peter Freyther | 594b322 | 2011-08-06 06:42:00 +0200 | [diff] [blame] | 237 | if (chan_mode == GSM48_CMODE_SPEECH_AMR) |
Andreas Eversberg | 7326652 | 2014-01-19 11:47:44 +0100 | [diff] [blame] | 238 | handle_mr_config(conn, new_lchan, full_rate); |
Holger Hans Peter Freyther | 77cd95d | 2010-11-14 16:19:48 +0100 | [diff] [blame] | 239 | |
Andreas Eversberg | 723a751 | 2013-10-11 12:55:35 +0200 | [diff] [blame] | 240 | if (rsl_chan_activate_lchan(new_lchan, 0x1, 0) < 0) { |
Holger Hans Peter Freyther | 77cd95d | 2010-11-14 16:19:48 +0100 | [diff] [blame] | 241 | LOGP(DHO, LOGL_ERROR, "could not activate channel\n"); |
| 242 | lchan_free(new_lchan); |
| 243 | return -1; |
| 244 | } |
| 245 | |
| 246 | /* remember that we have the channel */ |
| 247 | conn->secondary_lchan = new_lchan; |
| 248 | new_lchan->conn = conn; |
| 249 | |
| 250 | rsl_lchan_set_state(new_lchan, LCHAN_S_ACT_REQ); |
| 251 | return 0; |
| 252 | } |
Holger Hans Peter Freyther | b094171 | 2010-11-04 12:06:57 +0100 | [diff] [blame] | 253 | |
Neels Hofmeyr | 42eb014 | 2016-05-20 17:15:44 +0200 | [diff] [blame] | 254 | struct gsm_subscriber_connection *bsc_subscr_con_allocate(struct gsm_lchan *lchan) |
Holger Hans Peter Freyther | a2aedad | 2010-09-16 00:47:32 +0800 | [diff] [blame] | 255 | { |
| 256 | struct gsm_subscriber_connection *conn; |
Neels Hofmeyr | d90fa42 | 2016-05-09 21:03:12 +0200 | [diff] [blame] | 257 | struct gsm_network *net = lchan->ts->trx->bts->network; |
Holger Hans Peter Freyther | a2aedad | 2010-09-16 00:47:32 +0800 | [diff] [blame] | 258 | |
Neels Hofmeyr | d90fa42 | 2016-05-09 21:03:12 +0200 | [diff] [blame] | 259 | conn = talloc_zero(net, struct gsm_subscriber_connection); |
Holger Hans Peter Freyther | a2aedad | 2010-09-16 00:47:32 +0800 | [diff] [blame] | 260 | if (!conn) |
| 261 | return NULL; |
| 262 | |
Neels Hofmeyr | 5e0b0a6 | 2016-05-09 22:33:01 +0200 | [diff] [blame] | 263 | conn->network = net; |
Holger Hans Peter Freyther | a2aedad | 2010-09-16 00:47:32 +0800 | [diff] [blame] | 264 | conn->lchan = lchan; |
| 265 | conn->bts = lchan->ts->trx->bts; |
Neels Hofmeyr | d3270a9 | 2017-02-02 01:07:28 +0100 | [diff] [blame] | 266 | conn->via_ran = RAN_GERAN_A; |
Neels Hofmeyr | ce67be1 | 2017-05-08 15:12:20 +0200 | [diff] [blame] | 267 | conn->lac = conn->bts->location_area_code; |
Holger Hans Peter Freyther | a2aedad | 2010-09-16 00:47:32 +0800 | [diff] [blame] | 268 | lchan->conn = conn; |
Neels Hofmeyr | d90fa42 | 2016-05-09 21:03:12 +0200 | [diff] [blame] | 269 | llist_add_tail(&conn->entry, &net->subscr_conns); |
Holger Hans Peter Freyther | a2aedad | 2010-09-16 00:47:32 +0800 | [diff] [blame] | 270 | return conn; |
| 271 | } |
| 272 | |
Neels Hofmeyr | 42eb014 | 2016-05-20 17:15:44 +0200 | [diff] [blame] | 273 | void bsc_subscr_con_free(struct gsm_subscriber_connection *conn) |
Holger Hans Peter Freyther | a2aedad | 2010-09-16 00:47:32 +0800 | [diff] [blame] | 274 | { |
Holger Hans Peter Freyther | a2aedad | 2010-09-16 00:47:32 +0800 | [diff] [blame] | 275 | if (!conn) |
| 276 | return; |
| 277 | |
Harald Welte | 9066b74 | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 278 | if (conn->network->bsc_api->conn_cleanup) |
| 279 | conn->network->bsc_api->conn_cleanup(conn); |
Holger Hans Peter Freyther | a2aedad | 2010-09-16 00:47:32 +0800 | [diff] [blame] | 280 | |
Harald Welte | 9066b74 | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 281 | if (conn->vsub) { |
| 282 | LOGP(DNM, LOGL_ERROR, "conn->vsub should have been cleared.\n"); |
| 283 | conn->vsub = NULL; |
Holger Hans Peter Freyther | a2aedad | 2010-09-16 00:47:32 +0800 | [diff] [blame] | 284 | } |
| 285 | |
Holger Hans Peter Freyther | a2828fa | 2010-11-14 15:50:42 +0100 | [diff] [blame] | 286 | if (conn->ho_lchan) { |
Holger Hans Peter Freyther | a2aedad | 2010-09-16 00:47:32 +0800 | [diff] [blame] | 287 | LOGP(DNM, LOGL_ERROR, "The ho_lchan should have been cleared.\n"); |
Holger Hans Peter Freyther | a2828fa | 2010-11-14 15:50:42 +0100 | [diff] [blame] | 288 | conn->ho_lchan->conn = NULL; |
| 289 | } |
| 290 | |
| 291 | if (conn->lchan) { |
| 292 | LOGP(DNM, LOGL_ERROR, "The lchan should have been cleared.\n"); |
| 293 | conn->lchan->conn = NULL; |
| 294 | } |
Holger Hans Peter Freyther | a2aedad | 2010-09-16 00:47:32 +0800 | [diff] [blame] | 295 | |
Holger Hans Peter Freyther | 77cd95d | 2010-11-14 16:19:48 +0100 | [diff] [blame] | 296 | if (conn->secondary_lchan) { |
| 297 | LOGP(DNM, LOGL_ERROR, "The secondary_lchan should have been cleared.\n"); |
| 298 | conn->secondary_lchan->conn = NULL; |
| 299 | } |
| 300 | |
Holger Hans Peter Freyther | 79f763f | 2010-09-16 00:53:37 +0800 | [diff] [blame] | 301 | llist_del(&conn->entry); |
Holger Hans Peter Freyther | a2aedad | 2010-09-16 00:47:32 +0800 | [diff] [blame] | 302 | talloc_free(conn); |
Holger Hans Peter Freyther | a2aedad | 2010-09-16 00:47:32 +0800 | [diff] [blame] | 303 | } |
| 304 | |
Holger Hans Peter Freyther | abcddf1 | 2010-06-14 18:20:15 +0800 | [diff] [blame] | 305 | int bsc_api_init(struct gsm_network *network, struct bsc_api *api) |
| 306 | { |
| 307 | network->bsc_api = api; |
| 308 | return 0; |
| 309 | } |
Holger Hans Peter Freyther | ec32b58 | 2010-03-23 07:40:46 +0100 | [diff] [blame] | 310 | |
Harald Welte | b70bd52 | 2011-09-13 00:02:09 +0100 | [diff] [blame] | 311 | /*! \brief process incoming 08.08 DTAP from MSC (send via BTS to MS) */ |
Holger Hans Peter Freyther | ec32b58 | 2010-03-23 07:40:46 +0100 | [diff] [blame] | 312 | int gsm0808_submit_dtap(struct gsm_subscriber_connection *conn, |
Holger Hans Peter Freyther | afa0ad1 | 2012-04-18 18:58:36 +0200 | [diff] [blame] | 313 | struct msgb *msg, int link_id, int allow_sacch) |
Holger Hans Peter Freyther | ec32b58 | 2010-03-23 07:40:46 +0100 | [diff] [blame] | 314 | { |
Holger Hans Peter Freyther | 8ce8d3a | 2010-12-27 10:55:45 +0100 | [diff] [blame] | 315 | uint8_t sapi; |
| 316 | |
| 317 | |
| 318 | if (!conn->lchan) { |
| 319 | LOGP(DMSC, LOGL_ERROR, |
| 320 | "Called submit dtap without an lchan.\n"); |
| 321 | msgb_free(msg); |
| 322 | return -1; |
| 323 | } |
| 324 | |
| 325 | sapi = link_id & 0x7; |
Holger Hans Peter Freyther | ec32b58 | 2010-03-23 07:40:46 +0100 | [diff] [blame] | 326 | msg->lchan = conn->lchan; |
Pablo Neira Ayuso | 7abecfc | 2011-08-17 22:43:54 +0200 | [diff] [blame] | 327 | msg->dst = msg->lchan->ts->trx->rsl_link; |
Holger Hans Peter Freyther | 9c595b7 | 2010-06-15 11:20:52 +0800 | [diff] [blame] | 328 | |
Holger Hans Peter Freyther | 8d380dc | 2010-11-10 10:16:02 +0100 | [diff] [blame] | 329 | /* If we are on a TCH and need to submit a SMS (on SAPI=3) we need to use the SACH */ |
Holger Hans Peter Freyther | afa0ad1 | 2012-04-18 18:58:36 +0200 | [diff] [blame] | 330 | if (allow_sacch && sapi != 0) { |
Holger Hans Peter Freyther | 8d380dc | 2010-11-10 10:16:02 +0100 | [diff] [blame] | 331 | if (conn->lchan->type == GSM_LCHAN_TCH_F || conn->lchan->type == GSM_LCHAN_TCH_H) |
| 332 | link_id |= 0x40; |
| 333 | } |
| 334 | |
Holger Hans Peter Freyther | f6d0e06 | 2010-06-17 17:48:13 +0800 | [diff] [blame] | 335 | msg->l3h = msg->data; |
Harald Welte | b70bd52 | 2011-09-13 00:02:09 +0100 | [diff] [blame] | 336 | /* is requested SAPI already up? */ |
Holger Hans Peter Freyther | 9c595b7 | 2010-06-15 11:20:52 +0800 | [diff] [blame] | 337 | if (conn->lchan->sapis[sapi] == LCHAN_SAPI_UNUSED) { |
Harald Welte | b70bd52 | 2011-09-13 00:02:09 +0100 | [diff] [blame] | 338 | /* Establish L2 for additional SAPI */ |
Holger Hans Peter Freyther | 9c595b7 | 2010-06-15 11:20:52 +0800 | [diff] [blame] | 339 | OBSC_LINKID_CB(msg) = link_id; |
| 340 | if (rll_establish(msg->lchan, sapi, rll_ind_cb, msg) != 0) { |
| 341 | msgb_free(msg); |
| 342 | send_sapi_reject(conn, link_id); |
| 343 | return -1; |
| 344 | } |
| 345 | return 0; |
| 346 | } else { |
Harald Welte | b70bd52 | 2011-09-13 00:02:09 +0100 | [diff] [blame] | 347 | /* Directly forward via RLL/RSL to BTS */ |
Holger Hans Peter Freyther | 9c595b7 | 2010-06-15 11:20:52 +0800 | [diff] [blame] | 348 | return rsl_data_request(msg, link_id); |
| 349 | } |
Holger Hans Peter Freyther | ec32b58 | 2010-03-23 07:40:46 +0100 | [diff] [blame] | 350 | } |
Holger Hans Peter Freyther | 2a9285c | 2010-06-14 18:03:06 +0800 | [diff] [blame] | 351 | |
Holger Hans Peter Freyther | a5dcdd9 | 2012-04-07 13:25:47 +0200 | [diff] [blame] | 352 | /* |
| 353 | * \brief Check if the given channel is compatible with the mode/fullrate |
Holger Hans Peter Freyther | a5dcdd9 | 2012-04-07 13:25:47 +0200 | [diff] [blame] | 354 | */ |
| 355 | static int chan_compat_with_mode(struct gsm_lchan *lchan, int chan_mode, int full_rate) |
| 356 | { |
Harald Welte | bb53e35 | 2012-08-24 15:21:35 +0200 | [diff] [blame] | 357 | switch (chan_mode) { |
| 358 | case GSM48_CMODE_SIGN: |
| 359 | /* signalling is always possible */ |
| 360 | return 1; |
| 361 | case GSM48_CMODE_SPEECH_V1: |
| 362 | case GSM48_CMODE_SPEECH_AMR: |
| 363 | case GSM48_CMODE_DATA_3k6: |
| 364 | case GSM48_CMODE_DATA_6k0: |
| 365 | /* these services can all run on TCH/H, but we may have |
| 366 | * an explicit override by the 'full_rate' argument */ |
| 367 | switch (lchan->type) { |
| 368 | case GSM_LCHAN_TCH_F: |
| 369 | return 1; |
| 370 | case GSM_LCHAN_TCH_H: |
| 371 | if (full_rate) |
| 372 | return 0; |
| 373 | else |
| 374 | return 1; |
| 375 | break; |
| 376 | default: |
| 377 | return 0; |
| 378 | } |
| 379 | break; |
| 380 | case GSM48_CMODE_DATA_12k0: |
| 381 | case GSM48_CMODE_DATA_14k5: |
| 382 | case GSM48_CMODE_SPEECH_EFR: |
| 383 | /* these services all explicitly require a TCH/F */ |
| 384 | if (lchan->type == GSM_LCHAN_TCH_F) |
| 385 | return 1; |
| 386 | else |
| 387 | return 0; |
| 388 | break; |
| 389 | } |
Holger Hans Peter Freyther | a5dcdd9 | 2012-04-07 13:25:47 +0200 | [diff] [blame] | 390 | |
Harald Welte | bb53e35 | 2012-08-24 15:21:35 +0200 | [diff] [blame] | 391 | return 0; |
Holger Hans Peter Freyther | a5dcdd9 | 2012-04-07 13:25:47 +0200 | [diff] [blame] | 392 | } |
| 393 | |
Holger Hans Peter Freyther | c354de8 | 2010-07-23 16:49:38 +0800 | [diff] [blame] | 394 | /** |
| 395 | * Send a GSM08.08 Assignment Request. Right now this does not contain the |
Holger Hans Peter Freyther | 088dde8 | 2010-11-10 11:07:12 +0100 | [diff] [blame] | 396 | * audio codec type or the allowed rates for the config. It is assumed that |
Holger Hans Peter Freyther | a5dcdd9 | 2012-04-07 13:25:47 +0200 | [diff] [blame] | 397 | * this is for audio handling only. In case the current channel does not allow |
| 398 | * the selected mode a new one will be allocated. |
| 399 | * |
| 400 | * TODO: Add multirate configuration, make it work for more than audio. |
Holger Hans Peter Freyther | c354de8 | 2010-07-23 16:49:38 +0800 | [diff] [blame] | 401 | */ |
Holger Hans Peter Freyther | 2603c1f | 2010-11-10 10:01:20 +0100 | [diff] [blame] | 402 | int gsm0808_assign_req(struct gsm_subscriber_connection *conn, int chan_mode, int full_rate) |
Holger Hans Peter Freyther | c354de8 | 2010-07-23 16:49:38 +0800 | [diff] [blame] | 403 | { |
| 404 | struct bsc_api *api; |
Neels Hofmeyr | a9f2bb5 | 2016-05-09 21:09:47 +0200 | [diff] [blame] | 405 | api = conn->network->bsc_api; |
Holger Hans Peter Freyther | c354de8 | 2010-07-23 16:49:38 +0800 | [diff] [blame] | 406 | |
Harald Welte | 9fc70f3 | 2012-08-24 15:08:23 +0200 | [diff] [blame] | 407 | if (!chan_compat_with_mode(conn->lchan, chan_mode, full_rate)) { |
Holger Hans Peter Freyther | 77cd95d | 2010-11-14 16:19:48 +0100 | [diff] [blame] | 408 | if (handle_new_assignment(conn, chan_mode, full_rate) != 0) |
| 409 | goto error; |
Holger Hans Peter Freyther | 088dde8 | 2010-11-10 11:07:12 +0100 | [diff] [blame] | 410 | } else { |
Holger Hans Peter Freyther | 594b322 | 2011-08-06 06:42:00 +0200 | [diff] [blame] | 411 | if (chan_mode == GSM48_CMODE_SPEECH_AMR) |
Andreas Eversberg | 7326652 | 2014-01-19 11:47:44 +0100 | [diff] [blame] | 412 | handle_mr_config(conn, conn->lchan, full_rate); |
Holger Hans Peter Freyther | 088dde8 | 2010-11-10 11:07:12 +0100 | [diff] [blame] | 413 | |
Max | 8db12e4 | 2016-04-18 23:11:18 +0200 | [diff] [blame] | 414 | LOGP(DMSC, LOGL_NOTICE, |
Max | 8dc8f23 | 2017-02-09 19:13:02 +0100 | [diff] [blame] | 415 | "Sending %s ChanModify for speech: %s on channel %s\n", |
| 416 | gsm_lchan_name(conn->lchan), |
Max | 8db12e4 | 2016-04-18 23:11:18 +0200 | [diff] [blame] | 417 | get_value_string(gsm48_chan_mode_names, chan_mode), |
| 418 | get_value_string(gsm_chan_t_names, conn->lchan->type)); |
Holger Hans Peter Freyther | 77cd95d | 2010-11-14 16:19:48 +0100 | [diff] [blame] | 419 | gsm48_lchan_modify(conn->lchan, chan_mode); |
Holger Hans Peter Freyther | 088dde8 | 2010-11-10 11:07:12 +0100 | [diff] [blame] | 420 | } |
| 421 | |
Holger Hans Peter Freyther | 77cd95d | 2010-11-14 16:19:48 +0100 | [diff] [blame] | 422 | /* we will now start the timer to complete the assignment */ |
Pablo Neira Ayuso | 5121576 | 2017-05-08 20:57:52 +0200 | [diff] [blame] | 423 | osmo_timer_setup(&conn->T10, assignment_t10_timeout, conn); |
Pablo Neira Ayuso | bf540cb | 2011-05-06 12:11:06 +0200 | [diff] [blame] | 424 | osmo_timer_schedule(&conn->T10, GSM0808_T10_VALUE); |
Holger Hans Peter Freyther | c354de8 | 2010-07-23 16:49:38 +0800 | [diff] [blame] | 425 | return 0; |
Holger Hans Peter Freyther | 77cd95d | 2010-11-14 16:19:48 +0100 | [diff] [blame] | 426 | |
| 427 | error: |
| 428 | api->assign_fail(conn, 0, NULL); |
| 429 | return -1; |
Holger Hans Peter Freyther | c354de8 | 2010-07-23 16:49:38 +0800 | [diff] [blame] | 430 | } |
| 431 | |
Holger Hans Peter Freyther | 7700846 | 2010-06-16 14:10:45 +0800 | [diff] [blame] | 432 | int gsm0808_page(struct gsm_bts *bts, unsigned int page_group, unsigned int mi_len, |
| 433 | uint8_t *mi, int chan_type) |
| 434 | { |
Harald Welte | baaf3e2 | 2016-11-17 20:54:04 +0100 | [diff] [blame] | 435 | return rsl_paging_cmd(bts, page_group, mi_len, mi, chan_type, false); |
Holger Hans Peter Freyther | 7700846 | 2010-06-16 14:10:45 +0800 | [diff] [blame] | 436 | } |
| 437 | |
Holger Hans Peter Freyther | 77cd95d | 2010-11-14 16:19:48 +0100 | [diff] [blame] | 438 | static void handle_ass_compl(struct gsm_subscriber_connection *conn, |
| 439 | struct msgb *msg) |
| 440 | { |
| 441 | struct gsm48_hdr *gh; |
Neels Hofmeyr | a9f2bb5 | 2016-05-09 21:09:47 +0200 | [diff] [blame] | 442 | struct bsc_api *api = conn->network->bsc_api; |
Holger Hans Peter Freyther | 77cd95d | 2010-11-14 16:19:48 +0100 | [diff] [blame] | 443 | |
| 444 | if (conn->secondary_lchan != msg->lchan) { |
| 445 | LOGP(DMSC, LOGL_ERROR, "Assignment Compl should occur on second lchan.\n"); |
| 446 | return; |
| 447 | } |
| 448 | |
| 449 | gh = msgb_l3(msg); |
| 450 | if (msgb_l3len(msg) - sizeof(*gh) != 1) { |
Harald Welte | 7b1d25a | 2015-01-01 12:32:03 +0100 | [diff] [blame] | 451 | LOGP(DMSC, LOGL_ERROR, "Assignment Compl invalid: %zu\n", |
Holger Hans Peter Freyther | 77cd95d | 2010-11-14 16:19:48 +0100 | [diff] [blame] | 452 | msgb_l3len(msg) - sizeof(*gh)); |
| 453 | return; |
| 454 | } |
| 455 | |
Andreas Eversberg | dcf38e1 | 2013-12-05 14:37:11 +0100 | [diff] [blame] | 456 | /* switch TRAU muxer for E1 based BTS from one channel to another */ |
| 457 | if (is_e1_bts(conn->bts)) |
| 458 | switch_trau_mux(conn->lchan, conn->secondary_lchan); |
| 459 | |
Holger Hans Peter Freyther | 77cd95d | 2010-11-14 16:19:48 +0100 | [diff] [blame] | 460 | /* swap channels */ |
Pablo Neira Ayuso | bf540cb | 2011-05-06 12:11:06 +0200 | [diff] [blame] | 461 | osmo_timer_del(&conn->T10); |
Holger Hans Peter Freyther | 77cd95d | 2010-11-14 16:19:48 +0100 | [diff] [blame] | 462 | |
Holger Hans Peter Freyther | d66777f | 2012-12-06 12:20:56 +0100 | [diff] [blame] | 463 | lchan_release(conn->lchan, 0, RSL_REL_LOCAL_END); |
Holger Hans Peter Freyther | 77cd95d | 2010-11-14 16:19:48 +0100 | [diff] [blame] | 464 | conn->lchan = conn->secondary_lchan; |
| 465 | conn->secondary_lchan = NULL; |
| 466 | |
| 467 | if (is_ipaccess_bts(conn->bts) && conn->lchan->tch_mode != GSM48_CMODE_SIGN) |
| 468 | rsl_ipacc_crcx(conn->lchan); |
| 469 | |
Holger Hans Peter Freyther | 40aac3f | 2011-12-27 12:31:02 +0100 | [diff] [blame] | 470 | api->assign_compl(conn, gh->data[0], |
Holger Hans Peter Freyther | 77cd95d | 2010-11-14 16:19:48 +0100 | [diff] [blame] | 471 | lchan_to_chosen_channel(conn->lchan), |
| 472 | conn->lchan->encr.alg_id, |
| 473 | chan_mode_to_speech(conn->lchan)); |
| 474 | } |
| 475 | |
| 476 | static void handle_ass_fail(struct gsm_subscriber_connection *conn, |
| 477 | struct msgb *msg) |
| 478 | { |
Neels Hofmeyr | a9f2bb5 | 2016-05-09 21:09:47 +0200 | [diff] [blame] | 479 | struct bsc_api *api = conn->network->bsc_api; |
Holger Hans Peter Freyther | 77cd95d | 2010-11-14 16:19:48 +0100 | [diff] [blame] | 480 | uint8_t *rr_failure; |
| 481 | struct gsm48_hdr *gh; |
| 482 | |
| 483 | |
| 484 | if (conn->lchan != msg->lchan) { |
| 485 | LOGP(DMSC, LOGL_ERROR, "Assignment failure should occur on primary lchan.\n"); |
| 486 | return; |
| 487 | } |
| 488 | |
| 489 | /* stop the timer and release it */ |
Pablo Neira Ayuso | bf540cb | 2011-05-06 12:11:06 +0200 | [diff] [blame] | 490 | osmo_timer_del(&conn->T10); |
Holger Hans Peter Freyther | d66777f | 2012-12-06 12:20:56 +0100 | [diff] [blame] | 491 | lchan_release(conn->secondary_lchan, 0, RSL_REL_LOCAL_END); |
Holger Hans Peter Freyther | 77cd95d | 2010-11-14 16:19:48 +0100 | [diff] [blame] | 492 | conn->secondary_lchan = NULL; |
| 493 | |
| 494 | gh = msgb_l3(msg); |
| 495 | if (msgb_l3len(msg) - sizeof(*gh) != 1) { |
Ruben Undheim | 59d57da | 2016-12-20 17:38:31 +0100 | [diff] [blame] | 496 | LOGP(DMSC, LOGL_ERROR, "assignment failure unhandled: %zu\n", |
Holger Hans Peter Freyther | 77cd95d | 2010-11-14 16:19:48 +0100 | [diff] [blame] | 497 | msgb_l3len(msg) - sizeof(*gh)); |
| 498 | rr_failure = NULL; |
| 499 | } else { |
| 500 | rr_failure = &gh->data[0]; |
| 501 | } |
| 502 | |
| 503 | api->assign_fail(conn, |
| 504 | GSM0808_CAUSE_RADIO_INTERFACE_MESSAGE_FAILURE, |
| 505 | rr_failure); |
| 506 | } |
| 507 | |
Harald Welte | 95e862c | 2012-01-23 10:28:35 +0100 | [diff] [blame] | 508 | static void handle_classmark_chg(struct gsm_subscriber_connection *conn, |
| 509 | struct msgb *msg) |
| 510 | { |
| 511 | struct bsc_api *api = msg->lchan->ts->trx->bts->network->bsc_api; |
| 512 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 513 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 514 | uint8_t cm2_len, cm3_len = 0; |
| 515 | uint8_t *cm2, *cm3 = NULL; |
| 516 | |
| 517 | DEBUGP(DRR, "CLASSMARK CHANGE "); |
| 518 | |
| 519 | /* classmark 2 */ |
| 520 | cm2_len = gh->data[0]; |
| 521 | cm2 = &gh->data[1]; |
| 522 | DEBUGPC(DRR, "CM2(len=%u) ", cm2_len); |
| 523 | |
| 524 | if (payload_len > cm2_len + 1) { |
| 525 | /* we must have a classmark3 */ |
| 526 | if (gh->data[cm2_len+1] != 0x20) { |
| 527 | DEBUGPC(DRR, "ERR CM3 TAG\n"); |
Harald Welte | cf149ee | 2012-01-23 16:40:24 +0100 | [diff] [blame] | 528 | return; |
Harald Welte | 95e862c | 2012-01-23 10:28:35 +0100 | [diff] [blame] | 529 | } |
| 530 | if (cm2_len > 3) { |
| 531 | DEBUGPC(DRR, "CM2 too long!\n"); |
Harald Welte | cf149ee | 2012-01-23 16:40:24 +0100 | [diff] [blame] | 532 | return; |
Harald Welte | 95e862c | 2012-01-23 10:28:35 +0100 | [diff] [blame] | 533 | } |
| 534 | |
| 535 | cm3_len = gh->data[cm2_len+2]; |
| 536 | cm3 = &gh->data[cm2_len+3]; |
| 537 | if (cm3_len > 14) { |
| 538 | DEBUGPC(DRR, "CM3 len %u too long!\n", cm3_len); |
Harald Welte | cf149ee | 2012-01-23 16:40:24 +0100 | [diff] [blame] | 539 | return; |
Harald Welte | 95e862c | 2012-01-23 10:28:35 +0100 | [diff] [blame] | 540 | } |
| 541 | DEBUGPC(DRR, "CM3(len=%u)\n", cm3_len); |
| 542 | } |
| 543 | api->classmark_chg(conn, cm2, cm2_len, cm3, cm3_len); |
| 544 | } |
| 545 | |
Harald Welte | cf149ee | 2012-01-23 16:40:24 +0100 | [diff] [blame] | 546 | /* Chapter 9.1.16 Handover complete */ |
| 547 | static void handle_rr_ho_compl(struct msgb *msg) |
| 548 | { |
| 549 | struct lchan_signal_data sig; |
| 550 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 551 | |
| 552 | DEBUGP(DRR, "HANDOVER COMPLETE cause = %s\n", |
| 553 | rr_cause_name(gh->data[0])); |
| 554 | |
| 555 | sig.lchan = msg->lchan; |
| 556 | sig.mr = NULL; |
| 557 | osmo_signal_dispatch(SS_LCHAN, S_LCHAN_HANDOVER_COMPL, &sig); |
| 558 | /* FIXME: release old channel */ |
| 559 | } |
| 560 | |
| 561 | /* Chapter 9.1.17 Handover Failure */ |
| 562 | static void handle_rr_ho_fail(struct msgb *msg) |
| 563 | { |
| 564 | struct lchan_signal_data sig; |
| 565 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 566 | |
| 567 | DEBUGP(DRR, "HANDOVER FAILED cause = %s\n", |
| 568 | rr_cause_name(gh->data[0])); |
| 569 | |
| 570 | sig.lchan = msg->lchan; |
| 571 | sig.mr = NULL; |
| 572 | osmo_signal_dispatch(SS_LCHAN, S_LCHAN_HANDOVER_FAIL, &sig); |
| 573 | /* FIXME: release allocated new channel */ |
| 574 | } |
| 575 | |
| 576 | |
Holger Hans Peter Freyther | 46caa30 | 2010-11-04 12:18:00 +0100 | [diff] [blame] | 577 | static void dispatch_dtap(struct gsm_subscriber_connection *conn, |
| 578 | uint8_t link_id, struct msgb *msg) |
Holger Hans Peter Freyther | 6c199e7 | 2010-11-04 11:18:03 +0100 | [diff] [blame] | 579 | { |
| 580 | struct bsc_api *api = msg->lchan->ts->trx->bts->network->bsc_api; |
| 581 | struct gsm48_hdr *gh; |
| 582 | uint8_t pdisc; |
Neels Hofmeyr | 531734a | 2016-03-14 16:13:24 +0100 | [diff] [blame] | 583 | uint8_t msg_type; |
Holger Hans Peter Freyther | 6c199e7 | 2010-11-04 11:18:03 +0100 | [diff] [blame] | 584 | int rc; |
| 585 | |
| 586 | if (msgb_l3len(msg) < sizeof(*gh)) { |
| 587 | LOGP(DMSC, LOGL_ERROR, "Message too short for a GSM48 header.\n"); |
| 588 | return; |
| 589 | } |
| 590 | |
| 591 | gh = msgb_l3(msg); |
Neels Hofmeyr | 531734a | 2016-03-14 16:13:24 +0100 | [diff] [blame] | 592 | pdisc = gsm48_hdr_pdisc(gh); |
| 593 | msg_type = gsm48_hdr_msg_type(gh); |
Harald Welte | cf149ee | 2012-01-23 16:40:24 +0100 | [diff] [blame] | 594 | |
| 595 | /* the idea is to handle all RR messages here, and only hand |
| 596 | * MM/CC/SMS-CP/LCS up to the MSC. Some messages like PAGING |
| 597 | * RESPONSE or CM SERVICE REQUEST will not be covered here, as |
| 598 | * they are only possible in the first L3 message of each L2 |
| 599 | * channel, i.e. 'conn' will not exist and gsm0408_rcvmsg() |
| 600 | * will call api->compl_l3() for it */ |
Holger Hans Peter Freyther | 6c199e7 | 2010-11-04 11:18:03 +0100 | [diff] [blame] | 601 | switch (pdisc) { |
| 602 | case GSM48_PDISC_RR: |
Neels Hofmeyr | 531734a | 2016-03-14 16:13:24 +0100 | [diff] [blame] | 603 | switch (msg_type) { |
Harald Welte | cf149ee | 2012-01-23 16:40:24 +0100 | [diff] [blame] | 604 | case GSM48_MT_RR_GPRS_SUSP_REQ: |
Philipp | d37981e | 2016-10-10 15:11:41 +0200 | [diff] [blame] | 605 | DEBUGP(DRR, "%s\n", |
| 606 | gsm48_rr_msg_name(GSM48_MT_RR_GPRS_SUSP_REQ)); |
Harald Welte | cf149ee | 2012-01-23 16:40:24 +0100 | [diff] [blame] | 607 | break; |
| 608 | case GSM48_MT_RR_STATUS: |
Philipp | d37981e | 2016-10-10 15:11:41 +0200 | [diff] [blame] | 609 | LOGP(DRR, LOGL_NOTICE, "%s (cause: %s)\n", |
Harald Welte | 0db2f69 | 2017-07-11 00:38:30 +0200 | [diff] [blame^] | 610 | gsm48_rr_msg_name(GSM48_MT_RR_STATUS), |
Philipp | d37981e | 2016-10-10 15:11:41 +0200 | [diff] [blame] | 611 | rr_cause_name(gh->data[0])); |
Harald Welte | cf149ee | 2012-01-23 16:40:24 +0100 | [diff] [blame] | 612 | break; |
| 613 | case GSM48_MT_RR_MEAS_REP: |
| 614 | /* This shouldn't actually end up here, as RSL treats |
| 615 | * L3 Info of 08.58 MEASUREMENT REPORT different by calling |
| 616 | * directly into gsm48_parse_meas_rep */ |
Harald Welte | 6e8dcf3 | 2012-04-26 19:35:58 +0200 | [diff] [blame] | 617 | LOGP(DMEAS, LOGL_ERROR, "DIRECT GSM48 MEASUREMENT REPORT ?!? "); |
Harald Welte | cf149ee | 2012-01-23 16:40:24 +0100 | [diff] [blame] | 618 | break; |
| 619 | case GSM48_MT_RR_HANDO_COMPL: |
| 620 | handle_rr_ho_compl(msg); |
| 621 | break; |
| 622 | case GSM48_MT_RR_HANDO_FAIL: |
| 623 | handle_rr_ho_fail(msg); |
| 624 | break; |
Holger Hans Peter Freyther | 6c199e7 | 2010-11-04 11:18:03 +0100 | [diff] [blame] | 625 | case GSM48_MT_RR_CIPH_M_COMPL: |
| 626 | if (api->cipher_mode_compl) |
Harald Welte | cf149ee | 2012-01-23 16:40:24 +0100 | [diff] [blame] | 627 | api->cipher_mode_compl(conn, msg, |
Holger Hans Peter Freyther | 6c199e7 | 2010-11-04 11:18:03 +0100 | [diff] [blame] | 628 | conn->lchan->encr.alg_id); |
| 629 | break; |
| 630 | case GSM48_MT_RR_ASS_COMPL: |
Holger Hans Peter Freyther | 77cd95d | 2010-11-14 16:19:48 +0100 | [diff] [blame] | 631 | handle_ass_compl(conn, msg); |
Holger Hans Peter Freyther | 6c199e7 | 2010-11-04 11:18:03 +0100 | [diff] [blame] | 632 | break; |
| 633 | case GSM48_MT_RR_ASS_FAIL: |
Holger Hans Peter Freyther | 77cd95d | 2010-11-14 16:19:48 +0100 | [diff] [blame] | 634 | handle_ass_fail(conn, msg); |
Holger Hans Peter Freyther | 6c199e7 | 2010-11-04 11:18:03 +0100 | [diff] [blame] | 635 | break; |
| 636 | case GSM48_MT_RR_CHAN_MODE_MODIF_ACK: |
Pablo Neira Ayuso | bf540cb | 2011-05-06 12:11:06 +0200 | [diff] [blame] | 637 | osmo_timer_del(&conn->T10); |
Holger Hans Peter Freyther | 6c199e7 | 2010-11-04 11:18:03 +0100 | [diff] [blame] | 638 | rc = gsm48_rx_rr_modif_ack(msg); |
Holger Hans Peter Freyther | 40aac3f | 2011-12-27 12:31:02 +0100 | [diff] [blame] | 639 | if (rc < 0) { |
Holger Hans Peter Freyther | 6c199e7 | 2010-11-04 11:18:03 +0100 | [diff] [blame] | 640 | api->assign_fail(conn, |
Holger Hans Peter Freyther | 45b575f | 2010-11-05 10:37:17 +0100 | [diff] [blame] | 641 | GSM0808_CAUSE_NO_RADIO_RESOURCE_AVAILABLE, |
| 642 | NULL); |
Holger Hans Peter Freyther | 40aac3f | 2011-12-27 12:31:02 +0100 | [diff] [blame] | 643 | } else if (rc >= 0) { |
Holger Hans Peter Freyther | b094171 | 2010-11-04 12:06:57 +0100 | [diff] [blame] | 644 | api->assign_compl(conn, 0, |
| 645 | lchan_to_chosen_channel(conn->lchan), |
| 646 | conn->lchan->encr.alg_id, |
| 647 | chan_mode_to_speech(conn->lchan)); |
Holger Hans Peter Freyther | 40aac3f | 2011-12-27 12:31:02 +0100 | [diff] [blame] | 648 | } |
Holger Hans Peter Freyther | 6c199e7 | 2010-11-04 11:18:03 +0100 | [diff] [blame] | 649 | break; |
Harald Welte | 95e862c | 2012-01-23 10:28:35 +0100 | [diff] [blame] | 650 | case GSM48_MT_RR_CLSM_CHG: |
| 651 | handle_classmark_chg(conn, msg); |
Harald Welte | 95e862c | 2012-01-23 10:28:35 +0100 | [diff] [blame] | 652 | break; |
Harald Welte | ae1d010 | 2012-07-16 13:20:53 +0200 | [diff] [blame] | 653 | case GSM48_MT_RR_APP_INFO: |
| 654 | /* Passing RR APP INFO to MSC, not quite |
| 655 | * according to spec */ |
| 656 | if (api->dtap) |
| 657 | api->dtap(conn, link_id, msg); |
| 658 | break; |
Harald Welte | cf149ee | 2012-01-23 16:40:24 +0100 | [diff] [blame] | 659 | default: |
| 660 | /* Normally, a MSC should never receive RR |
| 661 | * messages, but we'd rather forward what we |
| 662 | * don't know than drop it... */ |
Philipp | d37981e | 2016-10-10 15:11:41 +0200 | [diff] [blame] | 663 | LOGP(DRR, LOGL_NOTICE, |
| 664 | "BSC: Passing %s 04.08 RR message to MSC\n", |
| 665 | gsm48_rr_msg_name(msg_type)); |
Harald Welte | cf149ee | 2012-01-23 16:40:24 +0100 | [diff] [blame] | 666 | if (api->dtap) |
| 667 | api->dtap(conn, link_id, msg); |
Holger Hans Peter Freyther | 6c199e7 | 2010-11-04 11:18:03 +0100 | [diff] [blame] | 668 | } |
| 669 | break; |
Harald Welte | cf149ee | 2012-01-23 16:40:24 +0100 | [diff] [blame] | 670 | default: |
| 671 | if (api->dtap) |
| 672 | api->dtap(conn, link_id, msg); |
Holger Hans Peter Freyther | 6c199e7 | 2010-11-04 11:18:03 +0100 | [diff] [blame] | 673 | break; |
| 674 | } |
Holger Hans Peter Freyther | 6c199e7 | 2010-11-04 11:18:03 +0100 | [diff] [blame] | 675 | } |
| 676 | |
Harald Welte | b70bd52 | 2011-09-13 00:02:09 +0100 | [diff] [blame] | 677 | /*! \brief RSL has received a DATA INDICATION with L3 from MS */ |
Holger Hans Peter Freyther | 9764331 | 2010-06-17 16:41:25 +0800 | [diff] [blame] | 678 | int gsm0408_rcvmsg(struct msgb *msg, uint8_t link_id) |
| 679 | { |
| 680 | int rc; |
Holger Hans Peter Freyther | 9764331 | 2010-06-17 16:41:25 +0800 | [diff] [blame] | 681 | struct bsc_api *api = msg->lchan->ts->trx->bts->network->bsc_api; |
Holger Hans Peter Freyther | 2412a07 | 2010-06-28 15:47:12 +0800 | [diff] [blame] | 682 | struct gsm_lchan *lchan; |
Holger Hans Peter Freyther | 9764331 | 2010-06-17 16:41:25 +0800 | [diff] [blame] | 683 | |
Holger Hans Peter Freyther | 2412a07 | 2010-06-28 15:47:12 +0800 | [diff] [blame] | 684 | lchan = msg->lchan; |
Holger Hans Peter Freyther | 49ab278 | 2010-07-05 11:38:37 +0800 | [diff] [blame] | 685 | if (lchan->state != LCHAN_S_ACTIVE) { |
Harald Welte | 2cafc4b | 2010-12-24 13:06:11 +0100 | [diff] [blame] | 686 | LOGP(DRSL, LOGL_INFO, "Got data in non active state(%s), " |
| 687 | "discarding.\n", gsm_lchans_name(lchan->state)); |
Holger Hans Peter Freyther | 49ab278 | 2010-07-05 11:38:37 +0800 | [diff] [blame] | 688 | return -1; |
| 689 | } |
| 690 | |
| 691 | |
Holger Hans Peter Freyther | 2412a07 | 2010-06-28 15:47:12 +0800 | [diff] [blame] | 692 | if (lchan->conn) { |
Harald Welte | b70bd52 | 2011-09-13 00:02:09 +0100 | [diff] [blame] | 693 | /* if we already have a connection, forward via DTAP to |
| 694 | * MSC */ |
Holger Hans Peter Freyther | 46caa30 | 2010-11-04 12:18:00 +0100 | [diff] [blame] | 695 | dispatch_dtap(lchan->conn, link_id, msg); |
Holger Hans Peter Freyther | 9764331 | 2010-06-17 16:41:25 +0800 | [diff] [blame] | 696 | } else { |
Harald Welte | b70bd52 | 2011-09-13 00:02:09 +0100 | [diff] [blame] | 697 | /* allocate a new connection */ |
Holger Hans Peter Freyther | 2412a07 | 2010-06-28 15:47:12 +0800 | [diff] [blame] | 698 | rc = BSC_API_CONN_POL_REJECT; |
Neels Hofmeyr | 42eb014 | 2016-05-20 17:15:44 +0200 | [diff] [blame] | 699 | lchan->conn = bsc_subscr_con_allocate(msg->lchan); |
Holger Hans Peter Freyther | 05bbec7 | 2011-01-16 18:15:26 +0100 | [diff] [blame] | 700 | if (!lchan->conn) { |
Holger Hans Peter Freyther | d66777f | 2012-12-06 12:20:56 +0100 | [diff] [blame] | 701 | lchan_release(lchan, 1, RSL_REL_NORMAL); |
Holger Hans Peter Freyther | 05bbec7 | 2011-01-16 18:15:26 +0100 | [diff] [blame] | 702 | return -1; |
| 703 | } |
Holger Hans Peter Freyther | 2412a07 | 2010-06-28 15:47:12 +0800 | [diff] [blame] | 704 | |
Harald Welte | b70bd52 | 2011-09-13 00:02:09 +0100 | [diff] [blame] | 705 | /* fwd via bsc_api to send COMPLETE L3 INFO to MSC */ |
Holger Hans Peter Freyther | 05bbec7 | 2011-01-16 18:15:26 +0100 | [diff] [blame] | 706 | rc = api->compl_l3(lchan->conn, msg, 0); |
Holger Hans Peter Freyther | 2412a07 | 2010-06-28 15:47:12 +0800 | [diff] [blame] | 707 | |
| 708 | if (rc != BSC_API_CONN_POL_ACCEPT) { |
Holger Hans Peter Freyther | 8d216c7 | 2010-11-15 10:33:59 +0100 | [diff] [blame] | 709 | lchan->conn->lchan = NULL; |
Neels Hofmeyr | 42eb014 | 2016-05-20 17:15:44 +0200 | [diff] [blame] | 710 | bsc_subscr_con_free(lchan->conn); |
Holger Hans Peter Freyther | d66777f | 2012-12-06 12:20:56 +0100 | [diff] [blame] | 711 | lchan_release(lchan, 1, RSL_REL_NORMAL); |
Holger Hans Peter Freyther | 2412a07 | 2010-06-28 15:47:12 +0800 | [diff] [blame] | 712 | } |
Holger Hans Peter Freyther | 9764331 | 2010-06-17 16:41:25 +0800 | [diff] [blame] | 713 | } |
| 714 | |
| 715 | return 0; |
| 716 | } |
| 717 | |
Harald Welte | b70bd52 | 2011-09-13 00:02:09 +0100 | [diff] [blame] | 718 | /*! \brief We received a GSM 08.08 CIPHER MODE from the MSC */ |
Holger Hans Peter Freyther | dbc62db | 2010-07-23 16:55:24 +0800 | [diff] [blame] | 719 | int gsm0808_cipher_mode(struct gsm_subscriber_connection *conn, int cipher, |
Holger Hans Peter Freyther | 2f169d6 | 2010-11-10 09:42:50 +0100 | [diff] [blame] | 720 | const uint8_t *key, int len, int include_imeisv) |
Holger Hans Peter Freyther | dbc62db | 2010-07-23 16:55:24 +0800 | [diff] [blame] | 721 | { |
Holger Hans Peter Freyther | 4be7d41 | 2010-11-10 10:25:34 +0100 | [diff] [blame] | 722 | if (cipher > 0 && key == NULL) { |
| 723 | LOGP(DRSL, LOGL_ERROR, "Need to have an encrytpion key.\n"); |
| 724 | return -1; |
| 725 | } |
| 726 | |
| 727 | if (len > MAX_A5_KEY_LEN) { |
| 728 | LOGP(DRSL, LOGL_ERROR, "The key is too long: %d\n", len); |
| 729 | return -1; |
| 730 | } |
| 731 | |
| 732 | conn->lchan->encr.alg_id = RSL_ENC_ALG_A5(cipher); |
| 733 | if (key) { |
| 734 | conn->lchan->encr.key_len = len; |
| 735 | memcpy(conn->lchan->encr.key, key, len); |
| 736 | } |
| 737 | |
| 738 | return gsm48_send_rr_ciph_mode(conn->lchan, include_imeisv); |
Holger Hans Peter Freyther | dbc62db | 2010-07-23 16:55:24 +0800 | [diff] [blame] | 739 | } |
| 740 | |
Holger Hans Peter Freyther | aaa40b8 | 2010-09-16 20:48:15 +0800 | [diff] [blame] | 741 | /* |
| 742 | * Release all occupied RF Channels but stay around for more. |
| 743 | */ |
Holger Hans Peter Freyther | adb6e1c | 2010-09-18 06:44:24 +0800 | [diff] [blame] | 744 | int gsm0808_clear(struct gsm_subscriber_connection *conn) |
Holger Hans Peter Freyther | 4049455 | 2010-06-28 17:09:29 +0800 | [diff] [blame] | 745 | { |
Holger Hans Peter Freyther | 1f69b46 | 2010-09-16 22:49:37 +0800 | [diff] [blame] | 746 | if (conn->ho_lchan) |
Holger Hans Peter Freyther | ebd50a6 | 2010-12-27 13:46:48 +0100 | [diff] [blame] | 747 | bsc_clear_handover(conn, 1); |
Holger Hans Peter Freyther | d065165 | 2010-06-30 12:17:35 +0800 | [diff] [blame] | 748 | |
Holger Hans Peter Freyther | 77cd95d | 2010-11-14 16:19:48 +0100 | [diff] [blame] | 749 | if (conn->secondary_lchan) |
Holger Hans Peter Freyther | d66777f | 2012-12-06 12:20:56 +0100 | [diff] [blame] | 750 | lchan_release(conn->secondary_lchan, 0, RSL_REL_LOCAL_END); |
Holger Hans Peter Freyther | 77cd95d | 2010-11-14 16:19:48 +0100 | [diff] [blame] | 751 | |
Holger Hans Peter Freyther | abf962b | 2010-11-14 16:04:46 +0100 | [diff] [blame] | 752 | if (conn->lchan) |
Holger Hans Peter Freyther | d66777f | 2012-12-06 12:20:56 +0100 | [diff] [blame] | 753 | lchan_release(conn->lchan, 1, RSL_REL_NORMAL); |
Holger Hans Peter Freyther | 1f69b46 | 2010-09-16 22:49:37 +0800 | [diff] [blame] | 754 | |
Holger Hans Peter Freyther | aaa40b8 | 2010-09-16 20:48:15 +0800 | [diff] [blame] | 755 | conn->lchan = NULL; |
Holger Hans Peter Freyther | 77cd95d | 2010-11-14 16:19:48 +0100 | [diff] [blame] | 756 | conn->secondary_lchan = NULL; |
Holger Hans Peter Freyther | aaa40b8 | 2010-09-16 20:48:15 +0800 | [diff] [blame] | 757 | conn->ho_lchan = NULL; |
| 758 | conn->bts = NULL; |
| 759 | |
Pablo Neira Ayuso | bf540cb | 2011-05-06 12:11:06 +0200 | [diff] [blame] | 760 | osmo_timer_del(&conn->T10); |
Holger Hans Peter Freyther | 77cd95d | 2010-11-14 16:19:48 +0100 | [diff] [blame] | 761 | |
Holger Hans Peter Freyther | 4049455 | 2010-06-28 17:09:29 +0800 | [diff] [blame] | 762 | return 0; |
| 763 | } |
| 764 | |
Holger Hans Peter Freyther | 9c595b7 | 2010-06-15 11:20:52 +0800 | [diff] [blame] | 765 | static void send_sapi_reject(struct gsm_subscriber_connection *conn, int link_id) |
| 766 | { |
| 767 | struct bsc_api *api; |
| 768 | |
Holger Hans Peter Freyther | 2412a07 | 2010-06-28 15:47:12 +0800 | [diff] [blame] | 769 | if (!conn) |
| 770 | return; |
| 771 | |
Neels Hofmeyr | a9f2bb5 | 2016-05-09 21:09:47 +0200 | [diff] [blame] | 772 | api = conn->network->bsc_api; |
Holger Hans Peter Freyther | 9c595b7 | 2010-06-15 11:20:52 +0800 | [diff] [blame] | 773 | if (!api || !api->sapi_n_reject) |
| 774 | return; |
| 775 | |
| 776 | api->sapi_n_reject(conn, link_id); |
| 777 | } |
| 778 | |
| 779 | static void rll_ind_cb(struct gsm_lchan *lchan, uint8_t link_id, void *_data, enum bsc_rllr_ind rllr_ind) |
| 780 | { |
| 781 | struct msgb *msg = _data; |
| 782 | |
Holger Hans Peter Freyther | 7e50c81 | 2010-11-10 10:59:05 +0100 | [diff] [blame] | 783 | /* |
| 784 | * There seems to be a small window that the RLL timer can |
| 785 | * fire after a lchan_release call and before the S_CHALLOC_FREED |
| 786 | * is called. Check if a conn is set before proceeding. |
| 787 | */ |
| 788 | if (!lchan->conn) |
| 789 | return; |
| 790 | |
Holger Hans Peter Freyther | 9c595b7 | 2010-06-15 11:20:52 +0800 | [diff] [blame] | 791 | switch (rllr_ind) { |
| 792 | case BSC_RLLR_IND_EST_CONF: |
| 793 | rsl_data_request(msg, OBSC_LINKID_CB(msg)); |
| 794 | break; |
| 795 | case BSC_RLLR_IND_REL_IND: |
| 796 | case BSC_RLLR_IND_ERR_IND: |
| 797 | case BSC_RLLR_IND_TIMEOUT: |
Holger Hans Peter Freyther | 2412a07 | 2010-06-28 15:47:12 +0800 | [diff] [blame] | 798 | send_sapi_reject(lchan->conn, OBSC_LINKID_CB(msg)); |
Holger Hans Peter Freyther | 9c595b7 | 2010-06-15 11:20:52 +0800 | [diff] [blame] | 799 | msgb_free(msg); |
| 800 | break; |
| 801 | } |
| 802 | } |
| 803 | |
Holger Hans Peter Freyther | abcddf1 | 2010-06-14 18:20:15 +0800 | [diff] [blame] | 804 | static int bsc_handle_lchan_signal(unsigned int subsys, unsigned int signal, |
| 805 | void *handler_data, void *signal_data) |
| 806 | { |
| 807 | struct bsc_api *bsc; |
| 808 | struct gsm_lchan *lchan; |
Holger Hans Peter Freyther | 08eebd5 | 2010-12-27 13:28:20 +0100 | [diff] [blame] | 809 | struct lchan_signal_data *lchan_data; |
Holger Hans Peter Freyther | abcddf1 | 2010-06-14 18:20:15 +0800 | [diff] [blame] | 810 | |
Holger Hans Peter Freyther | f05750c | 2010-11-14 19:29:42 +0100 | [diff] [blame] | 811 | if (subsys != SS_LCHAN) |
Holger Hans Peter Freyther | abcddf1 | 2010-06-14 18:20:15 +0800 | [diff] [blame] | 812 | return 0; |
| 813 | |
Holger Hans Peter Freyther | 9ae7b29 | 2010-12-27 12:30:12 +0100 | [diff] [blame] | 814 | |
Holger Hans Peter Freyther | 08eebd5 | 2010-12-27 13:28:20 +0100 | [diff] [blame] | 815 | lchan_data = signal_data; |
| 816 | if (!lchan_data->lchan || !lchan_data->lchan->conn) |
Holger Hans Peter Freyther | abcddf1 | 2010-06-14 18:20:15 +0800 | [diff] [blame] | 817 | return 0; |
| 818 | |
Holger Hans Peter Freyther | 08eebd5 | 2010-12-27 13:28:20 +0100 | [diff] [blame] | 819 | lchan = lchan_data->lchan; |
Holger Hans Peter Freyther | abcddf1 | 2010-06-14 18:20:15 +0800 | [diff] [blame] | 820 | bsc = lchan->ts->trx->bts->network->bsc_api; |
Holger Hans Peter Freyther | aaa40b8 | 2010-09-16 20:48:15 +0800 | [diff] [blame] | 821 | if (!bsc) |
Holger Hans Peter Freyther | abcddf1 | 2010-06-14 18:20:15 +0800 | [diff] [blame] | 822 | return 0; |
| 823 | |
Holger Hans Peter Freyther | f05750c | 2010-11-14 19:29:42 +0100 | [diff] [blame] | 824 | switch (signal) { |
| 825 | case S_LCHAN_UNEXPECTED_RELEASE: |
| 826 | handle_release(lchan->conn, bsc, lchan); |
| 827 | break; |
Holger Hans Peter Freyther | 77cd95d | 2010-11-14 16:19:48 +0100 | [diff] [blame] | 828 | case S_LCHAN_ACTIVATE_ACK: |
| 829 | handle_chan_ack(lchan->conn, bsc, lchan); |
| 830 | break; |
| 831 | case S_LCHAN_ACTIVATE_NACK: |
| 832 | handle_chan_nack(lchan->conn, bsc, lchan); |
| 833 | break; |
Holger Hans Peter Freyther | f05750c | 2010-11-14 19:29:42 +0100 | [diff] [blame] | 834 | } |
| 835 | |
| 836 | return 0; |
| 837 | } |
| 838 | |
| 839 | static void handle_release(struct gsm_subscriber_connection *conn, |
| 840 | struct bsc_api *bsc, struct gsm_lchan *lchan) |
| 841 | { |
| 842 | int destruct = 1; |
| 843 | |
Holger Hans Peter Freyther | 77cd95d | 2010-11-14 16:19:48 +0100 | [diff] [blame] | 844 | if (conn->secondary_lchan == lchan) { |
Pablo Neira Ayuso | bf540cb | 2011-05-06 12:11:06 +0200 | [diff] [blame] | 845 | osmo_timer_del(&conn->T10); |
Holger Hans Peter Freyther | 77cd95d | 2010-11-14 16:19:48 +0100 | [diff] [blame] | 846 | conn->secondary_lchan = NULL; |
| 847 | |
| 848 | bsc->assign_fail(conn, |
| 849 | GSM0808_CAUSE_RADIO_INTERFACE_FAILURE, |
| 850 | NULL); |
| 851 | } |
| 852 | |
Holger Hans Peter Freyther | 77cd95d | 2010-11-14 16:19:48 +0100 | [diff] [blame] | 853 | /* clear the connection now */ |
| 854 | if (bsc->clear_request) |
| 855 | destruct = bsc->clear_request(conn, 0); |
| 856 | |
Harald Welte | 6349b7f | 2010-12-26 22:12:53 +0100 | [diff] [blame] | 857 | /* now give up all channels */ |
| 858 | if (conn->lchan == lchan) |
| 859 | conn->lchan = NULL; |
Holger Hans Peter Freyther | ebd50a6 | 2010-12-27 13:46:48 +0100 | [diff] [blame] | 860 | if (conn->ho_lchan == lchan) { |
| 861 | bsc_clear_handover(conn, 0); |
Harald Welte | 6349b7f | 2010-12-26 22:12:53 +0100 | [diff] [blame] | 862 | conn->ho_lchan = NULL; |
Holger Hans Peter Freyther | ebd50a6 | 2010-12-27 13:46:48 +0100 | [diff] [blame] | 863 | } |
Harald Welte | 6349b7f | 2010-12-26 22:12:53 +0100 | [diff] [blame] | 864 | lchan->conn = NULL; |
Holger Hans Peter Freyther | 77cd95d | 2010-11-14 16:19:48 +0100 | [diff] [blame] | 865 | |
Holger Hans Peter Freyther | aaa40b8 | 2010-09-16 20:48:15 +0800 | [diff] [blame] | 866 | gsm0808_clear(conn); |
| 867 | |
Holger Hans Peter Freyther | 05c6884 | 2010-11-03 19:01:58 +0100 | [diff] [blame] | 868 | if (destruct) |
Neels Hofmeyr | 42eb014 | 2016-05-20 17:15:44 +0200 | [diff] [blame] | 869 | bsc_subscr_con_free(conn); |
Holger Hans Peter Freyther | abcddf1 | 2010-06-14 18:20:15 +0800 | [diff] [blame] | 870 | } |
| 871 | |
Holger Hans Peter Freyther | 77cd95d | 2010-11-14 16:19:48 +0100 | [diff] [blame] | 872 | static void handle_chan_ack(struct gsm_subscriber_connection *conn, |
| 873 | struct bsc_api *api, struct gsm_lchan *lchan) |
| 874 | { |
| 875 | if (conn->secondary_lchan != lchan) |
| 876 | return; |
| 877 | |
| 878 | LOGP(DMSC, LOGL_NOTICE, "Sending assignment on chan: %p\n", lchan); |
Dieter Spaar | 6b35377 | 2011-09-03 14:11:24 +0200 | [diff] [blame] | 879 | gsm48_send_rr_ass_cmd(conn->lchan, lchan, lchan->ms_power); |
Holger Hans Peter Freyther | 77cd95d | 2010-11-14 16:19:48 +0100 | [diff] [blame] | 880 | } |
| 881 | |
| 882 | static void handle_chan_nack(struct gsm_subscriber_connection *conn, |
| 883 | struct bsc_api *api, struct gsm_lchan *lchan) |
| 884 | { |
| 885 | if (conn->secondary_lchan != lchan) |
| 886 | return; |
| 887 | |
| 888 | LOGP(DMSC, LOGL_ERROR, "Channel activation failed. Waiting for timeout now\n"); |
| 889 | conn->secondary_lchan->conn = NULL; |
| 890 | conn->secondary_lchan = NULL; |
| 891 | } |
| 892 | |
Holger Hans Peter Freyther | abcddf1 | 2010-06-14 18:20:15 +0800 | [diff] [blame] | 893 | static __attribute__((constructor)) void on_dso_load_bsc(void) |
| 894 | { |
Pablo Neira Ayuso | bbc5b99 | 2011-05-06 12:12:31 +0200 | [diff] [blame] | 895 | osmo_signal_register_handler(SS_LCHAN, bsc_handle_lchan_signal, NULL); |
Holger Hans Peter Freyther | 0cfbe26 | 2010-06-15 11:20:24 +0800 | [diff] [blame] | 896 | } |
Holger Hans Peter Freyther | 93dfa24 | 2014-08-08 21:06:30 +0200 | [diff] [blame] | 897 | |