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