KeySync: added device group merge. Builds but still untested. GroupMerge
authorEdouard Tisserant <edouard@pep-project.org>
Thu, 16 Feb 2017 12:43:35 +0100
branchGroupMerge
changeset 1586599deda50386
parent 1585 655cfb838ac6
child 1587 6db4fde2cdae
KeySync: added device group merge. Builds but still untested.
asn.1/devicegroup.asn1
src/sync.h
src/sync_actions.c
src/sync_impl.c
src/sync_impl.h
sync/devicegroup.fsm
sync/gen_actions.ysl2
sync/generated/sync_fsm.c
sync/generated/sync_fsm.h
sync/generated/sync_send_actions.c
sync/skeletons/sync_actions.c
     1.1 --- a/asn.1/devicegroup.asn1	Mon Feb 13 21:26:55 2017 +0100
     1.2 +++ b/asn.1/devicegroup.asn1	Thu Feb 16 12:43:35 2017 +0100
     1.3 @@ -20,6 +20,7 @@
     1.4  
     1.5  GroupKeys ::= SEQUENCE {
     1.6      partner-id     UTF8String  (SIZE(1..1024)) OPTIONAL,
     1.7 +    group-id       UTF8String  (SIZE(1..1024)) OPTIONAL,
     1.8      ownIdentities IdentityList
     1.9  }
    1.10  
     2.1 --- a/src/sync.h	Mon Feb 13 21:26:55 2017 +0100
     2.2 +++ b/src/sync.h	Thu Feb 16 12:43:35 2017 +0100
     2.3 @@ -160,6 +160,13 @@
     2.4          App displays trustwords, and requests user accept or reject
     2.5          App calls deliverHandshakeResult with user's answer
     2.6  
     2.7 +    SYNC_NOTIFY_INIT_MOVE_OUR_DEVICE
     2.8 +        Device (me) is grouped and will leave current group to join another
     2.9 +        device's (partner) group.
    2.10 +        App displays trustwords, and requests user accept or reject
    2.11 +        App calls deliverHandshakeResult with user's answer
    2.12 +
    2.13 +
    2.14      SYNC_NOTIFY_TIMEOUT :
    2.15          KeySync operation timed out.
    2.16          Identities are set reflecting peers involved in aborted operation.
    2.17 @@ -173,6 +180,10 @@
    2.18          New group created.
    2.19          App displays message. No feedback to engine.
    2.20  
    2.21 +    SYNC_NOTIFY_ACCEPTED_DEVICE_MOVED
    2.22 +        New device was moved from one group to another.
    2.23 +        App displays message. No feedback to engine.
    2.24 +
    2.25     To deliver handshake result back to engine once user reacted,
    2.26     deliver_handshake_result is used. Result can be :
    2.27  
    2.28 @@ -224,13 +235,15 @@
    2.29      SYNC_NOTIFY_INIT_ADD_OUR_DEVICE,
    2.30      SYNC_NOTIFY_INIT_ADD_OTHER_DEVICE,
    2.31      SYNC_NOTIFY_INIT_FORM_GROUP,
    2.32 +    SYNC_NOTIFY_INIT_MOVE_OUR_DEVICE,
    2.33  
    2.34      // handshake process timed out
    2.35      SYNC_NOTIFY_TIMEOUT,
    2.36  
    2.37      // handshake accepted by user
    2.38      SYNC_NOTIFY_ACCEPTED_DEVICE_ADDED,
    2.39 -    SYNC_NOTIFY_ACCEPTED_GROUP_CREATED
    2.40 +    SYNC_NOTIFY_ACCEPTED_GROUP_CREATED,
    2.41 +    SYNC_NOTIFY_ACCEPTED_DEVICE_MOVED
    2.42  
    2.43  } sync_handshake_signal;
    2.44  
     3.1 --- a/src/sync_actions.c	Mon Feb 13 21:26:55 2017 +0100
     3.2 +++ b/src/sync_actions.c	Thu Feb 16 12:43:35 2017 +0100
     3.3 @@ -7,6 +7,7 @@
     3.4  #include "pEp_internal.h"
     3.5  #include "message.h"
     3.6  #include "sync_fsm.h"
     3.7 +#include "sync_impl.h"
     3.8  #include "map_asn1.h"
     3.9  #include "baseprotocol.h"
    3.10  
    3.11 @@ -39,15 +40,20 @@
    3.12      if (!(session && partner))
    3.13          return invalid_condition; // error
    3.14  
    3.15 -    // an already existing group always wins
    3.16 +    int partner_is_group = partner->flags & PEP_idf_devicegroup;
    3.17  
    3.18 -    if (deviceGrouped(session)) {
    3.19 -        assert(!(partner->flags & PEP_idf_devicegroup));
    3.20 -        return 1;
    3.21 +    if (deviceGrouped(session)){
    3.22 +        // existing group always wins against sole device
    3.23 +        if(!partner_is_group)
    3.24 +            return 1;
    3.25 +    } else {
    3.26 +        // sole device always loses against group
    3.27 +        if(partner_is_group)
    3.28 +            return 0;
    3.29      }
    3.30  
    3.31 -    if (partner->flags & PEP_idf_devicegroup)
    3.32 -        return 0;
    3.33 +    // two groups or two sole are elected based on key age
    3.34 +    // key created first wins
    3.35  
    3.36      Identity me = NULL;
    3.37      PEP_STATUS status = get_identity(session, partner->address, PEP_OWN_USERID,
    3.38 @@ -205,35 +211,13 @@
    3.39      return status;
    3.40  }
    3.41  
    3.42 -
    3.43 -// storeGroupKeys() - 
    3.44 -//
    3.45 -//  params:
    3.46 -//      session (in)        session handle
    3.47 -//      state (in)          state the state machine is in
    3.48 -//      partner (in)        partner to communicate with
    3.49 -//      _group_keys (in)    group keys received from partner
    3.50 -//
    3.51 -//  returns:
    3.52 -//      PEP_STATUS_OK or any other value on error
    3.53 -
    3.54 -PEP_STATUS storeGroupKeys(
    3.55 +PEP_STATUS _storeGroupKeys(
    3.56          PEP_SESSION session,
    3.57 -        DeviceState_state state,
    3.58 -        Identity partner,
    3.59 -        void *_group_keys
    3.60 +        identity_list *group_keys
    3.61      )
    3.62  {
    3.63      PEP_STATUS status = PEP_STATUS_OK;
    3.64  
    3.65 -    assert(session);
    3.66 -    assert(partner);
    3.67 -    assert(_group_keys);
    3.68 -    if (!(session && partner && _group_keys))
    3.69 -        return PEP_ILLEGAL_VALUE;
    3.70 -
    3.71 -    identity_list *group_keys = (identity_list *) _group_keys;
    3.72 -
    3.73      for (identity_list *il = group_keys; il && il->ident; il = il->next) {
    3.74  
    3.75          // Check that identity isn't excluded from sync.
    3.76 @@ -251,24 +235,113 @@
    3.77          free(il->ident->user_id);
    3.78          il->ident->user_id = strdup(PEP_OWN_USERID);
    3.79          assert(il->ident->user_id);
    3.80 -        if (!il->ident->user_id)
    3.81 -            goto enomem;
    3.82 +        if (!il->ident->user_id){
    3.83 +            status = PEP_OUT_OF_MEMORY;
    3.84 +            break;
    3.85 +        }
    3.86          status = set_identity(session, il->ident);
    3.87          if (status != PEP_STATUS_OK)
    3.88              break;
    3.89      }
    3.90  
    3.91      free_identity_list(group_keys);
    3.92 +    return status;
    3.93 +}
    3.94      
    3.95 +
    3.96 +// storeGroupKeys() - 
    3.97 +//
    3.98 +//  params:
    3.99 +//      session (in)        session handle
   3.100 +//      state (in)          state the state machine is in
   3.101 +//      partner (in)        partner to communicate with
   3.102 +//      _group_keys (in)    group keys received from partner
   3.103 +//
   3.104 +//  returns:
   3.105 +//      PEP_STATUS_OK or any other value on error
   3.106 +
   3.107 +PEP_STATUS storeGroupKeys(
   3.108 +        PEP_SESSION session,
   3.109 +        DeviceState_state state,
   3.110 +        Identity partner,
   3.111 +        void *group_keys_extra_
   3.112 +    )
   3.113 +{
   3.114 +    PEP_STATUS status = PEP_STATUS_OK;
   3.115 +
   3.116 +    assert(session);
   3.117 +    assert(partner);
   3.118 +    assert(group_keys_extra_);
   3.119 +    if (!(session && partner && group_keys_extra_))
   3.120 +        return PEP_ILLEGAL_VALUE;
   3.121 +
   3.122 +    group_keys_extra_t *group_keys_extra = 
   3.123 +        (group_keys_extra_t*) group_keys_extra_;
   3.124 +    identity_list *group_keys = group_keys_extra->group_keys;
   3.125 +    char *group_id = group_keys_extra->group_id;
   3.126 +
   3.127 +    status = _storeGroupKeys(session, group_keys);
   3.128 +    if (status != PEP_STATUS_OK)
   3.129 +        goto exitfree;
   3.130 +
   3.131 +    // set group id according to given group-id
   3.132 +    status = set_device_group(session, group_id);
   3.133 +    if (status != PEP_STATUS_OK)
   3.134 +        goto exitfree;
   3.135 +    
   3.136 +    // change sync_uuid when entering group 
   3.137 +    // thus ignoring unprocessed handshakes
   3.138 +    // addressed to previous self (sole) once in.
   3.139 +    pEpUUID uuid;
   3.140 +    uuid_generate_random(uuid);
   3.141 +    uuid_unparse_upper(uuid, session->sync_uuid);
   3.142 +
   3.143 +exitfree:
   3.144 +    free_identity_list(group_keys);
   3.145 +    free(group_id);
   3.146 +    free(group_keys_extra);
   3.147 +
   3.148      return status;
   3.149 +}
   3.150  
   3.151 -enomem:
   3.152 -    status = PEP_OUT_OF_MEMORY;
   3.153 +// storeGroupUpdate() - 
   3.154 +//
   3.155 +//  params:
   3.156 +//      session (in)        session handle
   3.157 +//      state (in)          state the state machine is in
   3.158 +//      partner (in)        partner to communicate with
   3.159 +//      _group_keys (in)    group keys received from partner
   3.160 +//
   3.161 +//  returns:
   3.162 +//      PEP_STATUS_OK or any other value on error
   3.163 +
   3.164 +PEP_STATUS storeGroupUpdate(
   3.165 +        PEP_SESSION session,
   3.166 +        DeviceState_state state,
   3.167 +        Identity partner,
   3.168 +        void *group_keys_
   3.169 +    )
   3.170 +{
   3.171 +    PEP_STATUS status = PEP_STATUS_OK;
   3.172 +
   3.173 +    assert(session);
   3.174 +    assert(partner);
   3.175 +    assert(group_keys_);
   3.176 +    if (!(session && partner && group_keys_))
   3.177 +        return PEP_ILLEGAL_VALUE;
   3.178 +
   3.179 +    identity_list *group_keys = (identity_list*) group_keys_;
   3.180 +
   3.181 +    status = _storeGroupKeys(session, group_keys);
   3.182 +    if (status != PEP_STATUS_OK)
   3.183 +        goto exitfree;
   3.184 +
   3.185 +exitfree:
   3.186 +
   3.187      free_identity_list(group_keys);
   3.188      return status;
   3.189  }
   3.190 -
   3.191 -// enterGroup() - 
   3.192 +// makeGroup() - 
   3.193  //
   3.194  //  params:
   3.195  //      session (in)        session handle
   3.196 @@ -279,7 +352,7 @@
   3.197  //  returns:
   3.198  //      PEP_STATUS_OK or any other value on error
   3.199  
   3.200 -PEP_STATUS enterGroup(
   3.201 +PEP_STATUS makeGroup(
   3.202          PEP_SESSION session,
   3.203          DeviceState_state state,
   3.204          Identity partner,
   3.205 @@ -290,9 +363,6 @@
   3.206  
   3.207      assert(session);
   3.208  
   3.209 -    // groups have no uuid for now
   3.210 -    status = set_device_group(session, "1");
   3.211 -
   3.212      // change sync_uuid when entering group 
   3.213      // thus ignoring unprocessed handshakes
   3.214      // addressed to previous self (sole) once in.
   3.215 @@ -300,6 +370,9 @@
   3.216      uuid_generate_random(uuid);
   3.217      uuid_unparse_upper(uuid, session->sync_uuid);
   3.218      
   3.219 +    // take that new uuid as group-id
   3.220 +    status = set_device_group(session, session->sync_uuid);
   3.221 +
   3.222      return status;
   3.223  }
   3.224  
     4.1 --- a/src/sync_impl.c	Mon Feb 13 21:26:55 2017 +0100
     4.2 +++ b/src/sync_impl.c	Thu Feb 16 12:43:35 2017 +0100
     4.3 @@ -7,7 +7,6 @@
     4.4  // #define for the dllimport / dllexport DYNAMIC_API stuff.
     4.5  #include "pEp_internal.h"
     4.6  
     4.7 -#include "../asn.1/DeviceGroup-Protocol.h"
     4.8  #include "sync_impl.h"
     4.9  #include "keymanagement.h"
    4.10  #include "message_api.h"
    4.11 @@ -70,6 +69,23 @@
    4.12                      status = PEP_SYNC_ILLEGAL_MESSAGE;
    4.13                      goto error;
    4.14                  }
    4.15 +
    4.16 +                if(msgIsFromGroup) {
    4.17 +                    char *devgrp = NULL;
    4.18 +                    status = get_device_group(session, &devgrp);
    4.19 +
    4.20 +                    // if handshake request comes from same group ignore, ignore it
    4.21 +                    if (status == PEP_STATUS_OK && devgrp && devgrp[0] &&
    4.22 +                        strncmp(devgrp,
    4.23 +                                (const char *)msg->payload.choice.handshakeRequest.group_id->buf,
    4.24 +                                msg->payload.choice.handshakeRequest.group_id->size) != 0){
    4.25 +                        status = PEP_SYNC_ILLEGAL_MESSAGE;
    4.26 +                        goto error;
    4.27 +                    }
    4.28 +                    free(devgrp);
    4.29 +                    // if it comes from another group, then this is groupmerge
    4.30 +                }
    4.31 +
    4.32                  event = HandshakeRequest;
    4.33                  break;
    4.34  
    4.35 @@ -78,6 +94,7 @@
    4.36                  break;
    4.37  
    4.38              case DeviceGroup_Protocol__payload_PR_groupKeys:
    4.39 +            {
    4.40                  // re-check uuid in case sync_uuid changed while in the queue
    4.41                  if (strncmp(session->sync_uuid,
    4.42                              (const char *)msg->payload.choice.groupKeys.partner_id->buf,
    4.43 @@ -85,9 +102,26 @@
    4.44                      status = PEP_SYNC_ILLEGAL_MESSAGE;
    4.45                      goto error;
    4.46                  }
    4.47 -                // no break
    4.48 -            case DeviceGroup_Protocol__payload_PR_groupUpdate:
    4.49 -            {
    4.50 +                group_keys_extra_t *group_keys_extra;
    4.51 +                group_keys_extra = malloc(sizeof(group_keys_extra_t));
    4.52 +                if(group_keys_extra == NULL){
    4.53 +                    status = PEP_OUT_OF_MEMORY;
    4.54 +                    ASN_STRUCT_FREE(asn_DEF_DeviceGroup_Protocol, msg);
    4.55 +                    goto error;
    4.56 +                }
    4.57 +
    4.58 +                char *group_id = strndup(
    4.59 +                        (char*)msg->payload.choice.groupKeys.group_id->buf,
    4.60 +                        msg->payload.choice.groupKeys.group_id->size);
    4.61 +
    4.62 +                if (msg->payload.choice.groupKeys.group_id && !group_id){
    4.63 +                    status = PEP_OUT_OF_MEMORY;
    4.64 +                    free(group_keys_extra);
    4.65 +                    ASN_STRUCT_FREE(asn_DEF_DeviceGroup_Protocol, msg);
    4.66 +                    goto error;
    4.67 +                }
    4.68 +                group_keys_extra->group_id = group_id;
    4.69 +
    4.70                  identity_list *group_keys = IdentityList_to_identity_list(
    4.71                          msg->payload.present == 
    4.72                            DeviceGroup_Protocol__payload_PR_groupKeys ?
    4.73 @@ -96,13 +130,28 @@
    4.74                          NULL);
    4.75                  if (!group_keys) {
    4.76                      status = PEP_OUT_OF_MEMORY;
    4.77 +                    free(group_id);
    4.78 +                    free(group_keys_extra);
    4.79 +                    ASN_STRUCT_FREE(asn_DEF_DeviceGroup_Protocol, msg);
    4.80 +                    goto error;
    4.81 +                }
    4.82 +                group_keys_extra->group_keys = group_keys;
    4.83 +
    4.84 +                extra = (void *) group_keys_extra;
    4.85 +
    4.86 +                break;
    4.87 +            }
    4.88 +            case DeviceGroup_Protocol__payload_PR_groupUpdate:
    4.89 +            {
    4.90 +                identity_list *group_keys = IdentityList_to_identity_list(
    4.91 +                        &msg->payload.choice.groupUpdate.ownIdentities, NULL);
    4.92 +                if (!group_keys) {
    4.93 +                    status = PEP_OUT_OF_MEMORY;
    4.94                      ASN_STRUCT_FREE(asn_DEF_DeviceGroup_Protocol, msg);
    4.95                      goto error;
    4.96                  }
    4.97                  extra = (void *) group_keys;
    4.98 -                event = msg->payload.present == 
    4.99 -                          DeviceGroup_Protocol__payload_PR_groupKeys ?
   4.100 -                            GroupKeys : GroupUpdate;
   4.101 +                event = GroupUpdate;
   4.102                  break;
   4.103              }
   4.104  
     5.1 --- a/src/sync_impl.h	Mon Feb 13 21:26:55 2017 +0100
     5.2 +++ b/src/sync_impl.h	Thu Feb 16 12:43:35 2017 +0100
     5.3 @@ -3,6 +3,7 @@
     5.4  
     5.5  #pragma once
     5.6  
     5.7 +#include "../asn.1/DeviceGroup-Protocol.h"
     5.8  #include "message.h"
     5.9  #include "sync.h"
    5.10  #include "sync_fsm.h"
    5.11 @@ -11,6 +12,11 @@
    5.12  extern "C" {
    5.13  #endif
    5.14  
    5.15 +typedef struct _group_keys_extra {
    5.16 +    identity_list *group_keys;
    5.17 +    char *group_id;
    5.18 +} group_keys_extra_t;
    5.19 +
    5.20  PEP_STATUS receive_sync_msg(
    5.21          PEP_SESSION session,
    5.22          sync_msg_t *sync_msg,
     6.1 --- a/sync/devicegroup.fsm	Mon Feb 13 21:26:55 2017 +0100
     6.2 +++ b/sync/devicegroup.fsm	Thu Feb 16 12:43:35 2017 +0100
     6.3 @@ -84,7 +84,7 @@
     6.4              on HandshakeAccepted(Identity partner) {
     6.5                  do acceptHandshake(partner); 
     6.6                  if keyElectionWon(partner) {
     6.7 -                    do enterGroup;
     6.8 +                    do makeGroup;
     6.9                      do sendGroupKeys(partner);
    6.10                      do notifyAcceptedGroupCreated(partner);
    6.11                      go Grouped;
    6.12 @@ -103,7 +103,6 @@
    6.13              on GroupKeys(Identity partner, Stringlist keys) {
    6.14                  if sameIdentities(partner, expected) {
    6.15                      do storeGroupKeys(partner, keys);
    6.16 -                    do enterGroup;
    6.17                      do sendGroupUpdate;
    6.18                      do notifyAcceptedDeviceAdded(partner);
    6.19                      go Grouped;
    6.20 @@ -118,8 +117,10 @@
    6.21          state Grouped end=1 {
    6.22              on KeyGen
    6.23                  do sendGroupUpdate;
    6.24 -            on CannotDecrypt
    6.25 +            on CannotDecrypt {
    6.26                  do sendUpdateRequest;
    6.27 +                do sendBeacon;
    6.28 +            }
    6.29              on UpdateRequest
    6.30                  do sendGroupUpdate;
    6.31              on Beacon(Identity partner){
    6.32 @@ -131,14 +132,16 @@
    6.33                  go HandshakingGrouped(partner);
    6.34              }
    6.35              on GroupUpdate(Identity partner, Stringlist keys)
    6.36 -                do storeGroupKeys(partner, keys);
    6.37 +                do storeGroupUpdate(partner, keys);
    6.38          }
    6.39  
    6.40          state GroupedBeaconed timeout=600 (Identity expected){
    6.41              on KeyGen
    6.42                  do sendGroupUpdate;
    6.43 -            on CannotDecrypt
    6.44 +            on CannotDecrypt {
    6.45                  do sendUpdateRequest;
    6.46 +                do sendBeacon;
    6.47 +            }
    6.48              on UpdateRequest
    6.49                  do sendGroupUpdate;
    6.50              on Beacon(Identity partner){
    6.51 @@ -159,21 +162,43 @@
    6.52          }
    6.53  
    6.54          state HandshakingGrouped timeout=600 (Identity expected) {
    6.55 -            on Init
    6.56 -                do notifyInitAddOurDevice(partner);
    6.57 +            // HandshakeRequest from same group are filtered in receive_sync_msg
    6.58 +            on Init{
    6.59 +                if keyElectionWon(partner) {
    6.60 +                    do notifyInitAddOtherDevice(partner);
    6.61 +                } else {
    6.62 +                    do notifyInitMoveOurDevice(partner);
    6.63 +                }
    6.64 +            }
    6.65              on HandshakeRejected(Identity partner) {
    6.66                  do rejectHandshake(partner);             // stores rejection of partner
    6.67                  go Grouped;
    6.68              }
    6.69              on HandshakeAccepted(Identity partner) {
    6.70                  do acceptHandshake(partner); 
    6.71 -
    6.72 -                // an already existing group always wins
    6.73 -                do sendGroupKeys(partner);
    6.74 -
    6.75 +                if keyElectionWon(partner) {
    6.76 +                    do sendGroupKeys(partner);
    6.77 +                    do notifyAcceptedDeviceAdded(partner);
    6.78 +                    go Grouped;
    6.79 +                }
    6.80 +                go WaitForGroupKeysGrouped(partner);
    6.81 +            }
    6.82 +            on Cancel go Grouped;
    6.83 +            on Timeout {
    6.84 +                do notifyTimeout(expected);
    6.85                  go Grouped;
    6.86              }
    6.87 -            on Cancel go Grouped;
    6.88 +        }
    6.89 +
    6.90 +        state WaitForGroupKeysGrouped timeout=600 (Identity expected) {
    6.91 +            on GroupKeys(Identity partner, Stringlist keys) {
    6.92 +                if sameIdentities(partner, expected) {
    6.93 +                    do storeGroupKeys(partner, keys);
    6.94 +                    do sendGroupUpdate;
    6.95 +                    do notifyAcceptedDeviceMoved(partner);
    6.96 +                    go Grouped;
    6.97 +                }
    6.98 +            }
    6.99              on Timeout {
   6.100                  do notifyTimeout(expected);
   6.101                  go Grouped;
     7.1 --- a/sync/gen_actions.ysl2	Mon Feb 13 21:26:55 2017 +0100
     7.2 +++ b/sync/gen_actions.ysl2	Thu Feb 16 12:43:35 2017 +0100
     7.3 @@ -203,6 +203,16 @@
     7.4                  |>                              partner->user_id, -1);
     7.5                  |> if (partner->user_id && !msg->payload.choice.«$lname».partner_id)
     7.6                  |>    goto enomem;
     7.7 +                |
     7.8 +                |> char *devgrp = NULL;
     7.9 +                |> status = get_device_group(session, &devgrp);
    7.10 +                |> if (status == PEP_STATUS_OK && devgrp && devgrp[0])
    7.11 +                |> msg->payload.choice.«$lname».group_id = 
    7.12 +                |>     OCTET_STRING_new_fromBuf(&asn_DEF_UTF8String,
    7.13 +                |>                              devgrp, -1);
    7.14 +                |> free(devgrp);
    7.15 +                |> if (devgrp && !msg->payload.choice.«$lname».partner_id)
    7.16 +                |>    goto enomem;
    7.17              }
    7.18          }
    7.19          ||
     8.1 --- a/sync/generated/sync_fsm.c	Mon Feb 13 21:26:55 2017 +0100
     8.2 +++ b/sync/generated/sync_fsm.c	Thu Feb 16 12:43:35 2017 +0100
     8.3 @@ -272,8 +272,8 @@
     8.4                      if (cond_result < 0)
     8.5                          return cond_result;
     8.6                      if (cond_result) {
     8.7 -                        DEBUG_LOG("FSM action", "sync_fsm.c, state=HandshakingSole, event=HandshakeAccepted", "action=enterGroup")
     8.8 -                        status = enterGroup(session, state, NULL, NULL);
     8.9 +                        DEBUG_LOG("FSM action", "sync_fsm.c, state=HandshakingSole, event=HandshakeAccepted", "action=makeGroup")
    8.10 +                        status = makeGroup(session, state, NULL, NULL);
    8.11                          if (status == PEP_OUT_OF_MEMORY)
    8.12                              return (int) invalid_out_of_memory;
    8.13                          if (status != PEP_STATUS_OK)
    8.14 @@ -367,12 +367,6 @@
    8.15                              return (int) invalid_out_of_memory;
    8.16                          if (status != PEP_STATUS_OK)
    8.17                              return (int) invalid_action;
    8.18 -                        DEBUG_LOG("FSM action", "sync_fsm.c, state=WaitForGroupKeysSole, event=GroupKeys", "action=enterGroup")
    8.19 -                        status = enterGroup(session, state, NULL, NULL);
    8.20 -                        if (status == PEP_OUT_OF_MEMORY)
    8.21 -                            return (int) invalid_out_of_memory;
    8.22 -                        if (status != PEP_STATUS_OK)
    8.23 -                            return (int) invalid_action;
    8.24                          DEBUG_LOG("FSM action", "sync_fsm.c, state=WaitForGroupKeysSole, event=GroupKeys", "action=sendGroupUpdate")
    8.25                          status = sendGroupUpdate(session, state, NULL, NULL);
    8.26                          if (status == PEP_OUT_OF_MEMORY)
    8.27 @@ -441,6 +435,12 @@
    8.28                          return (int) invalid_out_of_memory;
    8.29                      if (status != PEP_STATUS_OK)
    8.30                          return (int) invalid_action;
    8.31 +                    DEBUG_LOG("FSM action", "sync_fsm.c, state=Grouped, event=CannotDecrypt", "action=sendBeacon")
    8.32 +                    status = sendBeacon(session, state, NULL, NULL);
    8.33 +                    if (status == PEP_OUT_OF_MEMORY)
    8.34 +                        return (int) invalid_out_of_memory;
    8.35 +                    if (status != PEP_STATUS_OK)
    8.36 +                        return (int) invalid_action;
    8.37                      break;
    8.38                  }
    8.39                  case UpdateRequest:
    8.40 @@ -483,8 +483,8 @@
    8.41                  case GroupUpdate:
    8.42                  {
    8.43                      DEBUG_LOG("FSM event", "sync_fsm.c, state=Grouped", "event=GroupUpdate")
    8.44 -                    DEBUG_LOG("FSM action", "sync_fsm.c, state=Grouped, event=GroupUpdate", "action=storeGroupKeys")
    8.45 -                    status = storeGroupKeys(session, state, partner, extra /*keys*/);
    8.46 +                    DEBUG_LOG("FSM action", "sync_fsm.c, state=Grouped, event=GroupUpdate", "action=storeGroupUpdate")
    8.47 +                    status = storeGroupUpdate(session, state, partner, extra /*keys*/);
    8.48                      if (status == PEP_OUT_OF_MEMORY)
    8.49                          return (int) invalid_out_of_memory;
    8.50                      if (status != PEP_STATUS_OK)
    8.51 @@ -523,6 +523,12 @@
    8.52                          return (int) invalid_out_of_memory;
    8.53                      if (status != PEP_STATUS_OK)
    8.54                          return (int) invalid_action;
    8.55 +                    DEBUG_LOG("FSM action", "sync_fsm.c, state=GroupedBeaconed, event=CannotDecrypt", "action=sendBeacon")
    8.56 +                    status = sendBeacon(session, state, NULL, NULL);
    8.57 +                    if (status == PEP_OUT_OF_MEMORY)
    8.58 +                        return (int) invalid_out_of_memory;
    8.59 +                    if (status != PEP_STATUS_OK)
    8.60 +                        return (int) invalid_action;
    8.61                      break;
    8.62                  }
    8.63                  case UpdateRequest:
    8.64 @@ -617,12 +623,30 @@
    8.65                  case Init:
    8.66                  {
    8.67                      DEBUG_LOG("FSM event", "sync_fsm.c, state=HandshakingGrouped", "event=Init")
    8.68 -                    DEBUG_LOG("FSM action", "sync_fsm.c, state=HandshakingGrouped, event=Init", "action=notifyInitAddOurDevice")
    8.69 -                    status = notifyInitAddOurDevice(session, state, partner, NULL);
    8.70 -                    if (status == PEP_OUT_OF_MEMORY)
    8.71 -                        return (int) invalid_out_of_memory;
    8.72 -                    if (status != PEP_STATUS_OK)
    8.73 -                        return (int) invalid_action;
    8.74 +                    cond_result = keyElectionWon(session, partner);
    8.75 +                    #ifndef NDEBUG
    8.76 +                    char resstr[11] = {0,};
    8.77 +                    snprintf(resstr,10,"result=%d",cond_result);
    8.78 +                    #endif
    8.79 +                    DEBUG_LOG("FSM condition", "sync_fsm.c, state=HandshakingGrouped, event=Init, condition=keyElectionWon", resstr)
    8.80 +                    if (cond_result < 0)
    8.81 +                        return cond_result;
    8.82 +                    if (cond_result) {
    8.83 +                        DEBUG_LOG("FSM action", "sync_fsm.c, state=HandshakingGrouped, event=Init", "action=notifyInitAddOtherDevice")
    8.84 +                        status = notifyInitAddOtherDevice(session, state, partner, NULL);
    8.85 +                        if (status == PEP_OUT_OF_MEMORY)
    8.86 +                            return (int) invalid_out_of_memory;
    8.87 +                        if (status != PEP_STATUS_OK)
    8.88 +                            return (int) invalid_action;
    8.89 +                    }
    8.90 +                    else {
    8.91 +                        DEBUG_LOG("FSM action", "sync_fsm.c, state=HandshakingGrouped, event=Init", "action=notifyInitMoveOurDevice")
    8.92 +                        status = notifyInitMoveOurDevice(session, state, partner, NULL);
    8.93 +                        if (status == PEP_OUT_OF_MEMORY)
    8.94 +                            return (int) invalid_out_of_memory;
    8.95 +                        if (status != PEP_STATUS_OK)
    8.96 +                            return (int) invalid_action;
    8.97 +                    }
    8.98                      break;
    8.99                  }
   8.100                  case HandshakeRejected:
   8.101 @@ -650,18 +674,41 @@
   8.102                          return (int) invalid_out_of_memory;
   8.103                      if (status != PEP_STATUS_OK)
   8.104                          return (int) invalid_action;
   8.105 -                    DEBUG_LOG("FSM action", "sync_fsm.c, state=HandshakingGrouped, event=HandshakeAccepted", "action=sendGroupKeys")
   8.106 -                    status = sendGroupKeys(session, state, partner, NULL);
   8.107 -                    if (status == PEP_OUT_OF_MEMORY)
   8.108 -                        return (int) invalid_out_of_memory;
   8.109 -                    if (status != PEP_STATUS_OK)
   8.110 -                        return (int) invalid_action;
   8.111 +                    cond_result = keyElectionWon(session, partner);
   8.112 +                    #ifndef NDEBUG
   8.113 +                    char resstr[11] = {0,};
   8.114 +                    snprintf(resstr,10,"result=%d",cond_result);
   8.115 +                    #endif
   8.116 +                    DEBUG_LOG("FSM condition", "sync_fsm.c, state=HandshakingGrouped, event=HandshakeAccepted, condition=keyElectionWon", resstr)
   8.117 +                    if (cond_result < 0)
   8.118 +                        return cond_result;
   8.119 +                    if (cond_result) {
   8.120 +                        DEBUG_LOG("FSM action", "sync_fsm.c, state=HandshakingGrouped, event=HandshakeAccepted", "action=sendGroupKeys")
   8.121 +                        status = sendGroupKeys(session, state, partner, NULL);
   8.122 +                        if (status == PEP_OUT_OF_MEMORY)
   8.123 +                            return (int) invalid_out_of_memory;
   8.124 +                        if (status != PEP_STATUS_OK)
   8.125 +                            return (int) invalid_action;
   8.126 +                        DEBUG_LOG("FSM action", "sync_fsm.c, state=HandshakingGrouped, event=HandshakeAccepted", "action=notifyAcceptedDeviceAdded")
   8.127 +                        status = notifyAcceptedDeviceAdded(session, state, partner, NULL);
   8.128 +                        if (status == PEP_OUT_OF_MEMORY)
   8.129 +                            return (int) invalid_out_of_memory;
   8.130 +                        if (status != PEP_STATUS_OK)
   8.131 +                            return (int) invalid_action;
   8.132 +                        if(session->sync_state_payload){
   8.133 +                            free_identity((Identity)session->sync_state_payload);
   8.134 +                            session->sync_state_payload = NULL;
   8.135 +                        }
   8.136 +                        DEBUG_LOG("FSM transition", "sync_fsm.c, state=HandshakingGrouped, event=HandshakeAccepted", "target=Grouped")
   8.137 +                        return Grouped;
   8.138 +                    }
   8.139                      if(session->sync_state_payload){
   8.140                          free_identity((Identity)session->sync_state_payload);
   8.141                          session->sync_state_payload = NULL;
   8.142                      }
   8.143 -                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=HandshakingGrouped, event=HandshakeAccepted", "target=Grouped")
   8.144 -                    return Grouped;
   8.145 +                    session->sync_state_payload = identity_dup(partner);
   8.146 +                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=HandshakingGrouped, event=HandshakeAccepted", "target=WaitForGroupKeysGrouped")
   8.147 +                    return WaitForGroupKeysGrouped;
   8.148                  }
   8.149                  case Cancel:
   8.150                  {
   8.151 @@ -694,6 +741,73 @@
   8.152              }
   8.153              break;
   8.154          }
   8.155 +        case WaitForGroupKeysGrouped:
   8.156 +        {
   8.157 +            Identity expected = (Identity)session->sync_state_payload;
   8.158 +            *timeout = 600;
   8.159 +            DEBUG_LOG("Entering FSM state", "sync_fsm.c", "state=WaitForGroupKeysGrouped")
   8.160 +            switch (event) {
   8.161 +                case Init: DEBUG_LOG("FSM event", "sync_fsm.c, state=WaitForGroupKeysGrouped", "event=Init") break;
   8.162 +                case GroupKeys:
   8.163 +                {
   8.164 +                    DEBUG_LOG("FSM event", "sync_fsm.c, state=WaitForGroupKeysGrouped", "event=GroupKeys")
   8.165 +                    cond_result = sameIdentities(session, partner, expected);
   8.166 +                    #ifndef NDEBUG
   8.167 +                    char resstr[11] = {0,};
   8.168 +                    snprintf(resstr,10,"result=%d",cond_result);
   8.169 +                    #endif
   8.170 +                    DEBUG_LOG("FSM condition", "sync_fsm.c, state=WaitForGroupKeysGrouped, event=GroupKeys, condition=sameIdentities", resstr)
   8.171 +                    if (cond_result < 0)
   8.172 +                        return cond_result;
   8.173 +                    if (cond_result) {
   8.174 +                        DEBUG_LOG("FSM action", "sync_fsm.c, state=WaitForGroupKeysGrouped, event=GroupKeys", "action=storeGroupKeys")
   8.175 +                        status = storeGroupKeys(session, state, partner, extra /*keys*/);
   8.176 +                        if (status == PEP_OUT_OF_MEMORY)
   8.177 +                            return (int) invalid_out_of_memory;
   8.178 +                        if (status != PEP_STATUS_OK)
   8.179 +                            return (int) invalid_action;
   8.180 +                        DEBUG_LOG("FSM action", "sync_fsm.c, state=WaitForGroupKeysGrouped, event=GroupKeys", "action=sendGroupUpdate")
   8.181 +                        status = sendGroupUpdate(session, state, NULL, NULL);
   8.182 +                        if (status == PEP_OUT_OF_MEMORY)
   8.183 +                            return (int) invalid_out_of_memory;
   8.184 +                        if (status != PEP_STATUS_OK)
   8.185 +                            return (int) invalid_action;
   8.186 +                        DEBUG_LOG("FSM action", "sync_fsm.c, state=WaitForGroupKeysGrouped, event=GroupKeys", "action=notifyAcceptedDeviceMoved")
   8.187 +                        status = notifyAcceptedDeviceMoved(session, state, partner, NULL);
   8.188 +                        if (status == PEP_OUT_OF_MEMORY)
   8.189 +                            return (int) invalid_out_of_memory;
   8.190 +                        if (status != PEP_STATUS_OK)
   8.191 +                            return (int) invalid_action;
   8.192 +                        if(session->sync_state_payload){
   8.193 +                            free_identity((Identity)session->sync_state_payload);
   8.194 +                            session->sync_state_payload = NULL;
   8.195 +                        }
   8.196 +                        DEBUG_LOG("FSM transition", "sync_fsm.c, state=WaitForGroupKeysGrouped, event=GroupKeys", "target=Grouped")
   8.197 +                        return Grouped;
   8.198 +                    }
   8.199 +                    break;
   8.200 +                }
   8.201 +                case Timeout:
   8.202 +                {
   8.203 +                    DEBUG_LOG("FSM event", "sync_fsm.c, state=WaitForGroupKeysGrouped", "event=Timeout")
   8.204 +                    DEBUG_LOG("FSM action", "sync_fsm.c, state=WaitForGroupKeysGrouped, event=Timeout", "action=notifyTimeout")
   8.205 +                    status = notifyTimeout(session, state, expected, NULL);
   8.206 +                    if (status == PEP_OUT_OF_MEMORY)
   8.207 +                        return (int) invalid_out_of_memory;
   8.208 +                    if (status != PEP_STATUS_OK)
   8.209 +                        return (int) invalid_action;
   8.210 +                    if(session->sync_state_payload){
   8.211 +                        free_identity((Identity)session->sync_state_payload);
   8.212 +                        session->sync_state_payload = NULL;
   8.213 +                    }
   8.214 +                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=WaitForGroupKeysGrouped, event=Timeout", "target=Grouped")
   8.215 +                    return Grouped;
   8.216 +                }
   8.217 +                default:
   8.218 +                    return (DeviceState_state) invalid_event;
   8.219 +            }
   8.220 +            break;
   8.221 +        }
   8.222          default:
   8.223              return (DeviceState_state) invalid_state;
   8.224      }
     9.1 --- a/sync/generated/sync_fsm.h	Mon Feb 13 21:26:55 2017 +0100
     9.2 +++ b/sync/generated/sync_fsm.h	Thu Feb 16 12:43:35 2017 +0100
     9.3 @@ -52,7 +52,8 @@
     9.4      WaitForGroupKeysSole, 
     9.5      Grouped, 
     9.6      GroupedBeaconed, 
     9.7 -    HandshakingGrouped
     9.8 +    HandshakingGrouped, 
     9.9 +    WaitForGroupKeysGrouped
    9.10  } DeviceState_state;
    9.11  
    9.12  // events
    9.13 @@ -81,7 +82,7 @@
    9.14  PEP_STATUS notifyInitAddOurDevice(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
    9.15  PEP_STATUS rejectHandshake(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
    9.16  PEP_STATUS acceptHandshake(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
    9.17 -PEP_STATUS enterGroup(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
    9.18 +PEP_STATUS makeGroup(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
    9.19  PEP_STATUS sendGroupKeys(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
    9.20  PEP_STATUS notifyAcceptedGroupCreated(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
    9.21  PEP_STATUS notifyTimeout(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
    9.22 @@ -89,6 +90,10 @@
    9.23  PEP_STATUS sendGroupUpdate(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
    9.24  PEP_STATUS notifyAcceptedDeviceAdded(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
    9.25  PEP_STATUS sendUpdateRequest(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
    9.26 +PEP_STATUS storeGroupUpdate(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
    9.27 +PEP_STATUS notifyInitAddOtherDevice(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
    9.28 +PEP_STATUS notifyInitMoveOurDevice(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
    9.29 +PEP_STATUS notifyAcceptedDeviceMoved(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
    9.30  
    9.31  // event injector
    9.32  
    10.1 --- a/sync/generated/sync_send_actions.c	Mon Feb 13 21:26:55 2017 +0100
    10.2 +++ b/sync/generated/sync_send_actions.c	Thu Feb 16 12:43:35 2017 +0100
    10.3 @@ -92,6 +92,16 @@
    10.4      if (partner->user_id && !msg->payload.choice.handshakeRequest.partner_id)
    10.5         goto enomem;
    10.6  
    10.7 +    char *devgrp = NULL;
    10.8 +    status = get_device_group(session, &devgrp);
    10.9 +    if (status == PEP_STATUS_OK && devgrp && devgrp[0])
   10.10 +    msg->payload.choice.handshakeRequest.group_id = 
   10.11 +        OCTET_STRING_new_fromBuf(&asn_DEF_UTF8String,
   10.12 +                                 devgrp, -1);
   10.13 +    free(devgrp);
   10.14 +    if (devgrp && !msg->payload.choice.handshakeRequest.partner_id)
   10.15 +       goto enomem;
   10.16 +
   10.17      bool encrypted = true;
   10.18      status = unicast_msg(session, partner, state, msg, encrypted);
   10.19      if (status != PEP_STATUS_OK)
   10.20 @@ -148,6 +158,16 @@
   10.21      if (partner->user_id && !msg->payload.choice.groupKeys.partner_id)
   10.22         goto enomem;
   10.23  
   10.24 +    char *devgrp = NULL;
   10.25 +    status = get_device_group(session, &devgrp);
   10.26 +    if (status == PEP_STATUS_OK && devgrp && devgrp[0])
   10.27 +    msg->payload.choice.groupKeys.group_id = 
   10.28 +        OCTET_STRING_new_fromBuf(&asn_DEF_UTF8String,
   10.29 +                                 devgrp, -1);
   10.30 +    free(devgrp);
   10.31 +    if (devgrp && !msg->payload.choice.groupKeys.partner_id)
   10.32 +       goto enomem;
   10.33 +
   10.34      bool encrypted = true;
   10.35      status = unicast_msg(session, partner, state, msg, encrypted);
   10.36      if (status != PEP_STATUS_OK)
   10.37 @@ -395,3 +415,81 @@
   10.38      return _notifyHandshake(session, partner, SYNC_NOTIFY_ACCEPTED_DEVICE_ADDED);
   10.39  }
   10.40  
   10.41 +
   10.42 +// notifyInitAddOtherDevice() - notify InitAddOtherDevice to app
   10.43 +//
   10.44 +//  params:
   10.45 +//      session (in)        session handle
   10.46 +//      state (in)          state the state machine is in
   10.47 +//      partner (in)        partner to communicate with
   10.48 +//
   10.49 +//  returns:
   10.50 +//      PEP_STATUS_OK or any other value on error
   10.51 +
   10.52 +PEP_STATUS notifyInitAddOtherDevice(
   10.53 +        PEP_SESSION session,
   10.54 +        DeviceState_state state,
   10.55 +        Identity partner,
   10.56 +        void *extra
   10.57 +    )
   10.58 +{
   10.59 +    assert(session && state);
   10.60 +    assert(extra == NULL);
   10.61 +    if (!(session && state && extra == NULL))
   10.62 +        return PEP_ILLEGAL_VALUE;
   10.63 +
   10.64 +    return _notifyHandshake(session, partner, SYNC_NOTIFY_INIT_ADD_OTHER_DEVICE);
   10.65 +}
   10.66 +
   10.67 +
   10.68 +// notifyInitMoveOurDevice() - notify InitMoveOurDevice to app
   10.69 +//
   10.70 +//  params:
   10.71 +//      session (in)        session handle
   10.72 +//      state (in)          state the state machine is in
   10.73 +//      partner (in)        partner to communicate with
   10.74 +//
   10.75 +//  returns:
   10.76 +//      PEP_STATUS_OK or any other value on error
   10.77 +
   10.78 +PEP_STATUS notifyInitMoveOurDevice(
   10.79 +        PEP_SESSION session,
   10.80 +        DeviceState_state state,
   10.81 +        Identity partner,
   10.82 +        void *extra
   10.83 +    )
   10.84 +{
   10.85 +    assert(session && state);
   10.86 +    assert(extra == NULL);
   10.87 +    if (!(session && state && extra == NULL))
   10.88 +        return PEP_ILLEGAL_VALUE;
   10.89 +
   10.90 +    return _notifyHandshake(session, partner, SYNC_NOTIFY_INIT_MOVE_OUR_DEVICE);
   10.91 +}
   10.92 +
   10.93 +
   10.94 +// notifyAcceptedDeviceMoved() - notify AcceptedDeviceMoved to app
   10.95 +//
   10.96 +//  params:
   10.97 +//      session (in)        session handle
   10.98 +//      state (in)          state the state machine is in
   10.99 +//      partner (in)        partner to communicate with
  10.100 +//
  10.101 +//  returns:
  10.102 +//      PEP_STATUS_OK or any other value on error
  10.103 +
  10.104 +PEP_STATUS notifyAcceptedDeviceMoved(
  10.105 +        PEP_SESSION session,
  10.106 +        DeviceState_state state,
  10.107 +        Identity partner,
  10.108 +        void *extra
  10.109 +    )
  10.110 +{
  10.111 +    assert(session && state);
  10.112 +    assert(extra == NULL);
  10.113 +    if (!(session && state && extra == NULL))
  10.114 +        return PEP_ILLEGAL_VALUE;
  10.115 +
  10.116 +    return _notifyHandshake(session, partner, SYNC_NOTIFY_ACCEPTED_DEVICE_MOVED);
  10.117 +}
  10.118 +
    11.1 --- a/sync/skeletons/sync_actions.c	Mon Feb 13 21:26:55 2017 +0100
    11.2 +++ b/sync/skeletons/sync_actions.c	Thu Feb 16 12:43:35 2017 +0100
    11.3 @@ -156,7 +156,7 @@
    11.4  }
    11.5  
    11.6  
    11.7 -// enterGroup() - 
    11.8 +// makeGroup() - 
    11.9  //
   11.10  //  params:
   11.11  //      session (in)        session handle
   11.12 @@ -166,7 +166,7 @@
   11.13  //  returns:
   11.14  //      PEP_STATUS_OK or any other value on error
   11.15  
   11.16 -PEP_STATUS enterGroup(
   11.17 +PEP_STATUS makeGroup(
   11.18          PEP_SESSION session,
   11.19          DeviceState_state state,
   11.20          Identity partner,
   11.21 @@ -340,3 +340,151 @@
   11.22      return status;
   11.23  }
   11.24  
   11.25 +
   11.26 +// storeGroupUpdate() - 
   11.27 +//
   11.28 +//  params:
   11.29 +//      session (in)        session handle
   11.30 +//      state (in)          state the state machine is in
   11.31 +//      partner (in)        partner to communicate with
   11.32 +//
   11.33 +//  returns:
   11.34 +//      PEP_STATUS_OK or any other value on error
   11.35 +
   11.36 +PEP_STATUS storeGroupUpdate(
   11.37 +        PEP_SESSION session,
   11.38 +        DeviceState_state state,
   11.39 +        Identity partner,
   11.40 +        void *extra
   11.41 +    )
   11.42 +{
   11.43 +    PEP_STATUS status = PEP_STATUS_OK;
   11.44 +
   11.45 +    assert(session);
   11.46 +    assert(partner);
   11.47 +    if (!(session && partner))
   11.48 +        return PEP_ILLEGAL_VALUE;
   11.49 +
   11.50 +    // working code
   11.51 +
   11.52 +    // free extra
   11.53 +    return status;
   11.54 +
   11.55 +enomem:
   11.56 +    status = PEP_OUT_OF_MEMORY;
   11.57 +error:
   11.58 +    // free extra
   11.59 +    return status;
   11.60 +}
   11.61 +
   11.62 +
   11.63 +// notifyInitAddOtherDevice() - 
   11.64 +//
   11.65 +//  params:
   11.66 +//      session (in)        session handle
   11.67 +//      state (in)          state the state machine is in
   11.68 +//      partner (in)        partner to communicate with
   11.69 +//
   11.70 +//  returns:
   11.71 +//      PEP_STATUS_OK or any other value on error
   11.72 +
   11.73 +PEP_STATUS notifyInitAddOtherDevice(
   11.74 +        PEP_SESSION session,
   11.75 +        DeviceState_state state,
   11.76 +        Identity partner,
   11.77 +        void *extra
   11.78 +    )
   11.79 +{
   11.80 +    PEP_STATUS status = PEP_STATUS_OK;
   11.81 +
   11.82 +    assert(session);
   11.83 +    assert(partner);
   11.84 +    if (!(session && partner))
   11.85 +        return PEP_ILLEGAL_VALUE;
   11.86 +
   11.87 +    // working code
   11.88 +
   11.89 +    // free extra
   11.90 +    return status;
   11.91 +
   11.92 +enomem:
   11.93 +    status = PEP_OUT_OF_MEMORY;
   11.94 +error:
   11.95 +    // free extra
   11.96 +    return status;
   11.97 +}
   11.98 +
   11.99 +
  11.100 +// notifyInitMoveOurDevice() - 
  11.101 +//
  11.102 +//  params:
  11.103 +//      session (in)        session handle
  11.104 +//      state (in)          state the state machine is in
  11.105 +//      partner (in)        partner to communicate with
  11.106 +//
  11.107 +//  returns:
  11.108 +//      PEP_STATUS_OK or any other value on error
  11.109 +
  11.110 +PEP_STATUS notifyInitMoveOurDevice(
  11.111 +        PEP_SESSION session,
  11.112 +        DeviceState_state state,
  11.113 +        Identity partner,
  11.114 +        void *extra
  11.115 +    )
  11.116 +{
  11.117 +    PEP_STATUS status = PEP_STATUS_OK;
  11.118 +
  11.119 +    assert(session);
  11.120 +    assert(partner);
  11.121 +    if (!(session && partner))
  11.122 +        return PEP_ILLEGAL_VALUE;
  11.123 +
  11.124 +    // working code
  11.125 +
  11.126 +    // free extra
  11.127 +    return status;
  11.128 +
  11.129 +enomem:
  11.130 +    status = PEP_OUT_OF_MEMORY;
  11.131 +error:
  11.132 +    // free extra
  11.133 +    return status;
  11.134 +}
  11.135 +
  11.136 +
  11.137 +// notifyAcceptedDeviceMoved() - 
  11.138 +//
  11.139 +//  params:
  11.140 +//      session (in)        session handle
  11.141 +//      state (in)          state the state machine is in
  11.142 +//      partner (in)        partner to communicate with
  11.143 +//
  11.144 +//  returns:
  11.145 +//      PEP_STATUS_OK or any other value on error
  11.146 +
  11.147 +PEP_STATUS notifyAcceptedDeviceMoved(
  11.148 +        PEP_SESSION session,
  11.149 +        DeviceState_state state,
  11.150 +        Identity partner,
  11.151 +        void *extra
  11.152 +    )
  11.153 +{
  11.154 +    PEP_STATUS status = PEP_STATUS_OK;
  11.155 +
  11.156 +    assert(session);
  11.157 +    assert(partner);
  11.158 +    if (!(session && partner))
  11.159 +        return PEP_ILLEGAL_VALUE;
  11.160 +
  11.161 +    // working code
  11.162 +
  11.163 +    // free extra
  11.164 +    return status;
  11.165 +
  11.166 +enomem:
  11.167 +    status = PEP_OUT_OF_MEMORY;
  11.168 +error:
  11.169 +    // free extra
  11.170 +    return status;
  11.171 +}
  11.172 +