Skip to content

Commit 89a85a8

Browse files
author
Jarkko Paso
committed
FHSS: Added copyright headers, comments etc.
1 parent 5d0f44e commit 89a85a8

File tree

2 files changed

+95
-24
lines changed

2 files changed

+95
-24
lines changed

source/Service_Libs/fhss/channel_functions.c

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,44 @@
1+
/*
2+
* Copyright (c) 2016-2017, Arm Limited and affiliates.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
117
#include "nsconfig.h"
218

19+
#define rot(x,k) (((x)<<(k)) | ((x)>>(32-(k))))
20+
21+
#define final(a,b,c) \
22+
{ \
23+
c ^= b; c -= rot(b, 14); \
24+
a ^= c; a -= rot(c, 11); \
25+
b ^= a; b -= rot(a, 25); \
26+
c ^= b; c -= rot(b, 16); \
27+
a ^= c; a -= rot(c, 4); \
28+
b ^= a; b -= rot(a, 14); \
29+
c ^= b; c -= rot(b, 24); \
30+
}
31+
32+
#define mix(a,b,c) \
33+
{ \
34+
a -= c; a ^= rot(c, 4); c += b; \
35+
b -= a; b ^= rot(a, 6); a += c; \
36+
c -= b; c ^= rot(b, 8); b += a; \
37+
a -= c; a ^= rot(c, 16); c += b; \
38+
b -= a; b ^= rot(a, 19); a += c; \
39+
c -= b; c ^= rot(b, 4); b += a; \
40+
}
41+
342
static uint32_t global_seed = 1;
443

544
void tr51_seed_rand(uint32_t seed)
@@ -45,7 +84,7 @@ void tr51_compute_cfd(uint8_t *mac, uint8_t *first_element, uint8_t *step_size,
4584
*step_size = (mac[7] % (channel_table_length - 1)) + 1;
4685
}
4786

48-
uint8_t tr51_find_excluded(int32_t channel, uint16_t *excluded_channels, uint16_t number_of_excluded_channels)
87+
static uint8_t tr51_find_excluded(int32_t channel, uint16_t *excluded_channels, uint16_t number_of_excluded_channels)
4988
{
5089
uint8_t count = 0;
5190
if (excluded_channels != NULL) {
@@ -78,29 +117,6 @@ uint16_t tr51_calculate_hopping_sequence(int32_t *channel_table, uint16_t channe
78117
return slot;
79118
}
80119

81-
#define rot(x,k) (((x)<<(k)) | ((x)>>(32-(k))))
82-
83-
#define final(a,b,c) \
84-
{ \
85-
c ^= b; c -= rot(b, 14); \
86-
a ^= c; a -= rot(c, 11); \
87-
b ^= a; b -= rot(a, 25); \
88-
c ^= b; c -= rot(b, 16); \
89-
a ^= c; a -= rot(c, 4); \
90-
b ^= a; b -= rot(a, 14); \
91-
c ^= b; c -= rot(b, 24); \
92-
}
93-
94-
#define mix(a,b,c) \
95-
{ \
96-
a -= c; a ^= rot(c, 4); c += b; \
97-
b -= a; b ^= rot(a, 6); a += c; \
98-
c -= b; c ^= rot(b, 8); b += a; \
99-
a -= c; a ^= rot(c, 16); c += b; \
100-
b -= a; b ^= rot(a, 19); a += c; \
101-
c -= b; c ^= rot(b, 4); b += a; \
102-
}
103-
104120
static uint32_t dh1cf_hashword(const uint32_t *key, size_t key_length, uint32_t init_value)
105121
{
106122
uint32_t a,b,c;
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright (c) 2016-2017, Arm Limited and affiliates.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
/**
19+
* @brief Calculate channel table based on TR51 channel function.
20+
* @param number_of_channels Number of channels in table.
21+
* @param nearest_prime Nearest prime number. Must be equal to or larger than number_of_channels.
22+
* @param channel_table Output channel table. Has to be at least nearest_prime in length.
23+
*/
24+
void tr51_calculate_channel_table(uint16_t number_of_channels, uint16_t nearest_prime, int32_t *channel_table);
25+
26+
/**
27+
* @brief Calculate hopping sequence for a specific peer.
28+
* @param channel_table Used channel table.
29+
* @param channel_table_length Length of the used channel table.
30+
* @param first_element Start generated by CFD function.
31+
* @param step_size Step size generated by CFD function.
32+
* @param output_table Output hopping sequence table.
33+
* @param excluded_channels List of not used channels.
34+
* @param number_of_excluded_channels Number of not used channels.
35+
* @return Number of channels in sequence.
36+
*/
37+
uint16_t tr51_calculate_hopping_sequence(int32_t *channel_table, uint16_t channel_table_length, uint8_t first_element, uint8_t step_size, int32_t *output_table, uint16_t *excluded_channels, uint16_t number_of_excluded_channels);
38+
39+
/**
40+
* @brief Compute the unicast schedule channel index.
41+
* @param slot_number Current slot number.
42+
* @param mac MAC address of the node for which the index is calculated.
43+
* @param number_of_channels Number of channels.
44+
* @return Channel index.
45+
*/
46+
int32_t dh1cf_get_uc_channel_index(uint16_t slot_number, uint8_t *mac, int16_t number_of_channels);
47+
48+
/**
49+
* @brief Compute the broadcast schedule channel index.
50+
* @param slot_number Current slot number.
51+
* @param bsi Broadcast schedule identifier of the node for which the index is calculated.
52+
* @param number_of_channels Number of channels.
53+
* @return Channel index.
54+
*/
55+
int32_t dh1cf_get_bc_channel_index(uint16_t slot_number, uint16_t bsi, int16_t number_of_channels);

0 commit comments

Comments
 (0)