nhdp_address.h
4.73 KB
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
/*
* Copyright (C) 2014 Freie Universität Berlin
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
/**
* @ingroup nhdp
* @{
*
* @file
* @brief Centralized address storage interface for NHDP
*
* @author Fabian Nack <nack@inf.fu-berlin.de>
*/
#ifndef NHDP_ADDRESS_H
#define NHDP_ADDRESS_H
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief NHDP address representation
*/
typedef struct nhdp_addr {
uint8_t *addr; /**< Pointer to the address data */
size_t addr_size; /**< Size in bytes of the address */
uint8_t addr_type; /**< AF type for the address */
uint8_t usg_count; /**< Usage count in information bases */
uint8_t in_tmp_table; /**< Signals usage in a writers temp table */
uint16_t tmp_metric_val; /**< Encoded metric value used during HELLO processing */
struct nhdp_addr *next; /**< Pointer to next address (used in central storage) */
} nhdp_addr_t;
/**
* @brief Container for NHDP address storage in a list
*/
typedef struct nhdp_addr_entry {
struct nhdp_addr *address; /**< Pointer to NHDP address storage entry */
struct nhdp_addr_entry *next; /**< Pointer to the next address list element */
} nhdp_addr_entry_t;
/**
* @name NHDP address temp usage helper macros
*
* @{
*/
#define NHDP_ADDR_TMP_NONE (0x00)
#define NHDP_ADDR_TMP_ANY (0x01)
#define NHDP_ADDR_TMP_SYM (0x03)
#define NHDP_ADDR_TMP_REM_LIST (0x04)
#define NHDP_ADDR_TMP_TH_REM_LIST (0x08)
#define NHDP_ADDR_TMP_TH_SYM_LIST (0x10)
#define NHDP_ADDR_TMP_NB_LIST (0x20)
#define NHDP_ADDR_TMP_SEND_LIST (0x60)
#define NHDP_ADDR_TMP_IN_ANY(addr) ((addr->in_tmp_table & 0x01))
#define NHDP_ADDR_TMP_IN_SYM(addr) ((addr->in_tmp_table & 0x02) >> 1)
#define NHDP_ADDR_TMP_IN_REM_LIST(addr) ((addr->in_tmp_table & 0x04) >> 2)
#define NHDP_ADDR_TMP_IN_TH_REM_LIST(addr) ((addr->in_tmp_table & 0x08) >> 3)
#define NHDP_ADDR_TMP_IN_TH_SYM_LIST(addr) ((addr->in_tmp_table & 0x10) >> 4)
#define NHDP_ADDR_TMP_IN_NB_LIST(addr) ((addr->in_tmp_table & 0x20) >> 5)
#define NHDP_ADDR_TMP_IN_SEND_LIST(addr) ((addr->in_tmp_table & 0x40) >> 6)
/** @} */
/**
* @brief Get or create a NHDP address for the given address
*
* @param[in] addr Pointer to the given address
* @param[in] addr_size Length in bytes of the given address
* @param[in] addr_type AF type of the given address
*
* @return Pointer to the NHDP address representation of the given address
* @return NULL on error
*/
nhdp_addr_t *nhdp_addr_db_get_address(uint8_t *addr, size_t addr_size, uint8_t addr_type);
/**
* @brief Decrement the usage counter of a given NHDP address
*
* The NHDP address is deleted if the usage counter reaches zero.
*
* @param[in] addr Pointer to the NHDP address
*/
void nhdp_decrement_addr_usage(nhdp_addr_t *addr);
/**
* @brief Free the given address list
*
* This function frees every address list entry of the given address list.
*
* @param[in] list_head Pointer to the head of the address list to free
*/
void nhdp_free_addr_list(nhdp_addr_entry_t *list_head);
/**
* @brief Free the given address list entry
*
* Additionally to freeing the address entry, this function takes care that
* the usage counter of the list entry's address is decremented.
*
* @param[in] addr_entry Pointer to the address list entry to free
*/
void nhdp_free_addr_entry(nhdp_addr_entry_t *addr_entry);
/**
* @brief Construct an addr list containing all addresses with
* the given tmp_type
*
* @return Pointer to the head of the newly created address list
* @return NULL on error
*/
nhdp_addr_entry_t *nhdp_generate_addr_list_from_tmp(uint8_t tmp_type);
/**
* @brief Reset in_tmp_table flag of all NHDP addresses
*
* @note
* Must not be called from outside the NHDP writer's or reader's message creation process.
*
* @param[in] decr_usg Flag whether the usage counter of a resetted addr has to be decremented
*/
void nhdp_reset_addresses_tmp_usg(uint8_t decr_usg);
/**
* @brief Get a pointer to the head of the address storage list
*
* @return Pointer to the head of the central storage address list
* @return NULL if no addresses are registered
*/
nhdp_addr_t *nhdp_get_addr_db_head(void);
#ifdef __cplusplus
}
#endif
#endif /* NHDP_ADDRESS_H */
/** @} */