~ubuntu-branches/ubuntu/edgy/ap-utils/edgy

« back to all changes in this revision

Viewing changes to lib/scr.c

  • Committer: Bazaar Package Importer
  • Author(s): Celso González
  • Date: 2004-12-05 19:40:10 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20041205194010-4sbpbou1f4nn5xh9
Tags: 1.4.1+1.5pre1-1
* The "Freedom Of Ukraine" release
* New upstream release (closes: #243208 fix little incorrection in man page)
  - added two new programs ap-auth and ap-gl
  - added support for VERNET AP extension
  - lots of ui improvement
  - Some lintian fixes about utf8 encoding
  

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
#include <unistd.h>
23
23
#include <string.h>
24
24
#include "ap-utils.h"
25
 
#include "ap-curses.h"
26
25
#include <menu.h>
27
26
 
28
27
extern WINDOW *main_sub, *win_for_help, *main_win;
29
28
 
 
29
enum { dBm, percentage, rawval } sts_viewtype = dBm;
 
30
 
30
31
void
31
32
scroll_rows(struct MacListStat *first, int begin, int end, int row,
32
33
            int stat)
41
42
        curr = curr->next;
42
43
    i = 0;
43
44
    while (end-- > begin) {
44
 
        if (stat==1) {
45
 
            sprintf(message,
46
 
                    "%4u       %02X%02X%02X%02X%02X%02X        %3u%5u   %3u",
47
 
                    begin + i, curr->addr[0] & 0xFF, curr->addr[1] & 0xFF,
48
 
                    curr->addr[2] & 0xFF, curr->addr[3] & 0xFF,
49
 
                    curr->addr[4] & 0xFF, curr->addr[5] & 0xFF,
50
 
                    curr->quality, curr->idle, curr->rssi);
51
 
        } else if(stat==2) {
52
 
            sprintf(message,
53
 
                    "%2u %02X%02X%02X%02X%02X%02X %3d%% %4ddBm  %3u    %2u   %s",
54
 
                    begin + i,
55
 
                    curr->addr[0] & 0xFF, curr->addr[1] & 0xFF,
56
 
                    curr->addr[2] & 0xFF, curr->addr[3] & 0xFF,
57
 
                    curr->addr[4] & 0xFF, curr->addr[5] & 0xFF,
58
 
                    curr->quality, curr->rssi, curr->Status, curr->Port, inet_ntoa(curr->IP));
 
45
        if (stat == 1) {
 
46
            /* NWN view */
 
47
            sprintf(message,
 
48
                (sts_viewtype == dBm) ?
 
49
                "%4u       %02X%02X%02X%02X%02X%02X        %3u%5u   %3udBm"
 
50
                :
 
51
                (sts_viewtype == percentage) ?
 
52
                "%4u       %02X%02X%02X%02X%02X%02X        %3u%5u     %3u%%"
 
53
                :
 
54
                "%4u       %02X%02X%02X%02X%02X%02X        %3u%5u      %3u",
 
55
                begin + i, curr->addr[0] & 0xFF, curr->addr[1] & 0xFF,
 
56
                curr->addr[2] & 0xFF, curr->addr[3] & 0xFF,
 
57
                curr->addr[4] & 0xFF, curr->addr[5] & 0xFF,
 
58
                curr->quality,
 
59
                curr->idle,
 
60
                conv_rssi(curr->rssi)
 
61
            );
 
62
        } else if (stat == 2) {
 
63
            /* ATMEL410_SBRIDGES (firmware 1.4k.1) view */
 
64
            sprintf(message,
 
65
                (sts_viewtype == dBm) ?
 
66
                "%2u %02X%02X%02X%02X%02X%02X %3d%% %4ddBm  %3u    %2u   %s"
 
67
                :
 
68
                (sts_viewtype == percentage) ?
 
69
                "%2u %02X%02X%02X%02X%02X%02X %3d%%   %3u%%  %3u    %2u   %s"
 
70
                :
 
71
                "%2u %02X%02X%02X%02X%02X%02X %3d%%    %3u  %3u    %2u   %s",
 
72
                begin + i,
 
73
                curr->addr[0] & 0xFF, curr->addr[1] & 0xFF,
 
74
                curr->addr[2] & 0xFF, curr->addr[3] & 0xFF,
 
75
                curr->addr[4] & 0xFF, curr->addr[5] & 0xFF,
 
76
                curr->quality,
 
77
                conv_rssi(curr->rssi),
 
78
                curr->Status,
 
79
                curr->Port,
 
80
                inet_ntoa(curr->IP)
 
81
            );
 
82
        } else if (stat == 3) {
 
83
            /* ATMEL12350_VERNET view */
 
84
            sprintf(message,
 
85
                (sts_viewtype == dBm) ?
 
86
                "%2u %02X%02X%02X%02X%02X%02X %02X%02X%02X%02X%02X%02X "
 
87
                "%4ddBm  %3u    %2u  %s"
 
88
                :
 
89
                (sts_viewtype == percentage) ?
 
90
                "%2u %02X%02X%02X%02X%02X%02X %02X%02X%02X%02X%02X%02X "
 
91
                "  %3u%%   %3u    %2u  %s"
 
92
                :
 
93
                "%2u %02X%02X%02X%02X%02X%02X %02X%02X%02X%02X%02X%02X "
 
94
                "   %3u   %3u    %2u  %s",
 
95
                begin + i,
 
96
                curr->addr[0] & 0xFF, curr->addr[1] & 0xFF,
 
97
                curr->addr[2] & 0xFF, curr->addr[3] & 0xFF,
 
98
                curr->addr[4] & 0xFF, curr->addr[5] & 0xFF,
 
99
                curr->ParentMacAddress[0] & 0xFF,
 
100
                curr->ParentMacAddress[1] & 0xFF,
 
101
                curr->ParentMacAddress[2] & 0xFF,
 
102
                curr->ParentMacAddress[3] & 0xFF,
 
103
                curr->ParentMacAddress[4] & 0xFF,
 
104
                curr->ParentMacAddress[5] & 0xFF,
 
105
                conv_rssi(curr->rssi),
 
106
                curr->Status,
 
107
                curr->Port,
 
108
                inet_ntoa(curr->IP)
 
109
            );
59
110
        } else {
60
 
            sprintf(message, "%4u       %02X%02X%02X%02X%02X%02X",
61
 
                    begin + i, curr->addr[0] & 0xFF, curr->addr[1] & 0xFF,
62
 
                    curr->addr[2] & 0xFF, curr->addr[3] & 0xFF,
63
 
                    curr->addr[4] & 0xFF, curr->addr[5] & 0xFF);
 
111
            /* generic ATMEL view */
 
112
            sprintf(message, "%2u       %02X%02X%02X%02X%02X%02X",
 
113
                begin + i, curr->addr[0] & 0xFF, curr->addr[1] & 0xFF,
 
114
                curr->addr[2] & 0xFF, curr->addr[3] & 0xFF,
 
115
                curr->addr[4] & 0xFF, curr->addr[5] & 0xFF
 
116
            );
64
117
        }
65
118
        mvwaddstr(main_sub, row + i, 0, message);
66
119
        i++;
67
120
        curr = curr->next;
68
121
    }
69
122
    wrefresh(main_sub);
70
 
 
71
123
}
72
124
 
73
125
void print_help(char *mess)
92
144
    wattrset(win_for_help, COLOR_PAIR(1));
93
145
}
94
146
 
