eapol/eapol_framework/eapol_common/type/simple_config/simple_config/include/simple_config_payloads.h
changeset 0 c8830336c852
child 2 1c7bc153c08e
equal deleted inserted replaced
-1:000000000000 0:c8830336c852
       
     1 /*
       
     2 * Copyright (c) 2001-2006 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  EAP and WLAN authentication protocols.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #if !defined(_SIMPLE_CONFIG_PAYLOADS_H_)
       
    22 #define _SIMPLE_CONFIG_PAYLOADS_H_
       
    23 
       
    24 #include "eap_variable_data.h"
       
    25 #include "eap_am_export.h"
       
    26 #include "simple_config_tlv_header.h"
       
    27 #include "simple_config_attribute_type.h"
       
    28 #include "eap_core_map.h"
       
    29 #include "eap_array.h"
       
    30 
       
    31 class simple_config_message_c;
       
    32 class crypto_hmac_c;
       
    33 
       
    34 class EAP_EXPORT simple_config_variable_data_c
       
    35 {
       
    36 private:
       
    37 	//--------------------------------------------------
       
    38 
       
    39 	abs_eap_am_tools_c * const m_am_tools;
       
    40 
       
    41 	eap_variable_data_c m_data;
       
    42 
       
    43 	simple_config_tlv_header_c m_header;
       
    44 
       
    45 	/// This is pointer to the next payload that have same attribute type.
       
    46 	/// This link is used when multiple instances of the same attribute types are included to a message.
       
    47 	simple_config_variable_data_c * m_next_payload_with_same_attribute_type;
       
    48 
       
    49 	bool m_is_mandatory;
       
    50 
       
    51 	bool m_is_valid;
       
    52 
       
    53 	//--------------------------------------------------
       
    54 protected:
       
    55 	//--------------------------------------------------
       
    56 
       
    57 	//--------------------------------------------------
       
    58 public:
       
    59 	//--------------------------------------------------
       
    60 
       
    61 	EAP_FUNC_IMPORT virtual ~simple_config_variable_data_c();
       
    62 
       
    63 	EAP_FUNC_IMPORT simple_config_variable_data_c(abs_eap_am_tools_c * const tools);
       
    64 
       
    65 	EAP_FUNC_IMPORT bool get_is_valid() const;
       
    66 
       
    67 	EAP_FUNC_IMPORT eap_status_e set_copy_of_buffer(
       
    68 		const simple_config_Attribute_Type_e current_payload_code,
       
    69 		const bool is_mandatory,
       
    70 		const void * const buffer,
       
    71 		const u32_t buffer_length);
       
    72 
       
    73 	EAP_FUNC_IMPORT eap_status_e add_data(
       
    74 		const void * const buffer,
       
    75 		const u32_t buffer_length);
       
    76 
       
    77 	EAP_FUNC_IMPORT u32_t get_data_length() const;
       
    78 
       
    79 	EAP_FUNC_IMPORT u8_t * get_data(const u32_t data_length) const;
       
    80 
       
    81 	simple_config_tlv_header_c * get_header();
       
    82 
       
    83 	EAP_FUNC_IMPORT eap_variable_data_c * get_full_attribute_buffer();
       
    84 
       
    85 	EAP_FUNC_IMPORT simple_config_Attribute_Type_e get_attribute_type() const;
       
    86 
       
    87 	EAP_FUNC_IMPORT bool get_is_mandatory() const;
       
    88 
       
    89 	EAP_FUNC_IMPORT void set_attribute_type(const simple_config_Attribute_Type_e type);
       
    90 
       
    91 	EAP_FUNC_IMPORT void add_next_payload_with_same_attribute_type(simple_config_variable_data_c * const attribute);
       
    92 
       
    93 	EAP_FUNC_IMPORT void set_next_payload_with_same_attribute_type(simple_config_variable_data_c * attribute);
       
    94 
       
    95 	EAP_FUNC_IMPORT simple_config_variable_data_c * get_next_payload_with_same_attribute_type();
       
    96 
       
    97 	EAP_FUNC_IMPORT simple_config_variable_data_c * copy() const;
       
    98 
       
    99 	EAP_FUNC_IMPORT void object_increase_reference_count();
       
   100 
       
   101 	EAP_FUNC_IMPORT eap_status_e check_header() const;
       
   102 
       
   103 	//--------------------------------------------------
       
   104 }; // class simple_config_variable_data_c
       
   105 
       
   106 
       
   107 //--------------------------------------------------
       
   108 
       
   109 
       
   110 // 
       
   111 class EAP_EXPORT simple_config_payloads_c
       
   112 : public abs_eap_core_map_c
       
   113 {
       
   114 private:
       
   115 	//--------------------------------------------------
       
   116 
       
   117 	abs_eap_am_tools_c * const m_am_tools;
       
   118 
       
   119 	/// This stores the simple_config_variable_data_c objects using eap_variable_data selector.
       
   120 	eap_core_map_c<simple_config_variable_data_c, abs_eap_core_map_c, eap_variable_data_c> m_payload_map;
       
   121 
       
   122 	/// This stores the same simple_config_variable_data_c objects to array.
       
   123 	/// This is to speed the sequential check of all payloads.
       
   124 	eap_array_c<simple_config_variable_data_c> m_read_payloads;
       
   125 
       
   126 	/// This index is used when payloads are retrieved in order.
       
   127 	u32_t m_payload_index;
       
   128 
       
   129 	bool m_is_valid;
       
   130 
       
   131 	eap_status_e verify_padding(
       
   132 		const u8_t * const possible_padding,
       
   133 		const u32_t possible_padding_length);
       
   134 
       
   135 	eap_status_e get_attribute_data(
       
   136 		const simple_config_Attribute_Type_e copied_attribute_type,
       
   137 		void * const data,
       
   138 		const u32_t data_length) const;
       
   139 
       
   140 	//--------------------------------------------------
       
   141 protected:
       
   142 	//--------------------------------------------------
       
   143 
       
   144 	//--------------------------------------------------
       
   145 public:
       
   146 	//--------------------------------------------------
       
   147 
       
   148 	EAP_FUNC_IMPORT virtual ~simple_config_payloads_c();
       
   149 
       
   150 	EAP_FUNC_IMPORT simple_config_payloads_c(
       
   151 		abs_eap_am_tools_c * const tools);
       
   152 
       
   153 	EAP_FUNC_IMPORT simple_config_variable_data_c * get_attribute_pointer(
       
   154 		const simple_config_Attribute_Type_e current_payload,
       
   155 		u32_t index) const;
       
   156 
       
   157 	EAP_FUNC_IMPORT simple_config_variable_data_c * get_attribute_pointer(
       
   158 		const simple_config_Attribute_Type_e current_payload) const;
       
   159 
       
   160 
       
   161 	EAP_FUNC_IMPORT u32_t get_attribute_count() const;
       
   162 
       
   163 	EAP_FUNC_IMPORT simple_config_variable_data_c * get_attribute(const u32_t attribute_index) const;
       
   164 
       
   165 	/**
       
   166 	 * This function adds new_payload object to payloads.
       
   167 	 * NOTE the data is NOT copied.
       
   168 	 */
       
   169 	EAP_FUNC_IMPORT eap_status_e add_attribute(
       
   170 		simple_config_variable_data_c *new_payload);
       
   171 
       
   172 	/**
       
   173 	 * This function copies the selected attribute from source to payloads.
       
   174 	 */
       
   175 	EAP_FUNC_IMPORT eap_status_e copy_attribute(
       
   176 		const simple_config_payloads_c * const source,
       
   177 		const simple_config_Attribute_Type_e attribute);
       
   178 
       
   179 	/**
       
   180 	 * This function copies the attribute data to payloads.
       
   181 	 */
       
   182 	EAP_FUNC_IMPORT eap_status_e copy_attribute_data(
       
   183 		const simple_config_Attribute_Type_e current_payload,
       
   184 		const bool is_mandatory,
       
   185 		const void * const data,
       
   186 		const u32_t data_length);
       
   187 
       
   188 	/**
       
   189 	 *	Function retrieves data of attribute type to data object.
       
   190 	 */
       
   191 	EAP_FUNC_IMPORT eap_status_e get_attribute_data(
       
   192 		const simple_config_Attribute_Type_e copied_attribute_type,
       
   193 		eap_variable_data_c * const data) const;
       
   194 
       
   195 	/**
       
   196 	 *	Function retrieves data of attribute type to data object.
       
   197 	 */
       
   198 	EAP_FUNC_IMPORT eap_status_e get_attribute_data(
       
   199 		const simple_config_Attribute_Type_e copied_attribute_type,
       
   200 		u8_t * const data) const;
       
   201 
       
   202 	/**
       
   203 	 *	Function retrieves data of attribute type to data object.
       
   204 	 */
       
   205 	EAP_FUNC_IMPORT eap_status_e get_attribute_data(
       
   206 		const simple_config_Attribute_Type_e copied_attribute_type,
       
   207 		u16_t * const data) const;
       
   208 
       
   209 	/**
       
   210 	 *	Function retrieves data of attribute type to data object.
       
   211 	 */
       
   212 	EAP_FUNC_IMPORT eap_status_e get_attribute_data(
       
   213 		const simple_config_Attribute_Type_e copied_attribute_type,
       
   214 		u32_t * const data) const;
       
   215 
       
   216 	/**
       
   217 	 *	Function retrieves data of attribute type to data object.
       
   218 	 */
       
   219 	EAP_FUNC_IMPORT eap_status_e get_attribute_data(
       
   220 		const simple_config_Attribute_Type_e copied_attribute_type,
       
   221 		u64_t * const data) const;
       
   222 
       
   223 	/**
       
   224 	 * This function parses the payloads starting from specified payload (p_payload).
       
   225 	 * Function parses all payloads from the buffer.
       
   226 	 * Payloads are stored to member variables.
       
   227 	 * @return If the length of the buffer and sum of the length of all payloads does not match
       
   228 	 * function returns eap_status_header_corrupted.
       
   229 	 * Also error is returned when illegal payload attribute is recognised.
       
   230 	 */
       
   231 	EAP_FUNC_IMPORT eap_status_e parse_simple_config_payloads(
       
   232 		void * const message_buffer, ///< This is the start of the message buffer.
       
   233 		u32_t * const buffer_length, ///< This is the length of the buffer. This must match with the length of all payloads.
       
   234 		u32_t * const padding_length ///< Length of possible padding is set to this variable.
       
   235 		);
       
   236 
       
   237 	/**
       
   238 	 * This function parses each payload attributes.
       
   239 	 * @return If payload attribute is illegal function returns eap_status_header_corrupted.
       
   240 	 * If payload attribute is unknown function returns eap_status_unsupported_payload.
       
   241 	 */
       
   242 	EAP_FUNC_IMPORT eap_status_e parse_generic_payload(
       
   243 		const simple_config_Attribute_Type_e current_payload, ///< This is the type of current payload attribute.
       
   244 		const simple_config_tlv_header_c * const payload ///< This is the current parsed payload.
       
   245 		);
       
   246 
       
   247 	EAP_FUNC_IMPORT eap_status_e check_payloads_existense(
       
   248 		const simple_config_Attribute_Type_e * const needed_payloads,
       
   249 		const u32_t count_of_needed_payloads) const;
       
   250 
       
   251 	/**
       
   252 	 * This function checks all mandatory AVPs are used.
       
   253 	 */
       
   254 	EAP_FUNC_IMPORT eap_status_e check_mandatory_payloads(
       
   255 		EAP_TEMPLATE_CONST eap_array_c<simple_config_Attribute_Type_e> * const used_payloads) const;
       
   256 
       
   257 	/**
       
   258 	 * This function checks all required AVPs are received.
       
   259 	 */
       
   260 	EAP_FUNC_IMPORT eap_status_e check_payloads_existense(
       
   261 		EAP_TEMPLATE_CONST eap_array_c<simple_config_Attribute_Type_e> * const needed_payloads) const;
       
   262 
       
   263 	EAP_FUNC_IMPORT bool get_is_valid() const;
       
   264 
       
   265 	EAP_FUNC_IMPORT eap_status_e create_simple_config_message(
       
   266 		simple_config_message_c * const new_simple_config_message_data,
       
   267 		const bool add_payloads) const;
       
   268 
       
   269 	EAP_FUNC_IMPORT eap_status_e add_payloads_to_simple_config_authenticator(
       
   270 		crypto_hmac_c * const hmac_sha_256,
       
   271 		const bool include_authenticator_attribute) const;
       
   272 
       
   273 	EAP_FUNC_IMPORT eap_status_e reset();
       
   274 
       
   275 	EAP_FUNC_IMPORT simple_config_payloads_c * copy() const;
       
   276 
       
   277 	//--------------------------------------------------
       
   278 }; // class simple_config_payloads_c
       
   279 
       
   280 
       
   281 #endif //#if !defined(_SIMPLE_CONFIG_PAYLOADS_H_)
       
   282 
       
   283 //--------------------------------------------------
       
   284 
       
   285 
       
   286 
       
   287 // End.