dbus_old_handlers_wps.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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") == 0)
  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(
  44. message, WPAS_ERROR_WPS_PBC_ERROR,
  45. "Could not start PBC negotiation");
  46. }
  47. return wpas_dbus_new_success_reply(message);
  48. }
  49. /**
  50. * wpas_dbus_iface_wps_pin - Establish the PIN number of the enrollee
  51. * @message: Pointer to incoming dbus message
  52. * @wpa_s: %wpa_supplicant data structure
  53. * Returns: A dbus message containing a UINT32 indicating success (1) or
  54. * failure (0)
  55. *
  56. * Handler function for "wpsPin" method call
  57. */
  58. DBusMessage * wpas_dbus_iface_wps_pin(DBusMessage *message,
  59. struct wpa_supplicant *wpa_s)
  60. {
  61. DBusMessage *reply = NULL;
  62. char *arg_bssid;
  63. char *pin = NULL;
  64. u8 bssid[ETH_ALEN], *_bssid = NULL;
  65. int ret = 0;
  66. char npin[9];
  67. if (!dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &arg_bssid,
  68. DBUS_TYPE_STRING, &pin, DBUS_TYPE_INVALID))
  69. return wpas_dbus_new_invalid_opts_error(message, NULL);
  70. if (os_strcmp(arg_bssid, "any") == 0)
  71. _bssid = NULL;
  72. else if (!hwaddr_aton(arg_bssid, bssid))
  73. _bssid = bssid;
  74. else {
  75. return wpas_dbus_new_invalid_opts_error(message,
  76. "Invalid BSSID");
  77. }
  78. if (os_strlen(pin) > 0)
  79. ret = wpas_wps_start_pin(wpa_s, _bssid, pin, 0,
  80. DEV_PW_DEFAULT);
  81. else
  82. ret = wpas_wps_start_pin(wpa_s, _bssid, NULL, 0,
  83. DEV_PW_DEFAULT);
  84. if (ret < 0) {
  85. return dbus_message_new_error(message,
  86. WPAS_ERROR_WPS_PIN_ERROR,
  87. "Could not init PIN");
  88. }
  89. reply = dbus_message_new_method_return(message);
  90. if (reply == NULL)
  91. return NULL;
  92. if (ret > 0) {
  93. os_snprintf(npin, sizeof(npin), "%08d", ret);
  94. pin = npin;
  95. }
  96. dbus_message_append_args(reply, DBUS_TYPE_STRING, &pin,
  97. DBUS_TYPE_INVALID);
  98. return reply;
  99. }
  100. /**
  101. * wpas_dbus_iface_wps_reg - Request credentials using the PIN of the AP
  102. * @message: Pointer to incoming dbus message
  103. * @wpa_s: %wpa_supplicant data structure
  104. * Returns: A dbus message containing a UINT32 indicating success (1) or
  105. * failure (0)
  106. *
  107. * Handler function for "wpsReg" method call
  108. */
  109. DBusMessage * wpas_dbus_iface_wps_reg(DBusMessage *message,
  110. struct wpa_supplicant *wpa_s)
  111. {
  112. char *arg_bssid;
  113. char *pin = NULL;
  114. u8 bssid[ETH_ALEN];
  115. int ret = 0;
  116. if (!dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &arg_bssid,
  117. DBUS_TYPE_STRING, &pin, DBUS_TYPE_INVALID))
  118. return wpas_dbus_new_invalid_opts_error(message, NULL);
  119. if (!hwaddr_aton(arg_bssid, bssid))
  120. ret = wpas_wps_start_reg(wpa_s, bssid, pin, NULL);
  121. else {
  122. return wpas_dbus_new_invalid_opts_error(message,
  123. "Invalid BSSID");
  124. }
  125. if (ret < 0) {
  126. return dbus_message_new_error(message,
  127. WPAS_ERROR_WPS_REG_ERROR,
  128. "Could not request credentials");
  129. }
  130. return wpas_dbus_new_success_reply(message);
  131. }