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

Add mac address as connection for matter device #121257

Conversation

MrEbbinghaus
Copy link
Contributor

Proposed change

This PR adds a mac address connection for matter devices that have a mac address, so that they can be matched with existing devices in the registry.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.
  • Untested files have been added to .coveragerc.

To help with the load of incoming pull requests:

@MrEbbinghaus MrEbbinghaus requested a review from a team as a code owner July 4, 2024 21:52
Copy link

@home-assistant home-assistant bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @MrEbbinghaus

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!

@home-assistant home-assistant bot marked this pull request as draft July 4, 2024 21:53
@home-assistant
Copy link

home-assistant bot commented Jul 4, 2024

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

@home-assistant
Copy link

home-assistant bot commented Jul 4, 2024

Hey there @home-assistant/matter, mind taking a look at this pull request as it has been labeled with an integration (matter) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of matter can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign matter Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the pull request.

@MrEbbinghaus MrEbbinghaus marked this pull request as ready for review July 4, 2024 22:00
@MrEbbinghaus MrEbbinghaus force-pushed the feature/add-connection-to-matternode branch from 38efa9c to 11a296d Compare July 4, 2024 22:09
@frenck frenck marked this pull request as draft July 6, 2024 11:43
@frenck
Copy link
Member

frenck commented Jul 6, 2024

I've marked this PR, as changes are requested that need to be processed.
Please un-draft it once it is ready for review again by clicking the "Ready for review" button.

Thanks! 👍

../Frenck

Learn more about our pull request process.

@MrEbbinghaus MrEbbinghaus force-pushed the feature/add-connection-to-matternode branch from 11a296d to e3f84fd Compare July 7, 2024 23:21
Copy link
Member

@marcelveldt marcelveldt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work!

@marcelveldt marcelveldt marked this pull request as ready for review July 10, 2024 09:41
@marcelveldt marcelveldt merged commit 2723ab3 into home-assistant:dev Jul 15, 2024
26 checks passed
@agners
Copy link
Member

agners commented Jul 16, 2024

So this PR seems to cause a bit of headache here. I see devices with many MAC addresses, and things merging weirdly on dev

image

@MrEbbinghaus
Copy link
Contributor Author

MrEbbinghaus commented Jul 16, 2024

@agners Oh no, that doesn't look right.
Can you send the matter diagnostics?

I suspect the devices all share the invalid 00:00:00:00:00:00 address.
I knew this could happen (see #121257 (comment)), but this is a HA core level issue, so I removed the check for invalid mac addresses.

@agners
Copy link
Member

agners commented Jul 16, 2024

I suspect the devices all share the invalid 00:00:00:00:00:00 address.

Yeah I have at least two devices which return 00:00:00:00:00:00.

I guess technically, this is a valid MAC address. But these devices don't use this as physical address (according to my AP). Technically, the Matter standard says NetworkInterface hardwareAddress field is mandatory and should contain "a" MAC address. I guess very strictly speaking, this is "a" MAC address, just not the valid/used one for that device 🙈

Anyhow, given that Matter devices return such addresses, this is more a Matter problem. I'd suggest to filter them out on Matter integration side.

@agners
Copy link
Member

agners commented Jul 16, 2024

Btw, what is the exact use case/motivation behind this PR? Do you have a device where this connects up with other integrations or something?

I am a bit worried since MAC address privacy extensions become more and more commonplace. The Matter standard also mentions that when it comes to host name generation. It seems we have to expect that devices rotate MAC addresses:

For DNS‐SD a target host name is required, in addition to the instance name. The target host name
SHALL be constructed using one of the available link-layer addresses, such as a 48-bit device MAC
address (for Ethernet and Wi‐Fi) or a 64-bit MAC Extended Address (for Thread) expressed as a
fixed-length twelve-character (or sixteen-character) hexadecimal string, encoded as ASCII (UTF-8)
text using capital letters, e.g., B75AFB458ECD.. In the event that a device performs MAC
address randomization for privacy
, then the target host name SHALL use the privacy-preserving
randomized version and the hostname SHALL be updated in the record every time the underlying
link-layer address rotates
. Note that it is legal to reuse the same hostname on more than one inter­
face, even if the underlying link-layer address does not match the hostname on that interface, since
the goal of using a link-layer address is to ensure local uniqueness of the generated hostname. If
future link layers are supported by Matter that do not use 48-bit MAC addresses or 64-bit MAC
Extended Address identifiers, then a similar rule will be defined for those technologies.

@MrEbbinghaus
Copy link
Contributor Author

Unfortunately, I can't work on this today.
@marcelveldt Should this PR be reverted and put on hold until there is a patch for the core code to validate mac addresses?
Or should I add the checks for now, and maybe it gets fixed later in the core?


@agners 00:00:00:xx:xx:xx (and a bunch of other addresses) are not valid identifiers.
'Values based on a zero-valued OUI [...] shall not be used as identifiers.'
See: https://standards.ieee.org/wp-content/uploads/import/documents/tutorials/eui.pdf


I still have the checks that I removed here:

https://github.com/MrEbbinghaus/core/blob/e3f84fd007d08b060b4a5c478427df94fa82dcb5/homeassistant/components/matter/adapter.py#L50-L67

    def is_NULL(self) -> bool:
        """Check if the address is NULL value/should not be used.

        See: https://standards.ieee.org/wp-content/uploads/import/documents/tutorials/eui.pdf
        'Values based on a zero-valued OUI [...] shall not be used as identifiers.'
        """
        return self.address[:3] == b"\x00\x00\x00"

    def is_individual(self) -> bool:
        """Check if the address is an individual address, not a group address."""
        return self.address[0] & 0x01 == 0

    def _valid_connection(self) -> bool:
        return self.is_individual() and not self.is_NULL()

@agners
Copy link
Member

agners commented Jul 16, 2024

@agners 00:00:00:xx:xx:xx (and a bunch of other addresses) are not valid identifiers.
'Values based on a zero-valued OUI [...] shall not be used as identifiers.'
See: https://standards.ieee.org/wp-content/uploads/import/documents/tutorials/eui.pdf

Oh I see. I just looked up OUI, and with 00:00:00 Xerox came up, so assumed it is valid.

@MrEbbinghaus
Copy link
Contributor Author

MrEbbinghaus commented Jul 16, 2024

Btw, what is the exact use case/motivation behind this PR? Do you have a device where this connects up with other integrations or something?

@agners I have a matter device that wants to connect to the manufacturer to make auto-updates, which I don't want.

My router integration adds a switch for every connected device to block its internet access.

And it annoys me that I regularly have duplicate devices in my list.

@MrEbbinghaus
Copy link
Contributor Author

MrEbbinghaus commented Jul 16, 2024

@agners You are right to point out that there will be more devices with address rotation in the future, which could be an issue for mac addresses to be used as unique device identifiers. However, this should not cause any severe problems in HA.
In the worst case, two integrations would have two different Mac addresses for the same device and the devices can't be merged automatically. But this is the status quo, so no UX degradation.
It is unlikely that 'randomly' generated Mac addresses for privacy will collide, and it would not only be a problem for HA alone but possibly for the entire network.

Also, as I understand it, the addresses are only stored until the integration that provides the entity reloads. So even when the addresses rotate, it wouldn't spam the device registry with addresses.

(Also, I guess that most Matter devices won't move from network to network regularly, and therefore manufacturers won't bother with implementing privacy enhancing rotating addresses.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants