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