UnwantedMessage.c.html 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. <?xml version='1.0' encoding='iso-8859-1'?>
  2. <!doctype html public '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
  3. <html xmlns='http://www.w3c.org/1999/xhtml' lang='en-us'>
  4. <head>
  5. <title>
  6. UnwantedMessage.c
  7. </title>
  8. <meta http-equiv='content-type' content='text/html;iso-8859-1'/>
  9. <meta name='generator' content='motley-tools 1.9.4 13:40:33 Feb 18 2015'/>
  10. <meta name='author' content='cmaier@cmassoc.net'/>
  11. <meta name='robots' content='noindex,nofollow'/>
  12. <link href='toolkit.css' rel='stylesheet' type='text/css'/>
  13. </head>
  14. <body>
  15. <div class='headerlink'>
  16. [<a href='uintspec.c.html' title=' uintspec.c '>PREV</a>]
  17. [<a href='toolkit.html' title=' Index '>HOME</a>]
  18. [<a href='UpgradeDevice1.c.html' title=' UpgradeDevice1.c '>NEXT</a>]
  19. </div>
  20. <pre>
  21. /*====================================================================*
  22. *
  23. * Copyright (c) 2013 Qualcomm Atheros, Inc.
  24. *
  25. * All rights reserved.
  26. *
  27. * Redistribution and use in source and binary forms, with or
  28. * without modification, are permitted (subject to the limitations
  29. * in the disclaimer below) provided that the following conditions
  30. * are met:
  31. *
  32. * * Redistributions of source code must retain the above copyright
  33. * notice, this list of conditions and the following disclaimer.
  34. *
  35. * * Redistributions in binary form must reproduce the above
  36. * copyright notice, this list of conditions and the following
  37. * disclaimer in the documentation and/or other materials
  38. * provided with the distribution.
  39. *
  40. * * Neither the name of Qualcomm Atheros nor the names of
  41. * its contributors may be used to endorse or promote products
  42. * derived from this software without specific prior written
  43. * permission.
  44. *
  45. * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
  46. * GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE
  47. * COPYRIGHT HOLDERS AND CONTRIBUTORS &quot;AS IS&quot; AND ANY EXPRESS OR
  48. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  49. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  50. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
  51. * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  52. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  53. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  54. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  55. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  56. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  57. * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  58. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  59. *
  60. *--------------------------------------------------------------------*/
  61. /*====================================================================*
  62. *
  63. * signed UnwantedMessage (void const * memory, size_t extent, uint8_t MMV, uint16_t MMTYPE);
  64. *
  65. * mme.h
  66. *
  67. * return true if memory does not contains a Qualcomm Atheros message
  68. * of the specified version and type; the message version determines
  69. * the location of the OUI field; messages with MMV = 1 have an FMI
  70. * used to track multi-part confirmation counts; out of order counts
  71. * are treated as an error;
  72. *
  73. * constant __WHYNOT__ displays reason for message rejection;
  74. *
  75. * batch is the fragment group identifier taken from the fragment
  76. * frame;
  77. *
  78. * total is the number of fragements in the group taken from the
  79. * fragment frame;
  80. *
  81. * index is the fragment identifier from the fragment frame;
  82. *
  83. * count is the number of fragments received so far;
  84. *
  85. *
  86. * Contributor(s):
  87. * Charles Maier &lt;cmaier@qca.qualcomm.com&gt;
  88. * Matthieu Poullet &lt;m.poullet@avm.de&gt;
  89. *
  90. *--------------------------------------------------------------------*/
  91. #ifndef UNWANTEDMESSAGE_SOURCE
  92. #define UNWANTEDMESSAGE_SOURCE
  93. #include &lt;stdint.h&gt;
  94. #include &lt;memory.h&gt;
  95. #include &quot;../tools/endian.h&quot;
  96. #include &quot;../tools/error.h&quot;
  97. #include &quot;../mme/mme.h&quot;
  98. signed UnwantedMessage (void const * memory, size_t extent, uint8_t MMV, uint16_t MMTYPE)
  99. {
  100. extern const byte localcast [ETHER_ADDR_LEN];
  101. // struct message * message = (struct message *)(memory);
  102. struct homeplug * homeplug = (struct homeplug *)(memory);
  103. if (!extent)
  104. {
  105. return (-1);
  106. }
  107. if (extent &lt; (ETHER_MIN_LEN - ETHER_CRC_LEN))
  108. {
  109. #if defined (__WHYNOT__)
  110. error (0, 0, &quot;Wrong Ethernet Frame Size: Received &quot; SIZE_T_SPEC &quot; bytes but need at least %d&quot;, extent, ETHER_MIN_LEN - ETHER_CRC_LEN);
  111. #endif
  112. return (-1);
  113. }
  114. if (extent &gt; (ETHER_MAX_LEN))
  115. {
  116. #if defined (__WHYNOT__)
  117. error (0, 0, &quot;Wrong Ethernet Frame Size: Received &quot; SIZE_T_SPEC &quot; bytes but need at most %d&quot;, extent, ETHER_MAX_LEN);
  118. #endif
  119. return (-1);
  120. }
  121. if (ntohs (homeplug-&gt;ethernet.MTYPE) != ETH_P_HPAV)
  122. {
  123. #if defined (__WHYNOT__)
  124. error (0, 0, &quot;Wrong Ethernet Frame Type: Received %04X while waiting for %04X&quot;, ntohs (homeplug-&gt;ethernet.MTYPE), ETH_P_HPAV);
  125. #endif
  126. return (-1);
  127. }
  128. if (homeplug-&gt;homeplug.MMV != MMV)
  129. {
  130. #if defined (__WHYNOT__)
  131. error (0, 0, &quot;Wrong Message Version: Received %02X but expected %02X&quot;, homeplug-&gt;homeplug.MMV, MMV);
  132. #endif
  133. return (-1);
  134. }
  135. if (homeplug-&gt;homeplug.MMV == 0)
  136. {
  137. struct qualcomm_hdr * qualcomm = (struct qualcomm_hdr *)(&amp;homeplug-&gt;homeplug);
  138. if (LE16TOH (qualcomm-&gt;MMTYPE) != MMTYPE)
  139. {
  140. #if defined (__WHYNOT__)
  141. error (0, 0, &quot;Wrong Message Type: Received %04X while waiting for %04X&quot;, LE16TOH (qualcomm-&gt;MMTYPE), MMTYPE);
  142. #endif
  143. return (-1);
  144. }
  145. if ((MMTYPE &lt; VS_MMTYPE_MIN) || (MMTYPE &gt; VS_MMTYPE_MAX))
  146. {
  147. }
  148. else if (memcmp (localcast, qualcomm-&gt;OUI, sizeof (qualcomm-&gt;OUI)))
  149. {
  150. #if defined (__WHYNOT__)
  151. error (0, 0, &quot;Wrong Message Vendor&quot;);
  152. #endif
  153. return (-1);
  154. }
  155. }
  156. if (homeplug-&gt;homeplug.MMV == 1)
  157. {
  158. struct qualcomm_fmi * qualcomm = (struct qualcomm_fmi *)(&amp;homeplug-&gt;homeplug);
  159. #if FMI
  160. static unsigned total = 0;
  161. static unsigned index = 0;
  162. static unsigned count = 0;
  163. #endif
  164. if (LE16TOH (qualcomm-&gt;MMTYPE) != MMTYPE)
  165. {
  166. #if defined (__WHYNOT__)
  167. error (0, 0, &quot;Wrong Message Type: Received %04X while waiting for %04X&quot;, LE16TOH (qualcomm-&gt;MMTYPE), MMTYPE);
  168. #endif
  169. return (-1);
  170. }
  171. #if FMI
  172. index = qualcomm-&gt;FMID &gt;&gt; 0 &amp; 0x0F;
  173. if (!index)
  174. {
  175. total = qualcomm-&gt;FMID &gt;&gt; 4 &amp; 0x0F;
  176. count = qualcomm-&gt;FMID &gt;&gt; 0 &amp; 0x0F;
  177. if (memcmp (localcast, qualcomm-&gt;OUI, sizeof (qualcomm-&gt;OUI)))
  178. {
  179. #if defined (__WHYNOT__)
  180. error (0, 0, &quot;Wrong Message Vendor&quot;);
  181. #endif
  182. return (-1);
  183. }
  184. }
  185. if (index != count)
  186. {
  187. #if defined (__WHYNOT__)
  188. error (0, 0, &quot;Message Fragment Out-of-order&quot;);
  189. #endif
  190. return (-1);
  191. }
  192. if (count &gt; total)
  193. {
  194. #if defined (__WHYNOT__)
  195. error (0, 0, &quot;Fragment Count Exceeds Total&quot;);
  196. #endif
  197. return (-1);
  198. }
  199. count++;
  200. #endif
  201. }
  202. return (0);
  203. }
  204. #endif
  205. </pre>
  206. <div class='footerlink'>
  207. [<a href='uintspec.c.html' title=' uintspec.c '>PREV</a>]
  208. [<a href='toolkit.html' title=' Index '>HOME</a>]
  209. [<a href='UpgradeDevice1.c.html' title=' UpgradeDevice1.c '>NEXT</a>]
  210. </div>
  211. </body>
  212. </html>