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