dbus_old_handlers_wps.c 4.0 KB

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