]> git.decadent.org.uk Git - ap-utils.git/blob - lib/scr.c
6ad506a3bcbefc3b2da320e9658380e4d9ac96b5
[ap-utils.git] / lib / scr.c
1 /*
2  *      scr.c from Access Point SNMP Utils for Linux
3  *      program output & screen related functions
4  *
5  * Copyright (c) 2002 Roman Festchook <roma at polesye dot net>
6  *
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.
10  *
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.
15  *
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
19  *
20  */
21 #include <stdlib.h>
22 #include <unistd.h>
23 #include <string.h>
24 #include "ap-utils.h"
25 #include <menu.h>
26
27 extern WINDOW *main_sub, *win_for_help, *main_win;
28 extern short ap_type, ap_vendorext;
29
30 enum { dBm, percentage, rawval } sts_viewtype = dBm;
31
32 void
33 scroll_rows(struct MacListStat *first, int begin, int end, int row,
34             int stat)
35 {
36     int i = 1;
37     struct MacListStat *curr = first;
38     char message[100];
39
40     clear_main(row);
41
42     while (i++ < begin)
43         curr = curr->next;
44     i = 0;
45     while (end-- > begin) {
46         if (stat == 1) {
47             /* NWN STAtions listing */
48             sprintf(message,
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,
53                 curr->quality,
54                 curr->idle,
55                 conv_rssi(curr->rssi)
56             );
57         } else if (stat == 2) {
58             /* ATMEL STAtions listing */
59             char parentmac[13] = "      -     ";
60             char rssi[5] = "   -";
61             char quality[5] = "   -";
62             char status[4] = "  -";
63             char port[4] = " -";
64             char ip[16] = "      -        ";
65
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);
76
77             if (curr->rssi)
78                 sprintf(rssi, "%4d", conv_rssi(curr->rssi));
79
80             if (curr->quality)
81                 sprintf(quality, "%3u%%", curr->quality);
82
83             if (curr->Status)
84                 sprintf(status, "%3u", curr->Status);
85
86             if (curr->Port)
87                 sprintf(port, "%2u", curr->Port);
88
89             if(curr->IP.s_addr)
90                 sprintf(ip, "%s", inet_ntoa(curr->IP));
91
92             sprintf(message, "%3u %02X%02X%02X%02X%02X%02X %s %s %s %s   %s %s",
93                 begin + i,
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
98             );
99         } else {
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
105             );
106         }
107         mvwaddstr(main_sub, row + i, 0, message);
108         i++;
109         curr = curr->next;
110     }
111     wrefresh(main_sub);
112 }
113
114 void print_help(char *mess)
115 {
116     unsigned short int j, len = (COLS - strlen(mess))/2;
117
118     werase(win_for_help);
119
120     for (j = 0; j <= len; j++) {
121         mvwaddch(win_for_help, 0, j, ' ');
122         mvwaddch(win_for_help, 0, COLS - j - 1, ' ');
123     }
124     
125     mvwaddstr(win_for_help, 0, len, mess);
126     wrefresh(win_for_help);
127 }
128
129 void print_helperr(char *mess)
130 {
131     wattrset(win_for_help, COLOR_PAIR(14) | A_BOLD);
132     print_help(mess);
133     wattrset(win_for_help, COLOR_PAIR(11));
134 }
135
136 void print_bold(WINDOW *wptr, char *mess)
137 {
138     wattrset(wptr, A_BOLD);
139     waddstr(wptr, mess);
140     wattrset(wptr, A_NORMAL);
141     wrefresh(wptr);
142 }
143
144 void print_menusel(int y, int x, char *mess1, char *mess2)
145 {
146     mvwaddstr(main_sub, y, x, mess1);
147     print_bold(main_sub, mess2);
148 }
149
150 void print_bottom(char *mess)
151 {
152     int i;
153     char message[100];
154     extern short ap_type, ap_vendorext;
155     extern char *ap_types[], *ap_vendorexts[][3];
156
157     sprintf(message, _("Current AP: %s Type: %s Ext: %s"),
158         mess, ap_types[ap_type], ap_vendorexts[ap_type][ap_vendorext]);
159     /* íÁÌÀÀ ÒÁÍËÕ */
160     for (i = 0; i < COLS - MCOLS - 1; i++)
161         mvwaddch(main_win, LINES - 3, i, ACS_BSBS);
162
163     wmove(main_win, LINES - 3, COLS - MCOLS - strlen(message) - 1);
164     print_bold(main_win, message);
165 }
166
167 void print_top(char *title_left, char *title_right)
168 {
169     int i = 0;
170
171     wmove(main_win, 0, 0);
172     while (i++ < COLS - MCOLS - 1)
173         waddch(main_win, ACS_BSBS);
174
175     wattrset(main_win, A_BOLD);
176     if (title_left)
177         mvwaddstr(main_win, 0, 2, title_left);
178
179     if (title_right)
180         mvwaddstr(main_win, 0, COLS - MCOLS - strlen(title_right) - 2,
181             title_right);
182
183     wattrset(main_win, A_NORMAL);
184     wrefresh(main_win);
185 }
186
187 void print_top_rssi(char *message_r)
188 {
189     char message_l[200];
190
191     sprintf(message_l, "%s", "RSSI: ");
192     switch (sts_viewtype) {
193         case dBm:
194            strcat(message_l, "dBm");
195            break;
196         case percentage:
197            strcat(message_l, "%");
198            break;
199         case rawval:
200            strcat(message_l, "raw");
201     }
202     print_top(message_l, message_r);
203 }
204
205 void clear_main(int m)
206 {
207     clear_main_new(m, LINES - 4);
208 }
209
210 void clear_main_new(int m, int n)
211 {
212     int i, j;
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, ' ');
217     wrefresh(main_sub);
218 }
219
220 int conv_rssi(int raw_rssi)
221 {
222     switch (sts_viewtype) {
223         case dBm:
224            return (dbmconv(raw_rssi)); 
225         case percentage:
226            return ((int)((minimum (raw_rssi, 40)) * (float)2.5));
227         case rawval:
228            return raw_rssi;
229     }
230     /* Should never happen */
231     return -1;
232 }
233