sync/generated/sync_fsm.c
author Edouard Tisserant <edouard@pep-project.org>
Tue, 24 Jan 2017 13:27:29 +0100
changeset 1555 7ffa6cf9d054
parent 1523 bc4a9401af51
child 1566 fcb7bade5c5f
permissions -rw-r--r--
Sync: added transmission of Beacon when timeout happens while waiting for group keys, thus re-trying handhake process. Timeout while waiting for groupKeys was leading to a situation where device that did lose key election wasn't re-attempting handshaking because already having keys (i.e. no CannotDecrypt event), then device was left Sole with no chance to enter the group again
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@1467
    27
                    cond_result = storedGroupKeys(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@1490
    32
                    DEBUG_LOG("FSM condition", "sync_fsm.c, state=InitState, event=Init, condition=storedGroupKeys", 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@1490
   275
                        DEBUG_LOG("FSM action", "sync_fsm.c, state=HandshakingSole, event=HandshakeAccepted", "action=sendGroupKeys")
edouard@1467
   276
                        status = sendGroupKeys(session, state, partner, NULL);
edouard@1467
   277
                        if (status == PEP_OUT_OF_MEMORY)
edouard@1467
   278
                            return (int) invalid_out_of_memory;
edouard@1467
   279
                        if (status != PEP_STATUS_OK)
edouard@1467
   280
                            return (int) invalid_action;
edouard@1490
   281
                        DEBUG_LOG("FSM action", "sync_fsm.c, state=HandshakingSole, event=HandshakeAccepted", "action=notifyAcceptedGroupCreated")
edouard@1477
   282
                        status = notifyAcceptedGroupCreated(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@1467
   287
                        if(session->sync_state_payload){
edouard@1467
   288
                            free_identity((Identity)session->sync_state_payload);
edouard@1467
   289
                            session->sync_state_payload = NULL;
edouard@1467
   290
                        }
edouard@1490
   291
                        DEBUG_LOG("FSM transition", "sync_fsm.c, state=HandshakingSole, event=HandshakeAccepted", "target=Grouped")
edouard@1467
   292
                        return Grouped;
edouard@1467
   293
                    }
edouard@1467
   294
                    if(session->sync_state_payload){
edouard@1467
   295
                        free_identity((Identity)session->sync_state_payload);
edouard@1467
   296
                        session->sync_state_payload = NULL;
edouard@1467
   297
                    }
edouard@1467
   298
                    session->sync_state_payload = identity_dup(partner);
edouard@1490
   299
                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=HandshakingSole, event=HandshakeAccepted", "target=WaitForGroupKeysSole")
edouard@1467
   300
                    return WaitForGroupKeysSole;
edouard@1467
   301
                }
edouard@1467
   302
                case Cancel:
edouard@1467
   303
                {
edouard@1490
   304
                    DEBUG_LOG("FSM event", "sync_fsm.c, state=HandshakingSole", "event=Cancel")
edouard@1467
   305
                    if(session->sync_state_payload){
edouard@1467
   306
                        free_identity((Identity)session->sync_state_payload);
edouard@1467
   307
                        session->sync_state_payload = NULL;
edouard@1467
   308
                    }
edouard@1490
   309
                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=HandshakingSole, event=Cancel", "target=Sole")
edouard@1467
   310
                    return Sole;
edouard@1467
   311
                }
edouard@1467
   312
                case Timeout:
edouard@1467
   313
                {
edouard@1490
   314
                    DEBUG_LOG("FSM event", "sync_fsm.c, state=HandshakingSole", "event=Timeout")
edouard@1490
   315
                    DEBUG_LOG("FSM action", "sync_fsm.c, state=HandshakingSole, event=Timeout", "action=notifyTimeout")
edouard@1477
   316
                    status = notifyTimeout(session, state, expected, NULL);
edouard@1467
   317
                    if (status == PEP_OUT_OF_MEMORY)
edouard@1467
   318
                        return (int) invalid_out_of_memory;
edouard@1467
   319
                    if (status != PEP_STATUS_OK)
edouard@1467
   320
                        return (int) invalid_action;
edouard@1555
   321
                    DEBUG_LOG("FSM action", "sync_fsm.c, state=HandshakingSole, event=Timeout", "action=sendBeacon")
edouard@1555
   322
                    status = sendBeacon(session, state, NULL, NULL);
edouard@1555
   323
                    if (status == PEP_OUT_OF_MEMORY)
edouard@1555
   324
                        return (int) invalid_out_of_memory;
edouard@1555
   325
                    if (status != PEP_STATUS_OK)
edouard@1555
   326
                        return (int) invalid_action;
edouard@1467
   327
                    if(session->sync_state_payload){
edouard@1467
   328
                        free_identity((Identity)session->sync_state_payload);
edouard@1467
   329
                        session->sync_state_payload = NULL;
edouard@1467
   330
                    }
edouard@1490
   331
                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=HandshakingSole, event=Timeout", "target=Sole")
edouard@1467
   332
                    return Sole;
edouard@1467
   333
                }
edouard@1467
   334
                default:
edouard@1467
   335
                    return (DeviceState_state) invalid_event;
edouard@1467
   336
            }
