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