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 bool encrypted = false;
45 status = multicast_self_msg(session, state, msg, encrypted);
46 if (status != PEP_STATUS_OK)
49 free_DeviceGroup_Protocol_msg(msg);
50 free_identity(partner);
54 status = PEP_OUT_OF_MEMORY;
56 free_identity(partner);
57 free_DeviceGroup_Protocol_msg(msg);
62 // sendHandshakeRequest() - send HandshakeRequest message
65 // session (in) session handle
66 // state (in) state the state machine is in
67 // partner (in) partner to communicate with
70 // PEP_STATUS_OK or any other value on error
72 PEP_STATUS sendHandshakeRequest(
74 DeviceState_state state,
79 assert(session && state);
80 if (!(session && state))
81 return PEP_ILLEGAL_VALUE;
83 PEP_STATUS status = PEP_STATUS_OK;
85 DeviceGroup_Protocol_t *msg = new_DeviceGroup_Protocol_msg(DeviceGroup_Protocol__payload_PR_handshakeRequest);
89 bool encrypted = true;
90 status = unicast_msg(session, partner, state, msg, encrypted);
91 if (status != PEP_STATUS_OK)
94 free_DeviceGroup_Protocol_msg(msg);
95 free_identity(partner);
99 status = PEP_OUT_OF_MEMORY;
101 free_identity(partner);
102 free_DeviceGroup_Protocol_msg(msg);
107 // sendGroupKeys() - send GroupKeys message
110 // session (in) session handle
111 // state (in) state the state machine is in
112 // partner (in) (must be NULL)
115 // PEP_STATUS_OK or any other value on error
117 PEP_STATUS sendGroupKeys(
119 DeviceState_state state,
124 assert(session && state);
125 if (!(session && state))
126 return PEP_ILLEGAL_VALUE;
128 PEP_STATUS status = PEP_STATUS_OK;
129 identity_list *kl = new_identity_list(NULL);
131 DeviceGroup_Protocol_t *msg = new_DeviceGroup_Protocol_msg(DeviceGroup_Protocol__payload_PR_groupKeys);
135 status = own_identities_retrieve(session, &kl);
136 if (status != PEP_STATUS_OK)
138 if (IdentityList_from_identity_list(kl, &msg->payload.choice.groupKeys.ownIdentities) == NULL)
141 bool encrypted = true;
142 status = unicast_msg(session, partner, state, msg, encrypted);
143 if (status != PEP_STATUS_OK)
146 free_identity_list(kl);
147 free_DeviceGroup_Protocol_msg(msg);
148 free_identity(partner);
149 return PEP_STATUS_OK;
152 status = PEP_OUT_OF_MEMORY;
154 free_identity(partner);
155 free_DeviceGroup_Protocol_msg(msg);
156 free_identity_list(kl);