summaryrefslogtreecommitdiff
path: root/mac/ca/inc/backoff.h
blob: 7d0b8ab355686a469b89b0521b11754f7a2a76a7 (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
#ifndef mac_ca_inc_backoff_h
#define mac_ca_inc_backoff_h
/* Cesar project {{{
 *
 * Copyright (C) 2007 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    mac/ca/inc/backoff.h
 * \brief   Backoff handling private header.
 * \ingroup mac_ca
 */
#include "mac/ca/ca.h"

#include "lib/rnd.h"

/** Channel Access backoff context. */
struct ca_backoff_t
{
    /** Whether backoff is active. */
    bool active;
    /** Current backoff procedure counter. */
    uint bpc;
    /** Current contention window size. */
    uint cw;
    /** Current backoff counter value. */
    uint bc;
    /** Current deferral counter. */
    uint dc;
    /** Random number generator context. */
    lib_rnd_t rnd_context;
};
typedef struct ca_backoff_t ca_backoff_t;

BEGIN_DECLS

/**
 * Initialise the backoff structure to a known state.
 * \param  ctx  ca context
 * \param  seed  32 bit random seed
 */
void
ca_backoff_init (ca_t *ctx, u32 seed);

/**
 * Initialise the backoff procedure for a new transmission.
 * \param  ctx  ca context
 * \param  cap  channel access priority
 *
 * Called when a new transmission is planned to start in a CSMA allocation.
 */
void
ca_backoff_new (ca_t *ctx, uint cap);

/* ca_backoff_deferred is public */
/* ca_backoff_success is public */
/* ca_backoff_cancel is public */

END_DECLS

#endif /* mac_ca_inc_backoff_h */