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