sync/generated/sync_fsm.c
author Edouard Tisserant <edouard@pep-project.org>
Sun, 12 Feb 2017 22:45:02 +0100
changeset 1574 12b7a45140d3
parent 1566 fcb7bade5c5f
child 1586 599deda50386
permissions -rw-r--r--
KeySync : reworked some SQL statements and condition checking if a device is grouped.
vb@1476
     1
#include "pEp_internal.h"
edouard@1467
     2
#include "sync_fsm.h"
edouard@1467
     3
edouard@1467
     4
// state machine for DeviceState
edouard@1467
     5
edouard@1467
     6
DeviceState_state fsm_DeviceState(
edouard@1467
     7
        PEP_SESSION session,
edouard@1467
     8
        DeviceState_state state,
edouard@1467
     9
        DeviceState_event event,
edouard@1467
    10
        Identity partner,
edouard@1467
    11
        void *extra,
edouard@1467
    12
        time_t *timeout
edouard@1467
    13
    )
edouard@1467
    14
{
edouard@1467
    15
    int cond_result;
edouard@1467
    16
    PEP_STATUS status = PEP_STATUS_OK;
edouard@1467
    17
edouard@1467
    18
    switch (state) {
edouard@1467
    19
        case InitState:
edouard@1467
    20
        {
edouard@1467
    21
            *timeout = 0;
edouard@1490
    22
            DEBUG_LOG("Entering FSM state", "sync_fsm.c", "state=InitState")
edouard@1467
    23
            switch (event) {
edouard@1467
    24
                case Init:
edouard@1467
    25
                {
edouard@1490
    26
                    DEBUG_LOG("FSM event", "sync_fsm.c, state=InitState", "event=Init")
edouard@1574
    27
                    cond_result = deviceGrouped(session);
edouard@1490
    28
                    #ifndef NDEBUG
edouard@1490
    29
                    char resstr[11] = {0,};
edouard@1490
    30
                    snprintf(resstr,10,"result=%d",cond_result);
edouard@1490
    31
                    #endif
edouard@1574
    32
                    DEBUG_LOG("FSM condition", "sync_fsm.c, state=InitState, event=Init, condition=deviceGrouped", resstr)
edouard@1467
    33
                    if (cond_result < 0)
edouard@1467
    34
                        return cond_result;
edouard@1467
    35
                    if (cond_result) {
edouard@1490
    36
                        DEBUG_LOG("FSM transition", "sync_fsm.c, state=InitState, event=Init", "target=Grouped")
edouard@1467
    37
                        return Grouped;
edouard@1467
    38
                    }
edouard@1490
    39
                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=InitState, event=Init", "target=Sole")
edouard@1467
    40
                    return Sole;
edouard@1467
    41
                }
edouard@1467
    42
                default:
edouard@1467
    43
                    return (DeviceState_state) invalid_event;
edouard@1467
    44
            }
edouard@1467
    45
            break;
edouard@1467
    46
        }
edouard@1467
    47
        case Sole:
edouard@1467
    48
        {
edouard@1467
    49
            *timeout = 0;
edouard@1490
    50
            DEBUG_LOG("Entering FSM state", "sync_fsm.c", "state=Sole")
edouard@1467
    51
            switch (event) {
edouard@1490
    52
                case Init: DEBUG_LOG("FSM event", "sync_fsm.c, state=Sole", "event=Init") break;
edouard@1467
    53
                case KeyGen:
edouard@1467
    54
                {
edouard@1490
    55
                    DEBUG_LOG("FSM event", "sync_fsm.c, state=Sole", "event=KeyGen")
edouard@1490
    56
                    DEBUG_LOG("FSM action", "sync_fsm.c, state=Sole, event=KeyGen", "action=sendBeacon")
edouard@1467
    57
                    status = sendBeacon(session, state, NULL, NULL);
edouard@1467
    58
                    if (status == PEP_OUT_OF_MEMORY)
edouard@1467
    59
                        return (int) invalid_out_of_memory;
edouard@1467
    60
                    if (status != PEP_STATUS_OK)
edouard@1467
    61
                        return (int) invalid_action;
edouard@1467
    62
                    break;
edouard@1467
    63
                }
edouard@1467
    64
                case CannotDecrypt:
edouard@1467
    65
                {
edouard@1490
    66
                    DEBUG_LOG("FSM event", "sync_fsm.c, state=Sole", "event=CannotDecrypt")
edouard@1490
    67
                    DEBUG_LOG("FSM action", "sync_fsm.c, state=Sole, event=CannotDecrypt", "action=sendBeacon")
edouard@1467
    68
                    status = sendBeacon(session, state, NULL, NULL);
edouard@1467
    69
                    if (status == PEP_OUT_OF_MEMORY)
edouard@1467
    70
                        return (int) invalid_out_of_memory;
edouard@1467
    71
                    if (status != PEP_STATUS_OK)
edouard@1467
    72
                        return (int) invalid_action;
edouard@1467
    73
                    break;
edouard@1467
    74
                }
edouard@1467
    75
                case Beacon:
edouard@1467
    76
                {
edouard@1490
    77
                    DEBUG_LOG("FSM event", "sync_fsm.c, state=Sole", "event=Beacon")
edouard@1490
    78
                    DEBUG_LOG("FSM action", "sync_fsm.c, state=Sole, event=Beacon", "action=sendHandshakeRequest")
edouard@1467
    79
                    status = sendHandshakeRequest(session, state, partner, NULL);
edouard@1467
    80
                    if (status == PEP_OUT_OF_MEMORY)
edouard@1467
    81
                        return (int) invalid_out_of_memory;
edouard@1467
    82
                    if (status != PEP_STATUS_OK)
edouard@1467
    83
                        return (int) invalid_action;
edouard@1523
    84
                    session->sync_state_payload = identity_dup(partner);
edouard@1523
    85
                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=Sole, event=Beacon", "target=SoleBeaconed")
edouard@1523
    86
                    return SoleBeaconed;
edouard@1467
    87
                }
edouard@1467
    88
                case HandshakeRequest:
edouard@1467
    89
                {
edouard@1490
    90
                    DEBUG_LOG("FSM event", "sync_fsm.c, state=Sole", "event=HandshakeRequest")
edouard@1490
    91
                    DEBUG_LOG("FSM action", "sync_fsm.c, state=Sole, event=HandshakeRequest", "action=sendHandshakeRequest")
edouard@1467
    92
                    status = sendHandshakeRequest(session, state, partner, NULL);
edouard@1467
    93
                    if (status == PEP_OUT_OF_MEMORY)
edouard@1467
    94
                        return (int) invalid_out_of_memory;
edouard@1467
    95
                    if (status != PEP_STATUS_OK)
edouard@1467
    96
                        return (int) invalid_action;
edouard@1467
    97
                    session->sync_state_payload = identity_dup(partner);
edouard@1490
    98
                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=Sole, event=HandshakeRequest", "target=HandshakingSole")
edouard@1467
    99
                    return HandshakingSole;
edouard@1467
   100
                }
edouard@1467
   101
                default:
edouard@1467
   102
                    return (DeviceState_state) invalid_event;
edouard@1467
   103
            }
edouard@1467
   104
            break;
edouard@1467
   105
        }
edouard@1523
   106
        case SoleBeaconed:
edouard@1523
   107
        {
edouard@1523
   108
            Identity expected = (Identity)session->sync_state_payload;
edouard@1523
   109
            *timeout = 600;
edouard@1523
   110
            DEBUG_LOG("Entering FSM state", "sync_fsm.c", "state=SoleBeaconed")
edouard@1523
   111
            switch (event) {
edouard@1523
   112
                case Init: DEBUG_LOG("FSM event", "sync_fsm.c, state=SoleBeaconed", "event=Init") break;
edouard@1523
   113
                case KeyGen:
edouard@1523
   114
                {
edouard@1523
   115
                    DEBUG_LOG("FSM event", "sync_fsm.c, state=SoleBeaconed", "event=KeyGen")
edouard@1523
   116
                    DEBUG_LOG("FSM action", "sync_fsm.c, state=SoleBeaconed, event=KeyGen", "action=sendBeacon")
edouard@1523
   117
                    status = sendBeacon(session, state, NULL, NULL);
edouard@1523
   118
                    if (status == PEP_OUT_OF_MEMORY)
edouard@1523
   119
                        return (int) invalid_out_of_memory;
edouard@1523
   120
                    if (status != PEP_STATUS_OK)
edouard@1523
   121
                        return (int) invalid_action;
edouard@1523
   122
                    if(session->sync_state_payload){
edouard@1523
   123
                        free_identity((Identity)session->sync_state_payload);
edouard@1523
   124
                        session->sync_state_payload = NULL;
edouard@1523
   125
                    }
edouard@1523
   126
                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=SoleBeaconed, event=KeyGen", "target=Sole")
edouard@1523
   127
                    return Sole;
edouard@1523
   128
                }
edouard@1523
   129
                case CannotDecrypt:
edouard@1523
   130
                {
edouard@1523
   131
                    DEBUG_LOG("FSM event", "sync_fsm.c, state=SoleBeaconed", "event=CannotDecrypt")
edouard@1523
   132
                    DEBUG_LOG("FSM action", "sync_fsm.c, state=SoleBeaconed, event=CannotDecrypt", "action=sendBeacon")
edouard@1523
   133
                    status = sendBeacon(session, state, NULL, NULL);
edouard@1523
   134
                    if (status == PEP_OUT_OF_MEMORY)
edouard@1523
   135
                        return (int) invalid_out_of_memory;
edouard@1523
   136
                    if (status != PEP_STATUS_OK)
edouard@1523
   137
                        return (int) invalid_action;
edouard@1523
   138
                    if(session->sync_state_payload){
edouard@1523
   139
                        free_identity((Identity)session->sync_state_payload);
edouard@1523
   140
                        session->sync_state_payload = NULL;
edouard@1523
   141
                    }
edouard@1523
   142
                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=SoleBeaconed, event=CannotDecrypt", "target=Sole")
edouard@1523
   143
                    return Sole;
edouard@1523
   144
                }
edouard@1523
   145
                case Beacon:
edouard@1523
   146
                {
edouard@1523
   147
                    DEBUG_LOG("FSM event", "sync_fsm.c, state=SoleBeaconed", "event=Beacon")
edouard@1523
   148
                    DEBUG_LOG("FSM action", "sync_fsm.c, state=SoleBeaconed, event=Beacon", "action=sendHandshakeRequest")
edouard@1523
   149
                    status = sendHandshakeRequest(session, state, partner, NULL);
edouard@1523
   150
                    if (status == PEP_OUT_OF_MEMORY)
edouard@1523
   151
                        return (int) invalid_out_of_memory;
edouard@1523
   152
                    if (status != PEP_STATUS_OK)
edouard@1523
   153
                        return (int) invalid_action;
edouard@1523
   154
                    if(session->sync_state_payload){
edouard@1523
   155
                        free_identity((Identity)session->sync_state_payload);
edouard@1523
   156
                        session->sync_state_payload = NULL;
edouard@1523
   157
                    }
edouard@1523
   158
                    session->sync_state_payload = identity_dup(partner);
edouard@1523
   159
                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=SoleBeaconed, event=Beacon", "target=SoleBeaconed")
edouard@1523
   160
                    return SoleBeaconed;
edouard@1523
   161
                }
edouard@1523
   162
                case HandshakeRequest:
edouard@1523
   163
                {
edouard@1523
   164
                    DEBUG_LOG("FSM event", "sync_fsm.c, state=SoleBeaconed", "event=HandshakeRequest")
edouard@1523
   165
                    cond_result = sameIdentities(session, partner, expected);
edouard@1523
   166
                    #ifndef NDEBUG
edouard@1523
   167
                    char resstr[11] = {0,};
edouard@1523
   168
                    snprintf(resstr,10,"result=%d",cond_result);
edouard@1523
   169
                    #endif
edouard@1523
   170
                    DEBUG_LOG("FSM condition", "sync_fsm.c, state=SoleBeaconed, event=HandshakeRequest, condition=sameIdentities", resstr)
edouard@1523
   171
                    if (cond_result < 0)
edouard@1523
   172
                        return cond_result;
edouard@1523
   173
                    if (cond_result) {
edouard@1523
   174
                    }
edouard@1523
   175
                    else {
edouard@1523
   176
                        DEBUG_LOG("FSM action", "sync_fsm.c, state=SoleBeaconed, event=HandshakeRequest", "action=sendHandshakeRequest")
edouard@1523
   177
                        status = sendHandshakeRequest(session, state, partner, NULL);
edouard@1523
   178
                        if (status == PEP_OUT_OF_MEMORY)
edouard@1523
   179
                            return (int) invalid_out_of_memory;
edouard@1523
   180
                        if (status != PEP_STATUS_OK)
edouard@1523
   181
                            return (int) invalid_action;
edouard@1523
   182
                    }
edouard@1523
   183
                    if(session->sync_state_payload){
edouard@1523
   184
                        free_identity((Identity)session->sync_state_payload);
edouard@1523
   185
                        session->sync_state_payload = NULL;
edouard@1523
   186
                    }
edouard@1523
   187
                    session->sync_state_payload = identity_dup(partner);
edouard@1523
   188
                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=SoleBeaconed, event=HandshakeRequest", "target=HandshakingSole")
edouard@1523
   189
                    return HandshakingSole;
edouard@1523
   190
                }
edouard@1523
   191
                case Timeout:
edouard@1523
   192
                {
edouard@1523
   193
                    DEBUG_LOG("FSM event", "sync_fsm.c, state=SoleBeaconed", "event=Timeout")
edouard@1523
   194
                    if(session->sync_state_payload){
edouard@1523
   195
                        free_identity((Identity)session->sync_state_payload);
edouard@1523
   196
                        session->sync_state_payload = NULL;
edouard@1523
   197
                    }
edouard@1523
   198
                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=SoleBeaconed, event=Timeout", "target=Sole")
edouard@1523
   199
                    return Sole;
edouard@1523
   200
                }
edouard@1523
   201
                default:
edouard@1523
   202
                    return (DeviceState_state) invalid_event;
edouard@1523
   203
            }
edouard@1523
   204
            break;
edouard@1523
   205
        }
edouard@1467
   206
        case HandshakingSole:
edouard@1467
   207
        {
edouard@1467
   208
            Identity expected = (Identity)session->sync_state_payload;
edouard@1467
   209
            *timeout = 600;
edouard@1490
   210
            DEBUG_LOG("Entering FSM state", "sync_fsm.c", "state=HandshakingSole")
edouard@1467
   211
            switch (event) {
edouard@1467
   212
                case Init:
edouard@1467
   213
                {
edouard@1490
   214
                    DEBUG_LOG("FSM event", "sync_fsm.c, state=HandshakingSole", "event=Init")
edouard@1477
   215
                    cond_result = keyElectionWon(session, partner);
edouard@1490
   216
                    #ifndef NDEBUG
edouard@1490
   217
                    char resstr[11] = {0,};
edouard@1490
   218
                    snprintf(resstr,10,"result=%d",cond_result);
edouard@1490
   219
                    #endif
edouard@1490
   220
                    DEBUG_LOG("FSM condition", "sync_fsm.c, state=HandshakingSole, event=Init, condition=keyElectionWon", resstr)
edouard@1477
   221
                    if (cond_result < 0)
edouard@1477
   222
                        return cond_result;
edouard@1477
   223
                    if (cond_result) {
edouard@1490
   224
                        DEBUG_LOG("FSM action", "sync_fsm.c, state=HandshakingSole, event=Init", "action=notifyInitFormGroup")
edouard@1477
   225
                        status = notifyInitFormGroup(session, state, partner, NULL);
edouard@1477
   226
                        if (status == PEP_OUT_OF_MEMORY)
edouard@1477
   227
                            return (int) invalid_out_of_memory;
edouard@1477
   228
                        if (status != PEP_STATUS_OK)
edouard@1477
   229
                            return (int) invalid_action;
edouard@1477
   230
                    }
edouard@1477
   231
                    else {
edouard@1490
   232
                        DEBUG_LOG("FSM action", "sync_fsm.c, state=HandshakingSole, event=Init", "action=notifyInitAddOurDevice")
edouard@1477
   233
                        status = notifyInitAddOurDevice(session, state, partner, NULL);
edouard@1477
   234
                        if (status == PEP_OUT_OF_MEMORY)
edouard@1477
   235
                            return (int) invalid_out_of_memory;
edouard@1477
   236
                        if (status != PEP_STATUS_OK)
edouard@1477
   237
                            return (int) invalid_action;
edouard@1477
   238
                    }
edouard@1467
   239
                    break;
edouard@1467
   240
                }
edouard@1467
   241
                case HandshakeRejected:
edouard@1467
   242
                {
edouard@1490
   243
                    DEBUG_LOG("FSM event", "sync_fsm.c, state=HandshakingSole", "event=HandshakeRejected")
edouard@1490
   244
                    DEBUG_LOG("FSM action", "sync_fsm.c, state=HandshakingSole, event=HandshakeRejected", "action=rejectHandshake")
edouard@1467
   245
                    status = rejectHandshake(session, state, partner, NULL);
edouard@1467
   246
                    if (status == PEP_OUT_OF_MEMORY)
edouard@1467
   247
                        return (int) invalid_out_of_memory;
edouard@1467
   248
                    if (status != PEP_STATUS_OK)
edouard@1467
   249
                        return (int) invalid_action;
edouard@1467
   250
                    if(session->sync_state_payload){
edouard@1467
   251
                        free_identity((Identity)session->sync_state_payload);
edouard@1467
   252
                        session->sync_state_payload = NULL;
edouard@1467
   253
                    }
edouard@1490
   254
                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=HandshakingSole, event=HandshakeRejected", "target=Sole")
edouard@1467
   255
                    return Sole;
edouard@1467
   256
                }
edouard@1467
   257
                case HandshakeAccepted:
edouard@1467
   258
                {
edouard@1490
   259
                    DEBUG_LOG("FSM event", "sync_fsm.c, state=HandshakingSole", "event=HandshakeAccepted")
edouard@1490
   260
                    DEBUG_LOG("FSM action", "sync_fsm.c, state=HandshakingSole, event=HandshakeAccepted", "action=acceptHandshake")
edouard@1467
   261
                    status = acceptHandshake(session, state, partner, NULL);
edouard@1467
   262
                    if (status == PEP_OUT_OF_MEMORY)
edouard@1467
   263
                        return (int) invalid_out_of_memory;
edouard@1467
   264
                    if (status != PEP_STATUS_OK)
edouard@1467
   265
                        return (int) invalid_action;
edouard@1467
   266
                    cond_result = keyElectionWon(session, partner);
edouard@1490
   267
                    #ifndef NDEBUG
edouard@1490
   268
                    char resstr[11] = {0,};
edouard@1490
   269
                    snprintf(resstr,10,"result=%d",cond_result);
edouard@1490
   270
                    #endif
edouard@1490
   271
                    DEBUG_LOG("FSM condition", "sync_fsm.c, state=HandshakingSole, event=HandshakeAccepted, condition=keyElectionWon", resstr)
edouard@1467
   272
                    if (cond_result < 0)
edouard@1467
   273
                        return cond_result;
edouard@1467
   274
                    if (cond_result) {
edouard@1566
   275
                        DEBUG_LOG("FSM action", "sync_fsm.c, state=HandshakingSole, event=HandshakeAccepted", "action=enterGroup")
edouard@1566
   276
                        status = enterGroup(session, state, NULL, NULL);
edouard@1566
   277
                        if (status == PEP_OUT_OF_MEMORY)
edouard@1566
   278
                            return (int) invalid_out_of_memory;
edouard@1566
   279
                        if (status != PEP_STATUS_OK)
edouard@1566
   280
                            return (int) invalid_action;
edouard@1490
   281
                        DEBUG_LOG("FSM action", "sync_fsm.c, state=HandshakingSole, event=HandshakeAccepted", "action=sendGroupKeys")
edouard@1467
   282
                        status = sendGroupKeys(session, state, partner, NULL);
edouard@1467
   283
                        if (status == PEP_OUT_OF_MEMORY)
edouard@1467
   284
                            return (int) invalid_out_of_memory;
edouard@1467
   285
                        if (status != PEP_STATUS_OK)
edouard@1467
   286
                            return (int) invalid_action;
edouard@1490
   287
                        DEBUG_LOG("FSM action", "sync_fsm.c, state=HandshakingSole, event=HandshakeAccepted", "action=notifyAcceptedGroupCreated")
edouard@1477
   288
                        status = notifyAcceptedGroupCreated(session, state, partner, NULL);
edouard@1467
   289
                        if (status == PEP_OUT_OF_MEMORY)
edouard@1467
   290
                            return (int) invalid_out_of_memory;
edouard@1467
   291
                        if (status != PEP_STATUS_OK)
edouard@1467
   292
                            return (int) invalid_action;
edouard@1467
   293
                        if(session->sync_state_payload){
edouard@1467
   294
                            free_identity((Identity)session->sync_state_payload);
edouard@1467
   295
                            session->sync_state_payload = NULL;
edouard@1467
   296
                        }
edouard@1490
   297
                        DEBUG_LOG("FSM transition", "sync_fsm.c, state=HandshakingSole, event=HandshakeAccepted", "target=Grouped")
edouard@1467
   298
                        return Grouped;
edouard@1467
   299
                    }
edouard@1467
   300
                    if(session->sync_state_payload){
edouard@1467
   301
                        free_identity((Identity)session->sync_state_payload);
edouard@1467
   302
                        session->sync_state_payload = NULL;
edouard@1467
   303
                    }
edouard@1467
   304
                    session->sync_state_payload = identity_dup(partner);
edouard@1490
   305
                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=HandshakingSole, event=HandshakeAccepted", "target=WaitForGroupKeysSole")
edouard@1467
   306
                    return WaitForGroupKeysSole;
edouard@1467
   307
                }
edouard@1467
   308
                case Cancel:
edouard@1467
   309
                {
edouard@1490
   310
                    DEBUG_LOG("FSM event", "sync_fsm.c, state=HandshakingSole", "event=Cancel")
edouard@1467
   311
                    if(session->sync_state_payload){
edouard@1467
   312
                        free_identity((Identity)session->sync_state_payload);
edouard@1467
   313
                        session->sync_state_payload = NULL;
edouard@1467
   314
                    }
edouard@1490
   315
                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=HandshakingSole, event=Cancel", "target=Sole")
edouard@1467
   316
                    return Sole;
edouard@1467
   317
                }
edouard@1467
   318
                case Timeout:
edouard@1467
   319
                {
edouard@1490
   320
                    DEBUG_LOG("FSM event", "sync_fsm.c, state=HandshakingSole", "event=Timeout")
edouard@1490
   321
                    DEBUG_LOG("FSM action", "sync_fsm.c, state=HandshakingSole, event=Timeout", "action=notifyTimeout")
edouard@1477
   322
                    status = notifyTimeout(session, state, expected, NULL);
edouard@1467
   323
                    if (status == PEP_OUT_OF_MEMORY)
edouard@1467
   324
                        return (int) invalid_out_of_memory;
edouard@1467
   325
                    if (status != PEP_STATUS_OK)
edouard@1467
   326
                        return (int) invalid_action;
edouard@1555
   327
                    DEBUG_LOG("FSM action", "sync_fsm.c, state=HandshakingSole, event=Timeout", "action=sendBeacon")
edouard@1555
   328
                    status = sendBeacon(session, state, NULL, NULL);
edouard@1555
   329
                    if (status == PEP_OUT_OF_MEMORY)
edouard@1555
   330
                        return (int) invalid_out_of_memory;
edouard@1555
   331
                    if (status != PEP_STATUS_OK)
edouard@1555
   332
                        return (int) invalid_action;
edouard@1467
   333
                    if(session->sync_state_payload){
edouard@1467
   334
                        free_identity((Identity)session->sync_state_payload);
edouard@1467
   335
                        session->sync_state_payload = NULL;
edouard@1467
   336
                    }
edouard@1490
   337
                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=HandshakingSole, event=Timeout", "target=Sole")
edouard@1467
   338
                    return Sole;
edouard@1467
   339
                }
edouard@1467
   340
                default:
edouard@1467
   341
                    return (DeviceState_state) invalid_event;
edouard@1467
   342
            }
edouard@1467
   343
            break;
edouard@1467
   344
        }
edouard@1467
   345
        case WaitForGroupKeysSole:
edouard@1467
   346
        {
edouard@1467
   347
            Identity expected = (Identity)session->sync_state_payload;
edouard@1467
   348
            *timeout = 600;
edouard@1490
   349
            DEBUG_LOG("Entering FSM state", "sync_fsm.c", "state=WaitForGroupKeysSole")
edouard@1467
   350
            switch (event) {
edouard@1490
   351
                case Init: DEBUG_LOG("FSM event", "sync_fsm.c, state=WaitForGroupKeysSole", "event=Init") break;
edouard@1467
   352
                case GroupKeys:
edouard@1467
   353
                {
edouard@1490
   354
                    DEBUG_LOG("FSM event", "sync_fsm.c, state=WaitForGroupKeysSole", "event=GroupKeys")
edouard@1523
   355
                    cond_result = sameIdentities(session, partner, expected);
edouard@1523
   356
                    #ifndef NDEBUG
edouard@1523
   357
                    char resstr[11] = {0,};
edouard@1523
   358
                    snprintf(resstr,10,"result=%d",cond_result);
edouard@1523
   359
                    #endif
edouard@1523
   360
                    DEBUG_LOG("FSM condition", "sync_fsm.c, state=WaitForGroupKeysSole, event=GroupKeys, condition=sameIdentities", resstr)
edouard@1523
   361
                    if (cond_result < 0)
edouard@1523
   362
                        return cond_result;
edouard@1523
   363
                    if (cond_result) {
edouard@1523
   364
                        DEBUG_LOG("FSM action", "sync_fsm.c, state=WaitForGroupKeysSole, event=GroupKeys", "action=storeGroupKeys")
edouard@1523
   365
                        status = storeGroupKeys(session, state, partner, extra /*keys*/);
edouard@1523
   366
                        if (status == PEP_OUT_OF_MEMORY)
edouard@1523
   367
                            return (int) invalid_out_of_memory;
edouard@1523
   368
                        if (status != PEP_STATUS_OK)
edouard@1523
   369
                            return (int) invalid_action;
edouard@1566
   370
                        DEBUG_LOG("FSM action", "sync_fsm.c, state=WaitForGroupKeysSole, event=GroupKeys", "action=enterGroup")
edouard@1566
   371
                        status = enterGroup(session, state, NULL, NULL);
edouard@1566
   372
                        if (status == PEP_OUT_OF_MEMORY)
edouard@1566
   373
                            return (int) invalid_out_of_memory;
edouard@1566
   374
                        if (status != PEP_STATUS_OK)
edouard@1566
   375
                            return (int) invalid_action;
edouard@1566
   376
                        DEBUG_LOG("FSM action", "sync_fsm.c, state=WaitForGroupKeysSole, event=GroupKeys", "action=sendGroupUpdate")
edouard@1566
   377
                        status = sendGroupUpdate(session, state, NULL, NULL);
edouard@1566
   378
                        if (status == PEP_OUT_OF_MEMORY)
edouard@1566
   379
                            return (int) invalid_out_of_memory;
edouard@1566
   380
                        if (status != PEP_STATUS_OK)
edouard@1566
   381
                            return (int) invalid_action;
edouard@1523
   382
                        DEBUG_LOG("FSM action", "sync_fsm.c, state=WaitForGroupKeysSole, event=GroupKeys", "action=notifyAcceptedDeviceAdded")
edouard@1523
   383
                        status = notifyAcceptedDeviceAdded(session, state, partner, NULL);
edouard@1523
   384
                        if (status == PEP_OUT_OF_MEMORY)
edouard@1523
   385
                            return (int) invalid_out_of_memory;
edouard@1523
   386
                        if (status != PEP_STATUS_OK)
edouard@1523
   387
                            return (int) invalid_action;
edouard@1523
   388
                        if(session->sync_state_payload){
edouard@1523
   389
                            free_identity((Identity)session->sync_state_payload);
edouard@1523
   390
                            session->sync_state_payload = NULL;
edouard@1523
   391
                        }
edouard@1523
   392
                        DEBUG_LOG("FSM transition", "sync_fsm.c, state=WaitForGroupKeysSole, event=GroupKeys", "target=Grouped")
edouard@1523
   393
                        return Grouped;
edouard@1467
   394
                    }
edouard@1523
   395
                    break;
edouard@1467
   396
                }
edouard@1467
   397
                case Timeout:
edouard@1467
   398
                {
edouard@1490
   399
                    DEBUG_LOG("FSM event", "sync_fsm.c, state=WaitForGroupKeysSole", "event=Timeout")
edouard@1490
   400
                    DEBUG_LOG("FSM action", "sync_fsm.c, state=WaitForGroupKeysSole, event=Timeout", "action=notifyTimeout")
edouard@1477
   401
                    status = notifyTimeout(session, state, expected, NULL);
edouard@1467
   402
                    if (status == PEP_OUT_OF_MEMORY)
edouard@1467
   403
                        return (int) invalid_out_of_memory;
edouard@1467
   404
                    if (status != PEP_STATUS_OK)
edouard@1467
   405
                        return (int) invalid_action;
edouard@1467
   406
                    if(session->sync_state_payload){
edouard@1467
   407
                        free_identity((Identity)session->sync_state_payload);
edouard@1467
   408
                        session->sync_state_payload = NULL;
edouard@1467
   409
                    }
edouard@1490
   410
                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=WaitForGroupKeysSole, event=Timeout", "target=Sole")
edouard@1467
   411
                    return Sole;
edouard@1467
   412
                }
edouard@1467
   413
                default:
edouard@1467
   414
                    return (DeviceState_state) invalid_event;
edouard@1467
   415
            }
edouard@1467
   416
            break;
edouard@1467
   417
        }
edouard@1467
   418
        case Grouped:
edouard@1467
   419
        {
edouard@1467
   420
            *timeout = 0;
edouard@1490
   421
            DEBUG_LOG("Entering FSM state", "sync_fsm.c", "state=Grouped")
edouard@1467
   422
            switch (event) {
edouard@1566
   423
                case Init: DEBUG_LOG("FSM event", "sync_fsm.c, state=Grouped", "event=Init") break;
edouard@1467
   424
                case KeyGen:
edouard@1467
   425
                {
edouard@1490
   426
                    DEBUG_LOG("FSM event", "sync_fsm.c, state=Grouped", "event=KeyGen")
edouard@1490
   427
                    DEBUG_LOG("FSM action", "sync_fsm.c, state=Grouped, event=KeyGen", "action=sendGroupUpdate")
edouard@1467
   428
                    status = sendGroupUpdate(session, state, NULL, NULL);
edouard@1467
   429
                    if (status == PEP_OUT_OF_MEMORY)
edouard@1467
   430
                        return (int) invalid_out_of_memory;
edouard@1467
   431
                    if (status != PEP_STATUS_OK)
edouard@1467
   432
                        return (int) invalid_action;
edouard@1467
   433
                    break;
edouard@1467
   434
                }
edouard@1467
   435
                case CannotDecrypt:
edouard@1467
   436
                {
edouard@1490
   437
                    DEBUG_LOG("FSM event", "sync_fsm.c, state=Grouped", "event=CannotDecrypt")
edouard@1490
   438
                    DEBUG_LOG("FSM action", "sync_fsm.c, state=Grouped, event=CannotDecrypt", "action=sendUpdateRequest")
edouard@1467
   439
                    status = sendUpdateRequest(session, state, NULL, NULL);
edouard@1467
   440
                    if (status == PEP_OUT_OF_MEMORY)
edouard@1467
   441
                        return (int) invalid_out_of_memory;
edouard@1467
   442
                    if (status != PEP_STATUS_OK)
edouard@1467
   443
                        return (int) invalid_action;
edouard@1467
   444
                    break;
edouard@1467
   445
                }
edouard@1467
   446
                case UpdateRequest:
edouard@1467
   447
                {
edouard@1490
   448
                    DEBUG_LOG("FSM event", "sync_fsm.c, state=Grouped", "event=UpdateRequest")
edouard@1490
   449
                    DEBUG_LOG("FSM action", "sync_fsm.c, state=Grouped, event=UpdateRequest", "action=sendGroupUpdate")
edouard@1467
   450
                    status = sendGroupUpdate(session, state, NULL, NULL);
edouard@1467
   451
                    if (status == PEP_OUT_OF_MEMORY)
edouard@1467
   452
                        return (int) invalid_out_of_memory;
edouard@1467
   453
                    if (status != PEP_STATUS_OK)
edouard@1467
   454
                        return (int) invalid_action;
edouard@1467
   455
                    break;
edouard@1467
   456
                }
edouard@1467
   457
                case Beacon:
edouard@1467
   458
                {
edouard@1490
   459
                    DEBUG_LOG("FSM event", "sync_fsm.c, state=Grouped", "event=Beacon")
edouard@1490
   460
                    DEBUG_LOG("FSM action", "sync_fsm.c, state=Grouped, event=Beacon", "action=sendHandshakeRequest")
edouard@1467
   461
                    status = sendHandshakeRequest(session, state, partner, NULL);
edouard@1467
   462
                    if (status == PEP_OUT_OF_MEMORY)
edouard@1467
   463
                        return (int) invalid_out_of_memory;
edouard@1467
   464
                    if (status != PEP_STATUS_OK)
edouard@1467
   465
                        return (int) invalid_action;
edouard@1523
   466
                    session->sync_state_payload = identity_dup(partner);
edouard@1523
   467
                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=Grouped, event=Beacon", "target=GroupedBeaconed")
edouard@1523
   468
                    return GroupedBeaconed;
edouard@1467
   469
                }
edouard@1467
   470
                case HandshakeRequest:
edouard@1467
   471
                {
edouard@1490
   472
                    DEBUG_LOG("FSM event", "sync_fsm.c, state=Grouped", "event=HandshakeRequest")
edouard@1490
   473
                    DEBUG_LOG("FSM action", "sync_fsm.c, state=Grouped, event=HandshakeRequest", "action=sendHandshakeRequest")
edouard@1467
   474
                    status = sendHandshakeRequest(session, state, partner, NULL);
edouard@1467
   475
                    if (status == PEP_OUT_OF_MEMORY)
edouard@1467
   476
                        return (int) invalid_out_of_memory;
edouard@1467
   477
                    if (status != PEP_STATUS_OK)
edouard@1467
   478
                        return (int) invalid_action;
edouard@1467
   479
                    session->sync_state_payload = identity_dup(partner);
edouard@1490
   480
                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=Grouped, event=HandshakeRequest", "target=HandshakingGrouped")
edouard@1467
   481
                    return HandshakingGrouped;
edouard@1467
   482
                }
edouard@1467
   483
                case GroupUpdate:
edouard@1467
   484
                {
edouard@1490
   485
                    DEBUG_LOG("FSM event", "sync_fsm.c, state=Grouped", "event=GroupUpdate")
edouard@1490
   486
                    DEBUG_LOG("FSM action", "sync_fsm.c, state=Grouped, event=GroupUpdate", "action=storeGroupKeys")
edouard@1467
   487
                    status = storeGroupKeys(session, state, partner, extra /*keys*/);
edouard@1467
   488
                    if (status == PEP_OUT_OF_MEMORY)
edouard@1467
   489
                        return (int) invalid_out_of_memory;
edouard@1467
   490
                    if (status != PEP_STATUS_OK)
edouard@1467
   491
                        return (int) invalid_action;
edouard@1467
   492
                    break;
edouard@1467
   493
                }
edouard@1467
   494
                default:
edouard@1467
   495
                    return (DeviceState_state) invalid_event;
edouard@1467
   496
            }
edouard@1467
   497
            break;
edouard@1467
   498
        }
edouard@1523
   499
        case GroupedBeaconed:
edouard@1523
   500
        {
edouard@1523
   501
            Identity expected = (Identity)session->sync_state_payload;
edouard@1523
   502
            *timeout = 600;
edouard@1523
   503
            DEBUG_LOG("Entering FSM state", "sync_fsm.c", "state=GroupedBeaconed")
edouard@1523
   504
            switch (event) {
edouard@1523
   505
                case Init: DEBUG_LOG("FSM event", "sync_fsm.c, state=GroupedBeaconed", "event=Init") break;
edouard@1523
   506
                case KeyGen:
edouard@1523
   507
                {
edouard@1523
   508
                    DEBUG_LOG("FSM event", "sync_fsm.c, state=GroupedBeaconed", "event=KeyGen")
edouard@1523
   509
                    DEBUG_LOG("FSM action", "sync_fsm.c, state=GroupedBeaconed, event=KeyGen", "action=sendGroupUpdate")
edouard@1523
   510
                    status = sendGroupUpdate(session, state, NULL, NULL);
edouard@1523
   511
                    if (status == PEP_OUT_OF_MEMORY)
edouard@1523
   512
                        return (int) invalid_out_of_memory;
edouard@1523
   513
                    if (status != PEP_STATUS_OK)
edouard@1523
   514
                        return (int) invalid_action;
edouard@1523
   515
                    break;
edouard@1523
   516
                }
edouard@1523
   517
                case CannotDecrypt:
edouard@1523
   518
                {
edouard@1523
   519
                    DEBUG_LOG("FSM event", "sync_fsm.c, state=GroupedBeaconed", "event=CannotDecrypt")
edouard@1523
   520
                    DEBUG_LOG("FSM action", "sync_fsm.c, state=GroupedBeaconed, event=CannotDecrypt", "action=sendUpdateRequest")
edouard@1523
   521
                    status = sendUpdateRequest(session, state, NULL, NULL);
edouard@1523
   522
                    if (status == PEP_OUT_OF_MEMORY)
edouard@1523
   523
                        return (int) invalid_out_of_memory;
edouard@1523
   524
                    if (status != PEP_STATUS_OK)
edouard@1523
   525
                        return (int) invalid_action;
edouard@1523
   526
                    break;
edouard@1523
   527
                }
edouard@1523
   528
                case UpdateRequest:
edouard@1523
   529
                {
edouard@1523
   530
                    DEBUG_LOG("FSM event", "sync_fsm.c, state=GroupedBeaconed", "event=UpdateRequest")
edouard@1523
   531
                    DEBUG_LOG("FSM action", "sync_fsm.c, state=GroupedBeaconed, event=UpdateRequest", "action=sendGroupUpdate")
edouard@1523
   532
                    status = sendGroupUpdate(session, state, NULL, NULL);
edouard@1523
   533
                    if (status == PEP_OUT_OF_MEMORY)
edouard@1523
   534
                        return (int) invalid_out_of_memory;
edouard@1523
   535
                    if (status != PEP_STATUS_OK)
edouard@1523
   536
                        return (int) invalid_action;
edouard@1523
   537
                    break;
edouard@1523
   538
                }
edouard@1523
   539
                case Beacon:
edouard@1523
   540
                {
edouard@1523
   541
                    DEBUG_LOG("FSM event", "sync_fsm.c, state=GroupedBeaconed", "event=Beacon")
edouard@1523
   542
                    DEBUG_LOG("FSM action", "sync_fsm.c, state=GroupedBeaconed, event=Beacon", "action=sendHandshakeRequest")
edouard@1523
   543
                    status = sendHandshakeRequest(session, state, partner, NULL);
edouard@1523
   544
                    if (status == PEP_OUT_OF_MEMORY)
edouard@1523
   545
                        return (int) invalid_out_of_memory;
edouard@1523
   546
                    if (status != PEP_STATUS_OK)
edouard@1523
   547
                        return (int) invalid_action;
edouard@1523
   548
                    if(session->sync_state_payload){
edouard@1523
   549
                        free_identity((Identity)session->sync_state_payload);
edouard@1523
   550
                        session->sync_state_payload = NULL;
edouard@1523
   551
                    }
edouard@1523
   552
                    session->sync_state_payload = identity_dup(partner);
edouard@1523
   553
                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=GroupedBeaconed, event=Beacon", "target=GroupedBeaconed")
edouard@1523
   554
                    return GroupedBeaconed;
edouard@1523
   555
                }
edouard@1523
   556
                case HandshakeRequest:
edouard@1523
   557
                {
edouard@1523
   558
                    DEBUG_LOG("FSM event", "sync_fsm.c, state=GroupedBeaconed", "event=HandshakeRequest")
edouard@1523
   559
                    cond_result = sameIdentities(session, partner, expected);
edouard@1523
   560
                    #ifndef NDEBUG
edouard@1523
   561
                    char resstr[11] = {0,};
edouard@1523
   562
                    snprintf(resstr,10,"result=%d",cond_result);
edouard@1523
   563
                    #endif
edouard@1523
   564
                    DEBUG_LOG("FSM condition", "sync_fsm.c, state=GroupedBeaconed, event=HandshakeRequest, condition=sameIdentities", resstr)
edouard@1523
   565
                    if (cond_result < 0)
edouard@1523
   566
                        return cond_result;
edouard@1523
   567
                    if (cond_result) {
edouard@1523
   568
                    }
edouard@1523
   569
                    else {
edouard@1523
   570
                        DEBUG_LOG("FSM action", "sync_fsm.c, state=GroupedBeaconed, event=HandshakeRequest", "action=sendHandshakeRequest")
edouard@1523
   571
                        status = sendHandshakeRequest(session, state, partner, NULL);
edouard@1523
   572
                        if (status == PEP_OUT_OF_MEMORY)
edouard@1523
   573
                            return (int) invalid_out_of_memory;
edouard@1523
   574
                        if (status != PEP_STATUS_OK)
edouard@1523
   575
                            return (int) invalid_action;
edouard@1523
   576
                    }
edouard@1523
   577
                    if(session->sync_state_payload){
edouard@1523
   578
                        free_identity((Identity)session->sync_state_payload);
edouard@1523
   579
                        session->sync_state_payload = NULL;
edouard@1523
   580
                    }
edouard@1523
   581
                    session->sync_state_payload = identity_dup(partner);
edouard@1523
   582
                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=GroupedBeaconed, event=HandshakeRequest", "target=HandshakingGrouped")
edouard@1523
   583
                    return HandshakingGrouped;
edouard@1523
   584
                }
edouard@1523
   585
                case GroupUpdate:
edouard@1523
   586
                {
edouard@1523
   587
                    DEBUG_LOG("FSM event", "sync_fsm.c, state=GroupedBeaconed", "event=GroupUpdate")
edouard@1523
   588
                    DEBUG_LOG("FSM action", "sync_fsm.c, state=GroupedBeaconed, event=GroupUpdate", "action=storeGroupKeys")
edouard@1523
   589
                    status = storeGroupKeys(session, state, partner, extra /*keys*/);
edouard@1523
   590
                    if (status == PEP_OUT_OF_MEMORY)
edouard@1523
   591
                        return (int) invalid_out_of_memory;
edouard@1523
   592
                    if (status != PEP_STATUS_OK)
edouard@1523
   593
                        return (int) invalid_action;
edouard@1523
   594
                    break;
edouard@1523
   595
                }
edouard@1523
   596
                case Timeout:
edouard@1523
   597
                {
edouard@1523
   598
                    DEBUG_LOG("FSM event", "sync_fsm.c, state=GroupedBeaconed", "event=Timeout")
edouard@1523
   599
                    if(session->sync_state_payload){
edouard@1523
   600
                        free_identity((Identity)session->sync_state_payload);
edouard@1523
   601
                        session->sync_state_payload = NULL;
edouard@1523
   602
                    }
edouard@1523
   603
                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=GroupedBeaconed, event=Timeout", "target=Grouped")
edouard@1523
   604
                    return Grouped;
edouard@1523
   605
                }
edouard@1523
   606
                default:
edouard@1523
   607
                    return (DeviceState_state) invalid_event;
edouard@1523
   608
            }
edouard@1523
   609
            break;
edouard@1523
   610
        }
edouard@1467
   611
        case HandshakingGrouped:
edouard@1467
   612
        {
edouard@1467
   613
            Identity expected = (Identity)session->sync_state_payload;
edouard@1467
   614
            *timeout = 600;
edouard@1490
   615
            DEBUG_LOG("Entering FSM state", "sync_fsm.c", "state=HandshakingGrouped")
edouard@1467
   616
            switch (event) {
edouard@1467
   617
                case Init:
edouard@1467
   618
                {
edouard@1490
   619
                    DEBUG_LOG("FSM event", "sync_fsm.c, state=HandshakingGrouped", "event=Init")
edouard@1490
   620
                    DEBUG_LOG("FSM action", "sync_fsm.c, state=HandshakingGrouped, event=Init", "action=notifyInitAddOurDevice")
edouard@1477
   621
                    status = notifyInitAddOurDevice(session, state, partner, NULL);
edouard@1467
   622
                    if (status == PEP_OUT_OF_MEMORY)
edouard@1467
   623
                        return (int) invalid_out_of_memory;
edouard@1467
   624
                    if (status != PEP_STATUS_OK)
edouard@1467
   625
                        return (int) invalid_action;
edouard@1467
   626
                    break;
edouard@1467
   627
                }
edouard@1467
   628
                case HandshakeRejected:
edouard@1467
   629
                {
edouard@1490
   630
                    DEBUG_LOG("FSM event", "sync_fsm.c, state=HandshakingGrouped", "event=HandshakeRejected")
edouard@1490
   631
                    DEBUG_LOG("FSM action", "sync_fsm.c, state=HandshakingGrouped, event=HandshakeRejected", "action=rejectHandshake")
edouard@1467
   632
                    status = rejectHandshake(session, state, partner, NULL);
edouard@1467
   633
                    if (status == PEP_OUT_OF_MEMORY)
edouard@1467
   634
                        return (int) invalid_out_of_memory;
edouard@1467
   635
                    if (status != PEP_STATUS_OK)
edouard@1467
   636
                        return (int) invalid_action;
edouard@1467
   637
                    if(session->sync_state_payload){
edouard@1467
   638
                        free_identity((Identity)session->sync_state_payload);
edouard@1467
   639
                        session->sync_state_payload = NULL;
edouard@1467
   640
                    }
edouard@1490
   641
                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=HandshakingGrouped, event=HandshakeRejected", "target=Grouped")
edouard@1467
   642
                    return Grouped;
edouard@1467
   643
                }
edouard@1467
   644
                case HandshakeAccepted:
edouard@1467
   645
                {
edouard@1490
   646
                    DEBUG_LOG("FSM event", "sync_fsm.c, state=HandshakingGrouped", "event=HandshakeAccepted")
edouard@1490
   647
                    DEBUG_LOG("FSM action", "sync_fsm.c, state=HandshakingGrouped, event=HandshakeAccepted", "action=acceptHandshake")
edouard@1467
   648
                    status = acceptHandshake(session, state, partner, NULL);
edouard@1467
   649
                    if (status == PEP_OUT_OF_MEMORY)
edouard@1467
   650
                        return (int) invalid_out_of_memory;
edouard@1467
   651
                    if (status != PEP_STATUS_OK)
edouard@1467
   652
                        return (int) invalid_action;
edouard@1490
   653
                    DEBUG_LOG("FSM action", "sync_fsm.c, state=HandshakingGrouped, event=HandshakeAccepted", "action=sendGroupKeys")
edouard@1467
   654
                    status = sendGroupKeys(session, state, partner, NULL);
edouard@1467
   655
                    if (status == PEP_OUT_OF_MEMORY)
edouard@1467
   656
                        return (int) invalid_out_of_memory;
edouard@1467
   657
                    if (status != PEP_STATUS_OK)
edouard@1467
   658
                        return (int) invalid_action;
edouard@1467
   659
                    if(session->sync_state_payload){
edouard@1467
   660
                        free_identity((Identity)session->sync_state_payload);
edouard@1467
   661
                        session->sync_state_payload = NULL;
edouard@1467
   662
                    }
edouard@1490
   663
                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=HandshakingGrouped, event=HandshakeAccepted", "target=Grouped")
edouard@1467
   664
                    return Grouped;
edouard@1467
   665
                }
edouard@1574
   666
                case Cancel:
edouard@1574
   667
                {
edouard@1574
   668
                    DEBUG_LOG("FSM event", "sync_fsm.c, state=HandshakingGrouped", "event=Cancel")
edouard@1574
   669
                    if(session->sync_state_payload){
edouard@1574
   670
                        free_identity((Identity)session->sync_state_payload);
edouard@1574
   671
                        session->sync_state_payload = NULL;
edouard@1574
   672
                    }
edouard@1574
   673
                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=HandshakingGrouped, event=Cancel", "target=Grouped")
edouard@1574
   674
                    return Grouped;
edouard@1574
   675
                }
edouard@1467
   676
                case Timeout:
edouard@1467
   677
                {
edouard@1490
   678
                    DEBUG_LOG("FSM event", "sync_fsm.c, state=HandshakingGrouped", "event=Timeout")
edouard@1490
   679
                    DEBUG_LOG("FSM action", "sync_fsm.c, state=HandshakingGrouped, event=Timeout", "action=notifyTimeout")
edouard@1477
   680
                    status = notifyTimeout(session, state, expected, NULL);
edouard@1467
   681
                    if (status == PEP_OUT_OF_MEMORY)
edouard@1467
   682
                        return (int) invalid_out_of_memory;
edouard@1467
   683
                    if (status != PEP_STATUS_OK)
edouard@1467
   684
                        return (int) invalid_action;
edouard@1467
   685
                    if(session->sync_state_payload){
edouard@1467
   686
                        free_identity((Identity)session->sync_state_payload);
edouard@1467
   687
                        session->sync_state_payload = NULL;
edouard@1467
   688
                    }
edouard@1490
   689
                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=HandshakingGrouped, event=Timeout", "target=Grouped")
edouard@1467
   690
                    return Grouped;
edouard@1467
   691
                }
edouard@1467
   692
                default:
edouard@1467
   693
                    return (DeviceState_state) invalid_event;
edouard@1467
   694
            }
edouard@1467
   695
            break;
edouard@1467
   696
        }
edouard@1467
   697
        default:
edouard@1467
   698
            return (DeviceState_state) invalid_state;
edouard@1467
   699
    }
edouard@1467
   700
edouard@1467
   701
    return state;
edouard@1467
   702
}
edouard@1467
   703