summaryrefslogtreecommitdiff
path: root/cesar/cp/sta/action/src/sc.c
blob: bea9e43efc08040a5ffe6bea5ad78aad0f6b3c08 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
/* Cesar project {{{
 *
 * Copyright (C) 2009 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    cp/sta/action/src/sc.c
 * \brief   STA action, Simple Connect procedure functions definitions.
 * \ingroup cp_sta_action
 */
#include "common/std.h"
#include "cp/inc/context.h"
#include "cp/sta/action/inc/context.h"
#include "cp/sta/action/assoc.h"
#include "cp/sta/core/core.h"
#include "cp/msg/inc/msg_cm.h"
#include "cp/msg/inc/msg_drv.h"
#include "cp/fsm/inc/events.h"
#include "cp/fsm/fsm.h"
#include "cp/cco/action/cco_action.h"
#include "cp/secu/defs.h"

#include "cp/sta/action/sc.h"

/**
 * SC timeout.
 */
#define SC_TIMEOUT_MS   30000

/**
 * Minimum value of the timer for periodic broadcast of SC_JOIN.REQ MME.
 */
#define SC_PERIODIC_SC_JOIN_REQ_BCAST_MS_MIN 750

/**
 * Maximum value of the timer for periodic broadcast of SC_JOIN.REQ MME.
 */
#define SC_PERIODIC_SC_JOIN_REQ_BCAST_MS_MAX 1250

/**
 * Start SC timer.
 * \param  ctx  control plane context.
 */
void
cp_sta_action_sc__start_timer (cp_t *ctx);

/**
 * Stop SC timer.
 * \param  ctx  control plane context.
 */
void
cp_sta_action_sc__stop_timer (cp_t *ctx);

/**
 * Start the SC procedure as the "add" STA.
 * \param  ctx  control plane context.
 * \param  peer  peer with which we are doing the SC procedure.
 *
 * This function send the SC_JOIN.CNF and make the top FSM move to CCo if
 * needed.
 */
void
cp_sta_action_sc__start_sc_in_add (cp_t *ctx, cp_mme_peer_t *peer);

/**
 * Send a CM_SC_JOIN.REQ to all STA in broadcast.
 * \param  ctx  control plane context.
 */
void
cp_sta_action_sc__send_cm_sc_join_req (cp_t *ctx);

/**
 * Start the SC JOIN.REQ timer.
 * \param  ctx  control plane context.
 */
void
cp_sta_action_sc__start_sc_join_req_timer (cp_t *ctx);

void
cp_sta_action_sc__start_timer (cp_t *ctx)
{
    /* Check parameter. */
    dbg_assert (ctx);
    /* Event to generate when SC timeout. */
    cp_fsm_event_t *event = cp_fsm_event_bare_new
        (ctx, CP_FSM_EVENT_TYPE_sc_timeout);
    /* Enable SC timeout timer. */
    cp_sta_core_gen_timed_event (ctx, &ctx->sta_action.sc.timeout_timer, event,
                                 SC_TIMEOUT_MS);
}

void
cp_sta_action_sc__stop_timer (cp_t *ctx)
{
    /* Check parameter. */
    dbg_assert (ctx);
    /* Disable SC timeout timer. */
    cp_sta_core_stop_timed_or_cyclic_event (ctx,
                                            &ctx->sta_action.sc.timeout_timer);
}

