Skip to content

Commit

Permalink
FHSS: Added copyright headers, comments etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarkko Paso committed Jan 10, 2018
1 parent 5d0f44e commit 89a85a8
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 24 deletions.
64 changes: 40 additions & 24 deletions source/Service_Libs/fhss/channel_functions.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,44 @@
/*
* Copyright (c) 2016-2017, Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "nsconfig.h"

#define rot(x,k) (((x)<<(k)) | ((x)>>(32-(k))))

#define final(a,b,c) \
{ \
c ^= b; c -= rot(b, 14); \
a ^= c; a -= rot(c, 11); \
b ^= a; b -= rot(a, 25); \
c ^= b; c -= rot(b, 16); \
a ^= c; a -= rot(c, 4); \
b ^= a; b -= rot(a, 14); \
c ^= b; c -= rot(b, 24); \
}

#define mix(a,b,c) \
{ \
a -= c; a ^= rot(c, 4); c += b; \
b -= a; b ^= rot(a, 6); a += c; \
c -= b; c ^= rot(b, 8); b += a; \
a -= c; a ^= rot(c, 16); c += b; \
b -= a; b ^= rot(a, 19); a += c; \
c -= b; c ^= rot(b, 4); b += a; \
}

static uint32_t global_seed = 1;

void tr51_seed_rand(uint32_t seed)
Expand Down Expand Up @@ -45,7 +84,7 @@ void tr51_compute_cfd(uint8_t *mac, uint8_t *first_element, uint8_t *step_size,
*step_size = (mac[7] % (channel_table_length - 1)) + 1;
}

uint8_t tr51_find_excluded(int32_t channel, uint16_t *excluded_channels, uint16_t number_of_excluded_channels)
static uint8_t tr51_find_excluded(int32_t channel, uint16_t *excluded_channels, uint16_t number_of_excluded_channels)
{
uint8_t count = 0;
if (excluded_channels != NULL) {
Expand Down Expand Up @@ -78,29 +117,6 @@ uint16_t tr51_calculate_hopping_sequence(int32_t *channel_table, uint16_t channe
return slot;
}

#define rot(x,k) (((x)<<(k)) | ((x)>>(32-(k))))

#define final(a,b,c) \
{ \
c ^= b; c -= rot(b, 14); \
a ^= c; a -= rot(c, 11); \
b ^= a; b -= rot(a, 25); \
c ^= b; c -= rot(b, 16); \
a ^= c; a -= rot(c, 4); \
b ^= a; b -= rot(a, 14); \
c ^= b; c -= rot(b, 24); \
}

#define mix(a,b,c) \
{ \
a -= c; a ^= rot(c, 4); c += b; \
b -= a; b ^= rot(a, 6); a += c; \
c -= b; c ^= rot(b, 8); b += a; \
a -= c; a ^= rot(c, 16); c += b; \
b -= a; b ^= rot(a, 19); a += c; \
c -= b; c ^= rot(b, 4); b += a; \
}

static uint32_t dh1cf_hashword(const uint32_t *key, size_t key_length, uint32_t init_value)
{
uint32_t a,b,c;
Expand Down
55 changes: 55 additions & 0 deletions source/Service_Libs/fhss/channel_functions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright (c) 2016-2017, Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* @brief Calculate channel table based on TR51 channel function.
* @param number_of_channels Number of channels in table.
* @param nearest_prime Nearest prime number. Must be equal to or larger than number_of_channels.
* @param channel_table Output channel table. Has to be at least nearest_prime in length.
*/
void tr51_calculate_channel_table(uint16_t number_of_channels, uint16_t nearest_prime, int32_t *channel_table);

/**
* @brief Calculate hopping sequence for a specific peer.
* @param channel_table Used channel table.
* @param channel_table_length Length of the used channel table.
* @param first_element Start generated by CFD function.
* @param step_size Step size generated by CFD function.
* @param output_table Output hopping sequence table.
* @param excluded_channels List of not used channels.
* @param number_of_excluded_channels Number of not used channels.
* @return Number of channels in sequence.
*/
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);

/**
* @brief Compute the unicast schedule channel index.
* @param slot_number Current slot number.
* @param mac MAC address of the node for which the index is calculated.
* @param number_of_channels Number of channels.
* @return Channel index.
*/
int32_t dh1cf_get_uc_channel_index(uint16_t slot_number, uint8_t *mac, int16_t number_of_channels);

/**
* @brief Compute the broadcast schedule channel index.
* @param slot_number Current slot number.
* @param bsi Broadcast schedule identifier of the node for which the index is calculated.
* @param number_of_channels Number of channels.
* @return Channel index.
*/
int32_t dh1cf_get_bc_channel_index(uint16_t slot_number, uint16_t bsi, int16_t number_of_channels);

0 comments on commit 89a85a8

Please sign in to comment.