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 struct timeval select_tv;
469 /* flush logfile name */
476 /* send reload command */
477 memset(&msg, 0, sizeof(msg));
478 msg.message = ADMIN_REQUEST_STATE;
479 // printf("sizeof=%d\n",sizeof(msg));fflush(stdout);
480 if (write(sock, &msg, sizeof(msg)) != sizeof(msg))
483 return("Broken pipe while sending command.");
486 /* receive response */
487 if (read(sock, &msg, sizeof(msg)) != sizeof(msg))
490 return("Broken pipe while receiving response.");
493 if (msg.message != ADMIN_RESPONSE_STATE)
496 return("Response not valid. Expecting state response.");
498 num = msg.u.s.interfaces + msg.u.s.remotes + msg.u.s.joins + msg.u.s.epoints + msg.u.s.ports;
499 m = (struct admin_message *)MALLOC(num*sizeof(struct admin_message));
504 if ((len = read(sock, ((unsigned char *)(m))+off, num*sizeof(struct admin_message)-off)) != num*(int)sizeof(struct admin_message)-off)
508 // fprintf(stderr, "got=%d expected=%d\n", i, num*sizeof(struct admin_message));
510 return("Broken pipe while receiving state infos.");
512 if (len < num*(int)sizeof(struct admin_message))
521 // fprintf("getting =%d interfaces\n", msg.u.s.interfaces);
522 while(i < msg.u.s.interfaces)
524 // fprintf(stderr, "j=%d message=%d\n", j, m[j].message);
525 if (m[j].message != ADMIN_RESPONSE_S_INTERFACE)
529 return("Response not valid. Expecting interface information.");
535 while(i < msg.u.s.remotes)
537 if (m[j].message != ADMIN_RESPONSE_S_REMOTE)
541 return("Response not valid. Expecting remote application information.");
547 while(i < msg.u.s.joins)
549 if (m[j].message != ADMIN_RESPONSE_S_JOIN)
553 return("Response not valid. Expecting join information.");
559 while(i < msg.u.s.epoints)
561 if (m[j].message != ADMIN_RESPONSE_S_EPOINT)
565 return("Response not valid. Expecting endpoint information.");
571 while(i < msg.u.s.ports)
573 if (m[j].message != ADMIN_RESPONSE_S_PORT)
577 return("Response not valid. Expecting port information.");
582 // now j is the number of message blocks
590 if (!!strcmp(logfile, msg.u.s.logfile))
592 SCPY(logfile, msg.u.s.logfile);
600 logline[i][1] = '\0';
604 logfh = open(logfile, O_RDONLY|O_NONBLOCK);
607 /* seek at the end -8000 chars */
608 lseek(logfh, -8000, SEEK_END);
609 /* if not at the beginning, read until endofline */
610 logline[logcur % LOGLINES][0] = '\0';
611 l = read(logfh, logline[logcur % LOGLINES], sizeof(logline[logcur % LOGLINES])-1);
614 /* read first line and skip junk */
615 logline[logcur % LOGLINES][l] = '\0';
616 if ((p = strchr(logline[logcur % LOGLINES],'\n')))
619 SCPY(logline[logcur % LOGLINES], p+1);
620 SCPY(logline[(logcur-1) % LOGLINES], "...");
632 ll = strlen(logline[logcur % LOGLINES]);
633 l = read(logfh, logline[logcur % LOGLINES]+ll, sizeof(logline[logcur % LOGLINES])-ll-1);
636 logline[logcur % LOGLINES][ll+l] = '\0';
638 /* put data to lines */
639 while ((p = strchr(logline[logcur % LOGLINES],'\n')))
643 SCPY(logline[logcur % LOGLINES], p+1);
645 /* if line is full without return, go next line */
646 if (strlen(logline[logcur % LOGLINES]) == sizeof(logline[logcur % LOGLINES])-1)
649 logline[logcur % LOGLINES][0] = '\0';
654 /* display interfaces */
655 if (show_interfaces > 0)
659 ii = i + msg.u.s.interfaces;
662 /* show interface summary */
663 move(++line>1?line:1, 0);
665 if (m[i].u.i.block >= 2)
667 SPRINT(buffer, "%s (%d)%s", m[i].u.i.interface_name, m[i].u.i.portnum, (m[i].u.i.extension)?" (extension)":"");
670 addstr(" not loaded");
673 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);
675 if (m[i].u.i.ptp || !m[i].u.i.ntmode)
677 color((m[i].u.i.l2link)?green:red);
678 addstr((m[i].u.i.l2link)?" L2 UP":" L2 down");
680 color((m[i].u.i.l1link)?green:blue);
681 addstr((m[i].u.i.l1link)?" L1 ACTIVE":" L1 inactive");
687 if (line+2 >= LINES) goto end;
689 if (show_interfaces > 1)
693 jj = m[i].u.i.channels;
696 /* show all channels */
697 if (show_interfaces>2 || m[i].u.i.busy[j]>0)
700 /* show left side / right side */
701 if ((k & 1) && (COLS > 70))
703 move(line>1?line:1,4+((COLS-4)/2));
706 move(++line>1?line:1, 1);
713 SPRINT(buffer,"S%2d: ", j+1+(j>=15));
715 SPRINT(buffer,"B%2d: ", j+1);
717 switch(m[i].u.i.busy[j])
720 if ((!m[i].u.i.l2link && m[i].u.i.ptp) || m[i].u.i.block)
730 case B_STATE_ACTIVATING:
738 case B_STATE_DEACTIVATING:
742 case B_STATE_EXPORTING:
750 case B_STATE_IMPORTING:
755 if (m[i].u.i.port[j])
757 /* search for port */
758 l = msg.u.s.interfaces+msg.u.s.joins+msg.u.s.epoints;
759 ll = l+msg.u.s.ports;
762 if (m[l].u.p.serial == m[i].u.i.port[j])
764 SPRINT(buffer, " %s(%ld)", m[l].u.p.name, m[l].u.p.serial);
775 move(line>1?line:1, 1);
786 move(line>1?line:1, 1);
789 if (line+2 >= LINES) goto end;
790 /* show summary if no channels were shown */
791 if (show_interfaces<2 && ltee==0)
794 move(++line>1?line:1, 1);
797 if (m[i].u.i.l2link && m[i].u.i.block==0)
800 SPRINT(buffer,"all %d channels free", m[i].u.i.channels);
804 SPRINT(buffer,"all %d channels blocked", m[i].u.i.channels);
808 if (line+2 >= LINES) goto end;
815 ii = i + msg.u.s.remotes;
818 /* show remote summary */
819 move(++line>1?line:1, 0);
821 SPRINT(buffer, "Remote: %s", m[i].u.r.name);
827 if (line+2 >= LINES) goto end;
829 /* display calls (brief) */
833 i = msg.u.s.interfaces+msg.u.s.joins;
834 ii = i+msg.u.s.epoints;
837 /* for each endpoint... */
840 move(++line>1?line:1, 0);
842 SPRINT(buffer, "(%d): ", m[i].u.e.serial);
845 if (m[i].u.e.terminal[0])
849 addstr(m[i].u.e.terminal);
853 SPRINT(buffer, " %s", m[i].u.e.callerid);
858 SPRINT(buffer, "%s", m[i].u.e.dialing);
860 if (m[i].u.e.action[0])
865 addstr(m[i].u.e.action);
867 if (line+2 >= LINES) goto end;
872 j = msg.u.s.interfaces;
873 jj = j+msg.u.s.joins;
876 /* for each call... */
877 move(++line>1?line:1, 0);
879 SPRINT(buffer, "(%d):", m[j].u.j.serial);
881 i = msg.u.s.interfaces+msg.u.s.joins;
882 ii = i+msg.u.s.epoints;
885 /* for each endpoint... */
886 if (m[i].u.e.join == m[j].u.j.serial)
889 SPRINT(buffer, " (%d)", m[i].u.e.serial);
892 if (m[i].u.e.terminal[0])
896 addstr(m[i].u.e.terminal);
900 SPRINT(buffer, "-%s", m[i].u.e.callerid);
905 SPRINT(buffer, "%s", m[i].u.e.dialing);
911 if (line+2 >= LINES) goto end;
916 if (line+2 >= LINES) goto end;
918 /* display calls (structurd) */
921 /* show all ports with no epoint */
923 i = msg.u.s.interfaces+msg.u.s.joins+msg.u.s.epoints;
924 ii = i+msg.u.s.ports;
927 if (!m[i].u.p.epoint)
929 move(++line>1?line:1, 8);
930 if (line+2 >= LINES) goto end;
931 line = debug_port(&msg, m, line, i, 0);
932 if (line+2 >= LINES) goto end;
939 if (line+2 >= LINES) goto end;
941 /* show all epoints with no call */
943 i = msg.u.s.interfaces+msg.u.s.joins;
944 ii = i+msg.u.s.epoints;
949 move(++line>1?line:1, 4);
950 if (line+2 >= LINES) goto end;
951 line = debug_epoint(&msg, m, line, i, 0);
952 if (line+2 >= LINES) goto end;
959 if (line+2 >= LINES) goto end;
963 i = msg.u.s.interfaces;
964 ii = i+msg.u.s.joins;
967 move(++line>1?line:1, 0);
968 if (line+2 >= LINES) goto end;
969 line = debug_join(&msg, m, line, i);
970 if (line+2 >= LINES) goto end;
976 if (line+2 >= LINES) goto end;
985 move(line++>1?line-1:1, 0);
987 hline(ACS_HLINE, COLS);
990 l = logcur-(LINES-line-2);
992 if (ll-l >= LOGLINES)
996 move(line++>1?line-1:1, 0);
997 if ((int)strlen(logline[l % LOGLINES]) > hoffset)
998 SCPY(buffer, logline[l % LOGLINES] + hoffset);
1001 if (COLS < (int)strlen(buffer))
1003 buffer[COLS-1] = '\0';
1018 /* display name/time */
1020 // hline(' ', COLS);
1023 msg.u.s.version_string[sizeof(msg.u.s.version_string)-1] = '\0';
1024 SPRINT(buffer, "LCR %s", msg.u.s.version_string);
1029 SPRINT(buffer, "%04d-%02d-%02d %02d:%02d:%02d",
1030 msg.u.s.tm.tm_year+1900, msg.u.s.tm.tm_mon+1, msg.u.s.tm.tm_mday,
1031 msg.u.s.tm.tm_hour, msg.u.s.tm.tm_min, msg.u.s.tm.tm_sec);
1034 /* displeay head line */
1037 hline(ACS_HLINE, COLS);
1041 SPRINT(buffer, "Offset +%d", offset);
1048 SPRINT(buffer, "H-Offset +%d", hoffset);
1055 hline(ACS_HLINE, COLS);
1060 SPRINT(buffer, "-> %s", enter_string);
1064 SPRINT(buffer, "i=interfaces '%s' c=calls '%s' l=log q=quit +-*/=scroll enter", text_interfaces[show_interfaces], text_calls[show_calls]);
1070 if (lastlines!=LINES || lastcols!=COLS)
1079 /* user input in enter mode */
1087 if (!enter_string[0])
1090 SPRINT(logline[logcur++ % LOGLINES], "> %s", enter_string);
1091 if (!!strncmp(enter_string, "interface", 10) &&
1092 !!strncmp(enter_string, "route", 6) &&
1093 !!strncmp(enter_string, "release ", 8) &&
1094 !!strncmp(enter_string, "block ", 6) &&
1095 !!strncmp(enter_string, "unblock ", 8) &&
1096 !!strncmp(enter_string, "unload ", 7))
1098 SPRINT(logline[logcur++ % LOGLINES], "usage:");
1099 SPRINT(logline[logcur++ % LOGLINES], "interface (reload interface.conf)");
1100 SPRINT(logline[logcur++ % LOGLINES], "route (reload routing.conf)");
1101 SPRINT(logline[logcur++ % LOGLINES], "release <EP> (release endpoint with given ID)");
1102 SPRINT(logline[logcur++ % LOGLINES], "block <port> (block port for further calls)");
1103 SPRINT(logline[logcur++ % LOGLINES], "unblock <port> (unblock port for further calls, load if not loaded)");
1104 SPRINT(logline[logcur++ % LOGLINES], "unload <port> (unload mISDN stack, release call calls)");
1107 /* applend output to log window */
1108 SPRINT(buffer, "%s %s", argv[0], enter_string);
1109 fp = popen(buffer, "r");
1112 while(fgets(logline[logcur % LOGLINES], sizeof(logline[0]), fp))
1113 logline[logcur++ % LOGLINES][sizeof(logline[0])-1] = '\0';
1117 SPRINT(logline[logcur++ % LOGLINES], "failed to execute '%s'", buffer);
1120 logline[logcur % LOGLINES][0] = '\0';
1121 enter_string[0] = '\0';
1124 if (ch>=32 && ch<=126)
1126 SCCAT(enter_string, ch);
1132 if (ch==8 || ch==127)
1134 if (enter_string[0])
1135 enter_string[strlen(enter_string)-1] = '\0';
1146 FD_ZERO(&select_rfds);
1147 FD_SET(0, &select_rfds);
1148 select_tv.tv_sec = 0;
1149 select_tv.tv_usec = 250000;
1150 select(1, &select_rfds, NULL, NULL, &select_tv);
1155 /* user input in normal mode */
1158 case 12: /* refresh */
1169 case 'i': /* toggle interface */
1171 if (show_interfaces > 3) show_interfaces = 0;
1174 case 'c': /* toggle calls */
1176 if (show_calls > 2) show_calls = 0;
1179 case 'l': /* toggle log */
1181 if (show_log > 1) show_log = 0;
1184 case '+': /* scroll down */
1188 case '-': /* scroll up */
1193 case '*': /* scroll right */
1197 case '/': /* scroll left */
1202 case 10: /* entermode */
1207 FD_ZERO(&select_rfds);
1208 FD_SET(0, &select_rfds);
1209 select_tv.tv_sec = 0;
1210 select_tv.tv_usec = 250000;
1211 select(1, &select_rfds, NULL, NULL, &select_tv);
1216 /* check for logfh */
1221 /* cleanup curses and exit */
1229 * Send command and show error message.
1231 char *admin_cmd(int sock, int mode, char *extension, char *number)
1233 static struct admin_message msg;
1235 /* send reload command */
1236 memset(&msg, 0, sizeof(msg));
1239 case MODE_INTERFACE:
1240 msg.message = ADMIN_REQUEST_CMD_INTERFACE;
1243 msg.message = ADMIN_REQUEST_CMD_ROUTE;
1246 msg.message = ADMIN_REQUEST_CMD_DIAL;
1247 SPRINT(msg.u.x.message, "%s:%s", extension?:"", number?:"");
1250 msg.message = ADMIN_REQUEST_CMD_RELEASE;
1251 SCPY(msg.u.x.message, number);
1254 msg.message = ADMIN_REQUEST_CMD_BLOCK;
1255 msg.u.x.portnum = atoi(number);
1259 msg.message = ADMIN_REQUEST_CMD_BLOCK;
1260 msg.u.x.portnum = atoi(number);
1264 msg.message = ADMIN_REQUEST_CMD_BLOCK;
1265 msg.u.x.portnum = atoi(number);
1270 if (write(sock, &msg, sizeof(msg)) != sizeof(msg))
1271 return("Broken pipe while sending command.");
1273 /* receive response */
1274 if (read(sock, &msg, sizeof(msg)) != sizeof(msg))
1275 return("Broken pipe while receiving response.");
1278 case MODE_INTERFACE:
1279 if (msg.message != ADMIN_RESPONSE_CMD_INTERFACE)
1280 return("Response not valid.");
1283 if (msg.message != ADMIN_RESPONSE_CMD_ROUTE)
1284 return("Response not valid.");
1287 if (msg.message != ADMIN_RESPONSE_CMD_DIAL)
1288 return("Response not valid.");
1291 if (msg.message != ADMIN_RESPONSE_CMD_RELEASE)
1292 return("Response not valid.");
1297 if (msg.message != ADMIN_RESPONSE_CMD_BLOCK)
1298 return("Response not valid.");
1302 /* process response */
1305 return(msg.u.x.message);
1307 printf("Command successfull.\n");
1315 char *admin_testcall(int sock, int argc, char *argv[])
1317 static struct admin_message msg;
1319 printf("pid=%d\n", getpid()); fflush(stdout);
1321 /* send reload command */
1322 memset(&msg, 0, sizeof(msg));
1323 msg.message = ADMIN_CALL_SETUP;
1326 SCPY(msg.u.call.interface, argv[2]);
1330 SCPY(msg.u.call.callerid, argv[3]);
1334 SCPY(msg.u.call.dialing, argv[4]);
1338 if (argv[5][0] == 'p')
1339 msg.u.call.present = 1;
1341 msg.u.call.bc_capa = 0x00; /*INFO_BC_SPEECH*/
1342 msg.u.call.bc_mode = 0x00; /*INFO_BMODE_CIRCUIT*/
1343 msg.u.call.bc_info1 = 0;
1345 msg.u.call.exthlc = 0;
1347 msg.u.call.bc_capa = strtol(argv[6],NULL,0);
1349 msg.u.call.bc_info1 = 3 | 0x80; /* alaw, if no capability is given at all */
1351 msg.u.call.bc_mode = strtol(argv[7],NULL,0);
1352 if (msg.u.call.bc_mode) msg.u.call.bc_mode = 2;
1355 msg.u.call.bc_info1 = strtol(argv[8],NULL,0);
1356 if (msg.u.call.bc_info1 < 0)
1357 msg.u.call.bc_info1 = 0;
1359 msg.u.call.bc_info1 |= 0x80;
1362 msg.u.call.hlc = strtol(argv[9],NULL,0);
1363 if (msg.u.call.hlc < 0)
1366 msg.u.call.hlc |= 0x80;
1368 // printf("hlc=%d\n", msg.u.call.hlc);
1370 msg.u.call.exthlc = strtol(argv[10],NULL,0);
1371 if (msg.u.call.exthlc < 0)
1372 msg.u.call.exthlc = 0;
1374 msg.u.call.exthlc |= 0x80;
1377 if (write(sock, &msg, sizeof(msg)) != sizeof(msg))
1378 return("Broken pipe while sending command.");
1380 /* receive response */
1382 if (read(sock, &msg, sizeof(msg)) != sizeof(msg))
1383 return("Broken pipe while receiving response.");
1386 case ADMIN_CALL_SETUP_ACK:
1387 printf("SETUP ACKNOWLEDGE\n"); fflush(stdout);
1390 case ADMIN_CALL_PROCEEDING:
1391 printf("PROCEEDING\n"); fflush(stdout);
1394 case ADMIN_CALL_ALERTING:
1395 printf("ALERTING\n"); fflush(stdout);
1398 case ADMIN_CALL_CONNECT:
1399 printf("CONNECT\n number=%s\n", msg.u.call.callerid); fflush(stdout);
1402 case ADMIN_CALL_NOTIFY:
1403 printf("NOTIFY\n notify=%d\n number=%s\n", msg.u.call.notify, msg.u.call.callerid); fflush(stdout);
1406 case ADMIN_CALL_DISCONNECT:
1407 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);
1410 case ADMIN_CALL_RELEASE:
1411 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);
1415 return("Response not valid.");
1418 printf("Command successfull.\n");
1426 char *admin_trace(int sock, int argc, char *argv[])
1428 static struct admin_message msg;
1432 if (argc > 2) if (!strcasecmp(argv[2], "help"))
1434 printf("Trace Help\n----------\n");
1435 printf("%s trace [brief|short] [<filter>=<value> [...]]\n\n", argv[0]);
1436 printf("By default a complete trace is shown in detailed format.\n");
1437 printf("To show a more compact format, use 'brief' or 'short' keyword.\n");
1438 printf("Use filter values to select specific trace messages.\n");
1439 printf("All given filter values must match. If no filter is given, anything matches.\n\n");
1440 printf("Filters:\n");
1441 printf(" category=<mask bits>\n");
1442 printf(" 0x01 = CH: channel object trace\n");
1443 printf(" 0x02 = EP: endpoint object trace\n");
1444 printf(" port=<mISDN port> select only given port for trace\n");
1445 printf(" interface=<interface name> select only given interface for trace\n");
1446 printf(" caller=<caller id> select only given caller id for trace\n");
1447 printf(" dialing=<number> select only given dialed number for trace\n");
1451 /* init trace request */
1452 memset(&msg, 0, sizeof(msg));
1453 msg.message = ADMIN_TRACE_REQUEST;
1454 msg.u.trace_req.detail = 3;
1460 if (!strcasecmp(argv[i], "brief"))
1461 msg.u.trace_req.detail = 1;
1462 else if (!strcasecmp(argv[i], "short"))
1463 msg.u.trace_req.detail = 2;
1464 else if (!strncasecmp(argv[i], "category=", 9))
1465 msg.u.trace_req.category = atoi(argv[i]+9);
1466 else if (!strncasecmp(argv[i], "port=", 5))
1467 msg.u.trace_req.port = atoi(argv[i]+5);
1468 else if (!strncasecmp(argv[i], "interface=", 10))
1469 SCPY(msg.u.trace_req.interface, argv[i]+10);
1470 else if (!strncasecmp(argv[i], "caller=", 7))
1471 SCPY(msg.u.trace_req.caller, argv[i]+7);
1472 else if (!strncasecmp(argv[i], "dialing=", 8))
1473 SCPY(msg.u.trace_req.dialing, argv[i]+8);
1474 else return("Invalid trace option, try 'trace help'.");
1479 /* send trace request */
1480 if (write(sock, &msg, sizeof(msg)) != sizeof(msg))
1481 return("Broken pipe while sending trace request.");
1483 /* receive response */
1485 if (read(sock, &msg, sizeof(msg)) != sizeof(msg))
1486 return("Broken pipe while receiving response.");
1488 if (msg.message != ADMIN_TRACE_RESPONSE)
1489 return("Response not valid.");
1491 printf("%s", msg.u.trace_rsp.text);
1499 int main(int argc, char *argv[])
1502 char *socket_name = SOCKET_NAME;
1504 struct sockaddr_un sock_address;
1513 printf("Usage: %s state | interface | route | dial ...\n", argv[0]);
1514 printf("state - View current states using graphical console output.\n");
1515 printf("interface - Tell LCR to reload \"interface.conf\".\n");
1516 printf("route - Tell LCR to reload \"route.conf\".\n");
1517 printf("dial <extension> <number> - Tell LCR the next number to dial for extension.\n");
1518 printf("release <number> - Tell LCR to release endpoint with given number.\n");
1519 printf("block <port> - Block given port.\n");
1520 printf("unblock <port> - Unblock given port.\n");
1521 printf("unload <port> - Unload port. To load port use 'block' or 'unblock'.\n");
1522 printf("testcall <interface> <callerid> <number> [present|restrict [<capability>]] - Testcall\n");
1523 printf(" -> capability = <bc> <mode> <codec> <hlc> <exthlc> (Values must be numbers, -1 to omit.)\n");
1524 printf("trace [brief|short] [<filter> [...]] - Shows call trace. Use filter to reduce output.\n");
1525 printf(" -> Use 'trace help' to see filter description.\n");
1531 if (!(strcasecmp(argv[1],"state")))
1535 if (!(strcasecmp(argv[1],"interface")))
1537 mode = MODE_INTERFACE;
1539 if (!(strcasecmp(argv[1],"route")))
1543 if (!(strcasecmp(argv[1],"dial")))
1549 if (!(strcasecmp(argv[1],"release")))
1553 mode = MODE_RELEASE;
1555 if (!(strcasecmp(argv[1],"unblock")))
1559 mode = MODE_UNBLOCK;
1561 if (!(strcasecmp(argv[1],"block")))
1567 if (!(strcasecmp(argv[1],"unload")))
1573 if (!(strcasecmp(argv[1],"testcall")))
1577 mode = MODE_TESTCALL;
1579 if (!(strcasecmp(argv[1],"trace")))
1589 if ((sock = socket(PF_UNIX, SOCK_STREAM, 0)) < 0)
1591 fprintf(stderr, "Failed to create socket.\n");
1594 memset(&sock_address, 0, sizeof(sock_address));
1595 sock_address.sun_family = PF_UNIX;
1596 UCPY(sock_address.sun_path, socket_name);
1597 if ((conn = connect(sock, (struct sockaddr *)&sock_address, SUN_LEN(&sock_address))) < 0)
1600 fprintf(stderr, "Failed to connect to socket \"%s\".\nIs LCR running?\n", sock_address.sun_path);
1608 ret = admin_state(sock, argv);
1611 case MODE_INTERFACE:
1613 ret = admin_cmd(sock, mode, NULL, NULL);
1617 ret = admin_cmd(sock, mode, argv[2], argv[3]);
1624 ret = admin_cmd(sock, mode, NULL, argv[2]);
1628 ret = admin_testcall(sock, argc, argv);
1632 ret = admin_trace(sock, argc, argv);
1637 /* now we say good bye */
1640 // if (!strncasecmp(ret, "Broken Pipe", 11))
1642 printf("%s\n", ret);