void
cp_sta_action_sc__start_sc_in_add (cp_t *ctx, cp_mme_peer_t *peer)
{
    /* Check parameters. */
    dbg_assert (ctx);
    dbg_assert (peer);
    /* Keep track of peer with witch we are doing SC procedure. */
    ctx->sta_action.sc.peer = *peer;
    /* Create reply (CM_SC_JOIN.CNF). */
    cp_msg_cm_sc_join_cnf_t cnf;
    cnf.nid = cp_sta_own_data_get_nid (ctx);
    cnf.avln_status = MAC_TEI_IS_STA (cp_sta_own_data_get_tei (ctx));
    cnf.cco_cap = CP_CCO_LEVEL;
    cnf.pco_cap = CP_PCO_CAP;
    cnf.backup_cco_cap = CP_BACKUP_CCO_CAP;
    cnf.pco_status = cp_sta_own_data_get_pco_status (ctx);
    cnf.backup_cco_status = cp_sta_own_data_get_backup_cco_status (ctx);
    if (cnf.avln_status)
    {
        /* We are on AVLN, give our CCo status. */
        cnf.cco_status = cp_sta_own_data_get_cco_status (ctx);
    }
    else
    {
        /* We are not on an AVLN, we must create one and become CCo. */
        cnf.cco_status = true;
        /* Make the main CP FSM move to CCo. */
        cp_fsm_event_t *event = cp_fsm_event_bare_new
            (ctx, CP_FSM_EVENT_TYPE_sc_get_cco_functionality);
        cp_fsm_trigger (ctx, event);
    }
    /* Send the reply. */
    cp_msg_cm_sc_join_cnf_send (ctx, peer, &cnf);
}

void
cp_sta_action_sc__send_cm_sc_join_req (cp_t *ctx)
{
    /* Check parameter. */
    dbg_assert (ctx);

    /* Send the SC_JOIN MME. */
    cp_mme_peer_t peer = CP_MME_PEER (MAC_BROADCAST, MAC_TEI_UNASSOCIATED);
    cp_msg_cm_sc_join_req_send (ctx, &peer);
}

void
cp_sta_action_sc__start_sc_join_req_timer (cp_t *ctx)
{
    /* Check parameter. */
    dbg_assert (ctx);

    /* Event to generate when SC_JOIN.REQ timer times-out. */
    cp_fsm_event_t *event = cp_fsm_event_bare_new
        (ctx, CP_FSM_EVENT_TYPE_sc_join_req_timeout);
    /* Generate a random value to wait for the broadcast of SC_JOIN.REQ. */
    uint rnd_wait = lib_rnd_uniform (&ctx->rnd,
                                     SC_PERIODIC_SC_JOIN_REQ_BCAST_MS_MAX
                                     - SC_PERIODIC_SC_JOIN_REQ_BCAST_MS_MIN);
    rnd_wait += SC_PERIODIC_SC_JOIN_REQ_BCAST_MS_MIN;
    /* Start the SC JOIN REQ timer. */
    cp_sta_core_gen_timed_event
        (ctx, &ctx->sta_action.sc.timer_sc_join_req_broadcast,
         event, rnd_wait);
}

void
cp_sta_action_sc__start_sc_join (cp_t *ctx)
{
    /* Check parameter. */
    dbg_assert (ctx);

    /* Generate the event to make the SC FSM start. */
    cp_fsm_event_t *event = cp_fsm_event_bare_new
        (ctx, CP_FSM_EVENT_TYPE_sc_start_join);
    cp_fsm_post (ctx, event);
}

void
cp_sta_action_sc__start_sc_add (cp_t *ctx)
{
    /* Check parameter. */
    dbg_assert (ctx);

    /* Generate the event to make the SC FSM start. */
    cp_fsm_event_t *event = cp_fsm_event_bare_new
        (ctx, CP_FSM_EVENT_TYPE_sc_start_add);
    cp_fsm_post (ctx, event);
}

void
cp_sta_action_sc__sc_idle__enter (cp_t *ctx)
{
    /* Stop SC timer. */
    cp_sta_action_sc__stop_timer (ctx);
    cp_sta_own_data_set_sc (ctx, false);
}

void
cp_sta_action_sc__sc_idle__leave (cp_t *ctx)
{
    /* Check parameter. */
    dbg_assert (ctx);
    /* Start SC timer. */
    cp_sta_action_sc__start_timer (ctx);
    cp_sta_own_data_set_sc (ctx, true);
}

void
cp_sta_action_sc__sc_join__enter (cp_t *ctx)
{
    /* Send a SC_JOIN.REQ. */
    cp_sta_action_sc__start_sc_join_req_timer (ctx);
    /* Start the timer. */
    cp_sta_action_sc__send_cm_sc_join_req (ctx);
}

