3 // state machine for DeviceState
5 DeviceState_state fsm_DeviceState(
7 DeviceState_state state,
8 DeviceState_event event,
14 PEP_STATUS status = PEP_STATUS_OK;
20 cond_result = storedGroupKeys(session);
28 return (DeviceState_state) invalid_event;
35 status = sendBeacon(session, state, NULL, NULL);
36 if (status == PEP_OUT_OF_MEMORY)
37 return (int) invalid_out_of_memory;
38 if (status != PEP_STATUS_OK)
39 return (int) invalid_action;
42 status = sendBeacon(session, state, NULL, NULL);
43 if (status == PEP_OUT_OF_MEMORY)
44 return (int) invalid_out_of_memory;
45 if (status != PEP_STATUS_OK)
46 return (int) invalid_action;
49 status = sendHandshakeRequest(session, state, partner, NULL);
50 if (status == PEP_OUT_OF_MEMORY)
51 return (int) invalid_out_of_memory;
52 if (status != PEP_STATUS_OK)
53 return (int) invalid_action;
55 case HandshakeRequest:
56 status = sendHandshakeRequest(session, state, partner, NULL);
57 if (status == PEP_OUT_OF_MEMORY)
58 return (int) invalid_out_of_memory;
59 if (status != PEP_STATUS_OK)
60 return (int) invalid_action;
61 return HandshakingSole;
63 return (DeviceState_state) invalid_event;
70 status = showHandshake(session, state, partner, NULL);
71 if (status == PEP_OUT_OF_MEMORY)
72 return (int) invalid_out_of_memory;
73 if (status != PEP_STATUS_OK)
74 return (int) invalid_action;
76 case HandshakeRejected:
77 status = reject(session, state, partner, NULL);
78 if (status == PEP_OUT_OF_MEMORY)
79 return (int) invalid_out_of_memory;
80 if (status != PEP_STATUS_OK)
81 return (int) invalid_action;
83 case HandshakeAccepted:
84 cond_result = keyElectionWon(session, partner);
90 return WaitForGroupKeys;
92 return (DeviceState_state) invalid_event;
96 case WaitForGroupKeys:
99 status = storeGroupKeys(session, state, partner, NULL);
100 if (status == PEP_OUT_OF_MEMORY)
101 return (int) invalid_out_of_memory;
102 if (status != PEP_STATUS_OK)
103 return (int) invalid_action;
108 status = reject(session, state, partner, NULL);
109 if (status == PEP_OUT_OF_MEMORY)
110 return (int) invalid_out_of_memory;
111 if (status != PEP_STATUS_OK)
112 return (int) invalid_action;
115 return (DeviceState_state) invalid_event;
122 status = sendGroupKeys(session, state, NULL, NULL);
123 if (status == PEP_OUT_OF_MEMORY)
124 return (int) invalid_out_of_memory;
125 if (status != PEP_STATUS_OK)
126 return (int) invalid_action;
128 case HandshakeRequest:
129 status = sendHandshakeRequest(session, state, partner, NULL);
130 if (status == PEP_OUT_OF_MEMORY)
131 return (int) invalid_out_of_memory;
132 if (status != PEP_STATUS_OK)
133 return (int) invalid_action;
134 status = showHandshake(session, state, partner, NULL);
135 if (status == PEP_OUT_OF_MEMORY)
136 return (int) invalid_out_of_memory;
137 if (status != PEP_STATUS_OK)
138 return (int) invalid_action;
140 case HandshakeRejected:
141 status = reject(session, state, partner, NULL);
142 if (status == PEP_OUT_OF_MEMORY)
143 return (int) invalid_out_of_memory;
144 if (status != PEP_STATUS_OK)
145 return (int) invalid_action;
150 status = reject(session, state, NULL, NULL);
151 if (status == PEP_OUT_OF_MEMORY)
152 return (int) invalid_out_of_memory;
153 if (status != PEP_STATUS_OK)
154 return (int) invalid_action;
157 return (DeviceState_state) invalid_event;
162 return (DeviceState_state) invalid_state;