wmm_ac.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * Wi-Fi Multimedia Admission Control (WMM-AC)
  3. * Copyright(c) 2014, Intel Mobile Communication GmbH.
  4. * Copyright(c) 2014, Intel Corporation. All rights reserved.
  5. *
  6. * This software may be distributed under the terms of the BSD license.
  7. * See README for more details.
  8. */
  9. #include "includes.h"
  10. #include "utils/common.h"
  11. #include "common/ieee802_11_common.h"
  12. #include "wpa_supplicant_i.h"
  13. #include "driver_i.h"
  14. #include "wmm_ac.h"
  15. static struct wmm_ac_assoc_data *
  16. wmm_ac_process_param_elem(struct wpa_supplicant *wpa_s, const u8 *ies,
  17. size_t ies_len)
  18. {
  19. struct ieee802_11_elems elems;
  20. struct wmm_parameter_element *wmm_params;
  21. struct wmm_ac_assoc_data *assoc_data;
  22. int i;
  23. /* Parsing WMM Parameter Element */
  24. if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) != ParseOK) {
  25. wpa_printf(MSG_DEBUG, "WMM AC: could not parse assoc ies");
  26. return NULL;
  27. }
  28. if (!elems.wmm) {
  29. wpa_printf(MSG_DEBUG, "WMM AC: No WMM IE");
  30. return NULL;
  31. }
  32. if (elems.wmm_len != sizeof(*wmm_params)) {
  33. wpa_printf(MSG_WARNING, "WMM AC: Invalid WMM ie length");
  34. return NULL;
  35. }
  36. wmm_params = (struct wmm_parameter_element *)(elems.wmm);
  37. assoc_data = os_zalloc(sizeof(*assoc_data));
  38. if (!assoc_data)
  39. return NULL;
  40. for (i = 0; i < WMM_AC_NUM; i++)
  41. assoc_data->ac_params[i].acm =
  42. !!(wmm_params->ac[i].aci_aifsn & WMM_AC_ACM);
  43. wpa_printf(MSG_DEBUG,
  44. "WMM AC: AC mandatory: AC_BE=%u AC_BK=%u AC_VI=%u AC_VO=%u",
  45. assoc_data->ac_params[WMM_AC_BE].acm,
  46. assoc_data->ac_params[WMM_AC_BK].acm,
  47. assoc_data->ac_params[WMM_AC_VI].acm,
  48. assoc_data->ac_params[WMM_AC_VO].acm);
  49. return assoc_data;
  50. }
  51. static int wmm_ac_init(struct wpa_supplicant *wpa_s, const u8 *ies,
  52. size_t ies_len, const struct wmm_params *wmm_params)
  53. {
  54. struct wmm_ac_assoc_data *assoc_data;
  55. u8 ac;
  56. if (wpa_s->wmm_ac_assoc_info) {
  57. wpa_printf(MSG_ERROR, "WMM AC: Already initialized");
  58. return -1;
  59. }
  60. if (!ies) {
  61. wpa_printf(MSG_ERROR, "WMM AC: Missing IEs");
  62. return -1;
  63. }
  64. if (!(wmm_params->info_bitmap & WMM_PARAMS_UAPSD_QUEUES_INFO)) {
  65. wpa_printf(MSG_DEBUG, "WMM AC: Missing U-APSD configuration");
  66. return -1;
  67. }
  68. assoc_data = wmm_ac_process_param_elem(wpa_s, ies, ies_len);
  69. if (!assoc_data)
  70. return -1;
  71. wpa_printf(MSG_DEBUG, "WMM AC: U-APSD queues=0x%x",
  72. wmm_params->uapsd_queues);
  73. for (ac = 0; ac < WMM_AC_NUM; ac++) {
  74. assoc_data->ac_params[ac].uapsd =
  75. !!(wmm_params->uapsd_queues & BIT(ac));
  76. }
  77. wpa_s->wmm_ac_assoc_info = assoc_data;
  78. return 0;
  79. }
  80. static void wmm_ac_deinit(struct wpa_supplicant *wpa_s)
  81. {
  82. os_free(wpa_s->wmm_ac_assoc_info);
  83. wpa_s->wmm_ac_assoc_info = NULL;
  84. }
  85. void wmm_ac_notify_assoc(struct wpa_supplicant *wpa_s, const u8 *ies,
  86. size_t ies_len, const struct wmm_params *wmm_params)
  87. {
  88. if (wmm_ac_init(wpa_s, ies, ies_len, wmm_params))
  89. return;
  90. wpa_printf(MSG_DEBUG,
  91. "WMM AC: Valid WMM association, WMM AC is enabled");
  92. }
  93. void wmm_ac_notify_disassoc(struct wpa_supplicant *wpa_s)
  94. {
  95. if (!wpa_s->wmm_ac_assoc_info)
  96. return;
  97. wmm_ac_deinit(wpa_s);
  98. wpa_printf(MSG_DEBUG, "WMM AC: WMM AC is disabled");
  99. }