-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Reading 8- or 16-bit attributes from big-endian device returns 0 #6166
Comments
pjzander-signify
added a commit
to pjzander-signify/connectedhomeip
that referenced
this issue
Apr 20, 2021
pjzander-signify
added a commit
to pjzander-signify/connectedhomeip
that referenced
this issue
Apr 20, 2021
pjzander-signify
added a commit
to pjzander-signify/connectedhomeip
that referenced
this issue
May 7, 2021
pjzander-signify
added a commit
to pjzander-signify/connectedhomeip
that referenced
this issue
May 10, 2021
I will create a new pull request |
pjzander-signify
added a commit
to pjzander-signify/connectedhomeip
that referenced
this issue
May 11, 2021
pjzander-signify
added a commit
to pjzander-signify/connectedhomeip
that referenced
this issue
May 11, 2021
pjzander-signify
added a commit
to pjzander-signify/connectedhomeip
that referenced
this issue
May 11, 2021
andy31415
pushed a commit
that referenced
this issue
May 13, 2021
…) (#6685) Co-authored-by: Justin Wood <woody@apple.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Problem
When reading an 8- or 16-bit attribute from a big endian device the value is 0, despite that defaults other than 0 are defined.
The defaults of these attributes are defined in a zap-file and from that a header file is generated (endpoint_config.h).
This header file contains structures that are used by the software to read cluster information and the attributes of these clusters.
The value of these attributes are stored in a union that also contains 2 pointers:
typedef union { uint8_t * ptrToDefaultValue; uint16_t defaultValue; EmberAfAttributeMinMaxValue * ptrToMinMaxValue; } EmberAfDefaultOrMinMaxAttributeValue;
A generated default value is compiled into that union using an explicit type cast to a pointer.
Example:
{ (uint8_t *) 3 } }
In a 32-bit little-endian the memory layout will be:
03 00 00 00
The 16-bit defaultValue (the first 2 bytes) will have the value 3, which is correct.
In a 32-bit big-endian system the layout will be:
00 00 00 03
The 16-bit defaultValue (the first 2 bytes) will have the value 0, which is not correct.
Proposed Solution
Use a structure for the defaultValue, and that structure has the same size as a pointer.
Then use alignment bits to always align the 16-bit defaultValue with the least-significant-bits of the pointer.
The text was updated successfully, but these errors were encountered: