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