From 0b2c143f942cd0560405e5cf381e2f734468ee6a Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Mon, 14 Jun 2010 12:40:20 +0200 Subject: initial commit of early experimentation/testing code for tcap and map --- test/Makefile | 20 +++++++ test/gprs_update.c | 162 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 182 insertions(+) create mode 100644 test/Makefile create mode 100644 test/gprs_update.c diff --git a/test/Makefile b/test/Makefile new file mode 100644 index 0000000..08f0aba --- /dev/null +++ b/test/Makefile @@ -0,0 +1,20 @@ + +CFLAGS += -I/usr/local/include/ +CFLAGS += -I/usr/local/include/asn1c/ +CFLAGS += -I/usr/local/include/osmocom/map/ +CFLAGS += -I/usr/local/include/osmocom/tcap/ +CFLAGS += -DPDU=MyCustomType + +LDFLAGS += -lasn1c -losmo-asn1-map -losmo-asn1-tcap -lm + +all: gprs_update + +gprs_update: gprs_update.o + $(CC) $(LDFLAGS) -o $@ $^ + +%.o: %.c + $(CC) $(CFLAGS) -o $@ -c $^ + +clean: + rm *.o + rm gprs_update diff --git a/test/gprs_update.c b/test/gprs_update.c new file mode 100644 index 0000000..d9d7531 --- /dev/null +++ b/test/gprs_update.c @@ -0,0 +1,162 @@ +/* Early tests with libasn1c and libosmo-asn1-tcap + libosmo-asn1-map */ + +/* (C) 2010 by Harald Welte + * All Rights Reserved + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (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 + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + */ + +#include +#include +#include +#include + +#include + +#include + +/* TCAP */ +#include +#include +#include + +/* MAP */ +#include +#include +#include +#include + +static const int map_app_ctx_oid[] = { 0, 4, 0, 0, 1, 0, 0, 0 }; +static const int gprsLocationUpdateContext_v3[] = { 0, 4, 0, 0, 1, 0, 32, 3 }; + +static const int diag_ref_struct[] = { 0, 0, 17, 773, 1, 1, 1 }; +static const int diag_ref_unstruct[] = { 0, 0, 17, 773, 1, 2, 1 }; + +/* construct MAP invoke (component) */ +static Component_t *create_map_invoke(uint32_t opcode, asn_TYPE_descriptor_t *td, + void *sptr) +{ + Component_t *comp; + Invoke_t *inv; + + comp = calloc(1, sizeof(*comp)); + memset(comp, 0, sizeof(*comp)); + + comp->present = Component_PR_invoke; + inv = &comp->choice.invoke; + + inv->invokeID = 1; /* FIXME: what is this? */ + inv->opCode.present = OPERATION_PR_localValue; + asn_long2INTEGER(&inv->opCode.choice.localValue, opcode); + + if (td && sptr) + inv->parameter = ANY_new_fromType(td, sptr); + + return comp; +} + +static Component_t *upd_gprs_loc_invoke(void) +{ + Component_t *comp; + + UpdateGprsLocationArg_t ula; + memset(&ula, 0, sizeof(ula)); + OCTET_STRING_fromString(&ula.imsi, "012345678912345"); + OCTET_STRING_fromString(&ula.sgsn_Number, "1"); + OCTET_STRING_fromString(&ula.sgsn_Address, "1.2.3.4"); + + xer_fprint(stdout, &asn_DEF_UpdateGprsLocationArg, &ula); + + /* build MAP invoke component with UpdateGPRSLocArg */ + comp = create_map_invoke(GSMMAPOperationLocalvalue_updateGprsLocation, + &asn_DEF_UpdateGprsLocationArg, &ula); + + xer_fprint(stdout, &asn_DEF_Component, comp); + + return comp; +} + +static uint8_t _dial_version1 = 0x80; +static BIT_STRING_t dial_version1 = { + .buf = &_dial_version1, + .size = 1, + .bits_unused = 7, +}; + +/* construct DialoguePDU wwith AARQ */ +static DialoguePDU_t *upd_gprs_loc_aarq() +{ + DialoguePDU_t *dial; + AARQ_apdu_t *aarq; + + dial = calloc(1, sizeof(*dial)); + memset(dial, 0, sizeof(*dial)); + dial->present = DialoguePDU_PR_dialogueRequest; + + aarq = &dial->choice.dialogueRequest; + aarq->protocol_version = &dial_version1; + OBJECT_IDENTIFIER_set_arcs(&aarq->application_context_name, + &gprsLocationUpdateContext_v3, + sizeof(gprsLocationUpdateContext_v3[0]), + ARRAY_SIZE(gprsLocationUpdateContext_v3)); + + xer_fprint(stdout, &asn_DEF_DialoguePDU, dial); + + return dial; +} + + +static int tcap_msg(void) +{ + uint32_t trans_id = 1; + struct ComponentPortion cp; + ExternalPDU_t ext; + Component_t *comp; + DialoguePDU_t *dial; + TCMessage_t *tcm; + + memset(&ext, 0, sizeof(ext)); + + tcm = calloc(1, sizeof(*tcm)); + memset(tcm, 0, sizeof(*tcm)); + + tcm->present = TCMessage_PR_begin; + OCTET_STRING_fromBuf(&tcm->choice.begin.otid, + (const char *) &trans_id, sizeof(trans_id)); + + /* build dialogue sequence from OID and DialoguePDU */ + dial = upd_gprs_loc_aarq(); + + OBJECT_IDENTIFIER_set_arcs(&ext.oid, &diag_ref_struct, + sizeof(diag_ref_struct[0]), + ARRAY_SIZE(diag_ref_struct)); + ANY_fromType(&ext.dialog, &asn_DEF_DialoguePDU, dial); + tcm->choice.begin.dialoguePortion = + ANY_new_fromType(&asn_DEF_ExternalPDU, &ext); + + /* add SEQUENCE_OF invoke component */ + memset(&cp, 0, sizeof(cp)); + tcm->choice.begin.components = &cp; + comp = upd_gprs_loc_invoke(); + ASN_SEQUENCE_ADD(&cp.list, comp); + + xer_fprint(stdout, &asn_DEF_TCMessage, tcm); +} + +int main(int argc, char **argv) +{ + tcap_msg(); +} -- cgit v1.2.3