void
cp_sta_action_sc__sc_join__leave (cp_t *ctx)
{
    /* Check parameter. */
    dbg_assert (ctx);
    /* Disable SC timeout timer. */
    cp_sta_core_stop_timed_or_cyclic_event
        (ctx, &ctx->sta_action.sc.timer_sc_join_req_broadcast);
}

void
cp_sta_action_sc__sc_timeout (cp_t *ctx)
{
    /* Stop assoc FSM. */
    cp_fsm_trigger_new_event (ctx, bare, to_leave);
    /* Generate the event for the CP FSM. */
    cp_fsm_post_new_event (ctx, bare, sc_failed);
}

void
cp_sta_action_sc__sc_add__cm_sc_join_req (cp_t *ctx, cp_mme_rx_t *mme)
{
    /* Check parameters. */
    dbg_assert (ctx);
    dbg_assert (mme);

    uint cco_cap;

    /* Check received MME. */
    if ((mme->peer.tei != 0x0)
        || (!cp_msg_cm_sc_join_req_receive (ctx, mme, &cco_cap))
       )
    {
        /* Error in received MME. */
        cp_fsm_branch (ctx, SC_ADD, CM_SC_JOIN_REQ, nok);
    }
    else
    {
        /* Let's try SC procedure with peer. */
        cp_sta_action_sc__start_sc_in_add (ctx, &mme->peer);
        /* Move FSM. */
        cp_fsm_branch (ctx, SC_ADD, CM_SC_JOIN_REQ, ok);
    }
}

void
cp_sta_action_sc__to_stop (cp_t *ctx)
{
    /* Generate the event for the CP FSM. */
    cp_fsm_event_t *event = cp_fsm_event_bare_new
        (ctx, CP_FSM_EVENT_TYPE_sc_failed);
    cp_fsm_post (ctx, event);
}

void
cp_sta_action_sc__sc_wait_peer_associated__new_sta_associated (cp_t *ctx,
                                                               cp_net_t *net,
                                                               cp_sta_t *sta)
{
    /* Check parameters. */
    dbg_assert (ctx);
    dbg_assert (net);
    dbg_assert (sta);

    /* If it is our net and the STA we are doing the SC procedure. */
    if (ctx->sta_action.sc.peer.mac == cp_sta_get_mac_address (sta))
    {
        /* Store its TEI. */
        ctx->sta_action.sc.peer.tei = cp_sta_get_tei (sta);
        /* Start the exchange of hash key to build the TEK. */
        cp_msg_cm_get_key_req_t req;
        req.relayed = false;
        req.key_type = CP_MSG_KEY_HASH_KEY;
        req.nid = cp_sta_own_data_get_nid (ctx);
        /* Generate hash key. */
        cp_secu_generate_hash (ctx, lib_rnd32 (&ctx->rnd), req.hash_key,
        CP_SECU_HASH_KEY_FOR_TEK_SIZE);
        /* Keep a copy of the hash key. */
        memcpy (ctx->sta_action.sc.hash_key, req.hash_key, CP_HASH_KEY_SIZE);
        cp_secu_protocol_run_new (&ctx->sta_action.sc.prun, 3,
                                  &ctx->rnd);
        /* Send GET_KEY_REQ_PID3. */
        cp_msg_cm_get_key_req_send (ctx, &ctx->sta_action.sc.peer,
                                    CP_MME_PEKS_SPC_NOT_EMBEDDED, /* Not encrypted! */
                                    &ctx->sta_action.sc.prun, &req);
        /* Update FSM. */
        cp_fsm_branch (ctx, SC_WAIT_PEER_ASSOCIATED, new_sta_associated,
                       sta_is_sc_peer);
    }
    else
    {
        /* Nothing to do. */
        /* Update FSM. */
        cp_fsm_branch (ctx, SC_WAIT_PEER_ASSOCIATED, new_sta_associated,
                       sta_not_sc_peer);
    }
}

