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 | |
Harald Welte | bf5e8df | 2009-02-03 12:59:45 +0000 | [diff] [blame] | 4 | /* (C) 2008-2009 by Harald Welte <laforge@gnumonks.org> |
Harald Welte | 498b0bb | 2009-01-09 21:27:43 +0000 | [diff] [blame] | 5 | * (C) 2008, 2009 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 | db253af | 2008-12-30 17:56:55 +0000 | [diff] [blame] | 30 | #include <time.h> |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 31 | #include <netinet/in.h> |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 32 | |
Harald Welte | 75a983f | 2008-12-27 21:34:06 +0000 | [diff] [blame] | 33 | #include <openbsc/db.h> |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 34 | #include <openbsc/msgb.h> |
| 35 | #include <openbsc/debug.h> |
| 36 | #include <openbsc/gsm_data.h> |
| 37 | #include <openbsc/gsm_subscriber.h> |
Daniel Willmann | 8b3390e | 2008-12-28 00:31:09 +0000 | [diff] [blame] | 38 | #include <openbsc/gsm_04_11.h> |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 39 | #include <openbsc/gsm_04_08.h> |
| 40 | #include <openbsc/abis_rsl.h> |
Holger Freyther | ca362a6 | 2009-01-04 21:05:01 +0000 | [diff] [blame] | 41 | #include <openbsc/chan_alloc.h> |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 42 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 43 | #define GSM48_ALLOC_SIZE 1024 |
| 44 | #define GSM48_ALLOC_HEADROOM 128 |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 45 | |
Harald Welte | 65e74cc | 2008-12-29 01:55:35 +0000 | [diff] [blame] | 46 | static int gsm48_tx_simple(struct gsm_lchan *lchan, |
| 47 | u_int8_t pdisc, u_int8_t msg_type); |
Holger Freyther | b7193e4 | 2008-12-29 17:44:08 +0000 | [diff] [blame] | 48 | static void schedule_reject(struct gsm_lchan *lchan); |
Harald Welte | 65e74cc | 2008-12-29 01:55:35 +0000 | [diff] [blame] | 49 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 50 | struct gsm_lai { |
| 51 | u_int16_t mcc; |
| 52 | u_int16_t mnc; |
| 53 | u_int16_t lac; |
| 54 | }; |
| 55 | |
Holger Freyther | 89824fc | 2008-12-30 16:18:18 +0000 | [diff] [blame] | 56 | static int authorize_everonye = 0; |
| 57 | void gsm0408_allow_everyone(int everyone) |
| 58 | { |
| 59 | printf("Allowing everyone?\n"); |
| 60 | authorize_everonye = everyone; |
| 61 | } |
| 62 | |
Holger Freyther | e97f7fb | 2008-12-31 18:52:11 +0000 | [diff] [blame] | 63 | static int reject_cause = 0; |
| 64 | void gsm0408_set_reject_cause(int cause) |
| 65 | { |
| 66 | reject_cause = cause; |
| 67 | } |
| 68 | |
Holger Freyther | 73487a2 | 2008-12-31 18:53:57 +0000 | [diff] [blame] | 69 | static int authorize_subscriber(struct gsm_loc_updating_operation *loc, |
| 70 | struct gsm_subscriber *subscriber) |
Holger Freyther | 89824fc | 2008-12-30 16:18:18 +0000 | [diff] [blame] | 71 | { |
| 72 | if (!subscriber) |
| 73 | return 0; |
| 74 | |
Holger Freyther | 73487a2 | 2008-12-31 18:53:57 +0000 | [diff] [blame] | 75 | /* |
| 76 | * Do not send accept yet as more information should arrive. Some |
| 77 | * phones will not send us the information and we will have to check |
| 78 | * what we want to do with that. |
| 79 | */ |
| 80 | if (loc && (loc->waiting_for_imsi || loc->waiting_for_imei)) |
| 81 | return 0; |
| 82 | |
Holger Freyther | 89824fc | 2008-12-30 16:18:18 +0000 | [diff] [blame] | 83 | if (authorize_everonye) |
| 84 | return 1; |
| 85 | |
| 86 | return subscriber->authorized; |
| 87 | } |
Holger Freyther | 07cc8d8 | 2008-12-29 06:23:46 +0000 | [diff] [blame] | 88 | |
Holger Freyther | 73487a2 | 2008-12-31 18:53:57 +0000 | [diff] [blame] | 89 | static void release_loc_updating_req(struct gsm_lchan *lchan) |
| 90 | { |
Harald Welte | 179f064 | 2008-12-31 23:59:18 +0000 | [diff] [blame] | 91 | if (!lchan->loc_operation) |
Holger Freyther | 73487a2 | 2008-12-31 18:53:57 +0000 | [diff] [blame] | 92 | return; |
| 93 | |
| 94 | del_timer(&lchan->loc_operation->updating_timer); |
| 95 | free(lchan->loc_operation); |
| 96 | lchan->loc_operation = 0; |
Holger Freyther | 3eaa792 | 2009-01-01 02:59:03 +0000 | [diff] [blame] | 97 | put_lchan(lchan); |
Holger Freyther | 73487a2 | 2008-12-31 18:53:57 +0000 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | static void allocate_loc_updating_req(struct gsm_lchan *lchan) |
| 101 | { |
Holger Freyther | 67b4b9a | 2009-01-01 03:46:11 +0000 | [diff] [blame] | 102 | use_lchan(lchan); |
Holger Freyther | 73487a2 | 2008-12-31 18:53:57 +0000 | [diff] [blame] | 103 | release_loc_updating_req(lchan); |
| 104 | |
| 105 | lchan->loc_operation = (struct gsm_loc_updating_operation *) |
| 106 | malloc(sizeof(*lchan->loc_operation)); |
| 107 | memset(lchan->loc_operation, 0, sizeof(*lchan->loc_operation)); |
| 108 | } |
Holger Freyther | 07cc8d8 | 2008-12-29 06:23:46 +0000 | [diff] [blame] | 109 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 110 | static void to_bcd(u_int8_t *bcd, u_int16_t val) |
| 111 | { |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 112 | bcd[2] = val % 10; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 113 | val = val / 10; |
| 114 | bcd[1] = val % 10; |
| 115 | val = val / 10; |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 116 | bcd[0] = val % 10; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 117 | val = val / 10; |
| 118 | } |
| 119 | |
Holger Freyther | 1774661 | 2008-12-28 16:32:44 +0000 | [diff] [blame] | 120 | 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] | 121 | u_int16_t mnc, u_int16_t lac) |
| 122 | { |
| 123 | u_int8_t bcd[3]; |
| 124 | |
| 125 | to_bcd(bcd, mcc); |
| 126 | lai48->digits[0] = bcd[0] | (bcd[1] << 4); |
| 127 | lai48->digits[1] = bcd[2]; |
| 128 | |
| 129 | to_bcd(bcd, mnc); |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 130 | /* FIXME: do we need three-digit MNC? See Table 10.5.3 */ |
| 131 | #if 0 |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 132 | lai48->digits[1] |= bcd[2] << 4; |
| 133 | lai48->digits[2] = bcd[0] | (bcd[1] << 4); |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 134 | #else |
| 135 | lai48->digits[1] |= 0xf << 4; |
| 136 | lai48->digits[2] = bcd[1] | (bcd[2] << 4); |
| 137 | #endif |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 138 | |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 139 | lai48->lac = htons(lac); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 140 | } |
| 141 | |
Harald Welte | 255539c | 2008-12-28 02:26:27 +0000 | [diff] [blame] | 142 | #define TMSI_LEN 5 |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 143 | #define MID_TMSI_LEN (TMSI_LEN + 2) |
| 144 | |
Harald Welte | 255539c | 2008-12-28 02:26:27 +0000 | [diff] [blame] | 145 | 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] | 146 | { |
Harald Welte | 65e74cc | 2008-12-29 01:55:35 +0000 | [diff] [blame] | 147 | u_int32_t *tptr = (u_int32_t *) &buf[3]; |
Harald Welte | 255539c | 2008-12-28 02:26:27 +0000 | [diff] [blame] | 148 | |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 149 | buf[0] = GSM48_IE_MOBILE_ID; |
Harald Welte | 1a41218 | 2008-12-27 22:13:43 +0000 | [diff] [blame] | 150 | buf[1] = TMSI_LEN; |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 151 | buf[2] = 0xf0 | GSM_MI_TYPE_TMSI; |
Harald Welte | 255539c | 2008-12-28 02:26:27 +0000 | [diff] [blame] | 152 | *tptr = htonl(tmsi); |
| 153 | |
| 154 | return 7; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 155 | } |
| 156 | |
Holger Freyther | 819dd20 | 2009-01-04 03:52:50 +0000 | [diff] [blame] | 157 | struct msgb *gsm48_msgb_alloc(void) |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 158 | { |
| 159 | return msgb_alloc_headroom(GSM48_ALLOC_SIZE, GSM48_ALLOC_HEADROOM); |
| 160 | } |
| 161 | |
Holger Freyther | 3e2c323 | 2009-01-04 03:55:31 +0000 | [diff] [blame] | 162 | int gsm48_sendmsg(struct msgb *msg) |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 163 | { |
Harald Welte | 65e74cc | 2008-12-29 01:55:35 +0000 | [diff] [blame] | 164 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msg->data; |
| 165 | |
| 166 | if (msg->lchan) { |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 167 | msg->trx = msg->lchan->ts->trx; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 168 | |
Harald Welte | 65e74cc | 2008-12-29 01:55:35 +0000 | [diff] [blame] | 169 | if ((gh->proto_discr & GSM48_PDISC_MASK) == GSM48_PDISC_CC) { |
| 170 | /* Send a 04.08 call control message, add transaction |
| 171 | * ID and TI flag */ |
| 172 | gh->proto_discr |= msg->lchan->call.transaction_id; |
| 173 | |
| 174 | /* GSM 04.07 Section 11.2.3.1.3 */ |
| 175 | switch (msg->lchan->call.type) { |
| 176 | case GSM_CT_MO: |
| 177 | gh->proto_discr |= 0x80; |
| 178 | break; |
| 179 | case GSM_CT_MT: |
| 180 | break; |
Holger Freyther | ca362a6 | 2009-01-04 21:05:01 +0000 | [diff] [blame] | 181 | case GSM_CT_NONE: |
| 182 | break; |
Harald Welte | 65e74cc | 2008-12-29 01:55:35 +0000 | [diff] [blame] | 183 | } |
| 184 | } |
| 185 | } |
| 186 | |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 187 | msg->l3h = msg->data; |
| 188 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 189 | return rsl_data_request(msg, 0); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 190 | } |
| 191 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 192 | |
Holger Freyther | 429e776 | 2008-12-30 13:28:30 +0000 | [diff] [blame] | 193 | /* Chapter 9.2.14 : Send LOCATION UPDATING REJECT */ |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 194 | 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] | 195 | { |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 196 | struct msgb *msg = gsm48_msgb_alloc(); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 197 | struct gsm48_hdr *gh; |
| 198 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 199 | msg->lchan = lchan; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 200 | |
| 201 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 1); |
| 202 | gh->proto_discr = GSM48_PDISC_MM; |
Harald Welte | 10b487b | 2008-12-27 19:53:37 +0000 | [diff] [blame] | 203 | gh->msg_type = GSM48_MT_MM_LOC_UPD_REJECT; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 204 | gh->data[0] = cause; |
| 205 | |
Harald Welte | db253af | 2008-12-30 17:56:55 +0000 | [diff] [blame] | 206 | DEBUGP(DMM, "-> LOCATION UPDATING REJECT on channel: %d\n", lchan->nr); |
| 207 | |
Harald Welte | 65e74cc | 2008-12-29 01:55:35 +0000 | [diff] [blame] | 208 | return gsm48_sendmsg(msg); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | /* Chapter 9.2.13 : Send LOCATION UPDATE ACCEPT */ |
Harald Welte | 75a983f | 2008-12-27 21:34:06 +0000 | [diff] [blame] | 212 | 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] | 213 | { |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 214 | struct gsm_bts *bts = lchan->ts->trx->bts; |
| 215 | struct msgb *msg = gsm48_msgb_alloc(); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 216 | struct gsm48_hdr *gh; |
| 217 | struct gsm48_loc_area_id *lai; |
| 218 | u_int8_t *mid; |
Holger Freyther | 07cc8d8 | 2008-12-29 06:23:46 +0000 | [diff] [blame] | 219 | int ret; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 220 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 221 | msg->lchan = lchan; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 222 | |
| 223 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 224 | gh->proto_discr = GSM48_PDISC_MM; |
| 225 | gh->msg_type = GSM48_MT_MM_LOC_UPD_ACCEPT; |
| 226 | |
| 227 | lai = (struct gsm48_loc_area_id *) msgb_put(msg, sizeof(*lai)); |
Holger Freyther | 1774661 | 2008-12-28 16:32:44 +0000 | [diff] [blame] | 228 | gsm0408_generate_lai(lai, bts->network->country_code, |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 229 | bts->network->network_code, bts->location_area_code); |
| 230 | |
| 231 | mid = msgb_put(msg, MID_TMSI_LEN); |
| 232 | generate_mid_from_tmsi(mid, tmsi); |
| 233 | |
| 234 | DEBUGP(DMM, "-> LOCATION UPDATE ACCEPT\n"); |
| 235 | |
Harald Welte | db253af | 2008-12-30 17:56:55 +0000 | [diff] [blame] | 236 | ret = gsm48_sendmsg(msg); |
| 237 | |
Harald Welte | ba4cf16 | 2009-01-10 01:49:35 +0000 | [diff] [blame] | 238 | ret = gsm48_cc_tx_setup(lchan); |
Harald Welte | db253af | 2008-12-30 17:56:55 +0000 | [diff] [blame] | 239 | ret = gsm48_tx_mm_info(lchan); |
Harald Welte | db253af | 2008-12-30 17:56:55 +0000 | [diff] [blame] | 240 | |
Holger Freyther | 07cc8d8 | 2008-12-29 06:23:46 +0000 | [diff] [blame] | 241 | return ret; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 242 | } |
| 243 | |
Harald Welte | fc977a8 | 2008-12-27 10:19:37 +0000 | [diff] [blame] | 244 | static char bcd2char(u_int8_t bcd) |
| 245 | { |
| 246 | if (bcd < 0xa) |
| 247 | return '0' + bcd; |
| 248 | else |
| 249 | return 'A' + (bcd - 0xa); |
| 250 | } |
| 251 | |
Harald Welte | bf5e8df | 2009-02-03 12:59:45 +0000 | [diff] [blame] | 252 | /* Convert Mobile Identity (10.5.1.4) to string */ |
Harald Welte | fc977a8 | 2008-12-27 10:19:37 +0000 | [diff] [blame] | 253 | static int mi_to_string(char *string, int str_len, u_int8_t *mi, int mi_len) |
| 254 | { |
| 255 | int i; |
| 256 | u_int8_t mi_type; |
| 257 | char *str_cur = string; |
Harald Welte | 4ed0e92 | 2009-01-10 03:17:30 +0000 | [diff] [blame] | 258 | u_int32_t tmsi; |
Harald Welte | fc977a8 | 2008-12-27 10:19:37 +0000 | [diff] [blame] | 259 | |
| 260 | mi_type = mi[0] & GSM_MI_TYPE_MASK; |
| 261 | |
| 262 | switch (mi_type) { |
| 263 | case GSM_MI_TYPE_NONE: |
| 264 | break; |
| 265 | case GSM_MI_TYPE_TMSI: |
Harald Welte | 4ed0e92 | 2009-01-10 03:17:30 +0000 | [diff] [blame] | 266 | /* Table 10.5.4.3, reverse generate_mid_from_tmsi */ |
| 267 | if (mi_len == TMSI_LEN && mi[0] == (0xf0 | GSM_MI_TYPE_TMSI)) { |
| 268 | memcpy(&tmsi, &mi[1], 4); |
| 269 | tmsi = ntohl(tmsi); |
| 270 | return snprintf(string, str_len, "%u", tmsi); |
Harald Welte | fc977a8 | 2008-12-27 10:19:37 +0000 | [diff] [blame] | 271 | } |
| 272 | break; |
| 273 | case GSM_MI_TYPE_IMSI: |
| 274 | case GSM_MI_TYPE_IMEI: |
| 275 | case GSM_MI_TYPE_IMEISV: |
Harald Welte | db253af | 2008-12-30 17:56:55 +0000 | [diff] [blame] | 276 | *str_cur++ = bcd2char(mi[0] >> 4); |
| 277 | |
| 278 | for (i = 1; i < mi_len; i++) { |
Harald Welte | fc977a8 | 2008-12-27 10:19:37 +0000 | [diff] [blame] | 279 | if (str_cur + 2 >= string + str_len) |
| 280 | return str_cur - string; |
| 281 | *str_cur++ = bcd2char(mi[i] & 0xf); |
Harald Welte | db253af | 2008-12-30 17:56:55 +0000 | [diff] [blame] | 282 | /* skip last nibble in last input byte when GSM_EVEN */ |
| 283 | if( (i != mi_len-1) || (mi[0] & GSM_MI_ODD)) |
| 284 | *str_cur++ = bcd2char(mi[i] >> 4); |
Harald Welte | fc977a8 | 2008-12-27 10:19:37 +0000 | [diff] [blame] | 285 | } |
| 286 | break; |
| 287 | default: |
| 288 | break; |
| 289 | } |
Harald Welte | fc977a8 | 2008-12-27 10:19:37 +0000 | [diff] [blame] | 290 | *str_cur++ = '\0'; |
Harald Welte | db253af | 2008-12-30 17:56:55 +0000 | [diff] [blame] | 291 | |
Harald Welte | fc977a8 | 2008-12-27 10:19:37 +0000 | [diff] [blame] | 292 | return str_cur - string; |
| 293 | } |
| 294 | |
Harald Welte | bf5e8df | 2009-02-03 12:59:45 +0000 | [diff] [blame] | 295 | /* Transmit Chapter 9.2.10 Identity Request */ |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 296 | static int mm_tx_identity_req(struct gsm_lchan *lchan, u_int8_t id_type) |
| 297 | { |
| 298 | struct msgb *msg = gsm48_msgb_alloc(); |
| 299 | struct gsm48_hdr *gh; |
Harald Welte | fc977a8 | 2008-12-27 10:19:37 +0000 | [diff] [blame] | 300 | |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 301 | msg->lchan = lchan; |
| 302 | |
| 303 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 1); |
| 304 | gh->proto_discr = GSM48_PDISC_MM; |
| 305 | gh->msg_type = GSM48_MT_MM_ID_REQ; |
| 306 | gh->data[0] = id_type; |
| 307 | |
Harald Welte | 65e74cc | 2008-12-29 01:55:35 +0000 | [diff] [blame] | 308 | return gsm48_sendmsg(msg); |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | #define MI_SIZE 32 |
| 312 | |
Harald Welte | bf5e8df | 2009-02-03 12:59:45 +0000 | [diff] [blame] | 313 | /* Parse Chapter 9.2.11 Identity Response */ |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 314 | static int mm_rx_id_resp(struct msgb *msg) |
| 315 | { |
| 316 | struct gsm48_hdr *gh = msgb_l3(msg); |
Harald Welte | 75a983f | 2008-12-27 21:34:06 +0000 | [diff] [blame] | 317 | struct gsm_lchan *lchan = msg->lchan; |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 318 | u_int8_t mi_type = gh->data[1] & GSM_MI_TYPE_MASK; |
| 319 | char mi_string[MI_SIZE]; |
Harald Welte | 75a983f | 2008-12-27 21:34:06 +0000 | [diff] [blame] | 320 | u_int32_t tmsi; |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 321 | |
| 322 | 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] | 323 | DEBUGP(DMM, "IDENTITY RESPONSE: mi_type=0x%02x MI(%s)\n", |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 324 | mi_type, mi_string); |
| 325 | |
Holger Freyther | c6ea9db | 2008-12-30 19:18:21 +0000 | [diff] [blame] | 326 | /* |
| 327 | * Rogue messages could trick us but so is life |
| 328 | */ |
| 329 | put_lchan(lchan); |
| 330 | |
Harald Welte | 75a983f | 2008-12-27 21:34:06 +0000 | [diff] [blame] | 331 | switch (mi_type) { |
| 332 | case GSM_MI_TYPE_IMSI: |
| 333 | if (!lchan->subscr) |
| 334 | lchan->subscr = db_create_subscriber(mi_string); |
Holger Freyther | 73487a2 | 2008-12-31 18:53:57 +0000 | [diff] [blame] | 335 | if (lchan->loc_operation) |
| 336 | lchan->loc_operation->waiting_for_imsi = 0; |
Harald Welte | 75a983f | 2008-12-27 21:34:06 +0000 | [diff] [blame] | 337 | break; |
| 338 | case GSM_MI_TYPE_IMEI: |
Harald Welte | 255539c | 2008-12-28 02:26:27 +0000 | [diff] [blame] | 339 | case GSM_MI_TYPE_IMEISV: |
Harald Welte | 75a983f | 2008-12-27 21:34:06 +0000 | [diff] [blame] | 340 | /* update subscribe <-> IMEI mapping */ |
| 341 | if (lchan->subscr) |
| 342 | db_subscriber_assoc_imei(lchan->subscr, mi_string); |
Holger Freyther | 73487a2 | 2008-12-31 18:53:57 +0000 | [diff] [blame] | 343 | if (lchan->loc_operation) |
| 344 | lchan->loc_operation->waiting_for_imei = 0; |
Harald Welte | 75a983f | 2008-12-27 21:34:06 +0000 | [diff] [blame] | 345 | break; |
| 346 | } |
Holger Freyther | 73487a2 | 2008-12-31 18:53:57 +0000 | [diff] [blame] | 347 | |
| 348 | /* Check if we can let the mobile station enter */ |
| 349 | if (authorize_subscriber(lchan->loc_operation, lchan->subscr)) { |
| 350 | db_subscriber_alloc_tmsi(lchan->subscr); |
| 351 | tmsi = strtoul(lchan->subscr->tmsi, NULL, 10); |
| 352 | release_loc_updating_req(lchan); |
| 353 | return gsm0408_loc_upd_acc(msg->lchan, tmsi); |
| 354 | } |
| 355 | |
Harald Welte | 75a983f | 2008-12-27 21:34:06 +0000 | [diff] [blame] | 356 | return 0; |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 357 | } |
| 358 | |
Harald Welte | 255539c | 2008-12-28 02:26:27 +0000 | [diff] [blame] | 359 | |
| 360 | static void loc_upd_rej_cb(void *data) |
| 361 | { |
| 362 | struct gsm_lchan *lchan = data; |
| 363 | |
Holger Freyther | 73487a2 | 2008-12-31 18:53:57 +0000 | [diff] [blame] | 364 | release_loc_updating_req(lchan); |
Holger Freyther | e97f7fb | 2008-12-31 18:52:11 +0000 | [diff] [blame] | 365 | gsm0408_loc_upd_rej(lchan, reject_cause); |
Holger Freyther | 67b4b9a | 2009-01-01 03:46:11 +0000 | [diff] [blame] | 366 | lchan_auto_release(lchan); |
Harald Welte | 255539c | 2008-12-28 02:26:27 +0000 | [diff] [blame] | 367 | } |
| 368 | |
Holger Freyther | b7193e4 | 2008-12-29 17:44:08 +0000 | [diff] [blame] | 369 | static void schedule_reject(struct gsm_lchan *lchan) |
| 370 | { |
Holger Freyther | 73487a2 | 2008-12-31 18:53:57 +0000 | [diff] [blame] | 371 | lchan->loc_operation->updating_timer.cb = loc_upd_rej_cb; |
| 372 | lchan->loc_operation->updating_timer.data = lchan; |
| 373 | schedule_timer(&lchan->loc_operation->updating_timer, 5, 0); |
Holger Freyther | b7193e4 | 2008-12-29 17:44:08 +0000 | [diff] [blame] | 374 | } |
| 375 | |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 376 | #define MI_SIZE 32 |
Harald Welte | bf5e8df | 2009-02-03 12:59:45 +0000 | [diff] [blame] | 377 | /* Chapter 9.2.15: Receive Location Updating Request */ |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 378 | static int mm_rx_loc_upd_req(struct msgb *msg) |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 379 | { |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 380 | struct gsm48_hdr *gh = msgb_l3(msg); |
Harald Welte | 702d870 | 2008-12-26 20:25:35 +0000 | [diff] [blame] | 381 | struct gsm_bts *bts = msg->trx->bts; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 382 | struct gsm48_loc_upd_req *lu; |
| 383 | struct gsm_subscriber *subscr; |
Harald Welte | 255539c | 2008-12-28 02:26:27 +0000 | [diff] [blame] | 384 | struct gsm_lchan *lchan = msg->lchan; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 385 | u_int8_t mi_type; |
Harald Welte | 75a983f | 2008-12-27 21:34:06 +0000 | [diff] [blame] | 386 | u_int32_t tmsi; |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 387 | char mi_string[MI_SIZE]; |
| 388 | int rc; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 389 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 390 | lu = (struct gsm48_loc_upd_req *) gh->data; |
| 391 | |
| 392 | mi_type = lu->mi[0] & GSM_MI_TYPE_MASK; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 393 | |
Harald Welte | fc977a8 | 2008-12-27 10:19:37 +0000 | [diff] [blame] | 394 | mi_to_string(mi_string, sizeof(mi_string), lu->mi, lu->mi_len); |
| 395 | |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 396 | DEBUGP(DMM, "LUPDREQ: mi_type=0x%02x MI(%s)\n", mi_type, mi_string); |
Holger Freyther | 73487a2 | 2008-12-31 18:53:57 +0000 | [diff] [blame] | 397 | |
| 398 | allocate_loc_updating_req(lchan); |
| 399 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 400 | switch (mi_type) { |
| 401 | case GSM_MI_TYPE_IMSI: |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 402 | /* we always want the IMEI, too */ |
Holger Freyther | c6ea9db | 2008-12-30 19:18:21 +0000 | [diff] [blame] | 403 | use_lchan(lchan); |
Harald Welte | 255539c | 2008-12-28 02:26:27 +0000 | [diff] [blame] | 404 | rc = mm_tx_identity_req(lchan, GSM_MI_TYPE_IMEISV); |
Holger Freyther | 73487a2 | 2008-12-31 18:53:57 +0000 | [diff] [blame] | 405 | lchan->loc_operation->waiting_for_imei = 1; |
Holger Freyther | c6ea9db | 2008-12-30 19:18:21 +0000 | [diff] [blame] | 406 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 407 | /* look up subscriber based on IMSI */ |
Harald Welte | 75a983f | 2008-12-27 21:34:06 +0000 | [diff] [blame] | 408 | subscr = db_create_subscriber(mi_string); |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 409 | break; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 410 | case GSM_MI_TYPE_TMSI: |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 411 | /* we always want the IMEI, too */ |
Holger Freyther | c6ea9db | 2008-12-30 19:18:21 +0000 | [diff] [blame] | 412 | use_lchan(lchan); |
Harald Welte | 255539c | 2008-12-28 02:26:27 +0000 | [diff] [blame] | 413 | rc = mm_tx_identity_req(lchan, GSM_MI_TYPE_IMEISV); |
Holger Freyther | 73487a2 | 2008-12-31 18:53:57 +0000 | [diff] [blame] | 414 | lchan->loc_operation->waiting_for_imei = 1; |
Holger Freyther | c6ea9db | 2008-12-30 19:18:21 +0000 | [diff] [blame] | 415 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 416 | /* look up the subscriber based on TMSI, request IMSI if it fails */ |
Harald Welte | ba4cf16 | 2009-01-10 01:49:35 +0000 | [diff] [blame] | 417 | subscr = subscr_get_by_tmsi(mi_string); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 418 | if (!subscr) { |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 419 | /* send IDENTITY REQUEST message to get IMSI */ |
Holger Freyther | c6ea9db | 2008-12-30 19:18:21 +0000 | [diff] [blame] | 420 | use_lchan(lchan); |
Harald Welte | 255539c | 2008-12-28 02:26:27 +0000 | [diff] [blame] | 421 | rc = mm_tx_identity_req(lchan, GSM_MI_TYPE_IMSI); |
Holger Freyther | 73487a2 | 2008-12-31 18:53:57 +0000 | [diff] [blame] | 422 | lchan->loc_operation->waiting_for_imsi = 1; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 423 | } |
| 424 | break; |
| 425 | case GSM_MI_TYPE_IMEI: |
| 426 | case GSM_MI_TYPE_IMEISV: |
| 427 | /* no sim card... FIXME: what to do ? */ |
| 428 | fprintf(stderr, "Unimplemented mobile identity type\n"); |
| 429 | break; |
| 430 | default: |
| 431 | fprintf(stderr, "Unknown mobile identity type\n"); |
| 432 | break; |
| 433 | } |
| 434 | |
Harald Welte | 255539c | 2008-12-28 02:26:27 +0000 | [diff] [blame] | 435 | lchan->subscr = subscr; |
| 436 | |
Holger Freyther | 73487a2 | 2008-12-31 18:53:57 +0000 | [diff] [blame] | 437 | /* |
| 438 | * Schedule the reject timer and check if we can let the |
| 439 | * subscriber into our network immediately or if we need to wait |
| 440 | * for identity responses. |
| 441 | */ |
| 442 | schedule_reject(lchan); |
| 443 | if (!authorize_subscriber(lchan->loc_operation, subscr)) |
Harald Welte | e872cb1 | 2009-01-01 00:33:37 +0000 | [diff] [blame] | 444 | return 0; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 445 | |
Harald Welte | 75a983f | 2008-12-27 21:34:06 +0000 | [diff] [blame] | 446 | db_subscriber_alloc_tmsi(subscr); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 447 | subscr_update(subscr, bts); |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 448 | |
Harald Welte | 255539c | 2008-12-28 02:26:27 +0000 | [diff] [blame] | 449 | tmsi = strtoul(subscr->tmsi, NULL, 10); |
| 450 | |
Holger Freyther | 73487a2 | 2008-12-31 18:53:57 +0000 | [diff] [blame] | 451 | release_loc_updating_req(lchan); |
Harald Welte | 255539c | 2008-12-28 02:26:27 +0000 | [diff] [blame] | 452 | return gsm0408_loc_upd_acc(lchan, tmsi); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 453 | } |
| 454 | |
Harald Welte | db253af | 2008-12-30 17:56:55 +0000 | [diff] [blame] | 455 | /* Section 9.2.15a */ |
| 456 | int gsm48_tx_mm_info(struct gsm_lchan *lchan) |
| 457 | { |
| 458 | struct msgb *msg = gsm48_msgb_alloc(); |
| 459 | struct gsm48_hdr *gh; |
| 460 | struct gsm_network *net = lchan->ts->trx->bts->network; |
Harald Welte | db253af | 2008-12-30 17:56:55 +0000 | [diff] [blame] | 461 | u_int8_t *ptr8; |
| 462 | u_int16_t *ptr16; |
| 463 | int name_len; |
Harald Welte | db253af | 2008-12-30 17:56:55 +0000 | [diff] [blame] | 464 | int i; |
| 465 | |
| 466 | msg->lchan = lchan; |
| 467 | |
| 468 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 469 | gh->proto_discr = GSM48_PDISC_MM; |
| 470 | gh->msg_type = GSM48_MT_MM_INFO; |
| 471 | |
| 472 | if (net->name_long) { |
| 473 | name_len = strlen(net->name_long); |
| 474 | /* 10.5.3.5a */ |
| 475 | ptr8 = msgb_put(msg, 3); |
| 476 | ptr8[0] = GSM48_IE_NAME_LONG; |
| 477 | ptr8[1] = name_len*2 +1; |
| 478 | ptr8[2] = 0x90; /* UCS2, no spare bits, no CI */ |
| 479 | |
| 480 | ptr16 = (u_int16_t *) msgb_put(msg, name_len*2); |
| 481 | for (i = 0; i < name_len; i++) |
Harald Welte | 179f064 | 2008-12-31 23:59:18 +0000 | [diff] [blame] | 482 | ptr16[i] = htons(net->name_long[i]); |
Harald Welte | db253af | 2008-12-30 17:56:55 +0000 | [diff] [blame] | 483 | |
| 484 | /* FIXME: Use Cell Broadcast, not UCS-2, since |
| 485 | * UCS-2 is only supported by later revisions of the spec */ |
| 486 | } |
| 487 | |
| 488 | if (net->name_short) { |
| 489 | name_len = strlen(net->name_short); |
| 490 | /* 10.5.3.5a */ |
| 491 | ptr8 = (u_int8_t *) msgb_put(msg, 3); |
| 492 | ptr8[0] = GSM48_IE_NAME_LONG; |
| 493 | ptr8[1] = name_len*2 + 1; |
| 494 | ptr8[2] = 0x90; /* UCS2, no spare bits, no CI */ |
| 495 | |
Harald Welte | e872cb1 | 2009-01-01 00:33:37 +0000 | [diff] [blame] | 496 | ptr16 = (u_int16_t *) msgb_put(msg, name_len*2); |
Harald Welte | db253af | 2008-12-30 17:56:55 +0000 | [diff] [blame] | 497 | for (i = 0; i < name_len; i++) |
Harald Welte | 179f064 | 2008-12-31 23:59:18 +0000 | [diff] [blame] | 498 | ptr16[i] = htons(net->name_short[i]); |
Harald Welte | db253af | 2008-12-30 17:56:55 +0000 | [diff] [blame] | 499 | } |
| 500 | |
| 501 | #if 0 |
Holger Freyther | ca362a6 | 2009-01-04 21:05:01 +0000 | [diff] [blame] | 502 | /* move back to the top */ |
| 503 | time_t cur_t; |
| 504 | struct tm* cur_time; |
| 505 | int tz15min; |
Harald Welte | db253af | 2008-12-30 17:56:55 +0000 | [diff] [blame] | 506 | /* Section 10.5.3.9 */ |
| 507 | cur_t = time(NULL); |
| 508 | cur_time = gmtime(cur_t); |
| 509 | ptr8 = msgb_put(msg, 8); |
| 510 | ptr8[0] = GSM48_IE_NET_TIME_TZ; |
| 511 | ptr8[1] = to_bcd8(cur_time->tm_year % 100); |
| 512 | ptr8[2] = to_bcd8(cur_time->tm_mon); |
| 513 | ptr8[3] = to_bcd8(cur_time->tm_mday); |
| 514 | ptr8[4] = to_bcd8(cur_time->tm_hour); |
| 515 | ptr8[5] = to_bcd8(cur_time->tm_min); |
| 516 | ptr8[6] = to_bcd8(cur_time->tm_sec); |
| 517 | /* 02.42: coded as BCD encoded signed value in units of 15 minutes */ |
| 518 | tz15min = (cur_time->tm_gmtoff)/(60*15); |
| 519 | ptr8[6] = to_bcd8(tz15min); |
| 520 | if (tz15min < 0) |
| 521 | ptr8[6] |= 0x80; |
| 522 | #endif |
| 523 | |
| 524 | return gsm48_sendmsg(msg); |
| 525 | } |
| 526 | |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 527 | static int gsm48_tx_mm_serv_ack(struct gsm_lchan *lchan) |
| 528 | { |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 529 | DEBUGP(DMM, "-> CM SERVICE ACK\n"); |
Harald Welte | 65e74cc | 2008-12-29 01:55:35 +0000 | [diff] [blame] | 530 | 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] | 531 | } |
Harald Welte | ba4cf16 | 2009-01-10 01:49:35 +0000 | [diff] [blame] | 532 | |
| 533 | /* 9.2.6 CM service reject */ |
| 534 | static int gsm48_tx_mm_serv_rej(struct gsm_lchan *lchan, |
| 535 | enum gsm48_reject_value value) |
| 536 | { |
| 537 | struct msgb *msg = gsm48_msgb_alloc(); |
| 538 | struct gsm48_hdr *gh; |
| 539 | |
| 540 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 1); |
| 541 | |
| 542 | msg->lchan = lchan; |
| 543 | use_lchan(lchan); |
| 544 | |
| 545 | gh->proto_discr = GSM48_PDISC_MM; |
| 546 | gh->msg_type = GSM48_MT_MM_CM_SERV_REJ; |
| 547 | gh->data[0] = value; |
| 548 | DEBUGP(DMM, "-> CM SERVICE Reject cause: %d\n", value); |
| 549 | |
| 550 | return gsm48_sendmsg(msg); |
| 551 | } |
| 552 | |
Harald Welte | 4ed0e92 | 2009-01-10 03:17:30 +0000 | [diff] [blame] | 553 | |
| 554 | /* |
| 555 | * Handle CM Service Requests |
| 556 | * a) Verify that the packet is long enough to contain the information |
| 557 | * we require otherwsie reject with INCORRECT_MESSAGE |
| 558 | * b) Try to parse the TMSI. If we do not have one reject |
| 559 | * c) Check that we know the subscriber with the TMSI otherwise reject |
| 560 | * with a HLR cause |
| 561 | * d) Set the subscriber on the gsm_lchan and accept |
| 562 | */ |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 563 | static int gsm48_rx_mm_serv_req(struct msgb *msg) |
| 564 | { |
Harald Welte | ba4cf16 | 2009-01-10 01:49:35 +0000 | [diff] [blame] | 565 | u_int8_t mi_type; |
Harald Welte | 4ed0e92 | 2009-01-10 03:17:30 +0000 | [diff] [blame] | 566 | char mi_string[MI_SIZE]; |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 567 | |
Harald Welte | ba4cf16 | 2009-01-10 01:49:35 +0000 | [diff] [blame] | 568 | struct gsm_subscriber *subscr; |
| 569 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 570 | struct gsm48_service_request *req = |
| 571 | (struct gsm48_service_request *)gh->data; |
| 572 | |
| 573 | if (msg->data_len < sizeof(struct gsm48_service_request*)) { |
| 574 | DEBUGP(DMM, "<- CM SERVICE REQUEST wrong sized message\n"); |
| 575 | return gsm48_tx_mm_serv_rej(msg->lchan, |
| 576 | GSM48_REJECT_INCORRECT_MESSAGE); |
| 577 | } |
| 578 | |
| 579 | if (msg->data_len < req->mi_len + 6) { |
| 580 | DEBUGP(DMM, "<- CM SERVICE REQUEST MI does not fit in package\n"); |
| 581 | return gsm48_tx_mm_serv_rej(msg->lchan, |
| 582 | GSM48_REJECT_INCORRECT_MESSAGE); |
| 583 | } |
| 584 | |
| 585 | mi_type = req->mi[0] & GSM_MI_TYPE_MASK; |
| 586 | if (mi_type != GSM_MI_TYPE_TMSI) { |
| 587 | DEBUGP(DMM, "<- CM SERVICE REQUEST mi type is not TMSI: %d\n", mi_type); |
| 588 | return gsm48_tx_mm_serv_rej(msg->lchan, |
| 589 | GSM48_REJECT_INCORRECT_MESSAGE); |
| 590 | } |
| 591 | |
Harald Welte | 4ed0e92 | 2009-01-10 03:17:30 +0000 | [diff] [blame] | 592 | mi_to_string(mi_string, sizeof(mi_string), req->mi, req->mi_len); |
| 593 | subscr = subscr_get_by_tmsi(mi_string); |
| 594 | DEBUGP(DMM, "<- CM SERVICE REQUEST serv_type=0x%02x mi_type=0x%02x M(%s)\n", |
| 595 | req->cm_service_type, mi_type, mi_string); |
Harald Welte | bcae43f | 2008-12-27 21:45:37 +0000 | [diff] [blame] | 596 | |
Harald Welte | 4ed0e92 | 2009-01-10 03:17:30 +0000 | [diff] [blame] | 597 | if (!subscr) |
| 598 | return gsm48_tx_mm_serv_rej(msg->lchan, |
| 599 | GSM48_REJECT_IMSI_UNKNOWN_IN_HLR); |
| 600 | |
| 601 | if (!msg->lchan->subscr) |
| 602 | msg->lchan->subscr = subscr; |
Harald Welte | 9bb7c70 | 2009-01-10 03:21:41 +0000 | [diff] [blame] | 603 | else if (msg->lchan->subscr != subscr) { |
| 604 | DEBUGP(DMM, "<- CM Channel already owned by someone else?\n"); |
| 605 | subscr_put(subscr); |
| 606 | } |
| 607 | |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 608 | return gsm48_tx_mm_serv_ack(msg->lchan); |
| 609 | } |
| 610 | |
Harald Welte | bf5e8df | 2009-02-03 12:59:45 +0000 | [diff] [blame] | 611 | /* Receive a GSM 04.08 Mobility Management (MM) message */ |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 612 | static int gsm0408_rcv_mm(struct msgb *msg) |
| 613 | { |
| 614 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 615 | int rc; |
| 616 | |
| 617 | switch (gh->msg_type & 0xbf) { |
| 618 | case GSM48_MT_MM_LOC_UPD_REQUEST: |
Holger Freyther | 429e776 | 2008-12-30 13:28:30 +0000 | [diff] [blame] | 619 | DEBUGP(DMM, "LOCATION UPDATING REQUEST\n"); |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 620 | rc = mm_rx_loc_upd_req(msg); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 621 | break; |
| 622 | case GSM48_MT_MM_ID_RESP: |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 623 | rc = mm_rx_id_resp(msg); |
| 624 | break; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 625 | case GSM48_MT_MM_CM_SERV_REQ: |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 626 | rc = gsm48_rx_mm_serv_req(msg); |
| 627 | break; |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 628 | case GSM48_MT_MM_STATUS: |
| 629 | DEBUGP(DMM, "MM STATUS: FIXME parse error cond.\n"); |
| 630 | break; |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 631 | case GSM48_MT_MM_TMSI_REALL_COMPL: |
Harald Welte | 69b2af2 | 2009-01-06 19:47:00 +0000 | [diff] [blame] | 632 | DEBUGP(DMM, "TMSI Reallocation Completed. Subscriber: %s\n", |
| 633 | msg->lchan->subscr ? |
| 634 | msg->lchan->subscr->imsi : |
| 635 | "unknown subscriber"); |
| 636 | break; |
| 637 | case GSM48_MT_MM_CM_REEST_REQ: |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 638 | case GSM48_MT_MM_AUTH_RESP: |
| 639 | case GSM48_MT_MM_IMSI_DETACH_IND: |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 640 | fprintf(stderr, "Unimplemented GSM 04.08 MM msg type 0x%02x\n", |
| 641 | gh->msg_type); |
| 642 | break; |
| 643 | default: |
| 644 | fprintf(stderr, "Unknown GSM 04.08 MM msg type 0x%02x\n", |
| 645 | gh->msg_type); |
| 646 | break; |
| 647 | } |
| 648 | |
| 649 | return rc; |
| 650 | } |
Harald Welte | bf5e8df | 2009-02-03 12:59:45 +0000 | [diff] [blame] | 651 | |
Harald Welte | 2d35ae6 | 2009-02-06 12:02:13 +0000 | [diff] [blame] | 652 | /* Receive a PAGING RESPONSE message from the MS */ |
| 653 | static int gsm48_rr_rx_pag_resp(struct msgb *msg) |
| 654 | { |
| 655 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 656 | struct gsm48_paging_response *pr = |
| 657 | (struct gsm48_paging_response *) gh->data; |
| 658 | u_int8_t mi_type = pr->mi[0] & GSM_MI_TYPE_MASK; |
| 659 | char mi_string[MI_SIZE]; |
| 660 | struct gsm_subscriber *subscr; |
| 661 | int rc = 0; |
| 662 | |
| 663 | mi_to_string(mi_string, sizeof(mi_string), &pr->mi[0], pr->mi_len); |
| 664 | DEBUGP(DRR, "PAGING RESPONSE: mi_type=0x%02x MI(%s)\n", |
| 665 | mi_type, mi_string); |
| 666 | subscr = subscr_get_by_tmsi(mi_string); |
| 667 | |
| 668 | if (!subscr) { |
| 669 | DEBUGP(DRR, "<- Can't find any subscriber for this ID\n"); |
| 670 | /* FIXME: close channel? */ |
| 671 | return -EINVAL; |
| 672 | } |
| 673 | DEBUGP(DRR, "<- Channel was requested by %s\n", |
| 674 | subscr->name ? subscr->name : subscr->imsi); |
| 675 | |
| 676 | if (!msg->lchan->subscr) |
| 677 | msg->lchan->subscr = subscr; |
| 678 | else if (msg->lchan->subscr != subscr) { |
| 679 | DEBUGP(DRR, "<- Channel already owned by someone else?\n"); |
| 680 | subscr_put(subscr); |
| 681 | } |
| 682 | |
| 683 | return rc; |
| 684 | } |
| 685 | |
Harald Welte | bf5e8df | 2009-02-03 12:59:45 +0000 | [diff] [blame] | 686 | /* Receive a GSM 04.08 Radio Resource (RR) message */ |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 687 | static int gsm0408_rcv_rr(struct msgb *msg) |
| 688 | { |
| 689 | struct gsm48_hdr *gh = msgb_l3(msg); |
Harald Welte | 2d35ae6 | 2009-02-06 12:02:13 +0000 | [diff] [blame] | 690 | int rc = 0; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 691 | |
| 692 | switch (gh->msg_type) { |
| 693 | case GSM48_MT_RR_CLSM_CHG: |
| 694 | DEBUGP(DRR, "CLASSMARK CHANGE\n"); |
| 695 | /* FIXME: what to do ?!? */ |
| 696 | break; |
Harald Welte | fc977a8 | 2008-12-27 10:19:37 +0000 | [diff] [blame] | 697 | case GSM48_MT_RR_GPRS_SUSP_REQ: |
| 698 | DEBUGP(DRR, "GRPS SUSPEND REQUEST\n"); |
| 699 | break; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 700 | case GSM48_MT_RR_PAG_RESP: |
Harald Welte | 2d35ae6 | 2009-02-06 12:02:13 +0000 | [diff] [blame] | 701 | rc = gsm48_rr_rx_pag_resp(msg); |
| 702 | break; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 703 | default: |
Harald Welte | 2d35ae6 | 2009-02-06 12:02:13 +0000 | [diff] [blame] | 704 | fprintf(stderr, "Unimplemented GSM 04.08 RR msg type 0x%02x\n", |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 705 | gh->msg_type); |
| 706 | break; |
| 707 | } |
| 708 | |
Harald Welte | 2d35ae6 | 2009-02-06 12:02:13 +0000 | [diff] [blame] | 709 | return rc; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 710 | } |
| 711 | |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 712 | /* Call Control */ |
| 713 | |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 714 | static int gsm48_cc_tx_status(struct gsm_lchan *lchan) |
| 715 | { |
| 716 | struct msgb *msg = gsm48_msgb_alloc(); |
| 717 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 718 | u_int8_t *cause, *call_state; |
| 719 | |
Harald Welte | 65e74cc | 2008-12-29 01:55:35 +0000 | [diff] [blame] | 720 | gh->proto_discr = GSM48_PDISC_CC; |
| 721 | |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 722 | msg->lchan = lchan; |
| 723 | |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 724 | gh->msg_type = GSM48_MT_CC_STATUS; |
| 725 | |
| 726 | cause = msgb_put(msg, 3); |
| 727 | cause[0] = 2; |
| 728 | cause[1] = GSM48_CAUSE_CS_GSM | GSM48_CAUSE_LOC_USER; |
| 729 | cause[2] = 0x80 | 30; /* response to status inquiry */ |
| 730 | |
| 731 | call_state = msgb_put(msg, 1); |
| 732 | call_state[0] = 0xc0 | 0x00; |
| 733 | |
Harald Welte | 65e74cc | 2008-12-29 01:55:35 +0000 | [diff] [blame] | 734 | return gsm48_sendmsg(msg); |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 735 | } |
| 736 | |
Harald Welte | 6f4b753 | 2008-12-29 00:39:37 +0000 | [diff] [blame] | 737 | static int gsm48_tx_simple(struct gsm_lchan *lchan, |
| 738 | u_int8_t pdisc, u_int8_t msg_type) |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 739 | { |
| 740 | struct msgb *msg = gsm48_msgb_alloc(); |
| 741 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 742 | |
| 743 | msg->lchan = lchan; |
| 744 | |
Harald Welte | 6f4b753 | 2008-12-29 00:39:37 +0000 | [diff] [blame] | 745 | gh->proto_discr = pdisc; |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 746 | gh->msg_type = msg_type; |
| 747 | |
Harald Welte | 65e74cc | 2008-12-29 01:55:35 +0000 | [diff] [blame] | 748 | return gsm48_sendmsg(msg); |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 749 | } |
| 750 | |
| 751 | static int gsm48_cc_rx_status_enq(struct msgb *msg) |
| 752 | { |
| 753 | return gsm48_cc_tx_status(msg->lchan); |
| 754 | } |
| 755 | |
Holger Freyther | ca362a6 | 2009-01-04 21:05:01 +0000 | [diff] [blame] | 756 | #if 0 |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 757 | static int gsm48_cc_rx_setup(struct msgb *msg) |
| 758 | { |
Harald Welte | 6f4b753 | 2008-12-29 00:39:37 +0000 | [diff] [blame] | 759 | return gsm48_tx_simple(msg->lchan, GSM48_PDISC_CC, |
| 760 | GSM48_MT_CC_CALL_CONF); |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 761 | } |
Holger Freyther | ca362a6 | 2009-01-04 21:05:01 +0000 | [diff] [blame] | 762 | #endif |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 763 | |
Harald Welte | 65e74cc | 2008-12-29 01:55:35 +0000 | [diff] [blame] | 764 | int gsm48_cc_tx_setup(struct gsm_lchan *lchan) |
| 765 | { |
| 766 | struct msgb *msg = gsm48_msgb_alloc(); |
| 767 | struct gsm48_hdr *gh; |
| 768 | struct gsm_call *call = &lchan->call; |
| 769 | |
| 770 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 8); |
| 771 | |
| 772 | call->type = GSM_CT_MT; |
| 773 | msg->lchan = lchan; |
Harald Welte | 498b0bb | 2009-01-09 21:27:43 +0000 | [diff] [blame] | 774 | use_lchan(lchan); |
Harald Welte | 65e74cc | 2008-12-29 01:55:35 +0000 | [diff] [blame] | 775 | |
| 776 | gh->proto_discr = GSM48_PDISC_CC; |
| 777 | gh->msg_type = GSM48_MT_CC_SETUP; |
| 778 | gh->data[0] = 0x34; |
| 779 | gh->data[1] = 0x00; |
| 780 | gh->data[2] = 0x5c; |
| 781 | gh->data[3] = 0x04; |
| 782 | gh->data[4] = 0xb9; |
| 783 | gh->data[5] = 0x83; |
| 784 | gh->data[6] = 0x32; |
| 785 | gh->data[7] = 0x24; |
| 786 | |
| 787 | DEBUGP(DCC, "Sending SETUP\n"); |
| 788 | |
| 789 | return gsm48_sendmsg(msg); |
| 790 | } |
| 791 | |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 792 | static int gsm0408_rcv_cc(struct msgb *msg) |
| 793 | { |
| 794 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 795 | u_int8_t msg_type = gh->msg_type & 0xbf; |
| 796 | struct gsm_call *call = &msg->lchan->call; |
| 797 | int rc = 0; |
| 798 | |
| 799 | switch (msg_type) { |
| 800 | case GSM48_MT_CC_CALL_CONF: |
| 801 | /* Response to SETUP */ |
| 802 | DEBUGP(DCC, "CALL CONFIRM\n"); |
| 803 | break; |
| 804 | case GSM48_MT_CC_RELEASE_COMPL: |
| 805 | /* Answer from MS to RELEASE */ |
| 806 | DEBUGP(DCC, "RELEASE COMPLETE (state->NULL)\n"); |
| 807 | call->state = GSM_CSTATE_NULL; |
| 808 | break; |
| 809 | case GSM48_MT_CC_ALERTING: |
| 810 | DEBUGP(DCC, "ALERTING\n"); |
| 811 | break; |
| 812 | case GSM48_MT_CC_CONNECT: |
| 813 | DEBUGP(DCC, "CONNECT\n"); |
| 814 | /* MT: need to respond with CONNECT_ACK */ |
Harald Welte | 6f4b753 | 2008-12-29 00:39:37 +0000 | [diff] [blame] | 815 | rc = gsm48_tx_simple(msg->lchan, GSM48_PDISC_CC, |
| 816 | GSM48_MT_CC_CONNECT_ACK); |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 817 | break; |
| 818 | case GSM48_MT_CC_CONNECT_ACK: |
| 819 | /* MO: Answer to CONNECT */ |
| 820 | call->state = GSM_CSTATE_ACTIVE; |
| 821 | DEBUGP(DCC, "CONNECT_ACK (state->ACTIVE)\n"); |
| 822 | break; |
| 823 | case GSM48_MT_CC_RELEASE: |
| 824 | DEBUGP(DCC, "RELEASE\n"); |
| 825 | /* need to respond with RELEASE_COMPLETE */ |
| 826 | break; |
| 827 | case GSM48_MT_CC_STATUS_ENQ: |
| 828 | rc = gsm48_cc_rx_status_enq(msg); |
| 829 | break; |
| 830 | case GSM48_MT_CC_DISCONNECT: |
| 831 | /* Section 5.4.3.2 */ |
| 832 | DEBUGP(DCC, "DISCONNECT (state->RELEASE_REQ)\n"); |
| 833 | call->state = GSM_CSTATE_RELEASE_REQ; |
Harald Welte | 498b0bb | 2009-01-09 21:27:43 +0000 | [diff] [blame] | 834 | if (call->state != GSM_CSTATE_NULL) |
| 835 | put_lchan(msg->lchan); |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 836 | /* FIXME: clear the network connection */ |
Harald Welte | 6f4b753 | 2008-12-29 00:39:37 +0000 | [diff] [blame] | 837 | rc = gsm48_tx_simple(msg->lchan, GSM48_PDISC_CC, |
| 838 | GSM48_MT_CC_RELEASE); |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 839 | break; |
| 840 | case GSM48_MT_CC_SETUP: |
Harald Welte | 498b0bb | 2009-01-09 21:27:43 +0000 | [diff] [blame] | 841 | if (call->state == GSM_CSTATE_NULL || call->state == GSM_CSTATE_RELEASE_REQ) |
| 842 | use_lchan(msg->lchan); |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 843 | call->type = GSM_CT_MO; |
| 844 | call->state = GSM_CSTATE_INITIATED; |
| 845 | call->transaction_id = gh->proto_discr & 0xf0; |
| 846 | DEBUGP(DCC, "SETUP(tid=0x%02x)\n", call->transaction_id); |
Harald Welte | 6f4b753 | 2008-12-29 00:39:37 +0000 | [diff] [blame] | 847 | rc = gsm48_tx_simple(msg->lchan, GSM48_PDISC_CC, |
| 848 | GSM48_MT_CC_CONNECT); |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 849 | /* FIXME: continue with CALL_PROCEEDING, ALERTING, CONNECT, RELEASE_COMPLETE */ |
| 850 | break; |
| 851 | case GSM48_MT_CC_EMERG_SETUP: |
| 852 | DEBUGP(DCC, "EMERGENCY SETUP\n"); |
| 853 | /* FIXME: continue with CALL_PROCEEDING, ALERTING, CONNECT, RELEASE_COMPLETE */ |
| 854 | break; |
| 855 | default: |
Harald Welte | 2d35ae6 | 2009-02-06 12:02:13 +0000 | [diff] [blame] | 856 | fprintf(stderr, "Unimplemented GSM 04.08 CC msg type 0x%02x\n", |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 857 | msg_type); |
| 858 | break; |
| 859 | } |
| 860 | |
| 861 | return rc; |
| 862 | } |
| 863 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 864 | /* here we pass in a msgb from the RSL->RLL. We expect the l3 pointer to be set */ |
| 865 | int gsm0408_rcvmsg(struct msgb *msg) |
| 866 | { |
| 867 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 868 | u_int8_t pdisc = gh->proto_discr & 0x0f; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 869 | int rc = 0; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 870 | |
| 871 | switch (pdisc) { |
| 872 | case GSM48_PDISC_CC: |
| 873 | rc = gsm0408_rcv_cc(msg); |
| 874 | break; |
| 875 | case GSM48_PDISC_MM: |
| 876 | rc = gsm0408_rcv_mm(msg); |
| 877 | break; |
| 878 | case GSM48_PDISC_RR: |
| 879 | rc = gsm0408_rcv_rr(msg); |
| 880 | break; |
Harald Welte | bcae43f | 2008-12-27 21:45:37 +0000 | [diff] [blame] | 881 | case GSM48_PDISC_SMS: |
Daniel Willmann | 8b3390e | 2008-12-28 00:31:09 +0000 | [diff] [blame] | 882 | rc = gsm0411_rcv_sms(msg); |
Harald Welte | bcae43f | 2008-12-27 21:45:37 +0000 | [diff] [blame] | 883 | break; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 884 | case GSM48_PDISC_MM_GPRS: |
Harald Welte | bcae43f | 2008-12-27 21:45:37 +0000 | [diff] [blame] | 885 | case GSM48_PDISC_SM_GPRS: |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 886 | fprintf(stderr, "Unimplemented GSM 04.08 discriminator 0x%02d\n", |
| 887 | pdisc); |
| 888 | break; |
| 889 | default: |
| 890 | fprintf(stderr, "Unknown GSM 04.08 discriminator 0x%02d\n", |
| 891 | pdisc); |
| 892 | break; |
| 893 | } |
| 894 | |
| 895 | return rc; |
| 896 | } |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 897 | |
| 898 | enum chreq_type { |
| 899 | CHREQ_T_EMERG_CALL, |
| 900 | CHREQ_T_CALL_REEST_TCH_F, |
| 901 | CHREQ_T_CALL_REEST_TCH_H, |
| 902 | CHREQ_T_CALL_REEST_TCH_H_DBL, |
| 903 | CHREQ_T_SDCCH, |
| 904 | CHREQ_T_TCH_F, |
| 905 | CHREQ_T_VOICE_CALL_TCH_H, |
| 906 | CHREQ_T_DATA_CALL_TCH_H, |
| 907 | CHREQ_T_LOCATION_UPD, |
| 908 | CHREQ_T_PAG_R_ANY, |
| 909 | CHREQ_T_PAG_R_TCH_F, |
| 910 | CHREQ_T_PAG_R_TCH_FH, |
| 911 | }; |
| 912 | |
| 913 | /* Section 9.1.8 / Table 9.9 */ |
| 914 | struct chreq { |
| 915 | u_int8_t val; |
| 916 | u_int8_t mask; |
| 917 | enum chreq_type type; |
| 918 | }; |
| 919 | |
| 920 | /* If SYSTEM INFORMATION TYPE 4 NECI bit == 1 */ |
| 921 | static const struct chreq chreq_type_neci1[] = { |
| 922 | { 0xa0, 0xe0, CHREQ_T_EMERG_CALL }, |
| 923 | { 0xc0, 0xe0, CHREQ_T_CALL_REEST_TCH_F }, |
| 924 | { 0x68, 0xfc, CHREQ_T_CALL_REEST_TCH_H }, |
| 925 | { 0x6c, 0xfc, CHREQ_T_CALL_REEST_TCH_H_DBL }, |
| 926 | { 0xe0, 0xe0, CHREQ_T_SDCCH }, |
| 927 | { 0x40, 0xf0, CHREQ_T_VOICE_CALL_TCH_H }, |
| 928 | { 0x50, 0xf0, CHREQ_T_DATA_CALL_TCH_H }, |
| 929 | { 0x00, 0xf0, CHREQ_T_LOCATION_UPD }, |
| 930 | { 0x10, 0xf0, CHREQ_T_SDCCH }, |
| 931 | { 0x80, 0xe0, CHREQ_T_PAG_R_ANY }, |
| 932 | { 0x20, 0xf0, CHREQ_T_PAG_R_TCH_F }, |
| 933 | { 0x30, 0xf0, CHREQ_T_PAG_R_TCH_FH }, |
| 934 | }; |
| 935 | |
| 936 | /* If SYSTEM INFORMATION TYPE 4 NECI bit == 0 */ |
| 937 | static const struct chreq chreq_type_neci0[] = { |
| 938 | { 0xa0, 0xe0, CHREQ_T_EMERG_CALL }, |
| 939 | { 0xc0, 0xe0, CHREQ_T_CALL_REEST_TCH_H }, |
| 940 | { 0xe0, 0xe0, CHREQ_T_TCH_F }, |
| 941 | { 0x50, 0xf0, CHREQ_T_DATA_CALL_TCH_H }, |
| 942 | { 0x00, 0xe0, CHREQ_T_LOCATION_UPD }, |
| 943 | { 0x80, 0xe0, CHREQ_T_PAG_R_ANY }, |
| 944 | { 0x20, 0xf0, CHREQ_T_PAG_R_TCH_F }, |
| 945 | { 0x30, 0xf0, CHREQ_T_PAG_R_TCH_FH }, |
| 946 | }; |
| 947 | |
| 948 | static const enum gsm_chan_t ctype_by_chreq[] = { |
| 949 | [CHREQ_T_EMERG_CALL] = GSM_LCHAN_TCH_F, |
| 950 | [CHREQ_T_CALL_REEST_TCH_F] = GSM_LCHAN_TCH_F, |
| 951 | [CHREQ_T_CALL_REEST_TCH_H] = GSM_LCHAN_TCH_H, |
| 952 | [CHREQ_T_CALL_REEST_TCH_H_DBL] = GSM_LCHAN_TCH_H, |
| 953 | [CHREQ_T_SDCCH] = GSM_LCHAN_SDCCH, |
| 954 | [CHREQ_T_TCH_F] = GSM_LCHAN_TCH_F, |
| 955 | [CHREQ_T_VOICE_CALL_TCH_H] = GSM_LCHAN_TCH_H, |
| 956 | [CHREQ_T_DATA_CALL_TCH_H] = GSM_LCHAN_TCH_H, |
| 957 | [CHREQ_T_LOCATION_UPD] = GSM_LCHAN_SDCCH, |
| 958 | [CHREQ_T_PAG_R_ANY] = GSM_LCHAN_SDCCH, |
| 959 | [CHREQ_T_PAG_R_TCH_F] = GSM_LCHAN_TCH_F, |
| 960 | [CHREQ_T_PAG_R_TCH_FH] = GSM_LCHAN_TCH_F, |
| 961 | }; |
| 962 | |
Harald Welte | e14a57c | 2008-12-29 04:08:28 +0000 | [diff] [blame] | 963 | static const enum gsm_chreq_reason_t reason_by_chreq[] = { |
| 964 | [CHREQ_T_EMERG_CALL] = GSM_CHREQ_REASON_EMERG, |
| 965 | [CHREQ_T_CALL_REEST_TCH_F] = GSM_CHREQ_REASON_CALL, |
| 966 | [CHREQ_T_CALL_REEST_TCH_H] = GSM_CHREQ_REASON_CALL, |
| 967 | [CHREQ_T_CALL_REEST_TCH_H_DBL] = GSM_CHREQ_REASON_CALL, |
| 968 | [CHREQ_T_SDCCH] = GSM_CHREQ_REASON_OTHER, |
| 969 | [CHREQ_T_TCH_F] = GSM_CHREQ_REASON_OTHER, |
| 970 | [CHREQ_T_VOICE_CALL_TCH_H] = GSM_CHREQ_REASON_OTHER, |
| 971 | [CHREQ_T_DATA_CALL_TCH_H] = GSM_CHREQ_REASON_OTHER, |
| 972 | [CHREQ_T_LOCATION_UPD] = GSM_CHREQ_REASON_LOCATION_UPD, |
| 973 | [CHREQ_T_PAG_R_ANY] = GSM_CHREQ_REASON_PAG, |
| 974 | [CHREQ_T_PAG_R_TCH_F] = GSM_CHREQ_REASON_PAG, |
| 975 | [CHREQ_T_PAG_R_TCH_FH] = GSM_CHREQ_REASON_PAG, |
| 976 | }; |
| 977 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 978 | enum gsm_chan_t get_ctype_by_chreq(struct gsm_bts *bts, u_int8_t ra) |
| 979 | { |
| 980 | int i; |
| 981 | /* FIXME: determine if we set NECI = 0 in the BTS SI4 */ |
| 982 | |
| 983 | for (i = 0; i < ARRAY_SIZE(chreq_type_neci0); i++) { |
| 984 | const struct chreq *chr = &chreq_type_neci0[i]; |
| 985 | if ((ra & chr->mask) == chr->val) |
| 986 | return ctype_by_chreq[chr->type]; |
| 987 | } |
| 988 | fprintf(stderr, "Unknown CHANNEL REQUEST RQD 0x%02x\n", ra); |
| 989 | return GSM_LCHAN_SDCCH; |
| 990 | } |
Harald Welte | e14a57c | 2008-12-29 04:08:28 +0000 | [diff] [blame] | 991 | |
| 992 | enum gsm_chreq_reason_t get_reason_by_chreq(struct gsm_bts *bts, u_int8_t ra) |
| 993 | { |
| 994 | int i; |
| 995 | /* FIXME: determine if we set NECI = 0 in the BTS SI4 */ |
| 996 | |
| 997 | for (i = 0; i < ARRAY_SIZE(chreq_type_neci0); i++) { |
| 998 | const struct chreq *chr = &chreq_type_neci0[i]; |
| 999 | if ((ra & chr->mask) == chr->val) |
| 1000 | return reason_by_chreq[chr->type]; |
| 1001 | } |
| 1002 | fprintf(stderr, "Unknown CHANNEL REQUEST REASON 0x%02x\n", ra); |
| 1003 | return GSM_CHREQ_REASON_OTHER; |
| 1004 | } |