src/sync_fsm.h
author Volker Birk <vb@pep.foundation>
Sun, 31 Jul 2016 19:38:23 +0200
branchkeysync
changeset 951 dec407deb10e
parent 939 ed7dfdae3031
child 952 986fd7b2eb8f
permissions -rw-r--r--
...
Edouard@613
     1
#pragma once
Edouard@613
     2
Edouard@613
     3
// state machine for DeviceState
Edouard@613
     4
Edouard@613
     5
#include "pEpEngine.h"
vb@951
     6
#include "../asn.1/DeviceGroup-Protocol.h"
Edouard@613
     7
vb@676
     8
#ifdef __cplusplus
vb@676
     9
extern "C" {
vb@676
    10
#endif
vb@676
    11
Edouard@613
    12
// types
Edouard@613
    13
Edouard@613
    14
typedef pEp_identity * Identity;
vb@939
    15
typedef stringlist_t * Stringlist;
vb@939
    16
typedef union _param { Identity partner; stringlist_t *keylist; } param_t;
Edouard@613
    17
Edouard@613
    18
// error values
Edouard@613
    19
Edouard@613
    20
typedef enum _fsm_error {
vb@743
    21
    invalid_state = -2,
vb@743
    22
    invalid_event = -3
Edouard@613
    23
} fsm_error;
Edouard@613
    24
vb@951
    25
// conditions
vb@951
    26
vb@951
    27
bool storedGroupKeys(PEP_SESSION session);
vb@951
    28
bool keyElectionWon(PEP_SESSION session, Identity partner);
vb@951
    29
Edouard@613
    30
// states
Edouard@613
    31
Edouard@613
    32
typedef enum _DeviceState_state {
vb@951
    33
    DeviceState_state_NONE = 0,
vb@624
    34
    InitState, 
Edouard@613
    35
    Sole, 
Edouard@613
    36
    HandshakingSole, 
Edouard@613
    37
    WaitForGroupKeys, 
Edouard@613
    38
    Grouped
Edouard@613
    39
} DeviceState_state;
Edouard@613
    40
Edouard@613
    41
// events
Edouard@613
    42
Edouard@613
    43
typedef enum _DeviceState_event {
vb@951
    44
    DeviceState_event_NONE = 0,
vb@951
    45
    Init = 1,
vb@951
    46
    Beacon = 2,
vb@951
    47
    HandshakeRequest = 3,
vb@951
    48
    GroupKeys = 4,
Edouard@613
    49
    KeyGen, 
Edouard@613
    50
    CannotDecrypt, 
Edouard@613
    51
    HandshakeRejected, 
Edouard@613
    52
    HandshakeAccepted, 
Edouard@613
    53
    Cancel, 
vb@939
    54
    Reject, 
vb@939
    55
    Hand
Edouard@613
    56
} DeviceState_event;
Edouard@613
    57
Edouard@613
    58
// actions
Edouard@613
    59
vb@939
    60
PEP_STATUS sendBeacon(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
vb@939
    61
PEP_STATUS sendHandshakeRequest(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
vb@939
    62
PEP_STATUS showHandshake(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
vb@939
    63
PEP_STATUS reject(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
vb@939
    64
PEP_STATUS storeGroupKeys(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
vb@939
    65
PEP_STATUS sendGroupKeys(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
Edouard@613
    66
vb@951
    67
// message receiver
vb@951
    68
vb@951
    69
PEP_STATUS receive_DeviceState_msg(PEP_SESSION session, DeviceGroup_Protocol_t *msg);
vb@951
    70
vb@626
    71
// state machine
vb@626
    72
vb@626
    73
DeviceState_state fsm_DeviceState(
vb@627
    74
        PEP_SESSION session,
vb@626
    75
        DeviceState_state state,
vb@626
    76
        DeviceState_event event,
vb@939
    77
        Identity partner,
vb@951
    78
        void *extra
vb@626
    79
    );
vb@626
    80
Edouard@613
    81
// driver
Edouard@613
    82
vb@783
    83
DYNAMIC_API PEP_STATUS fsm_DeviceState_inject(
vb@690
    84
        PEP_SESSION session,
vb@690
    85
        DeviceState_event event,
vb@690
    86
        Identity partner,
vb@951
    87
        void *extra
vb@690
    88
    );
Edouard@613
    89
vb@676
    90
#ifdef __cplusplus
vb@676
    91
}
vb@676
    92
#endif
vb@676
    93