src/sync_actions.c
changeset 650 accc0ad7d32c
parent 627 ef1fdfde8ced
child 652 ccc02be8a27d
     1.1 --- a/src/sync_actions.c	Tue May 17 21:48:49 2016 +0200
     1.2 +++ b/src/sync_actions.c	Wed May 18 00:05:39 2016 +0200
     1.3 @@ -2,9 +2,13 @@
     1.4  
     1.5  #include <assert.h>
     1.6  #include "sync_fsm.h"
     1.7 +#include "map_asn1.h"
     1.8 +#include "../asn.1/Beacon.h"
     1.9 +#include "../asn.1/HandshakeRequest.h"
    1.10 +#include "../asn.1/OwnKeys.h"
    1.11  
    1.12  
    1.13 -// sendBeacon() - 
    1.14 +// sendBeacon() - send Beacon message
    1.15  //
    1.16  //  params:
    1.17  //      session (in)        session handle
    1.18 @@ -17,17 +21,28 @@
    1.19  {
    1.20      PEP_STATUS status = PEP_STATUS_OK;
    1.21  
    1.22 -    assert(partner == NULL);
    1.23 -    if (partner)
    1.24 +    assert(session);
    1.25 +    assert(!partner);
    1.26 +    if (!(session && !partner))
    1.27          return PEP_ILLEGAL_VALUE;
    1.28  
    1.29 -    // working code
    1.30 +    Beacon_t *msg = (Beacon_t *) calloc(1, sizeof(Beacon_t));
    1.31 +    assert(msg);
    1.32 +    if (!msg)
    1.33 +        goto enomem;
    1.34  
    1.35 +    
    1.36 +    return status;
    1.37  
    1.38 +enomem:
    1.39 +    status = PEP_OUT_OF_MEMORY;
    1.40 +error:
    1.41 +    ASN_STRUCT_FREE(asn_DEF_Beacon, msg);
    1.42      return status;
    1.43  }
    1.44  
    1.45 -// sendHandshakeRequest() - 
    1.46 +
    1.47 +// sendHandshakeRequest() - send HandshakeRequest message
    1.48  //
    1.49  //  params:
    1.50  //      session (in)        session handle
    1.51 @@ -40,17 +55,28 @@
    1.52  {
    1.53      PEP_STATUS status = PEP_STATUS_OK;
    1.54  
    1.55 +    assert(session);
    1.56      assert(partner);
    1.57 -    if (!partner)
    1.58 +    if (!(session && partner))
    1.59          return PEP_ILLEGAL_VALUE;
    1.60  
    1.61 -    // working code
    1.62 +    HandshakeRequest_t *msg = (HandshakeRequest_t *) calloc(1, sizeof(HandshakeRequest_t));
    1.63 +    assert(msg);
    1.64 +    if (!msg)
    1.65 +        goto enomem;
    1.66  
    1.67 +    
    1.68 +    return status;
    1.69  
    1.70 +enomem:
    1.71 +    status = PEP_OUT_OF_MEMORY;
    1.72 +error:
    1.73 +    ASN_STRUCT_FREE(asn_DEF_HandshakeRequest, msg);
    1.74      return status;
    1.75  }
    1.76  
    1.77 -// showHandshake() - 
    1.78 +
    1.79 +// showHandshake() - send
    1.80  //
    1.81  //  params:
    1.82  //      session (in)        session handle
    1.83 @@ -63,17 +89,25 @@
    1.84  {
    1.85      PEP_STATUS status = PEP_STATUS_OK;
    1.86  
    1.87 +    assert(session);
    1.88      assert(partner);
    1.89 -    if (!partner)
    1.90 +    if (!(session && partner))
    1.91          return PEP_ILLEGAL_VALUE;
    1.92  
    1.93      // working code
    1.94  
    1.95  
    1.96      return status;
    1.97 +
    1.98 +enomem:
    1.99 +    status = PEP_OUT_OF_MEMORY;
   1.100 +error:
   1.101 +    // free...
   1.102 +    return status;
   1.103  }
   1.104  
   1.105 -// reject() - 
   1.106 +
   1.107 +// reject() - send
   1.108  //
   1.109  //  params:
   1.110  //      session (in)        session handle
   1.111 @@ -86,17 +120,25 @@
   1.112  {
   1.113      PEP_STATUS status = PEP_STATUS_OK;
   1.114  
   1.115 +    assert(session);
   1.116      assert(partner);
   1.117 -    if (!partner)
   1.118 +    if (!(session && partner))
   1.119          return PEP_ILLEGAL_VALUE;
   1.120  
   1.121      // working code
   1.122  
   1.123  
   1.124      return status;
   1.125 +
   1.126 +enomem:
   1.127 +    status = PEP_OUT_OF_MEMORY;
   1.128 +error:
   1.129 +    // free...
   1.130 +    return status;
   1.131  }
   1.132  
   1.133 -// storeGroupKeys() - 
   1.134 +
   1.135 +// storeGroupKeys() - send
   1.136  //
   1.137  //  params:
   1.138  //      session (in)        session handle
   1.139 @@ -109,17 +151,25 @@
   1.140  {
   1.141      PEP_STATUS status = PEP_STATUS_OK;
   1.142  
   1.143 +    assert(session);
   1.144      assert(partner);
   1.145 -    if (!partner)
   1.146 +    if (!(session && partner))
   1.147          return PEP_ILLEGAL_VALUE;
   1.148  
   1.149      // working code
   1.150  
   1.151  
   1.152      return status;
   1.153 +
   1.154 +enomem:
   1.155 +    status = PEP_OUT_OF_MEMORY;
   1.156 +error:
   1.157 +    // free...
   1.158 +    return status;
   1.159  }
   1.160  
   1.161 -// sendOwnKeys() - 
   1.162 +
   1.163 +// sendOwnKeys() - send OwnKeys message
   1.164  //
   1.165  //  params:
   1.166  //      session (in)        session handle
   1.167 @@ -132,17 +182,28 @@
   1.168  {
   1.169      PEP_STATUS status = PEP_STATUS_OK;
   1.170  
   1.171 -    assert(partner == NULL);
   1.172 -    if (partner)
   1.173 +    assert(session);
   1.174 +    assert(!partner);
   1.175 +    if (!(session && !partner))
   1.176          return PEP_ILLEGAL_VALUE;
   1.177  
   1.178 -    // working code
   1.179 +    OwnKeys_t *msg = (OwnKeys_t *) calloc(1, sizeof(OwnKeys_t));
   1.180 +    assert(msg);
   1.181 +    if (!msg)
   1.182 +        goto enomem;
   1.183  
   1.184 +    
   1.185 +    return status;
   1.186  
   1.187 +enomem:
   1.188 +    status = PEP_OUT_OF_MEMORY;
   1.189 +error:
   1.190 +    ASN_STRUCT_FREE(asn_DEF_OwnKeys, msg);
   1.191      return status;
   1.192  }
   1.193  
   1.194 -// transmitGroupKeys() - 
   1.195 +
   1.196 +// transmitGroupKeys() - send
   1.197  //
   1.198  //  params:
   1.199  //      session (in)        session handle
   1.200 @@ -155,13 +216,20 @@
   1.201  {
   1.202      PEP_STATUS status = PEP_STATUS_OK;
   1.203  
   1.204 +    assert(session);
   1.205      assert(partner);
   1.206 -    if (!partner)
   1.207 +    if (!(session && partner))
   1.208          return PEP_ILLEGAL_VALUE;
   1.209  
   1.210      // working code
   1.211  
   1.212  
   1.213      return status;
   1.214 +
   1.215 +enomem:
   1.216 +    status = PEP_OUT_OF_MEMORY;
   1.217 +error:
   1.218 +    // free...
   1.219 +    return status;
   1.220  }
   1.221