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