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 | |
Daniel Willmann | 6fe997e | 2008-12-29 04:20:41 +0000 | [diff] [blame] | 196 | gsm0411_send_sms(lchan, 0); |
| 197 | |
Harald Welte | 65e74cc | 2008-12-29 01:55:35 +0000 | [diff] [blame] | 198 | return gsm48_cc_tx_setup(lchan); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 199 | } |
| 200 | |
Harald Welte | fc977a8 | 2008-12-27 10:19:37 +0000 | [diff] [blame] | 201 | static char bcd2char(u_int8_t bcd) |
| 202 | { |
| 203 | if (bcd < 0xa) |
| 204 | return '0' + bcd; |
| 205 | else |
| 206 | return 'A' + (bcd - 0xa); |
| 207 | } |
| 208 | |
| 209 | /* 10.5.1.4 */ |
| 210 | static int mi_to_string(char *string, int str_len, u_int8_t *mi, int mi_len) |
| 211 | { |
| 212 | int i; |
| 213 | u_int8_t mi_type; |
| 214 | char *str_cur = string; |
| 215 | |
| 216 | mi_type = mi[0] & GSM_MI_TYPE_MASK; |
| 217 | |
| 218 | switch (mi_type) { |
| 219 | case GSM_MI_TYPE_NONE: |
| 220 | break; |
| 221 | case GSM_MI_TYPE_TMSI: |
| 222 | for (i = 1; i < mi_len - 1; i++) { |
| 223 | if (str_cur + 2 >= string + str_len) |
| 224 | return str_cur - string; |
| 225 | *str_cur++ = bcd2char(mi[i] >> 4); |
| 226 | *str_cur++ = bcd2char(mi[i] & 0xf); |
| 227 | } |
| 228 | break; |
| 229 | case GSM_MI_TYPE_IMSI: |
| 230 | case GSM_MI_TYPE_IMEI: |
| 231 | case GSM_MI_TYPE_IMEISV: |
| 232 | if (mi[0] & GSM_MI_ODD) |
| 233 | *str_cur++ = bcd2char(mi[0] >> 4); |
| 234 | |
| 235 | for (i = 1; i < mi_len - 1; i++) { |
| 236 | if (str_cur + 2 >= string + str_len) |
| 237 | return str_cur - string; |
| 238 | *str_cur++ = bcd2char(mi[i] & 0xf); |
| 239 | *str_cur++ = bcd2char(mi[i] >> 4); |
| 240 | } |
| 241 | break; |
| 242 | default: |
| 243 | break; |
| 244 | } |
| 245 | |
| 246 | *str_cur++ = '\0'; |
| 247 | return str_cur - string; |
| 248 | } |
| 249 | |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 250 | /* Chapter 9.2.10 */ |
| 251 | static int mm_tx_identity_req(struct gsm_lchan *lchan, u_int8_t id_type) |
| 252 | { |
| 253 | struct msgb *msg = gsm48_msgb_alloc(); |
| 254 | struct gsm48_hdr *gh; |
Harald Welte | fc977a8 | 2008-12-27 10:19:37 +0000 | [diff] [blame] | 255 | |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 256 | msg->lchan = lchan; |
| 257 | |
| 258 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 1); |
| 259 | gh->proto_discr = GSM48_PDISC_MM; |
| 260 | gh->msg_type = GSM48_MT_MM_ID_REQ; |
| 261 | gh->data[0] = id_type; |
| 262 | |
Harald Welte | 65e74cc | 2008-12-29 01:55:35 +0000 | [diff] [blame] | 263 | return gsm48_sendmsg(msg); |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | #define MI_SIZE 32 |
| 267 | |
| 268 | /* Chapter 9.2.11 */ |
| 269 | static int mm_rx_id_resp(struct msgb *msg) |
| 270 | { |
| 271 | struct gsm48_hdr *gh = msgb_l3(msg); |
Harald Welte | 75a983f | 2008-12-27 21:34:06 +0000 | [diff] [blame] | 272 | struct gsm_lchan *lchan = msg->lchan; |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 273 | u_int8_t mi_type = gh->data[1] & GSM_MI_TYPE_MASK; |
| 274 | char mi_string[MI_SIZE]; |
Harald Welte | 75a983f | 2008-12-27 21:34:06 +0000 | [diff] [blame] | 275 | u_int32_t tmsi; |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 276 | |
| 277 | 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] | 278 | DEBUGP(DMM, "IDENTITY RESPONSE: mi_type=0x%02x MI(%s)\n", |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 279 | mi_type, mi_string); |
| 280 | |
Harald Welte | 75a983f | 2008-12-27 21:34:06 +0000 | [diff] [blame] | 281 | switch (mi_type) { |
| 282 | case GSM_MI_TYPE_IMSI: |
| 283 | if (!lchan->subscr) |
| 284 | lchan->subscr = db_create_subscriber(mi_string); |
| 285 | if (lchan->subscr && lchan->subscr->authorized) { |
| 286 | /* FIXME: check if we've recently received UPDATE REQUEST */ |
| 287 | db_subscriber_alloc_tmsi(lchan->subscr); |
Harald Welte | 255539c | 2008-12-28 02:26:27 +0000 | [diff] [blame] | 288 | tmsi = strtoul(lchan->subscr->tmsi, NULL, 10); |
Harald Welte | 75a983f | 2008-12-27 21:34:06 +0000 | [diff] [blame] | 289 | return gsm0408_loc_upd_acc(msg->lchan, tmsi); |
| 290 | } |
| 291 | break; |
| 292 | case GSM_MI_TYPE_IMEI: |
Harald Welte | 255539c | 2008-12-28 02:26:27 +0000 | [diff] [blame] | 293 | case GSM_MI_TYPE_IMEISV: |
Harald Welte | 75a983f | 2008-12-27 21:34:06 +0000 | [diff] [blame] | 294 | /* update subscribe <-> IMEI mapping */ |
| 295 | if (lchan->subscr) |
| 296 | db_subscriber_assoc_imei(lchan->subscr, mi_string); |
| 297 | break; |
| 298 | } |
| 299 | return 0; |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 300 | } |
| 301 | |
Harald Welte | 255539c | 2008-12-28 02:26:27 +0000 | [diff] [blame] | 302 | |
| 303 | static void loc_upd_rej_cb(void *data) |
| 304 | { |
| 305 | struct gsm_lchan *lchan = data; |
| 306 | |
| 307 | gsm0408_loc_upd_rej(lchan, 0x16); |
| 308 | rsl_chan_release(lchan); |
| 309 | } |
| 310 | |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 311 | #define MI_SIZE 32 |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 312 | /* Chapter 9.2.15 */ |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 313 | static int mm_rx_loc_upd_req(struct msgb *msg) |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 314 | { |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 315 | struct gsm48_hdr *gh = msgb_l3(msg); |
Harald Welte | 702d870 | 2008-12-26 20:25:35 +0000 | [diff] [blame] | 316 | struct gsm_bts *bts = msg->trx->bts; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 317 | struct gsm48_loc_upd_req *lu; |
| 318 | struct gsm_subscriber *subscr; |
Harald Welte | 255539c | 2008-12-28 02:26:27 +0000 | [diff] [blame] | 319 | struct gsm_lchan *lchan = msg->lchan; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 320 | u_int8_t mi_type; |
Harald Welte | 75a983f | 2008-12-27 21:34:06 +0000 | [diff] [blame] | 321 | u_int32_t tmsi; |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 322 | char mi_string[MI_SIZE]; |
| 323 | int rc; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 324 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 325 | lu = (struct gsm48_loc_upd_req *) gh->data; |
| 326 | |
| 327 | mi_type = lu->mi[0] & GSM_MI_TYPE_MASK; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 328 | |
Harald Welte | fc977a8 | 2008-12-27 10:19:37 +0000 | [diff] [blame] | 329 | mi_to_string(mi_string, sizeof(mi_string), lu->mi, lu->mi_len); |
| 330 | |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 331 | 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] | 332 | switch (mi_type) { |
| 333 | case GSM_MI_TYPE_IMSI: |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 334 | /* we always want the IMEI, too */ |
Harald Welte | 255539c | 2008-12-28 02:26:27 +0000 | [diff] [blame] | 335 | rc = mm_tx_identity_req(lchan, GSM_MI_TYPE_IMEISV); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 336 | /* look up subscriber based on IMSI */ |
Harald Welte | 75a983f | 2008-12-27 21:34:06 +0000 | [diff] [blame] | 337 | subscr = db_create_subscriber(mi_string); |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 338 | break; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 339 | case GSM_MI_TYPE_TMSI: |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 340 | /* we always want the IMEI, too */ |
Harald Welte | 255539c | 2008-12-28 02:26:27 +0000 | [diff] [blame] | 341 | rc = mm_tx_identity_req(lchan, GSM_MI_TYPE_IMEISV); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 342 | /* look up the subscriber based on TMSI, request IMSI if it fails */ |
Harald Welte | fc977a8 | 2008-12-27 10:19:37 +0000 | [diff] [blame] | 343 | subscr = subscr_get_by_tmsi(lu->mi); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 344 | if (!subscr) { |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 345 | /* send IDENTITY REQUEST message to get IMSI */ |
Harald Welte | 255539c | 2008-12-28 02:26:27 +0000 | [diff] [blame] | 346 | rc = mm_tx_identity_req(lchan, GSM_MI_TYPE_IMSI); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 347 | } |
| 348 | break; |
| 349 | case GSM_MI_TYPE_IMEI: |
| 350 | case GSM_MI_TYPE_IMEISV: |
| 351 | /* no sim card... FIXME: what to do ? */ |
| 352 | fprintf(stderr, "Unimplemented mobile identity type\n"); |
| 353 | break; |
| 354 | default: |
| 355 | fprintf(stderr, "Unknown mobile identity type\n"); |
| 356 | break; |
| 357 | } |
| 358 | |
Harald Welte | 255539c | 2008-12-28 02:26:27 +0000 | [diff] [blame] | 359 | lchan->subscr = subscr; |
| 360 | |
Harald Welte | 75a983f | 2008-12-27 21:34:06 +0000 | [diff] [blame] | 361 | if (!subscr || !subscr->authorized) { |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 362 | /* 0x16 is congestion */ |
Harald Welte | 255539c | 2008-12-28 02:26:27 +0000 | [diff] [blame] | 363 | lchan->timer.cb = loc_upd_rej_cb; |
| 364 | lchan->timer.data = lchan; |
| 365 | schedule_timer(&lchan->timer, 1, 0); |
| 366 | return 0; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 367 | } |
| 368 | |
Harald Welte | 75a983f | 2008-12-27 21:34:06 +0000 | [diff] [blame] | 369 | db_subscriber_alloc_tmsi(subscr); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 370 | subscr_update(subscr, bts); |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 371 | |
Harald Welte | 255539c | 2008-12-28 02:26:27 +0000 | [diff] [blame] | 372 | tmsi = strtoul(subscr->tmsi, NULL, 10); |
| 373 | |
| 374 | return gsm0408_loc_upd_acc(lchan, tmsi); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 375 | } |
| 376 | |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 377 | static int gsm48_tx_mm_serv_ack(struct gsm_lchan *lchan) |
| 378 | { |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 379 | DEBUGP(DMM, "-> CM SERVICE ACK\n"); |
Harald Welte | 65e74cc | 2008-12-29 01:55:35 +0000 | [diff] [blame] | 380 | 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] | 381 | } |
| 382 | |
| 383 | static int gsm48_rx_mm_serv_req(struct msgb *msg) |
| 384 | { |
| 385 | struct gsm48_hdr *gh = msgb_l3(msg); |
Harald Welte | bcae43f | 2008-12-27 21:45:37 +0000 | [diff] [blame] | 386 | u_int8_t serv_type = gh->data[0] & 0x0f; |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 387 | |
Harald Welte | 65e74cc | 2008-12-29 01:55:35 +0000 | [diff] [blame] | 388 | DEBUGP(DMM, "<- CM SERVICE REQUEST serv_type=0x%02x\n", serv_type); |
Harald Welte | bcae43f | 2008-12-27 21:45:37 +0000 | [diff] [blame] | 389 | |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 390 | return gsm48_tx_mm_serv_ack(msg->lchan); |
| 391 | } |
| 392 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 393 | static int gsm0408_rcv_mm(struct msgb *msg) |
| 394 | { |
| 395 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 396 | int rc; |
| 397 | |
| 398 | switch (gh->msg_type & 0xbf) { |
| 399 | case GSM48_MT_MM_LOC_UPD_REQUEST: |
| 400 | DEBUGP(DMM, "LOCATION UPDATE REQUEST\n"); |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 401 | rc = mm_rx_loc_upd_req(msg); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 402 | break; |
| 403 | case GSM48_MT_MM_ID_RESP: |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 404 | rc = mm_rx_id_resp(msg); |
| 405 | break; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 406 | case GSM48_MT_MM_CM_SERV_REQ: |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 407 | rc = gsm48_rx_mm_serv_req(msg); |
| 408 | break; |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 409 | case GSM48_MT_MM_STATUS: |
| 410 | DEBUGP(DMM, "MM STATUS: FIXME parse error cond.\n"); |
| 411 | break; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 412 | case GSM48_MT_MM_CM_REEST_REQ: |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 413 | case GSM48_MT_MM_TMSI_REALL_COMPL: |
| 414 | case GSM48_MT_MM_AUTH_RESP: |
| 415 | case GSM48_MT_MM_IMSI_DETACH_IND: |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 416 | fprintf(stderr, "Unimplemented GSM 04.08 MM msg type 0x%02x\n", |
| 417 | gh->msg_type); |
| 418 | break; |
| 419 | default: |
| 420 | fprintf(stderr, "Unknown GSM 04.08 MM msg type 0x%02x\n", |
| 421 | gh->msg_type); |
| 422 | break; |
| 423 | } |
| 424 | |
| 425 | return rc; |
| 426 | } |
| 427 | static int gsm0408_rcv_rr(struct msgb *msg) |
| 428 | { |
| 429 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 430 | |
| 431 | switch (gh->msg_type) { |
| 432 | case GSM48_MT_RR_CLSM_CHG: |
| 433 | DEBUGP(DRR, "CLASSMARK CHANGE\n"); |
| 434 | /* FIXME: what to do ?!? */ |
| 435 | break; |
Harald Welte | fc977a8 | 2008-12-27 10:19:37 +0000 | [diff] [blame] | 436 | case GSM48_MT_RR_GPRS_SUSP_REQ: |
| 437 | DEBUGP(DRR, "GRPS SUSPEND REQUEST\n"); |
| 438 | break; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 439 | case GSM48_MT_RR_PAG_RESP: |
| 440 | default: |
| 441 | fprintf(stderr, "Unimplemented GSM 04.08 msg type 0x%02x\n", |
| 442 | gh->msg_type); |
| 443 | break; |
| 444 | } |
| 445 | |
| 446 | return 0; |
| 447 | } |
| 448 | |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 449 | /* Call Control */ |
| 450 | |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 451 | static int gsm48_cc_tx_status(struct gsm_lchan *lchan) |
| 452 | { |
| 453 | struct msgb *msg = gsm48_msgb_alloc(); |
| 454 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 455 | u_int8_t *cause, *call_state; |
| 456 | |
Harald Welte | 65e74cc | 2008-12-29 01:55:35 +0000 | [diff] [blame] | 457 | gh->proto_discr = GSM48_PDISC_CC; |
| 458 | |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 459 | msg->lchan = lchan; |
| 460 | |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 461 | gh->msg_type = GSM48_MT_CC_STATUS; |
| 462 | |
| 463 | cause = msgb_put(msg, 3); |
| 464 | cause[0] = 2; |
| 465 | cause[1] = GSM48_CAUSE_CS_GSM | GSM48_CAUSE_LOC_USER; |
| 466 | cause[2] = 0x80 | 30; /* response to status inquiry */ |
| 467 | |
| 468 | call_state = msgb_put(msg, 1); |
| 469 | call_state[0] = 0xc0 | 0x00; |
| 470 | |
Harald Welte | 65e74cc | 2008-12-29 01:55:35 +0000 | [diff] [blame] | 471 | return gsm48_sendmsg(msg); |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 472 | } |
| 473 | |
Harald Welte | 6f4b753 | 2008-12-29 00:39:37 +0000 | [diff] [blame] | 474 | static int gsm48_tx_simple(struct gsm_lchan *lchan, |
| 475 | u_int8_t pdisc, u_int8_t msg_type) |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 476 | { |
| 477 | struct msgb *msg = gsm48_msgb_alloc(); |
| 478 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 479 | |
| 480 | msg->lchan = lchan; |
| 481 | |
Harald Welte | 6f4b753 | 2008-12-29 00:39:37 +0000 | [diff] [blame] | 482 | gh->proto_discr = pdisc; |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 483 | gh->msg_type = msg_type; |
| 484 | |
Harald Welte | 65e74cc | 2008-12-29 01:55:35 +0000 | [diff] [blame] | 485 | return gsm48_sendmsg(msg); |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 486 | } |
| 487 | |
| 488 | static int gsm48_cc_rx_status_enq(struct msgb *msg) |
| 489 | { |
| 490 | return gsm48_cc_tx_status(msg->lchan); |
| 491 | } |
| 492 | |
| 493 | static int gsm48_cc_rx_setup(struct msgb *msg) |
| 494 | { |
Harald Welte | 6f4b753 | 2008-12-29 00:39:37 +0000 | [diff] [blame] | 495 | return gsm48_tx_simple(msg->lchan, GSM48_PDISC_CC, |
| 496 | GSM48_MT_CC_CALL_CONF); |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 497 | } |
| 498 | |
Harald Welte | 65e74cc | 2008-12-29 01:55:35 +0000 | [diff] [blame] | 499 | int gsm48_cc_tx_setup(struct gsm_lchan *lchan) |
| 500 | { |
| 501 | struct msgb *msg = gsm48_msgb_alloc(); |
| 502 | struct gsm48_hdr *gh; |
| 503 | struct gsm_call *call = &lchan->call; |
| 504 | |
| 505 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 8); |
| 506 | |
| 507 | call->type = GSM_CT_MT; |
| 508 | msg->lchan = lchan; |
| 509 | |
| 510 | gh->proto_discr = GSM48_PDISC_CC; |
| 511 | gh->msg_type = GSM48_MT_CC_SETUP; |
| 512 | gh->data[0] = 0x34; |
| 513 | gh->data[1] = 0x00; |
| 514 | gh->data[2] = 0x5c; |
| 515 | gh->data[3] = 0x04; |
| 516 | gh->data[4] = 0xb9; |
| 517 | gh->data[5] = 0x83; |
| 518 | gh->data[6] = 0x32; |
| 519 | gh->data[7] = 0x24; |
| 520 | |
| 521 | DEBUGP(DCC, "Sending SETUP\n"); |
| 522 | |
| 523 | return gsm48_sendmsg(msg); |
| 524 | } |
| 525 | |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 526 | static int gsm0408_rcv_cc(struct msgb *msg) |
| 527 | { |
| 528 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 529 | u_int8_t msg_type = gh->msg_type & 0xbf; |
| 530 | struct gsm_call *call = &msg->lchan->call; |
| 531 | int rc = 0; |
| 532 | |
| 533 | switch (msg_type) { |
| 534 | case GSM48_MT_CC_CALL_CONF: |
| 535 | /* Response to SETUP */ |
| 536 | DEBUGP(DCC, "CALL CONFIRM\n"); |
| 537 | break; |
| 538 | case GSM48_MT_CC_RELEASE_COMPL: |
| 539 | /* Answer from MS to RELEASE */ |
| 540 | DEBUGP(DCC, "RELEASE COMPLETE (state->NULL)\n"); |
| 541 | call->state = GSM_CSTATE_NULL; |
| 542 | break; |
| 543 | case GSM48_MT_CC_ALERTING: |
| 544 | DEBUGP(DCC, "ALERTING\n"); |
| 545 | break; |
| 546 | case GSM48_MT_CC_CONNECT: |
| 547 | DEBUGP(DCC, "CONNECT\n"); |
| 548 | /* MT: need to respond with CONNECT_ACK */ |
Harald Welte | 6f4b753 | 2008-12-29 00:39:37 +0000 | [diff] [blame] | 549 | rc = gsm48_tx_simple(msg->lchan, GSM48_PDISC_CC, |
| 550 | GSM48_MT_CC_CONNECT_ACK); |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 551 | break; |
| 552 | case GSM48_MT_CC_CONNECT_ACK: |
| 553 | /* MO: Answer to CONNECT */ |
| 554 | call->state = GSM_CSTATE_ACTIVE; |
| 555 | DEBUGP(DCC, "CONNECT_ACK (state->ACTIVE)\n"); |
| 556 | break; |
| 557 | case GSM48_MT_CC_RELEASE: |
| 558 | DEBUGP(DCC, "RELEASE\n"); |
| 559 | /* need to respond with RELEASE_COMPLETE */ |
| 560 | break; |
| 561 | case GSM48_MT_CC_STATUS_ENQ: |
| 562 | rc = gsm48_cc_rx_status_enq(msg); |
| 563 | break; |
| 564 | case GSM48_MT_CC_DISCONNECT: |
| 565 | /* Section 5.4.3.2 */ |
| 566 | DEBUGP(DCC, "DISCONNECT (state->RELEASE_REQ)\n"); |
| 567 | call->state = GSM_CSTATE_RELEASE_REQ; |
| 568 | /* FIXME: clear the network connection */ |
Harald Welte | 6f4b753 | 2008-12-29 00:39:37 +0000 | [diff] [blame] | 569 | rc = gsm48_tx_simple(msg->lchan, GSM48_PDISC_CC, |
| 570 | GSM48_MT_CC_RELEASE); |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 571 | break; |
| 572 | case GSM48_MT_CC_SETUP: |
| 573 | call->type = GSM_CT_MO; |
| 574 | call->state = GSM_CSTATE_INITIATED; |
| 575 | call->transaction_id = gh->proto_discr & 0xf0; |
| 576 | DEBUGP(DCC, "SETUP(tid=0x%02x)\n", call->transaction_id); |
Harald Welte | 6f4b753 | 2008-12-29 00:39:37 +0000 | [diff] [blame] | 577 | rc = gsm48_tx_simple(msg->lchan, GSM48_PDISC_CC, |
| 578 | GSM48_MT_CC_CONNECT); |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 579 | /* FIXME: continue with CALL_PROCEEDING, ALERTING, CONNECT, RELEASE_COMPLETE */ |
| 580 | break; |
| 581 | case GSM48_MT_CC_EMERG_SETUP: |
| 582 | DEBUGP(DCC, "EMERGENCY SETUP\n"); |
| 583 | /* FIXME: continue with CALL_PROCEEDING, ALERTING, CONNECT, RELEASE_COMPLETE */ |
| 584 | break; |
| 585 | default: |
| 586 | fprintf(stderr, "Unimplemented GSM 04.08 msg type 0x%02x\n", |
| 587 | msg_type); |
| 588 | break; |
| 589 | } |
| 590 | |
| 591 | return rc; |
| 592 | } |
| 593 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 594 | /* here we pass in a msgb from the RSL->RLL. We expect the l3 pointer to be set */ |
| 595 | int gsm0408_rcvmsg(struct msgb *msg) |
| 596 | { |
| 597 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 598 | u_int8_t pdisc = gh->proto_discr & 0x0f; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 599 | int rc = 0; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 600 | |
| 601 | switch (pdisc) { |
| 602 | case GSM48_PDISC_CC: |
| 603 | rc = gsm0408_rcv_cc(msg); |
| 604 | break; |
| 605 | case GSM48_PDISC_MM: |
| 606 | rc = gsm0408_rcv_mm(msg); |
| 607 | break; |
| 608 | case GSM48_PDISC_RR: |
| 609 | rc = gsm0408_rcv_rr(msg); |
| 610 | break; |
Harald Welte | bcae43f | 2008-12-27 21:45:37 +0000 | [diff] [blame] | 611 | case GSM48_PDISC_SMS: |
Daniel Willmann | 8b3390e | 2008-12-28 00:31:09 +0000 | [diff] [blame] | 612 | rc = gsm0411_rcv_sms(msg); |
Harald Welte | bcae43f | 2008-12-27 21:45:37 +0000 | [diff] [blame] | 613 | break; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 614 | case GSM48_PDISC_MM_GPRS: |
Harald Welte | bcae43f | 2008-12-27 21:45:37 +0000 | [diff] [blame] | 615 | case GSM48_PDISC_SM_GPRS: |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 616 | fprintf(stderr, "Unimplemented GSM 04.08 discriminator 0x%02d\n", |
| 617 | pdisc); |
| 618 | break; |
| 619 | default: |
| 620 | fprintf(stderr, "Unknown GSM 04.08 discriminator 0x%02d\n", |
| 621 | pdisc); |
| 622 | break; |
| 623 | } |
| 624 | |
| 625 | return rc; |
| 626 | } |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 627 | |
| 628 | enum chreq_type { |
| 629 | CHREQ_T_EMERG_CALL, |
| 630 | CHREQ_T_CALL_REEST_TCH_F, |
| 631 | CHREQ_T_CALL_REEST_TCH_H, |
| 632 | CHREQ_T_CALL_REEST_TCH_H_DBL, |
| 633 | CHREQ_T_SDCCH, |
| 634 | CHREQ_T_TCH_F, |
| 635 | CHREQ_T_VOICE_CALL_TCH_H, |
| 636 | CHREQ_T_DATA_CALL_TCH_H, |
| 637 | CHREQ_T_LOCATION_UPD, |
| 638 | CHREQ_T_PAG_R_ANY, |
| 639 | CHREQ_T_PAG_R_TCH_F, |
| 640 | CHREQ_T_PAG_R_TCH_FH, |
| 641 | }; |
| 642 | |
| 643 | /* Section 9.1.8 / Table 9.9 */ |
| 644 | struct chreq { |
| 645 | u_int8_t val; |
| 646 | u_int8_t mask; |
| 647 | enum chreq_type type; |
| 648 | }; |
| 649 | |
| 650 | /* If SYSTEM INFORMATION TYPE 4 NECI bit == 1 */ |
| 651 | static const struct chreq chreq_type_neci1[] = { |
| 652 | { 0xa0, 0xe0, CHREQ_T_EMERG_CALL }, |
| 653 | { 0xc0, 0xe0, CHREQ_T_CALL_REEST_TCH_F }, |
| 654 | { 0x68, 0xfc, CHREQ_T_CALL_REEST_TCH_H }, |
| 655 | { 0x6c, 0xfc, CHREQ_T_CALL_REEST_TCH_H_DBL }, |
| 656 | { 0xe0, 0xe0, CHREQ_T_SDCCH }, |
| 657 | { 0x40, 0xf0, CHREQ_T_VOICE_CALL_TCH_H }, |
| 658 | { 0x50, 0xf0, CHREQ_T_DATA_CALL_TCH_H }, |
| 659 | { 0x00, 0xf0, CHREQ_T_LOCATION_UPD }, |
| 660 | { 0x10, 0xf0, CHREQ_T_SDCCH }, |
| 661 | { 0x80, 0xe0, CHREQ_T_PAG_R_ANY }, |
| 662 | { 0x20, 0xf0, CHREQ_T_PAG_R_TCH_F }, |
| 663 | { 0x30, 0xf0, CHREQ_T_PAG_R_TCH_FH }, |
| 664 | }; |
| 665 | |
| 666 | /* If SYSTEM INFORMATION TYPE 4 NECI bit == 0 */ |
| 667 | static const struct chreq chreq_type_neci0[] = { |
| 668 | { 0xa0, 0xe0, CHREQ_T_EMERG_CALL }, |
| 669 | { 0xc0, 0xe0, CHREQ_T_CALL_REEST_TCH_H }, |
| 670 | { 0xe0, 0xe0, CHREQ_T_TCH_F }, |
| 671 | { 0x50, 0xf0, CHREQ_T_DATA_CALL_TCH_H }, |
| 672 | { 0x00, 0xe0, CHREQ_T_LOCATION_UPD }, |
| 673 | { 0x80, 0xe0, CHREQ_T_PAG_R_ANY }, |
| 674 | { 0x20, 0xf0, CHREQ_T_PAG_R_TCH_F }, |
| 675 | { 0x30, 0xf0, CHREQ_T_PAG_R_TCH_FH }, |
| 676 | }; |
| 677 | |
| 678 | static const enum gsm_chan_t ctype_by_chreq[] = { |
| 679 | [CHREQ_T_EMERG_CALL] = GSM_LCHAN_TCH_F, |
| 680 | [CHREQ_T_CALL_REEST_TCH_F] = GSM_LCHAN_TCH_F, |
| 681 | [CHREQ_T_CALL_REEST_TCH_H] = GSM_LCHAN_TCH_H, |
| 682 | [CHREQ_T_CALL_REEST_TCH_H_DBL] = GSM_LCHAN_TCH_H, |
| 683 | [CHREQ_T_SDCCH] = GSM_LCHAN_SDCCH, |
| 684 | [CHREQ_T_TCH_F] = GSM_LCHAN_TCH_F, |
| 685 | [CHREQ_T_VOICE_CALL_TCH_H] = GSM_LCHAN_TCH_H, |
| 686 | [CHREQ_T_DATA_CALL_TCH_H] = GSM_LCHAN_TCH_H, |
| 687 | [CHREQ_T_LOCATION_UPD] = GSM_LCHAN_SDCCH, |
| 688 | [CHREQ_T_PAG_R_ANY] = GSM_LCHAN_SDCCH, |
| 689 | [CHREQ_T_PAG_R_TCH_F] = GSM_LCHAN_TCH_F, |
| 690 | [CHREQ_T_PAG_R_TCH_FH] = GSM_LCHAN_TCH_F, |
| 691 | }; |
| 692 | |
Harald Welte | e14a57c | 2008-12-29 04:08:28 +0000 | [diff] [blame] | 693 | static const enum gsm_chreq_reason_t reason_by_chreq[] = { |
| 694 | [CHREQ_T_EMERG_CALL] = GSM_CHREQ_REASON_EMERG, |
| 695 | [CHREQ_T_CALL_REEST_TCH_F] = GSM_CHREQ_REASON_CALL, |
| 696 | [CHREQ_T_CALL_REEST_TCH_H] = GSM_CHREQ_REASON_CALL, |
| 697 | [CHREQ_T_CALL_REEST_TCH_H_DBL] = GSM_CHREQ_REASON_CALL, |
| 698 | [CHREQ_T_SDCCH] = GSM_CHREQ_REASON_OTHER, |
| 699 | [CHREQ_T_TCH_F] = GSM_CHREQ_REASON_OTHER, |
| 700 | [CHREQ_T_VOICE_CALL_TCH_H] = GSM_CHREQ_REASON_OTHER, |
| 701 | [CHREQ_T_DATA_CALL_TCH_H] = GSM_CHREQ_REASON_OTHER, |
| 702 | [CHREQ_T_LOCATION_UPD] = GSM_CHREQ_REASON_LOCATION_UPD, |
| 703 | [CHREQ_T_PAG_R_ANY] = GSM_CHREQ_REASON_PAG, |
| 704 | [CHREQ_T_PAG_R_TCH_F] = GSM_CHREQ_REASON_PAG, |
| 705 | [CHREQ_T_PAG_R_TCH_FH] = GSM_CHREQ_REASON_PAG, |
| 706 | }; |
| 707 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 708 | enum gsm_chan_t get_ctype_by_chreq(struct gsm_bts *bts, u_int8_t ra) |
| 709 | { |
| 710 | int i; |
| 711 | /* FIXME: determine if we set NECI = 0 in the BTS SI4 */ |
| 712 | |
| 713 | for (i = 0; i < ARRAY_SIZE(chreq_type_neci0); i++) { |
| 714 | const struct chreq *chr = &chreq_type_neci0[i]; |
| 715 | if ((ra & chr->mask) == chr->val) |
| 716 | return ctype_by_chreq[chr->type]; |
| 717 | } |
| 718 | fprintf(stderr, "Unknown CHANNEL REQUEST RQD 0x%02x\n", ra); |
| 719 | return GSM_LCHAN_SDCCH; |
| 720 | } |
Harald Welte | e14a57c | 2008-12-29 04:08:28 +0000 | [diff] [blame] | 721 | |
| 722 | enum gsm_chreq_reason_t get_reason_by_chreq(struct gsm_bts *bts, u_int8_t ra) |
| 723 | { |
| 724 | int i; |
| 725 | /* FIXME: determine if we set NECI = 0 in the BTS SI4 */ |
| 726 | |
| 727 | for (i = 0; i < ARRAY_SIZE(chreq_type_neci0); i++) { |
| 728 | const struct chreq *chr = &chreq_type_neci0[i]; |
| 729 | if ((ra & chr->mask) == chr->val) |
| 730 | return reason_by_chreq[chr->type]; |
| 731 | } |
| 732 | fprintf(stderr, "Unknown CHANNEL REQUEST REASON 0x%02x\n", ra); |
| 733 | return GSM_CHREQ_REASON_OTHER; |
| 734 | } |