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