/** * @license * Copyright 2022-2026 Matter.js Authors * SPDX-License-Identifier: Apache-2.0 */ import { Bytes, MatterError, Observable } from "@matter/general"; export declare class BtpMatterError extends MatterError { } export declare class BtpProtocolError extends BtpMatterError { } export declare class BtpFlowError extends BtpMatterError { } export declare class BtpSessionHandler { #private; private readonly role; private readonly fragmentSize; private readonly clientWindowSize; private readonly writeBleCallback; private readonly disconnectBleCallback; private readonly handleMatterMessagePayload; private currentIncomingSegmentedMsgLength; private currentIncomingSegmentedPayload; private prevIncomingSequenceNumber; private prevIncomingAckNumber; private readonly ackReceiveTimer; private sequenceNumber; private prevAckedSequenceNumber; private readonly queuedOutgoingMatterMessages; private sendInProgress; private readonly sendAckTimer; private isActive; private idleTimeout; /** Emitted exactly once when the session transitions to closed. */ get closed(): Observable<[], void>; /** * Emitted instead of {@link closed} when the peer completed the handshake and then sent no BTP packet at all before * the acknowledgement timeout, although we sent it at least one Matter message. Carries the Matter messages the peer * never acknowledged in submission order. Only a central session above the minimum segment size reports this, as the * remedy is a smaller segment size. * * Some peripherals were observed to behave this way with large segments on Bluetooth 4.1 adapters and to work with * the minimum segment size; the cause is not established. Recovering is an interop workaround with no basis in the * specification: the transport may establish a fresh session with a smaller segment size and resend the messages, * which the specification neither describes nor forbids. * * The session is suspended when this fires: it no longer touches the transport, and the transport owns what happens * next. A session nobody observes closes on the acknowledgement timeout, so a transport that cannot renegotiate * need not observe this. */ get stalledAfterHandshake(): Observable<[messagesToReplay: readonly AllowSharedBufferSource[]], void>; /** Factory method to create a new BTPSessionHandler from a received handshake request */ static createFromHandshakeRequest(maxDataSize: number | undefined, handshakeRequestPayload: Bytes, writeBleCallback: (data: Bytes) => Promise, disconnectBleCallback: () => Promise, handleMatterMessagePayload: (data: Bytes) => Promise): Promise; /** * @param requestedSegmentSize The segment size offered in our handshake request. A peripheral must not select more * than we offered, so it also bounds the session; without it a peripheral that echoes an oversized value would * defeat a deliberate reduction of the segment size. */ static createAsCentral(handshakeResponsePayload: Bytes, writeBleCallback: (data: Bytes) => Promise, disconnectBleCallback: () => Promise, handleMatterMessagePayload: (data: Bytes) => Promise, requestedSegmentSize: number): Promise; /** * Creates a new BTP session handler * * @param role The role of the BTP session handler * @param btpVersion The BTP protocol version to use * @param fragmentSize The fragment size to use for the messages * @param clientWindowSize The client window size to use * @param writeBleCallback Callback to write data to the BLE transport * @param disconnectBleCallback Callback to disconnect the BLE transport * @param handleMatterMessagePayload Callback to handle a Matter message payload */ constructor(role: "central" | "peripheral", btpVersion: number, fragmentSize: number, clientWindowSize: number, writeBleCallback: (data: Bytes) => Promise, disconnectBleCallback: () => Promise, handleMatterMessagePayload: (data: Bytes) => Promise); /** * Handle incoming data from the transport layer and hand over completely received matter messages to the * ExchangeManager layer * * @param data ByteArray containing the data */ handleIncomingBleData(data: Bytes): Promise; /** * Send a Matter message to the transport layer, but before that encode it into a BTP packet and potentially split * it into multiple segments. This Method is indirectly called by the ExchangeManager layer when a Matter message * should be sent. * * @param data ByteArray containing the Matter message */ sendMatterMessage(data: Bytes): Promise; private processSendQueue; /** * Close the BTP session. This method is called when the BLE transport is disconnected and so the BTP session gets closed. */ close(): Promise; /** * End the session without touching the transport, so the same BLE connection can carry a renegotiated session. * Unlike {@link close} this emits neither {@link closed} nor a disconnect. */ suspend(): void; /** * If this timer expires and the peer has a pending acknowledgement, the peer SHALL immediately send that * acknowledgement */ private btpSendAckTimeoutTriggered; /** §4.19.4.8: ack proactively once our receive window runs low; skipped if queued data will piggyback it. */ private sendImmediateAckIfWindowLow; /** Send a stand-alone acknowledgement packet if one is pending. */ private sendStandaloneAck; /** * If a peer’s acknowledgement-received timer expires, or if a peer receives an invalid acknowledgement, * the peer SHALL close the BTP session and report an error to the application. * * A stall reported through {@link stalledAfterHandshake} suspends the session instead, leaving the transport to * its observer. */ private btpAckTimeoutTriggered; /** * Increments sequence number for the packets and round it off to 0 when it reaches the maximum limit. */ getNextSequenceNumber(): number; /** Wrap-safe forward distance between two sequence numbers (modulo 256); the -1 sentinels read as 255. */ private modularDistance; /** Free slots in the remote peer's receive window; gates our sending (§4.19.4.7). */ private remoteWindowFreeSlots; /** Free slots in our own receive window; drives proactive acknowledgement (§4.19.4.8). */ private localWindowFreeSlots; /** §4.19.4.7: a data-only packet must leave the last window slot free; an ack-bearing packet may use it. */ private canSend; } //# sourceMappingURL=BtpSessionHandler.d.ts.map