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