[hipl-dev] [Branch ~hipl-core/hipl/trunk] Rev 6388: HIP dual-version support

  • From: noreply@xxxxxxxxxxxxx
  • To: HIPL core team <hipl-dev@xxxxxxxxxxxxx>
  • Date: Wed, 18 Jul 2012 14:51:11 -0000

Merge authors:
  Xin (eric-nevup)
Related merge proposals:
  https://code.launchpad.net/~hipl-core/hipl/hipv2-modularization/+merge/113825
  proposed by: Xin (eric-nevup)
  review: Needs Fixing - Diego Biurrun (diego-biurrun)
  review: Approve - Artturi Karila (artturi-karila)
  review: Abstain - Christof Mroz (christof-mroz)
  review: Approve - Miika Komu (miika-iki)
------------------------------------------------------------
revno: 6388 [merge]
committer: Xin Gu <eric.nevup@xxxxxxxxx>
branch nick: hipl
timestamp: Wed 2012-07-18 17:42:57 +0300
message:
  HIP dual-version support
  
  1) Extend the modularization framework so we can register different functions
     for different HIP versions.
  2) Extend the builder to support v2, such as handling HIPv2 version number
     and providing common handling functions for list-like parameters.
  3) Build a dual-version HIPL daemon to support both version 1 and version 2.
modified:
  doc/HOWTO.xml.in
  hipd/hipd.conf
  libcore/builder.c
  libcore/builder.h
  libcore/conf.c
  libcore/icomm.h
  libcore/protodefs.h
  libcore/state.h
  libcore/transform.c
  libcore/transform.h
  libhipl/close.c
  libhipl/cookie.c
  libhipl/cookie.h
  libhipl/esp_prot_hipd_msg.c
  libhipl/esp_prot_light_update.c
  libhipl/hidb.c
  libhipl/hidb.h
  libhipl/hiprelay.c
  libhipl/init.c
  libhipl/init.h
  libhipl/input.c
  libhipl/nat.c
  libhipl/netdev.c
  libhipl/output.c
  libhipl/output.h
  libhipl/pkt_handling.c
  libhipl/pkt_handling.h
  libhipl/user.c
  modules/cert/hipd/cert.c
  modules/midauth/hipd/midauth.c
  modules/update/hipd/update.c
  test/libcore/cert.c
  test/libcore/gpl/pk.c


--
lp:hipl
https://code.launchpad.net/~hipl-core/hipl/trunk

Your team HIPL core team is subscribed to branch lp:hipl.
To unsubscribe from this branch go to 
https://code.launchpad.net/~hipl-core/hipl/trunk/+edit-subscription
=== modified file 'doc/HOWTO.xml.in'
--- doc/HOWTO.xml.in    2012-05-12 07:08:30 +0000
+++ doc/HOWTO.xml.in    2012-07-13 13:16:17 +0000
@@ -2607,6 +2607,49 @@
 
 </chapter> <!-- ch_cert_exchange -->
 
+<chapter id="ch_dual_version_support">
+    <title>HIP dual-version support</title>
+
+  <section id="ch_dual_version_support_functionality">
+    <title>Provided functionality</title>
+    <para>HIP dual-version support allows a host to run HIPv1 and HIPv2 as
+    a dual stack. Based on the version number of received I1 messages, the host
+    automatically determines the HIP version for this peer. The version is
+    decided separately for each host association, which means the host can
+    have a HIPv1 association with one peer, while maintaining a HIPv2
+    association with another peer.</para>
+    <para>HIP dual-version support also enables a host to choose the default
+    HIP version for HIP association initiation. This behavior can be configured
+    via both the hipd configuration file and the hipconf command line tool.
+    </para>
+  </section>
+
+  <section id="ch_dual_version_support_conf_file">
+    <title>Configure the default HIP version for HA initiation via the
+    configuration file</title>
+    <para>The configuration parameter: <emphasis>hip-default-version</emphasis>
+    in the hipd.conf file accepts two values: 1 and 2, which stand for HIPv1
+    and HIPv2 respectively. If the hipd cannot find this parameter in the
+    configuration file, HIPv1 will be used as default value.
+    </para>
+  </section>
+
+  <section id="ch_dual_version_support_hipconf">
+    <title>Configure the default HIP version for HA initiation via the
+    hipconf command</title>
+    <para>Modification of the configuration parameter: <emphasis>
+    hip-default-version</emphasis> in the hipconf command line takes effect
+    immediately and no restart of the daemon is required. Any HA before
+    the modification remains unchanged and all new HIP initiation messages
+    (I1 message) will be switched to the version given by the hipconf
+    command. Below is an example of setting the parameter to HIPv1. To use
+    HIPv2, change the value from 1 to 2. </para>
+    <para><programlisting>
+    hipconf daemon default-hip-version 1
+    </programlisting></para>
+</section>
+</chapter> <!-- ch_dual_version_support -->
+
 <chapter id="ch_exp_extensions">
     <title>Other Experimental HIP Extensions</title>
 

=== modified file 'hipd/hipd.conf'
--- hipd/hipd.conf      2011-12-12 14:26:13 +0000
+++ hipd/hipd.conf      2012-07-13 13:16:17 +0000
@@ -19,3 +19,4 @@
 #nat port local 11111 # change local default UDP port
 #nat port peer 22222 # change local peer UDP port
 debug medium        # debug verbosity: all, medium, low or none
+default-hip-version 1 # default HIP version number for the I1 message. 
(1=HIPv1, 2=HIPv2)

=== modified file 'libcore/builder.c'
--- libcore/builder.c   2012-05-12 10:21:32 +0000
+++ libcore/builder.c   2012-07-13 13:16:17 +0000
@@ -108,6 +108,41 @@
 
 static enum select_dh_key_t select_dh_key = STRONGER_KEY;
 
+enum cbo_flags {
+    CBO_HTON,
+    CBO_NTOH
+};
+
+/**
+ * Convert the byte order of a list of items in one buffer.
+ *
+ * @param content   the buffer to hold all the items
+ * @param count     the number of items in the buffer
+ * @param item_size the size of each item in bytes. The function only supports
+ *                  items in 2 bytes or 4 bytes.
+ * @param flag      the flag to decide the byte conversion order
+ */
+static void convert_byte_order(void *content, unsigned count,
+                               unsigned item_size, enum cbo_flags flag)
+{
+    uint32_t (*f32)(uint32_t) = (flag == CBO_HTON) ? htonl : ntohl;
+    uint16_t (*f16)(uint16_t) = (flag == CBO_HTON) ? htons : ntohs;
+
+    HIP_ASSERT(item_size == sizeof(uint16_t) || item_size == sizeof(uint32_t));
+
+    if (item_size == sizeof(uint16_t)) {
+        uint16_t *p = content;
+        for (unsigned i = 0; i < count; i++) {
+            p[i] = f16(p[i]);
+        }
+    } else {
+        uint32_t *p = content;
+        for (unsigned i = 0; i < count; i++) {
+            p[i] = f32(p[i]);
+        }
+    }
+}
+
 /**
  * attach a HIP RR and a hostname into a hip_host_id_priv parameter
  *
@@ -286,6 +321,28 @@
 }
 
 /**
+ * Get the HIP version number from a HIP message header.
+ *
+ * @param msg pointer to the beginning of the message header
+ * @return    HIP version number
+ */
+uint8_t hip_get_msg_version(const struct hip_common *msg)
+{
+    return msg->ver_res >> 4;
+}
+
+/**
+ * Set HIP version number to a given HIP message header.
+ *
+ * @param msg     pointer to the beginning of the message header
+ * @param version HIP message version
+ */
+void hip_set_msg_version(struct hip_common *msg, const uint8_t version)
+{
+    msg->ver_res = version << 4 | HIP_VER_RES;
+}
+
+/**
  * set the error value of the daemon message
  *
  * @param msg pointer to the beginning of the message header
@@ -1239,6 +1296,7 @@
     HIP_DEBUG("Msg length:     %d\n", hip_get_msg_total_len(msg));
     HIP_DEBUG("Msg err:        %d\n", hip_get_msg_err(msg));
     HIP_DEBUG("Msg controls:   0x%04x\n", msg->control);
+    HIP_DEBUG("Msg version:    %d\n", hip_get_msg_version(msg));
 
     while ((current_param = hip_get_next_param(msg, current_param))) {
         len = hip_get_param_contents_len(current_param);
@@ -1556,6 +1614,66 @@
 }
 
 /**
+ * Build a HIP parameter containing several items in a consecutive list.
+ *
+ * If the @c item_size is 2 bytes or 4 bytes, each item in the list will be
+ * transformed from host byte order to network byte order.
+ *
+ * @param msg          the pointer to a message where the parameter will be
+ *                     appended.
+ * @param param_type   the type of the parameter, in host byte order.
+ * @param list_content the pointer to a buffer containing all list items.
+ * @param item_count   the number of the items in the @c list_content.
+ * @param item_size    the size of each item in bytes.
+ * @return             zero on success, or negative value on error.
+ */
+int hip_build_param_list(struct hip_common *const msg, const hip_tlv 
param_type,
+                         void *const list_content, const hip_tlv_len 
item_count,
+                         const int item_size)
+{
+    // host to network byte order transform
+    convert_byte_order(list_content, item_count, item_size, CBO_HTON);
+
+    return hip_build_param_contents(msg, list_content, param_type,
+                                    item_count * item_size);
+}
+
+/**
+ * Fetch the content of a HIP list-like parameter to a specified buffer.
+ *
+ * If the buffer size is smaller than the size of all items in the list, the
+ * result in the buffer will be truncated to first N items
+ * (N <= @c item_number). If the @c item_size is 2 bytes or 4 bytes, result
+ * items will be transformed from network byte order to host byte order.
+ *
+ * @param param       pointer to the HIP list parameter.
+ * @param buffer      the buffer for holding items of the list parameter.
+ * @param item_number the number of items @c buffer can hold.
+ * @param item_size   the size of each item in bytes.
+ * @return            the number items in the given HIP list parameter.
+ */
+int hip_get_list_from_param(const struct hip_tlv_common *const param,
+                            void *const buffer, const int item_number,
+                            const int item_size)
+{
+    int plen         = hip_get_param_contents_len(param);
+    int actual_count = plen / item_size;
+
+    const void *p = param + 1;
+
+    if (actual_count > item_number) {
+        HIP_DEBUG("The buffer size is smaller than the size of list 
parameter.\n");
+        actual_count = item_number;
+    }
+    memcpy(buffer, p, actual_count * item_size);
+
+    /* network to host byte order transform */
+    convert_byte_order(buffer, actual_count, item_size, CBO_NTOH);
+
+    return actual_count;
+}
+
+/**
  * set whether to request for a response from hipd or not
  *
  * @param msg user message
@@ -1648,6 +1766,7 @@
  * @param control      HIP control bits in host byte order
  * @param hit_sender   source HIT in network byte order
  * @param hit_receiver destination HIT in network byte order
+ * @param version      HIP version number of the message
  * @todo build HIP network header in the same fashion as in build_daemon_hdr().
  * <ul>
  * <li>Write missing headers in the header using accessor functions
@@ -1664,7 +1783,8 @@
  */
 void hip_build_network_hdr(struct hip_common *msg, uint8_t type_hdr,
                            uint16_t control, const struct in6_addr *hit_sender,
-                           const struct in6_addr *hit_receiver)
+                           const struct in6_addr *hit_receiver,
+                           uint8_t version)
 {
     /* build header first and then parameters */
     HIP_ASSERT(hip_get_msg_total_len(msg) == 0);
@@ -1673,7 +1793,7 @@
     /* Do not touch the length; it is written by param builders */
     msg->type_hdr = type_hdr;                  /* 1 byte, no htons()    */
     /* version includes the SHIM6 bit */
-    msg->ver_res = (HIP_VER_RES << 4) | 1;       /* 1 byte, no htons() */
+    msg->ver_res = (version << 4) | HIP_VER_RES;  /* 1 byte, no htons() */
 
     msg->control  = htons(control);
     msg->checksum = htons(0);      /* this will be written by xmit */
@@ -1835,7 +1955,8 @@
                               struct sockaddr *src, struct sockaddr *dst,
                               int len)
 {
-    int err = 0, plen, checksum;
+    int     err = 0, plen, checksum;
+    uint8_t version;
 
     plen = hip_get_msg_total_len(hip_common);
 
@@ -1849,7 +1970,8 @@
 
     /* we should ignore reserved bits and SHIM6 bit when checking
      * the HIP header of incoming pakcets */
-    if ((hip_common->ver_res & 0xF0) != HIP_VER_RES << 4) {
+    version = hip_get_msg_version(hip_common);
+    if (version == 0 || version >= HIP_MAX_VERSION) {
         HIP_ERROR("Invalid version in received packet. Dropping\n");
         return -EPROTOTYPE;
     }
@@ -2470,9 +2592,9 @@
                                   const hip_transform_suite transform_suite[],
                                   const uint16_t transform_count)
 {
-    uint16_t                 i;
-    uint16_t                 transform_max;
-    struct hip_esp_transform transform_param;
+    uint16_t            i;
+    uint16_t            transform_max;
+    hip_transform_suite suite[transform_count + 1];
 
     transform_max = get_transform_max(HIP_PARAM_ESP_TRANSFORM);
 
@@ -2483,19 +2605,15 @@
         return -E2BIG;
     }
 
-    transform_param.reserved = 0;
-
-    /* Copy and convert transforms to network byte order. */
+    /* Build the content of the list, the first item in the list is a reserved
+     * zero field according to HIP_ESP_FRANSFORM format */
+    suite[0] = HIP_ESP_RESERVED;
     for (i = 0; i < transform_count; i++) {
-        transform_param.suite_id[i] = htons(transform_suite[i]);
+        suite[i + 1] = transform_suite[i];
     }
 
-    hip_set_param_type((struct hip_tlv_common *) &transform_param,
-                       HIP_PARAM_ESP_TRANSFORM);
-    hip_calc_param_len((struct hip_tlv_common *) &transform_param,
-                       2 + transform_count * sizeof(hip_transform_suite));
-
-    return hip_build_param(msg, &transform_param);
+    return hip_build_param_list(msg, HIP_PARAM_ESP_TRANSFORM, suite,
+                                transform_count + 1, 
sizeof(hip_transform_suite));
 }
 
 /**
@@ -2511,13 +2629,12 @@
                                   const hip_transform_suite transform_suite[],
                                   const uint16_t transform_count)
 {
-    uint16_t                 i;
-    uint16_t                 transform_max;
-    struct hip_hip_transform transform_param;
+    uint16_t            i;
+    uint16_t            transform_max;
+    hip_transform_suite transform_list[transform_count];
 
     transform_max = get_transform_max(HIP_PARAM_HIP_TRANSFORM);
 
-
     /* Check that the maximum number of transforms is not overflowed */
     if (transform_max > 0 && transform_count > transform_max) {
         HIP_ERROR("Too many transforms (%d) for type %d.\n",
@@ -2525,18 +2642,13 @@
         return -E2BIG;
     }
 
-
     /* Copy and convert transforms to network byte order. */
     for (i = 0; i < transform_count; i++) {
-        transform_param.suite_id[i] = htons(transform_suite[i]);
+        transform_list[i] = transform_suite[i];
     }
 
-    hip_set_param_type((struct hip_tlv_common *) &transform_param,
-                       HIP_PARAM_HIP_TRANSFORM);
-    hip_calc_param_len((struct hip_tlv_common *) &transform_param,
-                       transform_count * sizeof(hip_transform_suite));
-
-    return hip_build_param(msg, &transform_param);
+    return hip_build_param_list(msg, HIP_PARAM_HIP_TRANSFORM, transform_list,
+                                transform_count, sizeof(hip_transform_suite));
 }
 
 /**
@@ -2555,7 +2667,8 @@
      * which MUST match one of the values offered to the Initiator in
      * the R1 packet. Does this function check this?
      * -Lauri 01.08.2008. */
-    hip_tlv         type;
+    hip_tlv type = hip_get_param_type(transform_tlv);
+
     uint16_t        supported_hip_tf[] = { HIP_HIP_NULL_SHA1,
                                            HIP_HIP_3DES_SHA1,
                                            HIP_HIP_AES_SHA1 };
@@ -2564,20 +2677,32 @@
                                            HIP_ESP_AES_SHA1 };
     const uint16_t *table = NULL;
     const uint16_t *tfm;