edouard@1467
   337
            break;
edouard@1467
   338
        }
edouard@1467
   339
        case WaitForGroupKeysSole:
edouard@1467
   340
        {
edouard@1467
   341
            Identity expected = (Identity)session->sync_state_payload;
edouard@1467
   342
            *timeout = 600;
edouard@1490
   343
            DEBUG_LOG("Entering FSM state", "sync_fsm.c", "state=WaitForGroupKeysSole")
edouard@1467
   344
            switch (event) {
edouard@1490
   345
                case Init: DEBUG_LOG("FSM event", "sync_fsm.c, state=WaitForGroupKeysSole", "event=Init") break;
edouard@1467
   346
                case GroupKeys:
edouard@1467
   347
                {
edouard@1490
   348
                    DEBUG_LOG("FSM event", "sync_fsm.c, state=WaitForGroupKeysSole", "event=GroupKeys")
edouard@1523
   349
                    cond_result = sameIdentities(session, partner, expected);
edouard@1523
   350
                    #ifndef NDEBUG
edouard@1523
   351
                    char resstr[11] = {0,};
edouard@1523
   352
                    snprintf(resstr,10,"result=%d",cond_result);
edouard@1523
   353
                    #endif
edouard@1523
   354
                    DEBUG_LOG("FSM condition", "sync_fsm.c, state=WaitForGroupKeysSole, event=GroupKeys, condition=sameIdentities", resstr)
edouard@1523
   355
                    if (cond_result < 0)
edouard@1523
   356
                        return cond_result;
edouard@1523
   357
                    if (cond_result) {
edouard@1523
   358
                        DEBUG_LOG("FSM action", "sync_fsm.c, state=WaitForGroupKeysSole, event=GroupKeys", "action=storeGroupKeys")
edouard@1523
   359
                        status = storeGroupKeys(session, state, partner, extra /*keys*/);
edouard@1523
   360
                        if (status == PEP_OUT_OF_MEMORY)
edouard@1523
   361
                            return (int) invalid_out_of_memory;
edouard@1523
   362
                        if (status != PEP_STATUS_OK)
edouard@1523
   363
                            return (int) invalid_action;
edouard@1523
   364
                        DEBUG_LOG("FSM action", "sync_fsm.c, state=WaitForGroupKeysSole, event=GroupKeys", "action=notifyAcceptedDeviceAdded")
edouard@1523
   365
                        status = notifyAcceptedDeviceAdded(session, state, partner, NULL);
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@1523
   370
                        if(session->sync_state_payload){
edouard@1523
   371
                            free_identity((Identity)session->sync_state_payload);
edouard@1523
   372
                            session->sync_state_payload = NULL;
edouard@1523
   373
                        }
edouard@1523
   374
                        DEBUG_LOG("FSM transition", "sync_fsm.c, state=WaitForGroupKeysSole, event=GroupKeys", "target=Grouped")
edouard@1523
   375
                        return Grouped;
edouard@1467
   376
                    }
edouard@1523
   377
                    break;
edouard@1467
   378
                }
edouard@1467
   379
                case Timeout:
edouard@1467
   380
                {
edouard@1490
   381
                    DEBUG_LOG("FSM event", "sync_fsm.c, state=WaitForGroupKeysSole", "event=Timeout")
edouard@1490
   382
                    DEBUG_LOG("FSM action", "sync_fsm.c, state=WaitForGroupKeysSole, event=Timeout", "action=notifyTimeout")
edouard@1477
   383
                    status = notifyTimeout(session, state, expected, NULL);
edouard@1467
   384
                    if (status == PEP_OUT_OF_MEMORY)
edouard@1467
   385
                        return (int) invalid_out_of_memory;
edouard@1467
   386
                    if (status != PEP_STATUS_OK)
edouard@1467
   387
                        return (int) invalid_action;
edouard@1467
   388
                    if(session->sync_state_payload){
edouard@1467
   389
                        free_identity((Identity)session->sync_state_payload);
edouard@1467
   390
                        session->sync_state_payload = NULL;
edouard@1467
   391
                    }
edouard@1490
   392
                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=WaitForGroupKeysSole, event=Timeout", "target=Sole")
edouard@1467
   393
                    return Sole;
edouard@1467
   394
                }
edouard@1467
   395
                default:
edouard@1467
   396
                    return (DeviceState_state) invalid_event;
edouard@1467
   397
            }
edouard@1467
   398
            break;
edouard@1467
   399
        }
