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 | f1dae19 | 2009-12-14 22:24:28 +0100 | [diff] [blame] | 35 | #include <openbsc/bitvec.h> |
Harald Welte | 7584aea | 2009-02-11 11:44:12 +0000 | [diff] [blame] | 36 | #include <openbsc/tlv.h> |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 37 | #include <openbsc/debug.h> |
| 38 | #include <openbsc/gsm_data.h> |
Daniel Willmann | eea9337 | 2009-08-13 03:42:07 +0200 | [diff] [blame] | 39 | #include <openbsc/gsm_utils.h> |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 40 | #include <openbsc/gsm_subscriber.h> |
Daniel Willmann | 8b3390e | 2008-12-28 00:31:09 +0000 | [diff] [blame] | 41 | #include <openbsc/gsm_04_11.h> |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 42 | #include <openbsc/gsm_04_08.h> |
| 43 | #include <openbsc/abis_rsl.h> |
Holger Freyther | ca362a6 | 2009-01-04 21:05:01 +0000 | [diff] [blame] | 44 | #include <openbsc/chan_alloc.h> |
Harald Welte | 0b4c34e | 2009-02-09 17:54:43 +0000 | [diff] [blame] | 45 | #include <openbsc/paging.h> |
Holger Freyther | 053e09d | 2009-02-14 22:51:06 +0000 | [diff] [blame] | 46 | #include <openbsc/signal.h> |
Harald Welte | 45b407a | 2009-05-23 15:51:12 +0000 | [diff] [blame] | 47 | #include <openbsc/trau_frame.h> |
Harald Welte | 11fa29c | 2009-02-19 17:24:39 +0000 | [diff] [blame] | 48 | #include <openbsc/trau_mux.h> |
Harald Welte | 805f644 | 2009-07-28 18:25:29 +0200 | [diff] [blame] | 49 | #include <openbsc/rtp_proxy.h> |
Harald Welte | 2cf161b | 2009-06-20 22:36:41 +0200 | [diff] [blame] | 50 | #include <openbsc/talloc.h> |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 51 | #include <openbsc/transaction.h> |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 52 | #include <openbsc/ussd.h> |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 53 | |
Harald Welte | 0c38930 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 54 | #define GSM_MAX_FACILITY 128 |
| 55 | #define GSM_MAX_SSVERSION 128 |
| 56 | #define GSM_MAX_USERUSER 128 |
| 57 | |
Harald Welte (local) | d19e58b | 2009-08-15 02:30:58 +0200 | [diff] [blame] | 58 | void *tall_locop_ctx; |
Harald Welte | 2cf161b | 2009-06-20 22:36:41 +0200 | [diff] [blame] | 59 | |
Holger Hans Peter Freyther | 1494a76 | 2009-08-01 07:26:59 +0200 | [diff] [blame] | 60 | extern int ipacc_rtp_direct; |
Harald Welte | 805f644 | 2009-07-28 18:25:29 +0200 | [diff] [blame] | 61 | |
Harald Welte | 09e38af | 2009-02-16 22:52:23 +0000 | [diff] [blame] | 62 | static const struct tlv_definition rsl_att_tlvdef = { |
| 63 | .def = { |
| 64 | [GSM48_IE_MOBILE_ID] = { TLV_TYPE_TLV }, |
| 65 | [GSM48_IE_NAME_LONG] = { TLV_TYPE_TLV }, |
| 66 | [GSM48_IE_NAME_SHORT] = { TLV_TYPE_TLV }, |
| 67 | [GSM48_IE_UTC] = { TLV_TYPE_TV }, |
| 68 | [GSM48_IE_NET_TIME_TZ] = { TLV_TYPE_FIXED, 7 }, |
| 69 | [GSM48_IE_LSA_IDENT] = { TLV_TYPE_TLV }, |
| 70 | |
| 71 | [GSM48_IE_BEARER_CAP] = { TLV_TYPE_TLV }, |
| 72 | [GSM48_IE_CAUSE] = { TLV_TYPE_TLV }, |
| 73 | [GSM48_IE_CC_CAP] = { TLV_TYPE_TLV }, |
| 74 | [GSM48_IE_ALERT] = { TLV_TYPE_TLV }, |
| 75 | [GSM48_IE_FACILITY] = { TLV_TYPE_TLV }, |
| 76 | [GSM48_IE_PROGR_IND] = { TLV_TYPE_TLV }, |
| 77 | [GSM48_IE_AUX_STATUS] = { TLV_TYPE_TLV }, |
Harald Welte | 0c38930 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 78 | [GSM48_IE_NOTIFY] = { TLV_TYPE_TV }, |
Harald Welte | 09e38af | 2009-02-16 22:52:23 +0000 | [diff] [blame] | 79 | [GSM48_IE_KPD_FACILITY] = { TLV_TYPE_TV }, |
| 80 | [GSM48_IE_SIGNAL] = { TLV_TYPE_TV }, |
Harald Welte | 0c38930 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 81 | [GSM48_IE_CONN_BCD] = { TLV_TYPE_TLV }, |
| 82 | [GSM48_IE_CONN_SUB] = { TLV_TYPE_TLV }, |
Harald Welte | 09e38af | 2009-02-16 22:52:23 +0000 | [diff] [blame] | 83 | [GSM48_IE_CALLING_BCD] = { TLV_TYPE_TLV }, |
| 84 | [GSM48_IE_CALLING_SUB] = { TLV_TYPE_TLV }, |
| 85 | [GSM48_IE_CALLED_BCD] = { TLV_TYPE_TLV }, |
| 86 | [GSM48_IE_CALLED_SUB] = { TLV_TYPE_TLV }, |
| 87 | [GSM48_IE_REDIR_BCD] = { TLV_TYPE_TLV }, |
| 88 | [GSM48_IE_REDIR_SUB] = { TLV_TYPE_TLV }, |
| 89 | [GSM48_IE_LOWL_COMPAT] = { TLV_TYPE_TLV }, |
| 90 | [GSM48_IE_HIGHL_COMPAT] = { TLV_TYPE_TLV }, |
| 91 | [GSM48_IE_USER_USER] = { TLV_TYPE_TLV }, |
| 92 | [GSM48_IE_SS_VERS] = { TLV_TYPE_TLV }, |
| 93 | [GSM48_IE_MORE_DATA] = { TLV_TYPE_T }, |
| 94 | [GSM48_IE_CLIR_SUPP] = { TLV_TYPE_T }, |
| 95 | [GSM48_IE_CLIR_INVOC] = { TLV_TYPE_T }, |
| 96 | [GSM48_IE_REV_C_SETUP] = { TLV_TYPE_T }, |
Harald Welte | 0c38930 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 97 | [GSM48_IE_REPEAT_CIR] = { TLV_TYPE_T }, |
| 98 | [GSM48_IE_REPEAT_SEQ] = { TLV_TYPE_T }, |
Harald Welte | 09e38af | 2009-02-16 22:52:23 +0000 | [diff] [blame] | 99 | /* FIXME: more elements */ |
| 100 | }, |
| 101 | }; |
Harald Welte | cf5b359 | 2009-05-01 18:28:42 +0000 | [diff] [blame] | 102 | |
| 103 | static const char *rr_cause_names[] = { |
| 104 | [GSM48_RR_CAUSE_NORMAL] = "Normal event", |
| 105 | [GSM48_RR_CAUSE_ABNORMAL_UNSPEC] = "Abnormal release, unspecified", |
| 106 | [GSM48_RR_CAUSE_ABNORMAL_UNACCT] = "Abnormal release, channel unacceptable", |
| 107 | [GSM48_RR_CAUSE_ABNORMAL_TIMER] = "Abnormal release, timer expired", |
| 108 | [GSM48_RR_CAUSE_ABNORMAL_NOACT] = "Abnormal release, no activity on radio path", |
| 109 | [GSM48_RR_CAUSE_PREMPTIVE_REL] = "Preemptive release", |
| 110 | [GSM48_RR_CAUSE_HNDOVER_IMP] = "Handover impossible, timing advance out of range", |
| 111 | [GSM48_RR_CAUSE_CHAN_MODE_UNACCT] = "Channel mode unacceptable", |
| 112 | [GSM48_RR_CAUSE_FREQ_NOT_IMPL] = "Frequency not implemented", |
| 113 | [GSM48_RR_CAUSE_CALL_CLEARED] = "Call already cleared", |
| 114 | [GSM48_RR_CAUSE_SEMANT_INCORR] = "Semantically incorrect message", |
| 115 | [GSM48_RR_CAUSE_INVALID_MAND_INF] = "Invalid mandatory information", |
| 116 | [GSM48_RR_CAUSE_MSG_TYPE_N] = "Message type non-existant or not implemented", |
| 117 | [GSM48_RR_CAUSE_MSG_TYPE_N_COMPAT] = "Message type not compatible with protocol state", |
| 118 | [GSM48_RR_CAUSE_COND_IE_ERROR] = "Conditional IE error", |
| 119 | [GSM48_RR_CAUSE_NO_CELL_ALLOC_A] = "No cell allocation available", |
| 120 | [GSM48_RR_CAUSE_PROT_ERROR_UNSPC] = "Protocol error unspecified", |
| 121 | }; |
| 122 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 123 | static const char *cc_state_names[] = { |
| 124 | "NULL", |
| 125 | "INITIATED", |
| 126 | "illegal state 2", |
| 127 | "MO_CALL_PROC", |
| 128 | "CALL_DELIVERED", |
| 129 | "illegal state 5", |
| 130 | "CALL_PRESENT", |
| 131 | "CALL_RECEIVED", |
| 132 | "CONNECT_REQUEST", |
| 133 | "MO_TERM_CALL_CONF", |
| 134 | "ACTIVE", |
| 135 | "DISCONNECT_REQ", |
| 136 | "DISCONNECT_IND", |
| 137 | "illegal state 13", |
| 138 | "illegal state 14", |
| 139 | "illegal state 15", |
| 140 | "illegal state 16", |
| 141 | "illegal state 17", |
| 142 | "illegal state 18", |
| 143 | "RELEASE_REQ", |
| 144 | "illegal state 20", |
| 145 | "illegal state 21", |
| 146 | "illegal state 22", |
| 147 | "illegal state 23", |
| 148 | "illegal state 24", |
| 149 | "illegal state 25", |
| 150 | "MO_ORIG_MODIFY", |
| 151 | "MO_TERM_MODIFY", |
| 152 | "CONNECT_IND", |
| 153 | "illegal state 29", |
| 154 | "illegal state 30", |
| 155 | "illegal state 31", |
| 156 | }; |
| 157 | |
Harald Welte | cf5b359 | 2009-05-01 18:28:42 +0000 | [diff] [blame] | 158 | static char strbuf[64]; |
| 159 | |
| 160 | static const char *rr_cause_name(u_int8_t cause) |
| 161 | { |
| 162 | if (cause < ARRAY_SIZE(rr_cause_names) && |
| 163 | rr_cause_names[cause]) |
| 164 | return rr_cause_names[cause]; |
| 165 | |
| 166 | snprintf(strbuf, sizeof(strbuf), "0x%02x", cause); |
| 167 | return strbuf; |
| 168 | } |
| 169 | |
Harald Welte | 3c7dc6e | 2009-11-29 19:07:28 +0100 | [diff] [blame] | 170 | int gsm48_parse_meas_rep(struct gsm_meas_rep *rep, struct msgb *msg) |
Harald Welte | f7c4352 | 2009-06-09 20:24:21 +0000 | [diff] [blame] | 171 | { |
Harald Welte | 3c7dc6e | 2009-11-29 19:07:28 +0100 | [diff] [blame] | 172 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 173 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 174 | u_int8_t *data = gh->data; |
Harald Welte | f1dae19 | 2009-12-14 22:24:28 +0100 | [diff] [blame] | 175 | struct gsm_bts *bts = msg->lchan->ts->trx->bts; |
| 176 | struct bitvec *nbv = &bts->si_common.neigh_list; |
Harald Welte | 3c7dc6e | 2009-11-29 19:07:28 +0100 | [diff] [blame] | 177 | |
| 178 | if (gh->msg_type != GSM48_MT_RR_MEAS_REP) |
| 179 | return -EINVAL; |
Harald Welte | f7c4352 | 2009-06-09 20:24:21 +0000 | [diff] [blame] | 180 | |
| 181 | if (data[0] & 0x80) |
| 182 | rep->flags |= MEAS_REP_F_BA1; |
| 183 | if (data[0] & 0x40) |
Harald Welte | 3c7dc6e | 2009-11-29 19:07:28 +0100 | [diff] [blame] | 184 | rep->flags |= MEAS_REP_F_UL_DTX; |
Harald Welte | 5a691b5 | 2009-07-05 04:05:44 +0200 | [diff] [blame] | 185 | if ((data[1] & 0x40) == 0x00) |
Harald Welte | 3c7dc6e | 2009-11-29 19:07:28 +0100 | [diff] [blame] | 186 | rep->flags |= MEAS_REP_F_DL_VALID; |
Harald Welte | f7c4352 | 2009-06-09 20:24:21 +0000 | [diff] [blame] | 187 | |
Harald Welte | 3c7dc6e | 2009-11-29 19:07:28 +0100 | [diff] [blame] | 188 | rep->dl.full.rx_lev = data[0] & 0x3f; |
| 189 | rep->dl.sub.rx_lev = data[1] & 0x3f; |
| 190 | rep->dl.full.rx_qual = (data[3] >> 4) & 0x7; |
| 191 | rep->dl.sub.rx_qual = (data[3] >> 1) & 0x7; |
| 192 | |
Harald Welte | a2f74b8 | 2009-12-16 16:49:21 +0100 | [diff] [blame] | 193 | rep->num_cell = ((data[3] >> 6) & 0x3) | ((data[2] & 0x01) << 2); |
Harald Welte | f7c4352 | 2009-06-09 20:24:21 +0000 | [diff] [blame] | 194 | if (rep->num_cell < 1) |
Harald Welte | 3c7dc6e | 2009-11-29 19:07:28 +0100 | [diff] [blame] | 195 | return 0; |
Harald Welte | f7c4352 | 2009-06-09 20:24:21 +0000 | [diff] [blame] | 196 | |
| 197 | /* an encoding nightmare in perfection */ |
| 198 | |
Harald Welte | a2f74b8 | 2009-12-16 16:49:21 +0100 | [diff] [blame] | 199 | rep->cell[0].rxlev = data[3] & 0x3f; |
| 200 | rep->cell[0].arfcn = bitvec_get_nth_set_bit(nbv, data[4] >> 2); |
Harald Welte | 73ddaed | 2009-12-16 23:29:12 +0100 | [diff] [blame] | 201 | rep->cell[0].bsic = ((data[4] & 0x07) << 3) | (data[5] >> 5); |
Harald Welte | f7c4352 | 2009-06-09 20:24:21 +0000 | [diff] [blame] | 202 | if (rep->num_cell < 2) |
Harald Welte | 3c7dc6e | 2009-11-29 19:07:28 +0100 | [diff] [blame] | 203 | return 0; |
Harald Welte | f7c4352 | 2009-06-09 20:24:21 +0000 | [diff] [blame] | 204 | |
Harald Welte | a2f74b8 | 2009-12-16 16:49:21 +0100 | [diff] [blame] | 205 | rep->cell[1].rxlev = ((data[5] & 0x1f) << 1) | (data[6] >> 7); |
| 206 | rep->cell[1].arfcn = bitvec_get_nth_set_bit(nbv, (data[6] >> 2) & 0x1f); |
| 207 | rep->cell[1].bsic = ((data[6] & 0x03) << 4) | (data[7] >> 4); |
Harald Welte | f7c4352 | 2009-06-09 20:24:21 +0000 | [diff] [blame] | 208 | if (rep->num_cell < 3) |
Harald Welte | 3c7dc6e | 2009-11-29 19:07:28 +0100 | [diff] [blame] | 209 | return 0; |
Harald Welte | f7c4352 | 2009-06-09 20:24:21 +0000 | [diff] [blame] | 210 | |
Harald Welte | a2f74b8 | 2009-12-16 16:49:21 +0100 | [diff] [blame] | 211 | rep->cell[2].rxlev = ((data[7] & 0x0f) << 2) | (data[8] >> 6); |
| 212 | rep->cell[2].arfcn = bitvec_get_nth_set_bit(nbv, (data[8] >> 1) & 0x1f); |
| 213 | rep->cell[2].bsic = ((data[8] & 0x01) << 6) | (data[9] >> 3); |
Harald Welte | f7c4352 | 2009-06-09 20:24:21 +0000 | [diff] [blame] | 214 | if (rep->num_cell < 4) |
Harald Welte | 3c7dc6e | 2009-11-29 19:07:28 +0100 | [diff] [blame] | 215 | return 0; |
Harald Welte | f7c4352 | 2009-06-09 20:24:21 +0000 | [diff] [blame] | 216 | |
Harald Welte | a2f74b8 | 2009-12-16 16:49:21 +0100 | [diff] [blame] | 217 | rep->cell[3].rxlev = ((data[9] & 0x07) << 3) | (data[10] >> 5); |
| 218 | rep->cell[3].arfcn = bitvec_get_nth_set_bit(nbv, data[10] & 0x1f); |
| 219 | rep->cell[3].bsic = data[11] >> 2; |
Harald Welte | f7c4352 | 2009-06-09 20:24:21 +0000 | [diff] [blame] | 220 | if (rep->num_cell < 5) |
Harald Welte | 3c7dc6e | 2009-11-29 19:07:28 +0100 | [diff] [blame] | 221 | return 0; |
Harald Welte | f7c4352 | 2009-06-09 20:24:21 +0000 | [diff] [blame] | 222 | |
Harald Welte | a2f74b8 | 2009-12-16 16:49:21 +0100 | [diff] [blame] | 223 | rep->cell[4].rxlev = ((data[11] & 0x03) << 4) | (data[12] >> 4); |
Harald Welte | f1dae19 | 2009-12-14 22:24:28 +0100 | [diff] [blame] | 224 | rep->cell[4].arfcn = bitvec_get_nth_set_bit(nbv, |
Harald Welte | a2f74b8 | 2009-12-16 16:49:21 +0100 | [diff] [blame] | 225 | ((data[12] & 0xf) << 1) | (data[13] >> 7)); |
| 226 | rep->cell[4].bsic = (data[13] >> 1) & 0x3f; |
Harald Welte | f7c4352 | 2009-06-09 20:24:21 +0000 | [diff] [blame] | 227 | if (rep->num_cell < 6) |
Harald Welte | 3c7dc6e | 2009-11-29 19:07:28 +0100 | [diff] [blame] | 228 | return 0; |
Harald Welte | f7c4352 | 2009-06-09 20:24:21 +0000 | [diff] [blame] | 229 | |
Harald Welte | a2f74b8 | 2009-12-16 16:49:21 +0100 | [diff] [blame] | 230 | rep->cell[5].rxlev = ((data[13] & 0x01) << 5) | (data[14] >> 3); |
Harald Welte | f1dae19 | 2009-12-14 22:24:28 +0100 | [diff] [blame] | 231 | rep->cell[5].arfcn = bitvec_get_nth_set_bit(nbv, |
Harald Welte | a2f74b8 | 2009-12-16 16:49:21 +0100 | [diff] [blame] | 232 | ((data[14] & 0x07) << 2) | (data[15] >> 6)); |
| 233 | rep->cell[5].bsic = data[15] & 0x3f; |
Harald Welte | 3c7dc6e | 2009-11-29 19:07:28 +0100 | [diff] [blame] | 234 | |
| 235 | return 0; |
Harald Welte | f7c4352 | 2009-06-09 20:24:21 +0000 | [diff] [blame] | 236 | } |
| 237 | |
Holger Freyther | d51524f | 2009-06-09 08:27:07 +0000 | [diff] [blame] | 238 | int gsm0408_loc_upd_acc(struct gsm_lchan *lchan, u_int32_t tmsi); |
Harald Welte | 65e74cc | 2008-12-29 01:55:35 +0000 | [diff] [blame] | 239 | static int gsm48_tx_simple(struct gsm_lchan *lchan, |
| 240 | u_int8_t pdisc, u_int8_t msg_type); |
Holger Freyther | b7193e4 | 2008-12-29 17:44:08 +0000 | [diff] [blame] | 241 | static void schedule_reject(struct gsm_lchan *lchan); |
Harald Welte | 65e74cc | 2008-12-29 01:55:35 +0000 | [diff] [blame] | 242 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 243 | struct gsm_lai { |
| 244 | u_int16_t mcc; |
| 245 | u_int16_t mnc; |
| 246 | u_int16_t lac; |
| 247 | }; |
| 248 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 249 | static u_int32_t new_callref = 0x80000001; |
| 250 | |
Holger Freyther | 73487a2 | 2008-12-31 18:53:57 +0000 | [diff] [blame] | 251 | static int authorize_subscriber(struct gsm_loc_updating_operation *loc, |
| 252 | struct gsm_subscriber *subscriber) |
Holger Freyther | 89824fc | 2008-12-30 16:18:18 +0000 | [diff] [blame] | 253 | { |
| 254 | if (!subscriber) |
| 255 | return 0; |
| 256 | |
Holger Freyther | 73487a2 | 2008-12-31 18:53:57 +0000 | [diff] [blame] | 257 | /* |
| 258 | * Do not send accept yet as more information should arrive. Some |
| 259 | * phones will not send us the information and we will have to check |
| 260 | * what we want to do with that. |
| 261 | */ |
| 262 | if (loc && (loc->waiting_for_imsi || loc->waiting_for_imei)) |
| 263 | return 0; |
| 264 | |
Jan Luebbe | 06513f2 | 2009-08-12 12:48:00 +0200 | [diff] [blame] | 265 | switch (subscriber->net->auth_policy) { |
| 266 | case GSM_AUTH_POLICY_CLOSED: |
| 267 | return subscriber->authorized; |
Harald Welte (local) | aa9dc19 | 2009-08-13 13:49:51 +0200 | [diff] [blame] | 268 | case GSM_AUTH_POLICY_TOKEN: |
Harald Welte (local) | ee9afe3 | 2009-08-13 20:44:23 +0200 | [diff] [blame] | 269 | if (subscriber->authorized) |
| 270 | return subscriber->authorized; |
Harald Welte (local) | aa9dc19 | 2009-08-13 13:49:51 +0200 | [diff] [blame] | 271 | return (subscriber->flags & GSM_SUBSCRIBER_FIRST_CONTACT); |
Jan Luebbe | 06513f2 | 2009-08-12 12:48:00 +0200 | [diff] [blame] | 272 | case GSM_AUTH_POLICY_ACCEPT_ALL: |
Holger Freyther | 89824fc | 2008-12-30 16:18:18 +0000 | [diff] [blame] | 273 | return 1; |
Jan Luebbe | 06513f2 | 2009-08-12 12:48:00 +0200 | [diff] [blame] | 274 | default: |
| 275 | return 0; |
| 276 | } |
Holger Freyther | 89824fc | 2008-12-30 16:18:18 +0000 | [diff] [blame] | 277 | } |
Holger Freyther | 07cc8d8 | 2008-12-29 06:23:46 +0000 | [diff] [blame] | 278 | |
Holger Freyther | 73487a2 | 2008-12-31 18:53:57 +0000 | [diff] [blame] | 279 | static void release_loc_updating_req(struct gsm_lchan *lchan) |
| 280 | { |
Harald Welte | 179f064 | 2008-12-31 23:59:18 +0000 | [diff] [blame] | 281 | if (!lchan->loc_operation) |
Holger Freyther | 73487a2 | 2008-12-31 18:53:57 +0000 | [diff] [blame] | 282 | return; |
| 283 | |
Harald Welte | ff117a8 | 2009-05-23 05:22:08 +0000 | [diff] [blame] | 284 | bsc_del_timer(&lchan->loc_operation->updating_timer); |
Harald Welte | 2cf161b | 2009-06-20 22:36:41 +0200 | [diff] [blame] | 285 | talloc_free(lchan->loc_operation); |
Holger Freyther | 73487a2 | 2008-12-31 18:53:57 +0000 | [diff] [blame] | 286 | lchan->loc_operation = 0; |
Holger Freyther | 3eaa792 | 2009-01-01 02:59:03 +0000 | [diff] [blame] | 287 | put_lchan(lchan); |
Holger Freyther | 73487a2 | 2008-12-31 18:53:57 +0000 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | static void allocate_loc_updating_req(struct gsm_lchan *lchan) |
| 291 | { |
Holger Freyther | 67b4b9a | 2009-01-01 03:46:11 +0000 | [diff] [blame] | 292 | use_lchan(lchan); |
Holger Freyther | 73487a2 | 2008-12-31 18:53:57 +0000 | [diff] [blame] | 293 | release_loc_updating_req(lchan); |
| 294 | |
Harald Welte | 470ec29 | 2009-06-26 20:25:23 +0200 | [diff] [blame] | 295 | lchan->loc_operation = talloc_zero(tall_locop_ctx, |
| 296 | struct gsm_loc_updating_operation); |
Holger Freyther | 73487a2 | 2008-12-31 18:53:57 +0000 | [diff] [blame] | 297 | } |
Holger Freyther | 07cc8d8 | 2008-12-29 06:23:46 +0000 | [diff] [blame] | 298 | |
Holger Freyther | d51524f | 2009-06-09 08:27:07 +0000 | [diff] [blame] | 299 | static int gsm0408_authorize(struct gsm_lchan *lchan, struct msgb *msg) |
| 300 | { |
Holger Freyther | d51524f | 2009-06-09 08:27:07 +0000 | [diff] [blame] | 301 | if (authorize_subscriber(lchan->loc_operation, lchan->subscr)) { |
Harald Welte | ee5ad16 | 2009-08-09 19:07:00 +0200 | [diff] [blame] | 302 | int rc; |
| 303 | |
Holger Freyther | d51524f | 2009-06-09 08:27:07 +0000 | [diff] [blame] | 304 | db_subscriber_alloc_tmsi(lchan->subscr); |
Holger Freyther | d51524f | 2009-06-09 08:27:07 +0000 | [diff] [blame] | 305 | release_loc_updating_req(lchan); |
Holger Hans Peter Freyther | 2223025 | 2009-08-19 12:53:57 +0200 | [diff] [blame] | 306 | rc = gsm0408_loc_upd_acc(msg->lchan, lchan->subscr->tmsi); |
Harald Welte | 648b6ce | 2009-12-14 09:00:24 +0100 | [diff] [blame] | 307 | if (lchan->ts->trx->bts->network->send_mm_info) { |
| 308 | /* send MM INFO with network name */ |
| 309 | rc = gsm48_tx_mm_info(msg->lchan); |
| 310 | } |
Harald Welte | b83d938 | 2009-12-12 21:00:48 +0100 | [diff] [blame] | 311 | |
Harald Welte | ee5ad16 | 2009-08-09 19:07:00 +0200 | [diff] [blame] | 312 | /* call subscr_update after putting the loc_upd_acc |
| 313 | * in the transmit queue, since S_SUBSCR_ATTACHED might |
| 314 | * trigger further action like SMS delivery */ |
| 315 | subscr_update(lchan->subscr, msg->trx->bts, |
| 316 | GSM_SUBSCRIBER_UPDATE_ATTACHED); |
Harald Welte | b83d938 | 2009-12-12 21:00:48 +0100 | [diff] [blame] | 317 | /* try to close channel ASAP */ |
| 318 | lchan_auto_release(lchan); |
Harald Welte | ee5ad16 | 2009-08-09 19:07:00 +0200 | [diff] [blame] | 319 | return rc; |
Holger Freyther | d51524f | 2009-06-09 08:27:07 +0000 | [diff] [blame] | 320 | } |
| 321 | |
| 322 | return 0; |
| 323 | } |
| 324 | |
Holger Freyther | 7c19f74 | 2009-06-06 13:54:35 +0000 | [diff] [blame] | 325 | static int gsm0408_handle_lchan_signal(unsigned int subsys, unsigned int signal, |
| 326 | void *handler_data, void *signal_data) |
| 327 | { |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 328 | struct gsm_trans *trans, *temp; |
| 329 | |
Holger Freyther | 7c19f74 | 2009-06-06 13:54:35 +0000 | [diff] [blame] | 330 | if (subsys != SS_LCHAN || signal != S_LCHAN_UNEXPECTED_RELEASE) |
| 331 | return 0; |
| 332 | |
| 333 | /* |
| 334 | * Cancel any outstanding location updating request |
| 335 | * operation taking place on the lchan. |
| 336 | */ |
Harald Welte | 1a5c6bd | 2009-07-04 09:35:21 +0200 | [diff] [blame] | 337 | struct gsm_lchan *lchan = (struct gsm_lchan *)signal_data; |
Harald Welte | c05677b | 2009-06-26 20:17:06 +0200 | [diff] [blame] | 338 | if (!lchan) |
| 339 | return 0; |
| 340 | |
Holger Freyther | 7c19f74 | 2009-06-06 13:54:35 +0000 | [diff] [blame] | 341 | release_loc_updating_req(lchan); |
| 342 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 343 | /* Free all transactions that are associated with the released lchan */ |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 344 | /* FIXME: this is not neccessarily the right thing to do, we should |
| 345 | * only set trans->lchan to NULL and wait for another lchan to be |
| 346 | * established to the same MM entity (phone/subscriber) */ |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 347 | llist_for_each_entry_safe(trans, temp, &lchan->ts->trx->bts->network->trans_list, entry) { |
| 348 | if (trans->lchan == lchan) |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 349 | trans_free(trans); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 350 | } |
| 351 | |
Holger Freyther | 7c19f74 | 2009-06-06 13:54:35 +0000 | [diff] [blame] | 352 | return 0; |
| 353 | } |
| 354 | |
Harald Welte | 09e38af | 2009-02-16 22:52:23 +0000 | [diff] [blame] | 355 | static const char bcd_num_digits[] = { |
| 356 | '0', '1', '2', '3', '4', '5', '6', '7', |
| 357 | '8', '9', '*', '#', 'a', 'b', 'c', '\0' |
| 358 | }; |
| 359 | |
Harald Welte | 0c38930 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 360 | /* decode a 'called/calling/connect party BCD number' as in 10.5.4.7 */ |
| 361 | int decode_bcd_number(char *output, int output_len, const u_int8_t *bcd_lv, |
| 362 | int h_len) |
Harald Welte | 09e38af | 2009-02-16 22:52:23 +0000 | [diff] [blame] | 363 | { |
| 364 | u_int8_t in_len = bcd_lv[0]; |
| 365 | int i; |
| 366 | |
Harald Welte | 0c38930 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 367 | for (i = 1 + h_len; i <= in_len; i++) { |
Harald Welte | 09e38af | 2009-02-16 22:52:23 +0000 | [diff] [blame] | 368 | /* lower nibble */ |
| 369 | output_len--; |
| 370 | if (output_len <= 1) |
| 371 | break; |
| 372 | *output++ = bcd_num_digits[bcd_lv[i] & 0xf]; |
| 373 | |
| 374 | /* higher nibble */ |
| 375 | output_len--; |
| 376 | if (output_len <= 1) |
| 377 | break; |
| 378 | *output++ = bcd_num_digits[bcd_lv[i] >> 4]; |
| 379 | } |
| 380 | if (output_len >= 1) |
| 381 | *output++ = '\0'; |
| 382 | |
Harald Welte | 0c38930 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 383 | return 0; |
Harald Welte | 09e38af | 2009-02-16 22:52:23 +0000 | [diff] [blame] | 384 | } |
| 385 | |
| 386 | /* convert a single ASCII character to call-control BCD */ |
| 387 | static int asc_to_bcd(const char asc) |
| 388 | { |
| 389 | int i; |
| 390 | |
| 391 | for (i = 0; i < ARRAY_SIZE(bcd_num_digits); i++) { |
| 392 | if (bcd_num_digits[i] == asc) |
| 393 | return i; |
| 394 | } |
| 395 | return -EINVAL; |
| 396 | } |
| 397 | |
Harald Welte | 0c38930 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 398 | /* convert a ASCII phone number to 'called/calling/connect party BCD number' */ |
Harald Welte | 09e38af | 2009-02-16 22:52:23 +0000 | [diff] [blame] | 399 | int encode_bcd_number(u_int8_t *bcd_lv, u_int8_t max_len, |
Harald Welte | 0c38930 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 400 | int h_len, const char *input) |
Harald Welte | 09e38af | 2009-02-16 22:52:23 +0000 | [diff] [blame] | 401 | { |
| 402 | int in_len = strlen(input); |
| 403 | int i; |
Harald Welte | 0c38930 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 404 | u_int8_t *bcd_cur = bcd_lv + 1 + h_len; |
Harald Welte | 09e38af | 2009-02-16 22:52:23 +0000 | [diff] [blame] | 405 | |
| 406 | /* two digits per byte, plus type byte */ |
Harald Welte | 0c38930 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 407 | bcd_lv[0] = in_len/2 + h_len; |
Harald Welte | 09e38af | 2009-02-16 22:52:23 +0000 | [diff] [blame] | 408 | if (in_len % 2) |
| 409 | bcd_lv[0]++; |
| 410 | |
Harald Welte | 0c38930 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 411 | if (bcd_lv[0] > max_len) |
| 412 | return -EIO; |
Harald Welte | 09e38af | 2009-02-16 22:52:23 +0000 | [diff] [blame] | 413 | |
| 414 | for (i = 0; i < in_len; i++) { |
| 415 | int rc = asc_to_bcd(input[i]); |
| 416 | if (rc < 0) |
| 417 | return rc; |
| 418 | if (i % 2 == 0) |
| 419 | *bcd_cur = rc; |
| 420 | else |
| 421 | *bcd_cur++ |= (rc << 4); |
| 422 | } |
| 423 | /* append padding nibble in case of odd length */ |
| 424 | if (i % 2) |
| 425 | *bcd_cur++ |= 0xf0; |
| 426 | |
| 427 | /* return how many bytes we used */ |
| 428 | return (bcd_cur - bcd_lv); |
| 429 | } |
| 430 | |
Harald Welte | 0c38930 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 431 | /* decode 'bearer capability' */ |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 432 | static int decode_bearer_cap(struct gsm_mncc_bearer_cap *bcap, |
Harald Welte | 0c38930 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 433 | const u_int8_t *lv) |
| 434 | { |
| 435 | u_int8_t in_len = lv[0]; |
| 436 | int i, s; |
| 437 | |
| 438 | if (in_len < 1) |
| 439 | return -EINVAL; |
| 440 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 441 | bcap->speech_ver[0] = -1; /* end of list, of maximum 7 values */ |
Harald Welte | 0c38930 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 442 | |
| 443 | /* octet 3 */ |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 444 | bcap->transfer = lv[1] & 0x07; |
| 445 | bcap->mode = (lv[1] & 0x08) >> 3; |
| 446 | bcap->coding = (lv[1] & 0x10) >> 4; |
| 447 | bcap->radio = (lv[1] & 0x60) >> 5; |
Harald Welte | 0c38930 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 448 | |
Harald Welte | 09b7e7f | 2009-12-12 21:36:53 +0100 | [diff] [blame] | 449 | if (bcap->transfer == GSM_MNCC_BCAP_SPEECH) { |
| 450 | i = 1; |
| 451 | s = 0; |
| 452 | while(!(lv[i] & 0x80)) { |
| 453 | i++; /* octet 3a etc */ |
| 454 | if (in_len < i) |
| 455 | return 0; |
| 456 | bcap->speech_ver[s++] = lv[i] & 0x0f; |
| 457 | bcap->speech_ver[s] = -1; /* end of list */ |
| 458 | if (i == 2) /* octet 3a */ |
| 459 | bcap->speech_ctm = (lv[i] & 0x20) >> 5; |
| 460 | if (s == 7) /* maximum speech versions + end of list */ |
| 461 | return 0; |
| 462 | } |
| 463 | } else { |
| 464 | i = 1; |
| 465 | while (!(lv[i] & 0x80)) { |
| 466 | i++; /* octet 3a etc */ |
| 467 | if (in_len < i) |
| 468 | return 0; |
| 469 | /* ignore them */ |
| 470 | } |
| 471 | /* FIXME: implement OCTET 4+ parsing */ |
Harald Welte | 0c38930 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 472 | } |
| 473 | |
| 474 | return 0; |
| 475 | } |
| 476 | |
| 477 | /* encode 'bearer capability' */ |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 478 | static int encode_bearer_cap(struct msgb *msg, int lv_only, |
| 479 | const struct gsm_mncc_bearer_cap *bcap) |
Harald Welte | 0c38930 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 480 | { |
| 481 | u_int8_t lv[32 + 1]; |
Harald Welte | 09b7e7f | 2009-12-12 21:36:53 +0100 | [diff] [blame] | 482 | int i = 1, s; |
Harald Welte | 0c38930 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 483 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 484 | lv[1] = bcap->transfer; |
| 485 | lv[1] |= bcap->mode << 3; |
| 486 | lv[1] |= bcap->coding << 4; |
| 487 | lv[1] |= bcap->radio << 5; |
Harald Welte | 0c38930 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 488 | |
Harald Welte | 09b7e7f | 2009-12-12 21:36:53 +0100 | [diff] [blame] | 489 | if (bcap->transfer == GSM_MNCC_BCAP_SPEECH) { |
| 490 | for (s = 0; bcap->speech_ver[s] >= 0; s++) { |
| 491 | i++; /* octet 3a etc */ |
| 492 | lv[i] = bcap->speech_ver[s]; |
| 493 | if (i == 2) /* octet 3a */ |
| 494 | lv[i] |= bcap->speech_ctm << 5; |
| 495 | } |
| 496 | lv[i] |= 0x80; /* last IE of octet 3 etc */ |
| 497 | } else { |
| 498 | /* FIXME: implement OCTET 4+ encoding */ |
Harald Welte | 0c38930 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 499 | } |
Harald Welte | 0c38930 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 500 | |
| 501 | lv[0] = i; |
| 502 | if (lv_only) |
| 503 | msgb_lv_put(msg, lv[0], lv+1); |
| 504 | else |
| 505 | msgb_tlv_put(msg, GSM48_IE_BEARER_CAP, lv[0], lv+1); |
| 506 | |
| 507 | return 0; |
| 508 | } |
| 509 | |
| 510 | /* decode 'call control cap' */ |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 511 | static int decode_cccap(struct gsm_mncc_cccap *ccap, const u_int8_t *lv) |
Harald Welte | 0c38930 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 512 | { |
| 513 | u_int8_t in_len = lv[0]; |
| 514 | |
| 515 | if (in_len < 1) |
| 516 | return -EINVAL; |
| 517 | |
| 518 | /* octet 3 */ |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 519 | ccap->dtmf = lv[1] & 0x01; |
| 520 | ccap->pcp = (lv[1] & 0x02) >> 1; |
Harald Welte | 0c38930 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 521 | |
| 522 | return 0; |
| 523 | } |
| 524 | |
| 525 | /* decode 'called party BCD number' */ |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 526 | static int decode_called(struct gsm_mncc_number *called, |
| 527 | const u_int8_t *lv) |
Harald Welte | 0c38930 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 528 | { |
| 529 | u_int8_t in_len = lv[0]; |
| 530 | |
| 531 | if (in_len < 1) |
| 532 | return -EINVAL; |
| 533 | |
| 534 | /* octet 3 */ |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 535 | called->plan = lv[1] & 0x0f; |
| 536 | called->type = (lv[1] & 0x70) >> 4; |
Harald Welte | 0c38930 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 537 | |
| 538 | /* octet 4..N */ |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 539 | decode_bcd_number(called->number, sizeof(called->number), lv, 1); |
Harald Welte | 0c38930 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 540 | |
| 541 | return 0; |
| 542 | } |
| 543 | |
| 544 | /* encode 'called party BCD number' */ |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 545 | static int encode_called(struct msgb *msg, |
| 546 | const struct gsm_mncc_number *called) |
Harald Welte | 0c38930 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 547 | { |
| 548 | u_int8_t lv[18]; |
| 549 | int ret; |
| 550 | |
| 551 | /* octet 3 */ |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 552 | lv[1] = called->plan; |
| 553 | lv[1] |= called->type << 4; |
Harald Welte | 0c38930 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 554 | |
| 555 | /* octet 4..N, octet 2 */ |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 556 | ret = encode_bcd_number(lv, sizeof(lv), 1, called->number); |
Harald Welte | 0c38930 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 557 | if (ret < 0) |
| 558 | return ret; |
| 559 | |
| 560 | msgb_tlv_put(msg, GSM48_IE_CALLED_BCD, lv[0], lv+1); |
| 561 | |
| 562 | return 0; |
| 563 | } |
| 564 | |
| 565 | /* encode callerid of various IEs */ |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 566 | static int encode_callerid(struct msgb *msg, int ie, |
| 567 | const struct gsm_mncc_number *callerid) |
Harald Welte | 0c38930 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 568 | { |
| 569 | u_int8_t lv[13]; |
| 570 | int h_len = 1; |
| 571 | int ret; |
| 572 | |
| 573 | /* octet 3 */ |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 574 | lv[1] = callerid->plan; |
| 575 | lv[1] |= callerid->type << 4; |
Harald Welte | 0c38930 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 576 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 577 | if (callerid->present || callerid->screen) { |
Harald Welte | 0c38930 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 578 | /* octet 3a */ |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 579 | lv[2] = callerid->screen; |
| 580 | lv[2] |= callerid->present << 5; |
Harald Welte | 0c38930 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 581 | lv[2] |= 0x80; |
| 582 | h_len++; |
| 583 | } else |
| 584 | lv[1] |= 0x80; |
| 585 | |
| 586 | /* octet 4..N, octet 2 */ |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 587 | ret = encode_bcd_number(lv, sizeof(lv), h_len, callerid->number); |
Harald Welte | 0c38930 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 588 | if (ret < 0) |
| 589 | return ret; |
| 590 | |
| 591 | msgb_tlv_put(msg, ie, lv[0], lv+1); |
| 592 | |
| 593 | return 0; |
| 594 | } |
| 595 | |
| 596 | /* decode 'cause' */ |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 597 | static int decode_cause(struct gsm_mncc_cause *cause, |
Harald Welte | 0c38930 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 598 | const u_int8_t *lv) |
| 599 | { |
| 600 | u_int8_t in_len = lv[0]; |
| 601 | int i; |
| 602 | |
| 603 | if (in_len < 2) |
| 604 | return -EINVAL; |
| 605 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 606 | cause->diag_len = 0; |
Harald Welte | 0c38930 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 607 | |
| 608 | /* octet 3 */ |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 609 | cause->location = lv[1] & 0x0f; |
| 610 | cause->coding = (lv[1] & 0x60) >> 5; |
Harald Welte | 0c38930 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 611 | |
| 612 | i = 1; |
| 613 | if (!(lv[i] & 0x80)) { |
| 614 | i++; /* octet 3a */ |
| 615 | if (in_len < i+1) |
| 616 | return 0; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 617 | cause->rec = 1; |
| 618 | cause->rec_val = lv[i] & 0x7f; |
Harald Welte | 0c38930 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 619 | |
| 620 | } |
| 621 | i++; |
| 622 | |
| 623 | /* octet 4 */ |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 624 | cause->value = lv[i] & 0x7f; |
Harald Welte | 0c38930 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 625 | i++; |
| 626 | |
| 627 | if (in_len < i) /* no diag */ |
| 628 | return 0; |
| 629 | |
| 630 | if (in_len - (i-1) > 32) /* maximum 32 octets */ |
| 631 | return 0; |
| 632 | |
| 633 | /* octet 5-N */ |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 634 | memcpy(cause->diag, lv + i, in_len - (i-1)); |
| 635 | cause->diag_len = in_len - (i-1); |
Harald Welte | 0c38930 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 636 | |
| 637 | return 0; |
| 638 | } |
| 639 | |
| 640 | /* encode 'cause' */ |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 641 | static int encode_cause(struct msgb *msg, int lv_only, |
| 642 | const struct gsm_mncc_cause *cause) |
Harald Welte | 0c38930 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 643 | { |
| 644 | u_int8_t lv[32+4]; |
| 645 | int i; |
| 646 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 647 | if (cause->diag_len > 32) |
Harald Welte | 0c38930 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 648 | return -EINVAL; |
| 649 | |
| 650 | /* octet 3 */ |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 651 | lv[1] = cause->location; |
| 652 | lv[1] |= cause->coding << 5; |
Harald Welte | 0c38930 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 653 | |
| 654 | i = 1; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 655 | if (cause->rec) { |
Harald Welte | 0c38930 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 656 | i++; /* octet 3a */ |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 657 | lv[i] = cause->rec_val; |
Harald Welte | 0c38930 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 658 | } |
| 659 | lv[i] |= 0x80; /* end of octet 3 */ |
| 660 | |
| 661 | /* octet 4 */ |
| 662 | i++; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 663 | lv[i] = 0x80 | cause->value; |
Harald Welte | 0c38930 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 664 | |
| 665 | /* octet 5-N */ |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 666 | if (cause->diag_len) { |
| 667 | memcpy(lv + i, cause->diag, cause->diag_len); |
| 668 | i += cause->diag_len; |
Harald Welte | 0c38930 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 669 | } |
| 670 | |
| 671 | lv[0] = i; |
| 672 | if (lv_only) |
| 673 | msgb_lv_put(msg, lv[0], lv+1); |
| 674 | else |
| 675 | msgb_tlv_put(msg, GSM48_IE_CAUSE, lv[0], lv+1); |
| 676 | |
| 677 | return 0; |
| 678 | } |
| 679 | |
| 680 | /* encode 'calling number' */ |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 681 | static int encode_calling(struct msgb *msg, |
| 682 | const struct gsm_mncc_number *calling) |
Harald Welte | 0c38930 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 683 | { |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 684 | return encode_callerid(msg, GSM48_IE_CALLING_BCD, calling); |
Harald Welte | 0c38930 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 685 | } |
| 686 | |
| 687 | /* encode 'connected number' */ |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 688 | static int encode_connected(struct msgb *msg, |
| 689 | const struct gsm_mncc_number *connected) |
Harald Welte | 0c38930 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 690 | { |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 691 | return encode_callerid(msg, GSM48_IE_CONN_BCD, connected); |
Harald Welte | 0c38930 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 692 | } |
| 693 | |
| 694 | /* encode 'redirecting number' */ |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 695 | static int encode_redirecting(struct msgb *msg, |
| 696 | const struct gsm_mncc_number *redirecting) |
Harald Welte | 0c38930 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 697 | { |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 698 | return encode_callerid(msg, GSM48_IE_REDIR_BCD, redirecting); |
Harald Welte | 0c38930 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 699 | } |
| 700 | |
| 701 | /* decode 'facility' */ |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 702 | static int decode_facility(struct gsm_mncc_facility *facility, |
Harald Welte | 0c38930 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 703 | const u_int8_t *lv) |
| 704 | { |
| 705 | u_int8_t in_len = lv[0]; |
| 706 | |
| 707 | if (in_len < 1) |
| 708 | return -EINVAL; |
| 709 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 710 | if (in_len > sizeof(facility->info)) |
Harald Welte | 0c38930 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 711 | return -EINVAL; |
| 712 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 713 | memcpy(facility->info, lv+1, in_len); |
| 714 | facility->len = in_len; |
Harald Welte | 0c38930 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 715 | |
| 716 | return 0; |
| 717 | } |
| 718 | |
| 719 | /* encode 'facility' */ |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 720 | static int encode_facility(struct msgb *msg, int lv_only, |
| 721 | const struct gsm_mncc_facility *facility) |
Harald Welte | 0c38930 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 722 | { |
| 723 | u_int8_t lv[GSM_MAX_FACILITY + 1]; |
| 724 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 725 | if (facility->len < 1 || facility->len > GSM_MAX_FACILITY) |
Harald Welte | 0c38930 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 726 | return -EINVAL; |
| 727 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 728 | memcpy(lv+1, facility->info, facility->len); |
| 729 | lv[0] = facility->len; |
Harald Welte | 0c38930 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 730 | if (lv_only) |
| 731 | msgb_lv_put(msg, lv[0], lv+1); |
| 732 | else |
| 733 | msgb_tlv_put(msg, GSM48_IE_FACILITY, lv[0], lv+1); |
| 734 | |
| 735 | return 0; |
| 736 | } |
| 737 | |
| 738 | /* decode 'notify' */ |
| 739 | static int decode_notify(int *notify, const u_int8_t *v) |
| 740 | { |
| 741 | *notify = v[0] & 0x7f; |
| 742 | |
| 743 | return 0; |
| 744 | } |
| 745 | |
| 746 | /* encode 'notify' */ |
| 747 | static int encode_notify(struct msgb *msg, int notify) |
| 748 | { |
| 749 | msgb_v_put(msg, notify | 0x80); |
| 750 | |
| 751 | return 0; |
| 752 | } |
| 753 | |
| 754 | /* encode 'signal' */ |
| 755 | static int encode_signal(struct msgb *msg, int signal) |
| 756 | { |
| 757 | msgb_tv_put(msg, GSM48_IE_SIGNAL, signal); |
| 758 | |
| 759 | return 0; |
| 760 | } |
| 761 | |
| 762 | /* decode 'keypad' */ |
| 763 | static int decode_keypad(int *keypad, const u_int8_t *lv) |
| 764 | { |
| 765 | u_int8_t in_len = lv[0]; |
| 766 | |
| 767 | if (in_len < 1) |
| 768 | return -EINVAL; |
| 769 | |
| 770 | *keypad = lv[1] & 0x7f; |
| 771 | |
| 772 | return 0; |
| 773 | } |
| 774 | |
| 775 | /* encode 'keypad' */ |
| 776 | static int encode_keypad(struct msgb *msg, int keypad) |
| 777 | { |
| 778 | msgb_tv_put(msg, GSM48_IE_KPD_FACILITY, keypad); |
| 779 | |
| 780 | return 0; |
| 781 | } |
| 782 | |
| 783 | /* decode 'progress' */ |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 784 | static int decode_progress(struct gsm_mncc_progress *progress, |
Harald Welte | 0c38930 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 785 | const u_int8_t *lv) |
| 786 | { |
| 787 | u_int8_t in_len = lv[0]; |
| 788 | |
| 789 | if (in_len < 2) |
| 790 | return -EINVAL; |
| 791 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 792 | progress->coding = (lv[1] & 0x60) >> 5; |
| 793 | progress->location = lv[1] & 0x0f; |
| 794 | progress->descr = lv[2] & 0x7f; |
Harald Welte | 0c38930 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 795 | |
| 796 | return 0; |
| 797 | } |
| 798 | |
| 799 | /* encode 'progress' */ |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 800 | static int encode_progress(struct msgb *msg, int lv_only, |
| 801 | const struct gsm_mncc_progress *p) |
Harald Welte | 0c38930 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 802 | { |
| 803 | u_int8_t lv[3]; |
| 804 | |
| 805 | lv[0] = 2; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 806 | lv[1] = 0x80 | ((p->coding & 0x3) << 5) | (p->location & 0xf); |
| 807 | lv[2] = 0x80 | (p->descr & 0x7f); |
Harald Welte | 0c38930 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 808 | if (lv_only) |
| 809 | msgb_lv_put(msg, lv[0], lv+1); |
| 810 | else |
| 811 | msgb_tlv_put(msg, GSM48_IE_PROGR_IND, lv[0], lv+1); |
| 812 | |
| 813 | return 0; |
| 814 | } |
| 815 | |
| 816 | /* decode 'user-user' */ |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 817 | static int decode_useruser(struct gsm_mncc_useruser *uu, |
Harald Welte | 0c38930 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 818 | const u_int8_t *lv) |
| 819 | { |
| 820 | u_int8_t in_len = lv[0]; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 821 | char *info = uu->info; |
| 822 | int info_len = sizeof(uu->info); |
Harald Welte | 0c38930 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 823 | int i; |
| 824 | |
| 825 | if (in_len < 1) |
| 826 | return -EINVAL; |
| 827 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 828 | uu->proto = lv[1]; |
Harald Welte | 0c38930 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 829 | |
| 830 | for (i = 2; i <= in_len; i++) { |
| 831 | info_len--; |
| 832 | if (info_len <= 1) |
| 833 | break; |
| 834 | *info++ = lv[i]; |
| 835 | } |
| 836 | if (info_len >= 1) |
| 837 | *info++ = '\0'; |
| 838 | |
| 839 | return 0; |
| 840 | } |
| 841 | |
| 842 | /* encode 'useruser' */ |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 843 | static int encode_useruser(struct msgb *msg, int lv_only, |
| 844 | const struct gsm_mncc_useruser *uu) |
Harald Welte | 0c38930 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 845 | { |
| 846 | u_int8_t lv[GSM_MAX_USERUSER + 2]; |
| 847 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 848 | if (strlen(uu->info) > GSM_MAX_USERUSER) |
Harald Welte | 0c38930 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 849 | return -EINVAL; |
| 850 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 851 | lv[0] = 1 + strlen(uu->info); |
| 852 | lv[1] = uu->proto; |
| 853 | memcpy(lv + 2, uu->info, strlen(uu->info)); |
Harald Welte | 0c38930 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 854 | if (lv_only) |
| 855 | msgb_lv_put(msg, lv[0], lv+1); |
| 856 | else |
| 857 | msgb_tlv_put(msg, GSM48_IE_USER_USER, lv[0], lv+1); |
| 858 | |
| 859 | return 0; |
| 860 | } |
| 861 | |
| 862 | /* decode 'ss version' */ |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 863 | static int decode_ssversion(struct gsm_mncc_ssversion *ssv, |
Harald Welte | 0c38930 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 864 | const u_int8_t *lv) |
| 865 | { |
| 866 | u_int8_t in_len = lv[0]; |
| 867 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 868 | if (in_len < 1 || in_len < sizeof(ssv->info)) |
Harald Welte | 0c38930 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 869 | return -EINVAL; |
| 870 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 871 | memcpy(ssv->info, lv + 1, in_len); |
| 872 | ssv->len = in_len; |
Harald Welte | 0c38930 | 2009-06-10 12:08:54 +0800 | [diff] [blame] | 873 | |
| 874 | return 0; |
| 875 | } |
| 876 | |
| 877 | /* encode 'more data' */ |
| 878 | static int encode_more(struct msgb *msg) |
| 879 | { |
| 880 | u_int8_t *ie; |
| 881 | |
| 882 | ie = msgb_put(msg, 1); |
| 883 | ie[0] = GSM48_IE_MORE_DATA; |
| 884 | |
| 885 | return 0; |
| 886 | } |
| 887 | |
Holger Freyther | 429e776 | 2008-12-30 13:28:30 +0000 | [diff] [blame] | 888 | /* Chapter 9.2.14 : Send LOCATION UPDATING REJECT */ |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 889 | 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] | 890 | { |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 891 | struct msgb *msg = gsm48_msgb_alloc(); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 892 | struct gsm48_hdr *gh; |
| 893 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 894 | msg->lchan = lchan; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 895 | |
| 896 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 1); |
| 897 | gh->proto_discr = GSM48_PDISC_MM; |
Harald Welte | 10b487b | 2008-12-27 19:53:37 +0000 | [diff] [blame] | 898 | gh->msg_type = GSM48_MT_MM_LOC_UPD_REJECT; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 899 | gh->data[0] = cause; |
| 900 | |
Harald Welte | db253af | 2008-12-30 17:56:55 +0000 | [diff] [blame] | 901 | DEBUGP(DMM, "-> LOCATION UPDATING REJECT on channel: %d\n", lchan->nr); |
| 902 | |
Harald Welte | 39e2ead | 2009-07-23 21:13:03 +0200 | [diff] [blame] | 903 | return gsm48_sendmsg(msg, NULL); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 904 | } |
| 905 | |
| 906 | /* Chapter 9.2.13 : Send LOCATION UPDATE ACCEPT */ |
Harald Welte | 75a983f | 2008-12-27 21:34:06 +0000 | [diff] [blame] | 907 | 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] | 908 | { |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 909 | struct gsm_bts *bts = lchan->ts->trx->bts; |
| 910 | struct msgb *msg = gsm48_msgb_alloc(); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 911 | struct gsm48_hdr *gh; |
| 912 | struct gsm48_loc_area_id *lai; |
| 913 | u_int8_t *mid; |
| 914 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 915 | msg->lchan = lchan; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 916 | |
| 917 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 918 | gh->proto_discr = GSM48_PDISC_MM; |
| 919 | gh->msg_type = GSM48_MT_MM_LOC_UPD_ACCEPT; |
| 920 | |
| 921 | lai = (struct gsm48_loc_area_id *) msgb_put(msg, sizeof(*lai)); |
Holger Freyther | 1774661 | 2008-12-28 16:32:44 +0000 | [diff] [blame] | 922 | gsm0408_generate_lai(lai, bts->network->country_code, |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 923 | bts->network->network_code, bts->location_area_code); |
| 924 | |
Holger Hans Peter Freyther | 1494a76 | 2009-08-01 07:26:59 +0200 | [diff] [blame] | 925 | mid = msgb_put(msg, GSM48_MID_TMSI_LEN); |
Holger Hans Peter Freyther | 5d0e56f | 2009-08-20 08:41:24 +0200 | [diff] [blame] | 926 | gsm48_generate_mid_from_tmsi(mid, tmsi); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 927 | |
| 928 | DEBUGP(DMM, "-> LOCATION UPDATE ACCEPT\n"); |
| 929 | |
Harald Welte | b83d938 | 2009-12-12 21:00:48 +0100 | [diff] [blame] | 930 | return gsm48_sendmsg(msg, NULL); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 931 | } |
| 932 | |
Harald Welte | bf5e8df | 2009-02-03 12:59:45 +0000 | [diff] [blame] | 933 | /* Transmit Chapter 9.2.10 Identity Request */ |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 934 | static int mm_tx_identity_req(struct gsm_lchan *lchan, u_int8_t id_type) |
| 935 | { |
| 936 | struct msgb *msg = gsm48_msgb_alloc(); |
| 937 | struct gsm48_hdr *gh; |
Harald Welte | fc977a8 | 2008-12-27 10:19:37 +0000 | [diff] [blame] | 938 | |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 939 | msg->lchan = lchan; |
| 940 | |
| 941 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 1); |
| 942 | gh->proto_discr = GSM48_PDISC_MM; |
| 943 | gh->msg_type = GSM48_MT_MM_ID_REQ; |
| 944 | gh->data[0] = id_type; |
| 945 | |
Harald Welte | 39e2ead | 2009-07-23 21:13:03 +0200 | [diff] [blame] | 946 | return gsm48_sendmsg(msg, NULL); |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 947 | } |
| 948 | |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 949 | |
Harald Welte | bf5e8df | 2009-02-03 12:59:45 +0000 | [diff] [blame] | 950 | /* Parse Chapter 9.2.11 Identity Response */ |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 951 | static int mm_rx_id_resp(struct msgb *msg) |
| 952 | { |
| 953 | struct gsm48_hdr *gh = msgb_l3(msg); |
Harald Welte | 75a983f | 2008-12-27 21:34:06 +0000 | [diff] [blame] | 954 | struct gsm_lchan *lchan = msg->lchan; |
Harald Welte | 9176bd4 | 2009-07-23 18:46:00 +0200 | [diff] [blame] | 955 | struct gsm_bts *bts = lchan->ts->trx->bts; |
| 956 | struct gsm_network *net = bts->network; |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 957 | u_int8_t mi_type = gh->data[1] & GSM_MI_TYPE_MASK; |
Holger Hans Peter Freyther | d1862d7 | 2009-08-19 07:54:59 +0200 | [diff] [blame] | 958 | char mi_string[GSM48_MI_SIZE]; |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 959 | |
Holger Hans Peter Freyther | d1862d7 | 2009-08-19 07:54:59 +0200 | [diff] [blame] | 960 | gsm48_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] | 961 | DEBUGP(DMM, "IDENTITY RESPONSE: mi_type=0x%02x MI(%s)\n", |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 962 | mi_type, mi_string); |
| 963 | |
Harald Welte | 7659de1 | 2009-12-13 12:39:18 +0100 | [diff] [blame] | 964 | dispatch_signal(SS_SUBSCR, S_SUBSCR_IDENTITY, gh->data); |
| 965 | |
Harald Welte | 75a983f | 2008-12-27 21:34:06 +0000 | [diff] [blame] | 966 | switch (mi_type) { |
| 967 | case GSM_MI_TYPE_IMSI: |
Jan Luebbe | 370b41d | 2009-08-12 10:19:34 +0200 | [diff] [blame] | 968 | /* look up subscriber based on IMSI, create if not found */ |
| 969 | if (!lchan->subscr) { |
| 970 | lchan->subscr = subscr_get_by_imsi(net, mi_string); |
Harald Welte (local) | aa9dc19 | 2009-08-13 13:49:51 +0200 | [diff] [blame] | 971 | if (!lchan->subscr) |
| 972 | lchan->subscr = db_create_subscriber(net, mi_string); |
Jan Luebbe | b0dfc31 | 2009-08-12 10:12:52 +0200 | [diff] [blame] | 973 | } |
Holger Freyther | 73487a2 | 2008-12-31 18:53:57 +0000 | [diff] [blame] | 974 | if (lchan->loc_operation) |
| 975 | lchan->loc_operation->waiting_for_imsi = 0; |
Harald Welte | 75a983f | 2008-12-27 21:34:06 +0000 | [diff] [blame] | 976 | break; |
| 977 | case GSM_MI_TYPE_IMEI: |
Harald Welte | 255539c | 2008-12-28 02:26:27 +0000 | [diff] [blame] | 978 | case GSM_MI_TYPE_IMEISV: |
Harald Welte | 75a983f | 2008-12-27 21:34:06 +0000 | [diff] [blame] | 979 | /* update subscribe <-> IMEI mapping */ |
Harald Welte (local) | ee4410a | 2009-08-17 09:39:55 +0200 | [diff] [blame] | 980 | if (lchan->subscr) { |
Harald Welte | 75a983f | 2008-12-27 21:34:06 +0000 | [diff] [blame] | 981 | db_subscriber_assoc_imei(lchan->subscr, mi_string); |
Harald Welte (local) | ee4410a | 2009-08-17 09:39:55 +0200 | [diff] [blame] | 982 | db_sync_equipment(&lchan->subscr->equipment); |
| 983 | } |
Holger Freyther | 73487a2 | 2008-12-31 18:53:57 +0000 | [diff] [blame] | 984 | if (lchan->loc_operation) |
| 985 | lchan->loc_operation->waiting_for_imei = 0; |
Harald Welte | 75a983f | 2008-12-27 21:34:06 +0000 | [diff] [blame] | 986 | break; |
| 987 | } |
Holger Freyther | 73487a2 | 2008-12-31 18:53:57 +0000 | [diff] [blame] | 988 | |
| 989 | /* Check if we can let the mobile station enter */ |
Holger Freyther | d51524f | 2009-06-09 08:27:07 +0000 | [diff] [blame] | 990 | return gsm0408_authorize(lchan, msg); |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 991 | } |
| 992 | |
Harald Welte | 255539c | 2008-12-28 02:26:27 +0000 | [diff] [blame] | 993 | |
| 994 | static void loc_upd_rej_cb(void *data) |
| 995 | { |
| 996 | struct gsm_lchan *lchan = data; |
Harald Welte | 1085c09 | 2009-11-18 20:33:19 +0100 | [diff] [blame] | 997 | struct gsm_bts *bts = lchan->ts->trx->bts; |
Harald Welte | 255539c | 2008-12-28 02:26:27 +0000 | [diff] [blame] | 998 | |
Holger Freyther | 73487a2 | 2008-12-31 18:53:57 +0000 | [diff] [blame] | 999 | release_loc_updating_req(lchan); |
Harald Welte | 1085c09 | 2009-11-18 20:33:19 +0100 | [diff] [blame] | 1000 | gsm0408_loc_upd_rej(lchan, bts->network->reject_cause); |
Holger Freyther | 67b4b9a | 2009-01-01 03:46:11 +0000 | [diff] [blame] | 1001 | lchan_auto_release(lchan); |
Harald Welte | 255539c | 2008-12-28 02:26:27 +0000 | [diff] [blame] | 1002 | } |
| 1003 | |
Holger Freyther | b7193e4 | 2008-12-29 17:44:08 +0000 | [diff] [blame] | 1004 | static void schedule_reject(struct gsm_lchan *lchan) |
| 1005 | { |
Holger Freyther | 73487a2 | 2008-12-31 18:53:57 +0000 | [diff] [blame] | 1006 | lchan->loc_operation->updating_timer.cb = loc_upd_rej_cb; |
| 1007 | lchan->loc_operation->updating_timer.data = lchan; |
Harald Welte | ff117a8 | 2009-05-23 05:22:08 +0000 | [diff] [blame] | 1008 | bsc_schedule_timer(&lchan->loc_operation->updating_timer, 5, 0); |
Holger Freyther | b7193e4 | 2008-12-29 17:44:08 +0000 | [diff] [blame] | 1009 | } |
| 1010 | |
Harald Welte | 2a13937 | 2009-02-22 21:14:55 +0000 | [diff] [blame] | 1011 | static const char *lupd_name(u_int8_t type) |
| 1012 | { |
| 1013 | switch (type) { |
| 1014 | case GSM48_LUPD_NORMAL: |
| 1015 | return "NORMAL"; |
| 1016 | case GSM48_LUPD_PERIODIC: |
| 1017 | return "PEROIDOC"; |
| 1018 | case GSM48_LUPD_IMSI_ATT: |
| 1019 | return "IMSI ATTACH"; |
| 1020 | default: |
| 1021 | return "UNKNOWN"; |
| 1022 | } |
| 1023 | } |
| 1024 | |
Harald Welte | bf5e8df | 2009-02-03 12:59:45 +0000 | [diff] [blame] | 1025 | /* Chapter 9.2.15: Receive Location Updating Request */ |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 1026 | static int mm_rx_loc_upd_req(struct msgb *msg) |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1027 | { |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 1028 | struct gsm48_hdr *gh = msgb_l3(msg); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1029 | struct gsm48_loc_upd_req *lu; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1030 | struct gsm_subscriber *subscr = NULL; |
Harald Welte | 255539c | 2008-12-28 02:26:27 +0000 | [diff] [blame] | 1031 | struct gsm_lchan *lchan = msg->lchan; |
Harald Welte | 9176bd4 | 2009-07-23 18:46:00 +0200 | [diff] [blame] | 1032 | struct gsm_bts *bts = lchan->ts->trx->bts; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 1033 | u_int8_t mi_type; |
Holger Hans Peter Freyther | d1862d7 | 2009-08-19 07:54:59 +0200 | [diff] [blame] | 1034 | char mi_string[GSM48_MI_SIZE]; |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 1035 | int rc; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1036 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 1037 | lu = (struct gsm48_loc_upd_req *) gh->data; |
| 1038 | |
| 1039 | mi_type = lu->mi[0] & GSM_MI_TYPE_MASK; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1040 | |
Holger Hans Peter Freyther | d1862d7 | 2009-08-19 07:54:59 +0200 | [diff] [blame] | 1041 | gsm48_mi_to_string(mi_string, sizeof(mi_string), lu->mi, lu->mi_len); |
Harald Welte | fc977a8 | 2008-12-27 10:19:37 +0000 | [diff] [blame] | 1042 | |
Harald Welte | a036854 | 2009-06-27 02:58:43 +0200 | [diff] [blame] | 1043 | DEBUGPC(DMM, "mi_type=0x%02x MI(%s) type=%s ", mi_type, mi_string, |
Harald Welte | 2a13937 | 2009-02-22 21:14:55 +0000 | [diff] [blame] | 1044 | lupd_name(lu->type)); |
Holger Freyther | 73487a2 | 2008-12-31 18:53:57 +0000 | [diff] [blame] | 1045 | |
Harald Welte | 7659de1 | 2009-12-13 12:39:18 +0100 | [diff] [blame] | 1046 | dispatch_signal(SS_SUBSCR, S_SUBSCR_IDENTITY, &lu->mi_len); |
| 1047 | |
Holger Freyther | eaf0469 | 2009-06-06 13:54:44 +0000 | [diff] [blame] | 1048 | /* |
| 1049 | * Pseudo Spoof detection: Just drop a second/concurrent |
| 1050 | * location updating request. |
| 1051 | */ |
| 1052 | if (lchan->loc_operation) { |
Harald Welte | a036854 | 2009-06-27 02:58:43 +0200 | [diff] [blame] | 1053 | DEBUGPC(DMM, "ignoring request due an existing one: %p.\n", |
Holger Freyther | eaf0469 | 2009-06-06 13:54:44 +0000 | [diff] [blame] | 1054 | lchan->loc_operation); |
| 1055 | gsm0408_loc_upd_rej(lchan, GSM48_REJECT_PROTOCOL_ERROR); |
| 1056 | return 0; |
| 1057 | } |
| 1058 | |
Holger Freyther | 73487a2 | 2008-12-31 18:53:57 +0000 | [diff] [blame] | 1059 | allocate_loc_updating_req(lchan); |
| 1060 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1061 | switch (mi_type) { |
| 1062 | case GSM_MI_TYPE_IMSI: |
Harald Welte | a036854 | 2009-06-27 02:58:43 +0200 | [diff] [blame] | 1063 | DEBUGPC(DMM, "\n"); |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 1064 | /* we always want the IMEI, too */ |
Harald Welte | 015b9ad | 2009-02-28 18:22:03 +0000 | [diff] [blame] | 1065 | rc = mm_tx_identity_req(lchan, GSM_MI_TYPE_IMEI); |
Holger Freyther | 73487a2 | 2008-12-31 18:53:57 +0000 | [diff] [blame] | 1066 | lchan->loc_operation->waiting_for_imei = 1; |
Holger Freyther | c6ea9db | 2008-12-30 19:18:21 +0000 | [diff] [blame] | 1067 | |
Jan Luebbe | 370b41d | 2009-08-12 10:19:34 +0200 | [diff] [blame] | 1068 | /* look up subscriber based on IMSI, create if not found */ |
| 1069 | subscr = subscr_get_by_imsi(bts->network, mi_string); |
| 1070 | if (!subscr) { |
| 1071 | subscr = db_create_subscriber(bts->network, mi_string); |
| 1072 | } |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 1073 | break; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1074 | case GSM_MI_TYPE_TMSI: |
Harald Welte | a036854 | 2009-06-27 02:58:43 +0200 | [diff] [blame] | 1075 | DEBUGPC(DMM, "\n"); |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 1076 | /* we always want the IMEI, too */ |
Harald Welte | 015b9ad | 2009-02-28 18:22:03 +0000 | [diff] [blame] | 1077 | rc = mm_tx_identity_req(lchan, GSM_MI_TYPE_IMEI); |
Holger Freyther | 73487a2 | 2008-12-31 18:53:57 +0000 | [diff] [blame] | 1078 | lchan->loc_operation->waiting_for_imei = 1; |
Holger Freyther | c6ea9db | 2008-12-30 19:18:21 +0000 | [diff] [blame] | 1079 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1080 | /* look up the subscriber based on TMSI, request IMSI if it fails */ |
Holger Hans Peter Freyther | 2223025 | 2009-08-19 12:53:57 +0200 | [diff] [blame] | 1081 | subscr = subscr_get_by_tmsi(bts->network, |
| 1082 | tmsi_from_string(mi_string)); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1083 | if (!subscr) { |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 1084 | /* send IDENTITY REQUEST message to get IMSI */ |
Harald Welte | 255539c | 2008-12-28 02:26:27 +0000 | [diff] [blame] | 1085 | rc = mm_tx_identity_req(lchan, GSM_MI_TYPE_IMSI); |
Holger Freyther | 73487a2 | 2008-12-31 18:53:57 +0000 | [diff] [blame] | 1086 | lchan->loc_operation->waiting_for_imsi = 1; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1087 | } |
| 1088 | break; |
| 1089 | case GSM_MI_TYPE_IMEI: |
| 1090 | case GSM_MI_TYPE_IMEISV: |
| 1091 | /* no sim card... FIXME: what to do ? */ |
Harald Welte | a036854 | 2009-06-27 02:58:43 +0200 | [diff] [blame] | 1092 | DEBUGPC(DMM, "unimplemented mobile identity type\n"); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1093 | break; |
| 1094 | default: |
Harald Welte | a036854 | 2009-06-27 02:58:43 +0200 | [diff] [blame] | 1095 | DEBUGPC(DMM, "unknown mobile identity type\n"); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1096 | break; |
| 1097 | } |
| 1098 | |
Harald Welte | 24516ea | 2009-07-04 10:18:00 +0200 | [diff] [blame] | 1099 | /* schedule the reject timer */ |
| 1100 | schedule_reject(lchan); |
| 1101 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1102 | if (!subscr) { |
Harald Welte | a036854 | 2009-06-27 02:58:43 +0200 | [diff] [blame] | 1103 | DEBUGPC(DRR, "<- Can't find any subscriber for this ID\n"); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1104 | /* FIXME: request id? close channel? */ |
| 1105 | return -EINVAL; |
| 1106 | } |
| 1107 | |
Harald Welte | 255539c | 2008-12-28 02:26:27 +0000 | [diff] [blame] | 1108 | lchan->subscr = subscr; |
Harald Welte (local) | ee4410a | 2009-08-17 09:39:55 +0200 | [diff] [blame] | 1109 | lchan->subscr->equipment.classmark1 = lu->classmark1; |
Harald Welte | 255539c | 2008-12-28 02:26:27 +0000 | [diff] [blame] | 1110 | |
Harald Welte | 24516ea | 2009-07-04 10:18:00 +0200 | [diff] [blame] | 1111 | /* check if we can let the subscriber into our network immediately |
| 1112 | * or if we need to wait for identity responses. */ |
Holger Freyther | d51524f | 2009-06-09 08:27:07 +0000 | [diff] [blame] | 1113 | return gsm0408_authorize(lchan, msg); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1114 | } |
| 1115 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1116 | #if 0 |
| 1117 | static u_int8_t to_bcd8(u_int8_t val) |
| 1118 | { |
| 1119 | return ((val / 10) << 4) | (val % 10); |
| 1120 | } |
| 1121 | #endif |
| 1122 | |
Harald Welte | db253af | 2008-12-30 17:56:55 +0000 | [diff] [blame] | 1123 | /* Section 9.2.15a */ |
| 1124 | int gsm48_tx_mm_info(struct gsm_lchan *lchan) |
| 1125 | { |
| 1126 | struct msgb *msg = gsm48_msgb_alloc(); |
| 1127 | struct gsm48_hdr *gh; |
| 1128 | struct gsm_network *net = lchan->ts->trx->bts->network; |
Harald Welte | db253af | 2008-12-30 17:56:55 +0000 | [diff] [blame] | 1129 | u_int8_t *ptr8; |
Daniel Willmann | eea9337 | 2009-08-13 03:42:07 +0200 | [diff] [blame] | 1130 | int name_len, name_pad; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1131 | #if 0 |
| 1132 | time_t cur_t; |
| 1133 | struct tm* cur_time; |
| 1134 | int tz15min; |
| 1135 | #endif |
Harald Welte | db253af | 2008-12-30 17:56:55 +0000 | [diff] [blame] | 1136 | |
| 1137 | msg->lchan = lchan; |
| 1138 | |
| 1139 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 1140 | gh->proto_discr = GSM48_PDISC_MM; |
| 1141 | gh->msg_type = GSM48_MT_MM_INFO; |
| 1142 | |
| 1143 | if (net->name_long) { |
Daniel Willmann | eea9337 | 2009-08-13 03:42:07 +0200 | [diff] [blame] | 1144 | #if 0 |
Harald Welte | db253af | 2008-12-30 17:56:55 +0000 | [diff] [blame] | 1145 | name_len = strlen(net->name_long); |
| 1146 | /* 10.5.3.5a */ |
| 1147 | ptr8 = msgb_put(msg, 3); |
| 1148 | ptr8[0] = GSM48_IE_NAME_LONG; |
| 1149 | ptr8[1] = name_len*2 +1; |
| 1150 | ptr8[2] = 0x90; /* UCS2, no spare bits, no CI */ |
| 1151 | |
| 1152 | ptr16 = (u_int16_t *) msgb_put(msg, name_len*2); |
| 1153 | for (i = 0; i < name_len; i++) |
Harald Welte | 179f064 | 2008-12-31 23:59:18 +0000 | [diff] [blame] | 1154 | ptr16[i] = htons(net->name_long[i]); |
Harald Welte | db253af | 2008-12-30 17:56:55 +0000 | [diff] [blame] | 1155 | |
| 1156 | /* FIXME: Use Cell Broadcast, not UCS-2, since |
| 1157 | * UCS-2 is only supported by later revisions of the spec */ |
Daniel Willmann | eea9337 | 2009-08-13 03:42:07 +0200 | [diff] [blame] | 1158 | #endif |
| 1159 | name_len = (strlen(net->name_long)*7)/8; |
| 1160 | name_pad = (8 - strlen(net->name_long)*7)%8; |
| 1161 | if (name_pad > 0) |
| 1162 | name_len++; |
| 1163 | /* 10.5.3.5a */ |
| 1164 | ptr8 = msgb_put(msg, 3); |
| 1165 | ptr8[0] = GSM48_IE_NAME_LONG; |
| 1166 | ptr8[1] = name_len +1; |
| 1167 | ptr8[2] = 0x80 | name_pad; /* Cell Broadcast DCS, no CI */ |
| 1168 | |
| 1169 | ptr8 = msgb_put(msg, name_len); |
| 1170 | gsm_7bit_encode(ptr8, net->name_long); |
| 1171 | |
Harald Welte | db253af | 2008-12-30 17:56:55 +0000 | [diff] [blame] | 1172 | } |
| 1173 | |
| 1174 | if (net->name_short) { |
Daniel Willmann | eea9337 | 2009-08-13 03:42:07 +0200 | [diff] [blame] | 1175 | #if 0 |
Harald Welte | db253af | 2008-12-30 17:56:55 +0000 | [diff] [blame] | 1176 | name_len = strlen(net->name_short); |
| 1177 | /* 10.5.3.5a */ |
| 1178 | ptr8 = (u_int8_t *) msgb_put(msg, 3); |
Harald Welte | 7543eb7 | 2009-07-19 17:51:36 +0200 | [diff] [blame] | 1179 | ptr8[0] = GSM48_IE_NAME_SHORT; |
Harald Welte | db253af | 2008-12-30 17:56:55 +0000 | [diff] [blame] | 1180 | ptr8[1] = name_len*2 + 1; |
| 1181 | ptr8[2] = 0x90; /* UCS2, no spare bits, no CI */ |
| 1182 | |
Harald Welte | e872cb1 | 2009-01-01 00:33:37 +0000 | [diff] [blame] | 1183 | ptr16 = (u_int16_t *) msgb_put(msg, name_len*2); |
Harald Welte | db253af | 2008-12-30 17:56:55 +0000 | [diff] [blame] | 1184 | for (i = 0; i < name_len; i++) |
Harald Welte | 179f064 | 2008-12-31 23:59:18 +0000 | [diff] [blame] | 1185 | ptr16[i] = htons(net->name_short[i]); |
Daniel Willmann | eea9337 | 2009-08-13 03:42:07 +0200 | [diff] [blame] | 1186 | #endif |
| 1187 | name_len = (strlen(net->name_short)*7)/8; |
| 1188 | name_pad = (8 - strlen(net->name_short)*7)%8; |
| 1189 | if (name_pad > 0) |
| 1190 | name_len++; |
| 1191 | /* 10.5.3.5a */ |
| 1192 | ptr8 = (u_int8_t *) msgb_put(msg, 3); |
| 1193 | ptr8[0] = GSM48_IE_NAME_SHORT; |
| 1194 | ptr8[1] = name_len +1; |
| 1195 | ptr8[2] = 0x80 | name_pad; /* Cell Broadcast DCS, no CI */ |
| 1196 | |
| 1197 | ptr8 = msgb_put(msg, name_len); |
| 1198 | gsm_7bit_encode(ptr8, net->name_short); |
| 1199 | |
Harald Welte | db253af | 2008-12-30 17:56:55 +0000 | [diff] [blame] | 1200 | } |
| 1201 | |
| 1202 | #if 0 |
| 1203 | /* Section 10.5.3.9 */ |
| 1204 | cur_t = time(NULL); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1205 | cur_time = gmtime(&cur_t); |
Harald Welte | db253af | 2008-12-30 17:56:55 +0000 | [diff] [blame] | 1206 | ptr8 = msgb_put(msg, 8); |
| 1207 | ptr8[0] = GSM48_IE_NET_TIME_TZ; |
| 1208 | ptr8[1] = to_bcd8(cur_time->tm_year % 100); |
| 1209 | ptr8[2] = to_bcd8(cur_time->tm_mon); |
| 1210 | ptr8[3] = to_bcd8(cur_time->tm_mday); |
| 1211 | ptr8[4] = to_bcd8(cur_time->tm_hour); |
| 1212 | ptr8[5] = to_bcd8(cur_time->tm_min); |
| 1213 | ptr8[6] = to_bcd8(cur_time->tm_sec); |
| 1214 | /* 02.42: coded as BCD encoded signed value in units of 15 minutes */ |
| 1215 | tz15min = (cur_time->tm_gmtoff)/(60*15); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1216 | ptr8[7] = to_bcd8(tz15min); |
Harald Welte | db253af | 2008-12-30 17:56:55 +0000 | [diff] [blame] | 1217 | if (tz15min < 0) |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1218 | ptr8[7] |= 0x80; |
Harald Welte | db253af | 2008-12-30 17:56:55 +0000 | [diff] [blame] | 1219 | #endif |
| 1220 | |
Daniel Willmann | eea9337 | 2009-08-13 03:42:07 +0200 | [diff] [blame] | 1221 | DEBUGP(DMM, "-> MM INFO\n"); |
| 1222 | |
Harald Welte | 39e2ead | 2009-07-23 21:13:03 +0200 | [diff] [blame] | 1223 | return gsm48_sendmsg(msg, NULL); |
Harald Welte | db253af | 2008-12-30 17:56:55 +0000 | [diff] [blame] | 1224 | } |
| 1225 | |
Harald Welte | 7984d5c | 2009-08-12 22:56:50 +0200 | [diff] [blame] | 1226 | /* Section 9.2.2 */ |
| 1227 | int gsm48_tx_mm_auth_req(struct gsm_lchan *lchan, u_int8_t *rand) |
| 1228 | { |
| 1229 | struct msgb *msg = gsm48_msgb_alloc(); |
| 1230 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
Sylvain Munaut | 849f554 | 2009-09-27 11:10:17 +0200 | [diff] [blame] | 1231 | struct gsm48_auth_req *ar = (struct gsm48_auth_req *) msgb_put(msg, sizeof(*ar)); |
Harald Welte | 7984d5c | 2009-08-12 22:56:50 +0200 | [diff] [blame] | 1232 | |
| 1233 | DEBUGP(DMM, "-> AUTH REQ\n"); |
| 1234 | |
| 1235 | msg->lchan = lchan; |
| 1236 | gh->proto_discr = GSM48_PDISC_MM; |
| 1237 | gh->msg_type = GSM48_MT_MM_AUTH_REQ; |
| 1238 | |
Sylvain Munaut | 849f554 | 2009-09-27 11:10:17 +0200 | [diff] [blame] | 1239 | /* Key Sequence: FIXME fixed to 0 */ |
| 1240 | ar->key_seq = 0; |
| 1241 | |
Harald Welte | 7984d5c | 2009-08-12 22:56:50 +0200 | [diff] [blame] | 1242 | /* 16 bytes RAND parameters */ |
Harald Welte | 7984d5c | 2009-08-12 22:56:50 +0200 | [diff] [blame] | 1243 | if (rand) |
Sylvain Munaut | 849f554 | 2009-09-27 11:10:17 +0200 | [diff] [blame] | 1244 | memcpy(ar->rand, rand, 16); |
Harald Welte | 7984d5c | 2009-08-12 22:56:50 +0200 | [diff] [blame] | 1245 | |
| 1246 | return gsm48_sendmsg(msg, NULL); |
| 1247 | } |
| 1248 | |
| 1249 | /* Section 9.2.1 */ |
| 1250 | int gsm48_tx_mm_auth_rej(struct gsm_lchan *lchan) |
| 1251 | { |
| 1252 | DEBUGP(DMM, "-> AUTH REJECT\n"); |
| 1253 | return gsm48_tx_simple(lchan, GSM48_PDISC_MM, GSM48_MT_MM_AUTH_REJ); |
| 1254 | } |
| 1255 | |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 1256 | static int gsm48_tx_mm_serv_ack(struct gsm_lchan *lchan) |
| 1257 | { |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 1258 | DEBUGP(DMM, "-> CM SERVICE ACK\n"); |
Harald Welte | 65e74cc | 2008-12-29 01:55:35 +0000 | [diff] [blame] | 1259 | 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] | 1260 | } |
Harald Welte | ba4cf16 | 2009-01-10 01:49:35 +0000 | [diff] [blame] | 1261 | |
| 1262 | /* 9.2.6 CM service reject */ |
| 1263 | static int gsm48_tx_mm_serv_rej(struct gsm_lchan *lchan, |
| 1264 | enum gsm48_reject_value value) |
| 1265 | { |
| 1266 | struct msgb *msg = gsm48_msgb_alloc(); |
| 1267 | struct gsm48_hdr *gh; |
| 1268 | |
| 1269 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 1); |
| 1270 | |
| 1271 | msg->lchan = lchan; |
| 1272 | use_lchan(lchan); |
| 1273 | |
| 1274 | gh->proto_discr = GSM48_PDISC_MM; |
| 1275 | gh->msg_type = GSM48_MT_MM_CM_SERV_REJ; |
| 1276 | gh->data[0] = value; |
| 1277 | DEBUGP(DMM, "-> CM SERVICE Reject cause: %d\n", value); |
| 1278 | |
Harald Welte | 39e2ead | 2009-07-23 21:13:03 +0200 | [diff] [blame] | 1279 | return gsm48_sendmsg(msg, NULL); |
Harald Welte | ba4cf16 | 2009-01-10 01:49:35 +0000 | [diff] [blame] | 1280 | } |
| 1281 | |
Harald Welte | 4ed0e92 | 2009-01-10 03:17:30 +0000 | [diff] [blame] | 1282 | /* |
| 1283 | * Handle CM Service Requests |
| 1284 | * a) Verify that the packet is long enough to contain the information |
| 1285 | * we require otherwsie reject with INCORRECT_MESSAGE |
| 1286 | * b) Try to parse the TMSI. If we do not have one reject |
| 1287 | * c) Check that we know the subscriber with the TMSI otherwise reject |
| 1288 | * with a HLR cause |
| 1289 | * d) Set the subscriber on the gsm_lchan and accept |
| 1290 | */ |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 1291 | static int gsm48_rx_mm_serv_req(struct msgb *msg) |
| 1292 | { |
Harald Welte | ba4cf16 | 2009-01-10 01:49:35 +0000 | [diff] [blame] | 1293 | u_int8_t mi_type; |
Holger Hans Peter Freyther | d1862d7 | 2009-08-19 07:54:59 +0200 | [diff] [blame] | 1294 | char mi_string[GSM48_MI_SIZE]; |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 1295 | |
Harald Welte | 9176bd4 | 2009-07-23 18:46:00 +0200 | [diff] [blame] | 1296 | struct gsm_bts *bts = msg->lchan->ts->trx->bts; |
Harald Welte | ba4cf16 | 2009-01-10 01:49:35 +0000 | [diff] [blame] | 1297 | struct gsm_subscriber *subscr; |
| 1298 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 1299 | struct gsm48_service_request *req = |
| 1300 | (struct gsm48_service_request *)gh->data; |
Harald Welte | c9e0218 | 2009-05-01 19:07:53 +0000 | [diff] [blame] | 1301 | /* unfortunately in Phase1 the classmar2 length is variable */ |
| 1302 | u_int8_t classmark2_len = gh->data[1]; |
| 1303 | u_int8_t *classmark2 = gh->data+2; |
| 1304 | u_int8_t mi_len = *(classmark2 + classmark2_len); |
| 1305 | u_int8_t *mi = (classmark2 + classmark2_len + 1); |
Harald Welte | ba4cf16 | 2009-01-10 01:49:35 +0000 | [diff] [blame] | 1306 | |
Harald Welte | c9e0218 | 2009-05-01 19:07:53 +0000 | [diff] [blame] | 1307 | DEBUGP(DMM, "<- CM SERVICE REQUEST "); |
Harald Welte | ba4cf16 | 2009-01-10 01:49:35 +0000 | [diff] [blame] | 1308 | if (msg->data_len < sizeof(struct gsm48_service_request*)) { |
Harald Welte | c9e0218 | 2009-05-01 19:07:53 +0000 | [diff] [blame] | 1309 | DEBUGPC(DMM, "wrong sized message\n"); |
Harald Welte | ba4cf16 | 2009-01-10 01:49:35 +0000 | [diff] [blame] | 1310 | return gsm48_tx_mm_serv_rej(msg->lchan, |
| 1311 | GSM48_REJECT_INCORRECT_MESSAGE); |
| 1312 | } |
| 1313 | |
| 1314 | if (msg->data_len < req->mi_len + 6) { |
Harald Welte | c9e0218 | 2009-05-01 19:07:53 +0000 | [diff] [blame] | 1315 | DEBUGPC(DMM, "does not fit in packet\n"); |
Harald Welte | ba4cf16 | 2009-01-10 01:49:35 +0000 | [diff] [blame] | 1316 | return gsm48_tx_mm_serv_rej(msg->lchan, |
| 1317 | GSM48_REJECT_INCORRECT_MESSAGE); |
| 1318 | } |
| 1319 | |
Harald Welte | c9e0218 | 2009-05-01 19:07:53 +0000 | [diff] [blame] | 1320 | mi_type = mi[0] & GSM_MI_TYPE_MASK; |
Harald Welte | ba4cf16 | 2009-01-10 01:49:35 +0000 | [diff] [blame] | 1321 | if (mi_type != GSM_MI_TYPE_TMSI) { |
Harald Welte | c9e0218 | 2009-05-01 19:07:53 +0000 | [diff] [blame] | 1322 | DEBUGPC(DMM, "mi_type is not TMSI: %d\n", mi_type); |
Harald Welte | ba4cf16 | 2009-01-10 01:49:35 +0000 | [diff] [blame] | 1323 | return gsm48_tx_mm_serv_rej(msg->lchan, |
| 1324 | GSM48_REJECT_INCORRECT_MESSAGE); |
| 1325 | } |
| 1326 | |
Holger Hans Peter Freyther | d1862d7 | 2009-08-19 07:54:59 +0200 | [diff] [blame] | 1327 | gsm48_mi_to_string(mi_string, sizeof(mi_string), mi, mi_len); |
Harald Welte | c9e0218 | 2009-05-01 19:07:53 +0000 | [diff] [blame] | 1328 | 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] | 1329 | req->cm_service_type, mi_type, mi_string); |
Harald Welte | bcae43f | 2008-12-27 21:45:37 +0000 | [diff] [blame] | 1330 | |
Harald Welte | 7659de1 | 2009-12-13 12:39:18 +0100 | [diff] [blame] | 1331 | dispatch_signal(SS_SUBSCR, S_SUBSCR_IDENTITY, (classmark2 + classmark2_len)); |
| 1332 | |
Harald Welte | 3ac7f10 | 2009-08-10 10:12:45 +0200 | [diff] [blame] | 1333 | if (is_siemens_bts(bts)) |
| 1334 | send_siemens_mrpci(msg->lchan, classmark2-1); |
| 1335 | |
Holger Hans Peter Freyther | 2223025 | 2009-08-19 12:53:57 +0200 | [diff] [blame] | 1336 | subscr = subscr_get_by_tmsi(bts->network, |
| 1337 | tmsi_from_string(mi_string)); |
Holger Freyther | eb44398 | 2009-06-04 13:58:42 +0000 | [diff] [blame] | 1338 | |
Harald Welte | 2a13937 | 2009-02-22 21:14:55 +0000 | [diff] [blame] | 1339 | /* 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] | 1340 | if (!subscr) |
| 1341 | return gsm48_tx_mm_serv_rej(msg->lchan, |
| 1342 | GSM48_REJECT_IMSI_UNKNOWN_IN_HLR); |
| 1343 | |
| 1344 | if (!msg->lchan->subscr) |
| 1345 | msg->lchan->subscr = subscr; |
Sylvain Munaut | ea3f674 | 2009-12-18 18:28:10 +0100 | [diff] [blame] | 1346 | else if (msg->lchan->subscr == subscr) |
| 1347 | subscr_put(subscr); /* lchan already has a ref, don't need another one */ |
| 1348 | else { |
Harald Welte | 9bb7c70 | 2009-01-10 03:21:41 +0000 | [diff] [blame] | 1349 | DEBUGP(DMM, "<- CM Channel already owned by someone else?\n"); |
| 1350 | subscr_put(subscr); |
| 1351 | } |
| 1352 | |
Harald Welte | c2e302d | 2009-07-05 14:08:13 +0200 | [diff] [blame] | 1353 | subscr->equipment.classmark2_len = classmark2_len; |
| 1354 | memcpy(subscr->equipment.classmark2, classmark2, classmark2_len); |
| 1355 | db_sync_equipment(&subscr->equipment); |
Harald Welte | f7c4352 | 2009-06-09 20:24:21 +0000 | [diff] [blame] | 1356 | |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 1357 | return gsm48_tx_mm_serv_ack(msg->lchan); |
| 1358 | } |
| 1359 | |
Harald Welte | 2a13937 | 2009-02-22 21:14:55 +0000 | [diff] [blame] | 1360 | static int gsm48_rx_mm_imsi_detach_ind(struct msgb *msg) |
| 1361 | { |
Harald Welte | 9176bd4 | 2009-07-23 18:46:00 +0200 | [diff] [blame] | 1362 | struct gsm_bts *bts = msg->lchan->ts->trx->bts; |
Harald Welte | 2a13937 | 2009-02-22 21:14:55 +0000 | [diff] [blame] | 1363 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 1364 | struct gsm48_imsi_detach_ind *idi = |
| 1365 | (struct gsm48_imsi_detach_ind *) gh->data; |
| 1366 | u_int8_t mi_type = idi->mi[0] & GSM_MI_TYPE_MASK; |
Holger Hans Peter Freyther | d1862d7 | 2009-08-19 07:54:59 +0200 | [diff] [blame] | 1367 | char mi_string[GSM48_MI_SIZE]; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1368 | struct gsm_subscriber *subscr = NULL; |
Harald Welte | 2a13937 | 2009-02-22 21:14:55 +0000 | [diff] [blame] | 1369 | |
Holger Hans Peter Freyther | d1862d7 | 2009-08-19 07:54:59 +0200 | [diff] [blame] | 1370 | gsm48_mi_to_string(mi_string, sizeof(mi_string), idi->mi, idi->mi_len); |
Harald Welte | 2a13937 | 2009-02-22 21:14:55 +0000 | [diff] [blame] | 1371 | DEBUGP(DMM, "IMSI DETACH INDICATION: mi_type=0x%02x MI(%s): ", |
| 1372 | mi_type, mi_string); |
| 1373 | |
| 1374 | switch (mi_type) { |
| 1375 | case GSM_MI_TYPE_TMSI: |
Holger Hans Peter Freyther | 2223025 | 2009-08-19 12:53:57 +0200 | [diff] [blame] | 1376 | subscr = subscr_get_by_tmsi(bts->network, |
| 1377 | tmsi_from_string(mi_string)); |
Harald Welte | 2a13937 | 2009-02-22 21:14:55 +0000 | [diff] [blame] | 1378 | break; |
| 1379 | case GSM_MI_TYPE_IMSI: |
Harald Welte | 9176bd4 | 2009-07-23 18:46:00 +0200 | [diff] [blame] | 1380 | subscr = subscr_get_by_imsi(bts->network, mi_string); |
Harald Welte | 2a13937 | 2009-02-22 21:14:55 +0000 | [diff] [blame] | 1381 | break; |
| 1382 | case GSM_MI_TYPE_IMEI: |
| 1383 | case GSM_MI_TYPE_IMEISV: |
| 1384 | /* no sim card... FIXME: what to do ? */ |
Holger Freyther | 79f4ae6 | 2009-06-02 03:25:04 +0000 | [diff] [blame] | 1385 | DEBUGPC(DMM, "unimplemented mobile identity type\n"); |
Harald Welte | 2a13937 | 2009-02-22 21:14:55 +0000 | [diff] [blame] | 1386 | break; |
| 1387 | default: |
Holger Freyther | 79f4ae6 | 2009-06-02 03:25:04 +0000 | [diff] [blame] | 1388 | DEBUGPC(DMM, "unknown mobile identity type\n"); |
Harald Welte | 2a13937 | 2009-02-22 21:14:55 +0000 | [diff] [blame] | 1389 | break; |
| 1390 | } |
| 1391 | |
Holger Freyther | 4a49e77 | 2009-04-12 05:37:29 +0000 | [diff] [blame] | 1392 | if (subscr) { |
| 1393 | subscr_update(subscr, msg->trx->bts, |
| 1394 | GSM_SUBSCRIBER_UPDATE_DETACHED); |
Harald Welte | 2a13937 | 2009-02-22 21:14:55 +0000 | [diff] [blame] | 1395 | DEBUGP(DMM, "Subscriber: %s\n", |
| 1396 | subscr->name ? subscr->name : subscr->imsi); |
Harald Welte (local) | ee4410a | 2009-08-17 09:39:55 +0200 | [diff] [blame] | 1397 | |
| 1398 | subscr->equipment.classmark1 = idi->classmark1; |
| 1399 | db_sync_equipment(&subscr->equipment); |
| 1400 | |
Holger Freyther | c21cfbc | 2009-06-02 02:54:57 +0000 | [diff] [blame] | 1401 | subscr_put(subscr); |
Holger Freyther | 4a49e77 | 2009-04-12 05:37:29 +0000 | [diff] [blame] | 1402 | } else |
Harald Welte | 2a13937 | 2009-02-22 21:14:55 +0000 | [diff] [blame] | 1403 | DEBUGP(DMM, "Unknown Subscriber ?!?\n"); |
| 1404 | |
Harald Welte | b83d938 | 2009-12-12 21:00:48 +0100 | [diff] [blame] | 1405 | /* subscriber is detached: should we release lchan? */ |
| 1406 | |
Harald Welte | 2a13937 | 2009-02-22 21:14:55 +0000 | [diff] [blame] | 1407 | return 0; |
| 1408 | } |
| 1409 | |
Harald Welte | d2a7f5a | 2009-06-05 20:08:20 +0000 | [diff] [blame] | 1410 | static int gsm48_rx_mm_status(struct msgb *msg) |
| 1411 | { |
| 1412 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 1413 | |
| 1414 | DEBUGP(DMM, "MM STATUS (reject cause 0x%02x)\n", gh->data[0]); |
| 1415 | |
| 1416 | return 0; |
| 1417 | } |
| 1418 | |
Harald Welte | bf5e8df | 2009-02-03 12:59:45 +0000 | [diff] [blame] | 1419 | /* Receive a GSM 04.08 Mobility Management (MM) message */ |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1420 | static int gsm0408_rcv_mm(struct msgb *msg) |
| 1421 | { |
| 1422 | struct gsm48_hdr *gh = msgb_l3(msg); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1423 | int rc = 0; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1424 | |
| 1425 | switch (gh->msg_type & 0xbf) { |
| 1426 | case GSM48_MT_MM_LOC_UPD_REQUEST: |
Harald Welte | a036854 | 2009-06-27 02:58:43 +0200 | [diff] [blame] | 1427 | DEBUGP(DMM, "LOCATION UPDATING REQUEST: "); |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 1428 | rc = mm_rx_loc_upd_req(msg); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1429 | break; |
| 1430 | case GSM48_MT_MM_ID_RESP: |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 1431 | rc = mm_rx_id_resp(msg); |
| 1432 | break; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1433 | case GSM48_MT_MM_CM_SERV_REQ: |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 1434 | rc = gsm48_rx_mm_serv_req(msg); |
| 1435 | break; |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 1436 | case GSM48_MT_MM_STATUS: |
Harald Welte | d2a7f5a | 2009-06-05 20:08:20 +0000 | [diff] [blame] | 1437 | rc = gsm48_rx_mm_status(msg); |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 1438 | break; |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 1439 | case GSM48_MT_MM_TMSI_REALL_COMPL: |
Harald Welte | 69b2af2 | 2009-01-06 19:47:00 +0000 | [diff] [blame] | 1440 | DEBUGP(DMM, "TMSI Reallocation Completed. Subscriber: %s\n", |
| 1441 | msg->lchan->subscr ? |
| 1442 | msg->lchan->subscr->imsi : |
| 1443 | "unknown subscriber"); |
| 1444 | break; |
Harald Welte | 231ad4f | 2008-12-27 11:15:38 +0000 | [diff] [blame] | 1445 | case GSM48_MT_MM_IMSI_DETACH_IND: |
Harald Welte | 2a13937 | 2009-02-22 21:14:55 +0000 | [diff] [blame] | 1446 | rc = gsm48_rx_mm_imsi_detach_ind(msg); |
| 1447 | break; |
| 1448 | case GSM48_MT_MM_CM_REEST_REQ: |
| 1449 | DEBUGP(DMM, "CM REESTABLISH REQUEST: Not implemented\n"); |
| 1450 | break; |
| 1451 | case GSM48_MT_MM_AUTH_RESP: |
| 1452 | DEBUGP(DMM, "AUTHENTICATION RESPONSE: Not implemented\n"); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1453 | break; |
| 1454 | default: |
| 1455 | fprintf(stderr, "Unknown GSM 04.08 MM msg type 0x%02x\n", |
| 1456 | gh->msg_type); |
| 1457 | break; |
| 1458 | } |
| 1459 | |
| 1460 | return rc; |
| 1461 | } |
Harald Welte | bf5e8df | 2009-02-03 12:59:45 +0000 | [diff] [blame] | 1462 | |
Harald Welte | 2d35ae6 | 2009-02-06 12:02:13 +0000 | [diff] [blame] | 1463 | /* Receive a PAGING RESPONSE message from the MS */ |
Holger Hans Peter Freyther | ca0fcbe | 2009-10-23 13:48:54 +0200 | [diff] [blame] | 1464 | static int gsm48_rx_rr_pag_resp(struct msgb *msg) |
Harald Welte | 2d35ae6 | 2009-02-06 12:02:13 +0000 | [diff] [blame] | 1465 | { |
Harald Welte | 9176bd4 | 2009-07-23 18:46:00 +0200 | [diff] [blame] | 1466 | struct gsm_bts *bts = msg->lchan->ts->trx->bts; |
Harald Welte | 2d35ae6 | 2009-02-06 12:02:13 +0000 | [diff] [blame] | 1467 | struct gsm48_hdr *gh = msgb_l3(msg); |
Harald Welte | 6154898 | 2009-02-22 21:26:29 +0000 | [diff] [blame] | 1468 | u_int8_t *classmark2_lv = gh->data + 1; |
Holger Hans Peter Freyther | 3ee5d3e | 2009-08-21 05:18:21 +0200 | [diff] [blame] | 1469 | u_int8_t mi_type; |
Holger Hans Peter Freyther | d1862d7 | 2009-08-19 07:54:59 +0200 | [diff] [blame] | 1470 | char mi_string[GSM48_MI_SIZE]; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1471 | struct gsm_subscriber *subscr = NULL; |
Harald Welte | 2d35ae6 | 2009-02-06 12:02:13 +0000 | [diff] [blame] | 1472 | int rc = 0; |
| 1473 | |
Holger Hans Peter Freyther | 3ee5d3e | 2009-08-21 05:18:21 +0200 | [diff] [blame] | 1474 | gsm48_paging_extract_mi(msg, mi_string, &mi_type); |
Harald Welte | 2d35ae6 | 2009-02-06 12:02:13 +0000 | [diff] [blame] | 1475 | DEBUGP(DRR, "PAGING RESPONSE: mi_type=0x%02x MI(%s)\n", |
| 1476 | mi_type, mi_string); |
Harald Welte | 3ac7f10 | 2009-08-10 10:12:45 +0200 | [diff] [blame] | 1477 | |
Harald Welte | fe18d8f | 2009-02-22 21:14:24 +0000 | [diff] [blame] | 1478 | switch (mi_type) { |
| 1479 | case GSM_MI_TYPE_TMSI: |
Holger Hans Peter Freyther | 2223025 | 2009-08-19 12:53:57 +0200 | [diff] [blame] | 1480 | subscr = subscr_get_by_tmsi(bts->network, |
| 1481 | tmsi_from_string(mi_string)); |
Harald Welte | fe18d8f | 2009-02-22 21:14:24 +0000 | [diff] [blame] | 1482 | break; |
| 1483 | case GSM_MI_TYPE_IMSI: |
Harald Welte | 9176bd4 | 2009-07-23 18:46:00 +0200 | [diff] [blame] | 1484 | subscr = subscr_get_by_imsi(bts->network, mi_string); |
Harald Welte | fe18d8f | 2009-02-22 21:14:24 +0000 | [diff] [blame] | 1485 | break; |
| 1486 | } |
Harald Welte | 2d35ae6 | 2009-02-06 12:02:13 +0000 | [diff] [blame] | 1487 | |
| 1488 | if (!subscr) { |
| 1489 | DEBUGP(DRR, "<- Can't find any subscriber for this ID\n"); |
Harald Welte | 09e38af | 2009-02-16 22:52:23 +0000 | [diff] [blame] | 1490 | /* FIXME: request id? close channel? */ |
Harald Welte | 2d35ae6 | 2009-02-06 12:02:13 +0000 | [diff] [blame] | 1491 | return -EINVAL; |
| 1492 | } |
| 1493 | DEBUGP(DRR, "<- Channel was requested by %s\n", |
Harald Welte | 7604218 | 2009-08-08 16:03:15 +0200 | [diff] [blame] | 1494 | subscr->name && strlen(subscr->name) ? subscr->name : subscr->imsi); |
Holger Freyther | 053e09d | 2009-02-14 22:51:06 +0000 | [diff] [blame] | 1495 | |
Harald Welte | c2e302d | 2009-07-05 14:08:13 +0200 | [diff] [blame] | 1496 | subscr->equipment.classmark2_len = *classmark2_lv; |
| 1497 | memcpy(subscr->equipment.classmark2, classmark2_lv+1, *classmark2_lv); |
| 1498 | db_sync_equipment(&subscr->equipment); |
Harald Welte | f7c4352 | 2009-06-09 20:24:21 +0000 | [diff] [blame] | 1499 | |
Holger Hans Peter Freyther | 3ee5d3e | 2009-08-21 05:18:21 +0200 | [diff] [blame] | 1500 | rc = gsm48_handle_paging_resp(msg, subscr); |
Harald Welte | 2d35ae6 | 2009-02-06 12:02:13 +0000 | [diff] [blame] | 1501 | return rc; |
| 1502 | } |
| 1503 | |
Harald Welte | f7c4352 | 2009-06-09 20:24:21 +0000 | [diff] [blame] | 1504 | static int gsm48_rx_rr_classmark(struct msgb *msg) |
| 1505 | { |
| 1506 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 1507 | struct gsm_subscriber *subscr = msg->lchan->subscr; |
| 1508 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 1509 | u_int8_t cm2_len, cm3_len = 0; |
| 1510 | u_int8_t *cm2, *cm3 = NULL; |
| 1511 | |
| 1512 | DEBUGP(DRR, "CLASSMARK CHANGE "); |
| 1513 | |
| 1514 | /* classmark 2 */ |
| 1515 | cm2_len = gh->data[0]; |
| 1516 | cm2 = &gh->data[1]; |
| 1517 | DEBUGPC(DRR, "CM2(len=%u) ", cm2_len); |
| 1518 | |
| 1519 | if (payload_len > cm2_len + 1) { |
| 1520 | /* we must have a classmark3 */ |
| 1521 | if (gh->data[cm2_len+1] != 0x20) { |
| 1522 | DEBUGPC(DRR, "ERR CM3 TAG\n"); |
| 1523 | return -EINVAL; |
| 1524 | } |
| 1525 | if (cm2_len > 3) { |
| 1526 | DEBUGPC(DRR, "CM2 too long!\n"); |
| 1527 | return -EINVAL; |
| 1528 | } |
| 1529 | |
| 1530 | cm3_len = gh->data[cm2_len+2]; |
| 1531 | cm3 = &gh->data[cm2_len+3]; |
| 1532 | if (cm3_len > 14) { |
| 1533 | DEBUGPC(DRR, "CM3 len %u too long!\n", cm3_len); |
| 1534 | return -EINVAL; |
| 1535 | } |
| 1536 | DEBUGPC(DRR, "CM3(len=%u)\n", cm3_len); |
| 1537 | } |
| 1538 | if (subscr) { |
Harald Welte | c2e302d | 2009-07-05 14:08:13 +0200 | [diff] [blame] | 1539 | subscr->equipment.classmark2_len = cm2_len; |
| 1540 | memcpy(subscr->equipment.classmark2, cm2, cm2_len); |
Harald Welte | f7c4352 | 2009-06-09 20:24:21 +0000 | [diff] [blame] | 1541 | if (cm3) { |
Harald Welte | c2e302d | 2009-07-05 14:08:13 +0200 | [diff] [blame] | 1542 | subscr->equipment.classmark3_len = cm3_len; |
| 1543 | memcpy(subscr->equipment.classmark3, cm3, cm3_len); |
Harald Welte | f7c4352 | 2009-06-09 20:24:21 +0000 | [diff] [blame] | 1544 | } |
Harald Welte | c2e302d | 2009-07-05 14:08:13 +0200 | [diff] [blame] | 1545 | db_sync_equipment(&subscr->equipment); |
Harald Welte | f7c4352 | 2009-06-09 20:24:21 +0000 | [diff] [blame] | 1546 | } |
| 1547 | |
Harald Welte | f7c4352 | 2009-06-09 20:24:21 +0000 | [diff] [blame] | 1548 | return 0; |
| 1549 | } |
| 1550 | |
Harald Welte | cf5b359 | 2009-05-01 18:28:42 +0000 | [diff] [blame] | 1551 | static int gsm48_rx_rr_status(struct msgb *msg) |
| 1552 | { |
| 1553 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 1554 | |
| 1555 | DEBUGP(DRR, "STATUS rr_cause = %s\n", |
| 1556 | rr_cause_name(gh->data[0])); |
| 1557 | |
| 1558 | return 0; |
| 1559 | } |
| 1560 | |
Harald Welte | f7c4352 | 2009-06-09 20:24:21 +0000 | [diff] [blame] | 1561 | static int gsm48_rx_rr_meas_rep(struct msgb *msg) |
| 1562 | { |
Harald Welte | d12b0fd | 2009-12-15 21:36:05 +0100 | [diff] [blame] | 1563 | struct gsm_meas_rep *meas_rep = lchan_next_meas_rep(msg->lchan); |
Harald Welte | f7c4352 | 2009-06-09 20:24:21 +0000 | [diff] [blame] | 1564 | |
Harald Welte | 3c7dc6e | 2009-11-29 19:07:28 +0100 | [diff] [blame] | 1565 | /* This shouldn't actually end up here, as RSL treats |
| 1566 | * L3 Info of 08.58 MEASUREMENT REPORT different by calling |
| 1567 | * directly into gsm48_parse_meas_rep */ |
| 1568 | DEBUGP(DMEAS, "DIRECT GSM48 MEASUREMENT REPORT ?!? "); |
Harald Welte | d12b0fd | 2009-12-15 21:36:05 +0100 | [diff] [blame] | 1569 | gsm48_parse_meas_rep(meas_rep, msg); |
Harald Welte | f7c4352 | 2009-06-09 20:24:21 +0000 | [diff] [blame] | 1570 | |
| 1571 | return 0; |
| 1572 | } |
| 1573 | |
Harald Welte (local) | 6eef564 | 2009-08-15 23:32:44 +0200 | [diff] [blame] | 1574 | static int gsm48_rx_rr_app_info(struct msgb *msg) |
| 1575 | { |
| 1576 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 1577 | u_int8_t apdu_id_flags; |
| 1578 | u_int8_t apdu_len; |
| 1579 | u_int8_t *apdu_data; |
| 1580 | |
| 1581 | apdu_id_flags = gh->data[0]; |
| 1582 | apdu_len = gh->data[1]; |
| 1583 | apdu_data = gh->data+2; |
| 1584 | |
| 1585 | DEBUGP(DNM, "RX APPLICATION INFO id/flags=0x%02x apdu_len=%u apdu=%s", |
| 1586 | apdu_id_flags, apdu_len, hexdump(apdu_data, apdu_len)); |
| 1587 | |
Harald Welte (local) | 026531e | 2009-08-16 10:40:10 +0200 | [diff] [blame] | 1588 | return db_apdu_blob_store(msg->lchan->subscr, apdu_id_flags, apdu_len, apdu_data); |
Harald Welte (local) | 6eef564 | 2009-08-15 23:32:44 +0200 | [diff] [blame] | 1589 | } |
| 1590 | |
Harald Welte | d011e8b | 2009-11-29 22:45:52 +0100 | [diff] [blame] | 1591 | /* Chapter 9.1.16 Handover complete */ |
Harald Welte | 1e191c5 | 2009-12-14 17:51:15 +0100 | [diff] [blame] | 1592 | static int gsm48_rx_rr_ho_compl(struct msgb *msg) |
Harald Welte | d011e8b | 2009-11-29 22:45:52 +0100 | [diff] [blame] | 1593 | { |
| 1594 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 1595 | |
| 1596 | DEBUGP(DRR, "HANDOVER COMPLETE cause = %s\n", |
| 1597 | rr_cause_name(gh->data[0])); |
| 1598 | |
| 1599 | dispatch_signal(SS_LCHAN, S_LCHAN_HANDOVER_COMPL, msg->lchan); |
| 1600 | /* FIXME: release old channel */ |
| 1601 | |
| 1602 | return 0; |
| 1603 | } |
| 1604 | |
| 1605 | /* Chapter 9.1.17 Handover Failure */ |
Harald Welte | 1e191c5 | 2009-12-14 17:51:15 +0100 | [diff] [blame] | 1606 | static int gsm48_rx_rr_ho_fail(struct msgb *msg) |
Harald Welte | d011e8b | 2009-11-29 22:45:52 +0100 | [diff] [blame] | 1607 | { |
| 1608 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 1609 | |
| 1610 | DEBUGP(DRR, "HANDOVER FAILED cause = %s\n", |
| 1611 | rr_cause_name(gh->data[0])); |
| 1612 | |
| 1613 | dispatch_signal(SS_LCHAN, S_LCHAN_HANDOVER_FAIL, msg->lchan); |
| 1614 | /* FIXME: release allocated new channel */ |
| 1615 | |
| 1616 | return 0; |
| 1617 | } |
Harald Welte (local) | 6eef564 | 2009-08-15 23:32:44 +0200 | [diff] [blame] | 1618 | |
Harald Welte | bf5e8df | 2009-02-03 12:59:45 +0000 | [diff] [blame] | 1619 | /* Receive a GSM 04.08 Radio Resource (RR) message */ |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1620 | static int gsm0408_rcv_rr(struct msgb *msg) |
| 1621 | { |
| 1622 | struct gsm48_hdr *gh = msgb_l3(msg); |
Harald Welte | 2d35ae6 | 2009-02-06 12:02:13 +0000 | [diff] [blame] | 1623 | int rc = 0; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1624 | |
| 1625 | switch (gh->msg_type) { |
| 1626 | case GSM48_MT_RR_CLSM_CHG: |
Harald Welte | f7c4352 | 2009-06-09 20:24:21 +0000 | [diff] [blame] | 1627 | rc = gsm48_rx_rr_classmark(msg); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1628 | break; |
Harald Welte | fc977a8 | 2008-12-27 10:19:37 +0000 | [diff] [blame] | 1629 | case GSM48_MT_RR_GPRS_SUSP_REQ: |
| 1630 | DEBUGP(DRR, "GRPS SUSPEND REQUEST\n"); |
| 1631 | break; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1632 | case GSM48_MT_RR_PAG_RESP: |
Holger Hans Peter Freyther | ca0fcbe | 2009-10-23 13:48:54 +0200 | [diff] [blame] | 1633 | rc = gsm48_rx_rr_pag_resp(msg); |
Harald Welte | 2d35ae6 | 2009-02-06 12:02:13 +0000 | [diff] [blame] | 1634 | break; |
Harald Welte | 7ccf778 | 2009-02-17 01:43:01 +0000 | [diff] [blame] | 1635 | case GSM48_MT_RR_CHAN_MODE_MODIF_ACK: |
Holger Hans Peter Freyther | f520e64 | 2009-10-22 15:23:11 +0200 | [diff] [blame] | 1636 | rc = gsm48_rx_rr_modif_ack(msg); |
Harald Welte | 7ccf778 | 2009-02-17 01:43:01 +0000 | [diff] [blame] | 1637 | break; |
Harald Welte | cf5b359 | 2009-05-01 18:28:42 +0000 | [diff] [blame] | 1638 | case GSM48_MT_RR_STATUS: |
| 1639 | rc = gsm48_rx_rr_status(msg); |
| 1640 | break; |
Harald Welte | f7c4352 | 2009-06-09 20:24:21 +0000 | [diff] [blame] | 1641 | case GSM48_MT_RR_MEAS_REP: |
| 1642 | rc = gsm48_rx_rr_meas_rep(msg); |
| 1643 | break; |
Harald Welte (local) | 6eef564 | 2009-08-15 23:32:44 +0200 | [diff] [blame] | 1644 | case GSM48_MT_RR_APP_INFO: |
| 1645 | rc = gsm48_rx_rr_app_info(msg); |
| 1646 | break; |
Harald Welte | 08d91a5 | 2009-08-30 15:37:11 +0900 | [diff] [blame] | 1647 | case GSM48_MT_RR_CIPH_M_COMPL: |
| 1648 | DEBUGP(DRR, "CIPHERING MODE COMPLETE\n"); |
| 1649 | /* FIXME: check for MI (if any) */ |
| 1650 | break; |
Harald Welte | ccd5a88 | 2009-11-29 20:02:20 +0100 | [diff] [blame] | 1651 | case GSM48_MT_RR_HANDO_COMPL: |
Harald Welte | d011e8b | 2009-11-29 22:45:52 +0100 | [diff] [blame] | 1652 | rc = gsm48_rx_rr_ho_compl(msg); |
Harald Welte | ccd5a88 | 2009-11-29 20:02:20 +0100 | [diff] [blame] | 1653 | break; |
| 1654 | case GSM48_MT_RR_HANDO_FAIL: |
Harald Welte | d011e8b | 2009-11-29 22:45:52 +0100 | [diff] [blame] | 1655 | rc = gsm48_rx_rr_ho_fail(msg); |
Harald Welte | ccd5a88 | 2009-11-29 20:02:20 +0100 | [diff] [blame] | 1656 | break; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1657 | default: |
Harald Welte | 2d35ae6 | 2009-02-06 12:02:13 +0000 | [diff] [blame] | 1658 | fprintf(stderr, "Unimplemented GSM 04.08 RR msg type 0x%02x\n", |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1659 | gh->msg_type); |
| 1660 | break; |
| 1661 | } |
| 1662 | |
Harald Welte | 2d35ae6 | 2009-02-06 12:02:13 +0000 | [diff] [blame] | 1663 | return rc; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1664 | } |
| 1665 | |
Harald Welte (local) | 6eef564 | 2009-08-15 23:32:44 +0200 | [diff] [blame] | 1666 | int gsm48_send_rr_app_info(struct gsm_lchan *lchan, u_int8_t apdu_id, |
Holger Hans Peter Freyther | 8b77a34 | 2009-10-22 15:42:19 +0200 | [diff] [blame] | 1667 | u_int8_t apdu_len, const u_int8_t *apdu) |
Harald Welte (local) | 6eef564 | 2009-08-15 23:32:44 +0200 | [diff] [blame] | 1668 | { |
| 1669 | struct msgb *msg = gsm48_msgb_alloc(); |
| 1670 | struct gsm48_hdr *gh; |
| 1671 | |
| 1672 | msg->lchan = lchan; |
| 1673 | |
| 1674 | DEBUGP(DRR, "TX APPLICATION INFO id=0x%02x, len=%u\n", |
| 1675 | apdu_id, apdu_len); |
| 1676 | |
| 1677 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 2 + apdu_len); |
| 1678 | gh->proto_discr = GSM48_PDISC_RR; |
| 1679 | gh->msg_type = GSM48_MT_RR_APP_INFO; |
| 1680 | gh->data[0] = apdu_id; |
| 1681 | gh->data[1] = apdu_len; |
| 1682 | memcpy(gh->data+2, apdu, apdu_len); |
| 1683 | |
| 1684 | return gsm48_sendmsg(msg, NULL); |
| 1685 | } |
| 1686 | |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 1687 | /* Call Control */ |
| 1688 | |
Harald Welte | 7584aea | 2009-02-11 11:44:12 +0000 | [diff] [blame] | 1689 | /* The entire call control code is written in accordance with Figure 7.10c |
| 1690 | * for 'very early assignment', i.e. we allocate a TCH/F during IMMEDIATE |
| 1691 | * ASSIGN, then first use that TCH/F for signalling and later MODE MODIFY |
| 1692 | * it for voice */ |
| 1693 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1694 | static void new_cc_state(struct gsm_trans *trans, int state) |
| 1695 | { |
| 1696 | if (state > 31 || state < 0) |
| 1697 | return; |
| 1698 | |
| 1699 | DEBUGP(DCC, "new state %s -> %s\n", |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 1700 | cc_state_names[trans->cc.state], cc_state_names[state]); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1701 | |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 1702 | trans->cc.state = state; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1703 | } |
| 1704 | |
| 1705 | static int gsm48_cc_tx_status(struct gsm_trans *trans, void *arg) |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 1706 | { |
| 1707 | struct msgb *msg = gsm48_msgb_alloc(); |
| 1708 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 1709 | u_int8_t *cause, *call_state; |
| 1710 | |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 1711 | gh->msg_type = GSM48_MT_CC_STATUS; |
| 1712 | |
| 1713 | cause = msgb_put(msg, 3); |
| 1714 | cause[0] = 2; |
| 1715 | cause[1] = GSM48_CAUSE_CS_GSM | GSM48_CAUSE_LOC_USER; |
| 1716 | cause[2] = 0x80 | 30; /* response to status inquiry */ |
| 1717 | |
| 1718 | call_state = msgb_put(msg, 1); |
| 1719 | call_state[0] = 0xc0 | 0x00; |
| 1720 | |
Harald Welte | 39e2ead | 2009-07-23 21:13:03 +0200 | [diff] [blame] | 1721 | return gsm48_sendmsg(msg, trans); |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 1722 | } |
| 1723 | |
Harald Welte | 6f4b753 | 2008-12-29 00:39:37 +0000 | [diff] [blame] | 1724 | static int gsm48_tx_simple(struct gsm_lchan *lchan, |
| 1725 | u_int8_t pdisc, u_int8_t msg_type) |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 1726 | { |
| 1727 | struct msgb *msg = gsm48_msgb_alloc(); |
| 1728 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 1729 | |
| 1730 | msg->lchan = lchan; |
| 1731 | |
Harald Welte | 6f4b753 | 2008-12-29 00:39:37 +0000 | [diff] [blame] | 1732 | gh->proto_discr = pdisc; |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 1733 | gh->msg_type = msg_type; |
| 1734 | |
Harald Welte | 39e2ead | 2009-07-23 21:13:03 +0200 | [diff] [blame] | 1735 | return gsm48_sendmsg(msg, NULL); |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 1736 | } |
| 1737 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1738 | static void gsm48_stop_cc_timer(struct gsm_trans *trans) |
| 1739 | { |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 1740 | if (bsc_timer_pending(&trans->cc.timer)) { |
| 1741 | DEBUGP(DCC, "stopping pending timer T%x\n", trans->cc.Tcurrent); |
| 1742 | bsc_del_timer(&trans->cc.timer); |
| 1743 | trans->cc.Tcurrent = 0; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1744 | } |
| 1745 | } |
| 1746 | |
| 1747 | static int mncc_recvmsg(struct gsm_network *net, struct gsm_trans *trans, |
| 1748 | int msg_type, struct gsm_mncc *mncc) |
| 1749 | { |
| 1750 | struct msgb *msg; |
| 1751 | |
| 1752 | if (trans) |
| 1753 | if (trans->lchan) |
Harald Welte | 6f5aee0 | 2009-07-23 21:21:14 +0200 | [diff] [blame] | 1754 | DEBUGP(DCC, "(bts %d trx %d ts %d ti %x sub %s) " |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1755 | "Sending '%s' to MNCC.\n", |
| 1756 | trans->lchan->ts->trx->bts->nr, |
| 1757 | trans->lchan->ts->trx->nr, |
| 1758 | trans->lchan->ts->nr, trans->transaction_id, |
| 1759 | (trans->subscr)?(trans->subscr->extension):"-", |
| 1760 | get_mncc_name(msg_type)); |
| 1761 | else |
| 1762 | DEBUGP(DCC, "(bts - trx - ts - ti -- sub %s) " |
| 1763 | "Sending '%s' to MNCC.\n", |
| 1764 | (trans->subscr)?(trans->subscr->extension):"-", |
| 1765 | get_mncc_name(msg_type)); |
| 1766 | else |
| 1767 | DEBUGP(DCC, "(bts - trx - ts - ti -- sub -) " |
| 1768 | "Sending '%s' to MNCC.\n", get_mncc_name(msg_type)); |
| 1769 | |
| 1770 | mncc->msg_type = msg_type; |
| 1771 | |
Harald Welte | 966636f | 2009-06-26 19:39:35 +0200 | [diff] [blame] | 1772 | msg = msgb_alloc(sizeof(struct gsm_mncc), "MNCC"); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1773 | if (!msg) |
| 1774 | return -ENOMEM; |
| 1775 | memcpy(msg->data, mncc, sizeof(struct gsm_mncc)); |
| 1776 | msgb_enqueue(&net->upqueue, msg); |
| 1777 | |
| 1778 | return 0; |
| 1779 | } |
| 1780 | |
| 1781 | int mncc_release_ind(struct gsm_network *net, struct gsm_trans *trans, |
| 1782 | u_int32_t callref, int location, int value) |
| 1783 | { |
| 1784 | struct gsm_mncc rel; |
| 1785 | |
Harald Welte | 92f70c5 | 2009-06-12 01:54:08 +0800 | [diff] [blame] | 1786 | memset(&rel, 0, sizeof(rel)); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1787 | rel.callref = callref; |
Andreas Eversberg | 7563ac9 | 2009-06-14 22:14:12 +0800 | [diff] [blame] | 1788 | mncc_set_cause(&rel, location, value); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1789 | return mncc_recvmsg(net, trans, MNCC_REL_IND, &rel); |
| 1790 | } |
| 1791 | |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 1792 | /* Call Control Specific transaction release. |
| 1793 | * gets called by trans_free, DO NOT CALL YOURSELF! */ |
| 1794 | void _gsm48_cc_trans_free(struct gsm_trans *trans) |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1795 | { |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1796 | gsm48_stop_cc_timer(trans); |
| 1797 | |
| 1798 | /* send release to L4, if callref still exists */ |
| 1799 | if (trans->callref) { |
| 1800 | /* Ressource unavailable */ |
Harald Welte | 596fed4 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 1801 | mncc_release_ind(trans->subscr->net, trans, trans->callref, |
Andreas Eversberg | 7563ac9 | 2009-06-14 22:14:12 +0800 | [diff] [blame] | 1802 | GSM48_CAUSE_LOC_PRN_S_LU, |
| 1803 | GSM48_CC_CAUSE_RESOURCE_UNAVAIL); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1804 | } |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 1805 | if (trans->cc.state != GSM_CSTATE_NULL) |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1806 | new_cc_state(trans, GSM_CSTATE_NULL); |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 1807 | if (trans->lchan) |
| 1808 | trau_mux_unmap(&trans->lchan->ts->e1_link, trans->callref); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1809 | } |
| 1810 | |
| 1811 | static int gsm48_cc_tx_setup(struct gsm_trans *trans, void *arg); |
| 1812 | |
Harald Welte | 09e38af | 2009-02-16 22:52:23 +0000 | [diff] [blame] | 1813 | /* call-back from paging the B-end of the connection */ |
| 1814 | static int setup_trig_pag_evt(unsigned int hooknum, unsigned int event, |
Harald Welte | 7ccf778 | 2009-02-17 01:43:01 +0000 | [diff] [blame] | 1815 | struct msgb *msg, void *_lchan, void *param) |
Harald Welte | 09e38af | 2009-02-16 22:52:23 +0000 | [diff] [blame] | 1816 | { |
Harald Welte | 7ccf778 | 2009-02-17 01:43:01 +0000 | [diff] [blame] | 1817 | struct gsm_lchan *lchan = _lchan; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1818 | struct gsm_subscriber *subscr = param; |
| 1819 | struct gsm_trans *transt, *tmp; |
| 1820 | struct gsm_network *net; |
Harald Welte | c05677b | 2009-06-26 20:17:06 +0200 | [diff] [blame] | 1821 | |
Harald Welte | 09e38af | 2009-02-16 22:52:23 +0000 | [diff] [blame] | 1822 | if (hooknum != GSM_HOOK_RR_PAGING) |
| 1823 | return -EINVAL; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1824 | |
| 1825 | if (!subscr) |
| 1826 | return -EINVAL; |
| 1827 | net = subscr->net; |
| 1828 | if (!net) { |
| 1829 | DEBUGP(DCC, "Error Network not set!\n"); |
| 1830 | return -EINVAL; |
Harald Welte | 5a065df | 2009-02-22 21:13:18 +0000 | [diff] [blame] | 1831 | } |
Harald Welte | 7584aea | 2009-02-11 11:44:12 +0000 | [diff] [blame] | 1832 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1833 | /* check all tranactions (without lchan) for subscriber */ |
| 1834 | llist_for_each_entry_safe(transt, tmp, &net->trans_list, entry) { |
| 1835 | if (transt->subscr != subscr || transt->lchan) |
| 1836 | continue; |
| 1837 | switch (event) { |
| 1838 | case GSM_PAGING_SUCCEEDED: |
| 1839 | if (!lchan) // paranoid |
| 1840 | break; |
| 1841 | DEBUGP(DCC, "Paging subscr %s succeeded!\n", |
| 1842 | subscr->extension); |
| 1843 | /* Assign lchan */ |
| 1844 | if (!transt->lchan) { |
| 1845 | transt->lchan = lchan; |
| 1846 | use_lchan(lchan); |
| 1847 | } |
| 1848 | /* send SETUP request to called party */ |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 1849 | gsm48_cc_tx_setup(transt, &transt->cc.msg); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1850 | break; |
| 1851 | case GSM_PAGING_EXPIRED: |
| 1852 | DEBUGP(DCC, "Paging subscr %s expired!\n", |
| 1853 | subscr->extension); |
| 1854 | /* Temporarily out of order */ |
Harald Welte | 596fed4 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 1855 | mncc_release_ind(transt->subscr->net, transt, |
| 1856 | transt->callref, |
Andreas Eversberg | 7563ac9 | 2009-06-14 22:14:12 +0800 | [diff] [blame] | 1857 | GSM48_CAUSE_LOC_PRN_S_LU, |
| 1858 | GSM48_CC_CAUSE_DEST_OOO); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1859 | transt->callref = 0; |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 1860 | trans_free(transt); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1861 | break; |
| 1862 | } |
| 1863 | } |
Harald Welte | 09e38af | 2009-02-16 22:52:23 +0000 | [diff] [blame] | 1864 | return 0; |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 1865 | } |
Harald Welte | 7584aea | 2009-02-11 11:44:12 +0000 | [diff] [blame] | 1866 | |
Harald Welte | 805f644 | 2009-07-28 18:25:29 +0200 | [diff] [blame] | 1867 | /* some other part of the code sends us a signal */ |
| 1868 | static int handle_abisip_signal(unsigned int subsys, unsigned int signal, |
| 1869 | void *handler_data, void *signal_data) |
| 1870 | { |
| 1871 | struct gsm_lchan *lchan = signal_data; |
Harald Welte | 805f644 | 2009-07-28 18:25:29 +0200 | [diff] [blame] | 1872 | int rc; |
| 1873 | |
| 1874 | if (subsys != SS_ABISIP) |
| 1875 | return 0; |
| 1876 | |
| 1877 | /* in case we use direct BTS-to-BTS RTP */ |
| 1878 | if (ipacc_rtp_direct) |
| 1879 | return 0; |
| 1880 | |
Harald Welte | 805f644 | 2009-07-28 18:25:29 +0200 | [diff] [blame] | 1881 | switch (signal) { |
Holger Hans Peter Freyther | 231163d | 2009-11-18 21:06:12 +0100 | [diff] [blame] | 1882 | case S_ABISIP_CRCX_ACK: |
Harald Welte | 805f644 | 2009-07-28 18:25:29 +0200 | [diff] [blame] | 1883 | /* the BTS has successfully bound a TCH to a local ip/port, |
| 1884 | * which means we can connect our UDP socket to it */ |
Harald Welte | 2c82899 | 2009-12-02 01:56:49 +0530 | [diff] [blame] | 1885 | if (lchan->abis_ip.rtp_socket) { |
| 1886 | rtp_socket_free(lchan->abis_ip.rtp_socket); |
| 1887 | lchan->abis_ip.rtp_socket = NULL; |
Harald Welte | 805f644 | 2009-07-28 18:25:29 +0200 | [diff] [blame] | 1888 | } |
| 1889 | |
Harald Welte | 2c82899 | 2009-12-02 01:56:49 +0530 | [diff] [blame] | 1890 | lchan->abis_ip.rtp_socket = rtp_socket_create(); |
| 1891 | if (!lchan->abis_ip.rtp_socket) |
Harald Welte | 805f644 | 2009-07-28 18:25:29 +0200 | [diff] [blame] | 1892 | goto out_err; |
| 1893 | |
Harald Welte | 2c82899 | 2009-12-02 01:56:49 +0530 | [diff] [blame] | 1894 | rc = rtp_socket_connect(lchan->abis_ip.rtp_socket, |
| 1895 | lchan->abis_ip.bound_ip, |
| 1896 | lchan->abis_ip.bound_port); |
Harald Welte | 805f644 | 2009-07-28 18:25:29 +0200 | [diff] [blame] | 1897 | if (rc < 0) |
| 1898 | goto out_err; |
| 1899 | break; |
Holger Hans Peter Freyther | 231163d | 2009-11-18 21:06:12 +0100 | [diff] [blame] | 1900 | case S_ABISIP_DLCX_IND: |
Harald Welte | 805f644 | 2009-07-28 18:25:29 +0200 | [diff] [blame] | 1901 | /* the BTS tells us a RTP stream has been disconnected */ |
Harald Welte | 2c82899 | 2009-12-02 01:56:49 +0530 | [diff] [blame] | 1902 | if (lchan->abis_ip.rtp_socket) { |
| 1903 | rtp_socket_free(lchan->abis_ip.rtp_socket); |
| 1904 | lchan->abis_ip.rtp_socket = NULL; |
Harald Welte | 805f644 | 2009-07-28 18:25:29 +0200 | [diff] [blame] | 1905 | } |
| 1906 | break; |
| 1907 | } |
| 1908 | |
| 1909 | return 0; |
| 1910 | out_err: |
| 1911 | /* FIXME: do something */ |
| 1912 | return 0; |
| 1913 | } |
| 1914 | |
| 1915 | /* bind rtp proxy to local IP/port and tell BTS to connect to it */ |
| 1916 | static int ipacc_connect_proxy_bind(struct gsm_lchan *lchan) |
| 1917 | { |
Harald Welte | 2c82899 | 2009-12-02 01:56:49 +0530 | [diff] [blame] | 1918 | struct rtp_socket *rs = lchan->abis_ip.rtp_socket; |
Harald Welte | 805f644 | 2009-07-28 18:25:29 +0200 | [diff] [blame] | 1919 | int rc; |
| 1920 | |
Holger Hans Peter Freyther | 231163d | 2009-11-18 21:06:12 +0100 | [diff] [blame] | 1921 | rc = rsl_ipacc_mdcx(lchan, ntohl(rs->rtp.sin_local.sin_addr.s_addr), |
Harald Welte | 805f644 | 2009-07-28 18:25:29 +0200 | [diff] [blame] | 1922 | ntohs(rs->rtp.sin_local.sin_port), |
Harald Welte | 805f644 | 2009-07-28 18:25:29 +0200 | [diff] [blame] | 1923 | /* FIXME: use RTP payload of bound socket, not BTS*/ |
Harald Welte | 2c82899 | 2009-12-02 01:56:49 +0530 | [diff] [blame] | 1924 | lchan->abis_ip.rtp_payload2); |
Harald Welte | 805f644 | 2009-07-28 18:25:29 +0200 | [diff] [blame] | 1925 | |
| 1926 | return rc; |
| 1927 | } |
| 1928 | |
Harald Welte | 49f48b8 | 2009-02-17 15:29:33 +0000 | [diff] [blame] | 1929 | /* map two ipaccess RTP streams onto each other */ |
Harald Welte | 11fa29c | 2009-02-19 17:24:39 +0000 | [diff] [blame] | 1930 | 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] | 1931 | { |
Harald Welte | 11fa29c | 2009-02-19 17:24:39 +0000 | [diff] [blame] | 1932 | struct gsm_bts *bts = lchan->ts->trx->bts; |
| 1933 | struct gsm_bts *remote_bts = remote_lchan->ts->trx->bts; |
Harald Welte | 805f644 | 2009-07-28 18:25:29 +0200 | [diff] [blame] | 1934 | int rc; |
Harald Welte | 49f48b8 | 2009-02-17 15:29:33 +0000 | [diff] [blame] | 1935 | |
Harald Welte | 11fa29c | 2009-02-19 17:24:39 +0000 | [diff] [blame] | 1936 | DEBUGP(DCC, "Setting up TCH map between (bts=%u,trx=%u,ts=%u) and (bts=%u,trx=%u,ts=%u)\n", |
| 1937 | bts->nr, lchan->ts->trx->nr, lchan->ts->nr, |
| 1938 | remote_bts->nr, remote_lchan->ts->trx->nr, remote_lchan->ts->nr); |
| 1939 | |
| 1940 | if (bts->type != remote_bts->type) { |
| 1941 | DEBUGP(DCC, "Cannot switch calls between different BTS types yet\n"); |
| 1942 | return -EINVAL; |
| 1943 | } |
Harald Welte | 49f48b8 | 2009-02-17 15:29:33 +0000 | [diff] [blame] | 1944 | |
Harald Welte | 11fa29c | 2009-02-19 17:24:39 +0000 | [diff] [blame] | 1945 | switch (bts->type) { |
Mike Haben | e2d8227 | 2009-10-02 12:19:34 +0100 | [diff] [blame] | 1946 | case GSM_BTS_TYPE_NANOBTS: |
Harald Welte | 805f644 | 2009-07-28 18:25:29 +0200 | [diff] [blame] | 1947 | if (!ipacc_rtp_direct) { |
| 1948 | /* connect the TCH's to our RTP proxy */ |
| 1949 | rc = ipacc_connect_proxy_bind(lchan); |
| 1950 | if (rc < 0) |
| 1951 | return rc; |
| 1952 | rc = ipacc_connect_proxy_bind(remote_lchan); |
| 1953 | |
| 1954 | /* connect them with each other */ |
Harald Welte | 2c82899 | 2009-12-02 01:56:49 +0530 | [diff] [blame] | 1955 | rtp_socket_proxy(lchan->abis_ip.rtp_socket, |
| 1956 | remote_lchan->abis_ip.rtp_socket); |
Harald Welte | 805f644 | 2009-07-28 18:25:29 +0200 | [diff] [blame] | 1957 | } else { |
| 1958 | /* directly connect TCH RTP streams to each other */ |
Harald Welte | 2c82899 | 2009-12-02 01:56:49 +0530 | [diff] [blame] | 1959 | rc = rsl_ipacc_mdcx(lchan, remote_lchan->abis_ip.bound_ip, |
| 1960 | remote_lchan->abis_ip.bound_port, |
Harald Welte | 2c82899 | 2009-12-02 01:56:49 +0530 | [diff] [blame] | 1961 | remote_lchan->abis_ip.rtp_payload2); |
Harald Welte | 805f644 | 2009-07-28 18:25:29 +0200 | [diff] [blame] | 1962 | if (rc < 0) |
| 1963 | return rc; |
Harald Welte | 2c82899 | 2009-12-02 01:56:49 +0530 | [diff] [blame] | 1964 | rc = rsl_ipacc_mdcx(remote_lchan, lchan->abis_ip.bound_ip, |
| 1965 | lchan->abis_ip.bound_port, |
Harald Welte | 2c82899 | 2009-12-02 01:56:49 +0530 | [diff] [blame] | 1966 | lchan->abis_ip.rtp_payload2); |
Harald Welte | 805f644 | 2009-07-28 18:25:29 +0200 | [diff] [blame] | 1967 | } |
Harald Welte | 11fa29c | 2009-02-19 17:24:39 +0000 | [diff] [blame] | 1968 | break; |
| 1969 | case GSM_BTS_TYPE_BS11: |
| 1970 | trau_mux_map_lchan(lchan, remote_lchan); |
| 1971 | break; |
| 1972 | default: |
| 1973 | DEBUGP(DCC, "Unknown BTS type %u\n", bts->type); |
Harald Welte | 805f644 | 2009-07-28 18:25:29 +0200 | [diff] [blame] | 1974 | rc = -EINVAL; |
Harald Welte | 11fa29c | 2009-02-19 17:24:39 +0000 | [diff] [blame] | 1975 | break; |
| 1976 | } |
Harald Welte | 49f48b8 | 2009-02-17 15:29:33 +0000 | [diff] [blame] | 1977 | |
| 1978 | return 0; |
| 1979 | } |
| 1980 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1981 | /* bridge channels of two transactions */ |
| 1982 | static int tch_bridge(struct gsm_network *net, u_int32_t *refs) |
Harald Welte | 7ccf778 | 2009-02-17 01:43:01 +0000 | [diff] [blame] | 1983 | { |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 1984 | struct gsm_trans *trans1 = trans_find_by_callref(net, refs[0]); |
| 1985 | struct gsm_trans *trans2 = trans_find_by_callref(net, refs[1]); |
Harald Welte | 7ccf778 | 2009-02-17 01:43:01 +0000 | [diff] [blame] | 1986 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1987 | if (!trans1 || !trans2) |
Harald Welte | 7ccf778 | 2009-02-17 01:43:01 +0000 | [diff] [blame] | 1988 | return -EIO; |
| 1989 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1990 | if (!trans1->lchan || !trans2->lchan) |
| 1991 | return -EIO; |
| 1992 | |
| 1993 | /* through-connect channel */ |
| 1994 | return tch_map(trans1->lchan, trans2->lchan); |
Harald Welte | 7ccf778 | 2009-02-17 01:43:01 +0000 | [diff] [blame] | 1995 | } |
| 1996 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1997 | /* enable receive of channels to upqueue */ |
| 1998 | static int tch_recv(struct gsm_network *net, struct gsm_mncc *data, int enable) |
| 1999 | { |
| 2000 | struct gsm_trans *trans; |
Harald Welte | 7ccf778 | 2009-02-17 01:43:01 +0000 | [diff] [blame] | 2001 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2002 | /* Find callref */ |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 2003 | trans = trans_find_by_callref(net, data->callref); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2004 | if (!trans) |
| 2005 | return -EIO; |
| 2006 | if (!trans->lchan) |
| 2007 | return 0; |
| 2008 | |
| 2009 | // todo IPACCESS |
| 2010 | if (enable) |
| 2011 | return trau_recv_lchan(trans->lchan, data->callref); |
| 2012 | return trau_mux_unmap(NULL, data->callref); |
| 2013 | } |
| 2014 | |
| 2015 | /* send a frame to channel */ |
| 2016 | static int tch_frame(struct gsm_network *net, struct gsm_trau_frame *frame) |
| 2017 | { |
| 2018 | struct gsm_trans *trans; |
| 2019 | |
| 2020 | /* Find callref */ |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 2021 | trans = trans_find_by_callref(net, frame->callref); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2022 | if (!trans) |
| 2023 | return -EIO; |
| 2024 | if (!trans->lchan) |
| 2025 | return 0; |
| 2026 | if (trans->lchan->type != GSM_LCHAN_TCH_F && |
| 2027 | trans->lchan->type != GSM_LCHAN_TCH_H) |
| 2028 | return 0; |
| 2029 | |
| 2030 | // todo IPACCESS |
| 2031 | return trau_send_lchan(trans->lchan, |
| 2032 | (struct decoded_trau_frame *)frame->data); |
| 2033 | } |
| 2034 | |
| 2035 | |
| 2036 | static int gsm48_cc_rx_status_enq(struct gsm_trans *trans, struct msgb *msg) |
| 2037 | { |
| 2038 | DEBUGP(DCC, "-> STATUS ENQ\n"); |
| 2039 | return gsm48_cc_tx_status(trans, msg); |
| 2040 | } |
| 2041 | |
| 2042 | static int gsm48_cc_tx_release(struct gsm_trans *trans, void *arg); |
| 2043 | static int gsm48_cc_tx_disconnect(struct gsm_trans *trans, void *arg); |
| 2044 | |
| 2045 | static void gsm48_cc_timeout(void *arg) |
| 2046 | { |
| 2047 | struct gsm_trans *trans = arg; |
| 2048 | int disconnect = 0, release = 0; |
Harald Welte | c66b71c | 2009-06-11 14:23:20 +0800 | [diff] [blame] | 2049 | int mo_cause = GSM48_CC_CAUSE_RECOVERY_TIMER; |
| 2050 | int mo_location = GSM48_CAUSE_LOC_USER; |
| 2051 | int l4_cause = GSM48_CC_CAUSE_NORMAL_UNSPEC; |
| 2052 | int l4_location = GSM48_CAUSE_LOC_PRN_S_LU; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2053 | struct gsm_mncc mo_rel, l4_rel; |
| 2054 | |
| 2055 | memset(&mo_rel, 0, sizeof(struct gsm_mncc)); |
| 2056 | mo_rel.callref = trans->callref; |
| 2057 | memset(&l4_rel, 0, sizeof(struct gsm_mncc)); |
| 2058 | l4_rel.callref = trans->callref; |
| 2059 | |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 2060 | switch(trans->cc.Tcurrent) { |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2061 | case 0x303: |
| 2062 | release = 1; |
Harald Welte | c66b71c | 2009-06-11 14:23:20 +0800 | [diff] [blame] | 2063 | l4_cause = GSM48_CC_CAUSE_USER_NOTRESPOND; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2064 | break; |
| 2065 | case 0x310: |
| 2066 | disconnect = 1; |
Harald Welte | c66b71c | 2009-06-11 14:23:20 +0800 | [diff] [blame] | 2067 | l4_cause = GSM48_CC_CAUSE_USER_NOTRESPOND; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2068 | break; |
| 2069 | case 0x313: |
| 2070 | disconnect = 1; |
| 2071 | /* unknown, did not find it in the specs */ |
| 2072 | break; |
| 2073 | case 0x301: |
| 2074 | disconnect = 1; |
Harald Welte | c66b71c | 2009-06-11 14:23:20 +0800 | [diff] [blame] | 2075 | l4_cause = GSM48_CC_CAUSE_USER_NOTRESPOND; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2076 | break; |
| 2077 | case 0x308: |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 2078 | if (!trans->cc.T308_second) { |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2079 | /* restart T308 a second time */ |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 2080 | gsm48_cc_tx_release(trans, &trans->cc.msg); |
| 2081 | trans->cc.T308_second = 1; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2082 | break; /* stay in release state */ |
| 2083 | } |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 2084 | trans_free(trans); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2085 | return; |
| 2086 | // release = 1; |
| 2087 | // l4_cause = 14; |
| 2088 | // break; |
| 2089 | case 0x306: |
| 2090 | release = 1; |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 2091 | mo_cause = trans->cc.msg.cause.value; |
| 2092 | mo_location = trans->cc.msg.cause.location; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2093 | break; |
| 2094 | case 0x323: |
| 2095 | disconnect = 1; |
| 2096 | break; |
| 2097 | default: |
| 2098 | release = 1; |
| 2099 | } |
| 2100 | |
| 2101 | if (release && trans->callref) { |
| 2102 | /* process release towards layer 4 */ |
Harald Welte | 596fed4 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 2103 | mncc_release_ind(trans->subscr->net, trans, trans->callref, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2104 | l4_location, l4_cause); |
| 2105 | trans->callref = 0; |
| 2106 | } |
| 2107 | |
| 2108 | if (disconnect && trans->callref) { |
| 2109 | /* process disconnect towards layer 4 */ |
| 2110 | mncc_set_cause(&l4_rel, l4_location, l4_cause); |
Harald Welte | 596fed4 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 2111 | mncc_recvmsg(trans->subscr->net, trans, MNCC_DISC_IND, &l4_rel); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2112 | } |
| 2113 | |
| 2114 | /* process disconnect towards mobile station */ |
| 2115 | if (disconnect || release) { |
| 2116 | mncc_set_cause(&mo_rel, mo_location, mo_cause); |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 2117 | mo_rel.cause.diag[0] = ((trans->cc.Tcurrent & 0xf00) >> 8) + '0'; |
| 2118 | mo_rel.cause.diag[1] = ((trans->cc.Tcurrent & 0x0f0) >> 4) + '0'; |
| 2119 | mo_rel.cause.diag[2] = (trans->cc.Tcurrent & 0x00f) + '0'; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2120 | mo_rel.cause.diag_len = 3; |
| 2121 | |
| 2122 | if (disconnect) |
| 2123 | gsm48_cc_tx_disconnect(trans, &mo_rel); |
| 2124 | if (release) |
| 2125 | gsm48_cc_tx_release(trans, &mo_rel); |
| 2126 | } |
| 2127 | |
| 2128 | } |
| 2129 | |
| 2130 | static void gsm48_start_cc_timer(struct gsm_trans *trans, int current, |
| 2131 | int sec, int micro) |
| 2132 | { |
| 2133 | DEBUGP(DCC, "starting timer T%x with %d seconds\n", current, sec); |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 2134 | trans->cc.timer.cb = gsm48_cc_timeout; |
| 2135 | trans->cc.timer.data = trans; |
| 2136 | bsc_schedule_timer(&trans->cc.timer, sec, micro); |
| 2137 | trans->cc.Tcurrent = current; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2138 | } |
| 2139 | |
| 2140 | static int gsm48_cc_rx_setup(struct gsm_trans *trans, struct msgb *msg) |
| 2141 | { |
| 2142 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 2143 | u_int8_t msg_type = gh->msg_type & 0xbf; |
| 2144 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 2145 | struct tlv_parsed tp; |
| 2146 | struct gsm_mncc setup; |
| 2147 | |
| 2148 | memset(&setup, 0, sizeof(struct gsm_mncc)); |
| 2149 | setup.callref = trans->callref; |
| 2150 | tlv_parse(&tp, &rsl_att_tlvdef, gh->data, payload_len, 0, 0); |
| 2151 | /* emergency setup is identified by msg_type */ |
| 2152 | if (msg_type == GSM48_MT_CC_EMERG_SETUP) |
| 2153 | setup.emergency = 1; |
| 2154 | |
| 2155 | /* use subscriber as calling party number */ |
| 2156 | if (trans->subscr) { |
| 2157 | setup.fields |= MNCC_F_CALLING; |
| 2158 | strncpy(setup.calling.number, trans->subscr->extension, |
| 2159 | sizeof(setup.calling.number)-1); |
Andreas Eversberg | c079be4 | 2009-06-15 23:22:09 +0200 | [diff] [blame] | 2160 | strncpy(setup.imsi, trans->subscr->imsi, |
| 2161 | sizeof(setup.imsi)-1); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2162 | } |
| 2163 | /* bearer capability */ |
| 2164 | if (TLVP_PRESENT(&tp, GSM48_IE_BEARER_CAP)) { |
| 2165 | setup.fields |= MNCC_F_BEARER_CAP; |
| 2166 | decode_bearer_cap(&setup.bearer_cap, |
| 2167 | TLVP_VAL(&tp, GSM48_IE_BEARER_CAP)-1); |
| 2168 | } |
| 2169 | /* facility */ |
| 2170 | if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) { |
| 2171 | setup.fields |= MNCC_F_FACILITY; |
| 2172 | decode_facility(&setup.facility, |
| 2173 | TLVP_VAL(&tp, GSM48_IE_FACILITY)-1); |
| 2174 | } |
| 2175 | /* called party bcd number */ |
| 2176 | if (TLVP_PRESENT(&tp, GSM48_IE_CALLED_BCD)) { |
| 2177 | setup.fields |= MNCC_F_CALLED; |
| 2178 | decode_called(&setup.called, |
| 2179 | TLVP_VAL(&tp, GSM48_IE_CALLED_BCD)-1); |
| 2180 | } |
| 2181 | /* user-user */ |
| 2182 | if (TLVP_PRESENT(&tp, GSM48_IE_USER_USER)) { |
| 2183 | setup.fields |= MNCC_F_USERUSER; |
| 2184 | decode_useruser(&setup.useruser, |
| 2185 | TLVP_VAL(&tp, GSM48_IE_USER_USER)-1); |
| 2186 | } |
| 2187 | /* ss-version */ |
| 2188 | if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) { |
| 2189 | setup.fields |= MNCC_F_SSVERSION; |
| 2190 | decode_ssversion(&setup.ssversion, |
| 2191 | TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1); |
| 2192 | } |
| 2193 | /* CLIR suppression */ |
| 2194 | if (TLVP_PRESENT(&tp, GSM48_IE_CLIR_SUPP)) |
| 2195 | setup.clir.sup = 1; |
| 2196 | /* CLIR invocation */ |
| 2197 | if (TLVP_PRESENT(&tp, GSM48_IE_CLIR_INVOC)) |
| 2198 | setup.clir.inv = 1; |
| 2199 | /* cc cap */ |
| 2200 | if (TLVP_PRESENT(&tp, GSM48_IE_CC_CAP)) { |
| 2201 | setup.fields |= MNCC_F_CCCAP; |
| 2202 | decode_cccap(&setup.cccap, |
| 2203 | TLVP_VAL(&tp, GSM48_IE_CC_CAP)-1); |
| 2204 | } |
| 2205 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2206 | new_cc_state(trans, GSM_CSTATE_INITIATED); |
| 2207 | |
| 2208 | /* indicate setup to MNCC */ |
Harald Welte | 596fed4 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 2209 | mncc_recvmsg(trans->subscr->net, trans, MNCC_SETUP_IND, &setup); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2210 | |
Harald Welte | 13cac66 | 2009-07-29 12:10:35 +0200 | [diff] [blame] | 2211 | /* MNCC code will modify the channel asynchronously, we should |
| 2212 | * ipaccess-bind only after the modification has been made to the |
| 2213 | * lchan->tch_mode */ |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2214 | return 0; |
| 2215 | } |
| 2216 | |
| 2217 | static int gsm48_cc_tx_setup(struct gsm_trans *trans, void *arg) |
Harald Welte | 65e74cc | 2008-12-29 01:55:35 +0000 | [diff] [blame] | 2218 | { |
| 2219 | struct msgb *msg = gsm48_msgb_alloc(); |
| 2220 | struct gsm48_hdr *gh; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2221 | struct gsm_mncc *setup = arg; |
Harald Welte | 78283ef | 2009-07-23 21:36:44 +0200 | [diff] [blame] | 2222 | int rc, trans_id; |
Harald Welte | 65e74cc | 2008-12-29 01:55:35 +0000 | [diff] [blame] | 2223 | |
Harald Welte | 7ccf778 | 2009-02-17 01:43:01 +0000 | [diff] [blame] | 2224 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
Harald Welte | 65e74cc | 2008-12-29 01:55:35 +0000 | [diff] [blame] | 2225 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2226 | /* transaction id must not be assigned */ |
| 2227 | if (trans->transaction_id != 0xff) { /* unasssigned */ |
| 2228 | DEBUGP(DCC, "TX Setup with assigned transaction. " |
| 2229 | "This is not allowed!\n"); |
| 2230 | /* Temporarily out of order */ |
Harald Welte | 596fed4 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 2231 | rc = mncc_release_ind(trans->subscr->net, trans, trans->callref, |
Andreas Eversberg | 7563ac9 | 2009-06-14 22:14:12 +0800 | [diff] [blame] | 2232 | GSM48_CAUSE_LOC_PRN_S_LU, |
| 2233 | GSM48_CC_CAUSE_RESOURCE_UNAVAIL); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2234 | trans->callref = 0; |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 2235 | trans_free(trans); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2236 | return rc; |
| 2237 | } |
| 2238 | |
| 2239 | /* Get free transaction_id */ |
Harald Welte | 78283ef | 2009-07-23 21:36:44 +0200 | [diff] [blame] | 2240 | trans_id = trans_assign_trans_id(trans->subscr, GSM48_PDISC_CC, 0); |
| 2241 | if (trans_id < 0) { |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2242 | /* no free transaction ID */ |
Harald Welte | 596fed4 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 2243 | rc = mncc_release_ind(trans->subscr->net, trans, trans->callref, |
Andreas Eversberg | 7563ac9 | 2009-06-14 22:14:12 +0800 | [diff] [blame] | 2244 | GSM48_CAUSE_LOC_PRN_S_LU, |
| 2245 | GSM48_CC_CAUSE_RESOURCE_UNAVAIL); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2246 | trans->callref = 0; |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 2247 | trans_free(trans); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2248 | return rc; |
| 2249 | } |
Harald Welte | 78283ef | 2009-07-23 21:36:44 +0200 | [diff] [blame] | 2250 | trans->transaction_id = trans_id; |
Harald Welte | 49f48b8 | 2009-02-17 15:29:33 +0000 | [diff] [blame] | 2251 | |
Harald Welte | 65e74cc | 2008-12-29 01:55:35 +0000 | [diff] [blame] | 2252 | gh->msg_type = GSM48_MT_CC_SETUP; |
Harald Welte | 09e38af | 2009-02-16 22:52:23 +0000 | [diff] [blame] | 2253 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2254 | gsm48_start_cc_timer(trans, 0x303, GSM48_T303); |
Harald Welte | 65e74cc | 2008-12-29 01:55:35 +0000 | [diff] [blame] | 2255 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2256 | /* bearer capability */ |
| 2257 | if (setup->fields & MNCC_F_BEARER_CAP) |
| 2258 | encode_bearer_cap(msg, 0, &setup->bearer_cap); |
| 2259 | /* facility */ |
| 2260 | if (setup->fields & MNCC_F_FACILITY) |
| 2261 | encode_facility(msg, 0, &setup->facility); |
| 2262 | /* progress */ |
| 2263 | if (setup->fields & MNCC_F_PROGRESS) |
| 2264 | encode_progress(msg, 0, &setup->progress); |
| 2265 | /* calling party BCD number */ |
| 2266 | if (setup->fields & MNCC_F_CALLING) |
| 2267 | encode_calling(msg, &setup->calling); |
| 2268 | /* called party BCD number */ |
| 2269 | if (setup->fields & MNCC_F_CALLED) |
| 2270 | encode_called(msg, &setup->called); |
| 2271 | /* user-user */ |
| 2272 | if (setup->fields & MNCC_F_USERUSER) |
| 2273 | encode_useruser(msg, 0, &setup->useruser); |
| 2274 | /* redirecting party BCD number */ |
| 2275 | if (setup->fields & MNCC_F_REDIRECTING) |
| 2276 | encode_redirecting(msg, &setup->redirecting); |
| 2277 | /* signal */ |
| 2278 | if (setup->fields & MNCC_F_SIGNAL) |
| 2279 | encode_signal(msg, setup->signal); |
| 2280 | |
| 2281 | new_cc_state(trans, GSM_CSTATE_CALL_PRESENT); |
Harald Welte | 65e74cc | 2008-12-29 01:55:35 +0000 | [diff] [blame] | 2282 | |
Harald Welte | 39e2ead | 2009-07-23 21:13:03 +0200 | [diff] [blame] | 2283 | return gsm48_sendmsg(msg, trans); |
Harald Welte | 65e74cc | 2008-12-29 01:55:35 +0000 | [diff] [blame] | 2284 | } |
| 2285 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2286 | static int gsm48_cc_rx_call_conf(struct gsm_trans *trans, struct msgb *msg) |
| 2287 | { |
| 2288 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 2289 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 2290 | struct tlv_parsed tp; |
| 2291 | struct gsm_mncc call_conf; |
| 2292 | |
| 2293 | gsm48_stop_cc_timer(trans); |
| 2294 | gsm48_start_cc_timer(trans, 0x310, GSM48_T310); |
| 2295 | |
| 2296 | memset(&call_conf, 0, sizeof(struct gsm_mncc)); |
| 2297 | call_conf.callref = trans->callref; |
| 2298 | tlv_parse(&tp, &rsl_att_tlvdef, gh->data, payload_len, 0, 0); |
| 2299 | #if 0 |
| 2300 | /* repeat */ |
| 2301 | if (TLVP_PRESENT(&tp, GSM48_IE_REPEAT_CIR)) |
| 2302 | call_conf.repeat = 1; |
| 2303 | if (TLVP_PRESENT(&tp, GSM48_IE_REPEAT_SEQ)) |
| 2304 | call_conf.repeat = 2; |
| 2305 | #endif |
| 2306 | /* bearer capability */ |
| 2307 | if (TLVP_PRESENT(&tp, GSM48_IE_BEARER_CAP)) { |
| 2308 | call_conf.fields |= MNCC_F_BEARER_CAP; |
| 2309 | decode_bearer_cap(&call_conf.bearer_cap, |
| 2310 | TLVP_VAL(&tp, GSM48_IE_BEARER_CAP)-1); |
| 2311 | } |
| 2312 | /* cause */ |
| 2313 | if (TLVP_PRESENT(&tp, GSM48_IE_CAUSE)) { |
| 2314 | call_conf.fields |= MNCC_F_CAUSE; |
| 2315 | decode_cause(&call_conf.cause, |
| 2316 | TLVP_VAL(&tp, GSM48_IE_CAUSE)-1); |
| 2317 | } |
| 2318 | /* cc cap */ |
| 2319 | if (TLVP_PRESENT(&tp, GSM48_IE_CC_CAP)) { |
| 2320 | call_conf.fields |= MNCC_F_CCCAP; |
| 2321 | decode_cccap(&call_conf.cccap, |
| 2322 | TLVP_VAL(&tp, GSM48_IE_CC_CAP)-1); |
| 2323 | } |
| 2324 | |
| 2325 | new_cc_state(trans, GSM_CSTATE_MO_TERM_CALL_CONF); |
| 2326 | |
Harald Welte | 596fed4 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 2327 | return mncc_recvmsg(trans->subscr->net, trans, MNCC_CALL_CONF_IND, |
| 2328 | &call_conf); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2329 | } |
| 2330 | |
| 2331 | static int gsm48_cc_tx_call_proc(struct gsm_trans *trans, void *arg) |
| 2332 | { |
| 2333 | struct gsm_mncc *proceeding = arg; |
| 2334 | struct msgb *msg = gsm48_msgb_alloc(); |
| 2335 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 2336 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2337 | gh->msg_type = GSM48_MT_CC_CALL_PROC; |
| 2338 | |
| 2339 | new_cc_state(trans, GSM_CSTATE_MO_CALL_PROC); |
| 2340 | |
| 2341 | /* bearer capability */ |
| 2342 | if (proceeding->fields & MNCC_F_BEARER_CAP) |
| 2343 | encode_bearer_cap(msg, 0, &proceeding->bearer_cap); |
| 2344 | /* facility */ |
| 2345 | if (proceeding->fields & MNCC_F_FACILITY) |
| 2346 | encode_facility(msg, 0, &proceeding->facility); |
| 2347 | /* progress */ |
| 2348 | if (proceeding->fields & MNCC_F_PROGRESS) |
| 2349 | encode_progress(msg, 0, &proceeding->progress); |
| 2350 | |
Harald Welte | 39e2ead | 2009-07-23 21:13:03 +0200 | [diff] [blame] | 2351 | return gsm48_sendmsg(msg, trans); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2352 | } |
| 2353 | |
| 2354 | static int gsm48_cc_rx_alerting(struct gsm_trans *trans, struct msgb *msg) |
| 2355 | { |
| 2356 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 2357 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 2358 | struct tlv_parsed tp; |
| 2359 | struct gsm_mncc alerting; |
| 2360 | |
| 2361 | gsm48_stop_cc_timer(trans); |
| 2362 | gsm48_start_cc_timer(trans, 0x301, GSM48_T301); |
| 2363 | |
| 2364 | memset(&alerting, 0, sizeof(struct gsm_mncc)); |
| 2365 | alerting.callref = trans->callref; |
| 2366 | tlv_parse(&tp, &rsl_att_tlvdef, gh->data, payload_len, 0, 0); |
| 2367 | /* facility */ |
| 2368 | if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) { |
| 2369 | alerting.fields |= MNCC_F_FACILITY; |
| 2370 | decode_facility(&alerting.facility, |
| 2371 | TLVP_VAL(&tp, GSM48_IE_FACILITY)-1); |
| 2372 | } |
| 2373 | |
| 2374 | /* progress */ |
| 2375 | if (TLVP_PRESENT(&tp, GSM48_IE_PROGR_IND)) { |
| 2376 | alerting.fields |= MNCC_F_PROGRESS; |
| 2377 | decode_progress(&alerting.progress, |
| 2378 | TLVP_VAL(&tp, GSM48_IE_PROGR_IND)-1); |
| 2379 | } |
| 2380 | /* ss-version */ |
| 2381 | if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) { |
| 2382 | alerting.fields |= MNCC_F_SSVERSION; |
| 2383 | decode_ssversion(&alerting.ssversion, |
| 2384 | TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1); |
| 2385 | } |
| 2386 | |
| 2387 | new_cc_state(trans, GSM_CSTATE_CALL_RECEIVED); |
| 2388 | |
Harald Welte | 596fed4 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 2389 | return mncc_recvmsg(trans->subscr->net, trans, MNCC_ALERT_IND, |
| 2390 | &alerting); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2391 | } |
| 2392 | |
| 2393 | static int gsm48_cc_tx_alerting(struct gsm_trans *trans, void *arg) |
| 2394 | { |
| 2395 | struct gsm_mncc *alerting = arg; |
| 2396 | struct msgb *msg = gsm48_msgb_alloc(); |
| 2397 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 2398 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2399 | gh->msg_type = GSM48_MT_CC_ALERTING; |
| 2400 | |
| 2401 | /* facility */ |
| 2402 | if (alerting->fields & MNCC_F_FACILITY) |
| 2403 | encode_facility(msg, 0, &alerting->facility); |
| 2404 | /* progress */ |
| 2405 | if (alerting->fields & MNCC_F_PROGRESS) |
| 2406 | encode_progress(msg, 0, &alerting->progress); |
| 2407 | /* user-user */ |
| 2408 | if (alerting->fields & MNCC_F_USERUSER) |
| 2409 | encode_useruser(msg, 0, &alerting->useruser); |
| 2410 | |
| 2411 | new_cc_state(trans, GSM_CSTATE_CALL_DELIVERED); |
| 2412 | |
Harald Welte | 39e2ead | 2009-07-23 21:13:03 +0200 | [diff] [blame] | 2413 | return gsm48_sendmsg(msg, trans); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2414 | } |
| 2415 | |
| 2416 | static int gsm48_cc_tx_progress(struct gsm_trans *trans, void *arg) |
| 2417 | { |
| 2418 | struct gsm_mncc *progress = arg; |
| 2419 | struct msgb *msg = gsm48_msgb_alloc(); |
| 2420 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 2421 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2422 | gh->msg_type = GSM48_MT_CC_PROGRESS; |
| 2423 | |
| 2424 | /* progress */ |
| 2425 | encode_progress(msg, 1, &progress->progress); |
| 2426 | /* user-user */ |
| 2427 | if (progress->fields & MNCC_F_USERUSER) |
| 2428 | encode_useruser(msg, 0, &progress->useruser); |
| 2429 | |
Harald Welte | 39e2ead | 2009-07-23 21:13:03 +0200 | [diff] [blame] | 2430 | return gsm48_sendmsg(msg, trans); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2431 | } |
| 2432 | |
| 2433 | static int gsm48_cc_tx_connect(struct gsm_trans *trans, void *arg) |
| 2434 | { |
| 2435 | struct gsm_mncc *connect = arg; |
| 2436 | struct msgb *msg = gsm48_msgb_alloc(); |
| 2437 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 2438 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2439 | gh->msg_type = GSM48_MT_CC_CONNECT; |
| 2440 | |
| 2441 | gsm48_stop_cc_timer(trans); |
| 2442 | gsm48_start_cc_timer(trans, 0x313, GSM48_T313); |
| 2443 | |
| 2444 | /* facility */ |
| 2445 | if (connect->fields & MNCC_F_FACILITY) |
| 2446 | encode_facility(msg, 0, &connect->facility); |
| 2447 | /* progress */ |
| 2448 | if (connect->fields & MNCC_F_PROGRESS) |
| 2449 | encode_progress(msg, 0, &connect->progress); |
| 2450 | /* connected number */ |
| 2451 | if (connect->fields & MNCC_F_CONNECTED) |
| 2452 | encode_connected(msg, &connect->connected); |
| 2453 | /* user-user */ |
| 2454 | if (connect->fields & MNCC_F_USERUSER) |
| 2455 | encode_useruser(msg, 0, &connect->useruser); |
| 2456 | |
| 2457 | new_cc_state(trans, GSM_CSTATE_CONNECT_IND); |
| 2458 | |
Harald Welte | 39e2ead | 2009-07-23 21:13:03 +0200 | [diff] [blame] | 2459 | return gsm48_sendmsg(msg, trans); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2460 | } |
| 2461 | |
| 2462 | static int gsm48_cc_rx_connect(struct gsm_trans *trans, struct msgb *msg) |
| 2463 | { |
| 2464 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 2465 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 2466 | struct tlv_parsed tp; |
| 2467 | struct gsm_mncc connect; |
| 2468 | |
| 2469 | gsm48_stop_cc_timer(trans); |
| 2470 | |
| 2471 | memset(&connect, 0, sizeof(struct gsm_mncc)); |
| 2472 | connect.callref = trans->callref; |
| 2473 | tlv_parse(&tp, &rsl_att_tlvdef, gh->data, payload_len, 0, 0); |
| 2474 | /* use subscriber as connected party number */ |
| 2475 | if (trans->subscr) { |
| 2476 | connect.fields |= MNCC_F_CONNECTED; |
| 2477 | strncpy(connect.connected.number, trans->subscr->extension, |
| 2478 | sizeof(connect.connected.number)-1); |
Andreas Eversberg | c079be4 | 2009-06-15 23:22:09 +0200 | [diff] [blame] | 2479 | strncpy(connect.imsi, trans->subscr->imsi, |
| 2480 | sizeof(connect.imsi)-1); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2481 | } |
| 2482 | /* facility */ |
| 2483 | if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) { |
| 2484 | connect.fields |= MNCC_F_FACILITY; |
| 2485 | decode_facility(&connect.facility, |
| 2486 | TLVP_VAL(&tp, GSM48_IE_FACILITY)-1); |
| 2487 | } |
| 2488 | /* user-user */ |
| 2489 | if (TLVP_PRESENT(&tp, GSM48_IE_USER_USER)) { |
| 2490 | connect.fields |= MNCC_F_USERUSER; |
| 2491 | decode_useruser(&connect.useruser, |
| 2492 | TLVP_VAL(&tp, GSM48_IE_USER_USER)-1); |
| 2493 | } |
| 2494 | /* ss-version */ |
| 2495 | if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) { |
| 2496 | connect.fields |= MNCC_F_SSVERSION; |
| 2497 | decode_ssversion(&connect.ssversion, |
| 2498 | TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1); |
| 2499 | } |
| 2500 | |
| 2501 | new_cc_state(trans, GSM_CSTATE_CONNECT_REQUEST); |
| 2502 | |
Harald Welte | 596fed4 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 2503 | return mncc_recvmsg(trans->subscr->net, trans, MNCC_SETUP_CNF, &connect); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2504 | } |
| 2505 | |
| 2506 | |
| 2507 | static int gsm48_cc_rx_connect_ack(struct gsm_trans *trans, struct msgb *msg) |
| 2508 | { |
| 2509 | struct gsm_mncc connect_ack; |
| 2510 | |
| 2511 | gsm48_stop_cc_timer(trans); |
| 2512 | |
| 2513 | new_cc_state(trans, GSM_CSTATE_ACTIVE); |
| 2514 | |
| 2515 | memset(&connect_ack, 0, sizeof(struct gsm_mncc)); |
| 2516 | connect_ack.callref = trans->callref; |
Harald Welte | 596fed4 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 2517 | return mncc_recvmsg(trans->subscr->net, trans, MNCC_SETUP_COMPL_IND, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2518 | &connect_ack); |
| 2519 | } |
| 2520 | |
| 2521 | static int gsm48_cc_tx_connect_ack(struct gsm_trans *trans, void *arg) |
| 2522 | { |
| 2523 | struct msgb *msg = gsm48_msgb_alloc(); |
| 2524 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 2525 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2526 | gh->msg_type = GSM48_MT_CC_CONNECT_ACK; |
| 2527 | |
| 2528 | new_cc_state(trans, GSM_CSTATE_ACTIVE); |
| 2529 | |
Harald Welte | 39e2ead | 2009-07-23 21:13:03 +0200 | [diff] [blame] | 2530 | return gsm48_sendmsg(msg, trans); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2531 | } |
| 2532 | |
| 2533 | static int gsm48_cc_rx_disconnect(struct gsm_trans *trans, struct msgb *msg) |
| 2534 | { |
| 2535 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 2536 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 2537 | struct tlv_parsed tp; |
| 2538 | struct gsm_mncc disc; |
| 2539 | |
| 2540 | gsm48_stop_cc_timer(trans); |
| 2541 | |
| 2542 | new_cc_state(trans, GSM_CSTATE_DISCONNECT_REQ); |
| 2543 | |
| 2544 | memset(&disc, 0, sizeof(struct gsm_mncc)); |
| 2545 | disc.callref = trans->callref; |
| 2546 | tlv_parse(&tp, &rsl_att_tlvdef, gh->data, payload_len, GSM48_IE_CAUSE, 0); |
| 2547 | /* cause */ |
| 2548 | if (TLVP_PRESENT(&tp, GSM48_IE_CAUSE)) { |
| 2549 | disc.fields |= MNCC_F_CAUSE; |
| 2550 | decode_cause(&disc.cause, |
| 2551 | TLVP_VAL(&tp, GSM48_IE_CAUSE)-1); |
| 2552 | } |
| 2553 | /* facility */ |
| 2554 | if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) { |
| 2555 | disc.fields |= MNCC_F_FACILITY; |
| 2556 | decode_facility(&disc.facility, |
| 2557 | TLVP_VAL(&tp, GSM48_IE_FACILITY)-1); |
| 2558 | } |
| 2559 | /* user-user */ |
| 2560 | if (TLVP_PRESENT(&tp, GSM48_IE_USER_USER)) { |
| 2561 | disc.fields |= MNCC_F_USERUSER; |
| 2562 | decode_useruser(&disc.useruser, |
| 2563 | TLVP_VAL(&tp, GSM48_IE_USER_USER)-1); |
| 2564 | } |
| 2565 | /* ss-version */ |
| 2566 | if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) { |
| 2567 | disc.fields |= MNCC_F_SSVERSION; |
| 2568 | decode_ssversion(&disc.ssversion, |
| 2569 | TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1); |
| 2570 | } |
| 2571 | |
Harald Welte | 596fed4 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 2572 | return mncc_recvmsg(trans->subscr->net, trans, MNCC_DISC_IND, &disc); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2573 | |
| 2574 | } |
| 2575 | |
Harald Welte | c66b71c | 2009-06-11 14:23:20 +0800 | [diff] [blame] | 2576 | static struct gsm_mncc_cause default_cause = { |
| 2577 | .location = GSM48_CAUSE_LOC_PRN_S_LU, |
| 2578 | .coding = 0, |
| 2579 | .rec = 0, |
| 2580 | .rec_val = 0, |
| 2581 | .value = GSM48_CC_CAUSE_NORMAL_UNSPEC, |
| 2582 | .diag_len = 0, |
| 2583 | .diag = { 0 }, |
| 2584 | }; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2585 | |
| 2586 | static int gsm48_cc_tx_disconnect(struct gsm_trans *trans, void *arg) |
| 2587 | { |
| 2588 | struct gsm_mncc *disc = arg; |
| 2589 | struct msgb *msg = gsm48_msgb_alloc(); |
| 2590 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 2591 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2592 | gh->msg_type = GSM48_MT_CC_DISCONNECT; |
| 2593 | |
| 2594 | gsm48_stop_cc_timer(trans); |
| 2595 | gsm48_start_cc_timer(trans, 0x306, GSM48_T306); |
| 2596 | |
| 2597 | /* cause */ |
| 2598 | if (disc->fields & MNCC_F_CAUSE) |
| 2599 | encode_cause(msg, 1, &disc->cause); |
| 2600 | else |
| 2601 | encode_cause(msg, 1, &default_cause); |
| 2602 | |
| 2603 | /* facility */ |
| 2604 | if (disc->fields & MNCC_F_FACILITY) |
| 2605 | encode_facility(msg, 0, &disc->facility); |
| 2606 | /* progress */ |
| 2607 | if (disc->fields & MNCC_F_PROGRESS) |
| 2608 | encode_progress(msg, 0, &disc->progress); |
| 2609 | /* user-user */ |
| 2610 | if (disc->fields & MNCC_F_USERUSER) |
| 2611 | encode_useruser(msg, 0, &disc->useruser); |
| 2612 | |
| 2613 | /* store disconnect cause for T306 expiry */ |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 2614 | memcpy(&trans->cc.msg, disc, sizeof(struct gsm_mncc)); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2615 | |
| 2616 | new_cc_state(trans, GSM_CSTATE_DISCONNECT_IND); |
| 2617 | |
Harald Welte | 39e2ead | 2009-07-23 21:13:03 +0200 | [diff] [blame] | 2618 | return gsm48_sendmsg(msg, trans); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2619 | } |
| 2620 | |
| 2621 | static int gsm48_cc_rx_release(struct gsm_trans *trans, struct msgb *msg) |
| 2622 | { |
| 2623 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 2624 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 2625 | struct tlv_parsed tp; |
| 2626 | struct gsm_mncc rel; |
| 2627 | int rc; |
| 2628 | |
| 2629 | gsm48_stop_cc_timer(trans); |
| 2630 | |
| 2631 | memset(&rel, 0, sizeof(struct gsm_mncc)); |
| 2632 | rel.callref = trans->callref; |
| 2633 | tlv_parse(&tp, &rsl_att_tlvdef, gh->data, payload_len, 0, 0); |
| 2634 | /* cause */ |
| 2635 | if (TLVP_PRESENT(&tp, GSM48_IE_CAUSE)) { |
| 2636 | rel.fields |= MNCC_F_CAUSE; |
| 2637 | decode_cause(&rel.cause, |
| 2638 | TLVP_VAL(&tp, GSM48_IE_CAUSE)-1); |
| 2639 | } |
| 2640 | /* facility */ |
| 2641 | if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) { |
| 2642 | rel.fields |= MNCC_F_FACILITY; |
| 2643 | decode_facility(&rel.facility, |
| 2644 | TLVP_VAL(&tp, GSM48_IE_FACILITY)-1); |
| 2645 | } |
| 2646 | /* user-user */ |
| 2647 | if (TLVP_PRESENT(&tp, GSM48_IE_USER_USER)) { |
| 2648 | rel.fields |= MNCC_F_USERUSER; |
| 2649 | decode_useruser(&rel.useruser, |
| 2650 | TLVP_VAL(&tp, GSM48_IE_USER_USER)-1); |
| 2651 | } |
| 2652 | /* ss-version */ |
| 2653 | if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) { |
| 2654 | rel.fields |= MNCC_F_SSVERSION; |
| 2655 | decode_ssversion(&rel.ssversion, |
| 2656 | TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1); |
| 2657 | } |
| 2658 | |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 2659 | if (trans->cc.state == GSM_CSTATE_RELEASE_REQ) { |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2660 | /* release collision 5.4.5 */ |
Harald Welte | 596fed4 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 2661 | rc = mncc_recvmsg(trans->subscr->net, trans, MNCC_REL_CNF, &rel); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2662 | } else { |
Harald Welte | 596fed4 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 2663 | rc = gsm48_tx_simple(msg->lchan, |
Harald Welte | 6f5aee0 | 2009-07-23 21:21:14 +0200 | [diff] [blame] | 2664 | GSM48_PDISC_CC | (trans->transaction_id << 4), |
Harald Welte | 596fed4 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 2665 | GSM48_MT_CC_RELEASE_COMPL); |
| 2666 | rc = mncc_recvmsg(trans->subscr->net, trans, MNCC_REL_IND, &rel); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2667 | } |
| 2668 | |
| 2669 | new_cc_state(trans, GSM_CSTATE_NULL); |
| 2670 | |
| 2671 | trans->callref = 0; |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 2672 | trans_free(trans); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2673 | |
| 2674 | return rc; |
| 2675 | } |
| 2676 | |
| 2677 | static int gsm48_cc_tx_release(struct gsm_trans *trans, void *arg) |
| 2678 | { |
| 2679 | struct gsm_mncc *rel = arg; |
| 2680 | struct msgb *msg = gsm48_msgb_alloc(); |
| 2681 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 2682 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2683 | gh->msg_type = GSM48_MT_CC_RELEASE; |
| 2684 | |
| 2685 | trans->callref = 0; |
| 2686 | |
| 2687 | gsm48_stop_cc_timer(trans); |
| 2688 | gsm48_start_cc_timer(trans, 0x308, GSM48_T308); |
| 2689 | |
| 2690 | /* cause */ |
| 2691 | if (rel->fields & MNCC_F_CAUSE) |
| 2692 | encode_cause(msg, 0, &rel->cause); |
| 2693 | /* facility */ |
| 2694 | if (rel->fields & MNCC_F_FACILITY) |
| 2695 | encode_facility(msg, 0, &rel->facility); |
| 2696 | /* user-user */ |
| 2697 | if (rel->fields & MNCC_F_USERUSER) |
| 2698 | encode_useruser(msg, 0, &rel->useruser); |
| 2699 | |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 2700 | trans->cc.T308_second = 0; |
| 2701 | memcpy(&trans->cc.msg, rel, sizeof(struct gsm_mncc)); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2702 | |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 2703 | if (trans->cc.state != GSM_CSTATE_RELEASE_REQ) |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2704 | new_cc_state(trans, GSM_CSTATE_RELEASE_REQ); |
| 2705 | |
Harald Welte | 39e2ead | 2009-07-23 21:13:03 +0200 | [diff] [blame] | 2706 | return gsm48_sendmsg(msg, trans); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2707 | } |
| 2708 | |
| 2709 | static int gsm48_cc_rx_release_compl(struct gsm_trans *trans, struct msgb *msg) |
| 2710 | { |
| 2711 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 2712 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 2713 | struct tlv_parsed tp; |
| 2714 | struct gsm_mncc rel; |
| 2715 | int rc = 0; |
| 2716 | |
| 2717 | gsm48_stop_cc_timer(trans); |
| 2718 | |
| 2719 | memset(&rel, 0, sizeof(struct gsm_mncc)); |
| 2720 | rel.callref = trans->callref; |
| 2721 | tlv_parse(&tp, &rsl_att_tlvdef, gh->data, payload_len, 0, 0); |
| 2722 | /* cause */ |
| 2723 | if (TLVP_PRESENT(&tp, GSM48_IE_CAUSE)) { |
| 2724 | rel.fields |= MNCC_F_CAUSE; |
| 2725 | decode_cause(&rel.cause, |
| 2726 | TLVP_VAL(&tp, GSM48_IE_CAUSE)-1); |
| 2727 | } |
| 2728 | /* facility */ |
| 2729 | if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) { |
| 2730 | rel.fields |= MNCC_F_FACILITY; |
| 2731 | decode_facility(&rel.facility, |
| 2732 | TLVP_VAL(&tp, GSM48_IE_FACILITY)-1); |
| 2733 | } |
| 2734 | /* user-user */ |
| 2735 | if (TLVP_PRESENT(&tp, GSM48_IE_USER_USER)) { |
| 2736 | rel.fields |= MNCC_F_USERUSER; |
| 2737 | decode_useruser(&rel.useruser, |
| 2738 | TLVP_VAL(&tp, GSM48_IE_USER_USER)-1); |
| 2739 | } |
| 2740 | /* ss-version */ |
| 2741 | if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) { |
| 2742 | rel.fields |= MNCC_F_SSVERSION; |
| 2743 | decode_ssversion(&rel.ssversion, |
| 2744 | TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1); |
| 2745 | } |
| 2746 | |
| 2747 | if (trans->callref) { |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 2748 | switch (trans->cc.state) { |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2749 | case GSM_CSTATE_CALL_PRESENT: |
Harald Welte | 596fed4 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 2750 | rc = mncc_recvmsg(trans->subscr->net, trans, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2751 | MNCC_REJ_IND, &rel); |
| 2752 | break; |
| 2753 | case GSM_CSTATE_RELEASE_REQ: |
Harald Welte | 596fed4 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 2754 | rc = mncc_recvmsg(trans->subscr->net, trans, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2755 | MNCC_REL_CNF, &rel); |
Harald Welte | b83d938 | 2009-12-12 21:00:48 +0100 | [diff] [blame] | 2756 | /* FIXME: in case of multiple calls, we can't simply |
| 2757 | * hang up here ! */ |
| 2758 | lchan_auto_release(msg->lchan); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2759 | break; |
| 2760 | default: |
Harald Welte | 596fed4 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 2761 | rc = mncc_recvmsg(trans->subscr->net, trans, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2762 | MNCC_REL_IND, &rel); |
| 2763 | } |
| 2764 | } |
| 2765 | |
| 2766 | trans->callref = 0; |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 2767 | trans_free(trans); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2768 | |
| 2769 | return rc; |
| 2770 | } |
| 2771 | |
| 2772 | static int gsm48_cc_tx_release_compl(struct gsm_trans *trans, void *arg) |
| 2773 | { |
| 2774 | struct gsm_mncc *rel = arg; |
| 2775 | struct msgb *msg = gsm48_msgb_alloc(); |
| 2776 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 2777 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2778 | gh->msg_type = GSM48_MT_CC_RELEASE_COMPL; |
| 2779 | |
| 2780 | trans->callref = 0; |
| 2781 | |
| 2782 | gsm48_stop_cc_timer(trans); |
| 2783 | |
| 2784 | /* cause */ |
| 2785 | if (rel->fields & MNCC_F_CAUSE) |
| 2786 | encode_cause(msg, 0, &rel->cause); |
| 2787 | /* facility */ |
| 2788 | if (rel->fields & MNCC_F_FACILITY) |
| 2789 | encode_facility(msg, 0, &rel->facility); |
| 2790 | /* user-user */ |
| 2791 | if (rel->fields & MNCC_F_USERUSER) |
| 2792 | encode_useruser(msg, 0, &rel->useruser); |
| 2793 | |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 2794 | trans_free(trans); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2795 | |
Harald Welte | 39e2ead | 2009-07-23 21:13:03 +0200 | [diff] [blame] | 2796 | return gsm48_sendmsg(msg, trans); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2797 | } |
| 2798 | |
| 2799 | static int gsm48_cc_rx_facility(struct gsm_trans *trans, struct msgb *msg) |
| 2800 | { |
| 2801 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 2802 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 2803 | struct tlv_parsed tp; |
| 2804 | struct gsm_mncc fac; |
| 2805 | |
| 2806 | memset(&fac, 0, sizeof(struct gsm_mncc)); |
| 2807 | fac.callref = trans->callref; |
| 2808 | tlv_parse(&tp, &rsl_att_tlvdef, gh->data, payload_len, GSM48_IE_FACILITY, 0); |
| 2809 | /* facility */ |
| 2810 | if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) { |
| 2811 | fac.fields |= MNCC_F_FACILITY; |
| 2812 | decode_facility(&fac.facility, |
| 2813 | TLVP_VAL(&tp, GSM48_IE_FACILITY)-1); |
| 2814 | } |
| 2815 | /* ss-version */ |
| 2816 | if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) { |
| 2817 | fac.fields |= MNCC_F_SSVERSION; |
| 2818 | decode_ssversion(&fac.ssversion, |
| 2819 | TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1); |
| 2820 | } |
| 2821 | |
Harald Welte | 596fed4 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 2822 | return mncc_recvmsg(trans->subscr->net, trans, MNCC_FACILITY_IND, &fac); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2823 | } |
| 2824 | |
| 2825 | static int gsm48_cc_tx_facility(struct gsm_trans *trans, void *arg) |
| 2826 | { |
| 2827 | struct gsm_mncc *fac = arg; |
| 2828 | struct msgb *msg = gsm48_msgb_alloc(); |
| 2829 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 2830 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2831 | gh->msg_type = GSM48_MT_CC_FACILITY; |
| 2832 | |
| 2833 | /* facility */ |
| 2834 | encode_facility(msg, 1, &fac->facility); |
| 2835 | |
Harald Welte | 39e2ead | 2009-07-23 21:13:03 +0200 | [diff] [blame] | 2836 | return gsm48_sendmsg(msg, trans); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2837 | } |
| 2838 | |
| 2839 | static int gsm48_cc_rx_hold(struct gsm_trans *trans, struct msgb *msg) |
| 2840 | { |
| 2841 | struct gsm_mncc hold; |
| 2842 | |
| 2843 | memset(&hold, 0, sizeof(struct gsm_mncc)); |
| 2844 | hold.callref = trans->callref; |
Harald Welte | 596fed4 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 2845 | return mncc_recvmsg(trans->subscr->net, trans, MNCC_HOLD_IND, &hold); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2846 | } |
| 2847 | |
| 2848 | static int gsm48_cc_tx_hold_ack(struct gsm_trans *trans, void *arg) |
| 2849 | { |
| 2850 | struct msgb *msg = gsm48_msgb_alloc(); |
| 2851 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 2852 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2853 | gh->msg_type = GSM48_MT_CC_HOLD_ACK; |
| 2854 | |
Harald Welte | 39e2ead | 2009-07-23 21:13:03 +0200 | [diff] [blame] | 2855 | return gsm48_sendmsg(msg, trans); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2856 | } |
| 2857 | |
| 2858 | static int gsm48_cc_tx_hold_rej(struct gsm_trans *trans, void *arg) |
| 2859 | { |
| 2860 | struct gsm_mncc *hold_rej = arg; |
| 2861 | struct msgb *msg = gsm48_msgb_alloc(); |
| 2862 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 2863 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2864 | gh->msg_type = GSM48_MT_CC_HOLD_REJ; |
| 2865 | |
| 2866 | /* cause */ |
| 2867 | if (hold_rej->fields & MNCC_F_CAUSE) |
| 2868 | encode_cause(msg, 1, &hold_rej->cause); |
| 2869 | else |
| 2870 | encode_cause(msg, 1, &default_cause); |
| 2871 | |
Harald Welte | 39e2ead | 2009-07-23 21:13:03 +0200 | [diff] [blame] | 2872 | return gsm48_sendmsg(msg, trans); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2873 | } |
| 2874 | |
| 2875 | static int gsm48_cc_rx_retrieve(struct gsm_trans *trans, struct msgb *msg) |
| 2876 | { |
| 2877 | struct gsm_mncc retrieve; |
| 2878 | |
| 2879 | memset(&retrieve, 0, sizeof(struct gsm_mncc)); |
| 2880 | retrieve.callref = trans->callref; |
Harald Welte | 596fed4 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 2881 | return mncc_recvmsg(trans->subscr->net, trans, MNCC_RETRIEVE_IND, |
| 2882 | &retrieve); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2883 | } |
| 2884 | |
| 2885 | static int gsm48_cc_tx_retrieve_ack(struct gsm_trans *trans, void *arg) |
| 2886 | { |
| 2887 | struct msgb *msg = gsm48_msgb_alloc(); |
| 2888 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 2889 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2890 | gh->msg_type = GSM48_MT_CC_RETR_ACK; |
| 2891 | |
Harald Welte | 39e2ead | 2009-07-23 21:13:03 +0200 | [diff] [blame] | 2892 | return gsm48_sendmsg(msg, trans); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2893 | } |
| 2894 | |
| 2895 | static int gsm48_cc_tx_retrieve_rej(struct gsm_trans *trans, void *arg) |
| 2896 | { |
| 2897 | struct gsm_mncc *retrieve_rej = arg; |
| 2898 | struct msgb *msg = gsm48_msgb_alloc(); |
| 2899 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 2900 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2901 | gh->msg_type = GSM48_MT_CC_RETR_REJ; |
| 2902 | |
| 2903 | /* cause */ |
| 2904 | if (retrieve_rej->fields & MNCC_F_CAUSE) |
| 2905 | encode_cause(msg, 1, &retrieve_rej->cause); |
| 2906 | else |
| 2907 | encode_cause(msg, 1, &default_cause); |
| 2908 | |
Harald Welte | 39e2ead | 2009-07-23 21:13:03 +0200 | [diff] [blame] | 2909 | return gsm48_sendmsg(msg, trans); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2910 | } |
| 2911 | |
| 2912 | static int gsm48_cc_rx_start_dtmf(struct gsm_trans *trans, struct msgb *msg) |
| 2913 | { |
| 2914 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 2915 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 2916 | struct tlv_parsed tp; |
| 2917 | struct gsm_mncc dtmf; |
| 2918 | |
| 2919 | memset(&dtmf, 0, sizeof(struct gsm_mncc)); |
| 2920 | dtmf.callref = trans->callref; |
| 2921 | tlv_parse(&tp, &rsl_att_tlvdef, gh->data, payload_len, 0, 0); |
| 2922 | /* keypad facility */ |
| 2923 | if (TLVP_PRESENT(&tp, GSM48_IE_KPD_FACILITY)) { |
| 2924 | dtmf.fields |= MNCC_F_KEYPAD; |
| 2925 | decode_keypad(&dtmf.keypad, |
| 2926 | TLVP_VAL(&tp, GSM48_IE_KPD_FACILITY)-1); |
| 2927 | } |
| 2928 | |
Harald Welte | 596fed4 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 2929 | return mncc_recvmsg(trans->subscr->net, trans, MNCC_START_DTMF_IND, &dtmf); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2930 | } |
| 2931 | |
| 2932 | static int gsm48_cc_tx_start_dtmf_ack(struct gsm_trans *trans, void *arg) |
| 2933 | { |
| 2934 | struct gsm_mncc *dtmf = arg; |
| 2935 | struct msgb *msg = gsm48_msgb_alloc(); |
| 2936 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 2937 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2938 | gh->msg_type = GSM48_MT_CC_START_DTMF_ACK; |
| 2939 | |
| 2940 | /* keypad */ |
| 2941 | if (dtmf->fields & MNCC_F_KEYPAD) |
| 2942 | encode_keypad(msg, dtmf->keypad); |
| 2943 | |
Harald Welte | 39e2ead | 2009-07-23 21:13:03 +0200 | [diff] [blame] | 2944 | return gsm48_sendmsg(msg, trans); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2945 | } |
| 2946 | |
| 2947 | static int gsm48_cc_tx_start_dtmf_rej(struct gsm_trans *trans, void *arg) |
| 2948 | { |
| 2949 | struct gsm_mncc *dtmf = arg; |
| 2950 | struct msgb *msg = gsm48_msgb_alloc(); |
| 2951 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 2952 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2953 | gh->msg_type = GSM48_MT_CC_START_DTMF_REJ; |
| 2954 | |
| 2955 | /* cause */ |
| 2956 | if (dtmf->fields & MNCC_F_CAUSE) |
| 2957 | encode_cause(msg, 1, &dtmf->cause); |
| 2958 | else |
| 2959 | encode_cause(msg, 1, &default_cause); |
| 2960 | |
Harald Welte | 39e2ead | 2009-07-23 21:13:03 +0200 | [diff] [blame] | 2961 | return gsm48_sendmsg(msg, trans); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2962 | } |
| 2963 | |
| 2964 | static int gsm48_cc_tx_stop_dtmf_ack(struct gsm_trans *trans, void *arg) |
| 2965 | { |
| 2966 | struct msgb *msg = gsm48_msgb_alloc(); |
| 2967 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 2968 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2969 | gh->msg_type = GSM48_MT_CC_STOP_DTMF_ACK; |
| 2970 | |
Harald Welte | 39e2ead | 2009-07-23 21:13:03 +0200 | [diff] [blame] | 2971 | return gsm48_sendmsg(msg, trans); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2972 | } |
| 2973 | |
| 2974 | static int gsm48_cc_rx_stop_dtmf(struct gsm_trans *trans, struct msgb *msg) |
| 2975 | { |
| 2976 | struct gsm_mncc dtmf; |
| 2977 | |
| 2978 | memset(&dtmf, 0, sizeof(struct gsm_mncc)); |
| 2979 | dtmf.callref = trans->callref; |
| 2980 | |
Harald Welte | 596fed4 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 2981 | return mncc_recvmsg(trans->subscr->net, trans, MNCC_STOP_DTMF_IND, &dtmf); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2982 | } |
| 2983 | |
| 2984 | static int gsm48_cc_rx_modify(struct gsm_trans *trans, struct msgb *msg) |
| 2985 | { |
| 2986 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 2987 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 2988 | struct tlv_parsed tp; |
| 2989 | struct gsm_mncc modify; |
| 2990 | |
| 2991 | memset(&modify, 0, sizeof(struct gsm_mncc)); |
| 2992 | modify.callref = trans->callref; |
| 2993 | tlv_parse(&tp, &rsl_att_tlvdef, gh->data, payload_len, GSM48_IE_BEARER_CAP, 0); |
| 2994 | /* bearer capability */ |
| 2995 | if (TLVP_PRESENT(&tp, GSM48_IE_BEARER_CAP)) { |
| 2996 | modify.fields |= MNCC_F_BEARER_CAP; |
| 2997 | decode_bearer_cap(&modify.bearer_cap, |
| 2998 | TLVP_VAL(&tp, GSM48_IE_BEARER_CAP)-1); |
| 2999 | } |
| 3000 | |
| 3001 | new_cc_state(trans, GSM_CSTATE_MO_ORIG_MODIFY); |
| 3002 | |
Harald Welte | 596fed4 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 3003 | return mncc_recvmsg(trans->subscr->net, trans, MNCC_MODIFY_IND, &modify); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3004 | } |
| 3005 | |
| 3006 | static int gsm48_cc_tx_modify(struct gsm_trans *trans, void *arg) |
| 3007 | { |
| 3008 | struct gsm_mncc *modify = arg; |
| 3009 | struct msgb *msg = gsm48_msgb_alloc(); |
| 3010 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 3011 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3012 | gh->msg_type = GSM48_MT_CC_MODIFY; |
| 3013 | |
| 3014 | gsm48_start_cc_timer(trans, 0x323, GSM48_T323); |
| 3015 | |
| 3016 | /* bearer capability */ |
| 3017 | encode_bearer_cap(msg, 1, &modify->bearer_cap); |
| 3018 | |
| 3019 | new_cc_state(trans, GSM_CSTATE_MO_TERM_MODIFY); |
| 3020 | |
Harald Welte | 39e2ead | 2009-07-23 21:13:03 +0200 | [diff] [blame] | 3021 | return gsm48_sendmsg(msg, trans); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3022 | } |
| 3023 | |
| 3024 | static int gsm48_cc_rx_modify_complete(struct gsm_trans *trans, struct msgb *msg) |
| 3025 | { |
| 3026 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 3027 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 3028 | struct tlv_parsed tp; |
| 3029 | struct gsm_mncc modify; |
| 3030 | |
| 3031 | gsm48_stop_cc_timer(trans); |
| 3032 | |
| 3033 | memset(&modify, 0, sizeof(struct gsm_mncc)); |
| 3034 | modify.callref = trans->callref; |
| 3035 | tlv_parse(&tp, &rsl_att_tlvdef, gh->data, payload_len, GSM48_IE_BEARER_CAP, 0); |
| 3036 | /* bearer capability */ |
| 3037 | if (TLVP_PRESENT(&tp, GSM48_IE_BEARER_CAP)) { |
| 3038 | modify.fields |= MNCC_F_BEARER_CAP; |
| 3039 | decode_bearer_cap(&modify.bearer_cap, |
| 3040 | TLVP_VAL(&tp, GSM48_IE_BEARER_CAP)-1); |
| 3041 | } |
| 3042 | |
| 3043 | new_cc_state(trans, GSM_CSTATE_ACTIVE); |
| 3044 | |
Harald Welte | 596fed4 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 3045 | return mncc_recvmsg(trans->subscr->net, trans, MNCC_MODIFY_CNF, &modify); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3046 | } |
| 3047 | |
| 3048 | static int gsm48_cc_tx_modify_complete(struct gsm_trans *trans, void *arg) |
| 3049 | { |
| 3050 | struct gsm_mncc *modify = arg; |
| 3051 | struct msgb *msg = gsm48_msgb_alloc(); |
| 3052 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 3053 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3054 | gh->msg_type = GSM48_MT_CC_MODIFY_COMPL; |
| 3055 | |
| 3056 | /* bearer capability */ |
| 3057 | encode_bearer_cap(msg, 1, &modify->bearer_cap); |
| 3058 | |
| 3059 | new_cc_state(trans, GSM_CSTATE_ACTIVE); |
| 3060 | |
Harald Welte | 39e2ead | 2009-07-23 21:13:03 +0200 | [diff] [blame] | 3061 | return gsm48_sendmsg(msg, trans); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3062 | } |
| 3063 | |
| 3064 | static int gsm48_cc_rx_modify_reject(struct gsm_trans *trans, struct msgb *msg) |
| 3065 | { |
| 3066 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 3067 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 3068 | struct tlv_parsed tp; |
| 3069 | struct gsm_mncc modify; |
| 3070 | |
| 3071 | gsm48_stop_cc_timer(trans); |
| 3072 | |
| 3073 | memset(&modify, 0, sizeof(struct gsm_mncc)); |
| 3074 | modify.callref = trans->callref; |
| 3075 | tlv_parse(&tp, &rsl_att_tlvdef, gh->data, payload_len, GSM48_IE_BEARER_CAP, GSM48_IE_CAUSE); |
| 3076 | /* bearer capability */ |
| 3077 | if (TLVP_PRESENT(&tp, GSM48_IE_BEARER_CAP)) { |
| 3078 | modify.fields |= GSM48_IE_BEARER_CAP; |
| 3079 | decode_bearer_cap(&modify.bearer_cap, |
| 3080 | TLVP_VAL(&tp, GSM48_IE_BEARER_CAP)-1); |
| 3081 | } |
| 3082 | /* cause */ |
| 3083 | if (TLVP_PRESENT(&tp, GSM48_IE_CAUSE)) { |
| 3084 | modify.fields |= MNCC_F_CAUSE; |
| 3085 | decode_cause(&modify.cause, |
| 3086 | TLVP_VAL(&tp, GSM48_IE_CAUSE)-1); |
| 3087 | } |
| 3088 | |
| 3089 | new_cc_state(trans, GSM_CSTATE_ACTIVE); |
| 3090 | |
Harald Welte | 596fed4 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 3091 | return mncc_recvmsg(trans->subscr->net, trans, MNCC_MODIFY_REJ, &modify); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3092 | } |
| 3093 | |
| 3094 | static int gsm48_cc_tx_modify_reject(struct gsm_trans *trans, void *arg) |
| 3095 | { |
| 3096 | struct gsm_mncc *modify = arg; |
| 3097 | struct msgb *msg = gsm48_msgb_alloc(); |
| 3098 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 3099 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3100 | gh->msg_type = GSM48_MT_CC_MODIFY_REJECT; |
| 3101 | |
| 3102 | /* bearer capability */ |
| 3103 | encode_bearer_cap(msg, 1, &modify->bearer_cap); |
| 3104 | /* cause */ |
| 3105 | encode_cause(msg, 1, &modify->cause); |
| 3106 | |
| 3107 | new_cc_state(trans, GSM_CSTATE_ACTIVE); |
| 3108 | |
Harald Welte | 39e2ead | 2009-07-23 21:13:03 +0200 | [diff] [blame] | 3109 | return gsm48_sendmsg(msg, trans); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3110 | } |
| 3111 | |
| 3112 | static int gsm48_cc_tx_notify(struct gsm_trans *trans, void *arg) |
| 3113 | { |
| 3114 | struct gsm_mncc *notify = arg; |
| 3115 | struct msgb *msg = gsm48_msgb_alloc(); |
| 3116 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 3117 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3118 | gh->msg_type = GSM48_MT_CC_NOTIFY; |
| 3119 | |
| 3120 | /* notify */ |
| 3121 | encode_notify(msg, notify->notify); |
| 3122 | |
Harald Welte | 39e2ead | 2009-07-23 21:13:03 +0200 | [diff] [blame] | 3123 | return gsm48_sendmsg(msg, trans); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3124 | } |
| 3125 | |
| 3126 | static int gsm48_cc_rx_notify(struct gsm_trans *trans, struct msgb *msg) |
| 3127 | { |
| 3128 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 3129 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 3130 | // struct tlv_parsed tp; |
| 3131 | struct gsm_mncc notify; |
| 3132 | |
| 3133 | memset(¬ify, 0, sizeof(struct gsm_mncc)); |
| 3134 | notify.callref = trans->callref; |
| 3135 | // tlv_parse(&tp, &rsl_att_tlvdef, gh->data, payload_len); |
| 3136 | if (payload_len >= 1) |
| 3137 | decode_notify(¬ify.notify, gh->data); |
| 3138 | |
Harald Welte | 596fed4 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 3139 | return mncc_recvmsg(trans->subscr->net, trans, MNCC_NOTIFY_IND, ¬ify); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3140 | } |
| 3141 | |
| 3142 | static int gsm48_cc_tx_userinfo(struct gsm_trans *trans, void *arg) |
| 3143 | { |
| 3144 | struct gsm_mncc *user = arg; |
| 3145 | struct msgb *msg = gsm48_msgb_alloc(); |
| 3146 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 3147 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3148 | gh->msg_type = GSM48_MT_CC_USER_INFO; |
| 3149 | |
| 3150 | /* user-user */ |
| 3151 | if (user->fields & MNCC_F_USERUSER) |
| 3152 | encode_useruser(msg, 1, &user->useruser); |
| 3153 | /* more data */ |
| 3154 | if (user->more) |
| 3155 | encode_more(msg); |
| 3156 | |
Harald Welte | 39e2ead | 2009-07-23 21:13:03 +0200 | [diff] [blame] | 3157 | return gsm48_sendmsg(msg, trans); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3158 | } |
| 3159 | |
| 3160 | static int gsm48_cc_rx_userinfo(struct gsm_trans *trans, struct msgb *msg) |
| 3161 | { |
| 3162 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 3163 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 3164 | struct tlv_parsed tp; |
| 3165 | struct gsm_mncc user; |
| 3166 | |
| 3167 | memset(&user, 0, sizeof(struct gsm_mncc)); |
| 3168 | user.callref = trans->callref; |
| 3169 | tlv_parse(&tp, &rsl_att_tlvdef, gh->data, payload_len, GSM48_IE_USER_USER, 0); |
| 3170 | /* user-user */ |
| 3171 | if (TLVP_PRESENT(&tp, GSM48_IE_USER_USER)) { |
| 3172 | user.fields |= MNCC_F_USERUSER; |
| 3173 | decode_useruser(&user.useruser, |
| 3174 | TLVP_VAL(&tp, GSM48_IE_USER_USER)-1); |
| 3175 | } |
| 3176 | /* more data */ |
| 3177 | if (TLVP_PRESENT(&tp, GSM48_IE_MORE_DATA)) |
| 3178 | user.more = 1; |
| 3179 | |
Harald Welte | 596fed4 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 3180 | return mncc_recvmsg(trans->subscr->net, trans, MNCC_USERINFO_IND, &user); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3181 | } |
| 3182 | |
Holger Hans Peter Freyther | ff3f260 | 2009-10-22 15:13:00 +0200 | [diff] [blame] | 3183 | static int _gsm48_lchan_modify(struct gsm_trans *trans, void *arg) |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3184 | { |
| 3185 | struct gsm_mncc *mode = arg; |
| 3186 | |
Holger Hans Peter Freyther | ea52802 | 2009-11-18 22:57:02 +0100 | [diff] [blame] | 3187 | return gsm48_lchan_modify(trans->lchan, mode->lchan_mode); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3188 | } |
| 3189 | |
| 3190 | static struct downstate { |
| 3191 | u_int32_t states; |
| 3192 | int type; |
| 3193 | int (*rout) (struct gsm_trans *trans, void *arg); |
| 3194 | } downstatelist[] = { |
| 3195 | /* mobile originating call establishment */ |
| 3196 | {SBIT(GSM_CSTATE_INITIATED), /* 5.2.1.2 */ |
| 3197 | MNCC_CALL_PROC_REQ, gsm48_cc_tx_call_proc}, |
| 3198 | {SBIT(GSM_CSTATE_INITIATED) | SBIT(GSM_CSTATE_MO_CALL_PROC), /* 5.2.1.2 | 5.2.1.5 */ |
| 3199 | MNCC_ALERT_REQ, gsm48_cc_tx_alerting}, |
| 3200 | {SBIT(GSM_CSTATE_INITIATED) | SBIT(GSM_CSTATE_MO_CALL_PROC) | SBIT(GSM_CSTATE_CALL_DELIVERED), /* 5.2.1.2 | 5.2.1.6 | 5.2.1.6 */ |
| 3201 | MNCC_SETUP_RSP, gsm48_cc_tx_connect}, |
| 3202 | {SBIT(GSM_CSTATE_MO_CALL_PROC), /* 5.2.1.4.2 */ |
| 3203 | MNCC_PROGRESS_REQ, gsm48_cc_tx_progress}, |
| 3204 | /* mobile terminating call establishment */ |
| 3205 | {SBIT(GSM_CSTATE_NULL), /* 5.2.2.1 */ |
| 3206 | MNCC_SETUP_REQ, gsm48_cc_tx_setup}, |
| 3207 | {SBIT(GSM_CSTATE_CONNECT_REQUEST), |
| 3208 | MNCC_SETUP_COMPL_REQ, gsm48_cc_tx_connect_ack}, |
| 3209 | /* signalling during call */ |
| 3210 | {SBIT(GSM_CSTATE_ACTIVE), |
| 3211 | MNCC_NOTIFY_REQ, gsm48_cc_tx_notify}, |
| 3212 | {ALL_STATES - SBIT(GSM_CSTATE_NULL) - SBIT(GSM_CSTATE_RELEASE_REQ), |
| 3213 | MNCC_FACILITY_REQ, gsm48_cc_tx_facility}, |
| 3214 | {ALL_STATES, |
| 3215 | MNCC_START_DTMF_RSP, gsm48_cc_tx_start_dtmf_ack}, |
| 3216 | {ALL_STATES, |
| 3217 | MNCC_START_DTMF_REJ, gsm48_cc_tx_start_dtmf_rej}, |
| 3218 | {ALL_STATES, |
| 3219 | MNCC_STOP_DTMF_RSP, gsm48_cc_tx_stop_dtmf_ack}, |
| 3220 | {SBIT(GSM_CSTATE_ACTIVE), |
| 3221 | MNCC_HOLD_CNF, gsm48_cc_tx_hold_ack}, |
| 3222 | {SBIT(GSM_CSTATE_ACTIVE), |
| 3223 | MNCC_HOLD_REJ, gsm48_cc_tx_hold_rej}, |
| 3224 | {SBIT(GSM_CSTATE_ACTIVE), |
| 3225 | MNCC_RETRIEVE_CNF, gsm48_cc_tx_retrieve_ack}, |
| 3226 | {SBIT(GSM_CSTATE_ACTIVE), |
| 3227 | MNCC_RETRIEVE_REJ, gsm48_cc_tx_retrieve_rej}, |
| 3228 | {SBIT(GSM_CSTATE_ACTIVE), |
| 3229 | MNCC_MODIFY_REQ, gsm48_cc_tx_modify}, |
| 3230 | {SBIT(GSM_CSTATE_MO_ORIG_MODIFY), |
| 3231 | MNCC_MODIFY_RSP, gsm48_cc_tx_modify_complete}, |
| 3232 | {SBIT(GSM_CSTATE_MO_ORIG_MODIFY), |
| 3233 | MNCC_MODIFY_REJ, gsm48_cc_tx_modify_reject}, |
| 3234 | {SBIT(GSM_CSTATE_ACTIVE), |
| 3235 | MNCC_USERINFO_REQ, gsm48_cc_tx_userinfo}, |
| 3236 | /* clearing */ |
| 3237 | {SBIT(GSM_CSTATE_INITIATED), |
| 3238 | MNCC_REJ_REQ, gsm48_cc_tx_release_compl}, |
| 3239 | {ALL_STATES - SBIT(GSM_CSTATE_NULL) - SBIT(GSM_CSTATE_DISCONNECT_IND) - SBIT(GSM_CSTATE_RELEASE_REQ) - SBIT(GSM_CSTATE_DISCONNECT_REQ), /* 5.4.4 */ |
| 3240 | MNCC_DISC_REQ, gsm48_cc_tx_disconnect}, |
| 3241 | {ALL_STATES - SBIT(GSM_CSTATE_NULL) - SBIT(GSM_CSTATE_RELEASE_REQ), /* 5.4.3.2 */ |
| 3242 | MNCC_REL_REQ, gsm48_cc_tx_release}, |
| 3243 | /* special */ |
| 3244 | {ALL_STATES, |
Holger Hans Peter Freyther | ff3f260 | 2009-10-22 15:13:00 +0200 | [diff] [blame] | 3245 | MNCC_LCHAN_MODIFY, _gsm48_lchan_modify}, |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3246 | }; |
| 3247 | |
| 3248 | #define DOWNSLLEN \ |
| 3249 | (sizeof(downstatelist) / sizeof(struct downstate)) |
| 3250 | |
| 3251 | |
| 3252 | int mncc_send(struct gsm_network *net, int msg_type, void *arg) |
| 3253 | { |
Harald Welte | 1a6f798 | 2009-08-09 18:52:33 +0200 | [diff] [blame] | 3254 | int i, rc = 0; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3255 | struct gsm_trans *trans = NULL, *transt; |
Harald Welte | 1a6f798 | 2009-08-09 18:52:33 +0200 | [diff] [blame] | 3256 | struct gsm_lchan *lchan = NULL; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3257 | struct gsm_bts *bts = NULL; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3258 | struct gsm_mncc *data = arg, rel; |
| 3259 | |
| 3260 | /* handle special messages */ |
| 3261 | switch(msg_type) { |
| 3262 | case MNCC_BRIDGE: |
| 3263 | return tch_bridge(net, arg); |
| 3264 | case MNCC_FRAME_DROP: |
| 3265 | return tch_recv(net, arg, 0); |
| 3266 | case MNCC_FRAME_RECV: |
| 3267 | return tch_recv(net, arg, 1); |
| 3268 | case GSM_TRAU_FRAME: |
| 3269 | return tch_frame(net, arg); |
| 3270 | } |
| 3271 | |
| 3272 | memset(&rel, 0, sizeof(struct gsm_mncc)); |
| 3273 | rel.callref = data->callref; |
| 3274 | |
| 3275 | /* Find callref */ |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 3276 | trans = trans_find_by_callref(net, data->callref); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3277 | |
| 3278 | /* Callref unknown */ |
| 3279 | if (!trans) { |
Holger Hans Peter Freyther | ccf53c6 | 2009-10-27 14:21:14 +0100 | [diff] [blame] | 3280 | struct gsm_subscriber *subscr; |
| 3281 | |
Harald Welte | 4a3464c | 2009-07-04 10:11:24 +0200 | [diff] [blame] | 3282 | if (msg_type != MNCC_SETUP_REQ) { |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3283 | DEBUGP(DCC, "(bts - trx - ts - ti -- sub %s) " |
| 3284 | "Received '%s' from MNCC with " |
| 3285 | "unknown callref %d\n", data->called.number, |
| 3286 | get_mncc_name(msg_type), data->callref); |
| 3287 | /* Invalid call reference */ |
Andreas Eversberg | 7563ac9 | 2009-06-14 22:14:12 +0800 | [diff] [blame] | 3288 | return mncc_release_ind(net, NULL, data->callref, |
| 3289 | GSM48_CAUSE_LOC_PRN_S_LU, |
| 3290 | GSM48_CC_CAUSE_INVAL_TRANS_ID); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3291 | } |
Andreas Eversberg | c079be4 | 2009-06-15 23:22:09 +0200 | [diff] [blame] | 3292 | if (!data->called.number[0] && !data->imsi[0]) { |
| 3293 | DEBUGP(DCC, "(bts - trx - ts - ti) " |
| 3294 | "Received '%s' from MNCC with " |
| 3295 | "no number or IMSI\n", get_mncc_name(msg_type)); |
| 3296 | /* Invalid number */ |
| 3297 | return mncc_release_ind(net, NULL, data->callref, |
| 3298 | GSM48_CAUSE_LOC_PRN_S_LU, |
| 3299 | GSM48_CC_CAUSE_INV_NR_FORMAT); |
| 3300 | } |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3301 | /* New transaction due to setup, find subscriber */ |
Andreas Eversberg | c079be4 | 2009-06-15 23:22:09 +0200 | [diff] [blame] | 3302 | if (data->called.number[0]) |
Harald Welte | 9176bd4 | 2009-07-23 18:46:00 +0200 | [diff] [blame] | 3303 | subscr = subscr_get_by_extension(net, |
| 3304 | data->called.number); |
Andreas Eversberg | c079be4 | 2009-06-15 23:22:09 +0200 | [diff] [blame] | 3305 | else |
Harald Welte | 9176bd4 | 2009-07-23 18:46:00 +0200 | [diff] [blame] | 3306 | subscr = subscr_get_by_imsi(net, data->imsi); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3307 | /* If subscriber is not found */ |
| 3308 | if (!subscr) { |
| 3309 | DEBUGP(DCC, "(bts - trx - ts - ti -- sub %s) " |
| 3310 | "Received '%s' from MNCC with " |
| 3311 | "unknown subscriber %s\n", data->called.number, |
| 3312 | get_mncc_name(msg_type), data->called.number); |
| 3313 | /* Unknown subscriber */ |
Andreas Eversberg | 7563ac9 | 2009-06-14 22:14:12 +0800 | [diff] [blame] | 3314 | return mncc_release_ind(net, NULL, data->callref, |
| 3315 | GSM48_CAUSE_LOC_PRN_S_LU, |
| 3316 | GSM48_CC_CAUSE_UNASSIGNED_NR); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3317 | } |
| 3318 | /* If subscriber is not "attached" */ |
| 3319 | if (!subscr->lac) { |
| 3320 | DEBUGP(DCC, "(bts - trx - ts - ti -- sub %s) " |
| 3321 | "Received '%s' from MNCC with " |
| 3322 | "detached subscriber %s\n", data->called.number, |
| 3323 | get_mncc_name(msg_type), data->called.number); |
| 3324 | subscr_put(subscr); |
| 3325 | /* Temporarily out of order */ |
Andreas Eversberg | 7563ac9 | 2009-06-14 22:14:12 +0800 | [diff] [blame] | 3326 | return mncc_release_ind(net, NULL, data->callref, |
| 3327 | GSM48_CAUSE_LOC_PRN_S_LU, |
| 3328 | GSM48_CC_CAUSE_DEST_OOO); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3329 | } |
| 3330 | /* Create transaction */ |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 3331 | trans = trans_alloc(subscr, GSM48_PDISC_CC, 0xff, data->callref); |
| 3332 | if (!trans) { |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3333 | DEBUGP(DCC, "No memory for trans.\n"); |
| 3334 | subscr_put(subscr); |
| 3335 | /* Ressource unavailable */ |
Andreas Eversberg | 7563ac9 | 2009-06-14 22:14:12 +0800 | [diff] [blame] | 3336 | mncc_release_ind(net, NULL, data->callref, |
| 3337 | GSM48_CAUSE_LOC_PRN_S_LU, |
| 3338 | GSM48_CC_CAUSE_RESOURCE_UNAVAIL); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3339 | return -ENOMEM; |
| 3340 | } |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3341 | /* Find lchan */ |
Harald Welte | 1a6f798 | 2009-08-09 18:52:33 +0200 | [diff] [blame] | 3342 | lchan = lchan_for_subscr(subscr); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3343 | /* If subscriber has no lchan */ |
| 3344 | if (!lchan) { |
| 3345 | /* find transaction with this subscriber already paging */ |
| 3346 | llist_for_each_entry(transt, &net->trans_list, entry) { |
| 3347 | /* Transaction of our lchan? */ |
| 3348 | if (transt == trans || |
| 3349 | transt->subscr != subscr) |
| 3350 | continue; |
| 3351 | DEBUGP(DCC, "(bts %d trx - ts - ti -- sub %s) " |
| 3352 | "Received '%s' from MNCC with " |
| 3353 | "unallocated channel, paging already " |
| 3354 | "started.\n", bts->nr, |
| 3355 | data->called.number, |
| 3356 | get_mncc_name(msg_type)); |
Holger Hans Peter Freyther | ccf53c6 | 2009-10-27 14:21:14 +0100 | [diff] [blame] | 3357 | subscr_put(subscr); |
| 3358 | trans_free(trans); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3359 | return 0; |
| 3360 | } |
| 3361 | /* store setup informations until paging was successfull */ |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 3362 | memcpy(&trans->cc.msg, data, sizeof(struct gsm_mncc)); |
Harald Welte | a1b2858 | 2009-08-01 19:31:47 +0200 | [diff] [blame] | 3363 | /* Trigger paging */ |
| 3364 | paging_request(net, subscr, RSL_CHANNEED_TCH_F, |
| 3365 | setup_trig_pag_evt, subscr); |
Holger Hans Peter Freyther | ccf53c6 | 2009-10-27 14:21:14 +0100 | [diff] [blame] | 3366 | subscr_put(subscr); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3367 | return 0; |
| 3368 | } |
| 3369 | /* Assign lchan */ |
| 3370 | trans->lchan = lchan; |
| 3371 | use_lchan(lchan); |
Holger Hans Peter Freyther | ccf53c6 | 2009-10-27 14:21:14 +0100 | [diff] [blame] | 3372 | subscr_put(subscr); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3373 | } |
| 3374 | lchan = trans->lchan; |
| 3375 | |
| 3376 | /* if paging did not respond yet */ |
| 3377 | if (!lchan) { |
| 3378 | DEBUGP(DCC, "(bts - trx - ts - ti -- sub %s) " |
| 3379 | "Received '%s' from MNCC in paging state\n", |
| 3380 | (trans->subscr)?(trans->subscr->extension):"-", |
| 3381 | get_mncc_name(msg_type)); |
Harald Welte | c66b71c | 2009-06-11 14:23:20 +0800 | [diff] [blame] | 3382 | mncc_set_cause(&rel, GSM48_CAUSE_LOC_PRN_S_LU, |
| 3383 | GSM48_CC_CAUSE_NORM_CALL_CLEAR); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3384 | if (msg_type == MNCC_REL_REQ) |
| 3385 | rc = mncc_recvmsg(net, trans, MNCC_REL_CNF, &rel); |
| 3386 | else |
| 3387 | rc = mncc_recvmsg(net, trans, MNCC_REL_IND, &rel); |
| 3388 | trans->callref = 0; |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 3389 | trans_free(trans); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3390 | return rc; |
| 3391 | } |
| 3392 | |
| 3393 | DEBUGP(DCC, "(bts %d trx %d ts %d ti %02x sub %s) " |
| 3394 | "Received '%s' from MNCC in state %d (%s)\n", |
| 3395 | lchan->ts->trx->bts->nr, lchan->ts->trx->nr, lchan->ts->nr, |
| 3396 | trans->transaction_id, |
| 3397 | (lchan->subscr)?(lchan->subscr->extension):"-", |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 3398 | get_mncc_name(msg_type), trans->cc.state, |
| 3399 | cc_state_names[trans->cc.state]); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3400 | |
| 3401 | /* Find function for current state and message */ |
| 3402 | for (i = 0; i < DOWNSLLEN; i++) |
| 3403 | if ((msg_type == downstatelist[i].type) |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 3404 | && ((1 << trans->cc.state) & downstatelist[i].states)) |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3405 | break; |
| 3406 | if (i == DOWNSLLEN) { |
| 3407 | DEBUGP(DCC, "Message unhandled at this state.\n"); |
| 3408 | return 0; |
| 3409 | } |
| 3410 | |
| 3411 | rc = downstatelist[i].rout(trans, arg); |
| 3412 | |
| 3413 | return rc; |
| 3414 | } |
| 3415 | |
| 3416 | |
| 3417 | static struct datastate { |
| 3418 | u_int32_t states; |
| 3419 | int type; |
| 3420 | int (*rout) (struct gsm_trans *trans, struct msgb *msg); |
| 3421 | } datastatelist[] = { |
| 3422 | /* mobile originating call establishment */ |
| 3423 | {SBIT(GSM_CSTATE_NULL), /* 5.2.1.2 */ |
| 3424 | GSM48_MT_CC_SETUP, gsm48_cc_rx_setup}, |
| 3425 | {SBIT(GSM_CSTATE_NULL), /* 5.2.1.2 */ |
| 3426 | GSM48_MT_CC_EMERG_SETUP, gsm48_cc_rx_setup}, |
| 3427 | {SBIT(GSM_CSTATE_CONNECT_IND), /* 5.2.1.2 */ |
| 3428 | GSM48_MT_CC_CONNECT_ACK, gsm48_cc_rx_connect_ack}, |
| 3429 | /* mobile terminating call establishment */ |
| 3430 | {SBIT(GSM_CSTATE_CALL_PRESENT), /* 5.2.2.3.2 */ |
| 3431 | GSM48_MT_CC_CALL_CONF, gsm48_cc_rx_call_conf}, |
| 3432 | {SBIT(GSM_CSTATE_CALL_PRESENT) | SBIT(GSM_CSTATE_MO_TERM_CALL_CONF), /* ???? | 5.2.2.3.2 */ |
| 3433 | GSM48_MT_CC_ALERTING, gsm48_cc_rx_alerting}, |
| 3434 | {SBIT(GSM_CSTATE_CALL_PRESENT) | SBIT(GSM_CSTATE_MO_TERM_CALL_CONF) | SBIT(GSM_CSTATE_CALL_RECEIVED), /* (5.2.2.6) | 5.2.2.6 | 5.2.2.6 */ |
| 3435 | GSM48_MT_CC_CONNECT, gsm48_cc_rx_connect}, |
| 3436 | /* signalling during call */ |
| 3437 | {ALL_STATES - SBIT(GSM_CSTATE_NULL), |
| 3438 | GSM48_MT_CC_FACILITY, gsm48_cc_rx_facility}, |
| 3439 | {SBIT(GSM_CSTATE_ACTIVE), |
| 3440 | GSM48_MT_CC_NOTIFY, gsm48_cc_rx_notify}, |
| 3441 | {ALL_STATES, |
| 3442 | GSM48_MT_CC_START_DTMF, gsm48_cc_rx_start_dtmf}, |
| 3443 | {ALL_STATES, |
| 3444 | GSM48_MT_CC_STOP_DTMF, gsm48_cc_rx_stop_dtmf}, |
| 3445 | {ALL_STATES, |
| 3446 | GSM48_MT_CC_STATUS_ENQ, gsm48_cc_rx_status_enq}, |
| 3447 | {SBIT(GSM_CSTATE_ACTIVE), |
| 3448 | GSM48_MT_CC_HOLD, gsm48_cc_rx_hold}, |
| 3449 | {SBIT(GSM_CSTATE_ACTIVE), |
| 3450 | GSM48_MT_CC_RETR, gsm48_cc_rx_retrieve}, |
| 3451 | {SBIT(GSM_CSTATE_ACTIVE), |
| 3452 | GSM48_MT_CC_MODIFY, gsm48_cc_rx_modify}, |
| 3453 | {SBIT(GSM_CSTATE_MO_TERM_MODIFY), |
| 3454 | GSM48_MT_CC_MODIFY_COMPL, gsm48_cc_rx_modify_complete}, |
| 3455 | {SBIT(GSM_CSTATE_MO_TERM_MODIFY), |
| 3456 | GSM48_MT_CC_MODIFY_REJECT, gsm48_cc_rx_modify_reject}, |
| 3457 | {SBIT(GSM_CSTATE_ACTIVE), |
| 3458 | GSM48_MT_CC_USER_INFO, gsm48_cc_rx_userinfo}, |
| 3459 | /* clearing */ |
| 3460 | {ALL_STATES - SBIT(GSM_CSTATE_NULL) - SBIT(GSM_CSTATE_RELEASE_REQ), /* 5.4.3.2 */ |
| 3461 | GSM48_MT_CC_DISCONNECT, gsm48_cc_rx_disconnect}, |
| 3462 | {ALL_STATES - SBIT(GSM_CSTATE_NULL), /* 5.4.4.1.2.2 */ |
| 3463 | GSM48_MT_CC_RELEASE, gsm48_cc_rx_release}, |
| 3464 | {ALL_STATES, /* 5.4.3.4 */ |
| 3465 | GSM48_MT_CC_RELEASE_COMPL, gsm48_cc_rx_release_compl}, |
| 3466 | }; |
| 3467 | |
| 3468 | #define DATASLLEN \ |
| 3469 | (sizeof(datastatelist) / sizeof(struct datastate)) |
| 3470 | |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 3471 | static int gsm0408_rcv_cc(struct msgb *msg) |
| 3472 | { |
| 3473 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 3474 | u_int8_t msg_type = gh->msg_type & 0xbf; |
Harald Welte | 6f5aee0 | 2009-07-23 21:21:14 +0200 | [diff] [blame] | 3475 | u_int8_t transaction_id = ((gh->proto_discr & 0xf0) ^ 0x80) >> 4; /* flip */ |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3476 | struct gsm_lchan *lchan = msg->lchan; |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 3477 | struct gsm_trans *trans = NULL; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3478 | int i, rc = 0; |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 3479 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3480 | if (msg_type & 0x80) { |
| 3481 | DEBUGP(DCC, "MSG 0x%2x not defined for PD error\n", msg_type); |
| 3482 | return -EINVAL; |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 3483 | } |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3484 | |
| 3485 | /* Find transaction */ |
Harald Welte | b8b4073 | 2009-07-23 21:58:40 +0200 | [diff] [blame] | 3486 | trans = trans_find_by_id(lchan->subscr, GSM48_PDISC_CC, transaction_id); |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 3487 | |
Harald Welte | 6f5aee0 | 2009-07-23 21:21:14 +0200 | [diff] [blame] | 3488 | DEBUGP(DCC, "(bts %d trx %d ts %d ti %x sub %s) " |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3489 | "Received '%s' from MS in state %d (%s)\n", |
| 3490 | lchan->ts->trx->bts->nr, lchan->ts->trx->nr, lchan->ts->nr, |
| 3491 | transaction_id, (lchan->subscr)?(lchan->subscr->extension):"-", |
Holger Hans Peter Freyther | 1494a76 | 2009-08-01 07:26:59 +0200 | [diff] [blame] | 3492 | gsm0408_cc_msg_names[msg_type], trans?(trans->cc.state):0, |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 3493 | cc_state_names[trans?(trans->cc.state):0]); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3494 | |
| 3495 | /* Create transaction */ |
| 3496 | if (!trans) { |
Harald Welte | 6f5aee0 | 2009-07-23 21:21:14 +0200 | [diff] [blame] | 3497 | DEBUGP(DCC, "Unknown transaction ID %x, " |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3498 | "creating new trans.\n", transaction_id); |
| 3499 | /* Create transaction */ |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 3500 | trans = trans_alloc(lchan->subscr, GSM48_PDISC_CC, |
| 3501 | transaction_id, new_callref++); |
| 3502 | if (!trans) { |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3503 | DEBUGP(DCC, "No memory for trans.\n"); |
| 3504 | rc = gsm48_tx_simple(msg->lchan, |
Harald Welte | 6f5aee0 | 2009-07-23 21:21:14 +0200 | [diff] [blame] | 3505 | GSM48_PDISC_CC | (transaction_id << 4), |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3506 | GSM48_MT_CC_RELEASE_COMPL); |
| 3507 | return -ENOMEM; |
| 3508 | } |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3509 | /* Assign transaction */ |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3510 | trans->lchan = lchan; |
| 3511 | use_lchan(lchan); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3512 | } |
| 3513 | |
| 3514 | /* find function for current state and message */ |
| 3515 | for (i = 0; i < DATASLLEN; i++) |
| 3516 | if ((msg_type == datastatelist[i].type) |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 3517 | && ((1 << trans->cc.state) & datastatelist[i].states)) |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3518 | break; |
| 3519 | if (i == DATASLLEN) { |
| 3520 | DEBUGP(DCC, "Message unhandled at this state.\n"); |
| 3521 | return 0; |
| 3522 | } |
| 3523 | |
| 3524 | rc = datastatelist[i].rout(trans, msg); |
Harald Welte | 4bc90a1 | 2008-12-27 16:32:52 +0000 | [diff] [blame] | 3525 | |
| 3526 | return rc; |
| 3527 | } |
| 3528 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 3529 | /* here we pass in a msgb from the RSL->RLL. We expect the l3 pointer to be set */ |
Harald Welte (local) | daef606 | 2009-08-14 11:41:12 +0200 | [diff] [blame] | 3530 | int gsm0408_rcvmsg(struct msgb *msg, u_int8_t link_id) |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 3531 | { |
| 3532 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 3533 | u_int8_t pdisc = gh->proto_discr & 0x0f; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 3534 | int rc = 0; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 3535 | |
| 3536 | switch (pdisc) { |
| 3537 | case GSM48_PDISC_CC: |
| 3538 | rc = gsm0408_rcv_cc(msg); |
| 3539 | break; |
| 3540 | case GSM48_PDISC_MM: |
| 3541 | rc = gsm0408_rcv_mm(msg); |
| 3542 | break; |
| 3543 | case GSM48_PDISC_RR: |
| 3544 | rc = gsm0408_rcv_rr(msg); |
| 3545 | break; |
Harald Welte | bcae43f | 2008-12-27 21:45:37 +0000 | [diff] [blame] | 3546 | case GSM48_PDISC_SMS: |
Harald Welte (local) | daef606 | 2009-08-14 11:41:12 +0200 | [diff] [blame] | 3547 | rc = gsm0411_rcv_sms(msg, link_id); |
Harald Welte | bcae43f | 2008-12-27 21:45:37 +0000 | [diff] [blame] | 3548 | break; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 3549 | case GSM48_PDISC_MM_GPRS: |
Harald Welte | bcae43f | 2008-12-27 21:45:37 +0000 | [diff] [blame] | 3550 | case GSM48_PDISC_SM_GPRS: |
Mike Haben | 59d284e | 2009-09-26 19:00:03 +0200 | [diff] [blame] | 3551 | fprintf(stderr, "Unimplemented GSM 04.08 discriminator 0x%02x\n", |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 3552 | pdisc); |
| 3553 | break; |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 3554 | case GSM48_PDISC_NC_SS: |
| 3555 | rc = handle_rcv_ussd(msg); |
| 3556 | break; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 3557 | default: |
Mike Haben | 59d284e | 2009-09-26 19:00:03 +0200 | [diff] [blame] | 3558 | fprintf(stderr, "Unknown GSM 04.08 discriminator 0x%02x\n", |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 3559 | pdisc); |
| 3560 | break; |
| 3561 | } |
| 3562 | |
| 3563 | return rc; |
| 3564 | } |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 3565 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3566 | /* dequeue messages to layer 4 */ |
| 3567 | int bsc_upqueue(struct gsm_network *net) |
| 3568 | { |
| 3569 | struct gsm_mncc *mncc; |
| 3570 | struct msgb *msg; |
| 3571 | int work = 0; |
| 3572 | |
| 3573 | if (net) |
| 3574 | while ((msg = msgb_dequeue(&net->upqueue))) { |
| 3575 | mncc = (struct gsm_mncc *)msg->data; |
| 3576 | if (net->mncc_recv) |
| 3577 | net->mncc_recv(net, mncc->msg_type, mncc); |
| 3578 | work = 1; /* work done */ |
Harald Welte | 316c825 | 2009-06-26 19:40:48 +0200 | [diff] [blame] | 3579 | talloc_free(msg); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3580 | } |
| 3581 | |
| 3582 | return work; |
| 3583 | } |
Harald Welte | dcaf565 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 3584 | |
Harald Welte | 805f644 | 2009-07-28 18:25:29 +0200 | [diff] [blame] | 3585 | /* |
| 3586 | * This will be ran by the linker when loading the DSO. We use it to |
| 3587 | * do system initialization, e.g. registration of signal handlers. |
| 3588 | */ |
| 3589 | static __attribute__((constructor)) void on_dso_load_0408(void) |
| 3590 | { |
Harald Welte | 805f644 | 2009-07-28 18:25:29 +0200 | [diff] [blame] | 3591 | register_signal_handler(SS_LCHAN, gsm0408_handle_lchan_signal, NULL); |
| 3592 | register_signal_handler(SS_ABISIP, handle_abisip_signal, NULL); |
| 3593 | } |