rules.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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. * rules.h - Classification Rules Definitions and Declarations;
  44. *
  45. *. Qualcomm Atheros HomePlug AV Powerline Toolkit;
  46. *: Copyright (c) 2006-2010 by Intellon Corporation; ALL RIGHTS RESERVED;
  47. *; For demonstration and evaluation only; Not for production use.
  48. *
  49. * Contributor(s):
  50. * Charles Maier
  51. * Nathaniel Houghton
  52. *
  53. *--------------------------------------------------------------------*/
  54. #ifndef RULES_HEADER
  55. #define RULES_HEADER
  56. /*====================================================================*
  57. * system header files;
  58. *--------------------------------------------------------------------*/
  59. #include <stdint.h>
  60. /*====================================================================*
  61. * custom header files;
  62. *--------------------------------------------------------------------*/
  63. #include "../plc/plc.h"
  64. #include "../tools/symbol.h"
  65. /*====================================================================*
  66. * constants;
  67. *--------------------------------------------------------------------*/
  68. #define CLASSIFIER_STRING 64
  69. #define CLASSIFIER_CONTROLS 3
  70. #define CLASSIFIER_VOLATILITIES 2
  71. #define CLASSIFIER_ACTIONS 13
  72. #define CLASSIFIER_OPERANDS 3
  73. #define CLASSIFIER_OPERATORS 2
  74. #define CLASSIFIER_STATES 8
  75. #define CLASSIFIER_FIELDS 22
  76. #define CLASSIFIER_CONTROL_NAME "control"
  77. #define CLASSIFIER_VOLATILITY_NAME "volatility"
  78. #define CLASSIFIER_ACTION_NAME "action"
  79. #define CLASSIFIER_OPERAND_NAME "operand"
  80. #define CLASSIFIER_OPERATOR_NAME "operator"
  81. #define CLASSIFIER_STATE_NAME "state"
  82. #define CLASSIFIER_FIELD_NAME "field"
  83. #define CONTROL_ADD 0x00
  84. #define CONTROL_REM 0x01
  85. #define CONTROL_READ 0x02
  86. #define CONTROL_REMOVE CONTROL_REM
  87. #define VOLATILITY_TEMP 0x00
  88. #define VOLATILITY_PERM 0x01
  89. #define ACTION_CAP0 0x00
  90. #define ACTION_CAP1 0x01
  91. #define ACTION_CAP2 0x02
  92. #define ACTION_CAP3 0x03
  93. #define ACTION_DROP 0x04
  94. #define ACTION_DROPTX ACTION_DROP
  95. #define ACTION_BOOST 0x05
  96. #define ACTION_DROPRX 0x06
  97. #define ACTION_AUTOCONNECT 0x06
  98. #define ACTION_STRIPTX 0x20
  99. #define ACTION_STRIPRX 0x21
  100. #define ACTION_TAGTX 0x22
  101. #define ACTION_TAGRX 0x23
  102. #define OPERAND_ALL 0x00
  103. #define OPERAND_ANY 0x01
  104. #define OPERAND_ALWAYS 0x02
  105. #define OPERATOR_IS 0x00
  106. #define OPERATOR_NOT 0x01
  107. #define FIELD_ETH_DA 0x00
  108. #define FIELD_ETH_SA 0x01
  109. #define FIELD_VLAN_UP 0x02
  110. #define FIELD_VLAN_ID 0x03
  111. #define FIELD_IPV4_TOS 0x04
  112. #define FIELD_IPV4_PROT 0x05
  113. #define FIELD_IPV4_SA 0x06
  114. #define FIELD_IPV4_DA 0x07
  115. #define FIELD_IPV6_TC 0x08
  116. #define FIELD_IPV6_FL 0x09
  117. #define FIELD_IPV6_SA 0x0A
  118. #define FIELD_IPV6_DA 0x0B
  119. #define FIELD_TCP_SP 0x0C
  120. #define FIELD_TCP_DP 0x0D
  121. #define FIELD_UDP_SP 0x0E
  122. #define FIELD_UDP_DP 0x0F
  123. #define FIELD_IP_SP 0xE0
  124. #define FIELD_IP_DP 0xE1
  125. #define FIELD_HPAV_MME 0xE2
  126. #define FIELD_ETH_TYPE 0xE3
  127. #define FIELD_TCP_ACK 0xE4
  128. #define FIELD_VLAN_TAG 0xE5
  129. #define RULE_MAX_AUTOCONN 16
  130. #define RULE_MAX_PRIORITY_MAPS 8
  131. #define RULE_MAX_CLASSIFIERS 3
  132. /*====================================================================*
  133. * variables;
  134. *--------------------------------------------------------------------*/
  135. extern struct _code_ const controls [CLASSIFIER_CONTROLS];
  136. extern struct _code_ const volatilities [CLASSIFIER_VOLATILITIES];
  137. extern struct _code_ const actions [CLASSIFIER_ACTIONS];
  138. extern struct _code_ const operands [CLASSIFIER_OPERANDS];
  139. extern struct _code_ const fields [CLASSIFIER_FIELDS];
  140. extern struct _code_ const operators [CLASSIFIER_OPERATORS];
  141. extern struct _code_ const states [CLASSIFIER_STATES];
  142. #ifndef __GNUC__
  143. #pragma pack (push,1)
  144. #endif
  145. /*
  146. * MME and PIB Classifier Rules are similar but differ in size
  147. * and so we declare structures for each use; observe that
  148. * function ParseRule uses the compact MMERule structure;
  149. */
  150. typedef struct __packed cspec
  151. {
  152. uint16_t CSPEC_VERSION;
  153. uint32_t VLAN_TAG;
  154. uint32_t RSVD;
  155. }
  156. cspec;
  157. typedef struct __packed MMEClassifier
  158. {
  159. uint8_t CR_PID;
  160. uint8_t CR_OPERAND;
  161. uint8_t CR_VALUE [16];
  162. }
  163. MMEClassifier;
  164. typedef struct __packed PIBClassifier
  165. {
  166. uint32_t CR_PID;
  167. uint32_t CR_OPERAND;
  168. uint8_t CR_VALUE [16];
  169. }
  170. PIBClassifier;
  171. typedef struct __packed MMERule
  172. {
  173. uint8_t MCONTROL;
  174. uint8_t MVOLATILITY;
  175. uint8_t MACTION;
  176. uint8_t MOPERAND;
  177. uint8_t NUM_CLASSIFIERS;
  178. struct MMEClassifier CLASSIFIER [RULE_MAX_CLASSIFIERS];
  179. struct cspec cspec;
  180. }
  181. MMERule;
  182. typedef struct __packed PIBRule
  183. {
  184. uint8_t MCONTROL;
  185. uint8_t MVOLATILITY;
  186. uint8_t MACTION;
  187. uint8_t MOPERAND;
  188. uint32_t NUM_CLASSIFIERS;
  189. struct PIBClassifier CLASSIFIER [RULE_MAX_CLASSIFIERS];
  190. struct cspec cspec;
  191. }
  192. PIBRule;
  193. typedef struct __packed classifier_priority_map
  194. {
  195. uint32_t Priority;
  196. struct PIBClassifier CLASSIFIER;
  197. }
  198. classifier_priority_map;
  199. typedef struct __packed auto_connection
  200. {
  201. uint8_t MACTION;
  202. uint8_t MOPERAND;
  203. uint16_t NUM_CLASSIFIERS;
  204. struct PIBClassifier CLASSIFIER [RULE_MAX_CLASSIFIERS];
  205. struct cspec cspec;
  206. uint8_t RSVD [14];
  207. }
  208. auto_connection;
  209. typedef struct __packed PIBClassifiers
  210. {
  211. uint32_t priority_count;
  212. uint32_t autoconn_count;
  213. struct classifier_priority_map classifier_priority_map [RULE_MAX_PRIORITY_MAPS];
  214. struct auto_connection auto_connection [RULE_MAX_AUTOCONN];
  215. }
  216. PIBClassifiers;
  217. #ifndef __GNUC__
  218. #pragma pack (pop)
  219. #endif
  220. /*====================================================================*
  221. * functions;
  222. *--------------------------------------------------------------------*/
  223. signed MakeRule (struct plc * plc, struct MMERule * rule);
  224. signed ParseRule (int * argcp, char const ** argvp [], struct MMERule *, struct cspec *);
  225. signed PrintRule (uint32_t CR_PID, uint32_t CR_OPERAND, uint8_t CR_VALUE []);
  226. signed ReadRules (struct plc * plc);
  227. void cspec_dump (struct cspec *);
  228. void classifier_priority_map_dump (struct classifier_priority_map *);
  229. void auto_connection_dump (struct auto_connection *);
  230. void PIBClassifiersDump (struct PIBClassifiers *);
  231. void PIBClassifierDump (struct PIBClassifier *);
  232. void MMEClassifierDump (struct MMEClassifier *);
  233. void PIBRuleDump (struct PIBRule *);
  234. void MMERuleDump (struct MMERule *);
  235. /*====================================================================*
  236. *
  237. *--------------------------------------------------------------------*/
  238. #endif