OpenWrt – Blame information for rev 4

Subversion Repositories:
Rev:
Rev Author Line No. Line
4 office 1 --- a/Makefile
2 +++ b/Makefile
3 @@ -14,6 +14,10 @@ IWINFO_CLI = iwinfo
4 IWINFO_CLI_LDFLAGS = $(LDFLAGS) -L. -liwinfo
5 IWINFO_CLI_OBJ = iwinfo_cli.o
6  
7 +ifneq ($(filter rt,$(IWINFO_BACKENDS)),)
8 + IWINFO_CFLAGS += -DUSE_RTWIFI
9 + IWINFO_LIB_OBJ += iwinfo_rt_scan.o
10 +endif
11  
12 ifneq ($(filter wl,$(IWINFO_BACKENDS)),)
13 IWINFO_CFLAGS += -DUSE_WL
14 --- a/iwinfo_cli.c
15 +++ b/iwinfo_cli.c
16 @@ -111,7 +111,11 @@ static char * format_signal(int sig)
17 if (!sig)
18 snprintf(buf, sizeof(buf), "unknown");
19 else
20 +#ifdef USE_RTWIFI
21 + snprintf(buf, sizeof(buf), "%d %", sig);
22 +#else
23 snprintf(buf, sizeof(buf), "%d dBm", sig);
24 +#endif
25  
26 return buf;
27 }
28 @@ -600,7 +604,11 @@ static void print_scanlist(const struct
29 IWINFO_OPMODE_NAMES[e->mode],
30 format_channel(e->channel));
31 printf(" Signal: %s Quality: %s/%s\n",
32 +#ifdef USE_RTWIFI
33 + format_signal(e->signal),
34 +#else
35 format_signal(e->signal - 0x100),
36 +#endif
37 format_quality(e->quality),
38 format_quality_max(e->quality_max));
39 printf(" Encryption: %s\n\n",
40 --- /dev/null
41 +++ b/iwinfo_rt_scan.c
42 @@ -0,0 +1,157 @@
43 +#include "iwinfo.h"
44 +#include "iwinfo_wext.h"
45 +
46 +struct survey_table
47 +{
48 + char channel[4];
49 + char ssid[33];
50 + char len[4];
51 + char bssid[20];
52 + char security[23];
53 + char *crypto;
54 + char signal[9];
55 +};
56 +
57 +struct survey_table st[64];
58 +int survey_count = 0;
59 +
60 +#define RTPRIV_IOCTL_SET (SIOCIWFIRSTPRIV + 0x02)
61 +void iwpriv(const char *name, const char *key, const char *val)
62 +{
63 + int socket_id;
64 + struct iwreq wrq;
65 + char data[64];
66 + snprintf(data, 64, "%s=%s", key, val);
67 + socket_id = socket(AF_INET, SOCK_DGRAM, 0);
68 + strcpy(wrq.ifr_ifrn.ifrn_name, name);
69 + wrq.u.data.length = strlen(data);
70 + wrq.u.data.pointer = data;
71 + wrq.u.data.flags = 0;
72 + ioctl(socket_id, RTPRIV_IOCTL_SET, &wrq);
73 + close(socket_id);
74 +}
75 +
76 +static void next_field(char **line, char *output, int n) {
77 + char *l = *line;
78 + int i;
79 +
80 + memcpy(output, *line, n);
81 + *line = &l[n];
82 +
83 + for (i = n - 1; i > 0; i--) {
84 + if (output[i] != ' ')
85 + break;
86 + output[i] = '\0';
87 + }
88 +}
89 +
90 +#define RTPRIV_IOCTL_GSITESURVEY (SIOCIWFIRSTPRIV + 0x0D)
91 +void wifi_site_survey(const char *ifname, char* essid, int print)
92 +{
93 + char *s = malloc(IW_SCAN_MAX_DATA);
94 + int ret;
95 + int socket_id;
96 + struct iwreq wrq;
97 + char *line, *start;
98 + iwpriv(ifname, "SiteSurvey", (essid ? essid : ""));
99 + sleep(5);
100 + memset(s, 0x00, IW_SCAN_MAX_DATA);
101 + strcpy(wrq.ifr_name, ifname);
102 + wrq.u.data.length = IW_SCAN_MAX_DATA;
103 + wrq.u.data.pointer = s;
104 + wrq.u.data.flags = 0;
105 + socket_id = socket(AF_INET, SOCK_DGRAM, 0);
106 + ret = ioctl(socket_id, RTPRIV_IOCTL_GSITESURVEY, &wrq);
107 + close(socket_id);
108 + if(ret != 0)
109 + goto out;
110 + if(wrq.u.data.length < 1)
111 + goto out;
112 + /* ioctl result starts with a newline, for some reason */
113 + start = s;
114 + while (*start == '\n')
115 + start++;
116 + line = strtok((char *)start, "\n");
117 + line = strtok(NULL, "\n");
118 + survey_count = 0;
119 + while(line && (survey_count < 64)) {
120 + memset(&st[survey_count], 0, sizeof(st[survey_count]));
121 +
122 + next_field(&line, st[survey_count].channel, sizeof(st->channel));
123 + next_field(&line, st[survey_count].ssid, sizeof(st->ssid));
124 + next_field(&line, st[survey_count].len, sizeof(st->len));
125 + next_field(&line, st[survey_count].bssid, sizeof(st->bssid));
126 + next_field(&line, st[survey_count].security, sizeof(st->security));
127 + st[survey_count].crypto = strstr(st[survey_count].security, "/");
128 + if (st[survey_count].crypto) {
129 + *st[survey_count].crypto = '\0';
130 + st[survey_count].crypto++;
131 + if (print) printf("%s|%s|%s|%s\n",
132 + st[survey_count].channel, st[survey_count].ssid, st[survey_count].bssid, st[survey_count].security);
133 + }
134 + next_field(&line, st[survey_count].signal, sizeof(st->signal));
135 + line = strtok(NULL, "\n");
136 +
137 + /* skip hidden ssid */
138 + if (!strcmp(st[survey_count].len, "0")) {
139 + continue;
140 + }
141 + survey_count++;
142 + }
143 + if (survey_count == 0 && !print)
144 + printf("No results");
145 +out:
146 + free(s);
147 +}
148 +
149 +/*struct survey_table
150 +{
151 + char channel[4];
152 + char ssid[33];
153 + char bssid[20];
154 + char security[23];
155 + char *crypto;
156 +};
157 +*/
158 +
159 +int rt_get_scanlist(const char *ifname, char *buf, int *len)
160 +{
161 + struct iwinfo_scanlist_entry *e = (struct iwinfo_scanlist_entry *) buf;
162 + int i = 0;
163 +
164 + survey_count = 0;
165 +
166 + wifi_site_survey(ifname, NULL, 0);
167 +
168 + for (i = 0; i < survey_count; i++) {
169 + int j;
170 + for (j = 0; j < 6; j++) {
171 + e[i].mac[j] = (uint8_t) strtoul(&st[i].bssid[j * 3], NULL, 16);
172 + }
173 + strcpy(e[i].ssid, st[i].ssid);
174 + e[i].channel = atoi(st[i].channel);
175 + e[i].mode = IWINFO_OPMODE_MASTER;
176 + e[i].signal = atoi(st[i].signal);
177 + e[i].quality = atoi(st[i].signal);
178 + e[i].quality_max = 100;
179 + memset(&e[i].crypto, 0, sizeof(struct iwinfo_crypto_entry));
180 + if (strstr(st[i].security, "WPA")) {
181 + e[i].crypto.enabled = 1;
182 + e[i].crypto.auth_suites |= IWINFO_KMGMT_PSK;
183 + }
184 + if (!st[i].crypto)
185 + continue;
186 + if (strstr(st[i].crypto, "TKIP"))
187 + e[i].crypto.group_ciphers |= IWINFO_CIPHER_TKIP;
188 + if (strstr(st[i].crypto, "AES"))
189 + e[i].crypto.group_ciphers |= IWINFO_CIPHER_AESOCB;
190 + if (strstr(st[i].security, "WPA2"))
191 + e[i].crypto.wpa_version = 2;
192 + else if (strstr(st[i].security, "WPA"))
193 + e[i].crypto.wpa_version = 1;
194 + }
195 + *len = survey_count * sizeof(struct iwinfo_scanlist_entry);
196 +
197 + return 0;
198 +}
199 +
200 --- a/iwinfo_wext.c
201 +++ b/iwinfo_wext.c
202 @@ -556,7 +556,11 @@ const struct iwinfo_ops wext_ops = {
203 .phyname = wext_get_phyname,
204 .assoclist = wext_get_assoclist,
205 .txpwrlist = wext_get_txpwrlist,
206 +#ifdef USE_RTWIFI
207 + .scanlist = rt_get_scanlist,
208 +#else
209 .scanlist = wext_get_scanlist,
210 +#endif
211 .freqlist = wext_get_freqlist,
212 .countrylist = wext_get_countrylist,
213 .close = wext_close
214 --- a/iwinfo_wext.h
215 +++ b/iwinfo_wext.h
216 @@ -379,4 +379,8 @@ static const unsigned int standard_event
217  
218 int wext_get_scanlist(const char *ifname, char *buf, int *len);
219  
220 +#ifdef USE_RTWIFI
221 +int rt_get_scanlist(const char *ifname, char *buf, int *len);
222 +#endif
223 +
224 #endif