testmode.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * Copyright (c) 2010-2011 Atheros Communications Inc.
  3. * Copyright (c) 2011 Qualcomm Atheros, Inc.
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for any
  6. * purpose with or without fee is hereby granted, provided that the above
  7. * copyright notice and this permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  10. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  11. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  12. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  13. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  14. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  15. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16. */
  17. #include "testmode.h"
  18. #include "debug.h"
  19. #include <net/netlink.h>
  20. enum ath6kl_tm_attr {
  21. __ATH6KL_TM_ATTR_INVALID = 0,
  22. ATH6KL_TM_ATTR_CMD = 1,
  23. ATH6KL_TM_ATTR_DATA = 2,
  24. /* keep last */
  25. __ATH6KL_TM_ATTR_AFTER_LAST,
  26. ATH6KL_TM_ATTR_MAX = __ATH6KL_TM_ATTR_AFTER_LAST - 1,
  27. };
  28. enum ath6kl_tm_cmd {
  29. ATH6KL_TM_CMD_TCMD = 0,
  30. ATH6KL_TM_CMD_RX_REPORT = 1, /* not used anymore */
  31. };
  32. #define ATH6KL_TM_DATA_MAX_LEN 5000
  33. static const struct nla_policy ath6kl_tm_policy[ATH6KL_TM_ATTR_MAX + 1] = {
  34. [ATH6KL_TM_ATTR_CMD] = { .type = NLA_U32 },
  35. [ATH6KL_TM_ATTR_DATA] = { .type = NLA_BINARY,
  36. .len = ATH6KL_TM_DATA_MAX_LEN },
  37. };
  38. void ath6kl_tm_rx_event(struct ath6kl *ar, void *buf, size_t buf_len)
  39. {
  40. struct sk_buff *skb;
  41. if (!buf || buf_len == 0)
  42. return;
  43. skb = cfg80211_testmode_alloc_event_skb(ar->wiphy, buf_len, GFP_KERNEL);
  44. if (!skb) {
  45. ath6kl_warn("failed to allocate testmode rx skb!\n");
  46. return;
  47. }
  48. if (nla_put_u32(skb, ATH6KL_TM_ATTR_CMD, ATH6KL_TM_CMD_TCMD) ||
  49. nla_put(skb, ATH6KL_TM_ATTR_DATA, buf_len, buf))
  50. goto nla_put_failure;
  51. cfg80211_testmode_event(skb, GFP_KERNEL);
  52. return;
  53. nla_put_failure:
  54. kfree_skb(skb);
  55. ath6kl_warn("nla_put failed on testmode rx skb!\n");
  56. }
  57. int ath6kl_tm_cmd(struct wiphy *wiphy, struct wireless_dev *wdev,
  58. void *data, int len)
  59. {
  60. struct ath6kl *ar = wiphy_priv(wiphy);
  61. struct nlattr *tb[ATH6KL_TM_ATTR_MAX + 1];
  62. int err, buf_len;
  63. void *buf;
  64. err = nla_parse(tb, ATH6KL_TM_ATTR_MAX, data, len,
  65. ath6kl_tm_policy);
  66. if (err)
  67. return err;
  68. if (!tb[ATH6KL_TM_ATTR_CMD])
  69. return -EINVAL;
  70. switch (nla_get_u32(tb[ATH6KL_TM_ATTR_CMD])) {
  71. case ATH6KL_TM_CMD_TCMD:
  72. if (!tb[ATH6KL_TM_ATTR_DATA])
  73. return -EINVAL;
  74. buf = nla_data(tb[ATH6KL_TM_ATTR_DATA]);
  75. buf_len = nla_len(tb[ATH6KL_TM_ATTR_DATA]);
  76. ath6kl_wmi_test_cmd(ar->wmi, buf, buf_len);
  77. return 0;
  78. break;
  79. case ATH6KL_TM_CMD_RX_REPORT:
  80. default:
  81. return -EOPNOTSUPP;
  82. }
  83. }