95
 
void print_title(char *mess)
96
 
{
97
 
    int i;
98
 
    /* ����� ����� */
99
 
    for (i = 0; i < COLS - MCOLS - 1; i++)
100
 
        mvwaddch(main_win, 0, i, ACS_BSBS);
101
 
    wattrset(main_win, A_BOLD);
102
 
    mvwaddstr(main_win, 0, COLS - MCOLS - strlen(mess) - 2, mess);
103
 
    wattrset(main_win, A_NORMAL);
104
 
    wrefresh(main_win);
105
 
}
106
 
 
107
 
void print_viewtype(int v)
108
 
{
109
 
    char message[7];
110
 
 
111
 
    sprintf(message, "View: %c", v + '0');
112
 
    wattrset(main_win, A_BOLD);
113
 
    mvwaddstr(main_win, 0, 1, message);
114
 
    wattrset(main_win, A_NORMAL);
115
 
    wrefresh(main_win);
 
147
void print_bold(WINDOW *wptr, char *mess)
 
148
{
 
149
    wattrset(wptr, A_BOLD);
 
150
    waddstr(wptr, mess);
 
151
    wattrset(wptr, A_NORMAL);
 
152
    wrefresh(wptr);
116
153
}
117
154
 
118
155
void print_menusel(int y, int x, char *mess1, char *mess2)
119
156
{
120
157
    mvwaddstr(main_sub, y, x, mess1);
121
 
    wattrset(main_sub, A_BOLD);
122
 
    waddstr(main_sub, mess2);
123
 
    wattrset(main_sub, A_NORMAL);
124
 
    wrefresh(main_sub);
 
158
    print_bold(main_sub, mess2);
125
159
}
126
160
 
127
161
void print_bottom(char *mess)
128
162
{
129
163
    int i;
130
164
    char message[100];
131
 
    extern short ap_type;
132
 
    extern char *ap_types[];
 
165
    extern short ap_type, ap_vendorext;
 
166
    extern char *ap_types[], *ap_vendorexts[][3];
133
167
 
134
 
    sprintf(message, _("Current AP: %s Type: %s"), mess, ap_types[ap_type]);
 
168
    sprintf(message, _("Current AP: %s Type: %s Ext: %s"),
 
169
        mess, ap_types[ap_type], ap_vendorexts[ap_type][ap_vendorext]);
135
170
    /* ����� ����� */
136
171
    for (i = 0; i < COLS - MCOLS - 1; i++)
137
172
        mvwaddch(main_win, LINES - 3, i, ACS_BSBS);
 
173
 
 
174
    wmove(main_win, LINES - 3, COLS - MCOLS - strlen(message) - 1);
 
175
    print_bold(main_win, message);
 
176
}
 
177
 
 
178
void print_top(char *title_left, char *title_right)
 
179
{
 
180
    int i = 0;
 
181
 
 
182
    wmove(main_win, 0, 0);
 
183
    while (i++ < COLS - MCOLS - 1)
 
184
        waddch(main_win, ACS_BSBS);
 
185
 
138
186
    wattrset(main_win, A_BOLD);
139
 
    mvwaddstr(main_win, LINES - 3, COLS - MCOLS - strlen(message) - 1,
140
 
              message);
 
187
    if (title_left)
 
188
        mvwaddstr(main_win, 0, 2, title_left);
 
189
 
 
190
    if (title_right)
 
191
        mvwaddstr(main_win, 0, COLS - MCOLS - strlen(title_right) - 2,
 
192
            title_right);
 
193
 
141
194
    wattrset(main_win, A_NORMAL);
142
195
    wrefresh(main_win);
143
196
}
144
197
 
 
198
void print_top_rssi(char *message_r)
 
199
{
 
200
    char message_l[200];
 
201
 
 
202
    sprintf(message_l, "%s", VIEW);
 
203
    switch (sts_viewtype) {
 
204
        case dBm:
 
205
           strcat(message_l, "RSSI in dBm");
 
206
           break;
 
207
        case percentage:
 
208
           strcat(message_l, "RSSI in percentage");
 
209
           break;
 
210
        case rawval:
 
211
           strcat(message_l, "RSSI in raw values");
 
212
    }
 
213
    print_top(message_l, message_r);
 
214
}
145
215
 
146
216
void clear_main(int m)
147
217
{
157
227
            waddch(main_sub, ' ');
158
228
    wrefresh(main_sub);
159
229
}
 
230
 
 
231
int conv_rssi(int raw_rssi)
 
232
{
 
233
    switch (sts_viewtype) {
 
234
        case dBm:
 
235
           return (-96 + raw_rssi); 
 
236
        case percentage:
 
237
           return ((int)((minimum (raw_rssi, 40)) * (float)2.5));
 
238
        case rawval:
 
239
           return raw_rssi;
 
240
    }
 
241
    /* Should never happen */
 
242
    return -1;
 
243
}
 
244