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
     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     // these error values are corresponding to
    23     // PEP_SYNC_STATEMACHINE_ERROR - value
    24     invalid_state = -2,
    25     invalid_event = -3,
    26     invalid_condition = -4,
    27     invalid_action = -5,
    28 
    29     // out of memory condition
    30     invalid_out_of_memory = -128
    31 } fsm_error;
    32 
    33 // conditions
    34 
    35 int storedGroupKeys(PEP_SESSION session);
    36 int keyElectionWon(PEP_SESSION session, Identity partner);
    37 
    38 // states
    39 
    40 typedef enum _DeviceState_state {
    41     DeviceState_state_NONE = 0,
    42     InitState, 
    43     Sole, 
    44     HandshakingSole, 
    45     WaitForGroupKeys, 
    46     Grouped
    47 } DeviceState_state;
    48 
    49 // events
    50 
    51 typedef enum _DeviceState_event {
    52     DeviceState_event_NONE = 0,
    53     Init = 1,
    54     Beacon = 2,
    55     HandshakeRequest = 3,
    56     GroupKeys = 4,
    57     KeyGen, 
    58     CannotDecrypt, 
    59     HandshakeRejected, 
    60     HandshakeAccepted, 
    61     Cancel, 
    62     Reject, 
    63     Hand
    64 } DeviceState_event;
    65 
    66 // actions
    67 
    68 PEP_STATUS sendBeacon(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
    69 PEP_STATUS sendHandshakeRequest(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
    70 PEP_STATUS showHandshake(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
    71 PEP_STATUS reject(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
    72 PEP_STATUS storeGroupKeys(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
    73 PEP_STATUS sendGroupKeys(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
    74 
    75 // message receiver
    76 
    77 PEP_STATUS receive_DeviceState_msg(PEP_SESSION session, message *msg);
    78 
    79 // state machine
    80 
    81 DeviceState_state fsm_DeviceState(
    82         PEP_SESSION session,
    83         DeviceState_state state,
    84         DeviceState_event event,
    85         Identity partner,
    86         void *extra
    87     );
    88 
    89 // driver
    90 
    91 DYNAMIC_API PEP_STATUS fsm_DeviceState_inject(
    92         PEP_SESSION session,
    93         DeviceState_event event,
    94         Identity partner,
    95         void *extra
    96     );
    97 
    98 #ifdef __cplusplus
    99 }
   100 #endif
   101