Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Figure out a way to express PacketBuffer ownership in the type system #2707

Closed
bzbarsky-apple opened this issue Sep 17, 2020 · 19 comments · Fixed by #4364
Closed

Figure out a way to express PacketBuffer ownership in the type system #2707

bzbarsky-apple opened this issue Sep 17, 2020 · 19 comments · Fixed by #4364
Assignees
Labels
feature work p1 priority 1 work
Milestone

Comments

@bzbarsky-apple
Copy link
Contributor

Problem

If a function takes a PacketBuffer *, it's not obvious from the function signature whether it's expected to free the buffer or not. We can document the semantics, but that still leaves a lot of room for error, and for the function failing to actually implement the semantics properly.

Proposed Solution

Express "this function will free the buffer" in the type system. It seems to me that we want to be able to express the following concepts:

  1. A function is handed "ownership" of a PacketBuffer and is expected to free it.
  2. We are now handing "ownership" of our PacketBuffer to someone else and should not reference it anymore.
  3. We are now incrementing the refcount on a PacketBuffer, after which we will hand over one of the references to someone else and be responsible for releasing the other ourselves.

We could perhaps use std::shared_ptr for this, with std::move at the ownership transfers. Functions expecting ownership would take shared_ptr<PacketBuffer>&&. It's not completely ideal because nothing prevents use of a "moved out of" shared_ptr from being accessed, but at least it would be a null deref, not a UAF.

We could also just pass something like shared_ptr by value, if we think our refcounting is cheap enough.

Ideally, of course, we would have some sort of clonable PacketBuffer handle so we can model the increment explicitly as a clone and we'd have lifetimes a la Rust so when you hand the handle to someone the compiler won't let you touch it again. Sadly, I don't see a way to do that in C++; you can always mess with something like a unique_ptr you called release on...

@sagar-apple @pan-apple @andy31415 @gerickson @turon @rwalker-apple any thoughts or suggestions?

@issue-label-bot
Copy link

Issue-Label Bot is automatically applying the label feature_request to this issue, with a confidence of 0.64. Please mark this comment with 👍 or 👎 to give our bot feedback!

Links: app homepage, dashboard and code for this bot.

@mspang
Copy link
Contributor

mspang commented Sep 17, 2020

Shouldn't it be std::unique_ptr not std::shared_ptr ? Unique ownership captures the main use cases we're considering here; shared ownership makes lifetime much harder to nail down.

It seems to be that std::unique_ptr, with a single return statement should be comparable to what we have now in terms of code size, while being much safer. So that seems like a good idea to me.

@bzbarsky-apple
Copy link
Contributor Author

bzbarsky-apple commented Sep 17, 2020

Shouldn't it be std::unique_ptr not std::shared_ptr ? Unique ownership captures the main use cases we're considering here; shared ownership makes lifetime much harder to nail down.

The whole issue is that not all ownership here is unique. There are several places where we do a manual addref before passing a buffer down into code that "consumes" it, because that code doesn't actually consume everything we have in the buffer.... This is item 3 in my list above.

@mspang
Copy link
Contributor

mspang commented Sep 17, 2020

std::shared_ptr will introduce atomics, weak ptr support, and other things we probably don't want to pay for.

@bzbarsky-apple
Copy link
Contributor Author

I am perfectly comfortable with us inventing a PacketBufferHandle class that has the minimal set of semantics that we want, if people are ok with us doing our own thing.

I think we want:

  1. Construction from a PacketBuffer* addrefs the PacketBuffer.
  2. Construction from a PacketBufferHandle&& steals the value.
  3. Default-construction is allowed.
  4. All other constructors (specifically the copy ctor) are deleted.
  5. Construction from PacketBuffer* is protected; handles are vended by either PacketBuffer factory methods or by cloning an existing handle.
  6. Assignment operators other than one taking PacketBufferHandler&& are deleted.
  7. Destruction frees the PacketBuffer.

I think that more or less satisfies our use case, right?

@woody-apple woody-apple added this to the V1.0 milestone Sep 21, 2020
@rwalker-apple
Copy link
Contributor

I am perfectly comfortable with us inventing a PacketBufferHandle class that has the minimal set of semantics that we want, if people are ok with us doing our own thing.

I think we want:

  1. Construction from a PacketBuffer* addrefs the PacketBuffer.
  2. Construction from a PacketBufferHandle&& steals the value.
  3. Default-construction is allowed.
  4. All other constructors (specifically the copy ctor) are deleted.
  5. Construction from PacketBuffer* is protected; handles are vended by either PacketBuffer factory methods or by cloning an existing handle.
  6. Assignment operators other than one taking PacketBufferHandler&& are deleted.
  7. Destruction frees the PacketBuffer.

I think that more or less satisfies our use case, right?

yeah, I think that's complete, and would be a big improvement

@bzbarsky-apple
Copy link
Contributor Author

Here's what I have so far:

// Implementation inlined to make this zero-cost as much as possible.
class DLL_EXPORT PacketBufferHandle
{
public:
    PacketBufferHandle() : buffer(nullptr) {}
    PacketBufferHandle(decltype(nullptr)) : buffer(nullptr) {}
    PacketBufferHandle(PacketBufferHandle && aOther) 
    {
        buffer        = aOther.buffer;
        aOther.buffer = nullptr;
    }
    ~PacketBufferHandle()
    {
        // PacketBufferHandle::Free is null-safe, but maybe we should check for
        // null here to avoid the pool locking it does?
        PacketBuffer::Free(buffer);
    }
    PacketBufferHandle & operator=(PacketBufferHandle && aOther)
    {
        if (buffer)
        {
            PacketBuffer::Free(buffer);
        }
        buffer        = aOther.buffer;
        aOther.buffer = nullptr;
        return *this;
    }
    PacketBuffer * operator->() { return buffer; }
    // FIXME: or an explicit empty() or something?
    explicit operator bool() { return !!buffer; }

    void Clear()
    {
        if (buffer)
        {
            PacketBuffer::Free(buffer);
            buffer = nullptr;
        }
    }

    PacketBufferHandle Clone() const { return PacketBufferHandle(buffer); }

private:
    PacketBufferHandle(const PacketBufferHandle &) = delete;
    PacketBufferHandle & operator=(const PacketBufferHandle &) = delete;
    friend class PacketBuffer;
    PacketBufferHandle(PacketBuffer * aBuffer) : buffer(aBuffer) { buffer->AddRef(); }
    PacketBuffer * buffer;
};

I would propose that this be used as follows:

  • Functions that conceptually "consume" the buffer would take a PacketBufferHandle by value. This would (1) force callers to std::move at the callsite and (2) guarantee that after the call returns the caller has a nulled-out handle no matter what codepath the callee took. Another option here would be to take PacketBufferHandle &&, which would allow zero-cost forwarding of the argument by just passing the reference along instead of running constructor/destructor code at every call, but it would lead to a slightly more complex mental model in terms of who "owns" the value, especially on error returns. I guess a function that guarantees that it always calls a consuming function could still take PacketBufferHandle&& and maintain the "I always consume it" invariant.
  • Places that need to store a PacketBuffer would store a handle, and assign to it via the assignment operator taking an rvalue reference.
  • Places that need to return a PacketBuffer would return a PacketBufferHandle by value.

I suspect that there would need to be one big PR converting the whole tree to handles or something like that, though if we want to avoid that we could add a temporary forget() method that would allow us to go from a handle to a raw PacketBuffer* that someone else would then have to free. Then we could convert the tree incrementally, starting with SystemPacketBuffer.h/cpp with forget() at all the PacketBuffer::New* callsites and then working out from there until there are no more forget() calls in the tree.

@andy31415
Copy link
Contributor

