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