src/sync_fsm.h
author Volker Birk <vb@pep.foundation>
Mon, 01 Aug 2016 12:32:04 +0200
branchkeysync
changeset 959 c1c463ecf30c
parent 952 986fd7b2eb8f
child 964 ef02296c41ca
permissions -rw-r--r--
error handling in state machine
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@959
    23
    invalid_event = -3,
vb@959
    24
    invalid_condition = -4,
vb@959
    25
    invalid_action = -5
Edouard@613
    26
} fsm_error;
Edouard@613
    27
vb@951
    28
// conditions
vb@951
    29
vb@959
    30
int storedGroupKeys(PEP_SESSION session);
vb@959
    31
int keyElectionWon(PEP_SESSION session, Identity partner);
vb@951
    32
Edouard@613
    33
// states
Edouard@613
    34
Edouard@613
    35
typedef enum _DeviceState_state {
vb@951
    36
    DeviceState_state_NONE = 0,
vb@624
    37
    InitState, 
Edouard@613
    38
    Sole, 
Edouard@613
    39
    HandshakingSole, 
Edouard@613
    40
    WaitForGroupKeys, 
Edouard@613
    41
    Grouped
Edouard@613
    42
} DeviceState_state;
Edouard@613
    43
Edouard@613
    44
// events
Edouard@613
    45
Edouard@613
    46
typedef enum _DeviceState_event {
vb@951
    47
    DeviceState_event_NONE = 0,
vb@951
    48
    Init = 1,
vb@951
    49
    Beacon = 2,
vb@951
    50
    HandshakeRequest = 3,
vb@951
    51
    GroupKeys = 4,
Edouard@613
    52
    KeyGen, 
Edouard@613
    53
    CannotDecrypt, 
Edouard@613
    54
    HandshakeRejected, 
Edouard@613
    55
    HandshakeAccepted, 
Edouard@613
    56
    Cancel, 
vb@939
    57
    Reject, 
vb@939
    58
    Hand
Edouard@613
    59
} DeviceState_event;
Edouard@613
    60
Edouard@613
    61
// actions
Edouard@613
    62
vb@939
    63
PEP_STATUS sendBeacon(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
vb@939
    64
PEP_STATUS sendHandshakeRequest(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
vb@939
    65
PEP_STATUS showHandshake(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
vb@939
    66
PEP_STATUS reject(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
vb@939
    67
PEP_STATUS storeGroupKeys(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
vb@939
    68
PEP_STATUS sendGroupKeys(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
Edouard@613
    69
vb@951
    70
// message receiver
vb@951
    71
vb@952
    72
PEP_STATUS receive_DeviceState_msg(PEP_SESSION session, message *msg);
vb@951
    73
vb@626
    74
// state machine
vb@626
    75
vb@626
    76
DeviceState_state fsm_DeviceState(
vb@627
    77
        PEP_SESSION session,
vb@626
    78
        DeviceState_state state,
vb@626
    79
        DeviceState_event event,
vb@939
    80
        Identity partner,
vb@951
    81
        void *extra
vb@626
    82
    );
vb@626
    83
Edouard@613
    84
// driver
Edouard@613
    85
vb@783
    86
DYNAMIC_API PEP_STATUS fsm_DeviceState_inject(
vb@690
    87
        PEP_SESSION session,
vb@690
    88
        DeviceState_event event,
vb@690
    89
        Identity partner,
vb@951
    90
        void *extra
vb@690
    91
    );
Edouard@613
    92
vb@676
    93
#ifdef __cplusplus
vb@676
    94
}
vb@676
    95
#endif
vb@676
    96