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)
444 struct admin_message msg,
448 int line, offset = 0;
457 /* flush logfile name */
464 /* send reload command */
465 memset(&msg, 0, sizeof(msg));
466 msg.message = ADMIN_REQUEST_STATE;
467 // printf("sizeof=%d\n",sizeof(msg));fflush(stdout);
468 if (write(sock, &msg, sizeof(msg)) != sizeof(msg))
471 return("Broken pipe while sending command.");
474 /* receive response */
475 if (read(sock, &msg, sizeof(msg)) != sizeof(msg))
478 return("Broken pipe while receiving response.");
481 if (msg.message != ADMIN_RESPONSE_STATE)
484 return("Response not valid. Expecting state response.");
486 num = msg.u.s.interfaces + msg.u.s.joins + msg.u.s.epoints + msg.u.s.ports;
487 m = (struct admin_message *)MALLOC(num*sizeof(struct admin_message));
492 if ((len = read(sock, ((unsigned char *)(m))+off, num*sizeof(struct admin_message)-off)) != num*(int)sizeof(struct admin_message)-off)
496 // fprintf(stderr, "got=%d expected=%d\n", i, num*sizeof(struct admin_message));
498 return("Broken pipe while receiving state infos.");
500 if (len < num*(int)sizeof(struct admin_message))
509 // fprintf("getting =%d interfaces\n", msg.u.s.interfaces);
510 while(i < msg.u.s.interfaces)
512 // fprintf(stderr, "j=%d message=%d\n", j, m[j].message);
513 if (m[j].message != ADMIN_RESPONSE_S_INTERFACE)
517 return("Response not valid. Expecting interface information.");
523 while(i < msg.u.s.joins)
525 if (m[j].message != ADMIN_RESPONSE_S_JOIN)
529 return("Response not valid. Expecting call information.");
535 while(i < msg.u.s.epoints)
537 if (m[j].message != ADMIN_RESPONSE_S_EPOINT)
541 return("Response not valid. Expecting endpoint information.");
547 while(i < msg.u.s.ports)
549 if (m[j].message != ADMIN_RESPONSE_S_PORT)
553 return("Response not valid. Expecting port information.");
558 // now j is the number of message blocks
566 if (!!strcmp(logfile, msg.u.s.logfile))
568 SCPY(logfile, msg.u.s.logfile);
576 logline[i][1] = '\0';
580 logfh = open(logfile, O_RDONLY|O_NONBLOCK);
583 /* seek at the end -8000 chars */
584 lseek(logfh, -8000, SEEK_END);
585 /* if not at the beginning, read until endofline */
586 logline[logcur % LOGLINES][0] = '\0';
587 l = read(logfh, logline[logcur % LOGLINES], sizeof(logline[logcur % LOGLINES])-1);
590 /* read first line and skip junk */
591 logline[logcur % LOGLINES][l] = '\0';
592 if ((p = strchr(logline[logcur % LOGLINES],'\n')))
595 SCPY(logline[logcur % LOGLINES], p+1);
596 SCPY(logline[(logcur-1) % LOGLINES], "...");
608 ll = strlen(logline[logcur % LOGLINES]);
609 l = read(logfh, logline[logcur % LOGLINES]+ll, sizeof(logline[logcur % LOGLINES])-ll-1);
612 logline[logcur % LOGLINES][ll+l] = '\0';
614 /* put data to lines */
615 while ((p = strchr(logline[logcur % LOGLINES],'\n')))
619 SCPY(logline[logcur % LOGLINES], p+1);
621 /* if line is full without return, go next line */
622 if (strlen(logline[logcur % LOGLINES]) == sizeof(logline[logcur % LOGLINES])-1)
625 logline[logcur % LOGLINES][0] = '\0';
630 /* display interfaces */
631 if (show_interfaces > 0)
635 ii = i + msg.u.s.interfaces;
638 /* show interface summary */
639 move(++line>1?line:1, 0);
641 if (m[i].u.i.block >= 2)
643 SPRINT(buffer, "%s (%d)%s", m[i].u.i.interface_name, m[i].u.i.portnum, (m[i].u.i.extension)?" (extension)":"");
646 addstr(" not loaded");
649 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);
651 if (m[i].u.i.ptp || !m[i].u.i.ntmode)
653 color((m[i].u.i.l2link)?green:red);
654 addstr((m[i].u.i.l2link)?" L2 UP":" L2 down");
656 color((m[i].u.i.l1link)?green:blue);
657 addstr((m[i].u.i.l1link)?" L1 ACTIVE":" L1 inactive");
663 if (line+2 >= LINES) goto end;
665 if (show_interfaces > 1)
669 jj = m[i].u.i.channels;
672 /* show all channels */
673 if (show_interfaces>2 || m[i].u.i.busy[j]>0)
676 /* show left side / right side */
677 if ((k & 1) && (COLS > 70))
679 move(line>1?line:1,4+((COLS-4)/2));
682 move(++line>1?line:1, 1);
689 SPRINT(buffer,"S%2d: ", j+1+(j>=15));
691 SPRINT(buffer,"B%2d: ", j+1);
695 if (m[i].u.i.l2link && m[i].u.i.block==0)
698 color((m[i].u.i.busy[j])?yellow:blue);
699 addstr((m[i].u.i.busy[j])?"busy":"idle");
705 if (m[i].u.i.port[j])
707 /* search for port */
708 l = msg.u.s.interfaces+msg.u.s.joins+msg.u.s.epoints;
709 ll = l+msg.u.s.ports;
712 if (m[l].u.p.serial == m[i].u.i.port[j])
714 SPRINT(buffer, " %s(%ld)", m[l].u.p.name, m[l].u.p.serial);
725 move(line>1?line:1, 1);
736 move(line>1?line:1, 1);
739 if (line+2 >= LINES) goto end;
740 /* show summary if no channels were shown */
741 if (show_interfaces<2 && ltee==0)
744 move(++line>1?line:1, 1);
747 if (m[i].u.i.l2link && m[i].u.i.block==0)
750 SPRINT(buffer,"all %d channels free", m[i].u.i.channels);
754 SPRINT(buffer,"all %d channels blocked", m[i].u.i.channels);
758 if (line+2 >= LINES) goto end;
766 if (line+2 >= LINES) goto end;
768 /* display calls (brief) */
772 i = msg.u.s.interfaces+msg.u.s.joins;
773 ii = i+msg.u.s.epoints;
776 /* for each endpoint... */
779 move(++line>1?line:1, 0);
781 SPRINT(buffer, "(%d): ", m[i].u.e.serial);
784 if (m[i].u.e.terminal[0])
788 addstr(m[i].u.e.terminal);
792 SPRINT(buffer, " %s", m[i].u.e.callerid);
797 SPRINT(buffer, "%s", m[i].u.e.dialing);
799 if (m[i].u.e.action[0])
804 addstr(m[i].u.e.action);
806 if (line+2 >= LINES) goto end;
811 j = msg.u.s.interfaces;
812 jj = j+msg.u.s.joins;
815 /* for each call... */
816 move(++line>1?line:1, 0);
818 SPRINT(buffer, "(%d):", m[j].u.j.serial);
820 i = msg.u.s.interfaces+msg.u.s.joins;
821 ii = i+msg.u.s.epoints;
824 /* for each endpoint... */
825 if (m[i].u.e.join == m[j].u.j.serial)
828 SPRINT(buffer, " (%d)", m[i].u.e.serial);
831 if (m[i].u.e.terminal[0])
835 addstr(m[i].u.e.terminal);
839 SPRINT(buffer, "-%s", m[i].u.e.callerid);
844 SPRINT(buffer, "%s", m[i].u.e.dialing);
850 if (line+2 >= LINES) goto end;
855 if (line+2 >= LINES) goto end;
857 /* display calls (structurd) */
860 /* show all ports with no epoint */
862 i = msg.u.s.interfaces+msg.u.s.joins+msg.u.s.epoints;
863 ii = i+msg.u.s.ports;
866 if (!m[i].u.p.epoint)
868 move(++line>1?line:1, 8);
869 if (line+2 >= LINES) goto end;
870 line = debug_port(&msg, m, line, i, 0);
871 if (line+2 >= LINES) goto end;
878 if (line+2 >= LINES) goto end;
880 /* show all epoints with no call */
882 i = msg.u.s.interfaces+msg.u.s.joins;
883 ii = i+msg.u.s.epoints;
888 move(++line>1?line:1, 4);
889 if (line+2 >= LINES) goto end;
890 line = debug_epoint(&msg, m, line, i, 0);
891 if (line+2 >= LINES) goto end;
898 if (line+2 >= LINES) goto end;
902 i = msg.u.s.interfaces;
903 ii = i+msg.u.s.joins;
906 move(++line>1?line:1, 0);
907 if (line+2 >= LINES) goto end;
908 line = debug_join(&msg, m, line, i);
909 if (line+2 >= LINES) goto end;
915 if (line+2 >= LINES) goto end;
924 move(line++>1?line-1:1, 0);
926 hline(ACS_HLINE, COLS);
929 l = logcur-(LINES-line-2);
931 if (ll-l >= LOGLINES)
935 move(line++>1?line-1:1, 0);
936 SCPY(buffer, logline[l % LOGLINES]);
937 if (COLS < (int)strlen(buffer))
948 /* display name/time */
953 msg.u.s.version_string[sizeof(msg.u.s.version_string)-1] = '\0';
954 SPRINT(buffer, "LCR %s", msg.u.s.version_string);
959 SPRINT(buffer, "%04d-%02d-%02d %02d:%02d:%02d",
960 msg.u.s.tm.tm_year+1900, msg.u.s.tm.tm_mon+1, msg.u.s.tm.tm_mday,
961 msg.u.s.tm.tm_hour, msg.u.s.tm.tm_min, msg.u.s.tm.tm_sec);
964 /* displeay head line */
967 hline(ACS_HLINE, COLS);
971 SPRINT(buffer, "Offset +%d", offset);
978 hline(ACS_HLINE, COLS);
981 SPRINT(buffer, "i = interfaces '%s' c = calls '%s' l = log q = quit +/- = scroll", text_interfaces[show_interfaces], text_calls[show_calls]);
986 if (lastlines!=LINES || lastcols!=COLS)
996 case 12: /* refresh */
1007 case 'i': /* toggle interface */
1009 if (show_interfaces > 3) show_interfaces = 0;
1012 case 'c': /* toggle calls */
1014 if (show_calls > 2) show_calls = 0;
1017 case 'l': /* toggle log */
1019 if (show_log > 1) show_log = 0;
1022 case '+': /* scroll down */
1026 case '-': /* scroll up */
1036 /* check for logfh */
1041 /* cleanup curses and exit */
1049 * Send command and show error message.
1051 char *admin_cmd(int sock, int mode, char *extension, char *number)
1053 static struct admin_message msg;
1055 /* send reload command */
1056 memset(&msg, 0, sizeof(msg));
1059 case MODE_INTERFACE:
1060 msg.message = ADMIN_REQUEST_CMD_INTERFACE;
1063 msg.message = ADMIN_REQUEST_CMD_ROUTE;
1066 msg.message = ADMIN_REQUEST_CMD_DIAL;
1067 SPRINT(msg.u.x.message, "%s:%s", extension?:"", number?:"");
1070 msg.message = ADMIN_REQUEST_CMD_RELEASE;
1071 SCPY(msg.u.x.message, number);
1074 msg.message = ADMIN_REQUEST_CMD_BLOCK;
1075 msg.u.x.portnum = atoi(number);
1079 msg.message = ADMIN_REQUEST_CMD_BLOCK;
1080 msg.u.x.portnum = atoi(number);
1084 msg.message = ADMIN_REQUEST_CMD_BLOCK;
1085 msg.u.x.portnum = atoi(number);
1090 if (write(sock, &msg, sizeof(msg)) != sizeof(msg))
1091 return("Broken pipe while sending command.");
1093 /* receive response */
1094 if (read(sock, &msg, sizeof(msg)) != sizeof(msg))
1095 return("Broken pipe while receiving response.");
1098 case MODE_INTERFACE:
1099 if (msg.message != ADMIN_RESPONSE_CMD_INTERFACE)
1100 return("Response not valid.");
1103 if (msg.message != ADMIN_RESPONSE_CMD_ROUTE)
1104 return("Response not valid.");
1107 if (msg.message != ADMIN_RESPONSE_CMD_DIAL)
1108 return("Response not valid.");
1111 if (msg.message != ADMIN_RESPONSE_CMD_RELEASE)
1112 return("Response not valid.");
1117 if (msg.message != ADMIN_RESPONSE_CMD_BLOCK)
1118 return("Response not valid.");
1122 /* process response */
1125 return(msg.u.x.message);
1127 printf("Command successfull.\n");
1135 char *admin_testcall(int sock, int argc, char *argv[])
1137 static struct admin_message msg;
1139 printf("pid=%d\n", getpid()); fflush(stdout);
1141 /* send reload command */
1142 memset(&msg, 0, sizeof(msg));
1143 msg.message = ADMIN_CALL_SETUP;
1146 SCPY(msg.u.call.interface, argv[2]);
1150 SCPY(msg.u.call.callerid, argv[3]);
1154 SCPY(msg.u.call.dialing, argv[4]);
1158 if (argv[5][0] == 'p')
1159 msg.u.call.present = 1;
1161 msg.u.call.bc_capa = 0x00; /*INFO_BC_SPEECH*/
1162 msg.u.call.bc_mode = 0x00; /*INFO_BMODE_CIRCUIT*/
1163 msg.u.call.bc_info1 = 0;
1165 msg.u.call.exthlc = 0;
1167 msg.u.call.bc_capa = strtol(argv[6],NULL,0);
1169 msg.u.call.bc_info1 = 3 | 0x80; /* alaw, if no capability is given at all */
1171 msg.u.call.bc_mode = strtol(argv[7],NULL,0);
1172 if (msg.u.call.bc_mode) msg.u.call.bc_mode = 2;
1175 msg.u.call.bc_info1 = strtol(argv[8],NULL,0);
1176 if (msg.u.call.bc_info1 < 0)
1177 msg.u.call.bc_info1 = 0;
1179 msg.u.call.bc_info1 |= 0x80;
1182 msg.u.call.hlc = strtol(argv[9],NULL,0);
1183 if (msg.u.call.hlc < 0)
1186 msg.u.call.hlc |= 0x80;
1188 // printf("hlc=%d\n", msg.u.call.hlc);
1190 msg.u.call.exthlc = strtol(argv[10],NULL,0);
1191 if (msg.u.call.exthlc < 0)
1192 msg.u.call.exthlc = 0;
1194 msg.u.call.exthlc |= 0x80;
1197 if (write(sock, &msg, sizeof(msg)) != sizeof(msg))
1198 return("Broken pipe while sending command.");
1200 /* receive response */
1202 if (read(sock, &msg, sizeof(msg)) != sizeof(msg))
1203 return("Broken pipe while receiving response.");
1206 case ADMIN_CALL_SETUP_ACK:
1207 printf("SETUP ACKNOWLEDGE\n"); fflush(stdout);
1210 case ADMIN_CALL_PROCEEDING:
1211 printf("PROCEEDING\n"); fflush(stdout);
1214 case ADMIN_CALL_ALERTING:
1215 printf("ALERTING\n"); fflush(stdout);
1218 case ADMIN_CALL_CONNECT:
1219 printf("CONNECT\n number=%s\n", msg.u.call.callerid); fflush(stdout);
1222 case ADMIN_CALL_NOTIFY:
1223 printf("NOTIFY\n notify=%d\n number=%s\n", msg.u.call.notify, msg.u.call.callerid); fflush(stdout);
1226 case ADMIN_CALL_DISCONNECT:
1227 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);
1230 case ADMIN_CALL_RELEASE:
1231 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);
1235 return("Response not valid.");
1238 printf("Command successfull.\n");
1246 char *admin_trace(int sock, int argc, char *argv[])
1248 static struct admin_message msg;
1252 if (argc > 2) if (!strcasecmp(argv[2], "help"))
1254 printf("Trace Help\n----------\n");
1255 printf("%s trace [brief|short] [<filter>=<value> [...]]\n\n", argv[0]);
1256 printf("By default a complete trace is shown in detailed format.\n");
1257 printf("To show a more compact format, use 'brief' or 'short' keyword.\n");
1258 printf("Use filter values to select specific trace messages.\n");
1259 printf("All given filter values must match. If no filter is given, anything matches.\n\n");
1260 printf("Filters:\n");
1261 printf(" category=<mask bits>\n");
1262 printf(" 0x01 = CH: channel object trace\n");
1263 printf(" 0x02 = EP: endpoint object trace\n");
1264 printf(" port=<mISDN port> select only given port for trace\n");
1265 printf(" interface=<interface name> select only given interface for trace\n");
1266 printf(" caller=<caller id> select only given caller id for trace\n");
1267 printf(" dialing=<number> select only given dialed number for trace\n");
1271 /* init trace request */
1272 memset(&msg, 0, sizeof(msg));
1273 msg.message = ADMIN_TRACE_REQUEST;
1274 msg.u.trace_req.detail = 3;
1280 if (!strcasecmp(argv[i], "brief"))
1281 msg.u.trace_req.detail = 1;
1282 else if (!strcasecmp(argv[i], "short"))
1283 msg.u.trace_req.detail = 2;
1284 else if (!strncasecmp(argv[i], "category=", 9))
1285 msg.u.trace_req.category = atoi(argv[i]+9);
1286 else if (!strncasecmp(argv[i], "port=", 5))
1287 msg.u.trace_req.port = atoi(argv[i]+5);
1288 else if (!strncasecmp(argv[i], "interface=", 10))
1289 SCPY(msg.u.trace_req.interface, argv[i]+10);
1290 else if (!strncasecmp(argv[i], "caller=", 7))
1291 SCPY(msg.u.trace_req.caller, argv[i]+7);
1292 else if (!strncasecmp(argv[i], "dialing=", 8))
1293 SCPY(msg.u.trace_req.dialing, argv[i]+8);
1294 else return("Invalid trace option, try 'trace help'.");
1299 /* send trace request */
1300 if (write(sock, &msg, sizeof(msg)) != sizeof(msg))
1301 return("Broken pipe while sending trace request.");
1303 /* receive response */
1305 if (read(sock, &msg, sizeof(msg)) != sizeof(msg))
1306 return("Broken pipe while receiving response.");
1308 if (msg.message != ADMIN_TRACE_RESPONSE)
1309 return("Response not valid.");
1311 printf("%s", msg.u.trace_rsp.text);
1319 int main(int argc, char *argv[])
1322 char *socket_name = SOCKET_NAME;
1324 struct sockaddr_un sock_address;
1333 printf("Usage: %s state | interface | route | dial ...\n", argv[0]);
1334 printf("state - View current states using graphical console output.\n");
1335 printf("interface - Tell LCR to reload \"interface.conf\".\n");
1336 printf("route - Tell LCR to reload \"route.conf\".\n");
1337 printf("dial <extension> <number> - Tell LCR the next number to dial for extension.\n");
1338 printf("release <number> - Tell LCR to release endpoint with given number.\n");
1339 printf("block <port> - Block given port.\n");
1340 printf("unblock <port> - Unblock given port.\n");
1341 printf("unload <port> - Unload port. To load port use 'block' or 'unblock'.\n");
1342 printf("testcall <interface> <callerid> <number> [present|restrict [<capability>]] - Testcall\n");
1343 printf(" -> capability = <bc> <mode> <codec> <hlc> <exthlc> (Values must be numbers, -1 to omit.)\n");
1344 printf("trace [brief|short] [<filter> [...]] - Shows call trace. Use filter to reduce output.\n");
1345 printf(" -> Use 'trace help' to see filter description.\n");
1351 if (!(strcasecmp(argv[1],"state")))
1355 if (!(strcasecmp(argv[1],"interface")))
1357 mode = MODE_INTERFACE;
1359 if (!(strcasecmp(argv[1],"route")))
1363 if (!(strcasecmp(argv[1],"dial")))
1369 if (!(strcasecmp(argv[1],"release")))
1373 mode = MODE_RELEASE;
1375 if (!(strcasecmp(argv[1],"unblock")))
1379 mode = MODE_UNBLOCK;
1381 if (!(strcasecmp(argv[1],"block")))
1387 if (!(strcasecmp(argv[1],"unload")))
1393 if (!(strcasecmp(argv[1],"testcall")))
1397 mode = MODE_TESTCALL;
1399 if (!(strcasecmp(argv[1],"trace")))
1409 if ((sock = socket(PF_UNIX, SOCK_STREAM, 0)) < 0)
1411 fprintf(stderr, "Failed to create socket.\n");
1414 memset(&sock_address, 0, sizeof(sock_address));
1415 sock_address.sun_family = PF_UNIX;
1416 UCPY(sock_address.sun_path, socket_name);
1417 if ((conn = connect(sock, (struct sockaddr *)&sock_address, SUN_LEN(&sock_address))) < 0)
1420 fprintf(stderr, "Failed to connect to socket \"%s\".\nIs LCR running?\n", sock_address.sun_path);
1428 ret = admin_state(sock);
1431 case MODE_INTERFACE:
1433 ret = admin_cmd(sock, mode, NULL, NULL);
1437 ret = admin_cmd(sock, mode, argv[2], argv[3]);
1444 ret = admin_cmd(sock, mode, NULL, argv[2]);
1448 ret = admin_testcall(sock, argc, argv);
1451 ret = admin_trace(sock, argc, argv);
1455 /* now we say good bye */
1458 // if (!strncasecmp(ret, "Broken Pipe", 11))
1460 printf("%s\n", ret);