eapol/eapol_framework/wapi_common/include/wai_protocol_packet_header.h
changeset 17 8840d3e38314
equal deleted inserted replaced
2:1c7bc153c08e 17:8840d3e38314
       
     1 /*
       
     2 * ============================================================================
       
     3 *  Name        : ./accesssec/eapol/eapol_framework/wapi_common/include/wai_protocol_packet_header.h
       
     4 *  Part of     : WAPI / WAPI       *** Info from the SWAD
       
     5 *  Description : WAPI authentication
       
     6 *  Version     : %version: 16 % << Don't touch! Updated by Synergy at check-out.
       
     7 *
       
     8 *  Copyright © 2001-2009 Nokia.  All rights reserved.
       
     9 *  This material, including documentation and any related computer
       
    10 *  programs, is protected by copyright controlled by Nokia.  All
       
    11 *  rights are reserved.  Copying, including reproducing, storing,
       
    12 *  adapting or translating, any or all of this material requires the
       
    13 *  prior written consent of Nokia.  This material also contains
       
    14 *  confidential information which may not be disclosed to others
       
    15 *  without the prior written consent of Nokia.
       
    16 * ============================================================================
       
    17 * Template version: 4.2
       
    18 */
       
    19 
       
    20 
       
    21 
       
    22 #if !defined(_WAI_PROTOCOL_PACKET_HEADER_H_)
       
    23 #define _WAI_PROTOCOL_PACKET_HEADER_H_
       
    24 
       
    25 #if defined(USE_WAPI_CORE)
       
    26 
       
    27 #include "eap_tools.h"
       
    28 #include "wapi_types.h"
       
    29 #include "eap_general_header_base.h"
       
    30 
       
    31 /** @file */
       
    32 
       
    33 
       
    34 //----------------------------------------------------------------------------
       
    35 
       
    36 
       
    37 /// This class defines header of WAI protocol packet.
       
    38 /**
       
    39  * Here is a figure of header of WAI protocol packet.
       
    40  * Data follows wai_protocol_packet_header_c.
       
    41  * @code
       
    42  *  TLV-header:
       
    43  * 0                   1                   2                   3   
       
    44  *  0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 
       
    45  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
    46  * |            Version            |     Type      |    Subtype    |
       
    47  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
    48  * |            Reserved           |          Length               |
       
    49  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
    50  * |    Packet sequence number     |Frag. Seg. No. |     Flag      |
       
    51  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
    52  * | Data ...                                                       
       
    53  * +-+-+-+-+-                                                       
       
    54  * @endcode
       
    55  * 
       
    56  * For details see <a href="../../../internal/doc/WAPI/WAPI_design.doc">WAPI_design.doc</a>.
       
    57  */
       
    58 class EAP_EXPORT wai_protocol_packet_header_c
       
    59 : public eap_general_header_base_c
       
    60 {
       
    61 private:
       
    62 	//--------------------------------------------------
       
    63 
       
    64 	/// This is pointer to the tools class.
       
    65 	abs_eap_am_tools_c * const m_am_tools;
       
    66 
       
    67 	//--------------------------------------------------
       
    68 public:
       
    69 	//--------------------------------------------------
       
    70 
       
    71 	/// This is enumeration of masks of Flag field.
       
    72 	enum flag_masks
       
    73 	{
       
    74 		m_flag_mask_fragment_exists = 0x01,
       
    75 	};
       
    76 
       
    77 	/// This is enumeration of sizes of fields.
       
    78 	enum sizes
       
    79 	{
       
    80 		m_version_size = sizeof(u16_t),                 ///< This is size of Version 16-bit field.
       
    81 		m_type_size = sizeof(u8_t),                     ///< This is size of Type 8-bit field.
       
    82 		m_subtype_size = sizeof(u8_t),                  ///< This is size of Subtype 8-bit field.
       
    83 		m_reserved_size = sizeof(u16_t),                ///< This is size of Reserved 16-bit field.
       
    84 		m_length_size = sizeof(u16_t),                  ///< This is size of Length 16-bit field.
       
    85 		m_packet_sequence_number_size = sizeof(u16_t),  ///< This is size of Packet sequence number 16-bit field.
       
    86 		m_fragment_sequence_number_size = sizeof(u8_t), ///< This is size of Fragment sequence number 8-bit field.
       
    87 		m_flag_size = sizeof(u8_t),                     ///< This is size of Flag 8-bit field.
       
    88 	};
       
    89 
       
    90 	/// This is enumeration of offsets to data fields.
       
    91 	enum offsets
       
    92 	{
       
    93 		m_version_offset = 0ul,                                                                            ///< This is offset to Version 16-bit field.
       
    94 		m_type_offset = m_version_offset+m_version_size,                                                   ///< This is offset to Type 8-bit field.
       
    95 		m_subtype_offset = m_type_offset+m_type_size,                                                      ///< This is offset to Subtype 8-bit field.
       
    96 		m_reserved_offset = m_subtype_offset+m_subtype_size,                                               ///< This is offset to Reserved 16-bit field.
       
    97 		m_length_offset = m_reserved_offset+m_reserved_size,                                               ///< This is offset to Length 16-bit field.
       
    98 		m_packet_sequence_number_offset = m_length_offset+m_length_size,                                   ///< This is offset to Packet sequence number 16-bit field.
       
    99 		m_fragment_sequence_number_offset = m_packet_sequence_number_offset+m_packet_sequence_number_size, ///< This is offset to Fragment sequence number 8-bit field.
       
   100 		m_flag_offset = m_fragment_sequence_number_offset+m_fragment_sequence_number_size,                 ///< This is offset to Flag 8-bit field.
       
   101 		m_data_offset = m_flag_offset+m_flag_size,                                                         ///< This is offset to Data.
       
   102 	};
       
   103 
       
   104 	/**
       
   105 	 * The destructor of the wai_protocol_packet_header_c class does nothing.
       
   106 	 */
       
   107 	virtual ~wai_protocol_packet_header_c();
       
   108 
       
   109 	/**
       
   110 	 * The constructor of the wai_protocol_packet_header_c class.
       
   111 	 */
       
   112 	wai_protocol_packet_header_c(
       
   113 		abs_eap_am_tools_c * const tools);
       
   114 
       
   115 	/**
       
   116 	 * The constructor of the wai_protocol_packet_header_c class simply initializes the attributes.
       
   117 	 */
       
   118 	wai_protocol_packet_header_c(
       
   119 		abs_eap_am_tools_c * const tools,
       
   120 		void * const header_begin,
       
   121 		const u32_t header_buffer_length);
       
   122 
       
   123 	// - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       
   124 
       
   125 	/**
       
   126 	 * This function sets the header buffer.
       
   127 	 */
       
   128 	eap_status_e set_header_buffer(
       
   129 		void * const header_begin,
       
   130 		const u32_t header_buffer_length);
       
   131 
       
   132 	// - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       
   133 
       
   134 	/**
       
   135 	 * This function returns the Version value.
       
   136 	 */
       
   137 	wai_protocol_version_e get_version() const;
       
   138 
       
   139 	/**
       
   140 	 * This function returns the Type value.
       
   141 	 */
       
   142 	wai_protocol_type_e get_type() const;
       
   143 
       
   144 	/**
       
   145 	 * This function returns the Subtype value.
       
   146 	 */
       
   147 	wai_protocol_subtype_e get_subtype() const;
       
   148 
       
   149 	/**
       
   150 	 * This function returns the Reserved value.
       
   151 	 */
       
   152 	u16_t get_reserved() const;
       
   153 
       
   154 	/**
       
   155 	 * This function returns the Length value.
       
   156 	 */
       
   157 	u32_t get_length() const;
       
   158 
       
   159 	/**
       
   160 	 * This function returns the Packet sequence number value.
       
   161 	 */
       
   162 	u16_t get_packet_sequence_number() const;
       
   163 
       
   164 	/**
       
   165 	 * This function returns the Fragment sequence number value.
       
   166 	 */
       
   167 	u8_t get_fragment_sequence_number() const;
       
   168 
       
   169 	/**
       
   170 	 * This function returns the Flag value.
       
   171 	 */
       
   172 	u8_t get_flag() const;
       
   173 
       
   174 	/**
       
   175 	 * This function returns the header length of WAI protocol packet.
       
   176 	 */
       
   177 	static u32_t get_header_length();
       
   178 
       
   179 	/**
       
   180 	 * This function returns the data length of WAI protocol packet.
       
   181 	 */
       
   182 	u32_t get_data_length() const;
       
   183 
       
   184 	/**
       
   185 	 * This function returns pointer to the offset of data of WAI protocol packet.
       
   186 	 * @param offset is the offset of queried data in bytes.
       
   187 	 * @param contignuous_bytes is the length of queried data in bytes.
       
   188 	 */
       
   189 	u8_t * get_data_offset(const u32_t offset, const u32_t contignuous_bytes) const;
       
   190 
       
   191 
       
   192 	/**
       
   193 	 * This function returns pointer to the begin of data of WAI protocol packet.
       
   194 	 * @param contignuous_bytes is the length of queried data in bytes.
       
   195 	 */
       
   196 	u8_t * get_data(const u32_t contignuous_bytes) const;
       
   197 
       
   198 	// - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       
   199 
       
   200 	/**
       
   201 	 * This function checks the header is valid.
       
   202 	 */
       
   203 	eap_status_e check_header() const;
       
   204 
       
   205 	// - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       
   206 
       
   207 	/**
       
   208 	 * This function sets the Version value.
       
   209 	 */
       
   210 	eap_status_e set_version(const wai_protocol_version_e version);
       
   211 
       
   212 	/**
       
   213 	 * This function sets the Type value.
       
   214 	 */
       
   215 	eap_status_e set_type(const wai_protocol_type_e type);
       
   216 
       
   217 	/**
       
   218 	 * This function sets the Subype value.
       
   219 	 */
       
   220 	eap_status_e set_subtype(const wai_protocol_subtype_e subtype);
       
   221 
       
   222 	/**
       
   223 	 * This function sets the Reserved value.
       
   224 	 */
       
   225 	eap_status_e set_reserved(const u16_t reserved);
       
   226 
       
   227 	/**
       
   228 	 * This function sets the Length value.
       
   229 	 */
       
   230 	eap_status_e set_length(const u32_t length);
       
   231 
       
   232 	/**
       
   233 	 * This function sets the Packet sequence number value.
       
   234 	 */
       
   235 	eap_status_e set_packet_sequence_number(const u16_t packet_sequence_number);
       
   236 
       
   237 	/**
       
   238 	 * This function sets the Fragment sequence number value.
       
   239 	 */
       
   240 	eap_status_e set_fragment_sequence_number(const u8_t fragment_sequence_number);
       
   241 
       
   242 	/**
       
   243 	 * This function sets the Flag value.
       
   244 	 */
       
   245 	eap_status_e set_flag(const u8_t flag);
       
   246 
       
   247 	// - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       
   248 
       
   249 	/**
       
   250 	 * This function resets the WAI protocol packet header.
       
   251 	 */
       
   252 	eap_status_e reset_header();
       
   253 
       
   254 	// 
       
   255 	//--------------------------------------------------
       
   256 }; // class wai_protocol_packet_header_c
       
   257 
       
   258 //----------------------------------------------------------------------------------
       
   259 
       
   260 /// Macro traces payload type and data.
       
   261 #define WAI_PROTOCOL_PACKET_TRACE_HEADER(prefix, header, when_true_is_client) \
       
   262 	{ \
       
   263 		EAP_TRACE_DEBUG( \
       
   264 			m_am_tools, TRACE_FLAGS_DEFAULT|TRACE_TEST_VECTORS, \
       
   265 			(EAPL("v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v \n"))); \
       
   266 		EAP_TRACE_DATA_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT|TRACE_TEST_VECTORS, \
       
   267 			(EAPL("- buffer"), (header)->get_header_buffer((header)->get_header_buffer_length()), \
       
   268 			(header)->get_header_buffer_length())); \
       
   269 		EAP_TRACE_DEBUG( \
       
   270 			m_am_tools, TRACE_FLAGS_DEFAULT|TRACE_TEST_VECTORS, \
       
   271 			(EAPL("- %s, %s (0x%08x): Version=%d, Type=%d, Subtype=%d=%s, Reserved=%d,\n"), \
       
   272 			prefix, \
       
   273 			((when_true_is_client) == true ? "client" : "server"), \
       
   274 			(header)->get_header_buffer((header)->get_header_buffer_length()), \
       
   275 			(header)->get_version(), \
       
   276 			(header)->get_type(), \
       
   277 			(header)->get_subtype(), \
       
   278 			wapi_strings_c::get_wai_protocol_subtype_string((header)->get_subtype()), \
       
   279 			(header)->get_reserved())); \
       
   280 		EAP_TRACE_DEBUG( \
       
   281 			m_am_tools, TRACE_FLAGS_DEFAULT|TRACE_TEST_VECTORS, \
       
   282 			(EAPL("- %s, %s (0x%08x): Length=%d, Packet sequence number=%d, Fragment sequence number=%d, Flag=%d, data length 0x%04x.\n"), \
       
   283 			prefix, \
       
   284 			((when_true_is_client) == true ? "client" : "server"), \
       
   285 			(header)->get_header_buffer((header)->get_header_buffer_length()), \
       
   286 			(header)->get_length(), \
       
   287 			(header)->get_packet_sequence_number(), \
       
   288 			(header)->get_fragment_sequence_number(), \
       
   289 			(header)->get_flag(), \
       
   290 			(header)->get_data_length())); \
       
   291 		EAP_TRACE_DATA_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT|TRACE_TEST_VECTORS, \
       
   292 			(wapi_strings_c::get_wai_protocol_subtype_string((header)->get_subtype()), \
       
   293 			(header)->get_header_buffer((header)->get_header_buffer_length()), \
       
   294 			(header)->get_header_buffer_length())); \
       
   295 		EAP_TRACE_DEBUG( \
       
   296 			m_am_tools, TRACE_FLAGS_DEFAULT|TRACE_TEST_VECTORS, \
       
   297 			(EAPL("^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ \n"))); \
       
   298 	}
       
   299 
       
   300 //----------------------------------------------------------------------------------
       
   301 
       
   302 #endif //#if defined(USE_WAPI_CORE)
       
   303 
       
   304 #endif //#if !defined(_WAI_PROTOCOL_PACKET_HEADER_H_)
       
   305 
       
   306 
       
   307 
       
   308 // End.