2 * scr.c from Access Point SNMP Utils for Linux
3 * program output & screen related functions
5 * Copyright (c) 2002 Roman Festchook <roma at polesye dot net>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License Version 2 from
9 * June 1991 as published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 extern WINDOW *main_sub, *win_for_help, *main_win;
28 extern short ap_type, ap_vendorext;
30 enum { dBm, percentage, rawval } sts_viewtype = dBm;
33 scroll_rows(struct MacListStat *first, int begin, int end, int row,
37 struct MacListStat *curr = first;
45 while (end-- > begin) {
47 /* NWN STAtions listing */
49 "%4u %02X%02X%02X%02X%02X%02X %3u%5u %3d",
50 begin + i, curr->addr[0] & 0xFF, curr->addr[1] & 0xFF,
51 curr->addr[2] & 0xFF, curr->addr[3] & 0xFF,
52 curr->addr[4] & 0xFF, curr->addr[5] & 0xFF,
57 } else if (stat == 2) {
58 /* ATMEL STAtions listing */
59 char parentmac[13] = " - ";
61 char quality[5] = " -";
62 char status[4] = " -";
66 if (curr->ParentMacAddress[0] | curr->ParentMacAddress[1] |
67 curr->ParentMacAddress[2] | curr->ParentMacAddress[3] |
68 curr->ParentMacAddress[4] | curr->ParentMacAddress[5])
69 sprintf(parentmac, "%02X%02X%02X%02X%02X%02X",
70 curr->ParentMacAddress[0] & 0xFF,
71 curr->ParentMacAddress[1] & 0xFF,
72 curr->ParentMacAddress[2] & 0xFF,
73 curr->ParentMacAddress[3] & 0xFF,
74 curr->ParentMacAddress[4] & 0xFF,
75 curr->ParentMacAddress[5] & 0xFF);
78 sprintf(rssi, "%4d", conv_rssi(curr->rssi));
81 sprintf(quality, "%3u%%", curr->quality);
84 sprintf(status, "%3u", curr->Status);
87 sprintf(port, "%2u", curr->Port);
90 sprintf(ip, "%s", inet_ntoa(curr->IP));
92 sprintf(message, "%3u %02X%02X%02X%02X%02X%02X %s %s %s %s %s %s",
94 curr->addr[0] & 0xFF, curr->addr[1] & 0xFF,
95 curr->addr[2] & 0xFF, curr->addr[3] & 0xFF,
96 curr->addr[4] & 0xFF, curr->addr[5] & 0xFF,
97 parentmac, rssi, quality, status, port, ip
100 /* MAC auth table listing */
101 sprintf(message, " %3u %02X%02X%02X%02X%02X%02X",
102 begin + i, curr->addr[0] & 0xFF, curr->addr[1] & 0xFF,
103 curr->addr[2] & 0xFF, curr->addr[3] & 0xFF,
104 curr->addr[4] & 0xFF, curr->addr[5] & 0xFF
107 mvwaddstr(main_sub, row + i, 0, message);
114 void print_help(char *mess)
116 unsigned short int j, len = (COLS - strlen(mess))/2;
118 werase(win_for_help);
120 for (j = 0; j <= len; j++) {
121 mvwaddch(win_for_help, 0, j, ' ');
122 mvwaddch(win_for_help, 0, COLS - j - 1, ' ');
125 mvwaddstr(win_for_help, 0, len, mess);
126 wrefresh(win_for_help);
129 void print_helperr(char *mess)
131 wattrset(win_for_help, COLOR_PAIR(14) | A_BOLD);
133 wattrset(win_for_help, COLOR_PAIR(11));
136 void print_bold(WINDOW *wptr, char *mess)
138 wattrset(wptr, A_BOLD);
140 wattrset(wptr, A_NORMAL);
144 void print_menusel(int y, int x, char *mess1, char *mess2)
146 mvwaddstr(main_sub, y, x, mess1);
147 print_bold(main_sub, mess2);
150 void print_bottom(char *mess)
154 extern short ap_type, ap_vendorext;
155 extern char *ap_types[], *ap_vendorexts[][3];
157 sprintf(message, _("Current AP: %s Type: %s Ext: %s"),
158 mess, ap_types[ap_type], ap_vendorexts[ap_type][ap_vendorext]);
160 for (i = 0; i < COLS - MCOLS - 1; i++)
161 mvwaddch(main_win, LINES - 3, i, ACS_BSBS);
163 wmove(main_win, LINES - 3, COLS - MCOLS - strlen(message) - 1);
164 print_bold(main_win, message);
167 void print_top(char *title_left, char *title_right)
171 wmove(main_win, 0, 0);
172 while (i++ < COLS - MCOLS - 1)
173 waddch(main_win, ACS_BSBS);
175 wattrset(main_win, A_BOLD);
177 mvwaddstr(main_win, 0, 2, title_left);
180 mvwaddstr(main_win, 0, COLS - MCOLS - strlen(title_right) - 2,
183 wattrset(main_win, A_NORMAL);
187 void print_top_rssi(char *message_r)
191 sprintf(message_l, "%s", "RSSI: ");
192 switch (sts_viewtype) {
194 strcat(message_l, "dBm");
197 strcat(message_l, "%");
200 strcat(message_l, "raw");
202 print_top(message_l, message_r);
205 void clear_main(int m)
207 clear_main_new(m, LINES - 4);
210 void clear_main_new(int m, int n)
213 wmove(main_sub, m, 0);
214 for (i = m; i < n; i++)
215 for (j = 0; j < COLS - MCOLS - 1; j++)
216 waddch(main_sub, ' ');
220 int conv_rssi(int raw_rssi)
222 switch (sts_viewtype) {
224 return (dbmconv(raw_rssi));
226 return ((int)((minimum (raw_rssi, 40)) * (float)2.5));
230 /* Should never happen */