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