00001 /* 00002 * WPA Supplicant / WinMain() function for Windows-based applications 00003 * Copyright (c) 2006, Jouni Malinen <j@w1.fi> 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License version 2 as 00007 * published by the Free Software Foundation. 00008 * 00009 * Alternatively, this software may be distributed under the terms of BSD 00010 * license. 00011 * 00012 * See README and COPYING for more details. 00013 */ 00014 00015 #include "includes.h" 00016 00017 #include "common.h" 00018 #include "wpa_supplicant_i.h" 00019 00020 #ifdef _WIN32_WCE 00021 #define CMDLINE LPWSTR 00022 #else /* _WIN32_WCE */ 00023 #define CMDLINE LPSTR 00024 #endif /* _WIN32_WCE */ 00025 00026 00027 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, 00028 CMDLINE lpCmdLine, int nShowCmd) 00029 { 00030 int i; 00031 struct wpa_interface *ifaces, *iface; 00032 int iface_count, exitcode = -1; 00033 struct wpa_params params; 00034 struct wpa_global *global; 00035 00036 if (os_program_init()) 00037 return -1; 00038 00039 os_memset(¶ms, 0, sizeof(params)); 00040 params.wpa_debug_level = MSG_MSGDUMP; 00041 params.wpa_debug_file_path = "\\Temp\\wpa_supplicant-log.txt"; 00042 params.wpa_debug_show_keys = 1; 00043 00044 iface = ifaces = os_zalloc(sizeof(struct wpa_interface)); 00045 if (ifaces == NULL) 00046 return -1; 00047 iface_count = 1; 00048 00049 iface->confname = "default"; 00050 iface->driver = "ndis"; 00051 iface->ifname = ""; 00052 00053 exitcode = 0; 00054 global = wpa_supplicant_init(¶ms); 00055 if (global == NULL) { 00056 printf("Failed to initialize wpa_supplicant\n"); 00057 exitcode = -1; 00058 } 00059 00060 for (i = 0; exitcode == 0 && i < iface_count; i++) { 00061 if ((ifaces[i].confname == NULL && 00062 ifaces[i].ctrl_interface == NULL) || 00063 ifaces[i].ifname == NULL) { 00064 if (iface_count == 1 && (params.ctrl_interface || 00065 params.dbus_ctrl_interface)) 00066 break; 00067 exitcode = -1; 00068 break; 00069 } 00070 if (wpa_supplicant_add_iface(global, &ifaces[i]) == NULL) 00071 exitcode = -1; 00072 } 00073 00074 if (exitcode == 0) 00075 exitcode = wpa_supplicant_run(global); 00076 00077 wpa_supplicant_deinit(global); 00078 00079 os_free(ifaces); 00080 00081 os_program_deinit(); 00082 00083 return exitcode; 00084 }