diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/CHANGELOG.md b/features/FEATURE_COMMON_PAL/mbed-client-c/CHANGELOG.md deleted file mode 100644 index 0a38e2d05c..0000000000 --- a/features/FEATURE_COMMON_PAL/mbed-client-c/CHANGELOG.md +++ /dev/null @@ -1,691 +0,0 @@ -# Change Log - -## [v3.0.4](https://github.com/ARMmbed/mbed-client-c/releases/tag/v3.0.4) (23-dec-2016) -[Full Changelog](https://github.com/ARMmbed/mbed-client-c/compare/v3.0.2...v3.0.4) - -**New feature** - -- CoAP message ID randomization -- Initial memory optimized API added behind compile time flag - -**Closed issues:** - -- IOTCLT-1207 - sn_coap_builder_options_build_add_uint_option function produce wrong option value -- IOTCLT-828 / ARMmbed/mbed-client-c#59 - Random CoAP message ID - -**Merged pull requests:** - -commit 8d247d6baf16d7171dbc1d0e61383aeae59f9f20 (HEAD -> release-3.0.4, tag: v3.0.4, origin/release-3.0.4) -Author: Jaakko Kukkohovi -Date: Fri Dec 23 13:48:23 2016 +0200 - - version v3.0.4 - -commit 6f6d604dc9984dbae4bd183c4151be986de81a1b (origin/mem_opt_part_2, mem_opt_part_2) -Author: Tero Jääskö -Date: Thu Dec 22 20:12:48 2016 +0200 - - Make the code compile two different versions of the API - - If one defines MBED_CLIENT_C_NEW_API, the new versions of - sn_grs and sn_nsdl are selected and old code will continue to work - as is if the define is not there. - -commit 947bec9fd2a997a1f29633fa83f67fde40c16e0f -Author: Tero Jääskö -Date: Thu Dec 22 19:12:30 2016 +0200 - - Copy the changed files from memory_optimizations -branch to new name - -commit a3de842af0b19c8760482cc451b7a2e8520547fb -Author: Tero Jääskö -Date: Thu Dec 22 18:46:13 2016 +0200 - - Copy the sn_nsdl and sn_grs files to fork the API via define - -commit d6a4ece6c305a14030a97e340566893560c00496 (origin/master, origin/HEAD, master) -Author: Jaakko Kukkohovi -Date: Fri Dec 9 17:55:17 2016 +0200 - - Add application definable context to nsdl handle (#96) - - Added application definable context field to nsdl handle. This is useful for example when interfacing with c++ objects where a pointer to object is set as the context, and in the callback functions the context pointer can be used to call methods for the correct instance of the c++ object. - -commit e502b67a90ff96e52b98828e1e0c93d40071f171 -Author: simosillankorva -Date: Mon Nov 21 12:02:23 2016 +0200 - - Changed sn_coap_protocol.c to use randLIB for random message ID. (#91) - - * Changed sn_coap_protocol.c to use randLIB for random message ID. randLIB now needed to build the coap library. - - * Added randLIB dependency to module.json - - * Added check for message_id==0 when randomizing, as we dont want to change the api for sn_nsdl.c, that uses it for error cases when sending some messages. - - * Added randLiIB include path to unit tests. - - * Added randLIB_stub for sn_coap_protocol unit test. - -commit 4cdc3570f3a4dad1cef9787755718fec6917f8f2 -Merge: cfe1e4e 2f7e733 -Author: Antti Yli-Tokola -Date: Wed Nov 16 10:46:52 2016 +0200 - - Merge pull request #95 from ARMmbed/anttiylitokola-patch-1 - - Disable message duplication - -commit 2f7e7333799082b59346173c8c12fc71fb93ccde -Author: Antti Yli-Tokola -Date: Wed Nov 16 09:45:38 2016 +0200 - - Disable message duplication - - Message duplication is currently missing some features and it doesn't work reliable yet. Can be enabled again once "IOTCLT-1038 - CoAP duplicate message detection missing features" is implemented. - -commit cfe1e4e8c464a828eb6dfd4550b2f82831b0f489 (origin/memory_optimizations_base) -Author: Antti Kauppila -Date: Thu Nov 10 15:20:47 2016 +0200 - - Update sn_coap_builder.c - - 1 compilation warning fixed - -commit e9c5e25492914bcd583e74ae14f71c9c8465398c -Merge: fc1f9eb c0bb893 -Author: Antti Yli-Tokola -Date: Wed Nov 9 09:41:00 2016 +0200 - - Merge pull request #92 from ARMmbed/iotclt_1207 - - Fix CoAP option building - -commit c0bb8936b9d44cda49611bfee9ae55969b717811 -Author: Antti Yli-Tokola -Date: Wed Nov 9 08:20:29 2016 +0200 - - Replace unnecessary started flag with len variable. - -commit 1deac48ddb51a9e9d85ecb682b9b82c4072b5c44 -Author: Antti Yli-Tokola -Date: Tue Nov 8 14:20:34 2016 +0200 - - Fix CoAP option building - -commit fc1f9eb790d08306ee435dd3a8452cfc82d7d740 -Merge: 59be2f1 316a9db -Author: Yogesh Pande -Date: Thu Nov 3 16:35:47 2016 +0200 - - Merge pull request #90 from ARMmbed/valgrind_unittest_fixes - - Valgrind unittest fixes - -commit 316a9dbb11cf2b842255655501c30a5d0d040ca7 -Author: Tero Jääskö -Date: Tue Oct 25 19:24:57 2016 +0300 - - sn_coap_builder_unit_tests: fix 1976 valgrind errors - - Fix 1976 valgrind errors for uninitialized memory accesses by - initializing the buffers before trying to parse them. - - One example of error being fixed: - ---8<---8<---8<--- - ==8405== - ==8405== Conditional jump or move depends on uninitialised value(s) - ==8405== at 0x40EA6E: sn_coap_builder_options_get_option_part_count (sn_coap_builder.c:926) - ==8405== by 0x40E7CF: sn_coap_builder_options_calc_option_size (sn_coap_builder.c:834) - ==8405== by 0x40CDA2: sn_coap_builder_calc_needed_packet_data_size_2 (sn_coap_builder.c:238) - ==8405== by 0x40C8C5: sn_coap_builder_calc_needed_packet_data_size (sn_coap_builder.c:147) - ==8405== by 0x404609: TEST_libCoap_builder_sn_coap_builder_calc_needed_packet_data_size_Test::testBody() (libCoap_builder_test.cpp:339) - ==8405== by 0x418660: PlatformSpecificSetJmp (in /home/tero/work/mbed-github/mbed-client-c/test/nsdl-c/unittest/sn_coap_builder/sn_coap_builder_unit_tests) - ==8405== by 0x416C24: Utest::run() (in /home/tero/work/mbed-github/mbed-client-c/test/nsdl-c/unittest/sn_coap_builder/sn_coap_builder_unit_tests) - ==8405== by 0x4172DE: UtestShell::runOneTest(TestPlugin*, TestResult&) (in /home/tero/work/mbed-github/mbed-client-c/test/nsdl-c/unittest/sn_coap_builder/sn_coap_builder_unit_tests) - ==8405== by 0x418660: PlatformSpecificSetJmp (in /home/tero/work/mbed-github/mbed-client-c/test/nsdl-c/unittest/sn_coap_builder/sn_coap_builder_unit_tests) - ==8405== by 0x416B3B: UtestShell::runOneTestWithPlugins(TestPlugin*, TestResult&) (in /home/tero/work/mbed-github/mbed-client-c/test/nsdl-c/unittest/sn_coap_builder/sn_coap_builder_unit_tests) - ==8405== by 0x419F9D: TestRegistry::runAllTests(TestResult&) (in /home/tero/work/mbed-github/mbed-client-c/test/nsdl-c/unittest/sn_coap_builder/sn_coap_builder_unit_tests) - ==8405== by 0x4107D7: CommandLineTestRunner::runAllTests() (in /home/tero/work/mbed-github/mbed-client-c/test/nsdl-c/unittest/sn_coap_builder/sn_coap_builder_unit_tests) - -commit 7fe1b032d117aec24bacf929bff72aee2d4b1000 -Author: Tero Jääskö -Date: Tue Oct 25 17:32:26 2016 +0300 - - sn_nsdl_unit_tests: fix 23 valgrind errors - - Fix 23 valgrind error for uninitialized memory accesses. - - One example of warning being fixed: - ---8<---8<--- - ==3916== - ==3916== Conditional jump or move depends on uninitialised value(s) - ==3916== at 0x418976: sn_coap_parser_release_allocated_coap_msg_mem (sn_coap_parser_stub.c:42) - ==3916== by 0x420E3A: sn_nsdl_release_allocated_coap_msg_mem (sn_nsdl.c:2535) - ==3916== by 0x417A92: test_sn_nsdl_release_allocated_coap_msg_mem (test_sn_nsdl.c:2885) - ==3916== by 0x402E85: TEST_sn_nsdl_test_sn_nsdl_release_allocated_coap_msg_mem_Test::testBody() (sn_nsdltest.cpp:166) - ==3916== by 0x42A8B0: PlatformSpecificSetJmp (in mbed-client-c/test/nsdl-c/unittest/sn_nsdl/sn_nsdl_unit_tests) - ==3916== by 0x428E74: Utest::run() (in mbed-client-c/test/nsdl-c/unittest/sn_nsdl/sn_nsdl_unit_tests) - ==3916== by 0x42952E: UtestShell::runOneTest(TestPlugin*, TestResult&) (in mbed-client-c/test/nsdl-c/unittest/sn_nsdl/sn_nsdl_unit_tests) - ==3916== by 0x42A8B0: PlatformSpecificSetJmp (in mbed-github/mbed-client-c/test/nsdl-c/unittest/sn_nsdl/sn_nsdl_unit_tests) - ==3916== by 0x428D8B: UtestShell::runOneTestWithPlugins(TestPlugin*, TestResult&) (in mbed-client-c/test/nsdl-c/unittest/sn_nsdl/sn_nsdl_unit_tests) - ==3916== by 0x42C1ED: TestRegistry::runAllTests(TestResult&) (in mbed-client-c/test/nsdl-c/unittest/sn_nsdl/sn_nsdl_unit_tests) - ==3916== by 0x422A27: CommandLineTestRunner::runAllTests() (in mbed-client-c/test/nsdl-c/unittest/sn_nsdl/sn_nsdl_unit_tests) - ==3916== by 0x422ACC: CommandLineTestRunner::runAllTestsMain() (in mbed-client-c/test/nsdl-c/unittest/sn_nsdl/sn_nsdl_unit_tests) - -commit 36933741993f71dbd3e02521de5cf69876106030 -Author: Tero Jääskö -Date: Tue Oct 25 16:38:02 2016 +0300 - - sn_grs_unit_tests: fix 4 valgrind errors - - Fix 4 valgrind findings of uninitialized memory usage. - - One example of error being fixed: - ---8<----8<--- - ==30551== - ==30551== Conditional jump or move depends on uninitialised value(s) - ==30551== at 0x40F01B: sn_grs_convert_uri (sn_grs.c:949) - ==30551== by 0x40E7E7: sn_grs_search_resource (sn_grs.c:769) - ==30551== by 0x40D42F: sn_grs_process_coap (sn_grs.c:413) - ==30551== by 0x40869C: test_sn_grs_process_coap (test_sn_grs.c:654) - ==30551== by 0x401E7D: TEST_sn_grs_test_sn_grs_process_coap_Test::testBody() (sn_grstest.cpp:31) - ==30551== by 0x418C20: PlatformSpecificSetJmp (in mbed-client-c/test/nsdl-c/unittest/sn_grs/sn_grs_unit_tests) - ==30551== by 0x4171E4: Utest::run() (in mbed-client-c/test/nsdl-c/unittest/sn_grs/sn_grs_unit_tests) - ==30551== by 0x41789E: UtestShell::runOneTest(TestPlugin*, TestResult&) (in mbed-client-c/test/nsdl-c/unittest/sn_grs/sn_grs_unit_tests) - ==30551== by 0x418C20: PlatformSpecificSetJmp (in mbed-client-c/test/nsdl-c/unittest/sn_grs/sn_grs_unit_tests) - ==30551== by 0x4170FB: UtestShell::runOneTestWithPlugins(TestPlugin*, TestResult&) (in mbed-client-c/test/nsdl-c/unittest/sn_grs/sn_grs_unit_tests) - ==30551== by 0x41A55D: TestRegistry::runAllTests(TestResult&) (in mbed-client-c/test/nsdl-c/unittest/sn_grs/sn_grs_unit_tests) - ==30551== by 0x410D97: CommandLineTestRunner::runAllTests() (in mbed-client-c/test/nsdl-c/unittest/sn_grs/sn_grs_unit_tests) - -commit 1eebc512fe157227702b81684b36cb9bad179af2 -Author: Tero Jääskö -Date: Tue Oct 25 16:13:35 2016 +0300 - - sn_coap_protocol_unit_tests: Fix 297 valgrind errors for unint. memory. - - Fix 297 valgrind errors for uses of uninitialized memory. Most cases - were caused by same copy-pasted piece which allocated 3 bytes for a - buffer but used it as it was much, much larger. - - One sample of the fixed error: - ---8<---8<--- - ==22740== Invalid read of size 8 - ==22740== at 0x4C2F79E: memcpy@@GLIBC_2.14 (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) - ==22740== by 0x419329: sn_coap_protocol_build (sn_coap_protocol.c:492) - ==22740== by 0x41268E: TEST_libCoap_protocol_sn_coap_protocol_exec_Test::testBody() (libCoap_protocol_test.cpp:2076) - ==22740== by 0x427DE0: PlatformSpecificSetJmp (in mbed-client-c/test/nsdl-c/unittest/sn_coap_protocol/sn_coap_protocol_unit_tests) - ==22740== by 0x4263A4: Utest::run() (in mbed-client-c/test/nsdl-c/unittest/sn_coap_protocol/sn_coap_protocol_unit_tests) - ==22740== by 0x426A5E: UtestShell::runOneTest(TestPlugin*, TestResult&) (in mbed-client-c/test/nsdl-c/unittest/sn_coap_protocol/sn_coap_protocol_unit_tests) - ==22740== by 0x427DE0: PlatformSpecificSetJmp (in mbed-client-c/test/nsdl-c/unittest/sn_coap_protocol/sn_coap_protocol_unit_tests) - ==22740== by 0x4262BB: UtestShell::runOneTestWithPlugins(TestPlugin*, TestResult&) (in mbed-client-c/test/nsdl-c/unittest/sn_coap_protocol/sn_coap_protocol_unit_tests) - ==22740== by 0x42971D: TestRegistry::runAllTests(TestResult&) (in mbed-client-c/test/nsdl-c/unittest/sn_coap_protocol/sn_coap_protocol_unit_tests) - ==22740== by 0x41FF57: CommandLineTestRunner::runAllTests() (in mbed-client-c/test/nsdl-c/unittest/sn_coap_protocol/sn_coap_protocol_unit_tests) - ==22740== by 0x41FFFC: CommandLineTestRunner::runAllTestsMain() (in mbed-client-c/test/nsdl-c/unittest/sn_coap_protocol/sn_coap_protocol_unit_tests) - ==22740== by 0x42011E: CommandLineTestRunner::RunAllTests(int, char const**) (in mbed-client-c/test/nsdl-c/unittest/sn_coap_protocol/sn_coap_protocol_unit_tests) - -commit 1393616579ff888dc23384cc5a50a8be3b7f9935 -Author: Tero Jääskö -Date: Tue Oct 25 15:21:48 2016 +0300 - - sn_coap_parser_unit_tests: Fix uses of uninitialized memory. - - Fix 10 valgrind erros for uses of uninitialized memory. All the errors - are caused by same root cause, where code allocated memory for test buffer - and assumed it contains something useful or predictable. - - One error beind fixed: - --8<---8<--- - ==21841== Conditional jump or move depends on uninitialised value(s) - ==21841== at 0x4093CA: sn_coap_parser_options_parse (sn_coap_parser.c:262) - ==21841== by 0x408E5C: sn_coap_parser (sn_coap_parser.c:133) - ==21841== by 0x403FBC: test_sn_coap_parser (test_sn_coap_parser.c:61) - ==21841== by 0x401CFD: TEST_sn_coap_parser_test_sn_coap_parser_Test::testBody() (sn_coap_parsertest.cpp:20) - ==21841== by 0x414350: PlatformSpecificSetJmp (in /home/tero/work/mbed-github/mbed-client-c/test/nsdl-c/unittest/sn_coap_parser/sn_coap_parser_unit_tests) - ==21841== by 0x412914: Utest::run() (in /home/tero/work/mbed-github/mbed-client-c/test/nsdl-c/unittest/sn_coap_parser/sn_coap_parser_unit_tests) - ==21841== by 0x412FCE: UtestShell::runOneTest(TestPlugin*, TestResult&) (in /home/tero/work/mbed-github/mbed-client-c/test/nsdl-c/unittest/sn_coap_parser/sn_coap_parser_unit_tests) - ==21841== by 0x414350: PlatformSpecificSetJmp (in /home/tero/work/mbed-github/mbed-client-c/test/nsdl-c/unittest/sn_coap_parser/sn_coap_parser_unit_tests) - ==21841== by 0x41282B: UtestShell::runOneTestWithPlugins(TestPlugin*, TestResult&) (in /home/tero/work/mbed-github/mbed-client-c/test/nsdl-c/unittest/sn_coap_parser/sn_coap_parser_unit_tests) - ==21841== by 0x415C8D: TestRegistry::runAllTests(TestResult&) (in /home/tero/work/mbed-github/mbed-client-c/test/nsdl-c/unittest/sn_coap_parser/sn_coap_parser_unit_tests) - ==21841== by 0x40C4C7: CommandLineTestRunner::runAllTests() (in /home/tero/work/mbed-github/mbed-client-c/test/nsdl-c/unittest/sn_coap_parser/sn_coap_parser_unit_tests) - ==21841== by 0x40C56C: CommandLineTestRunner::runAllTestsMain() (in /home/tero/work/mbed-github/mbed-client-c/test/nsdl-c/unittest/sn_coap_parser/sn_coap_parser_unit_tests) - -commit 59be2f154af9b8388ae3e3e6a763cd5b0d2700f1 (tag: v3.0.3) -Author: Antti Yli-Tokola -Date: Thu Sep 29 10:52:54 2016 +0300 - - version v3.0.3 - -commit 3b89e2a465c3876cc184c92c72bdbe66193502c7 -Merge: 58f712b 4369a46 -Author: Antti Yli-Tokola -Date: Thu Sep 29 10:50:20 2016 +0300 - - Merge pull request #81 from ARMmbed/duplicate_fix - - Fix for message duplication handling - -commit 4369a4656e4a1ef5e81adf6316513d7a06e9a488 -Author: Antti Yli-Tokola -Date: Thu Sep 29 09:19:36 2016 +0300 - - Fix one failing unit test - -commit 72bfc3e7199d040b8bfa637e1840a0869f786231 -Author: Tero Heinonen -Date: Wed Sep 28 13:54:56 2016 +0300 - - Enable duplicate message detection - -commit 852c1f642afe7eb342016c76807d8b10a0fe7504 -Author: Tero Heinonen -Date: Thu Sep 22 14:12:15 2016 +0300 - - Fix for message duplication handling - - RFC 7252 chapter 4.5 talks only duplication of Confirmable- and - Non-confirmable messages. Adding check for message type before - processing duplication store and check. - -## [v3.0.2](https://github.com/ARMmbed/mbed-client-c/releases/tag/v3.0.2) (24-Sep-2016) -[Full Changelog](https://github.com/ARMmbed/mbed-client-c/compare/v3.0.1...v3.0.2) - -**New feature** - -- Make resending flags configurable through Yotta and mbed-cli build systems -- Introducing Configuration management through Config file - -**Closed issues:** - -- IOTCLT-882 - Confirmable messages sending - -**Merged pull requests:** - -commit 58f712b9f684bede1905ce35a1a39ebb257c049c (HEAD, tag: v3.0.2, origin/master, origin/HEAD, master) -Author: Yogesh Pande -Date: Sat Sep 24 15:04:36 2016 +0300 - - version v3.0.2 - -commit 39d5e98025f3d8067cea85c4a06470e0e9374812 -Merge: cf4c119 31d6566 -Author: Yogesh Pande -Date: Sat Sep 24 14:51:30 2016 +0300 - - Merge pull request #79 from ARMmbed/config-mechanism - - Introducing Configuration management through Config file - -commit 31d6566dddfe449e87819244027b847f53f53a96 (origin/config-mechanism) -Author: Yogesh Pande -Date: Sat Sep 24 12:53:47 2016 +0300 - - Fixing valgrind with unit tests - -commit a95a90a31e8f6123d14df84688b4e2e2f32e5507 -Author: Yogesh Pande -Date: Sat Sep 24 12:00:44 2016 +0300 - - Fixing valgrind memory leaks for unit tests - -commit 248fc713a4303cb1f724d10f4aa6d68933bb5aed -Author: Yogesh Pande -Date: Sat Sep 24 11:32:01 2016 +0300 - - Fix for failing unit tests - -commit cec0980b4ccff9708cd0130fea936a69839739b8 -Merge: cf09b2b cf4c119 -Author: Yogesh Pande -Date: Thu Sep 22 18:02:39 2016 +0300 - - Merge branch 'master' into config-mechanism - -commit cf4c1196520d64bf863b39efefc663ee60e58c61 -Merge: 330a16b f5f15cc -Author: Antti Yli-Tokola -Date: Thu Sep 22 12:55:33 2016 +0300 - - Merge pull request #80 from ARMmbed/revert-77-duplication - - Revert "Enable message duplication by default" - -commit f5f15ccce5fd719aa8d7de14a583d02fd0fd05b9 (origin/revert-77-duplication) -Author: Antti Yli-Tokola -Date: Thu Sep 22 12:30:50 2016 +0300 - - Revert "Enable message duplication by default" - -commit cf09b2b6233bf897a17bdb0102962947df87f4ae -Author: Yogesh Pande -Date: Thu Sep 22 09:57:41 2016 +0300 - - Fixed comments from PR#79 - - This commit includes - - Fixing comments from PR-79 - -commit 8fd7cc258168047c29aca27a659de448f45e0e6f -Author: Yogesh Pande -Date: Wed Sep 21 20:42:28 2016 +0300 - - Introducing Configuration management through Config file - - This commit includes - - Support for configuring various build time parameters throuh user supplied config file - that can be passed at compile time through Makefile system which will work for - non mbed-OS and non yotta build system as well. - -commit 330a16bbfc5dc597015c7bdd935b603282d7064e -Merge: b7d909e e268081 -Author: Antti Yli-Tokola -Date: Wed Sep 21 12:05:29 2016 +0300 - - Merge pull request #78 from ARMmbed/resend_flags - - Make resend flags configurable through Yotta and mbed-cli build sy… - -commit e268081bae1fa1db3b5b64dfb77d5b7a5bfed748 -Merge: dc16b29 b7d909e -Author: Antti Yli-Tokola -Date: Wed Sep 21 12:02:32 2016 +0300 - - Merge branch 'master' into resend_flags - -commit b7d909eca1c2259453dbe9c094b8a0c53d638fea -Merge: 7f0eaea ad3b468 -Author: Antti Yli-Tokola -Date: Wed Sep 21 12:02:15 2016 +0300 - - Merge pull request #77 from ARMmbed/duplication - - Enable message duplication by default - -commit dc16b299ab9ff4bd1eaa9d3ec120fa58180820c4 -Author: Antti Yli-Tokola -Date: Mon Sep 19 14:35:31 2016 +0300 - - Make resending flags configurable through Yotta and mbed-cli build systems - -commit ad3b46881bb61dfc2510d13d373bcd1faad114f4 -Author: Antti Yli-Tokola -Date: Fri Sep 16 08:58:38 2016 +0300 - - Enable message duplication by default - -## [v3.0.1](https://github.com/ARMmbed/mbed-client-c/releases/tag/v3.0.1) (15-Sep-2016) -[Full Changelog](https://github.com/ARMmbed/mbed-client-c/compare/mbed-os-5.0-rc1...v3.0.1) - -** New feature ** - -- Creates a new sn_nsdl_put_resource function, which takes ownership of sn_nsdl_resource_info_s resource object (not members) instead of creationg copy of it -- Rearranged struct member variable to pack better into memory -- Refactored coap_options_list to treat number members as numbers instead of strings -- Add option to pass incoming blocks to application instead storing them internally -- Added API for deleting one message from resending - -**Closed issues:** - -- IOTCLT-1001 - mDS does not sent RST anymore for Client after DELETE /subscriptions - -**Merged pull requests:** - -commit 7f0eaea060e1274f5ea6e239960a74fecb8a075d (HEAD, tag: v3.0.1, origin/master, origin/HEAD, master) -Author: Antti Kauppila -Date: Thu Sep 15 11:22:59 2016 +0300 - - version v3.0.1 - -commit 82677cffcafb06111b81f750782a9f5f5dc2fd21 -Author: Antti Kauppila -Date: Thu Sep 15 11:22:07 2016 +0300 - - Changed bool type to unsigned int - -commit e704a90cee81df0b5ee4a6839819ec4f946aad32 (tag: v3.0.0) -Author: Antti Yli-Tokola -Date: Thu Sep 15 10:30:56 2016 +0300 - - version v3.0.0 - -commit b273d51fd6f38b1938d8e2a942805dfdde3a59ef -Merge: 45e836b 4fdf010 -Author: Antti Yli-Tokola -Date: Thu Sep 15 10:25:34 2016 +0300 - - Merge pull request #75 from ARMmbed/coap-option-tidy - - Coap option tidy - -commit 4fdf010727d8bf45a6e2041b1202dbf7685b7c1e (origin/coap-option-tidy) -Author: Antti Yli-Tokola -Date: Thu Sep 15 10:18:53 2016 +0300 - - Remove commented out code - -commit 60a92da6e9315740cff41ec301895c8803a480c0 -Author: Antti Yli-Tokola -Date: Wed Sep 14 15:14:28 2016 +0300 - - Fix payload size calculation when blockwise is needed - -commit ac4dcda4d59821a6434205b26b4a4ea88e37f7b4 -Author: Antti Kauppila -Date: Wed Sep 14 10:00:09 2016 +0300 - - Blockwise transfer handling improved, fixes issue IOTCLT-1004 - + Unittests updated - -commit 2352759cb8b927bec229d4ac1bbe83472ceb39f2 -Author: Antti Kauppila -Date: Mon Sep 12 16:41:46 2016 +0300 - - Added sn_coap_parser_alloc_options function to create list with default values - - Updated unittests - -commit d5bf80d6d2374db924111c47d3e7f5cd45060ca3 -Author: Antti Kauppila -Date: Wed Sep 7 14:22:52 2016 +0300 - - Handle Size1/Size2 options as numbers - - This will simplify the handling of sizeX options. - Unittests have been updated also - -commit 58695b71ee218df4053344e5ca26accc894338ee -Author: Antti Kauppila -Date: Fri Sep 2 16:29:30 2016 +0300 - - Added put method, rearranged structs, updated unittests - -commit 754f4c015d675e5e0d7ef777e914df3910bb7320 -Author: Antti Kauppila -Date: Thu Sep 1 16:08:13 2016 +0300 - - Unittests updated & small fixes - -commit 626ac227c3de1837b7667c69087f5659dfdbd436 -Author: Kevin Bracey -Date: Mon Jun 22 12:58:08 2015 +0300 - - Treat Block2/Block1 options as numbers - - Rather than treat them as arbitary byte strings, process them as numbers. - This greatly simplifies a lot of the Block-wise transfer code. - - No public API change - users shouldn't be touching these options. - - Change-Id: I67f9eb4ff2610aeb0d7f7638dfb28c279f916889 - - Conflicts: - nsdl-c/sn_coap_header.h - source/libCoap/src/sn_coap_builder.c - source/libCoap/src/sn_coap_parser.c - source/libCoap/src/sn_coap_protocol.c - -commit acf48a4026304705797bc0c12382994d160afa37 -Author: Kevin Bracey -Date: Mon Jun 22 12:54:14 2015 +0300 - - Treat Observe option as a number - - Treat Observe option as a number, rather than a byte string. This is an - incompatible API change to both libCoap and libNsdl. - - Change-Id: I115afa988afbc239b45adfd7a21a33b2ee3bc42b - - Conflicts: - nsdl-c/sn_nsdl_lib.h - source/libCoap/src/sn_coap_builder.c - source/libCoap/src/sn_coap_protocol.c - -commit 48b5b2cb9fc4341656de54c38d10589d8fcc9db4 -Author: Kevin Bracey -Date: Mon Jun 22 12:37:58 2015 +0300 - - Treat Uri-Port as a number - - Treat the Uri-Port option as a number, rather than a byte string. - This is an incompatible API change for libCoap. - - Change-Id: I5e04f37cbe1f67a0cafa03befb746d6abff6f790 - - Conflicts: - source/libCoap/src/sn_coap_builder.c - -commit 9fa86767bd4efa7810223683d37df03a2ad4dd85 -Author: Kevin Bracey -Date: Mon Jun 22 12:34:06 2015 +0300 - - Treat Max-Age as a number - - Treat the Max-Age option as a number, rather than a byte string. This is - an incompatible API change for libCoap. - - Change-Id: I6abdbecb093f5ffa6ec009d591737592ca91e197 - - Conflicts: - source/libCoap/src/include/sn_coap_protocol_internal.h - source/libCoap/src/sn_coap_builder.c - source/libCoap/src/sn_coap_protocol.c - -commit e582e8ad318b469aebd5d6d59032fe4c18fde435 -Author: Kevin Bracey -Date: Mon Jun 22 12:11:12 2015 +0300 - - Treat Accept as a number - - In line with Content-Format, treat the Accept option as a number. - This is an incompatible API change for libCoap. - - This drops any ability to handle multiple Accept options - this existed - in early versions of CoAP, but was removed in draft 13. - - Change-Id: I5d0233bb01dfff7d944f5dcb1c0ec6bec88b710e - - Conflicts: - source/libCoap/src/sn_coap_builder.c - source/libCoap/src/sn_coap_parser.c - -commit 3bb5696d119a05323bbda3aaa8460bd56bef32ac -Author: Kevin Bracey -Date: Mon Jun 22 11:32:42 2015 +0300 - - Treat Content-Format as a number - - Treat the Content-Format option as a number - this is an incompatible API - change to libCoap. - - Clients will now correctly handle Content-Formats > 255, or Content-Format - options with zero-padding. - - NSDL-C seems to have some oddities in its Content-Format handling - it has - some lingering assumptions about "0=text/plain" being the default, which - is no longer true in the final CoRE/CoAP RFCs. This should be looked at; - no functional change is made to this by this commit. - - Change-Id: I4c25741964e562178b31508d30184b68783eadc2 - - Conflicts: - nsdl-c/sn_nsdl_lib.h - source/libCoap/src/sn_coap_builder.c - -commit 46b1bcf756ae5523e32a09612a0b049d0cdb62fa -Author: Kevin Bracey -Date: Mon Jun 22 09:50:33 2015 +0300 - - Add functions to build and parse "uint" options - - Many CoAP options are variable-length integers - create some - infrastructure to manipulate these by value, rather than treating as - byte strings. - - Change-Id: I0cf5c2b62d1745ca349f70bb272f726ead86ac0a - - Conflicts: - source/libCoap/src/sn_coap_builder.c - -commit 45e836b9a7b9a46dc9a97c7aae5570cb00f2d284 (HEAD, tag: v2.9.0, origin/master, origin/HEAD, master) -Author: Teemu Takaluoma -Date: Mon Sep 5 15:27:34 2016 +0300 - - version v2.9.0 - -commit 9022e05adb231fd8f619bb4fc2b0f05da99413a9 -Merge: ec0b281 87dfd6f -Author: Teemu Takaluoma -Date: Mon Sep 5 15:26:26 2016 +0300 - - Merge pull request #73 from ARMmbed/IOTCLT-1001 - - implement platform agnostic IP handling, Iotclt 1001 - -commit 87dfd6f11fc5a8a724e090e34540a8fc9bf8b290 -Author: Teemu Takaluoma -Date: Mon Sep 5 08:51:21 2016 +0300 - - add unit test - -commit b8ddefdcbfb58d355e170e8411eebc23ffe3c25c -Author: Teemu Takaluoma -Date: Sat Sep 3 14:14:28 2016 +0300 - - refactor address handling - -commit d89b6266fd52322fd7beafcd51365c980afbff05 -Author: Teemu Takaluoma -Date: Sat Sep 3 14:10:31 2016 +0300 - - Fix for IOTCLT-1001, implement platform agnostic IP handling - -commit ec0b281264f4859f28cfe207b89816835c56f392 (tag: v2.8.0) -Author: Antti Yli-Tokola -Date: Fri Aug 12 14:33:56 2016 +0300 - - version v2.8.0 - -commit 5ab0f01c31d6551547388307e0c0cfda272b611e -Author: Antti Yli-Tokola -Date: Fri Aug 12 14:30:24 2016 +0300 - - Add option to pass incoming blocks to application instead storing them internally (#71) - - * Add option to pass incoming blocks to application. If external_memory_block variable is set blocks are passed into application and not stored anymore internally. - -commit 168739c81618d105bfb3ccf77d14b0d38340ba6b -Merge: 758fd1e fbe4eeb -Author: Antti Yli-Tokola -Date: Wed Aug 10 12:49:42 2016 +0300 - - Merge pull request #65 from ARMmbed/retransmission_delete - - Added API for deleting one message from resending - -commit fbe4eeb8db1c7ed107dc3da6fd2fa5e3e9062ccb (origin/retransmission_delete) -Author: Tero Heinonen -Date: Fri Aug 5 11:48:17 2016 +0300 - - Added API for deleting one message from resending - queue. diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/LICENSE b/features/FEATURE_COMMON_PAL/mbed-client-c/LICENSE deleted file mode 100644 index 97df0e645d..0000000000 --- a/features/FEATURE_COMMON_PAL/mbed-client-c/LICENSE +++ /dev/null @@ -1,2 +0,0 @@ -Unless specifically indicated otherwise in a file, files are licensed -under the Apache 2.0 license, as can be found in: apache-2.0.txt \ No newline at end of file diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/README.txt b/features/FEATURE_COMMON_PAL/mbed-client-c/README.txt deleted file mode 100644 index f58f925c7d..0000000000 --- a/features/FEATURE_COMMON_PAL/mbed-client-c/README.txt +++ /dev/null @@ -1,2 +0,0 @@ -The mbed Device C Client Library provides a simple and efficient way to create mbed Device Client in -C. \ No newline at end of file diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/module.json b/features/FEATURE_COMMON_PAL/mbed-client-c/module.json deleted file mode 100644 index 52e3393600..0000000000 --- a/features/FEATURE_COMMON_PAL/mbed-client-c/module.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "name": "mbed-client-c", - "version": "3.0.4", - "description": "Nanostack NSDL and COAP library", - "keywords": [ - "coap", - "nanostack" - ], - "license": "Apache-2.0", - "extraIncludes": [ - "nsdl-c", - "source/libNsdl/src/include", - "source/libCoap/src/include" - ], - "dependencies": { - "nanostack-libservice": "^3.0.0", - "mbed-trace": ">=0.2.0,<2.0.0", - "nanostack-randlib": "^1.2.0" - }, - "targetDependencies": {} -} diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/nsdl-c/sn_nsdl.h b/features/FEATURE_COMMON_PAL/mbed-client-c/nsdl-c/sn_nsdl.h deleted file mode 100644 index 97deefb132..0000000000 --- a/features/FEATURE_COMMON_PAL/mbed-client-c/nsdl-c/sn_nsdl.h +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright (c) 2011-2015 ARM Limited. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 - * Licensed under the Apache License, Version 2.0 (the License); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** -* \file sn_nsdl.h -* -* \brief libNsdl generic header file -* -*/ - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef SN_NSDL_H_ -#define SN_NSDL_H_ - -/* * * Common * * */ - -#define SN_NSDL_SUCCESS 0 -#define SN_NSDL_FAILURE (-1) - -/* * * * * * * * * * * * * * */ -/* * * * ENUMERATIONS * * * */ -/* * * * * * * * * * * * * * */ - - -/** - * \brief Used protocol - */ -typedef enum sn_nsdl_capab_ { - SN_NSDL_PROTOCOL_HTTP = 0x01, /**< Unsupported */ - SN_NSDL_PROTOCOL_HTTPS = 0x02, /**< Unsupported */ - SN_NSDL_PROTOCOL_COAP = 0x04 /**< Supported */ -} sn_nsdl_capab_e; - -/** - * \brief Address type of given address - */ -typedef enum sn_nsdl_addr_type_ { - SN_NSDL_ADDRESS_TYPE_IPV6 = 0x01, /**< Supported */ - SN_NSDL_ADDRESS_TYPE_IPV4 = 0x02, /**< Supported */ - SN_NSDL_ADDRESS_TYPE_HOSTNAME = 0x03, /**< Unsupported */ - SN_NSDL_ADDRESS_TYPE_NONE = 0xFF -} sn_nsdl_addr_type_e; - - -#define SN_NDSL_RESOURCE_NOT_REGISTERED 0 -#define SN_NDSL_RESOURCE_REGISTERING 1 -#define SN_NDSL_RESOURCE_REGISTERED 2 - - -/* * * * * * * * * * * * * */ -/* * * * STRUCTURES * * * */ -/* * * * * * * * * * * * * */ - -/** - * \brief Address structure of Packet data - */ -typedef struct sn_nsdl_addr_ { - uint8_t addr_len; - sn_nsdl_addr_type_e type; - uint16_t port; - uint8_t *addr_ptr; -} sn_nsdl_addr_s; - -/** - * \brief Used for creating manually registration message with sn_coap_register() - */ -typedef struct registration_info_ { - uint8_t endpoint_len; - uint8_t endpoint_type_len; - uint16_t links_len; - - uint8_t *endpoint_ptr; /**< Endpoint name */ - uint8_t *endpoint_type_ptr; /**< Endpoint type */ - uint8_t *links_ptr; /**< Resource registration string */ -} registration_info_t; - -#endif /* SN_NSDL_H_ */ - -#ifdef __cplusplus -} -#endif diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/nsdl-c/sn_nsdl_lib.h b/features/FEATURE_COMMON_PAL/mbed-client-c/nsdl-c/sn_nsdl_lib.h deleted file mode 100755 index d4472bf524..0000000000 --- a/features/FEATURE_COMMON_PAL/mbed-client-c/nsdl-c/sn_nsdl_lib.h +++ /dev/null @@ -1,768 +0,0 @@ -/* - * Copyright (c) 2011-2015 ARM Limited. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 - * Licensed under the Apache License, Version 2.0 (the License); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** -* \file sn_nsdl_lib.h -* -* \brief NanoService Devices Library header file -* -* -*/ - -#ifndef SN_NSDL_LIB_H_ -#define SN_NSDL_LIB_H_ - -#ifdef MBED_CLIENT_C_NEW_API - -#include "nsdl-c/sn_nsdl_lib2.h" - -#else - -#include "ns_list.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define SN_NSDL_ENDPOINT_NOT_REGISTERED 0 -#define SN_NSDL_ENDPOINT_IS_REGISTERED 1 - -/* Handle structure */ -struct nsdl_s; - -/** - * \brief Received device server security - */ -typedef enum omalw_server_security_ { - SEC_NOT_SET = -1, - PSK = 0, - RPK = 1, - CERTIFICATE = 2, - NO_SEC = 3 -} omalw_server_security_t; - -/** - * \brief Endpoint binding and mode - */ -typedef enum sn_nsdl_oma_binding_and_mode_ { - BINDING_MODE_NOT_SET = 0, - BINDING_MODE_U = 0x01, - BINDING_MODE_Q = 0x02, - BINDING_MODE_S = 0x04 -} sn_nsdl_oma_binding_and_mode_t; - -/** - * \brief Endpoint registration mode. - * If REGISTER_WITH_RESOURCES, endpoint sends list of all resources during registration. - * If REGISTER_WITH_TEMPLATE, endpoint sends registration without resource list. Device server must have - * correctly configured template. - */ -typedef enum sn_nsdl_registration_mode_ { - REGISTER_WITH_RESOURCES = 0, - REGISTER_WITH_TEMPLATE -} sn_nsdl_registration_mode_t; - - -typedef struct omalw_certificate_list_ { - uint8_t certificate_chain_len; - uint16_t own_private_key_len; - uint16_t certificate_len[2]; - uint8_t *certificate_ptr[2]; - uint8_t *own_private_key_ptr; -} omalw_certificate_list_t; - -/** - * \brief Endpoint registration parameters - */ -typedef struct sn_nsdl_ep_parameters_ { - uint8_t endpoint_name_len; - uint8_t domain_name_len; - uint8_t type_len; - uint8_t lifetime_len; - uint8_t location_len; - - sn_nsdl_registration_mode_t ds_register_mode; /**< Defines registration mode */ - sn_nsdl_oma_binding_and_mode_t binding_and_mode; /**< Defines endpoints binding and mode */ - - uint8_t *endpoint_name_ptr; /**< Endpoint name */ - uint8_t *domain_name_ptr; /**< Domain to register. If null, NSP uses default domain */ - uint8_t *type_ptr; /**< Endpoint type */ - uint8_t *lifetime_ptr; /**< Endpoint lifetime in seconds. eg. "1200" = 1200 seconds */ - uint8_t *location_ptr; /**< Endpoint location in server, optional parameter,default is NULL */ -} sn_nsdl_ep_parameters_s; - -/** - * \brief For internal use - */ -typedef struct sn_nsdl_sent_messages_ { - uint8_t message_type; - uint16_t msg_id_number; - ns_list_link_t link; -} sn_nsdl_sent_messages_s; - -/** - * \brief Includes resource path - */ -typedef struct sn_grs_resource_ { - uint8_t pathlen; - uint8_t *path; -} sn_grs_resource_s; - -/** - * \brief Table of created resources - */ -typedef struct sn_grs_resource_list_ { - uint8_t res_count; /**< Number of resources */ - sn_grs_resource_s *res; -} sn_grs_resource_list_s; - -/** - * \brief Resource access rights - */ -typedef enum sn_grs_resource_acl_ { - SN_GRS_GET_ALLOWED = 0x01 , - SN_GRS_PUT_ALLOWED = 0x02, - SN_GRS_POST_ALLOWED = 0x04, - SN_GRS_DELETE_ALLOWED = 0x08 -} sn_grs_resource_acl_e; - - -typedef enum sn_nsdl_oma_device_error_ { - NO_ERROR = 0, - LOW_BATTERY_POWER = 1, - EXTERNAL_POWER_SUPPLY_OFF = 2, - GPS_MODULE_FAILURE = 3, - LOW_RECEIVED_SIGNAL_STRENGTH = 4, - OUT_OF_MEMORY = 5, - SMS_FAILURE = 6, - IP_CONN_FAILURE = 7, - PERIPHERAL_MALFUNCTION = 8 -} sn_nsdl_oma_device_error_t; - -/** - * \brief Defines the resource mode - */ -typedef enum sn_nsdl_resource_mode_ { - SN_GRS_STATIC = 0, /**< Static resources have some value that doesn't change */ - SN_GRS_DYNAMIC, /**< Dynamic resources are handled in application. Therefore one must give function callback pointer to them */ - SN_GRS_DIRECTORY /**< Directory resources are unused and unsupported */ -} sn_nsdl_resource_mode_e; - -/** - * \brief Resource registration parameters - */ -typedef struct sn_nsdl_resource_parameters_ { - unsigned int observable:2; - unsigned int registered:2; - - uint16_t resource_type_len; - uint16_t interface_description_len; - - uint16_t coap_content_type; -// uint8_t mime_content_type; - - uint8_t *resource_type_ptr; - uint8_t *interface_description_ptr; - -} sn_nsdl_resource_parameters_s; - -/** - * \brief Defines parameters for the resource. - */ -typedef struct sn_nsdl_resource_info_ { - - unsigned int mode:2; /**< STATIC etc.. */ - - unsigned int access:4; - - bool publish_uri:1; - - bool is_put:1; //if true, pointers are assumed to be consts (never freed). Note: resource_parameters_ptr is always freed! - - uint8_t external_memory_block; - - uint16_t pathlen; /**< Address */ - - uint16_t resourcelen; /**< 0 if dynamic resource, resource information in static resource */ - - sn_nsdl_resource_parameters_s *resource_parameters_ptr; - - uint8_t (*sn_grs_dyn_res_callback)(struct nsdl_s *, sn_coap_hdr_s *, sn_nsdl_addr_s *, sn_nsdl_capab_e); - - uint8_t *path; - - uint8_t *resource; /**< NULL if dynamic resource */ - - ns_list_link_t link; -} sn_nsdl_resource_info_s; - -/** - * \brief Defines OMA device object parameters. - */ -typedef struct sn_nsdl_oma_device_ { - sn_nsdl_oma_device_error_t error_code; /**< Error code. Mandatory. Can be more than one */ - uint8_t (*sn_oma_device_boot_callback)(struct nsdl_s *, sn_coap_hdr_s *, sn_nsdl_addr_s *, sn_nsdl_capab_e); /**< Device boot callback function. If defined, this is called when reset request is received */ - -} sn_nsdl_oma_device_t; - -/** - * \brief Defines OMAlw server information - */ -typedef struct sn_nsdl_oma_server_info_ { - sn_nsdl_addr_s *omalw_address_ptr; - omalw_server_security_t omalw_server_security; - -} sn_nsdl_oma_server_info_t; - -/** - * \brief Defines endpoint parameters to OMA bootstrap. - */ -typedef struct sn_nsdl_bs_ep_info_ { - void (*oma_bs_status_cb)(sn_nsdl_oma_server_info_t *); /**< Callback for OMA bootstrap status */ - - void (*oma_bs_status_cb_handle)(sn_nsdl_oma_server_info_t *, - struct nsdl_s *); /**< Callback for OMA bootstrap status with nsdl handle */ - - sn_nsdl_oma_device_t *device_object; /**< OMA LWM2M mandatory device resources */ -} sn_nsdl_bs_ep_info_t; - - - - -/** - * \fn struct nsdl_s *sn_nsdl_init (uint8_t (*sn_nsdl_tx_cb)(sn_nsdl_capab_e , uint8_t *, uint16_t, sn_nsdl_addr_s *), - * uint8_t (*sn_nsdl_rx_cb)(sn_coap_hdr_s *, sn_nsdl_addr_s *), - * sn_nsdl_mem_s *sn_memory) - * - * \brief Initialization function for NSDL library. Initializes NSDL, GRS, HTTP and CoAP. - * - * \param *sn_nsdl_tx_callback A callback function for sending messages. - * - * \param *sn_nsdl_rx_callback A callback function for parsed messages. If received message is not CoAP protocol message (eg. ACK), message for GRS (GET, PUT, POST, DELETE) or - * reply for some DS messages (register message etc.), rx callback will be called. - * - * \param *sn_memory Memory structure which includes function pointers to the allocation and free functions. - * - * \return pointer to created handle structure. NULL if failed - */ -struct nsdl_s *sn_nsdl_init(uint8_t (*sn_nsdl_tx_cb)(struct nsdl_s *, sn_nsdl_capab_e , uint8_t *, uint16_t, sn_nsdl_addr_s *), - uint8_t (*sn_nsdl_rx_cb)(struct nsdl_s *, sn_coap_hdr_s *, sn_nsdl_addr_s *), - void *(*sn_nsdl_alloc)(uint16_t), void (*sn_nsdl_free)(void *)); - -/** - * \fn extern uint16_t sn_nsdl_register_endpoint(struct nsdl_s *handle, sn_nsdl_ep_parameters_s *endpoint_info_ptr); - * - * \brief Registers endpoint to mbed Device Server. - * \param *handle Pointer to nsdl-library handle - * \param *endpoint_info_ptr Contains endpoint information. - * - * \return registration message ID, 0 if failed - */ -extern uint16_t sn_nsdl_register_endpoint(struct nsdl_s *handle, sn_nsdl_ep_parameters_s *endpoint_info_ptr); - -/** - * \fn extern uint16_t sn_nsdl_unregister_endpoint(struct nsdl_s *handle) - * - * \brief Sends unregister-message to mbed Device Server. - * - * \param *handle Pointer to nsdl-library handle - * - * \return unregistration message ID, 0 if failed - */ -extern uint16_t sn_nsdl_unregister_endpoint(struct nsdl_s *handle); - -/** - * \fn extern uint16_t sn_nsdl_update_registration(struct nsdl_s *handle, uint8_t *lt_ptr, uint8_t lt_len); - * - * \brief Update the registration with mbed Device Server. - * - * \param *handle Pointer to nsdl-library handle - * \param *lt_ptr Pointer to lifetime value string in ascii form, eg. "1200" - * \param lt_len Length of the lifetime string - * - * \return registration update message ID, 0 if failed - */ -extern uint16_t sn_nsdl_update_registration(struct nsdl_s *handle, uint8_t *lt_ptr, uint8_t lt_len); - -/** - * \fn extern int8_t sn_nsdl_set_endpoint_location(struct nsdl_s *handle, uint8_t *location_ptr, uint8_t location_len); - * - * \brief Sets the location receievd from Device Server. - * - * \param *handle Pointer to nsdl-library handle - * \param *lt_ptr Pointer to location value string , eg. "s322j4k" - * \param lt_len Length of the location string - * - * \return success, 0 if failed -1 - */ -extern int8_t sn_nsdl_set_endpoint_location(struct nsdl_s *handle, uint8_t *location_ptr, uint8_t location_len); - - -/** - * \fn extern int8_t sn_nsdl_is_ep_registered(struct nsdl_s *handle) - * - * \brief Checks if endpoint is registered. - * - * \param *handle Pointer to nsdl-library handle - * - * \return 1 Endpoint registration is done successfully - * \return 0 Endpoint is not registered - */ -extern int8_t sn_nsdl_is_ep_registered(struct nsdl_s *handle); - -/** - * \fn extern void sn_nsdl_nsp_lost(struct nsdl_s *handle); - * - * \brief A function to inform mbed Device C client library if application detects a fault in mbed Device Server registration. - * - * \param *handle Pointer to nsdl-library handle - * - * After calling this function sn_nsdl_is_ep_registered() will return "not registered". - */ -extern void sn_nsdl_nsp_lost(struct nsdl_s *handle); - -/** - * \fn extern uint16_t sn_nsdl_send_observation_notification(struct nsdl_s *handle, uint8_t *token_ptr, uint8_t token_len, - * uint8_t *payload_ptr, uint16_t payload_len, - * sn_coap_observe_e observe, - * sn_coap_msg_type_e message_type, sn_coap_content_format_e content_format) - * - * - * \brief Sends observation message to mbed Device Server - * - * \param *handle Pointer to nsdl-library handle - * \param *token_ptr Pointer to token to be used - * \param token_len Token length - * \param *payload_ptr Pointer to payload to be sent - * \param payload_len Payload length - * \param observe Observe option value to be sent - * \param message_type Observation message type (confirmable or non-confirmable) - * \param content_format Observation message payload content format - * - * \return !0 Success, observation messages message ID - * \return 0 Failure - */ -extern uint16_t sn_nsdl_send_observation_notification(struct nsdl_s *handle, uint8_t *token_ptr, uint8_t token_len, - uint8_t *payload_ptr, uint16_t payload_len, - sn_coap_observe_e observe, - sn_coap_msg_type_e message_type, - sn_coap_content_format_e content_format); - -/** - * \fn extern uint16_t sn_nsdl_send_observation_notification_with_uri_path(struct nsdl_s *handle, uint8_t *token_ptr, uint8_t token_len, - * uint8_t *payload_ptr, uint16_t payload_len, - * sn_coap_observe_e observe, - * sn_coap_msg_type_e message_type, uint8_t content_type, - * uint8_t *uri_path_ptr, - * uint16_t uri_path_len) - * - * - * \brief Sends observation message to mbed Device Server with uri path - * - * \param *handle Pointer to nsdl-library handle - * \param *token_ptr Pointer to token to be used - * \param token_len Token length - * \param *payload_ptr Pointer to payload to be sent - * \param payload_len Payload length - * \param observe Observe option value to be sent - * \param message_type Observation message type (confirmable or non-confirmable) - * \param content_type Observation message payload contetnt type - * \param uri_path_ptr Pointer to uri path to be sent - * \param uri_path_len Uri path len - * - * \return !0 Success, observation messages message ID - * \return 0 Failure - */ -extern uint16_t sn_nsdl_send_observation_notification_with_uri_path(struct nsdl_s *handle, uint8_t *token_ptr, uint8_t token_len, - uint8_t *payload_ptr, uint16_t payload_len, - sn_coap_observe_e observe, - sn_coap_msg_type_e message_type, - uint8_t content_type, - uint8_t *uri_path_ptr, - uint16_t uri_path_len); - -/** - * \fn extern uint32_t sn_nsdl_get_version(void) - * - * \brief Version query function. - * - * Used to retrieve the version information from the mbed Device C Client library. - * - * \return Pointer to library version string -*/ -extern char *sn_nsdl_get_version(void); - -/** - * \fn extern int8_t sn_nsdl_process_coap(struct nsdl_s *handle, uint8_t *packet, uint16_t packet_len, sn_nsdl_addr_s *src) - * - * \brief To push CoAP packet to mbed Device C Client library - * - * Used to push an CoAP packet to mbed Device C Client library for processing. - * - * \param *handle Pointer to nsdl-library handle - * - * \param *packet Pointer to a uint8_t array containing the packet (including the CoAP headers). - * After successful execution this array may contain the response packet. - * - * \param *packet_len Pointer to length of the packet. After successful execution this array may contain the length - * of the response packet. - * - * \param *src Pointer to packet source address information. After successful execution this array may contain - * the destination address of the response packet. - * - * \return 0 Success - * \return -1 Failure - */ -extern int8_t sn_nsdl_process_coap(struct nsdl_s *handle, uint8_t *packet, uint16_t packet_len, sn_nsdl_addr_s *src); - -/** - * \fn extern int8_t sn_nsdl_exec(struct nsdl_s *handle, uint32_t time); - * - * \brief CoAP retransmission function. - * - * Used to give execution time for the mbed Device C Client library for retransmissions. - * - * \param *handle Pointer to nsdl-library handle - * - * \param time Time in seconds. - * - * \return 0 Success - * \return -1 Failure - */ -extern int8_t sn_nsdl_exec(struct nsdl_s *handle, uint32_t time); - -/** - * \fn extern int8_t sn_nsdl_create_resource(struct nsdl_s *handle, sn_nsdl_resource_info_s *res); - * - * \brief Resource creating function. - * - * Used to create a static or dynamic CoAP resource. - * - * \param *res Pointer to a structure of type sn_nsdl_resource_info_t that contains the information - * about the resource. - * - * \return 0 Success - * \return -1 Failure - * \return -2 Resource already exists - * \return -3 Invalid path - * \return -4 List adding failure - */ -extern int8_t sn_nsdl_create_resource(struct nsdl_s *handle, sn_nsdl_resource_info_s *res); - -/** - * \fn extern int8_t sn_nsdl_put_resource(struct nsdl_s *handle, sn_nsdl_resource_info_s *res); - * - * \brief Resource putting function. - * - * Used to put a static or dynamic CoAP resource without creating copy of it. - * NOTE: Remember that only resource will be owned, not data that it contains - * - * \param *res Pointer to a structure of type sn_nsdl_resource_info_t that contains the information - * about the resource. - * - * \return 0 Success - * \return -1 Failure - * \return -2 Resource already exists - * \return -3 Invalid path - * \return -4 List adding failure - */ -extern int8_t sn_nsdl_put_resource(struct nsdl_s *handle, sn_nsdl_resource_info_s *res); - -/** - * \fn extern int8_t sn_nsdl_update_resource(sn_nsdl_resource_info_s *res) - * - * \brief Resource updating function. - * - * Used to update the direct value of a static resource, the callback function pointer of a dynamic resource - * and access rights of the recource. - * - * \param *handle Pointer to nsdl-library handle - * \param *res Pointer to a structure of type sn_nsdl_resource_info_t that contains the information - * about the resource. Only the pathlen and path elements are evaluated along with - * either resourcelen and resource or the function pointer. - * - * \return 0 Success - * \return -1 Failure - */ -extern int8_t sn_nsdl_update_resource(struct nsdl_s *handle, sn_nsdl_resource_info_s *res); - -/** - * \fn extern int8_t sn_nsdl_delete_resource(struct nsdl_s *handle, uint8_t pathlen, uint8_t *path) - * - * \brief Resource delete function. - * - * Used to delete a resource. If resource has a subresources, these all must also be removed. - * - * \param *handle Pointer to nsdl-library handle - * \param pathlen Contains the length of the path that is to be deleted (excluding possible trailing "\0"). - * \param *path_ptr A pointer to an array containing the path. - * - * \return 0 Success - * \return -1 Failure (No such resource) - */ -extern int8_t sn_nsdl_delete_resource(struct nsdl_s *handle, uint16_t pathlen, uint8_t *path); - -/** - * \fn extern sn_nsdl_resource_info_s *sn_nsdl_get_resource(struct nsdl_s *handle, uint16_t pathlen, uint8_t *path) - * - * \brief Resource get function. - * - * Used to get a resource. - * - * \param *handle Pointer to nsdl-library handle - * \param pathlen Contains the length of the path that is to be returned (excluding possible trailing '\0'). - * \param *path A pointer to an array containing the path. - * - * \return !NULL Success, pointer to a sn_nsdl_resource_info_s that contains the resource information\n - * \return NULL Failure - */ -extern sn_nsdl_resource_info_s *sn_nsdl_get_resource(struct nsdl_s *handle, uint16_t pathlen, uint8_t *path); - -/** - * \fn extern sn_grs_resource_list_s *sn_nsdl_list_resource(struct nsdl_s *handle, uint16_t pathlen, uint8_t *path) - * - * \brief Resource list function. - * - * \param *handle Pointer to nsdl-library handle - * \param pathlen Contains the length of the target path (excluding possible trailing '\0'). - * The length value is not examined if the path itself is a NULL pointer. - * \param *path A pointer to an array containing the path or a NULL pointer. - * - * \return !NULL A pointer to a sn_grs_resource_list_s structure containing the resource listing. - * \return NULL Failure with an unspecified error - */ -sn_grs_resource_list_s *sn_nsdl_list_resource(struct nsdl_s *handle, uint16_t pathlen, uint8_t *path); - -/** - * \fn extern void sn_nsdl_free_resource_list(struct nsdl_s *handle, sn_grs_resource_list_s *list) - * - * \brief Free a resource list obtained from sn_nsdl_list_resource() - * - * \param list The list to free, or NULL. - */ -void sn_nsdl_free_resource_list(struct nsdl_s *handle, sn_grs_resource_list_s *list); - -/** - * \fn extern int8_t sn_nsdl_send_coap_message(struct nsdl_s *handle, sn_nsdl_addr_s *address_ptr, sn_coap_hdr_s *coap_hdr_ptr); - * - * \brief Send an outgoing CoAP request. - * - * \param *handle Pointer to nsdl-library handle - * \param *address_ptr Pointer to source address struct - * \param *coap_hdr_ptr Pointer to CoAP message to be sent - * - * \return 0 Success - * \return -1 Failure - */ -extern int8_t sn_nsdl_send_coap_message(struct nsdl_s *handle, sn_nsdl_addr_s *address_ptr, sn_coap_hdr_s *coap_hdr_ptr); - -/** - * \fn extern int8_t set_NSP_address(struct nsdl_s *handle, uint8_t *NSP_address, uint16_t port, sn_nsdl_addr_type_e address_type); - * - * \brief This function is used to set the mbed Device Server address given by an application. - * - * \param *handle Pointer to nsdl-library handle - * \return 0 Success - * \return -1 Failed to indicate that internal address pointer is not allocated (call nsdl_init() first). - */ -extern int8_t set_NSP_address(struct nsdl_s *handle, uint8_t *NSP_address, uint16_t port, sn_nsdl_addr_type_e address_type); - -/** - * \fn extern int8_t set_NSP_address(struct nsdl_s *handle, uint8_t *NSP_address, uint8_t address_length, uint16_t port, sn_nsdl_addr_type_e address_type); - * - * \brief This function is used to set the mbed Device Server address given by an application. - * - * \param *handle Pointer to nsdl-library handle - * \return 0 Success - * \return -1 Failed to indicate that internal address pointer is not allocated (call nsdl_init() first). - */ -extern int8_t set_NSP_address_2(struct nsdl_s *handle, uint8_t *NSP_address, uint8_t address_length, uint16_t port, sn_nsdl_addr_type_e address_type); - -/** - * \fn extern int8_t sn_nsdl_destroy(struct nsdl_s *handle); - * - * \param *handle Pointer to nsdl-library handle - * \brief This function releases all allocated memory in mbed Device C Client library. - */ -extern int8_t sn_nsdl_destroy(struct nsdl_s *handle); - -/** - * \fn extern uint16_t sn_nsdl_oma_bootstrap(struct nsdl_s *handle, sn_nsdl_addr_s *bootstrap_address_ptr, sn_nsdl_ep_parameters_s *endpoint_info_ptr, sn_nsdl_bs_ep_info_t *bootstrap_endpoint_info_ptr); - * - * \brief Starts OMA bootstrap process - * - * \param *handle Pointer to nsdl-library handle - * - * \return bootstrap message ID, 0 if failed - */ -extern uint16_t sn_nsdl_oma_bootstrap(struct nsdl_s *handle, sn_nsdl_addr_s *bootstrap_address_ptr, sn_nsdl_ep_parameters_s *endpoint_info_ptr, sn_nsdl_bs_ep_info_t *bootstrap_endpoint_info_ptr); - -/** - * \fn extern omalw_certificate_list_t *sn_nsdl_get_certificates(struct nsdl_s *handle); - * - * \brief Get pointer to received device server certificates - * - * \param *handle Pointer to nsdl-library handle - */ -extern omalw_certificate_list_t *sn_nsdl_get_certificates(struct nsdl_s *handle); - -/** - * \fn extern int8_t sn_nsdl_update_certificates(struct nsdl_s *handle, omalw_certificate_list_t* certificate_ptr, uint8_t certificate_chain); - * - * \brief Updates certificate pointers to resource server. - * - * \param *handle Pointer to nsdl-library handle - */ -extern int8_t sn_nsdl_update_certificates(struct nsdl_s *handle, omalw_certificate_list_t *certificate_ptr, uint8_t certificate_chain); - -/** - * \fn extern int8_t sn_nsdl_create_oma_device_object(struct nsdl_s *handle, sn_nsdl_oma_device_t *device_object_ptr); - * - * \brief Creates new device object resource - * - * \param *handle Pointer to nsdl-library handle - */ -extern int8_t sn_nsdl_create_oma_device_object(struct nsdl_s *handle, sn_nsdl_oma_device_t *device_object_ptr); - -/** - * \fn sn_coap_hdr_s *sn_nsdl_build_response(struct nsdl_s *handle, sn_coap_hdr_s *coap_packet_ptr, uint8_t msg_code) - * - * \brief Prepares generic response packet from a request packet. This function allocates memory for the resulting sn_coap_hdr_s - * - * \param *handle Pointer to library handle - * \param *coap_packet_ptr The request packet pointer - * \param msg_code response messages code - * - * \return *coap_packet_ptr The allocated and pre-filled response packet pointer - * NULL Error in parsing the request - * - */ -extern sn_coap_hdr_s *sn_nsdl_build_response(struct nsdl_s *handle, sn_coap_hdr_s *coap_packet_ptr, uint8_t msg_code); - -/** - * \brief Allocates and initializes options list structure - * - * \param *handle Pointer to library handle - * \param *coap_msg_ptr is pointer to CoAP message that will contain the options - * - * If the message already has a pointer to an option structure, that pointer - * is returned, rather than a new structure being allocated. - * - * \return Return value is pointer to the CoAP options structure.\n - * In following failure cases NULL is returned:\n - * -Failure in given pointer (= NULL)\n - * -Failure in memory allocation (malloc() returns NULL) - */ -extern sn_coap_options_list_s *sn_nsdl_alloc_options_list(struct nsdl_s *handle, sn_coap_hdr_s *coap_msg_ptr); - -/** - * \fn void sn_nsdl_release_allocated_coap_msg_mem(struct nsdl_s *handle, sn_coap_hdr_s *freed_coap_msg_ptr) - * - * \brief Releases memory of given CoAP message - * - * Note!!! Does not release Payload part - * - * \param *handle Pointer to library handle - * - * \param *freed_coap_msg_ptr is pointer to released CoAP message - */ -extern void sn_nsdl_release_allocated_coap_msg_mem(struct nsdl_s *handle, sn_coap_hdr_s *freed_coap_msg_ptr); - -/** - * \fn int8_t sn_nsdl_set_retransmission_parameters(struct nsdl_s *handle, uint8_t resending_count, uint8_t resending_intervall) - * - * \brief If re-transmissions are enabled, this function changes resending count and interval. - * - * \param *handle Pointer to library handle - * \param uint8_t resending_count max number of resendings for message - * \param uint8_t resending_intervall message resending intervall in seconds - * \return 0 = success, -1 = failure - */ -extern int8_t sn_nsdl_set_retransmission_parameters(struct nsdl_s *handle, uint8_t resending_count, uint8_t resending_interval); - -/** - * \fn int8_t sn_nsdl_set_retransmission_buffer(struct nsdl_s *handle, uint8_t buffer_size_messages, uint16_t buffer_size_bytes) - * - * \brief If re-transmissions are enabled, this function changes message retransmission queue size. - * Set size to '0' to disable feature. If both are set to '0', then re-sendings are disabled. - * - * \param *handle Pointer to library handle - * \param uint8_t buffer_size_messages queue size - maximum number of messages to be saved to queue - * \param uint8_t buffer_size_bytes queue size - maximum size of messages saved to queue - * \return 0 = success, -1 = failure - */ -extern int8_t sn_nsdl_set_retransmission_buffer(struct nsdl_s *handle, - uint8_t buffer_size_messages, uint16_t buffer_size_bytes); - -/** - * \fn int8_t sn_nsdl_set_block_size(struct nsdl_s *handle, uint16_t block_size) - * - * \brief If block transfer is enabled, this function changes the block size. - * - * \param *handle Pointer to library handle - * \param uint16_t block_size maximum size of CoAP payload. Valid sizes are 16, 32, 64, 128, 256, 512 and 1024 bytes - * \return 0 = success, -1 = failure - */ -extern int8_t sn_nsdl_set_block_size(struct nsdl_s *handle, uint16_t block_size); - -/** - * \fn int8_t sn_nsdl_set_duplicate_buffer_size(struct nsdl_s *handle,uint8_t message_count) - * - * \brief If dublicate message detection is enabled, this function changes buffer size. - * - * \param *handle Pointer to library handle - * \param uint8_t message_count max number of messages saved for duplicate control - * \return 0 = success, -1 = failure - */ -extern int8_t sn_nsdl_set_duplicate_buffer_size(struct nsdl_s *handle, uint8_t message_count); - -/** - * \fn void *sn_nsdl_set_context(const struct nsdl_s *handle, void *context) - * - * \brief Set the application defined context parameter for given handle. - * This is useful for example when interfacing with c++ objects where a - * pointer to object is set as the context, and in the callback functions - * the context pointer can be used to call methods for the correct instance - * of the c++ object. - * - * \param *handle Pointer to library handle - * \param *context Pointer to the application defined context - * \return 0 = success, -1 = failure - */ -extern int8_t sn_nsdl_set_context(struct nsdl_s * const handle, void * const context); - -/** - * \fn void *sn_nsdl_get_context(const struct nsdl_s *handle) - * - * \brief Get the application defined context parameter for given handle. - * This is useful for example when interfacing with c++ objects where a - * pointer to object is set as the context, and in the callback functions - * the context pointer can be used to call methods for the correct instance - * of the c++ object. - * - * \param *handle Pointer to library handle - * \return Pointer to the application defined context - */ -extern void *sn_nsdl_get_context(const struct nsdl_s * const handle); - -#ifdef __cplusplus -} -#endif - -#endif /* MBED_CLIENT_C_NEW_API */ - - -#endif /* SN_NSDL_LIB_H_ */ diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/nsdl-c/sn_nsdl_lib2.h b/features/FEATURE_COMMON_PAL/mbed-client-c/nsdl-c/sn_nsdl_lib2.h deleted file mode 100755 index e33010422c..0000000000 --- a/features/FEATURE_COMMON_PAL/mbed-client-c/nsdl-c/sn_nsdl_lib2.h +++ /dev/null @@ -1,666 +0,0 @@ -/* - * Copyright (c) 2011-2015 ARM Limited. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 - * Licensed under the Apache License, Version 2.0 (the License); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** -* \file sn_nsdl_lib.h -* -* \brief NanoService Devices Library header file -* -* -*/ - -#ifndef SN_NSDL_LIB_2_H_ -#define SN_NSDL_LIB_2_H_ - -#ifdef MBED_CLIENT_C_NEW_API - -#include "mbed-client-libservice/ns_list.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define SN_NSDL_ENDPOINT_NOT_REGISTERED 0 -#define SN_NSDL_ENDPOINT_IS_REGISTERED 1 - - -/* Handle structure */ -struct nsdl_s; - -/** - * \brief Received device server security - */ -typedef enum omalw_server_security_ { - SEC_NOT_SET = -1, - PSK = 0, - RPK = 1, - CERTIFICATE = 2, - NO_SEC = 3 -} omalw_server_security_t; - -/** - * \brief Endpoint binding and mode - */ -typedef enum sn_nsdl_oma_binding_and_mode_ { - BINDING_MODE_NOT_SET = 0, - BINDING_MODE_U = 0x01, - BINDING_MODE_Q = 0x02, - BINDING_MODE_S = 0x04 -} sn_nsdl_oma_binding_and_mode_t; - -/** - * \brief Endpoint registration mode. - * If REGISTER_WITH_RESOURCES, endpoint sends list of all resources during registration. - * If REGISTER_WITH_TEMPLATE, endpoint sends registration without resource list. Device server must have - * correctly configured template. - */ -typedef enum sn_nsdl_registration_mode_ { - REGISTER_WITH_RESOURCES = 0, - REGISTER_WITH_TEMPLATE -} sn_nsdl_registration_mode_t; - -/** - * \brief Endpoint registration parameters - */ -typedef struct sn_nsdl_ep_parameters_ { - uint8_t endpoint_name_len; - uint8_t domain_name_len; - uint8_t type_len; - uint8_t lifetime_len; - uint8_t location_len; - - sn_nsdl_registration_mode_t ds_register_mode; /**< Defines registration mode */ - sn_nsdl_oma_binding_and_mode_t binding_and_mode; /**< Defines endpoints binding and mode */ - - uint8_t *endpoint_name_ptr; /**< Endpoint name */ - uint8_t *domain_name_ptr; /**< Domain to register. If null, NSP uses default domain */ - uint8_t *type_ptr; /**< Endpoint type */ - uint8_t *lifetime_ptr; /**< Endpoint lifetime in seconds. eg. "1200" = 1200 seconds */ - uint8_t *location_ptr; /**< Endpoint location in server, optional parameter,default is NULL */ -} sn_nsdl_ep_parameters_s; - -/** - * \brief For internal use - */ -typedef struct sn_nsdl_sent_messages_ { - uint8_t message_type; - uint16_t msg_id_number; - ns_list_link_t link; -} sn_nsdl_sent_messages_s; - -/** - * \brief Includes resource path - */ -typedef struct sn_grs_resource_ { - uint8_t pathlen; - uint8_t *path; -} sn_grs_resource_s; - -/** - * \brief Table of created resources - */ -typedef struct sn_grs_resource_list_ { - uint8_t res_count; /**< Number of resources */ - sn_grs_resource_s *res; -} sn_grs_resource_list_s; - -/** - * \brief Resource access rights - */ -typedef enum sn_grs_resource_acl_ { - SN_GRS_GET_ALLOWED = 0x01 , - SN_GRS_PUT_ALLOWED = 0x02, - SN_GRS_POST_ALLOWED = 0x04, - SN_GRS_DELETE_ALLOWED = 0x08 -} sn_grs_resource_acl_e; - -/** - * \brief Defines the resource mode - */ -typedef enum sn_nsdl_resource_mode_ { - SN_GRS_STATIC = 0, /**< Static resources have some value that doesn't change */ - SN_GRS_DYNAMIC, /**< Dynamic resources are handled in application. Therefore one must give function callback pointer to them */ - SN_GRS_DIRECTORY /**< Directory resources are unused and unsupported */ -} sn_nsdl_resource_mode_e; - -/** - * \brief Defines static parameters for the resource. - */ -typedef struct sn_nsdl_static_resource_parameters_ { - char *resource_type_ptr; // - char *interface_description_ptr; // - uint8_t *path; // convert to char*? - uint8_t *resource; /**< NULL if dynamic resource */ - int16_t pathlen; /**< Address */ // Check type - uint16_t resourcelen; /**< 0 if dynamic resource, resource information in static resource */ - bool external_memory_block:1; /**< 0 means block messages are handled inside this library, - otherwise block messages are passed to application */ - unsigned mode:2; /**< STATIC etc.. */ - bool free_on_delete:1; /**< 1 if struct is dynamic allocted --> to be freed */ -} sn_nsdl_static_resource_parameters_s; - -/** - * \brief Defines dynamic parameters for the resource. - */ -typedef struct sn_nsdl_resource_parameters_ { - uint8_t (*sn_grs_dyn_res_callback)(struct nsdl_s *, - sn_coap_hdr_s *, - sn_nsdl_addr_s *, - sn_nsdl_capab_e); -#ifdef MEMORY_OPTIMIZED_API - const sn_nsdl_static_resource_parameters_s *static_resource_parameters; -#else - sn_nsdl_static_resource_parameters_s *static_resource_parameters; -#endif - ns_list_link_t link; - uint16_t coap_content_type; /**< CoAP content type */ - unsigned access:4; /**< Allowed operation mode, GET, PUT, etc, - TODO! This should be in static struct but current - mbed-client implementation requires this to be changed at runtime */ - unsigned registered:2; /**< Is resource registered or not */ - bool publish_uri:1; /**< 1 if resource to be published to server */ - bool free_on_delete:1; /**< 1 if struct is dynamic allocted --> to be freed */ - bool observable:1; /**< Is resource observable or not */ -} sn_nsdl_dynamic_resource_parameters_s; - -/** - * \brief Defines OMAlw server information - */ -typedef struct sn_nsdl_oma_server_info_ { - sn_nsdl_addr_s *omalw_address_ptr; - omalw_server_security_t omalw_server_security; - -} sn_nsdl_oma_server_info_t; - -/** - * \brief Defines endpoint parameters to OMA bootstrap. - */ -typedef struct sn_nsdl_bs_ep_info_ { - void (*oma_bs_status_cb)(sn_nsdl_oma_server_info_t *); /**< Callback for OMA bootstrap status */ - - void (*oma_bs_status_cb_handle)(sn_nsdl_oma_server_info_t *, - struct nsdl_s *); /**< Callback for OMA bootstrap status with nsdl handle */ -} sn_nsdl_bs_ep_info_t; - -/** - * \fn struct nsdl_s *sn_nsdl_init (uint8_t (*sn_nsdl_tx_cb)(sn_nsdl_capab_e , uint8_t *, uint16_t, sn_nsdl_addr_s *), - * uint8_t (*sn_nsdl_rx_cb)(sn_coap_hdr_s *, sn_nsdl_addr_s *), - * sn_nsdl_mem_s *sn_memory) - * - * \brief Initialization function for NSDL library. Initializes NSDL, GRS, HTTP and CoAP. - * - * \param *sn_nsdl_tx_callback A callback function for sending messages. - * - * \param *sn_nsdl_rx_callback A callback function for parsed messages. If received message is not CoAP protocol message (eg. ACK), message for GRS (GET, PUT, POST, DELETE) or - * reply for some DS messages (register message etc.), rx callback will be called. - * - * \param *sn_memory Memory structure which includes function pointers to the allocation and free functions. - * - * \return pointer to created handle structure. NULL if failed - */ -struct nsdl_s *sn_nsdl_init(uint8_t (*sn_nsdl_tx_cb)(struct nsdl_s *, sn_nsdl_capab_e , uint8_t *, uint16_t, sn_nsdl_addr_s *), - uint8_t (*sn_nsdl_rx_cb)(struct nsdl_s *, sn_coap_hdr_s *, sn_nsdl_addr_s *), - void *(*sn_nsdl_alloc)(uint16_t), void (*sn_nsdl_free)(void *)); - -/** - * \fn extern uint16_t sn_nsdl_register_endpoint(struct nsdl_s *handle, sn_nsdl_ep_parameters_s *endpoint_info_ptr); - * - * \brief Registers endpoint to mbed Device Server. - * \param *handle Pointer to nsdl-library handle - * \param *endpoint_info_ptr Contains endpoint information. - * - * \return registration message ID, 0 if failed - */ -extern uint16_t sn_nsdl_register_endpoint(struct nsdl_s *handle, sn_nsdl_ep_parameters_s *endpoint_info_ptr); - -/** - * \fn extern uint16_t sn_nsdl_unregister_endpoint(struct nsdl_s *handle) - * - * \brief Sends unregister-message to mbed Device Server. - * - * \param *handle Pointer to nsdl-library handle - * - * \return unregistration message ID, 0 if failed - */ -extern uint16_t sn_nsdl_unregister_endpoint(struct nsdl_s *handle); - -/** - * \fn extern uint16_t sn_nsdl_update_registration(struct nsdl_s *handle, uint8_t *lt_ptr, uint8_t lt_len); - * - * \brief Update the registration with mbed Device Server. - * - * \param *handle Pointer to nsdl-library handle - * \param *lt_ptr Pointer to lifetime value string in ascii form, eg. "1200" - * \param lt_len Length of the lifetime string - * - * \return registration update message ID, 0 if failed - */ -extern uint16_t sn_nsdl_update_registration(struct nsdl_s *handle, uint8_t *lt_ptr, uint8_t lt_len); - -/** - * \fn extern int8_t sn_nsdl_set_endpoint_location(struct nsdl_s *handle, uint8_t *location_ptr, uint8_t location_len); - * - * \brief Sets the location receievd from Device Server. - * - * \param *handle Pointer to nsdl-library handle - * \param *lt_ptr Pointer to location value string , eg. "s322j4k" - * \param lt_len Length of the location string - * - * \return success, 0 if failed -1 - */ -extern int8_t sn_nsdl_set_endpoint_location(struct nsdl_s *handle, uint8_t *location_ptr, uint8_t location_len); - -/** - * \fn extern int8_t sn_nsdl_is_ep_registered(struct nsdl_s *handle) - * - * \brief Checks if endpoint is registered. - * - * \param *handle Pointer to nsdl-library handle - * - * \return 1 Endpoint registration is done successfully - * \return 0 Endpoint is not registered - */ -extern int8_t sn_nsdl_is_ep_registered(struct nsdl_s *handle); - -/** - * \fn extern void sn_nsdl_nsp_lost(struct nsdl_s *handle); - * - * \brief A function to inform mbed Device C client library if application detects a fault in mbed Device Server registration. - * - * \param *handle Pointer to nsdl-library handle - * - * After calling this function sn_nsdl_is_ep_registered() will return "not registered". - */ -extern void sn_nsdl_nsp_lost(struct nsdl_s *handle); - -/** - * \fn extern uint16_t sn_nsdl_send_observation_notification(struct nsdl_s *handle, uint8_t *token_ptr, uint8_t token_len, - * uint8_t *payload_ptr, uint16_t payload_len, - * sn_coap_observe_e observe, - * sn_coap_msg_type_e message_type, sn_coap_content_format_e content_format) - * - * - * \brief Sends observation message to mbed Device Server - * - * \param *handle Pointer to nsdl-library handle - * \param *token_ptr Pointer to token to be used - * \param token_len Token length - * \param *payload_ptr Pointer to payload to be sent - * \param payload_len Payload length - * \param observe Observe option value to be sent - * \param message_type Observation message type (confirmable or non-confirmable) - * \param content_format Observation message payload content format - * - * \return !0 Success, observation messages message ID - * \return 0 Failure - */ -extern uint16_t sn_nsdl_send_observation_notification(struct nsdl_s *handle, uint8_t *token_ptr, uint8_t token_len, - uint8_t *payload_ptr, uint16_t payload_len, - sn_coap_observe_e observe, - sn_coap_msg_type_e message_type, - sn_coap_content_format_e content_format); - -/** - * \fn extern uint32_t sn_nsdl_get_version(void) - * - * \brief Version query function. - * - * Used to retrieve the version information from the mbed Device C Client library. - * - * \return Pointer to library version string -*/ -extern char *sn_nsdl_get_version(void); - -/** - * \fn extern int8_t sn_nsdl_process_coap(struct nsdl_s *handle, uint8_t *packet, uint16_t packet_len, sn_nsdl_addr_s *src) - * - * \brief To push CoAP packet to mbed Device C Client library - * - * Used to push an CoAP packet to mbed Device C Client library for processing. - * - * \param *handle Pointer to nsdl-library handle - * - * \param *packet Pointer to a uint8_t array containing the packet (including the CoAP headers). - * After successful execution this array may contain the response packet. - * - * \param *packet_len Pointer to length of the packet. After successful execution this array may contain the length - * of the response packet. - * - * \param *src Pointer to packet source address information. After successful execution this array may contain - * the destination address of the response packet. - * - * \return 0 Success - * \return -1 Failure - */ -extern int8_t sn_nsdl_process_coap(struct nsdl_s *handle, uint8_t *packet, uint16_t packet_len, sn_nsdl_addr_s *src); - -/** - * \fn extern int8_t sn_nsdl_exec(struct nsdl_s *handle, uint32_t time); - * - * \brief CoAP retransmission function. - * - * Used to give execution time for the mbed Device C Client library for retransmissions. - * - * \param *handle Pointer to nsdl-library handle - * - * \param time Time in seconds. - * - * \return 0 Success - * \return -1 Failure - */ -extern int8_t sn_nsdl_exec(struct nsdl_s *handle, uint32_t time); - -#ifndef MEMORY_OPTIMIZED_API -/** - * \fn extern int8_t sn_nsdl_create_resource(struct nsdl_s *handle, const sn_nsdl_resource_parameters_s *res); - * - * \brief Resource creating function. - * - * Used to create a static or dynamic CoAP resource. - * - * \param *res Pointer to a structure of type sn_nsdl_resource_info_t that contains the information - * about the resource. - * - * \return 0 Success - * \return -1 Failure - * \return -2 Resource already exists - * \return -3 Invalid path - * \return -4 List adding failure - */ -extern int8_t sn_nsdl_create_resource(struct nsdl_s *handle, sn_nsdl_dynamic_resource_parameters_s *res); - -/** - * \fn extern int8_t sn_nsdl_update_resource(struct nsdl_s *handle, sn_nsdl_resource_parameters_s *res) - * - * \brief Resource updating function. - * - * Used to update the direct value of a static resource, the callback function pointer of a dynamic resource - * and access rights of the recource. - * - * \param *handle Pointer to nsdl-library handle - * \param *res Pointer to a structure of type sn_nsdl_resource_info_t that contains the information - * about the resource. Only the pathlen and path elements are evaluated along with - * either resourcelen and resource or the function pointer. - * - * \return 0 Success - * \return -1 Failure - */ -extern int8_t sn_nsdl_update_resource(struct nsdl_s *handle, sn_nsdl_dynamic_resource_parameters_s *res); -#endif - -/** - * \fn extern int8_t sn_nsdl_put_resource(struct nsdl_s *handle, const sn_nsdl_dynamic_resource_parameters_s *res); - * - * \brief Resource putting function. - * - * Used to put a static or dynamic CoAP resource without creating copy of it. - * NOTE: Remember that only resource will be owned, not data that it contains - * NOTE: The resource may be removed from list by sn_nsdl_pop_resource(). - * - * \param *res Pointer to a structure of type sn_nsdl_dynamic_resource_parameters_s that contains the information - * about the resource. - * - * \return 0 Success - * \return -1 Failure - * \return -2 Resource already exists - * \return -3 Invalid path - * \return -4 List adding failure - */ -extern int8_t sn_nsdl_put_resource(struct nsdl_s *handle, sn_nsdl_dynamic_resource_parameters_s *res); - -/** - * \fn extern int8_t sn_nsdl_pop_resource(struct nsdl_s *handle, const sn_nsdl_dynamic_resource_parameters_s *res); - * - * \brief Resource popping function. - * - * Used to remove a static or dynamic CoAP resource from lists without deleting it. - * NOTE: This function is a counterpart of sn_nsdl_put_resource(). - * - * \param *res Pointer to a structure of type sn_nsdl_dynamic_resource_parameters_s that contains the information - * about the resource. - * - * \return 0 Success - * \return -1 Failure - * \return -3 Invalid path - */ -extern int8_t sn_nsdl_pop_resource(struct nsdl_s *handle, sn_nsdl_dynamic_resource_parameters_s *res); - -/** - * \fn extern int8_t sn_nsdl_delete_resource(struct nsdl_s *handle, uint8_t pathlen, uint8_t *path) - * - * \brief Resource delete function. - * - * Used to delete a resource. If resource has a subresources, these all must also be removed. - * - * \param *handle Pointer to nsdl-library handle - * \param pathlen Contains the length of the path that is to be deleted (excluding possible trailing "\0"). - * \param *path_ptr A pointer to an array containing the path. - * - * \return 0 Success - * \return -1 Failure (No such resource) - */ -extern int8_t sn_nsdl_delete_resource(struct nsdl_s *handle, uint16_t pathlen, uint8_t *path); - -/** - * \fn extern sn_nsdl_dynamic_resource_parameters_s *sn_nsdl_get_resource(struct nsdl_s *handle, uint16_t pathlen, uint8_t *path) - * - * \brief Resource get function. - * - * Used to get a resource. - * - * \param *handle Pointer to nsdl-library handle - * \param pathlen Contains the length of the path that is to be returned (excluding possible trailing '\0'). - * \param *path A pointer to an array containing the path. - * - * \return !NULL Success, pointer to a sn_nsdl_dynamic_resource_parameters_s that contains the resource information\n - * \return NULL Failure - */ -extern sn_nsdl_dynamic_resource_parameters_s *sn_nsdl_get_resource(struct nsdl_s *handle, uint16_t pathlen, uint8_t *path); - -/** - * \fn extern sn_grs_resource_list_s *sn_nsdl_list_resource(struct nsdl_s *handle, uint16_t pathlen, uint8_t *path) - * - * \brief Resource list function. - * - * \param *handle Pointer to nsdl-library handle - * \param pathlen Contains the length of the target path (excluding possible trailing '\0'). - * The length value is not examined if the path itself is a NULL pointer. - * \param *path A pointer to an array containing the path or a NULL pointer. - * - * \return !NULL A pointer to a sn_grs_resource_list_s structure containing the resource listing. - * \return NULL Failure with an unspecified error - */ -sn_grs_resource_list_s *sn_nsdl_list_resource(struct nsdl_s *handle, uint16_t pathlen, uint8_t *path); - -/** - * \fn extern void sn_nsdl_free_resource_list(struct nsdl_s *handle, sn_grs_resource_list_s *list) - * - * \brief Free a resource list obtained from sn_nsdl_list_resource() - * - * \param list The list to free, or NULL. - */ -void sn_nsdl_free_resource_list(struct nsdl_s *handle, sn_grs_resource_list_s *list); - -/** - * \fn extern int8_t sn_nsdl_send_coap_message(struct nsdl_s *handle, sn_nsdl_addr_s *address_ptr, sn_coap_hdr_s *coap_hdr_ptr); - * - * \brief Send an outgoing CoAP request. - * - * \param *handle Pointer to nsdl-library handle - * \param *address_ptr Pointer to source address struct - * \param *coap_hdr_ptr Pointer to CoAP message to be sent - * - * \return 0 Success - * \return -1 Failure - */ -extern int8_t sn_nsdl_send_coap_message(struct nsdl_s *handle, sn_nsdl_addr_s *address_ptr, sn_coap_hdr_s *coap_hdr_ptr); - -/** - * \fn extern int8_t set_NSP_address(struct nsdl_s *handle, uint8_t *NSP_address, uint8_t address_length, uint16_t port, sn_nsdl_addr_type_e address_type); - * - * \brief This function is used to set the mbed Device Server address given by an application. - * - * \param *handle Pointer to nsdl-library handle - * \return 0 Success - * \return -1 Failed to indicate that internal address pointer is not allocated (call nsdl_init() first). - */ -extern int8_t set_NSP_address(struct nsdl_s *handle, uint8_t *NSP_address, uint8_t address_length, uint16_t port, sn_nsdl_addr_type_e address_type); - -/** - * \fn extern int8_t sn_nsdl_destroy(struct nsdl_s *handle); - * - * \param *handle Pointer to nsdl-library handle - * \brief This function releases all allocated memory in mbed Device C Client library. - */ -extern int8_t sn_nsdl_destroy(struct nsdl_s *handle); - -/** - * \fn extern uint16_t sn_nsdl_oma_bootstrap(struct nsdl_s *handle, sn_nsdl_addr_s *bootstrap_address_ptr, sn_nsdl_ep_parameters_s *endpoint_info_ptr, sn_nsdl_bs_ep_info_t *bootstrap_endpoint_info_ptr); - * - * \brief Starts OMA bootstrap process - * - * \param *handle Pointer to nsdl-library handle - * - * \return bootstrap message ID, 0 if failed - */ -extern uint16_t sn_nsdl_oma_bootstrap(struct nsdl_s *handle, sn_nsdl_addr_s *bootstrap_address_ptr, sn_nsdl_ep_parameters_s *endpoint_info_ptr, sn_nsdl_bs_ep_info_t *bootstrap_endpoint_info_ptr); - -/** - * \fn sn_coap_hdr_s *sn_nsdl_build_response(struct nsdl_s *handle, sn_coap_hdr_s *coap_packet_ptr, uint8_t msg_code) - * - * \brief Prepares generic response packet from a request packet. This function allocates memory for the resulting sn_coap_hdr_s - * - * \param *handle Pointer to library handle - * \param *coap_packet_ptr The request packet pointer - * \param msg_code response messages code - * - * \return *coap_packet_ptr The allocated and pre-filled response packet pointer - * NULL Error in parsing the request - * - */ -extern sn_coap_hdr_s *sn_nsdl_build_response(struct nsdl_s *handle, sn_coap_hdr_s *coap_packet_ptr, uint8_t msg_code); - -/** - * \brief Allocates and initializes options list structure - * - * \param *handle Pointer to library handle - * \param *coap_msg_ptr is pointer to CoAP message that will contain the options - * - * If the message already has a pointer to an option structure, that pointer - * is returned, rather than a new structure being allocated. - * - * \return Return value is pointer to the CoAP options structure.\n - * In following failure cases NULL is returned:\n - * -Failure in given pointer (= NULL)\n - * -Failure in memory allocation (malloc() returns NULL) - */ -extern sn_coap_options_list_s *sn_nsdl_alloc_options_list(struct nsdl_s *handle, sn_coap_hdr_s *coap_msg_ptr); - -/** - * \fn void sn_nsdl_release_allocated_coap_msg_mem(struct nsdl_s *handle, sn_coap_hdr_s *freed_coap_msg_ptr) - * - * \brief Releases memory of given CoAP message - * - * Note!!! Does not release Payload part - * - * \param *handle Pointer to library handle - * - * \param *freed_coap_msg_ptr is pointer to released CoAP message - */ -extern void sn_nsdl_release_allocated_coap_msg_mem(struct nsdl_s *handle, sn_coap_hdr_s *freed_coap_msg_ptr); - -/** - * \fn int8_t sn_nsdl_set_retransmission_parameters(struct nsdl_s *handle, uint8_t resending_count, uint8_t resending_intervall) - * - * \brief If re-transmissions are enabled, this function changes resending count and interval. - * - * \param *handle Pointer to library handle - * \param uint8_t resending_count max number of resendings for message - * \param uint8_t resending_intervall message resending intervall in seconds - * \return 0 = success, -1 = failure - */ -extern int8_t sn_nsdl_set_retransmission_parameters(struct nsdl_s *handle, uint8_t resending_count, uint8_t resending_interval); - -/** - * \fn int8_t sn_nsdl_set_retransmission_buffer(struct nsdl_s *handle, uint8_t buffer_size_messages, uint16_t buffer_size_bytes) - * - * \brief If re-transmissions are enabled, this function changes message retransmission queue size. - * Set size to '0' to disable feature. If both are set to '0', then re-sendings are disabled. - * - * \param *handle Pointer to library handle - * \param uint8_t buffer_size_messages queue size - maximum number of messages to be saved to queue - * \param uint8_t buffer_size_bytes queue size - maximum size of messages saved to queue - * \return 0 = success, -1 = failure - */ -extern int8_t sn_nsdl_set_retransmission_buffer(struct nsdl_s *handle, - uint8_t buffer_size_messages, uint16_t buffer_size_bytes); - -/** - * \fn int8_t sn_nsdl_set_block_size(struct nsdl_s *handle, uint16_t block_size) - * - * \brief If block transfer is enabled, this function changes the block size. - * - * \param *handle Pointer to library handle - * \param uint16_t block_size maximum size of CoAP payload. Valid sizes are 16, 32, 64, 128, 256, 512 and 1024 bytes - * \return 0 = success, -1 = failure - */ -extern int8_t sn_nsdl_set_block_size(struct nsdl_s *handle, uint16_t block_size); - -/** - * \fn int8_t sn_nsdl_set_duplicate_buffer_size(struct nsdl_s *handle,uint8_t message_count) - * - * \brief If dublicate message detection is enabled, this function changes buffer size. - * - * \param *handle Pointer to library handle - * \param uint8_t message_count max number of messages saved for duplicate control - * \return 0 = success, -1 = failure - */ -extern int8_t sn_nsdl_set_duplicate_buffer_size(struct nsdl_s *handle, uint8_t message_count); - -/** - * \fn void *sn_nsdl_set_context(const struct nsdl_s *handle, void *context) - * - * \brief Set the application defined context parameter for given handle. - * This is useful for example when interfacing with c++ objects where a - * pointer to object is set as the context, and in the callback functions - * the context pointer can be used to call methods for the correct instance - * of the c++ object. - * - * \param *handle Pointer to library handle - * \param *context Pointer to the application defined context - * \return 0 = success, -1 = failure - */ -extern int8_t sn_nsdl_set_context(struct nsdl_s * const handle, void * const context); - -/** - * \fn void *sn_nsdl_get_context(const struct nsdl_s *handle) - * - * \brief Get the application defined context parameter for given handle. - * This is useful for example when interfacing with c++ objects where a - * pointer to object is set as the context, and in the callback functions - * the context pointer can be used to call methods for the correct instance - * of the c++ object. - * - * \param *handle Pointer to library handle - * \return Pointer to the application defined context - */ -extern void *sn_nsdl_get_context(const struct nsdl_s * const handle); - -#ifdef __cplusplus -} -#endif -#endif /* MBED_CLIENT_C_NEW_API */ -#endif /* SN_NSDL_LIB_2_H_ */ diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/source/libNsdl/src/include/sn_grs.h b/features/FEATURE_COMMON_PAL/mbed-client-c/source/libNsdl/src/include/sn_grs.h deleted file mode 100755 index d9329cacf6..0000000000 --- a/features/FEATURE_COMMON_PAL/mbed-client-c/source/libNsdl/src/include/sn_grs.h +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Copyright (c) 2011-2015 ARM Limited. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 - * Licensed under the Apache License, Version 2.0 (the License); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef GRS_H_ -#define GRS_H_ - -#ifdef MBED_CLIENT_C_NEW_API - -#include "sn_grs2.h" - -#else - -#ifdef __cplusplus -extern "C" { -#endif - - -#define SN_GRS_RESOURCE_ALREADY_EXISTS -2 -#define SN_GRS_INVALID_PATH -3 -#define SN_GRS_LIST_ADDING_FAILURE -4 -#define SN_GRS_RESOURCE_UPDATED -5 - -#define ACCESS_DENIED -6 - -#define SN_GRS_DELETE_METHOD 0 -#define SN_GRS_SEARCH_METHOD 1 - -#define SN_GRS_DEFAULT_ACCESS 0x0F - -#define SN_NDSL_RESOURCE_NOT_REGISTERED 0 -#define SN_NDSL_RESOURCE_REGISTERING 1 -#define SN_NDSL_RESOURCE_REGISTERED 2 - -/***** Structs *****/ - -typedef struct sn_grs_version_ { - uint8_t major_version; - uint8_t minor_version; - uint8_t build; -} sn_grs_version_s; - -typedef NS_LIST_HEAD(sn_nsdl_resource_info_s, link) resource_list_t; - -struct grs_s { - struct coap_s *coap; - - void *(*sn_grs_alloc)(uint16_t); - void (*sn_grs_free)(void *); - uint8_t (*sn_grs_tx_callback)(struct nsdl_s *, sn_nsdl_capab_e , uint8_t *, uint16_t, sn_nsdl_addr_s *); - int8_t (*sn_grs_rx_callback)(struct nsdl_s *, sn_coap_hdr_s *, sn_nsdl_addr_s *); - - uint16_t resource_root_count; - resource_list_t resource_root_list; -}; - - -struct nsdl_s { - uint16_t update_register_msg_id; - uint16_t register_msg_len; - uint16_t update_register_msg_len; - - uint16_t register_msg_id; - uint16_t unregister_msg_id; - - uint16_t bootstrap_msg_id; - uint16_t oma_bs_port; /* Bootstrap port */ - uint8_t oma_bs_address_len; /* Bootstrap address length */ - unsigned int sn_nsdl_endpoint_registered:1; - bool handle_bootstrap_msg:1; - - struct grs_s *grs; - uint8_t *oma_bs_address_ptr; /* Bootstrap address pointer. If null, no bootstrap in use */ - sn_nsdl_ep_parameters_s *ep_information_ptr; // Endpoint parameters, Name, Domain etc.. - sn_nsdl_oma_server_info_t *nsp_address_ptr; // NSP server address information - /* Application definable context. This is useful for example when interfacing with c++ objects where a pointer to object is set as the - * context, and in the callback functions the context pointer can be used to call methods for the correct instance of the c++ object. */ - void *context; - - void (*sn_nsdl_oma_bs_done_cb)(sn_nsdl_oma_server_info_t *server_info_ptr); /* Callback to inform application when bootstrap is done */ - void *(*sn_nsdl_alloc)(uint16_t); - void (*sn_nsdl_free)(void *); - uint8_t (*sn_nsdl_tx_callback)(struct nsdl_s *, sn_nsdl_capab_e , uint8_t *, uint16_t, sn_nsdl_addr_s *); - uint8_t (*sn_nsdl_rx_callback)(struct nsdl_s *, sn_coap_hdr_s *, sn_nsdl_addr_s *); - void (*sn_nsdl_oma_bs_done_cb_handle)(sn_nsdl_oma_server_info_t *server_info_ptr, - struct nsdl_s *handle); /* Callback to inform application when bootstrap is done with nsdl handle */ -}; - -/***** Function prototypes *****/ -/** - * \fn extern grs_s *sn_grs_init (uint8_t (*sn_grs_tx_callback_ptr)(sn_nsdl_capab_e , uint8_t *, uint16_t, - * sn_nsdl_addr_s *), uint8_t (*sn_grs_rx_callback_ptr)(sn_coap_hdr_s *, sn_nsdl_addr_s *), - * sn_grs_mem_s *sn_memory) - * - * \brief GRS library initialize function. - * - * This function initializes GRS and CoAP. - * - * \param sn_grs_tx_callback A function pointer to a transmit callback function. Should return 1 when succeed, 0 when failed - * \param *sn_grs_rx_callback_ptr A function pointer to a receiving callback function. If received packet is not for GRS, it will be passed to - * upper level (NSDL) to be proceed. - * \param sn_memory A pointer to a structure containing the platform specific functions for memory allocation and free. - * - * \return success pointer to handle, failure = NULL - * -*/ -extern struct grs_s *sn_grs_init(uint8_t (*sn_grs_tx_callback_ptr)(struct nsdl_s *, sn_nsdl_capab_e , uint8_t *, uint16_t, - sn_nsdl_addr_s *), int8_t (*sn_grs_rx_callback_ptr)(struct nsdl_s *, sn_coap_hdr_s *, sn_nsdl_addr_s *), void *(*sn_grs_alloc)(uint16_t), void (*sn_grs_free)(void *)); - -extern const sn_nsdl_resource_info_s *sn_grs_get_first_resource(struct grs_s *handle); -extern const sn_nsdl_resource_info_s *sn_grs_get_next_resource(struct grs_s *handle, const sn_nsdl_resource_info_s *sn_grs_current_resource); -extern int8_t sn_grs_process_coap(struct nsdl_s *handle, sn_coap_hdr_s *coap_packet_ptr, sn_nsdl_addr_s *src); -extern sn_nsdl_resource_info_s *sn_grs_search_resource(struct grs_s *handle, uint16_t pathlen, uint8_t *path, uint8_t search_method); -extern int8_t sn_grs_destroy(struct grs_s *handle); -extern sn_grs_resource_list_s *sn_grs_list_resource(struct grs_s *handle, uint16_t pathlen, uint8_t *path); -extern void sn_grs_free_resource_list(struct grs_s *handle, sn_grs_resource_list_s *list); -extern int8_t sn_grs_update_resource(struct grs_s *handle, sn_nsdl_resource_info_s *res); -extern int8_t sn_grs_send_coap_message(struct nsdl_s *handle, sn_nsdl_addr_s *address_ptr, sn_coap_hdr_s *coap_hdr_ptr); -extern int8_t sn_grs_create_resource(struct grs_s *handle, sn_nsdl_resource_info_s *res); -extern int8_t sn_grs_put_resource(struct grs_s *handle, sn_nsdl_resource_info_s *res); -extern int8_t sn_grs_delete_resource(struct grs_s *handle, uint16_t pathlen, uint8_t *path); -extern void sn_grs_mark_resources_as_registered(struct nsdl_s *handle); - -#ifdef __cplusplus -} -#endif - -#endif /* MBED_CLIENT_C_NEW_API */ - - -#endif /* GRS_H_ */ diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/source/libNsdl/src/include/sn_grs2.h b/features/FEATURE_COMMON_PAL/mbed-client-c/source/libNsdl/src/include/sn_grs2.h deleted file mode 100755 index 8c777bbe8d..0000000000 --- a/features/FEATURE_COMMON_PAL/mbed-client-c/source/libNsdl/src/include/sn_grs2.h +++ /dev/null @@ -1,150 +0,0 @@ -/* - * Copyright (c) 2011-2015 ARM Limited. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 - * Licensed under the Apache License, Version 2.0 (the License); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef GRS_2_H_ -#define GRS_2_H_ - -#ifdef MBED_CLIENT_C_NEW_API - -#ifdef __cplusplus -extern "C" { -#endif - - -#define SN_GRS_RESOURCE_ALREADY_EXISTS -2 -#define SN_GRS_INVALID_PATH -3 -#define SN_GRS_LIST_ADDING_FAILURE -4 -#define SN_GRS_RESOURCE_UPDATED -5 - -#define ACCESS_DENIED -6 - -#define SN_GRS_DELETE_METHOD 0 -#define SN_GRS_SEARCH_METHOD 1 - -#define SN_GRS_DEFAULT_ACCESS 0x0F - -#define SN_NDSL_RESOURCE_NOT_REGISTERED 0 -#define SN_NDSL_RESOURCE_REGISTERING 1 -#define SN_NDSL_RESOURCE_REGISTERED 2 - -/***** Structs *****/ - -typedef struct sn_grs_version_ { - uint8_t major_version; - uint8_t minor_version; - uint8_t build; -} sn_grs_version_s; - -typedef NS_LIST_HEAD(sn_nsdl_dynamic_resource_parameters_s, link) resource_list_t; - -struct grs_s { - struct coap_s *coap; - - void *(*sn_grs_alloc)(uint16_t); - void (*sn_grs_free)(void *); - uint8_t (*sn_grs_tx_callback)(struct nsdl_s *, sn_nsdl_capab_e , uint8_t *, uint16_t, sn_nsdl_addr_s *); - int8_t (*sn_grs_rx_callback)(struct nsdl_s *, sn_coap_hdr_s *, sn_nsdl_addr_s *); - - uint16_t resource_root_count; - resource_list_t resource_root_list; -}; - - -struct nsdl_s { - uint16_t update_register_msg_id; - uint16_t register_msg_len; - uint16_t update_register_msg_len; - - uint16_t register_msg_id; - uint16_t unregister_msg_id; - - uint16_t bootstrap_msg_id; - uint16_t oma_bs_port; /* Bootstrap port */ - uint8_t oma_bs_address_len; /* Bootstrap address length */ - unsigned int sn_nsdl_endpoint_registered:1; - - struct grs_s *grs; - uint8_t *oma_bs_address_ptr; /* Bootstrap address pointer. If null, no bootstrap in use */ - sn_nsdl_ep_parameters_s *ep_information_ptr; // Endpoint parameters, Name, Domain etc.. - sn_nsdl_oma_server_info_t *nsp_address_ptr; // NSP server address information - /* Application definable context. This is useful for example when interfacing with c++ objects where a pointer to object is set as the - * context, and in the callback functions the context pointer can be used to call methods for the correct instance of the c++ object. */ - void *context; - - void (*sn_nsdl_oma_bs_done_cb)(sn_nsdl_oma_server_info_t *server_info_ptr); /* Callback to inform application when bootstrap is done */ - void *(*sn_nsdl_alloc)(uint16_t); - void (*sn_nsdl_free)(void *); - uint8_t (*sn_nsdl_tx_callback)(struct nsdl_s *, sn_nsdl_capab_e , uint8_t *, uint16_t, sn_nsdl_addr_s *); - uint8_t (*sn_nsdl_rx_callback)(struct nsdl_s *, sn_coap_hdr_s *, sn_nsdl_addr_s *); - void (*sn_nsdl_oma_bs_done_cb_handle)(sn_nsdl_oma_server_info_t *server_info_ptr, - struct nsdl_s *handle); /* Callback to inform application when bootstrap is done with nsdl handle */ -}; - -/***** Function prototypes *****/ -/** - * \fn extern grs_s *sn_grs_init (uint8_t (*sn_grs_tx_callback_ptr)(sn_nsdl_capab_e , uint8_t *, uint16_t, - * sn_nsdl_addr_s *), uint8_t (*sn_grs_rx_callback_ptr)(sn_coap_hdr_s *, sn_nsdl_addr_s *), - * sn_grs_mem_s *sn_memory) - * - * \brief GRS library initialize function. - * - * This function initializes GRS and CoAP. - * - * \param sn_grs_tx_callback A function pointer to a transmit callback function. Should return 1 when succeed, 0 when failed - * \param *sn_grs_rx_callback_ptr A function pointer to a receiving callback function. If received packet is not for GRS, it will be passed to - * upper level (NSDL) to be proceed. - * \param sn_memory A pointer to a structure containing the platform specific functions for memory allocation and free. - * - * \return success pointer to handle, failure = NULL - * -*/ -extern struct grs_s *sn_grs_init(uint8_t (*sn_grs_tx_callback_ptr)(struct nsdl_s *, sn_nsdl_capab_e , uint8_t *, uint16_t, - sn_nsdl_addr_s *), - int8_t (*sn_grs_rx_callback_ptr)(struct nsdl_s *, sn_coap_hdr_s *, sn_nsdl_addr_s *), - void *(*sn_grs_alloc)(uint16_t), - void (*sn_grs_free)(void *)); - -extern sn_nsdl_dynamic_resource_parameters_s *sn_grs_get_first_resource(struct grs_s *handle); -extern sn_nsdl_dynamic_resource_parameters_s *sn_grs_get_next_resource(struct grs_s *handle, - const sn_nsdl_dynamic_resource_parameters_s *sn_grs_current_resource); -extern int8_t sn_grs_process_coap(struct nsdl_s *handle, - sn_coap_hdr_s *coap_packet_ptr, - sn_nsdl_addr_s *src); -extern sn_nsdl_dynamic_resource_parameters_s *sn_grs_search_resource(struct grs_s *handle, - uint16_t pathlen, - uint8_t *path, - uint8_t search_method); -extern int8_t sn_grs_destroy(struct grs_s *handle); -extern sn_grs_resource_list_s *sn_grs_list_resource(struct grs_s *handle, uint16_t pathlen, uint8_t *path); -extern void sn_grs_free_resource_list(struct grs_s *handle, sn_grs_resource_list_s *list); -extern int8_t sn_grs_send_coap_message(struct nsdl_s *handle, - sn_nsdl_addr_s *address_ptr, - sn_coap_hdr_s *coap_hdr_ptr); -extern int8_t sn_grs_put_resource(struct grs_s *handle, sn_nsdl_dynamic_resource_parameters_s *res); -extern int8_t sn_grs_pop_resource(struct grs_s *handle, sn_nsdl_dynamic_resource_parameters_s *res); -extern int8_t sn_grs_delete_resource(struct grs_s *handle, uint16_t pathlen, uint8_t *path); -extern void sn_grs_mark_resources_as_registered(struct nsdl_s *handle); -#ifndef MEMORY_OPTIMIZED_API -extern int8_t sn_grs_create_resource(struct grs_s *handle, sn_nsdl_dynamic_resource_parameters_s *res); -extern int8_t sn_grs_update_resource(struct grs_s *handle, sn_nsdl_dynamic_resource_parameters_s *res); -#endif - -#ifdef __cplusplus -} -#endif - -#endif /* MBED_CLIENT_C_NEW_API */ - -#endif /* GRS_H_ */ diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/source/libNsdl/src/sn_grs.c b/features/FEATURE_COMMON_PAL/mbed-client-c/source/libNsdl/src/sn_grs.c deleted file mode 100755 index 144dd201f2..0000000000 --- a/features/FEATURE_COMMON_PAL/mbed-client-c/source/libNsdl/src/sn_grs.c +++ /dev/null @@ -1,1042 +0,0 @@ -/* - * Copyright (c) 2011-2015 ARM Limited. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 - * Licensed under the Apache License, Version 2.0 (the License); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * - * \file sn_grs.c - * - * \brief General resource server. - * - */ - -#ifndef MBED_CLIENT_C_NEW_API - -#include -#include - -#include "ns_list.h" -#include "ns_types.h" -#include "sn_nsdl.h" -#include "sn_coap_header.h" -#include "sn_coap_protocol.h" -#include "sn_coap_protocol_internal.h" -#include "sn_nsdl_lib.h" -#include "sn_grs.h" -#include "mbed-trace/mbed_trace.h" - -/* Defines */ -#define TRACE_GROUP "coap" -#define WELLKNOWN_PATH_LEN 16 -#define WELLKNOWN_PATH (".well-known/core") - -/* Local static function prototypes */ -static int8_t sn_grs_resource_info_free(struct grs_s *handle, sn_nsdl_resource_info_s *resource_ptr); -static uint8_t *sn_grs_convert_uri(uint16_t *uri_len, uint8_t *uri_ptr); -static int8_t sn_grs_add_resource_to_list(struct grs_s *handle, sn_nsdl_resource_info_s *resource_ptr); -static int8_t sn_grs_core_request(struct nsdl_s *handle, sn_nsdl_addr_s *src_addr_ptr, sn_coap_hdr_s *coap_packet_ptr); -static uint8_t coap_tx_callback(uint8_t *, uint16_t, sn_nsdl_addr_s *, void *); -static int8_t coap_rx_callback(sn_coap_hdr_s *coap_ptr, sn_nsdl_addr_s *address_ptr, void *param); - -/* Extern function prototypes */ -extern int8_t sn_nsdl_build_registration_body(struct nsdl_s *handle, sn_coap_hdr_s *message_ptr, uint8_t updating_registeration); - -/** - * \fn int8_t sn_grs_destroy(void) - * \brief This function may be used to flush GRS related stuff when a program exits. - * @return always 0. - */ -extern int8_t sn_grs_destroy(struct grs_s *handle) -{ - if( handle == NULL ){ - return 0; - } - ns_list_foreach_safe(sn_nsdl_resource_info_s, tmp, &handle->resource_root_list) { - ns_list_remove(&handle->resource_root_list, tmp); - --handle->resource_root_count; - sn_grs_resource_info_free(handle, tmp); - } - handle->sn_grs_free(handle); - - return 0; -} - -static uint8_t coap_tx_callback(uint8_t *data_ptr, uint16_t data_len, sn_nsdl_addr_s *address_ptr, void *param) -{ - struct nsdl_s *handle = (struct nsdl_s *)param; - - if (handle == NULL) { - return 0; - } - - return handle->grs->sn_grs_tx_callback(handle, SN_NSDL_PROTOCOL_COAP, data_ptr, data_len, address_ptr); -} - -static int8_t coap_rx_callback(sn_coap_hdr_s *coap_ptr, sn_nsdl_addr_s *address_ptr, void *param) -{ - struct nsdl_s *handle = (struct nsdl_s *)param; - - if (handle == NULL) { - return 0; - } - - return handle->sn_nsdl_rx_callback(handle, coap_ptr, address_ptr); -} - -/** - * \fn int8_t sn_grs_init (uint8_t (*sn_grs_tx_callback_ptr)(sn_nsdl_capab_e , uint8_t *, uint16_t, - * sn_nsdl_addr_s *), int8_t (*sn_grs_rx_callback_ptr)(sn_coap_hdr_s *, sn_nsdl_addr_s *), sn_nsdl_mem_s *sn_memory) - * - * \brief GRS library initialize function. - * - * This function initializes GRS and CoAP libraries. - * - * \param sn_grs_tx_callback A function pointer to a transmit callback function. - * \param *sn_grs_rx_callback_ptr A function pointer to a receiving callback function. If received packet is not for GRS, it will be passed to - * upper level (NSDL) to be proceed. - * \param sn_memory A pointer to a structure containing the platform specific functions for memory allocation and free. - * - * \return success = 0, failure = -1 - * -*/ -extern struct grs_s *sn_grs_init(uint8_t (*sn_grs_tx_callback_ptr)(struct nsdl_s *, sn_nsdl_capab_e , uint8_t *, uint16_t, - sn_nsdl_addr_s *), int8_t (*sn_grs_rx_callback_ptr)(struct nsdl_s *, sn_coap_hdr_s *, sn_nsdl_addr_s *), - void *(*sn_grs_alloc)(uint16_t), void (*sn_grs_free)(void *)) -{ - - struct grs_s *handle_ptr = NULL; - - /* Check parameters */ - if (sn_grs_alloc == NULL || sn_grs_free == NULL || - sn_grs_tx_callback_ptr == NULL || sn_grs_rx_callback_ptr == NULL) { - return NULL; - } - - handle_ptr = sn_grs_alloc(sizeof(struct grs_s)); - - if (handle_ptr == NULL) { - return NULL; - } - - memset(handle_ptr, 0, sizeof(struct grs_s)); - - /* Allocation and free - function pointers */ - handle_ptr->sn_grs_alloc = sn_grs_alloc; - handle_ptr->sn_grs_free = sn_grs_free; - - /* TX callback function pointer */ - handle_ptr->sn_grs_tx_callback = sn_grs_tx_callback_ptr; - handle_ptr->sn_grs_rx_callback = sn_grs_rx_callback_ptr; - - /* Initialize CoAP protocol library */ - handle_ptr->coap = sn_coap_protocol_init(sn_grs_alloc, sn_grs_free, coap_tx_callback, coap_rx_callback); - - return handle_ptr; -} - - -extern sn_grs_resource_list_s *sn_grs_list_resource(struct grs_s *handle, uint16_t pathlen, uint8_t *path) -{ - (void) pathlen; - sn_grs_resource_list_s *grs_resource_list_ptr = NULL; - - if( handle == NULL || path == NULL){ - return NULL; - } - - /* Allocate memory for the resource list to be filled */ - grs_resource_list_ptr = handle->sn_grs_alloc(sizeof(sn_grs_resource_list_s)); - if (!grs_resource_list_ptr) { - goto fail; - } - - /* Count resources to the resource list struct */ - grs_resource_list_ptr->res_count = handle->resource_root_count; - grs_resource_list_ptr->res = NULL; - - /**************************************/ - /* Fill resource structs to the table */ - /**************************************/ - - /* If resources in list */ - if (grs_resource_list_ptr->res_count) { - int i; - - /* Allocate memory for resources */ - grs_resource_list_ptr->res = handle->sn_grs_alloc(grs_resource_list_ptr->res_count * sizeof(sn_grs_resource_s)); - if (!grs_resource_list_ptr->res) { - goto fail; - } - - /* Initialise the pointers to NULL to permit easy cleanup */ - for (i = 0; i < grs_resource_list_ptr->res_count; i++) { - grs_resource_list_ptr->res[i].path = NULL; - grs_resource_list_ptr->res[i].pathlen = 0; - } - - i = 0; - ns_list_foreach(sn_nsdl_resource_info_s, grs_resource_ptr, &handle->resource_root_list) { - /* Copy pathlen to resource list */ - grs_resource_list_ptr->res[i].pathlen = grs_resource_ptr->pathlen; - - /* Allocate memory for path string */ - grs_resource_list_ptr->res[i].path = handle->sn_grs_alloc(grs_resource_list_ptr->res[i].pathlen); - if (!grs_resource_list_ptr->res[i].path) { - goto fail; - } - - /* Copy pathstring to resource list */ - memcpy(grs_resource_list_ptr->res[i].path, grs_resource_ptr->path, grs_resource_ptr->pathlen); - - i++; - } - } - return grs_resource_list_ptr; - -fail: - sn_grs_free_resource_list(handle, grs_resource_list_ptr); - return NULL; -} - -extern void sn_grs_free_resource_list(struct grs_s *handle, sn_grs_resource_list_s *list) -{ - if (!list || !handle) { - return; - } - - if (list->res) { - for (int i = 0; i < list->res_count; i++) { - if (list->res[i].path) { - handle->sn_grs_free(list->res[i].path); - list->res[i].path = NULL; - } - } - handle->sn_grs_free(list->res); - list->res = NULL; - } - - handle->sn_grs_free(list); -} - -extern const sn_nsdl_resource_info_s *sn_grs_get_first_resource(struct grs_s *handle) -{ - if( !handle ){ - return NULL; - } - return ns_list_get_first(&handle->resource_root_list); -} - -extern const sn_nsdl_resource_info_s *sn_grs_get_next_resource(struct grs_s *handle, const sn_nsdl_resource_info_s *sn_grs_current_resource) -{ - if( !handle || !sn_grs_current_resource ){ - return NULL; - } - return ns_list_get_next(&handle->resource_root_list, sn_grs_current_resource); -} - -extern int8_t sn_grs_delete_resource(struct grs_s *handle, uint16_t pathlen, uint8_t *path) -{ - /* Local variables */ - sn_nsdl_resource_info_s *resource_temp = NULL; - - /* Search if resource found */ - resource_temp = sn_grs_search_resource(handle, pathlen, path, SN_GRS_SEARCH_METHOD); - - /* If not found */ - if (resource_temp == NULL) { - return SN_NSDL_FAILURE; - } - - /* If found, delete it and delete also subresources, if there is any */ - do { - /* Remove from list */ - ns_list_remove(&handle->resource_root_list, resource_temp); - --handle->resource_root_count; - - /* Free */ - sn_grs_resource_info_free(handle, resource_temp); - - /* Search for subresources */ - resource_temp = sn_grs_search_resource(handle, pathlen, path, SN_GRS_DELETE_METHOD); - } while (resource_temp != NULL); - - return SN_NSDL_SUCCESS; -} - -extern int8_t sn_grs_update_resource(struct grs_s *handle, sn_nsdl_resource_info_s *res) -{ - /* Local variables */ - sn_nsdl_resource_info_s *resource_temp = NULL; - - if( !res || !handle ){ - return SN_NSDL_FAILURE; - } - - /* Search resource */ - resource_temp = sn_grs_search_resource(handle, res->pathlen, res->path, SN_GRS_SEARCH_METHOD); - if (!resource_temp) { - return SN_NSDL_FAILURE; - } - - /* If there is payload on resource, free it */ - if (resource_temp->resource != NULL) { - handle->sn_grs_free(resource_temp->resource); - resource_temp->resource = 0; - } - /* Update resource len */ - resource_temp->resourcelen = res->resourcelen; - - /* If resource len >0, allocate memory and copy payload */ - if (res->resourcelen) { - resource_temp->resource = handle->sn_grs_alloc(res->resourcelen); - if (resource_temp->resource == NULL) { - - resource_temp->resourcelen = 0; - return SN_NSDL_FAILURE; - - } - - memcpy(resource_temp->resource, res->resource, resource_temp->resourcelen); - } - - /* Update access rights and callback address */ - resource_temp->access = res->access; - resource_temp->sn_grs_dyn_res_callback = res->sn_grs_dyn_res_callback; - - /* TODO: resource_parameters_ptr not copied */ - - return SN_NSDL_SUCCESS; -} - -extern int8_t sn_grs_create_resource(struct grs_s *handle, sn_nsdl_resource_info_s *res) -{ - if (!res || !handle) { - return SN_NSDL_FAILURE; - } - - /* Check path validity */ - if (!res->pathlen || !res->path) { - return SN_GRS_INVALID_PATH; - } - - /* Check if resource already exists */ - if (sn_grs_search_resource(handle, res->pathlen, res->path, SN_GRS_SEARCH_METHOD) != (sn_nsdl_resource_info_s *)NULL) { - return SN_GRS_RESOURCE_ALREADY_EXISTS; - } - - if (res->resource_parameters_ptr) { - res->resource_parameters_ptr->registered = SN_NDSL_RESOURCE_NOT_REGISTERED; - } - - /* Create resource */ - if (sn_grs_add_resource_to_list(handle, res) == SN_NSDL_SUCCESS) { - return SN_NSDL_SUCCESS; - } - return SN_GRS_LIST_ADDING_FAILURE; -} - -int8_t sn_grs_put_resource(struct grs_s *handle, sn_nsdl_resource_info_s *res) -{ - if (!res || !handle) { - return SN_NSDL_FAILURE; - } - - /* Check path validity */ - if (!res->pathlen || !res->path) { - return SN_GRS_INVALID_PATH; - } - - /* Check if resource already exists */ - if (sn_grs_search_resource(handle, res->pathlen, res->path, SN_GRS_SEARCH_METHOD) != (sn_nsdl_resource_info_s *)NULL) { - return SN_GRS_RESOURCE_ALREADY_EXISTS; - } - - if (res->resource_parameters_ptr) { - res->resource_parameters_ptr->registered = SN_NDSL_RESOURCE_NOT_REGISTERED; - } - - res->is_put = true; - - ns_list_add_to_start(&handle->resource_root_list, res); - ++handle->resource_root_count; - - return SN_NSDL_SUCCESS; -} - - -/** - * \fn extern int8_t sn_grs_process_coap(uint8_t *packet, uint16_t *packet_len, sn_nsdl_addr_s *src) - * - * \brief To push CoAP packet to GRS library - * - * Used to push an CoAP packet to GRS library for processing. - * - * \param *packet Pointer to a uint8_t array containing the packet (including the CoAP headers). - * After successful execution this array may contain the response packet. - * - * \param *packet_len Pointer to length of the packet. After successful execution this array may contain the length - * of the response packet. - * - * \param *src Pointer to packet source address information. After successful execution this array may contain - * the destination address of the response packet. - * - * \return 0 = success, -1 = failure -*/ -extern int8_t sn_grs_process_coap(struct nsdl_s *nsdl_handle, sn_coap_hdr_s *coap_packet_ptr, sn_nsdl_addr_s *src_addr_ptr) -{ - if( !coap_packet_ptr || !nsdl_handle){ - return SN_NSDL_FAILURE; - } - - sn_nsdl_resource_info_s *resource_temp_ptr = NULL; - sn_coap_msg_code_e status = COAP_MSG_CODE_EMPTY; - sn_coap_hdr_s *response_message_hdr_ptr = NULL; - struct grs_s *handle = nsdl_handle->grs; - bool static_get_request = false; - - if (coap_packet_ptr->msg_code <= COAP_MSG_CODE_REQUEST_DELETE) { - /* Check if .well-known/core */ - if (coap_packet_ptr->uri_path_len == WELLKNOWN_PATH_LEN && memcmp(coap_packet_ptr->uri_path_ptr, WELLKNOWN_PATH, WELLKNOWN_PATH_LEN) == 0) { - return sn_grs_core_request(nsdl_handle, src_addr_ptr, coap_packet_ptr); - } - - /* Get resource */ - resource_temp_ptr = sn_grs_search_resource(handle, coap_packet_ptr->uri_path_len, coap_packet_ptr->uri_path_ptr, SN_GRS_SEARCH_METHOD); - - /* * * * * * * * * * * */ - /* If resource exists */ - /* * * * * * * * * * * */ - if (resource_temp_ptr) { - /* If dynamic resource, go to callback */ - if (resource_temp_ptr->mode == SN_GRS_DYNAMIC) { - /* Check accesses */ - if (((coap_packet_ptr->msg_code == COAP_MSG_CODE_REQUEST_GET) && !(resource_temp_ptr->access & SN_GRS_GET_ALLOWED)) || - ((coap_packet_ptr->msg_code == COAP_MSG_CODE_REQUEST_POST) && !(resource_temp_ptr->access & SN_GRS_POST_ALLOWED)) || - ((coap_packet_ptr->msg_code == COAP_MSG_CODE_REQUEST_PUT) && !(resource_temp_ptr->access & SN_GRS_PUT_ALLOWED)) || - ((coap_packet_ptr->msg_code == COAP_MSG_CODE_REQUEST_DELETE) && !(resource_temp_ptr->access & SN_GRS_DELETE_ALLOWED))) { - - status = COAP_MSG_CODE_RESPONSE_METHOD_NOT_ALLOWED; - } else { - /* Do not call null pointer.. */ - if (resource_temp_ptr->sn_grs_dyn_res_callback != NULL) { - resource_temp_ptr->sn_grs_dyn_res_callback(nsdl_handle, coap_packet_ptr, src_addr_ptr, SN_NSDL_PROTOCOL_COAP); - } - - if (coap_packet_ptr->coap_status == COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED && coap_packet_ptr->payload_ptr) { - handle->sn_grs_free(coap_packet_ptr->payload_ptr); - coap_packet_ptr->payload_ptr = 0; - } - sn_coap_parser_release_allocated_coap_msg_mem(handle->coap, coap_packet_ptr); - return SN_NSDL_SUCCESS; - } - } else { - /* Static resource handling */ - switch (coap_packet_ptr->msg_code) { - case (COAP_MSG_CODE_REQUEST_GET): - if (resource_temp_ptr->access & SN_GRS_GET_ALLOWED) { - status = COAP_MSG_CODE_RESPONSE_CONTENT; - static_get_request = true; - } else { - status = COAP_MSG_CODE_RESPONSE_METHOD_NOT_ALLOWED; - } - break; - case (COAP_MSG_CODE_REQUEST_POST): - if (resource_temp_ptr->access & SN_GRS_POST_ALLOWED) { - resource_temp_ptr->resourcelen = coap_packet_ptr->payload_len; - handle->sn_grs_free(resource_temp_ptr->resource); - resource_temp_ptr->resource = 0; - if (resource_temp_ptr->resourcelen) { - resource_temp_ptr->resource = handle->sn_grs_alloc(resource_temp_ptr->resourcelen); - if (!resource_temp_ptr->resource) { - status = COAP_MSG_CODE_RESPONSE_INTERNAL_SERVER_ERROR; - break; - } - memcpy(resource_temp_ptr->resource, coap_packet_ptr->payload_ptr, resource_temp_ptr->resourcelen); - } - if (coap_packet_ptr->content_format != COAP_CT_NONE) { - if (resource_temp_ptr->resource_parameters_ptr) { - resource_temp_ptr->resource_parameters_ptr->coap_content_type = coap_packet_ptr->content_format; - } - } - status = COAP_MSG_CODE_RESPONSE_CHANGED; - } else { - status = COAP_MSG_CODE_RESPONSE_METHOD_NOT_ALLOWED; - } - break; - case (COAP_MSG_CODE_REQUEST_PUT): - if (resource_temp_ptr->access & SN_GRS_PUT_ALLOWED) { - resource_temp_ptr->resourcelen = coap_packet_ptr->payload_len; - handle->sn_grs_free(resource_temp_ptr->resource); - resource_temp_ptr->resource = 0; - if (resource_temp_ptr->resourcelen) { - resource_temp_ptr->resource = handle->sn_grs_alloc(resource_temp_ptr->resourcelen); - if (!resource_temp_ptr->resource) { - status = COAP_MSG_CODE_RESPONSE_INTERNAL_SERVER_ERROR; - break; - } - memcpy(resource_temp_ptr->resource, coap_packet_ptr->payload_ptr, resource_temp_ptr->resourcelen); - } - if (coap_packet_ptr->content_format != COAP_CT_NONE) { - if (resource_temp_ptr->resource_parameters_ptr) { - resource_temp_ptr->resource_parameters_ptr->coap_content_type = coap_packet_ptr->content_format; - } - } - status = COAP_MSG_CODE_RESPONSE_CHANGED; - } else { - status = COAP_MSG_CODE_RESPONSE_METHOD_NOT_ALLOWED; - } - break; - - case (COAP_MSG_CODE_REQUEST_DELETE): - if (resource_temp_ptr->access & SN_GRS_DELETE_ALLOWED) { - if (sn_grs_delete_resource(handle, coap_packet_ptr->uri_path_len, coap_packet_ptr->uri_path_ptr) == SN_NSDL_SUCCESS) { - status = COAP_MSG_CODE_RESPONSE_DELETED; - } else { - //This is dead code (Currently only time delete fails is when resource is not found - //and sn_grs_search_resource is used with same arguments above!) - status = COAP_MSG_CODE_RESPONSE_INTERNAL_SERVER_ERROR; - } - } else { - status = COAP_MSG_CODE_RESPONSE_METHOD_NOT_ALLOWED; - } - break; - - default: - status = COAP_MSG_CODE_RESPONSE_FORBIDDEN; - break; - } - } - } - - /* * * * * * * * * * * * * * */ - /* If resource was not found */ - /* * * * * * * * * * * * * * */ - - else { - if (coap_packet_ptr->msg_code == COAP_MSG_CODE_REQUEST_POST) { - handle->sn_grs_rx_callback(nsdl_handle, coap_packet_ptr, src_addr_ptr); - - if (coap_packet_ptr->coap_status == COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED && coap_packet_ptr->payload_ptr) { - handle->sn_grs_free(coap_packet_ptr->payload_ptr); - coap_packet_ptr->payload_ptr = 0; - } - - sn_coap_parser_release_allocated_coap_msg_mem(handle->coap, coap_packet_ptr); - return SN_NSDL_SUCCESS; - } else { - status = COAP_MSG_CODE_RESPONSE_NOT_FOUND; - } - } - - } - - - /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - /* If received packed was other than reset, create response */ - /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - if (coap_packet_ptr->msg_type != COAP_MSG_TYPE_RESET && coap_packet_ptr->msg_type != COAP_MSG_TYPE_ACKNOWLEDGEMENT) { - - /* Allocate resopnse message */ - response_message_hdr_ptr = sn_coap_parser_alloc_message(handle->coap); - if (!response_message_hdr_ptr) { - if (coap_packet_ptr->coap_status == COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED && coap_packet_ptr->payload_ptr) { - handle->sn_grs_free(coap_packet_ptr->payload_ptr); - coap_packet_ptr->payload_ptr = 0; - } - sn_coap_parser_release_allocated_coap_msg_mem(handle->coap, coap_packet_ptr); - return SN_NSDL_FAILURE; - } - - /* If status has not been defined, response internal server error */ - if (status == COAP_MSG_CODE_EMPTY) { - status = COAP_MSG_CODE_RESPONSE_INTERNAL_SERVER_ERROR; - } - - /* Fill header */ - response_message_hdr_ptr->msg_code = status; - - if (coap_packet_ptr->msg_type == COAP_MSG_TYPE_CONFIRMABLE) { - response_message_hdr_ptr->msg_type = COAP_MSG_TYPE_ACKNOWLEDGEMENT; - } else { - response_message_hdr_ptr->msg_type = COAP_MSG_TYPE_NON_CONFIRMABLE; - } - - response_message_hdr_ptr->msg_id = coap_packet_ptr->msg_id; - - if (coap_packet_ptr->token_ptr) { - response_message_hdr_ptr->token_len = coap_packet_ptr->token_len; - response_message_hdr_ptr->token_ptr = handle->sn_grs_alloc(response_message_hdr_ptr->token_len); - if (!response_message_hdr_ptr->token_ptr) { - sn_coap_parser_release_allocated_coap_msg_mem(handle->coap, response_message_hdr_ptr); - - if (coap_packet_ptr->coap_status == COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED && coap_packet_ptr->payload_ptr) { - handle->sn_grs_free(coap_packet_ptr->payload_ptr); - coap_packet_ptr->payload_ptr = 0; - } - - sn_coap_parser_release_allocated_coap_msg_mem(handle->coap, coap_packet_ptr); - return SN_NSDL_FAILURE; - } - memcpy(response_message_hdr_ptr->token_ptr, coap_packet_ptr->token_ptr, response_message_hdr_ptr->token_len); - } - - if (status == COAP_MSG_CODE_RESPONSE_CONTENT) { - /* Add content type if other than default */ - if (resource_temp_ptr->resource_parameters_ptr) { - /* XXXX Why "if != 0"? 0 means text/plain, and is not the default for CoAP - this prevents setting text/plain? */ - if (resource_temp_ptr->resource_parameters_ptr->coap_content_type != 0) { - response_message_hdr_ptr->content_format = (sn_coap_content_format_e) resource_temp_ptr->resource_parameters_ptr->coap_content_type; - } - } - - /* Add payload */ - if (resource_temp_ptr->resourcelen != 0) { - response_message_hdr_ptr->payload_len = resource_temp_ptr->resourcelen; - response_message_hdr_ptr->payload_ptr = handle->sn_grs_alloc(response_message_hdr_ptr->payload_len); - - if (!response_message_hdr_ptr->payload_ptr) { - sn_coap_parser_release_allocated_coap_msg_mem(handle->coap, response_message_hdr_ptr); - - if (coap_packet_ptr->coap_status == COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED && coap_packet_ptr->payload_ptr) { - handle->sn_grs_free(coap_packet_ptr->payload_ptr); - coap_packet_ptr->payload_ptr = 0; - } - - sn_coap_parser_release_allocated_coap_msg_mem(handle->coap, coap_packet_ptr); - return SN_NSDL_FAILURE; - } - - memcpy(response_message_hdr_ptr->payload_ptr, resource_temp_ptr->resource, response_message_hdr_ptr->payload_len); - } - // Add max-age attribute for static resources. - // Not a mandatory parameter, no need to return in case of memory allocation fails. - if (static_get_request) { - if (sn_coap_parser_alloc_options(handle->coap, response_message_hdr_ptr)) { - response_message_hdr_ptr->options_list_ptr->max_age = 0; - } - } - } - sn_grs_send_coap_message(nsdl_handle, src_addr_ptr, response_message_hdr_ptr); - - if (response_message_hdr_ptr->payload_ptr) { - handle->sn_grs_free(response_message_hdr_ptr->payload_ptr); - response_message_hdr_ptr->payload_ptr = 0; - } - sn_coap_parser_release_allocated_coap_msg_mem(handle->coap, response_message_hdr_ptr); - } - - /* Free parsed CoAP message */ - if (coap_packet_ptr->coap_status == COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED && coap_packet_ptr->payload_ptr) { - handle->sn_grs_free(coap_packet_ptr->payload_ptr); - coap_packet_ptr->payload_ptr = 0; - } - sn_coap_parser_release_allocated_coap_msg_mem(handle->coap, coap_packet_ptr); - - - return SN_NSDL_SUCCESS; -} - -extern int8_t sn_grs_send_coap_message(struct nsdl_s *handle, sn_nsdl_addr_s *address_ptr, sn_coap_hdr_s *coap_hdr_ptr) -{ - tr_debug("sn_grs_send_coap_message"); - uint8_t *message_ptr = NULL; - uint16_t message_len = 0; - uint8_t ret_val = 0; - - if( !handle ){ - return SN_NSDL_FAILURE; - } - -#if SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE /* If Message blockwising is not used at all, this part of code will not be compiled */ - ret_val = prepare_blockwise_message(handle->grs->coap, coap_hdr_ptr); - if( 0 != ret_val ) { - return SN_NSDL_FAILURE; - } -#endif - - /* Calculate message length */ - message_len = sn_coap_builder_calc_needed_packet_data_size_2(coap_hdr_ptr, handle->grs->coap->sn_coap_block_data_size); - tr_debug("sn_grs_send_coap_message - msg len after calc: [%d]", message_len); - tr_debug("sn_grs_send_coap_message - msg id: [%d]", coap_hdr_ptr->msg_id); - - /* Allocate memory for message and check was allocating successfully */ - message_ptr = handle->grs->sn_grs_alloc(message_len); - if (message_ptr == NULL) { - return SN_NSDL_FAILURE; - } - - /* Build CoAP message */ - if (sn_coap_protocol_build(handle->grs->coap, address_ptr, message_ptr, coap_hdr_ptr, (void *)handle) < 0) { - handle->grs->sn_grs_free(message_ptr); - message_ptr = 0; - return SN_NSDL_FAILURE; - } - - /* Call tx callback function to send message */ - ret_val = handle->grs->sn_grs_tx_callback(handle, SN_NSDL_PROTOCOL_COAP, message_ptr, message_len, address_ptr); - - /* Free allocated memory */ - handle->grs->sn_grs_free(message_ptr); - message_ptr = 0; - - if (ret_val == 0) { - return SN_NSDL_FAILURE; - } else { - return SN_NSDL_SUCCESS; - } -} - -static int8_t sn_grs_core_request(struct nsdl_s *handle, sn_nsdl_addr_s *src_addr_ptr, sn_coap_hdr_s *coap_packet_ptr) -{ - sn_coap_hdr_s *response_message_hdr_ptr = NULL; - sn_coap_content_format_e wellknown_content_format = COAP_CT_LINK_FORMAT; - - /* Allocate response message */ - response_message_hdr_ptr = sn_coap_parser_alloc_message(handle->grs->coap); - if (response_message_hdr_ptr == NULL) { - if (coap_packet_ptr->coap_status == COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED && coap_packet_ptr->payload_ptr) { - handle->grs->sn_grs_free(coap_packet_ptr->payload_ptr); - coap_packet_ptr->payload_ptr = 0; - } - sn_coap_parser_release_allocated_coap_msg_mem(handle->grs->coap, coap_packet_ptr); - return SN_NSDL_FAILURE; - } - - /* Build response */ - response_message_hdr_ptr->msg_code = COAP_MSG_CODE_RESPONSE_CONTENT; - response_message_hdr_ptr->msg_type = COAP_MSG_TYPE_ACKNOWLEDGEMENT; - response_message_hdr_ptr->msg_id = coap_packet_ptr->msg_id; - response_message_hdr_ptr->content_format = wellknown_content_format; - - sn_nsdl_build_registration_body(handle, response_message_hdr_ptr, 0); - - /* Send and free */ - sn_grs_send_coap_message(handle, src_addr_ptr, response_message_hdr_ptr); - - if (response_message_hdr_ptr->payload_ptr) { - handle->grs->sn_grs_free(response_message_hdr_ptr->payload_ptr); - response_message_hdr_ptr->payload_ptr = 0; - } - sn_coap_parser_release_allocated_coap_msg_mem(handle->grs->coap, response_message_hdr_ptr); - - /* Free parsed CoAP message */ - if (coap_packet_ptr->coap_status == COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED && coap_packet_ptr->payload_ptr) { - handle->grs->sn_grs_free(coap_packet_ptr->payload_ptr); - coap_packet_ptr->payload_ptr = 0; - } - sn_coap_parser_release_allocated_coap_msg_mem(handle->grs->coap, coap_packet_ptr); - - return SN_NSDL_SUCCESS; -} - -/** - * \fn static sn_grs_resource_info_s *sn_grs_search_resource(uint16_t pathlen, uint8_t *path, uint8_t search_method) - * - * \brief Searches given resource from linked list - * - * Search either precise path, or subresources, eg. dr/x -> returns dr/x/1, dr/x/2 etc... - * - * \param pathlen Length of the path to be search - * - * \param *path Pointer to the path string to be search - * - * \param search_method Search method, SEARCH or DELETE - * - * \return Pointer to the resource. If resource not found, return value is NULL - * -*/ - -sn_nsdl_resource_info_s *sn_grs_search_resource(struct grs_s *handle, uint16_t pathlen, uint8_t *path, uint8_t search_method) -{ - - /* Local variables */ - uint8_t *path_temp_ptr = NULL; - /* Check parameters */ - if (!handle || !pathlen || !path) { - return NULL; - } - - /* Remove '/' - marks from the end and beginning */ - path_temp_ptr = sn_grs_convert_uri(&pathlen, path); - - /* Searchs exact path */ - if (search_method == SN_GRS_SEARCH_METHOD) { - /* Scan all nodes on list */ - ns_list_foreach(sn_nsdl_resource_info_s, resource_search_temp, &handle->resource_root_list) { - /* If length equals.. */ - if (resource_search_temp->pathlen == pathlen) { - /* Compare paths, If same return node pointer*/ - if (0 == memcmp(resource_search_temp->path, path_temp_ptr, pathlen)) { - return resource_search_temp; - } - } - } - } - /* Search also subresources, eg. dr/x -> returns dr/x/1, dr/x/2 etc... */ - else if (search_method == SN_GRS_DELETE_METHOD) { - /* Scan all nodes on list */ - ns_list_foreach(sn_nsdl_resource_info_s, resource_search_temp, &handle->resource_root_list) { - uint8_t *temp_path = resource_search_temp->path; - if (resource_search_temp->pathlen > pathlen && - (*(temp_path + (uint8_t)pathlen) == '/') && - 0 == memcmp(resource_search_temp->path, path_temp_ptr, pathlen)) { - return resource_search_temp; - } - } - } - - /* If there was not nodes we wanted, return NULL */ - return NULL; -} - - -/** - * \fn static int8_t sn_grs_add_resource_to_list(sn_grs_resource_info_s *resource_ptr) - * - * \brief Adds given resource to resource list - * - * \param *resource_ptr Pointer to the path string to be search - * - * \return 0 = SN_NSDL_SUCCESS, -1 = SN_NSDL_FAILURE - * -*/ -static int8_t sn_grs_add_resource_to_list(struct grs_s *handle, sn_nsdl_resource_info_s *resource_ptr) -{ - /* Local variables */ - uint8_t *path_start_ptr = NULL; - uint16_t path_len = 0; - sn_nsdl_resource_info_s *resource_copy_ptr = NULL; - - /* Allocate memory for the resource info copy */ - if (!resource_ptr->pathlen) { //Dead code - return SN_NSDL_FAILURE; - } - resource_copy_ptr = handle->sn_grs_alloc(sizeof(sn_nsdl_resource_info_s)); - if (resource_copy_ptr == NULL) { - return SN_NSDL_FAILURE; - } - - /* Set everything to zero */ - memset(resource_copy_ptr, 0, sizeof(sn_nsdl_resource_info_s)); - - resource_copy_ptr->mode = resource_ptr->mode; - resource_copy_ptr->resourcelen = resource_ptr->resourcelen; - resource_copy_ptr->sn_grs_dyn_res_callback = resource_ptr->sn_grs_dyn_res_callback; - resource_copy_ptr->access = resource_ptr->access; - resource_copy_ptr->publish_uri = resource_ptr->publish_uri; - resource_copy_ptr->external_memory_block = resource_ptr->external_memory_block; - - /* Remove '/' - chars from the beginning and from the end */ - - path_len = resource_ptr->pathlen; - path_start_ptr = sn_grs_convert_uri(&path_len, resource_ptr->path); - - /* Allocate memory for the path */ - resource_copy_ptr->path = handle->sn_grs_alloc(path_len); - if (!resource_copy_ptr->path) { - sn_grs_resource_info_free(handle, resource_copy_ptr); - return SN_NSDL_FAILURE; - } - - /* Update pathlen */ - resource_copy_ptr->pathlen = path_len; - - /* Copy path string to the copy */ - memcpy(resource_copy_ptr->path, path_start_ptr, resource_copy_ptr->pathlen); - - /* Allocate memory for the resource, and copy it to copy */ - if (resource_ptr->resource) { - resource_copy_ptr->resource = handle->sn_grs_alloc(resource_ptr->resourcelen); - if (!resource_copy_ptr->resource) { - sn_grs_resource_info_free(handle, resource_copy_ptr); - return SN_NSDL_FAILURE; - } - memcpy(resource_copy_ptr->resource, resource_ptr->resource, resource_ptr->resourcelen); - } - - - - /* If resource parameters exists, copy them */ - if (resource_ptr->resource_parameters_ptr) { - resource_copy_ptr->resource_parameters_ptr = handle->sn_grs_alloc(sizeof(sn_nsdl_resource_parameters_s)); - if (!resource_copy_ptr->resource_parameters_ptr) { - sn_grs_resource_info_free(handle, resource_copy_ptr); - return SN_NSDL_FAILURE; - } - - memset(resource_copy_ptr->resource_parameters_ptr, 0, sizeof(sn_nsdl_resource_parameters_s)); - - resource_copy_ptr->resource_parameters_ptr->resource_type_len = resource_ptr->resource_parameters_ptr->resource_type_len; - -// resource_copy_ptr->resource_parameters_ptr->mime_content_type = resource_ptr->resource_parameters_ptr->mime_content_type; - - resource_copy_ptr->resource_parameters_ptr->observable = resource_ptr->resource_parameters_ptr->observable; - - if (resource_ptr->resource_parameters_ptr->resource_type_ptr) { - resource_copy_ptr->resource_parameters_ptr->resource_type_ptr = handle->sn_grs_alloc(resource_ptr->resource_parameters_ptr->resource_type_len); - if (!resource_copy_ptr->resource_parameters_ptr->resource_type_ptr) { - sn_grs_resource_info_free(handle, resource_copy_ptr); - return SN_NSDL_FAILURE; - } - memcpy(resource_copy_ptr->resource_parameters_ptr->resource_type_ptr, resource_ptr->resource_parameters_ptr->resource_type_ptr, resource_ptr->resource_parameters_ptr->resource_type_len); - } - - resource_copy_ptr->resource_parameters_ptr->interface_description_len = resource_ptr->resource_parameters_ptr->interface_description_len; - - if (resource_ptr->resource_parameters_ptr->interface_description_ptr) { - resource_copy_ptr->resource_parameters_ptr->interface_description_ptr = handle->sn_grs_alloc(resource_ptr->resource_parameters_ptr->interface_description_len); - if (!resource_copy_ptr->resource_parameters_ptr->interface_description_ptr) { - sn_grs_resource_info_free(handle, resource_copy_ptr); - return SN_NSDL_FAILURE; - } - memcpy(resource_copy_ptr->resource_parameters_ptr->interface_description_ptr, resource_ptr->resource_parameters_ptr->interface_description_ptr, resource_ptr->resource_parameters_ptr->interface_description_len); - } - - /* Copy auto observation parameter */ - /* todo: aobs not supported ATM - needs fixing */ - /* if(resource_ptr->resource_parameters_ptr->auto_obs_ptr && resource_ptr->resource_parameters_ptr->auto_obs_len) - { - resource_copy_ptr->resource_parameters_ptr->auto_obs_ptr = sn_grs_alloc(resource_ptr->resource_parameters_ptr->auto_obs_len); - if(!resource_copy_ptr->resource_parameters_ptr->auto_obs_ptr) - { - sn_grs_resource_info_free(resource_copy_ptr); - return SN_NSDL_FAILURE; - } - memcpy(resource_copy_ptr->resource_parameters_ptr->auto_obs_ptr, resource_ptr->resource_parameters_ptr->auto_obs_ptr, resource_ptr->resource_parameters_ptr->auto_obs_len); - resource_copy_ptr->resource_parameters_ptr->auto_obs_len = resource_ptr->resource_parameters_ptr->auto_obs_len; - } - - resource_copy_ptr->resource_parameters_ptr->coap_content_type = resource_ptr->resource_parameters_ptr->coap_content_type; - */ - } - - /* Add copied resource to the linked list */ - ns_list_add_to_start(&handle->resource_root_list, resource_copy_ptr); - ++handle->resource_root_count; - - return SN_NSDL_SUCCESS; -} - - -/** - * \fn static uint8_t *sn_grs_convert_uri(uint16_t *uri_len, uint8_t *uri_ptr) - * - * \brief Removes '/' from the beginning and from the end of uri string - * - * \param *uri_len Pointer to the length of the path string - * - * \param *uri_ptr Pointer to the path string - * - * \return start pointer of the uri - * -*/ - -static uint8_t *sn_grs_convert_uri(uint16_t *uri_len, uint8_t *uri_ptr) -{ - /* Local variables */ - uint8_t *uri_start_ptr = uri_ptr; - - /* If '/' in the beginning, update uri start pointer and uri len */ - if (*uri_ptr == '/') { - uri_start_ptr = uri_ptr + 1; - *uri_len = *uri_len - 1; - } - - /* If '/' at the end, update uri len */ - if (*(uri_start_ptr + *uri_len - 1) == '/') { - *uri_len = *uri_len - 1; - } - - /* Return start pointer */ - return uri_start_ptr; -} - -/** - * \fn static int8_t sn_grs_resource_info_free(sn_grs_resource_info_s *resource_ptr) - * - * \brief Frees resource info structure - * - * \param *resource_ptr Pointer to the resource - * - * \return 0 if success, -1 if failed - * -*/ -static int8_t sn_grs_resource_info_free(struct grs_s *handle, sn_nsdl_resource_info_s *resource_ptr) -{ - if (resource_ptr) { - if (resource_ptr->resource_parameters_ptr) { - if (!resource_ptr->is_put) { - if (resource_ptr->resource_parameters_ptr->interface_description_ptr) { - handle->sn_grs_free(resource_ptr->resource_parameters_ptr->interface_description_ptr); - resource_ptr->resource_parameters_ptr->interface_description_ptr = 0; - } - - if (resource_ptr->resource_parameters_ptr->resource_type_ptr) { - handle->sn_grs_free(resource_ptr->resource_parameters_ptr->resource_type_ptr); - resource_ptr->resource_parameters_ptr->resource_type_ptr = 0; - } - } - - /* Todo: aobs not supported ATM - needs fixing */ - /* - if(resource_ptr->resource_parameters_ptr->auto_obs_ptr) - { - sn_grs_free(resource_ptr->resource_parameters_ptr->auto_obs_ptr); - resource_ptr->resource_parameters_ptr->auto_obs_ptr = 0; - } - */ - - handle->sn_grs_free(resource_ptr->resource_parameters_ptr); - resource_ptr->resource_parameters_ptr = 0; - } - - if (!resource_ptr->is_put) { - if (resource_ptr->path) { - handle->sn_grs_free(resource_ptr->path); - resource_ptr->path = 0; - } - if (resource_ptr->resource) { - handle->sn_grs_free(resource_ptr->resource); - resource_ptr->resource = 0; - } - } - handle->sn_grs_free(resource_ptr); - - return SN_NSDL_SUCCESS; - } - return SN_NSDL_FAILURE; //Dead code? -} - -void sn_grs_mark_resources_as_registered(struct nsdl_s *handle) -{ - if( !handle ){ - return; - } - - const sn_nsdl_resource_info_s *temp_resource; - - temp_resource = sn_grs_get_first_resource(handle->grs); - - while (temp_resource) { - if (temp_resource->resource_parameters_ptr) { - if (temp_resource->resource_parameters_ptr->registered == SN_NDSL_RESOURCE_REGISTERING) { - temp_resource->resource_parameters_ptr->registered = SN_NDSL_RESOURCE_REGISTERED; - } - } - temp_resource = sn_grs_get_next_resource(handle->grs, temp_resource); - } -} - -#endif \ No newline at end of file diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/source/libNsdl/src/sn_grs2.c b/features/FEATURE_COMMON_PAL/mbed-client-c/source/libNsdl/src/sn_grs2.c deleted file mode 100755 index 1d5331ff32..0000000000 --- a/features/FEATURE_COMMON_PAL/mbed-client-c/source/libNsdl/src/sn_grs2.c +++ /dev/null @@ -1,1023 +0,0 @@ -/* - * Copyright (c) 2011-2015 ARM Limited. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 - * Licensed under the Apache License, Version 2.0 (the License); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * - * \file sn_grs.c - * - * \brief General resource server. - * - */ -#ifdef MBED_CLIENT_C_NEW_API -#include -#include -#include "ns_list.h" -#include "ns_types.h" -#include "sn_nsdl.h" -#include "sn_coap_header.h" -#include "sn_coap_protocol.h" -#include "sn_coap_protocol_internal.h" -#include "sn_nsdl_lib.h" -#include "sn_grs.h" -#include "mbed-trace/mbed_trace.h" - -/* Defines */ -#define TRACE_GROUP "coap" -#define WELLKNOWN_PATH_LEN 16 -#define WELLKNOWN_PATH (".well-known/core") - -/* Local static function prototypes */ -static int8_t sn_grs_resource_info_free(struct grs_s *handle, sn_nsdl_dynamic_resource_parameters_s *resource_ptr); -static uint8_t *sn_grs_convert_uri(uint16_t *uri_len, uint8_t *uri_ptr); -#ifndef MEMORY_OPTIMIZED_API -static int8_t sn_grs_add_resource_to_list(struct grs_s *handle, sn_nsdl_dynamic_resource_parameters_s *resource_ptr); -#endif -static int8_t sn_grs_core_request(struct nsdl_s *handle, sn_nsdl_addr_s *src_addr_ptr, sn_coap_hdr_s *coap_packet_ptr); -static uint8_t coap_tx_callback(uint8_t *, uint16_t, sn_nsdl_addr_s *, void *); -static int8_t coap_rx_callback(sn_coap_hdr_s *coap_ptr, sn_nsdl_addr_s *address_ptr, void *param); - -/* Extern function prototypes */ -extern int8_t sn_nsdl_build_registration_body(struct nsdl_s *handle, sn_coap_hdr_s *message_ptr, uint8_t updating_registeration); - -/** - * \fn int8_t sn_grs_destroy(void) - * \brief This function may be used to flush GRS related stuff when a program exits. - * @return always 0. - */ -extern int8_t sn_grs_destroy(struct grs_s *handle) -{ - if( handle == NULL ){ - return 0; - } - ns_list_foreach_safe(sn_nsdl_dynamic_resource_parameters_s, tmp, &handle->resource_root_list) { - ns_list_remove(&handle->resource_root_list, tmp); - --handle->resource_root_count; - sn_grs_resource_info_free(handle, tmp); - } - handle->sn_grs_free(handle); - - return 0; -} - -static uint8_t coap_tx_callback(uint8_t *data_ptr, uint16_t data_len, sn_nsdl_addr_s *address_ptr, void *param) -{ - struct nsdl_s *handle = (struct nsdl_s *)param; - - if (handle == NULL) { - return 0; - } - - return handle->grs->sn_grs_tx_callback(handle, SN_NSDL_PROTOCOL_COAP, data_ptr, data_len, address_ptr); -} - -static int8_t coap_rx_callback(sn_coap_hdr_s *coap_ptr, sn_nsdl_addr_s *address_ptr, void *param) -{ - struct nsdl_s *handle = (struct nsdl_s *)param; - - if (handle == NULL) { - return 0; - } - - return handle->sn_nsdl_rx_callback(handle, coap_ptr, address_ptr); -} - -/** - * \fn int8_t sn_grs_init (uint8_t (*sn_grs_tx_callback_ptr)(sn_nsdl_capab_e , uint8_t *, uint16_t, - * sn_nsdl_addr_s *), int8_t (*sn_grs_rx_callback_ptr)(sn_coap_hdr_s *, sn_nsdl_addr_s *), sn_nsdl_mem_s *sn_memory) - * - * \brief GRS library initialize function. - * - * This function initializes GRS and CoAP libraries. - * - * \param sn_grs_tx_callback A function pointer to a transmit callback function. - * \param *sn_grs_rx_callback_ptr A function pointer to a receiving callback function. If received packet is not for GRS, it will be passed to - * upper level (NSDL) to be proceed. - * \param sn_memory A pointer to a structure containing the platform specific functions for memory allocation and free. - * - * \return success = 0, failure = -1 - * -*/ -extern struct grs_s *sn_grs_init(uint8_t (*sn_grs_tx_callback_ptr)(struct nsdl_s *, sn_nsdl_capab_e , uint8_t *, uint16_t, - sn_nsdl_addr_s *), int8_t (*sn_grs_rx_callback_ptr)(struct nsdl_s *, sn_coap_hdr_s *, sn_nsdl_addr_s *), - void *(*sn_grs_alloc)(uint16_t), void (*sn_grs_free)(void *)) -{ - - struct grs_s *handle_ptr = NULL; - - /* Check parameters */ - if (sn_grs_alloc == NULL || sn_grs_free == NULL || - sn_grs_tx_callback_ptr == NULL || sn_grs_rx_callback_ptr == NULL) { - return NULL; - } - - handle_ptr = sn_grs_alloc(sizeof(struct grs_s)); - - if (handle_ptr == NULL) { - return NULL; - } - - memset(handle_ptr, 0, sizeof(struct grs_s)); - - /* Allocation and free - function pointers */ - handle_ptr->sn_grs_alloc = sn_grs_alloc; - handle_ptr->sn_grs_free = sn_grs_free; - - /* TX callback function pointer */ - handle_ptr->sn_grs_tx_callback = sn_grs_tx_callback_ptr; - handle_ptr->sn_grs_rx_callback = sn_grs_rx_callback_ptr; - - /* Initialize CoAP protocol library */ - handle_ptr->coap = sn_coap_protocol_init(sn_grs_alloc, sn_grs_free, coap_tx_callback, coap_rx_callback); - - return handle_ptr; -} - -extern sn_grs_resource_list_s *sn_grs_list_resource(struct grs_s *handle, uint16_t pathlen, uint8_t *path) -{ - (void) pathlen; - sn_grs_resource_list_s *grs_resource_list_ptr = NULL; - - if( handle == NULL || path == NULL){ - return NULL; - } - - /* Allocate memory for the resource list to be filled */ - grs_resource_list_ptr = handle->sn_grs_alloc(sizeof(sn_grs_resource_list_s)); - if (!grs_resource_list_ptr) { - goto fail; - } - - /* Count resources to the resource list struct */ - grs_resource_list_ptr->res_count = handle->resource_root_count; - grs_resource_list_ptr->res = NULL; - - /**************************************/ - /* Fill resource structs to the table */ - /**************************************/ - - /* If resources in list */ - if (grs_resource_list_ptr->res_count) { - int i; - - /* Allocate memory for resources */ - grs_resource_list_ptr->res = handle->sn_grs_alloc(grs_resource_list_ptr->res_count * sizeof(sn_grs_resource_s)); - if (!grs_resource_list_ptr->res) { - goto fail; - } - - /* Initialise the pointers to NULL to permit easy cleanup */ - for (i = 0; i < grs_resource_list_ptr->res_count; i++) { - grs_resource_list_ptr->res[i].path = NULL; - grs_resource_list_ptr->res[i].pathlen = 0; - } - - i = 0; - ns_list_foreach(sn_nsdl_dynamic_resource_parameters_s, grs_resource_ptr, &handle->resource_root_list) { - /* Copy pathlen to resource list */ - grs_resource_list_ptr->res[i].pathlen = grs_resource_ptr->static_resource_parameters->pathlen; - - /* Allocate memory for path string */ - grs_resource_list_ptr->res[i].path = handle->sn_grs_alloc(grs_resource_list_ptr->res[i].pathlen); - if (!grs_resource_list_ptr->res[i].path) { - goto fail; - } - - /* Copy pathstring to resource list */ - memcpy(grs_resource_list_ptr->res[i].path, - grs_resource_ptr->static_resource_parameters->path, - grs_resource_ptr->static_resource_parameters->pathlen); - - i++; - } - } - return grs_resource_list_ptr; - -fail: - sn_grs_free_resource_list(handle, grs_resource_list_ptr); - return NULL; -} - -extern void sn_grs_free_resource_list(struct grs_s *handle, sn_grs_resource_list_s *list) -{ - if (!list || !handle) { - return; - } - - if (list->res) { - for (int i = 0; i < list->res_count; i++) { - if (list->res[i].path) { - handle->sn_grs_free(list->res[i].path); - list->res[i].path = NULL; - } - } - handle->sn_grs_free(list->res); - list->res = NULL; - } - - handle->sn_grs_free(list); -} - -extern sn_nsdl_dynamic_resource_parameters_s *sn_grs_get_first_resource(struct grs_s *handle) -{ - if( !handle ){ - return NULL; - } - return ns_list_get_first(&handle->resource_root_list); -} - -extern sn_nsdl_dynamic_resource_parameters_s *sn_grs_get_next_resource(struct grs_s *handle, - const sn_nsdl_dynamic_resource_parameters_s *sn_grs_current_resource) -{ - if( !handle || !sn_grs_current_resource ){ - return NULL; - } - return ns_list_get_next(&handle->resource_root_list, sn_grs_current_resource); -} - -extern int8_t sn_grs_delete_resource(struct grs_s *handle, uint16_t pathlen, uint8_t *path) -{ - /* Local variables */ - sn_nsdl_dynamic_resource_parameters_s *resource_temp = NULL; - - /* Search if resource found */ - resource_temp = sn_grs_search_resource(handle, pathlen, path, SN_GRS_SEARCH_METHOD); - - /* If not found */ - if (resource_temp == NULL) { - return SN_NSDL_FAILURE; - } - - /* If found, delete it and delete also subresources, if there is any */ - do { - /* Remove from list */ - ns_list_remove(&handle->resource_root_list, resource_temp); - --handle->resource_root_count; - - /* Free */ - sn_grs_resource_info_free(handle, resource_temp); - - /* Search for subresources */ - resource_temp = sn_grs_search_resource(handle, pathlen, path, SN_GRS_DELETE_METHOD); - } while (resource_temp != NULL); - - return SN_NSDL_SUCCESS; -} - -#ifndef MEMORY_OPTIMIZED_API -extern int8_t sn_grs_update_resource(struct grs_s *handle, sn_nsdl_dynamic_resource_parameters_s *res) -{ - /* Local variables */ - sn_nsdl_dynamic_resource_parameters_s *resource_temp = NULL; - - if( !res || !handle ){ - return SN_NSDL_FAILURE; - } - - /* Search resource */ - resource_temp = sn_grs_search_resource(handle, - res->static_resource_parameters->pathlen, - res->static_resource_parameters->path, - SN_GRS_SEARCH_METHOD); - if (!resource_temp) { - return SN_NSDL_FAILURE; - } - - /* If there is payload on resource, free it */ - if (resource_temp->static_resource_parameters->resource != NULL) { - handle->sn_grs_free(resource_temp->static_resource_parameters->resource); - resource_temp->static_resource_parameters->resource = 0; - } - /* Update resource len */ - resource_temp->static_resource_parameters->resourcelen = - res->static_resource_parameters->resourcelen; - - /* If resource len >0, allocate memory and copy payload */ - if (res->static_resource_parameters->resourcelen) { - resource_temp->static_resource_parameters->resource = - handle->sn_grs_alloc(res->static_resource_parameters->resourcelen); - if (resource_temp->static_resource_parameters->resource == NULL) { - resource_temp->static_resource_parameters->resourcelen = 0; - return SN_NSDL_FAILURE; - } - - memcpy(resource_temp->static_resource_parameters->resource, - res->static_resource_parameters->resource, - resource_temp->static_resource_parameters->resourcelen); - } - - /* Update access rights and callback address */ - resource_temp->access = res->access; - resource_temp->sn_grs_dyn_res_callback = res->sn_grs_dyn_res_callback; - - /* TODO: resource_parameters_ptr not copied */ - - return SN_NSDL_SUCCESS; -} - -extern int8_t sn_grs_create_resource(struct grs_s *handle, sn_nsdl_dynamic_resource_parameters_s *res) -{ - if (!res || !handle) { - return SN_NSDL_FAILURE; - } - - /* Check path validity */ - if (!res->static_resource_parameters->pathlen || !res->static_resource_parameters->path) { - return SN_GRS_INVALID_PATH; - } - - /* Check if resource already exists */ - if (sn_grs_search_resource(handle, - res->static_resource_parameters->pathlen, - res->static_resource_parameters->path, - SN_GRS_SEARCH_METHOD) != - (sn_nsdl_dynamic_resource_parameters_s *)NULL) { - return SN_GRS_RESOURCE_ALREADY_EXISTS; - } - - if (res) { - res->registered = SN_NDSL_RESOURCE_NOT_REGISTERED; - } - - /* Create resource */ - if (sn_grs_add_resource_to_list(handle, res) == SN_NSDL_SUCCESS) { - return SN_NSDL_SUCCESS; - } - return SN_GRS_LIST_ADDING_FAILURE; -} - -/** - * \fn static int8_t sn_grs_add_resource_to_list(sn_nsdl_dynamic_resource_parameters_s *resource_ptr) - * - * \brief Adds given resource to resource list - * - * \param *resource_ptr Pointer to the path string to be search - * - * \return 0 = SN_NSDL_SUCCESS, -1 = SN_NSDL_FAILURE - * -*/ -static int8_t sn_grs_add_resource_to_list(struct grs_s *handle, sn_nsdl_dynamic_resource_parameters_s *resource_ptr) -{ - /* Local variables */ - - uint8_t *path_start_ptr = NULL; - uint16_t path_len = 0; - sn_nsdl_dynamic_resource_parameters_s *resource_copy_ptr = NULL; - - /* Allocate memory for the resource info copy */ - if (!resource_ptr->static_resource_parameters->pathlen) { //Dead code - return SN_NSDL_FAILURE; - } - - resource_copy_ptr = handle->sn_grs_alloc(sizeof(sn_nsdl_dynamic_resource_parameters_s)); - if (resource_copy_ptr == NULL) { - return SN_NSDL_FAILURE; - } - - /* Set everything to zero */ - memset(resource_copy_ptr, 0, sizeof(sn_nsdl_dynamic_resource_parameters_s)); - resource_copy_ptr->sn_grs_dyn_res_callback = resource_ptr->sn_grs_dyn_res_callback; - resource_copy_ptr->publish_uri = resource_ptr->publish_uri; - resource_copy_ptr->free_on_delete = resource_ptr->free_on_delete; - resource_copy_ptr->coap_content_type = resource_ptr->coap_content_type; - resource_copy_ptr->observable = resource_ptr->observable; - resource_copy_ptr->access = resource_ptr->access; - /* If resource parameters exists, copy them */ - if (resource_ptr->static_resource_parameters) { - resource_copy_ptr->static_resource_parameters = handle->sn_grs_alloc(sizeof(sn_nsdl_static_resource_parameters_s)); - if (!resource_copy_ptr->static_resource_parameters) { - sn_grs_resource_info_free(handle, resource_copy_ptr); - return SN_NSDL_FAILURE; - } - - memset(resource_copy_ptr->static_resource_parameters, 0, sizeof(sn_nsdl_static_resource_parameters_s)); - resource_copy_ptr->static_resource_parameters->mode = - resource_ptr->static_resource_parameters->mode; - resource_copy_ptr->static_resource_parameters->external_memory_block = - resource_ptr->static_resource_parameters->external_memory_block; - resource_copy_ptr->static_resource_parameters->free_on_delete = - resource_ptr->static_resource_parameters->free_on_delete; - - resource_copy_ptr->static_resource_parameters->pathlen = - resource_ptr->static_resource_parameters->pathlen; - resource_copy_ptr->static_resource_parameters->resourcelen = - resource_ptr->static_resource_parameters->resourcelen; - - if (resource_ptr->static_resource_parameters->resource_type_ptr) { - // alloc space for terminating zero too - const size_t resource_type_len = strlen(resource_ptr->static_resource_parameters->resource_type_ptr) + 1; - resource_copy_ptr->static_resource_parameters->resource_type_ptr = - handle->sn_grs_alloc(resource_type_len); - if (!resource_copy_ptr->static_resource_parameters->resource_type_ptr) { - sn_grs_resource_info_free(handle, resource_copy_ptr); - return SN_NSDL_FAILURE; - } - memcpy(resource_copy_ptr->static_resource_parameters->resource_type_ptr, - resource_ptr->static_resource_parameters->resource_type_ptr, - resource_type_len); - } - - if (resource_ptr->static_resource_parameters->interface_description_ptr) { - // todo: a sn_grs_strdup() or similar helper to avoid this copy-paste pattern. - const size_t interface_description_len = strlen(resource_ptr->static_resource_parameters->interface_description_ptr) + 1; - resource_copy_ptr->static_resource_parameters->interface_description_ptr = - handle->sn_grs_alloc(interface_description_len); - if (!resource_copy_ptr->static_resource_parameters->interface_description_ptr) { - sn_grs_resource_info_free(handle, resource_copy_ptr); - return SN_NSDL_FAILURE; - } - memcpy(resource_copy_ptr->static_resource_parameters->interface_description_ptr, - resource_ptr->static_resource_parameters->interface_description_ptr, - interface_description_len); - } - - /* Remove '/' - chars from the beginning and from the end */ - - path_len = resource_ptr->static_resource_parameters->pathlen; - path_start_ptr = sn_grs_convert_uri(&path_len, resource_ptr->static_resource_parameters->path); - - /* Allocate memory for the path */ - resource_copy_ptr->static_resource_parameters->path = handle->sn_grs_alloc(path_len); - if (!resource_copy_ptr->static_resource_parameters->path) { - sn_grs_resource_info_free(handle, resource_copy_ptr); - return SN_NSDL_FAILURE; - } - - /* Update pathlen */ - resource_copy_ptr->static_resource_parameters->pathlen = path_len; - - /* Copy path string to the copy */ - memcpy(resource_copy_ptr->static_resource_parameters->path, - path_start_ptr, - resource_copy_ptr->static_resource_parameters->pathlen); - - /* Allocate memory for the resource, and copy it to copy */ - if (resource_ptr->static_resource_parameters->resource) { - resource_copy_ptr->static_resource_parameters->resource = - handle->sn_grs_alloc(resource_ptr->static_resource_parameters->resourcelen); - if (!resource_copy_ptr->static_resource_parameters->resource) { - sn_grs_resource_info_free(handle, resource_copy_ptr); - return SN_NSDL_FAILURE; - } - memcpy(resource_copy_ptr->static_resource_parameters->resource, - resource_ptr->static_resource_parameters->resource, - resource_ptr->static_resource_parameters->resourcelen); - } - } - - /* Add copied resource to the linked list */ - ns_list_add_to_start(&handle->resource_root_list, resource_copy_ptr); - ++handle->resource_root_count; - - return SN_NSDL_SUCCESS; -} -#endif - -int8_t sn_grs_put_resource(struct grs_s *handle, sn_nsdl_dynamic_resource_parameters_s *res) -{ - if (!res || !handle) { - return SN_NSDL_FAILURE; - } - - /* Check path validity */ - if (!res->static_resource_parameters->pathlen || !res->static_resource_parameters->path) { - return SN_GRS_INVALID_PATH; - } - - /* Check if resource already exists */ - if (sn_grs_search_resource(handle, - res->static_resource_parameters->pathlen, - res->static_resource_parameters->path, SN_GRS_SEARCH_METHOD) != (sn_nsdl_dynamic_resource_parameters_s *)NULL) { - return SN_GRS_RESOURCE_ALREADY_EXISTS; - } - - res->registered = SN_NDSL_RESOURCE_NOT_REGISTERED; - - ns_list_add_to_start(&handle->resource_root_list, res); - ++handle->resource_root_count; - - return SN_NSDL_SUCCESS; -} - -int8_t sn_grs_pop_resource(struct grs_s *handle, sn_nsdl_dynamic_resource_parameters_s *res) -{ - if (!res || !handle) { - return SN_NSDL_FAILURE; - } - - /* Check path validity */ - if (!res->static_resource_parameters->pathlen || !res->static_resource_parameters->path) { - return SN_GRS_INVALID_PATH; - } - - /* Check if resource exists on list. */ - if (sn_grs_search_resource(handle, - res->static_resource_parameters->pathlen, - res->static_resource_parameters->path, SN_GRS_SEARCH_METHOD) == (sn_nsdl_dynamic_resource_parameters_s *)NULL) { - return SN_NSDL_FAILURE; - } - - ns_list_remove(&handle->resource_root_list, res); - --handle->resource_root_count; - - return SN_NSDL_SUCCESS; -} - -/** - * \fn extern int8_t sn_grs_process_coap(uint8_t *packet, uint16_t *packet_len, sn_nsdl_addr_s *src) - * - * \brief To push CoAP packet to GRS library - * - * Used to push an CoAP packet to GRS library for processing. - * - * \param *packet Pointer to a uint8_t array containing the packet (including the CoAP headers). - * After successful execution this array may contain the response packet. - * - * \param *packet_len Pointer to length of the packet. After successful execution this array may contain the length - * of the response packet. - * - * \param *src Pointer to packet source address information. After successful execution this array may contain - * the destination address of the response packet. - * - * \return 0 = success, -1 = failure -*/ -extern int8_t sn_grs_process_coap(struct nsdl_s *nsdl_handle, sn_coap_hdr_s *coap_packet_ptr, sn_nsdl_addr_s *src_addr_ptr) -{ - tr_debug("sn_grs_process_coap"); - if( !coap_packet_ptr || !nsdl_handle){ - return SN_NSDL_FAILURE; - } - - tr_debug("sn_grs_process_coap - coap params:"); - tr_debug("msg code: (%d), msg type: (%d), msg id: (%d), path: (%.*s)", - coap_packet_ptr->msg_code, coap_packet_ptr->msg_type, coap_packet_ptr->msg_id, - coap_packet_ptr->uri_path_len, coap_packet_ptr->uri_path_ptr); - - sn_nsdl_dynamic_resource_parameters_s *resource_temp_ptr = NULL; - sn_coap_msg_code_e status = COAP_MSG_CODE_EMPTY; - sn_coap_hdr_s *response_message_hdr_ptr = NULL; - struct grs_s *handle = nsdl_handle->grs; - bool static_get_request = false; - - if (coap_packet_ptr->msg_code <= COAP_MSG_CODE_REQUEST_DELETE) { - /* Check if .well-known/core */ - if (coap_packet_ptr->uri_path_len == WELLKNOWN_PATH_LEN && memcmp(coap_packet_ptr->uri_path_ptr, WELLKNOWN_PATH, WELLKNOWN_PATH_LEN) == 0) { - return sn_grs_core_request(nsdl_handle, src_addr_ptr, coap_packet_ptr); - } - - /* Get resource */ - resource_temp_ptr = sn_grs_search_resource(handle, coap_packet_ptr->uri_path_len, coap_packet_ptr->uri_path_ptr, SN_GRS_SEARCH_METHOD); - - - /* * * * * * * * * * * */ - /* If resource exists */ - /* * * * * * * * * * * */ - if (resource_temp_ptr) { - tr_debug("sn_grs_process_coap - found (%.*s)", resource_temp_ptr->static_resource_parameters->pathlen, - resource_temp_ptr->static_resource_parameters->path); - /* If dynamic resource, go to callback */ - if (resource_temp_ptr->static_resource_parameters->mode == SN_GRS_DYNAMIC) { - /* Check accesses */ - if (((coap_packet_ptr->msg_code == COAP_MSG_CODE_REQUEST_GET) && !(resource_temp_ptr->access & SN_GRS_GET_ALLOWED)) || - ((coap_packet_ptr->msg_code == COAP_MSG_CODE_REQUEST_POST) && !(resource_temp_ptr->access & SN_GRS_POST_ALLOWED)) || - ((coap_packet_ptr->msg_code == COAP_MSG_CODE_REQUEST_PUT) && !(resource_temp_ptr->access & SN_GRS_PUT_ALLOWED)) || - ((coap_packet_ptr->msg_code == COAP_MSG_CODE_REQUEST_DELETE) && !(resource_temp_ptr->access & SN_GRS_DELETE_ALLOWED))) { - status = COAP_MSG_CODE_RESPONSE_METHOD_NOT_ALLOWED; - } else { - /* Do not call null pointer.. */ - if (resource_temp_ptr->sn_grs_dyn_res_callback != NULL) { - resource_temp_ptr->sn_grs_dyn_res_callback(nsdl_handle, coap_packet_ptr, src_addr_ptr, SN_NSDL_PROTOCOL_COAP); - } - - if (coap_packet_ptr->coap_status == COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED && coap_packet_ptr->payload_ptr) { - handle->sn_grs_free(coap_packet_ptr->payload_ptr); - coap_packet_ptr->payload_ptr = 0; - } - sn_coap_parser_release_allocated_coap_msg_mem(handle->coap, coap_packet_ptr); - return SN_NSDL_SUCCESS; - } - } else { - /* Static resource handling */ - switch (coap_packet_ptr->msg_code) { - case COAP_MSG_CODE_REQUEST_GET: - if (resource_temp_ptr->access & SN_GRS_GET_ALLOWED) { - status = COAP_MSG_CODE_RESPONSE_CONTENT; - static_get_request = true; - } else { - status = COAP_MSG_CODE_RESPONSE_METHOD_NOT_ALLOWED; - } - break; - - case COAP_MSG_CODE_REQUEST_POST: - case COAP_MSG_CODE_REQUEST_PUT: - case COAP_MSG_CODE_REQUEST_DELETE: - status = COAP_MSG_CODE_RESPONSE_METHOD_NOT_ALLOWED; - break; - - default: - status = COAP_MSG_CODE_RESPONSE_FORBIDDEN; - break; - } - } - } - - /* * * * * * * * * * * * * * */ - /* If resource was not found */ - /* * * * * * * * * * * * * * */ - - else { - if (coap_packet_ptr->msg_code == COAP_MSG_CODE_REQUEST_POST) { - handle->sn_grs_rx_callback(nsdl_handle, coap_packet_ptr, src_addr_ptr); - - if (coap_packet_ptr->coap_status == COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED && coap_packet_ptr->payload_ptr) { - handle->sn_grs_free(coap_packet_ptr->payload_ptr); - coap_packet_ptr->payload_ptr = 0; - } - - sn_coap_parser_release_allocated_coap_msg_mem(handle->coap, coap_packet_ptr); - return SN_NSDL_SUCCESS; - } else { - status = COAP_MSG_CODE_RESPONSE_NOT_FOUND; - } - } - } - - /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - /* If received packed was other than reset, create response */ - /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - if (coap_packet_ptr->msg_type != COAP_MSG_TYPE_RESET && coap_packet_ptr->msg_type != COAP_MSG_TYPE_ACKNOWLEDGEMENT) { - - /* Allocate resopnse message */ - response_message_hdr_ptr = sn_coap_parser_alloc_message(handle->coap); - if (!response_message_hdr_ptr) { - if (coap_packet_ptr->coap_status == COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED && coap_packet_ptr->payload_ptr) { - handle->sn_grs_free(coap_packet_ptr->payload_ptr); - coap_packet_ptr->payload_ptr = 0; - } - sn_coap_parser_release_allocated_coap_msg_mem(handle->coap, coap_packet_ptr); - return SN_NSDL_FAILURE; - } - - /* If status has not been defined, response internal server error */ - if (status == COAP_MSG_CODE_EMPTY) { - status = COAP_MSG_CODE_RESPONSE_INTERNAL_SERVER_ERROR; - } - - /* Fill header */ - response_message_hdr_ptr->msg_code = status; - - if (coap_packet_ptr->msg_type == COAP_MSG_TYPE_CONFIRMABLE) { - response_message_hdr_ptr->msg_type = COAP_MSG_TYPE_ACKNOWLEDGEMENT; - } else { - response_message_hdr_ptr->msg_type = COAP_MSG_TYPE_NON_CONFIRMABLE; - } - - response_message_hdr_ptr->msg_id = coap_packet_ptr->msg_id; - - if (coap_packet_ptr->token_ptr) { - response_message_hdr_ptr->token_len = coap_packet_ptr->token_len; - response_message_hdr_ptr->token_ptr = handle->sn_grs_alloc(response_message_hdr_ptr->token_len); - if (!response_message_hdr_ptr->token_ptr) { - sn_coap_parser_release_allocated_coap_msg_mem(handle->coap, response_message_hdr_ptr); - - if (coap_packet_ptr->coap_status == COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED && coap_packet_ptr->payload_ptr) { - handle->sn_grs_free(coap_packet_ptr->payload_ptr); - coap_packet_ptr->payload_ptr = 0; - } - - sn_coap_parser_release_allocated_coap_msg_mem(handle->coap, coap_packet_ptr); - return SN_NSDL_FAILURE; - } - memcpy(response_message_hdr_ptr->token_ptr, coap_packet_ptr->token_ptr, response_message_hdr_ptr->token_len); - } - - if (status == COAP_MSG_CODE_RESPONSE_CONTENT) { - /* Add content type if other than default */ - if (resource_temp_ptr->static_resource_parameters) { - /* XXXX Why "if != 0"? 0 means text/plain, and is not the default for CoAP - this prevents setting text/plain? */ - if (resource_temp_ptr->coap_content_type != 0) { - response_message_hdr_ptr->content_format = - (sn_coap_content_format_e) resource_temp_ptr->coap_content_type; - } - } - - /* Add payload */ - if (resource_temp_ptr->static_resource_parameters->resourcelen != 0) { - response_message_hdr_ptr->payload_len = resource_temp_ptr->static_resource_parameters->resourcelen; - response_message_hdr_ptr->payload_ptr = handle->sn_grs_alloc(response_message_hdr_ptr->payload_len); - - if (!response_message_hdr_ptr->payload_ptr) { - sn_coap_parser_release_allocated_coap_msg_mem(handle->coap, response_message_hdr_ptr); - - if (coap_packet_ptr->coap_status == COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED && coap_packet_ptr->payload_ptr) { - handle->sn_grs_free(coap_packet_ptr->payload_ptr); - coap_packet_ptr->payload_ptr = 0; - } - - sn_coap_parser_release_allocated_coap_msg_mem(handle->coap, coap_packet_ptr); - return SN_NSDL_FAILURE; - } - - memcpy(response_message_hdr_ptr->payload_ptr, - resource_temp_ptr->static_resource_parameters->resource, - response_message_hdr_ptr->payload_len); - } - // Add max-age attribute for static resources. - // Not a mandatory parameter, no need to return in case of memory allocation fails. - if (static_get_request) { - if (sn_coap_parser_alloc_options(handle->coap, response_message_hdr_ptr)) { - response_message_hdr_ptr->options_list_ptr->max_age = 0; - } - } - } - sn_grs_send_coap_message(nsdl_handle, src_addr_ptr, response_message_hdr_ptr); - - if (response_message_hdr_ptr->payload_ptr) { - handle->sn_grs_free(response_message_hdr_ptr->payload_ptr); - response_message_hdr_ptr->payload_ptr = 0; - } - sn_coap_parser_release_allocated_coap_msg_mem(handle->coap, response_message_hdr_ptr); - } - - /* Free parsed CoAP message */ - if (coap_packet_ptr->coap_status == COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED && coap_packet_ptr->payload_ptr) { - handle->sn_grs_free(coap_packet_ptr->payload_ptr); - coap_packet_ptr->payload_ptr = 0; - } - sn_coap_parser_release_allocated_coap_msg_mem(handle->coap, coap_packet_ptr); - - return SN_NSDL_SUCCESS; -} - -extern int8_t sn_grs_send_coap_message(struct nsdl_s *handle, sn_nsdl_addr_s *address_ptr, sn_coap_hdr_s *coap_hdr_ptr) -{ - tr_debug("sn_grs_send_coap_message"); - uint8_t *message_ptr = NULL; - uint16_t message_len = 0; - uint8_t ret_val = 0; - - if( !handle ){ - return SN_NSDL_FAILURE; - } - -#if SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE /* If Message blockwising is not used at all, this part of code will not be compiled */ - ret_val = prepare_blockwise_message(handle->grs->coap, coap_hdr_ptr); - if( 0 != ret_val ) { - return SN_NSDL_FAILURE; - } -#endif - - /* Calculate message length */ - message_len = sn_coap_builder_calc_needed_packet_data_size_2(coap_hdr_ptr, handle->grs->coap->sn_coap_block_data_size); - tr_debug("sn_grs_send_coap_message - msg len after calc: [%d]", message_len); - tr_debug("sn_grs_send_coap_message - msg id: [%d]", coap_hdr_ptr->msg_id); - - /* Allocate memory for message and check was allocating successfully */ - message_ptr = handle->grs->sn_grs_alloc(message_len); - if (message_ptr == NULL) { - return SN_NSDL_FAILURE; - } - - /* Build CoAP message */ - if (sn_coap_protocol_build(handle->grs->coap, address_ptr, message_ptr, coap_hdr_ptr, (void *)handle) < 0) { - handle->grs->sn_grs_free(message_ptr); - message_ptr = 0; - return SN_NSDL_FAILURE; - } - - /* Call tx callback function to send message */ - ret_val = handle->grs->sn_grs_tx_callback(handle, SN_NSDL_PROTOCOL_COAP, message_ptr, message_len, address_ptr); - - /* Free allocated memory */ - handle->grs->sn_grs_free(message_ptr); - message_ptr = 0; - - if (ret_val == 0) { - return SN_NSDL_FAILURE; - } else { - return SN_NSDL_SUCCESS; - } -} - -static int8_t sn_grs_core_request(struct nsdl_s *handle, sn_nsdl_addr_s *src_addr_ptr, sn_coap_hdr_s *coap_packet_ptr) -{ - sn_coap_hdr_s *response_message_hdr_ptr = NULL; - sn_coap_content_format_e wellknown_content_format = COAP_CT_LINK_FORMAT; - - /* Allocate response message */ - response_message_hdr_ptr = sn_coap_parser_alloc_message(handle->grs->coap); - if (response_message_hdr_ptr == NULL) { - if (coap_packet_ptr->coap_status == COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED && coap_packet_ptr->payload_ptr) { - handle->grs->sn_grs_free(coap_packet_ptr->payload_ptr); - coap_packet_ptr->payload_ptr = 0; - } - sn_coap_parser_release_allocated_coap_msg_mem(handle->grs->coap, coap_packet_ptr); - return SN_NSDL_FAILURE; - } - - /* Build response */ - response_message_hdr_ptr->msg_code = COAP_MSG_CODE_RESPONSE_CONTENT; - response_message_hdr_ptr->msg_type = COAP_MSG_TYPE_ACKNOWLEDGEMENT; - response_message_hdr_ptr->msg_id = coap_packet_ptr->msg_id; - response_message_hdr_ptr->content_format = wellknown_content_format; - - sn_nsdl_build_registration_body(handle, response_message_hdr_ptr, 0); - - /* Send and free */ - sn_grs_send_coap_message(handle, src_addr_ptr, response_message_hdr_ptr); - - if (response_message_hdr_ptr->payload_ptr) { - handle->grs->sn_grs_free(response_message_hdr_ptr->payload_ptr); - response_message_hdr_ptr->payload_ptr = 0; - } - sn_coap_parser_release_allocated_coap_msg_mem(handle->grs->coap, response_message_hdr_ptr); - - /* Free parsed CoAP message */ - if (coap_packet_ptr->coap_status == COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED && coap_packet_ptr->payload_ptr) { - handle->grs->sn_grs_free(coap_packet_ptr->payload_ptr); - coap_packet_ptr->payload_ptr = 0; - } - sn_coap_parser_release_allocated_coap_msg_mem(handle->grs->coap, coap_packet_ptr); - - return SN_NSDL_SUCCESS; -} - -/** - * \fn static sn_grs_resource_info_s *sn_grs_search_resource(uint16_t pathlen, uint8_t *path, uint8_t search_method) - * - * \brief Searches given resource from linked list - * - * Search either precise path, or subresources, eg. dr/x -> returns dr/x/1, dr/x/2 etc... - * - * \param pathlen Length of the path to be search - * - * \param *path Pointer to the path string to be search - * - * \param search_method Search method, SEARCH or DELETE - * - * \return Pointer to the resource. If resource not found, return value is NULL - * -*/ - -sn_nsdl_dynamic_resource_parameters_s *sn_grs_search_resource(struct grs_s *handle, uint16_t pathlen, uint8_t *path, uint8_t search_method) -{ - /* Local variables */ - uint8_t *path_temp_ptr = NULL; - /* Check parameters */ - if (!handle || !pathlen || !path) { - return NULL; - } - - /* Remove '/' - marks from the end and beginning */ - path_temp_ptr = sn_grs_convert_uri(&pathlen, path); - - /* Searchs exact path */ - if (search_method == SN_GRS_SEARCH_METHOD) { - /* Scan all nodes on list */ - ns_list_foreach(sn_nsdl_dynamic_resource_parameters_s, resource_search_temp, &handle->resource_root_list) { - /* If length equals.. */ - if (resource_search_temp->static_resource_parameters->pathlen == pathlen) { - /* Compare paths, If same return node pointer*/ - if (0 == memcmp(resource_search_temp->static_resource_parameters->path, - path_temp_ptr, - pathlen)) { - return resource_search_temp; - } - } - } - } - /* Search also subresources, eg. dr/x -> returns dr/x/1, dr/x/2 etc... */ - else if (search_method == SN_GRS_DELETE_METHOD) { - /* Scan all nodes on list */ - ns_list_foreach(sn_nsdl_dynamic_resource_parameters_s, resource_search_temp, &handle->resource_root_list) { - uint8_t *temp_path = resource_search_temp->static_resource_parameters->path; - if (resource_search_temp->static_resource_parameters->pathlen > pathlen && - (*(temp_path + (uint8_t)pathlen) == '/') && - 0 == memcmp(resource_search_temp->static_resource_parameters->path, - path_temp_ptr, - pathlen)) { - return resource_search_temp; - } - } - } - - /* If there was not nodes we wanted, return NULL */ - return NULL; -} - -/** - * \fn static uint8_t *sn_grs_convert_uri(uint16_t *uri_len, uint8_t *uri_ptr) - * - * \brief Removes '/' from the beginning and from the end of uri string - * - * \param *uri_len Pointer to the length of the path string - * - * \param *uri_ptr Pointer to the path string - * - * \return start pointer of the uri - * -*/ - -static uint8_t *sn_grs_convert_uri(uint16_t *uri_len, uint8_t *uri_ptr) -{ - /* Local variables */ - uint8_t *uri_start_ptr = uri_ptr; - - /* If '/' in the beginning, update uri start pointer and uri len */ - if (*uri_ptr == '/') { - uri_start_ptr = uri_ptr + 1; - *uri_len = *uri_len - 1; - } - - /* If '/' at the end, update uri len */ - if (*(uri_start_ptr + *uri_len - 1) == '/') { - *uri_len = *uri_len - 1; - } - - /* Return start pointer */ - return uri_start_ptr; -} - -/** - * \fn static int8_t sn_grs_resource_info_free(sn_grs_resource_info_s *resource_ptr) - * - * \brief Frees resource info structure - * - * \param *resource_ptr Pointer to the resource - * - * \return 0 if success, -1 if failed - * -*/ -static int8_t sn_grs_resource_info_free(struct grs_s *handle, sn_nsdl_dynamic_resource_parameters_s *resource_ptr) -{ - if (resource_ptr) { -#ifdef MEMORY_OPTIMIZED_API - if (resource_ptr->free_on_delete) { - handle->sn_grs_free(resource_ptr); - } - return SN_NSDL_FAILURE; -#else - if (resource_ptr->static_resource_parameters && - resource_ptr->static_resource_parameters->free_on_delete) { - if (resource_ptr->static_resource_parameters->interface_description_ptr) { - handle->sn_grs_free(resource_ptr->static_resource_parameters->interface_description_ptr); - resource_ptr->static_resource_parameters->interface_description_ptr = 0; - } - - if (resource_ptr->static_resource_parameters->resource_type_ptr) { - handle->sn_grs_free(resource_ptr->static_resource_parameters->resource_type_ptr); - resource_ptr->static_resource_parameters->resource_type_ptr = 0; - } - - if (resource_ptr->static_resource_parameters->path) { - handle->sn_grs_free(resource_ptr->static_resource_parameters->path); - resource_ptr->static_resource_parameters->path = 0; - } - - if (resource_ptr->static_resource_parameters->resource) { - handle->sn_grs_free(resource_ptr->static_resource_parameters->resource); - resource_ptr->static_resource_parameters->resource = 0; - } - - handle->sn_grs_free(resource_ptr->static_resource_parameters); - resource_ptr->static_resource_parameters = 0; - } - if (resource_ptr->free_on_delete) { - handle->sn_grs_free(resource_ptr); - } - return SN_NSDL_SUCCESS; -#endif - } - return SN_NSDL_FAILURE; //Dead code? -} - -void sn_grs_mark_resources_as_registered(struct nsdl_s *handle) -{ - if( !handle ){ - return; - } - - sn_nsdl_dynamic_resource_parameters_s *temp_resource; - - temp_resource = sn_grs_get_first_resource(handle->grs); - - while (temp_resource) { - if (temp_resource->registered == SN_NDSL_RESOURCE_REGISTERING) { - temp_resource->registered = SN_NDSL_RESOURCE_REGISTERED; - } - temp_resource = sn_grs_get_next_resource(handle->grs, temp_resource); - } -} -#endif diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/source/libNsdl/src/sn_nsdl.c b/features/FEATURE_COMMON_PAL/mbed-client-c/source/libNsdl/src/sn_nsdl.c deleted file mode 100755 index ff5ec8b1a3..0000000000 --- a/features/FEATURE_COMMON_PAL/mbed-client-c/source/libNsdl/src/sn_nsdl.c +++ /dev/null @@ -1,2611 +0,0 @@ -/* - * Copyright (c) 2011-2015 ARM Limited. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 - * Licensed under the Apache License, Version 2.0 (the License); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * \file sn_nsdl.c - * - * \brief Nano service device library - * - */ - -#ifndef MBED_CLIENT_C_NEW_API - -#include - -#include "ns_types.h" -#include "sn_nsdl.h" -#include "sn_coap_header.h" -#include "sn_coap_protocol.h" -#include "sn_coap_protocol_internal.h" -#include "sn_nsdl_lib.h" -#include "sn_grs.h" -#include "sn_config.h" -#include "mbed-trace/mbed_trace.h" - -#define TRACE_GROUP "coap" -/* Defines */ -#define TRACE_GROUP "coap" -#define RESOURCE_DIR_LEN 2 -#define EP_NAME_PARAMETERS_LEN 3 -#define ET_PARAMETER_LEN 3 -#define LT_PARAMETER_LEN 3 -#define DOMAIN_PARAMETER_LEN 2 -#define RT_PARAMETER_LEN 3 -#define IF_PARAMETER_LEN 3 -#define OBS_PARAMETER_LEN 3 -#define AOBS_PARAMETER_LEN 8 -#define COAP_CON_PARAMETER_LEN 3 -#define BS_EP_PARAMETER_LEN 3 -#define BS_QUEUE_MODE_PARAMATER_LEN 2 - -#define SN_NSDL_EP_REGISTER_MESSAGE 1 -#define SN_NSDL_EP_UPDATE_MESSAGE 2 - -#define SN_NSDL_MSG_UNDEFINED 0 -#define SN_NSDL_MSG_REGISTER 1 -#define SN_NSDL_MSG_UNREGISTER 2 -#define SN_NSDL_MSG_UPDATE 3 -#define SN_NSDL_MSG_BOOTSTRAP 4 - -#ifdef YOTTA_CFG_DISABLE_OBS_FEATURE -#define COAP_DISABLE_OBS_FEATURE YOTTA_CFG_DISABLE_OBS_FEATURE -#elif defined MBED_CONF_MBED_CLIENT_COAP_DISABLE_OBS_FEATURE -#define COAP_DISABLE_OBS_FEATURE MBED_CONF_MBED_CLIENT_COAP_DISABLE_OBS_FEATURE -#endif - -#ifdef YOTTA_CFG_DISABLE_BOOTSTRAP_FEATURE -#define MBED_CLIENT_DISABLE_BOOTSTRAP_FEATURE YOTTA_CFG_DISABLE_BOOTSTRAP_FEATURE -#elif defined MBED_CONF_MBED_CLIENT_DISABLE_BOOTSTRAP_FEATURE -#define MBED_CLIENT_DISABLE_BOOTSTRAP_FEATURE MBED_CONF_MBED_CLIENT_DISABLE_BOOTSTRAP_FEATURE -#endif - - -/* Constants */ -static uint8_t ep_name_parameter_string[] = {'e', 'p', '='}; /* Endpoint name. A unique name for the registering node in a domain. */ -static uint8_t resource_path_ptr[] = {'r', 'd'}; /* For resource directory */ -static uint8_t resource_type_parameter[] = {'r', 't', '='}; /* Resource type. Only once for registration */ -#ifndef COAP_DISABLE_OBS_FEATURE -static uint8_t obs_parameter[] = {'o', 'b', 's'}; /* Observable */ -#endif -//static uint8_t aobs_parameter[] = {'a','o','b','s',';','i','d','='}; /* Auto-observable - TBD */ -static uint8_t if_description_parameter[] = {'i', 'f', '='}; /* Interface description. Only once */ -static uint8_t ep_lifetime_parameter[] = {'l', 't', '='}; /* Lifetime. Number of seconds that this registration will be valid for. Must be updated within this time, or will be removed. */ -static uint8_t ep_domain_parameter[] = {'d', '='}; /* Domain name. If this parameter is missing, a default domain is assumed. */ -static uint8_t coap_con_type_parameter[] = {'c', 't', '='}; /* CoAP content type */ -/* * OMA BS parameters * */ -static uint8_t bs_uri[] = {'b', 's'}; -static uint8_t bs_ep_name[] = {'e', 'p', '='}; -static uint8_t et_parameter[] = {'e', 't', '='}; /* Endpoint type */ -static uint8_t bs_queue_mode[] = {'b', '='}; - -/* Function prototypes */ -static uint16_t sn_nsdl_internal_coap_send(struct nsdl_s *handle, sn_coap_hdr_s *coap_header_ptr, sn_nsdl_addr_s *dst_addr_ptr, uint8_t message_description); -static void sn_nsdl_resolve_nsp_address(struct nsdl_s *handle); -int8_t sn_nsdl_build_registration_body(struct nsdl_s *handle, sn_coap_hdr_s *message_ptr, uint8_t updating_registeration); -static uint16_t sn_nsdl_calculate_registration_body_size(struct nsdl_s *handle, uint8_t updating_registeration, int8_t *error); -static uint8_t sn_nsdl_calculate_uri_query_option_len(sn_nsdl_ep_parameters_s *endpoint_info_ptr, uint8_t msg_type); -static int8_t sn_nsdl_fill_uri_query_options(struct nsdl_s *handle, sn_nsdl_ep_parameters_s *parameter_ptr, sn_coap_hdr_s *source_msg_ptr, uint8_t msg_type); -static int8_t sn_nsdl_local_rx_function(struct nsdl_s *handle, sn_coap_hdr_s *coap_packet_ptr, sn_nsdl_addr_s *address_ptr); -static int8_t sn_nsdl_resolve_ep_information(struct nsdl_s *handle, sn_coap_hdr_s *coap_packet_ptr); -static uint8_t sn_nsdl_itoa_len(uint8_t value); -static uint8_t *sn_nsdl_itoa(uint8_t *ptr, uint8_t value); -static int32_t sn_nsdl_atoi(uint8_t *ptr, uint8_t len); -static uint32_t sn_nsdl_ahextoi(uint8_t *ptr, uint8_t len); -static int8_t sn_nsdl_resolve_lwm2m_address(struct nsdl_s *handle, uint8_t *uri, uint16_t uri_len); -static int8_t sn_nsdl_process_oma_tlv(struct nsdl_s *handle, uint8_t *data_ptr, uint16_t data_len); -static void sn_nsdl_check_oma_bs_status(struct nsdl_s *handle); -static int8_t sn_nsdl_create_oma_device_object_base(struct nsdl_s *handle, sn_nsdl_oma_device_t *oma_device_setup_ptr, sn_nsdl_oma_binding_and_mode_t binding_and_mode); -static int8_t set_endpoint_info(struct nsdl_s *handle, sn_nsdl_ep_parameters_s *endpoint_info_ptr); -static bool validateParameters(sn_nsdl_ep_parameters_s *parameter_ptr); -static bool validate(uint8_t* ptr, uint32_t len, char illegalChar); -static bool sn_nsdl_check_uint_overflow(uint16_t resource_size, uint16_t param_a, uint16_t param_b); - -int8_t sn_nsdl_destroy(struct nsdl_s *handle) -{ - if (handle == NULL) { - return SN_NSDL_FAILURE; - } - - if (handle->ep_information_ptr) { - if (handle->ep_information_ptr->endpoint_name_ptr) { - handle->sn_nsdl_free(handle->ep_information_ptr->endpoint_name_ptr); - handle->ep_information_ptr->endpoint_name_ptr = 0; - } - if (handle->ep_information_ptr->domain_name_ptr) { - handle->sn_nsdl_free(handle->ep_information_ptr->domain_name_ptr); - handle->ep_information_ptr->domain_name_ptr = 0; - handle->ep_information_ptr->domain_name_len = 0; - } - if (handle->ep_information_ptr->location_ptr) { - handle->sn_nsdl_free(handle->ep_information_ptr->location_ptr); - handle->ep_information_ptr->location_ptr = 0; - handle->ep_information_ptr->location_len = 0; - } - if (handle->ep_information_ptr->type_ptr) { - handle->sn_nsdl_free(handle->ep_information_ptr->type_ptr); - handle->ep_information_ptr->type_ptr = 0; - } - - if (handle->ep_information_ptr->lifetime_ptr) - - { - handle->sn_nsdl_free(handle->ep_information_ptr->lifetime_ptr); - handle->ep_information_ptr->lifetime_ptr = 0; - } - - handle->sn_nsdl_free(handle->ep_information_ptr); - handle->ep_information_ptr = 0; - } - - if (handle->nsp_address_ptr) { - if (handle->nsp_address_ptr->omalw_address_ptr) { - if (handle->nsp_address_ptr->omalw_address_ptr->addr_ptr) { - handle->sn_nsdl_free(handle->nsp_address_ptr->omalw_address_ptr->addr_ptr); - handle->nsp_address_ptr->omalw_address_ptr->addr_ptr = 0; - } - handle->sn_nsdl_free(handle->nsp_address_ptr->omalw_address_ptr); - } - - handle->sn_nsdl_free(handle->nsp_address_ptr); - handle->nsp_address_ptr = 0; - } - - if (handle->oma_bs_address_ptr) { - handle->sn_nsdl_free(handle->oma_bs_address_ptr); - } - - /* Destroy also libCoap and grs part of libNsdl */ - sn_coap_protocol_destroy(handle->grs->coap); - sn_grs_destroy(handle->grs); - handle->sn_nsdl_free(handle); - - return SN_NSDL_SUCCESS; -} - -struct nsdl_s *sn_nsdl_init(uint8_t (*sn_nsdl_tx_cb)(struct nsdl_s *, sn_nsdl_capab_e , uint8_t *, uint16_t, sn_nsdl_addr_s *), - uint8_t (*sn_nsdl_rx_cb)(struct nsdl_s *, sn_coap_hdr_s *, sn_nsdl_addr_s *), - void *(*sn_nsdl_alloc)(uint16_t), void (*sn_nsdl_free)(void *)) -{ - /* Check pointers and define function pointers */ - if (!sn_nsdl_alloc || !sn_nsdl_free || !sn_nsdl_tx_cb || !sn_nsdl_rx_cb) { - return NULL; - } - - struct nsdl_s *handle = NULL; - - handle = sn_nsdl_alloc(sizeof(struct nsdl_s)); - - if (handle == NULL) { - return NULL; - } - - memset(handle, 0, sizeof(struct nsdl_s)); - - /* Define function pointers */ - handle->sn_nsdl_alloc = sn_nsdl_alloc; - handle->sn_nsdl_free = sn_nsdl_free; - - handle->sn_nsdl_tx_callback = sn_nsdl_tx_cb; - handle->sn_nsdl_rx_callback = sn_nsdl_rx_cb; - - /* Initialize ep parameters struct */ - if (!handle->ep_information_ptr) { - handle->ep_information_ptr = handle->sn_nsdl_alloc(sizeof(sn_nsdl_ep_parameters_s)); - if (!handle->ep_information_ptr) { - sn_nsdl_free(handle); - return NULL; - } - memset(handle->ep_information_ptr, 0, sizeof(sn_nsdl_ep_parameters_s)); - } - - handle->grs = sn_grs_init(sn_nsdl_tx_cb, &sn_nsdl_local_rx_function, sn_nsdl_alloc, sn_nsdl_free); - - /* Initialize GRS */ - if (handle->grs == NULL) { - handle->sn_nsdl_free(handle->ep_information_ptr); - handle->ep_information_ptr = 0; - sn_nsdl_free(handle); - return NULL; - } - - sn_nsdl_resolve_nsp_address(handle); - - handle->sn_nsdl_endpoint_registered = SN_NSDL_ENDPOINT_NOT_REGISTERED; - // By default bootstrap msgs are handled in nsdl - handle->handle_bootstrap_msg = true; - handle->context = NULL; - - return handle; -} - -uint16_t sn_nsdl_register_endpoint(struct nsdl_s *handle, sn_nsdl_ep_parameters_s *endpoint_info_ptr) -{ - /* Local variables */ - sn_coap_hdr_s *register_message_ptr; - uint16_t message_id = 0; - - if (endpoint_info_ptr == NULL || handle == NULL) { - return 0; - } - - /*** Build endpoint register message ***/ - - /* Allocate memory for header struct */ - register_message_ptr = sn_coap_parser_alloc_message(handle->grs->coap); - if (register_message_ptr == NULL) { - return 0; - } - - /* Fill message fields -> confirmable post to specified NSP path */ - register_message_ptr->msg_type = COAP_MSG_TYPE_CONFIRMABLE; - register_message_ptr->msg_code = COAP_MSG_CODE_REQUEST_POST; - - /* Allocate memory for the extended options list */ - if (sn_coap_parser_alloc_options(handle->grs->coap, register_message_ptr) == NULL) { - sn_coap_parser_release_allocated_coap_msg_mem(handle->grs->coap, register_message_ptr); - register_message_ptr = 0; - return 0; - } - - register_message_ptr->uri_path_len = sizeof(resource_path_ptr); - register_message_ptr->uri_path_ptr = resource_path_ptr; - - /* Fill Uri-query options */ - if( SN_NSDL_FAILURE == sn_nsdl_fill_uri_query_options(handle, endpoint_info_ptr, - register_message_ptr, SN_NSDL_EP_REGISTER_MESSAGE) ){ - register_message_ptr->uri_path_ptr = NULL; - sn_coap_parser_release_allocated_coap_msg_mem(handle->grs->coap, register_message_ptr); - return 0; - } - - if (endpoint_info_ptr->ds_register_mode == REGISTER_WITH_RESOURCES) { - /* Built body for message */ - if (sn_nsdl_build_registration_body(handle, register_message_ptr, 0) == SN_NSDL_FAILURE) { - register_message_ptr->uri_path_ptr = NULL; - register_message_ptr->options_list_ptr->uri_host_ptr = NULL; - sn_coap_parser_release_allocated_coap_msg_mem(handle->grs->coap, register_message_ptr); - return 0; - } - } - - /* Clean (possible) existing and save new endpoint info to handle */ - if (set_endpoint_info(handle, endpoint_info_ptr) == -1) { - if (register_message_ptr->payload_ptr) { - handle->sn_nsdl_free(register_message_ptr->payload_ptr); - register_message_ptr->payload_ptr = NULL; - } - - register_message_ptr->uri_path_ptr = NULL; - register_message_ptr->options_list_ptr->uri_host_ptr = NULL; - - sn_coap_parser_release_allocated_coap_msg_mem(handle->grs->coap, register_message_ptr); - - return 0; - } - - /* Build and send coap message to NSP */ - message_id = sn_nsdl_internal_coap_send(handle, register_message_ptr, handle->nsp_address_ptr->omalw_address_ptr, SN_NSDL_MSG_REGISTER); - - if (register_message_ptr->payload_ptr) { - handle->sn_nsdl_free(register_message_ptr->payload_ptr); - register_message_ptr->payload_ptr = NULL; - } - - register_message_ptr->uri_path_ptr = NULL; - register_message_ptr->options_list_ptr->uri_host_ptr = NULL; - - sn_coap_parser_release_allocated_coap_msg_mem(handle->grs->coap, register_message_ptr); - - return message_id; -} - -uint16_t sn_nsdl_unregister_endpoint(struct nsdl_s *handle) -{ - /* Local variables */ - sn_coap_hdr_s *unregister_message_ptr; - uint8_t *temp_ptr = 0; - uint16_t message_id = 0; - - /* Check parameters */ - if (handle == NULL) { - return 0; - } - - /* Check that EP have been registered */ - if (sn_nsdl_is_ep_registered(handle)) { - - /* Memory allocation for unregister message */ - unregister_message_ptr = sn_coap_parser_alloc_message(handle->grs->coap); - if (!unregister_message_ptr) { - return 0; - } - - /* Fill unregister message */ - unregister_message_ptr->msg_type = COAP_MSG_TYPE_CONFIRMABLE; - unregister_message_ptr->msg_code = COAP_MSG_CODE_REQUEST_DELETE; - - if(handle->ep_information_ptr->location_ptr) { - unregister_message_ptr->uri_path_len = handle->ep_information_ptr->location_len; - unregister_message_ptr->uri_path_ptr = handle->sn_nsdl_alloc(unregister_message_ptr->uri_path_len); - if (!unregister_message_ptr->uri_path_ptr) { - sn_coap_parser_release_allocated_coap_msg_mem(handle->grs->coap, unregister_message_ptr); - return 0; - } - - temp_ptr = unregister_message_ptr->uri_path_ptr; - - memcpy(temp_ptr , handle->ep_information_ptr->location_ptr, handle->ep_information_ptr->location_len); - } else { - unregister_message_ptr->uri_path_len = (RESOURCE_DIR_LEN + 1 + handle->ep_information_ptr->domain_name_len + 1 + handle->ep_information_ptr->endpoint_name_len); - unregister_message_ptr->uri_path_ptr = handle->sn_nsdl_alloc(unregister_message_ptr->uri_path_len); - if (!unregister_message_ptr->uri_path_ptr) { - sn_coap_parser_release_allocated_coap_msg_mem(handle->grs->coap, unregister_message_ptr); - return 0; - } - - temp_ptr = unregister_message_ptr->uri_path_ptr; - - memcpy(temp_ptr, resource_path_ptr, RESOURCE_DIR_LEN); - temp_ptr += RESOURCE_DIR_LEN; - - *temp_ptr++ = '/'; - - memcpy(temp_ptr , handle->ep_information_ptr->domain_name_ptr, handle->ep_information_ptr->domain_name_len); - temp_ptr += handle->ep_information_ptr->domain_name_len; - - *temp_ptr++ = '/'; - - memcpy(temp_ptr , handle->ep_information_ptr->endpoint_name_ptr, handle->ep_information_ptr->endpoint_name_len); - } - - /* Send message */ - message_id = sn_nsdl_internal_coap_send(handle, unregister_message_ptr, handle->nsp_address_ptr->omalw_address_ptr, SN_NSDL_MSG_UNREGISTER); - - /* Free memory */ - sn_coap_parser_release_allocated_coap_msg_mem(handle->grs->coap, unregister_message_ptr); - - } - - return message_id; -} - -uint16_t sn_nsdl_update_registration(struct nsdl_s *handle, uint8_t *lt_ptr, uint8_t lt_len) -{ - /* Local variables */ - sn_coap_hdr_s *register_message_ptr; - uint8_t *temp_ptr; - sn_nsdl_ep_parameters_s temp_parameters; - uint16_t message_id = 0; - - /* Check parameters */ - if (handle == NULL) { - return 0; - } - - if (!sn_nsdl_is_ep_registered(handle)){ - return 0; - } - - memset(&temp_parameters, 0, sizeof(sn_nsdl_ep_parameters_s)); - - temp_parameters.lifetime_len = lt_len; - temp_parameters.lifetime_ptr = lt_ptr; - - /*** Build endpoint register update message ***/ - - /* Allocate memory for header struct */ - register_message_ptr = sn_coap_parser_alloc_message(handle->grs->coap); - if (register_message_ptr == NULL) { - return 0; - } - - /* Fill message fields -> confirmable post to specified NSP path */ - register_message_ptr->msg_type = COAP_MSG_TYPE_CONFIRMABLE; - register_message_ptr->msg_code = COAP_MSG_CODE_REQUEST_POST; - - if(handle->ep_information_ptr->location_ptr) { - register_message_ptr->uri_path_len = handle->ep_information_ptr->location_len; /* = Only location set by Device Server*/ - - register_message_ptr->uri_path_ptr = handle->sn_nsdl_alloc(register_message_ptr->uri_path_len); - if (!register_message_ptr->uri_path_ptr) { - sn_coap_parser_release_allocated_coap_msg_mem(handle->grs->coap, register_message_ptr); - return 0; - } - - temp_ptr = register_message_ptr->uri_path_ptr; - - /* location */ - memcpy(temp_ptr, handle->ep_information_ptr->location_ptr, handle->ep_information_ptr->location_len); - } else { - register_message_ptr->uri_path_len = sizeof(resource_path_ptr) + handle->ep_information_ptr->domain_name_len + handle->ep_information_ptr->endpoint_name_len + 2; /* = rd/domain/endpoint */ - - register_message_ptr->uri_path_ptr = handle->sn_nsdl_alloc(register_message_ptr->uri_path_len); - if (!register_message_ptr->uri_path_ptr) { - sn_coap_parser_release_allocated_coap_msg_mem(handle->grs->coap, register_message_ptr); - return 0; - } - - temp_ptr = register_message_ptr->uri_path_ptr; - - /* rd/ */ - memcpy(temp_ptr, resource_path_ptr, sizeof(resource_path_ptr)); - temp_ptr += sizeof(resource_path_ptr); - *temp_ptr++ = '/'; - - /* rd/DOMAIN/ */ - memcpy(temp_ptr, handle->ep_information_ptr->domain_name_ptr, handle->ep_information_ptr->domain_name_len); - temp_ptr += handle->ep_information_ptr->domain_name_len; - *temp_ptr++ = '/'; - - /* rd/domain/ENDPOINT */ - memcpy(temp_ptr, handle->ep_information_ptr->endpoint_name_ptr, handle->ep_information_ptr->endpoint_name_len); - } - - /* Allocate memory for the extended options list */ - if (sn_coap_parser_alloc_options(handle->grs->coap, register_message_ptr) == NULL) { - sn_coap_parser_release_allocated_coap_msg_mem(handle->grs->coap, register_message_ptr); - return 0; - } - - /* Fill Uri-query options */ - sn_nsdl_fill_uri_query_options(handle, &temp_parameters, register_message_ptr, SN_NSDL_EP_UPDATE_MESSAGE); - - /* Build payload */ - if (handle->ep_information_ptr->ds_register_mode == REGISTER_WITH_RESOURCES) { - - if (sn_nsdl_build_registration_body(handle, register_message_ptr, 1) == SN_NSDL_FAILURE) { - sn_coap_parser_release_allocated_coap_msg_mem(handle->grs->coap, register_message_ptr); - return 0; - } - } - - /* Build and send coap message to NSP */ - message_id = sn_nsdl_internal_coap_send(handle, register_message_ptr, handle->nsp_address_ptr->omalw_address_ptr, SN_NSDL_MSG_UPDATE); - - if (register_message_ptr->payload_ptr) { - handle->sn_nsdl_free(register_message_ptr->payload_ptr); - } - sn_coap_parser_release_allocated_coap_msg_mem(handle->grs->coap, register_message_ptr); - - return message_id; -} - -int8_t sn_nsdl_set_endpoint_location(struct nsdl_s *handle, uint8_t *location_ptr, uint8_t location_len) -{ - if(!handle || !location_ptr || (location_len == 0)) { - return -1; - } - - handle->sn_nsdl_free(handle->ep_information_ptr->location_ptr); - handle->ep_information_ptr->location_ptr = handle->sn_nsdl_alloc(location_len); - memcpy(handle->ep_information_ptr->location_ptr, location_ptr, location_len); - handle->ep_information_ptr->location_len = location_len; - - return 0; -} - -void sn_nsdl_nsp_lost(struct nsdl_s *handle) -{ - /* Check parameters */ - if (handle == NULL) { - return; - } - - handle->sn_nsdl_endpoint_registered = SN_NSDL_ENDPOINT_NOT_REGISTERED; -} - -int8_t sn_nsdl_is_ep_registered(struct nsdl_s *handle) -{ - /* Check parameters */ - if (handle == NULL) { - return SN_NSDL_FAILURE; - } - - return handle->sn_nsdl_endpoint_registered; -} - -uint16_t sn_nsdl_send_observation_notification(struct nsdl_s *handle, uint8_t *token_ptr, uint8_t token_len, - uint8_t *payload_ptr, uint16_t payload_len, - sn_coap_observe_e observe, - sn_coap_msg_type_e message_type, sn_coap_content_format_e content_format) -{ - return sn_nsdl_send_observation_notification_with_uri_path(handle, - token_ptr, - token_len, - payload_ptr, - payload_len, - observe, - message_type, - content_format, - NULL, - 0); -} - -uint16_t sn_nsdl_send_observation_notification_with_uri_path(struct nsdl_s *handle, uint8_t *token_ptr, uint8_t token_len, - uint8_t *payload_ptr, uint16_t payload_len, - sn_coap_observe_e observe, - sn_coap_msg_type_e message_type, uint8_t content_format, - uint8_t *uri_path_ptr, uint16_t uri_path_len) -{ - sn_coap_hdr_s *notification_message_ptr; - uint16_t return_msg_id = 0; - - /* Check parameters */ - if (handle == NULL || handle->grs == NULL) { - return 0; - } - - /* Allocate and initialize memory for header struct */ - notification_message_ptr = sn_coap_parser_alloc_message(handle->grs->coap); - if (notification_message_ptr == NULL) { - return 0; - } - - if (sn_coap_parser_alloc_options(handle->grs->coap, notification_message_ptr) == NULL) { - handle->sn_nsdl_free(notification_message_ptr); - return 0; - } - - /* Fill header */ - notification_message_ptr->msg_type = message_type; - notification_message_ptr->msg_code = COAP_MSG_CODE_RESPONSE_CONTENT; - - /* Fill token */ - notification_message_ptr->token_len = token_len; - notification_message_ptr->token_ptr = token_ptr; - - /* Fill payload */ - notification_message_ptr->payload_len = payload_len; - notification_message_ptr->payload_ptr = payload_ptr; - - /* Fill uri path */ - notification_message_ptr->uri_path_len = uri_path_len; - notification_message_ptr->uri_path_ptr = uri_path_ptr; - - /* Fill observe */ - notification_message_ptr->options_list_ptr->observe = observe; - - /* Fill content format */ - notification_message_ptr->content_format = content_format; - - /* Send message */ - if (sn_nsdl_send_coap_message(handle, handle->nsp_address_ptr->omalw_address_ptr, notification_message_ptr) == SN_NSDL_FAILURE) { - return_msg_id = 0; - } else { - return_msg_id = notification_message_ptr->msg_id; - } - - /* Free memory */ - notification_message_ptr->uri_path_ptr = NULL; - notification_message_ptr->payload_ptr = NULL; - notification_message_ptr->token_ptr = NULL; - - sn_coap_parser_release_allocated_coap_msg_mem(handle->grs->coap, notification_message_ptr); - - return return_msg_id; -} - - -/* * * * * * * * * * */ -/* ~ OMA functions ~ */ -/* * * * * * * * * * */ - -uint16_t sn_nsdl_oma_bootstrap(struct nsdl_s *handle, sn_nsdl_addr_s *bootstrap_address_ptr, - sn_nsdl_ep_parameters_s *endpoint_info_ptr, - sn_nsdl_bs_ep_info_t *bootstrap_endpoint_info_ptr) -{ -#ifndef MBED_CLIENT_DISABLE_BOOTSTRAP_FEATURE - /* Local variables */ - sn_coap_hdr_s bootstrap_coap_header; - uint8_t *uri_query_tmp_ptr; - uint16_t message_id = 0; - - /* Check parameters */ - if (!bootstrap_address_ptr || !bootstrap_endpoint_info_ptr || !endpoint_info_ptr || !handle) { - return 0; - } - /* Create device object */ - if (handle->handle_bootstrap_msg) { - if (sn_nsdl_create_oma_device_object_base(handle, bootstrap_endpoint_info_ptr->device_object, endpoint_info_ptr->binding_and_mode) < 0) { - return 0; - } - - handle->sn_nsdl_oma_bs_done_cb = bootstrap_endpoint_info_ptr->oma_bs_status_cb; - handle->sn_nsdl_oma_bs_done_cb_handle = bootstrap_endpoint_info_ptr->oma_bs_status_cb_handle; - } - - - /* XXX FIX -- Init CoAP header struct */ - sn_coap_parser_init_message(&bootstrap_coap_header); - - if (!sn_coap_parser_alloc_options(handle->grs->coap, &bootstrap_coap_header)) { - return 0; - } - - /* Build bootstrap start message */ - bootstrap_coap_header.msg_code = COAP_MSG_CODE_REQUEST_POST; - bootstrap_coap_header.msg_type = COAP_MSG_TYPE_CONFIRMABLE; - - bootstrap_coap_header.uri_path_ptr = bs_uri; - bootstrap_coap_header.uri_path_len = sizeof(bs_uri); - - uri_query_tmp_ptr = handle->sn_nsdl_alloc(endpoint_info_ptr->endpoint_name_len + BS_EP_PARAMETER_LEN); - if (!uri_query_tmp_ptr) { - handle->sn_nsdl_free(bootstrap_coap_header.options_list_ptr); - return 0; - } - - memcpy(uri_query_tmp_ptr, bs_ep_name, BS_EP_PARAMETER_LEN); - memcpy((uri_query_tmp_ptr + BS_EP_PARAMETER_LEN), endpoint_info_ptr->endpoint_name_ptr, endpoint_info_ptr->endpoint_name_len); - - bootstrap_coap_header.options_list_ptr->uri_query_len = endpoint_info_ptr->endpoint_name_len + BS_EP_PARAMETER_LEN; - bootstrap_coap_header.options_list_ptr->uri_query_ptr = uri_query_tmp_ptr; - - /* Save bootstrap server address */ - handle->oma_bs_address_len = bootstrap_address_ptr->addr_len; /* Length.. */ - handle->oma_bs_address_ptr = handle->sn_nsdl_alloc(handle->oma_bs_address_len); /* Address.. */ - if (!handle->oma_bs_address_ptr) { - handle->sn_nsdl_free(bootstrap_coap_header.options_list_ptr); - handle->sn_nsdl_free(uri_query_tmp_ptr); - return 0; - } - memcpy(handle->oma_bs_address_ptr, bootstrap_address_ptr->addr_ptr, handle->oma_bs_address_len); - handle->oma_bs_port = bootstrap_address_ptr->port; /* And port */ - - /* Send message */ - message_id = sn_nsdl_internal_coap_send(handle, &bootstrap_coap_header, bootstrap_address_ptr, SN_NSDL_MSG_BOOTSTRAP); - - /* Free allocated memory */ - handle->sn_nsdl_free(uri_query_tmp_ptr); - handle->sn_nsdl_free(bootstrap_coap_header.options_list_ptr); - - return message_id; -#else - return 0; -#endif //MBED_CLIENT_DISABLE_BOOTSTRAP_FEATURE - -} - -omalw_certificate_list_t *sn_nsdl_get_certificates(struct nsdl_s *handle) -{ -#ifndef MBED_CLIENT_DISABLE_BOOTSTRAP_FEATURE - sn_nsdl_resource_info_s *resource_ptr = 0;; - omalw_certificate_list_t *certi_list_ptr = 0; - - /* Check parameters */ - if (handle == NULL) { - return NULL; - } - - certi_list_ptr = handle->sn_nsdl_alloc(sizeof(omalw_certificate_list_t)); - - if (!certi_list_ptr) { - return NULL; - } - - /* Get private key resource */ - resource_ptr = sn_nsdl_get_resource(handle, 5, (void *)"0/0/5"); - if (!resource_ptr) { - handle->sn_nsdl_free(certi_list_ptr); - return NULL; - } - certi_list_ptr->own_private_key_ptr = resource_ptr->resource; - certi_list_ptr->own_private_key_len = resource_ptr->resourcelen; - - /* Get client certificate resource */ - resource_ptr = sn_nsdl_get_resource(handle, 5, (void *)"0/0/4"); - if (!resource_ptr) { - handle->sn_nsdl_free(certi_list_ptr); - return NULL; - } - certi_list_ptr->certificate_ptr[0] = resource_ptr->resource; - certi_list_ptr->certificate_len[0] = resource_ptr->resourcelen; - - /* Get root certificate resource */ - resource_ptr = sn_nsdl_get_resource(handle, 5, (void *)"0/0/3"); - if (!resource_ptr) { - handle->sn_nsdl_free(certi_list_ptr); - return NULL; - } - certi_list_ptr->certificate_ptr[1] = resource_ptr->resource; - certi_list_ptr->certificate_len[1] = resource_ptr->resourcelen; - - /* return filled list */ - return certi_list_ptr; -#else - return NULL; -#endif //MBED_CLIENT_DISABLE_BOOTSTRAP_FEATURE -} - -int8_t sn_nsdl_update_certificates(struct nsdl_s *handle, omalw_certificate_list_t *certificate_ptr, uint8_t certificate_chain) -{ -#ifndef MBED_CLIENT_DISABLE_BOOTSTRAP_FEATURE - (void)certificate_chain; - - /* Check pointers */ - if (!certificate_ptr || !handle) { - return SN_NSDL_FAILURE; - } - - sn_nsdl_resource_info_s *resource_ptr = 0;; - - /* Get private key resource */ - resource_ptr = sn_nsdl_get_resource(handle, 5, (void *)"0/0/5"); - if (!resource_ptr) { - return SN_NSDL_FAILURE; - } - handle->sn_nsdl_free(resource_ptr->resource); - resource_ptr->resource = certificate_ptr->own_private_key_ptr; - resource_ptr->resourcelen = certificate_ptr->own_private_key_len; - - /* Get client certificate resource */ - resource_ptr = sn_nsdl_get_resource(handle, 5, (void *)"0/0/4"); - if (!resource_ptr) { - return SN_NSDL_FAILURE; - } - handle->sn_nsdl_free(resource_ptr->resource); - resource_ptr->resource = certificate_ptr->certificate_ptr[0]; - resource_ptr->resourcelen = certificate_ptr->certificate_len[0]; - - /* Get root certificate resource */ - resource_ptr = sn_nsdl_get_resource(handle, 5, (void *)"0/0/3"); - if (!resource_ptr) { - return SN_NSDL_FAILURE; - } - handle->sn_nsdl_free(resource_ptr->resource); - resource_ptr->resource = certificate_ptr->certificate_ptr[1]; - resource_ptr->resourcelen = certificate_ptr->certificate_len[1]; - - return SN_NSDL_SUCCESS; -#else - return SN_NSDL_FAILURE; -#endif //MBED_CLIENT_DISABLE_BOOTSTRAP_FEATURE -} - -int8_t sn_nsdl_create_oma_device_object(struct nsdl_s *handle, sn_nsdl_oma_device_t *device_object_ptr) -{ -#ifndef MBED_CLIENT_DISABLE_BOOTSTRAP_FEATURE - sn_nsdl_resource_info_s *resource_temp = 0; - uint8_t path[8] = "3/0/11/0"; - - if (!device_object_ptr || !handle) { - return SN_NSDL_FAILURE; - } - - /* * Error code * */ - - /* Get first error message */ - resource_temp = sn_grs_search_resource(handle->grs, 8, path, SN_GRS_SEARCH_METHOD); - - while (resource_temp) { - if (resource_temp->resource) { - /* If no error code set */ - if (*resource_temp->resource == 0) { - /* Set error code */ - *resource_temp->resource = (uint8_t)device_object_ptr->error_code; - resource_temp->resourcelen = 1; - - sn_nsdl_update_resource(handle, resource_temp); - return SN_NSDL_SUCCESS; - } - break; - } - - if (path[7] == '9') { - return SN_NSDL_FAILURE; - } - - path[7]++; - resource_temp = sn_grs_search_resource(handle->grs, 8, path, SN_GRS_SEARCH_METHOD); - } - - /* Create new resource for this error */ - resource_temp = handle->sn_nsdl_alloc(sizeof(sn_nsdl_resource_info_s)); - if (!resource_temp) { - return SN_NSDL_FAILURE; - } - - memset(resource_temp, 0, sizeof(sn_nsdl_resource_info_s)); - - resource_temp->access = SN_GRS_GET_ALLOWED; - resource_temp->mode = SN_GRS_DYNAMIC; - - resource_temp->path = path; - resource_temp->pathlen = 8; - - resource_temp->resource = handle->sn_nsdl_alloc(1); - if (!resource_temp->resource) { - handle->sn_nsdl_free(resource_temp); - return SN_NSDL_FAILURE; - } - - *resource_temp->resource = (uint8_t)device_object_ptr->error_code; - resource_temp->resourcelen = 1; - - resource_temp->resource_parameters_ptr = handle->sn_nsdl_alloc(sizeof(sn_nsdl_resource_parameters_s)); - - if (!resource_temp->resource_parameters_ptr) { - handle->sn_nsdl_free(resource_temp->resource); - handle->sn_nsdl_free(resource_temp); - - return SN_NSDL_FAILURE; - } - - memset(resource_temp->resource_parameters_ptr, 0, sizeof(sn_nsdl_resource_parameters_s)); - - sn_nsdl_create_resource(handle, resource_temp); - - handle->sn_nsdl_free(resource_temp->resource); - handle->sn_nsdl_free(resource_temp->resource_parameters_ptr); - handle->sn_nsdl_free(resource_temp); - - return SN_NSDL_SUCCESS; -#else - return SN_NSDL_FAILURE; -#endif //MBED_CLIENT_DISABLE_BOOTSTRAP_FEATURE -} - -char *sn_nsdl_get_version(void) -{ -#if defined(YOTTA_MBED_CLIENT_C_VERSION_STRING) - return YOTTA_MBED_CLIENT_C_VERSION_STRING; -#elif defined(VERSION) - return VERSION; -#else - return "0.0.0"; -#endif -} - - -int8_t sn_nsdl_process_coap(struct nsdl_s *handle, uint8_t *packet_ptr, uint16_t packet_len, sn_nsdl_addr_s *src_ptr) -{ - sn_coap_hdr_s *coap_packet_ptr = NULL; - sn_coap_hdr_s *coap_response_ptr = NULL; - sn_nsdl_resource_info_s *resource = NULL; - /* Check parameters */ - if (handle == NULL) { - return SN_NSDL_FAILURE; - } - - /* Parse CoAP packet */ - coap_packet_ptr = sn_coap_protocol_parse(handle->grs->coap, src_ptr, packet_len, packet_ptr, (void *)handle); - - /* Check if parsing was successfull */ - if (coap_packet_ptr == (sn_coap_hdr_s *)NULL) { - return SN_NSDL_FAILURE; - } -#if SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE - // Pass block to application if external_memory_block is set - if(coap_packet_ptr->coap_status == COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVING) { - resource = sn_nsdl_get_resource(handle, coap_packet_ptr->uri_path_len, coap_packet_ptr->uri_path_ptr); - if(resource && resource->external_memory_block) { - sn_coap_protocol_block_remove(handle->grs->coap, - src_ptr, - coap_packet_ptr->payload_len, - coap_packet_ptr->payload_ptr); - } else { - resource = NULL; - } - } -#endif - /* Check, if coap itself sends response, or block receiving is ongoing... */ - if (coap_packet_ptr->coap_status != COAP_STATUS_OK && - coap_packet_ptr->coap_status != COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED &&coap_packet_ptr && - !resource) { - sn_coap_parser_release_allocated_coap_msg_mem(handle->grs->coap, coap_packet_ptr); - return SN_NSDL_SUCCESS; - } - - /* If proxy options added, return not supported */ - if (coap_packet_ptr->options_list_ptr) { - if (coap_packet_ptr->options_list_ptr->proxy_uri_len) { - coap_response_ptr = sn_coap_build_response(handle->grs->coap, coap_packet_ptr, COAP_MSG_CODE_RESPONSE_PROXYING_NOT_SUPPORTED); - if (coap_response_ptr) { - sn_nsdl_send_coap_message(handle, src_ptr, coap_response_ptr); - sn_coap_parser_release_allocated_coap_msg_mem(handle->grs->coap, coap_response_ptr); - sn_coap_parser_release_allocated_coap_msg_mem(handle->grs->coap, coap_packet_ptr); - return SN_NSDL_SUCCESS; - } else { - sn_coap_parser_release_allocated_coap_msg_mem(handle->grs->coap, coap_packet_ptr); - return SN_NSDL_FAILURE; - } - } - } - - /* * * * * * * * * * * * * * * * * * * * * * * * * * */ - /* If message is response message, call RX callback */ - /* * * * * * * * * * * * * * * * * * * * * * * * * * */ - - if ((coap_packet_ptr->msg_code > COAP_MSG_CODE_REQUEST_DELETE) || (coap_packet_ptr->msg_type == COAP_MSG_TYPE_ACKNOWLEDGEMENT)) { - int8_t retval = sn_nsdl_local_rx_function(handle, coap_packet_ptr, src_ptr); - if (coap_packet_ptr->coap_status == COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED && coap_packet_ptr->payload_ptr) { - handle->sn_nsdl_free(coap_packet_ptr->payload_ptr); - coap_packet_ptr->payload_ptr = 0; - } - sn_coap_parser_release_allocated_coap_msg_mem(handle->grs->coap, coap_packet_ptr); - return retval; - } -#ifndef MBED_CLIENT_DISABLE_BOOTSTRAP_FEATURE - /* * If OMA bootstrap message... * */ - bool bootstrap_msg = src_ptr && (handle->oma_bs_address_len == src_ptr->addr_len) && - (handle->oma_bs_port == src_ptr->port) && - !memcmp(handle->oma_bs_address_ptr, src_ptr->addr_ptr, handle->oma_bs_address_len); - // Pass bootstrap data to application - if (bootstrap_msg && !handle->handle_bootstrap_msg) { - handle->sn_nsdl_rx_callback(handle, coap_packet_ptr,src_ptr); - sn_coap_parser_release_allocated_coap_msg_mem(handle->grs->coap, coap_packet_ptr); - return SN_NSDL_SUCCESS; - } - // Internal handling - else if (bootstrap_msg) { - /* TLV message. Parse message and check status of the OMA bootstrap */ - /* process. If ok, call cb function and return. Otherwise send error */ - /* and return failure. */ - - if (coap_packet_ptr->content_format == 99) { //todo check message type - /* TLV parsing failed. Send response to get non-tlv messages */ - if (sn_nsdl_process_oma_tlv(handle, coap_packet_ptr->payload_ptr, coap_packet_ptr->payload_len) == SN_NSDL_FAILURE) { - coap_response_ptr = sn_coap_build_response(handle->grs->coap, coap_packet_ptr, COAP_MSG_CODE_RESPONSE_NOT_ACCEPTABLE); - if (coap_response_ptr) { - sn_nsdl_send_coap_message(handle, src_ptr, coap_response_ptr); - sn_coap_parser_release_allocated_coap_msg_mem(handle->grs->coap, coap_response_ptr); - } else { - sn_coap_parser_release_allocated_coap_msg_mem(handle->grs->coap, coap_packet_ptr); - return SN_NSDL_FAILURE; - } - } - /* Success TLV parsing */ - else { - coap_response_ptr = sn_coap_build_response(handle->grs->coap, coap_packet_ptr, COAP_MSG_CODE_RESPONSE_CREATED); - if (coap_response_ptr) { - sn_nsdl_send_coap_message(handle, src_ptr, coap_response_ptr); - sn_coap_parser_release_allocated_coap_msg_mem(handle->grs->coap, coap_response_ptr); - - } else { - sn_coap_parser_release_allocated_coap_msg_mem(handle->grs->coap, coap_packet_ptr); - return SN_NSDL_FAILURE; - } - sn_nsdl_check_oma_bs_status(handle); - } - - sn_coap_parser_release_allocated_coap_msg_mem(handle->grs->coap, coap_packet_ptr); - return SN_NSDL_SUCCESS; - } - - /* Non - TLV message */ - else if (coap_packet_ptr->content_format == 97) { - sn_grs_process_coap(handle, coap_packet_ptr, src_ptr); - - /* Todo: move this copying to sn_nsdl_check_oma_bs_status(), also from TLV parser */ - /* Security mode */ - if (*(coap_packet_ptr->uri_path_ptr + (coap_packet_ptr->uri_path_len - 1)) == '2') { - handle->nsp_address_ptr->omalw_server_security = (omalw_server_security_t)sn_nsdl_atoi(coap_packet_ptr->payload_ptr, coap_packet_ptr->payload_len); - sn_coap_parser_release_allocated_coap_msg_mem(handle->grs->coap, coap_packet_ptr); - } - - /* NSP address */ - else if (*(coap_packet_ptr->uri_path_ptr + (coap_packet_ptr->uri_path_len - 1)) == '0') { - sn_nsdl_resolve_lwm2m_address(handle, coap_packet_ptr->payload_ptr, coap_packet_ptr->payload_len); - sn_coap_parser_release_allocated_coap_msg_mem(handle->grs->coap, coap_packet_ptr); - } - - sn_nsdl_check_oma_bs_status(handle); - } else { - sn_coap_parser_release_allocated_coap_msg_mem(handle->grs->coap, coap_packet_ptr); - return SN_NSDL_FAILURE; - } - - - return SN_NSDL_SUCCESS; - } -#endif //MBED_CLIENT_DISABLE_BOOTSTRAP_FEATURE - - /* * * * * * * * * * * * * * * */ - /* Other messages are for GRS */ - /* * * * * * * * * * * * * * * */ - - return sn_grs_process_coap(handle, coap_packet_ptr, src_ptr); -} - -int8_t sn_nsdl_exec(struct nsdl_s *handle, uint32_t time) -{ - if(!handle || !handle->grs){ - return SN_NSDL_FAILURE; - } - /* Call CoAP execution function */ - return sn_coap_protocol_exec(handle->grs->coap, time); -} - -sn_nsdl_resource_info_s *sn_nsdl_get_resource(struct nsdl_s *handle, uint16_t pathlen, uint8_t *path_ptr) -{ - /* Check parameters */ - if (handle == NULL) { - return NULL; - } - - return sn_grs_search_resource(handle->grs, pathlen, path_ptr, SN_GRS_SEARCH_METHOD); -} - - -/** - * \fn static uint16_t sn_nsdl_internal_coap_send(struct nsdl_s *handle, sn_coap_hdr_s *coap_header_ptr, sn_nsdl_addr_s *dst_addr_ptr, uint8_t message_description) - * - * - * \brief To send NSDL messages. Stores message id?s and message description to catch response from NSP server - * \param *handle Pointer to nsdl-library handle - * \param *coap_header_ptr Pointer to the CoAP message header to be sent - * \param *dst_addr_ptr Pointer to the address structure that contains destination address information - * \param message_description Message description to be stored to list for waiting response - * - * \return message id, 0 if failed - */ -static uint16_t sn_nsdl_internal_coap_send(struct nsdl_s *handle, sn_coap_hdr_s *coap_header_ptr, sn_nsdl_addr_s *dst_addr_ptr, uint8_t message_description) -{ - - tr_debug("sn_nsdl_internal_coap_send"); - uint8_t *coap_message_ptr = NULL; - int32_t coap_message_len = 0; - uint16_t coap_header_len = 0; - -#if SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE /* If Message blockwising is not used at all, this part of code will not be compiled */ - int8_t ret_val = prepare_blockwise_message(handle->grs->coap, coap_header_ptr); - if( 0 != ret_val ) { - return 0; - } -#endif - - coap_message_len = sn_coap_builder_calc_needed_packet_data_size_2(coap_header_ptr, handle->grs->coap->sn_coap_block_data_size); - tr_debug("sn_nsdl_internal_coap_send - msg len after calc: [%d]", coap_message_len); - if (coap_message_len == 0) { - return 0; - } - - coap_message_ptr = handle->sn_nsdl_alloc(coap_message_len); - if (!coap_message_ptr) { - return 0; - } - - coap_header_len = coap_header_ptr->payload_len; - /* Build message */ - if (sn_coap_protocol_build(handle->grs->coap, dst_addr_ptr, coap_message_ptr, coap_header_ptr, (void *)handle) < 0) { - handle->sn_nsdl_free(coap_message_ptr); - return 0; - } - - /* If mesage type is confirmable, save it to list to wait for reply */ - if (coap_header_ptr->msg_type == COAP_MSG_TYPE_CONFIRMABLE) { - if (message_description == SN_NSDL_MSG_REGISTER) { - handle->register_msg_id = coap_header_ptr->msg_id; - handle->register_msg_len = coap_header_len; - } - else if (message_description == SN_NSDL_MSG_UNREGISTER) { - handle->unregister_msg_id = coap_header_ptr->msg_id; - } - else if (message_description == SN_NSDL_MSG_UPDATE) { - handle->update_register_msg_id = coap_header_ptr->msg_id; - handle->update_register_msg_len = coap_header_len; - } - else if (message_description == SN_NSDL_MSG_BOOTSTRAP) { - handle->bootstrap_msg_id = coap_header_ptr->msg_id; - } - } - - handle->sn_nsdl_tx_callback(handle, SN_NSDL_PROTOCOL_COAP, coap_message_ptr, coap_message_len, dst_addr_ptr); - handle->sn_nsdl_free(coap_message_ptr); - - return coap_header_ptr->msg_id; -} - -/** - * \fn static void sn_nsdl_resolve_nsp_address(struct nsdl_s *handle) - * - * \brief Resolves NSP server address. - * - * \param *handle Pointer to nsdl-library handle - * \note Application must set NSP address with set_nsp_address - */ -static void sn_nsdl_resolve_nsp_address(struct nsdl_s *handle) -{ - /* Local variables */ - if (!handle->nsp_address_ptr) { - //allocate only if previously not allocated - handle->nsp_address_ptr = handle->sn_nsdl_alloc(sizeof(sn_nsdl_oma_server_info_t)); - } - - if (handle->nsp_address_ptr) { - handle->nsp_address_ptr->omalw_server_security = SEC_NOT_SET; - handle->nsp_address_ptr->omalw_address_ptr = handle->sn_nsdl_alloc(sizeof(sn_nsdl_addr_s)); - if (handle->nsp_address_ptr->omalw_address_ptr) { - memset(handle->nsp_address_ptr->omalw_address_ptr, 0, sizeof(sn_nsdl_addr_s)); - handle->nsp_address_ptr->omalw_address_ptr->type = SN_NSDL_ADDRESS_TYPE_NONE; - } - } -} - -static int8_t sn_nsdl_create_oma_device_object_base(struct nsdl_s *handle, sn_nsdl_oma_device_t *oma_device_setup_ptr, sn_nsdl_oma_binding_and_mode_t binding_and_mode) -{ -#ifndef MBED_CLIENT_DISABLE_BOOTSTRAP_FEATURE - sn_nsdl_resource_info_s new_resource; - uint8_t object_path[8] = "3/0/11/0"; - uint8_t resource_temp[3]; - uint8_t x = 0; - - if (!oma_device_setup_ptr) { - return SN_NSDL_FAILURE; - } - - /* * Create resources. * */ - - /* These resources can be created multiple times. */ - memset(&new_resource, 0, sizeof(sn_nsdl_resource_info_s)); - new_resource.resource_parameters_ptr = handle->sn_nsdl_alloc(sizeof(sn_nsdl_resource_parameters_s)); - if (!new_resource.resource_parameters_ptr) { - return SN_NSDL_FAILURE; - } - - memset(new_resource.resource_parameters_ptr, 0, sizeof(sn_nsdl_resource_parameters_s)); - - /* Create error - resource */ - new_resource.mode = SN_GRS_STATIC; - new_resource.access = SN_GRS_GET_ALLOWED; - - new_resource.path = object_path; - new_resource.pathlen = 8; - - sn_nsdl_itoa(resource_temp, (uint8_t)oma_device_setup_ptr->error_code); - - new_resource.resource = resource_temp; - new_resource.resourcelen = 1; - - if (sn_nsdl_create_resource(handle, &new_resource) != SN_NSDL_SUCCESS) { - handle->sn_nsdl_free(new_resource.resource_parameters_ptr); - return SN_NSDL_FAILURE; - } - - /* These resources can be only once, during OMA bootstrap.. */ - /* Create supported binding and modes */ - object_path[5] = '6'; - new_resource.path = object_path; - new_resource.pathlen = 6; - - if (binding_and_mode & 0x01) { - resource_temp[x] = 'U'; - x++; - if (binding_and_mode & 0x02) { - resource_temp[x] = 'Q'; - x++; - } - } - if (binding_and_mode & 0x04) { - resource_temp[x] = 'S'; - x++; - if ((binding_and_mode & 0x02) && !(binding_and_mode & 0x01)) { - resource_temp[x] = 'Q'; - x++; - } - } - - new_resource.resourcelen = x; - - if (new_resource.resourcelen) { - new_resource.resource = resource_temp; - } else { - new_resource.resource = 0; - } - - - if (sn_nsdl_create_resource(handle, &new_resource) != SN_NSDL_SUCCESS) { - handle->sn_nsdl_free(new_resource.resource_parameters_ptr); - return SN_NSDL_FAILURE; - } - - - /* Create dynamic reboot object */ - new_resource.mode = SN_GRS_DYNAMIC; - - new_resource.access = SN_GRS_POST_ALLOWED; - - object_path[4] = '4'; - - new_resource.path = object_path; - new_resource.pathlen = 5; - - new_resource.resourcelen = 0; - new_resource.resource = 0; - - new_resource.sn_grs_dyn_res_callback = oma_device_setup_ptr->sn_oma_device_boot_callback; - - if (sn_nsdl_create_resource(handle, &new_resource) != SN_NSDL_SUCCESS) { - handle->sn_nsdl_free(new_resource.resource_parameters_ptr); - return SN_NSDL_FAILURE; - } - - handle->sn_nsdl_free(new_resource.resource_parameters_ptr); - return SN_NSDL_SUCCESS; -#else - return SN_NSDL_FAILURE; -#endif //MBED_CLIENT_DISABLE_BOOTSTRAP_FEATURE -} - -/** - * \fn int8_t sn_nsdl_build_registration_body(struct nsdl_s *handle, sn_coap_hdr_s *message_ptr, uint8_t updating_registeration) - * - * \brief To build GRS resources to registration message payload - * \param *handle Pointer to nsdl-library handle - * \param *message_ptr Pointer to CoAP message header - * - * \return SN_NSDL_SUCCESS = 0, Failed = -1 - */ -int8_t sn_nsdl_build_registration_body(struct nsdl_s *handle, sn_coap_hdr_s *message_ptr, uint8_t updating_registeration) -{ - tr_debug("sn_nsdl_build_registration_body"); - /* Local variables */ - uint8_t *temp_ptr; - const sn_nsdl_resource_info_s *resource_temp_ptr; - - /* Calculate needed memory and allocate */ - int8_t error = 0; - uint16_t msg_len = sn_nsdl_calculate_registration_body_size(handle, updating_registeration, &error); - if (SN_NSDL_FAILURE == error) { - return error; - } - - if (!msg_len) { - return SN_NSDL_SUCCESS; - } else { - message_ptr->payload_len = msg_len; - } - tr_debug("sn_nsdl_build_registration_body - body size: [%d]", message_ptr->payload_len); - message_ptr->payload_ptr = handle->sn_nsdl_alloc(message_ptr->payload_len); - if (!message_ptr->payload_ptr) { - return SN_NSDL_FAILURE; - } - - /* Build message */ - temp_ptr = message_ptr->payload_ptr; - - resource_temp_ptr = sn_grs_get_first_resource(handle->grs); - - /* Loop trough all resources */ - while (resource_temp_ptr) { - /* if resource needs to be registered */ - if (resource_temp_ptr->resource_parameters_ptr && resource_temp_ptr->publish_uri) { - if (updating_registeration && resource_temp_ptr->resource_parameters_ptr->registered == SN_NDSL_RESOURCE_REGISTERED) { - resource_temp_ptr = sn_grs_get_next_resource(handle->grs, resource_temp_ptr); - continue; - } else { - resource_temp_ptr->resource_parameters_ptr->registered = SN_NDSL_RESOURCE_REGISTERED; - } - - /* If not first resource, add '.' to separator */ - if (temp_ptr != message_ptr->payload_ptr) { - *temp_ptr++ = ','; - } - - *temp_ptr++ = '<'; - *temp_ptr++ = '/'; - memcpy(temp_ptr, resource_temp_ptr->path, resource_temp_ptr->pathlen); - temp_ptr += resource_temp_ptr->pathlen; - *temp_ptr++ = '>'; - - /* Resource attributes */ - if (resource_temp_ptr->resource_parameters_ptr->resource_type_len) { - *temp_ptr++ = ';'; - memcpy(temp_ptr, resource_type_parameter, RT_PARAMETER_LEN); - temp_ptr += RT_PARAMETER_LEN; - *temp_ptr++ = '"'; - memcpy(temp_ptr, resource_temp_ptr->resource_parameters_ptr->resource_type_ptr, resource_temp_ptr->resource_parameters_ptr->resource_type_len); - temp_ptr += resource_temp_ptr->resource_parameters_ptr->resource_type_len; - *temp_ptr++ = '"'; - } - - if (resource_temp_ptr->resource_parameters_ptr->interface_description_len) { - *temp_ptr++ = ';'; - memcpy(temp_ptr, if_description_parameter, IF_PARAMETER_LEN); - temp_ptr += IF_PARAMETER_LEN; - *temp_ptr++ = '"'; - memcpy(temp_ptr, resource_temp_ptr->resource_parameters_ptr->interface_description_ptr, resource_temp_ptr->resource_parameters_ptr->interface_description_len); - temp_ptr += resource_temp_ptr->resource_parameters_ptr->interface_description_len; - *temp_ptr++ = '"'; - } - - if (resource_temp_ptr->resource_parameters_ptr->coap_content_type != 0) { - *temp_ptr++ = ';'; - memcpy(temp_ptr, coap_con_type_parameter, COAP_CON_PARAMETER_LEN); - temp_ptr += COAP_CON_PARAMETER_LEN; - *temp_ptr++ = '"'; - temp_ptr = sn_nsdl_itoa(temp_ptr, resource_temp_ptr->resource_parameters_ptr->coap_content_type); - *temp_ptr++ = '"'; - } - - /* ;obs */ - // This needs to be re-visited and may be need an API for maganging obs value for different server implementation -#ifndef COAP_DISABLE_OBS_FEATURE - if (resource_temp_ptr->resource_parameters_ptr->observable) { - *temp_ptr++ = ';'; - memcpy(temp_ptr, obs_parameter, OBS_PARAMETER_LEN); - temp_ptr += OBS_PARAMETER_LEN; - } -#endif - /* ;aobs;id= */ - /* todo: aosb not supported ATM */ - /* - if((resource_temp_ptr->resource_parameters_ptr->auto_obs_len > 0 && resource_temp_ptr->resource_parameters_ptr->auto_obs_len <= 8) && - resource_temp_ptr->resource_parameters_ptr->auto_obs_ptr) - { - uint8_t i = 0; - - *temp_ptr++ = ';'; - memcpy(temp_ptr, aobs_parameter, AOBS_PARAMETER_LEN); - temp_ptr += AOBS_PARAMETER_LEN; - - while(i < resource_temp_ptr->resource_parameters_ptr->auto_obs_len) - { - temp_ptr = sn_nsdl_itoa(temp_ptr, *(resource_temp_ptr->resource_parameters_ptr->auto_obs_ptr + i)); - i++; - } - } - */ - - } - - resource_temp_ptr = sn_grs_get_next_resource(handle->grs, resource_temp_ptr); - } - - return SN_NSDL_SUCCESS; -} - -/** - * \fn static uint16_t sn_nsdl_calculate_registration_body_size(struct nsdl_s *handle, uint8_t updating_registeration, int8_t *error) - * - * - * \brief Calculates registration message payload size - * \param *handle Pointer to nsdl-library handle - * \param *updating_registeration Pointer to list of GRS resources - * \param *error Error code, SN_NSDL_SUCCESS or SN_NSDL_FAILURE - * - * \return Needed payload size - */ -static uint16_t sn_nsdl_calculate_registration_body_size(struct nsdl_s *handle, uint8_t updating_registeration, int8_t *error) -{ - tr_debug("sn_nsdl_calculate_registration_body_size"); - /* Local variables */ - uint16_t return_value = 0; - *error = SN_NSDL_SUCCESS; - const sn_nsdl_resource_info_s *resource_temp_ptr; - - /* check pointer */ - resource_temp_ptr = sn_grs_get_first_resource(handle->grs); - - while (resource_temp_ptr) { - if (resource_temp_ptr->resource_parameters_ptr && resource_temp_ptr->publish_uri) { - if (updating_registeration && resource_temp_ptr->resource_parameters_ptr->registered == SN_NDSL_RESOURCE_REGISTERED) { - resource_temp_ptr = sn_grs_get_next_resource(handle->grs, resource_temp_ptr); - continue; - } - - /* If not first resource, then '.' will be added */ - if (return_value) { - if (sn_nsdl_check_uint_overflow(return_value, 1, 0)) { - return_value++; - } else { - *error = SN_NSDL_FAILURE; - break; - } - } - - /* Count length for the resource path */ - if (sn_nsdl_check_uint_overflow(return_value, 3,resource_temp_ptr->pathlen)) { - return_value += (3 + resource_temp_ptr->pathlen); - } else { - *error = SN_NSDL_FAILURE; - break; - } - - /* Count lengths of the attributes */ - - /* Resource type parameter */ - if (resource_temp_ptr->resource_parameters_ptr->resource_type_len) { - /* ;rt="restype" */ - if (sn_nsdl_check_uint_overflow(return_value, 6, resource_temp_ptr->resource_parameters_ptr->resource_type_len)) { - return_value += (6 + resource_temp_ptr->resource_parameters_ptr->resource_type_len); - } else { - *error = SN_NSDL_FAILURE; - break; - } - } - - /* Interface description parameter */ - if (resource_temp_ptr->resource_parameters_ptr->interface_description_len) { - /* ;if="iftype" */ - if (sn_nsdl_check_uint_overflow(return_value, 6, resource_temp_ptr->resource_parameters_ptr->interface_description_len)) { - return_value += (6 + resource_temp_ptr->resource_parameters_ptr->interface_description_len); - } else { - *error = SN_NSDL_FAILURE; - break; - } - } - - if (resource_temp_ptr->resource_parameters_ptr->coap_content_type != 0) { - /* ;if="content" */ - uint8_t len = sn_nsdl_itoa_len(resource_temp_ptr->resource_parameters_ptr->coap_content_type); - if (sn_nsdl_check_uint_overflow(return_value, 6, len)) { - return_value += (6 + len); - } else { - *error = SN_NSDL_FAILURE; - break; - } - } -#ifndef COAP_DISABLE_OBS_FEATURE - // This needs to be re-visited and may be need an API for maganging obs value for different server implementation - if (resource_temp_ptr->resource_parameters_ptr->observable) { - if (sn_nsdl_check_uint_overflow(return_value, 4, 0)) { - return_value += 4; - } else { - *error = SN_NSDL_FAILURE; - break; - } - } -#endif - } - resource_temp_ptr = sn_grs_get_next_resource(handle->grs, resource_temp_ptr); - } - return return_value; -} - -/** - * \fn static uint8_t sn_nsdl_calculate_uri_query_option_len(sn_nsdl_ep_parameters_s *endpoint_info_ptr, uint8_t msg_type) - * - * - * \brief Calculates needed uri query option length - * - * \param *endpoint_info_ptr Pointer to endpoint info structure - * \param msg_type Message type - * - * \return number of parameters in uri query - */ -static uint8_t sn_nsdl_calculate_uri_query_option_len(sn_nsdl_ep_parameters_s *endpoint_info_ptr, uint8_t msg_type) -{ - uint8_t return_value = 0; - uint8_t number_of_parameters = 0; - - - if ((endpoint_info_ptr->endpoint_name_len != 0) && (msg_type == SN_NSDL_EP_REGISTER_MESSAGE) && endpoint_info_ptr->endpoint_name_ptr != 0) { - return_value += endpoint_info_ptr->endpoint_name_len; - return_value += EP_NAME_PARAMETERS_LEN; //ep= - number_of_parameters++; - } - - if ((endpoint_info_ptr->type_len != 0) && (msg_type == SN_NSDL_EP_REGISTER_MESSAGE) && (endpoint_info_ptr->type_ptr != 0)) { - return_value += endpoint_info_ptr->type_len; - return_value += ET_PARAMETER_LEN; //et= - number_of_parameters++; - } - - if ((endpoint_info_ptr->lifetime_len != 0) && (endpoint_info_ptr->lifetime_ptr != 0)) { - return_value += endpoint_info_ptr->lifetime_len; - return_value += LT_PARAMETER_LEN; //lt= - number_of_parameters++; - } - - if ((endpoint_info_ptr->domain_name_len != 0) && (msg_type == SN_NSDL_EP_REGISTER_MESSAGE) && (endpoint_info_ptr->domain_name_ptr != 0)) { - return_value += endpoint_info_ptr->domain_name_len; - return_value += DOMAIN_PARAMETER_LEN; //d= - number_of_parameters++; - } - - if (((endpoint_info_ptr->binding_and_mode & 0x04) || (endpoint_info_ptr->binding_and_mode & 0x01)) && (msg_type == SN_NSDL_EP_REGISTER_MESSAGE)) { - return_value += BS_QUEUE_MODE_PARAMATER_LEN; - - if (endpoint_info_ptr->binding_and_mode & 0x01) { - return_value++; - } - if (endpoint_info_ptr->binding_and_mode & 0x04) { - return_value++; - } - if ((endpoint_info_ptr->binding_and_mode & 0x02) && ((endpoint_info_ptr->binding_and_mode & 0x04) || (endpoint_info_ptr->binding_and_mode & 0x01))) { - return_value++; - } - - number_of_parameters++; - } - - if (number_of_parameters != 0) { - return_value += (number_of_parameters - 1); - } - - return return_value; -} - -/** - * \fn static int8_t sn_nsdl_fill_uri_query_options(struct nsdl_s *handle, sn_nsdl_ep_parameters_s *parameter_ptr, sn_coap_hdr_s *source_msg_ptr, uint8_t msg_type) - * - * - * \brief Fills uri-query options to message header struct - * \param *handle Pointer to nsdl-library handle - * \param *parameter_ptr Pointer to endpoint parameters struct - * \param *source_msg_ptr Pointer to CoAP header struct - * \param msg_type Message type - * - * \return SN_NSDL_SUCCESS = 0, Failed = -1 - */ -static int8_t sn_nsdl_fill_uri_query_options(struct nsdl_s *handle, sn_nsdl_ep_parameters_s *parameter_ptr, sn_coap_hdr_s *source_msg_ptr, uint8_t msg_type) -{ - uint8_t *temp_ptr = NULL; - if( !validateParameters(parameter_ptr) ){ - return SN_NSDL_FAILURE; - } - source_msg_ptr->options_list_ptr->uri_query_len = sn_nsdl_calculate_uri_query_option_len(parameter_ptr, msg_type); - if (source_msg_ptr->options_list_ptr->uri_query_len == 0) { - return 0; - } - - source_msg_ptr->options_list_ptr->uri_query_ptr = handle->sn_nsdl_alloc(source_msg_ptr->options_list_ptr->uri_query_len); - - if (source_msg_ptr->options_list_ptr->uri_query_ptr == NULL) { - return SN_NSDL_FAILURE; - } - memset(source_msg_ptr->options_list_ptr->uri_query_ptr,0,source_msg_ptr->options_list_ptr->uri_query_len); - - temp_ptr = source_msg_ptr->options_list_ptr->uri_query_ptr; - - /******************************************************/ - /* If endpoint name is configured, fill needed fields */ - /******************************************************/ - - if ((parameter_ptr->endpoint_name_len != 0) && (parameter_ptr->endpoint_name_ptr != 0) && (msg_type == SN_NSDL_EP_REGISTER_MESSAGE)) { - /* fill endpoint name, first ?ep=, then endpoint name */ - memcpy(temp_ptr, ep_name_parameter_string, sizeof(ep_name_parameter_string)); - temp_ptr += EP_NAME_PARAMETERS_LEN; - memcpy(temp_ptr, parameter_ptr->endpoint_name_ptr, parameter_ptr->endpoint_name_len); - temp_ptr += parameter_ptr->endpoint_name_len; - } - - /******************************************************/ - /* If endpoint type is configured, fill needed fields */ - /******************************************************/ - - if ((parameter_ptr->type_len != 0) && (parameter_ptr->type_ptr != 0) && (msg_type == SN_NSDL_EP_REGISTER_MESSAGE)) { - if (temp_ptr != source_msg_ptr->options_list_ptr->uri_query_ptr) { - *temp_ptr++ = '&'; - } - - memcpy(temp_ptr, et_parameter, sizeof(et_parameter)); - temp_ptr += ET_PARAMETER_LEN; - memcpy(temp_ptr, parameter_ptr->type_ptr, parameter_ptr->type_len); - temp_ptr += parameter_ptr->type_len; - } - - - /******************************************************/ - /* If lifetime is configured, fill needed fields */ - /******************************************************/ - - if ((parameter_ptr->lifetime_len != 0) && (parameter_ptr->lifetime_ptr != 0)) { - if (temp_ptr != source_msg_ptr->options_list_ptr->uri_query_ptr) { - *temp_ptr++ = '&'; - } - - memcpy(temp_ptr, ep_lifetime_parameter, sizeof(ep_lifetime_parameter)); - temp_ptr += LT_PARAMETER_LEN; - memcpy(temp_ptr, parameter_ptr->lifetime_ptr, parameter_ptr->lifetime_len); - temp_ptr += parameter_ptr->lifetime_len; - } - - /******************************************************/ - /* If domain is configured, fill needed fields */ - /******************************************************/ - - if ((parameter_ptr->domain_name_len != 0) && (parameter_ptr->domain_name_ptr != 0) && (msg_type == SN_NSDL_EP_REGISTER_MESSAGE)) { - if (temp_ptr != source_msg_ptr->options_list_ptr->uri_query_ptr) { - *temp_ptr++ = '&'; - } - - memcpy(temp_ptr, ep_domain_parameter, sizeof(ep_domain_parameter)); - temp_ptr += DOMAIN_PARAMETER_LEN; - memcpy(temp_ptr, parameter_ptr->domain_name_ptr, parameter_ptr->domain_name_len); - temp_ptr += parameter_ptr->domain_name_len; - } - - /******************************************************/ - /* If queue-mode is configured, fill needed fields */ - /******************************************************/ - - if (((parameter_ptr->binding_and_mode & 0x01) || (parameter_ptr->binding_and_mode & 0x04)) && (msg_type == SN_NSDL_EP_REGISTER_MESSAGE)) { - if (temp_ptr != source_msg_ptr->options_list_ptr->uri_query_ptr) { - *temp_ptr++ = '&'; - } - - memcpy(temp_ptr, bs_queue_mode, sizeof(bs_queue_mode)); - temp_ptr += BS_QUEUE_MODE_PARAMATER_LEN; - - if (parameter_ptr->binding_and_mode & 0x01) { - *temp_ptr++ = 'U'; - if (parameter_ptr->binding_and_mode & 0x02) { - *temp_ptr++ = 'Q'; - } - } - - if (parameter_ptr->binding_and_mode & 0x04) { - *temp_ptr++ = 'S'; - if ((parameter_ptr->binding_and_mode & 0x02) && !(parameter_ptr->binding_and_mode & 0x01)) { - *temp_ptr++ = 'Q'; - } - } - } - - return SN_NSDL_SUCCESS; -} - -static bool validateParameters(sn_nsdl_ep_parameters_s *parameter_ptr) -{ - if( !validate( parameter_ptr->domain_name_ptr, parameter_ptr->domain_name_len, '&' ) ){ - return false; - } - - if( !validate( parameter_ptr->endpoint_name_ptr, parameter_ptr->endpoint_name_len, '&' ) ){ - return false; - } - - if( !validate( parameter_ptr->lifetime_ptr, parameter_ptr->lifetime_len, '&' ) ){ - return false; - } - - if( !validate( parameter_ptr->type_ptr, parameter_ptr->type_len, '&' ) ){ - return false; - } - return true; -} - -static bool validate(uint8_t* ptr, uint32_t len, char illegalChar) -{ - if( ptr ){ - for( uint32_t i=0; i < len; i++ ){ - if( ptr[i] == illegalChar ){ - return false; - } - } - } - return true; -} - -/** - * \fn static int8_t sn_nsdl_local_rx_function(struct nsdl_s *handle, sn_coap_hdr_s *coap_packet_ptr, sn_nsdl_addr_s *address_ptr) - * - * \brief If received message is reply for the message that NSDL has been sent, it is processed here. Else, packet will be sent to application. - * \param *handle Pointer to nsdl-library handle - * \param *coap_packet_ptr Pointer to received CoAP packet - * \param *address_ptr Pointer to source address struct - * - * \return SN_NSDL_SUCCESS = 0, Failed = -1 - */ -static int8_t sn_nsdl_local_rx_function(struct nsdl_s *handle, sn_coap_hdr_s *coap_packet_ptr, sn_nsdl_addr_s *address_ptr) -{ - if ((coap_packet_ptr == 0) || (address_ptr == 0)) { - return -1; - } - - bool is_reg_msg = false; - bool is_update_reg_msg = false; - bool is_unreg_msg = false; - if (coap_packet_ptr->msg_code == COAP_MSG_CODE_RESPONSE_CREATED) { - if (handle->grs->coap->sn_coap_block_data_size > 0) { - handle->register_msg_id += handle->register_msg_len / handle->grs->coap->sn_coap_block_data_size; - } - if (coap_packet_ptr->msg_id == handle->register_msg_id) { - handle->sn_nsdl_endpoint_registered = SN_NSDL_ENDPOINT_IS_REGISTERED; - is_reg_msg = true; - sn_grs_mark_resources_as_registered(handle); - if (sn_nsdl_resolve_ep_information(handle, coap_packet_ptr) != SN_NSDL_SUCCESS) { - return SN_NSDL_FAILURE; - } - } - } - - else if (coap_packet_ptr->msg_code == COAP_MSG_CODE_RESPONSE_CHANGED) { - if (handle->grs->coap->sn_coap_block_data_size > 0) { - handle->update_register_msg_id += handle->update_register_msg_len / handle->grs->coap->sn_coap_block_data_size; - } - if (coap_packet_ptr->msg_id == handle->update_register_msg_id) { - is_update_reg_msg = true; - } - } - - if (coap_packet_ptr->msg_id == handle->unregister_msg_id) { - is_unreg_msg = true; - if (coap_packet_ptr->msg_code == COAP_MSG_CODE_RESPONSE_DELETED) { - if (handle->ep_information_ptr->endpoint_name_ptr) { - handle->sn_nsdl_free(handle->ep_information_ptr->endpoint_name_ptr); - handle->ep_information_ptr->endpoint_name_ptr = 0; - handle->ep_information_ptr->endpoint_name_len = 0; - } - if (handle->ep_information_ptr->domain_name_ptr) { - handle->sn_nsdl_free(handle->ep_information_ptr->domain_name_ptr); - handle->ep_information_ptr->domain_name_ptr = 0; - handle->ep_information_ptr->domain_name_len = 0; - } - } - } - - /* No messages to wait for, or message was not response to our request */ - int ret = handle->sn_nsdl_rx_callback(handle, coap_packet_ptr, address_ptr); - if (is_reg_msg) { - handle->register_msg_id = 0; - handle->register_msg_len = 0; - } - else if (is_unreg_msg) { - handle->unregister_msg_id = 0; - } - else if (is_update_reg_msg) { - handle->update_register_msg_id = 0; - handle->update_register_msg_len = 0; - } - return ret; -} - -/** - * \fn static int8_t sn_nsdl_resolve_ep_information(struct nsdl_s *handle, sn_coap_hdr_s *coap_packet_ptr) - * - * - * \brief Resolves endpoint information from received CoAP message - * \param *handle Pointer to nsdl-library handle - * \param *coap_packet_ptr Pointer to received CoAP message - * - * \return SN_NSDL_SUCCESS = 0, Failed = -1 - */ -static int8_t sn_nsdl_resolve_ep_information(struct nsdl_s *handle, sn_coap_hdr_s *coap_packet_ptr) -{ - uint8_t *temp_ptr; - uint8_t parameter_count = 0; - uint16_t parameter_len = 0; - - if (!coap_packet_ptr || !coap_packet_ptr->options_list_ptr || - !coap_packet_ptr->options_list_ptr->location_path_ptr) { - return SN_NSDL_FAILURE; - } - - temp_ptr = coap_packet_ptr->options_list_ptr->location_path_ptr; - - while (temp_ptr <= (coap_packet_ptr->options_list_ptr->location_path_ptr + coap_packet_ptr->options_list_ptr->location_path_len)) { - - if ((temp_ptr == (coap_packet_ptr->options_list_ptr->location_path_ptr + coap_packet_ptr->options_list_ptr->location_path_len)) || (*temp_ptr == '/')) { - - parameter_count++; - if (parameter_count == 2) { - if (!handle->ep_information_ptr->domain_name_ptr) { - handle->ep_information_ptr->domain_name_len = parameter_len - 1; - handle->ep_information_ptr->domain_name_ptr = handle->sn_nsdl_alloc(handle->ep_information_ptr->domain_name_len); - if (!handle->ep_information_ptr->domain_name_ptr) { - return SN_NSDL_FAILURE; - } - memcpy(handle->ep_information_ptr->domain_name_ptr, temp_ptr - handle->ep_information_ptr->domain_name_len, handle->ep_information_ptr->domain_name_len); - } - - } - if (parameter_count == 3) { - if (!handle->ep_information_ptr->endpoint_name_ptr) { - handle->ep_information_ptr->endpoint_name_len = parameter_len - 1; - handle->ep_information_ptr->endpoint_name_ptr = handle->sn_nsdl_alloc(handle->ep_information_ptr->endpoint_name_len); - if (!handle->ep_information_ptr->endpoint_name_ptr) { - if (handle->ep_information_ptr->domain_name_ptr) { - handle->sn_nsdl_free(handle->ep_information_ptr->domain_name_ptr); - handle->ep_information_ptr->domain_name_ptr = NULL; - handle->ep_information_ptr->domain_name_len = 0; - } - - return SN_NSDL_FAILURE; - - } - memcpy(handle->ep_information_ptr->endpoint_name_ptr, temp_ptr - handle->ep_information_ptr->endpoint_name_len, handle->ep_information_ptr->endpoint_name_len); - } - } - parameter_len = 0; - } - parameter_len++; - temp_ptr++; - } - - - return SN_NSDL_SUCCESS; -} - -int8_t set_NSP_address(struct nsdl_s *handle, uint8_t *NSP_address, uint16_t port, sn_nsdl_addr_type_e address_type) -{ - - /* Check parameters and source pointers */ - if (!handle || !handle->nsp_address_ptr || !handle->nsp_address_ptr->omalw_address_ptr || !NSP_address) { - return SN_NSDL_FAILURE; - } - - handle->nsp_address_ptr->omalw_address_ptr->type = address_type; - handle->nsp_address_ptr->omalw_server_security = SEC_NOT_SET; - - if (address_type == SN_NSDL_ADDRESS_TYPE_IPV4) { - if (handle->nsp_address_ptr->omalw_address_ptr->addr_ptr) { - handle->sn_nsdl_free(handle->nsp_address_ptr->omalw_address_ptr->addr_ptr); - } - - handle->nsp_address_ptr->omalw_address_ptr->addr_len = 4; - - handle->nsp_address_ptr->omalw_address_ptr->addr_ptr = handle->sn_nsdl_alloc(handle->nsp_address_ptr->omalw_address_ptr->addr_len); - if (!handle->nsp_address_ptr->omalw_address_ptr->addr_ptr) { - return SN_NSDL_FAILURE; - } - - memcpy(handle->nsp_address_ptr->omalw_address_ptr->addr_ptr, NSP_address, handle->nsp_address_ptr->omalw_address_ptr->addr_len); - handle->nsp_address_ptr->omalw_address_ptr->port = port; - } - - else if (address_type == SN_NSDL_ADDRESS_TYPE_IPV6) { - if (handle->nsp_address_ptr->omalw_address_ptr->addr_ptr) { - handle->sn_nsdl_free(handle->nsp_address_ptr->omalw_address_ptr->addr_ptr); - } - - handle->nsp_address_ptr->omalw_address_ptr->addr_len = 16; - - handle->nsp_address_ptr->omalw_address_ptr->addr_ptr = handle->sn_nsdl_alloc(handle->nsp_address_ptr->omalw_address_ptr->addr_len); - if (!handle->nsp_address_ptr->omalw_address_ptr->addr_ptr) { - return SN_NSDL_FAILURE; - } - - memcpy(handle->nsp_address_ptr->omalw_address_ptr->addr_ptr, NSP_address, handle->nsp_address_ptr->omalw_address_ptr->addr_len); - handle->nsp_address_ptr->omalw_address_ptr->port = port; - } - return SN_NSDL_SUCCESS; -} - -extern int8_t set_NSP_address_2(struct nsdl_s *handle, uint8_t *NSP_address, uint8_t address_length, uint16_t port, sn_nsdl_addr_type_e address_type) -{ - /* Check parameters and source pointers */ - if (!handle || !handle->nsp_address_ptr || !handle->nsp_address_ptr->omalw_address_ptr || !NSP_address) { - return SN_NSDL_FAILURE; - } - - handle->nsp_address_ptr->omalw_address_ptr->type = address_type; - handle->nsp_address_ptr->omalw_server_security = SEC_NOT_SET; - - if (handle->nsp_address_ptr->omalw_address_ptr->addr_ptr) { - handle->sn_nsdl_free(handle->nsp_address_ptr->omalw_address_ptr->addr_ptr); - } - - handle->nsp_address_ptr->omalw_address_ptr->addr_len = address_length; - - handle->nsp_address_ptr->omalw_address_ptr->addr_ptr = handle->sn_nsdl_alloc(handle->nsp_address_ptr->omalw_address_ptr->addr_len); - if (!handle->nsp_address_ptr->omalw_address_ptr->addr_ptr) { - return SN_NSDL_FAILURE; - } - - memcpy(handle->nsp_address_ptr->omalw_address_ptr->addr_ptr, NSP_address, handle->nsp_address_ptr->omalw_address_ptr->addr_len); - handle->nsp_address_ptr->omalw_address_ptr->port = port; - - return SN_NSDL_SUCCESS; -} - - -static uint8_t sn_nsdl_itoa_len(uint8_t value) -{ - uint8_t i = 0; - - do { - i++; - } while ((value /= 10) > 0); - - return i; -} - -static uint8_t *sn_nsdl_itoa(uint8_t *ptr, uint8_t value) -{ - - uint8_t start = 0; - uint8_t end = 0; - uint8_t i; - - i = 0; - - /* ITOA */ - do { - ptr[i++] = (value % 10) + '0'; - } while ((value /= 10) > 0); - - end = i - 1; - - /* reverse (part of ITOA) */ - while (start < end) { - uint8_t chr; - - chr = ptr[start]; - ptr[start] = ptr[end]; - ptr[end] = chr; - - start++; - end--; - - } - return (ptr + i); -} - -static int32_t sn_nsdl_atoi(uint8_t *ptr, uint8_t len) -{ - - int32_t result = 0; - - while (len--) { - - if (result) { - result *= 10; - } - - if (*ptr >= '0' && *ptr <= '9') { - result += *ptr - '0'; - } else{ - return -1; - } - - ptr++; - - } - return result; - -} - -static uint32_t sn_nsdl_ahextoi(uint8_t *ptr, uint8_t len) -{ - - uint32_t result = 0; - - while (len--) { - - if (result) { - result *= 16; - } - - if (*ptr >= '0' && *ptr <= '9') { - result += *ptr - '0'; - } else if (*ptr >= 'a' && *ptr <= 'f') { - result += *ptr - 87; - } else if (*ptr >= 'A' && *ptr <= 'F') { - result += *ptr - 55; - } - - ptr++; - - } - return result; - -} - -static int8_t sn_nsdl_resolve_lwm2m_address(struct nsdl_s *handle, uint8_t *uri, uint16_t uri_len) -{ -#ifndef MBED_CLIENT_DISABLE_BOOTSTRAP_FEATURE - if( uri_len < 2 ){ - return SN_NSDL_FAILURE; - } - uint8_t *temp_ptr = uri+2; - uint16_t i = 0; - uint8_t char_cnt = 0; - - /* jump over coap// */ - while ((*(temp_ptr - 2) != '/') || (*(temp_ptr - 1) != '/')) { - temp_ptr++; - if (temp_ptr - uri >= uri_len) { - return SN_NSDL_FAILURE; - } - } - - /* Resolve address type */ - /* Count semicolons */ - - int8_t endPos = -1; - - while (i < (uri_len - (temp_ptr - uri))) { - if (*(temp_ptr + i) == ':') { - char_cnt++; - }else if(*(temp_ptr + i) == ']'){ - endPos = i; - } - i++; - } - - uint8_t *temp_pos = temp_ptr; //store starting point in case of IPv4 parsing fails - - /* IPv6 */ - if (char_cnt > 2) { - i = 0; - - if( handle->nsp_address_ptr->omalw_address_ptr->addr_ptr ){ - handle->sn_nsdl_free(handle->nsp_address_ptr->omalw_address_ptr->addr_ptr); - } - - handle->nsp_address_ptr->omalw_address_ptr->type = SN_NSDL_ADDRESS_TYPE_IPV6; - handle->nsp_address_ptr->omalw_address_ptr->addr_len = 16; - handle->nsp_address_ptr->omalw_address_ptr->addr_ptr = handle->sn_nsdl_alloc(16); - if (!handle->nsp_address_ptr->omalw_address_ptr->addr_ptr) { - return SN_NSDL_FAILURE; - } - - memset(handle->nsp_address_ptr->omalw_address_ptr->addr_ptr, 0, 16); - if (*temp_ptr == '[' && endPos > 0 && (temp_ptr - uri) + endPos < uri_len && *(temp_ptr + endPos + 1) == ':') { - temp_ptr++; - endPos--; - }else{ - /* return failure, because port is mandatory */ - return SN_NSDL_FAILURE; - } - - int8_t loopbackPos = -1; - if( char_cnt != 8 ){ - i = 0; - char_cnt -= 1; - while( i+1 < endPos ){ - if(*(temp_ptr + i) == ':' && *(temp_ptr + i+1) == ':') { - loopbackPos = i; - break; - } - i++; - } - } - i = 0; - - uint8_t numberOfZeros = 8 - char_cnt; - if(loopbackPos == 0){ - numberOfZeros++; - } - - if(loopbackPos == endPos-2){ - numberOfZeros++; - } - - /* Resolve address */ - int8_t pos = loopbackPos == 0?0:-1; - while (i < 16 && ((temp_ptr - uri) + char_cnt) < uri_len) { - char_cnt = 0; - if( pos == loopbackPos ){ - for( int k=0; k < numberOfZeros; k++ ){ - i+=2; - } - pos+=2; - temp_ptr += 2; - if( numberOfZeros == 8 ){ - temp_ptr++; - } - continue; - } - while (*(temp_ptr + char_cnt) != ':' && *(temp_ptr + char_cnt) != ']') { - char_cnt++; - pos++; - } - pos++; - - if (char_cnt <= 2) { - i++; - } - - while (char_cnt) { - if (char_cnt % 2) { - *(handle->nsp_address_ptr->omalw_address_ptr->addr_ptr + i) = (uint8_t)sn_nsdl_ahextoi(temp_ptr, 1); - temp_ptr++; - char_cnt --; - } else { - *(handle->nsp_address_ptr->omalw_address_ptr->addr_ptr + i) = (uint8_t)sn_nsdl_ahextoi(temp_ptr, 2); - temp_ptr += 2; - char_cnt -= 2; - } - i++; - } - temp_ptr++; - } - - temp_ptr++; - uint16_t handled = (temp_ptr - uri); - if( handled < uri_len ){ - if( *(temp_ptr + (uri_len - (temp_ptr - uri) -1)) == '/' ){ - handle->nsp_address_ptr->omalw_address_ptr->port = sn_nsdl_atoi(temp_ptr, uri_len - (temp_ptr - uri) - 1); - }else{ - handle->nsp_address_ptr->omalw_address_ptr->port = sn_nsdl_atoi(temp_ptr, uri_len - (temp_ptr - uri)); - } - } - } - /* IPv4 or Hostname */ - else if (char_cnt == 1) { - char_cnt = 0; - i = 0; - - if( handle->nsp_address_ptr->omalw_address_ptr->addr_ptr ){ - handle->sn_nsdl_free(handle->nsp_address_ptr->omalw_address_ptr->addr_ptr); - } - - /* Check address type */ - while (i < (uri_len - (temp_ptr - uri))) { - if (*(temp_ptr + i) == '.') { - char_cnt++; - } - i++; - } - - bool parseOk = true; - - /* Try IPv4 first */ - if (char_cnt == 3) { - i = 0; - char_cnt = 0; - - handle->nsp_address_ptr->omalw_address_ptr->type = SN_NSDL_ADDRESS_TYPE_IPV4; - handle->nsp_address_ptr->omalw_address_ptr->addr_len = 4; - handle->nsp_address_ptr->omalw_address_ptr->addr_ptr = handle->sn_nsdl_alloc(4); - if (!handle->nsp_address_ptr->omalw_address_ptr->addr_ptr) { - return SN_NSDL_FAILURE; - } - - while (parseOk && ((temp_ptr - uri) < uri_len) && *(temp_ptr - 1) != ':') { - i++; - - if (*(temp_ptr + i) == ':' || *(temp_ptr + i) == '.') { - int8_t value = (int8_t)sn_nsdl_atoi(temp_ptr, i); - if( value == -1 ){ - parseOk = false; - char_cnt = 3; - handle->sn_nsdl_free(handle->nsp_address_ptr->omalw_address_ptr->addr_ptr); - handle->nsp_address_ptr->omalw_address_ptr->addr_ptr = NULL; - break; - } - *(handle->nsp_address_ptr->omalw_address_ptr->addr_ptr + char_cnt) = value; - temp_ptr = temp_ptr + i + 1; - char_cnt++; - i = 0; - } - } - if(parseOk) { - if( *(temp_ptr + (uri_len - (temp_ptr - uri) -1)) == '/' ){ - handle->nsp_address_ptr->omalw_address_ptr->port = sn_nsdl_atoi(temp_ptr, uri_len - (temp_ptr - uri) - 1); - }else{ - handle->nsp_address_ptr->omalw_address_ptr->port = sn_nsdl_atoi(temp_ptr, uri_len - (temp_ptr - uri)); - } - } - }else{ - parseOk = false; - } - - /* Then try Hostname */ - if(!parseOk) { - i = 0; - temp_ptr = temp_pos; - - handle->nsp_address_ptr->omalw_address_ptr->type = SN_NSDL_ADDRESS_TYPE_HOSTNAME; - - /* Resolve address length */ - if (uri_len > 0xff) { - return SN_NSDL_FAILURE; - } - - while (((temp_ptr - uri) + i < uri_len) && *(temp_ptr + i) != ':') { - i++; - } - - handle->nsp_address_ptr->omalw_address_ptr->addr_len = i; - - /* Copy address */ - handle->nsp_address_ptr->omalw_address_ptr->addr_ptr = handle->sn_nsdl_alloc(i); - if (!handle->nsp_address_ptr->omalw_address_ptr->addr_ptr) { - return SN_NSDL_FAILURE; - } - - memcpy(handle->nsp_address_ptr->omalw_address_ptr->addr_ptr, temp_ptr, i); - - temp_ptr += i + 1; - - /* Set port */ - if( *(temp_ptr + (uri_len - (temp_ptr - uri) - 1)) == '/' ){ - handle->nsp_address_ptr->omalw_address_ptr->port = sn_nsdl_atoi(temp_ptr, uri_len - (temp_ptr - uri) - 1); - }else{ - handle->nsp_address_ptr->omalw_address_ptr->port = sn_nsdl_atoi(temp_ptr, uri_len - (temp_ptr - uri)); - } - } - } else { - return SN_NSDL_FAILURE; - } - - return SN_NSDL_SUCCESS; -#else - return SN_NSDL_FAILURE; -#endif //MBED_CLIENT_DISABLE_BOOTSTRAP_FEATURE -} - - -int8_t sn_nsdl_process_oma_tlv(struct nsdl_s *handle, uint8_t *data_ptr, uint16_t data_len) -{ -#ifndef MBED_CLIENT_DISABLE_BOOTSTRAP_FEATURE - uint8_t *temp_ptr = data_ptr; - uint8_t type = 0; - uint16_t identifier = 0; - uint32_t length = 0; - uint8_t path_temp[5] = "0/0/x"; - - sn_nsdl_resource_info_s resource_temp = { - .resource_parameters_ptr = 0, - .mode = SN_GRS_STATIC, - .pathlen = 5, - .path = path_temp, - .resourcelen = 0, - .resource = 0, - .access = (sn_grs_resource_acl_e) 0x0f, /* All allowed */ - .sn_grs_dyn_res_callback = 0 - }; - - while ((temp_ptr - data_ptr) < data_len) { - /* Save type for future use */ - type = *temp_ptr++; - - /* * Bit 5: Indicates the Length of the Identifier. * */ - if (type & 0x20) { - /* 1=The Identifier field of this TLV is 16 bits long */ - identifier = (uint8_t)(*temp_ptr++) << 8; - identifier += (uint8_t) * temp_ptr++; - } else { - /* 0=The Identifier field of this TLV is 8 bits long */ - identifier = (uint8_t) * temp_ptr++; - } - - /* * Bit 4-3: Indicates the type of Length. * */ - if ((type & 0x18) == 0) { - /* 00 = No length field, the value immediately follows the Identifier field in is of the length indicated by Bits 2-0 of this field */ - length = (type & 0x07); - } else if ((type & 0x18) == 0x08) { - /* 01 = The Length field is 8-bits and Bits 2-0 MUST be ignored */ - length = *temp_ptr++; - } else if ((type & 0x18) == 0x10) { - /* 10 = The Length field is 16-bits and Bits 2-0 MUST be ignored */ - length = (uint8_t)(*temp_ptr++) << 8; - length += (uint8_t) * temp_ptr++; - } else if ((type & 0x18) == 0x18) { - /* 11 = The Length field is 24-bits and Bits 2-0 MUST be ignored */ - length = (uint8_t)(*temp_ptr++); - length = length << 16; - length += (uint8_t)(*temp_ptr++) << 8; - length += (uint8_t) * temp_ptr++; - } - - /* * Bits 7-6: Indicates the type of Identifier. * */ - if ((type & 0xC0) == 0x00) { - /* 00 = Object Instance in which case the Value contains one or more Resource TLVs */ - /* Not implemented, return failure */ - } else if ((type & 0xC0) == 0xC0) { - /* 11 = Resource with Value */ - switch (identifier) { - case 0: - /* Resolve LWM2M Server URI */ - sn_nsdl_resolve_lwm2m_address(handle, temp_ptr, length); - path_temp[4] = '0'; - resource_temp.resource = temp_ptr; - resource_temp.resourcelen = length; - if (sn_nsdl_create_resource(handle, &resource_temp) != SN_NSDL_SUCCESS) { - return SN_NSDL_FAILURE; - } - break; - case 2: - /* Resolve security Mode */ - handle->nsp_address_ptr->omalw_server_security = (omalw_server_security_t)sn_nsdl_atoi(temp_ptr, length); - path_temp[4] = '2'; - resource_temp.resource = temp_ptr; - resource_temp.resourcelen = length; - if (sn_nsdl_create_resource(handle, &resource_temp) != SN_NSDL_SUCCESS) { - return SN_NSDL_FAILURE; - } - - break; - case 3: - /* Public Key or Identity */ - path_temp[4] = '3'; - resource_temp.resource = temp_ptr; - resource_temp.resourcelen = length; - if (sn_nsdl_create_resource(handle, &resource_temp) != SN_NSDL_SUCCESS) { - return SN_NSDL_FAILURE; - } - break; - case 4: - /* Server Public Key or Identity */ - ; - path_temp[4] = '4'; - resource_temp.resource = temp_ptr; - resource_temp.resourcelen = length; - if (sn_nsdl_create_resource(handle, &resource_temp) != SN_NSDL_SUCCESS) { - return SN_NSDL_FAILURE; - } - - break; - case 5: - /* Secret Key */ - path_temp[4] = '5'; - resource_temp.resource = temp_ptr; - resource_temp.resourcelen = length; - if (sn_nsdl_create_resource(handle, &resource_temp) != SN_NSDL_SUCCESS) { - return SN_NSDL_FAILURE; - } - break; - default: - break; - } - - /* Move pointer to next TLV message */ - temp_ptr += length; - } - } - - return SN_NSDL_SUCCESS; -#else - return SN_NSDL_FAILURE; -#endif //MBED_CLIENT_DISABLE_BOOTSTRAP_FEATURE -} - -static void sn_nsdl_check_oma_bs_status(struct nsdl_s *handle) -{ -#ifndef MBED_CLIENT_DISABLE_BOOTSTRAP_FEATURE - /* Check OMA BS status */ - if ((handle->nsp_address_ptr->omalw_server_security == PSK) && (handle->nsp_address_ptr->omalw_address_ptr->type != SN_NSDL_ADDRESS_TYPE_NONE)) { - /* call cb that oma bootstrap is done */ - if(handle->sn_nsdl_oma_bs_done_cb != 0){ - handle->sn_nsdl_oma_bs_done_cb(handle->nsp_address_ptr); - } - if(handle->sn_nsdl_oma_bs_done_cb_handle != 0){ - handle->sn_nsdl_oma_bs_done_cb_handle(handle->nsp_address_ptr, handle); - } - - } else if ((handle->nsp_address_ptr->omalw_server_security == CERTIFICATE) && (handle->nsp_address_ptr->omalw_address_ptr->type != SN_NSDL_ADDRESS_TYPE_NONE) && - ((sn_nsdl_get_resource(handle, 5, (void *)"0/0/5") != 0) && - (sn_nsdl_get_resource(handle, 5, (void *)"0/0/4") != 0) && - (sn_nsdl_get_resource(handle, 5, (void *)"0/0/3") != 0))) { - if( handle->sn_nsdl_oma_bs_done_cb ){ - handle->sn_nsdl_oma_bs_done_cb(handle->nsp_address_ptr); - } - if( handle->sn_nsdl_oma_bs_done_cb_handle ){ - handle->sn_nsdl_oma_bs_done_cb_handle(handle->nsp_address_ptr, handle); - } - } -#endif //MBED_CLIENT_DISABLE_BOOTSTRAP_FEATURE -} - -static int8_t set_endpoint_info(struct nsdl_s *handle, sn_nsdl_ep_parameters_s *endpoint_info_ptr) -{ - if (handle->ep_information_ptr->domain_name_ptr) { - handle->sn_nsdl_free(handle->ep_information_ptr->domain_name_ptr); - handle->ep_information_ptr->domain_name_ptr = 0; - handle->ep_information_ptr->domain_name_len = 0; - } - - if (handle->ep_information_ptr->endpoint_name_ptr) { - handle->sn_nsdl_free(handle->ep_information_ptr->endpoint_name_ptr); - handle->ep_information_ptr->endpoint_name_ptr = 0; - handle->ep_information_ptr->endpoint_name_len = 0; - } - - if (endpoint_info_ptr->domain_name_ptr && endpoint_info_ptr->domain_name_len) { - handle->ep_information_ptr->domain_name_ptr = handle->sn_nsdl_alloc(endpoint_info_ptr->domain_name_len); - - if (!handle->ep_information_ptr->domain_name_ptr) { - return -1; - } - - memcpy(handle->ep_information_ptr->domain_name_ptr, endpoint_info_ptr->domain_name_ptr, endpoint_info_ptr->domain_name_len); - handle->ep_information_ptr->domain_name_len = endpoint_info_ptr->domain_name_len; - } - - if (endpoint_info_ptr->endpoint_name_ptr && endpoint_info_ptr->endpoint_name_len) { - handle->ep_information_ptr->endpoint_name_ptr = handle->sn_nsdl_alloc(endpoint_info_ptr->endpoint_name_len); - - if (!handle->ep_information_ptr->endpoint_name_ptr) { - if (handle->ep_information_ptr->domain_name_ptr) { - handle->sn_nsdl_free(handle->ep_information_ptr->domain_name_ptr); - handle->ep_information_ptr->domain_name_ptr = 0; - handle->ep_information_ptr->domain_name_len = 0; - } - return -1; - } - - memcpy(handle->ep_information_ptr->endpoint_name_ptr, endpoint_info_ptr->endpoint_name_ptr, endpoint_info_ptr->endpoint_name_len); - handle->ep_information_ptr->endpoint_name_len = endpoint_info_ptr->endpoint_name_len; - } - - handle->ep_information_ptr->binding_and_mode = endpoint_info_ptr->binding_and_mode; - handle->ep_information_ptr->ds_register_mode = endpoint_info_ptr->ds_register_mode; - - handle->ep_information_ptr->location_ptr = 0; - handle->ep_information_ptr->location_len = 0; - - return 0; -} - -/* Wrapper */ -sn_grs_resource_list_s *sn_nsdl_list_resource(struct nsdl_s *handle, uint16_t pathlen, uint8_t *path) -{ - /* Check parameters */ - if (handle == NULL) { - return NULL; - } - - return sn_grs_list_resource(handle->grs, pathlen, path); -} - -void sn_nsdl_free_resource_list(struct nsdl_s *handle, sn_grs_resource_list_s *list) -{ - /* Check parameters */ - if (handle == NULL) { - return; - } - - sn_grs_free_resource_list(handle->grs, list); -} - -extern int8_t sn_nsdl_update_resource(struct nsdl_s *handle, sn_nsdl_resource_info_s *res) -{ - /* Check parameters */ - if (handle == NULL) { - return SN_NSDL_FAILURE; - } - - return sn_grs_update_resource(handle->grs, res); -} - -extern int8_t sn_nsdl_send_coap_message(struct nsdl_s *handle, sn_nsdl_addr_s *address_ptr, sn_coap_hdr_s *coap_hdr_ptr) -{ - /* Check parameters */ - if (handle == NULL) { - return SN_NSDL_FAILURE; - } - - return sn_grs_send_coap_message(handle, address_ptr, coap_hdr_ptr); -} - -extern int8_t sn_nsdl_create_resource(struct nsdl_s *handle, sn_nsdl_resource_info_s *res) -{ - /* Check parameters */ - if (handle == NULL) { - return SN_NSDL_FAILURE; - } - - return sn_grs_create_resource(handle->grs, res); -} - -extern int8_t sn_nsdl_put_resource(struct nsdl_s *handle, sn_nsdl_resource_info_s *res) -{ - if (!handle) { - return SN_NSDL_FAILURE; - } - - return sn_grs_put_resource(handle->grs, res); -} - -extern int8_t sn_nsdl_delete_resource(struct nsdl_s *handle, uint16_t pathlen, uint8_t *path) -{ - /* Check parameters */ - if (handle == NULL) { - return SN_NSDL_FAILURE; - } - - return sn_grs_delete_resource(handle->grs, pathlen, path); -} -extern const sn_nsdl_resource_info_s *sn_nsdl_get_first_resource(struct nsdl_s *handle) -{ - /* Check parameters */ - if (handle == NULL) { - return NULL; - } - - return sn_grs_get_first_resource(handle->grs); -} -extern const sn_nsdl_resource_info_s *sn_nsdl_get_next_resource(struct nsdl_s *handle, const sn_nsdl_resource_info_s *resource) -{ - /* Check parameters */ - if (handle == NULL) { - return NULL; - } - - return sn_grs_get_next_resource(handle->grs, resource); -} - -extern sn_coap_hdr_s *sn_nsdl_build_response(struct nsdl_s *handle, sn_coap_hdr_s *coap_packet_ptr, uint8_t msg_code) -{ - if (handle == NULL) { - return NULL; - } - - return sn_coap_build_response(handle->grs->coap, coap_packet_ptr, msg_code); -} - -extern sn_coap_options_list_s *sn_nsdl_alloc_options_list(struct nsdl_s *handle, sn_coap_hdr_s *coap_msg_ptr) -{ - if (handle == NULL || coap_msg_ptr == NULL) { - return NULL; - } - return sn_coap_parser_alloc_options(handle->grs->coap, coap_msg_ptr); -} - -extern void sn_nsdl_release_allocated_coap_msg_mem(struct nsdl_s *handle, sn_coap_hdr_s *freed_coap_msg_ptr) -{ - if (handle == NULL) { - return; - } - - sn_coap_parser_release_allocated_coap_msg_mem(handle->grs->coap, freed_coap_msg_ptr); -} - -extern int8_t sn_nsdl_set_retransmission_parameters(struct nsdl_s *handle, - uint8_t resending_count, uint8_t resending_interval) -{ - if (handle == NULL) { - return SN_NSDL_FAILURE; - } - return sn_coap_protocol_set_retransmission_parameters(handle->grs->coap, - resending_count,resending_interval); -} - -extern int8_t sn_nsdl_set_retransmission_buffer(struct nsdl_s *handle, - uint8_t buffer_size_messages, uint16_t buffer_size_bytes) -{ - if (handle == NULL) { - return SN_NSDL_FAILURE; - } - return sn_coap_protocol_set_retransmission_buffer(handle->grs->coap, - buffer_size_messages, buffer_size_bytes); -} - -extern int8_t sn_nsdl_set_block_size(struct nsdl_s *handle, uint16_t block_size) -{ - if (handle == NULL) { - return SN_NSDL_FAILURE; - } - return sn_coap_protocol_set_block_size(handle->grs->coap, block_size); -} - -extern int8_t sn_nsdl_set_duplicate_buffer_size(struct nsdl_s *handle, uint8_t message_count) -{ - if (handle == NULL) { - return SN_NSDL_FAILURE; - } - return sn_coap_protocol_set_duplicate_buffer_size(handle->grs->coap, message_count); -} - -bool sn_nsdl_check_uint_overflow(uint16_t resource_size, uint16_t param_a, uint16_t param_b) -{ - uint16_t first_check = param_a + param_b; - if (first_check < param_b) { - return false; - } else { - uint16_t total = resource_size + first_check; - if (total < first_check) { - return false; - } else { - return true; - } - } -} - -extern int8_t sn_nsdl_set_context(struct nsdl_s * const handle, void * const context) -{ - if (handle == NULL) { - return SN_NSDL_FAILURE; - } - handle->context = context; - return SN_NSDL_SUCCESS; -} - -extern void *sn_nsdl_get_context(const struct nsdl_s * const handle) -{ - if (handle == NULL) { - return NULL; - } - return handle->context; -} - -#endif - diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/source/libNsdl/src/sn_nsdl2.c b/features/FEATURE_COMMON_PAL/mbed-client-c/source/libNsdl/src/sn_nsdl2.c deleted file mode 100755 index 33ba94678c..0000000000 --- a/features/FEATURE_COMMON_PAL/mbed-client-c/source/libNsdl/src/sn_nsdl2.c +++ /dev/null @@ -1,1760 +0,0 @@ -/* - * Copyright (c) 2011-2015 ARM Limited. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 - * Licensed under the Apache License, Version 2.0 (the License); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * \file sn_nsdl2.c - * - * \brief Nano service device library - * - */ -#ifdef MBED_CLIENT_C_NEW_API - -#include - -#include "ns_types.h" -#include "sn_nsdl.h" -#include "sn_coap_header.h" -#include "sn_coap_protocol.h" -#include "sn_coap_protocol_internal.h" -#include "sn_nsdl_lib.h" -#include "sn_grs.h" -#include "sn_config.h" -#include "mbed-trace/mbed_trace.h" - -#define TRACE_GROUP "coap" -/* Defines */ -#define TRACE_GROUP "coap" -#define RESOURCE_DIR_LEN 2 -#define EP_NAME_PARAMETERS_LEN 3 -#define ET_PARAMETER_LEN 3 -#define LT_PARAMETER_LEN 3 -#define DOMAIN_PARAMETER_LEN 2 -#define RT_PARAMETER_LEN 3 -#define IF_PARAMETER_LEN 3 -#define OBS_PARAMETER_LEN 3 -#define AOBS_PARAMETER_LEN 8 -#define COAP_CON_PARAMETER_LEN 3 -#define BS_EP_PARAMETER_LEN 3 -#define BS_QUEUE_MODE_PARAMATER_LEN 2 - -#define SN_NSDL_EP_REGISTER_MESSAGE 1 -#define SN_NSDL_EP_UPDATE_MESSAGE 2 - -#define SN_NSDL_MSG_UNDEFINED 0 -#define SN_NSDL_MSG_REGISTER 1 -#define SN_NSDL_MSG_UNREGISTER 2 -#define SN_NSDL_MSG_UPDATE 3 -#define SN_NSDL_MSG_BOOTSTRAP 4 - -#ifdef YOTTA_CFG_DISABLE_OBS_FEATURE -#define COAP_DISABLE_OBS_FEATURE YOTTA_CFG_DISABLE_OBS_FEATURE -#elif defined MBED_CONF_MBED_CLIENT_COAP_DISABLE_OBS_FEATURE -#define COAP_DISABLE_OBS_FEATURE MBED_CONF_MBED_CLIENT_COAP_DISABLE_OBS_FEATURE -#endif - -#ifdef YOTTA_CFG_DISABLE_BOOTSTRAP_FEATURE -#define MBED_CLIENT_DISABLE_BOOTSTRAP_FEATURE YOTTA_CFG_DISABLE_BOOTSTRAP_FEATURE -#elif defined MBED_CONF_MBED_CLIENT_DISABLE_BOOTSTRAP_FEATURE -#define MBED_CLIENT_DISABLE_BOOTSTRAP_FEATURE MBED_CONF_MBED_CLIENT_DISABLE_BOOTSTRAP_FEATURE -#endif - - -/* Constants */ -static uint8_t ep_name_parameter_string[] = {'e', 'p', '='}; /* Endpoint name. A unique name for the registering node in a domain. */ -static uint8_t resource_path_ptr[] = {'r', 'd'}; /* For resource directory */ -static uint8_t resource_type_parameter[] = {'r', 't', '='}; /* Resource type. Only once for registration */ -#ifndef COAP_DISABLE_OBS_FEATURE -static uint8_t obs_parameter[] = {'o', 'b', 's'}; /* Observable */ -#endif -static uint8_t if_description_parameter[] = {'i', 'f', '='}; /* Interface description. Only once */ -static uint8_t ep_lifetime_parameter[] = {'l', 't', '='}; /* Lifetime. Number of seconds that this registration will be valid for. Must be updated within this time, or will be removed. */ -static uint8_t ep_domain_parameter[] = {'d', '='}; /* Domain name. If this parameter is missing, a default domain is assumed. */ -static uint8_t coap_con_type_parameter[] = {'c', 't', '='}; /* CoAP content type */ -/* * OMA BS parameters * */ -static uint8_t bs_uri[] = {'b', 's'}; -static uint8_t bs_ep_name[] = {'e', 'p', '='}; -static uint8_t et_parameter[] = {'e', 't', '='}; /* Endpoint type */ -static uint8_t bs_queue_mode[] = {'b', '='}; - -/* Function prototypes */ -static uint16_t sn_nsdl_internal_coap_send(struct nsdl_s *handle, sn_coap_hdr_s *coap_header_ptr, sn_nsdl_addr_s *dst_addr_ptr, uint8_t message_description); -static void sn_nsdl_resolve_nsp_address(struct nsdl_s *handle); -int8_t sn_nsdl_build_registration_body(struct nsdl_s *handle, sn_coap_hdr_s *message_ptr, uint8_t updating_registeration); -static uint16_t sn_nsdl_calculate_registration_body_size(struct nsdl_s *handle, uint8_t updating_registeration, int8_t *error); -static uint8_t sn_nsdl_calculate_uri_query_option_len(sn_nsdl_ep_parameters_s *endpoint_info_ptr, uint8_t msg_type); -static int8_t sn_nsdl_fill_uri_query_options(struct nsdl_s *handle, sn_nsdl_ep_parameters_s *parameter_ptr, sn_coap_hdr_s *source_msg_ptr, uint8_t msg_type); -static int8_t sn_nsdl_local_rx_function(struct nsdl_s *handle, sn_coap_hdr_s *coap_packet_ptr, sn_nsdl_addr_s *address_ptr); -static int8_t sn_nsdl_resolve_ep_information(struct nsdl_s *handle, sn_coap_hdr_s *coap_packet_ptr); -static uint8_t sn_nsdl_itoa_len(uint8_t value); -static uint8_t *sn_nsdl_itoa(uint8_t *ptr, uint8_t value); -static int8_t set_endpoint_info(struct nsdl_s *handle, sn_nsdl_ep_parameters_s *endpoint_info_ptr); -static bool validateParameters(sn_nsdl_ep_parameters_s *parameter_ptr); -static bool validate(uint8_t* ptr, uint32_t len, char illegalChar); -static bool sn_nsdl_check_uint_overflow(uint16_t resource_size, uint16_t param_a, uint16_t param_b); - -int8_t sn_nsdl_destroy(struct nsdl_s *handle) -{ - if (handle == NULL) { - return SN_NSDL_FAILURE; - } - - if (handle->ep_information_ptr) { - if (handle->ep_information_ptr->endpoint_name_ptr) { - handle->sn_nsdl_free(handle->ep_information_ptr->endpoint_name_ptr); - handle->ep_information_ptr->endpoint_name_ptr = 0; - } - if (handle->ep_information_ptr->domain_name_ptr) { - handle->sn_nsdl_free(handle->ep_information_ptr->domain_name_ptr); - handle->ep_information_ptr->domain_name_ptr = 0; - handle->ep_information_ptr->domain_name_len = 0; - } - if (handle->ep_information_ptr->location_ptr) { - handle->sn_nsdl_free(handle->ep_information_ptr->location_ptr); - handle->ep_information_ptr->location_ptr = 0; - handle->ep_information_ptr->location_len = 0; - } - if (handle->ep_information_ptr->type_ptr) { - handle->sn_nsdl_free(handle->ep_information_ptr->type_ptr); - handle->ep_information_ptr->type_ptr = 0; - } - - if (handle->ep_information_ptr->lifetime_ptr) - - { - handle->sn_nsdl_free(handle->ep_information_ptr->lifetime_ptr); - handle->ep_information_ptr->lifetime_ptr = 0; - } - - handle->sn_nsdl_free(handle->ep_information_ptr); - handle->ep_information_ptr = 0; - } - - if (handle->nsp_address_ptr) { - if (handle->nsp_address_ptr->omalw_address_ptr) { - if (handle->nsp_address_ptr->omalw_address_ptr->addr_ptr) { - handle->sn_nsdl_free(handle->nsp_address_ptr->omalw_address_ptr->addr_ptr); - handle->nsp_address_ptr->omalw_address_ptr->addr_ptr = 0; - } - handle->sn_nsdl_free(handle->nsp_address_ptr->omalw_address_ptr); - } - - handle->sn_nsdl_free(handle->nsp_address_ptr); - handle->nsp_address_ptr = 0; - } - - if (handle->oma_bs_address_ptr) { - handle->sn_nsdl_free(handle->oma_bs_address_ptr); - } - - /* Destroy also libCoap and grs part of libNsdl */ - sn_coap_protocol_destroy(handle->grs->coap); - sn_grs_destroy(handle->grs); - handle->sn_nsdl_free(handle); - - return SN_NSDL_SUCCESS; -} - -struct nsdl_s *sn_nsdl_init(uint8_t (*sn_nsdl_tx_cb)(struct nsdl_s *, sn_nsdl_capab_e , uint8_t *, uint16_t, sn_nsdl_addr_s *), - uint8_t (*sn_nsdl_rx_cb)(struct nsdl_s *, sn_coap_hdr_s *, sn_nsdl_addr_s *), - void *(*sn_nsdl_alloc)(uint16_t), void (*sn_nsdl_free)(void *)) -{ - /* Check pointers and define function pointers */ - if (!sn_nsdl_alloc || !sn_nsdl_free || !sn_nsdl_tx_cb || !sn_nsdl_rx_cb) { - return NULL; - } - - struct nsdl_s *handle = NULL; - - handle = sn_nsdl_alloc(sizeof(struct nsdl_s)); - - if (handle == NULL) { - return NULL; - } - - memset(handle, 0, sizeof(struct nsdl_s)); - - /* Define function pointers */ - handle->sn_nsdl_alloc = sn_nsdl_alloc; - handle->sn_nsdl_free = sn_nsdl_free; - - handle->sn_nsdl_tx_callback = sn_nsdl_tx_cb; - handle->sn_nsdl_rx_callback = sn_nsdl_rx_cb; - - /* Initialize ep parameters struct */ - if (!handle->ep_information_ptr) { - handle->ep_information_ptr = handle->sn_nsdl_alloc(sizeof(sn_nsdl_ep_parameters_s)); - if (!handle->ep_information_ptr) { - sn_nsdl_free(handle); - return NULL; - } - memset(handle->ep_information_ptr, 0, sizeof(sn_nsdl_ep_parameters_s)); - } - - handle->grs = sn_grs_init(sn_nsdl_tx_cb, &sn_nsdl_local_rx_function, sn_nsdl_alloc, sn_nsdl_free); - - /* Initialize GRS */ - if (handle->grs == NULL) { - handle->sn_nsdl_free(handle->ep_information_ptr); - handle->ep_information_ptr = 0; - sn_nsdl_free(handle); - return NULL; - } - - sn_nsdl_resolve_nsp_address(handle); - - handle->sn_nsdl_endpoint_registered = SN_NSDL_ENDPOINT_NOT_REGISTERED; - handle->context = NULL; - - return handle; -} - -uint16_t sn_nsdl_register_endpoint(struct nsdl_s *handle, sn_nsdl_ep_parameters_s *endpoint_info_ptr) -{ - /* Local variables */ - sn_coap_hdr_s *register_message_ptr; - uint16_t message_id = 0; - - if (endpoint_info_ptr == NULL || handle == NULL) { - return 0; - } - - /*** Build endpoint register message ***/ - - /* Allocate memory for header struct */ - register_message_ptr = sn_coap_parser_alloc_message(handle->grs->coap); - if (register_message_ptr == NULL) { - return 0; - } - - /* Fill message fields -> confirmable post to specified NSP path */ - register_message_ptr->msg_type = COAP_MSG_TYPE_CONFIRMABLE; - register_message_ptr->msg_code = COAP_MSG_CODE_REQUEST_POST; - - /* Allocate memory for the extended options list */ - if (sn_coap_parser_alloc_options(handle->grs->coap, register_message_ptr) == NULL) { - sn_coap_parser_release_allocated_coap_msg_mem(handle->grs->coap, register_message_ptr); - register_message_ptr = 0; - return 0; - } - - register_message_ptr->uri_path_len = sizeof(resource_path_ptr); - register_message_ptr->uri_path_ptr = resource_path_ptr; - - /* Fill Uri-query options */ - if( SN_NSDL_FAILURE == sn_nsdl_fill_uri_query_options(handle, endpoint_info_ptr, - register_message_ptr, SN_NSDL_EP_REGISTER_MESSAGE) ){ - register_message_ptr->uri_path_ptr = NULL; - sn_coap_parser_release_allocated_coap_msg_mem(handle->grs->coap, register_message_ptr); - return 0; - } - - if (endpoint_info_ptr->ds_register_mode == REGISTER_WITH_RESOURCES) { - /* Built body for message */ - if (sn_nsdl_build_registration_body(handle, register_message_ptr, 0) == SN_NSDL_FAILURE) { - register_message_ptr->uri_path_ptr = NULL; - register_message_ptr->options_list_ptr->uri_host_ptr = NULL; - sn_coap_parser_release_allocated_coap_msg_mem(handle->grs->coap, register_message_ptr); - return 0; - } - } - - /* Clean (possible) existing and save new endpoint info to handle */ - if (set_endpoint_info(handle, endpoint_info_ptr) == -1) { - if (register_message_ptr->payload_ptr) { - handle->sn_nsdl_free(register_message_ptr->payload_ptr); - register_message_ptr->payload_ptr = NULL; - } - - register_message_ptr->uri_path_ptr = NULL; - register_message_ptr->options_list_ptr->uri_host_ptr = NULL; - - sn_coap_parser_release_allocated_coap_msg_mem(handle->grs->coap, register_message_ptr); - - return 0; - } - - /* Build and send coap message to NSP */ - message_id = sn_nsdl_internal_coap_send(handle, register_message_ptr, handle->nsp_address_ptr->omalw_address_ptr, SN_NSDL_MSG_REGISTER); - - if (register_message_ptr->payload_ptr) { - handle->sn_nsdl_free(register_message_ptr->payload_ptr); - register_message_ptr->payload_ptr = NULL; - } - - register_message_ptr->uri_path_ptr = NULL; - register_message_ptr->options_list_ptr->uri_host_ptr = NULL; - - sn_coap_parser_release_allocated_coap_msg_mem(handle->grs->coap, register_message_ptr); - - return message_id; -} - -uint16_t sn_nsdl_unregister_endpoint(struct nsdl_s *handle) -{ - /* Local variables */ - sn_coap_hdr_s *unregister_message_ptr; - uint8_t *temp_ptr = 0; - uint16_t message_id = 0; - - /* Check parameters */ - if (handle == NULL) { - return 0; - } - - /* Check that EP have been registered */ - if (sn_nsdl_is_ep_registered(handle)) { - - /* Memory allocation for unregister message */ - unregister_message_ptr = sn_coap_parser_alloc_message(handle->grs->coap); - if (!unregister_message_ptr) { - return 0; - } - - /* Fill unregister message */ - unregister_message_ptr->msg_type = COAP_MSG_TYPE_CONFIRMABLE; - unregister_message_ptr->msg_code = COAP_MSG_CODE_REQUEST_DELETE; - - if(handle->ep_information_ptr->location_ptr) { - unregister_message_ptr->uri_path_len = handle->ep_information_ptr->location_len; - unregister_message_ptr->uri_path_ptr = handle->sn_nsdl_alloc(unregister_message_ptr->uri_path_len); - if (!unregister_message_ptr->uri_path_ptr) { - sn_coap_parser_release_allocated_coap_msg_mem(handle->grs->coap, unregister_message_ptr); - return 0; - } - - temp_ptr = unregister_message_ptr->uri_path_ptr; - - memcpy(temp_ptr , handle->ep_information_ptr->location_ptr, handle->ep_information_ptr->location_len); - } else { - unregister_message_ptr->uri_path_len = (RESOURCE_DIR_LEN + 1 + handle->ep_information_ptr->domain_name_len + 1 + handle->ep_information_ptr->endpoint_name_len); - unregister_message_ptr->uri_path_ptr = handle->sn_nsdl_alloc(unregister_message_ptr->uri_path_len); - if (!unregister_message_ptr->uri_path_ptr) { - sn_coap_parser_release_allocated_coap_msg_mem(handle->grs->coap, unregister_message_ptr); - return 0; - } - - temp_ptr = unregister_message_ptr->uri_path_ptr; - - memcpy(temp_ptr, resource_path_ptr, RESOURCE_DIR_LEN); - temp_ptr += RESOURCE_DIR_LEN; - - *temp_ptr++ = '/'; - - memcpy(temp_ptr , handle->ep_information_ptr->domain_name_ptr, handle->ep_information_ptr->domain_name_len); - temp_ptr += handle->ep_information_ptr->domain_name_len; - - *temp_ptr++ = '/'; - - memcpy(temp_ptr , handle->ep_information_ptr->endpoint_name_ptr, handle->ep_information_ptr->endpoint_name_len); - } - - /* Send message */ - message_id = sn_nsdl_internal_coap_send(handle, unregister_message_ptr, handle->nsp_address_ptr->omalw_address_ptr, SN_NSDL_MSG_UNREGISTER); - - /* Free memory */ - sn_coap_parser_release_allocated_coap_msg_mem(handle->grs->coap, unregister_message_ptr); - - } - - return message_id; -} - -uint16_t sn_nsdl_update_registration(struct nsdl_s *handle, uint8_t *lt_ptr, uint8_t lt_len) -{ - /* Local variables */ - sn_coap_hdr_s *register_message_ptr; - uint8_t *temp_ptr; - sn_nsdl_ep_parameters_s temp_parameters; - uint16_t message_id = 0; - - /* Check parameters */ - if (handle == NULL) { - return 0; - } - - if (!sn_nsdl_is_ep_registered(handle)){ - return 0; - } - - memset(&temp_parameters, 0, sizeof(sn_nsdl_ep_parameters_s)); - - temp_parameters.lifetime_len = lt_len; - temp_parameters.lifetime_ptr = lt_ptr; - - /*** Build endpoint register update message ***/ - - /* Allocate memory for header struct */ - register_message_ptr = sn_coap_parser_alloc_message(handle->grs->coap); - if (register_message_ptr == NULL) { - return 0; - } - - /* Fill message fields -> confirmable post to specified NSP path */ - register_message_ptr->msg_type = COAP_MSG_TYPE_CONFIRMABLE; - register_message_ptr->msg_code = COAP_MSG_CODE_REQUEST_POST; - - if(handle->ep_information_ptr->location_ptr) { - register_message_ptr->uri_path_len = handle->ep_information_ptr->location_len; /* = Only location set by Device Server*/ - - register_message_ptr->uri_path_ptr = handle->sn_nsdl_alloc(register_message_ptr->uri_path_len); - if (!register_message_ptr->uri_path_ptr) { - sn_coap_parser_release_allocated_coap_msg_mem(handle->grs->coap, register_message_ptr); - return 0; - } - - temp_ptr = register_message_ptr->uri_path_ptr; - - /* location */ - memcpy(temp_ptr, handle->ep_information_ptr->location_ptr, handle->ep_information_ptr->location_len); - } else { - register_message_ptr->uri_path_len = sizeof(resource_path_ptr) + handle->ep_information_ptr->domain_name_len + handle->ep_information_ptr->endpoint_name_len + 2; /* = rd/domain/endpoint */ - - register_message_ptr->uri_path_ptr = handle->sn_nsdl_alloc(register_message_ptr->uri_path_len); - if (!register_message_ptr->uri_path_ptr) { - sn_coap_parser_release_allocated_coap_msg_mem(handle->grs->coap, register_message_ptr); - return 0; - } - - temp_ptr = register_message_ptr->uri_path_ptr; - - /* rd/ */ - memcpy(temp_ptr, resource_path_ptr, sizeof(resource_path_ptr)); - temp_ptr += sizeof(resource_path_ptr); - *temp_ptr++ = '/'; - - /* rd/DOMAIN/ */ - memcpy(temp_ptr, handle->ep_information_ptr->domain_name_ptr, handle->ep_information_ptr->domain_name_len); - temp_ptr += handle->ep_information_ptr->domain_name_len; - *temp_ptr++ = '/'; - - /* rd/domain/ENDPOINT */ - memcpy(temp_ptr, handle->ep_information_ptr->endpoint_name_ptr, handle->ep_information_ptr->endpoint_name_len); - } - - /* Allocate memory for the extended options list */ - if (sn_coap_parser_alloc_options(handle->grs->coap, register_message_ptr) == NULL) { - sn_coap_parser_release_allocated_coap_msg_mem(handle->grs->coap, register_message_ptr); - return 0; - } - - /* Fill Uri-query options */ - sn_nsdl_fill_uri_query_options(handle, &temp_parameters, register_message_ptr, SN_NSDL_EP_UPDATE_MESSAGE); - - /* Build payload */ - if (handle->ep_information_ptr->ds_register_mode == REGISTER_WITH_RESOURCES) { - - if (sn_nsdl_build_registration_body(handle, register_message_ptr, 1) == SN_NSDL_FAILURE) { - sn_coap_parser_release_allocated_coap_msg_mem(handle->grs->coap, register_message_ptr); - return 0; - } - } - - /* Build and send coap message to NSP */ - message_id = sn_nsdl_internal_coap_send(handle, register_message_ptr, handle->nsp_address_ptr->omalw_address_ptr, SN_NSDL_MSG_UPDATE); - - if (register_message_ptr->payload_ptr) { - handle->sn_nsdl_free(register_message_ptr->payload_ptr); - } - sn_coap_parser_release_allocated_coap_msg_mem(handle->grs->coap, register_message_ptr); - - return message_id; -} - -int8_t sn_nsdl_set_endpoint_location(struct nsdl_s *handle, uint8_t *location_ptr, uint8_t location_len) -{ - if(!handle || !location_ptr || (location_len == 0)) { - return -1; - } - - handle->sn_nsdl_free(handle->ep_information_ptr->location_ptr); - handle->ep_information_ptr->location_ptr = handle->sn_nsdl_alloc(location_len); - memcpy(handle->ep_information_ptr->location_ptr, location_ptr, location_len); - handle->ep_information_ptr->location_len = location_len; - - return 0; -} - -void sn_nsdl_nsp_lost(struct nsdl_s *handle) -{ - /* Check parameters */ - if (handle == NULL) { - return; - } - - handle->sn_nsdl_endpoint_registered = SN_NSDL_ENDPOINT_NOT_REGISTERED; -} - -int8_t sn_nsdl_is_ep_registered(struct nsdl_s *handle) -{ - /* Check parameters */ - if (handle == NULL) { - return SN_NSDL_FAILURE; - } - - return handle->sn_nsdl_endpoint_registered; -} - -uint16_t sn_nsdl_send_observation_notification(struct nsdl_s *handle, uint8_t *token_ptr, uint8_t token_len, - uint8_t *payload_ptr, uint16_t payload_len, sn_coap_observe_e observe, sn_coap_msg_type_e message_type, - sn_coap_content_format_e content_format) -{ - sn_coap_hdr_s *notification_message_ptr; - uint16_t return_msg_id = 0; - - /* Check parameters */ - if (handle == NULL || handle->grs == NULL) { - return 0; - } - - /* Allocate and initialize memory for header struct */ - notification_message_ptr = sn_coap_parser_alloc_message(handle->grs->coap); - if (notification_message_ptr == NULL) { - return 0; - } - - if (sn_coap_parser_alloc_options(handle->grs->coap, notification_message_ptr) == NULL) { - handle->sn_nsdl_free(notification_message_ptr); - return 0; - } - - /* Fill header */ - notification_message_ptr->msg_type = message_type; - notification_message_ptr->msg_code = COAP_MSG_CODE_RESPONSE_CONTENT; - - /* Fill token */ - notification_message_ptr->token_len = token_len; - notification_message_ptr->token_ptr = token_ptr; - - /* Fill payload */ - notification_message_ptr->payload_len = payload_len; - notification_message_ptr->payload_ptr = payload_ptr; - - /* Fill observe */ - notification_message_ptr->options_list_ptr->observe = observe; - - /* Fill content format */ - notification_message_ptr->content_format = content_format; - - /* Send message */ - if (sn_nsdl_send_coap_message(handle, handle->nsp_address_ptr->omalw_address_ptr, notification_message_ptr) == SN_NSDL_FAILURE) { - return_msg_id = 0; - } else { - return_msg_id = notification_message_ptr->msg_id; - } - - /* Free memory */ - notification_message_ptr->payload_ptr = NULL; - notification_message_ptr->token_ptr = NULL; - - sn_coap_parser_release_allocated_coap_msg_mem(handle->grs->coap, notification_message_ptr); - - return return_msg_id; -} - - -/* * * * * * * * * * */ -/* ~ OMA functions ~ */ -/* * * * * * * * * * */ - -uint16_t sn_nsdl_oma_bootstrap(struct nsdl_s *handle, sn_nsdl_addr_s *bootstrap_address_ptr, - sn_nsdl_ep_parameters_s *endpoint_info_ptr, - sn_nsdl_bs_ep_info_t *bootstrap_endpoint_info_ptr) -{ -#ifndef MBED_CLIENT_DISABLE_BOOTSTRAP_FEATURE - /* Local variables */ - sn_coap_hdr_s bootstrap_coap_header; - uint8_t *uri_query_tmp_ptr; - uint16_t message_id = 0; - - /* Check parameters */ - if (!bootstrap_address_ptr || !bootstrap_endpoint_info_ptr || !endpoint_info_ptr || !handle) { - return 0; - } - - handle->sn_nsdl_oma_bs_done_cb = bootstrap_endpoint_info_ptr->oma_bs_status_cb; - handle->sn_nsdl_oma_bs_done_cb_handle = bootstrap_endpoint_info_ptr->oma_bs_status_cb_handle; - - /* XXX FIX -- Init CoAP header struct */ - sn_coap_parser_init_message(&bootstrap_coap_header); - - if (!sn_coap_parser_alloc_options(handle->grs->coap, &bootstrap_coap_header)) { - return 0; - } - - /* Build bootstrap start message */ - bootstrap_coap_header.msg_code = COAP_MSG_CODE_REQUEST_POST; - bootstrap_coap_header.msg_type = COAP_MSG_TYPE_CONFIRMABLE; - - bootstrap_coap_header.uri_path_ptr = bs_uri; - bootstrap_coap_header.uri_path_len = sizeof(bs_uri); - - uri_query_tmp_ptr = handle->sn_nsdl_alloc(endpoint_info_ptr->endpoint_name_len + BS_EP_PARAMETER_LEN); - if (!uri_query_tmp_ptr) { - handle->sn_nsdl_free(bootstrap_coap_header.options_list_ptr); - return 0; - } - - memcpy(uri_query_tmp_ptr, bs_ep_name, BS_EP_PARAMETER_LEN); - memcpy((uri_query_tmp_ptr + BS_EP_PARAMETER_LEN), endpoint_info_ptr->endpoint_name_ptr, endpoint_info_ptr->endpoint_name_len); - - bootstrap_coap_header.options_list_ptr->uri_query_len = endpoint_info_ptr->endpoint_name_len + BS_EP_PARAMETER_LEN; - bootstrap_coap_header.options_list_ptr->uri_query_ptr = uri_query_tmp_ptr; - - /* Save bootstrap server address */ - handle->oma_bs_address_len = bootstrap_address_ptr->addr_len; /* Length.. */ - handle->oma_bs_address_ptr = handle->sn_nsdl_alloc(handle->oma_bs_address_len); /* Address.. */ - if (!handle->oma_bs_address_ptr) { - handle->sn_nsdl_free(bootstrap_coap_header.options_list_ptr); - handle->sn_nsdl_free(uri_query_tmp_ptr); - return 0; - } - memcpy(handle->oma_bs_address_ptr, bootstrap_address_ptr->addr_ptr, handle->oma_bs_address_len); - handle->oma_bs_port = bootstrap_address_ptr->port; /* And port */ - - /* Send message */ - message_id = sn_nsdl_internal_coap_send(handle, &bootstrap_coap_header, bootstrap_address_ptr, SN_NSDL_MSG_BOOTSTRAP); - - /* Free allocated memory */ - handle->sn_nsdl_free(uri_query_tmp_ptr); - handle->sn_nsdl_free(bootstrap_coap_header.options_list_ptr); - - return message_id; -#else - return 0; -#endif //MBED_CLIENT_DISABLE_BOOTSTRAP_FEATURE - -} - -char *sn_nsdl_get_version(void) -{ -#if defined(YOTTA_MBED_CLIENT_C_VERSION_STRING) - return YOTTA_MBED_CLIENT_C_VERSION_STRING; -#elif defined(VERSION) - return VERSION; -#else - return "0.0.0"; -#endif -} - -int8_t sn_nsdl_process_coap(struct nsdl_s *handle, uint8_t *packet_ptr, uint16_t packet_len, sn_nsdl_addr_s *src_ptr) -{ - sn_coap_hdr_s *coap_packet_ptr = NULL; - sn_coap_hdr_s *coap_response_ptr = NULL; - sn_nsdl_dynamic_resource_parameters_s *resource = NULL; - /* Check parameters */ - if (handle == NULL) { - return SN_NSDL_FAILURE; - } - - /* Parse CoAP packet */ - coap_packet_ptr = sn_coap_protocol_parse(handle->grs->coap, src_ptr, packet_len, packet_ptr, (void *)handle); - - /* Check if parsing was successfull */ - if (coap_packet_ptr == (sn_coap_hdr_s *)NULL) { - return SN_NSDL_FAILURE; - } -#if SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE - // Pass block to application if external_memory_block is set - if(coap_packet_ptr->coap_status == COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVING) { - resource = sn_nsdl_get_resource(handle, coap_packet_ptr->uri_path_len, coap_packet_ptr->uri_path_ptr); - if(resource && resource->static_resource_parameters->external_memory_block) { - sn_coap_protocol_block_remove(handle->grs->coap, - src_ptr, - coap_packet_ptr->payload_len, - coap_packet_ptr->payload_ptr); - } else { - resource = NULL; - } - } -#endif - /* Check, if coap itself sends response, or block receiving is ongoing... */ - if (coap_packet_ptr->coap_status != COAP_STATUS_OK && - coap_packet_ptr->coap_status != COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED &&coap_packet_ptr && - !resource) { - sn_coap_parser_release_allocated_coap_msg_mem(handle->grs->coap, coap_packet_ptr); - return SN_NSDL_SUCCESS; - } - - /* If proxy options added, return not supported */ - if (coap_packet_ptr->options_list_ptr) { - if (coap_packet_ptr->options_list_ptr->proxy_uri_len) { - coap_response_ptr = sn_coap_build_response(handle->grs->coap, coap_packet_ptr, COAP_MSG_CODE_RESPONSE_PROXYING_NOT_SUPPORTED); - if (coap_response_ptr) { - sn_nsdl_send_coap_message(handle, src_ptr, coap_response_ptr); - sn_coap_parser_release_allocated_coap_msg_mem(handle->grs->coap, coap_response_ptr); - sn_coap_parser_release_allocated_coap_msg_mem(handle->grs->coap, coap_packet_ptr); - return SN_NSDL_SUCCESS; - } else { - sn_coap_parser_release_allocated_coap_msg_mem(handle->grs->coap, coap_packet_ptr); - return SN_NSDL_FAILURE; - } - } - } - - /* * * * * * * * * * * * * * * * * * * * * * * * * * */ - /* If message is response message, call RX callback */ - /* * * * * * * * * * * * * * * * * * * * * * * * * * */ - - if ((coap_packet_ptr->msg_code > COAP_MSG_CODE_REQUEST_DELETE) || - (coap_packet_ptr->msg_type >= COAP_MSG_TYPE_ACKNOWLEDGEMENT)) { - int8_t retval = sn_nsdl_local_rx_function(handle, coap_packet_ptr, src_ptr); - if (coap_packet_ptr->coap_status == COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED && - coap_packet_ptr->payload_ptr) { - handle->sn_nsdl_free(coap_packet_ptr->payload_ptr); - coap_packet_ptr->payload_ptr = 0; - } - sn_coap_parser_release_allocated_coap_msg_mem(handle->grs->coap, coap_packet_ptr); - return retval; - } -#ifndef MBED_CLIENT_DISABLE_BOOTSTRAP_FEATURE - /* * If OMA bootstrap message... * */ - bool bootstrap_msg = src_ptr && (handle->oma_bs_address_len == src_ptr->addr_len) && - (handle->oma_bs_port == src_ptr->port) && - !memcmp(handle->oma_bs_address_ptr, src_ptr->addr_ptr, handle->oma_bs_address_len); - - // Pass bootstrap data to application - if (bootstrap_msg) { - handle->sn_nsdl_rx_callback(handle, coap_packet_ptr,src_ptr); - sn_coap_parser_release_allocated_coap_msg_mem(handle->grs->coap, coap_packet_ptr); - return SN_NSDL_SUCCESS; - } -#endif //MBED_CLIENT_DISABLE_BOOTSTRAP_FEATURE - - /* * * * * * * * * * * * * * * */ - /* Other messages are for GRS */ - /* * * * * * * * * * * * * * * */ - return sn_grs_process_coap(handle, coap_packet_ptr, src_ptr); -} - -int8_t sn_nsdl_exec(struct nsdl_s *handle, uint32_t time) -{ - if(!handle || !handle->grs){ - return SN_NSDL_FAILURE; - } - /* Call CoAP execution function */ - return sn_coap_protocol_exec(handle->grs->coap, time); -} - -sn_nsdl_dynamic_resource_parameters_s *sn_nsdl_get_resource(struct nsdl_s *handle, uint16_t pathlen, uint8_t *path_ptr) -{ - /* Check parameters */ - if (handle == NULL) { - return NULL; - } - - return sn_grs_search_resource(handle->grs, pathlen, path_ptr, SN_GRS_SEARCH_METHOD); -} - - -/** - * \fn static uint16_t sn_nsdl_internal_coap_send(struct nsdl_s *handle, sn_coap_hdr_s *coap_header_ptr, sn_nsdl_addr_s *dst_addr_ptr, uint8_t message_description) - * - * - * \brief To send NSDL messages. Stores message id?s and message description to catch response from NSP server - * \param *handle Pointer to nsdl-library handle - * \param *coap_header_ptr Pointer to the CoAP message header to be sent - * \param *dst_addr_ptr Pointer to the address structure that contains destination address information - * \param message_description Message description to be stored to list for waiting response - * - * \return message id, 0 if failed - */ -static uint16_t sn_nsdl_internal_coap_send(struct nsdl_s *handle, sn_coap_hdr_s *coap_header_ptr, sn_nsdl_addr_s *dst_addr_ptr, uint8_t message_description) -{ - - tr_debug("sn_nsdl_internal_coap_send"); - uint8_t *coap_message_ptr = NULL; - int32_t coap_message_len = 0; - uint16_t coap_header_len = 0; - -#if SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE /* If Message blockwising is not used at all, this part of code will not be compiled */ - int8_t ret_val = prepare_blockwise_message(handle->grs->coap, coap_header_ptr); - if( 0 != ret_val ) { - return 0; - } -#endif - - coap_message_len = sn_coap_builder_calc_needed_packet_data_size_2(coap_header_ptr, handle->grs->coap->sn_coap_block_data_size); - tr_debug("sn_nsdl_internal_coap_send - msg len after calc: [%d]", coap_message_len); - if (coap_message_len == 0) { - return 0; - } - - coap_message_ptr = handle->sn_nsdl_alloc(coap_message_len); - if (!coap_message_ptr) { - return 0; - } - - coap_header_len = coap_header_ptr->payload_len; - /* Build message */ - if (sn_coap_protocol_build(handle->grs->coap, dst_addr_ptr, coap_message_ptr, coap_header_ptr, (void *)handle) < 0) { - handle->sn_nsdl_free(coap_message_ptr); - return 0; - } - - /* If mesage type is confirmable, save it to list to wait for reply */ - if (coap_header_ptr->msg_type == COAP_MSG_TYPE_CONFIRMABLE) { - if (message_description == SN_NSDL_MSG_REGISTER) { - handle->register_msg_id = coap_header_ptr->msg_id; - handle->register_msg_len = coap_header_len; - } - else if (message_description == SN_NSDL_MSG_UNREGISTER) { - handle->unregister_msg_id = coap_header_ptr->msg_id; - } - else if (message_description == SN_NSDL_MSG_UPDATE) { - handle->update_register_msg_id = coap_header_ptr->msg_id; - handle->update_register_msg_len = coap_header_len; - } - else if (message_description == SN_NSDL_MSG_BOOTSTRAP) { - handle->bootstrap_msg_id = coap_header_ptr->msg_id; - } - } - - handle->sn_nsdl_tx_callback(handle, SN_NSDL_PROTOCOL_COAP, coap_message_ptr, coap_message_len, dst_addr_ptr); - handle->sn_nsdl_free(coap_message_ptr); - - return coap_header_ptr->msg_id; -} - -/** - * \fn static void sn_nsdl_resolve_nsp_address(struct nsdl_s *handle) - * - * \brief Resolves NSP server address. - * - * \param *handle Pointer to nsdl-library handle - * \note Application must set NSP address with set_nsp_address - */ -static void sn_nsdl_resolve_nsp_address(struct nsdl_s *handle) -{ - /* Local variables */ - if (!handle->nsp_address_ptr) { - //allocate only if previously not allocated - handle->nsp_address_ptr = handle->sn_nsdl_alloc(sizeof(sn_nsdl_oma_server_info_t)); - } - - if (handle->nsp_address_ptr) { - handle->nsp_address_ptr->omalw_server_security = SEC_NOT_SET; - handle->nsp_address_ptr->omalw_address_ptr = handle->sn_nsdl_alloc(sizeof(sn_nsdl_addr_s)); - if (handle->nsp_address_ptr->omalw_address_ptr) { - memset(handle->nsp_address_ptr->omalw_address_ptr, 0, sizeof(sn_nsdl_addr_s)); - handle->nsp_address_ptr->omalw_address_ptr->type = SN_NSDL_ADDRESS_TYPE_NONE; - } - } -} - -/** - * \fn int8_t sn_nsdl_build_registration_body(struct nsdl_s *handle, sn_coap_hdr_s *message_ptr, uint8_t updating_registeration) - * - * \brief To build GRS resources to registration message payload - * \param *handle Pointer to nsdl-library handle - * \param *message_ptr Pointer to CoAP message header - * - * \return SN_NSDL_SUCCESS = 0, Failed = -1 - */ -int8_t sn_nsdl_build_registration_body(struct nsdl_s *handle, sn_coap_hdr_s *message_ptr, uint8_t updating_registeration) -{ - tr_debug("sn_nsdl_build_registration_body"); - /* Local variables */ - uint8_t *temp_ptr; - sn_nsdl_dynamic_resource_parameters_s *resource_temp_ptr; - - /* Calculate needed memory and allocate */ - int8_t error = 0; - uint16_t msg_len = sn_nsdl_calculate_registration_body_size(handle, updating_registeration, &error); - if (SN_NSDL_FAILURE == error) { - return error; - } - - if (!msg_len) { - return SN_NSDL_SUCCESS; - } else { - message_ptr->payload_len = msg_len; - } - tr_debug("sn_nsdl_build_registration_body - body size: [%d]", message_ptr->payload_len); - message_ptr->payload_ptr = handle->sn_nsdl_alloc(message_ptr->payload_len); - if (!message_ptr->payload_ptr) { - return SN_NSDL_FAILURE; - } - - /* Build message */ - temp_ptr = message_ptr->payload_ptr; - - resource_temp_ptr = sn_grs_get_first_resource(handle->grs); - - /* Loop trough all resources */ - while (resource_temp_ptr) { - /* if resource needs to be registered */ - if (resource_temp_ptr->publish_uri) { - if (updating_registeration && resource_temp_ptr->registered == SN_NDSL_RESOURCE_REGISTERED) { - resource_temp_ptr = sn_grs_get_next_resource(handle->grs, resource_temp_ptr); - continue; - } else { - resource_temp_ptr->registered = SN_NDSL_RESOURCE_REGISTERED; - } - - /* If not first resource, add '.' to separator */ - if (temp_ptr != message_ptr->payload_ptr) { - *temp_ptr++ = ','; - } - - *temp_ptr++ = '<'; - *temp_ptr++ = '/'; - memcpy(temp_ptr, - resource_temp_ptr->static_resource_parameters->path, - resource_temp_ptr->static_resource_parameters->pathlen); - temp_ptr += resource_temp_ptr->static_resource_parameters->pathlen; - *temp_ptr++ = '>'; - - /* Resource attributes */ - size_t resource_type_len = 0; - if (resource_temp_ptr->static_resource_parameters->resource_type_ptr) { - resource_type_len = strlen(resource_temp_ptr->static_resource_parameters->resource_type_ptr); - } - if (resource_type_len) { - *temp_ptr++ = ';'; - memcpy(temp_ptr, resource_type_parameter, RT_PARAMETER_LEN); - temp_ptr += RT_PARAMETER_LEN; - *temp_ptr++ = '"'; - memcpy(temp_ptr, - resource_temp_ptr->static_resource_parameters->resource_type_ptr, - resource_type_len); - temp_ptr += resource_type_len; - *temp_ptr++ = '"'; - } - - size_t interface_description_len = 0; - if (resource_temp_ptr->static_resource_parameters->interface_description_ptr) { - interface_description_len = strlen(resource_temp_ptr->static_resource_parameters->interface_description_ptr); - } - - if (interface_description_len) { - *temp_ptr++ = ';'; - memcpy(temp_ptr, if_description_parameter, IF_PARAMETER_LEN); - temp_ptr += IF_PARAMETER_LEN; - *temp_ptr++ = '"'; - memcpy(temp_ptr, - resource_temp_ptr->static_resource_parameters->interface_description_ptr, - interface_description_len); - temp_ptr += interface_description_len; - *temp_ptr++ = '"'; - } - - if (resource_temp_ptr->coap_content_type != 0) { - *temp_ptr++ = ';'; - memcpy(temp_ptr, coap_con_type_parameter, COAP_CON_PARAMETER_LEN); - temp_ptr += COAP_CON_PARAMETER_LEN; - *temp_ptr++ = '"'; - temp_ptr = sn_nsdl_itoa(temp_ptr, - resource_temp_ptr->coap_content_type); - *temp_ptr++ = '"'; - } - - /* ;obs */ - // This needs to be re-visited and may be need an API for maganging obs value for different server implementation -#ifndef COAP_DISABLE_OBS_FEATURE - if (resource_temp_ptr->observable) { - *temp_ptr++ = ';'; - memcpy(temp_ptr, obs_parameter, OBS_PARAMETER_LEN); - temp_ptr += OBS_PARAMETER_LEN; - } -#endif - } - resource_temp_ptr = sn_grs_get_next_resource(handle->grs, resource_temp_ptr); - } - return SN_NSDL_SUCCESS; -} - -/** - * \fn static uint16_t sn_nsdl_calculate_registration_body_size(struct nsdl_s *handle, uint8_t updating_registeration, int8_t *error) - * - * - * \brief Calculates registration message payload size - * \param *handle Pointer to nsdl-library handle - * \param *updating_registeration Pointer to list of GRS resources - * \param *error Error code, SN_NSDL_SUCCESS or SN_NSDL_FAILURE - * - * \return Needed payload size - */ -static uint16_t sn_nsdl_calculate_registration_body_size(struct nsdl_s *handle, uint8_t updating_registeration, int8_t *error) -{ - tr_debug("sn_nsdl_calculate_registration_body_size"); - /* Local variables */ - uint16_t return_value = 0; - *error = SN_NSDL_SUCCESS; - const sn_nsdl_dynamic_resource_parameters_s *resource_temp_ptr; - - /* check pointer */ - resource_temp_ptr = sn_grs_get_first_resource(handle->grs); - - while (resource_temp_ptr) { - if (resource_temp_ptr->publish_uri) { - if (updating_registeration && resource_temp_ptr->registered == SN_NDSL_RESOURCE_REGISTERED) { - resource_temp_ptr = sn_grs_get_next_resource(handle->grs, resource_temp_ptr); - continue; - } - /* If not first resource, then '.' will be added */ - if (return_value) { - if (sn_nsdl_check_uint_overflow(return_value, 1, 0)) { - return_value++; - } else { - *error = SN_NSDL_FAILURE; - break; - } - } - - /* Count length for the resource path */ - if (sn_nsdl_check_uint_overflow(return_value, - 3, - resource_temp_ptr->static_resource_parameters->pathlen)) { - return_value += (3 + resource_temp_ptr->static_resource_parameters->pathlen); - } else { - *error = SN_NSDL_FAILURE; - break; - } - - /* Count lengths of the attributes */ - - /* Resource type parameter */ - size_t resource_type_len = 0; - if (resource_temp_ptr->static_resource_parameters->resource_type_ptr) { - resource_type_len = strlen(resource_temp_ptr->static_resource_parameters->resource_type_ptr); - } - - if (resource_type_len) { - /* ;rt="restype" */ - if (sn_nsdl_check_uint_overflow(return_value, - 6, - resource_type_len)) { - return_value += (6 + resource_type_len); - } else { - *error = SN_NSDL_FAILURE; - break; - } - } - - /* Interface description parameter */ - size_t interface_description_len = 0; - if (resource_temp_ptr->static_resource_parameters->interface_description_ptr) { - interface_description_len = strlen(resource_temp_ptr->static_resource_parameters->interface_description_ptr); - } - if (interface_description_len) { - /* ;if="iftype" */ - if (sn_nsdl_check_uint_overflow(return_value, - 6, - interface_description_len)) { - return_value += (6 + interface_description_len); - } else { - *error = SN_NSDL_FAILURE; - break; - } - } - - if (resource_temp_ptr->coap_content_type != 0) { - /* ;if="content" */ - uint8_t len = sn_nsdl_itoa_len(resource_temp_ptr->coap_content_type); - if (sn_nsdl_check_uint_overflow(return_value, 6, len)) { - return_value += (6 + len); - } else { - *error = SN_NSDL_FAILURE; - break; - } - } -#ifndef COAP_DISABLE_OBS_FEATURE - // This needs to be re-visited and may be need an API for maganging obs value for different server implementation - if (resource_temp_ptr->observable) { - if (sn_nsdl_check_uint_overflow(return_value, 4, 0)) { - return_value += 4; - } else { - *error = SN_NSDL_FAILURE; - break; - } - } -#endif - } - resource_temp_ptr = sn_grs_get_next_resource(handle->grs, resource_temp_ptr); - } - return return_value; -} - -/** - * \fn static uint8_t sn_nsdl_calculate_uri_query_option_len(sn_nsdl_ep_parameters_s *endpoint_info_ptr, uint8_t msg_type) - * - * - * \brief Calculates needed uri query option length - * - * \param *endpoint_info_ptr Pointer to endpoint info structure - * \param msg_type Message type - * - * \return number of parameters in uri query - */ -static uint8_t sn_nsdl_calculate_uri_query_option_len(sn_nsdl_ep_parameters_s *endpoint_info_ptr, uint8_t msg_type) -{ - uint8_t return_value = 0; - uint8_t number_of_parameters = 0; - - - if ((endpoint_info_ptr->endpoint_name_len != 0) && (msg_type == SN_NSDL_EP_REGISTER_MESSAGE) && endpoint_info_ptr->endpoint_name_ptr != 0) { - return_value += endpoint_info_ptr->endpoint_name_len; - return_value += EP_NAME_PARAMETERS_LEN; //ep= - number_of_parameters++; - } - - if ((endpoint_info_ptr->type_len != 0) && (msg_type == SN_NSDL_EP_REGISTER_MESSAGE) && (endpoint_info_ptr->type_ptr != 0)) { - return_value += endpoint_info_ptr->type_len; - return_value += ET_PARAMETER_LEN; //et= - number_of_parameters++; - } - - if ((endpoint_info_ptr->lifetime_len != 0) && (endpoint_info_ptr->lifetime_ptr != 0)) { - return_value += endpoint_info_ptr->lifetime_len; - return_value += LT_PARAMETER_LEN; //lt= - number_of_parameters++; - } - - if ((endpoint_info_ptr->domain_name_len != 0) && (msg_type == SN_NSDL_EP_REGISTER_MESSAGE) && (endpoint_info_ptr->domain_name_ptr != 0)) { - return_value += endpoint_info_ptr->domain_name_len; - return_value += DOMAIN_PARAMETER_LEN; //d= - number_of_parameters++; - } - - if (((endpoint_info_ptr->binding_and_mode & 0x04) || (endpoint_info_ptr->binding_and_mode & 0x01)) && (msg_type == SN_NSDL_EP_REGISTER_MESSAGE)) { - return_value += BS_QUEUE_MODE_PARAMATER_LEN; - - if (endpoint_info_ptr->binding_and_mode & 0x01) { - return_value++; - } - if (endpoint_info_ptr->binding_and_mode & 0x04) { - return_value++; - } - if ((endpoint_info_ptr->binding_and_mode & 0x02) && ((endpoint_info_ptr->binding_and_mode & 0x04) || (endpoint_info_ptr->binding_and_mode & 0x01))) { - return_value++; - } - - number_of_parameters++; - } - - if (number_of_parameters != 0) { - return_value += (number_of_parameters - 1); - } - - return return_value; -} - -/** - * \fn static int8_t sn_nsdl_fill_uri_query_options(struct nsdl_s *handle, sn_nsdl_ep_parameters_s *parameter_ptr, sn_coap_hdr_s *source_msg_ptr, uint8_t msg_type) - * - * - * \brief Fills uri-query options to message header struct - * \param *handle Pointer to nsdl-library handle - * \param *parameter_ptr Pointer to endpoint parameters struct - * \param *source_msg_ptr Pointer to CoAP header struct - * \param msg_type Message type - * - * \return SN_NSDL_SUCCESS = 0, Failed = -1 - */ -static int8_t sn_nsdl_fill_uri_query_options(struct nsdl_s *handle, sn_nsdl_ep_parameters_s *parameter_ptr, sn_coap_hdr_s *source_msg_ptr, uint8_t msg_type) -{ - uint8_t *temp_ptr = NULL; - if( !validateParameters(parameter_ptr) ){ - return SN_NSDL_FAILURE; - } - source_msg_ptr->options_list_ptr->uri_query_len = sn_nsdl_calculate_uri_query_option_len(parameter_ptr, msg_type); - if (source_msg_ptr->options_list_ptr->uri_query_len == 0) { - return 0; - } - - source_msg_ptr->options_list_ptr->uri_query_ptr = handle->sn_nsdl_alloc(source_msg_ptr->options_list_ptr->uri_query_len); - - if (source_msg_ptr->options_list_ptr->uri_query_ptr == NULL) { - return SN_NSDL_FAILURE; - } - memset(source_msg_ptr->options_list_ptr->uri_query_ptr,0,source_msg_ptr->options_list_ptr->uri_query_len); - - temp_ptr = source_msg_ptr->options_list_ptr->uri_query_ptr; - - /******************************************************/ - /* If endpoint name is configured, fill needed fields */ - /******************************************************/ - - if ((parameter_ptr->endpoint_name_len != 0) && (parameter_ptr->endpoint_name_ptr != 0) && (msg_type == SN_NSDL_EP_REGISTER_MESSAGE)) { - /* fill endpoint name, first ?ep=, then endpoint name */ - memcpy(temp_ptr, ep_name_parameter_string, sizeof(ep_name_parameter_string)); - temp_ptr += EP_NAME_PARAMETERS_LEN; - memcpy(temp_ptr, parameter_ptr->endpoint_name_ptr, parameter_ptr->endpoint_name_len); - temp_ptr += parameter_ptr->endpoint_name_len; - } - - /******************************************************/ - /* If endpoint type is configured, fill needed fields */ - /******************************************************/ - - if ((parameter_ptr->type_len != 0) && (parameter_ptr->type_ptr != 0) && (msg_type == SN_NSDL_EP_REGISTER_MESSAGE)) { - if (temp_ptr != source_msg_ptr->options_list_ptr->uri_query_ptr) { - *temp_ptr++ = '&'; - } - - memcpy(temp_ptr, et_parameter, sizeof(et_parameter)); - temp_ptr += ET_PARAMETER_LEN; - memcpy(temp_ptr, parameter_ptr->type_ptr, parameter_ptr->type_len); - temp_ptr += parameter_ptr->type_len; - } - - - /******************************************************/ - /* If lifetime is configured, fill needed fields */ - /******************************************************/ - - if ((parameter_ptr->lifetime_len != 0) && (parameter_ptr->lifetime_ptr != 0)) { - if (temp_ptr != source_msg_ptr->options_list_ptr->uri_query_ptr) { - *temp_ptr++ = '&'; - } - - memcpy(temp_ptr, ep_lifetime_parameter, sizeof(ep_lifetime_parameter)); - temp_ptr += LT_PARAMETER_LEN; - memcpy(temp_ptr, parameter_ptr->lifetime_ptr, parameter_ptr->lifetime_len); - temp_ptr += parameter_ptr->lifetime_len; - } - - /******************************************************/ - /* If domain is configured, fill needed fields */ - /******************************************************/ - - if ((parameter_ptr->domain_name_len != 0) && (parameter_ptr->domain_name_ptr != 0) && (msg_type == SN_NSDL_EP_REGISTER_MESSAGE)) { - if (temp_ptr != source_msg_ptr->options_list_ptr->uri_query_ptr) { - *temp_ptr++ = '&'; - } - - memcpy(temp_ptr, ep_domain_parameter, sizeof(ep_domain_parameter)); - temp_ptr += DOMAIN_PARAMETER_LEN; - memcpy(temp_ptr, parameter_ptr->domain_name_ptr, parameter_ptr->domain_name_len); - temp_ptr += parameter_ptr->domain_name_len; - } - - /******************************************************/ - /* If queue-mode is configured, fill needed fields */ - /******************************************************/ - - if (((parameter_ptr->binding_and_mode & 0x01) || (parameter_ptr->binding_and_mode & 0x04)) && (msg_type == SN_NSDL_EP_REGISTER_MESSAGE)) { - if (temp_ptr != source_msg_ptr->options_list_ptr->uri_query_ptr) { - *temp_ptr++ = '&'; - } - - memcpy(temp_ptr, bs_queue_mode, sizeof(bs_queue_mode)); - temp_ptr += BS_QUEUE_MODE_PARAMATER_LEN; - - if (parameter_ptr->binding_and_mode & 0x01) { - *temp_ptr++ = 'U'; - if (parameter_ptr->binding_and_mode & 0x02) { - *temp_ptr++ = 'Q'; - } - } - - if (parameter_ptr->binding_and_mode & 0x04) { - *temp_ptr++ = 'S'; - if ((parameter_ptr->binding_and_mode & 0x02) && !(parameter_ptr->binding_and_mode & 0x01)) { - *temp_ptr++ = 'Q'; - } - } - } - - return SN_NSDL_SUCCESS; -} - -static bool validateParameters(sn_nsdl_ep_parameters_s *parameter_ptr) -{ - if( !validate( parameter_ptr->domain_name_ptr, parameter_ptr->domain_name_len, '&' ) ){ - return false; - } - - if( !validate( parameter_ptr->endpoint_name_ptr, parameter_ptr->endpoint_name_len, '&' ) ){ - return false; - } - - if( !validate( parameter_ptr->lifetime_ptr, parameter_ptr->lifetime_len, '&' ) ){ - return false; - } - - if( !validate( parameter_ptr->type_ptr, parameter_ptr->type_len, '&' ) ){ - return false; - } - return true; -} - -static bool validate(uint8_t* ptr, uint32_t len, char illegalChar) -{ - if( ptr ){ - for( uint32_t i=0; i < len; i++ ){ - if( ptr[i] == illegalChar ){ - return false; - } - } - } - return true; -} - -/** - * \fn static int8_t sn_nsdl_local_rx_function(struct nsdl_s *handle, sn_coap_hdr_s *coap_packet_ptr, sn_nsdl_addr_s *address_ptr) - * - * \brief If received message is reply for the message that NSDL has been sent, it is processed here. Else, packet will be sent to application. - * \param *handle Pointer to nsdl-library handle - * \param *coap_packet_ptr Pointer to received CoAP packet - * \param *address_ptr Pointer to source address struct - * - * \return SN_NSDL_SUCCESS = 0, Failed = -1 - */ -static int8_t sn_nsdl_local_rx_function(struct nsdl_s *handle, sn_coap_hdr_s *coap_packet_ptr, sn_nsdl_addr_s *address_ptr) -{ - if ((coap_packet_ptr == 0) || (address_ptr == 0)) { - return -1; - } - - bool is_reg_msg = false; - bool is_update_reg_msg = false; - bool is_unreg_msg = false; - if (coap_packet_ptr->msg_code == COAP_MSG_CODE_RESPONSE_CREATED) { - if (handle->grs->coap->sn_coap_block_data_size > 0) { - handle->register_msg_id += handle->register_msg_len / handle->grs->coap->sn_coap_block_data_size; - } - if (coap_packet_ptr->msg_id == handle->register_msg_id) { - handle->sn_nsdl_endpoint_registered = SN_NSDL_ENDPOINT_IS_REGISTERED; - is_reg_msg = true; - sn_grs_mark_resources_as_registered(handle); - if (sn_nsdl_resolve_ep_information(handle, coap_packet_ptr) != SN_NSDL_SUCCESS) { - return SN_NSDL_FAILURE; - } - } - } - - else if (coap_packet_ptr->msg_code == COAP_MSG_CODE_RESPONSE_CHANGED) { - if (handle->grs->coap->sn_coap_block_data_size > 0) { - handle->update_register_msg_id += handle->update_register_msg_len / handle->grs->coap->sn_coap_block_data_size; - } - if (coap_packet_ptr->msg_id == handle->update_register_msg_id) { - is_update_reg_msg = true; - } - } - - if (coap_packet_ptr->msg_id == handle->unregister_msg_id) { - is_unreg_msg = true; - if (coap_packet_ptr->msg_code == COAP_MSG_CODE_RESPONSE_DELETED) { - if (handle->ep_information_ptr->endpoint_name_ptr) { - handle->sn_nsdl_free(handle->ep_information_ptr->endpoint_name_ptr); - handle->ep_information_ptr->endpoint_name_ptr = 0; - handle->ep_information_ptr->endpoint_name_len = 0; - } - if (handle->ep_information_ptr->domain_name_ptr) { - handle->sn_nsdl_free(handle->ep_information_ptr->domain_name_ptr); - handle->ep_information_ptr->domain_name_ptr = 0; - handle->ep_information_ptr->domain_name_len = 0; - } - } - } - - /* No messages to wait for, or message was not response to our request */ - int ret = handle->sn_nsdl_rx_callback(handle, coap_packet_ptr, address_ptr); - if (is_reg_msg) { - handle->register_msg_id = 0; - handle->register_msg_len = 0; - } - else if (is_unreg_msg) { - handle->unregister_msg_id = 0; - } - else if (is_update_reg_msg) { - handle->update_register_msg_id = 0; - handle->update_register_msg_len = 0; - } - return ret; -} - -/** - * \fn static int8_t sn_nsdl_resolve_ep_information(struct nsdl_s *handle, sn_coap_hdr_s *coap_packet_ptr) - * - * - * \brief Resolves endpoint information from received CoAP message - * \param *handle Pointer to nsdl-library handle - * \param *coap_packet_ptr Pointer to received CoAP message - * - * \return SN_NSDL_SUCCESS = 0, Failed = -1 - */ -static int8_t sn_nsdl_resolve_ep_information(struct nsdl_s *handle, sn_coap_hdr_s *coap_packet_ptr) -{ - uint8_t *temp_ptr; - uint8_t parameter_count = 0; - uint16_t parameter_len = 0; - - if (!coap_packet_ptr || !coap_packet_ptr->options_list_ptr || - !coap_packet_ptr->options_list_ptr->location_path_ptr) { - return SN_NSDL_FAILURE; - } - - temp_ptr = coap_packet_ptr->options_list_ptr->location_path_ptr; - - while (temp_ptr <= (coap_packet_ptr->options_list_ptr->location_path_ptr + coap_packet_ptr->options_list_ptr->location_path_len)) { - - if ((temp_ptr == (coap_packet_ptr->options_list_ptr->location_path_ptr + coap_packet_ptr->options_list_ptr->location_path_len)) || (*temp_ptr == '/')) { - - parameter_count++; - if (parameter_count == 2) { - if (!handle->ep_information_ptr->domain_name_ptr) { - handle->ep_information_ptr->domain_name_len = parameter_len - 1; - handle->ep_information_ptr->domain_name_ptr = handle->sn_nsdl_alloc(handle->ep_information_ptr->domain_name_len); - if (!handle->ep_information_ptr->domain_name_ptr) { - return SN_NSDL_FAILURE; - } - memcpy(handle->ep_information_ptr->domain_name_ptr, temp_ptr - handle->ep_information_ptr->domain_name_len, handle->ep_information_ptr->domain_name_len); - } - - } - if (parameter_count == 3) { - if (!handle->ep_information_ptr->endpoint_name_ptr) { - handle->ep_information_ptr->endpoint_name_len = parameter_len - 1; - handle->ep_information_ptr->endpoint_name_ptr = handle->sn_nsdl_alloc(handle->ep_information_ptr->endpoint_name_len); - if (!handle->ep_information_ptr->endpoint_name_ptr) { - if (handle->ep_information_ptr->domain_name_ptr) { - handle->sn_nsdl_free(handle->ep_information_ptr->domain_name_ptr); - handle->ep_information_ptr->domain_name_ptr = NULL; - handle->ep_information_ptr->domain_name_len = 0; - } - - return SN_NSDL_FAILURE; - - } - memcpy(handle->ep_information_ptr->endpoint_name_ptr, temp_ptr - handle->ep_information_ptr->endpoint_name_len, handle->ep_information_ptr->endpoint_name_len); - } - } - parameter_len = 0; - } - parameter_len++; - temp_ptr++; - } - - - return SN_NSDL_SUCCESS; -} - -extern int8_t set_NSP_address(struct nsdl_s *handle, uint8_t *NSP_address, uint8_t address_length, uint16_t port, sn_nsdl_addr_type_e address_type) -{ - /* Check parameters and source pointers */ - if (!handle || !handle->nsp_address_ptr || !handle->nsp_address_ptr->omalw_address_ptr || !NSP_address) { - return SN_NSDL_FAILURE; - } - - handle->nsp_address_ptr->omalw_address_ptr->type = address_type; - handle->nsp_address_ptr->omalw_server_security = SEC_NOT_SET; - - if (handle->nsp_address_ptr->omalw_address_ptr->addr_ptr) { - handle->sn_nsdl_free(handle->nsp_address_ptr->omalw_address_ptr->addr_ptr); - } - - handle->nsp_address_ptr->omalw_address_ptr->addr_len = address_length; - - handle->nsp_address_ptr->omalw_address_ptr->addr_ptr = handle->sn_nsdl_alloc(handle->nsp_address_ptr->omalw_address_ptr->addr_len); - if (!handle->nsp_address_ptr->omalw_address_ptr->addr_ptr) { - return SN_NSDL_FAILURE; - } - - memcpy(handle->nsp_address_ptr->omalw_address_ptr->addr_ptr, NSP_address, handle->nsp_address_ptr->omalw_address_ptr->addr_len); - handle->nsp_address_ptr->omalw_address_ptr->port = port; - - return SN_NSDL_SUCCESS; -} - - -static uint8_t sn_nsdl_itoa_len(uint8_t value) -{ - uint8_t i = 0; - - do { - i++; - } while ((value /= 10) > 0); - - return i; -} - -static uint8_t *sn_nsdl_itoa(uint8_t *ptr, uint8_t value) -{ - - uint8_t start = 0; - uint8_t end = 0; - uint8_t i; - - i = 0; - - /* ITOA */ - do { - ptr[i++] = (value % 10) + '0'; - } while ((value /= 10) > 0); - - end = i - 1; - - /* reverse (part of ITOA) */ - while (start < end) { - uint8_t chr; - - chr = ptr[start]; - ptr[start] = ptr[end]; - ptr[end] = chr; - - start++; - end--; - - } - return (ptr + i); -} - -static int8_t set_endpoint_info(struct nsdl_s *handle, sn_nsdl_ep_parameters_s *endpoint_info_ptr) -{ - if (handle->ep_information_ptr->domain_name_ptr) { - handle->sn_nsdl_free(handle->ep_information_ptr->domain_name_ptr); - handle->ep_information_ptr->domain_name_ptr = 0; - handle->ep_information_ptr->domain_name_len = 0; - } - - if (handle->ep_information_ptr->endpoint_name_ptr) { - handle->sn_nsdl_free(handle->ep_information_ptr->endpoint_name_ptr); - handle->ep_information_ptr->endpoint_name_ptr = 0; - handle->ep_information_ptr->endpoint_name_len = 0; - } - - if (endpoint_info_ptr->domain_name_ptr && endpoint_info_ptr->domain_name_len) { - handle->ep_information_ptr->domain_name_ptr = handle->sn_nsdl_alloc(endpoint_info_ptr->domain_name_len); - - if (!handle->ep_information_ptr->domain_name_ptr) { - return -1; - } - - memcpy(handle->ep_information_ptr->domain_name_ptr, endpoint_info_ptr->domain_name_ptr, endpoint_info_ptr->domain_name_len); - handle->ep_information_ptr->domain_name_len = endpoint_info_ptr->domain_name_len; - } - - if (endpoint_info_ptr->endpoint_name_ptr && endpoint_info_ptr->endpoint_name_len) { - handle->ep_information_ptr->endpoint_name_ptr = handle->sn_nsdl_alloc(endpoint_info_ptr->endpoint_name_len); - - if (!handle->ep_information_ptr->endpoint_name_ptr) { - if (handle->ep_information_ptr->domain_name_ptr) { - handle->sn_nsdl_free(handle->ep_information_ptr->domain_name_ptr); - handle->ep_information_ptr->domain_name_ptr = 0; - handle->ep_information_ptr->domain_name_len = 0; - } - return -1; - } - - memcpy(handle->ep_information_ptr->endpoint_name_ptr, endpoint_info_ptr->endpoint_name_ptr, endpoint_info_ptr->endpoint_name_len); - handle->ep_information_ptr->endpoint_name_len = endpoint_info_ptr->endpoint_name_len; - } - - handle->ep_information_ptr->binding_and_mode = endpoint_info_ptr->binding_and_mode; - handle->ep_information_ptr->ds_register_mode = endpoint_info_ptr->ds_register_mode; - - handle->ep_information_ptr->location_ptr = 0; - handle->ep_information_ptr->location_len = 0; - - return 0; -} - -/* Wrapper */ -sn_grs_resource_list_s *sn_nsdl_list_resource(struct nsdl_s *handle, uint16_t pathlen, uint8_t *path) -{ - /* Check parameters */ - if (handle == NULL) { - return NULL; - } - - return sn_grs_list_resource(handle->grs, pathlen, path); -} - -void sn_nsdl_free_resource_list(struct nsdl_s *handle, sn_grs_resource_list_s *list) -{ - /* Check parameters */ - if (handle == NULL) { - return; - } - - sn_grs_free_resource_list(handle->grs, list); -} - -#ifndef MEMORY_OPTIMIZED_API -extern int8_t sn_nsdl_update_resource(struct nsdl_s *handle, sn_nsdl_dynamic_resource_parameters_s *res) -{ - /* Check parameters */ - if (handle == NULL) { - return SN_NSDL_FAILURE; - } - - return sn_grs_update_resource(handle->grs, res); -} - -extern int8_t sn_nsdl_create_resource(struct nsdl_s *handle, sn_nsdl_dynamic_resource_parameters_s *res) -{ - /* Check parameters */ - if (handle == NULL) { - return SN_NSDL_FAILURE; - } - - return sn_grs_create_resource(handle->grs, res); -} -#endif - -extern int8_t sn_nsdl_send_coap_message(struct nsdl_s *handle, sn_nsdl_addr_s *address_ptr, sn_coap_hdr_s *coap_hdr_ptr) -{ - /* Check parameters */ - if (handle == NULL) { - return SN_NSDL_FAILURE; - } - - return sn_grs_send_coap_message(handle, address_ptr, coap_hdr_ptr); -} - -extern int8_t sn_nsdl_put_resource(struct nsdl_s *handle, sn_nsdl_dynamic_resource_parameters_s *res) -{ - if (!handle) { - return SN_NSDL_FAILURE; - } - - return sn_grs_put_resource(handle->grs, res); -} - -extern int8_t sn_nsdl_pop_resource(struct nsdl_s *handle, sn_nsdl_dynamic_resource_parameters_s *res) -{ - if (!handle) { - return SN_NSDL_FAILURE; - } - - return sn_grs_pop_resource(handle->grs, res); -} - -extern int8_t sn_nsdl_delete_resource(struct nsdl_s *handle, uint16_t pathlen, uint8_t *path) -{ - /* Check parameters */ - if (handle == NULL) { - return SN_NSDL_FAILURE; - } - - return sn_grs_delete_resource(handle->grs, pathlen, path); -} -extern const sn_nsdl_dynamic_resource_parameters_s *sn_nsdl_get_first_resource(struct nsdl_s *handle) -{ - /* Check parameters */ - if (handle == NULL) { - return NULL; - } - - return sn_grs_get_first_resource(handle->grs); -} -extern const sn_nsdl_dynamic_resource_parameters_s *sn_nsdl_get_next_resource(struct nsdl_s *handle, const sn_nsdl_dynamic_resource_parameters_s *resource) -{ - /* Check parameters */ - if (handle == NULL) { - return NULL; - } - - return sn_grs_get_next_resource(handle->grs, resource); -} - -extern sn_coap_hdr_s *sn_nsdl_build_response(struct nsdl_s *handle, sn_coap_hdr_s *coap_packet_ptr, uint8_t msg_code) -{ - if (handle == NULL) { - return NULL; - } - - return sn_coap_build_response(handle->grs->coap, coap_packet_ptr, msg_code); -} - -extern sn_coap_options_list_s *sn_nsdl_alloc_options_list(struct nsdl_s *handle, sn_coap_hdr_s *coap_msg_ptr) -{ - if (handle == NULL || coap_msg_ptr == NULL) { - return NULL; - } - return sn_coap_parser_alloc_options(handle->grs->coap, coap_msg_ptr); -} - -extern void sn_nsdl_release_allocated_coap_msg_mem(struct nsdl_s *handle, sn_coap_hdr_s *freed_coap_msg_ptr) -{ - if (handle == NULL) { - return; - } - - sn_coap_parser_release_allocated_coap_msg_mem(handle->grs->coap, freed_coap_msg_ptr); -} - -extern int8_t sn_nsdl_set_retransmission_parameters(struct nsdl_s *handle, - uint8_t resending_count, uint8_t resending_interval) -{ - if (handle == NULL) { - return SN_NSDL_FAILURE; - } - return sn_coap_protocol_set_retransmission_parameters(handle->grs->coap, - resending_count,resending_interval); -} - -extern int8_t sn_nsdl_set_retransmission_buffer(struct nsdl_s *handle, - uint8_t buffer_size_messages, uint16_t buffer_size_bytes) -{ - if (handle == NULL) { - return SN_NSDL_FAILURE; - } - return sn_coap_protocol_set_retransmission_buffer(handle->grs->coap, - buffer_size_messages, buffer_size_bytes); -} - -extern int8_t sn_nsdl_set_block_size(struct nsdl_s *handle, uint16_t block_size) -{ - if (handle == NULL) { - return SN_NSDL_FAILURE; - } - return sn_coap_protocol_set_block_size(handle->grs->coap, block_size); -} - -extern int8_t sn_nsdl_set_duplicate_buffer_size(struct nsdl_s *handle, uint8_t message_count) -{ - if (handle == NULL) { - return SN_NSDL_FAILURE; - } - return sn_coap_protocol_set_duplicate_buffer_size(handle->grs->coap, message_count); -} - -bool sn_nsdl_check_uint_overflow(uint16_t resource_size, uint16_t param_a, uint16_t param_b) -{ - uint16_t first_check = param_a + param_b; - if (first_check < param_b) { - return false; - } else { - uint16_t total = resource_size + first_check; - if (total < first_check) { - return false; - } else { - return true; - } - } -} - -extern int8_t sn_nsdl_set_context(struct nsdl_s * const handle, void * const context) -{ - if (handle == NULL) { - return SN_NSDL_FAILURE; - } - handle->context = context; - return SN_NSDL_SUCCESS; -} - -extern void *sn_nsdl_get_context(const struct nsdl_s * const handle) -{ - if (handle == NULL) { - return NULL; - } - return handle->context; -} - -#endif - diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/test/multithread-linux-test/CMakeLists.txt b/features/FEATURE_COMMON_PAL/mbed-client-c/test/multithread-linux-test/CMakeLists.txt deleted file mode 100644 index ea8f375813..0000000000 --- a/features/FEATURE_COMMON_PAL/mbed-client-c/test/multithread-linux-test/CMakeLists.txt +++ /dev/null @@ -1,15 +0,0 @@ -# NB external pthreads dependency!! -find_package (Threads) -add_executable(multithread-linux-test - "main.c" - "mbed_client.c" -) -target_link_libraries(multithread-linux-test - mbed-client-c -) - -target_link_libraries(multithread-linux-test - ${CMAKE_THREAD_LIBS_INIT} -) - - diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/test/multithread-linux-test/arguments.h b/features/FEATURE_COMMON_PAL/mbed-client-c/test/multithread-linux-test/arguments.h deleted file mode 100644 index de133d4263..0000000000 --- a/features/FEATURE_COMMON_PAL/mbed-client-c/test/multithread-linux-test/arguments.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2015 ARM Limited. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 - * Licensed under the Apache License, Version 2.0 (the License); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef _ARGUMENTS_ -#define _ARGUMENTS_ -#include "resource_generation_help.h" - -#ifdef MACOSX -// ---------------------------------------- -// Mac OS X -#ifdef __DARWIN_UNIX03 -typedef unsigned short port_t; -#else -#include -#endif // __DARWIN_UNIX03 -typedef unsigned long ipaddr_t; -#endif - -/* Argument variables */ -uint16_t arg_port, arg_sport, arg_dport; //0-65535 -char arg_dst[64]; - -#endif /* _ARGUMENTS_ */ - - diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/test/multithread-linux-test/main.c b/features/FEATURE_COMMON_PAL/mbed-client-c/test/multithread-linux-test/main.c deleted file mode 100644 index f03a893dc3..0000000000 --- a/features/FEATURE_COMMON_PAL/mbed-client-c/test/multithread-linux-test/main.c +++ /dev/null @@ -1,164 +0,0 @@ -/* - * Copyright (c) 2015 ARM Limited. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 - * Licensed under the Apache License, Version 2.0 (the License); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include -#include -#include "sn_nsdl.h" -#include "sn_coap_header.h" -#include "sn_coap_protocol.h" -#include "sn_nsdl_lib.h" -#include "ns_list.h" -#include "arguments.h" - -#define NUMTHREADS 10 - -extern int register_endpoint(int port, sn_nsdl_ep_parameters_s *endpoint_ptr, int thread_id); -void stop_pgm(char *s) -{ - perror(s); - exit(1); -} - -void *own_alloc(uint16_t size) -{ - if(size) { - return malloc(size); - } - else { - return 0; - } -} - -void own_free(void *ptr) -{ - free(ptr); -} - -void arg_init(void) -{ - memcpy(arg_dst,"::1",32); //default localhost - arg_sport=5683; - arg_dport=5683; -} - - -void usage_show(void) -{ - printf("Usage:\n\n" - - "multithread-linux-test [-d 127.0.0.1] \n" - "-d NSP IPv4 address (default = ::1)\n" - "-dp NSP port number (default = 5683)\n"); -} - -/* function to be executed by the new thread */ -void* create_endpoint(void *arg) -{ - int index = *((int *) arg); - int port = 8100 + index; - sn_nsdl_ep_parameters_s *endpoint_ptr; - uint8_t endpoint_type[] = {"type"}; - uint8_t lifetime_ptr[] = {"120"}; - char str[10]; - sprintf(str, "THREAD_%d", index); - endpoint_ptr = own_alloc(sizeof(sn_nsdl_ep_parameters_s)); - if(endpoint_ptr) - { - memset(endpoint_ptr, 0, sizeof(sn_nsdl_ep_parameters_s)); - endpoint_ptr->endpoint_name_ptr = str; - endpoint_ptr->endpoint_name_len = strlen(str); - endpoint_ptr->type_ptr = endpoint_type; - endpoint_ptr->type_len = sizeof(endpoint_type)-1; - endpoint_ptr->lifetime_ptr = lifetime_ptr; - endpoint_ptr->lifetime_len = sizeof(lifetime_ptr)-1; - } - register_endpoint(port, endpoint_ptr, index); - if(endpoint_ptr) { - own_free(endpoint_ptr); - endpoint_ptr = 0; - } -} - -int main(int argc, char **argv) -{ - uint8_t i; - arg_init(); - - if (argc<1) - { - usage_show(); - } - else - { - i=1; //argv[0] is the command itself - - argc--; //get the real number of arguments - while (i<=argc) - { - //check arguments - if (!(strcmp("-h",argv[i]))) - { - usage_show(); - stop_pgm(""); - } - else if (!(strcmp("-d",argv[i]))) - { - if (i++==argc) stop_pgm("Argument missed for option -d\n"); - memcpy(arg_dst,argv[i],strlen((const char*)argv[i])+1); - i++; - continue; - } - else if (!(strcmp("-p",argv[i]))) - { - if (i++==argc) stop_pgm("Argument missed for option -p\n"); - arg_port=atoi(argv[i]); - i++; - continue; - } - else if (!(strcmp("-dp",argv[i]))) - { - if (i++==argc) stop_pgm("Argument missed for option -dp\n"); - arg_dport=atoi(argv[i]); - i++; - continue; - } - else - { - usage_show(); - stop_pgm("\n--- Argument error ---\n"); - } - - } - } - - pthread_t threads[NUMTHREADS]; - for (int index = 0; index < NUMTHREADS; index++) { - pthread_create(&threads[index], NULL, create_endpoint, (void *) &index); - sleep(1); - } - - for (int i = 0; i < NUMTHREADS; i) { - pthread_join(threads[i], NULL); - } - exit(0); -} - - - diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/test/multithread-linux-test/mbed_client.c b/features/FEATURE_COMMON_PAL/mbed-client-c/test/multithread-linux-test/mbed_client.c deleted file mode 100644 index a3f76704cb..0000000000 --- a/features/FEATURE_COMMON_PAL/mbed-client-c/test/multithread-linux-test/mbed_client.c +++ /dev/null @@ -1,517 +0,0 @@ -/* - * Copyright (c) 2015 ARM Limited. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 - * Licensed under the Apache License, Version 2.0 (the License); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include -#include -#include /* For SIGIGN and SIGINT */ -#include -#include -#include -#include "sn_nsdl.h" -#include "sn_coap_header.h" -#include "sn_coap_protocol.h" -#include "sn_nsdl_lib.h" -#include "ns_list.h" -#include "sn_grs.h" -#include "arguments.h" -#include "resource_generation_help.h" - -#define BUFLEN 1024 - -/* Resource paths and values */ -static uint8_t res_manufacturer[] = {"3/0/0"}; -static uint8_t res_manufacturer_val[] = {"ARM"}; -static uint8_t res_model_number[] = {"3/0/1"}; -static uint8_t res_model_number_val[] = {"1.00"}; - -static uint8_t res_temp[] = {"3303/0/temp"}; -static uint8_t res_type_test[] = {"t"}; - -struct thread_data_struct { - struct nsdl_s *handle; - struct sockaddr_in sa_dst; - struct sockaddr_in sa_src; - int sock_server; - socklen_t slen_sa_dst; - int thread_id; - sn_nsdl_ep_parameters_s *endpoint_ptr; - sn_nsdl_addr_s received_packet_address; - ns_list_link_t link; - bool registered; - uint32_t ns_system_time; - uint8_t delayed_token[8]; - uint8_t delayed_token_len; - sn_coap_msg_type_e delayed_msg_type; - uint8_t delayed_response_cnt; - uint8_t res_temp_val[16]; -}; -typedef struct thread_data_struct thread_data_struct_s; - -extern void stop_pgm(); -extern void *own_alloc(uint16_t size); -extern void own_free(void* ptr); - -/* Function templates */ -int register_endpoint(int port, sn_nsdl_ep_parameters_s *endpoint, int thread_id); -uint8_t tx_function(struct nsdl_s *handle, sn_nsdl_capab_e protocol , uint8_t *data, uint16_t len, sn_nsdl_addr_s *address); -uint8_t rx_function(struct nsdl_s *handle, sn_coap_hdr_s *coap_header, sn_nsdl_addr_s *address); -static void ctrl_c_handle_function(); -typedef void (*signalhandler_t)(int); -void coap_exec_poll_function(int thread_id); -int16_t receive_msg(thread_data_struct_s *data_item, uint8_t *buf); -uint8_t general_resource_cb(struct nsdl_s *handle, sn_coap_hdr_s *coap_ptr, sn_nsdl_addr_s *address, sn_nsdl_capab_e protocol); -int8_t compare_uripaths(sn_coap_hdr_s *coap_header, const uint8_t *uri_path_to_compare); -void send_ack(struct nsdl_s *handle, sn_coap_hdr_s *received_coap_ptr, sn_nsdl_addr_s *address); - -/* CoAP related globals*/ -uint8_t text_plain = COAP_CT_TEXT_PLAIN; -uint8_t link_format = COAP_CT_LINK_FORMAT; - -/* Resource related globals*/ -uint8_t *reg_location = 0; -int8_t reg_location_len; - -/* List containing thread specific data */ -typedef NS_LIST_HEAD(thread_data_struct_s, link) thread_data_struct_t; -static thread_data_struct_t NS_LIST_NAME_INIT(data_list); - -/*****************************************************/ -/* This is called from main to start the CoAP server */ -/*****************************************************/ -int register_endpoint(int port, sn_nsdl_ep_parameters_s *endpoint, int thread_id) -{ - printf("Register endpoint, port: %d, thread id: %d\n", port, thread_id); - thread_data_struct_s *data_item = NULL; - uint8_t nsp_addr[16]; - pthread_t coap_exec_thread; - uint8_t received_address[4]; - uint8_t buf[BUFLEN]; - int16_t rcv_size=0; - - data_item = malloc(sizeof(thread_data_struct_s)); - data_item->slen_sa_dst = sizeof(data_item->sa_dst); - memset(&data_item->received_packet_address, 0, sizeof(sn_nsdl_addr_s)); - memset(&data_item->sa_dst, 0, sizeof(struct sockaddr_in)); - memset(&data_item->sa_src, 0, sizeof(struct sockaddr_in)); - data_item->received_packet_address.addr_ptr = received_address; - data_item->endpoint_ptr = endpoint; - data_item->registered = false; - data_item->thread_id = thread_id; - data_item->ns_system_time = 1; - data_item->delayed_token_len = 0; - data_item->delayed_response_cnt = 0; - - /* Initial values for temperature */ - char temp[10]; - if (thread_id >= 9) { - sprintf(temp, "25.%d", thread_id); - } else { - sprintf(temp, "2%d.0", thread_id); - } - strcpy(data_item->res_temp_val,temp); - - sn_nsdl_resource_info_s *resource_ptr = 0; - - if (signal(SIGINT, (signalhandler_t)ctrl_c_handle_function) == SIG_ERR) { - printf("Error with SIGINT: %s\n", strerror(errno)); - return -1; - } - - /* Open the server socket*/ - if ((data_item->sock_server=socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) ==-1 ) { - stop_pgm("socket() error"); - } - - /* Init the listen port addr*/ - memset((char *) &data_item->sa_src, 0, sizeof(data_item->sa_src)); - data_item->sa_src.sin_family = AF_INET; - data_item->sa_src.sin_port = htons(port); - - /* Listen to the port */ - data_item->sa_src.sin_addr.s_addr = INADDR_ANY; - if (bind(data_item->sock_server, (struct sockaddr *) &data_item->sa_src, sizeof(data_item->sa_src) ) == -1) { - stop_pgm("bind() error"); - } - - data_item->handle = sn_nsdl_init(&tx_function, &rx_function, &own_alloc, &own_free); - inet_pton(AF_INET, arg_dst, &nsp_addr); - - set_NSP_address(data_item->handle, nsp_addr, arg_dport, SN_NSDL_ADDRESS_TYPE_IPV4); - ns_list_add_to_start(&data_list, data_item); - - pthread_create(&coap_exec_thread, NULL, (void *)coap_exec_poll_function, data_item->thread_id); - - resource_ptr = own_alloc(sizeof(sn_nsdl_resource_info_s)); - if(!resource_ptr) { - return 0; - } - - memset(resource_ptr, 0, sizeof(sn_nsdl_resource_info_s)); - resource_ptr->resource_parameters_ptr = own_alloc(sizeof(sn_nsdl_resource_parameters_s)); - if(!resource_ptr->resource_parameters_ptr) { - own_free(resource_ptr); - return 0; - } - memset(resource_ptr->resource_parameters_ptr, 0, sizeof(sn_nsdl_resource_parameters_s)); - - /* Create resources */ - CREATE_STATIC_RESOURCE(resource_ptr, sizeof(res_manufacturer)-1, (uint8_t*) res_manufacturer, sizeof(res_type_test)-1, - (uint8_t*)res_type_test, (uint8_t*) res_manufacturer_val, - sizeof(res_manufacturer_val)-1, data_item->handle); - - CREATE_STATIC_RESOURCE(resource_ptr, sizeof(res_model_number)-1, (uint8_t*) res_model_number, sizeof(res_type_test)-1, - (uint8_t*)res_type_test, (uint8_t*) res_model_number_val, - sizeof(res_model_number_val)-1, data_item->handle); - - CREATE_DYNAMIC_RESOURCE(resource_ptr, sizeof(res_temp)-1, (uint8_t*) res_temp, sizeof(res_type_test)-1, - (uint8_t*)res_type_test, 0, &general_resource_cb, data_item->handle) - - /* Start registration */ - if(sn_nsdl_register_endpoint(data_item->handle, data_item->endpoint_ptr) == SN_NSDL_FAILURE) { - printf("NSP registration failed, thread:%d\n", data_item->thread_id); - } - - /* Free resource_ptr */ - if(resource_ptr->resource_parameters_ptr) { - own_free(resource_ptr->resource_parameters_ptr); - } - if(resource_ptr) { - own_free(resource_ptr); - } - - /* Main loop. */ - /* Listen and process incoming messages */ - while (1) - { - usleep(100); - memset(buf, 0, BUFLEN); - rcv_size = receive_msg(data_item,buf); - if(rcv_size > 0) { - sn_nsdl_process_coap(data_item->handle, buf, rcv_size, &data_item->received_packet_address); - } - } - return 0; -} - -int16_t receive_msg(thread_data_struct_s *data_item, uint8_t *buf) -{ - char rcv_in_addr[32]; - int16_t rcv_size=0; - - memset(rcv_in_addr,0,32); - - if ((rcv_size=recvfrom(data_item->sock_server, buf, BUFLEN, 0, - (struct sockaddr *)&data_item->sa_dst, (socklen_t*)&data_item->slen_sa_dst))==-1) { - stop_pgm("recvfrom()"); - } - else { - inet_ntop(AF_INET, &(data_item->sa_dst.sin_addr),rcv_in_addr,INET_ADDRSTRLEN); - data_item->received_packet_address.port = ntohs(data_item->sa_dst.sin_port); - data_item->received_packet_address.type = SN_NSDL_ADDRESS_TYPE_IPV4; - data_item->received_packet_address.addr_len = 4; - memcpy(data_item->received_packet_address.addr_ptr, &data_item->sa_dst.sin_addr, 4); - printf("\nRX %s.%d [%d B] - thread id: %d\n", rcv_in_addr, ntohs(data_item->sa_dst.sin_port), rcv_size, data_item->thread_id); - } - return rcv_size; -} - -/* Function needed for libCoap protocol. */ -uint8_t tx_function(struct nsdl_s *handle, sn_nsdl_capab_e protocol, - uint8_t *data, uint16_t len, sn_nsdl_addr_s *address) -{ - /* Set NSP address and port */ - thread_data_struct_s *data_item = NULL; - ns_list_foreach(thread_data_struct_s, item, &data_list) { - if (item->handle == handle) { - data_item = item; - break; - } - } - - if (data_item != NULL) { - printf("TX function - thread id: %d\n", data_item->thread_id); - ns_list_remove(&data_list, data_item); - data_item->sa_dst.sin_family = AF_INET; - data_item->sa_dst.sin_port = htons(address->port); - memcpy(&data_item->sa_dst.sin_addr, address->addr_ptr, address->addr_len); - ns_list_add_to_end(&data_list, data_item); - - int ret = sendto(data_item->sock_server, - data, - len, - 0, - (const struct sockaddr *)&data_item->sa_dst, - data_item->slen_sa_dst); - if (ret == -1) { - stop_pgm("sendto() failed"); - } - } - return 1; -} - -/* RX function for libNsdl. Passes CoAP responses sent from application to this function. Also response to registration message */ -uint8_t rx_function(struct nsdl_s *handle, sn_coap_hdr_s *coap_header, sn_nsdl_addr_s *address) -{ - if(!coap_header) - return 0; - - thread_data_struct_s *data_item = NULL; - ns_list_foreach(thread_data_struct_s, item, &data_list) { - if (item->handle == handle) { - data_item = item; - break; - } - } - if (!data_item) - return 0; - printf("\nRX callback mid:%d, thread id: %d\n", coap_header->msg_id, data_item->thread_id); - - /* If message is response to NSP registration */ - if(coap_header->msg_code == COAP_MSG_CODE_RESPONSE_CREATED && - !data_item->registered) { - reg_location_len = coap_header->options_list_ptr->location_path_len; - if(reg_location) - free(reg_location); - reg_location = malloc(reg_location_len); - - if(!reg_location) { - return 0; - } - - memcpy(reg_location, coap_header->options_list_ptr->location_path_ptr, reg_location_len); - printf("Registered to NSP: "); - for(int i = 0; i < reg_location_len; i++) - printf("%c", *(reg_location+i)); - printf("\n"); - - data_item->registered = true; - } - return 0; -} - -static void ctrl_c_handle_function() -{ - printf("Pressed ctrl-c\n"); - ns_list_foreach(thread_data_struct_s, item, &data_list) { - if (item->handle) { - sn_nsdl_unregister_endpoint(item->handle); - } - } - if(reg_location) - own_free(reg_location); - exit(1); -} - -void coap_exec_poll_function(int thread_id) -{ - uint8_t i = 0; - sn_coap_hdr_s coap_header; - - while(1) - { - sleep(1); - thread_data_struct_s *data_item = NULL; - ns_list_foreach(thread_data_struct_s, item, &data_list) { - if (item->thread_id == thread_id) { - data_item = item; - break; - } - } - if (data_item) { - /* nsdl execution function, must be called at least once / second. System time must be increased every second. */ - /* Cleans saved and unused data from libraries. Recommend to run this in same thread with other nsdl - functions */ - sn_nsdl_exec(data_item->handle, data_item->ns_system_time); - data_item->ns_system_time++; - - /* Check if reregistration needed */ - if(!(data_item->ns_system_time % (uint32_t)30) && data_item->ns_system_time) - { - printf("Update registration - thread id: %d\n", data_item->thread_id); - sn_nsdl_update_registration(data_item->handle, data_item->endpoint_ptr->lifetime_ptr, data_item->endpoint_ptr->lifetime_len); - } - - /* Send delayed response to request */ - /* This is just example. When receiving request to sen/temp, application send ack and after few seconds value for this resource */ - if(data_item->delayed_response_cnt == 1) { - printf("Delayed response - thread: %d\n", data_item->thread_id); - memset(&coap_header, 0, sizeof(sn_coap_hdr_s)); - - if(data_item->delayed_msg_type == COAP_MSG_TYPE_CONFIRMABLE) - coap_header.msg_type = COAP_MSG_TYPE_CONFIRMABLE; - else if(data_item->delayed_msg_type == COAP_MSG_TYPE_NON_CONFIRMABLE) - coap_header.msg_type = COAP_MSG_TYPE_NON_CONFIRMABLE; - - coap_header.msg_code = COAP_MSG_CODE_RESPONSE_CONTENT; - - if(data_item->delayed_token_len) - { - coap_header.token_len = data_item->delayed_token_len; - coap_header.token_ptr = data_item->delayed_token; - data_item->delayed_token_len = 0; - } - - coap_header.payload_len = sizeof(data_item->res_temp_val) - 1; - coap_header.payload_ptr = data_item->res_temp_val; - - sn_nsdl_send_coap_message(data_item->handle, &data_item->received_packet_address, &coap_header); - - data_item->delayed_response_cnt = 0; - - } - else if(data_item->delayed_response_cnt > 1) { - data_item->delayed_response_cnt--; - } - } - } -} - -/* This is callback for other DYNAMIC resources */ -uint8_t general_resource_cb(struct nsdl_s *handle, sn_coap_hdr_s *received_coap_ptr, - sn_nsdl_addr_s *address, sn_nsdl_capab_e protocol) -{ - sn_coap_hdr_s *coap_res_ptr = 0; - thread_data_struct_s *data_item = NULL; - ns_list_foreach(thread_data_struct_s, item, &data_list) { - if (item->handle == handle) { - data_item = item; - break; - } - } - if (!data_item) { - return 0; - } - - if (received_coap_ptr->msg_code == COAP_MSG_CODE_REQUEST_GET) { - printf("\nGeneral callback - thread id: %d\n", data_item->thread_id); - coap_res_ptr = sn_nsdl_build_response(data_item->handle, received_coap_ptr, COAP_MSG_CODE_RESPONSE_CONTENT); - coap_res_ptr->accept = COAP_CT_TEXT_PLAIN; - - /* Temperature resource */ - /* This makes delayed response, first ack and after that real value */ - if(compare_uripaths(received_coap_ptr, res_temp)) - { - send_ack(data_item->handle,received_coap_ptr, &data_item->received_packet_address); - if(coap_res_ptr->token_ptr) { - own_free(coap_res_ptr->token_ptr); - } - if(coap_res_ptr->options_list_ptr) { - own_free(coap_res_ptr->options_list_ptr); - } - own_free(coap_res_ptr); - return 0; - } - sn_nsdl_send_coap_message(data_item->handle, address, coap_res_ptr); - } - else if (received_coap_ptr->msg_code == COAP_MSG_CODE_REQUEST_PUT) { - if (received_coap_ptr->payload_ptr && received_coap_ptr->payload_len < 16) { - ns_list_remove(&data_list, data_item); - memcpy(data_item->res_temp_val,received_coap_ptr->payload_ptr, received_coap_ptr->payload_len); - printf("Update resource value to %s, thread id: %d\n", data_item->res_temp_val, data_item->thread_id); - ns_list_add_to_end(&data_list, data_item); - } - coap_res_ptr = sn_nsdl_build_response(data_item->handle, received_coap_ptr, COAP_MSG_CODE_RESPONSE_CHANGED); - sn_nsdl_send_coap_message(data_item->handle, address, coap_res_ptr); - } - /* Method not supported */ - else { - printf("Method not supported\n"); - coap_res_ptr = sn_coap_build_response(handle->grs->coap, received_coap_ptr, COAP_MSG_CODE_RESPONSE_METHOD_NOT_ALLOWED); - sn_nsdl_send_coap_message(handle, address, coap_res_ptr); - } - - if(coap_res_ptr->token_ptr) { - own_free(coap_res_ptr->token_ptr); - } - - if(coap_res_ptr->options_list_ptr) { - own_free(coap_res_ptr->options_list_ptr); - } - own_free(coap_res_ptr); - - return 0; -} - -int8_t compare_uripaths(sn_coap_hdr_s *coap_header, const uint8_t *uri_path_to_compare) -{ - if(memcmp(coap_header->uri_path_ptr,&uri_path_to_compare[0], coap_header->uri_path_len) == 0) - { - return 1; - } - return 0; -} - -void send_ack(struct nsdl_s *handle, sn_coap_hdr_s *received_coap_ptr, sn_nsdl_addr_s *address/*, sn_nsdl_addr_s *received_packet_address*/) -{ - printf("Send acknowledgement\n"); - sn_coap_hdr_s *coap_res_ptr = 0; - uint16_t message_len = 0; - uint8_t *message_ptr; - thread_data_struct_s *data_item = NULL; - ns_list_foreach(thread_data_struct_s, item, &data_list) { - if (item->handle == handle) { - data_item = item; - break; - } - } - if (data_item) { - if (received_coap_ptr->msg_code == COAP_MSG_CODE_REQUEST_GET) - { - if (received_coap_ptr->msg_type == COAP_MSG_TYPE_CONFIRMABLE) { - coap_res_ptr = own_alloc(sizeof(sn_coap_hdr_s)); - if(!coap_res_ptr) { - return; - } - memset(coap_res_ptr, 0x00, sizeof(sn_coap_hdr_s)); - coap_res_ptr->msg_type = COAP_MSG_TYPE_ACKNOWLEDGEMENT; - coap_res_ptr->msg_code = COAP_MSG_CODE_EMPTY; - coap_res_ptr->msg_id = received_coap_ptr->msg_id; - data_item->delayed_msg_type = COAP_MSG_TYPE_CONFIRMABLE; - } - else { - data_item->delayed_msg_type = COAP_MSG_TYPE_NON_CONFIRMABLE; - } - - if(received_coap_ptr->token_len) { - memset(data_item->delayed_token, 0, 8); - data_item->delayed_token_len = received_coap_ptr->token_len; - memcpy(data_item->delayed_token, received_coap_ptr->token_ptr, received_coap_ptr->token_len); - } - data_item->delayed_response_cnt = 1; - } - } - - if(coap_res_ptr) { - message_len = sn_coap_builder_calc_needed_packet_data_size(coap_res_ptr); - message_ptr = own_alloc(message_len); - if(!message_ptr) { - return; - } - - sn_coap_builder(message_ptr, coap_res_ptr); - tx_function(handle,SN_NSDL_PROTOCOL_COAP, message_ptr, message_len, address); - - /* Free memory */ - if(coap_res_ptr) { - own_free(coap_res_ptr); - } - own_free(message_ptr); - } - return; -} diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/test/multithread-linux-test/module.json b/features/FEATURE_COMMON_PAL/mbed-client-c/test/multithread-linux-test/module.json deleted file mode 100644 index 36989d394f..0000000000 --- a/features/FEATURE_COMMON_PAL/mbed-client-c/test/multithread-linux-test/module.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "name": "multithread-linux-test", - "version": "1.0.0", - "description": "Example application how to use mbed-client-c library", - "private": true, - "keywords": [], - "author": "Antti Yli-Tokola ", - "license": "Apache-2.0", - "dependencies": { - "mbed-client-c": "^2.0.0" - }, - "bin": "./" -} diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/test/multithread-linux-test/resource_generation_help.h b/features/FEATURE_COMMON_PAL/mbed-client-c/test/multithread-linux-test/resource_generation_help.h deleted file mode 100644 index 29c3117692..0000000000 --- a/features/FEATURE_COMMON_PAL/mbed-client-c/test/multithread-linux-test/resource_generation_help.h +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (c) 2015 ARM Limited. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 - * Licensed under the Apache License, Version 2.0 (the License); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef RESOURCE_GENERATION_HELP_H_ -#define RESOURCE_GENERATION_HELP_H_ - -/* - * A helper macro to create a static resoure - */ -#define CREATE_STATIC_RESOURCE(resource_structure, pt_len, pt, rpp_len, rpp_ptr, rsc, rsc_len, handle) \ -{ \ - resource_structure->access = (sn_grs_resource_acl_e)0xff; \ - resource_structure->mode = SN_GRS_STATIC; \ - resource_structure->pathlen = pt_len; \ - resource_structure->path = pt; \ - resource_structure->resource_parameters_ptr->resource_type_len = rpp_len; \ - resource_structure->resource_parameters_ptr->resource_type_ptr = rpp_ptr; \ - resource_structure->resource = rsc; \ - resource_structure->resourcelen = rsc_len; \ - sn_nsdl_create_resource(handle,resource_structure); \ -} - - -/* - * A helper macro to create a dynamic resoure - */ -#define CREATE_DYNAMIC_RESOURCE(resource_structure, pt_len, pt, rpp_len, rpp_ptr, is_observable, callback_ptr, handle) \ -{ \ - resource_structure->access = (sn_grs_resource_acl_e)0xff; \ - resource_structure->resource = 0; \ - resource_structure->resourcelen = 0; \ - resource_structure->sn_grs_dyn_res_callback = callback_ptr; \ - resource_structure->mode = SN_GRS_DYNAMIC; \ - resource_structure->pathlen = pt_len; \ - resource_structure->path = pt; \ - resource_structure->resource_parameters_ptr->resource_type_len = rpp_len; \ - resource_structure->resource_parameters_ptr->resource_type_ptr = rpp_ptr; \ - resource_structure->resource_parameters_ptr->observable = is_observable; \ - sn_nsdl_create_resource(handle,resource_structure); \ -} - -#define INIT_REGISTER_NSDL_ENDPOINT(endpoint_structure, name, typename_ptr, lifetime_ptr) \ -{ \ - if(!endpoint_structure) \ - { \ - endpoint_structure = own_alloc(sizeof(sn_nsdl_ep_parameters_s)); \ - } \ - if(endpoint_structure) \ - { \ - memset(endpoint_structure, 0, sizeof(sn_nsdl_ep_parameters_s)); \ - endpoint_structure->endpoint_name_ptr = name; \ - endpoint_structure->endpoint_name_len = sizeof(name)-1; \ - endpoint_structure->type_ptr = typename_ptr; \ - endpoint_structure->type_len = sizeof(typename_ptr)-1; \ - endpoint_structure->lifetime_ptr = lifetime_ptr; \ - endpoint_structure->lifetime_len = sizeof(lifetime_ptr)-1; \ - } \ -} - -#define CLEAN_REGISTER_NSDL_ENDPOINT(endpoint_structure) \ -{ \ - if(endpoint_structure) \ - { \ - own_free(endpoint_structure); \ - endpoint_structure = 0; \ - } \ -} \ - -#endif /* RESOURCE_GENERATION_HELP_H_ */ diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/test/multithread-linux-test/tester.sh b/features/FEATURE_COMMON_PAL/mbed-client-c/test/multithread-linux-test/tester.sh deleted file mode 100755 index 1ce8c9edf8..0000000000 --- a/features/FEATURE_COMMON_PAL/mbed-client-c/test/multithread-linux-test/tester.sh +++ /dev/null @@ -1,76 +0,0 @@ -#!/bin/bash -# Copyright (c) 2015 ARM Limited. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 -# Licensed under the Apache License, Version 2.0 (the License); you may -# not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# * http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an AS IS BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -initial_values=(20.0 21.0 22.0 23.0 24.0 25.0 26.0 27.0 28.0 25.9 ) -new_values=(30.0 31.0 32.0 33.0 34.0 35.0 36.0 37.0 38.0 35.9 ) -DESTINATION=$1 -function read_default_values { - echo "Read default values" - for i in {0..9} - do - value=`curl -s -H "Authorization: Basic YWRtaW46c2VjcmV0" "http://${DESTINATION}:8080/endpoints/THREAD_${i}/3303/0/temp?sync=true"` - echo "Thread${i} $value" - if [ "${initial_values[$i]}" != "$value" ]; - then - echo "Value ${initial_values[$i]} does not match to $value" - exit 1 - fi - done -} - -function read_new_values { - echo "Read new values" - for i in {0..9} - do - value=`curl -s -H "Authorization: Basic YWRtaW46c2VjcmV0" "http://${DESTINATION}:8080/endpoints/THREAD_${i}/3303/0/temp?sync=true"` - echo "Thread${i} $value" - if [ "${new_values[$i]}" != "$value" ]; - then - echo "Value ${new_values[$i]} does not match to $value" - exit 1 - fi - done -} - -function post_new_values { - echo "Post new values" - for i in {0..9} - do - curl -X PUT -H "Authorization: Basic YWRtaW46c2VjcmV0" "http://${DESTINATION}:8080/endpoints/THREAD_${i}/3303/0/temp?sync=true" -d "${new_values[$i]}" - done -} - -function post_default_values { - echo "Post default values" - for i in {0..9} - do - curl -X PUT -H "Authorization: Basic YWRtaW46c2VjcmV0" "http://${DESTINATION}:8080/endpoints/THREAD_${i}/3303/0/temp?sync=true" -d "${initial_values[$i]}" - done -} -post_default_values -while [ true ]; do - read_default_values - sleep 2 - post_new_values - sleep 2 - read_new_values - sleep 2 - post_default_values - sleep 2 -done - - - - diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/Makefile b/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/Makefile deleted file mode 100755 index c03b7dc6ea..0000000000 --- a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/Makefile +++ /dev/null @@ -1,19 +0,0 @@ -#scan for folders having "Makefile" in them and remove 'this' to prevent loop -DIRS := $(filter-out ./, $(sort $(dir $(shell find . -name 'Makefile')))) - -all: - for dir in $(DIRS); do \ - cd $$dir; make gcov; cd ..;\ - done - -clean: - for dir in $(DIRS); do \ - cd $$dir; make clean; cd ..;\ - done - rm -rf ../source/*gcov ../source/*gcda ../source/*o - rm -rf stubs/*gcov stubs/*gcda stubs/*o - rm -rf results/* - rm -rf coverages/* - rm -rf results - rm -rf coverages - diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/MakefileWorker.mk b/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/MakefileWorker.mk deleted file mode 100755 index 2096ced036..0000000000 --- a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/MakefileWorker.mk +++ /dev/null @@ -1,562 +0,0 @@ -#--------- -# -# MakefileWorker.mk -# -# Include this helper file in your makefile -# It makes -# A static library -# A test executable -# -# See this example for parameter settings -# examples/Makefile -# -#---------- -# Inputs - these variables describe what to build -# -# INCLUDE_DIRS - Directories used to search for include files. -# This generates a -I for each directory -# SRC_DIRS - Directories containing source file to built into the library -# SRC_FILES - Specific source files to build into library. Helpful when not all code -# in a directory can be built for test (hopefully a temporary situation) -# TEST_SRC_DIRS - Directories containing unit test code build into the unit test runner -# These do not go in a library. They are explicitly included in the test runner -# TEST_SRC_FILES - Specific source files to build into the unit test runner -# These do not go in a library. They are explicitly included in the test runner -# MOCKS_SRC_DIRS - Directories containing mock source files to build into the test runner -# These do not go in a library. They are explicitly included in the test runner -#---------- -# You can adjust these variables to influence how to build the test target -# and where to put and name outputs -# See below to determine defaults -# COMPONENT_NAME - the name of the thing being built -# TEST_TARGET - name the test executable. By default it is -# $(COMPONENT_NAME)_tests -# Helpful if you want 1 > make files in the same directory with different -# executables as output. -# CPPUTEST_HOME - where CppUTest home dir found -# TARGET_PLATFORM - Influences how the outputs are generated by modifying the -# CPPUTEST_OBJS_DIR and CPPUTEST_LIB_DIR to use a sub-directory under the -# normal objs and lib directories. Also modifies where to search for the -# CPPUTEST_LIB to link against. -# CPPUTEST_OBJS_DIR - a directory where o and d files go -# CPPUTEST_LIB_DIR - a directory where libs go -# CPPUTEST_ENABLE_DEBUG - build for debug -# CPPUTEST_USE_MEM_LEAK_DETECTION - Links with overridden new and delete -# CPPUTEST_USE_STD_CPP_LIB - Set to N to keep the standard C++ library out -# of the test harness -# CPPUTEST_USE_GCOV - Turn on coverage analysis -# Clean then build with this flag set to Y, then 'make gcov' -# CPPUTEST_MAPFILE - generate a map file -# CPPUTEST_WARNINGFLAGS - overly picky by default -# OTHER_MAKEFILE_TO_INCLUDE - a hook to use this makefile to make -# other targets. Like CSlim, which is part of fitnesse -# CPPUTEST_USE_VPATH - Use Make's VPATH functionality to support user -# specification of source files and directories that aren't below -# the user's Makefile in the directory tree, like: -# SRC_DIRS += ../../lib/foo -# It defaults to N, and shouldn't be necessary except in the above case. -#---------- -# -# Other flags users can initialize to sneak in their settings -# CPPUTEST_CXXFLAGS - flags for the C++ compiler -# CPPUTEST_CPPFLAGS - flags for the C++ AND C preprocessor -# CPPUTEST_CFLAGS - flags for the C complier -# CPPUTEST_LDFLAGS - Linker flags -#---------- - -# Some behavior is weird on some platforms. Need to discover the platform. - -# Platforms -UNAME_OUTPUT = "$(shell uname -a)" -MACOSX_STR = Darwin -MINGW_STR = MINGW -CYGWIN_STR = CYGWIN -LINUX_STR = Linux -SUNOS_STR = SunOS -UNKNWOWN_OS_STR = Unknown - -# Compilers -CC_VERSION_OUTPUT ="$(shell $(CXX) -v 2>&1)" -CLANG_STR = clang -SUNSTUDIO_CXX_STR = SunStudio - -UNAME_OS = $(UNKNWOWN_OS_STR) - -ifeq ($(findstring $(MINGW_STR),$(UNAME_OUTPUT)),$(MINGW_STR)) - UNAME_OS = $(MINGW_STR) -endif - -ifeq ($(findstring $(CYGWIN_STR),$(UNAME_OUTPUT)),$(CYGWIN_STR)) - UNAME_OS = $(CYGWIN_STR) -endif - -ifeq ($(findstring $(LINUX_STR),$(UNAME_OUTPUT)),$(LINUX_STR)) - UNAME_OS = $(LINUX_STR) -endif - -ifeq ($(findstring $(MACOSX_STR),$(UNAME_OUTPUT)),$(MACOSX_STR)) - UNAME_OS = $(MACOSX_STR) -#lion has a problem with the 'v' part of -a - UNAME_OUTPUT = "$(shell uname -pmnrs)" -endif - -ifeq ($(findstring $(SUNOS_STR),$(UNAME_OUTPUT)),$(SUNOS_STR)) - UNAME_OS = $(SUNOS_STR) - - SUNSTUDIO_CXX_ERR_STR = CC -flags -ifeq ($(findstring $(SUNSTUDIO_CXX_ERR_STR),$(CC_VERSION_OUTPUT)),$(SUNSTUDIO_CXX_ERR_STR)) - CC_VERSION_OUTPUT ="$(shell $(CXX) -V 2>&1)" - COMPILER_NAME = $(SUNSTUDIO_CXX_STR) -endif -endif - -ifeq ($(findstring $(CLANG_STR),$(CC_VERSION_OUTPUT)),$(CLANG_STR)) - COMPILER_NAME = $(CLANG_STR) -endif - -#Kludge for mingw, it does not have cc.exe, but gcc.exe will do -ifeq ($(UNAME_OS),$(MINGW_STR)) - CC := gcc -endif - -#And another kludge. Exception handling in gcc 4.6.2 is broken when linking the -# Standard C++ library as a shared library. Unbelievable. -ifeq ($(UNAME_OS),$(MINGW_STR)) - CPPUTEST_LDFLAGS += -static -endif -ifeq ($(UNAME_OS),$(CYGWIN_STR)) - CPPUTEST_LDFLAGS += -static -endif - - -#Kludge for MacOsX gcc compiler on Darwin9 who can't handle pendantic -ifeq ($(UNAME_OS),$(MACOSX_STR)) -ifeq ($(findstring Version 9,$(UNAME_OUTPUT)),Version 9) - CPPUTEST_PEDANTIC_ERRORS = N -endif -endif - -ifndef COMPONENT_NAME - COMPONENT_NAME = name_this_in_the_makefile -endif - -# Debug on by default -ifndef CPPUTEST_ENABLE_DEBUG - CPPUTEST_ENABLE_DEBUG = Y -endif - -# new and delete for memory leak detection on by default -ifndef CPPUTEST_USE_MEM_LEAK_DETECTION - CPPUTEST_USE_MEM_LEAK_DETECTION = Y -endif - -# Use the standard C library -ifndef CPPUTEST_USE_STD_C_LIB - CPPUTEST_USE_STD_C_LIB = Y -endif - -# Use the standard C++ library -ifndef CPPUTEST_USE_STD_CPP_LIB - CPPUTEST_USE_STD_CPP_LIB = Y -endif - -# Use gcov, off by default -ifndef CPPUTEST_USE_GCOV - CPPUTEST_USE_GCOV = N -endif - -ifndef CPPUTEST_PEDANTIC_ERRORS - CPPUTEST_PEDANTIC_ERRORS = Y -endif - -# Default warnings -ifndef CPPUTEST_WARNINGFLAGS - CPPUTEST_WARNINGFLAGS = -Wall -Wextra -Wshadow -Wswitch-default -Wswitch-enum -Wconversion -ifeq ($(CPPUTEST_PEDANTIC_ERRORS), Y) -# CPPUTEST_WARNINGFLAGS += -pedantic-errors - CPPUTEST_WARNINGFLAGS += -pedantic -endif -ifeq ($(UNAME_OS),$(LINUX_STR)) - CPPUTEST_WARNINGFLAGS += -Wsign-conversion -endif - CPPUTEST_CXX_WARNINGFLAGS = -Woverloaded-virtual - CPPUTEST_C_WARNINGFLAGS = -Wstrict-prototypes -endif - -#Wonderful extra compiler warnings with clang -ifeq ($(COMPILER_NAME),$(CLANG_STR)) -# -Wno-disabled-macro-expansion -> Have to disable the macro expansion warning as the operator new overload warns on that. -# -Wno-padded -> I sort-of like this warning but if there is a bool at the end of the class, it seems impossible to remove it! (except by making padding explicit) -# -Wno-global-constructors Wno-exit-time-destructors -> Great warnings, but in CppUTest it is impossible to avoid as the automatic test registration depends on the global ctor and dtor -# -Wno-weak-vtables -> The TEST_GROUP macro declares a class and will automatically inline its methods. Thats ok as they are only in one translation unit. Unfortunately, the warning can't detect that, so it must be disabled. - CPPUTEST_CXX_WARNINGFLAGS += -Weverything -Wno-disabled-macro-expansion -Wno-padded -Wno-global-constructors -Wno-exit-time-destructors -Wno-weak-vtables - CPPUTEST_C_WARNINGFLAGS += -Weverything -Wno-padded -endif - -# Uhm. Maybe put some warning flags for SunStudio here? -ifeq ($(COMPILER_NAME),$(SUNSTUDIO_CXX_STR)) - CPPUTEST_CXX_WARNINGFLAGS = - CPPUTEST_C_WARNINGFLAGS = -endif - -# Default dir for temporary files (d, o) -ifndef CPPUTEST_OBJS_DIR -ifndef TARGET_PLATFORM - CPPUTEST_OBJS_DIR = objs -else - CPPUTEST_OBJS_DIR = objs/$(TARGET_PLATFORM) -endif -endif - -# Default dir for the outout library -ifndef CPPUTEST_LIB_DIR -ifndef TARGET_PLATFORM - CPPUTEST_LIB_DIR = lib -else - CPPUTEST_LIB_DIR = lib/$(TARGET_PLATFORM) -endif -endif - -# No map by default -ifndef CPPUTEST_MAP_FILE - CPPUTEST_MAP_FILE = N -endif - -# No extentions is default -ifndef CPPUTEST_USE_EXTENSIONS - CPPUTEST_USE_EXTENSIONS = N -endif - -# No VPATH is default -ifndef CPPUTEST_USE_VPATH - CPPUTEST_USE_VPATH := N -endif -# Make empty, instead of 'N', for usage in $(if ) conditionals -ifneq ($(CPPUTEST_USE_VPATH), Y) - CPPUTEST_USE_VPATH := -endif - -ifndef TARGET_PLATFORM -#CPPUTEST_LIB_LINK_DIR = $(CPPUTEST_HOME)/lib -CPPUTEST_LIB_LINK_DIR = /usr/lib/x86_64-linux-gnu -else -CPPUTEST_LIB_LINK_DIR = $(CPPUTEST_HOME)/lib/$(TARGET_PLATFORM) -endif - -# -------------------------------------- -# derived flags in the following area -# -------------------------------------- - -# Without the C library, we'll need to disable the C++ library and ... -ifeq ($(CPPUTEST_USE_STD_C_LIB), N) - CPPUTEST_USE_STD_CPP_LIB = N - CPPUTEST_USE_MEM_LEAK_DETECTION = N - CPPUTEST_CPPFLAGS += -DCPPUTEST_STD_C_LIB_DISABLED - CPPUTEST_CPPFLAGS += -nostdinc -endif - -CPPUTEST_CPPFLAGS += -DCPPUTEST_COMPILATION - -ifeq ($(CPPUTEST_USE_MEM_LEAK_DETECTION), N) - CPPUTEST_CPPFLAGS += -DCPPUTEST_MEM_LEAK_DETECTION_DISABLED -else - ifndef CPPUTEST_MEMLEAK_DETECTOR_NEW_MACRO_FILE - CPPUTEST_MEMLEAK_DETECTOR_NEW_MACRO_FILE = -include $(CPPUTEST_HOME)/include/CppUTest/MemoryLeakDetectorNewMacros.h - endif - ifndef CPPUTEST_MEMLEAK_DETECTOR_MALLOC_MACRO_FILE - CPPUTEST_MEMLEAK_DETECTOR_MALLOC_MACRO_FILE = -include $(CPPUTEST_HOME)/include/CppUTest/MemoryLeakDetectorMallocMacros.h - endif -endif - -ifeq ($(CPPUTEST_ENABLE_DEBUG), Y) - CPPUTEST_CXXFLAGS += -g - CPPUTEST_CFLAGS += -g - CPPUTEST_LDFLAGS += -g -endif - -ifeq ($(CPPUTEST_USE_STD_CPP_LIB), N) - CPPUTEST_CPPFLAGS += -DCPPUTEST_STD_CPP_LIB_DISABLED -ifeq ($(CPPUTEST_USE_STD_C_LIB), Y) - CPPUTEST_CXXFLAGS += -nostdinc++ -endif -endif - -ifdef $(GMOCK_HOME) - GTEST_HOME = $(GMOCK_HOME)/gtest - CPPUTEST_CPPFLAGS += -I$(GMOCK_HOME)/include - GMOCK_LIBRARY = $(GMOCK_HOME)/lib/.libs/libgmock.a - LD_LIBRARIES += $(GMOCK_LIBRARY) - CPPUTEST_CPPFLAGS += -DINCLUDE_GTEST_TESTS - CPPUTEST_WARNINGFLAGS = - CPPUTEST_CPPFLAGS += -I$(GTEST_HOME)/include -I$(GTEST_HOME) - GTEST_LIBRARY = $(GTEST_HOME)/lib/.libs/libgtest.a - LD_LIBRARIES += $(GTEST_LIBRARY) -endif - - -ifeq ($(CPPUTEST_USE_GCOV), Y) - CPPUTEST_CXXFLAGS += -fprofile-arcs -ftest-coverage - CPPUTEST_CFLAGS += -fprofile-arcs -ftest-coverage -endif - -CPPUTEST_CXXFLAGS += $(CPPUTEST_WARNINGFLAGS) $(CPPUTEST_CXX_WARNINGFLAGS) -CPPUTEST_CPPFLAGS += $(CPPUTEST_WARNINGFLAGS) -CPPUTEST_CXXFLAGS += $(CPPUTEST_MEMLEAK_DETECTOR_NEW_MACRO_FILE) -CPPUTEST_CPPFLAGS += $(CPPUTEST_MEMLEAK_DETECTOR_MALLOC_MACRO_FILE) -CPPUTEST_CFLAGS += $(CPPUTEST_C_WARNINGFLAGS) - -TARGET_MAP = $(COMPONENT_NAME).map.txt -ifeq ($(CPPUTEST_MAP_FILE), Y) - CPPUTEST_LDFLAGS += -Wl,-map,$(TARGET_MAP) -endif - -# Link with CppUTest lib -CPPUTEST_LIB = $(CPPUTEST_LIB_LINK_DIR)/libCppUTest.a - -ifeq ($(CPPUTEST_USE_EXTENSIONS), Y) -CPPUTEST_LIB += $(CPPUTEST_LIB_LINK_DIR)/libCppUTestExt.a -endif - -ifdef CPPUTEST_STATIC_REALTIME - LD_LIBRARIES += -lrt -endif - -TARGET_LIB = \ - $(CPPUTEST_LIB_DIR)/lib$(COMPONENT_NAME).a - -ifndef TEST_TARGET - ifndef TARGET_PLATFORM - TEST_TARGET = $(COMPONENT_NAME)_tests - else - TEST_TARGET = $(COMPONENT_NAME)_$(TARGET_PLATFORM)_tests - endif -endif - -#Helper Functions -get_src_from_dir = $(wildcard $1/*.cpp) $(wildcard $1/*.cc) $(wildcard $1/*.c) -get_dirs_from_dirspec = $(wildcard $1) -get_src_from_dir_list = $(foreach dir, $1, $(call get_src_from_dir,$(dir))) -__src_to = $(subst .c,$1, $(subst .cc,$1, $(subst .cpp,$1,$(if $(CPPUTEST_USE_VPATH),$(notdir $2),$2)))) -src_to = $(addprefix $(CPPUTEST_OBJS_DIR)/,$(call __src_to,$1,$2)) -src_to_o = $(call src_to,.o,$1) -src_to_d = $(call src_to,.d,$1) -src_to_gcda = $(call src_to,.gcda,$1) -src_to_gcno = $(call src_to,.gcno,$1) -time = $(shell date +%s) -delta_t = $(eval minus, $1, $2) -debug_print_list = $(foreach word,$1,echo " $(word)";) echo; - -#Derived -STUFF_TO_CLEAN += $(TEST_TARGET) $(TEST_TARGET).exe $(TARGET_LIB) $(TARGET_MAP) - -SRC += $(call get_src_from_dir_list, $(SRC_DIRS)) $(SRC_FILES) -OBJ = $(call src_to_o,$(SRC)) - -STUFF_TO_CLEAN += $(OBJ) - -TEST_SRC += $(call get_src_from_dir_list, $(TEST_SRC_DIRS)) $(TEST_SRC_FILES) -TEST_OBJS = $(call src_to_o,$(TEST_SRC)) -STUFF_TO_CLEAN += $(TEST_OBJS) - - -MOCKS_SRC += $(call get_src_from_dir_list, $(MOCKS_SRC_DIRS)) -MOCKS_OBJS = $(call src_to_o,$(MOCKS_SRC)) -STUFF_TO_CLEAN += $(MOCKS_OBJS) - -ALL_SRC = $(SRC) $(TEST_SRC) $(MOCKS_SRC) - -# If we're using VPATH -ifeq ($(CPPUTEST_USE_VPATH), Y) -# gather all the source directories and add them - VPATH += $(sort $(dir $(ALL_SRC))) -# Add the component name to the objs dir path, to differentiate between same-name objects - CPPUTEST_OBJS_DIR := $(addsuffix /$(COMPONENT_NAME),$(CPPUTEST_OBJS_DIR)) -endif - -#Test coverage with gcov -GCOV_OUTPUT = gcov_output.txt -GCOV_REPORT = gcov_report.txt -GCOV_ERROR = gcov_error.txt -GCOV_GCDA_FILES = $(call src_to_gcda, $(ALL_SRC)) -GCOV_GCNO_FILES = $(call src_to_gcno, $(ALL_SRC)) -TEST_OUTPUT = $(TEST_TARGET).txt -STUFF_TO_CLEAN += \ - $(GCOV_OUTPUT)\ - $(GCOV_REPORT)\ - $(GCOV_REPORT).html\ - $(GCOV_ERROR)\ - $(GCOV_GCDA_FILES)\ - $(GCOV_GCNO_FILES)\ - $(TEST_OUTPUT) - -#The gcda files for gcov need to be deleted before each run -#To avoid annoying messages. -GCOV_CLEAN = $(SILENCE)rm -f $(GCOV_GCDA_FILES) $(GCOV_OUTPUT) $(GCOV_REPORT) $(GCOV_ERROR) -RUN_TEST_TARGET = $(SILENCE) $(GCOV_CLEAN) ; echo "Running $(TEST_TARGET)"; ./$(TEST_TARGET) $(CPPUTEST_EXE_FLAGS) -ojunit - -ifeq ($(CPPUTEST_USE_GCOV), Y) - - ifeq ($(COMPILER_NAME),$(CLANG_STR)) - LD_LIBRARIES += --coverage - else - LD_LIBRARIES += -lgcov - endif -endif - - -INCLUDES_DIRS_EXPANDED = $(call get_dirs_from_dirspec, $(INCLUDE_DIRS)) -INCLUDES += $(foreach dir, $(INCLUDES_DIRS_EXPANDED), -I$(dir)) -MOCK_DIRS_EXPANDED = $(call get_dirs_from_dirspec, $(MOCKS_SRC_DIRS)) -INCLUDES += $(foreach dir, $(MOCK_DIRS_EXPANDED), -I$(dir)) - -CPPUTEST_CPPFLAGS += $(INCLUDES) $(CPPUTESTFLAGS) - -DEP_FILES = $(call src_to_d, $(ALL_SRC)) -STUFF_TO_CLEAN += $(DEP_FILES) $(PRODUCTION_CODE_START) $(PRODUCTION_CODE_END) -STUFF_TO_CLEAN += $(STDLIB_CODE_START) $(MAP_FILE) cpputest_*.xml junit_run_output - -# We'll use the CPPUTEST_CFLAGS etc so that you can override AND add to the CppUTest flags -CFLAGS = $(CPPUTEST_CFLAGS) $(CPPUTEST_ADDITIONAL_CFLAGS) -CPPFLAGS = $(CPPUTEST_CPPFLAGS) $(CPPUTEST_ADDITIONAL_CPPFLAGS) -CXXFLAGS = $(CPPUTEST_CXXFLAGS) $(CPPUTEST_ADDITIONAL_CXXFLAGS) -LDFLAGS = $(CPPUTEST_LDFLAGS) $(CPPUTEST_ADDITIONAL_LDFLAGS) - -# Don't consider creating the archive a warning condition that does STDERR output -ARFLAGS := $(ARFLAGS)c - -DEP_FLAGS=-MMD -MP - -# Some macros for programs to be overridden. For some reason, these are not in Make defaults -RANLIB = ranlib - -# Targets - -.PHONY: all -all: start $(TEST_TARGET) - $(RUN_TEST_TARGET) - -.PHONY: start -start: $(TEST_TARGET) - $(SILENCE)START_TIME=$(call time) - -.PHONY: all_no_tests -all_no_tests: $(TEST_TARGET) - -.PHONY: flags -flags: - @echo - @echo "OS ${UNAME_OS}" - @echo "Compile C and C++ source with CPPFLAGS:" - @$(call debug_print_list,$(CPPFLAGS)) - @echo "Compile C++ source with CXXFLAGS:" - @$(call debug_print_list,$(CXXFLAGS)) - @echo "Compile C source with CFLAGS:" - @$(call debug_print_list,$(CFLAGS)) - @echo "Link with LDFLAGS:" - @$(call debug_print_list,$(LDFLAGS)) - @echo "Link with LD_LIBRARIES:" - @$(call debug_print_list,$(LD_LIBRARIES)) - @echo "Create libraries with ARFLAGS:" - @$(call debug_print_list,$(ARFLAGS)) - -TEST_DEPS = $(TEST_OBJS) $(MOCKS_OBJS) $(PRODUCTION_CODE_START) $(TARGET_LIB) $(USER_LIBS) $(PRODUCTION_CODE_END) $(CPPUTEST_LIB) $(STDLIB_CODE_START) -test-deps: $(TEST_DEPS) - -$(TEST_TARGET): $(TEST_DEPS) - @echo Linking $@ - $(SILENCE)$(CXX) -o $@ $^ $(LD_LIBRARIES) $(LDFLAGS) - -$(TARGET_LIB): $(OBJ) - @echo Building archive $@ - $(SILENCE)mkdir -p $(dir $@) - $(SILENCE)$(AR) $(ARFLAGS) $@ $^ - $(SILENCE)$(RANLIB) $@ - -test: $(TEST_TARGET) - $(RUN_TEST_TARGET) | tee $(TEST_OUTPUT) - -vtest: $(TEST_TARGET) - $(RUN_TEST_TARGET) -v | tee $(TEST_OUTPUT) - -$(CPPUTEST_OBJS_DIR)/%.o: %.cc - @echo compiling $(notdir $<) - $(SILENCE)mkdir -p $(dir $@) - $(SILENCE)$(COMPILE.cpp) $(DEP_FLAGS) $(OUTPUT_OPTION) $< - -$(CPPUTEST_OBJS_DIR)/%.o: %.cpp - @echo compiling $(notdir $<) - $(SILENCE)mkdir -p $(dir $@) - $(SILENCE)$(COMPILE.cpp) $(DEP_FLAGS) $(OUTPUT_OPTION) $< - -$(CPPUTEST_OBJS_DIR)/%.o: %.c - @echo compiling $(notdir $<) - $(SILENCE)mkdir -p $(dir $@) - $(SILENCE)$(COMPILE.c) $(DEP_FLAGS) $(OUTPUT_OPTION) $< - -ifneq "$(MAKECMDGOALS)" "clean" --include $(DEP_FILES) -endif - -.PHONY: clean -clean: - @echo Making clean - $(SILENCE)$(RM) $(STUFF_TO_CLEAN) - $(SILENCE)rm -rf gcov objs #$(CPPUTEST_OBJS_DIR) - $(SILENCE)rm -rf $(CPPUTEST_LIB_DIR) - $(SILENCE)find . -name "*.gcno" | xargs rm -f - $(SILENCE)find . -name "*.gcda" | xargs rm -f - -#realclean gets rid of all gcov, o and d files in the directory tree -#not just the ones made by this makefile -.PHONY: realclean -realclean: clean - $(SILENCE)rm -rf gcov - $(SILENCE)find . -name "*.gdcno" | xargs rm -f - $(SILENCE)find . -name "*.[do]" | xargs rm -f - -gcov: test -ifeq ($(CPPUTEST_USE_VPATH), Y) - $(SILENCE)gcov --object-directory $(CPPUTEST_OBJS_DIR) $(SRC) >> $(GCOV_OUTPUT) 2>> $(GCOV_ERROR) -else - $(SILENCE)for d in $(SRC_DIRS) ; do \ - gcov --object-directory $(CPPUTEST_OBJS_DIR)/$$d $$d/*.c $$d/*.cpp >> $(GCOV_OUTPUT) 2>>$(GCOV_ERROR) ; \ - done - $(SILENCE)for f in $(SRC_FILES) ; do \ - gcov --object-directory $(CPPUTEST_OBJS_DIR)/$$f $$f >> $(GCOV_OUTPUT) 2>>$(GCOV_ERROR) ; \ - done -endif -# $(CPPUTEST_HOME)/scripts/filterGcov.sh $(GCOV_OUTPUT) $(GCOV_ERROR) $(GCOV_REPORT) $(TEST_OUTPUT) - /usr/share/cpputest/scripts/filterGcov.sh $(GCOV_OUTPUT) $(GCOV_ERROR) $(GCOV_REPORT) $(TEST_OUTPUT) - $(SILENCE)cat $(GCOV_REPORT) - $(SILENCE)mkdir -p gcov - $(SILENCE)mv *.gcov gcov - $(SILENCE)mv gcov_* gcov - @echo "See gcov directory for details" - -.PHONEY: format -format: - $(CPPUTEST_HOME)/scripts/reformat.sh $(PROJECT_HOME_DIR) - -.PHONEY: debug -debug: - @echo - @echo "Target Source files:" - @$(call debug_print_list,$(SRC)) - @echo "Target Object files:" - @$(call debug_print_list,$(OBJ)) - @echo "Test Source files:" - @$(call debug_print_list,$(TEST_SRC)) - @echo "Test Object files:" - @$(call debug_print_list,$(TEST_OBJS)) - @echo "Mock Source files:" - @$(call debug_print_list,$(MOCKS_SRC)) - @echo "Mock Object files:" - @$(call debug_print_list,$(MOCKS_OBJS)) - @echo "All Input Dependency files:" - @$(call debug_print_list,$(DEP_FILES)) - @echo Stuff to clean: - @$(call debug_print_list,$(STUFF_TO_CLEAN)) - @echo Includes: - @$(call debug_print_list,$(INCLUDES)) - --include $(OTHER_MAKEFILE_TO_INCLUDE) diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/makefile_defines.txt b/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/makefile_defines.txt deleted file mode 100755 index 8778747c53..0000000000 --- a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/makefile_defines.txt +++ /dev/null @@ -1,24 +0,0 @@ -#--- Inputs ----# -CPPUTEST_HOME = /usr -CPPUTEST_USE_EXTENSIONS = Y -CPPUTEST_USE_VPATH = Y -CPPUTEST_USE_GCOV = Y -CPP_PLATFORM = gcc -INCLUDE_DIRS =\ - .\ - ../common\ - ../stubs\ - ../../../..\ - ../../../../source\ - ../../../../nsdl-c\ - ../../../../yotta_modules/nanostack-libservice/mbed-client-libservice\ - ../../../../yotta_modules/mbed-trace\ - ../../../../yotta_modules/nanostack-randlib/mbed-client-randlib\ - ../../../../../libService/libService\ - ../../../../source/libCoap/src/include\ - ../../../../source/libNsdl/src/include\ - /usr/include\ - $(CPPUTEST_HOME)/include\ - -CPPUTESTFLAGS = -D__thumb2__ -w -CPPUTEST_CFLAGS += -std=gnu99 diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/run_tests b/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/run_tests deleted file mode 100755 index 5698cf246f..0000000000 --- a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/run_tests +++ /dev/null @@ -1,44 +0,0 @@ -#!/bin/bash -echo -echo Build libCoap unit tests -echo - -# Remember to add new test folder to Makefile -make clean -make all - -echo -echo Create results -echo -mkdir results - -find ./ -name '*.xml' | xargs cp -t ./results/ - -echo -echo Create coverage document -echo -mkdir coverages -cd coverages - -#copy the .gcda & .gcno for all test projects (no need to modify -#cp ../../../source/*.gc* . -#find ../ -name '*.gcda' | xargs cp -t . -#find ../ -name '*.gcno' | xargs cp -t . -#find . -name "test*" -type f -delete -#find . -name "*test*" -type f -delete -#find . -name "*stub*" -type f -delete -#rm -rf main.* - -lcov -q -d ../. -c -o app.info -lcov -q -r app.info "/test*" -o app.info -lcov -q -r app.info "/mbed-client-libservice*" -o app.info -lcov -q -r app.info "/usr*" -o app.info -genhtml --no-branch-coverage app.info -cd .. -echo -echo -echo -echo Have a nice bug hunt! -echo -echo -echo diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/sn_coap_builder/Makefile b/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/sn_coap_builder/Makefile deleted file mode 100755 index 82ef67b86f..0000000000 --- a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/sn_coap_builder/Makefile +++ /dev/null @@ -1,16 +0,0 @@ -include ../makefile_defines.txt - -COMPONENT_NAME = sn_coap_builder_unit -SRC_FILES = \ - ../../../../source/libCoap/src/sn_coap_builder.c - -TEST_SRC_FILES = \ - main.cpp \ - libCoap_builder_test.cpp \ - ../stubs/sn_coap_header_check_stub.c \ - ../stubs/sn_coap_parser_stub.c \ - -include ../MakefileWorker.mk - - - diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/sn_coap_builder/libCoap_builder_test.cpp b/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/sn_coap_builder/libCoap_builder_test.cpp deleted file mode 100644 index 7721f734d0..0000000000 --- a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/sn_coap_builder/libCoap_builder_test.cpp +++ /dev/null @@ -1,531 +0,0 @@ -/* - * Copyright (c) 2015 ARM Limited. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 - * Licensed under the Apache License, Version 2.0 (the License); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include "CppUTest/TestHarness.h" -#include -#include -#include "sn_nsdl.h" -#include "sn_coap_header.h" -#include "sn_coap_protocol_internal.h" - -#include "sn_coap_header_check_stub.h" -#include "sn_coap_parser_stub.h" - -sn_coap_hdr_s coap_header; -sn_coap_options_list_s option_list; -uint8_t buffer[356]; -uint8_t temp[10]; - -uint8_t retCounter = 0; - -static void *own_alloc(uint16_t size) -{ - if( retCounter > 0 ){ - retCounter--; - return malloc(size); - } - return NULL; -} - -static void own_free(void *ptr) -{ - free(ptr); -} - -TEST_GROUP(libCoap_builder) -{ - void setup() { - sn_coap_header_check_stub.expectedInt8 = 0; - retCounter = 0; - memset(&coap_header, 0, sizeof(sn_coap_hdr_s)); - memset(&option_list, 0, sizeof(sn_coap_options_list_s)); - - coap_header.options_list_ptr = &option_list; - coap_header.msg_type = COAP_MSG_TYPE_ACKNOWLEDGEMENT; - coap_header.msg_code = COAP_MSG_CODE_RESPONSE_CREATED; - coap_header.msg_id = 12; - } - - void teardown() { - - } -}; - -TEST(libCoap_builder, build_confirmable_response) -{ - struct coap_s handle; - sn_coap_hdr_s *response = NULL; - - handle.sn_coap_protocol_malloc = &own_alloc; - handle.sn_coap_protocol_free = &own_free; - - coap_header.msg_type = COAP_MSG_TYPE_RESET; - coap_header.msg_code = COAP_MSG_CODE_REQUEST_GET; - coap_header.msg_id = 12; - - //NULL pointer - CHECK(sn_coap_build_response(NULL, NULL, 0) == NULL); - CHECK(sn_coap_build_response(&handle, NULL, 0) == NULL); - CHECK(sn_coap_build_response(NULL, &coap_header, 0) == NULL); - CHECK(sn_coap_build_response(&handle, &coap_header, COAP_MSG_CODE_RESPONSE_CONTENT) == NULL); - - retCounter = 1; - CHECK(sn_coap_build_response(&handle, &coap_header, COAP_MSG_CODE_RESPONSE_CONTENT) == NULL); - - coap_header.msg_type = COAP_MSG_TYPE_CONFIRMABLE; - - retCounter = 2; - response = sn_coap_build_response(&handle, &coap_header, COAP_MSG_CODE_RESPONSE_CONTENT); - - CHECK(response != NULL); - CHECK(response->msg_type == COAP_MSG_TYPE_ACKNOWLEDGEMENT); - CHECK(response->msg_id == 12); - CHECK(response->msg_code == COAP_MSG_CODE_RESPONSE_CONTENT); - - own_free(response); -} - -TEST(libCoap_builder, build_non_confirmable_response) -{ - struct coap_s handle; - sn_coap_hdr_s *response = NULL; - uint8_t token_val = 0x99; - - handle.sn_coap_protocol_malloc = &own_alloc; - handle.sn_coap_protocol_free = &own_free; - - coap_header.msg_type = COAP_MSG_TYPE_NON_CONFIRMABLE; - coap_header.msg_code = COAP_MSG_CODE_REQUEST_GET; - coap_header.msg_id = 12; - coap_header.token_len = 1; - coap_header.token_ptr = &token_val; - - retCounter = 1; - CHECK( NULL == sn_coap_build_response(&handle, &coap_header, COAP_MSG_CODE_RESPONSE_CONTENT)); - - retCounter = 2; - response = sn_coap_build_response(&handle, &coap_header, COAP_MSG_CODE_RESPONSE_CONTENT); - - CHECK(response != NULL); - CHECK(response->msg_type == COAP_MSG_TYPE_NON_CONFIRMABLE); - CHECK(response->msg_code == COAP_MSG_CODE_RESPONSE_CONTENT); - CHECK(response->token_ptr != NULL); - CHECK(memcmp(response->token_ptr, coap_header.token_ptr, coap_header.token_len) == 0); - CHECK(response->token_len == coap_header.token_len); - - own_free(response->token_ptr); - response->token_ptr = NULL; - own_free(response); - response = NULL; -} - -TEST(libCoap_builder, build_message_negative_cases) -{ - // Null pointers as a parameter - CHECK(sn_coap_builder(NULL, NULL) == -2); - CHECK(sn_coap_builder(NULL, &coap_header) == -2); - CHECK(sn_coap_builder(buffer, NULL) == -2); - - // Invalid option length - coap_header.token_ptr = temp; - CHECK(sn_coap_builder(buffer, &coap_header) == -1); -} - -TEST(libCoap_builder, build_message_ok_cases) -{ - CHECK(sn_coap_builder(buffer, &coap_header) == 11); -} - -TEST(libCoap_builder, build_message_options_token) -{ - coap_header.token_ptr = temp; - coap_header.token_len = 2; - CHECK(sn_coap_builder(buffer, &coap_header) == 13); -} - -TEST(libCoap_builder, build_message_options_uri_path) -{ - coap_header.uri_path_ptr = temp; - coap_header.uri_path_len = 2; - CHECK(sn_coap_builder(buffer, &coap_header) == 11); -} - -TEST(libCoap_builder, build_message_options_content_type) -{ - coap_header.content_format = COAP_CT_TEXT_PLAIN; - CHECK(sn_coap_builder(buffer, &coap_header) == 11); -} - -TEST(libCoap_builder, build_message_options_max_age) -{ - coap_header.options_list_ptr->max_age = 1; - CHECK(sn_coap_builder(buffer, &coap_header) == 12); -} - -TEST(libCoap_builder, build_message_options_proxy_uri) -{ - coap_header.options_list_ptr->proxy_uri_ptr = temp; - coap_header.options_list_ptr->proxy_uri_len = 2; - CHECK(sn_coap_builder(buffer, &coap_header) == 14); -} - -TEST(libCoap_builder, build_message_options_etag) -{ - coap_header.options_list_ptr->etag_ptr = temp; - coap_header.options_list_ptr->etag_len = 2; - CHECK(sn_coap_builder(buffer, &coap_header) == 14); -} - -TEST(libCoap_builder, build_message_options_uri_host) -{ - coap_header.options_list_ptr->uri_host_ptr = temp; - coap_header.options_list_ptr->uri_host_len = 2; - CHECK(sn_coap_builder(buffer, &coap_header) == 14); -} - -TEST(libCoap_builder, build_message_options_location_path) -{ - coap_header.options_list_ptr->location_path_ptr = temp; - coap_header.options_list_ptr->location_path_len = 2; - CHECK(sn_coap_builder(buffer, &coap_header) == 14); -} - -TEST(libCoap_builder, build_message_options_uri_port) -{ - coap_header.options_list_ptr->uri_port = 2; - CHECK(sn_coap_builder(buffer, &coap_header) == 12); -} - - -TEST(libCoap_builder, build_message_options_location_query) -{ - coap_header.options_list_ptr->location_query_ptr = temp; - coap_header.options_list_ptr->location_query_len = 2; - CHECK(sn_coap_builder(buffer, &coap_header) == 14); -} - -TEST(libCoap_builder, build_message_options_observe) -{ - coap_header.options_list_ptr->observe = 0; - CHECK(sn_coap_builder(buffer, &coap_header) == 11); -} - - -TEST(libCoap_builder, build_message_options_accept) -{ - coap_header.options_list_ptr->accept = COAP_CT_TEXT_PLAIN; - CHECK(sn_coap_builder(buffer, &coap_header) == 11); -} - -TEST(libCoap_builder, build_message_options_uri_query) -{ - coap_header.options_list_ptr->uri_query_ptr = temp; - temp[0] = '1'; - temp[1] = '&'; - temp[2] = '2'; - temp[3] = '&'; - temp[4] = '3'; - temp[5] = '\0'; - coap_header.options_list_ptr->uri_query_len = 6; - uint8_t val = sn_coap_builder(buffer, &coap_header); - CHECK( val == 18); - memset(&temp, 0, 10); -} - - -TEST(libCoap_builder, build_message_options_block1) -{ - coap_header.options_list_ptr->block1 = 267; - CHECK(sn_coap_builder(buffer, &coap_header) == 13); -} - -TEST(libCoap_builder, build_message_options_block2) -{ - coap_header.options_list_ptr->block2 = 267; - - sn_coap_header_check_stub.expectedInt8 = 44; - CHECK(sn_coap_builder(buffer, &coap_header) == -1); - - sn_coap_header_check_stub.expectedInt8 = 0; - CHECK(sn_coap_builder(buffer, &coap_header) == 13); - - coap_header.options_list_ptr = NULL; //return from sn_coap_builder_options_build immediately - sn_coap_header_check_stub.expectedInt8 = 0; - CHECK( 5 == sn_coap_builder(buffer, &coap_header) ); -} - -TEST(libCoap_builder, sn_coap_builder_calc_needed_packet_data_size) -{ - CHECK(sn_coap_builder_calc_needed_packet_data_size(NULL) == 0); - - sn_coap_hdr_s header; - memset(&header, 0, sizeof(sn_coap_hdr_s)); - header.msg_type = COAP_MSG_TYPE_ACKNOWLEDGEMENT; - header.token_ptr = (uint8_t*)malloc(10); - header.token_len = 10; - CHECK(sn_coap_builder_calc_needed_packet_data_size(&header) == 0); - free(header.token_ptr); - header.token_ptr = (uint8_t*)malloc(6); - header.token_len = 6; - - //Test variations of sn_coap_builder_options_calc_option_size here --> - header.uri_path_ptr = (uint8_t*)malloc(290); - memset(header.uri_path_ptr, '1', 290); - header.uri_path_len = 290; - header.uri_path_ptr[5] = '/'; - header.uri_path_ptr[285] = '/'; - - CHECK(sn_coap_builder_calc_needed_packet_data_size(&header) == 0); - - header.uri_path_ptr[285] = '1'; - header.uri_path_ptr[170] = '/'; - - header.content_format = sn_coap_content_format_e(0xFFFF22); - CHECK(sn_coap_builder_calc_needed_packet_data_size(&header) == 0); - - header.content_format = COAP_CT_TEXT_PLAIN; - CHECK(sn_coap_builder_calc_needed_packet_data_size(&header) == 304); - - sn_coap_options_list_s opt_list; - memset(&opt_list, 0, sizeof(sn_coap_options_list_s)); - header.options_list_ptr = &opt_list; - - header.options_list_ptr->accept = sn_coap_content_format_e(0xFFFF22); - CHECK(sn_coap_builder_calc_needed_packet_data_size(&header) == 0); - - header.options_list_ptr->observe = COAP_OBSERVE_NONE; - header.options_list_ptr->uri_port = COAP_OPTION_URI_PORT_NONE; - free(header.uri_path_ptr); - header.uri_path_ptr = NULL; - header.content_format = COAP_CT_NONE; - header.options_list_ptr->max_age = COAP_OPTION_MAX_AGE_DEFAULT; - header.options_list_ptr->accept = COAP_CT_TEXT_PLAIN; - CHECK(sn_coap_builder_calc_needed_packet_data_size(&header) == 14); - - header.options_list_ptr->max_age = 6; - CHECK(sn_coap_builder_calc_needed_packet_data_size(&header) == 16); - - //proxy uri tests (4) - header.options_list_ptr->proxy_uri_ptr = (uint8_t*)malloc(1800); - header.options_list_ptr->proxy_uri_len = 1800; - header.options_list_ptr->max_age = COAP_OPTION_MAX_AGE_DEFAULT; - header.options_list_ptr->accept = COAP_CT_NONE; - - CHECK(sn_coap_builder_calc_needed_packet_data_size(&header) == 0); - header.options_list_ptr->proxy_uri_len = 6; - header.options_list_ptr->etag_ptr = (uint8_t*)malloc(4); - header.options_list_ptr->etag_len = 0; - CHECK(sn_coap_builder_calc_needed_packet_data_size(&header) == 0); - - header.options_list_ptr->proxy_uri_len = 14; - CHECK(sn_coap_builder_calc_needed_packet_data_size(&header) == 0); - - // init now the buffer up to 4 bytes, as it will be accessed - memset(header.options_list_ptr->etag_ptr, 0, 4); - - header.options_list_ptr->proxy_uri_len = 281; - header.options_list_ptr->block1 = COAP_OPTION_BLOCK_NONE; - header.options_list_ptr->block2 = COAP_OPTION_BLOCK_NONE; - header.options_list_ptr->etag_len = 4; - CHECK(sn_coap_builder_calc_needed_packet_data_size(&header) == 300); - - header.options_list_ptr->uri_host_ptr = (uint8_t*)malloc(6); - header.options_list_ptr->uri_host_len = 0; - CHECK(sn_coap_builder_calc_needed_packet_data_size(&header) == 0); - - header.options_list_ptr->uri_host_len = 4; - header.options_list_ptr->location_path_ptr = (uint8_t*)calloc(270, 1); - header.options_list_ptr->location_path_len = 270; - CHECK(sn_coap_builder_calc_needed_packet_data_size(&header) == 0); - - header.options_list_ptr->uri_host_len = 44; - CHECK(sn_coap_builder_calc_needed_packet_data_size(&header) == 0); - - header.options_list_ptr->location_path_len = 27; - header.options_list_ptr->uri_port = 0xffff22; - CHECK(sn_coap_builder_calc_needed_packet_data_size(&header) == 0); - - header.options_list_ptr->uri_port = 6; - CHECK(sn_coap_builder_calc_needed_packet_data_size(&header) == 377); - - header.options_list_ptr->location_query_ptr = (uint8_t*)calloc(277, 1); - header.options_list_ptr->location_query_len = 277; - CHECK(sn_coap_builder_calc_needed_packet_data_size(&header) == 0); - - header.options_list_ptr->location_query_len = 27; - header.options_list_ptr->observe = 0; - free(header.options_list_ptr->location_path_ptr); - header.options_list_ptr->location_path_ptr = NULL; - header.options_list_ptr->location_path_len = 0; - CHECK(sn_coap_builder_calc_needed_packet_data_size(&header) == 379); - - header.options_list_ptr->uri_query_ptr = (uint8_t*)malloc(6); - header.options_list_ptr->uri_query_len = 0; - CHECK(sn_coap_builder_calc_needed_packet_data_size(&header) == 0); - - // init the 4 bytes to something useful, leave rest uninitialized to let valgrind warn if builder is processing past buffer - memset(header.options_list_ptr->uri_query_ptr, 0, 4); - header.options_list_ptr->uri_query_len = 4; - header.options_list_ptr->block2 = -1; - header.options_list_ptr->observe = 0xFFFFFF22; - header.options_list_ptr->uri_port = COAP_OPTION_URI_PORT_NONE; - free(header.options_list_ptr->etag_ptr); - header.options_list_ptr->etag_ptr = NULL; - header.options_list_ptr->etag_len = 0; - CHECK(sn_coap_builder_calc_needed_packet_data_size(&header) == 0); - - header.options_list_ptr->observe = COAP_OBSERVE_NONE; - free(header.options_list_ptr->uri_host_ptr); - header.options_list_ptr->uri_host_ptr = NULL; - CHECK(sn_coap_builder_calc_needed_packet_data_size(&header) == 330); - - header.options_list_ptr->observe = 1; - CHECK(sn_coap_builder_calc_needed_packet_data_size(&header) == 331); - - header.options_list_ptr->block2 = 0xFFFFFF22; - header.options_list_ptr->block1 = -1; - CHECK(sn_coap_builder_calc_needed_packet_data_size(&header) == 0); - - header.options_list_ptr->block2 = 267; - free(header.options_list_ptr->location_query_ptr); - header.options_list_ptr->location_query_ptr = NULL; - free(header.options_list_ptr->uri_query_ptr); - header.options_list_ptr->uri_query_ptr = NULL; - CHECK(sn_coap_builder_calc_needed_packet_data_size(&header) == 300); - - header.options_list_ptr->block1 = 0xFFFFFF22; - header.payload_len = 1; - CHECK(0 == sn_coap_builder_calc_needed_packet_data_size(&header)); - - header.options_list_ptr->block1 = 267; - header.payload_len = 1; - header.options_list_ptr->block2 = COAP_OPTION_BLOCK_NONE; - CHECK(302 == sn_coap_builder_calc_needed_packet_data_size(&header)); - - header.options_list_ptr->block1 = COAP_OPTION_BLOCK_NONE; - header.options_list_ptr->size1 = 266; - header.options_list_ptr->use_size1 = true; - - CHECK(sn_coap_builder_calc_needed_packet_data_size(&header) == 303); - - header.options_list_ptr->size2 = 266; - header.options_list_ptr->use_size2 = true; - header.payload_len = 1; - CHECK(306 == sn_coap_builder_calc_needed_packet_data_size(&header)); - - header.options_list_ptr->use_size1 = false; - header.options_list_ptr->use_size2 = false; - // <-- - free(header.options_list_ptr->location_query_ptr); - free(header.options_list_ptr->location_path_ptr); - free(header.options_list_ptr->uri_host_ptr); - free(header.options_list_ptr->etag_ptr); - free(header.options_list_ptr->proxy_uri_ptr); - header.options_list_ptr->location_query_ptr = NULL; - header.options_list_ptr->location_path_ptr = NULL; - header.options_list_ptr->uri_host_ptr = NULL; - header.options_list_ptr->etag_ptr = NULL; - header.options_list_ptr->proxy_uri_ptr = NULL; - CHECK(14 == sn_coap_builder_calc_needed_packet_data_size(&header)); - free(header.options_list_ptr->uri_query_ptr); - - //Test sn_coap_builder_options_calculate_jump_need "else" case - header.options_list_ptr = NULL; - uint16_t val = sn_coap_builder_calc_needed_packet_data_size(&header); - CHECK( 12 == val ); - - free(header.uri_path_ptr); - free(header.token_ptr); -} - - -TEST(libCoap_builder, sn_coap_builder_options_build_add_one_option) -{ - coap_header.options_list_ptr->proxy_uri_ptr = (uint8_t*)malloc(280); - memset(coap_header.options_list_ptr->proxy_uri_ptr, '1', 280); - coap_header.options_list_ptr->proxy_uri_len = 2; - sn_coap_header_check_stub.expectedInt8 = 0; - CHECK(sn_coap_builder(buffer, &coap_header) == 14); - - coap_header.options_list_ptr->proxy_uri_len = 27; - sn_coap_header_check_stub.expectedInt8 = 0; - CHECK(40 == sn_coap_builder(buffer, &coap_header)); - - coap_header.options_list_ptr->proxy_uri_len = 277; - sn_coap_header_check_stub.expectedInt8 = 0; - CHECK(291 == sn_coap_builder(buffer, &coap_header)); - - free(coap_header.options_list_ptr->proxy_uri_ptr); - coap_header.options_list_ptr->proxy_uri_ptr = NULL; - coap_header.options_list_ptr->proxy_uri_len = 0; -} - -TEST(libCoap_builder, sn_coap_builder_options_build_add_zero_length_option) -{ - coap_header.options_list_ptr->proxy_uri_ptr = (uint8_t*)malloc(280); - memset(coap_header.options_list_ptr->proxy_uri_ptr, '1', 280); - coap_header.options_list_ptr->proxy_uri_len = 2; - sn_coap_header_check_stub.expectedInt8 = 0; - coap_header.options_list_ptr->observe = 1; - int16_t val = sn_coap_builder(buffer, &coap_header); - CHECK(val == 15); - - free(coap_header.options_list_ptr->proxy_uri_ptr); -} - -TEST(libCoap_builder, sn_coap_builder_options_get_option_part_position) -{ - sn_coap_hdr_s header; - memset(&header, 0, sizeof(sn_coap_hdr_s)); - sn_coap_options_list_s opt_list; - memset(&opt_list, 0, sizeof(sn_coap_options_list_s)); - header.options_list_ptr = &opt_list; - header.options_list_ptr->accept = COAP_CT_TEXT_PLAIN; - uint16_t val = sn_coap_builder(buffer, &header); - CHECK(val == 11); - - header.options_list_ptr->accept = COAP_CT_TEXT_PLAIN; - val = sn_coap_builder(buffer, &header); - CHECK(val == 11); -} - -TEST(libCoap_builder, sn_coap_builder_payload_build) -{ - sn_coap_hdr_s header; - memset(&header, 0, sizeof(sn_coap_hdr_s)); - header.payload_ptr = (uint8_t*)malloc(5); - header.payload_len = 5; - sn_coap_options_list_s opt_list; - memset(&opt_list, 0, sizeof(sn_coap_options_list_s)); - header.options_list_ptr = &opt_list; - header.options_list_ptr->accept = COAP_CT_TEXT_PLAIN; - uint16_t val = sn_coap_builder(buffer, &header); - CHECK(val == 17); - - header.content_format = COAP_CT_NONE; - header.options_list_ptr->uri_port = -1; - header.options_list_ptr->observe = COAP_OBSERVE_NONE; - header.options_list_ptr->accept = COAP_CT_NONE; - header.options_list_ptr->block2 = COAP_OPTION_BLOCK_NONE; - header.options_list_ptr->block1 = 13; - header.options_list_ptr->use_size1 = true; - header.options_list_ptr->use_size2 = true; - header.options_list_ptr->max_age = COAP_OPTION_MAX_AGE_DEFAULT; - - val = sn_coap_builder(buffer, &header); - CHECK(val == 16); - - free(header.payload_ptr); -} diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/sn_coap_builder/main.cpp b/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/sn_coap_builder/main.cpp deleted file mode 100644 index 8011201522..0000000000 --- a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/sn_coap_builder/main.cpp +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c) 2015 ARM Limited. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 - * Licensed under the Apache License, Version 2.0 (the License); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "CppUTest/CommandLineTestRunner.h" -#include "CppUTest/TestPlugin.h" -#include "CppUTest/TestRegistry.h" -#include "CppUTestExt/MockSupportPlugin.h" - - - -int main(int ac, char **av) -{ - return CommandLineTestRunner::RunAllTests(ac, av); -} - -IMPORT_TEST_GROUP(libCoap_builder); diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/sn_coap_header_check/Makefile b/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/sn_coap_header_check/Makefile deleted file mode 100755 index 53623cd184..0000000000 --- a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/sn_coap_header_check/Makefile +++ /dev/null @@ -1,14 +0,0 @@ -include ../makefile_defines.txt - -COMPONENT_NAME = sn_coap_header_check_unit -SRC_FILES = \ - ../../../../source/libCoap/src/sn_coap_header_check.c - -TEST_SRC_FILES = \ - main.cpp \ - libCoap_header_test.cpp \ - -include ../MakefileWorker.mk - -CPPUTESTFLAGS += -DFEA_TRACE_SUPPORT - diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/sn_coap_header_check/libCoap_header_test.cpp b/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/sn_coap_header_check/libCoap_header_test.cpp deleted file mode 100644 index 688da4147b..0000000000 --- a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/sn_coap_header_check/libCoap_header_test.cpp +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2015 ARM Limited. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 - * Licensed under the Apache License, Version 2.0 (the License); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include "CppUTest/TestHarness.h" -#include -#include -#include "sn_nsdl.h" -#include "sn_coap_protocol.h" -#include "sn_nsdl_lib.h" -#include "sn_coap_header_internal.h" - - -TEST_GROUP(libCoap_header_check) -{ - void setup() { - - } - - void teardown() { - - } -}; - -TEST(libCoap_header_check, header_check) -{ - sn_coap_hdr_s coap_header; - - memset(&coap_header, 0, sizeof(sn_coap_hdr_s)); - coap_header.msg_type = COAP_MSG_TYPE_CONFIRMABLE; - coap_header.msg_code = COAP_MSG_CODE_REQUEST_GET; - - /* Happy-happy case */ - CHECK(sn_coap_header_validity_check(&coap_header, (coap_version_e)COAP_VERSION_1) == 0); - - - CHECK(sn_coap_header_validity_check(&coap_header, (coap_version_e) 0) == -1); - - coap_header.msg_type = (sn_coap_msg_type_e)0x40; - - CHECK(sn_coap_header_validity_check(&coap_header, (coap_version_e)COAP_VERSION_1) == -1); - - coap_header.msg_type = (sn_coap_msg_type_e)COAP_MSG_TYPE_CONFIRMABLE; - coap_header.msg_code = (sn_coap_msg_code_e)5; - - CHECK(sn_coap_header_validity_check(&coap_header, (coap_version_e)COAP_VERSION_1) == -1); -} diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/sn_coap_header_check/main.cpp b/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/sn_coap_header_check/main.cpp deleted file mode 100644 index 2195410940..0000000000 --- a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/sn_coap_header_check/main.cpp +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c) 2015 ARM Limited. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 - * Licensed under the Apache License, Version 2.0 (the License); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "CppUTest/CommandLineTestRunner.h" -#include "CppUTest/TestPlugin.h" -#include "CppUTest/TestRegistry.h" -#include "CppUTestExt/MockSupportPlugin.h" - - - -int main(int ac, char **av) -{ - return CommandLineTestRunner::RunAllTests(ac, av); -} - -IMPORT_TEST_GROUP(libCoap_header_check); diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/sn_coap_parser/Makefile b/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/sn_coap_parser/Makefile deleted file mode 100644 index 41230e994d..0000000000 --- a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/sn_coap_parser/Makefile +++ /dev/null @@ -1,17 +0,0 @@ -include ../makefile_defines.txt - -COMPONENT_NAME = sn_coap_parser_unit - -#This must be changed manually -SRC_FILES = \ - ../../../../source/libCoap/src/sn_coap_parser.c - -TEST_SRC_FILES = \ - main.cpp \ - sn_coap_parsertest.cpp \ - test_sn_coap_parser.c \ - -include ../MakefileWorker.mk - -CPPUTESTFLAGS += -DFEA_TRACE_SUPPORT - diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/sn_coap_parser/main.cpp b/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/sn_coap_parser/main.cpp deleted file mode 100644 index d0539a2e5d..0000000000 --- a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/sn_coap_parser/main.cpp +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Copyright (c) 2015 ARM. All rights reserved. - */ - -#include "CppUTest/CommandLineTestRunner.h" -#include "CppUTest/TestPlugin.h" -#include "CppUTest/TestRegistry.h" -#include "CppUTestExt/MockSupportPlugin.h" -int main(int ac, char** av) -{ - return CommandLineTestRunner::RunAllTests(ac, av); -} - -IMPORT_TEST_GROUP(sn_coap_parser); - diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/sn_coap_parser/sn_coap_parsertest.cpp b/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/sn_coap_parser/sn_coap_parsertest.cpp deleted file mode 100644 index 418f57668e..0000000000 --- a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/sn_coap_parser/sn_coap_parsertest.cpp +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2015 ARM. All rights reserved. - */ -#include "CppUTest/TestHarness.h" -#include "test_sn_coap_parser.h" - -TEST_GROUP(sn_coap_parser) -{ - void setup() - { - } - - void teardown() - { - } -}; - -TEST(sn_coap_parser, test_sn_coap_parser) -{ - CHECK(test_sn_coap_parser()); -} - -TEST(sn_coap_parser, test_sn_coap_parser_options_parsing) -{ - CHECK(test_sn_coap_parser_options_parsing()); -} - -TEST(sn_coap_parser, test_sn_coap_parser_options_parsing_switches) -{ - CHECK(test_sn_coap_parser_options_parsing_switches()); -} - -TEST(sn_coap_parser, test_sn_coap_parser_options_count_needed_memory_multiple_option) -{ - CHECK(test_sn_coap_parser_options_count_needed_memory_multiple_option()); -} - -TEST(sn_coap_parser, test_sn_coap_parser_options_parse_multiple_options) -{ - CHECK(test_sn_coap_parser_options_parse_multiple_options()); -} - -TEST(sn_coap_parser, test_sn_coap_parser_parsing) -{ - CHECK(test_sn_coap_parser_parsing()); -} - -TEST(sn_coap_parser, test_sn_coap_parser_release_allocated_coap_msg_mem) -{ - CHECK(test_sn_coap_parser_release_allocated_coap_msg_mem()); -} diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/sn_coap_parser/test_sn_coap_parser.c b/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/sn_coap_parser/test_sn_coap_parser.c deleted file mode 100644 index 2d5ff85c52..0000000000 --- a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/sn_coap_parser/test_sn_coap_parser.c +++ /dev/null @@ -1,985 +0,0 @@ -/* - * Copyright (c) 2015 ARM. All rights reserved. - */ -#include "test_sn_coap_parser.h" -#include -#include "stdint.h" -#include "sn_nsdl.h" -#include "sn_coap_header.h" -#include "sn_coap_header_internal.h" -#include "sn_coap_protocol_internal.h" -#include - -int retCounter = 0; - -void* myMalloc(uint16_t size) -{ - if( retCounter > 0 ){ - retCounter--; - return malloc(size); - }else { - return NULL; - } -} - -void myFree(void* ptr){ - free(ptr); -} - -bool test_sn_coap_parser() -{ - if( sn_coap_parser_alloc_message(NULL) ) { - return false; - } - - if( sn_coap_parser_alloc_options(NULL, NULL) ) { - return false; - } - - retCounter = 0; - bool ret = true; - // use zero-initialized buffer for tests - uint8_t* ptr = (uint8_t*)calloc(20, 1); - assert(ptr); - sn_coap_hdr_s * hdr = sn_coap_parser(NULL, 8, ptr, NULL); - if( hdr != NULL ){ - free(hdr); - ret = false; - } - - if( ret ){ - struct coap_s* coap = (struct coap_s*)malloc(sizeof(struct coap_s)); - coap->sn_coap_protocol_malloc = myMalloc; - coap->sn_coap_protocol_free = myFree; - retCounter = 0; - coap_version_e* ver = (coap_version_e*)malloc(sizeof(coap_version_e)); - hdr = sn_coap_parser(coap, 8, ptr, ver); - if( hdr != NULL ){ - free(hdr); - ret = false; - } - - if( ret ){ - retCounter = 1; - hdr = sn_coap_parser(coap, 8, ptr, ver); - if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){ - free(hdr); - ret = false; - } - if (hdr) - sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr); - } - free(ver); - free(coap); - - } - - free(ptr); - return ret; -} - -bool test_sn_coap_parser_options_parsing() -{ - bool ret = true; - uint8_t* ptr = (uint8_t*)malloc(20); - memset(ptr, 0, 20); - ptr[0] = 9; - struct coap_s* coap = (struct coap_s*)malloc(sizeof(struct coap_s)); - coap->sn_coap_protocol_malloc = myMalloc; - coap->sn_coap_protocol_free = myFree; - - retCounter = 1; - coap_version_e* ver = (coap_version_e*)malloc(sizeof(coap_version_e)); - sn_coap_hdr_s * hdr = sn_coap_parser(coap, 8, ptr, ver); - if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){ - ret = false; - }else{ - if (hdr) - sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr); - ptr[0] = 1; - retCounter = 1; - hdr = sn_coap_parser(coap, 8, ptr, ver); - if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){ - ret = false; - }else{ - if (hdr) - sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr); - ptr[5] = 255; //this point is sufficient to test parsing of payload - retCounter = 2; - hdr = sn_coap_parser(coap, 6, ptr, ver); - if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){ - ret = false; - }else{ - if (hdr) - sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr); - ptr[5] = 239; - retCounter = 2; - hdr = sn_coap_parser(coap, 8, ptr, ver); - if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){ - ret = false; - }else{ - if (hdr) - sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr); - ptr[5] = 254; //15 | 14 - retCounter = 2; - hdr = sn_coap_parser(coap, 8, ptr, ver); - if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){ - ret = false; - }else{ - if (hdr) - sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr); - ptr[5] = 238; //14 | 14 - ptr[6] = 6; - ptr[7] = 7; - retCounter = 2; - hdr = sn_coap_parser(coap, 8, ptr, ver); - if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){ - ret = false; - }else{ - if (hdr) - sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr); - ptr[5] = 221; //13 | 13 - ptr[6] = 6; - retCounter = 2; - hdr = sn_coap_parser(coap, 8, ptr, ver); - if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){ - ret = false; - } else { - if (hdr) - sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr); - } - } - } - } - } - } - } - - free(ver); - free(coap); - free(ptr); - return ret; -} - -bool test_sn_coap_parser_options_parsing_switches() -{ - bool ret = true; - uint8_t* ptr = (uint8_t*)malloc(20); - memset(ptr, 0, 20); - struct coap_s* coap = (struct coap_s*)malloc(sizeof(struct coap_s)); - coap->sn_coap_protocol_malloc = myMalloc; - coap->sn_coap_protocol_free = myFree; - coap_version_e* ver = (coap_version_e*)malloc(sizeof(coap_version_e)); - - //These should be tested: - /* - COAP_OPTION_IF_MATCH = 1, - COAP_OPTION_URI_HOST = 3, - COAP_OPTION_ETAG = 4, - COAP_OPTION_IF_NONE_MATCH = 5, - COAP_OPTION_OBSERVE = 6, - COAP_OPTION_URI_PORT = 7, - COAP_OPTION_LOCATION_PATH = 8, - COAP_OPTION_URI_PATH = 11, - COAP_OPTION_CONTENT_FORMAT = 12, - COAP_OPTION_MAX_AGE = 14, - COAP_OPTION_URI_QUERY = 15, - COAP_OPTION_ACCEPT = 17, - COAP_OPTION_LOCATION_QUERY = 20, - COAP_OPTION_BLOCK2 = 23, - COAP_OPTION_BLOCK1 = 27, - COAP_OPTION_SIZE2 = 28, - COAP_OPTION_PROXY_URI = 35, - COAP_OPTION_PROXY_SCHEME = 39, - COAP_OPTION_SIZE1 = 60 - */ - - ptr[0] = 1; - - retCounter = 2; - ptr[5] = 17; //1 | 1 (number | length) - sn_coap_hdr_s * hdr = sn_coap_parser(coap, 8, ptr, ver); - if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){ - return false; - } - - if (hdr) - sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr); - ptr[5] = 51; //1 | 3 - retCounter = 2; - hdr = sn_coap_parser(coap, 8, ptr, ver); - if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){ - return false; - } - - if (hdr) - sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr); - ptr[5] = 48; //3 | 0 - retCounter = 3; - hdr = sn_coap_parser(coap, 8, ptr, ver); - if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){ - return false; - } - - if (hdr) - sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr); - ptr[5] = 51; //3 | 3 - retCounter = 3; - hdr = sn_coap_parser(coap, 8, ptr, ver); - if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){ - return false; - } - - if (hdr) - sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr); - ptr[5] = 51; //3 | 3 - retCounter = 4; - //overflows, so not valid data - hdr = sn_coap_parser(coap, 8, ptr, ver); - if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){ - return false; - } - if (hdr) - sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr); - ptr[5] = 68; //4 | 4 - retCounter = 3; - hdr = sn_coap_parser(coap, 8, ptr, ver); - if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){ - return false; - } - if (hdr) - sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr); - ptr[5] = 68; //4 | 4 - retCounter = 4; - //This should test if (ret_status >= 0) {} - hdr = sn_coap_parser(coap, 8, ptr, ver); - if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){ - return false; - } - if (hdr) - sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr); - ptr[5] = 85; //5 | 5 - retCounter = 2; - hdr = sn_coap_parser(coap, 8, ptr, ver); - if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){ - return false; - } - if (hdr) - sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr); - ptr[5] = 102; //6 | 6 - retCounter = 3; - hdr = sn_coap_parser(coap, 8, ptr, ver); - if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){ - return false; - } - if (hdr) - sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr); - ptr[5] = 97; //6 | 1 - retCounter = 3; - hdr = sn_coap_parser(coap, 8, ptr, ver); - if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){ - return false; - } - if (hdr) - sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr); - ptr[5] = 97; //6 | 1 - retCounter = 4; - hdr = sn_coap_parser(coap, 8, ptr, ver); - if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){ - return false; - } - if (hdr) - sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr); - ptr[5] = 119; //7 | 7 - retCounter = 3; - hdr = sn_coap_parser(coap, 8, ptr, ver); - if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){ - return false; - } - if (hdr) - sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr); - ptr[5] = 113; //7 | 1 - retCounter = 3; - hdr = sn_coap_parser(coap, 8, ptr, ver); - if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){ - return false; - } - if (hdr) - sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr); - ptr[5] = 113; //7 | 1 - retCounter = 4; - hdr = sn_coap_parser(coap, 8, ptr, ver); - if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){ - return false; - } - if (hdr) - sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr); - ptr[5] = 128; //8 | 8 - retCounter = 3; - hdr = sn_coap_parser(coap, 8, ptr, ver); - if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){ - return false; - } - if (hdr) - sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr); - ptr[5] = 136; //8 | 8 - retCounter = 4; - //This should test if (ret_status >= 0) {} - hdr = sn_coap_parser(coap, 8, ptr, ver); - if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){ - return false; - } - if (hdr) - sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr); - ptr[5] = 187; //11 | 11 - retCounter = 2; - hdr = sn_coap_parser(coap, 8, ptr, ver); - if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){ - return false; - } - if (hdr) - sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr); - ptr[5] = 187; //11 | 11 - retCounter = 3; - //This should test if (ret_status >= 0) {} - hdr = sn_coap_parser(coap, 8, ptr, ver); - if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){ - return false; - } - if (hdr) - sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr); - ptr[5] = 204; //12 | 12 - retCounter = 2; - hdr = sn_coap_parser(coap, 8, ptr, ver); - if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){ - return false; - } - if (hdr) - sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr); - ptr[5] = 193; //12 | 1 - retCounter = 2; - hdr = sn_coap_parser(coap, 8, ptr, ver); - if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){ - return false; - } - if (hdr) - sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr); - ptr[5] = 193; //12 | 1 - retCounter = 3; - hdr = sn_coap_parser(coap, 8, ptr, ver); - if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){ - return false; - } - if (hdr) - sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr); - ptr[5] = 216; //13 | 8 - ptr[6] = 1; //1 -> 14 - retCounter = 3; - hdr = sn_coap_parser(coap, 8, ptr, ver); - if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){ - return false; - } - if (hdr) - sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr); - ptr[5] = 209; //13 | 1 - ptr[6] = 1; //1 -> 14 - retCounter = 2; - hdr = sn_coap_parser(coap, 8, ptr, ver); - if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){ - return false; - } - if (hdr) - sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr); - ptr[5] = 210; //13 | 2 - ptr[6] = 1; //1 -> 14 - retCounter = 3; - hdr = sn_coap_parser(coap, 6, ptr, ver); - if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){ - return false; - } - if (hdr) - sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr); - ptr[5] = 208; //13 | 0 - ptr[6] = 2; //2 -> 15 ??? - retCounter = 3; - hdr = sn_coap_parser(coap, 8, ptr, ver); - if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){ - return false; - } - if (hdr) - sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr); - ptr[5] = 209; //13 | 1 - ptr[6] = 2; //2 -> 15 ??? - retCounter = 5; - //This should test if (ret_status >= 0) {} - hdr = sn_coap_parser(coap, 7, ptr, ver); - if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){ - return false; - } - if (hdr) - sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr); - ptr[5] = 208; //13 | 0 - ptr[6] = 4; - retCounter = 3; - hdr = sn_coap_parser(coap, 8, ptr, ver); - if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){ - return false; - } - if (hdr) - sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr); - ptr[5] = 209; //13 | 1 - ptr[6] = 4; - retCounter = 5; - //This should test if (ret_status >= 0) {} - hdr = sn_coap_parser(coap, 7, ptr, ver); - if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){ - return false; - } - if (hdr) - sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr); - ptr[5] = 208; //13 | 0 - ptr[6] = 7; - retCounter = 3; - hdr = sn_coap_parser(coap, 8, ptr, ver); - if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){ - return false; - } - if (hdr) - sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr); - ptr[5] = 209; //13 | 1 - ptr[6] = 7; - retCounter = 5; - //This should test if (ret_status >= 0) {} - hdr = sn_coap_parser(coap, 7, ptr, ver); - if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){ - return false; - } - if (hdr) - sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr); - ptr[5] = 216; //13 | 8 - ptr[6] = 10; - retCounter = 3; - hdr = sn_coap_parser(coap, 8, ptr, ver); - if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){ - return false; - } - if (hdr) - sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr); - ptr[5] = 209; //13 | 1 - ptr[6] = 10; - retCounter = 2; - hdr = sn_coap_parser(coap, 8, ptr, ver); - if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){ - return false; - } - if (hdr) - sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr); - ptr[5] = 210; //13 | 2 - ptr[6] = 10; - retCounter = 3; - hdr = sn_coap_parser(coap, 8, ptr, ver); - if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){ - return false; - } - if (hdr) - sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr); - ptr[5] = 216; //13 | 8 - ptr[6] = 14; - retCounter = 3; - hdr = sn_coap_parser(coap, 8, ptr, ver); - if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){ - return false; - } - if (hdr) - sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr); - ptr[5] = 209; //13 | 1 - ptr[6] = 14; - retCounter = 2; - hdr = sn_coap_parser(coap, 8, ptr, ver); - if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){ - return false; - } - if (hdr) - sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr); - ptr[5] = 210; //13 | 2 - ptr[6] = 14; - retCounter = 3; - hdr = sn_coap_parser(coap, 8, ptr, ver); - if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){ - return false; - } - if (hdr) - sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr); - ptr[5] = 208; //13 | 0 - ptr[6] = 22; - retCounter = 3; - hdr = sn_coap_parser(coap, 8, ptr, ver); - if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){ - return false; - } - if (hdr) - sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr); - ptr[5] = 209; //13 | 1 - ptr[6] = 22; - retCounter = 3; - hdr = sn_coap_parser(coap, 8, ptr, ver); - if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){ - return false; - } - if (hdr) - sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr); - ptr[5] = 209; //13 | 1 - ptr[6] = 22; - retCounter = 4; - hdr = sn_coap_parser(coap, 7, ptr, ver); - if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){ - return false; - } - if (hdr) - sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr); - ptr[5] = 208; //13 | 0 - ptr[6] = 26; - retCounter = 2; - hdr = sn_coap_parser(coap, 8, ptr, ver); - if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){ - return false; - } - if (hdr) - sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr); - ptr[5] = 208; //13 | 0 - ptr[6] = 47; - retCounter = 2; - hdr = sn_coap_parser(coap, 8, ptr, ver); - if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){ - return false; - } - if (hdr) - sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr); - ptr[5] = 216; //13 | 8 - ptr[6] = 47; - retCounter = 3; - hdr = sn_coap_parser(coap, 8, ptr, ver); - if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){ - return false; - } - if (hdr) - sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr); - ptr[5] = 216; //13 | 8 - ptr[6] = 47; - retCounter = 3; - hdr = sn_coap_parser(coap, 8, ptr, ver); - if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){ - return false; - } - if (hdr) - sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr); - ptr[5] = 210; //13 | 2 - ptr[6] = 47; - retCounter = 4; - hdr = sn_coap_parser(coap, 8, ptr, ver); - if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){ - return false; - } - if (hdr) - sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr); - ptr[5] = 216; //13 | 8 - ptr[6] = 15; - retCounter = 3; - hdr = sn_coap_parser(coap, 8, ptr, ver); - if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){ - return false; - } - if (hdr) - sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr); - ptr[5] = 210; //13 | 2 - ptr[6] = 15; - retCounter = 4; - hdr = sn_coap_parser(coap, 8, ptr, ver); - if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){ - return false; - } - if (hdr) - sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr); - ptr[5] = 216; //13 | 8 - ptr[6] = 15; - retCounter = 3; - hdr = sn_coap_parser(coap, 8, ptr, ver); - if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){ - return false; - } - if (hdr) - sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr); - - ptr[5] = 209; //13 | 1 - ptr[6] = 10; - retCounter = 4; - hdr = sn_coap_parser(coap, 8, ptr, ver); - if( hdr == NULL ){ - return false; - } - - sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr); - - - free(ver); - free(coap); - free(ptr); - return ret; -} - -bool test_sn_coap_parser_options_count_needed_memory_multiple_option() -{ - bool ret = true; - uint8_t* ptr = (uint8_t*)malloc(65635); - memset(ptr, 0, 65635); - struct coap_s* coap = (struct coap_s*)malloc(sizeof(struct coap_s)); - coap->sn_coap_protocol_malloc = myMalloc; - coap->sn_coap_protocol_free = myFree; - coap_version_e* ver = (coap_version_e*)malloc(sizeof(coap_version_e)); - - //Some of these should be tested: - //These 6 will test sn_coap_parser_options_count_needed_memory_multiple_option overflows - ptr[0] = 1; - ptr[5] = 0x4d; //4 | 13 - ptr[6] = 254; - retCounter = 4; - //This should test if (ret_status >= 0) {} - sn_coap_hdr_s * hdr = sn_coap_parser(coap, 8, ptr, ver); - if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){ - ret = false; - goto end; - } - if (hdr) - sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr); - - ptr[0] = 1; - ptr[5] = 0x8d; //4 | 13 - ptr[6] = 254; - retCounter = 4; - //This should test if (ret_status >= 0) {} - hdr = sn_coap_parser(coap, 8, ptr, ver); - if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){ - ret = false; - goto end; - } - if (hdr) - sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr); - - ptr[0] = 1; - ptr[5] = 0xbd; - ptr[6] = 254; - retCounter = 4; - //This should test if (ret_status >= 0) {} - hdr = sn_coap_parser(coap, 8, ptr, ver); - if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){ - ret = false; - goto end; - } - if (hdr) - sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr); - - ptr[0] = 1; - ptr[5] = 0xdd; - ptr[6] = 2; - ptr[7] = 254; - retCounter = 4; - //This should test if (ret_status >= 0) {} - hdr = sn_coap_parser(coap, 8, ptr, ver); - if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){ - ret = false; - goto end; - } - if (hdr) - sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr); - - ptr[0] = 1; - ptr[5] = 0xdd; - ptr[6] = 4; - ptr[7] = 254; - retCounter = 4; - //This should test if (ret_status >= 0) {} - hdr = sn_coap_parser(coap, 8, ptr, ver); - if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){ - ret = false; - goto end; - } - if (hdr) - sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr); - - ptr[0] = 1; - ptr[5] = 0xdd; - ptr[6] = 7; - ptr[7] = 254; - retCounter = 4; - //This should test if (ret_status >= 0) {} - hdr = sn_coap_parser(coap, 8, ptr, ver); - if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){ - ret = false; - goto end; - } - if (hdr) - sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr); - - ptr[0] = 1; - ptr[5] = 0x81; - ptr[6] = 0x00; - ptr[7] = 0x20; - retCounter = 4; - //This should test if (ret_status >= 0) {} - hdr = sn_coap_parser(coap, 8, ptr, ver); - if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){ - ret = false; - goto end; - } - if (hdr) - sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr); - - ptr[0] = 1; - ptr[5] = 0x81; - ptr[6] = 0x00; - ptr[7] = 0x00; - retCounter = 4; - //This should test if (ret_status >= 0) {} - hdr = sn_coap_parser(coap, 6, ptr, ver); - if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){ - ret = false; - goto end; - } - if (hdr) - sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr); - - ptr[0] = 1; - ptr[5] = 0x81; - ptr[6] = 0x00; - ptr[7] = 0x0d; - retCounter = 4; - //This should test if (ret_status >= 0) {} - hdr = sn_coap_parser(coap, 8, ptr, ver); - if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){ - ret = false; - goto end; - } - if (hdr) - sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr); - - ptr[0] = 1; - ptr[5] = 0x81; - ptr[6] = 0x00; - ptr[7] = 0x0e; - retCounter = 4; - //This should test if (ret_status >= 0) {} - hdr = sn_coap_parser(coap, 8, ptr, ver); - if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){ - ret = false; - goto end; - } - if (hdr) - sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr); - - ptr[0] = 1; - ptr[5] = 0x81; - ptr[6] = 0x00; - ptr[7] = 0x0f; - retCounter = 4; - //This should test if (ret_status >= 0) {} - hdr = sn_coap_parser(coap, 8, ptr, ver); - if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){ - ret = false; - goto end; - } - if (hdr) - sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr); - -end: - free(ver); - free(coap); - free(ptr); - return ret; -} - -bool test_sn_coap_parser_options_parse_multiple_options() -{ - bool ret = true; - uint8_t* ptr = (uint8_t*)malloc(33); - memset(ptr, 0, 33); - struct coap_s* coap = (struct coap_s*)malloc(sizeof(struct coap_s)); - coap->sn_coap_protocol_malloc = myMalloc; - coap->sn_coap_protocol_free = myFree; - coap_version_e* ver = (coap_version_e*)malloc(sizeof(coap_version_e)); - - ptr[0] = 0x60; - ptr[4] = 0x82; //opt 8 & len 2 - ptr[5] = 0x00; - ptr[6] = 0x00; - ptr[7] = 0x0d; - ptr[8] = 0x00; - ptr[9] = 0x6f; - ptr[10] = 0x6d; - ptr[11] = 0x61; - ptr[12] = 0x69; - ptr[13] = 0x6e; - retCounter = 4; - sn_coap_hdr_s *hdr = sn_coap_parser(coap, 14, ptr, ver); - if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){ - ret = false; - goto end2; - } - if (hdr) - sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr); - - - ptr[7] = 0x0e; - ptr[8] = 0xff; - ptr[9] = 0x00; - retCounter = 4; - hdr = sn_coap_parser(coap, 14, ptr, ver); - if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){ - ret = false; - goto end2; - } - if (hdr) - sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr); - - ptr[0] = 0x60; - ptr[4] = 0x42; - ptr[5] = 0x00; - ptr[6] = 0x00; - ptr[7] = 0x06; - ptr[8] = 0x00; - ptr[9] = 0x6f; - ptr[10] = 0x6d; - ptr[11] = 0x61; - ptr[12] = 0x69; - ptr[13] = 0x6e; - retCounter = 4; - hdr = sn_coap_parser(coap, 14, ptr, ver); - if( hdr == NULL ){ - ret = false; - goto end2; - }else{ - sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr); - } - - free(ptr); - ptr = (uint8_t*)malloc(10); - memset(ptr, 0, 10); - - //this should be checked after bug http://jira.arm.com/browse/IOTCLT-244 is fixed - //This is illegal options message, but gets parsed though - //this test passes because parsing of data still fails (expected) - ptr[0] = 0x60; - ptr[4] = 0x82; - ptr[5] = 0x00; - ptr[6] = 0x00; - ptr[7] = 0x06; - ptr[8] = 0x00; - ptr[9] = 0x6f; - retCounter = 4; - hdr = sn_coap_parser(coap, 10, ptr, ver); - if( !hdr || (hdr && hdr->coap_status != COAP_STATUS_PARSER_ERROR_IN_HEADER) ){ - ret = false; - goto end2; - } - if (hdr) - sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr); - -end2: - free(ver); - free(coap); - free(ptr); - return ret; -} - -bool test_sn_coap_parser_parsing() -{ - bool ret = true; - uint8_t* ptr = (uint8_t*)malloc(33); - memset(ptr, 0, 33); - struct coap_s* coap = (struct coap_s*)malloc(sizeof(struct coap_s)); - coap->sn_coap_protocol_malloc = myMalloc; - coap->sn_coap_protocol_free = myFree; - coap_version_e* ver = (coap_version_e*)malloc(sizeof(coap_version_e)); - - ptr[0] = 0x60; - ptr[4] = 0x42; - ptr[5] = 0x00; - ptr[6] = 0x00; - retCounter = 4; - - //TODO: add sn_coap_parser_parsing related stuff - ptr[7] = 0x20; - ptr[8] = 0x00; - - sn_coap_hdr_s *hdr = NULL; - - //this should test parsing without payload marker, but it is not possible -// hdr = sn_coap_parser(coap, 9, ptr, ver); - -// if( hdr != NULL ){ -// ret = false; -// goto end3; -// } -// sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr); - - ptr[0] = 0x60; - ptr[4] = 0x42; - ptr[5] = 0x00; - ptr[6] = 0x00; - ptr[7] = 0x06; - ptr[8] = 0x00; - ptr[9] = 0x6f; - ptr[10] = 0x6d; - ptr[11] = 0x61; - ptr[12] = 0x69; - ptr[13] = 0x6e; - ptr[14] = 0xff; - ptr[15] = 0x1; - retCounter = 4; - - hdr = sn_coap_parser(coap, 16, ptr, ver); - - if( hdr == NULL ){ - ret = false; - goto end3; - } - - sn_coap_parser_release_allocated_coap_msg_mem(coap, hdr); - -end3: - free(ver); - free(coap); - free(ptr); - return ret; -} - -bool test_sn_coap_parser_release_allocated_coap_msg_mem() -{ - struct coap_s* coap = (struct coap_s*)malloc(sizeof(struct coap_s)); - coap->sn_coap_protocol_malloc = myMalloc; - coap->sn_coap_protocol_free = myFree; - retCounter = 99; - - sn_coap_parser_release_allocated_coap_msg_mem( NULL, NULL ); - - sn_coap_hdr_s* ptr = (sn_coap_hdr_s*)myMalloc(sizeof(sn_coap_hdr_s)); - ptr->uri_path_ptr = (uint8_t*)malloc(sizeof(uint8_t)); - ptr->token_ptr = (uint8_t*)malloc(sizeof(uint8_t)); - //ptr->payload_ptr = (uint8_t*)malloc(sizeof(uint8_t)); - ptr->options_list_ptr = (sn_coap_options_list_s*)myMalloc(sizeof(sn_coap_options_list_s)); - - ptr->options_list_ptr->max_age = 1; - ptr->options_list_ptr->proxy_uri_ptr = (uint8_t*)malloc(sizeof(uint8_t)); - ptr->options_list_ptr->etag_ptr = (uint8_t*)malloc(sizeof(uint8_t)); - ptr->options_list_ptr->uri_host_ptr = (uint8_t*)malloc(sizeof(uint8_t)); - ptr->options_list_ptr->location_path_ptr = (uint8_t*)malloc(sizeof(uint8_t)); - ptr->options_list_ptr->uri_port = 8; - ptr->options_list_ptr->location_query_ptr = (uint8_t*)malloc(sizeof(uint8_t)); - ptr->options_list_ptr->observe = 0; - ptr->options_list_ptr->uri_query_ptr = (uint8_t*)malloc(sizeof(uint8_t)); - - sn_coap_parser_release_allocated_coap_msg_mem( coap, ptr ); - - free(coap); - return true; //this is a memory leak check, so that will pass/fail -} - diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/sn_coap_parser/test_sn_coap_parser.h b/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/sn_coap_parser/test_sn_coap_parser.h deleted file mode 100644 index 4bf29dbd5d..0000000000 --- a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/sn_coap_parser/test_sn_coap_parser.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2015 ARM. All rights reserved. - */ -#ifndef TEST_SN_COAP_PARSER_H -#define TEST_SN_COAP_PARSER_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -bool test_sn_coap_parser(); - -//These splits above test to keep things more simpler -bool test_sn_coap_parser_options_parsing(); -bool test_sn_coap_parser_options_parsing_switches(); - -bool test_sn_coap_parser_options_count_needed_memory_multiple_option(); - -bool test_sn_coap_parser_options_parse_multiple_options(); - -bool test_sn_coap_parser_parsing(); -//<- split - -bool test_sn_coap_parser_release_allocated_coap_msg_mem(); - - -#ifdef __cplusplus -} -#endif - -#endif // TEST_SN_COAP_PARSER_H - diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/sn_coap_protocol/Makefile b/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/sn_coap_protocol/Makefile deleted file mode 100644 index 9510b8c8c0..0000000000 --- a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/sn_coap_protocol/Makefile +++ /dev/null @@ -1,23 +0,0 @@ -include ../makefile_defines.txt - -MBED_CLIENT_USER_CONFIG_FILE ?= $(CURDIR)/test_config.h -COMPONENT_NAME = sn_coap_protocol_unit -SRC_FILES = \ - ../../../../source/libCoap/src/sn_coap_protocol.c - -TEST_SRC_FILES = \ - main.cpp \ - libCoap_protocol_test.cpp \ - ../stubs/sn_coap_builder_stub.c \ - ../stubs/sn_coap_parser_stub.c \ - ../stubs/sn_coap_header_check_stub.c \ - ../stubs/ns_list_stub.c \ - ../stubs/randLIB_stub.cpp \ - -include ../MakefileWorker.mk - -# the config is needed for client application compilation too -override CFLAGS += -DMBED_CLIENT_USER_CONFIG_FILE='<$(MBED_CLIENT_USER_CONFIG_FILE)>' -override CXXFLAGS += -DMBED_CLIENT_USER_CONFIG_FILE='<$(MBED_CLIENT_USER_CONFIG_FILE)>' - -CPPUTESTFLAGS += -DYOTTA_CFG_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE=16 -DENABLE_RESENDINGS=1 -DSN_COAP_MAX_INCOMING_BLOCK_MESSAGE_SIZE=65535 diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/sn_coap_protocol/libCoap_protocol_test.cpp b/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/sn_coap_protocol/libCoap_protocol_test.cpp deleted file mode 100644 index 823dac7aab..0000000000 --- a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/sn_coap_protocol/libCoap_protocol_test.cpp +++ /dev/null @@ -1,2280 +0,0 @@ -/* - * Copyright (c) 2015 ARM Limited. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 - * Licensed under the Apache License, Version 2.0 (the License); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include "CppUTest/TestHarness.h" -#include -#include -#include -#include "sn_nsdl.h" -#include "sn_coap_protocol.h" -#include "sn_nsdl_lib.h" -#include "sn_coap_header_internal.h" -#include "sn_coap_protocol_internal.h" - -#include "sn_coap_builder_stub.h" -#include "sn_coap_parser_stub.h" -#include "sn_coap_header_check_stub.h" - - -int retCounter = 0; -static coap_s *coap_handle = NULL; -void myFree(void* addr); -void* myMalloc(uint16_t size); -uint8_t null_tx_cb(uint8_t *a, uint16_t b, sn_nsdl_addr_s *c, void *d); - -TEST_GROUP(libCoap_protocol) -{ - void setup() { - retCounter = 1; - coap_handle = sn_coap_protocol_init(myMalloc, myFree, null_tx_cb, NULL); - } - - void teardown() { - retCounter = 0; - sn_coap_protocol_destroy(coap_handle); - } -}; - -void* myMalloc(uint16_t size) -{ - if( retCounter > 0 ){ - retCounter--; - return malloc(size); - }else { - return NULL; - } -} - -void myFree(void* addr){ - if( addr ){ - free(addr); - } -} - -uint8_t null_tx_cb(uint8_t *a, uint16_t b, sn_nsdl_addr_s *c, void *d) -{ - return 0; -} - -int8_t null_rx_cb(sn_coap_hdr_s *a, sn_nsdl_addr_s *b, void *c) -{ - -} - -TEST(libCoap_protocol, sn_coap_protocol_destroy) -{ - CHECK( -1 == sn_coap_protocol_destroy(NULL)); - struct coap_s *handle = (struct coap_s *)malloc(sizeof(struct coap_s)); - handle->sn_coap_protocol_free = &myFree; - handle->sn_coap_protocol_malloc = &myMalloc; - ns_list_init(&handle->linked_list_resent_msgs); - coap_send_msg_s *msg_ptr = (coap_send_msg_s*)malloc(sizeof(coap_send_msg_s)); - memset(msg_ptr, 0, sizeof(coap_send_msg_s)); - msg_ptr->send_msg_ptr = (sn_nsdl_transmit_s*)malloc(sizeof(sn_nsdl_transmit_s)); - memset(msg_ptr->send_msg_ptr, 0 , sizeof(sn_nsdl_transmit_s)); - msg_ptr->send_msg_ptr->uri_path_ptr = (uint8_t*)malloc(2); - msg_ptr->send_msg_ptr->uri_path_len = 2; - - ns_list_add_to_end(&handle->linked_list_resent_msgs, msg_ptr); -#if SN_COAP_DUPLICATION_MAX_MSGS_COUNT - ns_list_init(&handle->linked_list_duplication_msgs); -#endif -#if SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE - ns_list_init(&handle->linked_list_blockwise_sent_msgs); - ns_list_init(&handle->linked_list_blockwise_received_payloads); -#endif - CHECK( 0 == sn_coap_protocol_destroy(handle)); -} - -TEST(libCoap_protocol, sn_coap_protocol_init_null_func_ptrs) -{ - POINTERS_EQUAL(NULL, sn_coap_protocol_init(NULL, NULL, NULL, NULL)); -} - -TEST(libCoap_protocol, sn_coap_protocol_init_null_malloc) -{ - POINTERS_EQUAL(NULL, sn_coap_protocol_init(myMalloc, myFree, null_tx_cb, NULL)); - - retCounter = 1; - struct coap_s * handle = sn_coap_protocol_init(myMalloc, myFree, null_tx_cb, NULL); - CHECK(NULL != handle); - - sn_coap_protocol_destroy(handle); -} - -TEST(libCoap_protocol, sn_coap_protocol_set_block_size) -{ -#if SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE - CHECK( 0 == sn_coap_protocol_set_block_size(coap_handle,16) ); - CHECK( -1 == sn_coap_protocol_set_block_size(NULL,1) ); -#endif - CHECK( -1 == sn_coap_protocol_set_block_size(coap_handle,1) ); -} - -TEST(libCoap_protocol, sn_coap_protocol_set_duplicate_buffer_size) -{ -#if SN_COAP_DUPLICATION_MAX_MSGS_COUNT - CHECK( 0 == sn_coap_protocol_set_duplicate_buffer_size(coap_handle,3)); - CHECK( -1 == sn_coap_protocol_set_duplicate_buffer_size(NULL,3)); -#endif - CHECK( -1 == sn_coap_protocol_set_duplicate_buffer_size(coap_handle,999)); -} - -TEST(libCoap_protocol, sn_coap_protocol_set_retransmission_parameters) -{ -#if ENABLE_RESENDINGS - CHECK( 0 == sn_coap_protocol_set_retransmission_parameters(coap_handle,3,0) ); - CHECK( 0 == sn_coap_protocol_set_retransmission_parameters(coap_handle,3, 10) ); - CHECK( -1 == sn_coap_protocol_set_retransmission_parameters(NULL,3,0) ); -#endif - CHECK( -1 == sn_coap_protocol_set_retransmission_parameters(coap_handle,999,0) ) -} - -TEST(libCoap_protocol, sn_coap_protocol_set_retransmission_buffer) -{ -#if ENABLE_RESENDINGS - CHECK( 0 == sn_coap_protocol_set_retransmission_buffer(coap_handle,3,3) ); - CHECK( -1 == sn_coap_protocol_set_retransmission_buffer(NULL,3,3) ); -#endif - CHECK( -1 == sn_coap_protocol_set_retransmission_buffer(coap_handle,3,999) ); -} - -//TEST(libCoap_protocol, sn_coap_protocol_clear_retransmission_buffer) -//{ -// sn_coap_protocol_clear_retransmission_buffer(); -//} -#include - -TEST(libCoap_protocol, sn_coap_protocol_delete_retransmission) -{ -#if ENABLE_RESENDINGS - retCounter = 6; - sn_nsdl_addr_s dst_addr_ptr; - sn_coap_hdr_s src_coap_msg_ptr; - uint8_t temp_addr[4] = {0}; - uint8_t dst_packet_data_ptr[4] = {0x40, 0x00, 0x00, 0x63}; - - memset(&dst_addr_ptr, 0, sizeof(sn_nsdl_addr_s)); - memset(&src_coap_msg_ptr, 0, sizeof(sn_coap_hdr_s)); - - dst_addr_ptr.addr_ptr = temp_addr; - dst_addr_ptr.addr_len = 4; - dst_addr_ptr.type = SN_NSDL_ADDRESS_TYPE_IPV4; - - struct coap_s * handle = sn_coap_protocol_init(myMalloc, myFree, null_tx_cb, NULL); - - CHECK( -1 == sn_coap_protocol_delete_retransmission(NULL, 0)); - - CHECK( -2 == sn_coap_protocol_delete_retransmission(handle, 0)); - - sn_coap_builder_stub.expectedInt16 = 4; - - CHECK( 0 < sn_coap_protocol_build(handle, &dst_addr_ptr, dst_packet_data_ptr, &src_coap_msg_ptr, NULL)); - - CHECK( 0 == sn_coap_protocol_delete_retransmission(handle, 99)); - - sn_coap_protocol_destroy(handle); -#endif -} - -TEST(libCoap_protocol, sn_coap_protocol_build) -{ - retCounter = 1; - struct coap_s * handle = sn_coap_protocol_init(myMalloc, myFree, null_tx_cb, NULL); - sn_nsdl_addr_s addr; - memset(&addr, 0, sizeof(sn_nsdl_addr_s)); - sn_coap_hdr_s hdr; - memset(&hdr, 0, sizeof(sn_coap_hdr_s)); - - uint8_t* dst_packet_data_ptr = (uint8_t*)malloc(5); - memset(dst_packet_data_ptr, '1', 5); - - CHECK( -2 == sn_coap_protocol_build(NULL, NULL, NULL, NULL, NULL)); - - CHECK( -2 == sn_coap_protocol_build(handle, &addr, dst_packet_data_ptr, &hdr, NULL)); - - hdr.msg_type = COAP_MSG_TYPE_CONFIRMABLE; - hdr.msg_id = 0; - - addr.addr_ptr = (uint8_t*)malloc(5); - memset(addr.addr_ptr, '1', 5); - - sn_coap_builder_stub.expectedInt16 = 0; - - CHECK( 0 == sn_coap_protocol_build(handle, &addr, dst_packet_data_ptr, &hdr, NULL)); - - hdr.payload_ptr = (uint8_t*)malloc(SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE + 20); - memset(hdr.payload_ptr, '1', SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE + 20); - hdr.payload_len = SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE + 20; - - sn_coap_builder_stub.expectedInt16 = -3; -// CHECK( -2 == sn_coap_protocol_build(handle, &addr, dst_packet_data_ptr, &hdr, NULL)); - - retCounter = 0; - hdr.options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); - memset(hdr.options_list_ptr, 0, sizeof(sn_coap_options_list_s)); - hdr.options_list_ptr->block1 = 67777; - - CHECK( -3 == sn_coap_protocol_build(handle, &addr, dst_packet_data_ptr, &hdr, NULL)); - free(hdr.options_list_ptr); - hdr.options_list_ptr = NULL; - - retCounter = 2; - CHECK( -3 == sn_coap_protocol_build(handle, &addr, dst_packet_data_ptr, &hdr, NULL)); - - free(hdr.options_list_ptr); - hdr.options_list_ptr = NULL; - - hdr.payload_len = SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE + 20; - hdr.msg_code = COAP_MSG_CODE_RESPONSE_BAD_REQUEST; - hdr.options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); - memset(hdr.options_list_ptr, 0, sizeof(sn_coap_options_list_s)); - hdr.options_list_ptr->block2 = 1; - retCounter = 0; - - CHECK( -3 == sn_coap_protocol_build(handle, &addr, dst_packet_data_ptr, &hdr, NULL)); - free(hdr.options_list_ptr); - hdr.options_list_ptr = NULL; - - free(hdr.payload_ptr); - hdr.payload_ptr = NULL; - hdr.payload_len = 0; - - //Test variations of sn_coap_convert_block_size here --> - for( int i=0; i < 8; i++ ){ - uint16_t multiplier = 16*pow(2, i); - sn_coap_protocol_set_block_size(handle,multiplier); - hdr.payload_ptr = (uint8_t*)malloc(multiplier + 20); - memset(hdr.payload_ptr, '1', multiplier + 20); - hdr.payload_len = multiplier + 20; - retCounter = 2; - hdr.msg_code = COAP_MSG_CODE_RESPONSE_BAD_REQUEST; - CHECK( -3 == sn_coap_protocol_build(handle, &addr, dst_packet_data_ptr, &hdr, NULL)); - hdr.msg_code = COAP_MSG_CODE_EMPTY; - - free(hdr.options_list_ptr); - hdr.options_list_ptr = NULL; - - free(hdr.payload_ptr); - hdr.payload_ptr = NULL; - hdr.payload_len = 0; - } - sn_coap_protocol_set_block_size(handle,SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE); - - // <-- Test variations of sn_coap_convert_block_size here - - retCounter = 1; - sn_coap_builder_stub.expectedInt16 = -1; - CHECK( -1 == sn_coap_protocol_build(handle, &addr, dst_packet_data_ptr, &hdr, NULL)); - - retCounter = 1; - sn_coap_builder_stub.expectedInt16 = 1; - CHECK( 1 == sn_coap_protocol_build(handle, &addr, dst_packet_data_ptr, &hdr, NULL)); - - hdr.msg_code = COAP_MSG_CODE_EMPTY; - - retCounter = 2; - sn_coap_builder_stub.expectedInt16 = 1; - CHECK( 1 == sn_coap_protocol_build(handle, &addr, dst_packet_data_ptr, &hdr, NULL)); - - retCounter = 3; - sn_coap_builder_stub.expectedInt16 = 1; - CHECK( 1 == sn_coap_protocol_build(handle, &addr, dst_packet_data_ptr, &hdr, NULL)); - - retCounter = 4; - sn_coap_builder_stub.expectedInt16 = 1; - CHECK( 1 == sn_coap_protocol_build(handle, &addr, dst_packet_data_ptr, &hdr, NULL)); - - retCounter = 5; - sn_coap_builder_stub.expectedInt16 = 1; - CHECK( 1 == sn_coap_protocol_build(handle, &addr, dst_packet_data_ptr, &hdr, NULL)); - - // Test second SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE --> - hdr.payload_ptr = (uint8_t*)malloc(SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE + 20); - memset(hdr.payload_ptr, '1', SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE + 20); - hdr.payload_len = SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE + 20; - - retCounter = 2; - sn_coap_builder_stub.expectedInt16 = 1; - CHECK( 1 == sn_coap_protocol_build(handle, &addr, dst_packet_data_ptr, &hdr, NULL)); - free(hdr.payload_ptr); - - hdr.payload_ptr = (uint8_t*)malloc(SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE + 20); - memset(hdr.payload_ptr, '1', SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE + 20); - hdr.payload_len = SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE + 20; - - retCounter = 4; - sn_coap_builder_stub.expectedInt16 = 1; - CHECK( 1 == sn_coap_protocol_build(handle, &addr, dst_packet_data_ptr, &hdr, NULL)); - - free(hdr.payload_ptr); - hdr.payload_ptr = (uint8_t*)malloc(UINT16_MAX); - memset(hdr.payload_ptr, '1', UINT16_MAX); - hdr.payload_len = UINT16_MAX; - - retCounter = 5; - sn_coap_builder_stub.expectedInt16 = 1; - CHECK( 1 == sn_coap_protocol_build(handle, &addr, dst_packet_data_ptr, &hdr, NULL)); - - free(hdr.payload_ptr); - hdr.payload_ptr = (uint8_t*)malloc(UINT16_MAX - 1); - memset(hdr.payload_ptr, '1', UINT16_MAX - 1); - hdr.payload_len = UINT16_MAX - 1; - - retCounter = 5; - sn_coap_builder_stub.expectedInt16 = 1; - CHECK( 1 == sn_coap_protocol_build(handle, &addr, dst_packet_data_ptr, &hdr, NULL)); - - sn_coap_protocol_destroy(handle); - handle = NULL; - retCounter = 1; - handle = sn_coap_protocol_init(myMalloc, myFree, null_tx_cb, NULL); - free(hdr.options_list_ptr); - hdr.options_list_ptr = NULL; - //Test sn_coap_protocol_copy_header here --> - retCounter = 6; - sn_coap_builder_stub.expectedInt16 = 1; - hdr.payload_len = SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE + 20; - CHECK( -2 == sn_coap_protocol_build(handle, &addr, dst_packet_data_ptr, &hdr, NULL)); - - free(hdr.options_list_ptr); - hdr.options_list_ptr = NULL; - - sn_coap_hdr_s* hdr2 = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); - memset(hdr2, 0, sizeof(sn_coap_hdr_s)); - hdr2->msg_type = COAP_MSG_TYPE_NON_CONFIRMABLE; - hdr2->uri_path_ptr = (uint8_t*)malloc(3); - hdr2->uri_path_len = 3; - hdr2->token_ptr = (uint8_t*)malloc(3); - hdr2->token_len = 3; - hdr2->content_format = COAP_CT_TEXT_PLAIN; - - hdr2->options_list_ptr = (sn_coap_options_list_s *)malloc(sizeof(sn_coap_options_list_s)); - memset(hdr2->options_list_ptr, 0, sizeof(sn_coap_options_list_s)); - hdr2->options_list_ptr->accept = COAP_CT_TEXT_PLAIN; - hdr2->options_list_ptr->block1 = 67777; - hdr2->options_list_ptr->block2 = 67777; - hdr2->options_list_ptr->etag_ptr = (uint8_t*)malloc(3); - hdr2->options_list_ptr->etag_len = 3; - hdr2->options_list_ptr->location_path_ptr = (uint8_t*)malloc(3); - hdr2->options_list_ptr->location_path_len = 3; - hdr2->options_list_ptr->location_query_ptr = (uint8_t*)malloc(3); - hdr2->options_list_ptr->location_query_len = 3; - hdr2->options_list_ptr->max_age = 3; - hdr2->options_list_ptr->observe = 0; - hdr2->options_list_ptr->proxy_uri_ptr = (uint8_t*)malloc(3); - hdr2->options_list_ptr->proxy_uri_len = 3; - hdr2->options_list_ptr->uri_host_ptr = (uint8_t*)malloc(3); - hdr2->options_list_ptr->uri_host_len = 3; - hdr2->options_list_ptr->uri_port = 3; - hdr2->options_list_ptr->uri_query_ptr = (uint8_t*)malloc(3); - hdr2->options_list_ptr->uri_query_len = 3; - hdr2->options_list_ptr->use_size1 = true; - hdr2->options_list_ptr->size1 = 0xFFFF01; - - int buff_len = SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE + 20; - hdr2->payload_ptr = (uint8_t*)malloc(buff_len); - - for( int i=0; i < 8; i++ ){ - retCounter = 1 + i; - sn_coap_builder_stub.expectedInt16 = 1; - hdr2->payload_len = buff_len; - int8_t rett = sn_coap_protocol_build(handle, &addr, dst_packet_data_ptr, hdr2, NULL); - CHECK( -2 == rett ); - } - - retCounter = 11; - sn_coap_builder_stub.expectedInt16 = 1; - hdr2->payload_len = buff_len; - CHECK( 1 == sn_coap_protocol_build(handle, &addr, dst_packet_data_ptr, hdr2, NULL)); - - retCounter = 19; - sn_coap_builder_stub.expectedInt16 = 1; - hdr2->payload_len = buff_len; - CHECK( 1 == sn_coap_protocol_build(handle, &addr, dst_packet_data_ptr, hdr2, NULL)); - - free(hdr2->payload_ptr); - sn_coap_parser_release_allocated_coap_msg_mem(handle, hdr2); - hdr2 = NULL; - - //<-- Test sn_coap_protocol_copy_header here - - hdr.msg_code = COAP_MSG_CODE_REQUEST_GET; - retCounter = 5; - sn_coap_builder_stub.expectedInt16 = 1; - hdr.payload_len = 0; - CHECK( 1 == sn_coap_protocol_build(handle, &addr, dst_packet_data_ptr, &hdr, NULL)); - - sn_coap_protocol_destroy(handle); - handle = NULL; - retCounter = 1; - handle = sn_coap_protocol_init(myMalloc, myFree, null_tx_cb, NULL); - - retCounter = 6; - sn_coap_builder_stub.expectedInt16 = 1; - hdr.payload_len = 0; - CHECK( -2 == sn_coap_protocol_build(handle, &addr, dst_packet_data_ptr, &hdr, NULL)); - - retCounter = 7; - sn_coap_builder_stub.expectedInt16 = 1; - hdr.payload_len = 0; - CHECK( 1 == sn_coap_protocol_build(handle, &addr, dst_packet_data_ptr, &hdr, NULL)); - - free(hdr.payload_ptr); - hdr.payload_ptr = NULL; - hdr.payload_len = 0; - - hdr.msg_code = COAP_MSG_CODE_EMPTY; - - // <-- Test second SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE - - free(addr.addr_ptr); - free(dst_packet_data_ptr); - sn_coap_protocol_destroy(handle); -} - -TEST(libCoap_protocol, sn_coap_protocol_parse) -{ - CHECK( NULL == sn_coap_protocol_parse(NULL, NULL, 0, NULL, NULL) ); - - retCounter = 1; - struct coap_s * handle = sn_coap_protocol_init(myMalloc, myFree, null_tx_cb, NULL); - sn_nsdl_addr_s* addr = (sn_nsdl_addr_s*)malloc(sizeof(sn_nsdl_addr_s)); - memset(addr, 0, sizeof(sn_nsdl_addr_s)); - - addr->addr_ptr = (uint8_t*)malloc(5); - - uint8_t *packet_data_ptr = (uint8_t*)malloc(5); - uint16_t packet_data_len = 5; - - sn_coap_parser_stub.expectedHeader = NULL; - CHECK( NULL == sn_coap_protocol_parse(handle, addr, packet_data_len, packet_data_ptr, NULL) ); - - sn_coap_parser_stub.expectedHeader = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_parser_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_header_check_stub.expectedInt8 = 1; - sn_coap_parser_stub.expectedHeader->coap_status = COAP_STATUS_PARSER_ERROR_IN_HEADER; - CHECK( NULL == sn_coap_protocol_parse(handle, addr, packet_data_len, packet_data_ptr, NULL) ); - - sn_coap_parser_stub.expectedHeader = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_parser_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_header_check_stub.expectedInt8 = 1; - sn_coap_parser_stub.expectedHeader->msg_code = sn_coap_msg_code_e(COAP_MSG_CODE_RESPONSE_PROXYING_NOT_SUPPORTED + 60); - - CHECK( NULL == sn_coap_protocol_parse(handle, addr, packet_data_len, packet_data_ptr, NULL) ); - - sn_coap_parser_stub.expectedHeader = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_parser_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_header_check_stub.expectedInt8 = 0; - - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_CONFIRMABLE; - sn_coap_parser_stub.expectedHeader->msg_code = COAP_MSG_CODE_EMPTY; - - CHECK( NULL == sn_coap_protocol_parse(handle, addr, packet_data_len, packet_data_ptr, NULL) ); - - //Test sn_coap_handle_blockwise_message, block1 != NULL --> - sn_coap_protocol_set_duplicate_buffer_size(handle,1); - - sn_coap_parser_stub.expectedHeader = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_parser_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_ACKNOWLEDGEMENT; - sn_coap_parser_stub.expectedHeader->msg_id = 4; - - sn_coap_options_list_s* list = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); - memset(list, 0, sizeof(sn_coap_options_list_s)); - sn_coap_parser_stub.expectedHeader->options_list_ptr = list; - sn_coap_parser_stub.expectedHeader->options_list_ptr->block1 = 1; - sn_coap_parser_stub.expectedHeader->msg_id = 4; - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_CONFIRMABLE; - sn_coap_parser_stub.expectedHeader->msg_code = COAP_MSG_CODE_REQUEST_GET; - - sn_coap_hdr_s *ret = sn_coap_protocol_parse(handle, addr, packet_data_len, packet_data_ptr, NULL); - CHECK( NULL == ret ); - - sn_coap_parser_stub.expectedHeader = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_parser_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_ACKNOWLEDGEMENT; - sn_coap_parser_stub.expectedHeader->msg_id = 4; - - list = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); - memset(list, 0, sizeof(sn_coap_options_list_s)); - sn_coap_parser_stub.expectedHeader->options_list_ptr = list; - sn_coap_parser_stub.expectedHeader->options_list_ptr->block1 = 1; - sn_coap_parser_stub.expectedHeader->msg_id = 4; - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_CONFIRMABLE; - sn_coap_parser_stub.expectedHeader->msg_code = COAP_MSG_CODE_REQUEST_GET; - uint8_t* payload = (uint8_t*)malloc(5); - sn_coap_parser_stub.expectedHeader->payload_ptr = payload; - sn_coap_parser_stub.expectedHeader->payload_len = 5; - - retCounter = 1; - ret = sn_coap_protocol_parse(handle, addr, packet_data_len, packet_data_ptr, NULL); - CHECK( NULL == ret ); - free(payload); - - sn_coap_parser_stub.expectedHeader = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_parser_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_ACKNOWLEDGEMENT; - sn_coap_parser_stub.expectedHeader->msg_id = 4; - - list = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); - memset(list, 0, sizeof(sn_coap_options_list_s)); - sn_coap_parser_stub.expectedHeader->options_list_ptr = list; - sn_coap_parser_stub.expectedHeader->options_list_ptr->block1 = 1; - sn_coap_parser_stub.expectedHeader->msg_id = 4; - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_CONFIRMABLE; - sn_coap_parser_stub.expectedHeader->msg_code = COAP_MSG_CODE_REQUEST_GET; - payload = (uint8_t*)malloc(5); - sn_coap_parser_stub.expectedHeader->payload_ptr = payload; - sn_coap_parser_stub.expectedHeader->payload_len = 5; - - retCounter = 2; - ret = sn_coap_protocol_parse(handle, addr, packet_data_len, packet_data_ptr, NULL); - CHECK( NULL == ret ); - free(payload); - - sn_coap_parser_stub.expectedHeader = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_parser_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_ACKNOWLEDGEMENT; - sn_coap_parser_stub.expectedHeader->msg_id = 4; - - list = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); - memset(list, 0, sizeof(sn_coap_options_list_s)); - sn_coap_parser_stub.expectedHeader->options_list_ptr = list; - sn_coap_parser_stub.expectedHeader->options_list_ptr->block1 = 1; - sn_coap_parser_stub.expectedHeader->msg_id = 4; - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_CONFIRMABLE; - sn_coap_parser_stub.expectedHeader->msg_code = COAP_MSG_CODE_REQUEST_GET; - payload = (uint8_t*)malloc(17); - sn_coap_parser_stub.expectedHeader->payload_ptr = payload; - sn_coap_parser_stub.expectedHeader->payload_len = 17; - - retCounter = 3; - ret = sn_coap_protocol_parse(handle, addr, packet_data_len, packet_data_ptr, NULL); - CHECK( COAP_STATUS_PARSER_DUPLICATED_MSG == ret->coap_status ); - - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_ACKNOWLEDGEMENT; - sn_coap_parser_stub.expectedHeader->msg_id = 5; - - retCounter = 3; - ret = sn_coap_protocol_parse(handle, addr, packet_data_len, packet_data_ptr, NULL); - CHECK( NULL == ret ); - free(payload); - - sn_coap_parser_stub.expectedHeader = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_parser_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_ACKNOWLEDGEMENT; - sn_coap_parser_stub.expectedHeader->msg_id = 6; - - list = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); - memset(list, 0, sizeof(sn_coap_options_list_s)); - sn_coap_parser_stub.expectedHeader->options_list_ptr = list; - sn_coap_parser_stub.expectedHeader->options_list_ptr->block1 = 1; - sn_coap_parser_stub.expectedHeader->msg_id = 5; - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_CONFIRMABLE; - sn_coap_parser_stub.expectedHeader->msg_code = COAP_MSG_CODE_REQUEST_GET; - payload = (uint8_t*)malloc(17); - sn_coap_parser_stub.expectedHeader->payload_ptr = payload; - sn_coap_parser_stub.expectedHeader->payload_len = 17; - - retCounter = 4; - ret = sn_coap_protocol_parse(handle, addr, packet_data_len, packet_data_ptr, NULL); - CHECK( NULL == ret ); - free(payload); - - sn_coap_parser_stub.expectedHeader = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_parser_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_ACKNOWLEDGEMENT; - sn_coap_parser_stub.expectedHeader->msg_id = 7; - - list = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); - memset(list, 0, sizeof(sn_coap_options_list_s)); - sn_coap_parser_stub.expectedHeader->options_list_ptr = list; - sn_coap_parser_stub.expectedHeader->options_list_ptr->block1 = 1; - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_CONFIRMABLE; - sn_coap_parser_stub.expectedHeader->msg_code = COAP_MSG_CODE_REQUEST_GET; - payload = (uint8_t*)malloc(17); - sn_coap_parser_stub.expectedHeader->payload_ptr = payload; - sn_coap_parser_stub.expectedHeader->payload_len = 17; - - retCounter = 5; - ret = sn_coap_protocol_parse(handle, addr, packet_data_len, packet_data_ptr, NULL); - CHECK( NULL == ret ); - free(payload); - - sn_coap_parser_stub.expectedHeader = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_parser_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_ACKNOWLEDGEMENT; - sn_coap_parser_stub.expectedHeader->msg_id = 8; - - list = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); - memset(list, 0, sizeof(sn_coap_options_list_s)); - sn_coap_parser_stub.expectedHeader->options_list_ptr = list; - sn_coap_parser_stub.expectedHeader->options_list_ptr->block1 = 1; - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_CONFIRMABLE; - sn_coap_parser_stub.expectedHeader->msg_code = COAP_MSG_CODE_REQUEST_GET; - - retCounter = 6; - ret = sn_coap_protocol_parse(handle, addr, packet_data_len, packet_data_ptr, NULL); - CHECK( COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED == ret->coap_status ); - free(ret->payload_ptr); - free(list); - free(sn_coap_parser_stub.expectedHeader); - - // block1 == 0x08 --> - sn_coap_parser_stub.expectedHeader = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_parser_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_ACKNOWLEDGEMENT; - sn_coap_parser_stub.expectedHeader->msg_id = 9; - - list = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); - memset(list, 0, sizeof(sn_coap_options_list_s)); - sn_coap_parser_stub.expectedHeader->options_list_ptr = list; - sn_coap_parser_stub.expectedHeader->options_list_ptr->block1 = 0x08; - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_CONFIRMABLE; - sn_coap_parser_stub.expectedHeader->msg_code = COAP_MSG_CODE_REQUEST_GET; - payload = (uint8_t*)malloc(17); - sn_coap_parser_stub.expectedHeader->payload_ptr = payload; - sn_coap_parser_stub.expectedHeader->payload_len = 17; - - retCounter = 2; - ret = sn_coap_protocol_parse(handle, addr, packet_data_len, packet_data_ptr, NULL); - CHECK( NULL == ret ); - free(payload); - - sn_coap_parser_stub.expectedHeader = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_parser_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_ACKNOWLEDGEMENT; - sn_coap_parser_stub.expectedHeader->msg_id = 10; - - list = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); - memset(list, 0, sizeof(sn_coap_options_list_s)); - sn_coap_parser_stub.expectedHeader->options_list_ptr = list; - sn_coap_parser_stub.expectedHeader->options_list_ptr->block1 = 0x08; - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_CONFIRMABLE; - sn_coap_parser_stub.expectedHeader->msg_code = COAP_MSG_CODE_REQUEST_GET; - payload = (uint8_t*)malloc(17); - sn_coap_parser_stub.expectedHeader->payload_ptr = payload; - sn_coap_parser_stub.expectedHeader->payload_len = 17; - - retCounter = 5; - ret = sn_coap_protocol_parse(handle, addr, packet_data_len, packet_data_ptr, NULL); - CHECK( NULL == ret ); - free(payload); - - sn_coap_parser_stub.expectedHeader = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_parser_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_ACKNOWLEDGEMENT; - sn_coap_parser_stub.expectedHeader->msg_id = 11; - - list = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); - memset(list, 0, sizeof(sn_coap_options_list_s)); - sn_coap_parser_stub.expectedHeader->options_list_ptr = list; - sn_coap_parser_stub.expectedHeader->options_list_ptr->block1 = 0x08; - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_CONFIRMABLE; - sn_coap_parser_stub.expectedHeader->msg_code = COAP_MSG_CODE_REQUEST_GET; - payload = (uint8_t*)malloc(17); - sn_coap_parser_stub.expectedHeader->payload_ptr = payload; - sn_coap_parser_stub.expectedHeader->payload_len = 17; - - retCounter = 6; - ret = sn_coap_protocol_parse(handle, addr, packet_data_len, packet_data_ptr, NULL); - CHECK( NULL == ret ); - free(payload); -// free(list); -// free(sn_coap_parser_stub.expectedHeader); - - sn_coap_parser_stub.expectedHeader = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_parser_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_ACKNOWLEDGEMENT; - sn_coap_parser_stub.expectedHeader->msg_id = 12; - - list = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); - memset(list, 0, sizeof(sn_coap_options_list_s)); - sn_coap_parser_stub.expectedHeader->options_list_ptr = list; - sn_coap_parser_stub.expectedHeader->options_list_ptr->block1 = 0x0F; - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_CONFIRMABLE; - sn_coap_parser_stub.expectedHeader->msg_code = COAP_MSG_CODE_REQUEST_POST; - payload = (uint8_t*)malloc(17); - sn_coap_parser_stub.expectedHeader->payload_ptr = payload; - sn_coap_parser_stub.expectedHeader->payload_len = 17; - sn_coap_builder_stub.expectedUint16 = 1; - - retCounter = 7; - ret = sn_coap_protocol_parse(handle, addr, packet_data_len, packet_data_ptr, NULL); - CHECK( NULL == ret ); - free(payload); - - sn_coap_parser_stub.expectedHeader = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_parser_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_ACKNOWLEDGEMENT; - sn_coap_parser_stub.expectedHeader->msg_id = 13; - - list = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); - memset(list, 0, sizeof(sn_coap_options_list_s)); - sn_coap_parser_stub.expectedHeader->options_list_ptr = list; - sn_coap_parser_stub.expectedHeader->options_list_ptr->block1 = 0x08; - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_CONFIRMABLE; - sn_coap_parser_stub.expectedHeader->msg_code = COAP_MSG_CODE_REQUEST_PUT; - payload = (uint8_t*)malloc(17); - sn_coap_parser_stub.expectedHeader->payload_ptr = payload; - sn_coap_parser_stub.expectedHeader->payload_len = 17; - sn_coap_builder_stub.expectedUint16 = 1; - - retCounter = 8; - ret = sn_coap_protocol_parse(handle, addr, packet_data_len, packet_data_ptr, NULL); - CHECK( NULL != ret ); - CHECK(COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVING == ret->coap_status); - free(payload); - free(list); - free(sn_coap_parser_stub.expectedHeader); - - sn_coap_parser_stub.expectedHeader = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_parser_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_ACKNOWLEDGEMENT; - sn_coap_parser_stub.expectedHeader->msg_id = 14; - - list = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); - memset(list, 0, sizeof(sn_coap_options_list_s)); - sn_coap_parser_stub.expectedHeader->options_list_ptr = list; - sn_coap_parser_stub.expectedHeader->options_list_ptr->block1 = 0x08; - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_CONFIRMABLE; - sn_coap_parser_stub.expectedHeader->msg_code = COAP_MSG_CODE_REQUEST_DELETE; - payload = (uint8_t*)malloc(17); - sn_coap_parser_stub.expectedHeader->payload_ptr = payload; - sn_coap_parser_stub.expectedHeader->payload_len = 17; - - retCounter = 7; - ret = sn_coap_protocol_parse(handle, addr, packet_data_len, packet_data_ptr, NULL); - CHECK( NULL == ret ); - free(payload); -// free(list); -// free(sn_coap_parser_stub.expectedHeader); - - /* Size is more than we can handle */ - sn_coap_parser_stub.expectedHeader = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_parser_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_ACKNOWLEDGEMENT; - sn_coap_parser_stub.expectedHeader->msg_id = 100; - - list = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); - memset(list, 0, sizeof(sn_coap_options_list_s)); - sn_coap_parser_stub.expectedHeader->options_list_ptr = list; - sn_coap_parser_stub.expectedHeader->options_list_ptr->block1 = 0x08; - sn_coap_parser_stub.expectedHeader->options_list_ptr->use_size1 = true; - sn_coap_parser_stub.expectedHeader->options_list_ptr->size1 = 0xFFFFFF01; - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_CONFIRMABLE; - sn_coap_parser_stub.expectedHeader->msg_code = COAP_MSG_CODE_REQUEST_PUT; - payload = (uint8_t*)malloc(65535); - sn_coap_parser_stub.expectedHeader->payload_ptr = payload; - sn_coap_parser_stub.expectedHeader->payload_len = 65535; - - retCounter = 10; - ret = sn_coap_protocol_parse(handle, addr, packet_data_len, packet_data_ptr, NULL); - CHECK( NULL != ret ); - - free(payload); - free(list); - free(sn_coap_parser_stub.expectedHeader); - - // received_coap_msg_ptr->msg_code > COAP_MSG_CODE_REQUEST_DELETE --> - - sn_coap_parser_stub.expectedHeader = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_parser_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_ACKNOWLEDGEMENT; - sn_coap_parser_stub.expectedHeader->msg_id = 15; - - list = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); - memset(list, 0, sizeof(sn_coap_options_list_s)); - sn_coap_parser_stub.expectedHeader->options_list_ptr = list; - sn_coap_parser_stub.expectedHeader->options_list_ptr->block1 = 0x00; - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_CONFIRMABLE; - sn_coap_parser_stub.expectedHeader->msg_code = COAP_MSG_CODE_RESPONSE_CREATED; - payload = (uint8_t*)malloc(17); - sn_coap_parser_stub.expectedHeader->payload_ptr = payload; - sn_coap_parser_stub.expectedHeader->payload_len = 17; - - retCounter = 2; - ret = sn_coap_protocol_parse(handle, addr, packet_data_len, packet_data_ptr, NULL); - CHECK( NULL != ret ); - CHECK( COAP_STATUS_OK == ret->coap_status ); - free(payload); - free(list); - free(sn_coap_parser_stub.expectedHeader); - - sn_coap_parser_stub.expectedHeader = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_parser_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_ACKNOWLEDGEMENT; - sn_coap_parser_stub.expectedHeader->msg_id = 16; - - list = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); - memset(list, 0, sizeof(sn_coap_options_list_s)); - sn_coap_parser_stub.expectedHeader->options_list_ptr = list; - sn_coap_parser_stub.expectedHeader->options_list_ptr->block1 = 0x08; - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_CONFIRMABLE; - sn_coap_parser_stub.expectedHeader->msg_code = COAP_MSG_CODE_RESPONSE_CREATED; - payload = (uint8_t*)malloc(17); - sn_coap_parser_stub.expectedHeader->payload_ptr = payload; - sn_coap_parser_stub.expectedHeader->payload_len = 17; - - - sn_nsdl_addr_s tmp_addr; - memset(&tmp_addr, 0, sizeof(sn_nsdl_addr_s)); - sn_coap_hdr_s tmp_hdr; - memset(&tmp_hdr, 0, sizeof(sn_coap_hdr_s)); - - uint8_t* dst_packet_data_ptr = (uint8_t*)malloc(5); - memset(dst_packet_data_ptr, '1', 5); - - tmp_addr.addr_ptr = (uint8_t*)malloc(5); - memset(tmp_addr.addr_ptr, '1', 5); - - retCounter = 20; - sn_coap_builder_stub.expectedInt16 = 1; - int buff_size = SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE + 20; - tmp_hdr.payload_ptr = (uint8_t*)malloc(buff_size); - tmp_hdr.options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); - memset(tmp_hdr.options_list_ptr, 0, sizeof(sn_coap_options_list_s)); - tmp_hdr.options_list_ptr->block2 = 1; - tmp_hdr.msg_id = 16; - tmp_hdr.payload_len = buff_size; - sn_coap_protocol_build(handle, &tmp_addr, dst_packet_data_ptr, &tmp_hdr, NULL); - - free(tmp_hdr.options_list_ptr); - free(tmp_hdr.payload_ptr); - free(tmp_addr.addr_ptr); - free(dst_packet_data_ptr); - - retCounter = 2; - ret = sn_coap_protocol_parse(handle, addr, packet_data_len, packet_data_ptr, NULL); - CHECK( NULL == ret ); - free(payload); - - sn_coap_protocol_destroy(handle); - retCounter = 1; - handle = sn_coap_protocol_init(myMalloc, myFree, null_tx_cb, NULL); - - sn_coap_parser_stub.expectedHeader = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_parser_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_ACKNOWLEDGEMENT; - sn_coap_parser_stub.expectedHeader->msg_id = 17; - - list = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); - memset(list, 0, sizeof(sn_coap_options_list_s)); - sn_coap_parser_stub.expectedHeader->options_list_ptr = list; - sn_coap_parser_stub.expectedHeader->options_list_ptr->block1 = 0x08; - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_CONFIRMABLE; - sn_coap_parser_stub.expectedHeader->msg_code = COAP_MSG_CODE_RESPONSE_CREATED; - payload = (uint8_t*)malloc(17); - sn_coap_parser_stub.expectedHeader->payload_ptr = payload; - sn_coap_parser_stub.expectedHeader->payload_len = 17; - - memset(&tmp_addr, 0, sizeof(sn_nsdl_addr_s)); - memset(&tmp_hdr, 0, sizeof(sn_coap_hdr_s)); - - dst_packet_data_ptr = (uint8_t*)malloc(5); - memset(dst_packet_data_ptr, '1', 5); - - tmp_addr.addr_ptr = (uint8_t*)malloc(5); - memset(tmp_addr.addr_ptr, '1', 5); - - retCounter = 21; - sn_coap_builder_stub.expectedInt16 = 1; - int buff_len = SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE + 20; - tmp_hdr.payload_ptr = (uint8_t*)malloc(buff_len); - tmp_hdr.options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); - memset(tmp_hdr.options_list_ptr, 0, sizeof(sn_coap_options_list_s)); - tmp_hdr.options_list_ptr->block1 = -1; - tmp_hdr.options_list_ptr->block2 = 1; - tmp_hdr.msg_id = 17; - tmp_hdr.payload_len = buff_len; - - sn_coap_protocol_build(handle, &tmp_addr, dst_packet_data_ptr, &tmp_hdr, NULL); - - free(tmp_hdr.options_list_ptr); - free(tmp_hdr.payload_ptr); - free(tmp_addr.addr_ptr); - free(dst_packet_data_ptr); - - retCounter = 2; - ret = sn_coap_protocol_parse(handle, addr, packet_data_len, packet_data_ptr, NULL); - CHECK( NULL == ret ); - free(payload); - - sn_coap_parser_stub.expectedHeader = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_parser_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_ACKNOWLEDGEMENT; - sn_coap_parser_stub.expectedHeader->msg_id = 18; - - list = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); - memset(list, 0, sizeof(sn_coap_options_list_s)); - sn_coap_parser_stub.expectedHeader->options_list_ptr = list; - sn_coap_parser_stub.expectedHeader->options_list_ptr->block1 = 0xe808; - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_CONFIRMABLE; - sn_coap_parser_stub.expectedHeader->msg_code = COAP_MSG_CODE_RESPONSE_CREATED; - payload = (uint8_t*)malloc(17); - sn_coap_parser_stub.expectedHeader->payload_ptr = payload; - sn_coap_parser_stub.expectedHeader->payload_len = 17; - - - memset(&tmp_addr, 0, sizeof(sn_nsdl_addr_s)); - memset(&tmp_hdr, 0, sizeof(sn_coap_hdr_s)); - - dst_packet_data_ptr = (uint8_t*)malloc(5); - memset(dst_packet_data_ptr, '1', 5); - - tmp_addr.addr_ptr = (uint8_t*)malloc(5); - memset(tmp_addr.addr_ptr, '1', 5); - - retCounter = 20; - sn_coap_builder_stub.expectedInt16 = 1; - buff_len = UINT16_MAX; - tmp_hdr.payload_ptr = (uint8_t*)malloc(buff_len); -// tmp_hdr.options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); -// memset(tmp_hdr.options_list_ptr, 0, sizeof(sn_coap_options_list_s)); -// tmp_hdr.options_list_ptr->block2 = 1; - tmp_hdr.msg_id = 18; - tmp_hdr.msg_code = COAP_MSG_CODE_RESPONSE_CREATED; - tmp_hdr.payload_len = SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE + 20; - sn_coap_protocol_build(handle, &tmp_addr, dst_packet_data_ptr, &tmp_hdr, NULL); - - free(tmp_hdr.options_list_ptr); - tmp_hdr.options_list_ptr = NULL; - - tmp_hdr.payload_len = UINT16_MAX; - sn_coap_protocol_build(handle, &tmp_addr, dst_packet_data_ptr, &tmp_hdr, NULL); - free(tmp_hdr.options_list_ptr); - free(tmp_hdr.payload_ptr); - tmp_hdr.payload_ptr = NULL; - free(tmp_addr.addr_ptr); - free(dst_packet_data_ptr); - - retCounter = 2; - ret = sn_coap_protocol_parse(handle, addr, packet_data_len, packet_data_ptr, NULL); - CHECK( NULL == ret ); - free(payload); - - sn_coap_parser_stub.expectedHeader = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_parser_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_ACKNOWLEDGEMENT; - sn_coap_parser_stub.expectedHeader->msg_id = 19; - - list = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); - memset(list, 0, sizeof(sn_coap_options_list_s)); - sn_coap_parser_stub.expectedHeader->options_list_ptr = list; - sn_coap_parser_stub.expectedHeader->options_list_ptr->block1 = 0xeee808; - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_CONFIRMABLE; - sn_coap_parser_stub.expectedHeader->msg_code = COAP_MSG_CODE_RESPONSE_CREATED; - payload = (uint8_t*)malloc(17); - sn_coap_parser_stub.expectedHeader->payload_ptr = payload; - sn_coap_parser_stub.expectedHeader->payload_len = 17; - - memset(&tmp_addr, 0, sizeof(sn_nsdl_addr_s)); - memset(&tmp_hdr, 0, sizeof(sn_coap_hdr_s)); - - dst_packet_data_ptr = (uint8_t*)malloc(5); - memset(dst_packet_data_ptr, '1', 5); - - tmp_addr.addr_ptr = (uint8_t*)malloc(5); - memset(tmp_addr.addr_ptr, '1', 5); - - retCounter = 21; - sn_coap_builder_stub.expectedInt16 = 1; - tmp_hdr.payload_ptr = (uint8_t*)malloc(3); -// tmp_hdr.options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); -// memset(tmp_hdr.options_list_ptr, 0, sizeof(sn_coap_options_list_s)); -// tmp_hdr.options_list_ptr->block2 = 1; - tmp_hdr.msg_id = 19; - tmp_hdr.msg_code = COAP_MSG_CODE_REQUEST_GET; - tmp_hdr.payload_len = 1; - sn_coap_protocol_build(handle, &tmp_addr, dst_packet_data_ptr, &tmp_hdr, NULL); - - free(tmp_hdr.options_list_ptr); - free(tmp_hdr.payload_ptr); - tmp_hdr.payload_ptr = NULL; - free(tmp_addr.addr_ptr); - free(dst_packet_data_ptr); - - retCounter = 2; - ret = sn_coap_protocol_parse(handle, addr, packet_data_len, packet_data_ptr, NULL); - CHECK( NULL == ret ); - free(payload); - - sn_coap_parser_stub.expectedHeader = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_parser_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_ACKNOWLEDGEMENT; - sn_coap_parser_stub.expectedHeader->msg_id = 20; - - list = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); - memset(list, 0, sizeof(sn_coap_options_list_s)); - sn_coap_parser_stub.expectedHeader->options_list_ptr = list; - sn_coap_parser_stub.expectedHeader->options_list_ptr->block1 = 0xeee808; - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_CONFIRMABLE; - sn_coap_parser_stub.expectedHeader->msg_code = COAP_MSG_CODE_RESPONSE_CREATED; - payload = (uint8_t*)malloc(17); - sn_coap_parser_stub.expectedHeader->payload_ptr = payload; - sn_coap_parser_stub.expectedHeader->payload_len = 17; - - memset(&tmp_addr, 0, sizeof(sn_nsdl_addr_s)); - memset(&tmp_hdr, 0, sizeof(sn_coap_hdr_s)); - - dst_packet_data_ptr = (uint8_t*)malloc(5); - memset(dst_packet_data_ptr, '1', 5); - - tmp_addr.addr_ptr = (uint8_t*)malloc(5); - memset(tmp_addr.addr_ptr, '1', 5); - - retCounter = 21; - sn_coap_builder_stub.expectedInt16 = 1; - tmp_hdr.payload_ptr = (uint8_t*)malloc(3); -// tmp_hdr.options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); -// memset(tmp_hdr.options_list_ptr, 0, sizeof(sn_coap_options_list_s)); -// tmp_hdr.options_list_ptr->block2 = 1; - tmp_hdr.msg_id = 20; - tmp_hdr.msg_code = COAP_MSG_CODE_REQUEST_GET; - tmp_hdr.payload_len = 1; - sn_coap_protocol_build(handle, &tmp_addr, dst_packet_data_ptr, &tmp_hdr, NULL); - - free(tmp_hdr.options_list_ptr); - free(tmp_hdr.payload_ptr); - tmp_hdr.payload_ptr = NULL; - free(tmp_addr.addr_ptr); - free(dst_packet_data_ptr); - - retCounter = 5; - ret = sn_coap_protocol_parse(handle, addr, packet_data_len, packet_data_ptr, NULL); - CHECK( NULL != ret ); - CHECK( COAP_STATUS_PARSER_BLOCKWISE_ACK == ret->coap_status ); - free(payload); - sn_coap_parser_release_allocated_coap_msg_mem(handle, ret); - - //<-- block1 == 0x08 - //<-- Test sn_coap_handle_blockwise_message, block1 != -1 - - sn_coap_protocol_destroy(handle); - retCounter = 1; - handle = sn_coap_protocol_init(myMalloc, myFree, null_tx_cb, NULL); - - //Test sn_coap_handle_blockwise_message, block2 != -1 --> - sn_coap_protocol_set_duplicate_buffer_size(handle,1); - - // block2 length == 1,2,3 --> - - sn_coap_parser_stub.expectedHeader = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_parser_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_ACKNOWLEDGEMENT; - sn_coap_parser_stub.expectedHeader->msg_id = 16; - - list = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); - memset(list, 0, sizeof(sn_coap_options_list_s)); - sn_coap_parser_stub.expectedHeader->options_list_ptr = list; - sn_coap_parser_stub.expectedHeader->options_list_ptr->block2 = 0x08; - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_CONFIRMABLE; - sn_coap_parser_stub.expectedHeader->msg_code = COAP_MSG_CODE_REQUEST_DELETE; - payload = (uint8_t*)malloc(17); - sn_coap_parser_stub.expectedHeader->payload_ptr = payload; - sn_coap_parser_stub.expectedHeader->payload_len = 17; - sn_coap_parser_stub.expectedHeader->uri_path_ptr = NULL; - - memset(&tmp_addr, 0, sizeof(sn_nsdl_addr_s)); - memset(&tmp_hdr, 0, sizeof(sn_coap_hdr_s)); - - dst_packet_data_ptr = (uint8_t*)malloc(5); - memset(dst_packet_data_ptr, '1', 5); - - tmp_addr.addr_ptr = (uint8_t*)malloc(5); - memset(tmp_addr.addr_ptr, '1', 5); - - retCounter = 20; - sn_coap_builder_stub.expectedInt16 = 1; - buff_len = SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE + 20; - tmp_hdr.payload_ptr = (uint8_t*)malloc(buff_len); - tmp_hdr.options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); - memset(tmp_hdr.options_list_ptr, 0, sizeof(sn_coap_options_list_s)); - tmp_hdr.options_list_ptr->block2 = 1; - tmp_hdr.msg_id = 16; - tmp_hdr.payload_len = buff_len; - sn_coap_protocol_build(handle, &tmp_addr, dst_packet_data_ptr, &tmp_hdr, NULL); - - free(tmp_hdr.options_list_ptr); - free(tmp_hdr.payload_ptr); - free(tmp_addr.addr_ptr); - free(dst_packet_data_ptr); - - retCounter = 2; - ret = sn_coap_protocol_parse(handle, addr, packet_data_len, packet_data_ptr, NULL); - CHECK( NULL == ret ); - free(payload); -// sn_coap_parser_release_allocated_coap_msg_mem(handle, sn_coap_parser_stub.expectedHeader); - - sn_coap_protocol_destroy(handle); - retCounter = 1; - handle = sn_coap_protocol_init(myMalloc, myFree, null_tx_cb, NULL); - - sn_coap_parser_stub.expectedHeader = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_parser_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_ACKNOWLEDGEMENT; - sn_coap_parser_stub.expectedHeader->msg_id = 17; - - list = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); - memset(list, 0, sizeof(sn_coap_options_list_s)); - sn_coap_parser_stub.expectedHeader->options_list_ptr = list; - sn_coap_parser_stub.expectedHeader->options_list_ptr->block2 = 0x08; - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_CONFIRMABLE; - sn_coap_parser_stub.expectedHeader->msg_code = COAP_MSG_CODE_REQUEST_DELETE; - payload = (uint8_t*)malloc(17); - sn_coap_parser_stub.expectedHeader->payload_ptr = payload; - sn_coap_parser_stub.expectedHeader->payload_len = 17; - - memset(&tmp_addr, 0, sizeof(sn_nsdl_addr_s)); - memset(&tmp_hdr, 0, sizeof(sn_coap_hdr_s)); - - dst_packet_data_ptr = (uint8_t*)malloc(5); - memset(dst_packet_data_ptr, '1', 5); - - tmp_addr.addr_ptr = (uint8_t*)malloc(5); - memset(tmp_addr.addr_ptr, '1', 5); - - retCounter = 21; - sn_coap_builder_stub.expectedInt16 = 1; - buff_len = SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE + 20; - tmp_hdr.payload_ptr = (uint8_t*)malloc(buff_len); - tmp_hdr.options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); - memset(tmp_hdr.options_list_ptr, 0, sizeof(sn_coap_options_list_s)); - tmp_hdr.options_list_ptr->block1 = -1; - tmp_hdr.options_list_ptr->block2 = 1; - tmp_hdr.msg_id = 17; - tmp_hdr.payload_len = buff_len; - - sn_coap_protocol_build(handle, &tmp_addr, dst_packet_data_ptr, &tmp_hdr, NULL); - - free(tmp_hdr.options_list_ptr); - free(tmp_hdr.payload_ptr); - free(tmp_addr.addr_ptr); - free(dst_packet_data_ptr); - - retCounter = 3; - ret = sn_coap_protocol_parse(handle, addr, packet_data_len, packet_data_ptr, NULL); - CHECK( NULL == ret ); - free(payload); -// sn_coap_parser_release_allocated_coap_msg_mem(handle, sn_coap_parser_stub.expectedHeader); - - sn_coap_protocol_destroy(handle); - retCounter = 1; - handle = sn_coap_protocol_init(myMalloc, myFree, null_tx_cb, NULL); - - sn_coap_parser_stub.expectedHeader = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_parser_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_ACKNOWLEDGEMENT; - sn_coap_parser_stub.expectedHeader->msg_id = 18; - - list = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); - memset(list, 0, sizeof(sn_coap_options_list_s)); - sn_coap_parser_stub.expectedHeader->options_list_ptr = list; - sn_coap_parser_stub.expectedHeader->options_list_ptr->block2 = 0xe808; - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_CONFIRMABLE; - sn_coap_parser_stub.expectedHeader->msg_code = COAP_MSG_CODE_REQUEST_DELETE; - payload = (uint8_t*)malloc(17); - sn_coap_parser_stub.expectedHeader->payload_ptr = payload; - sn_coap_parser_stub.expectedHeader->payload_len = 17; - - - memset(&tmp_addr, 0, sizeof(sn_nsdl_addr_s)); - memset(&tmp_hdr, 0, sizeof(sn_coap_hdr_s)); - - dst_packet_data_ptr = (uint8_t*)malloc(5); - memset(dst_packet_data_ptr, '1', 5); - - tmp_addr.addr_ptr = (uint8_t*)malloc(5); - memset(tmp_addr.addr_ptr, '1', 5); - - retCounter = 20; - sn_coap_builder_stub.expectedInt16 = 1; - buff_len = SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE + 20; - tmp_hdr.payload_ptr = (uint8_t*)malloc(buff_len); - tmp_hdr.options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); - memset(tmp_hdr.options_list_ptr, 0, sizeof(sn_coap_options_list_s)); - tmp_hdr.options_list_ptr->use_size2 = true; - tmp_hdr.options_list_ptr->size2 = 0xFF01; - tmp_hdr.msg_id = 18; - tmp_hdr.msg_code = COAP_MSG_CODE_RESPONSE_CREATED; - tmp_hdr.payload_len = buff_len; - sn_coap_protocol_build(handle, &tmp_addr, dst_packet_data_ptr, &tmp_hdr, NULL); - - free(tmp_hdr.options_list_ptr); - free(tmp_hdr.payload_ptr); - tmp_hdr.payload_ptr = NULL; - free(tmp_addr.addr_ptr); - free(dst_packet_data_ptr); - - retCounter = 3; - ret = sn_coap_protocol_parse(handle, addr, packet_data_len, packet_data_ptr, NULL); - CHECK( NULL == ret ); - free(payload); -// sn_coap_parser_release_allocated_coap_msg_mem(handle, sn_coap_parser_stub.expectedHeader); - - sn_coap_protocol_destroy(handle); - retCounter = 1; - handle = sn_coap_protocol_init(myMalloc, myFree, null_tx_cb, NULL); - - sn_coap_parser_stub.expectedHeader = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_parser_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_ACKNOWLEDGEMENT; - sn_coap_parser_stub.expectedHeader->msg_id = 19; - - list = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); - memset(list, 0, sizeof(sn_coap_options_list_s)); - sn_coap_parser_stub.expectedHeader->options_list_ptr = list; - sn_coap_parser_stub.expectedHeader->options_list_ptr->block2 = 0xeee808; - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_CONFIRMABLE; - sn_coap_parser_stub.expectedHeader->msg_code = COAP_MSG_CODE_REQUEST_DELETE; - payload = (uint8_t*)malloc(17); - sn_coap_parser_stub.expectedHeader->payload_ptr = payload; - sn_coap_parser_stub.expectedHeader->payload_len = 17; - - memset(&tmp_addr, 0, sizeof(sn_nsdl_addr_s)); - memset(&tmp_hdr, 0, sizeof(sn_coap_hdr_s)); - - dst_packet_data_ptr = (uint8_t*)malloc(5); - memset(dst_packet_data_ptr, '1', 5); - - tmp_addr.addr_ptr = (uint8_t*)malloc(5); - memset(tmp_addr.addr_ptr, '1', 5); - - retCounter = 21; - sn_coap_builder_stub.expectedInt16 = 1; - tmp_hdr.payload_ptr = (uint8_t*)malloc(3); -// tmp_hdr.options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); -// memset(tmp_hdr.options_list_ptr, 0, sizeof(sn_coap_options_list_s)); -// tmp_hdr.options_list_ptr->block2 = 1; - tmp_hdr.msg_id = 19; - tmp_hdr.msg_code = COAP_MSG_CODE_REQUEST_GET; - tmp_hdr.payload_len = 1; - sn_coap_protocol_build(handle, &tmp_addr, dst_packet_data_ptr, &tmp_hdr, NULL); - - free(tmp_hdr.options_list_ptr); - free(tmp_hdr.payload_ptr); - tmp_hdr.payload_ptr = NULL; - free(tmp_addr.addr_ptr); - free(dst_packet_data_ptr); - - retCounter = 2; - ret = sn_coap_protocol_parse(handle, addr, packet_data_len, packet_data_ptr, NULL); - CHECK( NULL == ret ); - free(payload); -// sn_coap_parser_release_allocated_coap_msg_mem(handle, sn_coap_parser_stub.expectedHeader); - - sn_coap_protocol_destroy(handle); - retCounter = 1; - handle = sn_coap_protocol_init(myMalloc, myFree, null_tx_cb, NULL); - - sn_coap_parser_stub.expectedHeader = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_parser_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_ACKNOWLEDGEMENT; - sn_coap_parser_stub.expectedHeader->msg_id = 200; - - list = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); - memset(list, 0, sizeof(sn_coap_options_list_s)); - sn_coap_parser_stub.expectedHeader->options_list_ptr = list; - sn_coap_parser_stub.expectedHeader->options_list_ptr->block2 = 0xeee808; - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_CONFIRMABLE; - sn_coap_parser_stub.expectedHeader->msg_code = COAP_MSG_CODE_REQUEST_DELETE; - payload = (uint8_t*)malloc(17); - sn_coap_parser_stub.expectedHeader->payload_ptr = payload; - sn_coap_parser_stub.expectedHeader->payload_len = 17; - - memset(&tmp_addr, 0, sizeof(sn_nsdl_addr_s)); - memset(&tmp_hdr, 0, sizeof(sn_coap_hdr_s)); - - dst_packet_data_ptr = (uint8_t*)malloc(5); - memset(dst_packet_data_ptr, '1', 5); - - tmp_addr.addr_ptr = (uint8_t*)malloc(5); - memset(tmp_addr.addr_ptr, '1', 5); - - retCounter = 21; - sn_coap_builder_stub.expectedInt16 = 1; - tmp_hdr.payload_ptr = (uint8_t*)malloc(3); - tmp_hdr.msg_id = 200; - tmp_hdr.msg_code = COAP_MSG_CODE_REQUEST_GET; - tmp_hdr.payload_len = 1; - sn_coap_protocol_build(handle, &tmp_addr, dst_packet_data_ptr, &tmp_hdr, NULL); - - free(tmp_hdr.options_list_ptr); - free(tmp_hdr.payload_ptr); - tmp_hdr.payload_ptr = NULL; - free(tmp_addr.addr_ptr); - free(dst_packet_data_ptr); - - retCounter = 3; - ret = sn_coap_protocol_parse(handle, addr, packet_data_len, packet_data_ptr, NULL); - CHECK( NULL == ret ); - free(payload); -// sn_coap_parser_release_allocated_coap_msg_mem(handle, sn_coap_parser_stub.expectedHeader); - - - sn_coap_protocol_destroy(handle); - retCounter = 1; - handle = sn_coap_protocol_init(myMalloc, myFree, null_tx_cb, NULL); - - sn_coap_parser_stub.expectedHeader = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_parser_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_ACKNOWLEDGEMENT; - sn_coap_parser_stub.expectedHeader->msg_id = 20; - - list = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); - memset(list, 0, sizeof(sn_coap_options_list_s)); - sn_coap_parser_stub.expectedHeader->options_list_ptr = list; - sn_coap_parser_stub.expectedHeader->options_list_ptr->block1 = -1; - sn_coap_parser_stub.expectedHeader->options_list_ptr->block2 = 0xeee808; - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_CONFIRMABLE; - sn_coap_parser_stub.expectedHeader->msg_code = COAP_MSG_CODE_REQUEST_DELETE; - payload = (uint8_t*)malloc(17); - sn_coap_parser_stub.expectedHeader->payload_ptr = payload; - sn_coap_parser_stub.expectedHeader->payload_len = 17; - - memset(&tmp_addr, 0, sizeof(sn_nsdl_addr_s)); - memset(&tmp_hdr, 0, sizeof(sn_coap_hdr_s)); - - dst_packet_data_ptr = (uint8_t*)malloc(5); - memset(dst_packet_data_ptr, '1', 5); - - tmp_addr.addr_ptr = (uint8_t*)malloc(5); - memset(tmp_addr.addr_ptr, '1', 5); - - retCounter = 20; - sn_coap_builder_stub.expectedInt16 = 1; - buff_len = SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE + 20; - tmp_hdr.payload_ptr = (uint8_t*)malloc(buff_len); - - tmp_hdr.msg_id = 20; - tmp_hdr.msg_code = COAP_MSG_CODE_RESPONSE_CREATED; - tmp_hdr.payload_len = buff_len; - sn_coap_protocol_build(handle, &tmp_addr, dst_packet_data_ptr, &tmp_hdr, NULL); - - free(tmp_hdr.options_list_ptr); - free(tmp_hdr.payload_ptr); - tmp_hdr.payload_ptr = NULL; - free(tmp_addr.addr_ptr); - free(dst_packet_data_ptr); - - retCounter = 6; - ret = sn_coap_protocol_parse(handle, addr, packet_data_len, packet_data_ptr, NULL); - CHECK( NULL != ret ); - CHECK( COAP_STATUS_PARSER_BLOCKWISE_ACK == ret->coap_status ); - free(payload); - sn_coap_parser_release_allocated_coap_msg_mem(handle, sn_coap_parser_stub.expectedHeader); - - //<-- block2 length == 1,2,3 - - // block2 == 0x08 --> - - sn_coap_protocol_destroy(handle); - retCounter = 1; - handle = sn_coap_protocol_init(myMalloc, myFree, null_tx_cb, NULL); - - sn_coap_parser_stub.expectedHeader = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_parser_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_ACKNOWLEDGEMENT; - - list = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); - memset(list, 0, sizeof(sn_coap_options_list_s)); - sn_coap_parser_stub.expectedHeader->options_list_ptr = list; - sn_coap_parser_stub.expectedHeader->options_list_ptr->block1 = -1; - sn_coap_parser_stub.expectedHeader->options_list_ptr->block2 = 0x08; - sn_coap_parser_stub.expectedHeader->msg_id = 41; - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_CONFIRMABLE; - sn_coap_parser_stub.expectedHeader->msg_code = COAP_MSG_CODE_RESPONSE_CREATED; - payload = (uint8_t*)malloc(5); - sn_coap_parser_stub.expectedHeader->payload_ptr = payload; - sn_coap_parser_stub.expectedHeader->payload_len = 5; - - ret = sn_coap_protocol_parse(handle, addr, packet_data_len, packet_data_ptr, NULL); - CHECK( NULL == ret ); - free(payload); - - sn_coap_parser_stub.expectedHeader = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_parser_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_ACKNOWLEDGEMENT; - - list = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); - memset(list, 0, sizeof(sn_coap_options_list_s)); - sn_coap_parser_stub.expectedHeader->options_list_ptr = list; - sn_coap_parser_stub.expectedHeader->options_list_ptr->block1 = -1; - sn_coap_parser_stub.expectedHeader->options_list_ptr->block2 = 0x08; - sn_coap_parser_stub.expectedHeader->msg_id = 41; - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_CONFIRMABLE; - sn_coap_parser_stub.expectedHeader->msg_code = COAP_MSG_CODE_RESPONSE_CREATED; - payload = (uint8_t*)malloc(5); - sn_coap_parser_stub.expectedHeader->payload_ptr = payload; - sn_coap_parser_stub.expectedHeader->payload_len = 5; - - memset(&tmp_addr, 0, sizeof(sn_nsdl_addr_s)); - memset(&tmp_hdr, 0, sizeof(sn_coap_hdr_s)); - - dst_packet_data_ptr = (uint8_t*)malloc(5); - memset(dst_packet_data_ptr, '1', 5); - - tmp_addr.addr_ptr = (uint8_t*)malloc(5); - memset(tmp_addr.addr_ptr, '1', 5); - - retCounter = 20; - sn_coap_builder_stub.expectedInt16 = 1; - buff_len = SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE + 20; - tmp_hdr.payload_ptr = (uint8_t*)malloc(buff_len); - tmp_hdr.options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); - memset(tmp_hdr.options_list_ptr, 0, sizeof(sn_coap_options_list_s)); - tmp_hdr.options_list_ptr->block2 = 1; - tmp_hdr.msg_id = 41; - tmp_hdr.payload_len = buff_len; - sn_coap_protocol_build(handle, &tmp_addr, dst_packet_data_ptr, &tmp_hdr, NULL); - - free(tmp_hdr.options_list_ptr); - free(tmp_hdr.payload_ptr); - free(tmp_addr.addr_ptr); - free(dst_packet_data_ptr); - - retCounter = 0; - ret = sn_coap_protocol_parse(handle, addr, packet_data_len, packet_data_ptr, NULL); - CHECK( NULL == ret ); - free(payload); - free(list); - free(sn_coap_parser_stub.expectedHeader); - - sn_coap_parser_stub.expectedHeader = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_parser_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_ACKNOWLEDGEMENT; - - list = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); - memset(list, 0, sizeof(sn_coap_options_list_s)); - sn_coap_parser_stub.expectedHeader->options_list_ptr = list; - sn_coap_parser_stub.expectedHeader->options_list_ptr->block1 = -1; - sn_coap_parser_stub.expectedHeader->options_list_ptr->block2 = 0x08; - sn_coap_parser_stub.expectedHeader->msg_id = 42; - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_CONFIRMABLE; - sn_coap_parser_stub.expectedHeader->msg_code = COAP_MSG_CODE_RESPONSE_CREATED; - payload = (uint8_t*)malloc(5); - sn_coap_parser_stub.expectedHeader->payload_ptr = payload; - sn_coap_parser_stub.expectedHeader->payload_len = 5; - - memset(&tmp_addr, 0, sizeof(sn_nsdl_addr_s)); - memset(&tmp_hdr, 0, sizeof(sn_coap_hdr_s)); - - dst_packet_data_ptr = (uint8_t*)malloc(5); - memset(dst_packet_data_ptr, '1', 5); - - tmp_addr.addr_ptr = (uint8_t*)malloc(5); - memset(tmp_addr.addr_ptr, '1', 5); - - retCounter = 20; - sn_coap_builder_stub.expectedInt16 = 1; - buff_len = SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE + 20; - tmp_hdr.payload_ptr = (uint8_t*)malloc(buff_len); - tmp_hdr.options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); - memset(tmp_hdr.options_list_ptr, 0, sizeof(sn_coap_options_list_s)); - tmp_hdr.options_list_ptr->block2 = 1; - tmp_hdr.msg_id = 42; - tmp_hdr.payload_len = buff_len; - sn_coap_protocol_build(handle, &tmp_addr, dst_packet_data_ptr, &tmp_hdr, NULL); - - free(tmp_hdr.options_list_ptr); - free(tmp_hdr.payload_ptr); - free(tmp_addr.addr_ptr); - free(dst_packet_data_ptr); - - retCounter = 5; - ret = sn_coap_protocol_parse(handle, addr, packet_data_len, packet_data_ptr, NULL); - CHECK( NULL == ret ); - free(payload); - free(list); - free(sn_coap_parser_stub.expectedHeader); - - sn_coap_parser_stub.expectedHeader = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_parser_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_ACKNOWLEDGEMENT; - - list = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); - memset(list, 0, sizeof(sn_coap_options_list_s)); - sn_coap_parser_stub.expectedHeader->options_list_ptr = list; - sn_coap_parser_stub.expectedHeader->options_list_ptr->block1 = -1; - sn_coap_parser_stub.expectedHeader->options_list_ptr->block2 = 0x08; - sn_coap_parser_stub.expectedHeader->msg_id = 43; - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_CONFIRMABLE; - sn_coap_parser_stub.expectedHeader->msg_code = COAP_MSG_CODE_RESPONSE_CREATED; - payload = (uint8_t*)malloc(5); - sn_coap_parser_stub.expectedHeader->payload_ptr = payload; - sn_coap_parser_stub.expectedHeader->payload_len = 5; - - memset(&tmp_addr, 0, sizeof(sn_nsdl_addr_s)); - memset(&tmp_hdr, 0, sizeof(sn_coap_hdr_s)); - - dst_packet_data_ptr = (uint8_t*)malloc(5); - memset(dst_packet_data_ptr, '1', 5); - - tmp_addr.addr_ptr = (uint8_t*)malloc(5); - memset(tmp_addr.addr_ptr, '1', 5); - - retCounter = 20; - sn_coap_builder_stub.expectedInt16 = 1; - buff_len = SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE + 20; - tmp_hdr.payload_ptr = (uint8_t*)malloc(buff_len); - tmp_hdr.options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); - memset(tmp_hdr.options_list_ptr, 0, sizeof(sn_coap_options_list_s)); - tmp_hdr.options_list_ptr->block2 = 1; - tmp_hdr.msg_id = 43; - tmp_hdr.payload_len = buff_len; - sn_coap_protocol_build(handle, &tmp_addr, dst_packet_data_ptr, &tmp_hdr, NULL); - - free(tmp_hdr.options_list_ptr); - free(tmp_hdr.payload_ptr); - free(tmp_addr.addr_ptr); - free(dst_packet_data_ptr); - - retCounter = 6; - ret = sn_coap_protocol_parse(handle, addr, packet_data_len, packet_data_ptr, NULL); - CHECK( NULL == ret ); - free(payload); -// sn_coap_parser_release_allocated_coap_msg_mem(handle, sn_coap_parser_stub.expectedHeader); - - sn_coap_parser_stub.expectedHeader = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_parser_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_ACKNOWLEDGEMENT; - - list = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); - memset(list, 0, sizeof(sn_coap_options_list_s)); - sn_coap_parser_stub.expectedHeader->options_list_ptr = list; - sn_coap_parser_stub.expectedHeader->options_list_ptr->block1 = -1; - sn_coap_parser_stub.expectedHeader->options_list_ptr->block2 = 0x08; - sn_coap_parser_stub.expectedHeader->msg_id = 44; - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_CONFIRMABLE; - sn_coap_parser_stub.expectedHeader->msg_code = COAP_MSG_CODE_RESPONSE_CREATED; - payload = (uint8_t*)malloc(5); - sn_coap_parser_stub.expectedHeader->payload_ptr = payload; - sn_coap_parser_stub.expectedHeader->payload_len = 5; - - memset(&tmp_addr, 0, sizeof(sn_nsdl_addr_s)); - memset(&tmp_hdr, 0, sizeof(sn_coap_hdr_s)); - - dst_packet_data_ptr = (uint8_t*)malloc(5); - memset(dst_packet_data_ptr, '1', 5); - - tmp_addr.addr_ptr = (uint8_t*)malloc(5); - memset(tmp_addr.addr_ptr, '1', 5); - - retCounter = 20; - sn_coap_builder_stub.expectedInt16 = 1; - buff_len = SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE + 20; - tmp_hdr.payload_ptr = (uint8_t*)malloc(buff_len); - tmp_hdr.options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); - memset(tmp_hdr.options_list_ptr, 0, sizeof(sn_coap_options_list_s)); - tmp_hdr.options_list_ptr->block2 = 1; - tmp_hdr.msg_id = 44; - tmp_hdr.payload_len = buff_len; - sn_coap_protocol_build(handle, &tmp_addr, dst_packet_data_ptr, &tmp_hdr, NULL); - - free(tmp_hdr.options_list_ptr); - free(tmp_hdr.payload_ptr); - free(tmp_addr.addr_ptr); - free(dst_packet_data_ptr); - - retCounter = 7; - ret = sn_coap_protocol_parse(handle, addr, packet_data_len, packet_data_ptr, NULL); - CHECK( NULL == ret ); - free(payload); - - sn_coap_parser_stub.expectedHeader = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_parser_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_ACKNOWLEDGEMENT; - - list = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); - memset(list, 0, sizeof(sn_coap_options_list_s)); - sn_coap_parser_stub.expectedHeader->options_list_ptr = list; - sn_coap_parser_stub.expectedHeader->options_list_ptr->block1 = -1; - sn_coap_parser_stub.expectedHeader->options_list_ptr->block2 = 0xa8a8; - sn_coap_parser_stub.expectedHeader->msg_id = 45; - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_CONFIRMABLE; - sn_coap_parser_stub.expectedHeader->msg_code = COAP_MSG_CODE_RESPONSE_CREATED; - payload = (uint8_t*)malloc(5); - sn_coap_parser_stub.expectedHeader->payload_ptr = payload; - sn_coap_parser_stub.expectedHeader->payload_len = 5; - - memset(&tmp_addr, 0, sizeof(sn_nsdl_addr_s)); - memset(&tmp_hdr, 0, sizeof(sn_coap_hdr_s)); - - dst_packet_data_ptr = (uint8_t*)malloc(5); - memset(dst_packet_data_ptr, '1', 5); - - tmp_addr.addr_ptr = (uint8_t*)malloc(5); - memset(tmp_addr.addr_ptr, '1', 5); - - retCounter = 20; - sn_coap_builder_stub.expectedInt16 = 1; - buff_len = SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE + 20; - tmp_hdr.payload_ptr = (uint8_t*)malloc(buff_len); - tmp_hdr.options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); - memset(tmp_hdr.options_list_ptr, 0, sizeof(sn_coap_options_list_s)); - tmp_hdr.options_list_ptr->block2 = 1; - tmp_hdr.msg_id = 45; - tmp_hdr.payload_len = buff_len; - sn_coap_protocol_build(handle, &tmp_addr, dst_packet_data_ptr, &tmp_hdr, NULL); - - free(tmp_hdr.options_list_ptr); - free(tmp_hdr.payload_ptr); - free(tmp_addr.addr_ptr); - free(dst_packet_data_ptr); - - sn_coap_builder_stub.expectedInt16 = -1; - retCounter = 8; - ret = sn_coap_protocol_parse(handle, addr, packet_data_len, packet_data_ptr, NULL); - CHECK( NULL == ret ); - free(payload); - - sn_coap_parser_stub.expectedHeader = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_parser_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_ACKNOWLEDGEMENT; - - list = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); - memset(list, 0, sizeof(sn_coap_options_list_s)); - sn_coap_parser_stub.expectedHeader->options_list_ptr = list; - sn_coap_parser_stub.expectedHeader->options_list_ptr->block1 = -1; - sn_coap_parser_stub.expectedHeader->options_list_ptr->block2 = 0xc8c8c8; - sn_coap_parser_stub.expectedHeader->msg_id = 46; - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_CONFIRMABLE; - sn_coap_parser_stub.expectedHeader->msg_code = COAP_MSG_CODE_RESPONSE_CREATED; - payload = (uint8_t*)malloc(5); - sn_coap_parser_stub.expectedHeader->payload_ptr = payload; - sn_coap_parser_stub.expectedHeader->payload_len = 5; - - memset(&tmp_addr, 0, sizeof(sn_nsdl_addr_s)); - memset(&tmp_hdr, 0, sizeof(sn_coap_hdr_s)); - - dst_packet_data_ptr = (uint8_t*)malloc(5); - memset(dst_packet_data_ptr, '1', 5); - - tmp_addr.addr_ptr = (uint8_t*)malloc(5); - memset(tmp_addr.addr_ptr, '1', 5); - - retCounter = 20; - sn_coap_builder_stub.expectedInt16 = 1; - buff_len = SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE + 20; - tmp_hdr.payload_ptr = (uint8_t*)malloc(buff_len); - tmp_hdr.options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); - memset(tmp_hdr.options_list_ptr, 0, sizeof(sn_coap_options_list_s)); - tmp_hdr.options_list_ptr->block2 = 1; - tmp_hdr.msg_id = 46; - tmp_hdr.payload_len = buff_len; - sn_coap_protocol_build(handle, &tmp_addr, dst_packet_data_ptr, &tmp_hdr, NULL); - - free(tmp_hdr.options_list_ptr); - free(tmp_hdr.payload_ptr); - free(tmp_addr.addr_ptr); - free(dst_packet_data_ptr); - - sn_coap_builder_stub.expectedInt16 = 1; - retCounter = 8; - ret = sn_coap_protocol_parse(handle, addr, packet_data_len, packet_data_ptr, NULL); - CHECK( NULL == ret ); - free(payload); - - sn_coap_protocol_destroy(handle); - retCounter = 1; - handle = sn_coap_protocol_init(myMalloc, myFree, null_tx_cb, NULL); - - sn_coap_parser_stub.expectedHeader = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_parser_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_ACKNOWLEDGEMENT; - - list = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); - memset(list, 0, sizeof(sn_coap_options_list_s)); - sn_coap_parser_stub.expectedHeader->options_list_ptr = list; - sn_coap_parser_stub.expectedHeader->options_list_ptr->block1 = -1; - sn_coap_parser_stub.expectedHeader->options_list_ptr->block2 = 0xc8c8c8; - sn_coap_parser_stub.expectedHeader->msg_id = 47; - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_CONFIRMABLE; - sn_coap_parser_stub.expectedHeader->msg_code = COAP_MSG_CODE_RESPONSE_CREATED; - payload = (uint8_t*)malloc(5); - sn_coap_parser_stub.expectedHeader->payload_ptr = payload; - sn_coap_parser_stub.expectedHeader->payload_len = 5; - - memset(&tmp_addr, 0, sizeof(sn_nsdl_addr_s)); - memset(&tmp_hdr, 0, sizeof(sn_coap_hdr_s)); - - dst_packet_data_ptr = (uint8_t*)malloc(5); - memset(dst_packet_data_ptr, '1', 5); - - tmp_addr.addr_ptr = (uint8_t*)malloc(5); - memset(tmp_addr.addr_ptr, '1', 5); - - retCounter = 20; - sn_coap_builder_stub.expectedInt16 = 1; - buff_len = SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE + 20; - tmp_hdr.payload_ptr = (uint8_t*)malloc(buff_len); - tmp_hdr.options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); - memset(tmp_hdr.options_list_ptr, 0, sizeof(sn_coap_options_list_s)); - tmp_hdr.options_list_ptr->block2 = 1; - tmp_hdr.msg_id = 47; - tmp_hdr.payload_len = buff_len; - sn_coap_protocol_build(handle, &tmp_addr, dst_packet_data_ptr, &tmp_hdr, NULL); - - free(tmp_hdr.options_list_ptr); - free(tmp_hdr.payload_ptr); - free(tmp_addr.addr_ptr); - free(dst_packet_data_ptr); - - sn_coap_builder_stub.expectedInt16 = 1; - retCounter = 9; - sn_coap_protocol_set_retransmission_buffer(handle,0,0); - ret = sn_coap_protocol_parse(handle, addr, packet_data_len, packet_data_ptr, NULL); - CHECK( NULL != ret ); - free(payload); - sn_coap_parser_release_allocated_coap_msg_mem(handle, ret); - - sn_coap_protocol_destroy(handle); - retCounter = 1; - handle = sn_coap_protocol_init(myMalloc, myFree, null_tx_cb, NULL); - - sn_coap_parser_stub.expectedHeader = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_parser_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_ACKNOWLEDGEMENT; - - list = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); - memset(list, 0, sizeof(sn_coap_options_list_s)); - sn_coap_parser_stub.expectedHeader->options_list_ptr = list; - sn_coap_parser_stub.expectedHeader->options_list_ptr->block1 = -1; - sn_coap_parser_stub.expectedHeader->options_list_ptr->block2 = 0xc8c8c8; - sn_coap_parser_stub.expectedHeader->msg_id = 47; - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_CONFIRMABLE; - sn_coap_parser_stub.expectedHeader->msg_code = COAP_MSG_CODE_RESPONSE_CREATED; - payload = (uint8_t*)malloc(5); - sn_coap_parser_stub.expectedHeader->payload_ptr = payload; - sn_coap_parser_stub.expectedHeader->payload_len = 5; - - memset(&tmp_addr, 0, sizeof(sn_nsdl_addr_s)); - memset(&tmp_hdr, 0, sizeof(sn_coap_hdr_s)); - - dst_packet_data_ptr = (uint8_t*)malloc(5); - memset(dst_packet_data_ptr, '1', 5); - - tmp_addr.addr_ptr = (uint8_t*)malloc(5); - memset(tmp_addr.addr_ptr, '1', 5); - - retCounter = 20; - sn_coap_builder_stub.expectedInt16 = 1; - buff_len = SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE + 20; - tmp_hdr.payload_ptr = (uint8_t*)malloc(buff_len); - tmp_hdr.options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); - memset(tmp_hdr.options_list_ptr, 0, sizeof(sn_coap_options_list_s)); - tmp_hdr.options_list_ptr->block2 = 1; - tmp_hdr.msg_id = 47; - tmp_hdr.payload_len = buff_len; - sn_coap_protocol_build(handle, &tmp_addr, dst_packet_data_ptr, &tmp_hdr, NULL); - - free(tmp_hdr.options_list_ptr); - free(tmp_hdr.payload_ptr); - free(tmp_addr.addr_ptr); - free(dst_packet_data_ptr); - - sn_coap_builder_stub.expectedInt16 = 1; - retCounter = 9; - sn_coap_protocol_set_retransmission_buffer(handle,2,1); - ret = sn_coap_protocol_parse(handle, addr, packet_data_len, packet_data_ptr, NULL); - CHECK( NULL != ret ); - free(payload); - sn_coap_parser_release_allocated_coap_msg_mem(handle, ret); - - // <-- block2 == 0x08 - - //<-- Test sn_coap_handle_blockwise_message, block2 != -1 - - sn_coap_protocol_destroy(handle); - retCounter = 1; - handle = sn_coap_protocol_init(myMalloc, myFree, null_tx_cb, NULL); - - sn_coap_parser_stub.expectedHeader = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_parser_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_ACKNOWLEDGEMENT; - - list = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); - memset(list, 0, sizeof(sn_coap_options_list_s)); - sn_coap_parser_stub.expectedHeader->options_list_ptr = list; - sn_coap_parser_stub.expectedHeader->options_list_ptr->block1 = -1; - sn_coap_parser_stub.expectedHeader->options_list_ptr->block2 = 1; - sn_coap_parser_stub.expectedHeader->msg_id = 41; - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_CONFIRMABLE; - sn_coap_parser_stub.expectedHeader->msg_code = COAP_MSG_CODE_RESPONSE_CREATED; - payload = (uint8_t*)malloc(5); - sn_coap_parser_stub.expectedHeader->payload_ptr = payload; - sn_coap_parser_stub.expectedHeader->payload_len = 5; - - ret = sn_coap_protocol_parse(handle, addr, packet_data_len, packet_data_ptr, NULL); - CHECK( NULL == ret ); - free(payload); - sn_coap_parser_release_allocated_coap_msg_mem(handle, sn_coap_parser_stub.expectedHeader); - - sn_coap_parser_stub.expectedHeader = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_parser_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_ACKNOWLEDGEMENT; - - list = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); - memset(list, 0, sizeof(sn_coap_options_list_s)); - sn_coap_parser_stub.expectedHeader->options_list_ptr = list; - sn_coap_parser_stub.expectedHeader->options_list_ptr->block1 = -1; - sn_coap_parser_stub.expectedHeader->options_list_ptr->block2 = 1; - sn_coap_parser_stub.expectedHeader->msg_id = 42; - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_CONFIRMABLE; - sn_coap_parser_stub.expectedHeader->msg_code = COAP_MSG_CODE_RESPONSE_CREATED; - payload = (uint8_t*)malloc(5); - sn_coap_parser_stub.expectedHeader->payload_ptr = payload; - sn_coap_parser_stub.expectedHeader->payload_len = 5; - - retCounter = 1; - ret = sn_coap_protocol_parse(handle, addr, packet_data_len, packet_data_ptr, NULL); - CHECK( NULL == ret ); - free(payload); - sn_coap_parser_release_allocated_coap_msg_mem(handle, sn_coap_parser_stub.expectedHeader); - - sn_coap_parser_stub.expectedHeader = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_parser_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_ACKNOWLEDGEMENT; - - list = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); - memset(list, 0, sizeof(sn_coap_options_list_s)); - sn_coap_parser_stub.expectedHeader->options_list_ptr = list; - sn_coap_parser_stub.expectedHeader->options_list_ptr->block1 = -1; - sn_coap_parser_stub.expectedHeader->options_list_ptr->block2 = 1; - sn_coap_parser_stub.expectedHeader->msg_id = 43; - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_CONFIRMABLE; - sn_coap_parser_stub.expectedHeader->msg_code = COAP_MSG_CODE_RESPONSE_CREATED; - payload = (uint8_t*)malloc(5); - sn_coap_parser_stub.expectedHeader->payload_ptr = payload; - sn_coap_parser_stub.expectedHeader->payload_len = 5; - - retCounter = 2; - ret = sn_coap_protocol_parse(handle, addr, packet_data_len, packet_data_ptr, NULL); - CHECK( NULL == ret ); - free(payload); - sn_coap_parser_release_allocated_coap_msg_mem(handle, sn_coap_parser_stub.expectedHeader); - - sn_coap_parser_stub.expectedHeader = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_parser_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_ACKNOWLEDGEMENT; - - list = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); - memset(list, 0, sizeof(sn_coap_options_list_s)); - sn_coap_parser_stub.expectedHeader->options_list_ptr = list; - sn_coap_parser_stub.expectedHeader->options_list_ptr->block1 = -1; - sn_coap_parser_stub.expectedHeader->options_list_ptr->block2 = 1; - sn_coap_parser_stub.expectedHeader->msg_id = 44; - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_CONFIRMABLE; - sn_coap_parser_stub.expectedHeader->msg_code = COAP_MSG_CODE_RESPONSE_CREATED; - payload = (uint8_t*)malloc(5); - sn_coap_parser_stub.expectedHeader->payload_ptr = payload; - sn_coap_parser_stub.expectedHeader->payload_len = 5; - - retCounter = 3; - ret = sn_coap_protocol_parse(handle, addr, packet_data_len, packet_data_ptr, NULL); - CHECK( NULL == ret ); - free(payload); - sn_coap_parser_release_allocated_coap_msg_mem(handle, sn_coap_parser_stub.expectedHeader); - - sn_coap_parser_stub.expectedHeader = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_parser_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_ACKNOWLEDGEMENT; - - list = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); - memset(list, 0, sizeof(sn_coap_options_list_s)); - sn_coap_parser_stub.expectedHeader->options_list_ptr = list; - sn_coap_parser_stub.expectedHeader->options_list_ptr->block1 = -1; - sn_coap_parser_stub.expectedHeader->options_list_ptr->block2 = 1; - sn_coap_parser_stub.expectedHeader->msg_id = 45; - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_CONFIRMABLE; - sn_coap_parser_stub.expectedHeader->msg_code = COAP_MSG_CODE_RESPONSE_CREATED; - payload = (uint8_t*)malloc(5); - sn_coap_parser_stub.expectedHeader->payload_ptr = payload; - sn_coap_parser_stub.expectedHeader->payload_len = 5; - - retCounter = 4; - ret = sn_coap_protocol_parse(handle, addr, packet_data_len, packet_data_ptr, NULL); - CHECK( NULL == ret ); - free(payload); - sn_coap_parser_release_allocated_coap_msg_mem(handle, sn_coap_parser_stub.expectedHeader); - - sn_coap_parser_stub.expectedHeader = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_parser_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_ACKNOWLEDGEMENT; - - list = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); - memset(list, 0, sizeof(sn_coap_options_list_s)); - sn_coap_parser_stub.expectedHeader->options_list_ptr = list; - sn_coap_parser_stub.expectedHeader->options_list_ptr->block1 = -1; - sn_coap_parser_stub.expectedHeader->options_list_ptr->block2 = 1; - sn_coap_parser_stub.expectedHeader->msg_id = 46; - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_CONFIRMABLE; - sn_coap_parser_stub.expectedHeader->msg_code = COAP_MSG_CODE_RESPONSE_CREATED; - payload = (uint8_t*)malloc(5); - sn_coap_parser_stub.expectedHeader->payload_ptr = payload; - sn_coap_parser_stub.expectedHeader->payload_len = 5; - - retCounter = 6; - ret = sn_coap_protocol_parse(handle, addr, packet_data_len, packet_data_ptr, NULL); - CHECK( NULL != ret ); - free(payload); - free(ret->payload_ptr); - sn_coap_parser_release_allocated_coap_msg_mem(handle, ret); - - sn_coap_protocol_destroy(handle); - retCounter = 1; - handle = sn_coap_protocol_init(myMalloc, myFree, null_tx_cb, NULL); - - sn_coap_parser_stub.expectedHeader = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_parser_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_ACKNOWLEDGEMENT; - sn_coap_parser_stub.expectedHeader->msg_id = 18; - - memset(&tmp_addr, 0, sizeof(sn_nsdl_addr_s)); - memset(&tmp_hdr, 0, sizeof(sn_coap_hdr_s)); - - dst_packet_data_ptr = (uint8_t*)malloc(5); - memset(dst_packet_data_ptr, '1', 5); - dst_packet_data_ptr[2]=0; - dst_packet_data_ptr[3]=18; - - tmp_addr.addr_ptr = (uint8_t*)malloc(5); - memset(tmp_addr.addr_ptr, '1', 5); - tmp_addr.port = 0; - - retCounter = 20; - sn_coap_builder_stub.expectedInt16 = 5; - buff_len = SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE + 20; - tmp_hdr.payload_ptr = (uint8_t*)malloc(buff_len); - tmp_hdr.msg_id = 18; - tmp_hdr.msg_code = COAP_MSG_CODE_RESPONSE_CREATED; - tmp_hdr.payload_len = buff_len; - sn_coap_protocol_build(handle, &tmp_addr, dst_packet_data_ptr, &tmp_hdr, NULL); - - free(tmp_hdr.options_list_ptr); - free(tmp_hdr.payload_ptr); - free(tmp_addr.addr_ptr); - free(dst_packet_data_ptr); - - ret = sn_coap_protocol_parse(handle, addr, packet_data_len, packet_data_ptr, NULL); - CHECK( ret != NULL ); - sn_coap_parser_release_allocated_coap_msg_mem(handle, ret); - - sn_coap_protocol_destroy(handle); - - retCounter = 1; - handle = sn_coap_protocol_init(myMalloc, myFree, null_tx_cb, NULL); - - sn_coap_parser_stub.expectedHeader = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_parser_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_RESET; - sn_coap_parser_stub.expectedHeader->msg_id = 18; - - memset(&tmp_addr, 0, sizeof(sn_nsdl_addr_s)); - memset(&tmp_hdr, 0, sizeof(sn_coap_hdr_s)); - - dst_packet_data_ptr = (uint8_t*)malloc(5); - memset(dst_packet_data_ptr, '1', 5); - dst_packet_data_ptr[2]=0; - dst_packet_data_ptr[3]=18; - - tmp_addr.addr_ptr = (uint8_t*)malloc(5); - memset(tmp_addr.addr_ptr, '1', 5); - tmp_addr.port = 0; - - retCounter = 20; - sn_coap_builder_stub.expectedInt16 = 5; - buff_len = SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE + 20; - tmp_hdr.payload_ptr = (uint8_t*)malloc(buff_len); - tmp_hdr.msg_id = 18; - tmp_hdr.msg_code = COAP_MSG_CODE_RESPONSE_CREATED; - tmp_hdr.payload_len = buff_len; - tmp_hdr.uri_path_ptr = (uint8_t*)malloc(7); - snprintf((char *)tmp_hdr.uri_path_ptr, 7, "13/0/1"); - tmp_hdr.uri_path_len = 7; - - sn_coap_protocol_build(handle, &tmp_addr, dst_packet_data_ptr, &tmp_hdr, NULL); - - free(tmp_hdr.uri_path_ptr); - free(tmp_hdr.options_list_ptr); - free(tmp_hdr.payload_ptr); - free(tmp_addr.addr_ptr); - free(dst_packet_data_ptr); - - ret = sn_coap_protocol_parse(handle, addr, packet_data_len, packet_data_ptr, NULL); - CHECK( ret != NULL ); - sn_coap_parser_release_allocated_coap_msg_mem(handle, ret); - - sn_coap_protocol_destroy(handle); - - retCounter = 1; - handle = sn_coap_protocol_init(myMalloc, myFree, null_tx_cb, NULL); - - sn_coap_parser_stub.expectedHeader = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_parser_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_ACKNOWLEDGEMENT; - sn_coap_parser_stub.expectedHeader->msg_id = 18; - - memset(&tmp_addr, 0, sizeof(sn_nsdl_addr_s)); - memset(&tmp_hdr, 0, sizeof(sn_coap_hdr_s)); - - dst_packet_data_ptr = (uint8_t*)malloc(5); - memset(dst_packet_data_ptr, '1', 5); - dst_packet_data_ptr[2]=0; - dst_packet_data_ptr[3]=185; - - tmp_addr.addr_ptr = (uint8_t*)malloc(5); - memset(tmp_addr.addr_ptr, '1', 5); - tmp_addr.port = 0; - - retCounter = 20; - sn_coap_builder_stub.expectedInt16 = 5; - buff_len = SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE + 20; - tmp_hdr.payload_ptr = (uint8_t*)malloc(buff_len); - tmp_hdr.msg_id = 18; - tmp_hdr.msg_code = COAP_MSG_CODE_RESPONSE_CREATED; - tmp_hdr.payload_len = buff_len; - tmp_hdr.uri_path_ptr = (uint8_t*)malloc(7); - snprintf((char *)tmp_hdr.uri_path_ptr, 7, "13/0/1"); - tmp_hdr.uri_path_len = 7; - sn_coap_protocol_build(handle, &tmp_addr, dst_packet_data_ptr, &tmp_hdr, NULL); - - free(tmp_hdr.options_list_ptr); - free(tmp_hdr.payload_ptr); - free(tmp_addr.addr_ptr); - free(dst_packet_data_ptr); - - ret = sn_coap_protocol_parse(handle, addr, packet_data_len, packet_data_ptr, NULL); - CHECK( ret != NULL ); - sn_coap_parser_release_allocated_coap_msg_mem(handle, ret); - - free(tmp_hdr.uri_path_ptr); - free(packet_data_ptr); - free(addr->addr_ptr); - free(addr); - sn_coap_protocol_destroy(handle); -} - -TEST(libCoap_protocol, sn_coap_protocol_exec) -{ - CHECK(-1 == sn_coap_protocol_exec(NULL, 0)); - - retCounter = 1; - struct coap_s * handle = sn_coap_protocol_init(myMalloc, myFree, null_tx_cb, NULL); - - sn_nsdl_addr_s tmp_addr; - memset(&tmp_addr, 0, sizeof(sn_nsdl_addr_s)); - sn_coap_hdr_s tmp_hdr; - memset(&tmp_hdr, 0, sizeof(sn_coap_hdr_s)); - - uint8_t* dst_packet_data_ptr = (uint8_t*)malloc(5); - memset(dst_packet_data_ptr, '1', 5); - - tmp_addr.addr_ptr = (uint8_t*)malloc(5); - memset(tmp_addr.addr_ptr, '1', 5); - - retCounter = 20; - sn_coap_builder_stub.expectedInt16 = 5; - int buff_size = SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE + 20; - tmp_hdr.payload_ptr = (uint8_t*)malloc(buff_size); - tmp_hdr.msg_id = 18; - tmp_hdr.msg_code = COAP_MSG_CODE_RESPONSE_CREATED; - tmp_hdr.payload_len = buff_size; - sn_coap_protocol_build(handle, &tmp_addr, dst_packet_data_ptr, &tmp_hdr, NULL); - - free(tmp_hdr.options_list_ptr); - free(tmp_hdr.payload_ptr); - free(tmp_addr.addr_ptr); - free(dst_packet_data_ptr); - - sn_coap_parser_stub.expectedHeader = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_parser_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_ACKNOWLEDGEMENT; - sn_coap_parser_stub.expectedHeader->msg_id = 7; - - sn_coap_options_list_s* list = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); - memset(list, 0, sizeof(sn_coap_options_list_s)); - sn_coap_parser_stub.expectedHeader->options_list_ptr = list; - sn_coap_parser_stub.expectedHeader->options_list_ptr->block1 = 1; - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_CONFIRMABLE; - sn_coap_parser_stub.expectedHeader->msg_code = COAP_MSG_CODE_REQUEST_GET; - uint8_t* payload = (uint8_t*)malloc(17); - sn_coap_parser_stub.expectedHeader->payload_ptr = payload; - sn_coap_parser_stub.expectedHeader->payload_len = 17; - - uint8_t *packet_data_ptr = (uint8_t*)malloc(5); - uint16_t packet_data_len = 5; - - sn_nsdl_addr_s* addr = (sn_nsdl_addr_s*)malloc(sizeof(sn_nsdl_addr_s)); - memset(addr, 0, sizeof(sn_nsdl_addr_s)); - - addr->addr_ptr = (uint8_t*)malloc(5); - - retCounter = 5; - sn_coap_protocol_parse(handle, addr, packet_data_len, packet_data_ptr, NULL); - free(payload); - free(packet_data_ptr); - free(addr->addr_ptr); - free(addr); - - CHECK(0 == sn_coap_protocol_exec(handle, 600)); - - sn_coap_builder_stub.expectedInt16 = 0; - retCounter = 0; - sn_coap_protocol_destroy(handle); -} - -TEST(libCoap_protocol, sn_coap_protocol_exec2) -{ - retCounter = 1; - struct coap_s * handle = sn_coap_protocol_init(myMalloc, myFree, null_tx_cb, null_rx_cb); - - sn_nsdl_addr_s tmp_addr; - memset(&tmp_addr, 0, sizeof(sn_nsdl_addr_s)); - sn_coap_hdr_s tmp_hdr; - memset(&tmp_hdr, 0, sizeof(sn_coap_hdr_s)); - - uint8_t* dst_packet_data_ptr = (uint8_t*)malloc(5); - memset(dst_packet_data_ptr, '1', 5); - - tmp_addr.addr_ptr = (uint8_t*)malloc(5); - memset(tmp_addr.addr_ptr, '1', 5); - - retCounter = 20; - sn_coap_builder_stub.expectedInt16 = 5; - int buf_len = SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE + 20; - tmp_hdr.payload_ptr = (uint8_t*)malloc(buf_len); - tmp_hdr.msg_id = 18; - tmp_hdr.msg_code = COAP_MSG_CODE_RESPONSE_CREATED; - tmp_hdr.payload_len = buf_len; - sn_coap_protocol_build(handle, &tmp_addr, dst_packet_data_ptr, &tmp_hdr, NULL); - - free(tmp_hdr.options_list_ptr); - free(tmp_hdr.payload_ptr); - free(tmp_addr.addr_ptr); - free(dst_packet_data_ptr); - - sn_coap_parser_stub.expectedHeader = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_parser_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_ACKNOWLEDGEMENT; - sn_coap_parser_stub.expectedHeader->msg_id = 7; - - sn_coap_options_list_s* list = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); - memset(list, 0, sizeof(sn_coap_options_list_s)); - sn_coap_parser_stub.expectedHeader->options_list_ptr = list; - sn_coap_parser_stub.expectedHeader->options_list_ptr->block1 = 1; - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_CONFIRMABLE; - sn_coap_parser_stub.expectedHeader->msg_code = COAP_MSG_CODE_REQUEST_GET; - uint8_t* payload = (uint8_t*)malloc(17); - sn_coap_parser_stub.expectedHeader->payload_ptr = payload; - sn_coap_parser_stub.expectedHeader->payload_len = 17; - - uint8_t *packet_data_ptr = (uint8_t*)malloc(5); - uint16_t packet_data_len = 5; - - sn_nsdl_addr_s* addr = (sn_nsdl_addr_s*)malloc(sizeof(sn_nsdl_addr_s)); - memset(addr, 0, sizeof(sn_nsdl_addr_s)); - - addr->addr_ptr = (uint8_t*)malloc(5); - - retCounter = 5; - sn_coap_protocol_parse(handle, addr, packet_data_len, packet_data_ptr, NULL); - free(payload); - free(packet_data_ptr); - free(addr->addr_ptr); - free(addr); - - sn_coap_parser_stub.expectedHeader = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_parser_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - - sn_coap_protocol_set_retransmission_parameters(handle,0, 5); - CHECK(0 == sn_coap_protocol_exec(handle, 600)); - - sn_coap_builder_stub.expectedInt16 = 0; - retCounter = 0; - sn_coap_protocol_destroy(handle); -} - -TEST(libCoap_protocol, sn_coap_protocol_block_remove) -{ - sn_coap_protocol_block_remove(0,0,0,0); - retCounter = 9; - sn_nsdl_addr_s* addr = (sn_nsdl_addr_s*)malloc(sizeof(sn_nsdl_addr_s)); - memset(addr, 0, sizeof(sn_nsdl_addr_s)); - addr->addr_ptr = (uint8_t*)malloc(5); - memset(addr->addr_ptr,'a',5); - addr->addr_len = 5; - struct coap_s * handle = sn_coap_protocol_init(myMalloc, myFree, null_tx_cb, NULL); - uint8_t *packet_data_ptr = (uint8_t*)malloc(5); - memset(packet_data_ptr,'x',5); - uint16_t packet_data_len = 5; - sn_coap_parser_stub.expectedHeader = NULL; - sn_coap_parser_stub.expectedHeader = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_parser_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_ACKNOWLEDGEMENT; - sn_coap_parser_stub.expectedHeader->msg_id = 13; - - sn_coap_options_list_s* list = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); - memset(list, 0, sizeof(sn_coap_options_list_s)); - sn_coap_parser_stub.expectedHeader->options_list_ptr = list; - sn_coap_parser_stub.expectedHeader->options_list_ptr->block1 = 0x08; - sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_CONFIRMABLE; - sn_coap_parser_stub.expectedHeader->msg_code = COAP_MSG_CODE_REQUEST_PUT; - uint8_t* payload = (uint8_t*)malloc(17); - sn_coap_parser_stub.expectedHeader->payload_ptr = packet_data_ptr; - sn_coap_parser_stub.expectedHeader->payload_len = packet_data_len; - sn_coap_builder_stub.expectedUint16 = 1; - - // Success - retCounter = 9; - sn_coap_protocol_parse(handle, addr, packet_data_len, packet_data_ptr, NULL); - CHECK(ns_list_count(&handle->linked_list_blockwise_received_payloads) == 1); - sn_coap_protocol_block_remove(handle,addr,packet_data_len,packet_data_ptr); - CHECK(ns_list_count(&handle->linked_list_blockwise_received_payloads) == 0); - - // Ports does not match - retCounter = 18; - sn_coap_parser_stub.expectedHeader->msg_id = 14; - addr->port = 5600; - sn_coap_protocol_parse(handle, addr, packet_data_len, packet_data_ptr, NULL); - CHECK(ns_list_count(&handle->linked_list_blockwise_received_payloads) == 1); - addr->port = 5601; - sn_coap_protocol_block_remove(handle,addr,packet_data_len,packet_data_ptr); - CHECK(ns_list_count(&handle->linked_list_blockwise_received_payloads) == 1); - - // Addresses does not match - retCounter = 18; - sn_coap_parser_stub.expectedHeader->msg_id = 15; - sn_coap_protocol_parse(handle, addr, packet_data_len, packet_data_ptr, NULL); - CHECK(ns_list_count(&handle->linked_list_blockwise_received_payloads) == 2); - addr->addr_ptr[0] = 'x'; - sn_coap_protocol_block_remove(handle,addr,packet_data_len,packet_data_ptr); - CHECK(ns_list_count(&handle->linked_list_blockwise_received_payloads) == 2); - - // Payload length does not match - addr->addr_ptr[0] = 'a'; - sn_coap_protocol_block_remove(handle,addr,packet_data_len+1,packet_data_ptr); - CHECK(ns_list_count(&handle->linked_list_blockwise_received_payloads) == 2); - - free(sn_coap_parser_stub.expectedHeader->options_list_ptr); - free(sn_coap_parser_stub.expectedHeader); - free(addr->addr_ptr); - free(addr); - free(payload); - free(packet_data_ptr); - sn_coap_protocol_destroy(handle); -} - diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/sn_coap_protocol/main.cpp b/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/sn_coap_protocol/main.cpp deleted file mode 100644 index f352953caa..0000000000 --- a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/sn_coap_protocol/main.cpp +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c) 2015 ARM Limited. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 - * Licensed under the Apache License, Version 2.0 (the License); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "CppUTest/CommandLineTestRunner.h" -#include "CppUTest/TestPlugin.h" -#include "CppUTest/TestRegistry.h" -#include "CppUTestExt/MockSupportPlugin.h" - - - -int main(int ac, char **av) -{ - return CommandLineTestRunner::RunAllTests(ac, av); -} - -IMPORT_TEST_GROUP(libCoap_protocol); diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/sn_coap_protocol/test_config.h b/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/sn_coap_protocol/test_config.h deleted file mode 100644 index 5b824ce4db..0000000000 --- a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/sn_coap_protocol/test_config.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef TEST_CONFIG_H -#define TEST_CONFIG_H - -/** - * \def SN_COAP_DUPLICATION_MAX_MSGS_COUNT - * \brief For Message duplication detection - * Init value for the maximum count of messages to be stored for duplication detection - * Setting of this value to 0 will disable duplication check, also reduce use of ROM memory - * Default is set to 0. - */ -#define SN_COAP_DUPLICATION_MAX_MSGS_COUNT 1 - -#endif diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/sn_grs/Makefile b/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/sn_grs/Makefile deleted file mode 100644 index 8cc88e776c..0000000000 --- a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/sn_grs/Makefile +++ /dev/null @@ -1,20 +0,0 @@ -include ../makefile_defines.txt - -COMPONENT_NAME = sn_grs_unit - -#This must be changed manually -SRC_FILES = \ - ../../../../source/libNsdl/src/sn_grs.c - -TEST_SRC_FILES = \ - main.cpp \ - sn_grstest.cpp \ - test_sn_grs.c \ - ../stubs/sn_coap_protocol_stub.c \ - ../stubs/sn_coap_parser_stub.c \ - ../stubs/sn_coap_builder_stub.c \ - ../stubs/sn_nsdl_stub.c \ - ../stubs/ns_list_stub.c \ - -include ../MakefileWorker.mk - diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/sn_grs/main.cpp b/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/sn_grs/main.cpp deleted file mode 100644 index 3f777d0dc3..0000000000 --- a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/sn_grs/main.cpp +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Copyright (c) 2015 ARM. All rights reserved. - */ - -#include "CppUTest/CommandLineTestRunner.h" -#include "CppUTest/TestPlugin.h" -#include "CppUTest/TestRegistry.h" -#include "CppUTestExt/MockSupportPlugin.h" -int main(int ac, char** av) -{ - return CommandLineTestRunner::RunAllTests(ac, av); -} - -IMPORT_TEST_GROUP(sn_grs); - diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/sn_grs/sn_grstest.cpp b/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/sn_grs/sn_grstest.cpp deleted file mode 100644 index 9c802ed9e1..0000000000 --- a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/sn_grs/sn_grstest.cpp +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright (c) 2015 ARM. All rights reserved. - */ -#include "CppUTest/TestHarness.h" -#include "test_sn_grs.h" - -TEST_GROUP(sn_grs) -{ - void setup() - { - } - - void teardown() - { - } -}; - -TEST(sn_grs, test_sn_grs_get_first_resource) -{ - CHECK(test_sn_grs_get_first_resource()); -} - - -TEST(sn_grs, test_sn_grs_get_next_resource) -{ - CHECK(test_sn_grs_get_next_resource()); -} - -TEST(sn_grs, test_sn_grs_process_coap) -{ - CHECK(test_sn_grs_process_coap()); -} - -TEST(sn_grs, test_sn_grs_search_resource) -{ - CHECK(test_sn_grs_search_resource()); -} - -TEST(sn_grs, test_sn_grs_destroy) -{ - CHECK(test_sn_grs_destroy()); -} - -TEST(sn_grs, test_sn_grs_init) -{ - CHECK(test_sn_grs_init()); -} - -TEST(sn_grs, test_sn_grs_list_resource) -{ - CHECK(test_sn_grs_list_resource()); -} - -TEST(sn_grs, test_sn_grs_free_resource_list) -{ - CHECK(test_sn_grs_free_resource_list()); -} - -TEST(sn_grs, test_sn_grs_update_resource) -{ - CHECK(test_sn_grs_update_resource()); -} - -TEST(sn_grs, test_sn_grs_send_coap_message) -{ - CHECK(test_sn_grs_send_coap_message()); -} - -TEST(sn_grs, test_sn_grs_create_resource) -{ - CHECK(test_sn_grs_create_resource()); -} - -TEST(sn_grs, test_sn_grs_put_resource) -{ - CHECK(test_sn_grs_put_resource()); -} - -TEST(sn_grs, test_sn_grs_delete_resource) -{ - CHECK(test_sn_grs_delete_resource()); -} - -TEST(sn_grs, test_sn_grs_mark_resources_as_registered) -{ - CHECK(test_sn_grs_mark_resources_as_registered()); -} - diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/sn_grs/test_sn_grs.c b/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/sn_grs/test_sn_grs.c deleted file mode 100644 index 32bad3bfce..0000000000 --- a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/sn_grs/test_sn_grs.c +++ /dev/null @@ -1,1227 +0,0 @@ -/* - * Copyright (c) 2015 ARM. All rights reserved. - */ -#include "test_sn_grs.h" -#include -#include -#include "sn_coap_header.h" -#include "sn_nsdl.h" -#include "sn_nsdl_lib.h" -#include "sn_grs.h" -#include "ns_list.h" - -#include "sn_nsdl_stub.h" -#include "sn_coap_protocol_stub.h" -#include "sn_coap_builder_stub.h" - -int retCounter = 0; -uint8_t retValUint8 = 0; - -void* myMalloc(uint16_t size) -{ - if( retCounter > 0 ){ - retCounter--; - return malloc(size); - }else { - return NULL; - } -} - -void myFree(void* ptr){ - free(ptr); -} - -uint8_t myTxCallback(struct nsdl_s *a, sn_nsdl_capab_e b, uint8_t *c, uint16_t d, - sn_nsdl_addr_s *e) -{ - return retValUint8; -} - -int8_t myRxCallback(struct nsdl_s *a, sn_coap_hdr_s *b, sn_nsdl_addr_s *c) -{ - return 0; -} - -uint8_t myResCallback(struct nsdl_s *a, sn_coap_hdr_s *b, sn_nsdl_addr_s *c, sn_nsdl_capab_e d) -{ - -} - - -bool test_sn_grs_destroy() -{ - if( SN_NSDL_SUCCESS != sn_grs_destroy(NULL)){ - return false; - } - struct grs_s* handle = (struct grs_s*)malloc(sizeof(struct grs_s)); - memset(handle, 0, sizeof(struct grs_s)); - handle->sn_grs_alloc = myMalloc; - handle->sn_grs_free = myFree; - - sn_nsdl_resource_info_s* res = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); - memset(res, 0, sizeof(sn_nsdl_resource_info_s)); - ns_list_add_to_start(&handle->resource_root_list, res); - ++handle->resource_root_count; - - if( SN_NSDL_SUCCESS != sn_grs_destroy(handle)){ - return false; - } - - return true; -} - -bool test_sn_grs_init() -{ - if( NULL != sn_grs_init(NULL, NULL, NULL, NULL) ){ - return false; - } - - if( NULL != sn_grs_init(&myTxCallback, &myRxCallback, &myMalloc, &myFree) ){ - return false; - } - - retCounter = 1; - sn_coap_protocol_stub.expectedCoap = (struct coap_s*)malloc(sizeof(struct coap_s)); - memset(sn_coap_protocol_stub.expectedCoap, 0, sizeof(struct coap_s)); - - struct grs_s* handle = sn_grs_init(&myTxCallback, &myRxCallback, &myMalloc, &myFree); - if( handle == NULL ){ - return false; - } - - struct nsdl_s* h = (struct nsdl_s*)malloc(sizeof(struct nsdl_s)); - memset(h, 0, sizeof(struct nsdl_s)); - h->grs = handle; - - if( 0 != sn_coap_protocol_stub.expectedCoap->sn_coap_rx_callback(NULL, NULL, NULL) ){ - return false; - } - - h->sn_nsdl_rx_callback = &myRxCallback; - if( 0 != sn_coap_protocol_stub.expectedCoap->sn_coap_rx_callback(NULL, NULL, h) ){ - return false; - } - - if( 0 != sn_coap_protocol_stub.expectedCoap->sn_coap_tx_callback(NULL, 0, NULL, NULL)){ - return false; - } - - retValUint8 = 0; - if( 0 != sn_coap_protocol_stub.expectedCoap->sn_coap_tx_callback(NULL, 0, NULL, h)){ - return false; - } - - free(sn_coap_protocol_stub.expectedCoap); - sn_coap_protocol_stub.expectedCoap = NULL; - - sn_grs_destroy(handle); - h->grs = NULL; - free(h); - - return true; -} - -bool test_sn_grs_list_resource() -{ - if( NULL != sn_grs_list_resource(NULL, 0, NULL) ){ - return false; - } - - retCounter = 1; - struct grs_s* handle = sn_grs_init(&myTxCallback, &myRxCallback, &myMalloc, &myFree); - - uint8_t* path = (uint8_t*)malloc(5); - if( NULL != sn_grs_list_resource(handle, 5, path) ){ - return false; - } - - handle->resource_root_count = 1; - retCounter = 1; - if( NULL != sn_grs_list_resource(handle, 5, path) ){ - return false; - } - - handle->resource_root_count = 0; - sn_nsdl_resource_info_s* res = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); - memset(res, 0, sizeof(sn_nsdl_resource_info_s)); - res->path = (uint8_t*)malloc(5); - res->pathlen = 5; - ns_list_add_to_start(&handle->resource_root_list, res); - ++handle->resource_root_count; - sn_nsdl_resource_info_s* res2 = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); - memset(res2, 0, sizeof(sn_nsdl_resource_info_s)); - res2->path = (uint8_t*)malloc(4); - res2->pathlen = 4; - ns_list_add_to_start(&handle->resource_root_list, res2); - ++handle->resource_root_count; - retCounter = 2; - if( NULL != sn_grs_list_resource(handle, 5, path) ){ - return false; - } - - retCounter = 4; - sn_grs_resource_list_s *list_ptr = sn_grs_list_resource(handle, 5, path); - if( NULL == list_ptr ){ - return false; - } - - sn_grs_free_resource_list(handle, list_ptr); - - free(path); - sn_grs_destroy(handle); - return true; -} - -bool test_sn_grs_free_resource_list() -{ - sn_grs_free_resource_list(NULL, NULL); - - retCounter = 1; - struct grs_s* handle = sn_grs_init(&myTxCallback, &myRxCallback, &myMalloc, &myFree); - - sn_grs_resource_list_s *grs_resource_list_ptr = (sn_grs_resource_list_s*)malloc(sizeof(sn_grs_resource_list_s)); - memset(grs_resource_list_ptr, 0, sizeof(sn_grs_resource_list_s)); - grs_resource_list_ptr->res_count = 1; - grs_resource_list_ptr->res = (sn_grs_resource_s*)malloc(sizeof(sn_grs_resource_s)); - grs_resource_list_ptr->res[0].path = (uint8_t*)malloc(2); - grs_resource_list_ptr->res[0].pathlen = 2; - - sn_grs_free_resource_list(handle, grs_resource_list_ptr); - - sn_grs_destroy(handle); - return true; -} - -bool test_sn_grs_get_first_resource() -{ - if( NULL != sn_grs_get_first_resource(NULL) ){ - return false; - } - - struct grs_s* handle = (struct grs_s*)malloc(sizeof(struct grs_s)); - memset(handle, 0, sizeof(struct grs_s)); - handle->sn_grs_alloc = myMalloc; - handle->sn_grs_free = myFree; - - sn_nsdl_resource_info_s* res = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); - memset(res, 0, sizeof(sn_nsdl_resource_info_s)); - ns_list_add_to_start(&handle->resource_root_list, res); - ++handle->resource_root_count; - - if( NULL == sn_grs_get_first_resource(handle) ){ - return false; - } - - sn_grs_destroy(handle); - return true; -} - -bool test_sn_grs_get_next_resource() -{ - if( NULL != sn_grs_get_next_resource(NULL, NULL) ){ - return false; - } - - struct grs_s* handle = (struct grs_s*)malloc(sizeof(struct grs_s)); - memset(handle, 0, sizeof(struct grs_s)); - handle->sn_grs_alloc = myMalloc; - handle->sn_grs_free = myFree; - - sn_nsdl_resource_info_s* res = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); - memset(res, 0, sizeof(sn_nsdl_resource_info_s)); - ns_list_add_to_start(&handle->resource_root_list, res); - ++handle->resource_root_count; - sn_nsdl_resource_info_s* res2 = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); - memset(res2, 0, sizeof(sn_nsdl_resource_info_s)); - ns_list_add_to_start(&handle->resource_root_list, res2); - ++handle->resource_root_count; - - if( NULL != sn_grs_get_next_resource(handle, NULL) ){ - return false; - } - - if( NULL == sn_grs_get_next_resource(handle, res2) ){ - return false; - } - - sn_grs_destroy(handle); - return true; -} - -bool test_sn_grs_delete_resource() -{ - if( SN_NSDL_FAILURE != sn_grs_delete_resource(NULL, 0, NULL) ){ - return false; - } - - struct grs_s* handle = (struct grs_s*)malloc(sizeof(struct grs_s)); - memset(handle, 0, sizeof(struct grs_s)); - handle->sn_grs_alloc = myMalloc; - handle->sn_grs_free = myFree; - - sn_nsdl_resource_info_s* res = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); - memset(res, 0, sizeof(sn_nsdl_resource_info_s)); - res->path = (uint8_t*)malloc(2); - res->pathlen = 1; - res->path[0] = 'a'; - res->path[1] = '\0'; - ns_list_add_to_start(&handle->resource_root_list, res); - ++handle->resource_root_count; - - sn_nsdl_resource_info_s* res2 = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); - memset(res2, 0, sizeof(sn_nsdl_resource_info_s)); - res2->path = (uint8_t*)malloc(4); - res2->pathlen = 3; - res2->path[0] = 'a'; - res2->path[1] = '/'; - res2->path[2] = '1'; - res2->path[3] = '\0'; - ns_list_add_to_start(&handle->resource_root_list, res2); - ++handle->resource_root_count; - - uint8_t path[2] = {'a', '\0'}; - if( SN_NSDL_SUCCESS != sn_grs_delete_resource(handle, 1, &path) ){ - return false; - } - - if (handle->resource_root_count != 0) { - return false; - } - - sn_nsdl_resource_info_s* res3 = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); - memset(res3, 0, sizeof(sn_nsdl_resource_info_s)); - res3->path = (uint8_t*)malloc(2); - res3->pathlen = 1; - res3->path[0] = 'a'; - res3->path[1] = '\0'; - ns_list_add_to_start(&handle->resource_root_list, res3); - ++handle->resource_root_count; - - /* a/1 */ - sn_nsdl_resource_info_s* res4 = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); - memset(res4, 0, sizeof(sn_nsdl_resource_info_s)); - res4->path = (uint8_t*)malloc(4); - res4->pathlen = 3; - res4->path[0] = 'a'; - res4->path[1] = '/'; - res4->path[2] = '1'; - res4->path[3] = '\0'; - ns_list_add_to_start(&handle->resource_root_list, res4); - ++handle->resource_root_count; - - /* a/1/0 */ - sn_nsdl_resource_info_s* res5 = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); - memset(res5, 0, sizeof(sn_nsdl_resource_info_s)); - res5->path = (uint8_t*)malloc(6); - res5->pathlen = 5; - res5->path[0] = 'a'; - res5->path[1] = '/'; - res5->path[2] = '1'; - res5->path[3] = '/'; - res5->path[4] = '0'; - res5->path[5] = '\0'; - ns_list_add_to_start(&handle->resource_root_list, res5); - ++handle->resource_root_count; - - /* a/10 */ - sn_nsdl_resource_info_s* res6 = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); - memset(res6, 0, sizeof(sn_nsdl_resource_info_s)); - res6->path = (uint8_t*)malloc(5); - res6->pathlen = 4; - res6->path[0] = 'a'; - res6->path[1] = '/'; - res6->path[2] = '1'; - res6->path[3] = '0'; - res6->path[4] = '\0'; - ns_list_add_to_start(&handle->resource_root_list, res6); - ++handle->resource_root_count; - - - /* a/10/0 */ - sn_nsdl_resource_info_s* res7 = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); - memset(res7, 0, sizeof(sn_nsdl_resource_info_s)); - res7->path = (uint8_t*)malloc(7); - res7->pathlen = 6; - res7->path[0] = 'a'; - res7->path[1] = '/'; - res7->path[2] = '1'; - res7->path[3] = '0'; - res7->path[4] = '/'; - res7->path[5] = '0'; - res7->path[6] = '\0'; - ns_list_add_to_start(&handle->resource_root_list, res7); - ++handle->resource_root_count; - - uint8_t path2[4] = {'a', '/', '1', '\0'}; - if( SN_NSDL_SUCCESS != sn_grs_delete_resource(handle, 3, &path2) ){ - return false; - } - - // "a/1" and "a/1/0" removed - if (handle->resource_root_count != 3) { - return false; - } - - uint8_t path3[5] = {'a', '/', '1', '0', '\0'}; - if( SN_NSDL_SUCCESS != sn_grs_delete_resource(handle, 4, &path3) ){ - return false; - } - - if (handle->resource_root_count != 1) { - return false; - } - - if( SN_NSDL_SUCCESS != sn_grs_delete_resource(handle, 1, &path) ){ - return false; - } - - if (handle->resource_root_count != 0) { - return false; - } - - sn_grs_destroy(handle); - return true; -} - -bool test_sn_grs_update_resource() -{ - if( SN_NSDL_FAILURE != sn_grs_update_resource(NULL, NULL) ){ - return false; - } - - struct grs_s* handle = (struct grs_s*)malloc(sizeof(struct grs_s)); - memset(handle, 0, sizeof(struct grs_s)); - handle->sn_grs_alloc = myMalloc; - handle->sn_grs_free = myFree; - - sn_nsdl_resource_info_s* res = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); - memset(res, 0, sizeof(sn_nsdl_resource_info_s)); - res->path = (uint8_t*)malloc(2); - res->pathlen = 1; - res->path[0] = 'a'; - res->path[1] = '\0'; - res->resource = (uint8_t*)malloc(2); - res->resourcelen = 2; - ns_list_add_to_start(&handle->resource_root_list, res); - ++handle->resource_root_count; - sn_nsdl_resource_info_s* res2 = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); - memset(res2, 0, sizeof(sn_nsdl_resource_info_s)); - res2->path = (uint8_t*)malloc(2); - res2->pathlen = 1; - res2->path[0] = 'b'; - res2->path[1] = '\0'; - ns_list_add_to_start(&handle->resource_root_list, res2); - ++handle->resource_root_count; - - sn_nsdl_resource_info_s* res3 = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); - memset(res3, 0, sizeof(sn_nsdl_resource_info_s)); - res3->path = (uint8_t*)malloc(2); - res3->pathlen = 1; - res3->path[0] = 't'; - res3->path[1] = '\0'; - - if( SN_NSDL_FAILURE != sn_grs_update_resource(handle, res3) ){ - return false; - } - - if( SN_NSDL_FAILURE != sn_grs_update_resource(handle, res) ){ - return false; - } - - retCounter = 1; - res3->path[0] = 'a'; - res3->resource = (uint8_t*)malloc(2); - res3->resourcelen = 2; - if( SN_NSDL_SUCCESS != sn_grs_update_resource(handle, res3) ){ - return false; - } - free(res3->resource); - free(res3->path); - free(res3); - - sn_grs_destroy(handle); - return true; -} - -bool test_sn_grs_create_resource() -{ - if( SN_NSDL_FAILURE != sn_grs_create_resource(NULL, NULL) ){ - return false; - } - - struct grs_s* handle = (struct grs_s*)malloc(sizeof(struct grs_s)); - memset(handle, 0, sizeof(struct grs_s)); - handle->sn_grs_alloc = myMalloc; - handle->sn_grs_free = myFree; - - sn_nsdl_resource_info_s* res = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); - memset(res, 0, sizeof(sn_nsdl_resource_info_s)); - res->pathlen = 1; - - if( SN_GRS_INVALID_PATH != sn_grs_create_resource(handle, res) ){ - return false; - } - - res->path = (uint8_t*)malloc(2); - res->path[0] = 'a'; - res->path[1] = '\0'; - res->resource = (uint8_t*)malloc(2); - res->resource[0] = 'a'; - res->resource[1] = '\0'; - res->resourcelen = 1; - res->resource_parameters_ptr = (sn_nsdl_resource_parameters_s*)malloc(sizeof(sn_nsdl_resource_parameters_s)); - memset(res->resource_parameters_ptr, 0, sizeof(sn_nsdl_resource_parameters_s)); - - res->resource_parameters_ptr->resource_type_ptr = (uint8_t*)malloc(2); - memset(res->resource_parameters_ptr->resource_type_ptr, 0, 2); - - res->resource_parameters_ptr->interface_description_ptr = (uint8_t*)malloc(2); - memset(res->resource_parameters_ptr->interface_description_ptr, 0, 2); - - if( SN_GRS_LIST_ADDING_FAILURE != sn_grs_create_resource(handle, res) ){ - return false; - } - - retCounter = 1; - if( SN_GRS_LIST_ADDING_FAILURE != sn_grs_create_resource(handle, res) ){ - return false; - } - - retCounter = 2; - if( SN_GRS_LIST_ADDING_FAILURE != sn_grs_create_resource(handle, res) ){ - return false; - } - - retCounter = 3; - if( SN_GRS_LIST_ADDING_FAILURE != sn_grs_create_resource(handle, res) ){ - return false; - } - - retCounter = 4; - if( SN_GRS_LIST_ADDING_FAILURE != sn_grs_create_resource(handle, res) ){ - return false; - } - - retCounter = 5; - if( SN_GRS_LIST_ADDING_FAILURE != sn_grs_create_resource(handle, res) ){ - return false; - } - - retCounter = 6; - if( SN_NSDL_SUCCESS != sn_grs_create_resource(handle, res) ){ - return false; - } - - if( SN_GRS_RESOURCE_ALREADY_EXISTS != sn_grs_create_resource(handle, res) ){ - return false; - } - - ns_list_add_to_start(&handle->resource_root_list, res); - sn_grs_destroy(handle); - return true; -} - -bool test_sn_grs_put_resource() -{ - if( SN_NSDL_FAILURE != sn_grs_put_resource(NULL, NULL) ){ - return false; - } - - struct grs_s* handle = (struct grs_s*)malloc(sizeof(struct grs_s)); - memset(handle, 0, sizeof(struct grs_s)); - handle->sn_grs_alloc = myMalloc; - handle->sn_grs_free = myFree; - - sn_nsdl_resource_info_s* res = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); - memset(res, 0, sizeof(sn_nsdl_resource_info_s)); - res->pathlen = 1; - - if( SN_GRS_INVALID_PATH != sn_grs_put_resource(handle, res) ){ - return false; - } - - uint8_t pa[2] = "a\0"; - res->path = &pa; - uint8_t re[2] = "a\0"; - res->resource = &re; - res->resourcelen = 1; - res->resource_parameters_ptr = (sn_nsdl_resource_parameters_s*)malloc(sizeof(sn_nsdl_resource_parameters_s)); - memset(res->resource_parameters_ptr, 0, sizeof(sn_nsdl_resource_parameters_s)); - - uint8_t rt[2]; - res->resource_parameters_ptr->resource_type_ptr = &rt; - - uint8_t ifp[2]; - res->resource_parameters_ptr->interface_description_ptr = &ifp; - - if( SN_NSDL_SUCCESS != sn_grs_put_resource(handle, res) ){ - return false; - } - - if( SN_GRS_RESOURCE_ALREADY_EXISTS != sn_grs_put_resource(handle, res) ){ - return false; - } - - - sn_grs_destroy(handle); - - return true; -} - -bool test_sn_grs_process_coap() -{ - if( SN_NSDL_FAILURE != sn_grs_process_coap(NULL, NULL, NULL) ){ - return false; - } - - sn_coap_protocol_stub.expectedCoap = (struct coap_s*)malloc(sizeof(struct coap_s)); - memset(sn_coap_protocol_stub.expectedCoap, 0, sizeof(struct coap_s)); - - struct nsdl_s* handle = (struct nsdl_s*)malloc(sizeof(struct nsdl_s)); - memset(handle, 0, sizeof(struct nsdl_s)); - - retCounter = 1; - //sn_coap_protocol_stub.expectedCoap = NULL; - struct grs_s* grs = sn_grs_init(&myTxCallback, &myRxCallback, &myMalloc, &myFree); - - handle->grs = grs; - - sn_coap_hdr_s* hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); - memset(hdr, 0, sizeof(sn_coap_hdr_s)); - - sn_nsdl_addr_s* addr = (sn_nsdl_addr_s*)malloc(sizeof(sn_nsdl_addr_s)); - memset(addr, 0, sizeof(sn_nsdl_addr_s)); - - hdr->msg_code = COAP_MSG_CODE_REQUEST_GET; - //Let's test first only upper if clause -> - hdr->msg_type = COAP_MSG_TYPE_RESET; - - hdr->uri_path_ptr = (uint8_t*)malloc(16); - memcpy(hdr->uri_path_ptr, ".well-known/core", 16); - hdr->uri_path_len = 16; - - hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; - hdr->payload_ptr = (uint8_t*)malloc(2); - - if( SN_NSDL_FAILURE != sn_grs_process_coap(handle, hdr, addr) ){ - return false; - } - - hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); - memset(hdr, 0, sizeof(sn_coap_hdr_s)); - hdr->msg_code = COAP_MSG_CODE_REQUEST_GET; - hdr->msg_type = COAP_MSG_TYPE_RESET; - hdr->uri_path_ptr = (uint8_t*)malloc(16); - memcpy(hdr->uri_path_ptr, ".well-known/core", 16); - hdr->uri_path_len = 16; - hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; - hdr->payload_ptr = (uint8_t*)malloc(2); - - retCounter = 1; - if( SN_NSDL_SUCCESS != sn_grs_process_coap(handle, hdr, addr) ){ - return false; - } - - hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); - memset(hdr, 0, sizeof(sn_coap_hdr_s)); - hdr->msg_code = COAP_MSG_CODE_REQUEST_GET; - hdr->msg_type = COAP_MSG_TYPE_RESET; - hdr->uri_path_ptr = (uint8_t*)malloc(16); - memcpy(hdr->uri_path_ptr, ".well-known/core", 16); - hdr->uri_path_len = 16; - hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; - hdr->payload_ptr = (uint8_t*)malloc(2); - - sn_nsdl_stub.allocatePayloadPtr = true; - handle->sn_nsdl_alloc = &myMalloc; - retCounter = 3; - if( SN_NSDL_SUCCESS != sn_grs_process_coap(handle, hdr, addr) ){ - return false; - } - - - sn_nsdl_stub.allocatePayloadPtr = false; - - hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); - memset(hdr, 0, sizeof(sn_coap_hdr_s)); - hdr->msg_code = COAP_MSG_CODE_REQUEST_GET; - hdr->msg_type = COAP_MSG_TYPE_RESET; - hdr->uri_path_ptr = (uint8_t*)calloc(2, 1); - hdr->uri_path_len = 2; - hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; - hdr->payload_ptr = (uint8_t*)calloc(2, 1); - hdr->payload_len = 2; - - if( SN_NSDL_SUCCESS != sn_grs_process_coap(handle, hdr, addr) ){ - return false; - } - - grs->sn_grs_rx_callback = &myRxCallback; - hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); - memset(hdr, 0, sizeof(sn_coap_hdr_s)); - hdr->msg_code = COAP_MSG_CODE_REQUEST_POST; - hdr->msg_type = COAP_MSG_TYPE_RESET; - hdr->uri_path_ptr = (uint8_t*)calloc(2, 1); - hdr->uri_path_len = 2; - hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; - hdr->payload_ptr = (uint8_t*)malloc(2); - hdr->payload_len = 2; - - if( SN_NSDL_SUCCESS != sn_grs_process_coap(handle, hdr, addr) ){ - return false; - } - - sn_nsdl_resource_info_s* res = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); - memset(res, 0, sizeof(sn_nsdl_resource_info_s)); - res->path = (uint8_t*)malloc(2); - res->pathlen = 1; - res->path[0] = 'a'; - res->path[1] = '\0'; - res->mode = SN_GRS_DYNAMIC; - res->sn_grs_dyn_res_callback = &myResCallback; - res->resource_parameters_ptr = (sn_nsdl_resource_parameters_s*)malloc(sizeof(sn_nsdl_resource_parameters_s)); - memset(res->resource_parameters_ptr, 0, sizeof(sn_nsdl_resource_parameters_s)); - ns_list_add_to_start(&handle->grs->resource_root_list, res); - ++handle->grs->resource_root_count; - - hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); - memset(hdr, 0, sizeof(sn_coap_hdr_s)); - hdr->msg_code = COAP_MSG_CODE_REQUEST_POST; - hdr->msg_type = COAP_MSG_TYPE_RESET; - hdr->uri_path_ptr = (uint8_t*)malloc(2); - hdr->uri_path_ptr[0] = 'a'; - hdr->uri_path_ptr[1] = '\0'; - hdr->uri_path_len = 1; - hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; - hdr->payload_ptr = (uint8_t*)malloc(2); - - if( SN_NSDL_SUCCESS != sn_grs_process_coap(handle, hdr, addr) ){ - return false; - } - - res->access = SN_GRS_GET_ALLOWED; - - hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); - memset(hdr, 0, sizeof(sn_coap_hdr_s)); - hdr->msg_code = COAP_MSG_CODE_REQUEST_GET; - hdr->msg_type = COAP_MSG_TYPE_RESET; - hdr->uri_path_ptr = (uint8_t*)malloc(2); - hdr->uri_path_ptr[0] = 'a'; - hdr->uri_path_ptr[1] = '\0'; - hdr->uri_path_len = 1; - hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; - hdr->payload_ptr = (uint8_t*)malloc(2); - - if( SN_NSDL_SUCCESS != sn_grs_process_coap(handle, hdr, addr) ){ - return false; - } - - res->mode = SN_GRS_STATIC; - - hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); - memset(hdr, 0, sizeof(sn_coap_hdr_s)); - hdr->msg_code = COAP_MSG_CODE_REQUEST_GET; - hdr->msg_type = COAP_MSG_TYPE_RESET; - hdr->uri_path_ptr = (uint8_t*)malloc(2); - hdr->uri_path_ptr[0] = 'a'; - hdr->uri_path_ptr[1] = '\0'; - hdr->uri_path_len = 1; - hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; - hdr->payload_ptr = (uint8_t*)malloc(2); - - if( SN_NSDL_SUCCESS != sn_grs_process_coap(handle, hdr, addr) ){ - return false; - } - - res->access = 0; - hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); - memset(hdr, 0, sizeof(sn_coap_hdr_s)); - hdr->msg_code = COAP_MSG_CODE_REQUEST_GET; - hdr->msg_type = COAP_MSG_TYPE_RESET; - hdr->uri_path_ptr = (uint8_t*)malloc(2); - hdr->uri_path_ptr[0] = 'a'; - hdr->uri_path_ptr[1] = '\0'; - hdr->uri_path_len = 1; - hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; - hdr->payload_ptr = (uint8_t*)malloc(2); - - if( SN_NSDL_SUCCESS != sn_grs_process_coap(handle, hdr, addr) ){ - return false; - } - - res->access = SN_GRS_POST_ALLOWED; - hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); - memset(hdr, 0, sizeof(sn_coap_hdr_s)); - hdr->msg_code = COAP_MSG_CODE_REQUEST_POST; - hdr->msg_type = COAP_MSG_TYPE_RESET; - hdr->uri_path_ptr = (uint8_t*)malloc(2); - hdr->uri_path_ptr[0] = 'a'; - hdr->uri_path_ptr[1] = '\0'; - hdr->uri_path_len = 1; - hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; - hdr->payload_ptr = (uint8_t*)malloc(2); - hdr->payload_len = 2; - - if( SN_NSDL_SUCCESS != sn_grs_process_coap(handle, hdr, addr) ){ - return false; - } - - retCounter = 1; - hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); - memset(hdr, 0, sizeof(sn_coap_hdr_s)); - hdr->msg_code = COAP_MSG_CODE_REQUEST_POST; - hdr->msg_type = COAP_MSG_TYPE_RESET; - hdr->uri_path_ptr = (uint8_t*)malloc(2); - hdr->uri_path_ptr[0] = 'a'; - hdr->uri_path_ptr[1] = '\0'; - hdr->uri_path_len = 1; - hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; - hdr->payload_ptr = (uint8_t*)malloc(2); - hdr->payload_len = 2; - hdr->content_format = COAP_CT_TEXT_PLAIN; - - if( SN_NSDL_SUCCESS != sn_grs_process_coap(handle, hdr, addr) ){ - return false; - } - - res->access = 0; - hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); - memset(hdr, 0, sizeof(sn_coap_hdr_s)); - hdr->msg_code = COAP_MSG_CODE_REQUEST_POST; - hdr->msg_type = COAP_MSG_TYPE_RESET; - hdr->uri_path_ptr = (uint8_t*)malloc(2); - hdr->uri_path_ptr[0] = 'a'; - hdr->uri_path_ptr[1] = '\0'; - hdr->uri_path_len = 1; - hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; - hdr->payload_ptr = (uint8_t*)malloc(2); - hdr->payload_len = 2; - - if( SN_NSDL_SUCCESS != sn_grs_process_coap(handle, hdr, addr) ){ - return false; - } - - res->access = SN_GRS_PUT_ALLOWED; - hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); - memset(hdr, 0, sizeof(sn_coap_hdr_s)); - hdr->msg_code = COAP_MSG_CODE_REQUEST_PUT; - hdr->msg_type = COAP_MSG_TYPE_RESET; - hdr->uri_path_ptr = (uint8_t*)malloc(2); - hdr->uri_path_ptr[0] = 'a'; - hdr->uri_path_ptr[1] = '\0'; - hdr->uri_path_len = 1; - hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; - hdr->payload_ptr = (uint8_t*)malloc(2); - hdr->payload_len = 2; - - if( SN_NSDL_SUCCESS != sn_grs_process_coap(handle, hdr, addr) ){ - return false; - } - - retCounter = 1; - hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); - memset(hdr, 0, sizeof(sn_coap_hdr_s)); - hdr->msg_code = COAP_MSG_CODE_REQUEST_PUT; - hdr->msg_type = COAP_MSG_TYPE_RESET; - hdr->uri_path_ptr = (uint8_t*)malloc(2); - hdr->uri_path_ptr[0] = 'a'; - hdr->uri_path_ptr[1] = '\0'; - hdr->uri_path_len = 1; - hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; - hdr->payload_ptr = (uint8_t*)malloc(2); - hdr->payload_len = 2; - hdr->content_format = 1; - - if( SN_NSDL_SUCCESS != sn_grs_process_coap(handle, hdr, addr) ){ - return false; - } - - res->access = 0; - hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); - memset(hdr, 0, sizeof(sn_coap_hdr_s)); - hdr->msg_code = COAP_MSG_CODE_REQUEST_PUT; - hdr->msg_type = COAP_MSG_TYPE_RESET; - hdr->uri_path_ptr = (uint8_t*)malloc(2); - hdr->uri_path_ptr[0] = 'a'; - hdr->uri_path_ptr[1] = '\0'; - hdr->uri_path_len = 1; - hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; - hdr->payload_ptr = (uint8_t*)malloc(2); - hdr->payload_len = 2; - - if( SN_NSDL_SUCCESS != sn_grs_process_coap(handle, hdr, addr) ){ - return false; - } - - //default: - res->access = 0; - hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); - memset(hdr, 0, sizeof(sn_coap_hdr_s)); - hdr->msg_code = COAP_MSG_CODE_EMPTY; - hdr->msg_type = COAP_MSG_TYPE_RESET; - hdr->uri_path_ptr = (uint8_t*)malloc(2); - hdr->uri_path_ptr[0] = 'a'; - hdr->uri_path_ptr[1] = '\0'; - hdr->uri_path_len = 1; - hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; - hdr->payload_ptr = (uint8_t*)malloc(2); - hdr->payload_len = 2; - - if( SN_NSDL_SUCCESS != sn_grs_process_coap(handle, hdr, addr) ){ - return false; - } - - //DELETE - res->access = 0; - hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); - memset(hdr, 0, sizeof(sn_coap_hdr_s)); - hdr->msg_code = COAP_MSG_CODE_REQUEST_DELETE; - hdr->msg_type = COAP_MSG_TYPE_RESET; - hdr->uri_path_ptr = (uint8_t*)malloc(2); - hdr->uri_path_ptr[0] = 'a'; - hdr->uri_path_ptr[1] = '\0'; - hdr->uri_path_len = 1; - hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; - hdr->payload_ptr = (uint8_t*)malloc(2); - hdr->payload_len = 2; - - if( SN_NSDL_SUCCESS != sn_grs_process_coap(handle, hdr, addr) ){ - return false; - } - - res->access = SN_GRS_DELETE_ALLOWED; - hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); - memset(hdr, 0, sizeof(sn_coap_hdr_s)); - hdr->msg_code = COAP_MSG_CODE_REQUEST_DELETE; - hdr->msg_type = COAP_MSG_TYPE_RESET; - hdr->uri_path_ptr = (uint8_t*)malloc(2); - hdr->uri_path_ptr[0] = 'a'; - hdr->uri_path_ptr[1] = '\0'; - hdr->uri_path_len = 1; - hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; - hdr->payload_ptr = (uint8_t*)malloc(2); - hdr->payload_len = 2; - - if( SN_NSDL_SUCCESS != sn_grs_process_coap(handle, hdr, addr) ){ - return false; - } - - //This tries to test dead code -// res = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); -// memset(res, 0, sizeof(sn_nsdl_resource_info_s)); -// res->path = (uint8_t*)malloc(2); -// res->pathlen = 1; -// res->path[0] = 'a'; -// res->path[1] = '\0'; -// res->mode = SN_GRS_STATIC; -// res->sn_grs_dyn_res_callback = &myResCallback; -// res->resource_parameters_ptr = (sn_nsdl_resource_parameters_s*)malloc(sizeof(sn_nsdl_resource_parameters_s)); -// res->access = SN_GRS_DELETE_ALLOWED; -// memset(res->resource_parameters_ptr, 0, sizeof(sn_nsdl_resource_parameters_s)); -// ns_list_add_to_start(&handle->grs->resource_root_list, res); -// ++handle->grs->resource_root_count; - -// hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); -// memset(hdr, 0, sizeof(sn_coap_hdr_s)); -// hdr->msg_code = COAP_MSG_CODE_REQUEST_DELETE; -// hdr->msg_type = COAP_MSG_TYPE_RESET; -// hdr->uri_path_ptr = (uint8_t*)malloc(2); -// hdr->uri_path_ptr[0] = 'a'; -// hdr->uri_path_ptr[1] = '\0'; -// hdr->uri_path_len = 1; -// hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; -// hdr->payload_ptr = (uint8_t*)malloc(2); -// hdr->payload_len = 2; -// hdr->content_format = 1; -// - -// if( SN_NSDL_SUCCESS != sn_grs_process_coap(handle, hdr, addr) ){ -// return false; -// } - -//*********************************************** - // Test below if clause -> - hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); - memset(hdr, 0, sizeof(sn_coap_hdr_s)); - hdr->msg_code = 999; - hdr->msg_type = COAP_MSG_TYPE_NON_CONFIRMABLE; - hdr->uri_path_ptr = (uint8_t*)malloc(2); - hdr->uri_path_ptr[0] = 'a'; - hdr->uri_path_ptr[1] = '\0'; - hdr->uri_path_len = 1; - hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; - hdr->payload_ptr = (uint8_t*)malloc(2); - hdr->payload_len = 2; - hdr->content_format = 1; - - if( SN_NSDL_FAILURE != sn_grs_process_coap(handle, hdr, addr) ){ - return false; - } - - hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); - memset(hdr, 0, sizeof(sn_coap_hdr_s)); - hdr->msg_code = COAP_MSG_CODE_EMPTY; - hdr->msg_type = COAP_MSG_TYPE_NON_CONFIRMABLE; - hdr->uri_path_ptr = (uint8_t*)malloc(2); - hdr->uri_path_ptr[0] = 'a'; - hdr->uri_path_ptr[1] = '\0'; - hdr->uri_path_len = 1; - hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; - hdr->payload_ptr = (uint8_t*)malloc(2); - hdr->payload_len = 2; - hdr->content_format = 1; - - hdr->token_ptr = (uint8_t*)malloc(1); - hdr->token_len = 1; - - retCounter = 1; - if( SN_NSDL_FAILURE != sn_grs_process_coap(handle, hdr, addr) ){ - return false; - } - - res = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); - memset(res, 0, sizeof(sn_nsdl_resource_info_s)); - res->path = (uint8_t*)malloc(2); - res->pathlen = 1; - res->path[0] = 'a'; - res->path[1] = '\0'; - res->mode = SN_GRS_STATIC; - res->sn_grs_dyn_res_callback = &myResCallback; - res->resource_parameters_ptr = (sn_nsdl_resource_parameters_s*)malloc(sizeof(sn_nsdl_resource_parameters_s)); - res->access = SN_GRS_GET_ALLOWED; - memset(res->resource_parameters_ptr, 0, sizeof(sn_nsdl_resource_parameters_s)); - res->resource_parameters_ptr->coap_content_type = 1; - ns_list_add_to_start(&handle->grs->resource_root_list, res); - ++handle->grs->resource_root_count; - - hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); - memset(hdr, 0, sizeof(sn_coap_hdr_s)); - hdr->msg_code = 999; - hdr->msg_type = COAP_MSG_TYPE_NON_CONFIRMABLE; - hdr->uri_path_ptr = (uint8_t*)malloc(2); - hdr->uri_path_ptr[0] = 'a'; - hdr->uri_path_ptr[1] = '\0'; - hdr->uri_path_len = 1; - hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; - hdr->payload_ptr = (uint8_t*)malloc(2); - hdr->payload_len = 2; - hdr->content_format = 1; - - hdr->token_ptr = (uint8_t*)malloc(1); - hdr->token_len = 1; - - retCounter = 1; - if( SN_NSDL_FAILURE != sn_grs_process_coap(handle, hdr, addr) ){ - return false; - } - - hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); - memset(hdr, 0, sizeof(sn_coap_hdr_s)); - hdr->msg_code = COAP_MSG_CODE_REQUEST_GET; - hdr->msg_type = COAP_MSG_TYPE_CONFIRMABLE; - hdr->uri_path_ptr = (uint8_t*)malloc(2); - hdr->uri_path_ptr[0] = 'a'; - hdr->uri_path_ptr[1] = '\0'; - hdr->uri_path_len = 1; - hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; - hdr->payload_ptr = (uint8_t*)malloc(2); - hdr->payload_len = 2; - hdr->content_format = 1; - - hdr->token_ptr = (uint8_t*)malloc(1); - hdr->token_len = 1; - - retCounter = 3; - if( SN_NSDL_SUCCESS != sn_grs_process_coap(handle, hdr, addr) ){ - return false; - } - - res->resource = (uint8_t*)malloc(2); - res->resourcelen = 2; - - hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); - memset(hdr, 0, sizeof(sn_coap_hdr_s)); - hdr->msg_code = COAP_MSG_CODE_REQUEST_GET; - hdr->msg_type = COAP_MSG_TYPE_CONFIRMABLE; - hdr->uri_path_ptr = (uint8_t*)malloc(2); - hdr->uri_path_ptr[0] = 'a'; - hdr->uri_path_ptr[1] = '\0'; - hdr->uri_path_len = 1; - hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; - hdr->payload_ptr = (uint8_t*)malloc(2); - hdr->payload_len = 2; - hdr->content_format = 1; - hdr->token_ptr = (uint8_t*)malloc(1); - hdr->token_len = 1; - - retCounter = 2; - if( SN_NSDL_FAILURE != sn_grs_process_coap(handle, hdr, addr) ){ - return false; - } - - hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); - memset(hdr, 0, sizeof(sn_coap_hdr_s)); - hdr->msg_code = COAP_MSG_CODE_REQUEST_GET; - hdr->msg_type = COAP_MSG_TYPE_CONFIRMABLE; - hdr->uri_path_ptr = (uint8_t*)malloc(2); - hdr->uri_path_ptr[0] = 'a'; - hdr->uri_path_ptr[1] = '\0'; - hdr->uri_path_len = 1; - hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; - hdr->payload_ptr = (uint8_t*)malloc(2); - hdr->payload_len = 2; - hdr->content_format = 1; - - hdr->token_ptr = (uint8_t*)malloc(1); - hdr->token_len = 1; - - retCounter = 6; - if( SN_NSDL_SUCCESS != sn_grs_process_coap(handle, hdr, addr) ){ - return false; - } - - - free(sn_coap_protocol_stub.expectedCoap); - sn_coap_protocol_stub.expectedCoap = NULL; - free(addr); - sn_grs_destroy(handle->grs); - free(handle); - return true; -} - -bool test_sn_grs_send_coap_message() -{ - if( SN_NSDL_FAILURE != sn_grs_send_coap_message(NULL, NULL, NULL) ){ - return false; - } - sn_coap_protocol_stub.expectedCoap = (struct coap_s*)malloc(sizeof(struct coap_s)); - memset(sn_coap_protocol_stub.expectedCoap, 0, sizeof(struct coap_s)); - - struct nsdl_s* handle = (struct nsdl_s*)malloc(sizeof(struct nsdl_s)); - memset(handle, 0, sizeof(struct nsdl_s)); - - retCounter = 1; - struct grs_s* grs = sn_grs_init(&myTxCallback, &myRxCallback, &myMalloc, &myFree); - - handle->grs = grs; - -// sn_coap_hdr_s* hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); -// memset(hdr, 0, sizeof(sn_coap_hdr_s)); - -// sn_nsdl_addr_s* addr = (sn_nsdl_addr_s*)malloc(sizeof(sn_nsdl_addr_s)); -// memset(addr, 0, sizeof(sn_nsdl_addr_s)); - - sn_coap_builder_stub.expectedUint16 = 2; - - if( SN_NSDL_FAILURE != sn_grs_send_coap_message(handle, NULL, NULL) ){ - return false; - } - - retCounter = 1; - sn_coap_protocol_stub.expectedInt16 = -1; - if( SN_NSDL_FAILURE != sn_grs_send_coap_message(handle, NULL, NULL) ){ - return false; - } - - retCounter = 1; - sn_coap_protocol_stub.expectedInt16 = 2; - if( SN_NSDL_FAILURE != sn_grs_send_coap_message(handle, NULL, NULL) ){ - return false; - } - - retValUint8 = 1; - retCounter = 1; - sn_coap_protocol_stub.expectedInt16 = 2; - if( SN_NSDL_SUCCESS != sn_grs_send_coap_message(handle, NULL, NULL) ){ - return false; - } - free(sn_coap_protocol_stub.expectedCoap); - sn_coap_protocol_stub.expectedCoap = NULL; - sn_grs_destroy(handle->grs); - free(handle); - return true; -} - - -bool test_sn_grs_search_resource() -{ - if( NULL != sn_grs_search_resource(NULL, 0, NULL, 0) ){ - return false; - } - struct grs_s* handle = (struct grs_s*)malloc(sizeof(struct grs_s)); - memset(handle, 0, sizeof(struct grs_s)); - handle->sn_grs_alloc = myMalloc; - handle->sn_grs_free = myFree; - - uint8_t* path = (uint8_t*)malloc(6); - path[0] = '/'; - path[1] = 'a'; - path[2] = 'b'; - path[3] = 'c'; - path[4] = '/'; - if( NULL != sn_grs_search_resource(handle, 5, path, SN_GRS_SEARCH_METHOD) ){ - return false; - } - - handle->resource_root_count = 0; - sn_nsdl_resource_info_s* res = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); - memset(res, 0, sizeof(sn_nsdl_resource_info_s)); - res->path = (uint8_t*)malloc(4); - res->path[0] = 'a'; - res->path[1] = 'b'; - res->path[2] = 'c'; - res->pathlen = 3; - ns_list_add_to_start(&handle->resource_root_list, res); - ++handle->resource_root_count; - - if( NULL == sn_grs_search_resource(handle, 5, path, SN_GRS_SEARCH_METHOD) ){ - return false; - } - - res->path[3] = '/'; - res->pathlen = 4; - - if( NULL == sn_grs_search_resource(handle, 5, path, SN_GRS_DELETE_METHOD) ){ - return false; - } - - free(path); - sn_grs_destroy(handle); - return true; -} - -bool test_sn_grs_mark_resources_as_registered() -{ - sn_grs_mark_resources_as_registered(NULL); - - struct nsdl_s* handle = (struct nsdl_s*)malloc(sizeof(struct nsdl_s)); - memset(handle, 0, sizeof(struct nsdl_s)); - - retCounter = 1; - struct grs_s* grs = sn_grs_init(&myTxCallback, &myRxCallback, &myMalloc, &myFree); - handle->grs = grs; - - sn_nsdl_resource_info_s* res = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); - memset(res, 0, sizeof(sn_nsdl_resource_info_s)); - res->path = (uint8_t*)malloc(2); - res->pathlen = 1; - res->path[0] = 'a'; - res->path[1] = '\0'; - res->mode = SN_GRS_DYNAMIC; - res->sn_grs_dyn_res_callback = &myResCallback; - res->resource_parameters_ptr = (sn_nsdl_resource_parameters_s*)malloc(sizeof(sn_nsdl_resource_parameters_s)); - memset(res->resource_parameters_ptr, 0, sizeof(sn_nsdl_resource_parameters_s)); - res->resource_parameters_ptr->registered = SN_NDSL_RESOURCE_REGISTERING; - ns_list_add_to_start(&handle->grs->resource_root_list, res); - ++handle->grs->resource_root_count; - - sn_grs_mark_resources_as_registered(handle); - if( SN_NDSL_RESOURCE_REGISTERED != res->resource_parameters_ptr->registered ){ - return false; - } - - sn_grs_destroy(handle->grs); - free(handle); - return true; -} - diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/sn_grs/test_sn_grs.h b/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/sn_grs/test_sn_grs.h deleted file mode 100644 index 1bd2eb98b6..0000000000 --- a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/sn_grs/test_sn_grs.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2015 ARM. All rights reserved. - */ -#ifndef TEST_SN_GRS_H -#define TEST_SN_GRS_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -bool test_sn_grs_get_first_resource(); -bool test_sn_grs_get_next_resource(); -bool test_sn_grs_process_coap(); -bool test_sn_grs_search_resource(); -bool test_sn_grs_destroy(); -bool test_sn_grs_init(); -bool test_sn_grs_list_resource(); -bool test_sn_grs_free_resource_list(); -bool test_sn_grs_update_resource(); -bool test_sn_grs_send_coap_message(); -bool test_sn_grs_create_resource(); -bool test_sn_grs_put_resource(); -bool test_sn_grs_delete_resource(); -bool test_sn_grs_mark_resources_as_registered(); - -#ifdef __cplusplus -} -#endif - -#endif // TEST_SN_GRS_H - diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/sn_nsdl/Makefile b/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/sn_nsdl/Makefile deleted file mode 100644 index c263ff4d42..0000000000 --- a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/sn_nsdl/Makefile +++ /dev/null @@ -1,21 +0,0 @@ -include ../makefile_defines.txt - -COMPONENT_NAME = sn_nsdl_unit - -#This must be changed manually -SRC_FILES = \ - ../../../../source/libNsdl/src/sn_nsdl.c - -TEST_SRC_FILES = \ - main.cpp \ - sn_nsdltest.cpp \ - test_sn_nsdl.c \ - ../stubs/sn_coap_protocol_stub.c \ - ../stubs/sn_grs_stub.c \ - ../stubs/sn_coap_parser_stub.c \ - ../stubs/sn_coap_builder_stub.c \ - -include ../MakefileWorker.mk - -CPPUTESTFLAGS += -DYOTTA_CFG_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE=16 - diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/sn_nsdl/main.cpp b/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/sn_nsdl/main.cpp deleted file mode 100644 index f0ed8e4254..0000000000 --- a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/sn_nsdl/main.cpp +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Copyright (c) 2015 ARM. All rights reserved. - */ - -#include "CppUTest/CommandLineTestRunner.h" -#include "CppUTest/TestPlugin.h" -#include "CppUTest/TestRegistry.h" -#include "CppUTestExt/MockSupportPlugin.h" -int main(int ac, char** av) -{ - return CommandLineTestRunner::RunAllTests(ac, av); -} - -IMPORT_TEST_GROUP(sn_nsdl); - diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/sn_nsdl/sn_nsdltest.cpp b/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/sn_nsdl/sn_nsdltest.cpp deleted file mode 100644 index b4b7760b67..0000000000 --- a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/sn_nsdl/sn_nsdltest.cpp +++ /dev/null @@ -1,199 +0,0 @@ -/* - * Copyright (c) 2015 ARM. All rights reserved. - */ -#include "CppUTest/TestHarness.h" -#include "test_sn_nsdl.h" - -TEST_GROUP(sn_nsdl) -{ - void setup() - { - } - - void teardown() - { - } -}; - -TEST(sn_nsdl, test_sn_nsdl_destroy) -{ - CHECK(test_sn_nsdl_destroy()); -} - -TEST(sn_nsdl, test_sn_nsdl_init) -{ - CHECK(test_sn_nsdl_init()); -} - -TEST(sn_nsdl, test_sn_nsdl_register_endpoint) -{ - CHECK(test_sn_nsdl_register_endpoint()); -} - -TEST(sn_nsdl, test_sn_nsdl_unregister_endpoint) -{ - CHECK(test_sn_nsdl_unregister_endpoint()); -} - -TEST(sn_nsdl, test_sn_nsdl_update_registration) -{ - CHECK(test_sn_nsdl_update_registration()); -} - -TEST(sn_nsdl, test_sn_nsdl_set_endpoint_location) -{ - CHECK(test_sn_nsdl_set_endpoint_location()); -} - -TEST(sn_nsdl, test_sn_nsdl_nsp_lost) -{ - CHECK(test_sn_nsdl_nsp_lost()); -} - -TEST(sn_nsdl, test_sn_nsdl_is_ep_registered) -{ - CHECK(test_sn_nsdl_is_ep_registered()); -} - -TEST(sn_nsdl, test_sn_nsdl_send_observation_notification) -{ - CHECK(test_sn_nsdl_send_observation_notification()); -} - -TEST(sn_nsdl, test_sn_nsdl_send_observation_notification_with_uri_path) -{ - CHECK(test_sn_nsdl_send_observation_notification_with_uri_path()); -} - -TEST(sn_nsdl, test_sn_nsdl_oma_bootstrap) -{ - CHECK(test_sn_nsdl_oma_bootstrap()); -} - -TEST(sn_nsdl, test_sn_nsdl_get_certificates) -{ - CHECK(test_sn_nsdl_get_certificates()); -} - -TEST(sn_nsdl, test_sn_nsdl_update_certificates) -{ - CHECK(test_sn_nsdl_update_certificates()); -} - -TEST(sn_nsdl, test_sn_nsdl_create_oma_device_object) -{ - CHECK(test_sn_nsdl_create_oma_device_object()); -} - -TEST(sn_nsdl, test_sn_nsdl_get_version) -{ - CHECK(test_sn_nsdl_get_version()); -} - -TEST(sn_nsdl, test_sn_nsdl_process_coap) -{ - CHECK(test_sn_nsdl_process_coap()); -} - - -TEST(sn_nsdl, test_sn_nsdl_exec) -{ - CHECK(test_sn_nsdl_exec()); -} - -TEST(sn_nsdl, test_sn_nsdl_get_resource) -{ - CHECK(test_sn_nsdl_get_resource()); -} - -TEST(sn_nsdl, test_set_NSP_address) -{ - CHECK(test_set_NSP_address()); -} - -TEST(sn_nsdl, test_sn_nsdl_list_resource) -{ - CHECK(test_sn_nsdl_list_resource()); -} - -TEST(sn_nsdl, test_sn_nsdl_free_resource_list) -{ - CHECK(test_sn_nsdl_free_resource_list()); -} - -TEST(sn_nsdl, test_sn_nsdl_update_resource) -{ - CHECK(test_sn_nsdl_update_resource()); -} - -TEST(sn_nsdl, test_sn_nsdl_send_coap_message) -{ - CHECK(test_sn_nsdl_send_coap_message()); -} - -TEST(sn_nsdl, test_sn_nsdl_create_resource) -{ - CHECK(test_sn_nsdl_create_resource()); -} - -TEST(sn_nsdl, test_sn_nsdl_put_resource) -{ - CHECK(test_sn_nsdl_put_resource()); -} - -TEST(sn_nsdl, test_sn_nsdl_delete_resource) -{ - CHECK(test_sn_nsdl_delete_resource()); -} - -TEST(sn_nsdl, test_sn_nsdl_get_first_resource) -{ - CHECK(test_sn_nsdl_get_first_resource()); -} - -TEST(sn_nsdl, test_sn_nsdl_get_next_resource) -{ - CHECK(test_sn_nsdl_get_next_resource()); -} - -TEST(sn_nsdl, test_sn_nsdl_build_response) -{ - CHECK(test_sn_nsdl_build_response()); -} - -TEST(sn_nsdl, test_sn_nsdl_release_allocated_coap_msg_mem) -{ - CHECK(test_sn_nsdl_release_allocated_coap_msg_mem()); -} - -TEST(sn_nsdl, test_sn_nsdl_set_retransmission_parameters) -{ - CHECK(test_sn_nsdl_set_retransmission_parameters()); -} - -TEST(sn_nsdl, test_sn_nsdl_set_retransmission_buffer) -{ - CHECK(test_sn_nsdl_set_retransmission_buffer()); -} - -TEST(sn_nsdl, test_sn_nsdl_set_block_size) -{ - CHECK(test_sn_nsdl_set_block_size()); -} - -TEST(sn_nsdl, test_sn_nsdl_set_duplicate_buffer_size) -{ - CHECK(test_sn_nsdl_set_duplicate_buffer_size()); -} - -TEST(sn_nsdl, test_sn_nsdl_get_context) -{ - CHECK(test_sn_nsdl_get_context()); -} - -TEST(sn_nsdl, test_sn_nsdl_set_context) -{ - CHECK(test_sn_nsdl_set_context()); -} - - diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/sn_nsdl/test_sn_nsdl.c b/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/sn_nsdl/test_sn_nsdl.c deleted file mode 100644 index be9f763224..0000000000 --- a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/sn_nsdl/test_sn_nsdl.c +++ /dev/null @@ -1,3022 +0,0 @@ -/* -* Copyright (c) 2015 ARM. All rights reserved. - */ -#include "test_sn_nsdl.h" -#include -#include - -#include "sn_coap_header.h" -#include "sn_nsdl.h" -#include "sn_nsdl_lib.h" -#include "sn_grs.h" - -#include "sn_grs_stub.h" -#include "sn_coap_builder_stub.h" -#include "sn_coap_protocol_stub.h" - -int retCounter = 0; -uint8_t rxRetVal = 0; - -void* myMalloc(uint16_t size) -{ - if( retCounter > 0 ){ - retCounter--; - return malloc(size); - }else { - return NULL; - } -} - -void myFree(void* ptr){ - free(ptr); -} - -void myBootstrapCallback(sn_nsdl_oma_server_info_t *server_info_ptr){ - -} - -void myBootstrapCallbackHandle(sn_nsdl_oma_server_info_t *server_info_ptr, struct nsdl_s *a){ - -} - -uint8_t nsdl_tx_callback(struct nsdl_s *a, sn_nsdl_capab_e b, uint8_t *c, uint16_t d, sn_nsdl_addr_s *e) -{ - -} - -uint8_t nsdl_rx_callback(struct nsdl_s *a, sn_coap_hdr_s *b, sn_nsdl_addr_s *c) -{ - return rxRetVal; -} - -bool test_sn_nsdl_destroy() -{ - if( SN_NSDL_FAILURE != sn_nsdl_destroy(NULL) ){ - return false; - } - - struct nsdl_s* handle = (struct nsdl_s*)malloc(sizeof(struct nsdl_s)); - handle->sn_nsdl_alloc = myMalloc; - handle->sn_nsdl_free = myFree; - handle->oma_bs_address_ptr = (uint8_t*)malloc(5); - - handle->ep_information_ptr = (sn_nsdl_ep_parameters_s *)malloc(sizeof(sn_nsdl_ep_parameters_s)); - memset(handle->ep_information_ptr,0,sizeof(sn_nsdl_ep_parameters_s)); - handle->ep_information_ptr->endpoint_name_ptr = (uint8_t*)malloc(5); - handle->ep_information_ptr->domain_name_ptr = (uint8_t*)malloc(5); - handle->ep_information_ptr->type_ptr = (uint8_t*)malloc(5); - handle->ep_information_ptr->lifetime_ptr = (uint8_t*)malloc(5); - handle->ep_information_ptr->location_ptr = (uint8_t*)malloc(5); - - handle->nsp_address_ptr = (sn_nsdl_oma_server_info_t *)malloc(sizeof(sn_nsdl_oma_server_info_t)); - handle->nsp_address_ptr->omalw_address_ptr = (sn_nsdl_addr_s*)malloc(sizeof(sn_nsdl_addr_s)); - handle->nsp_address_ptr->omalw_address_ptr->addr_ptr = (uint8_t*)malloc(5); - - handle->grs = (struct grs_s *)malloc(sizeof(struct grs_s)); - - int8_t ret = sn_nsdl_destroy(handle); - return ret == SN_NSDL_SUCCESS; -} - -bool test_sn_nsdl_init() -{ - if( NULL != sn_nsdl_init(&nsdl_tx_callback, &nsdl_rx_callback, &myMalloc, NULL) ){ - return false; - } - - retCounter = 0; - if( NULL != sn_nsdl_init(&nsdl_tx_callback, &nsdl_rx_callback, &myMalloc, &myFree) ){ - return false; - } - - retCounter = 1; - if( NULL != sn_nsdl_init(&nsdl_tx_callback, &nsdl_rx_callback, &myMalloc, &myFree) ){ - return false; - } - - sn_grs_stub.retNull = true; - retCounter = 2; - if( NULL != sn_nsdl_init(&nsdl_tx_callback, &nsdl_rx_callback, &myMalloc, &myFree) ){ - return false; - } - - sn_grs_stub.retNull = false; - sn_grs_stub.expectedGrs = (struct grs_s *)malloc(sizeof(struct grs_s)); //gets deleted during call - memset(sn_grs_stub.expectedGrs,0, sizeof(struct grs_s)); - retCounter = 4; - struct nsdl_s* handle = sn_nsdl_init(&nsdl_tx_callback, &nsdl_rx_callback, &myMalloc, &myFree); - sn_grs_stub.expectedGrs = NULL; - if( NULL == handle ){ - return false; - } - sn_nsdl_destroy(handle); - - return true; -} - -bool test_sn_nsdl_register_endpoint() -{ - if( 0 != sn_nsdl_register_endpoint(NULL, NULL) ){ - return false; - } - sn_grs_stub.retNull = false; - retCounter = 5; - sn_grs_stub.expectedGrs = (struct grs_s *)malloc(sizeof(struct grs_s)); - memset(sn_grs_stub.expectedGrs,0, sizeof(struct grs_s)); - struct nsdl_s* handle = sn_nsdl_init(&nsdl_tx_callback, &nsdl_rx_callback, &myMalloc, &myFree); - sn_grs_stub.expectedGrs->coap = (struct coap_s *)malloc(sizeof(struct coap_s)); - sn_grs_stub.expectedGrs->coap->sn_coap_protocol_free = myFree; - sn_grs_stub.expectedGrs->coap->sn_coap_protocol_malloc = myMalloc; - sn_grs_stub.expectedGrs->coap->sn_coap_rx_callback = nsdl_rx_callback; - sn_grs_stub.expectedGrs->coap->sn_coap_tx_callback = nsdl_tx_callback; - - sn_nsdl_ep_parameters_s *eptr = (sn_nsdl_ep_parameters_s*)malloc(sizeof(sn_nsdl_ep_parameters_s)); - memset(eptr, 0, sizeof(sn_nsdl_ep_parameters_s)); - - if( 0 != sn_nsdl_register_endpoint(handle, eptr) ){ - return false; - } - - retCounter = 0; - if( 0 != sn_nsdl_register_endpoint(handle, eptr) ){ - return false; - } - - retCounter = 1; - if( 0 != sn_nsdl_register_endpoint(handle, eptr) ){ - return false; - } - - bool ret = true; - - retCounter = 2; - eptr->endpoint_name_ptr = (uint8_t*)malloc(2); - eptr->endpoint_name_ptr[0] = 'a'; - eptr->endpoint_name_ptr[1] = '\0'; - eptr->endpoint_name_len = 1; - eptr->type_ptr = (uint8_t*)malloc(2); - eptr->type_ptr[0] = 'a'; - eptr->type_ptr[1] = '\0'; - eptr->type_len = 1; - eptr->lifetime_ptr = (uint8_t*)malloc(2); - eptr->lifetime_ptr[0] = 'a'; - eptr->lifetime_ptr[1] = '\0'; - eptr->lifetime_len = 1; - eptr->domain_name_ptr = (uint8_t*)malloc(2); - eptr->domain_name_ptr[0] = 'a'; - eptr->domain_name_ptr[1] = '\0'; - eptr->domain_name_len = 1; - eptr->binding_and_mode = 0x07; - - if( 0 != sn_nsdl_register_endpoint(handle, eptr) ){ - ret = false; - goto end; - } - - //Test validateParameters here --> - ret = true; - - retCounter = 2; - eptr->endpoint_name_ptr[0] = '&'; - eptr->endpoint_name_ptr[1] = '\0'; - eptr->endpoint_name_len = 1; - eptr->type_ptr[0] = 'a'; - eptr->type_ptr[1] = '\0'; - eptr->type_len = 1; - eptr->lifetime_ptr[0] = 'a'; - eptr->lifetime_ptr[1] = '\0'; - eptr->lifetime_len = 1; - eptr->domain_name_ptr[0] = 'a'; - eptr->domain_name_ptr[1] = '\0'; - eptr->domain_name_len = 1; - eptr->binding_and_mode = 0x07; - - if( 0 != sn_nsdl_register_endpoint(handle, eptr) ){ - ret = false; - goto end; - } - - ret = true; - - retCounter = 2; - eptr->endpoint_name_ptr[0] = 'a'; - eptr->endpoint_name_ptr[1] = '\0'; - eptr->endpoint_name_len = 1; - eptr->type_ptr[0] = '&'; - eptr->type_ptr[1] = '\0'; - eptr->type_len = 1; - eptr->lifetime_ptr[0] = 'a'; - eptr->lifetime_ptr[1] = '\0'; - eptr->lifetime_len = 1; - eptr->domain_name_ptr[0] = 'a'; - eptr->domain_name_ptr[1] = '\0'; - eptr->domain_name_len = 1; - eptr->binding_and_mode = 0x07; - - if( 0 != sn_nsdl_register_endpoint(handle, eptr) ){ - ret = false; - goto end; - } - - ret = true; - - retCounter = 2; - eptr->endpoint_name_ptr[0] = 'a'; - eptr->endpoint_name_ptr[1] = '\0'; - eptr->endpoint_name_len = 1; - eptr->type_ptr[0] = 'a'; - eptr->type_ptr[1] = '\0'; - eptr->type_len = 1; - eptr->lifetime_ptr[0] = '&'; - eptr->lifetime_ptr[1] = '\0'; - eptr->lifetime_len = 1; - eptr->domain_name_ptr[0] = 'a'; - eptr->domain_name_ptr[1] = '\0'; - eptr->domain_name_len = 1; - eptr->binding_and_mode = 0x07; - - if( 0 != sn_nsdl_register_endpoint(handle, eptr) ){ - ret = false; - goto end; - } - - ret = true; - - retCounter = 2; - eptr->endpoint_name_ptr[0] = 'a'; - eptr->endpoint_name_ptr[1] = '\0'; - eptr->endpoint_name_len = 1; - eptr->type_ptr[0] = 'a'; - eptr->type_ptr[1] = '\0'; - eptr->type_len = 1; - eptr->lifetime_ptr[0] = 'a'; - eptr->lifetime_ptr[1] = '\0'; - eptr->lifetime_len = 1; - eptr->domain_name_ptr[0] = '&'; - eptr->domain_name_ptr[1] = '\0'; - eptr->domain_name_len = 1; - eptr->binding_and_mode = 0x07; - - if( 0 != sn_nsdl_register_endpoint(handle, eptr) ){ - ret = false; - goto end; - } - eptr->domain_name_ptr[0] = 'a'; - //<-- Test validateParameters here - - eptr->binding_and_mode = 0x07; - retCounter = 3; - sn_grs_stub.infoRetCounter = 2; - sn_grs_stub.expectedInfo = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); - memset( sn_grs_stub.expectedInfo, 0, sizeof(sn_nsdl_resource_info_s)); - sn_grs_stub.expectedInfo->resource_parameters_ptr = (sn_nsdl_resource_parameters_s*)malloc(sizeof(sn_nsdl_resource_parameters_s)); - sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_len = 1; - sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_ptr = (uint8_t*)malloc(2); - sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_ptr[0] = 'a'; - sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_ptr[1] = '\0'; - sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_ptr = (uint8_t*)malloc(2); - sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_ptr[0] = 'a'; - sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_ptr[1] = '\0'; - sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_len = 1; - sn_grs_stub.expectedInfo->resource_parameters_ptr->observable = 1; - sn_grs_stub.expectedInfo->resource_parameters_ptr->coap_content_type = 0; // XXX: why was this left uninitialized? what was point of this test? - - sn_grs_stub.expectedInfo->path = (uint8_t*)malloc(2); - sn_grs_stub.expectedInfo->path[0] = 'a'; - sn_grs_stub.expectedInfo->path[1] = '\0'; - sn_grs_stub.expectedInfo->pathlen = 1; - sn_grs_stub.expectedInfo->resource = (uint8_t*)malloc(2); - sn_grs_stub.expectedInfo->resource[0] = 'a'; - sn_grs_stub.expectedInfo->resource[1] = '\0'; - sn_grs_stub.expectedInfo->resourcelen = 1; - sn_grs_stub.expectedInfo->publish_uri = 1; - //sn_nsdl_build_registration_body == SN_NSDL_FAILURE - int8_t val = sn_nsdl_register_endpoint(handle, eptr); - - free(sn_grs_stub.expectedInfo->resource); - free(sn_grs_stub.expectedInfo->path); - free(sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_ptr); - free(sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_ptr); - free(sn_grs_stub.expectedInfo->resource_parameters_ptr); - free(sn_grs_stub.expectedInfo); - sn_grs_stub.expectedInfo = NULL; - if( 0 != val ){ - ret = false; - goto end; - } - - //creates payload - sn_grs_stub.info2ndRetCounter = 0; - sn_grs_stub.infoRetCounter = 1; - sn_grs_stub.expectedInfo = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); - memset( sn_grs_stub.expectedInfo, 0, sizeof(sn_nsdl_resource_info_s)); - sn_grs_stub.expectedInfo->resource_parameters_ptr = (sn_nsdl_resource_parameters_s*)calloc(sizeof(sn_nsdl_resource_parameters_s), 1); - sn_grs_stub.expectedInfo->resource_parameters_ptr->observable = 1; - sn_grs_stub.expectedInfo->publish_uri = 1; - eptr->binding_and_mode = 0x06; - retCounter = 4; - //set_endpoint_info == -1 - val = sn_nsdl_register_endpoint(handle, eptr); - free(sn_grs_stub.expectedInfo->resource_parameters_ptr); - free(sn_grs_stub.expectedInfo); - - if( 0 != val ){ - ret = false; - goto end; - } - - - handle->ep_information_ptr->domain_name_ptr = (uint8_t*)malloc(3); - handle->ep_information_ptr->endpoint_name_ptr = (uint8_t*)malloc(3); - eptr->binding_and_mode = 0x06; - retCounter = 4; - //set_endpoint_info == -1 - val = sn_nsdl_register_endpoint(handle, eptr); - if( 0 != val ){ - ret = false; - goto end; - } - - //creates payload - sn_grs_stub.info2ndRetCounter = 2; - sn_grs_stub.infoRetCounter = 2; - sn_grs_stub.expectedInfo = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); - memset( sn_grs_stub.expectedInfo, 0, sizeof(sn_nsdl_resource_info_s)); - sn_grs_stub.expectedInfo->resource_parameters_ptr = (sn_nsdl_resource_parameters_s*)malloc(sizeof(sn_nsdl_resource_parameters_s)); - sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_len = 1; - sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_ptr = (uint8_t*)malloc(2); - sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_ptr[0] = 'a'; - sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_ptr[1] = '\0'; - sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_ptr = (uint8_t*)malloc(2); - sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_ptr[0] = 'a'; - sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_ptr[1] = '\0'; - sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_len = 1; - sn_grs_stub.expectedInfo->resource_parameters_ptr->observable = 1; - sn_grs_stub.expectedInfo->resource_parameters_ptr->coap_content_type = 0; - - sn_grs_stub.expectedInfo->path = (uint8_t*)malloc(2); - sn_grs_stub.expectedInfo->path[0] = 'a'; - sn_grs_stub.expectedInfo->path[1] = '\0'; - sn_grs_stub.expectedInfo->pathlen = 1; - sn_grs_stub.expectedInfo->resource = (uint8_t*)malloc(2); - sn_grs_stub.expectedInfo->resource[0] = 'a'; - sn_grs_stub.expectedInfo->resource[1] = '\0'; - sn_grs_stub.expectedInfo->resourcelen = 1; - sn_grs_stub.expectedInfo->publish_uri = 1; - eptr->binding_and_mode = 0x06; - retCounter = 7; - - sn_coap_builder_stub.expectedUint16 = 1; - sn_coap_protocol_stub.expectedInt16 = 1; - //passes - val = sn_nsdl_register_endpoint(handle, eptr); - free(sn_grs_stub.expectedInfo->resource); - free(sn_grs_stub.expectedInfo->path); - free(sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_ptr); - free(sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_ptr); - free(sn_grs_stub.expectedInfo->resource_parameters_ptr); - free(sn_grs_stub.expectedInfo); - - if( 0 != val ){ - ret = false; - goto end; - } - - //test resource_type_len overflow - sn_grs_stub.info2ndRetCounter = 2; - sn_grs_stub.infoRetCounter = 2; - sn_grs_stub.expectedInfo = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); - memset( sn_grs_stub.expectedInfo, 0, sizeof(sn_nsdl_resource_info_s)); - sn_grs_stub.expectedInfo->resource_parameters_ptr = (sn_nsdl_resource_parameters_s*)malloc(sizeof(sn_nsdl_resource_parameters_s)); - sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_len = UINT16_MAX; - sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_ptr = (uint8_t*)malloc(UINT16_MAX); - sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_ptr[0] = 'a'; - sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_ptr[1] = '\0'; - sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_ptr = (uint8_t*)malloc(2); - sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_ptr[0] = 'a'; - sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_ptr[1] = '\0'; - sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_len = 1; - sn_grs_stub.expectedInfo->resource_parameters_ptr->observable = 1; - - sn_grs_stub.expectedInfo->path = (uint8_t*)malloc(2); - sn_grs_stub.expectedInfo->path[0] = 'a'; - sn_grs_stub.expectedInfo->path[1] = '\0'; - sn_grs_stub.expectedInfo->pathlen = 1; - sn_grs_stub.expectedInfo->resource = (uint8_t*)malloc(2); - sn_grs_stub.expectedInfo->resource[0] = 'a'; - sn_grs_stub.expectedInfo->resource[1] = '\0'; - sn_grs_stub.expectedInfo->resourcelen = 1; - sn_grs_stub.expectedInfo->publish_uri = 1; - eptr->binding_and_mode = 0x06; - retCounter = 7; - - sn_coap_builder_stub.expectedUint16 = 1; - sn_coap_protocol_stub.expectedInt16 = 1; - //passes - val = sn_nsdl_register_endpoint(handle, eptr); - free(sn_grs_stub.expectedInfo->resource); - free(sn_grs_stub.expectedInfo->path); - free(sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_ptr); - free(sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_ptr); - free(sn_grs_stub.expectedInfo->resource_parameters_ptr); - free(sn_grs_stub.expectedInfo); - - if( 0 != val ){ - ret = false; - goto end; - } - - //test interface len overflow - sn_grs_stub.info2ndRetCounter = 2; - sn_grs_stub.infoRetCounter = 2; - sn_grs_stub.expectedInfo = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); - memset( sn_grs_stub.expectedInfo, 0, sizeof(sn_nsdl_resource_info_s)); - sn_grs_stub.expectedInfo->resource_parameters_ptr = (sn_nsdl_resource_parameters_s*)malloc(sizeof(sn_nsdl_resource_parameters_s)); - sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_len = 1; - sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_ptr = (uint8_t*)malloc(2); - sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_ptr[0] = 'a'; - sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_ptr[1] = '\0'; - sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_ptr = (uint8_t*)malloc(2); - sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_ptr[0] = 'a'; - sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_ptr[1] = '\0'; - sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_len = 1; - sn_grs_stub.expectedInfo->resource_parameters_ptr->observable = 1; - - sn_grs_stub.expectedInfo->path = (uint8_t*)malloc(2); - sn_grs_stub.expectedInfo->path[0] = 'a'; - sn_grs_stub.expectedInfo->path[1] = '\0'; - sn_grs_stub.expectedInfo->pathlen = UINT16_MAX; - sn_grs_stub.expectedInfo->resource = (uint8_t*)malloc(2); - sn_grs_stub.expectedInfo->resource[0] = 'a'; - sn_grs_stub.expectedInfo->resource[1] = '\0'; - sn_grs_stub.expectedInfo->resourcelen = 1; - sn_grs_stub.expectedInfo->publish_uri = 1; - eptr->binding_and_mode = 0x06; - retCounter = 7; - - sn_coap_builder_stub.expectedUint16 = 1; - sn_coap_protocol_stub.expectedInt16 = 1; - //passes - val = sn_nsdl_register_endpoint(handle, eptr); - free(sn_grs_stub.expectedInfo->resource); - free(sn_grs_stub.expectedInfo->path); - free(sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_ptr); - free(sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_ptr); - free(sn_grs_stub.expectedInfo->resource_parameters_ptr); - free(sn_grs_stub.expectedInfo); - - if( 0 != val ){ - ret = false; - goto end; - } - - //test coap content overflow - sn_grs_stub.info2ndRetCounter = 2; - sn_grs_stub.infoRetCounter = 2; - sn_grs_stub.expectedInfo = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); - memset( sn_grs_stub.expectedInfo, 0, sizeof(sn_nsdl_resource_info_s)); - sn_grs_stub.expectedInfo->resource_parameters_ptr = (sn_nsdl_resource_parameters_s*)malloc(sizeof(sn_nsdl_resource_parameters_s)); - sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_len = 1; - sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_ptr = (uint8_t*)malloc(2); - sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_ptr[0] = 'a'; - sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_ptr[1] = '\0'; - sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_ptr = (uint8_t*)malloc(2); - sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_ptr[0] = 'a'; - sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_ptr[1] = '\0'; - sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_len = UINT16_MAX - 20; - sn_grs_stub.expectedInfo->resource_parameters_ptr->observable = 1; - sn_grs_stub.expectedInfo->resource_parameters_ptr->coap_content_type = UINT8_MAX; - - sn_grs_stub.expectedInfo->path = (uint8_t*)malloc(2); - sn_grs_stub.expectedInfo->path[0] = 'a'; - sn_grs_stub.expectedInfo->path[1] = '\0'; - sn_grs_stub.expectedInfo->pathlen = 1; - sn_grs_stub.expectedInfo->resource = (uint8_t*)malloc(2); - sn_grs_stub.expectedInfo->resource[0] = 'a'; - sn_grs_stub.expectedInfo->resource[1] = '\0'; - sn_grs_stub.expectedInfo->resourcelen = 1; - sn_grs_stub.expectedInfo->publish_uri = 1; - eptr->binding_and_mode = 0x06; - retCounter = 7; - - sn_coap_builder_stub.expectedUint16 = 1; - sn_coap_protocol_stub.expectedInt16 = 1; - //passes - val = sn_nsdl_register_endpoint(handle, eptr); - free(sn_grs_stub.expectedInfo->resource); - free(sn_grs_stub.expectedInfo->path); - free(sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_ptr); - free(sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_ptr); - free(sn_grs_stub.expectedInfo->resource_parameters_ptr); - free(sn_grs_stub.expectedInfo); - - if( 0 != val ){ - ret = false; - goto end; - } - - //test observe len overflow - sn_grs_stub.info2ndRetCounter = 2; - sn_grs_stub.infoRetCounter = 2; - sn_grs_stub.expectedInfo = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); - memset( sn_grs_stub.expectedInfo, 0, sizeof(sn_nsdl_resource_info_s)); - sn_grs_stub.expectedInfo->resource_parameters_ptr = (sn_nsdl_resource_parameters_s*)malloc(sizeof(sn_nsdl_resource_parameters_s)); - sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_len = 1; - sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_ptr = (uint8_t*)malloc(2); - sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_ptr[0] = 'a'; - sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_ptr[1] = '\0'; - sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_ptr = (uint8_t*)malloc(2); - sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_ptr[0] = 'a'; - sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_ptr[1] = '\0'; - sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_len = UINT16_MAX - 25; - sn_grs_stub.expectedInfo->resource_parameters_ptr->observable = 1; - sn_grs_stub.expectedInfo->resource_parameters_ptr->coap_content_type = 1; - - sn_grs_stub.expectedInfo->path = (uint8_t*)malloc(2); - sn_grs_stub.expectedInfo->path[0] = 'a'; - sn_grs_stub.expectedInfo->path[1] = '\0'; - sn_grs_stub.expectedInfo->pathlen = 1; - sn_grs_stub.expectedInfo->resource = (uint8_t*)malloc(2); - sn_grs_stub.expectedInfo->resource[0] = 'a'; - sn_grs_stub.expectedInfo->resource[1] = '\0'; - sn_grs_stub.expectedInfo->resourcelen = 1; - sn_grs_stub.expectedInfo->publish_uri = 1; - eptr->binding_and_mode = 0x06; - retCounter = 7; - - sn_coap_builder_stub.expectedUint16 = 1; - sn_coap_protocol_stub.expectedInt16 = 1; - //passes - val = sn_nsdl_register_endpoint(handle, eptr); - free(sn_grs_stub.expectedInfo->resource); - free(sn_grs_stub.expectedInfo->path); - free(sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_ptr); - free(sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_ptr); - free(sn_grs_stub.expectedInfo->resource_parameters_ptr); - free(sn_grs_stub.expectedInfo); - - if( 0 != val ){ - ret = false; - goto end; - } - - //test observe len overflow - sn_grs_stub.info2ndRetCounter = 2; - sn_grs_stub.infoRetCounter = 2; - sn_grs_stub.expectedInfo = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); - memset( sn_grs_stub.expectedInfo, 0, sizeof(sn_nsdl_resource_info_s)); - sn_grs_stub.expectedInfo->resource_parameters_ptr = (sn_nsdl_resource_parameters_s*)malloc(sizeof(sn_nsdl_resource_parameters_s)); - sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_len = 1; - sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_ptr = (uint8_t*)malloc(2); - sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_ptr[0] = 'a'; - sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_ptr[1] = '\0'; - sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_ptr = (uint8_t*)malloc(2); - sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_ptr[0] = 'a'; - sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_ptr[1] = '\0'; - sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_len = UINT16_MAX - 28; - sn_grs_stub.expectedInfo->resource_parameters_ptr->observable = 1; - sn_grs_stub.expectedInfo->resource_parameters_ptr->coap_content_type = 1; - - sn_grs_stub.expectedInfo->path = (uint8_t*)malloc(2); - sn_grs_stub.expectedInfo->path[0] = 'a'; - sn_grs_stub.expectedInfo->path[1] = '\0'; - sn_grs_stub.expectedInfo->pathlen = 1; - sn_grs_stub.expectedInfo->resource = (uint8_t*)malloc(2); - sn_grs_stub.expectedInfo->resource[0] = 'a'; - sn_grs_stub.expectedInfo->resource[1] = '\0'; - sn_grs_stub.expectedInfo->resourcelen = 1; - sn_grs_stub.expectedInfo->publish_uri = 1; - eptr->binding_and_mode = 0x06; - retCounter = 7; - - sn_coap_builder_stub.expectedUint16 = 1; - sn_coap_protocol_stub.expectedInt16 = 1; - //passes - val = sn_nsdl_register_endpoint(handle, eptr); - free(sn_grs_stub.expectedInfo->resource); - free(sn_grs_stub.expectedInfo->path); - free(sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_ptr); - free(sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_ptr); - free(sn_grs_stub.expectedInfo->resource_parameters_ptr); - free(sn_grs_stub.expectedInfo); - - if( 0 != val ){ - ret = false; - goto end; - } - - sn_grs_stub.info2ndRetCounter = 2; - sn_grs_stub.infoRetCounter = 2; - sn_grs_stub.expectedInfo = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); - memset( sn_grs_stub.expectedInfo, 0, sizeof(sn_nsdl_resource_info_s)); - sn_grs_stub.expectedInfo->resource_parameters_ptr = (sn_nsdl_resource_parameters_s*)malloc(sizeof(sn_nsdl_resource_parameters_s)); - sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_len = 1; - sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_ptr = (uint8_t*)malloc(2); - sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_ptr[0] = 'a'; - sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_ptr[1] = '\0'; - sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_ptr = (uint8_t*)malloc(2); - sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_ptr[0] = 'a'; - sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_ptr[1] = '\0'; - sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_len = 1; - sn_grs_stub.expectedInfo->resource_parameters_ptr->observable = 1; - sn_grs_stub.expectedInfo->resource_parameters_ptr->coap_content_type = 0; - sn_grs_stub.expectedInfo->path = (uint8_t*)malloc(2); - sn_grs_stub.expectedInfo->path[0] = 'a'; - sn_grs_stub.expectedInfo->path[1] = '\0'; - sn_grs_stub.expectedInfo->pathlen = 1; - sn_grs_stub.expectedInfo->resource = (uint8_t*)malloc(2); - sn_grs_stub.expectedInfo->resource[0] = 'a'; - sn_grs_stub.expectedInfo->resource[1] = '\0'; - sn_grs_stub.expectedInfo->resourcelen = 1; - sn_grs_stub.expectedInfo->publish_uri = 1; - eptr->binding_and_mode = 0x06; - retCounter = 4; - sn_coap_builder_stub.expectedUint16 = 1; - sn_coap_protocol_stub.expectedInt16 = 1; - //set_endpoint_info == -1 - val = sn_nsdl_register_endpoint(handle, eptr); - free(sn_grs_stub.expectedInfo->resource); - free(sn_grs_stub.expectedInfo->path); - free(sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_ptr); - free(sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_ptr); - free(sn_grs_stub.expectedInfo->resource_parameters_ptr); - free(sn_grs_stub.expectedInfo); - - if( 0 != val ){ - ret = false; - goto end; - } - -end: - free(sn_grs_stub.expectedGrs->coap); - free(eptr->domain_name_ptr); - free(eptr->lifetime_ptr); - free(eptr->type_ptr); - free(eptr->endpoint_name_ptr); - - free(eptr); - sn_nsdl_destroy(handle); - return true; -} - -bool test_sn_nsdl_unregister_endpoint() -{ - if( 0 != sn_nsdl_unregister_endpoint(NULL) ){ - return false; - } - - sn_grs_stub.retNull = false; - retCounter = 5; - sn_grs_stub.expectedGrs = (struct grs_s *)malloc(sizeof(struct grs_s)); - memset(sn_grs_stub.expectedGrs,0, sizeof(struct grs_s)); - struct nsdl_s* handle = sn_nsdl_init(&nsdl_tx_callback, &nsdl_rx_callback, &myMalloc, &myFree); - sn_grs_stub.expectedGrs->coap = (struct coap_s *)malloc(sizeof(struct coap_s)); - sn_grs_stub.expectedGrs->coap->sn_coap_protocol_free = myFree; - sn_grs_stub.expectedGrs->coap->sn_coap_protocol_malloc = myMalloc; - sn_grs_stub.expectedGrs->coap->sn_coap_rx_callback = nsdl_rx_callback; - sn_grs_stub.expectedGrs->coap->sn_coap_tx_callback = nsdl_tx_callback; - - if( 0 != sn_nsdl_unregister_endpoint(handle) ){ - return false; - } - - handle->sn_nsdl_endpoint_registered = 1; - if( 0 != sn_nsdl_unregister_endpoint(handle) ){ - return false; - } - - retCounter = 0; - handle->sn_nsdl_endpoint_registered = 1; - if( 0 != sn_nsdl_unregister_endpoint(handle) ){ - return false; - } - - retCounter = 1; - handle->sn_nsdl_endpoint_registered = 1; - if( 0 != sn_nsdl_unregister_endpoint(handle) ){ - return false; - } - - retCounter = 2; - handle->sn_nsdl_endpoint_registered = 1; - sn_coap_builder_stub.expectedUint16 = 0; - if( 0 != sn_nsdl_unregister_endpoint(handle) ){ - return false; - } - - //Following tests will test sn_nsdl_internal_coap_send() + stuff - retCounter = 2; - handle->sn_nsdl_endpoint_registered = 1; - sn_coap_builder_stub.expectedUint16 = 1; - if( 0 != sn_nsdl_unregister_endpoint(handle) ){ - return false; - } - - retCounter = 3; - handle->sn_nsdl_endpoint_registered = 1; - sn_coap_builder_stub.expectedUint16 = 1; - sn_coap_protocol_stub.expectedInt16 = -1; - if( 0 != sn_nsdl_unregister_endpoint(handle) ){ - return false; - } - - retCounter = 3; - handle->sn_nsdl_endpoint_registered = 1; - sn_coap_builder_stub.expectedUint16 = 1; - sn_coap_protocol_stub.expectedInt16 = 1; - if( 0 != sn_nsdl_unregister_endpoint(handle) ){ - return false; - } - - u_int8_t loc[] = {"location"}; - - handle->ep_information_ptr->location_ptr = (uint8_t*)malloc(sizeof(loc)); - handle->ep_information_ptr->location_len = (uint8_t)sizeof(loc); - - retCounter = 1; - handle->sn_nsdl_endpoint_registered = 1; - sn_coap_builder_stub.expectedUint16 = 1; - if( 0 != sn_nsdl_unregister_endpoint(handle) ){ - return false; - } - - retCounter = 2; - handle->sn_nsdl_endpoint_registered = 1; - sn_coap_builder_stub.expectedUint16 = 1; - sn_coap_protocol_stub.expectedInt16 = -1; - if( 0 != sn_nsdl_unregister_endpoint(handle) ){ - return false; - } - free(sn_grs_stub.expectedGrs->coap); - sn_nsdl_destroy(handle); - return true; -} - -bool test_sn_nsdl_update_registration() -{ - if( 0 != sn_nsdl_update_registration(NULL, NULL, 0) ){ - return false; - } - - sn_grs_stub.retNull = false; - retCounter = 4; - sn_grs_stub.expectedGrs = (struct grs_s *)malloc(sizeof(struct grs_s)); - memset(sn_grs_stub.expectedGrs,0, sizeof(struct grs_s)); - struct nsdl_s* handle = sn_nsdl_init(&nsdl_tx_callback, &nsdl_rx_callback, &myMalloc, &myFree); - sn_grs_stub.expectedGrs->coap = (struct coap_s *)malloc(sizeof(struct coap_s)); - sn_grs_stub.expectedGrs->coap->sn_coap_protocol_free = myFree; - sn_grs_stub.expectedGrs->coap->sn_coap_protocol_malloc = myMalloc; - sn_grs_stub.expectedGrs->coap->sn_coap_rx_callback = nsdl_rx_callback; - sn_grs_stub.expectedGrs->coap->sn_coap_tx_callback = nsdl_tx_callback; - - if( 0 != sn_nsdl_update_registration(handle, NULL, 0) ){ - return false; - } - - handle->sn_nsdl_endpoint_registered = 1; - if( 0 != sn_nsdl_update_registration(handle, NULL, 0) ){ - return false; - } - - retCounter = 1; - if( 0 != sn_nsdl_update_registration(handle, NULL, 0) ){ - return false; - } - - retCounter = 2; - if( 0 != sn_nsdl_update_registration(handle, NULL, 0) ){ - return false; - } - - retCounter = 4; - sn_grs_stub.infoRetCounter = 2; - sn_grs_stub.expectedInfo = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); - memset( sn_grs_stub.expectedInfo, 0, sizeof(sn_nsdl_resource_info_s)); - sn_grs_stub.expectedInfo->resource_parameters_ptr = (sn_nsdl_resource_parameters_s*)malloc(sizeof(sn_nsdl_resource_parameters_s)); - sn_grs_stub.expectedInfo->resource_parameters_ptr->registered = SN_NDSL_RESOURCE_REGISTERED; - sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_len = 1; - sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_ptr = (uint8_t*)malloc(2); - sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_ptr[0] = 'a'; - sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_ptr[1] = '\0'; - sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_ptr = (uint8_t*)malloc(2); - sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_ptr[0] = 'a'; - sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_ptr[1] = '\0'; - sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_len = 1; - sn_grs_stub.expectedInfo->resource_parameters_ptr->observable = 1; - - sn_grs_stub.expectedInfo->path = (uint8_t*)malloc(2); - sn_grs_stub.expectedInfo->path[0] = 'a'; - sn_grs_stub.expectedInfo->path[1] = '\0'; - sn_grs_stub.expectedInfo->pathlen = 1; - sn_grs_stub.expectedInfo->resource = (uint8_t*)malloc(2); - sn_grs_stub.expectedInfo->resource[0] = 'a'; - sn_grs_stub.expectedInfo->resource[1] = '\0'; - sn_grs_stub.expectedInfo->resourcelen = 1; - sn_grs_stub.expectedInfo->publish_uri = 1; - - sn_coap_builder_stub.expectedUint16 = 1; - int8_t val = sn_nsdl_update_registration(handle, NULL, 0); - - free(sn_grs_stub.expectedInfo->resource); - free(sn_grs_stub.expectedInfo->path); - free(sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_ptr); - free(sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_ptr); - free(sn_grs_stub.expectedInfo->resource_parameters_ptr); - free(sn_grs_stub.expectedInfo); - sn_grs_stub.expectedInfo = NULL; - - if( 0 != val ){ - return false; - } - - sn_grs_stub.info2ndRetCounter = 1; - sn_grs_stub.infoRetCounter = 1; - sn_grs_stub.expectedInfo = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); - memset( sn_grs_stub.expectedInfo, 0, sizeof(sn_nsdl_resource_info_s)); - sn_grs_stub.expectedInfo->resource_parameters_ptr = (sn_nsdl_resource_parameters_s*)calloc(sizeof(sn_nsdl_resource_parameters_s), 1); - sn_grs_stub.expectedInfo->resource_parameters_ptr->observable = 1; - sn_grs_stub.expectedInfo->publish_uri = 1; - retCounter = 3; - //set_endpoint_info == -1 - //sn_nsdl_build_registration_body == SN_NSDL_FAILURE - val = sn_nsdl_update_registration(handle, NULL, 0); - free(sn_grs_stub.expectedInfo->resource_parameters_ptr); - free(sn_grs_stub.expectedInfo); - - if( 0 != val ){ - return false; - } - - sn_grs_stub.info2ndRetCounter = 2; - sn_grs_stub.infoRetCounter = 2; - sn_grs_stub.expectedInfo = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); - memset( sn_grs_stub.expectedInfo, 0, sizeof(sn_nsdl_resource_info_s)); - sn_grs_stub.expectedInfo->resource_parameters_ptr = (sn_nsdl_resource_parameters_s*)malloc(sizeof(sn_nsdl_resource_parameters_s)); - memset( sn_grs_stub.expectedInfo->resource_parameters_ptr, 0, sizeof(sn_nsdl_resource_parameters_s)); - sn_grs_stub.expectedInfo->resource_parameters_ptr->observable = 1; - sn_grs_stub.expectedInfo->publish_uri = 1; - retCounter = 4; - sn_grs_stub.expectedInfo->resource_parameters_ptr->registered = SN_NDSL_RESOURCE_REGISTERING; - //set_endpoint_info == -1 - val = sn_nsdl_update_registration(handle, NULL, 0); - free(sn_grs_stub.expectedInfo->resource_parameters_ptr); - free(sn_grs_stub.expectedInfo); - - if( 0 != val ){ - return false; - } - - u_int8_t loc[] = {"location"}; - - handle->ep_information_ptr->location_ptr = (uint8_t*)malloc(sizeof(loc)); - handle->ep_information_ptr->location_len = (uint8_t)sizeof(loc); - - sn_grs_stub.info2ndRetCounter = 1; - sn_grs_stub.infoRetCounter = 1; - sn_grs_stub.expectedInfo = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); - memset( sn_grs_stub.expectedInfo, 0, sizeof(sn_nsdl_resource_info_s)); - sn_grs_stub.expectedInfo->resource_parameters_ptr = (sn_nsdl_resource_parameters_s*)malloc(sizeof(sn_nsdl_resource_parameters_s)); - memset( sn_grs_stub.expectedInfo->resource_parameters_ptr, 0, sizeof(sn_nsdl_resource_parameters_s)); - sn_grs_stub.expectedInfo->resource_parameters_ptr->observable = 1; - sn_grs_stub.expectedInfo->publish_uri = 1; - retCounter = 1; - sn_grs_stub.expectedInfo->resource_parameters_ptr->registered = SN_NDSL_RESOURCE_REGISTERING; - //set_endpoint_info == -1 - val = sn_nsdl_update_registration(handle, NULL, 0); - free(sn_grs_stub.expectedInfo->resource_parameters_ptr); - free(sn_grs_stub.expectedInfo); - - if( 0 != val ){ - return false; - } - - sn_grs_stub.info2ndRetCounter = 2; - sn_grs_stub.infoRetCounter = 2; - sn_grs_stub.expectedInfo = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); - memset( sn_grs_stub.expectedInfo, 0, sizeof(sn_nsdl_resource_info_s)); - sn_grs_stub.expectedInfo->resource_parameters_ptr = (sn_nsdl_resource_parameters_s*)malloc(sizeof(sn_nsdl_resource_parameters_s)); - memset( sn_grs_stub.expectedInfo->resource_parameters_ptr, 0, sizeof(sn_nsdl_resource_parameters_s)); - sn_grs_stub.expectedInfo->resource_parameters_ptr->observable = 1; - sn_grs_stub.expectedInfo->publish_uri = 1; - retCounter = 2; - sn_grs_stub.expectedInfo->resource_parameters_ptr->registered = SN_NDSL_RESOURCE_REGISTERING; - //set_endpoint_info == -1 - val = sn_nsdl_update_registration(handle, NULL, 0); - free(sn_grs_stub.expectedInfo->resource_parameters_ptr); - free(sn_grs_stub.expectedInfo); - - if( 0 != val ){ - return false; - } - free(sn_grs_stub.expectedGrs->coap); - sn_nsdl_destroy(handle); - return true; -} - -bool test_sn_nsdl_set_endpoint_location() -{ - - u_int8_t loc[] = {"location"}; - - uint8_t* location_ptr = (uint8_t*)malloc(sizeof(loc)); - uint8_t location_len = (uint8_t)sizeof(loc); - - sn_grs_stub.retNull = false; - retCounter = 4; - sn_grs_stub.expectedGrs = (struct grs_s *)malloc(sizeof(struct grs_s)); - memset(sn_grs_stub.expectedGrs,0, sizeof(struct grs_s)); - struct nsdl_s* handle = sn_nsdl_init(&nsdl_tx_callback, &nsdl_rx_callback, &myMalloc, &myFree); - - - if(sn_nsdl_set_endpoint_location(NULL,location_ptr,location_len) != -1){ - return false; - } - - if(sn_nsdl_set_endpoint_location(NULL,NULL,location_len) != -1){ - return false; - } - - if(sn_nsdl_set_endpoint_location(handle,NULL,location_len) != -1){ - return false; - } - - if(sn_nsdl_set_endpoint_location(handle,location_ptr,0) != -1){ - return false; - } - - if(sn_nsdl_set_endpoint_location(NULL,location_ptr,0) != -1){ - return false; - } - - retCounter = 1; - - if(sn_nsdl_set_endpoint_location(handle,location_ptr,location_len) != 0){ - return false; - } - - sn_nsdl_destroy(handle); - free(location_ptr); - - return true; -} - -bool test_sn_nsdl_nsp_lost() -{ - sn_nsdl_nsp_lost(NULL); - - sn_grs_stub.retNull = false; - retCounter = 4; - sn_grs_stub.expectedGrs = (struct grs_s *)malloc(sizeof(struct grs_s)); - memset(sn_grs_stub.expectedGrs,0, sizeof(struct grs_s)); - struct nsdl_s* handle = sn_nsdl_init(&nsdl_tx_callback, &nsdl_rx_callback, &myMalloc, &myFree); - - bool ret = true; - sn_nsdl_nsp_lost(handle); - if( SN_NSDL_ENDPOINT_NOT_REGISTERED != handle->sn_nsdl_endpoint_registered ){ - ret = false; - } - sn_nsdl_destroy(handle); - return ret; -} - -bool test_sn_nsdl_is_ep_registered() -{ - if( SN_NSDL_FAILURE != sn_nsdl_is_ep_registered(NULL)){ - return false; - } - sn_grs_stub.retNull = false; - retCounter = 4; - sn_grs_stub.expectedGrs = (struct grs_s *)malloc(sizeof(struct grs_s)); - memset(sn_grs_stub.expectedGrs,0, sizeof(struct grs_s)); - struct nsdl_s* handle = sn_nsdl_init(&nsdl_tx_callback, &nsdl_rx_callback, &myMalloc, &myFree); - handle->sn_nsdl_endpoint_registered = 1; - - bool ret = sn_nsdl_is_ep_registered(handle) == 1; - - sn_nsdl_destroy(handle); - return ret; -} - -bool test_sn_nsdl_send_observation_notification() -{ - if( 0 != sn_nsdl_send_observation_notification(NULL, NULL, 0,NULL,0,0,0,0) ){ - return false; - } - sn_grs_stub.retNull = false; - sn_grs_stub.expectedInt8 = SN_NSDL_SUCCESS; - retCounter = 5; - sn_grs_stub.expectedGrs = (struct grs_s *)malloc(sizeof(struct grs_s)); - memset(sn_grs_stub.expectedGrs,0, sizeof(struct grs_s)); - struct nsdl_s* handle = sn_nsdl_init(&nsdl_tx_callback, &nsdl_rx_callback, &myMalloc, &myFree); - sn_grs_stub.expectedGrs->coap = (struct coap_s *)malloc(sizeof(struct coap_s)); - sn_grs_stub.expectedGrs->coap->sn_coap_protocol_free = myFree; - sn_grs_stub.expectedGrs->coap->sn_coap_protocol_malloc = myMalloc; - sn_grs_stub.expectedGrs->coap->sn_coap_rx_callback = nsdl_rx_callback; - sn_grs_stub.expectedGrs->coap->sn_coap_tx_callback = nsdl_tx_callback; - - if( 0 != sn_nsdl_send_observation_notification(handle, NULL, 0,NULL,0,0,0,0) ){ - return false; - } - - retCounter = 0; - if( 0 != sn_nsdl_send_observation_notification(handle, NULL, 0,NULL,0,0,0,0) ){ - return false; - } - - retCounter = 1; - if( 0 != sn_nsdl_send_observation_notification(handle, NULL, 0,NULL,0,0,0,0) ){ - return false; - } - - retCounter = 2; - if( 0 != sn_nsdl_send_observation_notification(handle, NULL, 0,NULL,0,0,0,1) ){ - return false; - } - - retCounter = 2; - if( 0 != sn_nsdl_send_observation_notification(handle, NULL, 0,NULL,0,0,0,1) ){ - return false; - } - - retCounter = 2; - sn_grs_stub.int8SuccessCounter = 0; - sn_grs_stub.expectedInt8 = SN_NSDL_FAILURE; - if( 0 != sn_nsdl_send_observation_notification(handle, NULL, 0,NULL,0,0,0,1) ){ - return false; - } - free(sn_grs_stub.expectedGrs->coap); - sn_nsdl_destroy(handle); - return true; -} - -bool test_sn_nsdl_send_observation_notification_with_uri_path() -{ - if( 0 != sn_nsdl_send_observation_notification_with_uri_path(NULL, NULL, 0,NULL,0,0,0,0, NULL,0) ){ - return false; - } - sn_grs_stub.retNull = false; - retCounter = 5; - sn_grs_stub.expectedGrs = (struct grs_s *)malloc(sizeof(struct grs_s)); - memset(sn_grs_stub.expectedGrs,0, sizeof(struct grs_s)); - struct nsdl_s* handle = sn_nsdl_init(&nsdl_tx_callback, &nsdl_rx_callback, &myMalloc, &myFree); - sn_grs_stub.expectedGrs->coap = (struct coap_s *)malloc(sizeof(struct coap_s)); - sn_grs_stub.expectedGrs->coap->sn_coap_protocol_free = myFree; - sn_grs_stub.expectedGrs->coap->sn_coap_protocol_malloc = myMalloc; - sn_grs_stub.expectedGrs->coap->sn_coap_rx_callback = nsdl_rx_callback; - sn_grs_stub.expectedGrs->coap->sn_coap_tx_callback = nsdl_tx_callback; - - u_int8_t path[] = {"13/0/1"}; - uint8_t* uri_path_ptr = (uint8_t*)malloc(sizeof(path)); - uint8_t uri_path_len = (uint8_t)sizeof(path); - if( 0 != sn_nsdl_send_observation_notification_with_uri_path(handle, NULL, 0,NULL,0,0,0,0,uri_path_ptr,uri_path_len) ){ - return false; - } - - retCounter = 0; - if( 0 != sn_nsdl_send_observation_notification_with_uri_path(handle, NULL, 0,NULL,0,0,0,0,uri_path_ptr,uri_path_len) ){ - return false; - } - - retCounter = 1; - if( 0 != sn_nsdl_send_observation_notification_with_uri_path(handle, NULL, 0,NULL,0,0,0,0,uri_path_ptr,uri_path_len) ){ - return false; - } - - retCounter = 2; - if( 0 != sn_nsdl_send_observation_notification_with_uri_path(handle, NULL, 0,NULL,0,0,0,1,uri_path_ptr,uri_path_len) ){ - return false; - } - - retCounter = 2; - if( 0 != sn_nsdl_send_observation_notification_with_uri_path(handle, NULL, 0,NULL,0,0,0,1,uri_path_ptr,uri_path_len) ){ - return false; - } - - retCounter = 2; - if( 0 != sn_nsdl_send_observation_notification_with_uri_path(handle, NULL, 0,NULL,0,0,0,1,uri_path_ptr,uri_path_len) ){ - return false; - } - - retCounter = 2; - sn_grs_stub.int8SuccessCounter = 0; - sn_grs_stub.expectedInt8 = SN_NSDL_FAILURE; - if( 0 != sn_nsdl_send_observation_notification_with_uri_path(handle, NULL, 0,NULL,0,0,0,1,NULL,0) ){ - return false; - } - free(sn_grs_stub.expectedGrs->coap); - free(uri_path_ptr); - sn_nsdl_destroy(handle); - return true; -} - -bool test_sn_nsdl_oma_bootstrap() -{ - if( 0 != sn_nsdl_oma_bootstrap(NULL, NULL, NULL, NULL)){ - return false; - } - sn_grs_stub.retNull = false; - retCounter = 5; - sn_grs_stub.expectedGrs = (struct grs_s *)malloc(sizeof(struct grs_s)); - memset(sn_grs_stub.expectedGrs,0, sizeof(struct grs_s)); - struct nsdl_s* handle = sn_nsdl_init(&nsdl_tx_callback, &nsdl_rx_callback, &myMalloc, &myFree); - sn_grs_stub.expectedGrs->coap = (struct coap_s *)malloc(sizeof(struct coap_s)); - sn_grs_stub.expectedGrs->coap->sn_coap_protocol_free = myFree; - sn_grs_stub.expectedGrs->coap->sn_coap_protocol_malloc = myMalloc; - sn_grs_stub.expectedGrs->coap->sn_coap_rx_callback = nsdl_rx_callback; - sn_grs_stub.expectedGrs->coap->sn_coap_tx_callback = nsdl_tx_callback; - - sn_nsdl_addr_s *addr = (sn_nsdl_addr_s*)malloc(sizeof(sn_nsdl_addr_s)); - memset(addr, 0, sizeof(sn_nsdl_addr_s)); - sn_nsdl_ep_parameters_s *param = (sn_nsdl_ep_parameters_s*)malloc(sizeof(sn_nsdl_ep_parameters_s)); - memset(param, 0, sizeof(sn_nsdl_ep_parameters_s)); - sn_nsdl_bs_ep_info_t *info = (sn_nsdl_bs_ep_info_t*)malloc(sizeof(sn_nsdl_bs_ep_info_t)); - memset(info, 0, sizeof(sn_nsdl_bs_ep_info_t)); - - if( 0 != sn_nsdl_oma_bootstrap(handle, addr, param, info)){ - return false; - } - - info->device_object = (sn_nsdl_oma_device_t*)malloc(sizeof(sn_nsdl_oma_device_t)); - memset(info->device_object, 0, sizeof(sn_nsdl_oma_device_t)); - - if( 0 != sn_nsdl_oma_bootstrap(handle, addr, param, info)){ - return false; - } - - retCounter = 0; - sn_grs_stub.expectedInt8 = -1; - if( 0 != sn_nsdl_oma_bootstrap(handle, addr, param, info)){ - return false; - } - - retCounter = 1; - sn_grs_stub.expectedInt8 = -1; - if( 0 != sn_nsdl_oma_bootstrap(handle, addr, param, info)){ - return false; - } - - retCounter = 1; - sn_grs_stub.expectedInt8 = -1; - sn_grs_stub.int8SuccessCounter = 1; - param->binding_and_mode = 0; - if( 0 != sn_nsdl_oma_bootstrap(handle, addr, param, info)){ - return false; - } - - retCounter = 1; - sn_grs_stub.int8SuccessCounter = 2; - param->binding_and_mode = 3; - if( 0 != sn_nsdl_oma_bootstrap(handle, addr, param, info)){ - return false; - } - - retCounter = 1; - sn_grs_stub.int8SuccessCounter = 3; - param->binding_and_mode = 6; - if( 0 != sn_nsdl_oma_bootstrap(handle, addr, param, info)){ - return false; - } - - retCounter = 2; - sn_grs_stub.int8SuccessCounter = 3; - param->binding_and_mode = 6; - if( 0 != sn_nsdl_oma_bootstrap(handle, addr, param, info)){ - return false; - } - - retCounter = 3; - sn_grs_stub.int8SuccessCounter = 3; - param->binding_and_mode = 6; - if( 0 != sn_nsdl_oma_bootstrap(handle, addr, param, info)){ - return false; - } - - retCounter = 6; - sn_grs_stub.expectedInt8 = 0; - sn_grs_stub.int8SuccessCounter = 3; - param->binding_and_mode = 6; - sn_coap_builder_stub.expectedUint16 = 1; - if( 0 != sn_nsdl_oma_bootstrap(handle, addr, param, info)){ - return false; - } - - free(info->device_object); - free(info); - free(param); - free(addr); - free(sn_grs_stub.expectedGrs->coap); - retCounter = 1; - sn_nsdl_destroy(handle); - return true; -} - -bool test_sn_nsdl_get_certificates() -{ - if( 0 != sn_nsdl_get_certificates(NULL)){ - return false; - } - sn_grs_stub.retNull = false; - retCounter = 4; - sn_grs_stub.expectedGrs = (struct grs_s *)malloc(sizeof(struct grs_s)); - memset(sn_grs_stub.expectedGrs,0, sizeof(struct grs_s)); - struct nsdl_s* handle = sn_nsdl_init(&nsdl_tx_callback, &nsdl_rx_callback, &myMalloc, &myFree); - - if( 0 != sn_nsdl_get_certificates(handle)){ - return false; - } - - retCounter = 1; - sn_grs_stub.retNull = true; - if( 0 != sn_nsdl_get_certificates(handle)){ - return false; - } - - retCounter = 1; - sn_grs_stub.retNull = false; - sn_grs_stub.infoRetCounter = 1; - sn_grs_stub.expectedInfo = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); - memset( sn_grs_stub.expectedInfo, 0, sizeof(sn_nsdl_resource_info_s)); - if( 0 != sn_nsdl_get_certificates(handle)){ - return false; - } - - retCounter = 1; - sn_grs_stub.retNull = false; - sn_grs_stub.infoRetCounter = 2; - if( 0 != sn_nsdl_get_certificates(handle)){ - return false; - } - - retCounter = 1; - sn_grs_stub.retNull = false; - sn_grs_stub.infoRetCounter = 3; - omalw_certificate_list_t* list = sn_nsdl_get_certificates(handle); - if( 0 == list ){ - return false; - } - free(list); - free(sn_grs_stub.expectedInfo); - - sn_nsdl_destroy(handle); - return true; -} - -bool test_sn_nsdl_update_certificates() -{ - if( -1 != sn_nsdl_update_certificates(NULL, NULL, 0) ){ - return false; - } - sn_grs_stub.retNull = false; - retCounter = 4; - sn_grs_stub.expectedGrs = (struct grs_s *)malloc(sizeof(struct grs_s)); - memset(sn_grs_stub.expectedGrs,0, sizeof(struct grs_s)); - struct nsdl_s* handle = sn_nsdl_init(&nsdl_tx_callback, &nsdl_rx_callback, &myMalloc, &myFree); - - omalw_certificate_list_t* list = (omalw_certificate_list_t*)malloc(sizeof(omalw_certificate_list_t)); - memset( list, 0, sizeof(omalw_certificate_list_t)); - - sn_grs_stub.retNull = true; - if( -1 != sn_nsdl_update_certificates(handle, list, 0) ){ - return false; - } - - sn_grs_stub.retNull = false; - sn_grs_stub.infoRetCounter = 1; - sn_grs_stub.expectedInfo = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); - memset( sn_grs_stub.expectedInfo, 0, sizeof(sn_nsdl_resource_info_s)); - if( -1 != sn_nsdl_update_certificates(handle, list, 0) ){ - return false; - } - - sn_grs_stub.retNull = false; - sn_grs_stub.infoRetCounter = 2; - if( -1 != sn_nsdl_update_certificates(handle, list, 0) ){ - return false; - } - - sn_grs_stub.retNull = false; - sn_grs_stub.infoRetCounter = 3; - if( 0 != sn_nsdl_update_certificates(handle, list, 0) ){ - return false; - } - - free(sn_grs_stub.expectedInfo); - free(list); - sn_nsdl_destroy(handle); - return true; -} - -bool test_sn_nsdl_create_oma_device_object() -{ - if( -1 != sn_nsdl_create_oma_device_object(NULL, NULL) ){ - return false; - } - sn_grs_stub.retNull = false; - retCounter = 4; - sn_grs_stub.expectedGrs = (struct grs_s *)malloc(sizeof(struct grs_s)); - memset(sn_grs_stub.expectedGrs,0, sizeof(struct grs_s)); - struct nsdl_s* handle = sn_nsdl_init(&nsdl_tx_callback, &nsdl_rx_callback, &myMalloc, &myFree); - - sn_nsdl_oma_device_t *device = (sn_nsdl_oma_device_t*)malloc(sizeof(sn_nsdl_oma_device_t)); - memset( device, 0, sizeof(sn_nsdl_oma_device_t)); - - sn_grs_stub.retNull = true; - if( -1 != sn_nsdl_create_oma_device_object(handle, device) ){ - return false; - } - - sn_grs_stub.retNull = false; - sn_grs_stub.infoRetCounter = 1; - sn_grs_stub.expectedInfo = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); - memset( sn_grs_stub.expectedInfo, 0, sizeof(sn_nsdl_resource_info_s)); - - sn_grs_stub.useMockedPath = true; - sn_grs_stub.mockedPath[0] = '9'; - sn_grs_stub.mockedPath[1] = '9'; - sn_grs_stub.mockedPath[2] = '9'; - sn_grs_stub.mockedPath[3] = '9'; - sn_grs_stub.mockedPath[4] = '9'; - sn_grs_stub.mockedPath[5] = '9'; - sn_grs_stub.mockedPath[6] = '9'; - sn_grs_stub.mockedPath[7] = '9'; - sn_grs_stub.mockedPathLen = 8; - - if( -1 != sn_nsdl_create_oma_device_object(handle, device) ){ - return false; - } - - sn_grs_stub.infoRetCounter = 1; - sn_grs_stub.useMockedPath = true; - sn_grs_stub.mockedPath[0] = '1'; - sn_grs_stub.mockedPath[1] = '1'; - sn_grs_stub.mockedPath[2] = '1'; - sn_grs_stub.mockedPath[3] = '1'; - sn_grs_stub.mockedPath[4] = '1'; - sn_grs_stub.mockedPath[5] = '1'; - sn_grs_stub.mockedPath[6] = '1'; - sn_grs_stub.mockedPath[7] = '1'; - sn_grs_stub.mockedPathLen = 8; - - if( -1 != sn_nsdl_create_oma_device_object(handle, device) ){ - return false; - } - - sn_grs_stub.useMockedPath = false; - sn_grs_stub.infoRetCounter = 1; - - sn_grs_stub.expectedInfo->resource = (uint8_t*)malloc(4); - *sn_grs_stub.expectedInfo->resource = 0; - - if( SN_NSDL_SUCCESS != sn_nsdl_create_oma_device_object(handle, device) ){ - return false; - } - - sn_grs_stub.infoRetCounter = 1; - *sn_grs_stub.expectedInfo->resource = 1; - if( -1 != sn_nsdl_create_oma_device_object(handle, device) ){ - return false; - } - - free( sn_grs_stub.expectedInfo->resource ); - - retCounter = 1; - if( -1 != sn_nsdl_create_oma_device_object(handle, device) ){ - return false; - } - - retCounter = 2; - if( -1 != sn_nsdl_create_oma_device_object(handle, device) ){ - return false; - } - - retCounter = 3; - if( SN_NSDL_SUCCESS != sn_nsdl_create_oma_device_object(handle, device) ){ - return false; - } - - free(sn_grs_stub.expectedInfo); - free(device); - sn_nsdl_destroy(handle); - return true; -} - -bool test_sn_nsdl_get_version() -{ - char* ret = sn_nsdl_get_version(); - if( strcmp(ret, "0.0.0") != 0 ){ - return false; - } - - return true; -} - -bool test_sn_nsdl_process_coap() -{ - if( -1 != sn_nsdl_process_coap(NULL, NULL, 0, NULL) ){ - return false; - } - sn_grs_stub.retNull = false; - retCounter = 4; - sn_grs_stub.expectedGrs = (struct grs_s *)malloc(sizeof(struct grs_s)); - memset(sn_grs_stub.expectedGrs,0, sizeof(struct grs_s)); - struct nsdl_s* handle = sn_nsdl_init(&nsdl_tx_callback, &nsdl_rx_callback, &myMalloc, &myFree); - - sn_coap_protocol_stub.expectedHeader = NULL; - if( -1 != sn_nsdl_process_coap(handle, NULL, 0, NULL) ){ - return false; - } - - sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_grs_stub.expectedGrs->coap = (struct coap_s *)malloc(sizeof(struct coap_s)); - sn_grs_stub.expectedGrs->coap->sn_coap_protocol_free = myFree; - sn_grs_stub.expectedGrs->coap->sn_coap_protocol_malloc = myMalloc; - sn_grs_stub.expectedGrs->coap->sn_coap_rx_callback = nsdl_rx_callback; - sn_grs_stub.expectedGrs->coap->sn_coap_tx_callback = nsdl_tx_callback; - sn_grs_stub.expectedGrs->coap->sn_coap_block_data_size = 1; - - sn_coap_protocol_stub.expectedHeader->coap_status = 2; // != 0 && != 6 - if( SN_NSDL_SUCCESS != sn_nsdl_process_coap(handle, NULL, 0, NULL) ){ - return false; - } - - sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_protocol_stub.expectedHeader->coap_status = 0; - sn_coap_protocol_stub.expectedHeader->options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); - memset(sn_coap_protocol_stub.expectedHeader->options_list_ptr, 0, sizeof(sn_coap_options_list_s)); - sn_coap_protocol_stub.expectedHeader->options_list_ptr->proxy_uri_len = 2; - sn_coap_protocol_stub.expectedHeader->options_list_ptr->proxy_uri_ptr = (uint8_t*)malloc(2); - memset(sn_coap_protocol_stub.expectedHeader->options_list_ptr->proxy_uri_ptr, 0, 2); - - if( -1 != sn_nsdl_process_coap(handle, NULL, 0, NULL) ){ - return false; - } - - sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_protocol_stub.expectedHeader->coap_status = 0; - sn_coap_protocol_stub.expectedHeader->options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); - memset(sn_coap_protocol_stub.expectedHeader->options_list_ptr, 0, sizeof(sn_coap_options_list_s)); - sn_coap_protocol_stub.expectedHeader->options_list_ptr->proxy_uri_len = 2; - sn_coap_protocol_stub.expectedHeader->options_list_ptr->proxy_uri_ptr = (uint8_t*)malloc(2); - - sn_coap_builder_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_builder_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - if( SN_NSDL_SUCCESS != sn_nsdl_process_coap(handle, NULL, 0, NULL) ){ - return false; - } - sn_coap_builder_stub.expectedHeader = NULL; - - sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_protocol_stub.expectedHeader->coap_status = 6; - sn_coap_protocol_stub.expectedHeader->msg_code = COAP_MSG_CODE_REQUEST_DELETE + 1; - sn_coap_protocol_stub.expectedHeader->payload_ptr = (uint8_t*)malloc(2); - - if( -1 != sn_nsdl_process_coap(handle, NULL, 0, NULL) ){ - return false; - } - - sn_nsdl_addr_s *addr = (sn_nsdl_addr_s*)malloc(sizeof(sn_nsdl_addr_s)); - memset(addr, 0, sizeof(sn_nsdl_addr_s)); - - //Test sn_nsdl_local_rx_function fully here - sn_coap_builder_stub.expectedHeader = NULL; - - sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_protocol_stub.expectedHeader->coap_status = 6; - sn_coap_protocol_stub.expectedHeader->msg_code = COAP_MSG_CODE_REQUEST_DELETE + 1; - sn_coap_protocol_stub.expectedHeader->payload_ptr = (uint8_t*)malloc(2); - sn_coap_protocol_stub.expectedHeader->msg_id = 5; - sn_coap_protocol_stub.expectedHeader->msg_code = COAP_MSG_CODE_RESPONSE_CREATED; - handle->register_msg_id = 5; - handle->unregister_msg_id = 5; - if( -1 != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ - return false; - } - - sn_coap_builder_stub.expectedHeader = NULL; - - sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_protocol_stub.expectedHeader->coap_status = 6; - sn_coap_protocol_stub.expectedHeader->msg_code = COAP_MSG_CODE_REQUEST_DELETE + 1; - sn_coap_protocol_stub.expectedHeader->payload_ptr = (uint8_t*)malloc(2); - sn_coap_protocol_stub.expectedHeader->msg_id = 5; - sn_coap_protocol_stub.expectedHeader->msg_code = COAP_MSG_CODE_RESPONSE_CREATED; - sn_coap_protocol_stub.expectedHeader->options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); - memset(sn_coap_protocol_stub.expectedHeader->options_list_ptr, 0, sizeof(sn_coap_options_list_s)); - sn_coap_protocol_stub.expectedHeader->options_list_ptr->location_path_ptr = (uint8_t*)calloc(2, 1); - sn_coap_protocol_stub.expectedHeader->options_list_ptr->location_path_len = 2; - handle->register_msg_id = 5; - - if( 0 != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ - return false; - } - - sn_coap_builder_stub.expectedHeader = NULL; - - sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_protocol_stub.expectedHeader->coap_status = 6; - sn_coap_protocol_stub.expectedHeader->msg_code = COAP_MSG_CODE_REQUEST_DELETE + 1; - sn_coap_protocol_stub.expectedHeader->payload_ptr = (uint8_t*)malloc(2); - sn_coap_protocol_stub.expectedHeader->msg_id = 5; - sn_coap_protocol_stub.expectedHeader->msg_code = COAP_MSG_CODE_RESPONSE_CREATED; - sn_coap_protocol_stub.expectedHeader->options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); - memset(sn_coap_protocol_stub.expectedHeader->options_list_ptr, 0, sizeof(sn_coap_options_list_s)); - sn_coap_protocol_stub.expectedHeader->options_list_ptr->location_path_ptr = (uint8_t*)malloc(3); - sn_coap_protocol_stub.expectedHeader->options_list_ptr->location_path_len = 3; - - sn_coap_protocol_stub.expectedHeader->options_list_ptr->location_path_ptr[0] = '/'; - sn_coap_protocol_stub.expectedHeader->options_list_ptr->location_path_ptr[1] = '/'; - sn_coap_protocol_stub.expectedHeader->options_list_ptr->location_path_ptr[2] = '/'; - handle->register_msg_id = 5; - - if( -1 != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ - return false; - } - - sn_coap_builder_stub.expectedHeader = NULL; - - sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_protocol_stub.expectedHeader->coap_status = 6; - sn_coap_protocol_stub.expectedHeader->msg_code = COAP_MSG_CODE_REQUEST_DELETE + 1; - sn_coap_protocol_stub.expectedHeader->payload_ptr = (uint8_t*)malloc(2); - sn_coap_protocol_stub.expectedHeader->msg_id = 5; - sn_coap_protocol_stub.expectedHeader->msg_code = COAP_MSG_CODE_RESPONSE_CREATED; - sn_coap_protocol_stub.expectedHeader->options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); - memset(sn_coap_protocol_stub.expectedHeader->options_list_ptr, 0, sizeof(sn_coap_options_list_s)); - sn_coap_protocol_stub.expectedHeader->options_list_ptr->location_path_ptr = (uint8_t*)malloc(3); - sn_coap_protocol_stub.expectedHeader->options_list_ptr->location_path_len = 3; - - sn_coap_protocol_stub.expectedHeader->options_list_ptr->location_path_ptr[0] = '/'; - sn_coap_protocol_stub.expectedHeader->options_list_ptr->location_path_ptr[1] = '/'; - sn_coap_protocol_stub.expectedHeader->options_list_ptr->location_path_ptr[2] = '/'; - handle->register_msg_id = 5; - - retCounter = 1; - if( -1 != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ - return false; - } - - sn_coap_builder_stub.expectedHeader = NULL; - - sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_protocol_stub.expectedHeader->coap_status = 6; - sn_coap_protocol_stub.expectedHeader->msg_code = COAP_MSG_CODE_REQUEST_DELETE + 1; - sn_coap_protocol_stub.expectedHeader->payload_ptr = (uint8_t*)malloc(2); - sn_coap_protocol_stub.expectedHeader->msg_id = 5; - sn_coap_protocol_stub.expectedHeader->msg_code = COAP_MSG_CODE_RESPONSE_CREATED; - sn_coap_protocol_stub.expectedHeader->options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); - memset(sn_coap_protocol_stub.expectedHeader->options_list_ptr, 0, sizeof(sn_coap_options_list_s)); - sn_coap_protocol_stub.expectedHeader->options_list_ptr->location_path_ptr = (uint8_t*)malloc(3); - sn_coap_protocol_stub.expectedHeader->options_list_ptr->location_path_len = 3; - - sn_coap_protocol_stub.expectedHeader->options_list_ptr->location_path_ptr[0] = '/'; - sn_coap_protocol_stub.expectedHeader->options_list_ptr->location_path_ptr[1] = '/'; - sn_coap_protocol_stub.expectedHeader->options_list_ptr->location_path_ptr[2] = '/'; - - handle->register_msg_id = 5; - retCounter = 2; - if( 0 != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ - return false; - } - free(handle->ep_information_ptr->endpoint_name_ptr); - handle->ep_information_ptr->endpoint_name_ptr = NULL; - free(handle->ep_information_ptr->domain_name_ptr); - handle->ep_information_ptr->domain_name_ptr = NULL; - - sn_coap_builder_stub.expectedHeader = NULL; - - sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_protocol_stub.expectedHeader->coap_status = 6; - sn_coap_protocol_stub.expectedHeader->msg_code = COAP_MSG_CODE_REQUEST_DELETE + 1; - sn_coap_protocol_stub.expectedHeader->payload_ptr = (uint8_t*)malloc(2); - sn_coap_protocol_stub.expectedHeader->msg_id = 5; - sn_coap_protocol_stub.expectedHeader->msg_code = COAP_MSG_CODE_RESPONSE_CHANGED; - sn_coap_protocol_stub.expectedHeader->options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); - memset(sn_coap_protocol_stub.expectedHeader->options_list_ptr, 0, sizeof(sn_coap_options_list_s)); - sn_coap_protocol_stub.expectedHeader->options_list_ptr->location_path_ptr = (uint8_t*)malloc(3); - sn_coap_protocol_stub.expectedHeader->options_list_ptr->location_path_len = 3; - - sn_coap_protocol_stub.expectedHeader->options_list_ptr->location_path_ptr[0] = '/'; - sn_coap_protocol_stub.expectedHeader->options_list_ptr->location_path_ptr[1] = '/'; - sn_coap_protocol_stub.expectedHeader->options_list_ptr->location_path_ptr[2] = '/'; - - handle->register_msg_id = 0; - handle->unregister_msg_id = 0; - handle->update_register_msg_id = 5; - - retCounter = 2; - if( 0 != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ - return false; - } - free(handle->ep_information_ptr->endpoint_name_ptr); - handle->ep_information_ptr->endpoint_name_ptr = NULL; - free(handle->ep_information_ptr->domain_name_ptr); - handle->ep_information_ptr->domain_name_ptr = NULL; - - sn_coap_builder_stub.expectedHeader = NULL; - - sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_protocol_stub.expectedHeader->coap_status = 6; - sn_coap_protocol_stub.expectedHeader->msg_code = COAP_MSG_CODE_REQUEST_DELETE + 1; - sn_coap_protocol_stub.expectedHeader->payload_ptr = (uint8_t*)malloc(2); - sn_coap_protocol_stub.expectedHeader->msg_id = 5; - sn_coap_protocol_stub.expectedHeader->msg_code = COAP_MSG_CODE_RESPONSE_DELETED; - sn_coap_protocol_stub.expectedHeader->options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); - memset(sn_coap_protocol_stub.expectedHeader->options_list_ptr, 0, sizeof(sn_coap_options_list_s)); - sn_coap_protocol_stub.expectedHeader->options_list_ptr->location_path_ptr = (uint8_t*)malloc(3); - sn_coap_protocol_stub.expectedHeader->options_list_ptr->location_path_len = 3; - handle->register_msg_id = 5; - handle->unregister_msg_id = 5; - - handle->ep_information_ptr->endpoint_name_ptr = (uint8_t*)malloc(2); - handle->ep_information_ptr->domain_name_ptr = (uint8_t*)malloc(2); - - if( 0 != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ - return false; - } - - // <-- Test sn_nsdl_local_rx_function fully here - - sn_coap_builder_stub.expectedHeader = NULL; - - - sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_protocol_stub.expectedHeader->coap_status = 6; - sn_coap_protocol_stub.expectedHeader->msg_code = 0; - sn_grs_stub.expectedInt8 = -1; - - if( -1 != sn_nsdl_process_coap(handle, NULL, 0, NULL) ){ - return false; - } - // sn_coap_protocol_stub.expectedHeader is not deleted - - if( -1 != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ - return false; - } - - - sn_grs_stub.expectedInt8 = 0; - sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_protocol_stub.expectedHeader->coap_status = 6; - sn_coap_protocol_stub.expectedHeader->msg_code = 0; - sn_coap_protocol_stub.expectedHeader->content_format = 9; - - if( -1 != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ - return false; - } - - uint8_t * payload_ptr = (uint8_t*)malloc(40); - memset(payload_ptr, 0, 40); - - sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_protocol_stub.expectedHeader->coap_status = 6; - sn_coap_protocol_stub.expectedHeader->msg_code = 0; - sn_coap_protocol_stub.expectedHeader->content_format = 99; - - payload_ptr[0] = 0x20; - payload_ptr[1] = 0x00; - payload_ptr[2] = 0x01; - sn_coap_protocol_stub.expectedHeader->payload_ptr = payload_ptr; - sn_coap_protocol_stub.expectedHeader->payload_len = 3; - - if( -1 != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ - return false; - } - - sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_protocol_stub.expectedHeader->coap_status = 6; - sn_coap_protocol_stub.expectedHeader->msg_code = 0; - sn_coap_protocol_stub.expectedHeader->content_format = 99; - - payload_ptr[0] = 0x18; - payload_ptr[1] = 0x00; - payload_ptr[2] = 0x00; - payload_ptr[3] = 0x01; - sn_coap_protocol_stub.expectedHeader->payload_ptr = payload_ptr; - sn_coap_protocol_stub.expectedHeader->payload_len = 4; - - if( -1 != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ - return false; - } - - sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_protocol_stub.expectedHeader->coap_status = 6; - sn_coap_protocol_stub.expectedHeader->msg_code = 0; - sn_coap_protocol_stub.expectedHeader->content_format = 99; - - payload_ptr[0] = 0x08; - payload_ptr[1] = 0x01; - sn_coap_protocol_stub.expectedHeader->payload_len = 2; - sn_coap_protocol_stub.expectedHeader->payload_ptr = payload_ptr; - - sn_coap_builder_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_builder_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - if( SN_NSDL_SUCCESS != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ - return false; - } - sn_coap_builder_stub.expectedHeader = NULL; - - sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_protocol_stub.expectedHeader->coap_status = 6; - sn_coap_protocol_stub.expectedHeader->msg_code = 0; - sn_coap_protocol_stub.expectedHeader->content_format = 99; - - payload_ptr[0] = 0x10; - payload_ptr[1] = 0x00; - payload_ptr[2] = 0x01; - sn_coap_protocol_stub.expectedHeader->payload_len = 3; - sn_coap_protocol_stub.expectedHeader->payload_ptr = payload_ptr; - - sn_coap_builder_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_builder_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - if( SN_NSDL_SUCCESS != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ - return false; - } - sn_coap_builder_stub.expectedHeader = NULL; - - //Test sn_nsdl_process_oma_tlv switches with failing - - sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_protocol_stub.expectedHeader->coap_status = 6; - sn_coap_protocol_stub.expectedHeader->msg_code = 0; - sn_coap_protocol_stub.expectedHeader->content_format = 99; - - payload_ptr[0] = 0xC0; - payload_ptr[1] = 0x00; - payload_ptr[2] = 0xC0; - payload_ptr[3] = 0x00; - sn_coap_protocol_stub.expectedHeader->payload_len = 4; - sn_coap_protocol_stub.expectedHeader->payload_ptr = payload_ptr; - sn_grs_stub.int8SuccessCounter = 1; - sn_grs_stub.expectedInt8 = -1; - - sn_coap_builder_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_builder_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - if( SN_NSDL_SUCCESS != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ - return false; - } - sn_coap_builder_stub.expectedHeader = NULL; - - sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_protocol_stub.expectedHeader->coap_status = 6; - sn_coap_protocol_stub.expectedHeader->msg_code = 0; - sn_coap_protocol_stub.expectedHeader->content_format = 99; - - payload_ptr[0] = 0xC0; - payload_ptr[1] = 0x02; - payload_ptr[2] = 0xC0; - payload_ptr[3] = 0x02; - sn_coap_protocol_stub.expectedHeader->payload_len = 4; - sn_coap_protocol_stub.expectedHeader->payload_ptr = payload_ptr; - sn_grs_stub.int8SuccessCounter = 1; - sn_grs_stub.expectedInt8 = -1; - - sn_coap_builder_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_builder_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - if( SN_NSDL_SUCCESS != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ - return false; - } - sn_coap_builder_stub.expectedHeader = NULL; - - sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_protocol_stub.expectedHeader->coap_status = 6; - sn_coap_protocol_stub.expectedHeader->msg_code = 0; - sn_coap_protocol_stub.expectedHeader->content_format = 99; - - payload_ptr[0] = 0xC0; - payload_ptr[1] = 0x03; - payload_ptr[2] = 0xC0; - payload_ptr[3] = 0x03; - sn_coap_protocol_stub.expectedHeader->payload_len = 4; - sn_coap_protocol_stub.expectedHeader->payload_ptr = payload_ptr; - sn_grs_stub.int8SuccessCounter = 1; - sn_grs_stub.expectedInt8 = -1; - - sn_coap_builder_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_builder_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - if( SN_NSDL_SUCCESS != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ - return false; - } - sn_coap_builder_stub.expectedHeader = NULL; - - sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_protocol_stub.expectedHeader->coap_status = 6; - sn_coap_protocol_stub.expectedHeader->msg_code = 0; - sn_coap_protocol_stub.expectedHeader->content_format = 99; - - payload_ptr[0] = 0xC0; - payload_ptr[1] = 0x04; - payload_ptr[2] = 0xC0; - payload_ptr[3] = 0x04; - sn_coap_protocol_stub.expectedHeader->payload_len = 4; - sn_coap_protocol_stub.expectedHeader->payload_ptr = payload_ptr; - sn_grs_stub.int8SuccessCounter = 1; - sn_grs_stub.expectedInt8 = -1; - - sn_coap_builder_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_builder_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - if( SN_NSDL_SUCCESS != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ - return false; - } - sn_coap_builder_stub.expectedHeader = NULL; - - sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_protocol_stub.expectedHeader->coap_status = 6; - sn_coap_protocol_stub.expectedHeader->msg_code = 0; - sn_coap_protocol_stub.expectedHeader->content_format = 99; - - payload_ptr[0] = 0xC0; - payload_ptr[1] = 0x05; - payload_ptr[2] = 0xC0; - payload_ptr[3] = 0x05; - sn_coap_protocol_stub.expectedHeader->payload_len = 4; - sn_coap_protocol_stub.expectedHeader->payload_ptr = payload_ptr; - sn_grs_stub.int8SuccessCounter = 1; - sn_grs_stub.expectedInt8 = -1; - - if( SN_NSDL_FAILURE != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ - return false; - } - - sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_protocol_stub.expectedHeader->coap_status = 6; - sn_coap_protocol_stub.expectedHeader->msg_code = 0; - sn_coap_protocol_stub.expectedHeader->content_format = 99; - - payload_ptr[0] = 0xC0; - payload_ptr[1] = 0x01; - sn_coap_protocol_stub.expectedHeader->payload_len = 2; - sn_coap_protocol_stub.expectedHeader->payload_ptr = payload_ptr; - sn_grs_stub.int8SuccessCounter = 1; - sn_grs_stub.expectedInt8 = -1; - - if( SN_NSDL_FAILURE != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ - return false; - } - - // Content type 97 tests - sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_protocol_stub.expectedHeader->coap_status = 6; - sn_coap_protocol_stub.expectedHeader->msg_code = 0; - sn_coap_protocol_stub.expectedHeader->content_format = 97; - sn_coap_protocol_stub.expectedHeader->uri_path_ptr = (uint8_t*)malloc(1); - sn_coap_protocol_stub.expectedHeader->uri_path_ptr[0] = '2'; - sn_coap_protocol_stub.expectedHeader->uri_path_len = 1; - - if( SN_NSDL_SUCCESS != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ - return false; - } - - // --> - sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_protocol_stub.expectedHeader->coap_status = 6; - sn_coap_protocol_stub.expectedHeader->msg_code = 0; - sn_coap_protocol_stub.expectedHeader->content_format = 97; - sn_coap_protocol_stub.expectedHeader->uri_path_ptr = (uint8_t*)malloc(1); - sn_coap_protocol_stub.expectedHeader->uri_path_ptr[0] = '2'; - sn_coap_protocol_stub.expectedHeader->uri_path_len = 1; - sn_grs_stub.infoRetCounter = 3; - sn_grs_stub.expectedInfo = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); - memset( sn_grs_stub.expectedInfo, 0, sizeof(sn_nsdl_resource_info_s)); - - handle->nsp_address_ptr->omalw_address_ptr->type = 1; - - payload_ptr[0] = '2'; - payload_ptr[1] = '\0'; - sn_coap_protocol_stub.expectedHeader->payload_len = 1; - sn_coap_protocol_stub.expectedHeader->payload_ptr = payload_ptr; - - handle->sn_nsdl_oma_bs_done_cb = myBootstrapCallback; - handle->sn_nsdl_oma_bs_done_cb_handle = myBootstrapCallbackHandle; - - if( SN_NSDL_SUCCESS != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ - return false; - } - - free(sn_grs_stub.expectedInfo); - sn_grs_stub.expectedInfo = NULL; - - sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_protocol_stub.expectedHeader->coap_status = 6; - sn_coap_protocol_stub.expectedHeader->msg_code = 0; - sn_coap_protocol_stub.expectedHeader->content_format = 97; - sn_coap_protocol_stub.expectedHeader->uri_path_ptr = (uint8_t*)malloc(1); - sn_coap_protocol_stub.expectedHeader->uri_path_ptr[0] = '2'; - sn_coap_protocol_stub.expectedHeader->uri_path_len = 1; - sn_grs_stub.infoRetCounter = 3; - sn_grs_stub.expectedInfo = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); - memset( sn_grs_stub.expectedInfo, 0, sizeof(sn_nsdl_resource_info_s)); - handle->nsp_address_ptr->omalw_server_security = CERTIFICATE; - handle->nsp_address_ptr->omalw_address_ptr->type = 1; - - payload_ptr[0] = 'a'; - payload_ptr[1] = 'F'; - sn_coap_protocol_stub.expectedHeader->payload_len = 2; - sn_coap_protocol_stub.expectedHeader->payload_ptr = payload_ptr; - - handle->sn_nsdl_oma_bs_done_cb = myBootstrapCallback; - handle->sn_nsdl_oma_bs_done_cb_handle = myBootstrapCallbackHandle; - - if( SN_NSDL_SUCCESS != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ - return false; - } - - free(sn_grs_stub.expectedInfo); - sn_grs_stub.expectedInfo = NULL; - - handle->nsp_address_ptr->omalw_server_security = 0; - // <-- - - sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_protocol_stub.expectedHeader->coap_status = 6; - sn_coap_protocol_stub.expectedHeader->msg_code = 0; - sn_coap_protocol_stub.expectedHeader->content_format = 97; - sn_coap_protocol_stub.expectedHeader->uri_path_ptr = (uint8_t*)malloc(1); - sn_coap_protocol_stub.expectedHeader->uri_path_ptr[0] = '0'; - sn_coap_protocol_stub.expectedHeader->uri_path_len = 1; - - payload_ptr[0] = 0xC0; - payload_ptr[1] = 0x01; - sn_coap_protocol_stub.expectedHeader->payload_len = 1; - sn_coap_protocol_stub.expectedHeader->payload_ptr = payload_ptr; - - if( SN_NSDL_SUCCESS != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ - return false; - } - - //TODO: test rest of sn_nsdl_resolve_lwm2m_address here - - sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_protocol_stub.expectedHeader->coap_status = 6; - sn_coap_protocol_stub.expectedHeader->msg_code = 0; - sn_coap_protocol_stub.expectedHeader->content_format = 97; - sn_coap_protocol_stub.expectedHeader->uri_path_ptr = (uint8_t*)malloc(1); - sn_coap_protocol_stub.expectedHeader->uri_path_ptr[0] = '0'; - sn_coap_protocol_stub.expectedHeader->uri_path_len = 1; - - payload_ptr[0] = 0xC0; - payload_ptr[1] = 0x01; - sn_coap_protocol_stub.expectedHeader->payload_len = 2; - sn_coap_protocol_stub.expectedHeader->payload_ptr = payload_ptr; - - if( SN_NSDL_SUCCESS != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ - return false; - } - - sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_protocol_stub.expectedHeader->coap_status = 6; - sn_coap_protocol_stub.expectedHeader->msg_code = 0; - sn_coap_protocol_stub.expectedHeader->content_format = 97; - sn_coap_protocol_stub.expectedHeader->uri_path_ptr = (uint8_t*)malloc(1); - sn_coap_protocol_stub.expectedHeader->uri_path_ptr[0] = '0'; - sn_coap_protocol_stub.expectedHeader->uri_path_len = 1; - - payload_ptr[0] = 0xC0; - payload_ptr[1] = 0x01; - sn_coap_protocol_stub.expectedHeader->payload_len = 2; - sn_coap_protocol_stub.expectedHeader->payload_ptr = payload_ptr; - - if( SN_NSDL_SUCCESS != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ - return false; - } - - sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_protocol_stub.expectedHeader->coap_status = 6; - sn_coap_protocol_stub.expectedHeader->msg_code = 0; - sn_coap_protocol_stub.expectedHeader->content_format = 97; - sn_coap_protocol_stub.expectedHeader->uri_path_ptr = (uint8_t*)malloc(1); - sn_coap_protocol_stub.expectedHeader->uri_path_ptr[0] = '0'; - sn_coap_protocol_stub.expectedHeader->uri_path_len = 1; - - payload_ptr[0] = '/'; - payload_ptr[1] = '/'; - sn_coap_protocol_stub.expectedHeader->payload_len = 2; - sn_coap_protocol_stub.expectedHeader->payload_ptr = payload_ptr; - - if( SN_NSDL_SUCCESS != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ - return false; - } - - // --> Test IPv6 parsing here - sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_protocol_stub.expectedHeader->coap_status = 6; - sn_coap_protocol_stub.expectedHeader->msg_code = 0; - sn_coap_protocol_stub.expectedHeader->content_format = 97; - sn_coap_protocol_stub.expectedHeader->uri_path_ptr = (uint8_t*)malloc(1); - sn_coap_protocol_stub.expectedHeader->uri_path_ptr[0] = '0'; - sn_coap_protocol_stub.expectedHeader->uri_path_len = 1; - - payload_ptr[0] = '/'; - payload_ptr[1] = '/'; - payload_ptr[2] = ':'; - payload_ptr[3] = ':'; - payload_ptr[4] = 'A'; - payload_ptr[5] = ':'; - payload_ptr[6] = 'd'; - payload_ptr[7] = ':'; - payload_ptr[8] = '7'; - sn_coap_protocol_stub.expectedHeader->payload_len = 9; - sn_coap_protocol_stub.expectedHeader->payload_ptr = payload_ptr; - - if( SN_NSDL_SUCCESS != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ - return false; - } - - sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_protocol_stub.expectedHeader->coap_status = 6; - sn_coap_protocol_stub.expectedHeader->msg_code = 0; - sn_coap_protocol_stub.expectedHeader->content_format = 97; - sn_coap_protocol_stub.expectedHeader->uri_path_ptr = (uint8_t*)malloc(1); - sn_coap_protocol_stub.expectedHeader->uri_path_ptr[0] = '0'; - sn_coap_protocol_stub.expectedHeader->uri_path_len = 1; - - payload_ptr[0] = '/'; - payload_ptr[1] = '/'; - payload_ptr[2] = '['; - payload_ptr[3] = ':'; - payload_ptr[4] = 'A'; - payload_ptr[5] = ':'; - payload_ptr[6] = 'd'; - payload_ptr[7] = '7'; - payload_ptr[8] = ':'; - payload_ptr[9] = ':'; - payload_ptr[10] = ']'; - sn_coap_protocol_stub.expectedHeader->payload_len = 11; - sn_coap_protocol_stub.expectedHeader->payload_ptr = payload_ptr; - - retCounter = 0; - if( SN_NSDL_SUCCESS != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ - return false; - } - free( handle->nsp_address_ptr->omalw_address_ptr->addr_ptr ); //Investigate why would leak if removed? - handle->nsp_address_ptr->omalw_address_ptr->addr_ptr = NULL; - - sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_protocol_stub.expectedHeader->coap_status = 6; - sn_coap_protocol_stub.expectedHeader->msg_code = 0; - sn_coap_protocol_stub.expectedHeader->content_format = 97; - sn_coap_protocol_stub.expectedHeader->uri_path_ptr = (uint8_t*)malloc(1); - sn_coap_protocol_stub.expectedHeader->uri_path_ptr[0] = '0'; - sn_coap_protocol_stub.expectedHeader->uri_path_len = 1; - - payload_ptr[0] = '/'; - payload_ptr[1] = '/'; - payload_ptr[2] = '['; - payload_ptr[3] = '1'; - payload_ptr[4] = ':'; - payload_ptr[5] = 'A'; - payload_ptr[6] = '7'; - payload_ptr[7] = ':'; - payload_ptr[8] = 'd'; - payload_ptr[9] = '7'; - payload_ptr[10] = '7'; - payload_ptr[11] = ':'; - payload_ptr[12] = 'd'; - payload_ptr[13] = 'E'; - payload_ptr[14] = '7'; - payload_ptr[15] = '7'; - payload_ptr[16] = ':'; - payload_ptr[17] = ':'; - payload_ptr[18] = ']'; - payload_ptr[19] = ':'; - payload_ptr[20] = '3'; - sn_coap_protocol_stub.expectedHeader->payload_len = 21; - sn_coap_protocol_stub.expectedHeader->payload_ptr = payload_ptr; - - retCounter = 1; - if( SN_NSDL_SUCCESS != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ - return false; - } - free( handle->nsp_address_ptr->omalw_address_ptr->addr_ptr ); //Investigate why would leak if removed? - handle->nsp_address_ptr->omalw_address_ptr->addr_ptr = NULL; - - sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_protocol_stub.expectedHeader->coap_status = 6; - sn_coap_protocol_stub.expectedHeader->msg_code = 0; - sn_coap_protocol_stub.expectedHeader->content_format = 97; - sn_coap_protocol_stub.expectedHeader->uri_path_ptr = (uint8_t*)malloc(1); - sn_coap_protocol_stub.expectedHeader->uri_path_ptr[0] = '0'; - sn_coap_protocol_stub.expectedHeader->uri_path_len = 1; - - handle->nsp_address_ptr->omalw_address_ptr->addr_ptr = (uint8_t*)malloc(3); - - payload_ptr[0] = '/'; - payload_ptr[1] = '/'; - payload_ptr[2] = '['; - payload_ptr[3] = ':'; - payload_ptr[4] = ':'; - payload_ptr[5] = 'A'; - payload_ptr[6] = '7'; - payload_ptr[7] = ':'; - payload_ptr[8] = 'd'; - payload_ptr[9] = '7'; - payload_ptr[10] = '7'; - payload_ptr[11] = ':'; - payload_ptr[12] = 'd'; - payload_ptr[13] = 'E'; - payload_ptr[14] = '7'; - payload_ptr[15] = '7'; - payload_ptr[16] = ':'; - payload_ptr[17] = '1'; - payload_ptr[18] = ']'; - payload_ptr[19] = ':'; - payload_ptr[20] = '3'; - payload_ptr[21] = '/'; - sn_coap_protocol_stub.expectedHeader->payload_len = 22; - sn_coap_protocol_stub.expectedHeader->payload_ptr = payload_ptr; - - retCounter = 1; - if( SN_NSDL_SUCCESS != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ - return false; - } - free( handle->nsp_address_ptr->omalw_address_ptr->addr_ptr ); //Investigate why would leak if removed? - handle->nsp_address_ptr->omalw_address_ptr->addr_ptr = NULL; - - sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_protocol_stub.expectedHeader->coap_status = 6; - sn_coap_protocol_stub.expectedHeader->msg_code = 0; - sn_coap_protocol_stub.expectedHeader->content_format = 97; - sn_coap_protocol_stub.expectedHeader->uri_path_ptr = (uint8_t*)malloc(1); - sn_coap_protocol_stub.expectedHeader->uri_path_ptr[0] = '0'; - sn_coap_protocol_stub.expectedHeader->uri_path_len = 1; - - handle->nsp_address_ptr->omalw_address_ptr->addr_ptr = (uint8_t*)malloc(3); - - payload_ptr[0] = '/'; - payload_ptr[1] = '/'; - payload_ptr[2] = '['; - payload_ptr[3] = '2'; - payload_ptr[4] = ':'; - payload_ptr[5] = 'A'; - payload_ptr[6] = '7'; - payload_ptr[7] = ':'; - payload_ptr[8] = ':'; - payload_ptr[9] = '7'; - payload_ptr[10] = '7'; - payload_ptr[11] = ':'; - payload_ptr[12] = 'd'; - payload_ptr[13] = 'E'; - payload_ptr[14] = '7'; - payload_ptr[15] = '7'; - payload_ptr[16] = ':'; - payload_ptr[17] = '1'; - payload_ptr[18] = ']'; - payload_ptr[19] = ':'; - payload_ptr[20] = '3'; - payload_ptr[21] = '/'; - sn_coap_protocol_stub.expectedHeader->payload_len = 22; - sn_coap_protocol_stub.expectedHeader->payload_ptr = payload_ptr; - - retCounter = 1; - if( SN_NSDL_SUCCESS != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ - return false; - } - free( handle->nsp_address_ptr->omalw_address_ptr->addr_ptr ); //Investigate why would leak if removed? - handle->nsp_address_ptr->omalw_address_ptr->addr_ptr = NULL; - - sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_protocol_stub.expectedHeader->coap_status = 6; - sn_coap_protocol_stub.expectedHeader->msg_code = 0; - sn_coap_protocol_stub.expectedHeader->content_format = 97; - sn_coap_protocol_stub.expectedHeader->uri_path_ptr = (uint8_t*)malloc(1); - sn_coap_protocol_stub.expectedHeader->uri_path_ptr[0] = '0'; - sn_coap_protocol_stub.expectedHeader->uri_path_len = 1; - - payload_ptr[0] = '/'; - payload_ptr[1] = '/'; - payload_ptr[2] = '['; - payload_ptr[3] = ':'; - payload_ptr[4] = ':'; - payload_ptr[5] = ']'; - payload_ptr[6] = ':'; - payload_ptr[7] = '5'; - payload_ptr[8] = '/'; - sn_coap_protocol_stub.expectedHeader->payload_len = 9; - sn_coap_protocol_stub.expectedHeader->payload_ptr = payload_ptr; - - retCounter = 1; - if( SN_NSDL_SUCCESS != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ - return false; - } - free( handle->nsp_address_ptr->omalw_address_ptr->addr_ptr ); //Investigate why would leak if removed? - handle->nsp_address_ptr->omalw_address_ptr->addr_ptr = NULL; - // <-- - - sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_protocol_stub.expectedHeader->coap_status = 6; - sn_coap_protocol_stub.expectedHeader->msg_code = 0; - sn_coap_protocol_stub.expectedHeader->content_format = 97; - sn_coap_protocol_stub.expectedHeader->uri_path_ptr = (uint8_t*)malloc(1); - sn_coap_protocol_stub.expectedHeader->uri_path_ptr[0] = '0'; - sn_coap_protocol_stub.expectedHeader->uri_path_len = 1; - - payload_ptr[0] = '/'; - payload_ptr[1] = '/'; - payload_ptr[2] = ':'; - sn_coap_protocol_stub.expectedHeader->payload_len = 3; - sn_coap_protocol_stub.expectedHeader->payload_ptr = payload_ptr; - handle->sn_nsdl_oma_bs_done_cb = myBootstrapCallback; - handle->sn_nsdl_oma_bs_done_cb_handle = myBootstrapCallbackHandle; - - handle->nsp_address_ptr->omalw_address_ptr->addr_ptr = (uint8_t*)malloc(3); - - if( SN_NSDL_SUCCESS != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ - return false; - } - - //Test IPv4 here --> - sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_protocol_stub.expectedHeader->coap_status = 6; - sn_coap_protocol_stub.expectedHeader->msg_code = 0; - sn_coap_protocol_stub.expectedHeader->content_format = 97; - sn_coap_protocol_stub.expectedHeader->uri_path_ptr = (uint8_t*)malloc(1); - sn_coap_protocol_stub.expectedHeader->uri_path_ptr[0] = '0'; - sn_coap_protocol_stub.expectedHeader->uri_path_len = 1; - - payload_ptr[0] = '/'; - payload_ptr[1] = '/'; - payload_ptr[2] = '1'; - payload_ptr[3] = '.'; - payload_ptr[4] = '2'; - payload_ptr[5] = '.'; - payload_ptr[6] = '3'; - payload_ptr[7] = '.'; - payload_ptr[8] = '4'; - payload_ptr[9] = ':'; - payload_ptr[10] = '6'; - sn_coap_protocol_stub.expectedHeader->payload_len = 11; - sn_coap_protocol_stub.expectedHeader->payload_ptr = payload_ptr; - handle->sn_nsdl_oma_bs_done_cb = myBootstrapCallback; - handle->sn_nsdl_oma_bs_done_cb_handle = myBootstrapCallbackHandle; - - if( SN_NSDL_SUCCESS != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ - return false; - } - - sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_protocol_stub.expectedHeader->coap_status = 6; - sn_coap_protocol_stub.expectedHeader->msg_code = 0; - sn_coap_protocol_stub.expectedHeader->content_format = 97; - sn_coap_protocol_stub.expectedHeader->uri_path_ptr = (uint8_t*)malloc(1); - sn_coap_protocol_stub.expectedHeader->uri_path_ptr[0] = '0'; - sn_coap_protocol_stub.expectedHeader->uri_path_len = 1; - - payload_ptr[0] = '/'; - payload_ptr[1] = '/'; - payload_ptr[2] = '1'; - payload_ptr[3] = '.'; - payload_ptr[4] = '2'; - payload_ptr[5] = '.'; - payload_ptr[6] = '3'; - payload_ptr[7] = '.'; - payload_ptr[8] = '4'; - payload_ptr[9] = ':'; - payload_ptr[10] = '6'; - payload_ptr[11] = '6'; - sn_coap_protocol_stub.expectedHeader->payload_len = 12; - sn_coap_protocol_stub.expectedHeader->payload_ptr = payload_ptr; - handle->sn_nsdl_oma_bs_done_cb = myBootstrapCallback; - handle->sn_nsdl_oma_bs_done_cb_handle = myBootstrapCallbackHandle; - - - retCounter = 1; - if( SN_NSDL_SUCCESS != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ - return false; - } - free( handle->nsp_address_ptr->omalw_address_ptr->addr_ptr ); //Investigate why would leak if removed? - handle->nsp_address_ptr->omalw_address_ptr->addr_ptr = NULL; - - sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_protocol_stub.expectedHeader->coap_status = 6; - sn_coap_protocol_stub.expectedHeader->msg_code = 0; - sn_coap_protocol_stub.expectedHeader->content_format = 97; - sn_coap_protocol_stub.expectedHeader->uri_path_ptr = (uint8_t*)malloc(1); - sn_coap_protocol_stub.expectedHeader->uri_path_ptr[0] = '0'; - sn_coap_protocol_stub.expectedHeader->uri_path_len = 1; - - payload_ptr[0] = '/'; - payload_ptr[1] = '/'; - payload_ptr[2] = '1'; - payload_ptr[3] = '.'; - payload_ptr[4] = '2'; - payload_ptr[5] = '.'; - payload_ptr[6] = '3'; - payload_ptr[7] = '.'; - payload_ptr[8] = '4'; - payload_ptr[9] = ':'; - payload_ptr[10] = '6'; - payload_ptr[11] = '6'; - payload_ptr[12] = '/'; - sn_coap_protocol_stub.expectedHeader->payload_len = 13; - sn_coap_protocol_stub.expectedHeader->payload_ptr = payload_ptr; - handle->sn_nsdl_oma_bs_done_cb = myBootstrapCallback; - handle->sn_nsdl_oma_bs_done_cb_handle = myBootstrapCallbackHandle; - - retCounter = 1; - if( SN_NSDL_SUCCESS != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ - return false; - } - free( handle->nsp_address_ptr->omalw_address_ptr->addr_ptr ); //Investigate why would leak if removed? - handle->nsp_address_ptr->omalw_address_ptr->addr_ptr = NULL; - - sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_protocol_stub.expectedHeader->coap_status = 6; - sn_coap_protocol_stub.expectedHeader->msg_code = 0; - sn_coap_protocol_stub.expectedHeader->content_format = 97; - sn_coap_protocol_stub.expectedHeader->uri_path_ptr = (uint8_t*)malloc(1); - sn_coap_protocol_stub.expectedHeader->uri_path_ptr[0] = '0'; - sn_coap_protocol_stub.expectedHeader->uri_path_len = 1; - - payload_ptr[0] = '/'; - payload_ptr[1] = '/'; - payload_ptr[2] = 's'; - payload_ptr[3] = '.'; - payload_ptr[4] = 't'; - payload_ptr[5] = '.'; - payload_ptr[6] = 'u'; - payload_ptr[7] = '.'; - payload_ptr[8] = 'v'; - payload_ptr[9] = ':'; - payload_ptr[10] = '6'; - sn_coap_protocol_stub.expectedHeader->payload_len = 11; - sn_coap_protocol_stub.expectedHeader->payload_ptr = payload_ptr; - handle->sn_nsdl_oma_bs_done_cb = myBootstrapCallback; - handle->sn_nsdl_oma_bs_done_cb_handle = myBootstrapCallbackHandle; - - retCounter = 1; - if( SN_NSDL_SUCCESS != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ - return false; - } - free( handle->nsp_address_ptr->omalw_address_ptr->addr_ptr ); //Investigate why would leak if removed? - handle->nsp_address_ptr->omalw_address_ptr->addr_ptr = NULL; - - sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_protocol_stub.expectedHeader->coap_status = 6; - sn_coap_protocol_stub.expectedHeader->msg_code = 0; - sn_coap_protocol_stub.expectedHeader->content_format = 97; - sn_coap_protocol_stub.expectedHeader->uri_path_ptr = (uint8_t*)malloc(1); - sn_coap_protocol_stub.expectedHeader->uri_path_ptr[0] = '0'; - sn_coap_protocol_stub.expectedHeader->uri_path_len = 1; - - payload_ptr[0] = '/'; - payload_ptr[1] = '/'; - payload_ptr[2] = 's'; - payload_ptr[3] = '.'; - payload_ptr[4] = 't'; - payload_ptr[5] = '.'; - payload_ptr[6] = 'u'; - payload_ptr[7] = '.'; - payload_ptr[8] = 'v'; - payload_ptr[9] = ':'; - payload_ptr[10] = '6'; - sn_coap_protocol_stub.expectedHeader->payload_len = 11; - sn_coap_protocol_stub.expectedHeader->payload_ptr = payload_ptr; - handle->sn_nsdl_oma_bs_done_cb = myBootstrapCallback; - handle->sn_nsdl_oma_bs_done_cb_handle = myBootstrapCallbackHandle; - handle->handle_bootstrap_msg = false; - - retCounter = 1; - if( SN_NSDL_SUCCESS != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ - return false; - } - free( handle->nsp_address_ptr->omalw_address_ptr->addr_ptr ); //Investigate why would leak if removed? - handle->nsp_address_ptr->omalw_address_ptr->addr_ptr = NULL; - handle->handle_bootstrap_msg = true; - sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_protocol_stub.expectedHeader->coap_status = 6; - sn_coap_protocol_stub.expectedHeader->msg_code = 0; - sn_coap_protocol_stub.expectedHeader->content_format = 97; - sn_coap_protocol_stub.expectedHeader->uri_path_ptr = (uint8_t*)malloc(1); - sn_coap_protocol_stub.expectedHeader->uri_path_ptr[0] = '0'; - sn_coap_protocol_stub.expectedHeader->uri_path_len = 1; - - payload_ptr[0] = '/'; - payload_ptr[1] = '/'; - payload_ptr[2] = 's'; - payload_ptr[3] = '.'; - payload_ptr[4] = 't'; - payload_ptr[5] = '.'; - payload_ptr[6] = 'u'; - payload_ptr[7] = '.'; - payload_ptr[8] = 'v'; - payload_ptr[9] = '.'; - payload_ptr[10] = 'w'; - payload_ptr[11] = ':'; - payload_ptr[12] = '6'; - payload_ptr[13] = '/'; - sn_coap_protocol_stub.expectedHeader->payload_len = 14; - sn_coap_protocol_stub.expectedHeader->payload_ptr = payload_ptr; - handle->sn_nsdl_oma_bs_done_cb = myBootstrapCallback; - handle->sn_nsdl_oma_bs_done_cb_handle = myBootstrapCallbackHandle; - - retCounter = 1; - if( SN_NSDL_SUCCESS != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ - return false; - } - free( handle->nsp_address_ptr->omalw_address_ptr->addr_ptr ); //Investigate why would leak if removed? - handle->nsp_address_ptr->omalw_address_ptr->addr_ptr = NULL; - - sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_protocol_stub.expectedHeader->coap_status = 6; - sn_coap_protocol_stub.expectedHeader->msg_code = 0; - sn_coap_protocol_stub.expectedHeader->content_format = 97; - sn_coap_protocol_stub.expectedHeader->uri_path_ptr = (uint8_t*)malloc(1); - sn_coap_protocol_stub.expectedHeader->uri_path_ptr[0] = '0'; - sn_coap_protocol_stub.expectedHeader->uri_path_len = 1; - - payload_ptr[0] = '/'; - payload_ptr[1] = '/'; - payload_ptr[2] = 's'; - payload_ptr[3] = '.'; - payload_ptr[4] = 't'; - payload_ptr[5] = '.'; - payload_ptr[6] = 'u'; - payload_ptr[7] = '.'; - payload_ptr[8] = 'v'; - payload_ptr[9] = '.'; - payload_ptr[10] = 'w'; - payload_ptr[11] = ':'; - payload_ptr[12] = '6'; - sn_coap_protocol_stub.expectedHeader->payload_len = 13; - sn_coap_protocol_stub.expectedHeader->payload_ptr = payload_ptr; - handle->sn_nsdl_oma_bs_done_cb = myBootstrapCallback; - handle->sn_nsdl_oma_bs_done_cb_handle = myBootstrapCallbackHandle; - - retCounter = 1; - if( SN_NSDL_SUCCESS != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ - return false; - } - free( handle->nsp_address_ptr->omalw_address_ptr->addr_ptr ); //Investigate why would leak if removed? - handle->nsp_address_ptr->omalw_address_ptr->addr_ptr = NULL; - - sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_protocol_stub.expectedHeader->coap_status = 6; - sn_coap_protocol_stub.expectedHeader->msg_code = 0; - sn_coap_protocol_stub.expectedHeader->content_format = 97; - sn_coap_protocol_stub.expectedHeader->uri_path_ptr = (uint8_t*)malloc(1); - sn_coap_protocol_stub.expectedHeader->uri_path_ptr[0] = '0'; - sn_coap_protocol_stub.expectedHeader->uri_path_len = 1; - - free( payload_ptr ); - payload_ptr = malloc(276); - memset(payload_ptr, 1, 276); - payload_ptr[0] = '/'; - payload_ptr[1] = '/'; - payload_ptr[2] = 's'; - payload_ptr[3] = '.'; - payload_ptr[4] = 't'; - payload_ptr[5] = '.'; - payload_ptr[6] = 'u'; - payload_ptr[7] = '.'; - payload_ptr[8] = 'v'; - payload_ptr[9] = '.'; - payload_ptr[10] = 'w'; - payload_ptr[11] = ':'; - payload_ptr[12] = '6'; - sn_coap_protocol_stub.expectedHeader->payload_len = 276; - sn_coap_protocol_stub.expectedHeader->payload_ptr = payload_ptr; - handle->sn_nsdl_oma_bs_done_cb = myBootstrapCallback; - handle->sn_nsdl_oma_bs_done_cb_handle = myBootstrapCallbackHandle; - - retCounter = 1; - if( SN_NSDL_SUCCESS != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ - return false; - } - free( handle->nsp_address_ptr->omalw_address_ptr->addr_ptr ); //Investigate why would leak if removed? - handle->nsp_address_ptr->omalw_address_ptr->addr_ptr = NULL; - // <-- - - sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_protocol_stub.expectedHeader->coap_status = 6; - sn_coap_protocol_stub.expectedHeader->msg_code = 0; - sn_coap_protocol_stub.expectedHeader->content_format = 97; - sn_coap_protocol_stub.expectedHeader->uri_path_ptr = (uint8_t*)malloc(1); - sn_coap_protocol_stub.expectedHeader->uri_path_ptr[0] = '0'; - sn_coap_protocol_stub.expectedHeader->uri_path_len = 1; - - payload_ptr[0] = '/'; - payload_ptr[1] = '/'; - payload_ptr[2] = ':'; - payload_ptr[3] = ':'; - sn_coap_protocol_stub.expectedHeader->payload_len = 4; - sn_coap_protocol_stub.expectedHeader->payload_ptr = payload_ptr; - - if( SN_NSDL_SUCCESS != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ - return false; - } - - sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_protocol_stub.expectedHeader->coap_status = 3; - sn_coap_protocol_stub.expectedHeader->msg_code = 0; - sn_coap_protocol_stub.expectedHeader->content_format = 97; - sn_coap_protocol_stub.expectedHeader->uri_path_ptr = (uint8_t*)malloc(1); - sn_coap_protocol_stub.expectedHeader->uri_path_ptr[0] = '0'; - sn_coap_protocol_stub.expectedHeader->uri_path_len = 1; - - payload_ptr[0] = '/'; - payload_ptr[1] = '/'; - payload_ptr[2] = ':'; - payload_ptr[3] = ':'; - sn_coap_protocol_stub.expectedHeader->payload_len = 4; - sn_coap_protocol_stub.expectedHeader->payload_ptr = payload_ptr; - - if( SN_NSDL_SUCCESS != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ - return false; - } - - sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); - memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); - sn_coap_protocol_stub.expectedHeader->coap_status = 3; - sn_coap_protocol_stub.expectedHeader->msg_code = 0; - sn_coap_protocol_stub.expectedHeader->content_format = 97; - sn_coap_protocol_stub.expectedHeader->uri_path_ptr = (uint8_t*)malloc(1); - sn_coap_protocol_stub.expectedHeader->uri_path_ptr[0] = '0'; - sn_coap_protocol_stub.expectedHeader->uri_path_len = 1; - - payload_ptr[0] = '/'; - payload_ptr[1] = '/'; - payload_ptr[2] = ':'; - payload_ptr[3] = ':'; - sn_coap_protocol_stub.expectedHeader->payload_len = 4; - sn_coap_protocol_stub.expectedHeader->payload_ptr = payload_ptr; - - sn_grs_stub.expectedInfo = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); - memset( sn_grs_stub.expectedInfo, 0, sizeof(sn_nsdl_resource_info_s)); - sn_grs_stub.expectedInfo->external_memory_block = 1; - if( SN_NSDL_SUCCESS != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ - return false; - } - free(sn_grs_stub.expectedInfo); - sn_grs_stub.expectedInfo = NULL; - free(sn_grs_stub.expectedGrs->coap); - free(payload_ptr); - free(addr); - sn_nsdl_destroy(handle); - return true; -} - -bool test_sn_nsdl_exec() -{ - if( -1 != sn_nsdl_exec(NULL, NULL) ){ - return false; - } - - retCounter = 4; - sn_grs_stub.expectedGrs = (struct grs_s *)malloc(sizeof(struct grs_s)); - memset(sn_grs_stub.expectedGrs,0, sizeof(struct grs_s)); - struct nsdl_s* handle = sn_nsdl_init(&nsdl_tx_callback, &nsdl_rx_callback, &myMalloc, &myFree); - sn_coap_protocol_stub.expectedInt8 = 0; - - if( 0 != sn_nsdl_exec(handle,0) ){ - return false; - } - - sn_nsdl_destroy(handle); - return true; -} - -bool test_sn_nsdl_get_resource() -{ - if( NULL != sn_nsdl_get_resource(NULL, 0, NULL) ){ - return false; - } - sn_grs_stub.retNull = false; - retCounter = 4; - sn_grs_stub.expectedGrs = (struct grs_s *)malloc(sizeof(struct grs_s)); - memset(sn_grs_stub.expectedGrs,0, sizeof(struct grs_s)); - - struct nsdl_s* handle = sn_nsdl_init(&nsdl_tx_callback, &nsdl_rx_callback, &myMalloc, &myFree); - - sn_nsdl_get_resource(handle, 0, NULL); - - sn_nsdl_destroy(handle); - return true; -} - -bool test_set_NSP_address() -{ - if( SN_NSDL_FAILURE != set_NSP_address(NULL, NULL, 0, SN_NSDL_ADDRESS_TYPE_IPV4) ){ - return false; - } - sn_grs_stub.retNull = false; - retCounter = 4; - sn_grs_stub.expectedGrs = (struct grs_s *)malloc(sizeof(struct grs_s)); - memset(sn_grs_stub.expectedGrs,0, sizeof(struct grs_s)); - struct nsdl_s* handle = sn_nsdl_init(&nsdl_tx_callback, &nsdl_rx_callback, &myMalloc, &myFree); - - handle->nsp_address_ptr->omalw_address_ptr->addr_ptr = (uint8_t*)malloc(2); - memset( handle->nsp_address_ptr->omalw_address_ptr->addr_ptr, 0, 2 ); - - // Note: the set_NSP_address() will read 4 bytes of source address - uint8_t* addr4 = (uint8_t*)calloc(4, 1); - - if( SN_NSDL_FAILURE != set_NSP_address(handle, addr4, 0, SN_NSDL_ADDRESS_TYPE_IPV4) ){ - return false; - } - handle->nsp_address_ptr->omalw_address_ptr->addr_ptr = NULL; - - retCounter = 1; - if( SN_NSDL_SUCCESS != set_NSP_address(handle, addr4, 0, SN_NSDL_ADDRESS_TYPE_IPV4) ){ - return false; - } - free(handle->nsp_address_ptr->omalw_address_ptr->addr_ptr); - handle->nsp_address_ptr->omalw_address_ptr->addr_ptr = NULL; - - // Note: the set_NSP_address() will read 16 bytes of source address - uint8_t* addr6 = (uint8_t*)calloc(16, 1); - - if( SN_NSDL_FAILURE != set_NSP_address(handle, addr6, 0, SN_NSDL_ADDRESS_TYPE_IPV6) ){ - return false; - } - - - handle->nsp_address_ptr->omalw_address_ptr->addr_ptr = NULL; - handle->nsp_address_ptr->omalw_address_ptr->addr_ptr = (uint8_t*)malloc(2); - handle->nsp_address_ptr->omalw_address_ptr->addr_len = 2; - memset( handle->nsp_address_ptr->omalw_address_ptr->addr_ptr, 0, 2 ); - - retCounter = 1; - if( SN_NSDL_SUCCESS != set_NSP_address(handle, addr6, 0, SN_NSDL_ADDRESS_TYPE_IPV6) ){ - return false; - } - - free(addr4); - free(addr6); - sn_nsdl_destroy(handle); - return true; -} - -bool test_sn_nsdl_list_resource() -{ - if( NULL != sn_nsdl_list_resource(NULL, 0, NULL) ){ - return false; - } - sn_grs_stub.retNull = false; - retCounter = 4; - sn_grs_stub.expectedGrs = (struct grs_s *)malloc(sizeof(struct grs_s)); - memset(sn_grs_stub.expectedGrs,0, sizeof(struct grs_s)); - struct nsdl_s* handle = sn_nsdl_init(&nsdl_tx_callback, &nsdl_rx_callback, &myMalloc, &myFree); - - if( NULL != sn_nsdl_list_resource(handle, 0, NULL) ){ - return false; - } - - sn_nsdl_destroy(handle); - return true; -} - -bool test_sn_nsdl_free_resource_list() -{ - sn_nsdl_free_resource_list(NULL, NULL); - - sn_grs_stub.retNull = false; - retCounter = 4; - sn_grs_stub.expectedGrs = (struct grs_s *)malloc(sizeof(struct grs_s)); - memset(sn_grs_stub.expectedGrs,0, sizeof(struct grs_s)); - struct nsdl_s* handle = sn_nsdl_init(&nsdl_tx_callback, &nsdl_rx_callback, &myMalloc, &myFree); - - sn_grs_resource_list_s* list = (sn_grs_resource_list_s*)malloc(sizeof(sn_grs_resource_list_s)); - sn_nsdl_free_resource_list(handle, list); //mem leak or pass - - sn_nsdl_destroy(handle); - return true; -} - -bool test_sn_nsdl_update_resource() -{ - if( SN_NSDL_FAILURE != sn_nsdl_update_resource(NULL, NULL) ){ - return false; - } - sn_grs_stub.retNull = false; - retCounter = 4; - sn_grs_stub.expectedGrs = (struct grs_s *)malloc(sizeof(struct grs_s)); - memset(sn_grs_stub.expectedGrs,0, sizeof(struct grs_s)); - struct nsdl_s* handle = sn_nsdl_init(&nsdl_tx_callback, &nsdl_rx_callback, &myMalloc, &myFree); - - if( 0 != sn_nsdl_update_resource(handle, NULL) ){ - return false; - } - - sn_nsdl_destroy(handle); - return true; -} - -bool test_sn_nsdl_send_coap_message() -{ - if( SN_NSDL_FAILURE != sn_nsdl_send_coap_message(NULL, NULL, NULL) ){ - return false; - } - sn_grs_stub.retNull = false; - retCounter = 4; - sn_grs_stub.expectedGrs = (struct grs_s *)malloc(sizeof(struct grs_s)); - memset(sn_grs_stub.expectedGrs,0, sizeof(struct grs_s)); - struct nsdl_s* handle = sn_nsdl_init(&nsdl_tx_callback, &nsdl_rx_callback, &myMalloc, &myFree); - - if( 0 != sn_nsdl_send_coap_message(handle, NULL, NULL) ){ - return false; - } - - sn_nsdl_destroy(handle); - return true; -} - -bool test_sn_nsdl_create_resource() -{ - if( SN_NSDL_FAILURE != sn_nsdl_create_resource(NULL, NULL) ){ - return false; - } - sn_grs_stub.retNull = false; - retCounter = 4; - sn_grs_stub.expectedGrs = (struct grs_s *)malloc(sizeof(struct grs_s)); - memset(sn_grs_stub.expectedGrs,0, sizeof(struct grs_s)); - struct nsdl_s* handle = sn_nsdl_init(&nsdl_tx_callback, &nsdl_rx_callback, &myMalloc, &myFree); - - if( 0 != sn_nsdl_create_resource(handle, NULL) ){ - return false; - } - - sn_nsdl_destroy(handle); - return true; -} - -bool test_sn_nsdl_put_resource() -{ - if( SN_NSDL_FAILURE != sn_nsdl_put_resource(NULL, NULL) ){ - return false; - } - sn_grs_stub.retNull = false; - retCounter = 4; - sn_grs_stub.expectedGrs = (struct grs_s *)malloc(sizeof(struct grs_s)); - memset(sn_grs_stub.expectedGrs,0, sizeof(struct grs_s)); - struct nsdl_s* handle = sn_nsdl_init(&nsdl_tx_callback, &nsdl_rx_callback, &myMalloc, &myFree); - - if( 0 != sn_nsdl_put_resource(handle, NULL) ){ - return false; - } - - sn_nsdl_destroy(handle); - return true; -} - -bool test_sn_nsdl_delete_resource() -{ - if( SN_NSDL_FAILURE != sn_nsdl_delete_resource(NULL, 0, NULL) ){ - return false; - } - sn_grs_stub.retNull = false; - retCounter = 4; - sn_grs_stub.expectedGrs = (struct grs_s *)malloc(sizeof(struct grs_s)); - memset(sn_grs_stub.expectedGrs,0, sizeof(struct grs_s)); - struct nsdl_s* handle = sn_nsdl_init(&nsdl_tx_callback, &nsdl_rx_callback, &myMalloc, &myFree); - - if( 0 != sn_nsdl_delete_resource(handle, 0, NULL) ){ - return false; - } - - sn_nsdl_destroy(handle); - return true; -} - -bool test_sn_nsdl_get_first_resource() -{ - if( NULL != sn_nsdl_get_first_resource(NULL) ){ - return false; - } - sn_grs_stub.retNull = false; - retCounter = 4; - sn_grs_stub.expectedGrs = (struct grs_s *)malloc(sizeof(struct grs_s)); - memset(sn_grs_stub.expectedGrs,0, sizeof(struct grs_s)); - struct nsdl_s* handle = sn_nsdl_init(&nsdl_tx_callback, &nsdl_rx_callback, &myMalloc, &myFree); - - if( NULL != sn_nsdl_get_first_resource(handle) ){ - return false; - } - - sn_nsdl_destroy(handle); - return true; -} - -bool test_sn_nsdl_get_next_resource() -{ - if( NULL != sn_nsdl_get_next_resource(NULL, NULL) ){ - return false; - } - sn_grs_stub.retNull = false; - retCounter = 4; - sn_grs_stub.expectedGrs = (struct grs_s *)malloc(sizeof(struct grs_s)); - memset(sn_grs_stub.expectedGrs,0, sizeof(struct grs_s)); - struct nsdl_s* handle = sn_nsdl_init(&nsdl_tx_callback, &nsdl_rx_callback, &myMalloc, &myFree); - - if( NULL != sn_nsdl_get_next_resource(handle, NULL) ){ - return false; - } - - sn_nsdl_destroy(handle); - return true; -} - -bool test_sn_nsdl_build_response() -{ - if( NULL != sn_nsdl_build_response(NULL, NULL, 0) ){ - return false; - } - sn_grs_stub.retNull = false; - retCounter = 4; - sn_grs_stub.expectedGrs = (struct grs_s *)malloc(sizeof(struct grs_s)); - memset(sn_grs_stub.expectedGrs,0, sizeof(struct grs_s)); - struct nsdl_s* handle = sn_nsdl_init(&nsdl_tx_callback, &nsdl_rx_callback, &myMalloc, &myFree); - - if( NULL != sn_nsdl_build_response(handle, NULL, 0) ){ - return false; - } - - sn_nsdl_destroy(handle); - return true; -} - -bool test_sn_nsdl_release_allocated_coap_msg_mem() -{ - sn_nsdl_release_allocated_coap_msg_mem(NULL, NULL); - sn_grs_stub.retNull = false; - retCounter = 4; - sn_grs_stub.expectedGrs = (struct grs_s *)malloc(sizeof(struct grs_s)); - memset(sn_grs_stub.expectedGrs,0, sizeof(struct grs_s)); - struct nsdl_s* handle = sn_nsdl_init(&nsdl_tx_callback, &nsdl_rx_callback, &myMalloc, &myFree); - - sn_coap_hdr_s* list = (sn_coap_hdr_s*)calloc(sizeof(sn_coap_hdr_s), 1); - - sn_nsdl_release_allocated_coap_msg_mem(handle, list); //mem leak or pass - - sn_nsdl_destroy(handle); - return true; -} - -bool test_sn_nsdl_set_retransmission_parameters() -{ - struct nsdl_s* handle = NULL; - if (sn_nsdl_set_retransmission_parameters(handle, 10, 10) == 0){ - return false; - } - retCounter = 4; - sn_grs_stub.expectedGrs = (struct grs_s *)malloc(sizeof(struct grs_s)); - memset(sn_grs_stub.expectedGrs,0, sizeof(struct grs_s)); - handle = sn_nsdl_init(&nsdl_tx_callback, &nsdl_rx_callback, &myMalloc, &myFree); - sn_coap_protocol_stub.expectedInt8 = 0; - - if (sn_nsdl_set_retransmission_parameters(handle, 10, 10) != 0){ - return false; - } - sn_nsdl_destroy(handle); - return true; -} - -bool test_sn_nsdl_set_retransmission_buffer() -{ - struct nsdl_s* handle = NULL; - if (sn_nsdl_set_retransmission_buffer(handle,3,3 ) == 0){ - return false; - } - retCounter = 4; - sn_grs_stub.expectedGrs = (struct grs_s *)malloc(sizeof(struct grs_s)); - memset(sn_grs_stub.expectedGrs,0, sizeof(struct grs_s)); - handle = sn_nsdl_init(&nsdl_tx_callback, &nsdl_rx_callback, &myMalloc, &myFree); - sn_coap_protocol_stub.expectedInt8 = 0; - - if (sn_nsdl_set_retransmission_buffer(handle,3,3 ) != 0){ - return false; - } - sn_nsdl_destroy(handle); - return true; -} - -bool test_sn_nsdl_set_block_size() -{ - struct nsdl_s* handle = NULL; - if (sn_nsdl_set_block_size(handle,16) == 0){ - return false; - } - retCounter = 4; - sn_grs_stub.expectedGrs = (struct grs_s *)malloc(sizeof(struct grs_s)); - memset(sn_grs_stub.expectedGrs,0, sizeof(struct grs_s)); - handle = sn_nsdl_init(&nsdl_tx_callback, &nsdl_rx_callback, &myMalloc, &myFree); - sn_coap_protocol_stub.expectedInt8 = 0; - - if (sn_nsdl_set_block_size(handle,16) != 0){ - return false; - } - sn_nsdl_destroy(handle); - return true; -} - -bool test_sn_nsdl_set_duplicate_buffer_size() -{ - struct nsdl_s* handle = NULL; - if (sn_nsdl_set_duplicate_buffer_size(handle,999) == 0){ - return false; - } - retCounter = 4; - sn_grs_stub.expectedGrs = (struct grs_s *)malloc(sizeof(struct grs_s)); - memset(sn_grs_stub.expectedGrs,0, sizeof(struct grs_s)); - handle = sn_nsdl_init(&nsdl_tx_callback, &nsdl_rx_callback, &myMalloc, &myFree); - sn_coap_protocol_stub.expectedInt8 = 0; - - if (sn_nsdl_set_duplicate_buffer_size(handle,999) != 0){ - return false; - } - sn_nsdl_destroy(handle); - return true; -} - -bool test_sn_nsdl_set_context() -{ - struct nsdl_s* handle = NULL; - if (sn_nsdl_set_context(handle,NULL) == 0){ - printf("\n\neka\n\n"); - return false; - } - retCounter = 4; - sn_grs_stub.expectedGrs = (struct grs_s *)malloc(sizeof(struct grs_s)); - memset(sn_grs_stub.expectedGrs,0, sizeof(struct grs_s)); - handle = sn_nsdl_init(&nsdl_tx_callback, &nsdl_rx_callback, &myMalloc, &myFree); - - if (sn_nsdl_set_context(handle,NULL) != 0){ - printf("\n\ntoka\n\n"); - return false; - } - - int somecontext = 1; - if (sn_nsdl_set_context(handle,&somecontext) != 0){ - printf("\n\nkolmas\n\n"); - return false; - } - sn_nsdl_destroy(handle); - return true; -} - -bool test_sn_nsdl_get_context() -{ - struct nsdl_s* handle = NULL; - if (sn_nsdl_get_context(handle) != NULL){ - return false; - } - - retCounter = 4; - sn_grs_stub.expectedGrs = (struct grs_s *)malloc(sizeof(struct grs_s)); - memset(sn_grs_stub.expectedGrs,0, sizeof(struct grs_s)); - handle = sn_nsdl_init(&nsdl_tx_callback, &nsdl_rx_callback, &myMalloc, &myFree); - - int somecontext = 1; - sn_nsdl_set_context(handle,&somecontext); - if (sn_nsdl_get_context(handle) != &somecontext){ - return false; - } - - sn_nsdl_destroy(handle); - return true; -} diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/sn_nsdl/test_sn_nsdl.h b/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/sn_nsdl/test_sn_nsdl.h deleted file mode 100644 index 4a06024d5f..0000000000 --- a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/sn_nsdl/test_sn_nsdl.h +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright (c) 2015 ARM. All rights reserved. - */ -#ifndef TEST_SN_NSDL_H -#define TEST_SN_NSDL_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -bool test_sn_nsdl_destroy(); - -bool test_sn_nsdl_init(); - -bool test_sn_nsdl_register_endpoint(); - -bool test_sn_nsdl_unregister_endpoint(); - -bool test_sn_nsdl_update_registration(); - -bool test_sn_nsdl_set_endpoint_location(); - -bool test_sn_nsdl_nsp_lost(); - -bool test_sn_nsdl_is_ep_registered(); - -bool test_sn_nsdl_send_observation_notification(); - -bool test_sn_nsdl_send_observation_notification_with_uri_path(); - -bool test_sn_nsdl_oma_bootstrap(); - -bool test_sn_nsdl_get_certificates(); - -bool test_sn_nsdl_update_certificates(); - -bool test_sn_nsdl_create_oma_device_object(); - -bool test_sn_nsdl_get_version(); - -bool test_sn_nsdl_process_coap(); - -bool test_sn_nsdl_exec(); - -bool test_sn_nsdl_get_resource(); - -bool test_set_NSP_address(); - -bool test_sn_nsdl_list_resource(); - -bool test_sn_nsdl_free_resource_list(); - -bool test_sn_nsdl_update_resource(); - -bool test_sn_nsdl_send_coap_message(); - -bool test_sn_nsdl_create_resource(); - -bool test_sn_nsdl_put_resource(); - -bool test_sn_nsdl_delete_resource(); - -bool test_sn_nsdl_get_first_resource(); - -bool test_sn_nsdl_get_next_resource(); - -bool test_sn_nsdl_build_response(); - -bool test_sn_nsdl_release_allocated_coap_msg_mem(); - -bool test_sn_nsdl_set_retransmission_parameters(); - -bool test_sn_nsdl_set_retransmission_buffer(); - -bool test_sn_nsdl_set_block_size(); - -bool test_sn_nsdl_set_duplicate_buffer_size(); - -bool test_sn_nsdl_set_context(); - -bool test_sn_nsdl_get_context(); - -#ifdef __cplusplus -} -#endif - -#endif // TEST_SN_NSDL_H - diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/stubs/ns_list_stub.c b/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/stubs/ns_list_stub.c deleted file mode 100644 index a48d3a5371..0000000000 --- a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/stubs/ns_list_stub.c +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright (c) 2015 ARM Limited. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 - * Licensed under the Apache License, Version 2.0 (the License); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#define NS_LIST_FN extern -#include "ns_list.h" - diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/stubs/randLIB_stub.cpp b/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/stubs/randLIB_stub.cpp deleted file mode 100644 index a46dd0706d..0000000000 --- a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/stubs/randLIB_stub.cpp +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (c) 2016 ARM Limited. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 - * Licensed under the Apache License, Version 2.0 (the License); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "randLIB_stub.h" - - -uint8_t randLIB_stub::uint8_value; -uint16_t randLIB_stub::uint16_value; -uint32_t randLIB_stub::uint32_value; -uint64_t randLIB_stub::uint64_value; -void* randLIB_stub::void_value; - -extern "C"{ - -void randLIB_seed_random(void){} - -void randLIB_add_seed(uint64_t seed){} - -uint8_t randLIB_get_8bit(void) -{ - return randLIB_stub::uint8_value; -} - -uint16_t randLIB_get_16bit(void) -{ - return randLIB_stub::uint16_value; -} - -uint32_t randLIB_get_32bit(void) -{ - return randLIB_stub::uint32_value; -} - -uint64_t randLIB_get_64bit(void) -{ - return randLIB_stub::uint64_value; -} - -void *randLIB_get_n_bytes_random(void *data_ptr, uint8_t count) -{ - return randLIB_stub::void_value; -} - -uint16_t randLIB_get_random_in_range(uint16_t min, uint16_t max) -{ - return randLIB_stub::uint16_value; -} - -uint32_t randLIB_randomise_base(uint32_t base, uint16_t min_factor, uint16_t max_factor) -{ - return randLIB_stub::uint32_value; -} - -} - diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/stubs/randLIB_stub.h b/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/stubs/randLIB_stub.h deleted file mode 100644 index 5cfe2c61e4..0000000000 --- a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/stubs/randLIB_stub.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2016 ARM Limited. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 - * Licensed under the Apache License, Version 2.0 (the License); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef M2M_RANDLIB_STUB_H -#define M2M_RANDLIB_STUB_H - -#include - -//some internal test related stuff -namespace randLIB_stub -{ - extern uint8_t uint8_value; - extern uint16_t uint16_value; - extern uint32_t uint32_value; - extern uint64_t uint64_value; - extern void* void_value; -} - -#endif // M2M_RANDLIB_STUB_H \ No newline at end of file diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/stubs/sn_coap_builder_stub.c b/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/stubs/sn_coap_builder_stub.c deleted file mode 100644 index b240ae2a46..0000000000 --- a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/stubs/sn_coap_builder_stub.c +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (c) 2011-2015 ARM Limited. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 - * Licensed under the Apache License, Version 2.0 (the License); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * \file sn_coap_builder.c - * - * \brief CoAP Message builder - * - * Functionality: Builds CoAP message - * - */ - -/* * * * * * * * * * * * * * */ -/* * * * INCLUDE FILES * * * */ -/* * * * * * * * * * * * * * */ - -#include "ns_types.h" -#include "sn_coap_header.h" -#include "sn_coap_builder_stub.h" - - -sn_coap_builder_stub_def sn_coap_builder_stub; - -sn_coap_hdr_s *sn_coap_build_response(struct coap_s *handle, sn_coap_hdr_s *coap_packet_ptr, uint8_t msg_code) -{ - return sn_coap_builder_stub.expectedHeader; -} - -int16_t sn_coap_builder_2(uint8_t *dst_packet_data_ptr, sn_coap_hdr_s *src_coap_msg_ptr, uint16_t blockwise_size) -{ - return sn_coap_builder_stub.expectedInt16; -} - -int16_t sn_coap_builder(uint8_t *dst_packet_data_ptr, sn_coap_hdr_s *src_coap_msg_ptr) -{ - return sn_coap_builder_stub.expectedInt16; -} - -uint16_t sn_coap_builder_calc_needed_packet_data_size_2(sn_coap_hdr_s *src_coap_msg_ptr, uint16_t blockwise_size) -{ - return sn_coap_builder_stub.expectedUint16; -} - -uint16_t sn_coap_builder_calc_needed_packet_data_size(sn_coap_hdr_s *src_coap_msg_ptr) -{ - return sn_coap_builder_stub.expectedUint16; -} - -int16_t sn_coap_builder_options_build_add_zero_length_option(uint8_t **dst_packet_data_pptr, uint8_t option_length, uint8_t option_exist, sn_coap_option_numbers_e option_number) -{ - return sn_coap_builder_stub.expectedInt16; -} diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/stubs/sn_coap_builder_stub.h b/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/stubs/sn_coap_builder_stub.h deleted file mode 100644 index 55b1c35d89..0000000000 --- a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/stubs/sn_coap_builder_stub.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2015 ARM Limited. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 - * Licensed under the Apache License, Version 2.0 (the License); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef __SN_COAP_BUILDER_STUB_H__ -#define __SN_COAP_BUILDER_STUB_H__ - -typedef struct { - int16_t expectedInt16; - uint16_t expectedUint16; - sn_coap_hdr_s *expectedHeader; -} sn_coap_builder_stub_def; - -extern sn_coap_builder_stub_def sn_coap_builder_stub; - -#endif //__SN_COAP_BUILDER_STUB_H__ diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/stubs/sn_coap_header_check_stub.c b/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/stubs/sn_coap_header_check_stub.c deleted file mode 100644 index 9229bebcda..0000000000 --- a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/stubs/sn_coap_header_check_stub.c +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2015 ARM Limited. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 - * Licensed under the Apache License, Version 2.0 (the License); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * \file sn_coap_header_check.c - * - * \brief CoAP Header validity checker - * - * Functionality: Checks validity of CoAP Header - * - */ - -#include "ns_types.h" -#include "sn_coap_header.h" - -#include "sn_coap_header_check_stub.h" - -sn_coap_header_check_stub_def sn_coap_header_check_stub; - -int8_t sn_coap_header_validity_check(sn_coap_hdr_s *src_coap_msg_ptr, coap_version_e coap_version) -{ - return sn_coap_header_check_stub.expectedInt8; -} diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/stubs/sn_coap_header_check_stub.h b/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/stubs/sn_coap_header_check_stub.h deleted file mode 100644 index 268c42b298..0000000000 --- a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/stubs/sn_coap_header_check_stub.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2015 ARM Limited. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 - * Licensed under the Apache License, Version 2.0 (the License); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef __SN_COAP_HEADER_CHECK_STUB_H__ -#define __SN_COAP_HEADER_CHECK_STUB_H__ - -#include - -typedef struct { - int8_t expectedInt8; -} sn_coap_header_check_stub_def; - -extern sn_coap_header_check_stub_def sn_coap_header_check_stub; - -#endif //__SN_COAP_HEADER_CHECK_STUB_H__ diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/stubs/sn_coap_parser_stub.c b/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/stubs/sn_coap_parser_stub.c deleted file mode 100644 index 2943d32307..0000000000 --- a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/stubs/sn_coap_parser_stub.c +++ /dev/null @@ -1,135 +0,0 @@ -/* - * Copyright (c) 2015 ARM Limited. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 - * Licensed under the Apache License, Version 2.0 (the License); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - *\file sn_coap_parser.c - * - * \brief CoAP Header parser - * - * Functionality: Parses CoAP Header - * - */ - -#include "ns_types.h" -#include "sn_nsdl.h" -#include "sn_coap_header.h" -#include "sn_coap_protocol_internal.h" -#include "sn_coap_parser_stub.h" - -sn_coap_parser_def sn_coap_parser_stub; - -sn_coap_hdr_s *sn_coap_parser(struct coap_s *handle, uint16_t packet_data_len, uint8_t *packet_data_ptr, coap_version_e *coap_version_ptr) -{ - return sn_coap_parser_stub.expectedHeader; -} - -void sn_coap_parser_release_allocated_coap_msg_mem(struct coap_s *handle, sn_coap_hdr_s *freed_coap_msg_ptr) -{ - if (freed_coap_msg_ptr != NULL) { - if (freed_coap_msg_ptr->uri_path_ptr != NULL) { - free(freed_coap_msg_ptr->uri_path_ptr); - freed_coap_msg_ptr->uri_path_ptr = NULL; - } - - if (freed_coap_msg_ptr->token_ptr != NULL) { - free(freed_coap_msg_ptr->token_ptr); - } - - if (freed_coap_msg_ptr->options_list_ptr != NULL) { - if (freed_coap_msg_ptr->options_list_ptr->proxy_uri_ptr != NULL) { - free(freed_coap_msg_ptr->options_list_ptr->proxy_uri_ptr); - } - - if (freed_coap_msg_ptr->options_list_ptr->etag_ptr != NULL) { - free(freed_coap_msg_ptr->options_list_ptr->etag_ptr); - } - - if (freed_coap_msg_ptr->options_list_ptr->uri_host_ptr != NULL) { - free(freed_coap_msg_ptr->options_list_ptr->uri_host_ptr); - } - - if (freed_coap_msg_ptr->options_list_ptr->location_path_ptr != NULL) { - free(freed_coap_msg_ptr->options_list_ptr->location_path_ptr); - } - - if (freed_coap_msg_ptr->options_list_ptr->location_query_ptr != NULL) { - free(freed_coap_msg_ptr->options_list_ptr->location_query_ptr); - } - - if (freed_coap_msg_ptr->options_list_ptr->uri_query_ptr != NULL) { - free(freed_coap_msg_ptr->options_list_ptr->uri_query_ptr); - } - - free(freed_coap_msg_ptr->options_list_ptr); - } - - free(freed_coap_msg_ptr); - freed_coap_msg_ptr = NULL; - } -} - -sn_coap_hdr_s *sn_coap_parser_init_message(sn_coap_hdr_s *coap_msg_ptr) -{ - /* * * * Check given pointer * * * */ - if (coap_msg_ptr == NULL) { - return NULL; - } - - /* XXX not technically legal to memset pointers to 0 */ - memset(coap_msg_ptr, 0x00, sizeof(sn_coap_hdr_s)); - - return coap_msg_ptr; -} - -sn_coap_hdr_s *sn_coap_parser_alloc_message(struct coap_s *handle) -{ - sn_coap_hdr_s *returned_coap_msg_ptr; - - /* * * * Check given pointer * * * */ - if (handle == NULL) { - return NULL; - } - - /* * * * Allocate memory for returned CoAP message and initialize allocated memory with with default values * * * */ - returned_coap_msg_ptr = handle->sn_coap_protocol_malloc(sizeof(sn_coap_hdr_s)); - - return sn_coap_parser_init_message(returned_coap_msg_ptr); -} - -sn_coap_options_list_s *sn_coap_parser_alloc_options(struct coap_s *handle, sn_coap_hdr_s *coap_msg_ptr) -{ - /* * * * Check given pointers * * * */ - if (handle == NULL || coap_msg_ptr == NULL) { - return NULL; - } - - /* * * * If the message already has options, return them * * * */ - if (coap_msg_ptr->options_list_ptr) { - return coap_msg_ptr->options_list_ptr; - } - - /* * * * Allocate memory for options and initialize allocated memory with with default values * * * */ - coap_msg_ptr->options_list_ptr = handle->sn_coap_protocol_malloc(sizeof(sn_coap_options_list_s)); - - if (coap_msg_ptr->options_list_ptr == NULL) { - return NULL; - } - - /* XXX not technically legal to memset pointers to 0 */ - memset(coap_msg_ptr->options_list_ptr, 0x00, sizeof(sn_coap_options_list_s)); - - return coap_msg_ptr->options_list_ptr; -} diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/stubs/sn_coap_parser_stub.h b/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/stubs/sn_coap_parser_stub.h deleted file mode 100644 index c24339c0e6..0000000000 --- a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/stubs/sn_coap_parser_stub.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 2015 ARM Limited. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 - * Licensed under the Apache License, Version 2.0 (the License); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef __SN_COAP_PARSER_STUB_H__ -#define __SN_COAP_PARSER_STUB_H__ - -typedef struct { - sn_coap_hdr_s *expectedHeader; -} sn_coap_parser_def; - -extern sn_coap_parser_def sn_coap_parser_stub; - -#endif //__SN_COAP_PARSER_STUB_H__ diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/stubs/sn_coap_protocol_stub.c b/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/stubs/sn_coap_protocol_stub.c deleted file mode 100644 index 70c5b5b446..0000000000 --- a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/stubs/sn_coap_protocol_stub.c +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright (c) 2015 ARM Limited. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 - * Licensed under the Apache License, Version 2.0 (the License); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include -#include /* For libary malloc() */ -#include /* For memset() and memcpy() */ -#ifdef __linux__ -#include -#endif - -#include "ns_types.h" -#include "sn_nsdl.h" -#include "sn_coap_protocol.h" -#include "sn_coap_header_internal.h" -#include "sn_coap_protocol_internal.h" -#include "sn_coap_protocol_stub.h" - -uint16_t sn_coap_block_data_size = 0; - -uint8_t sn_coap_resending_queue_msgs = 0; -uint8_t sn_coap_resending_queue_bytes = 0; -uint8_t sn_coap_resending_count = 0; -uint8_t sn_coap_resending_intervall = 0; - -uint8_t sn_coap_duplication_buffer_size = 0; - -sn_coap_protocol_stub_def sn_coap_protocol_stub; - -int8_t sn_coap_protocol_destroy(struct coap_s *handle) -{ - return sn_coap_protocol_stub.expectedInt8; -} - -struct coap_s *sn_coap_protocol_init(void *(*used_malloc_func_ptr)(uint16_t), void (*used_free_func_ptr)(void *), - uint8_t (*used_tx_callback_ptr)(uint8_t *, uint16_t, sn_nsdl_addr_s *, void *), - int8_t (*used_rx_callback_ptr)(sn_coap_hdr_s *, sn_nsdl_addr_s *, void *param)) -{ - if( sn_coap_protocol_stub.expectedCoap ){ - sn_coap_protocol_stub.expectedCoap->sn_coap_protocol_free = used_free_func_ptr; - sn_coap_protocol_stub.expectedCoap->sn_coap_protocol_malloc = used_malloc_func_ptr; - sn_coap_protocol_stub.expectedCoap->sn_coap_rx_callback = used_rx_callback_ptr; - sn_coap_protocol_stub.expectedCoap->sn_coap_tx_callback = used_tx_callback_ptr; - //sn_coap_protocol_stub.expectedCoap->linked_list_resent_msgs = - } - return sn_coap_protocol_stub.expectedCoap; -} - -int8_t sn_coap_protocol_set_block_size(struct coap_s *handle, uint16_t block_size) -{ - return sn_coap_protocol_stub.expectedInt8; -} - -int8_t sn_coap_protocol_set_duplicate_buffer_size(struct coap_s *handle, uint8_t message_count) -{ - return sn_coap_protocol_stub.expectedInt8; -} - -int8_t sn_coap_protocol_set_retransmission_parameters(struct coap_s *handle, uint8_t resending_count, uint8_t resending_intervall) -{ - return sn_coap_protocol_stub.expectedInt8; -} - -int8_t sn_coap_protocol_set_retransmission_buffer(struct coap_s *handle, uint8_t buffer_size_messages, uint16_t buffer_size_bytes) -{ - return sn_coap_protocol_stub.expectedInt8; -} - -void sn_coap_protocol_clear_retransmission_buffer(struct coap_s *handle) -{ -} - -int8_t prepare_blockwise_message(struct coap_s *handle, sn_coap_hdr_s *src_coap_msg_ptr) -{ - return sn_coap_protocol_stub.expectedInt8; -} - -int16_t sn_coap_protocol_build(struct coap_s *handle, sn_nsdl_addr_s *dst_addr_ptr, - uint8_t *dst_packet_data_ptr, sn_coap_hdr_s *src_coap_msg_ptr, void *param) -{ - return sn_coap_protocol_stub.expectedInt16; -} - -sn_coap_hdr_s *sn_coap_protocol_parse(struct coap_s *handle, sn_nsdl_addr_s *src_addr_ptr, uint16_t packet_data_len, uint8_t *packet_data_ptr, void *param) -{ - return sn_coap_protocol_stub.expectedHeader; -} - -int8_t sn_coap_protocol_exec(struct coap_s *handle, uint32_t current_time) -{ - return sn_coap_protocol_stub.expectedInt8; -} - -coap_send_msg_s *sn_coap_protocol_allocate_mem_for_msg(struct coap_s *handle, sn_nsdl_addr_s *dst_addr_ptr, uint16_t packet_data_len) -{ - return sn_coap_protocol_stub.expectedSendMsg; -} - -void sn_coap_protocol_block_remove(struct coap_s *handle, sn_nsdl_addr_s *source_address, uint16_t payload_length, void *payload) -{ -} - - diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/stubs/sn_coap_protocol_stub.h b/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/stubs/sn_coap_protocol_stub.h deleted file mode 100644 index b61ac411ea..0000000000 --- a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/stubs/sn_coap_protocol_stub.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2015 ARM Limited. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 - * Licensed under the Apache License, Version 2.0 (the License); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef __SN_COAP_PROTOCOL_STUB_H__ -#define __SN_COAP_PROTOCOL_STUB_H__ - -#include "sn_coap_header_internal.h" -#include "sn_coap_protocol_internal.h" -#include "sn_coap_header.h" - -typedef struct { - int8_t expectedInt8; - int16_t expectedInt16; - struct coap_s *expectedCoap; - sn_coap_hdr_s *expectedHeader; - coap_send_msg_s *expectedSendMsg; -} sn_coap_protocol_stub_def; - -extern sn_coap_protocol_stub_def sn_coap_protocol_stub; - -#endif //__SN_COAP_PROTOCOL_STUB_H__ diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/stubs/sn_grs_stub.c b/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/stubs/sn_grs_stub.c deleted file mode 100755 index ea05e9d67e..0000000000 --- a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/stubs/sn_grs_stub.c +++ /dev/null @@ -1,180 +0,0 @@ -/* - * Copyright (c) 2015 ARM Limited. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 - * Licensed under the Apache License, Version 2.0 (the License); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * - * \file sn_grs.c - * - * \brief General resource server. - * - */ -#include -#include - -#include "ns_list.h" -#include "ns_types.h" -#include "sn_nsdl.h" -#include "sn_coap_header.h" -#include "sn_coap_protocol.h" -#include "sn_nsdl_lib.h" -#include "sn_grs.h" - -#include "sn_grs_stub.h" - -sn_grs_stub_def sn_grs_stub; - -/* Extern function prototypes */ -extern int8_t sn_nsdl_build_registration_body(struct nsdl_s *handle, sn_coap_hdr_s *message_ptr, uint8_t updating_registeration); - - -extern int8_t sn_grs_destroy(struct grs_s *handle) -{ - if( handle ){ - free(handle); - } - return sn_grs_stub.expectedInt8; -} - -extern struct grs_s *sn_grs_init(uint8_t (*sn_grs_tx_callback_ptr)(struct nsdl_s *, sn_nsdl_capab_e , uint8_t *, uint16_t, - sn_nsdl_addr_s *), int8_t (*sn_grs_rx_callback_ptr)(struct nsdl_s *, sn_coap_hdr_s *, sn_nsdl_addr_s *), - void *(*sn_grs_alloc)(uint16_t), void (*sn_grs_free)(void *)) -{ - if( sn_grs_stub.retNull ){ - return NULL; - } - return sn_grs_stub.expectedGrs; -} - - - -extern sn_grs_resource_list_s *sn_grs_list_resource(struct grs_s *handle, uint16_t pathlen, uint8_t *path) -{ - if( sn_grs_stub.retNull ){ - return NULL; - } - return sn_grs_stub.expectedList; -} - - -extern void sn_grs_free_resource_list(struct grs_s *handle, sn_grs_resource_list_s *list) -{ - if( list ){ - free(list); - list = NULL; - } -} - - -extern const sn_nsdl_resource_info_s *sn_grs_get_first_resource(struct grs_s *handle) -{ - if( sn_grs_stub.retNull ){ - return NULL; - } - if( sn_grs_stub.infoRetCounter == -1 && sn_grs_stub.info2ndRetCounter > 0 ){ - sn_grs_stub.info2ndRetCounter--; - return sn_grs_stub.expectedInfo; - } - if( sn_grs_stub.infoRetCounter > 0){ - sn_grs_stub.infoRetCounter--; - return sn_grs_stub.expectedInfo; - } - sn_grs_stub.infoRetCounter = -1; - return NULL; -} - - -extern const sn_nsdl_resource_info_s *sn_grs_get_next_resource(struct grs_s *handle, const sn_nsdl_resource_info_s *sn_grs_current_resource) -{ - if( sn_grs_stub.retNull ){ - return NULL; - } - if( sn_grs_stub.infoRetCounter == -1 && sn_grs_stub.info2ndRetCounter > 0 ){ - sn_grs_stub.info2ndRetCounter--; - return sn_grs_stub.expectedInfo; - } - if( sn_grs_stub.infoRetCounter > 0){ - sn_grs_stub.infoRetCounter--; - return sn_grs_stub.expectedInfo; - } - sn_grs_stub.infoRetCounter = -1; - return NULL; -} - - -extern int8_t sn_grs_delete_resource(struct grs_s *handle, uint16_t pathlen, uint8_t *path) -{ - return sn_grs_stub.expectedInt8; -} - - -extern int8_t sn_grs_update_resource(struct grs_s *handle, sn_nsdl_resource_info_s *res) -{ - return sn_grs_stub.expectedInt8; -} - - -extern int8_t sn_grs_create_resource(struct grs_s *handle, sn_nsdl_resource_info_s *res) -{ - if( sn_grs_stub.int8SuccessCounter > 0 ){ - sn_grs_stub.int8SuccessCounter--; - return SN_NSDL_SUCCESS; - } - return sn_grs_stub.expectedInt8; -} - -int8_t sn_grs_put_resource(struct grs_s *handle, sn_nsdl_resource_info_s *res) -{ - if( sn_grs_stub.int8SuccessCounter > 0 ){ - sn_grs_stub.int8SuccessCounter--; - return SN_NSDL_SUCCESS; - } - return sn_grs_stub.expectedInt8; -} - -extern int8_t sn_grs_process_coap(struct nsdl_s *nsdl_handle, sn_coap_hdr_s *coap_packet_ptr, sn_nsdl_addr_s *src_addr_ptr) -{ - return sn_grs_stub.expectedInt8; -} - -extern int8_t sn_grs_send_coap_message(struct nsdl_s *handle, sn_nsdl_addr_s *address_ptr, sn_coap_hdr_s *coap_hdr_ptr) -{ - return sn_grs_stub.expectedInt8; -} - -sn_nsdl_resource_info_s *sn_grs_search_resource(struct grs_s *handle, uint16_t pathlen, uint8_t *path, uint8_t search_method) -{ - if(sn_grs_stub.useMockedPath){ - memcpy(path, &sn_grs_stub.mockedPath, sn_grs_stub.mockedPathLen); - } - if( sn_grs_stub.retNull ){ - return NULL; - } - if( sn_grs_stub.infoRetCounter == -1 && sn_grs_stub.info2ndRetCounter > 0 ){ - sn_grs_stub.info2ndRetCounter--; - return sn_grs_stub.expectedInfo; - } - if( sn_grs_stub.infoRetCounter > 0){ - sn_grs_stub.infoRetCounter--; - return sn_grs_stub.expectedInfo; - } - sn_grs_stub.infoRetCounter = -1; - return NULL; -} - -void sn_grs_mark_resources_as_registered(struct nsdl_s *handle) -{ -} - diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/stubs/sn_grs_stub.h b/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/stubs/sn_grs_stub.h deleted file mode 100644 index bf4774560c..0000000000 --- a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/stubs/sn_grs_stub.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2015 ARM Limited. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 - * Licensed under the Apache License, Version 2.0 (the License); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef __SN_GRS_STUB_H__ -#define __SN_GRS_STUB_H__ - -#include "sn_nsdl_lib.h" -#include "sn_grs.h" - -typedef struct { - bool retNull; - int8_t infoRetCounter; - int8_t info2ndRetCounter; - int8_t expectedInt8; - int8_t int8SuccessCounter; - struct grs_s *expectedGrs; - sn_nsdl_resource_info_s *expectedInfo; - sn_grs_resource_list_s *expectedList; - - bool useMockedPath; - uint8_t mockedPath[8]; - uint8_t mockedPathLen; -}sn_grs_stub_def; - -extern sn_grs_stub_def sn_grs_stub; - -#endif //__SN_GRS_STUB_H__ diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/stubs/sn_nsdl_stub.c b/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/stubs/sn_nsdl_stub.c deleted file mode 100755 index bf6940103b..0000000000 --- a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/stubs/sn_nsdl_stub.c +++ /dev/null @@ -1,229 +0,0 @@ -/* - * Copyright (c) 2015 ARM Limited. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 - * Licensed under the Apache License, Version 2.0 (the License); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -#include "ns_types.h" -#include "sn_nsdl.h" -#include "sn_coap_header.h" -#include "sn_coap_protocol.h" -#include "sn_nsdl_lib.h" -#include "sn_grs.h" - -/* Defines */ -#define RESOURCE_DIR_LEN 2 -#define EP_NAME_PARAMETERS_LEN 3 -#define ET_PARAMETER_LEN 3 -#define LT_PARAMETER_LEN 3 -#define DOMAIN_PARAMETER_LEN 2 -#define RT_PARAMETER_LEN 3 -#define IF_PARAMETER_LEN 3 -#define OBS_PARAMETER_LEN 3 -#define AOBS_PARAMETER_LEN 8 -#define COAP_CON_PARAMETER_LEN 3 -#define BS_EP_PARAMETER_LEN 3 -#define BS_QUEUE_MODE_PARAMATER_LEN 2 - -#define SN_NSDL_EP_REGISTER_MESSAGE 1 -#define SN_NSDL_EP_UPDATE_MESSAGE 2 - -#define SN_NSDL_MSG_UNDEFINED 0 -#define SN_NSDL_MSG_REGISTER 1 -#define SN_NSDL_MSG_UNREGISTER 2 -#define SN_NSDL_MSG_UPDATE 3 - -#include "sn_nsdl_stub.h" - -sn_nsdl_stub_def sn_nsdl_stub; - -int8_t sn_nsdl_destroy(struct nsdl_s *handle) -{ - return sn_nsdl_stub.expectedInt8; -} - -struct nsdl_s *sn_nsdl_init(uint8_t (*sn_nsdl_tx_cb)(struct nsdl_s *, sn_nsdl_capab_e , uint8_t *, uint16_t, sn_nsdl_addr_s *), - uint8_t (*sn_nsdl_rx_cb)(struct nsdl_s *, sn_coap_hdr_s *, sn_nsdl_addr_s *), - void *(*sn_nsdl_alloc)(uint16_t), void (*sn_nsdl_free)(void *)) -{ - return NULL; -} - -uint16_t sn_nsdl_register_endpoint(struct nsdl_s *handle, sn_nsdl_ep_parameters_s *endpoint_info_ptr) -{ - return sn_nsdl_stub.expectedUint16; -} - -uint16_t sn_nsdl_unregister_endpoint(struct nsdl_s *handle) -{ - return sn_nsdl_stub.expectedUint16; -} - -uint16_t sn_nsdl_update_registration(struct nsdl_s *handle, uint8_t *lt_ptr, uint8_t lt_len) -{ - return sn_nsdl_stub.expectedUint16; -} - -int8_t sn_nsdl_set_endpoint_location(struct nsdl_s *handle, uint8_t *loc_ptr, uint8_t loc_len) -{ - return sn_nsdl_stub.expectedInt8; -} - -void sn_nsdl_nsp_lost(struct nsdl_s *handle) -{ -} - -int8_t sn_nsdl_is_ep_registered(struct nsdl_s *handle) -{ - return sn_nsdl_stub.expectedInt8; -} - -uint16_t sn_nsdl_send_observation_notification_with_uri_path(struct nsdl_s *handle, uint8_t *token_ptr, uint8_t token_len, - uint8_t *payload_ptr, uint16_t payload_len, - sn_coap_observe_e observe, - sn_coap_msg_type_e message_type, - uint8_t content_type, - uint8_t *uri_path_ptr, - uint16_t uri_path_len) -{ - return sn_nsdl_stub.expectedUint16; -} - -uint16_t sn_nsdl_send_observation_notification(struct nsdl_s *handle, uint8_t *token_ptr, uint8_t token_len, - uint8_t *payload_ptr, uint16_t payload_len, - sn_coap_observe_e observe, - sn_coap_msg_type_e message_type, - sn_coap_content_format_e content_format) -{ - return sn_nsdl_stub.expectedUint16; -} - -/* * * * * * * * * * */ -/* ~ OMA functions ~ */ -/* * * * * * * * * * */ - -uint16_t sn_nsdl_oma_bootstrap(struct nsdl_s *handle, sn_nsdl_addr_s *bootstrap_address_ptr, sn_nsdl_ep_parameters_s *endpoint_info_ptr, sn_nsdl_bs_ep_info_t *bootstrap_endpoint_info_ptr) -{ - return sn_nsdl_stub.expectedUint16; -} - -omalw_certificate_list_t *sn_nsdl_get_certificates(struct nsdl_s *handle) -{ - return NULL; -} - -int8_t sn_nsdl_update_certificates(struct nsdl_s *handle, omalw_certificate_list_t *certificate_ptr, uint8_t certificate_chain) -{ - return sn_nsdl_stub.expectedInt8; -} - -int8_t sn_nsdl_create_oma_device_object(struct nsdl_s *handle, sn_nsdl_oma_device_t *device_object_ptr) -{ - return sn_nsdl_stub.expectedInt8; -} - -char *sn_nsdl_get_version(void) -{ - return NULL; -} - - -int8_t sn_nsdl_process_coap(struct nsdl_s *handle, uint8_t *packet_ptr, uint16_t packet_len, sn_nsdl_addr_s *src_ptr) -{ - return sn_nsdl_stub.expectedInt8; -} - -int8_t sn_nsdl_exec(struct nsdl_s *handle, uint32_t time) -{ - return sn_nsdl_stub.expectedInt8; -} - -sn_nsdl_resource_info_s *sn_nsdl_get_resource(struct nsdl_s *handle, uint16_t pathlen, uint8_t *path_ptr) -{ - return NULL; -} - -int8_t sn_nsdl_build_registration_body(struct nsdl_s *handle, sn_coap_hdr_s *message_ptr, uint8_t updating_registeration) -{ - if( sn_nsdl_stub.allocatePayloadPtr && message_ptr && handle){ - message_ptr->payload_ptr = handle->sn_nsdl_alloc(2); - message_ptr->payload_len = 2; - } - return sn_nsdl_stub.expectedInt8; -} - -int8_t set_NSP_address(struct nsdl_s *handle, uint8_t *NSP_address, uint16_t port, sn_nsdl_addr_type_e address_type) -{ - return sn_nsdl_stub.expectedInt8; -} - -int8_t sn_nsdl_process_oma_tlv(struct nsdl_s *handle, uint8_t *data_ptr, uint16_t data_len) -{ - return sn_nsdl_stub.expectedInt8; -} - -/* Wrapper */ -sn_grs_resource_list_s *sn_nsdl_list_resource(struct nsdl_s *handle, uint16_t pathlen, uint8_t *path) -{ - return NULL; -} - -void sn_nsdl_free_resource_list(struct nsdl_s *handle, sn_grs_resource_list_s *list) -{ -} - -extern int8_t sn_nsdl_update_resource(struct nsdl_s *handle, sn_nsdl_resource_info_s *res) -{ - return sn_nsdl_stub.expectedInt8; -} - -extern int8_t sn_nsdl_send_coap_message(struct nsdl_s *handle, sn_nsdl_addr_s *address_ptr, sn_coap_hdr_s *coap_hdr_ptr) -{ - return sn_nsdl_stub.expectedInt8; -} - -extern int8_t sn_nsdl_create_resource(struct nsdl_s *handle, sn_nsdl_resource_info_s *res) -{ - return sn_nsdl_stub.expectedInt8; -} - -extern int8_t sn_nsdl_put_resource(struct nsdl_s *handle, sn_nsdl_resource_info_s *res) -{ - return sn_nsdl_stub.expectedInt8; -} - -extern int8_t sn_nsdl_delete_resource(struct nsdl_s *handle, uint16_t pathlen, uint8_t *path) -{ - return sn_nsdl_stub.expectedInt8; -} - -extern const sn_nsdl_resource_info_s *sn_nsdl_get_first_resource(struct nsdl_s *handle) -{ - return NULL; -} - -extern const sn_nsdl_resource_info_s *sn_nsdl_get_next_resource(struct nsdl_s *handle, const sn_nsdl_resource_info_s *resource) -{ - return NULL; -} - -extern sn_coap_hdr_s *sn_nsdl_build_response(struct nsdl_s *handle, sn_coap_hdr_s *coap_packet_ptr, uint8_t msg_code) -{ - return NULL; -} - -extern void sn_nsdl_release_allocated_coap_msg_mem(struct nsdl_s *handle, sn_coap_hdr_s *freed_coap_msg_ptr) -{ -} diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/stubs/sn_nsdl_stub.h b/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/stubs/sn_nsdl_stub.h deleted file mode 100644 index 33bedeee21..0000000000 --- a/features/FEATURE_COMMON_PAL/mbed-client-c/test/nsdl-c/unittest/stubs/sn_nsdl_stub.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2015 ARM Limited. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 - * Licensed under the Apache License, Version 2.0 (the License); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef __SN_NSDL_STUB_H__ -#define __SN_NSDL_STUB_H__ - -typedef struct { - int8_t expectedInt8; - uint16_t expectedUint16; - bool allocatePayloadPtr; -}sn_nsdl_stub_def; - -extern sn_nsdl_stub_def sn_nsdl_stub; - -#endif //__SN_NSDL_STUB_H__ diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/unittest/test_libCoap/Test.c b/features/FEATURE_COMMON_PAL/mbed-client-c/unittest/test_libCoap/Test.c deleted file mode 100644 index 886c510738..0000000000 --- a/features/FEATURE_COMMON_PAL/mbed-client-c/unittest/test_libCoap/Test.c +++ /dev/null @@ -1,621 +0,0 @@ -/* - * Copyright (c) 2015 ARM Limited. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 - * Licensed under the Apache License, Version 2.0 (the License); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * \file \test_libCoap\Test.c - * - * \brief Unit tests for libCoap - */ -#include "ns_types.h" -#include "sn_nsdl.h" -#include "sn_coap_header.h" -#include "sn_coap_protocol.h" -#include "sn_coap_header_internal.h" - -#include "unity.h" -#include "string.h" -#include "stdlib.h" - -static uint8_t *message_ptr = 0; -static uint16_t message_len = 0; -static sn_coap_hdr_s coap_header; -sn_nsdl_addr_s coap_address; -static uint8_t address[16] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}; - -/* CoAP parameters to be used */ -static uint8_t option_short[3] = {0x61, 0x62, 0x63}; -static uint32_t option_short_value = 0x616263; -static uint8_t option_path[5] = {0x62, 0x63, 0x2f, 0x61, 0x62}; -static uint8_t option_30[30]; -static uint8_t option_300[300]; -static uint8_t option_600[600]; -static uint8_t option_800[800]; - -/* Resultat sju rätt är: */ -static uint8_t coap_message_no_options[4] = {0x60, 0x44, 0x12, 0x34}; -static uint8_t coap_message_token_payload[11] = {0x63, 0x44, 0x12, 0x34, 0x61, 0x62, 0x63, 0xff, 0x61, 0x62, 0x63}; -static uint8_t coap_message_wrong_version[4] = {0xe0, 0x44, 0x12, 0x34}; -static uint8_t coap_message_malformed[4] = {0x60, 0xae, 0x43, 0x11}; -static uint8_t coap_message_option_short[9] = {0x60, 0x44, 0x12, 0x34, 0xd3, 0x16, 0x61, 0x62, 0x63}; // option number 35 -static uint8_t coap_message_option_30[7] = {0x60, 0x44, 0x12, 0x34, 0xdd, 0x16, 0x11}; // option number 35, length 30 -static uint8_t coap_message_option_300[8] = {0x60, 0x44, 0x12, 0x34, 0xde, 0x16, 0x00, 0x1f}; // option number 35, length 300 -static uint8_t coap_message_option_600[8] = {0x60, 0x44, 0x12, 0x34, 0xde, 0x16, 0x01, 0x4b}; // option number 35, length 600 -static uint8_t coap_message_option_800[8] = {0x60, 0x44, 0x12, 0x34, 0xde, 0x16, 0x02, 0x13}; // option number 35, length 800 -/* Options = Token - 3 bytes, max age - 14 - 3 bytes, Uri path - 11 - 2 x 2 bytes, Uri host - 3 - 3 bytes */ -static uint8_t coap_message_multiple_options[21] = {0x63, 0x44, 0x12, 0x34, 0x61, 0x62, 0x63, 0x33, 0x61, 0x62, 0x63, 0x82, 0x62, 0x63, 0x02, 0x61, 0x62, 0x33, 0x61, 0x62, 0x63}; - -static uint8_t coap_message_empty_con[4] = {0x40, 0x00, 0x12, 0x34}; -static uint8_t coap_message_wrong_code_1[4] = {0x40, 0x24, 0x12, 0x34}; -static uint8_t coap_message_wrong_code_6[4] = {0x40, 0xc4, 0x12, 0x34}; -static uint8_t coap_message_wrong_code_7[4] = {0x40, 0xe4, 0x12, 0x34}; - - -void *own_alloc(uint16_t size); -void own_free(void *ptr); - -struct coap_s *handle; - -uint8_t tx_function(uint8_t *data_ptr, uint16_t data_len, sn_nsdl_addr_s *address_ptr, void *param); -int8_t rx_callback(sn_coap_hdr_s *coap_header_ptr, sn_nsdl_addr_s *address_ptr, void *param); - -/* non-test function declarations */ -void fill_with_random(uint8_t *ptr, uint16_t len); - -/* Unity test code starts */ -void setUp(void) -{ - //This is run before EACH TEST - -} - -void tearDown(void) -{ - -} - -void test_libcoap_init(void) -{ - handle = sn_coap_protocol_init(&own_alloc, &own_free, &tx_function, &rx_callback); - - TEST_ASSERT_NOT_NULL(handle); -} - - -/** - * \fn test_libcoap_builder_no_options(void) - * - * \brief Build CoAP message - ACK - Changed - * - */ -void test_libcoap_builder_no_options(void) -{ - memset(&coap_header, 0, sizeof(sn_coap_hdr_s)); - coap_header.msg_type = COAP_MSG_TYPE_ACKNOWLEDGEMENT; - coap_header.msg_code = COAP_MSG_CODE_RESPONSE_CHANGED; - coap_header.msg_id = 0x1234; - - coap_header.options_list_ptr = malloc(sizeof(sn_coap_options_list_s)); - memset(coap_header.options_list_ptr, 0, sizeof(sn_coap_options_list_s)); - - message_len = sn_coap_builder_calc_needed_packet_data_size(&coap_header); - message_ptr = malloc(message_len); - sn_coap_builder(message_ptr, &coap_header); - - TEST_ASSERT_EQUAL(sizeof(coap_message_no_options), message_len); - TEST_ASSERT_EQUAL_INT8_ARRAY(coap_message_no_options, message_ptr, sizeof(coap_message_no_options)); - - free(message_ptr); - message_ptr = 0; -} - -/** - * \fn test_libcoap_builder_token_and_payload(void) - * - * \brief Build CoAP message - ACK - changed - token - payload - * - */ -void test_libcoap_builder_token_and_payload(void) -{ - memset(&coap_header, 0, sizeof(sn_coap_hdr_s)); - coap_header.msg_type = COAP_MSG_TYPE_ACKNOWLEDGEMENT; - coap_header.msg_code = COAP_MSG_CODE_RESPONSE_CHANGED; - coap_header.msg_id = 0x1234; - coap_header.token_len = sizeof(option_short); - coap_header.token_ptr = option_short; - coap_header.payload_len = sizeof(option_short); - coap_header.payload_ptr = option_short; - - coap_header.options_list_ptr = malloc(sizeof(sn_coap_options_list_s)); - memset(coap_header.options_list_ptr, 0, sizeof(sn_coap_options_list_s)); - - message_len = sn_coap_builder_calc_needed_packet_data_size(&coap_header); - message_ptr = malloc(message_len); - sn_coap_builder(message_ptr, &coap_header); - - TEST_ASSERT_EQUAL(sizeof(coap_message_token_payload), message_len); - TEST_ASSERT_EQUAL_INT8_ARRAY(coap_message_token_payload, message_ptr, sizeof(coap_message_token_payload)); - - free(message_ptr); - message_ptr = 0; -} - -/** - * \fn test_libcoap_builder_short_option(void) - * - * \brief Build CoAP message - ACK - changed - short proxy URI option - * - */ -void test_libcoap_builder_short_option(void) -{ - coap_header.token_len = 0; - coap_header.token_ptr = 0; - coap_header.payload_len = 0; - coap_header.payload_ptr = 0; - - coap_header.options_list_ptr->proxy_uri_len = sizeof(option_short); - coap_header.options_list_ptr->proxy_uri_ptr = option_short; - - message_len = sn_coap_builder_calc_needed_packet_data_size(&coap_header); - message_ptr = malloc(message_len); - sn_coap_builder(message_ptr, &coap_header); - - TEST_ASSERT_EQUAL(sizeof(coap_message_option_short), message_len); - TEST_ASSERT_EQUAL_INT8_ARRAY(coap_message_option_short, message_ptr, sizeof(coap_message_option_short)); - - free(message_ptr); - message_ptr = 0; -} - -/** - * \fn test_libcoap_builder_option_30(void) - * - * \brief Build CoAP message - ACK - changed - proxy URI option, length 30 bytes - * - */ -void test_libcoap_builder_option_30(void) -{ - fill_with_random(option_30, sizeof(option_30)); - coap_header.options_list_ptr->proxy_uri_len = sizeof(option_30); - coap_header.options_list_ptr->proxy_uri_ptr = option_30; - - message_len = sn_coap_builder_calc_needed_packet_data_size(&coap_header); - message_ptr = malloc(message_len); - sn_coap_builder(message_ptr, &coap_header); - - TEST_ASSERT_EQUAL((sizeof(coap_message_option_30) + sizeof(option_30)), message_len); - TEST_ASSERT_EQUAL_INT8_ARRAY(coap_message_option_30, message_ptr, sizeof(coap_message_option_30)); - - free(message_ptr); - message_ptr = 0; - -} - -/** - * \fn test_libcoap_builder_option_300(void) - * - * \brief Build CoAP message - ACK - changed - proxy URI option, length 300 bytes - * - */ -void test_libcoap_builder_option_300(void) -{ - fill_with_random(option_300, sizeof(option_300)); - coap_header.options_list_ptr->proxy_uri_len = sizeof(option_300); - coap_header.options_list_ptr->proxy_uri_ptr = option_300; - - message_len = sn_coap_builder_calc_needed_packet_data_size(&coap_header); - message_ptr = malloc(message_len); - sn_coap_builder(message_ptr, &coap_header); - - TEST_ASSERT_EQUAL(sizeof(coap_message_option_300) + sizeof(option_300), message_len); - TEST_ASSERT_EQUAL_INT8_ARRAY(coap_message_option_300, message_ptr, sizeof(coap_message_option_300)); - - free(message_ptr); - message_ptr = 0; -} - -/** - * \fn test_libcoap_builder_option_600(void) - * - * \brief Build CoAP message - ACK - changed - proxy URI option, length 600 bytes - * - */ - -void test_libcoap_builder_option_600(void) -{ - fill_with_random(option_600, sizeof(option_600)); - coap_header.options_list_ptr->proxy_uri_len = sizeof(option_600); - coap_header.options_list_ptr->proxy_uri_ptr = option_600; - - message_len = sn_coap_builder_calc_needed_packet_data_size(&coap_header); - message_ptr = malloc(message_len); - sn_coap_builder(message_ptr, &coap_header); - - TEST_ASSERT_EQUAL(sizeof(coap_message_option_600) + sizeof(option_600), message_len); - TEST_ASSERT_EQUAL_INT8_ARRAY(coap_message_option_600, message_ptr, sizeof(coap_message_option_600)); - - free(message_ptr); - message_ptr = 0; -} - -/** - * \fn test_libcoap_builder_option_800(void) - * - * \brief Build CoAP message - ACK - changed - proxy URI option, length 800 bytes - * - */ -void test_libcoap_builder_option_800(void) -{ - fill_with_random(option_800, sizeof(option_800)); - coap_header.options_list_ptr->proxy_uri_len = sizeof(option_800); - coap_header.options_list_ptr->proxy_uri_ptr = option_800; - - message_len = sn_coap_builder_calc_needed_packet_data_size(&coap_header); - message_ptr = malloc(message_len); - sn_coap_builder(message_ptr, &coap_header); - - TEST_ASSERT_EQUAL(sizeof(coap_message_option_800) + sizeof(option_800), message_len); - TEST_ASSERT_EQUAL_INT8_ARRAY(coap_message_option_800, message_ptr, sizeof(coap_message_option_800)); - - free(message_ptr); - message_ptr = 0; -} - -/** - * \fn test_libcoap_builder_message_with_multiple_options(void) - * - * \brief Build CoAP message - ACK - changed - URI host - URI path - max age - token - * - */ -void test_libcoap_builder_message_with_multiple_options(void) -{ - coap_header.options_list_ptr->proxy_uri_len = 0; - coap_header.options_list_ptr->proxy_uri_ptr = 0; - - coap_header.options_list_ptr->uri_host_len = sizeof(option_short); - coap_header.options_list_ptr->uri_host_ptr = option_short; - - coap_header.uri_path_len = sizeof(option_path); - coap_header.uri_path_ptr = option_path; - - coap_header.options_list_ptr->max_age = option_short_value; - - coap_header.token_len = sizeof(option_short); - coap_header.token_ptr = option_short; - - message_len = sn_coap_builder_calc_needed_packet_data_size(&coap_header); - message_ptr = malloc(message_len); - sn_coap_builder(message_ptr, &coap_header); - - TEST_ASSERT_EQUAL(sizeof(coap_message_multiple_options), message_len); - TEST_ASSERT_EQUAL_INT8_ARRAY(coap_message_multiple_options, message_ptr, sizeof(coap_message_multiple_options)); - - free(message_ptr); - message_ptr = 0; -} - -/*******************************************************************************/ -/*** CoAP PARSER TEST ***/ -/*******************************************************************************/ - -/** - * \fn test_libcoap_parser_parse_message_without_options(void) - * - * \brief call coap protocol parser with message without options (ACK - changed) - * - */ -void test_libcoap_parser_parse_message_without_options(void) -{ - coap_address.addr_ptr = address; - - sn_coap_hdr_s *coap_header_ptr = sn_coap_protocol_parse(handle, &coap_address, sizeof(coap_message_no_options), coap_message_no_options, NULL); - - TEST_ASSERT_NOT_NULL(coap_header_ptr); - - TEST_ASSERT_EQUAL(COAP_MSG_TYPE_ACKNOWLEDGEMENT, coap_header_ptr->msg_type); - TEST_ASSERT_EQUAL(COAP_MSG_CODE_RESPONSE_CHANGED, coap_header_ptr->msg_code); - TEST_ASSERT_EQUAL(0x1234, coap_header_ptr->msg_id); - - sn_coap_parser_release_allocated_coap_msg_mem(handle, coap_header_ptr); -} - -/** - * \fn test_libcoap_parser_parse_message_with_payload_and_token(void) - * - * \brief call coap protocol parser with message with token option and small payload (ACK - changed) - * - */ -void test_libcoap_parser_parse_message_with_payload_and_token(void) -{ - coap_address.addr_ptr = address; - - sn_coap_hdr_s *coap_header_ptr = sn_coap_protocol_parse(handle, &coap_address, sizeof(coap_message_token_payload), coap_message_token_payload, NULL); - - TEST_ASSERT_NOT_NULL(coap_header_ptr); - - TEST_ASSERT_EQUAL(COAP_MSG_TYPE_ACKNOWLEDGEMENT, coap_header_ptr->msg_type); - TEST_ASSERT_EQUAL(COAP_MSG_CODE_RESPONSE_CHANGED, coap_header_ptr->msg_code); - TEST_ASSERT_EQUAL(0x1234, coap_header_ptr->msg_id); - - TEST_ASSERT_EQUAL(3, coap_header_ptr->token_len); - TEST_ASSERT_EQUAL_INT8_ARRAY(option_short, coap_header_ptr->token_ptr, sizeof(option_short)); - - TEST_ASSERT_EQUAL(3, coap_header_ptr->payload_len); - TEST_ASSERT_EQUAL_INT8_ARRAY(option_short, coap_header_ptr->payload_ptr, sizeof(option_short)); - - sn_coap_parser_release_allocated_coap_msg_mem(handle, coap_header_ptr); -} - -/** - * \fn test_libcoap_parser_parse_message_with_small_option(void) - * - * \brief call coap protocol parser with message with small option (ACK - changed - URI query) - * - */ -void test_libcoap_parser_parse_message_with_small_option(void) -{ - coap_address.addr_ptr = address; - - sn_coap_hdr_s *coap_header_ptr = sn_coap_protocol_parse(handle, &coap_address, sizeof(coap_message_option_short), coap_message_option_short, NULL); - - TEST_ASSERT_NOT_NULL(coap_header_ptr); - TEST_ASSERT_NOT_NULL(coap_header_ptr->options_list_ptr); - - TEST_ASSERT_EQUAL(COAP_MSG_TYPE_ACKNOWLEDGEMENT, coap_header_ptr->msg_type); - TEST_ASSERT_EQUAL(COAP_MSG_CODE_RESPONSE_CHANGED, coap_header_ptr->msg_code); - TEST_ASSERT_EQUAL(0x1234, coap_header_ptr->msg_id); - - TEST_ASSERT_EQUAL(sizeof(option_short), coap_header_ptr->options_list_ptr->proxy_uri_len); - TEST_ASSERT_EQUAL_INT8_ARRAY(option_short, coap_header_ptr->options_list_ptr->proxy_uri_ptr, sizeof(option_short)); - - sn_coap_parser_release_allocated_coap_msg_mem(handle, coap_header_ptr); -} - - -/** - * \fn test_libcoap_parser_parse_message_with_multiple_options(void) - * - * \brief call coap protocol parser with message with multiple options (ACK - changed - token - max age - URI path - URI host) - * - */ -void test_libcoap_parser_parse_message_with_multiple_options(void) -{ - coap_address.addr_ptr = address; - - sn_coap_hdr_s *coap_header_ptr = sn_coap_protocol_parse(handle, &coap_address, sizeof(coap_message_multiple_options), coap_message_multiple_options, NULL); - - TEST_ASSERT_NOT_NULL(coap_header_ptr); - TEST_ASSERT_NOT_NULL(coap_header_ptr->options_list_ptr); - - TEST_ASSERT_EQUAL(COAP_MSG_TYPE_ACKNOWLEDGEMENT, coap_header_ptr->msg_type); - TEST_ASSERT_EQUAL(COAP_MSG_CODE_RESPONSE_CHANGED, coap_header_ptr->msg_code); - TEST_ASSERT_EQUAL(0x1234, coap_header_ptr->msg_id); - - - TEST_ASSERT_EQUAL(sizeof(option_short), coap_header_ptr->options_list_ptr->uri_host_len); - TEST_ASSERT_EQUAL_INT8_ARRAY(option_short, coap_header_ptr->options_list_ptr->uri_host_ptr, sizeof(option_short)); - - TEST_ASSERT_EQUAL(sizeof(option_path), coap_header_ptr->uri_path_len); - TEST_ASSERT_EQUAL_INT8_ARRAY(option_path, coap_header_ptr->uri_path_ptr, sizeof(option_path)); - - TEST_ASSERT_EQUAL(option_short_value, coap_header_ptr->options_list_ptr->max_age); - - TEST_ASSERT_EQUAL(sizeof(option_short), coap_header_ptr->token_len); - TEST_ASSERT_EQUAL_INT8_ARRAY(option_short, coap_header_ptr->token_ptr, sizeof(option_short)); - - - sn_coap_parser_release_allocated_coap_msg_mem(handle, coap_header_ptr); -} - -/*******************************************************************************/ -/*** NEGATIVE TEST CASES ***/ -/*******************************************************************************/ - -/** - * \fn test_libcoap_negative_build_with_null_pointer(void) - * - * \brief - Call sn_coap_builder_calc_needed_packet_data_size with null pointer parameter - * - Call sn_coap_builder with null pointer parameter - * - */ -void test_libcoap_negative_build_with_null_pointer(void) -{ - int16_t ret_val_1 = 0; - int16_t ret_val_2 = 0; - - message_len = sn_coap_builder_calc_needed_packet_data_size(NULL); - ret_val_1 = sn_coap_builder(message_ptr, NULL); - ret_val_2 = sn_coap_builder(NULL, &coap_header); - - TEST_ASSERT_EQUAL(0, message_len); - TEST_ASSERT_EQUAL(-2, ret_val_1); - TEST_ASSERT_EQUAL(-2, ret_val_2); -} - -/** - * \fn test_libcoap_negative_parse_with_null_pointer(void) - * - * \brief - Call sn_coap_protocol_parse with null pointer parameter - * - */ -void test_libcoap_negative_parse_with_null_pointer(void) -{ - coap_address.addr_ptr = address; - - sn_coap_hdr_s *coap_header_ptr = sn_coap_protocol_parse(handle, NULL, sizeof(coap_message_no_options), coap_message_no_options, NULL); - TEST_ASSERT_NULL(coap_header_ptr); - - coap_header_ptr = sn_coap_protocol_parse(NULL, &coap_address, sizeof(coap_message_no_options), coap_message_no_options, NULL); - TEST_ASSERT_NULL(coap_header_ptr); - - coap_header_ptr = sn_coap_protocol_parse(handle, &coap_address, sizeof(coap_message_no_options), NULL, NULL); - TEST_ASSERT_NULL(coap_header_ptr); -} - -/** - * \fn test_libcoap_negative_parse_with_coap_packet_len_null(void) - * - * \brief - Call sn_coap_protocol_parse with parameter length = 0 - * - */ -void test_libcoap_negative_parse_with_coap_packet_len_null(void) -{ - coap_address.addr_ptr = address; - - sn_coap_hdr_s *coap_header_ptr = sn_coap_protocol_parse(handle, &coap_address, 0, coap_message_no_options, NULL); - TEST_ASSERT_NULL(coap_header_ptr); -} - -/** - * \fn test_libcoap_negative_parse_with_wrong_coap_packet_len(void) - * - * \brief - Call sn_coap_protocol_parse with wrong packet length - * - */ -void test_libcoap_negative_parse_with_wrong_coap_packet_len(void) -{ - coap_address.addr_ptr = address; - - sn_coap_hdr_s *coap_header_ptr = sn_coap_protocol_parse(handle, &coap_address, (sizeof(coap_message_multiple_options) - 1), coap_message_multiple_options, NULL); - TEST_ASSERT_NULL(coap_header_ptr); -} - -/** - * \fn test_libcoap_negative_parse_with_wrong_coap_version(void) - * - * \brief - Call sn_coap_protocol_parse with wrong CoAP version - * - */ -void test_libcoap_negative_parse_with_wrong_coap_version(void) -{ - coap_address.addr_ptr = address; - - sn_coap_hdr_s *coap_header_ptr = sn_coap_protocol_parse(handle, &coap_address, sizeof(coap_message_wrong_version), coap_message_wrong_version, NULL); - TEST_ASSERT_NULL(coap_header_ptr); -} - -/** - * \fn test_libcoap_negative_parse_malformed_coap(void) - * - * \brief - Call sn_coap_protocol_parse with malformed CoAP message - * - */ -void test_libcoap_negative_parse_malformed_coap(void) -{ - coap_address.addr_ptr = address; - - sn_coap_hdr_s *coap_header_ptr = sn_coap_protocol_parse(handle, &coap_address, sizeof(coap_message_malformed), coap_message_malformed, NULL); - TEST_ASSERT_NULL(coap_header_ptr); -} - -/** - * \fn test_libcoap_negative_parse_empty_con(void) - * - * \brief - Call sn_coap_protocol_parse with "CoAP ping" message. Should return RST - * - */ -void test_libcoap_negative_parse_empty_con(void) -{ - coap_address.addr_ptr = address; - - sn_coap_hdr_s *coap_header_ptr = sn_coap_protocol_parse(handle, &coap_address, sizeof(coap_message_empty_con), coap_message_empty_con, NULL); - TEST_ASSERT_NULL(coap_header_ptr); - -} - -/** - * \fn test_libcoap_negative_parse_wrong_code_1(void) - * - * \brief - Call sn_coap_protocol_parse with wrong message code. Should return RST - * - */ -void test_libcoap_negative_parse_wrong_code_1(void) -{ - coap_address.addr_ptr = address; - - sn_coap_hdr_s *coap_header_ptr = sn_coap_protocol_parse(handle, &coap_address, sizeof(coap_message_wrong_code_1), coap_message_wrong_code_1, NULL); - TEST_ASSERT_NULL(coap_header_ptr); - -} - -/** - * \fn test_libcoap_negative_parse_wrong_code_6(void) - * - * \brief - Call sn_coap_protocol_parse with wrong message code. Should return RST - * - */ -void test_libcoap_negative_parse_wrong_code_6(void) -{ - coap_address.addr_ptr = address; - - sn_coap_hdr_s *coap_header_ptr = sn_coap_protocol_parse(handle, &coap_address, sizeof(coap_message_wrong_code_6), coap_message_wrong_code_6, NULL); - TEST_ASSERT_NULL(coap_header_ptr); - -} - -/** - * \fn test_libcoap_negative_parse_wrong_code_7(void) - * - * \brief - Call sn_coap_protocol_parse with wrong message code. Should return RST - * - */ -void test_libcoap_negative_parse_wrong_code_7(void) -{ - coap_address.addr_ptr = address; - - sn_coap_hdr_s *coap_header_ptr = sn_coap_protocol_parse(handle, &coap_address, sizeof(coap_message_wrong_code_7), coap_message_wrong_code_7, NULL); - TEST_ASSERT_NULL(coap_header_ptr); - -} - - -/*******************************/ -/*** non-test functions ***/ -/*******************************/ - -void fill_with_random(uint8_t *ptr, uint16_t len) -{ - while (len--) { - *(ptr + len) = 'a'; - } -} - -void *own_alloc(uint16_t size) -{ - return malloc(size); -} - -void own_free(void *ptr) -{ - free(ptr); -} - -uint8_t tx_function(uint8_t *data_ptr, uint16_t data_len, sn_nsdl_addr_s *address_ptr, void *param) -{ - return 0; -} - -int8_t rx_callback(sn_coap_hdr_s *coap_header_ptr, sn_nsdl_addr_s *address_ptr, void *param) -{ - return 0; -} - - - - - - - - - diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/unittest/test_libCoap/makefile b/features/FEATURE_COMMON_PAL/mbed-client-c/unittest/test_libCoap/makefile deleted file mode 100644 index f762fc6992..0000000000 --- a/features/FEATURE_COMMON_PAL/mbed-client-c/unittest/test_libCoap/makefile +++ /dev/null @@ -1,31 +0,0 @@ -# ========================================== -# Unity Project - A Test Framework for C -# Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams -# [Released under MIT License. Please refer to license.txt for details] -# ========================================== - -C_COMPILER=gcc -TARGET_BASE=test_libCoap -TARGET_EXTENSION=.out -TARGET = $(TARGET_BASE)$(TARGET_EXTENSION) - -SRC_FILES=../../../unittest/src/unity.c ../../source/libCoap/src/sn_coap_protocol.c ../../source/libCoap/src/sn_coap_parser.c \ -../../source/libCoap/src/sn_coap_header_check.c ../../source/libCoap/src/sn_coap_builder.c ../../../libService/source/libList/ns_list.c \ -Test.c Test_Runner.c - -INC_DIRS=-I../../../unittest/src -I../../nsdl-c/ -I../../source/libCoap/src/include -I../../../libService/libService - -SYMBOLS=-DTEST -std=gnu99 -DUNITY_EXCLUDE_STDINT_H - -CLEANUP = rm -f build/*.o ; rm -f $(TARGET) - -all: clean default - -default: - ruby ../../../unittest/auto/generate_test_runner.rb Test.c Test_Runner.c - $(C_COMPILER) $(INC_DIRS) $(SYMBOLS) $(SRC_FILES) -o $(TARGET) - ./$(TARGET) - -clean: - $(CLEANUP) - diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/unittest/test_libNsdl/Test.c b/features/FEATURE_COMMON_PAL/mbed-client-c/unittest/test_libNsdl/Test.c deleted file mode 100644 index 577a74ccbd..0000000000 --- a/features/FEATURE_COMMON_PAL/mbed-client-c/unittest/test_libNsdl/Test.c +++ /dev/null @@ -1,701 +0,0 @@ -/* - * Copyright (c) 2015 ARM Limited. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 - * Licensed under the Apache License, Version 2.0 (the License); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * \file \test_libNsdl\Test.c - * - * \brief Unit tests for libNsdl - * NOTE!! Needs libCoap.a from ../../nsdl-c/libCoap/x86_gcc - * - * */ - -#include "ns_types.h" - -#include "sn_nsdl.h" -#include "sn_coap_header.h" -#include "sn_coap_protocol.h" -#include "sn_nsdl_lib.h" - -#include "unity.h" -#include "string.h" -#include "stdlib.h" - -/* non-test function declarations */ -void fill_with_random(uint8_t *ptr, uint16_t len); -void *own_alloc(uint16_t size); -void own_free(void *ptr); -uint8_t nsdl_tx_dummy(struct nsdl_s *, sn_nsdl_capab_e , uint8_t *, uint16_t, sn_nsdl_addr_s *); -uint8_t nsdl_rx_dummy(struct nsdl_s *, sn_coap_hdr_s *, sn_nsdl_addr_s *); -uint8_t dynamic_callback(struct nsdl_s *handle, sn_coap_hdr_s *coap_header_ptr, sn_nsdl_addr_s *address_ptr, sn_nsdl_capab_e protocol); -static void init_temp_variables(void); - -static uint8_t res1_path[] = {"test/res1"}; -static uint8_t res1_content[] = {"res1 content"}; - -static uint8_t res2_path[] = {"test/res2"}; -static uint8_t res2_content[] = {"res2 content"}; - -static uint8_t res3_path[] = {"test/res3"}; -static uint8_t res3_content[] = {"res3 content"}; - -static uint8_t res4_path[] = {"test/res4"}; -static uint8_t res4_content[] = {"res4 content"}; - -static uint8_t res5_path[] = {"test/res5"}; -static uint8_t res5_content[] = {"res5 content"}; - -static uint8_t res_negative_path[] = {"test/negative"}; -static uint8_t res_negative_content[] = {"negative_test content"}; - -static uint8_t address[16] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}; - -/* Change byte 13 to differend resources */ -static uint8_t get_message[14] = {0x40, 0x01, 0x12, 0x34, 0xb4, 0x74, 0x65, 0x73, 0x74, 0x04, 0x72, 0x65, 0x73, 0x31}; -static uint8_t put_message[18] = {0x40, 0x03, 0x12, 0x34, 0xb4, 0x74, 0x65, 0x73, 0x74, 0x04, 0x72, 0x65, 0x73, 0x32, 0xff, 0x61, 0x62, 0x63}; -static uint8_t post_message[18] = {0x40, 0x02, 0x12, 0x34, 0xb4, 0x74, 0x65, 0x73, 0x74, 0x04, 0x72, 0x65, 0x73, 0x33, 0xff, 0x61, 0x62, 0x63}; -static uint8_t delete_message[14] = {0x40, 0x04, 0x12, 0x34, 0xb4, 0x74, 0x65, 0x73, 0x74, 0x04, 0x72, 0x65, 0x73, 0x34}; - -static uint8_t message_payload[3] = {0x61, 0x62, 0x63}; - -static uint8_t get_response[17] = {0x60, 0x45, 0x12, 0x34, 0xff, 0x72, 0x65, 0x73, 0x31, 0x20, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74}; -static uint8_t response_not_allowed[4] = {0x60, 0x85, 0x12, 0x34}; -static uint8_t response_changed[4] = {0x60, 0x44, 0x12, 0x34}; -static uint8_t response_created[4] = {0x60, 0x41, 0x12, 0x34}; -static uint8_t response_deleted[4] = {0x60, 0x42, 0x12, 0x34}; - -#define NSP_ADDRESS_LEN 4 -#define NSP_PORT 5683 - -#define NSP_REGISTRATION_MESSAGE_LEN 72 -static uint8_t registration_message[NSP_REGISTRATION_MESSAGE_LEN] = { - 0x40, 0x02, 0x01, 0x47, 0xb2, 0x72, 0x64, 0xff, 0x3c, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x2f, 0x72, - 0x65, 0x73, 0x35, 0x3e, 0x2c, 0x3c, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x2f, 0x72, 0x65, 0x73, 0x34, - 0x3e, 0x2c, 0x3c, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x2f, 0x72, 0x65, 0x73, 0x33, 0x3e, 0x2c, 0x3c, - 0x2f, 0x74, 0x65, 0x73, 0x74, 0x2f, 0x72, 0x65, 0x73, 0x32, 0x3e, 0x2c, 0x3c, 0x2f, 0x74, 0x65, - 0x73, 0x74, 0x2f, 0x72, 0x65, 0x73, 0x31, 0x3e -}; - -static uint16_t message_temp_len = 0; -static uint8_t *message_temp_ptr = 0; -static sn_nsdl_addr_s *address_temp_ptr = 0; - -struct nsdl_s *handle; - -/* Unity test code starts */ -void setUp(void) -{ - //This is run before EACH TEST - -} - -void tearDown(void) -{ - -} - -/** - * \fn void test_libnsdl_init(void) - * - * \brief Tests sn_nsdl_init - function. Function must return failure (-1) if initialization fails. - * - * Negative test cases: - * - Memory structure contains null pointer(s) - * - One of the parameter is null - * - */ -void test_libnsdl_init(void) -{ - /* Memory struct contains null */ - handle = sn_nsdl_init(&nsdl_tx_dummy, &nsdl_rx_dummy, NULL, NULL); - TEST_ASSERT_NULL(handle); - - handle = sn_nsdl_init(&nsdl_tx_dummy, &nsdl_rx_dummy, &own_alloc, NULL); - TEST_ASSERT_NULL(handle); - - handle = sn_nsdl_init(&nsdl_tx_dummy, &nsdl_rx_dummy, NULL, &own_free); - TEST_ASSERT_NULL(handle); - - /* One of parameters is null */ - handle = sn_nsdl_init(NULL, &nsdl_rx_dummy, &own_alloc, &own_free); - TEST_ASSERT_NULL(handle); - - handle = sn_nsdl_init(&nsdl_tx_dummy, NULL, &own_alloc, &own_free); - TEST_ASSERT_NULL(handle); - - /* OK case */ - handle = sn_nsdl_init(&nsdl_tx_dummy, &nsdl_rx_dummy, &own_alloc, &own_free); - TEST_ASSERT_NOT_NULL(handle); -} - -/** - * \fn void test_libnsdl_create_resource(void) - * - * \brief Tests sn_nsdl_create_resource - function. Creates five resources. - * - * STATIC RESOURCES: - * - Resource 1 - * * Get allowed - * - Resource 2 - * * Put allowed - * - Resource 3 - * * Post allowed - * - Resource 4 - * * Delete allowed - * - * DYNAMIC RESOURCES: - * - Resource 5 - * * All allowed - * - * Negative test cases: - * - Resource already exists - * - Null pointer as a parameter - * - */ -void test_libnsdl_create_resource(void) -{ - sn_nsdl_resource_info_s resource; - sn_nsdl_resource_parameters_s resource_parameters; - int8_t ret_val; - - memset(&resource, 0, sizeof(sn_nsdl_resource_info_s)); - memset(&resource_parameters, 0, sizeof(sn_nsdl_resource_parameters_s)); - - - /* Resource 1*/ - resource.access = SN_GRS_GET_ALLOWED; - resource.mode = SN_GRS_STATIC; - resource.path = res1_path; - resource.pathlen = sizeof(res1_path) - 1; - resource.resource = res1_content; - resource.resourcelen = sizeof(res1_content) - 1; - resource.resource_parameters_ptr = &resource_parameters; - - ret_val = sn_nsdl_create_resource(handle, &resource); - TEST_ASSERT_EQUAL(0, ret_val); - - - /* Resource 2 */ - resource.access = SN_GRS_PUT_ALLOWED; - resource.path = res2_path; - resource.pathlen = sizeof(res2_path) - 1; - resource.resource = res2_content; - resource.resourcelen = sizeof(res2_content) - 1; - - ret_val = sn_nsdl_create_resource(handle, &resource); - TEST_ASSERT_EQUAL(0, ret_val); - - - /* Resource 3 */ - resource.access = SN_GRS_POST_ALLOWED; - resource.path = res3_path; - resource.pathlen = sizeof(res3_path) - 1; - resource.resource = res3_content; - resource.resourcelen = sizeof(res3_content) - 1; - - ret_val = sn_nsdl_create_resource(handle, &resource); - TEST_ASSERT_EQUAL(0, ret_val); - - - /* Resource 4 */ - resource.access = SN_GRS_DELETE_ALLOWED; - resource.path = res4_path; - resource.pathlen = sizeof(res4_path) - 1; - resource.resource = res4_content; - resource.resourcelen = sizeof(res4_content) - 1; - - ret_val = sn_nsdl_create_resource(handle, &resource); - TEST_ASSERT_EQUAL(0, ret_val); - - - /* Resource 5 - Dynamic*/ - resource.mode = SN_GRS_DYNAMIC; - - resource.access = 0xFF; - resource.path = res5_path; - resource.pathlen = sizeof(res5_path) - 1; - resource.resource = res5_content; - resource.resourcelen = sizeof(res5_content) - 1; - resource.sn_grs_dyn_res_callback = &dynamic_callback; - - ret_val = sn_nsdl_create_resource(handle, &resource); - TEST_ASSERT_EQUAL(0, ret_val); - - /*** Negative test cases ***/ - - /* Already exists */ - ret_val = sn_nsdl_create_resource(handle, &resource); - TEST_ASSERT_EQUAL(-2, ret_val); - - /* Null pointer */ - ret_val = sn_nsdl_create_resource(handle, NULL); - TEST_ASSERT_EQUAL(-1, ret_val); - - ret_val = sn_nsdl_create_resource(NULL, &resource); - TEST_ASSERT_EQUAL(-1, ret_val); - - resource.path = NULL; - resource.pathlen = sizeof(res_negative_path) - 1; - resource.resource = res_negative_content; - resource.resourcelen = sizeof(res_negative_content) - 1; - - ret_val = sn_nsdl_create_resource(handle, &resource); - TEST_ASSERT_EQUAL(-3, ret_val); - - resource.path = res_negative_path; - resource.pathlen = 0; - - ret_val = sn_nsdl_create_resource(handle, &resource); - TEST_ASSERT_EQUAL(-3, ret_val); - -} - -/** - * \fn test_libnsdl_list_resources(void) - * - * \brief Calls sn_nsdl_list_resource - function - * Function must return list of early created resources - */ - -void test_libnsdl_list_resources(void) -{ - sn_grs_resource_list_s *resource_list_ptr; - - resource_list_ptr = sn_nsdl_list_resource(handle, 0, 0); - - TEST_ASSERT_EQUAL(5, resource_list_ptr->res_count); - - TEST_ASSERT_EQUAL_INT8_ARRAY(resource_list_ptr->res[4].path, res1_path, resource_list_ptr->res[4].pathlen); - TEST_ASSERT_EQUAL_INT8_ARRAY(resource_list_ptr->res[3].path, res2_path, resource_list_ptr->res[3].pathlen); - TEST_ASSERT_EQUAL_INT8_ARRAY(resource_list_ptr->res[2].path, res3_path, resource_list_ptr->res[2].pathlen); - TEST_ASSERT_EQUAL_INT8_ARRAY(resource_list_ptr->res[1].path, res4_path, resource_list_ptr->res[1].pathlen); - TEST_ASSERT_EQUAL_INT8_ARRAY(resource_list_ptr->res[0].path, res5_path, resource_list_ptr->res[0].pathlen); - -} - -/** - * \fn test_libnsdl_get_resource(void) - * - * \brief Calls sn_nsdl_get_resource - function - * Function must return pointer to created resource - * - * Negative test cases: - * - call function with null parameter - * - */ - -void test_libnsdl_get_resource(void) -{ - sn_nsdl_resource_info_s *res_ptr; - - /* With null pointer */ - res_ptr = sn_nsdl_get_resource(handle, 0, res1_path); - TEST_ASSERT_NULL(res_ptr); - - res_ptr = sn_nsdl_get_resource(handle, sizeof(res1_path) - 1, NULL); - TEST_ASSERT_NULL(res_ptr); - - res_ptr = sn_nsdl_get_resource(NULL, sizeof(res1_path) - 1, res1_path); - TEST_ASSERT_NULL(res_ptr); - - /* Ok case, gets resource 1 and checks that path and content are ok */ - res_ptr = sn_nsdl_get_resource(handle, sizeof(res1_path) - 1, res1_path); - TEST_ASSERT_NOT_NULL(res_ptr); - - TEST_ASSERT_EQUAL_INT8_ARRAY(res_ptr->path, res1_path, sizeof(res1_path) - 1); - TEST_ASSERT_EQUAL_INT8_ARRAY(res_ptr->resource, res1_content, sizeof(res1_content) - 1); -} - -/** - * \fn test_libnsdl_set_nsp_address(void) - * - * \brief Sets NSP address to nsdl-library - * - * Negative test cases: - * - call function with null parameter - */ -void test_libnsdl_set_nsp_address(void) -{ - int8_t ret_val = 0; - - /* with null pointer */ - ret_val = set_NSP_address(handle, NULL, NSP_PORT, SN_NSDL_ADDRESS_TYPE_IPV4); - TEST_ASSERT_EQUAL(-1, ret_val); - - ret_val = set_NSP_address(NULL, address, NSP_PORT, SN_NSDL_ADDRESS_TYPE_IPV4); - TEST_ASSERT_EQUAL(-1, ret_val); - - /* OK case */ - ret_val = set_NSP_address(handle, address, NSP_PORT, SN_NSDL_ADDRESS_TYPE_IPV4); - TEST_ASSERT_EQUAL(0, ret_val); -} - -/** - * \fn test_libnsdl_set_nsp_address_2(void) - * - * \brief Sets NSP address to nsdl-library - * - * Negative test cases: - * - call function with null parameter - */ -void test_libnsdl_set_nsp_address_2(void) -{ - int8_t ret_val = 0; - - /* with null pointer */ - ret_val = set_NSP_address_2(handle, NULL, NSP_ADDRESS_LEN, NSP_PORT, SN_NSDL_ADDRESS_TYPE_IPV4); - TEST_ASSERT_EQUAL(-1, ret_val); - - ret_val = set_NSP_address_2(NULL, address, NSP_ADDRESS_LEN, NSP_PORT, SN_NSDL_ADDRESS_TYPE_IPV4); - TEST_ASSERT_EQUAL(-1, ret_val); - - /* OK case */ - ret_val = set_NSP_address_2(handle, address, NSP_ADDRESS_LEN, NSP_PORT, SN_NSDL_ADDRESS_TYPE_IPV4); - TEST_ASSERT_EQUAL(0, ret_val); -} - -/** - * \fn test_libnsdl_register(void) - * - * \brief Calls sn_nsdl_get_resource - function - * - * Negative test cases: - * - call function with null parameter - * - */ - -void test_libnsdl_register(void) -{ - int8_t ret_val = 0; - sn_nsdl_ep_parameters_s endpoint_info; - - memset(&endpoint_info, 0, sizeof(sn_nsdl_ep_parameters_s)); - - /* With null pointer */ - ret_val = sn_nsdl_register_endpoint(handle, NULL); - TEST_ASSERT_EQUAL(0, ret_val); - - ret_val = sn_nsdl_register_endpoint(NULL, &endpoint_info); - TEST_ASSERT_EQUAL(0, ret_val); - - /* OK case */ - ret_val = sn_nsdl_register_endpoint(handle, &endpoint_info); - TEST_ASSERT_NOT_EQUAL(0, ret_val); - - /* Check address */ - TEST_ASSERT_EQUAL(NSP_PORT, address_temp_ptr->port); - TEST_ASSERT_EQUAL_INT8_ARRAY(address, address_temp_ptr->addr_ptr, address_temp_ptr->addr_len); - - /* Check registration message !Note, message ID [bytes 2-3] is random in every message! */ - TEST_ASSERT_EQUAL(NSP_REGISTRATION_MESSAGE_LEN, message_temp_len); - TEST_ASSERT_EQUAL_INT8_ARRAY(message_temp_ptr, registration_message, 2); //message header - TEST_ASSERT_EQUAL_INT8_ARRAY(message_temp_ptr + 4, registration_message + 4, message_temp_len - 4); //Rest of the message - - init_temp_variables(); -} - -/** - * \fn void test_libnsdl_get_requests_to_resources(void) - * - * \brief Process CoAP message "GET" - * - * - GET to resource that is allowed - * - GET to resource that is not allowed - * - */ - -void test_libnsdl_get_requests_to_resources(void) -{ - sn_nsdl_addr_s address_struct; - int8_t ret_val = 0; - - address_struct.addr_ptr = address; - address_struct.addr_len = 16; - address_struct.port = NSP_PORT; - - /* Get to resource that is allowed */ - ret_val = sn_nsdl_process_coap(handle, get_message, sizeof(get_message), &address_struct); - - TEST_ASSERT_EQUAL(0, ret_val); - TEST_ASSERT_EQUAL(sizeof(get_response), message_temp_len); - TEST_ASSERT_EQUAL_INT8_ARRAY(message_temp_ptr, get_response, message_temp_len); - - init_temp_variables(); - - /* Get to resource that is not allowed */ - get_message[13] = 0x32; - ret_val = sn_nsdl_process_coap(handle, get_message, sizeof(get_message), &address_struct); - get_message[13] = 0x31; - - TEST_ASSERT_EQUAL(0, ret_val); - - TEST_ASSERT_EQUAL(sizeof(response_not_allowed), message_temp_len); - TEST_ASSERT_EQUAL_INT8_ARRAY(message_temp_ptr, response_not_allowed, message_temp_len); - - init_temp_variables(); -} - -/** - * \fn void test_libnsdl_put_requests_to_resources(void) - * - * \brief Process CoAP message "PUT" - * - * - PUT to resource that is allowed - * - PUT to resource that is not allowed - */ -void test_libnsdl_put_requests_to_resources(void) -{ - sn_nsdl_addr_s address_struct; - int8_t ret_val = 0; - sn_nsdl_resource_info_s *res_ptr; - - address_struct.addr_ptr = address; - address_struct.addr_len = 16; - address_struct.port = NSP_PORT; - - /* Put to resource that is allowed */ - ret_val = sn_nsdl_process_coap(handle, put_message, sizeof(put_message), &address_struct); - - TEST_ASSERT_EQUAL(0, ret_val); - TEST_ASSERT_EQUAL(sizeof(response_changed), message_temp_len); - TEST_ASSERT_EQUAL_INT8_ARRAY(response_changed, message_temp_ptr, message_temp_len); - - //get resource and read res value - res_ptr = sn_nsdl_get_resource(handle, sizeof(res2_path) - 1, res2_path); - TEST_ASSERT_EQUAL_INT8_ARRAY(message_payload, res_ptr->resource, sizeof(message_payload)); - - init_temp_variables(); - - /* Put to resource that is not allowed */ - put_message[13] = 0x31; - ret_val = sn_nsdl_process_coap(handle, put_message, sizeof(put_message), &address_struct); - put_message[13] = 0x32; - - TEST_ASSERT_EQUAL(0, ret_val); - TEST_ASSERT_EQUAL(sizeof(response_not_allowed), message_temp_len); - TEST_ASSERT_EQUAL_INT8_ARRAY(response_not_allowed, message_temp_ptr, message_temp_len); - - init_temp_variables(); -} - -/** - * \fn void test_libnsdl_post_requests_to_resources(void) - * - * \brief Process CoAP message "POST" - * - * - POST to resource that is allowed - * - POST to resource that is not allowed - * - */ -void test_libnsdl_post_requests_to_resources(void) -{ - sn_nsdl_addr_s address_struct; - int8_t ret_val = 0; - sn_nsdl_resource_info_s *res_ptr; - - address_struct.addr_ptr = address; - address_struct.addr_len = 16; - address_struct.port = NSP_PORT; - - /* Post to resource that is allowed */ - ret_val = sn_nsdl_process_coap(handle, post_message, sizeof(post_message), &address_struct); - - TEST_ASSERT_EQUAL(0, ret_val); - TEST_ASSERT_EQUAL(sizeof(response_changed), message_temp_len); - TEST_ASSERT_EQUAL_INT8_ARRAY(response_changed, message_temp_ptr, message_temp_len); - - //get resource and read res value - res_ptr = sn_nsdl_get_resource(handle, sizeof(res3_path) - 1, res3_path); - TEST_ASSERT_EQUAL_INT8_ARRAY(message_payload, res_ptr->resource, sizeof(message_payload)); - - init_temp_variables(); - - /* Post to resource that is not allowed */ - post_message[13] = 0x32; - ret_val = sn_nsdl_process_coap(handle, post_message, sizeof(post_message), &address_struct); - post_message[13] = 0x33; - - TEST_ASSERT_EQUAL(0, ret_val); - TEST_ASSERT_EQUAL(sizeof(response_not_allowed), message_temp_len); - TEST_ASSERT_EQUAL_INT8_ARRAY(response_not_allowed, message_temp_ptr, message_temp_len); - - init_temp_variables(); -} - -/** - * \fn void test_libnsdl_delete_requests_to_resources(void) - * - * \brief Process CoAP message "DELETE" - * - * - DELETE to resource that is allowed - * - DELETE to resource that is not allowed - * - */ -void test_libnsdl_delete_requests_to_resources(void) -{ - sn_nsdl_addr_s address_struct; - int8_t ret_val = 0; - sn_nsdl_resource_info_s *res_ptr; - - address_struct.addr_ptr = address; - address_struct.addr_len = 16; - address_struct.port = NSP_PORT; - - /* Delete to resource that is not allowed */ - delete_message[13] = 0x33; - ret_val = sn_nsdl_process_coap(handle, delete_message, sizeof(delete_message), &address_struct); - delete_message[13] = 0x34; - - TEST_ASSERT_EQUAL(0, ret_val); - TEST_ASSERT_EQUAL(sizeof(response_not_allowed), message_temp_len); - TEST_ASSERT_EQUAL_INT8_ARRAY(response_not_allowed, message_temp_ptr, message_temp_len); - - init_temp_variables(); -} - -/** - * \fn void test_libnsdl_update_resource_value(void) - * - * \brief Updates resource value from application - * - */ -void test_libnsdl_update_resource_value(void) -{ - sn_nsdl_resource_info_s resource; - sn_nsdl_resource_info_s *res_ptr; - sn_nsdl_resource_parameters_s resource_parameters; - int8_t ret_val; - - memset(&resource, 0, sizeof(sn_nsdl_resource_info_s)); - memset(&resource_parameters, 0, sizeof(sn_nsdl_resource_parameters_s)); - - /* Resource 1*/ - resource.access = SN_GRS_GET_ALLOWED; - resource.mode = SN_GRS_STATIC; - resource.path = res1_path; - resource.pathlen = sizeof(res1_path) - 1; - resource.resource = message_payload; - resource.resourcelen = sizeof(message_payload); - resource.resource_parameters_ptr = &resource_parameters; - - ret_val = sn_nsdl_update_resource(handle, &resource); - - TEST_ASSERT_EQUAL(0, ret_val); - - //get resource and read res value - res_ptr = sn_nsdl_get_resource(handle, sizeof(res1_path) - 1, res1_path); - TEST_ASSERT_NOT_NULL(res_ptr); - TEST_ASSERT_EQUAL_INT8_ARRAY(message_payload, res_ptr->resource, sizeof(message_payload)); - -} - -/** - * \fn void test_libnsdl_delete_resource(void) - * - * \brief Delete resource from application - * - */ -void test_libnsdl_delete_resource(void) -{ - sn_nsdl_resource_info_s *res_ptr; - int8_t ret_val; - - ret_val = sn_nsdl_delete_resource(handle, sizeof(res4_path) - 1, res4_path); - - TEST_ASSERT_EQUAL(0, ret_val); - - //get resource and read res value - res_ptr = sn_nsdl_get_resource(handle, sizeof(res4_path) - 1, res4_path); - TEST_ASSERT_NULL(res_ptr); -} - - -/*******************************/ -/*** non-test functions ***/ -/*******************************/ - -void fill_with_random(uint8_t *ptr, uint16_t len) -{ - while (len--) { - *(ptr + len) = 'a'; - } -} - -void *own_alloc(uint16_t size) -{ - return malloc(size); -} - -void own_free(void *ptr) -{ - free(ptr); -} - -uint8_t nsdl_tx_dummy(struct nsdl_s *handle, sn_nsdl_capab_e protocol, uint8_t *data_ptr, uint16_t data_len, sn_nsdl_addr_s *address_ptr) -{ - message_temp_ptr = malloc(data_len); - memcpy(message_temp_ptr, data_ptr, data_len); - - message_temp_len = data_len; - - address_temp_ptr = malloc(sizeof(sn_nsdl_addr_s)); - memcpy(address_temp_ptr, address_ptr, sizeof(sn_nsdl_addr_s)); - -#if 0 - uint8_t i; - printf("\nlength = %d\n", data_len); - for (i = 0; i < data_len; i++) { - printf("0x"); - if (*(data_ptr + i) <= 0x0F) { - printf("0"); - } - printf("%x, ", *(data_ptr + i)); - if (!((i + 1) % 16)) { - printf("\n"); - } - } - printf("\n"); -#endif -} - -uint8_t nsdl_rx_dummy(struct nsdl_s *handle, sn_coap_hdr_s *coap_header_ptr, sn_nsdl_addr_s *address_ptr) -{ - -} - -uint8_t dynamic_callback(struct nsdl_s *handle, sn_coap_hdr_s *coap_header_ptr, sn_nsdl_addr_s *address_ptr, sn_nsdl_capab_e protocol) -{ - -} - -static void init_temp_variables(void) -{ - if (message_temp_ptr) { - free(message_temp_ptr); - message_temp_ptr = 0; - } - if (address_temp_ptr) { - free(address_temp_ptr); - address_temp_ptr = 0; - } - message_temp_len = 0; -} - - - - - - - - diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/unittest/test_libNsdl/makefile b/features/FEATURE_COMMON_PAL/mbed-client-c/unittest/test_libNsdl/makefile deleted file mode 100644 index 8037c3cadd..0000000000 --- a/features/FEATURE_COMMON_PAL/mbed-client-c/unittest/test_libNsdl/makefile +++ /dev/null @@ -1,33 +0,0 @@ -# ========================================== -# Unity Project - A Test Framework for C -# Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams -# [Released under MIT License. Please refer to license.txt for details] -# ========================================== - -C_COMPILER=gcc -TARGET_BASE=test_libNsdl -TARGET_EXTENSION=.out - -TARGET = $(TARGET_BASE)$(TARGET_EXTENSION) - -SRC_FILES=../../../unittest/src/unity.c ../../source/libNsdl/src/sn_grs.c ../../source/libNsdl/src/sn_nsdl.c \ -../../../libService/source/libList/ns_list.c Test.c Test_Runner.c - -INC_DIRS=-I../../../unittest/src -I../../nsdl-c/ -I../../source/libNsdl/src/include -I../../../libService/libService - -SYMBOLS= -std=c99 -DTEST -DUNITY_EXCLUDE_STDINT_H - -LDFLAGS = -L../../ -lnsdl_gcc - -CLEANUP = rm -f build/*.o ; rm -f $(TARGET) - -all: clean default - -default: - ruby ../../../unittest/auto/generate_test_runner.rb Test.c Test_Runner.c - $(C_COMPILER) $(INC_DIRS) $(SYMBOLS) $(SRC_FILES) -o $(TARGET) $(LDFLAGS) - ./$(TARGET) - -clean: - $(CLEANUP) - diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/.gitattributes b/features/FEATURE_COMMON_PAL/mbed-coap/.gitattributes similarity index 100% rename from features/FEATURE_COMMON_PAL/mbed-client-c/.gitattributes rename to features/FEATURE_COMMON_PAL/mbed-coap/.gitattributes diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/.gitignore b/features/FEATURE_COMMON_PAL/mbed-coap/.gitignore similarity index 79% rename from features/FEATURE_COMMON_PAL/mbed-client-c/.gitignore rename to features/FEATURE_COMMON_PAL/mbed-coap/.gitignore index 0b5c53aa76..174f6a2aa8 100644 --- a/features/FEATURE_COMMON_PAL/mbed-client-c/.gitignore +++ b/features/FEATURE_COMMON_PAL/mbed-coap/.gitignore @@ -27,8 +27,8 @@ Backup* docs/ yotta_modules yotta_targets -test/nsdl-c/unittest/coverages -test/nsdl-c/unittest/results +test/mbed-coap/unittest/coverages +test/mbed-coap/unittest/results .yotta.json coverage/ lcov/ diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/.mbedignore b/features/FEATURE_COMMON_PAL/mbed-coap/.mbedignore similarity index 100% rename from features/FEATURE_COMMON_PAL/mbed-client-c/.mbedignore rename to features/FEATURE_COMMON_PAL/mbed-coap/.mbedignore diff --git a/features/FEATURE_COMMON_PAL/mbed-coap/.settings/language.settings.xml b/features/FEATURE_COMMON_PAL/mbed-coap/.settings/language.settings.xml new file mode 100644 index 0000000000..10adfebcee --- /dev/null +++ b/features/FEATURE_COMMON_PAL/mbed-coap/.settings/language.settings.xml @@ -0,0 +1,195 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/features/FEATURE_COMMON_PAL/mbed-coap/.settings/org.eclipse.cdt.core.prefs b/features/FEATURE_COMMON_PAL/mbed-coap/.settings/org.eclipse.cdt.core.prefs new file mode 100644 index 0000000000..648e86b1d8 --- /dev/null +++ b/features/FEATURE_COMMON_PAL/mbed-coap/.settings/org.eclipse.cdt.core.prefs @@ -0,0 +1,62 @@ +eclipse.preferences.version=1 +environment/project/0.2056004298.141662914.1517984773.801758434.1788862897.788959847/CC/delimiter=; +environment/project/0.2056004298.141662914.1517984773.801758434.1788862897.788959847/CC/operation=append +environment/project/0.2056004298.141662914.1517984773.801758434.1788862897.788959847/CC/value=gcc +environment/project/0.2056004298.141662914.1517984773.801758434.1788862897.788959847/V/delimiter=; +environment/project/0.2056004298.141662914.1517984773.801758434.1788862897.788959847/V/operation=append +environment/project/0.2056004298.141662914.1517984773.801758434.1788862897.788959847/V/value=1 +environment/project/0.2056004298.141662914.1517984773.801758434.1788862897.788959847/append=true +environment/project/0.2056004298.141662914.1517984773.801758434.1788862897.788959847/appendContributed=true +environment/project/0.2056004298.141662914.2121498000.642060230.2118977701.1678729521/CPU/delimiter=; +environment/project/0.2056004298.141662914.2121498000.642060230.2118977701.1678729521/CPU/operation=replace +environment/project/0.2056004298.141662914.2121498000.642060230.2118977701.1678729521/CPU/value=Cortex-M0 +environment/project/0.2056004298.141662914.2121498000.642060230.2118977701.1678729521/DEBUG/delimiter=; +environment/project/0.2056004298.141662914.2121498000.642060230.2118977701.1678729521/DEBUG/operation=replace +environment/project/0.2056004298.141662914.2121498000.642060230.2118977701.1678729521/DEBUG/value=1 +environment/project/0.2056004298.141662914.2121498000.642060230.2118977701.1678729521/PLATFORM/delimiter=; +environment/project/0.2056004298.141662914.2121498000.642060230.2118977701.1678729521/PLATFORM/operation=append +environment/project/0.2056004298.141662914.2121498000.642060230.2118977701.1678729521/PLATFORM/value=arm-unknown-linux-uclibcgnueabi- +environment/project/0.2056004298.141662914.2121498000.642060230.2118977701.1678729521/V/delimiter=; +environment/project/0.2056004298.141662914.2121498000.642060230.2118977701.1678729521/V/operation=append +environment/project/0.2056004298.141662914.2121498000.642060230.2118977701.1678729521/V/value=1 +environment/project/0.2056004298.141662914.2121498000.642060230.2118977701.1678729521/append=true +environment/project/0.2056004298.141662914.2121498000.642060230.2118977701.1678729521/appendContributed=true +environment/project/0.2056004298.141662914.2121498000.642060230.2118977701/CPU/delimiter=; +environment/project/0.2056004298.141662914.2121498000.642060230.2118977701/CPU/operation=replace +environment/project/0.2056004298.141662914.2121498000.642060230.2118977701/CPU/value=Cortex-M0 +environment/project/0.2056004298.141662914.2121498000.642060230.2118977701/DEBUG/delimiter=; +environment/project/0.2056004298.141662914.2121498000.642060230.2118977701/DEBUG/operation=replace +environment/project/0.2056004298.141662914.2121498000.642060230.2118977701/DEBUG/value=1 +environment/project/0.2056004298.141662914.2121498000.642060230.2118977701/PLATFORM/delimiter=; +environment/project/0.2056004298.141662914.2121498000.642060230.2118977701/PLATFORM/operation=append +environment/project/0.2056004298.141662914.2121498000.642060230.2118977701/PLATFORM/value=arm-unknown-linux-uclibcgnueabi- +environment/project/0.2056004298.141662914.2121498000.642060230.2118977701/V/delimiter=; +environment/project/0.2056004298.141662914.2121498000.642060230.2118977701/V/operation=append +environment/project/0.2056004298.141662914.2121498000.642060230.2118977701/V/value=1 +environment/project/0.2056004298.141662914.2121498000.642060230.2118977701/append=true +environment/project/0.2056004298.141662914.2121498000.642060230.2118977701/appendContributed=true +environment/project/0.2056004298.1497082229.1854995973/CC/delimiter=; +environment/project/0.2056004298.1497082229.1854995973/CC/operation=append +environment/project/0.2056004298.1497082229.1854995973/CC/value=ArmCC +environment/project/0.2056004298.1497082229.1854995973/CPU/delimiter=; +environment/project/0.2056004298.1497082229.1854995973/CPU/operation=replace +environment/project/0.2056004298.1497082229.1854995973/CPU/value=Cortex-M0 +environment/project/0.2056004298.1497082229.1854995973/DEBUG/delimiter=; +environment/project/0.2056004298.1497082229.1854995973/DEBUG/operation=replace +environment/project/0.2056004298.1497082229.1854995973/DEBUG/value=1 +environment/project/0.2056004298.1497082229.1854995973/V/delimiter=; +environment/project/0.2056004298.1497082229.1854995973/V/operation=append +environment/project/0.2056004298.1497082229.1854995973/V/value=1 +environment/project/0.2056004298.1497082229.1854995973/append=true +environment/project/0.2056004298.1497082229.1854995973/appendContributed=true +environment/project/0.2056004298.1497082229/CC/delimiter=; +environment/project/0.2056004298.1497082229/CC/operation=append +environment/project/0.2056004298.1497082229/CC/value=ArmCC +environment/project/0.2056004298.1497082229/CPU/delimiter=; +environment/project/0.2056004298.1497082229/CPU/operation=append +environment/project/0.2056004298.1497082229/CPU/value=Cortex-M3 +environment/project/0.2056004298.1497082229/V/delimiter=; +environment/project/0.2056004298.1497082229/V/operation=append +environment/project/0.2056004298.1497082229/V/value=1 +environment/project/0.2056004298.1497082229/append=true +environment/project/0.2056004298.1497082229/appendContributed=true diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/.yotta_ignore b/features/FEATURE_COMMON_PAL/mbed-coap/.yotta_ignore similarity index 100% rename from features/FEATURE_COMMON_PAL/mbed-client-c/.yotta_ignore rename to features/FEATURE_COMMON_PAL/mbed-coap/.yotta_ignore diff --git a/features/FEATURE_COMMON_PAL/mbed-coap/CHANGELOG.md b/features/FEATURE_COMMON_PAL/mbed-coap/CHANGELOG.md new file mode 100644 index 0000000000..f83b67ce0a --- /dev/null +++ b/features/FEATURE_COMMON_PAL/mbed-coap/CHANGELOG.md @@ -0,0 +1,7 @@ +# Change Log + +## [v4.0.0](https://github.com/ARMmbed/mbed-coap/releases/tag/v4.0.0) + +**New feature** + + - Initial release of mbed-coap separated from mbed-client-c diff --git a/features/FEATURE_COMMON_PAL/mbed-coap/LICENSE b/features/FEATURE_COMMON_PAL/mbed-coap/LICENSE new file mode 100644 index 0000000000..8dada3edaf --- /dev/null +++ b/features/FEATURE_COMMON_PAL/mbed-coap/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "{}" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright {yyyy} {name of copyright owner} + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/Makefile b/features/FEATURE_COMMON_PAL/mbed-coap/Makefile similarity index 56% rename from features/FEATURE_COMMON_PAL/mbed-client-c/Makefile rename to features/FEATURE_COMMON_PAL/mbed-coap/Makefile index 7371210d28..2e43e5a173 100644 --- a/features/FEATURE_COMMON_PAL/mbed-client-c/Makefile +++ b/features/FEATURE_COMMON_PAL/mbed-coap/Makefile @@ -1,5 +1,5 @@ # -# Makefile for combined NSDL+COAP library +# Makefile for COAP library # # Define compiler toolchain with CC or PLATFORM variables @@ -15,22 +15,19 @@ # OR (IAR-ARM) # make CC=iccarm -LIB = libnsdl.a +LIB = libmbedcoap.a SRCS := \ - source/libNsdl/src/sn_grs.c \ - source/libNsdl/src/sn_nsdl.c \ - source/libCoap/src/sn_coap_protocol.c \ - source/libCoap/src/sn_coap_parser.c \ - source/libCoap/src/sn_coap_header_check.c \ - source/libCoap/src/sn_coap_builder.c \ + source/sn_coap_protocol.c \ + source/sn_coap_parser.c \ + source/sn_coap_header_check.c \ + source/sn_coap_builder.c \ override CFLAGS += -DVERSION='"$(VERSION)"' -override CFLAGS += -Isource/libNsdl/src/include/ -override CFLAGS += -Isource/libCoap/src/include/ +override CFLAGS += -Isource/include/ SERVLIB_DIR := ../libService override CFLAGS += -I$(SERVLIB_DIR)/libService -override CFLAGS += -Insdl-c/ +override CFLAGS += -I. include ../libService/toolchain_rules.mk @@ -42,4 +39,4 @@ release: .PHONY: deploy_to deploy_to: all - tar --transform 's,^,nsdl-c/,' --append -f $(TO) *.a nsdl-c + tar --transform 's,^,libcoap/,' --append -f $(TO) *.a libcoap diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/Makefile.test b/features/FEATURE_COMMON_PAL/mbed-coap/Makefile.test similarity index 89% rename from features/FEATURE_COMMON_PAL/mbed-client-c/Makefile.test rename to features/FEATURE_COMMON_PAL/mbed-coap/Makefile.test index 38c19e922b..4cc7296c5f 100644 --- a/features/FEATURE_COMMON_PAL/mbed-client-c/Makefile.test +++ b/features/FEATURE_COMMON_PAL/mbed-coap/Makefile.test @@ -1,5 +1,5 @@ # -# Makefile.test for combined NSDL+COAP library unit tests +# Makefile.test for combined COAP library unit tests # @@ -27,13 +27,13 @@ test: $(TESTDIRS) @rm -f lcov/index.xml @find ./ -name '*.gcno' | xargs cp --backup=numbered -t ./coverage/ @find ./ -name '*.gcda' | xargs cp --backup=numbered -t ./coverage/ - @gcovr --object-directory ./coverage --exclude-unreachable-branches -e '.*/builds/.*' -e '.*/test/.*' -e '.*/yotta_modules/.*' -e '.*/stubs/.*' -e '.*/mbed-client-c/.*' -x -o ./lcov/gcovr.xml + @gcovr --object-directory ./coverage --exclude-unreachable-branches -e '.*/builds/.*' -e '.*/test/.*' -e '.*/yotta_modules/.*' -e '.*/stubs/.*' -e '.*/mbed-coap/.*' -x -o ./lcov/gcovr.xml @lcov -d test/. -c -o $(COVERAGEFILE) @lcov -q -r $(COVERAGEFILE) "/usr*" -o $(COVERAGEFILE) @lcov -q -r $(COVERAGEFILE) "/test*" -o $(COVERAGEFILE) @lcov -q -r $(COVERAGEFILE) "/mbed-client-libservice*" -o $(COVERAGEFILE) @genhtml -q $(COVERAGEFILE) --show-details --output-directory lcov/html - @echo mbed-client-c module unit tests built + @echo mbed-coap module unit tests built $(TESTDIRS): @make -C $(@:build-%=%) diff --git a/features/FEATURE_COMMON_PAL/mbed-coap/README.md b/features/FEATURE_COMMON_PAL/mbed-coap/README.md new file mode 100644 index 0000000000..918c822226 --- /dev/null +++ b/features/FEATURE_COMMON_PAL/mbed-coap/README.md @@ -0,0 +1,2 @@ +# mbed-coap +CoAP C library - Builder and Parser for CoAP messages diff --git a/features/FEATURE_COMMON_PAL/mbed-coap/README.txt b/features/FEATURE_COMMON_PAL/mbed-coap/README.txt new file mode 100644 index 0000000000..d3131164f3 --- /dev/null +++ b/features/FEATURE_COMMON_PAL/mbed-coap/README.txt @@ -0,0 +1 @@ +CoAP C library - Builder and Parser for CoAP messages. diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/apache-2.0.txt b/features/FEATURE_COMMON_PAL/mbed-coap/apache-2.0.txt similarity index 100% rename from features/FEATURE_COMMON_PAL/mbed-client-c/apache-2.0.txt rename to features/FEATURE_COMMON_PAL/mbed-coap/apache-2.0.txt diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/doxygen/client-c_doxy b/features/FEATURE_COMMON_PAL/mbed-coap/doxygen/libcoap_doxy similarity index 99% rename from features/FEATURE_COMMON_PAL/mbed-client-c/doxygen/client-c_doxy rename to features/FEATURE_COMMON_PAL/mbed-coap/doxygen/libcoap_doxy index 6762da802b..c1b2c80c13 100644 --- a/features/FEATURE_COMMON_PAL/mbed-client-c/doxygen/client-c_doxy +++ b/features/FEATURE_COMMON_PAL/mbed-coap/doxygen/libcoap_doxy @@ -26,7 +26,7 @@ DOXYFILE_ENCODING = UTF-8 # identify the project. Note that if you do not use Doxywizard you need # to put quotes around the project name if it contains spaces. -PROJECT_NAME = client-c +PROJECT_NAME = libcoap # The PROJECT_NUMBER tag can be used to enter a project or revision number. # This could be handy for archiving the generated documentation or @@ -38,7 +38,7 @@ PROJECT_NUMBER = # for a project that appears at the top of each page and should give viewer # a quick idea about the purpose of the project. Keep the description short. -PROJECT_BRIEF = "mbed Server c Client library" +PROJECT_BRIEF = "CoAP C library" # With the PROJECT_LOGO tag one can specify an logo or icon that is # included in the documentation. The maximum height of the logo should not diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/junit_xsl.xslt b/features/FEATURE_COMMON_PAL/mbed-coap/junit_xsl.xslt similarity index 100% rename from features/FEATURE_COMMON_PAL/mbed-client-c/junit_xsl.xslt rename to features/FEATURE_COMMON_PAL/mbed-coap/junit_xsl.xslt diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/nsdl-c/sn_coap_header.h b/features/FEATURE_COMMON_PAL/mbed-coap/mbed-coap/sn_coap_header.h similarity index 91% rename from features/FEATURE_COMMON_PAL/mbed-client-c/nsdl-c/sn_coap_header.h rename to features/FEATURE_COMMON_PAL/mbed-coap/mbed-coap/sn_coap_header.h index 7e7166ad2f..50efc52bdf 100644 --- a/features/FEATURE_COMMON_PAL/mbed-client-c/nsdl-c/sn_coap_header.h +++ b/features/FEATURE_COMMON_PAL/mbed-coap/mbed-coap/sn_coap_header.h @@ -227,6 +227,60 @@ typedef struct sn_coap_hdr_ { sn_coap_options_list_s *options_list_ptr; /**< Must be set to NULL if not used */ } sn_coap_hdr_s; +/* * * * * * * * * * * * * * */ +/* * * * ENUMERATIONS * * * */ +/* * * * * * * * * * * * * * */ + + +/** + * \brief Used protocol + */ +typedef enum sn_nsdl_capab_ { + SN_NSDL_PROTOCOL_HTTP = 0x01, /**< Unsupported */ + SN_NSDL_PROTOCOL_HTTPS = 0x02, /**< Unsupported */ + SN_NSDL_PROTOCOL_COAP = 0x04 /**< Supported */ +} sn_nsdl_capab_e; + +/* * * * * * * * * * * * * */ +/* * * * STRUCTURES * * * */ +/* * * * * * * * * * * * * */ + + +/** + * \brief Used for creating manually registration message with sn_coap_register() + */ +typedef struct registration_info_ { + uint8_t endpoint_len; + uint8_t endpoint_type_len; + uint16_t links_len; + + uint8_t *endpoint_ptr; /**< Endpoint name */ + uint8_t *endpoint_type_ptr; /**< Endpoint type */ + uint8_t *links_ptr; /**< Resource registration string */ +} registration_info_t; + + +/** + * \brief Address type of given address + */ +typedef enum sn_nsdl_addr_type_ { + SN_NSDL_ADDRESS_TYPE_IPV6 = 0x01, /**< Supported */ + SN_NSDL_ADDRESS_TYPE_IPV4 = 0x02, /**< Supported */ + SN_NSDL_ADDRESS_TYPE_HOSTNAME = 0x03, /**< Unsupported */ + SN_NSDL_ADDRESS_TYPE_NONE = 0xFF +} sn_nsdl_addr_type_e; + +/** + * \brief Address structure of Packet data + */ +typedef struct sn_nsdl_addr_ { + uint8_t addr_len; + sn_nsdl_addr_type_e type; + uint16_t port; + uint8_t *addr_ptr; +} sn_nsdl_addr_s; + + /* * * * * * * * * * * * * * * * * * * * * * */ /* * * * EXTERNAL FUNCTION PROTOTYPES * * * */ /* * * * * * * * * * * * * * * * * * * * * * */ diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/nsdl-c/sn_coap_protocol.h b/features/FEATURE_COMMON_PAL/mbed-coap/mbed-coap/sn_coap_protocol.h similarity index 100% rename from features/FEATURE_COMMON_PAL/mbed-client-c/nsdl-c/sn_coap_protocol.h rename to features/FEATURE_COMMON_PAL/mbed-coap/mbed-coap/sn_coap_protocol.h diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/nsdl-c/sn_config.h b/features/FEATURE_COMMON_PAL/mbed-coap/mbed-coap/sn_config.h similarity index 100% rename from features/FEATURE_COMMON_PAL/mbed-client-c/nsdl-c/sn_config.h rename to features/FEATURE_COMMON_PAL/mbed-coap/mbed-coap/sn_config.h diff --git a/features/FEATURE_COMMON_PAL/mbed-coap/module.json b/features/FEATURE_COMMON_PAL/mbed-coap/module.json new file mode 100644 index 0000000000..f517a9d9f3 --- /dev/null +++ b/features/FEATURE_COMMON_PAL/mbed-coap/module.json @@ -0,0 +1,25 @@ +{ + "name": "mbed-coap", + "version": "4.0.0", + "description": "COAP library", + "keywords": [ + "coap", + "nanostack" + ], + "license": "Apache-2.0", + "extraIncludes": [ + "source/include" + ], + "dependencies": { + "nanostack-libservice": "^3.0.0", + "mbed-trace": ">=0.2.0,<2.0.0", + "nanostack-randlib": "^1.2.0" + }, + "targetDependencies": {}, + "author": "Yogesh Pande ", + "repository": { + "url": "https://github.com/ARMmbed/mbed-coap.git", + "type": "git" + }, + "homepage": "https://github.com/ARMmbed/mbed-coap" +} diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/run_unit_tests.sh b/features/FEATURE_COMMON_PAL/mbed-coap/run_unit_tests.sh similarity index 95% rename from features/FEATURE_COMMON_PAL/mbed-client-c/run_unit_tests.sh rename to features/FEATURE_COMMON_PAL/mbed-coap/run_unit_tests.sh index e503c34e04..797ca2c6ce 100755 --- a/features/FEATURE_COMMON_PAL/mbed-client-c/run_unit_tests.sh +++ b/features/FEATURE_COMMON_PAL/mbed-coap/run_unit_tests.sh @@ -14,7 +14,7 @@ # limitations under the License. echo -echo "Build mbed Client C unit tests" +echo "Build mbed-coap C unit tests" echo yt target x86-linux-native diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/run_unit_tests_with_valgrind.sh b/features/FEATURE_COMMON_PAL/mbed-coap/run_unit_tests_with_valgrind.sh similarity index 100% rename from features/FEATURE_COMMON_PAL/mbed-client-c/run_unit_tests_with_valgrind.sh rename to features/FEATURE_COMMON_PAL/mbed-coap/run_unit_tests_with_valgrind.sh diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/source/libCoap/src/include/sn_coap_header_internal.h b/features/FEATURE_COMMON_PAL/mbed-coap/source/include/sn_coap_header_internal.h similarity index 100% rename from features/FEATURE_COMMON_PAL/mbed-client-c/source/libCoap/src/include/sn_coap_header_internal.h rename to features/FEATURE_COMMON_PAL/mbed-coap/source/include/sn_coap_header_internal.h diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/source/libCoap/src/include/sn_coap_protocol_internal.h b/features/FEATURE_COMMON_PAL/mbed-coap/source/include/sn_coap_protocol_internal.h similarity index 99% rename from features/FEATURE_COMMON_PAL/mbed-client-c/source/libCoap/src/include/sn_coap_protocol_internal.h rename to features/FEATURE_COMMON_PAL/mbed-coap/source/include/sn_coap_protocol_internal.h index 37c790e1f6..dbd161ab81 100644 --- a/features/FEATURE_COMMON_PAL/mbed-client-c/source/libCoap/src/include/sn_coap_protocol_internal.h +++ b/features/FEATURE_COMMON_PAL/mbed-coap/source/include/sn_coap_protocol_internal.h @@ -26,7 +26,7 @@ #include "ns_list.h" #include "sn_coap_header_internal.h" -#include "sn_config.h" +#include "mbed-coap/sn_config.h" #ifdef __cplusplus extern "C" { diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/source/libCoap/src/sn_coap_builder.c b/features/FEATURE_COMMON_PAL/mbed-coap/source/sn_coap_builder.c similarity index 99% rename from features/FEATURE_COMMON_PAL/mbed-client-c/source/libCoap/src/sn_coap_builder.c rename to features/FEATURE_COMMON_PAL/mbed-coap/source/sn_coap_builder.c index 89fba38d96..5a530122a4 100644 --- a/features/FEATURE_COMMON_PAL/mbed-client-c/source/libCoap/src/sn_coap_builder.c +++ b/features/FEATURE_COMMON_PAL/mbed-coap/source/sn_coap_builder.c @@ -30,8 +30,7 @@ #include /* For memset() and memcpy() */ #include "ns_types.h" -#include "sn_nsdl.h" -#include "sn_coap_header.h" +#include "mbed-coap/sn_coap_header.h" #include "sn_coap_header_internal.h" #include "sn_coap_protocol_internal.h" #include "mbed-trace/mbed_trace.h" diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/source/libCoap/src/sn_coap_header_check.c b/features/FEATURE_COMMON_PAL/mbed-coap/source/sn_coap_header_check.c similarity index 97% rename from features/FEATURE_COMMON_PAL/mbed-client-c/source/libCoap/src/sn_coap_header_check.c rename to features/FEATURE_COMMON_PAL/mbed-coap/source/sn_coap_header_check.c index cf0ae768ff..0b48553af7 100644 --- a/features/FEATURE_COMMON_PAL/mbed-client-c/source/libCoap/src/sn_coap_header_check.c +++ b/features/FEATURE_COMMON_PAL/mbed-coap/source/sn_coap_header_check.c @@ -25,9 +25,8 @@ /* * * * INCLUDE FILES * * * */ #include "ns_types.h" -#include "sn_nsdl.h" -#include "sn_coap_header.h" -#include "sn_coap_protocol.h" +#include "mbed-coap/sn_coap_header.h" +#include "mbed-coap/sn_coap_protocol.h" #include "sn_coap_header_internal.h" #include "sn_coap_protocol_internal.h" diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/source/libCoap/src/sn_coap_parser.c b/features/FEATURE_COMMON_PAL/mbed-coap/source/sn_coap_parser.c similarity index 99% rename from features/FEATURE_COMMON_PAL/mbed-client-c/source/libCoap/src/sn_coap_parser.c rename to features/FEATURE_COMMON_PAL/mbed-coap/source/sn_coap_parser.c index be4f538be3..6ec7c68de4 100644 --- a/features/FEATURE_COMMON_PAL/mbed-client-c/source/libCoap/src/sn_coap_parser.c +++ b/features/FEATURE_COMMON_PAL/mbed-coap/source/sn_coap_parser.c @@ -31,9 +31,8 @@ #include /* For memset() and memcpy() */ #include "ns_types.h" -#include "sn_nsdl.h" -#include "sn_coap_header.h" -#include "sn_coap_protocol.h" +#include "mbed-coap/sn_coap_header.h" +#include "mbed-coap/sn_coap_protocol.h" #include "sn_coap_header_internal.h" #include "sn_coap_protocol_internal.h" diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/source/libCoap/src/sn_coap_protocol.c b/features/FEATURE_COMMON_PAL/mbed-coap/source/sn_coap_protocol.c similarity index 99% rename from features/FEATURE_COMMON_PAL/mbed-client-c/source/libCoap/src/sn_coap_protocol.c rename to features/FEATURE_COMMON_PAL/mbed-coap/source/sn_coap_protocol.c index 23b9c21673..0612d16b25 100644 --- a/features/FEATURE_COMMON_PAL/mbed-client-c/source/libCoap/src/sn_coap_protocol.c +++ b/features/FEATURE_COMMON_PAL/mbed-coap/source/sn_coap_protocol.c @@ -36,8 +36,7 @@ #endif #include "ns_types.h" -#include "sn_nsdl.h" -#include "sn_coap_protocol.h" +#include "mbed-coap/sn_coap_protocol.h" #include "sn_coap_header_internal.h" #include "sn_coap_protocol_internal.h" #include "randLIB.h" diff --git a/features/FEATURE_COMMON_PAL/mbed-client-c/xsl_script.sh b/features/FEATURE_COMMON_PAL/mbed-coap/xsl_script.sh similarity index 100% rename from features/FEATURE_COMMON_PAL/mbed-client-c/xsl_script.sh rename to features/FEATURE_COMMON_PAL/mbed-coap/xsl_script.sh diff --git a/features/nanostack/FEATURE_NANOSTACK/coap-service/.yotta_ignore b/features/nanostack/FEATURE_NANOSTACK/coap-service/.yotta_ignore deleted file mode 100644 index ab97c1af02..0000000000 --- a/features/nanostack/FEATURE_NANOSTACK/coap-service/.yotta_ignore +++ /dev/null @@ -1,4 +0,0 @@ -unittest/* -test/* -doxygen/* - diff --git a/features/nanostack/FEATURE_NANOSTACK/coap-service/Makefile b/features/nanostack/FEATURE_NANOSTACK/coap-service/Makefile index b392f24e7d..920d4773d5 100644 --- a/features/nanostack/FEATURE_NANOSTACK/coap-service/Makefile +++ b/features/nanostack/FEATURE_NANOSTACK/coap-service/Makefile @@ -24,8 +24,9 @@ override CFLAGS += -I$(SERVLIB_DIR)/libService/ NANOSTACK_DIR := ../nanostack override CFLAGS += -I$(NANOSTACK_DIR)/nanostack/ -NSDLC_DIR := ../nsdl-c -override CFLAGS += -I$(NSDLC_DIR)/nsdl-c +COAP_DIR := ../mbed-coap +override CFLAGS += -I$(COAP_DIR)/ + EVENTLOOP_DIR := ../event-loop override CFLAGS += -I$(EVENTLOOP_DIR)/nanostack-event-loop/ diff --git a/features/nanostack/FEATURE_NANOSTACK/coap-service/coap-service/coap_service_api.h b/features/nanostack/FEATURE_NANOSTACK/coap-service/coap-service/coap_service_api.h index 9924d1f311..8a9a1fd754 100644 --- a/features/nanostack/FEATURE_NANOSTACK/coap-service/coap-service/coap_service_api.h +++ b/features/nanostack/FEATURE_NANOSTACK/coap-service/coap-service/coap_service_api.h @@ -26,7 +26,7 @@ extern "C" { #include #include "ns_types.h" -#include "sn_coap_header.h" +#include "mbed-coap/sn_coap_header.h" #include "ns_address.h" /** diff --git a/features/nanostack/FEATURE_NANOSTACK/coap-service/module.json b/features/nanostack/FEATURE_NANOSTACK/coap-service/module.json deleted file mode 100644 index 06a5aa0e15..0000000000 --- a/features/nanostack/FEATURE_NANOSTACK/coap-service/module.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "name": "coap-service", - "version": "4.0.3", - "description": "CoAP Service library", - "keywords": [ - "coap", - "service" - ], - "repository": { - "url": "git@github.com:ARMmbed/coap-service.git", - "type": "git" - }, - "homepage": "https://github.com/ARMmbed/coap-service", - "license": "Apache-2.0", - "extraIncludes": [ - "coap-service", - "nanostack-event-loop", - "source/include" - ], - "dependencies": { - "nanostack-libservice": "^3.0.0", - "mbed-client-c": "^3.0.0", - "sal-stack-nanostack": "^5.0.0", - "mbedtls": "^2.0.0" - }, - "targetDependencies": {} -} diff --git a/features/nanostack/FEATURE_NANOSTACK/coap-service/source/coap_connection_handler.c b/features/nanostack/FEATURE_NANOSTACK/coap-service/source/coap_connection_handler.c index e6e4664d84..b04e127d51 100644 --- a/features/nanostack/FEATURE_NANOSTACK/coap-service/source/coap_connection_handler.c +++ b/features/nanostack/FEATURE_NANOSTACK/coap-service/source/coap_connection_handler.c @@ -32,7 +32,7 @@ typedef struct internal_socket_s { int16_t data_len; uint8_t *data; - int8_t socket; + int8_t socket; //positive value = socket id, negative value virtual socket id bool real_socket; uint8_t usage_counter; bool is_secure; @@ -46,6 +46,11 @@ static NS_LIST_DEFINE(socket_list, internal_socket_t, link); static void timer_cb(void* param); +static void recv_sckt_msg(void *cb_res); +#ifdef COAP_SECURITY_AVAILABLE +static void secure_recv_sckt_msg(void *cb_res); +#endif + #define TIMER_STATE_CANCELLED -1 /* cancelled */ #define TIMER_STATE_NO_EXPIRY 0 /* none of the delays is expired */ #define TIMER_STATE_INT_EXPIRY 1 /* the intermediate delay only is expired */ @@ -92,6 +97,17 @@ static secure_session_t *secure_session_find_by_timer_id(int8_t timer_id) return this; } +static bool is_secure_session_valid(secure_session_t *session) +{ + secure_session_t *this = NULL; + ns_list_foreach(secure_session_t, cur_ptr, &secure_session_list) { + if (cur_ptr == session) { + return true; + } + } + return false; +} + static void secure_session_delete(secure_session_t *this) { if (this) { @@ -111,6 +127,17 @@ static void secure_session_delete(secure_session_t *this) return; } +static int8_t virtual_socket_id_allocate() +{ + int8_t new_virtual_socket_id = -1; // must not overlap with real socket id's + ns_list_foreach(internal_socket_t, cur_ptr, &socket_list) { + if (cur_ptr->socket <= new_virtual_socket_id) { + new_virtual_socket_id = cur_ptr->socket - 1; + } + } + return new_virtual_socket_id; +} + static secure_session_t *secure_session_create(internal_socket_t *parent, const uint8_t *address_ptr, uint16_t port) { if(!address_ptr){ @@ -195,11 +222,6 @@ static secure_session_t *secure_session_find(internal_socket_t *parent, const ui return this; } - - -static void recv_sckt_msg(void *cb_res); -static void secure_recv_sckt_msg(void *cb_res); - static internal_socket_t *int_socket_create(uint16_t listen_port, bool use_ephemeral_port, bool is_secure, bool real_socket, bool bypassSec) { internal_socket_t *this = ns_dyn_mem_alloc(sizeof(internal_socket_t)); @@ -245,8 +267,8 @@ static internal_socket_t *int_socket_create(uint16_t listen_port, bool use_ephem // Set socket option to receive packet info socket_setsockopt(this->socket, SOCKET_IPPROTO_IPV6, SOCKET_IPV6_RECVPKTINFO, &(const bool) {1}, sizeof(bool)); - }else{ - this->socket = -1; + } else { + this->socket = virtual_socket_id_allocate(); } ns_list_add_to_start(&socket_list, this); @@ -300,16 +322,18 @@ static internal_socket_t *int_socket_find(uint16_t port, bool is_secure, bool is return this; } -static int8_t send_to_real_socket(int8_t socket_id, const ns_address_t *address, const uint8_t source_address[static 16], const void *buffer, uint16_t length) +static int send_to_real_socket(int8_t socket_id, const ns_address_t *address, const uint8_t source_address[static 16], const void *buffer, uint16_t length) { - ns_iovec_t msg_iov; - ns_msghdr_t msghdr; - - msghdr.msg_name = (void*)address; - msghdr.msg_namelen = sizeof(ns_address_t); - msghdr.msg_iov = &msg_iov; - msghdr.msg_iovlen = 1; - msghdr.flags = 0; + ns_iovec_t msg_iov = { + .iov_base = (void *) buffer, + .iov_len = length + }; + ns_msghdr_t msghdr = { + .msg_name = (void *) address, + .msg_namelen = sizeof(ns_address_t), + .msg_iov = &msg_iov, + .msg_iovlen = 1 + }; if (memcmp(source_address, ns_in6addr_any, 16)) { uint8_t ancillary_databuffer[NS_CMSG_SPACE(sizeof(ns_in6_pktinfo_t))]; @@ -328,14 +352,8 @@ static int8_t send_to_real_socket(int8_t socket_id, const ns_address_t *address, pktinfo = (ns_in6_pktinfo_t*)NS_CMSG_DATA(cmsg); pktinfo->ipi6_ifindex = 0; memcpy(pktinfo->ipi6_addr, source_address, 16); - } else { - msghdr.msg_control = NULL; - msghdr.msg_controllen = 0; } - msg_iov.iov_base = (void *)buffer; - msg_iov.iov_len = length; - return socket_sendmsg(socket_id, &msghdr, 0); } @@ -364,7 +382,7 @@ static int secure_session_sendto(int8_t socket_id, void *handle, const void *buf //For some reason socket_sendto returns 0 in success, while other socket impls return number of bytes sent!!! //TODO: check if address_ptr is valid and use that instead if it is - int8_t ret = send_to_real_socket(sock->socket, &session->remote_host, session->local_address, buf, len); + int ret = send_to_real_socket(sock->socket, &session->remote_host, session->local_address, buf, len); if (ret < 0) { return ret; } @@ -395,7 +413,8 @@ static int secure_session_recvfrom(int8_t socket_id, unsigned char *buf, size_t static void timer_cb(void *param) { secure_session_t *sec = param; - if( sec ){ + + if( sec && is_secure_session_valid(sec)){ if(sec->timer.fin_ms > sec->timer.int_ms){ /* Intermediate expiry */ sec->timer.fin_ms -= sec->timer.int_ms; @@ -483,7 +502,6 @@ static int read_data(socket_callback_t *sckt_data, internal_socket_t *sock, ns_a msghdr.msg_iovlen = 1; msghdr.msg_control = ancillary_databuffer; msghdr.msg_controllen = sizeof(ancillary_databuffer); - msghdr.flags = 0; msg_iov.iov_base = sock->data; msg_iov.iov_len = sckt_data->d_len; @@ -511,6 +529,8 @@ static int read_data(socket_callback_t *sckt_data, internal_socket_t *sock, ns_a } else { goto return_failure; } + } else { + goto return_failure; } return 0; @@ -524,6 +544,7 @@ return_failure: } +#ifdef COAP_SECURITY_AVAILABLE static void secure_recv_sckt_msg(void *cb_res) { socket_callback_t *sckt_data = cb_res; @@ -606,6 +627,7 @@ static void secure_recv_sckt_msg(void *cb_res) } } } +#endif static void recv_sckt_msg(void *cb_res) { diff --git a/features/nanostack/FEATURE_NANOSTACK/coap-service/source/coap_message_handler.c b/features/nanostack/FEATURE_NANOSTACK/coap-service/source/coap_message_handler.c index c4162b8fb1..72c9e86af5 100644 --- a/features/nanostack/FEATURE_NANOSTACK/coap-service/source/coap_message_handler.c +++ b/features/nanostack/FEATURE_NANOSTACK/coap-service/source/coap_message_handler.c @@ -6,7 +6,7 @@ #include "nsdynmemLIB.h" #include "coap_service_api_internal.h" #include "coap_message_handler.h" -#include "sn_coap_protocol.h" +#include "mbed-coap/sn_coap_protocol.h" #include "socket_api.h" #include "ns_types.h" #include "ns_list.h" diff --git a/features/nanostack/FEATURE_NANOSTACK/coap-service/source/coap_security_handler.c b/features/nanostack/FEATURE_NANOSTACK/coap-service/source/coap_security_handler.c index 5b4326a3bc..6113cf96ae 100644 --- a/features/nanostack/FEATURE_NANOSTACK/coap-service/source/coap_security_handler.c +++ b/features/nanostack/FEATURE_NANOSTACK/coap-service/source/coap_security_handler.c @@ -75,12 +75,19 @@ static int get_timer( void *sec_obj ); static int coap_security_handler_configure_keys( coap_security_t *sec, coap_security_keys_t keys ); int entropy_poll( void *data, unsigned char *output, size_t len, size_t *olen ); + //Point these back to M2MConnectionHandler!!! int f_send( void *ctx, const unsigned char *buf, size_t len ); int f_recv(void *ctx, unsigned char *buf, size_t len); static int coap_security_handler_init(coap_security_t *sec){ const char *pers = "dtls_client"; +#ifdef COAP_SERVICE_PROVIDE_STRONG_ENTROPY_SOURCE + const int entropy_source_type = MBEDTLS_ENTROPY_SOURCE_STRONG; +#else + const int entropy_source_type = MBEDTLS_ENTROPY_SOURCE_WEAK; +#endif + mbedtls_ssl_init( &sec->_ssl ); mbedtls_ssl_config_init( &sec->_conf ); mbedtls_ctr_drbg_init( &sec->_ctr_drbg ); @@ -97,10 +104,8 @@ static int coap_security_handler_init(coap_security_t *sec){ sec->_is_started = false; - //TODO: Must have at least 1 strong entropy source, otherwise DTLS will fail. - //This is NOT strong even we say it is! if( mbedtls_entropy_add_source( &sec->_entropy, entropy_poll, NULL, - 128, 1 ) < 0 ){ + 128, entropy_source_type ) < 0 ){ return -1; } diff --git a/features/nanostack/FEATURE_NANOSTACK/coap-service/source/coap_service_api.c b/features/nanostack/FEATURE_NANOSTACK/coap-service/source/coap_service_api.c index d6c330202b..3341615131 100644 --- a/features/nanostack/FEATURE_NANOSTACK/coap-service/source/coap_service_api.c +++ b/features/nanostack/FEATURE_NANOSTACK/coap-service/source/coap_service_api.c @@ -10,8 +10,7 @@ #include "ns_list.h" #include "ns_trace.h" #include "nsdynmemLIB.h" -#include "sn_nsdl.h" -#include "sn_coap_header.h" +#include "mbed-coap/sn_coap_header.h" #include "coap_service_api.h" #include "coap_message_handler.h" #include "eventOS_event.h" @@ -127,14 +126,14 @@ static uint8_t coap_tx_function(uint8_t *data_ptr, uint16_t data_len, sn_nsdl_ad ns_address_t dest_addr; if (!transaction_ptr || !data_ptr) { - return -1; + return 0; } tr_debug("Service %d, CoAP TX Function - mid: %d", transaction_ptr->service_id, common_read_16_bit(data_ptr + 2)); this = service_find(transaction_ptr->service_id); if (!this) { - return -1; + return 0; } memcpy(&(dest_addr.address), address_ptr->addr_ptr, 16); @@ -235,7 +234,7 @@ static int send_cb(int8_t socket_id, const uint8_t address[static 16], uint16_t { coap_service_t *this = service_find_by_socket(socket_id); if (this && this->virtual_socket_send_cb) { - tr_debug("send to virtual socket"); + tr_debug("send to virtual socket, service: %d", this->service_id); return this->virtual_socket_send_cb(this->service_id, (uint8_t*)address, port, data_ptr, data_len); } return -1; @@ -380,7 +379,7 @@ int16_t coap_service_virtual_socket_recv(int8_t service_id, uint8_t source_addr_ int16_t coap_service_virtual_socket_set_cb(int8_t service_id, coap_service_virtual_socket_send_cb *send_method_ptr) { coap_service_t *this = service_find(service_id); - tr_debug("register virtual socket cb"); + tr_debug("register virtual socket cb to service %d", service_id); if (!this) { return -1; } diff --git a/features/nanostack/FEATURE_NANOSTACK/coap-service/source/include/coap_message_handler.h b/features/nanostack/FEATURE_NANOSTACK/coap-service/source/include/coap_message_handler.h index 2637ee201e..6cd4d8f7d6 100644 --- a/features/nanostack/FEATURE_NANOSTACK/coap-service/source/include/coap_message_handler.h +++ b/features/nanostack/FEATURE_NANOSTACK/coap-service/source/include/coap_message_handler.h @@ -20,8 +20,7 @@ #define __COAP_MESSAGE_HANDLER_H__ #include -#include "sn_coap_header.h" -#include "sn_nsdl.h" +#include "mbed-coap/sn_coap_header.h" #include "ns_list.h" #define TRANSACTION_LIFETIME 180 diff --git a/features/nanostack/FEATURE_NANOSTACK/coap-service/source/include/coap_security_handler.h b/features/nanostack/FEATURE_NANOSTACK/coap-service/source/include/coap_security_handler.h index a2c8bfcb24..525f3c38d6 100644 --- a/features/nanostack/FEATURE_NANOSTACK/coap-service/source/include/coap_security_handler.h +++ b/features/nanostack/FEATURE_NANOSTACK/coap-service/source/include/coap_security_handler.h @@ -18,9 +18,7 @@ #ifndef __COAP_SECURITY_HANDLER_H__ #define __COAP_SECURITY_HANDLER_H__ -#include -#include -#include +#include "ns_types.h" #ifdef NS_USE_EXTERNAL_MBED_TLS #include "mbedtls/ssl.h" @@ -99,6 +97,8 @@ const void *coap_security_handler_keyblock(const coap_security_t *sec); #else +NS_DUMMY_DEFINITIONS_OK + /* Dummy definitions, including needed error codes */ #define MBEDTLS_ERR_SSL_TIMEOUT (-1) #define MBEDTLS_ERR_SSL_WANT_READ (-2) diff --git a/features/nanostack/FEATURE_NANOSTACK/coap-service/test/coap-service/unittest/coap_service_api/test_coap_service_api.c b/features/nanostack/FEATURE_NANOSTACK/coap-service/test/coap-service/unittest/coap_service_api/test_coap_service_api.c index f1937770dc..68eead7a92 100644 --- a/features/nanostack/FEATURE_NANOSTACK/coap-service/test/coap-service/unittest/coap_service_api/test_coap_service_api.c +++ b/features/nanostack/FEATURE_NANOSTACK/coap-service/test/coap-service/unittest/coap_service_api/test_coap_service_api.c @@ -252,22 +252,22 @@ bool test_coap_callbacks() addr.addr_len = 2; addr.port = 4; addr.addr_ptr = &data; - if( 255 != coap_message_handler_stub.coap_ptr->sn_coap_tx_callback(NULL, 0, &addr, NULL)) + if( 0 != coap_message_handler_stub.coap_ptr->sn_coap_tx_callback(NULL, 0, &addr, NULL)) return false; coap_transaction_t *tr = (coap_transaction_t *)malloc(sizeof(coap_transaction_t)); memset(tr, 0, sizeof(coap_transaction_t)); - if( 255 != coap_message_handler_stub.coap_ptr->sn_coap_tx_callback(&data, 0, &addr, tr)) + if( 0 != coap_message_handler_stub.coap_ptr->sn_coap_tx_callback(&data, 0, &addr, tr)) return false; tr->service_id = 1; thread_conn_handler_stub.int_value = -2; - if( 255 != coap_message_handler_stub.coap_ptr->sn_coap_tx_callback(&data, 0, &addr, tr)) + if( 0 != coap_message_handler_stub.coap_ptr->sn_coap_tx_callback(&data, 0, &addr, tr)) return false; nsdynmemlib_stub.returnCounter = 1; - if( 255 != coap_message_handler_stub.coap_ptr->sn_coap_tx_callback(&data, 2, &addr, tr)) + if( 0 != coap_message_handler_stub.coap_ptr->sn_coap_tx_callback(&data, 2, &addr, tr)) return false; free(tr->data_ptr); diff --git a/features/nanostack/FEATURE_NANOSTACK/coap-service/test/coap-service/unittest/makefile_defines.txt b/features/nanostack/FEATURE_NANOSTACK/coap-service/test/coap-service/unittest/makefile_defines.txt index b3346512cb..3e0bc1b91b 100755 --- a/features/nanostack/FEATURE_NANOSTACK/coap-service/test/coap-service/unittest/makefile_defines.txt +++ b/features/nanostack/FEATURE_NANOSTACK/coap-service/test/coap-service/unittest/makefile_defines.txt @@ -15,15 +15,16 @@ INCLUDE_DIRS =\ ../../../../yotta_modules/nanostack-randlib/mbed-client-randlib/ \ ../../../../yotta_modules/nanostack-libservice/ \ ../../../../yotta_modules/nanostack-libservice/mbed-client-libservice/ \ - ../../../../yotta_modules/mbed-client-c/nsdl-c/ \ - ../../../../yotta_modules/mbed-client-c/source/libCoap/src/include/ \ + ../../../../yotta_modules/mbed-coap/ \ + ../../../../yotta_modules/mbed-coap/source/include/ \ ../../../../yotta_modules/sal-stack-nanostack-eventloop/nanostack-event-loop/ \ ../../../../yotta_modules/sal-stack-nanostack-eventloop/source/ \ ../../../../yotta_modules/mbed-trace/ \ ../../../../../nanostack/nanostack/\ ../../../../../libService/libService/\ - ../../../../../nsdl-c/nsdl-c/\ - ../../../../../nsdl-c/source/libCoap/src/include/\ + ../../../../../mbed-coap/\ + ../../../../../mbed-coap/mbed-coap\ + ../../../../../mbed-coap/source/include/\ ../../../../../event-loop/nanostack-event-loop/\ ../../../../../event-loop/source/ \ ../../../../../mbedtls/include/ \ diff --git a/features/nanostack/FEATURE_NANOSTACK/coap-service/test/coap-service/unittest/stub/coap_service_api_stub.c b/features/nanostack/FEATURE_NANOSTACK/coap-service/test/coap-service/unittest/stub/coap_service_api_stub.c index ba728df32c..29d6c59a3b 100644 --- a/features/nanostack/FEATURE_NANOSTACK/coap-service/test/coap-service/unittest/stub/coap_service_api_stub.c +++ b/features/nanostack/FEATURE_NANOSTACK/coap-service/test/coap-service/unittest/stub/coap_service_api_stub.c @@ -8,7 +8,6 @@ #include "ns_list.h" #include "ns_trace.h" #include "nsdynmemLIB.h" -#include "sn_nsdl.h" #include "sn_coap_header.h" #include "coap_service_api.h" #include "coap_message_handler.h" diff --git a/features/nanostack/FEATURE_NANOSTACK/coap-service/test/coap-service/unittest/stub/eventOS_event_stub.c b/features/nanostack/FEATURE_NANOSTACK/coap-service/test/coap-service/unittest/stub/eventOS_event_stub.c index b050d35078..e2a532e01d 100644 --- a/features/nanostack/FEATURE_NANOSTACK/coap-service/test/coap-service/unittest/stub/eventOS_event_stub.c +++ b/features/nanostack/FEATURE_NANOSTACK/coap-service/test/coap-service/unittest/stub/eventOS_event_stub.c @@ -9,11 +9,6 @@ eventOs_event_stub_def eventOs_event_stub; -int8_t eventOS_event_send(arm_event_s *event) -{ - return eventOs_event_stub.int8_value; -} - int8_t eventOS_event_handler_create(void (*handler_func_ptr)(arm_event_s *), uint8_t init_event_type) { eventOs_event_stub.event_ptr = handler_func_ptr; diff --git a/features/nanostack/FEATURE_NANOSTACK/coap-service/test/coap-service/unittest/stub/sn_coap_parser_stub.c b/features/nanostack/FEATURE_NANOSTACK/coap-service/test/coap-service/unittest/stub/sn_coap_parser_stub.c index d177012671..a1365aa9cb 100644 --- a/features/nanostack/FEATURE_NANOSTACK/coap-service/test/coap-service/unittest/stub/sn_coap_parser_stub.c +++ b/features/nanostack/FEATURE_NANOSTACK/coap-service/test/coap-service/unittest/stub/sn_coap_parser_stub.c @@ -12,7 +12,6 @@ */ #include "ns_types.h" -#include "sn_nsdl.h" #include "sn_coap_protocol.h" #include "sn_coap_parser_stub.h" diff --git a/features/nanostack/FEATURE_NANOSTACK/coap-service/test/coap-service/unittest/stub/sn_coap_protocol_stub.c b/features/nanostack/FEATURE_NANOSTACK/coap-service/test/coap-service/unittest/stub/sn_coap_protocol_stub.c index 86e4d7f097..a7f87e7931 100644 --- a/features/nanostack/FEATURE_NANOSTACK/coap-service/test/coap-service/unittest/stub/sn_coap_protocol_stub.c +++ b/features/nanostack/FEATURE_NANOSTACK/coap-service/test/coap-service/unittest/stub/sn_coap_protocol_stub.c @@ -11,7 +11,6 @@ #endif #include "ns_types.h" -#include "sn_nsdl.h" #include "sn_coap_protocol.h" #include "sn_coap_header_internal.h" #include "sn_coap_protocol_internal.h" diff --git a/features/nanostack/FEATURE_NANOSTACK/coap-service/test/coap-service/unittest/stub/socket_api_stub.c b/features/nanostack/FEATURE_NANOSTACK/coap-service/test/coap-service/unittest/stub/socket_api_stub.c index 521a9c204d..8fa094f49d 100644 --- a/features/nanostack/FEATURE_NANOSTACK/coap-service/test/coap-service/unittest/stub/socket_api_stub.c +++ b/features/nanostack/FEATURE_NANOSTACK/coap-service/test/coap-service/unittest/stub/socket_api_stub.c @@ -58,14 +58,6 @@ int8_t socket_bind(int8_t socket, const ns_address_t *address) return socket_api_stub.int8_value; } -int8_t socket_send(int8_t socket, uint8_t *buffer, uint16_t length) -{ - if( socket_api_stub.counter >= 0){ - return socket_api_stub.values[socket_api_stub.counter--]; - } - - return socket_api_stub.int8_value; -} int16_t socket_read(int8_t socket, ns_address_t *address, uint8_t *buffer, uint16_t length) { if( address ){ @@ -78,15 +70,7 @@ int16_t socket_read(int8_t socket, ns_address_t *address, uint8_t *buffer, uint1 return socket_api_stub.int8_value; } -int8_t socket_sendto(int8_t socket, ns_address_t *address, uint8_t *buffer, uint16_t length) -{ - if( socket_api_stub.counter >= 0){ - return socket_api_stub.values[socket_api_stub.counter--]; - } - - return socket_api_stub.int8_value; -} -int8_t socket_read_session_address(int8_t socket, ns_address_t *address) +int8_t socket_getpeername(int8_t socket, ns_address_t *address) { if( socket_api_stub.counter >= 0){ return socket_api_stub.values[socket_api_stub.counter--]; @@ -110,8 +94,7 @@ int8_t socket_getsockopt(int8_t socket, uint8_t level, uint8_t opt_name, void *o return socket_api_stub.int8_value; } - -int8_t socket_sendmsg(int8_t socket, const ns_msghdr_t *msg, int flags) +int16_t socket_sendmsg(int8_t socket, const ns_msghdr_t *msg, int flags) { if( socket_api_stub.counter >= 0){ return socket_api_stub.values[socket_api_stub.counter--];