void
cp_sta_action_sc__sc_join__cm_sc_join_req (cp_t *ctx, cp_mme_rx_t *mme)
{
    /* Check parameters. */
    dbg_assert (ctx);
    dbg_assert (mme);

    uint cco_cap;
    /* Check SC_JOIN.REQ */
    if (!cp_msg_cm_sc_join_req_receive (ctx, mme, &cco_cap))
    {
        /* Incorrect MME. */
        cp_fsm_branch (ctx, SC_JOIN, CM_SC_JOIN_REQ, nok);
    }
    else
    {
        /* SC_JOIN.REQ is correct, let's compare CCo capabilities to know
         * which one is going to SC_ADD. */
        /* To prevent a warning. */
        const uint my_cco_cap = CP_CCO_LEVEL;
        if ((my_cco_cap > cco_cap)
            || ((my_cco_cap == cco_cap)
                && (cp_sta_own_data_get_mac_address (ctx) > mme->peer.mac)))
        {
            /* My CCo capabilities are greater than the peer. */
            /* Act if we were in SC_ADD procedure. */
            cp_sta_action_sc__start_sc_in_add (ctx, &mme->peer);
            /* Update FSM. */
            cp_fsm_branch (ctx, SC_JOIN, CM_SC_JOIN_REQ,
                           ok_my_cco_cap_greater);
        }
        else
        {
            /* Peer CCo capabilities are greater than mine. */
            /* Nothing to do, update FSM. */
            cp_fsm_branch (ctx, SC_JOIN, CM_SC_JOIN_REQ, ok_my_cco_cap_lower);
        }
    }
}

void
cp_sta_action_sc__sc_join__cm_sc_join_cnf (cp_t *ctx, cp_mme_rx_t *mme)
{
    /* Check parameters. */
    dbg_assert (ctx);
    dbg_assert (mme);

    /* Check MME. */
    cp_msg_cm_sc_join_cnf_t cnf;
    if (!cp_msg_cm_sc_join_cnf_receive (ctx, mme, &cnf))
    {
        /* Error in MME. */
        cp_fsm_branch (ctx, SC_JOIN, CM_SC_JOIN_CNF, nok);
    }
    else
    {
        /* Set NID from MME. */
        cp_sta_own_data_set_nid (ctx, cnf.nid);
        /* Copy SC peer information. */
        ctx->sta_action.sc.peer = mme->peer;
        /* We need to wait for beacon. */
        cp_fsm_branch (ctx, SC_JOIN, CM_SC_JOIN_CNF, ok);
    }
}

void
cp_sta_action_sc__sc_join__sc_join_req_timeout (cp_t *ctx)
{
    /* Send the SC_JOIN.REQ MME. */
    cp_sta_action_sc__start_sc_join_req_timer (ctx);
    /* Restart timer. */
    cp_sta_action_sc__send_cm_sc_join_req (ctx);
}

void
cp_sta_action_sc__sc_wait_beacon__beacon (cp_t *ctx, cp_beacon_desc_t *beacon,
                                          cp_net_t *net, cp_sta_t *sta)
{
    /* Check parameters. */
    dbg_assert (ctx);
    dbg_assert (beacon);
    dbg_assert (net);
    dbg_assert (sta);

    if (cp_sta_get_cco_status (sta))
    {
        /* Extract some data. */
        cp_sta_own_data_t *own_data = cp_sta_mgr_get_sta_own_data (ctx);
        cp_nid_t our_nid = cp_sta_own_data_get_nid (ctx);
        cp_nid_t its_nid = cp_net_get_nid (ctx, net);
        u8 its_snid = cp_net_get_snid (ctx, net);

        /* If we want this AVLN. */
        if (!own_data->nid_track /* No AVLN tracked. */
            || (our_nid != own_data->nid_track
                && our_nid == its_nid) /* Better NID match. */
           )
        {
            /* Track the AVLN with the corresponding NID. */
            own_data->nid_track = its_nid;
            cp_sta_own_data_set_snid (ctx, its_snid);
            /* Ask beacon module to track this AVLN. */
            cp_beacon_process_tracked_avln (ctx, beacon, net);
        }
        if (its_nid == our_nid)
        {
            /* Start assoc procedure. */
            cp_sta_action_sc_assoc_start (ctx, net, sta);
            /* Inform main FSM we have start SC association procedure. */
            cp_fsm_trigger_new_event (ctx, bare, sc_succeed);
            cp_fsm_branch (ctx, SC_WAIT_BEACON, BEACON, nid_match);
        }
        else
        {
            cp_fsm_branch (ctx, SC_WAIT_BEACON, BEACON, nid_differs);
        }
    }
    else
    {
        cp_fsm_branch (ctx, SC_WAIT_BEACON, BEACON, nid_differs);
    }
}

