151 lines
3.5 KiB
C
151 lines
3.5 KiB
C
|
|
#include <stdint.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
//#include <asn1/OBJECT_IDENTIFIER.h>
|
|
|
|
#include <osmocore/utils.h>
|
|
|
|
#include "tcap_user.h"
|
|
|
|
static struct {
|
|
struct tcap_transport_entity *tte;
|
|
unsigned int begin_rcvd:1;
|
|
uint32_t dialg_id;
|
|
} test_state;
|
|
|
|
static int send_continue()
|
|
{
|
|
struct tcap_dialg_ind tcdi;
|
|
|
|
memset(&tcdi, 0, sizeof(tcdi));
|
|
tcdi.dialg_id = test_state.dialg_id;
|
|
return tcap_user_req_dialg(TCAP_PR_TC_CONTINUE, &tcdi);
|
|
}
|
|
|
|
static void tcap_gen_oper_local(struct OPERATION *op, uint32_t local_value)
|
|
{
|
|
op->present = OPERATION_PR_localValue;
|
|
asn_long2INTEGER(&op->choice.localValue, local_value);
|
|
}
|
|
|
|
/* UpdateGprsLocationArg */
|
|
static const int gprsLocationUpdateContext_v3[] = { 0, 4, 0, 0, 1, 0, 32, 3 };
|
|
static OBJECT_IDENTIFIER_t gprs_loc_upd_ctx_v3_oid;
|
|
|
|
static const uint8_t gprs_loc_upd_param[] = {
|
|
0x30, 0x1d, 0x04, 0x0f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x31, 0x32,
|
|
0x33, 0x34, 0x35, 0x04, 0x01, 0x31, 0x04, 0x07, 0x31, 0x2e, 0x32, 0x2e, 0x33, 0x2e, 0x34
|
|
};
|
|
|
|
static int send_invoke(uint32_t dialg_id, int8_t invoke_id, const uint8_t *param, uint32_t param_len)
|
|
{
|
|
struct tcap_component_ind tcci;
|
|
|
|
|
|
memset(&tcci, 0, sizeof(tcci));
|
|
tcci.dialg_id = dialg_id;
|
|
tcci.invoke_id = invoke_id;
|
|
tcci.linked_id = NULL;
|
|
tcap_gen_oper_local(&tcci.operation, 1);
|
|
tcci.timeout_secs = 10;
|
|
tcci.op_class = 1;
|
|
|
|
tcci.parameter.buf = param;
|
|
tcci.parameter.size = param_len;
|
|
|
|
return tcap_user_req_comp(TCAP_PR_TC_INVOKE, &tcci);
|
|
}
|
|
|
|
static int send_begin(uint32_t dialg_id, OBJECT_IDENTIFIER_t *app_ctx)
|
|
{
|
|
struct tcap_dialg_ind tcdi;
|
|
|
|
memset(&tcdi, 0, sizeof(tcdi));
|
|
tcdi.dialg_id = dialg_id;
|
|
tcdi.app_ctx_name = app_ctx;
|
|
tcdi.transp_ent = test_state.tte;
|
|
|
|
return tcap_user_req_dialg(TCAP_PR_TC_BEGIN, &tcdi);
|
|
}
|
|
|
|
int tcap_user_ind_dialg(enum tcap_primitive prim, struct tcap_dialg_ind *tcdi)
|
|
{
|
|
printf("-> USER_IND_DIALG(%s): ", tcap_prim_name(prim));
|
|
|
|
switch (prim) {
|
|
case TCAP_PR_TC_BEGIN:
|
|
test_state.begin_rcvd = 1;
|
|
test_state.dialg_id = tcdi->dialg_id;
|
|
printf("dialg_id=0x%08x ", tcdi->dialg_id);
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
return 0;
|
|
}
|
|
|
|
int tcap_user_ind_comp(enum tcap_primitive prim, struct tcap_component_ind *tcci)
|
|
{
|
|
printf("-> USER_IND_COMP(%s)\n", tcap_prim_name(prim));
|
|
|
|
if (!test_state.begin_rcvd)
|
|
return -1;
|
|
|
|
switch (prim) {
|
|
case TCAP_PR_TC_INVOKE:
|
|
/* actually process the invoke */
|
|
send_invoke(test_state.dialg_id, 0, NULL, 0);
|
|
if (tcci->last_component)
|
|
send_continue();
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int initialize(void)
|
|
{
|
|
OBJECT_IDENTIFIER_set_arcs(&gprs_loc_upd_ctx_v3_oid, &gprsLocationUpdateContext_v3,
|
|
sizeof(gprsLocationUpdateContext_v3[0]),
|
|
ARRAY_SIZE(gprsLocationUpdateContext_v3));
|
|
}
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
struct sockaddr_storage ss;
|
|
struct sockaddr_in *sin = (struct sockaddr_in *)&ss;
|
|
|
|
initialize();
|
|
|
|
ss.ss_family = AF_INET;
|
|
sin->sin_addr.s_addr = INADDR_ANY;
|
|
sin->sin_port = htons(4242);
|
|
|
|
test_state.tte = tcap_transp_udp_create(&ss);
|
|
if (!test_state.tte) {
|
|
fprintf(stderr, "Cannot create UDP socket\n");
|
|
exit(1);
|
|
}
|
|
/* make sure we sent messages to ourselves */
|
|
inet_aton("127.0.0.1", &sin->sin_addr);
|
|
memcpy(&test_state.tte->remote_addr, &ss, sizeof(test_state.tte->remote_addr));
|
|
|
|
send_invoke(0x1234, 0, gprs_loc_upd_param, sizeof(gprs_loc_upd_param));
|
|
send_invoke(0x1234, 1, NULL, 0);
|
|
send_invoke(0x1234, -1, NULL, 0);
|
|
send_begin(0x1234, &gprs_loc_upd_ctx_v3_oid);
|
|
|
|
while (1) {
|
|
bsc_select_main(0);
|
|
}
|
|
}
|