Skip to content

Commit cc32457

Browse files
author
Mika Leppänen
committed
Modified PAEs to use protocol core timer function call
Moved timer services out from PAE tasklets and added call to PAE timer from core timer. Changed PAE tasklet to have one common instance shared between PAEs.
1 parent 03469f3 commit cc32457

File tree

18 files changed

+159
-126
lines changed

18 files changed

+159
-126
lines changed

source/6LoWPAN/ws/ws_pae_auth.c

Lines changed: 37 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ typedef struct {
5757
protocol_interface_info_entry_t *interface_ptr; /**< Interface pointer */
5858
supp_list_t active_supp_list; /**< List of active supplicants */
5959
supp_list_t inactive_supp_list; /**< List of inactive supplicants */
60-
int8_t tasklet_id; /**< Tasklet identifier */
6160
arm_event_storage_t *timer; /**< Timer */
6261
sec_prot_gtk_keys_t *gtks; /**< GTKs */
62+
bool timer_running; /**< Timer is running */
6363
} pae_auth_t;
6464

6565
static void ws_pae_auth_free(pae_auth_t *pae_auth);
@@ -71,13 +71,15 @@ static int8_t ws_pae_auth_timer_if_start(kmp_service_t *service, kmp_api_t *kmp)
7171
static int8_t ws_pae_auth_timer_if_stop(kmp_service_t *service, kmp_api_t *kmp);
7272
static int8_t ws_pae_auth_timer_start(pae_auth_t *pae_auth);
7373
static int8_t ws_pae_auth_timer_stop(pae_auth_t *pae_auth);
74+
static bool ws_pae_auth_timer_running(pae_auth_t *pae_auth);
7475
static void ws_pae_auth_kmp_service_addr_get(kmp_service_t *service, kmp_api_t *kmp, kmp_addr_t *local_addr, kmp_addr_t *remote_addr);
7576
static kmp_api_t *ws_pae_auth_kmp_incoming_ind(kmp_service_t *service, kmp_type_e type, const kmp_addr_t *addr);
7677
static void ws_pae_auth_kmp_api_create_confirm(kmp_api_t *kmp, kmp_result_e result);
7778
static void ws_pae_auth_kmp_api_create_indication(kmp_api_t *kmp, kmp_type_e type, kmp_addr_t *addr);
7879
static void ws_pae_auth_kmp_api_finished_indication(kmp_api_t *kmp, kmp_result_e result, kmp_sec_keys_t *sec_keys);
7980
static void ws_pae_auth_kmp_api_finished(kmp_api_t *kmp);
8081

82+
static int8_t tasklet_id = -1;
8183
static NS_LIST_DEFINE(pae_auth_list, pae_auth_t, link);
8284

8385
int8_t ws_pae_auth_init(protocol_interface_info_entry_t *interface_ptr, sec_prot_gtk_keys_t *gtks)
@@ -139,9 +141,11 @@ int8_t ws_pae_auth_init(protocol_interface_info_entry_t *interface_ptr, sec_prot
139141
goto error;
140142
}
141143

142-
pae_auth->tasklet_id = eventOS_event_handler_create(ws_pae_auth_tasklet_handler, PAE_TASKLET_INIT);
143-
if (pae_auth->tasklet_id < 0) {
144-
goto error;
144+
if (tasklet_id < 0) {
145+
tasklet_id = eventOS_event_handler_create(ws_pae_auth_tasklet_handler, PAE_TASKLET_INIT);
146+
if (tasklet_id < 0) {
147+
goto error;
148+
}
145149
}
146150

147151
ns_list_add_to_end(&pae_auth_list, pae_auth);
@@ -216,8 +220,9 @@ static int8_t ws_pae_auth_event_send(kmp_service_t *service, void *data)
216220
}
217221

