Trace BLE frame delivery and authenticated packet dispatch
This commit is contained in:
1 parent
33b4f0acc8
commit
8811276ca8
3 files changed
+20
No files matched your search
@@ -52,6 +52,12 @@ static uint64_t read64(const uint8_t* p) {
|
||||
return v;
|
||||
}
|
||||
static void write64(uint8_t* p, uint64_t v) { for (int i = 7; i >= 0; i--) { p[i] = v; v >>= 8; } }
|
||||
/* Диагностический отпечаток зашифрованного кадра для сопоставления журналов двух узлов. */
|
||||
static uint32_t frame_tag(const uint8_t* data, size_t len) {
|
||||
uint32_t tag = 2166136261u;
|
||||
for (size_t i = 0; i < len; i++) tag = (tag ^ data[i]) * 16777619u;
|
||||
return tag;
|
||||
}
|
||||
static void release_entry(struct ll_entry* e) { if (e) { queue_dgram_free(e); queue_entry_free(e); } }
|
||||
static struct ble_connection* lookup(struct ble_transport* t, ble_link_id id) {
|
||||
if (t && id) for (int i = 0; i < BLE_LINKS_MAX; i++) if (t->links[i].id == id) return &t->links[i];
|
||||
@@ -352,6 +358,8 @@ void ble_backend_received(struct ble_transport* t, ble_link_id id, enum ble_chan
|
||||
memcpy(entry->dgram, ch->assembly, total); entry->len = total;
|
||||
if (queue_data_put(ch->rx, entry) != 0) { DEBUG_ERROR(CAT, "BLE RX queue invariant failed"); return; }
|
||||
c->stats.rx_bytes += total; c->stats.rx_frames++;
|
||||
DEBUG_TRACE(DEBUG_CATEGORY_DEBUG, "BLE wire RX link=%llu channel=%d seq=%u bytes=%u tag=%08x",
|
||||
(unsigned long long)id, channel, seq, total, frame_tag(entry->dgram, entry->len));
|
||||
DEBUG_TRACE(CAT, "BLE RX frame link=%llu channel=%d seq=%u bytes=%u queued=%d", (unsigned long long)id, channel, seq, total, queue_entry_count(ch->rx));
|
||||
void (*received)(void*, ble_link_id) = channel == BLE_CHANNEL_DATA ? t->config.callbacks.received : t->config.callbacks.invite_received;
|
||||
if (received) received(t->config.arg, id);
|
||||
@@ -379,6 +387,9 @@ void ble_backend_sent(struct ble_transport* t, ble_link_id id, int success) {
|
||||
ch->offset += c->pending_bytes;
|
||||
if (ch->offset == ch->current->len) {
|
||||
c->stats.tx_bytes += ch->current->len; c->stats.tx_frames++;
|
||||
DEBUG_TRACE(DEBUG_CATEGORY_DEBUG, "BLE wire TX link=%llu channel=%d seq=%u bytes=%u tag=%08x",
|
||||
(unsigned long long)id, channel, ch->sequence, ch->current->len,
|
||||
frame_tag(ch->current->dgram, ch->current->len));
|
||||
DEBUG_TRACE(CAT, "BLE TX frame link=%llu channel=%d seq=%u bytes=%u", (unsigned long long)id, channel, ch->sequence, ch->current->len);
|
||||
release_entry(ch->current); ch->current = NULL;
|
||||
}
|
||||
|
||||
@@ -2389,6 +2389,8 @@ static void bound_receive(struct ETCP_LINK* link, struct ll_entry* entry) {
|
||||
conn->log_name, result, length); goto done;
|
||||
}
|
||||
pkt->data_len = length - 3; pkt->noencrypt_len = 0; pkt->link = link;
|
||||
DEBUG_TRACE(DEBUG_CATEGORY_DEBUG, "[%s] packet channel RX path=%u wire=%u plain=%zu code=%02x up=%u",
|
||||
conn->log_name, link->local_link_id, entry->len, length, pkt->data[0], pkt->flag_up);
|
||||
if (pkt->data[0] == ETCP_INIT_REQUEST || pkt->data[0] == ETCP_INIT_REQUEST_NOINIT) {
|
||||
const struct ETCP_INIT_REQUEST_PKT* req = (const struct ETCP_INIT_REQUEST_PKT*)pkt->data;
|
||||
if (pkt->data_len < ETCP_INIT_REQ_SIZE || !req->link_id || wire_read64(req->node_id) != conn->peer_node_id ||
|
||||
|
||||
@@ -49,6 +49,8 @@ static struct UTUN_INSTANCE* echo_instance; /* Временный bind толь
|
||||
static int policy;
|
||||
static int incoming_policy;
|
||||
static int radio_ready;
|
||||
static int probe_trace;
|
||||
static debug_level_t saved_trace;
|
||||
static uint8_t identity[24];
|
||||
static int identity_len;
|
||||
static int command(int op, jlong gen, jlong token, const char* text, const uint8_t* bytes, size_t len, int arg) {
|
||||
@@ -258,6 +260,7 @@ struct ble_etcp* android_ble_driver(void) { return driver; }
|
||||
void android_ble_detach(void) {
|
||||
if (echo_instance) { etcp_unbind(echo_instance, ETCP_ID_BLE_PROBE); echo_instance = NULL; }
|
||||
ble_etcp_destroy(driver); driver = NULL; transport = NULL;
|
||||
if (probe_trace) { debug_set_category_level(DEBUG_CATEGORY_DEBUG, saved_trace); probe_trace = 0; }
|
||||
}
|
||||
static void configure(void* arg) {
|
||||
int flags = (int)(intptr_t)arg;
|
||||
@@ -275,6 +278,10 @@ static void configure(void* arg) {
|
||||
android_ble_detach();
|
||||
command(6, 0, 0, NULL, NULL, 0, incoming_policy);
|
||||
if (!(flags & 1)) return;
|
||||
if (flags & (8 | 32)) {
|
||||
saved_trace = g_debug_config.category_levels[DEBUG_CATEGORY_DEBUG]; probe_trace = 1;
|
||||
debug_set_category_level(DEBUG_CATEGORY_DEBUG, DEBUG_LEVEL_TRACE);
|
||||
}
|
||||
struct ble_config cfg = {0}; cfg.node_id = inst->node_id; cfg.company_id = 0xffff;
|
||||
cfg.callbacks.advertising = advertising;
|
||||
cfg.callbacks.status = status; cfg.callbacks.broadcast = broadcast; cfg.callbacks.validate = validate; cfg.callbacks.received = received;
|
||||
|
||||
Reference in new issue
Block a user