src/sync_actions.c
author Volker Birk <vb@pep-project.org>
Wed, 18 May 2016 00:05:39 +0200
changeset 650 accc0ad7d32c
parent 627 ef1fdfde8ced
child 652 ccc02be8a27d
permissions -rw-r--r--
...
vb@623
     1
// Actions for DeviceState state machine
vb@623
     2
vb@623
     3
#include <assert.h>
vb@623
     4
#include "sync_fsm.h"
vb@650
     5
#include "map_asn1.h"
vb@650
     6
#include "../asn.1/Beacon.h"
vb@650
     7
#include "../asn.1/HandshakeRequest.h"
vb@650
     8
#include "../asn.1/OwnKeys.h"
vb@623
     9
vb@623
    10
vb@650
    11
// sendBeacon() - send Beacon message
vb@623
    12
//
vb@623
    13
//  params:
vb@627
    14
//      session (in)        session handle
vb@623
    15
//      partner (in)        (must be NULL)
vb@623
    16
//
vb@623
    17
//  returns:
vb@623
    18
//      PEP_STATUS_OK or any other value on error
vb@623
    19
vb@627
    20
PEP_STATUS sendBeacon(PEP_SESSION session, const Identity partner)
vb@623
    21
{
vb@623
    22
    PEP_STATUS status = PEP_STATUS_OK;
vb@623
    23
vb@650
    24
    assert(session);
vb@650
    25
    assert(!partner);
vb@650
    26
    if (!(session && !partner))
vb@623
    27
        return PEP_ILLEGAL_VALUE;
vb@623
    28
vb@650
    29
    Beacon_t *msg = (Beacon_t *) calloc(1, sizeof(Beacon_t));
vb@650
    30
    assert(msg);
vb@650
    31
    if (!msg)
vb@650
    32
        goto enomem;
vb@623
    33
vb@650
    34
    
vb@650
    35
    return status;
vb@623
    36
vb@650
    37
enomem:
vb@650
    38
    status = PEP_OUT_OF_MEMORY;
vb@650
    39
error:
vb@650
    40
    ASN_STRUCT_FREE(asn_DEF_Beacon, msg);
vb@623
    41
    return status;
vb@623
    42
}
vb@623
    43
vb@650
    44
vb@650
    45
// sendHandshakeRequest() - send HandshakeRequest message
vb@623
    46
//
vb@623
    47
//  params:
vb@627
    48
//      session (in)        session handle
vb@623
    49
//      partner (in)        partner in sync
vb@623
    50
//
vb@623
    51
//  returns:
vb@623
    52
//      PEP_STATUS_OK or any other value on error
vb@623
    53
vb@627
    54
PEP_STATUS sendHandshakeRequest(PEP_SESSION session, const Identity partner)
vb@623
    55
{
vb@623
    56
    PEP_STATUS status = PEP_STATUS_OK;
vb@623
    57
vb@650
    58
    assert(session);
vb@623
    59
    assert(partner);
vb@650
    60
    if (!(session && partner))
vb@623
    61
        return PEP_ILLEGAL_VALUE;
vb@623
    62
vb@650
    63
    HandshakeRequest_t *msg = (HandshakeRequest_t *) calloc(1, sizeof(HandshakeRequest_t));
vb@650
    64
    assert(msg);
vb@650
    65
    if (!msg)
vb@650
    66
        goto enomem;
vb@623
    67
vb@650
    68
    
vb@650
    69
    return status;
vb@623
    70
vb@650
    71
enomem:
vb@650
    72
    status = PEP_OUT_OF_MEMORY;
vb@650
    73
error:
vb@650
    74
    ASN_STRUCT_FREE(asn_DEF_HandshakeRequest, msg);
vb@623
    75
    return status;
vb@623
    76
}
vb@623
    77
vb@650
    78
vb@650
    79
// showHandshake() - send
vb@623
    80
//
vb@623
    81
//  params:
vb@627
    82
//      session (in)        session handle
vb@623
    83
//      partner (in)        partner in sync
vb@623
    84
//
vb@623
    85
//  returns:
vb@623
    86
//      PEP_STATUS_OK or any other value on error
vb@623
    87
vb@627
    88
PEP_STATUS showHandshake(PEP_SESSION session, const Identity partner)
vb@623
    89
{
vb@623
    90
    PEP_STATUS status = PEP_STATUS_OK;
vb@623
    91
vb@650
    92
    assert(session);
vb@623
    93
    assert(partner);
vb@650
    94
    if (!(session && partner))
vb@623
    95
        return PEP_ILLEGAL_VALUE;
vb@623
    96
vb@623
    97
    // working code
vb@623
    98
vb@623
    99
vb@623
   100
    return status;
vb@650
   101
vb@650
   102
enomem:
vb@650
   103
    status = PEP_OUT_OF_MEMORY;
vb@650
   104
error:
vb@650
   105
    // free...
vb@650
   106
    return status;
vb@623
   107
}
vb@623
   108
vb@650
   109
vb@650
   110
// reject() - send
vb@623
   111