edouard@1467
   400
        case Grouped:
edouard@1467
   401
        {
edouard@1467
   402
            *timeout = 0;
edouard@1490
   403
            DEBUG_LOG("Entering FSM state", "sync_fsm.c", "state=Grouped")
edouard@1467
   404
            switch (event) {
edouard@1467
   405
                case Init:
edouard@1467
   406
                {
edouard@1490
   407
                    DEBUG_LOG("FSM event", "sync_fsm.c, state=Grouped", "event=Init")
edouard@1490
   408
                    DEBUG_LOG("FSM action", "sync_fsm.c, state=Grouped, event=Init", "action=enterGroup")
edouard@1467
   409
                    status = enterGroup(session, state, NULL, NULL);
edouard@1467
   410
                    if (status == PEP_OUT_OF_MEMORY)
edouard@1467
   411
                        return (int) invalid_out_of_memory;
edouard@1467
   412
                    if (status != PEP_STATUS_OK)
edouard@1467
   413
                        return (int) invalid_action;
edouard@1467
   414
                    break;
edouard@1467
   415
                }
edouard@1467
   416
                case KeyGen:
edouard@1467
   417
                {
edouard@1490
   418
                    DEBUG_LOG("FSM event", "sync_fsm.c, state=Grouped", "event=KeyGen")
edouard@1490
   419
                    DEBUG_LOG("FSM action", "sync_fsm.c, state=Grouped, event=KeyGen", "action=sendGroupUpdate")
edouard@1467
   420
                    status = sendGroupUpdate(session, state, NULL, NULL);
edouard@1467
   421
                    if (status == PEP_OUT_OF_MEMORY)
edouard@1467
   422
                        return (int) invalid_out_of_memory;
edouard@1467
   423
                    if (status != PEP_STATUS_OK)
edouard@1467
   424
                        return (int) invalid_action;
edouard@1467
   425
                    break;
edouard@1467
   426
                }
edouard@1467
   427
                case CannotDecrypt:
edouard@1467
   428
                {
edouard@1490
   429
                    DEBUG_LOG("FSM event", "sync_fsm.c, state=Grouped", "event=CannotDecrypt")
edouard@1490
   430
                    DEBUG_LOG("FSM action", "sync_fsm.c, state=Grouped, event=CannotDecrypt", "action=sendUpdateRequest")
edouard@1467
   431
                    status = sendUpdateRequest(session, state, NULL, NULL);
edouard@1467
   432
                    if (status == PEP_OUT_OF_MEMORY)
edouard@1467
   433
                        return (int) invalid_out_of_memory;
edouard@1467
   434
                    if (status != PEP_STATUS_OK)
edouard@1467
   435
                        return (int) invalid_action;
edouard@1467
   436
                    break;
edouard@1467
   437
                }
edouard@1467
   438
                case UpdateRequest:
edouard@1467
   439
                {
edouard@1490
   440
                    DEBUG_LOG("FSM event", "sync_fsm.c, state=Grouped", "event=UpdateRequest")
edouard@1490
   441
                    DEBUG_LOG("FSM action", "sync_fsm.c, state=Grouped, event=UpdateRequest", "action=sendGroupUpdate")
edouard@1467
   442
                    status = sendGroupUpdate(session, state, NULL, NULL);
edouard@1467
   443
                    if (status == PEP_OUT_OF_MEMORY)
edouard@1467
   444
                        return (int) invalid_out_of_memory;
edouard@1467
   445
                    if (status != PEP_STATUS_OK)
edouard@1467
   446
                        return (int) invalid_action;
edouard@1467
   447
                    break;
edouard@1467
   448
                }
edouard@1467
   449
                case Beacon:
edouard@1467
   450
                {
edouard@1490
   451
                    DEBUG_LOG("FSM event", "sync_fsm.c, state=Grouped", "event=Beacon")
edouard@1490
   452
                    DEBUG_LOG("FSM action", "sync_fsm.c, state=Grouped, event=Beacon", "action=sendHandshakeRequest")
edouard@1467
   453
                    status = sendHandshakeRequest(session, state, partner, NULL);
edouard@1467
   454
                    if (status == PEP_OUT_OF_MEMORY)
edouard@1467
   455
                        return (int) invalid_out_of_memory;
edouard@1467
   456
                    if (status != PEP_STATUS_OK)
edouard@1467
   457
                        return (int) invalid_action;
edouard@1523
   458
                    session->sync_state_payload = identity_dup(partner);
edouard@1523
   459
                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=Grouped, event=Beacon", "target=GroupedBeaconed")
edouard@1523
   460
                    return GroupedBeaconed;
edouard@1467
   461
                }
edouard@1467
   462
                case HandshakeRequest:
edouard@1467
   463
                {
edouard@1490
   464
                    DEBUG_LOG("FSM event", "sync_fsm.c, state=Grouped", "event=HandshakeRequest")
edouard@1490
   465
                    DEBUG_LOG("FSM action", "sync_fsm.c, state=Grouped, event=HandshakeRequest", "action=sendHandshakeRequest")
edouard@1467
   466
                    status = sendHandshakeRequest(session, state, partner, NULL);
edouard@1467
   467
                    if (status == PEP_OUT_OF_MEMORY)
edouard@1467
   468
                        return (int) invalid_out_of_memory;
edouard@1467
   469
                    if (status != PEP_STATUS_OK)
edouard@1467
   470
                        return (int) invalid_action;
edouard@1467
   471
                    session->sync_state_payload = identity_dup(partner);
edouard@1490
   472
                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=Grouped, event=HandshakeRequest", "target=HandshakingGrouped")
edouard@1467
   473
                    return HandshakingGrouped;
edouard@1467
   474
                }
edouard@1467
   475
                case GroupUpdate:
edouard@1467
   476
                {
edouard@1490
   477
                    DEBUG_LOG("FSM event", "sync_fsm.c, state=Grouped", "event=GroupUpdate")
edouard@1490
   478
                    DEBUG_LOG("FSM action", "sync_fsm.c, state=Grouped, event=GroupUpdate", "action=storeGroupKeys")
edouard@1467
   479
                    status = storeGroupKeys(session, state, partner, extra /*keys*/);
edouard@1467
   480
                    if (status == PEP_OUT_OF_MEMORY)
edouard@1467
   481
                        return (int) invalid_out_of_memory;
edouard@1467
   482
                    if (status != PEP_STATUS_OK)
edouard@1467
   483
                        return (int) invalid_action;
edouard@1467
   484
                    break;
edouard@1467
   485
                }
edouard@1467
   486
                default:
edouard@1467
   487
                    return (DeviceState_state) invalid_event;
edouard@1467
   488
            }
edouard@1467
   489
            break;
edouard@1467
   490
        }
