wps_upnp_ap.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * Wi-Fi Protected Setup - UPnP AP functionality
  3. * Copyright (c) 2009, Jouni Malinen <j@w1.fi>
  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 "common.h"
  10. #include "eloop.h"
  11. #include "uuid.h"
  12. #include "wps_i.h"
  13. #include "wps_upnp.h"
  14. #include "wps_upnp_i.h"
  15. static void upnp_er_set_selected_timeout(void *eloop_ctx, void *timeout_ctx)
  16. {
  17. struct subscription *s = eloop_ctx;
  18. struct wps_registrar *reg = timeout_ctx;
  19. wpa_printf(MSG_DEBUG, "WPS: SetSelectedRegistrar from ER timed out");
  20. s->selected_registrar = 0;
  21. wps_registrar_selected_registrar_changed(reg);
  22. }
  23. int upnp_er_set_selected_registrar(struct wps_registrar *reg,
  24. struct subscription *s,
  25. const struct wpabuf *msg)
  26. {
  27. struct wps_parse_attr attr;
  28. wpa_hexdump_buf(MSG_MSGDUMP, "WPS: SetSelectedRegistrar attributes",
  29. msg);
  30. if (wps_validate_upnp_set_selected_registrar(msg) < 0)
  31. return -1;
  32. if (wps_parse_msg(msg, &attr) < 0)
  33. return -1;
  34. s->reg = reg;
  35. eloop_cancel_timeout(upnp_er_set_selected_timeout, s, reg);
  36. os_memset(s->authorized_macs, 0, sizeof(s->authorized_macs));
  37. if (attr.selected_registrar == NULL || *attr.selected_registrar == 0) {
  38. wpa_printf(MSG_DEBUG, "WPS: SetSelectedRegistrar: Disable "
  39. "Selected Registrar");
  40. s->selected_registrar = 0;
  41. } else {
  42. s->selected_registrar = 1;
  43. s->dev_password_id = attr.dev_password_id ?
  44. WPA_GET_BE16(attr.dev_password_id) : DEV_PW_DEFAULT;
  45. s->config_methods = attr.sel_reg_config_methods ?
  46. WPA_GET_BE16(attr.sel_reg_config_methods) : -1;
  47. if (attr.authorized_macs) {
  48. int count = attr.authorized_macs_len / ETH_ALEN;
  49. if (count > WPS_MAX_AUTHORIZED_MACS)
  50. count = WPS_MAX_AUTHORIZED_MACS;
  51. os_memcpy(s->authorized_macs, attr.authorized_macs,
  52. count * ETH_ALEN);
  53. } else if (!attr.version2) {
  54. #ifdef CONFIG_WPS2
  55. wpa_printf(MSG_DEBUG, "WPS: Add broadcast "
  56. "AuthorizedMACs for WPS 1.0 ER");
  57. os_memset(s->authorized_macs, 0xff, ETH_ALEN);
  58. #endif /* CONFIG_WPS2 */
  59. }
  60. eloop_register_timeout(WPS_PBC_WALK_TIME, 0,
  61. upnp_er_set_selected_timeout, s, reg);
  62. }
  63. wps_registrar_selected_registrar_changed(reg);
  64. return 0;
  65. }
  66. void upnp_er_remove_notification(struct wps_registrar *reg,
  67. struct subscription *s)
  68. {
  69. s->selected_registrar = 0;
  70. eloop_cancel_timeout(upnp_er_set_selected_timeout, s, reg);
  71. if (reg)
  72. wps_registrar_selected_registrar_changed(reg);
  73. }