1 // Send Actions for DeviceState state machine
4 #include "pEp_internal.h"
5 #include "keymanagement.h"
8 #include "baseprotocol.h"
10 #include "../asn.1/DeviceGroup-Protocol.h"
11 #include "sync_impl.h"
12 #include "../asn.1/Beacon.h"
13 #include "../asn.1/HandshakeRequest.h"
14 #include "../asn.1/GroupKeys.h"
17 // sendBeacon() - send Beacon message
20 // session (in) session handle
21 // state (in) state the state machine is in
22 // partner (in) (must be NULL)
25 // PEP_STATUS_OK or any other value on error
27 PEP_STATUS sendBeacon(
29 DeviceState_state state,
34 assert(session && state);
35 if (!(session && state))
36 return PEP_ILLEGAL_VALUE;
38 PEP_STATUS status = PEP_STATUS_OK;
40 DeviceGroup_Protocol_t *msg = new_DeviceGroup_Protocol_msg(DeviceGroup_Protocol__payload_PR_beacon);
44 status = multicast_self_msg(session, state, msg);
45 if (status != PEP_STATUS_OK)
48 free_DeviceGroup_Protocol_msg(msg);
52 status = PEP_OUT_OF_MEMORY;
54 free_DeviceGroup_Protocol_msg(msg);
59 // sendHandshakeRequest() - send HandshakeRequest message
62 // session (in) session handle
63 // state (in) state the state machine is in
64 // partner (in) partner to communicate with
67 // PEP_STATUS_OK or any other value on error
69 PEP_STATUS sendHandshakeRequest(
71 DeviceState_state state,
76 assert(session && state);
77 if (!(session && state))
78 return PEP_ILLEGAL_VALUE;
80 PEP_STATUS status = PEP_STATUS_OK;
82 DeviceGroup_Protocol_t *msg = new_DeviceGroup_Protocol_msg(DeviceGroup_Protocol__payload_PR_handshakeRequest);
86 status = unicast_msg(session, partner, state, msg);
87 if (status != PEP_STATUS_OK)
90 free_DeviceGroup_Protocol_msg(msg);
94 status = PEP_OUT_OF_MEMORY;
96 free_DeviceGroup_Protocol_msg(msg);
101 // sendGroupKeys() - send GroupKeys message
104 // session (in) session handle
105 // state (in) state the state machine is in
106 // partner (in) (must be NULL)
109 // PEP_STATUS_OK or any other value on error
111 PEP_STATUS sendGroupKeys(
113 DeviceState_state state,
118 assert(session && state);
119 if (!(session && state))
120 return PEP_ILLEGAL_VALUE;
122 PEP_STATUS status = PEP_STATUS_OK;
123 identity_list *kl = new_identity_list(NULL);
125 DeviceGroup_Protocol_t *msg = new_DeviceGroup_Protocol_msg(DeviceGroup_Protocol__payload_PR_groupKeys);
129 status = own_identities_retrieve(session, &kl);
130 if (status != PEP_STATUS_OK)
132 if (IdentityList_from_identity_list(kl, &msg->payload.choice.groupKeys.ownIdentities) == NULL)
135 status = unicast_msg(session, partner, state, msg);
136 if (status != PEP_STATUS_OK)
139 free_identity_list(kl);
140 free_DeviceGroup_Protocol_msg(msg);
141 return PEP_STATUS_OK;
144 status = PEP_OUT_OF_MEMORY;
146 free_DeviceGroup_Protocol_msg(msg);
147 free_identity_list(kl);