wps_upnp_ap.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * Wi-Fi Protected Setup - UPnP AP functionality
  3. * Copyright (c) 2009, Jouni Malinen <j@w1.fi>
  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 "common.h"
  16. #include "eloop.h"
  17. #include "uuid.h"
  18. #include "wps_i.h"
  19. #include "wps_upnp.h"
  20. #include "wps_upnp_i.h"
  21. static void upnp_er_set_selected_timeout(void *eloop_ctx, void *timeout_ctx)
  22. {
  23. struct subscription *s = eloop_ctx;
  24. wpa_printf(MSG_DEBUG, "WPS: SetSelectedRegistrar from ER timed out");
  25. s->selected_registrar = 0;
  26. wps_registrar_selected_registrar_changed(s->reg);
  27. }
  28. int upnp_er_set_selected_registrar(struct wps_registrar *reg,
  29. struct subscription *s,
  30. const struct wpabuf *msg)
  31. {
  32. struct wps_parse_attr attr;
  33. wpa_hexdump_buf(MSG_MSGDUMP, "WPS: SetSelectedRegistrar attributes",
  34. msg);
  35. if (wps_parse_msg(msg, &attr) < 0)
  36. return -1;
  37. if (!wps_version_supported(attr.version)) {
  38. wpa_printf(MSG_DEBUG, "WPS: Unsupported SetSelectedRegistrar "
  39. "version 0x%x", attr.version ? *attr.version : 0);
  40. return -1;
  41. }
  42. s->reg = reg;
  43. eloop_cancel_timeout(upnp_er_set_selected_timeout, s, NULL);
  44. if (attr.selected_registrar == NULL || *attr.selected_registrar == 0) {
  45. wpa_printf(MSG_DEBUG, "WPS: SetSelectedRegistrar: Disable "
  46. "Selected Registrar");
  47. s->selected_registrar = 0;
  48. } else {
  49. s->selected_registrar = 1;
  50. s->dev_password_id = attr.dev_password_id ?
  51. WPA_GET_BE16(attr.dev_password_id) : DEV_PW_DEFAULT;
  52. s->config_methods = attr.sel_reg_config_methods ?
  53. WPA_GET_BE16(attr.sel_reg_config_methods) : -1;
  54. eloop_register_timeout(WPS_PBC_WALK_TIME, 0,
  55. upnp_er_set_selected_timeout, s, NULL);
  56. }
  57. wps_registrar_selected_registrar_changed(reg);
  58. return 0;
  59. }
  60. void upnp_er_remove_notification(struct subscription *s)
  61. {
  62. s->selected_registrar = 0;
  63. eloop_cancel_timeout(upnp_er_set_selected_timeout, s, NULL);
  64. if (s->reg)
  65. wps_registrar_selected_registrar_changed(s->reg);
  66. }