src/sync_send_actions.c
author Volker Birk <vb@pep.foundation>
Tue, 23 Aug 2016 11:37:37 +0200
branchkeysync
changeset 1058 1d34706c62d1
parent 1047 2a4a2ec1340b
child 1060 fcfc07caa0f6
permissions -rw-r--r--
some redesign for unicast_msg()
vb@883
     1
// Send Actions for DeviceState state machine
vb@883
     2
vb@883
     3
#include <assert.h>
vb@883
     4
#include "pEp_internal.h"
vb@883
     5
#include "keymanagement.h"
vb@883
     6
#include "message.h"
vb@883
     7
#include "sync_fsm.h"
vb@883
     8
#include "baseprotocol.h"
vb@883
     9
#include "map_asn1.h"
vb@985
    10
#include "../asn.1/DeviceGroup-Protocol.h"
vb@1047
    11
#include "sync_impl.h"
vb@883
    12
#include "../asn.1/Beacon.h"
vb@883
    13
#include "../asn.1/HandshakeRequest.h"
vb@883
    14
#include "../asn.1/GroupKeys.h"
vb@883
    15
vb@883
    16
vb@883
    17
// sendBeacon() - send Beacon message
vb@883
    18
//
vb@883
    19
//  params:
vb@883
    20
//      session (in)        session handle
vb@883
    21
//      state (in)          state the state machine is in
vb@883
    22
//      partner (in)        (must be NULL)
vb@883
    23
//
vb@883
    24
//  returns:
vb@883
    25
//      PEP_STATUS_OK or any other value on error
vb@883
    26
vb@883
    27
PEP_STATUS sendBeacon(
vb@883
    28
        PEP_SESSION session,
vb@883
    29
        DeviceState_state state,
vb@939
    30
        Identity partner,
vb@939
    31
        void *extra
vb@883
    32
    )
vb@883
    33
{
vb@883
    34
    PEP_STATUS status = PEP_STATUS_OK;
vb@883
    35
vb@1058
    36
    DeviceGroup_Protocol_t *msg = new_DeviceGroup_Protocol_msg(DeviceGroup_Protocol__payload_PR_beacon);
vb@883
    37
    if (!msg)
vb@883
    38
        goto enomem;
vb@883
    39
vb@1058
    40
    status = unicast_msg(session, partner, state, msg);
vb@883
    41
    if (status != PEP_STATUS_OK)
vb@883
    42
        goto error;
vb@883
    43
vb@1058
    44
    return PEP_STATUS_OK;
vb@883
    45
vb@883
    46
enomem:
vb@883
    47
    status = PEP_OUT_OF_MEMORY;
vb@883
    48
error:
vb@1058
    49
    free_DeviceGroup_Protocol_msg(msg);
vb@883
    50
    return status;
vb@883
    51
}
vb@883
    52
vb@883
    53
vb@883
    54
// sendHandshakeRequest() - send HandshakeRequest message
vb@883
    55
//
vb@883
    56
//  params:
vb@883
    57
//      session (in)        session handle
vb@883
    58
//      state (in)          state the state machine is in
vb@883
    59
//      partner (in)        partner to communicate with
vb@883
    60
//
vb@883
    61
//  returns:
vb@883
    62
//      PEP_STATUS_OK or any other value on error
vb@883
    63
vb@883
    64
PEP_STATUS sendHandshakeRequest(
vb@883
    65
        PEP_SESSION session,
vb@883
    66
        DeviceState_state state,
vb@939
    67
        Identity partner,
vb@939
    68
        void *extra
vb@883
    69
    )
vb@883
    70
{
vb@883
    71
    PEP_STATUS status = PEP_STATUS_OK;
vb@883
    72
vb@1058
    73
    DeviceGroup_Protocol_t *msg = new_DeviceGroup_Protocol_msg(DeviceGroup_Protocol__payload_PR_handshakeRequest);
vb@883
    74
    if (!msg)
vb@883
    75
        goto enomem;
vb@883
    76
vb@1058
    77
    status = unicast_msg(session, partner, state, msg);
vb@883
    78
    if (status != PEP_STATUS_OK)
vb@883
    79
        goto error;
vb@883
    80
vb@1058
    81
    return PEP_STATUS_OK;
vb@883
    82
vb@883
    83
enomem:
vb@883
    84
    status = PEP_OUT_OF_MEMORY;
vb@883
    85
error:
vb@1058
    86
    free_DeviceGroup_Protocol_msg(msg);
vb@883
    87
    return status;
vb@883
    88
}
vb@883
    89
vb@883
    90
vb@883
    91
// sendGroupKeys() - send GroupKeys message
vb@883
    92
//
vb@883
    93
//  params:
vb@883
    94
//      session (in)        session handle
vb@883
    95
//      state (in)          state the state machine is in
vb@883
    96
//      partner (in)        (must be NULL)
vb@883
    97
//
vb@883
    98
//  returns:
vb@883
    99
//      PEP_STATUS_OK or any other value on error
vb@883
   100
vb@883
   101
PEP_STATUS sendGroupKeys(
vb@883
   102
        PEP_SESSION session,
vb@883
   103
        DeviceState_state state,
vb@939
   104
        Identity partner,
vb@939
   105
        void *extra
vb@883
   106
    )
vb@883
   107
{
vb@883
   108
    PEP_STATUS status = PEP_STATUS_OK;
vb@1058
   109
    identity_list *kl = new_identity_list(NULL);
vb@883
   110
vb@1058
   111
    DeviceGroup_Protocol_t *msg = new_DeviceGroup_Protocol_msg(DeviceGroup_Protocol__payload_PR_groupKeys);
vb@1058
   112
    if (!msg)
vb@883
   113
        goto enomem;
vb@883
   114
vb@955
   115
    status = own_identities_retrieve(session, &kl);
vb@955
   116
    if (status != PEP_STATUS_OK)
vb@955
   117
        goto error;
vb@1058
   118
    if (IdentityList_from_identity_list(kl, &msg->payload.choice.groupKeys.ownIdentities) == NULL)
vb@955
   119
        goto enomem;
vb@955
   120
vb@1058
   121
    status = unicast_msg(session, partner, state, msg);
vb@883
   122
    if (status != PEP_STATUS_OK)
vb@883
   123
        goto error;
vb@883
   124
vb@955
   125
    free_identity_list(kl);
vb@1058
   126
    return PEP_STATUS_OK;
vb@883
   127
vb@883
   128
enomem:
vb@883
   129
    status = PEP_OUT_OF_MEMORY;
vb@883
   130
error:
vb@1058
   131
    free_DeviceGroup_Protocol_msg(msg);
vb@955
   132
    free_identity_list(kl);
vb@883
   133
    return status;
vb@883
   134
}
vb@883
   135