libosmo-tcap/src/csl_cha_ism.c

216 lines
4.4 KiB
C
Raw Normal View History

/* ITU-T Q.77x TCAP / ISM - Invocation State Machine,
* part of CHA (ComponentHAndling), part of CSL (Component Sub-Layer) */
#include <osmocore/talloc.h>
#include <osmocore/msgb.h>
#include "tcap.h"
struct tcap_invocation *tcap_ism_lookup(struct tcap_dialogue *td, int8_t invoke_id)
{
struct tcap_invocation *ti;
llist_for_each_entry(ti, &td->ism_list, list) {
if (ti->invoke_id == invoke_id)
return ti;
}
return NULL:
}
struct tcap_invocation *tcap_ism_alloc(struct tcap_dialogue *td, int8_t invoke_id)
{
struct tcap_invocation *ti = talloc_zero(td, struct tcap_invocation);
if (!ti)
return NULL;
ti->invoke_id = invoke_id;
ti->linked_id = -1234;
ti->dialogue = td;
ti->state = TCAP_IS_IDLE;
llist_add(&ti->list, &td->ism_list);
return ti;
}
void tcap_ism_free(struct tcap_invocation *ti)
{
llist_del(&ti->list);
talloc_free(ti);
}
/* Invocation timer expiry */
static int tcap_ism_inv_timer_exp(void *_ti)
{
struct tcap_invocation *ti = _ti;
switch (ti->state) {
case TCAP_IS_OP_SENT_CL1:
case TCAP_IS_OP_SENT_CL2:
case TCAP_IS_OP_SENT_CL3:
case TCAP_IS_OP_SENT_CL4:
/* TC-L-CANCEL.ind (TCU <- CHA) */
ti->state = TI_IS_INVALID;
llist_del(&ti->list);
talloc_free(ti);
break;
default:
return -EINVAL;
}
return 0;
}
/* Reject timer expiry */
static int tcap_ism_rej_timer_exp(void *_ti)
{
struct tcap_invocation *ti = _ti;
if (state != TCAP_IS_WAIT_REJECT)
return -EINVAL;
ti->state = TI_IS_INVALID;
llist_del(&ti->list);
talloc_free(ti);
return 0;
}
/* Operation sent (CCO -> ISM) */
int tcap_ism_op_sent(struct tcap_invocation *ti, uint8_t op_class)
{
/* Start invocation timer */
ti->inv_timer.cb = tcap_ism_inv_timer_exp;
ti->inv_timer.data = ti;
bsc_schedule_timer(&ti->inv_timer, sec, usec);
switch (op_class) {
case 1:
ti->state = TCAP_IS_OP_SENT_CL1;
break;
case 2:
ti->state = TCAP_IS_OP_SENT_CL2;
break;
case 3:
ti->state = TCAP_IS_OP_SENT_CL3;
break;
case 4:
ti->state = TCAP_IS_OP_SENT_CL4;
break;
default:
return -EINVAL;
}
}
/* RR-L received (CCO -> ISM) */
int tcap_ism_rr_l_recv(struct tcap_invocation *ti)
{
int rc = 0;
switch (ti->state) {
case TCAP_IS_OP_SENT_CL1:
case TCAP_IS_OP_SENT_CL3:
/* TC-RESULT-L.ind (TCU <- CHA) */
rc = tcap_tcu_result_l_ind();
/* Stop invocation timer */
bsc_del_timer(&ti->inv_timer);
/* Start reject timer */
ti->rej_timer.cb = tcap_ism_rej_timer_exp;
ti->rej_timer.data = ti;
bsc_schedule_timer(&ti->rej_timer, sec, usec);
ti->state = TCAP_IS_WAIT_REJECT;
break;
case TCAP_IS_OP_SENT_CL2:
case TCAP_IS_OP_SENT_CL4:
/* Generate RJ component (CCO <- ISM) */
rc = tcap_cco_gen_rej(ti);
/* Stop invocation timer */
bsc_del_timer(&ti->inv_timer);
ti->state = TCAP_IS_INVALID;
llist_del(&ti->list);
talloc_free(ti);
break;
}
}
/* RE received (CCO -> ISM) */
int tcap_ism_re_recv(struct tcap_invocation *ti)
{
switch (ti->state) {
case TCAP_IS_OP_SENT_CL1:
case TCAP_IS_OP_SENT_CL2:
/* TC-U-ERROR.ind (TCU <- CHA) */
/* Stop invocation timer */
bsc_del_timer(&ti->inv_timer);
/* Start reject timer */
ti->rej_timer.cb = tcap_ism_rej_timer_exp;
ti->rej_timer.data = ti;
bsc_schedule_timer(&ti->rej_timer, sec, usec);
ti->state = TCAP_IS_WAIT_REJECT;
break;
case TCAP_IS_OP_SENT_CL3:
case TCAP_IS_OP_SENT_CL4:
ti->state = TCAP_IS_INVALID;
llist_del(&ti->list);
talloc_free(ti);
break;
default:
return -EINVAL;
}
return 0;
}
/* RR-NL received (CCO -> ISM) */
int tcap_ism_rr_nl_recv(struct tcap_invocation *ti)
{
int rc = 0;
switch (ti->state) {
case TCAP_IS_OP_SENT_CL1:
case TCAP_IS_OP_SENT_CL3:
/* TC-RESULT-NL.ind (TCU <- CHA) */
rc = tcap_tcu_result_nl_ind();
/* stay in SENT_CL1 state */
break;
case TCAP_IS_OP_SENT_CL2:
case TCAP_IS_OP_SENT_CL4:
/* Generate RJ component (CCO <- ISM) */
rc = tcap_cco_gen_rej(ti);
/* Stop invocation timer */
bsc_del_timer(&ti->inv_timer);
ti->state = TCAP_IS_INVALID;
llist_del(&ti->list);
talloc_free(ti);
break;
default:
return -EINVAL;
}
return rc;
}
/* Terminate (CCO -> ISM) */
int tcap_ism_terminate(struct tcap_invocation *ti)
{
switch (ti->state) {
case TCAP_IS_OP_SENT_CL1:
case TCAP_IS_OP_SENT_CL2:
case TCAP_IS_OP_SENT_CL3:
case TCAP_IS_OP_SENT_CL4:
case TCAP_IS_WAIT_REJECT:
break;
default:
return -EINVAL;
}
/* Stop invoation timer */
bsc_del_timer(&ti->inv_timer);
ti->state = TCAP_IS_INVALID;
llist_del(&ti->list);
talloc_free(ti);
return 0;
}