Allow different B data handler

Signed-off-by: Karsten Keil <kkeil@linux-pingi.de>
This commit is contained in:
Karsten Keil 2011-10-29 15:13:58 +02:00
parent 29a8d4961e
commit 7adb7b8017
7 changed files with 1190 additions and 1306 deletions

View File

@ -144,8 +144,7 @@ struct lController *get_lController(struct mApplication *app, int cont)
return lc;
}
void
SendMessage2Application(struct mApplication *appl, struct mc_buf *mc)
void SendMessage2Application(struct mApplication *appl, struct mc_buf *mc)
{
int ret;
@ -154,8 +153,7 @@ SendMessage2Application(struct mApplication *appl, struct mc_buf *mc)
wprint("Message send error len=%d ret=%d - %s\n", mc->len, ret, strerror(errno));
}
void
SendCmsg2Application(struct mApplication *appl, struct mc_buf *mc)
void SendCmsg2Application(struct mApplication *appl, struct mc_buf *mc)
{
int ret;
@ -169,8 +167,7 @@ SendCmsg2Application(struct mApplication *appl, struct mc_buf *mc)
capi20_cmd2str(mc->rb[4], mc->rb[5]), CAPIMSG_CONTROL(mc->rb), mc->len, ret);
}
void
SendCmsgAnswer2Application(struct mApplication *appl, struct mc_buf *mc, __u16 Info)
void SendCmsgAnswer2Application(struct mApplication *appl, struct mc_buf *mc, __u16 Info)
{
capi_cmsg_answer(&mc->cmsg);
mc->cmsg.Info = Info;
@ -179,8 +176,7 @@ SendCmsgAnswer2Application(struct mApplication *appl, struct mc_buf *mc, __u16 I
#define CapiFacilityNotSupported 0x300b
static int
FacilityMessage(struct mApplication *appl, struct pController *pc, struct mc_buf *mc)
static int FacilityMessage(struct mApplication *appl, struct pController *pc, struct mc_buf *mc)
{
int ret = CapiNoError;
struct mPLCI *plci;
@ -398,4 +394,3 @@ int PutMessageApplication(struct mApplication *appl, struct mc_buf *mc)
SendCmsgAnswer2Application(appl, mc, ret);
return ret;
}

View File

@ -31,7 +31,6 @@
#define DEF_CONFIG_FILE "/etc/capi20.conf"
#endif
typedef enum {
PIT_None = 0,
PIT_mISDNmain,
@ -75,8 +74,7 @@ void usage(void)
fprintf(stderr, "\n");
}
int
opt_parse(int ac, char *av[])
int opt_parse(int ac, char *av[])
{
int c;
@ -189,12 +187,14 @@ static int read_config_file(char *name)
continue;
}
if (contr < 0 || contr > 126) {
fprintf(stderr, "Invalid controller nr (%d) in config file %s, line %d: %s\n", contr + 1, name, lnr, line);
fprintf(stderr, "Invalid controller nr (%d) in config file %s, line %d: %s\n", contr + 1, name,
lnr, line);
nr_controller = -2;
goto err;
}
if (capicontr < 1 || capicontr > 127) {
fprintf(stderr, "Invalid capi controller nr (%d) in config file %s, line %d: %s\n", capicontr, name, lnr, line);
fprintf(stderr, "Invalid capi controller nr (%d) in config file %s, line %d: %s\n", capicontr,
name, lnr, line);
nr_controller = -3;
goto err;
}
@ -347,8 +347,7 @@ struct BInstance *ControllerSelChannel(struct pController *pc, int nr, int proto
bi = pc->BInstances + nr;
if (bi->usecnt) {
/* for now only one user allowed - this is not sufficient for X25 */
wprint("Request for channel number %d on controller %d but channel already in use\n",
nr, pc->profile.ncontroller);
wprint("Request for channel number %d on controller %d but channel already in use\n", nr, pc->profile.ncontroller);
return NULL;
} else {
bi->usecnt++;
@ -357,7 +356,7 @@ struct BInstance *ControllerSelChannel(struct pController *pc, int nr, int proto
return bi;
}
int OpenBInstance(struct BInstance *bi, struct lPLCI *lp)
int OpenBInstance(struct BInstance *bi, struct lPLCI *lp, BDataTrans_t *fromd)
{
int sk;
int ret;
@ -402,12 +401,23 @@ int OpenBInstance(struct BInstance *bi, struct lPLCI *lp)
ret = 0;
bi->UpId = 0;
bi->DownId = 0;
bi->from_down = fromd;
}
}
return ret;
}
int CloseBInstance(struct BInstance *bi) {
static int dummy_btrans(struct BInstance *bi, struct mc_buf *mc)
{
struct mISDNhead *hh = (struct mISDNhead *)mc->rb;
wprint("Controller%d ch%d: Got %s id %x - but %s called\n", bi->pc->profile.ncontroller, bi->nr,
_mi_msg_type2str(hh->prim), hh->id, __func__);
return -EINVAL;
}
int CloseBInstance(struct BInstance *bi)
{
int ret = 0;
if (bi->usecnt) {
@ -422,6 +432,7 @@ int CloseBInstance(struct BInstance *bi) {
ncciReleaseLink(bi->nc);
bi->nc = NULL;
bi->lp = NULL;
bi->from_down = dummy_btrans;
} else {
wprint("BInstance %d not active\n", bi->nr);
ret = -1;
@ -434,7 +445,6 @@ int recvBchannel(int idx)
int ret;
struct BInstance *bi;
struct mc_buf *mc;
struct mISDNhead *hh;
mc = alloc_mc_buf();
if (!mc)
@ -458,32 +468,11 @@ int recvBchannel(int idx)
ret, mc->rb[0], mc->rb[1], mc->rb[2], mc->rb[3], mc->rb[4], mc->rb[5], mc->rb[6], mc->rb[7]);
ret = -EMSGSIZE;
}
if (ret < 0)
goto end;
if (ret > 0) {
mc->len = ret;
hh = (struct mISDNhead *)mc->rb;
switch(hh->prim) {
case PH_ACTIVATE_IND:
case PH_ACTIVATE_CNF:
case PH_DEACTIVATE_IND:
case PH_DEACTIVATE_CNF:
case DL_ESTABLISH_IND:
case DL_ESTABLISH_CNF:
case DL_RELEASE_IND:
case DL_RELEASE_CNF:
case PH_DATA_IND:
case PH_DATA_CNF:
case DL_DATA_IND:
case PH_CONTROL_IND:
case PH_CONTROL_CNF:
ret = recvB_L12(bi, hh->prim, mc);
break;
default:
iprint("Controller%d ch%d: Got %s (%x) id=%x len %d - not handled\n",
bi->pc->profile.ncontroller, bi->nr, _mi_msg_type2str(hh->prim),
hh->prim, hh->id, ret);
ret = bi->from_down(bi, mc);
}
end:
if (ret != 0) /* if message is not queued or freed */
free_mc_buf(mc);
return ret;
@ -548,13 +537,11 @@ static int l3_callback(struct mlayer3 *l3, unsigned int cmd, unsigned int pid, s
case MT_RESUME_REJECT:
case MT_NOTIFY:
if (!plci)
wprint("Controller %d - got %s but no PLCI found\n",
pc->profile.ncontroller, _mi_msg_type2str(cmd));
wprint("Controller %d - got %s but no PLCI found\n", pc->profile.ncontroller, _mi_msg_type2str(cmd));
break;
case MT_FREE:
if (!plci)
wprint("Controller %d - got %s but no PLCI found\n",
pc->profile.ncontroller, _mi_msg_type2str(cmd));
wprint("Controller %d - got %s but no PLCI found\n", pc->profile.ncontroller, _mi_msg_type2str(cmd));
else
plci->pid = MISDN_PID_NONE;
break;
@ -603,9 +590,11 @@ int ListenController(struct pController *pc)
if (!pc->l3) {
pc->l3 = open_layer3(pc->mNr, pc->L3Proto, pc->L3Flags, l3_callback, pc);
if (!pc->l3) {
eprint("Cannot open L3 for controller %d L3 protocol %x L3 flags %x\n", pc->mNr, pc->L3Proto, pc->L3Flags);
eprint("Cannot open L3 for controller %d L3 protocol %x L3 flags %x\n", pc->mNr, pc->L3Proto,
pc->L3Flags);
} else
dprint(MIDEBUG_CONTROLLER, "Controller %d l3 open for protocol %x L3 flags %x\n", pc->mNr, pc->L3Proto, pc->L3Flags);
dprint(MIDEBUG_CONTROLLER, "Controller %d l3 open for protocol %x L3 flags %x\n", pc->mNr,
pc->L3Proto, pc->L3Flags);
}
}
return 0;
@ -766,7 +755,6 @@ static void misdn_manufacturer_req(int fd, struct mc_buf *mc)
eprint("error send %d/%d - %s\n", ret, 10, strerror(errno));
}
static int main_recv(int fd, int idx)
{
int ret, len, cmd, dl;
@ -938,8 +926,7 @@ int main_loop(void)
close(mainpoll[i].fd);
res = del_mainpoll(mainpoll[i].fd);
if (res < 0) {
eprint("Cannot delete fd=%d from mainpoll result %d\n",
fd, res);
eprint("Cannot delete fd=%d from mainpoll result %d\n", fd, res);
} else
dprint(MIDEBUG_POLL, "Deleted fd=%d from mainpoll\n", fd);
}
@ -985,7 +972,6 @@ static int my_lib_debug(const char *file, int line, const char *func, int level,
return ret;
}
static int my_capilib_dbg(const char *file, int line, const char *func, const char *fmt, va_list va)
{
return my_lib_debug(file, line, func, 1, fmt, va);
@ -1058,8 +1044,7 @@ int main(int argc, char *argv[])
}
c = 0;
nb = 0;
while(c <= MISDN_MAX_CHANNEL + 1)
{
while (c <= MISDN_MAX_CHANNEL + 1) {
if (c <= MISDN_MAX_CHANNEL && test_channelmap(c, pc->devinfo.channelmap)) {
nb++;
pc->BImax = c;

View File

@ -13,9 +13,7 @@ enum {
ST_LISTEN_L_0_1,
ST_LISTEN_L_1,
ST_LISTEN_L_1_1,
}
const ST_LISTEN_COUNT = ST_LISTEN_L_1_1 + 1;
} const ST_LISTEN_COUNT = ST_LISTEN_L_1_1 + 1;
static char *str_st_listen[] = {
"ST_LISTEN_L_0",
@ -27,20 +25,16 @@ static char *str_st_listen[] = {
enum {
EV_LISTEN_REQ,
EV_LISTEN_CONF,
}
const EV_LISTEN_COUNT = EV_LISTEN_CONF + 1;
} const EV_LISTEN_COUNT = EV_LISTEN_CONF + 1;
static char *str_ev_listen[] = {
"EV_LISTEN_REQ",
"EV_LISTEN_CONF",
};
static struct Fsm listen_fsm =
{ 0, 0, 0, 0, 0 };
static struct Fsm listen_fsm = { 0, 0, 0, 0, 0 };
static void
listen_debug(struct FsmInst *fi, char *fmt, ...)
static void listen_debug(struct FsmInst *fi, char *fmt, ...)
{
char tmp[128];
char *p = tmp;
@ -50,16 +44,14 @@ listen_debug(struct FsmInst *fi, char *fmt, ...)
if (!fi->debug)
return;
va_start(args, fmt);
p += sprintf(p, "Controller%d ApplId %d listen ",
lc->Contr->profile.ncontroller, lc->Appl->AppId);
p += sprintf(p, "Controller%d ApplId %d listen ", lc->Contr->profile.ncontroller, lc->Appl->AppId);
p += vsprintf(p, fmt, args);
*p = 0;
dprint(MIDEBUG_STATES, "%s\n", tmp);
va_end(args);
}
static void
listen_req_l_x(struct FsmInst *fi, int event, void *arg, int state)
static void listen_req_l_x(struct FsmInst *fi, int event, void *arg, int state)
{
struct lController *lc = fi->userdata;
struct mc_buf *mc = arg;
@ -81,20 +73,17 @@ listen_req_l_x(struct FsmInst *fi, int event, void *arg, int state)
FsmEvent(&lc->listen_m, EV_LISTEN_CONF, mc);
}
static void
listen_req_l_0(struct FsmInst *fi, int event, void *arg)
static void listen_req_l_0(struct FsmInst *fi, int event, void *arg)
{
listen_req_l_x(fi, event, arg, ST_LISTEN_L_0_1);
}
static void
listen_req_l_1(struct FsmInst *fi, int event, void *arg)
static void listen_req_l_1(struct FsmInst *fi, int event, void *arg)
{
listen_req_l_x(fi, event, arg, ST_LISTEN_L_1_1);
}
static void
listen_conf_l_x_1(struct FsmInst *fi, int event, void *arg, int state)
static void listen_conf_l_x_1(struct FsmInst *fi, int event, void *arg, int state)
{
struct lController *lc = fi->userdata;
struct mc_buf *mc = arg;
@ -111,20 +100,17 @@ listen_conf_l_x_1(struct FsmInst *fi, int event, void *arg, int state)
SendCmsg2Application(lc->Appl, mc);
}
static void
listen_conf_l_0_1(struct FsmInst *fi, int event, void *arg)
static void listen_conf_l_0_1(struct FsmInst *fi, int event, void *arg)
{
listen_conf_l_x_1(fi, event, arg, ST_LISTEN_L_0);
}
static void
listen_conf_l_1_1(struct FsmInst *fi, int event, void *arg)
static void listen_conf_l_1_1(struct FsmInst *fi, int event, void *arg)
{
listen_conf_l_x_1(fi, event, arg, ST_LISTEN_L_1);
}
static struct FsmNode fn_listen_list[] =
{
static struct FsmNode fn_listen_list[] = {
{ST_LISTEN_L_0, EV_LISTEN_REQ, listen_req_l_0},
{ST_LISTEN_L_0_1, EV_LISTEN_CONF, listen_conf_l_0_1},
{ST_LISTEN_L_1, EV_LISTEN_REQ, listen_req_l_1},
@ -133,7 +119,6 @@ static struct FsmNode fn_listen_list[] =
const int FN_LISTEN_COUNT = sizeof(fn_listen_list) / sizeof(struct FsmNode);
struct lController *addlController(struct mApplication *app, struct pController *pc)
{
struct lController *lc, *old;
@ -173,8 +158,7 @@ void listenDestr(struct lController *lc)
{
}
int
listenRequest(struct lController *lc, struct mc_buf *mc)
int listenRequest(struct lController *lc, struct mc_buf *mc)
{
FsmEvent(&lc->listen_m, EV_LISTEN_REQ, mc);
free_mc_buf(mc);
@ -183,8 +167,7 @@ listenRequest(struct lController *lc, struct mc_buf *mc)
int listenHandle(struct lController *lc, uint16_t CIPValue)
{
if ((lc->CIPmask & 1) ||
(lc->CIPmask & (1 << CIPValue)))
if ((lc->CIPmask & 1) || (lc->CIPmask & (1 << CIPValue)))
return 1;
return 0;
}

View File

@ -25,7 +25,6 @@
static int lPLCILinkUp(struct lPLCI *);
static int lPLCILinkDown(struct lPLCI *);
// --------------------------------------------------------------------
// PLCI state machine
//
@ -49,9 +48,7 @@ enum {
ST_PLCI_P_5,
ST_PLCI_P_6,
ST_PLCI_P_RES,
}
const ST_PLCI_COUNT = ST_PLCI_P_RES + 1;
} const ST_PLCI_COUNT = ST_PLCI_P_RES + 1;
static char *str_st_plci[] = {
"ST_PLCI_P_0",
@ -112,9 +109,7 @@ enum {
EV_L3_REJECT_IND,
EV_PH_CONTROL_IND,
EV_AP_RELEASE,
}
const EV_PLCI_COUNT = EV_AP_RELEASE + 1;
} const EV_PLCI_COUNT = EV_AP_RELEASE + 1;
static char *str_ev_plci[] = {
"EV_AP_CONNECT_REQ",
@ -163,11 +158,9 @@ static char* str_ev_plci[] = {
"EV_AP_RELEASE",
};
static struct Fsm plci_fsm =
{ 0, 0, 0, 0, 0 };
static struct Fsm plci_fsm = { 0, 0, 0, 0, 0 };
static void
lPLCI_debug(struct FsmInst *fi, char *fmt, ...)
static void lPLCI_debug(struct FsmInst *fi, char *fmt, ...)
{
char tmp[128];
char *p = tmp;
@ -184,22 +177,17 @@ lPLCI_debug(struct FsmInst *fi, char *fmt, ...)
va_end(args);
}
static inline void
Send2Application(struct lPLCI *lp, struct mc_buf *mc)
static inline void Send2Application(struct lPLCI *lp, struct mc_buf *mc)
{
SendCmsg2Application(lp->lc->Appl, mc);
}
static inline void
lPLCICmsgHeader(struct lPLCI *lp, _cmsg *cmsg, __u8 cmd, __u8 subcmd)
static inline void lPLCICmsgHeader(struct lPLCI *lp, _cmsg * cmsg, __u8 cmd, __u8 subcmd)
{
capi_cmsg_header(cmsg, lp->lc->Appl->AppId, cmd, subcmd,
lp->lc->Appl->MsgId++, lp->plci);
capi_cmsg_header(cmsg, lp->lc->Appl->AppId, cmd, subcmd, lp->lc->Appl->MsgId++, lp->plci);
}
static void
lPLCIClearOtherApps(struct lPLCI *lp)
static void lPLCIClearOtherApps(struct lPLCI *lp)
{
struct lPLCI *o_lp;
struct mc_buf *mc = NULL;
@ -220,8 +208,7 @@ lPLCIClearOtherApps(struct lPLCI *lp)
free_mc_buf(mc);
}
static void
lPLCIInfoIndMsg(struct lPLCI *lp, uint32_t mask, unsigned char mt, struct mc_buf *arg)
static void lPLCIInfoIndMsg(struct lPLCI *lp, uint32_t mask, unsigned char mt, struct mc_buf *arg)
{
struct mc_buf *mc = arg;
@ -241,8 +228,7 @@ lPLCIInfoIndMsg(struct lPLCI *lp, uint32_t mask, unsigned char mt, struct mc_bu
mc_clear_cmsg(mc);
}
static void
lPLCIInfoIndIE(struct lPLCI *lp, unsigned char ie, uint32_t mask, struct mc_buf *mc)
static void lPLCIInfoIndIE(struct lPLCI *lp, unsigned char ie, uint32_t mask, struct mc_buf *mc)
{
unsigned char **v_ie, *iep;
int pos;
@ -561,8 +547,7 @@ static int plci_parse_channel_id(struct lPLCI *lp, struct mc_buf *mc)
return ret;
}
static void
plci_connect_req(struct FsmInst *fi, int event, void *arg)
static void plci_connect_req(struct FsmInst *fi, int event, void *arg)
{
struct lPLCI *lp = fi->userdata;
struct mPLCI *plci = lp->PLCI;
@ -595,8 +580,7 @@ answer:
FsmEvent(fi, EV_PI_CONNECT_CONF, mc);
}
static void
plci_connect_conf(struct FsmInst *fi, int event, void *arg)
static void plci_connect_conf(struct FsmInst *fi, int event, void *arg)
{
struct lPLCI *lp = fi->userdata;
struct mc_buf *mc = arg;
@ -611,8 +595,7 @@ plci_connect_conf(struct FsmInst *fi, int event, void *arg)
}
}
static void
plci_connect_ind(struct FsmInst *fi, int event, void *arg)
static void plci_connect_ind(struct FsmInst *fi, int event, void *arg)
{
FsmChangeState(fi, ST_PLCI_P_2);
Send2Application(fi->userdata, arg);
@ -653,8 +636,7 @@ static void plci_resume_req(struct FsmInst *fi, int event, void *arg)
plciL4L3(plci, MT_RESUME, arg);
}
static void
plci_alert_req(struct FsmInst *fi, int event, void *arg)
static void plci_alert_req(struct FsmInst *fi, int event, void *arg)
{
struct lPLCI *lp = fi->userdata;
struct mPLCI *plci = lp->PLCI;
@ -682,8 +664,7 @@ answer:
Send2Application(lp, mc);
}
static void
plci_connect_resp(struct FsmInst *fi, int event, void *arg)
static void plci_connect_resp(struct FsmInst *fi, int event, void *arg)
{
struct lPLCI *lp = fi->userdata;
struct mPLCI *plci = lp->PLCI;
@ -704,13 +685,27 @@ plci_connect_resp(struct FsmInst *fi, int event, void *arg)
}
// ignore, reject
switch (mc->cmsg.Reject) {
case 2: cause = 0x90; break; // normal call clearing
case 3: cause = 0x91; break; // user busy
case 4: cause = 0xac; break; // req circuit/channel not avail
case 5: cause = 0x9d; break; // fac rejected
case 6: cause = 0x86; break; // channel unacceptable
case 7: cause = 0xd8; break; // incompatible dest
case 8: cause = 0x9b; break; // dest out of order
case 2:
cause = 0x90;
break; // normal call clearing
case 3:
cause = 0x91;
break; // user busy
case 4:
cause = 0xac;
break; // req circuit/channel not avail
case 5:
cause = 0x9d;
break; // fac rejected
case 6:
cause = 0x86;
break; // channel unacceptable
case 7:
cause = 0xd8;
break; // incompatible dest
case 8:
cause = 0x9b;
break; // dest out of order
default:
if ((mc->cmsg.Reject & 0xff00) == 0x3400) {
cause = mc->cmsg.Reject & 0xff;
@ -747,8 +742,7 @@ plci_connect_resp(struct FsmInst *fi, int event, void *arg)
FsmEvent(&lp->plci_m, EV_PI_DISCONNECT_IND, mc);
}
static void
plci_connect_active_ind(struct FsmInst *fi, int event, void *arg)
static void plci_connect_active_ind(struct FsmInst *fi, int event, void *arg)
{
struct lPLCI *lp = fi->userdata;
@ -809,28 +803,24 @@ static void plci_resume_conf(struct FsmInst *fi, int event, void *arg)
Send2Application(lp, arg);
}
static void
plci_disconnect_ind(struct FsmInst *fi, int event, void *arg)
static void plci_disconnect_ind(struct FsmInst *fi, int event, void *arg)
{
FsmChangeState(fi, ST_PLCI_P_6);
Send2Application(fi->userdata, arg);
}
static void
plci_disconnect_resp(struct FsmInst *fi, int event, void *arg)
static void plci_disconnect_resp(struct FsmInst *fi, int event, void *arg)
{
FsmChangeState(fi, ST_PLCI_P_0);
lPLCI_free(fi->userdata);
}
static void
plci_appl_release(struct FsmInst *fi, int event, void *arg)
static void plci_appl_release(struct FsmInst *fi, int event, void *arg)
{
lPLCI_free(fi->userdata);
}
static void
plci_appl_release_disc(struct FsmInst *fi, int event, void *arg)
static void plci_appl_release_disc(struct FsmInst *fi, int event, void *arg)
{
struct lPLCI *lp = fi->userdata;
struct mPLCI *plci = lp->PLCI;
@ -857,8 +847,7 @@ plci_appl_release_disc(struct FsmInst *fi, int event, void *arg)
}
}
static void
plci_cc_setup_conf(struct FsmInst *fi, int event, void *arg)
static void plci_cc_setup_conf(struct FsmInst *fi, int event, void *arg)
{
struct lPLCI *lp = fi->userdata;
struct mc_buf *mc = arg;
@ -880,8 +869,7 @@ plci_cc_setup_conf(struct FsmInst *fi, int event, void *arg)
FsmEvent(fi, EV_PI_CONNECT_ACTIVE_IND, mc);
}
static void
plci_cc_setup_conf_err(struct FsmInst *fi, int event, void *arg)
static void plci_cc_setup_conf_err(struct FsmInst *fi, int event, void *arg)
{
struct lPLCI *lp = fi->userdata;
struct mc_buf *mc = arg;
@ -900,8 +888,7 @@ plci_cc_setup_conf_err(struct FsmInst *fi, int event, void *arg)
free_mc_buf(mc);
}
static void
plci_channel_err(struct FsmInst *fi, int event, void *arg)
static void plci_channel_err(struct FsmInst *fi, int event, void *arg)
{
struct lPLCI *lp = fi->userdata;
int cause;
@ -929,8 +916,7 @@ plci_channel_err(struct FsmInst *fi, int event, void *arg)
free_mc_buf(mc);
}
static void
plci_cc_setup_ind(struct FsmInst *fi, int event, void *arg)
static void plci_cc_setup_ind(struct FsmInst *fi, int event, void *arg)
{
struct lPLCI *lp = fi->userdata;
struct mc_buf *mc = arg;
@ -977,8 +963,7 @@ plci_cc_setup_ind(struct FsmInst *fi, int event, void *arg)
FsmEvent(&lp->plci_m, EV_PI_CONNECT_IND, mc);
}
static void
plci_cc_setup_compl_ind(struct FsmInst *fi, int event, void *arg)
static void plci_cc_setup_compl_ind(struct FsmInst *fi, int event, void *arg)
{
struct lPLCI *lp = fi->userdata;
struct mc_buf *mc = arg;
@ -996,8 +981,7 @@ plci_cc_setup_compl_ind(struct FsmInst *fi, int event, void *arg)
free_mc_buf(mc);
}
static void
plci_cc_disconnect_ind(struct FsmInst *fi, int event, void *arg)
static void plci_cc_disconnect_ind(struct FsmInst *fi, int event, void *arg)
{
struct lPLCI *lp = fi->userdata;
struct mc_buf *mc = arg;
@ -1020,8 +1004,7 @@ plci_cc_disconnect_ind(struct FsmInst *fi, int event, void *arg)
plciL4L3(lp->PLCI, MT_RELEASE, NULL);
}
static void
plci_cc_release_ind(struct FsmInst *fi, int event, void *arg)
static void plci_cc_release_ind(struct FsmInst *fi, int event, void *arg)
{
struct lPLCI *lp = fi->userdata;
struct mc_buf *mc = arg;
@ -1057,8 +1040,7 @@ plci_cc_release_ind(struct FsmInst *fi, int event, void *arg)
free_mc_buf(mc);
}
static void
plci_cc_notify_ind(struct FsmInst *fi, int event, void *arg)
static void plci_cc_notify_ind(struct FsmInst *fi, int event, void *arg)
{
struct lPLCI *lp = fi->userdata;
struct mc_buf *mc = arg;
@ -1096,8 +1078,7 @@ static void plci_hold_conf(struct FsmInst *fi, int event, void *arg)
FsmChangeState(fi, ST_PLCI_P_HELD);
}
static void
lPLCI_hold_reply(struct lPLCI *lp, uint16_t SuppServiceReason, void *arg)
static void lPLCI_hold_reply(struct lPLCI *lp, uint16_t SuppServiceReason, void *arg)
{
unsigned char tmp[10], *p;
struct mc_buf *mc = arg;
@ -1123,8 +1104,7 @@ lPLCI_hold_reply(struct lPLCI *lp, uint16_t SuppServiceReason, void *arg)
free_mc_buf(mc);
}
static void
plci_cc_hold_rej(struct FsmInst *fi, int event, void *arg)
static void plci_cc_hold_rej(struct FsmInst *fi, int event, void *arg)
{
struct lPLCI *lp = fi->userdata;
uint16_t SuppServiceReason;
@ -1145,8 +1125,7 @@ plci_cc_hold_rej(struct FsmInst *fi, int event, void *arg)
lPLCI_hold_reply(lp, SuppServiceReason, arg);
}
static void
plci_cc_hold_ack(struct FsmInst *fi, int event, void *arg)
static void plci_cc_hold_ack(struct FsmInst *fi, int event, void *arg)
{
struct lPLCI *lp = fi->userdata;
@ -1154,8 +1133,7 @@ plci_cc_hold_ack(struct FsmInst *fi, int event, void *arg)
lPLCILinkDown(lp);
}
static void
plci_cc_hold_ind(struct FsmInst *fi, int event, void *arg)
static void plci_cc_hold_ind(struct FsmInst *fi, int event, void *arg)
{
struct lPLCI *lp = fi->userdata;
@ -1173,8 +1151,7 @@ static void plci_retrieve_conf(struct FsmInst *fi, int event, void *arg)
Send2Application(lp, arg);
}
static void
lPLCI_retrieve_reply(struct lPLCI *lp, uint16_t SuppServiceReason, void *arg)
static void lPLCI_retrieve_reply(struct lPLCI *lp, uint16_t SuppServiceReason, void *arg)
{
unsigned char tmp[10], *p;
struct mc_buf *mc = arg;
@ -1203,8 +1180,7 @@ lPLCI_retrieve_reply(struct lPLCI *lp, uint16_t SuppServiceReason, void *arg)
free_mc_buf(mc);
}
static void
plci_cc_retrieve_rej(struct FsmInst *fi, int event, void *arg)
static void plci_cc_retrieve_rej(struct FsmInst *fi, int event, void *arg)
{
struct lPLCI *lp = fi->userdata;
uint16_t SuppServiceReason;
@ -1225,8 +1201,7 @@ plci_cc_retrieve_rej(struct FsmInst *fi, int event, void *arg)
lPLCI_retrieve_reply(lp, SuppServiceReason, arg);
}
static void
plci_cc_retrieve_ack(struct FsmInst *fi, int event, void *arg)
static void plci_cc_retrieve_ack(struct FsmInst *fi, int event, void *arg)
{
struct lPLCI *lp = fi->userdata;
struct mc_buf *mc = arg;
@ -1241,8 +1216,7 @@ plci_cc_retrieve_ack(struct FsmInst *fi, int event, void *arg)
}
}
static void
plci_cc_retrieve_ind(struct FsmInst *fi, int event, void *arg)
static void plci_cc_retrieve_ind(struct FsmInst *fi, int event, void *arg)
{
struct lPLCI *lp = fi->userdata;
struct mc_buf *mc = arg;
@ -1261,8 +1235,7 @@ plci_cc_retrieve_ind(struct FsmInst *fi, int event, void *arg)
plciL4L3(lp->PLCI, mt, NULL);
}
static void
lPLCI_suspend_reply(struct lPLCI *lp, uint16_t SuppServiceReason, void *arg)
static void lPLCI_suspend_reply(struct lPLCI *lp, uint16_t SuppServiceReason, void *arg)
{
unsigned char tmp[10], *p;
struct mc_buf *mc = arg;
@ -1290,8 +1263,7 @@ lPLCI_suspend_reply(struct lPLCI *lp, uint16_t SuppServiceReason, void *arg)
free_mc_buf(mc);
}
static void
plci_cc_suspend_err(struct FsmInst *fi, int event, void *arg)
static void plci_cc_suspend_err(struct FsmInst *fi, int event, void *arg)
{
struct lPLCI *lp = fi->userdata;
uint16_t SuppServiceReason;
@ -1312,8 +1284,7 @@ plci_cc_suspend_err(struct FsmInst *fi, int event, void *arg)
lPLCI_suspend_reply(lp, SuppServiceReason, arg);
}
static void
plci_cc_suspend_conf(struct FsmInst *fi, int event, void *arg)
static void plci_cc_suspend_conf(struct FsmInst *fi, int event, void *arg)
{
struct lPLCI *lp = fi->userdata;
struct mc_buf *mc = arg;
@ -1336,8 +1307,7 @@ plci_cc_suspend_conf(struct FsmInst *fi, int event, void *arg)
free_mc_buf(mc);
}
static void
plci_cc_resume_err(struct FsmInst *fi, int event, void *arg)
static void plci_cc_resume_err(struct FsmInst *fi, int event, void *arg)
{
struct lPLCI *lp = fi->userdata;
struct mc_buf *mc = arg;
@ -1367,8 +1337,7 @@ plci_cc_resume_err(struct FsmInst *fi, int event, void *arg)
free_mc_buf(mc);
}
static void
plci_cc_resume_conf(struct FsmInst *fi, int event, void *arg)
static void plci_cc_resume_conf(struct FsmInst *fi, int event, void *arg)
{
struct lPLCI *lp = fi->userdata;
struct mc_buf *mc = arg;
@ -1390,8 +1359,7 @@ plci_cc_resume_conf(struct FsmInst *fi, int event, void *arg)
FsmEvent(&lp->plci_m, EV_PI_RESUME_CONF, mc);
}
static void
plci_select_b_protocol_req(struct FsmInst *fi, int event, void *arg)
static void plci_select_b_protocol_req(struct FsmInst *fi, int event, void *arg)
{
struct lPLCI *lp = fi->userdata;
struct mc_buf *mc = arg;
@ -1418,8 +1386,7 @@ answer:
Send2Application(lp, arg);
}
static void
plci_info_req_overlap(struct FsmInst *fi, int event, void *arg)
static void plci_info_req_overlap(struct FsmInst *fi, int event, void *arg)
{
struct lPLCI *lp = fi->userdata;
struct mc_buf *mc = arg;
@ -1439,8 +1406,7 @@ plci_info_req_overlap(struct FsmInst *fi, int event, void *arg)
Send2Application(lp, mc);
}
static void
plci_cc_ph_control_ind(struct FsmInst *fi, int event, void *arg)
static void plci_cc_ph_control_ind(struct FsmInst *fi, int event, void *arg)
{
struct lPLCI *lp = fi->userdata;
struct mc_buf *mc = arg;
@ -1461,14 +1427,12 @@ plci_cc_ph_control_ind(struct FsmInst *fi, int event, void *arg)
}
}
static void
plci_info_req(struct FsmInst *fi, int event, void *arg)
static void plci_info_req(struct FsmInst *fi, int event, void *arg)
{
// FIXME handle INFO CONF
}
static struct FsmNode fn_plci_list[] =
{
static struct FsmNode fn_plci_list[] = {
{ST_PLCI_P_0, EV_AP_CONNECT_REQ, plci_connect_req},
{ST_PLCI_P_0, EV_PI_CONNECT_IND, plci_connect_ind},
{ST_PLCI_P_0, EV_AP_RESUME_REQ, plci_resume_req},
@ -1562,8 +1526,7 @@ static struct FsmNode fn_plci_list[] =
const int FN_PLCI_COUNT = sizeof(fn_plci_list) / sizeof(struct FsmNode);
int
lPLCICreate(struct lPLCI **lpp, struct lController *lc, struct mPLCI *plci)
int lPLCICreate(struct lPLCI **lpp, struct lController *lc, struct mPLCI *plci)
{
struct lPLCI *lp;
@ -1617,19 +1580,17 @@ void lPLCI_free(struct lPLCI *lp)
free(lp);
}
void
lPLCIRelease(struct lPLCI *lp)
void lPLCIRelease(struct lPLCI *lp)
{
/* TODO clean NCCIs */
FsmEvent(&lp->plci_m, EV_AP_RELEASE, NULL);
}
static int
lPLCILinkUp(struct lPLCI *lp)
static int lPLCILinkUp(struct lPLCI *lp)
{
int proto = -1, ret = 0;
struct mISDNhead mh;
BDataTrans_t *from_down = NULL;
mh.id = 1;
mh.prim = 0;
@ -1639,16 +1600,6 @@ lPLCILinkUp(struct lPLCI *lp)
return -EINVAL;
}
/* handle DTMF TODO
if ((pid.protocol[2] == ISDN_PID_L2_B_TRANS) &&
(pid.protocol[1] == ISDN_PID_L1_B_64TRANS))
pid.protocol[2] = ISDN_PID_L2_B_TRANSDTMF;
*/
if (lp->Bprotocol.B3 > 23) {
eprint("wrong B3 prot %x\n", lp->Bprotocol.B3);
return 0x3003;
}
switch (lp->Bprotocol.B1) {
case 0: /* HDLC */
proto = ISDN_P_B_HDLC;
@ -1664,7 +1615,7 @@ lPLCILinkUp(struct lPLCI *lp)
}
break;
default:
wprint("wrong B1 prot %x\n", lp->Bprotocol.B3);
wprint("Unsupported B1 prot %x\n", lp->Bprotocol.B1);
ret = 0x3001;
break;
}
@ -1677,18 +1628,26 @@ lPLCILinkUp(struct lPLCI *lp)
case 1: /* trans */
break;
default:
wprint("wrong B1 prot %x\n", lp->Bprotocol.B3);
wprint("Unsupported B2 prot %x\n", lp->Bprotocol.B2);
ret = 0x3002;
break;
}
switch (lp->Bprotocol.B3) {
case 0: /* trans */
from_down = recvBdirect;
break;
default:
wprint("Unsupported B3 prot %x\n", lp->Bprotocol.B3);
ret = 0x3003;
break;
}
if (ret)
return ret;
if (proto == -1)
return 0x3003;
dprint(MIDEBUG_PLCI, "lPLCILinkUp B1(%x) B2(%x) B3(%x) ch(%d) proto(%x)\n",
lp->Bprotocol.B1, lp->Bprotocol.B2, lp->Bprotocol.B3,
lp->chid.nr, proto);
lp->Bprotocol.B1, lp->Bprotocol.B2, lp->Bprotocol.B3, lp->chid.nr, proto);
/*
capidebug(CAPI_DBG_PLCI, "lPLCILinkUp B1cfg(%d) B2cfg(%d) B3cfg(%d) maxplen(%d)",
lp->Bprotocol.B1cfg[0], lp->Bprotocol.B2cfg[0],
@ -1703,7 +1662,7 @@ lPLCILinkUp(struct lPLCI *lp)
}
dprint(MIDEBUG_PLCI, "lPLCILinkUp lp->link(%p)\n", lp->BIlink);
/* TODO open the B-channel */
if (!OpenBInstance(lp->BIlink, lp)) {
if (!OpenBInstance(lp->BIlink, lp, from_down)) {
if (!lp->PLCI->outgoing) {
ret = send(lp->BIlink->fd, &mh, 8, 0);
if (ret < 0) {
@ -1720,8 +1679,7 @@ lPLCILinkUp(struct lPLCI *lp)
return ret;
}
struct mNCCI *
getNCCI4addr(struct lPLCI *lp, uint32_t addr, int mode)
struct mNCCI *getNCCI4addr(struct lPLCI *lp, uint32_t addr, int mode)
{
struct mNCCI *ncci = NULL;
int cnt = 0;
@ -1750,8 +1708,8 @@ getNCCI4addr(struct lPLCI *lp, uint32_t addr, int mode)
return NULL;
}
void
lPLCIDelNCCI(struct mNCCI *ncci) {
void lPLCIDelNCCI(struct mNCCI *ncci)
{
struct lPLCI *lp = ncci->lp;
if (lp->Nccis != ncci) {
@ -1770,8 +1728,7 @@ lPLCIDelNCCI(struct mNCCI *ncci) {
}
}
void
lPLCI_l3l4(struct lPLCI *lp, int pr, struct mc_buf *mc)
void lPLCI_l3l4(struct lPLCI *lp, int pr, struct mc_buf *mc)
{
int ret;
@ -1965,8 +1922,7 @@ lPLCI_l3l4(struct lPLCI *lp, int pr, struct mc_buf *mc)
}
}
void
lPLCIGetCmsg(struct lPLCI *lp, struct mc_buf *mc)
void lPLCIGetCmsg(struct lPLCI *lp, struct mc_buf *mc)
{
int retval = 0;
@ -2049,14 +2005,12 @@ static int lPLCILinkDown(struct lPLCI *lp)
return 0;
}
int
lPLCIFacHoldReq(struct lPLCI *lp, struct FacReqParm *facReqParm, struct FacConfParm *facConfParm)
int lPLCIFacHoldReq(struct lPLCI *lp, struct FacReqParm *facReqParm, struct FacConfParm *facConfParm)
{
/* no parameter needed so we do not need a l3m */
if (FsmEvent(&lp->plci_m, EV_AP_HOLD_REQ, NULL)) {
// no routine
facConfParm->u.Info.SupplementaryServiceInfo =
CapiRequestNotAllowedInThisState;
facConfParm->u.Info.SupplementaryServiceInfo = CapiRequestNotAllowedInThisState;
return CapiMessageNotSupportedInCurrentState;
} else {
facConfParm->u.Info.SupplementaryServiceInfo = CapiNoError;
@ -2064,14 +2018,12 @@ lPLCIFacHoldReq(struct lPLCI *lp, struct FacReqParm *facReqParm, struct FacConfP
return CapiNoError;
}
int
lPLCIFacRetrieveReq(struct lPLCI *lp, struct FacReqParm *facReqParm, struct FacConfParm *facConfParm)
int lPLCIFacRetrieveReq(struct lPLCI *lp, struct FacReqParm *facReqParm, struct FacConfParm *facConfParm)
{
/* no parameter needed so we do not need a l3m */
if (FsmEvent(&lp->plci_m, EV_AP_RETRIEVE_REQ, NULL)) {
// no routine
facConfParm->u.Info.SupplementaryServiceInfo =
CapiRequestNotAllowedInThisState;
facConfParm->u.Info.SupplementaryServiceInfo = CapiRequestNotAllowedInThisState;
return CapiMessageNotSupportedInCurrentState;
} else {
facConfParm->u.Info.SupplementaryServiceInfo = CapiNoError;
@ -2079,8 +2031,7 @@ lPLCIFacRetrieveReq(struct lPLCI *lp, struct FacReqParm *facReqParm, struct FacC
return CapiNoError;
}
int
lPLCIFacSuspendReq(struct lPLCI *lp, struct FacReqParm *facReqParm, struct FacConfParm *facConfParm)
int lPLCIFacSuspendReq(struct lPLCI *lp, struct FacReqParm *facReqParm, struct FacConfParm *facConfParm)
{
unsigned char *CallId;
struct l3_msg *l3m;
@ -2098,8 +2049,7 @@ lPLCIFacSuspendReq(struct lPLCI *lp, struct FacReqParm *facReqParm, struct FacCo
if (FsmEvent(&lp->plci_m, EV_AP_SUSPEND_REQ, l3m)) {
// no routine
facConfParm->u.Info.SupplementaryServiceInfo =
CapiRequestNotAllowedInThisState;
facConfParm->u.Info.SupplementaryServiceInfo = CapiRequestNotAllowedInThisState;
free_l3_msg(l3m);
return CapiMessageNotSupportedInCurrentState;
} else {
@ -2108,8 +2058,7 @@ lPLCIFacSuspendReq(struct lPLCI *lp, struct FacReqParm *facReqParm, struct FacCo
return CapiNoError;
}
int
lPLCIFacResumeReq(struct lPLCI *lp, struct FacReqParm *facReqParm, struct FacConfParm *facConfParm)
int lPLCIFacResumeReq(struct lPLCI *lp, struct FacReqParm *facReqParm, struct FacConfParm *facConfParm)
{
__u8 *CallId;
struct l3_msg *l3m;
@ -2149,7 +2098,6 @@ void init_lPLCI_fsm(void)
FsmNew(&plci_fsm, fn_plci_list, FN_PLCI_COUNT);
}
void free_lPLCI_fsm(void)
{
FsmFree(&plci_fsm);

View File

@ -38,6 +38,7 @@ struct lPLCI;
struct mNCCI;
struct pController;
struct lController;
struct BInstance;
struct Bprotocol {
uint16_t B1;
@ -48,6 +49,8 @@ struct Bprotocol {
unsigned char B3cfg[80];
};
typedef int (BDataTrans_t)(struct BInstance *, struct mc_buf *);
struct BInstance {
int nr;
int usecnt;
@ -58,9 +61,10 @@ struct BInstance {
struct pController *pc;
struct lPLCI *lp;
struct mNCCI *nc;
BDataTrans_t *from_down;
};
int OpenBInstance(struct BInstance *, struct lPLCI *);
int OpenBInstance(struct BInstance *, struct lPLCI *, BDataTrans_t *);
int CloseBInstance(struct BInstance *);
struct capi_profile {
@ -118,7 +122,6 @@ struct lController *addlController(struct mApplication *, struct pController *);
void rm_lController(struct lController *lc);
int listenRequest(struct lController *, struct mc_buf *);
struct mApplication {
struct mApplication *next;
int refc; /* refcount */
@ -246,11 +249,10 @@ void free_ncci_fsm(void);
struct mNCCI *ncciCreate(struct lPLCI *);
void ncciFree(struct mNCCI *);
int ncciSendMessage(struct mNCCI *, uint8_t, uint8_t, struct mc_buf *);
int recvB_L12(struct BInstance *, int, struct mc_buf *);
int recvBdirect(struct BInstance *, struct mc_buf *);
void ncciReleaseLink(struct mNCCI *);
void ncciDel_lPlci(struct mNCCI *);
#define MC_BUF_ALLOC(a) if (!(a = alloc_mc_buf())) {eprint("Cannot allocate mc_buff\n");return;}
#define CMSGCMD(cm) CAPICMD((cm)->Command, (cm)->Subcommand)
@ -263,7 +265,6 @@ void ncciDel_lPlci(struct mNCCI *);
#define MC_DEBUG_NCCI 0x10
#define MC_DEBUG_NCCI_DATA 0x20
#define MIDEBUG_POLL (MC_DEBUG_POLL << 24)
#define MIDEBUG_CONTROLLER (MC_DEBUG_CONTROLLER << 24)
#define MIDEBUG_STATES (MC_DEBUG_STATES << 24)

View File

@ -20,7 +20,6 @@
#include "mc_buffer.h"
#include <mISDN/q931.h>
struct mPLCI *new_mPLCI(struct pController *pc, int pid, struct lPLCI *lp)
{
struct mPLCI *plci;
@ -128,8 +127,7 @@ static void plciHandleSetupInd(struct mPLCI *plci, int pr, struct mc_buf *mc)
CIPValue = q931CIPValue(mc);
pc = plci->pc;
CIPmask = 1 << CIPValue;
dprint(MIDEBUG_PLCI, "PLCI %04x: Check CIPvalue %d (%08x) with CIPmask %08x\n",
plci->plci, CIPValue, CIPmask, pc->CIPmask);
dprint(MIDEBUG_PLCI, "PLCI %04x: Check CIPvalue %d (%08x) with CIPmask %08x\n", plci->plci, CIPValue, CIPmask, pc->CIPmask);
if (CIPValue && ((CIPmask & pc->CIPmask) || (pc->CIPmask & 1))) {
/* at least one Application is listen for this service */
lc = pc->lClist;
@ -178,8 +176,7 @@ int plci_l3l4(struct mPLCI *plci, int pr, struct l3_msg *l3m)
mc = alloc_mc_buf();
if (!mc) {
wprint("PLCI %04x: Cannot allocate mc_buf for %s\n",
plci->plci, _mi_msg_type2str(pr));
wprint("PLCI %04x: Cannot allocate mc_buf for %s\n", plci->plci, _mi_msg_type2str(pr));
return -ENOMEM;
}
mc->l3m = l3m;
@ -252,8 +249,12 @@ struct lPLCI *get_lPLCI4Id(struct mPLCI *plci, uint16_t appId)
struct mPLCI *getPLCI4pid(struct pController *pc, int pid)
{
struct mPLCI *plci = pc->plciL;
struct mPLCI *plci;
if (pc)
plci = pc->plciL;
else
plci = NULL;
while (plci) {
if (plci->pid == pid)
break;
@ -264,8 +265,12 @@ struct mPLCI *getPLCI4pid(struct pController *pc, int pid)
struct mPLCI *getPLCI4Id(struct pController *pc, uint32_t id)
{
struct mPLCI *plci = pc->plciL;
struct mPLCI *plci;
if (pc)
plci = pc->plciL;
else
plci = NULL;
while (plci) {
if (plci->plci == id)
break;
@ -274,8 +279,7 @@ struct mPLCI *getPLCI4Id(struct pController *pc, uint32_t id)
return plci;
}
int
plciL4L3(struct mPLCI *plci, int mt, struct l3_msg *l3m)
int plciL4L3(struct mPLCI *plci, int mt, struct l3_msg *l3m)
{
int ret;

View File

@ -40,9 +40,7 @@ enum {
ST_NCCI_N_3,
ST_NCCI_N_4,
ST_NCCI_N_5,
}
const ST_NCCI_COUNT = ST_NCCI_N_5 + 1;
} const ST_NCCI_COUNT = ST_NCCI_N_5 + 1;
static char *str_st_ncci[] = {
"ST_NCCI_N_0",
@ -80,9 +78,7 @@ enum {
EV_DL_DOWN_IND,
EV_NC_LINKDOWN,
EV_AP_RELEASE,
}
const EV_NCCI_COUNT = EV_AP_RELEASE + 1;
} const EV_NCCI_COUNT = EV_AP_RELEASE + 1;
static char *str_ev_ncci[] = {
"EV_AP_CONNECT_B3_REQ",
@ -115,8 +111,7 @@ static struct Fsm ncci_fsm = { 0, 0, 0, 0, 0 };
static int ncciL4L3(struct mNCCI *ncci, uint32_t, int, int, void *, struct mc_buf *);
static void
ncci_debug(struct FsmInst *fi, char *fmt, ...)
static void ncci_debug(struct FsmInst *fi, char *fmt, ...)
{
char tmp[128];
char *p = tmp;
@ -133,21 +128,17 @@ ncci_debug(struct FsmInst *fi, char *fmt, ...)
va_end(args);
}
static inline void
Send2Application(struct mNCCI *ncci, struct mc_buf *mc)
static inline void Send2Application(struct mNCCI *ncci, struct mc_buf *mc)
{
SendCmsg2Application(ncci->appl, mc);
}
static inline void
ncciCmsgHeader(struct mNCCI *ncci, struct mc_buf *mc, __u8 cmd, __u8 subcmd)
static inline void ncciCmsgHeader(struct mNCCI *ncci, struct mc_buf *mc, __u8 cmd, __u8 subcmd)
{
capi_cmsg_header(&mc->cmsg, ncci->appl->AppId, cmd, subcmd,
ncci->appl->MsgId++, ncci->ncci);
capi_cmsg_header(&mc->cmsg, ncci->appl->AppId, cmd, subcmd, ncci->appl->MsgId++, ncci->ncci);
}
static void
ncci_connect_b3_req(struct FsmInst *fi, int event, void *arg)
static void ncci_connect_b3_req(struct FsmInst *fi, int event, void *arg)
{
struct mNCCI *ncci = fi->userdata;
struct mc_buf *mc = arg;
@ -161,16 +152,14 @@ ncci_connect_b3_req(struct FsmInst *fi, int event, void *arg)
FsmEvent(fi, EV_NC_CONNECT_B3_CONF, mc);
}
static void
ncci_connect_b3_ind(struct FsmInst *fi, int event, void *arg)
static void ncci_connect_b3_ind(struct FsmInst *fi, int event, void *arg)
{
// from DL_ESTABLISH
FsmChangeState(fi, ST_NCCI_N_1);
Send2Application(fi->userdata, arg);
}
static void
ncci_connect_b3_resp(struct FsmInst *fi, int event, void *arg)
static void ncci_connect_b3_resp(struct FsmInst *fi, int event, void *arg)
{
struct mNCCI *ncci = fi->userdata;
struct mc_buf *mc = arg;
@ -188,8 +177,7 @@ ncci_connect_b3_resp(struct FsmInst *fi, int event, void *arg)
FsmEvent(&ncci->ncci_m, event, mc);
}
static void
ncci_connect_b3_conf(struct FsmInst *fi, int event, void *arg)
static void ncci_connect_b3_conf(struct FsmInst *fi, int event, void *arg)
{
struct mNCCI *ncci = fi->userdata;
struct mc_buf *mc = arg;
@ -207,8 +195,7 @@ ncci_connect_b3_conf(struct FsmInst *fi, int event, void *arg)
}
}
static void
ncci_disconnect_b3_req(struct FsmInst *fi, int event, void *arg)
static void ncci_disconnect_b3_req(struct FsmInst *fi, int event, void *arg)
{
struct mNCCI *ncci = fi->userdata;
struct mc_buf *mc = arg;
@ -229,8 +216,7 @@ ncci_disconnect_b3_req(struct FsmInst *fi, int event, void *arg)
ncciL4L3(ncci, prim, 0, 0, NULL, NULL);
}
static void
ncci_disconnect_b3_conf(struct FsmInst *fi, int event, void *arg)
static void ncci_disconnect_b3_conf(struct FsmInst *fi, int event, void *arg)
{
struct mc_buf *mc = arg;
@ -240,8 +226,7 @@ ncci_disconnect_b3_conf(struct FsmInst *fi, int event, void *arg)
Send2Application(fi->userdata, mc);
}
static void
ncci_disconnect_b3_ind(struct FsmInst *fi, int event, void *arg)
static void ncci_disconnect_b3_ind(struct FsmInst *fi, int event, void *arg)
{
struct mNCCI *ncci = fi->userdata;
@ -249,15 +234,13 @@ ncci_disconnect_b3_ind(struct FsmInst *fi, int event, void *arg)
Send2Application(ncci, arg);
}
static void
ncci_disconnect_b3_resp(struct FsmInst *fi, int event, void *arg)
static void ncci_disconnect_b3_resp(struct FsmInst *fi, int event, void *arg)
{
FsmChangeState(fi, ST_NCCI_N_0);
ncciFree(fi->userdata);
}
static void
ncci_facility_req(struct FsmInst *fi, int event, void *arg)
static void ncci_facility_req(struct FsmInst *fi, int event, void *arg)
{
struct mNCCI *ncci = fi->userdata;
struct mc_buf *mc = arg;
@ -277,8 +260,7 @@ ncci_facility_req(struct FsmInst *fi, int event, void *arg)
mc->cmsg.Info = CapiIllMessageParmCoding;
} else if (p && p[0]) {
func = CAPIMSG_U16(p, 1);
ncci_debug(fi, "%s: p %02x %02x %02x func(%x)",
__FUNCTION__, p[0], p[1], p[2], func);
ncci_debug(fi, "%s: p %02x %02x %02x func(%x)", __FUNCTION__, p[0], p[1], p[2], func);
switch (func) {
case 1:
op = DTMF_TONE_START;
@ -299,8 +281,7 @@ ncci_facility_req(struct FsmInst *fi, int event, void *arg)
Send2Application(ncci, mc);
}
static void
ncci_manufacturer_req(struct FsmInst *fi, int event, void *arg)
static void ncci_manufacturer_req(struct FsmInst *fi, int event, void *arg)
{
struct mNCCI *ncci = fi->userdata;
struct mc_buf *mc = arg;
@ -310,7 +291,8 @@ ncci_manufacturer_req(struct FsmInst *fi, int event, void *arg)
uint8_t len;
uint16_t Info;
uint16_t vol;
} __attribute__((packed)) mcp = {2, CapiNoError, 0};
} __attribute__ ((packed)) mcp = {
2, CapiNoError, 0};
struct _manu_req_para {
uint8_t len;
@ -337,8 +319,7 @@ ncci_manufacturer_req(struct FsmInst *fi, int event, void *arg)
mcp.Info = CapiIllMessageParmCoding;
break;
}
op = (cmsg->Function == mISDN_MF_HANDSET_SETSPKVOLUME) ?
HW_POTS_SETSPKVOL : HW_POTS_SETMICVOL;
op = (cmsg->Function == mISDN_MF_HANDSET_SETSPKVOLUME) ? HW_POTS_SETSPKVOL : HW_POTS_SETMICVOL;
err = ncciL4L3(ncci, PH_CONTROL | REQUEST, op, 2, &mrp->vol, NULL);
if (err == -ENODEV)
mcp.Info = CapiSupplementaryServiceNotSupported;
@ -363,8 +344,7 @@ ncci_manufacturer_req(struct FsmInst *fi, int event, void *arg)
Send2Application(ncci, mc);
}
static void
ncci_connect_b3_active_ind(struct FsmInst *fi, int event, void *arg)
static void ncci_connect_b3_active_ind(struct FsmInst *fi, int event, void *arg)
{
struct mNCCI *ncci = fi->userdata;
int i;
@ -377,13 +357,11 @@ ncci_connect_b3_active_ind(struct FsmInst *fi, int event, void *arg)
Send2Application(ncci, arg);
}
static void
ncci_connect_b3_active_resp(struct FsmInst *fi, int event, void *arg)
static void ncci_connect_b3_active_resp(struct FsmInst *fi, int event, void *arg)
{
}
static void
ncci_n0_dl_establish_ind_conf(struct FsmInst *fi, int event, void *arg)
static void ncci_n0_dl_establish_ind_conf(struct FsmInst *fi, int event, void *arg)
{
struct mNCCI *ncci = fi->userdata;
@ -391,8 +369,7 @@ ncci_n0_dl_establish_ind_conf(struct FsmInst *fi, int event, void *arg)
FsmEvent(&ncci->ncci_m, EV_NC_CONNECT_B3_IND, arg);
}
static void
ncci_dl_establish_conf(struct FsmInst *fi, int event, void *arg)
static void ncci_dl_establish_conf(struct FsmInst *fi, int event, void *arg)
{
struct mNCCI *ncci = fi->userdata;
struct mc_buf *mc = arg;
@ -401,8 +378,7 @@ ncci_dl_establish_conf(struct FsmInst *fi, int event, void *arg)
FsmEvent(&ncci->ncci_m, EV_NC_CONNECT_B3_ACTIVE_IND, mc);
}
static void
ncci_dl_release_ind_conf(struct FsmInst *fi, int event, void *arg)
static void ncci_dl_release_ind_conf(struct FsmInst *fi, int event, void *arg)
{
struct mNCCI *ncci = fi->userdata;
struct mc_buf *mc = arg;
@ -411,8 +387,7 @@ ncci_dl_release_ind_conf(struct FsmInst *fi, int event, void *arg)
FsmEvent(&ncci->ncci_m, EV_NC_DISCONNECT_B3_IND, mc);
}
static void
ncci_linkdown(struct FsmInst *fi, int event, void *arg)
static void ncci_linkdown(struct FsmInst *fi, int event, void *arg)
{
struct mNCCI *ncci = fi->userdata;
struct mc_buf *mc = arg;
@ -421,8 +396,7 @@ ncci_linkdown(struct FsmInst *fi, int event, void *arg)
FsmEvent(&ncci->ncci_m, EV_NC_DISCONNECT_B3_IND, mc);
}
static void
ncci_dl_down_ind(struct FsmInst *fi, int event, void *arg)
static void ncci_dl_down_ind(struct FsmInst *fi, int event, void *arg)
{
struct mNCCI *ncci = fi->userdata;
struct mc_buf *mc = arg;
@ -432,15 +406,13 @@ ncci_dl_down_ind(struct FsmInst *fi, int event, void *arg)
FsmEvent(&ncci->ncci_m, EV_NC_DISCONNECT_B3_IND, mc);
}
static void
ncci_appl_release(struct FsmInst *fi, int event, void *arg)
static void ncci_appl_release(struct FsmInst *fi, int event, void *arg)
{
FsmChangeState(fi, ST_NCCI_N_0);
ncciFree(fi->userdata);
}
static void
ncci_appl_release_disc(struct FsmInst *fi, int event, void *arg)
static void ncci_appl_release_disc(struct FsmInst *fi, int event, void *arg)
{
struct mNCCI *ncci = fi->userdata;
int prim;
@ -449,8 +421,7 @@ ncci_appl_release_disc(struct FsmInst *fi, int event, void *arg)
ncciL4L3(ncci, prim, 0, 0, NULL, NULL);
}
static struct FsmNode fn_ncci_list[] =
{
static struct FsmNode fn_ncci_list[] = {
{ST_NCCI_N_0, EV_AP_CONNECT_B3_REQ, ncci_connect_b3_req},
{ST_NCCI_N_0, EV_NC_CONNECT_B3_IND, ncci_connect_b3_ind},
{ST_NCCI_N_0, EV_DL_ESTABLISH_CONF, ncci_n0_dl_establish_ind_conf},
@ -512,8 +483,8 @@ static struct FsmNode fn_ncci_list[] =
{ST_NCCI_N_5, EV_AP_DISCONNECT_B3_RESP, ncci_disconnect_b3_resp},
{ST_NCCI_N_5, EV_AP_RELEASE, ncci_appl_release},
};
const int FN_NCCI_COUNT = sizeof(fn_ncci_list)/sizeof(struct FsmNode);
const int FN_NCCI_COUNT = sizeof(fn_ncci_list) / sizeof(struct FsmNode);
static void initNCCIHeaders(struct mNCCI *nc)
{
@ -544,8 +515,7 @@ static void initNCCIHeaders(struct mNCCI *nc)
nc->down_iv[0].iov_len = sizeof(nc->down_header);
}
struct mNCCI *
ncciCreate(struct lPLCI *lp)
struct mNCCI *ncciCreate(struct lPLCI *lp)
{
struct mNCCI *nc, *old;
@ -607,8 +577,7 @@ ncciCreate(struct lPLCI *lp)
return nc;
}
void
ncciFree(struct mNCCI *ncci)
void ncciFree(struct mNCCI *ncci)
{
int i;
@ -623,15 +592,13 @@ ncciFree(struct mNCCI *ncci)
free(ncci);
}
void
ncciDel_lPlci(struct mNCCI *ncci)
void ncciDel_lPlci(struct mNCCI *ncci)
{
ncci->lp = NULL;
/* maybe we should release the NCCI here */
}
void
ncciReleaseLink(struct mNCCI *ncci)
void ncciReleaseLink(struct mNCCI *ncci)
{
/* this is normal shutdown on speech and other transparent protocols */
struct mc_buf *mc = alloc_mc_buf();
@ -642,7 +609,6 @@ ncciReleaseLink(struct mNCCI *ncci)
}
}
static void AnswerDataB3Req(struct mNCCI *ncci, struct mc_buf *mc, uint16_t Info)
{
uint16_t dh = CAPIMSG_U16(mc->rb, 18);
@ -748,8 +714,8 @@ static void SendDataB3Down(struct mNCCI *ncci, uint16_t len)
pthread_mutex_unlock(&ncci->lock);
return;
} else
dprint(MIDEBUG_NCCI_DATA, "NCCI %06x: send down %d bytes type %s id %d current oidx[%d] sent %d/%d\n", ncci->ncci, ret,
_mi_msg_type2str(ncci->down_header.prim), ncci->down_header.id, ncci->oidx,
dprint(MIDEBUG_NCCI_DATA, "NCCI %06x: send down %d bytes type %s id %d current oidx[%d] sent %d/%d\n", ncci->ncci,
ret, _mi_msg_type2str(ncci->down_header.prim), ncci->down_header.id, ncci->oidx,
ncci->xmit_handles[ncci->oidx].sent, ncci->xmit_handles[ncci->oidx].dlen);
ncci->dlbusy = 1;
if (ncci->flowmode == flmIndication) {
@ -922,7 +888,8 @@ static void ncciDataConf(struct mNCCI *ncci, struct mc_buf *mc)
free_mc_buf(mc);
return;
}
dprint(MIDEBUG_NCCI_DATA, "NCCI %06x: confirm xmit_handles[%d] pktid=%x handle=%d\n", ncci->ncci, i, hh->id, ncci->xmit_handles[i].DataHandle);
dprint(MIDEBUG_NCCI_DATA, "NCCI %06x: confirm xmit_handles[%d] pktid=%x handle=%d\n", ncci->ncci, i, hh->id,
ncci->xmit_handles[i].DataHandle);
free_mc_buf(mc);
mc = ncci->xmit_handles[i].pkt;
ncci->xmit_handles[i].pkt = NULL;
@ -934,8 +901,7 @@ static void ncciDataConf(struct mNCCI *ncci, struct mc_buf *mc)
return;
}
static void
ncciDataResp(struct mNCCI *ncci, struct mc_buf *mc)
static void ncciDataResp(struct mNCCI *ncci, struct mc_buf *mc)
{
int i;
uint16_t dh = CAPIMSG_RESP_DATAHANDLE(mc->rb);
@ -1002,7 +968,8 @@ static int ncciGetCmsg(struct mNCCI *ncci, uint8_t cmd, uint8_t subcmd, struct m
if (subcmd == CAPI_REQ)
retval = CapiMessageNotSupportedInCurrentState;
else { /* RESP */
wprint("NCCI %06x: Error Message %02x/%02x not supported in state %s\n", ncci->ncci, cmd, subcmd, str_st_ncci[ncci->ncci_m.state]);
wprint("NCCI %06x: Error Message %02x/%02x not supported in state %s\n", ncci->ncci, cmd, subcmd,
str_st_ncci[ncci->ncci_m.state]);
retval = CapiNoError;
}
}
@ -1011,7 +978,6 @@ static int ncciGetCmsg(struct mNCCI *ncci, uint8_t cmd, uint8_t subcmd, struct m
return retval;
}
int ncciSendMessage(struct mNCCI *ncci, uint8_t cmd, uint8_t subcmd, struct mc_buf *mc)
{
int ret = CapiNoError;
@ -1043,7 +1009,8 @@ int ncciSendMessage(struct mNCCI *ncci, uint8_t cmd, uint8_t subcmd, struct mc_b
ret = ncciDataReq(ncci, mc);
} else {
ret = CapiMessageNotSupportedInCurrentState;
wprint("NCCI %06x: DATA_B3_REQ - but but NCCI state %s\n", ncci->ncci, str_st_ncci[ncci->ncci_m.state]);
wprint("NCCI %06x: DATA_B3_REQ - but but NCCI state %s\n", ncci->ncci,
str_st_ncci[ncci->ncci_m.state]);
}
} else if (subcmd == CAPI_RESP) {
ncciDataResp(ncci, mc);
@ -1060,8 +1027,7 @@ int ncciSendMessage(struct mNCCI *ncci, uint8_t cmd, uint8_t subcmd, struct mc_b
return ret;
}
static int
ncciL4L3(struct mNCCI *ncci, uint32_t prim, int id, int len, void *data, struct mc_buf *mc)
static int ncciL4L3(struct mNCCI *ncci, uint32_t prim, int id, int len, void *data, struct mc_buf *mc)
{
struct mc_buf *loc = mc;
struct mISDNhead *hh;
@ -1071,7 +1037,8 @@ ncciL4L3(struct mNCCI *ncci, uint32_t prim, int id, int len, void *data, struct
if (!mc) {
loc = alloc_mc_buf();
if (!loc) {
eprint("NCCI %06x: prim %s id %x len %d cannot allocate buffer\n", ncci->ncci, _mi_msg_type2str(prim), id, len);
eprint("NCCI %06x: prim %s id %x len %d cannot allocate buffer\n", ncci->ncci, _mi_msg_type2str(prim), id,
len);
return -ENOMEM;
}
}
@ -1097,32 +1064,34 @@ ncciL4L3(struct mNCCI *ncci, uint32_t prim, int id, int len, void *data, struct
return ret;
}
int recvB_L12(struct BInstance *bi, int pr, struct mc_buf *mc)
int recvBdirect(struct BInstance *bi, struct mc_buf *mc)
{
struct mISDNhead *hh;
int ret = 0;
hh = (struct mISDNhead *)mc->rb;
switch(pr) {
// we're not using the Fsm for DL_DATA for performance reasons
switch (hh->prim) {
// we're not using the Fsm and _cmesg coding for DL_DATA for performance reasons
case PH_DATA_IND:
case DL_DATA_IND:
if (!bi->nc) {
wprint("Controller%d ch%d: Got %s but but no NCCI set\n", bi->pc->profile.ncontroller, bi->nr, _mi_msg_type2str(pr));
wprint("Controller%d ch%d: Got %s but but no NCCI set\n", bi->pc->profile.ncontroller, bi->nr,
_mi_msg_type2str(hh->prim));
ret = -EINVAL;
break;
}
if (bi->nc->ncci_m.state == ST_NCCI_N_ACT) {
ret = ncciDataInd(bi->nc, hh->prim, mc);
} else {
wprint("Controller%d ch%d: Got %s but but NCCI state %s\n",
bi->pc->profile.ncontroller, bi->nr, _mi_msg_type2str(pr), str_st_ncci[bi->nc->ncci_m.state]);
wprint("Controller%d ch%d: Got %s but but NCCI state %s\n", bi->pc->profile.ncontroller, bi->nr,
_mi_msg_type2str(hh->prim), str_st_ncci[bi->nc->ncci_m.state]);
ret = 1;
}
break;
case PH_DATA_CNF:
if (!bi->nc) {
wprint("Controller%d ch%d: Got %s but no NCCI set\n", bi->pc->profile.ncontroller, bi->nr, _mi_msg_type2str(pr));
wprint("Controller%d ch%d: Got %s but no NCCI set\n", bi->pc->profile.ncontroller, bi->nr,
_mi_msg_type2str(hh->prim));
ret = -EINVAL;
} else {
ncciDataConf(bi->nc, mc);
@ -1139,10 +1108,8 @@ int recvB_L12(struct BInstance *bi, int pr, struct mc_buf *mc)
}
}
FsmEvent(&bi->nc->ncci_m, EV_DL_ESTABLISH_CONF, mc);
/* send dummy to allow better buffering */
hh->prim = PH_DATA_IND;
mc->len = 136;
memset(&mc->rb[8], 128, 128);
mc->len = 520;
memset(&mc->rb[8], 0x55, 512);
ncciDataInd(bi->nc, hh->prim, mc);
ret = 0;
break;
@ -1161,7 +1128,8 @@ int recvB_L12(struct BInstance *bi, int pr, struct mc_buf *mc)
case DL_RELEASE_IND:
case PH_DEACTIVATE_IND:
if (!bi->nc) {
wprint("Controller%d ch%d: Got %s but but no NCCI set\n", bi->pc->profile.ncontroller, bi->nr, _mi_msg_type2str(pr));
wprint("Controller%d ch%d: Got %s but but no NCCI set\n", bi->pc->profile.ncontroller, bi->nr,
_mi_msg_type2str(hh->prim));
ret = -EINVAL;
break;
}
@ -1171,7 +1139,8 @@ int recvB_L12(struct BInstance *bi, int pr, struct mc_buf *mc)
case DL_RELEASE_CNF:
case PH_DEACTIVATE_CNF:
if (!bi->nc) {
wprint("Controller%d ch%d: Got %s but but no NCCI set\n", bi->pc->profile.ncontroller, bi->nr, _mi_msg_type2str(pr));
wprint("Controller%d ch%d: Got %s but but no NCCI set\n", bi->pc->profile.ncontroller, bi->nr,
_mi_msg_type2str(hh->prim));
ret = -EINVAL;
break;
}
@ -1182,23 +1151,23 @@ int recvB_L12(struct BInstance *bi, int pr, struct mc_buf *mc)
case PH_CONTROL_CNF:
/* handled by AppPlci */
if (!bi->lp) {
wprint("Controller%d ch%d: Got %s but but no lPLCI set\n", bi->pc->profile.ncontroller, bi->nr, _mi_msg_type2str(pr));
wprint("Controller%d ch%d: Got %s but but no lPLCI set\n", bi->pc->profile.ncontroller, bi->nr,
_mi_msg_type2str(hh->prim));
ret = -EINVAL;
} else {
lPLCI_l3l4(bi->lp, pr, mc);
lPLCI_l3l4(bi->lp, hh->prim, mc);
ret = 1;
}
break;
default:
wprint("Controller%d ch%d: Got %s (%x) id=%x len %d\n",
bi->pc->profile.ncontroller, bi->nr, _mi_msg_type2str(pr), pr, hh->id, mc->len);
wprint("Controller%d ch%d: Got %s (%x) id=%x len %d\n", bi->pc->profile.ncontroller, bi->nr,
_mi_msg_type2str(hh->prim), hh->prim, hh->id, mc->len);
ret = -EINVAL;
}
return ret;
}
void
init_ncci_fsm(void)
void init_ncci_fsm(void)
{
ncci_fsm.state_count = ST_NCCI_COUNT;
ncci_fsm.event_count = EV_NCCI_COUNT;
@ -1207,8 +1176,7 @@ init_ncci_fsm(void)
FsmNew(&ncci_fsm, fn_ncci_list, FN_NCCI_COUNT);
}
void
free_ncci_fsm(void)
void free_ncci_fsm(void)
{
FsmFree(&ncci_fsm);
}