1
2#ifndef NOUSB
3/* assoclist.c */
4#include <stdlib.h>
5#include <stdio.h>
6#include <string.h>
7#include <unistd.h>
8#include <sys/types.h>
9#include <sys/ioctl.h>
10#include <sys/socket.h>
11#include <net/if.h>
12#include <error.h>
13#include <httpd.h>
14#include <bcmnvram.h>
15#define	MAXBUF		(8192)
16
17typedef unsigned char	UINT8;
18typedef unsigned short	UINT16;
19typedef unsigned long	UINT32;
20typedef unsigned int	UINT;
21typedef int		INT;
22
23#define WLC_UP	       		0x02
24#define WLC_DOWN		0x03
25#define	WLC_DUMP       		0x06
26#define WLC_GET_RATE   		0x0C
27#define WLC_SET_RATE   		0x0D
28#define WLC_GET_FRAG   		0x0F
29#define WLC_SET_FRAG   		0x10
30#define WLC_GET_RTS		0x11
31#define WLC_SET_RTS		0x12
32#define WLC_GET_INFRA		0x13
33#define WLC_SET_INFRA		0x14
34#define WLC_GET_BSSID  		0x17
35#define WLC_SET_BSSID		0x18
36#define WLC_GET_SSID  		0x19
37#define WLC_SET_SSID		0x1A
38#define WLC_GET_CHANNEL		0x1D
39#define WLC_SET_CHANNEL		0x1E
40#define WLC_GET_SRL    		0x1F
41#define WLC_SET_SRL		0x20
42#define WLC_GET_LRL    		0x21
43#define WLC_SET_LRL    		0x22
44#define WLC_GET_PLCPHDR		0x23
45#define WLC_SET_PLCPHDR		0x24
46#define WLC_GET_RADIO  		0x25
47#define WLC_SET_RADIO		0x26
48
49#define WLC_SCAN  		0x32
50#define WLC_SCANRESULTS		0x33
51
52#define WLC_SET_EVM  		0x3C
53#define WLC_GET_TXPWR		0x41
54#define WLC_SET_TXPWR  		0x42
55
56#define WLC_GET_MACLIST		0x45
57#define WLC_SET_MACLIST		0x46
58#define WLC_GET_RATESET		0x47
59#define WLC_SET_RATESET		0x48
60
61#define WLC_GET_LOCALE		0x49
62#define WLC_SET_LOCALE 		0x4A
63#define WLC_GET_SROM		0x4F
64#define WLC_SET_SROM   		0x50
65
66#define WLC_FREQ_ACCURACY	0x5C
67#define WLC_CARRIER_SUPPRESS	0x5D
68#define WLC_GET_MAC_DENY	0x69
69#define WLC_SET_MAC_DENY	0x6A
70#define WLC_GET_WDSLIST		0x7B
71#define WLC_SET_WDSLIST		0x7C
72#define WLC_GET_LAZYWDS		0x8A
73#define WLC_SET_LAZYWDS		0x8B
74#define WLC_GET_SHORTSLOT	0x90
75#define WLC_GET_SHORTSLOT_OVERRID	0x91
76#define WLC_SET_SHORTSLOT_OVERRID	0x92
77#define WLC_GET_SHORTSLOT_RESTRICT	0x93
78#define WLC_SET_SHORTSLOT_RESTRICT	0x94
79#define WLC_GET_ASSOCLIST	0x9F
80
81#define RTPRIV_IOCTL 		(0x8be0 + 0x01)
82#define RTPRIV_IOCTL_SET 	(0x8be0 + 0x02)
83#define RTLINUX_GET_OID_802_11_QUERY_MAC_TABLE 	8048
84#define RTLINUX_SET_OID_802_11_ACL		8049
85#define RTLINUX_SET_OID_802_11_TEST_MODE        8051
86
87
88#define MAX_LEN_OF_MAC_TABLE 64
89#define ETH_LENGTH_OF_ADDRESS 6
90
91typedef struct
92{
93	UINT8 Addr[ETH_LENGTH_OF_ADDRESS];
94	UINT8 Aid;
95	UINT8 Psm;
96} MACENTRY;
97
98typedef struct
99{
100	UINT32 num;
101	MACENTRY mac[MAX_LEN_OF_MAC_TABLE];
102} RT_802_11_MAC_TABLE;
103
104/*================================================================*/
105/* Local Types */
106
107typedef struct wl_ioctl
108{
109	UINT8	*buf;
110	UINT16	len;
111	UINT16  flag;
112} wl_ioctl_t;
113
114static int	wl_ioctl_nobr(UINT8 *name, int cmd, void *buf, int len );
115
116int ej_wl_status_nobr(int eid, webs_t wp, int argc, char_t **argv)
117{
118	char		*devname;
119	int		result;
120	int		cmd;
121	UINT8		buf[MAXBUF];
122	INT		*bufint;
123	int unit;
124	char tmp[100], prefix[] = "wlXXXXXXXXXX_";
125	char *name;
126	struct maclist *auth, *assoc, *authorized;
127	int max_sta_count, maclist_size;
128	int i, j, ret, val;
129	int channel;
130
131	channel = atoi(nvram_safe_get("wl_channel"));
132
133	if ((unit = atoi(nvram_safe_get("wl_unit"))) < 0)
134		return -1;
135
136	snprintf(prefix, sizeof(prefix), "wl%d_", unit);
137	name = nvram_safe_get(strcat_r(prefix, "ifname", tmp));
138
139	if (nvram_match(strcat_r(prefix, "mode", tmp), "ap"))
140	{
141		if (nvram_match("wl_lazywds", "1") ||
142			nvram_match("wl_wdsapply_x", "1"))
143			ret+=websWrite(wp, "Mode	: Hybrid\n");
144		else    ret+=websWrite(wp, "Mode	: AP Only\n");
145
146		ret+=websWrite(wp, "Channel	: %d\n", channel);
147
148	}
149	else if (nvram_match(strcat_r(prefix, "mode", tmp), "wds"))
150	{
151		ret+=websWrite(wp, "Mode	: WDS Only\n");
152		ret+=websWrite(wp, "Channel	: %d\n", channel);
153	}
154
155	devname = "ra0";
156
157	cmd = RTLINUX_GET_OID_802_11_QUERY_MAC_TABLE;
158
159
160	websWrite(wp, "\n");
161	websWrite(wp, "Stations List                           \n");
162	websWrite(wp, "----------------------------------------\n");
163
164	if ( (result = wl_ioctl_nobr(devname, cmd, buf, sizeof(RT_802_11_MAC_TABLE))) != 0 ){
165		//fprintf(stderr, "Fail: cmd=0x%02x (%d)\n", cmd, result);
166		//websWrite(wp, "Fail: cmd=0x%02x (%d)\n", cmd, result);
167	}
168	else if ( cmd == RTLINUX_GET_OID_802_11_QUERY_MAC_TABLE )
169	{
170		RT_802_11_MAC_TABLE  *mactable;
171		int j;
172
173		mactable = (RT_802_11_MAC_TABLE *)buf;
174
175		//websWrite(wp, "mac number: %x\n", mactable->num);
176
177		for ( i=0; i< mactable->num; i++ )
178		{
179			for(j=0;j<6;j++)
180			{
181				websWrite(wp, "%02x", mactable->mac[i].Addr[j]);
182				if ( (j % 6)==5 )
183					websWrite(wp, "\n");
184				else
185					websWrite(wp, ":");
186			}
187		}
188	}
189	return result;
190}
191
192/*----------------------------------------------------------------
193* wl_ioctl
194*
195* TODO: describe
196*
197* Arguments:
198*
199* Returns:
200*       0       - success
201*       ~0      - failure
202----------------------------------------------------------------*/
203int wl_ioctl_nobr( UINT8 *name, int cmd, void *buf, int len )
204{
205	struct ifreq	ifr;
206	wl_ioctl_t	*ioc;
207	int		ret = 0;
208	int 		s;
209
210	if ( (s = socket(AF_INET, SOCK_DGRAM, 0)) < 0 ) {
211		perror("socket");
212		return 1;
213	}
214
215	ioc = (wl_ioctl_t *)&(ifr.ifr_data);
216	ioc->buf = buf;
217	ioc->len = len;
218	ioc->flag = cmd;
219
220	strncpy(ifr.ifr_name, name, IFNAMSIZ);
221	//ifr.ifr_data = (caddr_t) &ioc;
222	if ( (ret = ioctl(s, RTPRIV_IOCTL, &ifr)) < 0 ) {
223		perror(ifr.ifr_name);
224	}
225	close(s);
226
227	//printf("ioctl %d : %x\n", ioc->len, ioc->buf);
228//%x %x %x %x\n", ioc->len, (unsigned char)ioc->buf[0],(unsigned char)ioc->buf[1], (unsigned char)ioc->buf[2], (unsigned char)ioc->buf[3]);
229	return ret;
230}
231#endif
232
233
234