2 * stations.c from Access Point SNMP Utils for Linux
4 * Copyright (c) 2002 Roman Festchook <roma at polesye dot net>
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.
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.
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
27 #include "ap-curses.h"
29 #define STAS _("Associated Stations")
31 #define MAX_LINES LINES-4
34 extern WINDOW *main_sub;
39 struct AssociatedSTAsInfo {
41 unsigned char MacAddress[6];
44 { 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x02, 0x05, 0x01,
49 { 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x02, 0x05, 0x02,
53 char bridgeOperationalMode[] = {
54 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x04, 0x01, 0x00
58 struct MacListStat *first = NULL, *curr = NULL;
60 int mac_num, begin, end, total_mac;
64 if (ap_type == ATMEL12350) {
69 bridgeOperationalMode[5] = 0xE0;
70 bridgeOperationalMode[6] = 0x3E;
75 varbinds[0].oid = bridgeOperationalMode;
76 varbinds[0].len_oid = sizeof(bridgeOperationalMode);
77 varbinds[0].value = bridgeOperationalMode;
78 varbinds[0].len_val = 0;
79 varbinds[0].type = NULL_VALUE;
81 if (snmp(varbinds, 1, GET) <= 0) {
82 print_helperr(ERR_RET);
86 if (*(varbinds[0].value) == 3) {
87 mvwaddstr(main_sub, 3, 1, _("AP now in AP Client Mode and don't has any associated stations"));
96 varbinds[0].oid = StasNum;
97 varbinds[0].len_oid = sizeof(StasNum);
98 varbinds[0].value = StasNum;
99 varbinds[0].type = NULL_VALUE;
100 varbinds[0].len_val = 0;
101 print_help(WAIT_RET);
102 if (snmp(varbinds, 1, GET) <= 0) {
103 print_helperr(ERR_RET);
108 total_mac = *(varbinds[0].value);
111 sprintf(message, "%s: %d", STAS, total_mac);
112 print_title(message);
113 mvwaddstr(main_sub, 0, 3, _("Id MAC address"));
116 while (mac_num <= total_mac) {
118 varbinds[0].oid = StasMac;
119 varbinds[0].len_oid = sizeof(StasMac);
120 varbinds[0].type = INT_VALUE;
121 get.Num = swap2(mac_num);
122 varbinds[0].value = (char *) &get;
123 varbinds[0].len_val = sizeof(get);
125 if (snmp(varbinds, 1, SET) <= 0) {
126 print_helperr(ERR_RET);
131 if (varbinds[0].len_val == 24) {
135 (struct AssociatedSTAsInfo *) malloc(varbinds[0].len_val);
136 memcpy(mac, varbinds[0].value, varbinds[0].len_val);
137 /* mac = (struct AssociatedSTAsInfo *) varbinds[0].value;*/
139 print_helperr(_("AssociatedSTAsInfo packet error"));
146 (struct MacListStat *) malloc(sizeof(struct MacListStat));
150 (struct MacListStat *) malloc(sizeof(struct MacListStat));
154 memcpy(curr->addr, mac->MacAddress, 6);
159 end = (MAX_LINES < mac_num) ? MAX_LINES : mac_num;
160 scroll_rows(first, begin, end, 1, 0);
161 print_help(_("Arrows - scroll; S - save to file; Q - quit to menu."));
166 save_Stations(first);
173 scroll_rows(first, begin, end, 1, 0);
181 scroll_rows(first, begin, end, 1, 0);
191 while ((curr = first)) {
201 unsigned char Mac[] =
202 { 0x2b, 0x06, 0x01, 0x04, 0x01, 0x87, 0x29, 0x03, 0x01, 0x03, 0x01,
203 0x02, 0x01, 0x02, 0x80, 0x00 };
205 unsigned char Quality[] =
206 { 0x2b, 0x06, 0x01, 0x04, 0x01, 0x87, 0x29, 0x03, 0x01, 0x03, 0x01,
207 0x02, 0x01, 0x03, 0x80, 0x00 };
208 unsigned char Age[] =
209 { 0x2b, 0x06, 0x01, 0x04, 0x01, 0x87, 0x29, 0x03, 0x01, 0x03, 0x01,
210 0x02, 0x01, 0x04, 0x80, 0x00 };
211 unsigned char RSSI[] =
212 { 0x2b, 0x06, 0x01, 0x04, 0x01, 0x87, 0x29, 0x03, 0x01, 0x03, 0x01,
213 0x02, 0x01, 0x05, 0x80, 0x00 };
215 struct MacListStat *first = NULL, *curr = NULL;
216 char null[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, message[1024];
217 int mac_num, begin, end;
219 unsigned char next_num;
223 print_title(_("Associated stations"));
224 mvwaddstr(main_sub, 0, 3,
225 _("Id MAC address Quality Age RSSI"));
227 print_help(WAIT_RET);
229 varbinds[0].oid = Mac;
230 varbinds[0].len_oid = sizeof(Mac);
231 varbinds[0].len_val = 0;
232 varbinds[0].type = NULL_VALUE;
233 if (snmp(varbinds, 1, GET_NEXT) <= 0) {
234 print_helperr(ERR_RET);
237 next_num = varbinds[0].oid[varbinds[0].len_oid - 1];
239 while (memcmp(varbinds[0].oid, Mac, sizeof(Mac) - 2) == 0) {
241 Mac[sizeof(Mac) - 1] = next_num;
242 Quality[sizeof(Mac) - 1] = next_num;
243 Age[sizeof(Mac) - 1] = next_num;
244 RSSI[sizeof(Mac) - 1] = next_num;
246 if(sizeof(Mac) == varbinds[0].len_oid) {
247 Mac[sizeof(Mac) - 2] = varbinds[0].oid[varbinds[0].len_oid - 2];
248 Quality[sizeof(Mac) - 2] = varbinds[0].oid[varbinds[0].len_oid - 2];
249 Age[sizeof(Mac) - 2] = varbinds[0].oid[varbinds[0].len_oid - 2];
250 RSSI[sizeof(Mac) - 2] = varbinds[0].oid[varbinds[0].len_oid - 2];
253 varbinds[0].oid = Mac;
254 varbinds[0].len_oid = sizeof(Mac);
255 varbinds[0].len_val = 0;
256 varbinds[0].type = NULL_VALUE;
257 varbinds[1].oid = Quality;
258 varbinds[1].len_oid = sizeof(Quality);
259 varbinds[1].len_val = 0;
260 varbinds[1].type = NULL_VALUE;
261 varbinds[2].oid = Age;
262 varbinds[2].len_oid = sizeof(Age);
263 varbinds[2].len_val = 0;
264 varbinds[2].type = NULL_VALUE;
265 varbinds[3].oid = RSSI;
266 varbinds[3].len_oid = sizeof(RSSI);
267 varbinds[3].len_val = 0;
268 varbinds[3].type = NULL_VALUE;
269 if (snmp(varbinds, 4, GET) <= 0) {
270 print_helperr(ERR_RET);
276 if (memcmp(null, varbinds[0].value, 6)) {
279 (struct MacListStat *)
280 malloc(sizeof(struct MacListStat));
284 (struct MacListStat *)
285 malloc(sizeof(struct MacListStat));
288 memcpy(curr->addr, varbinds[0].value, 6);
289 curr->quality = *varbinds[1].value;
290 curr->idle = *varbinds[2].value;
291 curr->rssi = *varbinds[3].value;
296 varbinds[0].oid = Mac;
297 varbinds[0].len_oid = sizeof(Mac);
298 varbinds[0].len_val = 0;
299 varbinds[0].type = NULL_VALUE;
300 if (snmp(varbinds, 1, GET_NEXT) <= 0) {
301 print_helperr(ERR_RET);
304 next_num = varbinds[0].oid[varbinds[0].len_oid - 1];
307 sprintf(message, "%s: %d", _("Associated stations"), mac_num);
308 print_title(message);
311 end = (MAX_LINES < mac_num+1) ? MAX_LINES : mac_num+1;
312 scroll_rows(first, begin, end, 1, 1);
313 print_help(_("Arrows - scroll; S - save to file; Q - quit to menu."));
318 save_Stations(first);
322 if (end < mac_num+1) {
325 scroll_rows(first, begin, end, 1, 1);
333 scroll_rows(first, begin, end, 1, 1);
347 while ((curr = first)) {