src/sync_send_actions.c
author Volker Birk <vb@pep.foundation>
Tue, 23 Aug 2016 11:48:50 +0200
branchkeysync
changeset 1060 fcfc07caa0f6
parent 1058 1d34706c62d1
child 1066 e6db6bb9d542
permissions -rw-r--r--
adding some parameter check to send*() functions
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@1060
    34
    assert(session && state);
vb@1060
    35
    if (!(session && state))
vb@1060
    36
        return PEP_ILLEGAL_VALUE;
vb@1060
    37
vb@883
    38
    PEP_STATUS status = PEP_STATUS_OK;
vb@883
    39
vb@1058
    40
    DeviceGroup_Protocol_t *msg = new_DeviceGroup_Protocol_msg(DeviceGroup_Protocol__payload_PR_beacon);
vb@883
    41
    if (!msg)
vb@883
    42
        goto enomem;
vb@883
    43
vb@1060
    44
    status = multicast_self_msg(session, state, msg);
vb@883
    45
    if (status != PEP_STATUS_OK)
vb@883
    46
        goto error;
vb@883
    47
vb@1058
    48
    return PEP_STATUS_OK;
vb@883
    49
vb@883
    50
enomem:
vb@883
    51
    status = PEP_OUT_OF_MEMORY;
vb@883
    52
error:
vb@1058
    53
    free_DeviceGroup_Protocol_msg(msg);
vb@883
    54
    return status;
vb@883
    55
}
vb@883
    56
vb@883
    57
vb@883
    58
// sendHandshakeRequest() - send HandshakeRequest message
vb@883
    59
//
vb@883
    60
//  params:
vb@883
    61
//      session (in)        session handle
vb@883
    62
//      state (in)          state the state machine is in
vb@883
    63
//      partner (in)        partner to communicate with
vb@883
    64
//
vb@883
    65
//  returns:
vb@883
    66
//      PEP_STATUS_OK or any other value on error
vb@883
    67
vb@883
    68
PEP_STATUS sendHandshakeRequest(
vb@883
    69
        PEP_SESSION session,
vb@883
    70
        DeviceState_state state,
vb@939
    71
        Identity partner,
vb@939
    72
        void *extra
vb@883
    73
    )
vb@883
    74
{
vb@1060
    75
    assert(session && state);
vb@1060
    76
    if (!(session && state))
vb@1060
    77
        return PEP_ILLEGAL_VALUE;
vb@1060
    78
vb@883
    79
    PEP_STATUS status = PEP_STATUS_OK;
vb@883
    80
vb@1058
    81
    DeviceGroup_Protocol_t *msg = new_DeviceGroup_Protocol_msg(DeviceGroup_Protocol__payload_PR_handshakeRequest);
vb@883
    82
    if (!msg)
vb@883
    83
        goto enomem;
vb@883
    84
vb@1058
    85
    status = unicast_msg(session, partner, state, msg);
vb@883
    86
    if (status != PEP_STATUS_OK)
vb@883
    87
        goto error;
vb@883
    88
vb@1058
    89
    return PEP_STATUS_OK;
vb@883
    90
vb@883
    91
enomem:
vb@883
    92
    status = PEP_OUT_OF_MEMORY;
vb@883
    93
error:
vb@1058
    94
    free_DeviceGroup_Protocol_msg(msg);
vb@883
    95
    return status;
vb@883
    96
}
vb@883
    97
vb@883
    98
vb@883
    99
// sendGroupKeys() - send GroupKeys message
vb@883
   100
//
vb@883
   101
//  params:
vb@883
   102
//      session (in)        session handle
vb@883
   103
//      state (in)          state the state machine is in
vb@883
   104
//      partner (in)        (must be NULL)
vb@883
   105
//
vb@883
   106
//  returns:
vb@883
   107
//      PEP_STATUS_OK or any other value on error
vb@883
   108
vb@883
   109
PEP_STATUS sendGroupKeys(
vb@883
   110
        PEP_SESSION session,
vb@883
   111
        DeviceState_state state,
vb@939
   112
        Identity partner,
vb@939
   113
        void *extra
vb@883
   114
    )
vb@883
   115
{
vb@1060
   116
    assert(session && state);
vb@1060
   117
    if (!(session && state))
vb@1060
   118
        return PEP_ILLEGAL_VALUE;
vb@1060
   119
vb@883
   120
    PEP_STATUS status = PEP_STATUS_OK;
vb@1058
   121
    identity_list *kl = new_identity_list(NULL);
vb@883
   122
vb@1058
   123
    DeviceGroup_Protocol_t *msg = new_DeviceGroup_Protocol_msg(DeviceGroup_Protocol__payload_PR_groupKeys);
vb@1058
   124
    if (!msg)
vb@883
   125
        goto enomem;
vb@883
   126
vb@955
   127
    status = own_identities_retrieve(session, &kl);
vb@955
   128
    if (status != PEP_STATUS_OK)
vb@955
   129
        goto error;
vb@1058
   130
    if (IdentityList_from_identity_list(kl, &msg->payload.choice.groupKeys.ownIdentities) == NULL)
vb@955
   131
        goto enomem;
vb@955
   132
vb@1058
   133
    status = unicast_msg(session, partner, state, msg);
vb@883
   134
    if (status != PEP_STATUS_OK)
vb@883
   135
        goto error;
vb@883
   136
vb@955
   137
    free_identity_list(kl);
vb@1058
   138
    return PEP_STATUS_OK;
vb@883
   139
vb@883
   140
enomem:
vb@883
   141
    status = PEP_OUT_OF_MEMORY;
vb@883
   142
error:
vb@1058
   143
    free_DeviceGroup_Protocol_msg(msg);
vb@955
   144
    free_identity_list(kl);
vb@883
   145
    return status;
vb@883
   146
}
vb@883
   147