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