edouard@1523
   491
        case GroupedBeaconed:
edouard@1523
   492
        {
edouard@1523
   493
            Identity expected = (Identity)session->sync_state_payload;
edouard@1523
   494
            *timeout = 600;
edouard@1523
   495
            DEBUG_LOG("Entering FSM state", "sync_fsm.c", "state=GroupedBeaconed")
edouard@1523
   496
            switch (event) {
edouard@1523
   497
                case Init: DEBUG_LOG("FSM event", "sync_fsm.c, state=GroupedBeaconed", "event=Init") break;
edouard@1523
   498
                case KeyGen:
edouard@1523
   499
                {
edouard@1523
   500
                    DEBUG_LOG("FSM event", "sync_fsm.c, state=GroupedBeaconed", "event=KeyGen")
edouard@1523
   501
                    DEBUG_LOG("FSM action", "sync_fsm.c, state=GroupedBeaconed, event=KeyGen", "action=sendGroupUpdate")
edouard@1523
   502
                    status = sendGroupUpdate(session, state, NULL, NULL);
edouard@1523
   503
                    if (status == PEP_OUT_OF_MEMORY)
edouard@1523
   504
                        return (int) invalid_out_of_memory;
edouard@1523
   505
                    if (status != PEP_STATUS_OK)
edouard@1523
   506
                        return (int) invalid_action;
edouard@1523
   507
                    break;
edouard@1523
   508
                }
edouard@1523
   509
                case CannotDecrypt:
edouard@1523
   510
                {
edouard@1523
   511
                    DEBUG_LOG("FSM event", "sync_fsm.c, state=GroupedBeaconed", "event=CannotDecrypt")
edouard@1523
   512
                    DEBUG_LOG("FSM action", "sync_fsm.c, state=GroupedBeaconed, event=CannotDecrypt", "action=sendUpdateRequest")
edouard@1523
   513
                    status = sendUpdateRequest(session, state, NULL, NULL);
edouard@1523
   514
                    if (status == PEP_OUT_OF_MEMORY)
edouard@1523
   515
                        return (int) invalid_out_of_memory;
edouard@1523
   516
                    if (status != PEP_STATUS_OK)
edouard@1523
   517
                        return (int) invalid_action;
edouard@1523
   518
                    break;
edouard@1523
   519
                }
edouard@1523
   520
                case UpdateRequest:
edouard@1523
   521
                {
edouard@1523
   522
                    DEBUG_LOG("FSM event", "sync_fsm.c, state=GroupedBeaconed", "event=UpdateRequest")
edouard@1523
   523
                    DEBUG_LOG("FSM action", "sync_fsm.c, state=GroupedBeaconed, event=UpdateRequest", "action=sendGroupUpdate")
edouard@1523
   524
                    status = sendGroupUpdate(session, state, NULL, NULL);
edouard@1523
   525
                    if (status == PEP_OUT_OF_MEMORY)
edouard@1523
   526
                        return (int) invalid_out_of_memory;
edouard@1523
   527
                    if (status != PEP_STATUS_OK)
edouard@1523
   528
                        return (int) invalid_action;
edouard@1523
   529
                    break;
edouard@1523
   530
                }
edouard@1523
   531
                case Beacon:
edouard@1523
   532
                {
edouard@1523
   533
                    DEBUG_LOG("FSM event", "sync_fsm.c, state=GroupedBeaconed", "event=Beacon")
edouard@1523
   534
                    DEBUG_LOG("FSM action", "sync_fsm.c, state=GroupedBeaconed, event=Beacon", "action=sendHandshakeRequest")
edouard@1523
   535
                    status = sendHandshakeRequest(session, state, partner, NULL);
edouard@1523
   536
                    if (status == PEP_OUT_OF_MEMORY)
edouard@1523
   537
                        return (int) invalid_out_of_memory;
edouard@1523
   538
                    if (status != PEP_STATUS_OK)
edouard@1523
   539
                        return (int) invalid_action;
edouard@1523
   540
                    if(session->sync_state_payload){
edouard@1523
   541
                        free_identity((Identity)session->sync_state_payload);
edouard@1523
   542
                        session->sync_state_payload = NULL;
edouard@1523
   543
                    }
edouard@1523
   544
                    session->sync_state_payload = identity_dup(partner);
edouard@1523
   545
                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=GroupedBeaconed, event=Beacon", "target=GroupedBeaconed")
edouard@1523
   546
                    return GroupedBeaconed;
edouard@1523
   547
                }
edouard@1523
   548
                case HandshakeRequest:
edouard@1523
   549
                {
edouard@1523
   550
                    DEBUG_LOG("FSM event", "sync_fsm.c, state=GroupedBeaconed", "event=HandshakeRequest")
edouard@1523
   551
                    cond_result = sameIdentities(session, partner, expected);
edouard@1523
   552
                    #ifndef NDEBUG
edouard@1523
   553
                    char resstr[11] = {0,};
edouard@1523
   554
                    snprintf(resstr,10,"result=%d",cond_result);
edouard@1523
   555
                    #endif
edouard@1523
   556
                    DEBUG_LOG("FSM condition", "sync_fsm.c, state=GroupedBeaconed, event=HandshakeRequest, condition=sameIdentities", resstr)
edouard@1523
   557
                    if (cond_result < 0)
edouard@1523
   558
                        return cond_result;
edouard@1523
   559
                    if (cond_result) {
edouard@1523
   560
                    }
edouard@1523
   561
                    else {
edouard@1523
   562
                        DEBUG_LOG("FSM action", "sync_fsm.c, state=GroupedBeaconed, event=HandshakeRequest", "action=sendHandshakeRequest")
edouard@1523
   563
                        status = sendHandshakeRequest(session, state, partner, NULL);
edouard@1523
   564
                        if (status == PEP_OUT_OF_MEMORY)
edouard@1523
   565
                            return (int) invalid_out_of_memory;
edouard@1523
   566
                        if (status != PEP_STATUS_OK)
edouard@1523
   567
                            return (int) invalid_action;
edouard@1523
   568
                    }
edouard@1523
   569
                    if(session->sync_state_payload){
edouard@1523
   570
                        free_identity((Identity)session->sync_state_payload);
edouard@1523
   571
                        session->sync_state_payload = NULL;
edouard@1523
   572
                    }
edouard@1523
   573
                    session->sync_state_payload = identity_dup(partner);
edouard@1523
   574
                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=GroupedBeaconed, event=HandshakeRequest", "target=HandshakingGrouped")
edouard@1523
   575
                    return HandshakingGrouped;
edouard@1523
   576
                }
edouard@1523
   577
                case GroupUpdate:
edouard@1523
   578
                {
edouard@1523
   579
                    DEBUG_LOG("FSM event", "sync_fsm.c, state=GroupedBeaconed", "event=GroupUpdate")
edouard@1523
   580
                    DEBUG_LOG("FSM action", "sync_fsm.c, state=GroupedBeaconed, event=GroupUpdate", "action=storeGroupKeys")
edouard@1523
   581
                    status = storeGroupKeys(session, state, partner, extra /*keys*/);
edouard@1523
   582
                    if (status == PEP_OUT_OF_MEMORY)
edouard@1523
   583
                        return (int) invalid_out_of_memory;
edouard@1523
   584
                    if (status != PEP_STATUS_OK)
edouard@1523
   585
                        return (int) invalid_action;
edouard@1523
   586
                    break;
edouard@1523
   587
                }
edouard@1523
   588
                case Timeout:
edouard@1523
   589
                {
edouard@1523
   590
                    DEBUG_LOG("FSM event", "sync_fsm.c, state=GroupedBeaconed", "event=Timeout")
edouard@1523
   591
                    if(session->sync_state_payload){
edouard@1523
   592
                        free_identity((Identity)session->sync_state_payload);
edouard@1523
   593
                        session->sync_state_payload = NULL;
edouard@1523
   594
                    }
edouard@1523
   595
                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=GroupedBeaconed, event=Timeout", "target=Grouped")
edouard@1523
   596
                    return Grouped;
edouard@1523
   597
                }
edouard@1523
   598
                default:
edouard@1523
   599
                    return (DeviceState_state) invalid_event;
edouard@1523
   600
            }
edouard@1523
   601
            break;
edouard@1523
   602
        }
