Holger Hans Peter Freyther | 1494a76 | 2009-08-01 07:26:59 +0200 | [diff] [blame] | 1 | /* GSM Mobile Radio Interface Layer 3 messages on the A-bis interface |
| 2 | * 3GPP TS 04.08 version 7.21.0 Release 1998 / ETSI TS 100 940 V7.21.0 |
| 3 | * utility functions |
| 4 | */ |
| 5 | |
| 6 | /* (C) 2008-2009 by Harald Welte <laforge@gnumonks.org> |
| 7 | * (C) 2008, 2009 by Holger Hans Peter Freyther <zecke@selfish.org> |
| 8 | * |
| 9 | * All Rights Reserved |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 12 | * it under the terms of the GNU Affero General Public License as published by |
| 13 | * the Free Software Foundation; either version 3 of the License, or |
Holger Hans Peter Freyther | 1494a76 | 2009-08-01 07:26:59 +0200 | [diff] [blame] | 14 | * (at your option) any later version. |
| 15 | * |
| 16 | * This program is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 19 | * GNU Affero General Public License for more details. |
Holger Hans Peter Freyther | 1494a76 | 2009-08-01 07:26:59 +0200 | [diff] [blame] | 20 | * |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 21 | * You should have received a copy of the GNU Affero General Public License |
| 22 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
Holger Hans Peter Freyther | 1494a76 | 2009-08-01 07:26:59 +0200 | [diff] [blame] | 23 | * |
| 24 | */ |
| 25 | #include <stdio.h> |
| 26 | #include <stdlib.h> |
Holger Hans Peter Freyther | adc1478 | 2009-08-21 04:57:35 +0200 | [diff] [blame] | 27 | #include <errno.h> |
Holger Hans Peter Freyther | 1494a76 | 2009-08-01 07:26:59 +0200 | [diff] [blame] | 28 | #include <netinet/in.h> |
| 29 | |
Pablo Neira Ayuso | 136f453 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 30 | #include <osmocom/core/msgb.h> |
| 31 | #include <osmocom/gsm/gsm48.h> |
Holger Hans Peter Freyther | e2fee35 | 2010-12-22 12:32:56 +0100 | [diff] [blame] | 32 | |
| 33 | #include <openbsc/abis_rsl.h> |
Holger Hans Peter Freyther | 1494a76 | 2009-08-01 07:26:59 +0200 | [diff] [blame] | 34 | #include <openbsc/debug.h> |
| 35 | #include <openbsc/gsm_04_08.h> |
| 36 | #include <openbsc/transaction.h> |
Holger Hans Peter Freyther | 3ee5d3e | 2009-08-21 05:18:21 +0200 | [diff] [blame] | 37 | #include <openbsc/paging.h> |
| 38 | #include <openbsc/signal.h> |
Jacob Erlbeck | 24d3b91 | 2013-10-31 15:36:41 +0100 | [diff] [blame] | 39 | #include <openbsc/bsc_api.h> |
Holger Hans Peter Freyther | 1494a76 | 2009-08-01 07:26:59 +0200 | [diff] [blame] | 40 | |
Holger Hans Peter Freyther | 1494a76 | 2009-08-01 07:26:59 +0200 | [diff] [blame] | 41 | /* should ip.access BTS use direct RTP streams between each other (1), |
| 42 | * or should OpenBSC always act as RTP relay/proxy in between (0) ? */ |
| 43 | int ipacc_rtp_direct = 1; |
| 44 | |
Holger Hans Peter Freyther | 9c137a7 | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 45 | static int gsm48_sendmsg(struct msgb *msg) |
Holger Hans Peter Freyther | 1494a76 | 2009-08-01 07:26:59 +0200 | [diff] [blame] | 46 | { |
Holger Hans Peter Freyther | 9c137a7 | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 47 | if (msg->lchan) |
Pablo Neira Ayuso | 7abecfc | 2011-08-17 22:43:54 +0200 | [diff] [blame] | 48 | msg->dst = msg->lchan->ts->trx->rsl_link; |
Holger Hans Peter Freyther | 1494a76 | 2009-08-01 07:26:59 +0200 | [diff] [blame] | 49 | |
Holger Hans Peter Freyther | 1494a76 | 2009-08-01 07:26:59 +0200 | [diff] [blame] | 50 | msg->l3h = msg->data; |
Holger Hans Peter Freyther | 1494a76 | 2009-08-01 07:26:59 +0200 | [diff] [blame] | 51 | return rsl_data_request(msg, 0); |
| 52 | } |
| 53 | |
Holger Hans Peter Freyther | 1494a76 | 2009-08-01 07:26:59 +0200 | [diff] [blame] | 54 | /* Section 9.1.8 / Table 9.9 */ |
| 55 | struct chreq { |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 56 | uint8_t val; |
| 57 | uint8_t mask; |
Holger Hans Peter Freyther | 1494a76 | 2009-08-01 07:26:59 +0200 | [diff] [blame] | 58 | enum chreq_type type; |
| 59 | }; |
| 60 | |
| 61 | /* If SYSTEM INFORMATION TYPE 4 NECI bit == 1 */ |
| 62 | static const struct chreq chreq_type_neci1[] = { |
| 63 | { 0xa0, 0xe0, CHREQ_T_EMERG_CALL }, |
| 64 | { 0xc0, 0xe0, CHREQ_T_CALL_REEST_TCH_F }, |
| 65 | { 0x68, 0xfc, CHREQ_T_CALL_REEST_TCH_H }, |
| 66 | { 0x6c, 0xfc, CHREQ_T_CALL_REEST_TCH_H_DBL }, |
Sylvain Munaut | cfcf7e8 | 2010-12-27 00:59:23 +0100 | [diff] [blame] | 67 | { 0xe0, 0xe0, CHREQ_T_TCH_F }, |
Holger Hans Peter Freyther | 1494a76 | 2009-08-01 07:26:59 +0200 | [diff] [blame] | 68 | { 0x40, 0xf0, CHREQ_T_VOICE_CALL_TCH_H }, |
| 69 | { 0x50, 0xf0, CHREQ_T_DATA_CALL_TCH_H }, |
| 70 | { 0x00, 0xf0, CHREQ_T_LOCATION_UPD }, |
| 71 | { 0x10, 0xf0, CHREQ_T_SDCCH }, |
Holger Hans Peter Freyther | 135a7c6 | 2009-11-17 16:46:46 +0100 | [diff] [blame] | 72 | { 0x80, 0xe0, CHREQ_T_PAG_R_ANY_NECI1 }, |
Holger Hans Peter Freyther | 1494a76 | 2009-08-01 07:26:59 +0200 | [diff] [blame] | 73 | { 0x20, 0xf0, CHREQ_T_PAG_R_TCH_F }, |
| 74 | { 0x30, 0xf0, CHREQ_T_PAG_R_TCH_FH }, |
Holger Hans Peter Freyther | d61654c | 2009-11-21 20:20:43 +0100 | [diff] [blame] | 75 | { 0x67, 0xff, CHREQ_T_LMU }, |
| 76 | { 0x60, 0xf9, CHREQ_T_RESERVED_SDCCH }, |
| 77 | { 0x61, 0xfb, CHREQ_T_RESERVED_SDCCH }, |
| 78 | { 0x63, 0xff, CHREQ_T_RESERVED_SDCCH }, |
| 79 | { 0x7f, 0xff, CHREQ_T_RESERVED_IGNORE }, |
Holger Hans Peter Freyther | 1494a76 | 2009-08-01 07:26:59 +0200 | [diff] [blame] | 80 | }; |
| 81 | |
| 82 | /* If SYSTEM INFORMATION TYPE 4 NECI bit == 0 */ |
| 83 | static const struct chreq chreq_type_neci0[] = { |
| 84 | { 0xa0, 0xe0, CHREQ_T_EMERG_CALL }, |
| 85 | { 0xc0, 0xe0, CHREQ_T_CALL_REEST_TCH_H }, |
| 86 | { 0xe0, 0xe0, CHREQ_T_TCH_F }, |
| 87 | { 0x50, 0xf0, CHREQ_T_DATA_CALL_TCH_H }, |
| 88 | { 0x00, 0xe0, CHREQ_T_LOCATION_UPD }, |
Holger Hans Peter Freyther | 135a7c6 | 2009-11-17 16:46:46 +0100 | [diff] [blame] | 89 | { 0x80, 0xe0, CHREQ_T_PAG_R_ANY_NECI0 }, |
Holger Hans Peter Freyther | 1494a76 | 2009-08-01 07:26:59 +0200 | [diff] [blame] | 90 | { 0x20, 0xf0, CHREQ_T_PAG_R_TCH_F }, |
| 91 | { 0x30, 0xf0, CHREQ_T_PAG_R_TCH_FH }, |
Holger Hans Peter Freyther | d61654c | 2009-11-21 20:20:43 +0100 | [diff] [blame] | 92 | { 0x67, 0xff, CHREQ_T_LMU }, |
| 93 | { 0x60, 0xf9, CHREQ_T_RESERVED_SDCCH }, |
| 94 | { 0x61, 0xfb, CHREQ_T_RESERVED_SDCCH }, |
| 95 | { 0x63, 0xff, CHREQ_T_RESERVED_SDCCH }, |
| 96 | { 0x7f, 0xff, CHREQ_T_RESERVED_IGNORE }, |
Holger Hans Peter Freyther | 1494a76 | 2009-08-01 07:26:59 +0200 | [diff] [blame] | 97 | }; |
| 98 | |
| 99 | static const enum gsm_chan_t ctype_by_chreq[] = { |
| 100 | [CHREQ_T_EMERG_CALL] = GSM_LCHAN_TCH_F, |
| 101 | [CHREQ_T_CALL_REEST_TCH_F] = GSM_LCHAN_TCH_F, |
| 102 | [CHREQ_T_CALL_REEST_TCH_H] = GSM_LCHAN_TCH_H, |
| 103 | [CHREQ_T_CALL_REEST_TCH_H_DBL] = GSM_LCHAN_TCH_H, |
| 104 | [CHREQ_T_SDCCH] = GSM_LCHAN_SDCCH, |
| 105 | [CHREQ_T_TCH_F] = GSM_LCHAN_TCH_F, |
| 106 | [CHREQ_T_VOICE_CALL_TCH_H] = GSM_LCHAN_TCH_H, |
| 107 | [CHREQ_T_DATA_CALL_TCH_H] = GSM_LCHAN_TCH_H, |
| 108 | [CHREQ_T_LOCATION_UPD] = GSM_LCHAN_SDCCH, |
Holger Hans Peter Freyther | 135a7c6 | 2009-11-17 16:46:46 +0100 | [diff] [blame] | 109 | [CHREQ_T_PAG_R_ANY_NECI1] = GSM_LCHAN_SDCCH, |
| 110 | [CHREQ_T_PAG_R_ANY_NECI0] = GSM_LCHAN_SDCCH, |
Holger Hans Peter Freyther | 1494a76 | 2009-08-01 07:26:59 +0200 | [diff] [blame] | 111 | [CHREQ_T_PAG_R_TCH_F] = GSM_LCHAN_TCH_F, |
| 112 | [CHREQ_T_PAG_R_TCH_FH] = GSM_LCHAN_TCH_F, |
Holger Hans Peter Freyther | d61654c | 2009-11-21 20:20:43 +0100 | [diff] [blame] | 113 | [CHREQ_T_LMU] = GSM_LCHAN_SDCCH, |
| 114 | [CHREQ_T_RESERVED_SDCCH] = GSM_LCHAN_SDCCH, |
| 115 | [CHREQ_T_RESERVED_IGNORE] = GSM_LCHAN_UNKNOWN, |
Holger Hans Peter Freyther | 1494a76 | 2009-08-01 07:26:59 +0200 | [diff] [blame] | 116 | }; |
| 117 | |
| 118 | static const enum gsm_chreq_reason_t reason_by_chreq[] = { |
| 119 | [CHREQ_T_EMERG_CALL] = GSM_CHREQ_REASON_EMERG, |
| 120 | [CHREQ_T_CALL_REEST_TCH_F] = GSM_CHREQ_REASON_CALL, |
| 121 | [CHREQ_T_CALL_REEST_TCH_H] = GSM_CHREQ_REASON_CALL, |
| 122 | [CHREQ_T_CALL_REEST_TCH_H_DBL] = GSM_CHREQ_REASON_CALL, |
| 123 | [CHREQ_T_SDCCH] = GSM_CHREQ_REASON_OTHER, |
| 124 | [CHREQ_T_TCH_F] = GSM_CHREQ_REASON_OTHER, |
Harald Welte | 9385c11 | 2009-12-12 20:57:52 +0100 | [diff] [blame] | 125 | [CHREQ_T_VOICE_CALL_TCH_H] = GSM_CHREQ_REASON_CALL, |
Holger Hans Peter Freyther | 1494a76 | 2009-08-01 07:26:59 +0200 | [diff] [blame] | 126 | [CHREQ_T_DATA_CALL_TCH_H] = GSM_CHREQ_REASON_OTHER, |
| 127 | [CHREQ_T_LOCATION_UPD] = GSM_CHREQ_REASON_LOCATION_UPD, |
Holger Hans Peter Freyther | 135a7c6 | 2009-11-17 16:46:46 +0100 | [diff] [blame] | 128 | [CHREQ_T_PAG_R_ANY_NECI1] = GSM_CHREQ_REASON_PAG, |
| 129 | [CHREQ_T_PAG_R_ANY_NECI0] = GSM_CHREQ_REASON_PAG, |
Holger Hans Peter Freyther | 1494a76 | 2009-08-01 07:26:59 +0200 | [diff] [blame] | 130 | [CHREQ_T_PAG_R_TCH_F] = GSM_CHREQ_REASON_PAG, |
| 131 | [CHREQ_T_PAG_R_TCH_FH] = GSM_CHREQ_REASON_PAG, |
Holger Hans Peter Freyther | d61654c | 2009-11-21 20:20:43 +0100 | [diff] [blame] | 132 | [CHREQ_T_LMU] = GSM_CHREQ_REASON_OTHER, |
| 133 | [CHREQ_T_RESERVED_SDCCH] = GSM_CHREQ_REASON_OTHER, |
| 134 | [CHREQ_T_RESERVED_IGNORE] = GSM_CHREQ_REASON_OTHER, |
Holger Hans Peter Freyther | 1494a76 | 2009-08-01 07:26:59 +0200 | [diff] [blame] | 135 | }; |
| 136 | |
Holger Hans Peter Freyther | 7889107 | 2010-09-06 09:36:02 +0800 | [diff] [blame] | 137 | /* verify that the two tables match */ |
Pablo Neira Ayuso | c0d17f2 | 2011-05-07 12:12:48 +0200 | [diff] [blame] | 138 | osmo_static_assert(sizeof(ctype_by_chreq) == |
Holger Hans Peter Freyther | 7889107 | 2010-09-06 09:36:02 +0800 | [diff] [blame] | 139 | sizeof(((struct gsm_network *) NULL)->ctype_by_chreq), assert_size); |
| 140 | |
| 141 | /* |
| 142 | * Update channel types for request based on policy. E.g. in the |
| 143 | * case of a TCH/H network/bsc use TCH/H for the emergency calls, |
| 144 | * for early assignment assign a SDCCH and some other options. |
| 145 | */ |
| 146 | void gsm_net_update_ctype(struct gsm_network *network) |
| 147 | { |
| 148 | /* copy over the data */ |
| 149 | memcpy(network->ctype_by_chreq, ctype_by_chreq, sizeof(ctype_by_chreq)); |
| 150 | |
| 151 | /* |
| 152 | * Use TCH/H for emergency calls when this cell allows TCH/H. Maybe it |
| 153 | * is better to iterate over the BTS/TRX and check if no TCH/F is available |
| 154 | * and then set it to TCH/H. |
| 155 | */ |
| 156 | if (network->neci) |
| 157 | network->ctype_by_chreq[CHREQ_T_EMERG_CALL] = GSM_LCHAN_TCH_H; |
Holger Hans Peter Freyther | 76fc4a3 | 2010-09-06 09:41:50 +0800 | [diff] [blame] | 158 | |
| 159 | if (network->pag_any_tch) { |
| 160 | if (network->neci) { |
| 161 | network->ctype_by_chreq[CHREQ_T_PAG_R_ANY_NECI0] = GSM_LCHAN_TCH_H; |
| 162 | network->ctype_by_chreq[CHREQ_T_PAG_R_ANY_NECI1] = GSM_LCHAN_TCH_H; |
| 163 | } else { |
| 164 | network->ctype_by_chreq[CHREQ_T_PAG_R_ANY_NECI0] = GSM_LCHAN_TCH_F; |
| 165 | network->ctype_by_chreq[CHREQ_T_PAG_R_ANY_NECI1] = GSM_LCHAN_TCH_F; |
| 166 | } |
| 167 | } |
Holger Hans Peter Freyther | 7889107 | 2010-09-06 09:36:02 +0800 | [diff] [blame] | 168 | } |
| 169 | |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 170 | enum gsm_chan_t get_ctype_by_chreq(struct gsm_network *network, uint8_t ra) |
Holger Hans Peter Freyther | 1494a76 | 2009-08-01 07:26:59 +0200 | [diff] [blame] | 171 | { |
| 172 | int i; |
Holger Hans Peter Freyther | 843b44d | 2009-11-17 16:38:25 +0100 | [diff] [blame] | 173 | int length; |
| 174 | const struct chreq *chreq; |
Holger Hans Peter Freyther | 1494a76 | 2009-08-01 07:26:59 +0200 | [diff] [blame] | 175 | |
Holger Hans Peter Freyther | 7889107 | 2010-09-06 09:36:02 +0800 | [diff] [blame] | 176 | if (network->neci) { |
Holger Hans Peter Freyther | 843b44d | 2009-11-17 16:38:25 +0100 | [diff] [blame] | 177 | chreq = chreq_type_neci1; |
| 178 | length = ARRAY_SIZE(chreq_type_neci1); |
| 179 | } else { |
| 180 | chreq = chreq_type_neci0; |
| 181 | length = ARRAY_SIZE(chreq_type_neci0); |
| 182 | } |
| 183 | |
| 184 | |
| 185 | for (i = 0; i < length; i++) { |
| 186 | const struct chreq *chr = &chreq[i]; |
Holger Hans Peter Freyther | 1494a76 | 2009-08-01 07:26:59 +0200 | [diff] [blame] | 187 | if ((ra & chr->mask) == chr->val) |
Holger Hans Peter Freyther | 7889107 | 2010-09-06 09:36:02 +0800 | [diff] [blame] | 188 | return network->ctype_by_chreq[chr->type]; |
Holger Hans Peter Freyther | 1494a76 | 2009-08-01 07:26:59 +0200 | [diff] [blame] | 189 | } |
Harald Welte | 50720e7 | 2009-12-24 11:50:20 +0100 | [diff] [blame] | 190 | LOGP(DRR, LOGL_ERROR, "Unknown CHANNEL REQUEST RQD 0x%02x\n", ra); |
Holger Hans Peter Freyther | 1494a76 | 2009-08-01 07:26:59 +0200 | [diff] [blame] | 191 | return GSM_LCHAN_SDCCH; |
| 192 | } |
| 193 | |
Harald Welte | b226864 | 2011-07-23 10:53:30 +0200 | [diff] [blame] | 194 | int get_reason_by_chreq(uint8_t ra, int neci) |
Holger Hans Peter Freyther | 1494a76 | 2009-08-01 07:26:59 +0200 | [diff] [blame] | 195 | { |
| 196 | int i; |
Holger Hans Peter Freyther | 843b44d | 2009-11-17 16:38:25 +0100 | [diff] [blame] | 197 | int length; |
| 198 | const struct chreq *chreq; |
Holger Hans Peter Freyther | 1494a76 | 2009-08-01 07:26:59 +0200 | [diff] [blame] | 199 | |
Holger Hans Peter Freyther | 843b44d | 2009-11-17 16:38:25 +0100 | [diff] [blame] | 200 | if (neci) { |
| 201 | chreq = chreq_type_neci1; |
| 202 | length = ARRAY_SIZE(chreq_type_neci1); |
| 203 | } else { |
| 204 | chreq = chreq_type_neci0; |
| 205 | length = ARRAY_SIZE(chreq_type_neci0); |
| 206 | } |
| 207 | |
| 208 | for (i = 0; i < length; i++) { |
| 209 | const struct chreq *chr = &chreq[i]; |
Holger Hans Peter Freyther | 1494a76 | 2009-08-01 07:26:59 +0200 | [diff] [blame] | 210 | if ((ra & chr->mask) == chr->val) |
| 211 | return reason_by_chreq[chr->type]; |
| 212 | } |
Harald Welte | 50720e7 | 2009-12-24 11:50:20 +0100 | [diff] [blame] | 213 | LOGP(DRR, LOGL_ERROR, "Unknown CHANNEL REQUEST REASON 0x%02x\n", ra); |
Holger Hans Peter Freyther | 1494a76 | 2009-08-01 07:26:59 +0200 | [diff] [blame] | 214 | return GSM_CHREQ_REASON_OTHER; |
| 215 | } |
| 216 | |
Holger Hans Peter Freyther | 11cb7a9 | 2015-08-20 19:32:46 +0200 | [diff] [blame] | 217 | static void mr_config_for_ms(struct gsm_lchan *lchan, struct msgb *msg) |
| 218 | { |
| 219 | if (lchan->tch_mode == GSM48_CMODE_SPEECH_AMR) |
| 220 | msgb_tlv_put(msg, GSM48_IE_MUL_RATE_CFG, lchan->mr_ms_lv[0], |
| 221 | lchan->mr_ms_lv + 1); |
| 222 | } |
| 223 | |
Holger Hans Peter Freyther | 1494a76 | 2009-08-01 07:26:59 +0200 | [diff] [blame] | 224 | /* 7.1.7 and 9.1.7: RR CHANnel RELease */ |
| 225 | int gsm48_send_rr_release(struct gsm_lchan *lchan) |
| 226 | { |
Holger Hans Peter Freyther | 8239e06 | 2016-01-25 22:03:25 +0100 | [diff] [blame] | 227 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 RR REL"); |
Holger Hans Peter Freyther | 1494a76 | 2009-08-01 07:26:59 +0200 | [diff] [blame] | 228 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 229 | uint8_t *cause; |
Holger Hans Peter Freyther | 1494a76 | 2009-08-01 07:26:59 +0200 | [diff] [blame] | 230 | |
| 231 | msg->lchan = lchan; |
| 232 | gh->proto_discr = GSM48_PDISC_RR; |
| 233 | gh->msg_type = GSM48_MT_RR_CHAN_REL; |
| 234 | |
| 235 | cause = msgb_put(msg, 1); |
| 236 | cause[0] = GSM48_RR_CAUSE_NORMAL; |
| 237 | |
| 238 | DEBUGP(DRR, "Sending Channel Release: Chan: Number: %d Type: %d\n", |
| 239 | lchan->nr, lchan->type); |
| 240 | |
| 241 | /* Send actual release request to MS */ |
Holger Hans Peter Freyther | b348939 | 2011-12-28 16:21:05 +0100 | [diff] [blame] | 242 | return gsm48_sendmsg(msg); |
Holger Hans Peter Freyther | 1494a76 | 2009-08-01 07:26:59 +0200 | [diff] [blame] | 243 | } |
| 244 | |
Holger Hans Peter Freyther | adc1478 | 2009-08-21 04:57:35 +0200 | [diff] [blame] | 245 | int send_siemens_mrpci(struct gsm_lchan *lchan, |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 246 | uint8_t *classmark2_lv) |
Holger Hans Peter Freyther | adc1478 | 2009-08-21 04:57:35 +0200 | [diff] [blame] | 247 | { |
| 248 | struct rsl_mrpci mrpci; |
| 249 | |
| 250 | if (classmark2_lv[0] < 2) |
| 251 | return -EINVAL; |
| 252 | |
| 253 | mrpci.power_class = classmark2_lv[1] & 0x7; |
| 254 | mrpci.vgcs_capable = classmark2_lv[2] & (1 << 1); |
| 255 | mrpci.vbs_capable = classmark2_lv[2] & (1 <<2); |
| 256 | mrpci.gsm_phase = (classmark2_lv[1]) >> 5 & 0x3; |
| 257 | |
| 258 | return rsl_siemens_mrpci(lchan, &mrpci); |
| 259 | } |
| 260 | |
Holger Hans Peter Freyther | b7b9c1d | 2010-05-16 01:07:20 +0800 | [diff] [blame] | 261 | int gsm48_extract_mi(uint8_t *classmark2_lv, int length, char *mi_string, uint8_t *mi_type) |
Holger Hans Peter Freyther | 3ee5d3e | 2009-08-21 05:18:21 +0200 | [diff] [blame] | 262 | { |
Holger Hans Peter Freyther | f6903de | 2010-05-16 01:51:14 +0800 | [diff] [blame] | 263 | /* Check the size for the classmark */ |
Holger Hans Peter Freyther | b7b9c1d | 2010-05-16 01:07:20 +0800 | [diff] [blame] | 264 | if (length < 1 + *classmark2_lv) |
Holger Hans Peter Freyther | f6903de | 2010-05-16 01:51:14 +0800 | [diff] [blame] | 265 | return -1; |
| 266 | |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 267 | uint8_t *mi_lv = classmark2_lv + *classmark2_lv + 1; |
Holger Hans Peter Freyther | b7b9c1d | 2010-05-16 01:07:20 +0800 | [diff] [blame] | 268 | if (length < 2 + *classmark2_lv + mi_lv[0]) |
Holger Hans Peter Freyther | f6903de | 2010-05-16 01:51:14 +0800 | [diff] [blame] | 269 | return -2; |
| 270 | |
| 271 | *mi_type = mi_lv[1] & GSM_MI_TYPE_MASK; |
Holger Hans Peter Freyther | 3ee5d3e | 2009-08-21 05:18:21 +0200 | [diff] [blame] | 272 | return gsm48_mi_to_string(mi_string, GSM48_MI_SIZE, mi_lv+1, *mi_lv); |
| 273 | } |
| 274 | |
Holger Hans Peter Freyther | b7b9c1d | 2010-05-16 01:07:20 +0800 | [diff] [blame] | 275 | int gsm48_paging_extract_mi(struct gsm48_pag_resp *resp, int length, |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 276 | char *mi_string, uint8_t *mi_type) |
Holger Hans Peter Freyther | b7b9c1d | 2010-05-16 01:07:20 +0800 | [diff] [blame] | 277 | { |
| 278 | static const uint32_t classmark_offset = |
| 279 | offsetof(struct gsm48_pag_resp, classmark2); |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 280 | uint8_t *classmark2_lv = (uint8_t *) &resp->classmark2; |
Holger Hans Peter Freyther | b7b9c1d | 2010-05-16 01:07:20 +0800 | [diff] [blame] | 281 | return gsm48_extract_mi(classmark2_lv, length - classmark_offset, |
| 282 | mi_string, mi_type); |
| 283 | } |
| 284 | |
Holger Hans Peter Freyther | db4ef0d | 2010-06-21 10:46:44 +0800 | [diff] [blame] | 285 | int gsm48_handle_paging_resp(struct gsm_subscriber_connection *conn, |
Neels Hofmeyr | 6d804b1 | 2017-02-18 22:20:46 +0100 | [diff] [blame^] | 286 | struct msgb *msg, struct bsc_subscr *bsub) |
Holger Hans Peter Freyther | 3ee5d3e | 2009-08-21 05:18:21 +0200 | [diff] [blame] | 287 | { |
| 288 | struct gsm_bts *bts = msg->lchan->ts->trx->bts; |
| 289 | struct gsm48_hdr *gh = msgb_l3(msg); |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 290 | uint8_t *classmark2_lv = gh->data + 1; |
Holger Hans Peter Freyther | 3ee5d3e | 2009-08-21 05:18:21 +0200 | [diff] [blame] | 291 | |
| 292 | if (is_siemens_bts(bts)) |
| 293 | send_siemens_mrpci(msg->lchan, classmark2_lv); |
| 294 | |
Neels Hofmeyr | 6d804b1 | 2017-02-18 22:20:46 +0100 | [diff] [blame^] | 295 | if (!conn->bsub) { |
| 296 | conn->bsub = bsub; |
| 297 | } else if (conn->bsub != bsub) { |
| 298 | LOGP(DRR, LOGL_ERROR, |
| 299 | "<- Channel already owned by someone else?\n"); |
| 300 | bsc_subscr_put(bsub); |
Holger Hans Peter Freyther | 3ee5d3e | 2009-08-21 05:18:21 +0200 | [diff] [blame] | 301 | return -EINVAL; |
| 302 | } else { |
| 303 | DEBUGP(DRR, "<- Channel already owned by us\n"); |
Neels Hofmeyr | 6d804b1 | 2017-02-18 22:20:46 +0100 | [diff] [blame^] | 304 | bsc_subscr_put(bsub); |
| 305 | bsub = conn->bsub; |
Holger Hans Peter Freyther | 3ee5d3e | 2009-08-21 05:18:21 +0200 | [diff] [blame] | 306 | } |
| 307 | |
Alexander Couzens | b847a21 | 2016-08-02 11:34:11 +0200 | [diff] [blame] | 308 | rate_ctr_inc(&bts->network->bsc_ctrs->ctr[BSC_CTR_PAGING_COMPLETED]); |
Harald Welte | 24ff6ee | 2009-12-22 00:41:05 +0100 | [diff] [blame] | 309 | |
Holger Hans Peter Freyther | 3ee5d3e | 2009-08-21 05:18:21 +0200 | [diff] [blame] | 310 | /* Stop paging on the bts we received the paging response */ |
Neels Hofmeyr | 6d804b1 | 2017-02-18 22:20:46 +0100 | [diff] [blame^] | 311 | paging_request_stop(&bts->network->bts_list, conn->bts, bsub, conn, |
| 312 | msg); |
Holger Hans Peter Freyther | 3ee5d3e | 2009-08-21 05:18:21 +0200 | [diff] [blame] | 313 | return 0; |
| 314 | } |
Holger Hans Peter Freyther | ea4088a | 2009-10-05 13:25:06 +0200 | [diff] [blame] | 315 | |
| 316 | /* Chapter 9.1.9: Ciphering Mode Command */ |
Holger Hans Peter Freyther | ca6bc1d | 2009-10-05 14:00:14 +0200 | [diff] [blame] | 317 | int gsm48_send_rr_ciph_mode(struct gsm_lchan *lchan, int want_imeisv) |
Holger Hans Peter Freyther | ea4088a | 2009-10-05 13:25:06 +0200 | [diff] [blame] | 318 | { |
Holger Hans Peter Freyther | 8239e06 | 2016-01-25 22:03:25 +0100 | [diff] [blame] | 319 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 CIPH"); |
Holger Hans Peter Freyther | ea4088a | 2009-10-05 13:25:06 +0200 | [diff] [blame] | 320 | struct gsm48_hdr *gh; |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 321 | uint8_t ciph_mod_set; |
Holger Hans Peter Freyther | ea4088a | 2009-10-05 13:25:06 +0200 | [diff] [blame] | 322 | |
| 323 | msg->lchan = lchan; |
| 324 | |
| 325 | DEBUGP(DRR, "TX CIPHERING MODE CMD\n"); |
| 326 | |
| 327 | if (lchan->encr.alg_id <= RSL_ENC_ALG_A5(0)) |
| 328 | ciph_mod_set = 0; |
| 329 | else |
| 330 | ciph_mod_set = (lchan->encr.alg_id-2)<<1 | 1; |
| 331 | |
| 332 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 1); |
| 333 | gh->proto_discr = GSM48_PDISC_RR; |
| 334 | gh->msg_type = GSM48_MT_RR_CIPH_M_CMD; |
Holger Hans Peter Freyther | ca6bc1d | 2009-10-05 14:00:14 +0200 | [diff] [blame] | 335 | gh->data[0] = (want_imeisv & 0x1) << 4 | (ciph_mod_set & 0xf); |
Holger Hans Peter Freyther | ea4088a | 2009-10-05 13:25:06 +0200 | [diff] [blame] | 336 | |
| 337 | return rsl_encryption_cmd(msg); |
| 338 | } |
| 339 | |
Harald Welte | 8c83af6 | 2009-11-29 20:02:53 +0100 | [diff] [blame] | 340 | static void gsm48_cell_desc(struct gsm48_cell_desc *cd, |
| 341 | const struct gsm_bts *bts) |
| 342 | { |
| 343 | cd->ncc = (bts->bsic >> 3 & 0x7); |
| 344 | cd->bcc = (bts->bsic & 0x7); |
| 345 | cd->arfcn_hi = bts->c0->arfcn >> 8; |
| 346 | cd->arfcn_lo = bts->c0->arfcn & 0xff; |
| 347 | } |
| 348 | |
Harald Welte | a39b0f2 | 2010-06-14 22:26:10 +0200 | [diff] [blame] | 349 | void gsm48_lchan2chan_desc(struct gsm48_chan_desc *cd, |
| 350 | const struct gsm_lchan *lchan) |
Harald Welte | 8c83af6 | 2009-11-29 20:02:53 +0100 | [diff] [blame] | 351 | { |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 352 | uint16_t arfcn = lchan->ts->trx->arfcn & 0x3ff; |
Harald Welte | 8c83af6 | 2009-11-29 20:02:53 +0100 | [diff] [blame] | 353 | |
Harald Welte | f6093a4 | 2011-06-25 10:02:33 +0200 | [diff] [blame] | 354 | cd->chan_nr = gsm_lchan2chan_nr(lchan); |
Harald Welte | a39b0f2 | 2010-06-14 22:26:10 +0200 | [diff] [blame] | 355 | if (!lchan->ts->hopping.enabled) { |
Harald Welte | 1fe2412 | 2014-01-19 17:18:21 +0100 | [diff] [blame] | 356 | cd->h0.tsc = gsm_ts_tsc(lchan->ts); |
Harald Welte | a39b0f2 | 2010-06-14 22:26:10 +0200 | [diff] [blame] | 357 | cd->h0.h = 0; |
| 358 | cd->h0.arfcn_high = arfcn >> 8; |
| 359 | cd->h0.arfcn_low = arfcn & 0xff; |
| 360 | } else { |
Harald Welte | 1fe2412 | 2014-01-19 17:18:21 +0100 | [diff] [blame] | 361 | cd->h1.tsc = gsm_ts_tsc(lchan->ts); |
Harald Welte | a39b0f2 | 2010-06-14 22:26:10 +0200 | [diff] [blame] | 362 | cd->h1.h = 1; |
| 363 | cd->h1.maio_high = lchan->ts->hopping.maio >> 2; |
| 364 | cd->h1.maio_low = lchan->ts->hopping.maio & 0x03; |
| 365 | cd->h1.hsn = lchan->ts->hopping.hsn; |
| 366 | } |
Harald Welte | 8c83af6 | 2009-11-29 20:02:53 +0100 | [diff] [blame] | 367 | } |
| 368 | |
Holger Hans Peter Freyther | 615ed46 | 2015-09-24 11:30:58 +0200 | [diff] [blame] | 369 | int gsm48_multirate_config(uint8_t *lv, struct amr_multirate_conf *mr, struct amr_mode *modes) |
Andreas Eversberg | 7326652 | 2014-01-19 11:47:44 +0100 | [diff] [blame] | 370 | { |
| 371 | int num = 0, i; |
| 372 | |
| 373 | for (i = 0; i < 8; i++) { |
| 374 | if (((mr->gsm48_ie[1] >> i) & 1)) |
| 375 | num++; |
| 376 | } |
| 377 | if (num > 4) { |
| 378 | LOGP(DRR, LOGL_ERROR, "BUG: Using multirate codec with too " |
| 379 | "many modes in config.\n"); |
| 380 | num = 4; |
| 381 | } |
| 382 | if (num < 1) { |
| 383 | LOGP(DRR, LOGL_ERROR, "BUG: Using multirate codec with no " |
| 384 | "mode in config.\n"); |
| 385 | num = 1; |
| 386 | } |
| 387 | |
| 388 | lv[0] = (num == 1) ? 2 : (num + 2); |
| 389 | memcpy(lv + 1, mr->gsm48_ie, 2); |
| 390 | if (num == 1) |
| 391 | return 0; |
Holger Hans Peter Freyther | 615ed46 | 2015-09-24 11:30:58 +0200 | [diff] [blame] | 392 | |
| 393 | lv[3] = modes[0].threshold & 0x3f; |
| 394 | lv[4] = modes[0].hysteresis << 4; |
| 395 | if (num == 2) |
| 396 | return 0; |
| 397 | lv[4] |= (modes[1].threshold & 0x3f) >> 2; |
| 398 | lv[5] = modes[1].threshold << 6; |
| 399 | lv[5] |= (modes[1].hysteresis & 0x0f) << 2; |
| 400 | if (num == 3) |
| 401 | return 0; |
| 402 | lv[5] |= (modes[2].threshold & 0x3f) >> 4; |
| 403 | lv[6] = modes[2].threshold << 4; |
| 404 | lv[6] |= modes[2].hysteresis & 0x0f; |
Andreas Eversberg | 7326652 | 2014-01-19 11:47:44 +0100 | [diff] [blame] | 405 | |
| 406 | return 0; |
| 407 | } |
| 408 | |
Harald Welte | 29aca17 | 2010-06-15 16:45:51 +0200 | [diff] [blame] | 409 | #define GSM48_HOCMD_CCHDESC_LEN 16 |
| 410 | |
Harald Welte | 8c83af6 | 2009-11-29 20:02:53 +0100 | [diff] [blame] | 411 | /* Chapter 9.1.15: Handover Command */ |
Harald Welte | 7a7a0d5 | 2009-12-17 00:25:18 +0100 | [diff] [blame] | 412 | int gsm48_send_ho_cmd(struct gsm_lchan *old_lchan, struct gsm_lchan *new_lchan, |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 413 | uint8_t power_command, uint8_t ho_ref) |
Harald Welte | 8c83af6 | 2009-11-29 20:02:53 +0100 | [diff] [blame] | 414 | { |
Holger Hans Peter Freyther | 8239e06 | 2016-01-25 22:03:25 +0100 | [diff] [blame] | 415 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 HO CMD"); |
Harald Welte | 8c83af6 | 2009-11-29 20:02:53 +0100 | [diff] [blame] | 416 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 417 | struct gsm48_ho_cmd *ho = |
| 418 | (struct gsm48_ho_cmd *) msgb_put(msg, sizeof(*ho)); |
Harald Welte | 8c83af6 | 2009-11-29 20:02:53 +0100 | [diff] [blame] | 419 | |
| 420 | msg->lchan = old_lchan; |
Harald Welte | 7a7a0d5 | 2009-12-17 00:25:18 +0100 | [diff] [blame] | 421 | gh->proto_discr = GSM48_PDISC_RR; |
| 422 | gh->msg_type = GSM48_MT_RR_HANDO_CMD; |
Harald Welte | 8c83af6 | 2009-11-29 20:02:53 +0100 | [diff] [blame] | 423 | |
| 424 | /* mandatory bits */ |
| 425 | gsm48_cell_desc(&ho->cell_desc, new_lchan->ts->trx->bts); |
Harald Welte | a39b0f2 | 2010-06-14 22:26:10 +0200 | [diff] [blame] | 426 | gsm48_lchan2chan_desc(&ho->chan_desc, new_lchan); |
Harald Welte | 7a7a0d5 | 2009-12-17 00:25:18 +0100 | [diff] [blame] | 427 | ho->ho_ref = ho_ref; |
Harald Welte | 8c83af6 | 2009-11-29 20:02:53 +0100 | [diff] [blame] | 428 | ho->power_command = power_command; |
| 429 | |
Harald Welte | 29aca17 | 2010-06-15 16:45:51 +0200 | [diff] [blame] | 430 | if (new_lchan->ts->hopping.enabled) { |
| 431 | struct gsm_bts *bts = new_lchan->ts->trx->bts; |
| 432 | struct gsm48_system_information_type_1 *si1; |
| 433 | uint8_t *cur; |
| 434 | |
| 435 | si1 = GSM_BTS_SI(bts, SYSINFO_TYPE_1); |
| 436 | /* Copy the Cell Chan Desc (ARFCNS in this cell) */ |
| 437 | msgb_put_u8(msg, GSM48_IE_CELL_CH_DESC); |
| 438 | cur = msgb_put(msg, GSM48_HOCMD_CCHDESC_LEN); |
| 439 | memcpy(cur, si1->cell_channel_description, |
| 440 | GSM48_HOCMD_CCHDESC_LEN); |
| 441 | /* Copy the Mobile Allocation */ |
| 442 | msgb_tlv_put(msg, GSM48_IE_MA_BEFORE, |
| 443 | new_lchan->ts->hopping.ma_len, |
| 444 | new_lchan->ts->hopping.ma_data); |
| 445 | } |
Harald Welte | 8c83af6 | 2009-11-29 20:02:53 +0100 | [diff] [blame] | 446 | /* FIXME: optional bits for type of synchronization? */ |
| 447 | |
Holger Hans Peter Freyther | 9c137a7 | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 448 | return gsm48_sendmsg(msg); |
Harald Welte | 8c83af6 | 2009-11-29 20:02:53 +0100 | [diff] [blame] | 449 | } |
| 450 | |
Holger Hans Peter Freyther | e81a610 | 2009-10-22 11:47:45 +0200 | [diff] [blame] | 451 | /* Chapter 9.1.2: Assignment Command */ |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 452 | int gsm48_send_rr_ass_cmd(struct gsm_lchan *dest_lchan, struct gsm_lchan *lchan, uint8_t power_command) |
Holger Hans Peter Freyther | e81a610 | 2009-10-22 11:47:45 +0200 | [diff] [blame] | 453 | { |
Holger Hans Peter Freyther | 8239e06 | 2016-01-25 22:03:25 +0100 | [diff] [blame] | 454 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 ASS CMD"); |
Holger Hans Peter Freyther | e81a610 | 2009-10-22 11:47:45 +0200 | [diff] [blame] | 455 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 456 | struct gsm48_ass_cmd *ass = |
| 457 | (struct gsm48_ass_cmd *) msgb_put(msg, sizeof(*ass)); |
Holger Hans Peter Freyther | e81a610 | 2009-10-22 11:47:45 +0200 | [diff] [blame] | 458 | |
| 459 | DEBUGP(DRR, "-> ASSIGNMENT COMMAND tch_mode=0x%02x\n", lchan->tch_mode); |
| 460 | |
Holger Hans Peter Freyther | 550197f | 2010-01-28 09:43:49 +0100 | [diff] [blame] | 461 | msg->lchan = dest_lchan; |
Holger Hans Peter Freyther | e81a610 | 2009-10-22 11:47:45 +0200 | [diff] [blame] | 462 | gh->proto_discr = GSM48_PDISC_RR; |
| 463 | gh->msg_type = GSM48_MT_RR_ASS_CMD; |
| 464 | |
| 465 | /* |
| 466 | * fill the channel information element, this code |
| 467 | * should probably be shared with rsl_rx_chan_rqd(), |
Max | 7a301d3 | 2016-04-07 11:38:52 +0200 | [diff] [blame] | 468 | * gsm48_lchan_modify(). But beware that 10.5.2.5 |
Holger Hans Peter Freyther | e81a610 | 2009-10-22 11:47:45 +0200 | [diff] [blame] | 469 | * 10.5.2.5.a have slightly different semantic for |
| 470 | * the chan_desc. But as long as multi-slot configurations |
| 471 | * are not used we seem to be fine. |
| 472 | */ |
Harald Welte | a39b0f2 | 2010-06-14 22:26:10 +0200 | [diff] [blame] | 473 | gsm48_lchan2chan_desc(&ass->chan_desc, lchan); |
Holger Hans Peter Freyther | e81a610 | 2009-10-22 11:47:45 +0200 | [diff] [blame] | 474 | ass->power_command = power_command; |
| 475 | |
Harald Welte | 29aca17 | 2010-06-15 16:45:51 +0200 | [diff] [blame] | 476 | /* optional: cell channel description */ |
| 477 | |
Holger Hans Peter Freyther | 1b891fd | 2010-01-28 11:51:24 +0100 | [diff] [blame] | 478 | msgb_tv_put(msg, GSM48_IE_CHANMODE_1, lchan->tch_mode); |
| 479 | |
Harald Welte | 29aca17 | 2010-06-15 16:45:51 +0200 | [diff] [blame] | 480 | /* mobile allocation in case of hopping */ |
| 481 | if (lchan->ts->hopping.enabled) { |
| 482 | msgb_tlv_put(msg, GSM48_IE_MA_BEFORE, lchan->ts->hopping.ma_len, |
| 483 | lchan->ts->hopping.ma_data); |
| 484 | } |
| 485 | |
Holger Hans Peter Freyther | a6bcc74 | 2009-11-16 22:49:24 +0100 | [diff] [blame] | 486 | /* in case of multi rate we need to attach a config */ |
Holger Hans Peter Freyther | 11cb7a9 | 2015-08-20 19:32:46 +0200 | [diff] [blame] | 487 | mr_config_for_ms(lchan, msg); |
Holger Hans Peter Freyther | a6bcc74 | 2009-11-16 22:49:24 +0100 | [diff] [blame] | 488 | |
Holger Hans Peter Freyther | 9c137a7 | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 489 | return gsm48_sendmsg(msg); |
Holger Hans Peter Freyther | e81a610 | 2009-10-22 11:47:45 +0200 | [diff] [blame] | 490 | } |
Holger Hans Peter Freyther | ff3f260 | 2009-10-22 15:13:00 +0200 | [diff] [blame] | 491 | |
| 492 | /* 9.1.5 Channel mode modify: Modify the mode on the MS side */ |
Max | 7a301d3 | 2016-04-07 11:38:52 +0200 | [diff] [blame] | 493 | int gsm48_lchan_modify(struct gsm_lchan *lchan, uint8_t mode) |
Holger Hans Peter Freyther | ff3f260 | 2009-10-22 15:13:00 +0200 | [diff] [blame] | 494 | { |
Holger Hans Peter Freyther | 8239e06 | 2016-01-25 22:03:25 +0100 | [diff] [blame] | 495 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 CHN MOD"); |
Holger Hans Peter Freyther | ff3f260 | 2009-10-22 15:13:00 +0200 | [diff] [blame] | 496 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 497 | struct gsm48_chan_mode_modify *cmm = |
| 498 | (struct gsm48_chan_mode_modify *) msgb_put(msg, sizeof(*cmm)); |
Holger Hans Peter Freyther | ff3f260 | 2009-10-22 15:13:00 +0200 | [diff] [blame] | 499 | |
| 500 | DEBUGP(DRR, "-> CHANNEL MODE MODIFY mode=0x%02x\n", mode); |
| 501 | |
| 502 | lchan->tch_mode = mode; |
| 503 | msg->lchan = lchan; |
| 504 | gh->proto_discr = GSM48_PDISC_RR; |
| 505 | gh->msg_type = GSM48_MT_RR_CHAN_MODE_MODIF; |
| 506 | |
| 507 | /* fill the channel information element, this code |
| 508 | * should probably be shared with rsl_rx_chan_rqd() */ |
Harald Welte | a39b0f2 | 2010-06-14 22:26:10 +0200 | [diff] [blame] | 509 | gsm48_lchan2chan_desc(&cmm->chan_desc, lchan); |
Holger Hans Peter Freyther | ff3f260 | 2009-10-22 15:13:00 +0200 | [diff] [blame] | 510 | cmm->mode = mode; |
| 511 | |
Holger Hans Peter Freyther | a6bcc74 | 2009-11-16 22:49:24 +0100 | [diff] [blame] | 512 | /* in case of multi rate we need to attach a config */ |
Holger Hans Peter Freyther | 11cb7a9 | 2015-08-20 19:32:46 +0200 | [diff] [blame] | 513 | mr_config_for_ms(lchan, msg); |
Holger Hans Peter Freyther | a6bcc74 | 2009-11-16 22:49:24 +0100 | [diff] [blame] | 514 | |
Holger Hans Peter Freyther | 9c137a7 | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 515 | return gsm48_sendmsg(msg); |
Holger Hans Peter Freyther | ff3f260 | 2009-10-22 15:13:00 +0200 | [diff] [blame] | 516 | } |
| 517 | |
Holger Hans Peter Freyther | f520e64 | 2009-10-22 15:23:11 +0200 | [diff] [blame] | 518 | int gsm48_rx_rr_modif_ack(struct msgb *msg) |
| 519 | { |
Holger Hans Peter Freyther | 25b1e25 | 2009-11-18 19:30:24 +0100 | [diff] [blame] | 520 | int rc; |
Holger Hans Peter Freyther | f520e64 | 2009-10-22 15:23:11 +0200 | [diff] [blame] | 521 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 522 | struct gsm48_chan_mode_modify *mod = |
| 523 | (struct gsm48_chan_mode_modify *) gh->data; |
| 524 | |
| 525 | DEBUGP(DRR, "CHANNEL MODE MODIFY ACK\n"); |
| 526 | |
| 527 | if (mod->mode != msg->lchan->tch_mode) { |
Harald Welte | 50720e7 | 2009-12-24 11:50:20 +0100 | [diff] [blame] | 528 | LOGP(DRR, LOGL_ERROR, "CHANNEL MODE change failed. Wanted: %d Got: %d\n", |
Holger Hans Peter Freyther | f520e64 | 2009-10-22 15:23:11 +0200 | [diff] [blame] | 529 | msg->lchan->tch_mode, mod->mode); |
| 530 | return -1; |
| 531 | } |
| 532 | |
| 533 | /* update the channel type */ |
| 534 | switch (mod->mode) { |
| 535 | case GSM48_CMODE_SIGN: |
| 536 | msg->lchan->rsl_cmode = RSL_CMOD_SPD_SIGN; |
| 537 | break; |
| 538 | case GSM48_CMODE_SPEECH_V1: |
| 539 | case GSM48_CMODE_SPEECH_EFR: |
| 540 | case GSM48_CMODE_SPEECH_AMR: |
| 541 | msg->lchan->rsl_cmode = RSL_CMOD_SPD_SPEECH; |
| 542 | break; |
| 543 | case GSM48_CMODE_DATA_14k5: |
| 544 | case GSM48_CMODE_DATA_12k0: |
| 545 | case GSM48_CMODE_DATA_6k0: |
| 546 | case GSM48_CMODE_DATA_3k6: |
| 547 | msg->lchan->rsl_cmode = RSL_CMOD_SPD_DATA; |
| 548 | break; |
| 549 | } |
| 550 | |
| 551 | /* We've successfully modified the MS side of the channel, |
| 552 | * now go on to modify the BTS side of the channel */ |
Holger Hans Peter Freyther | 25b1e25 | 2009-11-18 19:30:24 +0100 | [diff] [blame] | 553 | rc = rsl_chan_mode_modify_req(msg->lchan); |
| 554 | |
| 555 | /* FIXME: we not only need to do this after mode modify, but |
| 556 | * also after channel activation */ |
| 557 | if (is_ipaccess_bts(msg->lchan->ts->trx->bts) && mod->mode != GSM48_CMODE_SIGN) |
| 558 | rsl_ipacc_crcx(msg->lchan); |
| 559 | return rc; |
Holger Hans Peter Freyther | f520e64 | 2009-10-22 15:23:11 +0200 | [diff] [blame] | 560 | } |
Holger Hans Peter Freyther | 92ffd92 | 2009-12-22 07:45:17 +0100 | [diff] [blame] | 561 | |
| 562 | int gsm48_parse_meas_rep(struct gsm_meas_rep *rep, struct msgb *msg) |
| 563 | { |
| 564 | struct gsm48_hdr *gh = msgb_l3(msg); |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 565 | uint8_t *data = gh->data; |
Holger Hans Peter Freyther | 92ffd92 | 2009-12-22 07:45:17 +0100 | [diff] [blame] | 566 | struct gsm_bts *bts = msg->lchan->ts->trx->bts; |
| 567 | struct bitvec *nbv = &bts->si_common.neigh_list; |
Harald Welte | a06c35e | 2009-12-25 22:46:25 +0100 | [diff] [blame] | 568 | struct gsm_meas_rep_cell *mrc; |
Holger Hans Peter Freyther | 92ffd92 | 2009-12-22 07:45:17 +0100 | [diff] [blame] | 569 | |
| 570 | if (gh->msg_type != GSM48_MT_RR_MEAS_REP) |
| 571 | return -EINVAL; |
| 572 | |
| 573 | if (data[0] & 0x80) |
| 574 | rep->flags |= MEAS_REP_F_BA1; |
| 575 | if (data[0] & 0x40) |
| 576 | rep->flags |= MEAS_REP_F_UL_DTX; |
| 577 | if ((data[1] & 0x40) == 0x00) |
| 578 | rep->flags |= MEAS_REP_F_DL_VALID; |
| 579 | |
| 580 | rep->dl.full.rx_lev = data[0] & 0x3f; |
| 581 | rep->dl.sub.rx_lev = data[1] & 0x3f; |
Sylvain Munaut | 48ea4e8 | 2012-12-25 13:06:27 +0100 | [diff] [blame] | 582 | rep->dl.full.rx_qual = (data[2] >> 4) & 0x7; |
| 583 | rep->dl.sub.rx_qual = (data[2] >> 1) & 0x7; |
Holger Hans Peter Freyther | 92ffd92 | 2009-12-22 07:45:17 +0100 | [diff] [blame] | 584 | |
| 585 | rep->num_cell = ((data[3] >> 6) & 0x3) | ((data[2] & 0x01) << 2); |
| 586 | if (rep->num_cell < 1 || rep->num_cell > 6) |
| 587 | return 0; |
| 588 | |
| 589 | /* an encoding nightmare in perfection */ |
Harald Welte | a06c35e | 2009-12-25 22:46:25 +0100 | [diff] [blame] | 590 | mrc = &rep->cell[0]; |
| 591 | mrc->rxlev = data[3] & 0x3f; |
Harald Welte | 950eca9 | 2009-12-25 22:49:34 +0100 | [diff] [blame] | 592 | mrc->neigh_idx = data[4] >> 3; |
Harald Welte | eaa95d5 | 2009-12-25 23:01:54 +0100 | [diff] [blame] | 593 | mrc->arfcn = bitvec_get_nth_set_bit(nbv, mrc->neigh_idx + 1); |
Harald Welte | a06c35e | 2009-12-25 22:46:25 +0100 | [diff] [blame] | 594 | mrc->bsic = ((data[4] & 0x07) << 3) | (data[5] >> 5); |
Holger Hans Peter Freyther | 92ffd92 | 2009-12-22 07:45:17 +0100 | [diff] [blame] | 595 | if (rep->num_cell < 2) |
| 596 | return 0; |
| 597 | |
Harald Welte | a06c35e | 2009-12-25 22:46:25 +0100 | [diff] [blame] | 598 | mrc = &rep->cell[1]; |
| 599 | mrc->rxlev = ((data[5] & 0x1f) << 1) | (data[6] >> 7); |
Harald Welte | 950eca9 | 2009-12-25 22:49:34 +0100 | [diff] [blame] | 600 | mrc->neigh_idx = (data[6] >> 2) & 0x1f; |
Harald Welte | eaa95d5 | 2009-12-25 23:01:54 +0100 | [diff] [blame] | 601 | mrc->arfcn = bitvec_get_nth_set_bit(nbv, mrc->neigh_idx + 1); |
Harald Welte | a06c35e | 2009-12-25 22:46:25 +0100 | [diff] [blame] | 602 | mrc->bsic = ((data[6] & 0x03) << 4) | (data[7] >> 4); |
Holger Hans Peter Freyther | 92ffd92 | 2009-12-22 07:45:17 +0100 | [diff] [blame] | 603 | if (rep->num_cell < 3) |
| 604 | return 0; |
| 605 | |
Harald Welte | a06c35e | 2009-12-25 22:46:25 +0100 | [diff] [blame] | 606 | mrc = &rep->cell[2]; |
| 607 | mrc->rxlev = ((data[7] & 0x0f) << 2) | (data[8] >> 6); |
Harald Welte | 950eca9 | 2009-12-25 22:49:34 +0100 | [diff] [blame] | 608 | mrc->neigh_idx = (data[8] >> 1) & 0x1f; |
Harald Welte | eaa95d5 | 2009-12-25 23:01:54 +0100 | [diff] [blame] | 609 | mrc->arfcn = bitvec_get_nth_set_bit(nbv, mrc->neigh_idx + 1); |
Harald Welte (local) | 6589858 | 2009-12-26 14:12:43 +0100 | [diff] [blame] | 610 | mrc->bsic = ((data[8] & 0x01) << 5) | (data[9] >> 3); |
Holger Hans Peter Freyther | 92ffd92 | 2009-12-22 07:45:17 +0100 | [diff] [blame] | 611 | if (rep->num_cell < 4) |
| 612 | return 0; |
| 613 | |
Harald Welte | a06c35e | 2009-12-25 22:46:25 +0100 | [diff] [blame] | 614 | mrc = &rep->cell[3]; |
| 615 | mrc->rxlev = ((data[9] & 0x07) << 3) | (data[10] >> 5); |
Harald Welte | 950eca9 | 2009-12-25 22:49:34 +0100 | [diff] [blame] | 616 | mrc->neigh_idx = data[10] & 0x1f; |
Harald Welte | eaa95d5 | 2009-12-25 23:01:54 +0100 | [diff] [blame] | 617 | mrc->arfcn = bitvec_get_nth_set_bit(nbv, mrc->neigh_idx + 1); |
Harald Welte | a06c35e | 2009-12-25 22:46:25 +0100 | [diff] [blame] | 618 | mrc->bsic = data[11] >> 2; |
Holger Hans Peter Freyther | 92ffd92 | 2009-12-22 07:45:17 +0100 | [diff] [blame] | 619 | if (rep->num_cell < 5) |
| 620 | return 0; |
| 621 | |
Harald Welte | a06c35e | 2009-12-25 22:46:25 +0100 | [diff] [blame] | 622 | mrc = &rep->cell[4]; |
| 623 | mrc->rxlev = ((data[11] & 0x03) << 4) | (data[12] >> 4); |
Harald Welte | 950eca9 | 2009-12-25 22:49:34 +0100 | [diff] [blame] | 624 | mrc->neigh_idx = ((data[12] & 0xf) << 1) | (data[13] >> 7); |
Harald Welte | eaa95d5 | 2009-12-25 23:01:54 +0100 | [diff] [blame] | 625 | mrc->arfcn = bitvec_get_nth_set_bit(nbv, mrc->neigh_idx + 1); |
Harald Welte | a06c35e | 2009-12-25 22:46:25 +0100 | [diff] [blame] | 626 | mrc->bsic = (data[13] >> 1) & 0x3f; |
Holger Hans Peter Freyther | 92ffd92 | 2009-12-22 07:45:17 +0100 | [diff] [blame] | 627 | if (rep->num_cell < 6) |
| 628 | return 0; |
| 629 | |
Harald Welte | a06c35e | 2009-12-25 22:46:25 +0100 | [diff] [blame] | 630 | mrc = &rep->cell[5]; |
Harald Welte | 950eca9 | 2009-12-25 22:49:34 +0100 | [diff] [blame] | 631 | mrc->rxlev = ((data[13] & 0x01) << 5) | (data[14] >> 3); |
| 632 | mrc->neigh_idx = ((data[14] & 0x07) << 2) | (data[15] >> 6); |
Harald Welte | eaa95d5 | 2009-12-25 23:01:54 +0100 | [diff] [blame] | 633 | mrc->arfcn = bitvec_get_nth_set_bit(nbv, mrc->neigh_idx + 1); |
Harald Welte | a06c35e | 2009-12-25 22:46:25 +0100 | [diff] [blame] | 634 | mrc->bsic = data[15] & 0x3f; |
Holger Hans Peter Freyther | 92ffd92 | 2009-12-22 07:45:17 +0100 | [diff] [blame] | 635 | |
| 636 | return 0; |
| 637 | } |
Holger Hans Peter Freyther | 2c0f166 | 2010-06-15 19:39:27 +0800 | [diff] [blame] | 638 | |
Jacob Erlbeck | 24d3b91 | 2013-10-31 15:36:41 +0100 | [diff] [blame] | 639 | /* 9.2.5 CM service accept */ |
| 640 | int gsm48_tx_mm_serv_ack(struct gsm_subscriber_connection *conn) |
| 641 | { |
Holger Hans Peter Freyther | 8239e06 | 2016-01-25 22:03:25 +0100 | [diff] [blame] | 642 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 SERV ACK"); |
Jacob Erlbeck | 24d3b91 | 2013-10-31 15:36:41 +0100 | [diff] [blame] | 643 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 644 | |
| 645 | msg->lchan = conn->lchan; |
| 646 | |
| 647 | gh->proto_discr = GSM48_PDISC_MM; |
| 648 | gh->msg_type = GSM48_MT_MM_CM_SERV_ACC; |
| 649 | |
| 650 | DEBUGP(DMM, "-> CM SERVICE ACK\n"); |
| 651 | |
| 652 | return gsm0808_submit_dtap(conn, msg, 0, 0); |
| 653 | } |
| 654 | |
| 655 | /* 9.2.6 CM service reject */ |
| 656 | int gsm48_tx_mm_serv_rej(struct gsm_subscriber_connection *conn, |
| 657 | enum gsm48_reject_value value) |
| 658 | { |
| 659 | struct msgb *msg; |
| 660 | |
| 661 | msg = gsm48_create_mm_serv_rej(value); |
| 662 | if (!msg) { |
| 663 | LOGP(DMM, LOGL_ERROR, "Failed to allocate CM Service Reject.\n"); |
| 664 | return -1; |
| 665 | } |
| 666 | |
| 667 | DEBUGP(DMM, "-> CM SERVICE Reject cause: %d\n", value); |
| 668 | |
| 669 | return gsm0808_submit_dtap(conn, msg, 0, 0); |
| 670 | } |