2009-07-23 19:25:08 +00:00
|
|
|
/* GSM 04.07 Transaction handling */
|
|
|
|
|
|
|
|
/* (C) 2009 by Harald Welte <laforge@gnumonks.org>
|
|
|
|
* All Rights Reserved
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
2011-01-01 14:25:50 +00:00
|
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2009-07-23 19:25:08 +00:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2011-01-01 14:25:50 +00:00
|
|
|
* GNU Affero General Public License for more details.
|
2009-07-23 19:25:08 +00:00
|
|
|
*
|
2011-01-01 14:25:50 +00:00
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2009-07-23 19:25:08 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2017-09-04 13:04:35 +00:00
|
|
|
#include <osmocom/msc/transaction.h>
|
|
|
|
#include <osmocom/msc/gsm_data.h>
|
|
|
|
#include <osmocom/msc/mncc.h>
|
|
|
|
#include <osmocom/msc/debug.h>
|
2011-03-22 15:47:59 +00:00
|
|
|
#include <osmocom/core/talloc.h>
|
2017-09-04 13:04:35 +00:00
|
|
|
#include <osmocom/msc/gsm_04_08.h>
|
|
|
|
#include <osmocom/msc/mncc.h>
|
|
|
|
#include <osmocom/msc/osmo_msc.h>
|
|
|
|
#include <osmocom/msc/vlr.h>
|
2009-07-23 19:25:08 +00:00
|
|
|
|
2009-08-15 00:30:58 +00:00
|
|
|
void *tall_trans_ctx;
|
2009-07-23 19:25:08 +00:00
|
|
|
|
2009-08-10 05:54:02 +00:00
|
|
|
void _gsm48_cc_trans_free(struct gsm_trans *trans);
|
2018-06-17 14:09:28 +00:00
|
|
|
void _gsm911_nc_ss_trans_free(struct gsm_trans *trans);
|
2009-08-10 05:54:02 +00:00
|
|
|
|
2016-06-19 16:06:02 +00:00
|
|
|
/*! Find a transaction in connection for given protocol + transaction ID
|
|
|
|
* \param[in] conn Connection in whihc we want to find transaction
|
|
|
|
* \param[in] proto Protocol of transaction
|
|
|
|
* \param[in] trans_id Transaction ID of transaction
|
|
|
|
* \returns Matching transaction, if any
|
|
|
|
*/
|
2014-12-02 13:22:53 +00:00
|
|
|
struct gsm_trans *trans_find_by_id(struct gsm_subscriber_connection *conn,
|
2011-04-18 15:04:00 +00:00
|
|
|
uint8_t proto, uint8_t trans_id)
|
2009-07-23 19:25:08 +00:00
|
|
|
{
|
|
|
|
struct gsm_trans *trans;
|
2016-05-09 19:09:47 +00:00
|
|
|
struct gsm_network *net = conn->network;
|
2016-06-19 16:06:02 +00:00
|
|
|
struct vlr_subscr *vsub = conn->vsub;
|
2009-07-23 19:25:08 +00:00
|
|
|
|
|
|
|
llist_for_each_entry(trans, &net->trans_list, entry) {
|
2016-06-19 16:06:02 +00:00
|
|
|
if (trans->vsub == vsub &&
|
2009-07-23 19:58:40 +00:00
|
|
|
trans->protocol == proto &&
|
|
|
|
trans->transaction_id == trans_id)
|
2009-07-23 19:25:08 +00:00
|
|
|
return trans;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-06-19 16:06:02 +00:00
|
|
|
/*! Find a transaction by call reference
|
|
|
|
* \param[in] net Network in which we should search
|
|
|
|
* \param[in] callref Call Reference of transaction
|
|
|
|
* \returns Matching transaction, if any
|
|
|
|
*/
|
2009-07-23 19:25:08 +00:00
|
|
|
struct gsm_trans *trans_find_by_callref(struct gsm_network *net,
|
2011-04-18 15:04:00 +00:00
|
|
|
uint32_t callref)
|
2009-07-23 19:25:08 +00:00
|
|
|
{
|
|
|
|
struct gsm_trans *trans;
|
|
|
|
|
|
|
|
llist_for_each_entry(trans, &net->trans_list, entry) {
|
|
|
|
if (trans->callref == callref)
|
|
|
|
return trans;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-06-19 16:06:02 +00:00
|
|
|
/*! Allocate a new transaction and add it to network list
|
|
|
|
* \param[in] net Netwokr in which we allocate transaction
|
|
|
|
* \param[in] subscr Subscriber for which we allocate transaction
|
|
|
|
* \param[in] protocol Protocol (CC/SMS/...)
|
|
|
|
* \param[in] callref Call Reference
|
|
|
|
* \returns Transaction
|
|
|
|
*/
|
2014-12-02 13:22:53 +00:00
|
|
|
struct gsm_trans *trans_alloc(struct gsm_network *net,
|
2016-06-19 16:06:02 +00:00
|
|
|
struct vlr_subscr *vsub,
|
2011-04-18 15:04:00 +00:00
|
|
|
uint8_t protocol, uint8_t trans_id,
|
|
|
|
uint32_t callref)
|
2009-07-23 19:25:08 +00:00
|
|
|
{
|
|
|
|
struct gsm_trans *trans;
|
|
|
|
|
2017-07-05 10:34:18 +00:00
|
|
|
/* a valid subscriber is indispensable */
|
|
|
|
if (vsub == NULL) {
|
|
|
|
LOGP(DCC, LOGL_NOTICE,
|
|
|
|
"unable to alloc transaction, invalid subscriber (NULL)\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-11-22 00:58:00 +00:00
|
|
|
DEBUGP(DCC, "(ti %02x sub %s callref %x) New transaction\n",
|
|
|
|
trans_id, vlr_subscr_name(vsub), callref);
|
|
|
|
|
2009-07-23 19:25:08 +00:00
|
|
|
trans = talloc_zero(tall_trans_ctx, struct gsm_trans);
|
|
|
|
if (!trans)
|
|
|
|
return NULL;
|
|
|
|
|
2016-06-19 16:06:02 +00:00
|
|
|
trans->vsub = vlr_subscr_get(vsub);
|
2009-07-23 19:25:08 +00:00
|
|
|
|
|
|
|
trans->protocol = protocol;
|
|
|
|
trans->transaction_id = trans_id;
|
|
|
|
trans->callref = callref;
|
|
|
|
|
2014-12-02 10:58:00 +00:00
|
|
|
trans->net = net;
|
|
|
|
llist_add_tail(&trans->entry, &net->trans_list);
|
2009-07-23 19:25:08 +00:00
|
|
|
|
|
|
|
return trans;
|
|
|
|
}
|
|
|
|
|
2016-06-19 16:06:02 +00:00
|
|
|
/*! Release a transaction
|
|
|
|
* \param[in] trans Transaction to be released
|
|
|
|
*/
|
2009-07-23 19:25:08 +00:00
|
|
|
void trans_free(struct gsm_trans *trans)
|
|
|
|
{
|
2017-11-22 13:33:12 +00:00
|
|
|
enum msc_subscr_conn_use conn_usage_token = MSC_CONN_USE_UNTRACKED;
|
2018-03-12 22:59:07 +00:00
|
|
|
struct gsm_subscriber_connection *conn;
|
2017-11-22 13:33:12 +00:00
|
|
|
|
2009-07-23 19:25:08 +00:00
|
|
|
switch (trans->protocol) {
|
|
|
|
case GSM48_PDISC_CC:
|
|
|
|
_gsm48_cc_trans_free(trans);
|
2017-11-22 13:33:12 +00:00
|
|
|
conn_usage_token = MSC_CONN_USE_TRANS_CC;
|
2009-07-23 19:25:08 +00:00
|
|
|
break;
|
2009-08-14 12:52:17 +00:00
|
|
|
case GSM48_PDISC_SMS:
|
|
|
|
_gsm411_sms_trans_free(trans);
|
2017-11-22 13:33:12 +00:00
|
|
|
conn_usage_token = MSC_CONN_USE_TRANS_SMS;
|
2009-08-14 12:52:17 +00:00
|
|
|
break;
|
2018-04-17 12:17:11 +00:00
|
|
|
case GSM48_PDISC_NC_SS:
|
2018-06-17 14:09:28 +00:00
|
|
|
_gsm911_nc_ss_trans_free(trans);
|
2018-04-17 12:17:11 +00:00
|
|
|
conn_usage_token = MSC_CONN_USE_TRANS_NC_SS;
|
|
|
|
break;
|
2009-07-23 19:25:08 +00:00
|
|
|
}
|
|
|
|
|
2015-04-06 10:03:45 +00:00
|
|
|
if (trans->paging_request) {
|
|
|
|
subscr_remove_request(trans->paging_request);
|
2010-12-29 16:09:07 +00:00
|
|
|
trans->paging_request = NULL;
|
2009-07-23 19:25:08 +00:00
|
|
|
}
|
|
|
|
|
2016-06-19 16:06:02 +00:00
|
|
|
if (trans->vsub) {
|
|
|
|
vlr_subscr_put(trans->vsub);
|
|
|
|
trans->vsub = NULL;
|
2012-12-22 17:16:47 +00:00
|
|
|
}
|
2009-07-23 19:25:08 +00:00
|
|
|
|
2018-03-12 22:59:07 +00:00
|
|
|
conn = trans->conn;
|
2013-12-27 17:07:23 +00:00
|
|
|
trans->conn = NULL;
|
refactor subscr_conn and subscr_conn_fsm de-/alloc
Refactor:
1. Glue the gsm_subscriber_connection alloc to the subscr_conn_fsm.
2. Add separate AUTH_CIPH state to the FSM.
3. Use conn->use_count to trigger conn release.
4. Add separate RELEASING state to the FSM.
5. Add rate counters for each of the three Complete Layer 3 types.
Details:
1. Glue the gsm_subscriber_connection alloc to the subscr_conn_fsm.
Historically, a gsm_subscriber_connection was allocated in libbsc land, and
only upon Complete Layer 3 did libmsc add the fsm instance. After splitting
openbsc.git into a separate osmo-msc, this is no longer necessary, hence:
Closely tie gsm_subscriber_connection allocation to the subscr_conn_fsm
instance: talloc the conn as a child of the FSM instance, and discard the conn
as soon as the FSM terminates.
2. Add separate AUTH_CIPH state to the FSM.
Decoding the Complete Layer 3 message is distinctly separate from waiting for
the VLR FSMs to conclude. Use the NEW state as "we don't know if this is a
valid message yet", and the AUTH_CIPH state as "evaluating, don't release".
A profound effect of this: should we for any odd reason fail to leave the FSM's
NEW state, the conn will be released right at the end of msc_compl_l3(),
without needing to trigger release in each code path.
3. Use conn->use_count to trigger conn release.
Before, the FSM itself would hold a use count on the conn, and hence we would
need to ask it whether it is ready to release the conn yet by dispatching
events, to achieve a use_count decrement.
Instead, unite the FSM instance and conn, and do not hold a use count by the
FSM. Hence, trigger an FSM "UNUSED" event only when the use_count reaches zero.
As long as use counts are done correctly, the FSM will terminate correctly.
These exceptions:
- The new AUTH_CIPH state explicitly ignores UNUSED events, since we expect the
use count to reach zero while evaluating Authentication and Ciphering. (I
experimented with holding a use count by AUTH_CIPH onenter() and releasing by
onleave(), but the use count and thus the conn are released before the next
state can initiate transactions that would increment the use count again.
Same thing for the VLR FSMs holding a use count, they should be done before
we advance to the next state. The easiest is to simply expect zero use count
during the AUTH_CIPH state.)
- A CM Service Request means that even though the MSC would be through with all
it wants to do, we shall still wait for a request to follow from the MS.
Hence the FSM holds a use count on itself while a CM Service is pending.
- While waiting for a Release/Clear Complete, the FSM holds a use count on
itself.
4. Add separate RELEASING state to the FSM.
If we decide to release for other reasons than a use count reaching zero, we
still need to be able to wait for the msc_dtap() use count on the conn to
release.
(An upcoming patch will further use the RELEASING state to properly wait for
Clear Complete / Release Complete messages.)
5. Add rate counters for each of the three Complete Layer 3 types.
Besides LU, also count CM Service Request and Paging Response
acceptance/rejections. Without these counters, only very few of the auth+ciph
outcomes actually show in the counters.
Related: OS#3122
Change-Id: I55feb379e176a96a831e105b86202b17a0ffe889
2018-03-30 22:02:14 +00:00
|
|
|
llist_del(&trans->entry);
|
2009-07-23 19:25:08 +00:00
|
|
|
talloc_free(trans);
|
2018-03-12 22:59:07 +00:00
|
|
|
|
refactor subscr_conn and subscr_conn_fsm de-/alloc
Refactor:
1. Glue the gsm_subscriber_connection alloc to the subscr_conn_fsm.
2. Add separate AUTH_CIPH state to the FSM.
3. Use conn->use_count to trigger conn release.
4. Add separate RELEASING state to the FSM.
5. Add rate counters for each of the three Complete Layer 3 types.
Details:
1. Glue the gsm_subscriber_connection alloc to the subscr_conn_fsm.
Historically, a gsm_subscriber_connection was allocated in libbsc land, and
only upon Complete Layer 3 did libmsc add the fsm instance. After splitting
openbsc.git into a separate osmo-msc, this is no longer necessary, hence:
Closely tie gsm_subscriber_connection allocation to the subscr_conn_fsm
instance: talloc the conn as a child of the FSM instance, and discard the conn
as soon as the FSM terminates.
2. Add separate AUTH_CIPH state to the FSM.
Decoding the Complete Layer 3 message is distinctly separate from waiting for
the VLR FSMs to conclude. Use the NEW state as "we don't know if this is a
valid message yet", and the AUTH_CIPH state as "evaluating, don't release".
A profound effect of this: should we for any odd reason fail to leave the FSM's
NEW state, the conn will be released right at the end of msc_compl_l3(),
without needing to trigger release in each code path.
3. Use conn->use_count to trigger conn release.
Before, the FSM itself would hold a use count on the conn, and hence we would
need to ask it whether it is ready to release the conn yet by dispatching
events, to achieve a use_count decrement.
Instead, unite the FSM instance and conn, and do not hold a use count by the
FSM. Hence, trigger an FSM "UNUSED" event only when the use_count reaches zero.
As long as use counts are done correctly, the FSM will terminate correctly.
These exceptions:
- The new AUTH_CIPH state explicitly ignores UNUSED events, since we expect the
use count to reach zero while evaluating Authentication and Ciphering. (I
experimented with holding a use count by AUTH_CIPH onenter() and releasing by
onleave(), but the use count and thus the conn are released before the next
state can initiate transactions that would increment the use count again.
Same thing for the VLR FSMs holding a use count, they should be done before
we advance to the next state. The easiest is to simply expect zero use count
during the AUTH_CIPH state.)
- A CM Service Request means that even though the MSC would be through with all
it wants to do, we shall still wait for a request to follow from the MS.
Hence the FSM holds a use count on itself while a CM Service is pending.
- While waiting for a Release/Clear Complete, the FSM holds a use count on
itself.
4. Add separate RELEASING state to the FSM.
If we decide to release for other reasons than a use count reaching zero, we
still need to be able to wait for the msc_dtap() use count on the conn to
release.
(An upcoming patch will further use the RELEASING state to properly wait for
Clear Complete / Release Complete messages.)
5. Add rate counters for each of the three Complete Layer 3 types.
Besides LU, also count CM Service Request and Paging Response
acceptance/rejections. Without these counters, only very few of the auth+ciph
outcomes actually show in the counters.
Related: OS#3122
Change-Id: I55feb379e176a96a831e105b86202b17a0ffe889
2018-03-30 22:02:14 +00:00
|
|
|
if (conn)
|
|
|
|
msc_subscr_conn_put(conn, conn_usage_token);
|
2009-07-23 19:25:08 +00:00
|
|
|
}
|
|
|
|
|
2016-06-19 16:06:02 +00:00
|
|
|
/*! allocate an unused transaction ID for the given subscriber
|
|
|
|
* in the given protocol using the ti_flag specified
|
|
|
|
* \param[in] net GSM network
|
|
|
|
* \param[in] subscr Subscriber for which to find ID
|
|
|
|
* \param[in] protocol Protocol for whihc to find ID
|
|
|
|
* \param[in] ti_flag FIXME
|
|
|
|
*/
|
|
|
|
int trans_assign_trans_id(struct gsm_network *net, struct vlr_subscr *vsub,
|
2011-04-18 15:04:00 +00:00
|
|
|
uint8_t protocol, uint8_t ti_flag)
|
2009-07-23 19:25:08 +00:00
|
|
|
{
|
|
|
|
struct gsm_trans *trans;
|
|
|
|
unsigned int used_tid_bitmask = 0;
|
2009-12-24 12:26:17 +00:00
|
|
|
int i, j, h;
|
2009-07-23 19:36:44 +00:00
|
|
|
|
|
|
|
if (ti_flag)
|
|
|
|
ti_flag = 0x8;
|
2009-07-23 19:25:08 +00:00
|
|
|
|
|
|
|
/* generate bitmask of already-used TIDs for this (subscr,proto) */
|
|
|
|
llist_for_each_entry(trans, &net->trans_list, entry) {
|
2016-06-19 16:06:02 +00:00
|
|
|
if (trans->vsub != vsub ||
|
2009-07-23 19:25:08 +00:00
|
|
|
trans->protocol != protocol ||
|
|
|
|
trans->transaction_id == 0xff)
|
|
|
|
continue;
|
|
|
|
used_tid_bitmask |= (1 << trans->transaction_id);
|
|
|
|
}
|
|
|
|
|
2009-12-24 12:26:17 +00:00
|
|
|
/* find a new one, trying to go in a 'circular' pattern */
|
|
|
|
for (h = 6; h > 0; h--)
|
|
|
|
if (used_tid_bitmask & (1 << (h | ti_flag)))
|
|
|
|
break;
|
2009-12-18 17:28:11 +00:00
|
|
|
for (i = 0; i < 7; i++) {
|
2009-12-24 12:26:17 +00:00
|
|
|
j = ((h + i) % 7) | ti_flag;
|
|
|
|
if ((used_tid_bitmask & (1 << j)) == 0)
|
|
|
|
return j;
|
2009-07-23 19:36:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
2009-07-23 19:25:08 +00:00
|
|
|
}
|
2012-11-23 20:33:15 +00:00
|
|
|
|
2016-06-19 16:06:02 +00:00
|
|
|
/*! Check if we have any transaction for given connection
|
|
|
|
* \param[in] conn Connection to check
|
|
|
|
* \returns 1 in case there is a transaction, 0 otherwise
|
|
|
|
*/
|
2016-05-20 19:59:55 +00:00
|
|
|
struct gsm_trans *trans_has_conn(const struct gsm_subscriber_connection *conn)
|
2012-11-23 20:33:15 +00:00
|
|
|
{
|
|
|
|
struct gsm_trans *trans;
|
|
|
|
|
2016-05-09 19:09:47 +00:00
|
|
|
llist_for_each_entry(trans, &conn->network->trans_list, entry)
|
2012-11-23 20:33:15 +00:00
|
|
|
if (trans->conn == conn)
|
2016-05-20 19:59:55 +00:00
|
|
|
return trans;
|
2012-11-23 20:33:15 +00:00
|
|
|
|
2016-05-20 19:59:55 +00:00
|
|
|
return NULL;
|
2012-11-23 20:33:15 +00:00
|
|
|
}
|
2016-06-19 16:06:02 +00:00
|
|
|
|
|
|
|
/*! Free all transactions associated with a connection, presumably when the
|
|
|
|
* conn is being closed. The transaction code will inform the CC or SMS
|
|
|
|
* facilities, which will then send the necessary release indications.
|
|
|
|
* \param[in] conn Connection that is going to be closed.
|
|
|
|
*/
|
|
|
|
void trans_conn_closed(struct gsm_subscriber_connection *conn)
|
|
|
|
{
|
|
|
|
struct gsm_trans *trans;
|
|
|
|
|
|
|
|
/* As part of the CC REL_IND the remote leg might be released and this
|
|
|
|
* will trigger another call to trans_free. This is something the llist
|
|
|
|
* macro can not handle and we need to re-iterate the list every time.
|
|
|
|
*/
|
|
|
|
restart:
|
|
|
|
llist_for_each_entry(trans, &conn->network->trans_list, entry) {
|
|
|
|
if (trans->conn == conn) {
|
|
|
|
trans_free(trans);
|
|
|
|
goto restart;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|