ndis_events.c (151214) | ndis_events.c (151223) |
---|---|
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> | 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 151214 2005-10-10 17:51:12Z wpaul $"); | 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; | 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; |
|
71 72#define PROGNAME "ndis_events" 73 74#define WPA_SUPPLICANT_PORT 9876 75#define NDIS_INDICATION_LEN 2048 76 77#define EVENT_CONNECT 0 78#define EVENT_DISCONNECT 1 --- 105 unchanged lines hidden (view full) --- 184 e = (struct ndis_evt *)indication; 185 e->ne_len = NDIS_INDICATION_LEN - sizeof(struct ndis_evt); 186 187 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); 188 ifr.ifr_data = indication; 189 190 if (ioctl(s, SIOCGPRIVATE_0, &ifr) < 0) { 191 close(s); | 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); |
192 dbgmsg("failed to read event info from %s\n", ifname); | 193 dbgmsg("failed to read event info from %s: %d", ifname, errno); |
193 return; 194 } 195 196 if (e->ne_sts == NDIS_STATUS_MEDIA_CONNECT) { 197 type = EVENT_CONNECT; 198 if (verbose) 199 dbgmsg("Received a connect event for %s", ifname); | 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; |
|
200 } 201 if (e->ne_sts == NDIS_STATUS_MEDIA_DISCONNECT) { 202 type = EVENT_DISCONNECT; 203 if (verbose) 204 dbgmsg("Received a disconnect event for %s", ifname); | 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; |
|
205 } 206 if (e->ne_sts == NDIS_STATUS_MEDIA_SPECIFIC_INDICATION) { 207 type = EVENT_MEDIA_SPECIFIC; 208 if (verbose) 209 dbgmsg("Received a media-specific event for %s", 210 ifname); 211 } 212 --- 26 unchanged lines hidden (view full) --- 239 close(s); 240 return; 241} 242 243static void 244usage(progname) 245 char *progname; 246{ | 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{ |
247 fprintf(stderr, "Usage: ndis_events [-d] [-v]\n", progname); | 252 fprintf(stderr, "Usage: ndis_events [-a] [-d] [-v]\n", progname); |
248 exit(1); 249} 250 251int 252main(argc, argv) 253 int argc; 254 char *argv[]; 255{ 256 int s, r, n; 257 struct sockaddr_in sin; 258 char msg[NDIS_INDICATION_LEN]; 259 struct rt_msghdr *rtm; 260 struct if_msghdr *ifm; 261 char ifname[IFNAMSIZ]; 262 int ch; 263 | 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 |
264 while ((ch = getopt(argc, argv, "dv")) != -1) { | 269 while ((ch = getopt(argc, argv, "dva")) != -1) { |
265 switch(ch) { 266 case 'd': 267 debug++; 268 break; 269 case 'v': 270 verbose++; 271 break; | 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; |
|
272 default: 273 usage(PROGNAME); 274 break; 275 } 276 } 277 278 if (!debug && daemon(0, 0)) 279 err(1, "failed to daemonize ourselves"); --- 51 unchanged lines hidden --- | 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 --- |