1526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt/* 2526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * WPA Supplicant / WinMain() function for Windows-based applications 3526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * Copyright (c) 2006, Jouni Malinen <j@w1.fi> 4526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * 5526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * This program is free software; you can redistribute it and/or modify 6526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * it under the terms of the GNU General Public License version 2 as 7526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * published by the Free Software Foundation. 8526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * 9526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * Alternatively, this software may be distributed under the terms of BSD 10526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * license. 11526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * 12526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * See README and COPYING for more details. 13526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt */ 14526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt 15526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt#include "includes.h" 16526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt 17526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt#include "common.h" 18526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt#include "wpa_supplicant_i.h" 19526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt 20526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt#ifdef _WIN32_WCE 21526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt#define CMDLINE LPWSTR 22526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt#else /* _WIN32_WCE */ 23526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt#define CMDLINE LPSTR 24526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt#endif /* _WIN32_WCE */ 25526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt 26526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt 27526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidtint WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, 28526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt CMDLINE lpCmdLine, int nShowCmd) 29526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt{ 30526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt int i; 31526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt struct wpa_interface *ifaces, *iface; 32526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt int iface_count, exitcode = -1; 33526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt struct wpa_params params; 34526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt struct wpa_global *global; 35526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt 36526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt if (os_program_init()) 37526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt return -1; 38526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt 39526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt os_memset(¶ms, 0, sizeof(params)); 40526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt params.wpa_debug_level = MSG_MSGDUMP; 41526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt params.wpa_debug_file_path = "\\Temp\\wpa_supplicant-log.txt"; 42526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt params.wpa_debug_show_keys = 1; 43526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt 44526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt iface = ifaces = os_zalloc(sizeof(struct wpa_interface)); 45526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt if (ifaces == NULL) 46526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt return -1; 47526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt iface_count = 1; 48526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt 49526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt iface->confname = "default"; 50526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt iface->driver = "ndis"; 51526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt iface->ifname = ""; 52526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt 53526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt exitcode = 0; 54526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt global = wpa_supplicant_init(¶ms); 55526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt if (global == NULL) { 56526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt printf("Failed to initialize wpa_supplicant\n"); 57526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt exitcode = -1; 58526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt } 59526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt 60526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt for (i = 0; exitcode == 0 && i < iface_count; i++) { 61526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt if ((ifaces[i].confname == NULL && 62526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt ifaces[i].ctrl_interface == NULL) || 63526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt ifaces[i].ifname == NULL) { 64526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt if (iface_count == 1 && (params.ctrl_interface || 65526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt params.dbus_ctrl_interface)) 66526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt break; 67526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt exitcode = -1; 68526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt break; 69526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt } 70526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt if (wpa_supplicant_add_iface(global, &ifaces[i]) == NULL) 71526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt exitcode = -1; 72526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt } 73526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt 74526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt if (exitcode == 0) 75526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt exitcode = wpa_supplicant_run(global); 76526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt 77526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt wpa_supplicant_deinit(global); 78526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt 79526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt os_free(ifaces); 80526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt 81526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt os_program_deinit(); 82526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt 83526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt return exitcode; 84526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt} 85