We may want some Aquire and Release semantics as well (I added such things in #2987)

It would be nice if we could gradually change code rather than an 'all-or-nothing approach'. Usually one would move classes without change into some 'deprecated' (maybe have using DeprecatedPacketBuffe = PacketBuffer) and then work towards updating things.

I would like ownership to be better for sure - I had bugs because of this.

@bzbarsky-apple
Copy link
Contributor Author

We may want some Aquire and Release semantics as well

Given that we always allocate PacketBuffers ourselves (so don't need to Acquire things coming from outside our code), the one case I can think that might need Acquire/Release is if we have to pass a PacketBuffer to some third-party code that basically takes a void*, with ownership being enforced by some out-of-band mechanism (i.e. we pass it a pointer, it eventually calls some callback with that pointer and we free in the callback). If we run into that situation, we can add something to enable it, but I'd rather wait to see whether this becomes an issue in practice.

@rwalker-apple
Copy link
Contributor

note that we don't always allocate PacketBuffers "ourselves", many come up from lwip.

@bzbarsky-apple
Copy link
Contributor Author

Ah, in that case we'll need an Acquire/Adopt thing, yes.

@tcarmelveilleux
Copy link
Contributor

note that we don't always allocate PacketBuffers "ourselves", many come up from lwip.

This is spot-on. Note, as well, that PacketBuffers are implemented on top of lwip pbuf, and there is thus a reference count. PacketBuffers should not be considered to be like "heap". They are kinda more like shared pointers, but they are not direct payload buffer either (not uint8_t*, but rather header + payload). In the underlying pbuf implementation, the pbuf may be linearly allocated header + payload from a heap, or may be passed back from a memory pool, with the payload itself being a reference, or coming from a heap (lwip internal or external allocator) or buffer pools. Lots of companies (including Google Nest) have optimized pbuf allocation code to fit different constraints over time. It's important not to consider a "one size fits all, PacketBuffer means dynamic byte buffer" as this break royally in subtle ways when mixed with different flavors of lwip.

@bzbarsky-apple
Copy link
Contributor Author

Right, to be clear, what we are trying to build here is something to do automated refcounting of PacketBuffers. We are not making any assumptions about heaps or allocation strategies or anything like that. Just making sure that refcounting happens in the right places with minimal space for getting it wrong.

@franck-apple franck-apple added p3 priority 3 work p1 priority 1 work and removed p3 priority 3 work labels Oct 16, 2020
@franck-apple franck-apple modified the milestones: V1.0, 2020-10-30 Oct 22, 2020
@bzbarsky-apple
Copy link
Contributor Author

@kpschoedel do you have any specific planned timeframe for this? This is continuing to cause pain in new code we write.....

@kpschoedel
Copy link
Contributor

@kpschoedel do you have any specific planned timeframe for this? This is continuing to cause pain in new code we write.....

I hadn't, as I was focusing on collection memory use information, but I can start to prioritize this.

BroderickCarlin pushed a commit that referenced this issue Dec 9, 2020
#### Problem

Code should use `PacketBufferHandle` rather than `PacketBuffer *`.

#### Summary of Changes

Simply by using `Create` factory instead of declare-adopt-move.

Part of issue #2707 - Figure out a way to express PacketBuffer ownership in the type system
hnnajh pushed a commit to hnnajh/connectedhomeip that referenced this issue Dec 10, 2020
* Some conversions to use PacketBufferHandle

#### Problem

Code should use `PacketBufferHandle` rather than `PacketBuffer *`.

#### Summary of Changes

- Converts remaining receive path in //src/inet and //src/transport.
- Converts most of //src/ble.
- Introduces Handle versions of the `AddToEnd`/`DetachTail` pair.

Part of issue project-chip#2707 - Figure out a way to express PacketBuffer ownership in the type system

* Restyled by clang-format

* review

* revive BtpEngine::Clear[TR]xPacket()
* simplify conditional
* (void) message.DetachTail() → message.FreeHead()
* remove ExchangeContext::kSendFlag_RetainBuffer
* missed pBuf.IsNull()
* DetachHead() → PopTail()
* typos

Co-authored-by: Restyled.io <[email protected]>
kpschoedel added a commit to kpschoedel/connectedhomeip that referenced this issue Dec 10, 2020
#### Problem

Code should use `PacketBufferHandle` rather than `PacketBuffer *`.

#### Summary of Changes

- Change arguments from `PacketBuffer *` to `PacketBufferHandle`.
  Unfortunately, since this code covers a handful of virtual methods,
  it's impractical to change much less at once.

Part of issue project-chip#2707 - Figure out a way to express PacketBuffer ownership in the type system
kpschoedel added a commit to kpschoedel/connectedhomeip that referenced this issue Dec 14, 2020
#### Problem

Code should use `PacketBufferHandle` rather than `PacketBuffer *`.
Some existing methods should be removed or made private so that code
does not have unnecessary access to the raw pointer.

#### Summary of Changes

- convert public use of `PacketBufferHandle::Adopt()`.
- convert internal use of `Adopt()` to private `Free()`.
- renamed `PacketBuffer::Create()` factory to `Adopt()`.
- rename private `PacketBuffer::Next()` to `ChainedBuffer()`.
- explicity note `PacketBuffer::Next_ForNow()` remaining use in TLV.
- make `PacketBuffer::Free()` private.
- make `PacketBuffer::Consume()` private.
- make `PacketBuffer::AddToEnd_ForNow()` private (still used in tests).
- remove `PacketBuffer::FreeHead_ForNow()`.
- remove `operator*`.

Part of issue project-chip#2707 - Figure out a way to express PacketBuffer ownership in the type system
chrisdecenzo pushed a commit that referenced this issue Jan 6, 2021
* RotatingId: version0

* RotatingId: version1

* RotatingId: version0

* RotatingId: version1

* Fix Darwin host build (#3990)

#### Problem

Some conversions to use PacketBufferHandle (#3909) broke Darwin builds,
which aren't currently run in CI.

#### Summary of Changes

Fix src/platform/Darwin/BleConnectionDelegateImpl.mm to match the API
change in #3909.

* Add '-Wextra' to compiler flags (#3902)

* Implement Level Control Cluster (#3806)

* New seekbar in Android CHIPTool
* Sample usage in lighting-app/nrfconnect

Signed-off-by: Markus Becker <[email protected]>

* Fix Rendezvous over BLE after recent changes (#4012)

PR #3704 introduced a change that the BLE transport in
RendezvousSession is only initialized when PeerAddress
in RendezvousParams is of type BLE. However, PeerAddress
isn't initialized anywhere. As a result Rendezvous over BLE
stopped working between Android CHIPTool and accessories.

Btw, remove an assert related to the storage delegate
as it seems an optional member of the device controller.

* [thread] fix invalid configuration of active dataset (#4008)

* Fix data loss or crash in TCPEndPoint with LwIP (#4022)

* Fix data loss or crash in TCPEndPoint with LwIP

#### Problem

Under the configuration CHIP_SYSTEM_CONFIG_USE_LWIP, in some cases where
the data size exceeds the TCP window size, TCPEndPoint can either die or
lose data when accounting of un-acked data falls out of sync.

#### Summary of Changes

Imported fix from Weave:

* This change removes separate accounting of the unsent
  data position and replaces it with simple counting of
  sent-but-not-acked data and a skip-loop at the start
  of DriveSending().

Fixes #4013 - Data loss or crash in TCPEndPoint with LwIP

* Restyled by clang-format

Co-authored-by: Restyled.io <[email protected]>

* Update lighting-app gen/ folder with ZAP generated content (#4010)

* Fix segmentation fault error in response echo message (#3984)

* Add back Android default build coverage & fix the build (#3966)

mDNS doesn't build with no device layer. Remove it from the build and
add back the coverage that would catch this that was lost in #3340.

* Update all-clusters-app gen/ folder with ZAP generated content (#3963)

* Move src/inet/tests to auto-test-driver generation (#3997)

* Rename TestUtils to UnitTestRegistration. (#4021)

Looking to remove usage of 'Utils' unless we have really no choice.
'UnitTestRegistration' seems clearer in what it does compared to
'TestUtils'.

* Update src/lib/core/tests to auto-test-driver generation (#3991)

* Cleanup zap chip-helper.js (#3973)

* Cleanup zap chip-helper.js

* Restyled by clang-format

Co-authored-by: Restyled.io <[email protected]>

* Move src/transport/tests to auto-test-driver generation (#3999)

* Move src/transport/tests to auto-test-driver generation

* Add relevant libraries (and more test-capable libs) to nrf.

* Refactor inet test helpers (to not include actual inet tests), try to make qemu allow better linkage but still failed for transport tests so disabled for now

* Added more tests on esp32 qemu

* Restyle fixes

* Fix cast errors in InetCommon

* Disable raw tests from zephyr: somehow they fail running out of endpoints

* Disable DNS test on zephyr

* Remove inet endpoint test from zephyr

* Remove inet endpoint test from zephyr - fix again

* Modify gitignore

* Restyle fixes

* Use CHIPDeviceController instead of CHIPDeviceController_deprecated (#3979)

* Implement the missing part of Exchange Header in Transport layer (#4017)

* Implement the missing part of Exchange Header in Transport layer

* Revert comment 'if' back to 'iff'("if and only if")

* Remove duplicated send flag defines and put ExchangeMgr/ExchangeConte… (#3994)

* Remove duplicated send flag defines and put ExchangeMgr/ExchangeContext under the same namespace as CRMP

* Rename kSendFlag_Default to kSendFlag_None

* Move src/lib/asn1/tests and src/ble/tests to auto-test-driver generation (#3998)

* Move src/lib/asn1/tests and src/ble/tests to auto-test-driver generation

* Remove one more unused file

* Attempt to enable asn1 and ble tests in esp32 - see if they pass or not

* Fix merge error

* Update include header for ASN1 test

* Include  ASN1 in libCHIP

* Some conversions to use PacketBufferHandle (#4011)

* Some conversions to use PacketBufferHandle

#### Problem

Code should use `PacketBufferHandle` rather than `PacketBuffer *`.

#### Summary of Changes

- Converts remaining receive path in //src/inet and //src/transport.
- Converts most of //src/ble.
- Introduces Handle versions of the `AddToEnd`/`DetachTail` pair.

Part of issue #2707 - Figure out a way to express PacketBuffer ownership in the type system

* Restyled by clang-format

* review

* revive BtpEngine::Clear[TR]xPacket()
* simplify conditional
* (void) message.DetachTail() → message.FreeHead()
* remove ExchangeContext::kSendFlag_RetainBuffer
* missed pBuf.IsNull()
* DetachHead() → PopTail()
* typos

Co-authored-by: Restyled.io <[email protected]>

* Move src/system/tests to auto-test-driver generation (#4000)

* Move src/system/tests to auto-test-driver generation

* Remove a TCP/IP init call that was killing qemu

* Remove explicit "all" target from root build file (#3967)

The "all" target exists implicitly and contains everything. We don't
need to specify one, and it's misleading to do so specifying deps has no
effect.

* Make src/setup_payload compile with -Werror=conversion (#4032)

* Add SSID and password to chip-tool pairing (#4054)

* Get temperature-measurement and all-clusters-app to use examples/common/chip-app-server (#4039)

#### Problem

PR #3704 introduced a change where a `PeerAddress` is now required in order to start `RendezvousSession`.
Sadly the multiple code paths bootstrapping `RendezvousSession` has not been updated.

PR #4012 add a fix for some of the `examples/` but not for the `all-clusters-app` nor the `temperature-measurement-app`.

To avoid such situation, this PR merge `examples/common/chip-app-server` and the custom code from `all-clusters-app` and `temperature-measurement-app`.

One of the more discutable change of this PR (imo) is the code that moves the custom `Echo` mechanism from the `all-clusters-app` to `chip-app-server`. I was hoping to get rid of it before doing this change but the `all-clusters-app` and the `temperature-measurement-app` are broken since #3704 and this PR should fix that.
Also I have a PR (mostly) ready once #3979 lands to get rid of this `Echo` specific code and replace it by a manufacturer specific `ping` command.

 #### Summary of Changes
 * Remove `EchoServer.cpp`, `RendezvousDeviceDelegate.cpp` and `include/RendezvousDeviceDelegate.h` from `all-clusters-app`
 * Remove `ResponseServer.cpp`, `RendezvousDeviceDelegate.cpp` and `include/RendezvousDeviceDelegate.h` from `temperature-measurement-app`
 * Introduce `chip-app-server/include/AppDelegate.h` in order to keep the behavior the `all-clusters-app` that turns on/off leds on different events. Maybe it should be converted to some types of `ChipDeviceEvent` or `CHIPCallback` at some point.
 * Fix `chip-app-server` to accomodate for the specifics of `all-clusters-app`

* Add all Thread ULA addresses to the lwip interface (#4053)

ULA prefixes will used for CHIP network so we need to add all these
addresses to the interface.

* Remove src/lib/message. (#4055)

* Remove src/lib/message.

Updated messaging implementation lives in src/messaging and the
src/lib/message is not currently compiled or linked in.

This saves us from looking at this code when some refactoring is needed
(e.g. the SystemPacketBuffer changes).

* Remove one more unused file

* [ChipTool] Add Payload Parse Command (#3696)

* [ChipTool] Add Payload Parse Command

* [ChipTool] Add Payload Parse Command

* [ChipTool] Restyle issues resolved

* Restyled by whitespace

* Resolve build errors caused by Command.h schema change

Co-authored-by: lijayaku <[email protected]>
Co-authored-by: Restyled.io <[email protected]>

* rename ParseCommand to QRCodeParseCommand

* adding AdditionalDataParseCommand version 0

* Adding parsing logic + logging

* adding another parsing method

* Basic Parsing is DONE

* fixing memory issue

* removing some logs

* removing more logs

* minor update

* Add RotatingDeviceId to DNS-SD

* fix compilation problem

* fix minor diffs

* cleanup rotating id in ble

* fix dns

* nits

* fix compilation

* Revert "fix minor diffs"

This reverts commit 88fb69c.

* nits

* nit fixes

* update allocation

* update allocation

* refactoring

* revert settings.json

* fix styling

* Update README file

* adding a build flag to bypass advertising the additional data field

* fix styling

* fixing README style

* Fixing nits + added description about the additional data

* fixed minor comment

* remove ParseCommand

* removing unused headers + nits

* Fixing Additional data TLV Tags

* Fix Styling

* removed unnecessary logging tag

* fixing writing rotating id

* fixing minor styles

* adding check for rotating id tag

* restyling

* update AdditionalDataPayloadParser to work on vector of bytes

* restyling

* Nit fix

* Renaming QRCode command to SetupPayload command

* update parse command for additional data

* change compile flags

* update some comments

* fixing parsing/generating the additional data payload

* changing the additional parser APIs

* restyling

* reverting pigweed repo changes

* rename CHIP_ENABLE_ADDITIONAL_ADVERTISING

* removing logging tag

* adding extra validation in parser

* adding docs to the additional data payload parser

* Update ReadME.md

Co-authored-by: Kevin Schoedel <[email protected]>
Co-authored-by: Vivien Nicolas <[email protected]>
Co-authored-by: Markus Becker <[email protected]>
Co-authored-by: Damian Królik <[email protected]>
Co-authored-by: Łukasz Duda <[email protected]>
Co-authored-by: Restyled.io <[email protected]>
Co-authored-by: Yufeng Wang <[email protected]>
Co-authored-by: Michael Spang <[email protected]>
Co-authored-by: Andrei Litvin <[email protected]>
Co-authored-by: jepenven-silabs <[email protected]>
Co-authored-by: Boris Zbarsky <[email protected]>
Co-authored-by: Jiacheng Guo <[email protected]>
Co-authored-by: Liju Jayakumar <[email protected]>
Co-authored-by: lijayaku <[email protected]>
andy31415 pushed a commit that referenced this issue Jan 8, 2021
* Convert mdns Builder classes to use PacketBufferHandle

#### Problem

Code should use `PacketBufferHandle` rather than `PacketBuffer`
directly.

#### Summary of Changes

Convert mdns::Minimal::QueryBuilder and mdns::Minimal::ResponseBuilder
to take and hold PacketBufferHandle.

Part of issue #2707 - Figure out a way to express PacketBuffer ownership in the type system

* Review: make QueryBuilder take const&

* WIP

* Revise to match ResponseBuilder in #4102

* Restyled by clang-format

* remove PacketReporter.cpp change

Co-authored-by: Restyled.io <[email protected]>
kpschoedel added a commit to kpschoedel/connectedhomeip that referenced this issue Jan 8, 2021
* RotatingId: version0

* RotatingId: version1

* RotatingId: version0

* RotatingId: version1

* Fix Darwin host build (project-chip#3990)

#### Problem

Some conversions to use PacketBufferHandle (project-chip#3909) broke Darwin builds,
which aren't currently run in CI.

#### Summary of Changes

Fix src/platform/Darwin/BleConnectionDelegateImpl.mm to match the API
change in project-chip#3909.

* Add '-Wextra' to compiler flags (project-chip#3902)

* Implement Level Control Cluster (project-chip#3806)

* New seekbar in Android CHIPTool
* Sample usage in lighting-app/nrfconnect

Signed-off-by: Markus Becker <[email protected]>

* Fix Rendezvous over BLE after recent changes (project-chip#4012)

PR project-chip#3704 introduced a change that the BLE transport in
RendezvousSession is only initialized when PeerAddress
in RendezvousParams is of type BLE. However, PeerAddress
isn't initialized anywhere. As a result Rendezvous over BLE
stopped working between Android CHIPTool and accessories.

Btw, remove an assert related to the storage delegate
as it seems an optional member of the device controller.

* [thread] fix invalid configuration of active dataset (project-chip#4008)

* Fix data loss or crash in TCPEndPoint with LwIP (project-chip#4022)

* Fix data loss or crash in TCPEndPoint with LwIP

#### Problem

Under the configuration CHIP_SYSTEM_CONFIG_USE_LWIP, in some cases where
the data size exceeds the TCP window size, TCPEndPoint can either die or
lose data when accounting of un-acked data falls out of sync.

#### Summary of Changes

Imported fix from Weave:

* This change removes separate accounting of the unsent
  data position and replaces it with simple counting of
  sent-but-not-acked data and a skip-loop at the start
  of DriveSending().

Fixes project-chip#4013 - Data loss or crash in TCPEndPoint with LwIP

* Restyled by clang-format

Co-authored-by: Restyled.io <[email protected]>

* Update lighting-app gen/ folder with ZAP generated content (project-chip#4010)

* Fix segmentation fault error in response echo message (project-chip#3984)

* Add back Android default build coverage & fix the build (project-chip#3966)

mDNS doesn't build with no device layer. Remove it from the build and
add back the coverage that would catch this that was lost in project-chip#3340.

* Update all-clusters-app gen/ folder with ZAP generated content (project-chip#3963)

* Move src/inet/tests to auto-test-driver generation (project-chip#3997)

* Rename TestUtils to UnitTestRegistration. (project-chip#4021)

Looking to remove usage of 'Utils' unless we have really no choice.
'UnitTestRegistration' seems clearer in what it does compared to
'TestUtils'.

* Update src/lib/core/tests to auto-test-driver generation (project-chip#3991)

* Cleanup zap chip-helper.js (project-chip#3973)

* Cleanup zap chip-helper.js

* Restyled by clang-format

Co-authored-by: Restyled.io <[email protected]>

* Move src/transport/tests to auto-test-driver generation (project-chip#3999)

* Move src/transport/tests to auto-test-driver generation

* Add relevant libraries (and more test-capable libs) to nrf.

* Refactor inet test helpers (to not include actual inet tests), try to make qemu allow better linkage but still failed for transport tests so disabled for now

* Added more tests on esp32 qemu

* Restyle fixes

* Fix cast errors in InetCommon

* Disable raw tests from zephyr: somehow they fail running out of endpoints

* Disable DNS test on zephyr

* Remove inet endpoint test from zephyr

* Remove inet endpoint test from zephyr - fix again

* Modify gitignore

* Restyle fixes

* Use CHIPDeviceController instead of CHIPDeviceController_deprecated (project-chip#3979)

* Implement the missing part of Exchange Header in Transport layer (project-chip#4017)

* Implement the missing part of Exchange Header in Transport layer

* Revert comment 'if' back to 'iff'("if and only if")

* Remove duplicated send flag defines and put ExchangeMgr/ExchangeConte… (project-chip#3994)

* Remove duplicated send flag defines and put ExchangeMgr/ExchangeContext under the same namespace as CRMP

* Rename kSendFlag_Default to kSendFlag_None

* Move src/lib/asn1/tests and src/ble/tests to auto-test-driver generation (project-chip#3998)

* Move src/lib/asn1/tests and src/ble/tests to auto-test-driver generation

* Remove one more unused file

* Attempt to enable asn1 and ble tests in esp32 - see if they pass or not

* Fix merge error

* Update include header for ASN1 test

* Include  ASN1 in libCHIP

* Some conversions to use PacketBufferHandle (project-chip#4011)

* Some conversions to use PacketBufferHandle

#### Problem

Code should use `PacketBufferHandle` rather than `PacketBuffer *`.

#### Summary of Changes

- Converts remaining receive path in //src/inet and //src/transport.
- Converts most of //src/ble.
- Introduces Handle versions of the `AddToEnd`/`DetachTail` pair.

Part of issue project-chip#2707 - Figure out a way to express PacketBuffer ownership in the type system

* Restyled by clang-format

* review

* revive BtpEngine::Clear[TR]xPacket()
* simplify conditional
* (void) message.DetachTail() → message.FreeHead()
* remove ExchangeContext::kSendFlag_RetainBuffer
* missed pBuf.IsNull()
* DetachHead() → PopTail()
* typos

Co-authored-by: Restyled.io <[email protected]>

* Move src/system/tests to auto-test-driver generation (project-chip#4000)

* Move src/system/tests to auto-test-driver generation

* Remove a TCP/IP init call that was killing qemu

* Remove explicit "all" target from root build file (project-chip#3967)

The "all" target exists implicitly and contains everything. We don't
need to specify one, and it's misleading to do so specifying deps has no
effect.

* Make src/setup_payload compile with -Werror=conversion (project-chip#4032)

* Add SSID and password to chip-tool pairing (project-chip#4054)

* Get temperature-measurement and all-clusters-app to use examples/common/chip-app-server (project-chip#4039)

#### Problem

PR project-chip#3704 introduced a change where a `PeerAddress` is now required in order to start `RendezvousSession`.
Sadly the multiple code paths bootstrapping `RendezvousSession` has not been updated.

PR project-chip#4012 add a fix for some of the `examples/` but not for the `all-clusters-app` nor the `temperature-measurement-app`.

To avoid such situation, this PR merge `examples/common/chip-app-server` and the custom code from `all-clusters-app` and `temperature-measurement-app`.

One of the more discutable change of this PR (imo) is the code that moves the custom `Echo` mechanism from the `all-clusters-app` to `chip-app-server`. I was hoping to get rid of it before doing this change but the `all-clusters-app` and the `temperature-measurement-app` are broken since project-chip#3704 and this PR should fix that.
Also I have a PR (mostly) ready once project-chip#3979 lands to get rid of this `Echo` specific code and replace it by a manufacturer specific `ping` command.

 #### Summary of Changes
 * Remove `EchoServer.cpp`, `RendezvousDeviceDelegate.cpp` and `include/RendezvousDeviceDelegate.h` from `all-clusters-app`
 * Remove `ResponseServer.cpp`, `RendezvousDeviceDelegate.cpp` and `include/RendezvousDeviceDelegate.h` from `temperature-measurement-app`
 * Introduce `chip-app-server/include/AppDelegate.h` in order to keep the behavior the `all-clusters-app` that turns on/off leds on different events. Maybe it should be converted to some types of `ChipDeviceEvent` or `CHIPCallback` at some point.
 * Fix `chip-app-server` to accomodate for the specifics of `all-clusters-app`

* Add all Thread ULA addresses to the lwip interface (project-chip#4053)

ULA prefixes will used for CHIP network so we need to add all these
addresses to the interface.

* Remove src/lib/message. (project-chip#4055)

* Remove src/lib/message.

Updated messaging implementation lives in src/messaging and the
src/lib/message is not currently compiled or linked in.

This saves us from looking at this code when some refactoring is needed
(e.g. the SystemPacketBuffer changes).

* Remove one more unused file

* [ChipTool] Add Payload Parse Command (project-chip#3696)

* [ChipTool] Add Payload Parse Command

* [ChipTool] Add Payload Parse Command

* [ChipTool] Restyle issues resolved

* Restyled by whitespace

* Resolve build errors caused by Command.h schema change

Co-authored-by: lijayaku <[email protected]>
Co-authored-by: Restyled.io <[email protected]>

* rename ParseCommand to QRCodeParseCommand

* adding AdditionalDataParseCommand version 0

* Adding parsing logic + logging

* adding another parsing method

* Basic Parsing is DONE

* fixing memory issue

* removing some logs

* removing more logs

* minor update

* Add RotatingDeviceId to DNS-SD

* fix compilation problem

* fix minor diffs

* cleanup rotating id in ble

* fix dns

* nits

* fix compilation

* Revert "fix minor diffs"

This reverts commit 88fb69c.

* nits

* nit fixes

* update allocation

* update allocation

* refactoring

* revert settings.json

* fix styling

* Update README file

* adding a build flag to bypass advertising the additional data field

* fix styling

* fixing README style

* Fixing nits + added description about the additional data

* fixed minor comment

* remove ParseCommand

* removing unused headers + nits

* Fixing Additional data TLV Tags

* Fix Styling

* removed unnecessary logging tag

* fixing writing rotating id

* fixing minor styles

* adding check for rotating id tag

* restyling

* update AdditionalDataPayloadParser to work on vector of bytes

* restyling

* Nit fix

* Renaming QRCode command to SetupPayload command

* update parse command for additional data

* change compile flags

* update some comments

* fixing parsing/generating the additional data payload

* changing the additional parser APIs

* restyling

* reverting pigweed repo changes

* rename CHIP_ENABLE_ADDITIONAL_ADVERTISING

* removing logging tag

* adding extra validation in parser

* adding docs to the additional data payload parser

* Update ReadME.md

Co-authored-by: Kevin Schoedel <[email protected]>
Co-authored-by: Vivien Nicolas <[email protected]>
Co-authored-by: Markus Becker <[email protected]>
Co-authored-by: Damian Królik <[email protected]>
Co-authored-by: Łukasz Duda <[email protected]>
Co-authored-by: Restyled.io <[email protected]>
Co-authored-by: Yufeng Wang <[email protected]>
Co-authored-by: Michael Spang <[email protected]>
Co-authored-by: Andrei Litvin <[email protected]>
Co-authored-by: jepenven-silabs <[email protected]>
Co-authored-by: Boris Zbarsky <[email protected]>
Co-authored-by: Jiacheng Guo <[email protected]>
Co-authored-by: Liju Jayakumar <[email protected]>
Co-authored-by: lijayaku <[email protected]>
kpschoedel added a commit to kpschoedel/connectedhomeip that referenced this issue Jan 8, 2021
…4094)

* Convert mdns Builder classes to use PacketBufferHandle

#### Problem

Code should use `PacketBufferHandle` rather than `PacketBuffer`
directly.

#### Summary of Changes

Convert mdns::Minimal::QueryBuilder and mdns::Minimal::ResponseBuilder
to take and hold PacketBufferHandle.

Part of issue project-chip#2707 - Figure out a way to express PacketBuffer ownership in the type system

* Review: make QueryBuilder take const&

* WIP

* Revise to match ResponseBuilder in project-chip#4102

* Restyled by clang-format

* remove PacketReporter.cpp change

Co-authored-by: Restyled.io <[email protected]>
kpschoedel added a commit to kpschoedel/connectedhomeip that referenced this issue Jan 8, 2021
#### Problem

Code should use `PacketBufferHandle` rather than `PacketBuffer *`.
Some existing methods should be removed or made private so that code
does not have unnecessary access to the raw pointer.

#### Summary of Changes

- convert public use of `PacketBufferHandle::Adopt()`.
- convert internal use of `Adopt()` to private `Free()`.
- renamed `PacketBuffer::Create()` factory to `Adopt()`.
- rename private `PacketBuffer::Next()` to `ChainedBuffer()`.
- explicity note `PacketBuffer::Next_ForNow()` remaining use in TLV.
- make `PacketBuffer::Free()` private.
- make `PacketBuffer::Consume()` private.
- make `PacketBuffer::AddToEnd_ForNow()` private (still used in tests).
- remove `PacketBuffer::FreeHead_ForNow()`.
- remove `operator*`.

Part of issue project-chip#2707 - Figure out a way to express PacketBuffer ownership in the type system
andy31415 pushed a commit that referenced this issue Jan 8, 2021
* SystemPacketBuffer.h cleanup

#### Problem

Code should use `PacketBufferHandle` rather than `PacketBuffer *`.
Some existing methods should be removed or made private so that code
does not have unnecessary access to the raw pointer.

#### Summary of Changes

- convert public use of `PacketBufferHandle::Adopt()`.
- convert internal use of `Adopt()` to private `Free()`.
- renamed `PacketBuffer::Create()` factory to `Adopt()`.
- rename private `PacketBuffer::Next()` to `ChainedBuffer()`.
- explicity note `PacketBuffer::Next_ForNow()` remaining use in TLV.
- make `PacketBuffer::Free()` private.
- make `PacketBuffer::Consume()` private.
- make `PacketBuffer::AddToEnd_ForNow()` private (still used in tests).
- remove `PacketBuffer::FreeHead_ForNow()`.
- remove `operator*`.

Part of issue #2707 - Figure out a way to express PacketBuffer ownership in the type system

* Fix build (crossed paths with #4132)

* Remove PacketBufferHandle::Free()

* Fixes for #4241
kpschoedel added a commit to kpschoedel/connectedhomeip that referenced this issue Jan 8, 2021
#### Problem

Uses of `PacketBuffer` have largely been replaced by
`PacketBufferHandle`. The unit test had not kept up.

#### Summary of Changes

- Added tests for PacketBufferHandle specifically.
- Added many checks of reference counts to verify the ownership model.
- Some more refactoring into `PacketBufferTest`, friend class of
  `PacketBuffer` and `PacketBufferHandle`, to use private fields
  and track buffer allocations.

part of project-chip#2707 - Figure out a way to express PacketBuffer ownership in the type system
kpschoedel added a commit to kpschoedel/connectedhomeip that referenced this issue Jan 13, 2021
#### Problem

Using `PacketBufferHandle` rather than raw `PacketBuffer*` imposes
some overhead on argument passing.

#### Summary of Changes

Parameters converted from by-value to by-rvalue-reference only where
the function unconditionally (and clearly) moves the handle out of
the parameter.

part of project-chip#2707 - Figure out a way to express PacketBuffer ownership in the type system
andy31415 pushed a commit that referenced this issue Jan 14, 2021
* Update TestSystemPacketBuffer

#### Problem

Uses of `PacketBuffer` have largely been replaced by
`PacketBufferHandle`. The unit test had not kept up.

#### Summary of Changes

- Added tests for PacketBufferHandle specifically.
- Added many checks of reference counts to verify the ownership model.
- Some more refactoring into `PacketBufferTest`, friend class of
  `PacketBuffer` and `PacketBufferHandle`, to use private fields
  and track buffer allocations.

part of #2707 - Figure out a way to express PacketBuffer ownership in the type system

* Release buffers more often so that tests work with small pools.
kpschoedel added a commit to kpschoedel/connectedhomeip that referenced this issue Jan 14, 2021
#### Problem

Using `PacketBufferHandle` rather than raw `PacketBuffer*` imposes
some overhead on argument passing.

#### Summary of Changes

Parameters converted from by-value to by-rvalue-reference only where
the function unconditionally (and clearly) moves the handle out of
the parameter.

part of project-chip#2707 - Figure out a way to express PacketBuffer ownership in the type system
kpschoedel added a commit to kpschoedel/connectedhomeip that referenced this issue Jan 14, 2021
#### Problem

Code should use `PacketBufferHandle` rather than `PacketBuffer *`.
A few references and transitional interfaces remain.

#### Summary of Changes

- Promote `Release_ForNow()` to `UnsafeRelease()`. It's impractical
  to remove entirely since it's used conjunction with platform event
  queues.
- Rename `GetLwIPpbuf()` to `UnsafeGetLwIPpbuf()` for consistency.
- Privatize `AddRef()` and raw `SetDataLength()`.
- Remove `AddToEnd_ForNow()`.
- Remove various `using PacketBuffer` declarations.
- Remove obsolete comments about `PacketBuffer *` ownership, and
  rephrase comments mentioning the `PacketBuffer` class by name.

Fixes project-chip#2707 - Figure out a way to express PacketBuffer ownership in the type system
rwalker-apple pushed a commit that referenced this issue Jan 15, 2021
* Use rvalue references for some PacketBufferHandle parameters

#### Problem

Using `PacketBufferHandle` rather than raw `PacketBuffer*` imposes
some overhead on argument passing.

#### Summary of Changes

Parameters converted from by-value to by-rvalue-reference only where
the function unconditionally (and clearly) moves the handle out of
the parameter.

part of #2707 - Figure out a way to express PacketBuffer ownership in the type system

* Restyled by clang-format

* Fix merge from master

Co-authored-by: Restyled.io <[email protected]>
bzbarsky-apple pushed a commit that referenced this issue Jan 26, 2021
* Final PacketBufferHandle cleanup.

#### Problem

Code should use `PacketBufferHandle` rather than `PacketBuffer *`.
A few references and transitional interfaces remain.

#### Summary of Changes

- Promote `Release_ForNow()` to `UnsafeRelease()`. It's impractical
  to remove entirely since it's used conjunction with platform event
  queues.
- Rename `GetLwIPpbuf()` to `UnsafeGetLwIPpbuf()` for consistency.
- Privatize `AddRef()` and raw `SetDataLength()`.
- Remove `AddToEnd_ForNow()`.
- Remove various `using PacketBuffer` declarations.
- Remove obsolete comments about `PacketBuffer *` ownership, and
  rephrase comments mentioning the `PacketBuffer` class by name.

Fixes #2707 - Figure out a way to express PacketBuffer ownership in the type system
austinh0 pushed a commit to austinh0/connectedhomeip that referenced this issue Jan 28, 2021
* Final PacketBufferHandle cleanup.

#### Problem

Code should use `PacketBufferHandle` rather than `PacketBuffer *`.
A few references and transitional interfaces remain.

#### Summary of Changes

- Promote `Release_ForNow()` to `UnsafeRelease()`. It's impractical
  to remove entirely since it's used conjunction with platform event
  queues.
- Rename `GetLwIPpbuf()` to `UnsafeGetLwIPpbuf()` for consistency.
- Privatize `AddRef()` and raw `SetDataLength()`.
- Remove `AddToEnd_ForNow()`.
- Remove various `using PacketBuffer` declarations.
- Remove obsolete comments about `PacketBuffer *` ownership, and
  rephrase comments mentioning the `PacketBuffer` class by name.

Fixes project-chip#2707 - Figure out a way to express PacketBuffer ownership in the type system
austinh0 pushed a commit to austinh0/connectedhomeip that referenced this issue Jan 28, 2021
* Final PacketBufferHandle cleanup.

#### Problem

Code should use `PacketBufferHandle` rather than `PacketBuffer *`.
A few references and transitional interfaces remain.

#### Summary of Changes

- Promote `Release_ForNow()` to `UnsafeRelease()`. It's impractical
  to remove entirely since it's used conjunction with platform event
  queues.
- Rename `GetLwIPpbuf()` to `UnsafeGetLwIPpbuf()` for consistency.
- Privatize `AddRef()` and raw `SetDataLength()`.
- Remove `AddToEnd_ForNow()`.
- Remove various `using PacketBuffer` declarations.
- Remove obsolete comments about `PacketBuffer *` ownership, and
  rephrase comments mentioning the `PacketBuffer` class by name.

Fixes project-chip#2707 - Figure out a way to express PacketBuffer ownership in the type system
woody-apple pushed a commit that referenced this issue Sep 17, 2021
…aligned with the spec (#9455)

* RotatingId: version0

* RotatingId: version1

* RotatingId: version0

* RotatingId: version1

* Fix Darwin host build (#3990)

#### Problem

Some conversions to use PacketBufferHandle (#3909) broke Darwin builds,
which aren't currently run in CI.

#### Summary of Changes

Fix src/platform/Darwin/BleConnectionDelegateImpl.mm to match the API
change in #3909.

* Add '-Wextra' to compiler flags (#3902)

* Implement Level Control Cluster (#3806)

* New seekbar in Android CHIPTool
* Sample usage in lighting-app/nrfconnect

Signed-off-by: Markus Becker <[email protected]>

* Fix Rendezvous over BLE after recent changes (#4012)

PR #3704 introduced a change that the BLE transport in
RendezvousSession is only initialized when PeerAddress
in RendezvousParams is of type BLE. However, PeerAddress
isn't initialized anywhere. As a result Rendezvous over BLE
stopped working between Android CHIPTool and accessories.

Btw, remove an assert related to the storage delegate
as it seems an optional member of the device controller.

* [thread] fix invalid configuration of active dataset (#4008)

* Fix data loss or crash in TCPEndPoint with LwIP (#4022)

* Fix data loss or crash in TCPEndPoint with LwIP

#### Problem

Under the configuration CHIP_SYSTEM_CONFIG_USE_LWIP, in some cases where
the data size exceeds the TCP window size, TCPEndPoint can either die or
lose data when accounting of un-acked data falls out of sync.

#### Summary of Changes

Imported fix from Weave:

* This change removes separate accounting of the unsent
  data position and replaces it with simple counting of
  sent-but-not-acked data and a skip-loop at the start
  of DriveSending().

Fixes #4013 - Data loss or crash in TCPEndPoint with LwIP

* Restyled by clang-format

Co-authored-by: Restyled.io <[email protected]>

* Update lighting-app gen/ folder with ZAP generated content (#4010)

* Fix segmentation fault error in response echo message (#3984)

* Add back Android default build coverage & fix the build (#3966)

mDNS doesn't build with no device layer. Remove it from the build and
add back the coverage that would catch this that was lost in #3340.

* Update all-clusters-app gen/ folder with ZAP generated content (#3963)

* Move src/inet/tests to auto-test-driver generation (#3997)

* Rename TestUtils to UnitTestRegistration. (#4021)

Looking to remove usage of 'Utils' unless we have really no choice.
'UnitTestRegistration' seems clearer in what it does compared to
'TestUtils'.

* Update src/lib/core/tests to auto-test-driver generation (#3991)

* Cleanup zap chip-helper.js (#3973)

* Cleanup zap chip-helper.js

* Restyled by clang-format

Co-authored-by: Restyled.io <[email protected]>

* Move src/transport/tests to auto-test-driver generation (#3999)

* Move src/transport/tests to auto-test-driver generation

* Add relevant libraries (and more test-capable libs) to nrf.

* Refactor inet test helpers (to not include actual inet tests), try to make qemu allow better linkage but still failed for transport tests so disabled for now

* Added more tests on esp32 qemu

* Restyle fixes

* Fix cast errors in InetCommon

* Disable raw tests from zephyr: somehow they fail running out of endpoints

* Disable DNS test on zephyr

* Remove inet endpoint test from zephyr

* Remove inet endpoint test from zephyr - fix again

* Modify gitignore

* Restyle fixes

* Use CHIPDeviceController instead of CHIPDeviceController_deprecated (#3979)

* Implement the missing part of Exchange Header in Transport layer (#4017)

* Implement the missing part of Exchange Header in Transport layer

* Revert comment 'if' back to 'iff'("if and only if")

* Remove duplicated send flag defines and put ExchangeMgr/ExchangeConte… (#3994)

* Remove duplicated send flag defines and put ExchangeMgr/ExchangeContext under the same namespace as CRMP

* Rename kSendFlag_Default to kSendFlag_None

* Move src/lib/asn1/tests and src/ble/tests to auto-test-driver generation (#3998)

* Move src/lib/asn1/tests and src/ble/tests to auto-test-driver generation

* Remove one more unused file

* Attempt to enable asn1 and ble tests in esp32 - see if they pass or not

* Fix merge error

* Update include header for ASN1 test

* Include  ASN1 in libCHIP

* Some conversions to use PacketBufferHandle (#4011)

* Some conversions to use PacketBufferHandle

#### Problem

Code should use `PacketBufferHandle` rather than `PacketBuffer *`.

#### Summary of Changes

- Converts remaining receive path in //src/inet and //src/transport.
- Converts most of //src/ble.
- Introduces Handle versions of the `AddToEnd`/`DetachTail` pair.

Part of issue #2707 - Figure out a way to express PacketBuffer ownership in the type system

* Restyled by clang-format

* review

* revive BtpEngine::Clear[TR]xPacket()
* simplify conditional
* (void) message.DetachTail() → message.FreeHead()
* remove ExchangeContext::kSendFlag_RetainBuffer
* missed pBuf.IsNull()
* DetachHead() → PopTail()
* typos

Co-authored-by: Restyled.io <[email protected]>

* Move src/system/tests to auto-test-driver generation (#4000)

* Move src/system/tests to auto-test-driver generation

* Remove a TCP/IP init call that was killing qemu

* Remove explicit "all" target from root build file (#3967)

The "all" target exists implicitly and contains everything. We don't
need to specify one, and it's misleading to do so specifying deps has no
effect.

* Make src/setup_payload compile with -Werror=conversion (#4032)

* Add SSID and password to chip-tool pairing (#4054)

* Get temperature-measurement and all-clusters-app to use examples/common/chip-app-server (#4039)

#### Problem

PR #3704 introduced a change where a `PeerAddress` is now required in order to start `RendezvousSession`.
Sadly the multiple code paths bootstrapping `RendezvousSession` has not been updated.

PR #4012 add a fix for some of the `examples/` but not for the `all-clusters-app` nor the `temperature-measurement-app`.

To avoid such situation, this PR merge `examples/common/chip-app-server` and the custom code from `all-clusters-app` and `temperature-measurement-app`.

One of the more discutable change of this PR (imo) is the code that moves the custom `Echo` mechanism from the `all-clusters-app` to `chip-app-server`. I was hoping to get rid of it before doing this change but the `all-clusters-app` and the `temperature-measurement-app` are broken since #3704 and this PR should fix that.
Also I have a PR (mostly) ready once #3979 lands to get rid of this `Echo` specific code and replace it by a manufacturer specific `ping` command.

 #### Summary of Changes
 * Remove `EchoServer.cpp`, `RendezvousDeviceDelegate.cpp` and `include/RendezvousDeviceDelegate.h` from `all-clusters-app`
 * Remove `ResponseServer.cpp`, `RendezvousDeviceDelegate.cpp` and `include/RendezvousDeviceDelegate.h` from `temperature-measurement-app`
 * Introduce `chip-app-server/include/AppDelegate.h` in order to keep the behavior the `all-clusters-app` that turns on/off leds on different events. Maybe it should be converted to some types of `ChipDeviceEvent` or `CHIPCallback` at some point.
 * Fix `chip-app-server` to accomodate for the specifics of `all-clusters-app`

* Add all Thread ULA addresses to the lwip interface (#4053)

ULA prefixes will used for CHIP network so we need to add all these
addresses to the interface.

* Remove src/lib/message. (#4055)

* Remove src/lib/message.

Updated messaging implementation lives in src/messaging and the
src/lib/message is not currently compiled or linked in.

This saves us from looking at this code when some refactoring is needed
(e.g. the SystemPacketBuffer changes).

* Remove one more unused file

* [ChipTool] Add Payload Parse Command (#3696)

* [ChipTool] Add Payload Parse Command

* [ChipTool] Add Payload Parse Command

* [ChipTool] Restyle issues resolved

* Restyled by whitespace

* Resolve build errors caused by Command.h schema change

Co-authored-by: lijayaku <[email protected]>
Co-authored-by: Restyled.io <[email protected]>

* rename ParseCommand to QRCodeParseCommand

* adding AdditionalDataParseCommand version 0

* Adding parsing logic + logging

* adding another parsing method

* Basic Parsing is DONE

* fixing memory issue

* removing some logs

* removing more logs

* minor update

* Add RotatingDeviceId to DNS-SD

* Revert "Merge pull request #4 from hnnajh/rotating-id-test"

This reverts commit 0235d05, reversing
changes made to 3e1a4b9.

* Storing RI in Octet String + Adding Binary format for BLE

* Fixing rotating id parser + adding unittests

* restyling

* refactoring rotating id unit tests

* Added more unit tests for Rotating Device Id

* updated styling

* refactor RI tests

* Added RI Unittest + more validation

* applying restyling

* Fix CI

* update styling

* Fix CI

* Update Styling

* Fix CI

* Restyling

* Fixing nits

* Using MutableByteSpan in RI generation

* Fixing nits

Co-authored-by: Kevin Schoedel <[email protected]>
Co-authored-by: Vivien Nicolas <[email protected]>
Co-authored-by: Markus Becker <[email protected]>
Co-authored-by: Damian Królik <[email protected]>
Co-authored-by: Łukasz Duda <[email protected]>
Co-authored-by: Restyled.io <[email protected]>
Co-authored-by: Yufeng Wang <[email protected]>
Co-authored-by: Michael Spang <[email protected]>
Co-authored-by: Andrei Litvin <[email protected]>
Co-authored-by: jepenven-silabs <[email protected]>
Co-authored-by: Boris Zbarsky <[email protected]>
Co-authored-by: Jiacheng Guo <[email protected]>
Co-authored-by: Liju Jayakumar <[email protected]>
Co-authored-by: lijayaku <[email protected]>
mleisner pushed a commit to mleisner/connectedhomeip that referenced this issue Sep 20, 2021
…aligned with the spec (project-chip#9455)

* RotatingId: version0

* RotatingId: version1

* RotatingId: version0

* RotatingId: version1

* Fix Darwin host build (project-chip#3990)

#### Problem

Some conversions to use PacketBufferHandle (project-chip#3909) broke Darwin builds,
which aren't currently run in CI.

#### Summary of Changes

Fix src/platform/Darwin/BleConnectionDelegateImpl.mm to match the API
change in project-chip#3909.

* Add '-Wextra' to compiler flags (project-chip#3902)

* Implement Level Control Cluster (project-chip#3806)

* New seekbar in Android CHIPTool
* Sample usage in lighting-app/nrfconnect

Signed-off-by: Markus Becker <[email protected]>

* Fix Rendezvous over BLE after recent changes (project-chip#4012)

PR project-chip#3704 introduced a change that the BLE transport in
RendezvousSession is only initialized when PeerAddress
in RendezvousParams is of type BLE. However, PeerAddress
isn't initialized anywhere. As a result Rendezvous over BLE
stopped working between Android CHIPTool and accessories.

Btw, remove an assert related to the storage delegate
as it seems an optional member of the device controller.

* [thread] fix invalid configuration of active dataset (project-chip#4008)

* Fix data loss or crash in TCPEndPoint with LwIP (project-chip#4022)

* Fix data loss or crash in TCPEndPoint with LwIP

#### Problem

Under the configuration CHIP_SYSTEM_CONFIG_USE_LWIP, in some cases where
the data size exceeds the TCP window size, TCPEndPoint can either die or
lose data when accounting of un-acked data falls out of sync.

#### Summary of Changes

Imported fix from Weave:

* This change removes separate accounting of the unsent
  data position and replaces it with simple counting of
  sent-but-not-acked data and a skip-loop at the start
  of DriveSending().

Fixes project-chip#4013 - Data loss or crash in TCPEndPoint with LwIP

* Restyled by clang-format

Co-authored-by: Restyled.io <[email protected]>

* Update lighting-app gen/ folder with ZAP generated content (project-chip#4010)

* Fix segmentation fault error in response echo message (project-chip#3984)

* Add back Android default build coverage & fix the build (project-chip#3966)

mDNS doesn't build with no device layer. Remove it from the build and
add back the coverage that would catch this that was lost in project-chip#3340.

* Update all-clusters-app gen/ folder with ZAP generated content (project-chip#3963)

* Move src/inet/tests to auto-test-driver generation (project-chip#3997)

* Rename TestUtils to UnitTestRegistration. (project-chip#4021)

Looking to remove usage of 'Utils' unless we have really no choice.
'UnitTestRegistration' seems clearer in what it does compared to
'TestUtils'.

* Update src/lib/core/tests to auto-test-driver generation (project-chip#3991)

* Cleanup zap chip-helper.js (project-chip#3973)

* Cleanup zap chip-helper.js

* Restyled by clang-format

Co-authored-by: Restyled.io <[email protected]>

* Move src/transport/tests to auto-test-driver generation (project-chip#3999)

* Move src/transport/tests to auto-test-driver generation

* Add relevant libraries (and more test-capable libs) to nrf.

* Refactor inet test helpers (to not include actual inet tests), try to make qemu allow better linkage but still failed for transport tests so disabled for now

* Added more tests on esp32 qemu

* Restyle fixes

* Fix cast errors in InetCommon

* Disable raw tests from zephyr: somehow they fail running out of endpoints

* Disable DNS test on zephyr

* Remove inet endpoint test from zephyr

* Remove inet endpoint test from zephyr - fix again

* Modify gitignore

* Restyle fixes

* Use CHIPDeviceController instead of CHIPDeviceController_deprecated (project-chip#3979)

* Implement the missing part of Exchange Header in Transport layer (project-chip#4017)

* Implement the missing part of Exchange Header in Transport layer

* Revert comment 'if' back to 'iff'("if and only if")

* Remove duplicated send flag defines and put ExchangeMgr/ExchangeConte… (project-chip#3994)

* Remove duplicated send flag defines and put ExchangeMgr/ExchangeContext under the same namespace as CRMP

* Rename kSendFlag_Default to kSendFlag_None

* Move src/lib/asn1/tests and src/ble/tests to auto-test-driver generation (project-chip#3998)

* Move src/lib/asn1/tests and src/ble/tests to auto-test-driver generation

* Remove one more unused file

* Attempt to enable asn1 and ble tests in esp32 - see if they pass or not

* Fix merge error

* Update include header for ASN1 test

* Include  ASN1 in libCHIP

* Some conversions to use PacketBufferHandle (project-chip#4011)

* Some conversions to use PacketBufferHandle

#### Problem

Code should use `PacketBufferHandle` rather than `PacketBuffer *`.

#### Summary of Changes

- Converts remaining receive path in //src/inet and //src/transport.
- Converts most of //src/ble.
- Introduces Handle versions of the `AddToEnd`/`DetachTail` pair.

Part of issue project-chip#2707 - Figure out a way to express PacketBuffer ownership in the type system

* Restyled by clang-format

* review

* revive BtpEngine::Clear[TR]xPacket()
* simplify conditional
* (void) message.DetachTail() → message.FreeHead()
* remove ExchangeContext::kSendFlag_RetainBuffer
* missed pBuf.IsNull()
* DetachHead() → PopTail()
* typos

Co-authored-by: Restyled.io <[email protected]>

* Move src/system/tests to auto-test-driver generation (project-chip#4000)

* Move src/system/tests to auto-test-driver generation

* Remove a TCP/IP init call that was killing qemu

* Remove explicit "all" target from root build file (project-chip#3967)

The "all" target exists implicitly and contains everything. We don't
need to specify one, and it's misleading to do so specifying deps has no
effect.

* Make src/setup_payload compile with -Werror=conversion (project-chip#4032)

* Add SSID and password to chip-tool pairing (project-chip#4054)

* Get temperature-measurement and all-clusters-app to use examples/common/chip-app-server (project-chip#4039)

#### Problem

PR project-chip#3704 introduced a change where a `PeerAddress` is now required in order to start `RendezvousSession`.
Sadly the multiple code paths bootstrapping `RendezvousSession` has not been updated.

PR project-chip#4012 add a fix for some of the `examples/` but not for the `all-clusters-app` nor the `temperature-measurement-app`.

To avoid such situation, this PR merge `examples/common/chip-app-server` and the custom code from `all-clusters-app` and `temperature-measurement-app`.

One of the more discutable change of this PR (imo) is the code that moves the custom `Echo` mechanism from the `all-clusters-app` to `chip-app-server`. I was hoping to get rid of it before doing this change but the `all-clusters-app` and the `temperature-measurement-app` are broken since project-chip#3704 and this PR should fix that.
Also I have a PR (mostly) ready once project-chip#3979 lands to get rid of this `Echo` specific code and replace it by a manufacturer specific `ping` command.

 #### Summary of Changes
 * Remove `EchoServer.cpp`, `RendezvousDeviceDelegate.cpp` and `include/RendezvousDeviceDelegate.h` from `all-clusters-app`
 * Remove `ResponseServer.cpp`, `RendezvousDeviceDelegate.cpp` and `include/RendezvousDeviceDelegate.h` from `temperature-measurement-app`
 * Introduce `chip-app-server/include/AppDelegate.h` in order to keep the behavior the `all-clusters-app` that turns on/off leds on different events. Maybe it should be converted to some types of `ChipDeviceEvent` or `CHIPCallback` at some point.
 * Fix `chip-app-server` to accomodate for the specifics of `all-clusters-app`

* Add all Thread ULA addresses to the lwip interface (project-chip#4053)

ULA prefixes will used for CHIP network so we need to add all these
addresses to the interface.

* Remove src/lib/message. (project-chip#4055)

* Remove src/lib/message.

Updated messaging implementation lives in src/messaging and the
src/lib/message is not currently compiled or linked in.

This saves us from looking at this code when some refactoring is needed
(e.g. the SystemPacketBuffer changes).

* Remove one more unused file

* [ChipTool] Add Payload Parse Command (project-chip#3696)

* [ChipTool] Add Payload Parse Command

* [ChipTool] Add Payload Parse Command

* [ChipTool] Restyle issues resolved

* Restyled by whitespace

* Resolve build errors caused by Command.h schema change

Co-authored-by: lijayaku <[email protected]>
Co-authored-by: Restyled.io <[email protected]>

* rename ParseCommand to QRCodeParseCommand

* adding AdditionalDataParseCommand version 0

* Adding parsing logic + logging

* adding another parsing method

* Basic Parsing is DONE

* fixing memory issue

* removing some logs

* removing more logs

* minor update

* Add RotatingDeviceId to DNS-SD

* Revert "Merge pull request #4 from hnnajh/rotating-id-test"

This reverts commit 0235d05, reversing
changes made to 3e1a4b9.

* Storing RI in Octet String + Adding Binary format for BLE

* Fixing rotating id parser + adding unittests

* restyling

* refactoring rotating id unit tests

* Added more unit tests for Rotating Device Id

* updated styling

* refactor RI tests

* Added RI Unittest + more validation

* applying restyling

* Fix CI

* update styling

* Fix CI

* Update Styling

* Fix CI

* Restyling

* Fixing nits

* Using MutableByteSpan in RI generation

* Fixing nits

Co-authored-by: Kevin Schoedel <[email protected]>
Co-authored-by: Vivien Nicolas <[email protected]>
Co-authored-by: Markus Becker <[email protected]>
Co-authored-by: Damian Królik <[email protected]>
Co-authored-by: Łukasz Duda <[email protected]>
Co-authored-by: Restyled.io <[email protected]>
Co-authored-by: Yufeng Wang <[email protected]>
Co-authored-by: Michael Spang <[email protected]>
Co-authored-by: Andrei Litvin <[email protected]>
Co-authored-by: jepenven-silabs <[email protected]>
Co-authored-by: Boris Zbarsky <[email protected]>
Co-authored-by: Jiacheng Guo <[email protected]>
Co-authored-by: Liju Jayakumar <[email protected]>
Co-authored-by: lijayaku <[email protected]>
andy31415 added a commit that referenced this issue Jan 20, 2022
* RotatingId: version0

* RotatingId: version1

* RotatingId: version0

* RotatingId: version1

* Fix Darwin host build (#3990)

#### Problem

Some conversions to use PacketBufferHandle (#3909) broke Darwin builds,
which aren't currently run in CI.

#### Summary of Changes

Fix src/platform/Darwin/BleConnectionDelegateImpl.mm to match the API
change in #3909.

* Add '-Wextra' to compiler flags (#3902)

* Implement Level Control Cluster (#3806)

* New seekbar in Android CHIPTool
* Sample usage in lighting-app/nrfconnect

Signed-off-by: Markus Becker <[email protected]>

* Fix Rendezvous over BLE after recent changes (#4012)

PR #3704 introduced a change that the BLE transport in
RendezvousSession is only initialized when PeerAddress
in RendezvousParams is of type BLE. However, PeerAddress
isn't initialized anywhere. As a result Rendezvous over BLE
stopped working between Android CHIPTool and accessories.

Btw, remove an assert related to the storage delegate
as it seems an optional member of the device controller.

* [thread] fix invalid configuration of active dataset (#4008)

* Fix data loss or crash in TCPEndPoint with LwIP (#4022)

* Fix data loss or crash in TCPEndPoint with LwIP

#### Problem

Under the configuration CHIP_SYSTEM_CONFIG_USE_LWIP, in some cases where
the data size exceeds the TCP window size, TCPEndPoint can either die or
lose data when accounting of un-acked data falls out of sync.

#### Summary of Changes

Imported fix from Weave:

* This change removes separate accounting of the unsent
  data position and replaces it with simple counting of
  sent-but-not-acked data and a skip-loop at the start
  of DriveSending().

Fixes #4013 - Data loss or crash in TCPEndPoint with LwIP

* Restyled by clang-format

Co-authored-by: Restyled.io <[email protected]>

* Update lighting-app gen/ folder with ZAP generated content (#4010)

* Fix segmentation fault error in response echo message (#3984)

* Add back Android default build coverage & fix the build (#3966)

mDNS doesn't build with no device layer. Remove it from the build and
add back the coverage that would catch this that was lost in #3340.

* Update all-clusters-app gen/ folder with ZAP generated content (#3963)

* Move src/inet/tests to auto-test-driver generation (#3997)

* Rename TestUtils to UnitTestRegistration. (#4021)

Looking to remove usage of 'Utils' unless we have really no choice.
'UnitTestRegistration' seems clearer in what it does compared to
'TestUtils'.

* Update src/lib/core/tests to auto-test-driver generation (#3991)

* Cleanup zap chip-helper.js (#3973)

* Cleanup zap chip-helper.js

* Restyled by clang-format

Co-authored-by: Restyled.io <[email protected]>

* Move src/transport/tests to auto-test-driver generation (#3999)

* Move src/transport/tests to auto-test-driver generation

* Add relevant libraries (and more test-capable libs) to nrf.

* Refactor inet test helpers (to not include actual inet tests), try to make qemu allow better linkage but still failed for transport tests so disabled for now

* Added more tests on esp32 qemu

* Restyle fixes

* Fix cast errors in InetCommon

* Disable raw tests from zephyr: somehow they fail running out of endpoints

* Disable DNS test on zephyr

* Remove inet endpoint test from zephyr

* Remove inet endpoint test from zephyr - fix again

* Modify gitignore

* Restyle fixes

* Use CHIPDeviceController instead of CHIPDeviceController_deprecated (#3979)

* Implement the missing part of Exchange Header in Transport layer (#4017)

* Implement the missing part of Exchange Header in Transport layer

* Revert comment 'if' back to 'iff'("if and only if")

* Remove duplicated send flag defines and put ExchangeMgr/ExchangeConte… (#3994)

* Remove duplicated send flag defines and put ExchangeMgr/ExchangeContext under the same namespace as CRMP

* Rename kSendFlag_Default to kSendFlag_None

* Move src/lib/asn1/tests and src/ble/tests to auto-test-driver generation (#3998)

* Move src/lib/asn1/tests and src/ble/tests to auto-test-driver generation

* Remove one more unused file

* Attempt to enable asn1 and ble tests in esp32 - see if they pass or not

* Fix merge error

* Update include header for ASN1 test

* Include  ASN1 in libCHIP

* Some conversions to use PacketBufferHandle (#4011)

* Some conversions to use PacketBufferHandle

#### Problem

Code should use `PacketBufferHandle` rather than `PacketBuffer *`.

#### Summary of Changes

- Converts remaining receive path in //src/inet and //src/transport.
- Converts most of //src/ble.
- Introduces Handle versions of the `AddToEnd`/`DetachTail` pair.

Part of issue #2707 - Figure out a way to express PacketBuffer ownership in the type system

* Restyled by clang-format

* review

* revive BtpEngine::Clear[TR]xPacket()
* simplify conditional
* (void) message.DetachTail() → message.FreeHead()
* remove ExchangeContext::kSendFlag_RetainBuffer
* missed pBuf.IsNull()
* DetachHead() → PopTail()
* typos

Co-authored-by: Restyled.io <[email protected]>

* Move src/system/tests to auto-test-driver generation (#4000)

* Move src/system/tests to auto-test-driver generation

* Remove a TCP/IP init call that was killing qemu

* Remove explicit "all" target from root build file (#3967)

The "all" target exists implicitly and contains everything. We don't
need to specify one, and it's misleading to do so specifying deps has no
effect.

* Make src/setup_payload compile with -Werror=conversion (#4032)

* Add SSID and password to chip-tool pairing (#4054)

* Get temperature-measurement and all-clusters-app to use examples/common/chip-app-server (#4039)

#### Problem

PR #3704 introduced a change where a `PeerAddress` is now required in order to start `RendezvousSession`.
Sadly the multiple code paths bootstrapping `RendezvousSession` has not been updated.

PR #4012 add a fix for some of the `examples/` but not for the `all-clusters-app` nor the `temperature-measurement-app`.

To avoid such situation, this PR merge `examples/common/chip-app-server` and the custom code from `all-clusters-app` and `temperature-measurement-app`.

One of the more discutable change of this PR (imo) is the code that moves the custom `Echo` mechanism from the `all-clusters-app` to `chip-app-server`. I was hoping to get rid of it before doing this change but the `all-clusters-app` and the `temperature-measurement-app` are broken since #3704 and this PR should fix that.
Also I have a PR (mostly) ready once #3979 lands to get rid of this `Echo` specific code and replace it by a manufacturer specific `ping` command.

 #### Summary of Changes
 * Remove `EchoServer.cpp`, `RendezvousDeviceDelegate.cpp` and `include/RendezvousDeviceDelegate.h` from `all-clusters-app`
 * Remove `ResponseServer.cpp`, `RendezvousDeviceDelegate.cpp` and `include/RendezvousDeviceDelegate.h` from `temperature-measurement-app`
 * Introduce `chip-app-server/include/AppDelegate.h` in order to keep the behavior the `all-clusters-app` that turns on/off leds on different events. Maybe it should be converted to some types of `ChipDeviceEvent` or `CHIPCallback` at some point.
 * Fix `chip-app-server` to accomodate for the specifics of `all-clusters-app`

* Add all Thread ULA addresses to the lwip interface (#4053)

ULA prefixes will used for CHIP network so we need to add all these
addresses to the interface.

* Remove src/lib/message. (#4055)

* Remove src/lib/message.

Updated messaging implementation lives in src/messaging and the
src/lib/message is not currently compiled or linked in.

This saves us from looking at this code when some refactoring is needed
(e.g. the SystemPacketBuffer changes).

* Remove one more unused file

* [ChipTool] Add Payload Parse Command (#3696)

* [ChipTool] Add Payload Parse Command

* [ChipTool] Add Payload Parse Command

* [ChipTool] Restyle issues resolved

* Restyled by whitespace

* Resolve build errors caused by Command.h schema change

Co-authored-by: lijayaku <[email protected]>
Co-authored-by: Restyled.io <[email protected]>

* rename ParseCommand to QRCodeParseCommand

* adding AdditionalDataParseCommand version 0

* Adding parsing logic + logging

* adding another parsing method

* Basic Parsing is DONE

* fixing memory issue

* removing some logs

* removing more logs

* minor update

* Add RotatingDeviceId to DNS-SD

* Revert "Merge pull request #4 from hnnajh/rotating-id-test"

This reverts commit 0235d05, reversing
changes made to 3e1a4b9.

* increment lifetime counter

* Incrementing lifetime counter at each BLE/MDNS advertisement

* address comments

* Update src/include/platform/ConfigurationManager.h

Co-authored-by: Boris Zbarsky <[email protected]>

* removing unnecessary lines

* nit

* Update src/app/server/Dnssd.cpp

Co-authored-by: chrisdecenzo <[email protected]>

* restyling

* Update src/app/server/Dnssd.cpp

Co-authored-by: chrisdecenzo <[email protected]>

* Update src/app/server/Dnssd.cpp

Co-authored-by: chrisdecenzo <[email protected]>

* fix comments

* incrementing lifetimecounter once

* remove unnecessary include

Co-authored-by: Kevin Schoedel <[email protected]>
Co-authored-by: Vivien Nicolas <[email protected]>
Co-authored-by: Markus Becker <[email protected]>
Co-authored-by: Damian Królik <[email protected]>
Co-authored-by: Łukasz Duda <[email protected]>
Co-authored-by: Restyled.io <[email protected]>
Co-authored-by: Yufeng Wang <[email protected]>
Co-authored-by: Michael Spang <[email protected]>
Co-authored-by: Andrei Litvin <[email protected]>
Co-authored-by: jepenven-silabs <[email protected]>
Co-authored-by: Boris Zbarsky <[email protected]>
Co-authored-by: Jiacheng Guo <[email protected]>
Co-authored-by: Liju Jayakumar <[email protected]>
Co-authored-by: lijayaku <[email protected]>
Co-authored-by: chrisdecenzo <[email protected]>
selissia pushed a commit to selissia/connectedhomeip that referenced this issue Jan 28, 2022
* RotatingId: version0

* RotatingId: version1

* RotatingId: version0

* RotatingId: version1

* Fix Darwin host build (project-chip#3990)

#### Problem

Some conversions to use PacketBufferHandle (project-chip#3909) broke Darwin builds,
which aren't currently run in CI.

#### Summary of Changes

Fix src/platform/Darwin/BleConnectionDelegateImpl.mm to match the API
change in project-chip#3909.

* Add '-Wextra' to compiler flags (project-chip#3902)

* Implement Level Control Cluster (project-chip#3806)

* New seekbar in Android CHIPTool
* Sample usage in lighting-app/nrfconnect

Signed-off-by: Markus Becker <[email protected]>

* Fix Rendezvous over BLE after recent changes (project-chip#4012)

PR project-chip#3704 introduced a change that the BLE transport in
RendezvousSession is only initialized when PeerAddress
in RendezvousParams is of type BLE. However, PeerAddress
isn't initialized anywhere. As a result Rendezvous over BLE
stopped working between Android CHIPTool and accessories.

Btw, remove an assert related to the storage delegate
as it seems an optional member of the device controller.

* [thread] fix invalid configuration of active dataset (project-chip#4008)

* Fix data loss or crash in TCPEndPoint with LwIP (project-chip#4022)

* Fix data loss or crash in TCPEndPoint with LwIP

#### Problem

Under the configuration CHIP_SYSTEM_CONFIG_USE_LWIP, in some cases where
the data size exceeds the TCP window size, TCPEndPoint can either die or
lose data when accounting of un-acked data falls out of sync.

#### Summary of Changes

Imported fix from Weave:

* This change removes separate accounting of the unsent
  data position and replaces it with simple counting of
  sent-but-not-acked data and a skip-loop at the start
  of DriveSending().

Fixes project-chip#4013 - Data loss or crash in TCPEndPoint with LwIP

* Restyled by clang-format

Co-authored-by: Restyled.io <[email protected]>

* Update lighting-app gen/ folder with ZAP generated content (project-chip#4010)

* Fix segmentation fault error in response echo message (project-chip#3984)

* Add back Android default build coverage & fix the build (project-chip#3966)

mDNS doesn't build with no device layer. Remove it from the build and
add back the coverage that would catch this that was lost in project-chip#3340.

* Update all-clusters-app gen/ folder with ZAP generated content (project-chip#3963)

* Move src/inet/tests to auto-test-driver generation (project-chip#3997)

* Rename TestUtils to UnitTestRegistration. (project-chip#4021)

Looking to remove usage of 'Utils' unless we have really no choice.
'UnitTestRegistration' seems clearer in what it does compared to
'TestUtils'.

* Update src/lib/core/tests to auto-test-driver generation (project-chip#3991)

* Cleanup zap chip-helper.js (project-chip#3973)

* Cleanup zap chip-helper.js

* Restyled by clang-format

Co-authored-by: Restyled.io <[email protected]>

* Move src/transport/tests to auto-test-driver generation (project-chip#3999)

* Move src/transport/tests to auto-test-driver generation

* Add relevant libraries (and more test-capable libs) to nrf.

* Refactor inet test helpers (to not include actual inet tests), try to make qemu allow better linkage but still failed for transport tests so disabled for now

* Added more tests on esp32 qemu

* Restyle fixes

* Fix cast errors in InetCommon

* Disable raw tests from zephyr: somehow they fail running out of endpoints

* Disable DNS test on zephyr

* Remove inet endpoint test from zephyr

* Remove inet endpoint test from zephyr - fix again

* Modify gitignore

* Restyle fixes

* Use CHIPDeviceController instead of CHIPDeviceController_deprecated (project-chip#3979)

* Implement the missing part of Exchange Header in Transport layer (project-chip#4017)

* Implement the missing part of Exchange Header in Transport layer

* Revert comment 'if' back to 'iff'("if and only if")

* Remove duplicated send flag defines and put ExchangeMgr/ExchangeConte… (project-chip#3994)

* Remove duplicated send flag defines and put ExchangeMgr/ExchangeContext under the same namespace as CRMP

* Rename kSendFlag_Default to kSendFlag_None

* Move src/lib/asn1/tests and src/ble/tests to auto-test-driver generation (project-chip#3998)

* Move src/lib/asn1/tests and src/ble/tests to auto-test-driver generation

* Remove one more unused file

* Attempt to enable asn1 and ble tests in esp32 - see if they pass or not

* Fix merge error

* Update include header for ASN1 test

* Include  ASN1 in libCHIP

* Some conversions to use PacketBufferHandle (project-chip#4011)

* Some conversions to use PacketBufferHandle

#### Problem

Code should use `PacketBufferHandle` rather than `PacketBuffer *`.

#### Summary of Changes

- Converts remaining receive path in //src/inet and //src/transport.
- Converts most of //src/ble.
- Introduces Handle versions of the `AddToEnd`/`DetachTail` pair.

Part of issue project-chip#2707 - Figure out a way to express PacketBuffer ownership in the type system

* Restyled by clang-format

* review

* revive BtpEngine::Clear[TR]xPacket()
* simplify conditional
* (void) message.DetachTail() → message.FreeHead()
* remove ExchangeContext::kSendFlag_RetainBuffer
* missed pBuf.IsNull()
* DetachHead() → PopTail()
* typos

Co-authored-by: Restyled.io <[email protected]>

* Move src/system/tests to auto-test-driver generation (project-chip#4000)

* Move src/system/tests to auto-test-driver generation

* Remove a TCP/IP init call that was killing qemu

* Remove explicit "all" target from root build file (project-chip#3967)

The "all" target exists implicitly and contains everything. We don't
need to specify one, and it's misleading to do so specifying deps has no
effect.

* Make src/setup_payload compile with -Werror=conversion (project-chip#4032)

* Add SSID and password to chip-tool pairing (project-chip#4054)

* Get temperature-measurement and all-clusters-app to use examples/common/chip-app-server (project-chip#4039)

#### Problem

PR project-chip#3704 introduced a change where a `PeerAddress` is now required in order to start `RendezvousSession`.
Sadly the multiple code paths bootstrapping `RendezvousSession` has not been updated.

PR project-chip#4012 add a fix for some of the `examples/` but not for the `all-clusters-app` nor the `temperature-measurement-app`.

To avoid such situation, this PR merge `examples/common/chip-app-server` and the custom code from `all-clusters-app` and `temperature-measurement-app`.

One of the more discutable change of this PR (imo) is the code that moves the custom `Echo` mechanism from the `all-clusters-app` to `chip-app-server`. I was hoping to get rid of it before doing this change but the `all-clusters-app` and the `temperature-measurement-app` are broken since project-chip#3704 and this PR should fix that.
Also I have a PR (mostly) ready once project-chip#3979 lands to get rid of this `Echo` specific code and replace it by a manufacturer specific `ping` command.

 #### Summary of Changes
 * Remove `EchoServer.cpp`, `RendezvousDeviceDelegate.cpp` and `include/RendezvousDeviceDelegate.h` from `all-clusters-app`
 * Remove `ResponseServer.cpp`, `RendezvousDeviceDelegate.cpp` and `include/RendezvousDeviceDelegate.h` from `temperature-measurement-app`
 * Introduce `chip-app-server/include/AppDelegate.h` in order to keep the behavior the `all-clusters-app` that turns on/off leds on different events. Maybe it should be converted to some types of `ChipDeviceEvent` or `CHIPCallback` at some point.
 * Fix `chip-app-server` to accomodate for the specifics of `all-clusters-app`

* Add all Thread ULA addresses to the lwip interface (project-chip#4053)

ULA prefixes will used for CHIP network so we need to add all these
addresses to the interface.

* Remove src/lib/message. (project-chip#4055)

* Remove src/lib/message.

Updated messaging implementation lives in src/messaging and the
src/lib/message is not currently compiled or linked in.

This saves us from looking at this code when some refactoring is needed
(e.g. the SystemPacketBuffer changes).

* Remove one more unused file

* [ChipTool] Add Payload Parse Command (project-chip#3696)

* [ChipTool] Add Payload Parse Command

* [ChipTool] Add Payload Parse Command

* [ChipTool] Restyle issues resolved

* Restyled by whitespace

* Resolve build errors caused by Command.h schema change

Co-authored-by: lijayaku <[email protected]>
Co-authored-by: Restyled.io <[email protected]>

* rename ParseCommand to QRCodeParseCommand

* adding AdditionalDataParseCommand version 0

* Adding parsing logic + logging

* adding another parsing method

* Basic Parsing is DONE

* fixing memory issue

* removing some logs

* removing more logs

* minor update

* Add RotatingDeviceId to DNS-SD

* Revert "Merge pull request #4 from hnnajh/rotating-id-test"

This reverts commit 0235d05, reversing
changes made to 3e1a4b9.

* increment lifetime counter

* Incrementing lifetime counter at each BLE/MDNS advertisement

* address comments

* Update src/include/platform/ConfigurationManager.h

Co-authored-by: Boris Zbarsky <[email protected]>

* removing unnecessary lines

* nit

* Update src/app/server/Dnssd.cpp

Co-authored-by: chrisdecenzo <[email protected]>

* restyling

* Update src/app/server/Dnssd.cpp

Co-authored-by: chrisdecenzo <[email protected]>

* Update src/app/server/Dnssd.cpp

Co-authored-by: chrisdecenzo <[email protected]>

* fix comments

* incrementing lifetimecounter once

* remove unnecessary include

Co-authored-by: Kevin Schoedel <[email protected]>
Co-authored-by: Vivien Nicolas <[email protected]>
Co-authored-by: Markus Becker <[email protected]>
Co-authored-by: Damian Królik <[email protected]>
Co-authored-by: Łukasz Duda <[email protected]>
Co-authored-by: Restyled.io <[email protected]>
Co-authored-by: Yufeng Wang <[email protected]>
Co-authored-by: Michael Spang <[email protected]>
Co-authored-by: Andrei Litvin <[email protected]>
Co-authored-by: jepenven-silabs <[email protected]>
Co-authored-by: Boris Zbarsky <[email protected]>
Co-authored-by: Jiacheng Guo <[email protected]>
Co-authored-by: Liju Jayakumar <[email protected]>
Co-authored-by: lijayaku <[email protected]>
Co-authored-by: chrisdecenzo <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature work p1 priority 1 work
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants