File: stations.c

package info (click to toggle)
ap-utils 1.5-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 2,752 kB
  • sloc: ansic: 22,708; sh: 3,973; yacc: 316; makefile: 310
file content (199 lines) | stat: -rw-r--r-- 5,066 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
/*
 *      stations.c from Access Point SNMP Utils for Linux
 *
 * Copyright (c) 2002 Roman Festchook <roma at polesye dot net>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License Version 2 from
 * June 1991 as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 */
#include <sys/wait.h>
#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>
#include <signal.h>
#include <string.h>
#include "ap-utils.h"

#define MAX_LINES LINES-4

extern int LINES;
extern WINDOW *main_sub;
extern short ap_type;

void atmel_stations()
{
    char StasNum[] = {
	0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x02, 0x05, 0x01, 0x00
    };
    char StasMac[] = {
	0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x02, 0x05, 0x02, 0x00
    };
    char bridgeOperationalMode[] = {
         0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x04, 0x01, 0x00
    };
    
    struct AssociatedSTAsInfo {
	unsigned short Num;
	unsigned char MacAddress[6];
	unsigned char Status;
	unsigned char Port;
	unsigned char ParentMacAddress[6];
	unsigned char RSSI;
	unsigned char LinkQuality;
	unsigned char IP[4];
	unsigned char Reserved[2];
    } *mac = NULL, get;

    struct MacListStat *first = NULL, *curr = NULL;
    char message[1024];
    int mac_num, begin, end, total_mac;
    varbind varbinds[1];

    print_top(NULL, ST_TITLE);

    varbinds[0].oid = bridgeOperationalMode;
    varbinds[0].len_oid = sizeof(bridgeOperationalMode);
    varbinds[0].value = bridgeOperationalMode;
    varbinds[0].len_val = 0;
    varbinds[0].type = NULL_VALUE;
    print_help(WAIT_RET);
    if (snmp(varbinds, 1, GET) <= 0) {
         print_helperr(ERR_RET);
         goto exit;
    }

    if (*(varbinds[0].value) == 3) {
	mvwaddstr(main_sub, 3, 1, _("AP is currently in AP Client Mode => "
	    "no associated STAtions."));
	print_help(ANY_KEY);
	wrefresh(main_sub);
	getch();
	goto exit;
    }

    varbinds[0].oid = StasNum;
    varbinds[0].len_oid = sizeof(StasNum);
    varbinds[0].value = StasNum;
    varbinds[0].type = NULL_VALUE;
    varbinds[0].len_val = 0;
    print_help(WAIT_RET);
    if (snmp(varbinds, 1, GET) <= 0) {
	print_helperr(ERR_RET);
	getch();
	goto exit;
    }

    total_mac = *(varbinds[0].value);
    mac_num = 1;

    sprintf(message, "%s: %d", ST_TITLE, total_mac);
    print_top(NULL, message);
    wattrset(main_sub, COLOR_PAIR(13));
    mvwaddstr(main_sub, 0, 0,
	_("  #     MAC       Parent MAC  RSSI   LQ Sts MACn      IP        "));
    wattrset(main_sub, A_NORMAL);
    noecho();

    while (mac_num <= total_mac) {

	varbinds[0].oid = StasMac;
	varbinds[0].len_oid = sizeof(StasMac);
	varbinds[0].type = INT_VALUE;
	get.Num = swap2(mac_num);
	varbinds[0].value = (char *) &get;
	varbinds[0].len_val = sizeof(get);

	if (snmp(varbinds, 1, SET) <= 0) {
	    print_helperr(ERR_RET);
	    getch();
	    goto exit;
	}

	if (varbinds[0].len_val == 24) {
	    if (mac)
		free(mac);
	    mac =
		(struct AssociatedSTAsInfo *) malloc(varbinds[0].len_val);
	    memcpy(mac, varbinds[0].value, varbinds[0].len_val);
/*	    mac = (struct AssociatedSTAsInfo *) varbinds[0].value;*/
	} else {
	    print_helperr(_("AssociatedSTAsInfo packet error"));
	    goto exit;
	}


	if (first == NULL) {
	    first =
		(struct MacListStat *) malloc(sizeof(struct MacListStat));
	    curr = first;
	} else {
	    curr->next =
		(struct MacListStat *) malloc(sizeof(struct MacListStat));
	    curr = curr->next;
	}

	memcpy(curr->addr, mac->MacAddress, 6);
//	memcpy(curr->ParentMacAddress, mac->ParentMacAddress, 6);
	memcpy(&(curr->IP.s_addr), mac->IP, 4);
	curr->quality = 100 - (minimum(mac->LinkQuality, 40)*2.5);
//	curr->rssi = - 96 + mac->RSSI;
//	curr->quality = mac->LinkQuality;
	curr->rssi = mac->RSSI;
	
	curr->Port = mac->Port;
	curr->Status = mac->Status;
	curr->next = NULL;
	mac_num++;
    }
    begin = 1;
    end = (mac_num > MAX_LINES) ? MAX_LINES : mac_num;
    scroll_rows(first, begin, end, 1, 2);
    while (1) {
	print_help(_("Arrows - scroll; S - save to file; Q - quit to menu."));
	switch (getch()) {
	case 'S':
	case 's':
	    save_Stations(first);
	    continue;
	case KEY_RIGHT:
	case KEY_DOWN:
	    if (end < mac_num) {
		begin++;
		end++;
		scroll_rows(first, begin, end, 1, 2);
	    }
	    continue;
	case KEY_UP:
	case KEY_LEFT:
	    if (begin > 1) {
		begin--;
		end--;
		scroll_rows(first, begin, end, 1, 2);
	    }
	    continue;
	case 'Q':
	case 'q':
	    goto exit;
	}
    }

  exit:
    while ((curr = first) != 0) {
	first = curr->next;
	free(curr);
    }
    print_top(NULL, NULL);
    clear_main(0);
}