diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 5f999e2949b82c..b2b2db02411f12 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -18,7 +18,8 @@ RUN apt-get -fy install git vim emacs sudo \ iproute2 procps lsb-release \ bash-completion \ build-essential cmake cppcheck valgrind \ - wget curl telnet bsdtar + wget curl telnet bsdtar \ + docker.io RUN groupadd --gid $USER_GID $USERNAME RUN useradd -s /bin/bash --uid $USER_UID --gid $USER_GID -m $USERNAME RUN echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME @@ -31,4 +32,9 @@ RUN cd /var/downloads RUN curl -JL https://github.com/microsoft/vscode-cpptools/releases/download/0.27.0/cpptools-linux.vsix | bsdtar -xvf - extension RUN mkdir -p /home/vscode/.vscode-server/extensions RUN mv extension /home/vscode/.vscode-server/extensions/ms-vscode.cpptools-0.27.0 +RUN mkdir -p /home/vscode/bin +RUN curl https://raw.githubusercontent.com/restyled-io/restyler/master/bin/restyle-path -o /home/vscode/bin/restyle-path +RUN chmod +x /home/vscode/bin/restyle-path RUN chown -R vscode:vscode /home/vscode + + diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index fd98bad31a4138..a89e4c306a050e 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,5 +1,6 @@ { "name": "CHIP Ubuntu Development Environment", + "runArgs": ["--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined"], "build": { "dockerfile": "Dockerfile", "args": { @@ -7,11 +8,6 @@ "BUILD_VERSION": "0.2.7" } }, - "runArgs": [ - "--cap-add=SYS_PTRACE", - "--security-opt", - "seccomp=unconfined" - ], "remoteUser": "vscode", // Add the IDs of extensions you want installed when the container is created in the array below. "extensions": [ @@ -23,9 +19,11 @@ "eamodio.gitlens", "yuichinukiyama.vscode-preview-server", "aaron-bond.better-comments", - "foxundermoon.shell-format" + "foxundermoon.shell-format", + "editorconfig.editorconfig", + "esbenp.prettier-vscode" ], - // Use 'settings' to set *default* container specific settings.json values on container create. + // Use 'settings' to set *default* container specific settings.json values on container create. // You can edit these settings after create using File > Preferences > Settings > Remote. "settings": { "terminal.integrated.shell.linux": "/bin/bash" diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000000000..d4b519989dca63 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,3 @@ +trim_trailing_whitespace = true +insert_final_newline = false +indent_style = space diff --git a/.prettierrc.json b/.prettierrc.json new file mode 100644 index 00000000000000..a7d683b1c25176 --- /dev/null +++ b/.prettierrc.json @@ -0,0 +1,12 @@ +{ + "$schema": "http://json.schemastore.org/prettierrc", + "printWidth": 80, + "tabWidth": 4, + "useTabs": false, + "semi": true, + "trailingComma": "all", + "bracketSpacing": true, + "jsxBracketSameLine": false, + "arrowParens": "avoid", + "proseWrap": "always" +} diff --git a/.restyled.yaml b/.restyled.yaml index dd9c3eaa9aa0fe..54af825a78fed8 100644 --- a/.restyled.yaml +++ b/.restyled.yaml @@ -27,6 +27,14 @@ exclude: - "third_party/**/*" - "third_party/**" - "third_party/*" + - "third_party" + - "**/third_party/**/*" + - "**/third_party/*" + - "**/third_party/**" + - "**/third_party/**/*" + - "examples/lock-app/efr32/third_party/**/*" + - "examples/lock-app/efr32/third_party/*" + - "examples/lock-app/efr32/third_party/**" - "build/**/*" - "autom4te.cache/**/*" @@ -57,26 +65,40 @@ restylers: - "**/*.js" - "**/*.m" interpreters: [] - - name: jq + - name: prettier-json + image: restyled/restyler-prettier:v1.19.1-2 enabled: true + command: + - prettier + - "--write" + arguments: [] include: - "**/*.json" + interpreters: [] - name: prettier-markdown + image: restyled/restyler-prettier:v1.19.1-2 + command: + - prettier + - "--write" + arguments: [] enabled: true include: - "**/*.md" - "**/*.markdown" - name: prettier-yaml + image: restyled/restyler-prettier:v1.19.1-2 enabled: true include: - "**/*.yml" - "**/*.yaml" - name: shellharden + image: restyled/restyler-shellharden:v4.1.1-2 enabled: true include: - "**/*.sh" - "**/*.bash" - name: shfmt + image: restyled/restyler-shfmt:v3.0.1 enabled: true include: - "**/*.sh" diff --git a/.travis.yml b/.travis.yml index c45ea778711a5b..71968386597010 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,9 @@ language: minimal +branches: + except: + - /^restyled.*$/ + services: - docker diff --git a/.vscode/launch.json b/.vscode/launch.json index d45bab1d8f47f4..7aab2993d2165b 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -4,8 +4,6 @@ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ - - { "name": "QRCode Tests", "type": "cppdbg", @@ -26,7 +24,6 @@ } ] }, - { "name": "CHIP crypto Tests", "type": "cppdbg", diff --git a/.vscode/settings.json b/.vscode/settings.json index 07eb9c7aa803ef..d1820983dedf03 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -22,6 +22,18 @@ "[dockerfile]": { "editor.defaultFormatter": "ms-azuretools.vscode-docker" }, + "[jsonc]": { + "editor.defaultFormatter": "esbenp.prettier-vscode" + }, + "[shellscript]": { + "editor.defaultFormatter": "foxundermoon.shell-format" + }, + "[properties]": { + "editor.defaultFormatter": "foxundermoon.shell-format" + }, + "[markdown]": { + "editor.defaultFormatter": "esbenp.prettier-vscode" + }, "files.associations": { "iostream": "cpp", "array": "cpp", @@ -66,7 +78,8 @@ "cinttypes": "cpp", "typeinfo": "cpp", "*.ipp": "cpp", - "aes.h": "c" + "aes.h": "c", + "stdio.h": "c" }, "files.eol": "\n", "editor.formatOnSave": true, @@ -108,5 +121,6 @@ "backgroundColor": "transparent" } ], - "clang-format.fallbackStyle": "WebKit" + "clang-format.fallbackStyle": "WebKit", + "files.trimFinalNewlines": true } diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 8cf31ffa1ec255..ba6428242ec3bf 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -15,9 +15,7 @@ "reveal": "always", "panel": "shared" }, - "problemMatcher": [ - "$gcc" - ] + "problemMatcher": ["$gcc"] }, { "label": "Auto-enforce coding style", @@ -30,9 +28,7 @@ "reveal": "always", "panel": "shared" }, - "problemMatcher": [ - "$gcc" - ] + "problemMatcher": ["$gcc"] }, { "label": "Verify coding style conformance", @@ -40,9 +36,7 @@ "command": "make -C build/default pretty-check", "group": "none", "dependsOn": "Bootstrap", - "problemMatcher": [ - "$gcc" - ] + "problemMatcher": ["$gcc"] }, { "label": "Run Unit and Functional Tests", @@ -50,9 +44,7 @@ "command": "make -C build/default check", "group": "none", "dependsOn": "Bootstrap", - "problemMatcher": [ - "$gcc" - ] + "problemMatcher": ["$gcc"] }, { "label": "Run Distribution Generation", @@ -60,9 +52,7 @@ "command": "make -C build/default distcheck", "group": "none", "dependsOn": "Bootstrap", - "problemMatcher": [ - "$gcc" - ] + "problemMatcher": ["$gcc"] }, { "label": "Run Code Coverage", @@ -70,9 +60,7 @@ "command": "make -C build/default coverage; code -r build/default/src/chip.info/index.html", "group": "none", "dependsOn": "Bootstrap", - "problemMatcher": [ - "$gcc" - ] + "problemMatcher": ["$gcc"] }, { "label": "Clean", @@ -80,36 +68,28 @@ "command": "make -C build/default distclean", "group": "none", "dependsOn": "Bootstrap", - "problemMatcher": [ - "$gcc" - ] + "problemMatcher": ["$gcc"] }, { "label": "Configure", "type": "shell", "command": "mkdir -p build/default && (cd build/default && ../../bootstrap-configure --enable-debug --enable-coverage)", "group": "none", - "problemMatcher": [ - "$gcc" - ] + "problemMatcher": ["$gcc"] }, { "label": "Bootstrap", "type": "shell", "command": "if [[ ! -f build/default/config.status ]]; then mkdir -p build/default; (cd build/default && ../../bootstrap-configure --enable-debug --enable-coverage); else ./bootstrap -w make; fi", "group": "none", - "problemMatcher": [ - "$gcc" - ], + "problemMatcher": ["$gcc"] }, { "label": "Clean Tree", "type": "shell", "command": "make -f Makefile-bootstrap clean-repos && git clean -Xdf", "group": "none", - "problemMatcher": [ - "$gcc" - ] + "problemMatcher": ["$gcc"] }, { "label": "Run Setup Payload Tests", @@ -117,18 +97,14 @@ "command": "make -C build/default/src/setup_payload check", "group": "none", "dependsOn": "Bootstrap", - "problemMatcher": [ - "$gcc" - ] + "problemMatcher": ["$gcc"] }, { "label": "Build & Run Crypto Tests", "type": "shell", "command": "make -C build/default/src/crypto check", "group": "none", - "problemMatcher": [ - "$gcc" - ] + "problemMatcher": ["$gcc"] }, { "label": "Build nRF5 Lock App", @@ -136,9 +112,7 @@ "command": "make -C examples/lock-app/nrf5", "group": "none", "dependsOn": "Clean Tree", - "problemMatcher": [ - "$gcc" - ] - }, - ], + "problemMatcher": ["$gcc"] + } + ] } diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index 03d22e97b6af3e..371df3b0e1ee60 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -1,86 +1,81 @@ # Project CHIP Open Source Code of Conduct -This Project CHIP Open Source – Code of Conduct applies to all those -contributing to, participating in, or maintaining the Project CHIP -open source project, including Zigbee Alliance members and -non-members. +This Project CHIP Open Source Code of Conduct applies to all those contributing +to, participating in, or maintaining the Project CHIP open source project, +including Zigbee Alliance members and non-members. ## Our Pledge In the interest of fostering an open and welcoming environment, we as -contributors and maintainers pledge to make participation in our -project and our community a harassment-free experience for everyone, -regardless of age, body size, disability, ethnicity, sex -characteristics, gender identity and expression, level of experience, -education, socio-economic status, nationality, personal appearance, -race, religion, or sexual identity and orientation. +contributors and maintainers pledge to make participation in our project and our +community a harassment-free experience for everyone, regardless of age, body +size, disability, ethnicity, sex characteristics, gender identity and +expression, level of experience, education, socio-economic status, nationality, +personal appearance, race, religion, or sexual identity and orientation. ## Our Standards -Examples of behavior that contributes to creating a positive -environment include: +Examples of behavior that contributes to creating a positive environment +include: -* Using welcoming and inclusive language -* Being respectful of differing viewpoints and experiences -* Gracefully accepting constructive criticism -* Focusing on what is best for the community -* Showing empathy towards other community members +- Using welcoming and inclusive language +- Being respectful of differing viewpoints and experiences +- Gracefully accepting constructive criticism +- Focusing on what is best for the community +- Showing empathy towards other community members Examples of unacceptable behavior by participants include: -* The use of violent threats, abusive, discriminatory, or derogatory language -* The use of sexualized language or imagery and unwelcome sexual - attention or advances -* Trolling, insulting/derogatory comments, and personal or political attacks -* Public or private harassment -* Publishing others' private information, such as a physical or - electronic address, without explicit permission -* Posting of violent content -* Engaging in unwanted physical contact -* Other conduct which could reasonably be considered inappropriate in - a professional setting -* Advocating for or encouraging any of the above behaviors +- The use of violent threats, abusive, discriminatory, or derogatory language +- The use of sexualized language or imagery and unwelcome sexual attention or + advances +- Trolling, insulting/derogatory comments, and personal or political attacks +- Public or private harassment +- Publishing others' private information, such as a physical or electronic + address, without explicit permission +- Posting of violent content +- Engaging in unwanted physical contact +- Other conduct which could reasonably be considered inappropriate in a + professional setting +- Advocating for or encouraging any of the above behaviors ## Our Responsibilities -Project maintainers are expected to take appropriate and fair -corrective action in response to any instances of unacceptable -behavior. Project maintainers have the right and responsibility to -remove, edit, or reject comments, commits, code, wiki edits, issues, -and other contributions that are not aligned to this Code of Conduct, -or to ban temporarily or permanently any contributor for other -behaviors that they deem inappropriate, threatening, offensive, or -harmful. +Project maintainers are expected to take appropriate and fair corrective action +in response to any instances of unacceptable behavior. Project maintainers have +the right and responsibility to remove, edit, or reject comments, commits, code, +wiki edits, issues, and other contributions that are not aligned to this Code of +Conduct, or to ban temporarily or permanently any contributor for other +behaviors that they deem inappropriate, threatening, offensive, or harmful. ## Scope -This Code of Conduct applies within all project spaces, and it also -applies when an individual is representing the project or its -community in public spaces. Examples of representing a project or -community include using an official project e-mail address, posting -via an official social media account, or acting as an appointed -representative at an online or offline event. Representation of a -project may be further defined and clarified by project maintainers. +This Code of Conduct applies within all project spaces, and it also applies when +an individual is representing the project or its community in public spaces. +Examples of representing a project or community include using an official +project e-mail address, posting via an official social media account, or acting +as an appointed representative at an online or offline event. Representation of +a project may be further defined and clarified by project maintainers. ## Enforcement -Instances of abusive, harassing, or otherwise unacceptable behavior -may be reported by contacting the Project CHIP open source team at -[INSERT EMAIL ADDRESS]. All complaints will be reviewed and -investigated and will result in a response that is deemed necessary -and appropriate to the circumstances. The Project CHIP open source -team should maintain confidentiality with regard to the reporter of an -incident. Further details of specific enforcement policies may be +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported by contacting the Project CHIP open source team at [INSERT EMAIL +ADDRESS]. All complaints will be reviewed and investigated and will result in a +response that is deemed necessary and appropriate to the circumstances. The +Project CHIP open source team should maintain confidentiality with regard to the +reporter of an incident. Further details of specific enforcement policies may be posted separately. -Project maintainers who do not follow or enforce the Code of Conduct -in good faith may face temporary or permanent repercussions as -determined by Project CHIP open source leadership. +Project maintainers who do not follow or enforce the Code of Conduct in good +faith may face temporary or permanent repercussions as determined by Project +CHIP open source leadership. ## Attribution -This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, -available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html +This Code of Conduct is adapted from the [Contributor Covenant][homepage], +version 1.4, available at +https://www.contributor-covenant.org/version/1/4/code-of-conduct.html [homepage]: https://www.contributor-covenant.org diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ec25662498e577..f7f70b247a40c4 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,52 +1,64 @@ -Contributing to CHIP -======================== +# Contributing to CHIP -Want to contribute? Great! First, read this page (including the small -print at the end). -By submitting a pull request, you represent that you have the right to license your contribution to Zigbee and the -community, and agree by submitting the patch that your contributions are licensed under the +Want to contribute? Great! First, read this page (including the small print at +the end). By submitting a pull request, you represent that you have the right to +license your contribution to Zigbee and the community, and agree by submitting +the patch that your contributions are licensed under the [Apache 2.0 license](./LICENSE). -Before submitting the pull request, please make sure you have tested your changes and that they follow the project +Before submitting the pull request, please make sure you have tested your +changes and that they follow the project [guidelines for contributing code](#pull-request-requirements). ## Becoming a Member -Currently these are the requirements to becoming a member of the [Project-CHIP Repository](https://github.com/project-chip/connectedhomeip) -* Must be a member of the Zigbee Alliance CHIP TSG Working Group -* Have signed the Zigbee CHIP WG CLA -* Have signed up as a Tiger team member in one of the follow roles: Lead, Spec Writer, Developer (or exception granted), Code Approvers, or Support Staff -* Have approval from your company's official approver +Currently these are the requirements to becoming a member of the +[Project-CHIP Repository](https://github.com/project-chip/connectedhomeip) + +- Must be a member of the Zigbee Alliance CHIP TSG Working Group +- Have signed the Zigbee CHIP WG CLA +- Have signed up as a Tiger team member in one of the follow roles: Lead, Spec + Writer, Developer (or exception granted), Code Approvers, or Support Staff +- Have approval from your company's official approver ## Becoming a Contributor -Currently these are the requirements to becoming a member of the [Project-CHIP Repository](https://github.com/project-chip/connectedhomeip) -* Must be a member of the Zigbee Alliance CHIP TSG Working Group -* Have signed the Zigbee CHIP WG CLA -* Agree to the [Code of Conduct](./CODE_OF_CONDUCT.md) -* Agree to the [License](./LICENSE) -* Have signed up as a Tiger team member in one of the follow roles: Lead, Spec Writer, Developer (or exception granted), Code Approvers, or Support Staff -* Have approval from your company's official approver +Currently these are the requirements to becoming a member of the +[Project-CHIP Repository](https://github.com/project-chip/connectedhomeip) + +- Must be a member of the Zigbee Alliance CHIP TSG Working Group +- Have signed the Zigbee CHIP WG CLA +- Agree to the [Code of Conduct](./CODE_OF_CONDUCT.md) +- Agree to the [License](./LICENSE) +- Have signed up as a Tiger team member in one of the follow roles: Lead, Spec + Writer, Developer (or exception granted), Code Approvers, or Support Staff +- Have approval from your company's official approver ## Bugs -If you find a bug in the source code, you can help us by [submitting a GitHub Issue](https://github.com/project-chip/connectedhomeip/issues/new). The best bug reports provide a detailed description of the issue and step-by-step instructions for predictably reproducing the issue. Even better, you can [submit a Pull Request](#submitting-a-pull-request) with a fix. +If you find a bug in the source code, you can help us by +[submitting a GitHub Issue](https://github.com/project-chip/connectedhomeip/issues/new). +The best bug reports provide a detailed description of the issue and +step-by-step instructions for predictably reproducing the issue. Even better, +you can [submit a Pull Request](#submitting-a-pull-request) with a fix. ## New Features -You can request a new feature by [submitting a GitHub Issue](https://github.com/project-chip/connectedhomeip/issues/new). +You can request a new feature by +[submitting a GitHub Issue](https://github.com/project-chip/connectedhomeip/issues/new). -If you would like to implement a new feature, please consider the scope of the new feature: +If you would like to implement a new feature, please consider the scope of the +new feature: -* *Large feature*: first [submit a GitHub - Issue](https://github.com/project-chip/connectedhomeip/issues/new) and communicate - your proposal so that the community can review and provide feedback. Getting - early feedback will help ensure your implementation work is accepted by the - community. This will also allow us to better coordinate our efforts and - minimize duplicated effort. +- _Large feature_: first + [submit a GitHub Issue](https://github.com/project-chip/connectedhomeip/issues/new) + and communicate your proposal so that the community can review and provide + feedback. Getting early feedback will help ensure your implementation work + is accepted by the community. This will also allow us to better coordinate + our efforts and minimize duplicated effort. -* *Small feature*: can be implemented and directly [submitted as a Pull - Request](#submitting-a-pull-request). +- _Small feature_: can be implemented and directly + [submitted as a Pull Request](#submitting-a-pull-request). ## Contributing Code @@ -56,9 +68,8 @@ CHIP follows the "Fork-and-Pull" model for accepting contributions. Setup your GitHub fork and continuous-integration services: -1. Fork the [CHIP - repository](https://github.com/project-chip/connectedhomeip) by clicking "Fork" - on the web UI. +1. Fork the [CHIP repository](https://github.com/project-chip/connectedhomeip) + by clicking "Fork" on the web UI. 2. All contributions must pass all checks and reviews to be accepted. @@ -130,7 +141,6 @@ git rebase -i master This will open up a text editor where you can specify which commits to squash. - #### Push and Test ```bash @@ -141,73 +151,78 @@ git checkout git push origin ``` -This will trigger the continuous-integration checks. You -can view the results in the respective services. Note that the integration -checks will report failures on occasion. +This will trigger the continuous-integration checks. You can view the results in +the respective services. Note that the integration checks will report failures +on occasion. #### Pull Request Requirements CHIP considers there to be a few different types of pull requests: -- Trivial bug fix -- - Decription 1 -- - Decription 2 -- Small Bug fix -- - Decription 1 -- - Decription 2 -- Bug Fix -- - Decription 1 -- - Decription 2 -- Significiant Change -- - Decription 1 -- - Decription 2 -- Feature -- - Decription 1 -- - Decription 2 -- Architecture Change -- - Decription 1 -- - Decription 2 + +- Trivial bug fix +- - Decription 1 +- - Decription 2 +- Small Bug fix +- - Decription 1 +- - Decription 2 +- Bug Fix +- - Decription 1 +- - Decription 2 +- Significiant Change +- - Decription 1 +- - Decription 2 +- Feature +- - Decription 1 +- - Decription 2 +- Architecture Change +- - Decription 1 +- - Decription 2 ### Prior to review, all changes require: -- [GitHub Workflows](.github/workflows) pass -- [Certification Tests](tests/certification/README.md) pass -- [Fuzz Tests](tests/fuzz/README.md) pass -- [Integration Tests](tests/integration/README.md) pass -- Linting passes -- Code style passes + +- [GitHub Workflows](.github/workflows) pass +- [Certification Tests](tests/certification/README.md) pass +- [Fuzz Tests](tests/fuzz/README.md) pass +- [Integration Tests](tests/integration/README.md) pass +- Linting passes +- Code style passes ### Review Requirements + Each type of change has unique additional requirements, here's a table of those: -| Type | Reviewer Requirements | New Unit Tests | New Certification Tests | New Fuzz Tests | New Integration Tests | -|----|----|----|----|----|----| -| Trivial bug fix | 3 [approved reviewers](./REVIEWERS.md) | | | | | -| Small Bug fix | 3 [approved reviewers](./REVIEWERS.md) | | | | | -| Bug Fix | 3 [approved reviewers](./REVIEWERS.md) | | | | | -| Significiant Change | 3 [approved reviewers](./REVIEWERS.md) | | | | | -| Feature | 3 [approved reviewers](./REVIEWERS.md) | | | | | -| Architecture Change | 3 [approved reviewers](./REVIEWERS.md) | | | | | +| Type | Reviewer Requirements | New Unit Tests | New Certification Tests | New Fuzz Tests | New Integration Tests | +| ------------------- | -------------------------------------- | -------------- | ----------------------- | -------------- | --------------------- | +| Trivial bug fix | 3 [approved reviewers](./REVIEWERS.md) | | | | | +| Small Bug fix | 3 [approved reviewers](./REVIEWERS.md) | | | | | +| Bug Fix | 3 [approved reviewers](./REVIEWERS.md) | | | | | +| Significiant Change | 3 [approved reviewers](./REVIEWERS.md) | | | | | +| Feature | 3 [approved reviewers](./REVIEWERS.md) | | | | | +| Architecture Change | 3 [approved reviewers](./REVIEWERS.md) | | | | | -Note: Where multiple reviewers are required, each reviewer must be from a different member company. +Note: Where multiple reviewers are required, each reviewer must be from a +different member company. #### Submit Pull Request -Once you've validated the CI results, go to the page for -your fork on GitHub, select your development branch, and click the pull request -button. If you need to make any adjustments to your pull request, just push the -updates to GitHub. Your pull request will automatically track the changes on -your development branch and update. +Once you've validated the CI results, go to the page for your fork on GitHub, +select your development branch, and click the pull request button. If you need +to make any adjustments to your pull request, just push the updates to GitHub. +Your pull request will automatically track the changes on your development +branch and update. #### Merge Requirements -* Passes [Review Requirements](#review-requirements) -* [GitHub Workflows](.github/workflows) pass -* [Certification Tests](tests/certification/README.md) pass -* [Fuzz Tests](tests/fuzz/README.md) pass -* [Integration Tests](tests/integration/README.md) pass -* Linting passes -* Code style passes +- Passes [Review Requirements](#review-requirements) +- [GitHub Workflows](.github/workflows) pass +- [Certification Tests](tests/certification/README.md) pass +- [Fuzz Tests](tests/fuzz/README.md) pass +- [Integration Tests](tests/integration/README.md) pass +- Linting passes +- Code style passes -**When can I merge?** After these have been satisfied, any reviewer, or the originator can merge the PR into master. +**When can I merge?** After these have been satisfied, any reviewer, or the +originator can merge the PR into master. ### Documentation @@ -215,4 +230,3 @@ Documentation undergoes the same review process as code See the [Documentation Style Guide](docs/STYLE_GUIDE.md) for more information on how to author and format documentation for contribution. - diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 7bd768e9a09562..a6c30831c9ed11 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -1,3 +1,4 @@ The following organizations and individuals have contributed to the CHIP SDK: -* Apple Inc -* Google Inc + +- Apple Inc +- Google Inc diff --git a/README.md b/README.md index 1f40722e0b8a12..90f3aebbf3f202 100644 --- a/README.md +++ b/README.md @@ -7,51 +7,55 @@ All documentation is inside of the [docs section](./docs/README.md) -Instructions about how to build and develop CHIP can be found [here](./docs/README.md#building-and-developing). +Instructions about how to build and develop CHIP can be found +[here](./docs/README.md#building-and-developing). # Need help? There are numerous avenues for CHIP support: -* Bugs and feature requests [submit to the Issue Tracker](https://github.com/project-chip/connectedhomeip/issues) -* Stack Overflow [post questions using the chip tag](http://stackoverflow.com/questions/tagged/chip) + +- Bugs and feature requests + [submit to the Issue Tracker](https://github.com/project-chip/connectedhomeip/issues) +- Stack Overflow + [post questions using the chip tag](http://stackoverflow.com/questions/tagged/chip) # Directory Structure The CHIP repository is structured as follows: -| File / Folder | Contents | -|----|----| -| `.default-version` | Default CHIP version if none is available via source code control tags, `.dist-version`, or `.local-version`.| -| `bootstrap` | GNU autotools bootstrap script for the CHIP build system. | -| `bootstrap-configure` | Convenience script that will bootstrap the CHIP build system, via `bootstrap`, and invoke `configure`.| -| `build/` | Build system support content and build output directories | -| `BUILDING.md` | More detailed information on configuring and building CHIP for different targets | -| `CODE_OF_CONDUCT.md` | Code of Conduct for CHIP, and contributions to it | -| `CONTRIBUTING.md` | Guidelines for contributing to CHIP | -| `CONTRIBUTORS.md` | Contributors to CHIP | -| `docs/` | Documentation | -| `integrations/` | Third party integrations related to this project | -| `integrations/github/` | GitHub integrations related to this project | -| `integrations/github/actions` | GitHub actions related to this project | -| `integrations/docker/` | Docker scripts and Dockerfiles | -| `images/` | Images | -| `LICENSE` | CHIP License file (Apache 2.0) | -| `Makefile-Android` | Convenience makefile for building CHIP against Android.| -| `Makefile-iOS` | Convenience makefile for building CHIP against iOS.| -| `Makefile-Standalone` | Convenience makefile for building CHIP as a standalone package on desktop and server systems. | -| `README.md` | This file | -| `src/` | Implementation of CHIP| -| `tests/` | Tests for CHIP | -| `third_party/` | Third-party code used by CHIP.| -| `tools/` | Tools needed to work with the CHIP repo, as well as develop in the repository | +| File / Folder | Contents | +| ----------------------------- | ------------------------------------------------------------------------------------------------------------- | +| `.default-version` | Default CHIP version if none is available via source code control tags, `.dist-version`, or `.local-version`. | +| `bootstrap` | GNU autotools bootstrap script for the CHIP build system. | +| `bootstrap-configure` | Convenience script that will bootstrap the CHIP build system, via `bootstrap`, and invoke `configure`. | +| `build/` | Build system support content and build output directories | +| `BUILDING.md` | More detailed information on configuring and building CHIP for different targets | +| `CODE_OF_CONDUCT.md` | Code of Conduct for CHIP, and contributions to it | +| `CONTRIBUTING.md` | Guidelines for contributing to CHIP | +| `CONTRIBUTORS.md` | Contributors to CHIP | +| `docs/` | Documentation | +| `integrations/` | Third party integrations related to this project | +| `integrations/github/` | GitHub integrations related to this project | +| `integrations/github/actions` | GitHub actions related to this project | +| `integrations/docker/` | Docker scripts and Dockerfiles | +| `images/` | Images | +| `LICENSE` | CHIP License file (Apache 2.0) | +| `Makefile-Android` | Convenience makefile for building CHIP against Android. | +| `Makefile-iOS` | Convenience makefile for building CHIP against iOS. | +| `Makefile-Standalone` | Convenience makefile for building CHIP as a standalone package on desktop and server systems. | +| `README.md` | This file | +| `src/` | Implementation of CHIP | +| `tests/` | Tests for CHIP | +| `third_party/` | Third-party code used by CHIP. | +| `tools/` | Tools needed to work with the CHIP repo, as well as develop in the repository | # Contributing -We would love for you to contribute to CHIP and help make it even -better than it is today! See the [CONTRIBUTING.md](./CONTRIBUTING.md) -file for more information. - +We would love for you to contribute to CHIP and help make it even better than it +is today! See the [CONTRIBUTING.md](./CONTRIBUTING.md) file for more +information. # License -CHIP is released under the [Apache 2.0 license](./LICENSE) Please read more details therein +CHIP is released under the [Apache 2.0 license](./LICENSE) Please read more +details therein diff --git a/REVIEWERS.md b/REVIEWERS.md index 3150c4bb703a92..f0aa2ef6cffdb4 100644 --- a/REVIEWERS.md +++ b/REVIEWERS.md @@ -1,13 +1,14 @@ -The following individuals can be chosen as, and act as required reviewers on any PR +The following individuals can be chosen as, and act as required reviewers on any +PR -| Name | Company | -|----|----| -| [anush-apple](https://github.com/anush-apple) | Apple, Inc. | +| Name | Company | +| ----------------------------------------------------- | ------------------- | +| [anush-apple](https://github.com/anush-apple) | Apple, Inc. | | [BroderickCarlin](https://github.com/BroderickCarlin) | Samsung SmartThings | -| [chrisdecenzo](https://github.com/chrisdecenzo) | Amazon, Inc. | -| [hawk248](https://github.com/hawk248) | Comcast, Inc. | -| [jelderton](https://github.com/jelderton) | Comcast, Inc. | -| [gerickson](https://github.com/gerickson) | Google, Inc. | -| [robszewczyk](https://github.com/robszewczyk) | Google, Inc. | -| [tpmanley](https://github.com/tpmanley) | Samsung SmartThings | -| [woody-apple](https://github.com/woody-apple) | Apple, Inc. | +| [chrisdecenzo](https://github.com/chrisdecenzo) | Amazon, Inc. | +| [hawk248](https://github.com/hawk248) | Comcast, Inc. | +| [jelderton](https://github.com/jelderton) | Comcast, Inc. | +| [gerickson](https://github.com/gerickson) | Google, Inc. | +| [robszewczyk](https://github.com/robszewczyk) | Google, Inc. | +| [tpmanley](https://github.com/tpmanley) | Samsung SmartThings | +| [woody-apple](https://github.com/woody-apple) | Apple, Inc. | diff --git a/bootstrap b/bootstrap index 631b8cfe70d7d3..6cc2e51b630a66 100755 --- a/bootstrap +++ b/bootstrap @@ -28,6 +28,6 @@ nlbuild_autotools_stem="third_party/nlbuild-autotools/repo" -abs_srcdir=$(cd $(dirname "${0}") && pwd) +abs_srcdir=$(cd "$(dirname "${0}")" && pwd) -(cd "${abs_srcdir}" && exec "${abs_srcdir}/${nlbuild_autotools_stem}/scripts/bootstrap" -I "${abs_srcdir}/${nlbuild_autotools_stem}" "${@}") +(cd "$abs_srcdir" && exec "$abs_srcdir/$nlbuild_autotools_stem/scripts/bootstrap" -I "$abs_srcdir/$nlbuild_autotools_stem" "${@}") diff --git a/docs/BUILDING.md b/docs/BUILDING.md index 749af15fa06d6d..dacc17800cc3ae 100644 --- a/docs/BUILDING.md +++ b/docs/BUILDING.md @@ -1,41 +1,42 @@ ## Build Documentation -The CHIP build system uses GNU autotools to build -various platform images on Linux or MacOS. +The CHIP build system uses GNU autotools to build various platform images on +Linux or MacOS. Tested on: -* MacOS -* Ubuntu 18.04 +- MacOS +- Ubuntu 18.04 Build system features: -* Package management: 'make dist' and 'make distcheck' -* Cross-platform handling: (Linux, Darwin, iOS, Android, embedded arm, etc.) -* Multiple compiler support: clang, GCC -* Integrates automated testing framework: 'make check' -* Code style enforcement: 'make pretty' and 'make pretty-check' integration with clang-format -Assuming you have all the required tools installed, the system will build the code, -build a distribution, tidy, format, run tests, and run code coverage on the entire tree. -Tests are built into the make system. +- Package management: 'make dist' and 'make distcheck' +- Cross-platform handling: (Linux, Darwin, iOS, Android, embedded arm, etc.) +- Multiple compiler support: clang, GCC +- Integrates automated testing framework: 'make check' +- Code style enforcement: 'make pretty' and 'make pretty-check' integration + with clang-format +Assuming you have all the required tools installed, the system will build the +code, build a distribution, tidy, format, run tests, and run code coverage on +the entire tree. Tests are built into the make system. ### Tool Prerequisites -To take advantage of all the current capabilities of the make system, you'll want: - -* Bash 4.0 or greater -* GNU make, automake, autoconf, libtool -* C and C++ compilers -* clang-tidy -* clang-format-9 -* gcov +To take advantage of all the current capabilities of the make system, you'll +want: +- Bash 4.0 or greater +- GNU make, automake, autoconf, libtool +- C and C++ compilers +- clang-tidy +- clang-format-9 +- gcov #### How to install tool prerequisites on Linux -On Debian-based Linux distributions such as Ubuntu, these dependencies -can be satisfied with the following: +On Debian-based Linux distributions such as Ubuntu, these dependencies can be +satisfied with the following: ``` sudo apt-get install make autoconf automake libtool @@ -56,7 +57,8 @@ brew install lcov ### Autotools Build Preparation -Before running any other build command, the `./bootstrap` command must be run from the top-level. +Before running any other build command, the `./bootstrap` command must be run +from the top-level. ``` # Initial preparation @@ -74,14 +76,16 @@ This will build all sources, libraries, and tests for the given platform: make -f Makefile-Standalone ``` -The helper Makefile- will automatically run configure the using a default set of parameters, and allow custom override parameters to be passed via environment variables. An example of this follows: +The helper Makefile- will automatically run configure the using a +default set of parameters, and allow custom override parameters to be passed via +environment variables. An example of this follows: ``` TESTS=1 DEBUG=1 COVERAGE=1 make -f Makefile-Standalone ``` -At any time after this if a Makefile.am is updated, `./bootstrap -w make` must be run again for the changes to be picked up. - +At any time after this if a Makefile.am is updated, `./bootstrap -w make` must +be run again for the changes to be picked up. ### Build Custom configuration @@ -93,42 +97,51 @@ mkdir build/ cd build/ ../../configure ``` -Where `` is something that describes what configuration (as described by ``) -of the tree you're planning to build, or simply `out` if you're not feeling creative. -- [x] **Build all source, libraries, and tests** +Where `` is something that describes what configuration (as described by +``) of the tree you're planning to build, or simply `out` if +you're not feeling creative. + +- [x] **Build all source, libraries, and tests** + ``` make ``` -- [x] **Build distribution** +- [x] **Build distribution** + ``` make dist ``` -- [x] **Build and check distribution, running all functional and unit tests** +- [x] **Build and check distribution, running all functional and unit tests** + ``` make distcheck ``` -- [x] **Run tests** +- [x] **Run tests** + ``` make check ``` -- [x] **Verify coding style conformance** +- [x] **Verify coding style conformance** + ``` make pretty-check ``` -- [x] **Auto-enforce coding style** +- [x] **Auto-enforce coding style** + ``` make pretty ``` -- [x] **Build just one module in a subdirectory** +- [x] **Build just one module in a subdirectory** -Either enter the desired subdirectory directly and run `make` or pass the desired subdirectory to `make -C`. +Either enter the desired subdirectory directly and run `make` or pass the +desired subdirectory to `make -C`. ``` $ make -C src/system @@ -151,22 +164,24 @@ make[1]: Entering directory 'src/system' ar: `u' modifier ignored since `D' is the default (see `U') make[1]: Leaving directory 'src/system' ``` -- [x] **Add new source folder** -Add the folder to `src/` -Update `src/Makefile.am` to add the folder -Update `AC_CONFIG_FILES` in `configure.ac` + +- [x] **Add new source folder** Add the folder to `src/` Update + `src/Makefile.am` to add the folder Update `AC_CONFIG_FILES` in + `configure.ac` And then build as needed. -- [x] **Clean out entire source tree** +- [x] **Clean out entire source tree** -This will clear out all build artifacts, including those created by `./bootstrap`. +This will clear out all build artifacts, including those created by +`./bootstrap`. ``` make distclean ``` -If the source has been pulled using `git clone` the following command can also be used to clear out all build artifacts: +If the source has been pulled using `git clone` the following command can also +be used to clear out all build artifacts: ``` # To clean all intermediate build files from the tree @@ -196,23 +211,24 @@ make -f Makefile-Android ## Maintaining CHIP -If you want to maintain, enhance, extend, or otherwise modify CHIP, it -is likely you will need to change its build system, based on GNU -autotools, in some circumstances. +If you want to maintain, enhance, extend, or otherwise modify CHIP, it is likely +you will need to change its build system, based on GNU autotools, in some +circumstances. -After any change to the CHIP build system, including any *Makefile.am* -files or the *configure.ac* file, you must run the `bootstrap` or -`bootstrap-configure` (which runs both `bootstrap` and `configure` in -one shot) script to update the build system. +After any change to the CHIP build system, including any _Makefile.am_ files or +the _configure.ac_ file, you must run the `bootstrap` or `bootstrap-configure` +(which runs both `bootstrap` and `configure` in one shot) script to update the +build system. ### Dependencies -Due to its leverage of GNU autotools, if you want to modify or -otherwise maintain the CHIP build system, the following -additional packages are required and are invoked by `bootstrap`: +Due to its leverage of GNU autotools, if you want to modify or otherwise +maintain the CHIP build system, the following additional packages are required +and are invoked by `bootstrap`: - * autoconf - * automake - * libtool +- autoconf +- automake +- libtool -Instructions for installing these tools is in the Tool Prerequisites section above. +Instructions for installing these tools is in the Tool Prerequisites section +above. diff --git a/docs/PROJECT_FLOW.md b/docs/PROJECT_FLOW.md index 866e0087e5d3eb..0d79e9f2853cf0 100644 --- a/docs/PROJECT_FLOW.md +++ b/docs/PROJECT_FLOW.md @@ -12,14 +12,14 @@ be under the auspices of some open issue. This may seem onerous and in some cases duplicative, so consider these guidelines when deciding whether to you can get away with not creating an issue: -- Trivial fixes: issues can function as TODO lists, simple reminders that - something should be addressed. Sometimes, though, the work required to fix is - smaller than the work required to write the issue. -- Issues intended to be addressed by a PR may not actually be fixed or may - regress. -- Issues can span PRs (as PRs should be as small as possible, but no smaller). -- Issues help form an important basis for release notes. Any PR that addresses a - problem that should have release visibility, please do open an issue. +- Trivial fixes: issues can function as TODO lists, simple reminders that + something should be addressed. Sometimes, though, the work required to fix + is smaller than the work required to write the issue. +- Issues intended to be addressed by a PR may not actually be fixed or may + regress. +- Issues can span PRs (as PRs should be as small as possible, but no smaller). +- Issues help form an important basis for release notes. Any PR that addresses + a problem that should have release visibility, please do open an issue. ### Pull requests @@ -30,11 +30,11 @@ your reviewers. PR Don'ts: -- Don't combine unrelated changes. E.g. if the PR addresses a bug in some C - code, an update to the top-level .gitignore doesn't belong. -- Don't make stacks. E.g. if a change in a component requires a new feature or - even a small tweak in one or more of its dependencies, each dependency change - belongs in its own separate PR. +- Don't combine unrelated changes. E.g. if the PR addresses a bug in some C + code, an update to the top-level .gitignore doesn't belong. +- Don't make stacks. E.g. if a change in a component requires a new feature or + even a small tweak in one or more of its dependencies, each dependency + change belongs in its own separate PR. ### Milestones diff --git a/docs/README.md b/docs/README.md index f96378db329f38..531df56015dd5f 100644 --- a/docs/README.md +++ b/docs/README.md @@ -2,21 +2,31 @@ ## Building and Developing -* Documentation about building from the command line can be found in [the build guide](./BUILDING.md) -* Documentation about standard build & development flows using [Visual Studio Code](https://code.visualstudio.com/) can be found in [the development guide](./VSCODE_DEVELOPMENT.md) +- Documentation about building from the command line can be found in + [the build guide](./BUILDING.md) +- Documentation about standard build & development flows using + [Visual Studio Code](https://code.visualstudio.com/) can be found in + [the development guide](./VSCODE_DEVELOPMENT.md) ## Project Flow -* Documentation about general CHIP usage of GitHub, and project tools is documented in [the project flow](./PROJECT_FLOW.md) +- Documentation about general CHIP usage of GitHub, and project tools is + documented in [the project flow](./PROJECT_FLOW.md) ## Style Guide -* Documentation about style is documented in [the style guide](./STYLE_GUIDE.md) -* Additional documentation about more specific files are in the [style folder](./style/) +- Documentation about style is documented in + [the style guide](./STYLE_GUIDE.md) +- Additional documentation about more specific files are in the + [style folder](./style/) ## Third Party Tools Some tools and utilities are dependent on third party tools, such as Docker. -[Docker](https://www.docker.com) is an excellent way to have stable build environments that don't pollute the host OS. It is also much easier to maintain stability across multiple host environments. Install stable version of [Docker Desktop](https://www.docker.com/products/docker-desktop) relevant to your native OS (MacOS or Windows). Once installed, you can run docker commands from the shell/terminal. - +[Docker](https://www.docker.com) is an excellent way to have stable build +environments that don't pollute the host OS. It is also much easier to maintain +stability across multiple host environments. Install stable version of +[Docker Desktop](https://www.docker.com/products/docker-desktop) relevant to +your native OS (MacOS or Windows). Once installed, you can run docker commands +from the shell/terminal. diff --git a/docs/STYLE_GUIDE.md b/docs/STYLE_GUIDE.md index f5765028330968..7e439f52764d7c 100644 --- a/docs/STYLE_GUIDE.md +++ b/docs/STYLE_GUIDE.md @@ -2,31 +2,35 @@ CHIP documentation lives here: -* **GitHub** — All guides and tutorials across the complete [Project-CHIP organization](https://github.com/project-chip). +- **GitHub** — All guides and tutorials across the complete + [Project-CHIP organization](https://github.com/project-chip). -See [CONTRIBUTING.md](../CONTRIBUTING.md) for general information on contributing to this project. +See [CONTRIBUTING.md](../CONTRIBUTING.md) for general information on +contributing to this project. ## Location -Place all documentation contributions in the appropriate location in the [`/docs`](./) directory. Most contributions should go into the `/docs/guides` subdirectory, which covers conceptual and usage content. +Place all documentation contributions in the appropriate location in the +[`/docs`](./) directory. Most contributions should go into the `/docs/guides` +subdirectory, which covers conceptual and usage content. Current documentation structure: -Directory | Description -----|---- -`/actions` | Custom GitHub actions -`/docs/guides` | Conceptual or usage content that doesn't fit within a subdirectory, and high-level tutorials -`/docs/guides/images` | All images included in guide content -`/docs/guides/profiles` | Content describing or illustrating use of CHIP profiles -`/docs/guides/test` | Content related to testing CHIP -`/docs/guides/tools` | Content describing or illustrating use of CHIP tools -`/docs/guides/primer` | CHIP Primer content -`/docs/presentations` | PDF presentations on CHIP features -`/docs/specs` | PDFs of CHIP specifications -`/images` | Top-level CHIP images, such as logos - -If you are unsure of the best location for your contribution, create an Issue and ask, or let us know in your Pull Request. - +| Directory | Description | +| ----------------------- | -------------------------------------------------------------------------------------------- | +| `/actions` | Custom GitHub actions | +| `/docs/guides` | Conceptual or usage content that doesn't fit within a subdirectory, and high-level tutorials | +| `/docs/guides/images` | All images included in guide content | +| `/docs/guides/profiles` | Content describing or illustrating use of CHIP profiles | +| `/docs/guides/test` | Content related to testing CHIP | +| `/docs/guides/tools` | Content describing or illustrating use of CHIP tools | +| `/docs/guides/primer` | CHIP Primer content | +| `/docs/presentations` | PDF presentations on CHIP features | +| `/docs/specs` | PDFs of CHIP specifications | +| `/images` | Top-level CHIP images, such as logos | + +If you are unsure of the best location for your contribution, create an Issue +and ask, or let us know in your Pull Request. ## Style @@ -42,19 +46,26 @@ The text of a link should be descriptive, so it's clear what the link is for: ## Markdown guidelines -Use standard Markdown when authoring CHIP documentation. While HTML may be used for more complex content such as tables, use Markdown as much as possible. +Use standard Markdown when authoring CHIP documentation. While HTML may be used +for more complex content such as tables, use Markdown as much as possible. > Note: Edit this file to see the Markdown behind the examples. ### Headers -The document title should be an h1 header (#) and in title case (all words are capitalized). All section headers should be h2 (##) or lower and in sentence case (only the first word and proper nouns are capitalized). +The document title should be an h1 header (#) and in title case (all words are +capitalized). All section headers should be h2 (##) or lower and in sentence +case (only the first word and proper nouns are capitalized). -The best practice for document clarity is to not go lower than h3, but h4 is fine on occasion. Try to avoid using h4 often, or going lower than h4. If this happens, the document should be reorganized or broken up to ensure it stays at h3 with the occasional h4. +The best practice for document clarity is to not go lower than h3, but h4 is +fine on occasion. Try to avoid using h4 often, or going lower than h4. If this +happens, the document should be reorganized or broken up to ensure it stays at +h3 with the occasional h4. ### Command line examples -Feel free to use either `$` or `%` to preface command line examples, but be consistent within the same doc or set of docs: +Feel free to use either `$` or `%` to preface command line examples, but be +consistent within the same doc or set of docs: ``` $ git clone https://github.com/project-chip/connectedhomeip.git @@ -63,14 +74,16 @@ $ git clone https://github.com/project-chip/connectedhomeip.git ### Terminal prompts -If you need use a full terminal prompt with username and hostname, use the format of `root@{hostname}{special-characters}#`. +If you need use a full terminal prompt with username and hostname, use the +format of `root@{hostname}{special-characters}#`. + +For example, when logged into a Docker container, you might have a prompt like +this: -For example, when logged into a Docker container, you might have a prompt like this: ``` root@c0f3912a74ff:/# ``` - ### Commands and output All example commands and output should be in code blocks with backticks: @@ -79,15 +92,17 @@ All example commands and output should be in code blocks with backticks: code in backticks ``` -...unless the code is within a step list. In a step list, indent the code blocks: +...unless the code is within a step list. In a step list, indent the code +blocks: code indented ### Code blocks in step lists -When writing procedures that feature code blocks, indent the content for the code blocks: +When writing procedures that feature code blocks, indent the content for the +code blocks: -1. Step one: +1. Step one: $ git clone https://github.com/project-chip/connectedhomeip.git $ cd connectedhomeip @@ -96,8 +111,9 @@ When writing procedures that feature code blocks, indent the content for the cod $ ./configure -For clarity in instructions, avoid putting additional step commands after a code sample -within a step item. Instead rewrite the instruction so this is not necessary. +For clarity in instructions, avoid putting additional step commands after a code +sample within a step item. Instead rewrite the instruction so this is not +necessary. For example, avoid this: @@ -111,19 +127,19 @@ Instead, do this: 1. Step three, do this now, and you will see that thing: - $ ./configure + $ ./configure ### Inline code -Use backticks for `inline code`. This includes file paths and file or binary names. +Use backticks for `inline code`. This includes file paths and file or binary +names. ### Code Comments Use uppercase `CHIP` in comments, as it is an acronym. - Supported keywords: -Keyword | Description -----|---- -alarm | Alarm +| Keyword | Description | +| ------- | ----------- | +| alarm | Alarm | diff --git a/docs/VSCODE_DEVELOPMENT.md b/docs/VSCODE_DEVELOPMENT.md index 2c34955cd3e7ca..89bb3c836cde52 100644 --- a/docs/VSCODE_DEVELOPMENT.md +++ b/docs/VSCODE_DEVELOPMENT.md @@ -1,79 +1,120 @@ # Visual Studio Code Development -[Visual Studio Code](https://code.visualstudio.com/) is a great and simple IDE that can be used to build & develop with for CHIP. +[Visual Studio Code](https://code.visualstudio.com/) is a great and simple IDE +that can be used to build & develop with for CHIP. -CHIP supports the docker / remote container workflow in Visual Studio Code, and has a container environment setup automatically. You can read more about this workflow [here](https://code.visualstudio.com/docs/remote/containers). +CHIP supports the docker / remote container workflow in Visual Studio Code, and +has a container environment setup automatically. You can read more about this +workflow [here](https://code.visualstudio.com/docs/remote/containers). Tested on: -* MacOS 10.5 -* Windows 10 Pro + WSL + Ubuntu 18 LTS + +- MacOS 10.5 +- Windows 10 Pro + WSL + Ubuntu 18 LTS ## Setup Steps -1. *Windows Only* Enable the Windows Subsystem for Linux (WSL) following instructions here: -1. *Windows Only* Install Ubuntu from the Windows App Store here: -1. Install [Docker](https://www.docker.com/) for your operating system of choice from here: -1. Install [Visual Studio Code](https://code.visualstudio.com/) for your operating system of choice here: +1. _Windows Only_ Enable the Windows Subsystem for Linux (WSL) following + instructions here: + +1. _Windows Only_ Install Ubuntu from the Windows App Store here: + +1. Install [Docker](https://www.docker.com/) for your operating system of choice + from here: +1. Install [Visual Studio Code](https://code.visualstudio.com/) for your + operating system of choice here: 1. Install [Git](https://git-scm.com/) if you haven't already -1. *Windows Only* Enable git to use LF instead of CLRF by default: `git config --global core.autocrlf false` -1. Git clone the main CHIP repository here: +1. _Windows Only_ Enable git to use LF instead of CLRF by default: + `git config --global core.autocrlf false` +1. Git clone the main CHIP repository here: + 1. Launch Visual Studio Code, and open the cloned folder from -1. Install the [Remote - Containers](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) extension for Visual Studio Code, this extension allows you to use docker containers as a development backend. -1. Once this is installed, you'll be prompted to reload Visual Studio Code, do so -1. At the bottom right of your Visual Studio Code window you should have a new box prompting you to re-open the window as a container. Hit yes. -1. *Windows Only* Update your Visual Studio Code settings as documented here: https://code.visualstudio.com/docs/editor/integrated-terminal#_configuration to use Bash on Ubuntu (on Windows) eg: -`"terminal.integrated.shell.windows": "C:\\Windows\\System32\\bash.exe"` -1. Now your local machine is building a docker image that has all the tools necessary to build and test CHIP. This can take some time, but will eventually complete and open up the source tree +1. Install the + [Remote - Containers](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) + extension for Visual Studio Code, this extension allows you to use docker + containers as a development backend. +1. Once this is installed, you'll be prompted to reload Visual Studio Code, do + so +1. At the bottom right of your Visual Studio Code window you should have a new + box prompting you to re-open the window as a container. Hit yes. +1. _Windows Only_ Update your Visual Studio Code settings as documented here: + https://code.visualstudio.com/docs/editor/integrated-terminal#_configuration + to use Bash on Ubuntu (on Windows) eg: + `"terminal.integrated.shell.windows": "C:\\Windows\\System32\\bash.exe"` +1. Now your local machine is building a docker image that has all the tools + necessary to build and test CHIP. This can take some time, but will + eventually complete and open up the source tree ## Bootstrapping your source tree (one time) -1. Under the "Terminal" menu (or using another shortcut to the same tool), select "Run Task..." + +1. Under the "Terminal" menu (or using another shortcut to the same tool), + select "Run Task..." 1. Select the "Bootstrap" task ## Building the Source Tree + 1. Under the "Terminal" menu select "Run Build Task..." ## Tasks -Located in the [tasks json](../.vscode/tasks.json) file you'll find a list of tasks that can be run from the "Run Task..." command. -Example tasks are "Clean", "Run Pretty Check" +Located in the [tasks json](../.vscode/tasks.json) file you'll find a list of +tasks that can be run from the "Run Task..." command. Example tasks are "Clean", +"Run Pretty Check" -Developers are encouraged to add tasks to the [tasks json](../.vscode/tasks.json) over time to make sure everyone is using the same base configuration and build. +Developers are encouraged to add tasks to the +[tasks json](../.vscode/tasks.json) over time to make sure everyone is using the +same base configuration and build. ### Current base tasks are listed here -* Main Build - Full build and test of the tree -* Auto-enforce coding style -* Verify coding style conformance -* Run Unit and Functional Tests -* Run Distribution Generation - Build and check distribution, running all functional and unit tests -* Run Code Coverage (via 'make coverage') -* Clean build - Full clean build and test of the tree -* Bootstrap the source tree - On a clean tree, pull in the third party dependencies required -* Clean Tree - Full (and destructive) git clean of the tree + +- Main Build - Full build and test of the tree +- Auto-enforce coding style +- Verify coding style conformance +- Run Unit and Functional Tests +- Run Distribution Generation - Build and check distribution, running all + functional and unit tests +- Run Code Coverage (via 'make coverage') +- Clean build - Full clean build and test of the tree +- Bootstrap the source tree - On a clean tree, pull in the third party + dependencies required +- Clean Tree - Full (and destructive) git clean of the tree ## Launch Tasks -Located in the [launch json](../.vscode/launch.json) file you'll find a list of build & run jobs that can be run from the "Run" tab and start a run or debug session. +Located in the [launch json](../.vscode/launch.json) file you'll find a list of +build & run jobs that can be run from the "Run" tab and start a run or debug +session. -Developers are encouraged to add tasks to the [launch json](../.vscode/launch.json) over time to make sure everyone is using the same base debuging setup. +Developers are encouraged to add tasks to the +[launch json](../.vscode/launch.json) over time to make sure everyone is using +the same base debuging setup. ## Submitting a Pull Request - Practical Advice ### Before submitting a PR, make sure these commands run and succeed -* Run task: "Verify coding style conformance" -* Run task: "Run Distribution Generation" + +- Run task: "Verify coding style conformance" +- Run task: "Run Distribution Generation" ## Common Issues -* [Missing Git credential](https://code.visualstudio.com/docs/remote/containers#_sharing-git-credentials-with-your-container) -* [Missing Git SSH keys](https://code.visualstudio.com/docs/remote/containers#_sharing-git-credentials-with-your-container) -* [Using GPG signing keys](https://github.com/microsoft/vscode-remote-release/issues/72) + +- [Missing Git credential](https://code.visualstudio.com/docs/remote/containers#_sharing-git-credentials-with-your-container) +- [Missing Git SSH keys](https://code.visualstudio.com/docs/remote/containers#_sharing-git-credentials-with-your-container) +- [Using GPG signing keys](https://github.com/microsoft/vscode-remote-release/issues/72) ## Visual Studio Code FAQ -* *Highly* recommend you read through [this page](https://code.visualstudio.com/docs/getstarted/settings) to learn how to configure Visual Studio Code to suit your style: -* Great primer set of videos [here](https://code.visualstudio.com/docs/getstarted/introvideos) +- _Highly_ recommend you read through + [this page](https://code.visualstudio.com/docs/getstarted/settings) to learn + how to configure Visual Studio Code to suit your style: + +- Great primer set of videos + [here](https://code.visualstudio.com/docs/getstarted/introvideos) + ## Visual Studio Code Recommended Settings -* Configure the editor to format on save, in your Visual Studio Code Settings: `"editor.formatOnSave": true` -* Configure the clang-format extension `@ext:xaver.clang-format`, it is installed in the docker container. Make sure all languages are enabled - +- Configure the editor to format on save, in your Visual Studio Code Settings: + `"editor.formatOnSave": true` +- Configure the clang-format extension `@ext:xaver.clang-format`, it is + installed in the docker container. Make sure all languages are enabled diff --git a/docs/style/README.md b/docs/style/README.md index 890578a55f2f60..7fa304cd800577 100644 --- a/docs/style/README.md +++ b/docs/style/README.md @@ -1,6 +1,8 @@ # Style -When necessary to drive into more detail about styles about specific types of files this is where CHIP collects them +When necessary to drive into more detail about styles about specific types of +files this is where CHIP collects them ## Specific Types -* [Makefiles](./STYLE_MAKEFILES.md) + +- [Makefiles](./STYLE_MAKEFILES.md) diff --git a/docs/style/STYLE_MAKEFILES.md b/docs/style/STYLE_MAKEFILES.md index 7263f3203dd381..2dbad85512d21a 100644 --- a/docs/style/STYLE_MAKEFILES.md +++ b/docs/style/STYLE_MAKEFILES.md @@ -1,3 +1,4 @@ # CHIP Makefile Style Guide -Use `tabs` only where strictly necessary. For example, Avoid using `tabs` to align line breaks. +Use `tabs` only where strictly necessary. For example, Avoid using `tabs` to +align line breaks. diff --git a/examples/lock-app/efr32/README.md b/examples/lock-app/efr32/README.md index 5ad9ce4003fae8..71b14aaaf3485b 100644 --- a/examples/lock-app/efr32/README.md +++ b/examples/lock-app/efr32/README.md @@ -4,12 +4,12 @@ An example showing the use of CHIP on the Silicon Labs EFR32 MG12.
-- [CHIP EFR32 Lock Example](#chip-efr32-lock-example) - - [Introduction](#introduction) - - [Building](#building) - - [Initializing the EFR32 module](#initializing-the-efr32-module) - - [Flashing the Application](#flashing-the-application) - - [Viewing Logging Output](#viewing-logging-output) +- [CHIP EFR32 Lock Example](#chip-efr32-lock-example) + - [Introduction](#introduction) + - [Building](#building) + - [Initializing the EFR32 module](#initializing-the-efr32-module) + - [Flashing the Application](#flashing-the-application) + - [Viewing Logging Output](#viewing-logging-output)
@@ -35,8 +35,8 @@ file can be flashed directly onto the Silicon Labs WSTK kit hardware. ## Building -- Download and install the - [Silicon Labs Simplicity Studio and SDK for Thread and Zigbee version v2.7](https://www.silabs.com/products/development-tools/software/simplicity-studio) +- Download and install the + [Silicon Labs Simplicity Studio and SDK for Thread and Zigbee version v2.7](https://www.silabs.com/products/development-tools/software/simplicity-studio) Install SimplicityStudio or extract the SimplicityStudio archive to where you want to install Simplicity Studio and follow the instructions in README.txt @@ -50,23 +50,23 @@ In Simplicity Studio from the Launcher perspective click on the "Update Software" button. The Package Manager window will Open. Ensure that the following SDKs are installed (as of January 2020). -- Bluetooth 2.13.0.0 -- Flex 2.7.0.0 +- Bluetooth 2.13.0.0 +- Flex 2.7.0.0 -- Download and install a suitable ARM gcc tool chain: - [GNU Arm Embedded Toolchain 9-2019-q4-major](https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm/downloads) +- Download and install a suitable ARM gcc tool chain: + [GNU Arm Embedded Toolchain 9-2019-q4-major](https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm/downloads) -- Install some additional tools(likely already present for CHIP developers): +- Install some additional tools(likely already present for CHIP developers): - # Linux - $ sudo apt-get install git make automake libtool ccache + # Linux + $ sudo apt-get install git make automake libtool ccache - # Mac OS X - $ brew install automake libtool ccache + # Mac OS X + $ brew install automake libtool ccache -- To build for an MG21 part make the following changes to the - platform/CMSIS/Include/core_cm33.h file within the Silicon Labs SDK. Copy the - following lines to the top of the core_cm33.h file. +- To build for an MG21 part make the following changes to the + platform/CMSIS/Include/core_cm33.h file within the Silicon Labs SDK. Copy + the following lines to the top of the core_cm33.h file. ```cpp #if defined(__GNUC__) @@ -74,28 +74,28 @@ following SDKs are installed (as of January 2020). #endif ``` -- Supported hardware: +- Supported hardware: - MG12 boards: + MG12 boards: - - BRD4161A / SLWSTK6000B / Wireless Starter Kit / 2.4GHz@19dBm - - BRD4166A / SLTB004A / Thunderboard Sense 2 / 2.4GHz@10dBm - - BRD4170A / SLWSTK6000B / Multiband Wireless Starter Kit / 2.4GHz@19dBm, - 915MHz@19dBm - - BRD4304A / SLWSTK6000B / MGM12P Module / 2.4GHz@19dBm + - BRD4161A / SLWSTK6000B / Wireless Starter Kit / 2.4GHz@19dBm + - BRD4166A / SLTB004A / Thunderboard Sense 2 / 2.4GHz@10dBm + - BRD4170A / SLWSTK6000B / Multiband Wireless Starter Kit / 2.4GHz@19dBm, + 915MHz@19dBm + - BRD4304A / SLWSTK6000B / MGM12P Module / 2.4GHz@19dBm - MG21 boards: + MG21 boards: - - BRD4180A / SLWSTK6006A / Wireless Starter Kit / 2.4GHz@20dBm + - BRD4180A / SLWSTK6006A / Wireless Starter Kit / 2.4GHz@20dBm -* Build the example application: +* Build the example application: - $ export EFR32_SDK_ROOT= - $ make BOARD=BRD4161A + $ export EFR32_SDK_ROOT= + $ make BOARD=BRD4161A -- To delete generated executable, libraries and object files use: +- To delete generated executable, libraries and object files use: - $ make BOARD=BRD4161A clean + $ make BOARD=BRD4161A clean @@ -105,32 +105,32 @@ The example application is designed to run on the Silicon Labs SDK development kit. Prior to installing the application, the device's flash memory should be erased. -- Connect the host machine to the J-Link Interface MCU USB connector on the - EFR32 WSTK. +- Connect the host machine to the J-Link Interface MCU USB connector on the + EFR32 WSTK. -- Use the Makefile to erase the flash: +- Use the Makefile to erase the flash: - $ make BOARD=BRD4161A erase + $ make BOARD=BRD4161A erase -- To erase a specific device using its serial number: +- To erase a specific device using its serial number: - $ make BOARD=BRD4161A SERIALNO=440113717 erase + $ make BOARD=BRD4161A SERIALNO=440113717 erase ## Flashing the Application -- To rebuild the image and flash the example app: +- To rebuild the image and flash the example app: - $ make BOARD=BRD4161A flash + $ make BOARD=BRD4161A flash -- To rebuild the image and flash a specific device using its serial number: +- To rebuild the image and flash a specific device using its serial number: - $ make BOARD=BRD4161A SERIALNO=440113717 flash + $ make BOARD=BRD4161A SERIALNO=440113717 flash -- To flash an existing image without rebuilding: +- To flash an existing image without rebuilding: - $ make BOARD=BRD4161A flash-app + $ make BOARD=BRD4161A flash-app @@ -146,36 +146,36 @@ Software and Documentation Pack_ ([web site](https://www.segger.com/downloads/jlink#J-LinkSoftwareAndDocumentationPack)). Alternatively the _SEGGER Ozone - J-Link Debugger_ can be used to view RTT logs. -- Download the J-Link installer by navigating to the appropriate URL and - agreeing to the license agreement. +- Download the J-Link installer by navigating to the appropriate URL and + agreeing to the license agreement. -- [JLink_Linux_x86_64.deb](https://www.segger.com/downloads/jlink/JLink_Linux_x86_64.deb) -- [JLink_MacOSX.pkg](https://www.segger.com/downloads/jlink/JLink_MacOSX.pkg) +- [JLink_Linux_x86_64.deb](https://www.segger.com/downloads/jlink/JLink_Linux_x86_64.deb) +- [JLink_MacOSX.pkg](https://www.segger.com/downloads/jlink/JLink_MacOSX.pkg) -* Install the J-Link software +* Install the J-Link software - $ cd ~/Downloads - $ sudo dpkg -i JLink_Linux_V*_x86_64.deb + $ cd ~/Downloads + $ sudo dpkg -i JLink_Linux_V*_x86_64.deb -* In Linux, grant the logged in user the ability to talk to the development - hardware via the linux tty device (/dev/ttyACMx) by adding them to the dialout - group. +* In Linux, grant the logged in user the ability to talk to the development + hardware via the linux tty device (/dev/ttyACMx) by adding them to the + dialout group. - $ sudo usermod -a -G dialout ${USER} + $ sudo usermod -a -G dialout ${USER} Once the above is complete, log output can be viewed using the JLinkExe tool in combination with JLinkRTTClient as follows: -- Run the JLinkExe tool with arguments to autoconnect to the WSTK board: +- Run the JLinkExe tool with arguments to autoconnect to the WSTK board: - For MG12 use: + For MG12 use: - $ JLinkExe -device EFR32MG12PXXXF1024 -if JTAG -speed 4000 -autoconnect 1 + $ JLinkExe -device EFR32MG12PXXXF1024 -if JTAG -speed 4000 -autoconnect 1 - For MG21 use: + For MG21 use: - $ JLinkExe -device EFR32MG21AXXXF1024 -if SWD -speed 4000 -autoconnect 1 + $ JLinkExe -device EFR32MG21AXXXF1024 -if SWD -speed 4000 -autoconnect 1 -- In a second terminal, run the JLinkRTTClient to view logs: +- In a second terminal, run the JLinkRTTClient to view logs: - $ JLinkRTTClient + $ JLinkRTTClient diff --git a/examples/lock-app/efr32/src/AppTask.cpp b/examples/lock-app/efr32/src/AppTask.cpp index 6bf6e587fc5e32..78049be6d5911f 100644 --- a/examples/lock-app/efr32/src/AppTask.cpp +++ b/examples/lock-app/efr32/src/AppTask.cpp @@ -19,8 +19,8 @@ #include "AppTask.h" #include "AppEvent.h" -#include "LEDWidget.h" #include "ButtonHandler.h" +#include "LEDWidget.h" #include "AppConfig.h" @@ -131,11 +131,11 @@ void AppTask::AppTaskMain(void * pvParameter) eventReceived = xQueueReceive(sAppEventQueue, &event, 0); } - // Collect connectivity and configuration state from the CHIP stack. Because the - // CHIP event loop is being run in a separate task, the stack must be locked - // while these values are queried. However we use a non-blocking lock request - // (TryLockCHIPStack()) to avoid blocking other UI activities when the CHIP - // task is busy (e.g. with a long crypto operation). + // Collect connectivity and configuration state from the CHIP stack. Because + // the CHIP event loop is being run in a separate task, the stack must be + // locked while these values are queried. However we use a non-blocking + // lock request (TryLockCHIPStack()) to avoid blocking other UI activities + // when the CHIP task is busy (e.g. with a long crypto operation). if (PlatformMgr().TryLockChipStack()) { sIsThreadProvisioned = ConnectivityMgr().IsThreadProvisioned(); @@ -147,19 +147,20 @@ void AppTask::AppTaskMain(void * pvParameter) } // Consider the system to be "fully connected" if it has service - // connectivity and it is able to interact with the service on a regular basis. + // connectivity and it is able to interact with the service on a regular + // basis. bool isFullyConnected = (sHaveServiceConnectivity && sIsServiceSubscriptionEstablished); // Update the status LED if factory reset has not been initiated. // // If system has "full connectivity", keep the LED On constantly. // - // If thread and service provisioned, but not attached to the thread network yet OR no - // connectivity to the service OR subscriptions are not fully established - // THEN blink the LED Off for a short period of time. + // If thread and service provisioned, but not attached to the thread network + // yet OR no connectivity to the service OR subscriptions are not fully + // established THEN blink the LED Off for a short period of time. // - // If the system has ble connection(s) uptill the stage above, THEN blink the LEDs at an even - // rate of 100ms. + // If the system has ble connection(s) uptill the stage above, THEN blink + // the LEDs at an even rate of 100ms. // // Otherwise, blink the LED ON for a very short time. if (sAppTask.mFunction != kFunction_FactoryReset) @@ -262,17 +263,20 @@ void AppTask::FunctionTimerEventHandler(AppEvent * aEvent) return; } - // If we reached here, the button was held past FACTORY_RESET_TRIGGER_TIMEOUT, initiate factory reset + // If we reached here, the button was held past FACTORY_RESET_TRIGGER_TIMEOUT, + // initiate factory reset if (sAppTask.mFunctionTimerActive && sAppTask.mFunction == kFunction_SoftwareUpdate) { EFR32_LOG("Factory Reset Triggered. Release button within %ums to cancel.", FACTORY_RESET_TRIGGER_TIMEOUT); - // Start timer for FACTORY_RESET_CANCEL_WINDOW_TIMEOUT to allow user to cancel, if required. + // Start timer for FACTORY_RESET_CANCEL_WINDOW_TIMEOUT to allow user to + // cancel, if required. sAppTask.StartTimer(FACTORY_RESET_CANCEL_WINDOW_TIMEOUT); sAppTask.mFunction = kFunction_FactoryReset; - // Turn off all LEDs before starting blink to make sure blink is co-ordinated. + // Turn off all LEDs before starting blink to make sure blink is + // co-ordinated. sStatusLED.Set(false); sLockLED.Set(false); @@ -292,11 +296,13 @@ void AppTask::FunctionHandler(AppEvent * aEvent) return; } - // To trigger software update: press the APP_FUNCTION_BUTTON button briefly (< FACTORY_RESET_TRIGGER_TIMEOUT) - // To initiate factory reset: press the APP_FUNCTION_BUTTON for FACTORY_RESET_TRIGGER_TIMEOUT + - // FACTORY_RESET_CANCEL_WINDOW_TIMEOUT All LEDs start blinking after FACTORY_RESET_TRIGGER_TIMEOUT to signal factory - // reset has been initiated. To cancel factory reset: release the APP_FUNCTION_BUTTON once all LEDs start blinking - // within the FACTORY_RESET_CANCEL_WINDOW_TIMEOUT + // To trigger software update: press the APP_FUNCTION_BUTTON button briefly (< + // FACTORY_RESET_TRIGGER_TIMEOUT) To initiate factory reset: press the + // APP_FUNCTION_BUTTON for FACTORY_RESET_TRIGGER_TIMEOUT + + // FACTORY_RESET_CANCEL_WINDOW_TIMEOUT All LEDs start blinking after + // FACTORY_RESET_TRIGGER_TIMEOUT to signal factory reset has been initiated. + // To cancel factory reset: release the APP_FUNCTION_BUTTON once all LEDs + // start blinking within the FACTORY_RESET_CANCEL_WINDOW_TIMEOUT if (aEvent->ButtonEvent.Action == APP_BUTTON_PRESSED) { if (!sAppTask.mFunctionTimerActive && sAppTask.mFunction == kFunction_NoneSelected) @@ -308,7 +314,8 @@ void AppTask::FunctionHandler(AppEvent * aEvent) } else { - // If the button was released before factory reset got initiated, trigger a software update. + // If the button was released before factory reset got initiated, trigger a + // software update. if (sAppTask.mFunctionTimerActive && sAppTask.mFunction == kFunction_SoftwareUpdate) { sAppTask.CancelTimer(); @@ -325,7 +332,8 @@ void AppTask::FunctionHandler(AppEvent * aEvent) sAppTask.CancelTimer(); - // Change the function to none selected since factory reset has been canceled. + // Change the function to none selected since factory reset has been + // canceled. sAppTask.mFunction = kFunction_NoneSelected; EFR32_LOG("Factory Reset has been Canceled"); diff --git a/examples/lock-app/efr32/src/ButtonHandler.cpp b/examples/lock-app/efr32/src/ButtonHandler.cpp index eb2883c52b1242..c27f9ab2bc89c8 100644 --- a/examples/lock-app/efr32/src/ButtonHandler.cpp +++ b/examples/lock-app/efr32/src/ButtonHandler.cpp @@ -16,8 +16,8 @@ * limitations under the License. */ -#include "AppTask.h" #include "ButtonHandler.h" +#include "AppTask.h" #include "AppConfig.h" @@ -32,8 +32,9 @@ typedef struct ButtonArray } ButtonArray_t; static const ButtonArray_t sButtonArray[BSP_BUTTON_COUNT] = BSP_BUTTON_INIT; // GPIO info for the 2 WDTK buttons. -TimerHandle_t buttonTimers[BSP_BUTTON_COUNT]; // FreeRTOS timers used for debouncing buttons. Array to hold handles to - // the created timers. +TimerHandle_t buttonTimers[BSP_BUTTON_COUNT]; // FreeRTOS timers used for debouncing +// buttons. Array to hold handles to +// the created timers. void ButtonHandler::Init(void) { @@ -46,7 +47,8 @@ void ButtonHandler::Init(void) APP_BUTTON_DEBOUNCE_PERIOD_MS, // timer period false, // no timer reload (==one-shot) (void *) (int) i, // init timer id = button index - TimerCallback // timer callback handler (all buttons use the same timer cn function) + TimerCallback // timer callback handler (all buttons use + // the same timer cn function) ); } } @@ -105,7 +107,8 @@ void ButtonHandler::EventHelper(uint8_t btnIdx, bool isrContext) { portBASE_TYPE taskWoken = pdFALSE; // For FreeRTOS timer (below). - // Start/restart the button debounce timer (Note ISR version of FreeRTOS api call here). + // Start/restart the button debounce timer (Note ISR version of FreeRTOS + // api call here). xTimerStartFromISR(buttonTimers[btnIdx], &taskWoken); if (taskWoken != pdFALSE) diff --git a/examples/lock-app/efr32/src/LEDWidget.cpp b/examples/lock-app/efr32/src/LEDWidget.cpp index 1fe112b0f67398..1d31a5ff4bff89 100644 --- a/examples/lock-app/efr32/src/LEDWidget.cpp +++ b/examples/lock-app/efr32/src/LEDWidget.cpp @@ -17,8 +17,8 @@ * limitations under the License. */ -#include "AppTask.h" #include "LEDWidget.h" +#include "AppTask.h" #include "bsp.h" diff --git a/examples/lock-app/efr32/src/display/init_lcd.c b/examples/lock-app/efr32/src/display/init_lcd.c index 58f05b04a3931a..6bab885eec938e 100644 --- a/examples/lock-app/efr32/src/display/init_lcd.c +++ b/examples/lock-app/efr32/src/display/init_lcd.c @@ -20,10 +20,11 @@ #include #include "init_lcd.h" -#include "sample_qr_code.h" + #include "display.h" #include "dmd.h" #include "glib.h" +#include "sample_qr_code.h" static GLIB_Context_t glibContext; diff --git a/examples/lock-app/efr32/src/init_board.c b/examples/lock-app/efr32/src/init_board.c index 55535981984494..31053f471bc76f 100644 --- a/examples/lock-app/efr32/src/init_board.c +++ b/examples/lock-app/efr32/src/init_board.c @@ -62,7 +62,8 @@ void initBoard(void) || (HAL_USART1_ENABLE == 1) \ || (HAL_USART0_ENABLE == 1)) */ - // Put the SPI flash into Deep Power Down mode for those radio boards where it is available + // Put the SPI flash into Deep Power Down mode for those radio boards where it + // is available MX25_init(); MX25_DP(); // We must disable SPI communication @@ -75,4 +76,4 @@ void initVcomEnable(void) // Enable VCOM if requested GPIO_PinModeSet(BSP_VCOM_ENABLE_PORT, BSP_VCOM_ENABLE_PIN, gpioModePushPull, HAL_VCOM_ENABLE); #endif // HAL_VCOM_ENABLE -} \ No newline at end of file +} diff --git a/examples/lock-app/efr32/src/main.cpp b/examples/lock-app/efr32/src/main.cpp index 46df5ccb4be827..87aa266ca14515 100644 --- a/examples/lock-app/efr32/src/main.cpp +++ b/examples/lock-app/efr32/src/main.cpp @@ -17,21 +17,21 @@ * limitations under the License. */ +#include #include #include -#include +#include #include #include -#include #include #include #include "AppConfig.h" -#include "init_mcu.h" #include "init_board.h" +#include "init_mcu.h" #if DISPLAY_ENABLED #include "init_lcd.h" diff --git a/examples/lock-app/nrf5/README.md b/examples/lock-app/nrf5/README.md index 07297ae000603f..259a0b09b6ed0f 100644 --- a/examples/lock-app/nrf5/README.md +++ b/examples/lock-app/nrf5/README.md @@ -5,15 +5,15 @@ An example application showing the use
-- [CHIP nRF52840 Lock Example Application](#chip-nrf52840-lock-example-application) - - [Introduction](#introduction) - - [Device UI](#device-ui) - - [Building](#building) - - [Using CHIP's VSCode `devcontainer`](#using-chips-vscode-devcontainer) - - [Using Native Shell](#using-native-shell) - - [Initializing the nRF52840 DK](#initializing-the-nrf52840-dk) - - [Flashing the Application](#flashing-the-application) - - [Viewing Logging Output](#viewing-logging-output) +- [CHIP nRF52840 Lock Example Application](#chip-nrf52840-lock-example-application) + - [Introduction](#introduction) + - [Device UI](#device-ui) + - [Building](#building) + - [Using CHIP's VSCode `devcontainer`](#using-chips-vscode-devcontainer) + - [Using Native Shell](#using-native-shell) + - [Initializing the nRF52840 DK](#initializing-the-nrf52840-dk) + - [Flashing the Application](#flashing-the-application) + - [Viewing Logging Output](#viewing-logging-output)
@@ -52,17 +52,19 @@ general-purpose LEDs and buttons built in to the nRF52840 DK dev board. **LED #1** shows the overall state of the device and its connectivity. Four states are depicted: -- _Short Flash On (50ms on/950ms off)_ — The device is in an unprovisioned - (unpaired) state and is waiting for a commissioning application to connect. +- _Short Flash On (50ms on/950ms off)_ — The device is in an + unprovisioned (unpaired) state and is waiting for a commissioning + application to connect. -* _Rapid Even Flashing (100ms on/100ms off)_ — The device is in an - unprovisioned state and a commissioning application is connected via BLE. +* _Rapid Even Flashing (100ms on/100ms off)_ — The device is in an + unprovisioned state and a commissioning application is connected via BLE. -- _Short Flash Off (950ms on/50ms off)_ — The device is full provisioned, - but does not yet have full network (Thread) or service connectivity. +- _Short Flash Off (950ms on/50ms off)_ — The device is full + provisioned, but does not yet have full network (Thread) or service + connectivity. -* _Solid On_ — The device is fully provisioned and has full network and - service connectivity. +* _Solid On_ — The device is fully provisioned and has full network and + service connectivity. **Button #1** can be used to initiate a OTA software update as well as to reset the device to a default state. @@ -108,51 +110,51 @@ Alternatively, you can run `Build nRF5 Lock App` VSCode task. ### Using Native Shell -- Download and install the - [Nordic nRF5 SDK for Thread and Zigbee](https://www.nordicsemi.com/Software-and-Tools/Software/nRF5-SDK-for-Thread-and-Zigbee) - ([Direct download link](https://www.nordicsemi.com/-/media/Software-and-other-downloads/SDKs/nRF5-SDK-for-Thread/nRF5-SDK-for-Thread-and-Zigbee/nRF5SDKforThreadandZigbeev400dc7186b.zip)) +- Download and install the + [Nordic nRF5 SDK for Thread and Zigbee](https://www.nordicsemi.com/Software-and-Tools/Software/nRF5-SDK-for-Thread-and-Zigbee) + ([Direct download link](https://www.nordicsemi.com/-/media/Software-and-other-downloads/SDKs/nRF5-SDK-for-Thread/nRF5-SDK-for-Thread-and-Zigbee/nRF5SDKforThreadandZigbeev400dc7186b.zip)) -* Download and install the - [Nordic nRF5x Command Line Tools](https://www.nordicsemi.com/Software-and-Tools/Development-Tools/nRF-Command-Line-Tools/Download) - (Direct download link: - [Linux](https://www.nordicsemi.com/-/media/Software-and-other-downloads/Desktop-software/nRF-command-line-tools/sw/Versions-10-x-x/10-7-0/nRFCommandLineTools1070Linuxamd64tar.gz) - [Mac OS X](https://www.nordicsemi.com/-/media/Software-and-other-downloads/Desktop-software/nRF-command-line-tools/sw/Versions-10-x-x/10-7-0/nRF-Command-Line-Tools_10_7_0_OSX.tar)) +* Download and install the + [Nordic nRF5x Command Line Tools](https://www.nordicsemi.com/Software-and-Tools/Development-Tools/nRF-Command-Line-Tools/Download) + (Direct download link: + [Linux](https://www.nordicsemi.com/-/media/Software-and-other-downloads/Desktop-software/nRF-command-line-tools/sw/Versions-10-x-x/10-7-0/nRFCommandLineTools1070Linuxamd64tar.gz) + [Mac OS X](https://www.nordicsemi.com/-/media/Software-and-other-downloads/Desktop-software/nRF-command-line-tools/sw/Versions-10-x-x/10-7-0/nRF-Command-Line-Tools_10_7_0_OSX.tar)) -* Download and install a suitable ARM gcc tool chain: - [GNU Arm Embedded Toolchain 7-2018-q2-update](https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm/downloads) - (Direct download link: - [Linux](https://armkeil.blob.core.windows.net/developer/Files/downloads/gnu-rm/9-2019q4/gcc-arm-none-eabi-9-2019-q4-major-x86_64-linux.tar.bz2) - [Mac OS X](https://armkeil.blob.core.windows.net/developer/Files/downloads/gnu-rm/9-2019q4/gcc-arm-none-eabi-9-2019-q4-major-mac.tar.bz2)) +* Download and install a suitable ARM gcc tool chain: + [GNU Arm Embedded Toolchain 7-2018-q2-update](https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm/downloads) + (Direct download link: + [Linux](https://armkeil.blob.core.windows.net/developer/Files/downloads/gnu-rm/9-2019q4/gcc-arm-none-eabi-9-2019-q4-major-x86_64-linux.tar.bz2) + [Mac OS X](https://armkeil.blob.core.windows.net/developer/Files/downloads/gnu-rm/9-2019q4/gcc-arm-none-eabi-9-2019-q4-major-mac.tar.bz2)) -- Install some additional tools: +- Install some additional tools: - # Linux - $ sudo apt-get install git make automake libtool ccache + # Linux + $ sudo apt-get install git make automake libtool ccache - # Mac OS X - $ brew install automake libtool ccache + # Mac OS X + $ brew install automake libtool ccache -- Set the following environment variables based on the locations/versions of the - packages installed above: +- Set the following environment variables based on the locations/versions of + the packages installed above: - export NRF5_SDK_ROOT=${HOME}/tools/nRF5_SDK_for_Thread_and_Zigbee_v3.1.0 - export NRF5_TOOLS_ROOT=${HOME}/tools/nRF-Command-Line-Tools - export GNU_INSTALL_ROOT=${HOME}/tools/gcc-arm-none-eabi-7-2018-q2-update/bin/ - export PATH=${PATH}:${NRF5_TOOLS_ROOT}/nrfjprog + export NRF5_SDK_ROOT=${HOME}/tools/nRF5_SDK_for_Thread_and_Zigbee_v3.1.0 + export NRF5_TOOLS_ROOT=${HOME}/tools/nRF-Command-Line-Tools + export GNU_INSTALL_ROOT=${HOME}/tools/gcc-arm-none-eabi-7-2018-q2-update/bin/ + export PATH=${PATH}:${NRF5_TOOLS_ROOT}/nrfjprog

For convenience, place these settings in local script file (e.g. setup-env.sh) so that they can be loaded into the environment as needed (e.g. by running 'source ./setup-env.sh').

-- Clone the [CHIP](https://github.com/project-chip/connectedhomeip) repo into a - local directory +- Clone the [CHIP](https://github.com/project-chip/connectedhomeip) repo into + a local directory - $ cd ~ - $ git clone https://github.com/project-chip/connectedhomeip.git + $ cd ~ + $ git clone https://github.com/project-chip/connectedhomeip.git -* Run make to build the application +* Run make to build the application - $ cd ~/connectedhomeip/examples/lock-app/nrf5 - $ make clean - $ make + $ cd ~/connectedhomeip/examples/lock-app/nrf5 + $ make clean + $ make @@ -163,15 +165,15 @@ The example application is designed to run on the development kit. Prior to installing the application, the device's flash memory should be erased and the Nordic SoftDevice image installed. -- Connect the host machine to the J-Link Interface MCU USB connector on the - nRF52840 DK. The Interface MCU connector is the one on the _short_ side of the - board. +- Connect the host machine to the J-Link Interface MCU USB connector on the + nRF52840 DK. The Interface MCU connector is the one on the _short_ side of + the board. -* Use the Makefile to erase the flash and program the Nordic SoftDevice image. +* Use the Makefile to erase the flash and program the Nordic SoftDevice image. - $ cd ~/connectedhomeip/examples/lock-app/nrf5 - $ make erase - $ make flash-softdevice + $ cd ~/connectedhomeip/examples/lock-app/nrf5 + $ make erase + $ make flash-softdevice Once the above is complete, it shouldn't need be done again _unless_ the SoftDevice image or the Nordic configuration storage (fds) area becomes corrupt. @@ -203,33 +205,34 @@ Using the RTT facility requires downloading and installing the _SEGGER J-Link Software and Documentation Pack_ ([web site](https://www.segger.com/downloads/jlink#J-LinkSoftwareAndDocumentationPack)). -- Download the J-Link installer by navigating to the appropriate URL and - agreeing to the license agreement. +- Download the J-Link installer by navigating to the appropriate URL and + agreeing to the license agreement.

Linux: JLink_Linux_x86_64.deb

MacOS: JLink_MacOSX.pkg

-- Install the J-Link software +- Install the J-Link software - $ cd ~/Downloads - $ sudo dpkg -i JLink_Linux_V*_x86_64.deb + $ cd ~/Downloads + $ sudo dpkg -i JLink_Linux_V*_x86_64.deb -* In Linux, grant the logged in user the ability to talk to the development - hardware via the linux tty device (/dev/ttyACMx) by adding them to the dialout - group. +* In Linux, grant the logged in user the ability to talk to the development + hardware via the linux tty device (/dev/ttyACMx) by adding them to the + dialout group. - $ sudo usermod -a -G dialout ${USER} + $ sudo usermod -a -G dialout ${USER} Once the above is complete, log output can be viewed using the JLinkExe tool in combination with JLinkRTTClient as follows: -- Run the JLinkExe tool with arguments to autoconnect to the nRF82480 DK board: +- Run the JLinkExe tool with arguments to autoconnect to the nRF82480 DK + board: - $ JLinkExe -device NRF52840_XXAA -if SWD -speed 4000 -autoconnect 1 + $ JLinkExe -device NRF52840_XXAA -if SWD -speed 4000 -autoconnect 1 -- In a second terminal, run the JLinkRTTClient: +- In a second terminal, run the JLinkRTTClient: - $ JLinkRTTClient + $ JLinkRTTClient Logging output will appear in the second terminal. diff --git a/integrations/README.md b/integrations/README.md index 12ba2da71bc261..f08c5dd078f700 100644 --- a/integrations/README.md +++ b/integrations/README.md @@ -1,4 +1,4 @@ # Integrations -/integrations are collections of scripts, configurations, and other -glue for interacting with tools, services, etc. +/integrations are collections of scripts, configurations, and other glue for +interacting with tools, services, etc. diff --git a/integrations/ci-tools/build.sh b/integrations/ci-tools/build.sh index d80d1a0b90fac5..f7099c7d01097c 100755 --- a/integrations/ci-tools/build.sh +++ b/integrations/ci-tools/build.sh @@ -54,6 +54,7 @@ case "$TASK" in run-code-coverage) docker_run_bash_command "$bootstrap" docker_run_bash_command 'make V=1 -C build/default coverage' + docker_run_bash_command 'bash <(curl -s https://codecov.io/bash)' ;; run-crypto-tests) diff --git a/integrations/ci-tools/post_build_success.sh b/integrations/ci-tools/post_build_success.sh index 38c878be60eaa1..a9bf588e2f8845 100755 --- a/integrations/ci-tools/post_build_success.sh +++ b/integrations/ci-tools/post_build_success.sh @@ -1,3 +1 @@ #!/bin/bash - -bash <(curl -s https://codecov.io/bash) diff --git a/integrations/clang/clang-format-check.sh b/integrations/clang/clang-format-check.sh index 38a2b052f37616..69fa0af430874c 100755 --- a/integrations/clang/clang-format-check.sh +++ b/integrations/clang/clang-format-check.sh @@ -7,14 +7,14 @@ # die() { - echo " *** ERROR: $*" - exit 1 + echo " *** ERROR: $*" + exit 1 } # from `man diff`: # Exit status is 0 if inputs are the same, 1 if different, 2 if trouble. -"$(dirname "$0")"/clang-format.sh -style=file "$@" | diff -u "$@" - || die "diffs exist" +"$(dirname "$0")"/clang-format.sh -style=file "$@" | diff -u "$@" - || die "diffs exist" for arg; do true; done file=$arg diff --git a/integrations/clang/clang-format.sh b/integrations/clang/clang-format.sh index c9a84c754e0324..18a67a3610a3da 100755 --- a/integrations/clang/clang-format.sh +++ b/integrations/clang/clang-format.sh @@ -3,41 +3,40 @@ CLANG_FORMAT_VERSION="clang-format version 9.0" die() { - echo " *** ERROR: $*" - exit 1 + echo " *** ERROR: $*" + exit 1 } -if command -v clang-format-9 > /dev/null; then - alias clang-format=clang-format-9 -elif command -v clang-format > /dev/null; then - case "$(clang-format --version)" in - "$CLANG_FORMAT_VERSION"*) - ;; - *) - die "$(clang-format --version); \"$CLANG_FORMAT_VERSION\" required" - ;; - esac +if command -v clang-format-9 >/dev/null; then + alias clang-format=clang-format-9 +elif command -v clang-format >/dev/null; then + case "$(clang-format --version)" in + "$CLANG_FORMAT_VERSION"*) ;; + + *) + die "$(clang-format --version); \"$CLANG_FORMAT_VERSION\" required" + ;; + esac else - die "$CLANG_FORMAT_VERSION required" + die "$CLANG_FORMAT_VERSION required" fi clang-format "$@" || die "format failed" # ensure EOF newline REPLACE=no -for arg -do - case $arg in - -i) - REPLACE=yes - ;; - esac +for arg; do + case $arg in + -i) + REPLACE=yes + ;; + esac done file=$arg [[ $REPLACE != yes ]] || { - [[ -z $(tail -c1 "$file") ]] || echo >> "$file" + [[ -z $(tail -c1 "$file") ]] || echo >>"$file" } exit 0 diff --git a/integrations/docker/images/chip-build/README.md b/integrations/docker/images/chip-build/README.md index 5488e0f3a7ee33..486d52f0f8a237 100644 --- a/integrations/docker/images/chip-build/README.md +++ b/integrations/docker/images/chip-build/README.md @@ -1,30 +1,31 @@ # Docker connectedhomeip:chip-build -connectedhomeip/chip-build is the name of the Docker image used by -CHIP for continuous integration and other builds. +connectedhomeip/chip-build is the name of the Docker image used by CHIP for +continuous integration and other builds. Contents of this directory: - * build.sh - utility for building (and optionally) tagging and pushing - the chip-build Docker image - * version - the semver-style version of the image in use for this branch - of CHIP - * Dockerfile - description of the image +- build.sh - utility for building (and optionally) tagging and pushing the + chip-build Docker image +- version - the semver-style version of the image in use for this branch of + CHIP +- Dockerfile - description of the image -Please update version when any required tooling is updated. Some rough guidelines: +Please update version when any required tooling is updated. Some rough +guidelines: - * Updating a tool? Increment dot version unless the tool has - a major version delta or a backward incompatibility - * Adding a tool? Increment minor version: e.g. 0.2.1 -> 0.3.0 - * Removing a tool? Increment major version: e.g. 1.2 -> 2.0 +- Updating a tool? Increment dot version unless the tool has a major version + delta or a backward incompatibility +- Adding a tool? Increment minor version: e.g. 0.2.1 -> 0.3.0 +- Removing a tool? Increment major version: e.g. 1.2 -> 2.0 Typical use: - 1. new build tool dependency identified - 2. add tool to Dockerfile - 3. update version - 4. `$ ./build.sh`, which installs the image locally as the new version - 5. verify that the build works locally in the new image - 6. `$ docker login` - 7. `$ ./build.sh --push --latest`, *_Note:_* omit `--latest` unless - on the master branch +1. new build tool dependency identified +2. add tool to Dockerfile +3. update version +4. `$ ./build.sh`, which installs the image locally as the new version +5. verify that the build works locally in the new image +6. `$ docker login` +7. `$ ./build.sh --push --latest`, _*Note:*_ omit `--latest` unless on the + master branch diff --git a/integrations/docker/run_build.sh b/integrations/docker/run_build.sh index 01ae3ce7df1e24..bbdcb6c33e6127 100755 --- a/integrations/docker/run_build.sh +++ b/integrations/docker/run_build.sh @@ -1,4 +1,4 @@ #!/usr/bin/env bash # This script assumes it's being run from the ToT -./bootstrap && mkdir -p build/default && (cd build/default && ../../configure --enable-coverage) && make -C build/default "${@:-distcheck}" && git clean -Xdf && (cd examples/lock-app/nrf5 && make) \ No newline at end of file +./bootstrap && mkdir -p build/default && (cd build/default && ../../configure --enable-coverage) && make -C build/default "${@:-distcheck}" && git clean -Xdf && (cd examples/lock-app/nrf5 && make) diff --git a/integrations/docker/run_docker_build.sh b/integrations/docker/run_docker_build.sh index 845ab1feb5923e..71b35dc5dc8151 100755 --- a/integrations/docker/run_docker_build.sh +++ b/integrations/docker/run_docker_build.sh @@ -6,10 +6,10 @@ here=$(cd "$(dirname "$0")" && pwd) # | # +---------------+ # V -SOURCE_PATH=$(cd "${here}/../.." && pwd) +SOURCE_PATH=$(cd "$here/../.." && pwd) ORGANIZATION="connectedhomeip" IMAGE="chip-build" -VERSION=$(cat "${here}/images/${IMAGE}/version") +VERSION=$(cat "$here/images/$IMAGE/version") -docker run --rm -w "${SOURCE_PATH}" -v "${SOURCE_PATH}:${SOURCE_PATH}" "${ORGANIZATION}/${IMAGE}:${VERSION}" integrations/docker/run_build.sh "${@:-distcheck}" +docker run --rm -w "$SOURCE_PATH" -v "$SOURCE_PATH:$SOURCE_PATH" "$ORGANIZATION/$IMAGE:$VERSION" integrations/docker/run_build.sh "${@:-distcheck}" diff --git a/integrations/github/actions/clang-tidy/action.yml b/integrations/github/actions/clang-tidy/action.yml index 0c6ca3021613c2..0433c5801c3512 100644 --- a/integrations/github/actions/clang-tidy/action.yml +++ b/integrations/github/actions/clang-tidy/action.yml @@ -1,21 +1,21 @@ name: "Clang Pull Request Tidy" description: "clang-tidy" inputs: - files_added: - description: "JSON list of files added" - required: false - files_modified: - description: "JSON list of files modified" - required: false - clang_arguments: - description: "Additional arguments to clang-tidy" - required: false + files_added: + description: "JSON list of files added" + required: false + files_modified: + description: "JSON list of files modified" + required: false + clang_arguments: + description: "Additional arguments to clang-tidy" + required: false outputs: - clang-result: - description: "Clang results path" + clang-result: + description: "Clang results path" runs: - using: "docker" - image: "Dockerfile" + using: "docker" + image: "Dockerfile" branding: - color: "blue" - icon: "shield" + color: "blue" + icon: "shield" diff --git a/integrations/github/actions/clang-tidy/run_clang.sh b/integrations/github/actions/clang-tidy/run_clang.sh index b007427fd5c087..10dc794a9da20b 100644 --- a/integrations/github/actions/clang-tidy/run_clang.sh +++ b/integrations/github/actions/clang-tidy/run_clang.sh @@ -7,45 +7,45 @@ echo "files modified: $FILES_MODIFIED" echo "files added: $FILES_ADDED" # convert to arrays -read -r -a FILES_MODIFIED <<< "$FILES_MODIFIED" -read -r -a FILES_ADDED <<< "$FILES_ADDED" +read -r -a FILES_MODIFIED <<<"$FILES_MODIFIED" +read -r -a FILES_ADDED <<<"$FILES_ADDED" # shellcheck disable=SC2206 -CLANG_TIDY_ARGUMENTS=( "${FILES_MODIFIED[@]}" "${FILES_ADDED[@]}" $CLANG_TIDY_ARGUMENTS ) +CLANG_TIDY_ARGUMENTS=("${FILES_MODIFIED[@]}" "${FILES_ADDED[@]}" "$CLANG_TIDY_ARGUMENTS") # nun clang-tidy -if clang-tidy "${CLANG_TIDY_ARGUMENTS[@]}" -export-fixes=fixes.yml > clang_output.txt; then - echo "Clang passed! Good job!" - echo ::set-output name=clang-result::"" +if clang-tidy "${CLANG_TIDY_ARGUMENTS[@]}" -export-fixes=fixes.yml >clang_output.txt; then + echo "Clang passed! Good job!" + echo ::set-output name=clang-result::"" else - CLANG_OUTPUT=$(cat clang_output.txt) - FIXES_OUTPUT=$(cat fixes.yml) + CLANG_OUTPUT=$(cat clang_output.txt) + FIXES_OUTPUT=$(cat fixes.yml) - # Cleanup the files we don't need - rm clang_output.txt - rm fixes.yml + # Cleanup the files we don't need + rm clang_output.txt + rm fixes.yml - PULL_REQUEST_COMMENT="" - PULL_REQUEST_COMMENT+=$'### Automated clang-tidy Review\n' + PULL_REQUEST_COMMENT="" + PULL_REQUEST_COMMENT+=$'### Automated clang-tidy Review\n' - PULL_REQUEST_COMMENT+=$'#### Clang Warnings & Errors\n' - PULL_REQUEST_COMMENT+=$'\n```\n' - PULL_REQUEST_COMMENT+="$CLANG_OUTPUT" - PULL_REQUEST_COMMENT+=$'\n```\n' + PULL_REQUEST_COMMENT+=$'#### Clang Warnings & Errors\n' + PULL_REQUEST_COMMENT+=$'\n```\n' + PULL_REQUEST_COMMENT+="$CLANG_OUTPUT" + PULL_REQUEST_COMMENT+=$'\n```\n' - PULL_REQUEST_COMMENT+=$'#### Recommended Fixes\n' - PULL_REQUEST_COMMENT+=$'\n```\n' - PULL_REQUEST_COMMENT+="$FIXES_OUTPUT" - PULL_REQUEST_COMMENT+=$'\n```\n' + PULL_REQUEST_COMMENT+=$'#### Recommended Fixes\n' + PULL_REQUEST_COMMENT+=$'\n```\n' + PULL_REQUEST_COMMENT+="$FIXES_OUTPUT" + PULL_REQUEST_COMMENT+=$'\n```\n' - PULL_REQUEST_COMMENT_URL=$(jq -r .pull_request.comments_url < "$GITHUB_EVENT_PATH") + PULL_REQUEST_COMMENT_URL=$(jq -r .pull_request.comments_url <"$GITHUB_EVENT_PATH") - echo ::set-output name=clang-result::"$CLANG_OUTPUT" + echo ::set-output name=clang-result::"$CLANG_OUTPUT" - if [[ -n $PULL_REQUEST_COMMENT_URL && ${str:?null} != null ]]; then - echo "Posting to comment URL: $PULL_REQUEST_COMMENT_URL" + if [[ -n $PULL_REQUEST_COMMENT_URL && ${str:?null} != null ]]; then + echo "Posting to comment URL: $PULL_REQUEST_COMMENT_URL" - REQUEST_DATA=$(echo '{}' | jq --arg body "$PULL_REQUEST_COMMENT" '.body = $body') - curl -s -S -H "Authorization: token $GITHUB_TOKEN" --header "Content-Type: application/vnd.github.VERSION.text+json" --data "$REQUEST_DATA" "$PULL_REQUEST_COMMENT_URL" - fi + REQUEST_DATA=$(echo '{}' | jq --arg body "$PULL_REQUEST_COMMENT" '.body = $body') + curl -s -S -H "Authorization: token $GITHUB_TOKEN" --header "Content-Type: application/vnd.github.VERSION.text+json" --data "$REQUEST_DATA" "$PULL_REQUEST_COMMENT_URL" + fi fi diff --git a/src/include/platform/CHIPDeviceConfig.h b/src/include/platform/CHIPDeviceConfig.h index 5bf7cc99e265d0..e6e5ae01f0f79e 100644 --- a/src/include/platform/CHIPDeviceConfig.h +++ b/src/include/platform/CHIPDeviceConfig.h @@ -22,8 +22,6 @@ * Defines compile-time configuration values for the chip Device Layer. */ - - #ifndef CHIP_DEVICE_CONFIG_H #define CHIP_DEVICE_CONFIG_H @@ -632,7 +630,6 @@ #define CHIP_DEVICE_CONFIG_ENABLE_FIXED_TUNNEL_SERVER 0 #endif - /** CHIP_DEVICE_CONFIG_TUNNEL_SERVER_ADDRESS * * The address of the server to which the device should establish a service tunnel. @@ -716,9 +713,9 @@ #endif // Enable Network Telemetry feature if it is enabled for at lease one network. -#define CHIP_DEVICE_CONFIG_ENABLE_NETWORK_TELEMETRY (CHIP_DEVICE_CONFIG_ENABLE_WIFI_TELEMETRY || \ - CHIP_DEVICE_CONFIG_ENABLE_THREAD_TELEMETRY || \ - CHIP_DEVICE_CONFIG_ENABLE_TUNNEL_TELEMETRY) +#define CHIP_DEVICE_CONFIG_ENABLE_NETWORK_TELEMETRY \ + (CHIP_DEVICE_CONFIG_ENABLE_WIFI_TELEMETRY || CHIP_DEVICE_CONFIG_ENABLE_THREAD_TELEMETRY || \ + CHIP_DEVICE_CONFIG_ENABLE_TUNNEL_TELEMETRY) /** * @def CHIP_DEVICE_CONFIG_DEFAULT_TELEMETRY_INTERVAL_MS @@ -808,7 +805,7 @@ * The event id counter persisted storage epoch. */ #ifndef CHIP_DEVICE_CONFIG_EVENT_ID_COUNTER_EPOCH -#define CHIP_DEVICE_CONFIG_EVENT_ID_COUNTER_EPOCH (0x10000) +#define CHIP_DEVICE_CONFIG_EVENT_ID_COUNTER_EPOCH (0x10000) #endif /** @@ -818,7 +815,7 @@ * The critical event id counter (eidc) persisted storage key. */ #ifndef CHIP_DEVICE_CONFIG_PERSISTED_STORAGE_CRIT_EIDC_KEY -#define CHIP_DEVICE_CONFIG_PERSISTED_STORAGE_CRIT_EIDC_KEY "crit-eidc" +#define CHIP_DEVICE_CONFIG_PERSISTED_STORAGE_CRIT_EIDC_KEY "crit-eidc" #endif /** @@ -828,7 +825,7 @@ * The production event id counter (eidc) persisted storage key. */ #ifndef CHIP_DEVICE_CONFIG_PERSISTED_STORAGE_PROD_EIDC_KEY -#define CHIP_DEVICE_CONFIG_PERSISTED_STORAGE_PROD_EIDC_KEY "prod-eidc" +#define CHIP_DEVICE_CONFIG_PERSISTED_STORAGE_PROD_EIDC_KEY "prod-eidc" #endif /** @@ -838,7 +835,7 @@ * The info event id counter (eidc) persisted storage key. */ #ifndef CHIP_DEVICE_CONFIG_PERSISTED_STORAGE_INFO_EIDC_KEY -#define CHIP_DEVICE_CONFIG_PERSISTED_STORAGE_INFO_EIDC_KEY "info-eidc" +#define CHIP_DEVICE_CONFIG_PERSISTED_STORAGE_INFO_EIDC_KEY "info-eidc" #endif /** @@ -848,7 +845,7 @@ * The debug event id counter (eidc) persisted storage key. */ #ifndef CHIP_DEVICE_CONFIG_PERSISTED_STORAGE_DEBUG_EIDC_KEY -#define CHIP_DEVICE_CONFIG_PERSISTED_STORAGE_DEBUG_EIDC_KEY "debug-eidc" +#define CHIP_DEVICE_CONFIG_PERSISTED_STORAGE_DEBUG_EIDC_KEY "debug-eidc" #endif // -------------------- Software Update Manager Configuration -------------------- @@ -934,7 +931,7 @@ * specify the max wait time interval to be used (in milliseconds) */ #ifndef CHIP_DEVICE_CONFIG_SOFTWARE_UPDATE_MAX_WAIT_TIME_INTERVAL_MS -#define CHIP_DEVICE_CONFIG_SOFTWARE_UPDATE_MAX_WAIT_TIME_INTERVAL_MS 1*60*60*1000 // 1 hour +#define CHIP_DEVICE_CONFIG_SOFTWARE_UPDATE_MAX_WAIT_TIME_INTERVAL_MS 1 * 60 * 60 * 1000 // 1 hour #endif /** @@ -961,7 +958,7 @@ * */ #ifndef CHIP_DEVICE_CONFIG_SWU_WAIT_TIME_MULTIPLIER_MS -#define CHIP_DEVICE_CONFIG_SWU_WAIT_TIME_MULTIPLIER_MS 1*60*1000 // 1 minute +#define CHIP_DEVICE_CONFIG_SWU_WAIT_TIME_MULTIPLIER_MS 1 * 60 * 1000 // 1 minute #endif /** @@ -969,6 +966,6 @@ * * Specifies the block size to be used during software download over BDX. */ -#define CHIP_DEVICE_CONFIG_SWU_BDX_BLOCK_SIZE 1024 +#define CHIP_DEVICE_CONFIG_SWU_BDX_BLOCK_SIZE 1024 #endif // CHIP_DEVICE_CONFIG_H diff --git a/src/include/platform/CHIPDeviceError.h b/src/include/platform/CHIPDeviceError.h index cca6f3d7eded69..282c617a1fc43c 100644 --- a/src/include/platform/CHIPDeviceError.h +++ b/src/include/platform/CHIPDeviceError.h @@ -19,7 +19,6 @@ #ifndef CHIP_DEVICE_ERROR_H #define CHIP_DEVICE_ERROR_H - #define CHIP_DEVICE_ERROR_MIN 11000000 #define CHIP_DEVICE_ERROR_MAX 11000999 #define _CHIP_DEVICE_ERROR(e) (CHIP_DEVICE_ERROR_MIN + (e)) @@ -31,7 +30,7 @@ * The requested configuration value was not found. * */ -#define CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND _CHIP_DEVICE_ERROR(1) +#define CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND _CHIP_DEVICE_ERROR(1) /** * @def CHIP_DEVICE_ERROR_NOT_SERVICE_PROVISIONED @@ -40,7 +39,7 @@ * The device has not been service provisioned. * */ -#define CHIP_DEVICE_ERROR_NOT_SERVICE_PROVISIONED _CHIP_DEVICE_ERROR(2) +#define CHIP_DEVICE_ERROR_NOT_SERVICE_PROVISIONED _CHIP_DEVICE_ERROR(2) /** * @def CHIP_DEVICE_ERROR_SOFTWARE_UPDATE_ABORTED @@ -49,7 +48,7 @@ * The software update was aborted by application * */ -#define CHIP_DEVICE_ERROR_SOFTWARE_UPDATE_ABORTED _CHIP_DEVICE_ERROR(3) +#define CHIP_DEVICE_ERROR_SOFTWARE_UPDATE_ABORTED _CHIP_DEVICE_ERROR(3) /** * @def CHIP_DEVICE_ERROR_SOFTWARE_UPDATE_IGNORED @@ -58,6 +57,6 @@ * The software update was ignored by application. * */ -#define CHIP_DEVICE_ERROR_SOFTWARE_UPDATE_IGNORED _CHIP_DEVICE_ERROR(4) +#define CHIP_DEVICE_ERROR_SOFTWARE_UPDATE_IGNORED _CHIP_DEVICE_ERROR(4) #endif // CHIP_DEVICE_ERROR_H diff --git a/src/include/platform/ConfigurationManager.h b/src/include/platform/ConfigurationManager.h index 701245d3b85a14..a99cf3fe8bc16c 100644 --- a/src/include/platform/ConfigurationManager.h +++ b/src/include/platform/ConfigurationManager.h @@ -31,7 +31,7 @@ namespace chip { namespace Ble { struct ChipBLEDeviceIdentificationInfo; } -} +} // namespace chip namespace chip { namespace DeviceLayer { @@ -39,7 +39,8 @@ namespace DeviceLayer { class PlatformManagerImpl; class ConfigurationManagerImpl; namespace Internal { -template class GenericPlatformManagerImpl; +template +class GenericPlatformManagerImpl; } /** @@ -48,13 +49,12 @@ template class GenericPlatformManagerImpl; class ConfigurationManager { public: - // ===== Members that define the public interface of the ConfigurationManager enum { - kMaxPairingCodeLength = 15, - kMaxSerialNumberLength = 32, + kMaxPairingCodeLength = 15, + kMaxSerialNumberLength = 32, kMaxFirmwareRevisionLength = 32, }; @@ -66,8 +66,8 @@ class ConfigurationManager CHIP_ERROR GetPrimary802154MACAddress(uint8_t * buf); CHIP_ERROR GetManufacturingDate(uint16_t & year, uint8_t & month, uint8_t & dayOfMonth); CHIP_ERROR GetFirmwareRevision(char * buf, size_t bufSize, size_t & outLen); - CHIP_ERROR GetFirmwareBuildTime(uint16_t & year, uint8_t & month, uint8_t & dayOfMonth, - uint8_t & hour, uint8_t & minute, uint8_t & second); + CHIP_ERROR GetFirmwareBuildTime(uint16_t & year, uint8_t & month, uint8_t & dayOfMonth, uint8_t & hour, uint8_t & minute, + uint8_t & second); CHIP_ERROR GetDeviceId(uint64_t & deviceId); CHIP_ERROR GetDeviceCertificate(uint8_t * buf, size_t bufSize, size_t & certLen); CHIP_ERROR GetDeviceIntermediateCACerts(uint8_t * buf, size_t bufSize, size_t & certsLen); @@ -99,7 +99,8 @@ class ConfigurationManager CHIP_ERROR StoreManufacturerDeviceIntermediateCACerts(const uint8_t * certs, size_t certsLen); CHIP_ERROR StoreManufacturerDevicePrivateKey(const uint8_t * key, size_t keyLen); CHIP_ERROR StorePairingCode(const char * pairingCode, size_t pairingCodeLen); - CHIP_ERROR StoreServiceProvisioningData(uint64_t serviceId, const uint8_t * serviceConfig, size_t serviceConfigLen, const char * accountId, size_t accountIdLen); + CHIP_ERROR StoreServiceProvisioningData(uint64_t serviceId, const uint8_t * serviceConfig, size_t serviceConfigLen, + const char * accountId, size_t accountIdLen); CHIP_ERROR ClearServiceProvisioningData(); CHIP_ERROR StoreServiceConfig(const uint8_t * serviceConfig, size_t serviceConfigLen); CHIP_ERROR StorePairedAccountId(const char * accountId, size_t accountIdLen); @@ -123,11 +124,11 @@ class ConfigurationManager CHIP_ERROR ComputeProvisioningHash(uint8_t * hashBuf, size_t hashBufSize); private: - // ===== Members for internal use by the following friends. friend class ::chip::DeviceLayer::PlatformManagerImpl; - template friend class ::chip::DeviceLayer::Internal::GenericPlatformManagerImpl; + template + friend class ::chip::DeviceLayer::Internal::GenericPlatformManagerImpl; // Parentheses used to fix clang parsing issue with these declarations friend CHIP_ERROR ::chip::Platform::PersistedStorage::Read(::chip::Platform::PersistedStorage::Key key, uint32_t & value); friend CHIP_ERROR ::chip::Platform::PersistedStorage::Write(::chip::Platform::PersistedStorage::Key key, uint32_t value); @@ -147,13 +148,12 @@ class ConfigurationManager #endif protected: - // Construction/destruction limited to subclasses. - ConfigurationManager() = default; + ConfigurationManager() = default; ~ConfigurationManager() = default; // No copy, move or assignment. - ConfigurationManager(const ConfigurationManager &) = delete; + ConfigurationManager(const ConfigurationManager &) = delete; ConfigurationManager(const ConfigurationManager &&) = delete; ConfigurationManager & operator=(const ConfigurationManager &) = delete; }; @@ -195,7 +195,7 @@ namespace DeviceLayer { */ inline CHIP_ERROR ConfigurationManager::GetVendorId(uint16_t & vendorId) { - return static_cast(this)->_GetVendorId(vendorId); + return static_cast(this)->_GetVendorId(vendorId); } /** @@ -203,7 +203,7 @@ inline CHIP_ERROR ConfigurationManager::GetVendorId(uint16_t & vendorId) */ inline CHIP_ERROR ConfigurationManager::GetProductId(uint16_t & productId) { - return static_cast(this)->_GetProductId(productId); + return static_cast(this)->_GetProductId(productId); } /** @@ -211,299 +211,302 @@ inline CHIP_ERROR ConfigurationManager::GetProductId(uint16_t & productId) */ inline CHIP_ERROR ConfigurationManager::GetProductRevision(uint16_t & productRev) { - return static_cast(this)->_GetProductRevision(productRev); + return static_cast(this)->_GetProductRevision(productRev); } inline CHIP_ERROR ConfigurationManager::GetSerialNumber(char * buf, size_t bufSize, size_t & serialNumLen) { - return static_cast(this)->_GetSerialNumber(buf, bufSize, serialNumLen); + return static_cast(this)->_GetSerialNumber(buf, bufSize, serialNumLen); } inline CHIP_ERROR ConfigurationManager::GetPrimaryWiFiMACAddress(uint8_t * buf) { - return static_cast(this)->_GetPrimaryWiFiMACAddress(buf); + return static_cast(this)->_GetPrimaryWiFiMACAddress(buf); } inline CHIP_ERROR ConfigurationManager::GetPrimary802154MACAddress(uint8_t * buf) { - return static_cast(this)->_GetPrimary802154MACAddress(buf); + return static_cast(this)->_GetPrimary802154MACAddress(buf); } inline CHIP_ERROR ConfigurationManager::GetManufacturingDate(uint16_t & year, uint8_t & month, uint8_t & dayOfMonth) { - return static_cast(this)->_GetManufacturingDate(year, month, dayOfMonth); + return static_cast(this)->_GetManufacturingDate(year, month, dayOfMonth); } inline CHIP_ERROR ConfigurationManager::GetFirmwareRevision(char * buf, size_t bufSize, size_t & outLen) { - return static_cast(this)->_GetFirmwareRevision(buf, bufSize, outLen); + return static_cast(this)->_GetFirmwareRevision(buf, bufSize, outLen); } -inline CHIP_ERROR ConfigurationManager::GetFirmwareBuildTime(uint16_t & year, uint8_t & month, uint8_t & dayOfMonth, - uint8_t & hour, uint8_t & minute, uint8_t & second) +inline CHIP_ERROR ConfigurationManager::GetFirmwareBuildTime(uint16_t & year, uint8_t & month, uint8_t & dayOfMonth, uint8_t & hour, + uint8_t & minute, uint8_t & second) { - return static_cast(this)->_GetFirmwareBuildTime(year, month, dayOfMonth, hour, minute, second); + return static_cast(this)->_GetFirmwareBuildTime(year, month, dayOfMonth, hour, minute, second); } inline CHIP_ERROR ConfigurationManager::GetDeviceId(uint64_t & deviceId) { - return static_cast(this)->_GetDeviceId(deviceId); + return static_cast(this)->_GetDeviceId(deviceId); } inline CHIP_ERROR ConfigurationManager::GetDeviceCertificate(uint8_t * buf, size_t bufSize, size_t & certLen) { - return static_cast(this)->_GetDeviceCertificate(buf, bufSize, certLen); + return static_cast(this)->_GetDeviceCertificate(buf, bufSize, certLen); } inline CHIP_ERROR ConfigurationManager::GetDeviceIntermediateCACerts(uint8_t * buf, size_t bufSize, size_t & certsLen) { - return static_cast(this)->_GetDeviceIntermediateCACerts(buf, bufSize, certsLen); + return static_cast(this)->_GetDeviceIntermediateCACerts(buf, bufSize, certsLen); } inline CHIP_ERROR ConfigurationManager::GetDevicePrivateKey(uint8_t * buf, size_t bufSize, size_t & keyLen) { - return static_cast(this)->_GetDevicePrivateKey(buf, bufSize, keyLen); + return static_cast(this)->_GetDevicePrivateKey(buf, bufSize, keyLen); } inline CHIP_ERROR ConfigurationManager::GetManufacturerDeviceId(uint64_t & deviceId) { - return static_cast(this)->_GetManufacturerDeviceId(deviceId); + return static_cast(this)->_GetManufacturerDeviceId(deviceId); } inline CHIP_ERROR ConfigurationManager::GetManufacturerDeviceCertificate(uint8_t * buf, size_t bufSize, size_t & certLen) { - return static_cast(this)->_GetManufacturerDeviceCertificate(buf, bufSize, certLen); + return static_cast(this)->_GetManufacturerDeviceCertificate(buf, bufSize, certLen); } inline CHIP_ERROR ConfigurationManager::GetManufacturerDeviceIntermediateCACerts(uint8_t * buf, size_t bufSize, size_t & certsLen) { - return static_cast(this)->_GetManufacturerDeviceIntermediateCACerts(buf, bufSize, certsLen); + return static_cast(this)->_GetManufacturerDeviceIntermediateCACerts(buf, bufSize, certsLen); } inline CHIP_ERROR ConfigurationManager::GetManufacturerDevicePrivateKey(uint8_t * buf, size_t bufSize, size_t & keyLen) { - return static_cast(this)->_GetManufacturerDevicePrivateKey(buf, bufSize, keyLen); + return static_cast(this)->_GetManufacturerDevicePrivateKey(buf, bufSize, keyLen); } inline CHIP_ERROR ConfigurationManager::GetPairingCode(char * buf, size_t bufSize, size_t & pairingCodeLen) { - return static_cast(this)->_GetPairingCode(buf, bufSize, pairingCodeLen); + return static_cast(this)->_GetPairingCode(buf, bufSize, pairingCodeLen); } inline CHIP_ERROR ConfigurationManager::GetServiceId(uint64_t & serviceId) { - return static_cast(this)->_GetServiceId(serviceId); + return static_cast(this)->_GetServiceId(serviceId); } inline CHIP_ERROR ConfigurationManager::GetFabricId(uint64_t & fabricId) { - return static_cast(this)->_GetFabricId(fabricId); + return static_cast(this)->_GetFabricId(fabricId); } inline CHIP_ERROR ConfigurationManager::GetServiceConfig(uint8_t * buf, size_t bufSize, size_t & serviceConfigLen) { - return static_cast(this)->_GetServiceConfig(buf, bufSize, serviceConfigLen); + return static_cast(this)->_GetServiceConfig(buf, bufSize, serviceConfigLen); } inline CHIP_ERROR ConfigurationManager::GetPairedAccountId(char * buf, size_t bufSize, size_t & accountIdLen) { - return static_cast(this)->_GetPairedAccountId(buf, bufSize, accountIdLen); + return static_cast(this)->_GetPairedAccountId(buf, bufSize, accountIdLen); } inline CHIP_ERROR ConfigurationManager::StoreSerialNumber(const char * serialNum, size_t serialNumLen) { - return static_cast(this)->_StoreSerialNumber(serialNum, serialNumLen); + return static_cast(this)->_StoreSerialNumber(serialNum, serialNumLen); } inline CHIP_ERROR ConfigurationManager::StorePrimaryWiFiMACAddress(const uint8_t * buf) { - return static_cast(this)->_StorePrimaryWiFiMACAddress(buf); + return static_cast(this)->_StorePrimaryWiFiMACAddress(buf); } inline CHIP_ERROR ConfigurationManager::StorePrimary802154MACAddress(const uint8_t * buf) { - return static_cast(this)->_StorePrimary802154MACAddress(buf); + return static_cast(this)->_StorePrimary802154MACAddress(buf); } inline CHIP_ERROR ConfigurationManager::StoreManufacturingDate(const char * mfgDate, size_t mfgDateLen) { - return static_cast(this)->_StoreManufacturingDate(mfgDate, mfgDateLen); + return static_cast(this)->_StoreManufacturingDate(mfgDate, mfgDateLen); } inline CHIP_ERROR ConfigurationManager::StoreProductRevision(uint16_t productRev) { - return static_cast(this)->_StoreProductRevision(productRev); + return static_cast(this)->_StoreProductRevision(productRev); } inline CHIP_ERROR ConfigurationManager::StoreFabricId(uint64_t fabricId) { - return static_cast(this)->_StoreFabricId(fabricId); + return static_cast(this)->_StoreFabricId(fabricId); } #if CHIP_DEVICE_CONFIG_ENABLE_JUST_IN_TIME_PROVISIONING inline CHIP_ERROR ConfigurationManager::StoreDeviceId(uint64_t deviceId) { - return static_cast(this)->_StoreDeviceId(deviceId); + return static_cast(this)->_StoreDeviceId(deviceId); } inline CHIP_ERROR ConfigurationManager::StoreDeviceCertificate(const uint8_t * cert, size_t certLen) { - return static_cast(this)->_StoreDeviceCertificate(cert, certLen); + return static_cast(this)->_StoreDeviceCertificate(cert, certLen); } inline CHIP_ERROR ConfigurationManager::StoreDeviceIntermediateCACerts(const uint8_t * certs, size_t certsLen) { - return static_cast(this)->_StoreDeviceIntermediateCACerts(certs, certsLen); + return static_cast(this)->_StoreDeviceIntermediateCACerts(certs, certsLen); } inline CHIP_ERROR ConfigurationManager::StoreDevicePrivateKey(const uint8_t * key, size_t keyLen) { - return static_cast(this)->_StoreDevicePrivateKey(key, keyLen); + return static_cast(this)->_StoreDevicePrivateKey(key, keyLen); } #endif // CHIP_DEVICE_CONFIG_ENABLE_JUST_IN_TIME_PROVISIONING inline CHIP_ERROR ConfigurationManager::StoreManufacturerDeviceId(uint64_t deviceId) { - return static_cast(this)->_StoreManufacturerDeviceId(deviceId); + return static_cast(this)->_StoreManufacturerDeviceId(deviceId); } inline CHIP_ERROR ConfigurationManager::StoreManufacturerDeviceCertificate(const uint8_t * cert, size_t certLen) { - return static_cast(this)->_StoreManufacturerDeviceCertificate(cert, certLen); + return static_cast(this)->_StoreManufacturerDeviceCertificate(cert, certLen); } inline CHIP_ERROR ConfigurationManager::StoreManufacturerDeviceIntermediateCACerts(const uint8_t * certs, size_t certsLen) { - return static_cast(this)->_StoreManufacturerDeviceIntermediateCACerts(certs, certsLen); + return static_cast(this)->_StoreManufacturerDeviceIntermediateCACerts(certs, certsLen); } inline CHIP_ERROR ConfigurationManager::StoreManufacturerDevicePrivateKey(const uint8_t * key, size_t keyLen) { - return static_cast(this)->_StoreManufacturerDevicePrivateKey(key, keyLen); + return static_cast(this)->_StoreManufacturerDevicePrivateKey(key, keyLen); } inline CHIP_ERROR ConfigurationManager::StorePairingCode(const char * pairingCode, size_t pairingCodeLen) { - return static_cast(this)->_StorePairingCode(pairingCode, pairingCodeLen); + return static_cast(this)->_StorePairingCode(pairingCode, pairingCodeLen); } -inline CHIP_ERROR ConfigurationManager::StoreServiceProvisioningData(uint64_t serviceId, const uint8_t * serviceConfig, size_t serviceConfigLen, const char * accountId, size_t accountIdLen) +inline CHIP_ERROR ConfigurationManager::StoreServiceProvisioningData(uint64_t serviceId, const uint8_t * serviceConfig, + size_t serviceConfigLen, const char * accountId, + size_t accountIdLen) { - return static_cast(this)->_StoreServiceProvisioningData(serviceId, serviceConfig, serviceConfigLen, accountId, accountIdLen); + return static_cast(this)->_StoreServiceProvisioningData(serviceId, serviceConfig, serviceConfigLen, accountId, + accountIdLen); } inline CHIP_ERROR ConfigurationManager::ClearServiceProvisioningData() { - return static_cast(this)->_ClearServiceProvisioningData(); + return static_cast(this)->_ClearServiceProvisioningData(); } inline CHIP_ERROR ConfigurationManager::StoreServiceConfig(const uint8_t * serviceConfig, size_t serviceConfigLen) { - return static_cast(this)->_StoreServiceConfig(serviceConfig, serviceConfigLen); + return static_cast(this)->_StoreServiceConfig(serviceConfig, serviceConfigLen); } inline CHIP_ERROR ConfigurationManager::StorePairedAccountId(const char * accountId, size_t accountIdLen) { - return static_cast(this)->_StorePairedAccountId(accountId, accountIdLen); + return static_cast(this)->_StorePairedAccountId(accountId, accountIdLen); } inline CHIP_ERROR ConfigurationManager::ReadPersistedStorageValue(::chip::Platform::PersistedStorage::Key key, uint32_t & value) { - return static_cast(this)->_ReadPersistedStorageValue(key, value); + return static_cast(this)->_ReadPersistedStorageValue(key, value); } inline CHIP_ERROR ConfigurationManager::WritePersistedStorageValue(::chip::Platform::PersistedStorage::Key key, uint32_t value) { - return static_cast(this)->_WritePersistedStorageValue(key, value); + return static_cast(this)->_WritePersistedStorageValue(key, value); } inline CHIP_ERROR ConfigurationManager::GetQRCodeString(char * buf, size_t bufSize) { - return static_cast(this)->_GetQRCodeString(buf, bufSize); + return static_cast(this)->_GetQRCodeString(buf, bufSize); } inline CHIP_ERROR ConfigurationManager::GetWiFiAPSSID(char * buf, size_t bufSize) { - return static_cast(this)->_GetWiFiAPSSID(buf, bufSize); + return static_cast(this)->_GetWiFiAPSSID(buf, bufSize); } inline CHIP_ERROR ConfigurationManager::GetBLEDeviceIdentificationInfo(Ble::ChipBLEDeviceIdentificationInfo & deviceIdInfo) { - return static_cast(this)->_GetBLEDeviceIdentificationInfo(deviceIdInfo); + return static_cast(this)->_GetBLEDeviceIdentificationInfo(deviceIdInfo); } inline bool ConfigurationManager::IsServiceProvisioned() { - return static_cast(this)->_IsServiceProvisioned(); + return static_cast(this)->_IsServiceProvisioned(); } inline bool ConfigurationManager::IsPairedToAccount() { - return static_cast(this)->_IsPairedToAccount(); + return static_cast(this)->_IsPairedToAccount(); } inline bool ConfigurationManager::IsMemberOfFabric() { - return static_cast(this)->_IsMemberOfFabric(); + return static_cast(this)->_IsMemberOfFabric(); } inline bool ConfigurationManager::IsFullyProvisioned() { - return static_cast(this)->_IsFullyProvisioned(); + return static_cast(this)->_IsFullyProvisioned(); } inline void ConfigurationManager::InitiateFactoryReset() { - static_cast(this)->_InitiateFactoryReset(); + static_cast(this)->_InitiateFactoryReset(); } inline CHIP_ERROR ConfigurationManager::ComputeProvisioningHash(uint8_t * hashBuf, size_t hashBufSize) { - return static_cast(this)->_ComputeProvisioningHash(hashBuf, hashBufSize); + return static_cast(this)->_ComputeProvisioningHash(hashBuf, hashBufSize); } inline CHIP_ERROR ConfigurationManager::Init() { - return static_cast(this)->_Init(); + return static_cast(this)->_Init(); } inline CHIP_ERROR ConfigurationManager::ConfigureChipStack() { - return static_cast(this)->_ConfigureChipStack(); + return static_cast(this)->_ConfigureChipStack(); } inline bool ConfigurationManager::CanFactoryReset() { - return static_cast(this)->_CanFactoryReset(); + return static_cast(this)->_CanFactoryReset(); } inline CHIP_ERROR ConfigurationManager::GetFailSafeArmed(bool & val) { - return static_cast(this)->_GetFailSafeArmed(val); + return static_cast(this)->_GetFailSafeArmed(val); } inline CHIP_ERROR ConfigurationManager::SetFailSafeArmed(bool val) { - return static_cast(this)->_SetFailSafeArmed(val); + return static_cast(this)->_SetFailSafeArmed(val); } #if CHIP_DEVICE_CONFIG_ENABLE_JUST_IN_TIME_PROVISIONING inline bool ConfigurationManager::OperationalDeviceCredentialsProvisioned() { - return static_cast(this)->_OperationalDeviceCredentialsProvisioned(); + return static_cast(this)->_OperationalDeviceCredentialsProvisioned(); } inline CHIP_ERROR ConfigurationManager::ClearOperationalDeviceCredentials(void) { - return static_cast(this)->_ClearOperationalDeviceCredentials(); + return static_cast(this)->_ClearOperationalDeviceCredentials(); } inline void ConfigurationManager::UseManufacturerCredentialsAsOperational(bool val) { - static_cast(this)->_UseManufacturerCredentialsAsOperational(val); + static_cast(this)->_UseManufacturerCredentialsAsOperational(val); } #endif // CHIP_DEVICE_CONFIG_ENABLE_JUST_IN_TIME_PROVISIONING diff --git a/src/include/platform/ConnectivityManager.h b/src/include/platform/ConnectivityManager.h index 9349ad87a4a1d2..153b207915562e 100644 --- a/src/include/platform/ConnectivityManager.h +++ b/src/include/platform/ConnectivityManager.h @@ -29,9 +29,12 @@ namespace DeviceLayer { namespace Internal { class NetworkProvisioningServerImpl; -template class GenericNetworkProvisioningServerImpl; -template class GenericPlatformManagerImpl; -template class GenericPlatformManagerImpl_FreeRTOS; +template +class GenericNetworkProvisioningServerImpl; +template +class GenericPlatformManagerImpl; +template +class GenericPlatformManagerImpl_FreeRTOS; } // namespace Internal class ConnectivityManagerImpl; @@ -44,56 +47,55 @@ class ConnectivityManager using ImplClass = ::chip::DeviceLayer::ConnectivityManagerImpl; public: - // ===== Members that define the public interface of the ConnectivityManager enum WiFiStationMode { - kWiFiStationMode_NotSupported = 0, - kWiFiStationMode_ApplicationControlled = 1, - kWiFiStationMode_Disabled = 2, - kWiFiStationMode_Enabled = 3, + kWiFiStationMode_NotSupported = 0, + kWiFiStationMode_ApplicationControlled = 1, + kWiFiStationMode_Disabled = 2, + kWiFiStationMode_Enabled = 3, }; enum WiFiAPMode { - kWiFiAPMode_NotSupported = 0, - kWiFiAPMode_ApplicationControlled = 1, - kWiFiAPMode_Disabled = 2, - kWiFiAPMode_Enabled = 3, - kWiFiAPMode_OnDemand = 4, - kWiFiAPMode_OnDemand_NoStationProvision = 5, + kWiFiAPMode_NotSupported = 0, + kWiFiAPMode_ApplicationControlled = 1, + kWiFiAPMode_Disabled = 2, + kWiFiAPMode_Enabled = 3, + kWiFiAPMode_OnDemand = 4, + kWiFiAPMode_OnDemand_NoStationProvision = 5, }; enum ThreadMode { - kThreadMode_NotSupported = 0, - kThreadMode_ApplicationControlled = 1, - kThreadMode_Disabled = 2, - kThreadMode_Enabled = 3, + kThreadMode_NotSupported = 0, + kThreadMode_ApplicationControlled = 1, + kThreadMode_Disabled = 2, + kThreadMode_Enabled = 3, }; enum ServiceTunnelMode { - kServiceTunnelMode_NotSupported = 0, - kServiceTunnelMode_Disabled = 1, - kServiceTunnelMode_Enabled = 2, + kServiceTunnelMode_NotSupported = 0, + kServiceTunnelMode_Disabled = 1, + kServiceTunnelMode_Enabled = 2, }; enum CHIPoBLEServiceMode { - kCHIPoBLEServiceMode_NotSupported = 0, - kCHIPoBLEServiceMode_Enabled = 1, - kCHIPoBLEServiceMode_Disabled = 2, + kCHIPoBLEServiceMode_NotSupported = 0, + kCHIPoBLEServiceMode_Enabled = 1, + kCHIPoBLEServiceMode_Disabled = 2, }; enum ThreadDeviceType { - kThreadDeviceType_NotSupported = 0, - kThreadDeviceType_Router = 1, - kThreadDeviceType_FullEndDevice = 2, - kThreadDeviceType_MinimalEndDevice = 3, - kThreadDeviceType_SleepyEndDevice = 4, + kThreadDeviceType_NotSupported = 0, + kThreadDeviceType_Router = 1, + kThreadDeviceType_FullEndDevice = 2, + kThreadDeviceType_MinimalEndDevice = 3, + kThreadDeviceType_SleepyEndDevice = 4, }; struct ThreadPollingConfig; @@ -174,14 +176,16 @@ class ConnectivityManager static const char * CHIPoBLEServiceModeToStr(CHIPoBLEServiceMode mode); private: - // ===== Members for internal use by the following friends. friend class PlatformManagerImpl; - template friend class Internal::GenericPlatformManagerImpl; - template friend class Internal::GenericPlatformManagerImpl_FreeRTOS; + template + friend class Internal::GenericPlatformManagerImpl; + template + friend class Internal::GenericPlatformManagerImpl_FreeRTOS; friend class Internal::NetworkProvisioningServerImpl; - template friend class Internal::GenericNetworkProvisioningServerImpl; + template + friend class Internal::GenericNetworkProvisioningServerImpl; CHIP_ERROR Init(void); void OnPlatformEvent(const ChipDeviceEvent * event); @@ -190,13 +194,12 @@ class ConnectivityManager void OnWiFiStationProvisionChange(void); protected: - // Construction/destruction limited to subclasses. - ConnectivityManager() = default; + ConnectivityManager() = default; ~ConnectivityManager() = default; // No copy, move or assignment. - ConnectivityManager(const ConnectivityManager &) = delete; + ConnectivityManager(const ConnectivityManager &) = delete; ConnectivityManager(const ConnectivityManager &&) = delete; ConnectivityManager & operator=(const ConnectivityManager &) = delete; }; @@ -206,18 +209,17 @@ class ConnectivityManager */ struct ConnectivityManager::ThreadPollingConfig { - uint32_t ActivePollingIntervalMS; /**< Interval at which the device polls its parent Thread router when - when there are active chip exchanges in progress. Only meaningful - when the device is acting as a sleepy end node. */ + uint32_t ActivePollingIntervalMS; /**< Interval at which the device polls its parent Thread router when + when there are active chip exchanges in progress. Only meaningful + when the device is acting as a sleepy end node. */ - uint32_t InactivePollingIntervalMS; /**< Interval at which the device polls its parent Thread router when - when there are NO active chip exchanges in progress. Only meaningful - when the device is acting as a sleepy end node. */ + uint32_t InactivePollingIntervalMS; /**< Interval at which the device polls its parent Thread router when + when there are NO active chip exchanges in progress. Only meaningful + when the device is acting as a sleepy end node. */ void Clear() { memset(this, 0, sizeof(*this)); } }; - /** * Returns a reference to the public interface of the ConnectivityManager singleton object. * @@ -237,7 +239,6 @@ extern ConnectivityManagerImpl & ConnectivityMgrImpl(void); } // namespace DeviceLayer } // namespace chip - /* Include a header file containing the implementation of the ConfigurationManager * object for the selected platform. */ @@ -248,273 +249,272 @@ extern ConnectivityManagerImpl & ConnectivityMgrImpl(void); #include CONNECTIVITYMANAGERIMPL_HEADER #endif - namespace chip { namespace DeviceLayer { inline ConnectivityManager::WiFiStationMode ConnectivityManager::GetWiFiStationMode(void) { - return static_cast(this)->_GetWiFiStationMode(); + return static_cast(this)->_GetWiFiStationMode(); } inline CHIP_ERROR ConnectivityManager::SetWiFiStationMode(WiFiStationMode val) { - return static_cast(this)->_SetWiFiStationMode(val); + return static_cast(this)->_SetWiFiStationMode(val); } inline bool ConnectivityManager::IsWiFiStationEnabled(void) { - return static_cast(this)->_IsWiFiStationEnabled(); + return static_cast(this)->_IsWiFiStationEnabled(); } inline bool ConnectivityManager::IsWiFiStationApplicationControlled(void) { - return static_cast(this)->_IsWiFiStationApplicationControlled(); + return static_cast(this)->_IsWiFiStationApplicationControlled(); } inline bool ConnectivityManager::IsWiFiStationConnected(void) { - return static_cast(this)->_IsWiFiStationConnected(); + return static_cast(this)->_IsWiFiStationConnected(); } inline uint32_t ConnectivityManager::GetWiFiStationReconnectIntervalMS(void) { - return static_cast(this)->_GetWiFiStationReconnectIntervalMS(); + return static_cast(this)->_GetWiFiStationReconnectIntervalMS(); } inline CHIP_ERROR ConnectivityManager::SetWiFiStationReconnectIntervalMS(uint32_t val) { - return static_cast(this)->_SetWiFiStationReconnectIntervalMS(val); + return static_cast(this)->_SetWiFiStationReconnectIntervalMS(val); } inline bool ConnectivityManager::IsWiFiStationProvisioned(void) { - return static_cast(this)->_IsWiFiStationProvisioned(); + return static_cast(this)->_IsWiFiStationProvisioned(); } inline void ConnectivityManager::ClearWiFiStationProvision(void) { - static_cast(this)->_ClearWiFiStationProvision(); + static_cast(this)->_ClearWiFiStationProvision(); } inline ConnectivityManager::WiFiAPMode ConnectivityManager::GetWiFiAPMode(void) { - return static_cast(this)->_GetWiFiAPMode(); + return static_cast(this)->_GetWiFiAPMode(); } inline CHIP_ERROR ConnectivityManager::SetWiFiAPMode(WiFiAPMode val) { - return static_cast(this)->_SetWiFiAPMode(val); + return static_cast(this)->_SetWiFiAPMode(val); } inline bool ConnectivityManager::IsWiFiAPActive(void) { - return static_cast(this)->_IsWiFiAPActive(); + return static_cast(this)->_IsWiFiAPActive(); } inline bool ConnectivityManager::IsWiFiAPApplicationControlled(void) { - return static_cast(this)->_IsWiFiAPApplicationControlled(); + return static_cast(this)->_IsWiFiAPApplicationControlled(); } inline void ConnectivityManager::DemandStartWiFiAP(void) { - static_cast(this)->_DemandStartWiFiAP(); + static_cast(this)->_DemandStartWiFiAP(); } inline void ConnectivityManager::StopOnDemandWiFiAP(void) { - static_cast(this)->_StopOnDemandWiFiAP(); + static_cast(this)->_StopOnDemandWiFiAP(); } inline void ConnectivityManager::MaintainOnDemandWiFiAP(void) { - static_cast(this)->_MaintainOnDemandWiFiAP(); + static_cast(this)->_MaintainOnDemandWiFiAP(); } inline uint32_t ConnectivityManager::GetWiFiAPIdleTimeoutMS(void) { - return static_cast(this)->_GetWiFiAPIdleTimeoutMS(); + return static_cast(this)->_GetWiFiAPIdleTimeoutMS(); } inline void ConnectivityManager::SetWiFiAPIdleTimeoutMS(uint32_t val) { - static_cast(this)->_SetWiFiAPIdleTimeoutMS(val); + static_cast(this)->_SetWiFiAPIdleTimeoutMS(val); } inline CHIP_ERROR ConnectivityManager::GetAndLogWifiStatsCounters(void) { - return static_cast(this)->_GetAndLogWifiStatsCounters(); + return static_cast(this)->_GetAndLogWifiStatsCounters(); } inline bool ConnectivityManager::HaveServiceConnectivityViaTunnel(void) { - return static_cast(this)->_HaveServiceConnectivityViaTunnel(); + return static_cast(this)->_HaveServiceConnectivityViaTunnel(); } inline bool ConnectivityManager::HaveIPv4InternetConnectivity(void) { - return static_cast(this)->_HaveIPv4InternetConnectivity(); + return static_cast(this)->_HaveIPv4InternetConnectivity(); } inline bool ConnectivityManager::HaveIPv6InternetConnectivity(void) { - return static_cast(this)->_HaveIPv6InternetConnectivity(); + return static_cast(this)->_HaveIPv6InternetConnectivity(); } inline ConnectivityManager::ServiceTunnelMode ConnectivityManager::GetServiceTunnelMode(void) { - return static_cast(this)->_GetServiceTunnelMode(); + return static_cast(this)->_GetServiceTunnelMode(); } inline CHIP_ERROR ConnectivityManager::SetServiceTunnelMode(ServiceTunnelMode val) { - return static_cast(this)->_SetServiceTunnelMode(val); + return static_cast(this)->_SetServiceTunnelMode(val); } inline bool ConnectivityManager::IsServiceTunnelConnected(void) { - return static_cast(this)->_IsServiceTunnelConnected(); + return static_cast(this)->_IsServiceTunnelConnected(); } inline bool ConnectivityManager::IsServiceTunnelRestricted(void) { - return static_cast(this)->_IsServiceTunnelRestricted(); + return static_cast(this)->_IsServiceTunnelRestricted(); } inline bool ConnectivityManager::HaveServiceConnectivity(void) { - return static_cast(this)->_HaveServiceConnectivity(); + return static_cast(this)->_HaveServiceConnectivity(); } inline ConnectivityManager::ThreadMode ConnectivityManager::GetThreadMode(void) { - return static_cast(this)->_GetThreadMode(); + return static_cast(this)->_GetThreadMode(); } inline CHIP_ERROR ConnectivityManager::SetThreadMode(ThreadMode val) { - return static_cast(this)->_SetThreadMode(val); + return static_cast(this)->_SetThreadMode(val); } inline bool ConnectivityManager::IsThreadEnabled(void) { - return static_cast(this)->_IsThreadEnabled(); + return static_cast(this)->_IsThreadEnabled(); } inline bool ConnectivityManager::IsThreadApplicationControlled(void) { - return static_cast(this)->_IsThreadApplicationControlled(); + return static_cast(this)->_IsThreadApplicationControlled(); } inline ConnectivityManager::ThreadDeviceType ConnectivityManager::GetThreadDeviceType(void) { - return static_cast(this)->_GetThreadDeviceType(); + return static_cast(this)->_GetThreadDeviceType(); } inline CHIP_ERROR ConnectivityManager::SetThreadDeviceType(ThreadDeviceType deviceType) { - return static_cast(this)->_SetThreadDeviceType(deviceType); + return static_cast(this)->_SetThreadDeviceType(deviceType); } inline void ConnectivityManager::GetThreadPollingConfig(ThreadPollingConfig & pollingConfig) { - return static_cast(this)->_GetThreadPollingConfig(pollingConfig); + return static_cast(this)->_GetThreadPollingConfig(pollingConfig); } inline CHIP_ERROR ConnectivityManager::SetThreadPollingConfig(const ThreadPollingConfig & pollingConfig) { - return static_cast(this)->_SetThreadPollingConfig(pollingConfig); + return static_cast(this)->_SetThreadPollingConfig(pollingConfig); } inline bool ConnectivityManager::IsThreadAttached(void) { - return static_cast(this)->_IsThreadAttached(); + return static_cast(this)->_IsThreadAttached(); } inline bool ConnectivityManager::IsThreadProvisioned(void) { - return static_cast(this)->_IsThreadProvisioned(); + return static_cast(this)->_IsThreadProvisioned(); } inline void ConnectivityManager::ClearThreadProvision(void) { - static_cast(this)->_ClearThreadProvision(); + static_cast(this)->_ClearThreadProvision(); } inline bool ConnectivityManager::HaveServiceConnectivityViaThread(void) { - return static_cast(this)->_HaveServiceConnectivityViaThread(); + return static_cast(this)->_HaveServiceConnectivityViaThread(); } inline ConnectivityManager::CHIPoBLEServiceMode ConnectivityManager::GetCHIPoBLEServiceMode(void) { - return static_cast(this)->_GetCHIPoBLEServiceMode(); + return static_cast(this)->_GetCHIPoBLEServiceMode(); } inline CHIP_ERROR ConnectivityManager::SetCHIPoBLEServiceMode(CHIPoBLEServiceMode val) { - return static_cast(this)->_SetCHIPoBLEServiceMode(val); + return static_cast(this)->_SetCHIPoBLEServiceMode(val); } inline bool ConnectivityManager::IsBLEAdvertisingEnabled(void) { - return static_cast(this)->_IsBLEAdvertisingEnabled(); + return static_cast(this)->_IsBLEAdvertisingEnabled(); } inline CHIP_ERROR ConnectivityManager::SetBLEAdvertisingEnabled(bool val) { - return static_cast(this)->_SetBLEAdvertisingEnabled(val); + return static_cast(this)->_SetBLEAdvertisingEnabled(val); } inline bool ConnectivityManager::IsBLEFastAdvertisingEnabled(void) { - return static_cast(this)->_IsBLEFastAdvertisingEnabled(); + return static_cast(this)->_IsBLEFastAdvertisingEnabled(); } inline CHIP_ERROR ConnectivityManager::SetBLEFastAdvertisingEnabled(bool val) { - return static_cast(this)->_SetBLEFastAdvertisingEnabled(val); + return static_cast(this)->_SetBLEFastAdvertisingEnabled(val); } inline bool ConnectivityManager::IsBLEAdvertising(void) { - return static_cast(this)->_IsBLEAdvertising(); + return static_cast(this)->_IsBLEAdvertising(); } inline CHIP_ERROR ConnectivityManager::GetBLEDeviceName(char * buf, size_t bufSize) { - return static_cast(this)->_GetBLEDeviceName(buf, bufSize); + return static_cast(this)->_GetBLEDeviceName(buf, bufSize); } inline CHIP_ERROR ConnectivityManager::SetBLEDeviceName(const char * deviceName) { - return static_cast(this)->_SetBLEDeviceName(deviceName); + return static_cast(this)->_SetBLEDeviceName(deviceName); } inline uint16_t ConnectivityManager::NumBLEConnections(void) { - return static_cast(this)->_NumBLEConnections(); + return static_cast(this)->_NumBLEConnections(); } inline bool ConnectivityManager::IsUserSelectedModeActive(void) { - return static_cast(this)->_IsUserSelectedModeActive(); + return static_cast(this)->_IsUserSelectedModeActive(); } inline void ConnectivityManager::SetUserSelectedMode(bool val) { - static_cast(this)->_SetUserSelectedMode(val); + static_cast(this)->_SetUserSelectedMode(val); } inline uint16_t ConnectivityManager::GetUserSelectedModeTimeout(void) { - return static_cast(this)->_GetUserSelectedModeTimeout(); + return static_cast(this)->_GetUserSelectedModeTimeout(); } inline void ConnectivityManager::SetUserSelectedModeTimeout(uint16_t val) { - static_cast(this)->_SetUserSelectedModeTimeout(val); + static_cast(this)->_SetUserSelectedModeTimeout(val); } inline const char * ConnectivityManager::WiFiStationModeToStr(WiFiStationMode mode) @@ -539,26 +539,24 @@ inline const char * ConnectivityManager::CHIPoBLEServiceModeToStr(CHIPoBLEServic inline CHIP_ERROR ConnectivityManager::Init(void) { - return static_cast(this)->_Init(); + return static_cast(this)->_Init(); } -inline void ConnectivityManager::OnPlatformEvent(const ChipDeviceEvent * event) -{ -} +inline void ConnectivityManager::OnPlatformEvent(const ChipDeviceEvent * event) {} inline bool ConnectivityManager::CanStartWiFiScan(void) { - return static_cast(this)->_CanStartWiFiScan(); + return static_cast(this)->_CanStartWiFiScan(); } inline void ConnectivityManager::OnWiFiScanDone(void) { - static_cast(this)->_OnWiFiScanDone(); + static_cast(this)->_OnWiFiScanDone(); } inline void ConnectivityManager::OnWiFiStationProvisionChange(void) { - static_cast(this)->_OnWiFiStationProvisionChange(); + static_cast(this)->_OnWiFiStationProvisionChange(); } } // namespace DeviceLayer diff --git a/src/include/platform/ConnectivityManagerImpl.h b/src/include/platform/ConnectivityManagerImpl.h index 99083a6fb791c1..3304026c9f25b6 100644 --- a/src/include/platform/ConnectivityManagerImpl.h +++ b/src/include/platform/ConnectivityManagerImpl.h @@ -47,28 +47,26 @@ namespace DeviceLayer { /** * Concrete implementation of the ConnectivityManager singleton object for Nordic nRF52 platforms. */ -class ConnectivityManagerImpl final - : public ConnectivityManager, - public Internal::GenericConnectivityManagerImpl, +class ConnectivityManagerImpl final : public ConnectivityManager, + public Internal::GenericConnectivityManagerImpl, #if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE - public Internal::GenericConnectivityManagerImpl_BLE, + public Internal::GenericConnectivityManagerImpl_BLE, #else - public Internal::GenericConnectivityManagerImpl_NoBLE, + public Internal::GenericConnectivityManagerImpl_NoBLE, #endif #if CHIP_DEVICE_CONFIG_ENABLE_THREAD - public Internal::GenericConnectivityManagerImpl_Thread, + public Internal::GenericConnectivityManagerImpl_Thread, #else - public Internal::GenericConnectivityManagerImpl_NoThread, + public Internal::GenericConnectivityManagerImpl_NoThread, #endif - public Internal::GenericConnectivityManagerImpl_NoWiFi, - public Internal::GenericConnectivityManagerImpl_NoTunnel + public Internal::GenericConnectivityManagerImpl_NoWiFi, + public Internal::GenericConnectivityManagerImpl_NoTunnel { // Allow the ConnectivityManager interface class to delegate method calls to // the implementation methods provided by this class. friend class ConnectivityManager; private: - // ===== Members that implement the ConnectivityManager abstract interface. bool _HaveIPv4InternetConnectivity(void); @@ -100,7 +98,6 @@ inline bool ConnectivityManagerImpl::_HaveServiceConnectivity(void) return _HaveServiceConnectivityViaThread(); } - /** * Returns the public interface of the ConnectivityManager singleton object. * diff --git a/src/include/platform/EFR32/BLEManagerImpl.h b/src/include/platform/EFR32/BLEManagerImpl.h index 8dc395eeb2cefb..9e54cc7ad5a45a 100644 --- a/src/include/platform/EFR32/BLEManagerImpl.h +++ b/src/include/platform/EFR32/BLEManagerImpl.h @@ -40,10 +40,7 @@ using namespace chip::Ble; /** * Concrete implementation of the NetworkProvisioningServer singleton object for the EFR32 platforms. */ -class BLEManagerImpl final : public BLEManager, - private BleLayer, - private BlePlatformDelegate, - private BleApplicationDelegate +class BLEManagerImpl final : public BLEManager, private BleLayer, private BlePlatformDelegate, private BleApplicationDelegate { // Allow the BLEManager interface class to delegate method calls to // the implementation methods provided by this class. @@ -51,46 +48,34 @@ class BLEManagerImpl final : public BLEManager, // ===== Members that implement the BLEManager internal interface. - CHIP_ERROR _Init(void); - CHIPoBLEServiceMode _GetCHIPoBLEServiceMode(void); - CHIP_ERROR _SetCHIPoBLEServiceMode(CHIPoBLEServiceMode val); - bool _IsAdvertisingEnabled(void); - CHIP_ERROR _SetAdvertisingEnabled(bool val); - bool _IsFastAdvertisingEnabled(void); - CHIP_ERROR _SetFastAdvertisingEnabled(bool val); - bool _IsAdvertising(void); - CHIP_ERROR _GetDeviceName(char *buf, size_t bufSize); - CHIP_ERROR _SetDeviceName(const char *deviceName); - uint16_t _NumConnections(void); - void _OnPlatformEvent(const ChipDeviceEvent *event); - BleLayer *_GetBleLayer(void) const; + CHIP_ERROR _Init(void); + CHIPoBLEServiceMode _GetCHIPoBLEServiceMode(void); + CHIP_ERROR _SetCHIPoBLEServiceMode(CHIPoBLEServiceMode val); + bool _IsAdvertisingEnabled(void); + CHIP_ERROR _SetAdvertisingEnabled(bool val); + bool _IsFastAdvertisingEnabled(void); + CHIP_ERROR _SetFastAdvertisingEnabled(bool val); + bool _IsAdvertising(void); + CHIP_ERROR _GetDeviceName(char * buf, size_t bufSize); + CHIP_ERROR _SetDeviceName(const char * deviceName); + uint16_t _NumConnections(void); + void _OnPlatformEvent(const ChipDeviceEvent * event); + BleLayer * _GetBleLayer(void) const; // ===== Members that implement virtual methods on BlePlatformDelegate. - bool SubscribeCharacteristic(BLE_CONNECTION_OBJECT conId, - const ChipBleUUID * svcId, - const ChipBleUUID * charId) override; - bool UnsubscribeCharacteristic(BLE_CONNECTION_OBJECT conId, - const ChipBleUUID * svcId, - const ChipBleUUID * charId) override; - bool CloseConnection(BLE_CONNECTION_OBJECT conId) override; + bool SubscribeCharacteristic(BLE_CONNECTION_OBJECT conId, const ChipBleUUID * svcId, const ChipBleUUID * charId) override; + bool UnsubscribeCharacteristic(BLE_CONNECTION_OBJECT conId, const ChipBleUUID * svcId, const ChipBleUUID * charId) override; + bool CloseConnection(BLE_CONNECTION_OBJECT conId) override; uint16_t GetMTU(BLE_CONNECTION_OBJECT conId) const override; - bool SendIndication(BLE_CONNECTION_OBJECT conId, - const ChipBleUUID * svcId, - const ChipBleUUID * charId, - PacketBuffer * pBuf) override; - bool SendWriteRequest(BLE_CONNECTION_OBJECT conId, - const ChipBleUUID * svcId, - const ChipBleUUID * charId, - PacketBuffer * pBuf) override; - bool SendReadRequest(BLE_CONNECTION_OBJECT conId, - const ChipBleUUID * svcId, - const ChipBleUUID * charId, - PacketBuffer * pBuf) override; - bool SendReadResponse(BLE_CONNECTION_OBJECT conId, - BLE_READ_REQUEST_CONTEXT requestContext, - const ChipBleUUID * svcId, - const ChipBleUUID * charId) override; + bool SendIndication(BLE_CONNECTION_OBJECT conId, const ChipBleUUID * svcId, const ChipBleUUID * charId, + PacketBuffer * pBuf) override; + bool SendWriteRequest(BLE_CONNECTION_OBJECT conId, const ChipBleUUID * svcId, const ChipBleUUID * charId, + PacketBuffer * pBuf) override; + bool SendReadRequest(BLE_CONNECTION_OBJECT conId, const ChipBleUUID * svcId, const ChipBleUUID * charId, + PacketBuffer * pBuf) override; + bool SendReadResponse(BLE_CONNECTION_OBJECT conId, BLE_READ_REQUEST_CONTEXT requestContext, const ChipBleUUID * svcId, + const ChipBleUUID * charId) override; // ===== Members that implement virtual methods on BleApplicationDelegate. @@ -98,8 +83,8 @@ class BLEManagerImpl final : public BLEManager, // ===== Members for internal use by the following friends. - friend BLEManager & BLEMgr(void); - friend BLEManagerImpl &BLEMgrImpl(void); + friend BLEManager & BLEMgr(void); + friend BLEManagerImpl & BLEMgrImpl(void); static BLEManagerImpl sInstance; @@ -124,41 +109,41 @@ class BLEManagerImpl final : public BLEManager, struct CHIPoBLEConState { - bd_addr address; + bd_addr address; uint16_t mtu : 10; uint16_t allocated : 1; uint16_t subscribed : 1; uint16_t unused : 4; - uint8_t connectionHandle; - uint8_t bondingHandle; + uint8_t connectionHandle; + uint8_t bondingHandle; }; - CHIPoBLEConState mBleConnections[kMaxConnections]; - uint8_t mIndConfId[kMaxConnections]; + CHIPoBLEConState mBleConnections[kMaxConnections]; + uint8_t mIndConfId[kMaxConnections]; CHIPoBLEServiceMode mServiceMode; - uint16_t mFlags; - char mDeviceName[kMaxDeviceNameLength + 1]; - - CHIP_ERROR MapBLEError(int bleErr); - void DriveBLEState(void); - CHIP_ERROR ConfigureAdvertisingData(void); - CHIP_ERROR StartAdvertising(void); - CHIP_ERROR StopAdvertising(void); - void UpdateMtu(volatile struct gecko_cmd_packet *evt); - void HandleBootEvent(void); - void HandleConnectEvent(volatile struct gecko_cmd_packet *evt); - void HandleConnectionCloseEvent(volatile struct gecko_cmd_packet *evt); - void HandleWriteEvent(volatile struct gecko_cmd_packet *evt); - void HandleTXCharCCCDWrite(volatile struct gecko_cmd_packet *evt); - void HandleRXCharWrite(volatile struct gecko_cmd_packet *evt); - void HandleTxConfirmationEvent(volatile struct gecko_cmd_packet *evt); - void HandleSoftTimerEvent(volatile struct gecko_cmd_packet *evt); - bool RemoveConnection(uint8_t connectionHandle); - void AddConnection(uint8_t connectionHandle, uint8_t bondingHandle); - CHIPoBLEConState *GetConnectionState(uint8_t conId, bool allocate = false); - uint8_t GetTimerHandle(uint8_t connectionHandle, bool allocate = false); - static void DriveBLEState(intptr_t arg); - static void bluetoothStackEventHandler(void *p_arg); + uint16_t mFlags; + char mDeviceName[kMaxDeviceNameLength + 1]; + + CHIP_ERROR MapBLEError(int bleErr); + void DriveBLEState(void); + CHIP_ERROR ConfigureAdvertisingData(void); + CHIP_ERROR StartAdvertising(void); + CHIP_ERROR StopAdvertising(void); + void UpdateMtu(volatile struct gecko_cmd_packet * evt); + void HandleBootEvent(void); + void HandleConnectEvent(volatile struct gecko_cmd_packet * evt); + void HandleConnectionCloseEvent(volatile struct gecko_cmd_packet * evt); + void HandleWriteEvent(volatile struct gecko_cmd_packet * evt); + void HandleTXCharCCCDWrite(volatile struct gecko_cmd_packet * evt); + void HandleRXCharWrite(volatile struct gecko_cmd_packet * evt); + void HandleTxConfirmationEvent(volatile struct gecko_cmd_packet * evt); + void HandleSoftTimerEvent(volatile struct gecko_cmd_packet * evt); + bool RemoveConnection(uint8_t connectionHandle); + void AddConnection(uint8_t connectionHandle, uint8_t bondingHandle); + CHIPoBLEConState * GetConnectionState(uint8_t conId, bool allocate = false); + uint8_t GetTimerHandle(uint8_t connectionHandle, bool allocate = false); + static void DriveBLEState(intptr_t arg); + static void bluetoothStackEventHandler(void * p_arg); }; /** @@ -167,7 +152,7 @@ class BLEManagerImpl final : public BLEManager, * Internal components should use this to access features of the BLEManager object * that are common to all platforms. */ -inline BLEManager &BLEMgr(void) +inline BLEManager & BLEMgr(void) { return BLEManagerImpl::sInstance; } @@ -178,14 +163,14 @@ inline BLEManager &BLEMgr(void) * Internal components can use this to gain access to features of the BLEManager * that are specific to the EFR32 platforms. */ -inline BLEManagerImpl &BLEMgrImpl(void) +inline BLEManagerImpl & BLEMgrImpl(void) { return BLEManagerImpl::sInstance; } -inline BleLayer *BLEManagerImpl::_GetBleLayer() const +inline BleLayer * BLEManagerImpl::_GetBleLayer() const { - return (BleLayer *)(this); + return (BleLayer *) (this); } inline BLEManager::CHIPoBLEServiceMode BLEManagerImpl::_GetCHIPoBLEServiceMode(void) diff --git a/src/include/platform/EFR32/BlePlatformConfig.h b/src/include/platform/EFR32/BlePlatformConfig.h index a3518d9e6b2e38..9d4168f4ac4776 100644 --- a/src/include/platform/EFR32/BlePlatformConfig.h +++ b/src/include/platform/EFR32/BlePlatformConfig.h @@ -31,11 +31,11 @@ // ==================== Platform Adaptations ==================== #define BLE_CONNECTION_OBJECT uint8_t -#define BLE_CONNECTION_UNINITIALIZED ((uint8_t)-1) +#define BLE_CONNECTION_UNINITIALIZED ((uint8_t) -1) #define BLE_MAX_RECEIVE_WINDOW_SIZE 5 #define BLE_CONFIG_ERROR_TYPE int32_t -#define BLE_CONFIG_NO_ERROR 0 +#define BLE_CONFIG_NO_ERROR 0 #define BLE_CONFIG_ERROR_MIN 6000000 #define BLE_CONFIG_ERROR_MAX 6000999 #define _BLE_CONFIG_ERROR(e) (BLE_CONFIG_ERROR_MIN + (e)) diff --git a/src/include/platform/EFR32/CHIPPlatformConfig.h b/src/include/platform/EFR32/CHIPPlatformConfig.h index c2dfadc5206422..98429ac420d613 100644 --- a/src/include/platform/EFR32/CHIPPlatformConfig.h +++ b/src/include/platform/EFR32/CHIPPlatformConfig.h @@ -30,12 +30,12 @@ // ==================== General Platform Adaptations ==================== #define CHIP_CONFIG_ERROR_TYPE int32_t -#define CHIP_CONFIG_NO_ERROR 0 +#define CHIP_CONFIG_NO_ERROR 0 #define CHIP_CONFIG_ERROR_MIN 4000000 #define CHIP_CONFIG_ERROR_MAX 4000999 #define ASN1_CONFIG_ERROR_TYPE int32_t -#define ASN1_CONFIG_NO_ERROR 0 +#define ASN1_CONFIG_NO_ERROR 0 #define ASN1_CONFIG_ERROR_MIN 5000000 #define ASN1_CONFIG_ERROR_MAX 5000999 diff --git a/src/include/platform/EFR32/ConfigurationManagerImpl.h b/src/include/platform/EFR32/ConfigurationManagerImpl.h index 0eb43859231dc8..7a3ac83b9068e4 100644 --- a/src/include/platform/EFR32/ConfigurationManagerImpl.h +++ b/src/include/platform/EFR32/ConfigurationManagerImpl.h @@ -54,10 +54,10 @@ class ConfigurationManagerImpl final : public ConfigurationManager, // ===== Members that implement the ConfigurationManager public interface. CHIP_ERROR _Init(void); - CHIP_ERROR _GetPrimaryWiFiMACAddress(uint8_t *buf); + CHIP_ERROR _GetPrimaryWiFiMACAddress(uint8_t * buf); bool _CanFactoryReset(void); void _InitiateFactoryReset(void); - CHIP_ERROR _ReadPersistedStorageValue(::chip::Platform::PersistedStorage::Key key, uint32_t &value); + CHIP_ERROR _ReadPersistedStorageValue(::chip::Platform::PersistedStorage::Key key, uint32_t & value); CHIP_ERROR _WritePersistedStorageValue(::chip::Platform::PersistedStorage::Key key, uint32_t value); // NOTE: Other public interface methods are implemented by GenericConfigurationManagerImpl<>. @@ -65,8 +65,8 @@ class ConfigurationManagerImpl final : public ConfigurationManager, // ===== Members for internal use by the following friends. friend class Internal::NetworkProvisioningServerImpl; - friend ConfigurationManager & ConfigurationMgr(void); - friend ConfigurationManagerImpl &ConfigurationMgrImpl(void); + friend ConfigurationManager & ConfigurationMgr(void); + friend ConfigurationManagerImpl & ConfigurationMgrImpl(void); static ConfigurationManagerImpl sInstance; @@ -81,7 +81,7 @@ class ConfigurationManagerImpl final : public ConfigurationManager, * Chip applications should use this to access features of the ConfigurationManager object * that are common to all platforms. */ -inline ConfigurationManager &ConfigurationMgr(void) +inline ConfigurationManager & ConfigurationMgr(void) { return ConfigurationManagerImpl::sInstance; } @@ -92,12 +92,12 @@ inline ConfigurationManager &ConfigurationMgr(void) * Chip applications can use this to gain access to features of the ConfigurationManager * that are specific to the ESP32 platform. */ -inline ConfigurationManagerImpl &ConfigurationMgrImpl(void) +inline ConfigurationManagerImpl & ConfigurationMgrImpl(void) { return ConfigurationManagerImpl::sInstance; } -inline CHIP_ERROR ConfigurationManagerImpl::_GetPrimaryWiFiMACAddress(uint8_t *buf) +inline CHIP_ERROR ConfigurationManagerImpl::_GetPrimaryWiFiMACAddress(uint8_t * buf) { return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; } diff --git a/src/include/platform/EFR32/ConnectivityManagerImpl.h b/src/include/platform/EFR32/ConnectivityManagerImpl.h index c03650b014371d..37acd1d443c646 100644 --- a/src/include/platform/EFR32/ConnectivityManagerImpl.h +++ b/src/include/platform/EFR32/ConnectivityManagerImpl.h @@ -67,16 +67,16 @@ class ConnectivityManagerImpl final : public ConnectivityManager, private: // ===== Members that implement the ConnectivityManager abstract interface. - bool _HaveIPv4InternetConnectivity(void); - bool _HaveIPv6InternetConnectivity(void); - bool _HaveServiceConnectivity(void); + bool _HaveIPv4InternetConnectivity(void); + bool _HaveIPv6InternetConnectivity(void); + bool _HaveServiceConnectivity(void); CHIP_ERROR _Init(void); - void _OnPlatformEvent(const ChipDeviceEvent *event); + void _OnPlatformEvent(const ChipDeviceEvent * event); // ===== Members for internal use by the following friends. - friend ConnectivityManager & ConnectivityMgr(void); - friend ConnectivityManagerImpl &ConnectivityMgrImpl(void); + friend ConnectivityManager & ConnectivityMgr(void); + friend ConnectivityManagerImpl & ConnectivityMgrImpl(void); static ConnectivityManagerImpl sInstance; }; @@ -102,7 +102,7 @@ inline bool ConnectivityManagerImpl::_HaveServiceConnectivity(void) * Chip applications should use this to access features of the ConnectivityManager object * that are common to all platforms. */ -inline ConnectivityManager &ConnectivityMgr(void) +inline ConnectivityManager & ConnectivityMgr(void) { return ConnectivityManagerImpl::sInstance; } @@ -113,7 +113,7 @@ inline ConnectivityManager &ConnectivityMgr(void) * Chip applications can use this to gain access to features of the ConnectivityManager * that are specific to the ESP32 platform. */ -inline ConnectivityManagerImpl &ConnectivityMgrImpl(void) +inline ConnectivityManagerImpl & ConnectivityMgrImpl(void) { return ConnectivityManagerImpl::sInstance; } diff --git a/src/include/platform/EFR32/EFR32Config.h b/src/include/platform/EFR32/EFR32Config.h index b34151f2f0ab17..d095c911686798 100644 --- a/src/include/platform/EFR32/EFR32Config.h +++ b/src/include/platform/EFR32/EFR32Config.h @@ -68,29 +68,28 @@ class EFR32Config // NVM3 key base offsets used by the CHIP Device Layer. static constexpr uint8_t kChipFactory_KeyBase = 0xA2; // Persistent config values set at manufacturing time. Retained during factory reset. - static constexpr uint8_t kChipConfig_KeyBase = - 0xA3; // Persistent config values set at runtime. Cleared during factory reset. + static constexpr uint8_t kChipConfig_KeyBase = 0xA3; // Persistent config values set at runtime. Cleared during factory reset. static constexpr uint8_t kChipCounter_KeyBase = 0xA4; // Persistent counter values set at runtime. Retained during factory reset. // Key definitions for well-known configuration values. // Factory config keys - static constexpr Key kConfigKey_SerialNum = EFR32ConfigKey(kChipFactory_KeyBase, 0x00); - static constexpr Key kConfigKey_MfrDeviceId = EFR32ConfigKey(kChipFactory_KeyBase, 0x01); - static constexpr Key kConfigKey_MfrDeviceCert = EFR32ConfigKey(kChipFactory_KeyBase, 0x02); - static constexpr Key kConfigKey_MfrDevicePrivateKey = EFR32ConfigKey(kChipFactory_KeyBase, 0x03); - static constexpr Key kConfigKey_ManufacturingDate = EFR32ConfigKey(kChipFactory_KeyBase, 0x04); - static constexpr Key kConfigKey_PairingCode = EFR32ConfigKey(kChipFactory_KeyBase, 0x05); - static constexpr Key kConfigKey_MfrDeviceICACerts = EFR32ConfigKey(kChipFactory_KeyBase, 0x06); + static constexpr Key kConfigKey_SerialNum = EFR32ConfigKey(kChipFactory_KeyBase, 0x00); + static constexpr Key kConfigKey_MfrDeviceId = EFR32ConfigKey(kChipFactory_KeyBase, 0x01); + static constexpr Key kConfigKey_MfrDeviceCert = EFR32ConfigKey(kChipFactory_KeyBase, 0x02); + static constexpr Key kConfigKey_MfrDevicePrivateKey = EFR32ConfigKey(kChipFactory_KeyBase, 0x03); + static constexpr Key kConfigKey_ManufacturingDate = EFR32ConfigKey(kChipFactory_KeyBase, 0x04); + static constexpr Key kConfigKey_PairingCode = EFR32ConfigKey(kChipFactory_KeyBase, 0x05); + static constexpr Key kConfigKey_MfrDeviceICACerts = EFR32ConfigKey(kChipFactory_KeyBase, 0x06); // CHIP Config Keys - static constexpr Key kConfigKey_FabricId = EFR32ConfigKey(kChipConfig_KeyBase, 0x00); - static constexpr Key kConfigKey_ServiceConfig = EFR32ConfigKey(kChipConfig_KeyBase, 0x01); - static constexpr Key kConfigKey_PairedAccountId = EFR32ConfigKey(kChipConfig_KeyBase, 0x02); - static constexpr Key kConfigKey_ServiceId = EFR32ConfigKey(kChipConfig_KeyBase, 0x03); - static constexpr Key kConfigKey_FabricSecret = EFR32ConfigKey(kChipConfig_KeyBase, 0x04); - static constexpr Key kConfigKey_LastUsedEpochKeyId = EFR32ConfigKey(kChipConfig_KeyBase, 0x05); - static constexpr Key kConfigKey_FailSafeArmed = EFR32ConfigKey(kChipConfig_KeyBase, 0x06); - static constexpr Key kConfigKey_GroupKey = EFR32ConfigKey(kChipConfig_KeyBase, 0x07); + static constexpr Key kConfigKey_FabricId = EFR32ConfigKey(kChipConfig_KeyBase, 0x00); + static constexpr Key kConfigKey_ServiceConfig = EFR32ConfigKey(kChipConfig_KeyBase, 0x01); + static constexpr Key kConfigKey_PairedAccountId = EFR32ConfigKey(kChipConfig_KeyBase, 0x02); + static constexpr Key kConfigKey_ServiceId = EFR32ConfigKey(kChipConfig_KeyBase, 0x03); + static constexpr Key kConfigKey_FabricSecret = EFR32ConfigKey(kChipConfig_KeyBase, 0x04); + static constexpr Key kConfigKey_LastUsedEpochKeyId = EFR32ConfigKey(kChipConfig_KeyBase, 0x05); + static constexpr Key kConfigKey_FailSafeArmed = EFR32ConfigKey(kChipConfig_KeyBase, 0x06); + static constexpr Key kConfigKey_GroupKey = EFR32ConfigKey(kChipConfig_KeyBase, 0x07); static constexpr Key kConfigKey_ProductRevision = EFR32ConfigKey(kChipConfig_KeyBase, 0x08); static constexpr Key kConfigKey_OperationalDeviceId = EFR32ConfigKey(kChipConfig_KeyBase, 0x09); static constexpr Key kConfigKey_OperationalDeviceCert = EFR32ConfigKey(kChipConfig_KeyBase, 0x0A); @@ -98,8 +97,7 @@ class EFR32Config static constexpr Key kConfigKey_OperationalDevicePrivateKey = EFR32ConfigKey(kChipConfig_KeyBase, 0x0C); static constexpr Key kConfigKey_GroupKeyBase = EFR32ConfigKey(kChipConfig_KeyBase, 0x0D); - static constexpr Key kConfigKey_GroupKeyMax = - EFR32ConfigKey(kChipConfig_KeyBase, 0x1C); // Allows 16 Group Keys to be created. + static constexpr Key kConfigKey_GroupKeyMax = EFR32ConfigKey(kChipConfig_KeyBase, 0x1C); // Allows 16 Group Keys to be created. // Set key id limits for each group. static constexpr Key kMinConfigKey_ChipFactory = EFR32ConfigKey(kChipFactory_KeyBase, 0x00); @@ -113,29 +111,29 @@ class EFR32Config static CHIP_ERROR Init(void); // Configuration methods used by the GenericConfigurationManagerImpl<> template. - static CHIP_ERROR ReadConfigValue(Key key, bool &val); - static CHIP_ERROR ReadConfigValue(Key key, uint32_t &val); - static CHIP_ERROR ReadConfigValue(Key key, uint64_t &val); - static CHIP_ERROR ReadConfigValueStr(Key key, char *buf, size_t bufSize, size_t &outLen); - static CHIP_ERROR ReadConfigValueBin(Key key, uint8_t *buf, size_t bufSize, size_t &outLen); - static CHIP_ERROR ReadConfigValueCounter(uint8_t counterIdx, uint32_t &val); + static CHIP_ERROR ReadConfigValue(Key key, bool & val); + static CHIP_ERROR ReadConfigValue(Key key, uint32_t & val); + static CHIP_ERROR ReadConfigValue(Key key, uint64_t & val); + static CHIP_ERROR ReadConfigValueStr(Key key, char * buf, size_t bufSize, size_t & outLen); + static CHIP_ERROR ReadConfigValueBin(Key key, uint8_t * buf, size_t bufSize, size_t & outLen); + static CHIP_ERROR ReadConfigValueCounter(uint8_t counterIdx, uint32_t & val); static CHIP_ERROR WriteConfigValue(Key key, bool val); static CHIP_ERROR WriteConfigValue(Key key, uint32_t val); static CHIP_ERROR WriteConfigValue(Key key, uint64_t val); - static CHIP_ERROR WriteConfigValueStr(Key key, const char *str); - static CHIP_ERROR WriteConfigValueStr(Key key, const char *str, size_t strLen); - static CHIP_ERROR WriteConfigValueBin(Key key, const uint8_t *data, size_t dataLen); + static CHIP_ERROR WriteConfigValueStr(Key key, const char * str); + static CHIP_ERROR WriteConfigValueStr(Key key, const char * str, size_t strLen); + static CHIP_ERROR WriteConfigValueBin(Key key, const uint8_t * data, size_t dataLen); static CHIP_ERROR WriteConfigValueCounter(uint8_t counterIdx, uint32_t val); static CHIP_ERROR ClearConfigValue(Key key); - static bool ConfigValueExists(Key key); + static bool ConfigValueExists(Key key); static CHIP_ERROR FactoryResetConfig(void); - static bool ValidConfigKey(Key key); + static bool ValidConfigKey(Key key); static void RunConfigUnitTest(void); static void RepackNvm3Flash(void); protected: - using ForEachRecordFunct = std::function; + using ForEachRecordFunct = std::function; static CHIP_ERROR ForEachRecord(Key firstKey, Key lastKey, bool addNewRecord, ForEachRecordFunct funct); private: diff --git a/src/include/platform/EFR32/GroupKeyStoreImpl.h b/src/include/platform/EFR32/GroupKeyStoreImpl.h index ee512a3bd70ff7..891e5eb7221635 100644 --- a/src/include/platform/EFR32/GroupKeyStoreImpl.h +++ b/src/include/platform/EFR32/GroupKeyStoreImpl.h @@ -42,22 +42,19 @@ class GroupKeyStoreImpl final : public ::chip::Profiles::Security::AppKeys::Grou public: CHIP_ERROR Init(); - CHIP_ERROR RetrieveGroupKey(uint32_t keyId, ChipGroupKey &key) override; - CHIP_ERROR StoreGroupKey(const ChipGroupKey &key) override; + CHIP_ERROR RetrieveGroupKey(uint32_t keyId, ChipGroupKey & key) override; + CHIP_ERROR StoreGroupKey(const ChipGroupKey & key) override; CHIP_ERROR DeleteGroupKey(uint32_t keyId) override; CHIP_ERROR DeleteGroupKeysOfAType(uint32_t keyType) override; - CHIP_ERROR EnumerateGroupKeys(uint32_t keyType, - uint32_t *keyIds, - uint8_t keyIdsArraySize, - uint8_t & keyCount) override; + CHIP_ERROR EnumerateGroupKeys(uint32_t keyType, uint32_t * keyIds, uint8_t keyIdsArraySize, uint8_t & keyCount) override; CHIP_ERROR Clear(void) override; CHIP_ERROR RetrieveLastUsedEpochKeyId(void) override; CHIP_ERROR StoreLastUsedEpochKeyId(void) override; private: static constexpr size_t kFixedEncodedKeySize = 4U + // key id - 4U + // start time / global id - 1U; // key data length + 4U + // start time / global id + 1U; // key data length static constexpr size_t kMaxEncodedKeySize = kFixedEncodedKeySize + ChipGroupKey::MaxKeySize; @@ -66,9 +63,9 @@ class GroupKeyStoreImpl final : public ::chip::Profiles::Security::AppKeys::Grou static constexpr uint16_t kGroupKeyRecordKey = GetRecordKey(kConfigKey_GroupKey); */ - static CHIP_ERROR EncodeGroupKey(const ChipGroupKey &key, uint8_t *buf, size_t bufSize, size_t &encodedKeyLen); - static CHIP_ERROR DecodeGroupKey(const uint8_t *encodedKey, size_t encodedKeyLen, ChipGroupKey &key); - static CHIP_ERROR DecodeGroupKeyId(const uint8_t *encodedKey, size_t encodedKeyLen, uint32_t &keyId); + static CHIP_ERROR EncodeGroupKey(const ChipGroupKey & key, uint8_t * buf, size_t bufSize, size_t & encodedKeyLen); + static CHIP_ERROR DecodeGroupKey(const uint8_t * encodedKey, size_t encodedKeyLen, ChipGroupKey & key); + static CHIP_ERROR DecodeGroupKeyId(const uint8_t * encodedKey, size_t encodedKeyLen, uint32_t & keyId); }; } // namespace Internal diff --git a/src/include/platform/EFR32/InetPlatformConfig.h b/src/include/platform/EFR32/InetPlatformConfig.h index 0908aee0d7f158..e75703584aca54 100644 --- a/src/include/platform/EFR32/InetPlatformConfig.h +++ b/src/include/platform/EFR32/InetPlatformConfig.h @@ -31,7 +31,7 @@ // ==================== Platform Adaptations ==================== #define INET_CONFIG_ERROR_TYPE int32_t -#define INET_CONFIG_NO_ERROR 0 +#define INET_CONFIG_NO_ERROR 0 #define INET_CONFIG_ERROR_MIN 1000000 #define INET_CONFIG_ERROR_MAX 1000999 diff --git a/src/include/platform/EFR32/NetworkProvisioningServerImpl.h b/src/include/platform/EFR32/NetworkProvisioningServerImpl.h index 3c80a3352acb73..6b556dc49a04d5 100644 --- a/src/include/platform/EFR32/NetworkProvisioningServerImpl.h +++ b/src/include/platform/EFR32/NetworkProvisioningServerImpl.h @@ -29,9 +29,8 @@ namespace Internal { * Concrete implementation of the NetworkProvisioningServer singleton object for the * Silicon Labs EFR32 platforms. */ -class NetworkProvisioningServerImpl final - : public NetworkProvisioningServer, - public Internal::GenericNetworkProvisioningServerImpl +class NetworkProvisioningServerImpl final : public NetworkProvisioningServer, + public Internal::GenericNetworkProvisioningServerImpl { // Allow the NetworkProvisioningServer interface class to delegate method calls to // the implementation methods provided by this class. @@ -48,8 +47,8 @@ class NetworkProvisioningServerImpl final // ===== Members for internal use by the following friends. - friend ::chip::DeviceLayer::Internal::NetworkProvisioningServer &NetworkProvisioningSvr(void); - friend NetworkProvisioningServerImpl & NetworkProvisioningSvrImpl(void); + friend ::chip::DeviceLayer::Internal::NetworkProvisioningServer & NetworkProvisioningSvr(void); + friend NetworkProvisioningServerImpl & NetworkProvisioningSvrImpl(void); static NetworkProvisioningServerImpl sInstance; }; @@ -60,7 +59,7 @@ class NetworkProvisioningServerImpl final * Internal components should use this to access features of the NetworkProvisioningServer object * that are common to all platforms. */ -inline NetworkProvisioningServer &NetworkProvisioningSvr(void) +inline NetworkProvisioningServer & NetworkProvisioningSvr(void) { return NetworkProvisioningServerImpl::sInstance; } @@ -71,7 +70,7 @@ inline NetworkProvisioningServer &NetworkProvisioningSvr(void) * Internal components can use this to gain access to features of the NetworkProvisioningServer * that are specific to the ESP32 platform. */ -inline NetworkProvisioningServerImpl &NetworkProvisioningSvrImpl(void) +inline NetworkProvisioningServerImpl & NetworkProvisioningSvrImpl(void) { return NetworkProvisioningServerImpl::sInstance; } diff --git a/src/include/platform/EFR32/PlatformManagerImpl.h b/src/include/platform/EFR32/PlatformManagerImpl.h index 834711841f5c6c..c80806dff803ea 100644 --- a/src/include/platform/EFR32/PlatformManagerImpl.h +++ b/src/include/platform/EFR32/PlatformManagerImpl.h @@ -33,8 +33,7 @@ namespace DeviceLayer { /** * Concrete implementation of the PlatformManager singleton object for the EFR32 platform. */ -class PlatformManagerImpl final : public PlatformManager, - public Internal::GenericPlatformManagerImpl_FreeRTOS +class PlatformManagerImpl final : public PlatformManager, public Internal::GenericPlatformManagerImpl_FreeRTOS { // Allow the PlatformManager interface class to delegate method calls to // the implementation methods provided by this class. @@ -56,8 +55,8 @@ class PlatformManagerImpl final : public PlatformManager, // ===== Members for internal use by the following friends. - friend PlatformManager & PlatformMgr(void); - friend PlatformManagerImpl &PlatformMgrImpl(void); + friend PlatformManager & PlatformMgr(void); + friend PlatformManagerImpl & PlatformMgrImpl(void); friend class Internal::BLEManagerImpl; static PlatformManagerImpl sInstance; @@ -71,7 +70,7 @@ class PlatformManagerImpl final : public PlatformManager, * Chip applications should use this to access features of the PlatformManager object * that are common to all platforms. */ -inline PlatformManager &PlatformMgr(void) +inline PlatformManager & PlatformMgr(void) { return PlatformManagerImpl::sInstance; } @@ -82,7 +81,7 @@ inline PlatformManager &PlatformMgr(void) * Chip applications can use this to gain access to features of the PlatformManager * that are specific to the ESP32 platform. */ -inline PlatformManagerImpl &PlatformMgrImpl(void) +inline PlatformManagerImpl & PlatformMgrImpl(void) { return PlatformManagerImpl::sInstance; } diff --git a/src/include/platform/EFR32/SoftwareUpdateManagerImpl.h b/src/include/platform/EFR32/SoftwareUpdateManagerImpl.h index d5349a36fa2ff2..65b700cb4e2797 100644 --- a/src/include/platform/EFR32/SoftwareUpdateManagerImpl.h +++ b/src/include/platform/EFR32/SoftwareUpdateManagerImpl.h @@ -50,8 +50,8 @@ class SoftwareUpdateManagerImpl final : public SoftwareUpdateManager, public: // ===== Members for internal use by the following friends. - friend ::chip::DeviceLayer::SoftwareUpdateManager &SoftwareUpdateMgr(void); - friend SoftwareUpdateManagerImpl & SoftwareUpdateMgrImpl(void); + friend ::chip::DeviceLayer::SoftwareUpdateManager & SoftwareUpdateMgr(void); + friend SoftwareUpdateManagerImpl & SoftwareUpdateMgrImpl(void); static SoftwareUpdateManagerImpl sInstance; @@ -67,7 +67,7 @@ class SoftwareUpdateManagerImpl final : public SoftwareUpdateManager, * Internal components should use this to access features of the SoftwareUpdateManager object * that are common to all platforms. */ -inline SoftwareUpdateManager &SoftwareUpdateMgr(void) +inline SoftwareUpdateManager & SoftwareUpdateMgr(void) { return SoftwareUpdateManagerImpl::sInstance; } @@ -78,7 +78,7 @@ inline SoftwareUpdateManager &SoftwareUpdateMgr(void) * Internal components can use this to gain access to features of the SoftwareUpdateManager * that are specific to the EFR32 platform. */ -inline SoftwareUpdateManagerImpl &SoftwareUpdateMgrImpl(void) +inline SoftwareUpdateManagerImpl & SoftwareUpdateMgrImpl(void) { return SoftwareUpdateManagerImpl::sInstance; } diff --git a/src/include/platform/EFR32/ThreadStackManagerImpl.h b/src/include/platform/EFR32/ThreadStackManagerImpl.h index 91d6c0d3fe6530..f96daeecb51e47 100644 --- a/src/include/platform/EFR32/ThreadStackManagerImpl.h +++ b/src/include/platform/EFR32/ThreadStackManagerImpl.h @@ -37,17 +37,16 @@ namespace DeviceLayer { class ThreadStackManager; class ThreadStackManagerImpl; namespace Internal { -extern int GetEntropy_EFR32(uint8_t *buf, size_t bufSize); +extern int GetEntropy_EFR32(uint8_t * buf, size_t bufSize); } /** * Concrete implementation of the ThreadStackManager singleton object for EFR32 platforms * using the Silicon Labs SDK and the OpenThread stack. */ -class ThreadStackManagerImpl final - : public ThreadStackManager, - public Internal::GenericThreadStackManagerImpl_OpenThread_LwIP, - public Internal::GenericThreadStackManagerImpl_FreeRTOS +class ThreadStackManagerImpl final : public ThreadStackManager, + public Internal::GenericThreadStackManagerImpl_OpenThread_LwIP, + public Internal::GenericThreadStackManagerImpl_FreeRTOS { // Allow the ThreadStackManager interface class to delegate method calls to // the implementation methods provided by this class. @@ -61,14 +60,14 @@ class ThreadStackManagerImpl final // Allow glue functions called by OpenThread to call helper methods on this // class. - friend void ::otTaskletsSignalPending(otInstance *otInst); + friend void ::otTaskletsSignalPending(otInstance * otInst); friend void ::otSysEventSignalPending(void); public: // ===== Platform-specific members that may be accessed directly by the application. using ThreadStackManager::InitThreadStack; - CHIP_ERROR InitThreadStack(otInstance *otInst); + CHIP_ERROR InitThreadStack(otInstance * otInst); private: // ===== Methods that implement the ThreadStackManager abstract interface. @@ -79,7 +78,7 @@ class ThreadStackManagerImpl final friend ThreadStackManager & ::chip::DeviceLayer::ThreadStackMgr(void); friend ThreadStackManagerImpl & ::chip::DeviceLayer::ThreadStackMgrImpl(void); - friend int Internal::GetEntropy_EFR32(uint8_t *buf, size_t bufSize); + friend int Internal::GetEntropy_EFR32(uint8_t * buf, size_t bufSize); static ThreadStackManagerImpl sInstance; @@ -96,7 +95,7 @@ class ThreadStackManagerImpl final * Chip applications should use this to access features of the ThreadStackManager object * that are common to all platforms. */ -inline ThreadStackManager &ThreadStackMgr(void) +inline ThreadStackManager & ThreadStackMgr(void) { return ThreadStackManagerImpl::sInstance; } @@ -107,7 +106,7 @@ inline ThreadStackManager &ThreadStackMgr(void) * Chip applications can use this to gain access to features of the ThreadStackManager * that are specific to EFR32 platforms. */ -inline ThreadStackManagerImpl &ThreadStackMgrImpl(void) +inline ThreadStackManagerImpl & ThreadStackMgrImpl(void) { return ThreadStackManagerImpl::sInstance; } diff --git a/src/include/platform/EFR32/freertos_bluetooth.h b/src/include/platform/EFR32/freertos_bluetooth.h index 0f7dbd4f6c7d2f..5df1b5a2bc5ac6 100644 --- a/src/include/platform/EFR32/freertos_bluetooth.h +++ b/src/include/platform/EFR32/freertos_bluetooth.h @@ -42,7 +42,7 @@ extern EventGroupHandle_t bluetooth_event_flags; #define BLUETOOTH_EVENT_FLAG_EVT_HANDLED (0x20) // BGAPI event is handled // Bluetooth event data pointer -extern volatile struct gecko_cmd_packet *bluetooth_evt; +extern volatile struct gecko_cmd_packet * bluetooth_evt; // Function prototype for initializing Bluetooth stack. typedef errorcode_t (*bluetooth_stack_init_func)(); @@ -56,8 +56,7 @@ typedef errorcode_t (*bluetooth_stack_init_func)(); * @param stack_priority Bluetooth stack task priority * @param initialize_bluetooth_stack The function for initializing Bluetooth stack */ -errorcode_t bluetooth_start(UBaseType_t ll_priority, - UBaseType_t stack_priority, +errorcode_t bluetooth_start(UBaseType_t ll_priority, UBaseType_t stack_priority, bluetooth_stack_init_func initialize_bluetooth_stack); // Set the callback for wakeup, Bluetooth task will call this when it has a new event @@ -73,13 +72,10 @@ extern void BluetoothLLCallback(void); void BluetoothPend(void); void BluetoothPost(void); -EventBits_t vRaiseEventFlagBasedOnContext(EventGroupHandle_t xEventGroup, - EventBits_t uxBitsToWaitFor, - BaseType_t * pxHigherPriorityTaskWoken); -EventBits_t vSendToQueueBasedOnContext(QueueHandle_t xQueue, - void * xItemToQueue, - TickType_t xTicksToWait, - BaseType_t * pxHigherPriorityTaskWoken); +EventBits_t vRaiseEventFlagBasedOnContext(EventGroupHandle_t xEventGroup, EventBits_t uxBitsToWaitFor, + BaseType_t * pxHigherPriorityTaskWoken); +EventBits_t vSendToQueueBasedOnContext(QueueHandle_t xQueue, void * xItemToQueue, TickType_t xTicksToWait, + BaseType_t * pxHigherPriorityTaskWoken); #if __cplusplus } diff --git a/src/include/platform/GeneralUtils.h b/src/include/platform/GeneralUtils.h index e21af8d62af5f8..01691997990074 100644 --- a/src/include/platform/GeneralUtils.h +++ b/src/include/platform/GeneralUtils.h @@ -28,8 +28,8 @@ namespace DeviceLayer { extern CHIP_ERROR ParseCompilerDateStr(const char * dateStr, uint16_t & year, uint8_t & month, uint8_t & dayOfMonth); extern CHIP_ERROR Parse24HourTimeStr(const char * timeStr, uint8_t & hour, uint8_t & minute, uint8_t & second); -extern const char * CharacterizeIPv6Address(const chip::Inet::IPAddress &ipAddr); -extern const char * CharacterizeIPv6Prefix(const chip::Inet::IPPrefix &inPrefix); +extern const char * CharacterizeIPv6Address(const chip::Inet::IPAddress & ipAddr); +extern const char * CharacterizeIPv6Prefix(const chip::Inet::IPPrefix & inPrefix); extern void RegisterDeviceLayerErrorFormatter(void); extern bool FormatDeviceLayerError(char * buf, uint16_t bufSize, int32_t err); diff --git a/src/include/platform/PersistedStorage.h b/src/include/platform/PersistedStorage.h index c20c368b8c5bbc..f13b0625fd3d3d 100644 --- a/src/include/platform/PersistedStorage.h +++ b/src/include/platform/PersistedStorage.h @@ -50,7 +50,7 @@ typedef CHIP_CONFIG_PERSISTED_STORAGE_KEY_TYPE Key; * CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND if aKey does not exist * CHIP_NO_ERROR otherwise */ -CHIP_ERROR Read(Key aKey, uint32_t &aValue); +CHIP_ERROR Read(Key aKey, uint32_t & aValue); /** * @brief @@ -69,8 +69,8 @@ CHIP_ERROR Read(Key aKey, uint32_t &aValue); */ CHIP_ERROR Write(Key aKey, uint32_t aValue); -} // PersistedStorage -} // Platform -} // chip +} // namespace PersistedStorage +} // namespace Platform +} // namespace chip #endif // PERSISTED_STORAGE_H diff --git a/src/include/platform/PlatformManagerImpl.h b/src/include/platform/PlatformManagerImpl.h index 9c11d8bf735968..6919821e99b7bb 100644 --- a/src/include/platform/PlatformManagerImpl.h +++ b/src/include/platform/PlatformManagerImpl.h @@ -32,9 +32,7 @@ namespace DeviceLayer { /** * Concrete implementation of the PlatformManager singleton object for the nRF52 platform. */ -class PlatformManagerImpl final - : public PlatformManager, - public Internal::GenericPlatformManagerImpl_FreeRTOS +class PlatformManagerImpl final : public PlatformManager, public Internal::GenericPlatformManagerImpl_FreeRTOS { // Allow the PlatformManager interface class to delegate method calls to // the implementation methods provided by this class. @@ -45,13 +43,11 @@ class PlatformManagerImpl final friend Internal::GenericPlatformManagerImpl_FreeRTOS; public: - // ===== Platform-specific members that may be accessed directly by the application. /* none so far */ private: - // ===== Methods that implement the PlatformManager abstract interface. CHIP_ERROR _InitChipStack(void); diff --git a/src/include/platform/SoftwareUpdateManager.h b/src/include/platform/SoftwareUpdateManager.h index 281b7eaf9c6a43..4c4dcd3cac9e08 100644 --- a/src/include/platform/SoftwareUpdateManager.h +++ b/src/include/platform/SoftwareUpdateManager.h @@ -40,22 +40,20 @@ class SoftwareUpdateManager { using ImplClass = SoftwareUpdateManagerImpl; - public: - // ===== Members that define the public interface of the SoftwareUpdateManager enum State { - kState_Idle = 1, - kState_ScheduledHoldoff = 2, - kState_PrepareQuery = 3, - kState_Query = 4, - kState_PrepareImageStorage = 5, - kState_Download = 6, - kState_Install = 7, + kState_Idle = 1, + kState_ScheduledHoldoff = 2, + kState_PrepareQuery = 3, + kState_Query = 4, + kState_PrepareImageStorage = 5, + kState_Download = 6, + kState_Install = 7, - kState_ApplicationManaged = 8, + kState_ApplicationManaged = 8, kState_MaxState }; @@ -229,7 +227,7 @@ class SoftwareUpdateManager * * Applications must NOT handle this event. */ - kEvent_DefaultCheck = 100, + kEvent_DefaultCheck = 100, }; @@ -275,7 +273,7 @@ class SoftwareUpdateManager */ union InEventParam; - /** + /** * Outgoing parameters sent with events generated directly from this component * */ @@ -290,8 +288,8 @@ class SoftwareUpdateManager uint32_t NumRetries; }; - typedef void (*EventCallback)(void *apAppState, EventType aEvent, const InEventParam& aInParam, OutEventParam& aOutParam); - typedef void (*RetryPolicyCallback)(void *aAppState, RetryParam& aRetryParam, uint32_t& aOutIntervalMsec); + typedef void (*EventCallback)(void * apAppState, EventType aEvent, const InEventParam & aInParam, OutEventParam & aOutParam); + typedef void (*RetryPolicyCallback)(void * aAppState, RetryParam & aRetryParam, uint32_t & aOutIntervalMsec); CHIP_ERROR Abort(void); CHIP_ERROR CheckNow(void); @@ -306,26 +304,24 @@ class SoftwareUpdateManager State GetState(void); - static void DefaultEventHandler(void *apAppState, EventType aEvent, - const InEventParam& aInParam, - OutEventParam& aOutParam); + static void DefaultEventHandler(void * apAppState, EventType aEvent, const InEventParam & aInParam, OutEventParam & aOutParam); private: // ===== Members for internal use by the following friends. // friend class SoftwareUpdateManagerImpl; - template friend class Internal::GenericPlatformManagerImpl; + template + friend class Internal::GenericPlatformManagerImpl; CHIP_ERROR Init(void); protected: - // Construction/destruction limited to subclasses. - SoftwareUpdateManager() = default; + SoftwareUpdateManager() = default; ~SoftwareUpdateManager() = default; // No copy, move or assignment. - SoftwareUpdateManager(const SoftwareUpdateManager &) = delete; + SoftwareUpdateManager(const SoftwareUpdateManager &) = delete; SoftwareUpdateManager(const SoftwareUpdateManager &&) = delete; SoftwareUpdateManager & operator=(const SoftwareUpdateManager &) = delete; }; @@ -382,32 +378,32 @@ union SoftwareUpdateManager::InEventParam struct { uint8_t IntegrityType; - const char *URI; - const char *Version; + const char * URI; + const char * Version; } SoftwareUpdateAvailable; struct { - const char *URI; + const char * URI; } FetchPartialImageInfo; struct { - const char *URI; + const char * URI; uint8_t IntegrityType; } PrepareImageStorage; struct { - uint8_t *DataBlock; + uint8_t * DataBlock; uint32_t DataBlockLen; } StoreImageBlock; struct { uint8_t IntegrityType; - uint8_t *IntegrityValueBuf; // Pointer to the buffer for the app to copy Integrity Value into. - uint8_t IntegrityValueBufLen; // Length of the provided buffer. + uint8_t * IntegrityValueBuf; // Pointer to the buffer for the app to copy Integrity Value into. + uint8_t IntegrityValueBufLen; // Length of the provided buffer. } ComputeImageIntegrity; struct @@ -423,8 +419,8 @@ union SoftwareUpdateManager::OutEventParam bool DefaultHandlerCalled; struct { - const char *PackageSpecification; - const char *DesiredLocale; + const char * PackageSpecification; + const char * DesiredLocale; CHIP_ERROR Error; } PrepareQuery; @@ -456,57 +452,56 @@ union SoftwareUpdateManager::OutEventParam inline CHIP_ERROR SoftwareUpdateManager::Init(void) { - return static_cast(this)->_Init(); + return static_cast(this)->_Init(); } inline CHIP_ERROR SoftwareUpdateManager::CheckNow(void) { - return static_cast(this)->_CheckNow(); + return static_cast(this)->_CheckNow(); } inline CHIP_ERROR SoftwareUpdateManager::ImageInstallComplete(CHIP_ERROR aError) { - return static_cast(this)->_ImageInstallComplete(aError); + return static_cast(this)->_ImageInstallComplete(aError); } inline CHIP_ERROR SoftwareUpdateManager::PrepareImageStorageComplete(CHIP_ERROR aError) { - return static_cast(this)->_PrepareImageStorageComplete(aError); + return static_cast(this)->_PrepareImageStorageComplete(aError); } inline SoftwareUpdateManager::State SoftwareUpdateManager::GetState(void) { - return static_cast(this)->_GetState(); + return static_cast(this)->_GetState(); } inline CHIP_ERROR SoftwareUpdateManager::Abort(void) { - return static_cast(this)->_Abort(); + return static_cast(this)->_Abort(); } inline bool SoftwareUpdateManager::IsInProgress(void) { - return static_cast(this)->_IsInProgress(); + return static_cast(this)->_IsInProgress(); } inline CHIP_ERROR SoftwareUpdateManager::SetQueryIntervalWindow(uint32_t aMinRangeSecs, uint32_t aMaxRangeSecs) { - return static_cast(this)->_SetQueryIntervalWindow(aMinRangeSecs, aMaxRangeSecs); + return static_cast(this)->_SetQueryIntervalWindow(aMinRangeSecs, aMaxRangeSecs); } inline void SoftwareUpdateManager::SetRetryPolicyCallback(const RetryPolicyCallback aRetryPolicyCallback) { - static_cast(this)->_SetRetryPolicyCallback(aRetryPolicyCallback); + static_cast(this)->_SetRetryPolicyCallback(aRetryPolicyCallback); } inline CHIP_ERROR SoftwareUpdateManager::SetEventCallback(void * const aAppState, const EventCallback aEventCallback) { - return static_cast(this)->_SetEventCallback(aAppState, aEventCallback); + return static_cast(this)->_SetEventCallback(aAppState, aEventCallback); } -inline void SoftwareUpdateManager::DefaultEventHandler(void *apAppState, EventType aEvent, - const InEventParam& aInParam, - OutEventParam& aOutParam) +inline void SoftwareUpdateManager::DefaultEventHandler(void * apAppState, EventType aEvent, const InEventParam & aInParam, + OutEventParam & aOutParam) { ImplClass::_DefaultEventHandler(apAppState, aEvent, aInParam, aOutParam); } diff --git a/src/include/platform/SoftwareUpdateManagerImpl.h b/src/include/platform/SoftwareUpdateManagerImpl.h index 2eb756cc46425f..ae8b17d7634844 100644 --- a/src/include/platform/SoftwareUpdateManagerImpl.h +++ b/src/include/platform/SoftwareUpdateManagerImpl.h @@ -30,9 +30,8 @@ namespace DeviceLayer { * Concrete implementation of the SoftwareUpdateManager singleton object for the * nRF52 platforms. */ -class SoftwareUpdateManagerImpl final - : public SoftwareUpdateManager, - public Internal::GenericSoftwareUpdateManagerImpl +class SoftwareUpdateManagerImpl final : public SoftwareUpdateManager, + public Internal::GenericSoftwareUpdateManagerImpl { // Allow the SoftwareUpdateManager interface class to delegate method calls to // the implementation methods provided by this class. @@ -43,7 +42,6 @@ class SoftwareUpdateManagerImpl final friend class Internal::GenericSoftwareUpdateManagerImpl; public: - // ===== Members for internal use by the following friends. friend ::chip::DeviceLayer::SoftwareUpdateManager & SoftwareUpdateMgr(void); diff --git a/src/include/platform/ThreadStackManager.h b/src/include/platform/ThreadStackManager.h index 2448f8deaf2d60..4f09a067c4f72f 100644 --- a/src/include/platform/ThreadStackManager.h +++ b/src/include/platform/ThreadStackManager.h @@ -34,13 +34,20 @@ class ConfigurationManagerImpl; namespace Internal { class DeviceNetworkInfo; class DeviceControlServer; -template class GenericPlatformManagerImpl; -template class GenericPlatformManagerImpl_FreeRTOS; -template class GenericConnectivityManagerImpl_Thread; -template class GenericThreadStackManagerImpl_OpenThread; -template class GenericThreadStackManagerImpl_OpenThread_LwIP; -template class GenericThreadStackManagerImpl_FreeRTOS; -template class GenericNetworkProvisioningServerImpl; +template +class GenericPlatformManagerImpl; +template +class GenericPlatformManagerImpl_FreeRTOS; +template +class GenericConnectivityManagerImpl_Thread; +template +class GenericThreadStackManagerImpl_OpenThread; +template +class GenericThreadStackManagerImpl_OpenThread_LwIP; +template +class GenericThreadStackManagerImpl_FreeRTOS; +template +class GenericNetworkProvisioningServerImpl; } // namespace Internal /** @@ -52,7 +59,6 @@ class ThreadStackManager using ImplClass = ThreadStackManagerImpl; public: - // ===== Members that define the public interface of the ThreadStackManager CHIP_ERROR InitThreadStack(void); @@ -65,24 +71,31 @@ class ThreadStackManager CHIP_ERROR GetAndLogThreadStatsCounters(void); CHIP_ERROR GetAndLogThreadTopologyMinimal(void); CHIP_ERROR GetAndLogThreadTopologyFull(void); - CHIP_ERROR GetPrimary802154MACAddress(uint8_t *buf); + CHIP_ERROR GetPrimary802154MACAddress(uint8_t * buf); private: - // ===== Members for internal use by the following friends. friend class PlatformManagerImpl; friend class ConfigurationManagerImpl; friend class Internal::BLEManagerImpl; friend class Internal::DeviceControlServer; - template friend class Internal::GenericPlatformManagerImpl; - template friend class Internal::GenericConfigurationManagerImpl; - template friend class Internal::GenericPlatformManagerImpl_FreeRTOS; - template friend class Internal::GenericConnectivityManagerImpl_Thread; - template friend class Internal::GenericThreadStackManagerImpl_OpenThread; - template friend class Internal::GenericThreadStackManagerImpl_OpenThread_LwIP; - template friend class Internal::GenericThreadStackManagerImpl_FreeRTOS; - template friend class Internal::GenericNetworkProvisioningServerImpl; + template + friend class Internal::GenericPlatformManagerImpl; + template + friend class Internal::GenericConfigurationManagerImpl; + template + friend class Internal::GenericPlatformManagerImpl_FreeRTOS; + template + friend class Internal::GenericConnectivityManagerImpl_Thread; + template + friend class Internal::GenericThreadStackManagerImpl_OpenThread; + template + friend class Internal::GenericThreadStackManagerImpl_OpenThread_LwIP; + template + friend class Internal::GenericThreadStackManagerImpl_FreeRTOS; + template + friend class Internal::GenericNetworkProvisioningServerImpl; void OnPlatformEvent(const ChipDeviceEvent * event); bool IsThreadEnabled(void); @@ -102,13 +115,12 @@ class ThreadStackManager void OnCHIPoBLEAdvertisingStop(void); protected: - // Construction/destruction limited to subclasses. - ThreadStackManager() = default; + ThreadStackManager() = default; ~ThreadStackManager() = default; // No copy, move or assignment. - ThreadStackManager(const ThreadStackManager &) = delete; + ThreadStackManager(const ThreadStackManager &) = delete; ThreadStackManager(const ThreadStackManager &&) = delete; ThreadStackManager & operator=(const ThreadStackManager &) = delete; }; @@ -147,32 +159,32 @@ namespace DeviceLayer { inline CHIP_ERROR ThreadStackManager::InitThreadStack() { - return static_cast(this)->_InitThreadStack(); + return static_cast(this)->_InitThreadStack(); } inline void ThreadStackManager::ProcessThreadActivity() { - static_cast(this)->_ProcessThreadActivity(); + static_cast(this)->_ProcessThreadActivity(); } inline CHIP_ERROR ThreadStackManager::StartThreadTask() { - return static_cast(this)->_StartThreadTask(); + return static_cast(this)->_StartThreadTask(); } inline void ThreadStackManager::LockThreadStack() { - static_cast(this)->_LockThreadStack(); + static_cast(this)->_LockThreadStack(); } inline bool ThreadStackManager::TryLockThreadStack() { - return static_cast(this)->_TryLockThreadStack(); + return static_cast(this)->_TryLockThreadStack(); } inline void ThreadStackManager::UnlockThreadStack() { - static_cast(this)->_UnlockThreadStack(); + static_cast(this)->_UnlockThreadStack(); } /** @@ -180,107 +192,107 @@ inline void ThreadStackManager::UnlockThreadStack() */ inline bool ThreadStackManager::HaveRouteToAddress(const IPAddress & destAddr) { - return static_cast(this)->_HaveRouteToAddress(destAddr); + return static_cast(this)->_HaveRouteToAddress(destAddr); } inline void ThreadStackManager::OnPlatformEvent(const chipDeviceEvent * event) { - static_cast(this)->_OnPlatformEvent(event); + static_cast(this)->_OnPlatformEvent(event); } inline bool ThreadStackManager::IsThreadEnabled(void) { - return static_cast(this)->_IsThreadEnabled(); + return static_cast(this)->_IsThreadEnabled(); } inline CHIP_ERROR ThreadStackManager::SetThreadEnabled(bool val) { - return static_cast(this)->_SetThreadEnabled(val); + return static_cast(this)->_SetThreadEnabled(val); } inline bool ThreadStackManager::IsThreadProvisioned(void) { - return static_cast(this)->_IsThreadProvisioned(); + return static_cast(this)->_IsThreadProvisioned(); } inline bool ThreadStackManager::IsThreadAttached(void) { - return static_cast(this)->_IsThreadAttached(); + return static_cast(this)->_IsThreadAttached(); } inline CHIP_ERROR ThreadStackManager::GetThreadProvision(Internal::DeviceNetworkInfo & netInfo, bool includeCredentials) { - return static_cast(this)->_GetThreadProvision(netInfo, includeCredentials); + return static_cast(this)->_GetThreadProvision(netInfo, includeCredentials); } inline CHIP_ERROR ThreadStackManager::SetThreadProvision(const Internal::DeviceNetworkInfo & netInfo) { - return static_cast(this)->_SetThreadProvision(netInfo); + return static_cast(this)->_SetThreadProvision(netInfo); } inline void ThreadStackManager::ClearThreadProvision(void) { - static_cast(this)->_ClearThreadProvision(); + static_cast(this)->_ClearThreadProvision(); } inline ConnectivityManager::ThreadDeviceType ThreadStackManager::GetThreadDeviceType(void) { - return static_cast(this)->_GetThreadDeviceType(); + return static_cast(this)->_GetThreadDeviceType(); } inline CHIP_ERROR ThreadStackManager::SetThreadDeviceType(ConnectivityManager::ThreadDeviceType deviceType) { - return static_cast(this)->_SetThreadDeviceType(deviceType); + return static_cast(this)->_SetThreadDeviceType(deviceType); } inline void ThreadStackManager::GetThreadPollingConfig(ConnectivityManager::ThreadPollingConfig & pollingConfig) { - static_cast(this)->_GetThreadPollingConfig(pollingConfig); + static_cast(this)->_GetThreadPollingConfig(pollingConfig); } inline CHIP_ERROR ThreadStackManager::SetThreadPollingConfig(const ConnectivityManager::ThreadPollingConfig & pollingConfig) { - return static_cast(this)->_SetThreadPollingConfig(pollingConfig); + return static_cast(this)->_SetThreadPollingConfig(pollingConfig); } inline bool ThreadStackManager::HaveMeshConnectivity(void) { - return static_cast(this)->_HaveMeshConnectivity(); + return static_cast(this)->_HaveMeshConnectivity(); } inline void ThreadStackManager::OnMessageLayerActivityChanged(bool messageLayerIsActive) { - return static_cast(this)->_OnMessageLayerActivityChanged(messageLayerIsActive); + return static_cast(this)->_OnMessageLayerActivityChanged(messageLayerIsActive); } inline void ThreadStackManager::OnCHIPoBLEAdvertisingStart(void) { - static_cast(this)->_OnCHIPoBLEAdvertisingStart(); + static_cast(this)->_OnCHIPoBLEAdvertisingStart(); } inline void ThreadStackManager::OnCHIPoBLEAdvertisingStop(void) { - static_cast(this)->_OnCHIPoBLEAdvertisingStop(); + static_cast(this)->_OnCHIPoBLEAdvertisingStop(); } inline CHIP_ERROR ThreadStackManager::GetAndLogThreadStatsCounters(void) { - return static_cast(this)->_GetAndLogThreadStatsCounters(); + return static_cast(this)->_GetAndLogThreadStatsCounters(); } inline CHIP_ERROR ThreadStackManager::GetAndLogThreadTopologyMinimal(void) { - return static_cast(this)->_GetAndLogThreadTopologyMinimal(); + return static_cast(this)->_GetAndLogThreadTopologyMinimal(); } inline CHIP_ERROR ThreadStackManager::GetAndLogThreadTopologyFull(void) { - return static_cast(this)->_GetAndLogThreadTopologyFull(); + return static_cast(this)->_GetAndLogThreadTopologyFull(); } inline CHIP_ERROR ThreadStackManager::GetPrimary802154MACAddress(uint8_t * buf) { - return static_cast(this)->_GetPrimary802154MACAddress(buf); + return static_cast(this)->_GetPrimary802154MACAddress(buf); } } // namespace DeviceLayer diff --git a/src/include/platform/TimeSyncManager.h b/src/include/platform/TimeSyncManager.h index 2ff992c53efeef..8d150af3a1c078 100644 --- a/src/include/platform/TimeSyncManager.h +++ b/src/include/platform/TimeSyncManager.h @@ -30,8 +30,8 @@ namespace Profiles { namespace StatusReporting { class StatusReport; } -} -} +} // namespace Profiles +} // namespace chip namespace chip { namespace DeviceLayer { @@ -39,9 +39,11 @@ namespace DeviceLayer { class PlatformManagerImpl; namespace Internal { extern CHIP_ERROR InitServiceDirectoryManager(void); -template class GenericPlatformManagerImpl; -template class GenericPlatformManagerImpl_FreeRTOS; -} +template +class GenericPlatformManagerImpl; +template +class GenericPlatformManagerImpl_FreeRTOS; +} // namespace Internal /** * Manages time synchronization for chip Devices. @@ -49,14 +51,13 @@ template class GenericPlatformManagerImpl_FreeRTOS; class TimeSyncManager final { public: - // ===== Members that define the public interface of the TimeSyncManager enum TimeSyncMode { - kTimeSyncMode_NotSupported = 0, - kTimeSyncMode_Disabled = 1, - kTimeSyncMode_Service = 2, + kTimeSyncMode_NotSupported = 0, + kTimeSyncMode_Disabled = 1, + kTimeSyncMode_Service = 2, kTimeSyncMode_Max, }; @@ -70,12 +71,13 @@ class TimeSyncManager final bool IsTimeSynchronized(); private: - // ===== Members for internal use by the following friends. friend class PlatformManagerImpl; - template friend class Internal::GenericPlatformManagerImpl; - template friend class Internal::GenericPlatformManagerImpl_FreeRTOS; + template + friend class Internal::GenericPlatformManagerImpl; + template + friend class Internal::GenericPlatformManagerImpl_FreeRTOS; friend CHIP_ERROR Internal::InitServiceDirectoryManager(); friend TimeSyncManager & TimeSyncMgr(void); @@ -107,20 +109,20 @@ class TimeSyncManager final #if CHIP_DEVICE_CONFIG_ENABLE_CHIP_TIME_SERVICE_TIME_SYNC static void TimeServiceSync_HandleBindingEvent(void * appState, ::chip::Binding::EventType event, - const ::chip::Binding::InEventParam & inParam, ::chip::Binding::OutEventParam & outParam); + const ::chip::Binding::InEventParam & inParam, + ::chip::Binding::OutEventParam & outParam); static void TimeServiceSync_HandleSyncComplete(void * context, CHIP_ERROR result, int64_t syncedRealTimeUS); #endif static void DriveTimeSync(::chip::System::Layer * layer, void * appState, ::chip::System::Error err); protected: - // Construction/destruction limited to subclasses. - TimeSyncManager() = default; + TimeSyncManager() = default; ~TimeSyncManager() = default; // No copy, move or assignment. - TimeSyncManager(const TimeSyncManager &) = delete; + TimeSyncManager(const TimeSyncManager &) = delete; TimeSyncManager(const TimeSyncManager &&) = delete; TimeSyncManager & operator=(const TimeSyncManager &) = delete; }; diff --git a/src/include/platform/internal/BLEManager.h b/src/include/platform/internal/BLEManager.h index 03e12bf5b31fb0..2a79c969981d68 100644 --- a/src/include/platform/internal/BLEManager.h +++ b/src/include/platform/internal/BLEManager.h @@ -46,7 +46,6 @@ class BLEManager using ImplClass = BLEManagerImpl; public: - // ===== Members that define the internal interface of the BLEManager using CHIPoBLEServiceMode = ConnectivityManager::CHIPoBLEServiceMode; @@ -66,13 +65,12 @@ class BLEManager chip::Ble::BleLayer * GetBleLayer(void) const; protected: - // Construction/destruction limited to subclasses. - BLEManager() = default; + BLEManager() = default; ~BLEManager() = default; // No copy, move or assignment. - BLEManager(const BLEManager &) = delete; + BLEManager(const BLEManager &) = delete; BLEManager(const BLEManager &&) = delete; BLEManager & operator=(const BLEManager &) = delete; }; @@ -113,66 +111,64 @@ namespace Internal { inline CHIP_ERROR BLEManager::Init(void) { - return static_cast(this)->_Init(); + return static_cast(this)->_Init(); } inline BLEManager::CHIPoBLEServiceMode BLEManager::GetCHIPoBLEServiceMode(void) { - return static_cast(this)->_GetCHIPoBLEServiceMode(); + return static_cast(this)->_GetCHIPoBLEServiceMode(); } inline CHIP_ERROR BLEManager::SetCHIPoBLEServiceMode(CHIPoBLEServiceMode val) { - return static_cast(this)->_SetCHIPoBLEServiceMode(val); + return static_cast(this)->_SetCHIPoBLEServiceMode(val); } inline bool BLEManager::IsAdvertisingEnabled(void) { - return static_cast(this)->_IsAdvertisingEnabled(); + return static_cast(this)->_IsAdvertisingEnabled(); } inline CHIP_ERROR BLEManager::SetAdvertisingEnabled(bool val) { - return static_cast(this)->_SetAdvertisingEnabled(val); + return static_cast(this)->_SetAdvertisingEnabled(val); } inline bool BLEManager::IsFastAdvertisingEnabled(void) { - return static_cast(this)->_IsFastAdvertisingEnabled(); + return static_cast(this)->_IsFastAdvertisingEnabled(); } inline CHIP_ERROR BLEManager::SetFastAdvertisingEnabled(bool val) { - return static_cast(this)->_SetFastAdvertisingEnabled(val); + return static_cast(this)->_SetFastAdvertisingEnabled(val); } inline bool BLEManager::IsAdvertising(void) { - return static_cast(this)->_IsAdvertising(); + return static_cast(this)->_IsAdvertising(); } inline CHIP_ERROR BLEManager::GetDeviceName(char * buf, size_t bufSize) { - return static_cast(this)->_GetDeviceName(buf, bufSize); + return static_cast(this)->_GetDeviceName(buf, bufSize); } inline CHIP_ERROR BLEManager::SetDeviceName(const char * deviceName) { - return static_cast(this)->_SetDeviceName(deviceName); + return static_cast(this)->_SetDeviceName(deviceName); } inline uint16_t BLEManager::NumConnections(void) { - return static_cast(this)->_NumConnections(); + return static_cast(this)->_NumConnections(); } -inline void BLEManager::OnPlatformEvent(const ChipDeviceEvent * event) -{ -} +inline void BLEManager::OnPlatformEvent(const ChipDeviceEvent * event) {} inline chip::Ble::BleLayer * BLEManager::GetBleLayer(void) const { - return static_cast(this)->_GetBleLayer(); + return static_cast(this)->_GetBleLayer(); } } // namespace Internal @@ -182,5 +178,3 @@ inline chip::Ble::BleLayer * BLEManager::GetBleLayer(void) const #endif // CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE #endif // BLE_MANAGER_H - - diff --git a/src/include/platform/internal/DeviceDescriptionServer.h b/src/include/platform/internal/DeviceDescriptionServer.h index d3908cc5326597..eb552121044ac0 100644 --- a/src/include/platform/internal/DeviceDescriptionServer.h +++ b/src/include/platform/internal/DeviceDescriptionServer.h @@ -34,13 +34,11 @@ namespace Internal { /** * Implements the chip Device Description profile for a chip device. */ -class DeviceDescriptionServer final - : public ::chip::Profiles::DeviceDescription::DeviceDescriptionServer +class DeviceDescriptionServer final : public ::chip::Profiles::DeviceDescription::DeviceDescriptionServer { typedef ::chip::Profiles::DeviceDescription::DeviceDescriptionServer ServerBaseClass; public: - // ===== Members for internal use by other Device Layer components. CHIP_ERROR Init(); @@ -53,7 +51,6 @@ class DeviceDescriptionServer final void OnPlatformEvent(const ChipDeviceEvent * event); private: - // ===== Members for internal use by the following friends. friend DeviceDescriptionServer & DeviceDescriptionSvr(void); @@ -70,18 +67,17 @@ class DeviceDescriptionServer final uint32_t mUserSelectedModeEndTime; // Monotonic system time scaled to units of 1024ms. uint16_t mUserSelectedModeTimeoutSec; - static void HandleIdentifyRequest(void *appState, uint64_t nodeId, const IPAddress& nodeAddr, - const ::chip::Profiles::DeviceDescription::IdentifyRequestMessage& reqMsg, bool& sendResp, - ::chip::Profiles::DeviceDescription::IdentifyResponseMessage& respMsg); + static void HandleIdentifyRequest(void * appState, uint64_t nodeId, const IPAddress & nodeAddr, + const ::chip::Profiles::DeviceDescription::IdentifyRequestMessage & reqMsg, bool & sendResp, + ::chip::Profiles::DeviceDescription::IdentifyResponseMessage & respMsg); protected: - // Construction/destruction limited to subclasses. - DeviceDescriptionServer() = default; + DeviceDescriptionServer() = default; ~DeviceDescriptionServer() = default; // No copy, move or assignment. - DeviceDescriptionServer(const DeviceDescriptionServer &) = delete; + DeviceDescriptionServer(const DeviceDescriptionServer &) = delete; DeviceDescriptionServer(const DeviceDescriptionServer &&) = delete; DeviceDescriptionServer & operator=(const DeviceDescriptionServer &) = delete; }; @@ -98,5 +94,4 @@ inline DeviceDescriptionServer & DeviceDescriptionSvr(void) } // namespace DeviceLayer } // namespace chip - #endif // DEVICE_DESCRIPTION_SERVER_H diff --git a/src/include/platform/internal/GenericConfigurationManagerImpl.h b/src/include/platform/internal/GenericConfigurationManagerImpl.h index 2a434df04122eb..4e417bddb6a3e4 100644 --- a/src/include/platform/internal/GenericConfigurationManagerImpl.h +++ b/src/include/platform/internal/GenericConfigurationManagerImpl.h @@ -41,11 +41,10 @@ namespace Internal { * or indirectly) by the ConfigurationManagerImpl class, which also appears as the template's ImplClass * parameter. */ -template +template class GenericConfigurationManagerImpl { public: - // ===== Methods that implement the ConfigurationManager abstract interface. CHIP_ERROR _Init(); @@ -55,8 +54,8 @@ class GenericConfigurationManagerImpl CHIP_ERROR _GetProductRevision(uint16_t & productRev); CHIP_ERROR _StoreProductRevision(uint16_t productRev); CHIP_ERROR _GetFirmwareRevision(char * buf, size_t bufSize, size_t & outLen); - CHIP_ERROR _GetFirmwareBuildTime(uint16_t & year, uint8_t & month, uint8_t & dayOfMonth, - uint8_t & hour, uint8_t & minute, uint8_t & second); + CHIP_ERROR _GetFirmwareBuildTime(uint16_t & year, uint8_t & month, uint8_t & dayOfMonth, uint8_t & hour, uint8_t & minute, + uint8_t & second); CHIP_ERROR _GetSerialNumber(char * buf, size_t bufSize, size_t & serialNumLen); CHIP_ERROR _StoreSerialNumber(const char * serialNum, size_t serialNumLen); CHIP_ERROR _GetPrimaryWiFiMACAddress(uint8_t * buf); @@ -93,8 +92,8 @@ class GenericConfigurationManagerImpl CHIP_ERROR _StoreServiceConfig(const uint8_t * serviceConfig, size_t serviceConfigLen); CHIP_ERROR _GetPairedAccountId(char * buf, size_t bufSize, size_t & accountIdLen); CHIP_ERROR _StorePairedAccountId(const char * accountId, size_t accountIdLen); - CHIP_ERROR _StoreServiceProvisioningData(uint64_t serviceId, const uint8_t * serviceConfig, - size_t serviceConfigLen, const char * accountId, size_t accountIdLen); + CHIP_ERROR _StoreServiceProvisioningData(uint64_t serviceId, const uint8_t * serviceConfig, size_t serviceConfigLen, + const char * accountId, size_t accountIdLen); CHIP_ERROR _ClearServiceProvisioningData(); CHIP_ERROR _GetFailSafeArmed(bool & val); CHIP_ERROR _SetFailSafeArmed(bool val); @@ -113,7 +112,6 @@ class GenericConfigurationManagerImpl #endif protected: - enum { kFlag_IsServiceProvisioned = 0x01, @@ -129,7 +127,6 @@ class GenericConfigurationManagerImpl CHIP_ERROR PersistProvisioningData(ProvisioningDataSet & provData); private: - ImplClass * Impl() { return static_cast(this); } #if CHIP_DEVICE_CONFIG_ENABLE_JUST_IN_TIME_PROVISIONING @@ -140,23 +137,20 @@ class GenericConfigurationManagerImpl // Instruct the compiler to instantiate the template only when explicitly told to do so. extern template class Internal::GenericConfigurationManagerImpl; -template +template inline CHIP_ERROR GenericConfigurationManagerImpl::_GetVendorId(uint16_t & vendorId) { - vendorId = (uint16_t)CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID; + vendorId = (uint16_t) CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID; return CHIP_NO_ERROR; } -template +template inline CHIP_ERROR GenericConfigurationManagerImpl::_GetProductId(uint16_t & productId) { - productId = (uint16_t)CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID; + productId = (uint16_t) CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID; return CHIP_NO_ERROR; } - - - } // namespace Internal } // namespace DeviceLayer } // namespace chip diff --git a/src/include/platform/internal/GenericConnectivityManagerImpl.h b/src/include/platform/internal/GenericConnectivityManagerImpl.h index 2b2486427f123f..b2f7d755fe795f 100644 --- a/src/include/platform/internal/GenericConnectivityManagerImpl.h +++ b/src/include/platform/internal/GenericConnectivityManagerImpl.h @@ -37,11 +37,10 @@ namespace Internal { * or indirectly) by the ConfigurationManagerImpl class, which also appears as the template's ImplClass * parameter. */ -template +template class GenericConnectivityManagerImpl { public: - // ===== Methods that implement the ConnectivityManager abstract interface. bool _IsUserSelectedModeActive(void); @@ -50,32 +49,28 @@ class GenericConnectivityManagerImpl void _SetUserSelectedModeTimeout(uint16_t val); private: - ImplClass * Impl() { return static_cast(this); } }; -template +template inline bool GenericConnectivityManagerImpl::_IsUserSelectedModeActive(void) { return false; } -template +template inline void GenericConnectivityManagerImpl::_SetUserSelectedMode(bool val) -{ -} +{} -template +template inline uint16_t GenericConnectivityManagerImpl::_GetUserSelectedModeTimeout(void) { return 0; } -template +template inline void GenericConnectivityManagerImpl::_SetUserSelectedModeTimeout(uint16_t val) -{ -} - +{} } // namespace Internal } // namespace DeviceLayer diff --git a/src/include/platform/internal/GenericConnectivityManagerImpl_BLE.h b/src/include/platform/internal/GenericConnectivityManagerImpl_BLE.h index 4313b87ccc72a3..1c3fe253745142 100644 --- a/src/include/platform/internal/GenericConnectivityManagerImpl_BLE.h +++ b/src/include/platform/internal/GenericConnectivityManagerImpl_BLE.h @@ -34,7 +34,6 @@ class ConnectivityManagerImpl; namespace Internal { - /** * Provides a generic implementation of BLE-specific ConnectivityManager features for * platforms where BLE functionality is implemented by the BLEManager class. @@ -47,11 +46,10 @@ namespace Internal { * BLE support to the BLEManager class, is standard on platforms that support BLE, and helps to * limit the complexity of the ConnectivityManagerImpl class. */ -template +template class GenericConnectivityManagerImpl_BLE { public: - // ===== Methods that implement the ConnectivityManager abstract interface. ConnectivityManager::CHIPoBLEServiceMode _GetCHIPoBLEServiceMode(void); @@ -67,68 +65,68 @@ class GenericConnectivityManagerImpl_BLE static const char * _CHIPoBLEServiceModeToStr(ConnectivityManager::CHIPoBLEServiceMode mode); private: - ImplClass * Impl() { return static_cast(this); } }; // Instruct the compiler to instantiate the template only when explicitly told to do so. extern template class GenericConnectivityManagerImpl_BLE; -template +template inline ConnectivityManager::CHIPoBLEServiceMode GenericConnectivityManagerImpl_BLE::_GetCHIPoBLEServiceMode(void) { return BLEMgr().GetCHIPoBLEServiceMode(); } -template -inline CHIP_ERROR GenericConnectivityManagerImpl_BLE::_SetCHIPoBLEServiceMode(ConnectivityManager::CHIPoBLEServiceMode val) +template +inline CHIP_ERROR +GenericConnectivityManagerImpl_BLE::_SetCHIPoBLEServiceMode(ConnectivityManager::CHIPoBLEServiceMode val) { return BLEMgr().SetCHIPoBLEServiceMode(val); } -template +template inline bool GenericConnectivityManagerImpl_BLE::_IsBLEAdvertisingEnabled(void) { return BLEMgr().IsAdvertisingEnabled(); } -template +template inline CHIP_ERROR GenericConnectivityManagerImpl_BLE::_SetBLEAdvertisingEnabled(bool val) { return BLEMgr().SetAdvertisingEnabled(val); } -template +template inline bool GenericConnectivityManagerImpl_BLE::_IsBLEFastAdvertisingEnabled(void) { return BLEMgr().IsFastAdvertisingEnabled(); } -template +template inline CHIP_ERROR GenericConnectivityManagerImpl_BLE::_SetBLEFastAdvertisingEnabled(bool val) { return BLEMgr().SetFastAdvertisingEnabled(val); } -template +template inline bool GenericConnectivityManagerImpl_BLE::_IsBLEAdvertising(void) { return BLEMgr().IsAdvertising(); } -template +template inline CHIP_ERROR GenericConnectivityManagerImpl_BLE::_GetBLEDeviceName(char * buf, size_t bufSize) { return BLEMgr().GetDeviceName(buf, bufSize); } -template +template inline CHIP_ERROR GenericConnectivityManagerImpl_BLE::_SetBLEDeviceName(const char * deviceName) { return BLEMgr().SetDeviceName(deviceName); } -template +template inline uint16_t GenericConnectivityManagerImpl_BLE::_NumBLEConnections(void) { return BLEMgr().NumConnections(); diff --git a/src/include/platform/internal/GenericConnectivityManagerImpl_NoBLE.h b/src/include/platform/internal/GenericConnectivityManagerImpl_NoBLE.h index 75002bb47740f0..c54dd2510ffbe8 100644 --- a/src/include/platform/internal/GenericConnectivityManagerImpl_NoBLE.h +++ b/src/include/platform/internal/GenericConnectivityManagerImpl_NoBLE.h @@ -47,11 +47,10 @@ namespace Internal { * } * ``` */ -template +template class GenericConnectivityManagerImpl_NoBLE { public: - // ===== Methods that implement the ConnectivityManager abstract interface. ConnectivityManager::CHIPoBLEServiceMode _GetCHIPoBLEServiceMode(void); @@ -67,72 +66,73 @@ class GenericConnectivityManagerImpl_NoBLE static const char * _CHIPoBLEServiceModeToStr(ConnectivityManager::CHIPoBLEServiceMode mode); private: - ImplClass * Impl() { return static_cast(this); } }; -template +template inline ConnectivityManager::CHIPoBLEServiceMode GenericConnectivityManagerImpl_NoBLE::_GetCHIPoBLEServiceMode(void) { return ConnectivityManager::kCHIPoBLEServiceMode_NotSupported; } -template -inline CHIP_ERROR GenericConnectivityManagerImpl_NoBLE::_SetCHIPoBLEServiceMode(ConnectivityManager::CHIPoBLEServiceMode val) +template +inline CHIP_ERROR +GenericConnectivityManagerImpl_NoBLE::_SetCHIPoBLEServiceMode(ConnectivityManager::CHIPoBLEServiceMode val) { return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; } -template +template inline bool GenericConnectivityManagerImpl_NoBLE::_IsBLEAdvertisingEnabled(void) { return false; } -template +template inline CHIP_ERROR GenericConnectivityManagerImpl_NoBLE::_SetBLEAdvertisingEnabled(bool val) { return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; } -template +template inline bool GenericConnectivityManagerImpl_NoBLE::_IsBLEFastAdvertisingEnabled(void) { return false; } -template +template inline CHIP_ERROR GenericConnectivityManagerImpl_NoBLE::_SetBLEFastAdvertisingEnabled(bool val) { return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; } -template +template inline bool GenericConnectivityManagerImpl_NoBLE::_IsBLEAdvertising(void) { return false; } -template +template inline CHIP_ERROR GenericConnectivityManagerImpl_NoBLE::_GetBLEDeviceName(char * buf, size_t bufSize) { return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; } -template +template inline CHIP_ERROR GenericConnectivityManagerImpl_NoBLE::_SetBLEDeviceName(const char * deviceName) { return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; } -template +template inline uint16_t GenericConnectivityManagerImpl_NoBLE::_NumBLEConnections(void) { return false; } -template -inline const char * GenericConnectivityManagerImpl_NoBLE::_CHIPoBLEServiceModeToStr(ConnectivityManager::CHIPoBLEServiceMode mode) +template +inline const char * +GenericConnectivityManagerImpl_NoBLE::_CHIPoBLEServiceModeToStr(ConnectivityManager::CHIPoBLEServiceMode mode) { return NULL; } diff --git a/src/include/platform/internal/GenericConnectivityManagerImpl_NoThread.h b/src/include/platform/internal/GenericConnectivityManagerImpl_NoThread.h index bbce5bb86a755e..61389b472965ee 100644 --- a/src/include/platform/internal/GenericConnectivityManagerImpl_NoThread.h +++ b/src/include/platform/internal/GenericConnectivityManagerImpl_NoThread.h @@ -37,11 +37,10 @@ namespace Internal { * class, which also appears as the template's ImplClass parameter. * */ -template +template class GenericConnectivityManagerImpl_NoThread { protected: - // ===== Methods that implement the ConnectivityManager abstract interface. ConnectivityManager::ThreadMode _GetThreadMode(void); @@ -60,72 +59,74 @@ class GenericConnectivityManagerImpl_NoThread ImplClass * Impl() { return static_cast(this); } }; -template +template inline ConnectivityManager::ThreadMode GenericConnectivityManagerImpl_NoThread::_GetThreadMode(void) { return ConnectivityManager::kThreadMode_NotSupported; } -template +template inline CHIP_ERROR GenericConnectivityManagerImpl_NoThread::_SetThreadMode(ConnectivityManager::ThreadMode val) { return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; } -template +template inline bool GenericConnectivityManagerImpl_NoThread::_IsThreadEnabled(void) { return false; } -template +template inline bool GenericConnectivityManagerImpl_NoThread::_IsThreadApplicationControlled(void) { return false; } -template +template inline bool GenericConnectivityManagerImpl_NoThread::_IsThreadAttached(void) { return false; } -template +template inline bool GenericConnectivityManagerImpl_NoThread::_IsThreadProvisioned(void) { return false; } -template +template inline void GenericConnectivityManagerImpl_NoThread::_ClearThreadProvision(void) -{ -} +{} -template +template inline ConnectivityManager::ThreadDeviceType GenericConnectivityManagerImpl_NoThread::_GetThreadDeviceType(void) { return ConnectivityManager::kThreadDeviceType_NotSupported; } -template -inline CHIP_ERROR GenericConnectivityManagerImpl_NoThread::_SetThreadDeviceType(ConnectivityManager::ThreadDeviceType deviceType) +template +inline CHIP_ERROR +GenericConnectivityManagerImpl_NoThread::_SetThreadDeviceType(ConnectivityManager::ThreadDeviceType deviceType) { return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; } -template -inline void GenericConnectivityManagerImpl_NoThread::_GetThreadPollingConfig(ConnectivityManager::ThreadPollingConfig & pollingConfig) +template +inline void GenericConnectivityManagerImpl_NoThread::_GetThreadPollingConfig( + ConnectivityManager::ThreadPollingConfig & pollingConfig) { pollingConfig.Clear(); } -template -inline CHIP_ERROR GenericConnectivityManagerImpl_NoThread::_SetThreadPollingConfig(const ConnectivityManager::ThreadPollingConfig & pollingConfig) +template +inline CHIP_ERROR GenericConnectivityManagerImpl_NoThread::_SetThreadPollingConfig( + const ConnectivityManager::ThreadPollingConfig & pollingConfig) { return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; } -template +template inline bool GenericConnectivityManagerImpl_NoThread::_HaveServiceConnectivityViaThread(void) { return false; diff --git a/src/include/platform/internal/GenericConnectivityManagerImpl_NoTunnel.h b/src/include/platform/internal/GenericConnectivityManagerImpl_NoTunnel.h index e85d27542eb781..d7bca1bc1dff68 100644 --- a/src/include/platform/internal/GenericConnectivityManagerImpl_NoTunnel.h +++ b/src/include/platform/internal/GenericConnectivityManagerImpl_NoTunnel.h @@ -47,11 +47,10 @@ namespace Internal { * } * ``` */ -template +template class GenericConnectivityManagerImpl_NoTunnel { public: - // ===== Methods that implement the ConnectivityManager abstract interface. ConnectivityManager::ServiceTunnelMode _GetServiceTunnelMode(void); @@ -62,47 +61,47 @@ class GenericConnectivityManagerImpl_NoTunnel static const char * _ServiceTunnelModeToStr(ConnectivityManager::ServiceTunnelMode mode); private: - ImplClass * Impl() { return static_cast(this); } }; -template +template inline ConnectivityManager::ServiceTunnelMode GenericConnectivityManagerImpl_NoTunnel::_GetServiceTunnelMode(void) { return ConnectivityManager::kServiceTunnelMode_NotSupported; } -template -inline CHIP_ERROR GenericConnectivityManagerImpl_NoTunnel::_SetServiceTunnelMode(ConnectivityManager::ServiceTunnelMode val) +template +inline CHIP_ERROR +GenericConnectivityManagerImpl_NoTunnel::_SetServiceTunnelMode(ConnectivityManager::ServiceTunnelMode val) { return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; } -template +template inline bool GenericConnectivityManagerImpl_NoTunnel::_IsServiceTunnelConnected(void) { return false; } -template +template inline bool GenericConnectivityManagerImpl_NoTunnel::_IsServiceTunnelRestricted(void) { return false; } -template +template inline bool GenericConnectivityManagerImpl_NoTunnel::_HaveServiceConnectivityViaTunnel(void) { return false; } -template -inline const char * GenericConnectivityManagerImpl_NoTunnel::_ServiceTunnelModeToStr(ConnectivityManager::ServiceTunnelMode mode) +template +inline const char * +GenericConnectivityManagerImpl_NoTunnel::_ServiceTunnelModeToStr(ConnectivityManager::ServiceTunnelMode mode) { return NULL; } - } // namespace Internal } // namespace DeviceLayer } // namespace chip diff --git a/src/include/platform/internal/GenericConnectivityManagerImpl_NoWiFi.h b/src/include/platform/internal/GenericConnectivityManagerImpl_NoWiFi.h index 4fa0f07a53659c..fb480092e5b8a2 100644 --- a/src/include/platform/internal/GenericConnectivityManagerImpl_NoWiFi.h +++ b/src/include/platform/internal/GenericConnectivityManagerImpl_NoWiFi.h @@ -47,11 +47,10 @@ namespace Internal { * } * ``` */ -template +template class GenericConnectivityManagerImpl_NoWiFi { public: - // ===== Methods that implement the ConnectivityManager abstract interface. ConnectivityManager::WiFiStationMode _GetWiFiStationMode(void); @@ -80,142 +79,134 @@ class GenericConnectivityManagerImpl_NoWiFi static const char * _WiFiAPModeToStr(ConnectivityManager::WiFiAPMode mode); private: - ImplClass * Impl() { return static_cast(this); } }; -template +template inline ConnectivityManager::WiFiStationMode GenericConnectivityManagerImpl_NoWiFi::_GetWiFiStationMode(void) { return ConnectivityManager::kWiFiStationMode_NotSupported; } -template +template inline CHIP_ERROR GenericConnectivityManagerImpl_NoWiFi::_SetWiFiStationMode(ConnectivityManager::WiFiStationMode val) { return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; } -template +template inline bool GenericConnectivityManagerImpl_NoWiFi::_IsWiFiStationEnabled(void) { return false; } -template +template inline bool GenericConnectivityManagerImpl_NoWiFi::_IsWiFiStationConnected(void) { return false; } -template +template inline uint32_t GenericConnectivityManagerImpl_NoWiFi::_GetWiFiStationReconnectIntervalMS(void) { return 0; } -template +template inline CHIP_ERROR GenericConnectivityManagerImpl_NoWiFi::_SetWiFiStationReconnectIntervalMS(uint32_t val) { return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; } -template +template inline bool GenericConnectivityManagerImpl_NoWiFi::_IsWiFiStationProvisioned(void) { return false; } -template +template inline void GenericConnectivityManagerImpl_NoWiFi::_ClearWiFiStationProvision(void) -{ -} +{} -template +template inline ConnectivityManager::WiFiAPMode GenericConnectivityManagerImpl_NoWiFi::_GetWiFiAPMode(void) { return ConnectivityManager::kWiFiAPMode_NotSupported; } -template +template inline CHIP_ERROR GenericConnectivityManagerImpl_NoWiFi::_SetWiFiAPMode(ConnectivityManager::WiFiAPMode val) { return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; } -template +template inline bool GenericConnectivityManagerImpl_NoWiFi::_IsWiFiAPActive(void) { return false; } -template +template inline bool GenericConnectivityManagerImpl_NoWiFi::_IsWiFiAPApplicationControlled(void) { return false; } -template +template inline void GenericConnectivityManagerImpl_NoWiFi::_DemandStartWiFiAP(void) -{ -} +{} -template +template inline void GenericConnectivityManagerImpl_NoWiFi::_StopOnDemandWiFiAP(void) -{ -} +{} -template +template inline void GenericConnectivityManagerImpl_NoWiFi::_MaintainOnDemandWiFiAP(void) -{ -} +{} -template +template inline uint32_t GenericConnectivityManagerImpl_NoWiFi::_GetWiFiAPIdleTimeoutMS(void) { return 0; } -template +template inline void GenericConnectivityManagerImpl_NoWiFi::_SetWiFiAPIdleTimeoutMS(uint32_t val) -{ -} +{} -template +template inline CHIP_ERROR GenericConnectivityManagerImpl_NoWiFi::_GetAndLogWifiStatsCounters(void) { return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; } -template +template inline bool GenericConnectivityManagerImpl_NoWiFi::_CanStartWiFiScan() { return false; } -template +template inline void GenericConnectivityManagerImpl_NoWiFi::_OnWiFiScanDone() -{ -} +{} -template +template inline void GenericConnectivityManagerImpl_NoWiFi::_OnWiFiStationProvisionChange() -{ -} +{} -template -inline const char * GenericConnectivityManagerImpl_NoWiFi::_WiFiStationModeToStr(ConnectivityManager::WiFiStationMode mode) +template +inline const char * +GenericConnectivityManagerImpl_NoWiFi::_WiFiStationModeToStr(ConnectivityManager::WiFiStationMode mode) { return NULL; } -template +template inline const char * GenericConnectivityManagerImpl_NoWiFi::_WiFiAPModeToStr(ConnectivityManager::WiFiAPMode mode) { return NULL; } - } // namespace Internal } // namespace DeviceLayer } // namespace chip diff --git a/src/include/platform/internal/GenericConnectivityManagerImpl_Thread.h b/src/include/platform/internal/GenericConnectivityManagerImpl_Thread.h index e4666c8ca37a90..aa1097dd252ed6 100644 --- a/src/include/platform/internal/GenericConnectivityManagerImpl_Thread.h +++ b/src/include/platform/internal/GenericConnectivityManagerImpl_Thread.h @@ -46,11 +46,10 @@ namespace Internal { * APIs. This is achieved by delegating all stack-specific operations to the ThreadStackManager class. * */ -template +template class GenericConnectivityManagerImpl_Thread { protected: - // ===== Methods that implement the ConnectivityManager abstract interface. void _Init(void); @@ -73,13 +72,12 @@ class GenericConnectivityManagerImpl_Thread void UpdateServiceConnectivity(void); private: - // ===== Private members reserved for use by this class only. enum Flags { - kFlag_HaveServiceConnectivity = 0x01, - kFlag_IsApplicationControlled = 0x02 + kFlag_HaveServiceConnectivity = 0x01, + kFlag_IsApplicationControlled = 0x02 }; uint8_t mFlags; @@ -90,67 +88,70 @@ class GenericConnectivityManagerImpl_Thread // Instruct the compiler to instantiate the template only when explicitly told to do so. extern template class GenericConnectivityManagerImpl_Thread; -template +template inline void GenericConnectivityManagerImpl_Thread::_Init(void) { mFlags = 0; } -template +template inline bool GenericConnectivityManagerImpl_Thread::_IsThreadEnabled(void) { return ThreadStackMgrImpl().IsThreadEnabled(); } -template +template inline bool GenericConnectivityManagerImpl_Thread::_IsThreadApplicationControlled(void) { return GetFlag(mFlags, kFlag_IsApplicationControlled); } -template +template inline bool GenericConnectivityManagerImpl_Thread::_IsThreadAttached(void) { return ThreadStackMgrImpl().IsThreadAttached(); } -template +template inline bool GenericConnectivityManagerImpl_Thread::_IsThreadProvisioned(void) { return ThreadStackMgrImpl().IsThreadProvisioned(); } -template +template inline void GenericConnectivityManagerImpl_Thread::_ClearThreadProvision(void) { ThreadStackMgrImpl().ClearThreadProvision(); } -template +template inline ConnectivityManager::ThreadDeviceType GenericConnectivityManagerImpl_Thread::_GetThreadDeviceType(void) { return ThreadStackMgrImpl().GetThreadDeviceType(); } -template -inline CHIP_ERROR GenericConnectivityManagerImpl_Thread::_SetThreadDeviceType(ConnectivityManager::ThreadDeviceType deviceType) +template +inline CHIP_ERROR +GenericConnectivityManagerImpl_Thread::_SetThreadDeviceType(ConnectivityManager::ThreadDeviceType deviceType) { return ThreadStackMgrImpl().SetThreadDeviceType(deviceType); } -template -inline void GenericConnectivityManagerImpl_Thread::_GetThreadPollingConfig(ConnectivityManager::ThreadPollingConfig & pollingConfig) +template +inline void +GenericConnectivityManagerImpl_Thread::_GetThreadPollingConfig(ConnectivityManager::ThreadPollingConfig & pollingConfig) { ThreadStackMgrImpl().GetThreadPollingConfig(pollingConfig); } -template -inline CHIP_ERROR GenericConnectivityManagerImpl_Thread::_SetThreadPollingConfig(const ConnectivityManager::ThreadPollingConfig & pollingConfig) +template +inline CHIP_ERROR GenericConnectivityManagerImpl_Thread::_SetThreadPollingConfig( + const ConnectivityManager::ThreadPollingConfig & pollingConfig) { return ThreadStackMgrImpl().SetThreadPollingConfig(pollingConfig); } -template +template inline bool GenericConnectivityManagerImpl_Thread::_HaveServiceConnectivityViaThread(void) { return GetFlag(mFlags, kFlag_HaveServiceConnectivity); diff --git a/src/include/platform/internal/GenericPlatformManagerImpl.h b/src/include/platform/internal/GenericPlatformManagerImpl.h index bcd175bc959a88..60a3788e349397 100644 --- a/src/include/platform/internal/GenericPlatformManagerImpl.h +++ b/src/include/platform/internal/GenericPlatformManagerImpl.h @@ -37,11 +37,10 @@ namespace Internal { * or indirectly) by the PlatformManagerImpl class, which also appears as the template's ImplClass * parameter. */ -template +template class GenericPlatformManagerImpl { protected: - struct AppEventHandler { AppEventHandler * Next; @@ -69,7 +68,7 @@ class GenericPlatformManagerImpl private: bool mMsgLayerWasActive; - ImplClass * Impl() { return static_cast(this); } + ImplClass * Impl() { return static_cast(this); } }; // Instruct the compiler to instantiate the template only when explicitly told to do so. diff --git a/src/include/platform/internal/GenericPlatformManagerImpl_FreeRTOS.h b/src/include/platform/internal/GenericPlatformManagerImpl_FreeRTOS.h index 5df9995e7a365d..cfb8471637ddee 100644 --- a/src/include/platform/internal/GenericPlatformManagerImpl_FreeRTOS.h +++ b/src/include/platform/internal/GenericPlatformManagerImpl_FreeRTOS.h @@ -22,7 +22,6 @@ * for use on FreeRTOS platforms. */ - #ifndef GENERIC_PLATFORM_MANAGER_IMPL_FREERTOS_H #define GENERIC_PLATFORM_MANAGER_IMPL_FREERTOS_H @@ -52,12 +51,10 @@ namespace Internal { * (directly or indirectly) by the PlatformManagerImpl class, which also appears as the template's * ImplClass parameter. */ -template -class GenericPlatformManagerImpl_FreeRTOS - : public GenericPlatformManagerImpl +template +class GenericPlatformManagerImpl_FreeRTOS : public GenericPlatformManagerImpl { protected: - TimeOut_t mNextTimerBaseTime; TickType_t mNextTimerDurationTicks; SemaphoreHandle_t mChipStackLock; @@ -81,10 +78,9 @@ class GenericPlatformManagerImpl_FreeRTOS void PostEventFromISR(const ChipDeviceEvent * event, BaseType_t & yieldRequired); private: - // ===== Private members for use by this class only. - inline ImplClass * Impl() { return static_cast(this); } + inline ImplClass * Impl() { return static_cast(this); } static void EventLoopTaskMain(void * arg); }; diff --git a/src/include/platform/internal/GenericSoftwareUpdateManagerImpl.h b/src/include/platform/internal/GenericSoftwareUpdateManagerImpl.h index 79b7191b0a9747..d8135b5f614167 100644 --- a/src/include/platform/internal/GenericSoftwareUpdateManagerImpl.h +++ b/src/include/platform/internal/GenericSoftwareUpdateManagerImpl.h @@ -43,7 +43,7 @@ using namespace chip::Inet; * or indirectly) by the SoftwareUpdateManagerImpl class, which also appears as the template's ImplClass * parameter. */ -template +template class GenericSoftwareUpdateManagerImpl { @@ -55,9 +55,9 @@ class GenericSoftwareUpdateManagerImpl void _SetRetryPolicyCallback(const SoftwareUpdateManager::RetryPolicyCallback aRetryPolicyCallback); - static void _DefaultEventHandler(void *apAppState, SoftwareUpdateManager::EventType aEvent, - const SoftwareUpdateManager::InEventParam& aInParam, - SoftwareUpdateManager::OutEventParam& aOutParam); + static void _DefaultEventHandler(void * apAppState, SoftwareUpdateManager::EventType aEvent, + const SoftwareUpdateManager::InEventParam & aInParam, + SoftwareUpdateManager::OutEventParam & aOutParam); CHIP_ERROR _Abort(void); CHIP_ERROR _CheckNow(void); @@ -73,7 +73,8 @@ class GenericSoftwareUpdateManagerImpl void SoftwareUpdateFinished(CHIP_ERROR aError); CHIP_ERROR InstallImage(void); - CHIP_ERROR StoreImageBlock(uint32_t aLength, uint8_t *aData); + CHIP_ERROR StoreImageBlock(uint32_t aLength, uint8_t * aData); + private: // ===== Private members reserved for use by this class only. @@ -81,7 +82,7 @@ class GenericSoftwareUpdateManagerImpl void CheckImageState(void); void CheckImageIntegrity(void); void DriveState(SoftwareUpdateManager::State aNextState); - void GetEventState(int32_t& aEventState); + void GetEventState(int32_t & aEventState); void HandleImageQueryResponse(PacketBuffer * aPayload); void SendQuery(void); void StartImageInstall(void); @@ -94,15 +95,11 @@ class GenericSoftwareUpdateManagerImpl static void PrepareBinding(intptr_t arg); static void StartDownload(intptr_t arg); - static void HandleHoldOffTimerExpired(::chip::System::Layer * aLayer, - void * aAppState, - ::chip::System::Error aError); - static void DefaultRetryPolicyCallback(void * const aAppState, - SoftwareUpdateManager::RetryParam & aRetryParam, + static void HandleHoldOffTimerExpired(::chip::System::Layer * aLayer, void * aAppState, ::chip::System::Error aError); + static void DefaultRetryPolicyCallback(void * const aAppState, SoftwareUpdateManager::RetryParam & aRetryParam, uint32_t & aOutIntervalMsec); private: - SoftwareUpdateManager::State mState; void * mAppState; diff --git a/src/include/platform/internal/GenericSoftwareUpdateManagerImpl_BDX.h b/src/include/platform/internal/GenericSoftwareUpdateManagerImpl_BDX.h index 06eb24693d212b..4f7590923ba106 100644 --- a/src/include/platform/internal/GenericSoftwareUpdateManagerImpl_BDX.h +++ b/src/include/platform/internal/GenericSoftwareUpdateManagerImpl_BDX.h @@ -44,18 +44,18 @@ namespace Internal { * */ -template +template class GenericSoftwareUpdateManagerImpl_BDX { - using BDXTransfer = ::chip::Profiles::BulkDataTransfer::BDXTransfer; - using BDXNode = ::chip::Profiles::BulkDataTransfer::BdxNode; + using BDXTransfer = ::chip::Profiles::BulkDataTransfer::BDXTransfer; + using BDXNode = ::chip::Profiles::BulkDataTransfer::BdxNode; using ReceiveAccept = ::chip::Profiles::BulkDataTransfer::ReceiveAccept; protected: // ===== Members for use by the implementation subclass. CHIP_ERROR DoInit(void); - CHIP_ERROR StartImageDownload(char *aURI, uint64_t aStartOffset); + CHIP_ERROR StartImageDownload(char * aURI, uint64_t aStartOffset); CHIP_ERROR GetUpdateSchemeList(::chip::Profiles::SoftwareUpdate::UpdateSchemeList * aUpdateSchemeList); void AbortDownload(void); @@ -66,8 +66,7 @@ class GenericSoftwareUpdateManagerImpl_BDX CHIP_ERROR StartDownload(void); void ResetState(void); - static void BlockReceiveHandler(BDXTransfer * aXfer, uint64_t alength, uint8_t * aDataBlock, - bool aIsLastBlock); + static void BlockReceiveHandler(BDXTransfer * aXfer, uint64_t alength, uint8_t * aDataBlock, bool aIsLastBlock); static void ErrorHandler(BDXTransfer * aXfer, CHIP_ERROR anErrorCode); static CHIP_ERROR ReceiveAcceptHandler(BDXTransfer * aXfer, ReceiveAccept * aEeceiveAcceptMsg); static void ReceiveRejectHandler(BDXTransfer * aXfer, chip::StatusReport * aReport); @@ -75,8 +74,7 @@ class GenericSoftwareUpdateManagerImpl_BDX static void XferDoneHandler(BDXTransfer * aXfer); static void HandleBindingEvent(void * apAppState, ::chip::Binding::EventType aEvent, - const ::chip::Binding::InEventParam & aInParam, - ::chip::Binding::OutEventParam & aOutParam); + const ::chip::Binding::InEventParam & aInParam, ::chip::Binding::OutEventParam & aOutParam); ImplClass * Impl() { return static_cast(this); } diff --git a/src/include/platform/internal/testing/ConfigUnitTest.h b/src/include/platform/internal/testing/ConfigUnitTest.h index c177ae04697eb5..e7135344039ace 100644 --- a/src/include/platform/internal/testing/ConfigUnitTest.h +++ b/src/include/platform/internal/testing/ConfigUnitTest.h @@ -27,7 +27,7 @@ namespace chip { namespace DeviceLayer { namespace Internal { -template +template void RunConfigUnitTest(void) { CHIP_ERROR err; @@ -128,24 +128,20 @@ void RunConfigUnitTest(void) // ===== Test 7: Store and read binary data { - const static uint8_t kTestData[] = - { - 0xD5, 0x00, 0x00, 0x04, 0x00, 0x01, 0x00, 0x30, 0x01, 0x08, 0x79, 0x55, 0x9F, 0x15, 0x1F, 0x66, - 0x3D, 0x8F, 0x24, 0x02, 0x05, 0x37, 0x03, 0x27, 0x13, 0x02, 0x00, 0x00, 0xEE, 0xEE, 0x30, 0xB4, - 0x18, 0x18, 0x26, 0x04, 0x80, 0x41, 0x1B, 0x23, 0x26, 0x05, 0x7F, 0xFF, 0xFF, 0x52, 0x37, 0x06, - 0x27, 0x11, 0x01, 0x00, 0x00, 0x00, 0x00, 0x30, 0xB4, 0x18, 0x18, 0x24, 0x07, 0x02, 0x26, 0x08, - 0x25, 0x00, 0x5A, 0x23, 0x30, 0x0A, 0x39, 0x04, 0x9E, 0xC7, 0x77, 0xC5, 0xA4, 0x13, 0x31, 0xF7, - 0x72, 0x2E, 0x27, 0xC2, 0x86, 0x3D, 0xC5, 0x2E, 0xD5, 0xD2, 0x3C, 0xCF, 0x7E, 0x06, 0xE3, 0x48, - 0x53, 0x87, 0xE8, 0x4D, 0xB0, 0x27, 0x07, 0x58, 0x4A, 0x38, 0xB4, 0xF3, 0xB2, 0x47, 0x94, 0x45, - 0x58, 0x65, 0x80, 0x08, 0x17, 0x6B, 0x8E, 0x4F, 0x07, 0x41, 0xA3, 0x3D, 0x5D, 0xCE, 0x76, 0x86, - 0x35, 0x83, 0x29, 0x01, 0x18, 0x35, 0x82, 0x29, 0x01, 0x24, 0x02, 0x05, 0x18, 0x35, 0x84, 0x29, - 0x01, 0x36, 0x02, 0x04, 0x02, 0x04, 0x01, 0x18, 0x18, 0x35, 0x81, 0x30, 0x02, 0x08, 0x42, 0xBD, - 0x2C, 0x6B, 0x5B, 0x3A, 0x18, 0x16, 0x18, 0x35, 0x80, 0x30, 0x02, 0x08, 0x44, 0xE3, 0x40, 0x38, - 0xA9, 0xD4, 0xB5, 0xA7, 0x18, 0x35, 0x0C, 0x30, 0x01, 0x19, 0x00, 0xA6, 0x5D, 0x54, 0xF5, 0xAE, - 0x5D, 0x63, 0xEB, 0x69, 0xD8, 0xDB, 0xCB, 0xE2, 0x20, 0x0C, 0xD5, 0x6F, 0x43, 0x5E, 0x96, 0xA8, - 0x54, 0xB2, 0x74, 0x30, 0x02, 0x19, 0x00, 0xE0, 0x37, 0x02, 0x8B, 0xB3, 0x04, 0x06, 0xDD, 0xBD, - 0x28, 0xAA, 0xC4, 0xF1, 0xFF, 0xFB, 0xB1, 0xD4, 0x1C, 0x78, 0x40, 0xDA, 0x2C, 0xD8, 0x40, 0x18, - 0x18, + const static uint8_t kTestData[] = { + 0xD5, 0x00, 0x00, 0x04, 0x00, 0x01, 0x00, 0x30, 0x01, 0x08, 0x79, 0x55, 0x9F, 0x15, 0x1F, 0x66, 0x3D, 0x8F, 0x24, + 0x02, 0x05, 0x37, 0x03, 0x27, 0x13, 0x02, 0x00, 0x00, 0xEE, 0xEE, 0x30, 0xB4, 0x18, 0x18, 0x26, 0x04, 0x80, 0x41, + 0x1B, 0x23, 0x26, 0x05, 0x7F, 0xFF, 0xFF, 0x52, 0x37, 0x06, 0x27, 0x11, 0x01, 0x00, 0x00, 0x00, 0x00, 0x30, 0xB4, + 0x18, 0x18, 0x24, 0x07, 0x02, 0x26, 0x08, 0x25, 0x00, 0x5A, 0x23, 0x30, 0x0A, 0x39, 0x04, 0x9E, 0xC7, 0x77, 0xC5, + 0xA4, 0x13, 0x31, 0xF7, 0x72, 0x2E, 0x27, 0xC2, 0x86, 0x3D, 0xC5, 0x2E, 0xD5, 0xD2, 0x3C, 0xCF, 0x7E, 0x06, 0xE3, + 0x48, 0x53, 0x87, 0xE8, 0x4D, 0xB0, 0x27, 0x07, 0x58, 0x4A, 0x38, 0xB4, 0xF3, 0xB2, 0x47, 0x94, 0x45, 0x58, 0x65, + 0x80, 0x08, 0x17, 0x6B, 0x8E, 0x4F, 0x07, 0x41, 0xA3, 0x3D, 0x5D, 0xCE, 0x76, 0x86, 0x35, 0x83, 0x29, 0x01, 0x18, + 0x35, 0x82, 0x29, 0x01, 0x24, 0x02, 0x05, 0x18, 0x35, 0x84, 0x29, 0x01, 0x36, 0x02, 0x04, 0x02, 0x04, 0x01, 0x18, + 0x18, 0x35, 0x81, 0x30, 0x02, 0x08, 0x42, 0xBD, 0x2C, 0x6B, 0x5B, 0x3A, 0x18, 0x16, 0x18, 0x35, 0x80, 0x30, 0x02, + 0x08, 0x44, 0xE3, 0x40, 0x38, 0xA9, 0xD4, 0xB5, 0xA7, 0x18, 0x35, 0x0C, 0x30, 0x01, 0x19, 0x00, 0xA6, 0x5D, 0x54, + 0xF5, 0xAE, 0x5D, 0x63, 0xEB, 0x69, 0xD8, 0xDB, 0xCB, 0xE2, 0x20, 0x0C, 0xD5, 0x6F, 0x43, 0x5E, 0x96, 0xA8, 0x54, + 0xB2, 0x74, 0x30, 0x02, 0x19, 0x00, 0xE0, 0x37, 0x02, 0x8B, 0xB3, 0x04, 0x06, 0xDD, 0xBD, 0x28, 0xAA, 0xC4, 0xF1, + 0xFF, 0xFB, 0xB1, 0xD4, 0x1C, 0x78, 0x40, 0xDA, 0x2C, 0xD8, 0x40, 0x18, 0x18, }; uint8_t buf[512]; size_t dataLen; @@ -201,7 +197,7 @@ void RunConfigUnitTest(void) } } -} // namespace internal +} // namespace Internal } // namespace DeviceLayer } // namespace chip diff --git a/src/include/platform/nRF5/BLEManagerImpl.h b/src/include/platform/nRF5/BLEManagerImpl.h index acee4200d68013..bf45777d2096b8 100644 --- a/src/include/platform/nRF5/BLEManagerImpl.h +++ b/src/include/platform/nRF5/BLEManagerImpl.h @@ -39,25 +39,19 @@ using namespace chip::Ble; /** * Concrete implementation of the NetworkProvisioningServer singleton object for the nRF5 platforms. */ -class BLEManagerImpl final - : public BLEManager, - private BleLayer, - private BlePlatformDelegate, - private BleApplicationDelegate +class BLEManagerImpl final : public BLEManager, private BleLayer, private BlePlatformDelegate, private BleApplicationDelegate { // Allow the BLEManager interface class to delegate method calls to // the implementation methods provided by this class. friend BLEManager; public: - // ===== Platform-specific members available for use by the application. uint8_t GetAdvertisingHandle(void); void SetAdvertisingHandle(uint8_t handle); private: - // ===== Members that implement the BLEManager internal interface. CHIP_ERROR _Init(void); @@ -80,10 +74,14 @@ class BLEManagerImpl final bool UnsubscribeCharacteristic(BLE_CONNECTION_OBJECT conId, const ChipBleUUID * svcId, const ChipBleUUID * charId) override; bool CloseConnection(BLE_CONNECTION_OBJECT conId) override; uint16_t GetMTU(BLE_CONNECTION_OBJECT conId) const override; - bool SendIndication(BLE_CONNECTION_OBJECT conId, const ChipBleUUID * svcId, const ChipBleUUID * charId, PacketBuffer * pBuf) override; - bool SendWriteRequest(BLE_CONNECTION_OBJECT conId, const ChipBleUUID * svcId, const ChipBleUUID * charId, PacketBuffer * pBuf) override; - bool SendReadRequest(BLE_CONNECTION_OBJECT conId, const ChipBleUUID * svcId, const ChipBleUUID * charId, PacketBuffer * pBuf) override; - bool SendReadResponse(BLE_CONNECTION_OBJECT conId, BLE_READ_REQUEST_CONTEXT requestContext, const ChipBleUUID * svcId, const ChipBleUUID * charId) override; + bool SendIndication(BLE_CONNECTION_OBJECT conId, const ChipBleUUID * svcId, const ChipBleUUID * charId, + PacketBuffer * pBuf) override; + bool SendWriteRequest(BLE_CONNECTION_OBJECT conId, const ChipBleUUID * svcId, const ChipBleUUID * charId, + PacketBuffer * pBuf) override; + bool SendReadRequest(BLE_CONNECTION_OBJECT conId, const ChipBleUUID * svcId, const ChipBleUUID * charId, + PacketBuffer * pBuf) override; + bool SendReadResponse(BLE_CONNECTION_OBJECT conId, BLE_READ_REQUEST_CONTEXT requestContext, const ChipBleUUID * svcId, + const ChipBleUUID * charId) override; // ===== Members that implement virtual methods on BleApplicationDelegate. @@ -100,18 +98,19 @@ class BLEManagerImpl final enum { - kFlag_AsyncInitCompleted = 0x0001, /**< One-time asynchronous initialization actions have been performed. */ - kFlag_AdvertisingEnabled = 0x0002, /**< The application has enabled CHIPoBLE advertising. */ - kFlag_FastAdvertisingEnabled = 0x0004, /**< The application has enabled fast advertising. */ - kFlag_Advertising = 0x0008, /**< The system is currently CHIPoBLE advertising. */ - kFlag_AdvertisingRefreshNeeded = 0x0010, /**< The advertising state/configuration has changed, but the SoftDevice has yet to be updated. */ + kFlag_AsyncInitCompleted = 0x0001, /**< One-time asynchronous initialization actions have been performed. */ + kFlag_AdvertisingEnabled = 0x0002, /**< The application has enabled CHIPoBLE advertising. */ + kFlag_FastAdvertisingEnabled = 0x0004, /**< The application has enabled fast advertising. */ + kFlag_Advertising = 0x0008, /**< The system is currently CHIPoBLE advertising. */ + kFlag_AdvertisingRefreshNeeded = + 0x0010, /**< The advertising state/configuration has changed, but the SoftDevice has yet to be updated. */ }; enum { - kMaxConnections = MIN(BLE_LAYER_NUM_BLE_ENDPOINTS, NRF_SDH_BLE_PERIPHERAL_LINK_COUNT), - kMaxDeviceNameLength = 20, // TODO: right-size this - kMaxAdvertismentDataSetSize = 31 // TODO: verify this + kMaxConnections = MIN(BLE_LAYER_NUM_BLE_ENDPOINTS, NRF_SDH_BLE_PERIPHERAL_LINK_COUNT), + kMaxDeviceNameLength = 20, // TODO: right-size this + kMaxAdvertismentDataSetSize = 31 // TODO: verify this }; ble_gatts_char_handles_t mCHIPoBLECharHandle_RX; @@ -177,7 +176,7 @@ inline void BLEManagerImpl::SetAdvertisingHandle(uint8_t handle) inline BleLayer * BLEManagerImpl::_GetBleLayer() const { - return (BleLayer *)(this); + return (BleLayer *) (this); } inline BLEManager::CHIPoBLEServiceMode BLEManagerImpl::_GetCHIPoBLEServiceMode(void) diff --git a/src/include/platform/nRF5/BlePlatformConfig.h b/src/include/platform/nRF5/BlePlatformConfig.h index d3f3568485f4f6..cb4c3fb9f07258 100644 --- a/src/include/platform/nRF5/BlePlatformConfig.h +++ b/src/include/platform/nRF5/BlePlatformConfig.h @@ -31,7 +31,7 @@ // ==================== Platform Adaptations ==================== #define BLE_CONNECTION_OBJECT uint16_t -#define BLE_CONNECTION_UNINITIALIZED ((uint16_t)BLE_CONN_HANDLE_INVALID) +#define BLE_CONNECTION_UNINITIALIZED ((uint16_t) BLE_CONN_HANDLE_INVALID) #define BLE_MAX_RECEIVE_WINDOW_SIZE 5 #define BLE_CONFIG_ERROR_TYPE ret_code_t diff --git a/src/include/platform/nRF5/CHIPDevicePlatformConfig.h b/src/include/platform/nRF5/CHIPDevicePlatformConfig.h index f143d2a773d251..ed4d1efad2c020 100644 --- a/src/include/platform/nRF5/CHIPDevicePlatformConfig.h +++ b/src/include/platform/nRF5/CHIPDevicePlatformConfig.h @@ -22,7 +22,6 @@ * on nRF52 platforms using the Nordic nRF5 SDK. */ - #ifndef CHIP_DEVICE_PLATFORM_CONFIG_H #define CHIP_DEVICE_PLATFORM_CONFIG_H diff --git a/src/include/platform/nRF5/CHIPDevicePlatformEvent.h b/src/include/platform/nRF5/CHIPDevicePlatformEvent.h index b8d02ef001a9e2..79967d92dbcad8 100644 --- a/src/include/platform/nRF5/CHIPDevicePlatformEvent.h +++ b/src/include/platform/nRF5/CHIPDevicePlatformEvent.h @@ -34,7 +34,7 @@ namespace chip { namespace System { class PacketBuffer; } -} +} // namespace chip namespace chip { namespace DeviceLayer { @@ -54,7 +54,7 @@ enum PublicPlatformSpecificEventTypes */ enum InternalPlatformSpecificEventTypes { - kSoftDeviceBLEEvent = kRange_InternalPlatformSpecific, + kSoftDeviceBLEEvent = kRange_InternalPlatformSpecific, kCHIPoBLERXCharWriteEvent, kCHIPoBLEOutOfBuffersEvent, }; @@ -85,5 +85,4 @@ struct ChipDevicePlatformEvent final } // namespace DeviceLayer } // namespace chip - #endif // CHIP_DEVICE_PLATFORM_EVENT_H diff --git a/src/include/platform/nRF5/ConfigurationManagerImpl.h b/src/include/platform/nRF5/ConfigurationManagerImpl.h index 3ea5b210bb7acf..d027b97d1e0e82 100644 --- a/src/include/platform/nRF5/ConfigurationManagerImpl.h +++ b/src/include/platform/nRF5/ConfigurationManagerImpl.h @@ -34,10 +34,9 @@ namespace DeviceLayer { /** * Concrete implementation of the ConfigurationManager singleton object for the nRF52 platform. */ -class ConfigurationManagerImpl final - : public ConfigurationManager, - public Internal::GenericConfigurationManagerImpl, - private Internal::NRF5Config +class ConfigurationManagerImpl final : public ConfigurationManager, + public Internal::GenericConfigurationManagerImpl, + private Internal::NRF5Config { // Allow the ConfigurationManager interface class to delegate method calls to // the implementation methods provided by this class. @@ -48,7 +47,6 @@ class ConfigurationManagerImpl final friend class Internal::GenericConfigurationManagerImpl; private: - // ===== Members that implement the ConfigurationManager public interface. CHIP_ERROR _Init(void); diff --git a/src/include/platform/nRF5/GroupKeyStoreImpl.h b/src/include/platform/nRF5/GroupKeyStoreImpl.h index be1da64d3cd8b7..0a8c8fce61e498 100644 --- a/src/include/platform/nRF5/GroupKeyStoreImpl.h +++ b/src/include/platform/nRF5/GroupKeyStoreImpl.h @@ -35,14 +35,15 @@ class ChipGroupKey public: enum { - MaxKeySize = 36 + MaxKeySize = 36 }; - uint32_t KeyId; /**< The key ID. */ - uint8_t KeyLen; /**< The key length. */ - uint8_t Key[MaxKeySize]; /**< The secret key material. */ - union { - uint32_t StartTime; /**< The epoch key start time. */ - uint32_t GlobalId; /**< The application group key global ID. */ + uint32_t KeyId; /**< The key ID. */ + uint8_t KeyLen; /**< The key length. */ + uint8_t Key[MaxKeySize]; /**< The secret key material. */ + union + { + uint32_t StartTime; /**< The epoch key start time. */ + uint32_t GlobalId; /**< The application group key global ID. */ }; }; @@ -50,14 +51,11 @@ class ChipGroupKey * An implementation of the chip GroupKeyStoreBase API for platforms based * on the Nordic nRF5 SDK. */ -class GroupKeyStoreImpl final - : public ::chip::Profiles::Security::AppKeys::GroupKeyStoreBase, - private NRF5Config +class GroupKeyStoreImpl final : public ::chip::Profiles::Security::AppKeys::GroupKeyStoreBase, private NRF5Config { using ChipGroupKey = ::chip::Profiles::Security::AppKeys::ChipGroupKey; public: - CHIP_ERROR Init(); CHIP_ERROR RetrieveGroupKey(uint32_t keyId, ChipGroupKey & key) override; @@ -70,15 +68,14 @@ class GroupKeyStoreImpl final CHIP_ERROR StoreLastUsedEpochKeyId(void) override; private: + static constexpr size_t kFixedEncodedKeySize = 4U + // key id + 4U + // start time / global id + 1U; // key data length - static constexpr size_t kFixedEncodedKeySize = 4U + // key id - 4U + // start time / global id - 1U; // key data length - - static constexpr size_t kMaxEncodedKeySize = kFixedEncodedKeySize + ChipGroupKey::MaxKeySize; + static constexpr size_t kMaxEncodedKeySize = kFixedEncodedKeySize + ChipGroupKey::MaxKeySize; - static constexpr uint16_t kGroupKeyFileId = GetFileId(kConfigKey_GroupKey); - static constexpr uint16_t kGroupKeyRecordKey = GetRecordKey(kConfigKey_GroupKey); + static constexpr uint16_t kGroupKeyFileId = GetFileId(kConfigKey_GroupKey); + static constexpr uint16_t kGroupKeyRecordKey = GetRecordKey(kConfigKey_GroupKey); static CHIP_ERROR EncodeGroupKey(const ChipGroupKey & key, uint8_t * buf, size_t bufSize, size_t & encodedKeyLen); static CHIP_ERROR DecodeGroupKey(const uint8_t * encodedKey, size_t encodedKeyLen, ChipGroupKey & key); diff --git a/src/include/platform/nRF5/ThreadStackManagerImpl.h b/src/include/platform/nRF5/ThreadStackManagerImpl.h index 45943231db2df7..b931f841041947 100644 --- a/src/include/platform/nRF5/ThreadStackManagerImpl.h +++ b/src/include/platform/nRF5/ThreadStackManagerImpl.h @@ -46,10 +46,9 @@ extern int GetEntropy_nRF5(uint8_t * buf, size_t bufSize); * Concrete implementation of the ThreadStackManager singleton object for nRF52 platforms * using the Nordic nRF5 SDK and the OpenThread stack. */ -class ThreadStackManagerImpl final - : public ThreadStackManager, - public Internal::GenericThreadStackManagerImpl_OpenThread_LwIP, - public Internal::GenericThreadStackManagerImpl_FreeRTOS +class ThreadStackManagerImpl final : public ThreadStackManager, + public Internal::GenericThreadStackManagerImpl_OpenThread_LwIP, + public Internal::GenericThreadStackManagerImpl_FreeRTOS { // Allow the ThreadStackManager interface class to delegate method calls to // the implementation methods provided by this class. @@ -67,7 +66,6 @@ class ThreadStackManagerImpl final friend void ::otSysEventSignalPending(void); public: - // ===== Platform-specific members that may be accessed directly by the application. using ThreadStackManager::InitThreadStack; @@ -76,7 +74,6 @@ class ThreadStackManagerImpl final void _OnCHIPoBLEAdvertisingStop(void); private: - // ===== Methods that implement the ThreadStackManager abstract interface. CHIP_ERROR _InitThreadStack(void); @@ -118,7 +115,6 @@ inline ThreadStackManagerImpl & ThreadStackMgrImpl(void) return ThreadStackManagerImpl::sInstance; } - } // namespace DeviceLayer } // namespace chip diff --git a/src/include/platform/nRF5/nRF5Config.h b/src/include/platform/nRF5/nRF5Config.h index bd993373e82686..fce22edc5c65ff 100644 --- a/src/include/platform/nRF5/nRF5Config.h +++ b/src/include/platform/nRF5/nRF5Config.h @@ -41,7 +41,6 @@ constexpr inline uint32_t NRF5ConfigKey(uint16_t fileId, uint16_t recordId) return static_cast(fileId) << 16 | recordId; } - /** * Provides functions and definitions for accessing persisted device configuration * on platforms based on the Nordic nRF5 SDK. @@ -57,22 +56,23 @@ constexpr inline uint32_t NRF5ConfigKey(uint16_t fileId, uint16_t recordId) class NRF5Config { public: - // *** CAUTION ***: Changing the FDS file or record ids of these values will *break* existing devices. // Limits/definitions imposed by the Nordic SDK - static constexpr uint16_t kFDSFileIdMin = 0x0000; /**< Minimum value that can be used for a FDS file id (per Nordic SDK) */ - static constexpr uint16_t kFDSFileIdMax = 0xBFFF; /**< Maximum value that can be used for a FDS file id (per Nordic SDK) */ - static constexpr uint16_t kFDSRecordKeyMin = 0x0001; /**< Minimum value that can be used for a FDS record key (per Nordic SDK) */ - static constexpr uint16_t kFDSRecordKeyMax = 0xBFFF; /**< Maximum value that can be used for a FDS record key (per Nordic SDK) */ + static constexpr uint16_t kFDSFileIdMin = 0x0000; /**< Minimum value that can be used for a FDS file id (per Nordic SDK) */ + static constexpr uint16_t kFDSFileIdMax = 0xBFFF; /**< Maximum value that can be used for a FDS file id (per Nordic SDK) */ + static constexpr uint16_t kFDSRecordKeyMin = + 0x0001; /**< Minimum value that can be used for a FDS record key (per Nordic SDK) */ + static constexpr uint16_t kFDSRecordKeyMax = + 0xBFFF; /**< Maximum value that can be used for a FDS record key (per Nordic SDK) */ // FDS file ids used by the CHIP Device Layer - static constexpr uint16_t kFileId_ChipFactory = 0x235A; /**< FDS file containing persistent config values set at manufacturing time. - * Retained during factory reset. */ - static constexpr uint16_t kFileId_ChipConfig = 0x235B; /**< FDS file containing dynamic config values set at runtime. - * Cleared during factory reset. */ - static constexpr uint16_t kFileId_ChipCounter = 0x235C; /**< FDS file containing dynamic counter values set at runtime. - * Retained during factory reset. */ + static constexpr uint16_t kFileId_ChipFactory = 0x235A; /**< FDS file containing persistent config values set at manufacturing + * time. Retained during factory reset. */ + static constexpr uint16_t kFileId_ChipConfig = 0x235B; /**< FDS file containing dynamic config values set at runtime. + * Cleared during factory reset. */ + static constexpr uint16_t kFileId_ChipCounter = 0x235C; /**< FDS file containing dynamic counter values set at runtime. + * Retained during factory reset. */ // API data type used to represent the combination of a FDS file id and record key. using Key = uint32_t; @@ -84,27 +84,27 @@ class NRF5Config static constexpr Key kConfigKey_MfrDevicePrivateKey = NRF5ConfigKey(kFileId_ChipFactory, 0x0004); static constexpr Key kConfigKey_ManufacturingDate = NRF5ConfigKey(kFileId_ChipFactory, 0x0005); static constexpr Key kConfigKey_PairingCode = NRF5ConfigKey(kFileId_ChipFactory, 0x0006); - static constexpr Key kConfigKey_FabricId = NRF5ConfigKey(kFileId_ChipConfig, 0x0007); - static constexpr Key kConfigKey_ServiceConfig = NRF5ConfigKey(kFileId_ChipConfig, 0x0008); - static constexpr Key kConfigKey_PairedAccountId = NRF5ConfigKey(kFileId_ChipConfig, 0x0009); - static constexpr Key kConfigKey_ServiceId = NRF5ConfigKey(kFileId_ChipConfig, 0x000A); - static constexpr Key kConfigKey_FabricSecret = NRF5ConfigKey(kFileId_ChipConfig, 0x000B); - static constexpr Key kConfigKey_LastUsedEpochKeyId = NRF5ConfigKey(kFileId_ChipConfig, 0x000C); - static constexpr Key kConfigKey_FailSafeArmed = NRF5ConfigKey(kFileId_ChipConfig, 0x000D); - static constexpr Key kConfigKey_GroupKey = NRF5ConfigKey(kFileId_ChipConfig, 0x000E); + static constexpr Key kConfigKey_FabricId = NRF5ConfigKey(kFileId_ChipConfig, 0x0007); + static constexpr Key kConfigKey_ServiceConfig = NRF5ConfigKey(kFileId_ChipConfig, 0x0008); + static constexpr Key kConfigKey_PairedAccountId = NRF5ConfigKey(kFileId_ChipConfig, 0x0009); + static constexpr Key kConfigKey_ServiceId = NRF5ConfigKey(kFileId_ChipConfig, 0x000A); + static constexpr Key kConfigKey_FabricSecret = NRF5ConfigKey(kFileId_ChipConfig, 0x000B); + static constexpr Key kConfigKey_LastUsedEpochKeyId = NRF5ConfigKey(kFileId_ChipConfig, 0x000C); + static constexpr Key kConfigKey_FailSafeArmed = NRF5ConfigKey(kFileId_ChipConfig, 0x000D); + static constexpr Key kConfigKey_GroupKey = NRF5ConfigKey(kFileId_ChipConfig, 0x000E); static constexpr Key kConfigKey_ProductRevision = NRF5ConfigKey(kFileId_ChipFactory, 0x000F); static constexpr Key kConfigKey_MfrDeviceICACerts = NRF5ConfigKey(kFileId_ChipFactory, 0x0010); - static constexpr Key kConfigKey_OperationalDeviceId = NRF5ConfigKey(kFileId_ChipConfig, 0x0011); - static constexpr Key kConfigKey_OperationalDeviceCert = NRF5ConfigKey(kFileId_ChipConfig, 0x0012); - static constexpr Key kConfigKey_OperationalDeviceICACerts = NRF5ConfigKey(kFileId_ChipConfig, 0x0013); - static constexpr Key kConfigKey_OperationalDevicePrivateKey = NRF5ConfigKey(kFileId_ChipConfig, 0x0014); + static constexpr Key kConfigKey_OperationalDeviceId = NRF5ConfigKey(kFileId_ChipConfig, 0x0011); + static constexpr Key kConfigKey_OperationalDeviceCert = NRF5ConfigKey(kFileId_ChipConfig, 0x0012); + static constexpr Key kConfigKey_OperationalDeviceICACerts = NRF5ConfigKey(kFileId_ChipConfig, 0x0013); + static constexpr Key kConfigKey_OperationalDevicePrivateKey = NRF5ConfigKey(kFileId_ChipConfig, 0x0014); // Range of FDS record keys used to store CHIP persisted counter values. - static constexpr uint16_t kPersistedCounterRecordKeyBase = kFDSRecordKeyMin; - /**< Base record key for records containing CHIP persisted counter values. - * The CHIP counter id is added to this value to form the FDS record key.*/ - static constexpr uint16_t kPersistedCounterRecordKeyMax = kFDSRecordKeyMax; - /**< Max record key for records containing CHIP persisted counter values. */ + static constexpr uint16_t kPersistedCounterRecordKeyBase = kFDSRecordKeyMin; + /**< Base record key for records containing CHIP persisted counter values. + * The CHIP counter id is added to this value to form the FDS record key.*/ + static constexpr uint16_t kPersistedCounterRecordKeyMax = kFDSRecordKeyMax; + /**< Max record key for records containing CHIP persisted counter values. */ static CHIP_ERROR Init(void); @@ -127,12 +127,11 @@ class NRF5Config static void RunConfigUnitTest(void); protected: - struct FDSAsyncOp { enum { - kAddRecord = 0, + kAddRecord = 0, kUpdateRecord, kAddOrUpdateRecord, kDeleteRecord, @@ -151,7 +150,7 @@ class NRF5Config uint16_t RecordKey; uint8_t OpType; - inline FDSAsyncOp(uint8_t opType) : OpType(opType) { } + inline FDSAsyncOp(uint8_t opType) : OpType(opType) {} }; using ForEachRecordFunct = std::function; diff --git a/src/include/platform/nRF5/nRF5Utils.h b/src/include/platform/nRF5/nRF5Utils.h index 24b28afcd32cf5..a90d820fd4ff34 100644 --- a/src/include/platform/nRF5/nRF5Utils.h +++ b/src/include/platform/nRF5/nRF5Utils.h @@ -35,5 +35,4 @@ bool FormatNRFError(char * buf, uint16_t bufSize, int32_t err); } // namespace DeviceLayer } // namespace chip - #endif // NRF5_UTILS_H diff --git a/src/lib/core/CHIPCircularTLVBuffer.h b/src/lib/core/CHIPCircularTLVBuffer.h index 1d4a33e714f1e4..c0d06f0413fead 100644 --- a/src/lib/core/CHIPCircularTLVBuffer.h +++ b/src/lib/core/CHIPCircularTLVBuffer.h @@ -58,25 +58,27 @@ namespace TLV { class DLL_EXPORT CHIPCircularTLVBuffer { public: - CHIPCircularTLVBuffer(uint8_t *inBuffer, size_t inBufferLength); - CHIPCircularTLVBuffer(uint8_t *inBuffer, size_t inBufferLength, uint8_t *inHead); + CHIPCircularTLVBuffer(uint8_t * inBuffer, size_t inBufferLength); + CHIPCircularTLVBuffer(uint8_t * inBuffer, size_t inBufferLength, uint8_t * inHead); - CHIP_ERROR GetNewBuffer(TLVWriter& ioWriter, uint8_t *& outBufStart, uint32_t& outBufLen); - CHIP_ERROR FinalizeBuffer(TLVWriter& ioWriter, uint8_t *inBufStart, uint32_t inBufLen); - CHIP_ERROR GetNextBuffer(TLVReader& ioReader, const uint8_t *& outBufStart, uint32_t& outBufLen); + CHIP_ERROR GetNewBuffer(TLVWriter & ioWriter, uint8_t *& outBufStart, uint32_t & outBufLen); + CHIP_ERROR FinalizeBuffer(TLVWriter & ioWriter, uint8_t * inBufStart, uint32_t inBufLen); + CHIP_ERROR GetNextBuffer(TLVReader & ioReader, const uint8_t *& outBufStart, uint32_t & outBufLen); - inline uint8_t *QueueHead(void) const { return mQueueHead; }; - inline uint8_t *QueueTail(void) const { return mQueue + (((mQueueHead-mQueue) + mQueueLength) % mQueueSize); }; + inline uint8_t * QueueHead(void) const { return mQueueHead; }; + inline uint8_t * QueueTail(void) const { return mQueue + (((mQueueHead - mQueue) + mQueueLength) % mQueueSize); }; inline size_t DataLength(void) const { return mQueueLength; }; inline size_t AvailableDataLength(void) const { return mQueueSize - mQueueLength; }; inline size_t GetQueueSize(void) const { return mQueueSize; }; - inline uint8_t *GetQueue(void) const { return mQueue; }; + inline uint8_t * GetQueue(void) const { return mQueue; }; CHIP_ERROR EvictHead(void); - static CHIP_ERROR GetNewBufferFunct(TLVWriter& ioWriter, uintptr_t& inBufHandle, uint8_t *& outBufStart, uint32_t& outBufLen); - static CHIP_ERROR FinalizeBufferFunct(TLVWriter& ioWriter, uintptr_t inBufHandle, uint8_t *inBufStart, uint32_t inBufLen); - static CHIP_ERROR GetNextBufferFunct(TLVReader& ioReader, uintptr_t &inBufHandle, const uint8_t *& outBufStart, uint32_t& outBufLen); + static CHIP_ERROR GetNewBufferFunct(TLVWriter & ioWriter, uintptr_t & inBufHandle, uint8_t *& outBufStart, + uint32_t & outBufLen); + static CHIP_ERROR FinalizeBufferFunct(TLVWriter & ioWriter, uintptr_t inBufHandle, uint8_t * inBufStart, uint32_t inBufLen); + static CHIP_ERROR GetNextBufferFunct(TLVReader & ioReader, uintptr_t & inBufHandle, const uint8_t *& outBufStart, + uint32_t & outBufLen); /** * @typedef CHIP_ERROR (*ProcessEvictedElementFunct)(CHIPCircularTLVBuffer &inBuffer, void * inAppData, TLVReader &inReader) @@ -120,32 +122,35 @@ class DLL_EXPORT CHIPCircularTLVBuffer * triggered this element eviction will * fail. */ - typedef CHIP_ERROR (*ProcessEvictedElementFunct)(CHIPCircularTLVBuffer &inBuffer, void * inAppData, TLVReader &inReader); + typedef CHIP_ERROR (*ProcessEvictedElementFunct)(CHIPCircularTLVBuffer & inBuffer, void * inAppData, TLVReader & inReader); uint32_t mImplicitProfileId; void * mAppData; /**< An optional, user supplied context to be used with the callback processing the evicted element. */ - ProcessEvictedElementFunct mProcessEvictedElement; /**< An optional, user-supplied callback that processes the element prior to evicting it from the circular buffer. See the ProcessEvictedElementFunct type definition on additional information on implementing the mProcessEvictedElement function. */ + ProcessEvictedElementFunct + mProcessEvictedElement; /**< An optional, user-supplied callback that processes the element prior to evicting it from the + circular buffer. See the ProcessEvictedElementFunct type definition on additional information on + implementing the mProcessEvictedElement function. */ private: - uint8_t *mQueue; + uint8_t * mQueue; size_t mQueueSize; - uint8_t *mQueueHead; + uint8_t * mQueueHead; size_t mQueueLength; }; class DLL_EXPORT CircularTLVReader : public TLVReader { public: - void Init(CHIPCircularTLVBuffer *buf); + void Init(CHIPCircularTLVBuffer * buf); }; class DLL_EXPORT CircularTLVWriter : public TLVWriter { public: - void Init(CHIPCircularTLVBuffer *buf); + void Init(CHIPCircularTLVBuffer * buf); }; } // namespace TLV } // namespace chip -#endif //CHIP_CIRCULAR_TLV_BUFFER_H_ +#endif // CHIP_CIRCULAR_TLV_BUFFER_H_ diff --git a/src/lib/core/CHIPCore.h b/src/lib/core/CHIPCore.h index 50f50805d63006..c9ac2610d04d1d 100644 --- a/src/lib/core/CHIPCore.h +++ b/src/lib/core/CHIPCore.h @@ -36,8 +36,8 @@ #include -#define CHIP_CORE_IDENTITY "chip-core" -#define CHIP_CORE_PREFIX CHIP_CORE_IDENTITY ": " +#define CHIP_CORE_IDENTITY "chip-core" +#define CHIP_CORE_PREFIX CHIP_CORE_IDENTITY ": " namespace chip { @@ -47,7 +47,7 @@ using namespace ::chip::Ble; using namespace ::chip::Inet; -} +} // namespace chip #include /* diff --git a/src/lib/core/CHIPEncoding.h b/src/lib/core/CHIPEncoding.h index dcf3cfcac07bf3..fe8f8aca0926fc 100644 --- a/src/lib/core/CHIPEncoding.h +++ b/src/lib/core/CHIPEncoding.h @@ -67,7 +67,10 @@ namespace Encoding { * * @return The input value, byte order swapped. */ -inline uint16_t Swap16(uint16_t v) { return nl::ByteOrder::Swap16(v); } +inline uint16_t Swap16(uint16_t v) +{ + return nl::ByteOrder::Swap16(v); +} /** * This unconditionally performs a byte order swap by value of the @@ -77,7 +80,10 @@ inline uint16_t Swap16(uint16_t v) { return nl::ByteOrder::Swap16(v * * @return The input value, byte order swapped. */ -inline uint32_t Swap32(uint32_t v) { return nl::ByteOrder::Swap32(v); } +inline uint32_t Swap32(uint32_t v) +{ + return nl::ByteOrder::Swap32(v); +} /** * This unconditionally performs a byte order swap by value of the @@ -87,7 +93,10 @@ inline uint32_t Swap32(uint32_t v) { return nl::ByteOrder::Swap32(v * * @return The input value, byte order swapped. */ -inline uint64_t Swap64(uint64_t v) { return nl::ByteOrder::Swap64(v); } +inline uint64_t Swap64(uint64_t v) +{ + return nl::ByteOrder::Swap64(v); +} /** * Perform a, potentially unaligned, memory read of the 8-bit value @@ -98,7 +107,10 @@ inline uint64_t Swap64(uint64_t v) { return nl::ByteOrder::Swap64(v * * @return The 8-bit value at the specified pointer address. */ -inline uint8_t Get8(const uint8_t *p) { return nl::IO::Get8(p); } +inline uint8_t Get8(const uint8_t * p) +{ + return nl::IO::Get8(p); +} /** * Perform a, potentially unaligned, memory write of the target system @@ -110,7 +122,10 @@ inline uint8_t Get8(const uint8_t *p) { return nl::IO::Get8(p); } * @param[in] v The 8-bit value to write. * */ -inline void Put8(uint8_t *p, uint8_t v) { nl::IO::Put8(p, v); } +inline void Put8(uint8_t * p, uint8_t v) +{ + nl::IO::Put8(p, v); +} /** * Perform a, potentially unaligned, memory read of the 16-bit value @@ -123,7 +138,10 @@ inline void Put8(uint8_t *p, uint8_t v) { nl::IO::Put8(p, v); } * * @return The 8-bit value at the specified pointer address. */ -inline uint8_t Read8(uint8_t *& p) { return nl::IO::Read8((const void *&)p); } +inline uint8_t Read8(uint8_t *& p) +{ + return nl::IO::Read8((const void *&) p); +} /** * Perform a, potentially unaligned, memory read of the 16-bit value @@ -136,7 +154,10 @@ inline uint8_t Read8(uint8_t *& p) { return nl::IO::Read8((const vo * * @return The 8-bit value at the specified pointer address. */ -inline uint8_t Read8(const uint8_t *& p) { return nl::IO::Read8((const void *&)p); } +inline uint8_t Read8(const uint8_t *& p) +{ + return nl::IO::Read8((const void *&) p); +} /** * Perform a, potentially unaligned, memory write of the 8-bit value @@ -150,7 +171,10 @@ inline uint8_t Read8(const uint8_t *& p) { return nl::IO::Read8((const vo * @param[in] v The 8-bit value to write. * */ -inline void Write8(uint8_t *& p, uint8_t v) { *p++ = v; } +inline void Write8(uint8_t *& p, uint8_t v) +{ + *p++ = v; +} /** * @namespace chip::Encoding::LittleEndian @@ -188,7 +212,10 @@ namespace LittleEndian { * * @return The input value, if necessary, byte order swapped. */ -inline uint16_t HostSwap16(uint16_t v) { return nl::ByteOrder::Swap16LittleToHost(v); } +inline uint16_t HostSwap16(uint16_t v) +{ + return nl::ByteOrder::Swap16LittleToHost(v); +} /** * This conditionally performs, as necessary for the target system, a @@ -203,7 +230,10 @@ inline uint16_t HostSwap16(uint16_t v) { return nl::ByteOrder::Swap16Li * * @return The input value, if necessary, byte order swapped. */ -inline uint32_t HostSwap32(uint32_t v) { return nl::ByteOrder::Swap32LittleToHost(v); } +inline uint32_t HostSwap32(uint32_t v) +{ + return nl::ByteOrder::Swap32LittleToHost(v); +} /** * This conditionally performs, as necessary for the target system, a @@ -218,7 +248,10 @@ inline uint32_t HostSwap32(uint32_t v) { return nl::ByteOrder::Swap32Li * * @return The input value, if necessary, byte order swapped. */ -inline uint64_t HostSwap64(uint64_t v) { return nl::ByteOrder::Swap64LittleToHost(v); } +inline uint64_t HostSwap64(uint64_t v) +{ + return nl::ByteOrder::Swap64LittleToHost(v); +} /** * Perform a, potentially unaligned, memory read of the little endian @@ -232,7 +265,10 @@ inline uint64_t HostSwap64(uint64_t v) { return nl::ByteOrder::Swap64Li * @return The 16-bit value at the specified pointer address, if * necessary, byte reordered. */ -inline uint16_t Get16(const uint8_t *p) { return nl::IO::LittleEndian::GetUnaligned16(p); } +inline uint16_t Get16(const uint8_t * p) +{ + return nl::IO::LittleEndian::GetUnaligned16(p); +} /** * Perform a, potentially unaligned, memory read of the little endian @@ -246,7 +282,10 @@ inline uint16_t Get16(const uint8_t *p) { return nl::IO::LittleEndian::G * @return The 32-bit value at the specified pointer address, if * necessary, byte reordered. */ -inline uint32_t Get32(const uint8_t *p) { return nl::IO::LittleEndian::GetUnaligned32(p); } +inline uint32_t Get32(const uint8_t * p) +{ + return nl::IO::LittleEndian::GetUnaligned32(p); +} /** * Perform a, potentially unaligned, memory read of the little endian @@ -260,7 +299,10 @@ inline uint32_t Get32(const uint8_t *p) { return nl::IO::LittleEndian::G * @return The 64-bit value at the specified pointer address, if * necessary, byte reordered. */ -inline uint64_t Get64(const uint8_t *p) { return nl::IO::LittleEndian::GetUnaligned64(p); } +inline uint64_t Get64(const uint8_t * p) +{ + return nl::IO::LittleEndian::GetUnaligned64(p); +} /** * Perform a, potentially unaligned, memory write of the target system @@ -275,7 +317,10 @@ inline uint64_t Get64(const uint8_t *p) { return nl::IO::LittleEndian::G * @param[in] v The 16-bit value to write, if necessary, byte reordered. * */ -inline void Put16(uint8_t *p, uint16_t v) { nl::IO::LittleEndian::PutUnaligned16(p, v); } +inline void Put16(uint8_t * p, uint16_t v) +{ + nl::IO::LittleEndian::PutUnaligned16(p, v); +} /** * Perform a, potentially unaligned, memory write of the target system @@ -290,7 +335,10 @@ inline void Put16(uint8_t *p, uint16_t v) { nl::IO::LittleEndian::PutUnali * @param[in] v The 32-bit value to write, if necessary, byte reordered. * */ -inline void Put32(uint8_t *p, uint32_t v) { nl::IO::LittleEndian::PutUnaligned32(p, v); } +inline void Put32(uint8_t * p, uint32_t v) +{ + nl::IO::LittleEndian::PutUnaligned32(p, v); +} /** * Perform a, potentially unaligned, memory write of the target system @@ -305,7 +353,10 @@ inline void Put32(uint8_t *p, uint32_t v) { nl::IO::LittleEndian::PutUnali * @param[in] v The 64-bit value to write, if necessary, byte reordered. * */ -inline void Put64(uint8_t *p, uint64_t v) { nl::IO::LittleEndian::PutUnaligned64(p, v); } +inline void Put64(uint8_t * p, uint64_t v) +{ + nl::IO::LittleEndian::PutUnaligned64(p, v); +} /** * Perform a, potentially unaligned, memory read of the little endian @@ -322,7 +373,10 @@ inline void Put64(uint8_t *p, uint64_t v) { nl::IO::LittleEndian::PutUnali * @return The 16-bit value at the specified pointer address, if necessary, * byte order swapped. */ -inline uint16_t Read16(uint8_t *& p) { return nl::IO::LittleEndian::ReadUnaligned16((const void *&)p); } +inline uint16_t Read16(uint8_t *& p) +{ + return nl::IO::LittleEndian::ReadUnaligned16((const void *&) p); +} /** * Perform a, potentially unaligned, memory read of the little endian @@ -339,7 +393,10 @@ inline uint16_t Read16(uint8_t *& p) { return nl::IO::LittleEndian::R * @return The 32-bit value at the specified pointer address, if necessary, * byte order swapped. */ -inline uint32_t Read32(uint8_t *& p) { return nl::IO::LittleEndian::ReadUnaligned32((const void *&)p); } +inline uint32_t Read32(uint8_t *& p) +{ + return nl::IO::LittleEndian::ReadUnaligned32((const void *&) p); +} /** * Perform a, potentially unaligned, memory read of the little endian @@ -356,7 +413,10 @@ inline uint32_t Read32(uint8_t *& p) { return nl::IO::LittleEndian::R * @return The 64-bit value at the specified pointer address, if necessary, * byte order swapped. */ -inline uint64_t Read64(uint8_t *& p) { return nl::IO::LittleEndian::ReadUnaligned64((const void *&)p); } +inline uint64_t Read64(uint8_t *& p) +{ + return nl::IO::LittleEndian::ReadUnaligned64((const void *&) p); +} /** * Perform a, potentially unaligned, memory read of the little endian @@ -373,7 +433,10 @@ inline uint64_t Read64(uint8_t *& p) { return nl::IO::LittleEndian::R * @return The 16-bit value at the specified pointer address, if necessary, * byte order swapped. */ -inline uint16_t Read16(const uint8_t *& p) { return nl::IO::LittleEndian::ReadUnaligned16((const void *&)p); } +inline uint16_t Read16(const uint8_t *& p) +{ + return nl::IO::LittleEndian::ReadUnaligned16((const void *&) p); +} /** * Perform a, potentially unaligned, memory read of the little endian @@ -390,7 +453,10 @@ inline uint16_t Read16(const uint8_t *& p) { return nl::IO::LittleEndian::R * @return The 32-bit value at the specified pointer address, if necessary, * byte order swapped. */ -inline uint32_t Read32(const uint8_t *& p) { return nl::IO::LittleEndian::ReadUnaligned32((const void *&)p); } +inline uint32_t Read32(const uint8_t *& p) +{ + return nl::IO::LittleEndian::ReadUnaligned32((const void *&) p); +} /** * Perform a, potentially unaligned, memory read of the little endian @@ -407,7 +473,10 @@ inline uint32_t Read32(const uint8_t *& p) { return nl::IO::LittleEndian::R * @return The 64-bit value at the specified pointer address, if necessary, * byte order swapped. */ -inline uint64_t Read64(const uint8_t *& p) { return nl::IO::LittleEndian::ReadUnaligned64((const void *&)p); } +inline uint64_t Read64(const uint8_t *& p) +{ + return nl::IO::LittleEndian::ReadUnaligned64((const void *&) p); +} /** * Perform a, potentially unaligned, memory write of the target system @@ -425,7 +494,11 @@ inline uint64_t Read64(const uint8_t *& p) { return nl::IO::LittleEndian::R * swapped. * */ -inline void Write16(uint8_t *& p, uint16_t v) { Put16(p, v); p += sizeof(uint16_t); } +inline void Write16(uint8_t *& p, uint16_t v) +{ + Put16(p, v); + p += sizeof(uint16_t); +} /** * Perform a, potentially unaligned, memory write of the target system @@ -443,7 +516,11 @@ inline void Write16(uint8_t *& p, uint16_t v) { Put16(p, v); p += sizeof(uint1 * swapped. * */ -inline void Write32(uint8_t *& p, uint32_t v) { Put32(p, v); p += sizeof(uint32_t); } +inline void Write32(uint8_t *& p, uint32_t v) +{ + Put32(p, v); + p += sizeof(uint32_t); +} /** * Perform a, potentially unaligned, memory write of the target system @@ -461,10 +538,13 @@ inline void Write32(uint8_t *& p, uint32_t v) { Put32(p, v); p += sizeof(uint3 * swapped. * */ -inline void Write64(uint8_t *& p, uint64_t v) { Put64(p, v); p += sizeof(uint64_t); } - -} // LittleEndian +inline void Write64(uint8_t *& p, uint64_t v) +{ + Put64(p, v); + p += sizeof(uint64_t); +} +} // namespace LittleEndian /** * @namespace chip::Encoding::BigEndian @@ -502,7 +582,10 @@ namespace BigEndian { * * @return The input value, if necessary, byte order swapped. */ -inline uint16_t HostSwap16(uint16_t v) { return nl::ByteOrder::Swap16BigToHost(v); } +inline uint16_t HostSwap16(uint16_t v) +{ + return nl::ByteOrder::Swap16BigToHost(v); +} /** * This conditionally performs, as necessary for the target system, a @@ -517,7 +600,10 @@ inline uint16_t HostSwap16(uint16_t v) { return nl::ByteOrder::Swap16Bi * * @return The input value, if necessary, byte order swapped. */ -inline uint32_t HostSwap32(uint32_t v) { return nl::ByteOrder::Swap32BigToHost(v); } +inline uint32_t HostSwap32(uint32_t v) +{ + return nl::ByteOrder::Swap32BigToHost(v); +} /** * This conditionally performs, as necessary for the target system, a @@ -532,7 +618,10 @@ inline uint32_t HostSwap32(uint32_t v) { return nl::ByteOrder::Swap32Bi * * @return The input value, if necessary, byte order swapped. */ -inline uint64_t HostSwap64(uint64_t v) { return nl::ByteOrder::Swap64BigToHost(v); } +inline uint64_t HostSwap64(uint64_t v) +{ + return nl::ByteOrder::Swap64BigToHost(v); +} /** * Perform a, potentially unaligned, memory read of the big endian @@ -546,7 +635,10 @@ inline uint64_t HostSwap64(uint64_t v) { return nl::ByteOrder::Swap64Bi * @return The 16-bit value at the specified pointer address, if * necessary, byte reordered. */ -inline uint16_t Get16(const uint8_t *p) { return nl::IO::BigEndian::GetUnaligned16(p); } +inline uint16_t Get16(const uint8_t * p) +{ + return nl::IO::BigEndian::GetUnaligned16(p); +} /** * Perform a, potentially unaligned, memory read of the big endian @@ -560,7 +652,10 @@ inline uint16_t Get16(const uint8_t *p) { return nl::IO::BigEndian::GetU * @return The 32-bit value at the specified pointer address, if * necessary, byte reordered. */ -inline uint32_t Get32(const uint8_t *p) { return nl::IO::BigEndian::GetUnaligned32(p); } +inline uint32_t Get32(const uint8_t * p) +{ + return nl::IO::BigEndian::GetUnaligned32(p); +} /** * Perform a, potentially unaligned, memory read of the big endian @@ -574,7 +669,10 @@ inline uint32_t Get32(const uint8_t *p) { return nl::IO::BigEndian::GetU * @return The 64-bit value at the specified pointer address, if * necessary, byte reordered. */ -inline uint64_t Get64(const uint8_t *p) { return nl::IO::BigEndian::GetUnaligned64(p); } +inline uint64_t Get64(const uint8_t * p) +{ + return nl::IO::BigEndian::GetUnaligned64(p); +} /** * Perform a, potentially unaligned, memory write of the target system @@ -590,7 +688,10 @@ inline uint64_t Get64(const uint8_t *p) { return nl::IO::BigEndian::GetU * swapped. * */ -inline void Put16(uint8_t *p, uint16_t v) { nl::IO::BigEndian::PutUnaligned16(p, v); } +inline void Put16(uint8_t * p, uint16_t v) +{ + nl::IO::BigEndian::PutUnaligned16(p, v); +} /** * Perform a, potentially unaligned, memory write of the target system @@ -606,7 +707,10 @@ inline void Put16(uint8_t *p, uint16_t v) { nl::IO::BigEndian::PutUnaligne * swapped. * */ -inline void Put32(uint8_t *p, uint32_t v) { nl::IO::BigEndian::PutUnaligned32(p, v); } +inline void Put32(uint8_t * p, uint32_t v) +{ + nl::IO::BigEndian::PutUnaligned32(p, v); +} /** * Perform a, potentially unaligned, memory write of the target system @@ -622,7 +726,10 @@ inline void Put32(uint8_t *p, uint32_t v) { nl::IO::BigEndian::PutUnaligne * swapped. * */ -inline void Put64(uint8_t *p, uint64_t v) { nl::IO::BigEndian::PutUnaligned64(p, v); } +inline void Put64(uint8_t * p, uint64_t v) +{ + nl::IO::BigEndian::PutUnaligned64(p, v); +} /** * Perform a, potentially unaligned, memory read of the big endian @@ -639,7 +746,10 @@ inline void Put64(uint8_t *p, uint64_t v) { nl::IO::BigEndian::PutUnaligne * @return The 16-bit value at the specified pointer address, if necessary, * byte order swapped. */ -inline uint16_t Read16(uint8_t *& p) { return nl::IO::BigEndian::ReadUnaligned16((const void *&)p); } +inline uint16_t Read16(uint8_t *& p) +{ + return nl::IO::BigEndian::ReadUnaligned16((const void *&) p); +} /** * Perform a, potentially unaligned, memory read of the big endian @@ -656,7 +766,10 @@ inline uint16_t Read16(uint8_t *& p) { return nl::IO::BigEndian::Read * @return The 32-bit value at the specified pointer address, if necessary, * byte order swapped. */ -inline uint32_t Read32(uint8_t *& p) { return nl::IO::BigEndian::ReadUnaligned32((const void *&)p); } +inline uint32_t Read32(uint8_t *& p) +{ + return nl::IO::BigEndian::ReadUnaligned32((const void *&) p); +} /** * Perform a, potentially unaligned, memory read of the big endian @@ -673,7 +786,10 @@ inline uint32_t Read32(uint8_t *& p) { return nl::IO::BigEndian::Read * @return The 64-bit value at the specified pointer address, if necessary, * byte order swapped. */ -inline uint64_t Read64(uint8_t *& p) { return nl::IO::BigEndian::ReadUnaligned64((const void *&)p); } +inline uint64_t Read64(uint8_t *& p) +{ + return nl::IO::BigEndian::ReadUnaligned64((const void *&) p); +} /** * Perform a, potentially unaligned, memory read of the big endian @@ -690,7 +806,10 @@ inline uint64_t Read64(uint8_t *& p) { return nl::IO::BigEndian::Read * @return The 16-bit value at the specified pointer address, if necessary, * byte order swapped. */ -inline uint16_t Read16(const uint8_t *& p) { return nl::IO::BigEndian::ReadUnaligned16((const void *&)p); } +inline uint16_t Read16(const uint8_t *& p) +{ + return nl::IO::BigEndian::ReadUnaligned16((const void *&) p); +} /** * Perform a, potentially unaligned, memory read of the big endian @@ -707,7 +826,10 @@ inline uint16_t Read16(const uint8_t *& p) { return nl::IO::BigEndian::Read * @return The 32-bit value at the specified pointer address, if necessary, * byte order swapped. */ -inline uint32_t Read32(const uint8_t *& p) { return nl::IO::BigEndian::ReadUnaligned32((const void *&)p); } +inline uint32_t Read32(const uint8_t *& p) +{ + return nl::IO::BigEndian::ReadUnaligned32((const void *&) p); +} /** * Perform a, potentially unaligned, memory read of the big endian @@ -724,7 +846,10 @@ inline uint32_t Read32(const uint8_t *& p) { return nl::IO::BigEndian::Read * @return The 64-bit value at the specified pointer address, if necessary, * byte order swapped. */ -inline uint64_t Read64(const uint8_t *& p) { return nl::IO::BigEndian::ReadUnaligned64((const void *&)p); } +inline uint64_t Read64(const uint8_t *& p) +{ + return nl::IO::BigEndian::ReadUnaligned64((const void *&) p); +} /** * Perform a, potentially unaligned, memory write of the target system @@ -742,7 +867,11 @@ inline uint64_t Read64(const uint8_t *& p) { return nl::IO::BigEndian::Read * swapped. * */ -inline void Write16(uint8_t *& p, uint16_t v) { Put16(p, v); p += sizeof(uint16_t); } +inline void Write16(uint8_t *& p, uint16_t v) +{ + Put16(p, v); + p += sizeof(uint16_t); +} /** * Perform a, potentially unaligned, memory write of the target system @@ -760,7 +889,11 @@ inline void Write16(uint8_t *& p, uint16_t v) { Put16(p, v); p += sizeof(uint1 * swapped. * */ -inline void Write32(uint8_t *& p, uint32_t v) { Put32(p, v); p += sizeof(uint32_t); } +inline void Write32(uint8_t *& p, uint32_t v) +{ + Put32(p, v); + p += sizeof(uint32_t); +} /** * Perform a, potentially unaligned, memory write of the target system @@ -778,12 +911,15 @@ inline void Write32(uint8_t *& p, uint32_t v) { Put32(p, v); p += sizeof(uint3 * swapped. * */ -inline void Write64(uint8_t *& p, uint64_t v) { Put64(p, v); p += sizeof(uint64_t); } - -} // BigEndian +inline void Write64(uint8_t *& p, uint64_t v) +{ + Put64(p, v); + p += sizeof(uint64_t); +} +} // namespace BigEndian -} //Encoding -} //chip +} // namespace Encoding +} // namespace chip #endif // _CHIPENCODING_H diff --git a/src/lib/core/CHIPEventLoggingConfig.h b/src/lib/core/CHIPEventLoggingConfig.h index 94032ab090b0d9..5e18673058bd1c 100644 --- a/src/lib/core/CHIPEventLoggingConfig.h +++ b/src/lib/core/CHIPEventLoggingConfig.h @@ -36,7 +36,6 @@ #define CHIP_CONFIG_EVENT_SIZE_RESERVE 196 #endif /* CHIP_CONFIG_EVENT_SIZE_RESERVE */ - /** * @def CHIP_CONFIG_EVENT_SIZE_INCREMENT * @@ -92,7 +91,7 @@ * to approximate the size of an average WDM notification */ #ifndef CHIP_CONFIG_EVENT_LOGGING_EVENT_THRESHOLD -#define CHIP_CONFIG_EVENT_LOGGING_EVENT_THRESHOLD (CHIP_CONFIG_EVENT_LOGGING_XFER_THRESHOLD/CHIP_CONFIG_EVENT_SIZE_RESERVE) +#define CHIP_CONFIG_EVENT_LOGGING_EVENT_THRESHOLD (CHIP_CONFIG_EVENT_LOGGING_XFER_THRESHOLD / CHIP_CONFIG_EVENT_SIZE_RESERVE) #endif /** diff --git a/src/lib/core/CHIPKeyIds.h b/src/lib/core/CHIPKeyIds.h index 4f6e8bf007a89d..8350ee9ba44649 100644 --- a/src/lib/core/CHIPKeyIds.h +++ b/src/lib/core/CHIPKeyIds.h @@ -45,23 +45,22 @@ class ChipKeyId */ enum { - kMask_KeyFlags = 0xF0000000, /**< CHIP key flag field mask. */ - kMask_KeyType = 0x0FFFF000, /**< CHIP key type field mask. */ - kMask_KeyNumber = 0x00000FFF, /**< CHIP key number field mask. */ - kMask_RootKeyNumber = 0x00000C00, /**< Application group root key number field mask. */ - kMask_EpochKeyNumber = 0x00000380, /**< Application group epoch key number field mask. */ - kMask_GroupLocalNumber = 0x0000007F, /**< Application group local number field mask. */ + kMask_KeyFlags = 0xF0000000, /**< CHIP key flag field mask. */ + kMask_KeyType = 0x0FFFF000, /**< CHIP key type field mask. */ + kMask_KeyNumber = 0x00000FFF, /**< CHIP key number field mask. */ + kMask_RootKeyNumber = 0x00000C00, /**< Application group root key number field mask. */ + kMask_EpochKeyNumber = 0x00000380, /**< Application group epoch key number field mask. */ + kMask_GroupLocalNumber = 0x0000007F, /**< Application group local number field mask. */ - kShift_RootKeyNumber = 10, /**< Application group root key number field shift. */ - kShift_EpochKeyNumber = 7, /**< Application group epoch key number field shift. */ - kShift_GroupLocalNumber = 0, /**< Application group local number field shift. */ + kShift_RootKeyNumber = 10, /**< Application group root key number field shift. */ + kShift_EpochKeyNumber = 7, /**< Application group epoch key number field shift. */ + kShift_GroupLocalNumber = 0, /**< Application group local number field shift. */ - kFlag_UseCurrentEpochKey = 0x80000000, /**< Used to indicate that the key is of logical current type. */ + kFlag_UseCurrentEpochKey = 0x80000000, /**< Used to indicate that the key is of logical current type. */ - kTypeModifier_IncorporatesEpochKey = 0x00001000, /**< Used to indicate that the key incorporates group epoch key. */ + kTypeModifier_IncorporatesEpochKey = 0x00001000, /**< Used to indicate that the key incorporates group epoch key. */ }; - public: /** * @brief @@ -77,12 +76,12 @@ class ChipKeyId * are encoded in the CHIP message. * @{ */ - kType_None = 0x00000000, /**< CHIP message is unencrypted. */ - kType_General = 0x00001000, /**< General key type. */ - kType_Session = 0x00002000, /**< Session key type. */ - kType_AppStaticKey = 0x00004000, /**< Application static key type. */ + kType_None = 0x00000000, /**< CHIP message is unencrypted. */ + kType_General = 0x00001000, /**< General key type. */ + kType_Session = 0x00002000, /**< Session key type. */ + kType_AppStaticKey = 0x00004000, /**< Application static key type. */ /** Application rotating key type. */ - kType_AppRotatingKey = kType_AppStaticKey | kTypeModifier_IncorporatesEpochKey, + kType_AppRotatingKey = kType_AppStaticKey | kTypeModifier_IncorporatesEpochKey, /** @} */ /** @@ -98,13 +97,13 @@ class ChipKeyId * @{ */ /** Application group root key type. */ - kType_AppRootKey = 0x00010000, + kType_AppRootKey = 0x00010000, /** Application group epoch key type. */ - kType_AppEpochKey = 0x00020000 | kTypeModifier_IncorporatesEpochKey, + kType_AppEpochKey = 0x00020000 | kTypeModifier_IncorporatesEpochKey, /** Application group master key type. */ - kType_AppGroupMasterKey = 0x00030000, + kType_AppGroupMasterKey = 0x00030000, /** Application group intermediate key type. */ - kType_AppIntermediateKey = kType_AppRootKey | kTypeModifier_IncorporatesEpochKey, + kType_AppIntermediateKey = kType_AppRootKey | kTypeModifier_IncorporatesEpochKey, /** @} */ /** @@ -112,26 +111,25 @@ class ChipKeyId * @{ */ /** Unspecified CHIP key ID. */ - kNone = kType_None | 0x0000, + kNone = kType_None | 0x0000, /** CHIP fabric secret ID. */ - kFabricSecret = kType_General | 0x0001, + kFabricSecret = kType_General | 0x0001, /** Fabric root key ID. */ - kFabricRootKey = kType_AppRootKey | (0 << kShift_RootKeyNumber), + kFabricRootKey = kType_AppRootKey | (0 << kShift_RootKeyNumber), /** Client root key ID. */ - kClientRootKey = kType_AppRootKey | (1 << kShift_RootKeyNumber), + kClientRootKey = kType_AppRootKey | (1 << kShift_RootKeyNumber), /** Service root key ID. */ - kServiceRootKey = kType_AppRootKey | (2 << kShift_RootKeyNumber), + kServiceRootKey = kType_AppRootKey | (2 << kShift_RootKeyNumber), /** @} */ - /** * @brief Maximum values for key ID subfields. * @{ */ - kKeyNumber_Max = kMask_KeyNumber, - kRootKeyNumber_Max = (kMask_RootKeyNumber >> kShift_RootKeyNumber), - kEpochKeyNumber_Max = (kMask_EpochKeyNumber >> kShift_EpochKeyNumber), - kGroupLocalNumber_Max = (kMask_GroupLocalNumber >> kShift_GroupLocalNumber), + kKeyNumber_Max = kMask_KeyNumber, + kRootKeyNumber_Max = (kMask_RootKeyNumber >> kShift_RootKeyNumber), + kEpochKeyNumber_Max = (kMask_EpochKeyNumber >> kShift_EpochKeyNumber), + kGroupLocalNumber_Max = (kMask_GroupLocalNumber >> kShift_GroupLocalNumber), /** @} */ }; @@ -142,10 +140,7 @@ class ChipKeyId * @return type of the key ID. * */ - static uint32_t GetType(uint32_t keyId) - { - return keyId & kMask_KeyType; - } + static uint32_t GetType(uint32_t keyId) { return keyId & kMask_KeyType; } /** * Determine whether the specified key ID is of a general type. @@ -154,10 +149,7 @@ class ChipKeyId * @return true if the keyId has General type. * */ - static bool IsGeneralKey(uint32_t keyId) - { - return GetType(keyId) == kType_General; - } + static bool IsGeneralKey(uint32_t keyId) { return GetType(keyId) == kType_General; } /** * Determine whether the specified key ID is of a session type. @@ -166,10 +158,7 @@ class ChipKeyId * @return true if the keyId of a session type. * */ - static bool IsSessionKey(uint32_t keyId) - { - return GetType(keyId) == kType_Session; - } + static bool IsSessionKey(uint32_t keyId) { return GetType(keyId) == kType_Session; } /** * Determine whether the specified key ID is of an application static type. @@ -178,10 +167,7 @@ class ChipKeyId * @return true if the keyId of an application static type. * */ - static bool IsAppStaticKey(uint32_t keyId) - { - return GetType(keyId) == kType_AppStaticKey; - } + static bool IsAppStaticKey(uint32_t keyId) { return GetType(keyId) == kType_AppStaticKey; } /** * Determine whether the specified key ID is of an application rotating type. @@ -190,10 +176,7 @@ class ChipKeyId * @return true if the keyId of an application rotating type. * */ - static bool IsAppRotatingKey(uint32_t keyId) - { - return GetType(keyId) == kType_AppRotatingKey; - } + static bool IsAppRotatingKey(uint32_t keyId) { return GetType(keyId) == kType_AppRotatingKey; } static bool IsAppGroupKey(uint32_t keyId); @@ -204,10 +187,7 @@ class ChipKeyId * @return true if the keyId of an application root key type. * */ - static bool IsAppRootKey(uint32_t keyId) - { - return GetType(keyId) == kType_AppRootKey; - } + static bool IsAppRootKey(uint32_t keyId) { return GetType(keyId) == kType_AppRootKey; } /** * Determine whether the specified key ID is of an application epoch key type. @@ -216,10 +196,7 @@ class ChipKeyId * @return true if the keyId of an application epoch key type. * */ - static bool IsAppEpochKey(uint32_t keyId) - { - return GetType(keyId) == kType_AppEpochKey; - } + static bool IsAppEpochKey(uint32_t keyId) { return GetType(keyId) == kType_AppEpochKey; } /** * Determine whether the specified key ID is of an application group master key type. @@ -228,10 +205,7 @@ class ChipKeyId * @return true if the keyId of an application group master key type. * */ - static bool IsAppGroupMasterKey(uint32_t keyId) - { - return GetType(keyId) == kType_AppGroupMasterKey; - } + static bool IsAppGroupMasterKey(uint32_t keyId) { return GetType(keyId) == kType_AppGroupMasterKey; } /** * Construct session key ID given session key number. @@ -240,10 +214,7 @@ class ChipKeyId * @return session key ID. * */ - static uint16_t MakeSessionKeyId(uint16_t sessionKeyNumber) - { - return kType_Session | (sessionKeyNumber & kMask_KeyNumber); - } + static uint16_t MakeSessionKeyId(uint16_t sessionKeyNumber) { return kType_Session | (sessionKeyNumber & kMask_KeyNumber); } /** * Construct general key ID given general key number. @@ -252,10 +223,7 @@ class ChipKeyId * @return general key ID. * */ - static uint16_t MakeGeneralKeyId(uint16_t generalKeyNumber) - { - return kType_General | (generalKeyNumber & kMask_KeyNumber); - } + static uint16_t MakeGeneralKeyId(uint16_t generalKeyNumber) { return kType_General | (generalKeyNumber & kMask_KeyNumber); } /** * Get application group root key ID that was used to derive specified application key. @@ -264,10 +232,7 @@ class ChipKeyId * @return root key ID. * */ - static uint32_t GetRootKeyId(uint32_t keyId) - { - return kType_AppRootKey | (keyId & kMask_RootKeyNumber); - } + static uint32_t GetRootKeyId(uint32_t keyId) { return kType_AppRootKey | (keyId & kMask_RootKeyNumber); } /** * Get application group epoch key ID that was used to derive specified application key. @@ -276,10 +241,7 @@ class ChipKeyId * @return epoch key ID. * */ - static uint32_t GetEpochKeyId(uint32_t keyId) - { - return kType_AppEpochKey | (keyId & kMask_EpochKeyNumber); - } + static uint32_t GetEpochKeyId(uint32_t keyId) { return kType_AppEpochKey | (keyId & kMask_EpochKeyNumber); } /** * Get application group master key ID that was used to derive specified application key. @@ -288,10 +250,7 @@ class ChipKeyId * @return application group master key ID. * */ - static uint32_t GetAppGroupMasterKeyId(uint32_t keyId) - { - return kType_AppGroupMasterKey | (keyId & kMask_GroupLocalNumber); - } + static uint32_t GetAppGroupMasterKeyId(uint32_t keyId) { return kType_AppGroupMasterKey | (keyId & kMask_GroupLocalNumber); } /** * Get application group root key number that was used to derive specified application key. @@ -300,10 +259,7 @@ class ChipKeyId * @return root key number. * */ - static uint8_t GetRootKeyNumber(uint32_t keyId) - { - return (keyId & kMask_RootKeyNumber) >> kShift_RootKeyNumber; - } + static uint8_t GetRootKeyNumber(uint32_t keyId) { return (keyId & kMask_RootKeyNumber) >> kShift_RootKeyNumber; } /** * Get application group epoch key number that was used to derive specified application key. @@ -312,10 +268,7 @@ class ChipKeyId * @return epoch key number. * */ - static uint8_t GetEpochKeyNumber(uint32_t keyId) - { - return (keyId & kMask_EpochKeyNumber) >> kShift_EpochKeyNumber; - } + static uint8_t GetEpochKeyNumber(uint32_t keyId) { return (keyId & kMask_EpochKeyNumber) >> kShift_EpochKeyNumber; } /** * Get application group local number that was used to derive specified application key. @@ -324,10 +277,7 @@ class ChipKeyId * @return application group local number. * */ - static uint8_t GetAppGroupLocalNumber(uint32_t keyId) - { - return (keyId & kMask_GroupLocalNumber) >> kShift_GroupLocalNumber; - } + static uint8_t GetAppGroupLocalNumber(uint32_t keyId) { return (keyId & kMask_GroupLocalNumber) >> kShift_GroupLocalNumber; } /** * Construct application group root key ID given root key number. @@ -336,10 +286,7 @@ class ChipKeyId * @return root key ID. * */ - static uint32_t MakeRootKeyId(uint8_t rootKeyNumber) - { - return kType_AppRootKey | (rootKeyNumber << kShift_RootKeyNumber); - } + static uint32_t MakeRootKeyId(uint8_t rootKeyNumber) { return kType_AppRootKey | (rootKeyNumber << kShift_RootKeyNumber); } /** * Construct application group root key ID given epoch key number. @@ -348,10 +295,7 @@ class ChipKeyId * @return epoch key ID. * */ - static uint32_t MakeEpochKeyId(uint8_t epochKeyNumber) - { - return kType_AppEpochKey | (epochKeyNumber << kShift_EpochKeyNumber); - } + static uint32_t MakeEpochKeyId(uint8_t epochKeyNumber) { return kType_AppEpochKey | (epochKeyNumber << kShift_EpochKeyNumber); } /** * Construct application group master key ID given application group local number. @@ -372,10 +316,7 @@ class ChipKeyId * @return application current key ID. * */ - static uint32_t ConvertToCurrentAppKeyId(uint32_t keyId) - { - return (keyId & ~kMask_EpochKeyNumber) | kFlag_UseCurrentEpochKey; - } + static uint32_t ConvertToCurrentAppKeyId(uint32_t keyId) { return (keyId & ~kMask_EpochKeyNumber) | kFlag_UseCurrentEpochKey; } /** * Determine whether the specified application group key ID incorporates epoch key. @@ -384,20 +325,17 @@ class ChipKeyId * @return true if the keyId incorporates epoch key. * */ - static bool IncorporatesEpochKey(uint32_t keyId) - { - return (keyId & kTypeModifier_IncorporatesEpochKey) != 0; - } + static bool IncorporatesEpochKey(uint32_t keyId) { return (keyId & kTypeModifier_IncorporatesEpochKey) != 0; } static bool UsesCurrentEpochKey(uint32_t keyId); static bool IncorporatesRootKey(uint32_t keyId); static bool IncorporatesAppGroupMasterKey(uint32_t keyId); - static uint32_t MakeAppKeyId(uint32_t keyType, uint32_t rootKeyId, uint32_t epochKeyId, - uint32_t appGroupMasterKeyId, bool useCurrentEpochKey); + static uint32_t MakeAppKeyId(uint32_t keyType, uint32_t rootKeyId, uint32_t epochKeyId, uint32_t appGroupMasterKeyId, + bool useCurrentEpochKey); static uint32_t MakeAppIntermediateKeyId(uint32_t rootKeyId, uint32_t epochKeyId, bool useCurrentEpochKey); - static uint32_t MakeAppRotatingKeyId(uint32_t rootKeyId, uint32_t epochKeyId, - uint32_t appGroupMasterKeyId, bool useCurrentEpochKey); + static uint32_t MakeAppRotatingKeyId(uint32_t rootKeyId, uint32_t epochKeyId, uint32_t appGroupMasterKeyId, + bool useCurrentEpochKey); static uint32_t MakeAppStaticKeyId(uint32_t rootKeyId, uint32_t appGroupMasterKeyId); static uint32_t ConvertToStaticAppKeyId(uint32_t keyId); static uint32_t UpdateEpochKeyId(uint32_t keyId, uint32_t epochKeyId); @@ -405,7 +343,7 @@ class ChipKeyId static bool IsValidKeyId(uint32_t keyId); static bool IsMessageEncryptionKeyId(uint32_t keyId, bool allowLogicalKeys = true); static bool IsSameKeyOrGroup(uint32_t keyId1, uint32_t keyId2); - static const char *DescribeKey(uint32_t keyId); + static const char * DescribeKey(uint32_t keyId); }; } // namespace chip diff --git a/src/lib/core/CHIPTLV.h b/src/lib/core/CHIPTLV.h index 6ec71d5370330d..82fba0f7f4650b 100644 --- a/src/lib/core/CHIPTLV.h +++ b/src/lib/core/CHIPTLV.h @@ -59,7 +59,8 @@ namespace TLV { using chip::System::PacketBuffer; -enum { +enum +{ kTLVControlByte_NotSpecified = 0xFFFF }; @@ -91,16 +92,16 @@ enum { */ class DLL_EXPORT TLVReader { -friend class TLVWriter; -friend class TLVUpdater; + friend class TLVWriter; + friend class TLVUpdater; public: // *** See CHIPTLVReader.cpp file for API documentation *** - void Init(const TLVReader &aReader); - void Init(const uint8_t *data, uint32_t dataLen); - void Init(PacketBuffer *buf, uint32_t maxLen = 0xFFFFFFFFUL); - void Init(PacketBuffer *buf, uint32_t maxLen, bool allowDiscontiguousBuffers); + void Init(const TLVReader & aReader); + void Init(const uint8_t * data, uint32_t dataLen); + void Init(PacketBuffer * buf, uint32_t maxLen = 0xFFFFFFFFUL); + void Init(PacketBuffer * buf, uint32_t maxLen, bool allowDiscontiguousBuffers); CHIP_ERROR Next(void); CHIP_ERROR Next(TLVType expectedType, uint64_t expectedTag); @@ -110,51 +111,51 @@ friend class TLVUpdater; uint32_t GetLength(void) const; uint16_t GetControlByte(void) const; - CHIP_ERROR Get(bool& v); - CHIP_ERROR Get(int8_t& v); - CHIP_ERROR Get(int16_t& v); - CHIP_ERROR Get(int32_t& v); - CHIP_ERROR Get(int64_t& v); - CHIP_ERROR Get(uint8_t& v); - CHIP_ERROR Get(uint16_t& v); - CHIP_ERROR Get(uint32_t& v); - CHIP_ERROR Get(uint64_t& v); - CHIP_ERROR Get(float& v); - CHIP_ERROR Get(double& v); - CHIP_ERROR GetBytes(uint8_t *buf, uint32_t bufSize); - CHIP_ERROR DupBytes(uint8_t *& buf, uint32_t& dataLen); - CHIP_ERROR GetString(char *buf, uint32_t bufSize); + CHIP_ERROR Get(bool & v); + CHIP_ERROR Get(int8_t & v); + CHIP_ERROR Get(int16_t & v); + CHIP_ERROR Get(int32_t & v); + CHIP_ERROR Get(int64_t & v); + CHIP_ERROR Get(uint8_t & v); + CHIP_ERROR Get(uint16_t & v); + CHIP_ERROR Get(uint32_t & v); + CHIP_ERROR Get(uint64_t & v); + CHIP_ERROR Get(float & v); + CHIP_ERROR Get(double & v); + CHIP_ERROR GetBytes(uint8_t * buf, uint32_t bufSize); + CHIP_ERROR DupBytes(uint8_t *& buf, uint32_t & dataLen); + CHIP_ERROR GetString(char * buf, uint32_t bufSize); CHIP_ERROR DupString(char *& buf); CHIP_ERROR GetDataPtr(const uint8_t *& data); - CHIP_ERROR EnterContainer(TLVType& outerContainerType); + CHIP_ERROR EnterContainer(TLVType & outerContainerType); CHIP_ERROR ExitContainer(TLVType outerContainerType); - CHIP_ERROR OpenContainer(TLVReader& containerReader); - CHIP_ERROR CloseContainer(TLVReader& containerReader); + CHIP_ERROR OpenContainer(TLVReader & containerReader); + CHIP_ERROR CloseContainer(TLVReader & containerReader); TLVType GetContainerType(void) const; CHIP_ERROR VerifyEndOfContainer(void); uint32_t GetLengthRead(void) const { return mLenRead; } uint32_t GetRemainingLength(void) const { return mMaxLen - mLenRead; } - const uint8_t *GetReadPoint(void) const { return mReadPoint; } + const uint8_t * GetReadPoint(void) const { return mReadPoint; } uintptr_t GetBufHandle(void) const { return mBufHandle; } CHIP_ERROR Skip(void); uint32_t ImplicitProfileId; - void *AppData; + void * AppData; - typedef CHIP_ERROR (*GetNextBufferFunct)(TLVReader& reader, uintptr_t& bufHandle, const uint8_t *& bufStart, - uint32_t& bufLen); + typedef CHIP_ERROR (*GetNextBufferFunct)(TLVReader & reader, uintptr_t & bufHandle, const uint8_t *& bufStart, + uint32_t & bufLen); GetNextBufferFunct GetNextBuffer; protected: uint64_t mElemTag; uint64_t mElemLenOrVal; uintptr_t mBufHandle; - const uint8_t *mReadPoint; - const uint8_t *mBufEnd; + const uint8_t * mReadPoint; + const uint8_t * mBufEnd; uint32_t mLenRead; uint32_t mMaxLen; TLVType mContainerType; @@ -174,24 +175,21 @@ friend class TLVUpdater; CHIP_ERROR VerifyElement(void); uint64_t ReadTag(TLVTagControl tagControl, const uint8_t *& p); CHIP_ERROR EnsureData(CHIP_ERROR noDataErr); - CHIP_ERROR ReadData(uint8_t *buf, uint32_t len); - CHIP_ERROR GetElementHeadLength(uint8_t& elemHeadBytes) const; + CHIP_ERROR ReadData(uint8_t * buf, uint32_t len); + CHIP_ERROR GetElementHeadLength(uint8_t & elemHeadBytes) const; TLVElementType ElementType(void) const; - static CHIP_ERROR GetNextPacketBuffer(TLVReader& reader, uintptr_t& bufHandle, const uint8_t *& bufStart, - uint32_t& bufLen); - static CHIP_ERROR FailGetNextBuffer(TLVReader& reader, uintptr_t& bufHandle, const uint8_t *& bufStart, - uint32_t& bufLen); + static CHIP_ERROR GetNextPacketBuffer(TLVReader & reader, uintptr_t & bufHandle, const uint8_t *& bufStart, uint32_t & bufLen); + static CHIP_ERROR FailGetNextBuffer(TLVReader & reader, uintptr_t & bufHandle, const uint8_t *& bufStart, uint32_t & bufLen); #if CHIP_CONFIG_PROVIDE_OBSOLESCENT_INTERFACES - static CHIP_ERROR GetNextInetBuffer(TLVReader& reader, uintptr_t& bufHandle, const uint8_t *& bufStart, - uint32_t& bufLen); + static CHIP_ERROR GetNextInetBuffer(TLVReader & reader, uintptr_t & bufHandle, const uint8_t *& bufStart, uint32_t & bufLen); #endif // CHIP_CONFIG_PROVIDE_OBSOLESCENT_INTERFACES }; #if CHIP_CONFIG_PROVIDE_OBSOLESCENT_INTERFACES -inline CHIP_ERROR TLVReader::GetNextInetBuffer(TLVReader& reader, uintptr_t& bufHandle, const uint8_t *& bufStart, - uint32_t& bufLen) +inline CHIP_ERROR TLVReader::GetNextInetBuffer(TLVReader & reader, uintptr_t & bufHandle, const uint8_t *& bufStart, + uint32_t & bufLen) { return GetNextPacketBuffer(reader, bufHandle, bufStart, bufLen); } @@ -214,13 +212,14 @@ inline CHIP_ERROR TLVReader::GetNextInetBuffer(TLVReader& reader, uintptr_t& buf */ class DLL_EXPORT TLVWriter { -friend class TLVUpdater; + friend class TLVUpdater; + public: // *** See CHIPTLVWriter.cpp file for API documentation *** - void Init(uint8_t *buf, uint32_t maxLen); - void Init(PacketBuffer *buf, uint32_t maxLen = 0xFFFFFFFFUL); - void Init(PacketBuffer *buf, uint32_t maxLen, bool allowDiscontiguousBuffers); + void Init(uint8_t * buf, uint32_t maxLen); + void Init(PacketBuffer * buf, uint32_t maxLen = 0xFFFFFFFFUL); + void Init(PacketBuffer * buf, uint32_t maxLen, bool allowDiscontiguousBuffers); CHIP_ERROR Finalize(void); @@ -243,52 +242,50 @@ friend class TLVUpdater; CHIP_ERROR Put(uint64_t tag, float v); CHIP_ERROR Put(uint64_t tag, double v); CHIP_ERROR PutBoolean(uint64_t tag, bool v); - CHIP_ERROR PutBytes(uint64_t tag, const uint8_t *buf, uint32_t len); - CHIP_ERROR PutString(uint64_t tag, const char *buf); - CHIP_ERROR PutString(uint64_t tag, const char *buf, uint32_t len); - CHIP_ERROR PutStringF(uint64_t tag, const char *fmt, ...); - CHIP_ERROR VPutStringF(uint64_t tag, const char *fmt, va_list ap); + CHIP_ERROR PutBytes(uint64_t tag, const uint8_t * buf, uint32_t len); + CHIP_ERROR PutString(uint64_t tag, const char * buf); + CHIP_ERROR PutString(uint64_t tag, const char * buf, uint32_t len); + CHIP_ERROR PutStringF(uint64_t tag, const char * fmt, ...); + CHIP_ERROR VPutStringF(uint64_t tag, const char * fmt, va_list ap); CHIP_ERROR PutNull(uint64_t tag); - CHIP_ERROR CopyElement(TLVReader& reader); - CHIP_ERROR CopyElement(uint64_t tag, TLVReader& reader); + CHIP_ERROR CopyElement(TLVReader & reader); + CHIP_ERROR CopyElement(uint64_t tag, TLVReader & reader); - CHIP_ERROR StartContainer(uint64_t tag, TLVType containerType, TLVType& outerContainerType); + CHIP_ERROR StartContainer(uint64_t tag, TLVType containerType, TLVType & outerContainerType); CHIP_ERROR EndContainer(TLVType outerContainerType); - CHIP_ERROR OpenContainer(uint64_t tag, TLVType containerType, TLVWriter& containerWriter); - CHIP_ERROR CloseContainer(TLVWriter& containerWriter); - CHIP_ERROR PutPreEncodedContainer(uint64_t tag, TLVType containerType, const uint8_t *data, uint32_t dataLen); - CHIP_ERROR CopyContainer(TLVReader& container); - CHIP_ERROR CopyContainer(uint64_t tag, TLVReader& container); + CHIP_ERROR OpenContainer(uint64_t tag, TLVType containerType, TLVWriter & containerWriter); + CHIP_ERROR CloseContainer(TLVWriter & containerWriter); + CHIP_ERROR PutPreEncodedContainer(uint64_t tag, TLVType containerType, const uint8_t * data, uint32_t dataLen); + CHIP_ERROR CopyContainer(TLVReader & container); + CHIP_ERROR CopyContainer(uint64_t tag, TLVReader & container); CHIP_ERROR CopyContainer(uint64_t tag, const uint8_t * encodedContainer, uint16_t encodedContainerLen); TLVType GetContainerType(void) const; uint32_t GetLengthWritten(void); uint32_t ImplicitProfileId; - void *AppData; + void * AppData; - typedef CHIP_ERROR (*GetNewBufferFunct)(TLVWriter& writer, uintptr_t& bufHandle, uint8_t *& bufStart, - uint32_t& bufLen); + typedef CHIP_ERROR (*GetNewBufferFunct)(TLVWriter & writer, uintptr_t & bufHandle, uint8_t *& bufStart, uint32_t & bufLen); GetNewBufferFunct GetNewBuffer; - typedef CHIP_ERROR (*FinalizeBufferFunct)(TLVWriter& writer, uintptr_t bufHandle, uint8_t *bufStart, - uint32_t bufLen); + typedef CHIP_ERROR (*FinalizeBufferFunct)(TLVWriter & writer, uintptr_t bufHandle, uint8_t * bufStart, uint32_t bufLen); FinalizeBufferFunct FinalizeBuffer; // Implementations of GetNewBufferFunct/FinalizeBufferFunct that support writing into one or more // PacketBuffers. - static CHIP_ERROR GetNewPacketBuffer(TLVWriter& writer, uintptr_t& bufHandle, uint8_t *& bufStart, uint32_t& bufLen); - static CHIP_ERROR FinalizePacketBuffer(TLVWriter& writer, uintptr_t bufHandle, uint8_t *bufStart, uint32_t dataLen); + static CHIP_ERROR GetNewPacketBuffer(TLVWriter & writer, uintptr_t & bufHandle, uint8_t *& bufStart, uint32_t & bufLen); + static CHIP_ERROR FinalizePacketBuffer(TLVWriter & writer, uintptr_t bufHandle, uint8_t * bufStart, uint32_t dataLen); #if CHIP_CONFIG_PROVIDE_OBSOLESCENT_INTERFACES - static CHIP_ERROR GetNewInetBuffer(TLVWriter& writer, uintptr_t& bufHandle, uint8_t *& bufStart, uint32_t& bufLen); - static CHIP_ERROR FinalizeInetBuffer(TLVWriter& writer, uintptr_t bufHandle, uint8_t *bufStart, uint32_t dataLen); + static CHIP_ERROR GetNewInetBuffer(TLVWriter & writer, uintptr_t & bufHandle, uint8_t *& bufStart, uint32_t & bufLen); + static CHIP_ERROR FinalizeInetBuffer(TLVWriter & writer, uintptr_t bufHandle, uint8_t * bufStart, uint32_t dataLen); #endif // CHIP_CONFIG_PROVIDE_OBSOLESCENT_INTERFACES protected: uintptr_t mBufHandle; - uint8_t *mBufStart; - uint8_t *mWritePoint; + uint8_t * mBufStart; + uint8_t * mWritePoint; uint32_t mRemainingLen; uint32_t mLenWritten; uint32_t mMaxLen; @@ -302,7 +299,8 @@ friend class TLVUpdater; bool IsContainerOpen(void) const { return mContainerOpen; } void SetContainerOpen(bool aContainerOpen) { mContainerOpen = aContainerOpen; } - enum { + enum + { kEndOfContainerMarkerSize = 1, /**< Size of the EndOfContainer marker, used in reserving space. */ }; @@ -323,20 +321,20 @@ friend class TLVUpdater; void SetCloseContainerReserved(bool aCloseContainerReserved) { mCloseContainerReserved = aCloseContainerReserved; } #if CONFIG_HAVE_VCBPRINTF - static void CHIPTLVWriterPutcharCB(uint8_t c, void *appState); + static void CHIPTLVWriterPutcharCB(uint8_t c, void * appState); #endif CHIP_ERROR WriteElementHead(TLVElementType elemType, uint64_t tag, uint64_t lenOrVal); - CHIP_ERROR WriteElementWithData(TLVType type, uint64_t tag, const uint8_t *data, uint32_t dataLen); - CHIP_ERROR WriteData(const uint8_t *p, uint32_t len); + CHIP_ERROR WriteElementWithData(TLVType type, uint64_t tag, const uint8_t * data, uint32_t dataLen); + CHIP_ERROR WriteData(const uint8_t * p, uint32_t len); }; #if CHIP_CONFIG_PROVIDE_OBSOLESCENT_INTERFACES -inline CHIP_ERROR TLVWriter::GetNewInetBuffer(TLVWriter& writer, uintptr_t& bufHandle, uint8_t *& bufStart, uint32_t& bufLen) +inline CHIP_ERROR TLVWriter::GetNewInetBuffer(TLVWriter & writer, uintptr_t & bufHandle, uint8_t *& bufStart, uint32_t & bufLen) { return GetNewPacketBuffer(writer, bufHandle, bufStart, bufLen); } -inline CHIP_ERROR TLVWriter::FinalizeInetBuffer(TLVWriter& writer, uintptr_t bufHandle, uint8_t *bufStart, uint32_t dataLen) +inline CHIP_ERROR TLVWriter::FinalizeInetBuffer(TLVWriter & writer, uintptr_t bufHandle, uint8_t * bufStart, uint32_t dataLen) { return FinalizePacketBuffer(writer, bufHandle, bufStart, dataLen); } @@ -379,8 +377,8 @@ inline CHIP_ERROR TLVWriter::FinalizeInetBuffer(TLVWriter& writer, uintptr_t buf class DLL_EXPORT TLVUpdater { public: - CHIP_ERROR Init(uint8_t *buf, uint32_t dataLen, uint32_t maxLen); - CHIP_ERROR Init(TLVReader& aReader, uint32_t freeLen); + CHIP_ERROR Init(uint8_t * buf, uint32_t dataLen, uint32_t maxLen); + CHIP_ERROR Init(TLVReader & aReader, uint32_t freeLen); CHIP_ERROR Finalize(void) { return mUpdaterWriter.Finalize(); } // Common methods @@ -388,27 +386,27 @@ class DLL_EXPORT TLVUpdater uint32_t GetImplicitProfileId(void) { return mUpdaterReader.ImplicitProfileId; } CHIP_ERROR Move(void); void MoveUntilEnd(void); - CHIP_ERROR EnterContainer(TLVType& outerContainerType); + CHIP_ERROR EnterContainer(TLVType & outerContainerType); CHIP_ERROR ExitContainer(TLVType outerContainerType); - void GetReader(TLVReader& containerReader) { containerReader = mUpdaterReader; } + void GetReader(TLVReader & containerReader) { containerReader = mUpdaterReader; } // Reader methods CHIP_ERROR Next(void); - CHIP_ERROR Get(bool& v) { return mUpdaterReader.Get(v); } - CHIP_ERROR Get(int8_t& v) { return mUpdaterReader.Get(v); } - CHIP_ERROR Get(int16_t& v) { return mUpdaterReader.Get(v); } - CHIP_ERROR Get(int32_t& v) { return mUpdaterReader.Get(v); } - CHIP_ERROR Get(int64_t& v) { return mUpdaterReader.Get(v); } - CHIP_ERROR Get(uint8_t& v) { return mUpdaterReader.Get(v); } - CHIP_ERROR Get(uint16_t& v) { return mUpdaterReader.Get(v); } - CHIP_ERROR Get(uint32_t& v) { return mUpdaterReader.Get(v); } - CHIP_ERROR Get(uint64_t& v) { return mUpdaterReader.Get(v); } - CHIP_ERROR Get(float& v) { return mUpdaterReader.Get(v); } - CHIP_ERROR Get(double& v) { return mUpdaterReader.Get(v); } - CHIP_ERROR GetBytes(uint8_t *buf, uint32_t bufSize) { return mUpdaterReader.GetBytes(buf, bufSize); } - CHIP_ERROR DupBytes(uint8_t *& buf, uint32_t& dataLen) { return mUpdaterReader.DupBytes(buf, dataLen); } - CHIP_ERROR GetString(char *buf, uint32_t bufSize) { return mUpdaterReader.GetString(buf, bufSize); } + CHIP_ERROR Get(bool & v) { return mUpdaterReader.Get(v); } + CHIP_ERROR Get(int8_t & v) { return mUpdaterReader.Get(v); } + CHIP_ERROR Get(int16_t & v) { return mUpdaterReader.Get(v); } + CHIP_ERROR Get(int32_t & v) { return mUpdaterReader.Get(v); } + CHIP_ERROR Get(int64_t & v) { return mUpdaterReader.Get(v); } + CHIP_ERROR Get(uint8_t & v) { return mUpdaterReader.Get(v); } + CHIP_ERROR Get(uint16_t & v) { return mUpdaterReader.Get(v); } + CHIP_ERROR Get(uint32_t & v) { return mUpdaterReader.Get(v); } + CHIP_ERROR Get(uint64_t & v) { return mUpdaterReader.Get(v); } + CHIP_ERROR Get(float & v) { return mUpdaterReader.Get(v); } + CHIP_ERROR Get(double & v) { return mUpdaterReader.Get(v); } + CHIP_ERROR GetBytes(uint8_t * buf, uint32_t bufSize) { return mUpdaterReader.GetBytes(buf, bufSize); } + CHIP_ERROR DupBytes(uint8_t *& buf, uint32_t & dataLen) { return mUpdaterReader.DupBytes(buf, dataLen); } + CHIP_ERROR GetString(char * buf, uint32_t bufSize) { return mUpdaterReader.GetString(buf, bufSize); } CHIP_ERROR DupString(char *& buf) { return mUpdaterReader.DupString(buf); } TLVType GetType(void) const { return mUpdaterReader.GetType(); } @@ -441,12 +439,15 @@ class DLL_EXPORT TLVUpdater CHIP_ERROR Put(uint64_t tag, double v) { return mUpdaterWriter.Put(tag, v); } CHIP_ERROR PutBoolean(uint64_t tag, bool v) { return mUpdaterWriter.PutBoolean(tag, v); } CHIP_ERROR PutNull(uint64_t tag) { return mUpdaterWriter.PutNull(tag); } - CHIP_ERROR PutBytes(uint64_t tag, const uint8_t *buf, uint32_t len) { return mUpdaterWriter.PutBytes(tag, buf, len); } - CHIP_ERROR PutString(uint64_t tag, const char *buf) { return mUpdaterWriter.PutString(tag, buf); } - CHIP_ERROR PutString(uint64_t tag, const char *buf, uint32_t len) { return mUpdaterWriter.PutString(tag, buf, len); } - CHIP_ERROR CopyElement(TLVReader& reader) { return mUpdaterWriter.CopyElement(reader); } - CHIP_ERROR CopyElement(uint64_t tag, TLVReader& reader) { return mUpdaterWriter.CopyElement(tag, reader); } - CHIP_ERROR StartContainer(uint64_t tag, TLVType containerType, TLVType& outerContainerType) { return mUpdaterWriter.StartContainer(tag, containerType, outerContainerType); } + CHIP_ERROR PutBytes(uint64_t tag, const uint8_t * buf, uint32_t len) { return mUpdaterWriter.PutBytes(tag, buf, len); } + CHIP_ERROR PutString(uint64_t tag, const char * buf) { return mUpdaterWriter.PutString(tag, buf); } + CHIP_ERROR PutString(uint64_t tag, const char * buf, uint32_t len) { return mUpdaterWriter.PutString(tag, buf, len); } + CHIP_ERROR CopyElement(TLVReader & reader) { return mUpdaterWriter.CopyElement(reader); } + CHIP_ERROR CopyElement(uint64_t tag, TLVReader & reader) { return mUpdaterWriter.CopyElement(tag, reader); } + CHIP_ERROR StartContainer(uint64_t tag, TLVType containerType, TLVType & outerContainerType) + { + return mUpdaterWriter.StartContainer(tag, containerType, outerContainerType); + } CHIP_ERROR EndContainer(TLVType outerContainerType) { return mUpdaterWriter.EndContainer(outerContainerType); } uint32_t GetLengthWritten(void) { return mUpdaterWriter.GetLengthWritten(); } uint32_t GetRemainingFreeLength(void) { return mUpdaterWriter.mRemainingLen; } @@ -455,8 +456,8 @@ class DLL_EXPORT TLVUpdater void AdjustInternalWriterFreeSpace(void); private: - TLVWriter mUpdaterWriter; - TLVReader mUpdaterReader; + TLVWriter mUpdaterWriter; + TLVReader mUpdaterReader; const uint8_t * mElementStartAddr; }; diff --git a/src/lib/core/CHIPTLVData.hpp b/src/lib/core/CHIPTLVData.hpp index 3ed6aeb47c167b..6bf80296c8ca2e 100644 --- a/src/lib/core/CHIPTLVData.hpp +++ b/src/lib/core/CHIPTLVData.hpp @@ -26,7 +26,6 @@ * */ - #ifndef CHIP_TLV_DATA_H_ #define CHIP_TLV_DATA_H_ @@ -39,42 +38,42 @@ * * @note Integral truncate would take the least significant bits, regardless of hardware endianness. */ -#define CHIP_TLV_GetLower32From64(v) ((uint32_t)(((uint64_t)(v) >> 0) & 0xFFFFFFFFUL)) +#define CHIP_TLV_GetLower32From64(v) ((uint32_t)(((uint64_t)(v) >> 0) & 0xFFFFFFFFUL)) /* * @brief Integral truncate argument X to the next least significant 32-bit * * @note Right bit shift gets rid of the least significant bits, regardless of hardware endianness. */ -#define CHIP_TLV_GetUpper32From64(v) ((uint32_t)(((uint64_t)(v) >> 32) & 0xFFFFFFFFUL)) +#define CHIP_TLV_GetUpper32From64(v) ((uint32_t)(((uint64_t)(v) >> 32) & 0xFFFFFFFFUL)) /* * @brief Integral truncate L to the least significant 16-bit * * @note Integral truncate would take the least significant bits, regardless of hardware endianness. */ -#define CHIP_TLV_GetLower16From32(v) ((uint16_t)(((uint32_t)(v) >> 0) & 0xFFFFU)) +#define CHIP_TLV_GetLower16From32(v) ((uint16_t)(((uint32_t)(v) >> 0) & 0xFFFFU)) /* * @brief Integral truncate argument X to the next least significant 16-bit * * @note Right bit shift gets rid of the least significant bits, regardless of hardware endianness. */ -#define CHIP_TLV_GetUpper16From32(v) ((uint16_t)(((uint32_t)(v) >> 16) & 0xFFFFU)) +#define CHIP_TLV_GetUpper16From32(v) ((uint16_t)(((uint32_t)(v) >> 16) & 0xFFFFU)) /* * @brief Integral truncate L to the least significant 8-bit * * @note Integral truncate would take the least significant bits, regardless of hardware endianness. */ -#define CHIP_TLV_GetLower8From16(v) ((uint8_t)(((uint16_t)(v) >> 0) & 0xFFU)) +#define CHIP_TLV_GetLower8From16(v) ((uint8_t)(((uint16_t)(v) >> 0) & 0xFFU)) /* * @brief Integral truncate argument X to the next least significant 8-bit * * @note Right bit shift gets rid of the least significant bits, regardless of hardware endianness. */ -#define CHIP_TLV_GetUpper8From16(v) ((uint8_t)(((uint16_t)(v) >> 8) & 0xFFU)) +#define CHIP_TLV_GetUpper8From16(v) ((uint8_t)(((uint16_t)(v) >> 8) & 0xFFU)) /* * @brief Integral truncate argument v to 8-bit @@ -94,12 +93,14 @@ /* * @brief Integral truncate argument v to 32-bit, and then serialize it using CHIP standard Little Endian order */ -#define CHIP_TLV_Serialize32(v) CHIP_TLV_Serialize16(CHIP_TLV_GetLower16From32(v)), CHIP_TLV_Serialize16(CHIP_TLV_GetUpper16From32(v)) +#define CHIP_TLV_Serialize32(v) \ + CHIP_TLV_Serialize16(CHIP_TLV_GetLower16From32(v)), CHIP_TLV_Serialize16(CHIP_TLV_GetUpper16From32(v)) /* * @brief Integral truncate argument v to 64-bit, and then serialize it using CHIP standard Little Endian order */ -#define CHIP_TLV_Serialize64(v) CHIP_TLV_Serialize32(CHIP_TLV_GetLower32From64(v)), CHIP_TLV_Serialize32(CHIP_TLV_GetUpper32From64(v)) +#define CHIP_TLV_Serialize64(v) \ + CHIP_TLV_Serialize32(CHIP_TLV_GetLower32From64(v)), CHIP_TLV_Serialize32(CHIP_TLV_GetUpper32From64(v)) /* * @brief Specifies an anonymous TLV element, which doesn't have any tag @@ -117,32 +118,28 @@ * @param Tag The tag for this TLV element, defined under Common Profile. * Would be truncated to 16 bites. */ -#define CHIP_TLV_TAG_COMMON_PROFILE_2Bytes(Tag) \ - chip::TLV::kTLVTagControl_CommonProfile_2Bytes, CHIP_TLV_Serialize16(Tag) +#define CHIP_TLV_TAG_COMMON_PROFILE_2Bytes(Tag) chip::TLV::kTLVTagControl_CommonProfile_2Bytes, CHIP_TLV_Serialize16(Tag) /* * @brief Specifies a TLV element with a Common Profile tag * @param Tag The tag for this TLV element, defined under Common Profile. * Would be truncated to 32 bites. */ -#define CHIP_TLV_TAG_COMMON_PROFILE_4Bytes(Tag) \ - chip::TLV::kTLVTagControl_CommonProfile_4Bytes, CHIP_TLV_Serialize32(Tag) +#define CHIP_TLV_TAG_COMMON_PROFILE_4Bytes(Tag) chip::TLV::kTLVTagControl_CommonProfile_4Bytes, CHIP_TLV_Serialize32(Tag) /* * @brief Specifies a TLV element with an Implicit Profile tag * @param Tag The tag for this TLV element, defined under the current implicit profile. * Would be truncated to 16 bits. */ -#define CHIP_TLV_TAG_IMPLICIT_PROFILE_2Bytes(Tag) \ - chip::TLV::kTLVTagControl_ImplicitProfile_2Bytes, CHIP_TLV_Serialize16(Tag) +#define CHIP_TLV_TAG_IMPLICIT_PROFILE_2Bytes(Tag) chip::TLV::kTLVTagControl_ImplicitProfile_2Bytes, CHIP_TLV_Serialize16(Tag) /* * @brief Specifies a TLV element with an Implicit Profile tag * @param Tag The tag for this TLV element, defined under the current implicit profile. * Would be truncated to 32 bits. */ -#define CHIP_TLV_TAG_IMPLICIT_PROFILE_4Bytes(Tag) \ - chip::TLV::kTLVTagControl_ImplicitProfile_4Bytes, CHIP_TLV_Serialize32(Tag) +#define CHIP_TLV_TAG_IMPLICIT_PROFILE_4Bytes(Tag) chip::TLV::kTLVTagControl_ImplicitProfile_4Bytes, CHIP_TLV_Serialize32(Tag) /* * @brief Specifies a TLV element with a Fully Qualified tag @@ -150,8 +147,9 @@ * @param Tag The tag for this TLV element, defined under ProfileId. * Would be truncated to 16 bits. */ -#define CHIP_TLV_TAG_FULLY_QUALIFIED_6Bytes(ProfileId, Tag) \ - chip::TLV::kTLVTagControl_FullyQualified_6Bytes, CHIP_TLV_Serialize16(ProfileId >> 16), CHIP_TLV_Serialize16(ProfileId), CHIP_TLV_Serialize16(Tag) +#define CHIP_TLV_TAG_FULLY_QUALIFIED_6Bytes(ProfileId, Tag) \ + chip::TLV::kTLVTagControl_FullyQualified_6Bytes, CHIP_TLV_Serialize16(ProfileId >> 16), CHIP_TLV_Serialize16(ProfileId), \ + CHIP_TLV_Serialize16(Tag) /* * @brief Specifies a TLV element with a Fully Qualified tag @@ -159,8 +157,9 @@ * @param Tag The tag for this TLV element, defined under ProfileId. * Would be truncated to 32 bits. */ -#define CHIP_TLV_TAG_FULLY_QUALIFIED_8Bytes(ProfileId, Tag) \ - chip::TLV::kTLVTagControl_FullyQualified_8Bytes, CHIP_TLV_Serialize16(ProfileId >> 16), CHIP_TLV_Serialize16(ProfileId), CHIP_TLV_Serialize32(Tag) +#define CHIP_TLV_TAG_FULLY_QUALIFIED_8Bytes(ProfileId, Tag) \ + chip::TLV::kTLVTagControl_FullyQualified_8Bytes, CHIP_TLV_Serialize16(ProfileId >> 16), CHIP_TLV_Serialize16(ProfileId), \ + CHIP_TLV_Serialize32(Tag) /* * @brief Specifies a NULL TLV element, which has just the tag but no value @@ -191,7 +190,7 @@ * @param TagSpec Should be filled with macros begin with CHIP_TLV_TAG_ * @param Value Should be either true or false */ -#define CHIP_TLV_BOOL(TagSpec, Value) \ +#define CHIP_TLV_BOOL(TagSpec, Value) \ ((Value) ? chip::TLV::kTLVElementType_BooleanTrue : chip::TLV::kTLVElementType_BooleanFalse) | TagSpec /** @@ -202,8 +201,7 @@ * * @param ... Bytes representing the floating point value to serialize */ -#define CHIP_TLV_FLOAT32(TagSpec, ...) \ - chip::TLV::kTLVElementType_FloatingPointNumber32 | TagSpec, ## __VA_ARGS__ +#define CHIP_TLV_FLOAT32(TagSpec, ...) chip::TLV::kTLVElementType_FloatingPointNumber32 | TagSpec, ##__VA_ARGS__ /** * @brief @@ -213,8 +211,7 @@ * * @param ... Bytes representing the floating point value to serialize */ -#define CHIP_TLV_FLOAT64(TagSpec, ...) \ - chip::TLV::kTLVElementType_FloatingPointNumber64 | TagSpec, ## __VA_ARGS__ +#define CHIP_TLV_FLOAT64(TagSpec, ...) chip::TLV::kTLVElementType_FloatingPointNumber64 | TagSpec, ##__VA_ARGS__ /* * @brief Specifies a EndOfContainer TLV element, marking the end of a Structure, Array, or Path @@ -236,7 +233,6 @@ */ #define CHIP_TLV_END_OF_PATH CHIP_TLV_END_OF_CONTAINER - /* * @brief Specifies an 8-bit Signed Integer TLV element * @param TagSpec Should be filled with macros begin with CHIP_TLV_TAG_ @@ -303,8 +299,8 @@ * * @param ... Bytes representing the string characters to serialize */ -#define CHIP_TLV_UTF8_STRING_1ByteLength(TagSpec, StringLength, ...) \ - chip::TLV::kTLVElementType_UTF8String_1ByteLength | TagSpec, CHIP_TLV_Serialize8((uint8_t)(StringLength)), ## __VA_ARGS__ +#define CHIP_TLV_UTF8_STRING_1ByteLength(TagSpec, StringLength, ...) \ + chip::TLV::kTLVElementType_UTF8String_1ByteLength | TagSpec, CHIP_TLV_Serialize8((uint8_t)(StringLength)), ##__VA_ARGS__ /** * @brief @@ -316,8 +312,8 @@ * * @param ... Bytes representing the string characters to serialize */ -#define CHIP_TLV_UTF8_STRING_2ByteLength(TagSpec, StringLength, ...) \ - chip::TLV::kTLVElementType_UTF8String_2ByteLength | TagSpec, CHIP_TLV_Serialize16((uint16_t)(StringLength)), ## __VA_ARGS__ +#define CHIP_TLV_UTF8_STRING_2ByteLength(TagSpec, StringLength, ...) \ + chip::TLV::kTLVElementType_UTF8String_2ByteLength | TagSpec, CHIP_TLV_Serialize16((uint16_t)(StringLength)), ##__VA_ARGS__ /** * @brief @@ -329,8 +325,8 @@ * * @param ... Bytes representing the string characters to serialize */ -#define CHIP_TLV_UTF8_STRING_4ByteLength(TagSpec, StringLength, ...) \ - chip::TLV::kTLVElementType_UTF8String_4ByteLength | TagSpec, CHIP_TLV_Serialize32((uint32_t)(StringLength)), ## __VA_ARGS__ +#define CHIP_TLV_UTF8_STRING_4ByteLength(TagSpec, StringLength, ...) \ + chip::TLV::kTLVElementType_UTF8String_4ByteLength | TagSpec, CHIP_TLV_Serialize32((uint32_t)(StringLength)), ##__VA_ARGS__ /** * @brief @@ -342,8 +338,8 @@ * * @param ... Bytes representing the string characters to serialize */ -#define CHIP_TLV_UTF8_STRING_8ByteLength(TagSpec, StringLength, ...) \ - chip::TLV::kTLVElementType_UTF8String_8ByteLength | TagSpec, CHIP_TLV_Serialize64((uint64_t)(StringLength)), ## __VA_ARGS__ +#define CHIP_TLV_UTF8_STRING_8ByteLength(TagSpec, StringLength, ...) \ + chip::TLV::kTLVElementType_UTF8String_8ByteLength | TagSpec, CHIP_TLV_Serialize64((uint64_t)(StringLength)), ##__VA_ARGS__ /** * @brief @@ -355,8 +351,8 @@ * * @param ... Bytes to serialize */ -#define CHIP_TLV_BYTE_STRING_1ByteLength(TagSpec, StringLength, ...) \ - chip::TLV::kTLVElementType_ByteString_1ByteLength | TagSpec, CHIP_TLV_Serialize8((uint8_t)(StringLength)), ## __VA_ARGS__ +#define CHIP_TLV_BYTE_STRING_1ByteLength(TagSpec, StringLength, ...) \ + chip::TLV::kTLVElementType_ByteString_1ByteLength | TagSpec, CHIP_TLV_Serialize8((uint8_t)(StringLength)), ##__VA_ARGS__ /** * @brief @@ -368,8 +364,8 @@ * * @param ... Bytes to serialize */ -#define CHIP_TLV_BYTE_STRING_2ByteLength(TagSpec, StringLength, ...) \ - chip::TLV::kTLVElementType_ByteString_2ByteLength | TagSpec, CHIP_TLV_Serialize16((uint16_t)(StringLength)), ## __VA_ARGS__ +#define CHIP_TLV_BYTE_STRING_2ByteLength(TagSpec, StringLength, ...) \ + chip::TLV::kTLVElementType_ByteString_2ByteLength | TagSpec, CHIP_TLV_Serialize16((uint16_t)(StringLength)), ##__VA_ARGS__ /** * @brief @@ -381,8 +377,8 @@ * * @param ... Bytes to serialize */ -#define CHIP_TLV_BYTE_STRING_4ByteLength(TagSpec, StringLength, ...) \ - chip::TLV::kTLVElementType_ByteString_4ByteLength | TagSpec, CHIP_TLV_Serialize32((uint32_t)(StringLength)), ## __VA_ARGS__ +#define CHIP_TLV_BYTE_STRING_4ByteLength(TagSpec, StringLength, ...) \ + chip::TLV::kTLVElementType_ByteString_4ByteLength | TagSpec, CHIP_TLV_Serialize32((uint32_t)(StringLength)), ##__VA_ARGS__ /** * @brief @@ -394,7 +390,7 @@ * * @param ... Bytes to serialize */ -#define CHIP_TLV_BYTE_STRING_8ByteLength(TagSpec, StringLength, ...) \ - chip::TLV::kTLVElementType_ByteString_8ByteLength | TagSpec, CHIP_TLV_Serialize64((uint64_t)(StringLength)), ## __VA_ARGS__ +#define CHIP_TLV_BYTE_STRING_8ByteLength(TagSpec, StringLength, ...) \ + chip::TLV::kTLVElementType_ByteString_8ByteLength | TagSpec, CHIP_TLV_Serialize64((uint64_t)(StringLength)), ##__VA_ARGS__ #endif /* CHIPTLVDATA_H_ */ diff --git a/src/lib/core/CHIPTLVDebug.hpp b/src/lib/core/CHIPTLVDebug.hpp index 917e2f57466f03..d4ab049266c962 100644 --- a/src/lib/core/CHIPTLVDebug.hpp +++ b/src/lib/core/CHIPTLVDebug.hpp @@ -46,22 +46,23 @@ namespace TLV { */ namespace Debug { -typedef void (*DumpWriter)(const char *aFormat, ...); +typedef void (*DumpWriter)(const char * aFormat, ...); -struct DumpContext { +struct DumpContext +{ DumpWriter mWriter; - void * mContext; + void * mContext; }; -extern const char *DecodeType(const TLVType aType); +extern const char * DecodeType(const TLVType aType); -extern const char *DecodeTagControl(const TLVTagControl aTagControl); +extern const char * DecodeTagControl(const TLVTagControl aTagControl); -extern CHIP_ERROR DumpIterator(DumpWriter aWriter, const TLVReader &aReader); +extern CHIP_ERROR DumpIterator(DumpWriter aWriter, const TLVReader & aReader); -extern CHIP_ERROR DumpHandler(const TLVReader &aReader, size_t aDepth, void *aContext); +extern CHIP_ERROR DumpHandler(const TLVReader & aReader, size_t aDepth, void * aContext); -extern CHIP_ERROR Dump(const TLVReader &aReader, DumpWriter aWriter); +extern CHIP_ERROR Dump(const TLVReader & aReader, DumpWriter aWriter); } // namespace Debug diff --git a/src/lib/core/CHIPTLVTags.h b/src/lib/core/CHIPTLVTags.h index 64b5751c964534..79055b706adab3 100644 --- a/src/lib/core/CHIPTLVTags.h +++ b/src/lib/core/CHIPTLVTags.h @@ -34,45 +34,44 @@ enum TLVCommonProfiles * Used to indicate the absence of a profile id in a variable or member. * This is essentially the same as kCHIPProfile_NotSpecified defined in CHIPProfiles.h */ - kProfileIdNotSpecified = 0xFFFFFFFF, + kProfileIdNotSpecified = 0xFFFFFFFF, // TODO: Replace with chip::Profiles::kCHIPProfile_Common - kCommonProfileId = 0 + kCommonProfileId = 0 }; // TODO: Move to private namespace enum TLVTagFields { - kProfileIdMask = 0xFFFFFFFF00000000ULL, - kProfileIdShift = 32, - kVendorIdShift = 48, - kProfileNumShift = 32, - kTagNumMask = 0x00000000FFFFFFFFULL, - kSpecialTagMarker = 0xFFFFFFFF00000000ULL, - kContextTagMaxNum = 256 + kProfileIdMask = 0xFFFFFFFF00000000ULL, + kProfileIdShift = 32, + kVendorIdShift = 48, + kProfileNumShift = 32, + kTagNumMask = 0x00000000FFFFFFFFULL, + kSpecialTagMarker = 0xFFFFFFFF00000000ULL, + kContextTagMaxNum = 256 }; // TODO: Move to private namespace enum TLVTagControl { - kTLVTagControl_Anonymous = 0x00, - kTLVTagControl_ContextSpecific = 0x20, - kTLVTagControl_CommonProfile_2Bytes = 0x40, - kTLVTagControl_CommonProfile_4Bytes = 0x60, - kTLVTagControl_ImplicitProfile_2Bytes = 0x80, - kTLVTagControl_ImplicitProfile_4Bytes = 0xA0, - kTLVTagControl_FullyQualified_6Bytes = 0xC0, - kTLVTagControl_FullyQualified_8Bytes = 0xE0 + kTLVTagControl_Anonymous = 0x00, + kTLVTagControl_ContextSpecific = 0x20, + kTLVTagControl_CommonProfile_2Bytes = 0x40, + kTLVTagControl_CommonProfile_4Bytes = 0x60, + kTLVTagControl_ImplicitProfile_2Bytes = 0x80, + kTLVTagControl_ImplicitProfile_4Bytes = 0xA0, + kTLVTagControl_FullyQualified_6Bytes = 0xC0, + kTLVTagControl_FullyQualified_8Bytes = 0xE0 }; // TODO: Move to private namespace enum { - kTLVTagControlMask = 0xE0, - kTLVTagControlShift = 5 + kTLVTagControlMask = 0xE0, + kTLVTagControlShift = 5 }; - /** * Generates the API representation of a profile-specific TLV tag from a profile id and tag number * @@ -80,7 +79,10 @@ enum * @param[in] tagNum The profile-specific tag number assigned to the tag. * @return A 64-bit integer representing the tag. */ -inline uint64_t ProfileTag(uint32_t profileId, uint32_t tagNum) { return (((uint64_t)profileId) << kProfileIdShift) | tagNum; } +inline uint64_t ProfileTag(uint32_t profileId, uint32_t tagNum) +{ + return (((uint64_t) profileId) << kProfileIdShift) | tagNum; +} /** * Generates the API representation of a profile-specific TLV tag from a vendor id, profile number and tag number @@ -90,7 +92,10 @@ inline uint64_t ProfileTag(uint32_t profileId, uint32_t tagNum) { return (((uint * @param[in] tagNum The profile-specific tag number assigned to the tag. * @return A 64-bit integer representing the tag. */ -inline uint64_t ProfileTag(uint16_t vendorId, uint16_t profileNum, uint32_t tagNum) { return (((uint64_t)vendorId) << kVendorIdShift) | (((uint64_t)profileNum) << kProfileNumShift) | tagNum; } +inline uint64_t ProfileTag(uint16_t vendorId, uint16_t profileNum, uint32_t tagNum) +{ + return (((uint64_t) vendorId) << kVendorIdShift) | (((uint64_t) profileNum) << kProfileNumShift) | tagNum; +} /** * Generates the API representation for of context-specific TLV tag @@ -98,7 +103,10 @@ inline uint64_t ProfileTag(uint16_t vendorId, uint16_t profileNum, uint32_t tagN * @param[in] tagNum The context-specific tag number assigned to the tag. * @return A 64-bit integer representing the tag. */ -inline uint64_t ContextTag(uint8_t tagNum) { return kSpecialTagMarker | tagNum; } +inline uint64_t ContextTag(uint8_t tagNum) +{ + return kSpecialTagMarker | tagNum; +} /** * Generates the API representation of a common profile TLV tag @@ -106,7 +114,10 @@ inline uint64_t ContextTag(uint8_t tagNum) { return kSpecialTagMarker | tagNum; * @param[in] tagNum The common profile tag number assigned to the tag. * @return A 64-bit integer representing the tag. */ -inline uint64_t CommonTag(uint32_t tagNum) { return ProfileTag(kCommonProfileId, tagNum); } +inline uint64_t CommonTag(uint32_t tagNum) +{ + return ProfileTag(kCommonProfileId, tagNum); +} enum { @@ -119,7 +130,6 @@ enum UnknownImplicitTag = kSpecialTagMarker | 0x00000000FFFFFFFEULL }; - /** * Returns the profile id from a TLV tag * @@ -128,8 +138,10 @@ enum * @param[in] tag The API representation of a profile-specific TLV tag. * @return The profile id. */ -inline uint32_t ProfileIdFromTag(uint64_t tag) { return (uint32_t)((tag & kProfileIdMask) >> kProfileIdShift); } - +inline uint32_t ProfileIdFromTag(uint64_t tag) +{ + return (uint32_t)((tag & kProfileIdMask) >> kProfileIdShift); +} /** * Returns the profile number from a TLV tag @@ -139,8 +151,10 @@ inline uint32_t ProfileIdFromTag(uint64_t tag) { return (uint32_t)((tag & kProfi * @param[in] tag The API representation of a profile-specific TLV tag. * @return The associated profile number. */ -inline uint16_t ProfileNumFromTag(uint64_t tag) { return (uint16_t) ((tag & kProfileIdMask) >> kProfileIdShift); } - +inline uint16_t ProfileNumFromTag(uint64_t tag) +{ + return (uint16_t)((tag & kProfileIdMask) >> kProfileIdShift); +} /** * Returns the tag number from a TLV tag @@ -153,8 +167,10 @@ inline uint16_t ProfileNumFromTag(uint64_t tag) { return (uint16_t) ((tag & kPro * @param[in] tag The API representation of a profile-specific or context-specific TLV tag. * @return The associated tag number. */ -inline uint32_t TagNumFromTag(uint64_t tag) { return (uint32_t)(tag & kTagNumMask); } - +inline uint32_t TagNumFromTag(uint64_t tag) +{ + return (uint32_t)(tag & kTagNumMask); +} /** * Returns the vendor id from a TLV tag @@ -164,23 +180,32 @@ inline uint32_t TagNumFromTag(uint64_t tag) { return (uint32_t)(tag & kTagNumMas * @param[in] tag The API representation of a profile-specific TLV tag. * @return The associated vendor id. */ -inline uint16_t VendorIdFromTag(uint64_t tag) { return (uint16_t)((tag & kProfileIdMask) >> kVendorIdShift); } - +inline uint16_t VendorIdFromTag(uint64_t tag) +{ + return (uint16_t)((tag & kProfileIdMask) >> kVendorIdShift); +} /** * Returns true of the supplied tag is a profile-specific tag. */ -inline bool IsProfileTag(uint64_t tag) { return (tag & kProfileIdMask) != kSpecialTagMarker; } - +inline bool IsProfileTag(uint64_t tag) +{ + return (tag & kProfileIdMask) != kSpecialTagMarker; +} /** * Returns true if the supplied tag is a context-specific tag. */ -inline bool IsContextTag(uint64_t tag) { return (tag & kProfileIdMask) == kSpecialTagMarker && TagNumFromTag(tag) < kContextTagMaxNum; } - +inline bool IsContextTag(uint64_t tag) +{ + return (tag & kProfileIdMask) == kSpecialTagMarker && TagNumFromTag(tag) < kContextTagMaxNum; +} // TODO: move to private namespace -inline bool IsSpecialTag(uint64_t tag) { return (tag & kProfileIdMask) == kSpecialTagMarker; } +inline bool IsSpecialTag(uint64_t tag) +{ + return (tag & kProfileIdMask) == kSpecialTagMarker; +} } // namespace TLV } // namespace chip diff --git a/src/lib/core/CHIPTLVTypes.h b/src/lib/core/CHIPTLVTypes.h index 6ac7ee88664640..1330553b00a331 100644 --- a/src/lib/core/CHIPTLVTypes.h +++ b/src/lib/core/CHIPTLVTypes.h @@ -33,67 +33,67 @@ namespace TLV { */ enum TLVType { - kTLVType_NotSpecified = -1, - kTLVType_UnknownContainer = -2, - - kTLVType_SignedInteger = 0x00, - kTLVType_UnsignedInteger = 0x04, - kTLVType_Boolean = 0x08, - kTLVType_FloatingPointNumber = 0x0A, - kTLVType_UTF8String = 0x0C, - kTLVType_ByteString = 0x10, - kTLVType_Null = 0x14, - kTLVType_Structure = 0x15, - kTLVType_Array = 0x16, - kTLVType_Path = 0x17 + kTLVType_NotSpecified = -1, + kTLVType_UnknownContainer = -2, + + kTLVType_SignedInteger = 0x00, + kTLVType_UnsignedInteger = 0x04, + kTLVType_Boolean = 0x08, + kTLVType_FloatingPointNumber = 0x0A, + kTLVType_UTF8String = 0x0C, + kTLVType_ByteString = 0x10, + kTLVType_Null = 0x14, + kTLVType_Structure = 0x15, + kTLVType_Array = 0x16, + kTLVType_Path = 0x17 }; // TODO: Move to private namespace enum TLVElementType { - kTLVElementType_NotSpecified = -1, - kTLVElementType_Int8 = 0x00, - kTLVElementType_Int16 = 0x01, - kTLVElementType_Int32 = 0x02, - kTLVElementType_Int64 = 0x03, - kTLVElementType_UInt8 = 0x04, - kTLVElementType_UInt16 = 0x05, - kTLVElementType_UInt32 = 0x06, - kTLVElementType_UInt64 = 0x07, - kTLVElementType_BooleanFalse = 0x08, - kTLVElementType_BooleanTrue = 0x09, - kTLVElementType_FloatingPointNumber32 = 0x0A, - kTLVElementType_FloatingPointNumber64 = 0x0B, - kTLVElementType_UTF8String_1ByteLength = 0x0C, - kTLVElementType_UTF8String_2ByteLength = 0x0D, - kTLVElementType_UTF8String_4ByteLength = 0x0E, - kTLVElementType_UTF8String_8ByteLength = 0x0F, - kTLVElementType_ByteString_1ByteLength = 0x10, - kTLVElementType_ByteString_2ByteLength = 0x11, - kTLVElementType_ByteString_4ByteLength = 0x12, - kTLVElementType_ByteString_8ByteLength = 0x13, - kTLVElementType_Null = 0x14, - kTLVElementType_Structure = 0x15, - kTLVElementType_Array = 0x16, - kTLVElementType_Path = 0x17, - kTLVElementType_EndOfContainer = 0x18 + kTLVElementType_NotSpecified = -1, + kTLVElementType_Int8 = 0x00, + kTLVElementType_Int16 = 0x01, + kTLVElementType_Int32 = 0x02, + kTLVElementType_Int64 = 0x03, + kTLVElementType_UInt8 = 0x04, + kTLVElementType_UInt16 = 0x05, + kTLVElementType_UInt32 = 0x06, + kTLVElementType_UInt64 = 0x07, + kTLVElementType_BooleanFalse = 0x08, + kTLVElementType_BooleanTrue = 0x09, + kTLVElementType_FloatingPointNumber32 = 0x0A, + kTLVElementType_FloatingPointNumber64 = 0x0B, + kTLVElementType_UTF8String_1ByteLength = 0x0C, + kTLVElementType_UTF8String_2ByteLength = 0x0D, + kTLVElementType_UTF8String_4ByteLength = 0x0E, + kTLVElementType_UTF8String_8ByteLength = 0x0F, + kTLVElementType_ByteString_1ByteLength = 0x10, + kTLVElementType_ByteString_2ByteLength = 0x11, + kTLVElementType_ByteString_4ByteLength = 0x12, + kTLVElementType_ByteString_8ByteLength = 0x13, + kTLVElementType_Null = 0x14, + kTLVElementType_Structure = 0x15, + kTLVElementType_Array = 0x16, + kTLVElementType_Path = 0x17, + kTLVElementType_EndOfContainer = 0x18 }; // TODO: Move to private namespace enum TLVFieldSize { - kTLVFieldSize_0Byte = -1, - kTLVFieldSize_1Byte = 0, - kTLVFieldSize_2Byte = 1, - kTLVFieldSize_4Byte = 2, - kTLVFieldSize_8Byte = 3 + kTLVFieldSize_0Byte = -1, + kTLVFieldSize_1Byte = 0, + kTLVFieldSize_2Byte = 1, + kTLVFieldSize_4Byte = 2, + kTLVFieldSize_8Byte = 3 }; // TODO: Move to private namespace enum { - kTLVTypeMask = 0x1F, - kTLVTypeSizeMask = 0x03 + kTLVTypeMask = 0x1F, + kTLVTypeSizeMask = 0x03 }; /** @@ -165,5 +165,4 @@ inline uint8_t TLVFieldSizeToBytes(TLVFieldSize fieldSize) } // namespace TLV } // namespace chip - #endif /* CHIPTLVTYPES_H_ */ diff --git a/src/lib/core/CHIPTLVUtilities.hpp b/src/lib/core/CHIPTLVUtilities.hpp index 9455efaacee161..3d39e893390ba2 100644 --- a/src/lib/core/CHIPTLVUtilities.hpp +++ b/src/lib/core/CHIPTLVUtilities.hpp @@ -46,19 +46,20 @@ namespace TLV { */ namespace Utilities { -typedef CHIP_ERROR (*IterateHandler)(const TLVReader &aReader, size_t aDepth, void *aContext); +typedef CHIP_ERROR (*IterateHandler)(const TLVReader & aReader, size_t aDepth, void * aContext); -extern CHIP_ERROR Iterate(const TLVReader &aReader, IterateHandler aHandler, void *aContext); -extern CHIP_ERROR Iterate(const TLVReader &aReader, IterateHandler aHandler, void *aContext, const bool aRecurse); +extern CHIP_ERROR Iterate(const TLVReader & aReader, IterateHandler aHandler, void * aContext); +extern CHIP_ERROR Iterate(const TLVReader & aReader, IterateHandler aHandler, void * aContext, const bool aRecurse); -extern CHIP_ERROR Count(const TLVReader &aReader, size_t &aCount); -extern CHIP_ERROR Count(const TLVReader &aReader, size_t &aCount, const bool aRecurse); +extern CHIP_ERROR Count(const TLVReader & aReader, size_t & aCount); +extern CHIP_ERROR Count(const TLVReader & aReader, size_t & aCount, const bool aRecurse); -extern CHIP_ERROR Find(const TLVReader &aReader, const uint64_t &aTag, TLVReader &aResult); -extern CHIP_ERROR Find(const TLVReader &aReader, const uint64_t &aTag, TLVReader &aResult, const bool aRecurse); +extern CHIP_ERROR Find(const TLVReader & aReader, const uint64_t & aTag, TLVReader & aResult); +extern CHIP_ERROR Find(const TLVReader & aReader, const uint64_t & aTag, TLVReader & aResult, const bool aRecurse); -extern CHIP_ERROR Find(const TLVReader &aReader, IterateHandler aHandler, void *aContext, TLVReader &aResult); -extern CHIP_ERROR Find(const TLVReader &aReader, IterateHandler aHandler, void *aContext, TLVReader &aResult, const bool aRecurse); +extern CHIP_ERROR Find(const TLVReader & aReader, IterateHandler aHandler, void * aContext, TLVReader & aResult); +extern CHIP_ERROR Find(const TLVReader & aReader, IterateHandler aHandler, void * aContext, TLVReader & aResult, + const bool aRecurse); } // namespace Utilities } // namespace TLV diff --git a/src/lib/core/CHIPTimeConfig.h b/src/lib/core/CHIPTimeConfig.h index dd87bada0f6e59..f554ef3ef71994 100644 --- a/src/lib/core/CHIPTimeConfig.h +++ b/src/lib/core/CHIPTimeConfig.h @@ -175,7 +175,7 @@ * */ #ifndef CHIP_CONFIG_TIME_CLIENT_TIMER_MULTICAST_MSEC -#define CHIP_CONFIG_TIME_CLIENT_TIMER_MULTICAST_MSEC (2*1000) +#define CHIP_CONFIG_TIME_CLIENT_TIMER_MULTICAST_MSEC (2 * 1000) #endif // CHIP_CONFIG_TIME_CLIENT_TIMER_MULTICAST_MSEC /** @@ -189,7 +189,7 @@ * */ #ifndef CHIP_CONFIG_TIME_CLIENT_TIMER_UNICAST_MSEC -#define CHIP_CONFIG_TIME_CLIENT_TIMER_UNICAST_MSEC (2*1000) +#define CHIP_CONFIG_TIME_CLIENT_TIMER_UNICAST_MSEC (2 * 1000) #endif // CHIP_CONFIG_TIME_CLIENT_TIMER_UNICAST_MSEC /** @@ -204,7 +204,7 @@ * */ #ifndef CHIP_CONFIG_TIME_CLIENT_TIMER_CLOUD_SERVICE_MSEC -#define CHIP_CONFIG_TIME_CLIENT_TIMER_CLOUD_SERVICE_MSEC (5*1000) +#define CHIP_CONFIG_TIME_CLIENT_TIMER_CLOUD_SERVICE_MSEC (5 * 1000) #endif // CHIP_CONFIG_TIME_CLIENT_TIMER_CLOUD_SERVICE_MSEC /** @@ -218,7 +218,7 @@ * */ #ifndef CHIP_CONFIG_TIME_CLIENT_MAX_RTT_USEC -#define CHIP_CONFIG_TIME_CLIENT_MAX_RTT_USEC (10*1000000LL) +#define CHIP_CONFIG_TIME_CLIENT_MAX_RTT_USEC (10 * 1000000LL) #endif // CHIP_CONFIG_TIME_CLIENT_MAX_RTT_USEC /** @@ -273,7 +273,7 @@ * */ #ifndef CHIP_CONFIG_TIME_CLIENT_MIN_OFFSET_FROM_SERVER_USEC -#define CHIP_CONFIG_TIME_CLIENT_MIN_OFFSET_FROM_SERVER_USEC (2*1000000LL) +#define CHIP_CONFIG_TIME_CLIENT_MIN_OFFSET_FROM_SERVER_USEC (2 * 1000000LL) #endif // CHIP_CONFIG_TIME_CLIENT_MIN_OFFSET_FROM_SERVER_USEC /** @@ -302,7 +302,7 @@ * Default is 2 seconds. */ #ifndef CHIP_CONFIG_TIME_COORDINATOR_THRESHOLD_TO_SEND_NOTIFICATION_USEC -#define CHIP_CONFIG_TIME_COORDINATOR_THRESHOLD_TO_SEND_NOTIFICATION_USEC (2*1000000LL) +#define CHIP_CONFIG_TIME_COORDINATOR_THRESHOLD_TO_SEND_NOTIFICATION_USEC (2 * 1000000LL) #endif // CHIP_CONFIG_TIME_COORDINATOR_THRESHOLD_TO_SEND_NOTIFICATION_USEC #endif /* CHIP_TIME_CONFIG_H_ */ diff --git a/src/lib/core/CHIPVendorIdentifiers.hpp b/src/lib/core/CHIPVendorIdentifiers.hpp index 5a174c95bc9dcc..b3259e3a879168 100644 --- a/src/lib/core/CHIPVendorIdentifiers.hpp +++ b/src/lib/core/CHIPVendorIdentifiers.hpp @@ -35,8 +35,8 @@ namespace chip { enum ChipVendorId { - kChipVendor_Common = 0x0000, - kChipVendor_NotSpecified = 0xFFFF + kChipVendor_Common = 0x0000, + kChipVendor_NotSpecified = 0xFFFF }; }; // namespace chip diff --git a/src/lwip/efr32/arch/cc.h b/src/lwip/efr32/arch/cc.h index 38f88a6ecc6ac9..959f8b82c4853d 100644 --- a/src/lwip/efr32/arch/cc.h +++ b/src/lwip/efr32/arch/cc.h @@ -44,11 +44,11 @@ extern "C" { #define PACK_STRUCT_STRUCT __attribute__((__packed__)) #define PACK_STRUCT_FIELD(x) x -extern void LwIPLog(const char *fmt, ...); -#define LWIP_PLATFORM_DIAG(x) \ - do \ - { \ - LwIPLog x; \ +extern void LwIPLog(const char * fmt, ...); +#define LWIP_PLATFORM_DIAG(x) \ + do \ + { \ + LwIPLog x; \ } while (0) // Place LwIP pools into their own subsections of .bss to make it easier to see diff --git a/src/lwip/efr32/lwipopts.h b/src/lwip/efr32/lwipopts.h index 1aaa45c9b8a3b8..60e3c10c92118b 100644 --- a/src/lwip/efr32/lwipopts.h +++ b/src/lwip/efr32/lwipopts.h @@ -2,7 +2,7 @@ * * Copyright (c) 2020 Project CHIP Authors * Copyright (c) 2019 Nest Labs, Inc. - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -176,7 +176,7 @@ #define TCP_RST_DEBUG (LWIP_DBG_OFF) #define PPP_DEBUG (LWIP_DBG_OFF) -#define LWIP_DBG_TYPES_ON \ +#define LWIP_DBG_TYPES_ON \ (LWIP_DBG_ON | LWIP_DBG_TRACE) /* (LWIP_DBG_ON|LWIP_DBG_TRACE|LWIP_DBG_STATE|LWIP_DBG_FRESH|LWIP_DBG_HALT) */ #endif /* __LWIPOPTS_H__ */ diff --git a/src/lwip/freertos/arch/sys_arch.h b/src/lwip/freertos/arch/sys_arch.h index ba59613a68efd8..36fba6b19eec59 100644 --- a/src/lwip/freertos/arch/sys_arch.h +++ b/src/lwip/freertos/arch/sys_arch.h @@ -29,11 +29,11 @@ #include "semphr.h" #include "task.h" -#define SYS_MBOX_NULL ((xQueueHandle ) NULL) -#define SYS_SEM_NULL ((xSemaphoreHandle ) NULL) +#define SYS_MBOX_NULL ((xQueueHandle) NULL) +#define SYS_SEM_NULL ((xSemaphoreHandle) NULL) #define SYS_DEFAULT_THREAD_STACK_DEPTH configMINIMAL_STACK_SIZE -#define SYS_MESG_QUEUE_LENGTH ( (UBaseType_t) 6 ) -#define SYS_POST_BLOCK_TIME_MS 10000 +#define SYS_MESG_QUEUE_LENGTH ((UBaseType_t) 6) +#define SYS_POST_BLOCK_TIME_MS 10000 typedef QueueHandle_t sys_mbox_t; typedef xSemaphoreHandle sys_mutex_t; @@ -46,15 +46,35 @@ typedef UBaseType_t sys_prot_t; #include "lwip/sys.h" #define sys_sem_valid(sem) (((sem) != NULL) && (*(sem) != NULL)) -#define sys_sem_set_invalid(sem) do { if ((sem) != NULL) { *(sem) = NULL; } } while(0) +#define sys_sem_set_invalid(sem) \ + do \ + { \ + if ((sem) != NULL) \ + { \ + *(sem) = NULL; \ + } \ + } while (0) #define sys_mutex_valid(mutex) (((mutex) != NULL) && (*(mutex) != NULL)) -#define sys_mutex_set_invalid(mutex) do { if ((mutex) != NULL) { *(mutex) = NULL; } } while(0) +#define sys_mutex_set_invalid(mutex) \ + do \ + { \ + if ((mutex) != NULL) \ + { \ + *(mutex) = NULL; \ + } \ + } while (0) #define sys_mbox_valid(mbox) (((mbox) != NULL) && (*(mbox) != NULL)) -#define sys_mbox_set_invalid(mbox) do { if ((mbox) != NULL) { *(mbox) = NULL; } } while(0) +#define sys_mbox_set_invalid(mbox) \ + do \ + { \ + if ((mbox) != NULL) \ + { \ + *(mbox) = NULL; \ + } \ + } while (0) #define sys_profile_interval_set_pbuf_highwatermark(...) - #endif /* CHIP_LWIP_FREERTOS_ARCH_SYS_ARCH_H */ diff --git a/src/lwip/freertos/sys_arch.c b/src/lwip/freertos/sys_arch.c index 224e893819dd2f..1a987968dff56a 100644 --- a/src/lwip/freertos/sys_arch.c +++ b/src/lwip/freertos/sys_arch.c @@ -53,7 +53,7 @@ static portSTACK_TYPE gTCPIPTaskStack[TCPIP_THREAD_STACKSIZE]; #if LWIP_FREERTOS_USE_STATIC_TCPIP_QUEUE static StaticQueue_t gTCPIPMsgQueue; -static uint8_t gTCPIPMsgQueueStorage[SYS_MESG_QUEUE_LENGTH * sizeof(void*)]; +static uint8_t gTCPIPMsgQueueStorage[SYS_MESG_QUEUE_LENGTH * sizeof(void *)]; #endif static inline u32_t TicksToMS(TickType_t ticks) @@ -66,7 +66,7 @@ void sys_init(void) // nothing to do. } -err_t sys_sem_new(sys_sem_t *sem, u8_t count) +err_t sys_sem_new(sys_sem_t * sem, u8_t count) { *sem = xSemaphoreCreateBinary(); if (*sem != NULL) @@ -85,18 +85,18 @@ err_t sys_sem_new(sys_sem_t *sem, u8_t count) } } -void sys_sem_free(sys_sem_t *sem) +void sys_sem_free(sys_sem_t * sem) { vSemaphoreDelete(*sem); SYS_STATS_DEC(sem); } -void sys_sem_signal(sys_sem_t *sem) +void sys_sem_signal(sys_sem_t * sem) { xSemaphoreGive(*sem); } -u32_t sys_arch_sem_wait(sys_sem_t *sem, u32_t timeout) +u32_t sys_arch_sem_wait(sys_sem_t * sem, u32_t timeout) { TickType_t timeoutTicks, startTime; BaseType_t res; @@ -124,7 +124,7 @@ u32_t sys_arch_sem_wait(sys_sem_t *sem, u32_t timeout) return SYS_ARCH_TIMEOUT; } -err_t sys_mutex_new(sys_mutex_t *mutex) +err_t sys_mutex_new(sys_mutex_t * mutex) { *mutex = xSemaphoreCreateMutex(); if (*mutex != NULL) @@ -140,23 +140,23 @@ err_t sys_mutex_new(sys_mutex_t *mutex) } } -void sys_mutex_free(sys_mutex_t *mutex) +void sys_mutex_free(sys_mutex_t * mutex) { vSemaphoreDelete(*mutex); SYS_STATS_DEC(mutex); } -void sys_mutex_lock(sys_mutex_t *mutex) +void sys_mutex_lock(sys_mutex_t * mutex) { xSemaphoreTake(*mutex, portMAX_DELAY); } -void sys_mutex_unlock(sys_mutex_t *mutex) +void sys_mutex_unlock(sys_mutex_t * mutex) { xSemaphoreGive(*mutex); } -err_t sys_mbox_new(sys_mbox_t *mbox, int size) +err_t sys_mbox_new(sys_mbox_t * mbox, int size) { if (size != SYS_MESG_QUEUE_LENGTH) { @@ -165,9 +165,9 @@ err_t sys_mbox_new(sys_mbox_t *mbox, int size) } #if LWIP_FREERTOS_USE_STATIC_TCPIP_QUEUE - *mbox = xQueueCreateStatic((UBaseType_t)size, (UBaseType_t) sizeof(void *), gTCPIPMsgQueueStorage, &gTCPIPMsgQueue); + *mbox = xQueueCreateStatic((UBaseType_t) size, (UBaseType_t) sizeof(void *), gTCPIPMsgQueueStorage, &gTCPIPMsgQueue); #else - *mbox = xQueueCreate((UBaseType_t)size, (UBaseType_t) sizeof(void *)); + *mbox = xQueueCreate((UBaseType_t) size, (UBaseType_t) sizeof(void *)); #endif if (*mbox != NULL) { @@ -181,23 +181,23 @@ err_t sys_mbox_new(sys_mbox_t *mbox, int size) } } -void sys_mbox_free(sys_mbox_t *mbox) +void sys_mbox_free(sys_mbox_t * mbox) { vQueueDelete(*mbox); } -void sys_mbox_post(sys_mbox_t *mbox, void *msg) +void sys_mbox_post(sys_mbox_t * mbox, void * msg) { BaseType_t res; res = xQueueSendToBack(*mbox, &msg, pdMS_TO_TICKS(SYS_POST_BLOCK_TIME_MS)); LWIP_ASSERT("Error posting to LwIP mbox", res == pdTRUE); } -u32_t sys_arch_mbox_fetch(sys_mbox_t *mbox, void **msg, u32_t timeout) +u32_t sys_arch_mbox_fetch(sys_mbox_t * mbox, void ** msg, u32_t timeout) { TickType_t timeoutTicks, startTime; BaseType_t res; - void *dummy; + void * dummy; if (msg == NULL) msg = &dummy; @@ -211,7 +211,7 @@ u32_t sys_arch_mbox_fetch(sys_mbox_t *mbox, void **msg, u32_t timeout) do { - res = xQueueReceive(*mbox, (void *)msg, timeoutTicks); + res = xQueueReceive(*mbox, (void *) msg, timeoutTicks); } while (res != pdTRUE && timeout == 0); if (res == pdTRUE) @@ -228,20 +228,20 @@ u32_t sys_arch_mbox_fetch(sys_mbox_t *mbox, void **msg, u32_t timeout) } } -u32_t sys_arch_mbox_tryfetch(sys_mbox_t *mbox, void **msg) +u32_t sys_arch_mbox_tryfetch(sys_mbox_t * mbox, void ** msg) { BaseType_t res; - void *dummy; + void * dummy; if (msg == NULL) msg = &dummy; - res = xQueueReceive(*mbox, (void *)msg, 0); + res = xQueueReceive(*mbox, (void *) msg, 0); return (res == pdTRUE) ? 0 : SYS_MBOX_EMPTY; } -err_t sys_mbox_trypost(sys_mbox_t *mbox, void *msg) +err_t sys_mbox_trypost(sys_mbox_t * mbox, void * msg) { BaseType_t res; @@ -256,18 +256,18 @@ err_t sys_mbox_trypost(sys_mbox_t *mbox, void *msg) } } -sys_thread_t sys_thread_new(const char *name, lwip_thread_fn thread, void *arg, int stacksize, int prio) +sys_thread_t sys_thread_new(const char * name, lwip_thread_fn thread, void * arg, int stacksize, int prio) { TaskHandle_t taskH; - const unsigned short stacksizeWords = (unsigned short)(stacksize / sizeof(StackType_t)); + const unsigned short stacksizeWords = (unsigned short) (stacksize / sizeof(StackType_t)); if (strcmp(name, TCPIP_THREAD_NAME) != 0 || stacksize != TCPIP_THREAD_STACKSIZE) return NULL; #if LWIP_FREERTOS_USE_STATIC_TCPIP_TASK - taskH = xTaskCreateStatic(thread, name, stacksizeWords, arg, (UBaseType_t)prio, (StackType_t *)gTCPIPTaskStack, NULL); -#else // LWIP_FREERTOS_USE_STATIC_TCPIP_TASK - if (xTaskCreate(thread, name, stacksizeWords, arg, (UBaseType_t)prio, &taskH) != pdPASS) + taskH = xTaskCreateStatic(thread, name, stacksizeWords, arg, (UBaseType_t) prio, (StackType_t *) gTCPIPTaskStack, NULL); +#else // LWIP_FREERTOS_USE_STATIC_TCPIP_TASK + if (xTaskCreate(thread, name, stacksizeWords, arg, (UBaseType_t) prio, &taskH) != pdPASS) taskH = NULL; #endif // LWIP_FREERTOS_USE_STATIC_TCPIP_TASK @@ -288,4 +288,3 @@ void sys_arch_unprotect(sys_prot_t pval) { taskEXIT_CRITICAL_FROM_ISR(pval); } - diff --git a/src/lwip/nrf5/arch/cc.h b/src/lwip/nrf5/arch/cc.h index dec2d7d0c209bb..1cebdf30e705f4 100644 --- a/src/lwip/nrf5/arch/cc.h +++ b/src/lwip/nrf5/arch/cc.h @@ -62,11 +62,15 @@ extern "C" { #endif #endif // BYTE_ORDER -#define PACK_STRUCT_STRUCT __attribute__ ((__packed__)) +#define PACK_STRUCT_STRUCT __attribute__((__packed__)) #define PACK_STRUCT_FIELD(x) x -extern void LwIPLog(const char *fmt, ...); -#define LWIP_PLATFORM_DIAG(x) do { LwIPLog x; } while (0) +extern void LwIPLog(const char * fmt, ...); +#define LWIP_PLATFORM_DIAG(x) \ + do \ + { \ + LwIPLog x; \ + } while (0) // Place LwIP pools into their own subsections of .bss to make it easier to see // their sizes in the linker map file. diff --git a/src/lwip/nrf5/lwipopts.h b/src/lwip/nrf5/lwipopts.h index e6314efeb35d31..2f3f466d6ba5ea 100644 --- a/src/lwip/nrf5/lwipopts.h +++ b/src/lwip/nrf5/lwipopts.h @@ -23,146 +23,145 @@ * */ - #ifndef __LWIPOPTS_H__ #define __LWIPOPTS_H__ #include -#define NO_SYS 0 -#define MEM_ALIGNMENT (4) -#define MEMP_NUM_TCP_SEG (TCP_SND_QUEUELEN+1) -#define LWIP_TIMEVAL_PRIVATE (0) -#define MEM_LIBC_MALLOC (0) -#define LWIP_COMPAT_MUTEX (0) -#define SYS_LIGHTWEIGHT_PROT (1) -#define LWIP_AUTOIP (0) -#define LWIP_DHCP_AUTOIP_COOP (0) -#define LWIP_SOCKET_SET_ERRNO 0 -#define IP_REASS_MAX_PBUFS 0 -#define IP_REASSEMBLY 0 -#define MEMP_NUM_REASSDATA 0 -#define LWIP_SO_RCVTIMEO 0 -#define SO_REUSE (1) +#define NO_SYS 0 +#define MEM_ALIGNMENT (4) +#define MEMP_NUM_TCP_SEG (TCP_SND_QUEUELEN + 1) +#define LWIP_TIMEVAL_PRIVATE (0) +#define MEM_LIBC_MALLOC (0) +#define LWIP_COMPAT_MUTEX (0) +#define SYS_LIGHTWEIGHT_PROT (1) +#define LWIP_AUTOIP (0) +#define LWIP_DHCP_AUTOIP_COOP (0) +#define LWIP_SOCKET_SET_ERRNO 0 +#define IP_REASS_MAX_PBUFS 0 +#define IP_REASSEMBLY 0 +#define MEMP_NUM_REASSDATA 0 +#define LWIP_SO_RCVTIMEO 0 +#define SO_REUSE (1) #define LWIP_RANDOMIZE_INITIAL_LOCAL_PORTS (1) -#define LWIP_STATS (0) -#define LWIP_TCPIP_CORE_LOCKING 1 -#define TCP_QUEUE_OOSEQ 0 -#define ARP_QUEUEING (0) -#define TCPIP_THREAD_NAME "LWIP" +#define LWIP_STATS (0) +#define LWIP_TCPIP_CORE_LOCKING 1 +#define TCP_QUEUE_OOSEQ 0 +#define ARP_QUEUEING (0) +#define TCPIP_THREAD_NAME "LWIP" -#define LWIP_SOCKET 0 +#define LWIP_SOCKET 0 // TODO: seems like this is unnecessary on Thread-only platforms -#define LWIP_RAW 1 -#define MEMP_NUM_RAW_PCB (5) +#define LWIP_RAW 1 +#define MEMP_NUM_RAW_PCB (5) // TODO: verify count -#define MEMP_NUM_UDP_PCB (7) +#define MEMP_NUM_UDP_PCB (7) -#define LWIP_HAVE_LOOPIF (0) +#define LWIP_HAVE_LOOPIF (0) // TODO: not sure why this is disabled -#define LWIP_NETIF_LOOPBACK (0) - -#define MEMP_NUM_NETCONN (0) - -#define LWIP_IPV4 0 -#define LWIP_IPV6 1 -#define LWIP_ARP (0) -#define LWIP_DNS (0) -#define LWIP_ICMP (0) -#define LWIP_IGMP (0) -#define LWIP_DHCP (0) -#define LWIP_IPV6_REASS (0) -#define LWIP_IPV6_DHCP6 0 -#define LWIP_IPV6_AUTOCONFIG (0) -#define LWIP_IPV6_ROUTER_SUPPORT 0 -#define LWIP_ND6_LISTEN_RA 0 - -#define LWIP_ND6_NUM_NEIGHBORS (0) -#define LWIP_ND6_NUM_DESTINATIONS (0) -#define LWIP_ND6_NUM_PREFIXES (0) -#define LWIP_ND6_NUM_ROUTERS (0) -#define LWIP_ND6_MAX_MULTICAST_SOLICIT (0) -#define LWIP_ND6_MAX_UNICAST_SOLICIT (0) +#define LWIP_NETIF_LOOPBACK (0) + +#define MEMP_NUM_NETCONN (0) + +#define LWIP_IPV4 0 +#define LWIP_IPV6 1 +#define LWIP_ARP (0) +#define LWIP_DNS (0) +#define LWIP_ICMP (0) +#define LWIP_IGMP (0) +#define LWIP_DHCP (0) +#define LWIP_IPV6_REASS (0) +#define LWIP_IPV6_DHCP6 0 +#define LWIP_IPV6_AUTOCONFIG (0) +#define LWIP_IPV6_ROUTER_SUPPORT 0 +#define LWIP_ND6_LISTEN_RA 0 + +#define LWIP_ND6_NUM_NEIGHBORS (0) +#define LWIP_ND6_NUM_DESTINATIONS (0) +#define LWIP_ND6_NUM_PREFIXES (0) +#define LWIP_ND6_NUM_ROUTERS (0) +#define LWIP_ND6_MAX_MULTICAST_SOLICIT (0) +#define LWIP_ND6_MAX_UNICAST_SOLICIT (0) #define LWIP_ND6_MAX_NEIGHBOR_ADVERTISEMENT (0) -#define LWIP_ND6_TCP_REACHABILITY_HINTS (0) - -#define MEMP_SEPARATE_POOLS (1) -#define LWIP_PBUF_FROM_CUSTOM_POOLS (0) -#define MEMP_USE_CUSTOM_POOLS (0) -#define PBUF_POOL_SIZE (8) -#define PBUF_POOL_BUFSIZE (1500) -#define PBUF_POOL_SIZE_LARGE (3) -#define PBUF_POOL_SIZE_MEDIUM (4) -#define PBUF_POOL_SIZE_SMALL (5) -#define PBUF_POOL_BUFSIZE_LARGE (1280) -#define PBUF_POOL_BUFSIZE_MEDIUM (640) -#define PBUF_POOL_BUFSIZE_SMALL (256) -#define PBUF_CUSTOM_POOL_IDX_START (MEMP_PBUF_POOL_SMALL) -#define PBUF_CUSTOM_POOL_IDX_END (MEMP_PBUF_POOL_LARGE) +#define LWIP_ND6_TCP_REACHABILITY_HINTS (0) -#define TCP_MSS (1152) -#define TCP_SND_BUF (2 * TCP_MSS) -#define TCP_LISTEN_BACKLOG (1) +#define MEMP_SEPARATE_POOLS (1) +#define LWIP_PBUF_FROM_CUSTOM_POOLS (0) +#define MEMP_USE_CUSTOM_POOLS (0) +#define PBUF_POOL_SIZE (8) +#define PBUF_POOL_BUFSIZE (1500) +#define PBUF_POOL_SIZE_LARGE (3) +#define PBUF_POOL_SIZE_MEDIUM (4) +#define PBUF_POOL_SIZE_SMALL (5) +#define PBUF_POOL_BUFSIZE_LARGE (1280) +#define PBUF_POOL_BUFSIZE_MEDIUM (640) +#define PBUF_POOL_BUFSIZE_SMALL (256) +#define PBUF_CUSTOM_POOL_IDX_START (MEMP_PBUF_POOL_SMALL) +#define PBUF_CUSTOM_POOL_IDX_END (MEMP_PBUF_POOL_LARGE) -#define ETH_PAD_SIZE (0) -#define SUB_ETHERNET_HEADER_SPACE (0) -#define PBUF_LINK_HLEN (0) +#define TCP_MSS (1152) +#define TCP_SND_BUF (2 * TCP_MSS) +#define TCP_LISTEN_BACKLOG (1) -#define TCPIP_THREAD_STACKSIZE (4096) -#define TCPIP_THREAD_PRIO (2) +#define ETH_PAD_SIZE (0) +#define SUB_ETHERNET_HEADER_SPACE (0) +#define PBUF_LINK_HLEN (0) -#define NETIF_MAX_HWADDR_LEN 8U +#define TCPIP_THREAD_STACKSIZE (4096) +#define TCPIP_THREAD_PRIO (2) -#define LWIP_IPV6_NUM_ADDRESSES 5 +#define NETIF_MAX_HWADDR_LEN 8U -#define LWIP_IPV6_ND 0 -#define LWIP_ND6_QUEUEING 0 +#define LWIP_IPV6_NUM_ADDRESSES 5 -#define LWIP_MULTICAST_PING 0 +#define LWIP_IPV6_ND 0 +#define LWIP_ND6_QUEUEING 0 -#define TCPIP_MBOX_SIZE 6 -#define DEFAULT_RAW_RECVMBOX_SIZE 6 -#define DEFAULT_UDP_RECVMBOX_SIZE 6 -#define DEFAULT_TCP_RECVMBOX_SIZE 6 +#define LWIP_MULTICAST_PING 0 +#define TCPIP_MBOX_SIZE 6 +#define DEFAULT_RAW_RECVMBOX_SIZE 6 +#define DEFAULT_UDP_RECVMBOX_SIZE 6 +#define DEFAULT_TCP_RECVMBOX_SIZE 6 // TODO: make LWIP_DEBUG conditional on build type -#define LWIP_DEBUG 1 -#define MEMP_OVERFLOW_CHECK ( 0 ) -#define MEMP_SANITY_CHECK ( 0 ) -#define MEM_DEBUG (LWIP_DBG_OFF) -#define MEMP_DEBUG (LWIP_DBG_OFF) -#define PBUF_DEBUG (LWIP_DBG_OFF) -#define API_LIB_DEBUG (LWIP_DBG_OFF) -#define API_MSG_DEBUG (LWIP_DBG_OFF) -#define TCPIP_DEBUG (LWIP_DBG_OFF) -#define NETIF_DEBUG (LWIP_DBG_OFF) -#define SOCKETS_DEBUG (LWIP_DBG_OFF) -#define DEMO_DEBUG (LWIP_DBG_OFF) -#define DHCP_DEBUG (LWIP_DBG_OFF) -#define AUTOIP_DEBUG (LWIP_DBG_OFF) -#define ETHARP_DEBUG (LWIP_DBG_OFF) -#define IP_DEBUG (LWIP_DBG_OFF) -#define IP_REASS_DEBUG (LWIP_DBG_OFF) -#define IP6_DEBUG (LWIP_DBG_OFF) -#define RAW_DEBUG (LWIP_DBG_OFF) -#define ICMP_DEBUG (LWIP_DBG_OFF) -#define UDP_DEBUG (LWIP_DBG_OFF) -#define TCP_DEBUG (LWIP_DBG_OFF) -#define TCP_INPUT_DEBUG (LWIP_DBG_OFF) -#define TCP_OUTPUT_DEBUG (LWIP_DBG_OFF) -#define TCP_RTO_DEBUG (LWIP_DBG_OFF) -#define TCP_CWND_DEBUG (LWIP_DBG_OFF) -#define TCP_WND_DEBUG (LWIP_DBG_OFF) -#define TCP_FR_DEBUG (LWIP_DBG_OFF) -#define TCP_QLEN_DEBUG (LWIP_DBG_OFF) -#define TCP_RST_DEBUG (LWIP_DBG_OFF) -#define PPP_DEBUG (LWIP_DBG_OFF) - -#define LWIP_DBG_TYPES_ON (LWIP_DBG_ON | LWIP_DBG_TRACE) /* (LWIP_DBG_ON|LWIP_DBG_TRACE|LWIP_DBG_STATE|LWIP_DBG_FRESH|LWIP_DBG_HALT) */ +#define LWIP_DEBUG 1 +#define MEMP_OVERFLOW_CHECK (0) +#define MEMP_SANITY_CHECK (0) +#define MEM_DEBUG (LWIP_DBG_OFF) +#define MEMP_DEBUG (LWIP_DBG_OFF) +#define PBUF_DEBUG (LWIP_DBG_OFF) +#define API_LIB_DEBUG (LWIP_DBG_OFF) +#define API_MSG_DEBUG (LWIP_DBG_OFF) +#define TCPIP_DEBUG (LWIP_DBG_OFF) +#define NETIF_DEBUG (LWIP_DBG_OFF) +#define SOCKETS_DEBUG (LWIP_DBG_OFF) +#define DEMO_DEBUG (LWIP_DBG_OFF) +#define DHCP_DEBUG (LWIP_DBG_OFF) +#define AUTOIP_DEBUG (LWIP_DBG_OFF) +#define ETHARP_DEBUG (LWIP_DBG_OFF) +#define IP_DEBUG (LWIP_DBG_OFF) +#define IP_REASS_DEBUG (LWIP_DBG_OFF) +#define IP6_DEBUG (LWIP_DBG_OFF) +#define RAW_DEBUG (LWIP_DBG_OFF) +#define ICMP_DEBUG (LWIP_DBG_OFF) +#define UDP_DEBUG (LWIP_DBG_OFF) +#define TCP_DEBUG (LWIP_DBG_OFF) +#define TCP_INPUT_DEBUG (LWIP_DBG_OFF) +#define TCP_OUTPUT_DEBUG (LWIP_DBG_OFF) +#define TCP_RTO_DEBUG (LWIP_DBG_OFF) +#define TCP_CWND_DEBUG (LWIP_DBG_OFF) +#define TCP_WND_DEBUG (LWIP_DBG_OFF) +#define TCP_FR_DEBUG (LWIP_DBG_OFF) +#define TCP_QLEN_DEBUG (LWIP_DBG_OFF) +#define TCP_RST_DEBUG (LWIP_DBG_OFF) +#define PPP_DEBUG (LWIP_DBG_OFF) + +#define LWIP_DBG_TYPES_ON \ + (LWIP_DBG_ON | LWIP_DBG_TRACE) /* (LWIP_DBG_ON|LWIP_DBG_TRACE|LWIP_DBG_STATE|LWIP_DBG_FRESH|LWIP_DBG_HALT) */ #endif /* __LWIPOPTS_H__ */ diff --git a/src/lwip/standalone/TapInterface.c b/src/lwip/standalone/TapInterface.c index 6074933171cf64..85cdedb0f7fb2c 100644 --- a/src/lwip/standalone/TapInterface.c +++ b/src/lwip/standalone/TapInterface.c @@ -155,8 +155,7 @@ /* Global Variables */ -static const size_t kMacLength = sizeof (((TapInterface *)(0))->macAddr); - +static const size_t kMacLength = sizeof(((TapInterface *) (0))->macAddr); /** * This is the LwIP TUN/TAP shim interface low level output method. @@ -187,12 +186,11 @@ static const size_t kMacLength = sizeof (((TapInterface *)(0))->macAddr); * @sa #TapInterface_SetupNetif * */ -static err_t -TapInterface_low_level_output(struct netif *netif, struct pbuf *buf) +static err_t TapInterface_low_level_output(struct netif * netif, struct pbuf * buf) { - const TapInterface *tapif = (const TapInterface *)(netif->state); - err_t retval = ERR_OK; - struct pbuf *outBuf; + const TapInterface * tapif = (const TapInterface *) (netif->state); + err_t retval = ERR_OK; + struct pbuf * outBuf; int written; if (buf->tot_len > buf->len) @@ -265,27 +263,28 @@ TapInterface_low_level_output(struct netif *netif, struct pbuf *buf) * @sa #TapInterface_Select * */ -static struct pbuf * -TapInterface_low_level_input(TapInterface *tapif, struct netif *netif) +static struct pbuf * TapInterface_low_level_input(TapInterface * tapif, struct netif * netif) { struct pbuf *p, *q; u16_t len; char buf[2048]; - char *bufptr; + char * bufptr; /* Obtain the size of the packet and put it into the "len" variable. */ - len = read(tapif->fd, buf, sizeof (buf)); + len = read(tapif->fd, buf, sizeof(buf)); snmp_add_ifinoctets(netif, len); /* We allocate a pbuf chain of pbufs from the pool. */ p = pbuf_alloc(PBUF_LINK, len, PBUF_POOL); - if (p != NULL) { + if (p != NULL) + { /* We iterate over the pbuf chain until we have read the entire packet into the pbuf. */ bufptr = &buf[0]; - for(q = p; q != NULL; q = q->next) { + for (q = p; q != NULL; q = q->next) + { /* Read enough bytes to fill this pbuf in the chain. The available data in the pbuf is given by the q->len variable. */ @@ -294,7 +293,9 @@ TapInterface_low_level_input(TapInterface *tapif, struct netif *netif) bufptr += q->len; } /* acknowledge that packet has been read(); */ - } else { + } + else + { /* drop packet(); */ snmp_inc_ifindiscards(netif); printf("Could not allocate pbufs\n"); @@ -325,31 +326,30 @@ TapInterface_low_level_input(TapInterface *tapif, struct netif *netif) * @sa #TapInterface_Select * */ -err_t -TapInterface_SetupNetif(struct netif *netif) +err_t TapInterface_SetupNetif(struct netif * netif) { - const TapInterface *tapif = (const TapInterface *)(netif->state); + const TapInterface * tapif = (const TapInterface *) (netif->state); /* As far as LwIP is concerned, the network interface is an * Ethernet-like interface, so set it up accordingly, reusing * existing LwIP APIs for such interfaces where possible. */ - netif->name[0] = tapif->interfaceName[0]; - netif->name[1] = tapif->interfaceName[1]; - netif->output = etharp_output; + netif->name[0] = tapif->interfaceName[0]; + netif->name[1] = tapif->interfaceName[1]; + netif->output = etharp_output; #if LWIP_IPV6 netif->output_ip6 = ethip6_output; #endif /* LWIP_IPV6 */ netif->linkoutput = TapInterface_low_level_output; netif->mtu = 1500; - netif->flags |= (NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP); + netif->flags |= (NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP); #if LWIP_IPV4 - netif->flags |= (NETIF_FLAG_IGMP); + netif->flags |= (NETIF_FLAG_IGMP); #endif #if LWIP_IPV6 - netif->flags |= (NETIF_FLAG_MLD6); + netif->flags |= (NETIF_FLAG_MLD6); #endif netif->hwaddr_len = kMacLength; @@ -389,8 +389,7 @@ TapInterface_SetupNetif(struct netif *netif) * @sa #TapInterface_Select * */ -err_t -TapInterface_Init(TapInterface *tapif, const char *interfaceName, u8_t *macAddr) +err_t TapInterface_Init(TapInterface * tapif, const char * interfaceName, u8_t * macAddr) { #if defined(linux) struct ifreq ifr; @@ -406,7 +405,7 @@ TapInterface_Init(TapInterface *tapif, const char *interfaceName, u8_t *macAddr) /* Set the TUN/TAP interface storage to initial defaults. */ - memset(tapif, 0, sizeof (*tapif)); + memset(tapif, 0, sizeof(*tapif)); tapif->fd = -1; /* Intialize the TUN/TAP interface name and MAC address. If the @@ -422,9 +421,9 @@ TapInterface_Init(TapInterface *tapif, const char *interfaceName, u8_t *macAddr) } else { - const u32_t pid = htonl((u32_t)getpid()); + const u32_t pid = htonl((u32_t) getpid()); memset(tapif->macAddr, 0, kMacLength); - memcpy(tapif->macAddr + 2, &pid, sizeof (pid)); + memcpy(tapif->macAddr + 2, &pid, sizeof(pid)); } /* Attempt to open the OS-specific TUN/TAP driver control interface. @@ -443,10 +442,10 @@ TapInterface_Init(TapInterface *tapif, const char *interfaceName, u8_t *macAddr) * no packet information (IFF_NO_PI). */ - memset(&ifr, 0, sizeof (ifr)); + memset(&ifr, 0, sizeof(ifr)); ifr.ifr_flags = (IFF_TAP | IFF_NO_PI); - if (strlen(tapif->interfaceName) >= sizeof (ifr.ifr_name)) + if (strlen(tapif->interfaceName) >= sizeof(ifr.ifr_name)) { perror("TapInterface: invalid device name"); return ERR_ARG; @@ -454,7 +453,7 @@ TapInterface_Init(TapInterface *tapif, const char *interfaceName, u8_t *macAddr) strcpy(ifr.ifr_name, tapif->interfaceName); - if (ioctl(tapif->fd, TUNSETIFF, (void *)&ifr) < 0) + if (ioctl(tapif->fd, TUNSETIFF, (void *) &ifr) < 0) { perror("TapInterface: ioctl(TUNSETIFF) failed"); return ERR_IF; @@ -491,8 +490,7 @@ TapInterface_Init(TapInterface *tapif, const char *interfaceName, u8_t *macAddr) * @sa #TapInterface_SetupNetif * */ -int -TapInterface_Select(TapInterface *tapif, struct netif *netif, struct timeval sleepTime, size_t numIntfs) +int TapInterface_Select(TapInterface * tapif, struct netif * netif, struct timeval sleepTime, size_t numIntfs) { fd_set readfds; int ret; @@ -510,16 +508,17 @@ TapInterface_Select(TapInterface *tapif, struct netif *netif, struct timeval sle FD_SET(tapif[j].fd, &readfds); } - ret = select(tapif[numIntfs-1].fd + 1, &readfds, NULL, NULL, &sleepTime); + ret = select(tapif[numIntfs - 1].fd + 1, &readfds, NULL, NULL, &sleepTime); if (ret > 0) { for (j = 0; j < numIntfs; j++) { - if (! FD_ISSET(tapif[j].fd, &readfds)) + if (!FD_ISSET(tapif[j].fd, &readfds)) continue; - struct pbuf *p = TapInterface_low_level_input(&(tapif[j]), &(netif[j])); - if (p != NULL) { + struct pbuf * p = TapInterface_low_level_input(&(tapif[j]), &(netif[j])); + if (p != NULL) + { #if LINK_STATS lwip_stats.link.recv++; #endif /* LINK_STATS */ diff --git a/src/lwip/standalone/TapInterface.h b/src/lwip/standalone/TapInterface.h index 821f9e06b95a9c..62008bbeb1eab7 100644 --- a/src/lwip/standalone/TapInterface.h +++ b/src/lwip/standalone/TapInterface.h @@ -19,9 +19,9 @@ /* * Copyright (c) 2001-2003 Swedish Institute of Computer Science. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, @@ -30,21 +30,21 @@ * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. + * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT - * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT - * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING - * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY * OF SUCH DAMAGE. * * This file is part of the lwIP TCP/IP stack. - * + * * Author: Adam Dunkels * */ @@ -57,15 +57,16 @@ extern "C" { #endif -typedef struct TapInterface { - const char *interfaceName; - u8_t macAddr[6]; - int fd; +typedef struct TapInterface +{ + const char * interfaceName; + u8_t macAddr[6]; + int fd; } TapInterface; -err_t TapInterface_Init(TapInterface *tapif, const char *interfaceName, u8_t *macAddr); -err_t TapInterface_SetupNetif(struct netif *netif); -int TapInterface_Select(TapInterface *tapif, struct netif *netif, struct timeval sleepTime, size_t numIntfs); +err_t TapInterface_Init(TapInterface * tapif, const char * interfaceName, u8_t * macAddr); +err_t TapInterface_SetupNetif(struct netif * netif); +int TapInterface_Select(TapInterface * tapif, struct netif * netif, struct timeval sleepTime, size_t numIntfs); #ifdef __cplusplus } diff --git a/src/lwip/standalone/arch/cc.h b/src/lwip/standalone/arch/cc.h index a8b83a860734b7..3575f21272bb93 100644 --- a/src/lwip/standalone/arch/cc.h +++ b/src/lwip/standalone/arch/cc.h @@ -19,9 +19,9 @@ /* * Copyright (c) 2001-2003 Swedish Institute of Computer Science. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, @@ -30,21 +30,21 @@ * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. + * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT - * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT - * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING - * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY * OF SUCH DAMAGE. * * This file is part of the lwIP TCP/IP stack. - * + * * Author: Adam Dunkels * */ @@ -64,17 +64,17 @@ #endif /* BYTE_ORDER */ /* Define generic types used in lwIP */ -typedef unsigned char u8_t; -typedef signed char s8_t; -typedef unsigned short u16_t; -typedef signed short s16_t; -typedef unsigned int u32_t; -typedef signed int s32_t; +typedef unsigned char u8_t; +typedef signed char s8_t; +typedef unsigned short u16_t; +typedef signed short s16_t; +typedef unsigned int u32_t; +typedef signed int s32_t; typedef unsigned long mem_ptr_t; /* Define (sn)printf formatters for these lwIP types */ -#define X8_F "02x" +#define X8_F "02x" #define U16_F "hu" #define S16_F "hd" #define X16_F "hx" @@ -99,11 +99,20 @@ typedef unsigned long mem_ptr_t; #include #include /* Plaform specific diagnostic output */ -#define LWIP_PLATFORM_DIAG(x) do {printf x;} while(0) +#define LWIP_PLATFORM_DIAG(x) \ + do \ + { \ + printf x; \ + } while (0) -#define LWIP_PLATFORM_ASSERT(x) do {printf("Assertion \"%s\" failed at line %d in %s\n", \ - x, __LINE__, __FILE__); fflush(NULL); abort();} while(0) +#define LWIP_PLATFORM_ASSERT(x) \ + do \ + { \ + printf("Assertion \"%s\" failed at line %d in %s\n", x, __LINE__, __FILE__); \ + fflush(NULL); \ + abort(); \ + } while (0) -#define LWIP_RAND() ((u32_t)rand()) +#define LWIP_RAND() ((u32_t) rand()) #endif /* __ARCH_CC_H__ */ diff --git a/src/lwip/standalone/arch/perf.h b/src/lwip/standalone/arch/perf.h index 3523819475b1ac..f005be741b3bbf 100644 --- a/src/lwip/standalone/arch/perf.h +++ b/src/lwip/standalone/arch/perf.h @@ -19,9 +19,9 @@ /* * Copyright (c) 2001-2003 Swedish Institute of Computer Science. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, @@ -30,21 +30,21 @@ * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. + * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT - * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT - * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING - * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY * OF SUCH DAMAGE. * * This file is part of the lwIP TCP/IP stack. - * + * * Author: Adam Dunkels * */ @@ -54,11 +54,14 @@ #include #ifdef PERF -#define PERF_START { \ - unsigned long __c1l, __c1h, __c2l, __c2h; \ - __asm__(".byte 0x0f, 0x31" : "=a" (__c1l), "=d" (__c1h)) -#define PERF_STOP(x) __asm__(".byte 0x0f, 0x31" : "=a" (__c2l), "=d" (__c2h)); \ - perf_print(__c1l, __c1h, __c2l, __c2h, x);} +#define PERF_START \ + { \ + unsigned long __c1l, __c1h, __c2l, __c2h; \ + __asm__(".byte 0x0f, 0x31" : "=a"(__c1l), "=d"(__c1h)) +#define PERF_STOP(x) \ + __asm__(".byte 0x0f, 0x31" : "=a"(__c2l), "=d"(__c2h)); \ + perf_print(__c1l, __c1h, __c2l, __c2h, x); \ + } /*#define PERF_START do { \ struct tms __perf_start, __perf_end; \ @@ -66,20 +69,18 @@ #define PERF_STOP(x) times(&__perf_end); \ perf_print_times(&__perf_start, &__perf_end, x);\ } while(0)*/ -#else /* PERF */ -#define PERF_START /* null definition */ -#define PERF_STOP(x) /* null definition */ -#endif /* PERF */ +#else /* PERF */ +#define PERF_START /* null definition */ +#define PERF_STOP(x) /* null definition */ +#endif /* PERF */ -void perf_print(unsigned long c1l, unsigned long c1h, - unsigned long c2l, unsigned long c2h, - char *key); +void perf_print(unsigned long c1l, unsigned long c1h, unsigned long c2l, unsigned long c2h, char * key); -void perf_print_times(struct tms *start, struct tms *end, char *key); +void perf_print_times(struct tms * start, struct tms * end, char * key); -void perf_init(char *fname); +void perf_init(char * fname); -#define sys_profile_interval_set_pbuf_highwatermark(x,y) +#define sys_profile_interval_set_pbuf_highwatermark(x, y) #define sys_profile_pbuf_allocate(pbuf) #define sys_profile_pbuf_free(pbuf) #define sys_profile_pbuf_transfer(x, y) diff --git a/src/lwip/standalone/arch/sys_arch.h b/src/lwip/standalone/arch/sys_arch.h index ade18d21b68b76..bda55e17f3f779 100644 --- a/src/lwip/standalone/arch/sys_arch.h +++ b/src/lwip/standalone/arch/sys_arch.h @@ -19,9 +19,9 @@ /* * Copyright (c) 2001-2003 Swedish Institute of Computer Science. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, @@ -30,21 +30,21 @@ * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. + * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT - * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT - * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING - * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY * OF SUCH DAMAGE. * * This file is part of the lwIP TCP/IP stack. - * + * * Author: Adam Dunkels * */ @@ -54,19 +54,33 @@ #include #define SYS_MBOX_NULL NULL -#define SYS_SEM_NULL NULL +#define SYS_SEM_NULL NULL typedef u32_t sys_prot_t; struct sys_sem; typedef struct sys_sem * sys_sem_t; #define sys_sem_valid(sem) (((sem) != NULL) && (*(sem) != NULL)) -#define sys_sem_set_invalid(sem) do { if((sem) != NULL) { *(sem) = NULL; }}while(0) +#define sys_sem_set_invalid(sem) \ + do \ + { \ + if ((sem) != NULL) \ + { \ + *(sem) = NULL; \ + } \ + } while (0) struct sys_mbox; -typedef struct sys_mbox *sys_mbox_t; +typedef struct sys_mbox * sys_mbox_t; #define sys_mbox_valid(mbox) (((mbox) != NULL) && (*(mbox) != NULL)) -#define sys_mbox_set_invalid(mbox) do { if((mbox) != NULL) { *(mbox) = NULL; }}while(0) +#define sys_mbox_set_invalid(mbox) \ + do \ + { \ + if ((mbox) != NULL) \ + { \ + *(mbox) = NULL; \ + } \ + } while (0) struct sys_thread; typedef struct sys_thread * sys_thread_t; diff --git a/src/lwip/standalone/lwipopts.h b/src/lwip/standalone/lwipopts.h index 914d17e16790e4..62f8459a9034c0 100644 --- a/src/lwip/standalone/lwipopts.h +++ b/src/lwip/standalone/lwipopts.h @@ -24,7 +24,6 @@ * */ - #ifndef __LWIPOPTS_H__ #define __LWIPOPTS_H__ @@ -34,52 +33,51 @@ * NO_SYS==1: Provides VERY minimal functionality. Otherwise, * use lwIP facilities. */ -#define NO_SYS 0 +#define NO_SYS 0 /** * MEM_ALIGNMENT: should be set to the alignment of the CPU * 4 byte alignment -> #define MEM_ALIGNMENT 4 * 2 byte alignment -> #define MEM_ALIGNMENT 2 */ -#define MEM_ALIGNMENT (4) +#define MEM_ALIGNMENT (4) /** * MEM_SIZE: specify bigger memory size to pass LwIP-internal unit tests * (only needed when building tests) */ #ifdef CHIP_WITH_TESTS -#define MEM_SIZE (16000) +#define MEM_SIZE (16000) #endif /** * Use Malloc from LibC - saves code space */ -#define MEM_LIBC_MALLOC (0) +#define MEM_LIBC_MALLOC (0) /** * Do not use memory pools to create fixed, statically allocated pools of * memory in lieu of the Standard C Library heap and APIs. */ -#define MEM_USE_POOLS (0) +#define MEM_USE_POOLS (0) /** * Do not use custom memory pools for specific, named LwIP objects, sourced * from lwippools.h. */ -#define MEM_USE_CUSTOM_POOLS (MEM_USE_POOLS) +#define MEM_USE_CUSTOM_POOLS (MEM_USE_POOLS) /** * MEMP_NUM_NETBUF: the number of struct netbufs. * (only needed if you use the sequential API, like api_lib.c) */ -#define MEMP_NUM_NETBUF (PBUF_POOL_SIZE) - +#define MEMP_NUM_NETBUF (PBUF_POOL_SIZE) /** * MEMP_NUM_TCP_SEG: the number of simultaneously queued TCP segments. * (requires the LWIP_TCP option) */ -#define MEMP_NUM_TCP_SEG (TCP_SND_QUEUELEN+1) +#define MEMP_NUM_TCP_SEG (TCP_SND_QUEUELEN + 1) /** * PBUF_POOL_SIZE: the number of buffers in the pbuf pool. @@ -88,7 +86,7 @@ * To perform this override, define the makefile variable LWIP_NUM_PACKET_BUFFERS_IN_POOL */ #ifndef PBUF_POOL_SIZE -#define PBUF_POOL_SIZE (10) +#define PBUF_POOL_SIZE (10) #endif /* @@ -100,11 +98,11 @@ */ #if PBUF_POOL_SIZE > 2 #ifndef IP_REASS_MAX_PBUFS -#define IP_REASS_MAX_PBUFS (PBUF_POOL_SIZE - 2) +#define IP_REASS_MAX_PBUFS (PBUF_POOL_SIZE - 2) #endif #else -#define IP_REASS_MAX_PBUFS 0 -#define IP_REASSEMBLY 0 +#define IP_REASS_MAX_PBUFS 0 +#define IP_REASSEMBLY 0 #endif /** @@ -113,13 +111,13 @@ */ #if IP_REASS_MAX_PBUFS > 1 #ifndef MEMP_NUM_REASSDATA -#define MEMP_NUM_REASSDATA (IP_REASS_MAX_PBUFS - 1) +#define MEMP_NUM_REASSDATA (IP_REASS_MAX_PBUFS - 1) #endif #else -#define MEMP_NUM_REASSDATA 0 +#define MEMP_NUM_REASSDATA 0 #endif -#define PAYLOAD_MTU (1500) +#define PAYLOAD_MTU (1500) /** * TCP_MSS: TCP Maximum segment size. (default is 536, a conservative default, @@ -128,7 +126,7 @@ * when opening a connection. For the transmit size, this MSS sets * an upper limit on the MSS advertised by the remote host. */ -#define TCP_MSS (1152) +#define TCP_MSS (1152) /** * PBUF_POOL_BUFSIZE: the size of each pbuf in the pbuf pool. The default is @@ -137,15 +135,14 @@ * structure itself. */ -#define PBUF_POOL_BUFSIZE \ - LWIP_MEM_ALIGN_SIZE(PAYLOAD_MTU + PBUF_LINK_ENCAPSULATION_HLEN + PBUF_LINK_HLEN) + \ - LWIP_MEM_ALIGN_SIZE(sizeof(struct pbuf) + 1) +#define PBUF_POOL_BUFSIZE \ + LWIP_MEM_ALIGN_SIZE(PAYLOAD_MTU + PBUF_LINK_ENCAPSULATION_HLEN + PBUF_LINK_HLEN) + LWIP_MEM_ALIGN_SIZE(sizeof(struct pbuf) + 1) /** * TCP_SND_BUF: TCP sender buffer space (bytes). * must be at least as much as (2 * TCP_MSS) for things to work smoothly */ -#define TCP_SND_BUF (6 * TCP_MSS) +#define TCP_SND_BUF (6 * TCP_MSS) /** * ETH_PAD_SIZE: the header space required preceeding the of each pbuf in the pbuf pool. The default is @@ -154,9 +151,7 @@ * * This is zero since the role has been taken over by SUB_ETHERNET_HEADER_SPACE as ETH_PAD_SIZE was not always obeyed */ -#define ETH_PAD_SIZE (0) - - +#define ETH_PAD_SIZE (0) /** * LWIP_NETIF_TX_SINGLE_PBUF: if this is set to 1, lwIP tries to put all data @@ -167,79 +162,73 @@ * * @todo: TCP and IP-frag do not work with this, yet: */ -#define LWIP_NETIF_TX_SINGLE_PBUF (0) - +#define LWIP_NETIF_TX_SINGLE_PBUF (0) /** Define LWIP_COMPAT_MUTEX if the port has no mutexes and binary semaphores * should be used instead */ -#define LWIP_COMPAT_MUTEX (1) - +#define LWIP_COMPAT_MUTEX (1) /** Define LWIP_COMPAT_MUTEX_ALLOWED if the platform concurrency model has no * support for avoiding priority inversion deadlocks */ -#define LWIP_COMPAT_MUTEX_ALLOWED (1) - +#define LWIP_COMPAT_MUTEX_ALLOWED (1) /** * SYS_LIGHTWEIGHT_PROT==1: if you want inter-task protection for certain * critical regions during buffer allocation, deallocation and memory * allocation and deallocation. */ -#define SYS_LIGHTWEIGHT_PROT (0) - +#define SYS_LIGHTWEIGHT_PROT (0) /** * TCPIP_THREAD_STACKSIZE: The stack size used by the main tcpip thread. * The stack size value itself is platform-dependent, but is passed to * sys_thread_new() when the thread is created. */ -#define TCPIP_THREAD_STACKSIZE (1300) - +#define TCPIP_THREAD_STACKSIZE (1300) /** * TCPIP_THREAD_PRIO: The priority assigned to the main tcpip thread. * The priority value itself is platform-dependent, but is passed to * sys_thread_new() when the thread is created. */ -#define TCPIP_THREAD_PRIO (7) - -#define TCP_LISTEN_BACKLOG (1) +#define TCPIP_THREAD_PRIO (7) +#define TCP_LISTEN_BACKLOG (1) /** * LWIP_DHCP==1: Enable DHCP module. */ -#define LWIP_DHCP (1) +#define LWIP_DHCP (1) /** * Enable automatic IPv4 link-local address assignment. */ -#define LWIP_AUTOIP 1 +#define LWIP_AUTOIP 1 /** * Allow DHCP and automatic IPv4 link-local address assignment to * work cooperatively. */ -#define LWIP_DHCP_AUTOIP_COOP 1 +#define LWIP_DHCP_AUTOIP_COOP 1 /** * LWIP_PROVIDE_ERRNO: errno definitions from the Standard C Library. */ -#undef LWIP_PROVIDE_ERRNO +#undef LWIP_PROVIDE_ERRNO /** * ERRNO: set errno on interface invocation failures */ -#define ERRNO (1) +#define ERRNO (1) /** * MEMP_NUM_RAW_PCB: Number of raw connection PCBs * (requires the LWIP_RAW option) */ #ifndef MEMP_NUM_RAW_PCB -#define MEMP_NUM_RAW_PCB (5) +#define MEMP_NUM_RAW_PCB (5) #endif /** @@ -248,63 +237,59 @@ * (requires the LWIP_UDP option) */ #ifndef MEMP_NUM_UDP_PCB -#define MEMP_NUM_UDP_PCB (6) +#define MEMP_NUM_UDP_PCB (6) #endif /** * MEMP_NUM_SYS_TIMEOUT: the number of simulateously active timeouts. * (requires NO_SYS==0) - * Must be larger than or equal to LWIP_TCP + IP_REASSEMBLY + LWIP_ARP + (2*LWIP_DHCP) + LWIP_AUTOIP + LWIP_IGMP + LWIP_DNS + PPP_SUPPORT - * Since each InetTimer requires one matching LwIP timeout (if built with LwIP option), the number should be expanded to be - * (All LwIP needs) + (max number of InetTimers) + * Must be larger than or equal to LWIP_TCP + IP_REASSEMBLY + LWIP_ARP + (2*LWIP_DHCP) + LWIP_AUTOIP + LWIP_IGMP + LWIP_DNS + + * PPP_SUPPORT Since each InetTimer requires one matching LwIP timeout (if built with LwIP option), the number should be expanded to + * be (All LwIP needs) + (max number of InetTimers) */ -#define MEMP_NUM_SYS_TIMEOUT (48) - +#define MEMP_NUM_SYS_TIMEOUT (48) /* ARP before DHCP causes multi-second delay - turn it off */ -#define DHCP_DOES_ARP_CHECK (0) +#define DHCP_DOES_ARP_CHECK (0) /** * LWIP_HAVE_LOOPIF==1: Support loop interface (127.0.0.1) and loopif.c */ -#define LWIP_HAVE_LOOPIF (1) +#define LWIP_HAVE_LOOPIF (1) /** * LWIP_NETIF_LOOPBACK==1: Support sending packets with a destination IP * address equal to the netif IP address, looping them back up the stack. */ -#define LWIP_NETIF_LOOPBACK (0) +#define LWIP_NETIF_LOOPBACK (0) /** * MEMP_NUM_NETCONN: the number of struct netconns. * (only needed if you use the sequential API, like api_lib.c) */ -#define MEMP_NUM_NETCONN (8) +#define MEMP_NUM_NETCONN (8) /** * LWIP_SO_RCVTIMEO==1: Enable SO_RCVTIMEO processing. */ -#define LWIP_SO_RCVTIMEO (1) - +#define LWIP_SO_RCVTIMEO (1) /** * LWIP_IGMP==1: Turn on IGMP module. */ -#define LWIP_IGMP (1) - +#define LWIP_IGMP (1) /** * SO_REUSE==1: Enable SO_REUSEADDR option. * Required by IGMP for reuse of multicast address and port by other sockets */ -#define SO_REUSE (1) - +#define SO_REUSE (1) /** * LWIP_DNS==1: Turn on DNS module. UDP must be available for DNS * transport. */ -#define LWIP_DNS (1) +#define LWIP_DNS (1) /** * LWIP_POSIX_SOCKETS_IO_NAMES==1: Enable POSIX-style sockets functions names. @@ -314,38 +299,38 @@ * We disable this because this otherwise collides with the Standard C * Library where both LWIP and its headers are included. */ -#define LWIP_POSIX_SOCKETS_IO_NAMES (0) +#define LWIP_POSIX_SOCKETS_IO_NAMES (0) #ifdef LWIP_SO_RCVBUF -#if ( LWIP_SO_RCVBUF == 1 ) -#include /* Needed because RECV_BUFSIZE_DEFAULT is defined as INT_MAX */ -#endif /* if ( LWIP_SO_RCVBUF == 1 ) */ -#endif /* ifdef LWIP_SO_RCVBUF */ +#if (LWIP_SO_RCVBUF == 1) +#include /* Needed because RECV_BUFSIZE_DEFAULT is defined as INT_MAX */ +#endif /* if ( LWIP_SO_RCVBUF == 1 ) */ +#endif /* ifdef LWIP_SO_RCVBUF */ /** * LWIP_STATS : Turn on statistics gathering */ -#define LWIP_STATS (1) +#define LWIP_STATS (1) /** * LWIP_IPV6==1: Enable IPv6 */ #ifndef LWIP_IPV6 -#define LWIP_IPV6 1 +#define LWIP_IPV6 1 #endif /** * LWIP_IPV6_DHCP6==1: enable DHCPv6 stateful address autoconfiguration. */ #ifndef LWIP_IPV6_DHCP6 -#define LWIP_IPV6_DHCP6 1 +#define LWIP_IPV6_DHCP6 1 #endif /** * LWIP_IPV6_MLD==1: Enable multicast listener discovery protocol. */ #ifndef LWIP_IPV6_MLD -#define LWIP_IPV6_MLD 1 +#define LWIP_IPV6_MLD 1 #endif /** @@ -356,20 +341,20 @@ * for/by DAD in this epoch of LwIP), and another four (4) for * application groups. */ -#define MEMP_NUM_MLD6_GROUP ((1 + 1) + 4) +#define MEMP_NUM_MLD6_GROUP ((1 + 1) + 4) /** * LWIP_IPV6_FORWARD==1: Enable IPv6 forwarding. */ #ifndef LWIP_IPV6_FORWARD -#define LWIP_IPV6_FORWARD 1 +#define LWIP_IPV6_FORWARD 1 #endif /** * LWIP_IPV6_ROUTE_TABLE_SUPPORT==1: Enable support for a routing table and refering these during forwarding. */ #ifndef LWIP_IPV6_ROUTE_TABLE_SUPPORT -#define LWIP_IPV6_ROUTE_TABLE_SUPPORT 1 +#define LWIP_IPV6_ROUTE_TABLE_SUPPORT 1 #endif /** @@ -377,11 +362,11 @@ */ #ifndef IPV6_FRAG_COPYHEADER #if defined(__x86_64__) -#define IPV6_FRAG_COPYHEADER 1 +#define IPV6_FRAG_COPYHEADER 1 #else -#define IPV6_FRAG_COPYHEADER 0 +#define IPV6_FRAG_COPYHEADER 0 +#endif #endif -#endif /** * Debug printing @@ -390,34 +375,34 @@ */ #ifdef LWIP_DEBUG -#define MEMP_OVERFLOW_CHECK ( 1 ) -#define MEMP_SANITY_CHECK ( 1 ) - -#define MEM_DEBUG LWIP_DBG_OFF -#define MEMP_DEBUG LWIP_DBG_OFF -#define PBUF_DEBUG LWIP_DBG_ON -#define API_LIB_DEBUG LWIP_DBG_ON -#define API_MSG_DEBUG LWIP_DBG_ON -#define TCPIP_DEBUG LWIP_DBG_ON -#define NETIF_DEBUG LWIP_DBG_ON -#define SOCKETS_DEBUG LWIP_DBG_ON -#define DEMO_DEBUG LWIP_DBG_ON -#define IP_DEBUG LWIP_DBG_ON -#define IP6_DEBUG LWIP_DBG_ON -#define IP_REASS_DEBUG LWIP_DBG_ON -#define RAW_DEBUG LWIP_DBG_ON -#define ICMP_DEBUG LWIP_DBG_ON -#define UDP_DEBUG LWIP_DBG_ON -#define TCP_DEBUG LWIP_DBG_ON -#define TCP_INPUT_DEBUG LWIP_DBG_ON +#define MEMP_OVERFLOW_CHECK (1) +#define MEMP_SANITY_CHECK (1) + +#define MEM_DEBUG LWIP_DBG_OFF +#define MEMP_DEBUG LWIP_DBG_OFF +#define PBUF_DEBUG LWIP_DBG_ON +#define API_LIB_DEBUG LWIP_DBG_ON +#define API_MSG_DEBUG LWIP_DBG_ON +#define TCPIP_DEBUG LWIP_DBG_ON +#define NETIF_DEBUG LWIP_DBG_ON +#define SOCKETS_DEBUG LWIP_DBG_ON +#define DEMO_DEBUG LWIP_DBG_ON +#define IP_DEBUG LWIP_DBG_ON +#define IP6_DEBUG LWIP_DBG_ON +#define IP_REASS_DEBUG LWIP_DBG_ON +#define RAW_DEBUG LWIP_DBG_ON +#define ICMP_DEBUG LWIP_DBG_ON +#define UDP_DEBUG LWIP_DBG_ON +#define TCP_DEBUG LWIP_DBG_ON +#define TCP_INPUT_DEBUG LWIP_DBG_ON #define TCP_OUTPUT_DEBUG LWIP_DBG_ON -#define TCP_RTO_DEBUG LWIP_DBG_ON -#define TCP_CWND_DEBUG LWIP_DBG_ON -#define TCP_WND_DEBUG LWIP_DBG_ON -#define TCP_FR_DEBUG LWIP_DBG_ON -#define TCP_QLEN_DEBUG LWIP_DBG_ON -#define TCP_RST_DEBUG LWIP_DBG_ON -#define PPP_DEBUG LWIP_DBG_OFF +#define TCP_RTO_DEBUG LWIP_DBG_ON +#define TCP_CWND_DEBUG LWIP_DBG_ON +#define TCP_WND_DEBUG LWIP_DBG_ON +#define TCP_FR_DEBUG LWIP_DBG_ON +#define TCP_QLEN_DEBUG LWIP_DBG_ON +#define TCP_RST_DEBUG LWIP_DBG_ON +#define PPP_DEBUG LWIP_DBG_OFF extern unsigned char gLwIP_DebugFlags; #define LWIP_DBG_TYPES_ON gLwIP_DebugFlags @@ -437,14 +422,13 @@ extern unsigned char gLwIP_DebugFlags; * zero (0). That generally makes RTOSes such as FreeRTOS very * unhappy. Specify reasonable defaults instead. */ -#define TCPIP_MBOX_SIZE 6 +#define TCPIP_MBOX_SIZE 6 -#define DEFAULT_RAW_RECVMBOX_SIZE 6 +#define DEFAULT_RAW_RECVMBOX_SIZE 6 -#define DEFAULT_UDP_RECVMBOX_SIZE 6 - -#define DEFAULT_TCP_RECVMBOX_SIZE 6 +#define DEFAULT_UDP_RECVMBOX_SIZE 6 +#define DEFAULT_TCP_RECVMBOX_SIZE 6 /* --------------------------------- @@ -455,8 +439,7 @@ extern unsigned char gLwIP_DebugFlags; /** * LWIP_RAW==1: Enable application layer to hook into the IP layer itself. */ -#define LWIP_RAW 1 - +#define LWIP_RAW 1 /* ---------------------------------------------- @@ -467,7 +450,7 @@ extern unsigned char gLwIP_DebugFlags; /** * LWIP_NETCONN==1: Enable Netconn API (require to use api_lib.c) */ -#define LWIP_NETCONN 0 +#define LWIP_NETCONN 0 /* ------------------------------------ @@ -478,31 +461,28 @@ extern unsigned char gLwIP_DebugFlags; /** * LWIP_SOCKET==1: Enable Socket API (require to use sockets.c) */ -#define LWIP_SOCKET 0 - +#define LWIP_SOCKET 0 /** * Enable locking in the lwip (tcpip) thread. */ #ifndef LWIP_TCPIP_CORE_LOCKING -#define LWIP_TCPIP_CORE_LOCKING 1 +#define LWIP_TCPIP_CORE_LOCKING 1 #endif - /** * Enable support for TCP keepalives. */ #ifndef LWIP_TCP_KEEPALIVE -#define LWIP_TCP_KEEPALIVE 1 +#define LWIP_TCP_KEEPALIVE 1 #endif - /** LWIP_DONT_PROVIDE_BYTEORDER_FUNCTIONS: * Ensure compatibilty with platforms where LwIP is configured not to define the host/network byte-order conversion * functions normally provided in on POSIX systems. */ #ifndef LWIP_DONT_PROVIDE_BYTEORDER_FUNCTIONS -#define LWIP_DONT_PROVIDE_BYTEORDER_FUNCTIONS 1 +#define LWIP_DONT_PROVIDE_BYTEORDER_FUNCTIONS 1 #endif #endif /* __LWIPOPTS_H__ */ diff --git a/src/lwip/standalone/sys_arch.c b/src/lwip/standalone/sys_arch.c index d91a7bdeb090e4..7b338a3883f9bb 100644 --- a/src/lwip/standalone/sys_arch.c +++ b/src/lwip/standalone/sys_arch.c @@ -19,9 +19,9 @@ /* * Copyright (c) 2001-2003 Swedish Institute of Computer Science. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, @@ -30,21 +30,21 @@ * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. + * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT - * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT - * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING - * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY * OF SUCH DAMAGE. * * This file is part of the lwIP TCP/IP stack. - * + * * Author: Adam Dunkels * */ @@ -76,130 +76,134 @@ #include "lwip/opt.h" #include "lwip/stats.h" -#define UMAX(a, b) ((a) > (b) ? (a) : (b)) +#define UMAX(a, b) ((a) > (b) ? (a) : (b)) static struct timeval starttime; #if !NO_SYS -static struct sys_thread *threads = NULL; +static struct sys_thread * threads = NULL; static pthread_mutex_t threads_mutex = PTHREAD_MUTEX_INITIALIZER; -struct sys_mbox_msg { - struct sys_mbox_msg *next; - void *msg; +struct sys_mbox_msg +{ + struct sys_mbox_msg * next; + void * msg; }; #define SYS_MBOX_SIZE 128 -struct sys_mbox { - int first, last; - void *msgs[SYS_MBOX_SIZE]; - struct sys_sem *not_empty; - struct sys_sem *not_full; - struct sys_sem *mutex; - int wait_send; +struct sys_mbox +{ + int first, last; + void * msgs[SYS_MBOX_SIZE]; + struct sys_sem * not_empty; + struct sys_sem * not_full; + struct sys_sem * mutex; + int wait_send; }; -struct sys_sem { - unsigned int c; - pthread_cond_t cond; - pthread_mutex_t mutex; +struct sys_sem +{ + unsigned int c; + pthread_cond_t cond; + pthread_mutex_t mutex; }; -struct sys_thread { - struct sys_thread *next; - pthread_t pthread; +struct sys_thread +{ + struct sys_thread * next; + pthread_t pthread; }; #if SYS_LIGHTWEIGHT_PROT static pthread_mutex_t lwprot_mutex = PTHREAD_MUTEX_INITIALIZER; -static pthread_t lwprot_thread = (pthread_t)0xDEAD; -static int lwprot_count = 0; +static pthread_t lwprot_thread = (pthread_t) 0xDEAD; +static int lwprot_count = 0; #endif /* SYS_LIGHTWEIGHT_PROT */ -static struct sys_sem *sys_sem_new_internal(u8_t count); -static void sys_sem_free_internal(struct sys_sem *sem); +static struct sys_sem * sys_sem_new_internal(u8_t count); +static void sys_sem_free_internal(struct sys_sem * sem); -static u32_t cond_wait(pthread_cond_t * cond, pthread_mutex_t * mutex, - u32_t timeout); +static u32_t cond_wait(pthread_cond_t * cond, pthread_mutex_t * mutex, u32_t timeout); /*-----------------------------------------------------------------------------------*/ -static struct sys_thread * -introduce_thread(pthread_t id) +static struct sys_thread * introduce_thread(pthread_t id) { - struct sys_thread *thread; + struct sys_thread * thread; - thread = (struct sys_thread *)malloc(sizeof(struct sys_thread)); + thread = (struct sys_thread *) malloc(sizeof(struct sys_thread)); - if (thread != NULL) { - pthread_mutex_lock(&threads_mutex); - thread->next = threads; - thread->pthread = id; - threads = thread; - pthread_mutex_unlock(&threads_mutex); - } + if (thread != NULL) + { + pthread_mutex_lock(&threads_mutex); + thread->next = threads; + thread->pthread = id; + threads = thread; + pthread_mutex_unlock(&threads_mutex); + } - return thread; + return thread; } /*-----------------------------------------------------------------------------------*/ -static void -finish_thread(struct sys_thread *thread) +static void finish_thread(struct sys_thread * thread) { - struct sys_thread *cursor; - struct sys_thread *previous; - - if (thread != NULL) { - pthread_mutex_lock(&threads_mutex); - - previous = NULL; - cursor = threads; - while (cursor != NULL) { - if (cursor == thread) { - if (previous != NULL) { - previous->next = cursor->next; - } else { - threads = cursor->next; + struct sys_thread * cursor; + struct sys_thread * previous; + + if (thread != NULL) + { + pthread_mutex_lock(&threads_mutex); + + previous = NULL; + cursor = threads; + while (cursor != NULL) + { + if (cursor == thread) + { + if (previous != NULL) + { + previous->next = cursor->next; + } + else + { + threads = cursor->next; + } + cursor->next = NULL; + cursor->pthread = 0; + break; + } + previous = cursor; + cursor = cursor->next; } - cursor->next = NULL; - cursor->pthread = 0; - break; - } - previous = cursor; - cursor = cursor->next; - } - pthread_mutex_unlock(&threads_mutex); - free(thread); - } + pthread_mutex_unlock(&threads_mutex); + free(thread); + } } /*-----------------------------------------------------------------------------------*/ -sys_thread_t -sys_thread_new(const char *name, lwip_thread_fn function, void *arg, int stacksize, int prio) +sys_thread_t sys_thread_new(const char * name, lwip_thread_fn function, void * arg, int stacksize, int prio) { - int code; - pthread_t tmp; - struct sys_thread *st = NULL; - LWIP_UNUSED_ARG(name); - LWIP_UNUSED_ARG(stacksize); - LWIP_UNUSED_ARG(prio); - - code = pthread_create(&tmp, - NULL, - (void *(*)(void *)) - function, - arg); - - if (0 == code) { - st = introduce_thread(tmp); - } - - if (NULL == st) { - LWIP_DEBUGF(SYS_DEBUG, ("sys_thread_new: pthread_create %d, st = 0x%lx", - code, (unsigned long)st)); - abort(); - } - return st; + int code; + pthread_t tmp; + struct sys_thread * st = NULL; + LWIP_UNUSED_ARG(name); + LWIP_UNUSED_ARG(stacksize); + LWIP_UNUSED_ARG(prio); + + code = pthread_create(&tmp, NULL, (void * (*) (void *) ) function, arg); + + if (0 == code) + { + st = introduce_thread(tmp); + } + + if (NULL == st) + { + LWIP_DEBUGF(SYS_DEBUG, ("sys_thread_new: pthread_create %d, st = 0x%lx", code, (unsigned long) st)); + abort(); + } + return st; } /*-----------------------------------------------------------------------------------*/ err_t sys_thread_finish(sys_thread_t t) @@ -207,359 +211,385 @@ err_t sys_thread_finish(sys_thread_t t) int code; code = pthread_join(t->pthread, NULL); - if (0 == code) { - finish_thread(t); - return ERR_OK; + if (0 == code) + { + finish_thread(t); + return ERR_OK; } - else { - return ERR_VAL; + else + { + return ERR_VAL; } } /*-----------------------------------------------------------------------------------*/ -err_t sys_mbox_new_extra(void *pool, struct sys_mbox **mb, int size) { +err_t sys_mbox_new_extra(void * pool, struct sys_mbox ** mb, int size) +{ return sys_mbox_new(mb, size); } -err_t -sys_mbox_new(struct sys_mbox **mb, int size) +err_t sys_mbox_new(struct sys_mbox ** mb, int size) { - struct sys_mbox *mbox; - LWIP_UNUSED_ARG(size); - - mbox = (struct sys_mbox *)malloc(sizeof(struct sys_mbox)); - if (mbox == NULL) { - return ERR_MEM; - } - mbox->first = mbox->last = 0; - mbox->not_empty = sys_sem_new_internal(0); - mbox->not_full = sys_sem_new_internal(0); - mbox->mutex = sys_sem_new_internal(1); - mbox->wait_send = 0; - - SYS_STATS_INC_USED(mbox); - *mb = mbox; - return ERR_OK; + struct sys_mbox * mbox; + LWIP_UNUSED_ARG(size); + + mbox = (struct sys_mbox *) malloc(sizeof(struct sys_mbox)); + if (mbox == NULL) + { + return ERR_MEM; + } + mbox->first = mbox->last = 0; + mbox->not_empty = sys_sem_new_internal(0); + mbox->not_full = sys_sem_new_internal(0); + mbox->mutex = sys_sem_new_internal(1); + mbox->wait_send = 0; + + SYS_STATS_INC_USED(mbox); + *mb = mbox; + return ERR_OK; } /*-----------------------------------------------------------------------------------*/ -void -sys_mbox_free(struct sys_mbox **mb) +void sys_mbox_free(struct sys_mbox ** mb) { - if ((mb != NULL) && (*mb != SYS_MBOX_NULL)) { - struct sys_mbox *mbox = *mb; - SYS_STATS_DEC(mbox.used); - sys_arch_sem_wait(&mbox->mutex, 0); - - sys_sem_free_internal(mbox->not_empty); - sys_sem_free_internal(mbox->not_full); - sys_sem_free_internal(mbox->mutex); - mbox->not_empty = mbox->not_full = mbox->mutex = NULL; - /* LWIP_DEBUGF("sys_mbox_free: mbox 0x%lx\n", mbox); */ - free(mbox); - } + if ((mb != NULL) && (*mb != SYS_MBOX_NULL)) + { + struct sys_mbox * mbox = *mb; + SYS_STATS_DEC(mbox.used); + sys_arch_sem_wait(&mbox->mutex, 0); + + sys_sem_free_internal(mbox->not_empty); + sys_sem_free_internal(mbox->not_full); + sys_sem_free_internal(mbox->mutex); + mbox->not_empty = mbox->not_full = mbox->mutex = NULL; + /* LWIP_DEBUGF("sys_mbox_free: mbox 0x%lx\n", mbox); */ + free(mbox); + } } /*-----------------------------------------------------------------------------------*/ -err_t -sys_mbox_trypost(struct sys_mbox **mb, void *msg) +err_t sys_mbox_trypost(struct sys_mbox ** mb, void * msg) { - u8_t first; - struct sys_mbox *mbox; - LWIP_ASSERT("invalid mbox", (mb != NULL) && (*mb != NULL)); - mbox = *mb; + u8_t first; + struct sys_mbox * mbox; + LWIP_ASSERT("invalid mbox", (mb != NULL) && (*mb != NULL)); + mbox = *mb; - sys_arch_sem_wait(&mbox->mutex, 0); + sys_arch_sem_wait(&mbox->mutex, 0); - LWIP_DEBUGF(SYS_DEBUG, ("sys_mbox_trypost: mbox %p msg %p\n", - (void *)mbox, (void *)msg)); + LWIP_DEBUGF(SYS_DEBUG, ("sys_mbox_trypost: mbox %p msg %p\n", (void *) mbox, (void *) msg)); - if ((mbox->last + 1) >= (mbox->first + SYS_MBOX_SIZE)) { - sys_sem_signal(&mbox->mutex); - return ERR_MEM; - } + if ((mbox->last + 1) >= (mbox->first + SYS_MBOX_SIZE)) + { + sys_sem_signal(&mbox->mutex); + return ERR_MEM; + } - mbox->msgs[mbox->last % SYS_MBOX_SIZE] = msg; + mbox->msgs[mbox->last % SYS_MBOX_SIZE] = msg; - if (mbox->last == mbox->first) { - first = 1; - } else { - first = 0; - } + if (mbox->last == mbox->first) + { + first = 1; + } + else + { + first = 0; + } - mbox->last++; + mbox->last++; - if (first) { - sys_sem_signal(&mbox->not_empty); - } + if (first) + { + sys_sem_signal(&mbox->not_empty); + } - sys_sem_signal(&mbox->mutex); + sys_sem_signal(&mbox->mutex); - return ERR_OK; + return ERR_OK; } /*-----------------------------------------------------------------------------------*/ -void -sys_mbox_post(struct sys_mbox **mb, void *msg) +void sys_mbox_post(struct sys_mbox ** mb, void * msg) { - u8_t first; - struct sys_mbox *mbox; - LWIP_ASSERT("invalid mbox", (mb != NULL) && (*mb != NULL)); - mbox = *mb; + u8_t first; + struct sys_mbox * mbox; + LWIP_ASSERT("invalid mbox", (mb != NULL) && (*mb != NULL)); + mbox = *mb; - sys_arch_sem_wait(&mbox->mutex, 0); + sys_arch_sem_wait(&mbox->mutex, 0); - LWIP_DEBUGF(SYS_DEBUG, ("sys_mbox_post: mbox %p msg %p\n", (void *)mbox, (void *)msg)); + LWIP_DEBUGF(SYS_DEBUG, ("sys_mbox_post: mbox %p msg %p\n", (void *) mbox, (void *) msg)); - while ((mbox->last + 1) >= (mbox->first + SYS_MBOX_SIZE)) { - mbox->wait_send++; - sys_sem_signal(&mbox->mutex); - sys_arch_sem_wait(&mbox->not_full, 0); - sys_arch_sem_wait(&mbox->mutex, 0); - mbox->wait_send--; - } + while ((mbox->last + 1) >= (mbox->first + SYS_MBOX_SIZE)) + { + mbox->wait_send++; + sys_sem_signal(&mbox->mutex); + sys_arch_sem_wait(&mbox->not_full, 0); + sys_arch_sem_wait(&mbox->mutex, 0); + mbox->wait_send--; + } - mbox->msgs[mbox->last % SYS_MBOX_SIZE] = msg; + mbox->msgs[mbox->last % SYS_MBOX_SIZE] = msg; - if (mbox->last == mbox->first) { - first = 1; - } else { - first = 0; - } + if (mbox->last == mbox->first) + { + first = 1; + } + else + { + first = 0; + } - mbox->last++; + mbox->last++; - if (first) { - sys_sem_signal(&mbox->not_empty); - } + if (first) + { + sys_sem_signal(&mbox->not_empty); + } - sys_sem_signal(&mbox->mutex); + sys_sem_signal(&mbox->mutex); } /*-----------------------------------------------------------------------------------*/ -u32_t -sys_arch_mbox_tryfetch(struct sys_mbox **mb, void **msg) +u32_t sys_arch_mbox_tryfetch(struct sys_mbox ** mb, void ** msg) { - struct sys_mbox *mbox; - LWIP_ASSERT("invalid mbox", (mb != NULL) && (*mb != NULL)); - mbox = *mb; + struct sys_mbox * mbox; + LWIP_ASSERT("invalid mbox", (mb != NULL) && (*mb != NULL)); + mbox = *mb; - sys_arch_sem_wait(&mbox->mutex, 0); + sys_arch_sem_wait(&mbox->mutex, 0); - if (mbox->first == mbox->last) { - sys_sem_signal(&mbox->mutex); - return SYS_MBOX_EMPTY; - } + if (mbox->first == mbox->last) + { + sys_sem_signal(&mbox->mutex); + return SYS_MBOX_EMPTY; + } - if (msg != NULL) { - LWIP_DEBUGF(SYS_DEBUG, ("sys_mbox_tryfetch: mbox %p msg %p\n", (void *)mbox, *msg)); - *msg = mbox->msgs[mbox->first % SYS_MBOX_SIZE]; - } - else{ - LWIP_DEBUGF(SYS_DEBUG, ("sys_mbox_tryfetch: mbox %p, null msg\n", (void *)mbox)); - } + if (msg != NULL) + { + LWIP_DEBUGF(SYS_DEBUG, ("sys_mbox_tryfetch: mbox %p msg %p\n", (void *) mbox, *msg)); + *msg = mbox->msgs[mbox->first % SYS_MBOX_SIZE]; + } + else + { + LWIP_DEBUGF(SYS_DEBUG, ("sys_mbox_tryfetch: mbox %p, null msg\n", (void *) mbox)); + } - mbox->first++; + mbox->first++; - if (mbox->wait_send) { - sys_sem_signal(&mbox->not_full); - } + if (mbox->wait_send) + { + sys_sem_signal(&mbox->not_full); + } - sys_sem_signal(&mbox->mutex); + sys_sem_signal(&mbox->mutex); - return 0; + return 0; } /*-----------------------------------------------------------------------------------*/ -u32_t -sys_arch_mbox_fetch(struct sys_mbox **mb, void **msg, u32_t timeout) +u32_t sys_arch_mbox_fetch(struct sys_mbox ** mb, void ** msg, u32_t timeout) { - u32_t time_needed = 0; - struct sys_mbox *mbox; - LWIP_ASSERT("invalid mbox", (mb != NULL) && (*mb != NULL)); - mbox = *mb; + u32_t time_needed = 0; + struct sys_mbox * mbox; + LWIP_ASSERT("invalid mbox", (mb != NULL) && (*mb != NULL)); + mbox = *mb; - /* The mutex lock is quick so we don't bother with the timeout - stuff here. */ - sys_arch_sem_wait(&mbox->mutex, 0); + /* The mutex lock is quick so we don't bother with the timeout + stuff here. */ + sys_arch_sem_wait(&mbox->mutex, 0); - while (mbox->first == mbox->last) { - sys_sem_signal(&mbox->mutex); + while (mbox->first == mbox->last) + { + sys_sem_signal(&mbox->mutex); - /* We block while waiting for a mail to arrive in the mailbox. We - must be prepared to timeout. */ - if (timeout != 0) { - time_needed = sys_arch_sem_wait(&mbox->not_empty, timeout); + /* We block while waiting for a mail to arrive in the mailbox. We + must be prepared to timeout. */ + if (timeout != 0) + { + time_needed = sys_arch_sem_wait(&mbox->not_empty, timeout); - if (time_needed == SYS_ARCH_TIMEOUT) { - return SYS_ARCH_TIMEOUT; - } - } else { - sys_arch_sem_wait(&mbox->not_empty, 0); - } + if (time_needed == SYS_ARCH_TIMEOUT) + { + return SYS_ARCH_TIMEOUT; + } + } + else + { + sys_arch_sem_wait(&mbox->not_empty, 0); + } - sys_arch_sem_wait(&mbox->mutex, 0); - } + sys_arch_sem_wait(&mbox->mutex, 0); + } - if (msg != NULL) { - LWIP_DEBUGF(SYS_DEBUG, ("sys_mbox_fetch: mbox %p msg %p\n", (void *)mbox, *msg)); - *msg = mbox->msgs[mbox->first % SYS_MBOX_SIZE]; - } - else{ - LWIP_DEBUGF(SYS_DEBUG, ("sys_mbox_fetch: mbox %p, null msg\n", (void *)mbox)); - } + if (msg != NULL) + { + LWIP_DEBUGF(SYS_DEBUG, ("sys_mbox_fetch: mbox %p msg %p\n", (void *) mbox, *msg)); + *msg = mbox->msgs[mbox->first % SYS_MBOX_SIZE]; + } + else + { + LWIP_DEBUGF(SYS_DEBUG, ("sys_mbox_fetch: mbox %p, null msg\n", (void *) mbox)); + } - mbox->first++; + mbox->first++; - if (mbox->wait_send) { - sys_sem_signal(&mbox->not_full); - } + if (mbox->wait_send) + { + sys_sem_signal(&mbox->not_full); + } - sys_sem_signal(&mbox->mutex); + sys_sem_signal(&mbox->mutex); - return time_needed; + return time_needed; } /*-----------------------------------------------------------------------------------*/ -static struct sys_sem * -sys_sem_new_internal(u8_t count) +static struct sys_sem * sys_sem_new_internal(u8_t count) { - struct sys_sem *sem; - - sem = (struct sys_sem *)malloc(sizeof(struct sys_sem)); - if (sem != NULL) { - sem->c = count; - pthread_cond_init(&(sem->cond), NULL); - pthread_mutex_init(&(sem->mutex), NULL); - } - return sem; + struct sys_sem * sem; + + sem = (struct sys_sem *) malloc(sizeof(struct sys_sem)); + if (sem != NULL) + { + sem->c = count; + pthread_cond_init(&(sem->cond), NULL); + pthread_mutex_init(&(sem->mutex), NULL); + } + return sem; } /*-----------------------------------------------------------------------------------*/ -err_t -sys_sem_new(struct sys_sem **sem, u8_t count) +err_t sys_sem_new(struct sys_sem ** sem, u8_t count) { - SYS_STATS_INC_USED(sem); - *sem = sys_sem_new_internal(count); - if (*sem == NULL) { - return ERR_MEM; - } - return ERR_OK; + SYS_STATS_INC_USED(sem); + *sem = sys_sem_new_internal(count); + if (*sem == NULL) + { + return ERR_MEM; + } + return ERR_OK; } /*-----------------------------------------------------------------------------------*/ -static u32_t -cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex, u32_t timeout) +static u32_t cond_wait(pthread_cond_t * cond, pthread_mutex_t * mutex, u32_t timeout) { - time_t tdiff; - time_t sec, usec; - struct timeval rtime1, rtime2; - struct timespec ts; - int retval; - - if (timeout > 0) { - /* Get a timestamp and add the timeout value. */ - gettimeofday(&rtime1, NULL); - sec = rtime1.tv_sec; - usec = rtime1.tv_usec; - usec += timeout % 1000 * 1000; - sec += (int)(timeout / 1000) + (int)(usec / 1000000); - usec = usec % 1000000; - ts.tv_nsec = usec * 1000; - ts.tv_sec = sec; - - retval = pthread_cond_timedwait(cond, mutex, &ts); - - if (retval == ETIMEDOUT) { - return SYS_ARCH_TIMEOUT; - } else { - /* Calculate for how long we waited for the cond. */ - gettimeofday(&rtime2, NULL); - tdiff = (rtime2.tv_sec - rtime1.tv_sec) * 1000 + - (rtime2.tv_usec - rtime1.tv_usec) / 1000; - - if (tdiff <= 0) { + time_t tdiff; + time_t sec, usec; + struct timeval rtime1, rtime2; + struct timespec ts; + int retval; + + if (timeout > 0) + { + /* Get a timestamp and add the timeout value. */ + gettimeofday(&rtime1, NULL); + sec = rtime1.tv_sec; + usec = rtime1.tv_usec; + usec += timeout % 1000 * 1000; + sec += (int) (timeout / 1000) + (int) (usec / 1000000); + usec = usec % 1000000; + ts.tv_nsec = usec * 1000; + ts.tv_sec = sec; + + retval = pthread_cond_timedwait(cond, mutex, &ts); + + if (retval == ETIMEDOUT) + { + return SYS_ARCH_TIMEOUT; + } + else + { + /* Calculate for how long we waited for the cond. */ + gettimeofday(&rtime2, NULL); + tdiff = (rtime2.tv_sec - rtime1.tv_sec) * 1000 + (rtime2.tv_usec - rtime1.tv_usec) / 1000; + + if (tdiff <= 0) + { + return 0; + } + return (u32_t) tdiff; + } + } + else + { + pthread_cond_wait(cond, mutex); return 0; - } - return (u32_t)tdiff; } - } else { - pthread_cond_wait(cond, mutex); - return 0; - } } /*-----------------------------------------------------------------------------------*/ -u32_t -sys_arch_sem_wait(struct sys_sem **s, u32_t timeout) +u32_t sys_arch_sem_wait(struct sys_sem ** s, u32_t timeout) { - u32_t time_needed = 0; - struct sys_sem *sem; - LWIP_ASSERT("invalid sem", (s != NULL) && (*s != NULL)); - sem = *s; - - pthread_mutex_lock(&(sem->mutex)); - while (sem->c <= 0) { - if (timeout > 0) { - time_needed = cond_wait(&(sem->cond), &(sem->mutex), timeout); - - if (time_needed == SYS_ARCH_TIMEOUT) { - pthread_mutex_unlock(&(sem->mutex)); - return SYS_ARCH_TIMEOUT; - } - /* pthread_mutex_unlock(&(sem->mutex)); - return time_needed; */ - } else { - cond_wait(&(sem->cond), &(sem->mutex), 0); - } - } - sem->c--; - pthread_mutex_unlock(&(sem->mutex)); - return (u32_t)time_needed; + u32_t time_needed = 0; + struct sys_sem * sem; + LWIP_ASSERT("invalid sem", (s != NULL) && (*s != NULL)); + sem = *s; + + pthread_mutex_lock(&(sem->mutex)); + while (sem->c <= 0) + { + if (timeout > 0) + { + time_needed = cond_wait(&(sem->cond), &(sem->mutex), timeout); + + if (time_needed == SYS_ARCH_TIMEOUT) + { + pthread_mutex_unlock(&(sem->mutex)); + return SYS_ARCH_TIMEOUT; + } + /* pthread_mutex_unlock(&(sem->mutex)); + return time_needed; */ + } + else + { + cond_wait(&(sem->cond), &(sem->mutex), 0); + } + } + sem->c--; + pthread_mutex_unlock(&(sem->mutex)); + return (u32_t) time_needed; } /*-----------------------------------------------------------------------------------*/ -void -sys_sem_signal(struct sys_sem **s) +void sys_sem_signal(struct sys_sem ** s) { - struct sys_sem *sem; - LWIP_ASSERT("invalid sem", (s != NULL) && (*s != NULL)); - sem = *s; + struct sys_sem * sem; + LWIP_ASSERT("invalid sem", (s != NULL) && (*s != NULL)); + sem = *s; - pthread_mutex_lock(&(sem->mutex)); - sem->c++; + pthread_mutex_lock(&(sem->mutex)); + sem->c++; - if (sem->c > 1) { - sem->c = 1; - } + if (sem->c > 1) + { + sem->c = 1; + } - pthread_cond_broadcast(&(sem->cond)); - pthread_mutex_unlock(&(sem->mutex)); + pthread_cond_broadcast(&(sem->cond)); + pthread_mutex_unlock(&(sem->mutex)); } /*-----------------------------------------------------------------------------------*/ -static void -sys_sem_free_internal(struct sys_sem *sem) +static void sys_sem_free_internal(struct sys_sem * sem) { - pthread_cond_destroy(&(sem->cond)); - pthread_mutex_destroy(&(sem->mutex)); - free(sem); + pthread_cond_destroy(&(sem->cond)); + pthread_mutex_destroy(&(sem->mutex)); + free(sem); } /*-----------------------------------------------------------------------------------*/ -void -sys_sem_free(struct sys_sem **sem) +void sys_sem_free(struct sys_sem ** sem) { - if ((sem != NULL) && (*sem != SYS_SEM_NULL)) { - SYS_STATS_DEC(sem.used); - sys_sem_free_internal(*sem); - } + if ((sem != NULL) && (*sem != SYS_SEM_NULL)) + { + SYS_STATS_DEC(sem.used); + sys_sem_free_internal(*sem); + } } #endif /* !NO_SYS */ /*-----------------------------------------------------------------------------------*/ -u32_t -sys_now(void) +u32_t sys_now(void) { - struct timeval tv; - u32_t msec; - gettimeofday(&tv, NULL); + struct timeval tv; + u32_t msec; + gettimeofday(&tv, NULL); - msec = (u32_t)((tv.tv_sec - starttime.tv_sec) * 1000 + (tv.tv_usec - starttime.tv_usec) / 1000); + msec = (u32_t)((tv.tv_sec - starttime.tv_sec) * 1000 + (tv.tv_usec - starttime.tv_usec) / 1000); - return msec; + return msec; } /*-----------------------------------------------------------------------------------*/ -void -sys_init(void) +void sys_init(void) { - gettimeofday(&starttime, NULL); + gettimeofday(&starttime, NULL); } /*-----------------------------------------------------------------------------------*/ #if SYS_LIGHTWEIGHT_PROT @@ -577,8 +607,7 @@ that case the return value indicates that it is already protected. sys_arch_protect() is only required if your port is supporting an operating system. */ -sys_prot_t -sys_arch_protect(void) +sys_prot_t sys_arch_protect(void) { /* Note that for the UNIX port, we are using a lightweight mutex, and our * own counter (which is locked by the mutex). The return code is not actually @@ -586,10 +615,10 @@ sys_arch_protect(void) if (lwprot_thread != pthread_self()) { /* We are locking the mutex where it has not been locked before * - * or is being locked by another thread */ + * or is being locked by another thread */ pthread_mutex_lock(&lwprot_mutex); lwprot_thread = pthread_self(); - lwprot_count = 1; + lwprot_count = 1; } else /* It is already locked by THIS thread */ @@ -605,8 +634,7 @@ value specified by pval. See the documentation for sys_arch_protect() for more information. This function is only required if your port is supporting an operating system. */ -void -sys_arch_unprotect(sys_prot_t pval) +void sys_arch_unprotect(sys_prot_t pval) { LWIP_UNUSED_ARG(pval); if (lwprot_thread == pthread_self()) @@ -623,26 +651,25 @@ sys_arch_unprotect(sys_prot_t pval) /*-----------------------------------------------------------------------------------*/ #ifndef MAX_JIFFY_OFFSET -#define MAX_JIFFY_OFFSET ((~0U >> 1)-1) +#define MAX_JIFFY_OFFSET ((~0U >> 1) - 1) #endif #ifndef HZ #define HZ 100 #endif -u32_t -sys_jiffies(void) +u32_t sys_jiffies(void) { struct timeval tv; unsigned long sec; long usec; - gettimeofday(&tv,NULL); - sec = tv.tv_sec - starttime.tv_sec; + gettimeofday(&tv, NULL); + sec = tv.tv_sec - starttime.tv_sec; usec = tv.tv_usec; if (sec >= (MAX_JIFFY_OFFSET / HZ)) - return MAX_JIFFY_OFFSET; + return MAX_JIFFY_OFFSET; usec += 1000000L / HZ - 1; usec /= 1000000L / HZ; return HZ * sec + usec; @@ -652,11 +679,11 @@ sys_jiffies(void) #include -void ppp_trace(int level, const char *format, ...) +void ppp_trace(int level, const char * format, ...) { va_list args; - (void)level; + (void) level; va_start(args, format); vprintf(format, args); va_end(args); @@ -667,5 +694,4 @@ void ppp_trace(int level, const char *format, ...) unsigned char gLwIP_DebugFlags = 0; - #endif diff --git a/src/platform/EFR32/BLEManagerImpl.cpp b/src/platform/EFR32/BLEManagerImpl.cpp index 5d65ad8ad1e78f..4c6493a16d2861 100644 --- a/src/platform/EFR32/BLEManagerImpl.cpp +++ b/src/platform/EFR32/BLEManagerImpl.cpp @@ -59,7 +59,7 @@ namespace { #define MAX_ADV_DATA_LEN 31 // Timer Frequency used. -#define TIMER_CLK_FREQ ((uint32)32768) +#define TIMER_CLK_FREQ ((uint32) 32768) // Convert msec to timer ticks. #define TIMER_MS_2_TIMERTICK(ms) ((TIMER_CLK_FREQ * ms) / 1000) #define TIMER_S_2_TIMERTICK(s) (TIMER_CLK_FREQ * s) @@ -70,13 +70,13 @@ uint8_t bluetooth_stack_heap[DEFAULT_BLUETOOTH_HEAP(BLE_LAYER_NUM_BLE_ENDPOINTS) * details on each parameter) */ static gecko_configuration_t config; -const uint8_t UUID_CHIPoBLEService[] = {0xFB, 0x34, 0x9B, 0x5F, 0x80, 0x00, 0x00, 0x80, - 0x00, 0x10, 0x00, 0x00, 0xAF, 0xFE, 0x00, 0x00}; -const uint8_t ShortUUID_CHIPoBLEService[] = {0xAF, 0xFE}; -const ChipBleUUID ChipUUID_CHIPoBLEChar_RX = { - {0x18, 0xEE, 0x2E, 0xF5, 0x26, 0x3D, 0x45, 0x59, 0x95, 0x9F, 0x4F, 0x9C, 0x42, 0x9F, 0x9D, 0x11}}; -const ChipBleUUID ChipUUID_CHIPoBLEChar_TX = { - {0x18, 0xEE, 0x2E, 0xF5, 0x26, 0x3D, 0x45, 0x59, 0x95, 0x9F, 0x4F, 0x9C, 0x42, 0x9F, 0x9D, 0x12}}; +const uint8_t UUID_CHIPoBLEService[] = { 0xFB, 0x34, 0x9B, 0x5F, 0x80, 0x00, 0x00, 0x80, + 0x00, 0x10, 0x00, 0x00, 0xAF, 0xFE, 0x00, 0x00 }; +const uint8_t ShortUUID_CHIPoBLEService[] = { 0xAF, 0xFE }; +const ChipBleUUID ChipUUID_CHIPoBLEChar_RX = { { 0x18, 0xEE, 0x2E, 0xF5, 0x26, 0x3D, 0x45, 0x59, 0x95, 0x9F, 0x4F, 0x9C, 0x42, 0x9F, + 0x9D, 0x11 } }; +const ChipBleUUID ChipUUID_CHIPoBLEChar_TX = { { 0x18, 0xEE, 0x2E, 0xF5, 0x26, 0x3D, 0x45, 0x59, 0x95, 0x9F, 0x4F, 0x9C, 0x42, 0x9F, + 0x9D, 0x12 } }; } // namespace @@ -107,9 +107,9 @@ extern "C" errorcode_t initialize_bluetooth() static void initBleConfig(void) { memset(&config, 0, sizeof(gecko_configuration_t)); - config.config_flags = GECKO_CONFIG_FLAG_RTOS; /* Check flag options from UG136 */ - config.bluetooth.max_connections = BLE_LAYER_NUM_BLE_ENDPOINTS; /* Maximum number of simultaneous connections */ - config.bluetooth.heap = bluetooth_stack_heap; /* Bluetooth stack memory for connection management */ + config.config_flags = GECKO_CONFIG_FLAG_RTOS; /* Check flag options from UG136 */ + config.bluetooth.max_connections = BLE_LAYER_NUM_BLE_ENDPOINTS; /* Maximum number of simultaneous connections */ + config.bluetooth.heap = bluetooth_stack_heap; /* Bluetooth stack memory for connection management */ config.bluetooth.heap_size = sizeof(bluetooth_stack_heap); /* Size of Heap */ config.gattdb = &bg_gattdb_data; /* Pointer to GATT database */ config.scheduler_callback = BluetoothLLCallback; @@ -142,19 +142,18 @@ CHIP_ERROR BLEManagerImpl::_Init() initBleConfig(); // Start Bluetooth Link Layer and stack tasks - ret = bluetooth_start(CHIP_DEVICE_CONFIG_BLE_LL_TASK_PRIORITY, CHIP_DEVICE_CONFIG_BLE_STACK_TASK_PRIORITY, - initialize_bluetooth); + ret = + bluetooth_start(CHIP_DEVICE_CONFIG_BLE_LL_TASK_PRIORITY, CHIP_DEVICE_CONFIG_BLE_STACK_TASK_PRIORITY, initialize_bluetooth); VerifyOrExit(ret == bg_err_success, err = MapBLEError(ret)); // Create the Bluetooth Application task - xTaskCreate(bluetoothStackEventHandler, /* Function that implements the task. */ - CHIP_DEVICE_CONFIG_BLE_APP_TASK_NAME, /* Text name for the task. */ - CHIP_DEVICE_CONFIG_BLE_APP_TASK_STACK_SIZE / - sizeof(StackType_t), /* Number of indexes in the xStack array. */ - this, /* Parameter passed into the task. */ - CHIP_DEVICE_CONFIG_BLE_APP_TASK_PRIORITY, /* Priority at which the task is created. */ - NULL); /* Variable to hold the task's data structure. */ + xTaskCreate(bluetoothStackEventHandler, /* Function that implements the task. */ + CHIP_DEVICE_CONFIG_BLE_APP_TASK_NAME, /* Text name for the task. */ + CHIP_DEVICE_CONFIG_BLE_APP_TASK_STACK_SIZE / sizeof(StackType_t), /* Number of indexes in the xStack array. */ + this, /* Parameter passed into the task. */ + CHIP_DEVICE_CONFIG_BLE_APP_TASK_PRIORITY, /* Priority at which the task is created. */ + NULL); /* Variable to hold the task's data structure. */ mFlags = kFlag_AdvertisingEnabled; PlatformMgr().ScheduleWork(DriveBLEState, 0); @@ -177,19 +176,18 @@ uint16_t BLEManagerImpl::_NumConnections(void) return numCons; } -void BLEManagerImpl::bluetoothStackEventHandler(void *p_arg) +void BLEManagerImpl::bluetoothStackEventHandler(void * p_arg) { EventBits_t flags = 0; while (1) { // wait for Bluetooth stack events, do not consume set flag - flags |= - xEventGroupWaitBits(bluetooth_event_flags, /* The event group being tested. */ - BLUETOOTH_EVENT_FLAG_EVT_WAITING, /* The bits within the event group to wait for. */ - pdFALSE, /* Dont clear flags before returning */ - pdFALSE, /* Any flag will do, dont wait for all flags to be set */ - portMAX_DELAY); /* Wait for maximum duration for bit to be set */ + flags |= xEventGroupWaitBits(bluetooth_event_flags, /* The event group being tested. */ + BLUETOOTH_EVENT_FLAG_EVT_WAITING, /* The bits within the event group to wait for. */ + pdFALSE, /* Dont clear flags before returning */ + pdFALSE, /* Any flag will do, dont wait for all flags to be set */ + portMAX_DELAY); /* Wait for maximum duration for bit to be set */ if (flags & BLUETOOTH_EVENT_FLAG_EVT_WAITING) { @@ -203,20 +201,17 @@ void BLEManagerImpl::bluetoothStackEventHandler(void *p_arg) // handle bluetooth events switch (BGLIB_MSG_ID(bluetooth_evt->header)) { - case gecko_evt_system_boot_id: - { + case gecko_evt_system_boot_id: { sInstance.HandleBootEvent(); } break; - case gecko_evt_le_connection_opened_id: - { + case gecko_evt_le_connection_opened_id: { sInstance.HandleConnectEvent(bluetooth_evt); } break; - case gecko_evt_le_connection_closed_id: - { + case gecko_evt_le_connection_closed_id: { sInstance.HandleConnectionCloseEvent(bluetooth_evt); } break; @@ -224,21 +219,18 @@ void BLEManagerImpl::bluetoothStackEventHandler(void *p_arg) /* This event indicates that a remote GATT client is attempting to write a value of an * attribute in to the local GATT database, where the attribute was defined in the GATT * XML firmware configuration file to have type="user". */ - case gecko_evt_gatt_server_attribute_value_id: - { + case gecko_evt_gatt_server_attribute_value_id: { sInstance.HandleWriteEvent(bluetooth_evt); } break; - case gecko_evt_gatt_mtu_exchanged_id: - { + case gecko_evt_gatt_mtu_exchanged_id: { sInstance.UpdateMtu(bluetooth_evt); } break; // confirmation of indication received from remote GATT client - case gecko_evt_gatt_server_characteristic_status_id: - { + case gecko_evt_gatt_server_characteristic_status_id: { enum gatt_server_characteristic_status_flag StatusFlags; StatusFlags = (enum gatt_server_characteristic_status_flag) @@ -248,10 +240,8 @@ void BLEManagerImpl::bluetoothStackEventHandler(void *p_arg) { sInstance.HandleTxConfirmationEvent(bluetooth_evt); } - else if ((bluetooth_evt->data.evt_gatt_server_characteristic_status.characteristic == - gattdb_CHIPoBLEChar_Tx) && - (bluetooth_evt->data.evt_gatt_server_characteristic_status.status_flags == - gatt_server_client_config)) + else if ((bluetooth_evt->data.evt_gatt_server_characteristic_status.characteristic == gattdb_CHIPoBLEChar_Tx) && + (bluetooth_evt->data.evt_gatt_server_characteristic_status.status_flags == gatt_server_client_config)) { sInstance.HandleTXCharCCCDWrite(bluetooth_evt); } @@ -259,8 +249,7 @@ void BLEManagerImpl::bluetoothStackEventHandler(void *p_arg) break; /* Software Timer event */ - case gecko_evt_hardware_soft_timer_id: - { + case gecko_evt_hardware_soft_timer_id: { sInstance.HandleSoftTimerEvent(bluetooth_evt); } break; @@ -282,8 +271,7 @@ CHIP_ERROR BLEManagerImpl::_SetCHIPoBLEServiceMode(CHIPoBLEServiceMode val) CHIP_ERROR err = CHIP_NO_ERROR; VerifyOrExit(val != ConnectivityManager::kCHIPoBLEServiceMode_NotSupported, err = CHIP_ERROR_INVALID_ARGUMENT); - VerifyOrExit(mServiceMode != ConnectivityManager::kCHIPoBLEServiceMode_NotSupported, - err = CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE); + VerifyOrExit(mServiceMode != ConnectivityManager::kCHIPoBLEServiceMode_NotSupported, err = CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE); if (val != mServiceMode) { @@ -299,8 +287,7 @@ CHIP_ERROR BLEManagerImpl::_SetAdvertisingEnabled(bool val) { CHIP_ERROR err = CHIP_NO_ERROR; - VerifyOrExit(mServiceMode != ConnectivityManager::kCHIPoBLEServiceMode_NotSupported, - err = CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE); + VerifyOrExit(mServiceMode != ConnectivityManager::kCHIPoBLEServiceMode_NotSupported, err = CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE); if (GetFlag(mFlags, kFlag_AdvertisingEnabled) != val) { @@ -316,8 +303,7 @@ CHIP_ERROR BLEManagerImpl::_SetFastAdvertisingEnabled(bool val) { CHIP_ERROR err = CHIP_NO_ERROR; - VerifyOrExit(mServiceMode == ConnectivityManager::kCHIPoBLEServiceMode_NotSupported, - err = CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE); + VerifyOrExit(mServiceMode == ConnectivityManager::kCHIPoBLEServiceMode_NotSupported, err = CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE); if (GetFlag(mFlags, kFlag_FastAdvertisingEnabled) != val) { @@ -329,7 +315,7 @@ CHIP_ERROR BLEManagerImpl::_SetFastAdvertisingEnabled(bool val) return err; } -CHIP_ERROR BLEManagerImpl::_GetDeviceName(char *buf, size_t bufSize) +CHIP_ERROR BLEManagerImpl::_GetDeviceName(char * buf, size_t bufSize) { if (strlen(mDeviceName) >= bufSize) { @@ -339,7 +325,7 @@ CHIP_ERROR BLEManagerImpl::_GetDeviceName(char *buf, size_t bufSize) return CHIP_NO_ERROR; } -CHIP_ERROR BLEManagerImpl::_SetDeviceName(const char *deviceName) +CHIP_ERROR BLEManagerImpl::_SetDeviceName(const char * deviceName) { if (mServiceMode == ConnectivityManager::kCHIPoBLEServiceMode_NotSupported) { @@ -354,7 +340,7 @@ CHIP_ERROR BLEManagerImpl::_SetDeviceName(const char *deviceName) strcpy(mDeviceName, deviceName); SetFlag(mFlags, kFlag_DeviceNameSet, true); ChipLogProgress(DeviceLayer, "Setting device name to : \"%s\"", deviceName); - gecko_cmd_gatt_server_write_attribute_value(gattdb_device_name, 0, strlen(deviceName), (uint8_t *)deviceName); + gecko_cmd_gatt_server_write_attribute_value(gattdb_device_name, 0, strlen(deviceName), (uint8_t *) deviceName); } else { @@ -363,12 +349,11 @@ CHIP_ERROR BLEManagerImpl::_SetDeviceName(const char *deviceName) return CHIP_NO_ERROR; } -void BLEManagerImpl::_OnPlatformEvent(const ChipDeviceEvent *event) +void BLEManagerImpl::_OnPlatformEvent(const ChipDeviceEvent * event) { switch (event->Type) { - case DeviceEventType::kCHIPoBLESubscribe: - { + case DeviceEventType::kCHIPoBLESubscribe: { ChipDeviceEvent connEstEvent; ChipLogProgress(DeviceLayer, "_OnPlatformEvent kCHIPoBLESubscribe"); @@ -378,30 +363,26 @@ void BLEManagerImpl::_OnPlatformEvent(const ChipDeviceEvent *event) } break; - case DeviceEventType::kCHIPoBLEUnsubscribe: - { + case DeviceEventType::kCHIPoBLEUnsubscribe: { ChipLogProgress(DeviceLayer, "_OnPlatformEvent kCHIPoBLEUnsubscribe"); HandleUnsubscribeReceived(event->CHIPoBLEUnsubscribe.ConId, &CHIP_BLE_SVC_ID, &ChipUUID_CHIPoBLEChar_TX); } break; - case DeviceEventType::kCHIPoBLEWriteReceived: - { + case DeviceEventType::kCHIPoBLEWriteReceived: { ChipLogProgress(DeviceLayer, "_OnPlatformEvent kCHIPoBLEWriteReceived"); HandleWriteReceived(event->CHIPoBLEWriteReceived.ConId, &CHIP_BLE_SVC_ID, &ChipUUID_CHIPoBLEChar_RX, event->CHIPoBLEWriteReceived.Data); } break; - case DeviceEventType::kCHIPoBLEConnectionError: - { + case DeviceEventType::kCHIPoBLEConnectionError: { ChipLogProgress(DeviceLayer, "_OnPlatformEvent kCHIPoBLEConnectionError"); HandleConnectionError(event->CHIPoBLEConnectionError.ConId, event->CHIPoBLEConnectionError.Reason); } break; - case DeviceEventType::kCHIPoBLEIndicateConfirm: - { + case DeviceEventType::kCHIPoBLEIndicateConfirm: { ChipLogProgress(DeviceLayer, "_OnPlatformEvent kCHIPoBLEIndicateConfirm"); HandleIndicationConfirmation(event->CHIPoBLEIndicateConfirm.ConId, &CHIP_BLE_SVC_ID, &ChipUUID_CHIPoBLEChar_TX); } @@ -413,17 +394,13 @@ void BLEManagerImpl::_OnPlatformEvent(const ChipDeviceEvent *event) } } -bool BLEManagerImpl::SubscribeCharacteristic(BLE_CONNECTION_OBJECT conId, - const ChipBleUUID * svcId, - const ChipBleUUID * charId) +bool BLEManagerImpl::SubscribeCharacteristic(BLE_CONNECTION_OBJECT conId, const ChipBleUUID * svcId, const ChipBleUUID * charId) { ChipLogProgress(DeviceLayer, "BLEManagerImpl::SubscribeCharacteristic() not supported"); return false; } -bool BLEManagerImpl::UnsubscribeCharacteristic(BLE_CONNECTION_OBJECT conId, - const ChipBleUUID * svcId, - const ChipBleUUID * charId) +bool BLEManagerImpl::UnsubscribeCharacteristic(BLE_CONNECTION_OBJECT conId, const ChipBleUUID * svcId, const ChipBleUUID * charId) { ChipLogProgress(DeviceLayer, "BLEManagerImpl::UnsubscribeCharacteristic() not supported"); return false; @@ -431,8 +408,8 @@ bool BLEManagerImpl::UnsubscribeCharacteristic(BLE_CONNECTION_OBJECT conId, bool BLEManagerImpl::CloseConnection(BLE_CONNECTION_OBJECT conId) { - CHIP_ERROR err = CHIP_NO_ERROR; - gecko_msg_le_connection_close_rsp_t *rsp; + CHIP_ERROR err = CHIP_NO_ERROR; + gecko_msg_le_connection_close_rsp_t * rsp; ChipLogProgress(DeviceLayer, "Closing BLE GATT connection (con %u)", conId); @@ -449,20 +426,18 @@ bool BLEManagerImpl::CloseConnection(BLE_CONNECTION_OBJECT conId) uint16_t BLEManagerImpl::GetMTU(BLE_CONNECTION_OBJECT conId) const { - CHIPoBLEConState *conState = const_cast(this)->GetConnectionState(conId); + CHIPoBLEConState * conState = const_cast(this)->GetConnectionState(conId); return (conState != NULL) ? conState->mtu : 0; } -bool BLEManagerImpl::SendIndication(BLE_CONNECTION_OBJECT conId, - const ChipBleUUID * svcId, - const ChipBleUUID * charId, - PacketBuffer * data) +bool BLEManagerImpl::SendIndication(BLE_CONNECTION_OBJECT conId, const ChipBleUUID * svcId, const ChipBleUUID * charId, + PacketBuffer * data) { - CHIP_ERROR err = CHIP_NO_ERROR; - CHIPoBLEConState * conState = GetConnectionState(conId); - gecko_msg_gatt_server_send_characteristic_notification_rsp_t *rsp; - uint16_t cId = (UUIDsMatch(&ChipUUID_CHIPoBLEChar_RX, charId) ? gattdb_CHIPoBLEChar_Rx : gattdb_CHIPoBLEChar_Tx); - uint8_t timerHandle = GetTimerHandle(conId, true); + CHIP_ERROR err = CHIP_NO_ERROR; + CHIPoBLEConState * conState = GetConnectionState(conId); + gecko_msg_gatt_server_send_characteristic_notification_rsp_t * rsp; + uint16_t cId = (UUIDsMatch(&ChipUUID_CHIPoBLEChar_RX, charId) ? gattdb_CHIPoBLEChar_Rx : gattdb_CHIPoBLEChar_Tx); + uint8_t timerHandle = GetTimerHandle(conId, true); VerifyOrExit(((conState != NULL) && (conState->subscribed != 0)), err = CHIP_ERROR_INVALID_ARGUMENT); VerifyOrExit(timerHandle != kMaxConnections, err = CHIP_ERROR_NO_MEMORY); @@ -484,28 +459,22 @@ bool BLEManagerImpl::SendIndication(BLE_CONNECTION_OBJECT conId, return true; } -bool BLEManagerImpl::SendWriteRequest(BLE_CONNECTION_OBJECT conId, - const ChipBleUUID * svcId, - const ChipBleUUID * charId, - PacketBuffer * pBuf) +bool BLEManagerImpl::SendWriteRequest(BLE_CONNECTION_OBJECT conId, const ChipBleUUID * svcId, const ChipBleUUID * charId, + PacketBuffer * pBuf) { ChipLogProgress(DeviceLayer, "BLEManagerImpl::SendWriteRequest() not supported"); return false; } -bool BLEManagerImpl::SendReadRequest(BLE_CONNECTION_OBJECT conId, - const ChipBleUUID * svcId, - const ChipBleUUID * charId, - PacketBuffer * pBuf) +bool BLEManagerImpl::SendReadRequest(BLE_CONNECTION_OBJECT conId, const ChipBleUUID * svcId, const ChipBleUUID * charId, + PacketBuffer * pBuf) { ChipLogProgress(DeviceLayer, "BLEManagerImpl::SendReadRequest() not supported"); return false; } -bool BLEManagerImpl::SendReadResponse(BLE_CONNECTION_OBJECT conId, - BLE_READ_REQUEST_CONTEXT requestContext, - const ChipBleUUID * svcId, - const ChipBleUUID * charId) +bool BLEManagerImpl::SendReadResponse(BLE_CONNECTION_OBJECT conId, BLE_READ_REQUEST_CONTEXT requestContext, + const ChipBleUUID * svcId, const ChipBleUUID * charId) { ChipLogProgress(DeviceLayer, "BLEManagerImpl::SendReadResponse() not supported"); return false; @@ -520,10 +489,13 @@ CHIP_ERROR BLEManagerImpl::MapBLEError(int bleErr) { CHIP_ERROR err; - if (bleErr == bg_err_success) { - err = CHIP_NO_ERROR; - } else { - err = (CHIP_ERROR) bleErr + CHIP_DEVICE_CONFIG_EFR32_BLE_ERROR_MIN; + if (bleErr == bg_err_success) + { + err = CHIP_NO_ERROR; + } + else + { + err = (CHIP_ERROR) bleErr + CHIP_DEVICE_CONFIG_EFR32_BLE_ERROR_MIN; } return err; @@ -565,14 +537,14 @@ void BLEManagerImpl::DriveBLEState(void) CHIP_ERROR BLEManagerImpl::ConfigureAdvertisingData(void) { - struct gecko_msg_le_gap_bt5_set_adv_data_rsp_t *setAdvDataRsp; - ChipBLEDeviceIdentificationInfo mDeviceIdInfo; - CHIP_ERROR err; - uint8_t responseData[MAX_RESPONSE_DATA_LEN]; - uint8_t advData[MAX_ADV_DATA_LEN]; - uint8_t index = 0; - uint8_t mDeviceNameLength = 0; - uint8_t mDeviceIdInfoLength = 0; + struct gecko_msg_le_gap_bt5_set_adv_data_rsp_t * setAdvDataRsp; + ChipBLEDeviceIdentificationInfo mDeviceIdInfo; + CHIP_ERROR err; + uint8_t responseData[MAX_RESPONSE_DATA_LEN]; + uint8_t advData[MAX_ADV_DATA_LEN]; + uint8_t index = 0; + uint8_t mDeviceNameLength = 0; + uint8_t mDeviceIdInfoLength = 0; memset(responseData, 0, MAX_RESPONSE_DATA_LEN); memset(advData, 0, MAX_ADV_DATA_LEN); @@ -582,34 +554,33 @@ CHIP_ERROR BLEManagerImpl::ConfigureAdvertisingData(void) if (!GetFlag(mFlags, kFlag_DeviceNameSet)) { - snprintf(mDeviceName, sizeof(mDeviceName), "%s%04" PRIX32, CHIP_DEVICE_CONFIG_BLE_DEVICE_NAME_PREFIX, - (uint32_t)0); + snprintf(mDeviceName, sizeof(mDeviceName), "%s%04" PRIX32, CHIP_DEVICE_CONFIG_BLE_DEVICE_NAME_PREFIX, (uint32_t) 0); mDeviceName[kMaxDeviceNameLength] = 0; - gecko_cmd_gatt_server_write_attribute_value(gattdb_device_name, 0, strlen(mDeviceName), (uint8_t *)mDeviceName); + gecko_cmd_gatt_server_write_attribute_value(gattdb_device_name, 0, strlen(mDeviceName), (uint8_t *) mDeviceName); } mDeviceNameLength = strlen(mDeviceName); // Device Name length + length field mDeviceIdInfoLength = sizeof(mDeviceIdInfo); // Servicedatalen + length+ UUID (Short) index = 0; - responseData[index++] = 0x02; // length + responseData[index++] = 0x02; // length responseData[index++] = CHIP_ADV_DATA_TYPE_FLAGS; // AD type : flags responseData[index++] = CHIP_ADV_DATA_FLAGS; // AD value responseData[index++] = mDeviceNameLength + 1; // length - responseData[index++] = CHIP_ADV_DATA_TYPE_NAME; // AD type : name + responseData[index++] = CHIP_ADV_DATA_TYPE_NAME; // AD type : name memcpy(&responseData[index], mDeviceName, mDeviceNameLength); // AD value index += mDeviceNameLength; - responseData[index++] = CHIP_ADV_SHORT_UUID_LEN + 1; // AD length - responseData[index++] = CHIP_ADV_DATA_TYPE_UUID; // AD type : uuid - responseData[index++] = ShortUUID_CHIPoBLEService[0]; // AD value + responseData[index++] = CHIP_ADV_SHORT_UUID_LEN + 1; // AD length + responseData[index++] = CHIP_ADV_DATA_TYPE_UUID; // AD type : uuid + responseData[index++] = ShortUUID_CHIPoBLEService[0]; // AD value responseData[index++] = ShortUUID_CHIPoBLEService[1]; - setAdvDataRsp = gecko_cmd_le_gap_bt5_set_adv_data(CHIP_ADV_CHIPOBLE_SERVICE_HANDLE, CHIP_ADV_SCAN_RESPONSE_DATA, - index, (uint8_t *)&responseData); + setAdvDataRsp = gecko_cmd_le_gap_bt5_set_adv_data(CHIP_ADV_CHIPOBLE_SERVICE_HANDLE, CHIP_ADV_SCAN_RESPONSE_DATA, index, + (uint8_t *) &responseData); if (setAdvDataRsp->result != 0) { @@ -622,13 +593,12 @@ CHIP_ERROR BLEManagerImpl::ConfigureAdvertisingData(void) advData[index++] = mDeviceIdInfoLength + CHIP_ADV_SHORT_UUID_LEN + 1; // AD length advData[index++] = CHIP_ADV_DATA_TYPE_SERVICE_DATA; // AD type : Service Data - advData[index++] = ShortUUID_CHIPoBLEService[0]; // AD value + advData[index++] = ShortUUID_CHIPoBLEService[0]; // AD value advData[index++] = ShortUUID_CHIPoBLEService[1]; - memcpy(&advData[index], (void *)&mDeviceIdInfo, mDeviceIdInfoLength); // AD value + memcpy(&advData[index], (void *) &mDeviceIdInfo, mDeviceIdInfoLength); // AD value index += mDeviceIdInfoLength; - setAdvDataRsp = - gecko_cmd_le_gap_bt5_set_adv_data(CHIP_ADV_CHIPOBLE_SERVICE_HANDLE, CHIP_ADV_DATA, index, (uint8_t *)&advData); + setAdvDataRsp = gecko_cmd_le_gap_bt5_set_adv_data(CHIP_ADV_CHIPOBLE_SERVICE_HANDLE, CHIP_ADV_DATA, index, (uint8_t *) &advData); err = MapBLEError(setAdvDataRsp->result); @@ -638,23 +608,22 @@ CHIP_ERROR BLEManagerImpl::ConfigureAdvertisingData(void) CHIP_ERROR BLEManagerImpl::StartAdvertising(void) { - CHIP_ERROR err; - struct gecko_msg_le_gap_start_advertising_rsp_t *startAdvRsp; - uint32_t interval_min; - uint32_t interval_max; - uint16_t numConnectionss = NumConnections(); - uint8_t connectableAdv = - (numConnectionss < kMaxConnections) ? le_gap_connectable_scannable : le_gap_scannable_non_connectable; + CHIP_ERROR err; + struct gecko_msg_le_gap_start_advertising_rsp_t * startAdvRsp; + uint32_t interval_min; + uint32_t interval_max; + uint16_t numConnectionss = NumConnections(); + uint8_t connectableAdv = (numConnectionss < kMaxConnections) ? le_gap_connectable_scannable : le_gap_scannable_non_connectable; err = ConfigureAdvertisingData(); SuccessOrExit(err); ClearFlag(mFlags, kFlag_RestartAdvertising); - interval_min = interval_max = ((numConnectionss == 0 && !ConfigurationMgr().IsPairedToAccount()) || - GetFlag(mFlags, kFlag_FastAdvertisingEnabled)) - ? CHIP_DEVICE_CONFIG_BLE_FAST_ADVERTISING_INTERVAL - : CHIP_DEVICE_CONFIG_BLE_SLOW_ADVERTISING_INTERVAL; + interval_min = interval_max = + ((numConnectionss == 0 && !ConfigurationMgr().IsPairedToAccount()) || GetFlag(mFlags, kFlag_FastAdvertisingEnabled)) + ? CHIP_DEVICE_CONFIG_BLE_FAST_ADVERTISING_INTERVAL + : CHIP_DEVICE_CONFIG_BLE_SLOW_ADVERTISING_INTERVAL; gecko_cmd_le_gap_set_advertise_timing(CHIP_ADV_CHIPOBLE_SERVICE_HANDLE, interval_min, interval_max, 0, 0); @@ -668,8 +637,8 @@ CHIP_ERROR BLEManagerImpl::StartAdvertising(void) CHIP_ERROR BLEManagerImpl::StopAdvertising(void) { - CHIP_ERROR err = CHIP_NO_ERROR; - gecko_msg_le_gap_stop_advertising_rsp_t *rsp; + CHIP_ERROR err = CHIP_NO_ERROR; + gecko_msg_le_gap_stop_advertising_rsp_t * rsp; if (GetFlag(mFlags, kFlag_Advertising)) { @@ -685,10 +654,10 @@ CHIP_ERROR BLEManagerImpl::StopAdvertising(void) return err; } -void BLEManagerImpl::UpdateMtu(volatile struct gecko_cmd_packet *evt) +void BLEManagerImpl::UpdateMtu(volatile struct gecko_cmd_packet * evt) { - CHIPoBLEConState *bleConnState = GetConnectionState(evt->data.evt_gatt_mtu_exchanged.connection); - bleConnState->mtu = evt->data.evt_gatt_mtu_exchanged.mtu; + CHIPoBLEConState * bleConnState = GetConnectionState(evt->data.evt_gatt_mtu_exchanged.connection); + bleConnState->mtu = evt->data.evt_gatt_mtu_exchanged.mtu; ; } @@ -698,11 +667,11 @@ void BLEManagerImpl::HandleBootEvent(void) PlatformMgr().ScheduleWork(DriveBLEState, 0); } -void BLEManagerImpl::HandleConnectEvent(volatile struct gecko_cmd_packet *evt) +void BLEManagerImpl::HandleConnectEvent(volatile struct gecko_cmd_packet * evt) { - struct gecko_msg_le_connection_opened_evt_t *conn_evt = (struct gecko_msg_le_connection_opened_evt_t *)&(evt->data); - uint8_t connHandle = conn_evt->connection; - uint8_t bondingHandle = conn_evt->bonding; + struct gecko_msg_le_connection_opened_evt_t * conn_evt = (struct gecko_msg_le_connection_opened_evt_t *) &(evt->data); + uint8_t connHandle = conn_evt->connection; + uint8_t bondingHandle = conn_evt->bonding; ChipLogProgress(DeviceLayer, "Connect Event for handle : %d", connHandle); @@ -712,17 +681,17 @@ void BLEManagerImpl::HandleConnectEvent(volatile struct gecko_cmd_packet *evt) PlatformMgr().ScheduleWork(DriveBLEState, 0); } -void BLEManagerImpl::HandleConnectionCloseEvent(volatile struct gecko_cmd_packet *evt) +void BLEManagerImpl::HandleConnectionCloseEvent(volatile struct gecko_cmd_packet * evt) { - struct gecko_msg_le_connection_closed_evt_t *conn_evt = (struct gecko_msg_le_connection_closed_evt_t *)&(evt->data); - uint8_t connHandle = conn_evt->connection; + struct gecko_msg_le_connection_closed_evt_t * conn_evt = (struct gecko_msg_le_connection_closed_evt_t *) &(evt->data); + uint8_t connHandle = conn_evt->connection; ChipLogProgress(DeviceLayer, "Disconnect Event for handle : %d", connHandle); if (RemoveConnection(connHandle)) { ChipDeviceEvent event; - event.Type = DeviceEventType::kCHIPoBLEConnectionError; + event.Type = DeviceEventType::kCHIPoBLEConnectionError; event.CHIPoBLEConnectionError.ConId = connHandle; switch (conn_evt->reason) @@ -753,9 +722,9 @@ void BLEManagerImpl::HandleConnectionCloseEvent(volatile struct gecko_cmd_packet } } -void BLEManagerImpl::HandleWriteEvent(volatile struct gecko_cmd_packet *evt) +void BLEManagerImpl::HandleWriteEvent(volatile struct gecko_cmd_packet * evt) { - struct gecko_msg_gatt_server_read_attribute_type_rsp_t *rsp; + struct gecko_msg_gatt_server_read_attribute_type_rsp_t * rsp; uint16_t attribute = evt->data.evt_gatt_server_user_write_request.characteristic; ChipLogProgress(DeviceLayer, "Char Write Req, char : %d", attribute); @@ -766,11 +735,11 @@ void BLEManagerImpl::HandleWriteEvent(volatile struct gecko_cmd_packet *evt) } } -void BLEManagerImpl::HandleTXCharCCCDWrite(volatile struct gecko_cmd_packet *evt) +void BLEManagerImpl::HandleTXCharCCCDWrite(volatile struct gecko_cmd_packet * evt) { - CHIP_ERROR err = CHIP_NO_ERROR; - CHIPoBLEConState * bleConnState; - bool indicationsEnabled; + CHIP_ERROR err = CHIP_NO_ERROR; + CHIPoBLEConState * bleConnState; + bool indicationsEnabled; ChipDeviceEvent event; bleConnState = GetConnectionState(evt->data.evt_gatt_server_user_write_request.connection); @@ -791,7 +760,7 @@ void BLEManagerImpl::HandleTXCharCCCDWrite(volatile struct gecko_cmd_packet *evt // Post an event to the CHIP queue to process either a CHIPoBLE Subscribe or Unsubscribe based on // whether the client is enabling or disabling indications. { - event.Type = DeviceEventType::kCHIPoBLESubscribe; + event.Type = DeviceEventType::kCHIPoBLESubscribe; event.CHIPoBLESubscribe.ConId = evt->data.evt_gatt_server_user_write_request.connection; PlatformMgr().PostEvent(&event); } @@ -799,8 +768,8 @@ void BLEManagerImpl::HandleTXCharCCCDWrite(volatile struct gecko_cmd_packet *evt } else { - bleConnState->subscribed = 0; - event.Type = DeviceEventType::kCHIPoBLEUnsubscribe; + bleConnState->subscribed = 0; + event.Type = DeviceEventType::kCHIPoBLEUnsubscribe; event.CHIPoBLESubscribe.ConId = evt->data.evt_gatt_server_user_write_request.connection; PlatformMgr().PostEvent(&event); } @@ -812,12 +781,12 @@ void BLEManagerImpl::HandleTXCharCCCDWrite(volatile struct gecko_cmd_packet *evt } } -void BLEManagerImpl::HandleRXCharWrite(volatile struct gecko_cmd_packet *evt) +void BLEManagerImpl::HandleRXCharWrite(volatile struct gecko_cmd_packet * evt) { - CHIP_ERROR err = CHIP_NO_ERROR; - PacketBuffer *buf; - uint16_t writeLen = evt->data.evt_gatt_server_user_write_request.value.len; - uint8_t * data = (uint8_t *)evt->data.evt_gatt_server_user_write_request.value.data; + CHIP_ERROR err = CHIP_NO_ERROR; + PacketBuffer * buf; + uint16_t writeLen = evt->data.evt_gatt_server_user_write_request.value.len; + uint8_t * data = (uint8_t *) evt->data.evt_gatt_server_user_write_request.value.data; // Copy the data to a PacketBuffer. buf = PacketBuffer::New(0); @@ -826,14 +795,13 @@ void BLEManagerImpl::HandleRXCharWrite(volatile struct gecko_cmd_packet *evt) memcpy(buf->Start(), data, writeLen); buf->SetDataLength(writeLen); - ChipLogDetail(DeviceLayer, - "Write request/command received for CHIPoBLE RX characteristic (con %" PRIu16 ", len %" PRIu16 ")", - evt->data.evt_gatt_server_user_write_request.connection, buf->DataLength()); + ChipLogDetail(DeviceLayer, "Write request/command received for CHIPoBLE RX characteristic (con %" PRIu16 ", len %" PRIu16 ")", + evt->data.evt_gatt_server_user_write_request.connection, buf->DataLength()); // Post an event to the CHIP queue to deliver the data into the CHIP stack. { ChipDeviceEvent event; - event.Type = DeviceEventType::kCHIPoBLEWriteReceived; + event.Type = DeviceEventType::kCHIPoBLEWriteReceived; event.CHIPoBLEWriteReceived.ConId = evt->data.evt_gatt_server_user_write_request.connection; event.CHIPoBLEWriteReceived.Data = buf; PlatformMgr().PostEvent(&event); @@ -848,10 +816,10 @@ void BLEManagerImpl::HandleRXCharWrite(volatile struct gecko_cmd_packet *evt) PacketBuffer::Free(buf); } -void BLEManagerImpl::HandleTxConfirmationEvent(volatile struct gecko_cmd_packet *evt) +void BLEManagerImpl::HandleTxConfirmationEvent(volatile struct gecko_cmd_packet * evt) { ChipDeviceEvent event; - uint8_t timerHandle = sInstance.GetTimerHandle(evt->data.evt_gatt_server_characteristic_status.connection); + uint8_t timerHandle = sInstance.GetTimerHandle(evt->data.evt_gatt_server_characteristic_status.connection); ChipLogProgress(DeviceLayer, "Tx Confirmation received"); @@ -863,12 +831,12 @@ void BLEManagerImpl::HandleTxConfirmationEvent(volatile struct gecko_cmd_packet gecko_cmd_hardware_set_soft_timer(0, timerHandle, false); } - event.Type = DeviceEventType::kCHIPoBLEIndicateConfirm; + event.Type = DeviceEventType::kCHIPoBLEIndicateConfirm; event.CHIPoBLEIndicateConfirm.ConId = evt->data.evt_gatt_server_characteristic_status.connection; PlatformMgr().PostEvent(&event); } -void BLEManagerImpl::HandleSoftTimerEvent(volatile struct gecko_cmd_packet *evt) +void BLEManagerImpl::HandleSoftTimerEvent(volatile struct gecko_cmd_packet * evt) { // BLE Manager starts soft timers with timer handles less than kMaxConnections // If we receive a callback for unknown timer handle ignore this. @@ -876,18 +844,18 @@ void BLEManagerImpl::HandleSoftTimerEvent(volatile struct gecko_cmd_packet *evt) { ChipLogProgress(DeviceLayer, "BLEManagerImpl::HandleSoftTimerEvent CHIPOBLE_PROTOCOL_ABORT"); ChipDeviceEvent event; - event.Type = DeviceEventType::kCHIPoBLEConnectionError; - event.CHIPoBLEConnectionError.ConId = mIndConfId[evt->data.evt_hardware_soft_timer.handle]; + event.Type = DeviceEventType::kCHIPoBLEConnectionError; + event.CHIPoBLEConnectionError.ConId = mIndConfId[evt->data.evt_hardware_soft_timer.handle]; sInstance.mIndConfId[evt->data.evt_hardware_soft_timer.handle] = kUnusedIndex; - event.CHIPoBLEConnectionError.Reason = BLE_ERROR_CHIPOBLE_PROTOCOL_ABORT; + event.CHIPoBLEConnectionError.Reason = BLE_ERROR_CHIPOBLE_PROTOCOL_ABORT; PlatformMgr().PostEvent(&event); } } bool BLEManagerImpl::RemoveConnection(uint8_t connectionHandle) { - CHIPoBLEConState *bleConnState = GetConnectionState(connectionHandle, true); - bool status = false; + CHIPoBLEConState * bleConnState = GetConnectionState(connectionHandle, true); + bool status = false; if (bleConnState != NULL) { @@ -900,7 +868,7 @@ bool BLEManagerImpl::RemoveConnection(uint8_t connectionHandle) void BLEManagerImpl::AddConnection(uint8_t connectionHandle, uint8_t bondingHandle) { - CHIPoBLEConState *bleConnState = GetConnectionState(connectionHandle, true); + CHIPoBLEConState * bleConnState = GetConnectionState(connectionHandle, true); if (bleConnState != NULL) { @@ -911,7 +879,7 @@ void BLEManagerImpl::AddConnection(uint8_t connectionHandle, uint8_t bondingHand } } -BLEManagerImpl::CHIPoBLEConState *BLEManagerImpl::GetConnectionState(uint8_t connectionHandle, bool allocate) +BLEManagerImpl::CHIPoBLEConState * BLEManagerImpl::GetConnectionState(uint8_t connectionHandle, bool allocate) { uint8_t freeIndex = kMaxConnections; diff --git a/src/platform/EFR32/ConfigurationManagerImpl.cpp b/src/platform/EFR32/ConfigurationManagerImpl.cpp index 824a8940c37577..9fc6aa8a58645a 100644 --- a/src/platform/EFR32/ConfigurationManagerImpl.cpp +++ b/src/platform/EFR32/ConfigurationManagerImpl.cpp @@ -50,7 +50,7 @@ ConfigurationManagerImpl ConfigurationManagerImpl::sInstance; CHIP_ERROR ConfigurationManagerImpl::_Init() { CHIP_ERROR err; - bool failSafeArmed; + bool failSafeArmed; // Initialize the generic implementation base class. err = Internal::GenericConfigurationManagerImpl::_Init(); @@ -72,7 +72,7 @@ CHIP_ERROR ConfigurationManagerImpl::_Init() return err; } -::chip::Profiles::Security::AppKeys::GroupKeyStoreBase *ConfigurationManagerImpl::_GetGroupKeyStore() +::chip::Profiles::Security::AppKeys::GroupKeyStoreBase * ConfigurationManagerImpl::_GetGroupKeyStore() { return &gGroupKeyStore; } @@ -88,9 +88,8 @@ void ConfigurationManagerImpl::_InitiateFactoryReset() PlatformMgr().ScheduleWork(DoFactoryReset); } -CHIP_ERROR ConfigurationManagerImpl::_ReadPersistedStorageValue( - ::chip::Platform::PersistedStorage::Key persistedStorageKey, - uint32_t & value) +CHIP_ERROR ConfigurationManagerImpl::_ReadPersistedStorageValue(::chip::Platform::PersistedStorage::Key persistedStorageKey, + uint32_t & value) { // This method reads CHIP Persisted Counter type nvm3 objects. // (where persistedStorageKey represents an index to the counter). @@ -107,9 +106,8 @@ CHIP_ERROR ConfigurationManagerImpl::_ReadPersistedStorageValue( return err; } -CHIP_ERROR ConfigurationManagerImpl::_WritePersistedStorageValue( - ::chip::Platform::PersistedStorage::Key persistedStorageKey, - uint32_t value) +CHIP_ERROR ConfigurationManagerImpl::_WritePersistedStorageValue(::chip::Platform::PersistedStorage::Key persistedStorageKey, + uint32_t value) { // This method reads CHIP Persisted Counter type nvm3 objects. // (where persistedStorageKey represents an index to the counter). diff --git a/src/platform/EFR32/ConnectivityManagerImpl.cpp b/src/platform/EFR32/ConnectivityManagerImpl.cpp index 50854fb58f375e..c8f48c7aeaf1ff 100644 --- a/src/platform/EFR32/ConnectivityManagerImpl.cpp +++ b/src/platform/EFR32/ConnectivityManagerImpl.cpp @@ -61,7 +61,7 @@ CHIP_ERROR ConnectivityManagerImpl::_Init() return err; } -void ConnectivityManagerImpl::_OnPlatformEvent(const ChipDeviceEvent *event) +void ConnectivityManagerImpl::_OnPlatformEvent(const ChipDeviceEvent * event) { // Forward the event to the generic base classes as needed. #if CHIP_DEVICE_CONFIG_ENABLE_THREAD diff --git a/src/platform/EFR32/EFR32Config.cpp b/src/platform/EFR32/EFR32Config.cpp index 2a6450059f0c84..659e8481d9dce9 100644 --- a/src/platform/EFR32/EFR32Config.cpp +++ b/src/platform/EFR32/EFR32Config.cpp @@ -43,20 +43,20 @@ namespace Internal { // by nvm3_open() on alignment or size violation. // Local version of SDK macro (avoids uninitialized var compile error). -#define CHIP_NVM3_DEFINE_SECTION_STATIC_DATA(name, nvmSize, cacheSize) \ - static nvm3_CacheEntry_t name##_cache[cacheSize]; \ - static uint8_t name##_nvm[nvmSize] SL_ATTRIBUTE_SECTION(STRINGIZE(name##_section)) +#define CHIP_NVM3_DEFINE_SECTION_STATIC_DATA(name, nvmSize, cacheSize) \ + static nvm3_CacheEntry_t name##_cache[cacheSize]; \ + static uint8_t name##_nvm[nvmSize] SL_ATTRIBUTE_SECTION(STRINGIZE(name##_section)) // Local version of SDK macro (allows CHIP to configure the maximum nvm3 object size and headroom). -#define CHIP_NVM3_DEFINE_SECTION_INIT_DATA(name, maxObjectSize, repackHeadroom) \ - static nvm3_Init_t name = { \ - (nvm3_HalPtr_t)name##_nvm, \ - sizeof(name##_nvm), \ - name##_cache, \ - sizeof(name##_cache) / sizeof(nvm3_CacheEntry_t), \ - maxObjectSize, \ - repackHeadroom, \ - &nvm3_halFlashHandle, \ +#define CHIP_NVM3_DEFINE_SECTION_INIT_DATA(name, maxObjectSize, repackHeadroom) \ + static nvm3_Init_t name = { \ + (nvm3_HalPtr_t) name##_nvm, \ + sizeof(name##_nvm), \ + name##_cache, \ + sizeof(name##_cache) / sizeof(nvm3_CacheEntry_t), \ + maxObjectSize, \ + repackHeadroom, \ + &nvm3_halFlashHandle, \ } #define CHIP_NVM3_REPACK_HEADROOM 64 // Threshold for User non-forced nvm3 flash repacking. @@ -65,16 +65,15 @@ static nvm3_Handle_t handle; // Declare NVM3 data area and cache. -CHIP_NVM3_DEFINE_SECTION_STATIC_DATA(chipNvm3, - CHIP_DEVICE_CONFIG_NVM3_NUM_FLASH_PAGES_FOR_STORAGE *FLASH_PAGE_SIZE, - CHIP_DEVICE_CONFIG_NVM3_MAX_NUM_OBJECTS); +CHIP_NVM3_DEFINE_SECTION_STATIC_DATA(chipNvm3, CHIP_DEVICE_CONFIG_NVM3_NUM_FLASH_PAGES_FOR_STORAGE * FLASH_PAGE_SIZE, + CHIP_DEVICE_CONFIG_NVM3_MAX_NUM_OBJECTS); CHIP_NVM3_DEFINE_SECTION_INIT_DATA(chipNvm3, CHIP_DEVICE_CONFIG_NVM3_MAX_OBJECT_SIZE, CHIP_NVM3_REPACK_HEADROOM); CHIP_ERROR EFR32Config::Init() { CHIP_ERROR err; - bool needClose = false; + bool needClose = false; err = MapNvm3Error(nvm3_open(&handle, &chipNvm3)); SuccessOrExit(err); @@ -89,13 +88,13 @@ CHIP_ERROR EFR32Config::Init() return err; } -CHIP_ERROR EFR32Config::ReadConfigValue(Key key, bool &val) +CHIP_ERROR EFR32Config::ReadConfigValue(Key key, bool & val) { CHIP_ERROR err; - bool needClose = false; - uint32_t objectType; - size_t dataLen; - bool tmpVal; + bool needClose = false; + uint32_t objectType; + size_t dataLen; + bool tmpVal; VerifyOrExit(ValidConfigKey(key), err = CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND); // Verify key id. @@ -120,13 +119,13 @@ CHIP_ERROR EFR32Config::ReadConfigValue(Key key, bool &val) return err; } -CHIP_ERROR EFR32Config::ReadConfigValue(Key key, uint32_t &val) +CHIP_ERROR EFR32Config::ReadConfigValue(Key key, uint32_t & val) { CHIP_ERROR err; - bool needClose = false; - uint32_t objectType; - size_t dataLen; - uint32_t tmpVal; + bool needClose = false; + uint32_t objectType; + size_t dataLen; + uint32_t tmpVal; VerifyOrExit(ValidConfigKey(key), err = CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND); // Verify key id. @@ -151,13 +150,13 @@ CHIP_ERROR EFR32Config::ReadConfigValue(Key key, uint32_t &val) return err; } -CHIP_ERROR EFR32Config::ReadConfigValue(Key key, uint64_t &val) +CHIP_ERROR EFR32Config::ReadConfigValue(Key key, uint64_t & val) { CHIP_ERROR err; - bool needClose = false; - uint32_t objectType; - size_t dataLen; - uint64_t tmpVal; + bool needClose = false; + uint32_t objectType; + size_t dataLen; + uint64_t tmpVal; VerifyOrExit(ValidConfigKey(key), err = CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND); // Verify key id. @@ -182,12 +181,12 @@ CHIP_ERROR EFR32Config::ReadConfigValue(Key key, uint64_t &val) return err; } -CHIP_ERROR EFR32Config::ReadConfigValueStr(Key key, char *buf, size_t bufSize, size_t &outLen) +CHIP_ERROR EFR32Config::ReadConfigValueStr(Key key, char * buf, size_t bufSize, size_t & outLen) { CHIP_ERROR err; - bool needClose = false; - uint32_t objectType; - size_t dataLen; + bool needClose = false; + uint32_t objectType; + size_t dataLen; outLen = 0; @@ -240,12 +239,12 @@ CHIP_ERROR EFR32Config::ReadConfigValueStr(Key key, char *buf, size_t bufSize, s return err; } -CHIP_ERROR EFR32Config::ReadConfigValueBin(Key key, uint8_t *buf, size_t bufSize, size_t &outLen) +CHIP_ERROR EFR32Config::ReadConfigValueBin(Key key, uint8_t * buf, size_t bufSize, size_t & outLen) { CHIP_ERROR err; - bool needClose = false; - uint32_t objectType; - size_t dataLen; + bool needClose = false; + uint32_t objectType; + size_t dataLen; outLen = 0; @@ -280,11 +279,11 @@ CHIP_ERROR EFR32Config::ReadConfigValueBin(Key key, uint8_t *buf, size_t bufSize return err; } -CHIP_ERROR EFR32Config::ReadConfigValueCounter(uint8_t counterIdx, uint32_t &val) +CHIP_ERROR EFR32Config::ReadConfigValueCounter(uint8_t counterIdx, uint32_t & val) { CHIP_ERROR err; - bool needClose = false; - uint32_t tmpVal; + bool needClose = false; + uint32_t tmpVal; Key key = kMinConfigKey_ChipCounter + counterIdx; VerifyOrExit(ValidConfigKey(key), err = CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND); // Verify key id. @@ -309,7 +308,7 @@ CHIP_ERROR EFR32Config::ReadConfigValueCounter(uint8_t counterIdx, uint32_t &val CHIP_ERROR EFR32Config::WriteConfigValue(Key key, bool val) { CHIP_ERROR err; - bool needClose = false; + bool needClose = false; VerifyOrExit(ValidConfigKey(key), err = CHIP_ERROR_INVALID_ARGUMENT); // Verify key id. @@ -331,7 +330,7 @@ CHIP_ERROR EFR32Config::WriteConfigValue(Key key, bool val) CHIP_ERROR EFR32Config::WriteConfigValue(Key key, uint32_t val) { CHIP_ERROR err; - bool needClose = false; + bool needClose = false; VerifyOrExit(ValidConfigKey(key), err = CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND); // Verify key id. @@ -353,7 +352,7 @@ CHIP_ERROR EFR32Config::WriteConfigValue(Key key, uint32_t val) CHIP_ERROR EFR32Config::WriteConfigValue(Key key, uint64_t val) { CHIP_ERROR err; - bool needClose = false; + bool needClose = false; VerifyOrExit(ValidConfigKey(key), err = CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND); // Verify key id. @@ -372,15 +371,15 @@ CHIP_ERROR EFR32Config::WriteConfigValue(Key key, uint64_t val) return err; } -CHIP_ERROR EFR32Config::WriteConfigValueStr(Key key, const char *str) +CHIP_ERROR EFR32Config::WriteConfigValueStr(Key key, const char * str) { return WriteConfigValueStr(key, str, (str != NULL) ? strlen(str) : 0); } -CHIP_ERROR EFR32Config::WriteConfigValueStr(Key key, const char *str, size_t strLen) +CHIP_ERROR EFR32Config::WriteConfigValueStr(Key key, const char * str, size_t strLen) { CHIP_ERROR err; - bool needClose = false; + bool needClose = false; VerifyOrExit(ValidConfigKey(key), err = CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND); // Verify key id. @@ -409,10 +408,10 @@ CHIP_ERROR EFR32Config::WriteConfigValueStr(Key key, const char *str, size_t str return err; } -CHIP_ERROR EFR32Config::WriteConfigValueBin(Key key, const uint8_t *data, size_t dataLen) +CHIP_ERROR EFR32Config::WriteConfigValueBin(Key key, const uint8_t * data, size_t dataLen) { CHIP_ERROR err; - bool needClose = false; + bool needClose = false; VerifyOrExit(ValidConfigKey(key), err = CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND); // Verify key id. @@ -445,7 +444,7 @@ CHIP_ERROR EFR32Config::WriteConfigValueBin(Key key, const uint8_t *data, size_t CHIP_ERROR EFR32Config::WriteConfigValueCounter(uint8_t counterIdx, uint32_t val) { CHIP_ERROR err; - bool needClose = false; + bool needClose = false; Key key = kMinConfigKey_ChipCounter + counterIdx; VerifyOrExit(ValidConfigKey(key), err = CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND); // Verify key id. @@ -468,7 +467,7 @@ CHIP_ERROR EFR32Config::WriteConfigValueCounter(uint8_t counterIdx, uint32_t val CHIP_ERROR EFR32Config::ClearConfigValue(Key key) { CHIP_ERROR err; - bool needClose = false; + bool needClose = false; err = MapNvm3Error(nvm3_open(&handle, &chipNvm3)); SuccessOrExit(err); @@ -489,9 +488,9 @@ CHIP_ERROR EFR32Config::ClearConfigValue(Key key) bool EFR32Config::ConfigValueExists(Key key) { CHIP_ERROR err; - bool needClose = false; - uint32_t objectType; - size_t dataLen; + bool needClose = false; + uint32_t objectType; + size_t dataLen; err = MapNvm3Error(nvm3_open(&handle, &chipNvm3)); SuccessOrExit(err); @@ -517,7 +516,7 @@ CHIP_ERROR EFR32Config::FactoryResetConfig(void) // Iterate over all the CHIP Config nvm3 records and delete each one... err = ForEachRecord(kMinConfigKey_ChipConfig, kMaxConfigKey_ChipConfig, false, - [](const Key &nvm3Key, const size_t &length) -> CHIP_ERROR { + [](const Key & nvm3Key, const size_t & length) -> CHIP_ERROR { CHIP_ERROR err2; err2 = ClearConfigValue(nvm3Key); @@ -565,9 +564,9 @@ CHIP_ERROR EFR32Config::ForEachRecord(Key firstNvm3Key, Key lastNvm3Key, bool ad for (Key nvm3Key = firstNvm3Key; nvm3Key <= lastNvm3Key; ++nvm3Key) { - Ecode_t nvm3Res; + Ecode_t nvm3Res; uint32_t objectType; - size_t dataLen; + size_t dataLen; // Open nvm3 handle for reading on each iteration. err = MapNvm3Error(nvm3_open(&handle, &chipNvm3)); diff --git a/src/platform/EFR32/Logging.cpp b/src/platform/EFR32/Logging.cpp index 2cb50bbb97bf69..a4e29960aee36d 100644 --- a/src/platform/EFR32/Logging.cpp +++ b/src/platform/EFR32/Logging.cpp @@ -59,18 +59,17 @@ #define LOG_LWIP " " #define LOG_EFR32 " " - using namespace ::chip; using namespace ::chip::DeviceLayer; using namespace ::chip::DeviceLayer::Internal; -static bool sLogInitialized = false; -static uint8_t sLogBuffer[LOG_RTT_BUFFER_SIZE]; +static bool sLogInitialized = false; +static uint8_t sLogBuffer[LOG_RTT_BUFFER_SIZE]; /** * Print a log message to RTT */ -static void PrintLog(const char *msg) +static void PrintLog(const char * msg) { #if EFR32_LOG_ENABLED if (sLogInitialized) @@ -79,8 +78,8 @@ static void PrintLog(const char *msg) sz = strlen(msg); SEGGER_RTT_WriteNoLock(0, msg, sz); - const char *newline = "\r\n"; - sz = strlen(newline); + const char * newline = "\r\n"; + sz = strlen(newline); SEGGER_RTT_WriteNoLock(0, newline, sz); } #endif // EFR32_LOG_ENABLED @@ -103,7 +102,7 @@ extern "C" int efr32LogInit(void) /** * General-purpose logging function */ -extern "C" void efr32Log(const char *aFormat, ...) +extern "C" void efr32Log(const char * aFormat, ...) { va_list v; @@ -128,7 +127,7 @@ extern "C" void efr32Log(const char *aFormat, ...) namespace { -void GetModuleName(char *buf, uint8_t module) +void GetModuleName(char * buf, uint8_t module) { if (module == ::chip::Logging::kLogModule_DeviceLayer) { @@ -151,9 +150,7 @@ namespace DeviceLayer { * This function is intended be overridden by the application to, e.g., * schedule output of queued log entries. */ -void __attribute__((weak)) OnLogOutput(void) -{ -} +void __attribute__((weak)) OnLogOutput(void) {} } // namespace DeviceLayer } // namespace chip @@ -164,15 +161,15 @@ namespace Logging { /** * CHIP log output function. */ -void Log(uint8_t module, uint8_t category, const char *aFormat, ...) +void Log(uint8_t module, uint8_t category, const char * aFormat, ...) { - va_list v; + va_list v; va_start(v, aFormat); #if EFR32_LOG_ENABLED && _CHIP_USE_LOGGING if (IsCategoryEnabled(category)) { - char formattedMsg[CHIP_DEVICE_CONFIG_LOG_MESSAGE_MAX_SIZE]; + char formattedMsg[CHIP_DEVICE_CONFIG_LOG_MESSAGE_MAX_SIZE]; size_t formattedMsgLen; constexpr size_t maxPrefixLen = ChipLoggingModuleNameLen + 3; @@ -221,11 +218,10 @@ void Log(uint8_t module, uint8_t category, const char *aFormat, ...) } // namespace Logging } // namespace chip - /** * LwIP log output function. */ -extern "C" void LwIPLog(const char *aFormat, ...) +extern "C" void LwIPLog(const char * aFormat, ...) { va_list v; @@ -253,10 +249,10 @@ extern "C" void LwIPLog(const char *aFormat, ...) * Platform logging function for OpenThread */ #if CHIP_DEVICE_CONFIG_ENABLE_THREAD -extern "C" void otPlatLog(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat, ...) +extern "C" void otPlatLog(otLogLevel aLogLevel, otLogRegion aLogRegion, const char * aFormat, ...) { IgnoreUnusedVariable(aLogRegion); - va_list v; + va_list v; va_start(v, aFormat); #if EFR32_LOG_ENABLED @@ -309,21 +305,21 @@ extern "C" void otPlatLog(otLogLevel aLogLevel, otLogRegion aLogRegion, const ch /** * Log register contents to UART when a hard fault occurs. */ -extern "C" void debugHardfault(uint32_t *sp) +extern "C" void debugHardfault(uint32_t * sp) { uint32_t cfsr = SCB->CFSR; uint32_t hfsr = SCB->HFSR; uint32_t mmfar = SCB->MMFAR; uint32_t bfar = SCB->BFAR; - uint32_t r0 = sp[0]; - uint32_t r1 = sp[1]; - uint32_t r2 = sp[2]; - uint32_t r3 = sp[3]; - uint32_t r12 = sp[4]; - uint32_t lr = sp[5]; - uint32_t pc = sp[6]; - uint32_t psr = sp[7]; - char formattedMsg[32]; + uint32_t r0 = sp[0]; + uint32_t r1 = sp[1]; + uint32_t r2 = sp[2]; + uint32_t r3 = sp[3]; + uint32_t r12 = sp[4]; + uint32_t lr = sp[5]; + uint32_t pc = sp[6]; + uint32_t psr = sp[7]; + char formattedMsg[32]; if (sLogInitialized == false) { @@ -340,7 +336,7 @@ extern "C" void debugHardfault(uint32_t *sp) PrintLog(formattedMsg); snprintf(formattedMsg, sizeof formattedMsg, "SCB->BFAR 0x%08lx", bfar); PrintLog(formattedMsg); - snprintf(formattedMsg, sizeof formattedMsg, "SP 0x%08lx", (uint32_t)sp); + snprintf(formattedMsg, sizeof formattedMsg, "SP 0x%08lx", (uint32_t) sp); PrintLog(formattedMsg); snprintf(formattedMsg, sizeof formattedMsg, "R0 0x%08lx\n", r0); PrintLog(formattedMsg); diff --git a/src/platform/EFR32/NetworkProvisioningServerImpl.cpp b/src/platform/EFR32/NetworkProvisioningServerImpl.cpp index 876289ee7209b6..7b5de51b64b6c0 100644 --- a/src/platform/EFR32/NetworkProvisioningServerImpl.cpp +++ b/src/platform/EFR32/NetworkProvisioningServerImpl.cpp @@ -25,7 +25,6 @@ #include - namespace chip { namespace DeviceLayer { namespace Internal { diff --git a/src/platform/EFR32/ThreadStackManagerImpl.cpp b/src/platform/EFR32/ThreadStackManagerImpl.cpp index ff36584fd43ae6..dbe2c7fb7444d7 100644 --- a/src/platform/EFR32/ThreadStackManagerImpl.cpp +++ b/src/platform/EFR32/ThreadStackManagerImpl.cpp @@ -43,7 +43,7 @@ CHIP_ERROR ThreadStackManagerImpl::_InitThreadStack(void) return InitThreadStack(NULL); } -CHIP_ERROR ThreadStackManagerImpl::InitThreadStack(otInstance *otInst) +CHIP_ERROR ThreadStackManagerImpl::InitThreadStack(otInstance * otInst) { CHIP_ERROR err = CHIP_NO_ERROR; @@ -71,7 +71,7 @@ using namespace ::chip::DeviceLayer; * Glue function called directly by the OpenThread stack when tasklet processing work * is pending. */ -extern "C" void otTaskletsSignalPending(otInstance *p_instance) +extern "C" void otTaskletsSignalPending(otInstance * p_instance) { ThreadStackMgrImpl().SignalThreadActivityPending(); } diff --git a/src/platform/EFR32/freertos_bluetooth.c b/src/platform/EFR32/freertos_bluetooth.c index 3f24564b741349..cf0873174c295f 100644 --- a/src/platform/EFR32/freertos_bluetooth.c +++ b/src/platform/EFR32/freertos_bluetooth.c @@ -29,26 +29,26 @@ #include CONFIGURATION_HEADER #endif // CONFIGURATION_HEADER -void BluetoothUpdate(); -volatile struct gecko_cmd_packet *bluetooth_evt; -SemaphoreHandle_t BluetoothMutex = NULL; +void BluetoothUpdate(); +volatile struct gecko_cmd_packet * bluetooth_evt; +SemaphoreHandle_t BluetoothMutex = NULL; -volatile static uint32_t command_header; -volatile static void * command_data; +volatile static uint32_t command_header; +volatile static void * command_data; volatile static gecko_cmd_handler command_handler_func = NULL; // Bluetooth task #ifndef BLUETOOTH_STACK_SIZE #define BLUETOOTH_STACK_SIZE (2048) #endif -static void BluetoothTask(void *p_arg); +static void BluetoothTask(void * p_arg); static TaskHandle_t BluetoothTaskHandle = NULL; // Linklayer task #ifndef LINKLAYER_STACK_SIZE #define LINKLAYER_STACK_SIZE (2048) #endif -static void LinklayerTask(void *p_arg); +static void LinklayerTask(void * p_arg); static TaskHandle_t LinklayerTaskHandle = NULL; // #define RTOS_TICK_HZ 1024 @@ -59,12 +59,11 @@ static volatile wakeupCallback wakeupCB = NULL; // Set the task to post semaphore void BluetoothSetWakeupCallback(wakeupCallback cb) { - wakeupCB = (volatile wakeupCallback)cb; + wakeupCB = (volatile wakeupCallback) cb; } EventGroupHandle_t bluetooth_event_flags; -errorcode_t bluetooth_start(UBaseType_t ll_priority, - UBaseType_t stack_priority, +errorcode_t bluetooth_start(UBaseType_t ll_priority, UBaseType_t stack_priority, bluetooth_stack_init_func initialize_bluetooth_stack) { errorcode_t err; @@ -102,10 +101,9 @@ errorcode_t bluetooth_start(UBaseType_t ll_priority, void BluetoothLLCallback() { EventBits_t eventBits; - BaseType_t pxHigherPriorityTaskWoken = pdFALSE; - eventBits = - vRaiseEventFlagBasedOnContext(bluetooth_event_flags, BLUETOOTH_EVENT_FLAG_LL, &pxHigherPriorityTaskWoken); - (void)eventBits; + BaseType_t pxHigherPriorityTaskWoken = pdFALSE; + eventBits = vRaiseEventFlagBasedOnContext(bluetooth_event_flags, BLUETOOTH_EVENT_FLAG_LL, &pxHigherPriorityTaskWoken); + (void) eventBits; } // This callback is called from Bluetooth stack // Called from kernel aware interrupt context (RTCC interrupt) and from Bluetooth task @@ -113,30 +111,29 @@ void BluetoothLLCallback() void BluetoothUpdate() { EventBits_t eventBits; - BaseType_t pxHigherPriorityTaskWoken = pdFALSE; - eventBits = - vRaiseEventFlagBasedOnContext(bluetooth_event_flags, BLUETOOTH_EVENT_FLAG_STACK, &pxHigherPriorityTaskWoken); - (void)eventBits; + BaseType_t pxHigherPriorityTaskWoken = pdFALSE; + eventBits = vRaiseEventFlagBasedOnContext(bluetooth_event_flags, BLUETOOTH_EVENT_FLAG_STACK, &pxHigherPriorityTaskWoken); + (void) eventBits; } // Bluetooth task, it waits for events from bluetooth and handles them -void BluetoothTask(void *p) +void BluetoothTask(void * p) { EventBits_t flags = BLUETOOTH_EVENT_FLAG_EVT_HANDLED | BLUETOOTH_EVENT_FLAG_STACK; EventBits_t eventBits; - TickType_t xTicksToWait; + TickType_t xTicksToWait; while (1) { // Command needs to be sent to Bluetooth stack if (flags & BLUETOOTH_EVENT_FLAG_CMD_WAITING) { - uint32_t header = command_header; + uint32_t header = command_header; gecko_cmd_handler cmd_handler = command_handler_func; - sli_bt_cmd_handler_delegate(header, cmd_handler, (void *)command_data); + sli_bt_cmd_handler_delegate(header, cmd_handler, (void *) command_data); command_handler_func = NULL; flags &= ~BLUETOOTH_EVENT_FLAG_CMD_WAITING; eventBits = vRaiseEventFlagBasedOnContext(bluetooth_event_flags, BLUETOOTH_EVENT_FLAG_RSP_WAITING, NULL); - (void)eventBits; + (void) eventBits; } // Bluetooth stack needs updating, and evt can be used @@ -145,9 +142,8 @@ void BluetoothTask(void *p) bluetooth_evt = gecko_wait_event(); if (bluetooth_evt != NULL) { // we got event, notify event handler. evt state is now waiting handling - eventBits = - vRaiseEventFlagBasedOnContext(bluetooth_event_flags, BLUETOOTH_EVENT_FLAG_EVT_WAITING, NULL); - (void)eventBits; + eventBits = vRaiseEventFlagBasedOnContext(bluetooth_event_flags, BLUETOOTH_EVENT_FLAG_EVT_WAITING, NULL); + (void) eventBits; flags &= ~(BLUETOOTH_EVENT_FLAG_EVT_HANDLED); if (wakeupCB != NULL) { @@ -183,14 +179,13 @@ void BluetoothTask(void *p) // round up to RTOS ticks xTicksToWait = timeout / portTICK_PERIOD_MS; } - flags |= - xEventGroupWaitBits(bluetooth_event_flags, /* The event group being tested. */ - (BLUETOOTH_EVENT_FLAG_STACK + BLUETOOTH_EVENT_FLAG_EVT_HANDLED + - BLUETOOTH_EVENT_FLAG_CMD_WAITING), /* The bits within the event group to wait for. */ - pdTRUE, /* BLUETOOTH_EVENT_FLAG_LL should be cleared before returning. */ - pdFALSE, /* Wait for all the bits to be set, not needed for single bit. */ - xTicksToWait); /* Wait for maximum duration for bit to be set. With 1 ms tick, - portMAX_DELAY will result in wait of 50 days*/ + flags |= xEventGroupWaitBits(bluetooth_event_flags, /* The event group being tested. */ + (BLUETOOTH_EVENT_FLAG_STACK + BLUETOOTH_EVENT_FLAG_EVT_HANDLED + + BLUETOOTH_EVENT_FLAG_CMD_WAITING), /* The bits within the event group to wait for. */ + pdTRUE, /* BLUETOOTH_EVENT_FLAG_LL should be cleared before returning. */ + pdFALSE, /* Wait for all the bits to be set, not needed for single bit. */ + xTicksToWait); /* Wait for maximum duration for bit to be set. With 1 ms tick, + portMAX_DELAY will result in wait of 50 days*/ if (((flags & BLUETOOTH_EVENT_FLAG_STACK) == 0) && ((flags & BLUETOOTH_EVENT_FLAG_EVT_HANDLED) == 0) && ((flags & BLUETOOTH_EVENT_FLAG_CMD_WAITING) == 0)) @@ -201,9 +196,9 @@ void BluetoothTask(void *p) } } -static void LinklayerTask(void *p_arg) +static void LinklayerTask(void * p_arg) { - (void)p_arg; + (void) p_arg; while (1) { @@ -211,10 +206,10 @@ static void LinklayerTask(void *p_arg) uxBits = xEventGroupWaitBits(bluetooth_event_flags, /* The event group being tested. */ BLUETOOTH_EVENT_FLAG_LL, /* The bits within the event group to wait for. */ - pdTRUE, /* BLUETOOTH_EVENT_FLAG_LL should be cleared before returning. */ - pdTRUE, /* Wait for all the bits to be set, not needed for single bit. */ - portMAX_DELAY); /* Wait for maximum duration for bit to be set. With 1 ms tick, - portMAX_DELAY will result in wait of 50 days*/ + pdTRUE, /* BLUETOOTH_EVENT_FLAG_LL should be cleared before returning. */ + pdTRUE, /* Wait for all the bits to be set, not needed for single bit. */ + portMAX_DELAY); /* Wait for maximum duration for bit to be set. With 1 ms tick, + portMAX_DELAY will result in wait of 50 days*/ if (uxBits & BLUETOOTH_EVENT_FLAG_LL) { @@ -225,32 +220,32 @@ static void LinklayerTask(void *p_arg) // hooks for API // called from tasks using BGAPI -void rtos_gecko_handle_command(uint32_t header, void *payload) +void rtos_gecko_handle_command(uint32_t header, void * payload) { sli_bt_cmd_handler_rtos_delegate(header, NULL, payload); } -void rtos_gecko_handle_command_noresponse(uint32_t header, void *payload) +void rtos_gecko_handle_command_noresponse(uint32_t header, void * payload) { sli_bt_cmd_handler_rtos_delegate(header, NULL, payload); } -void sli_bt_cmd_handler_rtos_delegate(uint32_t header, gecko_cmd_handler handler, const void *payload) +void sli_bt_cmd_handler_rtos_delegate(uint32_t header, gecko_cmd_handler handler, const void * payload) { EventBits_t uxBits; command_header = header; command_handler_func = handler; - command_data = (void *)payload; + command_data = (void *) payload; // Command structure is filled, notify the stack uxBits = vRaiseEventFlagBasedOnContext(bluetooth_event_flags, BLUETOOTH_EVENT_FLAG_CMD_WAITING, NULL); // wait for response uxBits = xEventGroupWaitBits(bluetooth_event_flags, /* The event group being tested. */ BLUETOOTH_EVENT_FLAG_RSP_WAITING, /* The bits within the event group to wait for. */ - pdTRUE, /* BLUETOOTH_EVENT_FLAG_LL should be cleared before returning. */ - pdTRUE, /* Wait for all the bits to be set, not needed for single bit. */ - portMAX_DELAY); /* Wait for maximum duration for bit to be set. With 1 ms tick, - portMAX_DELAY will result in wait of 50 days*/ - (void)uxBits; + pdTRUE, /* BLUETOOTH_EVENT_FLAG_LL should be cleared before returning. */ + pdTRUE, /* Wait for all the bits to be set, not needed for single bit. */ + portMAX_DELAY); /* Wait for maximum duration for bit to be set. With 1 ms tick, + portMAX_DELAY will result in wait of 50 days*/ + (void) uxBits; } void BluetoothPend(void) @@ -271,41 +266,38 @@ void vApplicationMallocFailedHook(void) configTOTAL_HEAP_SIZE configuration constant in FreeRTOSConfig.h. */ /* Force an assert. */ - configASSERT((volatile void *)NULL); + configASSERT((volatile void *) NULL); } /*-----------------------------------------------------------*/ -void vApplicationStackOverflowHook(TaskHandle_t pxTask, char *pcTaskName) +void vApplicationStackOverflowHook(TaskHandle_t pxTask, char * pcTaskName) { - (void)pcTaskName; - (void)pxTask; + (void) pcTaskName; + (void) pxTask; /* Run time stack overflow checking is performed if configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook function is called if a stack overflow is detected. */ /* Force an assert. */ - configASSERT((volatile void *)NULL); + configASSERT((volatile void *) NULL); } -void vApplicationTickHook(void) -{ -} +void vApplicationTickHook(void) {} /*-----------------------------------------------------------*/ /* configUSE_STATIC_ALLOCATION is set to 1, so the application must provide an implementation of vApplicationGetIdleTaskMemory() to provide the memory that is used by the Idle task. */ -void vApplicationGetIdleTaskMemory(StaticTask_t **ppxIdleTaskTCBBuffer, - StackType_t ** ppxIdleTaskStackBuffer, - uint32_t * pulIdleTaskStackSize) +void vApplicationGetIdleTaskMemory(StaticTask_t ** ppxIdleTaskTCBBuffer, StackType_t ** ppxIdleTaskStackBuffer, + uint32_t * pulIdleTaskStackSize) { /* If the buffers to be provided to the Idle task are declared inside this function then they must be declared static - otherwise they will be allocated on the stack and so not exists after this function exits. */ static StaticTask_t xIdleTaskTCB; - static StackType_t uxIdleTaskStack[configMINIMAL_STACK_SIZE]; + static StackType_t uxIdleTaskStack[configMINIMAL_STACK_SIZE]; /* Pass out a pointer to the StaticTask_t structure in which the Idle task's state will be stored. */ @@ -324,15 +316,14 @@ void vApplicationGetIdleTaskMemory(StaticTask_t **ppxIdleTaskTCBBuffer, /* configUSE_STATIC_ALLOCATION and configUSE_TIMERS are both set to 1, so the application must provide an implementation of vApplicationGetTimerTaskMemory() to provide the memory that is used by the Timer service task. */ -void vApplicationGetTimerTaskMemory(StaticTask_t **ppxTimerTaskTCBBuffer, - StackType_t ** ppxTimerTaskStackBuffer, - uint32_t * pulTimerTaskStackSize) +void vApplicationGetTimerTaskMemory(StaticTask_t ** ppxTimerTaskTCBBuffer, StackType_t ** ppxTimerTaskStackBuffer, + uint32_t * pulTimerTaskStackSize) { /* If the buffers to be provided to the Timer task are declared inside this function then they must be declared static - otherwise they will be allocated on the stack and so not exists after this function exits. */ static StaticTask_t xTimerTaskTCB; - static StackType_t uxTimerTaskStack[configTIMER_TASK_STACK_DEPTH]; + static StackType_t uxTimerTaskStack[configTIMER_TASK_STACK_DEPTH]; /* Pass out a pointer to the StaticTask_t structure in which the Timer task's state will be stored. */ @@ -347,12 +338,11 @@ void vApplicationGetTimerTaskMemory(StaticTask_t **ppxTimerTaskTCBBuffer, *pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH; } -EventBits_t vRaiseEventFlagBasedOnContext(EventGroupHandle_t xEventGroup, - EventBits_t uxBitsToWaitFor, - BaseType_t * pxHigherPriorityTaskWoken) +EventBits_t vRaiseEventFlagBasedOnContext(EventGroupHandle_t xEventGroup, EventBits_t uxBitsToWaitFor, + BaseType_t * pxHigherPriorityTaskWoken) { EventBits_t eventBits; - BaseType_t higherPrioTaskWoken = pdFALSE; + BaseType_t higherPrioTaskWoken = pdFALSE; if (xPortIsInsideInterrupt()) { @@ -370,10 +360,8 @@ EventBits_t vRaiseEventFlagBasedOnContext(EventGroupHandle_t xEventGroup, return eventBits; } -EventBits_t vSendToQueueBasedOnContext(QueueHandle_t xQueue, - void * xItemToQueue, - TickType_t xTicksToWait, - BaseType_t * pxHigherPriorityTaskWoken) +EventBits_t vSendToQueueBasedOnContext(QueueHandle_t xQueue, void * xItemToQueue, TickType_t xTicksToWait, + BaseType_t * pxHigherPriorityTaskWoken) { BaseType_t status; BaseType_t higherPrioTaskWoken = pdFALSE; diff --git a/src/platform/EFR32/gatt_db.c b/src/platform/EFR32/gatt_db.c index 802e56ef3955ff..dbd1c7e7f0a89b 100644 --- a/src/platform/EFR32/gatt_db.c +++ b/src/platform/EFR32/gatt_db.c @@ -25,237 +25,354 @@ #define GATT_HEADER(F) F #define GATT_DATA(F) F -GATT_DATA(const uint16_t bg_gattdb_data_uuidtable_16_map [])= -{ - 0x2800, - 0x2801, - 0x2803, - 0x1800, - 0x2a00, - 0x2a01, - 0x180a, - 0x2a29, - 0x2a24, - 0x2a23, - 0xfeaf, - 0x1801, - 0x2a05, - 0x2b2a, - 0x2b29, - 0x2902, +GATT_DATA(const uint16_t bg_gattdb_data_uuidtable_16_map[]) = { + 0x2800, 0x2801, 0x2803, 0x1800, 0x2a00, 0x2a01, 0x180a, 0x2a29, 0x2a24, 0x2a23, 0xfeaf, 0x1801, 0x2a05, 0x2b2a, 0x2b29, 0x2902, }; -GATT_DATA(const uint8_t bg_gattdb_data_uuidtable_128_map [])= -{ -0xf0, 0x19, 0x21, 0xb4, 0x47, 0x8f, 0xa4, 0xbf, 0xa1, 0x4f, 0x63, 0xfd, 0xee, 0xd6, 0x14, 0x1d, -0x63, 0x60, 0x32, 0xe0, 0x37, 0x5e, 0xa4, 0x88, 0x53, 0x4e, 0x6d, 0xfb, 0x64, 0x35, 0xbf, 0xf7, -0x11, 0x9d, 0x9f, 0x42, 0x9c, 0x4f, 0x9f, 0x95, 0x59, 0x45, 0x3d, 0x26, 0xf5, 0x2e, 0xee, 0x18, -0x12, 0x9d, 0x9f, 0x42, 0x9c, 0x4f, 0x9f, 0x95, 0x59, 0x45, 0x3d, 0x26, 0xf5, 0x2e, 0xee, 0x18, +GATT_DATA(const uint8_t bg_gattdb_data_uuidtable_128_map[]) = { + 0xf0, 0x19, 0x21, 0xb4, 0x47, 0x8f, 0xa4, 0xbf, 0xa1, 0x4f, 0x63, 0xfd, 0xee, 0xd6, 0x14, 0x1d, + 0x63, 0x60, 0x32, 0xe0, 0x37, 0x5e, 0xa4, 0x88, 0x53, 0x4e, 0x6d, 0xfb, 0x64, 0x35, 0xbf, 0xf7, + 0x11, 0x9d, 0x9f, 0x42, 0x9c, 0x4f, 0x9f, 0x95, 0x59, 0x45, 0x3d, 0x26, 0xf5, 0x2e, 0xee, 0x18, + 0x12, 0x9d, 0x9f, 0x42, 0x9c, 0x4f, 0x9f, 0x95, 0x59, 0x45, 0x3d, 0x26, 0xf5, 0x2e, 0xee, 0x18, }; - - - -struct bg_gattdb_buffer_with_len bg_gattdb_data_attribute_field_27_data = { - .len=1, - .data={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,} -}; -GATT_DATA(const struct bg_gattdb_attribute_chrvalue bg_gattdb_data_attribute_field_27 ) = { - .properties=0x2e, - .index=6, - .max_len=247, - .data_varlen=&bg_gattdb_data_attribute_field_27_data, +struct bg_gattdb_buffer_with_len + bg_gattdb_data_attribute_field_27_data = { .len = 1, + .data = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + } }; +GATT_DATA(const struct bg_gattdb_attribute_chrvalue bg_gattdb_data_attribute_field_27) = { + .properties = 0x2e, + .index = 6, + .max_len = 247, + .data_varlen = &bg_gattdb_data_attribute_field_27_data, }; -GATT_DATA(const struct bg_gattdb_buffer_with_len bg_gattdb_data_attribute_field_26 ) = { - .len=19, - .data={0x2e,0x1c,0x00,0x12,0x9d,0x9f,0x42,0x9c,0x4f,0x9f,0x95,0x59,0x45,0x3d,0x26,0xf5,0x2e,0xee,0x18,} -}; -struct bg_gattdb_buffer_with_len bg_gattdb_data_attribute_field_25_data = { - .len=1, - .data={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,} -}; -GATT_DATA(const struct bg_gattdb_attribute_chrvalue bg_gattdb_data_attribute_field_25 ) = { - .properties=0x0a, - .index=5, - .max_len=247, - .data_varlen=&bg_gattdb_data_attribute_field_25_data, +GATT_DATA(const struct bg_gattdb_buffer_with_len bg_gattdb_data_attribute_field_26) = { .len = 19, + .data = { + 0x2e, 0x1c, 0x00, 0x12, 0x9d, + 0x9f, 0x42, 0x9c, 0x4f, 0x9f, + 0x95, 0x59, 0x45, 0x3d, 0x26, + 0xf5, 0x2e, 0xee, 0x18, + } }; +struct bg_gattdb_buffer_with_len + bg_gattdb_data_attribute_field_25_data = { .len = 1, + .data = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + } }; +GATT_DATA(const struct bg_gattdb_attribute_chrvalue bg_gattdb_data_attribute_field_25) = { + .properties = 0x0a, + .index = 5, + .max_len = 247, + .data_varlen = &bg_gattdb_data_attribute_field_25_data, }; -GATT_DATA(const struct bg_gattdb_buffer_with_len bg_gattdb_data_attribute_field_24 ) = { - .len=19, - .data={0x0a,0x1a,0x00,0x11,0x9d,0x9f,0x42,0x9c,0x4f,0x9f,0x95,0x59,0x45,0x3d,0x26,0xf5,0x2e,0xee,0x18,} -}; -GATT_DATA(const struct bg_gattdb_buffer_with_len bg_gattdb_data_attribute_field_23 ) = { - .len=2, - .data={0xaf,0xfe,} -}; -GATT_DATA(const struct bg_gattdb_attribute_chrvalue bg_gattdb_data_attribute_field_22 ) = { - .properties=0x08, - .index=4, - .max_len=0, - .data=NULL, +GATT_DATA(const struct bg_gattdb_buffer_with_len bg_gattdb_data_attribute_field_24) = { .len = 19, + .data = { + 0x0a, 0x1a, 0x00, 0x11, 0x9d, + 0x9f, 0x42, 0x9c, 0x4f, 0x9f, + 0x95, 0x59, 0x45, 0x3d, 0x26, + 0xf5, 0x2e, 0xee, 0x18, + } }; +GATT_DATA(const struct bg_gattdb_buffer_with_len bg_gattdb_data_attribute_field_23) = { .len = 2, + .data = { + 0xaf, + 0xfe, + } }; +GATT_DATA(const struct bg_gattdb_attribute_chrvalue bg_gattdb_data_attribute_field_22) = { + .properties = 0x08, + .index = 4, + .max_len = 0, + .data = NULL, }; -GATT_DATA(const struct bg_gattdb_buffer_with_len bg_gattdb_data_attribute_field_21 ) = { - .len=19, - .data={0x08,0x17,0x00,0x63,0x60,0x32,0xe0,0x37,0x5e,0xa4,0x88,0x53,0x4e,0x6d,0xfb,0x64,0x35,0xbf,0xf7,} -}; -GATT_DATA(const struct bg_gattdb_buffer_with_len bg_gattdb_data_attribute_field_20 ) = { - .len=16, - .data={0xf0,0x19,0x21,0xb4,0x47,0x8f,0xa4,0xbf,0xa1,0x4f,0x63,0xfd,0xee,0xd6,0x14,0x1d,} -}; -GATT_DATA(const struct bg_gattdb_buffer_with_len bg_gattdb_data_attribute_field_19 ) = { - .len=6, - .data={0x00,0x01,0x02,0x03,0x04,0x05,} -}; -GATT_DATA(const struct bg_gattdb_buffer_with_len bg_gattdb_data_attribute_field_18 ) = { - .len=5, - .data={0x02,0x14,0x00,0x23,0x2a,} -}; -GATT_DATA(const struct bg_gattdb_buffer_with_len bg_gattdb_data_attribute_field_17 ) = { - .len=10, - .data={0x42,0x6c,0x75,0x65,0x20,0x47,0x65,0x63,0x6b,0x6f,} -}; -GATT_DATA(const struct bg_gattdb_buffer_with_len bg_gattdb_data_attribute_field_16 ) = { - .len=5, - .data={0x02,0x12,0x00,0x24,0x2a,} -}; -GATT_DATA(const struct bg_gattdb_buffer_with_len bg_gattdb_data_attribute_field_15 ) = { - .len=12, - .data={0x53,0x69,0x6c,0x69,0x63,0x6f,0x6e,0x20,0x4c,0x61,0x62,0x73,} -}; -GATT_DATA(const struct bg_gattdb_buffer_with_len bg_gattdb_data_attribute_field_14 ) = { - .len=5, - .data={0x02,0x10,0x00,0x29,0x2a,} -}; -GATT_DATA(const struct bg_gattdb_buffer_with_len bg_gattdb_data_attribute_field_13 ) = { - .len=2, - .data={0x0a,0x18,} -}; -GATT_DATA(const struct bg_gattdb_buffer_with_len bg_gattdb_data_attribute_field_12 ) = { - .len=2, - .data={0x00,0x00,} -}; -GATT_DATA(const struct bg_gattdb_buffer_with_len bg_gattdb_data_attribute_field_11 ) = { - .len=5, - .data={0x02,0x0d,0x00,0x01,0x2a,} -}; -uint8_t bg_gattdb_data_attribute_field_10_data[13]={0x45,0x6d,0x70,0x74,0x79,0x20,0x45,0x78,0x61,0x6d,0x70,0x6c,0x65,}; -GATT_DATA(const struct bg_gattdb_attribute_chrvalue bg_gattdb_data_attribute_field_10 ) = { - .properties=0x0a, - .index=3, - .max_len=13, - .data=bg_gattdb_data_attribute_field_10_data, +GATT_DATA(const struct bg_gattdb_buffer_with_len bg_gattdb_data_attribute_field_21) = { .len = 19, + .data = { + 0x08, 0x17, 0x00, 0x63, 0x60, + 0x32, 0xe0, 0x37, 0x5e, 0xa4, + 0x88, 0x53, 0x4e, 0x6d, 0xfb, + 0x64, 0x35, 0xbf, 0xf7, + } }; +GATT_DATA(const struct bg_gattdb_buffer_with_len bg_gattdb_data_attribute_field_20) = { .len = 16, + .data = { + 0xf0, + 0x19, + 0x21, + 0xb4, + 0x47, + 0x8f, + 0xa4, + 0xbf, + 0xa1, + 0x4f, + 0x63, + 0xfd, + 0xee, + 0xd6, + 0x14, + 0x1d, + } }; +GATT_DATA(const struct bg_gattdb_buffer_with_len bg_gattdb_data_attribute_field_19) = { .len = 6, + .data = { + 0x00, + 0x01, + 0x02, + 0x03, + 0x04, + 0x05, + } }; +GATT_DATA(const struct bg_gattdb_buffer_with_len bg_gattdb_data_attribute_field_18) = { .len = 5, + .data = { + 0x02, + 0x14, + 0x00, + 0x23, + 0x2a, + } }; +GATT_DATA(const struct bg_gattdb_buffer_with_len bg_gattdb_data_attribute_field_17) = { .len = 10, + .data = { + 0x42, + 0x6c, + 0x75, + 0x65, + 0x20, + 0x47, + 0x65, + 0x63, + 0x6b, + 0x6f, + } }; +GATT_DATA(const struct bg_gattdb_buffer_with_len bg_gattdb_data_attribute_field_16) = { .len = 5, + .data = { + 0x02, + 0x12, + 0x00, + 0x24, + 0x2a, + } }; +GATT_DATA(const struct bg_gattdb_buffer_with_len bg_gattdb_data_attribute_field_15) = { .len = 12, + .data = { + 0x53, + 0x69, + 0x6c, + 0x69, + 0x63, + 0x6f, + 0x6e, + 0x20, + 0x4c, + 0x61, + 0x62, + 0x73, + } }; +GATT_DATA(const struct bg_gattdb_buffer_with_len bg_gattdb_data_attribute_field_14) = { .len = 5, + .data = { + 0x02, + 0x10, + 0x00, + 0x29, + 0x2a, + } }; +GATT_DATA(const struct bg_gattdb_buffer_with_len bg_gattdb_data_attribute_field_13) = { .len = 2, + .data = { + 0x0a, + 0x18, + } }; +GATT_DATA(const struct bg_gattdb_buffer_with_len bg_gattdb_data_attribute_field_12) = { .len = 2, + .data = { + 0x00, + 0x00, + } }; +GATT_DATA(const struct bg_gattdb_buffer_with_len bg_gattdb_data_attribute_field_11) = { .len = 5, + .data = { + 0x02, + 0x0d, + 0x00, + 0x01, + 0x2a, + } }; +uint8_t bg_gattdb_data_attribute_field_10_data[13] = { + 0x45, 0x6d, 0x70, 0x74, 0x79, 0x20, 0x45, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, +}; +GATT_DATA(const struct bg_gattdb_attribute_chrvalue bg_gattdb_data_attribute_field_10) = { + .properties = 0x0a, + .index = 3, + .max_len = 13, + .data = bg_gattdb_data_attribute_field_10_data, }; -GATT_DATA(const struct bg_gattdb_buffer_with_len bg_gattdb_data_attribute_field_9 ) = { - .len=5, - .data={0x0a,0x0b,0x00,0x00,0x2a,} -}; -GATT_DATA(const struct bg_gattdb_buffer_with_len bg_gattdb_data_attribute_field_8 ) = { - .len=2, - .data={0x00,0x18,} -}; -uint8_t bg_gattdb_data_attribute_field_7_data[1]={0x00,}; -GATT_DATA(const struct bg_gattdb_attribute_chrvalue bg_gattdb_data_attribute_field_7 ) = { - .properties=0x0a, - .index=2, - .max_len=1, - .data=bg_gattdb_data_attribute_field_7_data, +GATT_DATA(const struct bg_gattdb_buffer_with_len bg_gattdb_data_attribute_field_9) = { .len = 5, + .data = { + 0x0a, + 0x0b, + 0x00, + 0x00, + 0x2a, + } }; +GATT_DATA(const struct bg_gattdb_buffer_with_len bg_gattdb_data_attribute_field_8) = { .len = 2, + .data = { + 0x00, + 0x18, + } }; +uint8_t bg_gattdb_data_attribute_field_7_data[1] = { + 0x00, +}; +GATT_DATA(const struct bg_gattdb_attribute_chrvalue bg_gattdb_data_attribute_field_7) = { + .properties = 0x0a, + .index = 2, + .max_len = 1, + .data = bg_gattdb_data_attribute_field_7_data, }; -GATT_DATA(const struct bg_gattdb_buffer_with_len bg_gattdb_data_attribute_field_6 ) = { - .len=5, - .data={0x0a,0x08,0x00,0x29,0x2b,} -}; -uint8_t bg_gattdb_data_attribute_field_5_data[16]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,}; -GATT_DATA(const struct bg_gattdb_attribute_chrvalue bg_gattdb_data_attribute_field_5 ) = { - .properties=0x02, - .index=1, - .max_len=16, - .data=bg_gattdb_data_attribute_field_5_data, +GATT_DATA(const struct bg_gattdb_buffer_with_len bg_gattdb_data_attribute_field_6) = { .len = 5, + .data = { + 0x0a, + 0x08, + 0x00, + 0x29, + 0x2b, + } }; +uint8_t bg_gattdb_data_attribute_field_5_data[16] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +}; +GATT_DATA(const struct bg_gattdb_attribute_chrvalue bg_gattdb_data_attribute_field_5) = { + .properties = 0x02, + .index = 1, + .max_len = 16, + .data = bg_gattdb_data_attribute_field_5_data, }; -GATT_DATA(const struct bg_gattdb_buffer_with_len bg_gattdb_data_attribute_field_4 ) = { - .len=5, - .data={0x02,0x06,0x00,0x2a,0x2b,} -}; -uint8_t bg_gattdb_data_attribute_field_2_data[4]={0x00,0x00,0x00,0x00,}; -GATT_DATA(const struct bg_gattdb_attribute_chrvalue bg_gattdb_data_attribute_field_2 ) = { - .properties=0x20, - .index=0, - .max_len=4, - .data=bg_gattdb_data_attribute_field_2_data, +GATT_DATA(const struct bg_gattdb_buffer_with_len bg_gattdb_data_attribute_field_4) = { .len = 5, + .data = { + 0x02, + 0x06, + 0x00, + 0x2a, + 0x2b, + } }; +uint8_t bg_gattdb_data_attribute_field_2_data[4] = { + 0x00, + 0x00, + 0x00, + 0x00, +}; +GATT_DATA(const struct bg_gattdb_attribute_chrvalue bg_gattdb_data_attribute_field_2) = { + .properties = 0x20, + .index = 0, + .max_len = 4, + .data = bg_gattdb_data_attribute_field_2_data, }; -GATT_DATA(const struct bg_gattdb_buffer_with_len bg_gattdb_data_attribute_field_1 ) = { - .len=5, - .data={0x20,0x03,0x00,0x05,0x2a,} -}; -GATT_DATA(const struct bg_gattdb_buffer_with_len bg_gattdb_data_attribute_field_0 ) = { - .len=2, - .data={0x01,0x18,} -}; -GATT_DATA(const struct bg_gattdb_attribute bg_gattdb_data_attributes_map[])={ - {.uuid=0x0000,.permissions=0x801,.caps=0xffff,.datatype=0x00,.constdata=&bg_gattdb_data_attribute_field_0}, - {.uuid=0x0002,.permissions=0x801,.caps=0xffff,.datatype=0x00,.constdata=&bg_gattdb_data_attribute_field_1}, - {.uuid=0x000c,.permissions=0x800,.caps=0xffff,.datatype=0x01,.dynamicdata=&bg_gattdb_data_attribute_field_2}, - {.uuid=0x000f,.permissions=0x807,.caps=0xffff,.datatype=0x03,.configdata={.flags=0x02,.index=0x00,.clientconfig_index=0x00}}, - {.uuid=0x0002,.permissions=0x801,.caps=0xffff,.datatype=0x00,.constdata=&bg_gattdb_data_attribute_field_4}, - {.uuid=0x000d,.permissions=0x801,.caps=0xffff,.datatype=0x01,.dynamicdata=&bg_gattdb_data_attribute_field_5}, - {.uuid=0x0002,.permissions=0x801,.caps=0xffff,.datatype=0x00,.constdata=&bg_gattdb_data_attribute_field_6}, - {.uuid=0x000e,.permissions=0x803,.caps=0xffff,.datatype=0x01,.dynamicdata=&bg_gattdb_data_attribute_field_7}, - {.uuid=0x0000,.permissions=0x801,.caps=0xffff,.datatype=0x00,.constdata=&bg_gattdb_data_attribute_field_8}, - {.uuid=0x0002,.permissions=0x801,.caps=0xffff,.datatype=0x00,.constdata=&bg_gattdb_data_attribute_field_9}, - {.uuid=0x0004,.permissions=0x803,.caps=0xffff,.datatype=0x01,.dynamicdata=&bg_gattdb_data_attribute_field_10}, - {.uuid=0x0002,.permissions=0x801,.caps=0xffff,.datatype=0x00,.constdata=&bg_gattdb_data_attribute_field_11}, - {.uuid=0x0005,.permissions=0x801,.caps=0xffff,.datatype=0x00,.constdata=&bg_gattdb_data_attribute_field_12}, - {.uuid=0x0000,.permissions=0x801,.caps=0xffff,.datatype=0x00,.constdata=&bg_gattdb_data_attribute_field_13}, - {.uuid=0x0002,.permissions=0x801,.caps=0xffff,.datatype=0x00,.constdata=&bg_gattdb_data_attribute_field_14}, - {.uuid=0x0007,.permissions=0x801,.caps=0xffff,.datatype=0x00,.constdata=&bg_gattdb_data_attribute_field_15}, - {.uuid=0x0002,.permissions=0x801,.caps=0xffff,.datatype=0x00,.constdata=&bg_gattdb_data_attribute_field_16}, - {.uuid=0x0008,.permissions=0x801,.caps=0xffff,.datatype=0x00,.constdata=&bg_gattdb_data_attribute_field_17}, - {.uuid=0x0002,.permissions=0x801,.caps=0xffff,.datatype=0x00,.constdata=&bg_gattdb_data_attribute_field_18}, - {.uuid=0x0009,.permissions=0x801,.caps=0xffff,.datatype=0x00,.constdata=&bg_gattdb_data_attribute_field_19}, - {.uuid=0x0000,.permissions=0x801,.caps=0xffff,.datatype=0x00,.constdata=&bg_gattdb_data_attribute_field_20}, - {.uuid=0x0002,.permissions=0x801,.caps=0xffff,.datatype=0x00,.constdata=&bg_gattdb_data_attribute_field_21}, - {.uuid=0x8001,.permissions=0x802,.caps=0xffff,.datatype=0x07,.dynamicdata=&bg_gattdb_data_attribute_field_22}, - {.uuid=0x0000,.permissions=0x801,.caps=0xffff,.datatype=0x00,.constdata=&bg_gattdb_data_attribute_field_23}, - {.uuid=0x0002,.permissions=0x801,.caps=0xffff,.datatype=0x00,.constdata=&bg_gattdb_data_attribute_field_24}, - {.uuid=0x8002,.permissions=0x803,.caps=0xffff,.datatype=0x02,.dynamicdata=&bg_gattdb_data_attribute_field_25}, - {.uuid=0x0002,.permissions=0x801,.caps=0xffff,.datatype=0x00,.constdata=&bg_gattdb_data_attribute_field_26}, - {.uuid=0x8003,.permissions=0x807,.caps=0xffff,.datatype=0x02,.dynamicdata=&bg_gattdb_data_attribute_field_27}, - {.uuid=0x000f,.permissions=0x807,.caps=0xffff,.datatype=0x03,.configdata={.flags=0x02,.index=0x06,.clientconfig_index=0x01}}, +GATT_DATA(const struct bg_gattdb_buffer_with_len bg_gattdb_data_attribute_field_1) = { .len = 5, + .data = { + 0x20, + 0x03, + 0x00, + 0x05, + 0x2a, + } }; +GATT_DATA(const struct bg_gattdb_buffer_with_len bg_gattdb_data_attribute_field_0) = { .len = 2, + .data = { + 0x01, + 0x18, + } }; +GATT_DATA(const struct bg_gattdb_attribute bg_gattdb_data_attributes_map[]) = { + { .uuid = 0x0000, .permissions = 0x801, .caps = 0xffff, .datatype = 0x00, .constdata = &bg_gattdb_data_attribute_field_0 }, + { .uuid = 0x0002, .permissions = 0x801, .caps = 0xffff, .datatype = 0x00, .constdata = &bg_gattdb_data_attribute_field_1 }, + { .uuid = 0x000c, .permissions = 0x800, .caps = 0xffff, .datatype = 0x01, .dynamicdata = &bg_gattdb_data_attribute_field_2 }, + { .uuid = 0x000f, + .permissions = 0x807, + .caps = 0xffff, + .datatype = 0x03, + .configdata = { .flags = 0x02, .index = 0x00, .clientconfig_index = 0x00 } }, + { .uuid = 0x0002, .permissions = 0x801, .caps = 0xffff, .datatype = 0x00, .constdata = &bg_gattdb_data_attribute_field_4 }, + { .uuid = 0x000d, .permissions = 0x801, .caps = 0xffff, .datatype = 0x01, .dynamicdata = &bg_gattdb_data_attribute_field_5 }, + { .uuid = 0x0002, .permissions = 0x801, .caps = 0xffff, .datatype = 0x00, .constdata = &bg_gattdb_data_attribute_field_6 }, + { .uuid = 0x000e, .permissions = 0x803, .caps = 0xffff, .datatype = 0x01, .dynamicdata = &bg_gattdb_data_attribute_field_7 }, + { .uuid = 0x0000, .permissions = 0x801, .caps = 0xffff, .datatype = 0x00, .constdata = &bg_gattdb_data_attribute_field_8 }, + { .uuid = 0x0002, .permissions = 0x801, .caps = 0xffff, .datatype = 0x00, .constdata = &bg_gattdb_data_attribute_field_9 }, + { .uuid = 0x0004, .permissions = 0x803, .caps = 0xffff, .datatype = 0x01, .dynamicdata = &bg_gattdb_data_attribute_field_10 }, + { .uuid = 0x0002, .permissions = 0x801, .caps = 0xffff, .datatype = 0x00, .constdata = &bg_gattdb_data_attribute_field_11 }, + { .uuid = 0x0005, .permissions = 0x801, .caps = 0xffff, .datatype = 0x00, .constdata = &bg_gattdb_data_attribute_field_12 }, + { .uuid = 0x0000, .permissions = 0x801, .caps = 0xffff, .datatype = 0x00, .constdata = &bg_gattdb_data_attribute_field_13 }, + { .uuid = 0x0002, .permissions = 0x801, .caps = 0xffff, .datatype = 0x00, .constdata = &bg_gattdb_data_attribute_field_14 }, + { .uuid = 0x0007, .permissions = 0x801, .caps = 0xffff, .datatype = 0x00, .constdata = &bg_gattdb_data_attribute_field_15 }, + { .uuid = 0x0002, .permissions = 0x801, .caps = 0xffff, .datatype = 0x00, .constdata = &bg_gattdb_data_attribute_field_16 }, + { .uuid = 0x0008, .permissions = 0x801, .caps = 0xffff, .datatype = 0x00, .constdata = &bg_gattdb_data_attribute_field_17 }, + { .uuid = 0x0002, .permissions = 0x801, .caps = 0xffff, .datatype = 0x00, .constdata = &bg_gattdb_data_attribute_field_18 }, + { .uuid = 0x0009, .permissions = 0x801, .caps = 0xffff, .datatype = 0x00, .constdata = &bg_gattdb_data_attribute_field_19 }, + { .uuid = 0x0000, .permissions = 0x801, .caps = 0xffff, .datatype = 0x00, .constdata = &bg_gattdb_data_attribute_field_20 }, + { .uuid = 0x0002, .permissions = 0x801, .caps = 0xffff, .datatype = 0x00, .constdata = &bg_gattdb_data_attribute_field_21 }, + { .uuid = 0x8001, .permissions = 0x802, .caps = 0xffff, .datatype = 0x07, .dynamicdata = &bg_gattdb_data_attribute_field_22 }, + { .uuid = 0x0000, .permissions = 0x801, .caps = 0xffff, .datatype = 0x00, .constdata = &bg_gattdb_data_attribute_field_23 }, + { .uuid = 0x0002, .permissions = 0x801, .caps = 0xffff, .datatype = 0x00, .constdata = &bg_gattdb_data_attribute_field_24 }, + { .uuid = 0x8002, .permissions = 0x803, .caps = 0xffff, .datatype = 0x02, .dynamicdata = &bg_gattdb_data_attribute_field_25 }, + { .uuid = 0x0002, .permissions = 0x801, .caps = 0xffff, .datatype = 0x00, .constdata = &bg_gattdb_data_attribute_field_26 }, + { .uuid = 0x8003, .permissions = 0x807, .caps = 0xffff, .datatype = 0x02, .dynamicdata = &bg_gattdb_data_attribute_field_27 }, + { .uuid = 0x000f, + .permissions = 0x807, + .caps = 0xffff, + .datatype = 0x03, + .configdata = { .flags = 0x02, .index = 0x06, .clientconfig_index = 0x01 } }, }; -GATT_DATA(const uint16_t bg_gattdb_data_attributes_dynamic_mapping_map[])={ - 0x0003, - 0x0006, - 0x0008, - 0x000b, - 0x0017, - 0x001a, - 0x001c, +GATT_DATA(const uint16_t bg_gattdb_data_attributes_dynamic_mapping_map[]) = { + 0x0003, 0x0006, 0x0008, 0x000b, 0x0017, 0x001a, 0x001c, }; -GATT_DATA(const uint8_t bg_gattdb_data_adv_uuid16_map[])={0x0}; -GATT_DATA(const uint8_t bg_gattdb_data_adv_uuid128_map[])={0x0}; -GATT_HEADER(const struct bg_gattdb_def bg_gattdb_data)={ - .attributes=bg_gattdb_data_attributes_map, - .attributes_max=29, - .uuidtable_16_size=16, - .uuidtable_16=bg_gattdb_data_uuidtable_16_map, - .uuidtable_128_size=4, - .uuidtable_128=bg_gattdb_data_uuidtable_128_map, - .attributes_dynamic_max=7, - .attributes_dynamic_mapping=bg_gattdb_data_attributes_dynamic_mapping_map, - .adv_uuid16=bg_gattdb_data_adv_uuid16_map, - .adv_uuid16_num=0, - .adv_uuid128=bg_gattdb_data_adv_uuid128_map, - .adv_uuid128_num=0, - .caps_mask=0xffff, - .enabled_caps=0xffff, +GATT_DATA(const uint8_t bg_gattdb_data_adv_uuid16_map[]) = { 0x0 }; +GATT_DATA(const uint8_t bg_gattdb_data_adv_uuid128_map[]) = { 0x0 }; +GATT_HEADER(const struct bg_gattdb_def bg_gattdb_data) = { + .attributes = bg_gattdb_data_attributes_map, + .attributes_max = 29, + .uuidtable_16_size = 16, + .uuidtable_16 = bg_gattdb_data_uuidtable_16_map, + .uuidtable_128_size = 4, + .uuidtable_128 = bg_gattdb_data_uuidtable_128_map, + .attributes_dynamic_max = 7, + .attributes_dynamic_mapping = bg_gattdb_data_attributes_dynamic_mapping_map, + .adv_uuid16 = bg_gattdb_data_adv_uuid16_map, + .adv_uuid16_num = 0, + .adv_uuid128 = bg_gattdb_data_adv_uuid128_map, + .adv_uuid128_num = 0, + .caps_mask = 0xffff, + .enabled_caps = 0xffff, }; -const struct bg_gattdb_def *bg_gattdb=&bg_gattdb_data; +const struct bg_gattdb_def * bg_gattdb = &bg_gattdb_data; diff --git a/src/platform/FreeRTOS/SystemTimeSupport.cpp b/src/platform/FreeRTOS/SystemTimeSupport.cpp index e62a46c5bb73ec..040a68e08877f7 100644 --- a/src/platform/FreeRTOS/SystemTimeSupport.cpp +++ b/src/platform/FreeRTOS/SystemTimeSupport.cpp @@ -23,7 +23,6 @@ * time/clock functions based on the FreeRTOS tick counter. */ - #include #include @@ -72,22 +71,21 @@ uint64_t FreeRTOSTicksSinceBoot(void) // Note that sNumOverflows may be quite stale, and under those // circumstances, the function may violate monotonicity guarantees timeOut.xTimeOnEntering = xTaskGetTickCountFromISR(); - timeOut.xOverflowCount = sNumOfOverflows; + timeOut.xOverflowCount = sNumOfOverflows; } else { #endif - vTaskSetTimeOutState(&timeOut); + vTaskSetTimeOutState(&timeOut); #ifdef __CORTEX_M - // BaseType_t is supposed to be atomic - sNumOfOverflows = timeOut.xOverflowCount; + // BaseType_t is supposed to be atomic + sNumOfOverflows = timeOut.xOverflowCount; } #endif - return static_cast(timeOut.xTimeOnEntering) + - (static_cast(timeOut.xOverflowCount) << kTicksOverflowShift); + return static_cast(timeOut.xTimeOnEntering) + (static_cast(timeOut.xOverflowCount) << kTicksOverflowShift); } uint64_t GetClock_Monotonic(void) diff --git a/src/platform/GeneralUtils.cpp b/src/platform/GeneralUtils.cpp index 90040e5df6f23c..5c2e5809e5f505 100644 --- a/src/platform/GeneralUtils.cpp +++ b/src/platform/GeneralUtils.cpp @@ -33,7 +33,7 @@ CHIP_ERROR ParseCompilerDateStr(const char * dateStr, uint16_t & year, uint8_t & CHIP_ERROR err = CHIP_NO_ERROR; char monthStr[4]; const char * p; - char* endptr; + char * endptr; static const char months[] = "JanFebMarAprMayJunJulAugSepOctNovDec"; @@ -82,11 +82,7 @@ CHIP_ERROR Parse24HourTimeStr(const char * timeStr, uint8_t & hour, uint8_t & mi */ void RegisterDeviceLayerErrorFormatter(void) { - static ErrorFormatter sDeviceLayerErrorFormatter = - { - FormatDeviceLayerError, - NULL - }; + static ErrorFormatter sDeviceLayerErrorFormatter = { FormatDeviceLayerError, NULL }; RegisterErrorFormatter(&sDeviceLayerErrorFormatter); } @@ -115,8 +111,12 @@ bool FormatDeviceLayerError(char * buf, uint16_t bufSize, int32_t err) #if !CHIP_CONFIG_SHORT_ERROR_STR switch (err) { - case CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND : desc = "Config not found"; break; - case CHIP_DEVICE_ERROR_NOT_SERVICE_PROVISIONED : desc = "Not service provisioned"; break; + case CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND: + desc = "Config not found"; + break; + case CHIP_DEVICE_ERROR_NOT_SERVICE_PROVISIONED: + desc = "Not service provisioned"; + break; } #endif // !CHIP_CONFIG_SHORT_ERROR_STR diff --git a/src/platform/PersistedStorage.cpp b/src/platform/PersistedStorage.cpp index 51f0aaea3d7b57..6d5c852a587e26 100644 --- a/src/platform/PersistedStorage.cpp +++ b/src/platform/PersistedStorage.cpp @@ -41,7 +41,6 @@ CHIP_ERROR Write(Key key, uint32_t value) return ConfigurationMgr().WritePersistedStorageValue(key, value); } -} // PersistedStorage -} // Platform -} // chip - +} // namespace PersistedStorage +} // namespace Platform +} // namespace chip diff --git a/src/platform/SystemEventSupport.cpp b/src/platform/SystemEventSupport.cpp index b2ff82564f1d6b..ae835d3a7e10fc 100644 --- a/src/platform/SystemEventSupport.cpp +++ b/src/platform/SystemEventSupport.cpp @@ -33,12 +33,13 @@ namespace Layer { using namespace ::chip::DeviceLayer; -System::Error PostEvent(System::Layer & aLayer, void * aContext, System::Object & aTarget, System::EventType aType, uintptr_t aArgument) +System::Error PostEvent(System::Layer & aLayer, void * aContext, System::Object & aTarget, System::EventType aType, + uintptr_t aArgument) { ChipDeviceEvent event; - event.Type = DeviceEventType::kChipSystemLayerEvent; - event.ChipSystemLayerEvent.Type = aType; - event.ChipSystemLayerEvent.Target = &aTarget; + event.Type = DeviceEventType::kChipSystemLayerEvent; + event.ChipSystemLayerEvent.Type = aType; + event.ChipSystemLayerEvent.Target = &aTarget; event.ChipSystemLayerEvent.Argument = aArgument; PlatformMgr().PostEvent(&event); diff --git a/src/platform/nRF5/BLEManagerImpl.cpp b/src/platform/nRF5/BLEManagerImpl.cpp index 87ccaf73f61506..13cd7ba052796d 100644 --- a/src/platform/nRF5/BLEManagerImpl.cpp +++ b/src/platform/nRF5/BLEManagerImpl.cpp @@ -53,13 +53,17 @@ namespace { const uint16_t UUID16_CHIPoBLEService = 0xFEAF; const ble_uuid_t UUID_CHIPoBLEService = { UUID16_CHIPoBLEService, BLE_UUID_TYPE_BLE }; -const ble_uuid128_t UUID128_CHIPoBLEChar_RX = { { 0x11, 0x9D, 0x9F, 0x42, 0x9C, 0x4F, 0x9F, 0x95, 0x59, 0x45, 0x3D, 0x26, 0xF5, 0x2E, 0xEE, 0x18 } }; +const ble_uuid128_t UUID128_CHIPoBLEChar_RX = { { 0x11, 0x9D, 0x9F, 0x42, 0x9C, 0x4F, 0x9F, 0x95, 0x59, 0x45, 0x3D, 0x26, 0xF5, + 0x2E, 0xEE, 0x18 } }; ble_uuid_t UUID_CHIPoBLEChar_RX; -const ChipBleUUID chipUUID_CHIPoBLEChar_RX = { { 0x18, 0xEE, 0x2E, 0xF5, 0x26, 0x3D, 0x45, 0x59, 0x95, 0x9F, 0x4F, 0x9C, 0x42, 0x9F, 0x9D, 0x11 } }; +const ChipBleUUID chipUUID_CHIPoBLEChar_RX = { { 0x18, 0xEE, 0x2E, 0xF5, 0x26, 0x3D, 0x45, 0x59, 0x95, 0x9F, 0x4F, 0x9C, 0x42, 0x9F, + 0x9D, 0x11 } }; -const ble_uuid128_t UUID128_CHIPoBLEChar_TX = { { 0x12, 0x9D, 0x9F, 0x42, 0x9C, 0x4F, 0x9F, 0x95, 0x59, 0x45, 0x3D, 0x26, 0xF5, 0x2E, 0xEE, 0x18 } }; +const ble_uuid128_t UUID128_CHIPoBLEChar_TX = { { 0x12, 0x9D, 0x9F, 0x42, 0x9C, 0x4F, 0x9F, 0x95, 0x59, 0x45, 0x3D, 0x26, 0xF5, + 0x2E, 0xEE, 0x18 } }; ble_uuid_t UUID_CHIPoBLEChar_TX; -const ChipBleUUID chipUUID_CHIPoBLEChar_TX = { { 0x18, 0xEE, 0x2E, 0xF5, 0x26, 0x3D, 0x45, 0x59, 0x95, 0x9F, 0x4F, 0x9C, 0x42, 0x9F, 0x9D, 0x12 } }; +const ChipBleUUID chipUUID_CHIPoBLEChar_TX = { { 0x18, 0xEE, 0x2E, 0xF5, 0x26, 0x3D, 0x45, 0x59, 0x95, 0x9F, 0x4F, 0x9C, 0x42, 0x9F, + 0x9D, 0x12 } }; NRF_BLE_GATT_DEF(GATTModule); @@ -70,7 +74,7 @@ CHIP_ERROR RegisterVendorUUID(ble_uuid_t & uuid, const ble_uuid128_t & vendorUUI err = sd_ble_uuid_vs_add(&vendorUUID, &uuid.type); SuccessOrExit(err); - uuid.uuid = (((uint16_t)vendorUUID.uuid128[13]) << 8) | vendorUUID.uuid128[12]; + uuid.uuid = (((uint16_t) vendorUUID.uuid128[13]) << 8) | vendorUUID.uuid128[12]; exit: return err; @@ -78,7 +82,6 @@ CHIP_ERROR RegisterVendorUUID(ble_uuid_t & uuid, const ble_uuid128_t & vendorUUI } // unnamed namespace - BLEManagerImpl BLEManagerImpl::sInstance; #ifndef CHIP_DEVICE_LAYER_BLE_OBSERVER_PRIORITY #define CHIP_DEVICE_LAYER_BLE_OBSERVER_PRIORITY 3 @@ -91,9 +94,9 @@ CHIP_ERROR BLEManagerImpl::_Init() ble_add_char_params_t addCharParams; mServiceMode = ConnectivityManager::kCHIPoBLEServiceMode_Enabled; - mFlags = kFlag_AdvertisingEnabled; - mAdvHandle = BLE_GAP_ADV_SET_HANDLE_NOT_SET; - mNumGAPCons = 0; + mFlags = kFlag_AdvertisingEnabled; + mAdvHandle = BLE_GAP_ADV_SET_HANDLE_NOT_SET; + mNumGAPCons = 0; for (int i = 0; i < kMaxConnections; i++) { mSubscribedConIds[i] = BLE_CONNECTION_UNINITIALIZED; @@ -113,37 +116,37 @@ CHIP_ERROR BLEManagerImpl::_Init() SuccessOrExit(err); // Add the CHIPoBLE service. - err = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, (ble_uuid_t *)&UUID_CHIPoBLEService, &svcHandle); + err = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, (ble_uuid_t *) &UUID_CHIPoBLEService, &svcHandle); SuccessOrExit(err); // Add the CHIPoBLEChar_RX characteristic to the CHIPoBLE service. memset(&addCharParams, 0, sizeof(addCharParams)); - addCharParams.uuid = UUID_CHIPoBLEChar_RX.uuid; - addCharParams.uuid_type = UUID_CHIPoBLEChar_RX.type; - addCharParams.max_len = NRF_SDH_BLE_GATT_MAX_MTU_SIZE; - addCharParams.init_len = 0; - addCharParams.is_var_len = true; + addCharParams.uuid = UUID_CHIPoBLEChar_RX.uuid; + addCharParams.uuid_type = UUID_CHIPoBLEChar_RX.type; + addCharParams.max_len = NRF_SDH_BLE_GATT_MAX_MTU_SIZE; + addCharParams.init_len = 0; + addCharParams.is_var_len = true; addCharParams.char_props.write_wo_resp = 1; - addCharParams.char_props.write = 1; - addCharParams.read_access = SEC_OPEN; - addCharParams.write_access = SEC_OPEN; - addCharParams.cccd_write_access = SEC_NO_ACCESS; - err = characteristic_add(svcHandle, &addCharParams, &mCHIPoBLECharHandle_RX); + addCharParams.char_props.write = 1; + addCharParams.read_access = SEC_OPEN; + addCharParams.write_access = SEC_OPEN; + addCharParams.cccd_write_access = SEC_NO_ACCESS; + err = characteristic_add(svcHandle, &addCharParams, &mCHIPoBLECharHandle_RX); SuccessOrExit(err); // Add the CHIPoBLEChar_TX characteristic. memset(&addCharParams, 0, sizeof(addCharParams)); - addCharParams.uuid = UUID_CHIPoBLEChar_TX.uuid; - addCharParams.uuid_type = UUID_CHIPoBLEChar_TX.type; - addCharParams.max_len = NRF_SDH_BLE_GATT_MAX_MTU_SIZE; - addCharParams.is_var_len = true; - addCharParams.char_props.read = 1; - addCharParams.char_props.write = 1; + addCharParams.uuid = UUID_CHIPoBLEChar_TX.uuid; + addCharParams.uuid_type = UUID_CHIPoBLEChar_TX.type; + addCharParams.max_len = NRF_SDH_BLE_GATT_MAX_MTU_SIZE; + addCharParams.is_var_len = true; + addCharParams.char_props.read = 1; + addCharParams.char_props.write = 1; addCharParams.char_props.indicate = 1; - addCharParams.read_access = SEC_OPEN; - addCharParams.write_access = SEC_OPEN; - addCharParams.cccd_write_access = SEC_OPEN; - err = characteristic_add(svcHandle, &addCharParams, &mCHIPoBLECharHandle_TX); + addCharParams.read_access = SEC_OPEN; + addCharParams.write_access = SEC_OPEN; + addCharParams.cccd_write_access = SEC_OPEN; + err = characteristic_add(svcHandle, &addCharParams, &mCHIPoBLECharHandle_TX); SuccessOrExit(err); // Initialize the nRF5 GATT module and set the allowable GATT MTU and GAP packet sizes @@ -225,7 +228,7 @@ CHIP_ERROR BLEManagerImpl::_GetDeviceName(char * buf, size_t bufSize) CHIP_ERROR err; uint16_t len = (uint16_t)(bufSize - 1); - err = sd_ble_gap_device_name_get((uint8_t *)buf, &len); + err = sd_ble_gap_device_name_get((uint8_t *) buf, &len); SuccessOrExit(err); buf[len] = 0; @@ -249,9 +252,7 @@ CHIP_ERROR BLEManagerImpl::_SetDeviceName(const char * devName) } else { - snprintf(devNameBuf, sizeof(devNameBuf), "%s%04" PRIX32, - CHIP_DEVICE_CONFIG_BLE_DEVICE_NAME_PREFIX, - (uint32_t)0); + snprintf(devNameBuf, sizeof(devNameBuf), "%s%04" PRIX32, CHIP_DEVICE_CONFIG_BLE_DEVICE_NAME_PREFIX, (uint32_t) 0); devNameBuf[kMaxDeviceNameLength] = 0; } @@ -259,7 +260,7 @@ CHIP_ERROR BLEManagerImpl::_SetDeviceName(const char * devName) BLE_GAP_CONN_SEC_MODE_SET_NO_ACCESS(&secMode); // Configure the device name within the BLE soft device. - err = sd_ble_gap_device_name_set(&secMode, (const uint8_t *)devNameBuf, strlen(devNameBuf)); + err = sd_ble_gap_device_name_set(&secMode, (const uint8_t *) devNameBuf, strlen(devNameBuf)); SuccessOrExit(err); exit: @@ -342,7 +343,8 @@ uint16_t BLEManagerImpl::GetMTU(BLE_CONNECTION_OBJECT conId) const return nrf_ble_gatt_eff_mtu_get(&GATTModule, conId); } -bool BLEManagerImpl::SendIndication(BLE_CONNECTION_OBJECT conId, const ChipBleUUID * svcId, const ChipBleUUID * charId, PacketBuffer * data) +bool BLEManagerImpl::SendIndication(BLE_CONNECTION_OBJECT conId, const ChipBleUUID * svcId, const ChipBleUUID * charId, + PacketBuffer * data) { CHIP_ERROR err = CHIP_NO_ERROR; ble_gatts_hvx_params_t hvxParams; @@ -355,12 +357,12 @@ bool BLEManagerImpl::SendIndication(BLE_CONNECTION_OBJECT conId, const ChipBleUU // Send a indication for the CHIPoBLE TX characteristic to the client containing the supplied data. // Note that this call copies the data from the buffer. memset(&hvxParams, 0, sizeof(hvxParams)); - hvxParams.type = BLE_GATT_HVX_INDICATION; + hvxParams.type = BLE_GATT_HVX_INDICATION; hvxParams.handle = mCHIPoBLECharHandle_TX.value_handle; hvxParams.offset = 0; - hvxParams.p_len = &dataLen; + hvxParams.p_len = &dataLen; hvxParams.p_data = data->Start(); - err = sd_ble_gatts_hvx(conId, &hvxParams); + err = sd_ble_gatts_hvx(conId, &hvxParams); SuccessOrExit(err); exit: @@ -373,19 +375,22 @@ bool BLEManagerImpl::SendIndication(BLE_CONNECTION_OBJECT conId, const ChipBleUU return true; } -bool BLEManagerImpl::SendWriteRequest(BLE_CONNECTION_OBJECT conId, const ChipBleUUID * svcId, const ChipBleUUID * charId, PacketBuffer * pBuf) +bool BLEManagerImpl::SendWriteRequest(BLE_CONNECTION_OBJECT conId, const ChipBleUUID * svcId, const ChipBleUUID * charId, + PacketBuffer * pBuf) { ChipLogProgress(DeviceLayer, "BLEManagerImpl::SendWriteRequest() not supported"); return false; } -bool BLEManagerImpl::SendReadRequest(BLE_CONNECTION_OBJECT conId, const ChipBleUUID * svcId, const ChipBleUUID * charId, PacketBuffer * pBuf) +bool BLEManagerImpl::SendReadRequest(BLE_CONNECTION_OBJECT conId, const ChipBleUUID * svcId, const ChipBleUUID * charId, + PacketBuffer * pBuf) { ChipLogProgress(DeviceLayer, "BLEManagerImpl::SendReadRequest() not supported"); return false; } -bool BLEManagerImpl::SendReadResponse(BLE_CONNECTION_OBJECT conId, BLE_READ_REQUEST_CONTEXT requestContext, const ChipBleUUID * svcId, const ChipBleUUID * charId) +bool BLEManagerImpl::SendReadResponse(BLE_CONNECTION_OBJECT conId, BLE_READ_REQUEST_CONTEXT requestContext, + const ChipBleUUID * svcId, const ChipBleUUID * charId) { ChipLogProgress(DeviceLayer, "BLEManagerImpl::SendReadResponse() not supported"); return false; @@ -417,12 +422,13 @@ void BLEManagerImpl::DriveBLEState(void) } // If the application has enabled CHIPoBLE and BLE advertising... - if (mServiceMode == ConnectivityManager::kCHIPoBLEServiceMode_Enabled && GetFlag(mFlags, kFlag_AdvertisingEnabled) + if (mServiceMode == ConnectivityManager::kCHIPoBLEServiceMode_Enabled && + GetFlag(mFlags, kFlag_AdvertisingEnabled) #if CHIP_DEVICE_CONFIG_CHIPOBLE_SINGLE_CONNECTION // and no connections are active... && (mNumGAPCons == 0) #endif - ) + ) { // Start/re-start SoftDevice advertising if not already advertising, or if the // advertising state of the SoftDevice needs to be refreshed. @@ -497,18 +503,17 @@ CHIP_ERROR BLEManagerImpl::StartAdvertising(void) // Set advertising parameters. memset(&gapAdvParams, 0, sizeof(gapAdvParams)); - gapAdvParams.primary_phy = BLE_GAP_PHY_1MBPS; - gapAdvParams.duration = BLE_GAP_ADV_TIMEOUT_GENERAL_UNLIMITED; - gapAdvParams.filter_policy = BLE_GAP_ADV_FP_ANY; + gapAdvParams.primary_phy = BLE_GAP_PHY_1MBPS; + gapAdvParams.duration = BLE_GAP_ADV_TIMEOUT_GENERAL_UNLIMITED; + gapAdvParams.filter_policy = BLE_GAP_ADV_FP_ANY; // Advertise connectable if we haven't reached the maximum number of CHIPoBLE connections or the // maximum number of GAP connections. (Note that the SoftDevice will return an error if connectable // advertising is requested when the max number of GAP connections exist). numCHIPoBLECons = NumConnections(); - connectable = (numCHIPoBLECons < kMaxConnections && mNumGAPCons < NRF_SDH_BLE_PERIPHERAL_LINK_COUNT); - gapAdvParams.properties.type = connectable - ? BLE_GAP_ADV_TYPE_CONNECTABLE_SCANNABLE_UNDIRECTED - : BLE_GAP_ADV_TYPE_NONCONNECTABLE_SCANNABLE_UNDIRECTED; + connectable = (numCHIPoBLECons < kMaxConnections && mNumGAPCons < NRF_SDH_BLE_PERIPHERAL_LINK_COUNT); + gapAdvParams.properties.type = + connectable ? BLE_GAP_ADV_TYPE_CONNECTABLE_SCANNABLE_UNDIRECTED : BLE_GAP_ADV_TYPE_NONCONNECTABLE_SCANNABLE_UNDIRECTED; // Advertise in fast mode if not fully provisioned and there are no CHIPoBLE connections, or // if the application has expressly requested fast advertising. @@ -523,9 +528,7 @@ CHIP_ERROR BLEManagerImpl::StartAdvertising(void) char devNameBuf[kMaxDeviceNameLength + 1]; GetDeviceName(devNameBuf, sizeof(devNameBuf)); ChipLogProgress(DeviceLayer, "Configuring CHIPoBLE advertising (interval %" PRIu32 " ms, %sconnectable, device name %s)", - (((uint32_t)gapAdvParams.interval) * 10) / 16, - (connectable) ? "" : "non-", - devNameBuf); + (((uint32_t) gapAdvParams.interval) * 10) / 16, (connectable) ? "" : "non-", devNameBuf); } #endif // CHIP_PROGRESS_LOGGING @@ -557,7 +560,7 @@ CHIP_ERROR BLEManagerImpl::StartAdvertising(void) // Post a CHIPoBLEAdvertisingChange(Started) event. { ChipDeviceEvent advChange; - advChange.Type = DeviceEventType::kCHIPoBLEAdvertisingChange; + advChange.Type = DeviceEventType::kCHIPoBLEAdvertisingChange; advChange.CHIPoBLEAdvertisingChange.Result = kActivity_Started; PlatformMgr().PostEvent(&advChange); } @@ -600,7 +603,7 @@ CHIP_ERROR BLEManagerImpl::StopAdvertising(void) // Post a CHIPoBLEAdvertisingChange(Stopped) event. { ChipDeviceEvent advChange; - advChange.Type = DeviceEventType::kCHIPoBLEAdvertisingChange; + advChange.Type = DeviceEventType::kCHIPoBLEAdvertisingChange; advChange.CHIPoBLEAdvertisingChange.Result = kActivity_Stopped; PlatformMgr().PostEvent(&advChange); } @@ -619,14 +622,14 @@ CHIP_ERROR BLEManagerImpl::EncodeAdvertisingData(ble_gap_adv_data_t & gapAdvData // Form the contents of the advertising packet. memset(&advData, 0, sizeof(advData)); - advData.name_type = BLE_ADVDATA_FULL_NAME; - advData.include_appearance = false; - advData.flags = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE; + advData.name_type = BLE_ADVDATA_FULL_NAME; + advData.include_appearance = false; + advData.flags = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE; advData.uuids_complete.uuid_cnt = 1; - advData.uuids_complete.p_uuids = (ble_uuid_t *)&UUID_CHIPoBLEService; - gapAdvData.adv_data.p_data = mAdvDataBuf; - gapAdvData.adv_data.len = sizeof(mAdvDataBuf); - err = ble_advdata_encode(&advData, mAdvDataBuf, &gapAdvData.adv_data.len); + advData.uuids_complete.p_uuids = (ble_uuid_t *) &UUID_CHIPoBLEService; + gapAdvData.adv_data.p_data = mAdvDataBuf; + gapAdvData.adv_data.len = sizeof(mAdvDataBuf); + err = ble_advdata_encode(&advData, mAdvDataBuf, &gapAdvData.adv_data.len); SuccessOrExit(err); // Initialize the CHIP BLE Device Identification Information block that will be sent as payload @@ -637,16 +640,16 @@ CHIP_ERROR BLEManagerImpl::EncodeAdvertisingData(ble_gap_adv_data_t & gapAdvData // Form the contents of the scan response packet. memset(&serviceData, 0, sizeof(serviceData)); serviceData.service_uuid = UUID16_CHIPoBLEService; - serviceData.data.size = sizeof(deviceIdInfo); - serviceData.data.p_data = (uint8_t *)&deviceIdInfo; + serviceData.data.size = sizeof(deviceIdInfo); + serviceData.data.p_data = (uint8_t *) &deviceIdInfo; memset(&advData, 0, sizeof(advData)); - advData.name_type = BLE_ADVDATA_NO_NAME; - advData.include_appearance = false; - advData.p_service_data_array = &serviceData; - advData.service_data_count = 1; + advData.name_type = BLE_ADVDATA_NO_NAME; + advData.include_appearance = false; + advData.p_service_data_array = &serviceData; + advData.service_data_count = 1; gapAdvData.scan_rsp_data.p_data = mScanRespDataBuf; - gapAdvData.scan_rsp_data.len = sizeof(mScanRespDataBuf); - err = ble_advdata_encode(&advData, mScanRespDataBuf, &gapAdvData.scan_rsp_data.len); + gapAdvData.scan_rsp_data.len = sizeof(mScanRespDataBuf); + err = ble_advdata_encode(&advData, mScanRespDataBuf, &gapAdvData.scan_rsp_data.len); SuccessOrExit(err); exit: @@ -673,7 +676,7 @@ void BLEManagerImpl::DriveBLEState(intptr_t arg) void BLEManagerImpl::HandleSoftDeviceBLEEvent(const ChipDeviceEvent * event) { - CHIP_ERROR err = CHIP_NO_ERROR; + CHIP_ERROR err = CHIP_NO_ERROR; const ble_evt_t * bleEvent = &event->Platform.SoftDeviceBLEEvent.EventData; ChipLogDetail(DeviceLayer, "BLE SoftDevice event 0x%02x", bleEvent->header.evt_id); @@ -692,18 +695,14 @@ void BLEManagerImpl::HandleSoftDeviceBLEEvent(const ChipDeviceEvent * event) case BLE_GAP_EVT_SEC_PARAMS_REQUEST: // BLE Pairing not supported - err = sd_ble_gap_sec_params_reply(bleEvent->evt.gap_evt.conn_handle, - BLE_GAP_SEC_STATUS_PAIRING_NOT_SUPP, - NULL, - NULL); + err = sd_ble_gap_sec_params_reply(bleEvent->evt.gap_evt.conn_handle, BLE_GAP_SEC_STATUS_PAIRING_NOT_SUPP, NULL, NULL); SuccessOrExit(err); break; - case BLE_GAP_EVT_PHY_UPDATE_REQUEST: - { + case BLE_GAP_EVT_PHY_UPDATE_REQUEST: { ChipLogDetail(DeviceLayer, "BLE GAP PHY update request (con %" PRIu16 ")", bleEvent->evt.gap_evt.conn_handle); const ble_gap_phys_t phys = { BLE_GAP_PHY_AUTO, BLE_GAP_PHY_AUTO }; - err = sd_ble_gap_phy_update(bleEvent->evt.gap_evt.conn_handle, &phys); + err = sd_ble_gap_phy_update(bleEvent->evt.gap_evt.conn_handle, &phys); SuccessOrExit(err); break; } @@ -715,8 +714,7 @@ void BLEManagerImpl::HandleSoftDeviceBLEEvent(const ChipDeviceEvent * event) case BLE_GATTS_EVT_TIMEOUT: ChipLogProgress(DeviceLayer, "BLE GATT Server timeout (con %" PRIu16 ")", bleEvent->evt.gatts_evt.conn_handle); - err = sd_ble_gap_disconnect(bleEvent->evt.gatts_evt.conn_handle, - BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION); + err = sd_ble_gap_disconnect(bleEvent->evt.gatts_evt.conn_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION); SuccessOrExit(err); break; @@ -760,12 +758,12 @@ void BLEManagerImpl::SoftDeviceBLEEventCallback(const ble_evt_t * bleEvent, void bleEvent->evt.gatts_evt.params.write.handle == sInstance.mCHIPoBLECharHandle_RX.value_handle) { PacketBuffer * buf; - const uint16_t valLen = bleEvent->evt.gatts_evt.params.write.len; + const uint16_t valLen = bleEvent->evt.gatts_evt.params.write.len; const uint16_t minBufSize = CHIP_SYSTEM_PACKETBUFFER_HEADER_SIZE + valLen; // Attempt to allocate a packet buffer with enough space to hold the characteristic value. // Note that we must use pbuf_alloc() directly, as PacketBuffer::New() is not interrupt-safe. - buf = (PacketBuffer *)(pbuf_alloc(PBUF_RAW, minBufSize, PBUF_POOL)); + buf = (PacketBuffer *) (pbuf_alloc(PBUF_RAW, minBufSize, PBUF_POOL)); // If successful... if (buf != NULL) @@ -775,10 +773,10 @@ void BLEManagerImpl::SoftDeviceBLEEventCallback(const ble_evt_t * bleEvent, void buf->SetDataLength(valLen); // Arrange to post a CHIPoBLERXWriteEvent event to the CHIP queue. - event.Type = DeviceEventType::kCHIPoBLERXCharWriteEvent; - event.Platform.RXCharWriteEvent.ConId = bleEvent->evt.gatts_evt.conn_handle; + event.Type = DeviceEventType::kCHIPoBLERXCharWriteEvent; + event.Platform.RXCharWriteEvent.ConId = bleEvent->evt.gatts_evt.conn_handle; event.Platform.RXCharWriteEvent.WriteArgs = bleEvent->evt.gatts_evt.params.write; - event.Platform.RXCharWriteEvent.Data = buf; + event.Platform.RXCharWriteEvent.Data = buf; } // If we failed to allocate a buffer, post a kCHIPoBLEOutOfBuffersEvent event. @@ -801,7 +799,8 @@ void BLEManagerImpl::SoftDeviceBLEEventCallback(const ble_evt_t * bleEvent, void // Ignore any write event for anything *other* than the CHIPoBLE TX CCCD value. VerifyOrExit(bleEvent->header.evt_id != BLE_GATTS_EVT_WRITE || - bleEvent->evt.gatts_evt.params.write.handle == sInstance.mCHIPoBLECharHandle_TX.cccd_handle, /**/); + bleEvent->evt.gatts_evt.params.write.handle == sInstance.mCHIPoBLECharHandle_TX.cccd_handle, + /**/); // Arrange to post a SoftDeviceBLEEvent containing a copy of the BLE event. event.Type = DeviceEventType::kSoftDeviceBLEEvent; @@ -845,7 +844,8 @@ CHIP_ERROR BLEManagerImpl::HandleGAPDisconnect(const ChipDeviceEvent * event) { const ble_gap_evt_t * gapEvent = &event->Platform.SoftDeviceBLEEvent.EventData.evt.gap_evt; - ChipLogProgress(DeviceLayer, "BLE GAP connection terminated (con %" PRIu16 ", reason 0x%02" PRIx8 ")", gapEvent->conn_handle, gapEvent->params.disconnected.reason); + ChipLogProgress(DeviceLayer, "BLE GAP connection terminated (con %" PRIu16 ", reason 0x%02" PRIx8 ")", gapEvent->conn_handle, + gapEvent->params.disconnected.reason); // Update the number of GAP connections. if (mNumGAPCons > 0) @@ -883,7 +883,7 @@ CHIP_ERROR BLEManagerImpl::HandleGAPDisconnect(const ChipDeviceEvent * event) CHIP_ERROR BLEManagerImpl::HandleRXCharWrite(const ChipDeviceEvent * event) { - CHIP_ERROR err = CHIP_NO_ERROR; + CHIP_ERROR err = CHIP_NO_ERROR; PacketBuffer * buf = event->Platform.RXCharWriteEvent.Data; // Only allow write requests or write commands. @@ -895,7 +895,7 @@ CHIP_ERROR BLEManagerImpl::HandleRXCharWrite(const ChipDeviceEvent * event) // indications on the TX characteristic. ChipLogDetail(DeviceLayer, "Write request/command received for CHIPoBLE RX characteristic (con %" PRIu16 ", len %" PRIu16 ")", - event->Platform.RXCharWriteEvent.ConId, buf->DataLength()); + event->Platform.RXCharWriteEvent.ConId, buf->DataLength()); // Pass the data to the BLEEndPoint HandleWriteReceived(event->Platform.RXCharWriteEvent.ConId, &CHIP_BLE_SVC_ID, &chipUUID_CHIPoBLEChar_RX, buf); @@ -908,27 +908,29 @@ CHIP_ERROR BLEManagerImpl::HandleRXCharWrite(const ChipDeviceEvent * event) CHIP_ERROR BLEManagerImpl::HandleTXCharCCCDWrite(const ChipDeviceEvent * event) { - CHIP_ERROR err = CHIP_NO_ERROR; + CHIP_ERROR err = CHIP_NO_ERROR; const ble_gatts_evt_t * gattsEvent = &event->Platform.SoftDeviceBLEEvent.EventData.evt.gatts_evt; bool indicationsEnabled; enum { // Per the BLE GATT spec... - kCCCDBit_NotificationsEnabled = 0x0001, - kCCCDBit_IndicationsEnabled = 0x0002, + kCCCDBit_NotificationsEnabled = 0x0001, + kCCCDBit_IndicationsEnabled = 0x0002, }; // Only allow write requests or write commands. VerifyOrExit((gattsEvent->params.write.op == BLE_GATTS_OP_WRITE_REQ || gattsEvent->params.write.op == BLE_GATTS_OP_WRITE_CMD), err = CHIP_ERROR_INVALID_ARGUMENT); - ChipLogDetail(DeviceLayer, "Write request/command received for CHIPoBLE TX CCCD characteristic (con %" PRIu16 ", len %" PRIu16 ")", - gattsEvent->conn_handle, gattsEvent->params.write.len); + ChipLogDetail(DeviceLayer, + "Write request/command received for CHIPoBLE TX CCCD characteristic (con %" PRIu16 ", len %" PRIu16 ")", + gattsEvent->conn_handle, gattsEvent->params.write.len); // Ignore the write request if the value is 0 length. VerifyOrExit(gattsEvent->params.write.len > 0, /**/); - ChipLogDetail(DeviceLayer, "CCCD value: 0x%04" PRIx16, (((uint16_t)gattsEvent->params.write.data[1]) << 8) | gattsEvent->params.write.data[0]); + ChipLogDetail(DeviceLayer, "CCCD value: 0x%04" PRIx16, + (((uint16_t) gattsEvent->params.write.data[1]) << 8) | gattsEvent->params.write.data[0]); // Determine if the client is enabling or disabling indications. indicationsEnabled = ((gattsEvent->params.write.data[0] & kCCCDBit_IndicationsEnabled) != 0); @@ -955,8 +957,10 @@ CHIP_ERROR BLEManagerImpl::HandleTXCharCCCDWrite(const ChipDeviceEvent * event) gattMTU = nrf_ble_gatt_eff_mtu_get(&GATTModule, gattsEvent->conn_handle); nrf_ble_gatt_data_length_get(&GATTModule, gattsEvent->conn_handle, &packetDataLen); - ChipLogProgress(DeviceLayer, "CHIPoBLE connection established (con %" PRIu16 ", packet data len %" PRIu8 ", GATT MTU %" PRIu16 ")", - gattsEvent->conn_handle, packetDataLen, gattMTU); + ChipLogProgress(DeviceLayer, + "CHIPoBLE connection established (con %" PRIu16 ", packet data len %" PRIu8 ", GATT MTU %" PRIu16 + ")", + gattsEvent->conn_handle, packetDataLen, gattMTU); } #endif // CHIP_PROGRESS_LOGGING @@ -987,7 +991,8 @@ CHIP_ERROR BLEManagerImpl::HandleTXComplete(const ChipDeviceEvent * event) { const ble_gatts_evt_t * gattsEvent = &event->Platform.SoftDeviceBLEEvent.EventData.evt.gatts_evt; - ChipLogDetail(DeviceLayer, "Confirm received for CHIPoBLE TX characteristic indication (con %" PRIu16 ")", gattsEvent->conn_handle); + ChipLogDetail(DeviceLayer, "Confirm received for CHIPoBLE TX characteristic indication (con %" PRIu16 ")", + gattsEvent->conn_handle); // Signal the BLE Layer that the outstanding indication is complete. HandleIndicationConfirmation(gattsEvent->conn_handle, &CHIP_BLE_SVC_ID, &chipUUID_CHIPoBLEChar_TX); @@ -1050,7 +1055,6 @@ bool BLEManagerImpl::IsSubscribed(uint16_t conId) return false; } - } // namespace Internal } // namespace DeviceLayer } // namespace chip diff --git a/src/platform/nRF5/ConfigurationManagerImpl.cpp b/src/platform/nRF5/ConfigurationManagerImpl.cpp index 0e6d7280f0d260..e068d4fa378e95 100644 --- a/src/platform/nRF5/ConfigurationManagerImpl.cpp +++ b/src/platform/nRF5/ConfigurationManagerImpl.cpp @@ -1,4 +1,4 @@ - /* +/* * * Copyright (c) 2020 Project CHIP Authors * Copyright (c) 2018 Nest Labs, Inc. @@ -47,12 +47,10 @@ GroupKeyStoreImpl gGroupKeyStore; } // unnamed namespace - /** Singleton instance of the ConfigurationManager implementation object. */ ConfigurationManagerImpl ConfigurationManagerImpl::sInstance; - CHIP_ERROR ConfigurationManagerImpl::_Init() { CHIP_ERROR err; @@ -70,8 +68,8 @@ CHIP_ERROR ConfigurationManagerImpl::_Init() { FactoryProvisioning factoryProv; - uint8_t * const kDeviceRAMStart = (uint8_t *)0x20000000; - uint8_t * const kDeviceRAMEnd = kDeviceRAMStart + (NRF_FICR->INFO.RAM * 1024) - 1; + uint8_t * const kDeviceRAMStart = (uint8_t *) 0x20000000; + uint8_t * const kDeviceRAMEnd = kDeviceRAMStart + (NRF_FICR->INFO.RAM * 1024) - 1; // Scan device RAM for injected provisioning data and save to persistent storage if found. err = factoryProv.ProvisionDeviceFromRAM(kDeviceRAMStart, kDeviceRAMEnd); @@ -103,7 +101,8 @@ void ConfigurationManagerImpl::_InitiateFactoryReset() PlatformMgr().ScheduleWork(DoFactoryReset); } -CHIP_ERROR ConfigurationManagerImpl::_ReadPersistedStorageValue(::chip::Platform::PersistedStorage::Key persistedStorageKey, uint32_t & value) +CHIP_ERROR ConfigurationManagerImpl::_ReadPersistedStorageValue(::chip::Platform::PersistedStorage::Key persistedStorageKey, + uint32_t & value) { CHIP_ERROR err; uint16_t recordKey = persistedStorageKey + kPersistedCounterRecordKeyBase; @@ -121,7 +120,8 @@ CHIP_ERROR ConfigurationManagerImpl::_ReadPersistedStorageValue(::chip::Platform return err; } -CHIP_ERROR ConfigurationManagerImpl::_WritePersistedStorageValue(::chip::Platform::PersistedStorage::Key persistedStorageKey, uint32_t value) +CHIP_ERROR ConfigurationManagerImpl::_WritePersistedStorageValue(::chip::Platform::PersistedStorage::Key persistedStorageKey, + uint32_t value) { CHIP_ERROR err; uint16_t recordKey = persistedStorageKey + kPersistedCounterRecordKeyBase; diff --git a/src/platform/nRF5/ConnectivityManagerImpl.cpp b/src/platform/nRF5/ConnectivityManagerImpl.cpp index 06a4e460ec35ba..649e05149fc1d0 100644 --- a/src/platform/nRF5/ConnectivityManagerImpl.cpp +++ b/src/platform/nRF5/ConnectivityManagerImpl.cpp @@ -38,7 +38,6 @@ #include #endif - using namespace ::chip; using namespace ::chip::TLV; using namespace ::chip::DeviceLayer::Internal; @@ -48,7 +47,6 @@ namespace DeviceLayer { ConnectivityManagerImpl ConnectivityManagerImpl::sInstance; - CHIP_ERROR ConnectivityManagerImpl::_Init() { CHIP_ERROR err = CHIP_NO_ERROR; diff --git a/src/platform/nRF5/Entropy.cpp b/src/platform/nRF5/Entropy.cpp index d877cc09e32aeb..7cad7014783df7 100644 --- a/src/platform/nRF5/Entropy.cpp +++ b/src/platform/nRF5/Entropy.cpp @@ -118,8 +118,8 @@ int GetEntropy_nRF5(uint8_t * buf, size_t count) // In the absence of the SoftDevice, call the OpenThread platform API for // retrieving entropy. - otError otErr = otPlatRandomGetTrue(buf, (uint16_t)count); - res = (otErr == OT_ERROR_NONE); + otError otErr = otPlatRandomGetTrue(buf, (uint16_t) count); + res = (otErr == OT_ERROR_NONE); #endif // SOFTDEVICE_PRESENT @@ -144,7 +144,7 @@ CHIP_ERROR InitEntropy() // Seed the standard rand() pseudo-random generator with data from the secure random source. { unsigned int seed; - err = Platform::Security::GetSecureRandomData((uint8_t *)&seed, sizeof(seed)); + err = Platform::Security::GetSecureRandomData((uint8_t *) &seed, sizeof(seed)); SuccessOrExit(err); srand(seed); } diff --git a/src/platform/nRF5/GroupKeyStoreImpl.cpp b/src/platform/nRF5/GroupKeyStoreImpl.cpp index 9275eb11301289..af321ba3448843 100644 --- a/src/platform/nRF5/GroupKeyStoreImpl.cpp +++ b/src/platform/nRF5/GroupKeyStoreImpl.cpp @@ -39,31 +39,29 @@ CHIP_ERROR GroupKeyStoreImpl::RetrieveGroupKey(uint32_t keyId, ChipGroupKey & ke CHIP_ERROR err; // Iterate over all the GroupKey records looking for a matching key... - err = ForEachRecord(kGroupKeyFileId, kGroupKeyRecordKey, - [keyId, &key](const fds_flash_record_t & rec, bool & deleteRec) -> CHIP_ERROR - { - uint32_t curKeyId; - CHIP_ERROR err2 = CHIP_NO_ERROR; - - // Decode the CHIP key id for the current key. - err2 = DecodeGroupKeyId((const uint8_t *)rec.p_data, rec.p_header->length_words * kFDSWordSize, curKeyId); - SuccessOrExit(err2); - - // If it matches the key we're looking for... - if (curKeyId == keyId) - { - // Decode the associated key data. - err2 = DecodeGroupKey((const uint8_t *)rec.p_data, rec.p_header->length_words * kFDSWordSize, key); - SuccessOrExit(err2); - - // End the iteration by returning a CHIP_END_OF_INPUT result. - ExitNow(err2 = CHIP_END_OF_INPUT); - } - - exit: - return err2; - } - ); + err = ForEachRecord( + kGroupKeyFileId, kGroupKeyRecordKey, [keyId, &key](const fds_flash_record_t & rec, bool & deleteRec) -> CHIP_ERROR { + uint32_t curKeyId; + CHIP_ERROR err2 = CHIP_NO_ERROR; + + // Decode the CHIP key id for the current key. + err2 = DecodeGroupKeyId((const uint8_t *) rec.p_data, rec.p_header->length_words * kFDSWordSize, curKeyId); + SuccessOrExit(err2); + + // If it matches the key we're looking for... + if (curKeyId == keyId) + { + // Decode the associated key data. + err2 = DecodeGroupKey((const uint8_t *) rec.p_data, rec.p_header->length_words * kFDSWordSize, key); + SuccessOrExit(err2); + + // End the iteration by returning a CHIP_END_OF_INPUT result. + ExitNow(err2 = CHIP_END_OF_INPUT); + } + + exit: + return err2; + }); // If a matching key was found, return success. if (err == CHIP_END_OF_INPUT) @@ -93,7 +91,7 @@ CHIP_ERROR GroupKeyStoreImpl::StoreGroupKey(const ChipGroupKey & key) SuccessOrExit(err); // Allocate a buffer to hold the encoded key. - storedVal = (uint8_t *)nrf_malloc(storedValLen); + storedVal = (uint8_t *) nrf_malloc(storedValLen); VerifyOrExit(storedVal != NULL, err = CHIP_ERROR_NO_MEMORY); // Encode the key for storage in an FDS record. @@ -103,11 +101,11 @@ CHIP_ERROR GroupKeyStoreImpl::StoreGroupKey(const ChipGroupKey & key) // Add a GroupKey FDS record containing the encoded key. { FDSAsyncOp addOp(FDSAsyncOp::kAddRecord); - addOp.FileId = kGroupKeyFileId; - addOp.RecordKey = kGroupKeyRecordKey; - addOp.RecordData = storedVal; + addOp.FileId = kGroupKeyFileId; + addOp.RecordKey = kGroupKeyRecordKey; + addOp.RecordData = storedVal; addOp.RecordDataLengthWords = FDSWords(storedValLen); - err = DoAsyncFDSOp(addOp); + err = DoAsyncFDSOp(addOp); SuccessOrExit(err); } @@ -129,11 +127,12 @@ CHIP_ERROR GroupKeyStoreImpl::StoreGroupKey(const ChipGroupKey & key) } #if CHIP_CONFIG_SECURITY_TEST_MODE - ChipLogProgress(SecurityManager, "GroupKeyStore: storing key 0x%08" PRIX32 " (%s), len %" PRId8 ", data 0x%02" PRIX8 "...%s", - key.KeyId, ChipKeyId::DescribeKey(key.KeyId), key.KeyLen, key.Key[0], extraKeyInfo); + ChipLogProgress(SecurityManager, + "GroupKeyStore: storing key 0x%08" PRIX32 " (%s), len %" PRId8 ", data 0x%02" PRIX8 "...%s", key.KeyId, + ChipKeyId::DescribeKey(key.KeyId), key.KeyLen, key.Key[0], extraKeyInfo); #else - ChipLogProgress(SecurityManager, "GroupKeyStore: storing key 0x%08" PRIX32 " (%s), len %" PRId8 "%s", - key.KeyId, ChipKeyId::DescribeKey(key.KeyId), key.KeyLen, extraKeyInfo); + ChipLogProgress(SecurityManager, "GroupKeyStore: storing key 0x%08" PRIX32 " (%s), len %" PRId8 "%s", key.KeyId, + ChipKeyId::DescribeKey(key.KeyId), key.KeyLen, extraKeyInfo); #endif } @@ -153,28 +152,26 @@ CHIP_ERROR GroupKeyStoreImpl::DeleteGroupKey(uint32_t keyId) CHIP_ERROR err; // Iterate over all the GroupKey records looking for matching keys... - err = ForEachRecord(kGroupKeyFileId, kGroupKeyRecordKey, - [keyId](const fds_flash_record_t & rec, bool & deleteRec) -> CHIP_ERROR - { - uint32_t curKeyId; - CHIP_ERROR err2; - - // Decode the CHIP key id for the current group key. - err2 = DecodeGroupKeyId((const uint8_t *)rec.p_data, rec.p_header->length_words * kFDSWordSize, curKeyId); - SuccessOrExit(err2); - - // If it matches the key looking for, arrange for the record to be deleted. - deleteRec = (curKeyId == keyId); - - if (deleteRec) - { - ChipLogProgress(DeviceLayer, "GroupKeyStore: deleting key 0x%08" PRIX32, curKeyId); - } - - exit: - return err2; - } - ); + err = + ForEachRecord(kGroupKeyFileId, kGroupKeyRecordKey, [keyId](const fds_flash_record_t & rec, bool & deleteRec) -> CHIP_ERROR { + uint32_t curKeyId; + CHIP_ERROR err2; + + // Decode the CHIP key id for the current group key. + err2 = DecodeGroupKeyId((const uint8_t *) rec.p_data, rec.p_header->length_words * kFDSWordSize, curKeyId); + SuccessOrExit(err2); + + // If it matches the key looking for, arrange for the record to be deleted. + deleteRec = (curKeyId == keyId); + + if (deleteRec) + { + ChipLogProgress(DeviceLayer, "GroupKeyStore: deleting key 0x%08" PRIX32, curKeyId); + } + + exit: + return err2; + }); SuccessOrExit(err); exit: @@ -186,66 +183,62 @@ CHIP_ERROR GroupKeyStoreImpl::DeleteGroupKeysOfAType(uint32_t keyType) CHIP_ERROR err; // Iterate over all the GroupKey records looking for matching keys... - err = ForEachRecord(kGroupKeyFileId, kGroupKeyRecordKey, - [keyType](const fds_flash_record_t & rec, bool & deleteRec) -> CHIP_ERROR - { - uint32_t curKeyId; - CHIP_ERROR err2; - - // Decode the CHIP key id for the current group key. - err2 = DecodeGroupKeyId((const uint8_t *)rec.p_data, rec.p_header->length_words * kFDSWordSize, curKeyId); - SuccessOrExit(err2); - - // If the current key matches the type we're looking for, arrange for the - // record to be deleted. - deleteRec = (ChipKeyId::GetType(curKeyId) == keyType); - - if (deleteRec) - { - ChipLogProgress(DeviceLayer, "GroupKeyStore: deleting key 0x%08" PRIX32, curKeyId); - } - - exit: - return err2; - } - ); + err = ForEachRecord( + kGroupKeyFileId, kGroupKeyRecordKey, [keyType](const fds_flash_record_t & rec, bool & deleteRec) -> CHIP_ERROR { + uint32_t curKeyId; + CHIP_ERROR err2; + + // Decode the CHIP key id for the current group key. + err2 = DecodeGroupKeyId((const uint8_t *) rec.p_data, rec.p_header->length_words * kFDSWordSize, curKeyId); + SuccessOrExit(err2); + + // If the current key matches the type we're looking for, arrange for the + // record to be deleted. + deleteRec = (ChipKeyId::GetType(curKeyId) == keyType); + + if (deleteRec) + { + ChipLogProgress(DeviceLayer, "GroupKeyStore: deleting key 0x%08" PRIX32, curKeyId); + } + + exit: + return err2; + }); SuccessOrExit(err); exit: return err; } -CHIP_ERROR GroupKeyStoreImpl::EnumerateGroupKeys(uint32_t keyType, uint32_t * keyIds, - uint8_t keyIdsArraySize, uint8_t & keyCount) +CHIP_ERROR GroupKeyStoreImpl::EnumerateGroupKeys(uint32_t keyType, uint32_t * keyIds, uint8_t keyIdsArraySize, uint8_t & keyCount) { CHIP_ERROR err; keyCount = 0; // Iterate over all the GroupKey records looking for keys of the specified type... - err = ForEachRecord(kGroupKeyFileId, kGroupKeyRecordKey, - [keyType, keyIds, keyIdsArraySize, &keyCount](const fds_flash_record_t & rec, bool & deleteRec) -> CHIP_ERROR - { - uint32_t curKeyId; - CHIP_ERROR err2 = CHIP_NO_ERROR; - - // Decode the CHIP key id for the current key. - err2 = DecodeGroupKeyId((const uint8_t *)rec.p_data, rec.p_header->length_words * kFDSWordSize, curKeyId); - SuccessOrExit(err2); - - // If the current key matches the type we're looking for, add it to the keyIds array. - if (keyType == ChipKeyId::kType_None || ChipKeyId::GetType(curKeyId) == keyType) - { - keyIds[keyCount++] = curKeyId; - - // Stop iterating if there's no more room in the keyIds array. - VerifyOrExit(keyCount < keyIdsArraySize, err2 = CHIP_ERROR_BUFFER_TOO_SMALL); - } - - exit: - return err2; - } - ); + err = ForEachRecord( + kGroupKeyFileId, kGroupKeyRecordKey, + [keyType, keyIds, keyIdsArraySize, &keyCount](const fds_flash_record_t & rec, bool & deleteRec) -> CHIP_ERROR { + uint32_t curKeyId; + CHIP_ERROR err2 = CHIP_NO_ERROR; + + // Decode the CHIP key id for the current key. + err2 = DecodeGroupKeyId((const uint8_t *) rec.p_data, rec.p_header->length_words * kFDSWordSize, curKeyId); + SuccessOrExit(err2); + + // If the current key matches the type we're looking for, add it to the keyIds array. + if (keyType == ChipKeyId::kType_None || ChipKeyId::GetType(curKeyId) == keyType) + { + keyIds[keyCount++] = curKeyId; + + // Stop iterating if there's no more room in the keyIds array. + VerifyOrExit(keyCount < keyIdsArraySize, err2 = CHIP_ERROR_BUFFER_TOO_SMALL); + } + + exit: + return err2; + }); // Simply return a truncated list if there are more matching keys than will fit in the array. if (err == CHIP_ERROR_BUFFER_TOO_SMALL) @@ -263,13 +256,10 @@ CHIP_ERROR GroupKeyStoreImpl::Clear(void) CHIP_ERROR err; // Iterate over all GroupKey records deleting each one. - err = ForEachRecord(kGroupKeyFileId, kGroupKeyRecordKey, - [](const fds_flash_record_t & rec, bool & deleteRec) -> CHIP_ERROR - { - deleteRec = true; - return CHIP_NO_ERROR; - } - ); + err = ForEachRecord(kGroupKeyFileId, kGroupKeyRecordKey, [](const fds_flash_record_t & rec, bool & deleteRec) -> CHIP_ERROR { + deleteRec = true; + return CHIP_NO_ERROR; + }); SuccessOrExit(err); ChipLogProgress(DeviceLayer, "GroupKeyStore: cleared"); @@ -286,7 +276,7 @@ CHIP_ERROR GroupKeyStoreImpl::RetrieveLastUsedEpochKeyId(void) if (err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND) { LastUsedEpochKeyId = ChipKeyId::kNone; - err = CHIP_NO_ERROR; + err = CHIP_NO_ERROR; } return err; } @@ -305,7 +295,7 @@ CHIP_ERROR GroupKeyStoreImpl::Init() CHIP_ERROR GroupKeyStoreImpl::EncodeGroupKey(const ChipGroupKey & key, uint8_t * buf, size_t bufSize, size_t & encodedKeyLen) { CHIP_ERROR err = CHIP_NO_ERROR; - uint8_t * p = buf; + uint8_t * p = buf; VerifyOrExit(bufSize >= kFixedEncodedKeySize + key.KeyLen, err = CHIP_ERROR_BUFFER_TOO_SMALL); @@ -323,14 +313,14 @@ CHIP_ERROR GroupKeyStoreImpl::EncodeGroupKey(const ChipGroupKey & key, uint8_t * CHIP_ERROR GroupKeyStoreImpl::DecodeGroupKey(const uint8_t * encodedKey, size_t encodedKeyLen, ChipGroupKey & key) { - CHIP_ERROR err = CHIP_NO_ERROR; + CHIP_ERROR err = CHIP_NO_ERROR; const uint8_t * p = encodedKey; VerifyOrExit(encodedKeyLen >= kFixedEncodedKeySize, err = CHIP_ERROR_INVALID_ARGUMENT); - key.KeyId = Encoding::LittleEndian::Read32(p); + key.KeyId = Encoding::LittleEndian::Read32(p); key.StartTime = Encoding::LittleEndian::Read32(p); - key.KeyLen = Encoding::Read8(p); + key.KeyLen = Encoding::Read8(p); VerifyOrExit(encodedKeyLen >= kFixedEncodedKeySize + key.KeyLen, err = CHIP_ERROR_INVALID_ARGUMENT); @@ -355,4 +345,3 @@ CHIP_ERROR GroupKeyStoreImpl::DecodeGroupKeyId(const uint8_t * encodedKey, size_ } // namespace Internal } // namespace DeviceLayer } // namespace chip - diff --git a/src/platform/nRF5/Logging.cpp b/src/platform/nRF5/Logging.cpp index 456c4287449c4c..197cfe75f2afc4 100644 --- a/src/platform/nRF5/Logging.cpp +++ b/src/platform/nRF5/Logging.cpp @@ -45,7 +45,7 @@ using namespace ::chip::DeviceLayer::Internal; namespace { -void GetModuleName(char *buf, uint8_t module) +void GetModuleName(char * buf, uint8_t module) { if (module == ::chip::Logging::kLogModule_DeviceLayer) { @@ -68,14 +68,11 @@ namespace DeviceLayer { * This function is intended be overridden by the application to, e.g., * schedule output of queued log entries. */ -void __attribute__((weak)) OnLogOutput(void) -{ -} +void __attribute__((weak)) OnLogOutput(void) {} } // namespace DeviceLayer } // namespace chip - NRF_LOG_MODULE_REGISTER(); namespace chip { @@ -84,12 +81,12 @@ namespace Logging { /** * Openchip log output function. */ -void Log(uint8_t module, uint8_t category, const char *msg, ...) +void Log(uint8_t module, uint8_t category, const char * msg, ...) { va_list v; - (void)module; - (void)category; + (void) module; + (void) category; va_start(v, msg); @@ -107,7 +104,7 @@ void Log(uint8_t module, uint8_t category, const char *msg, ...) // Form the log prefix, e.g. "[DL] " formattedMsg[0] = '['; ::GetModuleName(formattedMsg + 1, module); - prefixLen = strlen(formattedMsg); + prefixLen = strlen(formattedMsg); formattedMsg[prefixLen++] = ']'; formattedMsg[prefixLen++] = ' '; @@ -115,7 +112,8 @@ void Log(uint8_t module, uint8_t category, const char *msg, ...) vsnprintf(formattedMsg + prefixLen, sizeof(formattedMsg) - prefixLen, msg, v); // Invoke the NRF logging library to log the message. - switch (category) { + switch (category) + { case kLogCategory_Error: NRF_LOG_ERROR("%s", NRF_LOG_PUSH(formattedMsg)); break; @@ -142,7 +140,6 @@ void Log(uint8_t module, uint8_t category, const char *msg, ...) } // namespace Logging } // namespace chip - #undef NRF_LOG_MODULE_NAME #define NRF_LOG_MODULE_NAME lwip NRF_LOG_MODULE_REGISTER(); @@ -150,8 +147,7 @@ NRF_LOG_MODULE_REGISTER(); /** * LwIP log output function. */ -extern "C" -void LwIPLog(const char *msg, ...) +extern "C" void LwIPLog(const char * msg, ...) { va_list v; @@ -164,7 +160,7 @@ void LwIPLog(const char *msg, ...) // Append the log message. size_t len = vsnprintf(formattedMsg, sizeof(formattedMsg), msg, v); - while (len > 0 && isspace(formattedMsg[len-1])) + while (len > 0 && isspace(formattedMsg[len - 1])) { len--; formattedMsg[len] = 0; @@ -188,13 +184,12 @@ void LwIPLog(const char *msg, ...) #define NRF_LOG_MODULE_NAME thread NRF_LOG_MODULE_REGISTER(); -extern "C" -void otPlatLog(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat, ...) +extern "C" void otPlatLog(otLogLevel aLogLevel, otLogRegion aLogRegion, const char * aFormat, ...) { va_list v; - (void)aLogLevel; - (void)aLogRegion; + (void) aLogLevel; + (void) aLogRegion; va_start(v, aFormat); @@ -206,7 +201,8 @@ void otPlatLog(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat vsnprintf(formattedMsg, sizeof(formattedMsg), aFormat, v); // Invoke the NRF logging library to log the message. - switch (aLogLevel) { + switch (aLogLevel) + { case OT_LOG_LEVEL_CRIT: NRF_LOG_ERROR("%s", NRF_LOG_PUSH(formattedMsg)); break; diff --git a/src/platform/nRF5/SoftwareUpdateManagerImpl.cpp b/src/platform/nRF5/SoftwareUpdateManagerImpl.cpp index a3e15f3757588e..7622520a83a4ca 100644 --- a/src/platform/nRF5/SoftwareUpdateManagerImpl.cpp +++ b/src/platform/nRF5/SoftwareUpdateManagerImpl.cpp @@ -16,7 +16,6 @@ * limitations under the License. */ - #include #if CHIP_DEVICE_CONFIG_ENABLE_SOFTWARE_UPDATE_MANAGER diff --git a/src/platform/nRF5/ThreadStackManagerImpl.cpp b/src/platform/nRF5/ThreadStackManagerImpl.cpp index 98910f02c734b7..e69705482816d8 100644 --- a/src/platform/nRF5/ThreadStackManagerImpl.cpp +++ b/src/platform/nRF5/ThreadStackManagerImpl.cpp @@ -109,8 +109,7 @@ using namespace ::chip::DeviceLayer; * Glue function called directly by the OpenThread stack when tasklet processing work * is pending. */ -extern "C" -void otTaskletsSignalPending(otInstance * p_instance) +extern "C" void otTaskletsSignalPending(otInstance * p_instance) { ThreadStackMgrImpl().SignalThreadActivityPending(); } @@ -119,10 +118,8 @@ void otTaskletsSignalPending(otInstance * p_instance) * Glue function called directly by the OpenThread stack when system event processing work * is pending. */ -extern "C" -void otSysEventSignalPending(void) +extern "C" void otSysEventSignalPending(void) { BaseType_t yieldRequired = ThreadStackMgrImpl().SignalThreadActivityPendingFromISR(); portYIELD_FROM_ISR(yieldRequired); } - diff --git a/src/platform/nRF5/nRF52840-OVERVIEW.md b/src/platform/nRF5/nRF52840-OVERVIEW.md index 01b0bdfa337b84..38490624a69070 100644 --- a/src/platform/nRF5/nRF52840-OVERVIEW.md +++ b/src/platform/nRF5/nRF52840-OVERVIEW.md @@ -1,51 +1,60 @@ # Overview of CHIP nRF52840 Adaption -The following is a quick overview of the nRF5 adaptation of CHIP. Most of this code will have parallels in any new adaptation. +The following is a quick overview of the nRF5 adaptation of CHIP. Most of this +code will have parallels in any new adaptation. (All file names are relative to `connectedhomeip/src/...`). `include/platform/nRF5/PlatformManagerImpl.h`
`nRF5/PlatformManagerImpl.cpp` -- Concrete implementation of PlatformManager interface -- Provides initialization of the CHIP stack and core event loop for the chip task -- Relies on GenericPlatformManagerImpl_FreeRTOS<> class to provide most of the implementation +- Concrete implementation of PlatformManager interface +- Provides initialization of the CHIP stack and core event loop for the chip + task +- Relies on GenericPlatformManagerImpl_FreeRTOS<> class to provide most of the + implementation `include/platform/nRF5/ConfigurationManagerImpl.h`
`nRF5/ConfigurationManagerImpl.cpp` -- Concrete implementation of ConfigurationManager interface -- Manages storage and retrieval of persistent configuration data -- Relies on GenericConfigurationManagerImpl<> classes to implement most API functionality -- Delegates low-level reading and writing of persistent values to NRF5Config class +- Concrete implementation of ConfigurationManager interface +- Manages storage and retrieval of persistent configuration data +- Relies on GenericConfigurationManagerImpl<> classes to implement most API + functionality +- Delegates low-level reading and writing of persistent values to NRF5Config + class `include/platform/nRF5/ConnectivityManagerImpl.h`
`nRF5/ConnectivityManagerImpl.cpp` -- Concrete implementation of ConnectivityManager interface -- Provides high-level APIs for managing device connectivity -- Relies on various generic implementation classes to provide API functionality -- Very much a work-in-progress in the nrf52840 branch +- Concrete implementation of ConnectivityManager interface +- Provides high-level APIs for managing device connectivity +- Relies on various generic implementation classes to provide API + functionality +- Very much a work-in-progress in the nrf52840 branch `include/platform/nRF5/ThreadStackManagerImpl.h`
`nRF5/ThreadStackManagerImpl.cpp` -- Concrete implementation of ThreadStackManager interface -- Supports Thread stack initialization and core event loop processing -- Relies on GenericThreadStackManagerImpl_OpenThread/FreeRTOS/LwIP<> classes to implement most API functionaltiy -- Work-in-progress [2019/04/01] +- Concrete implementation of ThreadStackManager interface +- Supports Thread stack initialization and core event loop processing +- Relies on GenericThreadStackManagerImpl_OpenThread/FreeRTOS/LwIP<> classes + to implement most API functionaltiy +- Work-in-progress [2019/04/01] `include/platform/nRF5/BLEManagerImpl.h`
`nRF5/BLEManagerImpl.cpp` -- Concrete implementation of the BLEManager interface -- Maps CHIP's BLE interface abstractions (BleLayer, BlePlatformDelegate, BleApplicationDelegate) onto the platform's native BLE services -- Implements chip-compatible BLE advertising. +- Concrete implementation of the BLEManager interface +- Maps CHIP's BLE interface abstractions (BleLayer, BlePlatformDelegate, + BleApplicationDelegate) onto the platform's native BLE services +- Implements chip-compatible BLE advertising. `platform/nRF5/Entropy.cpp` -- Implements interface to platform entropy source +- Implements interface to platform entropy source `platform/nRF5/Logging.cpp` -- Adaption of chip debug logging to platform logging facility. +- Adaption of chip debug logging to platform logging facility. `platform/nRF5/NRF5Config.cpp` -- Implements low-level read/write of persistent configuration values -- Class API specifically designed to work in conjunction with the GenericConfigurationManagerImpl<> class. +- Implements low-level read/write of persistent configuration values +- Class API specifically designed to work in conjunction with the + GenericConfigurationManagerImpl<> class. diff --git a/src/platform/nRF5/nRF5Config.cpp b/src/platform/nRF5/nRF5Config.cpp index 3100496740e76f..6fe95162021436 100644 --- a/src/platform/nRF5/nRF5Config.cpp +++ b/src/platform/nRF5/nRF5Config.cpp @@ -84,8 +84,8 @@ CHIP_ERROR NRF5Config::ReadConfigValue(Key key, bool & val) VerifyOrExit(rec.p_header->length_words == 1, err = CHIP_ERROR_INVALID_ARGUMENT); - wordVal = Encoding::LittleEndian::Get32((const uint8_t *)rec.p_data); - val = (wordVal != 0); + wordVal = Encoding::LittleEndian::Get32((const uint8_t *) rec.p_data); + val = (wordVal != 0); exit: if (needClose) @@ -108,7 +108,7 @@ CHIP_ERROR NRF5Config::ReadConfigValue(Key key, uint32_t & val) VerifyOrExit(rec.p_header->length_words == 1, err = CHIP_ERROR_INVALID_ARGUMENT); - val = Encoding::LittleEndian::Get32((const uint8_t *)rec.p_data); + val = Encoding::LittleEndian::Get32((const uint8_t *) rec.p_data); exit: if (needClose) @@ -131,7 +131,7 @@ CHIP_ERROR NRF5Config::ReadConfigValue(Key key, uint64_t & val) VerifyOrExit(rec.p_header->length_words == 2, err = CHIP_ERROR_INVALID_ARGUMENT); - val = Encoding::LittleEndian::Get64((const uint8_t *)rec.p_data); + val = Encoding::LittleEndian::Get64((const uint8_t *) rec.p_data); exit: if (needClose) @@ -153,10 +153,10 @@ CHIP_ERROR NRF5Config::ReadConfigValueStr(Key key, char * buf, size_t bufSize, s SuccessOrExit(err); needClose = true; - strEnd = (const uint8_t *)memchr(rec.p_data, 0, rec.p_header->length_words * kFDSWordSize); + strEnd = (const uint8_t *) memchr(rec.p_data, 0, rec.p_header->length_words * kFDSWordSize); VerifyOrExit(strEnd != NULL, err = CHIP_ERROR_INVALID_ARGUMENT); - outLen = strEnd - (const uint8_t *)rec.p_data; + outLen = strEnd - (const uint8_t *) rec.p_data; // NOTE: the caller is allowed to pass NULL for buf to query the length of the stored // value. @@ -190,7 +190,7 @@ CHIP_ERROR NRF5Config::ReadConfigValueBin(Key key, uint8_t * buf, size_t bufSize VerifyOrExit(rec.p_header->length_words >= 1, err = CHIP_ERROR_INVALID_ARGUMENT); // First two bytes are length. - outLen = Encoding::LittleEndian::Get16((const uint8_t *)rec.p_data); + outLen = Encoding::LittleEndian::Get16((const uint8_t *) rec.p_data); VerifyOrExit((rec.p_header->length_words * kFDSWordSize) >= (outLen + 2), err = CHIP_ERROR_INVALID_ARGUMENT); @@ -201,7 +201,7 @@ CHIP_ERROR NRF5Config::ReadConfigValueBin(Key key, uint8_t * buf, size_t bufSize { VerifyOrExit(bufSize >= outLen, err = CHIP_ERROR_BUFFER_TOO_SMALL); - memcpy(buf, ((const uint8_t *)rec.p_data) + 2, outLen); + memcpy(buf, ((const uint8_t *) rec.p_data) + 2, outLen); } exit: @@ -218,15 +218,16 @@ CHIP_ERROR NRF5Config::WriteConfigValue(Key key, bool val) uint32_t storedVal = (val) ? 1 : 0; FDSAsyncOp addOrUpdateOp(FDSAsyncOp::kAddOrUpdateRecord); - addOrUpdateOp.FileId = GetFileId(key); - addOrUpdateOp.RecordKey = GetRecordKey(key); - addOrUpdateOp.RecordData = (const uint8_t *)&storedVal; + addOrUpdateOp.FileId = GetFileId(key); + addOrUpdateOp.RecordKey = GetRecordKey(key); + addOrUpdateOp.RecordData = (const uint8_t *) &storedVal; addOrUpdateOp.RecordDataLengthWords = 1; err = DoAsyncFDSOp(addOrUpdateOp); SuccessOrExit(err); - ChipLogProgress(DeviceLayer, "FDS set: %04" PRIX16 "/%04" PRIX16 " = %s", GetFileId(key), GetRecordKey(key), val ? "true" : "false"); + ChipLogProgress(DeviceLayer, "FDS set: %04" PRIX16 "/%04" PRIX16 " = %s", GetFileId(key), GetRecordKey(key), + val ? "true" : "false"); exit: return err; @@ -237,15 +238,16 @@ CHIP_ERROR NRF5Config::WriteConfigValue(Key key, uint32_t val) CHIP_ERROR err; FDSAsyncOp addOrUpdateOp(FDSAsyncOp::kAddOrUpdateRecord); - addOrUpdateOp.FileId = GetFileId(key); - addOrUpdateOp.RecordKey = GetRecordKey(key); - addOrUpdateOp.RecordData = (const uint8_t *)&val; + addOrUpdateOp.FileId = GetFileId(key); + addOrUpdateOp.RecordKey = GetRecordKey(key); + addOrUpdateOp.RecordData = (const uint8_t *) &val; addOrUpdateOp.RecordDataLengthWords = 1; err = DoAsyncFDSOp(addOrUpdateOp); SuccessOrExit(err); - ChipLogProgress(DeviceLayer, "FDS set: 0x%04" PRIX16 "/0x%04" PRIX16 " = %" PRIu32 " (0x%" PRIX32 ")", GetFileId(key), GetRecordKey(key), val, val); + ChipLogProgress(DeviceLayer, "FDS set: 0x%04" PRIX16 "/0x%04" PRIX16 " = %" PRIu32 " (0x%" PRIX32 ")", GetFileId(key), + GetRecordKey(key), val, val); exit: return err; @@ -256,15 +258,16 @@ CHIP_ERROR NRF5Config::WriteConfigValue(Key key, uint64_t val) CHIP_ERROR err; FDSAsyncOp addOrUpdateOp(FDSAsyncOp::kAddOrUpdateRecord); - addOrUpdateOp.FileId = GetFileId(key); - addOrUpdateOp.RecordKey = GetRecordKey(key); - addOrUpdateOp.RecordData = (const uint8_t *)&val; + addOrUpdateOp.FileId = GetFileId(key); + addOrUpdateOp.RecordKey = GetRecordKey(key); + addOrUpdateOp.RecordData = (const uint8_t *) &val; addOrUpdateOp.RecordDataLengthWords = 2; err = DoAsyncFDSOp(addOrUpdateOp); SuccessOrExit(err); - ChipLogProgress(DeviceLayer, "FDS set: 0x%04" PRIX16 "/0x%04" PRIX16 " = %" PRIu64 " (0x%" PRIX64 ")", GetFileId(key), GetRecordKey(key), val, val); + ChipLogProgress(DeviceLayer, "FDS set: 0x%04" PRIX16 "/0x%04" PRIX16 " = %" PRIu64 " (0x%" PRIX64 ")", GetFileId(key), + GetRecordKey(key), val, val); exit: return err; @@ -284,22 +287,23 @@ CHIP_ERROR NRF5Config::WriteConfigValueStr(Key key, const char * str, size_t str { uint32_t storedValWords = FDSWords(strLen + 1); - storedVal = (uint8_t *)nrf_malloc(storedValWords * kFDSWordSize); + storedVal = (uint8_t *) nrf_malloc(storedValWords * kFDSWordSize); VerifyOrExit(storedVal != NULL, err = CHIP_ERROR_NO_MEMORY); memcpy(storedVal, str, strLen); storedVal[strLen] = 0; FDSAsyncOp addOrUpdateOp(FDSAsyncOp::kAddOrUpdateRecord); - addOrUpdateOp.FileId = GetFileId(key); - addOrUpdateOp.RecordKey = GetRecordKey(key); - addOrUpdateOp.RecordData = storedVal; + addOrUpdateOp.FileId = GetFileId(key); + addOrUpdateOp.RecordKey = GetRecordKey(key); + addOrUpdateOp.RecordData = storedVal; addOrUpdateOp.RecordDataLengthWords = storedValWords; err = DoAsyncFDSOp(addOrUpdateOp); SuccessOrExit(err); - ChipLogProgress(DeviceLayer, "FDS set: 0x%04" PRIX16 "/0x%04" PRIX16 " = \"%s\"", GetFileId(key), GetRecordKey(key), (const char *)storedVal); + ChipLogProgress(DeviceLayer, "FDS set: 0x%04" PRIX16 "/0x%04" PRIX16 " = \"%s\"", GetFileId(key), GetRecordKey(key), + (const char *) storedVal); } else @@ -325,24 +329,25 @@ CHIP_ERROR NRF5Config::WriteConfigValueBin(Key key, const uint8_t * data, size_t { uint32_t storedValWords = FDSWords(dataLen + 2); - storedVal = (uint8_t *)nrf_malloc(storedValWords * kFDSWordSize); + storedVal = (uint8_t *) nrf_malloc(storedValWords * kFDSWordSize); VerifyOrExit(storedVal != NULL, err = CHIP_ERROR_NO_MEMORY); // First two bytes encode the length. - Encoding::LittleEndian::Put16(storedVal, (uint16_t)dataLen); + Encoding::LittleEndian::Put16(storedVal, (uint16_t) dataLen); memcpy(storedVal + 2, data, dataLen); FDSAsyncOp addOrUpdateOp(FDSAsyncOp::kAddOrUpdateRecord); - addOrUpdateOp.FileId = GetFileId(key); - addOrUpdateOp.RecordKey = GetRecordKey(key); - addOrUpdateOp.RecordData = storedVal; + addOrUpdateOp.FileId = GetFileId(key); + addOrUpdateOp.RecordKey = GetRecordKey(key); + addOrUpdateOp.RecordData = storedVal; addOrUpdateOp.RecordDataLengthWords = storedValWords; err = DoAsyncFDSOp(addOrUpdateOp); SuccessOrExit(err); - ChipLogProgress(DeviceLayer, "FDS set: 0x%04" PRIX16 "/0x%04" PRIX16 " = (blob length %" PRId32 ")", GetFileId(key), GetRecordKey(key), dataLen); + ChipLogProgress(DeviceLayer, "FDS set: 0x%04" PRIX16 "/0x%04" PRIX16 " = (blob length %" PRId32 ")", GetFileId(key), + GetRecordKey(key), dataLen); } else @@ -364,7 +369,7 @@ CHIP_ERROR NRF5Config::ClearConfigValue(Key key) CHIP_ERROR err; FDSAsyncOp delOp(FDSAsyncOp::kDeleteRecordByKey); - delOp.FileId = GetFileId(key); + delOp.FileId = GetFileId(key); delOp.RecordKey = GetRecordKey(key); err = DoAsyncFDSOp(delOp); @@ -398,7 +403,7 @@ CHIP_ERROR NRF5Config::FactoryResetConfig(void) { FDSAsyncOp delOp(FDSAsyncOp::kDeleteFile); delOp.FileId = kFileId_ChipConfig; - err = DoAsyncFDSOp(delOp); + err = DoAsyncFDSOp(delOp); SuccessOrExit(err); ChipLogProgress(DeviceLayer, "FDS delete file: 0x%04" PRIX16, kFileId_ChipConfig); } @@ -429,12 +434,12 @@ CHIP_ERROR NRF5Config::OpenRecord(NRF5Config::Key key, fds_record_desc_t & recDe // Search for the requested record. Return "CONFIG_NOT_FOUND" if it doesn't exist. memset(&findToken, 0, sizeof(findToken)); fdsRes = fds_record_find(NRF5Config::GetFileId(key), NRF5Config::GetRecordKey(key), &recDesc, &findToken); - err = (fdsRes == FDS_ERR_NOT_FOUND) ? CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND : MapFDSError(fdsRes); + err = (fdsRes == FDS_ERR_NOT_FOUND) ? CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND : MapFDSError(fdsRes); SuccessOrExit(err); // Open the record for reading. fdsRes = fds_record_open(&recDesc, &rec); - err = MapFDSError(fdsRes); + err = MapFDSError(fdsRes); SuccessOrExit(err); exit: @@ -443,7 +448,8 @@ CHIP_ERROR NRF5Config::OpenRecord(NRF5Config::Key key, fds_record_desc_t & recDe CHIP_ERROR NRF5Config::ForEachRecord(uint16_t fileId, uint16_t recordKey, ForEachRecordFunct funct) { - CHIP_ERROR err = CHIP_NO_ERROR;; + CHIP_ERROR err = CHIP_NO_ERROR; + ; ret_code_t fdsRes; fds_find_token_t findToken; fds_record_desc_t recDesc; @@ -465,7 +471,7 @@ CHIP_ERROR NRF5Config::ForEachRecord(uint16_t fileId, uint16_t recordKey, ForEac // Open the record for reading. fdsRes = fds_record_open(&recDesc, &rec); - err = MapFDSError(fdsRes); + err = MapFDSError(fdsRes); SuccessOrExit(err); needClose = true; @@ -477,18 +483,18 @@ CHIP_ERROR NRF5Config::ForEachRecord(uint16_t fileId, uint16_t recordKey, ForEac // Close the record. needClose = false; - fdsRes = fds_record_close(&recDesc); - err = MapFDSError(fdsRes); + fdsRes = fds_record_close(&recDesc); + err = MapFDSError(fdsRes); SuccessOrExit(err); // Delete the record if requested. if (deleteRec) { FDSAsyncOp delOp(FDSAsyncOp::kDeleteRecord); - delOp.FileId = fileId; - delOp.RecordKey = recordKey; + delOp.FileId = fileId; + delOp.RecordKey = recordKey; delOp.RecordDesc = recDesc; - err = DoAsyncFDSOp(delOp); + err = DoAsyncFDSOp(delOp); SuccessOrExit(err); } } @@ -526,14 +532,13 @@ CHIP_ERROR NRF5Config::DoAsyncFDSOp(FDSAsyncOp & asyncOp) } // If adding or updating a record, prepare the FDS record structure with the record data. - if (asyncOp.OpType == FDSAsyncOp::kAddRecord || - asyncOp.OpType == FDSAsyncOp::kUpdateRecord || + if (asyncOp.OpType == FDSAsyncOp::kAddRecord || asyncOp.OpType == FDSAsyncOp::kUpdateRecord || asyncOp.OpType == FDSAsyncOp::kAddOrUpdateRecord) { memset(&rec, 0, sizeof(rec)); - rec.file_id = asyncOp.FileId; - rec.key = asyncOp.RecordKey; - rec.data.p_data = asyncOp.RecordData; + rec.file_id = asyncOp.FileId; + rec.key = asyncOp.RecordKey; + rec.data.p_data = asyncOp.RecordData; rec.data.length_words = asyncOp.RecordDataLengthWords; } @@ -550,13 +555,13 @@ CHIP_ERROR NRF5Config::DoAsyncFDSOp(FDSAsyncOp & asyncOp) // Depending on whether an existing record was found, call fds_record_write or fds_record_update. if (!existingRecFound) { - case FDSAsyncOp::kAddRecord: + case FDSAsyncOp::kAddRecord: fdsRes = fds_record_write(NULL, &rec); break; } else { - case FDSAsyncOp::kUpdateRecord: + case FDSAsyncOp::kUpdateRecord: fdsRes = fds_record_update(&asyncOp.RecordDesc, &rec); break; } @@ -679,8 +684,7 @@ void NRF5Config::HandleFDSEvent(const fds_evt_t * fdsEvent) case FDSAsyncOp::kUpdateRecord: // Ignore the event if its not a WRITE or UPDATE, or if its for a different file/record. if ((fdsEvent->id != FDS_EVT_WRITE && fdsEvent->id != FDS_EVT_UPDATE) || - fdsEvent->write.file_id != sActiveAsyncOp->FileId || - fdsEvent->write.record_key != sActiveAsyncOp->RecordKey) + fdsEvent->write.file_id != sActiveAsyncOp->FileId || fdsEvent->write.record_key != sActiveAsyncOp->RecordKey) { return; } @@ -688,8 +692,7 @@ void NRF5Config::HandleFDSEvent(const fds_evt_t * fdsEvent) case FDSAsyncOp::kDeleteRecord: case FDSAsyncOp::kDeleteRecordByKey: // Ignore the event if its not a DEL_RECORD, or if its for a different file/record. - if (fdsEvent->id != FDS_EVT_DEL_RECORD || - fdsEvent->del.record_id != sActiveAsyncOp->RecordDesc.record_id) + if (fdsEvent->id != FDS_EVT_DEL_RECORD || fdsEvent->del.record_id != sActiveAsyncOp->RecordDesc.record_id) { return; } @@ -749,24 +752,20 @@ void NRF5Config::RunConfigUnitTest() // NRF Config Test 1 -- Force GC { - const static uint8_t kTestData[] = - { - 0xD5, 0x00, 0x00, 0x04, 0x00, 0x01, 0x00, 0x30, 0x01, 0x08, 0x79, 0x55, 0x9F, 0x15, 0x1F, 0x66, - 0x3D, 0x8F, 0x24, 0x02, 0x05, 0x37, 0x03, 0x27, 0x13, 0x02, 0x00, 0x00, 0xEE, 0xEE, 0x30, 0xB4, - 0x18, 0x18, 0x26, 0x04, 0x80, 0x41, 0x1B, 0x23, 0x26, 0x05, 0x7F, 0xFF, 0xFF, 0x52, 0x37, 0x06, - 0x27, 0x11, 0x01, 0x00, 0x00, 0x00, 0x00, 0x30, 0xB4, 0x18, 0x18, 0x24, 0x07, 0x02, 0x26, 0x08, - 0x25, 0x00, 0x5A, 0x23, 0x30, 0x0A, 0x39, 0x04, 0x9E, 0xC7, 0x77, 0xC5, 0xA4, 0x13, 0x31, 0xF7, - 0x72, 0x2E, 0x27, 0xC2, 0x86, 0x3D, 0xC5, 0x2E, 0xD5, 0xD2, 0x3C, 0xCF, 0x7E, 0x06, 0xE3, 0x48, - 0x53, 0x87, 0xE8, 0x4D, 0xB0, 0x27, 0x07, 0x58, 0x4A, 0x38, 0xB4, 0xF3, 0xB2, 0x47, 0x94, 0x45, - 0x58, 0x65, 0x80, 0x08, 0x17, 0x6B, 0x8E, 0x4F, 0x07, 0x41, 0xA3, 0x3D, 0x5D, 0xCE, 0x76, 0x86, - 0x35, 0x83, 0x29, 0x01, 0x18, 0x35, 0x82, 0x29, 0x01, 0x24, 0x02, 0x05, 0x18, 0x35, 0x84, 0x29, - 0x01, 0x36, 0x02, 0x04, 0x02, 0x04, 0x01, 0x18, 0x18, 0x35, 0x81, 0x30, 0x02, 0x08, 0x42, 0xBD, - 0x2C, 0x6B, 0x5B, 0x3A, 0x18, 0x16, 0x18, 0x35, 0x80, 0x30, 0x02, 0x08, 0x44, 0xE3, 0x40, 0x38, - 0xA9, 0xD4, 0xB5, 0xA7, 0x18, 0x35, 0x0C, 0x30, 0x01, 0x19, 0x00, 0xA6, 0x5D, 0x54, 0xF5, 0xAE, - 0x5D, 0x63, 0xEB, 0x69, 0xD8, 0xDB, 0xCB, 0xE2, 0x20, 0x0C, 0xD5, 0x6F, 0x43, 0x5E, 0x96, 0xA8, - 0x54, 0xB2, 0x74, 0x30, 0x02, 0x19, 0x00, 0xE0, 0x37, 0x02, 0x8B, 0xB3, 0x04, 0x06, 0xDD, 0xBD, - 0x28, 0xAA, 0xC4, 0xF1, 0xFF, 0xFB, 0xB1, 0xD4, 0x1C, 0x78, 0x40, 0xDA, 0x2C, 0xD8, 0x40, 0x18, - 0x18, + const static uint8_t kTestData[] = { + 0xD5, 0x00, 0x00, 0x04, 0x00, 0x01, 0x00, 0x30, 0x01, 0x08, 0x79, 0x55, 0x9F, 0x15, 0x1F, 0x66, 0x3D, 0x8F, 0x24, + 0x02, 0x05, 0x37, 0x03, 0x27, 0x13, 0x02, 0x00, 0x00, 0xEE, 0xEE, 0x30, 0xB4, 0x18, 0x18, 0x26, 0x04, 0x80, 0x41, + 0x1B, 0x23, 0x26, 0x05, 0x7F, 0xFF, 0xFF, 0x52, 0x37, 0x06, 0x27, 0x11, 0x01, 0x00, 0x00, 0x00, 0x00, 0x30, 0xB4, + 0x18, 0x18, 0x24, 0x07, 0x02, 0x26, 0x08, 0x25, 0x00, 0x5A, 0x23, 0x30, 0x0A, 0x39, 0x04, 0x9E, 0xC7, 0x77, 0xC5, + 0xA4, 0x13, 0x31, 0xF7, 0x72, 0x2E, 0x27, 0xC2, 0x86, 0x3D, 0xC5, 0x2E, 0xD5, 0xD2, 0x3C, 0xCF, 0x7E, 0x06, 0xE3, + 0x48, 0x53, 0x87, 0xE8, 0x4D, 0xB0, 0x27, 0x07, 0x58, 0x4A, 0x38, 0xB4, 0xF3, 0xB2, 0x47, 0x94, 0x45, 0x58, 0x65, + 0x80, 0x08, 0x17, 0x6B, 0x8E, 0x4F, 0x07, 0x41, 0xA3, 0x3D, 0x5D, 0xCE, 0x76, 0x86, 0x35, 0x83, 0x29, 0x01, 0x18, + 0x35, 0x82, 0x29, 0x01, 0x24, 0x02, 0x05, 0x18, 0x35, 0x84, 0x29, 0x01, 0x36, 0x02, 0x04, 0x02, 0x04, 0x01, 0x18, + 0x18, 0x35, 0x81, 0x30, 0x02, 0x08, 0x42, 0xBD, 0x2C, 0x6B, 0x5B, 0x3A, 0x18, 0x16, 0x18, 0x35, 0x80, 0x30, 0x02, + 0x08, 0x44, 0xE3, 0x40, 0x38, 0xA9, 0xD4, 0xB5, 0xA7, 0x18, 0x35, 0x0C, 0x30, 0x01, 0x19, 0x00, 0xA6, 0x5D, 0x54, + 0xF5, 0xAE, 0x5D, 0x63, 0xEB, 0x69, 0xD8, 0xDB, 0xCB, 0xE2, 0x20, 0x0C, 0xD5, 0x6F, 0x43, 0x5E, 0x96, 0xA8, 0x54, + 0xB2, 0x74, 0x30, 0x02, 0x19, 0x00, 0xE0, 0x37, 0x02, 0x8B, 0xB3, 0x04, 0x06, 0xDD, 0xBD, 0x28, 0xAA, 0xC4, 0xF1, + 0xFF, 0xFB, 0xB1, 0xD4, 0x1C, 0x78, 0x40, 0xDA, 0x2C, 0xD8, 0x40, 0x18, 0x18, }; uint8_t buf[512]; size_t dataLen; @@ -787,8 +786,6 @@ void NRF5Config::RunConfigUnitTest() } } - - } // namespace Internal } // namespace DeviceLayer } // namespace chip diff --git a/src/platform/nRF5/nRF5Utils.cpp b/src/platform/nRF5/nRF5Utils.cpp index 2b5b148ad886fa..19f661c90cf300 100644 --- a/src/platform/nRF5/nRF5Utils.cpp +++ b/src/platform/nRF5/nRF5Utils.cpp @@ -38,11 +38,7 @@ namespace Internal { */ void RegisterNRFErrorFormatter(void) { - static ErrorFormatter sNRFErrorFormatter = - { - FormatNRFError, - NULL - }; + static ErrorFormatter sNRFErrorFormatter = { FormatNRFError, NULL }; RegisterErrorFormatter(&sNRFErrorFormatter); } @@ -83,8 +79,6 @@ bool FormatNRFError(char * buf, uint16_t bufSize, int32_t err) return true; } - } // namespace Internal } // namespace DeviceLayer } // namespace chip - diff --git a/src/system/SystemLayerPrivate.h b/src/system/SystemLayerPrivate.h index 9aeb22d42769a9..05bb59f2e088a9 100644 --- a/src/system/SystemLayerPrivate.h +++ b/src/system/SystemLayerPrivate.h @@ -39,7 +39,7 @@ // Compatibility adaptations for statistical data in LwIP 1.x #ifndef MEMP_STATS_GET -#define MEMP_STATS_GET(FIELD, INDEX) (lwip_stats.memp[INDEX].FIELD) +#define MEMP_STATS_GET(FIELD, INDEX) (lwip_stats.memp[INDEX].FIELD) #endif // !defined(MEMP_STATS_GET) #endif // LWIP_VERSION_MAJOR