62 lines
2.2 KiB
C++
62 lines
2.2 KiB
C++
/**
|
|
* Link Peer Module (Controller B) - the maintenance side of the link to A.
|
|
*
|
|
* The data path (DATA/CONFIG frames) is UARTReceiver's. This module owns
|
|
* everything else on the link, see wiki/pages/controller-b-ota.md:
|
|
*
|
|
* - STATUS frames B -> A every LINK_STATUS_PERIOD_MS (ESP-NOW unicast to A's
|
|
* MAC, learned from the frames A broadcasts): our version, OTA phase, uptime.
|
|
* - PAIR frames from A, accepted from the UART wire ONLY: the shared key that
|
|
* protects everything below. Kept in NVS, survives reflashes.
|
|
* - SECURE frames from A (ESP-NOW unicast, AES-256-GCM under the pairing key):
|
|
* WIFI_CREDS -> stored in NVS for the OTA module to join with
|
|
* OTA_CMD -> handed to the OTA module (check / install / rollback)
|
|
*
|
|
* Console (`link ...`, `wifi ...`) via Console::handle chain.
|
|
*/
|
|
|
|
#ifndef LINK_PEER_H
|
|
#define LINK_PEER_H
|
|
|
|
#include <Arduino.h>
|
|
#include "protocol/automotive_data.h"
|
|
|
|
namespace LinkPeer {
|
|
|
|
/** Load pairing key + Wi-Fi credentials from NVS. Call before the receivers start. */
|
|
void init();
|
|
|
|
/** STATUS transmit + housekeeping. Call from loop(). */
|
|
void tick();
|
|
|
|
/** ESP-NOW frames that are not DATA/CONFIG (EspNowReceiver hands them here). */
|
|
void onRadioFrame(const uint8_t* mac, const uint8_t* frame, size_t len);
|
|
|
|
/** A PAIR payload that arrived on the UART wire (UARTReceiver hands it here). */
|
|
void onPairFrame(const link_pair_t* p);
|
|
|
|
bool isPaired();
|
|
uint16_t keyFingerprint(); // 0 when unpaired
|
|
|
|
/** Stored Wi-Fi credentials (from A). False if none. Never printed. */
|
|
bool getWifiCredentials(char* ssid, size_t ssid_n, char* pass, size_t pass_n);
|
|
bool hasWifiCredentials();
|
|
void forgetWifi();
|
|
void unpair();
|
|
|
|
// ---- OTA module integration ------------------------------------------------
|
|
|
|
typedef void (*ota_cmd_handler_t)(uint8_t cmd, uint8_t flags);
|
|
void setOtaCommandHandler(ota_cmd_handler_t handler);
|
|
|
|
/** What the STATUS frame reports about the updater. */
|
|
void setOtaStatus(uint8_t phase, uint8_t progress, const char* latest, const char* message,
|
|
bool wifi_joined, bool pending_verify);
|
|
|
|
/** Console: `link status | unpair`, `wifi status | forget`. */
|
|
bool handleCommand(const char* line);
|
|
|
|
} // namespace LinkPeer
|
|
|
|
#endif // LINK_PEER_H
|