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