2010-12-10 02:53:28 +00:00
|
|
|
/*
|
2011-01-17 15:13:28 +00:00
|
|
|
* (C) 2010-2011 by Holger Hans Peter Freyther <zecke@selfish.org>
|
|
|
|
* (C) 2010-2011 by On-Waves
|
2010-12-10 02:53:28 +00:00
|
|
|
* 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-12-10 02:53:28 +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-12-10 02:53:28 +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-12-10 02:53:28 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <isup_types.h>
|
|
|
|
#include <cellmgr_debug.h>
|
2010-12-10 11:18:57 +00:00
|
|
|
#include <mtp_data.h>
|
2010-12-10 02:53:28 +00:00
|
|
|
|
2011-05-08 08:29:23 +00:00
|
|
|
#include <osmocom/core/msgb.h>
|
|
|
|
#include <osmocom/gsm/tlv.h>
|
2010-12-10 11:18:57 +00:00
|
|
|
|
2011-01-19 08:27:41 +00:00
|
|
|
static struct msgb *isup_status_alloc(int cic, int msg_type, uint8_t *extra, int range, int val)
|
2010-12-10 11:18:57 +00:00
|
|
|
{
|
|
|
|
struct isup_msg_hdr *hdr;
|
|
|
|
struct msgb *msg;
|
|
|
|
int bits, len;
|
2011-01-19 08:27:41 +00:00
|
|
|
uint8_t *data;
|
2010-12-10 11:18:57 +00:00
|
|
|
|
2011-01-19 08:19:17 +00:00
|
|
|
msg = msgb_alloc_headroom(4096, 128, "ISUP Simple MSG");
|
2010-12-10 11:18:57 +00:00
|
|
|
if (!msg) {
|
2011-01-19 08:19:17 +00:00
|
|
|
LOGP(DISUP, LOGL_ERROR, "Allocation of status message failed.\n");
|
2010-12-10 11:18:57 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
msg->l2h = msgb_put(msg, sizeof(*hdr));
|
|
|
|
|
|
|
|
/* write the ISUP header */
|
|
|
|
hdr = (struct isup_msg_hdr *) msg->l2h;
|
|
|
|
hdr->cic = cic;
|
2011-01-19 08:19:17 +00:00
|
|
|
hdr->msg_type = msg_type;
|
2010-12-10 11:18:57 +00:00
|
|
|
|
2011-01-19 08:27:41 +00:00
|
|
|
if (extra)
|
|
|
|
msgb_v_put(msg, *extra);
|
|
|
|
|
2010-12-10 11:18:57 +00:00
|
|
|
/*
|
|
|
|
* place the pointers here.
|
|
|
|
* 1.) place the variable start after us
|
|
|
|
* 2.) place the length
|
|
|
|
*/
|
|
|
|
msgb_v_put(msg, 1);
|
|
|
|
|
|
|
|
bits = range + 1;
|
|
|
|
len = (bits / 8) + 1;
|
|
|
|
msgb_v_put(msg, len + 1);
|
|
|
|
msgb_v_put(msg, range);
|
|
|
|
|
2011-01-19 08:27:41 +00:00
|
|
|
data = msgb_put(msg, len);
|
|
|
|
|
|
|
|
/* set the status bits to val... FIXME this sets the extra bits too */
|
|
|
|
memset(data, val, len);
|
2010-12-10 11:18:57 +00:00
|
|
|
|
|
|
|
return msg;
|
|
|
|
}
|
2010-12-10 06:34:01 +00:00
|
|
|
|
2011-01-19 08:33:00 +00:00
|
|
|
static struct msgb *isup_simple_alloc(int cic, int msg_type)
|
2011-01-18 22:34:19 +00:00
|
|
|
{
|
|
|
|
struct isup_msg_hdr *hdr;
|
|
|
|
struct msgb *msg;
|
|
|
|
|
2011-01-19 08:33:00 +00:00
|
|
|
msg = msgb_alloc_headroom(4096, 128, "ISUP Simple MSG");
|
2011-01-18 22:34:19 +00:00
|
|
|
if (!msg) {
|
2011-01-19 08:33:00 +00:00
|
|
|
LOGP(DISUP, LOGL_ERROR, "Allocation of Simple message failed.\n");
|
2011-01-18 22:34:19 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
msg->l2h = msgb_put(msg, sizeof(*hdr));
|
|
|
|
|
|
|
|
/* write the ISUP header */
|
|
|
|
hdr = (struct isup_msg_hdr *) msg->l2h;
|
|
|
|
hdr->cic = cic;
|
2011-01-19 08:33:00 +00:00
|
|
|
hdr->msg_type = msg_type;
|
2011-01-18 22:34:19 +00:00
|
|
|
|
|
|
|
msgb_v_put(msg, 0);
|
|
|
|
return msg;
|
|
|
|
}
|
|
|
|
|
2010-12-10 02:53:28 +00:00
|
|
|
/* this message contains the range */
|
2011-01-19 08:19:17 +00:00
|
|
|
int isup_parse_status(const uint8_t *data, uint8_t in_length)
|
2010-12-10 02:53:28 +00:00
|
|
|
{
|
|
|
|
uint8_t ptr;
|
|
|
|
|
2011-01-19 08:43:01 +00:00
|
|
|
if (in_length < 3) {
|
2010-12-10 02:53:28 +00:00
|
|
|
LOGP(DISUP, LOGL_ERROR, "This needs three bytes.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ptr = data[0];
|
|
|
|
if (1 + ptr > in_length) {
|
|
|
|
LOGP(DISUP, LOGL_ERROR, "Pointing outside the packet.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (1 + ptr + 1 > in_length) {
|
|
|
|
LOGP(DISUP, LOGL_ERROR, "No space for the data.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return data[0 + ptr + 1];
|
|
|
|
}
|
|
|
|
|
2010-12-10 06:34:01 +00:00
|
|
|
|
|
|
|
/* Handle incoming ISUP data */
|
2011-02-23 15:58:15 +00:00
|
|
|
static int handle_circuit_reset_grs(struct mtp_link_set *set, int sls, int cic,
|
2010-12-10 06:34:01 +00:00
|
|
|
const uint8_t *data, int size)
|
|
|
|
{
|
2010-12-10 11:18:57 +00:00
|
|
|
struct msgb *resp;
|
2010-12-10 06:34:01 +00:00
|
|
|
int range;
|
|
|
|
|
2011-01-19 08:19:17 +00:00
|
|
|
range = isup_parse_status(data, size);
|
2010-12-10 06:34:01 +00:00
|
|
|
if (range < 0)
|
|
|
|
return -1;
|
|
|
|
|
2011-01-19 08:27:41 +00:00
|
|
|
resp = isup_status_alloc(cic, ISUP_MSG_GRA, NULL, range, 0);
|
|
|
|
if (!resp)
|
|
|
|
return -1;
|
|
|
|
|
2011-02-23 15:58:15 +00:00
|
|
|
mtp_link_set_submit_isup_data(set, sls, resp->l2h, msgb_l2len(resp));
|
2011-01-19 08:27:41 +00:00
|
|
|
msgb_free(resp);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-02-23 15:58:15 +00:00
|
|
|
static int handle_circuit_reset_cgb(struct mtp_link_set *set, int sls, int cic,
|
2011-01-19 08:27:41 +00:00
|
|
|
const uint8_t *data, int size)
|
|
|
|
{
|
|
|
|
struct msgb *resp;
|
|
|
|
int range;
|
|
|
|
uint8_t val;
|
|
|
|
|
|
|
|
if (size < 1)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
range = isup_parse_status(data + 1, size - 1);
|
|
|
|
if (range < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
val = 0;
|
|
|
|
resp = isup_status_alloc(cic, ISUP_MSG_CGBA, &val, range, 0xff);
|
2010-12-10 11:18:57 +00:00
|
|
|
if (!resp)
|
|
|
|
return -1;
|
2010-12-10 06:34:01 +00:00
|
|
|
|
2011-02-23 15:58:15 +00:00
|
|
|
mtp_link_set_submit_isup_data(set, sls, resp->l2h, msgb_l2len(resp));
|
2010-12-10 11:18:57 +00:00
|
|
|
msgb_free(resp);
|
2010-12-10 06:34:01 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-02-23 15:58:15 +00:00
|
|
|
static int send_cgu(struct mtp_link_set *set, int sls, int cic, int range)
|
2011-01-19 08:33:00 +00:00
|
|
|
{
|
|
|
|
struct msgb *resp;
|
|
|
|
uint8_t val;
|
|
|
|
|
|
|
|
val = 0;
|
|
|
|
resp = isup_status_alloc(cic, ISUP_MSG_CGU, &val, range, 0);
|
|
|
|
if (!resp)
|
|
|
|
return -1;
|
|
|
|
|
2011-02-23 15:58:15 +00:00
|
|
|
mtp_link_set_submit_isup_data(set, sls, resp->l2h, msgb_l2len(resp));
|
2011-01-19 08:33:00 +00:00
|
|
|
msgb_free(resp);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-03-05 08:50:47 +00:00
|
|
|
static int handle_cgu(struct mtp_link_set *set, int sls, int cic,
|
|
|
|
uint8_t *data, uint16_t size)
|
|
|
|
{
|
|
|
|
uint8_t *out;
|
|
|
|
struct isup_msg_hdr *hdr;
|
|
|
|
struct msgb *resp;
|
|
|
|
|
|
|
|
resp = msgb_alloc_headroom(4096, 128, "ISUP CGUA MSG");
|
|
|
|
if (!resp) {
|
|
|
|
LOGP(DISUP, LOGL_ERROR, "Allocation of CGUA message failed.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
resp->l2h = msgb_put(resp, sizeof(*hdr));
|
|
|
|
|
|
|
|
/* write the ISUP header */
|
|
|
|
hdr = (struct isup_msg_hdr *) resp->l2h;
|
|
|
|
hdr->cic = cic;
|
|
|
|
hdr->msg_type = ISUP_MSG_CGUA;
|
|
|
|
|
|
|
|
out = msgb_put(resp, size);
|
|
|
|
memcpy(out, data, size);
|
|
|
|
|
|
|
|
mtp_link_set_submit_isup_data(set, sls, resp->l2h, msgb_l2len(resp));
|
|
|
|
msgb_free(resp);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-01-19 08:33:00 +00:00
|
|
|
static int handle_simple_resp(struct mtp_link_set *set, int sls, int cic, int msg_type)
|
2011-01-18 22:34:19 +00:00
|
|
|
{
|
|
|
|
struct msgb *resp;
|
|
|
|
|
2011-01-19 08:33:00 +00:00
|
|
|
resp = isup_simple_alloc(cic, msg_type);
|
2011-01-18 22:34:19 +00:00
|
|
|
if (!resp)
|
|
|
|
return -1;
|
|
|
|
mtp_link_set_submit_isup_data(set, sls, resp->l2h, msgb_l2len(resp));
|
|
|
|
msgb_free(resp);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-02-23 15:58:15 +00:00
|
|
|
int mtp_link_set_isup(struct mtp_link_set *set, struct msgb *msg, int sls)
|
2010-12-10 06:34:01 +00:00
|
|
|
{
|
|
|
|
int rc = -1;
|
|
|
|
int payload_size;
|
|
|
|
struct isup_msg_hdr *hdr;
|
|
|
|
|
|
|
|
if (msgb_l3len(msg) < sizeof(*hdr)) {
|
|
|
|
LOGP(DISUP, LOGL_ERROR, "ISUP header is too short.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-02-23 15:58:15 +00:00
|
|
|
if (set->pass_all_isup) {
|
|
|
|
mtp_link_set_forward_isup(set, msg, sls);
|
2011-01-17 19:21:45 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-12-10 06:34:01 +00:00
|
|
|
hdr = (struct isup_msg_hdr *) msg->l3h;
|
|
|
|
payload_size = msgb_l3len(msg) - sizeof(*hdr);
|
|
|
|
|
|
|
|
switch (hdr->msg_type) {
|
|
|
|
case ISUP_MSG_GRS:
|
2011-02-23 15:58:15 +00:00
|
|
|
rc = handle_circuit_reset_grs(set, sls, hdr->cic, hdr->data, payload_size);
|
2010-12-10 06:34:01 +00:00
|
|
|
break;
|
2011-01-19 08:27:41 +00:00
|
|
|
case ISUP_MSG_CGB:
|
2011-02-23 15:58:15 +00:00
|
|
|
rc = handle_circuit_reset_cgb(set, sls, hdr->cic, hdr->data, payload_size);
|
2011-01-19 08:33:00 +00:00
|
|
|
if (rc == 0)
|
2011-02-23 15:58:15 +00:00
|
|
|
rc = send_cgu(set, sls, hdr->cic, 28);
|
2011-01-19 08:33:00 +00:00
|
|
|
break;
|
2011-03-05 08:50:47 +00:00
|
|
|
case ISUP_MSG_CGU:
|
|
|
|
rc = handle_cgu(set, sls, hdr->cic, hdr->data, payload_size);
|
|
|
|
break;
|
2011-01-19 08:33:00 +00:00
|
|
|
case ISUP_MSG_CGUA:
|
2011-03-03 07:18:27 +00:00
|
|
|
LOGP(DISUP, LOGL_NOTICE, "CIC %d is now unblocked on linkset %d/%s.\n",
|
|
|
|
hdr->cic, set->nr, set->name);
|
2011-01-19 08:27:41 +00:00
|
|
|
break;
|
2011-01-18 22:34:19 +00:00
|
|
|
case ISUP_MSG_RSC:
|
2011-02-23 15:58:15 +00:00
|
|
|
rc = handle_simple_resp(set, sls, hdr->cic, ISUP_MSG_RLC);
|
2011-01-18 22:34:19 +00:00
|
|
|
break;
|
2010-12-10 06:34:01 +00:00
|
|
|
default:
|
2011-02-23 15:58:15 +00:00
|
|
|
mtp_link_set_forward_isup(set, msg, sls);
|
2011-01-17 15:13:28 +00:00
|
|
|
rc = 0;
|
2010-12-10 06:34:01 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|