edouard@1467
   603
        case HandshakingGrouped:
edouard@1467
   604
        {
edouard@1467
   605
            Identity expected = (Identity)session->sync_state_payload;
edouard@1467
   606
            *timeout = 600;
edouard@1490
   607
            DEBUG_LOG("Entering FSM state", "sync_fsm.c", "state=HandshakingGrouped")
edouard@1467
   608
            switch (event) {
edouard@1467
   609
                case Init:
edouard@1467
   610
                {
edouard@1490
   611
                    DEBUG_LOG("FSM event", "sync_fsm.c, state=HandshakingGrouped", "event=Init")
edouard@1490
   612
                    DEBUG_LOG("FSM action", "sync_fsm.c, state=HandshakingGrouped, event=Init", "action=notifyInitAddOurDevice")
edouard@1477
   613
                    status = notifyInitAddOurDevice(session, state, partner, NULL);
edouard@1467
   614
                    if (status == PEP_OUT_OF_MEMORY)
edouard@1467
   615
                        return (int) invalid_out_of_memory;
edouard@1467
   616
                    if (status != PEP_STATUS_OK)
edouard@1467
   617
                        return (int) invalid_action;
edouard@1467
   618
                    break;
edouard@1467
   619
                }
edouard@1467
   620
                case HandshakeRejected:
edouard@1467
   621
                {
edouard@1490
   622
                    DEBUG_LOG("FSM event", "sync_fsm.c, state=HandshakingGrouped", "event=HandshakeRejected")
edouard@1490
   623
                    DEBUG_LOG("FSM action", "sync_fsm.c, state=HandshakingGrouped, event=HandshakeRejected", "action=rejectHandshake")
edouard@1467
   624
                    status = rejectHandshake(session, state, partner, NULL);
edouard@1467
   625
                    if (status == PEP_OUT_OF_MEMORY)
edouard@1467
   626
                        return (int) invalid_out_of_memory;
edouard@1467
   627
                    if (status != PEP_STATUS_OK)
edouard@1467
   628
                        return (int) invalid_action;
edouard@1467
   629
                    if(session->sync_state_payload){
edouard@1467
   630
                        free_identity((Identity)session->sync_state_payload);
edouard@1467
   631
                        session->sync_state_payload = NULL;
edouard@1467
   632
                    }
edouard@1490
   633
                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=HandshakingGrouped, event=HandshakeRejected", "target=Grouped")
edouard@1467
   634
                    return Grouped;
edouard@1467
   635
                }
edouard@1467
   636
                case HandshakeAccepted:
edouard@1467
   637
                {
edouard@1490
   638
                    DEBUG_LOG("FSM event", "sync_fsm.c, state=HandshakingGrouped", "event=HandshakeAccepted")
edouard@1490
   639
                    DEBUG_LOG("FSM action", "sync_fsm.c, state=HandshakingGrouped, event=HandshakeAccepted", "action=acceptHandshake")
edouard@1467
   640
                    status = acceptHandshake(session, state, partner, NULL);
edouard@1467
   641
                    if (status == PEP_OUT_OF_MEMORY)
edouard@1467
   642
                        return (int) invalid_out_of_memory;
edouard@1467
   643
                    if (status != PEP_STATUS_OK)
edouard@1467
   644
                        return (int) invalid_action;
edouard@1490
   645
                    DEBUG_LOG("FSM action", "sync_fsm.c, state=HandshakingGrouped, event=HandshakeAccepted", "action=sendGroupKeys")
edouard@1467
   646
                    status = sendGroupKeys(session, state, partner, NULL);
edouard@1467
   647
                    if (status == PEP_OUT_OF_MEMORY)
edouard@1467
   648
                        return (int) invalid_out_of_memory;
edouard@1467
   649
                    if (status != PEP_STATUS_OK)
edouard@1467
   650
                        return (int) invalid_action;
edouard@1467
   651
                    if(session->sync_state_payload){
edouard@1467
   652
                        free_identity((Identity)session->sync_state_payload);
edouard@1467
   653
                        session->sync_state_payload = NULL;
edouard@1467
   654
                    }
edouard@1490
   655
                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=HandshakingGrouped, event=HandshakeAccepted", "target=Grouped")
edouard@1467
   656
                    return Grouped;
edouard@1467
   657
                }
edouard@1467
   658
                case Timeout:
edouard@1467
   659
                {
edouard@1490
   660
                    DEBUG_LOG("FSM event", "sync_fsm.c, state=HandshakingGrouped", "event=Timeout")
edouard@1490
   661
                    DEBUG_LOG("FSM action", "sync_fsm.c, state=HandshakingGrouped, event=Timeout", "action=notifyTimeout")
edouard@1477
   662
                    status = notifyTimeout(session, state, expected, NULL);
edouard@1467
   663
                    if (status == PEP_OUT_OF_MEMORY)
edouard@1467
   664
                        return (int) invalid_out_of_memory;
edouard@1467
   665
                    if (status != PEP_STATUS_OK)
edouard@1467
   666
                        return (int) invalid_action;
edouard@1467
   667
                    if(session->sync_state_payload){
edouard@1467
   668
                        free_identity((Identity)session->sync_state_payload);
edouard@1467
   669
                        session->sync_state_payload = NULL;
edouard@1467
   670
                    }
edouard@1490
   671
                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=HandshakingGrouped, event=Timeout", "target=Grouped")
edouard@1467
   672
                    return Grouped;
edouard@1467
   673
                }
edouard@1467
   674
                default:
edouard@1467
   675
                    return (DeviceState_state) invalid_event;
edouard@1467
   676
            }
edouard@1467
   677
            break;
edouard@1467
   678
        }
edouard@1467
   679
        default:
edouard@1467
   680
            return (DeviceState_state) invalid_state;
edouard@1467
   681
    }
edouard@1467
   682
edouard@1467
   683
    return state;
edouard@1467
   684
}
edouard@1467
   685