218222
arm_event_s event = {
219-
.receiver = pae_auth->tasklet_id,
223+
.receiver = tasklet_id,
220224
.sender = 0,
225+
.event_id = pae_auth->interface_ptr->id,
221226
.data_ptr = data,
222227
.event_type = PAE_TASKLET_EVENT,
223228
.priority = ARM_LIB_LOW_PRIORITY_EVENT,
@@ -232,27 +237,33 @@ static int8_t ws_pae_auth_event_send(kmp_service_t *service, void *data)
232237

233238
static void ws_pae_auth_tasklet_handler(arm_event_s *event)
234239
{
235-
pae_auth_t *pae_auth = NULL;
240+
if (event->event_type == PAE_TASKLET_INIT) {
236241

237-
ns_list_foreach(pae_auth_t, entry, &pae_auth_list) {
238-
if (entry->tasklet_id == event->receiver) {
239-
pae_auth = entry;
240-
break;
242+
} else if (event->event_type == PAE_TASKLET_EVENT) {
243+
pae_auth_t *pae_auth = NULL;
244+
245+
ns_list_foreach(pae_auth_t, entry, &pae_auth_list) {
246+
if (entry->interface_ptr->id == event->event_id) {
247+
pae_auth = entry;
248+
break;
249+
}
241250
}
242-
}
243251

244-
if (!pae_auth) {
245-
return;
252+
if (pae_auth) {
253+
kmp_service_event_if_event(pae_auth->kmp_service, event->data_ptr);
254+
}
246255
}
256+
}
247257

248-
if (event->event_type == PAE_TASKLET_INIT) {
258+
void ws_pae_auth_timer(uint16_t ticks)
259+
{
260+
ns_list_foreach(pae_auth_t, pae_auth, &pae_auth_list) {
261+
if (!ws_pae_auth_timer_running(pae_auth)) {
262+
continue;
263+
}
249264

250-
} else if (event->event_type == PAE_TASKLET_EVENT) {
251-
void *data = event->data_ptr;
252-
kmp_service_event_if_event(pae_auth->kmp_service, data);
253-
} else if (event->event_type == PAE_TASKLET_TIMER) {
254265
// Updates KMP timers
255-
bool running = ws_pae_lib_supp_list_timer_update(&pae_auth->active_supp_list, &pae_auth->inactive_supp_list, kmp_service_timer_if_timeout);
266+
bool running = ws_pae_lib_supp_list_timer_update(&pae_auth->active_supp_list, &pae_auth->inactive_supp_list, ticks, kmp_service_timer_if_timeout);
256267
if (!running) {
257268
ws_pae_auth_timer_stop(pae_auth);
258269
}
@@ -303,38 +314,21 @@ static int8_t ws_pae_auth_timer_if_stop(kmp_service_t *service, kmp_api_t *kmp)
303314

304315
static int8_t ws_pae_auth_timer_start(pae_auth_t *pae_auth)
305316
{
306-
if (!pae_auth->timer) {
307-
uint32_t ticks_in_100ms = eventOS_event_timer_ms_to_ticks(100);
308-
309-
arm_event_s event = {
310-
.receiver = pae_auth->tasklet_id,
311-
.sender = 0,
312-
.event_id = 0,
313-
.data_ptr = NULL,
314-
.event_type = PAE_TASKLET_TIMER,
315-
.priority = ARM_LIB_LOW_PRIORITY_EVENT,
316-
};
317-
318-
pae_auth->timer = eventOS_event_timer_request_every(&event, ticks_in_100ms);
319-
if (!pae_auth->timer) {
320-
return -1;
321-
}
322-
}
317+
pae_auth->timer_running = true;
323318
return 0;
324319
}
325320

326321
static int8_t ws_pae_auth_timer_stop(pae_auth_t *pae_auth)
327322
{
328-
if (!pae_auth->timer) {
329-
return -1;
330-
}
331-
332-
eventOS_cancel(pae_auth->timer);
333-
pae_auth->timer = NULL;
334-
323+
pae_auth->timer_running = false;
335324
return 0;
336325
}
337326

327+
static bool ws_pae_auth_timer_running(pae_auth_t *pae_auth)
328+
{
329+
return pae_auth->timer_running;
330+
}
331+
338332
static void ws_pae_auth_kmp_service_addr_get(kmp_service_t *service, kmp_api_t *kmp, kmp_addr_t *local_addr, kmp_addr_t *remote_addr)
339333
{
340334
(void) service;

source/6LoWPAN/ws/ws_pae_auth.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@
2222

2323
int8_t ws_pae_auth_init(protocol_interface_info_entry_t *interface_ptr, sec_prot_gtk_keys_t *gtks);
2424
int8_t ws_pae_auth_delete(protocol_interface_info_entry_t *interface_ptr);
25+
void ws_pae_auth_timer(uint16_t ticks);
2526

2627
#else
2728

2829
#define ws_pae_auth_init(interface_ptr)
2930
#define ws_pae_auth_delete(interface_ptr)
31+
#define ws_pae_auth_timer(ticks)
3032

3133
#endif
3234

source/6LoWPAN/ws/ws_pae_controller.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#define TRACE_GROUP "wspsc"
3535

3636
typedef int8_t ws_pae_delete(protocol_interface_info_entry_t *interface_ptr);
37+
typedef void ws_pae_timer(uint16_t ticks);
3738

3839
typedef struct {
3940
ns_list_link_t link; /**< Link */
@@ -43,6 +44,7 @@ typedef struct {
4344
ws_pae_controller_auth_completed *auth_completed; /**< Authentication completed callback, continue bootstrap */
4445
ws_pae_controller_key_insert *key_insert; /**< Key insert callback */
4546
ws_pae_delete *pae_delete; /**< PAE delete callback */
47+
ws_pae_timer *pae_timer; /**< PAE timer callback */
4648
} pae_controller_t;
4749

4850
static void ws_pae_controller_supp_key_insert(protocol_interface_info_entry_t *interface_ptr, uint8_t gtk_index, uint8_t *gtk);
@@ -67,6 +69,7 @@ int8_t ws_pae_controller_authenticate(protocol_interface_info_entry_t *interface
6769
}
6870

6971
controller->pae_delete = ws_pae_supp_delete;
72+
controller->pae_timer = ws_pae_supp_timer;
7073

7174
ws_pae_supp_cb_register(controller->interface_ptr, ws_pae_controller_supp_auth_completed, ws_pae_controller_supp_key_insert);
7275

@@ -105,6 +108,7 @@ int8_t ws_pae_controller_authenticator_start(protocol_interface_info_entry_t *in
105108
}
106109

107110
controller->pae_delete = ws_pae_auth_delete;
111+
controller->pae_timer = ws_pae_auth_timer;
108112

109113
controller->key_insert(0, controller->gtks.gtk[0].key, controller->interface_ptr);
110114

@@ -243,6 +247,15 @@ int8_t ws_pae_controller_delete(protocol_interface_info_entry_t *interface_ptr)
243247
return 0;
244248
}
245249

250+
void ws_pae_controller_timer(uint16_t ticks)
251+
{
252+
ns_list_foreach(pae_controller_t, entry, &pae_controller_list) {
253+
if (entry->pae_timer) {
254+
entry->pae_timer(ticks);
255+
}
256+
}
257+
}
258+
246259
static pae_controller_t *ws_pae_controller_get(protocol_interface_info_entry_t *interface_ptr)
247260
{
248261
ns_list_foreach(pae_controller_t, entry, &pae_controller_list) {

source/6LoWPAN/ws/ws_pae_controller.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
typedef void ws_pae_controller_key_insert(uint8_t gtk_index, uint8_t *gtk, protocol_interface_info_entry_t *interface_ptr);
2222
typedef void ws_pae_controller_auth_completed(bool success, protocol_interface_info_entry_t *interface_ptr);
2323

24+
#ifdef HAVE_WS
25+
2426
int8_t ws_pae_controller_set_target(protocol_interface_info_entry_t *interface_ptr, uint8_t *dest_eui_64);
2527
int8_t ws_pae_controller_authenticate(protocol_interface_info_entry_t *interface_ptr);
2628

@@ -30,5 +32,21 @@ int8_t ws_pae_controller_init(protocol_interface_info_entry_t *interface_ptr);
3032
int8_t ws_pae_controller_stop(protocol_interface_info_entry_t *interface_ptr);
3133
int8_t ws_pae_controller_delete(protocol_interface_info_entry_t *interface_ptr);
3234
int8_t ws_pae_controller_cb_register(protocol_interface_info_entry_t *interface_ptr, ws_pae_controller_auth_completed *completed, ws_pae_controller_key_insert *key_insert);
35+
void ws_pae_controller_timer(uint16_t ticks);
36+
37+
#else
38+
39+
#define ws_pae_controller_set_target(interface_ptr, dest_eui_64)
40+
#define ws_pae_controller_authenticate(interface_ptr)
41+
42+
#define ws_pae_controller_authenticator_start(interface_ptr)
43+
44+
#define ws_pae_controller_init(interface_ptr)
45+
#define ws_pae_controller_stop(interface_ptr)
46+
#define ws_pae_controller_delete(interface_ptr)
47+
#define ws_pae_controller_cb_register(interface_ptr, completed, key_insert)
48+
#define ws_pae_controller_timer(ticks)
49+
50+
#endif
3351

3452
#endif /* WS_PAE_CONTROLLER_H_ */

source/6LoWPAN/ws/ws_pae_lib.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,15 +120,15 @@ void ws_pae_lib_kmp_timer_stop(kmp_list_t *kmp_list, kmp_entry_t *entry)
120120
entry->timer_running = false;
121121
}
122122

123-
bool ws_pae_lib_kmp_timer_update(kmp_list_t *kmp_list, ws_pae_lib_kmp_timer_timeout timeout)
123+
bool ws_pae_lib_kmp_timer_update(kmp_list_t *kmp_list, uint16_t ticks, ws_pae_lib_kmp_timer_timeout timeout)
124124
{
125125
if (ns_list_is_empty(kmp_list)) {
126126
return false;
127127
}
128128

129129
ns_list_foreach_safe(kmp_entry_t, entry, kmp_list) {
130130
if (entry->timer_running) {
131-
timeout(entry->kmp);
131+
timeout(entry->kmp, ticks);
132132
} else {
133133
break;
134134
}
@@ -188,12 +188,12 @@ void ws_pae_lib_supp_list_delete(supp_list_t *supp_list)
188188
}
189189
}
190190

191-
bool ws_pae_lib_supp_list_timer_update(supp_list_t *active_supp_list, supp_list_t *inactive_supp_list, ws_pae_lib_kmp_timer_timeout timeout)
191+
bool ws_pae_lib_supp_list_timer_update(supp_list_t *active_supp_list, supp_list_t *inactive_supp_list, uint16_t ticks, ws_pae_lib_kmp_timer_timeout timeout)
192192
{
193193
bool timer_running = false;
194194

195195
ns_list_foreach_safe(supp_entry_t, entry, active_supp_list) {
196-
bool running = ws_pae_lib_supp_timer_update(entry, timeout);
196+
bool running = ws_pae_lib_supp_timer_update(entry, ticks, timeout);
197197
if (running) {
198198
timer_running = true;
199199
} else {
@@ -219,16 +219,18 @@ void ws_pae_lib_supp_delete(supp_entry_t *entry)
219219
kmp_address_delete(entry->addr);
220220
}
221221

222-
bool ws_pae_lib_supp_timer_update(supp_entry_t *entry, ws_pae_lib_kmp_timer_timeout timeout)
222+
bool ws_pae_lib_supp_timer_update(supp_entry_t *entry, uint16_t ticks, ws_pae_lib_kmp_timer_timeout timeout)
223223
{
224224
// Updates KMP timers and calls timeout callback
225-
bool keep_timer_running = ws_pae_lib_kmp_timer_update(&entry->kmp_list, timeout);
225+
bool keep_timer_running = ws_pae_lib_kmp_timer_update(&entry->kmp_list, ticks, timeout);
226226

227227
// If KMPs are not active updates supplicant timer
228228
if (!keep_timer_running) {
229-
if (entry->ticks > 1) {
229+
if (entry->ticks > ticks) {
230230
keep_timer_running = true;
231-
entry->ticks--;
231+
entry->ticks -= ticks;
232+
} else {
233+
entry->ticks = 0;
232234
}
233235
}
234236

source/6LoWPAN/ws/ws_pae_lib.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,21 +126,23 @@ void ws_pae_lib_kmp_timer_stop(kmp_list_t *kmp_list, kmp_entry_t *entry);
126126
* ws_pae_lib_kmp_timer_timeout KMP timer timeout callback
127127
*
128128
* \param kmp KMP
129+
* \param ticks timer ticks
129130
*
130131
*/
131-
typedef void ws_pae_lib_kmp_timer_timeout(kmp_api_t *kmp);
132+
typedef void ws_pae_lib_kmp_timer_timeout(kmp_api_t *kmp, uint16_t ticks);
132133

133134
/**
134135
* ws_pae_lib_kmp_timer_update updates KMP timers on KMP list
135136
*
136137
* \param kmp_list KMP list
138+
* \param ticks timer ticks
137139
* \param timeout callback to call on timeout
138140
*
139141
* \return true KMP list has KMPs
140142
* \return false no KMPs on KMP list
141143
*
142144
*/
143-
bool ws_pae_lib_kmp_timer_update(kmp_list_t *kmp_list, ws_pae_lib_kmp_timer_timeout timeout);
145+
bool ws_pae_lib_kmp_timer_update(kmp_list_t *kmp_list, uint16_t ticks, ws_pae_lib_kmp_timer_timeout timeout);
144146

145147

146148

@@ -201,23 +203,25 @@ void ws_pae_lib_supp_list_delete(supp_list_t *supp_list);
201203
*
202204
* \param active_supp_list list of active supplicants
203205
* \param inactive_supp_list list of inactive supplicants
206+
* \param ticks timer ticks
204207
* \param timeout callback to call on timeout
205208
*
206209
* \return true timer needs still to be running
207210
* \return false timer can be stopped
208211
*/
209-
bool ws_pae_lib_supp_list_timer_update(supp_list_t *active_supp_list, supp_list_t *inactive_supp_list, ws_pae_lib_kmp_timer_timeout timeout);
212+
bool ws_pae_lib_supp_list_timer_update(supp_list_t *active_supp_list, supp_list_t *inactive_supp_list, uint16_t ticks, ws_pae_lib_kmp_timer_timeout timeout);
210213

211214
/**
212215
* ws_pae_lib_supp_list_timer_update updates supplicant timers
213216
*
214217
* \param entry supplicant entry
218+
* \param ticks timer ticks
215219
* \param timeout callback to call on timeout
216220
*
217221
* \return true timer needs still to be running
218222
* \return false timer can be stopped
219223
*/
220-
bool ws_pae_lib_supp_timer_update(supp_entry_t *entry, ws_pae_lib_kmp_timer_timeout timeout);
224+
bool ws_pae_lib_supp_timer_update(supp_entry_t *entry, uint16_t ticks, ws_pae_lib_kmp_timer_timeout timeout);
221225

222226
/**
223227
* ws_pae_lib_supp_init initiates supplicant entry

0 commit comments

Comments
 (0)