1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281
|
/*====================================================================*
*
* Copyright (c) 2013 Qualcomm Atheros, Inc.
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or
* without modification, are permitted (subject to the limitations
* in the disclaimer below) provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* * Neither the name of Qualcomm Atheros nor the names of
* its contributors may be used to endorse or promote products
* derived from this software without specific prior written
* permission.
*
* NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
* GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE
* COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*--------------------------------------------------------------------*/
/*====================================================================*
*
* rules.h - Classification Rules Definitions and Declarations;
*
*. Qualcomm Atheros HomePlug AV Powerline Toolkit;
*: Copyright (c) 2006-2010 by Intellon Corporation; ALL RIGHTS RESERVED;
*; For demonstration and evaluation only; Not for production use.
*
* Contributor(s):
* Charles Maier
* Nathaniel Houghton
*
*--------------------------------------------------------------------*/
#ifndef RULES_HEADER
#define RULES_HEADER
/*====================================================================*
* system header files;
*--------------------------------------------------------------------*/
#include <stdint.h>
/*====================================================================*
* custom header files;
*--------------------------------------------------------------------*/
#include "../plc/plc.h"
#include "../tools/symbol.h"
/*====================================================================*
* constants;
*--------------------------------------------------------------------*/
#define CLASSIFIER_STRING 64
#define CLASSIFIER_CONTROLS 3
#define CLASSIFIER_VOLATILITIES 2
#define CLASSIFIER_ACTIONS 13
#define CLASSIFIER_OPERANDS 3
#define CLASSIFIER_OPERATORS 2
#define CLASSIFIER_STATES 8
#define CLASSIFIER_FIELDS 22
#define CLASSIFIER_CONTROL_NAME "control"
#define CLASSIFIER_VOLATILITY_NAME "volatility"
#define CLASSIFIER_ACTION_NAME "action"
#define CLASSIFIER_OPERAND_NAME "operand"
#define CLASSIFIER_OPERATOR_NAME "operator"
#define CLASSIFIER_STATE_NAME "state"
#define CLASSIFIER_FIELD_NAME "field"
#define CONTROL_ADD 0x00
#define CONTROL_REM 0x01
#define CONTROL_READ 0x02
#define CONTROL_REMOVE CONTROL_REM
#define VOLATILITY_TEMP 0x00
#define VOLATILITY_PERM 0x01
#define ACTION_CAP0 0x00
#define ACTION_CAP1 0x01
#define ACTION_CAP2 0x02
#define ACTION_CAP3 0x03
#define ACTION_DROP 0x04
#define ACTION_DROPTX ACTION_DROP
#define ACTION_BOOST 0x05
#define ACTION_DROPRX 0x06
#define ACTION_AUTOCONNECT 0x06
#define ACTION_STRIPTX 0x20
#define ACTION_STRIPRX 0x21
#define ACTION_TAGTX 0x22
#define ACTION_TAGRX 0x23
#define OPERAND_ALL 0x00
#define OPERAND_ANY 0x01
#define OPERAND_ALWAYS 0x02
#define OPERATOR_IS 0x00
#define OPERATOR_NOT 0x01
#define FIELD_ETH_DA 0x00
#define FIELD_ETH_SA 0x01
#define FIELD_VLAN_UP 0x02
#define FIELD_VLAN_ID 0x03
#define FIELD_IPV4_TOS 0x04
#define FIELD_IPV4_PROT 0x05
#define FIELD_IPV4_SA 0x06
#define FIELD_IPV4_DA 0x07
#define FIELD_IPV6_TC 0x08
#define FIELD_IPV6_FL 0x09
#define FIELD_IPV6_SA 0x0A
#define FIELD_IPV6_DA 0x0B
#define FIELD_TCP_SP 0x0C
#define FIELD_TCP_DP 0x0D
#define FIELD_UDP_SP 0x0E
#define FIELD_UDP_DP 0x0F
#define FIELD_IP_SP 0xE0
#define FIELD_IP_DP 0xE1
#define FIELD_HPAV_MME 0xE2
#define FIELD_ETH_TYPE 0xE3
#define FIELD_TCP_ACK 0xE4
#define FIELD_VLAN_TAG 0xE5
#define RULE_MAX_AUTOCONN 16
#define RULE_MAX_PRIORITY_MAPS 8
#define RULE_MAX_CLASSIFIERS 3
/*====================================================================*
* variables;
*--------------------------------------------------------------------*/
extern struct _code_ const controls [CLASSIFIER_CONTROLS];
extern struct _code_ const volatilities [CLASSIFIER_VOLATILITIES];
extern struct _code_ const actions [CLASSIFIER_ACTIONS];
extern struct _code_ const operands [CLASSIFIER_OPERANDS];
extern struct _code_ const fields [CLASSIFIER_FIELDS];
extern struct _code_ const operators [CLASSIFIER_OPERATORS];
extern struct _code_ const states [CLASSIFIER_STATES];
#ifndef __GNUC__
#pragma pack (push,1)
#endif
/*
* MME and PIB Classifier Rules are similar but differ in size
* and so we declare structures for each use; observe that
* function ParseRule uses the compact MMERule structure;
*/
typedef struct __packed cspec
{
uint16_t CSPEC_VERSION;
uint32_t VLAN_TAG;
uint32_t RSVD;
}
cspec;
typedef struct __packed MMEClassifier
{
uint8_t CR_PID;
uint8_t CR_OPERAND;
uint8_t CR_VALUE [16];
}
MMEClassifier;
typedef struct __packed PIBClassifier
{
uint32_t CR_PID;
uint32_t CR_OPERAND;
uint8_t CR_VALUE [16];
}
PIBClassifier;
typedef struct __packed MMERule
{
uint8_t MCONTROL;
uint8_t MVOLATILITY;
uint8_t MACTION;
uint8_t MOPERAND;
uint8_t NUM_CLASSIFIERS;
struct MMEClassifier CLASSIFIER [RULE_MAX_CLASSIFIERS];
struct cspec cspec;
}
MMERule;
typedef struct __packed PIBRule
{
uint8_t MCONTROL;
uint8_t MVOLATILITY;
uint8_t MACTION;
uint8_t MOPERAND;
uint32_t NUM_CLASSIFIERS;
struct PIBClassifier CLASSIFIER [RULE_MAX_CLASSIFIERS];
struct cspec cspec;
}
PIBRule;
typedef struct __packed classifier_priority_map
{
uint32_t Priority;
struct PIBClassifier CLASSIFIER;
}
classifier_priority_map;
typedef struct __packed auto_connection
{
uint8_t MACTION;
uint8_t MOPERAND;
uint16_t NUM_CLASSIFIERS;
struct PIBClassifier CLASSIFIER [RULE_MAX_CLASSIFIERS];
struct cspec cspec;
uint8_t RSVD [14];
}
auto_connection;
typedef struct __packed PIBClassifiers
{
uint32_t priority_count;
uint32_t autoconn_count;
struct classifier_priority_map classifier_priority_map [RULE_MAX_PRIORITY_MAPS];
struct auto_connection auto_connection [RULE_MAX_AUTOCONN];
}
PIBClassifiers;
#ifndef __GNUC__
#pragma pack (pop)
#endif
/*====================================================================*
* functions;
*--------------------------------------------------------------------*/
signed MakeRule (struct plc * plc, struct MMERule * rule);
signed ParseRule (int * argcp, char const ** argvp [], struct MMERule *, struct cspec *);
signed PrintRule (uint32_t CR_PID, uint32_t CR_OPERAND, uint8_t CR_VALUE []);
signed ReadRules (struct plc * plc);
void cspec_dump (struct cspec *);
void classifier_priority_map_dump (struct classifier_priority_map *);
void auto_connection_dump (struct auto_connection *);
void PIBClassifiersDump (struct PIBClassifiers *);
void PIBClassifierDump (struct PIBClassifier *);
void MMEClassifierDump (struct MMEClassifier *);
void PIBRuleDump (struct PIBRule *);
void MMERuleDump (struct MMERule *);
/*====================================================================*
*
*--------------------------------------------------------------------*/
#endif
|