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,
49 char *text_interfaces[] = {
56 char *text_calls[] = {
71 char logline[LOGLINES][256];
72 unsigned long logcur = 0;
79 void init_curses(void)
82 initscr(); cbreak(); noecho();
84 nodelay(stdscr, TRUE);
85 if (COLOR_PAIRS>=8 && COLORS>=8)
99 void cleanup_curses(void)
104 void color(int color)
106 if (COLOR_PAIRS>=8 && COLORS>=8)
107 attrset(COLOR_PAIR(color));
111 * permanently show current state using ncurses
113 int debug_port(struct admin_message *msg, struct admin_message *m, int line, int i, int vline)
120 SPRINT(buffer,"%s(%d)", m[i].u.p.name,m[i].u.p.serial);
124 switch (m[i].u.p.state)
126 case ADMIN_STATE_IDLE:
130 case ADMIN_STATE_IN_SETUP:
132 addstr("'in << setup'");
134 case ADMIN_STATE_OUT_SETUP:
136 addstr("'out >> setup'");
138 case ADMIN_STATE_IN_OVERLAP:
140 addstr("'in << overlap'");
142 case ADMIN_STATE_OUT_OVERLAP:
144 addstr("'out >> overlap'");
146 case ADMIN_STATE_IN_PROCEEDING:
148 addstr("'in << proc'");
150 case ADMIN_STATE_OUT_PROCEEDING:
152 addstr("'out >> proc'");
154 case ADMIN_STATE_IN_ALERTING:
156 addstr("'in << alert'");
158 case ADMIN_STATE_OUT_ALERTING:
160 addstr("'out >> alert'");
162 case ADMIN_STATE_CONNECT:
166 case ADMIN_STATE_IN_DISCONNECT:
168 addstr("'in << disc'");
170 case ADMIN_STATE_OUT_DISCONNECT:
172 addstr("'out >> disc'");
176 addstr("'--NONE--'");
182 addstr(" bchannel=");
184 SPRINT(buffer,"%d", m[i].u.p.isdn_chan);
186 if (m[i].u.p.isdn_ces >= 0)
191 SPRINT(buffer, "%d", m[i].u.p.isdn_ces);
194 if (m[i].u.p.isdn_hold)
203 int debug_epoint(struct admin_message *msg, struct admin_message *m, int line, int i, int vline)
205 unsigned long epoint = m[i].u.e.serial;
212 SPRINT(buffer,"EPOINT(%d)", epoint);
216 switch (m[i].u.e.state)
218 case ADMIN_STATE_IDLE:
222 case ADMIN_STATE_IN_SETUP:
224 addstr("'in << setup'");
226 case ADMIN_STATE_OUT_SETUP:
228 addstr("'out >> setup'");
230 case ADMIN_STATE_IN_OVERLAP:
232 addstr("'in << overlap'");
234 case ADMIN_STATE_OUT_OVERLAP:
236 addstr("'out >> overlap'");
238 case ADMIN_STATE_IN_PROCEEDING:
240 addstr("'in << proc'");
242 case ADMIN_STATE_OUT_PROCEEDING:
244 addstr("'out >> proc'");
246 case ADMIN_STATE_IN_ALERTING:
248 addstr("'in << alert'");
250 case ADMIN_STATE_OUT_ALERTING:
252 addstr("'out >> alert'");
254 case ADMIN_STATE_CONNECT:
258 case ADMIN_STATE_IN_DISCONNECT:
260 addstr("'in << disc'");
262 case ADMIN_STATE_OUT_DISCONNECT:
264 addstr("'out >> disc'");
268 addstr("'--NONE--'");
270 if (m[i].u.e.terminal[0])
273 addstr(" terminal=");
275 addstr(m[i].u.e.terminal);
278 SPRINT(buffer, " %s", m[i].u.e.callerid);
283 addstr(m[i].u.e.dialing);
284 if (m[i].u.e.action[0])
289 addstr(m[i].u.e.action);
294 addstr(" park="); /* 9 digits */
296 UCPY(buffer, "\""); /* 9 digits */
298 jj = m[i].u.e.park_len;
301 c = m[i].u.e.park_callid[j];
302 if (c >= 32 && c < 127 && c != '[')
306 UPRINT(buffer+strlen(buffer), "[%02x]", c);
314 switch(m[i].u.e.rx_state)
316 case NOTIFY_STATE_SUSPEND:
317 addstr(" in=suspend");
319 case NOTIFY_STATE_HOLD:
322 case NOTIFY_STATE_CONFERENCE:
323 addstr(" in=conference");
326 switch(m[i].u.e.tx_state)
328 case NOTIFY_STATE_SUSPEND:
329 addstr(" out=suspend");
331 case NOTIFY_STATE_HOLD:
334 case NOTIFY_STATE_CONFERENCE:
335 addstr(" out=conference");
343 if (m[i].u.e.crypt) /* crypt on */
353 /* loop all related ports */
355 j = msg->u.s.interfaces+msg->u.s.calls+msg->u.s.epoints;
356 jj = j + msg->u.s.ports;
359 if (m[j].u.p.epoint == epoint)
362 move(++line>1?line:1, 1);
367 move(line>1?line:1, 5);
370 move(line>1?line:1, 8);
371 if (line+2 >= LINES) break;
372 line = debug_port(msg, m, line, j, vline);
373 if (line+2 >= LINES) break;
380 move(ltee>1?line:1, 5);
386 int debug_call(struct admin_message *msg, struct admin_message *m, int line, int i)
388 unsigned long call = m[i].u.c.serial;
393 SPRINT(buffer,"CALL(%d)", call);
395 if (m[i].u.c.partyline)
398 addstr(" partyline=");
400 SPRINT(buffer, "%d\n", m[i].u.c.partyline);
403 /* find number of epoints */
404 j = msg->u.s.interfaces+msg->u.s.calls;
405 jj = j + msg->u.s.epoints;
409 if (m[j].u.e.call == call)
413 /* loop all related endpoints */
414 j = msg->u.s.interfaces+msg->u.s.calls;
415 jj = j + msg->u.s.epoints;
418 if (m[j].u.e.call == call)
421 move(++line>1?line:1, 1);
427 move(line>1?line:1, 4);
428 if (line+2 >= LINES) break;
429 line = debug_epoint(msg, m, line, j, i?1:0);
430 if (line+2 >= LINES) break;
437 char *admin_state(int sock)
439 struct admin_message msg,
443 int line, offset = 0;
452 /* flush logfile name */
459 /* send reload command */
460 memset(&msg, 0, sizeof(msg));
461 msg.message = ADMIN_REQUEST_STATE;
462 // printf("sizeof=%d\n",sizeof(msg));
463 if (write(sock, &msg, sizeof(msg)) != sizeof(msg))
466 return("Broken pipe while sending command.");
469 /* receive response */
470 if (read(sock, &msg, sizeof(msg)) != sizeof(msg))
473 return("Broken pipe while receiving response.");
475 if (msg.message != ADMIN_RESPONSE_STATE)
478 return("Response not valid. Expecting state response.");
480 num = msg.u.s.interfaces + msg.u.s.calls + msg.u.s.epoints + msg.u.s.ports;
481 if (!(m = (struct admin_message *)malloc(num*sizeof(struct admin_message))))
484 return("Not enough memory for messages.");
488 if ((len = read(sock, ((unsigned char *)(m))+off,
489 num*sizeof(struct admin_message)-off)) != num*sizeof(struct admin_message)-off)
493 // fprintf(stderr, "got=%d expected=%d\n", i, num*sizeof(struct admin_message));
495 return("Broken pipe while receiving state infos.");
497 if (len < num*sizeof(struct admin_message))
505 // fprintf("getting =%d interfaces\n", msg.u.s.interfaces);
506 while(i < msg.u.s.interfaces)
508 // fprintf(stderr, "j=%d message=%d\n", j, m[j].message);
509 if (m[j].message != ADMIN_RESPONSE_S_INTERFACE)
513 return("Response not valid. Expecting interface information.");
519 while(i < msg.u.s.calls)
521 if (m[j].message != ADMIN_RESPONSE_S_CALL)
525 return("Response not valid. Expecting call information.");
531 while(i < msg.u.s.epoints)
533 if (m[j].message != ADMIN_RESPONSE_S_EPOINT)
537 return("Response not valid. Expecting endpoint information.");
543 while(i < msg.u.s.ports)
545 if (m[j].message != ADMIN_RESPONSE_S_PORT)
549 return("Response not valid. Expecting port information.");
554 // now j is the number of message blocks
562 if (!!strcmp(logfile, msg.u.s.logfile))
564 SCPY(logfile, msg.u.s.logfile);
572 logline[i][1] = '\0';
576 logfh = open(logfile, O_RDONLY|O_NONBLOCK);
579 /* seek at the end -8000 chars */
580 lseek(logfh, -8000, SEEK_END);
581 /* if not at the beginning, read until endofline */
582 logline[logcur % LOGLINES][0] = '\0';
583 l = read(logfh, logline[logcur % LOGLINES], sizeof(logline[logcur % LOGLINES])-1);
586 /* read first line and skip junk */
587 logline[logcur % LOGLINES][l] = '\0';
588 if ((p = strchr(logline[logcur % LOGLINES],'\n')))
591 SCPY(logline[logcur % LOGLINES], p+1);
592 SCPY(logline[(logcur-1) % LOGLINES], "...");
604 ll = strlen(logline[logcur % LOGLINES]);
605 l = read(logfh, logline[logcur % LOGLINES]+ll, sizeof(logline[logcur % LOGLINES])-ll-1);
608 logline[logcur % LOGLINES][ll+l] = '\0';
610 /* put data to lines */
611 while ((p = strchr(logline[logcur % LOGLINES],'\n')))
615 SCPY(logline[logcur % LOGLINES], p+1);
617 /* if line is full without return, go next line */
618 if (strlen(logline[logcur % LOGLINES]) == sizeof(logline[logcur % LOGLINES])-1)
621 logline[logcur % LOGLINES][0] = '\0';
626 /* display interfaces */
627 if (show_interfaces > 0)
631 ii = i + msg.u.s.interfaces;
634 /* show interface summary */
635 move(++line>1?line:1, 0);
638 SPRINT(buffer, "%s(%d) '%s' %s use:%d ", (m[i].u.i.ntmode)?"NT":"TE", m[i].u.i.portnum, m[i].u.i.interface_name, (m[i].u.i.ptp)?"ptp ":"ptmp", m[i].u.i.use);
640 if (m[i].u.i.ptp || !m[i].u.i.ntmode)
642 color((m[i].u.i.l2link)?green:red);
643 addstr((m[i].u.i.l2link)?" L2 UP":" L2 down");
645 color((m[i].u.i.l1link)?green:blue);
646 addstr((m[i].u.i.l1link)?" L1 ACTIVE":" L1 inactive");
647 if (line+2 >= LINES) goto end;
649 if (show_interfaces > 1)
653 jj = m[i].u.i.channels;
656 /* show all channels */
657 if (show_interfaces>2 || m[i].u.i.busy[j]>0)
660 /* show left side / right side */
661 if ((k & 1) && (COLS > 70))
663 move(line>1?line:1,4+((COLS-4)/2));
666 move(++line>1?line:1, 1);
673 SPRINT(buffer,"S%2d: ", j+1+(j>=15));
675 SPRINT(buffer,"B%2d: ", j+1);
682 color((m[i].u.i.busy[j])?yellow:blue);
683 addstr((m[i].u.i.busy[j])?"busy":"idle");
689 if (m[i].u.i.port[j])
691 /* search for port */
692 l = msg.u.s.interfaces+msg.u.s.calls+msg.u.s.epoints;
693 ll = l+msg.u.s.ports;
696 if (m[l].u.p.serial == m[i].u.i.port[j])
698 SPRINT(buffer, " %s(%ld)", m[l].u.p.name, m[l].u.p.serial);
709 move(line>1?line:1, 1);
720 move(line>1?line:1, 1);
723 if (line+2 >= LINES) goto end;
724 /* show summary if no channels were shown */
725 if (show_interfaces<2 && ltee==0)
728 move(++line>1?line:1, 1);
734 SPRINT(buffer,"all %d channels free", m[i].u.i.channels);
738 SPRINT(buffer,"all %d channels blocked", m[i].u.i.channels);
742 if (line+2 >= LINES) goto end;
749 if (line+2 >= LINES) goto end;
751 /* display calls (brief) */
755 i = msg.u.s.interfaces+msg.u.s.calls;
756 ii = i+msg.u.s.epoints;
759 /* for each endpoint... */
762 move(++line>1?line:1, 0);
764 SPRINT(buffer, "(%d): ", m[i].u.e.serial);
767 if (m[i].u.e.terminal[0])
771 addstr(m[i].u.e.terminal);
775 SPRINT(buffer, " %s", m[i].u.e.callerid);
780 SPRINT(buffer, "%s", m[i].u.e.dialing);
782 if (m[i].u.e.action[0])
787 addstr(m[i].u.e.action);
789 if (line+2 >= LINES) goto end;
794 j = msg.u.s.interfaces;
795 jj = j+msg.u.s.calls;
798 /* for each call... */
799 move(++line>1?line:1, 0);
801 SPRINT(buffer, "(%d):", m[j].u.c.serial);
803 i = msg.u.s.interfaces+msg.u.s.calls;
804 ii = i+msg.u.s.epoints;
807 /* for each endpoint... */
808 if (m[i].u.e.call == m[j].u.c.serial)
811 SPRINT(buffer, " (%d)", m[i].u.e.serial);
814 if (m[i].u.e.terminal[0])
818 addstr(m[i].u.e.terminal);
822 SPRINT(buffer, "-%s", m[i].u.e.callerid);
827 SPRINT(buffer, "%s", m[i].u.e.dialing);
833 if (line+2 >= LINES) goto end;
838 if (line+2 >= LINES) goto end;
840 /* display calls (structurd) */
843 /* show all ports with no epoint */
845 i = msg.u.s.interfaces+msg.u.s.calls+msg.u.s.epoints;
846 ii = i+msg.u.s.ports;
849 if (!m[i].u.p.epoint)
851 move(++line>1?line:1, 8);
852 if (line+2 >= LINES) goto end;
853 line = debug_port(&msg, m, line, i, 0);
854 if (line+2 >= LINES) goto end;
861 if (line+2 >= LINES) goto end;
863 /* show all epoints with no call */
865 i = msg.u.s.interfaces+msg.u.s.calls;
866 ii = i+msg.u.s.epoints;
871 move(++line>1?line:1, 4);
872 if (line+2 >= LINES) goto end;
873 line = debug_epoint(&msg, m, line, i, 0);
874 if (line+2 >= LINES) goto end;
881 if (line+2 >= LINES) goto end;
885 i = msg.u.s.interfaces;
886 ii = i+msg.u.s.calls;
889 move(++line>1?line:1, 0);
890 if (line+2 >= LINES) goto end;
891 line = debug_call(&msg, m, line, i);
892 if (line+2 >= LINES) goto end;
898 if (line+2 >= LINES) goto end;
907 move(line++>1?line-1:1, 0);
909 hline(ACS_HLINE, COLS);
912 l = logcur-(LINES-line-2);
914 if (ll-l >= LOGLINES)
918 move(line++>1?line-1:1, 0);
919 SCPY(buffer, logline[l % LOGLINES]);
920 if (COLS < (int)sizeof(buffer))
931 /* display name/time */
936 msg.u.s.version_string[sizeof(msg.u.s.version_string)-1] = '\0';
937 SPRINT(buffer, "PBX4Linux %s", msg.u.s.version_string);
942 SPRINT(buffer, "%04d-%02d-%02d %02d:%02d:%02d",
943 msg.u.s.tm.tm_year+1900, msg.u.s.tm.tm_mon+1, msg.u.s.tm.tm_mday,
944 msg.u.s.tm.tm_hour, msg.u.s.tm.tm_min, msg.u.s.tm.tm_sec);
947 /* displeay head line */
950 hline(ACS_HLINE, COLS);
954 SPRINT(buffer, "Offset +%d", offset);
961 hline(ACS_HLINE, COLS);
964 SPRINT(buffer, "i = interfaces '%s' c = calls '%s' l = log q = quit +/- = scroll", text_interfaces[show_interfaces], text_calls[show_calls]);
969 if (lastlines!=LINES || lastcols!=COLS)
979 case 12: /* refresh */
990 case 'i': /* toggle interface */
992 if (show_interfaces > 3) show_interfaces = 0;
995 case 'c': /* toggle calls */
997 if (show_calls > 2) show_calls = 0;
1000 case 'l': /* toggle log */
1002 if (show_log > 1) show_log = 0;
1005 case '+': /* scroll down */
1009 case '-': /* scroll up */
1019 /* check for logfh */
1024 /* cleanup curses and exit */
1032 * Send command and show error message.
1034 char *admin_cmd(int sock, int mode, char *extension, char *number)
1036 static struct admin_message msg;
1038 /* send reload command */
1039 memset(&msg, 0, sizeof(msg));
1042 case MODE_INTERFACE:
1043 msg.message = ADMIN_REQUEST_CMD_INTERFACE;
1046 msg.message = ADMIN_REQUEST_CMD_ROUTE;
1049 msg.message = ADMIN_REQUEST_CMD_DIAL;
1050 SPRINT(msg.u.x.message, "%s:%s", extension?:"", number?:"");
1053 msg.message = ADMIN_REQUEST_CMD_RELEASE;
1054 SCPY(msg.u.x.message, number);
1058 if (write(sock, &msg, sizeof(msg)) != sizeof(msg))
1059 return("Broken pipe while sending command.");
1061 /* receive response */
1062 if (read(sock, &msg, sizeof(msg)) != sizeof(msg))
1063 return("Broken pipe while receiving response.");
1066 case MODE_INTERFACE:
1067 if (msg.message != ADMIN_RESPONSE_CMD_INTERFACE)
1068 return("Response not valid.");
1071 if (msg.message != ADMIN_RESPONSE_CMD_ROUTE)
1072 return("Response not valid.");
1075 if (msg.message != ADMIN_RESPONSE_CMD_DIAL)
1076 return("Response not valid.");
1079 if (msg.message != ADMIN_RESPONSE_CMD_RELEASE)
1080 return("Response not valid.");
1084 /* process response */
1087 return(msg.u.x.message);
1089 printf("Command successfull.\n");
1097 char *admin_testcall(int sock, int argc, char *argv[])
1099 static struct admin_message msg;
1101 printf("pid=%d\n", getpid()); fflush(stdout);
1103 /* send reload command */
1104 memset(&msg, 0, sizeof(msg));
1105 msg.message = ADMIN_CALL_SETUP;
1108 SCPY(msg.u.call.interface, argv[2]);
1112 SCPY(msg.u.call.callerid, argv[3]);
1116 SCPY(msg.u.call.dialing, argv[4]);
1120 if (argv[5][0] == 'p')
1121 msg.u.call.present = 1;
1123 msg.u.call.bc_capa = 0x00; /*INFO_BC_SPEECH*/
1124 msg.u.call.bc_mode = 0x00; /*INFO_BMODE_CIRCUIT*/
1125 msg.u.call.bc_info1 = 0;
1127 msg.u.call.exthlc = 0;
1129 msg.u.call.bc_capa = strtol(argv[6],NULL,0);
1131 msg.u.call.bc_info1 = 3 | 0x80; /* alaw, if no capability is given at all */
1133 msg.u.call.bc_mode = strtol(argv[7],NULL,0);
1134 if (msg.u.call.bc_mode) msg.u.call.bc_mode = 2;
1137 msg.u.call.bc_info1 = strtol(argv[8],NULL,0);
1138 if (msg.u.call.bc_info1 < 0)
1139 msg.u.call.bc_info1 = 0;
1141 msg.u.call.bc_info1 |= 0x80;
1144 msg.u.call.hlc = strtol(argv[9],NULL,0);
1145 if (msg.u.call.hlc < 0)
1148 msg.u.call.hlc |= 0x80;
1150 // printf("hlc=%d\n", msg.u.call.hlc);
1152 msg.u.call.exthlc = strtol(argv[10],NULL,0);
1153 if (msg.u.call.exthlc < 0)
1154 msg.u.call.exthlc = 0;
1156 msg.u.call.exthlc |= 0x80;
1159 if (write(sock, &msg, sizeof(msg)) != sizeof(msg))
1160 return("Broken pipe while sending command.");
1162 /* receive response */
1164 if (read(sock, &msg, sizeof(msg)) != sizeof(msg))
1165 return("Broken pipe while receiving response.");
1168 case ADMIN_CALL_SETUP_ACK:
1169 printf("SETUP ACKNOWLEDGE\n"); fflush(stdout);
1172 case ADMIN_CALL_PROCEEDING:
1173 printf("PROCEEDING\n"); fflush(stdout);
1176 case ADMIN_CALL_ALERTING:
1177 printf("ALERTING\n"); fflush(stdout);
1180 case ADMIN_CALL_CONNECT:
1181 printf("CONNECT\n number=%s\n", msg.u.call.callerid); fflush(stdout);
1184 case ADMIN_CALL_NOTIFY:
1185 printf("NOTIFY\n notify=%d\n number=%s\n", msg.u.call.notify, msg.u.call.callerid); fflush(stdout);
1188 case ADMIN_CALL_DISCONNECT:
1189 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);
1192 case ADMIN_CALL_RELEASE:
1193 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);
1197 return("Response not valid.");
1200 printf("Command successfull.\n");
1208 char *admin_trace(int sock, int argc, char *argv[])
1210 static struct admin_message msg;
1213 if (!strcasecmp(argv[2], "help"))
1215 printf("Trace Help\n----------\n");
1216 printf("%s trace [brief|short] [<filter>=<value> [...]]\n\n", argv[0]);
1217 printf("By default a complete trace is shown in detailed format.\n");
1218 printf("To show a more compact format, use 'brief' or 'short' keyword.\n");
1219 printf("Use filter values to select specific trace messages.\n");
1220 printf("All given filter values must match. If no filter is given, anything matches.\n\n");
1221 printf("Filters:\n");
1222 printf(" category=<mask bits>\n");
1223 printf(" 0x01 = L1: layer 1 trace (application view)\n");
1224 printf(" 0x02 = L2: layer 2 trace (application view)\n");
1225 printf(" 0x04 = L3: layer 3 trace (application view)\n");
1226 printf(" 0x08 = CH: channel selection trace\n");
1227 printf(" 0x10 = EP: endpoint trace\n");
1228 printf(" 0x20 = AP: application trace\n");
1229 printf(" 0x40 = RO: routing trace\n");
1236 /* send reload command */
1237 memset(&msg, 0, sizeof(msg));
1238 msg.message = ADMIN_CALL_SETUP;
1241 SCPY(msg.u.call.interface, argv[2]);
1245 SCPY(msg.u.call.callerid, argv[3]);
1249 SCPY(msg.u.call.dialing, argv[4]);
1253 if (argv[5][0] == 'p')
1254 msg.u.call.present = 1;
1256 msg.u.call.bc_capa = 0x00; /*INFO_BC_SPEECH*/
1257 msg.u.call.bc_mode = 0x00; /*INFO_BMODE_CIRCUIT*/
1258 msg.u.call.bc_info1 = 0;
1260 msg.u.call.exthlc = 0;
1262 msg.u.call.bc_capa = strtol(argv[6],NULL,0);
1264 msg.u.call.bc_info1 = 3 | 0x80; /* alaw, if no capability is given at all */
1266 msg.u.call.bc_mode = strtol(argv[7],NULL,0);
1267 if (msg.u.call.bc_mode) msg.u.call.bc_mode = 2;
1270 msg.u.call.bc_info1 = strtol(argv[8],NULL,0);
1271 if (msg.u.call.bc_info1 < 0)
1272 msg.u.call.bc_info1 = 0;
1274 msg.u.call.bc_info1 |= 0x80;
1277 msg.u.call.hlc = strtol(argv[9],NULL,0);
1278 if (msg.u.call.hlc < 0)
1281 msg.u.call.hlc |= 0x80;
1283 // printf("hlc=%d\n", msg.u.call.hlc);
1285 msg.u.call.exthlc = strtol(argv[10],NULL,0);
1286 if (msg.u.call.exthlc < 0)
1287 msg.u.call.exthlc = 0;
1289 msg.u.call.exthlc |= 0x80;
1292 if (write(sock, &msg, sizeof(msg)) != sizeof(msg))
1293 return("Broken pipe while sending command.");
1295 /* receive response */
1297 if (read(sock, &msg, sizeof(msg)) != sizeof(msg))
1298 return("Broken pipe while receiving response.");
1301 case ADMIN_CALL_SETUP_ACK:
1302 printf("SETUP ACKNOWLEDGE\n"); fflush(stdout);
1305 case ADMIN_CALL_PROCEEDING:
1306 printf("PROCEEDING\n"); fflush(stdout);
1309 case ADMIN_CALL_ALERTING:
1310 printf("ALERTING\n"); fflush(stdout);
1313 case ADMIN_CALL_CONNECT:
1314 printf("CONNECT\n number=%s\n", msg.u.call.callerid); fflush(stdout);
1317 case ADMIN_CALL_NOTIFY:
1318 printf("NOTIFY\n notify=%d\n number=%s\n", msg.u.call.notify, msg.u.call.callerid); fflush(stdout);
1321 case ADMIN_CALL_DISCONNECT:
1322 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);
1325 case ADMIN_CALL_RELEASE:
1326 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);
1330 return("Response not valid.");
1333 printf("Command successfull.\n");
1341 int main(int argc, char *argv[])
1344 char *socket_name = SOCKET_NAME;
1346 struct sockaddr_un sock_address;
1355 printf("Usage: %s state | interface | route | dial ...\n", argv[0]);
1356 printf("state - View current states using graphical console output.\n");
1357 printf("interface - Tell PBX to reload \"interface.conf\".\n");
1358 printf("route - Tell PBX to reload \"route.conf\".\n");
1359 printf("dial <extension> <number> - Tell PBX the next number to dial for extension.\n");
1360 printf("release <number> - Tell PBX to release endpoint with given number.\n");
1361 printf("testcall <interface> <callerid> <number> [present|restrict [<capability>]] - Testcall\n");
1362 printf(" -> capability = <bc> <mode> <codec> <hlc> <exthlc> (Values must be numbers, -1 to omit.)\n");
1363 printf("trace [brief|short] [<filter> [...]] - Shows call trace. Use filter to reduce output.\n");
1364 printf(" -> Use 'trace help' to see filter description.\n");
1370 if (!(strcasecmp(argv[1],"state")))
1374 if (!(strcasecmp(argv[1],"interface")))
1376 mode = MODE_INTERFACE;
1378 if (!(strcasecmp(argv[1],"route")))
1382 if (!(strcasecmp(argv[1],"dial")))
1388 if (!(strcasecmp(argv[1],"release")))
1392 mode = MODE_RELEASE;
1394 if (!(strcasecmp(argv[1],"testcall")))
1398 mode = MODE_TESTCALL;
1400 if (!(strcasecmp(argv[1],"trace")))
1412 if ((sock = socket(PF_UNIX, SOCK_STREAM, 0)) < 0)
1414 fprintf(stderr, "Failed to create socket.\n");
1417 memset(&sock_address, 0, sizeof(sock_address));
1418 sock_address.sun_family = PF_UNIX;
1419 UCPY(sock_address.sun_path, socket_name);
1420 if ((conn = connect(sock, (struct sockaddr *)&sock_address, SUN_LEN(&sock_address))) < 0)
1423 fprintf(stderr, "Failed to connect to socket \"%s\".\nIs PBX4Linux running?\n", sock_address.sun_path);
1431 ret = admin_state(sock);
1434 case MODE_INTERFACE:
1436 ret = admin_cmd(sock, mode, NULL, NULL);
1440 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);