├── .dockerignore ├── .gitattributes ├── .github ├── CODEOWNERS ├── PULL_REQUEST_TEMPLATE.md ├── actions │ └── build-mbed-edge │ │ └── action.yaml └── workflows │ ├── devmode-test-build.yml │ ├── misspell.yml │ └── pr-check-tests.yml ├── .gitignore ├── .gitmodules ├── CHANGELOG.md ├── CMakeLists.txt ├── CONTRIBUTING.md ├── Dockerfile ├── Dockerfile.debian.byoc ├── Dockerfile.debian.dev ├── Dockerfile.debian.prod ├── Dockerfile.edge-core-builder ├── Dockerfile.test ├── Doxyfile.in ├── Jenkinsfile ├── LICENSE ├── Makefile ├── Makefile.test ├── README.md ├── cli_template.tmpl ├── cmake ├── common.cmake ├── edge_configure.cmake ├── edge_include_directories.cmake ├── pal-platform-cmake │ ├── curl.cmake │ ├── mbedtls.cmake │ ├── parsec_se_driver.cmake │ └── trusted_storage.cmake ├── targets │ └── default.cmake └── toolchains │ └── mcc-linux-x86.cmake ├── common ├── CMakeLists.txt ├── apr_base64.c ├── common │ ├── msg_api.h │ ├── msg_api_internal.h │ ├── pt_api_error_parser.h │ ├── read_file.h │ ├── test_support.h │ └── websocket_comm.h ├── default_message_id_generator.c ├── edge-io-lib │ └── edge_io_lib.c ├── edge-mutex │ └── edge_mutex.c ├── edge_time.c ├── edge_trace.c ├── integer_length.c ├── msg_api.c ├── pt_api_error_codes.c ├── pt_api_error_parser.c ├── read_file.c └── websocket_comm.c ├── config ├── .gitignore ├── edge_component_update_config.h ├── header_template.txt ├── mbed_cloud_client_user_config.h ├── psa_storage_user_config.h └── sotp_fs_linux.h ├── docs ├── create_manifest_v3.md └── prepare_fota_component_update.md ├── doxygen_frontpage.md ├── edge-client ├── CMakeLists.txt ├── async_cb_params.cpp ├── edge-client │ ├── async_cb_params.h │ ├── async_cb_params_base.h │ ├── edge_client.h │ ├── edge_client_byoc.h │ ├── edge_client_cpp.h │ ├── edge_client_format_values.h │ ├── edge_client_impl.h │ ├── edge_client_internal.h │ ├── edge_client_mgmt.h │ ├── edge_core_cb.h │ ├── edge_core_cb_result.h │ ├── edge_manifest_object.h │ ├── eventloop_tracing.h │ ├── gateway_resource.h │ ├── request_context.h │ ├── reset_factory_settings.h │ ├── reset_factory_settings_internal.h │ └── subdevice_fota.h ├── edge_client.cpp ├── edge_client_byoc.c ├── edge_client_format_values.c ├── edge_core_cb.cpp ├── eventloop_tracing.c ├── gateway_resource.cpp ├── request_context.cpp ├── reset_factory_settings.c ├── subdevice_client.cpp └── subdevice_fota.cpp ├── edge-core ├── CMakeLists.txt ├── client_type.c ├── edge-core │ ├── client_type.h │ ├── edge_device_object.h │ ├── edge_server.h │ ├── grm_api_internal.h │ ├── http_server.h │ ├── mgmt_api_internal.h │ ├── protocol_api_internal.h │ ├── protocol_crypto_api.h │ ├── protocol_crypto_api_internal.h │ ├── server.h │ ├── srv_comm.h │ └── websocket_serv.h ├── edge_core.docopt ├── edge_core_clip.h ├── edge_server.c ├── edge_server_customer_code.c ├── gen_docopt.sh ├── grm_api.c ├── http_server.c ├── mgmt_api_internal.c ├── protocol_api.c ├── protocol_crypto_api.c ├── server.c ├── srv_comm.c └── websocket_serv.c ├── edge-rpc ├── CMakeLists.txt ├── edge-rpc │ ├── rpc.h │ └── rpc_timeout_api.h ├── rpc.c └── rpc_timeout_api.c ├── edge-tool ├── LICENSE ├── MANIFEST.in ├── README.md ├── __init__.py ├── cbor_converter.py ├── edge_tool.py ├── requirements.txt ├── setup.py ├── test_data │ ├── device.cbor │ ├── device.cbor.txt │ ├── mbed_cloud_dev_credentials.c │ └── update_default_resources.c └── tests │ ├── test_cbor.py │ └── test_cli.py ├── fota ├── COMP_1 │ ├── fota_update_activate.sh │ └── fota_update_verify.sh ├── MAIN │ └── fota_update_activate.sh └── fota_app_callbacks.c ├── git_details.cmake ├── include ├── common │ ├── apr_base64.h │ ├── constants.h │ ├── default_message_id_generator.h │ ├── edge_io_lib.h │ ├── edge_mutex.h │ ├── edge_time.h │ ├── edge_trace.h │ ├── integer_length.h │ └── pt_api_error_codes.h ├── edge-core │ ├── edge_server_customer_code.h │ └── protocol_api.h ├── pt-client-2 │ ├── pt_api.h │ ├── pt_certificate_api.h │ ├── pt_client_api.h │ ├── pt_common_api.h │ ├── pt_crypto_api.h │ ├── pt_device_object.h │ ├── pt_devices_api.h │ └── pt_userdata_api.h └── pt-client │ ├── client.h │ ├── pt_api.h │ └── pt_device_object.h ├── lib ├── CMakeLists.txt ├── jansson │ └── CMakeLists.txt ├── jsonrpc │ ├── LICENSE.md │ ├── jsonrpc.c │ └── jsonrpc │ │ └── jsonrpc.h ├── libevent │ └── CMakeLists.txt ├── libwebsockets │ └── CMakeLists.txt ├── pal-platform │ ├── Middleware │ │ ├── curl │ │ │ ├── .gitignore │ │ │ └── curl.cmake │ │ ├── parsec_se_driver │ │ │ ├── .gitignore │ │ │ ├── CMakeLists.txt │ │ │ └── parsec_se_driver.cmake │ │ └── trusted_storage │ │ │ ├── .gitignore │ │ │ ├── CMakeLists.txt │ │ │ └── trusted_storage.cmake │ ├── OS │ │ ├── Linux_Native │ │ │ └── Linux_Native.cmake │ │ ├── Linux_OpenWRT │ │ │ └── Linux_OpenWRT.cmake │ │ ├── Linux_Raspbian │ │ │ └── Linux_Raspbian.cmake │ │ ├── Linux_Yocto_v2.2 │ │ │ └── Linux_Yocto_v2.2.cmake │ │ └── NXP │ │ │ └── NXP.cmake │ ├── Toolchain │ │ ├── ARMCC │ │ │ ├── ARMCC-ASM.cmake │ │ │ ├── ARMCC-C.cmake │ │ │ ├── ARMCC-CXX.cmake │ │ │ ├── ARMCC-flags.cmake │ │ │ └── ARMCC.cmake │ │ ├── ARMGCC │ │ │ ├── ARMGCC-flags.cmake │ │ │ ├── ARMGCC.cmake │ │ │ └── armgcc_force_cpp.cmake │ │ ├── GCC-OPENWRT │ │ │ ├── GCC-OPENWRT-flags.cmake │ │ │ └── GCC-OPENWRT.cmake │ │ ├── GCC-RASPBERRYPI │ │ │ ├── GCC-RASPBERRYPI-flags.cmake │ │ │ └── GCC-RASPBERRYPI.cmake │ │ ├── GCC │ │ │ ├── GCC-flags.cmake │ │ │ └── GCC.cmake │ │ └── POKY-GLIBC │ │ │ ├── POKY-GLIBC-flags.cmake │ │ │ └── POKY-GLIBC.cmake │ ├── pal-platform.json │ ├── pal-platform.py │ └── requirements.txt ├── platform.cmake └── platform │ └── secure_element │ ├── mcc_se_init.c │ └── se_configs │ ├── se_data_user_config.h │ └── se_driver_config.h ├── mbed-trace-edge └── CMakeLists.txt ├── nano-stack └── CMakeLists.txt ├── pt-client-2 ├── CMakeLists.txt ├── client.c ├── pt-client-2 │ ├── pt_api_internal.h │ ├── pt_certificate_api_internal.h │ ├── pt_certificate_parser.h │ ├── pt_common_api_internal.h │ ├── pt_crypto_api_internal.h │ ├── pt_device_api_internal.h │ ├── pt_devices_api_internal.h │ ├── pt_firmware_download_api_internal.h │ ├── pt_object_api_internal.h │ ├── pt_object_instance_api_internal.h │ ├── pt_resource_api_internal.h │ └── pt_subdev_config.h ├── pt_api.c ├── pt_certificate_api.c ├── pt_certificate_parser.c ├── pt_crypto_api.c ├── pt_device_object.c ├── pt_firmware_download_api_internal.c └── pt_service_api.c ├── pt-client ├── CMakeLists.txt ├── client.c ├── pt-client │ └── pt_api_internal.h ├── pt_api.c ├── pt_device_object.c └── pt_service_api.c ├── start.sh └── test ├── CMakeLists.txt ├── cpputest-custom-types └── cpputest-custom-types │ ├── my_json_frame.h │ └── value_pointer.h ├── edge-client-mock ├── CMakeLists.txt ├── mock_edge_client.cpp └── mock_edge_client_byoc.cpp ├── edge-client ├── CMakeLists.txt ├── test_edge_client.cpp ├── test_edgeclient_format_values.cpp ├── test_edgeclient_format_values_by_type.cpp ├── test_edgeclient_mgmt.cpp ├── test_edgeclient_request_context.cpp ├── test_edgeclient_scan_values.cpp ├── test_main.cpp ├── test_rfs.cpp └── test_subdevice_fota.cpp ├── edge-core ├── CMakeLists.txt ├── data │ ├── complex_resource_hierarchy.json │ ├── device2_register_test.json │ ├── device2_unregister_test.json │ ├── device_register_test.json │ ├── device_register_test_instance_missing.json │ ├── device_register_test_invalid_resource_value.json │ ├── device_register_test_object_missing.json │ ├── device_register_test_resource_missing.json │ ├── device_unregister_test.json │ ├── device_write_non_string_value.json │ └── device_write_value_failure.json ├── server_test.cpp ├── test_default_message_id_generator.cpp ├── test_edge_core_mgmt_api.cpp ├── test_edge_server.cpp ├── test_http_server.cpp ├── test_integer_length.cpp ├── test_main.cpp ├── test_protocol_api.cpp ├── test_server.cpp ├── test_websocket_comm.cpp └── test_websocket_serv.cpp ├── edge-io-lib ├── CMakeLists.txt ├── system_if.cpp ├── test_edge_io_lib.cpp └── test_main.cpp ├── edge-rpc ├── CMakeLists.txt ├── test_main.cpp └── test_rpc.cpp ├── edge-server-mock ├── CMakeLists.txt ├── edge_server_mock.cpp └── test_fota_config.h ├── event-os-mock ├── CMakeLists.txt ├── event-os-mock │ └── eventOS_event_mock.h └── event_os_mock.cpp ├── generate_coverage.sh ├── kcm-mock ├── CMakeLists.txt └── kcm_mock.cpp ├── libevent-mock ├── CMakeLists.txt ├── evhttp_mock.cpp └── mock_event.cpp ├── libwebsocket-mock ├── CMakeLists.txt ├── libwebsocket-mock │ └── lws_mock.h ├── mock_lws.cpp └── mock_lws_minimal.cpp ├── mbed-cloud-client-mock ├── CMakeLists.txt ├── MbedCloudClient_mock.cpp ├── arm_uc_mmDerManifestAccessors_mock.cpp ├── m2mbase_mock.cpp ├── m2mendpoint_mock.cpp ├── m2minterfacefactory_mock.cpp ├── m2mobject_mock.cpp ├── m2mobjectinstance_mock.cpp ├── m2mresource_mock.cpp ├── m2mresourcebase_mock.cpp ├── ns_event_loop.cpp └── testfactory.cpp ├── pal-mock ├── CMakeLists.txt └── pal_mock.cpp ├── pt-client-2 ├── CMakeLists.txt ├── client_send_receive_helper.cpp ├── data │ └── write_from_edge_core_test.json ├── pt-client-2 │ ├── client_send_receive_helper.h │ ├── ipso_enums.h │ └── pt_client_helper.h ├── pt_client_helper.cpp ├── test_main.cpp ├── test_pt_certificate_api.cpp ├── test_pt_client.cpp ├── test_pt_client_ws_callback.cpp ├── test_pt_crypto_api.cpp ├── test_pt_device_api.cpp ├── test_pt_device_object.cpp └── test_pt_service.cpp ├── pt-client ├── CMakeLists.txt ├── data │ └── write_from_edge_core_test.json ├── test_main.cpp ├── test_pt_api.cpp ├── test_pt_client.cpp └── test_pt_service.cpp └── test-lib ├── CMakeLists.txt ├── edge_mutex_helper.cpp ├── json_helper.cpp ├── m2mcallbackstorage.cpp ├── mock_bufferevent.cpp ├── mock_edge_io_lib.cpp ├── mock_edge_msg_api.cpp ├── mock_edge_mutex.cpp ├── mock_edge_read.cpp ├── mock_edge_websocket_comm.cpp ├── mock_evconnlistener.cpp ├── mock_fcc_kcm.cpp ├── mock_m2mstring.cpp ├── mock_m2mtimer.cpp ├── mock_m2mtimer.h ├── mock_mbed_cloud_client.cpp ├── mock_rpc.cpp ├── msg_api_test_helper.cpp ├── test-lib ├── MyEvBuffer.h ├── edgeclient_request_context.h ├── evbase_mock.h ├── evbuf_mock.h ├── evhttp_mock.h ├── json_helper.h ├── json_message_t_pointer.h ├── json_pointer.h ├── msg_api_mocks.h ├── msg_api_test_helper.h ├── mutex_helper.h ├── rpc_mocks.h ├── server_test.h ├── test_edge_server.h └── test_http_server.h └── testfactory.h /.dockerignore: -------------------------------------------------------------------------------- 1 | .git 2 | build/ 3 | *.o 4 | *.log 5 | edge-tool-c -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto-detect 2 | * text=auto 3 | 4 | # If line feed normalization auto-detection fails 5 | # add known files here. Few examples below. 6 | # C sources 7 | # *.c text 8 | # *.h text 9 | # Compiled object files 10 | # *.o binary 11 | # *.so binary -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @PelionIoT/team-edge_vector 2 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | # Mbed Edge pull request 2 | 3 | ` 4 | Please fill this pull request template to describe your pull request. 5 | If it introduces API breaks please describe it in detail. 6 | ` 7 | 8 | ## Description 9 | 10 | `submitter: Please add a description of your PR here.` 11 | 12 | ## Test instructions 13 | 14 | `Submitter: Please add instructions to test your PR here.` 15 | 16 | `If your pull request is a fix for a defect please write instructions 17 | to reproduce the defect.` 18 | 19 | ## Check list 20 | 21 | ### API change(s) 22 | 23 | - [ ] Not applicable. 24 | - [ ] API is backwards compatible. 25 | - [ ] API documentation is updated. 26 | 27 | ### Example applications updated 28 | 29 | - [ ] Not applicable. 30 | 31 | ### Changelog 32 | 33 | - [ ] `CHANGELOG.md` updated. 34 | 35 | -------------------------------------------------------------------------------- /.github/actions/build-mbed-edge/action.yaml: -------------------------------------------------------------------------------- 1 | name: Build mbed-edge-devmode-test 2 | description: Build mbed-edge in developer mode 3 | 4 | inputs: 5 | dockerfile: 6 | description: Usually "./Dockerfile" 7 | required: false 8 | default: "./Dockerfile" 9 | context: 10 | description: Usually dot '.' 11 | required: false 12 | default: "." 13 | configfiles: 14 | description: The folder that contains the credential files 15 | required: true 16 | options: 17 | description: Additional options to pass to docker run 18 | required: false 19 | default: '' 20 | 21 | outputs: 22 | cid: 23 | description: Container ID 24 | value: ${{ steps.info.outputs.cid }} 25 | 26 | runs: 27 | using: composite 28 | steps: 29 | - name: Setup-Build-Files 30 | shell: bash 31 | run: | 32 | cd ${{ inputs.context }} 33 | cp -a ${{ inputs.configfiles }}/* config 34 | - name: Run 35 | shell: bash 36 | run: | 37 | cd ${{ inputs.context }} 38 | docker build ${{ inputs.options }} -f ${{ inputs.dockerfile }} . -------------------------------------------------------------------------------- /.github/workflows/devmode-test-build.yml: -------------------------------------------------------------------------------- 1 | name: production build 2 | 3 | on: 4 | push: 5 | paths-ignore: 6 | - '**/*.md' 7 | pull_request: 8 | branches: [ "master" ] 9 | workflow_dispatch: 10 | schedule: 11 | # Once week 03:26 on Saturday 12 | - cron: '26 3 * * Sat' 13 | 14 | # This allows a subsequently queued workflow run to interrupt previous runs 15 | concurrency: 16 | group: mbed-edge-test-build-${{ github.event.pull_request.head.label || github.head_ref || github.ref }} 17 | cancel-in-progress: true 18 | 19 | jobs: 20 | build: 21 | runs-on: [ "self-hosted", "client" ] 22 | env: 23 | SCRIPTS_INTERNAL_DIR: scripts-internal 24 | EDGE_CONFIGS_DIR: scripts-internal/edge/edge-config/build-mbed-edge-devmode-test 25 | SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} 26 | steps: 27 | - uses: actions/checkout@v4 28 | name: checkout repo 29 | with: 30 | submodules: recursive 31 | - name: Check out scripts-internal repository code 32 | uses: actions/checkout@v4 33 | with: 34 | repository: PelionIoT/scripts-internal 35 | token: ${{ secrets.ACCESS_TOKEN }} 36 | path: ${{ env.SCRIPTS_INTERNAL_DIR }} 37 | - name: Build devmode-test 38 | uses: ./.github/actions/build-mbed-edge 39 | with: 40 | configfiles: ${{ env.EDGE_CONFIGS_DIR }} 41 | - name: Post status to Slack testing_builds 42 | if: always() 43 | uses: act10ns/slack@v2 44 | with: 45 | status: ${{ job.status }} 46 | channel: '#testing_builds' 47 | -------------------------------------------------------------------------------- /.github/workflows/misspell.yml: -------------------------------------------------------------------------------- 1 | name: misspell 2 | on: 3 | push: 4 | workflow_dispatch: 5 | 6 | # This allows a subsequently queued workflow run to interrupt previous runs 7 | concurrency: 8 | group: mbed-edge-misspell-'${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}' 9 | cancel-in-progress: true 10 | 11 | jobs: 12 | static-checks: 13 | runs-on: [ "self-hosted", "client" ] 14 | steps: 15 | - name: Check out code 16 | uses: actions/checkout@v4 17 | - name: Misspell 18 | uses: PelionIoT/actions/.github/actions/misspell@main 19 | with: 20 | exceptions: "mosquitto" 21 | -------------------------------------------------------------------------------- /.github/workflows/pr-check-tests.yml: -------------------------------------------------------------------------------- 1 | name: PR-check unit tests 2 | 3 | on: 4 | push: 5 | branches: [ "master" ] 6 | pull_request: 7 | branches: [ "master" ] 8 | 9 | # This allows a subsequently queued workflow run to interrupt previous runs 10 | concurrency: 11 | group: mbed-edge-test-valgrind-${{ github.event.pull_request.head.label || github.head_ref || github.ref }} 12 | cancel-in-progress: true 13 | 14 | jobs: 15 | 16 | make-test-valgrind: 17 | 18 | runs-on: [ "self-hosted", "client" ] 19 | env: 20 | SCRIPTS_INTERNAL_DIR: scripts-internal 21 | EDGE_CONFIGS_DIR: scripts-internal/edge/edge-config/build-mbed-edge-devmode-test 22 | 23 | steps: 24 | - uses: actions/checkout@v3 25 | name: Checkout repo 26 | with: 27 | submodules: recursive 28 | - name: Check out scripts-internal repository code 29 | uses: actions/checkout@v4 30 | with: 31 | repository: PelionIoT/scripts-internal 32 | token: ${{ secrets.ACCESS_TOKEN }} 33 | path: ${{ env.SCRIPTS_INTERNAL_DIR }} 34 | - name: Run make -f Makefile.test 35 | uses: ./.github/actions/build-mbed-edge 36 | with: 37 | dockerfile: ./Dockerfile.test 38 | configfiles: ${{ env.EDGE_CONFIGS_DIR }} 39 | 40 | test-edge-tool: 41 | 42 | runs-on: [ "self-hosted", "client" ] 43 | env: 44 | SCRIPTS_INTERNAL_DIR: scripts-internal 45 | EDGE_CONFIGS_DIR: scripts-internal/edge/edge-config/build-mbed-edge-devmode-test 46 | 47 | steps: 48 | - uses: actions/checkout@v4 49 | name: Checkout repo 50 | with: 51 | submodules: recursive 52 | - name: Check out scripts-internal repository code 53 | uses: actions/checkout@v4 54 | with: 55 | repository: PelionIoT/scripts-internal 56 | token: ${{ secrets.ACCESS_TOKEN }} 57 | path: ${{ env.SCRIPTS_INTERNAL_DIR }} 58 | - uses: actions/setup-python@v4 59 | with: 60 | python-version: '3.10' 61 | - name: pytest 62 | run: | 63 | cd edge-tool 64 | python setup.py install 65 | pytest 66 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "lib/jansson/jansson"] 2 | path = lib/jansson/jansson 3 | url = https://github.com/akheron/jansson 4 | [submodule "lib/libevent/libevent"] 5 | path = lib/libevent/libevent 6 | url = https://github.com/libevent/libevent 7 | [submodule "lib/libwebsockets/libwebsockets"] 8 | path = lib/libwebsockets/libwebsockets 9 | url = https://github.com/ARMmbed/libwebsockets.git 10 | [submodule "lib/mbedtls"] 11 | path = lib/mbedtls 12 | url = https://github.com/ARMmbed/mbedtls 13 | [submodule "lib/mbed-cloud-client"] 14 | path = lib/mbed-cloud-client 15 | url = https://github.com/PelionIoT/mbed-cloud-client 16 | [submodule "lib/cpputest"] 17 | path = lib/cpputest 18 | url = https://github.com/cpputest/cpputest.git 19 | [submodule "lib/docopt.c"] 20 | path = lib/docopt.c 21 | url = https://github.com/docopt/docopt.c.git 22 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributions and pull requests 2 | 3 | Contributions to this project are accepted under the same license as this 4 | software. 5 | 6 | Submit only contributions where you have authored all the code. 7 | 8 | When working with a contribution, feel free to raise an issue in Github. 9 | This enables everyone to see if you are working with similar matter. It also 10 | encourages people to discuss on the issues. 11 | 12 | ## Working with an enhancement 13 | 14 | The preferred way to submit contributions is through a fork and pull requests. 15 | 16 | * Fork the Edge repository. 17 | * Clone it to your local development environment. 18 | * Create a branch for the work. 19 | * Create logical units of commits. Squash the commits to logical pieces if 20 | needed. 21 | * Implement only one task per branch. If you need to work on some other 22 | enhancement, do it on another branch to keep concerns separate. 23 | * Document the changes. 24 | * Test your changes. Include tests if possible. 25 | * Rebase your branch to the Edge repository head. Avoid merge commits. 26 | 27 | ## Submitting the enhancement 28 | 29 | When you have completed your work and the branch in the forked repository is 30 | ready to be submitted, verify the following requirements for your pull request: 31 | 32 | * Make sure that all of the commits contain a `Signed-off-by` line. Use your 33 | real name and email address. The `Author` and `Signed-off-by` lines must 34 | match. If any other person contributes to the commit, they must also add 35 | their own `Signed-off-by` line. 36 | * Submit your pull request to the Edge repository. The changes are reviewed and 37 | any comments may cause rework to the pull request. 38 | * When the changes are approved, they will be integrated to the Edge repository. 39 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:22.04 2 | 3 | ARG developer_certificate=./config/mbed_cloud_dev_credentials.c 4 | ARG update_certificate=./config/update_default_resources.c 5 | 6 | WORKDIR /usr/src/app/mbed-edge 7 | 8 | RUN apt-get update && \ 9 | DEBIAN_FRONTEND="noninteractive" apt-get -y install tzdata && \ 10 | apt-get install -y build-essential libc6-dev cmake python3.6 python3-pip python3-setuptools && \ 11 | apt-get install -y vim python3-venv 12 | 13 | COPY . . 14 | 15 | RUN pip3 install --upgrade pip 16 | RUN pip3 install manifest-tool 17 | 18 | RUN mkdir -p build && \ 19 | cd build && \ 20 | cmake -DDEVELOPER_MODE=ON -DFIRMWARE_UPDATE=ON .. && \ 21 | make 22 | 23 | CMD [ "./build/bin/edge-core", "--http-port", "8080", "--edge-pt-domain-socket", "/tmp/edge.sock" ] 24 | 25 | EXPOSE 8080 -------------------------------------------------------------------------------- /Dockerfile.debian.prod: -------------------------------------------------------------------------------- 1 | # Stage 1: Build the application 2 | FROM debian:bookworm-slim AS builder 3 | 4 | ARG fota_linux_storage_dir=/opt/izuma 5 | 6 | # Set the working directory 7 | WORKDIR /usr/src/app/mbed-edge 8 | 9 | # Install dependencies in a single step to reduce layers 10 | RUN apt-get update && \ 11 | DEBIAN_FRONTEND="noninteractive" apt-get install -y --no-install-recommends \ 12 | tzdata build-essential libc6-dev cmake libcurl4-openssl-dev libssl-dev \ 13 | python3 python3-pip pkg-config git && \ 14 | rm -rf /var/lib/apt/lists/* 15 | 16 | # Copy source files after dependencies are installed 17 | COPY . . 18 | 19 | # Return to main project and ensure it links with libbsd 20 | WORKDIR /usr/src/app/mbed-edge 21 | RUN mkdir -p build && cd build && \ 22 | cmake -DFACTORY_MODE=ON \ 23 | -DDEVELOPER_MODE=OFF \ 24 | -DFIRMWARE_UPDATE=ON \ 25 | -DTRACE_LEVEL=DEBUG \ 26 | -DFOTA_ENABLE=ON \ 27 | -DFOTA_COMBINED_IMAGE_SUPPORT=ON \ 28 | -DPLATFORM_TARGET=x86_x64_NativeLinux_mbedtls \ 29 | -DFOTA_LINUX_STORAGE_DIR=${fota_linux_storage_dir} \ 30 | .. && \ 31 | make -j$(nproc) 32 | 33 | # Stage 2: Create a minimal runtime image 34 | FROM debian:bookworm-slim 35 | 36 | ARG fota_linux_storage_dir=/opt/izuma 37 | ENV FOTA_LINUX_STORAGE_DIR=${fota_linux_storage_dir} 38 | 39 | # Set working directory 40 | WORKDIR /usr/src/app/mbed-edge 41 | 42 | # Install only the required runtime dependencies 43 | RUN apt-get update && \ 44 | DEBIAN_FRONTEND="noninteractive" apt-get install -y --no-install-recommends \ 45 | tzdata libc6 && \ 46 | rm -rf /var/lib/apt/lists/* 47 | 48 | RUN mkdir -p /opt/izuma 49 | 50 | # Copy only the built binary from the builder stage 51 | COPY --from=builder /usr/src/app/mbed-edge/build/ /usr/src/app/mbed-edge/build/ 52 | COPY --from=builder /usr/src/app/mbed-edge/fota/MAIN "${FOTA_LINUX_STORAGE_DIR}/MAIN" 53 | COPY --from=builder /usr/src/app/mbed-edge/fota/COMP_1 "${FOTA_LINUX_STORAGE_DIR}/COMP_1" 54 | 55 | CMD [ "./build/bin/edge-core", "--http-port", "8080", "--edge-pt-domain-socket", "/tmp/edge.sock" ] -------------------------------------------------------------------------------- /Dockerfile.edge-core-builder: -------------------------------------------------------------------------------- 1 | FROM ubuntu:22.04 2 | 3 | # Set environment variables 4 | ENV DEBIAN_FRONTEND=noninteractive \ 5 | TZ=Etc/UTC 6 | 7 | # Install required tools and dependencies 8 | RUN apt-get update && apt-get install -y \ 9 | build-essential \ 10 | cmake \ 11 | python3 \ 12 | python3-pip \ 13 | git \ 14 | curl \ 15 | wget \ 16 | unzip \ 17 | ninja-build \ 18 | pkg-config \ 19 | libssl-dev \ 20 | python3-pycryptodome \ 21 | python3-venv \ 22 | ca-certificates \ 23 | libcurl4-openssl-dev \ 24 | libglib2.0-dev \ 25 | libjson-c-dev \ 26 | libc6-dev \ 27 | && apt-get clean && rm -rf /var/lib/apt/lists/* 28 | 29 | # Create a working directory 30 | WORKDIR /workspace 31 | 32 | # Default command: open bash 33 | CMD ["/bin/bash"] 34 | -------------------------------------------------------------------------------- /Dockerfile.test: -------------------------------------------------------------------------------- 1 | FROM ubuntu:22.04 2 | 3 | WORKDIR /usr/src/app/mbed-edge 4 | 5 | ARG developer_certificate=./config/mbed_cloud_dev_credentials.c 6 | ARG update_certificate=./config/update_default_resources.c 7 | 8 | RUN apt-get update && \ 9 | DEBIAN_FRONTEND="noninteractive" apt-get -y install tzdata && \ 10 | apt-get install -y build-essential libc6-dev cmake python3.10 python3-pip python3-setuptools && \ 11 | apt-get install -y vim python3-venv valgrind 12 | 13 | COPY . . 14 | 15 | RUN pip3 install --upgrade pip 16 | RUN pip3 install manifest-tool 17 | 18 | CMD [ "make -f Makefile.test run-tests-with-valgrind" ] 19 | -------------------------------------------------------------------------------- /Jenkinsfile: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env groovy 2 | @Library('edge-ci') _ 3 | 4 | // Function is implemented in private repository https://github.com/PelionIoT/edge-ci/blob/master/vars/repoMbedEdge.groovy 5 | repoMbedEdge() 6 | -------------------------------------------------------------------------------- /Makefile.test: -------------------------------------------------------------------------------- 1 | JOBS:=$(shell nproc) 2 | 3 | .PHONY: clean build-test build-test-byoc build-test-devmode \ 4 | run-tests run-coverage run-tests-with-valgrind \ 5 | generate-cli-parsers 6 | 7 | clean: 8 | rm -rf build-test config/edge_version_info.h 9 | 10 | build: 11 | mkdir -p build-test 12 | 13 | generate-cli-parsers: 14 | cd edge-core && ./gen_docopt.sh 15 | 16 | lib/mbed-cloud-client/source/update_default_resources.c: lib/mbed-cloud-client 17 | manifest-dev-tool init 18 | 19 | build-test-byoc: lib/mbed-cloud-client/source/update_default_resources.c generate-cli-parsers build 20 | mkdir -p build-test 21 | cd build-test && cmake -DBUILD_TARGET=test -DBYOC_MODE=ON -DFOTA_ENABLE=OFF -DFIRMWARE_UPDATE=ON -DTRACE_LEVEL=DEBUG -DCMAKE_BUILD_TYPE=Debug .. && make -j ${JOBS} && cd .. 22 | 23 | build-test-fota-byoc: lib/mbed-cloud-client/source/update_default_resources.c generate-cli-parsers build 24 | mkdir -p build-test 25 | cd build-test && cmake -DBUILD_TARGET=test -DBYOC_MODE=ON -DFOTA_ENABLE=ON -DFIRMWARE_UPDATE=ON -DTRACE_LEVEL=DEBUG -DCMAKE_BUILD_TYPE=Debug .. && make -j ${JOBS} && cd .. 26 | 27 | build-test-devmode: lib/mbed-cloud-client/source/update_default_resources.c generate-cli-parsers build 28 | mkdir -p build-test-devmode 29 | cd build-test-devmode && cmake -DBUILD_TARGET=test -DDEVELOPER_MODE=ON -DTRACE_LEVEL=DEBUG -DCMAKE_BUILD_TYPE=Debug .. && make -j ${JOBS} && cd .. 30 | 31 | run-tests: build-test-byoc 32 | find ./build-test/bin -name "*-test" | xargs -n1 -I{} sh -c '{} || exit 255' 33 | 34 | run-tests-fota: build-test-fota-byoc 35 | find ./build-test/bin -name "*-test" | xargs -n1 -I{} sh -c '{} || exit 255' 36 | 37 | run-tests-with-valgrind: build-test-byoc 38 | find ./build-test/bin -name "*-test" | xargs -n1 -I{} sh -c 'valgrind --track-origins=yes --num-callers=100 --leak-check=full {}' 39 | 40 | run-coverage: run-tests 41 | cd ./build-test && ../test/generate_coverage.sh .. && cd .. 42 | echo "\033[0;33mCoverage report is at ./build-test/coverage.html/index.html\033[0m" 43 | 44 | run-fota-coverage: run-tests-fota 45 | cd ./build-test && ../test/generate_coverage.sh .. && cd .. 46 | echo "\033[0;33mCoverage report is at ./build-test/coverage.html/index.html\033[0m" 47 | -------------------------------------------------------------------------------- /cmake/pal-platform-cmake/curl.cmake: -------------------------------------------------------------------------------- 1 | ################################################################################# 2 | # Copyright 2020 ARM Ltd. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ################################################################################# 16 | 17 | if (NOT MBED_CLOUD_CLIENT_CURL_DYNAMIC_LINK) 18 | set (CMAKE_USE_OPENSSL OFF CACHE BOOL "disable openssl" FORCE) 19 | set (BUILD_TESTING OFF CACHE BOOL "disable testing" FORCE) 20 | set (BUILD_CURL_EXE OFF CACHE BOOL "don't build exe" FORCE) 21 | set (BUILD_SHARED_LIBS OFF CACHE BOOL "don't build share libs" FORCE) 22 | set (ENABLE_INET_PTON OFF CACHE BOOL "disable INET option" FORCE) 23 | set (CURL_ZLIB OFF CACHE BOOL "disable zlib" FORCE) 24 | set (HTTP_ONLY ON CACHE BOOL "set http only mode" FORCE) 25 | set (CMAKE_USE_LIBSSH2 OFF CACHE BOOL "disable ssh2" FORCE) 26 | set (CURL_DISABLE_CRYPTO_AUTH ON CACHE BOOL "disable crypto" FORCE) 27 | set (ENABLE_IPV6 OFF CACHE BOOL "disable ipv6" FORCE) 28 | set (CURL_DISABLE_MQTT ON CACHE BOOL "disable MQTT" FORCE) 29 | set (CURL_DISABLE_VERBOSE_STRINGS ON CACHE BOOL "disable verbose" FORCE) 30 | 31 | set (EXTRA_CMAKE_DIRS ${EXTRA_CMAKE_DIRS} "${CMAKE_SOURCE_DIR}/lib/pal-platform/Middleware/curl/curl") 32 | endif() -------------------------------------------------------------------------------- /cmake/pal-platform-cmake/mbedtls.cmake: -------------------------------------------------------------------------------- 1 | ################################################################################# 2 | # Copyright 2020 ARM Ltd. 3 | # 4 | # SPDX-License-Identifier: Apache-2.0 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | ################################################################################# 18 | 19 | 20 | SET(TLS_LIBRARY mbedTLS) 21 | SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -fomit-frame-pointer") 22 | SET(ENABLE_PROGRAMS OFF CACHE STRING "Avoid compiling mbedtls programs" ) 23 | SET(ENABLE_TESTING OFF CACHE STRING "Avoid compiling mbedtls tests") 24 | 25 | include_directories ("${CMAKE_SOURCE_DIR}/lib/mbedtls") 26 | include_directories ("${CMAKE_SOURCE_DIR}/lib/mbedtls/include") 27 | include_directories ("${CMAKE_SOURCE_DIR}/lib/mbedtls/include/mbedtls") 28 | include_directories ("${CMAKE_SOURCE_DIR}/lib/mbedtls/port/ksdk") 29 | include_directories ("${CMAKE_SOURCE_DIR}/lib/mbedtls/include/psa") 30 | include_directories ("${CMAKE_SOURCE_DIR}/lib/mbedtls/include/mbedtls") 31 | include_directories ("${CMAKE_SOURCE_DIR}/lib/mbedtls/library") 32 | 33 | message(status "device = ${PAL_TARGET_DEVICE}") 34 | set (EXTRA_CMAKE_DIRS ${EXTRA_CMAKE_DIRS} "${CMAKE_SOURCE_DIR}/lib/mbedtls") 35 | 36 | list (APPEND SRC_LIBS mbedtls mbedcrypto mbedx509) 37 | 38 | -------------------------------------------------------------------------------- /cmake/pal-platform-cmake/parsec_se_driver.cmake: -------------------------------------------------------------------------------- 1 | ################################################################################# 2 | # Copyright 2020 ARM Ltd. 3 | # 4 | # SPDX-License-Identifier: Apache-2.0 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | ################################################################################# 18 | 19 | if(PARSEC_TPM_SE_SUPPORT) 20 | # include parsec building cmake 21 | set (EXTRA_CMAKE_DIRS ${EXTRA_CMAKE_DIRS} "${CMAKE_SOURCE_DIR}/lib/pal-platform/Middleware/parsec_se_driver") 22 | endif() 23 | -------------------------------------------------------------------------------- /cmake/pal-platform-cmake/trusted_storage.cmake: -------------------------------------------------------------------------------- 1 | ################################################################################# 2 | # Copyright 2020 ARM Ltd. 3 | # 4 | # SPDX-License-Identifier: Apache-2.0 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | ################################################################################# 18 | 19 | include_directories (BEFORE "${CMAKE_SOURCE_DIR}/lib/pal-platform/Middleware/trusted_storage") 20 | include_directories (BEFORE "${CMAKE_SOURCE_DIR}/lib/pal-platform/Middleware/trusted_storage/trusted_storage/inc") 21 | 22 | set (EXTRA_CMAKE_DIRS ${EXTRA_CMAKE_DIRS} "${CMAKE_SOURCE_DIR}/lib/pal-platform/Middleware/trusted_storage") 23 | 24 | list (APPEND SRC_LIBS trusted_storage) 25 | -------------------------------------------------------------------------------- /cmake/targets/default.cmake: -------------------------------------------------------------------------------- 1 | MESSAGE ("Building standard x86_64 desktop Linux target") 2 | SET (OS_BRAND Linux) 3 | SET (MBED_CLOUD_CLIENT_DEVICE x86_x64) 4 | SET (PAL_TARGET_DEVICE x86_x64) 5 | 6 | if(FOTA_ENABLE AND NOT MBED_CLOUD_CLIENT_CURL_DYNAMIC_LINK) 7 | SET (MBED_CLOUD_CLIENT_MIDDLEWARE curl) 8 | SET (PLATFORM_TARGET x86_x64_NativeLinux_mbedtls) 9 | endif() 10 | 11 | if (${FOTA_ENABLE}) 12 | if (NOT DEFINED FOTA_LINUX_STORAGE_DIR) 13 | SET (MBED_CLOUD_CLIENT_FOTA_LINUX_CONFIG_DIR "\"/opt/izuma\"") 14 | endif() 15 | if (NOT DEFINED FOTA_LINUX_UPDATE_CANDIDATE_FILE) 16 | SET (MBED_CLOUD_CLIENT_FOTA_LINUX_CANDIDATE_FILENAME "\"fota_candidate\"") 17 | endif() 18 | add_definitions( 19 | -DMBED_CLOUD_CLIENT_FOTA_LINUX_CONFIG_DIR=${MBED_CLOUD_CLIENT_FOTA_LINUX_CONFIG_DIR} 20 | -DMBED_CLOUD_CLIENT_FOTA_LINUX_UPDATE_STORAGE_FILENAME="fota_candidate_storage" 21 | -DMBED_CLOUD_CLIENT_FOTA_LINUX_CANDIDATE_FILENAME=${MBED_CLOUD_CLIENT_FOTA_LINUX_CANDIDATE_FILENAME} 22 | ) 23 | endif() 24 | 25 | if(PARSEC_TPM_SE_SUPPORT) 26 | SET (PAL_FS_MOUNT_POINT_PRIMARY "\"./psa\"") 27 | SET (PAL_FS_MOUNT_POINT_SECONDARY "\"./psa\"") 28 | SET (MBED_CLOUD_CLIENT_MIDDLEWARE trusted_storage mbedtls parsec_se_driver) 29 | SET (PLATFORM_TARGET x86_x64_NativeLinux_mbedtls) 30 | SET (MBED_CLOUD_CLIENT_OS Linux_Native) 31 | SET (MBED_CLOUD_CLIENT_SDK ) 32 | SET (MBED_CLOUD_CLIENT_TOOLCHAIN ) 33 | SET (MBED_CLOUD_CLIENT_BUILD_SYS_MIN_VER 2) 34 | SET (MBED_CLOUD_CLIENT_NATIVE_SDK False) 35 | else() 36 | SET (PAL_FS_MOUNT_POINT_PRIMARY "\"./mcc_config\"") 37 | SET (PAL_FS_MOUNT_POINT_SECONDARY "\"./mcc_config\"") 38 | endif() 39 | 40 | SET (PAL_USER_DEFINED_CONFIGURATION "\"${CMAKE_CURRENT_SOURCE_DIR}/config/sotp_fs_linux.h\"") 41 | 42 | if (${FIRMWARE_UPDATE}) 43 | SET (MBED_CLOUD_CLIENT_UPDATE_STORAGE "ARM_UCP_LINUX_GENERIC") 44 | endif() 45 | 46 | -------------------------------------------------------------------------------- /cmake/toolchains/mcc-linux-x86.cmake: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | MESSAGE("Building with mcc-linux-x86 toolchain") 3 | 4 | # default to GNU99 5 | set (CMAKE_C_FLAGS "-fpic -Wall -std=gnu99 -pthread" CACHE STRING "" FORCE) 6 | set (CMAKE_CXX_FLAGS "-Wall -Wno-c++14-compat" CACHE STRING "" FORCE) 7 | 8 | # check that we are actually running on Linux, if we're not then we may pull in 9 | # incorrect dependencies. 10 | if(NOT (${CMAKE_HOST_SYSTEM_NAME} MATCHES "Linux")) 11 | message(FATAL_ERROR "This Linux native target will not work on non-Linux platforms (your platform is ${CMAKE_HOST_SYSTEM_NAME}).") 12 | endif() 13 | 14 | -------------------------------------------------------------------------------- /common/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file (GLOB APR_SOURCES ./apr_base64.c) 2 | file (GLOB DEFAULT_MSG_ID_GENERATOR_SOURCES ./default_message_id_generator.c) 3 | file (GLOB EDGE_TIME_SOURCES ./edge_time.c) 4 | file (GLOB EDGE_TRACE_SOURCES ./edge_trace.c) 5 | file (GLOB INTEGER_LENGTH_SOURCES ./integer_length.c) 6 | file (GLOB MSG_API_SOURCES ./msg_api.c) 7 | file (GLOB PT_API_ERROR_CODES_SOURCES ./pt_api_error_codes.c) 8 | file (GLOB READ_FILE_SOURCES ./read_file.c) 9 | file (GLOB WEBSOCKET_COMM_SOURCES ./websocket_comm.c) 10 | 11 | enable_language(C) 12 | enable_language(CXX) 13 | 14 | add_library (edge-apr-base64 ${APR_SOURCES}) 15 | add_library (edge-default-message-id-generator ${DEFAULT_MSG_ID_GENERATOR_SOURCES}) 16 | add_library (edge-time ${EDGE_TIME_SOURCES}) 17 | add_library (edge-trace ${EDGE_TRACE_SOURCES}) 18 | add_library (edge-integer-length ${INTEGER_LENGTH_SOURCES}) 19 | add_library (edge-msg-api ${MSG_API_SOURCES}) 20 | add_library (pt-api-error-codes ${PT_API_ERROR_CODES_SOURCES}) 21 | add_library (edge-read-file ${READ_FILE_SOURCES}) 22 | add_library (edge-websocket-common ${WEBSOCKET_COMM_SOURCES}) 23 | 24 | target_link_libraries(edge-default-message-id-generator edge-integer-length) 25 | -------------------------------------------------------------------------------- /common/common/msg_api.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ---------------------------------------------------------------------------- 3 | * Copyright 2018 ARM Ltd. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * ---------------------------------------------------------------------------- 19 | */ 20 | 21 | #ifndef MSG_API_H 22 | #define MSG_API_H 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | /** 29 | * \brief Type definition for MSG API call back function. 30 | */ 31 | typedef void (*event_loop_callback_t)(void *data); 32 | 33 | /** 34 | * \brief Sends a message to libevent event loop 35 | * \param base Pointer to libevent base structure. 36 | * \param message The message to send 37 | * \param callback The callback function which will receive the message. 38 | * \return true if the message was successfully sent. 39 | * false if the message couldn't be sent. 40 | */ 41 | bool msg_api_send_message(struct event_base *base, void *data, event_loop_callback_t callback); 42 | 43 | /** 44 | * \brief Sends a message to libevent event loop 45 | * \param base Pointer to libevent base structure. 46 | * \param message The message to send 47 | * \param callback The callback function which will receive the message. 48 | * \param timeout_in_ms Duration for triggering this message. 49 | * \return true if the message was successfully triggered. 50 | * false if the message couldn't be triggered. 51 | */ 52 | bool msg_api_send_message_after_timeout_in_ms(struct event_base *base, 53 | void *data, 54 | event_loop_callback_t callback, 55 | int32_t timeout_in_ms); 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /common/common/msg_api_internal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ---------------------------------------------------------------------------- 3 | * Copyright 2018 ARM Ltd. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * ---------------------------------------------------------------------------- 19 | */ 20 | #ifndef MSG_API_INTERNAL_H 21 | #define MSG_API_INTERNAL_H 22 | 23 | typedef struct x_event_message { 24 | struct event *ev; 25 | event_loop_callback_t callback; 26 | void *data; 27 | } event_message_t; 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /common/common/pt_api_error_parser.h: -------------------------------------------------------------------------------- 1 | 2 | #include "edge-client/request_context.h" 3 | #include "jansson.h" 4 | 5 | /** 6 | * \brief Parses the error code from the JSONRPC error response. 7 | * \param response The JSONRPC error response. `response` may not be NULL. 8 | * \param ctx Pointer to Edge Client request context. The value is written to `ctx->json`. `ctx` may not be NULL. 9 | */ 10 | void pt_api_error_parser_parse_error_response(json_t *response, edgeclient_request_context_t *ctx); 11 | 12 | -------------------------------------------------------------------------------- /common/common/read_file.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ---------------------------------------------------------------------------- 3 | * Copyright 2018 ARM Ltd. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * ---------------------------------------------------------------------------- 19 | */ 20 | 21 | #ifndef EDGE_READ_FILE_H 22 | #define EDGE_READ_FILE_H 23 | 24 | #include 25 | #include 26 | 27 | int edge_read_file(const char* filename, uint8_t** data, size_t *read); 28 | 29 | #endif /* EDGE_READ_FILE_H */ 30 | -------------------------------------------------------------------------------- /common/common/test_support.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ---------------------------------------------------------------------------- 3 | * Copyright 2018 ARM Ltd. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * ---------------------------------------------------------------------------- 19 | */ 20 | 21 | #ifdef BUILD_TYPE_TEST 22 | #define EDGE_LOCAL 23 | #else 24 | #define EDGE_LOCAL static 25 | #endif 26 | -------------------------------------------------------------------------------- /common/default_message_id_generator.c: -------------------------------------------------------------------------------- 1 | /* 2 | * ---------------------------------------------------------------------------- 3 | * Copyright 2018 ARM Ltd. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * ---------------------------------------------------------------------------- 19 | */ 20 | 21 | #include 22 | #include 23 | #include 24 | #include "common/integer_length.h" 25 | 26 | static uint32_t counter = 0; 27 | 28 | char *edge_default_generate_msg_id() 29 | { 30 | /* allocate space for null terminated string */ 31 | char *id = calloc(edge_int_length(counter) + 1, sizeof(char)); 32 | if (NULL != id) { 33 | sprintf(id, "%d", counter); 34 | counter++; 35 | } 36 | return id; 37 | } 38 | -------------------------------------------------------------------------------- /common/edge-mutex/edge_mutex.c: -------------------------------------------------------------------------------- 1 | /* 2 | * ---------------------------------------------------------------------------- 3 | * Copyright 2018 ARM Ltd. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * ---------------------------------------------------------------------------- 19 | */ 20 | #include 21 | #include "common/edge_mutex.h" 22 | 23 | /** 24 | * 25 | * 26 | */ 27 | int32_t edge_mutex_init(edge_mutex_t *mutex, int32_t type) 28 | { 29 | pthread_mutexattr_t attr; 30 | pthread_mutexattr_init(&attr); 31 | pthread_mutexattr_settype(&attr, type); 32 | int32_t ret = (int32_t) pthread_mutex_init(mutex, &attr); 33 | pthread_mutexattr_destroy(&attr); 34 | 35 | return ret; 36 | } 37 | 38 | int32_t edge_mutex_destroy(edge_mutex_t *mutex) 39 | { 40 | return (int32_t) pthread_mutex_destroy(mutex); 41 | } 42 | 43 | int32_t edge_mutex_lock(edge_mutex_t *mutex) 44 | { 45 | return (int32_t) pthread_mutex_lock(mutex); 46 | } 47 | 48 | int32_t edge_mutex_unlock(edge_mutex_t *mutex) 49 | { 50 | return (int32_t) pthread_mutex_unlock(mutex); 51 | } 52 | -------------------------------------------------------------------------------- /common/edge_time.c: -------------------------------------------------------------------------------- 1 | /* 2 | * ---------------------------------------------------------------------------- 3 | * Copyright 2018 ARM Ltd. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * ---------------------------------------------------------------------------- 19 | */ 20 | 21 | #define _POSIX_C_SOURCE 200809L 22 | #include 23 | #include 24 | #include 25 | #include "common/edge_time.h" 26 | #include 27 | 28 | uint64_t edgetime_get_monotonic_in_ms() 29 | { 30 | #ifdef _POSIX_MONOTONIC_CLOCK 31 | struct timespec ts; 32 | if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0) { 33 | return (uint64_t)(ts.tv_sec * 1000 + ts.tv_nsec / 1000000); 34 | } else { 35 | return 0; 36 | } 37 | #else 38 | return 0; 39 | #endif 40 | } 41 | 42 | bool edgetime_get_real_in_ns(uint64_t *seconds, uint64_t *ns) 43 | { 44 | struct timespec spec; 45 | if (0 == clock_gettime(CLOCK_REALTIME, &spec)) { 46 | *ns = spec.tv_nsec; 47 | *seconds = spec.tv_sec; 48 | return true; 49 | } else { 50 | *ns = 0; 51 | *seconds = 0; 52 | } 53 | return false; 54 | } 55 | 56 | -------------------------------------------------------------------------------- /common/integer_length.c: -------------------------------------------------------------------------------- 1 | /* 2 | * ---------------------------------------------------------------------------- 3 | * Copyright 2018 ARM Ltd. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * ---------------------------------------------------------------------------- 19 | */ 20 | 21 | #include 22 | #include 23 | #include 24 | #include "common/integer_length.h" 25 | 26 | uint16_t edge_int_length(uint32_t value) 27 | { 28 | uint16_t length = 1; 29 | while (value > 9) { 30 | length++; 31 | value /= 10; 32 | } 33 | return length; 34 | } 35 | 36 | int edge_str_to_uint16_t(const char *str, uint16_t *result) 37 | { 38 | if (!str || strlen(str) == 0) { 39 | return 1; 40 | } 41 | uint16_t len = strlen(str); 42 | for (int i = 0; i < len; i++) { 43 | if (str[i] < '0' || str[i] > '9') { 44 | return 1; 45 | } 46 | } 47 | *result = atoi(str); 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /common/pt_api_error_parser.c: -------------------------------------------------------------------------------- 1 | #include "common/pt_api_error_parser.h" 2 | #include "common/pt_api_error_codes.h" 3 | #include "mbed-trace/mbed_trace.h" 4 | #define TRACE_GROUP "jsonrpcerror" 5 | 6 | void pt_api_error_parser_parse_error_response(json_t *response, edgeclient_request_context_t *ctx) 7 | { 8 | int32_t code = PT_API_INTERNAL_ERROR; 9 | json_t *error = json_object_get(response, "error"); 10 | json_t *id_obj = json_object_get(response, "id"); 11 | char *id = NULL; 12 | 13 | if (id_obj) { 14 | id = json_dumps(id_obj, JSON_COMPACT|JSON_ENCODE_ANY); 15 | } 16 | 17 | if (error) { 18 | json_t *code_obj = json_object_get(error, "code"); 19 | if (code_obj) { 20 | code = json_integer_value(code_obj); 21 | } else { 22 | tr_err("pt_api_error_parser_parse_error_response: missing error code for response, id: %s", id); 23 | } 24 | } else { 25 | tr_err("pt_api_error_parser_parse_error_response: missing error object for response, id: %s", id); 26 | } 27 | free(id); 28 | ctx->jsonrpc_error_code = code; 29 | } 30 | 31 | -------------------------------------------------------------------------------- /config/.gitignore: -------------------------------------------------------------------------------- 1 | mbed_cloud_dev_credentials.* 2 | update_default_resources.c 3 | -------------------------------------------------------------------------------- /config/edge_component_update_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2025 Izuma Networks Inc 3 | * 4 | * This file is licensed under the Limited Revocable Evaluation License. 5 | * Use of this source code is subject to the terms and conditions of the license. 6 | * See IZLREL_LICENSE.txt for full details. 7 | */ 8 | 9 | #ifndef EDGE_COMPONENT_FOTA_CONFIG_H 10 | #define EDGE_COMPONENT_FOTA_CONFIG_H 11 | 12 | #define FOTA_SCRIPT_DIR "/opt/izuma" 13 | #define FOTA_INSTALL_SCRIPT "fota_update_activate.sh" 14 | #define FOTA_VERIFY_SCRIPT "fota_update_verify.sh" 15 | 16 | #define EDGE_COMPONENT_1_NAME "COMP_1" 17 | #define EDGE_COMPONENT_1_VERSION "0.0.1" 18 | 19 | #endif // EDGE_COMPONENT_FOTA_CONFIG_H -------------------------------------------------------------------------------- /config/header_template.txt: -------------------------------------------------------------------------------- 1 | /* 2 | * ---------------------------------------------------------------------------- 3 | * Copyright 2018 ARM Ltd. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * ---------------------------------------------------------------------------- 19 | */ 20 | 21 | -------------------------------------------------------------------------------- /config/mbed_cloud_client_user_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ---------------------------------------------------------------------------- 3 | * Copyright 2018-2021 Pelion. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * ---------------------------------------------------------------------------- 19 | */ 20 | 21 | /* 22 | * Minimal configuration for using mbed-cloud-client 23 | */ 24 | 25 | #ifndef MBED_CLOUD_CLIENT_USER_CONFIG_H 26 | #define MBED_CLOUD_CLIENT_USER_CONFIG_H 27 | 28 | #define MBED_CLOUD_CLIENT_ENDPOINT_TYPE "MBED_GW" 29 | #define MBED_CLOUD_CLIENT_TRANSPORT_MODE_TCP 30 | #define MBED_CLOUD_CLIENT_LIFETIME 3600 31 | 32 | #define SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE 1024 33 | #define SN_COAP_DISABLE_RESENDINGS 34 | 35 | /* set download buffer size in bytes (min. 1024 bytes) */ 36 | #define MBED_CLOUD_CLIENT_UPDATE_BUFFER (2 * 1024 * 1024) 37 | 38 | /* set the TCP KEEPALIVE values */ 39 | #define MBED_CLIENT_TCP_KEEPALIVE_INTERVAL 60 40 | #define MBED_CLIENT_TCP_KEEPALIVE_TIME 60 41 | #define MBED_CONF_MBED_CLIENT_MAX_RECONNECT_TIMEOUT 600 42 | #endif /* MBED_CLIENT_USER_CONFIG_H */ 43 | 44 | -------------------------------------------------------------------------------- /config/psa_storage_user_config.h: -------------------------------------------------------------------------------- 1 | // ---------------------------------------------------------------------------- 2 | // Copyright 2019 ARM Ltd. 3 | // 4 | // SPDX-License-Identifier: Apache-2.0 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // ---------------------------------------------------------------------------- 18 | 19 | #ifndef PSA_STORAGE_USER_CONFIG_H 20 | #define PSA_STORAGE_USER_CONFIG_H 21 | 22 | /** 23 | * \def PSA_STORAGE_FILE_C_STORAGE_PREFIX 24 | * 25 | * Define the path to the directory for Internal Trusted Storage 26 | * (PSA ITS) files representing persisted objects. For example, 27 | * to store files in "/home/username" define 28 | * PSA_STORAGE_FILE_C_STORAGE_PREFIX "/home/username/" 29 | * (note the appended "/"). 30 | */ 31 | #ifdef PSA_STORAGE_FILE_C_STORAGE_PREFIX 32 | #undef PSA_STORAGE_FILE_C_STORAGE_PREFIX 33 | #endif 34 | 35 | #define PSA_STORAGE_FILE_C_STORAGE_PREFIX "psa/" 36 | 37 | #endif /* PSA_STORAGE_USER_CONFIG_H */ 38 | -------------------------------------------------------------------------------- /config/sotp_fs_linux.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ---------------------------------------------------------------------------- 3 | * Copyright 2018 ARM Ltd. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * ---------------------------------------------------------------------------- 19 | */ 20 | #ifndef PAL_HEADER_SOTP_FS_LINUX 21 | #define PAL_HEADER_SOTP_FS_LINUX 22 | 23 | #define PAL_USE_HW_ROT 0 24 | #define PAL_USE_HW_RTC 0 25 | #define PAL_USE_HW_TRNG 1 26 | #define PAL_SIMULATOR_FLASH_OVER_FILE_SYSTEM 1 27 | #define PAL_USE_SECURE_TIME 1 28 | #define PAL_SIMULATOR_TEST_ENABLE 1 29 | 30 | #include "Linux_default.h" 31 | 32 | #endif //PAL_HEADER_SOTP_FS_LINUX 33 | -------------------------------------------------------------------------------- /docs/prepare_fota_component_update.md: -------------------------------------------------------------------------------- 1 | # Firmware (FOTA) with Edge Core 2 | 3 | ## Prepare edge-core for firmware update of the MAIN and COMP_1 components 4 | 5 | In the `./fota` directory, there are 2 folders that contain example firmware update scripts to demonstrate how to update the MAIN and COMP_1 components. Each component requires 2 update scripts: 1 for installation, `fota_update_activate.sh`, and 2 for verification, `fota_update_verify.sh`. By default, the MAIN component verification is performed internally by reading the firmware version from the metadata file; therefore, MAIN does not require a verification script. To complete the update process, Edge-core requires a restart after the installation script has successfully exited. By default, the Docker containers use the `./start.sh` script, which traps the process exit code and restarts edge-core after 5 seconds. 6 | 7 | The `fota_update_activate.sh` script is invoked once the firmware image is downloaded. A success is reported when the script exits with code 0. For any other value, the installation will fail and require a new firmware update campaign to retry the installation. The `fota_update_verify.sh` script is invoked after the installation is complete. To support an asynchronous update workflow, you can stall any of the scripts to report success only after the update process is finished. 8 | 9 | Edge-core reports to Izuma Cloud the number of components it supports. By default, you can have five components (including MAIN). You can update this number by overriding the compile-time macro [FOTA_NUM_COMPONENTS](https://github.com/PelionIoT/mbed-cloud-client/blob/c04abe4de443a82e4634737e8d5b9ae036718ba2/fota/fota_component_defs.h#L26). Additionally, note that currently, only the SemVer format MAJOR.MINOR.PATCH is supported, with all non-negative integer values. This is primarily done to easily compare versions between upgrades and ensure that updates are applied in an incremental manner. The component name cannot exceed nine characters, as set by the macro [FOTA_COMPONENT_MAX_NAME_SIZE](https://github.com/PelionIoT/mbed-cloud-client/blob/c04abe4de443a82e4634737e8d5b9ae036718ba2/fota/fota_component_defs.h#L31). 10 | 11 | To enable FOTA features, compile edge-core with the following flags: `-DFIRMWARE_UPDATE=ON -DFOTA_ENABLE=ON -DFOTA_COMBINED_IMAGE_SUPPORT=ON`. For a compilation example, refer to `Dockerfile.debian.*`. -------------------------------------------------------------------------------- /doxygen_frontpage.md: -------------------------------------------------------------------------------- 1 | ## Device Management Edge API 2 | 3 | This is the Doxygen generated API documentation of Device Management Edge. 4 | The API documentation should be used together with the 5 | [Device Management documentation](https://developer.izumanetworks.com/docs/device-management/current/welcome/index.html). 6 | 7 | The Device Management Edge APIs allow the developers to create protocol translators to adapt 8 | devices that use non-IP based protocols to be managed with Device Management. 9 | These can use for example BacNET, Zigbee, BLE, LoRa or MQTT protocols. Also devices that have 10 | IP connectivity but cannot host full Device Management Client can be adapted with Device Management 11 | Edge API through the protocol translator. 12 | 13 | The APIs are implemented in C and some protocol translator examples are in the [mbed-edge-examples repository](https://github.com/PelionIoT/mbed-edge-examples). 14 | 15 | The requirements to connect to Device Management are similar between Device Management Edge and 16 | Device Management Client. Please read the [Device Management Client documentation](https://developer.izumanetworks.com/docs/device-management/current/connecting/index.html) to understand 17 | the connectivity of Device Management Edge. 18 | 19 | ### Device Management Edge components 20 | 21 | The main components of the Device Management Edge are: 22 | * [Device Management Client](https://developer.izumanetworks.com/docs/device-management/current/welcome/index.html). 23 | * [Device Management Edge Core](https://developer.izumanetworks.com/docs/device-management-edge/latest/protocol-translator/edge-core.html). 24 | * [Protocol translator API](https://developer.izumanetworks.com/docs/device-management-edge/latest/protocol-translator/index.html#protocol-translator-development-with-the-c-api). 25 | 26 | Device Management Client provides the connectivity to Device Management which Edge core 27 | is extending. Device Management Edge Core implements the specific gateway functionality 28 | and logic. The protocol translator API is used to implement the specific protocol 29 | translator implementation to adapt devices to be managed with Device Management. 30 | 31 | The protocol translator communicates with Device Management Edge Core and these components 32 | implements the full adaptation of the devices to be managed. 33 | -------------------------------------------------------------------------------- /edge-client/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(edge-client) 2 | set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS TRUE) 3 | 4 | if (TARGET_GROUP STREQUAL test) 5 | add_definitions(-DBUILD_TYPE_TEST) 6 | endif () 7 | 8 | file (GLOB SOURCES ./*.cpp ./*.c ../common/integer_length.c ../common/msg_api.c) 9 | 10 | add_definitions(-DMBED_CONF_MBED_TRACE_ENABLE=1) 11 | 12 | add_library (edge-client STATIC ${SOURCES}) 13 | set_target_properties(edge-client PROPERTIES LINKER_LANGUAGE CXX) 14 | target_include_directories (edge-client PUBLIC ${ROOT_HOME}/edge-core) 15 | 16 | if (ENABLE_SUBDEVICE_FOTA) 17 | target_include_directories (edge-client PUBLIC ${ROOT_HOME}/lib/mbed-cloud-client/fota) 18 | endif() 19 | 20 | if(ENABLE_UC_HUB) 21 | target_include_directories (edge-client PUBLIC ${ROOT_HOME}/lib/mbed-cloud-client/update-client-hub/modules/common/update-client-common) 22 | endif() 23 | 24 | if (TARGET_GROUP STREQUAL test) 25 | list (APPEND EDGE_CLIENT_LIBS libevent-mock-lib edge-server-mock-lib test-lib pal-mock-lib mbed-cloud-client-mock) 26 | else () 27 | list (APPEND EDGE_CLIENT_LIBS pthread stdc++ mbedCloudClient mbedtls rt) 28 | if (${RFS_GPIO}) 29 | list (APPEND EDGE_CLIENT_LIBS gpiod) 30 | endif () 31 | if (${DEVELOPER_MODE}) 32 | list (APPEND EDGE_CLIENT_LIBS mbed-developer-certificate) 33 | endif () 34 | if (${FIRMWARE_UPDATE} AND ${DEVELOPER_MODE}) 35 | list (APPEND EDGE_CLIENT_LIBS mbed-update-default-resources) 36 | endif () 37 | endif () 38 | 39 | if(PARSEC_TPM_SE_SUPPORT) 40 | list (APPEND EDGE_CLIENT_LIBS palFilesystem fccstorage mbedcrypto -lm trusted_storage) 41 | endif() 42 | 43 | target_link_libraries(edge-client ${EDGE_CLIENT_LIBS}) 44 | -------------------------------------------------------------------------------- /edge-client/edge-client/edge_client_byoc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ---------------------------------------------------------------------------- 3 | * Copyright 2018 ARM Ltd. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * ---------------------------------------------------------------------------- 19 | */ 20 | 21 | #ifndef EDGE_CLIENT_BYOC_H_ 22 | #define EDGE_CLIENT_BYOC_H_ 23 | 24 | typedef struct { 25 | const char *cbor_file; // Passed value must be in stack. 26 | } byoc_data_t; 27 | 28 | byoc_data_t *edgeclient_create_byoc_data(char *cbor_file); 29 | void edgeclient_destroy_byoc_data(byoc_data_t *byoc_data); 30 | int edgeclient_inject_byoc(byoc_data_t *byoc_data); 31 | 32 | #endif /* EDGE_CLIENT_BYOC_H_ */ 33 | -------------------------------------------------------------------------------- /edge-client/edge-client/edge_client_mgmt.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ---------------------------------------------------------------------------- 3 | * Copyright 2018 ARM Ltd. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * ---------------------------------------------------------------------------- 19 | */ 20 | 21 | #ifndef EDGE_CLIENT_MGMT_H_ 22 | #define EDGE_CLIENT_MGMT_H_ 23 | 24 | #include "ns_list.h" 25 | #include "common/constants.h" 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | typedef struct edge_device_resource_entry_s { 32 | ns_list_link_t link; 33 | char *uri; 34 | Lwm2mResourceType type; 35 | uint8_t operation; 36 | } edge_device_resource_entry_t; 37 | 38 | typedef NS_LIST_HEAD(edge_device_resource_entry_t, link) edge_device_resource_list_t; 39 | 40 | typedef struct edge_device_entry_s { 41 | ns_list_link_t link; 42 | char *name; 43 | edge_device_resource_list_t *resources; 44 | } edge_device_entry_t; 45 | 46 | typedef NS_LIST_HEAD(edge_device_entry_t, link) edge_device_list_t; 47 | 48 | void edgeclient_destroy_device_list(edge_device_list_t *devices); 49 | edge_device_list_t *edgeclient_devices(); 50 | 51 | #ifdef __cplusplus 52 | } 53 | #endif 54 | 55 | #endif // EDGE_CLIENT_MGMT_H_ 56 | -------------------------------------------------------------------------------- /edge-client/edge-client/edge_core_cb_result.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ---------------------------------------------------------------------------- 3 | * Copyright 2018 ARM Ltd. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * ---------------------------------------------------------------------------- 19 | */ 20 | 21 | #ifndef EDGE_CORE_CB_RESULT_H 22 | #define EDGE_CORE_CB_RESULT_H 23 | 24 | #include "edge-client/edge_client.h" 25 | 26 | /** 27 | * \ingroup EDGE_CORE_CB_RESULT Edge Core Callback Result API 28 | * @{ 29 | */ 30 | 31 | /** 32 | * \file edge_core_cb_result.h 33 | * \brief Definition of the Edge Core Callback Result API (internal). 34 | */ 35 | 36 | #ifdef __cplusplus 37 | extern "C" { 38 | #endif 39 | 40 | /** 41 | * \brief Called when the asynchronous request succeeded. 42 | * This currently only traces information about the request. 43 | * \param ctx Data and state relating to the execute request. 44 | */ 45 | void edgecore_async_cb_success(edgeclient_request_context_t *ctx); 46 | 47 | /** 48 | * \brief Called when the asynchronous request failed. 49 | * This currently only traces information about the request. 50 | * \param ctx Data and state relating to the execute request. 51 | */ 52 | void edgecore_async_cb_failure(edgeclient_request_context_t *ctx); 53 | 54 | #ifdef __cplusplus 55 | } 56 | #endif 57 | 58 | /** 59 | * @} 60 | * Close EDGE_CORE_CB_RESULT Doxygen group definition 61 | */ 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /edge-client/edge-client/edge_manifest_object.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ---------------------------------------------------------------------------- 3 | * Copyright 2020 ARM Ltd. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * ---------------------------------------------------------------------------- 19 | */ 20 | 21 | #ifdef MBED_EDGE_SUBDEVICE_FOTA 22 | #ifndef EDGE_MANIFEST_OBJECT_H_ 23 | #define EDGE_MANIFEST_OBJECT_H_ 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | #define MANIFEST_OBJECT 10252 30 | #define DEVICE_META_OBJECT 10255 31 | #define MANIFEST_INSTANCE 0 32 | #define MANIFEST_RESOURCE_PAYLOAD 1 33 | #define MANIFEST_RESOURCE_STATE 2 34 | #define MANIFEST_RESOURCE_RESULT 3 35 | #define MANIFEST_ASSET_HASH 5 36 | #define MANIFEST_VERSION 6 37 | #define SOFTWARE_COMPONENT 14 38 | #define xstr(s) str(s) 39 | #define str(s) #s 40 | #define MANIFEST_INFORMATION 10252/0/1 41 | 42 | #ifdef __cplusplus 43 | } 44 | #endif 45 | 46 | #endif /* EDGE_MANIFEST_OBJECT_H_ */ 47 | 48 | #endif // MBED_EDGE_SUBDEVICE_FOTA -------------------------------------------------------------------------------- /edge-client/edge-client/eventloop_tracing.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ---------------------------------------------------------------------------- 3 | * Copyright 2018 ARM Ltd. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * ---------------------------------------------------------------------------- 19 | */ 20 | 21 | #ifndef EVENTLOOP_TRACING_H_ 22 | #define EVENTLOOP_TRACING_H_ 23 | 24 | #ifdef EDGE_EVENTLOOP_STATS_TRACING 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif // __cplusplus 29 | 30 | void eventloop_stats_init(); 31 | 32 | #ifdef __cplusplus 33 | } 34 | #endif // __cplusplus 35 | 36 | #else // EDGE_EVENTLOOP_STATS_TRACING 37 | 38 | // No eventloop tracing so define the empty init function 39 | #define eventloop_stats_init(...) ((void)0) 40 | 41 | #endif // EDGE_EVENTLOOP_STATS_TRACING 42 | 43 | #endif // EVENTLOP_TRACING_H_ 44 | -------------------------------------------------------------------------------- /edge-client/edge-client/reset_factory_settings.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ---------------------------------------------------------------------------- 3 | * Copyright 2018 ARM Ltd. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * ---------------------------------------------------------------------------- 19 | */ 20 | 21 | #ifndef RESET_FACTORY_SETTINGS_H 22 | #define RESET_FACTORY_SETTINGS_H 23 | 24 | #include "edge-client/edge_client.h" 25 | #include 26 | #include 27 | 28 | /** 29 | * \ingroup RESET_FACTORY_SETTINGS Reset Factory Settings API 30 | * @{ 31 | */ 32 | 33 | /** 34 | * \file reset_factory_settings.h 35 | * \brief Definition Reset Factory Settings Edge internal API (internal). 36 | */ 37 | 38 | /** 39 | * \brief Adds the reset factory settings resource. 40 | */ 41 | void rfs_add_factory_reset_resource(); 42 | 43 | /** 44 | * \brief Called when reset factory settings request comes from Device Management. 45 | * \param request_ctx Data and state information about the reset factory settings request. 46 | * \see edgeclient_request_context_t 47 | */ 48 | void rfs_reset_factory_settings_requested(edgeclient_request_context_t *request_ctx); 49 | 50 | /** 51 | * \brief Finalizes Factory Settings 52 | * 53 | * This function is called when Edge Core is shutting down and releasing the resources when the process is just about 54 | * to quit. It calls kcm_factory_reset and prints an error if it fails. 55 | */ 56 | void rfs_finalize_reset_factory_settings(); 57 | 58 | /** 59 | * @} 60 | * Close RESET_FACTORY_SETTINGS Doxygen group definition 61 | */ 62 | #endif 63 | -------------------------------------------------------------------------------- /edge-client/edge-client/reset_factory_settings_internal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ---------------------------------------------------------------------------- 3 | * Copyright 2018 ARM Ltd. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * ---------------------------------------------------------------------------- 19 | */ 20 | 21 | #ifndef RESET_FACTORY_SETTINGS_INTERNAL_H 22 | #define RESET_FACTORY_SETTINGS_INTERNAL_H 23 | #include 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | typedef struct x_rfs_thread_param { 30 | edgeclient_request_context_t *ctx; 31 | pthread_t *thread; 32 | } rfs_thread_param_t; 33 | 34 | typedef struct x_rfs_thread_result { 35 | pthread_t *thread; 36 | bool customer_rfs_succeeded; 37 | edgeclient_request_context_t *request_ctx; 38 | } rfs_thread_result_t; 39 | 40 | typedef struct x_rfs_request_message { 41 | edgeclient_request_context_t *request_ctx; 42 | } rfs_request_message_t; 43 | 44 | EDGE_LOCAL void rfs_reset_factory_settings_request_cb(void *arg); 45 | EDGE_LOCAL void rfs_reset_factory_settings_response_cb(void *arg); 46 | #ifdef __cplusplus 47 | } 48 | #endif 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /edge-core/edge-core/client_type.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ---------------------------------------------------------------------------- 3 | * Copyright 2018 ARM Ltd. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * ---------------------------------------------------------------------------- 19 | */ 20 | 21 | #ifndef CLIENT_TYPE_H 22 | #define CLIENT_TYPE_H 23 | 24 | #include 25 | #include "ns_list.h" 26 | 27 | enum client_type { 28 | PT, 29 | MGMT, 30 | GRM 31 | }; 32 | 33 | typedef struct string_list_entry { 34 | char *string; 35 | ns_list_link_t link; 36 | } string_list_entry_t; 37 | 38 | typedef NS_LIST_HEAD(string_list_entry_t, link) string_list_t; 39 | 40 | struct client_data; 41 | 42 | typedef void (*pre_destroy_client_data)(struct client_data *client_data); 43 | 44 | typedef struct client_data { 45 | char *name; 46 | bool registered; 47 | int id; 48 | void *method_table; 49 | string_list_t certificate_list; 50 | pre_destroy_client_data _pre_destroy_client_data; 51 | } client_data_t; 52 | 53 | /* 54 | * \brief Create a new client 55 | */ 56 | client_data_t *edge_core_create_client(enum client_type client_type); 57 | void edge_core_client_data_destroy(client_data_t **client_data); 58 | 59 | #endif // CLIENT_TYPE_H 60 | -------------------------------------------------------------------------------- /edge-core/edge-core/edge_device_object.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ---------------------------------------------------------------------------- 3 | * Copyright 2018 ARM Ltd. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * ---------------------------------------------------------------------------- 19 | */ 20 | 21 | #ifndef EDGE_DEVICE_OBJECT_H_ 22 | #define EDGE_DEVICE_OBJECT_H_ 23 | 24 | // Object ids 25 | #define EDGE_DEVICE_OBJECT_ID 3 26 | // Resource ids for EDGE_DEVICE_OBJECT_ID 27 | #define EDGE_FACTORY_RESET_RESOURCE_ID 5 28 | 29 | #endif /* EDGE_DEVICE_OBJECT_H_ */ 30 | -------------------------------------------------------------------------------- /edge-core/edge-core/http_server.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ---------------------------------------------------------------------------- 3 | * Copyright 2018 ARM Ltd. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * ---------------------------------------------------------------------------- 19 | */ 20 | 21 | #ifndef HTTP_SERVER_H 22 | #define HTTP_SERVER_H 23 | 24 | #include 25 | #include 26 | #include "common/test_support.h" 27 | #include "server.h" 28 | 29 | struct http_server { 30 | struct evhttp *http; 31 | struct evhttp_bound_socket *bound_socket; 32 | }; 33 | 34 | bool http_server_init(struct context *ctx, int port); 35 | void http_server_clean(struct http_server **server); 36 | json_t *http_state_in_json(struct context *ctx); 37 | 38 | /* Expose normally static methods for unit testing */ 39 | #ifdef BUILD_TYPE_TEST 40 | void status_request_cb(struct evhttp_request *req, void *arg); 41 | void generic_request_cb(struct evhttp_request *req, void *arg); 42 | #endif 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /edge-core/edge-core/mgmt_api_internal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ---------------------------------------------------------------------------- 3 | * Copyright 2018 ARM Ltd. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * ---------------------------------------------------------------------------- 19 | */ 20 | 21 | #ifndef MGMT_API_INTERNAL_H 22 | #define MGMT_API_INTERNAL_H 23 | 24 | #include "edge-rpc/rpc.h" 25 | 26 | int devices(json_t *request, json_t *json_params, json_t **result, void *userdata); 27 | int read_resource(json_t *request, json_t *json_params, json_t **result, void *userdata); 28 | int write_resource(json_t *request, json_t *json_params, json_t **result, void *userdata); 29 | 30 | extern struct jsonrpc_method_entry_t mgmt_api_method_table[]; 31 | 32 | #ifdef BUILD_TYPE_TEST 33 | struct edgeclient_request_context; 34 | void mgmt_api_write_success(struct edgeclient_request_context *ctx); 35 | void mgmt_api_write_failure(struct edgeclient_request_context *ctx); 36 | #endif 37 | 38 | #endif // MGMT_API_INTERNAL_H 39 | -------------------------------------------------------------------------------- /edge-core/edge-core/protocol_api_internal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ---------------------------------------------------------------------------- 3 | * Copyright 2018 ARM Ltd. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * ---------------------------------------------------------------------------- 19 | */ 20 | 21 | #ifndef PROTOCOL_API_INTERNAL_H 22 | #define PROTOCOL_API_INTERNAL_H 23 | 24 | #include "edge-rpc/rpc.h" 25 | #include "client_type.h" 26 | #include "edge-core/server.h" 27 | 28 | typedef struct transport_connection { 29 | void *transport; 30 | write_func write_function; 31 | } transport_connection_t; 32 | 33 | 34 | typedef struct connection { 35 | struct context *ctx; 36 | client_data_t *client_data; 37 | transport_connection_t *transport_connection; 38 | void *userdata; 39 | connection_id_t id; 40 | bool connected; 41 | } connection_t; 42 | 43 | typedef struct protocol_api_async_request_context_ { 44 | uint8_t *data_ptr; 45 | int data_int; 46 | connection_id_t connection_id; 47 | char *request_id; 48 | } protocol_api_async_request_context_t; 49 | 50 | void transport_connection_t_destroy(transport_connection_t **transport_connection); 51 | void edge_core_protocol_api_client_data_destroy(client_data_t *client_data); 52 | bool pt_api_check_request_id(struct json_message_t *jt); 53 | bool pt_api_check_service_availability(json_t **result); 54 | json_t *pt_api_allocate_response_common(const char *request_id); 55 | void protocol_api_free_async_ctx_func(rpc_request_context_t *ctx); 56 | protocol_api_async_request_context_t *protocol_api_prepare_async_ctx(const json_t *request, const connection_id_t connection_id); 57 | 58 | extern struct jsonrpc_method_entry_t method_table[]; 59 | 60 | #endif // PROTOCOL_API_INTERNAL_H 61 | -------------------------------------------------------------------------------- /edge-core/edge-core/protocol_crypto_api_internal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ---------------------------------------------------------------------------- 3 | * Copyright 2018 ARM Ltd. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * ---------------------------------------------------------------------------- 19 | */ 20 | 21 | #include "nanostack-event-loop/eventOS_event.h" 22 | 23 | typedef enum { 24 | CRYPTO_API_EVENT_INIT, 25 | CRYPTO_API_EVENT_GET_CERTIFICATE, 26 | CRYPTO_API_EVENT_GET_PUBLIC_KEY, 27 | CRYPTO_API_EVENT_GENERATE_RANDOM, 28 | CRYPTO_API_EVENT_ASYMMETRIC_SIGN, 29 | CRYPTO_API_EVENT_ASYMMETRIC_VERIFY, 30 | CRYPTO_API_EVENT_ECDH_KEY_AGREEMENT 31 | } crypto_api_event_e; 32 | 33 | #ifdef BUILD_TYPE_TEST 34 | void crypto_api_event_handler(arm_event_t *event); 35 | extern int8_t crypto_api_tasklet_id; 36 | #endif 37 | 38 | -------------------------------------------------------------------------------- /edge-core/edge-core/srv_comm.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ---------------------------------------------------------------------------- 3 | * Copyright 2018 ARM Ltd. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * ---------------------------------------------------------------------------- 19 | */ 20 | 21 | #ifndef SRV_COMM_H_ 22 | #define SRV_COMM_H_ 23 | 24 | #include "edge-core/protocol_api_internal.h" 25 | 26 | struct connection; 27 | 28 | int edge_core_write_data_frame_websocket(struct connection *connection, char *data, size_t len); 29 | void edge_core_process_data_frame_websocket(struct connection *connection, 30 | bool *protocol_error, 31 | size_t len, 32 | const char *data); 33 | bool close_connection(struct connection *connection); 34 | void close_connection_trigger(struct connection *connection); 35 | int edge_core_count_send_queue_websocket(struct connection *connection); 36 | void connection_destroy(struct connection **connection); 37 | 38 | #endif /* SRV_COMM_H_ */ 39 | 40 | -------------------------------------------------------------------------------- /edge-core/edge-core/websocket_serv.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ---------------------------------------------------------------------------- 3 | * Copyright 2018 ARM Ltd. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * ---------------------------------------------------------------------------- 19 | */ 20 | 21 | #ifndef INCLUDE_WEBSOCKET_SERV_H_ 22 | #define INCLUDE_WEBSOCKET_SERV_H_ 23 | 24 | typedef struct websocket_connection websocket_connection_t; 25 | websocket_connection_t *websocket_server_connection_initialize(websocket_connection_t *websocket_connection); 26 | void websocket_server_connection_destroy(websocket_connection_t *wct); 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /edge-core/edge_core.docopt: -------------------------------------------------------------------------------- 1 | Edge Core 2 | 3 | Usage: 4 | edge-core [options] 5 | edge-core --help 6 | edge-core --version 7 | 8 | Options: 9 | -h --help Show this screen. 10 | -v --version Show the version number 11 | --color-log Use ANSI colors in log. 12 | -p --edge-pt-domain-socket Protocol API domain socket [default: /tmp/edge.sock]. 13 | -o --http-port HTTP port number [default: 8080]. 14 | -r --reset-storage Before starting the server, clean the old Device Management Client 15 | configuration. 16 | -c --cbor-conf The CBOR configuration file path. 17 | The CBOR configuration option is mandatory for the first 18 | start of the Edge Core when it is built with BYOC_MODE. 19 | This option cannot be used if built with DEVELOPER_MODE or FACTORY_MODE. 20 | If this option is given second time (without --reset-storage) the current 21 | Device Management Client configuration is used. 22 | -------------------------------------------------------------------------------- /edge-core/edge_server_customer_code.c: -------------------------------------------------------------------------------- 1 | /* 2 | * ---------------------------------------------------------------------------- 3 | * Copyright 2018 ARM Ltd. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * ---------------------------------------------------------------------------- 19 | */ 20 | 21 | #include "edge-client/edge_client.h" 22 | #include "mbed-trace/mbed_trace.h" 23 | #include "edge-core/edge_server_customer_code.h" 24 | #define TRACE_GROUP "escstmr" 25 | 26 | bool edgeserver_execute_rfs_customer_code(edgeclient_request_context_t *request_ctx) 27 | { 28 | if (request_ctx) { 29 | tr_info("edgeserver_execute_rfs_customer_code %d/%d/%d", 30 | request_ctx->object_id, 31 | request_ctx->object_instance_id, 32 | request_ctx->resource_id); 33 | } else { 34 | tr_info("edgeserver_execute_rfs_customer_code (local)"); 35 | } 36 | return true; 37 | } 38 | 39 | -------------------------------------------------------------------------------- /edge-core/gen_docopt.sh: -------------------------------------------------------------------------------- 1 | # ---------------------------------------------------------------------------- 2 | # Copyright 2018 ARM Ltd. 3 | # 4 | # SPDX-License-Identifier: Apache-2.0 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # ---------------------------------------------------------------------------- 18 | python3 ../lib/docopt.c/docopt_c.py -t ../cli_template.tmpl -o edge_core_clip.h edge_core.docopt 19 | 20 | -------------------------------------------------------------------------------- /edge-core/websocket_serv.c: -------------------------------------------------------------------------------- 1 | /* 2 | * ---------------------------------------------------------------------------- 3 | * Copyright 2018 ARM Ltd. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * ---------------------------------------------------------------------------- 19 | */ 20 | 21 | #include 22 | #include 23 | #include 24 | #include "libwebsockets.h" 25 | #include "common/websocket_comm.h" 26 | #include "edge-core/websocket_serv.h" 27 | #include "ns_list.h" 28 | #include "mbed-trace/mbed_trace.h" 29 | #define TRACE_GROUP "webs" 30 | 31 | websocket_connection_t *websocket_server_connection_initialize(websocket_connection_t *websocket_connection) 32 | { 33 | websocket_message_list_t* sent = 34 | (websocket_message_list_t*) malloc(sizeof(websocket_message_list_t)); 35 | if (!sent) { 36 | tr_err("Could not allocate sent or received websocket message list."); 37 | free(sent); 38 | free(websocket_connection); 39 | return NULL; 40 | } 41 | 42 | ns_list_init(sent); 43 | websocket_connection->to_close = false; 44 | websocket_connection->sent = sent; 45 | websocket_connection->msg_len = 0; 46 | websocket_connection->msg = NULL; 47 | return websocket_connection; 48 | } 49 | 50 | void websocket_server_connection_destroy(websocket_connection_t *wct) 51 | { 52 | if (wct) { 53 | ns_list_foreach_safe(websocket_message_t, cur, wct->sent) { 54 | free(cur->bytes); 55 | ns_list_remove(wct->sent, cur); 56 | free(cur); 57 | } 58 | free(wct->sent); 59 | } 60 | } 61 | 62 | -------------------------------------------------------------------------------- /edge-rpc/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file (GLOB SOURCES ./*.c ../common/edge_time.c) 2 | list(APPEND SOURCES ../common/edge-mutex/edge_mutex.c) 3 | add_definitions(-DMBED_CONF_MBED_TRACE_ENABLE=1) 4 | if (TARGET_GROUP STREQUAL test) 5 | add_definitions(-DBUILD_TYPE_TEST) 6 | endif () 7 | 8 | add_library (rpc ${SOURCES}) 9 | target_include_directories (rpc PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include) 10 | target_include_directories (rpc PUBLIC ${CMAKE_CURRENT_LIST_DIR}/../lib/jsonrpc) 11 | 12 | target_link_libraries(rpc jsonrpc) 13 | -------------------------------------------------------------------------------- /edge-tool/MANIFEST.in: -------------------------------------------------------------------------------- 1 | global-exclude *.py[cod] __pycache__ *.so 2 | include README.md 3 | include LICENSE 4 | include requirements.txt 5 | include *.py 6 | 7 | -------------------------------------------------------------------------------- /edge-tool/README.md: -------------------------------------------------------------------------------- 1 | # Edge tool 2 | 3 | It can also be used to convert the development certificate to CBOR configuration object. The development certificate is a C source file which can be downloaded from the [Device Management Portal](https://portal.mbedcloud.com). 4 | 5 | The generated CBOR file can be given to Edge Core as command line argument when Edge Core is built with `BYOC_MODE`. 6 | 7 | ## Pre-requisites 8 | 9 | Python version 3.6 or newer with SSL support. 10 | 11 | The Edge tool depends on 12 | * [CBOR2](https://pypi.org/project/cbor2) 13 | * [PyCLibrary](https://pypi.org/project/pyclibrary) 14 | * [Cryptography](https://pypi.org/project/cryptography/) 15 | 16 | ## Install 17 | 18 | ``` 19 | virtualenv edge-tool 20 | source ./edge-tool/bin/activate 21 | python3 setup.py install 22 | ``` 23 | 24 | Please note that Yocto-builds work differently, they do not follow the `requirements.txt`. The Yocto builds bring in the Python-modules via recipes (version specific). 25 | 26 | ## Run tests 27 | 28 | You can run the tests simply with `pytest``. 29 | ``` 30 | pytest -v 31 | ``` 32 | 33 | ### How to run 34 | 35 | The entry point for Edge tool is [edge_tool.py](./edge_tool.py). 36 | 37 | ``` 38 | $ ./edge_tool.py -h 39 | ``` 40 | -------------------------------------------------------------------------------- /edge-tool/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PelionIoT/mbed-edge/6589c96c7731a6c2b34fe3278c755b8dbbdeb583/edge-tool/__init__.py -------------------------------------------------------------------------------- /edge-tool/edge_tool.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | # ---------------------------------------------------------------------------- 4 | # Copyright 2018 ARM Ltd. 5 | # Copyright (c) 2023 Izuma Networks 6 | # 7 | # SPDX-License-Identifier: Apache-2.0 8 | # 9 | # Licensed under the Apache License, Version 2.0 (the "License"); 10 | # you may not use this file except in compliance with the License. 11 | # You may obtain a copy of the License at 12 | # 13 | # http://www.apache.org/licenses/LICENSE-2.0 14 | # 15 | # Unless required by applicable law or agreed to in writing, software 16 | # distributed under the License is distributed on an "AS IS" BASIS, 17 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | # See the License for the specific language governing permissions and 19 | # limitations under the License. 20 | # ---------------------------------------------------------------------------- 21 | 22 | # noqa - E501 23 | """Convert developer certificates to CBOR for runtime injection. 24 | 25 | Usage: 26 | edge_tool.py convert-dev-cert (--development-certificate --cbor ) --update-resource 27 | edge_tool.py add-custom-cert --custom-cert --cbor 28 | edge_tool.py print-cbor --cbor 29 | edge_tool.py --help 30 | 31 | Options: 32 | --help Show this help. 33 | --development-certificate path> The path to Device Management development certificate C source file. 34 | --update-resource The path to `update_default_resources.c` source file. 35 | --cbor The CBOR output / input file path. 36 | --custom-cert The custom certificate name. 37 | """ 38 | 39 | import docopt 40 | 41 | from cbor_converter import CBORConverter, CBORUtils 42 | 43 | 44 | def main(): 45 | args = docopt.docopt(__doc__) 46 | if args["convert-dev-cert"]: 47 | converter = CBORConverter( 48 | args["--development-certificate"], 49 | args["--update-resource"], 50 | args["--cbor"], 51 | ) 52 | converter.convert_to_cbor() 53 | if args["add-custom-cert"]: 54 | CBORUtils.add_custom_certificate(args["--cbor"], args["--custom-cert"]) 55 | if args["print-cbor"]: 56 | CBORUtils.print_cbor(args["--cbor"]) 57 | 58 | 59 | if __name__ == "__main__": 60 | main() 61 | -------------------------------------------------------------------------------- /edge-tool/requirements.txt: -------------------------------------------------------------------------------- 1 | docopt==0.6.2 2 | cbor2==5.4.6 3 | pyclibrary==0.2.1 4 | cryptography==44.0.0 5 | six==1.16.0 6 | pytest==7.1.3 7 | -------------------------------------------------------------------------------- /edge-tool/setup.py: -------------------------------------------------------------------------------- 1 | # ---------------------------------------------------------------------------- 2 | # Copyright 2021 ARM Ltd. 3 | # Copyright (c) 2023 Izuma Networks 4 | # 5 | # SPDX-License-Identifier: Apache-2.0 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # ---------------------------------------------------------------------------- 19 | 20 | """edge-tool - convert developer certificates to CBOR for runtime injection.""" 21 | 22 | 23 | import os 24 | 25 | from setuptools import setup, find_packages 26 | 27 | repository_dir = os.path.dirname(__file__) 28 | 29 | with open(os.path.join(repository_dir, "requirements.txt")) as fh: 30 | requirements = fh.readlines() 31 | 32 | setup( 33 | name="edge-tool", 34 | version="0.22.0", 35 | author="DM devops and sre", 36 | author_email="dmdevopsandsre@izumanetworks.com", 37 | packages=find_packages(), 38 | url="https://github.com/PelionIoT/mbed-edge/edge-tool", 39 | install_requires=requirements, 40 | python_requires=">=3.6, <3.10", 41 | license="Apache 2.0", 42 | description="Tool to convert the development certificates to " 43 | "CBOR formatted object", 44 | scripts=["edge_tool.py", "cbor_converter.py"], 45 | ) 46 | -------------------------------------------------------------------------------- /edge-tool/test_data/device.cbor: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PelionIoT/mbed-edge/6589c96c7731a6c2b34fe3278c755b8dbbdeb583/edge-tool/test_data/device.cbor -------------------------------------------------------------------------------- /edge-tool/tests/test_cbor.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # 3 | # Copyright (c) 2023 Izuma Networks 4 | # 5 | # SPDX-License-Identifier: Apache-2.0 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | 19 | """Pytest based tests for testing certificate conversion to CBOR.""" 20 | 21 | import os 22 | import filecmp 23 | 24 | 25 | def test_cbor_conversion(tmpdir): 26 | """Test conversion (success)""" 27 | tmp_outfile = str(tmpdir.join("out.cbor")) 28 | ret = os.system( 29 | "./edge_tool.py convert-dev-cert " 30 | "--development-certificate test_data/mbed_cloud_dev_credentials.c " 31 | " --update-resource test_data/update_default_resources.c " 32 | f"--cbor {tmp_outfile}" 33 | ) 34 | assert ret == 0 35 | assert filecmp.cmp(tmp_outfile, "test_data/device.cbor", shallow=False) 36 | 37 | 38 | def test_cbor_print(tmpdir): 39 | """Test CBOR printing (success)""" 40 | tmp_outfile = str(tmpdir.join("out.txt")) 41 | ret = os.system( 42 | f"./edge_tool.py print-cbor " 43 | f"--cbor test_data/device.cbor >{tmp_outfile}" 44 | ) 45 | assert ret == 0 46 | assert filecmp.cmp(tmp_outfile, "test_data/device.cbor.txt", shallow=False) 47 | -------------------------------------------------------------------------------- /fota/COMP_1/fota_update_activate.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -euxo pipefail 3 | 4 | # Parse command line 5 | # 6 | # FIRMWARE 7 | 8 | FIRMWARE=${1?candidate file name is missing.} 9 | 10 | echo "Got firmware at $FIRMWARE" 11 | 12 | # Perform firmware update 13 | # exit 0 -> Success, anything else is failure 14 | exit 0 -------------------------------------------------------------------------------- /fota/COMP_1/fota_update_verify.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -euxo pipefail 3 | 4 | echo "Verfiying firmware update" 5 | # Perform firmware update verification 6 | echo "Success" 7 | 8 | # exit 0 -> Success, anything else is failure 9 | exit 0 -------------------------------------------------------------------------------- /fota/MAIN/fota_update_activate.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -euxo pipefail 3 | 4 | # Parse command line 5 | # 6 | # FIRMWARE 7 | 8 | FIRMWARE=${1?candidate file name is missing.} 9 | 10 | echo "Got firmware at $FIRMWARE" 11 | 12 | # Perform firmware update 13 | # exit 0 -> Success, anything else is failure 14 | exit 0 -------------------------------------------------------------------------------- /include/common/constants.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ---------------------------------------------------------------------------- 3 | * Copyright 2018 ARM Ltd. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * ---------------------------------------------------------------------------- 19 | */ 20 | 21 | #ifndef INCLUDE_COMMON_CONSTANTS_H_ 22 | #define INCLUDE_COMMON_CONSTANTS_H_ 23 | 24 | /** 25 | * \defgroup EDGE_CONSTANTS Common constants used in Edge Core. 26 | * @{ 27 | */ 28 | 29 | /** 30 | * \file constants.h 31 | * \brief Common constants used in Edge Core. 32 | */ 33 | 34 | /*! *\brief Read operation bitmask for a resource. */ 35 | #define OPERATION_READ 0x01 36 | /*! \brief Write operation bitmask for a resource. */ 37 | #define OPERATION_WRITE 0x02 38 | /*! \brief Combined read and write operation bitmask for a resource. */ 39 | #define OPERATION_READ_WRITE OPERATION_READ | OPERATION_WRITE 40 | /*! \brief Execution operation bitmask for a resource. */ 41 | #define OPERATION_EXECUTE 0x04 42 | /*! \brief Delete operation bitmask for a resource. */ 43 | #define OPERATION_DELETE 0x08 44 | 45 | /** 46 | * \brief LwM2M resource type enumeration constants. 47 | */ 48 | typedef enum { 49 | LWM2M_STRING, 50 | LWM2M_INTEGER, 51 | LWM2M_FLOAT, 52 | LWM2M_BOOLEAN, 53 | LWM2M_OPAQUE, 54 | LWM2M_TIME, 55 | LWM2M_OBJLINK 56 | } Lwm2mResourceType; 57 | 58 | /** 59 | * @} 60 | * Close EDGE_CONSTANTS Doxygen group definition 61 | */ 62 | 63 | #endif /* INCLUDE_COMMON_CONSTANTS_H_ */ 64 | -------------------------------------------------------------------------------- /include/common/default_message_id_generator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ---------------------------------------------------------------------------- 3 | * Copyright 2018 ARM Ltd. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * ---------------------------------------------------------------------------- 19 | */ 20 | 21 | #ifndef EDGE_DEFAULT_MESSAGE_ID_GENERATOR_H 22 | #define EDGE_DEFAULT_MESSAGE_ID_GENERATOR_H 23 | 24 | /** 25 | * \defgroup EDGE_DEFAULT_MESSAGE_ID_GENERATOR_LIB Default message id generator library 26 | * @{ 27 | */ 28 | 29 | /** 30 | * \file default_message_id_generator.h 31 | * \brief Default message ID generator for JSON-RPC messages. 32 | */ 33 | 34 | /** 35 | * \brief A prototype of the ID generation function. 36 | * 37 | * The function must provide unique and non-clashing IDs for the session. 38 | * 39 | * \return A unique message ID. 40 | */ 41 | typedef char *(*generate_msg_id)(); 42 | 43 | /** 44 | * \brief Default message generation function. 45 | * 46 | * This function implements a default message generator function. The prototype definition 47 | * of the function is `::generate_msg_id`. 48 | * 49 | * \return Numeric ascending message IDs are generated and returned as a character array.\n 50 | * The character array is NULL terminated.\n 51 | * If the allocation fails, NULL is returned. 52 | */ 53 | char *edge_default_generate_msg_id(); 54 | 55 | /** 56 | * @} 57 | * close EDGE_DEFAULT_MESSAGE_ID_GENERATOR_LIB Doxygen group definition 58 | */ 59 | 60 | #endif /* EDGE_DEFAULT_MESSAGE_ID_GENERATOR_H */ 61 | -------------------------------------------------------------------------------- /include/common/edge_time.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ---------------------------------------------------------------------------- 3 | * Copyright 2018 ARM Ltd. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * ---------------------------------------------------------------------------- 19 | */ 20 | 21 | #ifndef EDGE_TIME_H 22 | #define EDGE_TIME_H 23 | 24 | #include 25 | #include 26 | 27 | /** 28 | * \defgroup EDGE_TIME Edge time API. 29 | * @{ 30 | */ 31 | 32 | /** \file edge_time.h 33 | * \brief Edge time API 34 | * 35 | * Utility functions for getting time. 36 | */ 37 | 38 | /** 39 | * \brief Get current milliseconds. 40 | * Uses CLOCK_MONOTONIC as source from POSIX.1-2001, POSIX.1-2008, SUSv2 compliant system. 41 | * If _POSIX_MONOTONIC_CLOCK is not defined the function returns 0. 42 | * \return current milliseconds as uint64_t or 0 if clock source is not available. 43 | */ 44 | uint64_t edgetime_get_monotonic_in_ms(); 45 | 46 | /** 47 | * \brief Get the real time in seconds and nanoseconds. 48 | * Uses CLOCK_REAL as source. 49 | * \return true if the system call succeeded. 50 | * false if the system call failed and sets seconds and ns to 0. 51 | */ 52 | bool edgetime_get_real_in_ns(uint64_t *seconds, uint64_t *ns); 53 | 54 | /** 55 | * @} 56 | * Close EDGE_TIME Doxygen group definition 57 | */ 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /include/common/edge_trace.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ---------------------------------------------------------------------------- 3 | * Copyright 2018 ARM Ltd. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * ---------------------------------------------------------------------------- 19 | */ 20 | #ifndef EDGE_TRACE_API_H 21 | #define EDGE_TRACE_API_H 22 | 23 | #include "common/edge_mutex.h" 24 | 25 | /** 26 | * \defgroup EDGE_TRACE Edge trace API. 27 | * @{ 28 | */ 29 | 30 | /** \file edge_trace.h 31 | * \brief Edge trace API 32 | * 33 | * Utility functions for the Edge tracing functionality. 34 | */ 35 | 36 | /** 37 | * \brief The function may be used to initialize the Edge Trace API. 38 | * \param color_mode Set to true if ANSI color coded logging is needed. By setting false the plain text log is written. 39 | */ 40 | void edge_trace_init(int color_mode); 41 | 42 | /** 43 | * \brief The function destroys the Edge Trace API and frees the related resources. 44 | */ 45 | void edge_trace_destroy(); 46 | 47 | #ifdef BUILD_TYPE_TEST 48 | /** 49 | * \brief The static char buffer used for storing the timestamp prefix for the mbed-trace logger. 50 | */ 51 | extern char *timestamp_prefix; 52 | 53 | /** 54 | * Mutex needed for serializing traces from different threads. 55 | */ 56 | extern edge_mutex_t trace_mutex; 57 | 58 | /** 59 | * \brief The function to create timestamp prefixes for mbed-trace. 60 | * 61 | * \param size The length of the message body. 62 | * \return A pointer to timestamp prefix string. 63 | */ 64 | char *edge_trace_prefix(size_t size); 65 | #endif 66 | 67 | /** 68 | * @} 69 | * Close EDGE_TRACE Doxygen group definition 70 | */ 71 | 72 | #endif 73 | -------------------------------------------------------------------------------- /include/common/integer_length.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ---------------------------------------------------------------------------- 3 | * Copyright 2018 ARM Ltd. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * ---------------------------------------------------------------------------- 19 | */ 20 | 21 | #ifndef EDGE_INTEGER_LENGTH_H 22 | #define EDGE_INTEGER_LENGTH_H 23 | 24 | #include 25 | 26 | /** 27 | * \defgroup EDGE_INTEGER_LENGTH_LIB Integer length calculator 28 | * @{ 29 | */ 30 | 31 | /** \file integer_length.h 32 | * \brief Edge common integer handling functions. 33 | */ 34 | 35 | /** 36 | * \brief Return the length of the integer in characters. 37 | * This function calculates the needed space of characters to represent 38 | * the integer argument. 39 | * 40 | * \param value The value to calculate the length as a characters. 41 | * \return The length as characters. 42 | */ 43 | uint16_t edge_int_length(uint32_t value); 44 | 45 | /** 46 | * \brief Convert the string to uin16_t. 47 | * 48 | * \param str String to convert. String must be NUL-terminated. 49 | * \param result The pointer where to store the result. 50 | * \return 0 if conversion succeeded.\n 51 | 1 if an error occurred when converting str to uint16_t. 52 | */ 53 | int edge_str_to_uint16_t(const char *str, uint16_t *result); 54 | 55 | /** 56 | * @} 57 | * close EDGE_INTEGER_LENGTH_LIB Doxygen group definition 58 | */ 59 | 60 | #endif /* EDGE_INTEGER_LENGTH_GENERATOR_H */ 61 | -------------------------------------------------------------------------------- /include/edge-core/edge_server_customer_code.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ---------------------------------------------------------------------------- 3 | * Copyright 2018 ARM Ltd. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * ---------------------------------------------------------------------------- 19 | */ 20 | 21 | #ifndef EDGE_SERVER_CUSTOMER_CODE_H 22 | 23 | #include "edge-client/edge_client.h" 24 | 25 | /** 26 | * \defgroup EDGE_SERVER_CUSTOMER_CODE Edge Server Customer Code 27 | * \ingroup EDGE_SERVER_CUSTOMER_CODE 28 | * @{ 29 | */ 30 | 31 | /** \file edge_server_customer_code.h 32 | * \brief Edge server customer code 33 | * 34 | * This file contains hooks for a customer implementation. For example, when factory reset is called from Device Management, 35 | * `edgeserver_execute_rfs_customer_code` is called.\n 36 | * The customers may implement their own implementation for reset factory settings.\n 37 | * This function should always return within a reasonable time, ideally within a few seconds.\n 38 | * If the settings are reset successfully the Edge server will gracefully shutdown to be restarted. 39 | */ 40 | 41 | /** 42 | * \brief Called when reset factory settings is requested from Cloud. 43 | * 44 | * \param request_ctx Information about this request. 45 | * \return True if reset factory settings was successful.\n 46 | * False if reset failed. 47 | */ 48 | bool edgeserver_execute_rfs_customer_code(edgeclient_request_context_t *request_ctx); 49 | 50 | /** 51 | * @} 52 | * Close EDGE_SERVER_CUSTOMER_CODE Doxygen group definition 53 | */ 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /lib/jansson/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set (JANSSON_EXAMPLES OFF CACHE BOOL "Disable example from jansson.") 2 | set (JANSSON_BUILD_DOCS OFF CACHE BOOL "Disable documentation generation for jansson.") 3 | set (JANSSON_WITHOUT_TESTS ON CACHE BOOL "Disable tests from jansson.") 4 | set (JANSSON_INSTALL OFF CACHE BOOL "Disable install target from jansson.") 5 | add_subdirectory (jansson) 6 | -------------------------------------------------------------------------------- /lib/jsonrpc/LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 pijyoi 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /lib/libevent/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Workaround for: https://github.com/libevent/libevent/issues/482 2 | # Applies for CMake build for libevent 2.1.8-stable 3 | # Fixing commit: https://github.com/libevent/libevent/commit/66a4eb0c3ae3b1f22b084b2d3aeb5c872f37efbd 4 | set(EVENT__HAVE_WAITPID_WITH_WNOWAIT_EXITCODE 1) 5 | set(EVENT__HAVE_WAITPID_WITH_WNOWAIT_EXITCODE__TRYRUN_OUTPUT "") 6 | set (EVENT__DISABLE_DEBUG_MODE ON CACHE BOOL "Disable libevent debug mode.") 7 | set (EVENT__DISABLE_TESTS ON CACHE BOOL "Disable libevent tests.") 8 | set (EVENT__DISABLE_REGRESS ON CACHE BOOL "Disable libevent regression tests.") 9 | set (EVENT__DISABLE_SAMPLES ON CACHE BOOL "Disable libevent samples.") 10 | set (EVENT__DISABLE_OPENSSL ON CACHE BOOL "Disable OpenSSL support from libevent.") 11 | set (EVENT__DISABLE_BENCHMARK ON CACHE BOOL "Disable libevent bencmark executables.") 12 | 13 | add_subdirectory (libevent) 14 | -------------------------------------------------------------------------------- /lib/libwebsockets/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set (LWS_UNIX_SOCK ON CACHE BOOL "Device Management Edge communicates with domain sockets") 2 | set (LWS_WITH_SSL OFF CACHE BOOL "No SSL needed with domain sockets.") 3 | set (LWS_WITH_LIBEVENT ON CACHE BOOL "Libevent is selected as event loop.") 4 | set (LWS_WITH_SHARED OFF CACHE BOOL "No need for shared libraries, link it in.") 5 | set (LWS_WITH_SSL OFF CACHE BOOL "Disable ssl to help debugging") 6 | set (LWS_WITHOUT_TESTAPPS ON CACHE BOOL "Disable tests from libwebsockets.") 7 | set (LWS_WITHOUT_TEST_SERVER ON CACHE BOOL "Disable tests from libwebsockets.") 8 | set (LWS_WITHOUT_TEST_SERVER_EXT_POLL ON CACHE BOOL "Disable tests from libwebsockets.") 9 | set (LWS_WITHOUT_TEST_PING ON CACHE BOOL "Disable tests from libwebsockets.") 10 | set (LWS_WITHOUT_TEST_ECHO ON CACHE BOOL "Disable tests from libwebsockets.") 11 | set (LWS_WITHOUT_TEST_CLIENT ON CACHE BOOL "Disable tests from libwebsockets.") 12 | set (LWS_WITHOUT_TEST_FRAGGLE ON CACHE BOOL "Disable tests from libwebsockets.") 13 | add_subdirectory(libwebsockets) 14 | -------------------------------------------------------------------------------- /lib/pal-platform/Middleware/curl/.gitignore: -------------------------------------------------------------------------------- 1 | curl/ 2 | -------------------------------------------------------------------------------- /lib/pal-platform/Middleware/curl/curl.cmake: -------------------------------------------------------------------------------- 1 | ################################################################################# 2 | # Copyright 2022 Izuma Networks 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ################################################################################# 16 | 17 | if (NOT MBED_CLOUD_CLIENT_CURL_DYNAMIC_LINK) 18 | set (CURL_USE_OPENSSL OFF CACHE BOOL "disable openssl" FORCE) 19 | set (BUILD_TESTING OFF CACHE BOOL "disable testing" FORCE) 20 | set (BUILD_CURL_EXE OFF CACHE BOOL "don't build exe" FORCE) 21 | set (BUILD_SHARED_LIBS OFF CACHE BOOL "don't build share libs" FORCE) 22 | set (ENABLE_INET_PTON OFF CACHE BOOL "disable INET option" FORCE) 23 | set (CURL_ZLIB OFF CACHE BOOL "disable zlib" FORCE) 24 | set (HTTP_ONLY ON CACHE BOOL "set http only mode" FORCE) 25 | set (CURL_USE_LIBSSH2 OFF CACHE BOOL "disable ssh2" FORCE) 26 | set (CURL_DISABLE_CRYPTO_AUTH ON CACHE BOOL "disable crypto" FORCE) 27 | set (ENABLE_IPV6 OFF CACHE BOOL "disable ipv6" FORCE) 28 | set (CURL_DISABLE_MQTT ON CACHE BOOL "disable MQTT" FORCE) 29 | set (CURL_DISABLE_VERBOSE_STRINGS ON CACHE BOOL "disable verbose" FORCE) 30 | 31 | set (EXTRA_CMAKE_DIRS ${EXTRA_CMAKE_DIRS} "${CMAKE_SOURCE_DIR}/pal-platform/Middleware/curl/curl") 32 | endif() 33 | -------------------------------------------------------------------------------- /lib/pal-platform/Middleware/parsec_se_driver/.gitignore: -------------------------------------------------------------------------------- 1 | parsec_se_driver/ 2 | -------------------------------------------------------------------------------- /lib/pal-platform/Middleware/parsec_se_driver/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ################################################################################# 2 | # Copyright 2020 ARM Ltd. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ################################################################################# 16 | 17 | set(BUILD_CMD cargo build) 18 | set(WORKING_DIR "${CMAKE_CURRENT_SOURCE_DIR}/parsec_se_driver") 19 | set(ENV{MBEDTLS_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/../mbedtls/mbedtls/include) 20 | 21 | message ("Setting env variable MBEDTLS_INCLUDE_DIR to $ENV{MBEDTLS_INCLUDE_DIR}") 22 | 23 | if(${CMAKE_BUILD_TYPE} MATCHES "Debug") 24 | message ("Building Debug parsec_se_driver in ${WORKING_DIR} with ${BUILD_CMD}") 25 | execute_process( COMMAND ${BUILD_CMD} 26 | RESULT_VARIABLE CMD_ERROR 27 | WORKING_DIRECTORY ${WORKING_DIR} ) 28 | else() 29 | message ("Building Release parsec_se_driver in ${WORKING_DIR} with ${BUILD_CMD} --release") 30 | execute_process( COMMAND ${BUILD_CMD} --release 31 | RESULT_VARIABLE CMD_ERROR 32 | WORKING_DIRECTORY ${WORKING_DIR} ) 33 | endif() 34 | 35 | if(NOT ${CMD_ERROR} MATCHES "0") 36 | MESSAGE(SEND_ERROR "BUILD_CMD STATUS:" ${CMD_ERROR}) 37 | endif() 38 | 39 | -------------------------------------------------------------------------------- /lib/pal-platform/Middleware/parsec_se_driver/parsec_se_driver.cmake: -------------------------------------------------------------------------------- 1 | ################################################################################# 2 | # Copyright 2020 ARM Ltd. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ################################################################################# 16 | 17 | if(PARSEC_TPM_SE_SUPPORT) 18 | # include parsec building cmake 19 | set (EXTRA_CMAKE_DIRS ${EXTRA_CMAKE_DIRS} "${CMAKE_SOURCE_DIR}/pal-platform/Middleware/parsec_se_driver") 20 | endif() 21 | -------------------------------------------------------------------------------- /lib/pal-platform/Middleware/trusted_storage/.gitignore: -------------------------------------------------------------------------------- 1 | trusted_storage/ 2 | -------------------------------------------------------------------------------- /lib/pal-platform/Middleware/trusted_storage/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ################################################################################# 2 | # Copyright 2016 - 2019 ARM Ltd. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ################################################################################# 16 | 17 | FILE( 18 | GLOB_RECURSE 19 | trusted_storage 20 | 21 | "${CMAKE_CURRENT_SOURCE_DIR}/trusted_storage/lib/*.c" 22 | ) 23 | 24 | message ("*********************************************************************") 25 | message ("trusted_storage = [[${trusted_storage}]]") 26 | message ("*********************************************************************") 27 | 28 | add_library(trusted_storage STATIC "${trusted_storage}") 29 | -------------------------------------------------------------------------------- /lib/pal-platform/Middleware/trusted_storage/trusted_storage.cmake: -------------------------------------------------------------------------------- 1 | ################################################################################# 2 | # Copyright 2016 - 2019 ARM Ltd. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ################################################################################# 16 | 17 | include_directories (BEFORE "${CMAKE_SOURCE_DIR}/pal-platform/Middleware/trusted_storage") 18 | include_directories (BEFORE "${CMAKE_SOURCE_DIR}/pal-platform/Middleware/trusted_storage/trusted_storage/inc") 19 | 20 | set (EXTRA_CMAKE_DIRS ${EXTRA_CMAKE_DIRS} "${CMAKE_SOURCE_DIR}/pal-platform/Middleware/trusted_storage") 21 | 22 | list (APPEND SRC_LIBS trusted_storage) 23 | -------------------------------------------------------------------------------- /lib/pal-platform/OS/Linux_Native/Linux_Native.cmake: -------------------------------------------------------------------------------- 1 | ################################################################################# 2 | # Copyright 2016-2020 ARM Ltd. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ################################################################################# 16 | 17 | # Note: This Linux target configuration is designed for a desktop linux process execution. 18 | # This is for development use only. 19 | 20 | set (OS_BRAND Linux) 21 | SET(TARGET_NAME TARGET_X86_X64) 22 | 23 | cmake_policy(SET CMP0003 NEW) 24 | cmake_policy(SET CMP0011 OLD) 25 | 26 | add_definitions(-DTARGET_IS_PC_LINUX) 27 | add_definitions(-D__LINUX__) 28 | 29 | # This flag indicates a simulation mode which will also enable PAL_SIMULATOR_TEST_ENABLE implicitly. 30 | add_definitions(-DTARGET_X86_X64) 31 | 32 | option(STORAGE_ESFS "Enable ESFS" ON) 33 | 34 | -------------------------------------------------------------------------------- /lib/pal-platform/OS/Linux_OpenWRT/Linux_OpenWRT.cmake: -------------------------------------------------------------------------------- 1 | ################################################################################# 2 | # Copyright 2016-2020 ARM Ltd. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ################################################################################# 16 | 17 | set (OS_BRAND Linux) 18 | 19 | cmake_policy(SET CMP0003 NEW) 20 | cmake_policy(SET CMP0011 OLD) 21 | 22 | add_definitions(-DTARGET_IS_PC_LINUX) 23 | add_definitions(-D__LINUX__) 24 | 25 | option(STORAGE_ESFS "Enable ESFS" ON) 26 | -------------------------------------------------------------------------------- /lib/pal-platform/OS/Linux_Raspbian/Linux_Raspbian.cmake: -------------------------------------------------------------------------------- 1 | ################################################################################# 2 | # Copyright 2020 ARM Ltd. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ################################################################################# 16 | 17 | set (OS_BRAND Linux) 18 | add_definitions(-DTARGET_IS_PC_LINUX) 19 | add_definitions(-D__LINUX__) 20 | add_definitions(-D__RASPBIAN__) 21 | 22 | option(STORAGE_ESFS "Enable ESFS" ON) 23 | -------------------------------------------------------------------------------- /lib/pal-platform/OS/Linux_Yocto_v2.2/Linux_Yocto_v2.2.cmake: -------------------------------------------------------------------------------- 1 | ################################################################################# 2 | # Copyright 2016-2020 ARM Ltd. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ################################################################################# 16 | 17 | set (OS_BRAND Linux) 18 | 19 | cmake_policy(SET CMP0003 NEW) 20 | cmake_policy(SET CMP0011 OLD) 21 | 22 | add_definitions(-DTARGET_IS_PC_LINUX) 23 | add_definitions(-D__LINUX__) 24 | 25 | option(STORAGE_ESFS "Enable ESFS" ON) 26 | -------------------------------------------------------------------------------- /lib/pal-platform/OS/NXP/NXP.cmake: -------------------------------------------------------------------------------- 1 | ################################################################################# 2 | # Copyright 2016-2020 ARM Ltd. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ################################################################################# 16 | 17 | set (OS_BRAND NXP) 18 | add_definitions(-D__NXP__) 19 | 20 | cmake_policy(SET CMP0003 NEW) 21 | cmake_policy(SET CMP0011 OLD) 22 | -------------------------------------------------------------------------------- /lib/pal-platform/Toolchain/ARMCC/ARMCC-ASM.cmake: -------------------------------------------------------------------------------- 1 | ################################################################################# 2 | # Copyright 2016, 2017 ARM Ltd. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ################################################################################# 16 | 17 | set(CMAKE_ASM_OUTPUT_EXTENSION ".o") 18 | 19 | -------------------------------------------------------------------------------- /lib/pal-platform/Toolchain/ARMCC/ARMCC-C.cmake: -------------------------------------------------------------------------------- 1 | ################################################################################# 2 | # Copyright 2016, 2017 ARM Ltd. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ################################################################################# 16 | 17 | set(CMAKE_C_OUTPUT_EXTENSION ".o") 18 | set(CMAKE_DEPFILE_FLAGS_C "--depend-target= --depend= --depend_single_line --no_depend_system_headers") 19 | -------------------------------------------------------------------------------- /lib/pal-platform/Toolchain/ARMCC/ARMCC-CXX.cmake: -------------------------------------------------------------------------------- 1 | ################################################################################# 2 | # Copyright 2016, 2017 ARM Ltd. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ################################################################################# 16 | 17 | set(CMAKE_CXX_OUTPUT_EXTENSION ".o") 18 | set(CMAKE_DEPFILE_FLAGS_CXX "--depend-target= --depend= --depend_single_line --no_depend_system_headers") 19 | -------------------------------------------------------------------------------- /lib/pal-platform/Toolchain/POKY-GLIBC/POKY-GLIBC-flags.cmake: -------------------------------------------------------------------------------- 1 | 2 | ################################################################################# 3 | # Copyright 2016, 2017 ARM Ltd. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | ################################################################################# 17 | 18 | 19 | 20 | macro(SET_COMPILER_DBG_RLZ_FLAG flag value) 21 | SET(${flag}_DEBUG "${${flag}_DEBUG} ${value}") 22 | SET(${flag}_RELEASE "${${flag}_RELEASE} ${value}") 23 | #enable this if for debugging 24 | if (0) 25 | message("flag = ${flag}") 26 | message("value = ${value}") 27 | message("MY_C_FLAGS_RELEASE2 = ${CMAKE_C_FLAGS_RELEASE}") 28 | endif(0) # comment end 29 | endmacro(SET_COMPILER_DBG_RLZ_FLAG) 30 | 31 | 32 | SET_COMPILER_DBG_RLZ_FLAG (CMAKE_C_FLAGS "@${CMAKE_SOURCE_DIR}/include_file.txt") 33 | SET_COMPILER_DBG_RLZ_FLAG (CMAKE_CXX_FLAGS "@${CMAKE_SOURCE_DIR}/include_file.txt") 34 | -------------------------------------------------------------------------------- /lib/pal-platform/requirements.txt: -------------------------------------------------------------------------------- 1 | click>=6.5,<7.2 2 | requests>=2.1,<2.21 3 | intelhex>=2,<3 4 | imgtool>=1,<2 5 | -------------------------------------------------------------------------------- /lib/platform/secure_element/mcc_se_init.c: -------------------------------------------------------------------------------- 1 | // ---------------------------------------------------------------------------- 2 | // Copyright 2019-2020 ARM Ltd. 3 | // 4 | // SPDX-License-Identifier: Apache-2.0 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // ---------------------------------------------------------------------------- 18 | #ifdef MBED_CONF_MBED_CLOUD_CLIENT_SECURE_ELEMENT_SUPPORT 19 | #include "mcc_se_init.h" 20 | #include "mbed-trace/mbed_trace.h" 21 | #ifdef MBED_CONF_APP_SECURE_ELEMENT_ATCA_SUPPORT 22 | #include "mcc_atca_credentials_init.h" 23 | #endif 24 | #define TRACE_GROUP "secm" 25 | 26 | 27 | /******************************************************************************* 28 | * Code 29 | ******************************************************************************/ 30 | 31 | int mcc_se_init(void) 32 | { 33 | int res = 0; 34 | 35 | #ifdef MBED_CONF_APP_SECURE_ELEMENT_ATCA_SUPPORT 36 | /*The function decompresses SE device certificate chain and stores is to the device storage.*/ 37 | res = mcc_atca_credentials_init(); 38 | if (res != 0) { 39 | tr_error("mcc_atca_credentials_init failed"); 40 | } 41 | #endif 42 | 43 | return res; 44 | } 45 | #endif // MBED_CONF_MBED_CLOUD_CLIENT_SECURE_ELEMENT_SUPPORT 46 | -------------------------------------------------------------------------------- /lib/platform/secure_element/se_configs/se_data_user_config.h: -------------------------------------------------------------------------------- 1 | // ---------------------------------------------------------------------------- 2 | // Copyright 2019-2020 ARM Ltd. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ---------------------------------------------------------------------------- 16 | #ifndef __SE_DATA_USER_CONFIG_H__ 17 | #define __SE_DATA_USER_CONFIG_H__ 18 | 19 | #ifdef MBED_CONF_MBED_CLOUD_CLIENT_SECURE_ELEMENT_SUPPORT 20 | #include "fcc_defs.h" 21 | #include "se_slot_manager_defs.h" 22 | #include 23 | #include 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | 30 | #ifndef MBED_CONF_MBED_CLOUD_CLIENT_NON_PROVISIONED_SECURE_ELEMENT 31 | /*This file defines the number of Secure Element pre provisioned items and their information like kcm type, name and SE slot number. 32 | The item's information stored to the device during storage initialization */ 33 | 34 | #define SE_DATA_NUMBER_OF_PREPROVISIONED_ITEMS 1 //Total number of SE preprovisioned slots 35 | 36 | sem_preprovisioned_item_data_s g_sem_preprovisioned_data[SE_DATA_NUMBER_OF_PREPROVISIONED_ITEMS] = { 37 | {//KCM type,KCM item name, SE slot number 38 | .kcm_item_type = KCM_PRIVATE_KEY_ITEM, 39 | .kcm_item_name = g_fcc_bootstrap_device_private_key_name, 40 | .se_slot_num = 0 41 | } 42 | }; 43 | #endif 44 | 45 | #ifdef __cplusplus 46 | } 47 | #endif 48 | #endif //MBED_CONF_MBED_CLOUD_CLIENT_SECURE_ELEMENT_SUPPORT 49 | #endif //__SE_DATA_USER_CONFIG_H__ 50 | -------------------------------------------------------------------------------- /lib/platform/secure_element/se_configs/se_driver_config.h: -------------------------------------------------------------------------------- 1 | // ---------------------------------------------------------------------------- 2 | // Copyright 2019-2020 ARM Ltd. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ---------------------------------------------------------------------------- 16 | #ifndef __SE_DRIVER_CONFIG_H__ 17 | #define __SE_DRIVER_CONFIG_H__ 18 | 19 | #ifdef MBED_CONF_MBED_CLOUD_CLIENT_SECURE_ELEMENT_SUPPORT 20 | #ifdef MBED_CONF_APP_SECURE_ELEMENT_ATCA_SUPPORT 21 | #include "atecc608a_se.h" 22 | #endif 23 | 24 | #ifdef MBED_CONF_APP_SECURE_ELEMENT_PARSEC_TPM_SUPPORT 25 | #include "parsec_se_driver.h" 26 | #endif 27 | 28 | 29 | #include 30 | #include 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | #define PSA_DRIVER_SE_DRIVER_LOCATION_VALUE 0x000001 37 | /*SE driver lifetime value*/ 38 | #define PSA_DRIVER_SE_DRIVER_LIFETIME_VALUE PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION(PSA_KEY_PERSISTENCE_DEFAULT, PSA_DRIVER_SE_DRIVER_LOCATION_VALUE) 39 | 40 | /*This file defines SE driver lifetime and psa driver methods.*/ 41 | 42 | #ifdef MBED_CONF_APP_SECURE_ELEMENT_ATCA_SUPPORT 43 | /*SE driver lifetime value*/ 44 | #define PSA_DRIVER_SE_DRIVER_LIFETIME_VALUE PSA_ATECC608A_LIFETIME 45 | /*SE driver methods*/ 46 | psa_drv_se_t *g_se_driver_info = &atecc608a_drv_info; 47 | #endif 48 | 49 | #ifdef MBED_CONF_APP_SECURE_ELEMENT_PARSEC_TPM_SUPPORT 50 | /*SE driver lifetime value*/ 51 | /*SE driver methods*/ 52 | psa_drv_se_t *g_se_driver_info = &PARSEC_SE_DRIVER; 53 | #endif 54 | 55 | #ifdef __cplusplus 56 | } 57 | #endif 58 | #endif //#ifdef MBED_CONF_APP_SECURE_ELEMENT_SUPPORT 59 | #endif //__SE_DRIVER_CONFIG_H__ 60 | -------------------------------------------------------------------------------- /mbed-trace-edge/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This is needed because mbedTrace in mbed-cloud-client doesn't depend on nanostack. 2 | # And that's because nanostack does not use CMake. 3 | 4 | file (GLOB SOURCES ../lib/mbed-cloud-client/mbed-trace/source/*.c) 5 | add_library(mbedTraceEdge ${SOURCES}) 6 | 7 | target_link_libraries(mbedTraceEdge nanostack) 8 | -------------------------------------------------------------------------------- /nano-stack/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file (GLOB SOURCES ../lib/mbed-cloud-client/nanostack-libservice/source/libList/*.c) 2 | file (GLOB BIT_SOURCES ../lib/mbed-cloud-client/nanostack-libservice/source/libBits/*.c) 3 | file (GLOB STRING_SOURCES ../lib/mbed-cloud-client/nanostack-libservice/source/libip6string/*.c) 4 | 5 | list (APPEND SOURCES ${BIT_SOURCES}) 6 | list (APPEND SOURCES ${STRING_SOURCES}) 7 | 8 | add_library (nanostack STATIC ${SOURCES}) 9 | -------------------------------------------------------------------------------- /pt-client-2/pt-client-2/pt_certificate_api_internal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ---------------------------------------------------------------------------- 3 | * Copyright 2019 ARM Ltd. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * ---------------------------------------------------------------------------- 19 | */ 20 | 21 | #ifndef PT_CERTIFICATE_API_INTERNAL_H 22 | #define PT_CERTIFICATE_API_INTERNAL_H 23 | 24 | typedef struct pt_device_cert_renewal_context_s { 25 | char *device_id; 26 | char *cert_name; 27 | char *request_id; 28 | void *userdata; 29 | } pt_device_cert_renewal_context_t; 30 | 31 | pt_status_t pt_device_init_certificate_renewal_resources(connection_id_t connection_id, const char *device_id); 32 | 33 | #ifdef BUILD_TYPE_TEST 34 | 35 | void pt_device_cert_renewal_context_free(pt_device_cert_renewal_context_t *ctx); 36 | pt_status_t pt_device_certificate_renew_resource_callback(const connection_id_t connection_id, 37 | const char *device_id, 38 | const uint16_t object_id, 39 | const uint16_t object_instance_id, 40 | const uint16_t resource_id, 41 | const uint8_t operation, 42 | const uint8_t *value, 43 | const uint32_t size, 44 | void *userdata); 45 | 46 | #endif // BUILD_TYPE_TEST 47 | 48 | #endif // PT_CERTIFICATE_API_INTERNAL_H 49 | -------------------------------------------------------------------------------- /pt-client-2/pt-client-2/pt_common_api_internal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ---------------------------------------------------------------------------- 3 | * Copyright 2018 ARM Ltd. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * ---------------------------------------------------------------------------- 19 | */ 20 | 21 | #ifndef PT_COMMON_API_INTERNAL_H 22 | #define PT_COMMON_API_INTERNAL_H 23 | 24 | #include "pt-client-2/pt_common_api.h" 25 | 26 | typedef struct pt_resource pt_resource_t; 27 | typedef struct pt_object_instance pt_object_instance_t; 28 | typedef struct pt_object pt_object_t; 29 | typedef struct pt_device pt_device_t; 30 | typedef struct pt_devices_data pt_devices_t; 31 | 32 | #endif // PT_COMMON_API_INTERNAL_H 33 | -------------------------------------------------------------------------------- /pt-client-2/pt-client-2/pt_crypto_api_internal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ---------------------------------------------------------------------------- 3 | * Copyright 2019 ARM Ltd. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * ---------------------------------------------------------------------------- 19 | */ 20 | 21 | #ifndef PT_CRYPTO_API_INTERNAL_H 22 | #define PT_CRYPTO_API_INTERNAL_H 23 | 24 | #include 25 | 26 | #ifdef BUILD_TYPE_TEST 27 | 28 | void pt_crypto_success_with_data(json_t *response, void *callback_data, const char *json_key); 29 | void pt_crypto_success(json_t *response, void *callback_data); 30 | void pt_handle_pt_crypto_get_public_key_success(json_t *response, void *callback_data); 31 | void pt_handle_pt_crypto_get_certificate_success(json_t *response, void *callback_data); 32 | void pt_handle_pt_crypto_get_item_failure(json_t *response, void *callback_data); 33 | 34 | #endif // BUILD_TYPE_TEST 35 | 36 | #endif // PT_CRYPTO_API_INTERNAL_H 37 | -------------------------------------------------------------------------------- /pt-client-2/pt-client-2/pt_subdev_config.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __PT_SUBDEV_CONFIG_H__ 3 | #define __PT_SUBDEV_CONFIG_H__ 4 | 5 | #define COMPONENT_NAME_STR "MAIN" 6 | #define VERSION_NAME_STR "0.0.0" 7 | #define MANIFEST_VENDOR_STR "SUBDEVICE-VENDOR" 8 | #define MANIFEST_VENDOR_STR_SIZE strlen(MANIFEST_VENDOR_STR) 9 | #define MANIFEST_CLASS_STR "SUBDEVICE--CLASS" 10 | #define MANIFEST_CLASS_STR_SIZE strlen(MANIFEST_CLASS_STR) 11 | 12 | #endif // __PT_SUBDEV_CONFIG_H__ 13 | -------------------------------------------------------------------------------- /pt-client/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file (GLOB SOURCES 2 | ./*.c 3 | ../common/apr_base64.c 4 | ../common/default_message_id_generator.c 5 | ../common/edge_common.c 6 | ../common/integer_length.c 7 | ../common/pt_api_error_codes.c 8 | ../common/websocket_comm.c 9 | ) 10 | if (TARGET_GROUP STREQUAL test) 11 | add_definitions(-DBUILD_TYPE_TEST) 12 | else() 13 | list(APPEND SOURCES ../common/edge-mutex/edge_mutex.c) 14 | endif () 15 | 16 | include_directories (${CMAKE_CURRENT_LIST_DIR}/include) 17 | 18 | add_library (pt-client ${SOURCES}) 19 | 20 | add_definitions(-DMBED_CONF_MBED_TRACE_ENABLE=1) 21 | 22 | target_include_directories (pt-client PUBLIC ${CMAKE_CURRENT_LIST_DIR}) 23 | target_include_directories (pt-client PUBLIC ${CMAKE_CURRENT_LIST_DIR}/../lib/jsonrpc) 24 | target_include_directories (pt-client PUBLIC ${CMAKE_CURRENT_LIST_DIR}/../edge-rpc) 25 | SET (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -shared") 26 | 27 | if (TARGET_GROUP STREQUAL test) 28 | target_link_libraries (pt-client jansson rpc mbedTraceEdge) 29 | else () 30 | target_link_libraries (pt-client event jansson websockets rpc nanostack mbedTraceEdge) 31 | endif() 32 | -------------------------------------------------------------------------------- /start.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Enable core dumps 4 | ulimit -c unlimited 5 | mkdir -p /core 6 | echo "Core dumps enabled. Core files will be written to /core" 7 | 8 | # Path to the binary 9 | CMD="./build/bin/edge-core $@" 10 | 11 | echo "Starting: $CMD" 12 | 13 | # Run + monitor 14 | while true; do 15 | $CMD 16 | EXIT_CODE=$? 17 | echo "Process exited with code $EXIT_CODE" 18 | 19 | # If a core file was generated, print the stack trace 20 | CORE_FILE=$(ls /core/core.edge-core.* 2>/dev/null | tail -n 1) 21 | if [[ -f core ]]; then 22 | TIMESTAMP=$(date +%s) 23 | mv core "core.edge-core.${TIMESTAMP}" 24 | echo "==== Crash detected. Stack trace ====" 25 | gdb -batch -ex "thread apply all bt" -ex "quit" /usr/src/app/mbed-edge/build/bin/edge-core "core.edge-core.${TIMESTAMP}" 26 | fi 27 | 28 | echo "Restarting in 5s..." 29 | sleep 5 30 | done 31 | -------------------------------------------------------------------------------- /test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | enable_language(C) 2 | enable_language(CXX) 3 | 4 | if (TARGET_GROUP STREQUAL test) 5 | add_definitions(-DBUILD_TYPE_TEST) 6 | add_definitions(-DCPPUTEST_MEM_LEAK_DETECTION_DISABLED) 7 | endif () 8 | 9 | add_subdirectory (edge-core) 10 | add_subdirectory (edge-io-lib) 11 | add_subdirectory (edge-rpc) 12 | add_subdirectory (edge-server-mock) 13 | add_subdirectory (mbed-cloud-client-mock) 14 | add_subdirectory (edge-client) 15 | add_subdirectory (pal-mock) 16 | add_subdirectory (event-os-mock) 17 | add_subdirectory (kcm-mock) 18 | add_subdirectory (libevent-mock) 19 | add_subdirectory (libwebsocket-mock) 20 | add_subdirectory (edge-client-mock) 21 | add_subdirectory (pt-client) 22 | add_subdirectory (pt-client-2) 23 | add_subdirectory (test-lib) 24 | 25 | -------------------------------------------------------------------------------- /test/edge-client-mock/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file (GLOB SOURCES ./*.cpp ./*.c ${ROOT_HOME}/common/integer_length.c) 2 | 3 | add_definitions(-DMBED_CONF_MBED_TRACE_ENABLE=1) 4 | if(FOTA_ENABLE) 5 | add_definitions(-DMBED_EDGE_SUBDEVICE_FOTA) 6 | endif() 7 | add_library (edge-client-mock-lib ${SOURCES}) 8 | include_directories (../cpputest-custom-types) 9 | target_include_directories (edge-client-mock-lib PUBLIC ${CPPUTEST_HOME}/include) 10 | target_include_directories (edge-client-mock-lib PUBLIC ${ROOT_HOME}/test/test-lib) 11 | -------------------------------------------------------------------------------- /test/edge-client-mock/mock_edge_client_byoc.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "CppUTestExt/MockSupport.h" 3 | 4 | extern "C" { 5 | #include "edge-client/edge_client_byoc.h" 6 | 7 | byoc_data_t *edgeclient_create_byoc_data(char *cbor_file) 8 | { 9 | return (byoc_data_t*) mock().actualCall("edgeclient_create_byoc_data") 10 | .withPointerParameter("cbor_file", cbor_file) 11 | .returnPointerValue(); 12 | } 13 | 14 | int edgeclient_inject_byoc(byoc_data_t *byoc_data) 15 | { 16 | return mock().actualCall("edgeclient_inject_byoc").withPointerParameter("byoc_data", byoc_data).returnIntValue(); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /test/edge-client/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file (GLOB SOURCES ./*.cpp ../../common/apr_base64.c ../test-lib/msg_api_test_helper.cpp) 2 | 3 | enable_language(C) 4 | enable_language(CXX) 5 | if(FOTA_ENABLE) 6 | add_definitions(-DMBED_EDGE_SUBDEVICE_FOTA) 7 | endif() 8 | add_executable (edge-client-test ${SOURCES}) 9 | 10 | add_definitions(-DMBED_CONF_MBED_TRACE_ENABLE=1) 11 | include_directories (../cpputest-custom-types) 12 | target_include_directories (edge-client-test PUBLIC ${CPPUTEST_HOME}/include) 13 | target_include_directories (edge-client-test PUBLIC ${ROOT_HOME}/test/test-lib) 14 | target_include_directories (edge-client-test PUBLIC ${ROOT_HOME}/lib/mbed-cloud-client/unittests/stub) 15 | target_link_libraries (edge-client-test edge-server-mock-lib pal-mock-lib test-lib edge-client CppUTest CppUTestExt mbedTrace libservice pthread curl) 16 | 17 | add_definitions(-DTEST_DATA_DIR="${TEST_DATA_DIR}") 18 | -------------------------------------------------------------------------------- /test/edge-client/test_main.cpp: -------------------------------------------------------------------------------- 1 | #include "CppUTest/CommandLineTestRunner.h" 2 | #include 3 | #include 4 | #include 5 | #include "mbed-trace/mbed_trace.h" 6 | #include "cpputest-custom-types/value_pointer.h" 7 | #include "test-lib/edgeclient_request_context.h" 8 | 9 | int main(int args, char** argv) 10 | { 11 | MockSupportPlugin mock_plugin; 12 | ValuePointerComparator value_pointer_comparator; 13 | EdgeClientRequestContextComparator edgeclient_request_context_comparator; 14 | mock_plugin.installComparator("ValuePointer", value_pointer_comparator); 15 | mock_plugin.installComparator("EdgeClientRequestContext", edgeclient_request_context_comparator); 16 | 17 | TestRegistry::getCurrentRegistry()->installPlugin(&mock_plugin); 18 | 19 | mbed_trace_init(); 20 | // Clean the memory inside the mock (otherwise you will see memory leaks in the first testcase) 21 | mock().clear(); 22 | 23 | int result = RUN_ALL_TESTS(args, argv); 24 | 25 | mbed_trace_free(); 26 | 27 | return result; 28 | } 29 | -------------------------------------------------------------------------------- /test/edge-client/test_rfs.cpp: -------------------------------------------------------------------------------- 1 | #include "CppUTest/TestHarness.h" 2 | #include "CppUTestExt/MockSupport.h" 3 | 4 | #include "edge-client/edge_client.h" 5 | #include "edge-client/edge_core_cb.h" 6 | extern "C" { 7 | #include "edge-core/edge_device_object.h" 8 | #include "kcm_status.h" 9 | #include "edge-client/reset_factory_settings.h" 10 | } 11 | 12 | TEST_GROUP(edge_rfs){ 13 | void setup() 14 | { 15 | } 16 | 17 | void teardown() 18 | { 19 | } 20 | }; 21 | 22 | -------------------------------------------------------------------------------- /test/edge-core/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file (GLOB SOURCES ./*.cpp ${ROOT_HOME}/edge-rpc/rpc_timeout_api.c ${ROOT_HOME}/edge-client/edge_client_format_values.c ${ROOT_HOME}/lib/mbedtls/crypto/library/base64.c ../test-lib/msg_api_test_helper.cpp) 2 | enable_language(C) 3 | enable_language(CXX) 4 | 5 | set (TEST_DATA_DIR ${ROOT_HOME}/test/edge-core/data) 6 | 7 | add_executable (edge-core-test ${SOURCES}) 8 | 9 | add_definitions(-DMBED_CONF_MBED_TRACE_ENABLE=1) 10 | 11 | include_directories (../cpputest-custom-types ../libwebsocket-mock ../event-os-mock) 12 | target_include_directories (edge-core-test PUBLIC ${CPPUTEST_HOME}/include) 13 | target_include_directories (edge-core-test PUBLIC ${ROOT_HOME}/test/test-lib) 14 | 15 | target_link_libraries (edge-core-test edge-msg-api edge-websocket-common 16 | test-lib libwebsocket-mock-lib libevent-mock-lib pal-mock-lib edge-client-mock-lib edge-core 17 | event-os-mock-lib kcm-mock-lib CppUTest CppUTestExt) 18 | 19 | add_definitions(-DTEST_DATA_DIR="${TEST_DATA_DIR}") 20 | 21 | -------------------------------------------------------------------------------- /test/edge-core/data/complex_resource_hierarchy.json: -------------------------------------------------------------------------------- 1 | { 2 | "deviceId": "complex", 3 | "lifetime": 86400, 4 | "queuemode": "Q", 5 | "objects": [{ 6 | "objectId": 0, 7 | "objectInstances": [{ 8 | "objectInstanceId": 0, 9 | "resources": [{ 10 | "resourceId": 0, 11 | "operations": 1, 12 | "type": "int", 13 | "value": "AAAAAA==" 14 | }, { 15 | "resourceId": 1, 16 | "operations": 1, 17 | "type": "string", 18 | "value": "MA==" 19 | }] 20 | }, { 21 | "objectInstanceId": 1, 22 | "resources": [{ 23 | "resourceId": 0, 24 | "operations": 1, 25 | "type": "int", 26 | "value": "AAAAAA==" 27 | }, { 28 | "resourceId": 1, 29 | "operations": 1, 30 | "type": "string", 31 | "value": "MA==" 32 | }] 33 | }] 34 | }, { 35 | "objectId": 1, 36 | "objectInstances": [{ 37 | "objectInstanceId": 0, 38 | "resources": [{ 39 | "resourceId": 0, 40 | "operations": 1, 41 | "type": "int", 42 | "value": "AAAAAA==" 43 | }, { 44 | "resourceId": 1, 45 | "operations": 1, 46 | "type": "string", 47 | "value": "MA==" 48 | }] 49 | }, { 50 | "objectInstanceId": 1, 51 | "resources": [{ 52 | "resourceId": 0, 53 | "operations": 1, 54 | "type": "int", 55 | "value": "AAAAAA==" 56 | }, { 57 | "resourceId": 1, 58 | "operations": 1, 59 | "type": "string", 60 | "value": "MA==" 61 | }] 62 | }] 63 | }] 64 | } 65 | -------------------------------------------------------------------------------- /test/edge-core/data/device2_register_test.json: -------------------------------------------------------------------------------- 1 | { 2 | "deviceId": "test-device-2", 3 | "lifetime": 123456, 4 | "queuemode": "", 5 | "objects": [{ 6 | "objectId": 10, 7 | "objectInstances": [{ 8 | "objectInstanceId": 0, 9 | "resources": [{ 10 | "resourceId": 1, 11 | "operations": 1, 12 | "type": "opaque" 13 | }, { 14 | "resourceId": 2, 15 | "operations": 3, 16 | "type": "opaque" 17 | }] 18 | }, { 19 | "objectInstanceId": 5, 20 | "resources": [{ 21 | "resourceId": 0, 22 | "operations": 1, 23 | "type": "opaque" 24 | }] 25 | }] 26 | }, { 27 | "objectId": 13, 28 | "objectInstances": [{ 29 | "objectInstanceId": 0, 30 | "resources": [{ 31 | "resourceId": 37, 32 | "operations": 1, 33 | "type": "opaque" 34 | }] 35 | }] 36 | }] 37 | } -------------------------------------------------------------------------------- /test/edge-core/data/device2_unregister_test.json: -------------------------------------------------------------------------------- 1 | { 2 | "deviceId": "test-device-2" 3 | } -------------------------------------------------------------------------------- /test/edge-core/data/device_register_test_instance_missing.json: -------------------------------------------------------------------------------- 1 | { 2 | "deviceId": "test-device", 3 | "lifetime": 123456, 4 | "queuemode": "", 5 | "objects": [{ 6 | "objectId": 10, 7 | "objectInstances": [{ 8 | "objectInstanceIdInvalid": 0, 9 | "resources": [{ 10 | "resourceIdInvalid": 1, 11 | "operations": 1, 12 | "type": "opaque" 13 | }, { 14 | "resourceId": 2, 15 | "operations": 3, 16 | "type": "opaque" 17 | }] 18 | }] 19 | }, 20 | { 21 | "objectId": 13, 22 | "objectInstances": [{ 23 | "objectInstanceId": 0, 24 | "resources": [{ 25 | "resourceId": 37, 26 | "operations": 1, 27 | "type": "opaque" 28 | }] 29 | }] 30 | }] 31 | } 32 | 33 | -------------------------------------------------------------------------------- /test/edge-core/data/device_register_test_invalid_resource_value.json: -------------------------------------------------------------------------------- 1 | { 2 | "deviceId": "test-device", 3 | "lifetime": 123456, 4 | "queuemode": "", 5 | "objects": [{ 6 | "objectId": 10, 7 | "objectInstances": [{ 8 | "objectInstanceId": 0, 9 | "resources": [{ 10 | "resourceId": 2, 11 | "operations": 3, 12 | "type": "bool", 13 | "value" : "dHJ1ZXRydWU=" 14 | }] 15 | },{ 16 | "objectInstanceId": 0, 17 | "resources": [{ 18 | "resourceId": 37, 19 | "operations": 1, 20 | "type": "opaque" 21 | }] 22 | }] 23 | }] 24 | } 25 | 26 | -------------------------------------------------------------------------------- /test/edge-core/data/device_register_test_object_missing.json: -------------------------------------------------------------------------------- 1 | { 2 | "deviceId": "test-device", 3 | "lifetime": 123456, 4 | "queuemode": "", 5 | "objects": [{ 6 | "objectIdInvalid": 10, 7 | "objectInstances": [{ 8 | "objectInstanceIdInvalid": 0, 9 | "resources": [{ 10 | "resourceIdInvalid": 1, 11 | "operations": 1, 12 | "type": "opaque" 13 | }, { 14 | "resourceId": 2, 15 | "operations": 3, 16 | "type": "opaque" 17 | }] 18 | }] 19 | }, 20 | { 21 | "objectId": 13, 22 | "objectInstances": [{ 23 | "objectInstanceId": 0, 24 | "resources": [{ 25 | "resourceId": 37, 26 | "operations": 1, 27 | "type": "opaque" 28 | }] 29 | }] 30 | }] 31 | } 32 | 33 | -------------------------------------------------------------------------------- /test/edge-core/data/device_register_test_resource_missing.json: -------------------------------------------------------------------------------- 1 | { 2 | "deviceId": "test-device", 3 | "lifetime": 123456, 4 | "queuemode": "", 5 | "objects": [{ 6 | "objectId": 10, 7 | "objectInstances": [{ 8 | "objectInstanceId": 0, 9 | "resources": [{ 10 | "resourceIdInvalid": 1, 11 | "operations": 1, 12 | "type": "opaque" 13 | }, { 14 | "resourceId": 2, 15 | "operations": 3, 16 | "type": "opaque" 17 | }] 18 | },{ 19 | "objectInstanceId": 0, 20 | "resources": [{ 21 | "resourceId": 37, 22 | "operations": 1, 23 | "type": "opaque" 24 | }] 25 | }] 26 | }] 27 | } 28 | 29 | -------------------------------------------------------------------------------- /test/edge-core/data/device_unregister_test.json: -------------------------------------------------------------------------------- 1 | { 2 | "deviceId": "test-device" 3 | } -------------------------------------------------------------------------------- /test/edge-core/data/device_write_non_string_value.json: -------------------------------------------------------------------------------- 1 | { 2 | "deviceId": "test-device", 3 | "lifetime": 123456, 4 | "queuemode": "", 5 | "objects": [{ 6 | "objectId": 22, 7 | "objectInstances": [{ 8 | "objectInstanceId": 0, 9 | "resources": [{ 10 | "resourceId": 37, 11 | "operations": 1, 12 | "type": "int", 13 | "value": 0 14 | }] 15 | }] 16 | }] 17 | } 18 | 19 | -------------------------------------------------------------------------------- /test/edge-core/data/device_write_value_failure.json: -------------------------------------------------------------------------------- 1 | { 2 | "deviceId": "test-device", 3 | "lifetime": 123456, 4 | "queuemode": "", 5 | "objects": [{ 6 | "objectId": 22, 7 | "objectInstances": [{ 8 | "objectInstanceId": 0, 9 | "resources": [{ 10 | "resourceId": 37, 11 | "operations": 1, 12 | "type": "int", 13 | "value": "MTAw=" 14 | }] 15 | }] 16 | }] 17 | } 18 | 19 | 20 | -------------------------------------------------------------------------------- /test/edge-core/server_test.cpp: -------------------------------------------------------------------------------- 1 | extern "C" { 2 | #include "common/websocket_comm.h" 3 | #include "libwebsockets.h" 4 | #include 5 | #include "edge-core/protocol_api_internal.h" 6 | #include "edge-core/websocket_serv.h" 7 | #include "libwebsocket-mock/lws_mock.h" 8 | #include "test-lib/server_test.h" 9 | 10 | struct connection *server_test_establish_connection() 11 | { 12 | struct lws *wsi = lws_mock_create_wsi(); 13 | lws_mock_connection_established(wsi, LWS_CALLBACK_ESTABLISHED); 14 | websocket_connection_t *websocket_connection = (websocket_connection_t *) wsi->userdata; 15 | return websocket_connection->conn; 16 | } 17 | 18 | int server_test_connection_filter_cb(const char *uri) 19 | { 20 | struct lws *wsi = lws_mock_create_wsi(); 21 | return lws_mock_callback(wsi, LWS_CALLBACK_FILTER_PROTOCOL_CONNECTION); 22 | } 23 | 24 | void server_test_free_established_connection(struct connection *connection) 25 | { 26 | websocket_connection_t *websocket_connection = (websocket_connection_t *) 27 | connection->transport_connection->transport; 28 | websocket_server_connection_destroy(websocket_connection); 29 | if (websocket_connection && websocket_connection->wsi) { 30 | lws_mock_destroy_wsi(websocket_connection->wsi); 31 | } 32 | } 33 | 34 | void server_test_connection_closed(struct connection *connection) 35 | { 36 | lws_mock_connection_closed(((websocket_connection_t *) (connection->transport_connection->transport))->wsi); 37 | } 38 | 39 | void server_test_call_receive_cb(struct connection *connection, void *data, size_t len) 40 | { 41 | lws_mock_call_receive_cb(((websocket_connection_t *) (connection->transport_connection->transport))->wsi, 42 | data, 43 | len); 44 | } 45 | } // extern "C" 46 | -------------------------------------------------------------------------------- /test/edge-core/test_default_message_id_generator.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "CppUTest/TestHarness.h" 4 | 5 | extern "C" { 6 | #include "common/default_message_id_generator.h" 7 | } 8 | 9 | TEST_GROUP(default_message_id_generator) { 10 | void setup() 11 | { 12 | } 13 | 14 | void teardown() 15 | { 16 | } 17 | }; 18 | 19 | TEST(default_message_id_generator, test_generation_for_first_10K_values) 20 | { 21 | int32_t i; 22 | for (i = 0; i < 10000; i++) { 23 | char* id = edge_default_generate_msg_id(); 24 | CHECK_EQUAL(i, atoi(id)); 25 | free(id); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /test/edge-core/test_integer_length.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "CppUTest/TestHarness.h" 4 | 5 | extern "C" { 6 | #include "common/integer_length.h" 7 | } 8 | 9 | uint16_t MAX_UINT32_T_LEN = strlen("4294967295"); 10 | 11 | TEST_GROUP(integer_length) { 12 | void setup() 13 | { 14 | } 15 | 16 | void teardown() 17 | { 18 | } 19 | }; 20 | 21 | TEST(integer_length, test_negative_integer) 22 | { 23 | /* this test checks that the algorithm does not fail 24 | * the signed integer is converted to unsigned integer 25 | * which will equal to uint32_t of 4294967196. 26 | */ 27 | uint16_t len_of_unsigned = edge_int_length(4294967196); 28 | uint16_t len = edge_int_length(-100); 29 | CHECK_EQUAL(len_of_unsigned, len); 30 | } 31 | 32 | TEST(integer_length, test_zero) 33 | { 34 | CHECK_EQUAL(1, edge_int_length(0)); 35 | } 36 | 37 | TEST(integer_length, test_one) 38 | { 39 | CHECK_EQUAL(1, edge_int_length(1)); 40 | } 41 | 42 | TEST(integer_length, test_maximum_length) 43 | { 44 | CHECK_EQUAL(MAX_UINT32_T_LEN, edge_int_length((uint32_t) -1)); 45 | } 46 | 47 | TEST(integer_length, test_multiple_lengths) 48 | { 49 | uint32_t num = 0; 50 | uint32_t factor = 10; 51 | uint32_t current_factor = 10; 52 | for(int i = 1; i < 10; i++) { 53 | if (i < 9) { 54 | num = i * current_factor; 55 | } else { 56 | /* Must cap the uint32_t here, on the 9th round it will overflow 57 | * if multiplied with 10 58 | */ 59 | num = (uint32_t) -1; 60 | } 61 | CHECK_EQUAL(i + 1, edge_int_length(num)); 62 | current_factor = current_factor * factor; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /test/edge-core/test_main.cpp: -------------------------------------------------------------------------------- 1 | #include "CppUTest/CommandLineTestRunner.h" 2 | #include 3 | #include 4 | #include 5 | #include "test-lib/MyEvBuffer.h" 6 | #include "cpputest-custom-types/value_pointer.h" 7 | #include "mbed-trace/mbed_trace.h" 8 | 9 | int main(int args, char** argv) 10 | { 11 | MockSupportPlugin mock_plugin; 12 | MyEvBufferCopier ev_buffer_copier; 13 | ValuePointerComparator value_pointer_comparator; 14 | ValuePointerCopier value_pointer_copier; 15 | 16 | mock_plugin.installCopier("MyEvBuffer", ev_buffer_copier); 17 | mock_plugin.installComparator("ValuePointer", value_pointer_comparator); 18 | mock_plugin.installCopier("ValuePointer", value_pointer_copier); 19 | 20 | TestRegistry::getCurrentRegistry()->installPlugin(&mock_plugin); 21 | 22 | mbed_trace_init(); 23 | // Clean the memory inside the mock (otherwise you will see memory leaks in the first testcase) 24 | mock().clear(); 25 | 26 | int result = RUN_ALL_TESTS(args, argv); 27 | 28 | mbed_trace_free(); 29 | 30 | return result; 31 | } 32 | -------------------------------------------------------------------------------- /test/edge-core/test_websocket_comm.cpp: -------------------------------------------------------------------------------- 1 | #include "CppUTest/TestHarness.h" 2 | 3 | 4 | extern "C" { 5 | #include "common/websocket_comm.h" 6 | 7 | /** 8 | * Test definitions 9 | */ 10 | TEST_GROUP(websocket_comm) { 11 | void setup() 12 | { 13 | } 14 | 15 | void teardown() 16 | { 17 | } 18 | }; 19 | 20 | TEST(websocket_comm, test_complete_message) 21 | { 22 | websocket_connection_t *wsconn = (websocket_connection_t*) malloc(sizeof(websocket_connection_t)); 23 | wsconn->msg = NULL; 24 | wsconn->msg_len = 0; 25 | uint8_t *fragment = (uint8_t*) "{}"; 26 | size_t fragment_len = strlen((char*) fragment); 27 | CHECK_EQUAL(0, websocket_add_msg_fragment(wsconn, fragment, fragment_len)); 28 | CHECK_EQUAL(fragment_len, wsconn->msg_len); 29 | MEMCMP_EQUAL("{}", wsconn->msg, fragment_len); 30 | websocket_reset_message(wsconn); 31 | free(wsconn); 32 | } 33 | 34 | TEST(websocket_comm, test_fragmented_message) 35 | { 36 | websocket_connection_t *wsconn = (websocket_connection_t*) malloc(sizeof(websocket_connection_t)); 37 | wsconn->msg = NULL; 38 | wsconn->msg_len = 0; 39 | uint8_t *fragment = (uint8_t*) "{}"; 40 | size_t fragment_len = strlen((char*) fragment); 41 | CHECK_EQUAL(0, websocket_add_msg_fragment(wsconn, fragment, fragment_len)); 42 | CHECK_EQUAL(fragment_len, wsconn->msg_len); 43 | 44 | CHECK_EQUAL(0, websocket_add_msg_fragment(wsconn, fragment, fragment_len)); 45 | CHECK_EQUAL(2 * fragment_len, wsconn->msg_len); 46 | MEMCMP_EQUAL("{}{}", wsconn->msg, 2 * fragment_len); 47 | websocket_reset_message(wsconn); 48 | free(wsconn); 49 | } 50 | 51 | } // extern "C" 52 | -------------------------------------------------------------------------------- /test/edge-io-lib/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file (GLOB SOURCES ./*.cpp ${ROOT_HOME}/common/edge-io-lib/edge_io_lib.c) 2 | enable_language(C) 3 | enable_language(CXX) 4 | 5 | 6 | add_executable (edge-io-lib-test ${SOURCES}) 7 | 8 | add_definitions(-DMBED_CONF_MBED_TRACE_ENABLE=1) 9 | 10 | target_include_directories (edge-io-lib-test PUBLIC ${CPPUTEST_HOME}/include) 11 | 12 | target_link_libraries (edge-io-lib-test mbedTraceEdge CppUTest CppUTestExt) 13 | 14 | -------------------------------------------------------------------------------- /test/edge-io-lib/system_if.cpp: -------------------------------------------------------------------------------- 1 | #include "CppUTest/TestHarness.h" 2 | #include "CppUTestExt/MockSupport.h" 3 | 4 | extern "C" { 5 | 6 | int mocked_access(const char *__name, int __type) 7 | { 8 | return mock() 9 | .actualCall("access") 10 | .withStringParameter("path", __name) 11 | .withIntParameter("type", __type) 12 | .returnIntValue(); 13 | } 14 | 15 | int mocked_open(const char *__file, int __oflagv, mode_t mode) 16 | { 17 | return mock() 18 | .actualCall("open") 19 | .withStringParameter("path", __file) 20 | .withIntParameter("flag", __oflagv) 21 | .withIntParameter("mode", mode) 22 | .returnIntValue(); 23 | } 24 | 25 | int mocked_unlink(const char *path) 26 | { 27 | return mock().actualCall("unlink").withStringParameter("path", path).returnIntValue(); 28 | } 29 | 30 | int mocked_flock(int __fd, int __operation) 31 | { 32 | return mock() 33 | .actualCall("flock") 34 | .withIntParameter("fd", __fd) 35 | .withIntParameter("operation", __operation) 36 | .returnIntValue(); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /test/edge-io-lib/test_main.cpp: -------------------------------------------------------------------------------- 1 | #include "CppUTest/CommandLineTestRunner.h" 2 | #include 3 | #include 4 | #include 5 | #include "mbed-trace/mbed_trace.h" 6 | 7 | int main(int args, char** argv) 8 | { 9 | MockSupportPlugin mock_plugin; 10 | 11 | TestRegistry::getCurrentRegistry()->installPlugin(&mock_plugin); 12 | 13 | mbed_trace_init(); 14 | // Clean the memory inside the mock (otherwise you will see memory leaks in the first testcase) 15 | mock().clear(); 16 | 17 | int result = RUN_ALL_TESTS(args, argv); 18 | 19 | mbed_trace_free(); 20 | 21 | return result; 22 | } 23 | -------------------------------------------------------------------------------- /test/edge-rpc/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file (GLOB SOURCES ./*.cpp ${ROOT_HOME}/common/integer_length.c ${ROOT_HOME}/common/pt_api_error_codes.c) 2 | enable_language(C) 3 | enable_language(CXX) 4 | 5 | add_executable (edge-rpc-test ${SOURCES}) 6 | 7 | add_definitions(-DMBED_CONF_MBED_TRACE_ENABLE=1) 8 | 9 | target_include_directories (edge-rpc-test PUBLIC ${CPPUTEST_HOME}/include) 10 | target_include_directories (edge-rpc-test PUBLIC ${ROOT_HOME}/lib/jsonrpc) 11 | target_include_directories (edge-rpc-test PUBLIC ${ROOT_HOME}/test/test-lib) 12 | 13 | target_link_libraries (edge-rpc-test test-lib libevent-mock-lib rpc jansson jsonrpc mbedTrace libservice CppUTest CppUTestExt) 14 | -------------------------------------------------------------------------------- /test/edge-rpc/test_main.cpp: -------------------------------------------------------------------------------- 1 | #include "CppUTest/CommandLineTestRunner.h" 2 | #include 3 | #include 4 | #include 5 | #include "mbed-trace/mbed_trace.h" 6 | #include "test-lib/json_pointer.h" 7 | #include "test-lib/json_message_t_pointer.h" 8 | 9 | int main(int args, char** argv) 10 | { 11 | MockSupportPlugin mock_plugin; 12 | JsonPointerCopier json_pointer_copier; 13 | JsonPointerComparator json_pointer_comparator; 14 | JsonMessageTPointerComparator jmtp_comparator; 15 | JsonMessageTPointerCopier jmtp_copier; 16 | 17 | mock_plugin.installComparator("JsonPointer", json_pointer_comparator); 18 | mock_plugin.installComparator("JsonMessageTPointer", jmtp_comparator); 19 | mock_plugin.installCopier("JsonPointer", json_pointer_copier); 20 | mock_plugin.installCopier("JsonMessageTPointer", jmtp_copier); 21 | TestRegistry::getCurrentRegistry()->installPlugin(&mock_plugin); 22 | 23 | mbed_trace_init(); 24 | // Clean the memory inside the mock (otherwise you will see memory leaks in the first testcase) 25 | mock().clear(); 26 | // mock().tracing(true); 27 | 28 | int result = RUN_ALL_TESTS(args, argv); 29 | 30 | mbed_trace_free(); 31 | 32 | return result; 33 | } 34 | -------------------------------------------------------------------------------- /test/edge-server-mock/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file (GLOB SOURCES ./*.cpp ./*.c) 2 | 3 | add_definitions(-DMBED_CONF_MBED_TRACE_ENABLE=1) 4 | if(FOTA_ENABLE) 5 | add_definitions(-DMBED_EDGE_SUBDEVICE_FOTA) 6 | endif() 7 | add_library (edge-server-mock-lib ${SOURCES}) 8 | 9 | target_include_directories (edge-server-mock-lib PUBLIC ${CPPUTEST_HOME}/include) 10 | target_include_directories (edge-server-mock-lib PUBLIC ${ROOT_HOME}/test/test-lib) 11 | -------------------------------------------------------------------------------- /test/edge-server-mock/test_fota_config.h: -------------------------------------------------------------------------------- 1 | #ifndef _TEST_FOTA_CONF 2 | #define _TEST_FOTA_CONF 3 | 4 | #define DUMMY_BINARY_LOCATION "" 5 | #define VENDOR_ID "SUBDEVICE-VENDOR" 6 | #define CLASS_ID "SUBDEVICE--CLASS" 7 | #define FIRMWARE_VERSION 1000 8 | #define PAYLOAD_SIZE 100000 9 | #define COMPONENT_NAME "MAIN" 10 | #endif -------------------------------------------------------------------------------- /test/event-os-mock/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file (GLOB SOURCES ./*.cpp ./*.c) 2 | 3 | add_definitions(-DMBED_CONF_MBED_TRACE_ENABLE=1) 4 | 5 | add_library (event-os-mock-lib ${SOURCES}) 6 | 7 | target_include_directories (event-os-mock-lib PUBLIC ${CPPUTEST_HOME}/include) 8 | -------------------------------------------------------------------------------- /test/event-os-mock/event-os-mock/eventOS_event_mock.h: -------------------------------------------------------------------------------- 1 | #ifndef EVENT_OS_EVENT_MOCK_H 2 | #define EVENT_OS_EVENT_MOCK_H 3 | 4 | #include "nanostack-event-loop/eventOS_scheduler.h" 5 | #include "nanostack-event-loop/eventOS_event.h" 6 | 7 | /* Simulates event OS */ 8 | typedef struct os_event_item { 9 | ns_list_link_t link; 10 | arm_event_t event; 11 | } os_event_item_t; 12 | 13 | typedef NS_LIST_HEAD(os_event_item_t, link) os_event_items_t; 14 | 15 | typedef struct os_event_handler { 16 | ns_list_link_t link; 17 | void (*handler_func)(arm_event_t *); 18 | uint8_t init_event_type; 19 | } os_event_handler_t; 20 | 21 | typedef NS_LIST_HEAD(os_event_handler_t, link) os_event_handlers_t; 22 | 23 | void eventOS_mock_init(); 24 | void eventOS_mock_destroy(); 25 | bool eventOS_mock_event_handle(); 26 | void eventOS_scheduler_mutex_wait(); 27 | void eventOS_scheduler_mutex_release(); 28 | 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /test/kcm-mock/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file (GLOB SOURCES ./*.cpp ./*.c) 2 | 3 | add_definitions(-DMBED_CONF_MBED_TRACE_ENABLE=1) 4 | 5 | add_library (kcm-mock-lib ${SOURCES}) 6 | 7 | target_include_directories (kcm-mock-lib PUBLIC ${CPPUTEST_HOME}/include) 8 | -------------------------------------------------------------------------------- /test/libevent-mock/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file (GLOB SOURCES ./*.cpp ./*.c) 2 | 3 | add_library (libevent-mock-lib ${SOURCES}) 4 | 5 | target_include_directories (libevent-mock-lib PUBLIC ${CPPUTEST_HOME}/include) 6 | target_include_directories (libevent-mock-lib PUBLIC ${ROOT_HOME}/test/test-lib) 7 | -------------------------------------------------------------------------------- /test/libwebsocket-mock/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file (GLOB SOURCES ./mock_lws.cpp) 2 | file (GLOB MINIMAL ./mock_lws_minimal.cpp) 3 | 4 | include_directories (. ../cpputest-custom-types) 5 | 6 | add_library (libwebsocket-mock-lib ${SOURCES}) 7 | target_include_directories (libwebsocket-mock-lib PUBLIC ${CPPUTEST_HOME}/include) 8 | 9 | add_library (libwebsocket-mock-minimal-lib ${MINIMAL}) 10 | target_include_directories (libwebsocket-mock-minimal-lib PUBLIC ${CPPUTEST_HOME}/include) 11 | -------------------------------------------------------------------------------- /test/libwebsocket-mock/libwebsocket-mock/lws_mock.h: -------------------------------------------------------------------------------- 1 | #ifndef LWS_MOCK_H 2 | #define LWS_MOCK_H 3 | 4 | #include 5 | #include "libwebsockets.h" 6 | 7 | struct lws_context { 8 | const struct lws_protocols *protocols; 9 | }; 10 | 11 | struct lws { 12 | struct lws_context *context; 13 | void *userdata; 14 | const struct lws_protocols *protocol; 15 | bool is_client; 16 | bool connection_established; 17 | }; 18 | 19 | struct lws_context *lws_mock_get_context(); 20 | struct lws *lws_mock_create_wsi(); 21 | struct lws *lws_mock_get_wsi(); 22 | void lws_mock_destroy_wsi(struct lws *wsi); 23 | void lws_mock_connection_established(struct lws *wsi, enum lws_callback_reasons reason); 24 | void lws_mock_connection_closed(struct lws *wsi); 25 | void lws_mock_call_receive_cb(struct lws *wsi, void *in, size_t len); 26 | void lws_mock_callback_client_receive(unsigned char *buf, size_t len, int expected_ret_val); 27 | int lws_mock_callback(struct lws *wsi, enum lws_callback_reasons reason); 28 | void lws_mock_setup_connection_failure(); 29 | #endif 30 | -------------------------------------------------------------------------------- /test/mbed-cloud-client-mock/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(MBED_CLOUD_CLIENT ${ROOT_HOME}/lib/mbed-cloud-client) 2 | 3 | enable_language(C) 4 | enable_language(CXX) 5 | 6 | file (GLOB SOURCES *.cpp *.c) 7 | 8 | set(MBED_CLOUD_CLIENT ${ROOT_HOME}/lib/mbed-cloud-client) 9 | set(CLIENT_SOURCE_LOC ${MBED_CLOUD_CLIENT}/mbed-client/source/) 10 | file(GLOB M2M_SOURCES ${ROOT_HOME}/test/test-lib/m2mcallbackstorage.cpp) 11 | 12 | add_library (mbed-cloud-client-mock ${SOURCES} ${M2M_SOURCES}) 13 | 14 | add_definitions(-DMBED_CONF_MBED_TRACE_ENABLE=1) 15 | include_directories (../cpputest-custom-types) 16 | 17 | target_include_directories (mbed-cloud-client-mock PUBLIC ${CPPUTEST_HOME}/include) 18 | target_include_directories (mbed-cloud-client-mock PUBLIC ${CPPUTEST_HOME}/include) 19 | target_include_directories (mbed-cloud-client-mock PUBLIC ${ROOT_HOME}/test/test-lib/) 20 | target_include_directories (mbed-cloud-client-mock PUBLIC ${MBED_CLOUD_CLIENT}/mbed-client/source/include) 21 | 22 | if(FOTA_ENABLE) 23 | add_definitions(-DMBED_EDGE_SUBDEVICE_FOTA) 24 | endif() 25 | -------------------------------------------------------------------------------- /test/mbed-cloud-client-mock/MbedCloudClient_mock.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 ARM Limited. All rights reserved. 3 | * SPDX-License-Identifier: Apache-2.0 4 | * Licensed under the Apache License, Version 2.0 (the License); you may 5 | * not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifdef MBED_EDGE_SUBDEVICE_FOTA 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | #include "mbed-cloud-client/MbedCloudClientConfig.h" 25 | #include "mbed-cloud-client/MbedCloudClient.h" 26 | 27 | #include "update-client-hub/modules/common/update-client-common/arm_uc_error.h" 28 | #include "update-client-hub/modules/common/update-client-common/arm_uc_types.h" 29 | 30 | #include "CppUTestExt/MockSupport.h" 31 | #include "cpputest-custom-types/value_pointer.h" 32 | 33 | 34 | M2MInterface *MbedCloudClient::get_m2m_interface() 35 | { 36 | return NULL; 37 | } 38 | 39 | #endif // MBED_EDGE_SUBDEVICE_FOTA -------------------------------------------------------------------------------- /test/mbed-cloud-client-mock/ns_event_loop.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 ARM Limited. All rights reserved. 3 | * SPDX-License-Identifier: Apache-2.0 4 | * Licensed under the Apache License, Version 2.0 (the License); you may 5 | * not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "CppUTestExt/MockSupport.h" 18 | 19 | extern "C" 20 | { 21 | void ns_event_loop_thread_stop() 22 | { 23 | mock().actualCall("ns_event_loop_thread_stop"); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /test/mbed-cloud-client-mock/testfactory.cpp: -------------------------------------------------------------------------------- 1 | #include "testfactory.h" 2 | #include "m2mobject.h" 3 | #include "m2mendpoint.h" 4 | #include "m2mresource.h" 5 | 6 | M2MEndpoint * TestFactory::create_endpoint(String &name, char *path) 7 | { 8 | return new M2MEndpoint(name, path); 9 | } 10 | 11 | M2MObject* TestFactory::create_object(String &name, char *path, bool external_blockwise_store) 12 | { 13 | return new M2MObject(name, path, external_blockwise_store); 14 | } 15 | 16 | M2MObjectInstance *TestFactory::create_object_instance(M2MObject& parent) 17 | { 18 | return new M2MObjectInstance(parent, "", NULL); 19 | } 20 | 21 | M2MResource *TestFactory::create_resource(M2MObjectInstance &parent, String &resource_name, char *path, bool multiple_instance, bool external_blockwise_store) 22 | { 23 | return new M2MResource(parent, resource_name, M2MBase::Dynamic, "", M2MBase::OPAQUE, 24 | false /* observable */, path, 25 | multiple_instance, external_blockwise_store); 26 | } 27 | 28 | -------------------------------------------------------------------------------- /test/pal-mock/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file (GLOB SOURCES ./*.cpp ./*.c) 2 | 3 | add_definitions(-DMBED_CONF_MBED_TRACE_ENABLE=1) 4 | 5 | add_library (pal-mock-lib ${SOURCES}) 6 | 7 | target_include_directories (pal-mock-lib PUBLIC ${CPPUTEST_HOME}/include) 8 | -------------------------------------------------------------------------------- /test/pal-mock/pal_mock.cpp: -------------------------------------------------------------------------------- 1 | #include "pal.h" 2 | #include "pal_fileSystem.h" 3 | #include "CppUTestExt/MockSupport.h" 4 | 5 | palStatus_t pal_fsMkDir(const char *pathName) 6 | { 7 | return (palStatus_t)mock().actualCall("pal_fsMkDir") 8 | .withStringParameter("pathName", pathName) 9 | .returnIntValue(); 10 | } 11 | 12 | palStatus_t pal_fsSetMountPoint(pal_fsStorageID_t dataID, const char *Path) 13 | { 14 | return (palStatus_t) mock() 15 | .actualCall("pal_fsSetMountPoint") 16 | .withIntParameter("dataID", dataID) 17 | .withStringParameter("Path", Path) 18 | .returnIntValue(); 19 | } 20 | 21 | palStatus_t pal_osMutexCreate(palMutexID_t* mutexID) 22 | { 23 | return (palStatus_t)mock().actualCall("pal_osMutexCreate") 24 | .withPointerParameter("mutexID", (void *)mutexID) 25 | .returnIntValue(); 26 | } 27 | 28 | palStatus_t pal_osMutexWait(palMutexID_t mutexID, uint32_t millisec) 29 | { 30 | return (palStatus_t)mock().actualCall("pal_osMutexWait") 31 | .withUnsignedLongIntParameter("mutexID", mutexID) 32 | .withUnsignedIntParameter("millisec", millisec) 33 | .returnIntValue(); 34 | } 35 | 36 | palStatus_t pal_osMutexRelease(palMutexID_t mutexID) 37 | { 38 | return (palStatus_t)mock().actualCall("pal_osMutexRelease") 39 | .withUnsignedLongIntParameter("mutexID", mutexID) 40 | .returnIntValue(); 41 | } 42 | -------------------------------------------------------------------------------- /test/pt-client-2/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file (GLOB SOURCES ./*.cpp ../../common/edge_trace.c) 2 | 3 | enable_language(C) 4 | enable_language(CXX) 5 | 6 | set (TEST_DATA_DIR ${ROOT_HOME}/test/pt-client-2/data) 7 | add_definitions(-DTEST_DATA_DIR="${TEST_DATA_DIR}") 8 | 9 | add_executable (pt-client-2-test ${SOURCES}) 10 | 11 | include_directories (../cpputest-custom-types ../libwebsocket-mock) 12 | target_include_directories (pt-client-2-test PUBLIC ${CPPUTEST_HOME}/include) 13 | target_include_directories (pt-client-2-test PUBLIC ${ROOT_HOME}/test/test-lib) 14 | 15 | target_link_libraries (pt-client-2-test nanostack edge-mutex-mock pt-client-2 16 | edge-apr-base64 edge-default-message-id-generator pt-api-error-codes 17 | edge-websocket-common-mock edge-msg-api-common-mock edge-mutex-helper 18 | libwebsocket-mock-minimal-lib libevent-mock-lib CppUTest CppUTestExt pthread) 19 | -------------------------------------------------------------------------------- /test/pt-client-2/data/write_from_edge_core_test.json: -------------------------------------------------------------------------------- 1 | { 2 | "jsonrpc": "2.0", 3 | "id": "1234567890", 4 | "method": "write", 5 | "params": { 6 | "operation": 2, 7 | "uri": { 8 | "deviceId": "device-id-1", 9 | "objectId": 3306, 10 | "objectInstanceId": 0, 11 | "resourceId": 5700 12 | }, 13 | "value": "QCg9cKPXCj0=" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /test/pt-client-2/pt-client-2/client_send_receive_helper.h: -------------------------------------------------------------------------------- 1 | #ifndef CLIENT_SEND_RECEIVE_HELPER_H 2 | #define CLIENT_SEND_RECEIVE_HELPER_H 3 | extern "C" { 4 | #include "pt-client-2/pt_common_api.h" 5 | #include "common/default_message_id_generator.h" 6 | #include "pt-client-2/pt_api_internal.h" 7 | } 8 | #include "cpputest-custom-types/value_pointer.h" 9 | #include 10 | 11 | extern connection_id_t active_connection_id; 12 | extern connection_t *active_connection; 13 | extern int32_t rpc_id_counter; 14 | char *test_msg_generate_id(); 15 | void reset_rpc_id_counter(); 16 | void process_event_loop_send_message(bool connection_found); 17 | void process_event_loop_send_response(); 18 | ValuePointer *expect_outgoing_data_frame(const char *data); 19 | int test_write_function(struct connection *connection, char *data, size_t len); 20 | void receive_incoming_data_frame_expectations(); 21 | void find_client_device_expectations(); 22 | void receive_incoming_data_frame(connection_t *active_connection, const char *data); 23 | void expect_msg_api_message(); 24 | void expect_msg_api_message_sending_fails(); 25 | void process_event_loop_send_message(bool connection_found); 26 | connection_id_t create_client_connection(); 27 | void destroy_connection(connection_t *connection); 28 | pt_client_t *destroy_active_connection(); 29 | void destroy_client(pt_client_t *client); 30 | void free_client_and_connection(connection_id_t connection_id); 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /test/pt-client-2/pt-client-2/ipso_enums.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 ARM Limited. All rights reserved. 3 | * SPDX-License-Identifier: Apache-2.0 4 | * Licensed under the Apache License, Version 2.0 (the License); you may 5 | * not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef IPSO_ENUMS_H 18 | #define IPSO_ENUMS_H 19 | 20 | enum IPSO_OBJECTS { 21 | DIGITAL_OUTPUT = 3201, 22 | TEMPERATURE_SENSOR = 3303, 23 | HUMIDITY_SENSOR = 3304, 24 | CONCENTRATION_SENSOR = 3325, 25 | SET_POINT = 3308, 26 | FIRMWARE_UPDATE = 5 27 | }; 28 | 29 | enum IPSO_RESOURCES { 30 | MIN_MEASURED_VALUE = 5601, 31 | MAX_MEASURED_VALUE = 5602, 32 | RESET_MIN_MAX_MEASURED_VALUES = 5605, 33 | SENSOR_VALUE = 5700, 34 | SENSOR_UNITS = 5701, 35 | SENSOR_TYPE = 5751, 36 | ON_OFF_VALUE = 5850, 37 | SET_POINT_VALUE = 5900 38 | }; 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /test/pt-client-2/pt-client-2/pt_client_helper.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef TEST_PT_CLIENT_HELPER_H 3 | #define TEST_PT_CLIENT_HELPER_H 4 | 5 | #include "pt-client-2/pt_common_api.h" 6 | #include "pt-client-2/pt_client_api.h" 7 | 8 | pt_client_t *create_client(protocol_translator_callbacks_t *callbacks); 9 | 10 | /* Helper callbacks */ 11 | void initialize_callbacks(protocol_translator_callbacks_t *callbacks); 12 | void test_connection_ready_cb(connection_id_t connection_id, const char *name, void *userdata); 13 | void test_connection_shutdown_cb(connection_id_t connection_id, void *userdata); 14 | void test_success_handler(void *userdata); 15 | void test_failure_handler(void *userdata); 16 | void test_disconnected_cb(connection_id_t connection_id, void *userdata); 17 | void test_certificate_renewal_notifier_cb(const connection_id_t connection_id, 18 | const char *name, 19 | int32_t initiator, 20 | int32_t status, 21 | const char *description, 22 | void *userdata); 23 | pt_status_t test_device_certificate_renewal_request_handler(const connection_id_t connection_id, 24 | const char *device_id, 25 | const char *name, 26 | void *userdata); 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /test/pt-client-2/test_main.cpp: -------------------------------------------------------------------------------- 1 | #include "CppUTest/CommandLineTestRunner.h" 2 | #include 3 | #include 4 | #include 5 | #include "cpputest-custom-types/my_json_frame.h" 6 | #include "cpputest-custom-types/value_pointer.h" 7 | #include "mbed-trace/mbed_trace.h" 8 | #include "test-lib/msg_api_mocks.h" 9 | extern "C" { 10 | #include "edge-rpc/rpc.h" 11 | } 12 | 13 | int main(int args, char** argv) 14 | { 15 | MockSupportPlugin mock_plugin; 16 | MyJsonFrameCopier json_frame_copier; 17 | ValuePointerComparator value_pointer_comparator; 18 | ValuePointerCopier value_pointer_copier; 19 | 20 | mock_plugin.installCopier("MyJsonFrame", json_frame_copier); 21 | mock_plugin.installComparator("ValuePointer", value_pointer_comparator); 22 | mock_plugin.installCopier("ValuePointer", value_pointer_copier); 23 | 24 | TestRegistry::getCurrentRegistry()->installPlugin(&mock_plugin); 25 | 26 | // Clean the memory inside the mock (otherwise you will see memory leaks in the first testcase) 27 | mock().clear(); 28 | mbed_trace_init(); 29 | mock().expectOneCall("edge_mutex_init") 30 | .withIntParameter("type", PTHREAD_MUTEX_ERRORCHECK) 31 | .withPointerParameter("mutex", &rpc_mutex) 32 | .andReturnValue(0); 33 | rpc_init(); 34 | mock_msg_api_messages_init(); 35 | 36 | int result = RUN_ALL_TESTS(args, argv); 37 | 38 | mbed_trace_free(); 39 | 40 | return result; 41 | } 42 | -------------------------------------------------------------------------------- /test/pt-client-2/test_pt_device_object.cpp: -------------------------------------------------------------------------------- 1 | #include "CppUTest/TestHarness.h" 2 | #include "CppUTestExt/MockSupport.h" 3 | 4 | #include 5 | extern "C" { 6 | #include "pt-client-2/pt_api.h" 7 | #include "pt-client-2/pt_device_object.h" 8 | } 9 | 10 | TEST_GROUP(pt_device_object) 11 | { 12 | void setup() {} 13 | 14 | void teardown() { 15 | } 16 | }; 17 | 18 | #if 0 19 | void test_callback(const pt_resource_t *resource, 20 | uint8_t operation, 21 | const uint8_t *value, 22 | const uint32_t size) 23 | { 24 | // no-op 25 | } 26 | 27 | TEST(pt_device_object, test_initialize_device_object) 28 | { 29 | pt_status_t status = ptdo_initialize_device_object(NULL, NULL); 30 | CHECK(PT_STATUS_INVALID_PARAMETERS == status); 31 | 32 | pt_device_t *device = pt_device_create("device", 3600, NONE, &status); 33 | CHECK(PT_STATUS_SUCCESS == status); 34 | status = ptdo_initialize_device_object(device, NULL); 35 | CHECK(PT_STATUS_INVALID_PARAMETERS == status); 36 | 37 | ptdo_device_object_data_t ptdo; 38 | ptdo.reboot_callback = NULL; 39 | ptdo.factory_reset_callback = test_callback; 40 | ptdo.reset_error_code_callback = test_callback; 41 | ptdo.manufacturer = strdup("test"); 42 | ptdo.model_number = strdup("1"); 43 | ptdo.serial_number = strdup("2"); 44 | ptdo.firmware_version = strdup("3"); 45 | ptdo.hardware_version = strdup("4"); 46 | ptdo.software_version = strdup("5"); 47 | ptdo.device_type = strdup("type"); 48 | 49 | status = ptdo_initialize_device_object(device, &ptdo); 50 | CHECK(PT_STATUS_INVALID_PARAMETERS == status); 51 | 52 | ptdo.reboot_callback = test_callback; 53 | status = ptdo_initialize_device_object(device, &ptdo); 54 | CHECK(PT_STATUS_SUCCESS == status); 55 | 56 | mock().checkExpectations(); 57 | pt_device_free(device); 58 | } 59 | #endif 60 | -------------------------------------------------------------------------------- /test/pt-client/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file (GLOB SOURCES ./*.cpp ../../common/edge_trace.c) 2 | 3 | enable_language(C) 4 | enable_language(CXX) 5 | 6 | set (TEST_DATA_DIR ${ROOT_HOME}/test/pt-client/data) 7 | add_definitions(-DTEST_DATA_DIR="${TEST_DATA_DIR}") 8 | 9 | add_executable (pt-client-test ${SOURCES}) 10 | 11 | include_directories (../cpputest-custom-types ../libwebsocket-mock) 12 | target_include_directories (pt-client-test PUBLIC ${CPPUTEST_HOME}/include) 13 | target_include_directories (pt-client-test PUBLIC ${ROOT_HOME}/test/test-lib) 14 | 15 | target_link_libraries (pt-client-test nanostack pt-client libwebsocket-mock-lib libevent-mock-lib test-lib CppUTest CppUTestExt pthread) 16 | -------------------------------------------------------------------------------- /test/pt-client/data/write_from_edge_core_test.json: -------------------------------------------------------------------------------- 1 | { 2 | "jsonrpc": "2.0", 3 | "id": "1234567890", 4 | "method": "write", 5 | "params": { 6 | "operation": 2, 7 | "uri": { 8 | "deviceId": "device-id-1", 9 | "objectId": 3306, 10 | "objectInstanceId": 0, 11 | "resourceId": 5700 12 | }, 13 | "value": "QCg9cKPXCj0=" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /test/pt-client/test_main.cpp: -------------------------------------------------------------------------------- 1 | #include "CppUTest/CommandLineTestRunner.h" 2 | #include 3 | #include 4 | #include 5 | #include "cpputest-custom-types/my_json_frame.h" 6 | #include "cpputest-custom-types/value_pointer.h" 7 | 8 | int main(int args, char** argv) 9 | { 10 | MockSupportPlugin mock_plugin; 11 | MyJsonFrameCopier json_frame_copier; 12 | ValuePointerComparator value_pointer_comparator; 13 | ValuePointerCopier value_pointer_copier; 14 | 15 | mock_plugin.installCopier("MyJsonFrame", json_frame_copier); 16 | mock_plugin.installComparator("ValuePointer", value_pointer_comparator); 17 | mock_plugin.installCopier("ValuePointer", value_pointer_copier); 18 | 19 | TestRegistry::getCurrentRegistry()->installPlugin(&mock_plugin); 20 | 21 | // Clean the memory inside the mock (otherwise you will see memory leaks in the first testcase) 22 | mock().clear(); 23 | 24 | return RUN_ALL_TESTS(args, argv); 25 | } 26 | -------------------------------------------------------------------------------- /test/test-lib/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file (GLOB SOURCES ./*.cpp ./*.c) 2 | file (GLOB EDGE_WEBSOCKET_COMMON_MOCK_SOURCES ./mock_edge_websocket_comm.cpp) 3 | file (GLOB EDGE_MSG_API_COMMON_MOCK_SOURCES ./mock_edge_msg_api.cpp) 4 | file (GLOB EDGE_MUTEX_MOCK_SOURCES ./mock_edge_mutex.cpp) 5 | file (GLOB EDGE_MUTEX_HELPER_SOURCES ./edge_mutex_helper.cpp) 6 | 7 | add_definitions(-DMBED_CONF_MBED_TRACE_ENABLE=1) 8 | 9 | include_directories (../cpputest-custom-types) 10 | 11 | add_library (test-lib ${SOURCES}) 12 | target_include_directories (test-lib PUBLIC ${CPPUTEST_HOME}/include) 13 | 14 | add_library (edge-websocket-common-mock ${EDGE_WEBSOCKET_COMMON_MOCK_SOURCES}) 15 | target_include_directories (edge-websocket-common-mock PUBLIC ${CPPUTEST_HOME}/include) 16 | 17 | add_library (edge-msg-api-common-mock ${EDGE_MSG_API_COMMON_MOCK_SOURCES}) 18 | target_include_directories (edge-msg-api-common-mock PUBLIC ${CPPUTEST_HOME}/include) 19 | 20 | add_library (edge-mutex-mock ${EDGE_MUTEX_MOCK_SOURCES}) 21 | target_include_directories (edge-mutex-mock PUBLIC ${CPPUTEST_HOME}/include) 22 | 23 | add_library (edge-mutex-helper ${EDGE_MUTEX_HELPER_SOURCES}) 24 | target_include_directories (edge-mutex-helper PUBLIC ${CPPUTEST_HOME}/include) 25 | 26 | -------------------------------------------------------------------------------- /test/test-lib/edge_mutex_helper.cpp: -------------------------------------------------------------------------------- 1 | #include "CppUTest/TestHarness.h" 2 | #include "CppUTestExt/MockSupport.h" 3 | #include "test-lib/mutex_helper.h" 4 | 5 | void mh_expect_mutex_init(edge_mutex_t *mutex, int32_t type) 6 | { 7 | mock().expectOneCall("edge_mutex_init") 8 | .withPointerParameter("mutex", mutex) 9 | .withIntParameter("type", type) 10 | .andReturnValue(0); 11 | } 12 | 13 | void mh_expect_mutexing(edge_mutex_t *mutex) 14 | { 15 | mh_expect_mutex_lock(mutex); 16 | mh_expect_mutex_unlock(mutex); 17 | } 18 | 19 | void mh_expect_mutex_lock(edge_mutex_t *mutex) 20 | { 21 | mock().expectOneCall("edge_mutex_lock").withPointerParameter("mutex", mutex).andReturnValue(0); 22 | } 23 | 24 | void mh_expect_mutex_unlock(edge_mutex_t *mutex) 25 | { 26 | mock().expectOneCall("edge_mutex_unlock").withPointerParameter("mutex", mutex).andReturnValue(0); 27 | } 28 | 29 | -------------------------------------------------------------------------------- /test/test-lib/json_helper.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ---------------------------------------------------------------------------- 3 | * Copyright 2018 ARM Ltd. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * ---------------------------------------------------------------------------- 19 | */ 20 | 21 | #include "CppUTest/TestHarness.h" 22 | #include "CppUTestExt/MockSupport.h" 23 | #include 24 | extern "C" { 25 | #include "test-lib/json_helper.h" 26 | #define JSON_BUFFER_MAX_SIZE 4096 27 | 28 | 29 | json_t* load_json_params(const char *filepath) 30 | { 31 | FILE *fh; 32 | size_t json_buffer_size = 0; 33 | char json_buffer[JSON_BUFFER_MAX_SIZE]; 34 | fh = fopen(filepath, "r"); 35 | json_buffer_size = fread(json_buffer, sizeof(char), JSON_BUFFER_MAX_SIZE, fh); 36 | fclose(fh); 37 | if (json_buffer_size > JSON_BUFFER_MAX_SIZE) { 38 | FAIL("JSON buffer not big enough!"); 39 | } 40 | // NULL terminate json buffer 41 | json_buffer[json_buffer_size] = 0; 42 | // Load json buffer into structure 43 | json_error_t json_error; 44 | json_t *params = NULL; 45 | params = json_loads(json_buffer, 0, &json_error); 46 | if (params == NULL) { 47 | printf("\r\n%s:%d, col %d, pos %d\r\n", json_error.source, json_error.line, json_error.column, json_error.position); 48 | printf("Loading json from file got error: %s", json_error.text); 49 | FAIL("Loading json failed!"); 50 | } 51 | return params; 52 | } 53 | 54 | } // extern "C" 55 | -------------------------------------------------------------------------------- /test/test-lib/mock_edge_io_lib.cpp: -------------------------------------------------------------------------------- 1 | #define TRACE_GROUP "edge_io" 2 | #include "CppUTestExt/MockSupport.h" 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #include "common/edge_io_lib.h" 7 | #endif 8 | 9 | bool edge_io_file_exists(const char *path) 10 | { 11 | return mock().actualCall("edge_io_file_exists").withStringParameter("path", path).returnBoolValue(); 12 | } 13 | 14 | bool edge_io_acquire_lock_for_socket(const char *path, int *lock_fd) 15 | { 16 | return mock() 17 | .actualCall("edge_io_acquire_lock_for_socket") 18 | .withStringParameter("path", path) 19 | .withOutputParameter("lock_fd", lock_fd) 20 | .returnBoolValue(); 21 | } 22 | 23 | bool edge_io_release_lock_for_socket(const char *path, int lock_fd) 24 | { 25 | return mock().actualCall("edge_io_release_lock_for_socket") 26 | .withStringParameter("path", path) 27 | .withIntParameter("lock_fd", lock_fd) 28 | .returnBoolValue(); 29 | } 30 | 31 | int edge_io_unlink(const char *path) 32 | { 33 | return mock().actualCall("edge_io_unlink").withStringParameter("path", path).returnIntValue(); 34 | } 35 | 36 | #ifdef __cplusplus 37 | } 38 | #endif 39 | -------------------------------------------------------------------------------- /test/test-lib/mock_edge_mutex.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ---------------------------------------------------------------------------- 3 | * Copyright 2018 ARM Ltd. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * ---------------------------------------------------------------------------- 19 | */ 20 | #include "CppUTestExt/MockSupport.h" 21 | extern "C" { 22 | #include "common/edge_mutex.h" 23 | 24 | /* 25 | * Edge mutexes are needed to 26 | * */ 27 | 28 | int32_t edge_mutex_init(edge_mutex_t *mutex, int32_t type) 29 | { 30 | return mock() 31 | .actualCall("edge_mutex_init") 32 | .withIntParameter("type", type) 33 | .withPointerParameter("mutex", (void *) mutex) 34 | .returnIntValue(); 35 | } 36 | 37 | int32_t edge_mutex_destroy(edge_mutex_t *mutex) 38 | { 39 | return mock().actualCall("edge_mutex_destroy").withPointerParameter("mutex", (void *) mutex).returnIntValue(); 40 | } 41 | 42 | int32_t edge_mutex_lock(edge_mutex_t *mutex) 43 | { 44 | return mock().actualCall("edge_mutex_lock").withPointerParameter("mutex", (void *) mutex).returnIntValue(); 45 | } 46 | 47 | int32_t edge_mutex_unlock(edge_mutex_t *mutex) 48 | { 49 | return mock().actualCall("edge_mutex_unlock").withPointerParameter("mutex", (void *) mutex).returnIntValue(); 50 | } 51 | } /* extern "C" */ 52 | -------------------------------------------------------------------------------- /test/test-lib/mock_edge_read.cpp: -------------------------------------------------------------------------------- 1 | 2 | #define TRACE_GROUP "rf" 3 | #include "CppUTestExt/MockSupport.h" 4 | 5 | #ifdef __cplusplus 6 | extern "C" { 7 | #include "common/read_file.h" 8 | #endif 9 | 10 | int edge_read_file(const char* filename, uint8_t** data, size_t *read) { 11 | return mock().actualCall("edge_read_file").returnIntValue(); 12 | } 13 | 14 | #ifdef __cplusplus 15 | } 16 | #endif 17 | -------------------------------------------------------------------------------- /test/test-lib/mock_evconnlistener.cpp: -------------------------------------------------------------------------------- 1 | #include "CppUTest/TestHarness.h" 2 | #include "CppUTestExt/MockSupport.h" 3 | extern "C" { 4 | #include 5 | #include 6 | #include "event2/listener.h" 7 | 8 | 9 | struct evconnlistener *evconnlistener_new_bind(struct event_base *base, evconnlistener_cb cb, 10 | void *ptr, unsigned flags, int backlog, const struct sockaddr *sa, int socklen) 11 | { 12 | return (struct evconnlistener *) mock().actualCall("evconnlistener_new_bind") 13 | .returnPointerValue(); 14 | } 15 | 16 | void evconnlistener_set_error_cb(struct evconnlistener *lev, evconnlistener_errorcb errorcb) 17 | { 18 | mock().actualCall("evconnlistener_set_error_cb"); 19 | } 20 | 21 | } /* extern "C" */ 22 | -------------------------------------------------------------------------------- /test/test-lib/mock_m2mtimer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 ARM Limited. All rights reserved. 3 | * SPDX-License-Identifier: Apache-2.0 4 | * Licensed under the Apache License, Version 2.0 (the License); you may 5 | * not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include "mock_m2mtimer.h" 17 | 18 | #include "CppUTestExt/MockSupport.h" 19 | #include 20 | 21 | bool m2mtimer_stub::bool_value; 22 | bool m2mtimer_stub::total_bool_value; 23 | bool m2mtimer_stub::enable_mock; 24 | 25 | void m2mtimer_stub::clear() 26 | { 27 | bool_value = false; 28 | total_bool_value = false; 29 | enable_mock = false; 30 | } 31 | 32 | M2MTimer::M2MTimer(M2MTimerObserver& observer) 33 | : _observer(observer) 34 | { 35 | } 36 | 37 | M2MTimer::~M2MTimer() 38 | { 39 | } 40 | 41 | void M2MTimer::start_timer(uint64_t /*interval*/, 42 | M2MTimerObserver::Type /*type*/, 43 | bool /*single_shot*/) 44 | { 45 | if (m2mtimer_stub::enable_mock) { 46 | mock().actualCall("start_timer").onObject(this); 47 | } 48 | } 49 | 50 | void M2MTimer::start_dtls_timer(uint64_t , uint64_t , M2MTimerObserver::Type ) 51 | { 52 | if (m2mtimer_stub::enable_mock) { 53 | mock().actualCall("start_dtls_timer").onObject(this); 54 | } 55 | } 56 | 57 | void M2MTimer::stop_timer() 58 | { 59 | if (m2mtimer_stub::enable_mock) { 60 | mock().actualCall("stop_timer").onObject(this); 61 | } 62 | } 63 | 64 | 65 | bool M2MTimer::is_intermediate_interval_passed(){ 66 | return m2mtimer_stub::bool_value; 67 | } 68 | 69 | bool M2MTimer::is_total_interval_passed(){ 70 | return m2mtimer_stub::total_bool_value; 71 | } 72 | -------------------------------------------------------------------------------- /test/test-lib/mock_m2mtimer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 ARM Limited. All rights reserved. 3 | * SPDX-License-Identifier: Apache-2.0 4 | * Licensed under the Apache License, Version 2.0 (the License); you may 5 | * not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef M2M_TIMER_STUB_H 17 | #define M2M_TIMER_STUB_H 18 | 19 | #include "m2mtimer.h" 20 | 21 | //some internal test related stuff 22 | namespace m2mtimer_stub 23 | { 24 | extern bool bool_value; 25 | extern bool total_bool_value; 26 | extern bool enable_mock; 27 | void clear(); 28 | } 29 | 30 | #endif // M2M_TIMER_STUB_H 31 | 32 | -------------------------------------------------------------------------------- /test/test-lib/mock_rpc.cpp: -------------------------------------------------------------------------------- 1 | #include "CppUTestExt/MockSupport.h" 2 | #include "test-lib/rpc_mocks.h" 3 | #include "test-lib/json_pointer.h" 4 | #include "test-lib/json_message_t_pointer.h" 5 | 6 | int rpc_write_func_mock(struct connection *connection, char *data, size_t size) 7 | { 8 | mock().actualCall("write_func") 9 | .withParameter("connection", connection) 10 | .withParameter("data", data) 11 | .withParameter("size", size); 12 | // This mocks the data writing to output socket 13 | // must free the data here. 14 | free(data); 15 | return 0; 16 | } 17 | 18 | void rpc_test_handler(json_t *request, json_t *params, json_t *result, void *userdata) 19 | { 20 | JsonPointer request_p = JsonPointer(request); 21 | JsonPointer params_p = JsonPointer(params); 22 | JsonPointer result_p = JsonPointer(result); 23 | 24 | json_message_t *userdata_s = (json_message_t*) userdata; 25 | JsonMessageTPointer userdata_p = JsonMessageTPointer(userdata_s->data, 26 | userdata_s->len, 27 | userdata_s->connection); 28 | 29 | mock().actualCall("rpc_test_handler") 30 | .withParameterOfType("JsonPointer", "json_request", &request_p) 31 | .withParameterOfType("JsonPointer", "json_params", ¶ms_p) 32 | .withOutputParameterOfType("JsonPointer", "result", &result_p) 33 | .withParameterOfType("JsonMessageTPointer", "userdata", &userdata_p); 34 | } 35 | 36 | int rpc_test_handler_success(json_t *request, json_t *params, json_t **result, void *userdata) 37 | { 38 | *result = json_object(); 39 | json_object_set_new(*result, "test-result", json_string("good")); 40 | rpc_test_handler(request, params, *result, userdata); 41 | return 0; 42 | } 43 | 44 | int rpc_test_handler_error(json_t *request, json_t *params, json_t **result, void *userdata) 45 | { 46 | *result = json_object(); 47 | json_object_set_new(*result, "code", json_integer(-100)); 48 | json_object_set_new(*result, "message", json_string("test-error")); 49 | rpc_test_handler(request, params, *result, userdata); 50 | return 1; 51 | } 52 | -------------------------------------------------------------------------------- /test/test-lib/msg_api_test_helper.cpp: -------------------------------------------------------------------------------- 1 | #include "CppUTest/TestHarness.h" 2 | #include "CppUTestExt/MockSupport.h" 3 | #include "test-lib/msg_api_test_helper.h" 4 | extern "C" { 5 | #include "common/msg_api.h" 6 | } 7 | 8 | static void expect_event_message_common(struct event_base *base, 9 | event_loop_callback_t callback, 10 | bool expect_get_base, 11 | bool succeeds) 12 | { 13 | int event_assign_ret_val = 0; 14 | if (expect_get_base) { 15 | mock().expectOneCall("edge_server_get_base").andReturnValue(base); 16 | } 17 | mock().expectOneCall("event_get_struct_event_size"); 18 | if (!succeeds) { 19 | event_assign_ret_val = -1; 20 | } 21 | mock().expectOneCall("event_assign") 22 | .withPointerParameter("base", (void *) base) 23 | .withIntParameter("fd", -1) 24 | .withIntParameter("events", 0) 25 | .withPointerParameter("cb", (void *) event_cb) 26 | .andReturnValue(event_assign_ret_val); 27 | if (succeeds) { 28 | mock().expectOneCall("event_add").andReturnValue(0); 29 | mock().expectOneCall("event_active"); 30 | } 31 | } 32 | 33 | void expect_event_message(struct event_base *base, event_loop_callback_t callback, bool succeeds) 34 | { 35 | expect_event_message_common(base, callback, true, succeeds); 36 | } 37 | 38 | void expect_event_message_without_get_base(struct event_base *base, event_loop_callback_t callback, bool succeeds) 39 | { 40 | expect_event_message_common(base, callback, false, succeeds); 41 | } 42 | 43 | -------------------------------------------------------------------------------- /test/test-lib/test-lib/evbase_mock.h: -------------------------------------------------------------------------------- 1 | #ifndef EVBASE_MOCK_H_ 2 | #define EVBASE_MOCK_H_ 3 | 4 | #include 5 | #include 6 | /* Implementation of the libevent evbase internal structures */ 7 | struct event_base { 8 | pthread_mutex_t event_loop_simulation_lock; 9 | pthread_mutex_t wait_lock; 10 | pthread_mutex_t event_lock; 11 | pthread_mutex_t interrupt_lock; 12 | struct event *assigned_event; 13 | bool event_add_releases_event_lock; 14 | bool event_loop_wait_simulation; 15 | bool event_loop_started; 16 | }; 17 | 18 | struct bufferevent { 19 | struct event_base *base; 20 | struct connection *connection; 21 | }; 22 | 23 | struct evconnlistener { 24 | bool dummy; 25 | }; 26 | 27 | struct event { 28 | event_callback_fn cb; 29 | void *cb_arg; 30 | int fd; 31 | int events; 32 | struct event_base *base; 33 | }; 34 | 35 | struct event_base *evbase_mock_new(); 36 | void evbase_mock_delete(struct event_base *base); 37 | void evbase_mock_call_assigned_event_cb(struct event_base *base, bool lock_mutex); 38 | void evbase_mock_setup_event_loop_wait(struct event_base *base); 39 | void evbase_mock_acquire_event_loop_lock(struct event_base *base); 40 | void evbase_mock_release_event_loop_lock_and_block_interrupt(struct event_base *base); 41 | void evbase_mock_release_interrupt_thread(struct event_base *base); 42 | 43 | void evbase_mock_wait_until_event_loop(struct event_base *base); 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /test/test-lib/test-lib/evbuf_mock.h: -------------------------------------------------------------------------------- 1 | /* Implementation of the libevent internal structures */ 2 | #ifndef EVBUF_MOCK_H_ 3 | #define EVBUF_MOCK_H_ 4 | #include 5 | 6 | struct evbuffer { 7 | bool dummy; 8 | }; 9 | #endif 10 | -------------------------------------------------------------------------------- /test/test-lib/test-lib/evhttp_mock.h: -------------------------------------------------------------------------------- 1 | /* Implementation of the libevent internal structures */ 2 | #ifndef EVHTTP_MOCK_H_ 3 | #define EVHTTP_MOCK_H_ 4 | #include 5 | 6 | struct evhttp_request { 7 | enum evhttp_cmd_type command; 8 | }; 9 | 10 | struct evhttp { 11 | bool dummy; 12 | }; 13 | 14 | struct evhttp_bound_socket { 15 | bool dummy; 16 | }; 17 | 18 | struct evhttp_uri { 19 | bool dummy; 20 | }; 21 | #endif 22 | -------------------------------------------------------------------------------- /test/test-lib/test-lib/json_helper.h: -------------------------------------------------------------------------------- 1 | #ifndef JSON_HELPER_H 2 | #define JSON_HELPER_H 3 | 4 | #include 5 | 6 | json_t* load_json_params(const char *filepath); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /test/test-lib/test-lib/msg_api_mocks.h: -------------------------------------------------------------------------------- 1 | #ifndef MSG_API_MOCKS_H 2 | #define MSG_API_MOCKS_H 3 | 4 | #include "ns_list.h" 5 | 6 | typedef void (*event_loop_callback_t)(void *data); 7 | 8 | typedef struct { 9 | ns_list_link_t link; 10 | void *data; 11 | event_loop_callback_t callback; 12 | int32_t timeout_in_ms; 13 | } event_loop_message_t; 14 | 15 | // FIFO event queue which can be used to check the event messages 16 | typedef NS_LIST_HEAD(event_loop_message_t, link) event_loop_messages_t; 17 | 18 | void mock_msg_api_messages_init(); 19 | void mock_msg_api_wipeout_messages(); 20 | int32_t mock_msg_api_messages_in_queue(); 21 | event_loop_message_t *mock_msg_api_pop_message(); 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /test/test-lib/test-lib/msg_api_test_helper.h: -------------------------------------------------------------------------------- 1 | #ifndef MSG_API_TEST_HELPER_H 2 | #define MSG_API_TEST_HELPER_H 3 | extern "C" { 4 | #include "common/msg_api.h" 5 | void event_cb(evutil_socket_t fd, short what, void *arg); 6 | } 7 | 8 | void expect_event_message(struct event_base *base, event_loop_callback_t callback, bool succeeds); 9 | void expect_event_message_without_get_base(struct event_base *base, event_loop_callback_t callback, bool succeeds); 10 | 11 | #endif 12 | 13 | 14 | -------------------------------------------------------------------------------- /test/test-lib/test-lib/mutex_helper.h: -------------------------------------------------------------------------------- 1 | #ifndef EDGE_MUTEX_HELPER_H 2 | #define EDGE_MUTEX_HELPER_H 3 | 4 | extern "C" { 5 | #include "common/edge_mutex.h" 6 | }; 7 | 8 | void mh_expect_mutex_init(edge_mutex_t *mutex, int32_t type); 9 | void mh_expect_mutexing(edge_mutex_t *mutex); 10 | void mh_expect_mutex_lock(edge_mutex_t *mutex); 11 | void mh_expect_mutex_unlock(edge_mutex_t *mutex); 12 | 13 | #endif 14 | 15 | -------------------------------------------------------------------------------- /test/test-lib/test-lib/rpc_mocks.h: -------------------------------------------------------------------------------- 1 | #ifndef TEST_TEST_LIB_TEST_LIB_RPC_MOCKS_H_ 2 | #define TEST_TEST_LIB_TEST_LIB_RPC_MOCKS_H_ 3 | 4 | #include 5 | #include 6 | 7 | int rpc_write_func_mock(struct connection *connection, char *data, size_t size); 8 | int rpc_test_handler_success(json_t *request, json_t *params, json_t **result, void *userdata); 9 | int rpc_test_handler_error(json_t *request, json_t *params, json_t **result, void *userdata); 10 | 11 | #endif // TEST_TEST_LIB_TEST_LIB_RPC_MOCKS_H_ 12 | -------------------------------------------------------------------------------- /test/test-lib/test-lib/server_test.h: -------------------------------------------------------------------------------- 1 | #ifndef SERVER_TEST_H 2 | #define SERVER_TEST_H 3 | 4 | #include 5 | 6 | struct connection *server_test_establish_connection(); 7 | void server_test_free_established_connection(struct connection *connection); 8 | void server_test_call_receive_cb(struct connection *connection, void *data, size_t len); 9 | void server_test_connection_closed(struct connection *connection); 10 | int server_test_connection_filter_cb(const char *uri); 11 | #endif 12 | -------------------------------------------------------------------------------- /test/test-lib/test-lib/test_edge_server.h: -------------------------------------------------------------------------------- 1 | #ifndef TEST_EDGE_SERVER_H 2 | #define TEST_EDGE_SERVER_H 3 | 4 | #include "cpputest-custom-types/value_pointer.h" 5 | extern "C" { 6 | #include 7 | #include 8 | } 9 | 10 | typedef enum { 11 | MAIN_TEST_INITIALIZES_SERVER_NO, 12 | MAIN_TEST_INITIALIZES_SERVER_YES 13 | } main_test_server_init_param_e; 14 | 15 | typedef enum { 16 | MAIN_TEST_EVENT_BASE_CREATION_FAILS, 17 | MAIN_TEST_EVENT_BASE_CREATION_SUCCEEDS 18 | } main_test_event_base_creation_param_e; 19 | 20 | typedef enum { 21 | MAIN_TEST_EXPECT_RESET_STORAGE_NO = false, 22 | MAIN_TEST_EXPECT_RESET_STORAGE_YES = true 23 | } main_test_expected_reset_storage_e; 24 | 25 | typedef struct main_test_params { 26 | struct evconnlistener *listener; 27 | struct evhttp *http; 28 | struct evhttp_bound_socket *http_socket; 29 | struct event_base *base; 30 | struct event *timer_event; // timer for cleaning out timed out JSON RPC requests 31 | struct lws_context_creation_info *info; 32 | int event_dispatch_return_value; 33 | ValuePointer *null_value_pointer; 34 | pthread_t *tester_thread; 35 | bool wait_in_event_loop; 36 | bool removing_old_socket_fails; 37 | bool old_socket_exists; 38 | bool acquiring_socket_lock_fails; 39 | } main_test_params_t; 40 | 41 | main_test_params_t *edge_server_alloc_main_test_params( 42 | main_test_event_base_creation_param_e event_base_creation_succeeds); 43 | void edge_server_delete_main_test_params(main_test_params_t *params); 44 | void edge_server_main_expectations_until_event_loop(int argc, char **argv, main_test_params_t *params); 45 | void edge_server_main_expectations_after_event_loop(main_test_params_t *params); 46 | 47 | #endif 48 | 49 | -------------------------------------------------------------------------------- /test/test-lib/test-lib/test_http_server.h: -------------------------------------------------------------------------------- 1 | #ifndef TEST_HTTP_SERVER_H 2 | #define TEST_HTTP_SERVER_H 3 | 4 | extern "C" { 5 | #include 6 | #include 7 | } 8 | 9 | void test_http_server_init_succeeds_expectations(struct evhttp *http, 10 | struct evhttp_bound_socket *socket, 11 | const char *address, 12 | int32_t port); 13 | #endif 14 | -------------------------------------------------------------------------------- /test/test-lib/testfactory.h: -------------------------------------------------------------------------------- 1 | #ifndef TESTFACTORY_H 2 | #define TESTFACTORY_H 3 | 4 | #include 5 | #include 6 | 7 | #include "CppUTest/TestHarness.h" 8 | #include "CppUTestExt/MockSupport.h" 9 | 10 | #include "edge-client/edge_client.h" 11 | #include "mbed-client/m2mendpoint.h" 12 | #include "mbed-client/m2mobject.h" 13 | #include "pal.h" 14 | 15 | 16 | class TestFactory { 17 | public: 18 | static M2MEndpoint *create_endpoint(String &name, char *path); 19 | static M2MObject *create_object(String &name, char *path, bool external_blockwise_store); 20 | static M2MObjectInstance *create_object_instance(M2MObject &parent); 21 | static M2MResource *create_resource(M2MObjectInstance &parent, String &resource_name, char *path, bool multiple_instance, bool external_blockwise_store); 22 | static void delete_resource(M2MResource *resource) { delete resource; } 23 | static void delete_object_instance(M2MObjectInstance *object_instance) { delete object_instance; } 24 | static void delete_object(M2MObject *object) { delete object; } 25 | }; 26 | 27 | #endif 28 | 29 | 30 | --------------------------------------------------------------------------------