src/sync_actions.c
author Volker Birk <vb@pep-project.org>
Wed, 18 May 2016 12:21:06 +0200
changeset 652 ccc02be8a27d
parent 650 accc0ad7d32c
child 653 a9752fd8d54c
permissions -rw-r--r--
int32_t for sequence
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@652
    34
    int32_t seq;
vb@652
    35
    status = sequence_value(session, "DeviceGroup", &seq);
vb@652
    36
    if (status != PEP_STATUS_OK)
vb@652
    37
        goto error;
vb@652
    38
vb@652
    39
    INTEGER_t *sequence = (INTEGER_t *) calloc(1, sizeof(INTEGER_t));
vb@652
    40
    assert(sequence);
vb@652
    41
    if (!sequence)
vb@652
    42
        goto enomem;
vb@652
    43
    msg->header.sequence = seq;
vb@652
    44
vb@650
    45
    return status;
vb@623
    46
vb@650
    47
enomem:
vb@650
    48
    status = PEP_OUT_OF_MEMORY;
vb@650
    49
error:
vb@650
    50
    ASN_STRUCT_FREE(asn_DEF_Beacon, msg);
vb@623
    51
    return status;
vb@623
    52
}
vb@623
    53
vb@650
    54
vb@650
    55
// sendHandshakeRequest() - send HandshakeRequest message
vb@623
    56
//
vb@623
    57
//  params:
vb@627
    58
//      session (in)        session handle
vb@623
    59
//      partner (in)        partner in sync
vb@623
    60
//
vb@623
    61
//  returns:
vb@623
    62
//      PEP_STATUS_OK or any other value on error
vb@623
    63
vb@627
    64
PEP_STATUS sendHandshakeRequest(PEP_SESSION session, const Identity partner)
vb@623
    65
{
vb@623
    66
    PEP_STATUS status = PEP_STATUS_OK;
vb@623
    67
vb@650
    68
    assert(session);
vb@623
    69
    assert(partner);
vb@650
    70
    if (!(session && partner))
vb@623
    71
        return PEP_ILLEGAL_VALUE;
vb@623
    72
vb@650
    73
    HandshakeRequest_t *msg = (HandshakeRequest_t *) calloc(1, sizeof(HandshakeRequest_t));
vb@650
    74
    assert(msg);
vb@650
    75
    if (!msg)
vb@650
    76
        goto enomem;
vb@623
    77
vb@652
    78
    int32_t seq;
vb@652
    79
    status = sequence_value(session, "DeviceGroup", &seq);
vb@652
    80
    if (status != PEP_STATUS_OK)
vb@652
    81
        goto error;
vb@652
    82
vb@652
    83
    INTEGER_t *sequence = (INTEGER_t *) calloc(1, sizeof(INTEGER_t));
vb@652
    84
    assert(sequence);
vb@652
    85
    if (!sequence)
vb@652
    86
        goto enomem;
vb@652
    87
    msg->header.sequence = seq;
vb@652
    88
vb@650
    89
    return status;
vb@623
    90
vb@650
    91
enomem:
vb@650
    92
    status = PEP_OUT_OF_MEMORY;
vb@650
    93
error:
vb@650
    94
    ASN_STRUCT_FREE(asn_DEF_HandshakeRequest, msg);
vb@623
    95
    return status;
vb@623
    96
}
vb@623
    97
vb@650
    98
vb@650
    99
// showHandshake() - send
vb@623
   100
//
vb@623
   101
//  params:
vb@627
   102
//      session (in)        session handle
vb@623
   103
//      partner (in)        partner in sync
vb@623
   104
//
vb@623
   105
//  returns:
vb@623
   106
//      PEP_STATUS_OK or any other value on error
vb@623
   107
vb@627
   108
PEP_STATUS showHandshake(PEP_SESSION session, const Identity partner)
vb@623
   109
{
vb@623
   110
    PEP_STATUS status = PEP_STATUS_OK;
vb@623
   111
vb@650
   112
    assert(session);
vb@623
   113
    assert(partner);
vb@650
   114
    if (!(session && partner))
vb@623
   115
        return PEP_ILLEGAL_VALUE;
vb@623
   116
vb@623
   117
    // working code
vb@623
   118
vb@623
   119
vb@623
   120
    return status;
vb@650
   121
vb@650
   122
enomem:
vb@650
   123
    status = PEP_OUT_OF_MEMORY;
vb@650
   124
error:
vb@650
   125
    // free...
vb@650
   126
    return status;
vb@623
   127
}
vb@623
   128
vb@650
   129
vb@650
   130
// reject() - send
vb@623
   131
//
vb@623
   132
//  params:
vb@627
   133
//      session (in)        session handle
vb@623
   134
//      partner (in)        partner in sync
vb@623
   135
//
vb@623
   136
//  returns:
vb@623
   137
//      PEP_STATUS_OK or any other value on error
vb@623
   138
vb@627
   139
