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