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 |
| 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 | a269ece | 2009-08-21 04:57:35 +0200 | [diff] [blame] | 28 | #include <errno.h> |
Holger Hans Peter Freyther | 3689710 | 2009-08-01 07:26:59 +0200 | [diff] [blame] | 29 | #include <netinet/in.h> |
| 30 | |
| 31 | #include <openbsc/msgb.h> |
| 32 | #include <openbsc/debug.h> |
| 33 | #include <openbsc/gsm_04_08.h> |
| 34 | #include <openbsc/transaction.h> |
Holger Hans Peter Freyther | 1e43b8d | 2009-08-21 05:18:21 +0200 | [diff] [blame] | 35 | #include <openbsc/paging.h> |
| 36 | #include <openbsc/signal.h> |
Holger Hans Peter Freyther | 3689710 | 2009-08-01 07:26:59 +0200 | [diff] [blame] | 37 | |
| 38 | #define GSM48_ALLOC_SIZE 1024 |
| 39 | #define GSM48_ALLOC_HEADROOM 128 |
| 40 | |
| 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 | |
| 45 | |
| 46 | const char *gsm0408_cc_msg_names[] = { |
| 47 | "unknown 0x00", |
| 48 | "ALERTING", |
| 49 | "CALL_PROC", |
| 50 | "PROGRESS", |
| 51 | "ESTAB", |
| 52 | "SETUP", |
| 53 | "ESTAB_CONF", |
| 54 | "CONNECT", |
| 55 | "CALL_CONF", |
| 56 | "START_CC", |
| 57 | "unknown 0x0a", |
| 58 | "RECALL", |
| 59 | "unknown 0x0c", |
| 60 | "unknown 0x0d", |
| 61 | "EMERG_SETUP", |
| 62 | "CONNECT_ACK", |
| 63 | "USER_INFO", |
| 64 | "unknown 0x11", |
| 65 | "unknown 0x12", |
| 66 | "MODIFY_REJECT", |
| 67 | "unknown 0x14", |
| 68 | "unknown 0x15", |
| 69 | "unknown 0x16", |
| 70 | "MODIFY", |
| 71 | "HOLD", |
| 72 | "HOLD_ACK", |
| 73 | "HOLD_REJ", |
| 74 | "unknown 0x1b", |
| 75 | "RETR", |
| 76 | "RETR_ACK", |
| 77 | "RETR_REJ", |
| 78 | "MODIFY_COMPL", |
| 79 | "unknown 0x20", |
| 80 | "unknown 0x21", |
| 81 | "unknown 0x22", |
| 82 | "unknown 0x23", |
| 83 | "unknown 0x24", |
| 84 | "DISCONNECT", |
| 85 | "unknown 0x26", |
| 86 | "unknown 0x27", |
| 87 | "unknown 0x28", |
| 88 | "unknown 0x29", |
| 89 | "RELEASE_COMPL", |
| 90 | "unknown 0x2b", |
| 91 | "unknown 0x2c", |
| 92 | "RELEASE", |
| 93 | "unknown 0x2e", |
| 94 | "unknown 0x2f", |
| 95 | "unknown 0x30", |
| 96 | "STOP_DTMF", |
| 97 | "STOP_DTMF_ACK", |
| 98 | "unknown 0x33", |
| 99 | "STATUS_ENQ", |
| 100 | "START_DTMF", |
| 101 | "START_DTMF_ACK", |
| 102 | "START_DTMF_REJ", |
| 103 | "unknown 0x38", |
| 104 | "CONG_CTRL", |
| 105 | "FACILITY", |
| 106 | "unknown 0x3b", |
| 107 | "STATUS", |
| 108 | "unknown 0x3c", |
| 109 | "NOTIFY", |
| 110 | "unknown 0x3f", |
| 111 | }; |
| 112 | |
| 113 | |
| 114 | struct msgb *gsm48_msgb_alloc(void) |
| 115 | { |
| 116 | return msgb_alloc_headroom(GSM48_ALLOC_SIZE, GSM48_ALLOC_HEADROOM, |
| 117 | "GSM 04.08"); |
| 118 | } |
| 119 | |
| 120 | int gsm48_sendmsg(struct msgb *msg, struct gsm_trans *trans) |
| 121 | { |
| 122 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msg->data; |
| 123 | |
| 124 | /* if we get passed a transaction reference, do some common |
| 125 | * work that the caller no longer has to do */ |
| 126 | if (trans) { |
| 127 | gh->proto_discr = trans->protocol | (trans->transaction_id << 4); |
| 128 | msg->lchan = trans->lchan; |
| 129 | } |
| 130 | |
| 131 | if (msg->lchan) { |
| 132 | msg->trx = msg->lchan->ts->trx; |
| 133 | |
| 134 | if ((gh->proto_discr & GSM48_PDISC_MASK) == GSM48_PDISC_CC) |
| 135 | DEBUGP(DCC, "(bts %d trx %d ts %d ti %02x) " |
| 136 | "Sending '%s' to MS.\n", msg->trx->bts->nr, |
| 137 | msg->trx->nr, msg->lchan->ts->nr, |
| 138 | gh->proto_discr & 0xf0, |
| 139 | gsm0408_cc_msg_names[gh->msg_type & 0x3f]); |
| 140 | else |
| 141 | DEBUGP(DCC, "(bts %d trx %d ts %d pd %02x) " |
| 142 | "Sending 0x%02x to MS.\n", msg->trx->bts->nr, |
| 143 | msg->trx->nr, msg->lchan->ts->nr, |
| 144 | gh->proto_discr, gh->msg_type); |
| 145 | } |
| 146 | |
| 147 | msg->l3h = msg->data; |
| 148 | |
| 149 | return rsl_data_request(msg, 0); |
| 150 | } |
| 151 | |
| 152 | static void to_bcd(u_int8_t *bcd, u_int16_t val) |
| 153 | { |
| 154 | bcd[2] = val % 10; |
| 155 | val = val / 10; |
| 156 | bcd[1] = val % 10; |
| 157 | val = val / 10; |
| 158 | bcd[0] = val % 10; |
| 159 | val = val / 10; |
| 160 | } |
| 161 | |
Holger Hans Peter Freyther | 1e6ef9f | 2009-08-19 07:54:59 +0200 | [diff] [blame] | 162 | static char bcd2char(u_int8_t bcd) |
| 163 | { |
| 164 | if (bcd < 0xa) |
| 165 | return '0' + bcd; |
| 166 | else |
| 167 | return 'A' + (bcd - 0xa); |
| 168 | } |
| 169 | |
Holger Hans Peter Freyther | 20a0f32 | 2009-08-20 08:41:24 +0200 | [diff] [blame] | 170 | /* only works for numbers in ascci */ |
| 171 | static u_int8_t char2bcd(char c) |
| 172 | { |
| 173 | return c - 0x30; |
| 174 | } |
| 175 | |
Holger Hans Peter Freyther | 1e6ef9f | 2009-08-19 07:54:59 +0200 | [diff] [blame] | 176 | |
Holger Hans Peter Freyther | 3689710 | 2009-08-01 07:26:59 +0200 | [diff] [blame] | 177 | void gsm0408_generate_lai(struct gsm48_loc_area_id *lai48, u_int16_t mcc, |
| 178 | u_int16_t mnc, u_int16_t lac) |
| 179 | { |
| 180 | u_int8_t bcd[3]; |
| 181 | |
| 182 | to_bcd(bcd, mcc); |
| 183 | lai48->digits[0] = bcd[0] | (bcd[1] << 4); |
| 184 | lai48->digits[1] = bcd[2]; |
| 185 | |
| 186 | to_bcd(bcd, mnc); |
| 187 | /* FIXME: do we need three-digit MNC? See Table 10.5.3 */ |
| 188 | #if 0 |
| 189 | lai48->digits[1] |= bcd[2] << 4; |
| 190 | lai48->digits[2] = bcd[0] | (bcd[1] << 4); |
| 191 | #else |
| 192 | lai48->digits[1] |= 0xf << 4; |
| 193 | lai48->digits[2] = bcd[1] | (bcd[2] << 4); |
| 194 | #endif |
| 195 | |
| 196 | lai48->lac = htons(lac); |
| 197 | } |
| 198 | |
Holger Hans Peter Freyther | 20a0f32 | 2009-08-20 08:41:24 +0200 | [diff] [blame] | 199 | int gsm48_generate_mid_from_tmsi(u_int8_t *buf, u_int32_t tmsi) |
Holger Hans Peter Freyther | 3689710 | 2009-08-01 07:26:59 +0200 | [diff] [blame] | 200 | { |
| 201 | u_int32_t *tptr = (u_int32_t *) &buf[3]; |
| 202 | |
| 203 | buf[0] = GSM48_IE_MOBILE_ID; |
| 204 | buf[1] = GSM48_TMSI_LEN; |
| 205 | buf[2] = 0xf0 | GSM_MI_TYPE_TMSI; |
| 206 | *tptr = htonl(tmsi); |
| 207 | |
| 208 | return 7; |
| 209 | } |
| 210 | |
Holger Hans Peter Freyther | 20a0f32 | 2009-08-20 08:41:24 +0200 | [diff] [blame] | 211 | int gsm48_generate_mid_from_imsi(u_int8_t *buf, const char *imsi) |
| 212 | { |
| 213 | unsigned int length = strlen(imsi), i, off = 0; |
| 214 | u_int8_t odd = (length & 0x1) == 1; |
| 215 | |
| 216 | buf[0] = GSM48_IE_MOBILE_ID; |
| 217 | buf[2] = char2bcd(imsi[0]) << 4 | GSM_MI_TYPE_IMSI | (odd << 3); |
| 218 | |
| 219 | /* if the length is even we will fill half of the last octet */ |
| 220 | if (odd) |
| 221 | buf[1] = (length + 1) >> 1; |
| 222 | else |
| 223 | buf[1] = (length + 2) >> 1; |
| 224 | |
| 225 | for (i = 1; i < buf[1]; ++i) { |
| 226 | u_int8_t lower, upper; |
| 227 | |
| 228 | lower = char2bcd(imsi[++off]); |
| 229 | if (!odd && off + 1 == length) |
| 230 | upper = 0x0f; |
| 231 | else |
| 232 | upper = char2bcd(imsi[++off]) & 0x0f; |
| 233 | |
| 234 | buf[2 + i] = (upper << 4) | lower; |
| 235 | } |
| 236 | |
| 237 | return 2 + buf[1]; |
| 238 | } |
| 239 | |
Holger Hans Peter Freyther | 3689710 | 2009-08-01 07:26:59 +0200 | [diff] [blame] | 240 | /* Section 9.1.8 / Table 9.9 */ |
| 241 | struct chreq { |
| 242 | u_int8_t val; |
| 243 | u_int8_t mask; |
| 244 | enum chreq_type type; |
| 245 | }; |
| 246 | |
| 247 | /* If SYSTEM INFORMATION TYPE 4 NECI bit == 1 */ |
| 248 | static const struct chreq chreq_type_neci1[] = { |
| 249 | { 0xa0, 0xe0, CHREQ_T_EMERG_CALL }, |
| 250 | { 0xc0, 0xe0, CHREQ_T_CALL_REEST_TCH_F }, |
| 251 | { 0x68, 0xfc, CHREQ_T_CALL_REEST_TCH_H }, |
| 252 | { 0x6c, 0xfc, CHREQ_T_CALL_REEST_TCH_H_DBL }, |
| 253 | { 0xe0, 0xe0, CHREQ_T_SDCCH }, |
| 254 | { 0x40, 0xf0, CHREQ_T_VOICE_CALL_TCH_H }, |
| 255 | { 0x50, 0xf0, CHREQ_T_DATA_CALL_TCH_H }, |
| 256 | { 0x00, 0xf0, CHREQ_T_LOCATION_UPD }, |
| 257 | { 0x10, 0xf0, CHREQ_T_SDCCH }, |
| 258 | { 0x80, 0xe0, CHREQ_T_PAG_R_ANY }, |
| 259 | { 0x20, 0xf0, CHREQ_T_PAG_R_TCH_F }, |
| 260 | { 0x30, 0xf0, CHREQ_T_PAG_R_TCH_FH }, |
| 261 | }; |
| 262 | |
| 263 | /* If SYSTEM INFORMATION TYPE 4 NECI bit == 0 */ |
| 264 | static const struct chreq chreq_type_neci0[] = { |
| 265 | { 0xa0, 0xe0, CHREQ_T_EMERG_CALL }, |
| 266 | { 0xc0, 0xe0, CHREQ_T_CALL_REEST_TCH_H }, |
| 267 | { 0xe0, 0xe0, CHREQ_T_TCH_F }, |
| 268 | { 0x50, 0xf0, CHREQ_T_DATA_CALL_TCH_H }, |
| 269 | { 0x00, 0xe0, CHREQ_T_LOCATION_UPD }, |
| 270 | { 0x80, 0xe0, CHREQ_T_PAG_R_ANY }, |
| 271 | { 0x20, 0xf0, CHREQ_T_PAG_R_TCH_F }, |
| 272 | { 0x30, 0xf0, CHREQ_T_PAG_R_TCH_FH }, |
| 273 | }; |
| 274 | |
| 275 | static const enum gsm_chan_t ctype_by_chreq[] = { |
| 276 | [CHREQ_T_EMERG_CALL] = GSM_LCHAN_TCH_F, |
| 277 | [CHREQ_T_CALL_REEST_TCH_F] = GSM_LCHAN_TCH_F, |
| 278 | [CHREQ_T_CALL_REEST_TCH_H] = GSM_LCHAN_TCH_H, |
| 279 | [CHREQ_T_CALL_REEST_TCH_H_DBL] = GSM_LCHAN_TCH_H, |
| 280 | [CHREQ_T_SDCCH] = GSM_LCHAN_SDCCH, |
| 281 | [CHREQ_T_TCH_F] = GSM_LCHAN_TCH_F, |
| 282 | [CHREQ_T_VOICE_CALL_TCH_H] = GSM_LCHAN_TCH_H, |
| 283 | [CHREQ_T_DATA_CALL_TCH_H] = GSM_LCHAN_TCH_H, |
| 284 | [CHREQ_T_LOCATION_UPD] = GSM_LCHAN_SDCCH, |
| 285 | [CHREQ_T_PAG_R_ANY] = GSM_LCHAN_SDCCH, |
| 286 | [CHREQ_T_PAG_R_TCH_F] = GSM_LCHAN_TCH_F, |
| 287 | [CHREQ_T_PAG_R_TCH_FH] = GSM_LCHAN_TCH_F, |
| 288 | }; |
| 289 | |
| 290 | static const enum gsm_chreq_reason_t reason_by_chreq[] = { |
| 291 | [CHREQ_T_EMERG_CALL] = GSM_CHREQ_REASON_EMERG, |
| 292 | [CHREQ_T_CALL_REEST_TCH_F] = GSM_CHREQ_REASON_CALL, |
| 293 | [CHREQ_T_CALL_REEST_TCH_H] = GSM_CHREQ_REASON_CALL, |
| 294 | [CHREQ_T_CALL_REEST_TCH_H_DBL] = GSM_CHREQ_REASON_CALL, |
| 295 | [CHREQ_T_SDCCH] = GSM_CHREQ_REASON_OTHER, |
| 296 | [CHREQ_T_TCH_F] = GSM_CHREQ_REASON_OTHER, |
| 297 | [CHREQ_T_VOICE_CALL_TCH_H] = GSM_CHREQ_REASON_OTHER, |
| 298 | [CHREQ_T_DATA_CALL_TCH_H] = GSM_CHREQ_REASON_OTHER, |
| 299 | [CHREQ_T_LOCATION_UPD] = GSM_CHREQ_REASON_LOCATION_UPD, |
| 300 | [CHREQ_T_PAG_R_ANY] = GSM_CHREQ_REASON_PAG, |
| 301 | [CHREQ_T_PAG_R_TCH_F] = GSM_CHREQ_REASON_PAG, |
| 302 | [CHREQ_T_PAG_R_TCH_FH] = GSM_CHREQ_REASON_PAG, |
| 303 | }; |
| 304 | |
Holger Hans Peter Freyther | 96c8982 | 2009-11-16 17:12:38 +0100 | [diff] [blame] | 305 | enum gsm_chan_t get_ctype_by_chreq(struct gsm_bts *bts, u_int8_t ra, int neci) |
Holger Hans Peter Freyther | 3689710 | 2009-08-01 07:26:59 +0200 | [diff] [blame] | 306 | { |
| 307 | int i; |
| 308 | /* FIXME: determine if we set NECI = 0 in the BTS SI4 */ |
| 309 | |
| 310 | for (i = 0; i < ARRAY_SIZE(chreq_type_neci0); i++) { |
Holger Hans Peter Freyther | 96c8982 | 2009-11-16 17:12:38 +0100 | [diff] [blame] | 311 | const struct chreq *chr = neci ? &chreq_type_neci1[i] : &chreq_type_neci0[i]; |
Holger Hans Peter Freyther | 3689710 | 2009-08-01 07:26:59 +0200 | [diff] [blame] | 312 | if ((ra & chr->mask) == chr->val) |
| 313 | return ctype_by_chreq[chr->type]; |
| 314 | } |
| 315 | fprintf(stderr, "Unknown CHANNEL REQUEST RQD 0x%02x\n", ra); |
| 316 | return GSM_LCHAN_SDCCH; |
| 317 | } |
| 318 | |
Holger Hans Peter Freyther | 96c8982 | 2009-11-16 17:12:38 +0100 | [diff] [blame] | 319 | enum gsm_chreq_reason_t get_reason_by_chreq(struct gsm_bts *bts, u_int8_t ra, int neci) |
Holger Hans Peter Freyther | 3689710 | 2009-08-01 07:26:59 +0200 | [diff] [blame] | 320 | { |
| 321 | int i; |
| 322 | /* FIXME: determine if we set NECI = 0 in the BTS SI4 */ |
| 323 | |
| 324 | for (i = 0; i < ARRAY_SIZE(chreq_type_neci0); i++) { |
Holger Hans Peter Freyther | 96c8982 | 2009-11-16 17:12:38 +0100 | [diff] [blame] | 325 | const struct chreq *chr = neci ? &chreq_type_neci1[i] : &chreq_type_neci0[i]; |
Holger Hans Peter Freyther | 3689710 | 2009-08-01 07:26:59 +0200 | [diff] [blame] | 326 | if ((ra & chr->mask) == chr->val) |
| 327 | return reason_by_chreq[chr->type]; |
| 328 | } |
| 329 | fprintf(stderr, "Unknown CHANNEL REQUEST REASON 0x%02x\n", ra); |
| 330 | return GSM_CHREQ_REASON_OTHER; |
| 331 | } |
| 332 | |
| 333 | /* 7.1.7 and 9.1.7: RR CHANnel RELease */ |
| 334 | int gsm48_send_rr_release(struct gsm_lchan *lchan) |
| 335 | { |
| 336 | struct msgb *msg = gsm48_msgb_alloc(); |
| 337 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 338 | u_int8_t *cause; |
| 339 | |
| 340 | msg->lchan = lchan; |
| 341 | gh->proto_discr = GSM48_PDISC_RR; |
| 342 | gh->msg_type = GSM48_MT_RR_CHAN_REL; |
| 343 | |
| 344 | cause = msgb_put(msg, 1); |
| 345 | cause[0] = GSM48_RR_CAUSE_NORMAL; |
| 346 | |
| 347 | DEBUGP(DRR, "Sending Channel Release: Chan: Number: %d Type: %d\n", |
| 348 | lchan->nr, lchan->type); |
| 349 | |
| 350 | /* Send actual release request to MS */ |
| 351 | gsm48_sendmsg(msg, NULL); |
| 352 | /* FIXME: Start Timer T3109 */ |
| 353 | |
| 354 | /* Deactivate the SACCH on the BTS side */ |
| 355 | return rsl_deact_sacch(lchan); |
| 356 | } |
| 357 | |
Holger Hans Peter Freyther | 1e6ef9f | 2009-08-19 07:54:59 +0200 | [diff] [blame] | 358 | /* Convert Mobile Identity (10.5.1.4) to string */ |
| 359 | int gsm48_mi_to_string(char *string, const int str_len, const u_int8_t *mi, const int mi_len) |
| 360 | { |
| 361 | int i; |
| 362 | u_int8_t mi_type; |
| 363 | char *str_cur = string; |
| 364 | u_int32_t tmsi; |
| 365 | |
| 366 | mi_type = mi[0] & GSM_MI_TYPE_MASK; |
| 367 | |
| 368 | switch (mi_type) { |
| 369 | case GSM_MI_TYPE_NONE: |
| 370 | break; |
| 371 | case GSM_MI_TYPE_TMSI: |
| 372 | /* Table 10.5.4.3, reverse generate_mid_from_tmsi */ |
| 373 | if (mi_len == GSM48_TMSI_LEN && mi[0] == (0xf0 | GSM_MI_TYPE_TMSI)) { |
| 374 | memcpy(&tmsi, &mi[1], 4); |
| 375 | tmsi = ntohl(tmsi); |
| 376 | return snprintf(string, str_len, "%u", tmsi); |
| 377 | } |
| 378 | break; |
| 379 | case GSM_MI_TYPE_IMSI: |
| 380 | case GSM_MI_TYPE_IMEI: |
| 381 | case GSM_MI_TYPE_IMEISV: |
| 382 | *str_cur++ = bcd2char(mi[0] >> 4); |
| 383 | |
| 384 | for (i = 1; i < mi_len; i++) { |
| 385 | if (str_cur + 2 >= string + str_len) |
| 386 | return str_cur - string; |
| 387 | *str_cur++ = bcd2char(mi[i] & 0xf); |
| 388 | /* skip last nibble in last input byte when GSM_EVEN */ |
| 389 | if( (i != mi_len-1) || (mi[0] & GSM_MI_ODD)) |
| 390 | *str_cur++ = bcd2char(mi[i] >> 4); |
| 391 | } |
| 392 | break; |
| 393 | default: |
| 394 | break; |
| 395 | } |
| 396 | *str_cur++ = '\0'; |
| 397 | |
| 398 | return str_cur - string; |
| 399 | } |
| 400 | |
Holger Hans Peter Freyther | a269ece | 2009-08-21 04:57:35 +0200 | [diff] [blame] | 401 | |
| 402 | int send_siemens_mrpci(struct gsm_lchan *lchan, |
| 403 | u_int8_t *classmark2_lv) |
| 404 | { |
| 405 | struct rsl_mrpci mrpci; |
| 406 | |
| 407 | if (classmark2_lv[0] < 2) |
| 408 | return -EINVAL; |
| 409 | |
| 410 | mrpci.power_class = classmark2_lv[1] & 0x7; |
| 411 | mrpci.vgcs_capable = classmark2_lv[2] & (1 << 1); |
| 412 | mrpci.vbs_capable = classmark2_lv[2] & (1 <<2); |
| 413 | mrpci.gsm_phase = (classmark2_lv[1]) >> 5 & 0x3; |
| 414 | |
| 415 | return rsl_siemens_mrpci(lchan, &mrpci); |
| 416 | } |
| 417 | |
Holger Hans Peter Freyther | 1e43b8d | 2009-08-21 05:18:21 +0200 | [diff] [blame] | 418 | int gsm48_paging_extract_mi(struct msgb *msg, char *mi_string, u_int8_t *mi_type) |
| 419 | { |
| 420 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 421 | u_int8_t *classmark2_lv = gh->data + 1; |
| 422 | u_int8_t *mi_lv = gh->data + 2 + *classmark2_lv; |
| 423 | *mi_type = mi_lv[1] & GSM_MI_TYPE_MASK; |
| 424 | |
| 425 | return gsm48_mi_to_string(mi_string, GSM48_MI_SIZE, mi_lv+1, *mi_lv); |
| 426 | } |
| 427 | |
| 428 | int gsm48_handle_paging_resp(struct msgb *msg, struct gsm_subscriber *subscr) |
| 429 | { |
| 430 | struct gsm_bts *bts = msg->lchan->ts->trx->bts; |
| 431 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 432 | u_int8_t *classmark2_lv = gh->data + 1; |
| 433 | struct paging_signal_data sig_data; |
| 434 | |
| 435 | if (is_siemens_bts(bts)) |
| 436 | send_siemens_mrpci(msg->lchan, classmark2_lv); |
| 437 | |
| 438 | if (!msg->lchan->subscr) { |
| 439 | msg->lchan->subscr = subscr; |
| 440 | } else if (msg->lchan->subscr != subscr) { |
| 441 | DEBUGP(DRR, "<- Channel already owned by someone else?\n"); |
| 442 | subscr_put(subscr); |
| 443 | return -EINVAL; |
| 444 | } else { |
| 445 | DEBUGP(DRR, "<- Channel already owned by us\n"); |
| 446 | subscr_put(subscr); |
| 447 | subscr = msg->lchan->subscr; |
| 448 | } |
| 449 | |
| 450 | sig_data.subscr = subscr; |
| 451 | sig_data.bts = msg->lchan->ts->trx->bts; |
| 452 | sig_data.lchan = msg->lchan; |
| 453 | |
| 454 | dispatch_signal(SS_PAGING, S_PAGING_COMPLETED, &sig_data); |
| 455 | |
| 456 | /* Stop paging on the bts we received the paging response */ |
| 457 | paging_request_stop(msg->trx->bts, subscr, msg->lchan); |
| 458 | return 0; |
| 459 | } |
Holger Hans Peter Freyther | 3d76e88 | 2009-10-05 13:25:06 +0200 | [diff] [blame] | 460 | |
| 461 | /* Chapter 9.1.9: Ciphering Mode Command */ |
Holger Hans Peter Freyther | b94719d | 2009-10-05 14:00:14 +0200 | [diff] [blame] | 462 | 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] | 463 | { |
| 464 | struct msgb *msg = gsm48_msgb_alloc(); |
| 465 | struct gsm48_hdr *gh; |
| 466 | u_int8_t ciph_mod_set; |
| 467 | |
| 468 | msg->lchan = lchan; |
| 469 | |
| 470 | DEBUGP(DRR, "TX CIPHERING MODE CMD\n"); |
| 471 | |
| 472 | if (lchan->encr.alg_id <= RSL_ENC_ALG_A5(0)) |
| 473 | ciph_mod_set = 0; |
| 474 | else |
| 475 | ciph_mod_set = (lchan->encr.alg_id-2)<<1 | 1; |
| 476 | |
| 477 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 1); |
| 478 | gh->proto_discr = GSM48_PDISC_RR; |
| 479 | gh->msg_type = GSM48_MT_RR_CIPH_M_CMD; |
Holger Hans Peter Freyther | b94719d | 2009-10-05 14:00:14 +0200 | [diff] [blame] | 480 | 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] | 481 | |
| 482 | return rsl_encryption_cmd(msg); |
| 483 | } |
| 484 | |
Holger Hans Peter Freyther | 942ff17 | 2009-10-22 11:47:45 +0200 | [diff] [blame] | 485 | /* Chapter 9.1.2: Assignment Command */ |
| 486 | int gsm48_send_rr_ass_cmd(struct gsm_lchan *lchan, u_int8_t power_command) |
| 487 | { |
| 488 | struct msgb *msg = gsm48_msgb_alloc(); |
| 489 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 490 | struct gsm48_ass_cmd *ass = |
| 491 | (struct gsm48_ass_cmd *) msgb_put(msg, sizeof(*ass)); |
| 492 | u_int16_t arfcn = lchan->ts->trx->arfcn & 0x3ff; |
| 493 | |
| 494 | DEBUGP(DRR, "-> ASSIGNMENT COMMAND tch_mode=0x%02x\n", lchan->tch_mode); |
| 495 | |
| 496 | msg->lchan = lchan; |
| 497 | gh->proto_discr = GSM48_PDISC_RR; |
| 498 | gh->msg_type = GSM48_MT_RR_ASS_CMD; |
| 499 | |
| 500 | /* |
| 501 | * fill the channel information element, this code |
| 502 | * should probably be shared with rsl_rx_chan_rqd(), |
| 503 | * gsm48_tx_chan_mode_modify. But beware that 10.5.2.5 |
| 504 | * 10.5.2.5.a have slightly different semantic for |
| 505 | * the chan_desc. But as long as multi-slot configurations |
| 506 | * are not used we seem to be fine. |
| 507 | */ |
| 508 | ass->chan_desc.chan_nr = lchan2chan_nr(lchan); |
| 509 | ass->chan_desc.h0.tsc = lchan->ts->trx->bts->tsc; |
| 510 | ass->chan_desc.h0.h = 0; |
| 511 | ass->chan_desc.h0.arfcn_high = arfcn >> 8; |
| 512 | ass->chan_desc.h0.arfcn_low = arfcn & 0xff; |
| 513 | ass->power_command = power_command; |
| 514 | |
| 515 | return gsm48_sendmsg(msg, NULL); |
| 516 | } |
Holger Hans Peter Freyther | cf0f336 | 2009-10-22 15:13:00 +0200 | [diff] [blame] | 517 | |
| 518 | /* 9.1.5 Channel mode modify: Modify the mode on the MS side */ |
| 519 | int gsm48_tx_chan_mode_modify(struct gsm_lchan *lchan, u_int8_t mode) |
| 520 | { |
| 521 | struct msgb *msg = gsm48_msgb_alloc(); |
| 522 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 523 | struct gsm48_chan_mode_modify *cmm = |
| 524 | (struct gsm48_chan_mode_modify *) msgb_put(msg, sizeof(*cmm)); |
| 525 | u_int16_t arfcn = lchan->ts->trx->arfcn & 0x3ff; |
| 526 | |
| 527 | DEBUGP(DRR, "-> CHANNEL MODE MODIFY mode=0x%02x\n", mode); |
| 528 | |
| 529 | lchan->tch_mode = mode; |
| 530 | msg->lchan = lchan; |
| 531 | gh->proto_discr = GSM48_PDISC_RR; |
| 532 | gh->msg_type = GSM48_MT_RR_CHAN_MODE_MODIF; |
| 533 | |
| 534 | /* fill the channel information element, this code |
| 535 | * should probably be shared with rsl_rx_chan_rqd() */ |
| 536 | cmm->chan_desc.chan_nr = lchan2chan_nr(lchan); |
| 537 | cmm->chan_desc.h0.tsc = lchan->ts->trx->bts->tsc; |
| 538 | cmm->chan_desc.h0.h = 0; |
| 539 | cmm->chan_desc.h0.arfcn_high = arfcn >> 8; |
| 540 | cmm->chan_desc.h0.arfcn_low = arfcn & 0xff; |
| 541 | cmm->mode = mode; |
| 542 | |
| 543 | return gsm48_sendmsg(msg, NULL); |
| 544 | } |
| 545 | |
| 546 | int gsm48_lchan_modify(struct gsm_lchan *lchan, u_int8_t lchan_mode) |
| 547 | { |
| 548 | int rc; |
| 549 | |
| 550 | rc = gsm48_tx_chan_mode_modify(lchan, lchan_mode); |
| 551 | if (rc < 0) |
| 552 | return rc; |
| 553 | |
| 554 | /* FIXME: we not only need to do this after mode modify, but |
| 555 | * also after channel activation */ |
| 556 | if (is_ipaccess_bts(lchan->ts->trx->bts) && lchan_mode != GSM48_CMODE_SIGN) |
| 557 | rc = rsl_ipacc_bind(lchan); |
| 558 | |
| 559 | return rc; |
| 560 | } |
| 561 | |
Holger Hans Peter Freyther | 9e6d6ce | 2009-10-22 15:23:11 +0200 | [diff] [blame] | 562 | int gsm48_rx_rr_modif_ack(struct msgb *msg) |
| 563 | { |
| 564 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 565 | struct gsm48_chan_mode_modify *mod = |
| 566 | (struct gsm48_chan_mode_modify *) gh->data; |
| 567 | |
| 568 | DEBUGP(DRR, "CHANNEL MODE MODIFY ACK\n"); |
| 569 | |
| 570 | if (mod->mode != msg->lchan->tch_mode) { |
| 571 | DEBUGP(DRR, "CHANNEL MODE change failed. Wanted: %d Got: %d\n", |
| 572 | msg->lchan->tch_mode, mod->mode); |
| 573 | return -1; |
| 574 | } |
| 575 | |
| 576 | /* update the channel type */ |
| 577 | switch (mod->mode) { |
| 578 | case GSM48_CMODE_SIGN: |
| 579 | msg->lchan->rsl_cmode = RSL_CMOD_SPD_SIGN; |
| 580 | break; |
| 581 | case GSM48_CMODE_SPEECH_V1: |
| 582 | case GSM48_CMODE_SPEECH_EFR: |
| 583 | case GSM48_CMODE_SPEECH_AMR: |
| 584 | msg->lchan->rsl_cmode = RSL_CMOD_SPD_SPEECH; |
| 585 | break; |
| 586 | case GSM48_CMODE_DATA_14k5: |
| 587 | case GSM48_CMODE_DATA_12k0: |
| 588 | case GSM48_CMODE_DATA_6k0: |
| 589 | case GSM48_CMODE_DATA_3k6: |
| 590 | msg->lchan->rsl_cmode = RSL_CMOD_SPD_DATA; |
| 591 | break; |
| 592 | } |
| 593 | |
| 594 | /* We've successfully modified the MS side of the channel, |
| 595 | * now go on to modify the BTS side of the channel */ |
| 596 | return rsl_chan_mode_modify_req(msg->lchan); |
| 597 | } |