aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <zecke@selfish.org>2010-12-10 12:18:57 +0100
committerHolger Hans Peter Freyther <zecke@selfish.org>2010-12-10 13:22:46 +0100
commit3aad776b280c889a5432e51fbdbe78ef1af624c9 (patch)
tree4e8eb3e2b07c0b375c2b2edc1c6134945f3c3eec /src
parent433ea2f037effc600543823e5b3fa8ec540b989a (diff)
isup: Respond to a ISUP GRS with a GRA.
Diffstat (limited to 'src')
-rw-r--r--src/isup.c49
-rw-r--r--src/mtp_layer3.c23
2 files changed, 65 insertions, 7 deletions
diff --git a/src/isup.c b/src/isup.c
index 8cb91a9..f7452c5 100644
--- a/src/isup.c
+++ b/src/isup.c
@@ -21,8 +21,46 @@
#include <isup_types.h>
#include <cellmgr_debug.h>
+#include <mtp_data.h>
#include <osmocore/msgb.h>
+#include <osmocore/tlv.h>
+
+static struct msgb *isup_gra_alloc(int cic, int range)
+{
+ struct isup_msg_hdr *hdr;
+ struct msgb *msg;
+ int bits, len;
+
+ msg = msgb_alloc_headroom(4096, 128, "ISUP GRA");
+ if (!msg) {
+ LOGP(DISUP, LOGL_ERROR, "Allocation of GRA message failed.\n");
+ return NULL;
+ }
+
+ msg->l2h = msgb_put(msg, sizeof(*hdr));
+
+ /* write the ISUP header */
+ hdr = (struct isup_msg_hdr *) msg->l2h;
+ hdr->cic = cic;
+ hdr->msg_type = ISUP_MSG_GRA;
+
+ /*
+ * 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);
+
+ msgb_put(msg, len);
+
+ return msg;
+}
/* this message contains the range */
int isup_parse_grs(const uint8_t *data, uint8_t in_length)
@@ -53,17 +91,22 @@ int isup_parse_grs(const uint8_t *data, uint8_t in_length)
/* Handle incoming ISUP data */
-static int handle_circuit_reset_grs(struct mtp_link *link, int sls,
+static int handle_circuit_reset_grs(struct mtp_link *link, int sls, int cic,
const uint8_t *data, int size)
{
+ struct msgb *resp;
int range;
range = isup_parse_grs(data, size);
if (range < 0)
return -1;
- printf("ASKED to reset range: %d\n", range);
+ resp = isup_gra_alloc(cic, range);
+ if (!resp)
+ return -1;
+ mtp_link_submit_isup_data(link, sls, resp->l2h, msgb_l2len(resp));
+ msgb_free(resp);
return 0;
}
@@ -83,7 +126,7 @@ int mtp_link_forward_isup(struct mtp_link *link, struct msgb *msg, int sls)
switch (hdr->msg_type) {
case ISUP_MSG_GRS:
- rc = handle_circuit_reset_grs(link, sls, hdr->data, payload_size);
+ rc = handle_circuit_reset_grs(link, sls, hdr->cic, hdr->data, payload_size);
break;
default:
LOGP(DISUP, LOGL_NOTICE, "ISUP msg not handled: 0x%x\n", hdr->msg_type);
diff --git a/src/mtp_layer3.c b/src/mtp_layer3.c
index 4490c8b..78db37c 100644
--- a/src/mtp_layer3.c
+++ b/src/mtp_layer3.c
@@ -34,6 +34,8 @@
static void *tall_mtp_ctx = NULL;
+static int mtp_int_submit(struct mtp_link *link, int sls, int type, const uint8_t *data, unsigned int length);
+
static struct msgb *mtp_msg_alloc(struct mtp_link *link)
{
struct mtp_level_3_hdr *hdr;
@@ -500,21 +502,34 @@ int mtp_link_data(struct mtp_link *link, struct msgb *msg)
int mtp_link_submit_sccp_data(struct mtp_link *link, int sls, const uint8_t *data, unsigned int length)
{
- uint8_t *put_ptr;
- struct mtp_level_3_hdr *hdr;
- struct msgb *msg;
if (!link->sccp_up) {
LOGP(DINP, LOGL_ERROR, "SCCP msg after TRA and before SSA. Dropping it.\n");
return -1;
}
+ return mtp_int_submit(link, sls, MTP_SI_MNT_SCCP, data, length);
+}
+
+int mtp_link_submit_isup_data(struct mtp_link *link, int sls,
+ const uint8_t *data, unsigned int length)
+{
+ return mtp_int_submit(link, sls, MTP_SI_MNT_ISUP, data, length);
+}
+
+static int mtp_int_submit(struct mtp_link *link, int sls, int type,
+ const uint8_t *data, unsigned int length)
+{
+ uint8_t *put_ptr;
+ struct mtp_level_3_hdr *hdr;
+ struct msgb *msg;
+
msg = mtp_msg_alloc(link);
if (!msg)
return -1;
hdr = (struct mtp_level_3_hdr *) msg->l2h;
- hdr->ser_ind = MTP_SI_MNT_SCCP;
+ hdr->ser_ind = type;
hdr->addr = MTP_ADDR(sls % 16, link->dpc, link->opc);