Separating CoAP library from mbed-client-c

This commit includes
 - Removing CoAP sources from mbed-client-c to its own repository.
 - mbed-client-c is moved outside of mbed-os source tree because it is used by mbed-client, so
   it will be part of mbed-client offering.
 - CoAP sources are used by coap-service which is a part of nanostack deliveries hence coap now existing
   as independent module under mbed-coap.

 - Commit handles the interdepdency of coap-service with mbed-client-c because of coap sources, coap-service
   header files are now fixed to point to right header directory.
pull/3789/head
Yogesh Pande 2017-02-16 19:08:28 +02:00
parent 21b91c794e
commit f57433a00a
113 changed files with 652 additions and 21967 deletions

View File

@ -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 <jaakko.kukkohovi@arm.com>
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ö <tero.jaasko@arm.com>
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ö <tero.jaasko@arm.com>
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ö <tero.jaasko@arm.com>
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 <jaakko.kukkohovi@arm.com>
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 <simo.sillankorva@arm.com>
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 <antti.yli-tokola@arm.com>
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 <antti.yli-tokola@arm.com>
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 <antti.kauppila@arm.com>
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 <antti.yli-tokola@arm.com>
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 <antti.yli-tokola@arm.com>
Date: Wed Nov 9 08:20:29 2016 +0200
Replace unnecessary started flag with len variable.
commit 1deac48ddb51a9e9d85ecb682b9b82c4072b5c44
Author: Antti Yli-Tokola <antti.yli-tokola@arm.com>
Date: Tue Nov 8 14:20:34 2016 +0200
Fix CoAP option building
commit fc1f9eb790d08306ee435dd3a8452cfc82d7d740
Merge: 59be2f1 316a9db
Author: Yogesh Pande <yogpan01@users.noreply.github.com>
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ö <tero.jaasko@arm.com>
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ö <tero.jaasko@arm.com>
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ö <tero.jaasko@arm.com>
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ö <tero.jaasko@arm.com>
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ö <tero.jaasko@arm.com>
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 <antti.yli-tokola@arm.com>
Date: Thu Sep 29 10:52:54 2016 +0300
version v3.0.3
commit 3b89e2a465c3876cc184c92c72bdbe66193502c7
Merge: 58f712b 4369a46
Author: Antti Yli-Tokola <antti.yli-tokola@arm.com>
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 <antti.yli-tokola@arm.com>
Date: Thu Sep 29 09:19:36 2016 +0300
Fix one failing unit test
commit 72bfc3e7199d040b8bfa637e1840a0869f786231
Author: Tero Heinonen <tero.heinonen@arm.com>
Date: Wed Sep 28 13:54:56 2016 +0300
Enable duplicate message detection
commit 852c1f642afe7eb342016c76807d8b10a0fe7504
Author: Tero Heinonen <tero.heinonen@arm.com>
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 <Yogesh.Pande@arm.com>
Date: Sat Sep 24 15:04:36 2016 +0300
version v3.0.2
commit 39d5e98025f3d8067cea85c4a06470e0e9374812
Merge: cf4c119 31d6566
Author: Yogesh Pande <yogpan01@users.noreply.github.com>
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 <Yogesh.Pande@arm.com>
Date: Sat Sep 24 12:53:47 2016 +0300
Fixing valgrind with unit tests
commit a95a90a31e8f6123d14df84688b4e2e2f32e5507
Author: Yogesh Pande <Yogesh.Pande@arm.com>
Date: Sat Sep 24 12:00:44 2016 +0300
Fixing valgrind memory leaks for unit tests
commit 248fc713a4303cb1f724d10f4aa6d68933bb5aed
Author: Yogesh Pande <Yogesh.Pande@arm.com>
Date: Sat Sep 24 11:32:01 2016 +0300
Fix for failing unit tests
commit cec0980b4ccff9708cd0130fea936a69839739b8
Merge: cf09b2b cf4c119
Author: Yogesh Pande <yogpan01@users.noreply.github.com>
Date: Thu Sep 22 18:02:39 2016 +0300
Merge branch 'master' into config-mechanism
commit cf4c1196520d64bf863b39efefc663ee60e58c61
Merge: 330a16b f5f15cc
Author: Antti Yli-Tokola <antti.yli-tokola@arm.com>
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 <antti.yli-tokola@arm.com>
Date: Thu Sep 22 12:30:50 2016 +0300
Revert "Enable message duplication by default"
commit cf09b2b6233bf897a17bdb0102962947df87f4ae
Author: Yogesh Pande <Yogesh.Pande@arm.com>
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 <Yogesh.Pande@arm.com>
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 <antti.yli-tokola@arm.com>
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 <antti.yli-tokola@arm.com>
Date: Wed Sep 21 12:02:32 2016 +0300
Merge branch 'master' into resend_flags
commit b7d909eca1c2259453dbe9c094b8a0c53d638fea
Merge: 7f0eaea ad3b468
Author: Antti Yli-Tokola <antti.yli-tokola@arm.com>
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 <antti.yli-tokola@arm.com>
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 <antti.yli-tokola@arm.com>
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 <antti.kauppila@arm.com>
Date: Thu Sep 15 11:22:59 2016 +0300
version v3.0.1
commit 82677cffcafb06111b81f750782a9f5f5dc2fd21
Author: Antti Kauppila <antti.kauppila@arm.com>
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 <antti.yli-tokola@arm.com>
Date: Thu Sep 15 10:30:56 2016 +0300
version v3.0.0
commit b273d51fd6f38b1938d8e2a942805dfdde3a59ef
Merge: 45e836b 4fdf010
Author: Antti Yli-Tokola <antti.yli-tokola@arm.com>
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 <antti.yli-tokola@arm.com>
Date: Thu Sep 15 10:18:53 2016 +0300
Remove commented out code
commit 60a92da6e9315740cff41ec301895c8803a480c0
Author: Antti Yli-Tokola <antti.yli-tokola@arm.com>
Date: Wed Sep 14 15:14:28 2016 +0300
Fix payload size calculation when blockwise is needed
commit ac4dcda4d59821a6434205b26b4a4ea88e37f7b4
Author: Antti Kauppila <antti.kauppila@arm.com>
Date: Wed Sep 14 10:00:09 2016 +0300
Blockwise transfer handling improved, fixes issue IOTCLT-1004
+ Unittests updated
commit 2352759cb8b927bec229d4ac1bbe83472ceb39f2
Author: Antti Kauppila <antti.kauppila@arm.com>
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 <antti.kauppila@arm.com>
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 <antti.kauppila@arm.com>
Date: Fri Sep 2 16:29:30 2016 +0300
Added put method, rearranged structs, updated unittests
commit 754f4c015d675e5e0d7ef777e914df3910bb7320
Author: Antti Kauppila <antti.kauppila@arm.com>
Date: Thu Sep 1 16:08:13 2016 +0300
Unittests updated & small fixes
commit 626ac227c3de1837b7667c69087f5659dfdbd436
Author: Kevin Bracey <kevin.bracey@arm.com>
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 <kevin.bracey@arm.com>
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 <kevin.bracey@arm.com>
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 <kevin.bracey@arm.com>
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 <kevin.bracey@arm.com>
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 <kevin.bracey@arm.com>
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 <kevin.bracey@arm.com>
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 <teemu.takaluoma@arm.com>
Date: Mon Sep 5 15:27:34 2016 +0300
version v2.9.0
commit 9022e05adb231fd8f619bb4fc2b0f05da99413a9
Merge: ec0b281 87dfd6f
Author: Teemu Takaluoma <teemu.takaluoma@arm.com>
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 <teemu.takaluoma@arm.com>
Date: Mon Sep 5 08:51:21 2016 +0300
add unit test
commit b8ddefdcbfb58d355e170e8411eebc23ffe3c25c
Author: Teemu Takaluoma <teemu.takaluoma@arm.com>
Date: Sat Sep 3 14:14:28 2016 +0300
refactor address handling
commit d89b6266fd52322fd7beafcd51365c980afbff05
Author: Teemu Takaluoma <teemu.takaluoma@arm.com>
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 <antti.yli-tokola@arm.com>
Date: Fri Aug 12 14:33:56 2016 +0300
version v2.8.0
commit 5ab0f01c31d6551547388307e0c0cfda272b611e
Author: Antti Yli-Tokola <antti.yli-tokola@arm.com>
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 <antti.yli-tokola@arm.com>
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 <tero.heinonen@arm.com>
Date: Fri Aug 5 11:48:17 2016 +0300
Added API for deleting one message from resending
queue.

