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 }, |
| 78 | { 0x63, 0xff, CHREQ_T_RESERVED_SDCCH }, |
| 79 | { 0x7f, 0xff, CHREQ_T_RESERVED_IGNORE }, |
Holger Hans Peter Freyther | 3689710 | 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 | 313a6c8 | 2009-11-17 16:46:46 +0100 | [diff] [blame] | 89 | { 0x80, 0xe0, CHREQ_T_PAG_R_ANY_NECI0 }, |
Holger Hans Peter Freyther | 3689710 | 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 | a614a4c | 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 | 3689710 | 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 | 313a6c8 | 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 | 3689710 | 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 | a614a4c | 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 | 3689710 | 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 | 1f0eca2 | 2009-12-12 20:57:52 +0100 | [diff] [blame] | 125 | [CHREQ_T_VOICE_CALL_TCH_H] = GSM_CHREQ_REASON_CALL, |
Holger Hans Peter Freyther | 3689710 | 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 | 313a6c8 | 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 | 3689710 | 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 | a614a4c | 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 | 3689710 | 2009-08-01 07:26:59 +0200 | [diff] [blame] | 135 | }; |
| 136 | |
Holger Hans Peter Freyther | f0f37f1 | 2010-09-06 09:36:02 +0800 | [diff] [blame] | 137 | /* verify that the two tables match */ |
Pablo Neira Ayuso | b1d5a69 | 2011-05-07 12:12:48 +0200 | [diff] [blame] | 138 | osmo_static_assert(sizeof(ctype_by_chreq) == |
Holger Hans Peter Freyther | f0f37f1 | 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 | b6b9d70 | 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 | f0f37f1 | 2010-09-06 09:36:02 +0800 | [diff] [blame] | 168 | } |
| 169 | |
Holger Hans Peter Freyther | 7eb8a9a | 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 | 3689710 | 2009-08-01 07:26:59 +0200 | [diff] [blame] | 171 | { |
| 172 | int i; |
Holger Hans Peter Freyther | 29fabfb | 2009-11-17 16:38:25 +0100 | [diff] [blame] | 173 | int length; |
| 174 | const struct chreq *chreq; |
Holger Hans Peter Freyther | 3689710 | 2009-08-01 07:26:59 +0200 | [diff] [blame] | 175 | |
Holger Hans Peter Freyther | f0f37f1 | 2010-09-06 09:36:02 +0800 | [diff] [blame] | 176 | if (network->neci) { |
Holger Hans Peter Freyther | 29fabfb | 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 | 3689710 | 2009-08-01 07:26:59 +0200 | [diff] [blame] | 187 | if ((ra & chr->mask) == chr->val) |
Holger Hans Peter Freyther | f0f37f1 | 2010-09-06 09:36:02 +0800 | [diff] [blame] | 188 | return network->ctype_by_chreq[chr->type]; |
Holger Hans Peter Freyther | 3689710 | 2009-08-01 07:26:59 +0200 | [diff] [blame] | 189 | } |
Harald Welte | f58dea7 | 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 | 3689710 | 2009-08-01 07:26:59 +0200 | [diff] [blame] | 191 | return GSM_LCHAN_SDCCH; |
| 192 | } |
| 193 | |
Harald Welte | 5d977a8 | 2011-07-23 10:53:30 +0200 | [diff] [blame] | 194 | int get_reason_by_chreq(uint8_t ra, int neci) |
Holger Hans Peter Freyther | 3689710 | 2009-08-01 07:26:59 +0200 | [diff] [blame] | 195 | { |
| 196 | int i; |
Holger Hans Peter Freyther | 29fabfb | 2009-11-17 16:38:25 +0100 | [diff] [blame] | 197 | int length; |
| 198 | const struct chreq *chreq; |
Holger Hans Peter Freyther | 3689710 | 2009-08-01 07:26:59 +0200 | [diff] [blame] | 199 | |
Holger Hans Peter Freyther | 29fabfb | 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 | 3689710 | 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 | f58dea7 | 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 | 3689710 | 2009-08-01 07:26:59 +0200 | [diff] [blame] | 214 | return GSM_CHREQ_REASON_OTHER; |
| 215 | } |
| 216 | |
| 217 | /* 7.1.7 and 9.1.7: RR CHANnel RELease */ |
| 218 | int gsm48_send_rr_release(struct gsm_lchan *lchan) |
| 219 | { |
| 220 | struct msgb *msg = gsm48_msgb_alloc(); |
| 221 | 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] | 222 | uint8_t *cause; |
Holger Hans Peter Freyther | 3689710 | 2009-08-01 07:26:59 +0200 | [diff] [blame] | 223 | |
| 224 | msg->lchan = lchan; |
| 225 | gh->proto_discr = GSM48_PDISC_RR; |
| 226 | gh->msg_type = GSM48_MT_RR_CHAN_REL; |
| 227 | |
| 228 | cause = msgb_put(msg, 1); |
| 229 | cause[0] = GSM48_RR_CAUSE_NORMAL; |
| 230 | |
| 231 | DEBUGP(DRR, "Sending Channel Release: Chan: Number: %d Type: %d\n", |
| 232 | lchan->nr, lchan->type); |
| 233 | |
| 234 | /* Send actual release request to MS */ |
Holger Hans Peter Freyther | 969a405 | 2011-12-28 16:21:05 +0100 | [diff] [blame] | 235 | return gsm48_sendmsg(msg); |
Holger Hans Peter Freyther | 3689710 | 2009-08-01 07:26:59 +0200 | [diff] [blame] | 236 | } |
| 237 | |
Holger Hans Peter Freyther | a269ece | 2009-08-21 04:57:35 +0200 | [diff] [blame] | 238 | int send_siemens_mrpci(struct gsm_lchan *lchan, |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 239 | uint8_t *classmark2_lv) |
Holger Hans Peter Freyther | a269ece | 2009-08-21 04:57:35 +0200 | [diff] [blame] | 240 | { |
| 241 | struct rsl_mrpci mrpci; |
| 242 | |
| 243 | if (classmark2_lv[0] < 2) |
| 244 | return -EINVAL; |
| 245 | |
| 246 | mrpci.power_class = classmark2_lv[1] & 0x7; |
| 247 | mrpci.vgcs_capable = classmark2_lv[2] & (1 << 1); |
| 248 | mrpci.vbs_capable = classmark2_lv[2] & (1 <<2); |
| 249 | mrpci.gsm_phase = (classmark2_lv[1]) >> 5 & 0x3; |
| 250 | |
| 251 | return rsl_siemens_mrpci(lchan, &mrpci); |
| 252 | } |
| 253 | |
Holger Hans Peter Freyther | 088ca3a | 2010-05-16 01:07:20 +0800 | [diff] [blame] | 254 | 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] | 255 | { |
Holger Hans Peter Freyther | a943b2a | 2010-05-16 01:51:14 +0800 | [diff] [blame] | 256 | /* Check the size for the classmark */ |
Holger Hans Peter Freyther | 088ca3a | 2010-05-16 01:07:20 +0800 | [diff] [blame] | 257 | if (length < 1 + *classmark2_lv) |
Holger Hans Peter Freyther | a943b2a | 2010-05-16 01:51:14 +0800 | [diff] [blame] | 258 | return -1; |
| 259 | |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 260 | uint8_t *mi_lv = classmark2_lv + *classmark2_lv + 1; |
Holger Hans Peter Freyther | 088ca3a | 2010-05-16 01:07:20 +0800 | [diff] [blame] | 261 | if (length < 2 + *classmark2_lv + mi_lv[0]) |
Holger Hans Peter Freyther | a943b2a | 2010-05-16 01:51:14 +0800 | [diff] [blame] | 262 | return -2; |
| 263 | |
| 264 | *mi_type = mi_lv[1] & GSM_MI_TYPE_MASK; |
Holger Hans Peter Freyther | 1e43b8d | 2009-08-21 05:18:21 +0200 | [diff] [blame] | 265 | return gsm48_mi_to_string(mi_string, GSM48_MI_SIZE, mi_lv+1, *mi_lv); |
| 266 | } |
| 267 | |
Holger Hans Peter Freyther | 088ca3a | 2010-05-16 01:07:20 +0800 | [diff] [blame] | 268 | 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] | 269 | char *mi_string, uint8_t *mi_type) |
Holger Hans Peter Freyther | 088ca3a | 2010-05-16 01:07:20 +0800 | [diff] [blame] | 270 | { |
| 271 | static const uint32_t classmark_offset = |
| 272 | offsetof(struct gsm48_pag_resp, classmark2); |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 273 | uint8_t *classmark2_lv = (uint8_t *) &resp->classmark2; |
Holger Hans Peter Freyther | 088ca3a | 2010-05-16 01:07:20 +0800 | [diff] [blame] | 274 | return gsm48_extract_mi(classmark2_lv, length - classmark_offset, |
| 275 | mi_string, mi_type); |
| 276 | } |
| 277 | |
Holger Hans Peter Freyther | 0b83e54 | 2010-06-21 10:46:44 +0800 | [diff] [blame] | 278 | int gsm48_handle_paging_resp(struct gsm_subscriber_connection *conn, |
| 279 | struct msgb *msg, struct gsm_subscriber *subscr) |
Holger Hans Peter Freyther | 1e43b8d | 2009-08-21 05:18:21 +0200 | [diff] [blame] | 280 | { |
| 281 | struct gsm_bts *bts = msg->lchan->ts->trx->bts; |
| 282 | struct gsm48_hdr *gh = msgb_l3(msg); |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 283 | uint8_t *classmark2_lv = gh->data + 1; |
Holger Hans Peter Freyther | 1e43b8d | 2009-08-21 05:18:21 +0200 | [diff] [blame] | 284 | |
| 285 | if (is_siemens_bts(bts)) |
| 286 | send_siemens_mrpci(msg->lchan, classmark2_lv); |
| 287 | |
Holger Hans Peter Freyther | 0b83e54 | 2010-06-21 10:46:44 +0800 | [diff] [blame] | 288 | if (!conn->subscr) { |
| 289 | conn->subscr = subscr; |
| 290 | } else if (conn->subscr != subscr) { |
Harald Welte | f58dea7 | 2009-12-24 11:50:20 +0100 | [diff] [blame] | 291 | LOGP(DRR, LOGL_ERROR, "<- Channel already owned by someone else?\n"); |
Holger Hans Peter Freyther | 1e43b8d | 2009-08-21 05:18:21 +0200 | [diff] [blame] | 292 | subscr_put(subscr); |
| 293 | return -EINVAL; |
| 294 | } else { |
| 295 | DEBUGP(DRR, "<- Channel already owned by us\n"); |
| 296 | subscr_put(subscr); |
Holger Hans Peter Freyther | 0b83e54 | 2010-06-21 10:46:44 +0800 | [diff] [blame] | 297 | subscr = conn->subscr; |
Holger Hans Peter Freyther | 1e43b8d | 2009-08-21 05:18:21 +0200 | [diff] [blame] | 298 | } |
| 299 | |
Pablo Neira Ayuso | 1c45074 | 2011-05-06 12:13:10 +0200 | [diff] [blame] | 300 | osmo_counter_inc(bts->network->stats.paging.completed); |
Harald Welte | 3edc5a9 | 2009-12-22 00:41:05 +0100 | [diff] [blame] | 301 | |
Holger Hans Peter Freyther | 1e43b8d | 2009-08-21 05:18:21 +0200 | [diff] [blame] | 302 | /* Stop paging on the bts we received the paging response */ |
Sylvain Munaut | b7b6e78 | 2010-12-01 21:41:35 +0100 | [diff] [blame] | 303 | paging_request_stop(conn->bts, subscr, conn, msg); |
Holger Hans Peter Freyther | 1e43b8d | 2009-08-21 05:18:21 +0200 | [diff] [blame] | 304 | return 0; |
| 305 | } |
Holger Hans Peter Freyther | 3d76e88 | 2009-10-05 13:25:06 +0200 | [diff] [blame] | 306 | |
| 307 | /* Chapter 9.1.9: Ciphering Mode Command */ |
Holger Hans Peter Freyther | b94719d | 2009-10-05 14:00:14 +0200 | [diff] [blame] | 308 | 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] | 309 | { |
| 310 | struct msgb *msg = gsm48_msgb_alloc(); |
| 311 | struct gsm48_hdr *gh; |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 312 | uint8_t ciph_mod_set; |
Holger Hans Peter Freyther | 3d76e88 | 2009-10-05 13:25:06 +0200 | [diff] [blame] | 313 | |
| 314 | msg->lchan = lchan; |
| 315 | |
| 316 | DEBUGP(DRR, "TX CIPHERING MODE CMD\n"); |
| 317 | |
| 318 | if (lchan->encr.alg_id <= RSL_ENC_ALG_A5(0)) |
| 319 | ciph_mod_set = 0; |
| 320 | else |
| 321 | ciph_mod_set = (lchan->encr.alg_id-2)<<1 | 1; |
| 322 | |
| 323 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 1); |
| 324 | gh->proto_discr = GSM48_PDISC_RR; |
| 325 | gh->msg_type = GSM48_MT_RR_CIPH_M_CMD; |
Holger Hans Peter Freyther | b94719d | 2009-10-05 14:00:14 +0200 | [diff] [blame] | 326 | 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] | 327 | |
| 328 | return rsl_encryption_cmd(msg); |
| 329 | } |
| 330 | |
Harald Welte | f849366 | 2009-11-29 20:02:53 +0100 | [diff] [blame] | 331 | static void gsm48_cell_desc(struct gsm48_cell_desc *cd, |
| 332 | const struct gsm_bts *bts) |
| 333 | { |
| 334 | cd->ncc = (bts->bsic >> 3 & 0x7); |
| 335 | cd->bcc = (bts->bsic & 0x7); |
| 336 | cd->arfcn_hi = bts->c0->arfcn >> 8; |
| 337 | cd->arfcn_lo = bts->c0->arfcn & 0xff; |
| 338 | } |
| 339 | |
Harald Welte | a42a93f | 2010-06-14 22:26:10 +0200 | [diff] [blame] | 340 | void gsm48_lchan2chan_desc(struct gsm48_chan_desc *cd, |
| 341 | const struct gsm_lchan *lchan) |
Harald Welte | f849366 | 2009-11-29 20:02:53 +0100 | [diff] [blame] | 342 | { |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 343 | uint16_t arfcn = lchan->ts->trx->arfcn & 0x3ff; |
Harald Welte | 82094c3 | 2014-01-19 16:55:16 +0100 | [diff] [blame^] | 344 | uint8_t tsc; |
| 345 | |
| 346 | if (lchan->ts->tsc == -1) |
| 347 | tsc = lchan->ts->trx->bts->tsc; |
| 348 | else |
| 349 | tsc = lchan->ts->tsc; |
Harald Welte | f849366 | 2009-11-29 20:02:53 +0100 | [diff] [blame] | 350 | |
Harald Welte | e6d51f9 | 2011-06-25 10:02:33 +0200 | [diff] [blame] | 351 | cd->chan_nr = gsm_lchan2chan_nr(lchan); |
Harald Welte | a42a93f | 2010-06-14 22:26:10 +0200 | [diff] [blame] | 352 | if (!lchan->ts->hopping.enabled) { |
Harald Welte | 82094c3 | 2014-01-19 16:55:16 +0100 | [diff] [blame^] | 353 | cd->h0.tsc = tsc; |
Harald Welte | a42a93f | 2010-06-14 22:26:10 +0200 | [diff] [blame] | 354 | cd->h0.h = 0; |
| 355 | cd->h0.arfcn_high = arfcn >> 8; |
| 356 | cd->h0.arfcn_low = arfcn & 0xff; |
| 357 | } else { |
Harald Welte | 82094c3 | 2014-01-19 16:55:16 +0100 | [diff] [blame^] | 358 | cd->h1.tsc = tsc; |
Harald Welte | a42a93f | 2010-06-14 22:26:10 +0200 | [diff] [blame] | 359 | cd->h1.h = 1; |
| 360 | cd->h1.maio_high = lchan->ts->hopping.maio >> 2; |
| 361 | cd->h1.maio_low = lchan->ts->hopping.maio & 0x03; |
| 362 | cd->h1.hsn = lchan->ts->hopping.hsn; |
| 363 | } |
Harald Welte | f849366 | 2009-11-29 20:02:53 +0100 | [diff] [blame] | 364 | } |
| 365 | |
Harald Welte | 6332a8a | 2010-06-15 16:45:51 +0200 | [diff] [blame] | 366 | #define GSM48_HOCMD_CCHDESC_LEN 16 |
| 367 | |
Harald Welte | f849366 | 2009-11-29 20:02:53 +0100 | [diff] [blame] | 368 | /* Chapter 9.1.15: Handover Command */ |
Harald Welte | d0841fa | 2009-12-17 00:25:18 +0100 | [diff] [blame] | 369 | 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] | 370 | uint8_t power_command, uint8_t ho_ref) |
Harald Welte | f849366 | 2009-11-29 20:02:53 +0100 | [diff] [blame] | 371 | { |
| 372 | struct msgb *msg = gsm48_msgb_alloc(); |
| 373 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 374 | struct gsm48_ho_cmd *ho = |
| 375 | (struct gsm48_ho_cmd *) msgb_put(msg, sizeof(*ho)); |
Harald Welte | f849366 | 2009-11-29 20:02:53 +0100 | [diff] [blame] | 376 | |
| 377 | msg->lchan = old_lchan; |
Harald Welte | d0841fa | 2009-12-17 00:25:18 +0100 | [diff] [blame] | 378 | gh->proto_discr = GSM48_PDISC_RR; |
| 379 | gh->msg_type = GSM48_MT_RR_HANDO_CMD; |
Harald Welte | f849366 | 2009-11-29 20:02:53 +0100 | [diff] [blame] | 380 | |
| 381 | /* mandatory bits */ |
| 382 | gsm48_cell_desc(&ho->cell_desc, new_lchan->ts->trx->bts); |
Harald Welte | a42a93f | 2010-06-14 22:26:10 +0200 | [diff] [blame] | 383 | gsm48_lchan2chan_desc(&ho->chan_desc, new_lchan); |
Harald Welte | d0841fa | 2009-12-17 00:25:18 +0100 | [diff] [blame] | 384 | ho->ho_ref = ho_ref; |
Harald Welte | f849366 | 2009-11-29 20:02:53 +0100 | [diff] [blame] | 385 | ho->power_command = power_command; |
| 386 | |
Harald Welte | 6332a8a | 2010-06-15 16:45:51 +0200 | [diff] [blame] | 387 | if (new_lchan->ts->hopping.enabled) { |
| 388 | struct gsm_bts *bts = new_lchan->ts->trx->bts; |
| 389 | struct gsm48_system_information_type_1 *si1; |
| 390 | uint8_t *cur; |
| 391 | |
| 392 | si1 = GSM_BTS_SI(bts, SYSINFO_TYPE_1); |
| 393 | /* Copy the Cell Chan Desc (ARFCNS in this cell) */ |
| 394 | msgb_put_u8(msg, GSM48_IE_CELL_CH_DESC); |
| 395 | cur = msgb_put(msg, GSM48_HOCMD_CCHDESC_LEN); |
| 396 | memcpy(cur, si1->cell_channel_description, |
| 397 | GSM48_HOCMD_CCHDESC_LEN); |
| 398 | /* Copy the Mobile Allocation */ |
| 399 | msgb_tlv_put(msg, GSM48_IE_MA_BEFORE, |
| 400 | new_lchan->ts->hopping.ma_len, |
| 401 | new_lchan->ts->hopping.ma_data); |
| 402 | } |
Harald Welte | f849366 | 2009-11-29 20:02:53 +0100 | [diff] [blame] | 403 | /* FIXME: optional bits for type of synchronization? */ |
| 404 | |
Holger Hans Peter Freyther | 5bc4d1d | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 405 | return gsm48_sendmsg(msg); |
Harald Welte | f849366 | 2009-11-29 20:02:53 +0100 | [diff] [blame] | 406 | } |
| 407 | |
Holger Hans Peter Freyther | 942ff17 | 2009-10-22 11:47:45 +0200 | [diff] [blame] | 408 | /* Chapter 9.1.2: Assignment Command */ |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 409 | 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] | 410 | { |
| 411 | struct msgb *msg = gsm48_msgb_alloc(); |
| 412 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 413 | struct gsm48_ass_cmd *ass = |
| 414 | (struct gsm48_ass_cmd *) msgb_put(msg, sizeof(*ass)); |
Holger Hans Peter Freyther | 942ff17 | 2009-10-22 11:47:45 +0200 | [diff] [blame] | 415 | |
| 416 | DEBUGP(DRR, "-> ASSIGNMENT COMMAND tch_mode=0x%02x\n", lchan->tch_mode); |
| 417 | |
Holger Hans Peter Freyther | 2975453 | 2010-01-28 09:43:49 +0100 | [diff] [blame] | 418 | msg->lchan = dest_lchan; |
Holger Hans Peter Freyther | 942ff17 | 2009-10-22 11:47:45 +0200 | [diff] [blame] | 419 | gh->proto_discr = GSM48_PDISC_RR; |
| 420 | gh->msg_type = GSM48_MT_RR_ASS_CMD; |
| 421 | |
| 422 | /* |
| 423 | * fill the channel information element, this code |
| 424 | * should probably be shared with rsl_rx_chan_rqd(), |
| 425 | * gsm48_tx_chan_mode_modify. But beware that 10.5.2.5 |
| 426 | * 10.5.2.5.a have slightly different semantic for |
| 427 | * the chan_desc. But as long as multi-slot configurations |
| 428 | * are not used we seem to be fine. |
| 429 | */ |
Harald Welte | a42a93f | 2010-06-14 22:26:10 +0200 | [diff] [blame] | 430 | gsm48_lchan2chan_desc(&ass->chan_desc, lchan); |
Holger Hans Peter Freyther | 942ff17 | 2009-10-22 11:47:45 +0200 | [diff] [blame] | 431 | ass->power_command = power_command; |
| 432 | |
Harald Welte | 6332a8a | 2010-06-15 16:45:51 +0200 | [diff] [blame] | 433 | /* optional: cell channel description */ |
| 434 | |
Holger Hans Peter Freyther | bed3aab | 2010-01-28 11:51:24 +0100 | [diff] [blame] | 435 | msgb_tv_put(msg, GSM48_IE_CHANMODE_1, lchan->tch_mode); |
| 436 | |
Harald Welte | 6332a8a | 2010-06-15 16:45:51 +0200 | [diff] [blame] | 437 | /* mobile allocation in case of hopping */ |
| 438 | if (lchan->ts->hopping.enabled) { |
| 439 | msgb_tlv_put(msg, GSM48_IE_MA_BEFORE, lchan->ts->hopping.ma_len, |
| 440 | lchan->ts->hopping.ma_data); |
| 441 | } |
| 442 | |
Holger Hans Peter Freyther | 94bde97 | 2009-11-16 22:49:24 +0100 | [diff] [blame] | 443 | /* in case of multi rate we need to attach a config */ |
| 444 | if (lchan->tch_mode == GSM48_CMODE_SPEECH_AMR) { |
Holger Hans Peter Freyther | 3cce58f | 2009-11-18 22:57:02 +0100 | [diff] [blame] | 445 | if (lchan->mr_conf.ver == 0) { |
Harald Welte | f58dea7 | 2009-12-24 11:50:20 +0100 | [diff] [blame] | 446 | LOGP(DRR, LOGL_ERROR, "BUG: Using multirate codec " |
| 447 | "without multirate config.\n"); |
Holger Hans Peter Freyther | 94bde97 | 2009-11-16 22:49:24 +0100 | [diff] [blame] | 448 | } else { |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 449 | uint8_t *data = msgb_put(msg, 4); |
Holger Hans Peter Freyther | 94bde97 | 2009-11-16 22:49:24 +0100 | [diff] [blame] | 450 | data[0] = GSM48_IE_MUL_RATE_CFG; |
| 451 | data[1] = 0x2; |
Holger Hans Peter Freyther | 3cce58f | 2009-11-18 22:57:02 +0100 | [diff] [blame] | 452 | memcpy(&data[2], &lchan->mr_conf, 2); |
Holger Hans Peter Freyther | 94bde97 | 2009-11-16 22:49:24 +0100 | [diff] [blame] | 453 | } |
| 454 | } |
| 455 | |
Holger Hans Peter Freyther | 5bc4d1d | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 456 | return gsm48_sendmsg(msg); |
Holger Hans Peter Freyther | 942ff17 | 2009-10-22 11:47:45 +0200 | [diff] [blame] | 457 | } |
Holger Hans Peter Freyther | cf0f336 | 2009-10-22 15:13:00 +0200 | [diff] [blame] | 458 | |
| 459 | /* 9.1.5 Channel mode modify: Modify the mode on the MS side */ |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 460 | int gsm48_tx_chan_mode_modify(struct gsm_lchan *lchan, uint8_t mode) |
Holger Hans Peter Freyther | cf0f336 | 2009-10-22 15:13:00 +0200 | [diff] [blame] | 461 | { |
| 462 | struct msgb *msg = gsm48_msgb_alloc(); |
| 463 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 464 | struct gsm48_chan_mode_modify *cmm = |
| 465 | (struct gsm48_chan_mode_modify *) msgb_put(msg, sizeof(*cmm)); |
Holger Hans Peter Freyther | cf0f336 | 2009-10-22 15:13:00 +0200 | [diff] [blame] | 466 | |
| 467 | DEBUGP(DRR, "-> CHANNEL MODE MODIFY mode=0x%02x\n", mode); |
| 468 | |
| 469 | lchan->tch_mode = mode; |
| 470 | msg->lchan = lchan; |
| 471 | gh->proto_discr = GSM48_PDISC_RR; |
| 472 | gh->msg_type = GSM48_MT_RR_CHAN_MODE_MODIF; |
| 473 | |
| 474 | /* fill the channel information element, this code |
| 475 | * should probably be shared with rsl_rx_chan_rqd() */ |
Harald Welte | a42a93f | 2010-06-14 22:26:10 +0200 | [diff] [blame] | 476 | gsm48_lchan2chan_desc(&cmm->chan_desc, lchan); |
Holger Hans Peter Freyther | cf0f336 | 2009-10-22 15:13:00 +0200 | [diff] [blame] | 477 | cmm->mode = mode; |
| 478 | |
Holger Hans Peter Freyther | 94bde97 | 2009-11-16 22:49:24 +0100 | [diff] [blame] | 479 | /* in case of multi rate we need to attach a config */ |
Holger Hans Peter Freyther | 3cce58f | 2009-11-18 22:57:02 +0100 | [diff] [blame] | 480 | if (lchan->tch_mode == GSM48_CMODE_SPEECH_AMR) { |
| 481 | if (lchan->mr_conf.ver == 0) { |
Harald Welte | f58dea7 | 2009-12-24 11:50:20 +0100 | [diff] [blame] | 482 | LOGP(DRR, LOGL_ERROR, "BUG: Using multirate codec " |
| 483 | "without multirate config.\n"); |
Holger Hans Peter Freyther | 94bde97 | 2009-11-16 22:49:24 +0100 | [diff] [blame] | 484 | } else { |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 485 | uint8_t *data = msgb_put(msg, 4); |
Holger Hans Peter Freyther | 94bde97 | 2009-11-16 22:49:24 +0100 | [diff] [blame] | 486 | data[0] = GSM48_IE_MUL_RATE_CFG; |
| 487 | data[1] = 0x2; |
Holger Hans Peter Freyther | 3cce58f | 2009-11-18 22:57:02 +0100 | [diff] [blame] | 488 | memcpy(&data[2], &lchan->mr_conf, 2); |
Holger Hans Peter Freyther | 94bde97 | 2009-11-16 22:49:24 +0100 | [diff] [blame] | 489 | } |
| 490 | } |
| 491 | |
Holger Hans Peter Freyther | 5bc4d1d | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 492 | return gsm48_sendmsg(msg); |
Holger Hans Peter Freyther | cf0f336 | 2009-10-22 15:13:00 +0200 | [diff] [blame] | 493 | } |
| 494 | |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 495 | int gsm48_lchan_modify(struct gsm_lchan *lchan, uint8_t lchan_mode) |
Holger Hans Peter Freyther | cf0f336 | 2009-10-22 15:13:00 +0200 | [diff] [blame] | 496 | { |
| 497 | int rc; |
| 498 | |
Holger Hans Peter Freyther | 3cce58f | 2009-11-18 22:57:02 +0100 | [diff] [blame] | 499 | rc = gsm48_tx_chan_mode_modify(lchan, lchan_mode); |
Holger Hans Peter Freyther | cf0f336 | 2009-10-22 15:13:00 +0200 | [diff] [blame] | 500 | if (rc < 0) |
| 501 | return rc; |
| 502 | |
Holger Hans Peter Freyther | cf0f336 | 2009-10-22 15:13:00 +0200 | [diff] [blame] | 503 | return rc; |
| 504 | } |
| 505 | |
Holger Hans Peter Freyther | 9e6d6ce | 2009-10-22 15:23:11 +0200 | [diff] [blame] | 506 | int gsm48_rx_rr_modif_ack(struct msgb *msg) |
| 507 | { |
Holger Hans Peter Freyther | a7e8a58 | 2009-11-18 19:30:24 +0100 | [diff] [blame] | 508 | int rc; |
Holger Hans Peter Freyther | 9e6d6ce | 2009-10-22 15:23:11 +0200 | [diff] [blame] | 509 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 510 | struct gsm48_chan_mode_modify *mod = |
| 511 | (struct gsm48_chan_mode_modify *) gh->data; |
| 512 | |
| 513 | DEBUGP(DRR, "CHANNEL MODE MODIFY ACK\n"); |
| 514 | |
| 515 | if (mod->mode != msg->lchan->tch_mode) { |
Harald Welte | f58dea7 | 2009-12-24 11:50:20 +0100 | [diff] [blame] | 516 | 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] | 517 | msg->lchan->tch_mode, mod->mode); |
| 518 | return -1; |
| 519 | } |
| 520 | |
| 521 | /* update the channel type */ |
| 522 | switch (mod->mode) { |
| 523 | case GSM48_CMODE_SIGN: |
| 524 | msg->lchan->rsl_cmode = RSL_CMOD_SPD_SIGN; |
| 525 | break; |
| 526 | case GSM48_CMODE_SPEECH_V1: |
| 527 | case GSM48_CMODE_SPEECH_EFR: |
| 528 | case GSM48_CMODE_SPEECH_AMR: |
| 529 | msg->lchan->rsl_cmode = RSL_CMOD_SPD_SPEECH; |
| 530 | break; |
| 531 | case GSM48_CMODE_DATA_14k5: |
| 532 | case GSM48_CMODE_DATA_12k0: |
| 533 | case GSM48_CMODE_DATA_6k0: |
| 534 | case GSM48_CMODE_DATA_3k6: |
| 535 | msg->lchan->rsl_cmode = RSL_CMOD_SPD_DATA; |
| 536 | break; |
| 537 | } |
| 538 | |
| 539 | /* We've successfully modified the MS side of the channel, |
| 540 | * 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] | 541 | rc = rsl_chan_mode_modify_req(msg->lchan); |
| 542 | |
| 543 | /* FIXME: we not only need to do this after mode modify, but |
| 544 | * also after channel activation */ |
| 545 | if (is_ipaccess_bts(msg->lchan->ts->trx->bts) && mod->mode != GSM48_CMODE_SIGN) |
| 546 | rsl_ipacc_crcx(msg->lchan); |
| 547 | return rc; |
Holger Hans Peter Freyther | 9e6d6ce | 2009-10-22 15:23:11 +0200 | [diff] [blame] | 548 | } |
Holger Hans Peter Freyther | 9a8e84e | 2009-12-22 07:45:17 +0100 | [diff] [blame] | 549 | |
| 550 | int gsm48_parse_meas_rep(struct gsm_meas_rep *rep, struct msgb *msg) |
| 551 | { |
| 552 | struct gsm48_hdr *gh = msgb_l3(msg); |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 553 | uint8_t *data = gh->data; |
Holger Hans Peter Freyther | 9a8e84e | 2009-12-22 07:45:17 +0100 | [diff] [blame] | 554 | struct gsm_bts *bts = msg->lchan->ts->trx->bts; |
| 555 | struct bitvec *nbv = &bts->si_common.neigh_list; |
Harald Welte | 470f7f9 | 2009-12-25 22:46:25 +0100 | [diff] [blame] | 556 | struct gsm_meas_rep_cell *mrc; |
Holger Hans Peter Freyther | 9a8e84e | 2009-12-22 07:45:17 +0100 | [diff] [blame] | 557 | |
| 558 | if (gh->msg_type != GSM48_MT_RR_MEAS_REP) |
| 559 | return -EINVAL; |
| 560 | |
| 561 | if (data[0] & 0x80) |
| 562 | rep->flags |= MEAS_REP_F_BA1; |
| 563 | if (data[0] & 0x40) |
| 564 | rep->flags |= MEAS_REP_F_UL_DTX; |
| 565 | if ((data[1] & 0x40) == 0x00) |
| 566 | rep->flags |= MEAS_REP_F_DL_VALID; |
| 567 | |
| 568 | rep->dl.full.rx_lev = data[0] & 0x3f; |
| 569 | rep->dl.sub.rx_lev = data[1] & 0x3f; |
Sylvain Munaut | cca7203 | 2012-12-25 13:06:27 +0100 | [diff] [blame] | 570 | rep->dl.full.rx_qual = (data[2] >> 4) & 0x7; |
| 571 | rep->dl.sub.rx_qual = (data[2] >> 1) & 0x7; |
Holger Hans Peter Freyther | 9a8e84e | 2009-12-22 07:45:17 +0100 | [diff] [blame] | 572 | |
| 573 | rep->num_cell = ((data[3] >> 6) & 0x3) | ((data[2] & 0x01) << 2); |
| 574 | if (rep->num_cell < 1 || rep->num_cell > 6) |
| 575 | return 0; |
| 576 | |
| 577 | /* an encoding nightmare in perfection */ |
Harald Welte | 470f7f9 | 2009-12-25 22:46:25 +0100 | [diff] [blame] | 578 | mrc = &rep->cell[0]; |
| 579 | mrc->rxlev = data[3] & 0x3f; |
Harald Welte | 10c894d | 2009-12-25 22:49:34 +0100 | [diff] [blame] | 580 | mrc->neigh_idx = data[4] >> 3; |
Harald Welte | 3d6166c | 2009-12-25 23:01:54 +0100 | [diff] [blame] | 581 | mrc->arfcn = bitvec_get_nth_set_bit(nbv, mrc->neigh_idx + 1); |
Harald Welte | 470f7f9 | 2009-12-25 22:46:25 +0100 | [diff] [blame] | 582 | mrc->bsic = ((data[4] & 0x07) << 3) | (data[5] >> 5); |
Holger Hans Peter Freyther | 9a8e84e | 2009-12-22 07:45:17 +0100 | [diff] [blame] | 583 | if (rep->num_cell < 2) |
| 584 | return 0; |
| 585 | |
Harald Welte | 470f7f9 | 2009-12-25 22:46:25 +0100 | [diff] [blame] | 586 | mrc = &rep->cell[1]; |
| 587 | mrc->rxlev = ((data[5] & 0x1f) << 1) | (data[6] >> 7); |
Harald Welte | 10c894d | 2009-12-25 22:49:34 +0100 | [diff] [blame] | 588 | mrc->neigh_idx = (data[6] >> 2) & 0x1f; |
Harald Welte | 3d6166c | 2009-12-25 23:01:54 +0100 | [diff] [blame] | 589 | mrc->arfcn = bitvec_get_nth_set_bit(nbv, mrc->neigh_idx + 1); |
Harald Welte | 470f7f9 | 2009-12-25 22:46:25 +0100 | [diff] [blame] | 590 | mrc->bsic = ((data[6] & 0x03) << 4) | (data[7] >> 4); |
Holger Hans Peter Freyther | 9a8e84e | 2009-12-22 07:45:17 +0100 | [diff] [blame] | 591 | if (rep->num_cell < 3) |
| 592 | return 0; |
| 593 | |
Harald Welte | 470f7f9 | 2009-12-25 22:46:25 +0100 | [diff] [blame] | 594 | mrc = &rep->cell[2]; |
| 595 | mrc->rxlev = ((data[7] & 0x0f) << 2) | (data[8] >> 6); |
Harald Welte | 10c894d | 2009-12-25 22:49:34 +0100 | [diff] [blame] | 596 | mrc->neigh_idx = (data[8] >> 1) & 0x1f; |
Harald Welte | 3d6166c | 2009-12-25 23:01:54 +0100 | [diff] [blame] | 597 | 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] | 598 | mrc->bsic = ((data[8] & 0x01) << 5) | (data[9] >> 3); |
Holger Hans Peter Freyther | 9a8e84e | 2009-12-22 07:45:17 +0100 | [diff] [blame] | 599 | if (rep->num_cell < 4) |
| 600 | return 0; |
| 601 | |
Harald Welte | 470f7f9 | 2009-12-25 22:46:25 +0100 | [diff] [blame] | 602 | mrc = &rep->cell[3]; |
| 603 | mrc->rxlev = ((data[9] & 0x07) << 3) | (data[10] >> 5); |
Harald Welte | 10c894d | 2009-12-25 22:49:34 +0100 | [diff] [blame] | 604 | mrc->neigh_idx = data[10] & 0x1f; |
Harald Welte | 3d6166c | 2009-12-25 23:01:54 +0100 | [diff] [blame] | 605 | mrc->arfcn = bitvec_get_nth_set_bit(nbv, mrc->neigh_idx + 1); |
Harald Welte | 470f7f9 | 2009-12-25 22:46:25 +0100 | [diff] [blame] | 606 | mrc->bsic = data[11] >> 2; |
Holger Hans Peter Freyther | 9a8e84e | 2009-12-22 07:45:17 +0100 | [diff] [blame] | 607 | if (rep->num_cell < 5) |
| 608 | return 0; |
| 609 | |
Harald Welte | 470f7f9 | 2009-12-25 22:46:25 +0100 | [diff] [blame] | 610 | mrc = &rep->cell[4]; |
| 611 | mrc->rxlev = ((data[11] & 0x03) << 4) | (data[12] >> 4); |
Harald Welte | 10c894d | 2009-12-25 22:49:34 +0100 | [diff] [blame] | 612 | mrc->neigh_idx = ((data[12] & 0xf) << 1) | (data[13] >> 7); |
Harald Welte | 3d6166c | 2009-12-25 23:01:54 +0100 | [diff] [blame] | 613 | mrc->arfcn = bitvec_get_nth_set_bit(nbv, mrc->neigh_idx + 1); |
Harald Welte | 470f7f9 | 2009-12-25 22:46:25 +0100 | [diff] [blame] | 614 | mrc->bsic = (data[13] >> 1) & 0x3f; |
Holger Hans Peter Freyther | 9a8e84e | 2009-12-22 07:45:17 +0100 | [diff] [blame] | 615 | if (rep->num_cell < 6) |
| 616 | return 0; |
| 617 | |
Harald Welte | 470f7f9 | 2009-12-25 22:46:25 +0100 | [diff] [blame] | 618 | mrc = &rep->cell[5]; |
Harald Welte | 10c894d | 2009-12-25 22:49:34 +0100 | [diff] [blame] | 619 | mrc->rxlev = ((data[13] & 0x01) << 5) | (data[14] >> 3); |
| 620 | mrc->neigh_idx = ((data[14] & 0x07) << 2) | (data[15] >> 6); |
Harald Welte | 3d6166c | 2009-12-25 23:01:54 +0100 | [diff] [blame] | 621 | mrc->arfcn = bitvec_get_nth_set_bit(nbv, mrc->neigh_idx + 1); |
Harald Welte | 470f7f9 | 2009-12-25 22:46:25 +0100 | [diff] [blame] | 622 | mrc->bsic = data[15] & 0x3f; |
Holger Hans Peter Freyther | 9a8e84e | 2009-12-22 07:45:17 +0100 | [diff] [blame] | 623 | |
| 624 | return 0; |
| 625 | } |
Holger Hans Peter Freyther | a44eea5 | 2010-06-15 19:39:27 +0800 | [diff] [blame] | 626 | |
| 627 | struct msgb *gsm48_create_mm_serv_rej(enum gsm48_reject_value value) |
| 628 | { |
| 629 | struct msgb *msg; |
| 630 | struct gsm48_hdr *gh; |
| 631 | |
| 632 | msg = gsm48_msgb_alloc(); |
| 633 | if (!msg) |
| 634 | return NULL; |
| 635 | |
| 636 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 1); |
| 637 | gh->proto_discr = GSM48_PDISC_MM; |
| 638 | gh->msg_type = GSM48_MT_MM_CM_SERV_REJ; |
| 639 | gh->data[0] = value; |
| 640 | |
| 641 | return msg; |
| 642 | } |
Holger Hans Peter Freyther | 8073cbd | 2010-06-15 19:40:05 +0800 | [diff] [blame] | 643 | |
| 644 | struct msgb *gsm48_create_loc_upd_rej(uint8_t cause) |
| 645 | { |
| 646 | struct gsm48_hdr *gh; |
| 647 | struct msgb *msg; |
| 648 | |
| 649 | msg = gsm48_msgb_alloc(); |
| 650 | if (!msg) |
| 651 | return NULL; |
| 652 | |
| 653 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 1); |
| 654 | gh->proto_discr = GSM48_PDISC_MM; |
| 655 | gh->msg_type = GSM48_MT_MM_LOC_UPD_REJECT; |
| 656 | gh->data[0] = cause; |
| 657 | return msg; |
| 658 | } |
Jacob Erlbeck | 6bc0d0b | 2013-10-31 15:36:41 +0100 | [diff] [blame] | 659 | |
| 660 | /* 9.2.5 CM service accept */ |
| 661 | int gsm48_tx_mm_serv_ack(struct gsm_subscriber_connection *conn) |
| 662 | { |
| 663 | struct msgb *msg = gsm48_msgb_alloc(); |
| 664 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 665 | |
| 666 | msg->lchan = conn->lchan; |
| 667 | |
| 668 | gh->proto_discr = GSM48_PDISC_MM; |
| 669 | gh->msg_type = GSM48_MT_MM_CM_SERV_ACC; |
| 670 | |
| 671 | DEBUGP(DMM, "-> CM SERVICE ACK\n"); |
| 672 | |
| 673 | return gsm0808_submit_dtap(conn, msg, 0, 0); |
| 674 | } |
| 675 | |
| 676 | /* 9.2.6 CM service reject */ |
| 677 | int gsm48_tx_mm_serv_rej(struct gsm_subscriber_connection *conn, |
| 678 | enum gsm48_reject_value value) |
| 679 | { |
| 680 | struct msgb *msg; |
| 681 | |
| 682 | msg = gsm48_create_mm_serv_rej(value); |
| 683 | if (!msg) { |
| 684 | LOGP(DMM, LOGL_ERROR, "Failed to allocate CM Service Reject.\n"); |
| 685 | return -1; |
| 686 | } |
| 687 | |
| 688 | DEBUGP(DMM, "-> CM SERVICE Reject cause: %d\n", value); |
| 689 | |
| 690 | return gsm0808_submit_dtap(conn, msg, 0, 0); |
| 691 | } |