1 /*****************************************************************************\
5 **---------------------------------------------------------------------------**
6 ** Copyright: Andreas Eversberg **
8 ** Administration tool **
10 \*****************************************************************************/
15 #include <sys/types.h>
19 #include <sys/ioctl.h>
20 #include <sys/socket.h>
29 #define LTEE {addch(ACS_LTEE);addch(ACS_HLINE);addch(ACS_HLINE);}
30 #define LLCORNER {addch(ACS_LLCORNER);addch(ACS_HLINE);addch(ACS_HLINE);}
31 #define VLINE {addch(ACS_VLINE);addstr(" ");}
32 #define EMPTY {addstr(" ");}
33 //char rotator[] = {'-', '\\', '|', '/'};
34 int lastlines, lastcols;
35 int show_interfaces = 2,
52 char *text_interfaces[] = {
59 char *text_calls[] = {
74 char logline[LOGLINES][256];
75 unsigned long logcur = 0;
82 void init_curses(void)
85 initscr(); cbreak(); noecho();
87 nodelay(stdscr, TRUE);
88 if (COLOR_PAIRS>=8 && COLORS>=8)
102 void cleanup_curses(void)
107 void color(int color)
109 if (COLOR_PAIRS>=8 && COLORS>=8)
110 attrset(COLOR_PAIR(color));
114 * permanently show current state using ncurses
116 int debug_port(struct admin_message *msg, struct admin_message *m, int line, int i, int vline)
123 SPRINT(buffer,"%s(%d)", m[i].u.p.name,m[i].u.p.serial);
127 switch (m[i].u.p.state)
129 case ADMIN_STATE_IDLE:
133 case ADMIN_STATE_IN_SETUP:
135 addstr("'in << setup'");
137 case ADMIN_STATE_OUT_SETUP:
139 addstr("'out >> setup'");
141 case ADMIN_STATE_IN_OVERLAP:
143 addstr("'in << overlap'");
145 case ADMIN_STATE_OUT_OVERLAP:
147 addstr("'out >> overlap'");
149 case ADMIN_STATE_IN_PROCEEDING:
151 addstr("'in << proc'");
153 case ADMIN_STATE_OUT_PROCEEDING:
155 addstr("'out >> proc'");
157 case ADMIN_STATE_IN_ALERTING:
159 addstr("'in << alert'");
161 case ADMIN_STATE_OUT_ALERTING:
163 addstr("'out >> alert'");
165 case ADMIN_STATE_CONNECT:
169 case ADMIN_STATE_IN_DISCONNECT:
171 addstr("'in << disc'");
173 case ADMIN_STATE_OUT_DISCONNECT:
175 addstr("'out >> disc'");
179 addstr("'--NONE--'");
185 addstr(" bchannel=");
187 SPRINT(buffer,"%d", m[i].u.p.isdn_chan);
189 if (m[i].u.p.isdn_ces >= 0)
194 SPRINT(buffer, "%d", m[i].u.p.isdn_ces);
197 if (m[i].u.p.isdn_hold)
206 int debug_epoint(struct admin_message *msg, struct admin_message *m, int line, int i, int vline)
208 unsigned long epoint = m[i].u.e.serial;
215 SPRINT(buffer,"EPOINT(%d)", epoint);
219 switch (m[i].u.e.state)
221 case ADMIN_STATE_IDLE:
225 case ADMIN_STATE_IN_SETUP:
227 addstr("'in << setup'");
229 case ADMIN_STATE_OUT_SETUP:
231 addstr("'out >> setup'");
233 case ADMIN_STATE_IN_OVERLAP:
235 addstr("'in << overlap'");
237 case ADMIN_STATE_OUT_OVERLAP:
239 addstr("'out >> overlap'");
241 case ADMIN_STATE_IN_PROCEEDING:
243 addstr("'in << proc'");
245 case ADMIN_STATE_OUT_PROCEEDING:
247 addstr("'out >> proc'");
249 case ADMIN_STATE_IN_ALERTING:
251 addstr("'in << alert'");
253 case ADMIN_STATE_OUT_ALERTING:
255 addstr("'out >> alert'");
257 case ADMIN_STATE_CONNECT:
261 case ADMIN_STATE_IN_DISCONNECT:
263 addstr("'in << disc'");
265 case ADMIN_STATE_OUT_DISCONNECT:
267 addstr("'out >> disc'");
271 addstr("'--NONE--'");
273 if (m[i].u.e.terminal[0])
276 addstr(" terminal=");
278 addstr(m[i].u.e.terminal);
281 SPRINT(buffer, " %s", m[i].u.e.callerid);
286 addstr(m[i].u.e.dialing);
287 if (m[i].u.e.action[0])
292 addstr(m[i].u.e.action);
297 addstr(" park="); /* 9 digits */
299 UCPY(buffer, "\""); /* 9 digits */
301 jj = m[i].u.e.park_len;
304 c = m[i].u.e.park_callid[j];
305 if (c >= 32 && c < 127 && c != '[')
309 UPRINT(buffer+strlen(buffer), "[%02x]", c);
317 switch(m[i].u.e.rx_state)
319 case NOTIFY_STATE_SUSPEND:
320 addstr(" in=suspend");
322 case NOTIFY_STATE_HOLD:
325 case NOTIFY_STATE_CONFERENCE:
326 addstr(" in=conference");
329 switch(m[i].u.e.tx_state)
331 case NOTIFY_STATE_SUSPEND:
332 addstr(" out=suspend");
334 case NOTIFY_STATE_HOLD:
337 case NOTIFY_STATE_CONFERENCE:
338 addstr(" out=conference");
346 if (m[i].u.e.crypt) /* crypt on */
356 /* loop all related ports */
358 j = msg->u.s.interfaces+msg->u.s.calls+msg->u.s.epoints;
359 jj = j + msg->u.s.ports;
362 if (m[j].u.p.epoint == epoint)
365 move(++line>1?line:1, 1);
370 move(line>1?line:1, 5);
373 move(line>1?line:1, 8);
374 if (line+2 >= LINES) break;
375 line = debug_port(msg, m, line, j, vline);
376 if (line+2 >= LINES) break;
383 move(ltee>1?line:1, 5);
389 int debug_call(struct admin_message *msg, struct admin_message *m, int line, int i)
391 unsigned long call = m[i].u.c.serial;
396 SPRINT(buffer,"CALL(%d)", call);
398 if (m[i].u.c.partyline)
401 addstr(" partyline=");
403 SPRINT(buffer, "%d\n", m[i].u.c.partyline);
406 /* find number of epoints */
407 j = msg->u.s.interfaces+msg->u.s.calls;
408 jj = j + msg->u.s.epoints;
412 if (m[j].u.e.call == call)
416 /* loop all related endpoints */
417 j = msg->u.s.interfaces+msg->u.s.calls;
418 jj = j + msg->u.s.epoints;
421 if (m[j].u.e.call == call)
424 move(++line>1?line:1, 1);
430 move(line>1?line:1, 4);
431 if (line+2 >= LINES) break;
432 line = debug_epoint(msg, m, line, j, i?1:0);
433 if (line+2 >= LINES) break;
440 char *admin_state(int sock)
442 struct admin_message msg,
446 int line, offset = 0;
455 /* flush logfile name */
462 /* send reload command */
463 memset(&msg, 0, sizeof(msg));
464 msg.message = ADMIN_REQUEST_STATE;
465 // printf("sizeof=%d\n",sizeof(msg));fflush(stdout);
466 if (write(sock, &msg, sizeof(msg)) != sizeof(msg))
469 return("Broken pipe while sending command.");
472 /* receive response */
473 if (read(sock, &msg, sizeof(msg)) != sizeof(msg))
476 return("Broken pipe while receiving response.");
479 if (msg.message != ADMIN_RESPONSE_STATE)
482 return("Response not valid. Expecting state response.");
484 num = msg.u.s.interfaces + msg.u.s.calls + msg.u.s.epoints + msg.u.s.ports;
485 if (!(m = (struct admin_message *)malloc(num*sizeof(struct admin_message))))
488 return("Not enough memory for messages.");
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.calls)
527 if (m[j].message != ADMIN_RESPONSE_S_CALL)
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.calls+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.calls;
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.calls;
817 /* for each call... */
818 move(++line>1?line:1, 0);
820 SPRINT(buffer, "(%d):", m[j].u.c.serial);
822 i = msg.u.s.interfaces+msg.u.s.calls;
823 ii = i+msg.u.s.epoints;
826 /* for each endpoint... */
827 if (m[i].u.e.call == m[j].u.c.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.calls+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.calls;
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.calls;
908 move(++line>1?line:1, 0);
909 if (line+2 >= LINES) goto end;
910 line = debug_call(&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 SCPY(buffer, logline[l % LOGLINES]);
939 if (COLS < (int)sizeof(buffer))
950 /* display name/time */
955 msg.u.s.version_string[sizeof(msg.u.s.version_string)-1] = '\0';
956 SPRINT(buffer, "LCR %s", msg.u.s.version_string);
961 SPRINT(buffer, "%04d-%02d-%02d %02d:%02d:%02d",
962 msg.u.s.tm.tm_year+1900, msg.u.s.tm.tm_mon+1, msg.u.s.tm.tm_mday,
963 msg.u.s.tm.tm_hour, msg.u.s.tm.tm_min, msg.u.s.tm.tm_sec);
966 /* displeay head line */
969 hline(ACS_HLINE, COLS);
973 SPRINT(buffer, "Offset +%d", offset);
980 hline(ACS_HLINE, COLS);
983 SPRINT(buffer, "i = interfaces '%s' c = calls '%s' l = log q = quit +/- = scroll", text_interfaces[show_interfaces], text_calls[show_calls]);
988 if (lastlines!=LINES || lastcols!=COLS)
998 case 12: /* refresh */
1009 case 'i': /* toggle interface */
1011 if (show_interfaces > 3) show_interfaces = 0;
1014 case 'c': /* toggle calls */
1016 if (show_calls > 2) show_calls = 0;
1019 case 'l': /* toggle log */
1021 if (show_log > 1) show_log = 0;
1024 case '+': /* scroll down */
1028 case '-': /* scroll up */
1038 /* check for logfh */
1043 /* cleanup curses and exit */
1051 * Send command and show error message.
1053 char *admin_cmd(int sock, int mode, char *extension, char *number)
1055 static struct admin_message msg;
1057 /* send reload command */
1058 memset(&msg, 0, sizeof(msg));
1061 case MODE_INTERFACE:
1062 msg.message = ADMIN_REQUEST_CMD_INTERFACE;
1065 msg.message = ADMIN_REQUEST_CMD_ROUTE;
1068 msg.message = ADMIN_REQUEST_CMD_DIAL;
1069 SPRINT(msg.u.x.message, "%s:%s", extension?:"", number?:"");
1072 msg.message = ADMIN_REQUEST_CMD_RELEASE;
1073 SCPY(msg.u.x.message, number);
1076 msg.message = ADMIN_REQUEST_CMD_BLOCK;
1077 msg.u.x.portnum = atoi(number);
1081 msg.message = ADMIN_REQUEST_CMD_BLOCK;
1082 msg.u.x.portnum = atoi(number);
1086 msg.message = ADMIN_REQUEST_CMD_BLOCK;
1087 msg.u.x.portnum = atoi(number);
1092 if (write(sock, &msg, sizeof(msg)) != sizeof(msg))
1093 return("Broken pipe while sending command.");
1095 /* receive response */
1096 if (read(sock, &msg, sizeof(msg)) != sizeof(msg))
1097 return("Broken pipe while receiving response.");
1100 case MODE_INTERFACE:
1101 if (msg.message != ADMIN_RESPONSE_CMD_INTERFACE)
1102 return("Response not valid.");
1105 if (msg.message != ADMIN_RESPONSE_CMD_ROUTE)
1106 return("Response not valid.");
1109 if (msg.message != ADMIN_RESPONSE_CMD_DIAL)
1110 return("Response not valid.");
1113 if (msg.message != ADMIN_RESPONSE_CMD_RELEASE)
1114 return("Response not valid.");
1119 if (msg.message != ADMIN_RESPONSE_CMD_BLOCK)
1120 return("Response not valid.");
1124 /* process response */
1127 return(msg.u.x.message);
1129 printf("Command successfull.\n");
1137 char *admin_testcall(int sock, int argc, char *argv[])
1139 static struct admin_message msg;
1141 printf("pid=%d\n", getpid()); fflush(stdout);
1143 /* send reload command */
1144 memset(&msg, 0, sizeof(msg));
1145 msg.message = ADMIN_CALL_SETUP;
1148 SCPY(msg.u.call.interface, argv[2]);
1152 SCPY(msg.u.call.callerid, argv[3]);
1156 SCPY(msg.u.call.dialing, argv[4]);
1160 if (argv[5][0] == 'p')
1161 msg.u.call.present = 1;
1163 msg.u.call.bc_capa = 0x00; /*INFO_BC_SPEECH*/
1164 msg.u.call.bc_mode = 0x00; /*INFO_BMODE_CIRCUIT*/
1165 msg.u.call.bc_info1 = 0;
1167 msg.u.call.exthlc = 0;
1169 msg.u.call.bc_capa = strtol(argv[6],NULL,0);
1171 msg.u.call.bc_info1 = 3 | 0x80; /* alaw, if no capability is given at all */
1173 msg.u.call.bc_mode = strtol(argv[7],NULL,0);
1174 if (msg.u.call.bc_mode) msg.u.call.bc_mode = 2;
1177 msg.u.call.bc_info1 = strtol(argv[8],NULL,0);
1178 if (msg.u.call.bc_info1 < 0)
1179 msg.u.call.bc_info1 = 0;
1181 msg.u.call.bc_info1 |= 0x80;
1184 msg.u.call.hlc = strtol(argv[9],NULL,0);
1185 if (msg.u.call.hlc < 0)
1188 msg.u.call.hlc |= 0x80;
1190 // printf("hlc=%d\n", msg.u.call.hlc);
1192 msg.u.call.exthlc = strtol(argv[10],NULL,0);
1193 if (msg.u.call.exthlc < 0)
1194 msg.u.call.exthlc = 0;
1196 msg.u.call.exthlc |= 0x80;
1199 if (write(sock, &msg, sizeof(msg)) != sizeof(msg))
1200 return("Broken pipe while sending command.");
1202 /* receive response */
1204 if (read(sock, &msg, sizeof(msg)) != sizeof(msg))
1205 return("Broken pipe while receiving response.");
1208 case ADMIN_CALL_SETUP_ACK:
1209 printf("SETUP ACKNOWLEDGE\n"); fflush(stdout);
1212 case ADMIN_CALL_PROCEEDING:
1213 printf("PROCEEDING\n"); fflush(stdout);
1216 case ADMIN_CALL_ALERTING:
1217 printf("ALERTING\n"); fflush(stdout);
1220 case ADMIN_CALL_CONNECT:
1221 printf("CONNECT\n number=%s\n", msg.u.call.callerid); fflush(stdout);
1224 case ADMIN_CALL_NOTIFY:
1225 printf("NOTIFY\n notify=%d\n number=%s\n", msg.u.call.notify, msg.u.call.callerid); fflush(stdout);
1228 case ADMIN_CALL_DISCONNECT:
1229 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);
1232 case ADMIN_CALL_RELEASE:
1233 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);
1237 return("Response not valid.");
1240 printf("Command successfull.\n");
1248 char *admin_trace(int sock, int argc, char *argv[])
1250 static struct admin_message msg;
1254 if (argc > 2) if (!strcasecmp(argv[2], "help"))
1256 printf("Trace Help\n----------\n");
1257 printf("%s trace [brief|short] [<filter>=<value> [...]]\n\n", argv[0]);
1258 printf("By default a complete trace is shown in detailed format.\n");
1259 printf("To show a more compact format, use 'brief' or 'short' keyword.\n");
1260 printf("Use filter values to select specific trace messages.\n");
1261 printf("All given filter values must match. If no filter is given, anything matches.\n\n");
1262 printf("Filters:\n");
1263 printf(" category=<mask bits>\n");
1264 printf(" 0x01 = CH: channel object trace\n");
1265 printf(" 0x02 = EP: endpoint object trace\n");
1266 printf(" port=<mISDN port> select only given port for trace\n");
1267 printf(" interface=<interface name> select only given interface for trace\n");
1268 printf(" caller=<caller id> select only given caller id for trace\n");
1269 printf(" dialing=<number> select only given dialed number for trace\n");
1273 /* init trace request */
1274 memset(&msg, 0, sizeof(msg));
1275 msg.message = ADMIN_TRACE_REQUEST;
1276 msg.u.trace_req.detail = 3;
1282 if (!strcasecmp(argv[i], "brief"))
1283 msg.u.trace_req.detail = 1;
1284 else if (!strcasecmp(argv[i], "short"))
1285 msg.u.trace_req.detail = 2;
1286 else if (!strncasecmp(argv[i], "category=", 9))
1287 msg.u.trace_req.category = atoi(argv[i]+9);
1288 else if (!strncasecmp(argv[i], "port=", 5))
1289 msg.u.trace_req.port = atoi(argv[i]+5);
1290 else if (!strncasecmp(argv[i], "interface=", 10))
1291 SCPY(msg.u.trace_req.interface, argv[i]+10);
1292 else if (!strncasecmp(argv[i], "caller=", 7))
1293 SCPY(msg.u.trace_req.caller, argv[i]+7);
1294 else if (!strncasecmp(argv[i], "dialing=", 8))
1295 SCPY(msg.u.trace_req.dialing, argv[i]+8);
1296 else return("Invalid trace option, try 'trace help'.");
1301 /* send trace request */
1302 if (write(sock, &msg, sizeof(msg)) != sizeof(msg))
1303 return("Broken pipe while sending trace request.");
1305 /* receive response */
1307 if (read(sock, &msg, sizeof(msg)) != sizeof(msg))
1308 return("Broken pipe while receiving response.");
1310 if (msg.message != ADMIN_TRACE_RESPONSE)
1311 return("Response not valid.");
1313 printf("%s", msg.u.trace_rsp.text);
1321 int main(int argc, char *argv[])
1324 char *socket_name = SOCKET_NAME;
1326 struct sockaddr_un sock_address;
1335 printf("Usage: %s state | interface | route | dial ...\n", argv[0]);
1336 printf("state - View current states using graphical console output.\n");
1337 printf("interface - Tell LCR to reload \"interface.conf\".\n");
1338 printf("route - Tell LCR to reload \"route.conf\".\n");
1339 printf("dial <extension> <number> - Tell LCR the next number to dial for extension.\n");
1340 printf("release <number> - Tell LCR to release endpoint with given number.\n");
1341 printf("block <port> - Block given port.\n");
1342 printf("unblock <port> - Unblock given port.\n");
1343 printf("unload <port> - Unload port. To load port use 'block' or 'unblock'.\n");
1344 printf("testcall <interface> <callerid> <number> [present|restrict [<capability>]] - Testcall\n");
1345 printf(" -> capability = <bc> <mode> <codec> <hlc> <exthlc> (Values must be numbers, -1 to omit.)\n");
1346 printf("trace [brief|short] [<filter> [...]] - Shows call trace. Use filter to reduce output.\n");
1347 printf(" -> Use 'trace help' to see filter description.\n");
1353 if (!(strcasecmp(argv[1],"state")))
1357 if (!(strcasecmp(argv[1],"interface")))
1359 mode = MODE_INTERFACE;
1361 if (!(strcasecmp(argv[1],"route")))
1365 if (!(strcasecmp(argv[1],"dial")))
1371 if (!(strcasecmp(argv[1],"release")))
1375 mode = MODE_RELEASE;
1377 if (!(strcasecmp(argv[1],"unblock")))
1381 mode = MODE_UNBLOCK;
1383 if (!(strcasecmp(argv[1],"block")))
1389 if (!(strcasecmp(argv[1],"unload")))
1395 if (!(strcasecmp(argv[1],"testcall")))
1399 mode = MODE_TESTCALL;
1401 if (!(strcasecmp(argv[1],"trace")))
1411 if ((sock = socket(PF_UNIX, SOCK_STREAM, 0)) < 0)
1413 fprintf(stderr, "Failed to create socket.\n");
1416 memset(&sock_address, 0, sizeof(sock_address));
1417 sock_address.sun_family = PF_UNIX;
1418 UCPY(sock_address.sun_path, socket_name);
1419 if ((conn = connect(sock, (struct sockaddr *)&sock_address, SUN_LEN(&sock_address))) < 0)
1422 fprintf(stderr, "Failed to connect to socket \"%s\".\nIs LCR running?\n", sock_address.sun_path);
1430 ret = admin_state(sock);
1433 case MODE_INTERFACE:
1435 ret = admin_cmd(sock, mode, NULL, NULL);
1439 ret = admin_cmd(sock, mode, argv[2], argv[3]);
1446 ret = admin_cmd(sock, mode, NULL, argv[2]);
1450 ret = admin_testcall(sock, argc, argv);
1453 ret = admin_trace(sock, argc, argv);
1457 /* now we say good bye */
1460 // if (!strncasecmp(ret, "Broken Pipe", 11))
1462 printf("%s\n", ret);