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;
29 enum { dBm, percentage, rawval } sts_viewtype = dBm;
32 scroll_rows(struct MacListStat *first, int begin, int end, int row,
36 struct MacListStat *curr = first;
44 while (end-- > begin) {
48 "%4u %02X%02X%02X%02X%02X%02X %3u%5u %3d",
49 begin + i, curr->addr[0] & 0xFF, curr->addr[1] & 0xFF,
50 curr->addr[2] & 0xFF, curr->addr[3] & 0xFF,
51 curr->addr[4] & 0xFF, curr->addr[5] & 0xFF,
56 } else if (stat == 2) {
57 /* ATMEL STAtions view */
58 char parentmac[13] = " - ";
60 char quality[5] = " -";
61 char status[4] = " -";
65 if (curr->ParentMacAddress[0] | curr->ParentMacAddress[1] |
66 curr->ParentMacAddress[2] | curr->ParentMacAddress[3] |
67 curr->ParentMacAddress[4] | curr->ParentMacAddress[5])
68 sprintf(parentmac, "%02X%02X%02X%02X%02X%02X",
69 curr->ParentMacAddress[0] & 0xFF,
70 curr->ParentMacAddress[1] & 0xFF,
71 curr->ParentMacAddress[2] & 0xFF,
72 curr->ParentMacAddress[3] & 0xFF,
73 curr->ParentMacAddress[4] & 0xFF,
74 curr->ParentMacAddress[5] & 0xFF);
77 sprintf(rssi, "%4d", conv_rssi(curr->rssi));
80 sprintf(quality, "%3u%%", curr->quality);
83 sprintf(status, "%3u", curr->Status);
86 sprintf(port, "%2u", curr->Port);
89 sprintf(ip, "%s", inet_ntoa(curr->IP));
91 sprintf(message, "%3u %02X%02X%02X%02X%02X%02X %s %s %s %s %s %s",
93 curr->addr[0] & 0xFF, curr->addr[1] & 0xFF,
94 curr->addr[2] & 0xFF, curr->addr[3] & 0xFF,
95 curr->addr[4] & 0xFF, curr->addr[5] & 0xFF,
96 parentmac, rssi, quality, status, port, ip
99 /* used for MAC auth table listing */
100 sprintf(message, " %3u %02X%02X%02X%02X%02X%02X",
101 begin + i, curr->addr[0] & 0xFF, curr->addr[1] & 0xFF,
102 curr->addr[2] & 0xFF, curr->addr[3] & 0xFF,
103 curr->addr[4] & 0xFF, curr->addr[5] & 0xFF
106 mvwaddstr(main_sub, row + i, 0, message);
113 void print_help(char *mess)
115 unsigned short int j, len = (COLS - strlen(mess))/2;
117 werase(win_for_help);
119 for (j = 0; j <= len; j++) {
120 mvwaddch(win_for_help, 0, j, ' ');
121 mvwaddch(win_for_help, 0, COLS - j - 1, ' ');
124 mvwaddstr(win_for_help, 0, len, mess);
125 wrefresh(win_for_help);
128 void print_helperr(char *mess)
130 wattrset(win_for_help, COLOR_PAIR(14) | A_BOLD);
132 wattrset(win_for_help, COLOR_PAIR(11));
135 void print_bold(WINDOW *wptr, char *mess)
137 wattrset(wptr, A_BOLD);
139 wattrset(wptr, A_NORMAL);
143 void print_menusel(int y, int x, char *mess1, char *mess2)
145 mvwaddstr(main_sub, y, x, mess1);
146 print_bold(main_sub, mess2);
149 void print_bottom(char *mess)
153 extern short ap_type, ap_vendorext;
154 extern char *ap_types[], *ap_vendorexts[][3];
156 sprintf(message, _("Current AP: %s Type: %s Ext: %s"),
157 mess, ap_types[ap_type], ap_vendorexts[ap_type][ap_vendorext]);
159 for (i = 0; i < COLS - MCOLS - 1; i++)
160 mvwaddch(main_win, LINES - 3, i, ACS_BSBS);
162 wmove(main_win, LINES - 3, COLS - MCOLS - strlen(message) - 1);
163 print_bold(main_win, message);
166 void print_top(char *title_left, char *title_right)
170 wmove(main_win, 0, 0);
171 while (i++ < COLS - MCOLS - 1)
172 waddch(main_win, ACS_BSBS);
174 wattrset(main_win, A_BOLD);
176 mvwaddstr(main_win, 0, 2, title_left);
179 mvwaddstr(main_win, 0, COLS - MCOLS - strlen(title_right) - 2,
182 wattrset(main_win, A_NORMAL);
186 void print_top_rssi(char *message_r)
190 sprintf(message_l, "%s", "RSSI: ");
191 switch (sts_viewtype) {
193 strcat(message_l, "dBm");
196 strcat(message_l, "%");
199 strcat(message_l, "raw");
201 print_top(message_l, message_r);
204 void clear_main(int m)
206 clear_main_new(m, LINES - 4);
209 void clear_main_new(int m, int n)
212 wmove(main_sub, m, 0);
213 for (i = m; i < n; i++)
214 for (j = 0; j < COLS - MCOLS - 1; j++)
215 waddch(main_sub, ' ');
219 int conv_rssi(int raw_rssi)
221 switch (sts_viewtype) {
223 return (-96 + raw_rssi);
225 return ((int)((minimum (raw_rssi, 40)) * (float)2.5));
229 /* Should never happen */