View File

@ -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

View File

@ -1,2 +0,0 @@
The mbed Device C Client Library provides a simple and efficient way to create mbed Device Client in
C.

View File

@ -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": {}
}

View File

@ -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

View File

@ -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_ */

View File

@ -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_ */

View File

@ -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_ */

View File

@ -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_ */

View File

@ -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}
)

View File

@ -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 <mach/port.h>
#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_ */

View File

@ -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 <arpa/inet.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <pthread.h>
#include <string.h>
#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);
}

View File

@ -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 <arpa/inet.h>
#include <netinet/in.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <signal.h> /* For SIGIGN and SIGINT */
#include <unistd.h>
#include <errno.h>
#include <pthread.h>
#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;
}

View File

@ -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 <antti.yli-tokola@arm.com>",
"license": "Apache-2.0",
"dependencies": {
"mbed-client-c": "^2.0.0"
},
"bin": "./"
}

View File

@ -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_ */

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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 <string.h>
#include <stdint.h>
#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);
}

View File

@ -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);

View File

@ -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

View File

@ -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 <string.h>
#include <stdint.h>
#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);
}

View File

@ -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);

View File

@ -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

View File

@ -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);

View File

@ -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());
}

View File

@ -1,985 +0,0 @@
/*
* Copyright (c) 2015 ARM. All rights reserved.
*/
#include "test_sn_coap_parser.h"
#include <string.h>
#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 <assert.h>
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
}

