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, |
| 286 | struct msgb *msg, struct gsm_subscriber *subscr) |
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 | |
Holger Hans Peter Freyther | db4ef0d | 2010-06-21 10:46:44 +0800 | [diff] [blame] | 295 | if (!conn->subscr) { |
| 296 | conn->subscr = subscr; |
| 297 | } else if (conn->subscr != subscr) { |
Harald Welte | 50720e7 | 2009-12-24 11:50:20 +0100 | [diff] [blame] | 298 | LOGP(DRR, LOGL_ERROR, "<- Channel already owned by someone else?\n"); |
Holger Hans Peter Freyther | 3ee5d3e | 2009-08-21 05:18:21 +0200 | [diff] [blame] | 299 | subscr_put(subscr); |
| 300 | return -EINVAL; |
| 301 | } else { |
| 302 | DEBUGP(DRR, "<- Channel already owned by us\n"); |
| 303 | subscr_put(subscr); |
Holger Hans Peter Freyther | db4ef0d | 2010-06-21 10:46:44 +0800 | [diff] [blame] | 304 | subscr = conn->subscr; |
Holger Hans Peter Freyther | 3ee5d3e | 2009-08-21 05:18:21 +0200 | [diff] [blame] | 305 | } |
| 306 | |
Alexander Couzens | b847a21 | 2016-08-02 11:34:11 +0200 | [diff] [blame^] | 307 | rate_ctr_inc(&bts->network->bsc_ctrs->ctr[BSC_CTR_PAGING_COMPLETED]); |
Harald Welte | 24ff6ee | 2009-12-22 00:41:05 +0100 | [diff] [blame] | 308 | |
Holger Hans Peter Freyther | 3ee5d3e | 2009-08-21 05:18:21 +0200 | [diff] [blame] | 309 | /* Stop paging on the bts we received the paging response */ |
Sylvain Munaut | c7ff257 | 2010-12-01 21:41:35 +0100 | [diff] [blame] | 310 | paging_request_stop(conn->bts, subscr, conn, msg); |
Holger Hans Peter Freyther | 3ee5d3e | 2009-08-21 05:18:21 +0200 | [diff] [blame] | 311 | return 0; |
| 312 | } |
Holger Hans Peter Freyther | ea4088a | 2009-10-05 13:25:06 +0200 | [diff] [blame] | 313 | |
| 314 | /* Chapter 9.1.9: Ciphering Mode Command */ |
Holger Hans Peter Freyther | ca6bc1d | 2009-10-05 14:00:14 +0200 | [diff] [blame] | 315 | 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] | 316 | { |
Holger Hans Peter Freyther | 8239e06 | 2016-01-25 22:03:25 +0100 | [diff] [blame] | 317 | 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] | 318 | struct gsm48_hdr *gh; |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 319 | uint8_t ciph_mod_set; |
Holger Hans Peter Freyther | ea4088a | 2009-10-05 13:25:06 +0200 | [diff] [blame] | 320 | |
| 321 | msg->lchan = lchan; |
| 322 | |
| 323 | DEBUGP(DRR, "TX CIPHERING MODE CMD\n"); |
| 324 | |
| 325 | if (lchan->encr.alg_id <= RSL_ENC_ALG_A5(0)) |
| 326 | ciph_mod_set = 0; |
| 327 | else |
| 328 | ciph_mod_set = (lchan->encr.alg_id-2)<<1 | 1; |
| 329 | |
| 330 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 1); |
| 331 | gh->proto_discr = GSM48_PDISC_RR; |
| 332 | gh->msg_type = GSM48_MT_RR_CIPH_M_CMD; |
Holger Hans Peter Freyther | ca6bc1d | 2009-10-05 14:00:14 +0200 | [diff] [blame] | 333 | 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] | 334 | |
| 335 | return rsl_encryption_cmd(msg); |
| 336 | } |
| 337 | |
Harald Welte | 8c83af6 | 2009-11-29 20:02:53 +0100 | [diff] [blame] | 338 | static void gsm48_cell_desc(struct gsm48_cell_desc *cd, |
| 339 | const struct gsm_bts *bts) |
| 340 | { |
| 341 | cd->ncc = (bts->bsic >> 3 & 0x7); |
| 342 | cd->bcc = (bts->bsic & 0x7); |
| 343 | cd->arfcn_hi = bts->c0->arfcn >> 8; |
| 344 | cd->arfcn_lo = bts->c0->arfcn & 0xff; |
| 345 | } |
| 346 | |
Harald Welte | a39b0f2 | 2010-06-14 22:26:10 +0200 | [diff] [blame] | 347 | void gsm48_lchan2chan_desc(struct gsm48_chan_desc *cd, |
| 348 | const struct gsm_lchan *lchan) |
Harald Welte | 8c83af6 | 2009-11-29 20:02:53 +0100 | [diff] [blame] | 349 | { |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 350 | uint16_t arfcn = lchan->ts->trx->arfcn & 0x3ff; |
Harald Welte | 8c83af6 | 2009-11-29 20:02:53 +0100 | [diff] [blame] | 351 | |
Harald Welte | f6093a4 | 2011-06-25 10:02:33 +0200 | [diff] [blame] | 352 | cd->chan_nr = gsm_lchan2chan_nr(lchan); |
Harald Welte | a39b0f2 | 2010-06-14 22:26:10 +0200 | [diff] [blame] | 353 | if (!lchan->ts->hopping.enabled) { |
Harald Welte | 1fe2412 | 2014-01-19 17:18:21 +0100 | [diff] [blame] | 354 | cd->h0.tsc = gsm_ts_tsc(lchan->ts); |
Harald Welte | a39b0f2 | 2010-06-14 22:26:10 +0200 | [diff] [blame] | 355 | cd->h0.h = 0; |
| 356 | cd->h0.arfcn_high = arfcn >> 8; |
| 357 | cd->h0.arfcn_low = arfcn & 0xff; |
| 358 | } else { |
Harald Welte | 1fe2412 | 2014-01-19 17:18:21 +0100 | [diff] [blame] | 359 | cd->h1.tsc = gsm_ts_tsc(lchan->ts); |
Harald Welte | a39b0f2 | 2010-06-14 22:26:10 +0200 | [diff] [blame] | 360 | cd->h1.h = 1; |
| 361 | cd->h1.maio_high = lchan->ts->hopping.maio >> 2; |
| 362 | cd->h1.maio_low = lchan->ts->hopping.maio & 0x03; |
| 363 | cd->h1.hsn = lchan->ts->hopping.hsn; |
| 364 | } |
Harald Welte | 8c83af6 | 2009-11-29 20:02:53 +0100 | [diff] [blame] | 365 | } |
| 366 | |
Holger Hans Peter Freyther | 615ed46 | 2015-09-24 11:30:58 +0200 | [diff] [blame] | 367 | 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] | 368 | { |
| 369 | int num = 0, i; |
| 370 | |
| 371 | for (i = 0; i < 8; i++) { |
| 372 | if (((mr->gsm48_ie[1] >> i) & 1)) |
| 373 | num++; |
| 374 | } |
| 375 | if (num > 4) { |
| 376 | LOGP(DRR, LOGL_ERROR, "BUG: Using multirate codec with too " |
| 377 | "many modes in config.\n"); |
| 378 | num = 4; |
| 379 | } |
| 380 | if (num < 1) { |
| 381 | LOGP(DRR, LOGL_ERROR, "BUG: Using multirate codec with no " |
| 382 | "mode in config.\n"); |
| 383 | num = 1; |
| 384 | } |
| 385 | |
| 386 | lv[0] = (num == 1) ? 2 : (num + 2); |
| 387 | memcpy(lv + 1, mr->gsm48_ie, 2); |
| 388 | if (num == 1) |
| 389 | return 0; |
Holger Hans Peter Freyther | 615ed46 | 2015-09-24 11:30:58 +0200 | [diff] [blame] | 390 | |
| 391 | lv[3] = modes[0].threshold & 0x3f; |
| 392 | lv[4] = modes[0].hysteresis << 4; |
| 393 | if (num == 2) |
| 394 | return 0; |
| 395 | lv[4] |= (modes[1].threshold & 0x3f) >> 2; |
| 396 | lv[5] = modes[1].threshold << 6; |
| 397 | lv[5] |= (modes[1].hysteresis & 0x0f) << 2; |
| 398 | if (num == 3) |
| 399 | return 0; |
| 400 | lv[5] |= (modes[2].threshold & 0x3f) >> 4; |
| 401 | lv[6] = modes[2].threshold << 4; |
| 402 | lv[6] |= modes[2].hysteresis & 0x0f; |
Andreas Eversberg | 7326652 | 2014-01-19 11:47:44 +0100 | [diff] [blame] | 403 | |
| 404 | return 0; |
| 405 | } |
| 406 | |
Harald Welte | 29aca17 | 2010-06-15 16:45:51 +0200 | [diff] [blame] | 407 | #define GSM48_HOCMD_CCHDESC_LEN 16 |
| 408 | |
Harald Welte | 8c83af6 | 2009-11-29 20:02:53 +0100 | [diff] [blame] | 409 | /* Chapter 9.1.15: Handover Command */ |
Harald Welte | 7a7a0d5 | 2009-12-17 00:25:18 +0100 | [diff] [blame] | 410 | 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] | 411 | uint8_t power_command, uint8_t ho_ref) |
Harald Welte | 8c83af6 | 2009-11-29 20:02:53 +0100 | [diff] [blame] | 412 | { |
Holger Hans Peter Freyther | 8239e06 | 2016-01-25 22:03:25 +0100 | [diff] [blame] | 413 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 HO CMD"); |
Harald Welte | 8c83af6 | 2009-11-29 20:02:53 +0100 | [diff] [blame] | 414 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 415 | struct gsm48_ho_cmd *ho = |
| 416 | (struct gsm48_ho_cmd *) msgb_put(msg, sizeof(*ho)); |
Harald Welte | 8c83af6 | 2009-11-29 20:02:53 +0100 | [diff] [blame] | 417 | |
| 418 | msg->lchan = old_lchan; |
Harald Welte | 7a7a0d5 | 2009-12-17 00:25:18 +0100 | [diff] [blame] | 419 | gh->proto_discr = GSM48_PDISC_RR; |
| 420 | gh->msg_type = GSM48_MT_RR_HANDO_CMD; |
Harald Welte | 8c83af6 | 2009-11-29 20:02:53 +0100 | [diff] [blame] | 421 | |
| 422 | /* mandatory bits */ |
| 423 | gsm48_cell_desc(&ho->cell_desc, new_lchan->ts->trx->bts); |
Harald Welte | a39b0f2 | 2010-06-14 22:26:10 +0200 | [diff] [blame] | 424 | gsm48_lchan2chan_desc(&ho->chan_desc, new_lchan); |
Harald Welte | 7a7a0d5 | 2009-12-17 00:25:18 +0100 | [diff] [blame] | 425 | ho->ho_ref = ho_ref; |
Harald Welte | 8c83af6 | 2009-11-29 20:02:53 +0100 | [diff] [blame] | 426 | ho->power_command = power_command; |
| 427 | |
Harald Welte | 29aca17 | 2010-06-15 16:45:51 +0200 | [diff] [blame] | 428 | if (new_lchan->ts->hopping.enabled) { |
| 429 | struct gsm_bts *bts = new_lchan->ts->trx->bts; |
| 430 | struct gsm48_system_information_type_1 *si1; |
| 431 | uint8_t *cur; |
| 432 | |
| 433 | si1 = GSM_BTS_SI(bts, SYSINFO_TYPE_1); |
| 434 | /* Copy the Cell Chan Desc (ARFCNS in this cell) */ |
| 435 | msgb_put_u8(msg, GSM48_IE_CELL_CH_DESC); |
| 436 | cur = msgb_put(msg, GSM48_HOCMD_CCHDESC_LEN); |
| 437 | memcpy(cur, si1->cell_channel_description, |
| 438 | GSM48_HOCMD_CCHDESC_LEN); |
| 439 | /* Copy the Mobile Allocation */ |
| 440 | msgb_tlv_put(msg, GSM48_IE_MA_BEFORE, |
| 441 | new_lchan->ts->hopping.ma_len, |
| 442 | new_lchan->ts->hopping.ma_data); |
| 443 | } |
Harald Welte | 8c83af6 | 2009-11-29 20:02:53 +0100 | [diff] [blame] | 444 | /* FIXME: optional bits for type of synchronization? */ |
| 445 | |
Holger Hans Peter Freyther | 9c137a7 | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 446 | return gsm48_sendmsg(msg); |
Harald Welte | 8c83af6 | 2009-11-29 20:02:53 +0100 | [diff] [blame] | 447 | } |
| 448 | |
Holger Hans Peter Freyther | e81a610 | 2009-10-22 11:47:45 +0200 | [diff] [blame] | 449 | /* Chapter 9.1.2: Assignment Command */ |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 450 | 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] | 451 | { |
Holger Hans Peter Freyther | 8239e06 | 2016-01-25 22:03:25 +0100 | [diff] [blame] | 452 | 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] | 453 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 454 | struct gsm48_ass_cmd *ass = |
| 455 | (struct gsm48_ass_cmd *) msgb_put(msg, sizeof(*ass)); |
Holger Hans Peter Freyther | e81a610 | 2009-10-22 11:47:45 +0200 | [diff] [blame] | 456 | |
| 457 | DEBUGP(DRR, "-> ASSIGNMENT COMMAND tch_mode=0x%02x\n", lchan->tch_mode); |
| 458 | |
Holger Hans Peter Freyther | 550197f | 2010-01-28 09:43:49 +0100 | [diff] [blame] | 459 | msg->lchan = dest_lchan; |
Holger Hans Peter Freyther | e81a610 | 2009-10-22 11:47:45 +0200 | [diff] [blame] | 460 | gh->proto_discr = GSM48_PDISC_RR; |
| 461 | gh->msg_type = GSM48_MT_RR_ASS_CMD; |
| 462 | |
| 463 | /* |
| 464 | * fill the channel information element, this code |
| 465 | * should probably be shared with rsl_rx_chan_rqd(), |
Max | 7a301d3 | 2016-04-07 11:38:52 +0200 | [diff] [blame] | 466 | * gsm48_lchan_modify(). But beware that 10.5.2.5 |
Holger Hans Peter Freyther | e81a610 | 2009-10-22 11:47:45 +0200 | [diff] [blame] | 467 | * 10.5.2.5.a have slightly different semantic for |
| 468 | * the chan_desc. But as long as multi-slot configurations |
| 469 | * are not used we seem to be fine. |
| 470 | */ |
Harald Welte | a39b0f2 | 2010-06-14 22:26:10 +0200 | [diff] [blame] | 471 | gsm48_lchan2chan_desc(&ass->chan_desc, lchan); |
Holger Hans Peter Freyther | e81a610 | 2009-10-22 11:47:45 +0200 | [diff] [blame] | 472 | ass->power_command = power_command; |
| 473 | |
Harald Welte | 29aca17 | 2010-06-15 16:45:51 +0200 | [diff] [blame] | 474 | /* optional: cell channel description */ |
| 475 | |
Holger Hans Peter Freyther | 1b891fd | 2010-01-28 11:51:24 +0100 | [diff] [blame] | 476 | msgb_tv_put(msg, GSM48_IE_CHANMODE_1, lchan->tch_mode); |
| 477 | |
Harald Welte | 29aca17 | 2010-06-15 16:45:51 +0200 | [diff] [blame] | 478 | /* mobile allocation in case of hopping */ |
| 479 | if (lchan->ts->hopping.enabled) { |
| 480 | msgb_tlv_put(msg, GSM48_IE_MA_BEFORE, lchan->ts->hopping.ma_len, |
| 481 | lchan->ts->hopping.ma_data); |
| 482 | } |
| 483 | |
Holger Hans Peter Freyther | a6bcc74 | 2009-11-16 22:49:24 +0100 | [diff] [blame] | 484 | /* 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] | 485 | mr_config_for_ms(lchan, msg); |
Holger Hans Peter Freyther | a6bcc74 | 2009-11-16 22:49:24 +0100 | [diff] [blame] | 486 | |
Holger Hans Peter Freyther | 9c137a7 | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 487 | return gsm48_sendmsg(msg); |
Holger Hans Peter Freyther | e81a610 | 2009-10-22 11:47:45 +0200 | [diff] [blame] | 488 | } |
Holger Hans Peter Freyther | ff3f260 | 2009-10-22 15:13:00 +0200 | [diff] [blame] | 489 | |
| 490 | /* 9.1.5 Channel mode modify: Modify the mode on the MS side */ |
Max | 7a301d3 | 2016-04-07 11:38:52 +0200 | [diff] [blame] | 491 | 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] | 492 | { |
Holger Hans Peter Freyther | 8239e06 | 2016-01-25 22:03:25 +0100 | [diff] [blame] | 493 | 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] | 494 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 495 | struct gsm48_chan_mode_modify *cmm = |
| 496 | (struct gsm48_chan_mode_modify *) msgb_put(msg, sizeof(*cmm)); |
Holger Hans Peter Freyther | ff3f260 | 2009-10-22 15:13:00 +0200 | [diff] [blame] | 497 | |
| 498 | DEBUGP(DRR, "-> CHANNEL MODE MODIFY mode=0x%02x\n", mode); |
| 499 | |
| 500 | lchan->tch_mode = mode; |
| 501 | msg->lchan = lchan; |
| 502 | gh->proto_discr = GSM48_PDISC_RR; |
| 503 | gh->msg_type = GSM48_MT_RR_CHAN_MODE_MODIF; |
| 504 | |
| 505 | /* fill the channel information element, this code |
| 506 | * should probably be shared with rsl_rx_chan_rqd() */ |
Harald Welte | a39b0f2 | 2010-06-14 22:26:10 +0200 | [diff] [blame] | 507 | gsm48_lchan2chan_desc(&cmm->chan_desc, lchan); |
Holger Hans Peter Freyther | ff3f260 | 2009-10-22 15:13:00 +0200 | [diff] [blame] | 508 | cmm->mode = mode; |
| 509 | |
Holger Hans Peter Freyther | a6bcc74 | 2009-11-16 22:49:24 +0100 | [diff] [blame] | 510 | /* 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] | 511 | mr_config_for_ms(lchan, msg); |
Holger Hans Peter Freyther | a6bcc74 | 2009-11-16 22:49:24 +0100 | [diff] [blame] | 512 | |
Holger Hans Peter Freyther | 9c137a7 | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 513 | return gsm48_sendmsg(msg); |
Holger Hans Peter Freyther | ff3f260 | 2009-10-22 15:13:00 +0200 | [diff] [blame] | 514 | } |
| 515 | |
Holger Hans Peter Freyther | f520e64 | 2009-10-22 15:23:11 +0200 | [diff] [blame] | 516 | int gsm48_rx_rr_modif_ack(struct msgb *msg) |
| 517 | { |
Holger Hans Peter Freyther | 25b1e25 | 2009-11-18 19:30:24 +0100 | [diff] [blame] | 518 | int rc; |
Holger Hans Peter Freyther | f520e64 | 2009-10-22 15:23:11 +0200 | [diff] [blame] | 519 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 520 | struct gsm48_chan_mode_modify *mod = |
| 521 | (struct gsm48_chan_mode_modify *) gh->data; |
| 522 | |
| 523 | DEBUGP(DRR, "CHANNEL MODE MODIFY ACK\n"); |
| 524 | |
| 525 | if (mod->mode != msg->lchan->tch_mode) { |
Harald Welte | 50720e7 | 2009-12-24 11:50:20 +0100 | [diff] [blame] | 526 | 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] | 527 | msg->lchan->tch_mode, mod->mode); |
| 528 | return -1; |
| 529 | } |
| 530 | |
| 531 | /* update the channel type */ |
| 532 | switch (mod->mode) { |
| 533 | case GSM48_CMODE_SIGN: |
| 534 | msg->lchan->rsl_cmode = RSL_CMOD_SPD_SIGN; |
| 535 | break; |
| 536 | case GSM48_CMODE_SPEECH_V1: |
| 537 | case GSM48_CMODE_SPEECH_EFR: |
| 538 | case GSM48_CMODE_SPEECH_AMR: |
| 539 | msg->lchan->rsl_cmode = RSL_CMOD_SPD_SPEECH; |
| 540 | break; |
| 541 | case GSM48_CMODE_DATA_14k5: |
| 542 | case GSM48_CMODE_DATA_12k0: |
| 543 | case GSM48_CMODE_DATA_6k0: |
| 544 | case GSM48_CMODE_DATA_3k6: |
| 545 | msg->lchan->rsl_cmode = RSL_CMOD_SPD_DATA; |
| 546 | break; |
| 547 | } |
| 548 | |
| 549 | /* We've successfully modified the MS side of the channel, |
| 550 | * 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] | 551 | rc = rsl_chan_mode_modify_req(msg->lchan); |
| 552 | |
| 553 | /* FIXME: we not only need to do this after mode modify, but |
| 554 | * also after channel activation */ |
| 555 | if (is_ipaccess_bts(msg->lchan->ts->trx->bts) && mod->mode != GSM48_CMODE_SIGN) |
| 556 | rsl_ipacc_crcx(msg->lchan); |
| 557 | return rc; |
Holger Hans Peter Freyther | f520e64 | 2009-10-22 15:23:11 +0200 | [diff] [blame] | 558 | } |
Holger Hans Peter Freyther | 92ffd92 | 2009-12-22 07:45:17 +0100 | [diff] [blame] | 559 | |
| 560 | int gsm48_parse_meas_rep(struct gsm_meas_rep *rep, struct msgb *msg) |
| 561 | { |
| 562 | struct gsm48_hdr *gh = msgb_l3(msg); |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 563 | uint8_t *data = gh->data; |
Holger Hans Peter Freyther | 92ffd92 | 2009-12-22 07:45:17 +0100 | [diff] [blame] | 564 | struct gsm_bts *bts = msg->lchan->ts->trx->bts; |
| 565 | struct bitvec *nbv = &bts->si_common.neigh_list; |
Harald Welte | a06c35e | 2009-12-25 22:46:25 +0100 | [diff] [blame] | 566 | struct gsm_meas_rep_cell *mrc; |
Holger Hans Peter Freyther | 92ffd92 | 2009-12-22 07:45:17 +0100 | [diff] [blame] | 567 | |
| 568 | if (gh->msg_type != GSM48_MT_RR_MEAS_REP) |
| 569 | return -EINVAL; |
| 570 | |
| 571 | if (data[0] & 0x80) |
| 572 | rep->flags |= MEAS_REP_F_BA1; |
| 573 | if (data[0] & 0x40) |
| 574 | rep->flags |= MEAS_REP_F_UL_DTX; |
| 575 | if ((data[1] & 0x40) == 0x00) |
| 576 | rep->flags |= MEAS_REP_F_DL_VALID; |
| 577 | |
| 578 | rep->dl.full.rx_lev = data[0] & 0x3f; |
| 579 | rep->dl.sub.rx_lev = data[1] & 0x3f; |
Sylvain Munaut | 48ea4e8 | 2012-12-25 13:06:27 +0100 | [diff] [blame] | 580 | rep->dl.full.rx_qual = (data[2] >> 4) & 0x7; |
| 581 | rep->dl.sub.rx_qual = (data[2] >> 1) & 0x7; |
Holger Hans Peter Freyther | 92ffd92 | 2009-12-22 07:45:17 +0100 | [diff] [blame] | 582 | |
| 583 | rep->num_cell = ((data[3] >> 6) & 0x3) | ((data[2] & 0x01) << 2); |
| 584 | if (rep->num_cell < 1 || rep->num_cell > 6) |
| 585 | return 0; |
| 586 | |
| 587 | /* an encoding nightmare in perfection */ |
Harald Welte | a06c35e | 2009-12-25 22:46:25 +0100 | [diff] [blame] | 588 | mrc = &rep->cell[0]; |
| 589 | mrc->rxlev = data[3] & 0x3f; |
Harald Welte | 950eca9 | 2009-12-25 22:49:34 +0100 | [diff] [blame] | 590 | mrc->neigh_idx = data[4] >> 3; |
Harald Welte | eaa95d5 | 2009-12-25 23:01:54 +0100 | [diff] [blame] | 591 | mrc->arfcn = bitvec_get_nth_set_bit(nbv, mrc->neigh_idx + 1); |
Harald Welte | a06c35e | 2009-12-25 22:46:25 +0100 | [diff] [blame] | 592 | mrc->bsic = ((data[4] & 0x07) << 3) | (data[5] >> 5); |
Holger Hans Peter Freyther | 92ffd92 | 2009-12-22 07:45:17 +0100 | [diff] [blame] | 593 | if (rep->num_cell < 2) |
| 594 | return 0; |
| 595 | |
Harald Welte | a06c35e | 2009-12-25 22:46:25 +0100 | [diff] [blame] | 596 | mrc = &rep->cell[1]; |
| 597 | mrc->rxlev = ((data[5] & 0x1f) << 1) | (data[6] >> 7); |
Harald Welte | 950eca9 | 2009-12-25 22:49:34 +0100 | [diff] [blame] | 598 | mrc->neigh_idx = (data[6] >> 2) & 0x1f; |
Harald Welte | eaa95d5 | 2009-12-25 23:01:54 +0100 | [diff] [blame] | 599 | mrc->arfcn = bitvec_get_nth_set_bit(nbv, mrc->neigh_idx + 1); |
Harald Welte | a06c35e | 2009-12-25 22:46:25 +0100 | [diff] [blame] | 600 | mrc->bsic = ((data[6] & 0x03) << 4) | (data[7] >> 4); |
Holger Hans Peter Freyther | 92ffd92 | 2009-12-22 07:45:17 +0100 | [diff] [blame] | 601 | if (rep->num_cell < 3) |
| 602 | return 0; |
| 603 | |
Harald Welte | a06c35e | 2009-12-25 22:46:25 +0100 | [diff] [blame] | 604 | mrc = &rep->cell[2]; |
| 605 | mrc->rxlev = ((data[7] & 0x0f) << 2) | (data[8] >> 6); |
Harald Welte | 950eca9 | 2009-12-25 22:49:34 +0100 | [diff] [blame] | 606 | mrc->neigh_idx = (data[8] >> 1) & 0x1f; |
Harald Welte | eaa95d5 | 2009-12-25 23:01:54 +0100 | [diff] [blame] | 607 | 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] | 608 | mrc->bsic = ((data[8] & 0x01) << 5) | (data[9] >> 3); |
Holger Hans Peter Freyther | 92ffd92 | 2009-12-22 07:45:17 +0100 | [diff] [blame] | 609 | if (rep->num_cell < 4) |
| 610 | return 0; |
| 611 | |
Harald Welte | a06c35e | 2009-12-25 22:46:25 +0100 | [diff] [blame] | 612 | mrc = &rep->cell[3]; |
| 613 | mrc->rxlev = ((data[9] & 0x07) << 3) | (data[10] >> 5); |
Harald Welte | 950eca9 | 2009-12-25 22:49:34 +0100 | [diff] [blame] | 614 | mrc->neigh_idx = data[10] & 0x1f; |
Harald Welte | eaa95d5 | 2009-12-25 23:01:54 +0100 | [diff] [blame] | 615 | mrc->arfcn = bitvec_get_nth_set_bit(nbv, mrc->neigh_idx + 1); |
Harald Welte | a06c35e | 2009-12-25 22:46:25 +0100 | [diff] [blame] | 616 | mrc->bsic = data[11] >> 2; |
Holger Hans Peter Freyther | 92ffd92 | 2009-12-22 07:45:17 +0100 | [diff] [blame] | 617 | if (rep->num_cell < 5) |
| 618 | return 0; |
| 619 | |
Harald Welte | a06c35e | 2009-12-25 22:46:25 +0100 | [diff] [blame] | 620 | mrc = &rep->cell[4]; |
| 621 | mrc->rxlev = ((data[11] & 0x03) << 4) | (data[12] >> 4); |
Harald Welte | 950eca9 | 2009-12-25 22:49:34 +0100 | [diff] [blame] | 622 | mrc->neigh_idx = ((data[12] & 0xf) << 1) | (data[13] >> 7); |
Harald Welte | eaa95d5 | 2009-12-25 23:01:54 +0100 | [diff] [blame] | 623 | mrc->arfcn = bitvec_get_nth_set_bit(nbv, mrc->neigh_idx + 1); |
Harald Welte | a06c35e | 2009-12-25 22:46:25 +0100 | [diff] [blame] | 624 | mrc->bsic = (data[13] >> 1) & 0x3f; |
Holger Hans Peter Freyther | 92ffd92 | 2009-12-22 07:45:17 +0100 | [diff] [blame] | 625 | if (rep->num_cell < 6) |
| 626 | return 0; |
| 627 | |
Harald Welte | a06c35e | 2009-12-25 22:46:25 +0100 | [diff] [blame] | 628 | mrc = &rep->cell[5]; |
Harald Welte | 950eca9 | 2009-12-25 22:49:34 +0100 | [diff] [blame] | 629 | mrc->rxlev = ((data[13] & 0x01) << 5) | (data[14] >> 3); |
| 630 | mrc->neigh_idx = ((data[14] & 0x07) << 2) | (data[15] >> 6); |
Harald Welte | eaa95d5 | 2009-12-25 23:01:54 +0100 | [diff] [blame] | 631 | mrc->arfcn = bitvec_get_nth_set_bit(nbv, mrc->neigh_idx + 1); |
Harald Welte | a06c35e | 2009-12-25 22:46:25 +0100 | [diff] [blame] | 632 | mrc->bsic = data[15] & 0x3f; |
Holger Hans Peter Freyther | 92ffd92 | 2009-12-22 07:45:17 +0100 | [diff] [blame] | 633 | |
| 634 | return 0; |
| 635 | } |
Holger Hans Peter Freyther | 2c0f166 | 2010-06-15 19:39:27 +0800 | [diff] [blame] | 636 | |
| 637 | struct msgb *gsm48_create_mm_serv_rej(enum gsm48_reject_value value) |
| 638 | { |
| 639 | struct msgb *msg; |
| 640 | struct gsm48_hdr *gh; |
| 641 | |
Holger Hans Peter Freyther | 8239e06 | 2016-01-25 22:03:25 +0100 | [diff] [blame] | 642 | msg = gsm48_msgb_alloc_name("GSM 04.08 SERV REJ"); |
Holger Hans Peter Freyther | 2c0f166 | 2010-06-15 19:39:27 +0800 | [diff] [blame] | 643 | if (!msg) |
| 644 | return NULL; |
| 645 | |
| 646 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 1); |
| 647 | gh->proto_discr = GSM48_PDISC_MM; |
| 648 | gh->msg_type = GSM48_MT_MM_CM_SERV_REJ; |
| 649 | gh->data[0] = value; |
| 650 | |
| 651 | return msg; |
| 652 | } |
Holger Hans Peter Freyther | 230a4d8 | 2010-06-15 19:40:05 +0800 | [diff] [blame] | 653 | |
| 654 | struct msgb *gsm48_create_loc_upd_rej(uint8_t cause) |
| 655 | { |
| 656 | struct gsm48_hdr *gh; |
| 657 | struct msgb *msg; |
| 658 | |
Holger Hans Peter Freyther | 8239e06 | 2016-01-25 22:03:25 +0100 | [diff] [blame] | 659 | msg = gsm48_msgb_alloc_name("GSM 04.08 LOC UPD REJ"); |
Holger Hans Peter Freyther | 230a4d8 | 2010-06-15 19:40:05 +0800 | [diff] [blame] | 660 | if (!msg) |
| 661 | return NULL; |
| 662 | |
| 663 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 1); |
| 664 | gh->proto_discr = GSM48_PDISC_MM; |
| 665 | gh->msg_type = GSM48_MT_MM_LOC_UPD_REJECT; |
| 666 | gh->data[0] = cause; |
| 667 | return msg; |
| 668 | } |
Jacob Erlbeck | 24d3b91 | 2013-10-31 15:36:41 +0100 | [diff] [blame] | 669 | |
| 670 | /* 9.2.5 CM service accept */ |
| 671 | int gsm48_tx_mm_serv_ack(struct gsm_subscriber_connection *conn) |
| 672 | { |
Holger Hans Peter Freyther | 8239e06 | 2016-01-25 22:03:25 +0100 | [diff] [blame] | 673 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 SERV ACK"); |
Jacob Erlbeck | 24d3b91 | 2013-10-31 15:36:41 +0100 | [diff] [blame] | 674 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 675 | |
| 676 | msg->lchan = conn->lchan; |
| 677 | |
| 678 | gh->proto_discr = GSM48_PDISC_MM; |
| 679 | gh->msg_type = GSM48_MT_MM_CM_SERV_ACC; |
| 680 | |
| 681 | DEBUGP(DMM, "-> CM SERVICE ACK\n"); |
| 682 | |
| 683 | return gsm0808_submit_dtap(conn, msg, 0, 0); |
| 684 | } |
| 685 | |
| 686 | /* 9.2.6 CM service reject */ |
| 687 | int gsm48_tx_mm_serv_rej(struct gsm_subscriber_connection *conn, |
| 688 | enum gsm48_reject_value value) |
| 689 | { |
| 690 | struct msgb *msg; |
| 691 | |
| 692 | msg = gsm48_create_mm_serv_rej(value); |
| 693 | if (!msg) { |
| 694 | LOGP(DMM, LOGL_ERROR, "Failed to allocate CM Service Reject.\n"); |
| 695 | return -1; |
| 696 | } |
| 697 | |
| 698 | DEBUGP(DMM, "-> CM SERVICE Reject cause: %d\n", value); |
| 699 | |
| 700 | return gsm0808_submit_dtap(conn, msg, 0, 0); |
| 701 | } |