main_winmain.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. #include "includes.h"
  9. #include "common.h"
  10. #include "wpa_supplicant_i.h"
  11. #ifdef _WIN32_WCE
  12. #define CMDLINE LPWSTR
  13. #else /* _WIN32_WCE */
  14. #define CMDLINE LPSTR
  15. #endif /* _WIN32_WCE */
  16. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
  17. CMDLINE lpCmdLine, int nShowCmd)
  18. {
  19. int i;
  20. struct wpa_interface *ifaces, *iface;
  21. int iface_count, exitcode = -1;
  22. struct wpa_params params;
  23. struct wpa_global *global;
  24. if (os_program_init())
  25. return -1;
  26. os_memset(&params, 0, sizeof(params));
  27. params.wpa_debug_level = MSG_MSGDUMP;
  28. params.wpa_debug_file_path = "\\Temp\\wpa_supplicant-log.txt";
  29. params.wpa_debug_show_keys = 1;
  30. iface = ifaces = os_zalloc(sizeof(struct wpa_interface));
  31. if (ifaces == NULL)
  32. return -1;
  33. iface_count = 1;
  34. iface->confname = "default";
  35. iface->driver = "ndis";
  36. iface->ifname = "";
  37. exitcode = 0;
  38. global = wpa_supplicant_init(&params);
  39. if (global == NULL) {
  40. printf("Failed to initialize wpa_supplicant\n");
  41. exitcode = -1;
  42. }
  43. for (i = 0; exitcode == 0 && i < iface_count; i++) {
  44. if ((ifaces[i].confname == NULL &&
  45. ifaces[i].ctrl_interface == NULL) ||
  46. ifaces[i].ifname == NULL) {
  47. if (iface_count == 1 && (params.ctrl_interface ||
  48. params.dbus_ctrl_interface))
  49. break;
  50. exitcode = -1;
  51. break;
  52. }
  53. if (wpa_supplicant_add_iface(global, &ifaces[i], NULL) == NULL)
  54. exitcode = -1;
  55. }
  56. if (exitcode == 0)
  57. exitcode = wpa_supplicant_run(global);
  58. wpa_supplicant_deinit(global);
  59. os_free(ifaces);
  60. os_program_deinit();
  61. return exitcode;
  62. }