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