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 /* find number of epoints */
409 j = msg->u.s.interfaces+msg->u.s.joins;
410 jj = j + msg->u.s.epoints;
414 if (m[j].u.e.join == join)
418 /* loop all related endpoints */
419 j = msg->u.s.interfaces+msg->u.s.joins;
420 jj = j + msg->u.s.epoints;
423 if (m[j].u.e.join == join)
426 move(++line>1?line:1, 1);
432 move(line>1?line:1, 4);
433 if (line+2 >= LINES) break;
434 line = debug_epoint(msg, m, line, j, i?1:0);
435 if (line+2 >= LINES) break;
442 char *admin_state(int sock, char *argv[])
444 struct admin_message msg,
448 int line, offset = 0, hoffset = 0;
457 char enter_string[128] = "", ch;
459 /* flush logfile name */
466 /* send reload command */
467 memset(&msg, 0, sizeof(msg));
468 msg.message = ADMIN_REQUEST_STATE;
469 // printf("sizeof=%d\n",sizeof(msg));fflush(stdout);
470 if (write(sock, &msg, sizeof(msg)) != sizeof(msg))
473 return("Broken pipe while sending command.");
476 /* receive response */
477 if (read(sock, &msg, sizeof(msg)) != sizeof(msg))
480 return("Broken pipe while receiving response.");
483 if (msg.message != ADMIN_RESPONSE_STATE)
486 return("Response not valid. Expecting state response.");
488 num = msg.u.s.interfaces + msg.u.s.joins + msg.u.s.epoints + msg.u.s.ports;
489 m = (struct admin_message *)MALLOC(num*sizeof(struct admin_message));
494 if ((len = read(sock, ((unsigned char *)(m))+off, num*sizeof(struct admin_message)-off)) != num*(int)sizeof(struct admin_message)-off)
498 // fprintf(stderr, "got=%d expected=%d\n", i, num*sizeof(struct admin_message));
500 return("Broken pipe while receiving state infos.");
502 if (len < num*(int)sizeof(struct admin_message))
511 // fprintf("getting =%d interfaces\n", msg.u.s.interfaces);
512 while(i < msg.u.s.interfaces)
514 // fprintf(stderr, "j=%d message=%d\n", j, m[j].message);
515 if (m[j].message != ADMIN_RESPONSE_S_INTERFACE)
519 return("Response not valid. Expecting interface information.");
525 while(i < msg.u.s.joins)
527 if (m[j].message != ADMIN_RESPONSE_S_JOIN)
531 return("Response not valid. Expecting call information.");
537 while(i < msg.u.s.epoints)
539 if (m[j].message != ADMIN_RESPONSE_S_EPOINT)
543 return("Response not valid. Expecting endpoint information.");
549 while(i < msg.u.s.ports)
551 if (m[j].message != ADMIN_RESPONSE_S_PORT)
555 return("Response not valid. Expecting port information.");
560 // now j is the number of message blocks
568 if (!!strcmp(logfile, msg.u.s.logfile))
570 SCPY(logfile, msg.u.s.logfile);
578 logline[i][1] = '\0';
582 logfh = open(logfile, O_RDONLY|O_NONBLOCK);
585 /* seek at the end -8000 chars */
586 lseek(logfh, -8000, SEEK_END);
587 /* if not at the beginning, read until endofline */
588 logline[logcur % LOGLINES][0] = '\0';
589 l = read(logfh, logline[logcur % LOGLINES], sizeof(logline[logcur % LOGLINES])-1);
592 /* read first line and skip junk */
593 logline[logcur % LOGLINES][l] = '\0';
594 if ((p = strchr(logline[logcur % LOGLINES],'\n')))
597 SCPY(logline[logcur % LOGLINES], p+1);
598 SCPY(logline[(logcur-1) % LOGLINES], "...");
610 ll = strlen(logline[logcur % LOGLINES]);
611 l = read(logfh, logline[logcur % LOGLINES]+ll, sizeof(logline[logcur % LOGLINES])-ll-1);
614 logline[logcur % LOGLINES][ll+l] = '\0';
616 /* put data to lines */
617 while ((p = strchr(logline[logcur % LOGLINES],'\n')))
621 SCPY(logline[logcur % LOGLINES], p+1);
623 /* if line is full without return, go next line */
624 if (strlen(logline[logcur % LOGLINES]) == sizeof(logline[logcur % LOGLINES])-1)
627 logline[logcur % LOGLINES][0] = '\0';
632 /* display interfaces */
633 if (show_interfaces > 0)
637 ii = i + msg.u.s.interfaces;
640 /* show interface summary */
641 move(++line>1?line:1, 0);
643 if (m[i].u.i.block >= 2)
645 SPRINT(buffer, "%s (%d)%s", m[i].u.i.interface_name, m[i].u.i.portnum, (m[i].u.i.extension)?" (extension)":"");
648 addstr(" not loaded");
651 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);
653 if (m[i].u.i.ptp || !m[i].u.i.ntmode)
655 color((m[i].u.i.l2link)?green:red);
656 addstr((m[i].u.i.l2link)?" L2 UP":" L2 down");
658 color((m[i].u.i.l1link)?green:blue);
659 addstr((m[i].u.i.l1link)?" L1 ACTIVE":" L1 inactive");
665 if (line+2 >= LINES) goto end;
667 if (show_interfaces > 1)
671 jj = m[i].u.i.channels;
674 /* show all channels */
675 if (show_interfaces>2 || m[i].u.i.busy[j]>0)
678 /* show left side / right side */
679 if ((k & 1) && (COLS > 70))
681 move(line>1?line:1,4+((COLS-4)/2));
684 move(++line>1?line:1, 1);
691 SPRINT(buffer,"S%2d: ", j+1+(j>=15));
693 SPRINT(buffer,"B%2d: ", j+1);
697 if (m[i].u.i.l2link && m[i].u.i.block==0)
700 color((m[i].u.i.busy[j])?yellow:blue);
701 addstr((m[i].u.i.busy[j])?"busy":"idle");
707 if (m[i].u.i.port[j])
709 /* search for port */
710 l = msg.u.s.interfaces+msg.u.s.joins+msg.u.s.epoints;
711 ll = l+msg.u.s.ports;
714 if (m[l].u.p.serial == m[i].u.i.port[j])
716 SPRINT(buffer, " %s(%ld)", m[l].u.p.name, m[l].u.p.serial);
727 move(line>1?line:1, 1);
738 move(line>1?line:1, 1);
741 if (line+2 >= LINES) goto end;
742 /* show summary if no channels were shown */
743 if (show_interfaces<2 && ltee==0)
746 move(++line>1?line:1, 1);
749 if (m[i].u.i.l2link && m[i].u.i.block==0)
752 SPRINT(buffer,"all %d channels free", m[i].u.i.channels);
756 SPRINT(buffer,"all %d channels blocked", m[i].u.i.channels);
760 if (line+2 >= LINES) goto end;
768 if (line+2 >= LINES) goto end;
770 /* display calls (brief) */
774 i = msg.u.s.interfaces+msg.u.s.joins;
775 ii = i+msg.u.s.epoints;
778 /* for each endpoint... */
781 move(++line>1?line:1, 0);
783 SPRINT(buffer, "(%d): ", m[i].u.e.serial);
786 if (m[i].u.e.terminal[0])
790 addstr(m[i].u.e.terminal);
794 SPRINT(buffer, " %s", m[i].u.e.callerid);
799 SPRINT(buffer, "%s", m[i].u.e.dialing);
801 if (m[i].u.e.action[0])
806 addstr(m[i].u.e.action);
808 if (line+2 >= LINES) goto end;
813 j = msg.u.s.interfaces;
814 jj = j+msg.u.s.joins;
817 /* for each call... */
818 move(++line>1?line:1, 0);
820 SPRINT(buffer, "(%d):", m[j].u.j.serial);
822 i = msg.u.s.interfaces+msg.u.s.joins;
823 ii = i+msg.u.s.epoints;
826 /* for each endpoint... */
827 if (m[i].u.e.join == m[j].u.j.serial)
830 SPRINT(buffer, " (%d)", m[i].u.e.serial);
833 if (m[i].u.e.terminal[0])
837 addstr(m[i].u.e.terminal);
841 SPRINT(buffer, "-%s", m[i].u.e.callerid);
846 SPRINT(buffer, "%s", m[i].u.e.dialing);
852 if (line+2 >= LINES) goto end;
857 if (line+2 >= LINES) goto end;
859 /* display calls (structurd) */
862 /* show all ports with no epoint */
864 i = msg.u.s.interfaces+msg.u.s.joins+msg.u.s.epoints;
865 ii = i+msg.u.s.ports;
868 if (!m[i].u.p.epoint)
870 move(++line>1?line:1, 8);
871 if (line+2 >= LINES) goto end;
872 line = debug_port(&msg, m, line, i, 0);
873 if (line+2 >= LINES) goto end;
880 if (line+2 >= LINES) goto end;
882 /* show all epoints with no call */
884 i = msg.u.s.interfaces+msg.u.s.joins;
885 ii = i+msg.u.s.epoints;
890 move(++line>1?line:1, 4);
891 if (line+2 >= LINES) goto end;
892 line = debug_epoint(&msg, m, line, i, 0);
893 if (line+2 >= LINES) goto end;
900 if (line+2 >= LINES) goto end;
904 i = msg.u.s.interfaces;
905 ii = i+msg.u.s.joins;
908 move(++line>1?line:1, 0);
909 if (line+2 >= LINES) goto end;
910 line = debug_join(&msg, m, line, i);
911 if (line+2 >= LINES) goto end;
917 if (line+2 >= LINES) goto end;
926 move(line++>1?line-1:1, 0);
928 hline(ACS_HLINE, COLS);
931 l = logcur-(LINES-line-2);
933 if (ll-l >= LOGLINES)
937 move(line++>1?line-1:1, 0);
938 if (strlen(logline[l % LOGLINES]) > hoffset)
939 SCPY(buffer, logline[l % LOGLINES] + hoffset);
942 if (COLS < (int)strlen(buffer))
944 buffer[COLS-1] = '\0';
959 /* display name/time */
964 msg.u.s.version_string[sizeof(msg.u.s.version_string)-1] = '\0';
965 SPRINT(buffer, "LCR %s", msg.u.s.version_string);
970 SPRINT(buffer, "%04d-%02d-%02d %02d:%02d:%02d",
971 msg.u.s.tm.tm_year+1900, msg.u.s.tm.tm_mon+1, msg.u.s.tm.tm_mday,
972 msg.u.s.tm.tm_hour, msg.u.s.tm.tm_min, msg.u.s.tm.tm_sec);
975 /* displeay head line */
978 hline(ACS_HLINE, COLS);
982 SPRINT(buffer, "Offset +%d", offset);
989 SPRINT(buffer, "H-Offset +%d", hoffset);
996 hline(ACS_HLINE, COLS);
1000 SPRINT(buffer, "-> %s", enter_string);
1002 SPRINT(buffer, "i=interfaces '%s' c=calls '%s' l=log q=quit +-*/=scroll enter", text_interfaces[show_interfaces], text_calls[show_calls]);
1007 if (lastlines!=LINES || lastcols!=COLS)
1016 /* user input in enter mode */
1023 if (!enter_string[0])
1026 SPRINT(logline[logcur++ % LOGLINES], "> %s", enter_string);
1027 if (!!strncmp(enter_string, "interface", 10) &&
1028 !!strncmp(enter_string, "route", 6) &&
1029 !!strncmp(enter_string, "release ", 8) &&
1030 !!strncmp(enter_string, "block ", 6) &&
1031 !!strncmp(enter_string, "unblock ", 8) &&
1032 !!strncmp(enter_string, "unload ", 7))
1034 SPRINT(logline[logcur++ % LOGLINES], "usage:");
1035 SPRINT(logline[logcur++ % LOGLINES], "interface (reload interface.conf)");
1036 SPRINT(logline[logcur++ % LOGLINES], "route (reload routing.conf)");
1037 SPRINT(logline[logcur++ % LOGLINES], "release <EP> (release endpoint with given ID)");
1038 SPRINT(logline[logcur++ % LOGLINES], "block <port> (block port for further calls)");
1039 SPRINT(logline[logcur++ % LOGLINES], "unblock <port> (unblock port for further calls, load if not loaded)");
1040 SPRINT(logline[logcur++ % LOGLINES], "unload <port> (unload mISDN stack, release call calls)");
1043 /* applend output to log window */
1044 SPRINT(buffer, "%s %s", argv[0], enter_string);
1045 fp = popen(buffer, "r");
1048 while(fgets(logline[logcur % LOGLINES], sizeof(logline[0]), fp))
1049 logline[logcur++ % LOGLINES][sizeof(logline[0])-1] = '\0';
1053 SPRINT(logline[logcur++ % LOGLINES], "failed to execute '%s'", buffer);
1056 logline[logcur % LOGLINES][0] = '\0';
1057 enter_string[0] = '\0';
1060 if (ch>=32 && ch<=126)
1062 SCCAT(enter_string, ch);
1065 if (ch==8 || ch==127)
1067 if (enter_string[0])
1068 enter_string[strlen(enter_string)-1] = '\0';
1078 /* user input in normal mode */
1081 case 12: /* refresh */
1092 case 'i': /* toggle interface */
1094 if (show_interfaces > 3) show_interfaces = 0;
1097 case 'c': /* toggle calls */
1099 if (show_calls > 2) show_calls = 0;
1102 case 'l': /* toggle log */
1104 if (show_log > 1) show_log = 0;
1107 case '+': /* scroll down */
1111 case '-': /* scroll up */
1116 case '*': /* scroll right */
1120 case '/': /* scroll left */
1125 case 10: /* entermode */
1135 /* check for logfh */
1140 /* cleanup curses and exit */
1148 * Send command and show error message.
1150 char *admin_cmd(int sock, int mode, char *extension, char *number)
1152 static struct admin_message msg;
1154 /* send reload command */
1155 memset(&msg, 0, sizeof(msg));
1158 case MODE_INTERFACE:
1159 msg.message = ADMIN_REQUEST_CMD_INTERFACE;
1162 msg.message = ADMIN_REQUEST_CMD_ROUTE;
1165 msg.message = ADMIN_REQUEST_CMD_DIAL;
1166 SPRINT(msg.u.x.message, "%s:%s", extension?:"", number?:"");
1169 msg.message = ADMIN_REQUEST_CMD_RELEASE;
1170 SCPY(msg.u.x.message, number);
1173 msg.message = ADMIN_REQUEST_CMD_BLOCK;
1174 msg.u.x.portnum = atoi(number);
1178 msg.message = ADMIN_REQUEST_CMD_BLOCK;
1179 msg.u.x.portnum = atoi(number);
1183 msg.message = ADMIN_REQUEST_CMD_BLOCK;
1184 msg.u.x.portnum = atoi(number);
1189 if (write(sock, &msg, sizeof(msg)) != sizeof(msg))
1190 return("Broken pipe while sending command.");
1192 /* receive response */
1193 if (read(sock, &msg, sizeof(msg)) != sizeof(msg))
1194 return("Broken pipe while receiving response.");
1197 case MODE_INTERFACE:
1198 if (msg.message != ADMIN_RESPONSE_CMD_INTERFACE)
1199 return("Response not valid.");
1202 if (msg.message != ADMIN_RESPONSE_CMD_ROUTE)
1203 return("Response not valid.");
1206 if (msg.message != ADMIN_RESPONSE_CMD_DIAL)
1207 return("Response not valid.");
1210 if (msg.message != ADMIN_RESPONSE_CMD_RELEASE)
1211 return("Response not valid.");
1216 if (msg.message != ADMIN_RESPONSE_CMD_BLOCK)
1217 return("Response not valid.");
1221 /* process response */
1224 return(msg.u.x.message);
1226 printf("Command successfull.\n");
1234 char *admin_testcall(int sock, int argc, char *argv[])
1236 static struct admin_message msg;
1238 printf("pid=%d\n", getpid()); fflush(stdout);
1240 /* send reload command */
1241 memset(&msg, 0, sizeof(msg));
1242 msg.message = ADMIN_CALL_SETUP;
1245 SCPY(msg.u.call.interface, argv[2]);
1249 SCPY(msg.u.call.callerid, argv[3]);
1253 SCPY(msg.u.call.dialing, argv[4]);
1257 if (argv[5][0] == 'p')
1258 msg.u.call.present = 1;
1260 msg.u.call.bc_capa = 0x00; /*INFO_BC_SPEECH*/
1261 msg.u.call.bc_mode = 0x00; /*INFO_BMODE_CIRCUIT*/
1262 msg.u.call.bc_info1 = 0;
1264 msg.u.call.exthlc = 0;
1266 msg.u.call.bc_capa = strtol(argv[6],NULL,0);
1268 msg.u.call.bc_info1 = 3 | 0x80; /* alaw, if no capability is given at all */
1270 msg.u.call.bc_mode = strtol(argv[7],NULL,0);
1271 if (msg.u.call.bc_mode) msg.u.call.bc_mode = 2;
1274 msg.u.call.bc_info1 = strtol(argv[8],NULL,0);
1275 if (msg.u.call.bc_info1 < 0)
1276 msg.u.call.bc_info1 = 0;
1278 msg.u.call.bc_info1 |= 0x80;
1281 msg.u.call.hlc = strtol(argv[9],NULL,0);
1282 if (msg.u.call.hlc < 0)
1285 msg.u.call.hlc |= 0x80;
1287 // printf("hlc=%d\n", msg.u.call.hlc);
1289 msg.u.call.exthlc = strtol(argv[10],NULL,0);
1290 if (msg.u.call.exthlc < 0)
1291 msg.u.call.exthlc = 0;
1293 msg.u.call.exthlc |= 0x80;
1296 if (write(sock, &msg, sizeof(msg)) != sizeof(msg))
1297 return("Broken pipe while sending command.");
1299 /* receive response */
1301 if (read(sock, &msg, sizeof(msg)) != sizeof(msg))
1302 return("Broken pipe while receiving response.");
1305 case ADMIN_CALL_SETUP_ACK:
1306 printf("SETUP ACKNOWLEDGE\n"); fflush(stdout);
1309 case ADMIN_CALL_PROCEEDING:
1310 printf("PROCEEDING\n"); fflush(stdout);
1313 case ADMIN_CALL_ALERTING:
1314 printf("ALERTING\n"); fflush(stdout);
1317 case ADMIN_CALL_CONNECT:
1318 printf("CONNECT\n number=%s\n", msg.u.call.callerid); fflush(stdout);
1321 case ADMIN_CALL_NOTIFY:
1322 printf("NOTIFY\n notify=%d\n number=%s\n", msg.u.call.notify, msg.u.call.callerid); fflush(stdout);
1325 case ADMIN_CALL_DISCONNECT:
1326 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);
1329 case ADMIN_CALL_RELEASE:
1330 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);
1334 return("Response not valid.");
1337 printf("Command successfull.\n");
1345 char *admin_trace(int sock, int argc, char *argv[])
1347 static struct admin_message msg;
1351 if (argc > 2) if (!strcasecmp(argv[2], "help"))
1353 printf("Trace Help\n----------\n");
1354 printf("%s trace [brief|short] [<filter>=<value> [...]]\n\n", argv[0]);
1355 printf("By default a complete trace is shown in detailed format.\n");
1356 printf("To show a more compact format, use 'brief' or 'short' keyword.\n");
1357 printf("Use filter values to select specific trace messages.\n");
1358 printf("All given filter values must match. If no filter is given, anything matches.\n\n");
1359 printf("Filters:\n");
1360 printf(" category=<mask bits>\n");
1361 printf(" 0x01 = CH: channel object trace\n");
1362 printf(" 0x02 = EP: endpoint object trace\n");
1363 printf(" port=<mISDN port> select only given port for trace\n");
1364 printf(" interface=<interface name> select only given interface for trace\n");
1365 printf(" caller=<caller id> select only given caller id for trace\n");
1366 printf(" dialing=<number> select only given dialed number for trace\n");
1370 /* init trace request */
1371 memset(&msg, 0, sizeof(msg));
1372 msg.message = ADMIN_TRACE_REQUEST;
1373 msg.u.trace_req.detail = 3;
1379 if (!strcasecmp(argv[i], "brief"))
1380 msg.u.trace_req.detail = 1;
1381 else if (!strcasecmp(argv[i], "short"))
1382 msg.u.trace_req.detail = 2;
1383 else if (!strncasecmp(argv[i], "category=", 9))
1384 msg.u.trace_req.category = atoi(argv[i]+9);
1385 else if (!strncasecmp(argv[i], "port=", 5))
1386 msg.u.trace_req.port = atoi(argv[i]+5);
1387 else if (!strncasecmp(argv[i], "interface=", 10))
1388 SCPY(msg.u.trace_req.interface, argv[i]+10);
1389 else if (!strncasecmp(argv[i], "caller=", 7))
1390 SCPY(msg.u.trace_req.caller, argv[i]+7);
1391 else if (!strncasecmp(argv[i], "dialing=", 8))
1392 SCPY(msg.u.trace_req.dialing, argv[i]+8);
1393 else return("Invalid trace option, try 'trace help'.");
1398 /* send trace request */
1399 if (write(sock, &msg, sizeof(msg)) != sizeof(msg))
1400 return("Broken pipe while sending trace request.");
1402 /* receive response */
1404 if (read(sock, &msg, sizeof(msg)) != sizeof(msg))
1405 return("Broken pipe while receiving response.");
1407 if (msg.message != ADMIN_TRACE_RESPONSE)
1408 return("Response not valid.");
1410 printf("%s", msg.u.trace_rsp.text);
1418 int main(int argc, char *argv[])
1421 char *socket_name = SOCKET_NAME;
1423 struct sockaddr_un sock_address;
1432 printf("Usage: %s state | interface | route | dial ...\n", argv[0]);
1433 printf("state - View current states using graphical console output.\n");
1434 printf("interface - Tell LCR to reload \"interface.conf\".\n");
1435 printf("route - Tell LCR to reload \"route.conf\".\n");
1436 printf("dial <extension> <number> - Tell LCR the next number to dial for extension.\n");
1437 printf("release <number> - Tell LCR to release endpoint with given number.\n");
1438 printf("block <port> - Block given port.\n");
1439 printf("unblock <port> - Unblock given port.\n");
1440 printf("unload <port> - Unload port. To load port use 'block' or 'unblock'.\n");
1441 printf("testcall <interface> <callerid> <number> [present|restrict [<capability>]] - Testcall\n");
1442 printf(" -> capability = <bc> <mode> <codec> <hlc> <exthlc> (Values must be numbers, -1 to omit.)\n");
1443 printf("trace [brief|short] [<filter> [...]] - Shows call trace. Use filter to reduce output.\n");
1444 printf(" -> Use 'trace help' to see filter description.\n");
1450 if (!(strcasecmp(argv[1],"state")))
1454 if (!(strcasecmp(argv[1],"interface")))
1456 mode = MODE_INTERFACE;
1458 if (!(strcasecmp(argv[1],"route")))
1462 if (!(strcasecmp(argv[1],"dial")))
1468 if (!(strcasecmp(argv[1],"release")))
1472 mode = MODE_RELEASE;
1474 if (!(strcasecmp(argv[1],"unblock")))
1478 mode = MODE_UNBLOCK;
1480 if (!(strcasecmp(argv[1],"block")))
1486 if (!(strcasecmp(argv[1],"unload")))
1492 if (!(strcasecmp(argv[1],"testcall")))
1496 mode = MODE_TESTCALL;
1498 if (!(strcasecmp(argv[1],"trace")))
1508 if ((sock = socket(PF_UNIX, SOCK_STREAM, 0)) < 0)
1510 fprintf(stderr, "Failed to create socket.\n");
1513 memset(&sock_address, 0, sizeof(sock_address));
1514 sock_address.sun_family = PF_UNIX;
1515 UCPY(sock_address.sun_path, socket_name);
1516 if ((conn = connect(sock, (struct sockaddr *)&sock_address, SUN_LEN(&sock_address))) < 0)
1519 fprintf(stderr, "Failed to connect to socket \"%s\".\nIs LCR running?\n", sock_address.sun_path);
1527 ret = admin_state(sock, argv);
1530 case MODE_INTERFACE:
1532 ret = admin_cmd(sock, mode, NULL, NULL);
1536 ret = admin_cmd(sock, mode, argv[2], argv[3]);
1543 ret = admin_cmd(sock, mode, NULL, argv[2]);
1547 ret = admin_testcall(sock, argc, argv);
1550 ret = admin_trace(sock, argc, argv);
1554 /* now we say good bye */
1557 // if (!strncasecmp(ret, "Broken Pipe", 11))
1559 printf("%s\n", ret);