main_winmain.c revision 8d520ff1dc2da35cdca849e982051b86468016d8
1/*
2 * WPA Supplicant / WinMain() function for Windows-based applications
3 * Copyright (c) 2006, Jouni Malinen <j@w1.fi>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 *
9 * Alternatively, this software may be distributed under the terms of BSD
10 * license.
11 *
12 * See README and COPYING for more details.
13 */
14
15#include "includes.h"
16
17#include "common.h"
18#include "wpa_supplicant_i.h"
19
20#ifdef _WIN32_WCE
21#define CMDLINE LPWSTR
22#else /* _WIN32_WCE */
23#define CMDLINE LPSTR
24#endif /* _WIN32_WCE */
25
26
27int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
28		   CMDLINE lpCmdLine, int nShowCmd)
29{
30	int i;
31	struct wpa_interface *ifaces, *iface;
32	int iface_count, exitcode = -1;
33	struct wpa_params params;
34	struct wpa_global *global;
35
36	if (os_program_init())
37		return -1;
38
39	os_memset(&params, 0, sizeof(params));
40	params.wpa_debug_level = MSG_MSGDUMP;
41	params.wpa_debug_file_path = "\\Temp\\wpa_supplicant-log.txt";
42	params.wpa_debug_show_keys = 1;
43
44	iface = ifaces = os_zalloc(sizeof(struct wpa_interface));
45	if (ifaces == NULL)
46		return -1;
47	iface_count = 1;
48
49	iface->confname = "default";
50	iface->driver = "ndis";
51	iface->ifname = "";
52
53	exitcode = 0;
54	global = wpa_supplicant_init(&params);
55	if (global == NULL) {
56		printf("Failed to initialize wpa_supplicant\n");
57		exitcode = -1;
58	}
59
60	for (i = 0; exitcode == 0 && i < iface_count; i++) {
61		if ((ifaces[i].confname == NULL &&
62		     ifaces[i].ctrl_interface == NULL) ||
63		    ifaces[i].ifname == NULL) {
64			if (iface_count == 1 && (params.ctrl_interface ||
65						 params.dbus_ctrl_interface))
66				break;
67			exitcode = -1;
68			break;
69		}
70		if (wpa_supplicant_add_iface(global, &ifaces[i]) == NULL)
71			exitcode = -1;
72	}
73
74	if (exitcode == 0)
75		exitcode = wpa_supplicant_run(global);
76
77	wpa_supplicant_deinit(global);
78
79	os_free(ifaces);
80
81	os_program_deinit();
82
83	return exitcode;
84}
85