- notify payload written and tested
[strongswan.git] / Source / charon / generator.c
index 523af80..4acec72 100644 (file)
@@ -37,6 +37,7 @@
 #include "payloads/transform_substructure.h"
 #include "payloads/sa_payload.h"
 #include "payloads/ke_payload.h"
+#include "payloads/notify_payload.h"
 
 extern logger_manager_t *global_logger_manager;
 
@@ -671,6 +672,8 @@ static status_t generate_payload (private_generator_t *this,payload_t *payload)
        
        /* get payload type */
        payload_type = payload->get_type(payload);
+       /* spi size has to get reseted */
+       this->last_spi_size = 0;
        
        this->logger->log(this->logger,CONTROL,"Start generating payload of type %s",mapping_find(payload_type_t_mappings,payload_type));
        
@@ -746,7 +749,6 @@ static status_t generate_payload (private_generator_t *this,payload_t *payload)
                                        return status;
                                }
                                
-                               /* before iterative generate the transforms, store the current payload length position */
                                u_int32_t payload_length_position_offset = this->last_payload_length_position_offset;
                                /* Length of KE_PAYLOAD is calculated */
                                u_int16_t length_of_ke_payload = KE_PAYLOAD_HEADER_LENGTH + ((chunk_t *)(this->data_struct + rules[i].offset))->len;
@@ -759,7 +761,31 @@ static status_t generate_payload (private_generator_t *this,payload_t *payload)
                                        return status;
                                }
                                break;
-                       }                       
+                       }               
+                       case NOTIFICATION_DATA:
+                       {
+                               /* the Notification Data value is generated from chunk */
+                               status = this->generate_from_chunk(this,rules[i].offset);
+                               if (status != SUCCESS)
+                               {
+                                       this->logger->log(this->logger,CONTROL_MORE,"Could no write notification data from chunk");     
+                                       return status;
+                               }
+                               
+                               u_int32_t payload_length_position_offset = this->last_payload_length_position_offset;
+                               /* Length of Notification PAYLOAD is calculated */
+                               u_int16_t length_of_notify_payload = NOTIFY_PAYLOAD_HEADER_LENGTH + ((chunk_t *)(this->data_struct + rules[i].offset))->len;
+                               length_of_notify_payload += this->last_spi_size;
+                               u_int16_t int16_val = htons(length_of_notify_payload);
+
+                               status = this->write_bytes_to_buffer_at_offset(this,&int16_val,sizeof(u_int16_t),payload_length_position_offset);
+                               if (status != SUCCESS)
+                               {
+                                       this->logger->log(this->logger,CONTROL_MORE,"Could no write payload length into buffer");                                       
+                                       return status;
+                               }
+                               break;
+                       }               
                        case PROPOSALS:
                        {
                                /* before iterative generate the transforms, store the current payload length position */