-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhopping.c
More file actions
36 lines (29 loc) · 944 Bytes
/
hopping.c
File metadata and controls
36 lines (29 loc) · 944 Bytes
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
/*
* This file is part of the Bluesniff project.
* Copyright (C) 2025 LEXFO
*/
#include <stdint.h>
static uint16_t perm(uint16_t v) {
v = ((v & 0x5555) << 1) | ((v & 0xAAAA) >> 1);
v = ((v & 0x3333) << 2) | ((v & 0xCCCC) >> 2);
v = ((v & 0x0F0F) << 4) | ((v & 0xF0F0) >> 4);
return v;
}
static uint16_t channelId(uint32_t aa) { return (aa >> 16) ^ (aa & 0xFFFF); }
static uint16_t mam(uint16_t a, uint16_t b) { return (17 * a + b) & 0xFFFF; }
static uint16_t eventPrng(uint16_t counter, uint16_t channelId) {
uint16_t res = counter ^ channelId;
res = perm(res);
res = mam(res, channelId);
res = perm(res);
res = mam(res, channelId);
res = perm(res);
res = mam(res, channelId);
res = res ^ channelId;
return res;
}
static uint16_t unmappedChannel(uint16_t prn_e) { return prn_e % 37; }
uint16_t getChannel(uint16_t counter, uint32_t aa) {
uint16_t res = unmappedChannel(eventPrng(counter, channelId(aa)));
return res;
}