-    int             table_n = 0, pkt_tfms = 0, i;
-
-    type = hip_get_param_type(transform_tlv);
+    int             table_n = 0, i;
+
+    // reserve one extra slot for ESP reserved field
+    int      pkt_tfms = get_transform_max(type) + 1;
+    uint16_t suite[pkt_tfms];
+
+    pkt_tfms = hip_get_list_from_param(transform_tlv, suite, pkt_tfms,
+                                       sizeof(uint16_t));
+
     if (type == HIP_PARAM_HIP_TRANSFORM) {
-        table    = supported_hip_tf;
-        table_n  = sizeof(supported_hip_tf) / sizeof(uint16_t);
-        tfm      = (const uint16_t *) ((const uint8_t *) transform_tlv + 
sizeof(struct hip_tlv_common));
-        pkt_tfms = hip_get_param_contents_len(transform_tlv) / 
sizeof(uint16_t);
+        table   = supported_hip_tf;
+        table_n = sizeof(supported_hip_tf) / sizeof(uint16_t);
+        tfm     = suite;
+        if (pkt_tfms > HIP_TRANSFORM_HIP_MAX) {
+            pkt_tfms = HIP_TRANSFORM_HIP_MAX;
+        }
     } else if (type == HIP_PARAM_ESP_TRANSFORM) {
         table   = supported_esp_tf;
         table_n = sizeof(supported_esp_tf) / sizeof(uint16_t);
-        tfm     = (const uint16_t *) ((const uint8_t *) transform_tlv +
-                                      sizeof(struct hip_tlv_common) + 
sizeof(uint16_t));
-        pkt_tfms = (hip_get_param_contents_len(transform_tlv) - 
sizeof(uint16_t)) / sizeof(uint16_t);
+        if (pkt_tfms <= 1) {
+            /* the first item in the list is a reserved field for 
ESP_TRANSFORM */
+            HIP_ERROR("No ESP_TRANSFORM suite available\n");
+            return 0;
+        }
+        tfm = &suite[1];
+        pkt_tfms--;
     } else {
         HIP_ERROR("Invalid type %u\n", type);
         return 0;
@@ -2586,7 +2711,7 @@
     for (i = 0; i < pkt_tfms; i++, tfm++) {
         int j;
         for (j = 0; j < table_n; j++) {
-            if (ntohs(*tfm) == table[j]) {
+            if (*tfm == table[j]) {
                 return table[j];
             }
         }

=== modified file 'libcore/builder.h'
--- libcore/builder.h   2012-05-12 06:54:33 +0000
+++ libcore/builder.h   2012-07-13 13:16:17 +0000
@@ -63,12 +63,18 @@
                            uint8_t,
                            uint16_t,
                            const struct in6_addr *,
-                           const struct in6_addr *);
+                           const struct in6_addr *,
+                           uint8_t);
 int hip_host_id_hits(struct hip_hadb_state *entry, struct hip_common *msg);
 int hip_build_param_contents(struct hip_common *,
                              const void *,
                              hip_tlv,
                              hip_tlv);
+int hip_build_param_list(struct hip_common *const msg,
+                         const hip_tlv param_type,
+                         void *const list_content,
+                         const hip_tlv_len list_size,
+                         const int item_size);
 int hip_build_param_diffie_hellman_contents(struct hip_common *,
                                             uint8_t,
                                             void *,
@@ -168,6 +174,7 @@
 int hip_get_lifetime_seconds(uint8_t lifetime, time_t *seconds);
 int hip_check_network_msg_len(const struct hip_common *msg);
 hip_hdr_err hip_get_msg_err(const struct hip_common *);
+uint8_t hip_get_msg_version(const struct hip_common *msg);
 uint16_t hip_get_msg_total_len(const struct hip_common *);
 hip_hdr hip_get_msg_type(const struct hip_common *);
 const struct hip_tlv_common *hip_get_next_param(const struct hip_common *,
@@ -179,6 +186,9 @@
 const void *hip_get_param_contents(const struct hip_common *, hip_tlv);
 const void *hip_get_param_contents_direct(const void *);
 hip_tlv_len hip_get_param_contents_len(const void *);
+int hip_get_list_from_param(const struct hip_tlv_common *const param,
+                            void *const buffer, const int item_number,
+                            const int item_size);
 int hip_get_param_host_id_di_type_len(const struct hip_host_id *,
                                       const char **, int *);
 const char *hip_get_param_host_id_hostname(const struct hip_host_id *);
@@ -198,6 +208,7 @@
 void hip_set_msg_err(struct hip_common *, hip_hdr_err);
 void hip_set_msg_checksum(struct hip_common *msg, uint8_t checksum);
 void hip_set_msg_total_len(struct hip_common *, uint16_t);
+void hip_set_msg_version(struct hip_common *msg, const uint8_t version);
 void hip_set_param_contents_len(struct hip_tlv_common *, hip_tlv_len);
 void hip_set_param_lsi_value(struct hip_esp_info *, uint32_t);
 void hip_zero_msg_checksum(struct hip_common *);

=== modified file 'libcore/conf.c'
--- libcore/conf.c      2012-03-20 12:25:10 +0000
+++ libcore/conf.c      2012-06-03 10:26:55 +0000
@@ -129,7 +129,9 @@
 #define ACTION_MANUAL_UPDATE 40
 #define ACTION_BROADCAST 41
 #define ACTION_ACQUIRE 42
-#define ACTION_MAX 43 /* exclusive */
+/* This parameter defines which HIP version will be used by default */
+#define ACTION_DEFAULT_HIP_VERSION 45
+#define ACTION_MAX 46 /* exclusive */
 
 /**
  * TYPE_ constant list, as an index for each action_handler function.
@@ -180,7 +182,8 @@
 #define TYPE_MANUAL_UPDATE 43
 #define TYPE_BROADCAST     44
 #define TYPE_CERTIFICATE   45
-#define TYPE_MAX           46 /* exclusive */
+#define TYPE_DEFAULT_HIP_VERSION 46
+#define TYPE_MAX           47 /* exclusive */
 
 /* #define TYPE_RELAY         22 */
 
@@ -235,6 +238,7 @@
     "id-to-addr hit|lsi\n"
     "broadcast on|off\n"
     "acquire certificate <hit> [valid-till_timestamp]\n"
+    "default-hip-version 1|2\n"
 ;
 
 /**
@@ -655,6 +659,8 @@
         ret = ACTION_BROADCAST;
     } else if (!strcmp("acquire", argv[2])) {
         ret = ACTION_ACQUIRE;
+    } else if (!strcmp("default-hip-version", argv[2])) {
+        ret = ACTION_DEFAULT_HIP_VERSION;
     }
 
     return ret;
@@ -692,6 +698,7 @@
     case ACTION_HIT_TO_IP:
     case ACTION_HIT_TO_IP_SET:
     case ACTION_BROADCAST:
+    case ACTION_DEFAULT_HIP_VERSION:
         count = 1;
         break;
     case ACTION_ADD:
@@ -786,6 +793,8 @@
         ret = TYPE_LSI_TO_HIT;
     } else if (strcmp("broadcast", argv[2]) == 0) {
         ret = TYPE_BROADCAST;
+    } else if (strcmp("default-hip-version", text) == 0) {
+        ret = TYPE_DEFAULT_HIP_VERSION;
     } else {
         HIP_DEBUG("ERROR: NO MATCHES FOUND \n");
     }
@@ -837,6 +846,7 @@
     case ACTION_LSI_TO_HIT:
     case ACTION_DEBUG:
     case ACTION_SHOTGUN:
+    case ACTION_DEFAULT_HIP_VERSION:
         type_arg = 2;
         break;
     default:
@@ -2435,6 +2445,49 @@
 }
 
 /**
+ * Handles the hipconf commands where the type is @c default-hip-version.
+ *
+ * @param msg       a pointer to the buffer where the message for hipd will
+ *                  be written.
+ * @param action    unused.
+ * @param opt       an array of pointers to the command line arguments after
+ *                  the action and type.
+ * @param optc      the number of elements in the array.
+ * @param send_only unused.
+ * @return          zero on success, or negative error value on error.
+ */
+static int conf_handle_default_hip_version(struct hip_common *msg,
+                                           UNUSED int action, const char 
*opt[],
+                                           int optc, UNUSED int send_only)
+{
+    int status = 0;
+
+    if (optc != 0) {
+        HIP_ERROR("Incorrect number of arguments. "
+                  "Usage:\nhipconf default-hip-version 1|2\n");
+        return -EINVAL;
+    }
+
+    if (!strcmp("1", opt[0])) {
+        HIP_INFO("Default hip version: 1\n");
+        status = HIP_MSG_DEFAULT_HIP_VERSION_1;
+    } else if (!strcmp("2", opt[0])) {
+        HIP_INFO("Default hip version: 2\n");
+        status = HIP_MSG_DEFAULT_HIP_VERSION_2;
+    } else {
+        HIP_ERROR("Unknown argument\n");
+        return -EINVAL;
+    }
+
+    if (hip_build_user_hdr(msg, status, 0) < 0) {
+        HIP_ERROR("Failed to build the user message header.\n");
+        return -1;
+    }
+
+    return 0;
+}
+
+/**
  * Utility function which compactly checks whether a string represents
  * a positive natural number, since scanf() is too lenient.
  *
@@ -2678,6 +2731,7 @@
     conf_handle_manual_update,          /* 43: TYPE_MANUAL_UPDATE */
     conf_handle_broadcast,              /* 44: TYPE_BROADCAST */
     conf_handle_certificate,            /* 45: TYPE_CERTIFICATE */
+    conf_handle_default_hip_version,    /* 46: TYPE_DEFAULT_HIP_VERSION */
     NULL     /* TYPE_MAX, the end. */
 };
 

=== modified file 'libcore/icomm.h'
--- libcore/icomm.h     2012-05-12 06:54:33 +0000
+++ libcore/icomm.h     2012-06-07 12:45:16 +0000
@@ -158,6 +158,8 @@
 #define HIP_MSG_BROADCAST_ON                     203
 #define HIP_MSG_LSI_ON                           204
 #define HIP_MSG_LSI_OFF                          205
+#define HIP_MSG_DEFAULT_HIP_VERSION_1            206
+#define HIP_MSG_DEFAULT_HIP_VERSION_2            207
 /* @} */
 
 /* inclusive */

=== modified file 'libcore/protodefs.h'
--- libcore/protodefs.h 2012-05-12 06:54:33 +0000
+++ libcore/protodefs.h 2012-07-12 11:32:14 +0000
@@ -78,6 +78,7 @@
 /**
  * @todo add description
  */
+#define HIP_MAX_VERSION           3
 #define HIP_MAX_PACKET_TYPE      64
 
 #define HIP_HIT_TYPE_HASH100    1
@@ -372,7 +373,10 @@
 
 #define HIP_MAX_KEY_LEN 32 /* max. draw: 256 bits! */
 
-#define HIP_VER_RES                 0x01     /* Version 1, reserved 0 */
+#define HIP_ALL                     0
+#define HIP_V1                      1
+#define HIP_V2                      2
+#define HIP_VER_RES                 0x01       /* reserved and shim6 bit */
 #define HIP_USER_VER_RES            0xF0       /* Internal messages */
 
 
@@ -801,20 +805,6 @@
     struct hip_dh_public_value pub_val;
 } __attribute__((packed));
 
-struct hip_hip_transform {
-    hip_tlv             type;
-    hip_tlv_len         length;
-    hip_transform_suite suite_id[HIP_TRANSFORM_HIP_MAX];
-} __attribute__((packed));
-
-struct hip_esp_transform {
-    hip_tlv             type;
-    hip_tlv_len         length;
-    uint16_t            reserved;
-    hip_transform_suite suite_id[HIP_TRANSFORM_ESP_MAX];
-} __attribute__((packed));
-
-
 struct hip_encrypted_aes_sha1 {
     hip_tlv     type;
     hip_tlv_len length;

=== modified file 'libcore/state.h'
--- libcore/state.h     2012-05-12 10:21:32 +0000
+++ libcore/state.h     2012-06-03 10:26:55 +0000
@@ -314,6 +314,8 @@
     unsigned spi_outbound_old;
     unsigned spi_outbound_new;
 
+    /* The HIP version in use for this HA pair */
+    uint8_t hip_version;
     /* modular state */
     struct modular_state *hip_modular_state;
 } __attribute__((packed));

=== modified file 'libcore/transform.c'
--- libcore/transform.c 2011-08-15 14:11:56 +0000
+++ libcore/transform.c 2012-07-13 13:16:17 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010 Aalto University and RWTH Aachen University.
+ * Copyright (c) 2010, 2012 Aalto University and RWTH Aachen University.
  *
  * Permission is hereby granted, free of charge, to any person
  * obtaining a copy of this software and associated documentation
@@ -38,32 +38,27 @@
  * select a HIP transform
  *
  * @param ht HIP_TRANSFORM payload where the transform is selected from
- * @return the first acceptable Transform-ID or negative if no
- * acceptable transform was found. The return value is in host byte order.
+ * @return   the first acceptable Transform-ID or zero if no acceptable
+ *           transform was found. The return value is in host byte order.
  */
-hip_transform_suite hip_select_hip_transform(const struct hip_hip_transform 
*ht)
+hip_transform_suite hip_select_hip_transform(const struct hip_tlv_common *ht)
 {
-    hip_transform_suite        tid = 0;
-    int                        i;
-    int                        length;
+    int                        item_number = HIP_TRANSFORM_HIP_MAX;
+    hip_transform_suite        tid         = 0;
     const hip_transform_suite *suggestion;
-
-    length     = ntohs(ht->length);
-    suggestion = (const hip_transform_suite *) &ht->suite_id[0];
-
-    if ((length >> 1) > 6) {
-        HIP_ERROR("Too many transforms (%d)\n", length >> 1);
-        goto out;
-    }
-
-    for (i = 0; i < length; i++) {
-        switch (ntohs(*suggestion)) {
+    hip_transform_suite        suite[item_number];
+
+    item_number = hip_get_list_from_param(ht, suite, item_number,
+                                          sizeof(hip_transform_suite));
+
+    suggestion = suite;
+    while (item_number-- > 0) {
+        switch (*suggestion) {
         case HIP_HIP_AES_SHA1:
         case HIP_HIP_3DES_SHA1:
         case HIP_HIP_NULL_SHA1:
-            tid = ntohs(*suggestion);
+            tid = *suggestion;
             goto out;
-            break;
 
         default:
             /* Specs don't say what to do when unknown are found.
@@ -88,35 +83,41 @@
 
 /**
  * select an ESP transform to use
- * @param ht ESP_TRANSFORM payload where the transform is selected from
+ * @param param ESP_TRANSFORM payload where the transform is selected from
  *
- * @return the first acceptable Suite-ID or negative if no
- * acceptable Suite-ID was found.
+ * @return      the first acceptable Suite-ID or zero if no acceptable
+ *              Suite-ID was found.
  */
-hip_transform_suite hip_select_esp_transform(const struct hip_esp_transform 
*ht)
+hip_transform_suite hip_select_esp_transform(const struct hip_tlv_common 
*param)
 {
-    hip_transform_suite        tid = 0;
-    unsigned                   i, length;
+    int                        item_number = HIP_TRANSFORM_ESP_MAX;
+    hip_transform_suite        tid         = 0;
+    hip_transform_suite        suite[item_number];
     const hip_transform_suite *suggestion;
 
-    length     = hip_get_param_contents_len(ht);
-    suggestion = (const hip_transform_suite *) &ht->suite_id[0];
-
-    for (i = 0; i < length; i++) {
-        switch (ntohs(*suggestion)) {
+    item_number = hip_get_list_from_param(param, suite, item_number,
+                                          sizeof(hip_transform_suite));
+
+    /* the first item in the list is a reserved field and should be ignored */
+    if (--item_number < 1) {
+        HIP_ERROR("No ESP suite id can be found\n");
+        return 0;
+    }
+    suggestion = &suite[1];
+
+    while (item_number-- > 0) {
+        switch (*suggestion) {
         case HIP_ESP_AES_SHA1:
         case HIP_ESP_NULL_NULL:
         case HIP_ESP_3DES_SHA1:
         case HIP_ESP_NULL_SHA1:
-            tid = ntohs(*suggestion);
+            tid = *suggestion;
             goto out;
-            break;
         default:
             /* Specs don't say what to do when unknowns are found.
              * We ignore.
              */
-            HIP_ERROR("Unknown ESP suite id suggestion (%u)\n",
-                      ntohs(*suggestion));
+            HIP_ERROR("Unknown ESP suite id suggestion (%u)\n", *suggestion);
             break;
         }
         suggestion++;

=== modified file 'libcore/transform.h'
--- libcore/transform.h 2012-05-12 06:54:33 +0000
+++ libcore/transform.h 2012-06-07 12:45:16 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010 Aalto University and RWTH Aachen University.
+ * Copyright (c) 2010, 2012 Aalto University and RWTH Aachen University.
  *
  * Permission is hereby granted, free of charge, to any person
  * obtaining a copy of this software and associated documentation
@@ -28,8 +28,8 @@
 
 #include "protodefs.h"
 
-hip_transform_suite hip_select_esp_transform(const struct hip_esp_transform *);
-hip_transform_suite hip_select_hip_transform(const struct hip_hip_transform *);
+hip_transform_suite hip_select_esp_transform(const struct hip_tlv_common 
*param);
+hip_transform_suite hip_select_hip_transform(const struct hip_tlv_common 
*param);
 int hip_transform_key_length(int tid);
 
 #endif /* HIPL_LIBCORE_TRANSFORM_H */

=== modified file 'libhipl/close.c'
--- libhipl/close.c     2012-05-12 10:21:32 +0000
+++ libhipl/close.c     2012-06-03 10:26:55 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010-2011 Aalto University and RWTH Aachen University.
+ * Copyright (c) 2010-2012 Aalto University and RWTH Aachen University.
  *
  * Permission is hereby granted, free of charge, to any person
  * obtaining a copy of this software and associated documentation
@@ -115,7 +115,8 @@
                           HIP_CLOSE,
                           mask,
                           &entry->hit_our,
-                          &entry->hit_peer);
+                          &entry->hit_peer,
+                          entry->hip_version);
 
     /********ECHO (SIGNED) **********/
 
@@ -300,7 +301,8 @@
                           HIP_CLOSE_ACK,
                           HIP_PACKET_CTRL_NON,
                           &ctx->hadb_entry->hit_our,
-                          &ctx->hadb_entry->hit_peer);
+                          &ctx->hadb_entry->hit_peer,
+                          ctx->hadb_entry->hip_version);
 
     HIP_IFEL(hip_build_param_echo(ctx->output_msg, request + 1,
                                   echo_len, 1, 0), -1,

=== modified file 'libhipl/cookie.c'
--- libhipl/cookie.c    2012-05-12 10:21:32 +0000
+++ libhipl/cookie.c    2012-06-03 10:26:55 +0000
@@ -179,16 +179,17 @@
 /**
  * get a copy of R1entry structure
  *
- * @param ip_i Initiator's IPv6
- * @param ip_r Responder's IPv6
- * @param our_hit Our HIT
+ * @param ip_i        Initiator's IPv6
+ * @param ip_r        Responder's IPv6
+ * @param our_hit     Our HIT
+ * @param hip_version HIP message version
  *
  * @note Comments for the if 0 code are inlined below.
  *
  * Returns NULL if error.
  */
 struct hip_common *hip_get_r1(struct in6_addr *ip_i, struct in6_addr *ip_r,
-                              struct in6_addr *our_hit)
+                              struct in6_addr *our_hit, uint8_t hip_version)
 {
     struct hip_common    *err         = NULL, *r1 = NULL;
     struct hip_r1entry   *hip_r1table = NULL;
@@ -199,7 +200,7 @@
     HIP_IFEL(!(hid = hip_get_hostid_entry_by_lhi_and_algo(our_hit, 
HIP_ANY_ALGO, -1)),
              NULL, "Unknown HIT\n");
 
-    hip_r1table = hid->r1;
+    hip_r1table = hid->r1[hip_version];
     idx         = calc_cookie_idx(ip_i, ip_r);
     HIP_DEBUG("Calculated index: %d\n", idx);
 
@@ -220,18 +221,20 @@
 /**
  * precreate an R1 packet
  *
- * @param r1table a pointer to R1 table structure
- * @param hit the local HIT
- * @param sign a signing callback function
- * @param privkey the private key to use for signing
- * @param pubkey the host id (public key)
- * @return zero on success and non-zero on error
+ * @param r1table     a pointer to R1 table structure
+ * @param hit         the local HIT
+ * @param sign        a signing callback function
+ * @param privkey     the private key to use for signing
+ * @param pubkey      the host id (public key)
+ * @param hip_version HIP message version
+ * @return            zero on success and non-zero on error
  */
 int hip_precreate_r1(struct hip_r1entry *const r1table,
                      const struct in6_addr *const hit,
                      int (*sign)(void *const key, struct hip_common *const m),
                      void *const privkey,
-                     const struct hip_host_id *const pubkey)
+                     const struct hip_host_id *const pubkey,
+                     const uint8_t hip_version)
 {
     int i = 0;
     for (i = 0; i < HIP_R1TABLESIZE; i++) {
@@ -241,7 +244,8 @@
 
         hip_msg_init(&r1table[i].buf.msg);
 
-        if (hip_create_r1(&r1table[i].buf.msg, hit, sign, privkey, pubkey, 
cookie_k)) {
+        if (hip_create_r1(&r1table[i].buf.msg, hit, sign, privkey, pubkey,
+                          cookie_k, hip_version)) {
             HIP_ERROR("Unable to precreate R1s\n");
             return 0;
         }
@@ -257,16 +261,18 @@
  * as in the puzzle we sent. If not, then we check the previous ones (since the
  * puzzle might just have been expired).
  *
- * @param ip_i     a pointer to Initiator's IP address.
- * @param ip_r     a pointer to Responder's IP address.
- * @param hdr      a pointer to HIP packet common header
- * @param solution a pointer to a solution structure
- * @return         Zero if the cookie was verified successfully, negative
- *                 otherwise.
+ * @param ip_i        a pointer to Initiator's IP address.
+ * @param ip_r        a pointer to Responder's IP address.
+ * @param hdr         a pointer to HIP packet common header
+ * @param solution    a pointer to a solution structure
+ * @param hip_version HIP message version
+ * @return            Zero if the cookie was verified successfully, negative
+ *                    otherwise.
  */
 int hip_verify_cookie(struct in6_addr *ip_i, struct in6_addr *ip_r,
                       struct hip_common *hdr,
-                      const struct hip_solution *solution)
+                      const struct hip_solution *solution,
+                      const uint8_t hip_version)
 {
     /* In a effort to conform the HIPL coding convention, the return value
      * of this function was inverted. I.e. This function now returns
@@ -283,7 +289,7 @@
                                                           HIP_ANY_ALGO,
                                                           -1)),
              -1, "Requested source HIT not (any more) available.\n");
-    result = &hid->r1[calc_cookie_idx(ip_i, ip_r)];
+    result = &hid->r1[hip_version][calc_cookie_idx(ip_i, ip_r)];
 
     puzzle = hip_get_param(&result->buf.msg, HIP_PARAM_PUZZLE);
     HIP_IFEL(!puzzle, -1, "Internal error: could not find the cookie\n");
@@ -338,6 +344,7 @@
 static int recreate_r1s_for_entry_move(struct local_host_id *entry,
                                        UNUSED void *opaque)
 {
+    int i;
     int (*signature_func)(void *const key, struct hip_common *const m);
 
     switch (hip_get_host_id_algo(&entry->host_id)) {
@@ -357,9 +364,11 @@
         return -1;
     }
 
-    if (!hip_precreate_r1(entry->r1, &entry->hit, signature_func,
-                          entry->private_key, &entry->host_id)) {
-        return -1;
+    for (i = 1; i < HIP_MAX_VERSION; i++) {
+        if (!hip_precreate_r1(entry->r1[i], &entry->hit, signature_func,
+                              entry->private_key, &entry->host_id, i)) {
+            return -1;
+        }
     }
 
     return 0;

=== modified file 'libhipl/cookie.h'
--- libhipl/cookie.h    2012-05-12 10:21:32 +0000
+++ libhipl/cookie.h    2012-06-03 10:26:55 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010 Aalto University and RWTH Aachen University.
+ * Copyright (c) 2010, 2012 Aalto University and RWTH Aachen University.
  *
  * Permission is hereby granted, free of charge, to any person
  * obtaining a copy of this software and associated documentation
@@ -43,16 +43,19 @@
 
 struct hip_common *hip_get_r1(struct in6_addr *ip_i,
                               struct in6_addr *ip_r,
-                              struct in6_addr *peer_hit);
+                              struct in6_addr *peer_hit,
+                              uint8_t hip_version);
 int hip_recreate_all_precreated_r1_packets(void);
 int hip_precreate_r1(struct hip_r1entry *const r1table,
                      const struct in6_addr *const hit,
                      int (*sign)(void *const key, struct hip_common *const m),
                      void *const privkey,
-                     const struct hip_host_id *const pubkey);
+                     const struct hip_host_id *const pubkey,
+                     const uint8_t hip_version);
 int hip_verify_cookie(struct in6_addr *ip_i, struct in6_addr *ip_r,
                       struct hip_common *hdr,
-                      const struct hip_solution *cookie);
+                      const struct hip_solution *cookie,
+                      const uint8_t hip_version);
 int hip_inc_cookie_difficulty(void);
 int hip_dec_cookie_difficulty(void);
 int hip_get_puzzle_difficulty_msg(struct hip_common *msg);

=== modified file 'libhipl/esp_prot_hipd_msg.c'
--- libhipl/esp_prot_hipd_msg.c 2012-05-12 10:21:32 +0000
+++ libhipl/esp_prot_hipd_msg.c 2012-06-03 10:26:55 +0000
@@ -92,7 +92,8 @@
                           HIP_UPDATE,
                           mask,
                           &recv_update->hit_receiver,
-                          &recv_update->hit_sender);
+                          &recv_update->hit_sender,
+                          entry->hip_version);
 
     /* Add ESP_INFO */
     HIP_IFEL(hip_build_param_esp_info(resp_update,

=== modified file 'libhipl/esp_prot_light_update.c'
--- libhipl/esp_prot_light_update.c     2012-05-12 10:21:32 +0000
+++ libhipl/esp_prot_light_update.c     2012-06-03 10:26:55 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010-2011 Aalto University and RWTH Aachen University.
+ * Copyright (c) 2010-2012 Aalto University and RWTH Aachen University.
  *
  * Permission is hereby granted, free of charge, to any person
  * obtaining a copy of this software and associated documentation
@@ -76,7 +76,8 @@
                           HIP_LUPDATE,
                           mask,
                           &entry->hit_our,
-                          &entry->hit_peer);
+                          &entry->hit_peer,
+                          entry->hip_version);
 
     /* Add ESP_INFO */
     HIP_IFEL(hip_build_param_esp_info(light_ack, entry->current_keymat_index,
@@ -134,7 +135,8 @@
                           HIP_LUPDATE,
                           mask,
                           &entry->hit_our,
-                          &entry->hit_peer);
+                          &entry->hit_peer,
+                          entry->hip_version);
 
     /********************* add SEQ *********************/
 

=== modified file 'libhipl/hidb.c'
--- libhipl/hidb.c      2012-05-12 10:21:32 +0000
+++ libhipl/hidb.c      2012-06-03 10:26:55 +0000
@@ -429,6 +429,7 @@
                        hip_lsi_t *lsi,
                        const struct hip_host_id_priv *host_id)
 {
+    int                   i;
     int                   err      = 0;
     struct local_host_id *id_entry = NULL;
     struct local_host_id *old_entry;
@@ -492,13 +493,16 @@
         err = -1;
         goto out_err;
     }
-
-    HIP_IFEL(!hip_precreate_r1(id_entry->r1,
-                               &hit,
-                               signature_func,
-                               id_entry->private_key, &id_entry->host_id),
-             -ENOENT,
-             "Unable to precreate R1s.\n");
+    for (i = 1; i < HIP_MAX_VERSION; i++) {
+        HIP_IFEL(!hip_precreate_r1(id_entry->r1[i],
+                                   &hit,
+                                   signature_func,
+                                   id_entry->private_key,
+                                   &id_entry->host_id,
+                                   i),
+                 -ENOENT,
+                 "Unable to precreate R1s.\n");
+    }
 
 out_err:
     if (err && id_entry) {

=== modified file 'libhipl/hidb.h'
--- libhipl/hidb.h      2012-05-12 10:21:32 +0000
+++ libhipl/hidb.h      2012-06-03 10:26:55 +0000
@@ -45,7 +45,7 @@
     hip_lsi_t          lsi;
     struct hip_host_id host_id;
     void              *private_key;       /* RSA or DSA */
-    struct hip_r1entry r1[HIP_R1TABLESIZE];       /* precreated R1s */
+    struct hip_r1entry r1[HIP_MAX_VERSION][HIP_R1TABLESIZE];    /* precreated 
R1s */
 };
 
 struct local_host_id *hip_get_hostid_entry_by_lhi_and_algo(const struct 
in6_addr *const hit,

=== modified file 'libhipl/hiprelay.c'
--- libhipl/hiprelay.c  2012-05-12 10:21:32 +0000
+++ libhipl/hiprelay.c  2012-06-03 10:26:55 +0000
@@ -851,7 +851,8 @@
 
     hip_build_network_hdr(msg_to_be_relayed, type_hdr, 0,
                           &ctx->input_msg->hit_sender,
-                          &ctx->input_msg->hit_receiver);
+                          &ctx->input_msg->hit_receiver,
+                          hip_get_msg_version(ctx->input_msg));
 
     /* Notice that in most cases the incoming I1 has no paramaters at all,
      * and this "while" loop is skipped. Multiple rvses en route to responder
@@ -962,7 +963,8 @@
              "No memory to copy original I1\n");
 
     hip_build_network_hdr(r_to_be_relayed, type_hdr, 0,
-                          &r->hit_sender, &r->hit_receiver);
+                          &r->hit_sender, &r->hit_receiver,
+                          hip_get_msg_version(r));
 
     while ((current_param = hip_get_next_param(r, current_param)) != NULL) {
         HIP_DEBUG("Found parameter in R.\n");

=== modified file 'libhipl/init.c'
--- libhipl/init.c      2012-05-12 10:21:32 +0000
+++ libhipl/init.c      2012-07-12 11:32:14 +0000
@@ -151,6 +151,11 @@
 /* Startup flags of the HIPD. Keep the around, for they will be used at exit */
 static uint64_t sflags;
 
+/* The value of the default HIP version loaded from hipd.conf. Its accessor
+ * functions are hip_set_default_version() and hip_get_default_version().
+ */
+static uint8_t hip_default_hip_version = 1;
+
 
/******************************************************************************/
 /**
  * Catch SIGCHLD.
@@ -553,403 +558,399 @@
     lmod_register_packet_type(HIP_LUPDATE,   "HIP_LUPDATE");
 }
 
+static void init_handle_functions(void)
+{
+    HIP_DEBUG("Initialize handle functions.\n");
+
+    hip_register_handle_function(HIP_ALL, HIP_I1, HIP_STATE_UNASSOCIATED, 
&hip_check_i1,  20000);
+    hip_register_handle_function(HIP_ALL, HIP_I1, HIP_STATE_UNASSOCIATED, 
&hip_handle_i1, 30000);
+    hip_register_handle_function(HIP_ALL, HIP_I1, HIP_STATE_UNASSOCIATED, 
&hip_update_retransmissions, 35000);
+    hip_register_handle_function(HIP_ALL, HIP_I1, HIP_STATE_UNASSOCIATED, 
&hip_send_r1,   40000);
+    hip_register_handle_function(HIP_ALL, HIP_I1, HIP_STATE_I1_SENT, 
&hip_check_i1,  20000);
+    hip_register_handle_function(HIP_ALL, HIP_I1, HIP_STATE_I1_SENT, 
&hip_handle_i1, 30000);
+    hip_register_handle_function(HIP_ALL, HIP_I1, HIP_STATE_I1_SENT, 
&hip_update_retransmissions, 35000);
+    hip_register_handle_function(HIP_ALL, HIP_I1, HIP_STATE_I1_SENT, 
&hip_send_r1,   40000);
+    hip_register_handle_function(HIP_ALL, HIP_I1, HIP_STATE_I2_SENT, 
&hip_check_i1,  20000);
+    hip_register_handle_function(HIP_ALL, HIP_I1, HIP_STATE_I2_SENT, 
&hip_handle_i1, 30000);
+    hip_register_handle_function(HIP_ALL, HIP_I1, HIP_STATE_I2_SENT, 
&hip_update_retransmissions, 35000);
+    hip_register_handle_function(HIP_ALL, HIP_I1, HIP_STATE_I2_SENT, 
&hip_send_r1,   40000);
+    hip_register_handle_function(HIP_ALL, HIP_I1, HIP_STATE_R2_SENT, 
&hip_check_i1,  20000);
+    hip_register_handle_function(HIP_ALL, HIP_I1, HIP_STATE_R2_SENT, 
&hip_handle_i1, 30000);
+    hip_register_handle_function(HIP_ALL, HIP_I1, HIP_STATE_R2_SENT, 
&hip_update_retransmissions, 35000);
+    hip_register_handle_function(HIP_ALL, HIP_I1, HIP_STATE_R2_SENT, 
&hip_send_r1,   40000);
+    hip_register_handle_function(HIP_ALL, HIP_I1, HIP_STATE_ESTABLISHED, 
&hip_check_i1,  20000);
+    hip_register_handle_function(HIP_ALL, HIP_I1, HIP_STATE_ESTABLISHED, 
&hip_handle_i1, 30000);
+    hip_register_handle_function(HIP_ALL, HIP_I1, HIP_STATE_ESTABLISHED, 
&hip_update_retransmissions, 35000);
+    hip_register_handle_function(HIP_ALL, HIP_I1, HIP_STATE_ESTABLISHED, 
&hip_send_r1,   40000);
+    hip_register_handle_function(HIP_ALL, HIP_I1, HIP_STATE_CLOSING, 
&hip_check_i1,  20000);
+    hip_register_handle_function(HIP_ALL, HIP_I1, HIP_STATE_CLOSING, 
&hip_handle_i1, 30000);
+    hip_register_handle_function(HIP_ALL, HIP_I1, HIP_STATE_CLOSING, 
&hip_update_retransmissions, 35000);
+    hip_register_handle_function(HIP_ALL, HIP_I1, HIP_STATE_CLOSING, 
&hip_send_r1,   40000);
+    hip_register_handle_function(HIP_ALL, HIP_I1, HIP_STATE_CLOSED, 
&hip_check_i1,  20000);
+    hip_register_handle_function(HIP_ALL, HIP_I1, HIP_STATE_CLOSED, 
&hip_handle_i1, 30000);
+    hip_register_handle_function(HIP_ALL, HIP_I1, HIP_STATE_CLOSED, 
&hip_update_retransmissions, 35000);
+    hip_register_handle_function(HIP_ALL, HIP_I1, HIP_STATE_CLOSED, 
&hip_send_r1,   40000);
+    hip_register_handle_function(HIP_ALL, HIP_I1, HIP_STATE_NONE, 
&hip_check_i1,  20000);
+    hip_register_handle_function(HIP_ALL, HIP_I1, HIP_STATE_NONE, 
&hip_handle_i1, 30000);
+    hip_register_handle_function(HIP_ALL, HIP_I1, HIP_STATE_NONE, 
&hip_update_retransmissions, 35000);
+    hip_register_handle_function(HIP_ALL, HIP_I1, HIP_STATE_NONE, 
&hip_send_r1,   40000);
+
+    hip_register_handle_function(HIP_ALL, HIP_I2, HIP_STATE_UNASSOCIATED, 
&hip_check_i2,  20000);
+    hip_register_handle_function(HIP_ALL, HIP_I2, HIP_STATE_UNASSOCIATED, 
&hip_handle_i2, 30000);
+    hip_register_handle_function(HIP_ALL, HIP_I2, HIP_STATE_UNASSOCIATED, 
&hip_update_retransmissions, 30250);
+    hip_register_handle_function(HIP_ALL, HIP_I2, HIP_STATE_UNASSOCIATED, 
&hip_setup_ipsec_sa, 30500);
+    hip_register_handle_function(HIP_ALL, HIP_I2, HIP_STATE_UNASSOCIATED, 
&hip_create_r2, 40000);
+    hip_register_handle_function(HIP_ALL, HIP_I2, HIP_STATE_UNASSOCIATED, 
&hip_add_rvs_reg_from, 41000);
+    hip_register_handle_function(HIP_ALL, HIP_I2, HIP_STATE_UNASSOCIATED, 
&hip_hmac2_and_sign, 42000);
+    hip_register_handle_function(HIP_ALL, HIP_I2, HIP_STATE_UNASSOCIATED, 
&hip_add_rvs_relay_to, 43000);
+    hip_register_handle_function(HIP_ALL, HIP_I2, HIP_STATE_UNASSOCIATED, 
&hip_send_r2, 50000);
+    hip_register_handle_function(HIP_ALL, HIP_I2, HIP_STATE_I1_SENT, 
&hip_check_i2,  20000);
+    hip_register_handle_function(HIP_ALL, HIP_I2, HIP_STATE_I1_SENT, 
&hip_handle_i2, 30000);
+    hip_register_handle_function(HIP_ALL, HIP_I2, HIP_STATE_I1_SENT, 
&hip_update_retransmissions, 30250);
+    hip_register_handle_function(HIP_ALL, HIP_I2, HIP_STATE_I1_SENT, 
&hip_setup_ipsec_sa, 30500);
+    hip_register_handle_function(HIP_ALL, HIP_I2, HIP_STATE_I1_SENT, 
&hip_create_r2, 40000);
+    hip_register_handle_function(HIP_ALL, HIP_I2, HIP_STATE_I1_SENT, 
&hip_add_rvs_reg_from, 41000);
+    hip_register_handle_function(HIP_ALL, HIP_I2, HIP_STATE_I1_SENT, 
&hip_hmac2_and_sign, 42000);
+    hip_register_handle_function(HIP_ALL, HIP_I2, HIP_STATE_I1_SENT, 
&hip_add_rvs_relay_to, 43000);
+    hip_register_handle_function(HIP_ALL, HIP_I2, HIP_STATE_I1_SENT, 
&hip_send_r2, 50000);
+    hip_register_handle_function(HIP_ALL, HIP_I2, HIP_STATE_I2_SENT, 
&hip_check_i2,             20000);
+    hip_register_handle_function(HIP_ALL, HIP_I2, HIP_STATE_I2_SENT, 
&hip_handle_i2_in_i2_sent, 21000);
+    hip_register_handle_function(HIP_ALL, HIP_I2, HIP_STATE_I2_SENT, 
&hip_handle_i2,            30000);
+    hip_register_handle_function(HIP_ALL, HIP_I2, HIP_STATE_I2_SENT, 
&hip_update_retransmissions, 30250);
+    hip_register_handle_function(HIP_ALL, HIP_I2, HIP_STATE_I2_SENT, 
&hip_setup_ipsec_sa, 30500);
+    hip_register_handle_function(HIP_ALL, HIP_I2, HIP_STATE_I2_SENT, 
&hip_create_r2, 40000);
+    hip_register_handle_function(HIP_ALL, HIP_I2, HIP_STATE_I2_SENT, 
&hip_add_rvs_reg_from, 41000);
+    hip_register_handle_function(HIP_ALL, HIP_I2, HIP_STATE_I2_SENT, 
&hip_hmac2_and_sign, 42000);
+    hip_register_handle_function(HIP_ALL, HIP_I2, HIP_STATE_I2_SENT, 
&hip_add_rvs_relay_to, 43000);
+    hip_register_handle_function(HIP_ALL, HIP_I2, HIP_STATE_I2_SENT, 
&hip_send_r2, 50000);
+    hip_register_handle_function(HIP_ALL, HIP_I2, HIP_STATE_R2_SENT, 
&hip_check_i2,  20000);
+    hip_register_handle_function(HIP_ALL, HIP_I2, HIP_STATE_R2_SENT, 
&hip_handle_i2, 30000);
+    hip_register_handle_function(HIP_ALL, HIP_I2, HIP_STATE_R2_SENT, 
&hip_update_retransmissions, 30250);
+    hip_register_handle_function(HIP_ALL, HIP_I2, HIP_STATE_R2_SENT, 
&hip_setup_ipsec_sa, 30500);
+    hip_register_handle_function(HIP_ALL, HIP_I2, HIP_STATE_R2_SENT, 
&hip_create_r2, 40000);
+    hip_register_handle_function(HIP_ALL, HIP_I2, HIP_STATE_R2_SENT, 
&hip_add_rvs_reg_from, 41000);
+    hip_register_handle_function(HIP_ALL, HIP_I2, HIP_STATE_R2_SENT, 
&hip_hmac2_and_sign, 42000);
+    hip_register_handle_function(HIP_ALL, HIP_I2, HIP_STATE_R2_SENT, 
&hip_add_rvs_relay_to, 43000);
+    hip_register_handle_function(HIP_ALL, HIP_I2, HIP_STATE_R2_SENT, 
&hip_send_r2, 50000);
+    hip_register_handle_function(HIP_ALL, HIP_I2, HIP_STATE_ESTABLISHED, 
&hip_check_i2,  20000);
+    hip_register_handle_function(HIP_ALL, HIP_I2, HIP_STATE_ESTABLISHED, 
&hip_handle_i2, 30000);
+    hip_register_handle_function(HIP_ALL, HIP_I2, HIP_STATE_ESTABLISHED, 
&hip_update_retransmissions, 30250);
+    hip_register_handle_function(HIP_ALL, HIP_I2, HIP_STATE_ESTABLISHED, 
&hip_setup_ipsec_sa, 30500);
+    hip_register_handle_function(HIP_ALL, HIP_I2, HIP_STATE_ESTABLISHED, 
&hip_create_r2, 40000);
+    hip_register_handle_function(HIP_ALL, HIP_I2, HIP_STATE_ESTABLISHED, 
&hip_add_rvs_reg_from, 41000);
+    hip_register_handle_function(HIP_ALL, HIP_I2, HIP_STATE_ESTABLISHED, 
&hip_hmac2_and_sign, 42000);
+    hip_register_handle_function(HIP_ALL, HIP_I2, HIP_STATE_ESTABLISHED, 
&hip_add_rvs_relay_to, 43000);
+    hip_register_handle_function(HIP_ALL, HIP_I2, HIP_STATE_ESTABLISHED, 
&hip_send_r2, 50000);
+    hip_register_handle_function(HIP_ALL, HIP_I2, HIP_STATE_CLOSING, 
&hip_check_i2,  20000);
+    hip_register_handle_function(HIP_ALL, HIP_I2, HIP_STATE_CLOSING, 
&hip_handle_i2, 30000);
+    hip_register_handle_function(HIP_ALL, HIP_I2, HIP_STATE_CLOSING, 
&hip_update_retransmissions, 30250);
+    hip_register_handle_function(HIP_ALL, HIP_I2, HIP_STATE_CLOSING, 
&hip_setup_ipsec_sa, 30500);
+    hip_register_handle_function(HIP_ALL, HIP_I2, HIP_STATE_CLOSING, 
&hip_create_r2, 40000);
+    hip_register_handle_function(HIP_ALL, HIP_I2, HIP_STATE_CLOSING, 
&hip_add_rvs_reg_from, 41000);
+    hip_register_handle_function(HIP_ALL, HIP_I2, HIP_STATE_CLOSING, 
&hip_hmac2_and_sign, 42000);
+    hip_register_handle_function(HIP_ALL, HIP_I2, HIP_STATE_CLOSING, 
&hip_add_rvs_relay_to, 43000);
+    hip_register_handle_function(HIP_ALL, HIP_I2, HIP_STATE_CLOSING, 
&hip_send_r2, 50000);
+    hip_register_handle_function(HIP_ALL, HIP_I2, HIP_STATE_CLOSED, 
&hip_check_i2,  20000);
+    hip_register_handle_function(HIP_ALL, HIP_I2, HIP_STATE_CLOSED, 
&hip_handle_i2, 30000);
+    hip_register_handle_function(HIP_ALL, HIP_I2, HIP_STATE_CLOSED, 
&hip_update_retransmissions, 30250);
+    hip_register_handle_function(HIP_ALL, HIP_I2, HIP_STATE_CLOSED, 
&hip_setup_ipsec_sa, 30500);
+    hip_register_handle_function(HIP_ALL, HIP_I2, HIP_STATE_CLOSED, 
&hip_create_r2, 40000);
+    hip_register_handle_function(HIP_ALL, HIP_I2, HIP_STATE_CLOSED, 
&hip_add_rvs_reg_from, 41000);
+    hip_register_handle_function(HIP_ALL, HIP_I2, HIP_STATE_CLOSED, 
&hip_hmac2_and_sign, 42000);
+    hip_register_handle_function(HIP_ALL, HIP_I2, HIP_STATE_CLOSED, 
&hip_add_rvs_relay_to, 43000);
+    hip_register_handle_function(HIP_ALL, HIP_I2, HIP_STATE_CLOSED, 
&hip_send_r2, 50000);
+    hip_register_handle_function(HIP_ALL, HIP_I2, HIP_STATE_NONE, 
&hip_check_i2,  20000);
+    hip_register_handle_function(HIP_ALL, HIP_I2, HIP_STATE_NONE, 
&hip_handle_i2, 30000);
+    hip_register_handle_function(HIP_ALL, HIP_I2, HIP_STATE_NONE, 
&hip_update_retransmissions, 30250);
+    hip_register_handle_function(HIP_ALL, HIP_I2, HIP_STATE_NONE, 
&hip_setup_ipsec_sa, 30500);
+    hip_register_handle_function(HIP_ALL, HIP_I2, HIP_STATE_NONE, 
&hip_create_r2, 40000);
+    hip_register_handle_function(HIP_ALL, HIP_I2, HIP_STATE_NONE, 
&hip_add_rvs_reg_from, 41000);
+    hip_register_handle_function(HIP_ALL, HIP_I2, HIP_STATE_NONE, 
&hip_hmac2_and_sign, 42000);
+    hip_register_handle_function(HIP_ALL, HIP_I2, HIP_STATE_NONE, 
&hip_add_rvs_relay_to, 43000);
+    hip_register_handle_function(HIP_ALL, HIP_I2, HIP_STATE_NONE, 
&hip_send_r2, 50000);
+
+    hip_register_handle_function(HIP_ALL, HIP_R1, HIP_STATE_I1_SENT, 
&hip_check_r1,  20000);
+    hip_register_handle_function(HIP_ALL, HIP_R1, HIP_STATE_I1_SENT, 
&hip_handle_r1, 30000);
+    hip_register_handle_function(HIP_ALL, HIP_R1, HIP_STATE_I1_SENT, 
&hip_update_retransmissions, 30500);
+    hip_register_handle_function(HIP_ALL, HIP_R1, HIP_STATE_I1_SENT, 
&hip_build_esp_info, 31000);
+    hip_register_handle_function(HIP_ALL, HIP_R1, HIP_STATE_I1_SENT, 
&hip_build_solution, 32000);
+    hip_register_handle_function(HIP_ALL, HIP_R1, HIP_STATE_I1_SENT, 
&hip_handle_diffie_hellman, 33000);
+    hip_register_handle_function(HIP_ALL, HIP_R1, HIP_STATE_I1_SENT, 
&esp_prot_r1_handle_transforms, 34000);
+    hip_register_handle_function(HIP_ALL, HIP_R1, HIP_STATE_I1_SENT, 
&hip_create_i2, 40000);
+    hip_register_handle_function(HIP_ALL, HIP_R1, HIP_STATE_I1_SENT, 
&hip_add_signed_echo_response, 41000);
+    hip_register_handle_function(HIP_ALL, HIP_R1, HIP_STATE_I1_SENT, 
&hip_mac_and_sign_handler, 42000);
+    hip_register_handle_function(HIP_ALL, HIP_R1, HIP_STATE_I1_SENT, 
&hip_add_unsigned_echo_response, 43000);
+    hip_register_handle_function(HIP_ALL, HIP_R1, HIP_STATE_I1_SENT, 
&hip_send_i2,   50000);
+    hip_register_handle_function(HIP_ALL, HIP_R1, HIP_STATE_I2_SENT, 
&hip_check_r1,  20000);
+    hip_register_handle_function(HIP_ALL, HIP_R1, HIP_STATE_I2_SENT, 
&hip_handle_r1, 30000);
+    hip_register_handle_function(HIP_ALL, HIP_R1, HIP_STATE_I2_SENT, 
&hip_update_retransmissions, 30500);
+    hip_register_handle_function(HIP_ALL, HIP_R1, HIP_STATE_I2_SENT, 
&hip_build_esp_info, 31000);
+    hip_register_handle_function(HIP_ALL, HIP_R1, HIP_STATE_I2_SENT, 
&hip_build_solution, 32000);
+    hip_register_handle_function(HIP_ALL, HIP_R1, HIP_STATE_I2_SENT, 
&hip_handle_diffie_hellman, 33000);
+    hip_register_handle_function(HIP_ALL, HIP_R1, HIP_STATE_I2_SENT, 
&esp_prot_r1_handle_transforms, 34000);
+    hip_register_handle_function(HIP_ALL, HIP_R1, HIP_STATE_I2_SENT, 
&hip_create_i2, 40000);
+    hip_register_handle_function(HIP_ALL, HIP_R1, HIP_STATE_I2_SENT, 
&hip_add_signed_echo_response, 41000);
+    hip_register_handle_function(HIP_ALL, HIP_R1, HIP_STATE_I2_SENT, 
&hip_mac_and_sign_handler, 42000);
+    hip_register_handle_function(HIP_ALL, HIP_R1, HIP_STATE_I2_SENT, 
&hip_add_unsigned_echo_response, 43000);
+    hip_register_handle_function(HIP_ALL, HIP_R1, HIP_STATE_I2_SENT, 
&hip_send_i2,   50000);
+    hip_register_handle_function(HIP_ALL, HIP_R1, HIP_STATE_CLOSING, 
&hip_check_r1,  20000);
+    hip_register_handle_function(HIP_ALL, HIP_R1, HIP_STATE_CLOSING, 
&hip_handle_r1, 30000);
+    hip_register_handle_function(HIP_ALL, HIP_R1, HIP_STATE_CLOSING, 
&hip_update_retransmissions, 30500);
+    hip_register_handle_function(HIP_ALL, HIP_R1, HIP_STATE_CLOSING, 
&hip_build_esp_info, 31000);
+    hip_register_handle_function(HIP_ALL, HIP_R1, HIP_STATE_CLOSING, 
&hip_build_solution, 32000);
+    hip_register_handle_function(HIP_ALL, HIP_R1, HIP_STATE_CLOSING, 
&hip_handle_diffie_hellman, 33000);
+    hip_register_handle_function(HIP_ALL, HIP_R1, HIP_STATE_CLOSING, 
&esp_prot_r1_handle_transforms, 34000);
+    hip_register_handle_function(HIP_ALL, HIP_R1, HIP_STATE_CLOSING, 
&hip_create_i2, 40000);
+    hip_register_handle_function(HIP_ALL, HIP_R1, HIP_STATE_CLOSING, 
&hip_add_signed_echo_response, 41000);
+    hip_register_handle_function(HIP_ALL, HIP_R1, HIP_STATE_CLOSING, 
&hip_mac_and_sign_handler, 42000);
+    hip_register_handle_function(HIP_ALL, HIP_R1, HIP_STATE_CLOSING, 
&hip_add_unsigned_echo_response, 43000);
+    hip_register_handle_function(HIP_ALL, HIP_R1, HIP_STATE_CLOSING, 
&hip_send_i2,   50000);
+    hip_register_handle_function(HIP_ALL, HIP_R1, HIP_STATE_CLOSED, 
&hip_check_r1,  20000);
+    hip_register_handle_function(HIP_ALL, HIP_R1, HIP_STATE_CLOSED, 
&hip_handle_r1, 30000);
+    hip_register_handle_function(HIP_ALL, HIP_R1, HIP_STATE_CLOSED, 
&hip_update_retransmissions, 30500);
+    hip_register_handle_function(HIP_ALL, HIP_R1, HIP_STATE_CLOSED, 
&hip_build_esp_info, 31000);
+    hip_register_handle_function(HIP_ALL, HIP_R1, HIP_STATE_CLOSED, 
&hip_build_solution, 32000);
+    hip_register_handle_function(HIP_ALL, HIP_R1, HIP_STATE_CLOSED, 
&hip_handle_diffie_hellman, 33000);
+    hip_register_handle_function(HIP_ALL, HIP_R1, HIP_STATE_CLOSED, 
&esp_prot_r1_handle_transforms, 34000);
+    hip_register_handle_function(HIP_ALL, HIP_R1, HIP_STATE_CLOSED, 
&hip_create_i2, 40000);
+    hip_register_handle_function(HIP_ALL, HIP_R1, HIP_STATE_CLOSED, 
&hip_add_signed_echo_response, 41000);
+    hip_register_handle_function(HIP_ALL, HIP_R1, HIP_STATE_CLOSED, 
&hip_mac_and_sign_handler, 42000);
+    hip_register_handle_function(HIP_ALL, HIP_R1, HIP_STATE_CLOSED, 
&hip_add_unsigned_echo_response, 43000);
+    hip_register_handle_function(HIP_ALL, HIP_R1, HIP_STATE_CLOSED, 
&hip_send_i2, 50000);
+
+    hip_register_handle_function(HIP_ALL, HIP_R2, HIP_STATE_I2_SENT, 
&hip_check_r2,  20000);
+    hip_register_handle_function(HIP_ALL, HIP_R2, HIP_STATE_I2_SENT, 
&hip_handle_r2, 30000);
+    hip_register_handle_function(HIP_ALL, HIP_R2, HIP_STATE_I2_SENT, 
&hip_update_retransmissions, 30250);
+    hip_register_handle_function(HIP_ALL, HIP_R2, HIP_STATE_I2_SENT, 
&hip_setup_ipsec_sa, 30500);
+
+    hip_register_handle_function(HIP_ALL, HIP_NOTIFY, HIP_STATE_I1_SENT, 
&hip_check_notify,  20000);
+    hip_register_handle_function(HIP_ALL, HIP_NOTIFY, HIP_STATE_I1_SENT, 
&hip_handle_notify, 30000);
+    hip_register_handle_function(HIP_ALL, HIP_NOTIFY, HIP_STATE_I2_SENT, 
&hip_check_notify,  20000);
+    hip_register_handle_function(HIP_ALL, HIP_NOTIFY, HIP_STATE_I2_SENT, 
&hip_handle_notify, 30000);
+    hip_register_handle_function(HIP_ALL, HIP_NOTIFY, HIP_STATE_R2_SENT, 
&hip_check_notify,  20000);
+    hip_register_handle_function(HIP_ALL, HIP_NOTIFY, HIP_STATE_R2_SENT, 
&hip_handle_notify, 30000);
+    hip_register_handle_function(HIP_ALL, HIP_NOTIFY, HIP_STATE_ESTABLISHED, 
&hip_check_notify, 20000);
+    hip_register_handle_function(HIP_ALL, HIP_NOTIFY, HIP_STATE_ESTABLISHED, 
&hip_handle_notify, 30000);
+    hip_register_handle_function(HIP_ALL, HIP_NOTIFY, HIP_STATE_CLOSING, 
&hip_check_notify,  20000);
+    hip_register_handle_function(HIP_ALL, HIP_NOTIFY, HIP_STATE_CLOSING, 
&hip_handle_notify, 30000);
+    hip_register_handle_function(HIP_ALL, HIP_NOTIFY, HIP_STATE_CLOSED, 
&hip_check_notify,  20000);
+    hip_register_handle_function(HIP_ALL, HIP_NOTIFY, HIP_STATE_CLOSED, 
&hip_handle_notify, 30000);
+
+    hip_register_handle_function(HIP_ALL, HIP_CLOSE, HIP_STATE_ESTABLISHED,  
&hip_close_check_packet,     20000);
+    hip_register_handle_function(HIP_ALL, HIP_CLOSE, HIP_STATE_ESTABLISHED,  
&hip_update_retransmissions, 25000);
+    hip_register_handle_function(HIP_ALL, HIP_CLOSE, HIP_STATE_ESTABLISHED,  
&hip_close_create_response,  30000);
+    hip_register_handle_function(HIP_ALL, HIP_CLOSE, HIP_STATE_ESTABLISHED,  
&hip_close_send_response,    40000);
+
+    hip_register_handle_function(HIP_ALL, HIP_CLOSE, HIP_STATE_CLOSING,  
&hip_close_check_packet,     20000);
+    hip_register_handle_function(HIP_ALL, HIP_CLOSE, HIP_STATE_CLOSING,  
&hip_update_retransmissions, 25000);
+    hip_register_handle_function(HIP_ALL, HIP_CLOSE, HIP_STATE_CLOSING,  
&hip_close_create_response,  30000);
+    hip_register_handle_function(HIP_ALL, HIP_CLOSE, HIP_STATE_CLOSING,  
&hip_close_send_response,    40000);
+
+    hip_register_handle_function(HIP_ALL, HIP_CLOSE_ACK, HIP_STATE_CLOSING, 
&hip_close_ack_check_packet,  20000);
+    hip_register_handle_function(HIP_ALL, HIP_CLOSE_ACK, HIP_STATE_CLOSING, 
&hip_update_retransmissions,  25000);
+    hip_register_handle_function(HIP_ALL, HIP_CLOSE_ACK, HIP_STATE_CLOSING, 
&hip_close_ack_handle_packet, 30000);
+
+    hip_register_handle_function(HIP_ALL, HIP_CLOSE_ACK, HIP_STATE_CLOSED,  
&hip_close_ack_check_packet,  20000);
+    hip_register_handle_function(HIP_ALL, HIP_CLOSE_ACK, HIP_STATE_CLOSED,  
&hip_update_retransmissions,  25000);
+    hip_register_handle_function(HIP_ALL, HIP_CLOSE_ACK, HIP_STATE_CLOSED,  
&hip_close_ack_handle_packet, 30000);
+
+    hip_register_handle_function(HIP_ALL, HIP_LUPDATE, HIP_STATE_ESTABLISHED, 
&esp_prot_handle_light_update, 20000);
+    hip_register_handle_function(HIP_ALL, HIP_LUPDATE, HIP_STATE_R2_SENT,     
&esp_prot_handle_light_update, 20000);
+}
+
 static int libhip_init_handle_functions(void)
 {
     HIP_DEBUG("Initialize handle functions for libhip.\n");
 
-    hip_register_handle_function(HIP_I1, HIP_STATE_UNASSOCIATED, 
&hip_check_i1,  20000);
-    hip_register_handle_function(HIP_I1, HIP_STATE_UNASSOCIATED, 
&hip_handle_i1, 30000);
-    hip_register_handle_function(HIP_I1, HIP_STATE_UNASSOCIATED, 
&hip_update_retransmissions, 35000);
-    hip_register_handle_function(HIP_I1, HIP_STATE_UNASSOCIATED, &hip_send_r1, 
  40000);
-    hip_register_handle_function(HIP_I1, HIP_STATE_I1_SENT, &hip_check_i1,  
20000);
-    hip_register_handle_function(HIP_I1, HIP_STATE_I1_SENT, &hip_handle_i1, 
30000);
-    hip_register_handle_function(HIP_I1, HIP_STATE_I1_SENT, 
&hip_update_retransmissions, 35000);
-    hip_register_handle_function(HIP_I1, HIP_STATE_I1_SENT, &hip_send_r1,   
40000);
-    hip_register_handle_function(HIP_I1, HIP_STATE_I2_SENT, &hip_check_i1,  
20000);
-    hip_register_handle_function(HIP_I1, HIP_STATE_I2_SENT, &hip_handle_i1, 
30000);
-    hip_register_handle_function(HIP_I1, HIP_STATE_I2_SENT, 
&hip_update_retransmissions, 35000);
-    hip_register_handle_function(HIP_I1, HIP_STATE_I2_SENT, &hip_send_r1,   
40000);
-    hip_register_handle_function(HIP_I1, HIP_STATE_R2_SENT, &hip_check_i1,  
20000);
-    hip_register_handle_function(HIP_I1, HIP_STATE_R2_SENT, &hip_handle_i1, 
30000);
-    hip_register_handle_function(HIP_I1, HIP_STATE_R2_SENT, 
&hip_update_retransmissions, 35000);
-    hip_register_handle_function(HIP_I1, HIP_STATE_R2_SENT, &hip_send_r1,   
40000);
-    hip_register_handle_function(HIP_I1, HIP_STATE_ESTABLISHED, &hip_check_i1, 
 20000);
-    hip_register_handle_function(HIP_I1, HIP_STATE_ESTABLISHED, 
&hip_handle_i1, 30000);
-    hip_register_handle_function(HIP_I1, HIP_STATE_ESTABLISHED, 
&hip_update_retransmissions, 35000);
-    hip_register_handle_function(HIP_I1, HIP_STATE_ESTABLISHED, &hip_send_r1,  
 40000);
-    hip_register_handle_function(HIP_I1, HIP_STATE_CLOSING, &hip_check_i1,  
20000);
-    hip_register_handle_function(HIP_I1, HIP_STATE_CLOSING, &hip_handle_i1, 
30000);
-    hip_register_handle_function(HIP_I1, HIP_STATE_CLOSING, 
&hip_update_retransmissions, 35000);
-    hip_register_handle_function(HIP_I1, HIP_STATE_CLOSING, &hip_send_r1,   
40000);
-    hip_register_handle_function(HIP_I1, HIP_STATE_CLOSED, &hip_check_i1,  
20000);
-    hip_register_handle_function(HIP_I1, HIP_STATE_CLOSED, &hip_handle_i1, 
30000);
-    hip_register_handle_function(HIP_I1, HIP_STATE_CLOSED, 
&hip_update_retransmissions, 35000);
-    hip_register_handle_function(HIP_I1, HIP_STATE_CLOSED, &hip_send_r1,   
40000);
-    hip_register_handle_function(HIP_I1, HIP_STATE_NONE, &hip_check_i1,  
20000);
-    hip_register_handle_function(HIP_I1, HIP_STATE_NONE, &hip_handle_i1, 
30000);
-    hip_register_handle_function(HIP_I1, HIP_STATE_NONE, 
&hip_update_retransmissions, 35000);
-    hip_register_handle_function(HIP_I1, HIP_STATE_NONE, &hip_send_r1,   
40000);
-
-    hip_register_handle_function(HIP_I2, HIP_STATE_UNASSOCIATED, 
&hip_check_i2,  20000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_UNASSOCIATED, 
&hip_handle_i2, 30000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_UNASSOCIATED, 
&hip_update_retransmissions, 30250);
-    hip_register_handle_function(HIP_I2, HIP_STATE_UNASSOCIATED, 
&hip_create_r2, 40000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_UNASSOCIATED, 
&hip_add_rvs_reg_from, 41000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_UNASSOCIATED, 
&hip_hmac2_and_sign, 42000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_UNASSOCIATED, 
&hip_add_rvs_relay_to, 43000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_UNASSOCIATED, &hip_send_r2, 
50000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_I1_SENT, &hip_check_i2,  
20000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_I1_SENT, &hip_handle_i2, 
30000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_I1_SENT, 
&hip_update_retransmissions, 30250);
-    hip_register_handle_function(HIP_I2, HIP_STATE_I1_SENT, &hip_create_r2, 
40000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_I1_SENT, 
&hip_add_rvs_reg_from, 41000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_I1_SENT, 
&hip_hmac2_and_sign, 42000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_I1_SENT, 
&hip_add_rvs_relay_to, 43000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_I1_SENT, &hip_send_r2, 
50000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_I2_SENT, &hip_check_i2,     
        20000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_I2_SENT, 
&hip_handle_i2_in_i2_sent, 21000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_I2_SENT, &hip_handle_i2,    
        30000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_I2_SENT, 
&hip_update_retransmissions, 30250);
-    hip_register_handle_function(HIP_I2, HIP_STATE_I2_SENT, &hip_create_r2, 
40000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_I2_SENT, 
&hip_add_rvs_reg_from, 41000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_I2_SENT, 
&hip_hmac2_and_sign, 42000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_I2_SENT, 
&hip_add_rvs_relay_to, 43000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_I2_SENT, &hip_send_r2, 
50000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_R2_SENT, &hip_check_i2,  
20000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_R2_SENT, &hip_handle_i2, 
30000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_R2_SENT, 
&hip_update_retransmissions, 30250);
-    hip_register_handle_function(HIP_I2, HIP_STATE_R2_SENT, &hip_create_r2, 
40000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_R2_SENT, 
&hip_add_rvs_reg_from, 41000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_R2_SENT, 
&hip_hmac2_and_sign, 42000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_R2_SENT, 
&hip_add_rvs_relay_to, 43000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_R2_SENT, &hip_send_r2, 
50000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_ESTABLISHED, &hip_check_i2, 
 20000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_ESTABLISHED, 
&hip_handle_i2, 30000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_ESTABLISHED, 
&hip_update_retransmissions, 30250);
-    hip_register_handle_function(HIP_I2, HIP_STATE_ESTABLISHED, 
&hip_create_r2, 40000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_ESTABLISHED, 
&hip_add_rvs_reg_from, 41000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_ESTABLISHED, 
&hip_hmac2_and_sign, 42000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_ESTABLISHED, 
&hip_add_rvs_relay_to, 43000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_ESTABLISHED, &hip_send_r2, 
50000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_CLOSING, &hip_check_i2,  
20000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_CLOSING, &hip_handle_i2, 
30000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_CLOSING, 
&hip_update_retransmissions, 30250);
-    hip_register_handle_function(HIP_I2, HIP_STATE_CLOSING, &hip_create_r2, 
40000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_CLOSING, 
&hip_add_rvs_reg_from, 41000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_CLOSING, 
&hip_hmac2_and_sign, 42000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_CLOSING, 
&hip_add_rvs_relay_to, 43000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_CLOSING, &hip_send_r2, 
50000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_CLOSED, &hip_check_i2,  
20000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_CLOSED, &hip_handle_i2, 
30000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_CLOSED, 
&hip_update_retransmissions, 30250);
-    hip_register_handle_function(HIP_I2, HIP_STATE_CLOSED, &hip_create_r2, 
40000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_CLOSED, 
&hip_add_rvs_reg_from, 41000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_CLOSED, 
&hip_hmac2_and_sign, 42000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_CLOSED, 
&hip_add_rvs_relay_to, 43000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_CLOSED, &hip_send_r2, 
50000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_NONE, &hip_check_i2,  
20000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_NONE, &hip_handle_i2, 
30000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_NONE, 
&hip_update_retransmissions, 30250);
-    hip_register_handle_function(HIP_I2, HIP_STATE_NONE, &hip_create_r2, 
40000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_NONE, 
&hip_add_rvs_reg_from, 41000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_NONE, &hip_hmac2_and_sign, 
42000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_NONE, 
&hip_add_rvs_relay_to, 43000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_NONE, &hip_send_r2, 50000);
-
-    hip_register_handle_function(HIP_R1, HIP_STATE_I1_SENT, &hip_check_r1,  
20000);
-    hip_register_handle_function(HIP_R1, HIP_STATE_I1_SENT, &hip_handle_r1, 
30000);
-    hip_register_handle_function(HIP_R1, HIP_STATE_I1_SENT, 
&hip_update_retransmissions, 30500);
-    hip_register_handle_function(HIP_R1, HIP_STATE_I1_SENT, 
&hip_build_esp_info, 31000);
-    hip_register_handle_function(HIP_R1, HIP_STATE_I1_SENT, 
&hip_build_solution, 32000);
-    hip_register_handle_function(HIP_R1, HIP_STATE_I1_SENT, 
&hip_handle_diffie_hellman, 33000);
-    hip_register_handle_function(HIP_R1, HIP_STATE_I1_SENT, 
&esp_prot_r1_handle_transforms, 34000);
-    hip_register_handle_function(HIP_R1, HIP_STATE_I1_SENT, &hip_create_i2, 
40000);
-    hip_register_handle_function(HIP_R1, HIP_STATE_I1_SENT, 
&hip_add_signed_echo_response, 41000);
-    hip_register_handle_function(HIP_R1, HIP_STATE_I1_SENT, 
&hip_mac_and_sign_handler, 42000);
-    hip_register_handle_function(HIP_R1, HIP_STATE_I1_SENT, 
&hip_add_unsigned_echo_response, 43000);
-    hip_register_handle_function(HIP_R1, HIP_STATE_I1_SENT, &hip_send_i2,   
50000);
-    hip_register_handle_function(HIP_R1, HIP_STATE_I2_SENT, &hip_check_r1,  
20000);
-    hip_register_handle_function(HIP_R1, HIP_STATE_I2_SENT, &hip_handle_r1, 
30000);
-    hip_register_handle_function(HIP_R1, HIP_STATE_I2_SENT, 
&hip_update_retransmissions, 30500);
-    hip_register_handle_function(HIP_R1, HIP_STATE_I2_SENT, 
&hip_build_esp_info, 31000);
-    hip_register_handle_function(HIP_R1, HIP_STATE_I2_SENT, 
&hip_build_solution, 32000);
-    hip_register_handle_function(HIP_R1, HIP_STATE_I2_SENT, 
&hip_handle_diffie_hellman, 33000);
-    hip_register_handle_function(HIP_R1, HIP_STATE_I2_SENT, 
&esp_prot_r1_handle_transforms, 34000);
-    hip_register_handle_function(HIP_R1, HIP_STATE_I2_SENT, &hip_create_i2, 
40000);
-    hip_register_handle_function(HIP_R1, HIP_STATE_I2_SENT, 
&hip_add_signed_echo_response, 41000);
-    hip_register_handle_function(HIP_R1, HIP_STATE_I2_SENT, 
&hip_mac_and_sign_handler, 42000);
-    hip_register_handle_function(HIP_R1, HIP_STATE_I2_SENT, 
&hip_add_unsigned_echo_response, 43000);
-    hip_register_handle_function(HIP_R1, HIP_STATE_I2_SENT, &hip_send_i2,   
50000);
-    hip_register_handle_function(HIP_R1, HIP_STATE_CLOSING, &hip_check_r1,  
20000);
-    hip_register_handle_function(HIP_R1, HIP_STATE_CLOSING, &hip_handle_r1, 
30000);
-    hip_register_handle_function(HIP_R1, HIP_STATE_CLOSING, 
&hip_update_retransmissions, 30500);
-    hip_register_handle_function(HIP_R1, HIP_STATE_CLOSING, 
&hip_build_esp_info, 31000);
-    hip_register_handle_function(HIP_R1, HIP_STATE_CLOSING, 
&hip_build_solution, 32000);
-    hip_register_handle_function(HIP_R1, HIP_STATE_CLOSING, 
&hip_handle_diffie_hellman, 33000);
-    hip_register_handle_function(HIP_R1, HIP_STATE_CLOSING, 
&esp_prot_r1_handle_transforms, 34000);
-    hip_register_handle_function(HIP_R1, HIP_STATE_CLOSING, &hip_create_i2, 
40000);
-    hip_register_handle_function(HIP_R1, HIP_STATE_CLOSING, 
&hip_add_signed_echo_response, 41000);
-    hip_register_handle_function(HIP_R1, HIP_STATE_CLOSING, 
&hip_mac_and_sign_handler, 42000);
-    hip_register_handle_function(HIP_R1, HIP_STATE_CLOSING, 
&hip_add_unsigned_echo_response, 43000);
-    hip_register_handle_function(HIP_R1, HIP_STATE_CLOSING, &hip_send_i2,   
50000);
-    hip_register_handle_function(HIP_R1, HIP_STATE_CLOSED, &hip_check_r1,  
20000);
-    hip_register_handle_function(HIP_R1, HIP_STATE_CLOSED, &hip_handle_r1, 
30000);
-    hip_register_handle_function(HIP_R1, HIP_STATE_CLOSED, 
&hip_update_retransmissions, 30500);
-    hip_register_handle_function(HIP_R1, HIP_STATE_CLOSED, 
&hip_build_esp_info, 31000);
-    hip_register_handle_function(HIP_R1, HIP_STATE_CLOSED, 
&hip_build_solution, 32000);
-    hip_register_handle_function(HIP_R1, HIP_STATE_CLOSED, 
&hip_handle_diffie_hellman, 33000);
-    hip_register_handle_function(HIP_R1, HIP_STATE_CLOSED, 
&esp_prot_r1_handle_transforms, 34000);
-    hip_register_handle_function(HIP_R1, HIP_STATE_CLOSED, &hip_create_i2, 
40000);
-    hip_register_handle_function(HIP_R1, HIP_STATE_CLOSED, 
&hip_add_signed_echo_response, 41000);
-    hip_register_handle_function(HIP_R1, HIP_STATE_CLOSED, 
&hip_mac_and_sign_handler, 42000);
-    hip_register_handle_function(HIP_R1, HIP_STATE_CLOSED, 
&hip_add_unsigned_echo_response, 43000);
-    hip_register_handle_function(HIP_R1, HIP_STATE_CLOSED, &hip_send_i2, 
50000);
-
-    hip_register_handle_function(HIP_R2, HIP_STATE_I2_SENT, &hip_check_r2,  
20000);
-    hip_register_handle_function(HIP_R2, HIP_STATE_I2_SENT, &hip_handle_r2, 
30000);
-    hip_register_handle_function(HIP_R2, HIP_STATE_I2_SENT, 
&hip_update_retransmissions, 30250);
-
-    hip_register_handle_function(HIP_NOTIFY, HIP_STATE_I1_SENT, 
&hip_check_notify,  20000);
-    hip_register_handle_function(HIP_NOTIFY, HIP_STATE_I1_SENT, 
&hip_handle_notify, 30000);
-    hip_register_handle_function(HIP_NOTIFY, HIP_STATE_I2_SENT, 
&hip_check_notify,  20000);
-    hip_register_handle_function(HIP_NOTIFY, HIP_STATE_I2_SENT, 
&hip_handle_notify, 30000);
-    hip_register_handle_function(HIP_NOTIFY, HIP_STATE_R2_SENT, 
&hip_check_notify,  20000);
-    hip_register_handle_function(HIP_NOTIFY, HIP_STATE_R2_SENT, 
&hip_handle_notify, 30000);
-    hip_register_handle_function(HIP_NOTIFY, HIP_STATE_ESTABLISHED, 
&hip_check_notify, 20000);
-    hip_register_handle_function(HIP_NOTIFY, HIP_STATE_ESTABLISHED, 
&hip_handle_notify, 30000);
-    hip_register_handle_function(HIP_NOTIFY, HIP_STATE_CLOSING, 
&hip_check_notify,  20000);
-    hip_register_handle_function(HIP_NOTIFY, HIP_STATE_CLOSING, 
&hip_handle_notify, 30000);
-    hip_register_handle_function(HIP_NOTIFY, HIP_STATE_CLOSED, 
&hip_check_notify,  20000);
-    hip_register_handle_function(HIP_NOTIFY, HIP_STATE_CLOSED, 
&hip_handle_notify, 30000);
-
-    hip_register_handle_function(HIP_CLOSE, HIP_STATE_ESTABLISHED,  
&hip_close_check_packet,     20000);
-    hip_register_handle_function(HIP_CLOSE, HIP_STATE_ESTABLISHED,  
&hip_update_retransmissions, 25000);
-    hip_register_handle_function(HIP_CLOSE, HIP_STATE_ESTABLISHED,  
&hip_close_create_response,  30000);
-    hip_register_handle_function(HIP_CLOSE, HIP_STATE_ESTABLISHED,  
&hip_close_send_response,    40000);
-
-    hip_register_handle_function(HIP_CLOSE, HIP_STATE_CLOSING,  
&hip_close_check_packet,     20000);
-    hip_register_handle_function(HIP_CLOSE, HIP_STATE_CLOSING,  
&hip_update_retransmissions, 25000);
-    hip_register_handle_function(HIP_CLOSE, HIP_STATE_CLOSING,  
&hip_close_create_response,  30000);
-    hip_register_handle_function(HIP_CLOSE, HIP_STATE_CLOSING,  
&hip_close_send_response,    40000);
-
-    hip_register_handle_function(HIP_CLOSE_ACK, HIP_STATE_CLOSING, 
&hip_close_ack_check_packet,  20000);
-    hip_register_handle_function(HIP_CLOSE_ACK, HIP_STATE_CLOSING, 
&hip_update_retransmissions,  25000);
-    hip_register_handle_function(HIP_CLOSE_ACK, HIP_STATE_CLOSING, 
&hip_close_ack_handle_packet, 30000);
-
-    hip_register_handle_function(HIP_CLOSE_ACK, HIP_STATE_CLOSED,  
&hip_close_ack_check_packet,  20000);
-    hip_register_handle_function(HIP_CLOSE_ACK, HIP_STATE_CLOSED,  
&hip_update_retransmissions,  25000);
-    hip_register_handle_function(HIP_CLOSE_ACK, HIP_STATE_CLOSED,  
&hip_close_ack_handle_packet, 30000);
-
-    hip_register_handle_function(HIP_LUPDATE, HIP_STATE_ESTABLISHED, 
&esp_prot_handle_light_update, 20000);
-    hip_register_handle_function(HIP_LUPDATE, HIP_STATE_R2_SENT,     
&esp_prot_handle_light_update, 20000);
+    hip_register_handle_function(HIP_V1, HIP_I1, HIP_STATE_UNASSOCIATED, 
&hip_check_i1,  20000);
+    hip_register_handle_function(HIP_V1, HIP_I1, HIP_STATE_UNASSOCIATED, 
&hip_handle_i1, 30000);
+    hip_register_handle_function(HIP_V1, HIP_I1, HIP_STATE_UNASSOCIATED, 
&hip_update_retransmissions, 35000);
+    hip_register_handle_function(HIP_V1, HIP_I1, HIP_STATE_UNASSOCIATED, 
&hip_send_r1,   40000);
+    hip_register_handle_function(HIP_V1, HIP_I1, HIP_STATE_I1_SENT, 
&hip_check_i1,  20000);
+    hip_register_handle_function(HIP_V1, HIP_I1, HIP_STATE_I1_SENT, 
&hip_handle_i1, 30000);
+    hip_register_handle_function(HIP_V1, HIP_I1, HIP_STATE_I1_SENT, 
&hip_update_retransmissions, 35000);
+    hip_register_handle_function(HIP_V1, HIP_I1, HIP_STATE_I1_SENT, 
&hip_send_r1,   40000);
+    hip_register_handle_function(HIP_V1, HIP_I1, HIP_STATE_I2_SENT, 
&hip_check_i1,  20000);
+    hip_register_handle_function(HIP_V1, HIP_I1, HIP_STATE_I2_SENT, 
&hip_handle_i1, 30000);
+    hip_register_handle_function(HIP_V1, HIP_I1, HIP_STATE_I2_SENT, 
&hip_update_retransmissions, 35000);
+    hip_register_handle_function(HIP_V1, HIP_I1, HIP_STATE_I2_SENT, 
&hip_send_r1,   40000);
+    hip_register_handle_function(HIP_V1, HIP_I1, HIP_STATE_R2_SENT, 
&hip_check_i1,  20000);
+    hip_register_handle_function(HIP_V1, HIP_I1, HIP_STATE_R2_SENT, 
&hip_handle_i1, 30000);
+    hip_register_handle_function(HIP_V1, HIP_I1, HIP_STATE_R2_SENT, 
&hip_update_retransmissions, 35000);
+    hip_register_handle_function(HIP_V1, HIP_I1, HIP_STATE_R2_SENT, 
&hip_send_r1,   40000);
+    hip_register_handle_function(HIP_V1, HIP_I1, HIP_STATE_ESTABLISHED, 
&hip_check_i1,  20000);
+    hip_register_handle_function(HIP_V1, HIP_I1, HIP_STATE_ESTABLISHED, 
&hip_handle_i1, 30000);
+    hip_register_handle_function(HIP_V1, HIP_I1, HIP_STATE_ESTABLISHED, 
&hip_update_retransmissions, 35000);
+    hip_register_handle_function(HIP_V1, HIP_I1, HIP_STATE_ESTABLISHED, 
&hip_send_r1,   40000);
+    hip_register_handle_function(HIP_V1, HIP_I1, HIP_STATE_CLOSING, 
&hip_check_i1,  20000);
+    hip_register_handle_function(HIP_V1, HIP_I1, HIP_STATE_CLOSING, 
&hip_handle_i1, 30000);
+    hip_register_handle_function(HIP_V1, HIP_I1, HIP_STATE_CLOSING, 
&hip_update_retransmissions, 35000);
+    hip_register_handle_function(HIP_V1, HIP_I1, HIP_STATE_CLOSING, 
&hip_send_r1,   40000);
+    hip_register_handle_function(HIP_V1, HIP_I1, HIP_STATE_CLOSED, 
&hip_check_i1,  20000);
+    hip_register_handle_function(HIP_V1, HIP_I1, HIP_STATE_CLOSED, 
&hip_handle_i1, 30000);
+    hip_register_handle_function(HIP_V1, HIP_I1, HIP_STATE_CLOSED, 
&hip_update_retransmissions, 35000);
+    hip_register_handle_function(HIP_V1, HIP_I1, HIP_STATE_CLOSED, 
&hip_send_r1,   40000);
+    hip_register_handle_function(HIP_V1, HIP_I1, HIP_STATE_NONE, 
&hip_check_i1,  20000);
+    hip_register_handle_function(HIP_V1, HIP_I1, HIP_STATE_NONE, 
&hip_handle_i1, 30000);
+    hip_register_handle_function(HIP_V1, HIP_I1, HIP_STATE_NONE, 
&hip_update_retransmissions, 35000);
+    hip_register_handle_function(HIP_V1, HIP_I1, HIP_STATE_NONE, &hip_send_r1, 
  40000);
+
+    hip_register_handle_function(HIP_V1, HIP_I2, HIP_STATE_UNASSOCIATED, 
&hip_check_i2,  20000);
+    hip_register_handle_function(HIP_V1, HIP_I2, HIP_STATE_UNASSOCIATED, 
&hip_handle_i2, 30000);
+    hip_register_handle_function(HIP_V1, HIP_I2, HIP_STATE_UNASSOCIATED, 
&hip_update_retransmissions, 30250);
+    hip_register_handle_function(HIP_V1, HIP_I2, HIP_STATE_UNASSOCIATED, 
&hip_create_r2, 40000);
+    hip_register_handle_function(HIP_V1, HIP_I2, HIP_STATE_UNASSOCIATED, 
&hip_add_rvs_reg_from, 41000);
+    hip_register_handle_function(HIP_V1, HIP_I2, HIP_STATE_UNASSOCIATED, 
&hip_hmac2_and_sign, 42000);
+    hip_register_handle_function(HIP_V1, HIP_I2, HIP_STATE_UNASSOCIATED, 
&hip_add_rvs_relay_to, 43000);
+    hip_register_handle_function(HIP_V1, HIP_I2, HIP_STATE_UNASSOCIATED, 
&hip_send_r2, 50000);
+    hip_register_handle_function(HIP_V1, HIP_I2, HIP_STATE_I1_SENT, 
&hip_check_i2,  20000);
+    hip_register_handle_function(HIP_V1, HIP_I2, HIP_STATE_I1_SENT, 
&hip_handle_i2, 30000);
+    hip_register_handle_function(HIP_V1, HIP_I2, HIP_STATE_I1_SENT, 
&hip_update_retransmissions, 30250);
+    hip_register_handle_function(HIP_V1, HIP_I2, HIP_STATE_I1_SENT, 
&hip_create_r2, 40000);
+    hip_register_handle_function(HIP_V1, HIP_I2, HIP_STATE_I1_SENT, 
&hip_add_rvs_reg_from, 41000);
+    hip_register_handle_function(HIP_V1, HIP_I2, HIP_STATE_I1_SENT, 
&hip_hmac2_and_sign, 42000);
+    hip_register_handle_function(HIP_V1, HIP_I2, HIP_STATE_I1_SENT, 
&hip_add_rvs_relay_to, 43000);
+    hip_register_handle_function(HIP_V1, HIP_I2, HIP_STATE_I1_SENT, 
&hip_send_r2, 50000);
+    hip_register_handle_function(HIP_V1, HIP_I2, HIP_STATE_I2_SENT, 
&hip_check_i2,             20000);
+    hip_register_handle_function(HIP_V1, HIP_I2, HIP_STATE_I2_SENT, 
&hip_handle_i2_in_i2_sent, 21000);
+    hip_register_handle_function(HIP_V1, HIP_I2, HIP_STATE_I2_SENT, 
&hip_handle_i2,            30000);
+    hip_register_handle_function(HIP_V1, HIP_I2, HIP_STATE_I2_SENT, 
&hip_update_retransmissions, 30250);
+    hip_register_handle_function(HIP_V1, HIP_I2, HIP_STATE_I2_SENT, 
&hip_create_r2, 40000);
+    hip_register_handle_function(HIP_V1, HIP_I2, HIP_STATE_I2_SENT, 
&hip_add_rvs_reg_from, 41000);
+    hip_register_handle_function(HIP_V1, HIP_I2, HIP_STATE_I2_SENT, 
&hip_hmac2_and_sign, 42000);
+    hip_register_handle_function(HIP_V1, HIP_I2, HIP_STATE_I2_SENT, 
&hip_add_rvs_relay_to, 43000);
+    hip_register_handle_function(HIP_V1, HIP_I2, HIP_STATE_I2_SENT, 
&hip_send_r2, 50000);
+    hip_register_handle_function(HIP_V1, HIP_I2, HIP_STATE_R2_SENT, 
&hip_check_i2,  20000);
+    hip_register_handle_function(HIP_V1, HIP_I2, HIP_STATE_R2_SENT, 
&hip_handle_i2, 30000);
+    hip_register_handle_function(HIP_V1, HIP_I2, HIP_STATE_R2_SENT, 
&hip_update_retransmissions, 30250);
+    hip_register_handle_function(HIP_V1, HIP_I2, HIP_STATE_R2_SENT, 
&hip_create_r2, 40000);
+    hip_register_handle_function(HIP_V1, HIP_I2, HIP_STATE_R2_SENT, 
&hip_add_rvs_reg_from, 41000);
+    hip_register_handle_function(HIP_V1, HIP_I2, HIP_STATE_R2_SENT, 
&hip_hmac2_and_sign, 42000);
+    hip_register_handle_function(HIP_V1, HIP_I2, HIP_STATE_R2_SENT, 
&hip_add_rvs_relay_to, 43000);
+    hip_register_handle_function(HIP_V1, HIP_I2, HIP_STATE_R2_SENT, 
&hip_send_r2, 50000);
+    hip_register_handle_function(HIP_V1, HIP_I2, HIP_STATE_ESTABLISHED, 
&hip_check_i2,  20000);
+    hip_register_handle_function(HIP_V1, HIP_I2, HIP_STATE_ESTABLISHED, 
&hip_handle_i2, 30000);
+    hip_register_handle_function(HIP_V1, HIP_I2, HIP_STATE_ESTABLISHED, 
&hip_update_retransmissions, 30250);
+    hip_register_handle_function(HIP_V1, HIP_I2, HIP_STATE_ESTABLISHED, 
&hip_create_r2, 40000);
+    hip_register_handle_function(HIP_V1, HIP_I2, HIP_STATE_ESTABLISHED, 
&hip_add_rvs_reg_from, 41000);
+    hip_register_handle_function(HIP_V1, HIP_I2, HIP_STATE_ESTABLISHED, 
&hip_hmac2_and_sign, 42000);
+    hip_register_handle_function(HIP_V1, HIP_I2, HIP_STATE_ESTABLISHED, 
&hip_add_rvs_relay_to, 43000);
+    hip_register_handle_function(HIP_V1, HIP_I2, HIP_STATE_ESTABLISHED, 
&hip_send_r2, 50000);
+    hip_register_handle_function(HIP_V1, HIP_I2, HIP_STATE_CLOSING, 
&hip_check_i2,  20000);
+    hip_register_handle_function(HIP_V1, HIP_I2, HIP_STATE_CLOSING, 
&hip_handle_i2, 30000);
+    hip_register_handle_function(HIP_V1, HIP_I2, HIP_STATE_CLOSING, 
&hip_update_retransmissions, 30250);
+    hip_register_handle_function(HIP_V1, HIP_I2, HIP_STATE_CLOSING, 
&hip_create_r2, 40000);
+    hip_register_handle_function(HIP_V1, HIP_I2, HIP_STATE_CLOSING, 
&hip_add_rvs_reg_from, 41000);
+    hip_register_handle_function(HIP_V1, HIP_I2, HIP_STATE_CLOSING, 
&hip_hmac2_and_sign, 42000);
+    hip_register_handle_function(HIP_V1, HIP_I2, HIP_STATE_CLOSING, 
&hip_add_rvs_relay_to, 43000);
+    hip_register_handle_function(HIP_V1, HIP_I2, HIP_STATE_CLOSING, 
&hip_send_r2, 50000);
+    hip_register_handle_function(HIP_V1, HIP_I2, HIP_STATE_CLOSED, 
&hip_check_i2,  20000);
+    hip_register_handle_function(HIP_V1, HIP_I2, HIP_STATE_CLOSED, 
&hip_handle_i2, 30000);
+    hip_register_handle_function(HIP_V1, HIP_I2, HIP_STATE_CLOSED, 
&hip_update_retransmissions, 30250);
+    hip_register_handle_function(HIP_V1, HIP_I2, HIP_STATE_CLOSED, 
&hip_create_r2, 40000);
+    hip_register_handle_function(HIP_V1, HIP_I2, HIP_STATE_CLOSED, 
&hip_add_rvs_reg_from, 41000);
+    hip_register_handle_function(HIP_V1, HIP_I2, HIP_STATE_CLOSED, 
&hip_hmac2_and_sign, 42000);
+    hip_register_handle_function(HIP_V1, HIP_I2, HIP_STATE_CLOSED, 
&hip_add_rvs_relay_to, 43000);
+    hip_register_handle_function(HIP_V1, HIP_I2, HIP_STATE_CLOSED, 
&hip_send_r2, 50000);
+    hip_register_handle_function(HIP_V1, HIP_I2, HIP_STATE_NONE, 
&hip_check_i2,  20000);
+    hip_register_handle_function(HIP_V1, HIP_I2, HIP_STATE_NONE, 
&hip_handle_i2, 30000);
+    hip_register_handle_function(HIP_V1, HIP_I2, HIP_STATE_NONE, 
&hip_update_retransmissions, 30250);
+    hip_register_handle_function(HIP_V1, HIP_I2, HIP_STATE_NONE, 
&hip_create_r2, 40000);
+    hip_register_handle_function(HIP_V1, HIP_I2, HIP_STATE_NONE, 
&hip_add_rvs_reg_from, 41000);
+    hip_register_handle_function(HIP_V1, HIP_I2, HIP_STATE_NONE, 
&hip_hmac2_and_sign, 42000);
+    hip_register_handle_function(HIP_V1, HIP_I2, HIP_STATE_NONE, 
&hip_add_rvs_relay_to, 43000);
+    hip_register_handle_function(HIP_V1, HIP_I2, HIP_STATE_NONE, &hip_send_r2, 
50000);
+
+    hip_register_handle_function(HIP_V1, HIP_R1, HIP_STATE_I1_SENT, 
&hip_check_r1,  20000);
+    hip_register_handle_function(HIP_V1, HIP_R1, HIP_STATE_I1_SENT, 
&hip_handle_r1, 30000);
+    hip_register_handle_function(HIP_V1, HIP_R1, HIP_STATE_I1_SENT, 
&hip_update_retransmissions, 30500);
+    hip_register_handle_function(HIP_V1, HIP_R1, HIP_STATE_I1_SENT, 
&hip_build_esp_info, 31000);
+    hip_register_handle_function(HIP_V1, HIP_R1, HIP_STATE_I1_SENT, 
&hip_build_solution, 32000);
+    hip_register_handle_function(HIP_V1, HIP_R1, HIP_STATE_I1_SENT, 
&hip_handle_diffie_hellman, 33000);
+    hip_register_handle_function(HIP_V1, HIP_R1, HIP_STATE_I1_SENT, 
&esp_prot_r1_handle_transforms, 34000);
+    hip_register_handle_function(HIP_V1, HIP_R1, HIP_STATE_I1_SENT, 
&hip_create_i2, 40000);
+    hip_register_handle_function(HIP_V1, HIP_R1, HIP_STATE_I1_SENT, 
&hip_add_signed_echo_response, 41000);
+    hip_register_handle_function(HIP_V1, HIP_R1, HIP_STATE_I1_SENT, 
&hip_mac_and_sign_handler, 42000);
+    hip_register_handle_function(HIP_V1, HIP_R1, HIP_STATE_I1_SENT, 
&hip_add_unsigned_echo_response, 43000);
+    hip_register_handle_function(HIP_V1, HIP_R1, HIP_STATE_I1_SENT, 
&hip_send_i2,   50000);
+    hip_register_handle_function(HIP_V1, HIP_R1, HIP_STATE_I2_SENT, 
&hip_check_r1,  20000);
+    hip_register_handle_function(HIP_V1, HIP_R1, HIP_STATE_I2_SENT, 
&hip_handle_r1, 30000);
+    hip_register_handle_function(HIP_V1, HIP_R1, HIP_STATE_I2_SENT, 
&hip_update_retransmissions, 30500);
+    hip_register_handle_function(HIP_V1, HIP_R1, HIP_STATE_I2_SENT, 
&hip_build_esp_info, 31000);
+    hip_register_handle_function(HIP_V1, HIP_R1, HIP_STATE_I2_SENT, 
&hip_build_solution, 32000);
+    hip_register_handle_function(HIP_V1, HIP_R1, HIP_STATE_I2_SENT, 
&hip_handle_diffie_hellman, 33000);
+    hip_register_handle_function(HIP_V1, HIP_R1, HIP_STATE_I2_SENT, 
&esp_prot_r1_handle_transforms, 34000);
+    hip_register_handle_function(HIP_V1, HIP_R1, HIP_STATE_I2_SENT, 
&hip_create_i2, 40000);
+    hip_register_handle_function(HIP_V1, HIP_R1, HIP_STATE_I2_SENT, 
&hip_add_signed_echo_response, 41000);
+    hip_register_handle_function(HIP_V1, HIP_R1, HIP_STATE_I2_SENT, 
&hip_mac_and_sign_handler, 42000);
+    hip_register_handle_function(HIP_V1, HIP_R1, HIP_STATE_I2_SENT, 
&hip_add_unsigned_echo_response, 43000);
+    hip_register_handle_function(HIP_V1, HIP_R1, HIP_STATE_I2_SENT, 
&hip_send_i2,   50000);
+    hip_register_handle_function(HIP_V1, HIP_R1, HIP_STATE_CLOSING, 
&hip_check_r1,  20000);
+    hip_register_handle_function(HIP_V1, HIP_R1, HIP_STATE_CLOSING, 
&hip_handle_r1, 30000);
+    hip_register_handle_function(HIP_V1, HIP_R1, HIP_STATE_CLOSING, 
&hip_update_retransmissions, 30500);
+    hip_register_handle_function(HIP_V1, HIP_R1, HIP_STATE_CLOSING, 
&hip_build_esp_info, 31000);
+    hip_register_handle_function(HIP_V1, HIP_R1, HIP_STATE_CLOSING, 
&hip_build_solution, 32000);
+    hip_register_handle_function(HIP_V1, HIP_R1, HIP_STATE_CLOSING, 
&hip_handle_diffie_hellman, 33000);
+    hip_register_handle_function(HIP_V1, HIP_R1, HIP_STATE_CLOSING, 
&esp_prot_r1_handle_transforms, 34000);
+    hip_register_handle_function(HIP_V1, HIP_R1, HIP_STATE_CLOSING, 
&hip_create_i2, 40000);
+    hip_register_handle_function(HIP_V1, HIP_R1, HIP_STATE_CLOSING, 
&hip_add_signed_echo_response, 41000);
+    hip_register_handle_function(HIP_V1, HIP_R1, HIP_STATE_CLOSING, 
&hip_mac_and_sign_handler, 42000);
+    hip_register_handle_function(HIP_V1, HIP_R1, HIP_STATE_CLOSING, 
&hip_add_unsigned_echo_response, 43000);
+    hip_register_handle_function(HIP_V1, HIP_R1, HIP_STATE_CLOSING, 
&hip_send_i2,   50000);
+    hip_register_handle_function(HIP_V1, HIP_R1, HIP_STATE_CLOSED, 
&hip_check_r1,  20000);
+    hip_register_handle_function(HIP_V1, HIP_R1, HIP_STATE_CLOSED, 
&hip_handle_r1, 30000);
+    hip_register_handle_function(HIP_V1, HIP_R1, HIP_STATE_CLOSED, 
&hip_update_retransmissions, 30500);
+    hip_register_handle_function(HIP_V1, HIP_R1, HIP_STATE_CLOSED, 
&hip_build_esp_info, 31000);
+    hip_register_handle_function(HIP_V1, HIP_R1, HIP_STATE_CLOSED, 
&hip_build_solution, 32000);
+    hip_register_handle_function(HIP_V1, HIP_R1, HIP_STATE_CLOSED, 
&hip_handle_diffie_hellman, 33000);
+    hip_register_handle_function(HIP_V1, HIP_R1, HIP_STATE_CLOSED, 
&esp_prot_r1_handle_transforms, 34000);
+    hip_register_handle_function(HIP_V1, HIP_R1, HIP_STATE_CLOSED, 
&hip_create_i2, 40000);
+    hip_register_handle_function(HIP_V1, HIP_R1, HIP_STATE_CLOSED, 
&hip_add_signed_echo_response, 41000);
+    hip_register_handle_function(HIP_V1, HIP_R1, HIP_STATE_CLOSED, 
&hip_mac_and_sign_handler, 42000);
+    hip_register_handle_function(HIP_V1, HIP_R1, HIP_STATE_CLOSED, 
&hip_add_unsigned_echo_response, 43000);
+    hip_register_handle_function(HIP_V1, HIP_R1, HIP_STATE_CLOSED, 
&hip_send_i2, 50000);
+
+    hip_register_handle_function(HIP_V1, HIP_R2, HIP_STATE_I2_SENT, 
&hip_check_r2,  20000);
+    hip_register_handle_function(HIP_V1, HIP_R2, HIP_STATE_I2_SENT, 
&hip_handle_r2, 30000);
+    hip_register_handle_function(HIP_V1, HIP_R2, HIP_STATE_I2_SENT, 
&hip_update_retransmissions, 30250);
+
+    hip_register_handle_function(HIP_V1, HIP_NOTIFY, HIP_STATE_I1_SENT, 
&hip_check_notify,  20000);
+    hip_register_handle_function(HIP_V1, HIP_NOTIFY, HIP_STATE_I1_SENT, 
&hip_handle_notify, 30000);
+    hip_register_handle_function(HIP_V1, HIP_NOTIFY, HIP_STATE_I2_SENT, 
&hip_check_notify,  20000);
+    hip_register_handle_function(HIP_V1, HIP_NOTIFY, HIP_STATE_I2_SENT, 
&hip_handle_notify, 30000);
+    hip_register_handle_function(HIP_V1, HIP_NOTIFY, HIP_STATE_R2_SENT, 
&hip_check_notify,  20000);
+    hip_register_handle_function(HIP_V1, HIP_NOTIFY, HIP_STATE_R2_SENT, 
&hip_handle_notify, 30000);
+    hip_register_handle_function(HIP_V1, HIP_NOTIFY, HIP_STATE_ESTABLISHED, 
&hip_check_notify, 20000);
+    hip_register_handle_function(HIP_V1, HIP_NOTIFY, HIP_STATE_ESTABLISHED, 
&hip_handle_notify, 30000);
+    hip_register_handle_function(HIP_V1, HIP_NOTIFY, HIP_STATE_CLOSING, 
&hip_check_notify,  20000);
+    hip_register_handle_function(HIP_V1, HIP_NOTIFY, HIP_STATE_CLOSING, 
&hip_handle_notify, 30000);
+    hip_register_handle_function(HIP_V1, HIP_NOTIFY, HIP_STATE_CLOSED, 
&hip_check_notify,  20000);
+    hip_register_handle_function(HIP_V1, HIP_NOTIFY, HIP_STATE_CLOSED, 
&hip_handle_notify, 30000);
+
+    hip_register_handle_function(HIP_V1, HIP_CLOSE, HIP_STATE_ESTABLISHED,  
&hip_close_check_packet,     20000);
+    hip_register_handle_function(HIP_V1, HIP_CLOSE, HIP_STATE_ESTABLISHED,  
&hip_update_retransmissions, 25000);
+    hip_register_handle_function(HIP_V1, HIP_CLOSE, HIP_STATE_ESTABLISHED,  
&hip_close_create_response,  30000);
+    hip_register_handle_function(HIP_V1, HIP_CLOSE, HIP_STATE_ESTABLISHED,  
&hip_close_send_response,    40000);
+
+    hip_register_handle_function(HIP_V1, HIP_CLOSE, HIP_STATE_CLOSING,  
&hip_close_check_packet,     20000);
+    hip_register_handle_function(HIP_V1, HIP_CLOSE, HIP_STATE_CLOSING,  
&hip_update_retransmissions, 25000);
+    hip_register_handle_function(HIP_V1, HIP_CLOSE, HIP_STATE_CLOSING,  
&hip_close_create_response,  30000);
+    hip_register_handle_function(HIP_V1, HIP_CLOSE, HIP_STATE_CLOSING,  
&hip_close_send_response,    40000);
+
+    hip_register_handle_function(HIP_V1, HIP_CLOSE_ACK, HIP_STATE_CLOSING, 
&hip_close_ack_check_packet,  20000);
+    hip_register_handle_function(HIP_V1, HIP_CLOSE_ACK, HIP_STATE_CLOSING, 
&hip_update_retransmissions,  25000);
+    hip_register_handle_function(HIP_V1, HIP_CLOSE_ACK, HIP_STATE_CLOSING, 
&hip_close_ack_handle_packet, 30000);
+
+    hip_register_handle_function(HIP_V1, HIP_CLOSE_ACK, HIP_STATE_CLOSED,  
&hip_close_ack_check_packet,  20000);
+    hip_register_handle_function(HIP_V1, HIP_CLOSE_ACK, HIP_STATE_CLOSED,  
&hip_update_retransmissions,  25000);
+    hip_register_handle_function(HIP_V1, HIP_CLOSE_ACK, HIP_STATE_CLOSED,  
&hip_close_ack_handle_packet, 30000);
+
+    hip_register_handle_function(HIP_V1, HIP_LUPDATE, HIP_STATE_ESTABLISHED, 
&esp_prot_handle_light_update, 20000);
+    hip_register_handle_function(HIP_V1, HIP_LUPDATE, HIP_STATE_R2_SENT,     
&esp_prot_handle_light_update, 20000);
 
     return 0;
 }
 
-static int init_handle_functions(void)
-{
-    int err = 0;
-
-    HIP_DEBUG("Initialize handle functions.\n");
-
-    hip_register_handle_function(HIP_I1, HIP_STATE_UNASSOCIATED, 
&hip_check_i1,  20000);
-    hip_register_handle_function(HIP_I1, HIP_STATE_UNASSOCIATED, 
&hip_handle_i1, 30000);
-    hip_register_handle_function(HIP_I1, HIP_STATE_UNASSOCIATED, 
&hip_update_retransmissions, 35000);
-    hip_register_handle_function(HIP_I1, HIP_STATE_UNASSOCIATED, &hip_send_r1, 
  40000);
-    hip_register_handle_function(HIP_I1, HIP_STATE_I1_SENT, &hip_check_i1,  
20000);
-    hip_register_handle_function(HIP_I1, HIP_STATE_I1_SENT, &hip_handle_i1, 
30000);
-    hip_register_handle_function(HIP_I1, HIP_STATE_I1_SENT, 
&hip_update_retransmissions, 35000);
-    hip_register_handle_function(HIP_I1, HIP_STATE_I1_SENT, &hip_send_r1,   
40000);
-    hip_register_handle_function(HIP_I1, HIP_STATE_I2_SENT, &hip_check_i1,  
20000);
-    hip_register_handle_function(HIP_I1, HIP_STATE_I2_SENT, &hip_handle_i1, 
30000);
-    hip_register_handle_function(HIP_I1, HIP_STATE_I2_SENT, 
&hip_update_retransmissions, 35000);
-    hip_register_handle_function(HIP_I1, HIP_STATE_I2_SENT, &hip_send_r1,   
40000);
-    hip_register_handle_function(HIP_I1, HIP_STATE_R2_SENT, &hip_check_i1,  
20000);
-    hip_register_handle_function(HIP_I1, HIP_STATE_R2_SENT, &hip_handle_i1, 
30000);
-    hip_register_handle_function(HIP_I1, HIP_STATE_R2_SENT, 
&hip_update_retransmissions, 35000);
-    hip_register_handle_function(HIP_I1, HIP_STATE_R2_SENT, &hip_send_r1,   
40000);
-    hip_register_handle_function(HIP_I1, HIP_STATE_ESTABLISHED, &hip_check_i1, 
 20000);
-    hip_register_handle_function(HIP_I1, HIP_STATE_ESTABLISHED, 
&hip_handle_i1, 30000);
-    hip_register_handle_function(HIP_I1, HIP_STATE_ESTABLISHED, 
&hip_update_retransmissions, 35000);
-    hip_register_handle_function(HIP_I1, HIP_STATE_ESTABLISHED, &hip_send_r1,  
 40000);
-    hip_register_handle_function(HIP_I1, HIP_STATE_CLOSING, &hip_check_i1,  
20000);
-    hip_register_handle_function(HIP_I1, HIP_STATE_CLOSING, &hip_handle_i1, 
30000);
-    hip_register_handle_function(HIP_I1, HIP_STATE_CLOSING, 
&hip_update_retransmissions, 35000);
-    hip_register_handle_function(HIP_I1, HIP_STATE_CLOSING, &hip_send_r1,   
40000);
-    hip_register_handle_function(HIP_I1, HIP_STATE_CLOSED, &hip_check_i1,  
20000);
-    hip_register_handle_function(HIP_I1, HIP_STATE_CLOSED, &hip_handle_i1, 
30000);
-    hip_register_handle_function(HIP_I1, HIP_STATE_CLOSED, 
&hip_update_retransmissions, 35000);
-    hip_register_handle_function(HIP_I1, HIP_STATE_CLOSED, &hip_send_r1,   
40000);
-    hip_register_handle_function(HIP_I1, HIP_STATE_NONE, &hip_check_i1,  
20000);
-    hip_register_handle_function(HIP_I1, HIP_STATE_NONE, &hip_handle_i1, 
30000);
-    hip_register_handle_function(HIP_I1, HIP_STATE_NONE, 
&hip_update_retransmissions, 35000);
-    hip_register_handle_function(HIP_I1, HIP_STATE_NONE, &hip_send_r1,   
40000);
-
-    hip_register_handle_function(HIP_I2, HIP_STATE_UNASSOCIATED, 
&hip_check_i2,  20000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_UNASSOCIATED, 
&hip_handle_i2, 30000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_UNASSOCIATED, 
&hip_update_retransmissions, 30250);
-    hip_register_handle_function(HIP_I2, HIP_STATE_UNASSOCIATED, 
&hip_setup_ipsec_sa, 30500);
-    hip_register_handle_function(HIP_I2, HIP_STATE_UNASSOCIATED, 
&hip_create_r2, 40000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_UNASSOCIATED, 
&hip_add_rvs_reg_from, 41000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_UNASSOCIATED, 
&hip_hmac2_and_sign, 42000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_UNASSOCIATED, 
&hip_add_rvs_relay_to, 43000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_UNASSOCIATED, &hip_send_r2, 
50000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_I1_SENT, &hip_check_i2,  
20000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_I1_SENT, &hip_handle_i2, 
30000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_I1_SENT, 
&hip_update_retransmissions, 30250);
-    hip_register_handle_function(HIP_I2, HIP_STATE_I1_SENT, 
&hip_setup_ipsec_sa, 30500);
-    hip_register_handle_function(HIP_I2, HIP_STATE_I1_SENT, &hip_create_r2, 
40000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_I1_SENT, 
&hip_add_rvs_reg_from, 41000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_I1_SENT, 
&hip_hmac2_and_sign, 42000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_I1_SENT, 
&hip_add_rvs_relay_to, 43000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_I1_SENT, &hip_send_r2, 
50000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_I2_SENT, &hip_check_i2,     
        20000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_I2_SENT, 
&hip_handle_i2_in_i2_sent, 21000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_I2_SENT, &hip_handle_i2,    
        30000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_I2_SENT, 
&hip_update_retransmissions, 30250);
-    hip_register_handle_function(HIP_I2, HIP_STATE_I2_SENT, 
&hip_setup_ipsec_sa, 30500);
-    hip_register_handle_function(HIP_I2, HIP_STATE_I2_SENT, &hip_create_r2, 
40000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_I2_SENT, 
&hip_add_rvs_reg_from, 41000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_I2_SENT, 
&hip_hmac2_and_sign, 42000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_I2_SENT, 
&hip_add_rvs_relay_to, 43000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_I2_SENT, &hip_send_r2, 
50000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_R2_SENT, &hip_check_i2,  
20000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_R2_SENT, &hip_handle_i2, 
30000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_R2_SENT, 
&hip_update_retransmissions, 30250);
-    hip_register_handle_function(HIP_I2, HIP_STATE_R2_SENT, 
&hip_setup_ipsec_sa, 30500);
-    hip_register_handle_function(HIP_I2, HIP_STATE_R2_SENT, &hip_create_r2, 
40000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_R2_SENT, 
&hip_add_rvs_reg_from, 41000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_R2_SENT, 
&hip_hmac2_and_sign, 42000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_R2_SENT, 
&hip_add_rvs_relay_to, 43000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_R2_SENT, &hip_send_r2, 
50000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_ESTABLISHED, &hip_check_i2, 
 20000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_ESTABLISHED, 
&hip_handle_i2, 30000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_ESTABLISHED, 
&hip_update_retransmissions, 30250);
-    hip_register_handle_function(HIP_I2, HIP_STATE_ESTABLISHED, 
&hip_setup_ipsec_sa, 30500);
-    hip_register_handle_function(HIP_I2, HIP_STATE_ESTABLISHED, 
&hip_create_r2, 40000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_ESTABLISHED, 
&hip_add_rvs_reg_from, 41000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_ESTABLISHED, 
&hip_hmac2_and_sign, 42000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_ESTABLISHED, 
&hip_add_rvs_relay_to, 43000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_ESTABLISHED, &hip_send_r2, 
50000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_CLOSING, &hip_check_i2,  
20000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_CLOSING, &hip_handle_i2, 
30000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_CLOSING, 
&hip_update_retransmissions, 30250);
-    hip_register_handle_function(HIP_I2, HIP_STATE_CLOSING, 
&hip_setup_ipsec_sa, 30500);
-    hip_register_handle_function(HIP_I2, HIP_STATE_CLOSING, &hip_create_r2, 
40000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_CLOSING, 
&hip_add_rvs_reg_from, 41000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_CLOSING, 
&hip_hmac2_and_sign, 42000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_CLOSING, 
&hip_add_rvs_relay_to, 43000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_CLOSING, &hip_send_r2, 
50000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_CLOSED, &hip_check_i2,  
20000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_CLOSED, &hip_handle_i2, 
30000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_CLOSED, 
&hip_update_retransmissions, 30250);
-    hip_register_handle_function(HIP_I2, HIP_STATE_CLOSED, 
&hip_setup_ipsec_sa, 30500);
-    hip_register_handle_function(HIP_I2, HIP_STATE_CLOSED, &hip_create_r2, 
40000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_CLOSED, 
&hip_add_rvs_reg_from, 41000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_CLOSED, 
&hip_hmac2_and_sign, 42000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_CLOSED, 
&hip_add_rvs_relay_to, 43000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_CLOSED, &hip_send_r2, 
50000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_NONE, &hip_check_i2,  
20000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_NONE, &hip_handle_i2, 
30000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_NONE, 
&hip_update_retransmissions, 30250);
-    hip_register_handle_function(HIP_I2, HIP_STATE_NONE, &hip_setup_ipsec_sa, 
30500);
-    hip_register_handle_function(HIP_I2, HIP_STATE_NONE, &hip_create_r2, 
40000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_NONE, 
&hip_add_rvs_reg_from, 41000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_NONE, &hip_hmac2_and_sign, 
42000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_NONE, 
&hip_add_rvs_relay_to, 43000);
-    hip_register_handle_function(HIP_I2, HIP_STATE_NONE, &hip_send_r2, 50000);
-
-    hip_register_handle_function(HIP_R1, HIP_STATE_I1_SENT, &hip_check_r1,  
20000);
-    hip_register_handle_function(HIP_R1, HIP_STATE_I1_SENT, &hip_handle_r1, 
30000);
-    hip_register_handle_function(HIP_R1, HIP_STATE_I1_SENT, 
&hip_update_retransmissions, 30500);
-    hip_register_handle_function(HIP_R1, HIP_STATE_I1_SENT, 
&hip_build_esp_info, 31000);
-    hip_register_handle_function(HIP_R1, HIP_STATE_I1_SENT, 
&hip_build_solution, 32000);
-    hip_register_handle_function(HIP_R1, HIP_STATE_I1_SENT, 
&hip_handle_diffie_hellman, 33000);
-    hip_register_handle_function(HIP_R1, HIP_STATE_I1_SENT, 
&esp_prot_r1_handle_transforms, 34000);
-    hip_register_handle_function(HIP_R1, HIP_STATE_I1_SENT, &hip_create_i2, 
40000);
-    hip_register_handle_function(HIP_R1, HIP_STATE_I1_SENT, 
&hip_add_signed_echo_response, 41000);
-    hip_register_handle_function(HIP_R1, HIP_STATE_I1_SENT, 
&hip_mac_and_sign_handler, 42000);
-    hip_register_handle_function(HIP_R1, HIP_STATE_I1_SENT, 
&hip_add_unsigned_echo_response, 43000);
-    hip_register_handle_function(HIP_R1, HIP_STATE_I1_SENT, &hip_send_i2,   
50000);
-    hip_register_handle_function(HIP_R1, HIP_STATE_I2_SENT, &hip_check_r1,  
20000);
-    hip_register_handle_function(HIP_R1, HIP_STATE_I2_SENT, &hip_handle_r1, 
30000);
-    hip_register_handle_function(HIP_R1, HIP_STATE_I2_SENT, 
&hip_update_retransmissions, 30500);
-    hip_register_handle_function(HIP_R1, HIP_STATE_I2_SENT, 
&hip_build_esp_info, 31000);
-    hip_register_handle_function(HIP_R1, HIP_STATE_I2_SENT, 
&hip_build_solution, 32000);
-    hip_register_handle_function(HIP_R1, HIP_STATE_I2_SENT, 
&hip_handle_diffie_hellman, 33000);
-    hip_register_handle_function(HIP_R1, HIP_STATE_I2_SENT, 
&esp_prot_r1_handle_transforms, 34000);
-    hip_register_handle_function(HIP_R1, HIP_STATE_I2_SENT, &hip_create_i2, 
40000);
-    hip_register_handle_function(HIP_R1, HIP_STATE_I2_SENT, 
&hip_add_signed_echo_response, 41000);
-    hip_register_handle_function(HIP_R1, HIP_STATE_I2_SENT, 
&hip_mac_and_sign_handler, 42000);
-    hip_register_handle_function(HIP_R1, HIP_STATE_I2_SENT, 
&hip_add_unsigned_echo_response, 43000);
-    hip_register_handle_function(HIP_R1, HIP_STATE_I2_SENT, &hip_send_i2,   
50000);
-    hip_register_handle_function(HIP_R1, HIP_STATE_CLOSING, &hip_check_r1,  
20000);
-    hip_register_handle_function(HIP_R1, HIP_STATE_CLOSING, &hip_handle_r1, 
30000);
-    hip_register_handle_function(HIP_R1, HIP_STATE_CLOSING, 
&hip_update_retransmissions, 30500);
-    hip_register_handle_function(HIP_R1, HIP_STATE_CLOSING, 
&hip_build_esp_info, 31000);
-    hip_register_handle_function(HIP_R1, HIP_STATE_CLOSING, 
&hip_build_solution, 32000);
-    hip_register_handle_function(HIP_R1, HIP_STATE_CLOSING, 
&hip_handle_diffie_hellman, 33000);
-    hip_register_handle_function(HIP_R1, HIP_STATE_CLOSING, 
&esp_prot_r1_handle_transforms, 34000);
-    hip_register_handle_function(HIP_R1, HIP_STATE_CLOSING, &hip_create_i2, 
40000);
-    hip_register_handle_function(HIP_R1, HIP_STATE_CLOSING, 
&hip_add_signed_echo_response, 41000);
-    hip_register_handle_function(HIP_R1, HIP_STATE_CLOSING, 
&hip_mac_and_sign_handler, 42000);
-    hip_register_handle_function(HIP_R1, HIP_STATE_CLOSING, 
&hip_add_unsigned_echo_response, 43000);
-    hip_register_handle_function(HIP_R1, HIP_STATE_CLOSING, &hip_send_i2,   
50000);
-    hip_register_handle_function(HIP_R1, HIP_STATE_CLOSED, &hip_check_r1,  
20000);
-    hip_register_handle_function(HIP_R1, HIP_STATE_CLOSED, &hip_handle_r1, 
30000);
-    hip_register_handle_function(HIP_R1, HIP_STATE_CLOSED, 
&hip_update_retransmissions, 30500);
-    hip_register_handle_function(HIP_R1, HIP_STATE_CLOSED, 
&hip_build_esp_info, 31000);
-    hip_register_handle_function(HIP_R1, HIP_STATE_CLOSED, 
&hip_build_solution, 32000);
-    hip_register_handle_function(HIP_R1, HIP_STATE_CLOSED, 
&hip_handle_diffie_hellman, 33000);
-    hip_register_handle_function(HIP_R1, HIP_STATE_CLOSED, 
&esp_prot_r1_handle_transforms, 34000);
-    hip_register_handle_function(HIP_R1, HIP_STATE_CLOSED, &hip_create_i2, 
40000);
-    hip_register_handle_function(HIP_R1, HIP_STATE_CLOSED, 
&hip_add_signed_echo_response, 41000);
-    hip_register_handle_function(HIP_R1, HIP_STATE_CLOSED, 
&hip_mac_and_sign_handler, 42000);
-    hip_register_handle_function(HIP_R1, HIP_STATE_CLOSED, 
&hip_add_unsigned_echo_response, 43000);
-    hip_register_handle_function(HIP_R1, HIP_STATE_CLOSED, &hip_send_i2, 
50000);
-
-    hip_register_handle_function(HIP_R2, HIP_STATE_I2_SENT, &hip_check_r2,  
20000);
-    hip_register_handle_function(HIP_R2, HIP_STATE_I2_SENT, &hip_handle_r2, 
30000);
-    hip_register_handle_function(HIP_R2, HIP_STATE_I2_SENT, 
&hip_update_retransmissions, 30250);
-    hip_register_handle_function(HIP_R2, HIP_STATE_I2_SENT, 
&hip_setup_ipsec_sa, 30500);
-
-    hip_register_handle_function(HIP_NOTIFY, HIP_STATE_I1_SENT, 
&hip_check_notify,  20000);
-    hip_register_handle_function(HIP_NOTIFY, HIP_STATE_I1_SENT, 
&hip_handle_notify, 30000);
-    hip_register_handle_function(HIP_NOTIFY, HIP_STATE_I2_SENT, 
&hip_check_notify,  20000);
-    hip_register_handle_function(HIP_NOTIFY, HIP_STATE_I2_SENT, 
&hip_handle_notify, 30000);
-    hip_register_handle_function(HIP_NOTIFY, HIP_STATE_R2_SENT, 
&hip_check_notify,  20000);
-    hip_register_handle_function(HIP_NOTIFY, HIP_STATE_R2_SENT, 
&hip_handle_notify, 30000);
-    hip_register_handle_function(HIP_NOTIFY, HIP_STATE_ESTABLISHED, 
&hip_check_notify, 20000);
-    hip_register_handle_function(HIP_NOTIFY, HIP_STATE_ESTABLISHED, 
&hip_handle_notify, 30000);
-    hip_register_handle_function(HIP_NOTIFY, HIP_STATE_CLOSING, 
&hip_check_notify,  20000);
-    hip_register_handle_function(HIP_NOTIFY, HIP_STATE_CLOSING, 
&hip_handle_notify, 30000);
-    hip_register_handle_function(HIP_NOTIFY, HIP_STATE_CLOSED, 
&hip_check_notify,  20000);
-    hip_register_handle_function(HIP_NOTIFY, HIP_STATE_CLOSED, 
&hip_handle_notify, 30000);
-
-    hip_register_handle_function(HIP_CLOSE, HIP_STATE_ESTABLISHED,  
&hip_close_check_packet,     20000);
-    hip_register_handle_function(HIP_CLOSE, HIP_STATE_ESTABLISHED,  
&hip_update_retransmissions, 25000);
-    hip_register_handle_function(HIP_CLOSE, HIP_STATE_ESTABLISHED,  
&hip_close_create_response,  30000);
-    hip_register_handle_function(HIP_CLOSE, HIP_STATE_ESTABLISHED,  
&hip_close_send_response,    40000);
-
-    hip_register_handle_function(HIP_CLOSE, HIP_STATE_CLOSING,  
&hip_close_check_packet,     20000);
-    hip_register_handle_function(HIP_CLOSE, HIP_STATE_CLOSING,  
&hip_update_retransmissions, 25000);
-    hip_register_handle_function(HIP_CLOSE, HIP_STATE_CLOSING,  
&hip_close_create_response,  30000);
-    hip_register_handle_function(HIP_CLOSE, HIP_STATE_CLOSING,  
&hip_close_send_response,    40000);
-
-    hip_register_handle_function(HIP_CLOSE_ACK, HIP_STATE_CLOSING, 
&hip_close_ack_check_packet,  20000);
-    hip_register_handle_function(HIP_CLOSE_ACK, HIP_STATE_CLOSING, 
&hip_update_retransmissions,  25000);
-    hip_register_handle_function(HIP_CLOSE_ACK, HIP_STATE_CLOSING, 
&hip_close_ack_handle_packet, 30000);
-
-    hip_register_handle_function(HIP_CLOSE_ACK, HIP_STATE_CLOSED,  
&hip_close_ack_check_packet,  20000);
-    hip_register_handle_function(HIP_CLOSE_ACK, HIP_STATE_CLOSED,  
&hip_update_retransmissions,  25000);
-    hip_register_handle_function(HIP_CLOSE_ACK, HIP_STATE_CLOSED,  
&hip_close_ack_handle_packet, 30000);
-
-    hip_register_handle_function(HIP_LUPDATE, HIP_STATE_ESTABLISHED, 
&esp_prot_handle_light_update, 20000);
-    hip_register_handle_function(HIP_LUPDATE, HIP_STATE_R2_SENT,     
&esp_prot_handle_light_update, 20000);
-
-    return err;
-}
-
 /**
  * set or unset close-on-exec flag for a given file descriptor
  *
@@ -1459,3 +1460,32 @@
 out_err:
     return err;
 }
+
+/**
+ * Set the default HIP version to be used for outgoing I1 messages.
+ *
+ * @param version HIP version to be used in I1 message by default. It should
+ *                be greater than 0 and less than the @c HIP_MAX_VERSION.
+ * @return 0 on success, -1 on failure.
+ */
+int hip_set_default_version(uint8_t version)
+{
+    if (version <= 0 || version >= HIP_MAX_VERSION) {
+        HIP_ERROR("invalid default-hip-version: %d", version);
+        return -1;
+    }
+
+    hip_default_hip_version = version;
+
+    return 0;
+}
+
+/**
+ * Get the default HIP verison parameter.
+ *
+ * @return the default HIP version.
+ */
+uint8_t hip_get_default_version(void)
+{
+    return hip_default_hip_version;
+}

=== modified file 'libhipl/init.h'
--- libhipl/init.h      2012-05-12 10:21:32 +0000
+++ libhipl/init.h      2012-06-03 10:26:55 +0000
@@ -62,6 +62,8 @@
                             int is_output);
 void hip_exit(void);
 
+int hip_set_default_version(uint8_t version);
+uint8_t hip_get_default_version(void);
 int hipl_lib_init(enum logdebug);
 
 #endif /* HIPL_LIBHIPL_INIT_H */

=== modified file 'libhipl/input.c'
--- libhipl/input.c     2012-05-12 10:21:32 +0000
+++ libhipl/input.c     2012-07-13 13:16:17 +0000
@@ -247,12 +247,12 @@
     HIP_IFEL(!(param = hip_get_param(ctx->input_msg, HIP_PARAM_HIP_TRANSFORM)),
              -EINVAL,
              "Could not find HIP transform\n");
-    HIP_IFEL((hip_tfm = hip_select_hip_transform((const struct 
hip_hip_transform *) param)) == 0,
+    HIP_IFEL((hip_tfm = hip_select_hip_transform(param)) == 0,
              -EINVAL, "Could not select HIP transform\n");
     HIP_IFEL(!(param = hip_get_param(ctx->input_msg, HIP_PARAM_ESP_TRANSFORM)),
              -EINVAL,
              "Could not find ESP transform\n");
-    HIP_IFEL((esp_tfm = hip_select_esp_transform((const struct 
hip_esp_transform *) param)) == 0,
+    HIP_IFEL((esp_tfm = hip_select_esp_transform(param)) == 0,
              -EINVAL, "Could not select proper ESP transform\n");
 
     hip_transf_length  = hip_transform_key_length(hip_tfm);
@@ -493,6 +493,7 @@
 {
     struct in6_addr ipv6_any_addr = IN6ADDR_ANY_INIT;
     uint32_t        type, state;
+    uint8_t         msg_hip_version;
 
     if (hip_check_network_msg(ctx->input_msg)) {
         HIP_ERROR("Checking control message failed.\n");
@@ -529,10 +530,12 @@
      * printing packet data here works for all packets. To avoid excessive
      * debug printing do not print this information inside the individual
      * receive or handle functions. */
+    msg_hip_version = hip_get_msg_version(ctx->input_msg);
     HIP_INFO_IN6ADDR("Src IP", &ctx->src_addr);
     HIP_INFO_IN6ADDR("Dst IP", &ctx->dst_addr);
     HIP_DEBUG("Src port: %u\n", ctx->msg_ports.src_port);
     HIP_DEBUG("Dst port: %u\n", ctx->msg_ports.dst_port);
+    HIP_DEBUG("HIP version: %d\n", msg_hip_version);
     HIP_DUMP_MSG(ctx->input_msg);
 
     type = hip_get_msg_type(ctx->input_msg);
@@ -557,6 +560,23 @@
 
     if (ctx->hadb_entry) {
         state = ctx->hadb_entry->state;
+
+        /* If the HIP version of this hadb entry hasn't been set, we set it now
+         * so handler functions can access it later from the packet context.
+         * If the hadb entry already records its HIP version, we check whether
+         * the version of the current receiving message equals the version in
+         * hadb and drop those messages with invalid version. */
+        if (ctx->hadb_entry->hip_version == 0) {
+            ctx->hadb_entry->hip_version = msg_hip_version;
+            HIP_DEBUG("Set HIP version of the hadb entry to %d\n",
+                      msg_hip_version);
+        } else if (ctx->hadb_entry->hip_version != msg_hip_version) {
+            HIP_ERROR("The version of the inbound message (V%d) doesn't match "
+                      "the version of the corresponding hadb record (V%d)\n",
+                      ctx->hadb_entry->hip_version,
+                      msg_hip_version);
+            return -1;
+        }
     } else {
         state = HIP_STATE_NONE;
     }
@@ -856,7 +876,8 @@
                           HIP_I2,
                           0,
                           &ctx->input_msg->hit_receiver,
-                          &ctx->input_msg->hit_sender);
+                          &ctx->input_msg->hit_sender,
+                          ctx->hadb_entry->hip_version);
 
     /* note: we could skip keying material generation in the case
      * of a retransmission but then we'd had to fill ctx->hmac etc */
@@ -1342,6 +1363,7 @@
                  UNUSED const enum hip_state ha_state,
                  struct hip_packet_context *ctx)
 {
+    int                             hip_version       = 0;
     int                             err               = 0, is_loopback = 0;
     bool                            skip_key_creation = false;
     uint16_t                        mask              = HIP_PACKET_CTRL_ANON;
@@ -1410,6 +1432,7 @@
         skip_key_creation = true;
     } else {
         if (ctx->hadb_entry) {
+            hip_version = ctx->hadb_entry->hip_version;
             HIP_DEBUG("Removing existing state and creating new one.\n");
             HIP_IFEL(hip_del_peer_info_entry(ctx->hadb_entry),
                      -1, "Deleting peer info failed\n");
@@ -1421,6 +1444,10 @@
                  "Out of memory when allocating memory for a new HIP "
                  "association. Dropping the I2 packet.\n");
 
+        if (hip_version == 0) {
+            hip_version = hip_get_msg_version(ctx->input_msg);
+        }
+        ctx->hadb_entry->hip_version = hip_version;
         ipv6_addr_copy(&ctx->hadb_entry->hit_peer, 
&ctx->input_msg->hit_sender);
         ipv6_addr_copy(&ctx->hadb_entry->our_addr, &ctx->dst_addr);
         HIP_DEBUG("Initializing the HIP association.\n");
@@ -1440,7 +1467,8 @@
     HIP_IFEL(hip_verify_cookie(&ctx->src_addr,
                                &ctx->dst_addr,
                                ctx->input_msg,
-                               solution),
+                               solution,
+                               ctx->hadb_entry->hip_version),
              -EPROTO,
              "Cookie solution rejected. Dropping the I2 packet.\n");
 
@@ -1659,12 +1687,12 @@
                   UNUSED const enum hip_state ha_state,
                   struct hip_packet_context *ctx)
 {
-    int                             err      = 0, if_index = 0;
-    struct sockaddr_storage         ss_addr  = { 0 };
-    struct sockaddr                *addr     = NULL;
-    const struct hip_esp_info      *esp_info = NULL;
-    const struct hip_esp_transform *esp_tfm  = NULL;
-    const struct hip_locator       *locator  = NULL;
+    int                          err      = 0, if_index = 0;
+    struct sockaddr_storage      ss_addr  = { 0 };
+    struct sockaddr             *addr     = NULL;
+    const struct hip_esp_info   *esp_info = NULL;
+    const struct hip_tlv_common *esp_tfm  = NULL;
+    const struct hip_locator    *locator  = NULL;
 
     /* Get the interface index of the network device which has our
      * local IP address. */
@@ -1899,7 +1927,8 @@
                                       response,
                                       ctx->hadb_entry->local_controls,
                                       &ctx->hadb_entry->hit_our,
-                                      &ctx->hadb_entry->hit_peer);
+                                      &ctx->hadb_entry->hit_peer,
+                                      ctx->hadb_entry->hip_version);
 
                 /* Calculate the HIP header length */
                 hip_calc_hdr_len(ctx->output_msg);

=== modified file 'libhipl/nat.c'
--- libhipl/nat.c       2012-05-12 10:21:32 +0000
+++ libhipl/nat.c       2012-06-03 10:26:55 +0000
@@ -121,7 +121,7 @@
 
     hip_build_network_hdr(msg, HIP_NOTIFY,
                           0, &entry->hit_our,
-                          &entry->hit_peer);
+                          &entry->hit_peer, entry->hip_version);
 
     /* Calculate the HIP header length */
     hip_calc_hdr_len(msg);

=== modified file 'libhipl/netdev.c'
--- libhipl/netdev.c    2012-05-12 10:21:32 +0000
+++ libhipl/netdev.c    2012-06-03 10:26:55 +0000
@@ -69,6 +69,7 @@
 #include "config.h"
 #include "accessor.h"
 #include "hadb.h"
+#include "init.h"
 #include "hidb.h"
 #include "hipd.h"
 #include "hit_to_ip.h"
@@ -865,6 +866,7 @@
     entry = hip_hadb_find_byhits(src_hit, dst_hit);
     if (entry && !ipv6_addr_any(&entry->our_addr)) {
         reuse_hadb_local_address = 1;
+        entry->hip_version       = hip_get_default_version();
         goto send_i1;
     }
 
@@ -946,6 +948,7 @@
     entry->local_udp_port = ha_local_port;
     entry->peer_udp_port  = ha_peer_port;
     entry->nat_mode       = ha_nat_mode;
+    entry->hip_version    = hip_get_default_version();
 
     reuse_hadb_local_address = 1;
 

=== modified file 'libhipl/output.c'
--- libhipl/output.c    2012-05-12 10:21:32 +0000
+++ libhipl/output.c    2012-06-07 12:45:16 +0000
@@ -63,6 +63,7 @@
 #include "hidb.h"
 #include "hipd.h"
 #include "hiprelay.h"
+#include "init.h"
 #include "nat.h"
 #include "netdev.h"
 #include "registration.h"
@@ -208,7 +209,8 @@
 
     i1 = hip_msg_alloc();
 
-    hip_build_network_hdr(i1, HIP_I1, mask, &entry->hit_our, dst_hit);
+    hip_build_network_hdr(i1, HIP_I1, mask, &entry->hit_our,
+                          dst_hit, entry->hip_version);
 
     /* Calculate the HIP header length */
     hip_calc_hdr_len(i1);
@@ -375,13 +377,13 @@
                   UNUSED const enum hip_state ha_state,
                   struct hip_packet_context *ctx)
 {
-    hip_transform_suite     transform_hip_suite, transform_esp_suite;
-    const struct hip_param *param         = NULL;
-    struct hip_esp_info    *esp_info      = NULL;
-    struct local_host_id   *host_id_entry = NULL;
-    char                   *enc_in_msg    = NULL, *host_id_in_enc = NULL;
-    unsigned char          *iv            = NULL;
-    int                     err           = 0, host_id_in_enc_len = 0;
+    hip_transform_suite          transform_hip_suite, transform_esp_suite;
+    const struct hip_tlv_common *param         = NULL;
+    struct hip_esp_info         *esp_info      = NULL;
+    struct local_host_id        *host_id_entry = NULL;
+    char                        *enc_in_msg    = NULL, *host_id_in_enc = NULL;
+    unsigned char               *iv            = NULL;
+    int                          err           = 0, host_id_in_enc_len = 0;
 
     HIP_IFEL(ctx->error, -1, "Abort packet processing.\n");
 
@@ -409,7 +411,7 @@
     /********** HIP transform. **********/
     HIP_IFE(!(param = hip_get_param(ctx->input_msg, HIP_PARAM_HIP_TRANSFORM)),
             -ENOENT);
-    HIP_IFEL((transform_hip_suite = hip_select_hip_transform((const struct 
hip_hip_transform *) param)) == 0,
+    HIP_IFEL((transform_hip_suite = hip_select_hip_transform(param)) == 0,
              -EINVAL, "Could not find acceptable HIP transform suite.\n");
 
     /* Select only one transform */
@@ -483,7 +485,7 @@
             -ENOENT);
 
     /* Select only one transform */
-    HIP_IFEL((transform_esp_suite = hip_select_esp_transform((const struct 
hip_esp_transform *) param)) == 0,
+    HIP_IFEL((transform_esp_suite = hip_select_esp_transform(param)) == 0,
              -1, "Could not find acceptable hip transform suite\n");
     HIP_IFEL(hip_build_param_esp_transform(ctx->output_msg,
                                            &transform_esp_suite, 1), -1,
@@ -603,6 +605,7 @@
  * @param private_key  a pointer to the local host private key
  * @param host_id_pub  a pointer to the public host id of the local host
  * @param cookie_k     the difficulty value for the puzzle
+ * @param hip_version  HIP message version
  * @return             0 on success, a non-zero value on error.
  */
 int hip_create_r1(struct hip_common *const msg,
@@ -610,7 +613,8 @@
                   int (*sign)(void *const key, struct hip_common *const m),
                   void *const private_key,
                   const struct hip_host_id *const host_id_pub,
-                  const int cookie_k)
+                  const int cookie_k,
+                  const uint8_t hip_version)
 {
     int            err = 0;
     struct hip_srv service_list[HIP_TOTAL_EXISTING_SERVICES];
@@ -678,7 +682,7 @@
     /** @todo TH: hip_build_network_hdr has to be replaced with an
      *  appropriate function pointer */
     HIP_DEBUG_HIT("src_hit used to build r1 network header", src_hit);
-    hip_build_network_hdr(msg, HIP_R1, mask, src_hit, NULL);
+    hip_build_network_hdr(msg, HIP_R1, mask, src_hit, NULL, hip_version);
 
     /********** R1_COUNTER (OPTIONAL) *********/
 
@@ -863,7 +867,8 @@
     }
 
     HIP_IFEL(!(r1pkt = hip_get_r1(r1_dst_addr, &ctx->dst_addr,
-                                  &ctx->input_msg->hit_receiver)),
+                                  &ctx->input_msg->hit_receiver,
+                                  hip_get_msg_version(ctx->input_msg))),
              -ENOENT, "No precreated R1\n");
 
     if (&ctx->input_msg->hit_sender) {
@@ -1037,7 +1042,8 @@
      * source HIT. */
     hip_build_network_hdr(ctx->output_msg, HIP_R2, mask,
                           &ctx->hadb_entry->hit_our,
-                          &ctx->hadb_entry->hit_peer);
+                          &ctx->hadb_entry->hit_peer,
+                          ctx->hadb_entry->hip_version);
 
     HIP_DUMP_MSG(ctx->output_msg);
 

=== modified file 'libhipl/output.h'
--- libhipl/output.h    2012-05-12 10:21:32 +0000
+++ libhipl/output.h    2012-06-03 10:26:55 +0000
@@ -52,7 +52,8 @@
                   int (*sign)(void *const key, struct hip_common *const m),
                   void *const private_key,
                   const struct hip_host_id *const host_id_pub,
-                  const int cookie_k);
+                  const int cookie_k,
+                  const uint8_t hip_version);
 
 int hip_send_r1(const uint8_t packet_type,
                 const enum hip_state ha_state,

=== modified file 'libhipl/pkt_handling.c'
--- libhipl/pkt_handling.c      2012-05-12 10:21:32 +0000
+++ libhipl/pkt_handling.c      2012-07-12 11:32:14 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010-2011 Aalto University and RWTH Aachen University.
+ * Copyright (c) 2010-2012 Aalto University and RWTH Aachen University.
  *
  * Permission is hereby granted, free of charge, to any person
  * obtaining a copy of this software and associated documentation
@@ -30,6 +30,7 @@
 
 #include <stdint.h>
 
+#include "libcore/builder.h"
 #include "libcore/ife.h"
 #include "libcore/linkedlist.h"
 #include "libcore/protodefs.h"
@@ -46,25 +47,32 @@
 };
 
 /**
- * @todo add description
+ * This three-dimension array stores lists of packet handling functions
+ * categorized by HIP version numbers, HIP packet types and HIP host
+ * association states. Each list contains corresponding handle functions
+ * sorted by priority.
  */
-static struct hip_ll 
*hip_handle_functions[HIP_MAX_PACKET_TYPE][HIP_MAX_HA_STATE];
+static struct hip_ll 
*hip_handle_functions[HIP_MAX_VERSION][HIP_MAX_PACKET_TYPE][HIP_MAX_HA_STATE];
 
 /**
- * Register a function for handling of the specified combination from packet
- * type and host association state.
+ * Register a function for handling packets with specified combination from HIP
+ * version, packet type and host association state.
  *
- * @param packet_type The packet type of the control message (RFC 5201, 5.3.)
- * @param ha_state The host association state (RFC 5201, 4.4.1.)
+ * @param hip_version     HIP version. If HIP_ALL is given, the handle function
+                          is registered to all HIP versions which are supported
+                          by HIPL.
+ * @param packet_type     The packet type of the control message
+ *                        (RFC 5201, 5.3.)
+ * @param ha_state        The host association state (RFC 5201, 4.4.1.)
  * @param handle_function Pointer to the function which should be called
  *                        when the combination of packet type and host
  *                        association state is reached.
- * @param priority Execution priority for the handle function.
+ * @param priority        Execution priority for the handle function.
  *
- * @return Success =  0
- *         Error   = -1
+ * @return                0 on success, -1 on error.
  */
-int hip_register_handle_function(const uint8_t packet_type,
+int hip_register_handle_function(const uint8_t hip_version,
+                                 const uint8_t packet_type,
                                  const enum hip_state ha_state,
                                  int (*handle_function)(const uint8_t 
packet_type,
                                                         const enum hip_state 
ha_state,
@@ -74,6 +82,22 @@
     int                     err       = 0;
     struct handle_function *new_entry = NULL;
 
+    if (hip_version == HIP_ALL) {
+        for (int i = HIP_V1; i < HIP_MAX_VERSION; i++) {
+            err = hip_register_handle_function(i, packet_type, ha_state,
+                                               handle_function, priority);
+            if (err) {
+                return -1;
+            }
+        }
+        return 0;
+    }
+
+    if (hip_version <= 0 || hip_version >= HIP_MAX_VERSION) {
+        HIP_ERROR("Invalid HIP version: %d\n", hip_version);
+        return -1;
+    }
+
     HIP_IFEL(packet_type > HIP_MAX_PACKET_TYPE,
              -1,
              "Maximum packet type exceeded.\n");
@@ -88,11 +112,11 @@
     new_entry->priority = priority;
     new_entry->func_ptr = handle_function;
 
-    hip_handle_functions[packet_type][ha_state] =
-        lmod_register_function(hip_handle_functions[packet_type][ha_state],
+    hip_handle_functions[hip_version][packet_type][ha_state] =
+        
lmod_register_function(hip_handle_functions[hip_version][packet_type][ha_state],
                                new_entry,
                                priority);
-    if (!hip_handle_functions[packet_type][ha_state]) {
+    if (!hip_handle_functions[hip_version][packet_type][ha_state]) {
         HIP_ERROR("Error on registering a handle function.\n");
         err = -1;
     }
@@ -117,7 +141,8 @@
                              const enum hip_state ha_state,
                              struct hip_packet_context *ctx)
 {
-    int                       err  = 0;
+    int                       err = 0;
+    int                       hip_version;
     const struct hip_ll_node *iter = NULL;
 
     HIP_IFEL(packet_type > HIP_MAX_PACKET_TYPE,
@@ -127,13 +152,15 @@
              -1,
              "Maximum host association state exceeded.\n");
 
-    HIP_IFEL(!hip_handle_functions[packet_type][ha_state],
+    hip_version = hip_get_msg_version(ctx->input_msg);
+
+    HIP_IFEL(!hip_handle_functions[hip_version][packet_type][ha_state],
              -1,
              "Error on running handle functions.\nPacket type: %d, HA state: 
%d\n",
              packet_type,
              ha_state);
 
-    while ((iter = hip_ll_iterate(hip_handle_functions[packet_type][ha_state],
+    while ((iter = 
hip_ll_iterate(hip_handle_functions[hip_version][packet_type][ha_state],
                                   iter))
            && !ctx->error) {
         err = ((struct handle_function *) iter->ptr)->func_ptr(packet_type,
@@ -155,13 +182,15 @@
  */
 void hip_uninit_handle_functions(void)
 {
-    int i, j;
+    int i, j, k;
 
-    for (i = 0; i < HIP_MAX_PACKET_TYPE; i++) {
-        for (j = 0; j < HIP_MAX_HA_STATE; j++) {
-            if (hip_handle_functions[i][j]) {
-                hip_ll_uninit(hip_handle_functions[i][j], free);
-                free(hip_handle_functions[i][j]);
+    for (i = 0; i < HIP_MAX_VERSION; i++) {
+        for (j = 0; j < HIP_MAX_PACKET_TYPE; j++) {
+            for (k = 0; k < HIP_MAX_HA_STATE; k++) {
+                if (hip_handle_functions[i][j][k]) {
+                    hip_ll_uninit(hip_handle_functions[i][j][k], free);
+                    free(hip_handle_functions[i][j][k]);
+                }
             }
         }
     }

=== modified file 'libhipl/pkt_handling.h'
--- libhipl/pkt_handling.h      2012-05-12 10:21:32 +0000
+++ libhipl/pkt_handling.h      2012-06-03 10:26:55 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010-2011 Aalto University and RWTH Aachen University.
+ * Copyright (c) 2010-2012 Aalto University and RWTH Aachen University.
  *
  * Permission is hereby granted, free of charge, to any person
  * obtaining a copy of this software and associated documentation
@@ -31,7 +31,8 @@
 #include "libcore/protodefs.h"
 #include "libcore/state.h"
 
-int hip_register_handle_function(const uint8_t packet_type,
+int hip_register_handle_function(const uint8_t hip_version,
+                                 const uint8_t packet_type,
                                  const enum hip_state ha_state,
                                  int (*handle_function)(const uint8_t 
packet_type,
                                                         const enum hip_state 
ha_state,

=== modified file 'libhipl/user.c'
--- libhipl/user.c      2012-05-12 10:21:32 +0000
+++ libhipl/user.c      2012-06-03 10:26:55 +0000
@@ -694,6 +694,19 @@
         HIP_DEBUG("hip_broadcast_status =  %d (should be %d)\n",
                   hip_broadcast_status, HIP_MSG_BROADCAST_OFF);
         break;
+
+    case HIP_MSG_DEFAULT_HIP_VERSION_1:
+        hip_set_default_version(HIP_V1);
+        HIP_DEBUG("hip_default_version has been set to: %d\n",
+                  hip_get_default_version());
+        break;
+
+    case HIP_MSG_DEFAULT_HIP_VERSION_2:
+        hip_set_default_version(HIP_V2);
+        HIP_DEBUG("hip_default_version has been set to: %d\n",
+                  hip_get_default_version());
+        break;
+
     case HIP_MSG_LSI_ON:
         lsi_status = HIP_MSG_LSI_ON;
         break;

=== modified file 'modules/cert/hipd/cert.c'
--- modules/cert/hipd/cert.c    2012-05-12 10:21:32 +0000
+++ modules/cert/hipd/cert.c    2012-07-12 11:32:14 +0000
@@ -151,42 +151,42 @@
  */
 int hip_cert_init(void)
 {
-    if (hip_register_handle_function(HIP_I2, HIP_STATE_NONE,
-                                     &hip_add_certificate_r2, 40500)) {
-        HIP_ERROR("Error on registering certificate handle function.\n");
-        return -1;
-    }
-    if (hip_register_handle_function(HIP_I2, HIP_STATE_UNASSOCIATED,
-                                     &hip_add_certificate_r2, 40500)) {
-        HIP_ERROR("Error on registering certificate handle function.\n");
-        return -1;
-    }
-    if (hip_register_handle_function(HIP_I2, HIP_STATE_I1_SENT,
-                                     &hip_add_certificate_r2, 40500)) {
-        HIP_ERROR("Error on registering certificate handle function.\n");
-        return -1;
-    }
-    if (hip_register_handle_function(HIP_I2, HIP_STATE_I2_SENT,
-                                     &hip_add_certificate_r2, 40500)) {
-        HIP_ERROR("Error on registering certificate handle function.\n");
-        return -1;
-    }
-    if (hip_register_handle_function(HIP_I2, HIP_STATE_R2_SENT,
-                                     &hip_add_certificate_r2, 40500)) {
-        HIP_ERROR("Error on registering certificate handle function.\n");
-        return -1;
-    }
-    if (hip_register_handle_function(HIP_I2, HIP_STATE_ESTABLISHED,
-                                     &hip_add_certificate_r2, 40500)) {
-        HIP_ERROR("Error on registering certificate handle function.\n");
-        return -1;
-    }
-    if (hip_register_handle_function(HIP_UPDATE, HIP_STATE_ESTABLISHED,
+    if (hip_register_handle_function(HIP_ALL, HIP_I2, HIP_STATE_NONE,
+                                     &hip_add_certificate_r2, 40500)) {
+        HIP_ERROR("Error on registering certificate handle function.\n");
+        return -1;
+    }
+    if (hip_register_handle_function(HIP_ALL, HIP_I2, HIP_STATE_UNASSOCIATED,
+                                     &hip_add_certificate_r2, 40500)) {
+        HIP_ERROR("Error on registering certificate handle function.\n");
+        return -1;
+    }
+    if (hip_register_handle_function(HIP_ALL, HIP_I2, HIP_STATE_I1_SENT,
+                                     &hip_add_certificate_r2, 40500)) {
+        HIP_ERROR("Error on registering certificate handle function.\n");
+        return -1;
+    }
+    if (hip_register_handle_function(HIP_ALL, HIP_I2, HIP_STATE_I2_SENT,
+                                     &hip_add_certificate_r2, 40500)) {
+        HIP_ERROR("Error on registering certificate handle function.\n");
+        return -1;
+    }
+    if (hip_register_handle_function(HIP_ALL, HIP_I2, HIP_STATE_R2_SENT,
+                                     &hip_add_certificate_r2, 40500)) {
+        HIP_ERROR("Error on registering certificate handle function.\n");
+        return -1;
+    }
+    if (hip_register_handle_function(HIP_ALL, HIP_I2, HIP_STATE_ESTABLISHED,
+                                     &hip_add_certificate_r2, 40500)) {
+        HIP_ERROR("Error on registering certificate handle function.\n");
+        return -1;
+    }
+    if (hip_register_handle_function(HIP_ALL, HIP_UPDATE, 
HIP_STATE_ESTABLISHED,
                                      &hip_add_certificate_update, 20752)) {
         HIP_ERROR("Error on registering certificate handle function.\n");
         return -1;
     }
-    if (hip_register_handle_function(HIP_UPDATE, HIP_STATE_R2_SENT,
+    if (hip_register_handle_function(HIP_ALL, HIP_UPDATE, HIP_STATE_R2_SENT,
                                      &hip_add_certificate_update, 20752)) {
         HIP_ERROR("Error on registering certificate handle function.\n");
         return -1;

=== modified file 'modules/midauth/hipd/midauth.c'
--- modules/midauth/hipd/midauth.c      2012-05-12 10:21:32 +0000
+++ modules/midauth/hipd/midauth.c      2012-07-12 11:32:14 +0000
@@ -166,7 +166,7 @@
                                                            HIP_STATE_CLOSING,
                                                            HIP_STATE_CLOSED };
     for (unsigned i = 0; i < ARRAY_SIZE(challenge_request_R1_states); i++) {
-        if (hip_register_handle_function(HIP_R1,
+        if (hip_register_handle_function(HIP_ALL, HIP_R1,
                                          challenge_request_R1_states[i],
                                          &handle_challenge_request_param,
                                          32500)) {
@@ -189,7 +189,7 @@
                                                            HIP_STATE_CLOSED,
                                                            HIP_STATE_NONE };
     for (unsigned i = 0; i < ARRAY_SIZE(challenge_request_I2_states); i++) {
-        if (hip_register_handle_function(HIP_I2,
+        if (hip_register_handle_function(HIP_ALL, HIP_I2,
                                          challenge_request_I2_states[i],
                                          &handle_challenge_request_param,
                                          40322)) {
@@ -206,7 +206,7 @@
     const enum hip_state challenge_request_UPDATE_states[] = { 
HIP_STATE_R2_SENT,
                                                                
HIP_STATE_ESTABLISHED };
     for (unsigned i = 0; i < ARRAY_SIZE(challenge_request_UPDATE_states); i++) 
{
-        if (hip_register_handle_function(HIP_UPDATE,
+        if (hip_register_handle_function(HIP_ALL, HIP_UPDATE,
                                          challenge_request_UPDATE_states[i],
                                          &handle_challenge_request_param,
                                          20322)) {
@@ -214,7 +214,7 @@
             return -1;
         }
 
-        if (hip_register_handle_function(HIP_UPDATE,
+        if (hip_register_handle_function(HIP_ALL, HIP_UPDATE,
                                          challenge_request_UPDATE_states[i],
                                          &add_host_id_param_update,
                                          20750)) {

=== modified file 'modules/update/hipd/update.c'
--- modules/update/hipd/update.c        2012-05-12 10:21:32 +0000
+++ modules/update/hipd/update.c        2012-07-12 11:32:14 +0000
@@ -84,7 +84,8 @@
                           HIP_UPDATE,
                           0,
                           &ctx->hadb_entry->hit_our,
-                          &ctx->hadb_entry->hit_peer);
+                          &ctx->hadb_entry->hit_peer,
+                          ctx->hadb_entry->hip_version);
 
     return 0;
 }
@@ -723,7 +724,8 @@
                           HIP_UPDATE,
                           0,
                           &hadb_entry->hit_our,
-                          &hadb_entry->hit_peer);
+                          &hadb_entry->hit_peer,
+                          hadb_entry->hip_version);
 
     HIP_IFEL(hip_build_param_esp_info(locator_update_packet,
                                       hadb_entry->current_keymat_index,
@@ -782,195 +784,195 @@
              -1,
              "Error on registering update state uninit function.\n");
 
-    HIP_IFEL(hip_register_handle_function(HIP_R1,
+    HIP_IFEL(hip_register_handle_function(HIP_ALL, HIP_R1,
                                           HIP_STATE_I1_SENT,
                                           &hip_handle_locator, 31500),
              -1, "Error on registering LOCATOR handle function.\n");
-    HIP_IFEL(hip_register_handle_function(HIP_R1,
+    HIP_IFEL(hip_register_handle_function(HIP_ALL, HIP_R1,
                                           HIP_STATE_I2_SENT,
                                           &hip_handle_locator, 31500),
              -1, "Error on registering LOCATOR handle function.\n");
-    HIP_IFEL(hip_register_handle_function(HIP_R1,
+    HIP_IFEL(hip_register_handle_function(HIP_ALL, HIP_R1,
                                           HIP_STATE_CLOSING,
                                           &hip_handle_locator, 31500),
              -1, "Error on registering LOCATOR handle function.\n");
-    HIP_IFEL(hip_register_handle_function(HIP_R1,
+    HIP_IFEL(hip_register_handle_function(HIP_ALL, HIP_R1,
                                           HIP_STATE_CLOSED,
                                           &hip_handle_locator, 31500),
              -1, "Error on registering LOCATOR handle function.\n");
 
-    HIP_IFEL(hip_register_handle_function(HIP_UPDATE,
+    HIP_IFEL(hip_register_handle_function(HIP_ALL, HIP_UPDATE,
                                           HIP_STATE_R2_SENT,
                                           &check_update_freshness,
                                           20000),
              -1, "Error on registering UPDATE handle function.\n");
-    HIP_IFEL(hip_register_handle_function(HIP_UPDATE,
+    HIP_IFEL(hip_register_handle_function(HIP_ALL, HIP_UPDATE,
                                           HIP_STATE_R2_SENT,
                                           &check_update_packet,
                                           20100),
              -1, "Error on registering UPDATE handle function.\n");
-    HIP_IFEL(hip_register_handle_function(HIP_UPDATE,
+    HIP_IFEL(hip_register_handle_function(HIP_ALL, HIP_UPDATE,
                                           HIP_STATE_R2_SENT,
                                           &hip_update_retransmissions,
                                           20150),
              -1, "Error on registering UPDATE handle function.\n");
-    HIP_IFEL(hip_register_handle_function(HIP_UPDATE,
+    HIP_IFEL(hip_register_handle_function(HIP_ALL, HIP_UPDATE,
                                           HIP_STATE_R2_SENT,
                                           &prepare_update_response,
                                           20200),
              -1, "Error on registering UPDATE handle function.\n");
-    HIP_IFEL(hip_register_handle_function(HIP_UPDATE,
+    HIP_IFEL(hip_register_handle_function(HIP_ALL, HIP_UPDATE,
                                           HIP_STATE_R2_SENT,
                                           &hip_add_esp_info_param,
                                           20300),
              -1, "Error on registering UPDATE handle function.\n");
-    HIP_IFEL(hip_register_handle_function(HIP_UPDATE,
+    HIP_IFEL(hip_register_handle_function(HIP_ALL, HIP_UPDATE,
                                           HIP_STATE_R2_SENT,
                                           &hip_handle_esp_info_param,
                                           20400),
              -1, "Error on registering UPDATE handle function.\n");
-    HIP_IFEL(hip_register_handle_function(HIP_UPDATE,
+    HIP_IFEL(hip_register_handle_function(HIP_ALL, HIP_UPDATE,
                                           HIP_STATE_R2_SENT,
                                           &hip_handle_locator_parameter,
                                           20500),
              -1, "Error on registering UPDATE handle function.\n");
-    HIP_IFEL(hip_register_handle_function(HIP_UPDATE,
+    HIP_IFEL(hip_register_handle_function(HIP_ALL, HIP_UPDATE,
                                           HIP_STATE_R2_SENT,
                                           &hip_add_seq_param,
                                           20600),
              -1, "Error on registering UPDATE handle function.\n");
-    HIP_IFEL(hip_register_handle_function(HIP_UPDATE,
+    HIP_IFEL(hip_register_handle_function(HIP_ALL, HIP_UPDATE,
                                           HIP_STATE_R2_SENT,
                                           &hip_handle_seq_param,
                                           20700),
              -1, "Error on registering UPDATE handle function.\n");
-    HIP_IFEL(hip_register_handle_function(HIP_UPDATE,
+    HIP_IFEL(hip_register_handle_function(HIP_ALL, HIP_UPDATE,
                                           HIP_STATE_R2_SENT,
                                           &hip_add_echo_request_param,
                                           20800),
              -1, "Error on registering UPDATE handle function.\n");
-    HIP_IFEL(hip_register_handle_function(HIP_UPDATE,
+    HIP_IFEL(hip_register_handle_function(HIP_ALL, HIP_UPDATE,
                                           HIP_STATE_R2_SENT,
                                           &hip_handle_echo_request_sign_param,
                                           20900),
              -1, "Error on registering UPDATE handle function.\n");
-    HIP_IFEL(hip_register_handle_function(HIP_UPDATE,
+    HIP_IFEL(hip_register_handle_function(HIP_ALL, HIP_UPDATE,
                                           HIP_STATE_R2_SENT,
                                           &hip_mac_and_sign_handler,
                                           29900),
              -1, "Error on registering UPDATE handle function.\n");
-    HIP_IFEL(hip_register_handle_function(HIP_UPDATE,
+    HIP_IFEL(hip_register_handle_function(HIP_ALL, HIP_UPDATE,
                                           HIP_STATE_R2_SENT,
                                           &hip_handle_echo_request_param,
                                           29950),
              -1, "Error on registering UPDATE handle function.\n");
-    HIP_IFEL(hip_register_handle_function(HIP_UPDATE,
+    HIP_IFEL(hip_register_handle_function(HIP_ALL, HIP_UPDATE,
                                           HIP_STATE_R2_SENT,
                                           &delete_ipsec_sa,
                                           29990),
              -1, "Error on registering UPDATE handle function.\n");
-    HIP_IFEL(hip_register_handle_function(HIP_UPDATE,
+    HIP_IFEL(hip_register_handle_function(HIP_ALL, HIP_UPDATE,
                                           HIP_STATE_R2_SENT,
                                           &set_active_addresses,
                                           29999),
              -1, "Error on registering UPDATE handle function.\n");
-    HIP_IFEL(hip_register_handle_function(HIP_UPDATE,
+    HIP_IFEL(hip_register_handle_function(HIP_ALL, HIP_UPDATE,
                                           HIP_STATE_R2_SENT,
                                           &send_update_packet,
                                           30000),
              -1, "Error on registering UPDATE handle function.\n");
-    HIP_IFEL(hip_register_handle_function(HIP_UPDATE,
+    HIP_IFEL(hip_register_handle_function(HIP_ALL, HIP_UPDATE,
                                           HIP_STATE_R2_SENT,
                                           &create_ipsec_sa,
                                           30500),
              -1, "Error on registering UPDATE handle function.\n");
-    HIP_IFEL(hip_register_handle_function(HIP_UPDATE,
+    HIP_IFEL(hip_register_handle_function(HIP_ALL, HIP_UPDATE,
                                           HIP_STATE_R2_SENT,
                                           &update_change_state,
                                           40000),
              -1, "Error on registering UPDATE handle function.\n");
 
-    HIP_IFEL(hip_register_handle_function(HIP_UPDATE,
+    HIP_IFEL(hip_register_handle_function(HIP_ALL, HIP_UPDATE,
                                           HIP_STATE_ESTABLISHED,
                                           &check_update_freshness,
                                           20000),
              -1, "Error on registering UPDATE handle function.\n");
-    HIP_IFEL(hip_register_handle_function(HIP_UPDATE,
+    HIP_IFEL(hip_register_handle_function(HIP_ALL, HIP_UPDATE,
                                           HIP_STATE_ESTABLISHED,
                                           &check_update_packet,
                                           20100),
              -1, "Error on registering UPDATE handle function.\n");
-    HIP_IFEL(hip_register_handle_function(HIP_UPDATE,
+    HIP_IFEL(hip_register_handle_function(HIP_ALL, HIP_UPDATE,
                                           HIP_STATE_ESTABLISHED,
                                           &hip_update_retransmissions,
                                           20150),
              -1, "Error on registering UPDATE handle function.\n");
-    HIP_IFEL(hip_register_handle_function(HIP_UPDATE,
+    HIP_IFEL(hip_register_handle_function(HIP_ALL, HIP_UPDATE,
                                           HIP_STATE_ESTABLISHED,
                                           &prepare_update_response,
                                           20200),
              -1, "Error on registering UPDATE handle function.\n");
-    HIP_IFEL(hip_register_handle_function(HIP_UPDATE,
+    HIP_IFEL(hip_register_handle_function(HIP_ALL, HIP_UPDATE,
                                           HIP_STATE_ESTABLISHED,
                                           &hip_add_esp_info_param,
                                           20300),
              -1, "Error on registering UPDATE handle function.\n");
-    HIP_IFEL(hip_register_handle_function(HIP_UPDATE,
+    HIP_IFEL(hip_register_handle_function(HIP_ALL, HIP_UPDATE,
                                           HIP_STATE_ESTABLISHED,
                                           &hip_handle_esp_info_param,
                                           20400),
              -1, "Error on registering UPDATE handle function.\n");
-    HIP_IFEL(hip_register_handle_function(HIP_UPDATE,
+    HIP_IFEL(hip_register_handle_function(HIP_ALL, HIP_UPDATE,
                                           HIP_STATE_ESTABLISHED,
                                           &hip_handle_locator_parameter,
                                           20500),
              -1, "Error on registering UPDATE handle function.\n");
-    HIP_IFEL(hip_register_handle_function(HIP_UPDATE,
+    HIP_IFEL(hip_register_handle_function(HIP_ALL, HIP_UPDATE,
                                           HIP_STATE_ESTABLISHED,
                                           &hip_add_seq_param,
                                           20600),
              -1, "Error on registering UPDATE handle function.\n");
-    HIP_IFEL(hip_register_handle_function(HIP_UPDATE,
+    HIP_IFEL(hip_register_handle_function(HIP_ALL, HIP_UPDATE,
                                           HIP_STATE_ESTABLISHED,
                                           &hip_handle_seq_param,
                                           20700),
              -1, "Error on registering UPDATE handle function.\n");
-    HIP_IFEL(hip_register_handle_function(HIP_UPDATE,
+    HIP_IFEL(hip_register_handle_function(HIP_ALL, HIP_UPDATE,
                                           HIP_STATE_ESTABLISHED,
                                           &hip_add_echo_request_param,
                                           20800),
              -1, "Error on registering UPDATE handle function.\n");
-    HIP_IFEL(hip_register_handle_function(HIP_UPDATE,
+    HIP_IFEL(hip_register_handle_function(HIP_ALL, HIP_UPDATE,
                                           HIP_STATE_ESTABLISHED,
                                           &hip_handle_echo_request_sign_param,
                                           20900),
              -1, "Error on registering UPDATE handle function.\n");
-    HIP_IFEL(hip_register_handle_function(HIP_UPDATE,
+    HIP_IFEL(hip_register_handle_function(HIP_ALL, HIP_UPDATE,
                                           HIP_STATE_ESTABLISHED,
                                           &hip_mac_and_sign_handler,
                                           29900),
              -1, "Error on registering UPDATE handle function.\n");
-    HIP_IFEL(hip_register_handle_function(HIP_UPDATE,
+    HIP_IFEL(hip_register_handle_function(HIP_ALL, HIP_UPDATE,
                                           HIP_STATE_ESTABLISHED,
                                           &hip_handle_echo_request_param,
                                           29950),
              -1, "Error on registering UPDATE handle function.\n");
-    HIP_IFEL(hip_register_handle_function(HIP_UPDATE,
+    HIP_IFEL(hip_register_handle_function(HIP_ALL, HIP_UPDATE,
                                           HIP_STATE_ESTABLISHED,
                                           &delete_ipsec_sa,
                                           29990),
              -1, "Error on registering UPDATE handle function.\n");
-    HIP_IFEL(hip_register_handle_function(HIP_UPDATE,
+    HIP_IFEL(hip_register_handle_function(HIP_ALL, HIP_UPDATE,
                                           HIP_STATE_ESTABLISHED,
                                           &set_active_addresses,
                                           29999),
              -1, "Error on registering UPDATE handle function.\n");
-    HIP_IFEL(hip_register_handle_function(HIP_UPDATE,
+    HIP_IFEL(hip_register_handle_function(HIP_ALL, HIP_UPDATE,
                                           HIP_STATE_ESTABLISHED,
                                           &send_update_packet,
                                           30000),
              -1, "Error on registering UPDATE handle function.\n");
-    HIP_IFEL(hip_register_handle_function(HIP_UPDATE,
+    HIP_IFEL(hip_register_handle_function(HIP_ALL, HIP_UPDATE,
                                           HIP_STATE_ESTABLISHED,
                                           &create_ipsec_sa,
                                           30500),

=== modified file 'test/libcore/cert.c'
--- test/libcore/cert.c 2012-05-12 06:54:33 +0000
+++ test/libcore/cert.c 2012-06-03 10:26:55 +0000
@@ -164,7 +164,7 @@
                                                    ENCODING_FORMAT_PEM)) != 
NULL,
                 NULL);
     msg = hip_msg_alloc();
-    hip_build_network_hdr(msg, HIP_UPDATE, 0, &in6addr_any, &in6addr_any);
+    hip_build_network_hdr(msg, HIP_UPDATE, 0, &in6addr_any, &in6addr_any, 
HIP_V1);
     fail_unless((len = cert_X509_to_DER(cert, &buf)) > 0, NULL);
     fail_unless(hip_build_param_cert(msg, 0, 1, 1, HIP_CERT_X509V3, buf, len) 
== 0, NULL);
     fail_unless((cert2 = cert_get_X509_from_msg(msg)) != NULL, NULL);

=== modified file 'test/libcore/gpl/pk.c'
--- test/libcore/gpl/pk.c       2012-05-12 06:54:33 +0000
+++ test/libcore/gpl/pk.c       2012-06-03 10:26:55 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011 Aalto University and RWTH Aachen University.
+ * Copyright (c) 2011-2012 Aalto University and RWTH Aachen University.
  *
  * Permission is hereby granted, free of charge, to any person
  * obtaining a copy of this software and associated documentation
@@ -52,7 +52,8 @@
     for (i = 0; i < sizeof(nids) / sizeof(int); i++) {
         eckey = create_ecdsa_key(nids[i]);
         msg   = hip_msg_alloc();
-        hip_build_network_hdr(msg, HIP_UPDATE, 0, &in6addr_any, 
&in6addr_loopback);
+        hip_build_network_hdr(msg, HIP_UPDATE, 0, &in6addr_any,
+                              &in6addr_loopback, HIP_V1);
         hip_build_param_echo(msg, "AAAAA", 5, 1, 1);
 
         fail_unless(hip_ecdsa_sign(eckey, msg) == 0, NULL);
@@ -82,7 +83,8 @@
     }
 
     msg = hip_msg_alloc();
-    hip_build_network_hdr(msg, HIP_UPDATE, 0, &in6addr_any, &in6addr_loopback);
+    hip_build_network_hdr(msg, HIP_UPDATE, 0, &in6addr_any,
+                          &in6addr_loopback, HIP_V1);
     hip_build_param_echo(msg, "AAAAA", 5, 1, 1);
     fail_unless(hip_ecdsa_sign(eckeys[0], msg) == 0, NULL);
 

Other related posts:

  • » [hipl-dev] [Branch ~hipl-core/hipl/trunk] Rev 6388: HIP dual-version support - noreply