1/*- 2 * Copyright (c) 2005 3 * Bill Paul <wpaul@windriver.com>. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 17 unchanged lines hidden (view full) --- 26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 30 * THE POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33#include <sys/cdefs.h> |
34__FBSDID("$FreeBSD: head/usr.sbin/wpa/ndis_events/ndis_events.c 151223 2005-10-10 20:40:28Z wpaul $"); |
35 36/* 37 * This program simulates the behavior of the ndis_events utility 38 * supplied with wpa_supplicant for Windows. The original utility 39 * is designed to translate Windows WMI events. We don't have WMI, 40 * but we need to supply certain event info to wpa_supplicant in 41 * order to make WPA2 work correctly, so we fake up the interface. 42 */ --- 20 unchanged lines hidden (view full) --- 63#include <stdlib.h> 64#include <unistd.h> 65#include <err.h> 66#include <syslog.h> 67#include <stdarg.h> 68 69static int verbose = 0; 70static int debug = 0; |
71static int all_events = 0; |
72 73#define PROGNAME "ndis_events" 74 75#define WPA_SUPPLICANT_PORT 9876 76#define NDIS_INDICATION_LEN 2048 77 78#define EVENT_CONNECT 0 79#define EVENT_DISCONNECT 1 --- 105 unchanged lines hidden (view full) --- 185 e = (struct ndis_evt *)indication; 186 e->ne_len = NDIS_INDICATION_LEN - sizeof(struct ndis_evt); 187 188 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); 189 ifr.ifr_data = indication; 190 191 if (ioctl(s, SIOCGPRIVATE_0, &ifr) < 0) { 192 close(s); |
193 dbgmsg("failed to read event info from %s: %d", ifname, errno); |
194 return; 195 } 196 197 if (e->ne_sts == NDIS_STATUS_MEDIA_CONNECT) { 198 type = EVENT_CONNECT; 199 if (verbose) 200 dbgmsg("Received a connect event for %s", ifname); |
201 if (!all_events) 202 return; |
203 } 204 if (e->ne_sts == NDIS_STATUS_MEDIA_DISCONNECT) { 205 type = EVENT_DISCONNECT; 206 if (verbose) 207 dbgmsg("Received a disconnect event for %s", ifname); |
208 if (!all_events) 209 return; |
210 } 211 if (e->ne_sts == NDIS_STATUS_MEDIA_SPECIFIC_INDICATION) { 212 type = EVENT_MEDIA_SPECIFIC; 213 if (verbose) 214 dbgmsg("Received a media-specific event for %s", 215 ifname); 216 } 217 --- 26 unchanged lines hidden (view full) --- 244 close(s); 245 return; 246} 247 248static void 249usage(progname) 250 char *progname; 251{ |
252 fprintf(stderr, "Usage: ndis_events [-a] [-d] [-v]\n", progname); |
253 exit(1); 254} 255 256int 257main(argc, argv) 258 int argc; 259 char *argv[]; 260{ 261 int s, r, n; 262 struct sockaddr_in sin; 263 char msg[NDIS_INDICATION_LEN]; 264 struct rt_msghdr *rtm; 265 struct if_msghdr *ifm; 266 char ifname[IFNAMSIZ]; 267 int ch; 268 |
269 while ((ch = getopt(argc, argv, "dva")) != -1) { |
270 switch(ch) { 271 case 'd': 272 debug++; 273 break; 274 case 'v': 275 verbose++; 276 break; |
277 case 'a': 278 all_events++; 279 break; |
280 default: 281 usage(PROGNAME); 282 break; 283 } 284 } 285 286 if (!debug && daemon(0, 0)) 287 err(1, "failed to daemonize ourselves"); --- 51 unchanged lines hidden --- |