From 7adb7b8017b02dee0fe100e7828e76def9c8484a Mon Sep 17 00:00:00 2001 From: Karsten Keil Date: Sat, 29 Oct 2011 15:13:58 +0200 Subject: [PATCH] Allow different B data handler Signed-off-by: Karsten Keil --- capi20/application.c | 175 +++--- capi20/daemon.c | 203 +++---- capi20/listen.c | 79 +-- capi20/lplci.c | 1288 ++++++++++++++++++++---------------------- capi20/m_capi.h | 107 ++-- capi20/mplci.c | 64 ++- capi20/ncci.c | 580 +++++++++---------- 7 files changed, 1190 insertions(+), 1306 deletions(-) diff --git a/capi20/application.c b/capi20/application.c index ec0ae28..b165084 100644 --- a/capi20/application.c +++ b/capi20/application.c @@ -11,15 +11,15 @@ * this package for more details. */ -#include +#include #include #include #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; } - diff --git a/capi20/daemon.c b/capi20/daemon.c index 207acca..f373ca2 100644 --- a/capi20/daemon.c +++ b/capi20/daemon.c @@ -11,7 +11,7 @@ * this package for more details. */ -#include +#include #include #include #include @@ -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)) { diff --git a/capi20/listen.c b/capi20/listen.c index 403c9c0..4c071aa 100644 --- a/capi20/listen.c +++ b/capi20/listen.c @@ -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); } diff --git a/capi20/lplci.c b/capi20/lplci.c index dc7c3b4..4817b95 100644 --- a/capi20/lplci.c +++ b/capi20/lplci.c @@ -22,9 +22,8 @@ #include "../lib/include/helper.h" #include -static int lPLCILinkUp(struct lPLCI *); -static int lPLCILinkDown(struct lPLCI *); - +static int lPLCILinkUp(struct lPLCI *); +static int lPLCILinkDown(struct lPLCI *); // -------------------------------------------------------------------- // PLCI state machine @@ -49,11 +48,9 @@ enum { ST_PLCI_P_5, ST_PLCI_P_6, ST_PLCI_P_RES, -} +} const ST_PLCI_COUNT = ST_PLCI_P_RES + 1; -const ST_PLCI_COUNT = ST_PLCI_P_RES + 1; - -static char *str_st_plci[] = { +static char *str_st_plci[] = { "ST_PLCI_P_0", "ST_PLCI_P_0_1", "ST_PLCI_P_1", @@ -65,7 +62,7 @@ static char *str_st_plci[] = { "ST_PLCI_P_5", "ST_PLCI_P_6", "ST_PLCI_P_RES", -}; +}; enum { EV_AP_CONNECT_REQ, @@ -112,11 +109,9 @@ enum { EV_L3_REJECT_IND, EV_PH_CONTROL_IND, EV_AP_RELEASE, -} +} const EV_PLCI_COUNT = EV_AP_RELEASE + 1; -const EV_PLCI_COUNT = EV_AP_RELEASE + 1; - -static char* str_ev_plci[] = { +static char *str_ev_plci[] = { "EV_AP_CONNECT_REQ", "EV_PI_CONNECT_CONF", "EV_PI_CONNECT_IND", @@ -163,17 +158,15 @@ static char* str_ev_plci[] = { "EV_AP_RELEASE", }; -static struct Fsm plci_fsm = -{ 0, 0, 0, 0, 0 }; +static struct Fsm plci_fsm = { 0, 0, 0, 0, 0 }; -static void -lPLCI_debug(struct FsmInst *fi, char *fmt, ...) +static void lPLCI_debug(struct FsmInst *fi, char *fmt, ...) { char tmp[128]; char *p = tmp; va_list args; struct lPLCI *lp = fi->userdata; - + if (!(MIDEBUG_STATES & mI_debug_mask)) return; va_start(args, fmt); @@ -184,25 +177,20 @@ lPLCI_debug(struct FsmInst *fi, char *fmt, ...) va_end(args); } -static inline void -Send2Application(struct lPLCI *lp, struct mc_buf *mc) +static inline void Send2Application(struct lPLCI *lp, struct mc_buf *mc) { SendCmsg2Application(lp->lc->Appl, mc); } -static inline void -lPLCICmsgHeader(struct lPLCI *lp, _cmsg *cmsg, __u8 cmd, __u8 subcmd) +static inline void lPLCICmsgHeader(struct lPLCI *lp, _cmsg * cmsg, __u8 cmd, __u8 subcmd) { - capi_cmsg_header(cmsg, lp->lc->Appl->AppId, cmd, subcmd, - lp->lc->Appl->MsgId++, lp->plci); + capi_cmsg_header(cmsg, lp->lc->Appl->AppId, cmd, subcmd, lp->lc->Appl->MsgId++, lp->plci); } - -static void -lPLCIClearOtherApps(struct lPLCI *lp) +static void lPLCIClearOtherApps(struct lPLCI *lp) { - struct lPLCI *o_lp; - struct mc_buf *mc = NULL; + struct lPLCI *o_lp; + struct mc_buf *mc = NULL; if (!lp->PLCI) return; @@ -211,7 +199,7 @@ lPLCIClearOtherApps(struct lPLCI *lp) if (o_lp != lp) { MC_BUF_ALLOC(mc); lPLCICmsgHeader(o_lp, &mc->cmsg, CAPI_DISCONNECT, CAPI_IND); - mc->cmsg.Reason = 0x3304; // other application got the call + mc->cmsg.Reason = 0x3304; // other application got the call FsmEvent(&o_lp->plci_m, EV_PI_DISCONNECT_IND, mc); } o_lp = o_lp->next; @@ -220,14 +208,13 @@ lPLCIClearOtherApps(struct lPLCI *lp) free_mc_buf(mc); } -static void -lPLCIInfoIndMsg(struct lPLCI *lp, uint32_t mask, unsigned char mt, struct mc_buf *arg) +static void lPLCIInfoIndMsg(struct lPLCI *lp, uint32_t mask, unsigned char mt, struct mc_buf *arg) { struct mc_buf *mc = arg; if ((!(lp->lc->InfoMask & mask))) return; - + if (!mc) { MC_BUF_ALLOC(mc); } @@ -241,30 +228,29 @@ lPLCIInfoIndMsg(struct lPLCI *lp, uint32_t mask, unsigned char mt, struct mc_bu mc_clear_cmsg(mc); } -static void -lPLCIInfoIndIE(struct lPLCI *lp, unsigned char ie, uint32_t mask, struct mc_buf *mc) +static void lPLCIInfoIndIE(struct lPLCI *lp, unsigned char ie, uint32_t mask, struct mc_buf *mc) { unsigned char **v_ie, *iep; - int pos; + int pos; if (!mc || mc->l3m) return; - if (!(lp->lc->InfoMask & mask)) /* not requested by application */ + if (!(lp->lc->InfoMask & mask)) /* not requested by application */ return; - if (ie & 0x80) { /* Single octet */ + if (ie & 0x80) { /* Single octet */ if (ie != IE_COMPLETE) return; iep = &mc->l3m->sending_complete; } else { v_ie = &mc->l3m->bearer_capability; pos = l3_ie2pos(ie); - if (pos < 0) /* not supported IE */ + if (pos < 0) /* not supported IE */ return; iep = v_ie[pos]; } - if ((iep == NULL) || (*iep == 0)) /* not available in message */ + if ((iep == NULL) || (*iep == 0)) /* not available in message */ return; mc_clear_cmsg(mc); @@ -273,10 +259,10 @@ lPLCIInfoIndIE(struct lPLCI *lp, unsigned char ie, uint32_t mask, struct mc_buf mc->cmsg.InfoElement = iep; #ifdef HANDLE_EARLYB3 if (ie == IE_PROGRESS && lp->lc->InfoMask & CAPI_INFOMASK_EARLYB3) { - if (iep[0] == 0x02 && iep[2] == 0x88) { // in-band information available + if (iep[0] == 0x02 && iep[2] == 0x88) { // in-band information available lPLCILinkUp(lp); if (!test_bit(PLCI_STATE_STACKREADY, &lp->plci->state)) { - Send2ApplicationDelayed(lp,cmsg); + Send2ApplicationDelayed(lp, cmsg); return; } } @@ -285,9 +271,9 @@ lPLCIInfoIndIE(struct lPLCI *lp, unsigned char ie, uint32_t mask, struct mc_buf Send2Application(lp, mc); } -uint16_t q931CIPValue(struct mc_buf *mc) +uint16_t q931CIPValue(struct mc_buf * mc) { - uint16_t CIPValue = 0; + uint16_t CIPValue = 0; int capability, mode, rate, oct5; int hlc = -1, ehlc = -1; int ret, l; @@ -299,13 +285,13 @@ uint16_t q931CIPValue(struct mc_buf *mc) return 0; /* mi_decode_bearer_capability(struct l3_msg *l3m, - int *coding, int *capability, int *mode, int *rate, - int *oct_4a, int *oct_4b, int *oct_5, int *oct_5a, int *oct_5b1, - int *oct_5b2, int *oct_5c, int *oct_5d, int *oct_6, int *oct_7) - */ + int *coding, int *capability, int *mode, int *rate, + int *oct_4a, int *oct_4b, int *oct_5, int *oct_5a, int *oct_5b1, + int *oct_5b2, int *oct_5c, int *oct_5d, int *oct_6, int *oct_7) + */ ret = mi_decode_bearer_capability(mc->l3m, NULL, &capability, &mode, &rate, - NULL, NULL, &oct5, NULL, NULL, NULL, NULL, NULL, NULL, NULL); + NULL, NULL, &oct5, NULL, NULL, NULL, NULL, NULL, NULL, NULL); l = *mc->l3m->bearer_capability; if (l > 13) @@ -316,7 +302,7 @@ uint16_t q931CIPValue(struct mc_buf *mc) if (ret) { wprint("Error decoding bearer %s return %d - %s\n", bdebug, ret, strerror(-ret)); return 0; - } + } if (mode == 0) { switch (capability) { @@ -351,7 +337,7 @@ uint16_t q931CIPValue(struct mc_buf *mc) wprint("Invalid mode %d in bearer %s\n", mode, bdebug); return 0; } - + if (mc->l3m->hlc) { ret = mi_decode_hlc(mc->l3m, &hlc, &ehlc); l = *mc->l3m->hlc; @@ -419,7 +405,7 @@ uint16_t q931CIPValue(struct mc_buf *mc) return CIPValue; } -uint16_t CIPValue2setup(uint16_t CIPValue, struct l3_msg *l3m) +uint16_t CIPValue2setup(uint16_t CIPValue, struct l3_msg * l3m) { switch (CIPValue) { case 16: @@ -448,7 +434,7 @@ uint16_t CIPValue2setup(uint16_t CIPValue, struct l3_msg *l3m) return 0; } -uint16_t cmsg2setup_req(_cmsg *cmsg, struct l3_msg *l3m) +uint16_t cmsg2setup_req(_cmsg * cmsg, struct l3_msg * l3m) { if (CIPValue2setup(cmsg->CIPValue, l3m)) goto err; @@ -467,11 +453,11 @@ uint16_t cmsg2setup_req(_cmsg *cmsg, struct l3_msg *l3m) add_layer3_ie(l3m, IE_HLC, cmsg->HLC[0], &cmsg->HLC[1]); } return 0; - err: +err: return CapiIllMessageParmCoding; } -uint16_t cmsg2info_req(_cmsg *cmsg, struct l3_msg *l3m) +uint16_t cmsg2info_req(_cmsg * cmsg, struct l3_msg * l3m) { if (cmsg->Keypadfacility && cmsg->Keypadfacility[0]) add_layer3_ie(l3m, IE_KEYPAD, cmsg->Keypadfacility[0], &cmsg->Keypadfacility[1]); @@ -480,14 +466,14 @@ uint16_t cmsg2info_req(_cmsg *cmsg, struct l3_msg *l3m) return 0; } -uint16_t cmsg2alerting_req(_cmsg *cmsg, struct l3_msg *l3m) +uint16_t cmsg2alerting_req(_cmsg * cmsg, struct l3_msg * l3m) { if (cmsg->Useruserdata && cmsg->Useruserdata[0]) add_layer3_ie(l3m, IE_USER_USER, cmsg->Useruserdata[0], &cmsg->Useruserdata[1]); return 0; } -uint16_t lPLCICheckBprotocol(struct lPLCI *lp, _cmsg *cmsg) +uint16_t lPLCICheckBprotocol(struct lPLCI * lp, _cmsg * cmsg) { struct pController *pc = lp->PLCI->pc; unsigned long sprot; @@ -561,19 +547,18 @@ static int plci_parse_channel_id(struct lPLCI *lp, struct mc_buf *mc) return ret; } -static void -plci_connect_req(struct FsmInst *fi, int event, void *arg) +static void plci_connect_req(struct FsmInst *fi, int event, void *arg) { - struct lPLCI *lp = fi->userdata; - struct mPLCI *plci = lp->PLCI; - struct mc_buf *mc = arg; - struct l3_msg *l3m; - uint16_t Info = 0; + struct lPLCI *lp = fi->userdata; + struct mPLCI *plci = lp->PLCI; + struct mc_buf *mc = arg; + struct l3_msg *l3m; + uint16_t Info = 0; FsmChangeState(fi, ST_PLCI_P_0_1); plci->outgoing = 1; - l3m = alloc_l3_msg(); + l3m = alloc_l3_msg(); if (!l3m) { Info = CapiNoPlciAvailable; goto answer; @@ -590,17 +575,16 @@ plci_connect_req(struct FsmInst *fi, int event, void *arg) answer: capi_cmsg_answer(&mc->cmsg); mc->cmsg.Info = Info; - if (mc->cmsg.Info == 0) + if (mc->cmsg.Info == 0) mc->cmsg.adr.adrPLCI = lp->plci; FsmEvent(fi, EV_PI_CONNECT_CONF, mc); } -static void -plci_connect_conf(struct FsmInst *fi, int event, void *arg) +static void plci_connect_conf(struct FsmInst *fi, int event, void *arg) { - struct lPLCI *lp = fi->userdata; - struct mc_buf *mc = arg; - + struct lPLCI *lp = fi->userdata; + struct mc_buf *mc = arg; + if (mc->cmsg.Info == 0) { Send2Application(lp, mc); FsmChangeState(fi, ST_PLCI_P_1); @@ -611,8 +595,7 @@ plci_connect_conf(struct FsmInst *fi, int event, void *arg) } } -static void -plci_connect_ind(struct FsmInst *fi, int event, void *arg) +static void plci_connect_ind(struct FsmInst *fi, int event, void *arg) { FsmChangeState(fi, ST_PLCI_P_2); Send2Application(fi->userdata, arg); @@ -620,32 +603,32 @@ plci_connect_ind(struct FsmInst *fi, int event, void *arg) static void plci_hold_req(struct FsmInst *fi, int event, void *arg) { - struct lPLCI *lp = fi->userdata; - struct mPLCI *plci = lp->PLCI; + struct lPLCI *lp = fi->userdata; + struct mPLCI *plci = lp->PLCI; - plciL4L3(plci, MT_HOLD, arg); + plciL4L3(plci, MT_HOLD, arg); } static void plci_retrieve_req(struct FsmInst *fi, int event, void *arg) { - struct lPLCI *lp = fi->userdata; - struct mPLCI *plci = lp->PLCI; + struct lPLCI *lp = fi->userdata; + struct mPLCI *plci = lp->PLCI; - plciL4L3(plci, MT_RETRIEVE, arg); + plciL4L3(plci, MT_RETRIEVE, arg); } static void plci_suspend_req(struct FsmInst *fi, int event, void *arg) { - struct lPLCI *lp = fi->userdata; - struct mPLCI *plci = lp->PLCI; + struct lPLCI *lp = fi->userdata; + struct mPLCI *plci = lp->PLCI; - plciL4L3(plci, MT_SUSPEND, arg); + plciL4L3(plci, MT_SUSPEND, arg); } static void plci_resume_req(struct FsmInst *fi, int event, void *arg) { - struct lPLCI *lp = fi->userdata; - struct mPLCI *plci = lp->PLCI; + struct lPLCI *lp = fi->userdata; + struct mPLCI *plci = lp->PLCI; // we already sent CONF with Info = SuppInfo = 0 FsmChangeState(fi, ST_PLCI_P_RES); @@ -653,19 +636,18 @@ static void plci_resume_req(struct FsmInst *fi, int event, void *arg) plciL4L3(plci, MT_RESUME, arg); } -static void -plci_alert_req(struct FsmInst *fi, int event, void *arg) +static void plci_alert_req(struct FsmInst *fi, int event, void *arg) { - struct lPLCI *lp = fi->userdata; - struct mPLCI *plci = lp->PLCI; - struct mc_buf *mc = arg; - uint16_t Info = 0; - + struct lPLCI *lp = fi->userdata; + struct mPLCI *plci = lp->PLCI; + struct mc_buf *mc = arg; + uint16_t Info = 0; + if (plci->alerting) { - Info = 0x0003; // other app is already alerting + Info = 0x0003; // other app is already alerting } else { if (!mc->l3m) - mc->l3m = alloc_l3_msg(); + mc->l3m = alloc_l3_msg(); if (!mc->l3m) { wprint("alerting not send no l3m\n"); goto answer; @@ -682,16 +664,15 @@ answer: Send2Application(lp, mc); } -static void -plci_connect_resp(struct FsmInst *fi, int event, void *arg) +static void plci_connect_resp(struct FsmInst *fi, int event, void *arg) { - struct lPLCI *lp = fi->userdata; - struct mPLCI *plci = lp->PLCI; - struct mc_buf *mc = arg; - struct l3_msg *l3m; - int cause; + struct lPLCI *lp = fi->userdata; + struct mPLCI *plci = lp->PLCI; + struct mc_buf *mc = arg; + struct l3_msg *l3m; + int cause; - if (mc->cmsg.Reject == 0) { // accept + if (mc->cmsg.Reject == 0) { // accept if (lPLCICheckBprotocol(lp, &mc->cmsg)) { wprint("Bprotocol mismatch\n"); } @@ -704,31 +685,45 @@ plci_connect_resp(struct FsmInst *fi, int event, void *arg) } // ignore, reject switch (mc->cmsg.Reject) { - case 2: cause = 0x90; break; // normal call clearing - case 3: cause = 0x91; break; // user busy - case 4: cause = 0xac; break; // req circuit/channel not avail - case 5: cause = 0x9d; break; // fac rejected - case 6: cause = 0x86; break; // channel unacceptable - case 7: cause = 0xd8; break; // incompatible dest - case 8: cause = 0x9b; break; // dest out of order + case 2: + cause = 0x90; + break; // normal call clearing + case 3: + cause = 0x91; + break; // user busy + case 4: + cause = 0xac; + break; // req circuit/channel not avail + case 5: + cause = 0x9d; + break; // fac rejected + case 6: + cause = 0x86; + break; // channel unacceptable + case 7: + cause = 0xd8; + break; // incompatible dest + case 8: + cause = 0x9b; + break; // dest out of order default: if ((mc->cmsg.Reject & 0xff00) == 0x3400) { cause = mc->cmsg.Reject & 0xff; } else { - cause = 0x90; // normal call clearing + cause = 0x90; // normal call clearing } } // FIXME // WHY ??? // if (cmsg->Reject != 1) { - // ignore - // lPLCIClearOtherApps(lp); + // ignore + // lPLCIClearOtherApps(lp); // } // plciDetachlPLCI(plci, lp); if (plci->nAppl == 1) { int mt; - l3m = alloc_l3_msg(); + l3m = alloc_l3_msg(); if (!l3m) { wprint("disconnect not send no l3m\n"); } else { @@ -747,8 +742,7 @@ plci_connect_resp(struct FsmInst *fi, int event, void *arg) FsmEvent(&lp->plci_m, EV_PI_DISCONNECT_IND, mc); } -static void -plci_connect_active_ind(struct FsmInst *fi, int event, void *arg) +static void plci_connect_active_ind(struct FsmInst *fi, int event, void *arg) { struct lPLCI *lp = fi->userdata; @@ -763,23 +757,23 @@ static void plci_connect_active_resp(struct FsmInst *fi, int event, void *arg) static void plci_disconnect_req(struct FsmInst *fi, int event, void *arg) { - struct lPLCI *lp = fi->userdata; - struct mPLCI *plci = lp->PLCI; - struct mc_buf *mc = arg; - struct l3_msg *l3m; - int cause; + struct lPLCI *lp = fi->userdata; + struct mPLCI *plci = lp->PLCI; + struct mc_buf *mc = arg; + struct l3_msg *l3m; + int cause; FsmChangeState(fi, ST_PLCI_P_5); - + // FIXME handle additional Inf capi_cmsg_answer(&mc->cmsg); - mc->cmsg.Reason = 0; // disconnect initiated + mc->cmsg.Reason = 0; // disconnect initiated Send2Application(lp, mc); lPLCILinkDown(lp); if (lp->cause == 0) { - l3m = alloc_l3_msg(); + l3m = alloc_l3_msg(); if (!l3m) { wprint("disconnect not send no l3m\n"); } else { @@ -802,47 +796,43 @@ static void plci_suspend_conf(struct FsmInst *fi, int event, void *arg) static void plci_resume_conf(struct FsmInst *fi, int event, void *arg) { // facility_ind Resume: Reason = 0 - struct lPLCI *lp = fi->userdata; + struct lPLCI *lp = fi->userdata; FsmChangeState(fi, ST_PLCI_P_ACT); lPLCILinkUp(lp); Send2Application(lp, arg); } -static void -plci_disconnect_ind(struct FsmInst *fi, int event, void *arg) +static void plci_disconnect_ind(struct FsmInst *fi, int event, void *arg) { FsmChangeState(fi, ST_PLCI_P_6); Send2Application(fi->userdata, arg); } -static void -plci_disconnect_resp(struct FsmInst *fi, int event, void *arg) +static void plci_disconnect_resp(struct FsmInst *fi, int event, void *arg) { FsmChangeState(fi, ST_PLCI_P_0); lPLCI_free(fi->userdata); } -static void -plci_appl_release(struct FsmInst *fi, int event, void *arg) +static void plci_appl_release(struct FsmInst *fi, int event, void *arg) { lPLCI_free(fi->userdata); } -static void -plci_appl_release_disc(struct FsmInst *fi, int event, void *arg) +static void plci_appl_release_disc(struct FsmInst *fi, int event, void *arg) { - struct lPLCI *lp = fi->userdata; - struct mPLCI *plci = lp->PLCI; - int cause; - struct l3_msg *l3m; + struct lPLCI *lp = fi->userdata; + struct mPLCI *plci = lp->PLCI; + int cause; + struct l3_msg *l3m; FsmChangeState(fi, ST_PLCI_P_5); - + lPLCILinkDown(lp); if (lp->cause == 0) { - l3m = alloc_l3_msg(); + l3m = alloc_l3_msg(); if (!l3m) { wprint("disconnect not send no l3m\n"); } else { @@ -857,11 +847,10 @@ plci_appl_release_disc(struct FsmInst *fi, int event, void *arg) } } -static void -plci_cc_setup_conf(struct FsmInst *fi, int event, void *arg) +static void plci_cc_setup_conf(struct FsmInst *fi, int event, void *arg) { - struct lPLCI *lp = fi->userdata; - struct mc_buf *mc = arg; + struct lPLCI *lp = fi->userdata; + struct mc_buf *mc = arg; if (lp->chid.nr == MI_CHAN_NONE || lp->chid.nr == MI_CHAN_ANY) { /* no valid channel set */ @@ -880,11 +869,10 @@ plci_cc_setup_conf(struct FsmInst *fi, int event, void *arg) FsmEvent(fi, EV_PI_CONNECT_ACTIVE_IND, mc); } -static void -plci_cc_setup_conf_err(struct FsmInst *fi, int event, void *arg) +static void plci_cc_setup_conf_err(struct FsmInst *fi, int event, void *arg) { - struct lPLCI *lp = fi->userdata; - struct mc_buf *mc = arg; + struct lPLCI *lp = fi->userdata; + struct mc_buf *mc = arg; if (!mc) { mc = alloc_mc_buf(); @@ -896,17 +884,16 @@ plci_cc_setup_conf_err(struct FsmInst *fi, int event, void *arg) lPLCICmsgHeader(lp, &mc->cmsg, CAPI_DISCONNECT, CAPI_IND); mc->cmsg.Reason = CapiProtocolErrorLayer3; FsmEvent(&lp->plci_m, EV_PI_DISCONNECT_IND, mc); - if (!arg) /* if allocated local */ + if (!arg) /* if allocated local */ free_mc_buf(mc); } -static void -plci_channel_err(struct FsmInst *fi, int event, void *arg) +static void plci_channel_err(struct FsmInst *fi, int event, void *arg) { - struct lPLCI *lp = fi->userdata; - int cause; - struct l3_msg *l3m; - struct mc_buf *mc = arg; + struct lPLCI *lp = fi->userdata; + int cause; + struct l3_msg *l3m; + struct mc_buf *mc = arg; l3m = alloc_l3_msg(); if (l3m) { @@ -925,15 +912,14 @@ plci_channel_err(struct FsmInst *fi, int event, void *arg) lPLCICmsgHeader(lp, &mc->cmsg, CAPI_DISCONNECT, CAPI_IND); mc->cmsg.Reason = CapiProtocolErrorLayer3; FsmEvent(&lp->plci_m, EV_PI_DISCONNECT_IND, mc); - if (!arg) /* if allocated local */ + if (!arg) /* if allocated local */ free_mc_buf(mc); } -static void -plci_cc_setup_ind(struct FsmInst *fi, int event, void *arg) -{ - struct lPLCI *lp = fi->userdata; - struct mc_buf *mc = arg; +static void plci_cc_setup_ind(struct FsmInst *fi, int event, void *arg) +{ + struct lPLCI *lp = fi->userdata; + struct mc_buf *mc = arg; lPLCICmsgHeader(lp, &mc->cmsg, CAPI_CONNECT, CAPI_IND); @@ -961,7 +947,7 @@ plci_cc_setup_ind(struct FsmInst *fi, int event, void *arg) /* ETS 300 092 Annex B */ eie = mc->l3m->extra; for (i = 0; i < 8; i++) { - if (!eie->ie) /* stop if no additional ie */ + if (!eie->ie) /* stop if no additional ie */ break; if (eie->ie == IE_CALLING_PN && eie->codeset == 0) { if (eie->val && *eie->val) @@ -977,11 +963,10 @@ plci_cc_setup_ind(struct FsmInst *fi, int event, void *arg) FsmEvent(&lp->plci_m, EV_PI_CONNECT_IND, mc); } -static void -plci_cc_setup_compl_ind(struct FsmInst *fi, int event, void *arg) +static void plci_cc_setup_compl_ind(struct FsmInst *fi, int event, void *arg) { - struct lPLCI *lp = fi->userdata; - struct mc_buf *mc = arg; + struct lPLCI *lp = fi->userdata; + struct mc_buf *mc = arg; if (!mc) { mc = alloc_mc_buf(); @@ -992,15 +977,14 @@ plci_cc_setup_compl_ind(struct FsmInst *fi, int event, void *arg) } lPLCICmsgHeader(lp, &mc->cmsg, CAPI_CONNECT_ACTIVE, CAPI_IND); FsmEvent(&lp->plci_m, EV_PI_CONNECT_ACTIVE_IND, mc); - if (!arg) /* if allocated local */ + if (!arg) /* if allocated local */ free_mc_buf(mc); } -static void -plci_cc_disconnect_ind(struct FsmInst *fi, int event, void *arg) +static void plci_cc_disconnect_ind(struct FsmInst *fi, int event, void *arg) { - struct lPLCI *lp = fi->userdata; - struct mc_buf *mc = arg; + struct lPLCI *lp = fi->userdata; + struct mc_buf *mc = arg; int ret; lp->cause = -1; @@ -1010,7 +994,7 @@ plci_cc_disconnect_ind(struct FsmInst *fi, int event, void *arg) wprint("Error decoding cause %d - %s\n", ret, strerror(-ret)); } else iprint("PLCI %04x: Got Disconnect with cause %02d (0x%02x) loc %02x\n", - lp->plci, lp->cause, lp->cause, lp->cause_loc); + lp->plci, lp->cause, lp->cause, lp->cause_loc); } else iprint("PLCI %04x: Got Disconnect without cause info\n", lp->plci); if (lp->lc->InfoMask & CAPI_INFOMASK_EARLYB3) @@ -1020,12 +1004,11 @@ plci_cc_disconnect_ind(struct FsmInst *fi, int event, void *arg) plciL4L3(lp->PLCI, MT_RELEASE, NULL); } -static void -plci_cc_release_ind(struct FsmInst *fi, int event, void *arg) +static void plci_cc_release_ind(struct FsmInst *fi, int event, void *arg) { - struct lPLCI *lp = fi->userdata; - struct mc_buf *mc = arg; - int cause = -1, loc = -1, ret; + struct lPLCI *lp = fi->userdata; + struct mc_buf *mc = arg; + int cause = -1, loc = -1, ret; lPLCILinkDown(lp); if (!mc) { @@ -1053,41 +1036,40 @@ plci_cc_release_ind(struct FsmInst *fi, int event, void *arg) else mc->cmsg.Reason = 0; FsmEvent(&lp->plci_m, EV_PI_DISCONNECT_IND, mc); - if (!arg) /* if allocated local */ + if (!arg) /* if allocated local */ free_mc_buf(mc); } -static void -plci_cc_notify_ind(struct FsmInst *fi, int event, void *arg) +static void plci_cc_notify_ind(struct FsmInst *fi, int event, void *arg) { - struct lPLCI *lp = fi->userdata; - struct mc_buf *mc = arg; + struct lPLCI *lp = fi->userdata; + struct mc_buf *mc = arg; if (!mc || !mc->l3m || !mc->l3m->notify) return; - if (mc->l3m->notify[0] != 1) // len != 1 + if (mc->l3m->notify[0] != 1) // len != 1 return; switch (mc->l3m->notify[1]) { - case 0xF9: // user hold - SendSSNotificationEvent(lp, 0x8000); - break; - case 0xFA: // user retrieve - SendSSNotificationEvent(lp, 0x8001); - break; - case 0x80: // user suspended - SendSSNotificationEvent(lp, 0x8002); - break; - case 0x81: // user resumed - SendSSNotificationEvent(lp, 0x8003); - break; - case 0xFB: // call is diverting - SendSSNotificationEvent(lp, 0x8004); - break; - case 0xE8: // diversion activated - SendSSNotificationEvent(lp, 0x8005); - break; - default: - eprint("unhandled notification %x\n", mc->l3m->notify[1]); + case 0xF9: // user hold + SendSSNotificationEvent(lp, 0x8000); + break; + case 0xFA: // user retrieve + SendSSNotificationEvent(lp, 0x8001); + break; + case 0x80: // user suspended + SendSSNotificationEvent(lp, 0x8002); + break; + case 0x81: // user resumed + SendSSNotificationEvent(lp, 0x8003); + break; + case 0xFB: // call is diverting + SendSSNotificationEvent(lp, 0x8004); + break; + case 0xE8: // diversion activated + SendSSNotificationEvent(lp, 0x8005); + break; + default: + eprint("unhandled notification %x\n", mc->l3m->notify[1]); } } @@ -1096,11 +1078,10 @@ static void plci_hold_conf(struct FsmInst *fi, int event, void *arg) FsmChangeState(fi, ST_PLCI_P_HELD); } -static void -lPLCI_hold_reply(struct lPLCI *lp, uint16_t SuppServiceReason, void *arg) +static void lPLCI_hold_reply(struct lPLCI *lp, uint16_t SuppServiceReason, void *arg) { - unsigned char tmp[10], *p; - struct mc_buf *mc = arg; + unsigned char tmp[10], *p; + struct mc_buf *mc = arg; if (!mc) { mc = alloc_mc_buf(); @@ -1111,7 +1092,7 @@ lPLCI_hold_reply(struct lPLCI *lp, uint16_t SuppServiceReason, void *arg) } lPLCICmsgHeader(lp, &mc->cmsg, CAPI_FACILITY, CAPI_IND); p = &tmp[1]; - p += capiEncodeWord(p, 0x0002); // Hold + p += capiEncodeWord(p, 0x0002); // Hold p += capiEncodeFacIndSuspend(p, SuppServiceReason); tmp[0] = p - &tmp[1]; mc->cmsg.FacilitySelector = 0x0003; @@ -1119,17 +1100,16 @@ lPLCI_hold_reply(struct lPLCI *lp, uint16_t SuppServiceReason, void *arg) Send2Application(lp, mc); if (SuppServiceReason == CapiNoError) FsmEvent(&lp->plci_m, EV_PI_HOLD_CONF, NULL); - if (!arg) /* if allocated local */ + if (!arg) /* if allocated local */ free_mc_buf(mc); } -static void -plci_cc_hold_rej(struct FsmInst *fi, int event, void *arg) +static void plci_cc_hold_rej(struct FsmInst *fi, int event, void *arg) { - struct lPLCI *lp = fi->userdata; - uint16_t SuppServiceReason; - struct mc_buf *mc = arg; - int cause = 0, ret; + struct lPLCI *lp = fi->userdata; + uint16_t SuppServiceReason; + struct mc_buf *mc = arg; + int cause = 0, ret; if (mc && mc->l3m) { if (mc->l3m->cause && *mc->l3m->cause) { @@ -1139,25 +1119,23 @@ plci_cc_hold_rej(struct FsmInst *fi, int event, void *arg) SuppServiceReason = 0x3400 | (cause & 0x7f); } else SuppServiceReason = CapiProtocolErrorLayer3; - } else { // timeout + } else { // timeout SuppServiceReason = CapiProtocolErrorLayer3; } lPLCI_hold_reply(lp, SuppServiceReason, arg); } -static void -plci_cc_hold_ack(struct FsmInst *fi, int event, void *arg) +static void plci_cc_hold_ack(struct FsmInst *fi, int event, void *arg) { - struct lPLCI *lp = fi->userdata; + struct lPLCI *lp = fi->userdata; lPLCI_hold_reply(lp, CapiNoError, arg); lPLCILinkDown(lp); } -static void -plci_cc_hold_ind(struct FsmInst *fi, int event, void *arg) +static void plci_cc_hold_ind(struct FsmInst *fi, int event, void *arg) { - struct lPLCI *lp = fi->userdata; + struct lPLCI *lp = fi->userdata; lPLCI_hold_reply(lp, CapiNoError, arg); lPLCILinkDown(lp); @@ -1166,18 +1144,17 @@ plci_cc_hold_ind(struct FsmInst *fi, int event, void *arg) static void plci_retrieve_conf(struct FsmInst *fi, int event, void *arg) { - struct lPLCI *lp = fi->userdata; + struct lPLCI *lp = fi->userdata; FsmChangeState(fi, ST_PLCI_P_ACT); lPLCILinkUp(lp); Send2Application(lp, arg); } -static void -lPLCI_retrieve_reply(struct lPLCI *lp, uint16_t SuppServiceReason, void *arg) +static void lPLCI_retrieve_reply(struct lPLCI *lp, uint16_t SuppServiceReason, void *arg) { - unsigned char tmp[10], *p; - struct mc_buf *mc = arg; + unsigned char tmp[10], *p; + struct mc_buf *mc = arg; if (!mc) { mc = alloc_mc_buf(); @@ -1188,7 +1165,7 @@ lPLCI_retrieve_reply(struct lPLCI *lp, uint16_t SuppServiceReason, void *arg) } lPLCICmsgHeader(lp, &mc->cmsg, CAPI_FACILITY, CAPI_IND); p = &tmp[1]; - p += capiEncodeWord(p, 0x0003); // Retrieve + p += capiEncodeWord(p, 0x0003); // Retrieve p += capiEncodeFacIndSuspend(p, SuppServiceReason); tmp[0] = p - &tmp[1]; mc->cmsg.FacilitySelector = 0x0003; @@ -1196,20 +1173,19 @@ lPLCI_retrieve_reply(struct lPLCI *lp, uint16_t SuppServiceReason, void *arg) if (SuppServiceReason != CapiNoError) Send2Application(lp, mc); - else + else FsmEvent(&lp->plci_m, EV_PI_RETRIEVE_CONF, mc); - if (!arg) /* if allocated local */ + if (!arg) /* if allocated local */ free_mc_buf(mc); } -static void -plci_cc_retrieve_rej(struct FsmInst *fi, int event, void *arg) +static void plci_cc_retrieve_rej(struct FsmInst *fi, int event, void *arg) { - struct lPLCI *lp = fi->userdata; - uint16_t SuppServiceReason; - struct mc_buf *mc = arg; - int cause = 0, ret; + struct lPLCI *lp = fi->userdata; + uint16_t SuppServiceReason; + struct mc_buf *mc = arg; + int cause = 0, ret; if (mc && mc->l3m) { if (mc->l3m->cause && *mc->l3m->cause) { @@ -1219,35 +1195,33 @@ plci_cc_retrieve_rej(struct FsmInst *fi, int event, void *arg) SuppServiceReason = 0x3400 | (cause & 0x7f); } else SuppServiceReason = CapiProtocolErrorLayer3; - } else { // timeout + } else { // timeout SuppServiceReason = CapiProtocolErrorLayer3; } lPLCI_retrieve_reply(lp, SuppServiceReason, arg); } -static void -plci_cc_retrieve_ack(struct FsmInst *fi, int event, void *arg) +static void plci_cc_retrieve_ack(struct FsmInst *fi, int event, void *arg) { - struct lPLCI *lp = fi->userdata; - struct mc_buf *mc = arg; - int ret; + struct lPLCI *lp = fi->userdata; + struct mc_buf *mc = arg; + int ret; ret = plci_parse_channel_id(lp, mc); if (ret >= 0) { lPLCI_retrieve_reply(lp, CapiNoError, arg); } else { wprint("No valid channel for retrieve (%d)\n", ret); - lPLCI_retrieve_reply(lp, 0x3711, arg); /* resource Error */ + lPLCI_retrieve_reply(lp, 0x3711, arg); /* resource Error */ } } -static void -plci_cc_retrieve_ind(struct FsmInst *fi, int event, void *arg) +static void plci_cc_retrieve_ind(struct FsmInst *fi, int event, void *arg) { - struct lPLCI *lp = fi->userdata; - struct mc_buf *mc = arg; + struct lPLCI *lp = fi->userdata; + struct mc_buf *mc = arg; int mt; - int ret; + int ret; ret = plci_parse_channel_id(lp, mc); if (ret >= 0) { @@ -1255,17 +1229,16 @@ plci_cc_retrieve_ind(struct FsmInst *fi, int event, void *arg) mt = MT_RETRIEVE_ACKNOWLEDGE; } else { wprint("No valid channel for retrieve (%d)\n", ret); - lPLCI_retrieve_reply(lp, 0x3711, arg); /* resource Error */ + lPLCI_retrieve_reply(lp, 0x3711, arg); /* resource Error */ mt = MT_RETRIEVE_REJECT; } plciL4L3(lp->PLCI, mt, NULL); } -static void -lPLCI_suspend_reply(struct lPLCI *lp, uint16_t SuppServiceReason, void *arg) +static void lPLCI_suspend_reply(struct lPLCI *lp, uint16_t SuppServiceReason, void *arg) { - unsigned char tmp[10], *p; - struct mc_buf *mc = arg; + unsigned char tmp[10], *p; + struct mc_buf *mc = arg; if (!mc) { mc = alloc_mc_buf(); @@ -1276,7 +1249,7 @@ lPLCI_suspend_reply(struct lPLCI *lp, uint16_t SuppServiceReason, void *arg) } lPLCICmsgHeader(lp, &mc->cmsg, CAPI_FACILITY, CAPI_IND); p = &tmp[1]; - p += capiEncodeWord(p, 0x0004); // Suspend + p += capiEncodeWord(p, 0x0004); // Suspend p += capiEncodeFacIndSuspend(p, SuppServiceReason); tmp[0] = p - &tmp[1]; mc->cmsg.FacilitySelector = 0x0003; @@ -1286,17 +1259,16 @@ lPLCI_suspend_reply(struct lPLCI *lp, uint16_t SuppServiceReason, void *arg) if (SuppServiceReason == CapiNoError) FsmEvent(&lp->plci_m, EV_PI_SUSPEND_CONF, NULL); - if (!arg) /* if allocated local */ + if (!arg) /* if allocated local */ free_mc_buf(mc); } -static void -plci_cc_suspend_err(struct FsmInst *fi, int event, void *arg) +static void plci_cc_suspend_err(struct FsmInst *fi, int event, void *arg) { - struct lPLCI *lp = fi->userdata; - uint16_t SuppServiceReason; - struct mc_buf *mc = arg; - int cause = 0, ret; + struct lPLCI *lp = fi->userdata; + uint16_t SuppServiceReason; + struct mc_buf *mc = arg; + int cause = 0, ret; if (mc && mc->l3m) { if (mc->l3m->cause && *mc->l3m->cause) { @@ -1306,17 +1278,16 @@ plci_cc_suspend_err(struct FsmInst *fi, int event, void *arg) SuppServiceReason = 0x3400 | (cause & 0x7f); } else SuppServiceReason = CapiProtocolErrorLayer3; - } else { // timeout + } else { // timeout SuppServiceReason = CapiProtocolErrorLayer3; } lPLCI_suspend_reply(lp, SuppServiceReason, arg); } -static void -plci_cc_suspend_conf(struct FsmInst *fi, int event, void *arg) +static void plci_cc_suspend_conf(struct FsmInst *fi, int event, void *arg) { - struct lPLCI *lp = fi->userdata; - struct mc_buf *mc = arg; + struct lPLCI *lp = fi->userdata; + struct mc_buf *mc = arg; if (!mc) { mc = alloc_mc_buf(); @@ -1328,20 +1299,19 @@ plci_cc_suspend_conf(struct FsmInst *fi, int event, void *arg) lPLCILinkDown(lp); lPLCI_suspend_reply(lp, CapiNoError, arg); - + lPLCICmsgHeader(lp, &mc->cmsg, CAPI_DISCONNECT, CAPI_IND); FsmEvent(&lp->plci_m, EV_PI_DISCONNECT_IND, mc); - if (!arg) /* if allocated local */ + if (!arg) /* if allocated local */ free_mc_buf(mc); } -static void -plci_cc_resume_err(struct FsmInst *fi, int event, void *arg) +static void plci_cc_resume_err(struct FsmInst *fi, int event, void *arg) { - struct lPLCI *lp = fi->userdata; - struct mc_buf *mc = arg; - int cause = 0, ret; + struct lPLCI *lp = fi->userdata; + struct mc_buf *mc = arg; + int cause = 0, ret; if (!mc) { mc = alloc_mc_buf(); @@ -1359,21 +1329,20 @@ plci_cc_resume_err(struct FsmInst *fi, int event, void *arg) mc->cmsg.Reason = 0x3400 | (cause & 0x7f); } else mc->cmsg.Reason = 0; - } else // timeout + } else // timeout mc->cmsg.Reason = CapiProtocolErrorLayer1; FsmEvent(&lp->plci_m, EV_PI_DISCONNECT_IND, mc); - if (!arg) /* if allocated local */ + if (!arg) /* if allocated local */ free_mc_buf(mc); } -static void -plci_cc_resume_conf(struct FsmInst *fi, int event, void *arg) +static void plci_cc_resume_conf(struct FsmInst *fi, int event, void *arg) { - struct lPLCI *lp = fi->userdata; - struct mc_buf *mc = arg; - unsigned char tmp[10], *p; - int ret; + struct lPLCI *lp = fi->userdata; + struct mc_buf *mc = arg; + unsigned char tmp[10], *p; + int ret; ret = plci_parse_channel_id(lp, mc); if (ret < 0) { @@ -1382,7 +1351,7 @@ plci_cc_resume_conf(struct FsmInst *fi, int event, void *arg) } lPLCICmsgHeader(lp, &mc->cmsg, CAPI_FACILITY, CAPI_IND); p = &tmp[1]; - p += capiEncodeWord(p, 0x0005); // Suspend + p += capiEncodeWord(p, 0x0005); // Suspend p += capiEncodeFacIndSuspend(p, CapiNoError); tmp[0] = p - &tmp[1]; mc->cmsg.FacilitySelector = 0x0003; @@ -1390,13 +1359,12 @@ plci_cc_resume_conf(struct FsmInst *fi, int event, void *arg) FsmEvent(&lp->plci_m, EV_PI_RESUME_CONF, mc); } -static void -plci_select_b_protocol_req(struct FsmInst *fi, int event, void *arg) +static void plci_select_b_protocol_req(struct FsmInst *fi, int event, void *arg) { - struct lPLCI *lp = fi->userdata; - struct mc_buf *mc = arg; - uint16_t Info; - int ret; + struct lPLCI *lp = fi->userdata; + struct mc_buf *mc = arg; + uint16_t Info; + int ret; Info = lPLCICheckBprotocol(lp, &mc->cmsg); if (Info) @@ -1418,13 +1386,12 @@ answer: Send2Application(lp, arg); } -static void -plci_info_req_overlap(struct FsmInst *fi, int event, void *arg) +static void plci_info_req_overlap(struct FsmInst *fi, int event, void *arg) { - struct lPLCI *lp = fi->userdata; - struct mc_buf *mc = arg; - uint16_t Info = 0; - struct l3_msg *l3m; + struct lPLCI *lp = fi->userdata; + struct mc_buf *mc = arg; + uint16_t Info = 0; + struct l3_msg *l3m; l3m = alloc_l3_msg(); if (l3m) { @@ -1439,13 +1406,12 @@ plci_info_req_overlap(struct FsmInst *fi, int event, void *arg) Send2Application(lp, mc); } -static void -plci_cc_ph_control_ind(struct FsmInst *fi, int event, void *arg) +static void plci_cc_ph_control_ind(struct FsmInst *fi, int event, void *arg) { - struct lPLCI *lp = fi->userdata; - struct mc_buf *mc = arg; - unsigned int *tt; - __u8 tmp[2]; + struct lPLCI *lp = fi->userdata; + struct mc_buf *mc = arg; + unsigned int *tt; + __u8 tmp[2]; tt = (unsigned int *)(mc->rb + sizeof(struct mISDNhead)); dprint(MIDEBUG_PLCI, "PLCI:%04x tt(%x)\n", lp->plci, *tt); @@ -1461,111 +1427,108 @@ plci_cc_ph_control_ind(struct FsmInst *fi, int event, void *arg) } } -static void -plci_info_req(struct FsmInst *fi, int event, void *arg) +static void plci_info_req(struct FsmInst *fi, int event, void *arg) { // FIXME handle INFO CONF } -static struct FsmNode fn_plci_list[] = -{ - {ST_PLCI_P_0, EV_AP_CONNECT_REQ, plci_connect_req}, - {ST_PLCI_P_0, EV_PI_CONNECT_IND, plci_connect_ind}, - {ST_PLCI_P_0, EV_AP_RESUME_REQ, plci_resume_req}, - {ST_PLCI_P_0, EV_L3_SETUP_IND, plci_cc_setup_ind}, - {ST_PLCI_P_0, EV_AP_RELEASE, plci_appl_release}, +static struct FsmNode fn_plci_list[] = { + {ST_PLCI_P_0, EV_AP_CONNECT_REQ, plci_connect_req}, + {ST_PLCI_P_0, EV_PI_CONNECT_IND, plci_connect_ind}, + {ST_PLCI_P_0, EV_AP_RESUME_REQ, plci_resume_req}, + {ST_PLCI_P_0, EV_L3_SETUP_IND, plci_cc_setup_ind}, + {ST_PLCI_P_0, EV_AP_RELEASE, plci_appl_release}, - {ST_PLCI_P_0_1, EV_PI_CONNECT_CONF, plci_connect_conf}, - {ST_PLCI_P_0_1, EV_AP_RELEASE, plci_appl_release}, + {ST_PLCI_P_0_1, EV_PI_CONNECT_CONF, plci_connect_conf}, + {ST_PLCI_P_0_1, EV_AP_RELEASE, plci_appl_release}, - {ST_PLCI_P_1, EV_PI_CONNECT_ACTIVE_IND, plci_connect_active_ind}, - {ST_PLCI_P_1, EV_AP_DISCONNECT_REQ, plci_disconnect_req}, - {ST_PLCI_P_1, EV_PI_DISCONNECT_IND, plci_disconnect_ind}, - {ST_PLCI_P_1, EV_AP_INFO_REQ, plci_info_req_overlap}, - {ST_PLCI_P_1, EV_L3_SETUP_CONF, plci_cc_setup_conf}, - {ST_PLCI_P_1, EV_L3_SETUP_CONF_ERR, plci_cc_setup_conf_err}, - {ST_PLCI_P_1, EV_L3_DISCONNECT_IND, plci_cc_disconnect_ind}, - {ST_PLCI_P_1, EV_L3_RELEASE_PROC_IND, plci_cc_setup_conf_err}, - {ST_PLCI_P_1, EV_L3_RELEASE_IND, plci_cc_release_ind}, - {ST_PLCI_P_1, EV_L3_REJECT_IND, plci_cc_release_ind}, - {ST_PLCI_P_1, EV_PI_CHANNEL_ERR, plci_channel_err}, - {ST_PLCI_P_1, EV_AP_RELEASE, plci_appl_release_disc}, + {ST_PLCI_P_1, EV_PI_CONNECT_ACTIVE_IND, plci_connect_active_ind}, + {ST_PLCI_P_1, EV_AP_DISCONNECT_REQ, plci_disconnect_req}, + {ST_PLCI_P_1, EV_PI_DISCONNECT_IND, plci_disconnect_ind}, + {ST_PLCI_P_1, EV_AP_INFO_REQ, plci_info_req_overlap}, + {ST_PLCI_P_1, EV_L3_SETUP_CONF, plci_cc_setup_conf}, + {ST_PLCI_P_1, EV_L3_SETUP_CONF_ERR, plci_cc_setup_conf_err}, + {ST_PLCI_P_1, EV_L3_DISCONNECT_IND, plci_cc_disconnect_ind}, + {ST_PLCI_P_1, EV_L3_RELEASE_PROC_IND, plci_cc_setup_conf_err}, + {ST_PLCI_P_1, EV_L3_RELEASE_IND, plci_cc_release_ind}, + {ST_PLCI_P_1, EV_L3_REJECT_IND, plci_cc_release_ind}, + {ST_PLCI_P_1, EV_PI_CHANNEL_ERR, plci_channel_err}, + {ST_PLCI_P_1, EV_AP_RELEASE, plci_appl_release_disc}, - {ST_PLCI_P_2, EV_AP_ALERT_REQ, plci_alert_req}, - {ST_PLCI_P_2, EV_AP_CONNECT_RESP, plci_connect_resp}, - {ST_PLCI_P_2, EV_AP_DISCONNECT_REQ, plci_disconnect_req}, - {ST_PLCI_P_2, EV_PI_DISCONNECT_IND, plci_disconnect_ind}, - {ST_PLCI_P_2, EV_L3_RELEASE_PROC_IND, plci_cc_release_ind}, - {ST_PLCI_P_2, EV_AP_INFO_REQ, plci_info_req}, - {ST_PLCI_P_2, EV_L3_RELEASE_IND, plci_cc_release_ind}, - {ST_PLCI_P_2, EV_AP_RELEASE, plci_appl_release_disc}, + {ST_PLCI_P_2, EV_AP_ALERT_REQ, plci_alert_req}, + {ST_PLCI_P_2, EV_AP_CONNECT_RESP, plci_connect_resp}, + {ST_PLCI_P_2, EV_AP_DISCONNECT_REQ, plci_disconnect_req}, + {ST_PLCI_P_2, EV_PI_DISCONNECT_IND, plci_disconnect_ind}, + {ST_PLCI_P_2, EV_L3_RELEASE_PROC_IND, plci_cc_release_ind}, + {ST_PLCI_P_2, EV_AP_INFO_REQ, plci_info_req}, + {ST_PLCI_P_2, EV_L3_RELEASE_IND, plci_cc_release_ind}, + {ST_PLCI_P_2, EV_AP_RELEASE, plci_appl_release_disc}, - {ST_PLCI_P_4, EV_PI_CONNECT_ACTIVE_IND, plci_connect_active_ind}, - {ST_PLCI_P_4, EV_AP_DISCONNECT_REQ, plci_disconnect_req}, - {ST_PLCI_P_4, EV_PI_DISCONNECT_IND, plci_disconnect_ind}, - {ST_PLCI_P_4, EV_AP_INFO_REQ, plci_info_req}, - {ST_PLCI_P_4, EV_L3_SETUP_COMPL_IND, plci_cc_setup_compl_ind}, - {ST_PLCI_P_4, EV_L3_RELEASE_IND, plci_cc_release_ind}, - {ST_PLCI_P_4, EV_L3_RELEASE_PROC_IND, plci_cc_release_ind}, - {ST_PLCI_P_4, EV_PI_CHANNEL_ERR, plci_channel_err}, - {ST_PLCI_P_4, EV_AP_RELEASE, plci_appl_release_disc}, + {ST_PLCI_P_4, EV_PI_CONNECT_ACTIVE_IND, plci_connect_active_ind}, + {ST_PLCI_P_4, EV_AP_DISCONNECT_REQ, plci_disconnect_req}, + {ST_PLCI_P_4, EV_PI_DISCONNECT_IND, plci_disconnect_ind}, + {ST_PLCI_P_4, EV_AP_INFO_REQ, plci_info_req}, + {ST_PLCI_P_4, EV_L3_SETUP_COMPL_IND, plci_cc_setup_compl_ind}, + {ST_PLCI_P_4, EV_L3_RELEASE_IND, plci_cc_release_ind}, + {ST_PLCI_P_4, EV_L3_RELEASE_PROC_IND, plci_cc_release_ind}, + {ST_PLCI_P_4, EV_PI_CHANNEL_ERR, plci_channel_err}, + {ST_PLCI_P_4, EV_AP_RELEASE, plci_appl_release_disc}, - {ST_PLCI_P_ACT, EV_AP_CONNECT_ACTIVE_RESP, plci_connect_active_resp}, - {ST_PLCI_P_ACT, EV_AP_DISCONNECT_REQ, plci_disconnect_req}, - {ST_PLCI_P_ACT, EV_PI_DISCONNECT_IND, plci_disconnect_ind}, - {ST_PLCI_P_ACT, EV_AP_INFO_REQ, plci_info_req}, - {ST_PLCI_P_ACT, EV_AP_SELECT_B_PROTOCOL_REQ, plci_select_b_protocol_req}, - {ST_PLCI_P_ACT, EV_AP_HOLD_REQ, plci_hold_req}, - {ST_PLCI_P_ACT, EV_AP_SUSPEND_REQ, plci_suspend_req}, - {ST_PLCI_P_ACT, EV_PI_SUSPEND_CONF, plci_suspend_conf}, - {ST_PLCI_P_ACT, EV_L3_DISCONNECT_IND, plci_cc_disconnect_ind}, - {ST_PLCI_P_ACT, EV_L3_RELEASE_IND, plci_cc_release_ind}, - {ST_PLCI_P_ACT, EV_L3_RELEASE_PROC_IND, plci_cc_release_ind}, - {ST_PLCI_P_ACT, EV_L3_NOTIFY_IND, plci_cc_notify_ind}, - {ST_PLCI_P_ACT, EV_L3_HOLD_IND, plci_cc_hold_ind}, - {ST_PLCI_P_ACT, EV_L3_HOLD_ACKNOWLEDGE, plci_cc_hold_ack}, - {ST_PLCI_P_ACT, EV_L3_HOLD_REJECT, plci_cc_hold_rej}, - {ST_PLCI_P_ACT, EV_PI_HOLD_CONF, plci_hold_conf}, - {ST_PLCI_P_ACT, EV_L3_SUSPEND_ERR, plci_cc_suspend_err}, - {ST_PLCI_P_ACT, EV_L3_SUSPEND_CONF, plci_cc_suspend_conf}, - {ST_PLCI_P_ACT, EV_PH_CONTROL_IND, plci_cc_ph_control_ind}, - {ST_PLCI_P_ACT, EV_AP_RELEASE, plci_appl_release_disc}, + {ST_PLCI_P_ACT, EV_AP_CONNECT_ACTIVE_RESP, plci_connect_active_resp}, + {ST_PLCI_P_ACT, EV_AP_DISCONNECT_REQ, plci_disconnect_req}, + {ST_PLCI_P_ACT, EV_PI_DISCONNECT_IND, plci_disconnect_ind}, + {ST_PLCI_P_ACT, EV_AP_INFO_REQ, plci_info_req}, + {ST_PLCI_P_ACT, EV_AP_SELECT_B_PROTOCOL_REQ, plci_select_b_protocol_req}, + {ST_PLCI_P_ACT, EV_AP_HOLD_REQ, plci_hold_req}, + {ST_PLCI_P_ACT, EV_AP_SUSPEND_REQ, plci_suspend_req}, + {ST_PLCI_P_ACT, EV_PI_SUSPEND_CONF, plci_suspend_conf}, + {ST_PLCI_P_ACT, EV_L3_DISCONNECT_IND, plci_cc_disconnect_ind}, + {ST_PLCI_P_ACT, EV_L3_RELEASE_IND, plci_cc_release_ind}, + {ST_PLCI_P_ACT, EV_L3_RELEASE_PROC_IND, plci_cc_release_ind}, + {ST_PLCI_P_ACT, EV_L3_NOTIFY_IND, plci_cc_notify_ind}, + {ST_PLCI_P_ACT, EV_L3_HOLD_IND, plci_cc_hold_ind}, + {ST_PLCI_P_ACT, EV_L3_HOLD_ACKNOWLEDGE, plci_cc_hold_ack}, + {ST_PLCI_P_ACT, EV_L3_HOLD_REJECT, plci_cc_hold_rej}, + {ST_PLCI_P_ACT, EV_PI_HOLD_CONF, plci_hold_conf}, + {ST_PLCI_P_ACT, EV_L3_SUSPEND_ERR, plci_cc_suspend_err}, + {ST_PLCI_P_ACT, EV_L3_SUSPEND_CONF, plci_cc_suspend_conf}, + {ST_PLCI_P_ACT, EV_PH_CONTROL_IND, plci_cc_ph_control_ind}, + {ST_PLCI_P_ACT, EV_AP_RELEASE, plci_appl_release_disc}, - {ST_PLCI_P_HELD, EV_AP_RETRIEVE_REQ, plci_retrieve_req}, - {ST_PLCI_P_HELD, EV_L3_RETRIEVE_ACKNOWLEDGE, plci_cc_retrieve_ack}, - {ST_PLCI_P_HELD, EV_L3_RETRIEVE_REJECT, plci_cc_retrieve_rej}, - {ST_PLCI_P_HELD, EV_PI_RETRIEVE_CONF, plci_retrieve_conf}, - {ST_PLCI_P_HELD, EV_AP_DISCONNECT_REQ, plci_disconnect_req}, - {ST_PLCI_P_HELD, EV_AP_INFO_REQ, plci_info_req}, - {ST_PLCI_P_HELD, EV_L3_RETRIEVE_IND, plci_cc_retrieve_ind}, - {ST_PLCI_P_HELD, EV_L3_DISCONNECT_IND, plci_cc_disconnect_ind}, - {ST_PLCI_P_HELD, EV_L3_RELEASE_IND, plci_cc_release_ind}, - {ST_PLCI_P_HELD, EV_L3_RELEASE_PROC_IND, plci_cc_release_ind}, - {ST_PLCI_P_HELD, EV_L3_NOTIFY_IND, plci_cc_notify_ind}, - {ST_PLCI_P_HELD, EV_PI_DISCONNECT_IND, plci_disconnect_ind}, - {ST_PLCI_P_HELD, EV_AP_RELEASE, plci_appl_release_disc}, + {ST_PLCI_P_HELD, EV_AP_RETRIEVE_REQ, plci_retrieve_req}, + {ST_PLCI_P_HELD, EV_L3_RETRIEVE_ACKNOWLEDGE, plci_cc_retrieve_ack}, + {ST_PLCI_P_HELD, EV_L3_RETRIEVE_REJECT, plci_cc_retrieve_rej}, + {ST_PLCI_P_HELD, EV_PI_RETRIEVE_CONF, plci_retrieve_conf}, + {ST_PLCI_P_HELD, EV_AP_DISCONNECT_REQ, plci_disconnect_req}, + {ST_PLCI_P_HELD, EV_AP_INFO_REQ, plci_info_req}, + {ST_PLCI_P_HELD, EV_L3_RETRIEVE_IND, plci_cc_retrieve_ind}, + {ST_PLCI_P_HELD, EV_L3_DISCONNECT_IND, plci_cc_disconnect_ind}, + {ST_PLCI_P_HELD, EV_L3_RELEASE_IND, plci_cc_release_ind}, + {ST_PLCI_P_HELD, EV_L3_RELEASE_PROC_IND, plci_cc_release_ind}, + {ST_PLCI_P_HELD, EV_L3_NOTIFY_IND, plci_cc_notify_ind}, + {ST_PLCI_P_HELD, EV_PI_DISCONNECT_IND, plci_disconnect_ind}, + {ST_PLCI_P_HELD, EV_AP_RELEASE, plci_appl_release_disc}, - {ST_PLCI_P_5, EV_PI_DISCONNECT_IND, plci_disconnect_ind}, - {ST_PLCI_P_5, EV_L3_RELEASE_IND, plci_cc_release_ind}, - {ST_PLCI_P_5, EV_L3_RELEASE_PROC_IND, plci_cc_release_ind}, - {ST_PLCI_P_5, EV_AP_RELEASE, plci_appl_release}, + {ST_PLCI_P_5, EV_PI_DISCONNECT_IND, plci_disconnect_ind}, + {ST_PLCI_P_5, EV_L3_RELEASE_IND, plci_cc_release_ind}, + {ST_PLCI_P_5, EV_L3_RELEASE_PROC_IND, plci_cc_release_ind}, + {ST_PLCI_P_5, EV_AP_RELEASE, plci_appl_release}, - {ST_PLCI_P_6, EV_AP_DISCONNECT_RESP, plci_disconnect_resp}, - {ST_PLCI_P_6, EV_AP_RELEASE, plci_disconnect_resp}, + {ST_PLCI_P_6, EV_AP_DISCONNECT_RESP, plci_disconnect_resp}, + {ST_PLCI_P_6, EV_AP_RELEASE, plci_disconnect_resp}, - {ST_PLCI_P_RES, EV_PI_RESUME_CONF, plci_resume_conf}, - {ST_PLCI_P_RES, EV_PI_DISCONNECT_IND, plci_disconnect_ind}, - {ST_PLCI_P_RES, EV_L3_RESUME_ERR, plci_cc_resume_err}, - {ST_PLCI_P_RES, EV_L3_RESUME_CONF, plci_cc_resume_conf}, - {ST_PLCI_P_RES, EV_AP_RELEASE, plci_appl_release_disc}, + {ST_PLCI_P_RES, EV_PI_RESUME_CONF, plci_resume_conf}, + {ST_PLCI_P_RES, EV_PI_DISCONNECT_IND, plci_disconnect_ind}, + {ST_PLCI_P_RES, EV_L3_RESUME_ERR, plci_cc_resume_err}, + {ST_PLCI_P_RES, EV_L3_RESUME_CONF, plci_cc_resume_conf}, + {ST_PLCI_P_RES, EV_AP_RELEASE, plci_appl_release_disc}, }; -const int FN_PLCI_COUNT = sizeof(fn_plci_list)/sizeof(struct FsmNode); +const int FN_PLCI_COUNT = sizeof(fn_plci_list) / sizeof(struct FsmNode); -int -lPLCICreate(struct lPLCI **lpp, struct lController *lc, struct mPLCI *plci) +int lPLCICreate(struct lPLCI **lpp, struct lController *lc, struct mPLCI *plci) { - struct lPLCI *lp; + struct lPLCI *lp; lp = calloc(1, sizeof(*lp)); if (!lp) @@ -1577,11 +1540,11 @@ lPLCICreate(struct lPLCI **lpp, struct lController *lc, struct mPLCI *plci) /* DTMF */ lp->l1dtmf = 0; } - lp->plci_m.fsm = &plci_fsm; - lp->plci_m.state = ST_PLCI_P_0; -// lp->plci_m.debug = plci->contr->debug & CAPI_DBG_PLCI_STATE; - lp->plci_m.debug = MIDEBUG_PLCI & mI_debug_mask; - lp->plci_m.userdata = lp; + lp->plci_m.fsm = &plci_fsm; + lp->plci_m.state = ST_PLCI_P_0; +// lp->plci_m.debug = plci->contr->debug & CAPI_DBG_PLCI_STATE; + lp->plci_m.debug = MIDEBUG_PLCI & mI_debug_mask; + lp->plci_m.userdata = lp; lp->plci_m.printdebug = lPLCI_debug; lp->chid.nr = MI_CHAN_NONE; *lpp = lp; @@ -1605,7 +1568,7 @@ void lPLCI_free(struct lPLCI *lp) } else eprint("No l3m for RELEASE_COMPLETE for PLCI:%04x\n", lp->plci); } - plciDetachlPLCI(lp); + plciDetachlPLCI(lp); } nc = lp->Nccis; while (nc) { @@ -1617,19 +1580,17 @@ void lPLCI_free(struct lPLCI *lp) free(lp); } -void -lPLCIRelease(struct lPLCI *lp) +void lPLCIRelease(struct lPLCI *lp) { - /* TODO clean NCCIs */ + /* TODO clean NCCIs */ FsmEvent(&lp->plci_m, EV_AP_RELEASE, NULL); } - -static int -lPLCILinkUp(struct lPLCI *lp) +static int lPLCILinkUp(struct lPLCI *lp) { int proto = -1, ret = 0; struct mISDNhead mh; + BDataTrans_t *from_down = NULL; mh.id = 1; mh.prim = 0; @@ -1639,22 +1600,12 @@ lPLCILinkUp(struct lPLCI *lp) return -EINVAL; } - /* handle DTMF TODO - if ((pid.protocol[2] == ISDN_PID_L2_B_TRANS) && - (pid.protocol[1] == ISDN_PID_L1_B_64TRANS)) - pid.protocol[2] = ISDN_PID_L2_B_TRANSDTMF; - */ - if (lp->Bprotocol.B3 > 23) { - eprint("wrong B3 prot %x\n", lp->Bprotocol.B3); - return 0x3003; - } - - switch(lp->Bprotocol.B1) { - case 0: /* HDLC */ + switch (lp->Bprotocol.B1) { + case 0: /* HDLC */ proto = ISDN_P_B_HDLC; mh.prim = PH_ACTIVATE_REQ; break; - case 1: /* trans */ + case 1: /* trans */ if (lp->l1dtmf) { proto = ISDN_P_B_L2DSP; mh.prim = DL_ESTABLISH_REQ; @@ -1664,31 +1615,39 @@ lPLCILinkUp(struct lPLCI *lp) } break; default: - wprint("wrong B1 prot %x\n", lp->Bprotocol.B3); - ret = 0x3001; + wprint("Unsupported B1 prot %x\n", lp->Bprotocol.B1); + ret = 0x3001; break; } - switch(lp->Bprotocol.B2) { - case 0: /* HDLC */ + switch (lp->Bprotocol.B2) { + case 0: /* HDLC */ proto = ISDN_P_B_X75SLP; mh.prim = DL_ESTABLISH_REQ; break; - case 1:/* trans */ + case 1: /* trans */ break; default: - wprint("wrong B1 prot %x\n", lp->Bprotocol.B3); - ret = 0x3002; + wprint("Unsupported B2 prot %x\n", lp->Bprotocol.B2); + ret = 0x3002; break; } + + switch (lp->Bprotocol.B3) { + case 0: /* trans */ + from_down = recvBdirect; + break; + default: + wprint("Unsupported B3 prot %x\n", lp->Bprotocol.B3); + ret = 0x3003; + break; + } + if (ret) return ret; - if (proto == -1) - return 0x3003; dprint(MIDEBUG_PLCI, "lPLCILinkUp B1(%x) B2(%x) B3(%x) ch(%d) proto(%x)\n", - lp->Bprotocol.B1, lp->Bprotocol.B2, lp->Bprotocol.B3, - lp->chid.nr, proto); + lp->Bprotocol.B1, lp->Bprotocol.B2, lp->Bprotocol.B3, lp->chid.nr, proto); /* capidebug(CAPI_DBG_PLCI, "lPLCILinkUp B1cfg(%d) B2cfg(%d) B3cfg(%d) maxplen(%d)", lp->Bprotocol.B1cfg[0], lp->Bprotocol.B2cfg[0], @@ -1703,7 +1662,7 @@ lPLCILinkUp(struct lPLCI *lp) } dprint(MIDEBUG_PLCI, "lPLCILinkUp lp->link(%p)\n", lp->BIlink); /* TODO open the B-channel */ - if (!OpenBInstance(lp->BIlink, lp)) { + if (!OpenBInstance(lp->BIlink, lp, from_down)) { if (!lp->PLCI->outgoing) { ret = send(lp->BIlink->fd, &mh, 8, 0); if (ret < 0) { @@ -1720,16 +1679,15 @@ lPLCILinkUp(struct lPLCI *lp) return ret; } -struct mNCCI * -getNCCI4addr(struct lPLCI *lp, uint32_t addr, int mode) +struct mNCCI *getNCCI4addr(struct lPLCI *lp, uint32_t addr, int mode) { - struct mNCCI *ncci = NULL; - int cnt = 0; + struct mNCCI *ncci = NULL; + int cnt = 0; if (!lp) return NULL; ncci = lp->Nccis; - while(ncci) { + while (ncci) { cnt++; if (ncci->ncci == addr) return ncci; @@ -1750,8 +1708,8 @@ getNCCI4addr(struct lPLCI *lp, uint32_t addr, int mode) return NULL; } -void -lPLCIDelNCCI(struct mNCCI *ncci) { +void lPLCIDelNCCI(struct mNCCI *ncci) +{ struct lPLCI *lp = ncci->lp; if (lp->Nccis != ncci) { @@ -1760,7 +1718,7 @@ lPLCIDelNCCI(struct mNCCI *ncci) { } lp->Nccis = NULL; lp->NcciCnt = 0; - + if (ncci->BIlink) { ncci->BIlink->nc = NULL; if (ncci->BIlink->fd > 0) @@ -1770,236 +1728,234 @@ lPLCIDelNCCI(struct mNCCI *ncci) { } } -void -lPLCI_l3l4(struct lPLCI *lp, int pr, struct mc_buf *mc) +void lPLCI_l3l4(struct lPLCI *lp, int pr, struct mc_buf *mc) { - int ret; + int ret; dprint(MIDEBUG_PLCI, "lp(%x) %s %s arg\n", lp->plci, _mi_msg_type2str(pr), mc ? "with" : "no"); switch (pr) { - case MT_SETUP: - if (!mc || !mc->l3m) - return; - plci_parse_channel_id(lp, mc); - FsmEvent(&lp->plci_m, EV_L3_SETUP_IND, mc); - if (mc->l3m) { - lPLCIInfoIndIE(lp, IE_DISPLAY, CAPI_INFOMASK_DISPLAY, mc); - lPLCIInfoIndIE(lp, IE_USER_USER, CAPI_INFOMASK_USERUSER, mc); - lPLCIInfoIndIE(lp, IE_PROGRESS, CAPI_INFOMASK_PROGRESS, mc); - lPLCIInfoIndIE(lp, IE_FACILITY, CAPI_INFOMASK_FACILITY, mc); - lPLCIInfoIndIE(lp, IE_CHANNEL_ID, CAPI_INFOMASK_CHANNELID, mc); - lPLCIInfoIndIE(lp, IE_CALLED_PN, CAPI_INFOMASK_CALLEDPN, mc); - lPLCIInfoIndIE(lp, IE_COMPLETE, CAPI_INFOMASK_COMPLETE, mc); + case MT_SETUP: + if (!mc || !mc->l3m) + return; + plci_parse_channel_id(lp, mc); + FsmEvent(&lp->plci_m, EV_L3_SETUP_IND, mc); + if (mc->l3m) { + lPLCIInfoIndIE(lp, IE_DISPLAY, CAPI_INFOMASK_DISPLAY, mc); + lPLCIInfoIndIE(lp, IE_USER_USER, CAPI_INFOMASK_USERUSER, mc); + lPLCIInfoIndIE(lp, IE_PROGRESS, CAPI_INFOMASK_PROGRESS, mc); + lPLCIInfoIndIE(lp, IE_FACILITY, CAPI_INFOMASK_FACILITY, mc); + lPLCIInfoIndIE(lp, IE_CHANNEL_ID, CAPI_INFOMASK_CHANNELID, mc); + lPLCIInfoIndIE(lp, IE_CALLED_PN, CAPI_INFOMASK_CALLEDPN, mc); + lPLCIInfoIndIE(lp, IE_COMPLETE, CAPI_INFOMASK_COMPLETE, mc); + } + break; + case MT_TIMEOUT: + FsmEvent(&lp->plci_m, EV_L3_SETUP_CONF_ERR, mc); + break; + case MT_CONNECT: + if (mc->l3m) { + lPLCIInfoIndIE(lp, IE_DATE, CAPI_INFOMASK_DISPLAY, mc); + lPLCIInfoIndIE(lp, IE_DISPLAY, CAPI_INFOMASK_DISPLAY, mc); + lPLCIInfoIndIE(lp, IE_USER_USER, CAPI_INFOMASK_USERUSER, mc); + lPLCIInfoIndIE(lp, IE_PROGRESS, CAPI_INFOMASK_PROGRESS, mc); + lPLCIInfoIndIE(lp, IE_FACILITY, CAPI_INFOMASK_FACILITY, mc); + lPLCIInfoIndIE(lp, IE_CHANNEL_ID, CAPI_INFOMASK_CHANNELID, mc); + ret = plci_parse_channel_id(lp, mc); + if (ret < 0) { + dprint(MIDEBUG_PLCI, "Got no valid channel on %s (%d)\n", _mi_msg_type2str(pr), ret); } - break; - case MT_TIMEOUT: - FsmEvent(&lp->plci_m, EV_L3_SETUP_CONF_ERR, mc); - break; - case MT_CONNECT: - if (mc->l3m) { - lPLCIInfoIndIE(lp, IE_DATE, CAPI_INFOMASK_DISPLAY, mc); - lPLCIInfoIndIE(lp, IE_DISPLAY, CAPI_INFOMASK_DISPLAY, mc); - lPLCIInfoIndIE(lp, IE_USER_USER, CAPI_INFOMASK_USERUSER, mc); - lPLCIInfoIndIE(lp, IE_PROGRESS, CAPI_INFOMASK_PROGRESS, mc); - lPLCIInfoIndIE(lp, IE_FACILITY, CAPI_INFOMASK_FACILITY, mc); - lPLCIInfoIndIE(lp, IE_CHANNEL_ID, CAPI_INFOMASK_CHANNELID, mc); - ret = plci_parse_channel_id(lp, mc); - if (ret < 0) { - dprint(MIDEBUG_PLCI, "Got no valid channel on %s (%d)\n", _mi_msg_type2str(pr), ret); - } + } + FsmEvent(&lp->plci_m, EV_L3_SETUP_CONF, mc); + break; + case MT_CONNECT_ACKNOWLEDGE: + if (mc->l3m) { + lPLCIInfoIndIE(lp, IE_DISPLAY, CAPI_INFOMASK_DISPLAY, mc); + lPLCIInfoIndIE(lp, IE_CHANNEL_ID, CAPI_INFOMASK_CHANNELID, mc); + ret = plci_parse_channel_id(lp, mc); + if (ret < 0) { + dprint(MIDEBUG_PLCI, "Got no valid channel on %s (%d)\n", _mi_msg_type2str(pr), ret); } - FsmEvent(&lp->plci_m, EV_L3_SETUP_CONF, mc); - break; - case MT_CONNECT_ACKNOWLEDGE: - if (mc->l3m) { - lPLCIInfoIndIE(lp, IE_DISPLAY, CAPI_INFOMASK_DISPLAY, mc); - lPLCIInfoIndIE(lp, IE_CHANNEL_ID, CAPI_INFOMASK_CHANNELID, mc); - ret = plci_parse_channel_id(lp, mc); - if (ret < 0) { - dprint(MIDEBUG_PLCI, "Got no valid channel on %s (%d)\n", _mi_msg_type2str(pr), ret); - } + } + FsmEvent(&lp->plci_m, EV_L3_SETUP_COMPL_IND, mc); + break; + case MT_DISCONNECT: + if (mc->l3m) { + lPLCIInfoIndMsg(lp, CAPI_INFOMASK_EARLYB3, MT_DISCONNECT, mc); + lPLCIInfoIndIE(lp, IE_CAUSE, CAPI_INFOMASK_CAUSE, mc); + lPLCIInfoIndIE(lp, IE_DISPLAY, CAPI_INFOMASK_DISPLAY, mc); + lPLCIInfoIndIE(lp, IE_USER_USER, CAPI_INFOMASK_USERUSER, mc); + lPLCIInfoIndIE(lp, IE_PROGRESS, CAPI_INFOMASK_PROGRESS, mc); + lPLCIInfoIndIE(lp, IE_FACILITY, CAPI_INFOMASK_FACILITY, mc); + } + FsmEvent(&lp->plci_m, EV_L3_DISCONNECT_IND, mc); + break; + case MT_RELEASE: + if (mc->l3m) { + lPLCIInfoIndIE(lp, IE_CAUSE, CAPI_INFOMASK_CAUSE, mc); + lPLCIInfoIndIE(lp, IE_DISPLAY, CAPI_INFOMASK_DISPLAY, mc); + lPLCIInfoIndIE(lp, IE_USER_USER, CAPI_INFOMASK_USERUSER, mc); + lPLCIInfoIndIE(lp, IE_FACILITY, CAPI_INFOMASK_FACILITY, mc); + } + FsmEvent(&lp->plci_m, EV_L3_RELEASE_IND, mc); + break; + case MT_RELEASE_COMPLETE: + if (mc->l3m) { + lPLCIInfoIndIE(lp, IE_CAUSE, CAPI_INFOMASK_CAUSE, mc); + lPLCIInfoIndIE(lp, IE_DISPLAY, CAPI_INFOMASK_DISPLAY, mc); + lPLCIInfoIndIE(lp, IE_USER_USER, CAPI_INFOMASK_USERUSER, mc); + lPLCIInfoIndIE(lp, IE_FACILITY, CAPI_INFOMASK_FACILITY, mc); + } + FsmEvent(&lp->plci_m, EV_L3_RELEASE_IND, mc); + break; + case MT_FREE: + FsmEvent(&lp->plci_m, EV_L3_RELEASE_PROC_IND, mc); + break; + case MT_SETUP_ACKNOWLEDGE: + if (mc->l3m) { + lPLCIInfoIndMsg(lp, CAPI_INFOMASK_PROGRESS, MT_SETUP_ACKNOWLEDGE, mc); + lPLCIInfoIndIE(lp, IE_DISPLAY, CAPI_INFOMASK_DISPLAY, mc); + lPLCIInfoIndIE(lp, IE_PROGRESS, CAPI_INFOMASK_PROGRESS | CAPI_INFOMASK_EARLYB3, mc); + lPLCIInfoIndIE(lp, IE_CHANNEL_ID, CAPI_INFOMASK_CHANNELID, mc); + ret = plci_parse_channel_id(lp, mc); + if (ret < -1) { + wprint("Got channel coding error in %s (%d)\n", _mi_msg_type2str(pr), ret); } - FsmEvent(&lp->plci_m, EV_L3_SETUP_COMPL_IND, mc); - break; - case MT_DISCONNECT: - if (mc->l3m) { - lPLCIInfoIndMsg(lp, CAPI_INFOMASK_EARLYB3, MT_DISCONNECT, mc); - lPLCIInfoIndIE(lp, IE_CAUSE, CAPI_INFOMASK_CAUSE, mc); - lPLCIInfoIndIE(lp, IE_DISPLAY, CAPI_INFOMASK_DISPLAY, mc); - lPLCIInfoIndIE(lp, IE_USER_USER, CAPI_INFOMASK_USERUSER, mc); - lPLCIInfoIndIE(lp, IE_PROGRESS, CAPI_INFOMASK_PROGRESS, mc); - lPLCIInfoIndIE(lp, IE_FACILITY, CAPI_INFOMASK_FACILITY, mc); + } + break; + case MT_CALL_PROCEEDING: + if (mc->l3m) { + lPLCIInfoIndMsg(lp, CAPI_INFOMASK_PROGRESS, MT_CALL_PROCEEDING, mc); + lPLCIInfoIndIE(lp, IE_DISPLAY, CAPI_INFOMASK_DISPLAY, mc); + lPLCIInfoIndIE(lp, IE_PROGRESS, CAPI_INFOMASK_PROGRESS | CAPI_INFOMASK_EARLYB3, mc); + lPLCIInfoIndIE(lp, IE_CHANNEL_ID, CAPI_INFOMASK_CHANNELID, mc); + } + break; + case MT_ALERTING: + if (mc->l3m) { + lPLCIInfoIndMsg(lp, CAPI_INFOMASK_PROGRESS, MT_ALERTING, mc); + lPLCIInfoIndIE(lp, IE_DISPLAY, CAPI_INFOMASK_DISPLAY, mc); + lPLCIInfoIndIE(lp, IE_USER_USER, CAPI_INFOMASK_USERUSER, mc); + lPLCIInfoIndIE(lp, IE_PROGRESS, CAPI_INFOMASK_PROGRESS | CAPI_INFOMASK_EARLYB3, mc); + lPLCIInfoIndIE(lp, IE_FACILITY, CAPI_INFOMASK_FACILITY, mc); + lPLCIInfoIndIE(lp, IE_CHANNEL_ID, CAPI_INFOMASK_CHANNELID, mc); + ret = plci_parse_channel_id(lp, mc); + if (ret < -1) { + wprint("Got channel coding error in %s (%d)\n", _mi_msg_type2str(pr), ret); } - FsmEvent(&lp->plci_m, EV_L3_DISCONNECT_IND, mc); - break; - case MT_RELEASE: - if (mc->l3m) { - lPLCIInfoIndIE(lp, IE_CAUSE, CAPI_INFOMASK_CAUSE, mc); - lPLCIInfoIndIE(lp, IE_DISPLAY, CAPI_INFOMASK_DISPLAY, mc); - lPLCIInfoIndIE(lp, IE_USER_USER, CAPI_INFOMASK_USERUSER, mc); - lPLCIInfoIndIE(lp, IE_FACILITY, CAPI_INFOMASK_FACILITY, mc); - } - FsmEvent(&lp->plci_m, EV_L3_RELEASE_IND, mc); - break; - case MT_RELEASE_COMPLETE: - if (mc->l3m) { - lPLCIInfoIndIE(lp, IE_CAUSE, CAPI_INFOMASK_CAUSE, mc); - lPLCIInfoIndIE(lp, IE_DISPLAY, CAPI_INFOMASK_DISPLAY, mc); - lPLCIInfoIndIE(lp, IE_USER_USER, CAPI_INFOMASK_USERUSER, mc); - lPLCIInfoIndIE(lp, IE_FACILITY, CAPI_INFOMASK_FACILITY, mc); - } - FsmEvent(&lp->plci_m, EV_L3_RELEASE_IND, mc); - break; - case MT_FREE: - FsmEvent(&lp->plci_m, EV_L3_RELEASE_PROC_IND, mc); - break; - case MT_SETUP_ACKNOWLEDGE: - if (mc->l3m) { - lPLCIInfoIndMsg(lp, CAPI_INFOMASK_PROGRESS, MT_SETUP_ACKNOWLEDGE, mc); - lPLCIInfoIndIE(lp, IE_DISPLAY, CAPI_INFOMASK_DISPLAY, mc); - lPLCIInfoIndIE(lp, IE_PROGRESS, CAPI_INFOMASK_PROGRESS | CAPI_INFOMASK_EARLYB3, mc); - lPLCIInfoIndIE(lp, IE_CHANNEL_ID, CAPI_INFOMASK_CHANNELID, mc); - ret = plci_parse_channel_id(lp, mc); - if (ret < -1) { - wprint("Got channel coding error in %s (%d)\n", _mi_msg_type2str(pr), ret); - } - } - break; - case MT_CALL_PROCEEDING: - if (mc->l3m) { - lPLCIInfoIndMsg(lp, CAPI_INFOMASK_PROGRESS, MT_CALL_PROCEEDING, mc); - lPLCIInfoIndIE(lp, IE_DISPLAY, CAPI_INFOMASK_DISPLAY, mc); - lPLCIInfoIndIE(lp, IE_PROGRESS, CAPI_INFOMASK_PROGRESS | CAPI_INFOMASK_EARLYB3, mc); - lPLCIInfoIndIE(lp, IE_CHANNEL_ID, CAPI_INFOMASK_CHANNELID, mc); - } - break; - case MT_ALERTING: - if (mc->l3m) { - lPLCIInfoIndMsg(lp, CAPI_INFOMASK_PROGRESS, MT_ALERTING, mc); - lPLCIInfoIndIE(lp, IE_DISPLAY, CAPI_INFOMASK_DISPLAY, mc); - lPLCIInfoIndIE(lp, IE_USER_USER, CAPI_INFOMASK_USERUSER, mc); - lPLCIInfoIndIE(lp, IE_PROGRESS, CAPI_INFOMASK_PROGRESS | CAPI_INFOMASK_EARLYB3, mc); - lPLCIInfoIndIE(lp, IE_FACILITY, CAPI_INFOMASK_FACILITY, mc); - lPLCIInfoIndIE(lp, IE_CHANNEL_ID, CAPI_INFOMASK_CHANNELID, mc); - ret = plci_parse_channel_id(lp, mc); - if (ret < -1) { - wprint("Got channel coding error in %s (%d)\n", _mi_msg_type2str(pr), ret); - } - } - break; - case MT_PROGRESS: - if (mc->l3m) { - lPLCIInfoIndMsg(lp, CAPI_INFOMASK_PROGRESS, MT_PROGRESS, mc); - lPLCIInfoIndIE(lp, IE_CAUSE, CAPI_INFOMASK_CAUSE, mc); - lPLCIInfoIndIE(lp, IE_DISPLAY, CAPI_INFOMASK_DISPLAY, mc); - lPLCIInfoIndIE(lp, IE_USER_USER, CAPI_INFOMASK_USERUSER, mc); - lPLCIInfoIndIE(lp, IE_PROGRESS, CAPI_INFOMASK_PROGRESS | CAPI_INFOMASK_EARLYB3, mc); - } - break; - case MT_HOLD: - if (mc->l3m) - lPLCIInfoIndIE(lp, IE_DISPLAY, CAPI_INFOMASK_DISPLAY, mc); - if (FsmEvent(&lp->plci_m, EV_L3_HOLD_IND, mc)) { - /* no routine reject L3 */ - plciL4L3(lp->PLCI, MT_HOLD_REJECT, NULL); - } - break; - case MT_HOLD_ACKNOWLEDGE: - if (mc->l3m) - lPLCIInfoIndIE(lp, IE_DISPLAY, CAPI_INFOMASK_DISPLAY, mc); - FsmEvent(&lp->plci_m, EV_L3_HOLD_ACKNOWLEDGE, mc); - break; - case MT_HOLD_REJECT: - if (mc->l3m) { - lPLCIInfoIndIE(lp, IE_CAUSE, CAPI_INFOMASK_CAUSE, mc); - lPLCIInfoIndIE(lp, IE_DISPLAY, CAPI_INFOMASK_DISPLAY, mc); - } - FsmEvent(&lp->plci_m, EV_L3_HOLD_REJECT, mc); - break; - case MT_RETRIEVE: - if (mc->l3m) { - lPLCIInfoIndIE(lp, IE_DISPLAY, CAPI_INFOMASK_DISPLAY, mc); - lPLCIInfoIndIE(lp, IE_CHANNEL_ID, CAPI_INFOMASK_CHANNELID, mc); - } - if (FsmEvent(&lp->plci_m, EV_L3_RETRIEVE_IND, mc)) { - /* no routine reject L3 */ - plciL4L3(lp->PLCI, MT_RETRIEVE_REJECT, NULL); - } - break; - case MT_RETRIEVE_ACKNOWLEDGE: - if (mc->l3m) { - lPLCIInfoIndIE(lp, IE_DISPLAY, CAPI_INFOMASK_DISPLAY, mc); - lPLCIInfoIndIE(lp, IE_CHANNEL_ID, CAPI_INFOMASK_CHANNELID, mc); - } - FsmEvent(&lp->plci_m, EV_L3_RETRIEVE_ACKNOWLEDGE, mc); - break; - case MT_RETRIEVE_REJECT: - if (mc->l3m) { - lPLCIInfoIndIE(lp, IE_CAUSE, CAPI_INFOMASK_CAUSE, mc); - lPLCIInfoIndIE(lp, IE_DISPLAY, CAPI_INFOMASK_DISPLAY, mc); - } - FsmEvent(&lp->plci_m, EV_L3_RETRIEVE_REJECT, mc); - break; - case MT_SUSPEND_ACKNOWLEDGE: - FsmEvent(&lp->plci_m, EV_L3_SUSPEND_CONF, mc); - break; - case MT_SUSPEND_REJECT: - FsmEvent(&lp->plci_m, EV_L3_SUSPEND_ERR, mc); - break; - case MT_RESUME_ACKNOWLEDGE: - FsmEvent(&lp->plci_m, EV_L3_RESUME_CONF, mc); - break; - case MT_RESUME_REJECT: - FsmEvent(&lp->plci_m, EV_L3_RESUME_ERR, mc); - break; - case MT_NOTIFY: - FsmEvent(&lp->plci_m, EV_L3_NOTIFY_IND, mc); - break; - case PH_CONTROL_IND: - /* TOUCH TONE */ - FsmEvent(&lp->plci_m, EV_PH_CONTROL_IND, mc); - break; - default: - wprint("PLCI %x pr 0x%x not handled\n", lp->plci, pr); - break; + } + break; + case MT_PROGRESS: + if (mc->l3m) { + lPLCIInfoIndMsg(lp, CAPI_INFOMASK_PROGRESS, MT_PROGRESS, mc); + lPLCIInfoIndIE(lp, IE_CAUSE, CAPI_INFOMASK_CAUSE, mc); + lPLCIInfoIndIE(lp, IE_DISPLAY, CAPI_INFOMASK_DISPLAY, mc); + lPLCIInfoIndIE(lp, IE_USER_USER, CAPI_INFOMASK_USERUSER, mc); + lPLCIInfoIndIE(lp, IE_PROGRESS, CAPI_INFOMASK_PROGRESS | CAPI_INFOMASK_EARLYB3, mc); + } + break; + case MT_HOLD: + if (mc->l3m) + lPLCIInfoIndIE(lp, IE_DISPLAY, CAPI_INFOMASK_DISPLAY, mc); + if (FsmEvent(&lp->plci_m, EV_L3_HOLD_IND, mc)) { + /* no routine reject L3 */ + plciL4L3(lp->PLCI, MT_HOLD_REJECT, NULL); + } + break; + case MT_HOLD_ACKNOWLEDGE: + if (mc->l3m) + lPLCIInfoIndIE(lp, IE_DISPLAY, CAPI_INFOMASK_DISPLAY, mc); + FsmEvent(&lp->plci_m, EV_L3_HOLD_ACKNOWLEDGE, mc); + break; + case MT_HOLD_REJECT: + if (mc->l3m) { + lPLCIInfoIndIE(lp, IE_CAUSE, CAPI_INFOMASK_CAUSE, mc); + lPLCIInfoIndIE(lp, IE_DISPLAY, CAPI_INFOMASK_DISPLAY, mc); + } + FsmEvent(&lp->plci_m, EV_L3_HOLD_REJECT, mc); + break; + case MT_RETRIEVE: + if (mc->l3m) { + lPLCIInfoIndIE(lp, IE_DISPLAY, CAPI_INFOMASK_DISPLAY, mc); + lPLCIInfoIndIE(lp, IE_CHANNEL_ID, CAPI_INFOMASK_CHANNELID, mc); + } + if (FsmEvent(&lp->plci_m, EV_L3_RETRIEVE_IND, mc)) { + /* no routine reject L3 */ + plciL4L3(lp->PLCI, MT_RETRIEVE_REJECT, NULL); + } + break; + case MT_RETRIEVE_ACKNOWLEDGE: + if (mc->l3m) { + lPLCIInfoIndIE(lp, IE_DISPLAY, CAPI_INFOMASK_DISPLAY, mc); + lPLCIInfoIndIE(lp, IE_CHANNEL_ID, CAPI_INFOMASK_CHANNELID, mc); + } + FsmEvent(&lp->plci_m, EV_L3_RETRIEVE_ACKNOWLEDGE, mc); + break; + case MT_RETRIEVE_REJECT: + if (mc->l3m) { + lPLCIInfoIndIE(lp, IE_CAUSE, CAPI_INFOMASK_CAUSE, mc); + lPLCIInfoIndIE(lp, IE_DISPLAY, CAPI_INFOMASK_DISPLAY, mc); + } + FsmEvent(&lp->plci_m, EV_L3_RETRIEVE_REJECT, mc); + break; + case MT_SUSPEND_ACKNOWLEDGE: + FsmEvent(&lp->plci_m, EV_L3_SUSPEND_CONF, mc); + break; + case MT_SUSPEND_REJECT: + FsmEvent(&lp->plci_m, EV_L3_SUSPEND_ERR, mc); + break; + case MT_RESUME_ACKNOWLEDGE: + FsmEvent(&lp->plci_m, EV_L3_RESUME_CONF, mc); + break; + case MT_RESUME_REJECT: + FsmEvent(&lp->plci_m, EV_L3_RESUME_ERR, mc); + break; + case MT_NOTIFY: + FsmEvent(&lp->plci_m, EV_L3_NOTIFY_IND, mc); + break; + case PH_CONTROL_IND: + /* TOUCH TONE */ + FsmEvent(&lp->plci_m, EV_PH_CONTROL_IND, mc); + break; + default: + wprint("PLCI %x pr 0x%x not handled\n", lp->plci, pr); + break; } } -void -lPLCIGetCmsg(struct lPLCI *lp, struct mc_buf *mc) +void lPLCIGetCmsg(struct lPLCI *lp, struct mc_buf *mc) { - int retval = 0; + int retval = 0; switch (CMSGCMD(&mc->cmsg)) { - case CAPI_INFO_REQ: - retval = FsmEvent(&lp->plci_m, EV_AP_INFO_REQ, mc); - break; - case CAPI_ALERT_REQ: - retval = FsmEvent(&lp->plci_m, EV_AP_ALERT_REQ, mc); - break; - case CAPI_CONNECT_REQ: - retval = FsmEvent(&lp->plci_m, EV_AP_CONNECT_REQ, mc); - break; - case CAPI_CONNECT_RESP: - retval = FsmEvent(&lp->plci_m, EV_AP_CONNECT_RESP, mc); - break; - case CAPI_DISCONNECT_REQ: - retval = FsmEvent(&lp->plci_m, EV_AP_DISCONNECT_REQ, mc); - break; - case CAPI_DISCONNECT_RESP: - retval = FsmEvent(&lp->plci_m, EV_AP_DISCONNECT_RESP, mc); - break; - case CAPI_CONNECT_ACTIVE_RESP: - retval = FsmEvent(&lp->plci_m, EV_AP_CONNECT_ACTIVE_RESP, mc); - break; - case CAPI_SELECT_B_PROTOCOL_REQ: - retval = FsmEvent(&lp->plci_m, EV_AP_SELECT_B_PROTOCOL_REQ, mc); - break; - default: - wprint("PLCI:%x command %02x/%02x not handled\n", lp->plci, mc->cmsg.Command, mc->cmsg.Subcommand); - retval = -1; + case CAPI_INFO_REQ: + retval = FsmEvent(&lp->plci_m, EV_AP_INFO_REQ, mc); + break; + case CAPI_ALERT_REQ: + retval = FsmEvent(&lp->plci_m, EV_AP_ALERT_REQ, mc); + break; + case CAPI_CONNECT_REQ: + retval = FsmEvent(&lp->plci_m, EV_AP_CONNECT_REQ, mc); + break; + case CAPI_CONNECT_RESP: + retval = FsmEvent(&lp->plci_m, EV_AP_CONNECT_RESP, mc); + break; + case CAPI_DISCONNECT_REQ: + retval = FsmEvent(&lp->plci_m, EV_AP_DISCONNECT_REQ, mc); + break; + case CAPI_DISCONNECT_RESP: + retval = FsmEvent(&lp->plci_m, EV_AP_DISCONNECT_RESP, mc); + break; + case CAPI_CONNECT_ACTIVE_RESP: + retval = FsmEvent(&lp->plci_m, EV_AP_CONNECT_ACTIVE_RESP, mc); + break; + case CAPI_SELECT_B_PROTOCOL_REQ: + retval = FsmEvent(&lp->plci_m, EV_AP_SELECT_B_PROTOCOL_REQ, mc); + break; + default: + wprint("PLCI:%x command %02x/%02x not handled\n", lp->plci, mc->cmsg.Command, mc->cmsg.Subcommand); + retval = -1; } - if (retval) { + if (retval) { if (mc->cmsg.Subcommand == CAPI_REQ) { capi_cmsg_answer(&mc->cmsg); mc->cmsg.Info = CapiMessageNotSupportedInCurrentState; @@ -2010,7 +1966,7 @@ lPLCIGetCmsg(struct lPLCI *lp, struct mc_buf *mc) uint16_t lPLCISendMessage(struct lPLCI *lp, struct mc_buf *mc) { - uint16_t ret; + uint16_t ret; lPLCIGetCmsg(lp, mc); ret = CapiNoError; @@ -2019,14 +1975,14 @@ uint16_t lPLCISendMessage(struct lPLCI *lp, struct mc_buf *mc) struct mNCCI *ConnectB3Request(struct lPLCI *lp, struct mc_buf *mc) { - struct mNCCI *ncci = ncciCreate(lp); + struct mNCCI *ncci = ncciCreate(lp); if (!ncci) { wprint("Could not create NCCI for PCLI %04x\n", lp->plci); } else if (!ncci->BIlink) { wprint("No channel instance assigned for PCLI %04x\n", lp->plci); } - return ncci; + return ncci; } static int lPLCILinkDown(struct lPLCI *lp) @@ -2049,14 +2005,12 @@ static int lPLCILinkDown(struct lPLCI *lp) return 0; } -int -lPLCIFacHoldReq(struct lPLCI *lp, struct FacReqParm *facReqParm, struct FacConfParm *facConfParm) +int lPLCIFacHoldReq(struct lPLCI *lp, struct FacReqParm *facReqParm, struct FacConfParm *facConfParm) { /* no parameter needed so we do not need a l3m */ if (FsmEvent(&lp->plci_m, EV_AP_HOLD_REQ, NULL)) { // no routine - facConfParm->u.Info.SupplementaryServiceInfo = - CapiRequestNotAllowedInThisState; + facConfParm->u.Info.SupplementaryServiceInfo = CapiRequestNotAllowedInThisState; return CapiMessageNotSupportedInCurrentState; } else { facConfParm->u.Info.SupplementaryServiceInfo = CapiNoError; @@ -2064,14 +2018,12 @@ lPLCIFacHoldReq(struct lPLCI *lp, struct FacReqParm *facReqParm, struct FacConfP return CapiNoError; } -int -lPLCIFacRetrieveReq(struct lPLCI *lp, struct FacReqParm *facReqParm, struct FacConfParm *facConfParm) +int lPLCIFacRetrieveReq(struct lPLCI *lp, struct FacReqParm *facReqParm, struct FacConfParm *facConfParm) { /* no parameter needed so we do not need a l3m */ if (FsmEvent(&lp->plci_m, EV_AP_RETRIEVE_REQ, NULL)) { // no routine - facConfParm->u.Info.SupplementaryServiceInfo = - CapiRequestNotAllowedInThisState; + facConfParm->u.Info.SupplementaryServiceInfo = CapiRequestNotAllowedInThisState; return CapiMessageNotSupportedInCurrentState; } else { facConfParm->u.Info.SupplementaryServiceInfo = CapiNoError; @@ -2079,16 +2031,15 @@ lPLCIFacRetrieveReq(struct lPLCI *lp, struct FacReqParm *facReqParm, struct FacC return CapiNoError; } -int -lPLCIFacSuspendReq(struct lPLCI *lp, struct FacReqParm *facReqParm, struct FacConfParm *facConfParm) +int lPLCIFacSuspendReq(struct lPLCI *lp, struct FacReqParm *facReqParm, struct FacConfParm *facConfParm) { - unsigned char *CallId; - struct l3_msg *l3m; + unsigned char *CallId; + struct l3_msg *l3m; CallId = facReqParm->u.Suspend.CallIdentity; - if (CallId && CallId[0] > 8) + if (CallId && CallId[0] > 8) return CapiIllMessageParmCoding; - l3m = alloc_l3_msg(); + l3m = alloc_l3_msg(); if (!l3m) { wprint("Could not allocate l3 message for PLCI %04x\n", lp->plci); return CapiMsgOSResourceErr; @@ -2098,8 +2049,7 @@ lPLCIFacSuspendReq(struct lPLCI *lp, struct FacReqParm *facReqParm, struct FacCo if (FsmEvent(&lp->plci_m, EV_AP_SUSPEND_REQ, l3m)) { // no routine - facConfParm->u.Info.SupplementaryServiceInfo = - CapiRequestNotAllowedInThisState; + facConfParm->u.Info.SupplementaryServiceInfo = CapiRequestNotAllowedInThisState; free_l3_msg(l3m); return CapiMessageNotSupportedInCurrentState; } else { @@ -2108,18 +2058,17 @@ lPLCIFacSuspendReq(struct lPLCI *lp, struct FacReqParm *facReqParm, struct FacCo return CapiNoError; } -int -lPLCIFacResumeReq(struct lPLCI *lp, struct FacReqParm *facReqParm, struct FacConfParm *facConfParm) +int lPLCIFacResumeReq(struct lPLCI *lp, struct FacReqParm *facReqParm, struct FacConfParm *facConfParm) { - __u8 *CallId; - struct l3_msg *l3m; + __u8 *CallId; + struct l3_msg *l3m; CallId = facReqParm->u.Resume.CallIdentity; if (CallId && CallId[0] > 8) { lPLCI_free(lp); return CapiIllMessageParmCoding; } - l3m = alloc_l3_msg(); + l3m = alloc_l3_msg(); if (!l3m) { wprint("Could not allocate l3 message for PLCI %04x\n", lp->plci); lPLCI_free(lp); @@ -2145,11 +2094,10 @@ void init_lPLCI_fsm(void) plci_fsm.event_count = EV_PLCI_COUNT; plci_fsm.strEvent = str_ev_plci; plci_fsm.strState = str_st_plci; - + FsmNew(&plci_fsm, fn_plci_list, FN_PLCI_COUNT); } - void free_lPLCI_fsm(void) { FsmFree(&plci_fsm); diff --git a/capi20/m_capi.h b/capi20/m_capi.h index c5ba4a8..ab2d3fe 100644 --- a/capi20/m_capi.h +++ b/capi20/m_capi.h @@ -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) diff --git a/capi20/mplci.c b/capi20/mplci.c index 26249ee..7c7f9d0 100644 --- a/capi20/mplci.c +++ b/capi20/mplci.c @@ -20,10 +20,9 @@ #include "mc_buffer.h" #include - 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; } diff --git a/capi20/ncci.c b/capi20/ncci.c index 544cc21..750ad2c 100644 --- a/capi20/ncci.c +++ b/capi20/ncci.c @@ -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", @@ -53,7 +51,7 @@ static char *str_st_ncci[] = { "ST_NCCI_N_3", "ST_NCCI_N_4", "ST_NCCI_N_5", -}; +}; enum { EV_AP_CONNECT_B3_REQ, @@ -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,14 +111,13 @@ 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; va_list args; struct mNCCI *ncci = fi->userdata; - + if (!ncci->ncci_m.debug) return; va_start(args, fmt); @@ -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,18 +195,17 @@ 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) - */ + */ capi_cmsg_answer(&mc->cmsg); mc->cmsg.Info = Info; FsmEvent(fi, EV_NC_DISCONNECT_B3_CONF, mc); @@ -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,122 +226,117 @@ 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; - dprintf(MIDEBUG_NCCI, "NCCI %06x: fac\n", ncci->ncci); + dprintf(MIDEBUG_NCCI, "NCCI %06x: fac\n", ncci->ncci); 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) { @@ -531,7 +502,7 @@ static void initNCCIHeaders(struct mNCCI *nc) nc->up_msg.msg_flags = 0; nc->up_iv[0].iov_base = nc->up_header; nc->up_iv[0].iov_len = CAPI_B3_DATA_IND_HEADER_SIZE; - + nc->down_header.prim = nc->l1direct ? PH_DATA_REQ : DL_DATA_REQ; nc->down_msg.msg_name = NULL; nc->down_msg.msg_namelen = 0; @@ -542,10 +513,9 @@ static void initNCCIHeaders(struct mNCCI *nc) nc->down_msg.msg_flags = 0; nc->down_iv[0].iov_base = &nc->down_header; 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,13 +577,12 @@ 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); - + /* cleanup data queues */ for (i = 0; i < CAPI_MAXDATAWINDOW; i++) { if (ncci->xmit_handles[i].pkt) @@ -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) { @@ -816,9 +782,9 @@ static uint16_t ncciDataReq(struct mNCCI *ncci, struct mc_buf *mc) mc->rp = mc->rb + off; mc->len = len; 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); @@ -868,7 +834,7 @@ static int ncciDataInd(struct mNCCI *ncci, int pr, struct mc_buf *mc) dh = ++ncci->BIlink->UpId; ncci->recv_handles[i] = dh; - + CAPIMSG_SETMSGID(ncci->up_header, ncci->appl->MsgId++); CAPIMSG_SETDATALEN(ncci->up_header, dlen); capimsg_setu16(ncci->up_header, 18, dh); @@ -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 (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); }