//
vb@623
   112
//  params:
vb@627
   113
//      session (in)        session handle
vb@623
   114
//      partner (in)        partner in sync
vb@623
   115
//
vb@623
   116
//  returns:
vb@623
   117
//      PEP_STATUS_OK or any other value on error
vb@623
   118
vb@627
   119
PEP_STATUS reject(PEP_SESSION session, const Identity partner)
vb@623
   120
{
vb@623
   121
    PEP_STATUS status = PEP_STATUS_OK;
vb@623
   122
vb@650
   123
    assert(session);
vb@623
   124
    assert(partner);
vb@650
   125
    if (!(session && partner))
vb@623
   126
        return PEP_ILLEGAL_VALUE;
vb@623
   127
vb@623
   128
    // working code
vb@623
   129
vb@623
   130
vb@623
   131
    return status;
vb@650
   132
vb@650
   133
enomem:
vb@650
   134
    status = PEP_OUT_OF_MEMORY;
vb@650
   135
error:
vb@650
   136
    // free...
vb@650
   137
    return status;
vb@623
   138
}
vb@623
   139
vb@650
   140
vb@650
   141
// storeGroupKeys() - send
vb@623
   142
//
vb@623
   143
//  params:
vb@627
   144
//      session (in)        session handle
vb@623
   145
//      partner (in)        partner in sync
vb@623
   146
//
vb@623
   147
//  returns:
vb@623
   148
//      PEP_STATUS_OK or any other value on error
vb@623
   149
vb@627
   150
PEP_STATUS storeGroupKeys(PEP_SESSION session, const Identity partner)
vb@623
   151
{
vb@623
   152
    PEP_STATUS status = PEP_STATUS_OK;
vb@623
   153
vb@650
   154
    assert(session);
vb@623
   155
    assert(partner);
vb@650
   156
    if (!(session && partner))
vb@623
   157
        return PEP_ILLEGAL_VALUE;
vb@623
   158
vb@623
   159
    // working code
vb@623
   160
vb@623
   161
vb@623
   162
    return status;
vb@650
   163
vb@650
   164
enomem:
vb@650
   165
    status = PEP_OUT_OF_MEMORY;
vb@650
   166
error:
vb@650
   167
    // free...
vb@650
   168
    return status;
vb@623
   169
}
vb@623
   170
vb@650
   171
vb@650
   172
// sendOwnKeys() - send OwnKeys message
vb@623
   173
//
vb@623
   174
//  params:
vb@627
   175
//      session (in)        session handle
vb@623
   176
//      partner (in)        (must be NULL)
vb@623
   177
//
vb@623
   178
//  returns:
vb@623
   179
//      PEP_STATUS_OK or any other value on error
vb@623
   180
vb@627
   181
PEP_STATUS sendOwnKeys(PEP_SESSION session, const Identity partner)
vb@623
   182
{
vb@623
   183
    PEP_STATUS status = PEP_STATUS_OK;
vb@623
   184
vb@650
   185
    assert(session);
vb@650
   186
    assert(!partner);
vb@650
   187
    if (!(session && !partner))
vb@623
   188
        return PEP_ILLEGAL_VALUE;
vb@623
   189
vb@650
   190
    OwnKeys_t *msg = (OwnKeys_t *) calloc(1, sizeof(OwnKeys_t));
vb@650
   191
    assert(msg);
vb@650
   192
    if (!msg)
vb@650
   193
        goto enomem;
vb@623
   194
vb@650
   195
    
vb@650
   196
    return status;
vb@623
   197
vb@650
   198
enomem:
vb@650
   199
    status = PEP_OUT_OF_MEMORY;
vb@650
   200
error:
vb@650
   201
    ASN_STRUCT_FREE(asn_DEF_OwnKeys, msg);
vb@623
   202
    return status;
vb@623
   203
}
vb@623
   204
vb@650
   205
vb@650
   206
// transmitGroupKeys() - send
vb@623
   207
//
vb@623
   208
//  params:
vb@627
   209
//      session (in)        session handle
vb@623
   210
//      partner (in)        partner in sync
vb@623
   211
//
vb@623
   212
//  returns:
vb@623
   213
//      PEP_STATUS_OK or any other value on error
vb@623
   214
vb@627
   215
PEP_STATUS transmitGroupKeys(PEP_SESSION session, const Identity partner)
vb@623
   216
{
vb@623
   217
    PEP_STATUS status = PEP_STATUS_OK;
vb@623
   218
vb@650
   219
    assert(session);
vb@623
   220
    assert(partner);
vb@650
   221
    if (!(session && partner))
vb@623
   222
        return PEP_ILLEGAL_VALUE;
vb@623
   223
vb@623
   224
    // working code
vb@623
   225
vb@623
   226
vb@623
   227
    return status;
vb@650
   228
vb@650
   229
enomem:
vb@650
   230
    status = PEP_OUT_OF_MEMORY;
vb@650
   231
error:
vb@650
   232
    // free...
vb@650
   233
    return status;
vb@623
   234
}
vb@623
   235