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")
32 /* following for VERNET-enhanced ATMEL12350 MIB */
33 #define STAS_HEADER_VERNET \
34 _(" # MAC Parent MAC RSSI Status MACn IP ")
36 #define MAX_LINES LINES-4
39 extern WINDOW *main_sub;
41 extern char IS_ATMEL12350_VERNET;
42 extern int sts_viewtype;
46 char bridgeOperationalMode[] = {
47 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x04, 0x01, 0x00
50 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x02, 0x05, 0x01, 0x00
53 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x02, 0x05, 0x02, 0x00
56 struct AssociatedSTAsInfo {
58 unsigned char MacAddress[6];
59 /* following ones are specific for enhanced ATMEL 12350 MIB by VERNET */
62 unsigned char ParentMacAddress[6];
67 struct MacListStat *first = NULL, *curr = NULL;
69 int mac_idx, begin, end, total_mac;
73 if (ap_type == ATMEL12350) {
74 bridgeOperationalMode[5] = 0xE0;
75 bridgeOperationalMode[6] = 0x3E;
82 /* find out in what mode the AP currently is */
83 varbinds[0].oid = bridgeOperationalMode;
84 varbinds[0].len_oid = sizeof(bridgeOperationalMode);
85 varbinds[0].value = bridgeOperationalMode;
86 varbinds[0].len_val = 0;
87 varbinds[0].type = NULL_VALUE;
89 if (snmp(varbinds, 1, GET) <= 0) {
90 print_helperr(ERR_RET);
94 /* for AP in AP-Client mode & without VERNET firmware, disable status */
95 if (*(varbinds[0].value) == 3 && !IS_ATMEL12350_VERNET) {
96 mvwaddstr(main_sub, 3, 1, _("AP is currently in AP Client Mode => "
97 "no associated STAtions."));
105 wattrset(main_sub, COLOR_PAIR(3));
106 if (IS_ATMEL12350_VERNET)
107 mvwaddstr(main_sub, 0, 0, STAS_HEADER_VERNET);
109 mvwaddstr(main_sub, 0, 0, STAS_HEADER);
110 wattrset(main_sub, A_NORMAL);
113 /* find out how many STAtions is in the list */
114 varbinds[0].oid = StasNum;
115 varbinds[0].len_oid = sizeof(StasNum);
116 varbinds[0].value = StasNum;
117 varbinds[0].type = NULL_VALUE;
118 varbinds[0].len_val = 0;
120 print_help(WAIT_RET);
122 if (snmp(varbinds, 1, GET) <= 0) {
123 print_helperr(ERR_RET);
128 total_mac = *(varbinds[0].value);
129 print_help(WAIT_SET);
131 while (mac_idx <= total_mac) {
133 /* tell the AP we want first mac_idx-th MAC */
134 varbinds[0].oid = StasMac;
135 varbinds[0].len_oid = sizeof(StasMac);
136 varbinds[0].type = INT_VALUE;
137 get.Num = swap2(mac_idx);
138 varbinds[0].value = (char *) &get;
139 varbinds[0].len_val = sizeof(get);
141 if (snmp(varbinds, 1, SET) <= 0) {
142 print_helperr(ERR_RET);
147 if (varbinds[0].len_val == 24) {
151 (struct AssociatedSTAsInfo *) malloc(varbinds[0].len_val);
152 memcpy(mac, varbinds[0].value, varbinds[0].len_val);
153 /* mac = (struct AssociatedSTAsInfo *) varbinds[0].value; */
155 print_helperr(_("AssociatedSTAsInfo packet error"));
161 (struct MacListStat *) malloc(sizeof(struct MacListStat));
165 (struct MacListStat *) malloc(sizeof(struct MacListStat));
169 memcpy(curr->addr, mac->MacAddress, 6);
171 if (IS_ATMEL12350_VERNET) {
172 curr->Status = mac->Status;
173 curr->Port = mac->Port;
174 memcpy(curr->ParentMacAddress, mac->ParentMacAddress, 6);
175 curr->rssi = mac->RSSI;
176 memcpy(&(curr->IP.s_addr), mac->IP, 4);
184 end = (MAX_LINES < mac_idx) ? MAX_LINES : mac_idx;
186 if (IS_ATMEL12350_VERNET)
187 print_help(_("Arrows - scroll; S - save to file; Q - return; "
188 "T - toggle view; Other key - refresh"));
190 print_help(_("Arrows - scroll; S - save to file; Q - return; "
191 "Other key - refresh"));
194 sprintf(message, "%s: %d", STAS, total_mac);
195 print_title(message);
197 if (IS_ATMEL12350_VERNET) {
198 print_viewtype_rssi();
199 scroll_rows(first, begin, end, 1, 3);
201 scroll_rows(first, begin, end, 1, 0);
206 save_Stations(first);
227 if (IS_ATMEL12350_VERNET) {
229 if (sts_viewtype == 3)
234 while ((curr = first)) {
244 while ((curr = first)) {
254 unsigned char Mac[] = {
255 0x2b, 0x06, 0x01, 0x04, 0x01, 0x87, 0x29, 0x03, 0x01, 0x03, 0x01,
256 0x02, 0x01, 0x02, 0x80, 0x00 };
257 unsigned char Quality[] = {
258 0x2b, 0x06, 0x01, 0x04, 0x01, 0x87, 0x29, 0x03, 0x01, 0x03, 0x01,
259 0x02, 0x01, 0x03, 0x80, 0x00 };
260 unsigned char Age[] = {
261 0x2b, 0x06, 0x01, 0x04, 0x01, 0x87, 0x29, 0x03, 0x01, 0x03, 0x01,
262 0x02, 0x01, 0x04, 0x80, 0x00 };
263 unsigned char RSSI[] = {
264 0x2b, 0x06, 0x01, 0x04, 0x01, 0x87, 0x29, 0x03, 0x01, 0x03, 0x01,
265 0x02, 0x01, 0x05, 0x80, 0x00 };
267 struct MacListStat *first = NULL, *curr = NULL;
268 char null[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, message[1024];
269 int mac_idx, begin, end;
271 unsigned char next_num;
275 print_title(_("Associated stations"));
276 mvwaddstr(main_sub, 0, 3,
277 _("Id MAC address Quality Age RSSI"));
279 print_help(WAIT_RET);
281 varbinds[0].oid = Mac;
282 varbinds[0].len_oid = sizeof(Mac);
283 varbinds[0].len_val = 0;
284 varbinds[0].type = NULL_VALUE;
285 if (snmp(varbinds, 1, GET_NEXT) <= 0) {
286 print_helperr(ERR_RET);
289 next_num = varbinds[0].oid[varbinds[0].len_oid - 1];
291 while (memcmp(varbinds[0].oid, Mac, sizeof(Mac) - 2) == 0) {
293 Mac[sizeof(Mac) - 1] = next_num;
294 Quality[sizeof(Mac) - 1] = next_num;
295 Age[sizeof(Mac) - 1] = next_num;
296 RSSI[sizeof(Mac) - 1] = next_num;
298 if(sizeof(Mac) == varbinds[0].len_oid) {
299 Mac[sizeof(Mac) - 2] = varbinds[0].oid[varbinds[0].len_oid - 2];
300 Quality[sizeof(Mac) - 2] = varbinds[0].oid[varbinds[0].len_oid - 2];
301 Age[sizeof(Mac) - 2] = varbinds[0].oid[varbinds[0].len_oid - 2];
302 RSSI[sizeof(Mac) - 2] = varbinds[0].oid[varbinds[0].len_oid - 2];
305 varbinds[0].oid = Mac;
306 varbinds[0].len_oid = sizeof(Mac);
307 varbinds[0].len_val = 0;
308 varbinds[0].type = NULL_VALUE;
309 varbinds[1].oid = Quality;
310 varbinds[1].len_oid = sizeof(Quality);
311 varbinds[1].len_val = 0;
312 varbinds[1].type = NULL_VALUE;
313 varbinds[2].oid = Age;
314 varbinds[2].len_oid = sizeof(Age);
315 varbinds[2].len_val = 0;
316 varbinds[2].type = NULL_VALUE;
317 varbinds[3].oid = RSSI;
318 varbinds[3].len_oid = sizeof(RSSI);
319 varbinds[3].len_val = 0;
320 varbinds[3].type = NULL_VALUE;
321 if (snmp(varbinds, 4, GET) <= 0) {
322 print_helperr(ERR_RET);
327 if (memcmp(null, varbinds[0].value, 6)) {
330 (struct MacListStat *)
331 malloc(sizeof(struct MacListStat));
335 (struct MacListStat *)
336 malloc(sizeof(struct MacListStat));
339 memcpy(curr->addr, varbinds[0].value, 6);
340 curr->quality = *varbinds[1].value;
341 curr->idle = *varbinds[2].value;
342 curr->rssi = *varbinds[3].value;
347 varbinds[0].oid = Mac;
348 varbinds[0].len_oid = sizeof(Mac);
349 varbinds[0].len_val = 0;
350 varbinds[0].type = NULL_VALUE;
351 if (snmp(varbinds, 1, GET_NEXT) <= 0) {
352 print_helperr(ERR_RET);
355 next_num = varbinds[0].oid[varbinds[0].len_oid - 1];
358 sprintf(message, "%s: %d", _("Associated stations"), mac_idx);
359 print_title(message);
362 end = (MAX_LINES < mac_idx+1) ? MAX_LINES : mac_idx+1;
363 scroll_rows(first, begin, end, 1, 1);
364 print_help(_("Arrows - scroll; S - save to file; Q - quit to menu."));
369 save_Stations(first);
373 if (end < mac_idx+1) {
376 scroll_rows(first, begin, end, 1, 1);
384 scroll_rows(first, begin, end, 1, 1);
398 while ((curr = first)) {