Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [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 | |
| 4 | /* (C) 2008 by Harald Welte <laforge@gnumonks.org> |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 5 | * |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 6 | * All Rights Reserved |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License along |
| 19 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 20 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 21 | * |
| 22 | */ |
| 23 | |
| 24 | |
| 25 | #include <stdio.h> |
| 26 | #include <stdlib.h> |
| 27 | #include <string.h> |
| 28 | #include <errno.h> |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 29 | #include <netinet/in.h> |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 30 | |
Harald Welte | 75a983f | 2008-12-27 21:34:06 +0000 | [diff] [blame] | 31 | #include <openbsc/db.h> |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 32 | #include <openbsc/msgb.h> |
| 33 | #include <openbsc/debug.h> |
| 34 | #include <openbsc/gsm_data.h> |
| 35 | #include <openbsc/gsm_subscriber.h> |
Daniel Willmann | 8b3390e | 2008-12-28 00:31:09 +0000 | [diff] [blame] | 36 | #include <openbsc/gsm_04_11.h> |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 37 | #include <openbsc/gsm_04_08.h> |
| 38 | #include <openbsc/abis_rsl.h> |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 39 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 40 | #define GSM48_ALLOC_SIZE 1024 |
| 41 | #define GSM48_ALLOC_HEADROOM 128 |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 42 | |
Harald Welte | 65e74cc | 2008-12-29 01:55:35 +0000 | [diff] [blame] | 43 | static int gsm48_tx_simple(struct gsm_lchan *lchan, |
| 44 | u_int8_t pdisc, u_int8_t msg_type); |
| 45 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 46 | struct gsm_lai { |
| 47 | u_int16_t mcc; |
| 48 | u_int16_t mnc; |
| 49 | u_int16_t lac; |
| 50 | }; |
| 51 | |
| 52 | static void parse_lai(struct gsm_lai *lai, const struct gsm48_loc_area_id *lai48) |
| 53 | { |
| 54 | u_int8_t dig[4]; |
| 55 | |
| 56 | /* MCC */ |
| 57 | dig[1] = lai48->digits[0] & 0x0f; |
| 58 | dig[2] = lai48->digits[0] >> 4; |
| 59 | dig[3] = lai48->digits[1] & 0x0f; |
| 60 | lai->mcc = dig[3] * 100 + dig[2]; |
| 61 | |
| 62 | /* MNC */ |
| 63 | dig[1] = lai48->digits[1] >> 4; |
| 64 | dig[2] = lai48->digits[2] & 0x0f; |
| 65 | dig[3] = lai48->digits[2] >> 4; |
| 66 | lai->mnc = dig[3] * 100 + dig[2]; |
| 67 | |
| 68 | lai->lac = lai48->lac; |
| 69 | } |
| 70 | |
| 71 | static void to_bcd(u_int8_t *bcd, u_int16_t val) |
| 72 | { |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 73 | bcd[2] = val % 10; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 74 | val = val / 10; |
| 75 | bcd[1] = val % 10; |
| 76 | val = val / 10; |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 77 | bcd[0] = val % 10; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 78 | val = val / 10; |
| 79 | } |
| 80 | |
Holger Freyther | 1774661 | 2008-12-28 16:32:44 +0000 | [diff] [blame] | 81 | void gsm0408_generate_lai(struct gsm48_loc_area_id *lai48, u_int16_t mcc, |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 82 | u_int16_t mnc, u_int16_t lac) |
| 83 | { |
| 84 | u_int8_t bcd[3]; |
| 85 | |
| 86 | to_bcd(bcd, mcc); |
| 87 | lai48->digits[0] = bcd[0] | (bcd[1] << 4); |
| 88 | lai48->digits[1] = bcd[2]; |
| 89 | |
| 90 | to_bcd(bcd, mnc); |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 91 | /* FIXME: do we need three-digit MNC? See Table 10.5.3 */ |
| 92 | #if 0 |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 93 | lai48->digits[1] |= bcd[2] << 4; |
| 94 | lai48->digits[2] = bcd[0] | (bcd[1] << 4); |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 95 | #else |
| 96 | lai48->digits[1] |= 0xf << 4; |
| 97 | lai48->digits[2] = bcd[1] | (bcd[2] << 4); |
| 98 | #endif |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 99 | |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 100 | lai48->lac = htons(lac); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 101 | } |
| 102 | |
Harald Welte | 255539c | 2008-12-28 02:26:27 +0000 | [diff] [blame] | 103 | #define TMSI_LEN 5 |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 104 | #define MID_TMSI_LEN (TMSI_LEN + 2) |
| 105 | |
Harald Welte | 255539c | 2008-12-28 02:26:27 +0000 | [diff] [blame] | 106 | int generate_mid_from_tmsi(u_int8_t *buf, u_int32_t tmsi) |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 107 | { |
Harald Welte | 65e74cc | 2008-12-29 01:55:35 +0000 | [diff] [blame] | 108 | u_int32_t *tptr = (u_int32_t *) &buf[3]; |
Harald Welte | 255539c | 2008-12-28 02:26:27 +0000 | [diff] [blame] | 109 | |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 110 | buf[0] = GSM48_IE_MOBILE_ID; |
Harald Welte | 1a41218 | 2008-12-27 22:13:43 +0000 | [diff] [blame] | 111 | buf[1] = TMSI_LEN; |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 112 | buf[2] = 0xf0 | GSM_MI_TYPE_TMSI; |
Harald Welte | 255539c | 2008-12-28 02:26:27 +0000 | [diff] [blame] | 113 | *tptr = htonl(tmsi); |
| 114 | |
| 115 | return 7; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 116 | } |
| 117 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 118 | static struct msgb *gsm48_msgb_alloc(void) |
| 119 | { |
| 120 | return msgb_alloc_headroom(GSM48_ALLOC_SIZE, GSM48_ALLOC_HEADROOM); |
| 121 | } |
| 122 | |
Harald Welte | 65e74cc | 2008-12-29 01:55:35 +0000 | [diff] [blame] | 123 | static int gsm48_sendmsg(struct msgb *msg) |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 124 | { |
Harald Welte | 65e74cc | 2008-12-29 01:55:35 +0000 | [diff] [blame] | 125 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msg->data; |
| 126 | |
| 127 | if (msg->lchan) { |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 128 | msg->trx = msg->lchan->ts->trx; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 129 | |
Harald Welte | 65e74cc | 2008-12-29 01:55:35 +0000 | [diff] [blame] | 130 | if ((gh->proto_discr & GSM48_PDISC_MASK) == GSM48_PDISC_CC) { |
| 131 | /* Send a 04.08 call control message, add transaction |
| 132 | * ID and TI flag */ |
| 133 | gh->proto_discr |= msg->lchan->call.transaction_id; |
| 134 | |
| 135 | /* GSM 04.07 Section 11.2.3.1.3 */ |
| 136 | switch (msg->lchan->call.type) { |
| 137 | case GSM_CT_MO: |
| 138 | gh->proto_discr |= 0x80; |
| 139 | break; |
| 140 | case GSM_CT_MT: |
| 141 | break; |
| 142 | } |
| 143 | } |
| 144 | } |
| 145 | |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 146 | msg->l3h = msg->data; |
| 147 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 148 | return rsl_data_request(msg, 0); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 149 | } |
| 150 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 151 | |
| 152 | /* Chapter 9.2.14 : Send LOCATION UPDATE REJECT */ |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 153 | int gsm0408_loc_upd_rej(struct gsm_lchan *lchan, u_int8_t cause) |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 154 | { |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 155 | struct msgb *msg = gsm48_msgb_alloc(); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 156 | struct gsm48_hdr *gh; |
| 157 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 158 | msg->lchan = lchan; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 159 | |
| 160 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 1); |
| 161 | gh->proto_discr = GSM48_PDISC_MM; |
Harald Welte | 10b487b | 2008-12-27 19:53:37 +0000 | [diff] [blame] | 162 | gh->msg_type = GSM48_MT_MM_LOC_UPD_REJECT; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 163 | gh->data[0] = cause; |
| 164 | |
| 165 | DEBUGP(DMM, "-> LOCATION UPDATE REJECT\n"); |
| 166 | |
Harald Welte | 65e74cc | 2008-12-29 01:55:35 +0000 | [diff] [blame] | 167 | return gsm48_sendmsg(msg); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | /* Chapter 9.2.13 : Send LOCATION UPDATE ACCEPT */ |
Harald Welte | 75a983f | 2008-12-27 21:34:06 +0000 | [diff] [blame] | 171 | int gsm0408_loc_upd_acc(struct gsm_lchan *lchan, u_int32_t tmsi) |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 172 | { |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 173 | struct gsm_bts *bts = lchan->ts->trx->bts; |
| 174 | struct msgb *msg = gsm48_msgb_alloc(); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 175 | struct gsm48_hdr *gh; |
| 176 | struct gsm48_loc_area_id *lai; |
| 177 | u_int8_t *mid; |
| 178 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 179 | msg->lchan = lchan; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 180 | |
| 181 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 182 | gh->proto_discr = GSM48_PDISC_MM; |
| 183 | gh->msg_type = GSM48_MT_MM_LOC_UPD_ACCEPT; |
| 184 | |
| 185 | lai = (struct gsm48_loc_area_id *) msgb_put(msg, sizeof(*lai)); |
Holger Freyther | 1774661 | 2008-12-28 16:32:44 +0000 | [diff] [blame] | 186 | gsm0408_generate_lai(lai, bts->network->country_code, |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 187 | bts->network->network_code, bts->location_area_code); |
| 188 | |
| 189 | mid = msgb_put(msg, MID_TMSI_LEN); |
| 190 | generate_mid_from_tmsi(mid, tmsi); |
| 191 | |
| 192 | DEBUGP(DMM, "-> LOCATION UPDATE ACCEPT\n"); |
| 193 | |
Harald Welte | 65e74cc | 2008-12-29 01:55:35 +0000 | [diff] [blame] | 194 | gsm48_sendmsg(msg); |
| 195 | |
| 196 | return gsm48_cc_tx_setup(lchan); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 197 | } |
| 198 | |
Harald Welte | fc977a8 | 2008-12-27 10:19:37 +0000 | [diff] [blame] | 199 | static char bcd2char(u_int8_t bcd) |
| 200 | { |
| 201 | if (bcd < 0xa) |
| 202 | return '0' + bcd; |
| 203 | else |
| 204 | return 'A' + (bcd - 0xa); |
| 205 | } |
| 206 | |
| 207 | /* 10.5.1.4 */ |
| 208 | static int mi_to_string(char *string, int str_len, u_int8_t *mi, int mi_len) |
| 209 | { |
| 210 | int i; |
| 211 | u_int8_t mi_type; |
| 212 | char *str_cur = string; |
| 213 | |
| 214 | mi_type = mi[0] & GSM_MI_TYPE_MASK; |
| 215 | |
| 216 | switch (mi_type) { |
| 217 | case GSM_MI_TYPE_NONE: |
| 218 | break; |
| 219 | case GSM_MI_TYPE_TMSI: |
| 220 | for (i = 1; i < mi_len - 1; i++) { |
| 221 | if (str_cur + 2 >= string + str_len) |
| 222 | return str_cur - string; |
| 223 | *str_cur++ = bcd2char(mi[i] >> 4); |
| 224 | *str_cur++ = bcd2char(mi[i] & 0xf); |
| 225 | } |
| 226 | break; |
| 227 | case GSM_MI_TYPE_IMSI: |
| 228 | case GSM_MI_TYPE_IMEI: |
| 229 | case GSM_MI_TYPE_IMEISV: |
| 230 | if (mi[0] & GSM_MI_ODD) |
| 231 | *str_cur++ = bcd2char(mi[0] >> 4); |
| 232 | |
| 233 | for (i = 1; i < mi_len - 1; i++) { |
| 234 | if (str_cur + 2 >= string + str_len) |
| 235 | return str_cur - string; |
| 236 | *str_cur++ = bcd2char(mi[i] & 0xf); |
| 237 | *str_cur++ = bcd2char(mi[i] >> 4); |
| 238 | } |
| 239 | break; |
| 240 | default: |
| 241 | break; |
| 242 | } |
| 243 | |
| 244 | *str_cur++ = '\0'; |
| 245 | return str_cur - string; |
| 246 | } |
| 247 | |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 248 | /* Chapter 9.2.10 */ |
| 249 | static int mm_tx_identity_req(struct gsm_lchan *lchan, u_int8_t id_type) |
| 250 | { |
| 251 | struct msgb *msg = gsm48_msgb_alloc(); |
| 252 | struct gsm48_hdr *gh; |
Harald Welte | fc977a8 | 2008-12-27 10:19:37 +0000 | [diff] [blame] | 253 | |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 254 | msg->lchan = lchan; |
| 255 | |
| 256 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 1); |
| 257 | gh->proto_discr = GSM48_PDISC_MM; |
| 258 | gh->msg_type = GSM48_MT_MM_ID_REQ; |
| 259 | gh->data[0] = id_type; |
| 260 | |
Harald Welte | 65e74cc | 2008-12-29 01:55:35 +0000 | [diff] [blame] | 261 | return gsm48_sendmsg(msg); |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | #define MI_SIZE 32 |
| 265 | |
| 266 | /* Chapter 9.2.11 */ |
| 267 | static int mm_rx_id_resp(struct msgb *msg) |
| 268 | { |
| 269 | struct gsm48_hdr *gh = msgb_l3(msg); |
Harald Welte | 75a983f | 2008-12-27 21:34:06 +0000 | [diff] [blame] | 270 | struct gsm_lchan *lchan = msg->lchan; |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 271 | u_int8_t mi_type = gh->data[1] & GSM_MI_TYPE_MASK; |
| 272 | char mi_string[MI_SIZE]; |
Harald Welte | 75a983f | 2008-12-27 21:34:06 +0000 | [diff] [blame] | 273 | u_int32_t tmsi; |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 274 | |
| 275 | mi_to_string(mi_string, sizeof(mi_string), &gh->data[1], gh->data[0]); |
Harald Welte | 6125306 | 2008-12-27 11:25:50 +0000 | [diff] [blame] | 276 | DEBUGP(DMM, "IDENTITY RESPONSE: mi_type=0x%02x MI(%s)\n", |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 277 | mi_type, mi_string); |
| 278 | |
Harald Welte | 75a983f | 2008-12-27 21:34:06 +0000 | [diff] [blame] | 279 | switch (mi_type) { |
| 280 | case GSM_MI_TYPE_IMSI: |
| 281 | if (!lchan->subscr) |
| 282 | lchan->subscr = db_create_subscriber(mi_string); |
| 283 | if (lchan->subscr && lchan->subscr->authorized) { |
| 284 | /* FIXME: check if we've recently received UPDATE REQUEST */ |
| 285 | db_subscriber_alloc_tmsi(lchan->subscr); |
Harald Welte | 255539c | 2008-12-28 02:26:27 +0000 | [diff] [blame] | 286 | tmsi = strtoul(lchan->subscr->tmsi, NULL, 10); |
Harald Welte | 75a983f | 2008-12-27 21:34:06 +0000 | [diff] [blame] | 287 | return gsm0408_loc_upd_acc(msg->lchan, tmsi); |
| 288 | } |
| 289 | break; |
| 290 | case GSM_MI_TYPE_IMEI: |
Harald Welte | 255539c | 2008-12-28 02:26:27 +0000 | [diff] [blame] | 291 | case GSM_MI_TYPE_IMEISV: |
Harald Welte | 75a983f | 2008-12-27 21:34:06 +0000 | [diff] [blame] | 292 | /* update subscribe <-> IMEI mapping */ |
| 293 | if (lchan->subscr) |
| 294 | db_subscriber_assoc_imei(lchan->subscr, mi_string); |
| 295 | break; |
| 296 | } |
| 297 | return 0; |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 298 | } |
| 299 | |
Harald Welte | 255539c | 2008-12-28 02:26:27 +0000 | [diff] [blame] | 300 | |
| 301 | static void loc_upd_rej_cb(void *data) |
| 302 | { |
| 303 | struct gsm_lchan *lchan = data; |
| 304 | |
| 305 | gsm0408_loc_upd_rej(lchan, 0x16); |
| 306 | rsl_chan_release(lchan); |
| 307 | } |
| 308 | |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 309 | #define MI_SIZE 32 |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 310 | /* Chapter 9.2.15 */ |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 311 | static int mm_rx_loc_upd_req(struct msgb *msg) |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 312 | { |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 313 | struct gsm48_hdr *gh = msgb_l3(msg); |
Harald Welte | 702d870 | 2008-12-26 20:25:35 +0000 | [diff] [blame] | 314 | struct gsm_bts *bts = msg->trx->bts; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 315 | struct gsm48_loc_upd_req *lu; |
| 316 | struct gsm_subscriber *subscr; |
Harald Welte | 255539c | 2008-12-28 02:26:27 +0000 | [diff] [blame] | 317 | struct gsm_lchan *lchan = msg->lchan; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 318 | u_int8_t mi_type; |
Harald Welte | 75a983f | 2008-12-27 21:34:06 +0000 | [diff] [blame] | 319 | u_int32_t tmsi; |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 320 | char mi_string[MI_SIZE]; |
| 321 | int rc; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 322 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 323 | lu = (struct gsm48_loc_upd_req *) gh->data; |
| 324 | |
| 325 | mi_type = lu->mi[0] & GSM_MI_TYPE_MASK; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 326 | |
Harald Welte | fc977a8 | 2008-12-27 10:19:37 +0000 | [diff] [blame] | 327 | mi_to_string(mi_string, sizeof(mi_string), lu->mi, lu->mi_len); |
| 328 | |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 329 | DEBUGP(DMM, "LUPDREQ: mi_type=0x%02x MI(%s)\n", mi_type, mi_string); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 330 | switch (mi_type) { |
| 331 | case GSM_MI_TYPE_IMSI: |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 332 | /* we always want the IMEI, too */ |
Harald Welte | 255539c | 2008-12-28 02:26:27 +0000 | [diff] [blame] | 333 | rc = mm_tx_identity_req(lchan, GSM_MI_TYPE_IMEISV); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 334 | /* look up subscriber based on IMSI */ |
Harald Welte | 75a983f | 2008-12-27 21:34:06 +0000 | [diff] [blame] | 335 | subscr = db_create_subscriber(mi_string); |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 336 | break; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 337 | case GSM_MI_TYPE_TMSI: |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 338 | /* we always want the IMEI, too */ |
Harald Welte | 255539c | 2008-12-28 02:26:27 +0000 | [diff] [blame] | 339 | rc = mm_tx_identity_req(lchan, GSM_MI_TYPE_IMEISV); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 340 | /* look up the subscriber based on TMSI, request IMSI if it fails */ |
Harald Welte | fc977a8 | 2008-12-27 10:19:37 +0000 | [diff] [blame] | 341 | subscr = subscr_get_by_tmsi(lu->mi); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 342 | if (!subscr) { |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 343 | /* send IDENTITY REQUEST message to get IMSI */ |
Harald Welte | 255539c | 2008-12-28 02:26:27 +0000 | [diff] [blame] | 344 | rc = mm_tx_identity_req(lchan, GSM_MI_TYPE_IMSI); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 345 | } |
| 346 | break; |
| 347 | case GSM_MI_TYPE_IMEI: |
| 348 | case GSM_MI_TYPE_IMEISV: |
| 349 | /* no sim card... FIXME: what to do ? */ |
| 350 | fprintf(stderr, "Unimplemented mobile identity type\n"); |
| 351 | break; |
| 352 | default: |
| 353 | fprintf(stderr, "Unknown mobile identity type\n"); |
| 354 | break; |
| 355 | } |
| 356 | |
Harald Welte | 255539c | 2008-12-28 02:26:27 +0000 | [diff] [blame] | 357 | lchan->subscr = subscr; |
| 358 | |
Harald Welte | 75a983f | 2008-12-27 21:34:06 +0000 | [diff] [blame] | 359 | if (!subscr || !subscr->authorized) { |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 360 | /* 0x16 is congestion */ |
Harald Welte | 255539c | 2008-12-28 02:26:27 +0000 | [diff] [blame] | 361 | lchan->timer.cb = loc_upd_rej_cb; |
| 362 | lchan->timer.data = lchan; |
| 363 | schedule_timer(&lchan->timer, 1, 0); |
| 364 | return 0; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 365 | } |
| 366 | |
Harald Welte | 75a983f | 2008-12-27 21:34:06 +0000 | [diff] [blame] | 367 | db_subscriber_alloc_tmsi(subscr); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 368 | subscr_update(subscr, bts); |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 369 | |
Harald Welte | 255539c | 2008-12-28 02:26:27 +0000 | [diff] [blame] | 370 | tmsi = strtoul(subscr->tmsi, NULL, 10); |
| 371 | |
| 372 | return gsm0408_loc_upd_acc(lchan, tmsi); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 373 | } |
| 374 | |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 375 | static int gsm48_tx_mm_serv_ack(struct gsm_lchan *lchan) |
| 376 | { |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 377 | DEBUGP(DMM, "-> CM SERVICE ACK\n"); |
Harald Welte | 65e74cc | 2008-12-29 01:55:35 +0000 | [diff] [blame] | 378 | return gsm48_tx_simple(lchan, GSM48_PDISC_MM, GSM48_MT_MM_CM_SERV_ACC); |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 379 | } |
| 380 | |
| 381 | static int gsm48_rx_mm_serv_req(struct msgb *msg) |
| 382 | { |
| 383 | struct gsm48_hdr *gh = msgb_l3(msg); |
Harald Welte | bcae43f | 2008-12-27 21:45:37 +0000 | [diff] [blame] | 384 | u_int8_t serv_type = gh->data[0] & 0x0f; |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 385 | |
Harald Welte | 65e74cc | 2008-12-29 01:55:35 +0000 | [diff] [blame] | 386 | DEBUGP(DMM, "<- CM SERVICE REQUEST serv_type=0x%02x\n", serv_type); |
Harald Welte | bcae43f | 2008-12-27 21:45:37 +0000 | [diff] [blame] | 387 | |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 388 | return gsm48_tx_mm_serv_ack(msg->lchan); |
| 389 | } |
| 390 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 391 | static int gsm0408_rcv_mm(struct msgb *msg) |
| 392 | { |
| 393 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 394 | int rc; |
| 395 | |
| 396 | switch (gh->msg_type & 0xbf) { |
| 397 | case GSM48_MT_MM_LOC_UPD_REQUEST: |
| 398 | DEBUGP(DMM, "LOCATION UPDATE REQUEST\n"); |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 399 | rc = mm_rx_loc_upd_req(msg); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 400 | break; |
| 401 | case GSM48_MT_MM_ID_RESP: |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 402 | rc = mm_rx_id_resp(msg); |
| 403 | break; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 404 | case GSM48_MT_MM_CM_SERV_REQ: |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 405 | rc = gsm48_rx_mm_serv_req(msg); |
| 406 | break; |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 407 | case GSM48_MT_MM_STATUS: |
| 408 | DEBUGP(DMM, "MM STATUS: FIXME parse error cond.\n"); |
| 409 | break; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 410 | case GSM48_MT_MM_CM_REEST_REQ: |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 411 | case GSM48_MT_MM_TMSI_REALL_COMPL: |
| 412 | case GSM48_MT_MM_AUTH_RESP: |
| 413 | case GSM48_MT_MM_IMSI_DETACH_IND: |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 414 | fprintf(stderr, "Unimplemented GSM 04.08 MM msg type 0x%02x\n", |
| 415 | gh->msg_type); |
| 416 | break; |
| 417 | default: |
| 418 | fprintf(stderr, "Unknown GSM 04.08 MM msg type 0x%02x\n", |
| 419 | gh->msg_type); |
| 420 | break; |
| 421 | } |
| 422 | |
| 423 | return rc; |
| 424 | } |
| 425 | static int gsm0408_rcv_rr(struct msgb *msg) |
| 426 | { |
| 427 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 428 | |
| 429 | switch (gh->msg_type) { |
| 430 | case GSM48_MT_RR_CLSM_CHG: |
| 431 | DEBUGP(DRR, "CLASSMARK CHANGE\n"); |
| 432 | /* FIXME: what to do ?!? */ |
| 433 | break; |
Harald Welte | fc977a8 | 2008-12-27 10:19:37 +0000 | [diff] [blame] | 434 | case GSM48_MT_RR_GPRS_SUSP_REQ: |
| 435 | DEBUGP(DRR, "GRPS SUSPEND REQUEST\n"); |
| 436 | break; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 437 | case GSM48_MT_RR_PAG_RESP: |
| 438 | default: |
| 439 | fprintf(stderr, "Unimplemented GSM 04.08 msg type 0x%02x\n", |
| 440 | gh->msg_type); |
| 441 | break; |
| 442 | } |
| 443 | |
| 444 | return 0; |
| 445 | } |
| 446 | |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 447 | /* Call Control */ |
| 448 | |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 449 | static int gsm48_cc_tx_status(struct gsm_lchan *lchan) |
| 450 | { |
| 451 | struct msgb *msg = gsm48_msgb_alloc(); |
| 452 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 453 | u_int8_t *cause, *call_state; |
| 454 | |
Harald Welte | 65e74cc | 2008-12-29 01:55:35 +0000 | [diff] [blame] | 455 | gh->proto_discr = GSM48_PDISC_CC; |
| 456 | |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 457 | msg->lchan = lchan; |
| 458 | |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 459 | gh->msg_type = GSM48_MT_CC_STATUS; |
| 460 | |
| 461 | cause = msgb_put(msg, 3); |
| 462 | cause[0] = 2; |
| 463 | cause[1] = GSM48_CAUSE_CS_GSM | GSM48_CAUSE_LOC_USER; |
| 464 | cause[2] = 0x80 | 30; /* response to status inquiry */ |
| 465 | |
| 466 | call_state = msgb_put(msg, 1); |
| 467 | call_state[0] = 0xc0 | 0x00; |
| 468 | |
Harald Welte | 65e74cc | 2008-12-29 01:55:35 +0000 | [diff] [blame] | 469 | return gsm48_sendmsg(msg); |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 470 | } |
| 471 | |
Harald Welte | 6f4b753 | 2008-12-29 00:39:37 +0000 | [diff] [blame] | 472 | static int gsm48_tx_simple(struct gsm_lchan *lchan, |
| 473 | u_int8_t pdisc, u_int8_t msg_type) |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 474 | { |
| 475 | struct msgb *msg = gsm48_msgb_alloc(); |
| 476 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 477 | |
| 478 | msg->lchan = lchan; |
| 479 | |
Harald Welte | 6f4b753 | 2008-12-29 00:39:37 +0000 | [diff] [blame] | 480 | gh->proto_discr = pdisc; |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 481 | gh->msg_type = msg_type; |
| 482 | |
Harald Welte | 65e74cc | 2008-12-29 01:55:35 +0000 | [diff] [blame] | 483 | return gsm48_sendmsg(msg); |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 484 | } |
| 485 | |
| 486 | static int gsm48_cc_rx_status_enq(struct msgb *msg) |
| 487 | { |
| 488 | return gsm48_cc_tx_status(msg->lchan); |
| 489 | } |
| 490 | |
| 491 | static int gsm48_cc_rx_setup(struct msgb *msg) |
| 492 | { |
Harald Welte | 6f4b753 | 2008-12-29 00:39:37 +0000 | [diff] [blame] | 493 | return gsm48_tx_simple(msg->lchan, GSM48_PDISC_CC, |
| 494 | GSM48_MT_CC_CALL_CONF); |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 495 | } |
| 496 | |
Harald Welte | 65e74cc | 2008-12-29 01:55:35 +0000 | [diff] [blame] | 497 | int gsm48_cc_tx_setup(struct gsm_lchan *lchan) |
| 498 | { |
| 499 | struct msgb *msg = gsm48_msgb_alloc(); |
| 500 | struct gsm48_hdr *gh; |
| 501 | struct gsm_call *call = &lchan->call; |
| 502 | |
| 503 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 8); |
| 504 | |
| 505 | call->type = GSM_CT_MT; |
| 506 | msg->lchan = lchan; |
| 507 | |
| 508 | gh->proto_discr = GSM48_PDISC_CC; |
| 509 | gh->msg_type = GSM48_MT_CC_SETUP; |
| 510 | gh->data[0] = 0x34; |
| 511 | gh->data[1] = 0x00; |
| 512 | gh->data[2] = 0x5c; |
| 513 | gh->data[3] = 0x04; |
| 514 | gh->data[4] = 0xb9; |
| 515 | gh->data[5] = 0x83; |
| 516 | gh->data[6] = 0x32; |
| 517 | gh->data[7] = 0x24; |
| 518 | |
| 519 | DEBUGP(DCC, "Sending SETUP\n"); |
| 520 | |
| 521 | return gsm48_sendmsg(msg); |
| 522 | } |
| 523 | |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 524 | static int gsm0408_rcv_cc(struct msgb *msg) |
| 525 | { |
| 526 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 527 | u_int8_t msg_type = gh->msg_type & 0xbf; |
| 528 | struct gsm_call *call = &msg->lchan->call; |
| 529 | int rc = 0; |
| 530 | |
| 531 | switch (msg_type) { |
| 532 | case GSM48_MT_CC_CALL_CONF: |
| 533 | /* Response to SETUP */ |
| 534 | DEBUGP(DCC, "CALL CONFIRM\n"); |
| 535 | break; |
| 536 | case GSM48_MT_CC_RELEASE_COMPL: |
| 537 | /* Answer from MS to RELEASE */ |
| 538 | DEBUGP(DCC, "RELEASE COMPLETE (state->NULL)\n"); |
| 539 | call->state = GSM_CSTATE_NULL; |
| 540 | break; |
| 541 | case GSM48_MT_CC_ALERTING: |
| 542 | DEBUGP(DCC, "ALERTING\n"); |
| 543 | break; |
| 544 | case GSM48_MT_CC_CONNECT: |
| 545 | DEBUGP(DCC, "CONNECT\n"); |
| 546 | /* MT: need to respond with CONNECT_ACK */ |
Harald Welte | 6f4b753 | 2008-12-29 00:39:37 +0000 | [diff] [blame] | 547 | rc = gsm48_tx_simple(msg->lchan, GSM48_PDISC_CC, |
| 548 | GSM48_MT_CC_CONNECT_ACK); |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 549 | break; |
| 550 | case GSM48_MT_CC_CONNECT_ACK: |
| 551 | /* MO: Answer to CONNECT */ |
| 552 | call->state = GSM_CSTATE_ACTIVE; |
| 553 | DEBUGP(DCC, "CONNECT_ACK (state->ACTIVE)\n"); |
| 554 | break; |
| 555 | case GSM48_MT_CC_RELEASE: |
| 556 | DEBUGP(DCC, "RELEASE\n"); |
| 557 | /* need to respond with RELEASE_COMPLETE */ |
| 558 | break; |
| 559 | case GSM48_MT_CC_STATUS_ENQ: |
| 560 | rc = gsm48_cc_rx_status_enq(msg); |
| 561 | break; |
| 562 | case GSM48_MT_CC_DISCONNECT: |
| 563 | /* Section 5.4.3.2 */ |
| 564 | DEBUGP(DCC, "DISCONNECT (state->RELEASE_REQ)\n"); |
| 565 | call->state = GSM_CSTATE_RELEASE_REQ; |
| 566 | /* FIXME: clear the network connection */ |
Harald Welte | 6f4b753 | 2008-12-29 00:39:37 +0000 | [diff] [blame] | 567 | rc = gsm48_tx_simple(msg->lchan, GSM48_PDISC_CC, |
| 568 | GSM48_MT_CC_RELEASE); |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 569 | break; |
| 570 | case GSM48_MT_CC_SETUP: |
| 571 | call->type = GSM_CT_MO; |
| 572 | call->state = GSM_CSTATE_INITIATED; |
| 573 | call->transaction_id = gh->proto_discr & 0xf0; |
| 574 | DEBUGP(DCC, "SETUP(tid=0x%02x)\n", call->transaction_id); |
Harald Welte | 6f4b753 | 2008-12-29 00:39:37 +0000 | [diff] [blame] | 575 | rc = gsm48_tx_simple(msg->lchan, GSM48_PDISC_CC, |
| 576 | GSM48_MT_CC_CONNECT); |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 577 | /* FIXME: continue with CALL_PROCEEDING, ALERTING, CONNECT, RELEASE_COMPLETE */ |
| 578 | break; |
| 579 | case GSM48_MT_CC_EMERG_SETUP: |
| 580 | DEBUGP(DCC, "EMERGENCY SETUP\n"); |
| 581 | /* FIXME: continue with CALL_PROCEEDING, ALERTING, CONNECT, RELEASE_COMPLETE */ |
| 582 | break; |
| 583 | default: |
| 584 | fprintf(stderr, "Unimplemented GSM 04.08 msg type 0x%02x\n", |
| 585 | msg_type); |
| 586 | break; |
| 587 | } |
| 588 | |
| 589 | return rc; |
| 590 | } |
| 591 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 592 | /* here we pass in a msgb from the RSL->RLL. We expect the l3 pointer to be set */ |
| 593 | int gsm0408_rcvmsg(struct msgb *msg) |
| 594 | { |
| 595 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 596 | u_int8_t pdisc = gh->proto_discr & 0x0f; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 597 | int rc = 0; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 598 | |
| 599 | switch (pdisc) { |
| 600 | case GSM48_PDISC_CC: |
| 601 | rc = gsm0408_rcv_cc(msg); |
| 602 | break; |
| 603 | case GSM48_PDISC_MM: |
| 604 | rc = gsm0408_rcv_mm(msg); |
| 605 | break; |
| 606 | case GSM48_PDISC_RR: |
| 607 | rc = gsm0408_rcv_rr(msg); |
| 608 | break; |
Harald Welte | bcae43f | 2008-12-27 21:45:37 +0000 | [diff] [blame] | 609 | case GSM48_PDISC_SMS: |
Daniel Willmann | 8b3390e | 2008-12-28 00:31:09 +0000 | [diff] [blame] | 610 | rc = gsm0411_rcv_sms(msg); |
Harald Welte | bcae43f | 2008-12-27 21:45:37 +0000 | [diff] [blame] | 611 | break; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 612 | case GSM48_PDISC_MM_GPRS: |
Harald Welte | bcae43f | 2008-12-27 21:45:37 +0000 | [diff] [blame] | 613 | case GSM48_PDISC_SM_GPRS: |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 614 | fprintf(stderr, "Unimplemented GSM 04.08 discriminator 0x%02d\n", |
| 615 | pdisc); |
| 616 | break; |
| 617 | default: |
| 618 | fprintf(stderr, "Unknown GSM 04.08 discriminator 0x%02d\n", |
| 619 | pdisc); |
| 620 | break; |
| 621 | } |
| 622 | |
| 623 | return rc; |
| 624 | } |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 625 | |
| 626 | enum chreq_type { |
| 627 | CHREQ_T_EMERG_CALL, |
| 628 | CHREQ_T_CALL_REEST_TCH_F, |
| 629 | CHREQ_T_CALL_REEST_TCH_H, |
| 630 | CHREQ_T_CALL_REEST_TCH_H_DBL, |
| 631 | CHREQ_T_SDCCH, |
| 632 | CHREQ_T_TCH_F, |
| 633 | CHREQ_T_VOICE_CALL_TCH_H, |
| 634 | CHREQ_T_DATA_CALL_TCH_H, |
| 635 | CHREQ_T_LOCATION_UPD, |
| 636 | CHREQ_T_PAG_R_ANY, |
| 637 | CHREQ_T_PAG_R_TCH_F, |
| 638 | CHREQ_T_PAG_R_TCH_FH, |
| 639 | }; |
| 640 | |
| 641 | /* Section 9.1.8 / Table 9.9 */ |
| 642 | struct chreq { |
| 643 | u_int8_t val; |
| 644 | u_int8_t mask; |
| 645 | enum chreq_type type; |
| 646 | }; |
| 647 | |
| 648 | /* If SYSTEM INFORMATION TYPE 4 NECI bit == 1 */ |
| 649 | static const struct chreq chreq_type_neci1[] = { |
| 650 | { 0xa0, 0xe0, CHREQ_T_EMERG_CALL }, |
| 651 | { 0xc0, 0xe0, CHREQ_T_CALL_REEST_TCH_F }, |
| 652 | { 0x68, 0xfc, CHREQ_T_CALL_REEST_TCH_H }, |
| 653 | { 0x6c, 0xfc, CHREQ_T_CALL_REEST_TCH_H_DBL }, |
| 654 | { 0xe0, 0xe0, CHREQ_T_SDCCH }, |
| 655 | { 0x40, 0xf0, CHREQ_T_VOICE_CALL_TCH_H }, |
| 656 | { 0x50, 0xf0, CHREQ_T_DATA_CALL_TCH_H }, |
| 657 | { 0x00, 0xf0, CHREQ_T_LOCATION_UPD }, |
| 658 | { 0x10, 0xf0, CHREQ_T_SDCCH }, |
| 659 | { 0x80, 0xe0, CHREQ_T_PAG_R_ANY }, |
| 660 | { 0x20, 0xf0, CHREQ_T_PAG_R_TCH_F }, |
| 661 | { 0x30, 0xf0, CHREQ_T_PAG_R_TCH_FH }, |
| 662 | }; |
| 663 | |
| 664 | /* If SYSTEM INFORMATION TYPE 4 NECI bit == 0 */ |
| 665 | static const struct chreq chreq_type_neci0[] = { |
| 666 | { 0xa0, 0xe0, CHREQ_T_EMERG_CALL }, |
| 667 | { 0xc0, 0xe0, CHREQ_T_CALL_REEST_TCH_H }, |
| 668 | { 0xe0, 0xe0, CHREQ_T_TCH_F }, |
| 669 | { 0x50, 0xf0, CHREQ_T_DATA_CALL_TCH_H }, |
| 670 | { 0x00, 0xe0, CHREQ_T_LOCATION_UPD }, |
| 671 | { 0x80, 0xe0, CHREQ_T_PAG_R_ANY }, |
| 672 | { 0x20, 0xf0, CHREQ_T_PAG_R_TCH_F }, |
| 673 | { 0x30, 0xf0, CHREQ_T_PAG_R_TCH_FH }, |
| 674 | }; |
| 675 | |
| 676 | static const enum gsm_chan_t ctype_by_chreq[] = { |
| 677 | [CHREQ_T_EMERG_CALL] = GSM_LCHAN_TCH_F, |
| 678 | [CHREQ_T_CALL_REEST_TCH_F] = GSM_LCHAN_TCH_F, |
| 679 | [CHREQ_T_CALL_REEST_TCH_H] = GSM_LCHAN_TCH_H, |
| 680 | [CHREQ_T_CALL_REEST_TCH_H_DBL] = GSM_LCHAN_TCH_H, |
| 681 | [CHREQ_T_SDCCH] = GSM_LCHAN_SDCCH, |
| 682 | [CHREQ_T_TCH_F] = GSM_LCHAN_TCH_F, |
| 683 | [CHREQ_T_VOICE_CALL_TCH_H] = GSM_LCHAN_TCH_H, |
| 684 | [CHREQ_T_DATA_CALL_TCH_H] = GSM_LCHAN_TCH_H, |
| 685 | [CHREQ_T_LOCATION_UPD] = GSM_LCHAN_SDCCH, |
| 686 | [CHREQ_T_PAG_R_ANY] = GSM_LCHAN_SDCCH, |
| 687 | [CHREQ_T_PAG_R_TCH_F] = GSM_LCHAN_TCH_F, |
| 688 | [CHREQ_T_PAG_R_TCH_FH] = GSM_LCHAN_TCH_F, |
| 689 | }; |
| 690 | |
Harald Welte | e14a57c | 2008-12-29 04:08:28 +0000 | [diff] [blame] | 691 | static const enum gsm_chreq_reason_t reason_by_chreq[] = { |
| 692 | [CHREQ_T_EMERG_CALL] = GSM_CHREQ_REASON_EMERG, |
| 693 | [CHREQ_T_CALL_REEST_TCH_F] = GSM_CHREQ_REASON_CALL, |
| 694 | [CHREQ_T_CALL_REEST_TCH_H] = GSM_CHREQ_REASON_CALL, |
| 695 | [CHREQ_T_CALL_REEST_TCH_H_DBL] = GSM_CHREQ_REASON_CALL, |
| 696 | [CHREQ_T_SDCCH] = GSM_CHREQ_REASON_OTHER, |
| 697 | [CHREQ_T_TCH_F] = GSM_CHREQ_REASON_OTHER, |
| 698 | [CHREQ_T_VOICE_CALL_TCH_H] = GSM_CHREQ_REASON_OTHER, |
| 699 | [CHREQ_T_DATA_CALL_TCH_H] = GSM_CHREQ_REASON_OTHER, |
| 700 | [CHREQ_T_LOCATION_UPD] = GSM_CHREQ_REASON_LOCATION_UPD, |
| 701 | [CHREQ_T_PAG_R_ANY] = GSM_CHREQ_REASON_PAG, |
| 702 | [CHREQ_T_PAG_R_TCH_F] = GSM_CHREQ_REASON_PAG, |
| 703 | [CHREQ_T_PAG_R_TCH_FH] = GSM_CHREQ_REASON_PAG, |
| 704 | }; |
| 705 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 706 | enum gsm_chan_t get_ctype_by_chreq(struct gsm_bts *bts, u_int8_t ra) |
| 707 | { |
| 708 | int i; |
| 709 | /* FIXME: determine if we set NECI = 0 in the BTS SI4 */ |
| 710 | |
| 711 | for (i = 0; i < ARRAY_SIZE(chreq_type_neci0); i++) { |
| 712 | const struct chreq *chr = &chreq_type_neci0[i]; |
| 713 | if ((ra & chr->mask) == chr->val) |
| 714 | return ctype_by_chreq[chr->type]; |
| 715 | } |
| 716 | fprintf(stderr, "Unknown CHANNEL REQUEST RQD 0x%02x\n", ra); |
| 717 | return GSM_LCHAN_SDCCH; |
| 718 | } |
Harald Welte | e14a57c | 2008-12-29 04:08:28 +0000 | [diff] [blame] | 719 | |
| 720 | enum gsm_chreq_reason_t get_reason_by_chreq(struct gsm_bts *bts, u_int8_t ra) |
| 721 | { |
| 722 | int i; |
| 723 | /* FIXME: determine if we set NECI = 0 in the BTS SI4 */ |
| 724 | |
| 725 | for (i = 0; i < ARRAY_SIZE(chreq_type_neci0); i++) { |
| 726 | const struct chreq *chr = &chreq_type_neci0[i]; |
| 727 | if ((ra & chr->mask) == chr->val) |
| 728 | return reason_by_chreq[chr->type]; |
| 729 | } |
| 730 | fprintf(stderr, "Unknown CHANNEL REQUEST REASON 0x%02x\n", ra); |
| 731 | return GSM_CHREQ_REASON_OTHER; |
| 732 | } |