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 | 09e38af | 2009-02-16 22:52:23 +0000 | [diff] [blame^] | 364 | //ret = gsm48_cc_tx_setup(lchan); |
Harald Welte | db253af | 2008-12-30 17:56:55 +0000 | [diff] [blame] | 365 | ret = gsm48_tx_mm_info(lchan); |
Harald Welte | db253af | 2008-12-30 17:56:55 +0000 | [diff] [blame] | 366 | |
Holger Freyther | 07cc8d8 | 2008-12-29 06:23:46 +0000 | [diff] [blame] | 367 | return ret; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 368 | } |
| 369 | |
Harald Welte | fc977a8 | 2008-12-27 10:19:37 +0000 | [diff] [blame] | 370 | static char bcd2char(u_int8_t bcd) |
| 371 | { |
| 372 | if (bcd < 0xa) |
| 373 | return '0' + bcd; |
| 374 | else |
| 375 | return 'A' + (bcd - 0xa); |
| 376 | } |
| 377 | |
Harald Welte | bf5e8df | 2009-02-03 12:59:45 +0000 | [diff] [blame] | 378 | /* Convert Mobile Identity (10.5.1.4) to string */ |
Harald Welte | fc977a8 | 2008-12-27 10:19:37 +0000 | [diff] [blame] | 379 | static int mi_to_string(char *string, int str_len, u_int8_t *mi, int mi_len) |
| 380 | { |
| 381 | int i; |
| 382 | u_int8_t mi_type; |
| 383 | char *str_cur = string; |
Harald Welte | 4ed0e92 | 2009-01-10 03:17:30 +0000 | [diff] [blame] | 384 | u_int32_t tmsi; |
Harald Welte | fc977a8 | 2008-12-27 10:19:37 +0000 | [diff] [blame] | 385 | |
| 386 | mi_type = mi[0] & GSM_MI_TYPE_MASK; |
| 387 | |
| 388 | switch (mi_type) { |
| 389 | case GSM_MI_TYPE_NONE: |
| 390 | break; |
| 391 | case GSM_MI_TYPE_TMSI: |
Harald Welte | 4ed0e92 | 2009-01-10 03:17:30 +0000 | [diff] [blame] | 392 | /* Table 10.5.4.3, reverse generate_mid_from_tmsi */ |
| 393 | if (mi_len == TMSI_LEN && mi[0] == (0xf0 | GSM_MI_TYPE_TMSI)) { |
| 394 | memcpy(&tmsi, &mi[1], 4); |
| 395 | tmsi = ntohl(tmsi); |
| 396 | return snprintf(string, str_len, "%u", tmsi); |
Harald Welte | fc977a8 | 2008-12-27 10:19:37 +0000 | [diff] [blame] | 397 | } |
| 398 | break; |
| 399 | case GSM_MI_TYPE_IMSI: |
| 400 | case GSM_MI_TYPE_IMEI: |
| 401 | case GSM_MI_TYPE_IMEISV: |
Harald Welte | db253af | 2008-12-30 17:56:55 +0000 | [diff] [blame] | 402 | *str_cur++ = bcd2char(mi[0] >> 4); |
| 403 | |
| 404 | for (i = 1; i < mi_len; i++) { |
Harald Welte | fc977a8 | 2008-12-27 10:19:37 +0000 | [diff] [blame] | 405 | if (str_cur + 2 >= string + str_len) |
| 406 | return str_cur - string; |
| 407 | *str_cur++ = bcd2char(mi[i] & 0xf); |
Harald Welte | db253af | 2008-12-30 17:56:55 +0000 | [diff] [blame] | 408 | /* skip last nibble in last input byte when GSM_EVEN */ |
| 409 | if( (i != mi_len-1) || (mi[0] & GSM_MI_ODD)) |
| 410 | *str_cur++ = bcd2char(mi[i] >> 4); |
Harald Welte | fc977a8 | 2008-12-27 10:19:37 +0000 | [diff] [blame] | 411 | } |
| 412 | break; |
| 413 | default: |
| 414 | break; |
| 415 | } |
Harald Welte | fc977a8 | 2008-12-27 10:19:37 +0000 | [diff] [blame] | 416 | *str_cur++ = '\0'; |
Harald Welte | db253af | 2008-12-30 17:56:55 +0000 | [diff] [blame] | 417 | |
Harald Welte | fc977a8 | 2008-12-27 10:19:37 +0000 | [diff] [blame] | 418 | return str_cur - string; |
| 419 | } |
| 420 | |
Harald Welte | bf5e8df | 2009-02-03 12:59:45 +0000 | [diff] [blame] | 421 | /* Transmit Chapter 9.2.10 Identity Request */ |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 422 | static int mm_tx_identity_req(struct gsm_lchan *lchan, u_int8_t id_type) |
| 423 | { |
| 424 | struct msgb *msg = gsm48_msgb_alloc(); |
| 425 | struct gsm48_hdr *gh; |
Harald Welte | fc977a8 | 2008-12-27 10:19:37 +0000 | [diff] [blame] | 426 | |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 427 | msg->lchan = lchan; |
| 428 | |
| 429 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 1); |
| 430 | gh->proto_discr = GSM48_PDISC_MM; |
| 431 | gh->msg_type = GSM48_MT_MM_ID_REQ; |
| 432 | gh->data[0] = id_type; |
| 433 | |
Harald Welte | 65e74cc | 2008-12-29 01:55:35 +0000 | [diff] [blame] | 434 | return gsm48_sendmsg(msg); |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 435 | } |
| 436 | |
| 437 | #define MI_SIZE 32 |
| 438 | |
Harald Welte | bf5e8df | 2009-02-03 12:59:45 +0000 | [diff] [blame] | 439 | /* Parse Chapter 9.2.11 Identity Response */ |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 440 | static int mm_rx_id_resp(struct msgb *msg) |
| 441 | { |
| 442 | struct gsm48_hdr *gh = msgb_l3(msg); |
Harald Welte | 75a983f | 2008-12-27 21:34:06 +0000 | [diff] [blame] | 443 | struct gsm_lchan *lchan = msg->lchan; |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 444 | u_int8_t mi_type = gh->data[1] & GSM_MI_TYPE_MASK; |
| 445 | char mi_string[MI_SIZE]; |
Harald Welte | 75a983f | 2008-12-27 21:34:06 +0000 | [diff] [blame] | 446 | u_int32_t tmsi; |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 447 | |
| 448 | 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] | 449 | DEBUGP(DMM, "IDENTITY RESPONSE: mi_type=0x%02x MI(%s)\n", |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 450 | mi_type, mi_string); |
| 451 | |
Holger Freyther | c6ea9db | 2008-12-30 19:18:21 +0000 | [diff] [blame] | 452 | /* |
| 453 | * Rogue messages could trick us but so is life |
| 454 | */ |
| 455 | put_lchan(lchan); |
| 456 | |
Harald Welte | 75a983f | 2008-12-27 21:34:06 +0000 | [diff] [blame] | 457 | switch (mi_type) { |
| 458 | case GSM_MI_TYPE_IMSI: |
| 459 | if (!lchan->subscr) |
| 460 | lchan->subscr = db_create_subscriber(mi_string); |
Holger Freyther | 73487a2 | 2008-12-31 18:53:57 +0000 | [diff] [blame] | 461 | if (lchan->loc_operation) |
| 462 | lchan->loc_operation->waiting_for_imsi = 0; |
Harald Welte | 75a983f | 2008-12-27 21:34:06 +0000 | [diff] [blame] | 463 | break; |
| 464 | case GSM_MI_TYPE_IMEI: |
Harald Welte | 255539c | 2008-12-28 02:26:27 +0000 | [diff] [blame] | 465 | case GSM_MI_TYPE_IMEISV: |
Harald Welte | 75a983f | 2008-12-27 21:34:06 +0000 | [diff] [blame] | 466 | /* update subscribe <-> IMEI mapping */ |
| 467 | if (lchan->subscr) |
| 468 | db_subscriber_assoc_imei(lchan->subscr, mi_string); |
Holger Freyther | 73487a2 | 2008-12-31 18:53:57 +0000 | [diff] [blame] | 469 | if (lchan->loc_operation) |
| 470 | lchan->loc_operation->waiting_for_imei = 0; |
Harald Welte | 75a983f | 2008-12-27 21:34:06 +0000 | [diff] [blame] | 471 | break; |
| 472 | } |
Holger Freyther | 73487a2 | 2008-12-31 18:53:57 +0000 | [diff] [blame] | 473 | |
| 474 | /* Check if we can let the mobile station enter */ |
| 475 | if (authorize_subscriber(lchan->loc_operation, lchan->subscr)) { |
| 476 | db_subscriber_alloc_tmsi(lchan->subscr); |
| 477 | tmsi = strtoul(lchan->subscr->tmsi, NULL, 10); |
| 478 | release_loc_updating_req(lchan); |
| 479 | return gsm0408_loc_upd_acc(msg->lchan, tmsi); |
| 480 | } |
| 481 | |
Harald Welte | 75a983f | 2008-12-27 21:34:06 +0000 | [diff] [blame] | 482 | return 0; |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 483 | } |
| 484 | |
Harald Welte | 255539c | 2008-12-28 02:26:27 +0000 | [diff] [blame] | 485 | |
| 486 | static void loc_upd_rej_cb(void *data) |
| 487 | { |
| 488 | struct gsm_lchan *lchan = data; |
| 489 | |
Holger Freyther | 73487a2 | 2008-12-31 18:53:57 +0000 | [diff] [blame] | 490 | release_loc_updating_req(lchan); |
Holger Freyther | e97f7fb | 2008-12-31 18:52:11 +0000 | [diff] [blame] | 491 | gsm0408_loc_upd_rej(lchan, reject_cause); |
Holger Freyther | 67b4b9a | 2009-01-01 03:46:11 +0000 | [diff] [blame] | 492 | lchan_auto_release(lchan); |
Harald Welte | 255539c | 2008-12-28 02:26:27 +0000 | [diff] [blame] | 493 | } |
| 494 | |
Holger Freyther | b7193e4 | 2008-12-29 17:44:08 +0000 | [diff] [blame] | 495 | static void schedule_reject(struct gsm_lchan *lchan) |
| 496 | { |
Holger Freyther | 73487a2 | 2008-12-31 18:53:57 +0000 | [diff] [blame] | 497 | lchan->loc_operation->updating_timer.cb = loc_upd_rej_cb; |
| 498 | lchan->loc_operation->updating_timer.data = lchan; |
| 499 | schedule_timer(&lchan->loc_operation->updating_timer, 5, 0); |
Holger Freyther | b7193e4 | 2008-12-29 17:44:08 +0000 | [diff] [blame] | 500 | } |
| 501 | |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 502 | #define MI_SIZE 32 |
Harald Welte | bf5e8df | 2009-02-03 12:59:45 +0000 | [diff] [blame] | 503 | /* Chapter 9.2.15: Receive Location Updating Request */ |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 504 | static int mm_rx_loc_upd_req(struct msgb *msg) |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 505 | { |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 506 | struct gsm48_hdr *gh = msgb_l3(msg); |
Harald Welte | 702d870 | 2008-12-26 20:25:35 +0000 | [diff] [blame] | 507 | struct gsm_bts *bts = msg->trx->bts; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 508 | struct gsm48_loc_upd_req *lu; |
| 509 | struct gsm_subscriber *subscr; |
Harald Welte | 255539c | 2008-12-28 02:26:27 +0000 | [diff] [blame] | 510 | struct gsm_lchan *lchan = msg->lchan; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 511 | u_int8_t mi_type; |
Harald Welte | 75a983f | 2008-12-27 21:34:06 +0000 | [diff] [blame] | 512 | u_int32_t tmsi; |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 513 | char mi_string[MI_SIZE]; |
| 514 | int rc; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 515 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 516 | lu = (struct gsm48_loc_upd_req *) gh->data; |
| 517 | |
| 518 | mi_type = lu->mi[0] & GSM_MI_TYPE_MASK; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 519 | |
Harald Welte | fc977a8 | 2008-12-27 10:19:37 +0000 | [diff] [blame] | 520 | mi_to_string(mi_string, sizeof(mi_string), lu->mi, lu->mi_len); |
| 521 | |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 522 | 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] | 523 | |
| 524 | allocate_loc_updating_req(lchan); |
| 525 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 526 | switch (mi_type) { |
| 527 | case GSM_MI_TYPE_IMSI: |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 528 | /* we always want the IMEI, too */ |
Holger Freyther | c6ea9db | 2008-12-30 19:18:21 +0000 | [diff] [blame] | 529 | use_lchan(lchan); |
Harald Welte | 255539c | 2008-12-28 02:26:27 +0000 | [diff] [blame] | 530 | rc = mm_tx_identity_req(lchan, GSM_MI_TYPE_IMEISV); |
Holger Freyther | 73487a2 | 2008-12-31 18:53:57 +0000 | [diff] [blame] | 531 | lchan->loc_operation->waiting_for_imei = 1; |
Holger Freyther | c6ea9db | 2008-12-30 19:18:21 +0000 | [diff] [blame] | 532 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 533 | /* look up subscriber based on IMSI */ |
Harald Welte | 75a983f | 2008-12-27 21:34:06 +0000 | [diff] [blame] | 534 | subscr = db_create_subscriber(mi_string); |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 535 | break; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 536 | case GSM_MI_TYPE_TMSI: |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 537 | /* we always want the IMEI, too */ |
Holger Freyther | c6ea9db | 2008-12-30 19:18:21 +0000 | [diff] [blame] | 538 | use_lchan(lchan); |
Harald Welte | 255539c | 2008-12-28 02:26:27 +0000 | [diff] [blame] | 539 | rc = mm_tx_identity_req(lchan, GSM_MI_TYPE_IMEISV); |
Holger Freyther | 73487a2 | 2008-12-31 18:53:57 +0000 | [diff] [blame] | 540 | lchan->loc_operation->waiting_for_imei = 1; |
Holger Freyther | c6ea9db | 2008-12-30 19:18:21 +0000 | [diff] [blame] | 541 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 542 | /* look up the subscriber based on TMSI, request IMSI if it fails */ |
Harald Welte | ba4cf16 | 2009-01-10 01:49:35 +0000 | [diff] [blame] | 543 | subscr = subscr_get_by_tmsi(mi_string); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 544 | if (!subscr) { |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 545 | /* send IDENTITY REQUEST message to get IMSI */ |
Holger Freyther | c6ea9db | 2008-12-30 19:18:21 +0000 | [diff] [blame] | 546 | use_lchan(lchan); |
Harald Welte | 255539c | 2008-12-28 02:26:27 +0000 | [diff] [blame] | 547 | rc = mm_tx_identity_req(lchan, GSM_MI_TYPE_IMSI); |
Holger Freyther | 73487a2 | 2008-12-31 18:53:57 +0000 | [diff] [blame] | 548 | lchan->loc_operation->waiting_for_imsi = 1; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 549 | } |
| 550 | break; |
| 551 | case GSM_MI_TYPE_IMEI: |
| 552 | case GSM_MI_TYPE_IMEISV: |
| 553 | /* no sim card... FIXME: what to do ? */ |
| 554 | fprintf(stderr, "Unimplemented mobile identity type\n"); |
| 555 | break; |
| 556 | default: |
| 557 | fprintf(stderr, "Unknown mobile identity type\n"); |
| 558 | break; |
| 559 | } |
| 560 | |
Harald Welte | 255539c | 2008-12-28 02:26:27 +0000 | [diff] [blame] | 561 | lchan->subscr = subscr; |
| 562 | |
Holger Freyther | 73487a2 | 2008-12-31 18:53:57 +0000 | [diff] [blame] | 563 | /* |
| 564 | * Schedule the reject timer and check if we can let the |
| 565 | * subscriber into our network immediately or if we need to wait |
| 566 | * for identity responses. |
| 567 | */ |
| 568 | schedule_reject(lchan); |
| 569 | if (!authorize_subscriber(lchan->loc_operation, subscr)) |
Harald Welte | e872cb1 | 2009-01-01 00:33:37 +0000 | [diff] [blame] | 570 | return 0; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 571 | |
Harald Welte | 75a983f | 2008-12-27 21:34:06 +0000 | [diff] [blame] | 572 | db_subscriber_alloc_tmsi(subscr); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 573 | subscr_update(subscr, bts); |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 574 | |
Harald Welte | 255539c | 2008-12-28 02:26:27 +0000 | [diff] [blame] | 575 | tmsi = strtoul(subscr->tmsi, NULL, 10); |
| 576 | |
Holger Freyther | 73487a2 | 2008-12-31 18:53:57 +0000 | [diff] [blame] | 577 | release_loc_updating_req(lchan); |
Harald Welte | 255539c | 2008-12-28 02:26:27 +0000 | [diff] [blame] | 578 | return gsm0408_loc_upd_acc(lchan, tmsi); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 579 | } |
| 580 | |
Harald Welte | 7584aea | 2009-02-11 11:44:12 +0000 | [diff] [blame] | 581 | /* 9.1.5 Channel mode modify */ |
| 582 | int gsm48_tx_chan_mode_modify(struct gsm_lchan *lchan, u_int8_t mode) |
| 583 | { |
| 584 | struct msgb *msg = gsm48_msgb_alloc(); |
| 585 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 586 | struct gsm48_chan_mode_modify *cmm = |
| 587 | (struct gsm48_chan_mode_modify *) msgb_put(msg, sizeof(*cmm)); |
| 588 | u_int16_t arfcn = lchan->ts->trx->arfcn; |
| 589 | |
| 590 | msg->lchan = lchan; |
| 591 | gh->proto_discr = GSM48_PDISC_RR; |
| 592 | gh->msg_type = GSM48_MT_RR_CHAN_MODE_MODIF; |
| 593 | |
| 594 | /* fill the channel information element, this code |
| 595 | * should probably be shared with rsl_rx_chan_rqd() */ |
| 596 | cmm->chan_desc.chan_nr = lchan2chan_nr(lchan); |
| 597 | cmm->chan_desc.h0.h = 0; |
| 598 | cmm->chan_desc.h0.arfcn_high = arfcn >> 8; |
| 599 | cmm->chan_desc.h0.arfcn_low = arfcn & 0xff; |
| 600 | cmm->mode = mode; |
| 601 | |
| 602 | return gsm48_sendmsg(msg); |
| 603 | } |
| 604 | |
Harald Welte | db253af | 2008-12-30 17:56:55 +0000 | [diff] [blame] | 605 | /* Section 9.2.15a */ |
| 606 | int gsm48_tx_mm_info(struct gsm_lchan *lchan) |
| 607 | { |
| 608 | struct msgb *msg = gsm48_msgb_alloc(); |
| 609 | struct gsm48_hdr *gh; |
| 610 | struct gsm_network *net = lchan->ts->trx->bts->network; |
Harald Welte | db253af | 2008-12-30 17:56:55 +0000 | [diff] [blame] | 611 | u_int8_t *ptr8; |
| 612 | u_int16_t *ptr16; |
| 613 | int name_len; |
Harald Welte | db253af | 2008-12-30 17:56:55 +0000 | [diff] [blame] | 614 | int i; |
| 615 | |
| 616 | msg->lchan = lchan; |
| 617 | |
| 618 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 619 | gh->proto_discr = GSM48_PDISC_MM; |
| 620 | gh->msg_type = GSM48_MT_MM_INFO; |
| 621 | |
| 622 | if (net->name_long) { |
| 623 | name_len = strlen(net->name_long); |
| 624 | /* 10.5.3.5a */ |
| 625 | ptr8 = msgb_put(msg, 3); |
| 626 | ptr8[0] = GSM48_IE_NAME_LONG; |
| 627 | ptr8[1] = name_len*2 +1; |
| 628 | ptr8[2] = 0x90; /* UCS2, no spare bits, no CI */ |
| 629 | |
| 630 | ptr16 = (u_int16_t *) msgb_put(msg, name_len*2); |
| 631 | for (i = 0; i < name_len; i++) |
Harald Welte | 179f064 | 2008-12-31 23:59:18 +0000 | [diff] [blame] | 632 | ptr16[i] = htons(net->name_long[i]); |
Harald Welte | db253af | 2008-12-30 17:56:55 +0000 | [diff] [blame] | 633 | |
| 634 | /* FIXME: Use Cell Broadcast, not UCS-2, since |
| 635 | * UCS-2 is only supported by later revisions of the spec */ |
| 636 | } |
| 637 | |
| 638 | if (net->name_short) { |
| 639 | name_len = strlen(net->name_short); |
| 640 | /* 10.5.3.5a */ |
| 641 | ptr8 = (u_int8_t *) msgb_put(msg, 3); |
| 642 | ptr8[0] = GSM48_IE_NAME_LONG; |
| 643 | ptr8[1] = name_len*2 + 1; |
| 644 | ptr8[2] = 0x90; /* UCS2, no spare bits, no CI */ |
| 645 | |
Harald Welte | e872cb1 | 2009-01-01 00:33:37 +0000 | [diff] [blame] | 646 | ptr16 = (u_int16_t *) msgb_put(msg, name_len*2); |
Harald Welte | db253af | 2008-12-30 17:56:55 +0000 | [diff] [blame] | 647 | for (i = 0; i < name_len; i++) |
Harald Welte | 179f064 | 2008-12-31 23:59:18 +0000 | [diff] [blame] | 648 | ptr16[i] = htons(net->name_short[i]); |
Harald Welte | db253af | 2008-12-30 17:56:55 +0000 | [diff] [blame] | 649 | } |
| 650 | |
| 651 | #if 0 |
Holger Freyther | ca362a6 | 2009-01-04 21:05:01 +0000 | [diff] [blame] | 652 | /* move back to the top */ |
| 653 | time_t cur_t; |
| 654 | struct tm* cur_time; |
| 655 | int tz15min; |
Harald Welte | db253af | 2008-12-30 17:56:55 +0000 | [diff] [blame] | 656 | /* Section 10.5.3.9 */ |
| 657 | cur_t = time(NULL); |
| 658 | cur_time = gmtime(cur_t); |
| 659 | ptr8 = msgb_put(msg, 8); |
| 660 | ptr8[0] = GSM48_IE_NET_TIME_TZ; |
| 661 | ptr8[1] = to_bcd8(cur_time->tm_year % 100); |
| 662 | ptr8[2] = to_bcd8(cur_time->tm_mon); |
| 663 | ptr8[3] = to_bcd8(cur_time->tm_mday); |
| 664 | ptr8[4] = to_bcd8(cur_time->tm_hour); |
| 665 | ptr8[5] = to_bcd8(cur_time->tm_min); |
| 666 | ptr8[6] = to_bcd8(cur_time->tm_sec); |
| 667 | /* 02.42: coded as BCD encoded signed value in units of 15 minutes */ |
| 668 | tz15min = (cur_time->tm_gmtoff)/(60*15); |
| 669 | ptr8[6] = to_bcd8(tz15min); |
| 670 | if (tz15min < 0) |
| 671 | ptr8[6] |= 0x80; |
| 672 | #endif |
| 673 | |
| 674 | return gsm48_sendmsg(msg); |
| 675 | } |
| 676 | |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 677 | static int gsm48_tx_mm_serv_ack(struct gsm_lchan *lchan) |
| 678 | { |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 679 | DEBUGP(DMM, "-> CM SERVICE ACK\n"); |
Harald Welte | 65e74cc | 2008-12-29 01:55:35 +0000 | [diff] [blame] | 680 | 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] | 681 | } |
Harald Welte | ba4cf16 | 2009-01-10 01:49:35 +0000 | [diff] [blame] | 682 | |
| 683 | /* 9.2.6 CM service reject */ |
| 684 | static int gsm48_tx_mm_serv_rej(struct gsm_lchan *lchan, |
| 685 | enum gsm48_reject_value value) |
| 686 | { |
| 687 | struct msgb *msg = gsm48_msgb_alloc(); |
| 688 | struct gsm48_hdr *gh; |
| 689 | |
| 690 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 1); |
| 691 | |
| 692 | msg->lchan = lchan; |
| 693 | use_lchan(lchan); |
| 694 | |
| 695 | gh->proto_discr = GSM48_PDISC_MM; |
| 696 | gh->msg_type = GSM48_MT_MM_CM_SERV_REJ; |
| 697 | gh->data[0] = value; |
| 698 | DEBUGP(DMM, "-> CM SERVICE Reject cause: %d\n", value); |
| 699 | |
| 700 | return gsm48_sendmsg(msg); |
| 701 | } |
| 702 | |
Harald Welte | 4ed0e92 | 2009-01-10 03:17:30 +0000 | [diff] [blame] | 703 | |
| 704 | /* |
| 705 | * Handle CM Service Requests |
| 706 | * a) Verify that the packet is long enough to contain the information |
| 707 | * we require otherwsie reject with INCORRECT_MESSAGE |
| 708 | * b) Try to parse the TMSI. If we do not have one reject |
| 709 | * c) Check that we know the subscriber with the TMSI otherwise reject |
| 710 | * with a HLR cause |
| 711 | * d) Set the subscriber on the gsm_lchan and accept |
| 712 | */ |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 713 | static int gsm48_rx_mm_serv_req(struct msgb *msg) |
| 714 | { |
Harald Welte | ba4cf16 | 2009-01-10 01:49:35 +0000 | [diff] [blame] | 715 | u_int8_t mi_type; |
Harald Welte | 4ed0e92 | 2009-01-10 03:17:30 +0000 | [diff] [blame] | 716 | char mi_string[MI_SIZE]; |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 717 | |
Harald Welte | ba4cf16 | 2009-01-10 01:49:35 +0000 | [diff] [blame] | 718 | struct gsm_subscriber *subscr; |
| 719 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 720 | struct gsm48_service_request *req = |
| 721 | (struct gsm48_service_request *)gh->data; |
| 722 | |
| 723 | if (msg->data_len < sizeof(struct gsm48_service_request*)) { |
| 724 | DEBUGP(DMM, "<- CM SERVICE REQUEST wrong sized message\n"); |
| 725 | return gsm48_tx_mm_serv_rej(msg->lchan, |
| 726 | GSM48_REJECT_INCORRECT_MESSAGE); |
| 727 | } |
| 728 | |
| 729 | if (msg->data_len < req->mi_len + 6) { |
| 730 | DEBUGP(DMM, "<- CM SERVICE REQUEST MI does not fit in package\n"); |
| 731 | return gsm48_tx_mm_serv_rej(msg->lchan, |
| 732 | GSM48_REJECT_INCORRECT_MESSAGE); |
| 733 | } |
| 734 | |
| 735 | mi_type = req->mi[0] & GSM_MI_TYPE_MASK; |
| 736 | if (mi_type != GSM_MI_TYPE_TMSI) { |
| 737 | DEBUGP(DMM, "<- CM SERVICE REQUEST mi type is not TMSI: %d\n", mi_type); |
| 738 | return gsm48_tx_mm_serv_rej(msg->lchan, |
| 739 | GSM48_REJECT_INCORRECT_MESSAGE); |
| 740 | } |
| 741 | |
Harald Welte | 4ed0e92 | 2009-01-10 03:17:30 +0000 | [diff] [blame] | 742 | mi_to_string(mi_string, sizeof(mi_string), req->mi, req->mi_len); |
| 743 | subscr = subscr_get_by_tmsi(mi_string); |
| 744 | DEBUGP(DMM, "<- CM SERVICE REQUEST serv_type=0x%02x mi_type=0x%02x M(%s)\n", |
| 745 | req->cm_service_type, mi_type, mi_string); |
Harald Welte | bcae43f | 2008-12-27 21:45:37 +0000 | [diff] [blame] | 746 | |
Harald Welte | 4ed0e92 | 2009-01-10 03:17:30 +0000 | [diff] [blame] | 747 | if (!subscr) |
| 748 | return gsm48_tx_mm_serv_rej(msg->lchan, |
| 749 | GSM48_REJECT_IMSI_UNKNOWN_IN_HLR); |
| 750 | |
| 751 | if (!msg->lchan->subscr) |
| 752 | msg->lchan->subscr = subscr; |
Harald Welte | 9bb7c70 | 2009-01-10 03:21:41 +0000 | [diff] [blame] | 753 | else if (msg->lchan->subscr != subscr) { |
| 754 | DEBUGP(DMM, "<- CM Channel already owned by someone else?\n"); |
| 755 | subscr_put(subscr); |
| 756 | } |
| 757 | |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 758 | return gsm48_tx_mm_serv_ack(msg->lchan); |
| 759 | } |
| 760 | |
Harald Welte | bf5e8df | 2009-02-03 12:59:45 +0000 | [diff] [blame] | 761 | /* Receive a GSM 04.08 Mobility Management (MM) message */ |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 762 | static int gsm0408_rcv_mm(struct msgb *msg) |
| 763 | { |
| 764 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 765 | int rc; |
| 766 | |
| 767 | switch (gh->msg_type & 0xbf) { |
| 768 | case GSM48_MT_MM_LOC_UPD_REQUEST: |
Holger Freyther | 429e776 | 2008-12-30 13:28:30 +0000 | [diff] [blame] | 769 | DEBUGP(DMM, "LOCATION UPDATING REQUEST\n"); |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 770 | rc = mm_rx_loc_upd_req(msg); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 771 | break; |
| 772 | case GSM48_MT_MM_ID_RESP: |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 773 | rc = mm_rx_id_resp(msg); |
| 774 | break; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 775 | case GSM48_MT_MM_CM_SERV_REQ: |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 776 | rc = gsm48_rx_mm_serv_req(msg); |
| 777 | break; |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 778 | case GSM48_MT_MM_STATUS: |
| 779 | DEBUGP(DMM, "MM STATUS: FIXME parse error cond.\n"); |
| 780 | break; |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 781 | case GSM48_MT_MM_TMSI_REALL_COMPL: |
Harald Welte | 69b2af2 | 2009-01-06 19:47:00 +0000 | [diff] [blame] | 782 | DEBUGP(DMM, "TMSI Reallocation Completed. Subscriber: %s\n", |
| 783 | msg->lchan->subscr ? |
| 784 | msg->lchan->subscr->imsi : |
| 785 | "unknown subscriber"); |
| 786 | break; |
| 787 | case GSM48_MT_MM_CM_REEST_REQ: |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 788 | case GSM48_MT_MM_AUTH_RESP: |
| 789 | case GSM48_MT_MM_IMSI_DETACH_IND: |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 790 | fprintf(stderr, "Unimplemented GSM 04.08 MM msg type 0x%02x\n", |
| 791 | gh->msg_type); |
| 792 | break; |
| 793 | default: |
| 794 | fprintf(stderr, "Unknown GSM 04.08 MM msg type 0x%02x\n", |
| 795 | gh->msg_type); |
| 796 | break; |
| 797 | } |
| 798 | |
| 799 | return rc; |
| 800 | } |
Harald Welte | bf5e8df | 2009-02-03 12:59:45 +0000 | [diff] [blame] | 801 | |
Harald Welte | 2d35ae6 | 2009-02-06 12:02:13 +0000 | [diff] [blame] | 802 | /* Receive a PAGING RESPONSE message from the MS */ |
| 803 | static int gsm48_rr_rx_pag_resp(struct msgb *msg) |
| 804 | { |
| 805 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 806 | struct gsm48_paging_response *pr = |
| 807 | (struct gsm48_paging_response *) gh->data; |
| 808 | u_int8_t mi_type = pr->mi[0] & GSM_MI_TYPE_MASK; |
| 809 | char mi_string[MI_SIZE]; |
| 810 | struct gsm_subscriber *subscr; |
Harald Welte | 595ad7b | 2009-02-16 22:05:44 +0000 | [diff] [blame] | 811 | struct paging_signal_data sig_data; |
Harald Welte | 2d35ae6 | 2009-02-06 12:02:13 +0000 | [diff] [blame] | 812 | int rc = 0; |
| 813 | |
| 814 | mi_to_string(mi_string, sizeof(mi_string), &pr->mi[0], pr->mi_len); |
| 815 | DEBUGP(DRR, "PAGING RESPONSE: mi_type=0x%02x MI(%s)\n", |
| 816 | mi_type, mi_string); |
| 817 | subscr = subscr_get_by_tmsi(mi_string); |
| 818 | |
| 819 | if (!subscr) { |
| 820 | DEBUGP(DRR, "<- Can't find any subscriber for this ID\n"); |
Harald Welte | 09e38af | 2009-02-16 22:52:23 +0000 | [diff] [blame^] | 821 | /* FIXME: request id? close channel? */ |
Harald Welte | 2d35ae6 | 2009-02-06 12:02:13 +0000 | [diff] [blame] | 822 | return -EINVAL; |
| 823 | } |
| 824 | DEBUGP(DRR, "<- Channel was requested by %s\n", |
| 825 | subscr->name ? subscr->name : subscr->imsi); |
Holger Freyther | 053e09d | 2009-02-14 22:51:06 +0000 | [diff] [blame] | 826 | |
Holger Freyther | 2fa4cb5 | 2009-02-14 23:53:15 +0000 | [diff] [blame] | 827 | if (!msg->lchan->subscr) |
| 828 | msg->lchan->subscr = subscr; |
| 829 | else if (msg->lchan->subscr != subscr) { |
| 830 | DEBUGP(DRR, "<- Channel already owned by someone else?\n"); |
| 831 | subscr_put(subscr); |
| 832 | } |
| 833 | |
Harald Welte | 595ad7b | 2009-02-16 22:05:44 +0000 | [diff] [blame] | 834 | sig_data.subscr = subscr; |
| 835 | sig_data.bts = msg->lchan->ts->trx->bts; |
| 836 | sig_data.lchan = msg->lchan; |
| 837 | |
| 838 | dispatch_signal(SS_PAGING, S_PAGING_COMPLETED, &sig_data); |
Holger Freyther | 1fd3414 | 2009-02-09 23:42:03 +0000 | [diff] [blame] | 839 | paging_request_stop(msg->trx->bts, subscr); |
Harald Welte | 2d35ae6 | 2009-02-06 12:02:13 +0000 | [diff] [blame] | 840 | |
Harald Welte | 7584aea | 2009-02-11 11:44:12 +0000 | [diff] [blame] | 841 | /* FIXME: somehow signal the completion of the PAGING to |
| 842 | * the entity that requested the paging */ |
| 843 | |
Harald Welte | 2d35ae6 | 2009-02-06 12:02:13 +0000 | [diff] [blame] | 844 | return rc; |
| 845 | } |
| 846 | |
Harald Welte | bf5e8df | 2009-02-03 12:59:45 +0000 | [diff] [blame] | 847 | /* Receive a GSM 04.08 Radio Resource (RR) message */ |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 848 | static int gsm0408_rcv_rr(struct msgb *msg) |
| 849 | { |
| 850 | struct gsm48_hdr *gh = msgb_l3(msg); |
Harald Welte | 2d35ae6 | 2009-02-06 12:02:13 +0000 | [diff] [blame] | 851 | int rc = 0; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 852 | |
| 853 | switch (gh->msg_type) { |
| 854 | case GSM48_MT_RR_CLSM_CHG: |
| 855 | DEBUGP(DRR, "CLASSMARK CHANGE\n"); |
| 856 | /* FIXME: what to do ?!? */ |
| 857 | break; |
Harald Welte | fc977a8 | 2008-12-27 10:19:37 +0000 | [diff] [blame] | 858 | case GSM48_MT_RR_GPRS_SUSP_REQ: |
| 859 | DEBUGP(DRR, "GRPS SUSPEND REQUEST\n"); |
| 860 | break; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 861 | case GSM48_MT_RR_PAG_RESP: |
Harald Welte | 2d35ae6 | 2009-02-06 12:02:13 +0000 | [diff] [blame] | 862 | rc = gsm48_rr_rx_pag_resp(msg); |
| 863 | break; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 864 | default: |
Harald Welte | 2d35ae6 | 2009-02-06 12:02:13 +0000 | [diff] [blame] | 865 | fprintf(stderr, "Unimplemented GSM 04.08 RR msg type 0x%02x\n", |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 866 | gh->msg_type); |
| 867 | break; |
| 868 | } |
| 869 | |
Harald Welte | 2d35ae6 | 2009-02-06 12:02:13 +0000 | [diff] [blame] | 870 | return rc; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 871 | } |
| 872 | |
Holger Freyther | e64a7a3 | 2009-02-06 21:55:37 +0000 | [diff] [blame] | 873 | /* 7.1.7 and 9.1.7 Channel release*/ |
| 874 | int gsm48_send_rr_release(struct gsm_lchan *lchan) |
| 875 | { |
| 876 | struct msgb *msg = gsm48_msgb_alloc(); |
| 877 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 878 | u_int8_t *cause; |
| 879 | |
| 880 | msg->lchan = lchan; |
| 881 | gh->proto_discr = GSM48_PDISC_RR; |
| 882 | gh->msg_type = GSM48_MT_RR_CHAN_REL; |
| 883 | |
| 884 | cause = msgb_put(msg, 1); |
| 885 | cause[0] = GSM48_RR_CAUSE_NORMAL; |
| 886 | |
| 887 | DEBUGP(DRR, "Sending Channel Release: Chan: Number: %d Type: %d\n", |
| 888 | lchan->nr, lchan->type); |
| 889 | |
| 890 | return gsm48_sendmsg(msg); |
| 891 | } |
| 892 | |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 893 | /* Call Control */ |
| 894 | |
Harald Welte | 7584aea | 2009-02-11 11:44:12 +0000 | [diff] [blame] | 895 | /* The entire call control code is written in accordance with Figure 7.10c |
| 896 | * for 'very early assignment', i.e. we allocate a TCH/F during IMMEDIATE |
| 897 | * ASSIGN, then first use that TCH/F for signalling and later MODE MODIFY |
| 898 | * it for voice */ |
| 899 | |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 900 | static int gsm48_cc_tx_status(struct gsm_lchan *lchan) |
| 901 | { |
| 902 | struct msgb *msg = gsm48_msgb_alloc(); |
| 903 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 904 | u_int8_t *cause, *call_state; |
| 905 | |
Harald Welte | 65e74cc | 2008-12-29 01:55:35 +0000 | [diff] [blame] | 906 | gh->proto_discr = GSM48_PDISC_CC; |
| 907 | |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 908 | msg->lchan = lchan; |
| 909 | |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 910 | gh->msg_type = GSM48_MT_CC_STATUS; |
| 911 | |
| 912 | cause = msgb_put(msg, 3); |
| 913 | cause[0] = 2; |
| 914 | cause[1] = GSM48_CAUSE_CS_GSM | GSM48_CAUSE_LOC_USER; |
| 915 | cause[2] = 0x80 | 30; /* response to status inquiry */ |
| 916 | |
| 917 | call_state = msgb_put(msg, 1); |
| 918 | call_state[0] = 0xc0 | 0x00; |
| 919 | |
Harald Welte | 65e74cc | 2008-12-29 01:55:35 +0000 | [diff] [blame] | 920 | return gsm48_sendmsg(msg); |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 921 | } |
| 922 | |
Harald Welte | 6f4b753 | 2008-12-29 00:39:37 +0000 | [diff] [blame] | 923 | static int gsm48_tx_simple(struct gsm_lchan *lchan, |
| 924 | u_int8_t pdisc, u_int8_t msg_type) |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 925 | { |
| 926 | struct msgb *msg = gsm48_msgb_alloc(); |
| 927 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 928 | |
| 929 | msg->lchan = lchan; |
| 930 | |
Harald Welte | 6f4b753 | 2008-12-29 00:39:37 +0000 | [diff] [blame] | 931 | gh->proto_discr = pdisc; |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 932 | gh->msg_type = msg_type; |
| 933 | |
Harald Welte | 65e74cc | 2008-12-29 01:55:35 +0000 | [diff] [blame] | 934 | return gsm48_sendmsg(msg); |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 935 | } |
| 936 | |
Harald Welte | 09e38af | 2009-02-16 22:52:23 +0000 | [diff] [blame^] | 937 | /* call-back from paging the B-end of the connection */ |
| 938 | static int setup_trig_pag_evt(unsigned int hooknum, unsigned int event, |
| 939 | struct msgb *msg, void *data, void *param) |
| 940 | { |
| 941 | struct gsm_call *call = param; |
| 942 | |
| 943 | if (hooknum != GSM_HOOK_RR_PAGING) |
| 944 | return -EINVAL; |
| 945 | |
| 946 | switch (event) { |
| 947 | case GSM_PAGING_SUCCEEDED: |
| 948 | /* send SETUP request to called party */ |
| 949 | //gsm48_cc_tx_setup(lchan, call->subscr); |
| 950 | break; |
| 951 | case GSM_PAGING_EXPIRED: |
| 952 | /* notify caller that we cannot reach called party */ |
| 953 | break; |
| 954 | } |
| 955 | } |
| 956 | |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 957 | static int gsm48_cc_rx_status_enq(struct msgb *msg) |
| 958 | { |
| 959 | return gsm48_cc_tx_status(msg->lchan); |
| 960 | } |
| 961 | |
| 962 | static int gsm48_cc_rx_setup(struct msgb *msg) |
| 963 | { |
Harald Welte | 7584aea | 2009-02-11 11:44:12 +0000 | [diff] [blame] | 964 | struct gsm_call *call = &msg->lchan->call; |
| 965 | struct gsm48_hdr *gh = msgb_l3(msg); |
Harald Welte | 09e38af | 2009-02-16 22:52:23 +0000 | [diff] [blame^] | 966 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
Harald Welte | 7584aea | 2009-02-11 11:44:12 +0000 | [diff] [blame] | 967 | struct gsm_subscriber *called_subscr; |
Harald Welte | 09e38af | 2009-02-16 22:52:23 +0000 | [diff] [blame^] | 968 | char called_number[(43-2)*2 + 1] = "\0"; |
| 969 | struct tlv_parsed tp; |
| 970 | u_int8_t num_type; |
Harald Welte | 7584aea | 2009-02-11 11:44:12 +0000 | [diff] [blame] | 971 | int ret; |
| 972 | |
| 973 | if (call->state == GSM_CSTATE_NULL || |
| 974 | call->state == GSM_CSTATE_RELEASE_REQ) |
| 975 | use_lchan(msg->lchan); |
| 976 | |
| 977 | call->type = GSM_CT_MO; |
| 978 | call->state = GSM_CSTATE_INITIATED; |
| 979 | call->transaction_id = gh->proto_discr & 0xf0; |
| 980 | |
| 981 | DEBUGP(DCC, "SETUP(tid=0x%02x)\n", call->transaction_id); |
| 982 | |
Harald Welte | 09e38af | 2009-02-16 22:52:23 +0000 | [diff] [blame^] | 983 | tlv_parse(&tp, &rsl_att_tlvdef, gh->data, payload_len); |
| 984 | if (!TLVP_PRESENT(&tp, GSM48_IE_CALLED_BCD)) |
| 985 | goto err; |
Harald Welte | 7584aea | 2009-02-11 11:44:12 +0000 | [diff] [blame] | 986 | |
Harald Welte | 09e38af | 2009-02-16 22:52:23 +0000 | [diff] [blame^] | 987 | /* Parse the number that was dialed and lookup subscriber */ |
| 988 | num_type = decode_bcd_number(called_number, sizeof(called_number), |
| 989 | TLVP_VAL(&tp, GSM48_IE_CALLED_BCD)-1); |
| 990 | called_subscr = subscr_get_by_extension(called_number); |
Harald Welte | 7584aea | 2009-02-11 11:44:12 +0000 | [diff] [blame] | 991 | if (!called_subscr) { |
| 992 | DEBUGP(DCC, "could not find subscriber, RELEASE\n"); |
| 993 | put_lchan(msg->lchan); |
| 994 | return gsm48_tx_simple(msg->lchan, GSM48_PDISC_CC, |
| 995 | GSM48_MT_CC_RELEASE_COMPL); |
| 996 | } |
| 997 | |
Harald Welte | 09e38af | 2009-02-16 22:52:23 +0000 | [diff] [blame^] | 998 | subscr_get(msg->lchan->subscr); |
| 999 | call->subscr = msg->lchan->subscr; |
| 1000 | call->called_subscr = called_subscr; |
| 1001 | |
Harald Welte | 7584aea | 2009-02-11 11:44:12 +0000 | [diff] [blame] | 1002 | /* start paging of the receiving end of the call */ |
Harald Welte | 09e38af | 2009-02-16 22:52:23 +0000 | [diff] [blame^] | 1003 | paging_request(msg->trx->bts, called_subscr, RSL_CHANNEED_TCH_F, |
| 1004 | setup_trig_pag_evt, call); |
Harald Welte | 7584aea | 2009-02-11 11:44:12 +0000 | [diff] [blame] | 1005 | |
| 1006 | /* send a CALL PROCEEDING message to the MO */ |
| 1007 | ret = gsm48_tx_simple(msg->lchan, GSM48_PDISC_CC, |
| 1008 | GSM48_MT_CC_CALL_PROC); |
| 1009 | |
| 1010 | /* change TCH/F mode to voice */ |
| 1011 | return gsm48_tx_chan_mode_modify(msg->lchan, 0x01); |
Harald Welte | 09e38af | 2009-02-16 22:52:23 +0000 | [diff] [blame^] | 1012 | |
| 1013 | err: |
| 1014 | /* FIXME: send some kind of RELEASE */ |
| 1015 | return 0; |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 1016 | } |
Harald Welte | 7584aea | 2009-02-11 11:44:12 +0000 | [diff] [blame] | 1017 | |
| 1018 | static const u_int8_t calling_bcd[] = { 0xb9, 0x83, 0x32, 0x24 }; |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 1019 | |
Harald Welte | 09e38af | 2009-02-16 22:52:23 +0000 | [diff] [blame^] | 1020 | int gsm48_cc_tx_setup(struct gsm_lchan *lchan, |
| 1021 | struct gsm_subscriber *calling_subscriber) |
Harald Welte | 65e74cc | 2008-12-29 01:55:35 +0000 | [diff] [blame] | 1022 | { |
| 1023 | struct msgb *msg = gsm48_msgb_alloc(); |
| 1024 | struct gsm48_hdr *gh; |
| 1025 | struct gsm_call *call = &lchan->call; |
| 1026 | |
Harald Welte | 7584aea | 2009-02-11 11:44:12 +0000 | [diff] [blame] | 1027 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 4 + |
| 1028 | sizeof(calling_bcd)); |
Harald Welte | 65e74cc | 2008-12-29 01:55:35 +0000 | [diff] [blame] | 1029 | |
| 1030 | call->type = GSM_CT_MT; |
| 1031 | msg->lchan = lchan; |
Harald Welte | 498b0bb | 2009-01-09 21:27:43 +0000 | [diff] [blame] | 1032 | use_lchan(lchan); |
Harald Welte | 65e74cc | 2008-12-29 01:55:35 +0000 | [diff] [blame] | 1033 | |
| 1034 | gh->proto_discr = GSM48_PDISC_CC; |
| 1035 | gh->msg_type = GSM48_MT_CC_SETUP; |
Harald Welte | 09e38af | 2009-02-16 22:52:23 +0000 | [diff] [blame^] | 1036 | |
| 1037 | /* FIXME: use actual number of the caller */ |
Harald Welte | 7584aea | 2009-02-11 11:44:12 +0000 | [diff] [blame] | 1038 | msgb_tv_put(msg, GSM48_IE_SIGNAL, GSM48_SIGNAL_DIALTONE); |
| 1039 | msgb_tlv_put(msg, GSM48_IE_CALLING_BCD, |
| 1040 | sizeof(calling_bcd), calling_bcd); |
Harald Welte | 65e74cc | 2008-12-29 01:55:35 +0000 | [diff] [blame] | 1041 | |
| 1042 | DEBUGP(DCC, "Sending SETUP\n"); |
| 1043 | |
| 1044 | return gsm48_sendmsg(msg); |
| 1045 | } |
| 1046 | |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 1047 | static int gsm0408_rcv_cc(struct msgb *msg) |
| 1048 | { |
| 1049 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 1050 | u_int8_t msg_type = gh->msg_type & 0xbf; |
| 1051 | struct gsm_call *call = &msg->lchan->call; |
| 1052 | int rc = 0; |
| 1053 | |
| 1054 | switch (msg_type) { |
| 1055 | case GSM48_MT_CC_CALL_CONF: |
| 1056 | /* Response to SETUP */ |
| 1057 | DEBUGP(DCC, "CALL CONFIRM\n"); |
Harald Welte | 09e38af | 2009-02-16 22:52:23 +0000 | [diff] [blame^] | 1058 | /* FIXME: we now need to MODIFY the channel */ |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 1059 | break; |
| 1060 | case GSM48_MT_CC_RELEASE_COMPL: |
| 1061 | /* Answer from MS to RELEASE */ |
| 1062 | DEBUGP(DCC, "RELEASE COMPLETE (state->NULL)\n"); |
| 1063 | call->state = GSM_CSTATE_NULL; |
| 1064 | break; |
| 1065 | case GSM48_MT_CC_ALERTING: |
| 1066 | DEBUGP(DCC, "ALERTING\n"); |
Harald Welte | 09e38af | 2009-02-16 22:52:23 +0000 | [diff] [blame^] | 1067 | /* FIXME: forward ALERTING to other party */ |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 1068 | break; |
| 1069 | case GSM48_MT_CC_CONNECT: |
| 1070 | DEBUGP(DCC, "CONNECT\n"); |
| 1071 | /* MT: need to respond with CONNECT_ACK */ |
Harald Welte | 6f4b753 | 2008-12-29 00:39:37 +0000 | [diff] [blame] | 1072 | rc = gsm48_tx_simple(msg->lchan, GSM48_PDISC_CC, |
| 1073 | GSM48_MT_CC_CONNECT_ACK); |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 1074 | break; |
| 1075 | case GSM48_MT_CC_CONNECT_ACK: |
| 1076 | /* MO: Answer to CONNECT */ |
| 1077 | call->state = GSM_CSTATE_ACTIVE; |
| 1078 | DEBUGP(DCC, "CONNECT_ACK (state->ACTIVE)\n"); |
| 1079 | break; |
| 1080 | case GSM48_MT_CC_RELEASE: |
| 1081 | DEBUGP(DCC, "RELEASE\n"); |
| 1082 | /* need to respond with RELEASE_COMPLETE */ |
| 1083 | break; |
| 1084 | case GSM48_MT_CC_STATUS_ENQ: |
| 1085 | rc = gsm48_cc_rx_status_enq(msg); |
| 1086 | break; |
| 1087 | case GSM48_MT_CC_DISCONNECT: |
| 1088 | /* Section 5.4.3.2 */ |
| 1089 | DEBUGP(DCC, "DISCONNECT (state->RELEASE_REQ)\n"); |
| 1090 | call->state = GSM_CSTATE_RELEASE_REQ; |
Harald Welte | 498b0bb | 2009-01-09 21:27:43 +0000 | [diff] [blame] | 1091 | if (call->state != GSM_CSTATE_NULL) |
| 1092 | put_lchan(msg->lchan); |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 1093 | /* FIXME: clear the network connection */ |
Harald Welte | 6f4b753 | 2008-12-29 00:39:37 +0000 | [diff] [blame] | 1094 | rc = gsm48_tx_simple(msg->lchan, GSM48_PDISC_CC, |
| 1095 | GSM48_MT_CC_RELEASE); |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 1096 | break; |
| 1097 | case GSM48_MT_CC_SETUP: |
Harald Welte | 7584aea | 2009-02-11 11:44:12 +0000 | [diff] [blame] | 1098 | rc = gsm48_cc_rx_setup(msg); |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 1099 | break; |
| 1100 | case GSM48_MT_CC_EMERG_SETUP: |
| 1101 | DEBUGP(DCC, "EMERGENCY SETUP\n"); |
| 1102 | /* FIXME: continue with CALL_PROCEEDING, ALERTING, CONNECT, RELEASE_COMPLETE */ |
| 1103 | break; |
| 1104 | default: |
Harald Welte | 2d35ae6 | 2009-02-06 12:02:13 +0000 | [diff] [blame] | 1105 | fprintf(stderr, "Unimplemented GSM 04.08 CC msg type 0x%02x\n", |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 1106 | msg_type); |
| 1107 | break; |
| 1108 | } |
| 1109 | |
| 1110 | return rc; |
| 1111 | } |
| 1112 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1113 | /* here we pass in a msgb from the RSL->RLL. We expect the l3 pointer to be set */ |
| 1114 | int gsm0408_rcvmsg(struct msgb *msg) |
| 1115 | { |
| 1116 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 1117 | u_int8_t pdisc = gh->proto_discr & 0x0f; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 1118 | int rc = 0; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1119 | |
| 1120 | switch (pdisc) { |
| 1121 | case GSM48_PDISC_CC: |
| 1122 | rc = gsm0408_rcv_cc(msg); |
| 1123 | break; |
| 1124 | case GSM48_PDISC_MM: |
| 1125 | rc = gsm0408_rcv_mm(msg); |
| 1126 | break; |
| 1127 | case GSM48_PDISC_RR: |
| 1128 | rc = gsm0408_rcv_rr(msg); |
| 1129 | break; |
Harald Welte | bcae43f | 2008-12-27 21:45:37 +0000 | [diff] [blame] | 1130 | case GSM48_PDISC_SMS: |
Daniel Willmann | 8b3390e | 2008-12-28 00:31:09 +0000 | [diff] [blame] | 1131 | rc = gsm0411_rcv_sms(msg); |
Harald Welte | bcae43f | 2008-12-27 21:45:37 +0000 | [diff] [blame] | 1132 | break; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1133 | case GSM48_PDISC_MM_GPRS: |
Harald Welte | bcae43f | 2008-12-27 21:45:37 +0000 | [diff] [blame] | 1134 | case GSM48_PDISC_SM_GPRS: |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1135 | fprintf(stderr, "Unimplemented GSM 04.08 discriminator 0x%02d\n", |
| 1136 | pdisc); |
| 1137 | break; |
| 1138 | default: |
| 1139 | fprintf(stderr, "Unknown GSM 04.08 discriminator 0x%02d\n", |
| 1140 | pdisc); |
| 1141 | break; |
| 1142 | } |
| 1143 | |
| 1144 | return rc; |
| 1145 | } |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 1146 | |
| 1147 | enum chreq_type { |
| 1148 | CHREQ_T_EMERG_CALL, |
| 1149 | CHREQ_T_CALL_REEST_TCH_F, |
| 1150 | CHREQ_T_CALL_REEST_TCH_H, |
| 1151 | CHREQ_T_CALL_REEST_TCH_H_DBL, |
| 1152 | CHREQ_T_SDCCH, |
| 1153 | CHREQ_T_TCH_F, |
| 1154 | CHREQ_T_VOICE_CALL_TCH_H, |
| 1155 | CHREQ_T_DATA_CALL_TCH_H, |
| 1156 | CHREQ_T_LOCATION_UPD, |
| 1157 | CHREQ_T_PAG_R_ANY, |
| 1158 | CHREQ_T_PAG_R_TCH_F, |
| 1159 | CHREQ_T_PAG_R_TCH_FH, |
| 1160 | }; |
| 1161 | |
| 1162 | /* Section 9.1.8 / Table 9.9 */ |
| 1163 | struct chreq { |
| 1164 | u_int8_t val; |
| 1165 | u_int8_t mask; |
| 1166 | enum chreq_type type; |
| 1167 | }; |
| 1168 | |
| 1169 | /* If SYSTEM INFORMATION TYPE 4 NECI bit == 1 */ |
| 1170 | static const struct chreq chreq_type_neci1[] = { |
| 1171 | { 0xa0, 0xe0, CHREQ_T_EMERG_CALL }, |
| 1172 | { 0xc0, 0xe0, CHREQ_T_CALL_REEST_TCH_F }, |
| 1173 | { 0x68, 0xfc, CHREQ_T_CALL_REEST_TCH_H }, |
| 1174 | { 0x6c, 0xfc, CHREQ_T_CALL_REEST_TCH_H_DBL }, |
| 1175 | { 0xe0, 0xe0, CHREQ_T_SDCCH }, |
| 1176 | { 0x40, 0xf0, CHREQ_T_VOICE_CALL_TCH_H }, |
| 1177 | { 0x50, 0xf0, CHREQ_T_DATA_CALL_TCH_H }, |
| 1178 | { 0x00, 0xf0, CHREQ_T_LOCATION_UPD }, |
| 1179 | { 0x10, 0xf0, CHREQ_T_SDCCH }, |
| 1180 | { 0x80, 0xe0, CHREQ_T_PAG_R_ANY }, |
| 1181 | { 0x20, 0xf0, CHREQ_T_PAG_R_TCH_F }, |
| 1182 | { 0x30, 0xf0, CHREQ_T_PAG_R_TCH_FH }, |
| 1183 | }; |
| 1184 | |
| 1185 | /* If SYSTEM INFORMATION TYPE 4 NECI bit == 0 */ |
| 1186 | static const struct chreq chreq_type_neci0[] = { |
| 1187 | { 0xa0, 0xe0, CHREQ_T_EMERG_CALL }, |
| 1188 | { 0xc0, 0xe0, CHREQ_T_CALL_REEST_TCH_H }, |
| 1189 | { 0xe0, 0xe0, CHREQ_T_TCH_F }, |
| 1190 | { 0x50, 0xf0, CHREQ_T_DATA_CALL_TCH_H }, |
| 1191 | { 0x00, 0xe0, CHREQ_T_LOCATION_UPD }, |
| 1192 | { 0x80, 0xe0, CHREQ_T_PAG_R_ANY }, |
| 1193 | { 0x20, 0xf0, CHREQ_T_PAG_R_TCH_F }, |
| 1194 | { 0x30, 0xf0, CHREQ_T_PAG_R_TCH_FH }, |
| 1195 | }; |
| 1196 | |
| 1197 | static const enum gsm_chan_t ctype_by_chreq[] = { |
| 1198 | [CHREQ_T_EMERG_CALL] = GSM_LCHAN_TCH_F, |
| 1199 | [CHREQ_T_CALL_REEST_TCH_F] = GSM_LCHAN_TCH_F, |
| 1200 | [CHREQ_T_CALL_REEST_TCH_H] = GSM_LCHAN_TCH_H, |
| 1201 | [CHREQ_T_CALL_REEST_TCH_H_DBL] = GSM_LCHAN_TCH_H, |
| 1202 | [CHREQ_T_SDCCH] = GSM_LCHAN_SDCCH, |
| 1203 | [CHREQ_T_TCH_F] = GSM_LCHAN_TCH_F, |
| 1204 | [CHREQ_T_VOICE_CALL_TCH_H] = GSM_LCHAN_TCH_H, |
| 1205 | [CHREQ_T_DATA_CALL_TCH_H] = GSM_LCHAN_TCH_H, |
| 1206 | [CHREQ_T_LOCATION_UPD] = GSM_LCHAN_SDCCH, |
| 1207 | [CHREQ_T_PAG_R_ANY] = GSM_LCHAN_SDCCH, |
| 1208 | [CHREQ_T_PAG_R_TCH_F] = GSM_LCHAN_TCH_F, |
| 1209 | [CHREQ_T_PAG_R_TCH_FH] = GSM_LCHAN_TCH_F, |
| 1210 | }; |
| 1211 | |
Harald Welte | e14a57c | 2008-12-29 04:08:28 +0000 | [diff] [blame] | 1212 | static const enum gsm_chreq_reason_t reason_by_chreq[] = { |
| 1213 | [CHREQ_T_EMERG_CALL] = GSM_CHREQ_REASON_EMERG, |
| 1214 | [CHREQ_T_CALL_REEST_TCH_F] = GSM_CHREQ_REASON_CALL, |
| 1215 | [CHREQ_T_CALL_REEST_TCH_H] = GSM_CHREQ_REASON_CALL, |
| 1216 | [CHREQ_T_CALL_REEST_TCH_H_DBL] = GSM_CHREQ_REASON_CALL, |
| 1217 | [CHREQ_T_SDCCH] = GSM_CHREQ_REASON_OTHER, |
| 1218 | [CHREQ_T_TCH_F] = GSM_CHREQ_REASON_OTHER, |
| 1219 | [CHREQ_T_VOICE_CALL_TCH_H] = GSM_CHREQ_REASON_OTHER, |
| 1220 | [CHREQ_T_DATA_CALL_TCH_H] = GSM_CHREQ_REASON_OTHER, |
| 1221 | [CHREQ_T_LOCATION_UPD] = GSM_CHREQ_REASON_LOCATION_UPD, |
| 1222 | [CHREQ_T_PAG_R_ANY] = GSM_CHREQ_REASON_PAG, |
| 1223 | [CHREQ_T_PAG_R_TCH_F] = GSM_CHREQ_REASON_PAG, |
| 1224 | [CHREQ_T_PAG_R_TCH_FH] = GSM_CHREQ_REASON_PAG, |
| 1225 | }; |
| 1226 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 1227 | enum gsm_chan_t get_ctype_by_chreq(struct gsm_bts *bts, u_int8_t ra) |
| 1228 | { |
| 1229 | int i; |
| 1230 | /* FIXME: determine if we set NECI = 0 in the BTS SI4 */ |
| 1231 | |
| 1232 | for (i = 0; i < ARRAY_SIZE(chreq_type_neci0); i++) { |
| 1233 | const struct chreq *chr = &chreq_type_neci0[i]; |
| 1234 | if ((ra & chr->mask) == chr->val) |
| 1235 | return ctype_by_chreq[chr->type]; |
| 1236 | } |
| 1237 | fprintf(stderr, "Unknown CHANNEL REQUEST RQD 0x%02x\n", ra); |
| 1238 | return GSM_LCHAN_SDCCH; |
| 1239 | } |
Harald Welte | e14a57c | 2008-12-29 04:08:28 +0000 | [diff] [blame] | 1240 | |
| 1241 | enum gsm_chreq_reason_t get_reason_by_chreq(struct gsm_bts *bts, u_int8_t ra) |
| 1242 | { |
| 1243 | int i; |
| 1244 | /* FIXME: determine if we set NECI = 0 in the BTS SI4 */ |
| 1245 | |
| 1246 | for (i = 0; i < ARRAY_SIZE(chreq_type_neci0); i++) { |
| 1247 | const struct chreq *chr = &chreq_type_neci0[i]; |
| 1248 | if ((ra & chr->mask) == chr->val) |
| 1249 | return reason_by_chreq[chr->type]; |
| 1250 | } |
| 1251 | fprintf(stderr, "Unknown CHANNEL REQUEST REASON 0x%02x\n", ra); |
| 1252 | return GSM_CHREQ_REASON_OTHER; |
| 1253 | } |