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 | |
| 3 | /* (C) 2010 by Holger Hans Peter Freyther |
Holger Hans Peter Freyther | 85531cc | 2010-10-06 20:37:09 +0800 | [diff] [blame] | 4 | * (C) 2010 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> |
Holger Hans Peter Freyther | ec32b58 | 2010-03-23 07:40:46 +0100 | [diff] [blame] | 34 | |
Pablo Neira Ayuso | 136f453 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 35 | #include <osmocom/gsm/protocol/gsm_08_08.h> |
Holger Hans Peter Freyther | 6c199e7 | 2010-11-04 11:18:03 +0100 | [diff] [blame] | 36 | |
Pablo Neira Ayuso | 136f453 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 37 | #include <osmocom/core/talloc.h> |
Holger Hans Peter Freyther | abcddf1 | 2010-06-14 18:20:15 +0800 | [diff] [blame] | 38 | |
Holger Hans Peter Freyther | 77cd95d | 2010-11-14 16:19:48 +0100 | [diff] [blame] | 39 | #define GSM0808_T10_VALUE 6, 0 |
| 40 | |
Holger Hans Peter Freyther | 79f763f | 2010-09-16 00:53:37 +0800 | [diff] [blame] | 41 | static LLIST_HEAD(sub_connections); |
| 42 | |
Holger Hans Peter Freyther | 9c595b7 | 2010-06-15 11:20:52 +0800 | [diff] [blame] | 43 | static void rll_ind_cb(struct gsm_lchan *, uint8_t, void *, enum bsc_rllr_ind); |
| 44 | 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] | 45 | 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] | 46 | static void handle_chan_ack(struct gsm_subscriber_connection *conn, struct bsc_api *bsc, struct gsm_lchan *lchan); |
| 47 | 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] | 48 | |
Holger Hans Peter Freyther | b094171 | 2010-11-04 12:06:57 +0100 | [diff] [blame] | 49 | /* GSM 08.08 3.2.2.33 */ |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 50 | 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] | 51 | { |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 52 | uint8_t channel_mode = 0, channel = 0; |
Holger Hans Peter Freyther | b094171 | 2010-11-04 12:06:57 +0100 | [diff] [blame] | 53 | |
| 54 | switch (lchan->tch_mode) { |
| 55 | case GSM48_CMODE_SPEECH_V1: |
| 56 | case GSM48_CMODE_SPEECH_EFR: |
| 57 | case GSM48_CMODE_SPEECH_AMR: |
| 58 | channel_mode = 0x9; |
| 59 | break; |
| 60 | case GSM48_CMODE_SIGN: |
| 61 | channel_mode = 0x8; |
| 62 | break; |
| 63 | case GSM48_CMODE_DATA_14k5: |
| 64 | channel_mode = 0xe; |
| 65 | break; |
| 66 | case GSM48_CMODE_DATA_12k0: |
| 67 | channel_mode = 0xb; |
| 68 | break; |
| 69 | case GSM48_CMODE_DATA_6k0: |
| 70 | channel_mode = 0xc; |
| 71 | break; |
| 72 | case GSM48_CMODE_DATA_3k6: |
| 73 | channel_mode = 0xd; |
| 74 | break; |
| 75 | } |
| 76 | |
| 77 | switch (lchan->type) { |
| 78 | case GSM_LCHAN_NONE: |
| 79 | channel = 0x0; |
| 80 | break; |
| 81 | case GSM_LCHAN_SDCCH: |
| 82 | channel = 0x1; |
| 83 | break; |
| 84 | case GSM_LCHAN_TCH_F: |
| 85 | channel = 0x8; |
| 86 | break; |
| 87 | case GSM_LCHAN_TCH_H: |
| 88 | channel = 0x9; |
| 89 | break; |
| 90 | case GSM_LCHAN_UNKNOWN: |
| 91 | LOGP(DMSC, LOGL_ERROR, "Unknown lchan type: %p\n", lchan); |
| 92 | break; |
| 93 | } |
| 94 | |
| 95 | return channel_mode << 4 | channel; |
| 96 | } |
| 97 | |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 98 | 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] | 99 | { |
| 100 | int mode = 0; |
| 101 | |
| 102 | switch (lchan->tch_mode) { |
| 103 | case GSM48_CMODE_SPEECH_V1: |
| 104 | mode = 1; |
| 105 | break; |
| 106 | case GSM48_CMODE_SPEECH_EFR: |
| 107 | mode = 0x11; |
| 108 | break; |
| 109 | case GSM48_CMODE_SPEECH_AMR: |
| 110 | mode = 0x21; |
| 111 | break; |
| 112 | case GSM48_CMODE_SIGN: |
| 113 | case GSM48_CMODE_DATA_14k5: |
| 114 | case GSM48_CMODE_DATA_12k0: |
| 115 | case GSM48_CMODE_DATA_6k0: |
| 116 | case GSM48_CMODE_DATA_3k6: |
| 117 | default: |
| 118 | LOGP(DMSC, LOGL_ERROR, "Using non speech mode: %d\n", mode); |
| 119 | return 0; |
| 120 | break; |
| 121 | } |
| 122 | |
| 123 | /* assume to always do AMR HR on any TCH type */ |
| 124 | if (lchan->type == GSM_LCHAN_TCH_H || |
| 125 | lchan->tch_mode == GSM48_CMODE_SPEECH_AMR) |
| 126 | mode |= 0x4; |
| 127 | |
| 128 | return mode; |
| 129 | } |
| 130 | |
Holger Hans Peter Freyther | 77cd95d | 2010-11-14 16:19:48 +0100 | [diff] [blame] | 131 | static void assignment_t10_timeout(void *_conn) |
| 132 | { |
| 133 | struct bsc_api *api; |
| 134 | struct gsm_subscriber_connection *conn = |
| 135 | (struct gsm_subscriber_connection *) _conn; |
| 136 | |
| 137 | LOGP(DMSC, LOGL_ERROR, "Assigment T10 timeout on %p\n", conn); |
| 138 | |
| 139 | /* normal release on the secondary channel */ |
Daniel Willmann | 28d9ccb | 2011-08-10 11:40:54 +0200 | [diff] [blame] | 140 | if (conn->secondary_lchan) { |
| 141 | lchan_release(conn->secondary_lchan, 0, 1); |
| 142 | } else { |
| 143 | LOGP(DMSC, LOGL_NOTICE, "Secondary lchan is NULL, not releasing\n"); |
| 144 | } |
Holger Hans Peter Freyther | 77cd95d | 2010-11-14 16:19:48 +0100 | [diff] [blame] | 145 | conn->secondary_lchan = NULL; |
| 146 | |
| 147 | /* inform them about the failure */ |
| 148 | api = conn->bts->network->bsc_api; |
| 149 | api->assign_fail(conn, GSM0808_CAUSE_NO_RADIO_RESOURCE_AVAILABLE, NULL); |
| 150 | } |
| 151 | |
| 152 | /* |
| 153 | * Start a new assignment and make sure that it is completed within T10 either |
| 154 | * positively, negatively or by the timeout. |
| 155 | * |
| 156 | * 1.) allocate a new lchan |
| 157 | * 2.) copy the encryption key and other data from the |
| 158 | * old to the new channel. |
| 159 | * 3.) RSL Channel Activate this channel and wait |
| 160 | * |
| 161 | * -> Signal handler for the LCHAN |
| 162 | * 4.) Send GSM 04.08 assignment command to the MS |
| 163 | * |
| 164 | * -> Assignment Complete/Assignment Failure |
| 165 | * 5.) Release the SDCCH, continue signalling on the new link |
| 166 | */ |
| 167 | static int handle_new_assignment(struct gsm_subscriber_connection *conn, int chan_mode, int full_rate) |
| 168 | { |
| 169 | struct gsm_lchan *new_lchan; |
| 170 | int chan_type; |
| 171 | |
| 172 | chan_type = full_rate ? GSM_LCHAN_TCH_F : GSM_LCHAN_TCH_H; |
| 173 | |
| 174 | new_lchan = lchan_alloc(conn->bts, chan_type, 0); |
| 175 | |
| 176 | if (!new_lchan) { |
| 177 | LOGP(DMSC, LOGL_NOTICE, "No free channel.\n"); |
| 178 | return -1; |
| 179 | } |
| 180 | |
| 181 | /* copy old data to the new channel */ |
| 182 | memcpy(&new_lchan->encr, &conn->lchan->encr, sizeof(new_lchan->encr)); |
| 183 | new_lchan->ms_power = conn->lchan->ms_power; |
| 184 | new_lchan->bs_power = conn->lchan->bs_power; |
| 185 | |
| 186 | /* copy new data to it */ |
| 187 | new_lchan->tch_mode = chan_mode; |
| 188 | new_lchan->rsl_cmode = RSL_CMOD_SPD_SPEECH; |
| 189 | |
| 190 | /* handle AMR correctly */ |
| 191 | if (chan_mode == GSM48_CMODE_SPEECH_AMR) { |
| 192 | new_lchan->mr_conf.ver = 1; |
| 193 | new_lchan->mr_conf.icmi = 1; |
| 194 | new_lchan->mr_conf.m5_90 = 1; |
| 195 | } |
| 196 | |
| 197 | if (rsl_chan_activate_lchan(new_lchan, 0x1, 0, 0) < 0) { |
| 198 | LOGP(DHO, LOGL_ERROR, "could not activate channel\n"); |
| 199 | lchan_free(new_lchan); |
| 200 | return -1; |
| 201 | } |
| 202 | |
| 203 | /* remember that we have the channel */ |
| 204 | conn->secondary_lchan = new_lchan; |
| 205 | new_lchan->conn = conn; |
| 206 | |
| 207 | rsl_lchan_set_state(new_lchan, LCHAN_S_ACT_REQ); |
| 208 | return 0; |
| 209 | } |
Holger Hans Peter Freyther | b094171 | 2010-11-04 12:06:57 +0100 | [diff] [blame] | 210 | |
Holger Hans Peter Freyther | a2aedad | 2010-09-16 00:47:32 +0800 | [diff] [blame] | 211 | struct gsm_subscriber_connection *subscr_con_allocate(struct gsm_lchan *lchan) |
| 212 | { |
| 213 | struct gsm_subscriber_connection *conn; |
| 214 | |
| 215 | conn = talloc_zero(lchan->ts->trx->bts->network, struct gsm_subscriber_connection); |
| 216 | if (!conn) |
| 217 | return NULL; |
| 218 | |
| 219 | /* Configure the time and start it so it will be closed */ |
| 220 | conn->lchan = lchan; |
| 221 | conn->bts = lchan->ts->trx->bts; |
| 222 | lchan->conn = conn; |
Holger Hans Peter Freyther | 79f763f | 2010-09-16 00:53:37 +0800 | [diff] [blame] | 223 | llist_add_tail(&conn->entry, &sub_connections); |
Holger Hans Peter Freyther | a2aedad | 2010-09-16 00:47:32 +0800 | [diff] [blame] | 224 | return conn; |
| 225 | } |
| 226 | |
| 227 | /* TODO: move subscriber put here... */ |
| 228 | void subscr_con_free(struct gsm_subscriber_connection *conn) |
| 229 | { |
Holger Hans Peter Freyther | a2aedad | 2010-09-16 00:47:32 +0800 | [diff] [blame] | 230 | if (!conn) |
| 231 | return; |
| 232 | |
| 233 | |
| 234 | if (conn->subscr) { |
| 235 | subscr_put(conn->subscr); |
| 236 | conn->subscr = NULL; |
| 237 | } |
| 238 | |
| 239 | |
Holger Hans Peter Freyther | a2828fa | 2010-11-14 15:50:42 +0100 | [diff] [blame] | 240 | if (conn->ho_lchan) { |
Holger Hans Peter Freyther | a2aedad | 2010-09-16 00:47:32 +0800 | [diff] [blame] | 241 | 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] | 242 | conn->ho_lchan->conn = NULL; |
| 243 | } |
| 244 | |
| 245 | if (conn->lchan) { |
| 246 | LOGP(DNM, LOGL_ERROR, "The lchan should have been cleared.\n"); |
| 247 | conn->lchan->conn = NULL; |
| 248 | } |
Holger Hans Peter Freyther | a2aedad | 2010-09-16 00:47:32 +0800 | [diff] [blame] | 249 | |
Holger Hans Peter Freyther | 77cd95d | 2010-11-14 16:19:48 +0100 | [diff] [blame] | 250 | if (conn->secondary_lchan) { |
| 251 | LOGP(DNM, LOGL_ERROR, "The secondary_lchan should have been cleared.\n"); |
| 252 | conn->secondary_lchan->conn = NULL; |
| 253 | } |
| 254 | |
Holger Hans Peter Freyther | 79f763f | 2010-09-16 00:53:37 +0800 | [diff] [blame] | 255 | llist_del(&conn->entry); |
Holger Hans Peter Freyther | a2aedad | 2010-09-16 00:47:32 +0800 | [diff] [blame] | 256 | talloc_free(conn); |
Holger Hans Peter Freyther | a2aedad | 2010-09-16 00:47:32 +0800 | [diff] [blame] | 257 | } |
| 258 | |
Holger Hans Peter Freyther | abcddf1 | 2010-06-14 18:20:15 +0800 | [diff] [blame] | 259 | int bsc_api_init(struct gsm_network *network, struct bsc_api *api) |
| 260 | { |
| 261 | network->bsc_api = api; |
| 262 | return 0; |
| 263 | } |
Holger Hans Peter Freyther | ec32b58 | 2010-03-23 07:40:46 +0100 | [diff] [blame] | 264 | |
| 265 | int gsm0808_submit_dtap(struct gsm_subscriber_connection *conn, |
Holger Hans Peter Freyther | 8d380dc | 2010-11-10 10:16:02 +0100 | [diff] [blame] | 266 | struct msgb *msg, int link_id, int allow_sach) |
Holger Hans Peter Freyther | ec32b58 | 2010-03-23 07:40:46 +0100 | [diff] [blame] | 267 | { |
Holger Hans Peter Freyther | 8ce8d3a | 2010-12-27 10:55:45 +0100 | [diff] [blame] | 268 | uint8_t sapi; |
| 269 | |
| 270 | |
| 271 | if (!conn->lchan) { |
| 272 | LOGP(DMSC, LOGL_ERROR, |
| 273 | "Called submit dtap without an lchan.\n"); |
| 274 | msgb_free(msg); |
| 275 | return -1; |
| 276 | } |
| 277 | |
| 278 | sapi = link_id & 0x7; |
Holger Hans Peter Freyther | ec32b58 | 2010-03-23 07:40:46 +0100 | [diff] [blame] | 279 | msg->lchan = conn->lchan; |
| 280 | msg->trx = msg->lchan->ts->trx; |
Holger Hans Peter Freyther | 9c595b7 | 2010-06-15 11:20:52 +0800 | [diff] [blame] | 281 | |
Holger Hans Peter Freyther | 8d380dc | 2010-11-10 10:16:02 +0100 | [diff] [blame] | 282 | /* If we are on a TCH and need to submit a SMS (on SAPI=3) we need to use the SACH */ |
| 283 | if (allow_sach && sapi != 0) { |
| 284 | if (conn->lchan->type == GSM_LCHAN_TCH_F || conn->lchan->type == GSM_LCHAN_TCH_H) |
| 285 | link_id |= 0x40; |
| 286 | } |
| 287 | |
Holger Hans Peter Freyther | f6d0e06 | 2010-06-17 17:48:13 +0800 | [diff] [blame] | 288 | msg->l3h = msg->data; |
Holger Hans Peter Freyther | 9c595b7 | 2010-06-15 11:20:52 +0800 | [diff] [blame] | 289 | if (conn->lchan->sapis[sapi] == LCHAN_SAPI_UNUSED) { |
| 290 | OBSC_LINKID_CB(msg) = link_id; |
| 291 | if (rll_establish(msg->lchan, sapi, rll_ind_cb, msg) != 0) { |
| 292 | msgb_free(msg); |
| 293 | send_sapi_reject(conn, link_id); |
| 294 | return -1; |
| 295 | } |
| 296 | return 0; |
| 297 | } else { |
| 298 | return rsl_data_request(msg, link_id); |
| 299 | } |
Holger Hans Peter Freyther | ec32b58 | 2010-03-23 07:40:46 +0100 | [diff] [blame] | 300 | } |
Holger Hans Peter Freyther | 2a9285c | 2010-06-14 18:03:06 +0800 | [diff] [blame] | 301 | |
Holger Hans Peter Freyther | c354de8 | 2010-07-23 16:49:38 +0800 | [diff] [blame] | 302 | /** |
| 303 | * 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] | 304 | * audio codec type or the allowed rates for the config. It is assumed that |
| 305 | * this is for audio handling and that when we have a TCH it is capable of |
| 306 | * handling the audio codec. On top of that it is assumed that we are using |
| 307 | * AMR 5.9 when assigning a TCH/H. |
Holger Hans Peter Freyther | c354de8 | 2010-07-23 16:49:38 +0800 | [diff] [blame] | 308 | */ |
Holger Hans Peter Freyther | 2603c1f | 2010-11-10 10:01:20 +0100 | [diff] [blame] | 309 | 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] | 310 | { |
| 311 | struct bsc_api *api; |
| 312 | api = conn->bts->network->bsc_api; |
| 313 | |
Holger Hans Peter Freyther | 088dde8 | 2010-11-10 11:07:12 +0100 | [diff] [blame] | 314 | if (conn->lchan->type == GSM_LCHAN_SDCCH) { |
Holger Hans Peter Freyther | 77cd95d | 2010-11-14 16:19:48 +0100 | [diff] [blame] | 315 | if (handle_new_assignment(conn, chan_mode, full_rate) != 0) |
| 316 | goto error; |
Holger Hans Peter Freyther | 088dde8 | 2010-11-10 11:07:12 +0100 | [diff] [blame] | 317 | } else { |
| 318 | LOGP(DMSC, LOGL_NOTICE, |
| 319 | "Sending ChanModify for speech %d %d\n", chan_mode, full_rate); |
| 320 | if (chan_mode == GSM48_CMODE_SPEECH_AMR) { |
| 321 | conn->lchan->mr_conf.ver = 1; |
| 322 | conn->lchan->mr_conf.icmi = 1; |
| 323 | conn->lchan->mr_conf.m5_90 = 1; |
| 324 | } |
| 325 | |
Holger Hans Peter Freyther | 77cd95d | 2010-11-14 16:19:48 +0100 | [diff] [blame] | 326 | gsm48_lchan_modify(conn->lchan, chan_mode); |
Holger Hans Peter Freyther | 088dde8 | 2010-11-10 11:07:12 +0100 | [diff] [blame] | 327 | } |
| 328 | |
Holger Hans Peter Freyther | 77cd95d | 2010-11-14 16:19:48 +0100 | [diff] [blame] | 329 | /* we will now start the timer to complete the assignment */ |
| 330 | conn->T10.cb = assignment_t10_timeout; |
| 331 | conn->T10.data = conn; |
Pablo Neira Ayuso | bf540cb | 2011-05-06 12:11:06 +0200 | [diff] [blame] | 332 | osmo_timer_schedule(&conn->T10, GSM0808_T10_VALUE); |
Holger Hans Peter Freyther | c354de8 | 2010-07-23 16:49:38 +0800 | [diff] [blame] | 333 | return 0; |
Holger Hans Peter Freyther | 77cd95d | 2010-11-14 16:19:48 +0100 | [diff] [blame] | 334 | |
| 335 | error: |
| 336 | api->assign_fail(conn, 0, NULL); |
| 337 | return -1; |
Holger Hans Peter Freyther | c354de8 | 2010-07-23 16:49:38 +0800 | [diff] [blame] | 338 | } |
| 339 | |
Holger Hans Peter Freyther | 7700846 | 2010-06-16 14:10:45 +0800 | [diff] [blame] | 340 | int gsm0808_page(struct gsm_bts *bts, unsigned int page_group, unsigned int mi_len, |
| 341 | uint8_t *mi, int chan_type) |
| 342 | { |
| 343 | return rsl_paging_cmd(bts, page_group, mi_len, mi, chan_type); |
| 344 | } |
| 345 | |
Holger Hans Peter Freyther | 77cd95d | 2010-11-14 16:19:48 +0100 | [diff] [blame] | 346 | static void handle_ass_compl(struct gsm_subscriber_connection *conn, |
| 347 | struct msgb *msg) |
| 348 | { |
| 349 | struct gsm48_hdr *gh; |
| 350 | struct bsc_api *api = conn->bts->network->bsc_api; |
| 351 | |
| 352 | if (conn->secondary_lchan != msg->lchan) { |
| 353 | LOGP(DMSC, LOGL_ERROR, "Assignment Compl should occur on second lchan.\n"); |
| 354 | return; |
| 355 | } |
| 356 | |
| 357 | gh = msgb_l3(msg); |
| 358 | if (msgb_l3len(msg) - sizeof(*gh) != 1) { |
Harald Welte | 4d54d0b | 2011-02-19 16:48:17 +0100 | [diff] [blame] | 359 | LOGP(DMSC, LOGL_ERROR, "Assignment Compl invalid: %lu\n", |
Holger Hans Peter Freyther | 77cd95d | 2010-11-14 16:19:48 +0100 | [diff] [blame] | 360 | msgb_l3len(msg) - sizeof(*gh)); |
| 361 | return; |
| 362 | } |
| 363 | |
| 364 | /* swap channels */ |
Pablo Neira Ayuso | bf540cb | 2011-05-06 12:11:06 +0200 | [diff] [blame] | 365 | osmo_timer_del(&conn->T10); |
Holger Hans Peter Freyther | 77cd95d | 2010-11-14 16:19:48 +0100 | [diff] [blame] | 366 | |
| 367 | lchan_release(conn->lchan, 0, 1); |
| 368 | conn->lchan = conn->secondary_lchan; |
| 369 | conn->secondary_lchan = NULL; |
| 370 | |
| 371 | if (is_ipaccess_bts(conn->bts) && conn->lchan->tch_mode != GSM48_CMODE_SIGN) |
| 372 | rsl_ipacc_crcx(conn->lchan); |
| 373 | |
Holger Hans Peter Freyther | 013ae46 | 2011-08-13 22:45:40 +0200 | [diff] [blame] | 374 | if (api->assign_compl) |
| 375 | api->assign_compl(conn, gh->data[0], |
Holger Hans Peter Freyther | 77cd95d | 2010-11-14 16:19:48 +0100 | [diff] [blame] | 376 | lchan_to_chosen_channel(conn->lchan), |
| 377 | conn->lchan->encr.alg_id, |
| 378 | chan_mode_to_speech(conn->lchan)); |
| 379 | } |
| 380 | |
| 381 | static void handle_ass_fail(struct gsm_subscriber_connection *conn, |
| 382 | struct msgb *msg) |
| 383 | { |
| 384 | struct bsc_api *api = conn->bts->network->bsc_api; |
| 385 | uint8_t *rr_failure; |
| 386 | struct gsm48_hdr *gh; |
| 387 | |
| 388 | |
| 389 | if (conn->lchan != msg->lchan) { |
| 390 | LOGP(DMSC, LOGL_ERROR, "Assignment failure should occur on primary lchan.\n"); |
| 391 | return; |
| 392 | } |
| 393 | |
| 394 | /* stop the timer and release it */ |
Pablo Neira Ayuso | bf540cb | 2011-05-06 12:11:06 +0200 | [diff] [blame] | 395 | osmo_timer_del(&conn->T10); |
Holger Hans Peter Freyther | 77cd95d | 2010-11-14 16:19:48 +0100 | [diff] [blame] | 396 | lchan_release(conn->secondary_lchan, 0, 1); |
| 397 | conn->secondary_lchan = NULL; |
| 398 | |
| 399 | gh = msgb_l3(msg); |
| 400 | if (msgb_l3len(msg) - sizeof(*gh) != 1) { |
Harald Welte | 4d54d0b | 2011-02-19 16:48:17 +0100 | [diff] [blame] | 401 | LOGP(DMSC, LOGL_ERROR, "assignemnt failure unhandled: %lu\n", |
Holger Hans Peter Freyther | 77cd95d | 2010-11-14 16:19:48 +0100 | [diff] [blame] | 402 | msgb_l3len(msg) - sizeof(*gh)); |
| 403 | rr_failure = NULL; |
| 404 | } else { |
| 405 | rr_failure = &gh->data[0]; |
| 406 | } |
| 407 | |
| 408 | api->assign_fail(conn, |
| 409 | GSM0808_CAUSE_RADIO_INTERFACE_MESSAGE_FAILURE, |
| 410 | rr_failure); |
| 411 | } |
| 412 | |
Holger Hans Peter Freyther | 46caa30 | 2010-11-04 12:18:00 +0100 | [diff] [blame] | 413 | static void dispatch_dtap(struct gsm_subscriber_connection *conn, |
| 414 | uint8_t link_id, struct msgb *msg) |
Holger Hans Peter Freyther | 6c199e7 | 2010-11-04 11:18:03 +0100 | [diff] [blame] | 415 | { |
| 416 | struct bsc_api *api = msg->lchan->ts->trx->bts->network->bsc_api; |
| 417 | struct gsm48_hdr *gh; |
| 418 | uint8_t pdisc; |
| 419 | int rc; |
| 420 | |
| 421 | if (msgb_l3len(msg) < sizeof(*gh)) { |
| 422 | LOGP(DMSC, LOGL_ERROR, "Message too short for a GSM48 header.\n"); |
| 423 | return; |
| 424 | } |
| 425 | |
| 426 | gh = msgb_l3(msg); |
| 427 | pdisc = gh->proto_discr & 0x0f; |
| 428 | switch (pdisc) { |
| 429 | case GSM48_PDISC_RR: |
| 430 | switch (gh->msg_type) { |
| 431 | case GSM48_MT_RR_CIPH_M_COMPL: |
| 432 | if (api->cipher_mode_compl) |
| 433 | return api->cipher_mode_compl(conn, msg, |
| 434 | conn->lchan->encr.alg_id); |
| 435 | break; |
| 436 | case GSM48_MT_RR_ASS_COMPL: |
Holger Hans Peter Freyther | 77cd95d | 2010-11-14 16:19:48 +0100 | [diff] [blame] | 437 | handle_ass_compl(conn, msg); |
Holger Hans Peter Freyther | 6c199e7 | 2010-11-04 11:18:03 +0100 | [diff] [blame] | 438 | break; |
| 439 | case GSM48_MT_RR_ASS_FAIL: |
Holger Hans Peter Freyther | 77cd95d | 2010-11-14 16:19:48 +0100 | [diff] [blame] | 440 | handle_ass_fail(conn, msg); |
Holger Hans Peter Freyther | 6c199e7 | 2010-11-04 11:18:03 +0100 | [diff] [blame] | 441 | break; |
| 442 | case GSM48_MT_RR_CHAN_MODE_MODIF_ACK: |
Pablo Neira Ayuso | bf540cb | 2011-05-06 12:11:06 +0200 | [diff] [blame] | 443 | osmo_timer_del(&conn->T10); |
Holger Hans Peter Freyther | 6c199e7 | 2010-11-04 11:18:03 +0100 | [diff] [blame] | 444 | rc = gsm48_rx_rr_modif_ack(msg); |
Holger Hans Peter Freyther | 45b575f | 2010-11-05 10:37:17 +0100 | [diff] [blame] | 445 | if (rc < 0 && api->assign_fail) { |
Holger Hans Peter Freyther | 6c199e7 | 2010-11-04 11:18:03 +0100 | [diff] [blame] | 446 | api->assign_fail(conn, |
Holger Hans Peter Freyther | 45b575f | 2010-11-05 10:37:17 +0100 | [diff] [blame] | 447 | GSM0808_CAUSE_NO_RADIO_RESOURCE_AVAILABLE, |
| 448 | NULL); |
| 449 | } else if (rc >= 0 && api->assign_compl) |
Holger Hans Peter Freyther | b094171 | 2010-11-04 12:06:57 +0100 | [diff] [blame] | 450 | api->assign_compl(conn, 0, |
| 451 | lchan_to_chosen_channel(conn->lchan), |
| 452 | conn->lchan->encr.alg_id, |
| 453 | chan_mode_to_speech(conn->lchan)); |
Holger Hans Peter Freyther | 6c199e7 | 2010-11-04 11:18:03 +0100 | [diff] [blame] | 454 | return; |
| 455 | break; |
| 456 | } |
| 457 | break; |
| 458 | case GSM48_PDISC_MM: |
| 459 | break; |
| 460 | } |
| 461 | |
| 462 | /* default case */ |
| 463 | if (api->dtap) |
Holger Hans Peter Freyther | 46caa30 | 2010-11-04 12:18:00 +0100 | [diff] [blame] | 464 | api->dtap(conn, link_id, msg); |
Holger Hans Peter Freyther | 6c199e7 | 2010-11-04 11:18:03 +0100 | [diff] [blame] | 465 | } |
| 466 | |
Holger Hans Peter Freyther | 9764331 | 2010-06-17 16:41:25 +0800 | [diff] [blame] | 467 | int gsm0408_rcvmsg(struct msgb *msg, uint8_t link_id) |
| 468 | { |
| 469 | int rc; |
Holger Hans Peter Freyther | 9764331 | 2010-06-17 16:41:25 +0800 | [diff] [blame] | 470 | 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] | 471 | struct gsm_lchan *lchan; |
Holger Hans Peter Freyther | 9764331 | 2010-06-17 16:41:25 +0800 | [diff] [blame] | 472 | |
Holger Hans Peter Freyther | 2412a07 | 2010-06-28 15:47:12 +0800 | [diff] [blame] | 473 | lchan = msg->lchan; |
Holger Hans Peter Freyther | 49ab278 | 2010-07-05 11:38:37 +0800 | [diff] [blame] | 474 | if (lchan->state != LCHAN_S_ACTIVE) { |
Harald Welte | 2cafc4b | 2010-12-24 13:06:11 +0100 | [diff] [blame] | 475 | LOGP(DRSL, LOGL_INFO, "Got data in non active state(%s), " |
| 476 | "discarding.\n", gsm_lchans_name(lchan->state)); |
Holger Hans Peter Freyther | 49ab278 | 2010-07-05 11:38:37 +0800 | [diff] [blame] | 477 | return -1; |
| 478 | } |
| 479 | |
| 480 | |
Holger Hans Peter Freyther | 2412a07 | 2010-06-28 15:47:12 +0800 | [diff] [blame] | 481 | if (lchan->conn) { |
Holger Hans Peter Freyther | 46caa30 | 2010-11-04 12:18:00 +0100 | [diff] [blame] | 482 | dispatch_dtap(lchan->conn, link_id, msg); |
Holger Hans Peter Freyther | 9764331 | 2010-06-17 16:41:25 +0800 | [diff] [blame] | 483 | } else { |
Holger Hans Peter Freyther | 2412a07 | 2010-06-28 15:47:12 +0800 | [diff] [blame] | 484 | rc = BSC_API_CONN_POL_REJECT; |
| 485 | lchan->conn = subscr_con_allocate(msg->lchan); |
Holger Hans Peter Freyther | 05bbec7 | 2011-01-16 18:15:26 +0100 | [diff] [blame] | 486 | if (!lchan->conn) { |
| 487 | lchan_release(lchan, 0, 0); |
| 488 | return -1; |
| 489 | } |
Holger Hans Peter Freyther | 2412a07 | 2010-06-28 15:47:12 +0800 | [diff] [blame] | 490 | |
Holger Hans Peter Freyther | 05bbec7 | 2011-01-16 18:15:26 +0100 | [diff] [blame] | 491 | rc = api->compl_l3(lchan->conn, msg, 0); |
Holger Hans Peter Freyther | 2412a07 | 2010-06-28 15:47:12 +0800 | [diff] [blame] | 492 | |
| 493 | if (rc != BSC_API_CONN_POL_ACCEPT) { |
Holger Hans Peter Freyther | 8d216c7 | 2010-11-15 10:33:59 +0100 | [diff] [blame] | 494 | lchan->conn->lchan = NULL; |
Holger Hans Peter Freyther | 2412a07 | 2010-06-28 15:47:12 +0800 | [diff] [blame] | 495 | subscr_con_free(lchan->conn); |
Holger Hans Peter Freyther | 4049455 | 2010-06-28 17:09:29 +0800 | [diff] [blame] | 496 | lchan_release(lchan, 0, 0); |
Holger Hans Peter Freyther | 2412a07 | 2010-06-28 15:47:12 +0800 | [diff] [blame] | 497 | } |
Holger Hans Peter Freyther | 9764331 | 2010-06-17 16:41:25 +0800 | [diff] [blame] | 498 | } |
| 499 | |
| 500 | return 0; |
| 501 | } |
| 502 | |
Holger Hans Peter Freyther | dbc62db | 2010-07-23 16:55:24 +0800 | [diff] [blame] | 503 | 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] | 504 | const uint8_t *key, int len, int include_imeisv) |
Holger Hans Peter Freyther | dbc62db | 2010-07-23 16:55:24 +0800 | [diff] [blame] | 505 | { |
Holger Hans Peter Freyther | 4be7d41 | 2010-11-10 10:25:34 +0100 | [diff] [blame] | 506 | if (cipher > 0 && key == NULL) { |
| 507 | LOGP(DRSL, LOGL_ERROR, "Need to have an encrytpion key.\n"); |
| 508 | return -1; |
| 509 | } |
| 510 | |
| 511 | if (len > MAX_A5_KEY_LEN) { |
| 512 | LOGP(DRSL, LOGL_ERROR, "The key is too long: %d\n", len); |
| 513 | return -1; |
| 514 | } |
| 515 | |
| 516 | conn->lchan->encr.alg_id = RSL_ENC_ALG_A5(cipher); |
| 517 | if (key) { |
| 518 | conn->lchan->encr.key_len = len; |
| 519 | memcpy(conn->lchan->encr.key, key, len); |
| 520 | } |
| 521 | |
| 522 | return gsm48_send_rr_ciph_mode(conn->lchan, include_imeisv); |
Holger Hans Peter Freyther | dbc62db | 2010-07-23 16:55:24 +0800 | [diff] [blame] | 523 | } |
| 524 | |
Holger Hans Peter Freyther | aaa40b8 | 2010-09-16 20:48:15 +0800 | [diff] [blame] | 525 | /* |
| 526 | * Release all occupied RF Channels but stay around for more. |
| 527 | */ |
Holger Hans Peter Freyther | adb6e1c | 2010-09-18 06:44:24 +0800 | [diff] [blame] | 528 | int gsm0808_clear(struct gsm_subscriber_connection *conn) |
Holger Hans Peter Freyther | 4049455 | 2010-06-28 17:09:29 +0800 | [diff] [blame] | 529 | { |
Holger Hans Peter Freyther | 1f69b46 | 2010-09-16 22:49:37 +0800 | [diff] [blame] | 530 | if (conn->ho_lchan) |
Holger Hans Peter Freyther | ebd50a6 | 2010-12-27 13:46:48 +0100 | [diff] [blame] | 531 | bsc_clear_handover(conn, 1); |
Holger Hans Peter Freyther | d065165 | 2010-06-30 12:17:35 +0800 | [diff] [blame] | 532 | |
Holger Hans Peter Freyther | 77cd95d | 2010-11-14 16:19:48 +0100 | [diff] [blame] | 533 | if (conn->secondary_lchan) |
| 534 | lchan_release(conn->secondary_lchan, 0, 1); |
| 535 | |
Holger Hans Peter Freyther | abf962b | 2010-11-14 16:04:46 +0100 | [diff] [blame] | 536 | if (conn->lchan) |
Holger Hans Peter Freyther | 1f69b46 | 2010-09-16 22:49:37 +0800 | [diff] [blame] | 537 | lchan_release(conn->lchan, 1, 0); |
Holger Hans Peter Freyther | 1f69b46 | 2010-09-16 22:49:37 +0800 | [diff] [blame] | 538 | |
Holger Hans Peter Freyther | aaa40b8 | 2010-09-16 20:48:15 +0800 | [diff] [blame] | 539 | conn->lchan = NULL; |
Holger Hans Peter Freyther | 77cd95d | 2010-11-14 16:19:48 +0100 | [diff] [blame] | 540 | conn->secondary_lchan = NULL; |
Holger Hans Peter Freyther | aaa40b8 | 2010-09-16 20:48:15 +0800 | [diff] [blame] | 541 | conn->ho_lchan = NULL; |
| 542 | conn->bts = NULL; |
| 543 | |
Pablo Neira Ayuso | bf540cb | 2011-05-06 12:11:06 +0200 | [diff] [blame] | 544 | osmo_timer_del(&conn->T10); |
Holger Hans Peter Freyther | 77cd95d | 2010-11-14 16:19:48 +0100 | [diff] [blame] | 545 | |
Holger Hans Peter Freyther | 4049455 | 2010-06-28 17:09:29 +0800 | [diff] [blame] | 546 | return 0; |
| 547 | } |
| 548 | |
Holger Hans Peter Freyther | 9c595b7 | 2010-06-15 11:20:52 +0800 | [diff] [blame] | 549 | static void send_sapi_reject(struct gsm_subscriber_connection *conn, int link_id) |
| 550 | { |
| 551 | struct bsc_api *api; |
| 552 | |
Holger Hans Peter Freyther | 2412a07 | 2010-06-28 15:47:12 +0800 | [diff] [blame] | 553 | if (!conn) |
| 554 | return; |
| 555 | |
Holger Hans Peter Freyther | 9c595b7 | 2010-06-15 11:20:52 +0800 | [diff] [blame] | 556 | api = conn->bts->network->bsc_api; |
| 557 | if (!api || !api->sapi_n_reject) |
| 558 | return; |
| 559 | |
| 560 | api->sapi_n_reject(conn, link_id); |
| 561 | } |
| 562 | |
| 563 | static void rll_ind_cb(struct gsm_lchan *lchan, uint8_t link_id, void *_data, enum bsc_rllr_ind rllr_ind) |
| 564 | { |
| 565 | struct msgb *msg = _data; |
| 566 | |
Holger Hans Peter Freyther | 7e50c81 | 2010-11-10 10:59:05 +0100 | [diff] [blame] | 567 | /* |
| 568 | * There seems to be a small window that the RLL timer can |
| 569 | * fire after a lchan_release call and before the S_CHALLOC_FREED |
| 570 | * is called. Check if a conn is set before proceeding. |
| 571 | */ |
| 572 | if (!lchan->conn) |
| 573 | return; |
| 574 | |
Holger Hans Peter Freyther | 9c595b7 | 2010-06-15 11:20:52 +0800 | [diff] [blame] | 575 | switch (rllr_ind) { |
| 576 | case BSC_RLLR_IND_EST_CONF: |
| 577 | rsl_data_request(msg, OBSC_LINKID_CB(msg)); |
| 578 | break; |
| 579 | case BSC_RLLR_IND_REL_IND: |
| 580 | case BSC_RLLR_IND_ERR_IND: |
| 581 | case BSC_RLLR_IND_TIMEOUT: |
Holger Hans Peter Freyther | 2412a07 | 2010-06-28 15:47:12 +0800 | [diff] [blame] | 582 | send_sapi_reject(lchan->conn, OBSC_LINKID_CB(msg)); |
Holger Hans Peter Freyther | 9c595b7 | 2010-06-15 11:20:52 +0800 | [diff] [blame] | 583 | msgb_free(msg); |
| 584 | break; |
| 585 | } |
| 586 | } |
| 587 | |
Holger Hans Peter Freyther | abcddf1 | 2010-06-14 18:20:15 +0800 | [diff] [blame] | 588 | static int bsc_handle_lchan_signal(unsigned int subsys, unsigned int signal, |
| 589 | void *handler_data, void *signal_data) |
| 590 | { |
| 591 | struct bsc_api *bsc; |
| 592 | struct gsm_lchan *lchan; |
Holger Hans Peter Freyther | 08eebd5 | 2010-12-27 13:28:20 +0100 | [diff] [blame] | 593 | struct lchan_signal_data *lchan_data; |
Holger Hans Peter Freyther | abcddf1 | 2010-06-14 18:20:15 +0800 | [diff] [blame] | 594 | |
Holger Hans Peter Freyther | f05750c | 2010-11-14 19:29:42 +0100 | [diff] [blame] | 595 | if (subsys != SS_LCHAN) |
Holger Hans Peter Freyther | abcddf1 | 2010-06-14 18:20:15 +0800 | [diff] [blame] | 596 | return 0; |
| 597 | |
Holger Hans Peter Freyther | 9ae7b29 | 2010-12-27 12:30:12 +0100 | [diff] [blame] | 598 | |
Holger Hans Peter Freyther | 08eebd5 | 2010-12-27 13:28:20 +0100 | [diff] [blame] | 599 | lchan_data = signal_data; |
| 600 | if (!lchan_data->lchan || !lchan_data->lchan->conn) |
Holger Hans Peter Freyther | abcddf1 | 2010-06-14 18:20:15 +0800 | [diff] [blame] | 601 | return 0; |
| 602 | |
Holger Hans Peter Freyther | 08eebd5 | 2010-12-27 13:28:20 +0100 | [diff] [blame] | 603 | lchan = lchan_data->lchan; |
Holger Hans Peter Freyther | abcddf1 | 2010-06-14 18:20:15 +0800 | [diff] [blame] | 604 | bsc = lchan->ts->trx->bts->network->bsc_api; |
Holger Hans Peter Freyther | aaa40b8 | 2010-09-16 20:48:15 +0800 | [diff] [blame] | 605 | if (!bsc) |
Holger Hans Peter Freyther | abcddf1 | 2010-06-14 18:20:15 +0800 | [diff] [blame] | 606 | return 0; |
| 607 | |
Holger Hans Peter Freyther | f05750c | 2010-11-14 19:29:42 +0100 | [diff] [blame] | 608 | switch (signal) { |
| 609 | case S_LCHAN_UNEXPECTED_RELEASE: |
| 610 | handle_release(lchan->conn, bsc, lchan); |
| 611 | break; |
Holger Hans Peter Freyther | 77cd95d | 2010-11-14 16:19:48 +0100 | [diff] [blame] | 612 | case S_LCHAN_ACTIVATE_ACK: |
| 613 | handle_chan_ack(lchan->conn, bsc, lchan); |
| 614 | break; |
| 615 | case S_LCHAN_ACTIVATE_NACK: |
| 616 | handle_chan_nack(lchan->conn, bsc, lchan); |
| 617 | break; |
Holger Hans Peter Freyther | f05750c | 2010-11-14 19:29:42 +0100 | [diff] [blame] | 618 | } |
| 619 | |
| 620 | return 0; |
| 621 | } |
| 622 | |
| 623 | static void handle_release(struct gsm_subscriber_connection *conn, |
| 624 | struct bsc_api *bsc, struct gsm_lchan *lchan) |
| 625 | { |
| 626 | int destruct = 1; |
| 627 | |
Holger Hans Peter Freyther | 77cd95d | 2010-11-14 16:19:48 +0100 | [diff] [blame] | 628 | if (conn->secondary_lchan == lchan) { |
Pablo Neira Ayuso | bf540cb | 2011-05-06 12:11:06 +0200 | [diff] [blame] | 629 | osmo_timer_del(&conn->T10); |
Holger Hans Peter Freyther | 77cd95d | 2010-11-14 16:19:48 +0100 | [diff] [blame] | 630 | conn->secondary_lchan = NULL; |
| 631 | |
| 632 | bsc->assign_fail(conn, |
| 633 | GSM0808_CAUSE_RADIO_INTERFACE_FAILURE, |
| 634 | NULL); |
| 635 | } |
| 636 | |
Holger Hans Peter Freyther | 77cd95d | 2010-11-14 16:19:48 +0100 | [diff] [blame] | 637 | /* clear the connection now */ |
| 638 | if (bsc->clear_request) |
| 639 | destruct = bsc->clear_request(conn, 0); |
| 640 | |
Harald Welte | 6349b7f | 2010-12-26 22:12:53 +0100 | [diff] [blame] | 641 | /* now give up all channels */ |
| 642 | if (conn->lchan == lchan) |
| 643 | conn->lchan = NULL; |
Holger Hans Peter Freyther | ebd50a6 | 2010-12-27 13:46:48 +0100 | [diff] [blame] | 644 | if (conn->ho_lchan == lchan) { |
| 645 | bsc_clear_handover(conn, 0); |
Harald Welte | 6349b7f | 2010-12-26 22:12:53 +0100 | [diff] [blame] | 646 | conn->ho_lchan = NULL; |
Holger Hans Peter Freyther | ebd50a6 | 2010-12-27 13:46:48 +0100 | [diff] [blame] | 647 | } |
Harald Welte | 6349b7f | 2010-12-26 22:12:53 +0100 | [diff] [blame] | 648 | lchan->conn = NULL; |
Holger Hans Peter Freyther | 77cd95d | 2010-11-14 16:19:48 +0100 | [diff] [blame] | 649 | |
Holger Hans Peter Freyther | aaa40b8 | 2010-09-16 20:48:15 +0800 | [diff] [blame] | 650 | gsm0808_clear(conn); |
| 651 | |
Holger Hans Peter Freyther | 05c6884 | 2010-11-03 19:01:58 +0100 | [diff] [blame] | 652 | if (destruct) |
| 653 | subscr_con_free(conn); |
Holger Hans Peter Freyther | abcddf1 | 2010-06-14 18:20:15 +0800 | [diff] [blame] | 654 | } |
| 655 | |
Holger Hans Peter Freyther | 77cd95d | 2010-11-14 16:19:48 +0100 | [diff] [blame] | 656 | static void handle_chan_ack(struct gsm_subscriber_connection *conn, |
| 657 | struct bsc_api *api, struct gsm_lchan *lchan) |
| 658 | { |
| 659 | if (conn->secondary_lchan != lchan) |
| 660 | return; |
| 661 | |
| 662 | LOGP(DMSC, LOGL_NOTICE, "Sending assignment on chan: %p\n", lchan); |
| 663 | gsm48_send_rr_ass_cmd(conn->lchan, lchan, 0x3); |
| 664 | } |
| 665 | |
| 666 | static void handle_chan_nack(struct gsm_subscriber_connection *conn, |
| 667 | struct bsc_api *api, struct gsm_lchan *lchan) |
| 668 | { |
| 669 | if (conn->secondary_lchan != lchan) |
| 670 | return; |
| 671 | |
| 672 | LOGP(DMSC, LOGL_ERROR, "Channel activation failed. Waiting for timeout now\n"); |
| 673 | conn->secondary_lchan->conn = NULL; |
| 674 | conn->secondary_lchan = NULL; |
| 675 | } |
| 676 | |
Holger Hans Peter Freyther | abcddf1 | 2010-06-14 18:20:15 +0800 | [diff] [blame] | 677 | static __attribute__((constructor)) void on_dso_load_bsc(void) |
| 678 | { |
Pablo Neira Ayuso | bbc5b99 | 2011-05-06 12:12:31 +0200 | [diff] [blame] | 679 | 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] | 680 | } |