You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

dbus_old_handlers_wps.c 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*
  2. * WPA Supplicant / dbus-based control interface (WPS)
  3. * Copyright (c) 2006, Dan Williams <dcbw@redhat.com> and Red Hat, Inc.
  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. #include "includes.h"
  15. #include <dbus/dbus.h>
  16. #include "common.h"
  17. #include "../config.h"
  18. #include "../wpa_supplicant_i.h"
  19. #include "../wps_supplicant.h"
  20. #include "dbus_old.h"
  21. #include "dbus_old_handlers.h"
  22. /**
  23. * wpas_dbus_iface_wps_pbc - Request credentials using WPS PBC method
  24. * @message: Pointer to incoming dbus message
  25. * @wpa_s: %wpa_supplicant data structure
  26. * Returns: A dbus message containing a UINT32 indicating success (1) or
  27. * failure (0)
  28. *
  29. * Handler function for "wpsPbc" method call
  30. */
  31. DBusMessage * wpas_dbus_iface_wps_pbc(DBusMessage *message,
  32. struct wpa_supplicant *wpa_s)
  33. {
  34. char *arg_bssid = NULL;
  35. u8 bssid[ETH_ALEN];
  36. int ret = 0;
  37. if (!dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &arg_bssid,
  38. DBUS_TYPE_INVALID))
  39. return wpas_dbus_new_invalid_opts_error(message, NULL);
  40. if (!os_strcmp(arg_bssid, "any"))
  41. ret = wpas_wps_start_pbc(wpa_s, NULL, 0);
  42. else if (!hwaddr_aton(arg_bssid, bssid))
  43. ret = wpas_wps_start_pbc(wpa_s, bssid, 0);
  44. else {
  45. return wpas_dbus_new_invalid_opts_error(message,
  46. "Invalid BSSID");
  47. }
  48. if (ret < 0) {
  49. return dbus_message_new_error(message,
  50. WPAS_ERROR_WPS_PBC_ERROR,
  51. "Could not start PBC "
  52. "negotiation");
  53. }
  54. return wpas_dbus_new_success_reply(message);
  55. }
  56. /**
  57. * wpas_dbus_iface_wps_pin - Establish the PIN number of the enrollee
  58. * @message: Pointer to incoming dbus message
  59. * @wpa_s: %wpa_supplicant data structure
  60. * Returns: A dbus message containing a UINT32 indicating success (1) or
  61. * failure (0)
  62. *
  63. * Handler function for "wpsPin" method call
  64. */
  65. DBusMessage * wpas_dbus_iface_wps_pin(DBusMessage *message,
  66. struct wpa_supplicant *wpa_s)
  67. {
  68. DBusMessage *reply = NULL;
  69. char *arg_bssid;
  70. char *pin = NULL;
  71. u8 bssid[ETH_ALEN], *_bssid = NULL;
  72. int ret = 0;
  73. if (!dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &arg_bssid,
  74. DBUS_TYPE_STRING, &pin, DBUS_TYPE_INVALID))
  75. return wpas_dbus_new_invalid_opts_error(message, NULL);
  76. if (!os_strcmp(arg_bssid, "any"))
  77. _bssid = NULL;
  78. else if (!hwaddr_aton(arg_bssid, bssid))
  79. _bssid = bssid;
  80. else {
  81. return wpas_dbus_new_invalid_opts_error(message,
  82. "Invalid BSSID");
  83. }
  84. if (os_strlen(pin) > 0)
  85. ret = wpas_wps_start_pin(wpa_s, _bssid, pin, 0,
  86. DEV_PW_DEFAULT);
  87. else
  88. ret = wpas_wps_start_pin(wpa_s, _bssid, NULL, 0,
  89. DEV_PW_DEFAULT);
  90. if (ret < 0) {
  91. return dbus_message_new_error(message,
  92. WPAS_ERROR_WPS_PIN_ERROR,
  93. "Could not init PIN");
  94. }
  95. reply = dbus_message_new_method_return(message);
  96. if (reply == NULL)
  97. return NULL;
  98. if (ret == 0) {
  99. dbus_message_append_args(reply, DBUS_TYPE_STRING, &pin,
  100. DBUS_TYPE_INVALID);
  101. } else {
  102. char npin[9];
  103. os_snprintf(npin, sizeof(npin), "%08d", ret);
  104. dbus_message_append_args(reply, DBUS_TYPE_STRING, &npin,
  105. DBUS_TYPE_INVALID);
  106. }
  107. return reply;
  108. }
  109. /**
  110. * wpas_dbus_iface_wps_reg - Request credentials using the PIN of the AP
  111. * @message: Pointer to incoming dbus message
  112. * @wpa_s: %wpa_supplicant data structure
  113. * Returns: A dbus message containing a UINT32 indicating success (1) or
  114. * failure (0)
  115. *
  116. * Handler function for "wpsReg" method call
  117. */
  118. DBusMessage * wpas_dbus_iface_wps_reg(DBusMessage *message,
  119. struct wpa_supplicant *wpa_s)
  120. {
  121. char *arg_bssid;
  122. char *pin = NULL;
  123. u8 bssid[ETH_ALEN];
  124. int ret = 0;
  125. if (!dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &arg_bssid,
  126. DBUS_TYPE_STRING, &pin, DBUS_TYPE_INVALID))
  127. return wpas_dbus_new_invalid_opts_error(message, NULL);
  128. if (!os_strcmp(arg_bssid, "any"))
  129. ret = wpas_wps_start_reg(wpa_s, NULL, pin, NULL);
  130. else if (!hwaddr_aton(arg_bssid, bssid))
  131. ret = wpas_wps_start_reg(wpa_s, bssid, pin, NULL);
  132. else {
  133. return wpas_dbus_new_invalid_opts_error(message,
  134. "Invalid BSSID");
  135. }
  136. if (ret < 0) {
  137. return dbus_message_new_error(message,
  138. WPAS_ERROR_WPS_PBC_ERROR,
  139. "Could not request credentials");
  140. }
  141. return wpas_dbus_new_success_reply(message);
  142. }