eapol/eapol_framework/eapol_common/include/eap_buffer.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(_EAP_BUFFER_H_)
       
    22 #define _EAP_BUFFER_H_
       
    23 
       
    24 #include "eap_am_assert.h"
       
    25 #include "eap_variable_data.h"
       
    26 
       
    27 //--------------------------------------------------
       
    28 
       
    29 const u32_t EAP_MAX_LOCAL_PACKET_BUFFER_LENGTH = 1514;
       
    30 
       
    31 const u8_t EAP_MEM_GUARD_BYTE = 0x55;
       
    32 
       
    33 #if defined(_DEBUG) && defined(USE_EAP_MEM_GUARD)
       
    34 
       
    35 	const u32_t EAP_MEM_GUARD_LENGTH = 256u;
       
    36 
       
    37 	#define EAP_MEM_GUARDS(buffer_size) \
       
    38 		(EAP_MEM_GUARD_LENGTH+(buffer_size)+EAP_MEM_GUARD_LENGTH)
       
    39 
       
    40 #else
       
    41 
       
    42 	const u32_t EAP_MEM_GUARD_LENGTH = 0u;
       
    43 
       
    44 	#define EAP_MEM_GUARDS(buffer_size) (buffer_size)
       
    45 
       
    46 #endif //#if defined(_DEBUG) && defined(USE_EAP_MEM_GUARD)
       
    47 
       
    48 
       
    49 
       
    50 enum eap_write_buffer_e
       
    51 {
       
    52 	eap_write_buffer
       
    53 };
       
    54 
       
    55 
       
    56 enum eap_read_buffer_e
       
    57 {
       
    58 	eap_read_buffer
       
    59 };
       
    60 
       
    61 enum eap_random_error_type
       
    62 {
       
    63 	eap_random_error_type_manipulate_byte = 0,
       
    64 	eap_random_error_type_change_packet_length_longer,
       
    65 	eap_random_error_type_change_packet_length_shorter,
       
    66 	eap_random_error_type_none_keep_this_last_case,
       
    67 };
       
    68 
       
    69 //--------------------------------------------------
       
    70 
       
    71 class abs_eap_am_tools_c;
       
    72 class eapol_ethernet_header_wr_c;
       
    73 class eapol_ethernet_header_rd_c;
       
    74 
       
    75 
       
    76 /// Network packets are handled through eap_buf_chain_base_c class.
       
    77 class EAP_EXPORT eap_buf_chain_base_c
       
    78 {
       
    79 private:
       
    80 	//--------------------------------------------------
       
    81 
       
    82 	/// This is pointer to the tools class.
       
    83 	abs_eap_am_tools_c * const m_am_tools;
       
    84 
       
    85 	/// This struct decreases the memory print of eap_buf_chain_base_c.
       
    86 	struct eap_buf_chain_base_impl_str
       
    87 	{
       
    88 		/// This is the count of guard bytes allocated before and after the buffer.
       
    89 		u32_t m_mem_guard_length;
       
    90 
       
    91 		eap_variable_data_c * m_buffer;
       
    92 
       
    93 		/// This is pointer to the next buffer. NOTE this is NOT used in current version.
       
    94 		eap_buf_chain_base_c *m_next_buffer;
       
    95 
       
    96 		/// This is used to test protocol with manipulated packets. This is used in testing.
       
    97 		eap_random_error_type m_random_error_type;
       
    98 
       
    99 		/// This is used to test protocol with manipulated packets. This is used in testing.
       
   100 		u32_t m_send_packet_index;
       
   101 
       
   102 		/// This the pointer of sender stack.
       
   103 		/// This is used in testing.
       
   104 		const void *m_stack_address;
       
   105 
       
   106 		/// This indicates the buffer is initialized.
       
   107 		bool m_is_valid;
       
   108 
       
   109 		/// This is used to mark packet if it is manipulated. This is used in testing.
       
   110 		bool m_is_manipulated;
       
   111 
       
   112 		/// When this parameter is true eap_core_c activates re-transmission of this packet.
       
   113 		/// When this parameter is false eap_core_c does not activate re-transmission of this packet.
       
   114 		bool m_do_packet_retransmission;
       
   115 
       
   116 		/// This is tells whether the sender is client or server.
       
   117 		/// This is used in testing.
       
   118 		bool m_is_client;
       
   119 
       
   120 		/// This is used in testing.
       
   121 		bool m_do_length_checks;
       
   122 
       
   123 		/// This flag tells whether this packet must be encrypted (true) or not (false).
       
   124 		/// Encryption means the WLAN data encryption on the air (WEP, TKIP or CCMP).
       
   125 		/// Using this flag to tell the encryption allows the configuration of the
       
   126 		/// temporal key beforehand the key is used.
       
   127 		/// This is optimization to fasten the key configuration.
       
   128 		bool m_encrypt;
       
   129 	};
       
   130 
       
   131 	/// This is pointer to data of eap_buf_chain_base_c.
       
   132 	/// This decreases memory print of eap_buf_chain_base_c.
       
   133 	/// This decreases stack usage of EAP_Core.
       
   134 	eap_buf_chain_base_impl_str *  m_data;
       
   135 
       
   136 	//--------------------------------------------------
       
   137 
       
   138 	/**
       
   139 	 * This function initializes the eap_buf_chain_base_c object.
       
   140 	 */
       
   141 	EAP_FUNC_IMPORT eap_status_e initialize(
       
   142 		const u32_t mem_guard_length);
       
   143 
       
   144 	/**
       
   145 	 * Forses the inheritance.
       
   146 	 */
       
   147 	EAP_FUNC_IMPORT virtual void force_inheritance() = 0;
       
   148 
       
   149 	/**
       
   150 	 * Function checks the memory guard bytes.
       
   151 	 */
       
   152 	EAP_FUNC_IMPORT bool check_guard_bytes(const u8_t * const guard) const;
       
   153 
       
   154 	/**
       
   155 	 * Function sets the memory guard bytes.
       
   156 	 */
       
   157 	EAP_FUNC_IMPORT void set_mem_guard_bytes();
       
   158 
       
   159 	/**
       
   160 	 * Function zeroes the data buffer.
       
   161 	 */
       
   162 	EAP_FUNC_IMPORT void reset_data_buffer();
       
   163 
       
   164 	//--------------------------------------------------
       
   165 protected:
       
   166 	//--------------------------------------------------
       
   167 
       
   168 	/**
       
   169 	 * @return Returns pointer to the tools object.
       
   170 	 */
       
   171 	EAP_FUNC_IMPORT abs_eap_am_tools_c * get_am_tools();
       
   172 
       
   173 	//--------------------------------------------------
       
   174 public:
       
   175 	//--------------------------------------------------
       
   176 
       
   177 	/**
       
   178 	 * Function checks the all memory guard bytes.
       
   179 	 */
       
   180 	EAP_FUNC_IMPORT bool check_guards() const;
       
   181 
       
   182 	/**
       
   183 	 * The destructor of the eap_buf_chain_base_c class checks memory guards
       
   184 	 * and frees the allocated buffer.
       
   185 	 */
       
   186 	EAP_FUNC_IMPORT virtual ~eap_buf_chain_base_c();
       
   187 
       
   188 	/**
       
   189 	 * The constructor of the eap_buf_chain_wr class initializes attributes using
       
   190 	 * the parameters passes to it.
       
   191 	 * @param eap_write_buffer_e separates the write and read-only constructors.
       
   192 	 * @param tools parameter is pointer to the tools class.
       
   193 	 * @param data is pointer to the buffer containing the message. 
       
   194 	 * @param data_length parameter is count of bytes in the buffer.
       
   195 	 * @param reset_data parameter indicates whether the data bytes must be set zero.
       
   196 	 * @param free_buffer parameter indicates whether the destructor must free the data buffer.
       
   197 	 * @param mem_guard_length indicates the length of guard bytes both pre-fix and post-fix.
       
   198 	 *
       
   199 	 * NOTE the buffer allocated from the stack or from the heap must allocate additional
       
   200 	 * bytes for memory guards. The EAP_MEM_GUARDS(size) macro increases the size with count 
       
   201 	 * of memory guard bytes. The example use of eap_buf_chain_wr is as follows.
       
   202 	 * NOTE all sanity checks are ignored in the example.
       
   203 	 *
       
   204 	 * @code
       
   205 	 * u8_t packet_buffer[EAP_MEM_GUARDS(EAP_MAX_LOCAL_PACKET_BUFFER_LENGTH)];
       
   206 	 * eap_buf_chain_wr_c response_packet(
       
   207 	 *     eap_write_buffer, m_am_tools, packet_buffer,
       
   208 	 *     sizeof(packet_buffer), true, false, EAP_MEM_GUARD_LENGTH);
       
   209 	 * const u32_t eap_header_offset = get_type_partner()->get_header_offset(
       
   210 	 *     &MTU, &trailer_length);
       
   211 	 * eap_header_wr_c * const eap_response = (eap_header_wr_c * const)
       
   212 	 *     response_packet.get_data_offset(eap_header_offset,
       
   213 	 *         (EAP_MAX_LOCAL_PACKET_BUFFER_LENGTH
       
   214 	 *         -(eap_header_offset+ trailer_length)));
       
   215 	 * @endcode
       
   216 	 */
       
   217 	EAP_FUNC_IMPORT eap_buf_chain_base_c(
       
   218 		const eap_write_buffer_e, 
       
   219 		abs_eap_am_tools_c * const tools,
       
   220 		u8_t * const data, 
       
   221 		const u32_t data_length, 
       
   222 		const bool reset_data,
       
   223 		const bool free_buffer, 
       
   224 		const u32_t mem_guard_length);
       
   225 
       
   226 	/**
       
   227 	 * The constructor of the eap_buf_chain_wr class initializes attributes using
       
   228 	 * the parameters passes to it.
       
   229 	 * @param eap_read_buffer_e separates the write and read-only constructors.
       
   230 	 * @param tools parameter is pointer to the tools class.
       
   231 	 * @param data is pointer to the buffer containing the message. 
       
   232 	 * @param data_length parameter is count of bytes in the buffer.
       
   233 	 * @param free_buffer parameter indicates whether the destructor must free the data buffer.
       
   234 	 *
       
   235 	 * The example use of eap_buf_chain_wr is as follows.
       
   236 	 * NOTE all sanity checks are ignored in the example.
       
   237 	 *
       
   238 	 * @code
       
   239 	 * u8_t packet_buffer[EAP_MEM_GUARDS(EAP_MAX_LOCAL_PACKET_BUFFER_LENGTH)];
       
   240 	 * eap_buf_chain_rd_c response_packet(
       
   241 	 *     eap_read_buffer, m_am_tools, packet_buffer,
       
   242 	 *     sizeof(packet_buffer), false);
       
   243 	 * const u32_t eap_header_offset = get_type_partner()->get_header_offset(
       
   244 	 *     &MTU, &trailer_length);
       
   245 	 * eap_header_rd_c * const eap_response = (eap_header_rd_c * const)
       
   246 	 *     response_packet.get_data_offset(eap_header_offset,
       
   247 	 *         (EAP_MAX_LOCAL_PACKET_BUFFER_LENGTH
       
   248 	 *         -(eap_header_offset+ trailer_length)));
       
   249 	 * @endcode
       
   250 	 */
       
   251 	EAP_FUNC_IMPORT eap_buf_chain_base_c(
       
   252 		const eap_read_buffer_e,
       
   253 		abs_eap_am_tools_c * const tools,
       
   254 		const u8_t * const data, 
       
   255 		const u32_t data_length,
       
   256 		const bool free_buffer);
       
   257 
       
   258 	/**
       
   259 	 * The constructor of the eap_buf_chain_wr class initializes attributes using
       
   260 	 * the parameters passes to it.
       
   261 	 * New buffer is allocated from heap.
       
   262 	 * @param eap_write_buffer_e separates the write and read-only constructors.
       
   263 	 * @param tools parameter is pointer to the tools class.
       
   264 	 * @param data_length parameter is count of bytes in the buffer.
       
   265 	 *
       
   266 	 * The example use of eap_buf_chain_wr is as follows.
       
   267 	 * NOTE all sanity checks are ignored in the example.
       
   268 	 *
       
   269 	 * @code
       
   270 	 * eap_buf_chain_rd_c response_packet(
       
   271 	 *     eap_write_buffer_e, m_am_tools,
       
   272 	 *     PACKET_BUFFER_LENGTH);
       
   273 	 * const u32_t eap_header_offset = get_type_partner()->get_header_offset(
       
   274 	 *     &MTU, &trailer_length);
       
   275 	 * eap_header_rd_c * const eap_response = (eap_header_rd_c * const)
       
   276 	 *     response_packet.get_data_offset(eap_header_offset,
       
   277 	 *         (PACKET_BUFFER_LENGTH
       
   278 	 *         -(eap_header_offset+ trailer_length)));
       
   279 	 * @endcode
       
   280 	 */
       
   281 	EAP_FUNC_IMPORT eap_buf_chain_base_c(
       
   282 		const eap_write_buffer_e,
       
   283 		abs_eap_am_tools_c * const tools,
       
   284 		const u32_t data_length);
       
   285 
       
   286 	/**
       
   287 	 * The constructor of the eap_buf_chain_rd class initializes attributes using
       
   288 	 * the parameters passes to it.
       
   289 	 * New buffer is allocated from heap.
       
   290 	 * @param eap_write_buffer_e separates the write and read-only constructors.
       
   291 	 * @param tools parameter is pointer to the tools class.
       
   292 	 * @param data_length parameter is count of bytes in the buffer.
       
   293 	 *
       
   294 	 * The example use of eap_buf_chain_wr is as follows.
       
   295 	 * NOTE all sanity checks are ignored in the example.
       
   296 	 *
       
   297 	 * @code
       
   298 	 * eap_buf_chain_rd_c response_packet(
       
   299 	 *     eap_read_buffer, m_am_tools,
       
   300 	 *     PACKET_BUFFER_LENGTH);
       
   301 	 * const u32_t eap_header_offset = get_type_partner()->get_header_offset(
       
   302 	 *     &MTU, &trailer_length);
       
   303 	 * eap_header_rd_c * const eap_response = (eap_header_rd_c * const)
       
   304 	 *     response_packet.get_data_offset(eap_header_offset,
       
   305 	 *         (PACKET_BUFFER_LENGTH
       
   306 	 *         -(eap_header_offset+ trailer_length)));
       
   307 	 * @endcode
       
   308 	 */
       
   309 	EAP_FUNC_IMPORT eap_buf_chain_base_c(
       
   310 		const eap_read_buffer_e,
       
   311 		abs_eap_am_tools_c * const tools,
       
   312 		const u32_t data_length);
       
   313 
       
   314 	/**
       
   315 	 * @return Returns count of memory guard bytes.
       
   316 	 */
       
   317 	EAP_FUNC_IMPORT u32_t get_mem_guard_length();
       
   318 
       
   319 	/**
       
   320 	 * The get_buffer_length() function returns the length of buffer in bytes.
       
   321 	 */
       
   322 	EAP_FUNC_IMPORT u32_t get_buffer_length() const;
       
   323 
       
   324 	/**
       
   325 	 * The get_data_length() function returns count of data bytes in the buffer.
       
   326 	 */
       
   327 	EAP_FUNC_IMPORT u32_t get_data_length() const;
       
   328 
       
   329 	/**
       
   330 	 * The get_data_offset() function returns pointer to the data in offset (p_offset).
       
   331 	 * @param p_offset indicates the required offset.
       
   332 	 * @param p_continuous_bytes indicates how many bytes in continuous memory is needed.
       
   333 	 *
       
   334 	 * NOTE user of the eap_buf_chain_wr class must obtain the pointer to the data using
       
   335 	 * this or the get_data() function. These functions can handle the memory guard.
       
   336 	 */
       
   337 	EAP_FUNC_IMPORT u8_t * get_data_offset(const u32_t p_offset, const u32_t p_continuous_bytes) const;
       
   338 
       
   339 	/**
       
   340 	 * The get_data() function function returns pointer to the data.
       
   341 	 * @param p_continuous_bytes indicates how many bytes in continuous memory is needed.
       
   342 	 *
       
   343 	 * NOTE user of the eap_buf_chain_wr class must obtain the pointer to the data using
       
   344 	 * this or the get_data_offset() function. These functions can handle the memory guard.
       
   345 	 */
       
   346 	EAP_FUNC_IMPORT u8_t * get_data(const u32_t p_continuous_bytes) const;
       
   347 
       
   348 	/**
       
   349 	 * The set_buffer_length() function allocates the buffer of length bytes.
       
   350 	 */
       
   351 	EAP_FUNC_IMPORT eap_status_e set_buffer_length(const u32_t length);
       
   352 
       
   353 	/**
       
   354 	 * The set_data_length() function set the data length in the buffer.
       
   355 	 */
       
   356 	EAP_FUNC_IMPORT eap_status_e set_data_length(const u32_t length);
       
   357 
       
   358 	/**
       
   359 	 * The get_is_valid() function returns the status of the object.
       
   360 	 * @return True indicates the object is initialized.
       
   361 	 */
       
   362 	EAP_FUNC_IMPORT bool get_is_valid() const;
       
   363 
       
   364 	/**
       
   365 	 * The get_is_valid() function returns the status of the
       
   366 	 * data included in object.
       
   367 	 * @return True indicates the object includes valid data.
       
   368 	 */
       
   369 	EAP_FUNC_IMPORT bool get_is_valid_data() const;
       
   370 
       
   371 	/**
       
   372 	 * The set_is_manipulated() function sets flag to indicate this packet is manipulated.
       
   373 	 * This is used for testing purposes.
       
   374 	 */
       
   375 	EAP_FUNC_IMPORT void set_is_manipulated();
       
   376 
       
   377 	/**
       
   378 	 * The get_is_manipulated() function returns flag to indicate this packet is manipulated.
       
   379 	 * This is used for testing purposes.
       
   380 	 */
       
   381 	EAP_FUNC_IMPORT bool get_is_manipulated();
       
   382 
       
   383 	/**
       
   384 	 * This function sets the index of sent packet.
       
   385 	 * This is used for testing purposes.
       
   386 	 */
       
   387 	EAP_FUNC_IMPORT void set_send_packet_index(const u32_t send_packet_index);
       
   388 
       
   389 	/**
       
   390 	 * This function returns the index of sent packet.
       
   391 	 * This is used for testing purposes.
       
   392 	 */
       
   393 	EAP_FUNC_IMPORT u32_t get_send_packet_index();
       
   394 
       
   395 	/**
       
   396 	 * The set_random_error_type() function sets the type of manipulation of the packet.
       
   397 	 * This is used for testing purposes.
       
   398 	 */
       
   399 	EAP_FUNC_IMPORT void set_random_error_type(eap_random_error_type error_type);
       
   400 
       
   401 	/**
       
   402 	 * The get_random_error_type() function returns the type of manipulation of the packet.
       
   403 	 * This is used for testing purposes.
       
   404 	 */
       
   405 	EAP_FUNC_IMPORT eap_random_error_type get_random_error_type();
       
   406 
       
   407 	/**
       
   408 	 * The set_do_packet_retransmission() function sets the re-transmission flag of this packet.
       
   409 	 * Packet will be re-transmitted by lower layer when do_packet_retransmission_when_true is true.
       
   410 	 * Packet will not re-transmitted by lower layer when do_packet_retransmission_when_true is false.
       
   411 	 */
       
   412 	EAP_FUNC_IMPORT void set_do_packet_retransmission(const bool do_packet_retransmission_when_true);
       
   413 
       
   414 	/**
       
   415 	 * The set_do_packet_retransmission() function gets the re-transmission flag of this packet.
       
   416 	 */
       
   417 	EAP_FUNC_IMPORT bool get_do_packet_retransmission();
       
   418 
       
   419 	/**
       
   420 	 * This sets whether the sender is client or server.
       
   421 	 * This is used in testing.
       
   422 	 */
       
   423 	EAP_FUNC_IMPORT void set_is_client(const bool is_client_when_true);
       
   424 
       
   425 	/**
       
   426 	 * This gets whether the sender is client or server.
       
   427 	 * This is used in testing.
       
   428 	 */
       
   429 	EAP_FUNC_IMPORT bool get_is_client() const;
       
   430 
       
   431 	/**
       
   432 	 * This is used in testing.
       
   433 	 */
       
   434 	EAP_FUNC_IMPORT void set_do_length_checks(const bool do_length_checks);
       
   435 
       
   436 	/**
       
   437 	 * This is used in testing.
       
   438 	 */
       
   439 	EAP_FUNC_IMPORT bool get_do_length_checks() const;
       
   440 
       
   441 
       
   442 	/**
       
   443 	 * This sets whether this packet must be encrypted (true) or not (false).
       
   444 	 * Encryption means the WLAN data encryption on the air (WEP, TKIP or CCMP).
       
   445 	 * Using this flag to tell the encryption allows the configuration of the
       
   446 	 * temporal key beforehand the key is used.
       
   447 	 * This is optimization to fasten the key configuration.
       
   448 	 */
       
   449 	EAP_FUNC_IMPORT void set_encrypt(const bool encrypt_when_true);
       
   450 
       
   451 	/**
       
   452 	 * This gets whether this packet must be encrypted (true) or not (false).
       
   453 	 * Encryption means the WLAN data encryption on the air (WEP, TKIP or CCMP).
       
   454 	 * Using this flag to tell the encryption allows the configuration of the
       
   455 	 * temporal key beforehand the key is used.
       
   456 	 * This is optimization to fasten the key configuration.
       
   457 	 */
       
   458 	EAP_FUNC_IMPORT bool get_encrypt() const;
       
   459 
       
   460 
       
   461 	/**
       
   462 	 * This sets the pointer of sender stack.
       
   463 	 * This is used in testing.
       
   464 	 */
       
   465 	EAP_FUNC_IMPORT void set_stack_address(const void * const stack_address);
       
   466 
       
   467 	/**
       
   468 	 * This gets the pointer of sender stack.
       
   469 	 * This is used in testing.
       
   470 	 */
       
   471 	EAP_FUNC_IMPORT const void * get_stack_address() const;
       
   472 
       
   473 	/**
       
   474 	 * The add_data() function adds data to the end of the buffer.
       
   475 	 * If the buffer is empty the data is added to begin of the buffer.
       
   476 	 * @param buffer points the data to be added.
       
   477 	 * @param buffer_length is length of the buffer in bytes.
       
   478 	 */
       
   479 	EAP_FUNC_IMPORT eap_status_e add_data(
       
   480 		const void * const buffer,
       
   481 		const u32_t buffer_length);
       
   482 
       
   483 	/**
       
   484 	 * The add_data() function adds data to the end of the buffer.
       
   485 	 * If the buffer is empty the data is added to begin of the buffer.
       
   486 	 * @param buffer points the data to be added.
       
   487 	 */
       
   488 	EAP_FUNC_IMPORT eap_status_e add_data(
       
   489 		const eap_variable_data_c * const buffer);
       
   490 
       
   491 	/**
       
   492 	 * The add_data_to_offset() function adds data to the offset of the buffer.
       
   493 	 * @param offset tells the place where data will begin.
       
   494 	 * @param buffer points the data to be added.
       
   495 	 * @param buffer_length is length of the buffer in bytes.
       
   496 	 */
       
   497 	EAP_FUNC_IMPORT eap_status_e add_data_to_offset(
       
   498 		const u32_t offset,
       
   499 		const void * const buffer,
       
   500 		const u32_t buffer_length);
       
   501 
       
   502 	/**
       
   503 	 * The add_data() function adds data to the offset of the buffer.
       
   504 	 * @param offset tells the place where data will begin.
       
   505 	 * @param buffer points the data to be added.
       
   506 	 */
       
   507 	EAP_FUNC_IMPORT eap_status_e add_data_to_offset(
       
   508 		const u32_t offset,
       
   509 		const eap_variable_data_c * const buffer);
       
   510 
       
   511 	// 
       
   512 	//--------------------------------------------------
       
   513 }; // class eap_buf_chain_base_c
       
   514 
       
   515 
       
   516 
       
   517 /// Write only network packets are handled through eap_buf_chain_base_c class.
       
   518 /// Post-suffix _wr_c indicates the buffer has write attribute on.
       
   519 /// The eap_buf_chain_wr_c class is derived from eap_buf_chain_base class.
       
   520 class EAP_EXPORT eap_buf_chain_wr_c
       
   521 : public eap_buf_chain_base_c
       
   522 {
       
   523 private:
       
   524 
       
   525 	/**
       
   526 	 * Forses the inheritance.
       
   527 	 */
       
   528 	EAP_FUNC_IMPORT void force_inheritance();
       
   529 
       
   530 	//--------------------------------------------------
       
   531 protected:
       
   532 	//--------------------------------------------------
       
   533 
       
   534 	//--------------------------------------------------
       
   535 public:
       
   536 	//--------------------------------------------------
       
   537 
       
   538 	/**
       
   539 	 * The destructor does nothing special.
       
   540 	 */
       
   541 	EAP_FUNC_IMPORT virtual ~eap_buf_chain_wr_c();
       
   542 
       
   543 	/**
       
   544 	 * The costructor does nothing special. It just initializes all member attributes.
       
   545 	 * This version uses preallocated buffer.
       
   546 	 */
       
   547 	EAP_FUNC_IMPORT eap_buf_chain_wr_c(
       
   548 		const eap_write_buffer_e,
       
   549 		abs_eap_am_tools_c * const tools,
       
   550 		u8_t * const data,
       
   551 		const u32_t data_length,
       
   552 		const bool reset_data,
       
   553 		const bool free_buffer,
       
   554 		const u32_t mem_guard_length);
       
   555 
       
   556 	/**
       
   557 	 * The costructor does nothing special. It just initializes all member attributes.
       
   558 	 * This version allocates buffer from heap.
       
   559 	 */
       
   560 	EAP_FUNC_IMPORT eap_buf_chain_wr_c(
       
   561 		const eap_write_buffer_e,
       
   562 		abs_eap_am_tools_c * const tools,
       
   563 		const u32_t data_length);
       
   564 
       
   565 	/**
       
   566 	 * The costructor does nothing special. It just initializes all member attributes.
       
   567 	 * This version does not allocate buffer.
       
   568 	 * You must call set_buffer_length() member function to allocate buffer.
       
   569 	 */
       
   570 	EAP_FUNC_IMPORT eap_buf_chain_wr_c(
       
   571 		const eap_write_buffer_e,
       
   572 		abs_eap_am_tools_c * const tools);
       
   573 
       
   574 	/**
       
   575 	 * @return Returns the pointer to the ethernet header.
       
   576 	 */
       
   577 	EAP_FUNC_IMPORT u8_t * get_ethernet_header();
       
   578 
       
   579 	/**
       
   580 	 * The copy() function copies the eap_buf_chain_wr object.
       
   581 	 * Data is copied to new allocated buffer.
       
   582 	 */
       
   583 	EAP_FUNC_IMPORT eap_buf_chain_wr_c * copy();
       
   584 
       
   585 	// 
       
   586 	//--------------------------------------------------
       
   587 }; // class eap_buf_chain_wr_c
       
   588 
       
   589 
       
   590 /// Read only network packets are handled through eap_buf_chain_rd_c class.
       
   591 /// Post-suffix _rd_c indicates the buffer has read only attribute on.
       
   592 /// The eap_buf_chain_rd_c class is derived from eap_buf_chain_base class.
       
   593 class EAP_EXPORT eap_buf_chain_rd_c
       
   594 : public eap_buf_chain_base_c
       
   595 {
       
   596 private:
       
   597 
       
   598 	/**
       
   599 	 * Forses the inheritance.
       
   600 	 */
       
   601 	EAP_FUNC_IMPORT void force_inheritance();
       
   602 
       
   603 	//--------------------------------------------------
       
   604 protected:
       
   605 	//--------------------------------------------------
       
   606 
       
   607 	//--------------------------------------------------
       
   608 public:
       
   609 	//--------------------------------------------------
       
   610 
       
   611 	/**
       
   612 	 * The destructor of the eap_buf_chain_rd_c class checks memory guards.
       
   613 	 */
       
   614 	EAP_FUNC_IMPORT virtual ~eap_buf_chain_rd_c();
       
   615 
       
   616 	/**
       
   617 	 * The constructor of the eap_buf_chain_wr class initializes attributes using
       
   618 	 * the parameters passes to it.
       
   619 	 * @param eap_read_buffer_e separates the write and read-only constructors.
       
   620 	 * @param tools parameter is pointer to the tools class.
       
   621 	 * @param data is pointer to the buffer containing the message. 
       
   622 	 * @param data_length parameter is count of bytes in the buffer.
       
   623 	 * @param free_buffer parameter indicates whether the destructor must free the data buffer.
       
   624 	 *
       
   625 	 * The example use of eap_buf_chain_wr is as follows.
       
   626 	 * NOTE all sanity checks are ignored in the example.
       
   627 	 *
       
   628 	 * @code
       
   629 	 * u8_t packet_buffer[EAP_MEM_GUARDS(EAP_MAX_LOCAL_PACKET_BUFFER_LENGTH)];
       
   630 	 * eap_buf_chain_rd_c response_packet(
       
   631 	 *     eap_read_buffer, m_am_tools, packet_buffer,
       
   632 	 *     sizeof(packet_buffer), false);
       
   633 	 * const u32_t eap_header_offset = get_type_partner()->get_header_offset(
       
   634 	 *     &MTU, &trailer_length);
       
   635 	 * eap_header_rd_c * const eap_response = (eap_header_rd_c * const)
       
   636 	 *     response_packet.get_data_offset(eap_header_offset,
       
   637 	 *         (EAP_MAX_LOCAL_PACKET_BUFFER_LENGTH
       
   638 	 *         -(eap_header_offset+ trailer_length)));
       
   639 	 * @endcode
       
   640 	 */
       
   641 	EAP_FUNC_IMPORT eap_buf_chain_rd_c(
       
   642 		const eap_read_buffer_e, 
       
   643 		abs_eap_am_tools_c * const tools,
       
   644 		const u8_t * const data, 
       
   645 		const u32_t data_length,
       
   646 		const bool free_buffer);
       
   647 
       
   648 	/**
       
   649 	 * The costructor does nothing special. It just initializes all member attributes.
       
   650 	 * This version allocates buffer from heap.
       
   651 	 */
       
   652 	EAP_FUNC_IMPORT eap_buf_chain_rd_c(
       
   653 		const eap_read_buffer_e,
       
   654 		abs_eap_am_tools_c * const tools,
       
   655 		const u32_t data_length);
       
   656 
       
   657 	/**
       
   658 	 * The get_data() function function returns pointer to the data.
       
   659 	 * @param p_continuous_bytes indicates how many bytes in continuous memory is needed.
       
   660 	 *
       
   661 	 * NOTE user of the eap_buf_chain_wr class must obtain the pointer to the data using
       
   662 	 * this or the get_data_offset() function. These functions can handle the memory guard.
       
   663 	 */
       
   664 	EAP_FUNC_IMPORT const u8_t * get_data(const u32_t p_continuous_bytes) const;
       
   665 
       
   666 	/**
       
   667 	 * The get_data_offset() function returns pointer to the data in offset (p_offset).
       
   668 	 * @param p_offset indicates the required offset.
       
   669 	 * @param p_continuous_bytes indicates how many bytes in continuous memory is needed.
       
   670 	 *
       
   671 	 * NOTE user of the eap_buf_chain_wr class must obtain the pointer to the data using
       
   672 	 * this or the get_data() function. These functions can handle the memory guard.
       
   673 	 */
       
   674 	EAP_FUNC_IMPORT const u8_t * get_data_offset(const u32_t p_offset, const u32_t p_continuous_bytes) const;
       
   675 
       
   676 	/**
       
   677 	 * @return Returns the pointer to the ethernet header.
       
   678 	 */
       
   679 	EAP_FUNC_IMPORT const u8_t * get_ethernet_header() const;
       
   680 
       
   681 	// 
       
   682 	//--------------------------------------------------
       
   683 }; // class eap_buf_chain_rd_c
       
   684 
       
   685 
       
   686 #endif //#if !defined(_EAP_BUFFER_H_)
       
   687 
       
   688 //--------------------------------------------------
       
   689 
       
   690 
       
   691 
       
   692 // End.