95 lines
1.9 KiB
C
95 lines
1.9 KiB
C
|
|
#include <osmocore/linuxlist.h>
|
|
#include <osmocore/talloc.h>
|
|
|
|
#include "tcap.h"
|
|
|
|
static LLIST_HEAD(tcap_dialogues);
|
|
|
|
static uint32_t dialg_id_ctr = 0x4000;
|
|
static uint32_t trans_id_ctr = 0x8000;
|
|
|
|
void *tall_tcap_dialg_ctx;
|
|
|
|
uint32_t tcap_dialg_id_alloc(void)
|
|
{
|
|
uint32_t dialg_id;
|
|
|
|
dialg_id = dialg_id_ctr++;
|
|
|
|
while (tcap_dialg_by_dialg_id(dialg_id))
|
|
dialg_id = dialg_id_ctr++;
|
|
|
|
return dialg_id;
|
|
}
|
|
|
|
struct tcap_dialogue *tcap_dialg_by_dialg_id(uint32_t dialogue_id)
|
|
{
|
|
struct tcap_dialogue *td;
|
|
llist_for_each_entry(td, &tcap_dialogues, list) {
|
|
if (td->dialogue_id == dialogue_id)
|
|
return td;
|
|
}
|
|
return NULL;
|
|
}
|
|
|
|
struct tcap_dialogue *tcap_dialg_alloc(uint32_t dialogue_id)
|
|
{
|
|
struct tcap_dialogue *td = talloc_zero(tall_tcap_dialg_ctx, struct tcap_dialogue);
|
|
if (!td)
|
|
return NULL;
|
|
|
|
td->dialogue_id = dialogue_id;
|
|
td->trans.state = TCAP_TS_IDLE;
|
|
td->trans.tid_local = tcap_trans_id_alloc();
|
|
llist_add(&td->list, &tcap_dialogues);
|
|
INIT_LLIST_HEAD(&td->ism_list);
|
|
INIT_LLIST_HEAD(&td->pend_comp_list);
|
|
|
|
return td;
|
|
}
|
|
|
|
/* allocate a transaction (by allocating a dialogue) */
|
|
struct tcap_transaction *tcap_transaction_alloc(void)
|
|
{
|
|
uint32_t dialg_id = tcap_dialg_id_alloc();
|
|
struct tcap_dialogue *td = tcap_dialg_alloc(dialg_id);
|
|
return &td->trans;
|
|
}
|
|
|
|
struct tcap_transaction *tcap_transaction_by_remote_tid(uint32_t tid_remote)
|
|
{
|
|
struct tcap_dialogue *td;
|
|
|
|
llist_for_each_entry(td, &tcap_dialogues, list) {
|
|
if (td->trans.tid_remote == tid_remote)
|
|
return &td->trans;
|
|
}
|
|
|
|
return NULL;
|
|
}
|
|
|
|
struct tcap_transaction *tcap_transaction_by_local_tid(uint32_t tid_local)
|
|
{
|
|
struct tcap_dialogue *td;
|
|
|
|
llist_for_each_entry(td, &tcap_dialogues, list) {
|
|
if (td->trans.tid_local == tid_local)
|
|
return &td->trans;
|
|
}
|
|
|
|
return NULL;
|
|
}
|
|
|
|
uint32_t tcap_trans_id_alloc(void)
|
|
{
|
|
uint32_t trans_id;
|
|
|
|
trans_id = trans_id_ctr++;
|
|
|
|
while (tcap_transaction_by_local_tid(trans_id))
|
|
trans_id = trans_id_ctr++;
|
|
|
|
return trans_id;
|
|
}
|