View File

@ -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 <stdbool.h>
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

View File

@ -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

View File

@ -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);

View File

@ -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

View File

@ -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

View File

@ -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);

View File

@ -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());
}

View File

@ -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 <stdbool.h>
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

View File

@ -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

View File

@ -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);

View File

@ -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());
}

View File

@ -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 <stdbool.h>
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

View File

@ -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"

View File

@ -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;
}
}

View File

@ -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 <stdint.h>
//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

View File

@ -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;
}

View File

@ -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__

View File

@ -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;
}

View File

@ -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 <inttypes.h>
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__

View File

@ -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;
}

View File

@ -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__

View File

@ -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 <stdio.h>
#include <stdlib.h> /* For libary malloc() */
#include <string.h> /* For memset() and memcpy() */
#ifdef __linux__
#include <time.h>
#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)
{
}

View File

@ -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__

View File

@ -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 <string.h>
#include <stdlib.h>
#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)
{
}

View File

@ -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__

View File

@ -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 <string.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"
/* 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)
{
}

View File

@ -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__

View File

@ -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;
}

View File

@ -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)

View File

@ -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;
}

View File

@ -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)

View File

@ -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/

View File

@ -0,0 +1,195 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project>
<configuration id="0.2056004298.1497082229" name="ArmCC Cortex-M3">
<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuildCommandParser" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser" keep-relative-paths="false" name="CDT GCC Build Output Parser" parameter="(.*gcc)|([gc]\+\+)|(clang)|(ArmCC)" prefer-non-shared="true" resource-scope="per-project" store-entries-with-project="true">
<language id="org.eclipse.cdt.core.gcc">
<resource project-relative-path="">
<entry kind="includePath" name="/${ProjName}/libNsdl/src/include">
<flag value="VALUE_WORKSPACE_PATH"/>
</entry>
<entry kind="includePath" name="/${ProjName}/mbed-coap/src/include">
<flag value="VALUE_WORKSPACE_PATH"/>
</entry>
<entry kind="includePath" name="/libService/include">
<flag value="VALUE_WORKSPACE_PATH|RESOLVED"/>
</entry>
<entry kind="includePath" name="/${ProjName}/include">
<flag value="VALUE_WORKSPACE_PATH"/>
</entry>
<entry kind="macro" name="VERSION" value="&quot;2.0-release-77-g0f5d7bf-dirty&quot;"/>
</resource>
<resource project-relative-path="libList">
<entry kind="includePath" name="/${ProjName}/include">
<flag value="VALUE_WORKSPACE_PATH"/>
</entry>
</resource>
<resource project-relative-path="randLIB">
<entry kind="includePath" name="/${ProjName}/include">
<flag value="VALUE_WORKSPACE_PATH"/>
</entry>
</resource>
<resource project-relative-path="libX509_V3">
<entry kind="includePath" name="/${ProjName}/include">
<flag value="VALUE_WORKSPACE_PATH"/>
</entry>
</resource>
<resource project-relative-path="libaes">
<entry kind="includePath" name="/${ProjName}/include">
<flag value="VALUE_WORKSPACE_PATH"/>
</entry>
</resource>
<resource project-relative-path="nsdynmemLIB">
<entry kind="includePath" name="/${ProjName}/include">
<flag value="VALUE_WORKSPACE_PATH"/>
</entry>
</resource>
<resource project-relative-path="CCM_lib">
<entry kind="includePath" name="/${ProjName}/include">
<flag value="VALUE_WORKSPACE_PATH"/>
</entry>
</resource>
<resource project-relative-path="SHA256_Lib">
<entry kind="includePath" name="/${ProjName}/include">
<flag value="VALUE_WORKSPACE_PATH"/>
</entry>
</resource>
<resource project-relative-path="IPv6_fcf_lib">
<entry kind="includePath" name="/${ProjName}/include">
<flag value="VALUE_WORKSPACE_PATH"/>
</entry>
</resource>
<resource project-relative-path="libip6string">
<entry kind="includePath" name="/${ProjName}/include">
<flag value="VALUE_WORKSPACE_PATH"/>
</entry>
</resource>
<resource project-relative-path="ECC_library/src">
<entry kind="includePath" name="/${ProjName}/ECC_library">
<flag value="VALUE_WORKSPACE_PATH"/>
</entry>
<entry kind="includePath" name="/${ProjName}/include">
<flag value="VALUE_WORKSPACE_PATH"/>
</entry>
</resource>
<resource project-relative-path="libNSTun">
<entry kind="includePath" name="/${ProjName}/include">
<flag value="VALUE_WORKSPACE_PATH"/>
</entry>
</resource>
</language>
</provider>
</extension>
</configuration>
<configuration id="0.2056004298.1497082229.1854995973" name="ArmCC Cortex-M0">
<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuildCommandParser" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser" keep-relative-paths="false" name="CDT GCC Build Output Parser" parameter="(.*gcc)|([gc]\+\+)|(clang)|(ArmCC)" prefer-non-shared="true" resource-scope="per-project" store-entries-with-project="true">
<language id="org.eclipse.cdt.core.gcc">
<resource project-relative-path="libList">
<entry kind="includePath" name="/${ProjName}/include">
<flag value="VALUE_WORKSPACE_PATH"/>
</entry>
</resource>
<resource project-relative-path="">
<entry kind="includePath" name="/${ProjName}/libNsdl/src/include">
<flag value="VALUE_WORKSPACE_PATH"/>
</entry>
<entry kind="includePath" name="/${ProjName}/mbed-coap/src/include">
<flag value="VALUE_WORKSPACE_PATH"/>
</entry>
<entry kind="includePath" name="/libService/include">
<flag value="VALUE_WORKSPACE_PATH|RESOLVED"/>
</entry>
<entry kind="includePath" name="/${ProjName}/include">
<flag value="VALUE_WORKSPACE_PATH"/>
</entry>
<entry kind="macro" name="VERSION" value="&quot;2.0-release-77-g0f5d7bf-dirty&quot;"/>
</resource>
<resource project-relative-path="randLIB">
<entry kind="includePath" name="/${ProjName}/include">
<flag value="VALUE_WORKSPACE_PATH"/>
</entry>
</resource>
<resource project-relative-path="libX509_V3">
<entry kind="includePath" name="/${ProjName}/include">
<flag value="VALUE_WORKSPACE_PATH"/>
</entry>
</resource>
<resource project-relative-path="libaes">
<entry kind="includePath" name="/${ProjName}/include">
<flag value="VALUE_WORKSPACE_PATH"/>
</entry>
</resource>
<resource project-relative-path="nsdynmemLIB">
<entry kind="includePath" name="/${ProjName}/include">
<flag value="VALUE_WORKSPACE_PATH"/>
</entry>
</resource>
<resource project-relative-path="SHA256_Lib">
<entry kind="includePath" name="/${ProjName}/include">
<flag value="VALUE_WORKSPACE_PATH"/>
</entry>
</resource>
<resource project-relative-path="CCM_lib">
<entry kind="includePath" name="/${ProjName}/include">
<flag value="VALUE_WORKSPACE_PATH"/>
</entry>
</resource>
<resource project-relative-path="libip6string">
<entry kind="includePath" name="/${ProjName}/include">
<flag value="VALUE_WORKSPACE_PATH"/>
</entry>
</resource>
<resource project-relative-path="IPv6_fcf_lib">
<entry kind="includePath" name="/${ProjName}/include">
<flag value="VALUE_WORKSPACE_PATH"/>
</entry>
</resource>
<resource project-relative-path="ECC_library/src">
<entry kind="includePath" name="/${ProjName}/ECC_library">
<flag value="VALUE_WORKSPACE_PATH"/>
</entry>
<entry kind="includePath" name="/${ProjName}/include">
<flag value="VALUE_WORKSPACE_PATH"/>
</entry>
</resource>
<resource project-relative-path="libNSTun">
<entry kind="includePath" name="/${ProjName}/include">
<flag value="VALUE_WORKSPACE_PATH"/>
</entry>
</resource>
</language>
</provider>
</extension>
</configuration>
<configuration id="0.2056004298.141662914.2121498000.642060230.2118977701" name="GCC Cortex-M0">
<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuildCommandParser" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser" keep-relative-paths="false" name="CDT GCC Build Output Parser" parameter="(.*gcc)|([gc]\+\+)|(clang)" prefer-non-shared="true" resource-scope="per-project" store-entries-with-project="true"/>
</extension>
</configuration>
<configuration id="0.2056004298.141662914.2121498000.642060230.2118977701.1678729521" name="GCC Cortex-M3">
<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuildCommandParser" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser" keep-relative-paths="false" name="CDT GCC Build Output Parser" parameter="(.*gcc)|([gc]\+\+)|(clang)" prefer-non-shared="true" resource-scope="per-project" store-entries-with-project="true"/>
</extension>
</configuration>
<configuration id="0.2056004298.141662914.1517984773.801758434.1788862897.788959847" name="GCC Native">
<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuildCommandParser" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser" keep-relative-paths="false" name="CDT GCC Build Output Parser" parameter="(gcc)|([gc]\+\+)|(clang)" prefer-non-shared="true" resource-scope="per-project"/>
</extension>
</configuration>
</project>

View File

@ -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

View File

@ -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

View File

@ -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.

View File

@ -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

View File

@ -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-%=%)

View File

@ -0,0 +1,2 @@
# mbed-coap
CoAP C library - Builder and Parser for CoAP messages

View File

@ -0,0 +1 @@
CoAP C library - Builder and Parser for CoAP messages.

View File

@ -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

View File

@ -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 * * * */
/* * * * * * * * * * * * * * * * * * * * * * */

View File

@ -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 <yogesh.pande@arm.com>",
"repository": {
"url": "https://github.com/ARMmbed/mbed-coap.git",
"type": "git"
},
"homepage": "https://github.com/ARMmbed/mbed-coap"
}

View File

@ -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

View File

@ -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" {

View File

@ -30,8 +30,7 @@
#include <string.h> /* 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"

View File

@ -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"

View File

@ -31,9 +31,8 @@
#include <string.h> /* 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"

View File

@ -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"

View File

@ -1,4 +0,0 @@
unittest/*
test/*
doxygen/*

View File

@ -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/

View File

@ -26,7 +26,7 @@ extern "C" {
#include <string.h>
#include "ns_types.h"
#include "sn_coap_header.h"
#include "mbed-coap/sn_coap_header.h"
#include "ns_address.h"
/**

View File

@ -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": {}
}

Some files were not shown because too many files have changed in this diff Show More