ARPCPrint.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*====================================================================*
  2. *
  3. * Copyright (c) 2013 Qualcomm Atheros, Inc.
  4. *
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or
  8. * without modification, are permitted (subject to the limitations
  9. * in the disclaimer below) provided that the following conditions
  10. * are met:
  11. *
  12. * * Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. *
  15. * * Redistributions in binary form must reproduce the above
  16. * copyright notice, this list of conditions and the following
  17. * disclaimer in the documentation and/or other materials
  18. * provided with the distribution.
  19. *
  20. * * Neither the name of Qualcomm Atheros nor the names of
  21. * its contributors may be used to endorse or promote products
  22. * derived from this software without specific prior written
  23. * permission.
  24. *
  25. * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
  26. * GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE
  27. * COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
  28. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  29. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  30. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
  31. * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  32. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  33. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  34. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  35. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  36. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  37. * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  38. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  39. *
  40. *--------------------------------------------------------------------*/
  41. /*====================================================================*
  42. *
  43. * void ARPCPrint (FILE * fp, void const * memory, size_t extent);
  44. *
  45. * mme.h
  46. *
  47. * print formatted VS_ARPC payload on the specified output stream;
  48. * this implementation is generic; memory is the start address of
  49. * the message data (&RDATA [RDATAOFFSET]) and extent is the data
  50. * length (RDATALENGTH); the call might look like this ...
  51. *
  52. * ARPCPrint (fp, &ARPC->RDATA [ARPC->RDATAOFFSET], LE16TOH (ARPC->RDATALENGTH) - ARPC->RDATAOFFSET);
  53. *
  54. * ... where LE16TOH () performs 16-bit host endian conversion;
  55. *
  56. *
  57. * Contributor(s):
  58. * Charles Maier
  59. * Nathaniel Houghton
  60. * Florian Fainelli
  61. *
  62. *--------------------------------------------------------------------*/
  63. #ifndef ARPCPRINT_SOURCE
  64. #define ARPCPRINT_SOURCE
  65. #include <stdio.h>
  66. #include <stddef.h>
  67. #include "../tools/types.h"
  68. #include "../tools/endian.h"
  69. #include "../tools/memory.h"
  70. #include "../mme/mme.h"
  71. void ARPCPrint (FILE * fp, void const * memory, size_t extent)
  72. {
  73. #ifndef __GNUC__
  74. #pragma pack (push,1)
  75. #endif
  76. struct __packed vs_arpc_data
  77. {
  78. uint32_t BYPASS;
  79. uint16_t ARPCID;
  80. uint16_t DATALENGTH;
  81. uint8_t DATAOFFSET;
  82. uint8_t RESERVED [3];
  83. uint16_t ARGOFFSET;
  84. uint16_t STROFFSET;
  85. uint16_t ARGLENGTH;
  86. uint16_t STRLENGTH;
  87. uint8_t LIST [1];
  88. }
  89. * data = (struct vs_arpc_data *)(memory);
  90. #ifndef __GNUC__
  91. #pragma pack (pop)
  92. #endif
  93. uint32_t * argp = (uint32_t *)(&data->LIST [LE16TOH (data->ARGOFFSET)]);
  94. uint16_t argc = LE16TOH (data->ARGLENGTH) >> 2;
  95. while (argc--)
  96. {
  97. *argp = LE32TOH (*argp);
  98. argp++;
  99. }
  100. argp = (uint32_t *)(&data->LIST [LE16TOH (data->ARGOFFSET)]);
  101. fprintf (fp, (char *)(&data->LIST [LE16TOH (data->STROFFSET)]), argp [0], argp [1], argp [2], argp [3], argp [4], argp [5], argp [6], argp [7], argp [8], argp [9], argp [10], argp [11], argp [12], argp [13], argp [14], argp [15], argp [16], argp [17], argp [18], argp [19], argp [20], argp [21], argp [22], argp [23], argp [24], argp [25], argp [26], argp [27], argp [28], argp [29], argp [30], argp [31], argp [32], argp [33], argp [34], argp [35], argp [36], argp [37], argp [38], argp [39]);
  102. fprintf (fp, "\n");
  103. fflush (fp);
  104. return;
  105. }
  106. #endif