src/sync_fsm.c
author Volker Birk <vb@pep-project.org>
Sun, 29 May 2016 12:21:50 +0200
changeset 690 3ae86b68fdfe
parent 627 ef1fdfde8ced
child 711 d88dea0f5448
permissions -rw-r--r--
adding sending
vb@616
     1
#include "sync_fsm.h"
vb@616
     2
vb@616
     3
// state machine for DeviceState
vb@616
     4
vb@616
     5
DeviceState_state fsm_DeviceState(
vb@627
     6
        PEP_SESSION session,
vb@616
     7
        DeviceState_state state,
vb@616
     8
        DeviceState_event event,
vb@690
     9
        const Identity partner,
vb@690
    10
        DeviceState_state state_partner
vb@616
    11
    )
vb@616
    12
{
vb@616
    13
    switch (state) {
vb@624
    14
    case InitState:
vb@624
    15
        switch (event) {
vb@624
    16
            case Init:
vb@624
    17
                return Sole;
vb@624
    18
        default:
vb@624
    19
            return invalid_event;
vb@624
    20
        }
vb@624
    21
        break;
vb@624
    22
    
vb@616
    23
    case Sole:
vb@616
    24
        switch (event) {
vb@616
    25
            case KeyGen:
vb@690
    26
                sendBeacon(session, state, NULL);
vb@616
    27
                break;
vb@616
    28
            case CannotDecrypt:
vb@690
    29
                sendBeacon(session, state, NULL);
vb@616
    30
                break;
vb@616
    31
            case Beacon:
vb@690
    32
                sendHandshakeRequest(session, state, partner);
vb@616
    33
                break;
vb@616
    34
            case HandshakeRequest:
vb@690
    35
                sendHandshakeRequest(session, state, partner);
vb@616
    36
                return HandshakingSole;
vb@616
    37
        default:
vb@616
    38
            return invalid_event;
vb@616
    39
        }
vb@616
    40
        break;
vb@616
    41
    
vb@616
    42
    case HandshakingSole:
vb@616
    43
        switch (event) {
vb@616
    44
            case Init:
vb@690
    45
                showHandshake(session, state, partner);
vb@616
    46
                break;
vb@616
    47
            case HandshakeRejected:
vb@690
    48
                reject(session, state, partner);
vb@616
    49
                return Sole;
vb@616
    50
            case HandshakeAccepted:
vb@616
    51
                return WaitForGroupKeys;
vb@616
    52
        default:
vb@616
    53
            return invalid_event;
vb@616
    54
        }
vb@616
    55
        break;
vb@616
    56
    
vb@616
    57
    case WaitForGroupKeys:
vb@616
    58
        switch (event) {
vb@616
    59
            case ReceiveGroupKeys:
vb@690
    60
                storeGroupKeys(session, state, partner);
vb@616
    61
                return Grouped;
vb@616
    62
            case Cancel:
vb@616
    63
                return Sole;
vb@616
    64
            case Reject:
vb@690
    65
                reject(session, state, partner);
vb@616
    66
                return Sole;
vb@616
    67
        default:
vb@616
    68
            return invalid_event;
vb@616
    69
        }
vb@616
    70
        break;
vb@616
    71
    
vb@616
    72
    case Grouped:
vb@616
    73
        switch (event) {
vb@616
    74
            case KeyGen:
vb@690
    75
                sendOwnKeys(session, state, NULL);
vb@616
    76
                break;
vb@616
    77
            case HandshakeRequest:
vb@690
    78
                sendHandshakeRequest(session, state, partner);
vb@690
    79
                showHandshake(session, state, partner);
vb@616
    80
                break;
vb@616
    81
            case HandshakeRejected:
vb@690
    82
                reject(session, state, partner);
vb@616
    83
                break;
vb@616
    84
            case HandshakeAccepted:
vb@690
    85
                transmitGroupKeys(session, state, partner);
vb@616
    86
                break;
vb@616
    87
            case Reject:
vb@690
    88
                reject(session, state, NULL);
vb@616
    89
                break;
vb@616
    90
        default:
vb@616
    91
            return invalid_event;
vb@616
    92
        }
vb@616
    93
        break;
vb@616
    94
    
vb@616
    95
        default:
vb@616
    96
            return invalid_state;
vb@616
    97
    }
vb@616
    98
vb@616
    99
    return state;
vb@616
   100
}