wmi_tlv_helper.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*
  2. * Copyright (c) 2012-2017 The Linux Foundation. All rights reserved.
  3. *
  4. * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
  5. *
  6. *
  7. * Permission to use, copy, modify, and/or distribute this software for
  8. * any purpose with or without fee is hereby granted, provided that the
  9. * above copyright notice and this permission notice appear in all
  10. * copies.
  11. *
  12. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  13. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  14. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  15. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  16. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  17. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  18. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  19. * PERFORMANCE OF THIS SOFTWARE.
  20. */
  21. /*
  22. * This file was originally distributed by Qualcomm Atheros, Inc.
  23. * under proprietary terms before Copyright ownership was assigned
  24. * to the Linux Foundation.
  25. */
  26. #ifndef _WMI_TLV_HELPER_H_
  27. #define _WMI_TLV_HELPER_H_
  28. /*
  29. * Every command or event parameter structure will need a TLV definition.
  30. * The macro WMITLV_TABLE is used to help build this TLV definition. Inside this macro define, the
  31. * individual TLV's are specified. The parameters for WMITLV_ELEM are:
  32. * (1) the list of parameters that are passed unchanged from the WMITLV_TABLE. Currently, they are id,op,buf,len
  33. * (2) The TLV Tag. You should create a new tag for each cmd/event in WMITLV_TAG_ID. The name of the
  34. * tag is <WMI_TLVTAG_STRUC_><CMD or Event ID name>. There are special tags,
  35. * e.g. WMI_TLVTAG_ARRAY_UINT32 and WMI_TLVTAG_ARRAY_STRUC. WMI_TLVTAG_ARRAY_UINT32 is for a
  36. * variable size array of UINT32 elements. WMI_TLVTAG_ARRAY_STRUC is for a varialbe size array
  37. * of structures.
  38. * (3) type of the TLV. For WMI_TLVTAG_ARRAY_* tag, then it is the type of each element.
  39. * (4) Name of this TLV. It must be unique in this TLV TABLE.
  40. * (5) Either WMITLV_SIZE_FIX or WMITLV_SIZE_VAR to indicate if this TLV is variable size.
  41. *
  42. * Note: It is important that the last TLV_ELEM does not have the "\" character.
  43. */
  44. /* Size of the TLV Header which is the Tag and Length fields */
  45. #define WMI_TLV_HDR_SIZE (1 * sizeof(A_UINT32))
  46. /** TLV Helper macro to get the TLV Header given the pointer
  47. * to the TLV buffer. */
  48. #define WMITLV_GET_HDR(tlv_buf) (((A_UINT32 *)(tlv_buf))[0])
  49. /** TLV Helper macro to set the TLV Header given the pointer
  50. * to the TLV buffer. */
  51. #define WMITLV_SET_HDR(tlv_buf, tag, len) (((A_UINT32 *)(tlv_buf))[0]) = ((tag << 16) | (len & 0x0000FFFF))
  52. /** TLV Helper macro to get the TLV Tag given the TLV header. */
  53. #define WMITLV_GET_TLVTAG(tlv_header) ((A_UINT32)((tlv_header)>>16))
  54. /** TLV Helper macro to get the TLV Buffer Length (minus TLV
  55. * header size) given the TLV header. */
  56. #define WMITLV_GET_TLVLEN(tlv_header) ((A_UINT32)((tlv_header) & 0x0000FFFF))
  57. /** TLV Helper macro to get the TLV length from TLV structure size by removing TLV header size */
  58. #define WMITLV_GET_STRUCT_TLVLEN(tlv_struct) ((A_UINT32)(sizeof(tlv_struct)-WMI_TLV_HDR_SIZE))
  59. /* Indicates whether the TLV is fixed size or variable length */
  60. #define WMITLV_SIZE_FIX 0
  61. #define WMITLV_SIZE_VAR 1
  62. typedef struct {
  63. A_UINT32 tag_order;
  64. A_UINT32 tag_id;
  65. A_UINT32 tag_struct_size;
  66. A_UINT32 tag_varied_size;
  67. A_UINT32 tag_array_size;
  68. A_UINT32 cmd_num_tlv;
  69. } wmitlv_attributes_struc;
  70. /* Template structure definition for a variable size array of UINT32 */
  71. typedef struct {
  72. A_UINT32 tlv_header; /* TLV tag and len; tag equals WMI_TLVTAG_ARRAY_UINT32 */
  73. A_UINT32 uint32_array[1]; /* variable length Array of UINT32 */
  74. } wmitlv_array_uint32;
  75. /* Template structure definition for a variable size array of unknown structure */
  76. typedef struct {
  77. A_UINT32 tlv_header; /* TLV tag and len; tag equals WMI_TLVTAG_ARRAY_STRUC */
  78. A_UINT32 struc_array[1]; /* variable length Array of structures */
  79. } wmitlv_array_struc;
  80. /*
  81. * Used to fill in the "arr_size" parameter when it is not specified and hence, invalid. Can be used to
  82. * indicate if the original TLV definition specify this fixed array size.
  83. */
  84. #define WMITLV_ARR_SIZE_INVALID 0x1FE
  85. #define WMITLV_GET_TAG_NUM_TLV_ATTRIB(wmi_cmd_event_id) \
  86. WMI_TLV_HLPR_NUM_TLVS_FOR_##wmi_cmd_event_id
  87. void
  88. wmitlv_set_static_param_tlv_buf(void *param_tlv_buf, A_UINT32 max_tlvs_accomodated);
  89. void
  90. wmitlv_set_static_param_tlv_buf_ext(void *param_tlv_buf, A_UINT32 max_tlvs_accomodated, A_UINT32 indx);
  91. void
  92. wmitlv_free_allocated_command_tlvs(
  93. A_UINT32 cmd_id,
  94. void **wmi_cmd_struct_ptr);
  95. void
  96. wmitlv_free_allocated_event_tlvs(
  97. A_UINT32 event_id,
  98. void **wmi_cmd_struct_ptr);
  99. int
  100. wmitlv_check_command_tlv_params(
  101. void *os_ctx, void *param_struc_ptr, A_UINT32 param_buf_len, A_UINT32 wmi_cmd_event_id);
  102. int
  103. wmitlv_check_event_tlv_params(
  104. void *os_ctx, void *param_struc_ptr, A_UINT32 param_buf_len, A_UINT32 wmi_cmd_event_id);
  105. int
  106. wmitlv_check_and_pad_command_tlvs(
  107. void *os_ctx, void *param_struc_ptr, A_UINT32 param_buf_len, A_UINT32 wmi_cmd_event_id, void **wmi_cmd_struct_ptr);
  108. int
  109. wmitlv_check_and_pad_event_tlvs(
  110. void *os_ctx, void *param_struc_ptr, A_UINT32 param_buf_len, A_UINT32 wmi_cmd_event_id, void **wmi_cmd_struct_ptr);
  111. /** This structure is the element for the Version WhiteList
  112. * table. */
  113. typedef struct {
  114. A_UINT32 major;
  115. A_UINT32 minor;
  116. A_UINT32 namespace_0;
  117. A_UINT32 namespace_1;
  118. A_UINT32 namespace_2;
  119. A_UINT32 namespace_3;
  120. } wmi_whitelist_version_info;
  121. struct _wmi_abi_version; /* Forward declaration to make the ARM compiler happy */
  122. int
  123. wmi_cmp_and_set_abi_version(int num_whitelist, wmi_whitelist_version_info *version_whitelist_table,
  124. struct _wmi_abi_version *my_vers,
  125. struct _wmi_abi_version *opp_vers,
  126. struct _wmi_abi_version *out_vers);
  127. int
  128. wmi_versions_are_compatible(struct _wmi_abi_version *vers1, struct _wmi_abi_version *vers2);
  129. #endif /*_WMI_TLV_HELPER_H_*/