]> git.decadent.org.uk Git - ap-utils.git/blob - ap-gl/stations.c
Imported Upstream version 1.5~pre3~a
[ap-utils.git] / ap-gl / stations.c
1 /*
2  *      stations.c from Access Point SNMP Utils for Linux
3  *
4  * Copyright (c) 2002 Roman Festchook <roma at polesye dot net>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License Version 2 from
8  * June 1991 as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  */
20 #include <sys/wait.h>
21 #include <unistd.h>
22 #include <stdlib.h>
23 #include <fcntl.h>
24 #include <signal.h>
25 #include <string.h>
26 #include "ap-utils.h"
27
28 #define MAX_LINES LINES-4
29
30 extern int LINES;
31 extern WINDOW *main_sub;
32 extern short ap_type;
33
34 void atmel_stations()
35 {
36     char StasNum[] = {
37         0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x02, 0x05, 0x01, 0x00
38     };
39     char StasMac[] = {
40         0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x02, 0x05, 0x02, 0x00
41     };
42     char bridgeOperationalMode[] = {
43          0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x04, 0x01, 0x00
44     };
45     
46     struct AssociatedSTAsInfo {
47         unsigned short Num;
48         unsigned char MacAddress[6];
49         unsigned char Status;
50         unsigned char Port;
51         unsigned char ParentMacAddress[6];
52         unsigned char RSSI;
53         unsigned char LinkQuality;
54         unsigned char IP[4];
55         unsigned char Reserved[2];
56     } *mac = NULL, get;
57
58     struct MacListStat *first = NULL, *curr = NULL;
59     char message[1024];
60     int mac_num, begin, end, total_mac;
61     varbind varbinds[1];
62
63     print_top(NULL, ST_TITLE);
64
65     varbinds[0].oid = bridgeOperationalMode;
66     varbinds[0].len_oid = sizeof(bridgeOperationalMode);
67     varbinds[0].value = bridgeOperationalMode;
68     varbinds[0].len_val = 0;
69     varbinds[0].type = NULL_VALUE;
70     print_help(WAIT_RET);
71     if (snmp(varbinds, 1, GET) <= 0) {
72          print_helperr(ERR_RET);
73          goto exit;
74     }
75
76     if (*(varbinds[0].value) == 3) {
77         mvwaddstr(main_sub, 3, 1, _("AP is currently in AP Client Mode => "
78             "no associated STAtions."));
79         print_help(ANY_KEY);
80         wrefresh(main_sub);
81         getch();
82         goto exit;
83     }
84
85     varbinds[0].oid = StasNum;
86     varbinds[0].len_oid = sizeof(StasNum);
87     varbinds[0].value = StasNum;
88     varbinds[0].type = NULL_VALUE;
89     varbinds[0].len_val = 0;
90     print_help(WAIT_RET);
91     if (snmp(varbinds, 1, GET) <= 0) {
92         print_helperr(ERR_RET);
93         getch();
94         goto exit;
95     }
96
97     total_mac = *(varbinds[0].value);
98     mac_num = 1;
99
100     sprintf(message, "%s: %d", ST_TITLE, total_mac);
101     print_top(NULL, message);
102     wattrset(main_sub, COLOR_PAIR(13));
103     mvwaddstr(main_sub, 0, 0,
104         _("  #     MAC       Parent MAC  RSSI   LQ Sts MACn      IP        "));
105     wattrset(main_sub, A_NORMAL);
106     noecho();
107
108     while (mac_num <= total_mac) {
109
110         varbinds[0].oid = StasMac;
111         varbinds[0].len_oid = sizeof(StasMac);
112         varbinds[0].type = INT_VALUE;
113         get.Num = swap2(mac_num);
114         varbinds[0].value = (char *) &get;
115         varbinds[0].len_val = sizeof(get);
116
117         if (snmp(varbinds, 1, SET) <= 0) {
118             print_helperr(ERR_RET);
119             getch();
120             goto exit;
121         }
122
123         if (varbinds[0].len_val == 24) {
124             if (mac)
125                 free(mac);
126             mac =
127                 (struct AssociatedSTAsInfo *) malloc(varbinds[0].len_val);
128             memcpy(mac, varbinds[0].value, varbinds[0].len_val);
129 /*          mac = (struct AssociatedSTAsInfo *) varbinds[0].value;*/
130         } else {
131             print_helperr(_("AssociatedSTAsInfo packet error"));
132             goto exit;
133         }
134
135
136         if (first == NULL) {
137             first =
138                 (struct MacListStat *) malloc(sizeof(struct MacListStat));
139             curr = first;
140         } else {
141             curr->next =
142                 (struct MacListStat *) malloc(sizeof(struct MacListStat));
143             curr = curr->next;
144         }
145
146         memcpy(curr->addr, mac->MacAddress, 6);
147 //      memcpy(curr->ParentMacAddress, mac->ParentMacAddress, 6);
148         memcpy(&(curr->IP.s_addr), mac->IP, 4);
149         curr->quality = 100 - (minimum(mac->LinkQuality, 40)*2.5);
150 //      curr->rssi = - 96 + mac->RSSI;
151 //      curr->quality = mac->LinkQuality;
152         curr->rssi = mac->RSSI;
153         
154         curr->Port = mac->Port;
155         curr->Status = mac->Status;
156         curr->next = NULL;
157         mac_num++;
158     }
159     begin = 1;
160     end = (mac_num > MAX_LINES) ? MAX_LINES : mac_num;
161     scroll_rows(first, begin, end, 1, 2);
162     while (1) {
163         print_help(_("Arrows - scroll; S - save to file; Q - quit to menu."));
164         switch (getch()) {
165         case 'S':
166         case 's':
167             save_Stations(first);
168             continue;
169         case KEY_RIGHT:
170         case KEY_DOWN:
171             if (end < mac_num) {
172                 begin++;
173                 end++;
174                 scroll_rows(first, begin, end, 1, 2);
175             }
176             continue;
177         case KEY_UP:
178         case KEY_LEFT:
179             if (begin > 1) {
180                 begin--;
181                 end--;
182                 scroll_rows(first, begin, end, 1, 2);
183             }
184             continue;
185         case 'Q':
186         case 'q':
187             goto exit;
188         }
189     }
190
191   exit:
192     while ((curr = first) != 0) {
193         first = curr->next;
194         free(curr);
195     }
196     print_top(NULL, NULL);
197     clear_main(0);
198 }
199