2010-07-27 19:32:52 +00:00
|
|
|
/* MTP layer3 main handling code */
|
|
|
|
/*
|
|
|
|
* (C) 2010 by Holger Hans Peter Freyther <zecke@selfish.org>
|
|
|
|
* (C) 2010 by On-Waves
|
|
|
|
* All Rights Reserved
|
|
|
|
*
|
2011-01-16 16:45:14 +00:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* 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
|
2010-07-27 19:32:52 +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-16 16:45:14 +00:00
|
|
|
* GNU Affero General Public License for more details.
|
2010-07-27 19:32:52 +00:00
|
|
|
*
|
2011-01-16 16:45:14 +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/>.
|
2010-07-27 19:32:52 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include <mtp_data.h>
|
|
|
|
#include <mtp_level3.h>
|
2011-01-04 12:21:52 +00:00
|
|
|
#include <bsc_data.h>
|
2010-07-30 21:25:35 +00:00
|
|
|
#include <cellmgr_debug.h>
|
2010-12-10 06:34:01 +00:00
|
|
|
#include <isup_types.h>
|
2011-01-21 19:54:55 +00:00
|
|
|
#include <counter.h>
|
2010-07-27 19:32:52 +00:00
|
|
|
|
2010-07-30 21:25:35 +00:00
|
|
|
#include <osmocore/talloc.h>
|
2010-07-27 19:32:52 +00:00
|
|
|
|
2010-08-04 10:39:26 +00:00
|
|
|
#include <osmocom/sccp/sccp.h>
|
2010-07-27 19:32:52 +00:00
|
|
|
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
static void *tall_mtp_ctx = NULL;
|
|
|
|
|
2011-01-02 17:47:49 +00:00
|
|
|
static int mtp_int_submit(struct mtp_link_set *link, int pc, int sls, int type, const uint8_t *data, unsigned int length);
|
2010-12-10 11:18:57 +00:00
|
|
|
|
2011-01-24 19:49:58 +00:00
|
|
|
void mtp_link_submit(struct mtp_link *link, struct msgb *msg)
|
2011-01-21 19:54:55 +00:00
|
|
|
{
|
2011-01-22 14:52:07 +00:00
|
|
|
rate_ctr_inc(&link->ctrg->ctr[MTP_LNK_OUT]);
|
2011-01-21 19:54:55 +00:00
|
|
|
rate_ctr_inc(&link->set->ctrg->ctr[MTP_LSET_TOTA_OUT_MSG]);
|
|
|
|
link->write(link, msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-20 15:30:24 +00:00
|
|
|
struct msgb *mtp_msg_alloc(struct mtp_link_set *link)
|
2010-07-27 19:32:52 +00:00
|
|
|
{
|
|
|
|
struct mtp_level_3_hdr *hdr;
|
|
|
|
struct msgb *msg = msgb_alloc_headroom(4096, 128, "mtp-msg");
|
|
|
|
if (!msg) {
|
|
|
|
LOGP(DINP, LOGL_ERROR, "Failed to allocate mtp msg\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
msg->l2h = msgb_put(msg, sizeof(*hdr));
|
|
|
|
hdr = (struct mtp_level_3_hdr *) msg->l2h;
|
|
|
|
hdr->addr = MTP_ADDR(0x0, link->dpc, link->opc);
|
2010-11-26 20:05:39 +00:00
|
|
|
hdr->ni = link->ni;
|
2010-11-26 20:07:11 +00:00
|
|
|
hdr->spare = link->spare;
|
2010-07-27 19:32:52 +00:00
|
|
|
return msg;
|
|
|
|
}
|
|
|
|
|
2011-01-20 18:28:15 +00:00
|
|
|
static struct msgb *mtp_create_slta(struct mtp_link_set *link, int sls,
|
|
|
|
struct mtp_level_3_mng *in_mng, int l3_len)
|
2010-07-27 19:32:52 +00:00
|
|
|
{
|
|
|
|
struct mtp_level_3_hdr *hdr;
|
|
|
|
struct mtp_level_3_mng *mng;
|
|
|
|
struct msgb *out = mtp_msg_alloc(link);
|
|
|
|
|
|
|
|
if (!out)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
hdr = (struct mtp_level_3_hdr *) out->l2h;
|
|
|
|
hdr->ser_ind = MTP_SI_MNT_REG_MSG;
|
2011-01-20 18:28:15 +00:00
|
|
|
hdr->addr = MTP_ADDR(sls, link->dpc, link->opc);
|
|
|
|
|
2010-07-27 19:32:52 +00:00
|
|
|
mng = (struct mtp_level_3_mng *) msgb_put(out, sizeof(*mng));
|
|
|
|
mng->cmn.h0 = MTP_TST_MSG_GRP;
|
|
|
|
mng->cmn.h1 = MTP_TST_MSG_SLTA;
|
|
|
|
mng->length = l3_len - 2;
|
|
|
|
msgb_put(out, mng->length);
|
|
|
|
memcpy(mng->data, in_mng->data, mng->length);
|
|
|
|
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2011-01-20 15:30:24 +00:00
|
|
|
|
2011-01-25 12:35:10 +00:00
|
|
|
static struct msgb *mtp_base_alloc(struct mtp_link *link, int msg, int apoc)
|
2010-07-27 19:32:52 +00:00
|
|
|
{
|
|
|
|
struct mtp_level_3_hdr *hdr;
|
|
|
|
struct mtp_level_3_prohib *prb;
|
2011-01-25 12:35:10 +00:00
|
|
|
struct msgb *out = mtp_msg_alloc(link->set);
|
2010-07-27 19:32:52 +00:00
|
|
|
|
|
|
|
if (!out)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
hdr = (struct mtp_level_3_hdr *) out->l2h;
|
|
|
|
hdr->ser_ind = MTP_SI_MNT_SNM_MSG;
|
2011-01-25 12:35:10 +00:00
|
|
|
hdr->addr = MTP_ADDR(link->first_sls, link->set->dpc, link->set->opc);
|
2010-07-27 19:32:52 +00:00
|
|
|
prb = (struct mtp_level_3_prohib *) msgb_put(out, sizeof(*prb));
|
|
|
|
prb->cmn.h0 = MTP_PROHIBIT_MSG_GRP;
|
2011-01-18 19:35:11 +00:00
|
|
|
prb->cmn.h1 = msg;
|
2010-07-27 19:32:52 +00:00
|
|
|
prb->apoc = MTP_MAKE_APOC(apoc);
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2011-01-25 12:29:56 +00:00
|
|
|
static struct msgb *mtp_tfp_alloc(struct mtp_link *link, int apoc)
|
2011-01-18 19:35:11 +00:00
|
|
|
{
|
2011-01-25 12:35:10 +00:00
|
|
|
return mtp_base_alloc(link, MTP_PROHIBIT_MSG_SIG, apoc);
|
2011-01-18 19:35:11 +00:00
|
|
|
}
|
|
|
|
|
2011-01-25 12:29:56 +00:00
|
|
|
static struct msgb *mtp_tfa_alloc(struct mtp_link *link, int apoc)
|
2011-01-18 19:35:11 +00:00
|
|
|
{
|
2011-01-25 12:35:10 +00:00
|
|
|
return mtp_base_alloc(link, MTP_PROHIBIT_MSG_TFA, apoc);
|
2011-01-18 19:35:11 +00:00
|
|
|
}
|
|
|
|
|
2011-01-25 12:29:56 +00:00
|
|
|
static struct msgb *mtp_tra_alloc(struct mtp_link *link, int opc)
|
2010-07-27 19:32:52 +00:00
|
|
|
{
|
|
|
|
struct mtp_level_3_hdr *hdr;
|
|
|
|
struct mtp_level_3_cmn *cmn;
|
2011-01-25 12:29:56 +00:00
|
|
|
struct msgb *out = mtp_msg_alloc(link->set);
|
2010-07-27 19:32:52 +00:00
|
|
|
|
|
|
|
if (!out)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
hdr = (struct mtp_level_3_hdr *) out->l2h;
|
|
|
|
hdr->ser_ind = MTP_SI_MNT_SNM_MSG;
|
2011-01-25 12:29:56 +00:00
|
|
|
hdr->addr = MTP_ADDR(0x0, link->set->dpc, opc);
|
2010-07-27 19:32:52 +00:00
|
|
|
cmn = (struct mtp_level_3_cmn *) msgb_put(out, sizeof(*cmn));
|
|
|
|
cmn->h0 = MTP_TRF_RESTR_MSG_GRP;
|
|
|
|
cmn->h1 = MTP_RESTR_MSG_ALLWED;
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2011-01-02 17:47:49 +00:00
|
|
|
static struct msgb *mtp_sccp_alloc_scmg(struct mtp_link_set *link,
|
2011-01-19 09:51:44 +00:00
|
|
|
int type, int assn, int apoc, int sls)
|
2010-07-27 19:32:52 +00:00
|
|
|
{
|
|
|
|
struct sccp_data_unitdata *udt;
|
|
|
|
struct sccp_con_ctrl_prt_mgt *prt;
|
|
|
|
struct mtp_level_3_hdr *hdr;
|
2010-07-30 20:37:26 +00:00
|
|
|
uint8_t *data;
|
2010-07-27 19:32:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
struct msgb *out = mtp_msg_alloc(link);
|
|
|
|
|
|
|
|
if (!out)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
hdr = (struct mtp_level_3_hdr *) out->l2h;
|
|
|
|
hdr->ser_ind = MTP_SI_MNT_SCCP;
|
|
|
|
|
|
|
|
/* this appears to be round robin or such.. */
|
2011-01-01 12:34:58 +00:00
|
|
|
hdr->addr = MTP_ADDR(sls % 16, link->dpc, link->sccp_opc);
|
2010-07-27 19:32:52 +00:00
|
|
|
|
|
|
|
/* generate the UDT message... libsccp does not offer formating yet */
|
|
|
|
udt = (struct sccp_data_unitdata *) msgb_put(out, sizeof(*udt));
|
|
|
|
udt->type = SCCP_MSG_TYPE_UDT;
|
|
|
|
udt->proto_class = SCCP_PROTOCOL_CLASS_0;
|
|
|
|
udt->variable_called = 3;
|
|
|
|
udt->variable_calling = 5;
|
|
|
|
udt->variable_data = 7;
|
|
|
|
|
|
|
|
/* put the called and calling address. It is LV */
|
|
|
|
data = msgb_put(out, 2 + 1);
|
|
|
|
data[0] = 2;
|
|
|
|
data[1] = 0x42;
|
|
|
|
data[2] = 0x1;
|
|
|
|
|
|
|
|
data = msgb_put(out, 2 + 1);
|
|
|
|
data[0] = 2;
|
|
|
|
data[1] = 0x42;
|
|
|
|
data[2] = 0x1;
|
|
|
|
|
|
|
|
data = msgb_put(out, 1);
|
|
|
|
data[0] = sizeof(*prt);
|
|
|
|
|
|
|
|
prt = (struct sccp_con_ctrl_prt_mgt *) msgb_put(out, sizeof(*prt));
|
2010-12-31 12:40:19 +00:00
|
|
|
prt->sst = type;
|
|
|
|
prt->assn = assn;
|
2011-01-19 09:51:44 +00:00
|
|
|
prt->apoc = apoc;
|
2010-07-27 19:32:52 +00:00
|
|
|
prt->mul_ind = 0;
|
|
|
|
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2011-01-02 17:47:49 +00:00
|
|
|
void mtp_link_set_init(void)
|
2010-07-27 19:32:52 +00:00
|
|
|
{
|
|
|
|
tall_mtp_ctx = talloc_named_const(NULL, 1, "mtp-link");
|
|
|
|
}
|
|
|
|
|
2011-01-02 17:47:49 +00:00
|
|
|
struct mtp_link_set *mtp_link_set_alloc(void)
|
2010-07-27 19:32:52 +00:00
|
|
|
{
|
2011-01-21 19:54:55 +00:00
|
|
|
static int linkset_no = 0;
|
2011-01-02 17:47:49 +00:00
|
|
|
struct mtp_link_set *link;
|
2010-07-27 19:32:52 +00:00
|
|
|
|
2011-01-02 17:47:49 +00:00
|
|
|
link = talloc_zero(tall_mtp_ctx, struct mtp_link_set);
|
2010-07-27 19:32:52 +00:00
|
|
|
if (!link)
|
|
|
|
return NULL;
|
|
|
|
|
2011-01-21 19:54:55 +00:00
|
|
|
link->ctrg = rate_ctr_group_alloc(link,
|
|
|
|
mtp_link_set_rate_ctr_desc(),
|
|
|
|
linkset_no++);
|
|
|
|
if (!link->ctrg) {
|
|
|
|
LOGP(DINP, LOGL_ERROR, "Failed to allocate counter.\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-26 20:05:39 +00:00
|
|
|
link->ni = MTP_NI_NATION_NET;
|
2011-01-04 12:21:52 +00:00
|
|
|
INIT_LLIST_HEAD(&link->links);
|
|
|
|
|
2010-07-27 19:32:52 +00:00
|
|
|
return link;
|
|
|
|
}
|
|
|
|
|
2011-01-02 17:47:49 +00:00
|
|
|
void mtp_link_set_stop(struct mtp_link_set *link)
|
2010-07-27 19:32:52 +00:00
|
|
|
{
|
2011-01-20 15:30:24 +00:00
|
|
|
struct mtp_link *lnk;
|
|
|
|
llist_for_each_entry(lnk, &link->links, entry)
|
|
|
|
mtp_link_stop_link_test(lnk);
|
|
|
|
|
2010-07-27 19:32:52 +00:00
|
|
|
link->sccp_up = 0;
|
|
|
|
link->running = 0;
|
2011-01-20 13:23:10 +00:00
|
|
|
link->linkset_up = 0;
|
2010-07-27 19:32:52 +00:00
|
|
|
}
|
|
|
|
|
2011-01-02 17:47:49 +00:00
|
|
|
void mtp_link_set_reset(struct mtp_link_set *link)
|
2010-07-27 19:32:52 +00:00
|
|
|
{
|
2011-01-20 15:30:24 +00:00
|
|
|
struct mtp_link *lnk;
|
2011-01-02 17:47:49 +00:00
|
|
|
mtp_link_set_stop(link);
|
2010-07-27 19:32:52 +00:00
|
|
|
link->running = 1;
|
2011-01-20 15:30:24 +00:00
|
|
|
|
|
|
|
llist_for_each_entry(lnk, &link->links, entry)
|
|
|
|
mtp_link_start_link_test(lnk);
|
2010-07-27 19:32:52 +00:00
|
|
|
}
|
|
|
|
|
2011-01-25 12:29:56 +00:00
|
|
|
static int send_tfp(struct mtp_link *link, int apoc)
|
2011-01-18 17:52:34 +00:00
|
|
|
{
|
|
|
|
struct msgb *msg;
|
|
|
|
msg = mtp_tfp_alloc(link, apoc);
|
|
|
|
if (!msg)
|
|
|
|
return -1;
|
|
|
|
|
2011-01-25 12:29:56 +00:00
|
|
|
mtp_link_submit(link, msg);
|
2011-01-18 17:52:34 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-01-25 12:29:56 +00:00
|
|
|
static int send_tra(struct mtp_link *link, int opc)
|
2010-07-27 19:32:52 +00:00
|
|
|
{
|
|
|
|
struct msgb *msg;
|
2011-01-18 18:01:43 +00:00
|
|
|
msg = mtp_tra_alloc(link, opc);
|
|
|
|
if (!msg)
|
|
|
|
return -1;
|
2011-01-25 12:29:56 +00:00
|
|
|
mtp_link_submit(link, msg);
|
2011-01-18 18:01:43 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-01-25 12:29:56 +00:00
|
|
|
static int send_tfa(struct mtp_link *link, int opc)
|
2011-01-18 19:35:11 +00:00
|
|
|
{
|
|
|
|
struct msgb *msg;
|
|
|
|
msg = mtp_tfa_alloc(link, opc);
|
|
|
|
if (!msg)
|
|
|
|
return -1;
|
2011-01-25 12:29:56 +00:00
|
|
|
mtp_link_submit(link, msg);
|
2011-01-18 19:35:11 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-01-25 12:29:56 +00:00
|
|
|
static int linkset_up(struct mtp_link *link)
|
2011-01-20 13:23:10 +00:00
|
|
|
{
|
2011-01-25 12:29:56 +00:00
|
|
|
struct mtp_link_set *set = link->set;
|
|
|
|
|
2011-01-20 13:23:10 +00:00
|
|
|
/* the link set is already up */
|
|
|
|
if (set->linkset_up)
|
|
|
|
return 0;
|
|
|
|
|
2011-01-25 12:29:56 +00:00
|
|
|
if (send_tfp(link, 0) != 0)
|
2011-01-20 13:23:10 +00:00
|
|
|
return -1;
|
2011-01-25 12:29:56 +00:00
|
|
|
if (send_tfp(link, set->opc) != 0)
|
2011-01-20 13:23:10 +00:00
|
|
|
return -1;
|
|
|
|
if (set->sccp_opc != set->opc &&
|
2011-01-25 12:29:56 +00:00
|
|
|
send_tfp(link, set->sccp_opc) != 0)
|
2011-01-20 13:23:10 +00:00
|
|
|
return -1;
|
|
|
|
if (set->isup_opc != set->opc &&
|
2011-01-25 12:29:56 +00:00
|
|
|
send_tfp(link, set->isup_opc) != 0)
|
2011-01-20 13:23:10 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* Send the TRA for all PCs */
|
2011-01-25 12:29:56 +00:00
|
|
|
if (send_tra(link, set->opc) != 0)
|
2011-01-20 13:23:10 +00:00
|
|
|
return -1;
|
|
|
|
if (set->sccp_opc != set->opc &&
|
2011-01-25 12:29:56 +00:00
|
|
|
send_tfa(link, set->sccp_opc) != 0)
|
2011-01-20 13:23:10 +00:00
|
|
|
return -1;
|
|
|
|
if (set->isup_opc != set->opc &&
|
2011-01-25 12:29:56 +00:00
|
|
|
send_tfa(link, set->isup_opc) != 0)
|
2011-01-20 13:23:10 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
set->linkset_up = 1;
|
|
|
|
LOGP(DINP, LOGL_NOTICE,
|
2011-01-26 11:41:42 +00:00
|
|
|
"The linkset %s is considered running.\n", set->name);
|
2011-01-20 13:23:10 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-01-18 18:01:43 +00:00
|
|
|
static int mtp_link_sign_msg(struct mtp_link_set *link, struct mtp_level_3_hdr *hdr, int l3_len)
|
|
|
|
{
|
2010-07-27 19:32:52 +00:00
|
|
|
struct mtp_level_3_cmn *cmn;
|
2010-12-08 10:28:12 +00:00
|
|
|
uint16_t *apc;
|
2010-07-27 19:32:52 +00:00
|
|
|
|
2010-11-26 20:05:39 +00:00
|
|
|
if (hdr->ni != link->ni || l3_len < 1) {
|
2010-10-08 09:49:24 +00:00
|
|
|
LOGP(DINP, LOGL_ERROR, "Unhandled data (ni: %d len: %d)\n",
|
|
|
|
hdr->ni, l3_len);
|
2010-07-27 19:32:52 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
cmn = (struct mtp_level_3_cmn *) &hdr->data[0];
|
|
|
|
LOGP(DINP, LOGL_DEBUG, "reg msg: h0: 0x%x h1: 0x%x\n",
|
|
|
|
cmn->h0, cmn->h1);
|
|
|
|
|
|
|
|
switch (cmn->h0) {
|
|
|
|
case MTP_TRF_RESTR_MSG_GRP:
|
|
|
|
switch (cmn->h1) {
|
|
|
|
case MTP_RESTR_MSG_ALLWED:
|
2011-01-26 11:41:42 +00:00
|
|
|
LOGP(DINP, LOGL_INFO, "Received Restart Allowed. SST could be next: %s\n", link->name);
|
2010-12-10 11:27:00 +00:00
|
|
|
link->sccp_up = 1;
|
2011-01-26 11:41:42 +00:00
|
|
|
LOGP(DINP, LOGL_INFO, "SCCP traffic allowed. %s\n", link->name);
|
2010-07-27 19:32:52 +00:00
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2010-12-08 10:28:12 +00:00
|
|
|
case MTP_PROHIBIT_MSG_GRP:
|
|
|
|
switch (cmn->h1) {
|
|
|
|
case MTP_PROHIBIT_MSG_SIG:
|
|
|
|
if (l3_len < 3) {
|
|
|
|
LOGP(DINP, LOGL_ERROR, "TFP is too short.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
apc = (uint16_t *) &hdr->data[1];
|
|
|
|
LOGP(DINP, LOGL_INFO,
|
|
|
|
"TFP for the affected point code: %d\n", *apc);
|
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2010-07-27 19:32:52 +00:00
|
|
|
}
|
|
|
|
|
2010-12-08 10:10:34 +00:00
|
|
|
LOGP(DINP, LOGL_ERROR, "Unknown message:%d/%d %s\n", cmn->h0, cmn->h1, hexdump(&hdr->data[0], l3_len));
|
2010-07-27 19:32:52 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-01-20 15:30:24 +00:00
|
|
|
static int mtp_link_regular_msg(struct mtp_link *link, struct mtp_level_3_hdr *hdr, int l3_len)
|
2010-07-27 19:32:52 +00:00
|
|
|
{
|
|
|
|
struct msgb *out;
|
|
|
|
struct mtp_level_3_mng *mng;
|
|
|
|
|
2011-01-20 15:30:24 +00:00
|
|
|
if (hdr->ni != link->set->ni || l3_len < 1) {
|
2010-10-08 09:49:24 +00:00
|
|
|
LOGP(DINP, LOGL_ERROR, "Unhandled data (ni: %d len: %d)\n",
|
|
|
|
hdr->ni, l3_len);
|
2010-07-27 19:32:52 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-01-20 15:30:24 +00:00
|
|
|
if (MTP_ADDR_DPC(hdr->addr) != link->set->opc) {
|
2011-01-20 12:05:54 +00:00
|
|
|
LOGP(DINP, LOGL_ERROR, "MSG for 0x%x not handled by 0x%x\n",
|
2011-01-20 15:30:24 +00:00
|
|
|
MTP_ADDR_DPC(hdr->addr), link->set->opc);
|
2011-01-20 12:05:54 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-07-27 19:32:52 +00:00
|
|
|
mng = (struct mtp_level_3_mng *) &hdr->data[0];
|
|
|
|
LOGP(DINP, LOGL_DEBUG, "reg msg: h0: 0x%x h1: 0x%x\n",
|
|
|
|
mng->cmn.h0, mng->cmn.h1);
|
|
|
|
|
|
|
|
switch (mng->cmn.h0) {
|
|
|
|
case MTP_TST_MSG_GRP:
|
|
|
|
switch (mng->cmn.h1) {
|
|
|
|
case MTP_TST_MSG_SLTM:
|
|
|
|
/* simply respond to the request... */
|
2011-01-20 18:28:15 +00:00
|
|
|
out = mtp_create_slta(link->set,
|
|
|
|
MTP_LINK_SLS(hdr->addr),
|
|
|
|
mng, l3_len);
|
2010-07-27 19:32:52 +00:00
|
|
|
if (!out)
|
|
|
|
return -1;
|
2011-01-24 19:49:58 +00:00
|
|
|
mtp_link_submit(link, out);
|
2010-07-27 19:32:52 +00:00
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
case MTP_TST_MSG_SLTA:
|
2011-01-20 15:30:24 +00:00
|
|
|
/* If this link is proven set it up */
|
|
|
|
if (mtp_link_slta(link, l3_len, mng) == 0)
|
2011-01-25 12:29:56 +00:00
|
|
|
linkset_up(link);
|
2010-07-27 19:32:52 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-01-02 17:47:49 +00:00
|
|
|
static int mtp_link_sccp_data(struct mtp_link_set *link, struct mtp_level_3_hdr *hdr, struct msgb *msg, int l3_len)
|
2010-07-27 19:32:52 +00:00
|
|
|
{
|
|
|
|
struct msgb *out;
|
|
|
|
struct sccp_con_ctrl_prt_mgt *prt;
|
2010-12-10 11:27:00 +00:00
|
|
|
struct sccp_parse_result sccp;
|
2010-12-31 12:40:19 +00:00
|
|
|
int type;
|
2010-07-27 19:32:52 +00:00
|
|
|
|
|
|
|
msg->l2h = &hdr->data[0];
|
|
|
|
if (msgb_l2len(msg) != l3_len) {
|
|
|
|
LOGP(DINP, LOGL_ERROR, "Size is wrong after playing with the l2h header.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-12-10 11:27:00 +00:00
|
|
|
if (!link->sccp_up) {
|
|
|
|
LOGP(DINP, LOGL_ERROR, "SCCP traffic is not allowed.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2010-07-27 19:32:52 +00:00
|
|
|
|
2010-12-10 11:27:00 +00:00
|
|
|
memset(&sccp, 0, sizeof(sccp));
|
|
|
|
if (sccp_parse_header(msg, &sccp) != 0) {
|
|
|
|
LOGP(DINP, LOGL_ERROR, "Failed to parsed SCCP header.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2010-07-27 19:32:52 +00:00
|
|
|
|
2010-12-10 11:27:00 +00:00
|
|
|
/* check if it is a SST */
|
|
|
|
if (sccp_determine_msg_type(msg) == SCCP_MSG_TYPE_UDT
|
|
|
|
&& msg->l3h[0] == SCCP_SST) {
|
2010-07-27 19:32:52 +00:00
|
|
|
if (msgb_l3len(msg) != 5) {
|
2010-12-10 11:27:00 +00:00
|
|
|
LOGP(DINP, LOGL_ERROR,
|
|
|
|
"SCCP UDT msg of unexpected size: %u\n",
|
2010-07-27 19:32:52 +00:00
|
|
|
msgb_l3len(msg));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
prt = (struct sccp_con_ctrl_prt_mgt *) &msg->l3h[0];
|
2011-01-01 12:34:58 +00:00
|
|
|
if (prt->apoc != MTP_MAKE_APOC(link->sccp_opc)) {
|
2010-12-31 15:53:40 +00:00
|
|
|
LOGP(DINP, LOGL_ERROR, "Unknown APOC: %u/%u\n",
|
|
|
|
ntohs(prt->apoc), prt->apoc);
|
|
|
|
type = SCCP_SSP;
|
|
|
|
} else if (prt->assn != 1 && prt->assn != 254 &&
|
|
|
|
prt->assn != 7 && prt->assn != 8 && prt->assn != 146) {
|
|
|
|
LOGP(DINP, LOGL_ERROR, "Unknown affected SSN assn: %u\n",
|
|
|
|
prt->assn);
|
2010-12-31 12:40:19 +00:00
|
|
|
type = SCCP_SSP;
|
|
|
|
} else {
|
|
|
|
type = SCCP_SSA;
|
2010-07-27 19:32:52 +00:00
|
|
|
}
|
|
|
|
|
2011-01-19 09:51:44 +00:00
|
|
|
out = mtp_sccp_alloc_scmg(link, type, prt->assn, prt->apoc,
|
2010-12-31 12:40:19 +00:00
|
|
|
MTP_LINK_SLS(hdr->addr));
|
2010-07-27 19:32:52 +00:00
|
|
|
if (!out)
|
|
|
|
return -1;
|
|
|
|
|
2011-01-24 19:49:58 +00:00
|
|
|
mtp_link_submit(link->slc[MTP_LINK_SLS(hdr->addr)], out);
|
2010-12-10 11:27:00 +00:00
|
|
|
return 0;
|
2010-07-27 19:32:52 +00:00
|
|
|
}
|
2010-12-10 11:27:00 +00:00
|
|
|
|
2011-01-21 19:54:55 +00:00
|
|
|
rate_ctr_inc(&link->ctrg->ctr[MTP_LSET_SCCP_IN_MSG]);
|
2011-01-02 17:47:49 +00:00
|
|
|
mtp_link_set_forward_sccp(link, msg, MTP_LINK_SLS(hdr->addr));
|
2010-07-27 19:32:52 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-01-18 12:29:42 +00:00
|
|
|
int mtp_link_set_data(struct mtp_link *link, struct msgb *msg)
|
2010-07-27 19:32:52 +00:00
|
|
|
{
|
|
|
|
int rc = -1;
|
|
|
|
struct mtp_level_3_hdr *hdr;
|
|
|
|
int l3_len;
|
|
|
|
|
|
|
|
if (!msg->l2h || msgb_l2len(msg) < sizeof(*hdr))
|
|
|
|
return -1;
|
|
|
|
|
2011-01-20 14:42:13 +00:00
|
|
|
if (!link->set->running) {
|
2011-01-26 11:41:42 +00:00
|
|
|
LOGP(DINP, LOGL_ERROR, "Link is not running. Call mtp_link_reset first: %s/%d\n",
|
|
|
|
link->set->name, link->link_no);
|
2010-07-27 19:32:52 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
hdr = (struct mtp_level_3_hdr *) msg->l2h;
|
|
|
|
l3_len = msgb_l2len(msg) - sizeof(*hdr);
|
|
|
|
|
2011-01-24 19:52:30 +00:00
|
|
|
rate_ctr_inc(&link->ctrg->ctr[MTP_LNK_IN]);
|
2011-01-21 19:54:55 +00:00
|
|
|
rate_ctr_inc(&link->set->ctrg->ctr[MTP_LSET_TOTA_IN_MSG]);
|
|
|
|
|
2010-07-27 19:32:52 +00:00
|
|
|
switch (hdr->ser_ind) {
|
|
|
|
case MTP_SI_MNT_SNM_MSG:
|
2011-01-20 14:42:13 +00:00
|
|
|
rc = mtp_link_sign_msg(link->set, hdr, l3_len);
|
2010-07-27 19:32:52 +00:00
|
|
|
break;
|
|
|
|
case MTP_SI_MNT_REG_MSG:
|
2011-01-20 15:30:24 +00:00
|
|
|
rc = mtp_link_regular_msg(link, hdr, l3_len);
|
2010-07-27 19:32:52 +00:00
|
|
|
break;
|
|
|
|
case MTP_SI_MNT_SCCP:
|
2011-01-20 14:42:13 +00:00
|
|
|
rc = mtp_link_sccp_data(link->set, hdr, msg, l3_len);
|
2010-07-27 19:32:52 +00:00
|
|
|
break;
|
2010-12-08 10:12:46 +00:00
|
|
|
case MTP_SI_MNT_ISUP:
|
2010-12-10 06:34:01 +00:00
|
|
|
msg->l3h = &hdr->data[0];
|
2011-01-21 19:54:55 +00:00
|
|
|
rate_ctr_inc(&link->set->ctrg->ctr[MTP_LSET_IUSP_IN_MSG]);
|
2011-01-20 14:42:13 +00:00
|
|
|
rc = mtp_link_set_isup(link->set, msg, MTP_LINK_SLS(hdr->addr));
|
2010-12-08 10:12:46 +00:00
|
|
|
break;
|
2010-07-27 19:32:52 +00:00
|
|
|
default:
|
|
|
|
fprintf(stderr, "Unhandled: %u\n", hdr->ser_ind);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2011-01-02 17:47:49 +00:00
|
|
|
int mtp_link_set_submit_sccp_data(struct mtp_link_set *link, int sls, const uint8_t *data, unsigned int length)
|
2010-07-27 19:32:52 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
if (!link->sccp_up) {
|
|
|
|
LOGP(DINP, LOGL_ERROR, "SCCP msg after TRA and before SSA. Dropping it.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-01-02 17:11:37 +00:00
|
|
|
if (sls == -1) {
|
|
|
|
sls = link->last_sls;
|
|
|
|
link->last_sls = (link->last_sls + 1) % 16;
|
|
|
|
}
|
|
|
|
|
2011-01-21 19:54:55 +00:00
|
|
|
rate_ctr_inc(&link->ctrg->ctr[MTP_LSET_SCCP_OUT_MSG]);
|
2011-01-01 12:34:58 +00:00
|
|
|
return mtp_int_submit(link, link->sccp_opc, sls, MTP_SI_MNT_SCCP, data, length);
|
2010-12-10 11:18:57 +00:00
|
|
|
}
|
|
|
|
|
2011-01-02 17:47:49 +00:00
|
|
|
int mtp_link_set_submit_isup_data(struct mtp_link_set *link, int sls,
|
2010-12-10 11:18:57 +00:00
|
|
|
const uint8_t *data, unsigned int length)
|
|
|
|
{
|
2011-01-21 19:54:55 +00:00
|
|
|
rate_ctr_inc(&link->ctrg->ctr[MTP_LSET_ISUP_OUT_MSG]);
|
2011-01-17 21:37:11 +00:00
|
|
|
return mtp_int_submit(link, link->isup_opc, sls, MTP_SI_MNT_ISUP, data, length);
|
2010-12-10 11:18:57 +00:00
|
|
|
}
|
|
|
|
|
2011-01-02 17:47:49 +00:00
|
|
|
static int mtp_int_submit(struct mtp_link_set *link, int pc, int sls, int type,
|
2010-12-10 11:18:57 +00:00
|
|
|
const uint8_t *data, unsigned int length)
|
|
|
|
{
|
|
|
|
uint8_t *put_ptr;
|
|
|
|
struct mtp_level_3_hdr *hdr;
|
|
|
|
struct msgb *msg;
|
|
|
|
|
2011-01-17 19:12:32 +00:00
|
|
|
if (!link->slc[sls % 16])
|
|
|
|
return -1;
|
|
|
|
|
2010-07-27 19:32:52 +00:00
|
|
|
msg = mtp_msg_alloc(link);
|
|
|
|
if (!msg)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
hdr = (struct mtp_level_3_hdr *) msg->l2h;
|
2010-12-10 11:18:57 +00:00
|
|
|
hdr->ser_ind = type;
|
2010-07-27 19:32:52 +00:00
|
|
|
|
2011-01-01 12:34:58 +00:00
|
|
|
hdr->addr = MTP_ADDR(sls % 16, link->dpc, pc);
|
2010-07-27 19:32:52 +00:00
|
|
|
|
|
|
|
/* copy the raw sccp data */
|
|
|
|
put_ptr = msgb_put(msg, length);
|
|
|
|
memcpy(put_ptr, data, length);
|
|
|
|
|
2011-01-24 19:49:58 +00:00
|
|
|
mtp_link_submit(link->slc[sls % 16], msg);
|
2010-07-27 19:32:52 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2011-01-04 12:01:23 +00:00
|
|
|
|
2011-01-17 10:54:39 +00:00
|
|
|
static struct mtp_link *find_next_link(struct mtp_link_set *set,
|
|
|
|
struct mtp_link *data)
|
2011-01-16 10:56:05 +00:00
|
|
|
{
|
|
|
|
int found = 0;
|
2011-01-17 10:54:39 +00:00
|
|
|
struct mtp_link *next;
|
2011-01-16 10:56:05 +00:00
|
|
|
|
|
|
|
if (llist_empty(&set->links))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (data == NULL)
|
|
|
|
found = 1;
|
|
|
|
|
|
|
|
/* try to find the next one */
|
|
|
|
llist_for_each_entry(next, &set->links, entry) {
|
|
|
|
if (found && next->available)
|
|
|
|
return next;
|
|
|
|
if (next == data)
|
|
|
|
found = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* try to find any one */
|
|
|
|
llist_for_each_entry(next, &set->links, entry)
|
|
|
|
if (next->available)
|
|
|
|
return next;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-01-04 12:01:23 +00:00
|
|
|
void mtp_link_set_init_slc(struct mtp_link_set *set)
|
|
|
|
{
|
2011-01-25 12:24:06 +00:00
|
|
|
struct mtp_link *link = NULL, *tmp;
|
2011-01-04 12:01:23 +00:00
|
|
|
int i;
|
2011-01-16 10:56:05 +00:00
|
|
|
|
2011-01-25 12:24:06 +00:00
|
|
|
llist_for_each_entry(tmp, &set->links, entry)
|
|
|
|
tmp->first_sls = 100;
|
|
|
|
|
2011-01-16 10:56:05 +00:00
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(set->slc); ++i) {
|
|
|
|
link = find_next_link(set, link);
|
|
|
|
set->slc[i] = link;
|
2011-01-25 12:24:06 +00:00
|
|
|
|
|
|
|
if (link && i < link->first_sls)
|
|
|
|
link->first_sls = i;
|
2011-01-16 10:56:05 +00:00
|
|
|
}
|
2011-01-04 12:21:52 +00:00
|
|
|
}
|
|
|
|
|
2011-01-22 14:52:07 +00:00
|
|
|
int mtp_link_set_add_link(struct mtp_link_set *set, struct mtp_link *lnk)
|
2011-01-04 12:21:52 +00:00
|
|
|
{
|
2011-01-20 14:42:13 +00:00
|
|
|
lnk->set = set;
|
2011-01-20 17:26:18 +00:00
|
|
|
lnk->link_no = set->nr_links++;
|
2011-01-22 14:52:07 +00:00
|
|
|
if (mtp_link_init(lnk) != 0)
|
|
|
|
return -1;
|
2011-01-20 15:30:24 +00:00
|
|
|
|
|
|
|
llist_add_tail(&lnk->entry, &set->links);
|
2011-01-04 12:21:52 +00:00
|
|
|
mtp_link_set_init_slc(set);
|
2011-01-22 14:52:07 +00:00
|
|
|
return 0;
|
2011-01-04 12:01:23 +00:00
|
|
|
}
|