init ems server code
This commit is contained in:
13
plat/pal/Makefile
Normal file
13
plat/pal/Makefile
Normal file
@@ -0,0 +1,13 @@
|
||||
cc = gcc
|
||||
CFLAG = -g -Wall -c
|
||||
PAL_OBJ = rm.o
|
||||
PAL_LIB = lib/libpal.a
|
||||
|
||||
all: $(PAL_OBJ)
|
||||
ar -r $(PAL_LIB) $(PAL_OBJ)
|
||||
|
||||
rm.o: rm.c
|
||||
$(cc) $(CFLAG) $<
|
||||
clean:
|
||||
rm -rf *.o $(PAL_LIB)
|
||||
|
||||
0
plat/pal/lib/Just for creating lib directory.txt
Normal file
0
plat/pal/lib/Just for creating lib directory.txt
Normal file
123
plat/pal/pal.h
Normal file
123
plat/pal/pal.h
Normal file
@@ -0,0 +1,123 @@
|
||||
#ifndef _PAL_H_
|
||||
#define _PAL_H_
|
||||
|
||||
#include "../public/src/include/public.h"
|
||||
|
||||
#define PROTO_AIF 0
|
||||
#define PROTO_ISUP 1
|
||||
#define PROTO_BICC 2
|
||||
#define PROTO_ISDN 3
|
||||
#define PROTO_TUP 4
|
||||
#define PROTO_SIP 5
|
||||
#define PROTO_MGC 6
|
||||
#define MAX_PROTO_TYPE 7
|
||||
|
||||
#define VARIANT_ITU 0
|
||||
#define VARIANT_ANSI 1
|
||||
#define VARIANT_ETSI 2
|
||||
#define VARIANT_UK 3
|
||||
#define VARIANT_QSIG 4
|
||||
|
||||
#define DUAL_SEIZURE_REATTEMPT 0 /* Re-attempt on detection of dual seizure */
|
||||
#define DUAL_SEIZURE_CONTINUE 1 /* Continue the call on detection of dual seizure */
|
||||
|
||||
#define CTRL_PLAT_0 0
|
||||
#define CTRL_PLAT_1 1
|
||||
|
||||
#define PAL_MAX_CALLBACK 64
|
||||
#define PAL_MAX_SAP 16
|
||||
#define PAL_MAX_CG 256
|
||||
#define PAL_MAX_CIRCUIT 256
|
||||
#define PAL_DOMAIN_LEN 32
|
||||
|
||||
typedef struct sap_attribute {
|
||||
void *event_handle[PAL_MAX_CALLBACK];
|
||||
} sap_attrib_struct;
|
||||
|
||||
/* Non-Facility Associated Signalling */
|
||||
struct nfas_info {
|
||||
u8 flag;
|
||||
u32 prim_link;
|
||||
u32 backup_link;
|
||||
};
|
||||
|
||||
typedef struct cg_attribute {
|
||||
u8 protocol;
|
||||
u8 variant;
|
||||
u8 priority; //0: re-attempt; 1: continue
|
||||
u8 network_id;
|
||||
u32 dpc;
|
||||
u32 opc;
|
||||
char dest_domain[PAL_DOMAIN_LEN]; //for sip
|
||||
char local_domain[PAL_DOMAIN_LEN]; //for sip
|
||||
struct nfas_info nfas;
|
||||
u32 tg_id;
|
||||
} cg_attrib_struct;
|
||||
|
||||
typedef struct circuit_attribute {
|
||||
u8 plat_id;
|
||||
u8 cic_range;
|
||||
u32 head_cic;
|
||||
u32 link_id; //for isdn
|
||||
u8 user_network_if; //for isdn
|
||||
u8 d_chnl; //for isdn
|
||||
} circuit_attrib_struct;
|
||||
|
||||
typedef struct pal_sap {
|
||||
u8 id;
|
||||
u8 enable;
|
||||
sap_attrib_struct attrib;
|
||||
} pal_sap_struct;
|
||||
|
||||
typedef struct pal_circuitgroup {
|
||||
u8 id;
|
||||
u8 enable;
|
||||
u8 sap_id;
|
||||
u8 circuit_num;
|
||||
cg_attrib_struct attrib;
|
||||
} pal_cg_struct;
|
||||
|
||||
typedef struct pal_circuit {
|
||||
u8 id;
|
||||
u8 enable;
|
||||
u8 cg_id;
|
||||
circuit_attrib_struct attrib;
|
||||
} pal_circuit_struct;
|
||||
|
||||
typedef struct _pst_struct
|
||||
{
|
||||
u16 cg_id;
|
||||
u32 tg_id;
|
||||
u32 cic;
|
||||
|
||||
u32 sp_proc_id;
|
||||
u32 su_proc_id;
|
||||
|
||||
int trace_flag;
|
||||
} Pst;
|
||||
|
||||
/* Upper layer interface */
|
||||
extern u8 *pal_version(void);
|
||||
extern char* pal_error(void);
|
||||
extern int pal_bind_sap(sap_attrib_struct *attrib);
|
||||
extern int pal_create_cg(u8 sap_id, cg_attrib_struct *attrib);
|
||||
extern int pal_delete_cg(int cg_id);
|
||||
extern int pal_modify_cg(int cg_id, cg_attrib_struct *attrib);
|
||||
extern int pal_create_circuit(int cg_id, circuit_attrib_struct *attrib);
|
||||
extern int pal_delete_circuit(int circuit_id);
|
||||
|
||||
/* Lower layer interface */
|
||||
extern void *pal_get_handler(u32 cg_id);
|
||||
extern const pal_sap_struct *pal_sap_ptr(u8 sap_id);
|
||||
extern const pal_cg_struct *pal_cg_ptr(u32 cg_id);
|
||||
extern const pal_circuit_struct *pal_circuit_ptr(u32 circuit_id);
|
||||
extern const pal_cg_struct *pal_ss7_find_cg(u8 ni, u32 dpc, u32 opc);
|
||||
extern const pal_cg_struct *pal_isdn_find_cg(u32 link_id);
|
||||
extern const pal_cg_struct *pal_sip_find_cg(char *domain, char *their_domain);
|
||||
extern const pal_circuit_struct *pal_locate_circuit(u32 cg_id, u32 cic);
|
||||
extern const pal_circuit_struct *pal_ss7_find_circuit(u8 ni, u32 dpc, u32 opc, u32 cic);
|
||||
extern const pal_circuit_struct *pal_isdn_find_circuit(u32 link_id, u32 cic);
|
||||
extern const pal_circuit_struct *pal_isdn_find_circuit_of_link(u32 link_id);
|
||||
|
||||
#endif
|
||||
|
||||
339
plat/pal/rm.c
Normal file
339
plat/pal/rm.c
Normal file
@@ -0,0 +1,339 @@
|
||||
/*
|
||||
* pal/rm.c
|
||||
*
|
||||
* Copyright (C) 2008 ACRD
|
||||
* Written by: Xinyu Yan <xinyu.yan@adc.com>
|
||||
*
|
||||
* Description: Protocol Abstraction Layer - resource management part
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "pal.h"
|
||||
|
||||
struct resource_mgmt {
|
||||
pal_sap_struct sap[PAL_MAX_SAP];
|
||||
pal_cg_struct cg[PAL_MAX_CG];
|
||||
pal_circuit_struct circuit[PAL_MAX_CIRCUIT];
|
||||
};
|
||||
|
||||
#define ERROR_STRING_LEN 256
|
||||
|
||||
static u8 version[4] = {9, 0, 0, 1};
|
||||
static struct resource_mgmt pal_resource;
|
||||
static char error_string[ERROR_STRING_LEN+1];
|
||||
|
||||
u8 *pal_version(void)
|
||||
{
|
||||
return version;
|
||||
}
|
||||
|
||||
char *pal_error(void)
|
||||
{
|
||||
return error_string;
|
||||
}
|
||||
|
||||
/****************************************************/
|
||||
/*************** PAL upper layer interface ***************/
|
||||
/****************************************************/
|
||||
int pal_bind_sap(sap_attrib_struct *attrib)
|
||||
{
|
||||
int i;
|
||||
pal_sap_struct *sap;
|
||||
|
||||
for(i = 0; i < PAL_MAX_SAP; i++)
|
||||
{
|
||||
sap = &pal_resource.sap[i];
|
||||
if(sap->enable == 0)
|
||||
{
|
||||
sap->id = i;
|
||||
sap->enable = 1;
|
||||
memcpy(&sap->attrib, attrib, sizeof(sap_attrib_struct));
|
||||
return i;
|
||||
}
|
||||
}
|
||||
sprintf(error_string, "%s: no free sap\r\n", __FUNCTION__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int pal_unbind_sap(u8 sap_id)
|
||||
{
|
||||
//need not support//
|
||||
return -1;
|
||||
}
|
||||
|
||||
int pal_create_cg(u8 sap_id, cg_attrib_struct *attrib)
|
||||
{
|
||||
int i;
|
||||
pal_cg_struct *cg;
|
||||
|
||||
if(sap_id >= PAL_MAX_SAP)
|
||||
{
|
||||
sprintf(error_string, "%s: sap id(%d) out of range\r\n", __FUNCTION__, sap_id);
|
||||
return -1;
|
||||
}
|
||||
if(pal_resource.sap[sap_id].enable == 0)
|
||||
{
|
||||
sprintf(error_string, "%s: sap (%d) is not created\r\n", __FUNCTION__, sap_id);
|
||||
return -1;
|
||||
}
|
||||
|
||||
for(i = 0; i < PAL_MAX_CG; i++)
|
||||
{
|
||||
cg = &pal_resource.cg[i];
|
||||
if(cg->enable == 0)
|
||||
{
|
||||
cg->id = i;
|
||||
cg->enable = 1;
|
||||
cg->sap_id = sap_id;
|
||||
cg->circuit_num = 0;
|
||||
memcpy(&cg->attrib, attrib, sizeof(cg_attrib_struct));
|
||||
return i;
|
||||
}
|
||||
}
|
||||
sprintf(error_string, "%s: no free cg\r\n", __FUNCTION__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int pal_delete_cg(int cg_id)
|
||||
{
|
||||
pal_cg_struct *cg;
|
||||
|
||||
if(cg_id >= PAL_MAX_CG)
|
||||
{
|
||||
sprintf(error_string, "%s: cg id(%d) out of range\r\n", __FUNCTION__, cg_id);
|
||||
return -1;
|
||||
}
|
||||
cg = &pal_resource.cg[cg_id];
|
||||
if(cg->circuit_num > 0)
|
||||
{
|
||||
sprintf(error_string, "%s: %d circuit in used\r\n", __FUNCTION__, cg->circuit_num);
|
||||
return -1;
|
||||
}
|
||||
cg->enable = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pal_modify_cg(int cg_id, cg_attrib_struct *attrib)
|
||||
{
|
||||
pal_cg_struct *cg;
|
||||
|
||||
if(cg_id >= PAL_MAX_CG)
|
||||
{
|
||||
sprintf(error_string, "%s: cg id(%d) out of range\r\n", __FUNCTION__, cg_id);
|
||||
return -1;
|
||||
}
|
||||
cg = &pal_resource.cg[cg_id];
|
||||
memcpy(&cg->attrib, attrib, sizeof(cg_attrib_struct));
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pal_create_circuit(int cg_id, circuit_attrib_struct *attrib)
|
||||
{
|
||||
int i;
|
||||
pal_cg_struct *cg;
|
||||
pal_circuit_struct *circuit;
|
||||
|
||||
if(cg_id >= PAL_MAX_CG)
|
||||
{
|
||||
sprintf(error_string, "%s: cg id(%d) out of range\r\n", __FUNCTION__, cg_id);
|
||||
return -1;
|
||||
}
|
||||
cg = &pal_resource.cg[cg_id];
|
||||
if(cg->enable == 0)
|
||||
{
|
||||
sprintf(error_string, "%s: cg(%d) is not created\r\n", __FUNCTION__, cg_id);
|
||||
return -1;
|
||||
}
|
||||
for(i = 0; i < PAL_MAX_CIRCUIT; i++)
|
||||
{
|
||||
circuit = &pal_resource.circuit[i];
|
||||
if(circuit->enable == 0)
|
||||
{
|
||||
circuit->id = i;
|
||||
circuit->enable = 1;
|
||||
circuit->cg_id = cg_id;
|
||||
memcpy(&circuit->attrib, attrib, sizeof(circuit_attrib_struct));
|
||||
cg->circuit_num++;
|
||||
return i;
|
||||
}
|
||||
}
|
||||
sprintf(error_string, "%s: no free circuit\r\n", __FUNCTION__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int pal_delete_circuit(int circuit_id)
|
||||
{
|
||||
pal_cg_struct *cg;
|
||||
pal_circuit_struct *circuit;
|
||||
|
||||
if(circuit_id >= PAL_MAX_CIRCUIT)
|
||||
{
|
||||
sprintf(error_string, "%s: circuit id(%d) out of range\r\n", __FUNCTION__, circuit_id);
|
||||
return -1;
|
||||
}
|
||||
circuit = &pal_resource.circuit[circuit_id];
|
||||
cg = &pal_resource.cg[circuit->cg_id];
|
||||
circuit->enable = 0;
|
||||
cg->circuit_num--;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/****************************************************/
|
||||
/*************** PAL lower layer interface ***************/
|
||||
/****************************************************/
|
||||
static int protocol_is_ss7(u8 proto)
|
||||
{
|
||||
if((proto == PROTO_AIF) || (proto == PROTO_ISUP) || (proto == PROTO_BICC))
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *pal_get_handler(u32 cg_id)
|
||||
{
|
||||
u32 sap_id;
|
||||
|
||||
sap_id = pal_resource.cg[cg_id].sap_id;
|
||||
return pal_resource.sap[sap_id].attrib.event_handle;
|
||||
}
|
||||
|
||||
const pal_sap_struct *pal_sap_ptr(u8 sap_id)
|
||||
{
|
||||
if(sap_id < PAL_MAX_SAP)
|
||||
return &pal_resource.sap[sap_id];
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const pal_cg_struct *pal_cg_ptr(u32 cg_id)
|
||||
{
|
||||
if(cg_id < PAL_MAX_CG)
|
||||
return &pal_resource.cg[cg_id];
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const pal_circuit_struct *pal_circuit_ptr(u32 circuit_id)
|
||||
{
|
||||
if(circuit_id < PAL_MAX_CIRCUIT)
|
||||
return &pal_resource.circuit[circuit_id];
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const pal_cg_struct *pal_ss7_find_cg(u8 ni, u32 dpc, u32 opc)
|
||||
{
|
||||
int i;
|
||||
pal_cg_struct *cg;
|
||||
|
||||
for(i = 0; i < PAL_MAX_CG; i++)
|
||||
{
|
||||
cg = &pal_resource.cg[i];
|
||||
if(cg->enable == 0)
|
||||
continue;
|
||||
if(protocol_is_ss7(cg->attrib.protocol) == 0)
|
||||
continue;
|
||||
if((cg->attrib.network_id == ni) &&
|
||||
(cg->attrib.opc == opc) &&
|
||||
(cg->attrib.dpc == dpc))
|
||||
return cg;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const pal_cg_struct *pal_isdn_find_cg(u32 link_id)
|
||||
{
|
||||
int i;
|
||||
pal_circuit_struct *circuit;
|
||||
|
||||
for(i = 0; i < PAL_MAX_CIRCUIT; i++)
|
||||
{
|
||||
circuit = &pal_resource.circuit[i];
|
||||
if(circuit->enable == 0)
|
||||
continue;
|
||||
if(pal_resource.cg[circuit->cg_id].attrib.protocol != PROTO_ISDN)
|
||||
continue;
|
||||
if(circuit->attrib.link_id == link_id)
|
||||
return &pal_resource.cg[circuit->cg_id];
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const pal_cg_struct *pal_sip_find_cg(char *domain, char *their_domain)
|
||||
{
|
||||
int i;
|
||||
pal_cg_struct *cg;
|
||||
|
||||
for(i = 0; i < PAL_MAX_CG; i++)
|
||||
{
|
||||
cg = &pal_resource.cg[i];
|
||||
if(cg->enable == 0)
|
||||
continue;
|
||||
if(cg->attrib.protocol != PROTO_SIP)
|
||||
continue;
|
||||
if((strcmp(cg->attrib.local_domain, domain) == 0) && \
|
||||
(strcmp(cg->attrib.dest_domain, their_domain) == 0))
|
||||
return cg;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* Use "locate" when received primitive from upper layer
|
||||
* Use "find" when received message from network
|
||||
*/
|
||||
const pal_circuit_struct *pal_locate_circuit(u32 cg_id, u32 cic)
|
||||
{
|
||||
int i;
|
||||
pal_circuit_struct *circuit;
|
||||
circuit_attrib_struct *attrib;
|
||||
|
||||
for(i = 0; i < PAL_MAX_CIRCUIT; i++)
|
||||
{
|
||||
circuit = &pal_resource.circuit[i];
|
||||
if(circuit->cg_id != cg_id)
|
||||
continue;
|
||||
attrib = &circuit->attrib;
|
||||
if((cic >= attrib->head_cic) && (cic < attrib->head_cic+attrib->cic_range))
|
||||
return circuit;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const pal_circuit_struct *pal_ss7_find_circuit(u8 ni, u32 dpc, u32 opc, u32 cic)
|
||||
{
|
||||
const pal_cg_struct *cg;
|
||||
|
||||
if((cg = pal_ss7_find_cg(ni, dpc, opc)) == NULL)
|
||||
return NULL;
|
||||
return pal_locate_circuit(cg->id, cic);
|
||||
}
|
||||
|
||||
const pal_circuit_struct *pal_isdn_find_circuit(u32 link_id, u32 cic)
|
||||
{
|
||||
const pal_cg_struct *cg;
|
||||
|
||||
if((cg = pal_isdn_find_cg(link_id)) == NULL)
|
||||
return NULL;
|
||||
return pal_locate_circuit(cg->id, cic);
|
||||
}
|
||||
|
||||
const pal_circuit_struct *pal_isdn_find_circuit_of_link(u32 link_id)
|
||||
{
|
||||
int i;
|
||||
pal_circuit_struct *circuit;
|
||||
|
||||
for(i = 0; i < PAL_MAX_CIRCUIT; i++)
|
||||
{
|
||||
circuit = &pal_resource.circuit[i];
|
||||
if(circuit->enable == 0)
|
||||
continue;
|
||||
if(pal_resource.cg[circuit->cg_id].attrib.protocol != PROTO_ISDN)
|
||||
continue;
|
||||
if(circuit->attrib.link_id == link_id)
|
||||
return circuit;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user