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

@ -11,15 +11,15 @@
* this package for more details.
*/
#include <stdio.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#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;
@ -79,14 +79,14 @@ void ReleaseApplication(struct mApplication *appl)
}
/* TODO clean controller refs */
close(appl->fd);
free(appl);
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;
@ -252,14 +248,14 @@ int PutMessageApplication(struct mApplication *appl, struct mc_buf *mc)
lc = get_lController(appl, id & 0x7f);
if (lc)
pc = lc->Contr;
else
else
pc = get_cController(id & 0x7f);
if (!pc) {
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

@ -11,7 +11,7 @@
* this package for more details.
*/
#include <stdio.h>
#include <stdio.h>
#include <getopt.h>
#include <string.h>
#include <stdarg.h>
@ -31,7 +31,6 @@
#define DEF_CONFIG_FILE "/etc/capi20.conf"
#endif
typedef enum {
PIT_None = 0,
PIT_mISDNmain,
@ -44,7 +43,7 @@ typedef enum {
struct pollInfo {
pollInfo_t type;
void *data;
};
};
static struct pollfd *mainpoll;
static struct pollInfo *pollinfo;
@ -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;
@ -142,7 +140,7 @@ opt_parse(int ac, char *av[])
if (c != 0) {
fprintf(stderr, "unknown options: %s\n", av[optind]);
return -2;
}
}
return 0;
}
@ -176,7 +174,7 @@ static int read_config_file(char *name)
switch (n) {
case 0:
nr_controller = -1;
fprintf(stderr, "error in config file %s:%d:%s\n", name, lnr, line);
fprintf(stderr, "error in config file %s:%d:%s\n", name, lnr, line);
goto err;
case 1:
capicontr = contr + 1;
@ -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;
}
@ -258,7 +258,7 @@ static int add_mainpoll(int fd, pollInfo_t pit)
mainpoll_max++;
} else {
eprint("mainpoll full %d fds\n", mainpoll_size);
return -1;
return -1;
}
}
mainpoll[i].fd = fd;
@ -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,24 +926,23 @@ 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);
break;
mainpoll[i].fd, pollinfo[i].type);
break;
}
ret--;
ret--;
}
if (ret == 0)
break;
}
}
return error;
return error;
}
static int my_lib_debug(const char *file, int line, const char *func, int level, const char *fmt, va_list va)
@ -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);
@ -1021,7 +1007,7 @@ int main(int argc, char *argv[])
ver = init_layer3(4, &l3dbg);
mISDN_set_debug_level(libdebug);
iprint("Init mISDN lib version %x, debug = %x (%x)\n", ver, debugmask, libdebug);
/* open mISDN */
mIsock = socket(PF_ISDN, SOCK_RAW, ISDN_P_BASE);
if (mIsock < 0) {
@ -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);
@ -1139,7 +1124,7 @@ retry_Csock:
fprintf(stderr, "mISDNcapid is already running - only one instance can be used\n");
goto errout;
}
}
}
if (listen(mCsock, 15)) {

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,51 +25,45 @@ 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;
va_list args;
struct lController *lc = fi->userdata;
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,18 +158,16 @@ 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);
return CapiNoError;
}
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;
}
@ -195,7 +178,7 @@ void init_listen(void)
listen_fsm.event_count = EV_LISTEN_COUNT;
listen_fsm.strEvent = str_ev_listen;
listen_fsm.strState = str_st_listen;
FsmNew(&listen_fsm, fn_listen_list, FN_LISTEN_COUNT);
}

File diff suppressed because it is too large Load Diff

View File

@ -14,7 +14,7 @@
* GNU LESSER GENERAL PUBLIC LICENSE for more details.
*
*/
#ifndef _M_CAPI_H
#define _M_CAPI_H
@ -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;
@ -194,7 +197,7 @@ struct mNCCI *ConnectB3Request(struct lPLCI *, struct mc_buf *);
#define GET_NCCI_ONLY_PLCI 2
#define GET_NCCI_PLCI 3
struct _ConfQueue {
struct _ConfQueue {
uint32_t PktId;
uint16_t DataHandle;
uint16_t MsgId;
@ -203,7 +206,7 @@ struct _ConfQueue {
struct mc_buf *pkt;
unsigned char *sp;
};
#define CAPI_MAXDATAWINDOW 8
enum _flowmode {
@ -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;
}

File diff suppressed because it is too large Load Diff