dbus_old_handlers_wps.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. 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"))
  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. dbus_message_append_args(reply, DBUS_TYPE_STRING, &pin,
  94. DBUS_TYPE_INVALID);
  95. } else {
  96. char npin[9];
  97. os_snprintf(npin, sizeof(npin), "%08d", ret);
  98. dbus_message_append_args(reply, DBUS_TYPE_STRING, &npin,
  99. DBUS_TYPE_INVALID);
  100. }
  101. return reply;
  102. }
  103. /**
  104. * wpas_dbus_iface_wps_reg - Request credentials using the PIN of the AP
  105. * @message: Pointer to incoming dbus message
  106. * @wpa_s: %wpa_supplicant data structure
  107. * Returns: A dbus message containing a UINT32 indicating success (1) or
  108. * failure (0)
  109. *
  110. * Handler function for "wpsReg" method call
  111. */
  112. DBusMessage * wpas_dbus_iface_wps_reg(DBusMessage *message,
  113. struct wpa_supplicant *wpa_s)
  114. {
  115. char *arg_bssid;
  116. char *pin = NULL;
  117. u8 bssid[ETH_ALEN];
  118. int ret = 0;
  119. if (!dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &arg_bssid,
  120. DBUS_TYPE_STRING, &pin, DBUS_TYPE_INVALID))
  121. return wpas_dbus_new_invalid_opts_error(message, NULL);
  122. if (!os_strcmp(arg_bssid, "any"))
  123. ret = wpas_wps_start_reg(wpa_s, NULL, pin, NULL);
  124. else if (!hwaddr_aton(arg_bssid, bssid))
  125. ret = wpas_wps_start_reg(wpa_s, bssid, pin, NULL);
  126. else {
  127. return wpas_dbus_new_invalid_opts_error(message,
  128. "Invalid BSSID");
  129. }
  130. if (ret < 0) {
  131. return dbus_message_new_error(message,
  132. WPAS_ERROR_WPS_PBC_ERROR,
  133. "Could not request credentials");
  134. }
  135. return wpas_dbus_new_success_reply(message);
  136. }