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
     1 #pragma once
     2 
     3 // state machine for DeviceState
     4 
     5 #include "pEpEngine.h"
     6 #include "message.h"
     7 #include "../asn.1/DeviceGroup-Protocol.h"
     8 
     9 #ifdef __cplusplus
    10 extern "C" {
    11 #endif
    12 
    13 // types
    14 
    15 typedef pEp_identity * Identity;
    16 typedef stringlist_t * Stringlist;
    17 typedef union _param { Identity partner; stringlist_t *keylist; } param_t;
    18 
    19 // error values
    20 
    21 typedef enum _fsm_error {
    22     invalid_state = -2,
    23     invalid_event = -3,
    24     invalid_condition = -4,
    25     invalid_action = -5
    26 } fsm_error;
    27 
    28 // conditions
    29 
    30 int storedGroupKeys(PEP_SESSION session);
    31 int keyElectionWon(PEP_SESSION session, Identity partner);
    32 
    33 // states
    34 
    35 typedef enum _DeviceState_state {
    36     DeviceState_state_NONE = 0,
    37     InitState, 
    38     Sole, 
    39     HandshakingSole, 
    40     WaitForGroupKeys, 
    41     Grouped
    42 } DeviceState_state;
    43 
    44 // events
    45 
    46 typedef enum _DeviceState_event {
    47     DeviceState_event_NONE = 0,
    48     Init = 1,
    49     Beacon = 2,
    50     HandshakeRequest = 3,
    51     GroupKeys = 4,
    52     KeyGen, 
    53     CannotDecrypt, 
    54     HandshakeRejected, 
    55     HandshakeAccepted, 
    56     Cancel, 
    57     Reject, 
    58     Hand
    59 } DeviceState_event;
    60 
    61 // actions
    62 
    63 PEP_STATUS sendBeacon(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
    64 PEP_STATUS sendHandshakeRequest(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
    65 PEP_STATUS showHandshake(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
    66 PEP_STATUS reject(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
    67 PEP_STATUS storeGroupKeys(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
    68 PEP_STATUS sendGroupKeys(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
    69 
    70 // message receiver
    71 
    72 PEP_STATUS receive_DeviceState_msg(PEP_SESSION session, message *msg);
    73 
    74 // state machine
    75 
    76 DeviceState_state fsm_DeviceState(
    77         PEP_SESSION session,
    78         DeviceState_state state,
    79         DeviceState_event event,
    80         Identity partner,
    81         void *extra
    82     );
    83 
    84 // driver
    85 
    86 DYNAMIC_API PEP_STATUS fsm_DeviceState_inject(
    87         PEP_SESSION session,
    88         DeviceState_event event,
    89         Identity partner,
    90         void *extra
    91     );
    92 
    93 #ifdef __cplusplus
    94 }
    95 #endif
    96