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

@ -17,9 +17,9 @@
#include "m_capi.h"
#include "mc_buffer.h"
static struct mApplication *mApplications;
static struct mApplication *mApplications;
struct mApplication *RegisterApplication(uint16_t ApplId, uint32_t MaxB3Connection, uint32_t MaxB3Blks,uint32_t MaxSizeB3)
struct mApplication *RegisterApplication(uint16_t ApplId, uint32_t MaxB3Connection, uint32_t MaxB3Blks, uint32_t MaxSizeB3)
{
struct mApplication *appl, *old = mApplications;
@ -81,12 +81,12 @@ void ReleaseApplication(struct mApplication *appl)
close(appl->fd);
free(appl);
#if 0
int i, used = 0;
AppPlci_t **aplci_p = appl->AppPlcis;
int i, used = 0;
AppPlci_t **aplci_p = appl->AppPlcis;
if (test_and_set_bit(APPL_STATE_DESTRUCTOR, &appl->state)) {
// we are allready in this function
return(-EBUSY);
return (-EBUSY);
}
test_and_set_bit(APPL_STATE_RELEASE, &appl->state);
test_and_clear_bit(APPL_STATE_ACTIV, &appl->state);
@ -98,18 +98,18 @@ void ReleaseApplication(struct mApplication *appl)
for (i = 0; i < appl->maxplci; i++) {
if (*aplci_p) {
switch (who) {
case 4:
AppPlciDestr(*aplci_p);
*aplci_p = NULL;
break;
case 1:
case 2:
case 3:
AppPlciRelease(*aplci_p);
case 0:
if ((volatile AppPlci_t *)(*aplci_p))
used++;
break;
case 4:
AppPlciDestr(*aplci_p);
*aplci_p = NULL;
break;
case 1:
case 2:
case 3:
AppPlciRelease(*aplci_p);
case 0:
if ((volatile AppPlci_t *)(*aplci_p))
used++;
break;
}
}
aplci_p++;
@ -121,14 +121,14 @@ void ReleaseApplication(struct mApplication *appl)
list_add(&appl->head, &garbage_applications);
}
test_and_clear_bit(APPL_STATE_DESTRUCTOR, &appl->state);
return(-EBUSY);
return (-EBUSY);
}
list_del_init(&appl->head);
appl->maxplci = 0;
kfree(appl->AppPlcis);
appl->AppPlcis = NULL;
kfree(appl);
return(0);
return (0);
#endif
}
@ -144,18 +144,16 @@ 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;
int ret;
ret = send(appl->fd, mc->rb, mc->len, 0);
if (ret != mc->len)
wprint("Message send error len=%d ret=%d - %s\n", mc->len, ret, strerror(errno));
ret = send(appl->fd, mc->rb, mc->len, 0);
if (ret != mc->len)
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;
@ -165,12 +163,11 @@ SendCmsg2Application(struct mApplication *appl, struct mc_buf *mc)
if (ret != mc->len)
eprint("Message send error len=%d ret=%d - %s\n", mc->len, ret, strerror(errno));
else
dprint(MIDEBUG_NCCI_DATA, "Msg: %02x/%02x %s addr %x len %d/%d\n", mc->rb[4], mc->rb[5],
capi20_cmd2str(mc->rb[4], mc->rb[5]), CAPIMSG_CONTROL(mc->rb), mc->len, ret);
dprint(MIDEBUG_NCCI_DATA, "Msg: %02x/%02x %s addr %x len %d/%d\n", mc->rb[4], mc->rb[5],
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,52 +176,51 @@ 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;
struct lPLCI *lp;
struct mNCCI *ncci;
unsigned char tmp[64], *p;
int ret = CapiNoError;
struct mPLCI *plci;
struct lPLCI *lp;
struct mNCCI *ncci;
unsigned char tmp[64], *p;
p = tmp;
switch (mc->cmsg.FacilitySelector) {
#if 0
case 0x0000: // Handset
case 0x0000: // Handset
#endif
case 0x0001: // DTMF
dprint(MIDEBUG_CONTROLLER, "DTMF addr %06x\n", mc->cmsg.adr.adrNCCI);
plci = getPLCI4Id(pc, mc->cmsg.adr.adrPLCI & 0xFFFF);
lp = get_lPLCI4Id(plci, mc->cmsg.ApplId);
if (lp) {
ncci = getNCCI4addr(lp, mc->cmsg.adr.adrNCCI, GET_NCCI_PLCI);
if (ncci) {
ret = ncciSendMessage(ncci, mc->cmsg.Command, mc->cmsg.Subcommand, mc);
} else {
wprint("DTMF addr %06x NCCI not found\n", mc->cmsg.adr.adrNCCI);
ret = CapiIllController;
}
case 0x0001: // DTMF
dprint(MIDEBUG_CONTROLLER, "DTMF addr %06x\n", mc->cmsg.adr.adrNCCI);
plci = getPLCI4Id(pc, mc->cmsg.adr.adrPLCI & 0xFFFF);
lp = get_lPLCI4Id(plci, mc->cmsg.ApplId);
if (lp) {
ncci = getNCCI4addr(lp, mc->cmsg.adr.adrNCCI, GET_NCCI_PLCI);
if (ncci) {
ret = ncciSendMessage(ncci, mc->cmsg.Command, mc->cmsg.Subcommand, mc);
} else {
wprint("DTMF addr %06x lPLCI not found\n", mc->cmsg.adr.adrNCCI);
ret = CapiIllController;
}
break;
case 0x0003: // SupplementaryServices
// ret = SupplementaryFacilityReq(appl, mc);
capimsg_setu8(p, 0, 9);
capimsg_setu16(p, 1, 0);
capimsg_setu8(p, 3, 6);
capimsg_setu16(p, 4, 0);
capimsg_setu32(p, 6, 0);
mc->cmsg.FacilityConfirmationParameter = tmp;
SendCmsgAnswer2Application(appl, mc, ret);
free_mc_buf(mc);
ret = CapiNoError;
break;
default:
ret = CapiFacilityNotSupported;
break;
wprint("DTMF addr %06x NCCI not found\n", mc->cmsg.adr.adrNCCI);
ret = CapiIllController;
}
} else {
wprint("DTMF addr %06x lPLCI not found\n", mc->cmsg.adr.adrNCCI);
ret = CapiIllController;
}
break;
case 0x0003: // SupplementaryServices
// ret = SupplementaryFacilityReq(appl, mc);
capimsg_setu8(p, 0, 9);
capimsg_setu16(p, 1, 0);
capimsg_setu8(p, 3, 6);
capimsg_setu16(p, 4, 0);
capimsg_setu32(p, 6, 0);
mc->cmsg.FacilityConfirmationParameter = tmp;
SendCmsgAnswer2Application(appl, mc, ret);
free_mc_buf(mc);
ret = CapiNoError;
break;
default:
ret = CapiFacilityNotSupported;
break;
}
return ret;
}
@ -232,11 +228,11 @@ FacilityMessage(struct mApplication *appl, struct pController *pc, struct mc_buf
int PutMessageApplication(struct mApplication *appl, struct mc_buf *mc)
{
int id;
struct pController *pc;
struct lController *lc;
struct mPLCI *plci;
struct lPLCI *lp;
struct mNCCI *ncci;
struct pController *pc;
struct lController *lc;
struct mPLCI *plci;
struct lPLCI *lp;
struct mNCCI *ncci;
uint8_t cmd, subcmd;
int ret = CapiNoError;
@ -258,8 +254,8 @@ int PutMessageApplication(struct mApplication *appl, struct mc_buf *mc)
eprint("message %x controller for id %06x not found\n", cmd, id);
}
dprint(MIDEBUG_CONTROLLER, "ID: %06x cmd %02x/%02x %s\n", id, cmd, subcmd, capi20_cmd2str(cmd, subcmd));
switch(cmd) {
// for NCCI state machine
switch (cmd) {
// for NCCI state machine
case CAPI_DATA_B3:
case CAPI_CONNECT_B3_ACTIVE:
case CAPI_DISCONNECT_B3:
@ -273,8 +269,8 @@ int PutMessageApplication(struct mApplication *appl, struct mc_buf *mc)
ret = ncciSendMessage(ncci, cmd, subcmd, mc);
else {
wprint("Application%d: cmd %x (%s) plci %04x lplci %04x NCCI not found\n", appl->AppId, cmd,
capi20_cmd2str(mc->cmsg.Command, mc->cmsg.Subcommand),
plci ? plci->plci : 0xffff, lp ? lp->plci : 0xffff);
capi20_cmd2str(mc->cmsg.Command, mc->cmsg.Subcommand),
plci ? plci->plci : 0xffff, lp ? lp->plci : 0xffff);
ret = CapiIllController;
}
} else
@ -298,18 +294,18 @@ int PutMessageApplication(struct mApplication *appl, struct mc_buf *mc)
ret = ncciSendMessage(ncci, cmd, subcmd, mc);
else {
wprint("Application%d: cmd %x (%s) plci %04x lplci %04x NCCI not found\n", appl->AppId, cmd,
capi20_cmd2str(mc->cmsg.Command, mc->cmsg.Subcommand),
plci ? plci->plci : 0xffff, lp ? lp->plci : 0xffff);
capi20_cmd2str(mc->cmsg.Command, mc->cmsg.Subcommand),
plci ? plci->plci : 0xffff, lp ? lp->plci : 0xffff);
ret = CapiIllController;
}
break;
// for PLCI state machine
// for PLCI state machine
case CAPI_CONNECT:
case CAPI_INFO:
mcbuf_rb2cmsg(mc);
plci = getPLCI4Id(pc, mc->cmsg.adr.adrPLCI);
dprint(MIDEBUG_PLCI, "%s adrPLCI %06x plci:%04x ApplId %d\n", capi20_cmd2str(cmd, subcmd), mc->cmsg.adr.adrPLCI,
plci ? plci->plci : 0xffff, mc->cmsg.ApplId);
plci ? plci->plci : 0xffff, mc->cmsg.ApplId);
if (subcmd == CAPI_REQ) {
if (plci) {
lp = get_lPLCI4Id(plci, mc->cmsg.ApplId);
@ -317,7 +313,7 @@ int PutMessageApplication(struct mApplication *appl, struct mc_buf *mc)
ret = lPLCISendMessage(lp, mc);
else {
wprint("%s adrPLCI %06x plci:%04x ApplId %d no plci found\n", capi20_cmd2str(cmd, subcmd),
mc->cmsg.adr.adrPLCI, plci ? plci->plci : 0xffff, mc->cmsg.ApplId);
mc->cmsg.adr.adrPLCI, plci ? plci->plci : 0xffff, mc->cmsg.ApplId);
ret = CapiIllController;
}
} else {
@ -341,7 +337,7 @@ int PutMessageApplication(struct mApplication *appl, struct mc_buf *mc)
ret = lPLCISendMessage(lp, mc);
else {
wprint("%s adrPLCI %06x plci:%04x ApplId %d no plci found\n", capi20_cmd2str(cmd, subcmd),
mc->cmsg.adr.adrPLCI, plci ? plci->plci : 0xffff, mc->cmsg.ApplId);
mc->cmsg.adr.adrPLCI, plci ? plci->plci : 0xffff, mc->cmsg.ApplId);
ret = CapiIllController;
}
} else
@ -356,7 +352,7 @@ int PutMessageApplication(struct mApplication *appl, struct mc_buf *mc)
plci = getPLCI4Id(pc, mc->cmsg.adr.adrPLCI);
lp = get_lPLCI4Id(plci, mc->cmsg.ApplId);
dprint(MIDEBUG_PLCI, "adrPLCI %06x plci:%04x ApplId %d lp %p\n", mc->cmsg.adr.adrPLCI,
plci ? plci->plci : 0xffff, mc->cmsg.ApplId, lp);
plci ? plci->plci : 0xffff, mc->cmsg.ApplId, lp);
if (lp)
ret = lPLCISendMessage(lp, mc);
else
@ -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;
}
@ -277,7 +277,7 @@ static int del_mainpoll(int fd)
mainpoll[i].revents = 0;
mainpoll[i].fd = -1;
j = i;
switch(pollinfo[i].type) {
switch (pollinfo[i].type) {
default:
if (pollinfo[i].data)
free(pollinfo[i].data);
@ -287,7 +287,7 @@ static int del_mainpoll(int fd)
pollinfo[i].type = PIT_None;
break;
}
while(mainpoll_max && j == (mainpoll_max - 1) && mainpoll[j].fd == -1) {
while (mainpoll_max && j == (mainpoll_max - 1) && mainpoll[j].fd == -1) {
mainpoll_max--;
j--;
}
@ -326,29 +326,28 @@ struct BInstance *ControllerSelChannel(struct pController *pc, int nr, int proto
if (nr >= pc->BImax) {
wprint("Request for channel number %d but controller %d only has %d channels\n",
nr, pc->profile.ncontroller, pc->BImax);
nr, pc->profile.ncontroller, pc->BImax);
return NULL;
}
if (ISDN_P_B_START <= proto) {
pmask = 1 << (proto & ISDN_P_B_MASK);
if (!(pmask & pc->devinfo.Bprotocols)) {
wprint("Request for channel number %d on controller %d protocol 0x%02x not supported\n",
nr, pc->profile.ncontroller, proto);
nr, pc->profile.ncontroller, proto);
return NULL;
}
} else {
pmask = 1 << proto;
if (!(pmask & pc->devinfo.Dprotocols)) {
wprint("Request for channel number %d on controller %d protocol 0x%02x not supported\n",
nr, pc->profile.ncontroller, proto);
nr, pc->profile.ncontroller, proto);
return NULL;
}
}
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,18 +356,18 @@ 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;
struct sockaddr_mISDN addr;
int sk;
int ret;
struct sockaddr_mISDN addr;
sk = socket(PF_ISDN, SOCK_DGRAM, bi->proto);
if (sk < 0) {
wprint("Cannot open socket for BInstance %d on controller %d protocol 0x%02x - %s\n",
bi->nr, bi->pc->profile.ncontroller, bi->proto, strerror(errno));
bi->nr, bi->pc->profile.ncontroller, bi->proto, strerror(errno));
return -errno;
}
}
ret = fcntl(sk, F_SETFL, O_NONBLOCK);
if (ret < 0) {
@ -382,32 +381,43 @@ int OpenBInstance(struct BInstance *bi, struct lPLCI *lp)
addr.dev = bi->pc->mNr;
addr.channel = bi->nr;
ret = bind(sk, (struct sockaddr *) &addr, sizeof(addr));
ret = bind(sk, (struct sockaddr *)&addr, sizeof(addr));
if (ret < 0) {
ret = -errno;
wprint("Cannot bind socket for BInstance %d on controller %d (mISDN nr %d) protocol 0x%02x - %s\n",
bi->nr, bi->pc->profile.ncontroller, bi->pc->mNr, bi->proto, strerror(errno));
bi->nr, bi->pc->profile.ncontroller, bi->pc->mNr, bi->proto, strerror(errno));
close(sk);
} else {
bi->fd = sk;
ret = add_mainpoll(sk, PIT_Bchannel);
if (ret < 0) {
eprint("Error while adding mIsock to mainpoll (mainpoll_max %d)\n", mainpoll_max);
} else {
dprint(MIDEBUG_CONTROLLER, "Controller%d: Bchannel %d socket %d added to poll idx %d\n",
bi->pc->profile.ncontroller, bi->nr, sk, ret);
} else {
dprint(MIDEBUG_CONTROLLER, "Controller%d: Bchannel %d socket %d added to poll idx %d\n",
bi->pc->profile.ncontroller, bi->nr, sk, ret);
bi->fd = sk;
pollinfo[ret].data = bi;
bi->lp = 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,9 +432,10 @@ 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;
wprint("BInstance %d not active\n", bi->nr);
ret = -1;
}
return ret;
};
@ -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)
@ -451,40 +461,19 @@ int recvBchannel(int idx)
ret = -ECONNABORTED;
} else if (ret < 8) {
eprint("Short message read len %d (%02x%02x%02x%02x%02x%02x%02x%02x)\n",
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, 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 = -EBADMSG;
} else if (ret == MC_RB_SIZE) {
eprint("Message too big %d (%02x%02x%02x%02x%02x%02x%02x%02x)\n",
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, 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;
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);
if (ret > 0) {
mc->len = ret;
ret = bi->from_down(bi, mc);
}
end:
if (ret != 0) /* if message is not queued or freed */
if (ret != 0) /* if message is not queued or freed */
free_mc_buf(mc);
return ret;
}
@ -509,21 +498,21 @@ static int l3_callback(struct mlayer3 *l3, unsigned int cmd, unsigned int pid, s
int ret = 0;
dprint(MIDEBUG_CONTROLLER, "Controller %d - got %s (%x) from layer3 pid(%x) msg(%p)\n",
pc->profile.ncontroller, _mi_msg_type2str(cmd), cmd, pid, l3m);
pc->profile.ncontroller, _mi_msg_type2str(cmd), cmd, pid, l3m);
plci = getPLCI4pid(pc, pid);
switch(cmd) {
switch (cmd) {
case MT_SETUP:
if (plci) {
iprint("Controller %d - got %s but pid(%x) already in use\n",
pc->profile.ncontroller, _mi_msg_type2str(cmd), pid);
pc->profile.ncontroller, _mi_msg_type2str(cmd), pid);
break;
}
plci = new_mPLCI(pc, pid, NULL);
if (!plci) {
wprint("Controller %d - got %s but could not allocate new PLCI\n",
pc->profile.ncontroller, _mi_msg_type2str(cmd));
pc->profile.ncontroller, _mi_msg_type2str(cmd));
ret = -ENOMEM;
}
break;
@ -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;
@ -565,15 +552,15 @@ static int l3_callback(struct mlayer3 *l3, unsigned int cmd, unsigned int pid, s
break;
case MT_TIMEOUT:
iprint("Controller %d - got %s from layer3 pid(%x) msg(%p) plci(%04x)\n",
pc->profile.ncontroller, _mi_msg_type2str(cmd), pid, l3m, plci ? plci->plci : 0xffff);
pc->profile.ncontroller, _mi_msg_type2str(cmd), pid, l3m, plci ? plci->plci : 0xffff);
break;
case MT_ERROR :
case MT_ERROR:
wprint("Controller %d - got %s from layer3 pid(%x) msg(%p) plci(%04x)\n",
pc->profile.ncontroller, _mi_msg_type2str(cmd), pid, l3m, plci ? plci->plci : 0xffff);
pc->profile.ncontroller, _mi_msg_type2str(cmd), pid, l3m, plci ? plci->plci : 0xffff);
break;
default:
wprint("Controller %d - got %s (%x) from layer3 pid(%x) msg(%p) plci(%04x) - not handled\n",
pc->profile.ncontroller, _mi_msg_type2str(cmd), cmd, pid, l3m, plci ? plci->plci : 0xffff);
pc->profile.ncontroller, _mi_msg_type2str(cmd), cmd, pid, l3m, plci ? plci->plci : 0xffff);
ret = -EINVAL;
}
if (!ret && plci)
@ -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;
@ -635,7 +624,7 @@ static void get_profile(int fd, struct mc_buf *mc)
} else {
pc = get_cController(contr);
if (!pc) {
capimsg_setu16(mc->rb, 8, 0x2002); /* Illegal controller */
capimsg_setu16(mc->rb, 8, 0x2002); /* Illegal controller */
} else {
capimsg_setu16(mc->rb, 8, CapiNoError);
capimsg_setu16(mc->rb, 10, contr);
@ -731,10 +720,10 @@ static void get_capi_version(int fd, struct mc_buf *mc)
CAPIMSG_SETSUBCOMMAND(mc->rb, CAPI_CONF);
capimsg_setu16(mc->rb, 8, CapiNoError);
capimsg_setu32(mc->rb, 10, 2); /* major */
capimsg_setu32(mc->rb, 14, 0); /* minor */
capimsg_setu32(mc->rb, 18, 0); /* manu major */
capimsg_setu32(mc->rb, 22, 1); /* manu minor */
capimsg_setu32(mc->rb, 10, 2); /* major */
capimsg_setu32(mc->rb, 14, 0); /* minor */
capimsg_setu32(mc->rb, 18, 0); /* manu major */
capimsg_setu32(mc->rb, 22, 1); /* manu minor */
ret = send(fd, mc->rb, 26, 0);
if (ret != 26)
eprint("error send %d/%d - %s\n", ret, 26, strerror(errno));
@ -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;
@ -784,11 +772,11 @@ static int main_recv(int fd, int idx)
ret = -ECONNABORTED;
} else if (ret < 8) {
eprint("Short message read len %d (%02x%02x%02x%02x%02x%02x%02x%02x)\n",
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, 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 = -EBADMSG;
} else if (ret == MC_RB_SIZE) {
eprint("Message too big %d (%02x%02x%02x%02x%02x%02x%02x%02x)\n",
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, 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)
@ -841,7 +829,7 @@ static int main_recv(int fd, int idx)
break;
}
end:
if (ret != 0) /* if message is not queued or freed */
if (ret != 0) /* if message is not queued or freed */
free_mc_buf(mc);
return ret;
}
@ -860,16 +848,16 @@ int main_loop(void)
if (ret < 0) {
eprint("Error while adding mIsock to mainpoll (mainpoll_max %d)\n", mainpoll_max);
return -1;
} else
iprint("mIsock added to idx %d\n", ret);
} else
iprint("mIsock added to idx %d\n", ret);
ret = add_mainpoll(mCsock, PIT_CAPImain);
if (ret < 0) {
eprint("Error while adding mCsock to mainpoll (mainpoll_max %d)\n", mainpoll_max);
return -1;
} else
iprint("mCsock added to idx %d\n", ret);
} else
iprint("mCsock added to idx %d\n", ret);
while(running) {
while (running) {
ret = poll(mainpoll, mainpoll_max, -1);
if (ret < 0) {
wprint("Error on poll - %s\n", strerror(errno));
@ -879,7 +867,7 @@ int main_loop(void)
for (i = 0; i < mainpoll_max; i++) {
if (ret && mainpoll[i].revents) {
dprint(MIDEBUG_POLL, "Poll return %d for idx %d ev %x fd %d\n", ret,
i, mainpoll[i].revents, mainpoll[i].fd);
i, mainpoll[i].revents, mainpoll[i].fd);
switch (pollinfo[i].type) {
case PIT_Bchannel:
if (mainpoll[i].revents & POLLIN) {
@ -889,12 +877,12 @@ int main_loop(void)
ReleaseBchannel(i);
}
break;
case PIT_CAPImain: /* new connect */
case PIT_CAPImain: /* new connect */
if (mainpoll[i].revents & POLLIN) {
caddr.sun_family = AF_UNIX;
caddr.sun_path[0] = 0;
alen = sizeof(caddr);
nconn = accept(mCsock, (struct sockaddr*)&caddr, &alen);
nconn = accept(mCsock, (struct sockaddr *)&caddr, &alen);
if (nconn < 0) {
eprint("Error on accept - %s\n", strerror(errno));
} else {
@ -903,7 +891,7 @@ int main_loop(void)
if (idx < 0)
eprint("Cannot add fd=%d to mainpoll\n", nconn);
else
dprint(MIDEBUG_POLL, "nconn added to idx %d\n", idx);
dprint(MIDEBUG_POLL, "nconn added to idx %d\n", idx);
}
}
break;
@ -926,7 +914,7 @@ int main_loop(void)
res = del_mainpoll(mainpoll[i].fd);
if (res < 0) {
eprint("Cannot delete fd=%d from mainpoll result %d\n",
mainpoll[i].fd, res);
mainpoll[i].fd, res);
}
}
res = main_recv(mainpoll[i].fd, i);
@ -938,15 +926,14 @@ 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);
}
break;
default:
wprint("Unexpected poll event %x on fd %d type %d\n", mainpoll[i].revents,
mainpoll[i].fd, pollinfo[i].type);
mainpoll[i].fd, pollinfo[i].type);
break;
}
ret--;
@ -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);
@ -1048,7 +1034,7 @@ int main(int argc, char *argv[])
pc = &mI_Controller[i];
pc->mNr = i;
pc->devinfo.id = i;
pc->enable = 1; /* default all controllers are enabled */
pc->enable = 1; /* default all controllers are enabled */
pc->L3Proto = L3_PROTOCOL_DSS1_USER;
pc->L3Flags = 0;
ret = ioctl(mIsock, IMGETDEVINFO, &pc->devinfo);
@ -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;
@ -1079,7 +1064,7 @@ int main(int argc, char *argv[])
}
pc->profile.ncontroller = i + 1;
pc->profile.nbchannel = nb;
pc->profile.goptions = 1; /* internal controller */
pc->profile.goptions = 1; /* internal controller */
pc->profile.support1 = 0;
pc->profile.support2 = 0;
pc->profile.support3 = 0x01;
@ -1120,11 +1105,11 @@ retry_Csock:
}
mcaddr.sun_family = AF_UNIX;
sprintf(mcaddr.sun_path, MISDN_CAPI_SOCKET_PATH);
ret = bind(mCsock, (struct sockaddr*)&mcaddr, sizeof(mcaddr));
ret = bind(mCsock, (struct sockaddr *)&mcaddr, sizeof(mcaddr));
if (ret < 0) {
fprintf(stderr, "cannot bind socket to %s - %s\n", mcaddr.sun_path, strerror(errno));
if (errno == EADDRINUSE) { /* old socket file exist */
ret = connect(mCsock, (struct sockaddr*)&mcaddr, sizeof(mcaddr));
if (errno == EADDRINUSE) { /* old socket file exist */
ret = connect(mCsock, (struct sockaddr *)&mcaddr, sizeof(mcaddr));
if (ret < 0) {
/* seems the socket file is not in use */
ret = unlink(MISDN_CAPI_SOCKET_PATH);

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[] = {
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,28 +44,26 @@ 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;
struct lController *lc = fi->userdata;
struct mc_buf *mc = arg;
FsmChangeState(fi, state);
dprint(MIDEBUG_CONTROLLER, "Controller%d: set InfoMask %08x -> %08x\n",
lc->Contr->profile.ncontroller, lc->InfoMask, mc->cmsg.InfoMask);
lc->Contr->profile.ncontroller, lc->InfoMask, mc->cmsg.InfoMask);
dprint(MIDEBUG_CONTROLLER, "Controller%d: set CIPmask %08x -> %08x\n",
lc->Contr->profile.ncontroller, lc->CIPmask, mc->cmsg.CIPmask);
lc->Contr->profile.ncontroller, lc->CIPmask, mc->cmsg.CIPmask);
dprint(MIDEBUG_CONTROLLER, "Controller%d: set CIPmask2 %08x -> %08x\n",
lc->Contr->profile.ncontroller, lc->CIPmask2, mc->cmsg.CIPmask2);
lc->Contr->profile.ncontroller, lc->CIPmask2, mc->cmsg.CIPmask2);
lc->InfoMask = mc->cmsg.InfoMask;
lc->CIPmask = mc->cmsg.CIPmask;
lc->CIPmask2 = mc->cmsg.CIPmask2;
@ -81,27 +73,24 @@ 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;
struct lController *lc = fi->userdata;
struct mc_buf *mc = arg;
if (mc->cmsg.Info != CapiNoError) {
FsmChangeState(fi, state);
} else { // Info == 0
} else { // Info == 0
if (lc->CIPmask == 0) {
FsmChangeState(fi, ST_LISTEN_L_0);
} else {
@ -111,28 +100,24 @@ 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[] =
{
{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},
{ST_LISTEN_L_1_1, EV_LISTEN_CONF, listen_conf_l_1_1},
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},
{ST_LISTEN_L_1_1, EV_LISTEN_CONF, listen_conf_l_1_1},
};
const int FN_LISTEN_COUNT = sizeof(fn_listen_list)/sizeof(struct FsmNode);
const int FN_LISTEN_COUNT = sizeof(fn_listen_list) / sizeof(struct FsmNode);
struct lController *addlController(struct mApplication *app, struct pController *pc)
{
@ -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;
}

File diff suppressed because it is too large Load Diff

View File

@ -38,6 +38,7 @@ struct lPLCI;
struct mNCCI;
struct pController;
struct lController;
struct BInstance;
struct Bprotocol {
uint16_t B1;
@ -48,30 +49,33 @@ struct Bprotocol {
unsigned char B3cfg[80];
};
typedef int (BDataTrans_t)(struct BInstance *, struct mc_buf *);
struct BInstance {
int nr;
int nr;
int usecnt;
int proto;
int proto;
int fd;
uint16_t DownId; /* Ids for send down messages */
uint16_t UpId; /* Ids for send up messages */
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 {
uint16_t ncontroller; /* number of installed controller */
uint16_t nbchannel; /* number of B-Channels */
uint32_t goptions; /* global options */
uint32_t support1; /* B1 protocols support */
uint32_t support2; /* B2 protocols support */
uint32_t support3; /* B3 protocols support */
uint32_t reserved[6]; /* reserved */
uint32_t manu[5]; /* manufacturer specific information */
uint16_t ncontroller; /* number of installed controller */
uint16_t nbchannel; /* number of B-Channels */
uint32_t goptions; /* global options */
uint32_t support1; /* B1 protocols support */
uint32_t support2; /* B2 protocols support */
uint32_t support3; /* B3 protocols support */
uint32_t reserved[6]; /* reserved */
uint32_t manu[5]; /* manufacturer specific information */
};
/* physical controller access */
@ -87,7 +91,7 @@ struct pController {
struct mPLCI *plciL; /* List of PLCIs */
int appCnt;
int BImax; /* Nr of BInstances */
struct BInstance *BInstances; /* Array of BInstances [0 ... BImax - 1] */
struct BInstance *BInstances; /* Array of BInstances [0 ... BImax - 1] */
uint32_t InfoMask; /* Listen info mask all active applications */
uint32_t CIPmask; /* Listen CIP mask all active applications */
uint32_t CIPmask2; /* Listen CIP mask 2 all active applications */
@ -118,14 +122,13 @@ 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 */
int fd; /* Filedescriptor for CAPI messages */
struct lController *contL; /* list of controllers */
int refc; /* refcount */
int fd; /* Filedescriptor for CAPI messages */
struct lController *contL; /* list of controllers */
uint16_t AppId;
uint16_t MsgId; /* next message number */
uint16_t MsgId; /* next message number */
int MaxB3Con;
int MaxB3Blk;
int MaxB3Size;
@ -141,10 +144,10 @@ int ListenController(struct pController *);
struct mPLCI {
struct mPLCI *next;
uint32_t plci; /* PLCI ID */
int pid; /* L3 pid */
uint32_t plci; /* PLCI ID */
int pid; /* L3 pid */
struct pController *pc;
int nAppl;
int nAppl;
struct lPLCI *lPLCIs;
unsigned int alerting:1;
unsigned int outgoing:1;
@ -170,7 +173,7 @@ struct lPLCI {
struct mPLCI *PLCI;
struct FsmInst plci_m;
struct BInstance *BIlink;
int NcciCnt;
int NcciCnt;
struct mNCCI *Nccis;
int cause;
int cause_loc;
@ -213,32 +216,32 @@ enum _flowmode {
};
struct mNCCI {
struct mNCCI *next;
uint32_t ncci;
struct lPLCI *lp;
struct mApplication *appl;
struct BInstance *BIlink;
int window;
struct FsmInst ncci_m;
pthread_mutex_t lock;
struct _ConfQueue xmit_handles[CAPI_MAXDATAWINDOW];
uint32_t recv_handles[CAPI_MAXDATAWINDOW];
enum _flowmode flowmode;
uint16_t isize;
uint16_t osize;
uint16_t iidx;
uint16_t oidx;
struct msghdr down_msg;
struct iovec down_iv[3];
struct mISDNhead down_header;
struct msghdr up_msg;
struct iovec up_iv[2];
unsigned char up_header[30];
unsigned int dtmflisten:1;
unsigned int l1direct:1;
unsigned int l2trans:1;
unsigned int l3trans:1;
unsigned int dlbusy:1;
struct mNCCI *next;
uint32_t ncci;
struct lPLCI *lp;
struct mApplication *appl;
struct BInstance *BIlink;
int window;
struct FsmInst ncci_m;
pthread_mutex_t lock;
struct _ConfQueue xmit_handles[CAPI_MAXDATAWINDOW];
uint32_t recv_handles[CAPI_MAXDATAWINDOW];
enum _flowmode flowmode;
uint16_t isize;
uint16_t osize;
uint16_t iidx;
uint16_t oidx;
struct msghdr down_msg;
struct iovec down_iv[3];
struct mISDNhead down_header;
struct msghdr up_msg;
struct iovec up_iv[2];
unsigned char up_header[30];
unsigned int dtmflisten:1;
unsigned int l1direct:1;
unsigned int l2trans:1;
unsigned int l3trans:1;
unsigned int dlbusy:1;
};
void init_ncci_fsm(void);
@ -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,10 +20,9 @@
#include "mc_buffer.h"
#include <mISDN/q931.h>
struct mPLCI *new_mPLCI(struct pController *pc, int pid, struct lPLCI *lp)
{
struct mPLCI *plci;
struct mPLCI *plci;
int plci_nr = 1;
plci = pc->plciL;
@ -61,7 +60,7 @@ int free_mPLCI(struct mPLCI *plci)
if (p == plci)
pc->plciL = plci->next;
else {
while(p && p->next) {
while (p && p->next) {
if (p->next == plci) {
p->next = plci->next;
break;
@ -117,19 +116,18 @@ void plciDetachlPLCI(struct lPLCI *lp)
static void plciHandleSetupInd(struct mPLCI *plci, int pr, struct mc_buf *mc)
{
uint16_t CIPValue;
uint32_t CIPmask;
struct pController *pc;
struct lController *lc;
struct lPLCI *lp;
uint8_t found = 0;
int ret;
uint16_t CIPValue;
uint32_t CIPmask;
struct pController *pc;
struct lController *lc;
struct lPLCI *lp;
uint8_t found = 0;
int ret;
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;
@ -161,7 +159,7 @@ static void plciHandleSetupInd(struct mPLCI *plci, int pr, struct mc_buf *mc)
ret = pc->l3->to_layer3(pc->l3, MT_RELEASE_COMPLETE, plci->pid, l3m);
if (ret) {
wprint("Error %d - %s on sending %s to pid %x\n", ret, strerror(-ret),
_mi_msg_type2str(MT_RELEASE_COMPLETE), plci->pid);
_mi_msg_type2str(MT_RELEASE_COMPLETE), plci->pid);
free_l3_msg(l3m);
}
}
@ -173,13 +171,12 @@ static void plciHandleSetupInd(struct mPLCI *plci, int pr, struct mc_buf *mc)
int plci_l3l4(struct mPLCI *plci, int pr, struct l3_msg *l3m)
{
struct lPLCI *lp;
struct mc_buf *mc;
struct lPLCI *lp;
struct mc_buf *mc;
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;
@ -189,7 +186,7 @@ int plci_l3l4(struct mPLCI *plci, int pr, struct l3_msg *l3m)
break;
default:
lp = plci->lPLCIs;
while(lp) {
while (lp) {
lPLCI_l3l4(lp, pr, mc);
lp = lp->next;
}
@ -201,9 +198,9 @@ int plci_l3l4(struct mPLCI *plci, int pr, struct l3_msg *l3m)
int mPLCISendMessage(struct lController *lc, struct mc_buf *mc)
{
struct mPLCI *plci;
struct lPLCI *lp;
int ret;
struct mPLCI *plci;
struct lPLCI *lp;
int ret;
switch (mc->cmsg.Command) {
case CAPI_CONNECT:
@ -242,7 +239,7 @@ struct lPLCI *get_lPLCI4Id(struct mPLCI *plci, uint16_t appId)
if (!plci)
return NULL;
lp = plci->lPLCIs;
while(lp) {
while (lp) {
if (appId == lp->lc->Appl->AppId)
break;
lp = lp->next;
@ -252,9 +249,13 @@ 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;
while(plci) {
if (pc)
plci = pc->plciL;
else
plci = NULL;
while (plci) {
if (plci->pid == pid)
break;
plci = plci->next;
@ -264,9 +265,13 @@ 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;
while(plci) {
if (pc)
plci = pc->plciL;
else
plci = NULL;
while (plci) {
if (plci->plci == id)
break;
plci = plci->next;
@ -274,19 +279,18 @@ 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;
ret = plci->pc->l3->to_layer3(plci->pc->l3, mt, plci->pid, l3m);
if (ret < 0) {
wprint("Error sending %s to controller %d pid %x %s msg\n", _mi_msg_type2str(mt),
plci->pc->profile.ncontroller, plci->pid, l3m ? "with" : "no");
plci->pc->profile.ncontroller, plci->pid, l3m ? "with" : "no");
if (l3m)
free_l3_msg(l3m);
}
dprint(MIDEBUG_PLCI, "Sending %s to layer3 pid %x controller %d %s msg\n", _mi_msg_type2str(mt),
plci->pc->profile.ncontroller, plci->pid, l3m ? "with" : "no");
plci->pc->profile.ncontroller, plci->pid, l3m ? "with" : "no");
return 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,11 +78,9 @@ 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[] = {
static char *str_ev_ncci[] = {
"EV_AP_CONNECT_B3_REQ",
"EV_NC_CONNECT_B3_CONF",
"EV_NC_CONNECT_B3_IND",
@ -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,24 +128,20 @@ 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;
struct mNCCI *ncci = fi->userdata;
struct mc_buf *mc = arg;
FsmChangeState(fi, ST_NCCI_N_0_1);
capi_cmsg_answer(&mc->cmsg);
@ -161,19 +152,17 @@ 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;
struct mNCCI *ncci = fi->userdata;
struct mc_buf *mc = arg;
if (mc->cmsg.Info == 0) {
FsmChangeState(fi, ST_NCCI_N_2);
@ -188,12 +177,11 @@ 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;
unsigned int pr;
struct mNCCI *ncci = fi->userdata;
struct mc_buf *mc = arg;
unsigned int pr;
if (mc->cmsg.Info == 0) {
FsmChangeState(fi, ST_NCCI_N_2);
@ -207,15 +195,14 @@ 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;
uint16_t Info = 0;
int prim;
struct mNCCI *ncci = fi->userdata;
struct mc_buf *mc = arg;
uint16_t Info = 0;
int prim;
if (ncci->appl) { //FIXME
if (ncci->appl) { //FIXME
/* TODO: handle NCPI and wait for all DATA_B3_REQ confirmed on
* related protocols (voice, T30)
*/
@ -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,57 +226,53 @@ 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;
struct mNCCI *ncci = fi->userdata;
FsmChangeState(fi, ST_NCCI_N_5);
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;
u_char *p = mc->cmsg.FacilityRequestParameter;
uint16_t func;
int op;
struct mNCCI *ncci = fi->userdata;
struct mc_buf *mc = arg;
u_char *p = mc->cmsg.FacilityRequestParameter;
uint16_t func;
int op;
capi_cmsg_answer(&mc->cmsg);
mc->cmsg.Info = CapiNoError;
if (mc->cmsg.FacilitySelector == 0) { // Handset
if (mc->cmsg.FacilitySelector == 0) { // Handset
#ifdef HANDSET_SERVICE
int err = ncciL4L3(ncci, PH_CONTROL_REQ, HW_POTS_ON, 0, NULL, NULL);
if (err)
#endif
mc->cmsg.Info = CapiSupplementaryServiceNotSupported;
} else if (mc->cmsg.FacilitySelector != 1) { // not DTMF
} else if (mc->cmsg.FacilitySelector != 1) { // not DTMF
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;
ncciL4L3(ncci, PH_CONTROL_REQ, 0, sizeof(int), &op, NULL);
break;
case 2:
op = DTMF_TONE_STOP;
ncciL4L3(ncci, PH_CONTROL_REQ, 0, sizeof(int), &op, NULL);
break;
default:
mc->cmsg.Info = CapiSupplementaryServiceNotSupported;
break;
case 1:
op = DTMF_TONE_START;
ncciL4L3(ncci, PH_CONTROL_REQ, 0, sizeof(int), &op, NULL);
break;
case 2:
op = DTMF_TONE_STOP;
ncciL4L3(ncci, PH_CONTROL_REQ, 0, sizeof(int), &op, NULL);
break;
default:
mc->cmsg.Info = CapiSupplementaryServiceNotSupported;
break;
}
} else
mc->cmsg.Info = CapiIllMessageParmCoding;
@ -299,63 +281,62 @@ 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;
struct mNCCI *ncci = fi->userdata;
struct mc_buf *mc = arg;
#ifdef HANDSET_SERVICE
int err, op;
struct _manu_conf_para {
uint8_t len;
uint16_t Info;
uint16_t vol;
} __attribute__((packed)) mcp = {2, CapiNoError, 0};
int err, op;
struct _manu_conf_para {
uint8_t len;
uint16_t Info;
uint16_t vol;
} __attribute__ ((packed)) mcp = {
2, CapiNoError, 0};
struct _manu_req_para {
uint8_t len;
uint16_t vol;
} __attribute__((packed)) *mrp;
struct _manu_req_para {
uint8_t len;
uint16_t vol;
} __attribute__ ((packed)) * mrp;
mrp = (struct _manu_req_para *)cmsg->ManuData;
mrp = (struct _manu_req_para *)cmsg->ManuData;
capi_cmsg_answer(cmsg);
if (cmsg->Class == mISDN_MF_CLASS_HANDSET) { // Handset
switch(cmsg->Function) {
case mISDN_MF_HANDSET_ENABLE:
err = ncciL4L3(ncci, PH_CONTROL | REQUEST, HW_POTS_ON, 0, NULL, NULL);
if (err)
mcp.Info = CapiFacilityNotSupported;
break;
case mISDN_MF_HANDSET_DISABLE:
err = ncciL4L3(ncci, PH_CONTROL | REQUEST, HW_POTS_OFF, 0, NULL, NULL);
if (err)
mcp.Info = CapiSupplementaryServiceNotSupported;
break;
case mISDN_MF_HANDSET_SETMICVOLUME:
case mISDN_MF_HANDSET_SETSPKVOLUME:
if (!mrp || mrp->len != 2) {
mcp.Info = CapiIllMessageParmCoding;
break;
}
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;
else if (err)
mcp.Info = CapiIllMessageParmCoding;
break;
/* not handled yet */
case mISDN_MF_HANDSET_GETMICVOLUME:
case mISDN_MF_HANDSET_GETSPKVOLUME:
default:
if (cmsg->Class == mISDN_MF_CLASS_HANDSET) { // Handset
switch (cmsg->Function) {
case mISDN_MF_HANDSET_ENABLE:
err = ncciL4L3(ncci, PH_CONTROL | REQUEST, HW_POTS_ON, 0, NULL, NULL);
if (err)
mcp.Info = CapiFacilityNotSupported;
break;
case mISDN_MF_HANDSET_DISABLE:
err = ncciL4L3(ncci, PH_CONTROL | REQUEST, HW_POTS_OFF, 0, NULL, NULL);
if (err)
mcp.Info = CapiSupplementaryServiceNotSupported;
break;
case mISDN_MF_HANDSET_SETMICVOLUME:
case mISDN_MF_HANDSET_SETSPKVOLUME:
if (!mrp || mrp->len != 2) {
mcp.Info = CapiIllMessageParmCoding;
break;
}
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;
else if (err)
mcp.Info = CapiIllMessageParmCoding;
break;
/* not handled yet */
case mISDN_MF_HANDSET_GETMICVOLUME:
case mISDN_MF_HANDSET_GETSPKVOLUME:
default:
mcp.Info = CapiSupplementaryServiceNotSupported;
break;
}
} else
mcp.Info = CapiIllMessageParmCoding;
cmsg->ManuData = (_cstruct)&mcp;
cmsg->ManuData = (_cstruct) & mcp;
#else
capi_cmsg_answer(&mc->cmsg);
mc->cmsg.Info = CapiSupplementaryServiceNotSupported;
@ -363,11 +344,10 @@ 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;
struct mNCCI *ncci = fi->userdata;
int i;
FsmChangeState(fi, ST_NCCI_N_ACT);
for (i = 0; i < CAPI_MAXDATAWINDOW; i++) {
@ -377,70 +357,62 @@ 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;
struct mNCCI *ncci = fi->userdata;
ncciCmsgHeader(ncci, arg, CAPI_CONNECT_B3, CAPI_IND);
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;
struct mNCCI *ncci = fi->userdata;
struct mc_buf *mc = arg;
ncciCmsgHeader(ncci, mc, CAPI_CONNECT_B3_ACTIVE, CAPI_IND);
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;
struct mNCCI *ncci = fi->userdata;
struct mc_buf *mc = arg;
ncciCmsgHeader(ncci, mc, CAPI_DISCONNECT_B3, CAPI_IND);
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;
struct mNCCI *ncci = fi->userdata;
struct mc_buf *mc = arg;
ncciCmsgHeader(ncci, mc, CAPI_DISCONNECT_B3, CAPI_IND);
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;
struct mNCCI *ncci = fi->userdata;
struct mc_buf *mc = arg;
ncciCmsgHeader(ncci, mc, CAPI_DISCONNECT_B3, CAPI_IND);
mc->cmsg.Reason_B3 = CapiProtocolErrorLayer1;
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,71 +421,70 @@ ncci_appl_release_disc(struct FsmInst *fi, int event, void *arg)
ncciL4L3(ncci, prim, 0, 0, NULL, NULL);
}
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},
{ST_NCCI_N_0, EV_DL_ESTABLISH_IND, ncci_n0_dl_establish_ind_conf},
{ST_NCCI_N_0, EV_AP_RELEASE, ncci_appl_release},
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},
{ST_NCCI_N_0, EV_DL_ESTABLISH_IND, ncci_n0_dl_establish_ind_conf},
{ST_NCCI_N_0, EV_AP_RELEASE, ncci_appl_release},
{ST_NCCI_N_0_1, EV_NC_CONNECT_B3_CONF, ncci_connect_b3_conf},
{ST_NCCI_N_0_1, EV_AP_MANUFACTURER_REQ, ncci_manufacturer_req},
{ST_NCCI_N_0_1, EV_AP_RELEASE, ncci_appl_release},
{ST_NCCI_N_0_1, EV_NC_CONNECT_B3_CONF, ncci_connect_b3_conf},
{ST_NCCI_N_0_1, EV_AP_MANUFACTURER_REQ, ncci_manufacturer_req},
{ST_NCCI_N_0_1, EV_AP_RELEASE, ncci_appl_release},
{ST_NCCI_N_1, EV_AP_CONNECT_B3_RESP, ncci_connect_b3_resp},
{ST_NCCI_N_1, EV_AP_DISCONNECT_B3_REQ, ncci_disconnect_b3_req},
{ST_NCCI_N_1, EV_NC_DISCONNECT_B3_IND, ncci_disconnect_b3_ind},
{ST_NCCI_N_1, EV_AP_MANUFACTURER_REQ, ncci_manufacturer_req},
{ST_NCCI_N_1, EV_AP_RELEASE, ncci_appl_release_disc},
{ST_NCCI_N_1, EV_NC_LINKDOWN, ncci_linkdown},
{ST_NCCI_N_1, EV_AP_CONNECT_B3_RESP, ncci_connect_b3_resp},
{ST_NCCI_N_1, EV_AP_DISCONNECT_B3_REQ, ncci_disconnect_b3_req},
{ST_NCCI_N_1, EV_NC_DISCONNECT_B3_IND, ncci_disconnect_b3_ind},
{ST_NCCI_N_1, EV_AP_MANUFACTURER_REQ, ncci_manufacturer_req},
{ST_NCCI_N_1, EV_AP_RELEASE, ncci_appl_release_disc},
{ST_NCCI_N_1, EV_NC_LINKDOWN, ncci_linkdown},
{ST_NCCI_N_2, EV_NC_CONNECT_B3_ACTIVE_IND, ncci_connect_b3_active_ind},
{ST_NCCI_N_2, EV_AP_DISCONNECT_B3_REQ, ncci_disconnect_b3_req},
{ST_NCCI_N_2, EV_NC_DISCONNECT_B3_IND, ncci_disconnect_b3_ind},
{ST_NCCI_N_2, EV_DL_ESTABLISH_CONF, ncci_dl_establish_conf},
{ST_NCCI_N_2, EV_DL_RELEASE_IND, ncci_dl_release_ind_conf},
{ST_NCCI_N_2, EV_AP_MANUFACTURER_REQ, ncci_manufacturer_req},
{ST_NCCI_N_2, EV_AP_RELEASE, ncci_appl_release_disc},
{ST_NCCI_N_2, EV_NC_LINKDOWN, ncci_linkdown},
{ST_NCCI_N_2, EV_NC_CONNECT_B3_ACTIVE_IND, ncci_connect_b3_active_ind},
{ST_NCCI_N_2, EV_AP_DISCONNECT_B3_REQ, ncci_disconnect_b3_req},
{ST_NCCI_N_2, EV_NC_DISCONNECT_B3_IND, ncci_disconnect_b3_ind},
{ST_NCCI_N_2, EV_DL_ESTABLISH_CONF, ncci_dl_establish_conf},
{ST_NCCI_N_2, EV_DL_RELEASE_IND, ncci_dl_release_ind_conf},
{ST_NCCI_N_2, EV_AP_MANUFACTURER_REQ, ncci_manufacturer_req},
{ST_NCCI_N_2, EV_AP_RELEASE, ncci_appl_release_disc},
{ST_NCCI_N_2, EV_NC_LINKDOWN, ncci_linkdown},
#if 0
{ST_NCCI_N_3, EV_NC_RESET_B3_IND, ncci_reset_b3_ind},
{ST_NCCI_N_3, EV_DL_DOWN_IND, ncci_dl_down_ind},
{ST_NCCI_N_3, EV_AP_DISCONNECT_B3_REQ, ncci_disconnect_b3_req},
{ST_NCCI_N_3, EV_NC_DISCONNECT_B3_IND, ncci_disconnect_b3_ind},
{ST_NCCI_N_3, EV_AP_RELEASE, ncci_appl_release_disc},
{ST_NCCI_N_3, EV_NC_LINKDOWN, ncci_linkdown},
{ST_NCCI_N_3, EV_NC_RESET_B3_IND, ncci_reset_b3_ind},
{ST_NCCI_N_3, EV_DL_DOWN_IND, ncci_dl_down_ind},
{ST_NCCI_N_3, EV_AP_DISCONNECT_B3_REQ, ncci_disconnect_b3_req},
{ST_NCCI_N_3, EV_NC_DISCONNECT_B3_IND, ncci_disconnect_b3_ind},
{ST_NCCI_N_3, EV_AP_RELEASE, ncci_appl_release_disc},
{ST_NCCI_N_3, EV_NC_LINKDOWN, ncci_linkdown},
#endif
{ST_NCCI_N_ACT, EV_AP_CONNECT_B3_ACTIVE_RESP, ncci_connect_b3_active_resp},
{ST_NCCI_N_ACT, EV_AP_DISCONNECT_B3_REQ, ncci_disconnect_b3_req},
{ST_NCCI_N_ACT, EV_NC_DISCONNECT_B3_IND, ncci_disconnect_b3_ind},
{ST_NCCI_N_ACT, EV_DL_RELEASE_IND, ncci_dl_release_ind_conf},
{ST_NCCI_N_ACT, EV_DL_RELEASE_CONF, ncci_dl_release_ind_conf},
{ST_NCCI_N_ACT, EV_DL_DOWN_IND, ncci_dl_down_ind},
{ST_NCCI_N_ACT, EV_AP_FACILITY_REQ, ncci_facility_req},
{ST_NCCI_N_ACT, EV_AP_MANUFACTURER_REQ, ncci_manufacturer_req},
{ST_NCCI_N_ACT, EV_AP_RELEASE, ncci_appl_release_disc},
{ST_NCCI_N_ACT, EV_NC_LINKDOWN, ncci_linkdown},
{ST_NCCI_N_ACT, EV_AP_CONNECT_B3_ACTIVE_RESP, ncci_connect_b3_active_resp},
{ST_NCCI_N_ACT, EV_AP_DISCONNECT_B3_REQ, ncci_disconnect_b3_req},
{ST_NCCI_N_ACT, EV_NC_DISCONNECT_B3_IND, ncci_disconnect_b3_ind},
{ST_NCCI_N_ACT, EV_DL_RELEASE_IND, ncci_dl_release_ind_conf},
{ST_NCCI_N_ACT, EV_DL_RELEASE_CONF, ncci_dl_release_ind_conf},
{ST_NCCI_N_ACT, EV_DL_DOWN_IND, ncci_dl_down_ind},
{ST_NCCI_N_ACT, EV_AP_FACILITY_REQ, ncci_facility_req},
{ST_NCCI_N_ACT, EV_AP_MANUFACTURER_REQ, ncci_manufacturer_req},
{ST_NCCI_N_ACT, EV_AP_RELEASE, ncci_appl_release_disc},
{ST_NCCI_N_ACT, EV_NC_LINKDOWN, ncci_linkdown},
#if 0
{ST_NCCI_N_ACT, EV_AP_RESET_B3_REQ, ncci_reset_b3_req},
{ST_NCCI_N_ACT, EV_NC_RESET_B3_IND, ncci_reset_b3_ind},
{ST_NCCI_N_ACT, EV_NC_CONNECT_B3_T90_ACTIVE_IND,ncci_connect_b3_t90_active_ind},
{ST_NCCI_N_ACT, EV_AP_RESET_B3_REQ, ncci_reset_b3_req},
{ST_NCCI_N_ACT, EV_NC_RESET_B3_IND, ncci_reset_b3_ind},
{ST_NCCI_N_ACT, EV_NC_CONNECT_B3_T90_ACTIVE_IND, ncci_connect_b3_t90_active_ind},
#endif
{ST_NCCI_N_4, EV_NC_DISCONNECT_B3_CONF, ncci_disconnect_b3_conf},
{ST_NCCI_N_4, EV_NC_DISCONNECT_B3_IND, ncci_disconnect_b3_ind},
{ST_NCCI_N_4, EV_DL_RELEASE_CONF, ncci_dl_release_ind_conf},
{ST_NCCI_N_4, EV_DL_DOWN_IND, ncci_dl_down_ind},
{ST_NCCI_N_4, EV_AP_MANUFACTURER_REQ, ncci_manufacturer_req},
{ST_NCCI_N_4, EV_NC_LINKDOWN, ncci_linkdown},
{ST_NCCI_N_4, EV_NC_DISCONNECT_B3_CONF, ncci_disconnect_b3_conf},
{ST_NCCI_N_4, EV_NC_DISCONNECT_B3_IND, ncci_disconnect_b3_ind},
{ST_NCCI_N_4, EV_DL_RELEASE_CONF, ncci_dl_release_ind_conf},
{ST_NCCI_N_4, EV_DL_DOWN_IND, ncci_dl_down_ind},
{ST_NCCI_N_4, EV_AP_MANUFACTURER_REQ, ncci_manufacturer_req},
{ST_NCCI_N_4, EV_NC_LINKDOWN, ncci_linkdown},
{ST_NCCI_N_5, EV_AP_DISCONNECT_B3_RESP, ncci_disconnect_b3_resp},
{ST_NCCI_N_5, EV_AP_RELEASE, ncci_appl_release},
{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;
@ -554,15 +524,15 @@ ncciCreate(struct lPLCI *lp)
eprint("No memory for NCCI on PLCI:%04x\n", lp->plci);
return NULL;
}
nc->ncci_m.state = ST_NCCI_N_0;
// nc->ncci_m.debug = aplci->plci->contr->debug & CAPI_DBG_NCCI_STATE;
nc->ncci_m.debug = MIDEBUG_NCCI & mI_debug_mask;
nc->ncci_m.userdata = nc;
nc->ncci_m.state = ST_NCCI_N_0;
// nc->ncci_m.debug = aplci->plci->contr->debug & CAPI_DBG_NCCI_STATE;
nc->ncci_m.debug = MIDEBUG_NCCI & mI_debug_mask;
nc->ncci_m.userdata = nc;
nc->ncci_m.printdebug = ncci_debug;
/* unused NCCI */
lp->NcciCnt++;
nc->ncci = lp->plci;
nc->ncci |= (lp->NcciCnt <<16) & 0xFFFF0000;
nc->ncci |= (lp->NcciCnt << 16) & 0xFFFF0000;
nc->lp = lp;
nc->appl = lp->lc->Appl;
nc->BIlink = lp->BIlink;
@ -576,7 +546,7 @@ ncciCreate(struct lPLCI *lp)
nc->flowmode = flmIndication;
}
}
if (lp->Bprotocol.B2 == 0) { /* X.75 has own flowctrl */
if (lp->Bprotocol.B2 == 0) { /* X.75 has own flowctrl */
nc->l2trans = 1;
if (lp->Bprotocol.B1 == 0) {
nc->l1direct = 1;
@ -588,7 +558,7 @@ ncciCreate(struct lPLCI *lp)
nc->ncci_m.fsm = &ncci_fsm;
} else
nc->ncci_m.fsm = &ncci_fsm;
// nc->ncci_m.fsm = &ncciD_fsm;
// nc->ncci_m.fsm = &ncciD_fsm;
if (nc->window > CAPI_MAXDATAWINDOW) {
wprint("NCCI %06x: Datawindow too big (%d) reduced to (%d)\n", nc->ncci, nc->window, CAPI_MAXDATAWINDOW);
@ -607,10 +577,9 @@ ncciCreate(struct lPLCI *lp)
return nc;
}
void
ncciFree(struct mNCCI *ncci)
void ncciFree(struct mNCCI *ncci)
{
int i;
int i;
dprintf(MIDEBUG_NCCI, "NCCI %06x: free\n", ncci->ncci);
@ -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);
@ -735,7 +701,7 @@ static void SendDataB3Down(struct mNCCI *ncci, uint16_t len)
ret = sendmsg(ncci->BIlink->fd, &ncci->down_msg, MSG_DONTWAIT);
if (ret != tot) {
wprint("NCCI %06x: send returned %d while sending %d bytes type %s id %d - %s\n", ncci->ncci, ret, tot,
_mi_msg_type2str(ncci->down_header.prim), ncci->down_header.id, strerror(errno));
_mi_msg_type2str(ncci->down_header.prim), ncci->down_header.id, strerror(errno));
if (ncci->flowmode != flmIndication) {
ncci->dlbusy = 0;
ncci->xmit_handles[ncci->oidx].pkt = NULL;
@ -748,9 +714,9 @@ 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,
ncci->xmit_handles[ncci->oidx].sent, ncci->xmit_handles[ncci->oidx].dlen);
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) {
if (ncci->xmit_handles[ncci->oidx].sent == ncci->xmit_handles[ncci->oidx].dlen) {
@ -786,7 +752,7 @@ static void SendDataB3Down(struct mNCCI *ncci, uint16_t len)
static uint16_t ncciDataReq(struct mNCCI *ncci, struct mc_buf *mc)
{
uint16_t len, off;
uint16_t len, off;
off = CAPIMSG_LEN(mc->rb);
if (off != 22 && off != 30) {
@ -818,7 +784,7 @@ static uint16_t ncciDataReq(struct mNCCI *ncci, struct mc_buf *mc)
ncci->xmit_handles[ncci->iidx].sp = mc->rp;
dprint(MIDEBUG_NCCI_DATA, "NCCI %06x: handle = %d data offset %d totlen %d datalen %d flowmode:%d ncci->dlbusy:%d\n",
ncci->ncci, ncci->xmit_handles[ncci->iidx].DataHandle, off, mc->len, len, ncci->flowmode, ncci->dlbusy);
ncci->ncci, ncci->xmit_handles[ncci->iidx].DataHandle, off, mc->len, len, ncci->flowmode, ncci->dlbusy);
ncci->iidx++;
if (ncci->iidx == ncci->window)
ncci->iidx = 0;
@ -843,8 +809,8 @@ static int ncciDataInd(struct mNCCI *ncci, int pr, struct mc_buf *mc)
pthread_mutex_lock(&ncci->lock);
if (ncci->isize != dlen && (ncci->flowmode == flmIndication)) {
dprint(MIDEBUG_NCCI_DATA, "NCCI %06x: New isize (%d --> %d) set\n", ncci->ncci, ncci->isize, dlen);
ncci->isize = dlen;
ncci->osize = dlen;
ncci->isize = dlen;
ncci->osize = dlen;
}
if (!ncci->BIlink) {
pthread_mutex_unlock(&ncci->lock);
@ -885,11 +851,11 @@ static int ncciDataInd(struct mNCCI *ncci, int pr, struct mc_buf *mc)
pthread_mutex_unlock(&ncci->lock);
if (ret != tot) {
wprint("NCCI %06x: : frame with %d + %d bytes only %d bytes are sent - %s\n",
ncci->ncci, dlen, CAPI_B3_DATA_IND_HEADER_SIZE, ret, strerror(errno));
ncci->ncci, dlen, CAPI_B3_DATA_IND_HEADER_SIZE, ret, strerror(errno));
ret = -EINVAL;
} else
dprint(MIDEBUG_NCCI_DATA, "NCCI %06x: frame with %d + %d bytes handle %d was sent ret %d\n",
ncci->ncci, CAPI_B3_DATA_IND_HEADER_SIZE, dlen, dh, ret);
ncci->ncci, CAPI_B3_DATA_IND_HEADER_SIZE, dlen, dh, ret);
if (ncci->flowmode == flmIndication)
SendDataB3Down(ncci, dlen);
return ret;
@ -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);
@ -962,47 +928,48 @@ ncciDataResp(struct mNCCI *ncci, struct mc_buf *mc)
static int ncciGetCmsg(struct mNCCI *ncci, uint8_t cmd, uint8_t subcmd, struct mc_buf *mc)
{
int retval = CapiNoError;
int retval = CapiNoError;
if (!ncci->l3trans) {
eprint("NCCI %06x: Error L3 not transparent", ncci->ncci);
return -EINVAL;
}
switch (CAPICMD(cmd, subcmd)) {
case CAPI_CONNECT_B3_REQ:
retval = FsmEvent(&ncci->ncci_m, EV_AP_CONNECT_B3_REQ, mc);
break;
case CAPI_CONNECT_B3_RESP:
retval = FsmEvent(&ncci->ncci_m, EV_AP_CONNECT_B3_RESP, mc);
break;
case CAPI_CONNECT_B3_ACTIVE_RESP:
retval = FsmEvent(&ncci->ncci_m, EV_AP_CONNECT_B3_ACTIVE_RESP, mc);
break;
case CAPI_DISCONNECT_B3_REQ:
retval = FsmEvent(&ncci->ncci_m, EV_AP_DISCONNECT_B3_REQ, mc);
break;
case CAPI_DISCONNECT_B3_RESP:
retval = FsmEvent(&ncci->ncci_m, EV_AP_DISCONNECT_B3_RESP, mc);
break;
case CAPI_FACILITY_REQ:
retval = FsmEvent(&ncci->ncci_m, EV_AP_FACILITY_REQ, mc);
break;
case CAPI_FACILITY_RESP:
/* no need to handle */
retval = 0;
break;
case CAPI_MANUFACTURER_REQ:
retval = FsmEvent(&ncci->ncci_m, EV_AP_MANUFACTURER_REQ, mc);
break;
default:
eprint("NCCI %06x: Error Unhandled command %02x/%02x\n", ncci->ncci, cmd, subcmd);
retval = CapiMessageNotSupportedInCurrentState;
case CAPI_CONNECT_B3_REQ:
retval = FsmEvent(&ncci->ncci_m, EV_AP_CONNECT_B3_REQ, mc);
break;
case CAPI_CONNECT_B3_RESP:
retval = FsmEvent(&ncci->ncci_m, EV_AP_CONNECT_B3_RESP, mc);
break;
case CAPI_CONNECT_B3_ACTIVE_RESP:
retval = FsmEvent(&ncci->ncci_m, EV_AP_CONNECT_B3_ACTIVE_RESP, mc);
break;
case CAPI_DISCONNECT_B3_REQ:
retval = FsmEvent(&ncci->ncci_m, EV_AP_DISCONNECT_B3_REQ, mc);
break;
case CAPI_DISCONNECT_B3_RESP:
retval = FsmEvent(&ncci->ncci_m, EV_AP_DISCONNECT_B3_RESP, mc);
break;
case CAPI_FACILITY_REQ:
retval = FsmEvent(&ncci->ncci_m, EV_AP_FACILITY_REQ, mc);
break;
case CAPI_FACILITY_RESP:
/* no need to handle */
retval = 0;
break;
case CAPI_MANUFACTURER_REQ:
retval = FsmEvent(&ncci->ncci_m, EV_AP_MANUFACTURER_REQ, mc);
break;
default:
eprint("NCCI %06x: Error Unhandled command %02x/%02x\n", ncci->ncci, cmd, subcmd);
retval = CapiMessageNotSupportedInCurrentState;
}
if (retval) {
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]);
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]);
retval = CapiNoError;
}
}
@ -1011,27 +978,26 @@ 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;
#if 0
if (!ncci->l3trans) {
ret = ncci_l4l3_direct(ncci, mc);
switch(ret) {
case 0:
break;
case -EINVAL:
case -ENXIO:
int_error();
break; /* (CAPI_MSGBUSY) */
case -EXFULL:
int_error();
break; /* (CAPI_SENDQUEUEFULL) */
default:
int_errtxt("ncci_l4l3_direct return(%d)", ret);
dev_kfree_skb(skb);
break;
switch (ret) {
case 0:
break;
case -EINVAL:
case -ENXIO:
int_error();
break; /* (CAPI_MSGBUSY) */
case -EXFULL:
int_error();
break; /* (CAPI_SENDQUEUEFULL) */
default:
int_errtxt("ncci_l4l3_direct return(%d)", ret);
dev_kfree_skb(skb);
break;
}
return;
}
@ -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,34 +1139,35 @@ 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;
}
FsmEvent(&bi->nc->ncci_m, EV_DL_RELEASE_CONF, mc);
ret = 1;
break;
case PH_CONTROL_IND: /* e.g touch tones */
case PH_CONTROL_IND: /* e.g touch tones */
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);
}