void
cp_sta_action_sc__sc_building_tek__cm_get_key_cnf_pid3 (cp_t *ctx,
                                                        cp_mme_rx_t *mme)
{
    /* Check parameters. */
    dbg_assert (ctx);
    dbg_assert (mme);

    cp_msg_cm_get_key_cnf_t cnf;
    /* Check received MME. */
    if (!cp_mme_peer_cmp (&mme->peer, &ctx->sta_action.sc.peer)
        || !cp_msg_cm_get_key_cnf_receive (ctx, mme, &cnf)
        || (!cp_secu_protocol_check
            (&ctx->sta_action.sc.prun, &mme->prun,
             CP_SECU_PROTOCOL_RUN_CHECK_RESULT_NEXT))
        || (cnf.eks < CP_MME_PEKS_TEK_MIN)
        || (cnf.eks > CP_MME_PEKS_TEK_MAX))

    {
        /* Error in MME. */
        cp_fsm_branch (ctx, SC_BUILDING_TEK, CM_GET_KEY_CNF_PID3, unrelated);
    }
    else
    {
        if (cnf.result != CP_MSG_CM_GET_KEY_CNF_RESULT_KEY_GRANTED)
        {
            /* Hash key exchange fails. */
            cp_fsm_branch (ctx, SC_BUILDING_TEK, CM_GET_KEY_CNF_PID3, nok);
        }
        else
        {
            /* Hash key exchange for TEK succeed. */
            /* Compute TEK. */
            cp_secu_tek_gen ((u32 *)ctx->sta_action.sc.hash_key,
                             (u32 *)cnf.hash_key,
                             &ctx->sta_action.sc.tek);
            /* Set the TEK for encryption. */
            cp_sta_own_data_set_tek (ctx, ctx->sta_action.sc.tek);
            /* Next protocol run. */
            ctx->sta_action.sc.prun = mme->prun;
            cp_secu_protocol_next (&ctx->sta_action.sc.prun, &ctx->rnd,
                                   false);
            /* Create reply. */
            cp_msg_cm_set_key_req_t req;
            req.key_type = CP_MSG_KEY_NMK;
            req.cco_cap = CP_CCO_LEVEL;
            req.nid = cp_sta_own_data_get_nid (ctx);
            /* Check this. */
            req.new_eks = CP_MME_PEKS_NMK;
            req.new_key = cp_sta_own_data_get_nmk (ctx);
            /* Send the NMK encrypted with TEK. */
            cp_msg_cm_set_key_req_send (ctx, &mme->peer, CP_MME_PEKS_TEK_MIN,
                                        &ctx->sta_action.sc.prun,
                                        &req);
            cp_fsm_branch (ctx, SC_BUILDING_TEK, CM_GET_KEY_CNF_PID3, ok);
        }
    }
}

