X-Git-Url: http://git.eversberg.eu/gitweb.cgi?p=lcr.git;a=blobdiff_plain;f=lcradmin.c;h=306a0da93a2aa51e097793ff3faef3618c479d6d;hp=cf97f6928f8f6192359a42635426308c2118343d;hb=57549529c86785b7ecf5f56d2a3ff42b5e519755;hpb=5ad4c41dc406a15beaa0a7b73d9dada1df74f939 diff --git a/lcradmin.c b/lcradmin.c index cf97f69..306a0da 100644 --- a/lcradmin.c +++ b/lcradmin.c @@ -23,6 +23,7 @@ #include #include #include "macro.h" +#include "options.h" #include "join.h" #include "joinpbx.h" #include "extension.h" @@ -42,6 +43,7 @@ int show_interfaces = 2, enum { MODE_STATE, + MODE_PORTINFO, MODE_INTERFACE, MODE_ROUTE, MODE_DIAL, @@ -53,14 +55,14 @@ enum { MODE_TRACE, }; -char *text_interfaces[] = { +const char *text_interfaces[] = { "off", "brief", "active channels", "all channels", }; -char *text_calls[] = { +const char *text_calls[] = { "off", "brief", "structured", @@ -76,7 +78,7 @@ char red = 1, #define LOGLINES 128 char logline[LOGLINES][512]; -unsigned long logcur = 0; +unsigned int logcur = 0; int logfh = -1; char logfile[128]; @@ -209,7 +211,7 @@ int debug_port(struct admin_message *msg, struct admin_message *m, int line, int } int debug_epoint(struct admin_message *msg, struct admin_message *m, int line, int i, int vline) { - unsigned long epoint = m[i].u.e.serial; + unsigned int epoint = m[i].u.e.serial; char buffer[256]; unsigned char c; int j, jj; @@ -359,7 +361,7 @@ int debug_epoint(struct admin_message *msg, struct admin_message *m, int line, i } /* loop all related ports */ ltee = 0; - j = msg->u.s.interfaces+msg->u.s.joins+msg->u.s.epoints; + j = msg->u.s.interfaces+msg->u.s.remotes+msg->u.s.joins+msg->u.s.epoints; jj = j + msg->u.s.ports; while(j < jj) { @@ -392,7 +394,7 @@ int debug_epoint(struct admin_message *msg, struct admin_message *m, int line, i } int debug_join(struct admin_message *msg, struct admin_message *m, int line, int i) { - unsigned long join = m[i].u.j.serial; + unsigned int join = m[i].u.j.serial; char buffer[256]; int j, jj; @@ -416,7 +418,7 @@ int debug_join(struct admin_message *msg, struct admin_message *m, int line, int addstr(buffer); } /* find number of epoints */ - j = msg->u.s.interfaces+msg->u.s.joins; + j = msg->u.s.interfaces+msg->u.s.remotes+msg->u.s.joins; jj = j + msg->u.s.epoints; i = 0; while(j < jj) @@ -426,7 +428,7 @@ int debug_join(struct admin_message *msg, struct admin_message *m, int line, int j++; } /* loop all related endpoints */ - j = msg->u.s.interfaces+msg->u.s.joins; + j = msg->u.s.interfaces+msg->u.s.remotes+msg->u.s.joins; jj = j + msg->u.s.epoints; while(j < jj) { @@ -449,7 +451,8 @@ int debug_join(struct admin_message *msg, struct admin_message *m, int line, int return(line); } -char *admin_state(int sock, char *argv[]) + +const char *admin_state(int sock, char *argv[]) { struct admin_message msg, *m; @@ -457,7 +460,7 @@ char *admin_state(int sock, char *argv[]) *p; int line, offset = 0, hoffset = 0; int i, ii, j, jj, k; - unsigned long l, ll; + unsigned int l, ll; int num; int len; int off; @@ -666,21 +669,63 @@ char *admin_state(int sock, char *argv[]) color(white); if (m[i].u.i.block >= 2) { - SPRINT(buffer, "%s (%d)%s", m[i].u.i.interface_name, m[i].u.i.portnum, (m[i].u.i.extension)?" (extension)":""); + if (m[i].u.i.portnum < 0) + SPRINT(buffer, "%s (port ?: %s)%s", m[i].u.i.interface_name, m[i].u.i.portname, (m[i].u.i.extension)?" extension":""); + else + SPRINT(buffer, "%s (port %d: %s)%s", m[i].u.i.interface_name, m[i].u.i.portnum, m[i].u.i.portname, (m[i].u.i.extension)?" extension":""); addstr(buffer); color(red); addstr(" not loaded"); } else { - SPRINT(buffer, "%s (%d) %s %s%s use:%d", m[i].u.i.interface_name, m[i].u.i.portnum, (m[i].u.i.ntmode)?"NT-mode":"TE-mode", (m[i].u.i.ptp)?"ptp ":"ptmp", (m[i].u.i.extension)?" extension":"", m[i].u.i.use); + SPRINT(buffer, "%s", m[i].u.i.interface_name); + addstr(buffer); + color(yellow); + SPRINT(buffer, "(port %d: %s)", m[i].u.i.portnum, m[i].u.i.portname); + addstr(buffer); + color(cyan); + SPRINT(buffer, " %s %s%s%s%s", (m[i].u.i.ntmode)?"NT-mode":"TE-mode", (m[i].u.i.ptp)?"ptp":"ptmp", (m[i].u.i.l1hold)?" l1hold":"", (m[i].u.i.l2hold)?" l2hold":"", (m[i].u.i.extension)?" extension":""); + addstr(buffer); + if (m[i].u.i.use) + color(green); + else + color(blue); + SPRINT(buffer, " use:%d", m[i].u.i.use); addstr(buffer); if (m[i].u.i.ptp || !m[i].u.i.ntmode) { - color((m[i].u.i.l2link)?green:red); - addstr((m[i].u.i.l2link)?" L2 UP":" L2 down"); + color((m[i].u.i.l2link > 0)?green:red); + if (m[i].u.i.l2link < 0) + addstr(" L2 unknown"); + else + addstr((m[i].u.i.l2link)?" L2 UP":" L2 down"); + } + color((m[i].u.i.l1link > 0)?green:blue); + if (m[i].u.i.l1link < 0) + addstr(" L1 unknown"); + else + addstr((m[i].u.i.l1link)?" L1 ACTIVE":" L1 inactive"); + if (m[i].u.i.los) + { + color(red); + addstr(" LOS"); + } + if (m[i].u.i.ais) + { + color(red); + addstr(" AIS"); + } + if (m[i].u.i.rdi) + { + color(red); + addstr(" RDI"); + } + if (m[i].u.i.slip_tx || m[i].u.i.slip_rx) + { + color(red); + SPRINT(buffer, " SLIP(tx:%d rx:%d)", m[i].u.i.slip_tx, m[i].u.i.slip_rx); + addstr(buffer); } - color((m[i].u.i.l1link)?green:blue); - addstr((m[i].u.i.l1link)?" L1 ACTIVE":" L1 inactive"); if (m[i].u.i.block) { color(red); @@ -715,6 +760,8 @@ char *admin_state(int sock, char *argv[]) SPRINT(buffer,"S%2d: ", j+1+(j>=15)); else SPRINT(buffer,"B%2d: ", j+1); + if (m[i].u.i.mode[j] == B_MODE_HDLC) + SCAT(buffer,"HDLC "); addstr(buffer); switch(m[i].u.i.busy[j]) { @@ -757,7 +804,7 @@ char *admin_state(int sock, char *argv[]) if (m[i].u.i.port[j]) { /* search for port */ - l = msg.u.s.interfaces+msg.u.s.joins+msg.u.s.epoints; + l = msg.u.s.interfaces+msg.u.s.remotes+msg.u.s.joins+msg.u.s.epoints; ll = l+msg.u.s.ports; while(l < ll) { @@ -813,7 +860,7 @@ char *admin_state(int sock, char *argv[]) i++; anything = 1; } - i = 0; + i = msg.u.s.interfaces; ii = i + msg.u.s.remotes; while(i < ii) { @@ -832,7 +879,7 @@ char *admin_state(int sock, char *argv[]) if (show_calls == 1) { anything = 0; - i = msg.u.s.interfaces+msg.u.s.joins; + i = msg.u.s.interfaces+msg.u.s.remotes+msg.u.s.joins; ii = i+msg.u.s.epoints; while(i < ii) { @@ -871,7 +918,7 @@ char *admin_state(int sock, char *argv[]) i++; anything = 1; } - j = msg.u.s.interfaces; + j = msg.u.s.interfaces+msg.u.s.remotes; jj = j+msg.u.s.joins; while(j < jj) { @@ -880,7 +927,7 @@ char *admin_state(int sock, char *argv[]) color(white); SPRINT(buffer, "(%d):", m[j].u.j.serial); addstr(buffer); - i = msg.u.s.interfaces+msg.u.s.joins; + i = msg.u.s.interfaces+msg.u.s.remotes+msg.u.s.joins; ii = i+msg.u.s.epoints; while(i < ii) { @@ -922,7 +969,7 @@ char *admin_state(int sock, char *argv[]) { /* show all ports with no epoint */ anything = 0; - i = msg.u.s.interfaces+msg.u.s.joins+msg.u.s.epoints; + i = msg.u.s.interfaces+msg.u.s.remotes+msg.u.s.joins+msg.u.s.epoints; ii = i+msg.u.s.ports; while(i < ii) { @@ -942,7 +989,7 @@ char *admin_state(int sock, char *argv[]) /* show all epoints with no call */ anything = 0; - i = msg.u.s.interfaces+msg.u.s.joins; + i = msg.u.s.interfaces+msg.u.s.remotes+msg.u.s.joins; ii = i+msg.u.s.epoints; while(i < ii) { @@ -962,7 +1009,7 @@ char *admin_state(int sock, char *argv[]) /* show all joins */ anything = 0; - i = msg.u.s.interfaces; + i = msg.u.s.interfaces+msg.u.s.remotes; ii = i+msg.u.s.joins; while(i < ii) { @@ -1095,6 +1142,7 @@ char *admin_state(int sock, char *argv[]) !!strncmp(enter_string, "release ", 8) && !!strncmp(enter_string, "block ", 6) && !!strncmp(enter_string, "unblock ", 8) && + !!strncmp(enter_string, "load ", 5) && !!strncmp(enter_string, "unload ", 7)) { SPRINT(logline[logcur++ % LOGLINES], "usage:"); @@ -1102,7 +1150,7 @@ char *admin_state(int sock, char *argv[]) SPRINT(logline[logcur++ % LOGLINES], "route (reload routing.conf)"); SPRINT(logline[logcur++ % LOGLINES], "release (release endpoint with given ID)"); SPRINT(logline[logcur++ % LOGLINES], "block (block port for further calls)"); - SPRINT(logline[logcur++ % LOGLINES], "unblock (unblock port for further calls, load if not loaded)"); + SPRINT(logline[logcur++ % LOGLINES], "unblock/load (unblock port for further calls, load if not loaded)"); SPRINT(logline[logcur++ % LOGLINES], "unload (unload mISDN stack, release call calls)"); } else { @@ -1226,11 +1274,175 @@ char *admin_state(int sock, char *argv[]) return(NULL); } +const char *admin_portinfo(int sock, int argc, char *argv[]) +{ + struct admin_message msg, + *m; + int i, ii, j; + int num; + int len; + int off; + + /* send state request command */ + memset(&msg, 0, sizeof(msg)); + msg.message = ADMIN_REQUEST_STATE; + if (write(sock, &msg, sizeof(msg)) != sizeof(msg)) + { + cleanup_curses(); + return("Broken pipe while sending command."); + } + + /* receive response */ + if (read(sock, &msg, sizeof(msg)) != sizeof(msg)) + { + cleanup_curses(); + return("Broken pipe while receiving response."); + } + + if (msg.message != ADMIN_RESPONSE_STATE) + { + cleanup_curses(); + return("Response not valid. Expecting state response."); + } + num = msg.u.s.interfaces + msg.u.s.remotes + msg.u.s.joins + msg.u.s.epoints + msg.u.s.ports; + m = (struct admin_message *)MALLOC(num*sizeof(struct admin_message)); + off=0; + if (num) + { + readagain: + if ((len = read(sock, ((unsigned char *)(m))+off, num*sizeof(struct admin_message)-off)) != num*(int)sizeof(struct admin_message)-off) + { + if (len <= 0) { + FREE(m, 0); + cleanup_curses(); + return("Broken pipe while receiving state infos."); + } + if (len < num*(int)sizeof(struct admin_message)) + { + off+=len; + goto readagain; + } + } + } + j = 0; + i = 0; + while(i < msg.u.s.interfaces) + { + if (m[j].message != ADMIN_RESPONSE_S_INTERFACE) + { + FREE(m, 0); + cleanup_curses(); + return("Response not valid. Expecting interface information."); + } + i++; + j++; + } + i = 0; + while(i < msg.u.s.remotes) + { + if (m[j].message != ADMIN_RESPONSE_S_REMOTE) + { + FREE(m, 0); + cleanup_curses(); + return("Response not valid. Expecting remote application information."); + } + i++; + j++; + } + i = 0; + while(i < msg.u.s.joins) + { + if (m[j].message != ADMIN_RESPONSE_S_JOIN) + { + FREE(m, 0); + cleanup_curses(); + return("Response not valid. Expecting join information."); + } + i++; + j++; + } + i = 0; + while(i < msg.u.s.epoints) + { + if (m[j].message != ADMIN_RESPONSE_S_EPOINT) + { + FREE(m, 0); + cleanup_curses(); + return("Response not valid. Expecting endpoint information."); + } + i++; + j++; + } + i = 0; + while(i < msg.u.s.ports) + { + if (m[j].message != ADMIN_RESPONSE_S_PORT) + { + FREE(m, 0); + cleanup_curses(); + return("Response not valid. Expecting port information."); + } + i++; + j++; + } + // now j is the number of message blocks + + /* output interfaces */ + i = 0; + ii = i + msg.u.s.interfaces; + while(i < ii) + { + if (argc > 2) + { + if (!!strcmp(argv[2], m[i].u.i.interface_name)) + { + i++; + continue; + } + } + printf("%s:\n", m[i].u.i.interface_name); + if (m[i].u.i.portnum < 0) + printf("\t port = unknown\n"); + else + printf("\t port = %d \"%s\"\n",m[i].u.i.portnum, m[i].u.i.portname); + printf("\t extension = %s\n", (m[i].u.i.extension)?"yes":"no"); + if (m[i].u.i.block >= 2) + { + printf("\t status = not loaded\n"); + } else + { + if (m[i].u.i.block) + printf("\t status = blocked\n"); + else + printf("\t status = unblocked\n"); + printf("\t mode = %s %s%s%s\n", (m[i].u.i.ntmode)?"NT-mode":"TE-mode", (m[i].u.i.ptp)?"ptp":"ptmp", (m[i].u.i.l1hold)?" l1hold":"", (m[i].u.i.l2hold)?" l2hold":""); + if (m[i].u.i.l1link < 0) + printf("\t l1 link = unknown\n"); + else + printf("\t l1 link = %s\n", (m[i].u.i.l1link)?"up":"down"); + if (m[i].u.i.ptp || !m[i].u.i.ntmode) + { + if (m[i].u.i.l2link < 0) + printf("\t l2 link = unknown\n"); + else + printf("\t l2 link = %s\n", (m[i].u.i.l2link)?"up":"down"); + } + printf("\t usage = %d\n", m[i].u.i.use); + } + i++; + } + + /* free memory */ + FREE(m, 0); + + return(NULL); +} + /* * Send command and show error message. */ -char *admin_cmd(int sock, int mode, char *extension, char *number) +const char *admin_cmd(int sock, int mode, char *extension, char *number) { static struct admin_message msg; @@ -1318,14 +1530,14 @@ char *admin_cmd(int sock, int mode, char *extension, char *number) gettimeofday(&now_tv, &now_tz); \ now_d = ((double)(now_tv.tv_usec))/1000000 + now_tv.tv_sec; \ } -char *admin_testcall(int sock, int argc, char *argv[]) +const char *admin_testcall(int sock, int argc, char *argv[]) { static struct admin_message msg; int ar = 2; int stimeout = 0, ptimeout = 0, atimeout = 0, ctimeout = 0; int l; double timer = 0, now_d; - unsigned long on = 1; + unsigned int on = 1; struct timeval now_tv; struct timezone now_tz; @@ -1528,7 +1740,7 @@ next: /* * makes a trace */ -char *admin_trace(int sock, int argc, char *argv[]) +const char *admin_trace(int sock, int argc, char *argv[]) { static struct admin_message msg; int i; @@ -1557,6 +1769,7 @@ char *admin_trace(int sock, int argc, char *argv[]) memset(&msg, 0, sizeof(msg)); msg.message = ADMIN_TRACE_REQUEST; msg.u.trace_req.detail = 3; + msg.u.trace_req.port = -1; /* parse args */ i = 2; @@ -1604,10 +1817,9 @@ next: int main(int argc, char *argv[]) { int mode; - char *socket_name = SOCKET_NAME; int sock, conn; struct sockaddr_un sock_address; - char *ret; + const char *ret; /* show options */ @@ -1617,12 +1829,13 @@ int main(int argc, char *argv[]) printf("\n"); printf("Usage: %s state | interface | route | dial ...\n", argv[0]); printf("state - View current states using graphical console output.\n"); - printf("interface - Tell LCR to reload \"interface.conf\".\n"); + printf("portinfo - Get info of current ports.\n"); + printf("interface [] - Tell LCR to reload \"interface.conf\".\n"); printf("route - Tell LCR to reload \"route.conf\".\n"); printf("dial - Tell LCR the next number to dial for extension.\n"); printf("release - Tell LCR to release endpoint with given number.\n"); printf("block - Block given port.\n"); - printf("unblock - Unblock given port.\n"); + printf("unblock/load - Unblock given port.\n"); printf("unload - Unload port. To load port use 'block' or 'unblock'.\n"); printf("testcall [options] [present|restrict []] - Testcall\n"); printf(" -> options = --setup-timeout --proceeding-timeout \n"); @@ -1639,6 +1852,10 @@ int main(int argc, char *argv[]) { mode = MODE_STATE; } else + if (!(strcasecmp(argv[1],"portinfo"))) + { + mode = MODE_PORTINFO; + } else if (!(strcasecmp(argv[1],"interface"))) { mode = MODE_INTERFACE; @@ -1659,7 +1876,8 @@ int main(int argc, char *argv[]) goto usage; mode = MODE_RELEASE; } else - if (!(strcasecmp(argv[1],"unblock"))) + if (!(strcasecmp(argv[1],"unblock")) + || !(strcasecmp(argv[1],"load"))) { if (argc <= 2) goto usage; @@ -1691,6 +1909,10 @@ int main(int argc, char *argv[]) goto usage; } + if (read_options() == 0) { + exit(EXIT_FAILURE); + } + //pipeagain: /* open socket */ if ((sock = socket(PF_UNIX, SOCK_STREAM, 0)) < 0) @@ -1699,8 +1921,8 @@ int main(int argc, char *argv[]) exit(EXIT_FAILURE); } memset(&sock_address, 0, sizeof(sock_address)); + SPRINT(sock_address.sun_path, SOCKET_NAME, options.lock); sock_address.sun_family = PF_UNIX; - UCPY(sock_address.sun_path, socket_name); if ((conn = connect(sock, (struct sockaddr *)&sock_address, SUN_LEN(&sock_address))) < 0) { close(sock); @@ -1715,6 +1937,10 @@ int main(int argc, char *argv[]) ret = admin_state(sock, argv); break; + case MODE_PORTINFO: + ret = admin_portinfo(sock, argc, argv); + break; + case MODE_INTERFACE: case MODE_ROUTE: ret = admin_cmd(sock, mode, NULL, NULL);