1 /*****************************************************************************\
3 ** Linux Call Router **
5 **---------------------------------------------------------------------------**
6 ** Copyright: Andreas Eversberg **
8 ** Administration tool **
10 \*****************************************************************************/
15 #include <sys/types.h>
19 #include <sys/ioctl.h>
20 #include <sys/socket.h>
26 #include "extension.h"
31 #define LTEE {addch(ACS_LTEE);addch(ACS_HLINE);addch(ACS_HLINE);}
32 #define LLCORNER {addch(ACS_LLCORNER);addch(ACS_HLINE);addch(ACS_HLINE);}
33 #define VLINE {addch(ACS_VLINE);addstr(" ");}
34 #define EMPTY {addstr(" ");}
35 //char rotator[] = {'-', '\\', '|', '/'};
36 int lastlines, lastcols;
37 int show_interfaces = 2,
54 char *text_interfaces[] = {
61 char *text_calls[] = {
76 char logline[LOGLINES][512];
77 unsigned long logcur = 0;
84 void init_curses(void)
87 initscr(); cbreak(); noecho();
89 nodelay(stdscr, TRUE);
90 if (COLOR_PAIRS>=8 && COLORS>=8)
104 void cleanup_curses(void)
109 void color(int color)
111 if (COLOR_PAIRS>=8 && COLORS>=8)
112 attrset(COLOR_PAIR(color));
116 * permanently show current state using ncurses
118 int debug_port(struct admin_message *msg, struct admin_message *m, int line, int i, int vline)
125 SPRINT(buffer,"%s(%d)", m[i].u.p.name,m[i].u.p.serial);
129 switch (m[i].u.p.state)
131 case ADMIN_STATE_IDLE:
135 case ADMIN_STATE_IN_SETUP:
137 addstr("'in << setup'");
139 case ADMIN_STATE_OUT_SETUP:
141 addstr("'out >> setup'");
143 case ADMIN_STATE_IN_OVERLAP:
145 addstr("'in << overlap'");
147 case ADMIN_STATE_OUT_OVERLAP:
149 addstr("'out >> overlap'");
151 case ADMIN_STATE_IN_PROCEEDING:
153 addstr("'in << proc'");
155 case ADMIN_STATE_OUT_PROCEEDING:
157 addstr("'out >> proc'");
159 case ADMIN_STATE_IN_ALERTING:
161 addstr("'in << alert'");
163 case ADMIN_STATE_OUT_ALERTING:
165 addstr("'out >> alert'");
167 case ADMIN_STATE_CONNECT:
171 case ADMIN_STATE_IN_DISCONNECT:
173 addstr("'in << disc'");
175 case ADMIN_STATE_OUT_DISCONNECT:
177 addstr("'out >> disc'");
181 addstr("'--NONE--'");
187 addstr(" bchannel=");
189 SPRINT(buffer,"%d", m[i].u.p.isdn_chan);
191 if (m[i].u.p.isdn_ces >= 0)
196 SPRINT(buffer, "%d", m[i].u.p.isdn_ces);
199 if (m[i].u.p.isdn_hold)
208 int debug_epoint(struct admin_message *msg, struct admin_message *m, int line, int i, int vline)
210 unsigned long epoint = m[i].u.e.serial;
217 SPRINT(buffer,"EPOINT(%d)", epoint);
221 switch (m[i].u.e.state)
223 case ADMIN_STATE_IDLE:
227 case ADMIN_STATE_IN_SETUP:
229 addstr("'in << setup'");
231 case ADMIN_STATE_OUT_SETUP:
233 addstr("'out >> setup'");
235 case ADMIN_STATE_IN_OVERLAP:
237 addstr("'in << overlap'");
239 case ADMIN_STATE_OUT_OVERLAP:
241 addstr("'out >> overlap'");
243 case ADMIN_STATE_IN_PROCEEDING:
245 addstr("'in << proc'");
247 case ADMIN_STATE_OUT_PROCEEDING:
249 addstr("'out >> proc'");
251 case ADMIN_STATE_IN_ALERTING:
253 addstr("'in << alert'");
255 case ADMIN_STATE_OUT_ALERTING:
257 addstr("'out >> alert'");
259 case ADMIN_STATE_CONNECT:
263 case ADMIN_STATE_IN_DISCONNECT:
265 addstr("'in << disc'");
267 case ADMIN_STATE_OUT_DISCONNECT:
269 addstr("'out >> disc'");
273 addstr("'--NONE--'");
275 if (m[i].u.e.terminal[0])
278 addstr(" terminal=");
280 addstr(m[i].u.e.terminal);
283 SPRINT(buffer, " %s", m[i].u.e.callerid);
288 addstr(m[i].u.e.dialing);
289 if (m[i].u.e.action[0])
294 addstr(m[i].u.e.action);
299 addstr(" park="); /* 9 digits */
301 UCPY(buffer, "\""); /* 9 digits */
303 jj = m[i].u.e.park_len;
306 c = m[i].u.e.park_callid[j];
307 if (c >= 32 && c < 127 && c != '[')
311 UPRINT(buffer+strlen(buffer), "[%02x]", c);
319 switch(m[i].u.e.rx_state)
321 case NOTIFY_STATE_SUSPEND:
322 addstr(" in=suspend");
324 case NOTIFY_STATE_HOLD:
327 case NOTIFY_STATE_CONFERENCE:
328 addstr(" in=conference");
331 switch(m[i].u.e.tx_state)
333 case NOTIFY_STATE_SUSPEND:
334 addstr(" out=suspend");
336 case NOTIFY_STATE_HOLD:
339 case NOTIFY_STATE_CONFERENCE:
340 addstr(" out=conference");
348 if (m[i].u.e.crypt) /* crypt on */
358 /* loop all related ports */
360 j = msg->u.s.interfaces+msg->u.s.joins+msg->u.s.epoints;
361 jj = j + msg->u.s.ports;
364 if (m[j].u.p.epoint == epoint)
367 move(++line>1?line:1, 1);
372 move(line>1?line:1, 5);
375 move(line>1?line:1, 8);
376 if (line+2 >= LINES) break;
377 line = debug_port(msg, m, line, j, vline);
378 if (line+2 >= LINES) break;
385 move(ltee>1?line:1, 5);
391 int debug_join(struct admin_message *msg, struct admin_message *m, int line, int i)
393 unsigned long join = m[i].u.j.serial;
398 SPRINT(buffer,"JOIN(%d)", join);
400 if (m[i].u.j.partyline)
403 addstr(" partyline=");
405 SPRINT(buffer, "%d\n", m[i].u.j.partyline);
408 if (m[i].u.j.remote[0])
413 SPRINT(buffer, "%s\n", m[i].u.j.remote);
416 /* find number of epoints */
417 j = msg->u.s.interfaces+msg->u.s.joins;
418 jj = j + msg->u.s.epoints;
422 if (m[j].u.e.join == join)
426 /* loop all related endpoints */
427 j = msg->u.s.interfaces+msg->u.s.joins;
428 jj = j + msg->u.s.epoints;
431 if (m[j].u.e.join == join)
434 move(++line>1?line:1, 1);
440 move(line>1?line:1, 4);
441 if (line+2 >= LINES) break;
442 line = debug_epoint(msg, m, line, j, i?1:0);
443 if (line+2 >= LINES) break;
450 char *admin_state(int sock, char *argv[])
452 struct admin_message msg,
456 int line, offset = 0, hoffset = 0;
465 char enter_string[128] = "", ch;
467 /* flush logfile name */
474 /* send reload command */
475 memset(&msg, 0, sizeof(msg));
476 msg.message = ADMIN_REQUEST_STATE;
477 // printf("sizeof=%d\n",sizeof(msg));fflush(stdout);
478 if (write(sock, &msg, sizeof(msg)) != sizeof(msg))
481 return("Broken pipe while sending command.");
484 /* receive response */
485 if (read(sock, &msg, sizeof(msg)) != sizeof(msg))
488 return("Broken pipe while receiving response.");
491 if (msg.message != ADMIN_RESPONSE_STATE)
494 return("Response not valid. Expecting state response.");
496 num = msg.u.s.interfaces + msg.u.s.remotes + msg.u.s.joins + msg.u.s.epoints + msg.u.s.ports;
497 m = (struct admin_message *)MALLOC(num*sizeof(struct admin_message));
502 if ((len = read(sock, ((unsigned char *)(m))+off, num*sizeof(struct admin_message)-off)) != num*(int)sizeof(struct admin_message)-off)
506 // fprintf(stderr, "got=%d expected=%d\n", i, num*sizeof(struct admin_message));
508 return("Broken pipe while receiving state infos.");
510 if (len < num*(int)sizeof(struct admin_message))
519 // fprintf("getting =%d interfaces\n", msg.u.s.interfaces);
520 while(i < msg.u.s.interfaces)
522 // fprintf(stderr, "j=%d message=%d\n", j, m[j].message);
523 if (m[j].message != ADMIN_RESPONSE_S_INTERFACE)
527 return("Response not valid. Expecting interface information.");
533 while(i < msg.u.s.remotes)
535 if (m[j].message != ADMIN_RESPONSE_S_REMOTE)
539 return("Response not valid. Expecting remote application information.");
545 while(i < msg.u.s.joins)
547 if (m[j].message != ADMIN_RESPONSE_S_JOIN)
551 return("Response not valid. Expecting join information.");
557 while(i < msg.u.s.epoints)
559 if (m[j].message != ADMIN_RESPONSE_S_EPOINT)
563 return("Response not valid. Expecting endpoint information.");
569 while(i < msg.u.s.ports)
571 if (m[j].message != ADMIN_RESPONSE_S_PORT)
575 return("Response not valid. Expecting port information.");
580 // now j is the number of message blocks
588 if (!!strcmp(logfile, msg.u.s.logfile))
590 SCPY(logfile, msg.u.s.logfile);
598 logline[i][1] = '\0';
602 logfh = open(logfile, O_RDONLY|O_NONBLOCK);
605 /* seek at the end -8000 chars */
606 lseek(logfh, -8000, SEEK_END);
607 /* if not at the beginning, read until endofline */
608 logline[logcur % LOGLINES][0] = '\0';
609 l = read(logfh, logline[logcur % LOGLINES], sizeof(logline[logcur % LOGLINES])-1);
612 /* read first line and skip junk */
613 logline[logcur % LOGLINES][l] = '\0';
614 if ((p = strchr(logline[logcur % LOGLINES],'\n')))
617 SCPY(logline[logcur % LOGLINES], p+1);
618 SCPY(logline[(logcur-1) % LOGLINES], "...");
630 ll = strlen(logline[logcur % LOGLINES]);
631 l = read(logfh, logline[logcur % LOGLINES]+ll, sizeof(logline[logcur % LOGLINES])-ll-1);
634 logline[logcur % LOGLINES][ll+l] = '\0';
636 /* put data to lines */
637 while ((p = strchr(logline[logcur % LOGLINES],'\n')))
641 SCPY(logline[logcur % LOGLINES], p+1);
643 /* if line is full without return, go next line */
644 if (strlen(logline[logcur % LOGLINES]) == sizeof(logline[logcur % LOGLINES])-1)
647 logline[logcur % LOGLINES][0] = '\0';
652 /* display interfaces */
653 if (show_interfaces > 0)
657 ii = i + msg.u.s.interfaces;
660 /* show interface summary */
661 move(++line>1?line:1, 0);
663 if (m[i].u.i.block >= 2)
665 SPRINT(buffer, "%s (%d)%s", m[i].u.i.interface_name, m[i].u.i.portnum, (m[i].u.i.extension)?" (extension)":"");
668 addstr(" not loaded");
671 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);
673 if (m[i].u.i.ptp || !m[i].u.i.ntmode)
675 color((m[i].u.i.l2link)?green:red);
676 addstr((m[i].u.i.l2link)?" L2 UP":" L2 down");
678 color((m[i].u.i.l1link)?green:blue);
679 addstr((m[i].u.i.l1link)?" L1 ACTIVE":" L1 inactive");
685 if (line+2 >= LINES) goto end;
687 if (show_interfaces > 1)
691 jj = m[i].u.i.channels;
694 /* show all channels */
695 if (show_interfaces>2 || m[i].u.i.busy[j]>0)
698 /* show left side / right side */
699 if ((k & 1) && (COLS > 70))
701 move(line>1?line:1,4+((COLS-4)/2));
704 move(++line>1?line:1, 1);
711 SPRINT(buffer,"S%2d: ", j+1+(j>=15));
713 SPRINT(buffer,"B%2d: ", j+1);
717 if (m[i].u.i.l2link && m[i].u.i.block==0)
720 switch(m[i].u.i.busy[j])
726 case B_STATE_ACTIVATING:
734 case B_STATE_DEACTIVATING:
738 case B_STATE_EXPORTING:
746 case B_STATE_IMPORTING:
756 if (m[i].u.i.port[j])
758 /* search for port */
759 l = msg.u.s.interfaces+msg.u.s.joins+msg.u.s.epoints;
760 ll = l+msg.u.s.ports;
763 if (m[l].u.p.serial == m[i].u.i.port[j])
765 SPRINT(buffer, " %s(%ld)", m[l].u.p.name, m[l].u.p.serial);
776 move(line>1?line:1, 1);
787 move(line>1?line:1, 1);
790 if (line+2 >= LINES) goto end;
791 /* show summary if no channels were shown */
792 if (show_interfaces<2 && ltee==0)
795 move(++line>1?line:1, 1);
798 if (m[i].u.i.l2link && m[i].u.i.block==0)
801 SPRINT(buffer,"all %d channels free", m[i].u.i.channels);
805 SPRINT(buffer,"all %d channels blocked", m[i].u.i.channels);
809 if (line+2 >= LINES) goto end;
816 ii = i + msg.u.s.remotes;
819 /* show remote summary */
820 move(++line>1?line:1, 0);
822 SPRINT(buffer, "Remote: %s", m[i].u.r.name);
828 if (line+2 >= LINES) goto end;
830 /* display calls (brief) */
834 i = msg.u.s.interfaces+msg.u.s.joins;
835 ii = i+msg.u.s.epoints;
838 /* for each endpoint... */
841 move(++line>1?line:1, 0);
843 SPRINT(buffer, "(%d): ", m[i].u.e.serial);
846 if (m[i].u.e.terminal[0])
850 addstr(m[i].u.e.terminal);
854 SPRINT(buffer, " %s", m[i].u.e.callerid);
859 SPRINT(buffer, "%s", m[i].u.e.dialing);
861 if (m[i].u.e.action[0])
866 addstr(m[i].u.e.action);
868 if (line+2 >= LINES) goto end;
873 j = msg.u.s.interfaces;
874 jj = j+msg.u.s.joins;
877 /* for each call... */
878 move(++line>1?line:1, 0);
880 SPRINT(buffer, "(%d):", m[j].u.j.serial);
882 i = msg.u.s.interfaces+msg.u.s.joins;
883 ii = i+msg.u.s.epoints;
886 /* for each endpoint... */
887 if (m[i].u.e.join == m[j].u.j.serial)
890 SPRINT(buffer, " (%d)", m[i].u.e.serial);
893 if (m[i].u.e.terminal[0])
897 addstr(m[i].u.e.terminal);
901 SPRINT(buffer, "-%s", m[i].u.e.callerid);
906 SPRINT(buffer, "%s", m[i].u.e.dialing);
912 if (line+2 >= LINES) goto end;
917 if (line+2 >= LINES) goto end;
919 /* display calls (structurd) */
922 /* show all ports with no epoint */
924 i = msg.u.s.interfaces+msg.u.s.joins+msg.u.s.epoints;
925 ii = i+msg.u.s.ports;
928 if (!m[i].u.p.epoint)
930 move(++line>1?line:1, 8);
931 if (line+2 >= LINES) goto end;
932 line = debug_port(&msg, m, line, i, 0);
933 if (line+2 >= LINES) goto end;
940 if (line+2 >= LINES) goto end;
942 /* show all epoints with no call */
944 i = msg.u.s.interfaces+msg.u.s.joins;
945 ii = i+msg.u.s.epoints;
950 move(++line>1?line:1, 4);
951 if (line+2 >= LINES) goto end;
952 line = debug_epoint(&msg, m, line, i, 0);
953 if (line+2 >= LINES) goto end;
960 if (line+2 >= LINES) goto end;
964 i = msg.u.s.interfaces;
965 ii = i+msg.u.s.joins;
968 move(++line>1?line:1, 0);
969 if (line+2 >= LINES) goto end;
970 line = debug_join(&msg, m, line, i);
971 if (line+2 >= LINES) goto end;
977 if (line+2 >= LINES) goto end;
986 move(line++>1?line-1:1, 0);
988 hline(ACS_HLINE, COLS);
991 l = logcur-(LINES-line-2);
993 if (ll-l >= LOGLINES)
997 move(line++>1?line-1:1, 0);
998 if ((int)strlen(logline[l % LOGLINES]) > hoffset)
999 SCPY(buffer, logline[l % LOGLINES] + hoffset);
1002 if (COLS < (int)strlen(buffer))
1004 buffer[COLS-1] = '\0';
1019 /* display name/time */
1021 // hline(' ', COLS);
1024 msg.u.s.version_string[sizeof(msg.u.s.version_string)-1] = '\0';
1025 SPRINT(buffer, "LCR %s", msg.u.s.version_string);
1030 SPRINT(buffer, "%04d-%02d-%02d %02d:%02d:%02d",
1031 msg.u.s.tm.tm_year+1900, msg.u.s.tm.tm_mon+1, msg.u.s.tm.tm_mday,
1032 msg.u.s.tm.tm_hour, msg.u.s.tm.tm_min, msg.u.s.tm.tm_sec);
1035 /* displeay head line */
1038 hline(ACS_HLINE, COLS);
1042 SPRINT(buffer, "Offset +%d", offset);
1049 SPRINT(buffer, "H-Offset +%d", hoffset);
1056 hline(ACS_HLINE, COLS);
1060 SPRINT(buffer, "-> %s", enter_string);
1062 SPRINT(buffer, "i=interfaces '%s' c=calls '%s' l=log q=quit +-*/=scroll enter", text_interfaces[show_interfaces], text_calls[show_calls]);
1067 if (lastlines!=LINES || lastcols!=COLS)
1076 /* user input in enter mode */
1083 if (!enter_string[0])
1086 SPRINT(logline[logcur++ % LOGLINES], "> %s", enter_string);
1087 if (!!strncmp(enter_string, "interface", 10) &&
1088 !!strncmp(enter_string, "route", 6) &&
1089 !!strncmp(enter_string, "release ", 8) &&
1090 !!strncmp(enter_string, "block ", 6) &&
1091 !!strncmp(enter_string, "unblock ", 8) &&
1092 !!strncmp(enter_string, "unload ", 7))
1094 SPRINT(logline[logcur++ % LOGLINES], "usage:");
1095 SPRINT(logline[logcur++ % LOGLINES], "interface (reload interface.conf)");
1096 SPRINT(logline[logcur++ % LOGLINES], "route (reload routing.conf)");
1097 SPRINT(logline[logcur++ % LOGLINES], "release <EP> (release endpoint with given ID)");
1098 SPRINT(logline[logcur++ % LOGLINES], "block <port> (block port for further calls)");
1099 SPRINT(logline[logcur++ % LOGLINES], "unblock <port> (unblock port for further calls, load if not loaded)");
1100 SPRINT(logline[logcur++ % LOGLINES], "unload <port> (unload mISDN stack, release call calls)");
1103 /* applend output to log window */
1104 SPRINT(buffer, "%s %s", argv[0], enter_string);
1105 fp = popen(buffer, "r");
1108 while(fgets(logline[logcur % LOGLINES], sizeof(logline[0]), fp))
1109 logline[logcur++ % LOGLINES][sizeof(logline[0])-1] = '\0';
1113 SPRINT(logline[logcur++ % LOGLINES], "failed to execute '%s'", buffer);
1116 logline[logcur % LOGLINES][0] = '\0';
1117 enter_string[0] = '\0';
1120 if (ch>=32 && ch<=126)
1122 SCCAT(enter_string, ch);
1125 if (ch==8 || ch==127)
1127 if (enter_string[0])
1128 enter_string[strlen(enter_string)-1] = '\0';
1138 /* user input in normal mode */
1141 case 12: /* refresh */
1152 case 'i': /* toggle interface */
1154 if (show_interfaces > 3) show_interfaces = 0;
1157 case 'c': /* toggle calls */
1159 if (show_calls > 2) show_calls = 0;
1162 case 'l': /* toggle log */
1164 if (show_log > 1) show_log = 0;
1167 case '+': /* scroll down */
1171 case '-': /* scroll up */
1176 case '*': /* scroll right */
1180 case '/': /* scroll left */
1185 case 10: /* entermode */
1195 /* check for logfh */
1200 /* cleanup curses and exit */
1208 * Send command and show error message.
1210 char *admin_cmd(int sock, int mode, char *extension, char *number)
1212 static struct admin_message msg;
1214 /* send reload command */
1215 memset(&msg, 0, sizeof(msg));
1218 case MODE_INTERFACE:
1219 msg.message = ADMIN_REQUEST_CMD_INTERFACE;
1222 msg.message = ADMIN_REQUEST_CMD_ROUTE;
1225 msg.message = ADMIN_REQUEST_CMD_DIAL;
1226 SPRINT(msg.u.x.message, "%s:%s", extension?:"", number?:"");
1229 msg.message = ADMIN_REQUEST_CMD_RELEASE;
1230 SCPY(msg.u.x.message, number);
1233 msg.message = ADMIN_REQUEST_CMD_BLOCK;
1234 msg.u.x.portnum = atoi(number);
1238 msg.message = ADMIN_REQUEST_CMD_BLOCK;
1239 msg.u.x.portnum = atoi(number);
1243 msg.message = ADMIN_REQUEST_CMD_BLOCK;
1244 msg.u.x.portnum = atoi(number);
1249 if (write(sock, &msg, sizeof(msg)) != sizeof(msg))
1250 return("Broken pipe while sending command.");
1252 /* receive response */
1253 if (read(sock, &msg, sizeof(msg)) != sizeof(msg))
1254 return("Broken pipe while receiving response.");
1257 case MODE_INTERFACE:
1258 if (msg.message != ADMIN_RESPONSE_CMD_INTERFACE)
1259 return("Response not valid.");
1262 if (msg.message != ADMIN_RESPONSE_CMD_ROUTE)
1263 return("Response not valid.");
1266 if (msg.message != ADMIN_RESPONSE_CMD_DIAL)
1267 return("Response not valid.");
1270 if (msg.message != ADMIN_RESPONSE_CMD_RELEASE)
1271 return("Response not valid.");
1276 if (msg.message != ADMIN_RESPONSE_CMD_BLOCK)
1277 return("Response not valid.");
1281 /* process response */
1284 return(msg.u.x.message);
1286 printf("Command successfull.\n");
1294 char *admin_testcall(int sock, int argc, char *argv[])
1296 static struct admin_message msg;
1298 printf("pid=%d\n", getpid()); fflush(stdout);
1300 /* send reload command */
1301 memset(&msg, 0, sizeof(msg));
1302 msg.message = ADMIN_CALL_SETUP;
1305 SCPY(msg.u.call.interface, argv[2]);
1309 SCPY(msg.u.call.callerid, argv[3]);
1313 SCPY(msg.u.call.dialing, argv[4]);
1317 if (argv[5][0] == 'p')
1318 msg.u.call.present = 1;
1320 msg.u.call.bc_capa = 0x00; /*INFO_BC_SPEECH*/
1321 msg.u.call.bc_mode = 0x00; /*INFO_BMODE_CIRCUIT*/
1322 msg.u.call.bc_info1 = 0;
1324 msg.u.call.exthlc = 0;
1326 msg.u.call.bc_capa = strtol(argv[6],NULL,0);
1328 msg.u.call.bc_info1 = 3 | 0x80; /* alaw, if no capability is given at all */
1330 msg.u.call.bc_mode = strtol(argv[7],NULL,0);
1331 if (msg.u.call.bc_mode) msg.u.call.bc_mode = 2;
1334 msg.u.call.bc_info1 = strtol(argv[8],NULL,0);
1335 if (msg.u.call.bc_info1 < 0)
1336 msg.u.call.bc_info1 = 0;
1338 msg.u.call.bc_info1 |= 0x80;
1341 msg.u.call.hlc = strtol(argv[9],NULL,0);
1342 if (msg.u.call.hlc < 0)
1345 msg.u.call.hlc |= 0x80;
1347 // printf("hlc=%d\n", msg.u.call.hlc);
1349 msg.u.call.exthlc = strtol(argv[10],NULL,0);
1350 if (msg.u.call.exthlc < 0)
1351 msg.u.call.exthlc = 0;
1353 msg.u.call.exthlc |= 0x80;
1356 if (write(sock, &msg, sizeof(msg)) != sizeof(msg))
1357 return("Broken pipe while sending command.");
1359 /* receive response */
1361 if (read(sock, &msg, sizeof(msg)) != sizeof(msg))
1362 return("Broken pipe while receiving response.");
1365 case ADMIN_CALL_SETUP_ACK:
1366 printf("SETUP ACKNOWLEDGE\n"); fflush(stdout);
1369 case ADMIN_CALL_PROCEEDING:
1370 printf("PROCEEDING\n"); fflush(stdout);
1373 case ADMIN_CALL_ALERTING:
1374 printf("ALERTING\n"); fflush(stdout);
1377 case ADMIN_CALL_CONNECT:
1378 printf("CONNECT\n number=%s\n", msg.u.call.callerid); fflush(stdout);
1381 case ADMIN_CALL_NOTIFY:
1382 printf("NOTIFY\n notify=%d\n number=%s\n", msg.u.call.notify, msg.u.call.callerid); fflush(stdout);
1385 case ADMIN_CALL_DISCONNECT:
1386 printf("DISCONNECT\n cause=%d %s\n location=%d %s\n", msg.u.call.cause, (msg.u.call.cause>0 && msg.u.call.cause<128)?isdn_cause[msg.u.call.cause].german:"", msg.u.call.location, (msg.u.call.location>=0 && msg.u.call.location<128)?isdn_location[msg.u.call.location].german:""); fflush(stdout);
1389 case ADMIN_CALL_RELEASE:
1390 printf("RELEASE\n cause=%d %s\n location=%d %s\n", msg.u.call.cause, (msg.u.call.cause>0 && msg.u.call.cause<128)?isdn_cause[msg.u.call.cause].german:"", msg.u.call.location, (msg.u.call.location>=0 && msg.u.call.location<128)?isdn_location[msg.u.call.location].german:""); fflush(stdout);
1394 return("Response not valid.");
1397 printf("Command successfull.\n");
1405 char *admin_trace(int sock, int argc, char *argv[])
1407 static struct admin_message msg;
1411 if (argc > 2) if (!strcasecmp(argv[2], "help"))
1413 printf("Trace Help\n----------\n");
1414 printf("%s trace [brief|short] [<filter>=<value> [...]]\n\n", argv[0]);
1415 printf("By default a complete trace is shown in detailed format.\n");
1416 printf("To show a more compact format, use 'brief' or 'short' keyword.\n");
1417 printf("Use filter values to select specific trace messages.\n");
1418 printf("All given filter values must match. If no filter is given, anything matches.\n\n");
1419 printf("Filters:\n");
1420 printf(" category=<mask bits>\n");
1421 printf(" 0x01 = CH: channel object trace\n");
1422 printf(" 0x02 = EP: endpoint object trace\n");
1423 printf(" port=<mISDN port> select only given port for trace\n");
1424 printf(" interface=<interface name> select only given interface for trace\n");
1425 printf(" caller=<caller id> select only given caller id for trace\n");
1426 printf(" dialing=<number> select only given dialed number for trace\n");
1430 /* init trace request */
1431 memset(&msg, 0, sizeof(msg));
1432 msg.message = ADMIN_TRACE_REQUEST;
1433 msg.u.trace_req.detail = 3;
1439 if (!strcasecmp(argv[i], "brief"))
1440 msg.u.trace_req.detail = 1;
1441 else if (!strcasecmp(argv[i], "short"))
1442 msg.u.trace_req.detail = 2;
1443 else if (!strncasecmp(argv[i], "category=", 9))
1444 msg.u.trace_req.category = atoi(argv[i]+9);
1445 else if (!strncasecmp(argv[i], "port=", 5))
1446 msg.u.trace_req.port = atoi(argv[i]+5);
1447 else if (!strncasecmp(argv[i], "interface=", 10))
1448 SCPY(msg.u.trace_req.interface, argv[i]+10);
1449 else if (!strncasecmp(argv[i], "caller=", 7))
1450 SCPY(msg.u.trace_req.caller, argv[i]+7);
1451 else if (!strncasecmp(argv[i], "dialing=", 8))
1452 SCPY(msg.u.trace_req.dialing, argv[i]+8);
1453 else return("Invalid trace option, try 'trace help'.");
1458 /* send trace request */
1459 if (write(sock, &msg, sizeof(msg)) != sizeof(msg))
1460 return("Broken pipe while sending trace request.");
1462 /* receive response */
1464 if (read(sock, &msg, sizeof(msg)) != sizeof(msg))
1465 return("Broken pipe while receiving response.");
1467 if (msg.message != ADMIN_TRACE_RESPONSE)
1468 return("Response not valid.");
1470 printf("%s", msg.u.trace_rsp.text);
1478 int main(int argc, char *argv[])
1481 char *socket_name = SOCKET_NAME;
1483 struct sockaddr_un sock_address;
1492 printf("Usage: %s state | interface | route | dial ...\n", argv[0]);
1493 printf("state - View current states using graphical console output.\n");
1494 printf("interface - Tell LCR to reload \"interface.conf\".\n");
1495 printf("route - Tell LCR to reload \"route.conf\".\n");
1496 printf("dial <extension> <number> - Tell LCR the next number to dial for extension.\n");
1497 printf("release <number> - Tell LCR to release endpoint with given number.\n");
1498 printf("block <port> - Block given port.\n");
1499 printf("unblock <port> - Unblock given port.\n");
1500 printf("unload <port> - Unload port. To load port use 'block' or 'unblock'.\n");
1501 printf("testcall <interface> <callerid> <number> [present|restrict [<capability>]] - Testcall\n");
1502 printf(" -> capability = <bc> <mode> <codec> <hlc> <exthlc> (Values must be numbers, -1 to omit.)\n");
1503 printf("trace [brief|short] [<filter> [...]] - Shows call trace. Use filter to reduce output.\n");
1504 printf(" -> Use 'trace help' to see filter description.\n");
1510 if (!(strcasecmp(argv[1],"state")))
1514 if (!(strcasecmp(argv[1],"interface")))
1516 mode = MODE_INTERFACE;
1518 if (!(strcasecmp(argv[1],"route")))
1522 if (!(strcasecmp(argv[1],"dial")))
1528 if (!(strcasecmp(argv[1],"release")))
1532 mode = MODE_RELEASE;
1534 if (!(strcasecmp(argv[1],"unblock")))
1538 mode = MODE_UNBLOCK;
1540 if (!(strcasecmp(argv[1],"block")))
1546 if (!(strcasecmp(argv[1],"unload")))
1552 if (!(strcasecmp(argv[1],"testcall")))
1556 mode = MODE_TESTCALL;
1558 if (!(strcasecmp(argv[1],"trace")))
1568 if ((sock = socket(PF_UNIX, SOCK_STREAM, 0)) < 0)
1570 fprintf(stderr, "Failed to create socket.\n");
1573 memset(&sock_address, 0, sizeof(sock_address));
1574 sock_address.sun_family = PF_UNIX;
1575 UCPY(sock_address.sun_path, socket_name);
1576 if ((conn = connect(sock, (struct sockaddr *)&sock_address, SUN_LEN(&sock_address))) < 0)
1579 fprintf(stderr, "Failed to connect to socket \"%s\".\nIs LCR running?\n", sock_address.sun_path);
1587 ret = admin_state(sock, argv);
1590 case MODE_INTERFACE:
1592 ret = admin_cmd(sock, mode, NULL, NULL);
1596 ret = admin_cmd(sock, mode, argv[2], argv[3]);
1603 ret = admin_cmd(sock, mode, NULL, argv[2]);
1607 ret = admin_testcall(sock, argc, argv);
1610 ret = admin_trace(sock, argc, argv);
1614 /* now we say good bye */
1617 // if (!strncasecmp(ret, "Broken Pipe", 11))
1619 printf("%s\n", ret);