void
cp_sta_action_sc__sc_nmk_exchange__cm_set_key_cnf_pid3 (cp_t *ctx,
                                                        cp_mme_rx_t *mme)
{
    /* Check parameters. */
    dbg_assert (ctx);
    dbg_assert (mme);

    cp_msg_cm_set_key_cnf_t cnf;
    /* Check received MME. */
    if (!cp_mme_peer_cmp (&mme->peer, &ctx->sta_action.sc.peer)
        || !cp_msg_cm_set_key_cnf_receive (ctx, mme, &cnf)
        || (!cp_secu_protocol_check
            (&ctx->sta_action.sc.prun, &mme->prun,
             CP_SECU_PROTOCOL_RUN_CHECK_RESULT_LAST)))
    {
        /* Error in MME. */
        cp_fsm_branch (ctx, SC_NMK_EXCHANGE, CM_SET_KEY_CNF_PID3, unrelated);
    }
    else
    {
        if (cnf.result != CP_MSG_CM_SET_KEY_CNF_RESULT_SUCCESS)
        {
            /* NMK exchange failed, inform main FSM. */
            cp_fsm_event_t *event = cp_fsm_event_bare_new
                (ctx, CP_FSM_EVENT_TYPE_sc_failed);
            cp_fsm_post (ctx, event);
            /* Move the FSM. */
            cp_fsm_branch (ctx, SC_NMK_EXCHANGE, CM_SET_KEY_CNF_PID3, nok);
        }
        else
        {
            /* NMK exchange succeed, inform main FSM. */
            cp_fsm_event_t *event = cp_fsm_event_bare_new
                (ctx, CP_FSM_EVENT_TYPE_sc_succeed);
            cp_fsm_post (ctx, event);
            /* Move the FSM. */
            cp_fsm_branch (ctx, SC_NMK_EXCHANGE, CM_SET_KEY_CNF_PID3, ok);
        }
    }
}

void
cp_sta_action_sc__sc_usta_sc_get_cco_functionality (cp_t *ctx)
{
    /* Become CCo. */
    cp_cco_action__unassoc__cco_start (ctx);
}

void
cp_sta_action_sc__sc_usta_track_beacon (cp_t *ctx, cp_beacon_desc_t *beacon,
                                        cp_net_t *net, cp_sta_t *sta)
{
    /* Check parameters. */
    dbg_assert (beacon);
    dbg_assert (net);
    dbg_assert (sta);
    cp_sta_own_data_t *own_data = cp_sta_mgr_get_sta_own_data (ctx);
    cp_nid_t our_nid = cp_sta_own_data_get_nid (ctx);
    cp_nid_t its_nid = cp_net_get_nid (ctx, net);
    u8 its_snid = cp_net_get_snid (ctx, net);
    /* Does not support proxy networking for the moment, only handle CCo
     * beacon. */
    if (cp_sta_get_cco_status (sta))
    {
        /* Should we track this beacon? */
        if (!own_data->nid_track /* No AVLN tracked. */
            || (our_nid != own_data->nid_track
                && our_nid == its_nid) /* Better NID match. */
           )
        {
            own_data->nid_track = its_nid;
            cp_sta_own_data_set_snid (ctx, its_snid);
            cp_beacon_process_tracked_avln (ctx, beacon, net);
        }
    }
}

void
cp_sta_action_sc__sc_ucco_sc_get_cco_functionality (cp_t *ctx)
{
    /* Become CCo. */
    cp_cco_action__unassoc__cco_start (ctx);
}

void
cp_sta_action_sc__sc_ucco_track_beacon (cp_t *ctx, cp_beacon_desc_t *beacon,
                                        cp_net_t *net, cp_sta_t *sta)
{
    dbg_assert (ctx);
    dbg_assert (beacon);
    dbg_assert (net);
    dbg_assert (sta);
    /* Change to STA behaviour. */
    cp_beacon_reconfigure_timer (ctx, false);
    /* Handle incoming beacon. */
    cp_sta_action_sc__sc_usta_track_beacon (ctx, beacon, net, sta);
}

void
cp_sta_action_sc__sc_sta__avln_failure (cp_t *ctx)
{
    cp_fsm_event_t *event = cp_fsm_event_bare_new
        (ctx, CP_FSM_EVENT_TYPE_to_stop);
    cp_fsm_post (ctx, event);
}