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;
55 free_DeviceGroup_Protocol_msg(msg);
60 // sendHandshakeRequest() - send HandshakeRequest message
63 // session (in) session handle
64 // state (in) state the state machine is in
65 // partner (in) partner to communicate with
68 // PEP_STATUS_OK or any other value on error
70 PEP_STATUS sendHandshakeRequest(
72 DeviceState_state state,
77 assert(session && state);
78 if (!(session && state))
79 return PEP_ILLEGAL_VALUE;
81 PEP_STATUS status = PEP_STATUS_OK;
83 DeviceGroup_Protocol_t *msg = new_DeviceGroup_Protocol_msg(DeviceGroup_Protocol__payload_PR_handshakeRequest);
87 status = unicast_msg(session, partner, state, msg);
88 if (status != PEP_STATUS_OK)
91 free_DeviceGroup_Protocol_msg(msg);
95 status = PEP_OUT_OF_MEMORY;
98 free_DeviceGroup_Protocol_msg(msg);
103 // sendGroupKeys() - send GroupKeys message
106 // session (in) session handle
107 // state (in) state the state machine is in
108 // partner (in) (must be NULL)
111 // PEP_STATUS_OK or any other value on error
113 PEP_STATUS sendGroupKeys(
115 DeviceState_state state,
120 assert(session && state);
121 if (!(session && state))
122 return PEP_ILLEGAL_VALUE;
124 PEP_STATUS status = PEP_STATUS_OK;
125 identity_list *kl = new_identity_list(NULL);
127 DeviceGroup_Protocol_t *msg = new_DeviceGroup_Protocol_msg(DeviceGroup_Protocol__payload_PR_groupKeys);
131 status = own_identities_retrieve(session, &kl);
132 if (status != PEP_STATUS_OK)
134 if (IdentityList_from_identity_list(kl, &msg->payload.choice.groupKeys.ownIdentities) == NULL)
137 status = unicast_msg(session, partner, state, msg);
138 if (status != PEP_STATUS_OK)
141 free_identity_list(kl);
142 free_DeviceGroup_Protocol_msg(msg);
143 return PEP_STATUS_OK;
146 status = PEP_OUT_OF_MEMORY;
149 free_DeviceGroup_Protocol_msg(msg);
150 free_identity_list(kl);