Skip to content

Commit fbd5568

Browse files
author
Jarkko Paso
committed
FHSS: DH1CF channel functions implemented
1 parent cf03db2 commit fbd5568

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

source/Service_Libs/fhss/channel_functions.c

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,71 @@ uint16_t tr51_calculate_hopping_sequence(int32_t *channel_table, uint16_t channe
7777
}
7878
return slot;
7979
}
80+
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+
104+
static uint32_t dh1cf_hashword(const uint32_t *key, size_t key_length, uint32_t init_value)
105+
{
106+
uint32_t a,b,c;
107+
a = b = c = 0xdeadbeef + (((uint32_t)key_length) << 2) + init_value;
108+
while (key_length > 3) {
109+
a += key[0];
110+
b += key[1];
111+
c += key[2];
112+
mix(a, b, c);
113+
key_length -= 3;
114+
key += 3;
115+
}
116+
switch(key_length) {
117+
case 3 : c += key[2];
118+
case 2 : b += key[1];
119+
case 1 : a += key[0];
120+
final(a, b, c);
121+
case 0:
122+
break;
123+
}
124+
return c;
125+
}
126+
127+
int32_t dh1cf_get_uc_channel_index(uint16_t slot_number, uint8_t *mac, int16_t number_of_channels)
128+
{
129+
int32_t channel_number;
130+
uint32_t key[3];
131+
key[0] = (uint32_t)slot_number;
132+
key[1] = mac[4] << 24 | mac[5] << 16 | mac[6] << 8 | mac[7];
133+
key[2] = mac[0] << 24 | mac[1] << 16 | mac[2] << 8 | mac[3];
134+
channel_number = dh1cf_hashword(key, 3, 0) % number_of_channels;
135+
return channel_number;
136+
}
137+
138+
int32_t dh1cf_get_bc_channel_index(uint16_t slot_number, uint16_t bsi, int16_t number_of_channels)
139+
{
140+
int32_t channel_number;
141+
uint32_t key[3];
142+
key[0] = (uint32_t)slot_number;
143+
key[1] = bsi << 16;
144+
key[2] = 0;
145+
channel_number = dh1cf_hashword(key, 3, 0) % number_of_channels;
146+
return channel_number;
147+
}

0 commit comments

Comments
 (0)