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