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