PEP_STATUS reject(PEP_SESSION session, const Identity partner)
vb@623
   140
{
vb@623
   141
    PEP_STATUS status = PEP_STATUS_OK;
vb@623
   142
vb@650
   143
    assert(session);
vb@623
   144
    assert(partner);
vb@650
   145
    if (!(session && partner))
vb@623
   146
        return PEP_ILLEGAL_VALUE;
vb@623
   147
vb@623
   148
    // working code
vb@623
   149
vb@623
   150
vb@623
   151
    return status;
vb@650
   152
vb@650
   153
enomem:
vb@650
   154
    status = PEP_OUT_OF_MEMORY;
vb@650
   155
error:
vb@650
   156
    // free...
vb@650
   157
    return status;
vb@623
   158
}
vb@623
   159
vb@650
   160
vb@650
   161
// storeGroupKeys() - send
vb@623
   162
//
vb@623
   163
//  params:
vb@627
   164
//      session (in)        session handle
vb@623
   165
//      partner (in)        partner in sync
vb@623
   166
//
vb@623
   167
//  returns:
vb@623
   168
//      PEP_STATUS_OK or any other value on error
vb@623
   169
vb@627
   170
PEP_STATUS storeGroupKeys(PEP_SESSION session, const Identity partner)
vb@623
   171
{
vb@623
   172
    PEP_STATUS status = PEP_STATUS_OK;
vb@623
   173
vb@650
   174
    assert(session);
vb@623
   175
    assert(partner);
vb@650
   176
    if (!(session && partner))
vb@623
   177
        return PEP_ILLEGAL_VALUE;
vb@623
   178
vb@623
   179
    // working code
vb@623
   180
vb@623
   181
vb@623
   182
    return status;
vb@650
   183
vb@650
   184
enomem:
vb@650
   185
    status = PEP_OUT_OF_MEMORY;
vb@650
   186
error:
vb@650
   187
    // free...
vb@650
   188
    return status;
vb@623
   189
}
vb@623
   190
vb@650
   191
vb@650
   192
// sendOwnKeys() - send OwnKeys message
vb@623
   193
//
vb@623
   194
//  params:
vb@627
   195
//      session (in)        session handle
vb@623
   196
//      partner (in)        (must be NULL)
vb@623
   197
//
vb@623
   198
//  returns:
vb@623
   199
//      PEP_STATUS_OK or any other value on error
vb@623
   200
vb@627
   201
PEP_STATUS sendOwnKeys(PEP_SESSION session, const Identity partner)
vb@623
   202
{
vb@623
   203
    PEP_STATUS status = PEP_STATUS_OK;
vb@623
   204
vb@650
   205
    assert(session);
vb@650
   206
    assert(!partner);
vb@650
   207
    if (!(session && !partner))
vb@623
   208
        return PEP_ILLEGAL_VALUE;
vb@623
   209
vb@650
   210
    OwnKeys_t *msg = (OwnKeys_t *) calloc(1, sizeof(OwnKeys_t));
vb@650
   211
    assert(msg);
vb@650
   212
    if (!msg)
vb@650
   213
        goto enomem;
vb@623
   214
vb@652
   215
    int32_t seq;
vb@652
   216
    status = sequence_value(session, "DeviceGroup", &seq);
vb@652
   217
    if (status != PEP_STATUS_OK)
vb@652
   218
        goto error;
vb@652
   219
vb@652
   220
    INTEGER_t *sequence = (INTEGER_t *) calloc(1, sizeof(INTEGER_t));
vb@652
   221
    assert(sequence);
vb@652
   222
    if (!sequence)
vb@652
   223
        goto enomem;
vb@652
   224
    msg->header.sequence = seq;
vb@652
   225
vb@650
   226
    return status;
vb@623
   227
vb@650
   228
enomem:
vb@650
   229
    status = PEP_OUT_OF_MEMORY;
vb@650
   230
error:
vb@650
   231
    ASN_STRUCT_FREE(asn_DEF_OwnKeys, msg);
vb@623
   232
    return status;
vb@623
   233
}
vb@623
   234
vb@650
   235
vb@650
   236
// transmitGroupKeys() - send
vb@623
   237
//
vb@623
   238
//  params:
vb@627
   239
//      session (in)        session handle
vb@623
   240
//      partner (in)        partner in sync
vb@623
   241
//
vb@623
   242
//  returns:
vb@623
   243
//      PEP_STATUS_OK or any other value on error
vb@623
   244
vb@627
   245
PEP_STATUS transmitGroupKeys(PEP_SESSION session, const Identity partner)
vb@623
   246
{
vb@623
   247
    PEP_STATUS status = PEP_STATUS_OK;
vb@623
   248
vb@650
   249
    assert(session);
vb@623
   250
    assert(partner);
vb@650
   251
    if (!(session && partner))
vb@623
   252
        return PEP_ILLEGAL_VALUE;
vb@623
   253
vb@623
   254
    // working code
vb@623
   255
vb@623
   256
vb@623
   257
    return status;
vb@650
   258
vb@650
   259
enomem:
vb@650
   260
    status = PEP_OUT_OF_MEMORY;
vb@650
   261
error:
vb@650
   262
    // free...
vb@650
   263
    return status;
vb@623
   264
}
vb@623
   265