Allow different B data handler

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

View File

@ -11,15 +11,15 @@
* this package for more details. * this package for more details.
*/ */
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#include "m_capi.h" #include "m_capi.h"
#include "mc_buffer.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; struct mApplication *appl, *old = mApplications;
@ -79,14 +79,14 @@ void ReleaseApplication(struct mApplication *appl)
} }
/* TODO clean controller refs */ /* TODO clean controller refs */
close(appl->fd); close(appl->fd);
free(appl); free(appl);
#if 0 #if 0
int i, used = 0; int i, used = 0;
AppPlci_t **aplci_p = appl->AppPlcis; AppPlci_t **aplci_p = appl->AppPlcis;
if (test_and_set_bit(APPL_STATE_DESTRUCTOR, &appl->state)) { if (test_and_set_bit(APPL_STATE_DESTRUCTOR, &appl->state)) {
// we are allready in this function // we are allready in this function
return(-EBUSY); return (-EBUSY);
} }
test_and_set_bit(APPL_STATE_RELEASE, &appl->state); test_and_set_bit(APPL_STATE_RELEASE, &appl->state);
test_and_clear_bit(APPL_STATE_ACTIV, &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++) { for (i = 0; i < appl->maxplci; i++) {
if (*aplci_p) { if (*aplci_p) {
switch (who) { switch (who) {
case 4: case 4:
AppPlciDestr(*aplci_p); AppPlciDestr(*aplci_p);
*aplci_p = NULL; *aplci_p = NULL;
break; break;
case 1: case 1:
case 2: case 2:
case 3: case 3:
AppPlciRelease(*aplci_p); AppPlciRelease(*aplci_p);
case 0: case 0:
if ((volatile AppPlci_t *)(*aplci_p)) if ((volatile AppPlci_t *)(*aplci_p))
used++; used++;
break; break;
} }
} }
aplci_p++; aplci_p++;
@ -121,14 +121,14 @@ void ReleaseApplication(struct mApplication *appl)
list_add(&appl->head, &garbage_applications); list_add(&appl->head, &garbage_applications);
} }
test_and_clear_bit(APPL_STATE_DESTRUCTOR, &appl->state); test_and_clear_bit(APPL_STATE_DESTRUCTOR, &appl->state);
return(-EBUSY); return (-EBUSY);
} }
list_del_init(&appl->head); list_del_init(&appl->head);
appl->maxplci = 0; appl->maxplci = 0;
kfree(appl->AppPlcis); kfree(appl->AppPlcis);
appl->AppPlcis = NULL; appl->AppPlcis = NULL;
kfree(appl); kfree(appl);
return(0); return (0);
#endif #endif
} }
@ -144,18 +144,16 @@ struct lController *get_lController(struct mApplication *app, int cont)
return lc; return lc;
} }
void void SendMessage2Application(struct mApplication *appl, struct mc_buf *mc)
SendMessage2Application(struct mApplication *appl, struct mc_buf *mc)
{ {
int ret; int ret;
ret = send(appl->fd, mc->rb, mc->len, 0); ret = send(appl->fd, mc->rb, mc->len, 0);
if (ret != mc->len) if (ret != mc->len)
wprint("Message send error len=%d ret=%d - %s\n", mc->len, ret, strerror(errno)); wprint("Message send error len=%d ret=%d - %s\n", mc->len, ret, strerror(errno));
} }
void void SendCmsg2Application(struct mApplication *appl, struct mc_buf *mc)
SendCmsg2Application(struct mApplication *appl, struct mc_buf *mc)
{ {
int ret; int ret;
@ -165,12 +163,11 @@ SendCmsg2Application(struct mApplication *appl, struct mc_buf *mc)
if (ret != mc->len) if (ret != mc->len)
eprint("Message send error len=%d ret=%d - %s\n", mc->len, ret, strerror(errno)); eprint("Message send error len=%d ret=%d - %s\n", mc->len, ret, strerror(errno));
else else
dprint(MIDEBUG_NCCI_DATA, "Msg: %02x/%02x %s addr %x len %d/%d\n", mc->rb[4], mc->rb[5], 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); capi20_cmd2str(mc->rb[4], mc->rb[5]), CAPIMSG_CONTROL(mc->rb), mc->len, ret);
} }
void void SendCmsgAnswer2Application(struct mApplication *appl, struct mc_buf *mc, __u16 Info)
SendCmsgAnswer2Application(struct mApplication *appl, struct mc_buf *mc, __u16 Info)
{ {
capi_cmsg_answer(&mc->cmsg); capi_cmsg_answer(&mc->cmsg);
mc->cmsg.Info = Info; mc->cmsg.Info = Info;
@ -179,52 +176,51 @@ SendCmsgAnswer2Application(struct mApplication *appl, struct mc_buf *mc, __u16 I
#define CapiFacilityNotSupported 0x300b #define CapiFacilityNotSupported 0x300b
static int static int FacilityMessage(struct mApplication *appl, struct pController *pc, struct mc_buf *mc)
FacilityMessage(struct mApplication *appl, struct pController *pc, struct mc_buf *mc)
{ {
int ret = CapiNoError; int ret = CapiNoError;
struct mPLCI *plci; struct mPLCI *plci;
struct lPLCI *lp; struct lPLCI *lp;
struct mNCCI *ncci; struct mNCCI *ncci;
unsigned char tmp[64], *p; unsigned char tmp[64], *p;
p = tmp; p = tmp;
switch (mc->cmsg.FacilitySelector) { switch (mc->cmsg.FacilitySelector) {
#if 0 #if 0
case 0x0000: // Handset case 0x0000: // Handset
#endif #endif
case 0x0001: // DTMF case 0x0001: // DTMF
dprint(MIDEBUG_CONTROLLER, "DTMF addr %06x\n", mc->cmsg.adr.adrNCCI); dprint(MIDEBUG_CONTROLLER, "DTMF addr %06x\n", mc->cmsg.adr.adrNCCI);
plci = getPLCI4Id(pc, mc->cmsg.adr.adrPLCI & 0xFFFF); plci = getPLCI4Id(pc, mc->cmsg.adr.adrPLCI & 0xFFFF);
lp = get_lPLCI4Id(plci, mc->cmsg.ApplId); lp = get_lPLCI4Id(plci, mc->cmsg.ApplId);
if (lp) { if (lp) {
ncci = getNCCI4addr(lp, mc->cmsg.adr.adrNCCI, GET_NCCI_PLCI); ncci = getNCCI4addr(lp, mc->cmsg.adr.adrNCCI, GET_NCCI_PLCI);
if (ncci) { if (ncci) {
ret = ncciSendMessage(ncci, mc->cmsg.Command, mc->cmsg.Subcommand, mc); 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;
}
} else { } else {
wprint("DTMF addr %06x lPLCI not found\n", mc->cmsg.adr.adrNCCI); wprint("DTMF addr %06x NCCI not found\n", mc->cmsg.adr.adrNCCI);
ret = CapiIllController; ret = CapiIllController;
} }
break; } else {
case 0x0003: // SupplementaryServices wprint("DTMF addr %06x lPLCI not found\n", mc->cmsg.adr.adrNCCI);
// ret = SupplementaryFacilityReq(appl, mc); ret = CapiIllController;
capimsg_setu8(p, 0, 9); }
capimsg_setu16(p, 1, 0); break;
capimsg_setu8(p, 3, 6); case 0x0003: // SupplementaryServices
capimsg_setu16(p, 4, 0); // ret = SupplementaryFacilityReq(appl, mc);
capimsg_setu32(p, 6, 0); capimsg_setu8(p, 0, 9);
mc->cmsg.FacilityConfirmationParameter = tmp; capimsg_setu16(p, 1, 0);
SendCmsgAnswer2Application(appl, mc, ret); capimsg_setu8(p, 3, 6);
free_mc_buf(mc); capimsg_setu16(p, 4, 0);
ret = CapiNoError; capimsg_setu32(p, 6, 0);
break; mc->cmsg.FacilityConfirmationParameter = tmp;
default: SendCmsgAnswer2Application(appl, mc, ret);
ret = CapiFacilityNotSupported; free_mc_buf(mc);
break; ret = CapiNoError;
break;
default:
ret = CapiFacilityNotSupported;
break;
} }
return ret; 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 PutMessageApplication(struct mApplication *appl, struct mc_buf *mc)
{ {
int id; int id;
struct pController *pc; struct pController *pc;
struct lController *lc; struct lController *lc;
struct mPLCI *plci; struct mPLCI *plci;
struct lPLCI *lp; struct lPLCI *lp;
struct mNCCI *ncci; struct mNCCI *ncci;
uint8_t cmd, subcmd; uint8_t cmd, subcmd;
int ret = CapiNoError; int ret = CapiNoError;
@ -252,14 +248,14 @@ int PutMessageApplication(struct mApplication *appl, struct mc_buf *mc)
lc = get_lController(appl, id & 0x7f); lc = get_lController(appl, id & 0x7f);
if (lc) if (lc)
pc = lc->Contr; pc = lc->Contr;
else else
pc = get_cController(id & 0x7f); pc = get_cController(id & 0x7f);
if (!pc) { if (!pc) {
eprint("message %x controller for id %06x not found\n", cmd, id); 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)); dprint(MIDEBUG_CONTROLLER, "ID: %06x cmd %02x/%02x %s\n", id, cmd, subcmd, capi20_cmd2str(cmd, subcmd));
switch(cmd) { switch (cmd) {
// for NCCI state machine // for NCCI state machine
case CAPI_DATA_B3: case CAPI_DATA_B3:
case CAPI_CONNECT_B3_ACTIVE: case CAPI_CONNECT_B3_ACTIVE:
case CAPI_DISCONNECT_B3: case CAPI_DISCONNECT_B3:
@ -273,8 +269,8 @@ int PutMessageApplication(struct mApplication *appl, struct mc_buf *mc)
ret = ncciSendMessage(ncci, cmd, subcmd, mc); ret = ncciSendMessage(ncci, cmd, subcmd, mc);
else { else {
wprint("Application%d: cmd %x (%s) plci %04x lplci %04x NCCI not found\n", appl->AppId, cmd, 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), capi20_cmd2str(mc->cmsg.Command, mc->cmsg.Subcommand),
plci ? plci->plci : 0xffff, lp ? lp->plci : 0xffff); plci ? plci->plci : 0xffff, lp ? lp->plci : 0xffff);
ret = CapiIllController; ret = CapiIllController;
} }
} else } else
@ -298,18 +294,18 @@ int PutMessageApplication(struct mApplication *appl, struct mc_buf *mc)
ret = ncciSendMessage(ncci, cmd, subcmd, mc); ret = ncciSendMessage(ncci, cmd, subcmd, mc);
else { else {
wprint("Application%d: cmd %x (%s) plci %04x lplci %04x NCCI not found\n", appl->AppId, cmd, 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), capi20_cmd2str(mc->cmsg.Command, mc->cmsg.Subcommand),
plci ? plci->plci : 0xffff, lp ? lp->plci : 0xffff); plci ? plci->plci : 0xffff, lp ? lp->plci : 0xffff);
ret = CapiIllController; ret = CapiIllController;
} }
break; break;
// for PLCI state machine // for PLCI state machine
case CAPI_CONNECT: case CAPI_CONNECT:
case CAPI_INFO: case CAPI_INFO:
mcbuf_rb2cmsg(mc); mcbuf_rb2cmsg(mc);
plci = getPLCI4Id(pc, mc->cmsg.adr.adrPLCI); 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, 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 (subcmd == CAPI_REQ) {
if (plci) { if (plci) {
lp = get_lPLCI4Id(plci, mc->cmsg.ApplId); lp = get_lPLCI4Id(plci, mc->cmsg.ApplId);
@ -317,7 +313,7 @@ int PutMessageApplication(struct mApplication *appl, struct mc_buf *mc)
ret = lPLCISendMessage(lp, mc); ret = lPLCISendMessage(lp, mc);
else { else {
wprint("%s adrPLCI %06x plci:%04x ApplId %d no plci found\n", capi20_cmd2str(cmd, subcmd), 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; ret = CapiIllController;
} }
} else { } else {
@ -341,7 +337,7 @@ int PutMessageApplication(struct mApplication *appl, struct mc_buf *mc)
ret = lPLCISendMessage(lp, mc); ret = lPLCISendMessage(lp, mc);
else { else {
wprint("%s adrPLCI %06x plci:%04x ApplId %d no plci found\n", capi20_cmd2str(cmd, subcmd), 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; ret = CapiIllController;
} }
} else } else
@ -356,7 +352,7 @@ int PutMessageApplication(struct mApplication *appl, struct mc_buf *mc)
plci = getPLCI4Id(pc, mc->cmsg.adr.adrPLCI); plci = getPLCI4Id(pc, mc->cmsg.adr.adrPLCI);
lp = get_lPLCI4Id(plci, mc->cmsg.ApplId); lp = get_lPLCI4Id(plci, mc->cmsg.ApplId);
dprint(MIDEBUG_PLCI, "adrPLCI %06x plci:%04x ApplId %d lp %p\n", mc->cmsg.adr.adrPLCI, 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) if (lp)
ret = lPLCISendMessage(lp, mc); ret = lPLCISendMessage(lp, mc);
else else
@ -398,4 +394,3 @@ int PutMessageApplication(struct mApplication *appl, struct mc_buf *mc)
SendCmsgAnswer2Application(appl, mc, ret); SendCmsgAnswer2Application(appl, mc, ret);
return ret; return ret;
} }

View File

@ -11,7 +11,7 @@
* this package for more details. * this package for more details.
*/ */
#include <stdio.h> #include <stdio.h>
#include <getopt.h> #include <getopt.h>
#include <string.h> #include <string.h>
#include <stdarg.h> #include <stdarg.h>
@ -31,7 +31,6 @@
#define DEF_CONFIG_FILE "/etc/capi20.conf" #define DEF_CONFIG_FILE "/etc/capi20.conf"
#endif #endif
typedef enum { typedef enum {
PIT_None = 0, PIT_None = 0,
PIT_mISDNmain, PIT_mISDNmain,
@ -44,7 +43,7 @@ typedef enum {
struct pollInfo { struct pollInfo {
pollInfo_t type; pollInfo_t type;
void *data; void *data;
}; };
static struct pollfd *mainpoll; static struct pollfd *mainpoll;
static struct pollInfo *pollinfo; static struct pollInfo *pollinfo;
@ -75,8 +74,7 @@ void usage(void)
fprintf(stderr, "\n"); fprintf(stderr, "\n");
} }
int int opt_parse(int ac, char *av[])
opt_parse(int ac, char *av[])
{ {
int c; int c;
@ -142,7 +140,7 @@ opt_parse(int ac, char *av[])
if (c != 0) { if (c != 0) {
fprintf(stderr, "unknown options: %s\n", av[optind]); fprintf(stderr, "unknown options: %s\n", av[optind]);
return -2; return -2;
} }
return 0; return 0;
} }
@ -176,7 +174,7 @@ static int read_config_file(char *name)
switch (n) { switch (n) {
case 0: case 0:
nr_controller = -1; 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; goto err;
case 1: case 1:
capicontr = contr + 1; capicontr = contr + 1;
@ -189,12 +187,14 @@ static int read_config_file(char *name)
continue; continue;
} }
if (contr < 0 || contr > 126) { 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; nr_controller = -2;
goto err; goto err;
} }
if (capicontr < 1 || capicontr > 127) { 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; nr_controller = -3;
goto err; goto err;
} }
@ -258,7 +258,7 @@ static int add_mainpoll(int fd, pollInfo_t pit)
mainpoll_max++; mainpoll_max++;
} else { } else {
eprint("mainpoll full %d fds\n", mainpoll_size); eprint("mainpoll full %d fds\n", mainpoll_size);
return -1; return -1;
} }
} }
mainpoll[i].fd = fd; mainpoll[i].fd = fd;
@ -277,7 +277,7 @@ static int del_mainpoll(int fd)
mainpoll[i].revents = 0; mainpoll[i].revents = 0;
mainpoll[i].fd = -1; mainpoll[i].fd = -1;
j = i; j = i;
switch(pollinfo[i].type) { switch (pollinfo[i].type) {
default: default:
if (pollinfo[i].data) if (pollinfo[i].data)
free(pollinfo[i].data); free(pollinfo[i].data);
@ -287,7 +287,7 @@ static int del_mainpoll(int fd)
pollinfo[i].type = PIT_None; pollinfo[i].type = PIT_None;
break; 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--; mainpoll_max--;
j--; j--;
} }
@ -326,29 +326,28 @@ struct BInstance *ControllerSelChannel(struct pController *pc, int nr, int proto
if (nr >= pc->BImax) { if (nr >= pc->BImax) {
wprint("Request for channel number %d but controller %d only has %d channels\n", 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; return NULL;
} }
if (ISDN_P_B_START <= proto) { if (ISDN_P_B_START <= proto) {
pmask = 1 << (proto & ISDN_P_B_MASK); pmask = 1 << (proto & ISDN_P_B_MASK);
if (!(pmask & pc->devinfo.Bprotocols)) { if (!(pmask & pc->devinfo.Bprotocols)) {
wprint("Request for channel number %d on controller %d protocol 0x%02x not supported\n", 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; return NULL;
} }
} else { } else {
pmask = 1 << proto; pmask = 1 << proto;
if (!(pmask & pc->devinfo.Dprotocols)) { if (!(pmask & pc->devinfo.Dprotocols)) {
wprint("Request for channel number %d on controller %d protocol 0x%02x not supported\n", 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; return NULL;
} }
} }
bi = pc->BInstances + nr; bi = pc->BInstances + nr;
if (bi->usecnt) { if (bi->usecnt) {
/* for now only one user allowed - this is not sufficient for X25 */ /* 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", wprint("Request for channel number %d on controller %d but channel already in use\n", nr, pc->profile.ncontroller);
nr, pc->profile.ncontroller);
return NULL; return NULL;
} else { } else {
bi->usecnt++; bi->usecnt++;
@ -357,18 +356,18 @@ struct BInstance *ControllerSelChannel(struct pController *pc, int nr, int proto
return bi; return bi;
} }
int OpenBInstance(struct BInstance *bi, struct lPLCI *lp) int OpenBInstance(struct BInstance *bi, struct lPLCI *lp, BDataTrans_t *fromd)
{ {
int sk; int sk;
int ret; int ret;
struct sockaddr_mISDN addr; struct sockaddr_mISDN addr;
sk = socket(PF_ISDN, SOCK_DGRAM, bi->proto); sk = socket(PF_ISDN, SOCK_DGRAM, bi->proto);
if (sk < 0) { if (sk < 0) {
wprint("Cannot open socket for BInstance %d on controller %d protocol 0x%02x - %s\n", 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; return -errno;
} }
ret = fcntl(sk, F_SETFL, O_NONBLOCK); ret = fcntl(sk, F_SETFL, O_NONBLOCK);
if (ret < 0) { if (ret < 0) {
@ -382,32 +381,43 @@ int OpenBInstance(struct BInstance *bi, struct lPLCI *lp)
addr.dev = bi->pc->mNr; addr.dev = bi->pc->mNr;
addr.channel = bi->nr; addr.channel = bi->nr;
ret = bind(sk, (struct sockaddr *) &addr, sizeof(addr)); ret = bind(sk, (struct sockaddr *)&addr, sizeof(addr));
if (ret < 0) { if (ret < 0) {
ret = -errno; ret = -errno;
wprint("Cannot bind socket for BInstance %d on controller %d (mISDN nr %d) protocol 0x%02x - %s\n", 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); close(sk);
} else { } else {
bi->fd = sk; bi->fd = sk;
ret = add_mainpoll(sk, PIT_Bchannel); ret = add_mainpoll(sk, PIT_Bchannel);
if (ret < 0) { if (ret < 0) {
eprint("Error while adding mIsock to mainpoll (mainpoll_max %d)\n", mainpoll_max); eprint("Error while adding mIsock to mainpoll (mainpoll_max %d)\n", mainpoll_max);
} else { } else {
dprint(MIDEBUG_CONTROLLER, "Controller%d: Bchannel %d socket %d added to poll idx %d\n", dprint(MIDEBUG_CONTROLLER, "Controller%d: Bchannel %d socket %d added to poll idx %d\n",
bi->pc->profile.ncontroller, bi->nr, sk, ret); bi->pc->profile.ncontroller, bi->nr, sk, ret);
bi->fd = sk; bi->fd = sk;
pollinfo[ret].data = bi; pollinfo[ret].data = bi;
bi->lp = lp; bi->lp = lp;
ret = 0; ret = 0;
bi->UpId = 0; bi->UpId = 0;
bi->DownId = 0; bi->DownId = 0;
bi->from_down = fromd;
} }
} }
return ret; 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; int ret = 0;
if (bi->usecnt) { if (bi->usecnt) {
@ -422,9 +432,10 @@ int CloseBInstance(struct BInstance *bi) {
ncciReleaseLink(bi->nc); ncciReleaseLink(bi->nc);
bi->nc = NULL; bi->nc = NULL;
bi->lp = NULL; bi->lp = NULL;
bi->from_down = dummy_btrans;
} else { } else {
wprint("BInstance %d not active\n", bi->nr); wprint("BInstance %d not active\n", bi->nr);
ret = -1; ret = -1;
} }
return ret; return ret;
}; };
@ -434,7 +445,6 @@ int recvBchannel(int idx)
int ret; int ret;
struct BInstance *bi; struct BInstance *bi;
struct mc_buf *mc; struct mc_buf *mc;
struct mISDNhead *hh;
mc = alloc_mc_buf(); mc = alloc_mc_buf();
if (!mc) if (!mc)
@ -451,40 +461,19 @@ int recvBchannel(int idx)
ret = -ECONNABORTED; ret = -ECONNABORTED;
} else if (ret < 8) { } else if (ret < 8) {
eprint("Short message read len %d (%02x%02x%02x%02x%02x%02x%02x%02x)\n", 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; ret = -EBADMSG;
} else if (ret == MC_RB_SIZE) { } else if (ret == MC_RB_SIZE) {
eprint("Message too big %d (%02x%02x%02x%02x%02x%02x%02x%02x)\n", 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; ret = -EMSGSIZE;
} }
if (ret < 0) if (ret > 0) {
goto end; mc->len = ret;
mc->len = ret; ret = bi->from_down(bi, mc);
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);
} }
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); free_mc_buf(mc);
return ret; return ret;
} }
@ -509,21 +498,21 @@ static int l3_callback(struct mlayer3 *l3, unsigned int cmd, unsigned int pid, s
int ret = 0; int ret = 0;
dprint(MIDEBUG_CONTROLLER, "Controller %d - got %s (%x) from layer3 pid(%x) msg(%p)\n", 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); plci = getPLCI4pid(pc, pid);
switch(cmd) { switch (cmd) {
case MT_SETUP: case MT_SETUP:
if (plci) { if (plci) {
iprint("Controller %d - got %s but pid(%x) already in use\n", 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; break;
} }
plci = new_mPLCI(pc, pid, NULL); plci = new_mPLCI(pc, pid, NULL);
if (!plci) { if (!plci) {
wprint("Controller %d - got %s but could not allocate new PLCI\n", 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; ret = -ENOMEM;
} }
break; 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_RESUME_REJECT:
case MT_NOTIFY: case MT_NOTIFY:
if (!plci) if (!plci)
wprint("Controller %d - got %s but no PLCI found\n", wprint("Controller %d - got %s but no PLCI found\n", pc->profile.ncontroller, _mi_msg_type2str(cmd));
pc->profile.ncontroller, _mi_msg_type2str(cmd));
break; break;
case MT_FREE: case MT_FREE:
if (!plci) if (!plci)
wprint("Controller %d - got %s but no PLCI found\n", wprint("Controller %d - got %s but no PLCI found\n", pc->profile.ncontroller, _mi_msg_type2str(cmd));
pc->profile.ncontroller, _mi_msg_type2str(cmd));
else else
plci->pid = MISDN_PID_NONE; plci->pid = MISDN_PID_NONE;
break; break;
@ -565,15 +552,15 @@ static int l3_callback(struct mlayer3 *l3, unsigned int cmd, unsigned int pid, s
break; break;
case MT_TIMEOUT: case MT_TIMEOUT:
iprint("Controller %d - got %s from layer3 pid(%x) msg(%p) plci(%04x)\n", 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; break;
case MT_ERROR : case MT_ERROR:
wprint("Controller %d - got %s from layer3 pid(%x) msg(%p) plci(%04x)\n", 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; break;
default: default:
wprint("Controller %d - got %s (%x) from layer3 pid(%x) msg(%p) plci(%04x) - not handled\n", 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; ret = -EINVAL;
} }
if (!ret && plci) if (!ret && plci)
@ -603,9 +590,11 @@ int ListenController(struct pController *pc)
if (!pc->l3) { if (!pc->l3) {
pc->l3 = open_layer3(pc->mNr, pc->L3Proto, pc->L3Flags, l3_callback, pc); pc->l3 = open_layer3(pc->mNr, pc->L3Proto, pc->L3Flags, l3_callback, pc);
if (!pc->l3) { 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 } 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; return 0;
@ -635,7 +624,7 @@ static void get_profile(int fd, struct mc_buf *mc)
} else { } else {
pc = get_cController(contr); pc = get_cController(contr);
if (!pc) { if (!pc) {
capimsg_setu16(mc->rb, 8, 0x2002); /* Illegal controller */ capimsg_setu16(mc->rb, 8, 0x2002); /* Illegal controller */
} else { } else {
capimsg_setu16(mc->rb, 8, CapiNoError); capimsg_setu16(mc->rb, 8, CapiNoError);
capimsg_setu16(mc->rb, 10, contr); 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_SETSUBCOMMAND(mc->rb, CAPI_CONF);
capimsg_setu16(mc->rb, 8, CapiNoError); capimsg_setu16(mc->rb, 8, CapiNoError);
capimsg_setu32(mc->rb, 10, 2); /* major */ capimsg_setu32(mc->rb, 10, 2); /* major */
capimsg_setu32(mc->rb, 14, 0); /* minor */ capimsg_setu32(mc->rb, 14, 0); /* minor */
capimsg_setu32(mc->rb, 18, 0); /* manu major */ capimsg_setu32(mc->rb, 18, 0); /* manu major */
capimsg_setu32(mc->rb, 22, 1); /* manu minor */ capimsg_setu32(mc->rb, 22, 1); /* manu minor */
ret = send(fd, mc->rb, 26, 0); ret = send(fd, mc->rb, 26, 0);
if (ret != 26) if (ret != 26)
eprint("error send %d/%d - %s\n", ret, 26, strerror(errno)); 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)); eprint("error send %d/%d - %s\n", ret, 10, strerror(errno));
} }
static int main_recv(int fd, int idx) static int main_recv(int fd, int idx)
{ {
int ret, len, cmd, dl; int ret, len, cmd, dl;
@ -784,11 +772,11 @@ static int main_recv(int fd, int idx)
ret = -ECONNABORTED; ret = -ECONNABORTED;
} else if (ret < 8) { } else if (ret < 8) {
eprint("Short message read len %d (%02x%02x%02x%02x%02x%02x%02x%02x)\n", 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; ret = -EBADMSG;
} else if (ret == MC_RB_SIZE) { } else if (ret == MC_RB_SIZE) {
eprint("Message too big %d (%02x%02x%02x%02x%02x%02x%02x%02x)\n", 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; ret = -EMSGSIZE;
} }
if (ret < 0) if (ret < 0)
@ -841,7 +829,7 @@ static int main_recv(int fd, int idx)
break; break;
} }
end: 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); free_mc_buf(mc);
return ret; return ret;
} }
@ -860,16 +848,16 @@ int main_loop(void)
if (ret < 0) { if (ret < 0) {
eprint("Error while adding mIsock to mainpoll (mainpoll_max %d)\n", mainpoll_max); eprint("Error while adding mIsock to mainpoll (mainpoll_max %d)\n", mainpoll_max);
return -1; return -1;
} else } else
iprint("mIsock added to idx %d\n", ret); iprint("mIsock added to idx %d\n", ret);
ret = add_mainpoll(mCsock, PIT_CAPImain); ret = add_mainpoll(mCsock, PIT_CAPImain);
if (ret < 0) { if (ret < 0) {
eprint("Error while adding mCsock to mainpoll (mainpoll_max %d)\n", mainpoll_max); eprint("Error while adding mCsock to mainpoll (mainpoll_max %d)\n", mainpoll_max);
return -1; return -1;
} else } else
iprint("mCsock added to idx %d\n", ret); iprint("mCsock added to idx %d\n", ret);
while(running) { while (running) {
ret = poll(mainpoll, mainpoll_max, -1); ret = poll(mainpoll, mainpoll_max, -1);
if (ret < 0) { if (ret < 0) {
wprint("Error on poll - %s\n", strerror(errno)); wprint("Error on poll - %s\n", strerror(errno));
@ -879,7 +867,7 @@ int main_loop(void)
for (i = 0; i < mainpoll_max; i++) { for (i = 0; i < mainpoll_max; i++) {
if (ret && mainpoll[i].revents) { if (ret && mainpoll[i].revents) {
dprint(MIDEBUG_POLL, "Poll return %d for idx %d ev %x fd %d\n", ret, 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) { switch (pollinfo[i].type) {
case PIT_Bchannel: case PIT_Bchannel:
if (mainpoll[i].revents & POLLIN) { if (mainpoll[i].revents & POLLIN) {
@ -889,12 +877,12 @@ int main_loop(void)
ReleaseBchannel(i); ReleaseBchannel(i);
} }
break; break;
case PIT_CAPImain: /* new connect */ case PIT_CAPImain: /* new connect */
if (mainpoll[i].revents & POLLIN) { if (mainpoll[i].revents & POLLIN) {
caddr.sun_family = AF_UNIX; caddr.sun_family = AF_UNIX;
caddr.sun_path[0] = 0; caddr.sun_path[0] = 0;
alen = sizeof(caddr); alen = sizeof(caddr);
nconn = accept(mCsock, (struct sockaddr*)&caddr, &alen); nconn = accept(mCsock, (struct sockaddr *)&caddr, &alen);
if (nconn < 0) { if (nconn < 0) {
eprint("Error on accept - %s\n", strerror(errno)); eprint("Error on accept - %s\n", strerror(errno));
} else { } else {
@ -903,7 +891,7 @@ int main_loop(void)
if (idx < 0) if (idx < 0)
eprint("Cannot add fd=%d to mainpoll\n", nconn); eprint("Cannot add fd=%d to mainpoll\n", nconn);
else else
dprint(MIDEBUG_POLL, "nconn added to idx %d\n", idx); dprint(MIDEBUG_POLL, "nconn added to idx %d\n", idx);
} }
} }
break; break;
@ -926,7 +914,7 @@ int main_loop(void)
res = del_mainpoll(mainpoll[i].fd); res = del_mainpoll(mainpoll[i].fd);
if (res < 0) { if (res < 0) {
eprint("Cannot delete fd=%d from mainpoll result %d\n", 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); res = main_recv(mainpoll[i].fd, i);
@ -938,24 +926,23 @@ int main_loop(void)
close(mainpoll[i].fd); close(mainpoll[i].fd);
res = del_mainpoll(mainpoll[i].fd); res = del_mainpoll(mainpoll[i].fd);
if (res < 0) { if (res < 0) {
eprint("Cannot delete fd=%d from mainpoll result %d\n", eprint("Cannot delete fd=%d from mainpoll result %d\n", fd, res);
fd, res);
} else } else
dprint(MIDEBUG_POLL, "Deleted fd=%d from mainpoll\n", fd); dprint(MIDEBUG_POLL, "Deleted fd=%d from mainpoll\n", fd);
} }
break; break;
default: default:
wprint("Unexpected poll event %x on fd %d type %d\n", mainpoll[i].revents, wprint("Unexpected poll event %x on fd %d type %d\n", mainpoll[i].revents,
mainpoll[i].fd, pollinfo[i].type); mainpoll[i].fd, pollinfo[i].type);
break; break;
} }
ret--; ret--;
} }
if (ret == 0) if (ret == 0)
break; 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) 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; return ret;
} }
static int my_capilib_dbg(const char *file, int line, const char *func, const char *fmt, va_list va) 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); 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); ver = init_layer3(4, &l3dbg);
mISDN_set_debug_level(libdebug); mISDN_set_debug_level(libdebug);
iprint("Init mISDN lib version %x, debug = %x (%x)\n", ver, debugmask, libdebug); iprint("Init mISDN lib version %x, debug = %x (%x)\n", ver, debugmask, libdebug);
/* open mISDN */ /* open mISDN */
mIsock = socket(PF_ISDN, SOCK_RAW, ISDN_P_BASE); mIsock = socket(PF_ISDN, SOCK_RAW, ISDN_P_BASE);
if (mIsock < 0) { if (mIsock < 0) {
@ -1048,7 +1034,7 @@ int main(int argc, char *argv[])
pc = &mI_Controller[i]; pc = &mI_Controller[i];
pc->mNr = i; pc->mNr = i;
pc->devinfo.id = 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->L3Proto = L3_PROTOCOL_DSS1_USER;
pc->L3Flags = 0; pc->L3Flags = 0;
ret = ioctl(mIsock, IMGETDEVINFO, &pc->devinfo); ret = ioctl(mIsock, IMGETDEVINFO, &pc->devinfo);
@ -1058,8 +1044,7 @@ int main(int argc, char *argv[])
} }
c = 0; c = 0;
nb = 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)) { if (c <= MISDN_MAX_CHANNEL && test_channelmap(c, pc->devinfo.channelmap)) {
nb++; nb++;
pc->BImax = c; pc->BImax = c;
@ -1079,7 +1064,7 @@ int main(int argc, char *argv[])
} }
pc->profile.ncontroller = i + 1; pc->profile.ncontroller = i + 1;
pc->profile.nbchannel = nb; pc->profile.nbchannel = nb;
pc->profile.goptions = 1; /* internal controller */ pc->profile.goptions = 1; /* internal controller */
pc->profile.support1 = 0; pc->profile.support1 = 0;
pc->profile.support2 = 0; pc->profile.support2 = 0;
pc->profile.support3 = 0x01; pc->profile.support3 = 0x01;
@ -1120,11 +1105,11 @@ retry_Csock:
} }
mcaddr.sun_family = AF_UNIX; mcaddr.sun_family = AF_UNIX;
sprintf(mcaddr.sun_path, MISDN_CAPI_SOCKET_PATH); 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) { if (ret < 0) {
fprintf(stderr, "cannot bind socket to %s - %s\n", mcaddr.sun_path, strerror(errno)); fprintf(stderr, "cannot bind socket to %s - %s\n", mcaddr.sun_path, strerror(errno));
if (errno == EADDRINUSE) { /* old socket file exist */ if (errno == EADDRINUSE) { /* old socket file exist */
ret = connect(mCsock, (struct sockaddr*)&mcaddr, sizeof(mcaddr)); ret = connect(mCsock, (struct sockaddr *)&mcaddr, sizeof(mcaddr));
if (ret < 0) { if (ret < 0) {
/* seems the socket file is not in use */ /* seems the socket file is not in use */
ret = unlink(MISDN_CAPI_SOCKET_PATH); 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"); fprintf(stderr, "mISDNcapid is already running - only one instance can be used\n");
goto errout; goto errout;
} }
} }
} }
if (listen(mCsock, 15)) { if (listen(mCsock, 15)) {

View File

@ -13,9 +13,7 @@ enum {
ST_LISTEN_L_0_1, ST_LISTEN_L_0_1,
ST_LISTEN_L_1, ST_LISTEN_L_1,
ST_LISTEN_L_1_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[] = { static char *str_st_listen[] = {
"ST_LISTEN_L_0", "ST_LISTEN_L_0",
@ -27,51 +25,45 @@ static char *str_st_listen[] = {
enum { enum {
EV_LISTEN_REQ, EV_LISTEN_REQ,
EV_LISTEN_CONF, 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_REQ",
"EV_LISTEN_CONF", "EV_LISTEN_CONF",
}; };
static struct Fsm listen_fsm = static struct Fsm listen_fsm = { 0, 0, 0, 0, 0 };
{ 0, 0, 0, 0, 0 };
static void static void listen_debug(struct FsmInst *fi, char *fmt, ...)
listen_debug(struct FsmInst *fi, char *fmt, ...)
{ {
char tmp[128]; char tmp[128];
char *p = tmp; char *p = tmp;
va_list args; va_list args;
struct lController *lc = fi->userdata; struct lController *lc = fi->userdata;
if (!fi->debug) if (!fi->debug)
return; return;
va_start(args, fmt); va_start(args, fmt);
p += sprintf(p, "Controller%d ApplId %d listen ", p += sprintf(p, "Controller%d ApplId %d listen ", lc->Contr->profile.ncontroller, lc->Appl->AppId);
lc->Contr->profile.ncontroller, lc->Appl->AppId);
p += vsprintf(p, fmt, args); p += vsprintf(p, fmt, args);
*p = 0; *p = 0;
dprint(MIDEBUG_STATES, "%s\n", tmp); dprint(MIDEBUG_STATES, "%s\n", tmp);
va_end(args); va_end(args);
} }
static void static void listen_req_l_x(struct FsmInst *fi, int event, void *arg, int state)
listen_req_l_x(struct FsmInst *fi, int event, void *arg, int state)
{ {
struct lController *lc = fi->userdata; struct lController *lc = fi->userdata;
struct mc_buf *mc = arg; struct mc_buf *mc = arg;
FsmChangeState(fi, state); FsmChangeState(fi, state);
dprint(MIDEBUG_CONTROLLER, "Controller%d: set InfoMask %08x -> %08x\n", 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", 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", 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->InfoMask = mc->cmsg.InfoMask;
lc->CIPmask = mc->cmsg.CIPmask; lc->CIPmask = mc->cmsg.CIPmask;
lc->CIPmask2 = mc->cmsg.CIPmask2; 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); FsmEvent(&lc->listen_m, EV_LISTEN_CONF, mc);
} }
static void static void listen_req_l_0(struct FsmInst *fi, int event, void *arg)
listen_req_l_0(struct FsmInst *fi, int event, void *arg)
{ {
listen_req_l_x(fi, event, arg, ST_LISTEN_L_0_1); listen_req_l_x(fi, event, arg, ST_LISTEN_L_0_1);
} }
static void static void listen_req_l_1(struct FsmInst *fi, int event, void *arg)
listen_req_l_1(struct FsmInst *fi, int event, void *arg)
{ {
listen_req_l_x(fi, event, arg, ST_LISTEN_L_1_1); listen_req_l_x(fi, event, arg, ST_LISTEN_L_1_1);
} }
static void static void listen_conf_l_x_1(struct FsmInst *fi, int event, void *arg, int state)
listen_conf_l_x_1(struct FsmInst *fi, int event, void *arg, int state)
{ {
struct lController *lc = fi->userdata; struct lController *lc = fi->userdata;
struct mc_buf *mc = arg; struct mc_buf *mc = arg;
if (mc->cmsg.Info != CapiNoError) { if (mc->cmsg.Info != CapiNoError) {
FsmChangeState(fi, state); FsmChangeState(fi, state);
} else { // Info == 0 } else { // Info == 0
if (lc->CIPmask == 0) { if (lc->CIPmask == 0) {
FsmChangeState(fi, ST_LISTEN_L_0); FsmChangeState(fi, ST_LISTEN_L_0);
} else { } else {
@ -111,28 +100,24 @@ listen_conf_l_x_1(struct FsmInst *fi, int event, void *arg, int state)
SendCmsg2Application(lc->Appl, mc); SendCmsg2Application(lc->Appl, mc);
} }
static void static void listen_conf_l_0_1(struct FsmInst *fi, int event, void *arg)
listen_conf_l_0_1(struct FsmInst *fi, int event, void *arg)
{ {
listen_conf_l_x_1(fi, event, arg, ST_LISTEN_L_0); listen_conf_l_x_1(fi, event, arg, ST_LISTEN_L_0);
} }
static void static void listen_conf_l_1_1(struct FsmInst *fi, int event, void *arg)
listen_conf_l_1_1(struct FsmInst *fi, int event, void *arg)
{ {
listen_conf_l_x_1(fi, event, arg, ST_LISTEN_L_1); listen_conf_l_x_1(fi, event, arg, ST_LISTEN_L_1);
} }
static struct FsmNode fn_listen_list[] = static struct FsmNode fn_listen_list[] = {
{ {ST_LISTEN_L_0, EV_LISTEN_REQ, listen_req_l_0},
{ST_LISTEN_L_0, EV_LISTEN_REQ, listen_req_l_0}, {ST_LISTEN_L_0_1, EV_LISTEN_CONF, listen_conf_l_0_1},
{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, EV_LISTEN_REQ, listen_req_l_1}, {ST_LISTEN_L_1_1, EV_LISTEN_CONF, listen_conf_l_1_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) struct lController *addlController(struct mApplication *app, struct pController *pc)
{ {
@ -173,18 +158,16 @@ void listenDestr(struct lController *lc)
{ {
} }
int int listenRequest(struct lController *lc, struct mc_buf *mc)
listenRequest(struct lController *lc, struct mc_buf *mc)
{ {
FsmEvent(&lc->listen_m, EV_LISTEN_REQ, mc); FsmEvent(&lc->listen_m, EV_LISTEN_REQ, mc);
free_mc_buf(mc); free_mc_buf(mc);
return CapiNoError; return CapiNoError;
} }
int listenHandle(struct lController *lc, uint16_t CIPValue) int listenHandle(struct lController *lc, uint16_t CIPValue)
{ {
if ((lc->CIPmask & 1) || if ((lc->CIPmask & 1) || (lc->CIPmask & (1 << CIPValue)))
(lc->CIPmask & (1 << CIPValue)))
return 1; return 1;
return 0; return 0;
} }
@ -195,7 +178,7 @@ void init_listen(void)
listen_fsm.event_count = EV_LISTEN_COUNT; listen_fsm.event_count = EV_LISTEN_COUNT;
listen_fsm.strEvent = str_ev_listen; listen_fsm.strEvent = str_ev_listen;
listen_fsm.strState = str_st_listen; listen_fsm.strState = str_st_listen;
FsmNew(&listen_fsm, fn_listen_list, FN_LISTEN_COUNT); FsmNew(&listen_fsm, fn_listen_list, FN_LISTEN_COUNT);
} }

File diff suppressed because it is too large Load Diff

View File

@ -14,7 +14,7 @@
* GNU LESSER GENERAL PUBLIC LICENSE for more details. * GNU LESSER GENERAL PUBLIC LICENSE for more details.
* *
*/ */
#ifndef _M_CAPI_H #ifndef _M_CAPI_H
#define _M_CAPI_H #define _M_CAPI_H
@ -38,6 +38,7 @@ struct lPLCI;
struct mNCCI; struct mNCCI;
struct pController; struct pController;
struct lController; struct lController;
struct BInstance;
struct Bprotocol { struct Bprotocol {
uint16_t B1; uint16_t B1;
@ -48,30 +49,33 @@ struct Bprotocol {
unsigned char B3cfg[80]; unsigned char B3cfg[80];
}; };
typedef int (BDataTrans_t)(struct BInstance *, struct mc_buf *);
struct BInstance { struct BInstance {
int nr; int nr;
int usecnt; int usecnt;
int proto; int proto;
int fd; int fd;
uint16_t DownId; /* Ids for send down messages */ uint16_t DownId; /* Ids for send down messages */
uint16_t UpId; /* Ids for send up messages */ uint16_t UpId; /* Ids for send up messages */
struct pController *pc; struct pController *pc;
struct lPLCI *lp; struct lPLCI *lp;
struct mNCCI *nc; 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 *); int CloseBInstance(struct BInstance *);
struct capi_profile { struct capi_profile {
uint16_t ncontroller; /* number of installed controller */ uint16_t ncontroller; /* number of installed controller */
uint16_t nbchannel; /* number of B-Channels */ uint16_t nbchannel; /* number of B-Channels */
uint32_t goptions; /* global options */ uint32_t goptions; /* global options */
uint32_t support1; /* B1 protocols support */ uint32_t support1; /* B1 protocols support */
uint32_t support2; /* B2 protocols support */ uint32_t support2; /* B2 protocols support */
uint32_t support3; /* B3 protocols support */ uint32_t support3; /* B3 protocols support */
uint32_t reserved[6]; /* reserved */ uint32_t reserved[6]; /* reserved */
uint32_t manu[5]; /* manufacturer specific information */ uint32_t manu[5]; /* manufacturer specific information */
}; };
/* physical controller access */ /* physical controller access */
@ -87,7 +91,7 @@ struct pController {
struct mPLCI *plciL; /* List of PLCIs */ struct mPLCI *plciL; /* List of PLCIs */
int appCnt; int appCnt;
int BImax; /* Nr of BInstances */ 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 InfoMask; /* Listen info mask all active applications */
uint32_t CIPmask; /* Listen CIP mask all active applications */ uint32_t CIPmask; /* Listen CIP mask all active applications */
uint32_t CIPmask2; /* Listen CIP mask 2 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); void rm_lController(struct lController *lc);
int listenRequest(struct lController *, struct mc_buf *); int listenRequest(struct lController *, struct mc_buf *);
struct mApplication { struct mApplication {
struct mApplication *next; struct mApplication *next;
int refc; /* refcount */ int refc; /* refcount */
int fd; /* Filedescriptor for CAPI messages */ int fd; /* Filedescriptor for CAPI messages */
struct lController *contL; /* list of controllers */ struct lController *contL; /* list of controllers */
uint16_t AppId; uint16_t AppId;
uint16_t MsgId; /* next message number */ uint16_t MsgId; /* next message number */
int MaxB3Con; int MaxB3Con;
int MaxB3Blk; int MaxB3Blk;
int MaxB3Size; int MaxB3Size;
@ -141,10 +144,10 @@ int ListenController(struct pController *);
struct mPLCI { struct mPLCI {
struct mPLCI *next; struct mPLCI *next;
uint32_t plci; /* PLCI ID */ uint32_t plci; /* PLCI ID */
int pid; /* L3 pid */ int pid; /* L3 pid */
struct pController *pc; struct pController *pc;
int nAppl; int nAppl;
struct lPLCI *lPLCIs; struct lPLCI *lPLCIs;
unsigned int alerting:1; unsigned int alerting:1;
unsigned int outgoing:1; unsigned int outgoing:1;
@ -170,7 +173,7 @@ struct lPLCI {
struct mPLCI *PLCI; struct mPLCI *PLCI;
struct FsmInst plci_m; struct FsmInst plci_m;
struct BInstance *BIlink; struct BInstance *BIlink;
int NcciCnt; int NcciCnt;
struct mNCCI *Nccis; struct mNCCI *Nccis;
int cause; int cause;
int cause_loc; int cause_loc;
@ -194,7 +197,7 @@ struct mNCCI *ConnectB3Request(struct lPLCI *, struct mc_buf *);
#define GET_NCCI_ONLY_PLCI 2 #define GET_NCCI_ONLY_PLCI 2
#define GET_NCCI_PLCI 3 #define GET_NCCI_PLCI 3
struct _ConfQueue { struct _ConfQueue {
uint32_t PktId; uint32_t PktId;
uint16_t DataHandle; uint16_t DataHandle;
uint16_t MsgId; uint16_t MsgId;
@ -203,7 +206,7 @@ struct _ConfQueue {
struct mc_buf *pkt; struct mc_buf *pkt;
unsigned char *sp; unsigned char *sp;
}; };
#define CAPI_MAXDATAWINDOW 8 #define CAPI_MAXDATAWINDOW 8
enum _flowmode { enum _flowmode {
@ -213,32 +216,32 @@ enum _flowmode {
}; };
struct mNCCI { struct mNCCI {
struct mNCCI *next; struct mNCCI *next;
uint32_t ncci; uint32_t ncci;
struct lPLCI *lp; struct lPLCI *lp;
struct mApplication *appl; struct mApplication *appl;
struct BInstance *BIlink; struct BInstance *BIlink;
int window; int window;
struct FsmInst ncci_m; struct FsmInst ncci_m;
pthread_mutex_t lock; pthread_mutex_t lock;
struct _ConfQueue xmit_handles[CAPI_MAXDATAWINDOW]; struct _ConfQueue xmit_handles[CAPI_MAXDATAWINDOW];
uint32_t recv_handles[CAPI_MAXDATAWINDOW]; uint32_t recv_handles[CAPI_MAXDATAWINDOW];
enum _flowmode flowmode; enum _flowmode flowmode;
uint16_t isize; uint16_t isize;
uint16_t osize; uint16_t osize;
uint16_t iidx; uint16_t iidx;
uint16_t oidx; uint16_t oidx;
struct msghdr down_msg; struct msghdr down_msg;
struct iovec down_iv[3]; struct iovec down_iv[3];
struct mISDNhead down_header; struct mISDNhead down_header;
struct msghdr up_msg; struct msghdr up_msg;
struct iovec up_iv[2]; struct iovec up_iv[2];
unsigned char up_header[30]; unsigned char up_header[30];
unsigned int dtmflisten:1; unsigned int dtmflisten:1;
unsigned int l1direct:1; unsigned int l1direct:1;
unsigned int l2trans:1; unsigned int l2trans:1;
unsigned int l3trans:1; unsigned int l3trans:1;
unsigned int dlbusy:1; unsigned int dlbusy:1;
}; };
void init_ncci_fsm(void); void init_ncci_fsm(void);
@ -246,11 +249,10 @@ void free_ncci_fsm(void);
struct mNCCI *ncciCreate(struct lPLCI *); struct mNCCI *ncciCreate(struct lPLCI *);
void ncciFree(struct mNCCI *); void ncciFree(struct mNCCI *);
int ncciSendMessage(struct mNCCI *, uint8_t, uint8_t, struct mc_buf *); 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 ncciReleaseLink(struct mNCCI *);
void ncciDel_lPlci(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 MC_BUF_ALLOC(a) if (!(a = alloc_mc_buf())) {eprint("Cannot allocate mc_buff\n");return;}
#define CMSGCMD(cm) CAPICMD((cm)->Command, (cm)->Subcommand) #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 0x10
#define MC_DEBUG_NCCI_DATA 0x20 #define MC_DEBUG_NCCI_DATA 0x20
#define MIDEBUG_POLL (MC_DEBUG_POLL << 24) #define MIDEBUG_POLL (MC_DEBUG_POLL << 24)
#define MIDEBUG_CONTROLLER (MC_DEBUG_CONTROLLER << 24) #define MIDEBUG_CONTROLLER (MC_DEBUG_CONTROLLER << 24)
#define MIDEBUG_STATES (MC_DEBUG_STATES << 24) #define MIDEBUG_STATES (MC_DEBUG_STATES << 24)

View File

@ -20,10 +20,9 @@
#include "mc_buffer.h" #include "mc_buffer.h"
#include <mISDN/q931.h> #include <mISDN/q931.h>
struct mPLCI *new_mPLCI(struct pController *pc, int pid, struct lPLCI *lp) struct mPLCI *new_mPLCI(struct pController *pc, int pid, struct lPLCI *lp)
{ {
struct mPLCI *plci; struct mPLCI *plci;
int plci_nr = 1; int plci_nr = 1;
plci = pc->plciL; plci = pc->plciL;
@ -61,7 +60,7 @@ int free_mPLCI(struct mPLCI *plci)
if (p == plci) if (p == plci)
pc->plciL = plci->next; pc->plciL = plci->next;
else { else {
while(p && p->next) { while (p && p->next) {
if (p->next == plci) { if (p->next == plci) {
p->next = plci->next; p->next = plci->next;
break; break;
@ -117,19 +116,18 @@ void plciDetachlPLCI(struct lPLCI *lp)
static void plciHandleSetupInd(struct mPLCI *plci, int pr, struct mc_buf *mc) static void plciHandleSetupInd(struct mPLCI *plci, int pr, struct mc_buf *mc)
{ {
uint16_t CIPValue; uint16_t CIPValue;
uint32_t CIPmask; uint32_t CIPmask;
struct pController *pc; struct pController *pc;
struct lController *lc; struct lController *lc;
struct lPLCI *lp; struct lPLCI *lp;
uint8_t found = 0; uint8_t found = 0;
int ret; int ret;
CIPValue = q931CIPValue(mc); CIPValue = q931CIPValue(mc);
pc = plci->pc; pc = plci->pc;
CIPmask = 1 << CIPValue; CIPmask = 1 << CIPValue;
dprint(MIDEBUG_PLCI, "PLCI %04x: Check CIPvalue %d (%08x) with CIPmask %08x\n", dprint(MIDEBUG_PLCI, "PLCI %04x: Check CIPvalue %d (%08x) with CIPmask %08x\n", plci->plci, CIPValue, CIPmask, pc->CIPmask);
plci->plci, CIPValue, CIPmask, pc->CIPmask);
if (CIPValue && ((CIPmask & pc->CIPmask) || (pc->CIPmask & 1))) { if (CIPValue && ((CIPmask & pc->CIPmask) || (pc->CIPmask & 1))) {
/* at least one Application is listen for this service */ /* at least one Application is listen for this service */
lc = pc->lClist; 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); ret = pc->l3->to_layer3(pc->l3, MT_RELEASE_COMPLETE, plci->pid, l3m);
if (ret) { if (ret) {
wprint("Error %d - %s on sending %s to pid %x\n", ret, strerror(-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); 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) int plci_l3l4(struct mPLCI *plci, int pr, struct l3_msg *l3m)
{ {
struct lPLCI *lp; struct lPLCI *lp;
struct mc_buf *mc; struct mc_buf *mc;
mc = alloc_mc_buf(); mc = alloc_mc_buf();
if (!mc) { if (!mc) {
wprint("PLCI %04x: Cannot allocate mc_buf for %s\n", wprint("PLCI %04x: Cannot allocate mc_buf for %s\n", plci->plci, _mi_msg_type2str(pr));
plci->plci, _mi_msg_type2str(pr));
return -ENOMEM; return -ENOMEM;
} }
mc->l3m = l3m; mc->l3m = l3m;
@ -189,7 +186,7 @@ int plci_l3l4(struct mPLCI *plci, int pr, struct l3_msg *l3m)
break; break;
default: default:
lp = plci->lPLCIs; lp = plci->lPLCIs;
while(lp) { while (lp) {
lPLCI_l3l4(lp, pr, mc); lPLCI_l3l4(lp, pr, mc);
lp = lp->next; 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) int mPLCISendMessage(struct lController *lc, struct mc_buf *mc)
{ {
struct mPLCI *plci; struct mPLCI *plci;
struct lPLCI *lp; struct lPLCI *lp;
int ret; int ret;
switch (mc->cmsg.Command) { switch (mc->cmsg.Command) {
case CAPI_CONNECT: case CAPI_CONNECT:
@ -242,7 +239,7 @@ struct lPLCI *get_lPLCI4Id(struct mPLCI *plci, uint16_t appId)
if (!plci) if (!plci)
return NULL; return NULL;
lp = plci->lPLCIs; lp = plci->lPLCIs;
while(lp) { while (lp) {
if (appId == lp->lc->Appl->AppId) if (appId == lp->lc->Appl->AppId)
break; break;
lp = lp->next; 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 *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) if (plci->pid == pid)
break; break;
plci = plci->next; 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 *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) if (plci->plci == id)
break; break;
plci = plci->next; plci = plci->next;
@ -274,19 +279,18 @@ struct mPLCI *getPLCI4Id(struct pController *pc, uint32_t id)
return plci; return plci;
} }
int int plciL4L3(struct mPLCI *plci, int mt, struct l3_msg *l3m)
plciL4L3(struct mPLCI *plci, int mt, struct l3_msg *l3m)
{ {
int ret; int ret;
ret = plci->pc->l3->to_layer3(plci->pc->l3, mt, plci->pid, l3m); ret = plci->pc->l3->to_layer3(plci->pc->l3, mt, plci->pid, l3m);
if (ret < 0) { if (ret < 0) {
wprint("Error sending %s to controller %d pid %x %s msg\n", _mi_msg_type2str(mt), 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) if (l3m)
free_l3_msg(l3m); free_l3_msg(l3m);
} }
dprint(MIDEBUG_PLCI, "Sending %s to layer3 pid %x controller %d %s msg\n", _mi_msg_type2str(mt), 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; return ret;
} }

File diff suppressed because it is too large Load Diff