mme.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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. * mme.h -
  44. *
  45. * message header definitions and function declarations;
  46. *
  47. *. Qualcomm Atheros HomePlug AV Powerline Toolkit
  48. *: Copyright (c) 2009-2013 by Qualcomm Atheros Inc. ALL RIGHTS RESERVED;
  49. *; For demonstration and evaluation only; Not for production use.
  50. *
  51. * Contributor(s):
  52. * Charles Maier
  53. * Matthieu Poullet
  54. *
  55. *--------------------------------------------------------------------*/
  56. #ifndef MME_HEADER
  57. #define MME_HEADER
  58. /*====================================================================*
  59. * system header files;
  60. *--------------------------------------------------------------------*/
  61. #include <stdio.h>
  62. #include <stdint.h>
  63. #include <unistd.h>
  64. /*====================================================================*
  65. * custom header files;
  66. *--------------------------------------------------------------------*/
  67. #include "../ether/ether.h"
  68. #include "../ether/channel.h"
  69. #include "../mme/homeplug.h"
  70. #include "../mme/qualcomm.h"
  71. /*====================================================================*
  72. * manage cross-platform structure packing;
  73. *--------------------------------------------------------------------*/
  74. #ifndef __packed
  75. #ifdef __GNUC__
  76. #define __packed __attribute__ ((packed))
  77. #else
  78. #define __packed
  79. #endif
  80. #endif
  81. /*====================================================================*
  82. * Ethernet, HomePlug and Qualcomm Frame headers;
  83. *--------------------------------------------------------------------*/
  84. #ifndef __GNUC__
  85. #pragma pack (push, 1)
  86. #endif
  87. typedef struct __packed ethernet_hdr
  88. {
  89. uint8_t ODA [ETHER_ADDR_LEN];
  90. uint8_t OSA [ETHER_ADDR_LEN];
  91. uint16_t MTYPE;
  92. }
  93. ethernet_hdr;
  94. typedef struct __packed homeplug_hdr
  95. {
  96. uint8_t MMV;
  97. uint16_t MMTYPE;
  98. }
  99. homeplug_hdr;
  100. typedef struct __packed homeplug_fmi
  101. {
  102. uint8_t MMV;
  103. uint16_t MMTYPE;
  104. uint8_t FMSN;
  105. uint8_t FMID;
  106. }
  107. homeplug_fmi;
  108. typedef struct __packed qualcomm_hdr
  109. {
  110. uint8_t MMV;
  111. uint16_t MMTYPE;
  112. uint8_t OUI [ETHER_ADDR_LEN >> 1];
  113. }
  114. qualcomm_hdr;
  115. typedef struct __packed qualcomm_fmi
  116. {
  117. uint8_t MMV;
  118. uint16_t MMTYPE;
  119. uint8_t FMSN;
  120. uint8_t FMID;
  121. uint8_t OUI [ETHER_ADDR_LEN >> 1];
  122. }
  123. qualcomm_fmi;
  124. #ifndef __GNUC__
  125. #pragma pack (pop)
  126. #endif
  127. /*====================================================================*
  128. * Composite message formats;
  129. *--------------------------------------------------------------------*/
  130. #ifndef __GNUC__
  131. #pragma pack (push, 1)
  132. #endif
  133. typedef struct __packed message
  134. {
  135. struct ethernet_hdr ethernet;
  136. uint8_t content [ETHERMTU];
  137. }
  138. MESSAGE;
  139. typedef struct __packed homeplug
  140. {
  141. struct ethernet_hdr ethernet;
  142. struct homeplug_fmi homeplug;
  143. uint8_t content [ETHERMTU - sizeof (struct homeplug_fmi)];
  144. }
  145. HOMEPLUG;
  146. typedef struct __packed qualcomm
  147. {
  148. struct ethernet_hdr ethernet;
  149. struct qualcomm_fmi qualcomm;
  150. uint8_t content [ETHERMTU - sizeof (struct qualcomm_fmi)];
  151. }
  152. QUALCOMM;
  153. #ifndef __GNUC__
  154. #pragma pack (pop)
  155. #endif
  156. /*====================================================================*
  157. * functions;
  158. *--------------------------------------------------------------------*/
  159. void MMEPeek (void const * memory, size_t extent, FILE * fp);
  160. void ARPCPeek (void const * memory, size_t extent, FILE * fp);
  161. void ARPCWrite (signed fd, void const * memory, size_t extent);
  162. void ARPCPrint (FILE * fp, void const * memory, size_t extent);
  163. /*====================================================================*
  164. * functions;
  165. *--------------------------------------------------------------------*/
  166. char const * MMEName (uint16_t MMTYPE);
  167. char const * MMEMode (uint16_t MMTYPE);
  168. char const * MMECode (uint16_t MMTYPE, uint8_t MSTATUS);
  169. /*====================================================================*
  170. * header encode functions;
  171. *--------------------------------------------------------------------*/
  172. signed EthernetHeader (void * memory, const uint8_t peer [], const uint8_t host [], uint16_t protocol);
  173. signed HomePlugHeader (struct homeplug_hdr *, uint8_t MMV, uint16_t MMTYPE);
  174. signed QualcommHeader (struct qualcomm_hdr *, uint8_t MMV, uint16_t MMTYPE);
  175. signed HomePlugHeader1 (struct homeplug_fmi *, uint8_t MMV, uint16_t MMTYPE);
  176. signed QualcommHeader1 (struct qualcomm_fmi *, uint8_t MMV, uint16_t MMTYPE);
  177. /*====================================================================*
  178. * header decode functions;
  179. *--------------------------------------------------------------------*/
  180. signed UnwantedMessage (void const * memory, size_t extent, uint8_t MMV, uint16_t MMTYPE);
  181. signed FirmwareMessage (void const * memory);
  182. /*====================================================================*
  183. * intermmediate level Ethernet send/receive functions;
  184. *--------------------------------------------------------------------*/
  185. ssize_t sendmessage (struct channel const *, struct message *, ssize_t length);
  186. ssize_t readmessage (struct channel const *, struct message *, uint8_t MMV, uint16_t MMTYPE);
  187. /*====================================================================*
  188. *
  189. *--------------------------------------------------------------------*/
  190. #endif