diff options
-rw-r--r-- | include/mtp_data.h | 1 | ||||
-rw-r--r-- | src/isup.c | 49 | ||||
-rw-r--r-- | src/mtp_layer3.c | 23 | ||||
-rw-r--r-- | tests/isup/isup_parse_test.c | 3 |
4 files changed, 69 insertions, 7 deletions
diff --git a/include/mtp_data.h b/include/mtp_data.h index 14c2037..545c0f1 100644 --- a/include/mtp_data.h +++ b/include/mtp_data.h @@ -72,6 +72,7 @@ void mtp_link_stop(struct mtp_link *link); void mtp_link_reset(struct mtp_link *link); 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); +int mtp_link_submit_isup_data(struct mtp_link *link, int sls, const uint8_t *data, unsigned int length); /* one time init function */ @@ -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); diff --git a/tests/isup/isup_parse_test.c b/tests/isup/isup_parse_test.c index 721e9ce..af6b5bf 100644 --- a/tests/isup/isup_parse_test.c +++ b/tests/isup/isup_parse_test.c @@ -61,3 +61,6 @@ int main(int argc, char **argv) printf("All tests passed.\n"); return 0; } + +/* stubs */ +int mtp_link_submit_isup_data() {return -1;} |