Appearance
file cw_link_policy.h
Types
| Name | |
|---|---|
| struct | cw_tag_range_t Bereich von Property-IDs (obere 16 Bit des Tags), beide Grenzen inklusive. |
| struct | cw_lp_profile_t |
| struct | cw_lp_class_filter_t |
| enum | cw_link_class_t Werte wie P_LINK_CLASS (0x3202). |
| enum | cw_send_mode_t Werte wie P_SEND_MODE (0x3203). |
| enum | cw_cap_state_t Deckelzustand aus den 24-h-Zaehlern und dem Monatsvolumen. |
| enum | cw_volume_stage_t Stufe des NB-IoT-Monatsbudgets (README "History auf NB-IoT"). |
| enum | cw_wait_kind_t Woran eine Wartezeit vor dem naechsten Aufbau haengt. |
Functions Overview
| Name | |
|---|---|
| void | cw_lp_profile_defaults(cw_link_class_t cls, cw_lp_profile_t * out) |
| void | cw_lp_profile_resolve(cw_link_class_t cls, cw_lp_profile_t * p) Fuellt jedes 0-Feld von p aus den Vorgaben von cls; CW_LP_OFF wird 0. |
| cw_link_class_t | cw_lp_class_from_act(bool valid, uint8_t act) |
| cw_link_class_t | cw_lp_class_filter(cw_lp_class_filter_t * f, cw_link_class_t sample) |
| cw_link_class_t | cw_lp_effective_class(cw_link_class_t radio, uint32_t nat_keepalive_s) NAT ist eine Integrator- oder Backend-Angabe, keine Funkeigenschaft. |
| cw_link_class_t | cw_lp_guard_class(cw_link_class_t effective, cw_link_class_t radio) |
| bool | cw_lp_nat_suspected(const uint8_t ipv4[4]) |
| uint32_t | cw_lp_contact_interval_ms(const cw_lp_profile_t * p) |
| uint32_t | cw_lp_peer_rx_stall_ms(const cw_lp_profile_t * p) Rueckweg-Wache: ein ganzes Intervall plus zwei Antwortfristen plus Marge. |
| uint32_t | cw_lp_monitor_deadline_ms(const cw_lp_profile_t * p, uint32_t rnd) Frist der naechsten Monitoring-Meldung ab dem letzten Kontakt. |
| bool | cw_lp_elapsed(uint32_t now_ms, uint32_t since_ms, uint32_t span_ms) Vorzeichenlos ueber den 49,7-Tage-Tick-Wrap. |
| uint32_t | cw_lp_report_window_ms(const cw_lp_profile_t * p, cw_cap_state_t cap, uint32_t nbiot_window_ms, uint32_t rnd) |
| uint32_t | cw_lp_backoff_ms(uint32_t base_ms, uint32_t floor_ms, uint32_t cap_ms, uint32_t stage, uint32_t rnd) Full Jitter: U(floor, max(floor, min(cap, base * 2^stage))). |
| uint32_t | cw_lp_ladder_ms(uint32_t base_ms, uint32_t floor_ms, uint32_t cap_ms, uint32_t stage, uint32_t spread_ms, uint32_t rnd) |
| bool | cw_lp_rebuild_waits(uint32_t losses_since_ok) |
| uint32_t | cw_lp_budget_interval_ms(uint16_t budget_24h) Mindestabstand zweier Aufbauten bei erschoepftem 24-h-Budget. |
| uint32_t | cw_lp_budget_wait_ms(uint16_t budget_24h, uint32_t connects_24h, bool connect_seen, uint32_t since_last_ms) |
| bool | cw_lp_connect_due(bool waiting, bool elapsed, bool evidence, bool requested, bool route_back) |
| bool | cw_lp_failure_counts(int route_before, int route_after) |
| uint32_t | cw_lp_rebuild_stage(uint32_t stage, uint32_t losses_since_ok) |
| uint32_t | cw_lp_stable_session_ms(uint32_t guard_ms) |
| bool | cw_lp_wait_ends_on_evidence(cw_wait_kind_t kind) |
| uint32_t | cw_lp_persist_deadline(bool waiting, cw_wait_kind_t kind, uint32_t now_utc, uint32_t left_ms, uint32_t inherited_utc) |
| cw_cap_state_t | cw_lp_cap_state(const cw_lp_profile_t * p, uint32_t reports_24h, cw_volume_stage_t vol) Deckel aus der Zahl der Reports in den letzten 24 h und der Volumenstufe. |
| bool | cw_lp_report_allowed(cw_cap_state_t cap, bool immediate, bool last_gasp) |
| uint32_t | cw_lp_month_key(uint32_t utc_s, uint32_t * elapsed_s, uint32_t * month_s) |
| cw_volume_stage_t | cw_lp_volume_stage(uint32_t used_bytes, uint32_t month_budget_bytes, uint32_t elapsed_s, uint32_t month_s) |
| uint32_t | cw_lp_counter_delta(bool available, uint32_t cur, uint32_t * last) |
| cw_send_mode_t | cw_lp_mode(bool session_open, bool live, cw_cap_state_t cap) |
| bool | cw_lp_should_defer(cw_send_mode_t mode, cw_cap_state_t cap, bool immediate_pending) |
Defines
| Name | |
|---|---|
| CW_LP_OFF | Durationsfeld ausdruecklich auf 0 setzen, wo 0 sonst "Vorgabe" heisst. |
Types Documentation
enum cw_link_class_t
| Enumerator | Description |
|---|---|
| CW_LINK_UNKNOWN | |
| CW_LINK_LTEM | |
| CW_LINK_NBIOT | |
| CW_LINK_GSM | |
| CW_LINK_NAT |
Werte wie P_LINK_CLASS (0x3202).
enum cw_send_mode_t
| Enumerator | Description |
|---|---|
| CW_SEND_NORMAL | |
| CW_SEND_SESSION | |
| CW_SEND_LIVE | |
| CW_SEND_CAPPED_SOFT | |
| CW_SEND_CAPPED_HARD |
Werte wie P_SEND_MODE (0x3203).
enum cw_cap_state_t
| Enumerator | Description |
|---|---|
| CW_CAP_NONE | |
| CW_CAP_SOFT_80 | weich: Fenster verdoppelt |
| CW_CAP_SOFT_100 | weich: NB-IoT-Fenster |
| CW_CAP_HARD_REGULAR | hart: nur noch "sofort" aus der Reserve |
| CW_CAP_HARD_ALL | hart: gar nichts mehr bis der Eimer abrollt |
Deckelzustand aus den 24-h-Zaehlern und dem Monatsvolumen.
enum cw_volume_stage_t
| Enumerator | Description |
|---|---|
| CW_VOL_OK | bis 80 % des angesparten Anteils |
| CW_VOL_THIN_LATEST | 80-100 %: latest nur Endwert je Fenster |
| CW_VOL_THIN_CONDENSABLE | ueber 100 %: zusaetzlich condensable ausduennen |
| CW_VOL_STOP | ab 95 % des Monatsbudgets: regulaerer Versand stoppt |
Stufe des NB-IoT-Monatsbudgets (README "History auf NB-IoT").
enum cw_wait_kind_t
| Enumerator | Description |
|---|---|
| CW_WAIT_LADDER | Gegenstelle antwortete nicht. |
| CW_WAIT_BUDGET | 24-h-Aufbaubudget erschoepft |
| CW_WAIT_STARTUP | Anlaufstreuung nach dem Boot. |
Woran eine Wartezeit vor dem naechsten Aufbau haengt.
Function Details
function cw_lp_profile_defaults
cpp
void cw_lp_profile_defaults(
cw_link_class_t cls,
cw_lp_profile_t * out
)Vorgaben je Funktechnik. Unbekannt und 2G nehmen LTE-M; NAT behaelt die alten Fristen und hat hier kein eigenes Profil.
function cw_lp_profile_resolve
cpp
void cw_lp_profile_resolve(
cw_link_class_t cls,
cw_lp_profile_t * p
)Fuellt jedes 0-Feld von p aus den Vorgaben von cls; CW_LP_OFF wird 0.
function cw_lp_class_from_act
cpp
cw_link_class_t cw_lp_class_from_act(
bool valid,
uint8_t act
)Funktechnik aus dem +COPS-<AcT>. 3GPP und Quectel weichen ab: 7 ist E-UTRAN, Quectel meldet eMTC als 8.
function cw_lp_class_filter
cpp
cw_link_class_t cw_lp_class_filter(
cw_lp_class_filter_t * f,
cw_link_class_t sample
)function cw_lp_effective_class
cpp
cw_link_class_t cw_lp_effective_class(
cw_link_class_t radio,
uint32_t nat_keepalive_s
)NAT ist eine Integrator- oder Backend-Angabe, keine Funkeigenschaft.
function cw_lp_guard_class
cpp
cw_link_class_t cw_lp_guard_class(
cw_link_class_t effective,
cw_link_class_t radio
)Klasse, nach der die Wachen ihre Fristen waehlen. NAT bestimmt nur Takt und Ankuendigung; wie lange eine Antwort braucht, bestimmt die Funktechnik.
function cw_lp_nat_suspected
cpp
bool cw_lp_nat_suspected(
const uint8_t ipv4[4]
)Lokale Adresse ausserhalb der privaten Telekom-APN-Spanne 10.10.0.0/16. Nur zur Meldung; schaltet nichts um.
function cw_lp_contact_interval_ms
cpp
uint32_t cw_lp_contact_interval_ms(
const cw_lp_profile_t * p
)Angekuendigtes Kontaktintervall: laengste Stille, nach der das Geraet spaetestens selbst sendet und die Antwort abgewartet hat.
function cw_lp_peer_rx_stall_ms
cpp
uint32_t cw_lp_peer_rx_stall_ms(
const cw_lp_profile_t * p
)Rueckweg-Wache: ein ganzes Intervall plus zwei Antwortfristen plus Marge.
function cw_lp_monitor_deadline_ms
cpp
uint32_t cw_lp_monitor_deadline_ms(
const cw_lp_profile_t * p,
uint32_t rnd
)Frist der naechsten Monitoring-Meldung ab dem letzten Kontakt.
function cw_lp_elapsed
cpp
bool cw_lp_elapsed(
uint32_t now_ms,
uint32_t since_ms,
uint32_t span_ms
)Vorzeichenlos ueber den 49,7-Tage-Tick-Wrap.
function cw_lp_report_window_ms
cpp
uint32_t cw_lp_report_window_ms(
const cw_lp_profile_t * p,
cw_cap_state_t cap,
uint32_t nbiot_window_ms,
uint32_t rnd
)Laenge eines Report-Fensters: Grundfenster +U(0, 10 %), bei weichem Deckel verlaengert. nbiot_window_ms ist das Fenster der Stufe SOFT_100.
function cw_lp_backoff_ms
cpp
uint32_t cw_lp_backoff_ms(
uint32_t base_ms,
uint32_t floor_ms,
uint32_t cap_ms,
uint32_t stage,
uint32_t rnd
)Full Jitter: U(floor, max(floor, min(cap, base * 2^stage))).
function cw_lp_ladder_ms
cpp
uint32_t cw_lp_ladder_ms(
uint32_t base_ms,
uint32_t floor_ms,
uint32_t cap_ms,
uint32_t stage,
uint32_t spread_ms,
uint32_t rnd
)Reconnect-Leiter: min(cap, floor * 2^(stage - 1)) + U(0, spread). Stufe 0 wartet wie Stufe 1; ohne Untergrenze beginnt die Leiter bei base_ms.
function cw_lp_rebuild_waits
cpp
bool cw_lp_rebuild_waits(
uint32_t losses_since_ok
)Muss ein Neuaufbau nach einem Sitzungsverlust warten? Der erste geht sofort; jeder weitere ohne beantworteten Sync dazwischen steigt die Leiter hinauf.
function cw_lp_budget_interval_ms
cpp
uint32_t cw_lp_budget_interval_ms(
uint16_t budget_24h
)Mindestabstand zweier Aufbauten bei erschoepftem 24-h-Budget.
function cw_lp_budget_wait_ms
cpp
uint32_t cw_lp_budget_wait_ms(
uint16_t budget_24h,
uint32_t connects_24h,
bool connect_seen,
uint32_t since_last_ms
)Restwartezeit des 24-h-Budgets vor dem naechsten Aufbau, 0 = sofort. budget_24h 0 = kein Budget; since_last_ms zaehlt nur mit connect_seen.
function cw_lp_connect_due
cpp
bool cw_lp_connect_due(
bool waiting,
bool elapsed,
bool evidence,
bool requested,
bool route_back
)Steht ein Aufbau an? Waehrend einer Wartezeit nur, wenn sie abgelaufen ist oder Evidenz sie beendet: ein gescheiterter Aufbau meldet sich ueber onDisconnected() noch im Zustand Connecting und hinterlaesst so eine Anforderung, die sonst jede Wartezeit uebersprang.
function cw_lp_failure_counts
cpp
bool cw_lp_failure_counts(
int route_before,
int route_after
)Zaehlt ein gescheiterter Aufbau fuer die Leiter? Nur mit Route vor und nach dem Versuch: ohne Route hat keine Gegenstelle geschwiegen. Eine unbekannte Route (< 0) gilt als vorhanden.
function cw_lp_rebuild_stage
cpp
uint32_t cw_lp_rebuild_stage(
uint32_t stage,
uint32_t losses_since_ok
)Stufe vor einem wartenden Neuaufbau. Ein beantworteter erster Sync setzt die Stufe zurueck, die Verluste seit dem letzten Folgesync aber nicht: ein Transport, der aufbaut und dann verstummt, steigt so trotzdem hinauf.
function cw_lp_stable_session_ms
cpp
uint32_t cw_lp_stable_session_ms(
uint32_t guard_ms
)Online-Dauer, nach der Stufe und Verlustzaehler zurueckgehen. Mindestens ein Wachfenster guard_ms (danach hat der Rueckweg nachweislich getragen) und nie unter 10 min: eine Sitzung, die nach wenigen Minuten regelmaessig abreisst, behaelt ihre Verluste.
function cw_lp_wait_ends_on_evidence
cpp
bool cw_lp_wait_ends_on_evidence(
cw_wait_kind_t kind
)Beendet neue Evidenz (Adresse, Technik, Empfang, erstes Netz) die Wartezeit? Die Anlaufstreuung nicht: nach einem Stromausfall bekommen die Geraete einer Zelle fast zugleich Netz.
function cw_lp_persist_deadline
cpp
uint32_t cw_lp_persist_deadline(
bool waiting,
cw_wait_kind_t kind,
uint32_t now_utc,
uint32_t left_ms,
uint32_t inherited_utc
)Frist fuer den gespeicherten Leiter-Datensatz (UTC-Sekunden, 0 = keine; now_utc 0 = ohne Uhr). Leiter und Budget speichern ihr Ende, die Anlaufstreuung nur die Frist, die sie vorfand: ein Reset zahlt nichts auf die Leiter ein.
function cw_lp_cap_state
cpp
cw_cap_state_t cw_lp_cap_state(
const cw_lp_profile_t * p,
uint32_t reports_24h,
cw_volume_stage_t vol
)Deckel aus der Zahl der Reports in den letzten 24 h und der Volumenstufe.
function cw_lp_report_allowed
cpp
bool cw_lp_report_allowed(
cw_cap_state_t cap,
bool immediate,
bool last_gasp
)Darf ein Report jetzt raus? "sofort" nutzt die Reserve des harten Deckels; der Last Gasp geht immer, er ist die letzte Nachricht vor dem Stromausfall.
function cw_lp_month_key
cpp
uint32_t cw_lp_month_key(
uint32_t utc_s,
uint32_t * elapsed_s,
uint32_t * month_s
)Kalendermonat (UTC) als Jahr * 12 + Monat (1..12), 0 bei utc_s == 0. elapsed_s (optional): seit Monatsbeginn; month_s (optional): Laenge.
function cw_lp_volume_stage
cpp
cw_volume_stage_t cw_lp_volume_stage(
uint32_t used_bytes,
uint32_t month_budget_bytes,
uint32_t elapsed_s,
uint32_t month_s
)Stufe des Monatsbudgets. elapsed_s / month_s: Anteil des Monats, der schon angespart ist.
function cw_lp_counter_delta
cpp
uint32_t cw_lp_counter_delta(
bool available,
uint32_t cur,
uint32_t * last
)Bytes seit dem letzten Stand eines Netif-Zaehlers; last wird nachgefuehrt. Ohne Interface (available false) wird nichts gebucht und die Basis bleibt stehen: der Modemtreiber verwendet den PPP-Kontrollblock fuer jede Sitzung wieder, dessen Zaehler laufen nach dem Neuaufbau weiter.
function cw_lp_mode
cpp
cw_send_mode_t cw_lp_mode(
bool session_open,
bool live,
cw_cap_state_t cap
)Sendemodus fuer P_SEND_MODE: harter Deckel vor Live vor Sitzung vor weichem Deckel. Der weiche Deckel streckt nur das Report-Fenster; was der Nutzer gerade ansieht, bleibt sofort.
function cw_lp_should_defer
cpp
bool cw_lp_should_defer(
cw_send_mode_t mode,
cw_cap_state_t cap,
bool immediate_pending
)Wartet ein Sync auf das Report-Fenster? Sitzung und Live senden sofort, sonst nur "sofort"-Tags; was der Deckel verbietet, wartet immer.
Macros Documentation
define CW_LP_OFF
cpp
#define CW_LP_OFF (0xFFFFFFFFu)Durationsfeld ausdruecklich auf 0 setzen, wo 0 sonst "Vorgabe" heisst.
Source code
cpp
/*******************************************************************************
* @file cw_link_policy.h
* @license This file is part of the ImagineOn Coldwave eOS software package
* licensed under the ImagineOn software-licensing terms available
* under https://www.imagineon.de/de/info/licensing-terms
* @copyright Copyright (c) 2026. ImagineOn GmbH. www.imagineon.de.
*
* @brief Sendepolitik je Funktechnik (NH2N, GSMA TS.34) als reine
* Entscheidungsfunktionen.
*
* Ohne flake, ohne Uhr, ohne Zufallsquelle: Zeit und Zufall kommen als
* Parameter herein. So ist jede Entscheidung auf dem Host mit
* Entscheidungstabellen pruefbar, und coldwave.cpp haelt keine eigenen
* Fristen-Konstanten mehr, die von diesen hier abweichen koennten.
*******************************************************************************/
#ifndef CW_LINK_POLICY_H
#define CW_LINK_POLICY_H
#include <stdbool.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
// NOLINTBEGIN(modernize-use-using) - C-Header, cw_link_policy.c wird als C uebersetzt.
typedef enum {
CW_LINK_UNKNOWN = 0,
CW_LINK_LTEM = 1,
CW_LINK_NBIOT = 2,
CW_LINK_GSM = 3,
CW_LINK_NAT = 4,
} cw_link_class_t;
typedef enum {
CW_SEND_NORMAL = 0,
CW_SEND_SESSION = 1,
CW_SEND_LIVE = 2,
CW_SEND_CAPPED_SOFT = 3,
CW_SEND_CAPPED_HARD = 4,
} cw_send_mode_t;
typedef enum {
CW_CAP_NONE = 0,
CW_CAP_SOFT_80,
CW_CAP_SOFT_100,
CW_CAP_HARD_REGULAR,
CW_CAP_HARD_ALL,
} cw_cap_state_t;
typedef enum {
CW_VOL_OK = 0,
CW_VOL_THIN_LATEST,
CW_VOL_THIN_CONDENSABLE,
CW_VOL_STOP,
} cw_volume_stage_t;
#define CW_LP_OFF (0xFFFFFFFFu)
typedef struct cw_tag_range_t {
uint16_t first;
uint16_t last;
} cw_tag_range_t;
typedef struct cw_lp_profile_t {
uint32_t report_window_ms;
uint32_t monitor_ms;
uint32_t monitor_jitter_ms;
uint32_t sync_timeout_ms;
uint32_t backoff_floor_ms;
uint32_t backoff_cap_ms;
uint32_t month_budget_bytes;
uint16_t connect_budget_24h;
uint16_t report_cap_24h;
uint16_t report_reserve_24h;
uint8_t hard_cap;
} cw_lp_profile_t;
void cw_lp_profile_defaults(cw_link_class_t cls, cw_lp_profile_t* out);
void cw_lp_profile_resolve(cw_link_class_t cls, cw_lp_profile_t* p);
cw_link_class_t cw_lp_class_from_act(bool valid, uint8_t act);
typedef struct {
cw_link_class_t stable;
cw_link_class_t candidate;
} cw_lp_class_filter_t;
cw_link_class_t cw_lp_class_filter(cw_lp_class_filter_t* f, cw_link_class_t sample);
cw_link_class_t cw_lp_effective_class(cw_link_class_t radio, uint32_t nat_keepalive_s);
cw_link_class_t cw_lp_guard_class(cw_link_class_t effective, cw_link_class_t radio);
bool cw_lp_nat_suspected(const uint8_t ipv4[4]);
uint32_t cw_lp_contact_interval_ms(const cw_lp_profile_t* p);
uint32_t cw_lp_peer_rx_stall_ms(const cw_lp_profile_t* p);
uint32_t cw_lp_monitor_deadline_ms(const cw_lp_profile_t* p, uint32_t rnd);
bool cw_lp_elapsed(uint32_t now_ms, uint32_t since_ms, uint32_t span_ms);
uint32_t cw_lp_report_window_ms(const cw_lp_profile_t* p, cw_cap_state_t cap,
uint32_t nbiot_window_ms, uint32_t rnd);
uint32_t cw_lp_backoff_ms(uint32_t base_ms, uint32_t floor_ms, uint32_t cap_ms,
uint32_t stage, uint32_t rnd);
uint32_t cw_lp_ladder_ms(uint32_t base_ms, uint32_t floor_ms, uint32_t cap_ms, uint32_t stage,
uint32_t spread_ms, uint32_t rnd);
bool cw_lp_rebuild_waits(uint32_t losses_since_ok);
uint32_t cw_lp_budget_interval_ms(uint16_t budget_24h);
uint32_t cw_lp_budget_wait_ms(uint16_t budget_24h, uint32_t connects_24h, bool connect_seen,
uint32_t since_last_ms);
bool cw_lp_connect_due(bool waiting, bool elapsed, bool evidence, bool requested, bool route_back);
bool cw_lp_failure_counts(int route_before, int route_after);
uint32_t cw_lp_rebuild_stage(uint32_t stage, uint32_t losses_since_ok);
uint32_t cw_lp_stable_session_ms(uint32_t guard_ms);
typedef enum {
CW_WAIT_LADDER = 0,
CW_WAIT_BUDGET = 1,
CW_WAIT_STARTUP = 2,
} cw_wait_kind_t;
bool cw_lp_wait_ends_on_evidence(cw_wait_kind_t kind);
uint32_t cw_lp_persist_deadline(bool waiting, cw_wait_kind_t kind, uint32_t now_utc,
uint32_t left_ms, uint32_t inherited_utc);
cw_cap_state_t cw_lp_cap_state(const cw_lp_profile_t* p, uint32_t reports_24h,
cw_volume_stage_t vol);
bool cw_lp_report_allowed(cw_cap_state_t cap, bool immediate, bool last_gasp);
uint32_t cw_lp_month_key(uint32_t utc_s, uint32_t* elapsed_s, uint32_t* month_s);
cw_volume_stage_t cw_lp_volume_stage(uint32_t used_bytes, uint32_t month_budget_bytes,
uint32_t elapsed_s, uint32_t month_s);
uint32_t cw_lp_counter_delta(bool available, uint32_t cur, uint32_t* last);
cw_send_mode_t cw_lp_mode(bool session_open, bool live, cw_cap_state_t cap);
bool cw_lp_should_defer(cw_send_mode_t mode, cw_cap_state_t cap, bool immediate_pending);
// NOLINTEND(modernize-use-using) - Ende des C-Headers.
#ifdef __cplusplus
}
#endif
#endif /* CW_LINK_POLICY_H */