sync/generated/sync_send_actions.c
changeset 2271 25bfd109320c
child 2287 026ab4dae779
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/sync/generated/sync_send_actions.c	Fri Nov 03 13:32:38 2017 +0100
     1.3 @@ -0,0 +1,521 @@
     1.4 +// Send Actions for DeviceState state machine
     1.5 +
     1.6 +#include <assert.h>
     1.7 +#include "pEp_internal.h"
     1.8 +#include "keymanagement.h"
     1.9 +#include "message.h"
    1.10 +#include "sync_fsm.h"
    1.11 +#include "baseprotocol.h"
    1.12 +#include "map_asn1.h"
    1.13 +#include "../asn.1/DeviceGroup-Protocol.h"
    1.14 +#include "sync_impl.h"
    1.15 +#include "../asn.1/Beacon.h"
    1.16 +#include "../asn.1/HandshakeRequest.h"
    1.17 +#include "../asn.1/GroupKeys.h"
    1.18 +#include "../asn.1/GroupUpdate.h"
    1.19 +#include "../asn.1/UpdateRequest.h"
    1.20 +
    1.21 +
    1.22 +// sendBeacon() - send Beacon message
    1.23 +//
    1.24 +//  params:
    1.25 +//      session (in)        session handle
    1.26 +//      state (in)          state the state machine is in
    1.27 +//      partner (in)        (must be NULL)
    1.28 +//
    1.29 +//  returns:
    1.30 +//      PEP_STATUS_OK or any other value on error
    1.31 +
    1.32 +PEP_STATUS sendBeacon(
    1.33 +        PEP_SESSION session,
    1.34 +        DeviceState_state state,
    1.35 +        Identity partner,
    1.36 +        void *extra
    1.37 +    )
    1.38 +{
    1.39 +    assert(session && state);
    1.40 +    if (!(session && state))
    1.41 +        return PEP_ILLEGAL_VALUE;
    1.42 +
    1.43 +    PEP_STATUS status = PEP_STATUS_OK;
    1.44 +
    1.45 +    DeviceGroup_Protocol_t *msg = new_DeviceGroup_Protocol_msg(DeviceGroup_Protocol__payload_PR_beacon);
    1.46 +    if (!msg)
    1.47 +        goto enomem;
    1.48 +
    1.49 +    bool encrypted = false;
    1.50 +    status = multicast_self_msg(session, state, msg, encrypted);
    1.51 +    if (status != PEP_STATUS_OK)
    1.52 +        goto error;
    1.53 +
    1.54 +    free_DeviceGroup_Protocol_msg(msg);
    1.55 +    return PEP_STATUS_OK;
    1.56 +
    1.57 +enomem:
    1.58 +    status = PEP_OUT_OF_MEMORY;
    1.59 +error:
    1.60 +    free_DeviceGroup_Protocol_msg(msg);
    1.61 +    return status;
    1.62 +}
    1.63 +
    1.64 +
    1.65 +// sendHandshakeRequest() - send HandshakeRequest message
    1.66 +//
    1.67 +//  params:
    1.68 +//      session (in)        session handle
    1.69 +//      state (in)          state the state machine is in
    1.70 +//      partner (in)        partner to communicate with
    1.71 +//
    1.72 +//  returns:
    1.73 +//      PEP_STATUS_OK or any other value on error
    1.74 +
    1.75 +PEP_STATUS sendHandshakeRequest(
    1.76 +        PEP_SESSION session,
    1.77 +        DeviceState_state state,
    1.78 +        Identity partner,
    1.79 +        void *extra
    1.80 +    )
    1.81 +{
    1.82 +    assert(session && state);
    1.83 +    if (!(session && state))
    1.84 +        return PEP_ILLEGAL_VALUE;
    1.85 +
    1.86 +    PEP_STATUS status = PEP_STATUS_OK;
    1.87 +
    1.88 +    DeviceGroup_Protocol_t *msg = new_DeviceGroup_Protocol_msg(DeviceGroup_Protocol__payload_PR_handshakeRequest);
    1.89 +    if (!msg)
    1.90 +        goto enomem;
    1.91 +
    1.92 +    msg->payload.choice.handshakeRequest.partner_id = 
    1.93 +        OCTET_STRING_new_fromBuf(&asn_DEF_UTF8String,
    1.94 +                                 partner->user_id, -1);
    1.95 +    if (partner->user_id && !msg->payload.choice.handshakeRequest.partner_id)
    1.96 +       goto enomem;
    1.97 +
    1.98 +    char *devgrp = NULL;
    1.99 +    status = get_device_group(session, &devgrp);
   1.100 +    if (status == PEP_STATUS_OK && devgrp && devgrp[0])
   1.101 +    msg->payload.choice.handshakeRequest.group_id = 
   1.102 +        OCTET_STRING_new_fromBuf(&asn_DEF_UTF8String,
   1.103 +                                 devgrp, -1);
   1.104 +    free(devgrp);
   1.105 +    if (devgrp && !msg->payload.choice.handshakeRequest.partner_id)
   1.106 +       goto enomem;
   1.107 +
   1.108 +    bool encrypted = true;
   1.109 +    status = unicast_msg(session, partner, state, msg, encrypted);
   1.110 +    if (status != PEP_STATUS_OK)
   1.111 +        goto error;
   1.112 +
   1.113 +    free_DeviceGroup_Protocol_msg(msg);
   1.114 +    return PEP_STATUS_OK;
   1.115 +
   1.116 +enomem:
   1.117 +    status = PEP_OUT_OF_MEMORY;
   1.118 +error:
   1.119 +    free_DeviceGroup_Protocol_msg(msg);
   1.120 +    return status;
   1.121 +}
   1.122 +
   1.123 +
   1.124 +// sendGroupKeys() - send GroupKeys message
   1.125 +//
   1.126 +//  params:
   1.127 +//      session (in)        session handle
   1.128 +//      state (in)          state the state machine is in
   1.129 +//      partner (in)        partner to communicate with
   1.130 +//
   1.131 +//  returns:
   1.132 +//      PEP_STATUS_OK or any other value on error
   1.133 +
   1.134 +PEP_STATUS sendGroupKeys(
   1.135 +        PEP_SESSION session,
   1.136 +        DeviceState_state state,
   1.137 +        Identity partner,
   1.138 +        void *extra
   1.139 +    )
   1.140 +{
   1.141 +    assert(session && state);
   1.142 +    if (!(session && state))
   1.143 +        return PEP_ILLEGAL_VALUE;
   1.144 +
   1.145 +    PEP_STATUS status = PEP_STATUS_OK;
   1.146 +    identity_list *kl = new_identity_list(NULL);
   1.147 +
   1.148 +    DeviceGroup_Protocol_t *msg = new_DeviceGroup_Protocol_msg(DeviceGroup_Protocol__payload_PR_groupKeys);
   1.149 +    if (!msg)
   1.150 +        goto enomem;
   1.151 +
   1.152 +    status = _own_identities_retrieve(session, &kl, PEP_idf_not_for_sync);
   1.153 +    if (status != PEP_STATUS_OK)
   1.154 +        goto error;
   1.155 +    if (IdentityList_from_identity_list(kl, &msg->payload.choice.groupKeys.ownIdentities) == NULL)
   1.156 +        goto enomem;
   1.157 +
   1.158 +    msg->payload.choice.groupKeys.partner_id = 
   1.159 +        OCTET_STRING_new_fromBuf(&asn_DEF_UTF8String,
   1.160 +                                 partner->user_id, -1);
   1.161 +    if (partner->user_id && !msg->payload.choice.groupKeys.partner_id)
   1.162 +       goto enomem;
   1.163 +
   1.164 +    char *devgrp = NULL;
   1.165 +    status = get_device_group(session, &devgrp);
   1.166 +    if (status == PEP_STATUS_OK && devgrp && devgrp[0])
   1.167 +    msg->payload.choice.groupKeys.group_id = 
   1.168 +        OCTET_STRING_new_fromBuf(&asn_DEF_UTF8String,
   1.169 +                                 devgrp, -1);
   1.170 +    free(devgrp);
   1.171 +    if (devgrp && !msg->payload.choice.groupKeys.partner_id)
   1.172 +       goto enomem;
   1.173 +
   1.174 +    bool encrypted = true;
   1.175 +    status = unicast_msg(session, partner, state, msg, encrypted);
   1.176 +    if (status != PEP_STATUS_OK)
   1.177 +        goto error;
   1.178 +
   1.179 +    free_identity_list(kl);
   1.180 +    free_DeviceGroup_Protocol_msg(msg);
   1.181 +    return PEP_STATUS_OK;
   1.182 +
   1.183 +enomem:
   1.184 +    status = PEP_OUT_OF_MEMORY;
   1.185 +error:
   1.186 +    free_DeviceGroup_Protocol_msg(msg);
   1.187 +    free_identity_list(kl);
   1.188 +    return status;
   1.189 +}
   1.190 +
   1.191 +
   1.192 +// sendGroupUpdate() - send GroupUpdate message
   1.193 +//
   1.194 +//  params:
   1.195 +//      session (in)        session handle
   1.196 +//      state (in)          state the state machine is in
   1.197 +//      partner (in)        (must be NULL)
   1.198 +//
   1.199 +//  returns:
   1.200 +//      PEP_STATUS_OK or any other value on error
   1.201 +
   1.202 +PEP_STATUS sendGroupUpdate(
   1.203 +        PEP_SESSION session,
   1.204 +        DeviceState_state state,
   1.205 +        Identity partner,
   1.206 +        void *extra
   1.207 +    )
   1.208 +{
   1.209 +    assert(session && state);
   1.210 +    if (!(session && state))
   1.211 +        return PEP_ILLEGAL_VALUE;
   1.212 +
   1.213 +    PEP_STATUS status = PEP_STATUS_OK;
   1.214 +    identity_list *kl = new_identity_list(NULL);
   1.215 +
   1.216 +    DeviceGroup_Protocol_t *msg = new_DeviceGroup_Protocol_msg(DeviceGroup_Protocol__payload_PR_groupUpdate);
   1.217 +    if (!msg)
   1.218 +        goto enomem;
   1.219 +
   1.220 +    status = _own_identities_retrieve(session, &kl, PEP_idf_not_for_sync);
   1.221 +    if (status != PEP_STATUS_OK)
   1.222 +        goto error;
   1.223 +    if (IdentityList_from_identity_list(kl, &msg->payload.choice.groupUpdate.ownIdentities) == NULL)
   1.224 +        goto enomem;
   1.225 +
   1.226 +    bool encrypted = true;
   1.227 +    status = multicast_self_msg(session, state, msg, encrypted);
   1.228 +    if (status != PEP_STATUS_OK)
   1.229 +        goto error;
   1.230 +
   1.231 +    free_identity_list(kl);
   1.232 +    free_DeviceGroup_Protocol_msg(msg);
   1.233 +    return PEP_STATUS_OK;
   1.234 +
   1.235 +enomem:
   1.236 +    status = PEP_OUT_OF_MEMORY;
   1.237 +error:
   1.238 +    free_DeviceGroup_Protocol_msg(msg);
   1.239 +    return status;
   1.240 +}
   1.241 +
   1.242 +
   1.243 +// sendUpdateRequest() - send UpdateRequest message
   1.244 +//
   1.245 +//  params:
   1.246 +//      session (in)        session handle
   1.247 +//      state (in)          state the state machine is in
   1.248 +//      partner (in)        (must be NULL)
   1.249 +//
   1.250 +//  returns:
   1.251 +//      PEP_STATUS_OK or any other value on error
   1.252 +
   1.253 +PEP_STATUS sendUpdateRequest(
   1.254 +        PEP_SESSION session,
   1.255 +        DeviceState_state state,
   1.256 +        Identity partner,
   1.257 +        void *extra
   1.258 +    )
   1.259 +{
   1.260 +    assert(session && state);
   1.261 +    if (!(session && state))
   1.262 +        return PEP_ILLEGAL_VALUE;
   1.263 +
   1.264 +    PEP_STATUS status = PEP_STATUS_OK;
   1.265 +
   1.266 +    DeviceGroup_Protocol_t *msg = new_DeviceGroup_Protocol_msg(DeviceGroup_Protocol__payload_PR_updateRequest);
   1.267 +    if (!msg)
   1.268 +        goto enomem;
   1.269 +
   1.270 +    bool encrypted = true;
   1.271 +    status = multicast_self_msg(session, state, msg, encrypted);
   1.272 +    if (status != PEP_STATUS_OK)
   1.273 +        goto error;
   1.274 +
   1.275 +    free_DeviceGroup_Protocol_msg(msg);
   1.276 +    return PEP_STATUS_OK;
   1.277 +
   1.278 +enomem:
   1.279 +    status = PEP_OUT_OF_MEMORY;
   1.280 +error:
   1.281 +    free_DeviceGroup_Protocol_msg(msg);
   1.282 +    return status;
   1.283 +}
   1.284 +
   1.285 +
   1.286 +PEP_STATUS _notifyHandshake(
   1.287 +        PEP_SESSION session,
   1.288 +        Identity partner,
   1.289 +        sync_handshake_signal signal
   1.290 +    );
   1.291 +
   1.292 +// notifyInitFormGroup() - notify InitFormGroup to app
   1.293 +//
   1.294 +//  params:
   1.295 +//      session (in)        session handle
   1.296 +//      state (in)          state the state machine is in
   1.297 +//      partner (in)        partner to communicate with
   1.298 +//
   1.299 +//  returns:
   1.300 +//      PEP_STATUS_OK or any other value on error
   1.301 +
   1.302 +PEP_STATUS notifyInitFormGroup(
   1.303 +        PEP_SESSION session,
   1.304 +        DeviceState_state state,
   1.305 +        Identity partner,
   1.306 +        void *extra
   1.307 +    )
   1.308 +{
   1.309 +    assert(session && state);
   1.310 +    assert(extra == NULL);
   1.311 +    if (!(session && state && extra == NULL))
   1.312 +        return PEP_ILLEGAL_VALUE;
   1.313 +
   1.314 +    return _notifyHandshake(session, partner, SYNC_NOTIFY_INIT_FORM_GROUP);
   1.315 +}
   1.316 +
   1.317 +
   1.318 +// notifyInitAddOurDevice() - notify InitAddOurDevice to app
   1.319 +//
   1.320 +//  params:
   1.321 +//      session (in)        session handle
   1.322 +//      state (in)          state the state machine is in
   1.323 +//      partner (in)        partner to communicate with
   1.324 +//
   1.325 +//  returns:
   1.326 +//      PEP_STATUS_OK or any other value on error
   1.327 +
   1.328 +PEP_STATUS notifyInitAddOurDevice(
   1.329 +        PEP_SESSION session,
   1.330 +        DeviceState_state state,
   1.331 +        Identity partner,
   1.332 +        void *extra
   1.333 +    )
   1.334 +{
   1.335 +    assert(session && state);
   1.336 +    assert(extra == NULL);
   1.337 +    if (!(session && state && extra == NULL))
   1.338 +        return PEP_ILLEGAL_VALUE;
   1.339 +
   1.340 +    return _notifyHandshake(session, partner, SYNC_NOTIFY_INIT_ADD_OUR_DEVICE);
   1.341 +}
   1.342 +
   1.343 +
   1.344 +// notifyAcceptedGroupCreated() - notify AcceptedGroupCreated to app
   1.345 +//
   1.346 +//  params:
   1.347 +//      session (in)        session handle
   1.348 +//      state (in)          state the state machine is in
   1.349 +//      partner (in)        partner to communicate with
   1.350 +//
   1.351 +//  returns:
   1.352 +//      PEP_STATUS_OK or any other value on error
   1.353 +
   1.354 +PEP_STATUS notifyAcceptedGroupCreated(
   1.355 +        PEP_SESSION session,
   1.356 +        DeviceState_state state,
   1.357 +        Identity partner,
   1.358 +        void *extra
   1.359 +    )
   1.360 +{
   1.361 +    assert(session && state);
   1.362 +    assert(extra == NULL);
   1.363 +    if (!(session && state && extra == NULL))
   1.364 +        return PEP_ILLEGAL_VALUE;
   1.365 +
   1.366 +    return _notifyHandshake(session, partner, SYNC_NOTIFY_ACCEPTED_GROUP_CREATED);
   1.367 +}
   1.368 +
   1.369 +
   1.370 +// notifyTimeout() - notify Timeout to app
   1.371 +//
   1.372 +//  params:
   1.373 +//      session (in)        session handle
   1.374 +//      state (in)          state the state machine is in
   1.375 +//      partner (in)        partner to communicate with
   1.376 +//
   1.377 +//  returns:
   1.378 +//      PEP_STATUS_OK or any other value on error
   1.379 +
   1.380 +PEP_STATUS notifyTimeout(
   1.381 +        PEP_SESSION session,
   1.382 +        DeviceState_state state,
   1.383 +        Identity partner,
   1.384 +        void *extra
   1.385 +    )
   1.386 +{
   1.387 +    assert(session && state);
   1.388 +    assert(extra == NULL);
   1.389 +    if (!(session && state && extra == NULL))
   1.390 +        return PEP_ILLEGAL_VALUE;
   1.391 +
   1.392 +    return _notifyHandshake(session, partner, SYNC_NOTIFY_TIMEOUT);
   1.393 +}
   1.394 +
   1.395 +
   1.396 +// notifyAcceptedDeviceAdded() - notify AcceptedDeviceAdded to app
   1.397 +//
   1.398 +//  params:
   1.399 +//      session (in)        session handle
   1.400 +//      state (in)          state the state machine is in
   1.401 +//      partner (in)        partner to communicate with
   1.402 +//
   1.403 +//  returns:
   1.404 +//      PEP_STATUS_OK or any other value on error
   1.405 +
   1.406 +PEP_STATUS notifyAcceptedDeviceAdded(
   1.407 +        PEP_SESSION session,
   1.408 +        DeviceState_state state,
   1.409 +        Identity partner,
   1.410 +        void *extra
   1.411 +    )
   1.412 +{
   1.413 +    assert(session && state);
   1.414 +    assert(extra == NULL);
   1.415 +    if (!(session && state && extra == NULL))
   1.416 +        return PEP_ILLEGAL_VALUE;
   1.417 +
   1.418 +    return _notifyHandshake(session, partner, SYNC_NOTIFY_ACCEPTED_DEVICE_ADDED);
   1.419 +}
   1.420 +
   1.421 +
   1.422 +// notifyInitAddOtherDevice() - notify InitAddOtherDevice to app
   1.423 +//
   1.424 +//  params:
   1.425 +//      session (in)        session handle
   1.426 +//      state (in)          state the state machine is in
   1.427 +//      partner (in)        partner to communicate with
   1.428 +//
   1.429 +//  returns:
   1.430 +//      PEP_STATUS_OK or any other value on error
   1.431 +
   1.432 +PEP_STATUS notifyInitAddOtherDevice(
   1.433 +        PEP_SESSION session,
   1.434 +        DeviceState_state state,
   1.435 +        Identity partner,
   1.436 +        void *extra
   1.437 +    )
   1.438 +{
   1.439 +    assert(session && state);
   1.440 +    assert(extra == NULL);
   1.441 +    if (!(session && state && extra == NULL))
   1.442 +        return PEP_ILLEGAL_VALUE;
   1.443 +
   1.444 +    return _notifyHandshake(session, partner, SYNC_NOTIFY_INIT_ADD_OTHER_DEVICE);
   1.445 +}
   1.446 +
   1.447 +
   1.448 +// notifyInitMoveOurDevice() - notify InitMoveOurDevice to app
   1.449 +//
   1.450 +//  params:
   1.451 +//      session (in)        session handle
   1.452 +//      state (in)          state the state machine is in
   1.453 +//      partner (in)        partner to communicate with
   1.454 +//
   1.455 +//  returns:
   1.456 +//      PEP_STATUS_OK or any other value on error
   1.457 +
   1.458 +PEP_STATUS notifyInitMoveOurDevice(
   1.459 +        PEP_SESSION session,
   1.460 +        DeviceState_state state,
   1.461 +        Identity partner,
   1.462 +        void *extra
   1.463 +    )
   1.464 +{
   1.465 +    assert(session && state);
   1.466 +    assert(extra == NULL);
   1.467 +    if (!(session && state && extra == NULL))
   1.468 +        return PEP_ILLEGAL_VALUE;
   1.469 +
   1.470 +    return _notifyHandshake(session, partner, SYNC_NOTIFY_INIT_MOVE_OUR_DEVICE);
   1.471 +}
   1.472 +
   1.473 +
   1.474 +// notifyOvertaken() - notify Overtaken to app
   1.475 +//
   1.476 +//  params:
   1.477 +//      session (in)        session handle
   1.478 +//      state (in)          state the state machine is in
   1.479 +//      partner (in)        partner to communicate with
   1.480 +//
   1.481 +//  returns:
   1.482 +//      PEP_STATUS_OK or any other value on error
   1.483 +
   1.484 +PEP_STATUS notifyOvertaken(
   1.485 +        PEP_SESSION session,
   1.486 +        DeviceState_state state,
   1.487 +        Identity partner,
   1.488 +        void *extra
   1.489 +    )
   1.490 +{
   1.491 +    assert(session && state);
   1.492 +    assert(extra == NULL);
   1.493 +    if (!(session && state && extra == NULL))
   1.494 +        return PEP_ILLEGAL_VALUE;
   1.495 +
   1.496 +    return _notifyHandshake(session, partner, SYNC_NOTIFY_OVERTAKEN);
   1.497 +}
   1.498 +
   1.499 +
   1.500 +// notifyAcceptedDeviceMoved() - notify AcceptedDeviceMoved to app
   1.501 +//
   1.502 +//  params:
   1.503 +//      session (in)        session handle
   1.504 +//      state (in)          state the state machine is in
   1.505 +//      partner (in)        partner to communicate with
   1.506 +//
   1.507 +//  returns:
   1.508 +//      PEP_STATUS_OK or any other value on error
   1.509 +
   1.510 +PEP_STATUS notifyAcceptedDeviceMoved(
   1.511 +        PEP_SESSION session,
   1.512 +        DeviceState_state state,
   1.513 +        Identity partner,
   1.514 +        void *extra
   1.515 +    )
   1.516 +{
   1.517 +    assert(session && state);
   1.518 +    assert(extra == NULL);
   1.519 +    if (!(session && state && extra == NULL))
   1.520 +        return PEP_ILLEGAL_VALUE;
   1.521 +
   1.522 +    return _notifyHandshake(session, partner, SYNC_NOTIFY_ACCEPTED_DEVICE_MOVED);
   1.523 +}
   1.524 +