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