mirror of https://github.com/ARMmbed/mbed-os.git
Update mbed-client-c version 3.0.4
parent
eb3dc2d2c8
commit
d80f863647
|
@ -1,5 +1,293 @@
|
|||
# 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)
|
||||
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
#
|
||||
# Makefile for combined NSDL+COAP library
|
||||
#
|
||||
|
||||
# Define compiler toolchain with CC or PLATFORM variables
|
||||
# Example (GCC toolchains, default $CC and $AR are used)
|
||||
# make
|
||||
#
|
||||
# OR (Cross-compile GCC toolchain)
|
||||
# make PLATFORM=arm-linux-gnueabi-
|
||||
#
|
||||
# OR (armcc/Keil)
|
||||
# make CC=armcc AR=ArmAR
|
||||
#
|
||||
# OR (IAR-ARM)
|
||||
# make CC=iccarm
|
||||
|
||||
LIB = libnsdl.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 \
|
||||
|
||||
override CFLAGS += -DVERSION='"$(VERSION)"'
|
||||
|
||||
override CFLAGS += -Isource/libNsdl/src/include/
|
||||
override CFLAGS += -Isource/libCoap/src/include/
|
||||
SERVLIB_DIR := ../libService
|
||||
override CFLAGS += -I$(SERVLIB_DIR)/libService
|
||||
override CFLAGS += -Insdl-c/
|
||||
|
||||
include ../libService/toolchain_rules.mk
|
||||
|
||||
$(eval $(call generate_rules,$(LIB),$(SRCS)))
|
||||
|
||||
.PHONY: release
|
||||
release:
|
||||
7z a nsdl-c_$(VERSION).zip *.a *.lib include
|
||||
|
||||
.PHONY: deploy_to
|
||||
deploy_to: all
|
||||
tar --transform 's,^,nsdl-c/,' --append -f $(TO) *.a nsdl-c
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "mbed-client-c",
|
||||
"version": "3.0.2",
|
||||
"version": "3.0.4",
|
||||
"description": "Nanostack NSDL and COAP library",
|
||||
"keywords": [
|
||||
"coap",
|
||||
|
@ -14,7 +14,8 @@
|
|||
],
|
||||
"dependencies": {
|
||||
"nanostack-libservice": "^3.0.0",
|
||||
"mbed-trace": ">=0.2.0,<2.0.0"
|
||||
"mbed-trace": ">=0.2.0,<2.0.0",
|
||||
"nanostack-randlib": "^1.2.0"
|
||||
},
|
||||
"targetDependencies": {}
|
||||
}
|
||||
|
|
|
@ -25,6 +25,12 @@
|
|||
#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
|
||||
|
@ -723,8 +729,40 @@ extern int8_t sn_nsdl_set_block_size(struct nsdl_s *handle, uint16_t block_size)
|
|||
*/
|
||||
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_ */
|
||||
|
|
|
@ -0,0 +1,666 @@
|
|||
/*
|
||||
* 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_ */
|
|
@ -149,6 +149,7 @@ uint16_t sn_coap_builder_calc_needed_packet_data_size(sn_coap_hdr_s *src_coap_ms
|
|||
|
||||
uint16_t sn_coap_builder_calc_needed_packet_data_size_2(sn_coap_hdr_s *src_coap_msg_ptr, uint16_t blockwise_payload_size)
|
||||
{
|
||||
(void)blockwise_payload_size;
|
||||
tr_debug("sn_coap_builder_calc_needed_packet_data_size_2");
|
||||
uint16_t returned_byte_count = 0;
|
||||
|
||||
|
@ -750,13 +751,11 @@ static uint8_t sn_coap_builder_options_build_add_uint_option(uint8_t **dst_packe
|
|||
{
|
||||
uint8_t payload[4];
|
||||
uint8_t len = 0;
|
||||
|
||||
/* Construct the variable-length payload representing the value */
|
||||
while (option_value) {
|
||||
if (option_value & 0xff000000) {
|
||||
for (uint8_t i = 0; i < 4; i++) {
|
||||
if (len > 0 || (option_value & 0xff000000)) {
|
||||
payload[len++] = option_value >> 24;
|
||||
}
|
||||
|
||||
option_value <<= 8;
|
||||
}
|
||||
|
||||
|
|
|
@ -40,7 +40,9 @@
|
|||
#include "sn_coap_protocol.h"
|
||||
#include "sn_coap_header_internal.h"
|
||||
#include "sn_coap_protocol_internal.h"
|
||||
#include "randLIB.h"
|
||||
#include "mbed-trace/mbed_trace.h"
|
||||
|
||||
#define TRACE_GROUP "coap"
|
||||
/* * * * * * * * * * * * * * * * * * * * */
|
||||
/* * * * LOCAL FUNCTION PROTOTYPES * * * */
|
||||
|
@ -198,12 +200,12 @@ struct coap_s *sn_coap_protocol_init(void *(*used_malloc_func_ptr)(uint16_t), vo
|
|||
#endif /* ENABLE_RESENDINGS */
|
||||
|
||||
/* Randomize global message ID */
|
||||
#if defined __linux__ || defined TARGET_LIKE_MBED
|
||||
srand(rand()^time(NULL));
|
||||
message_id = rand() % 400 + 100;
|
||||
#else
|
||||
message_id = 100;
|
||||
#endif
|
||||
randLIB_seed_random();
|
||||
message_id = randLIB_get_16bit();
|
||||
if (message_id == 0) {
|
||||
message_id = 1;
|
||||
}
|
||||
tr_debug("Coap random msg ID: %d", message_id);
|
||||
|
||||
return handle;
|
||||
}
|
||||
|
@ -610,29 +612,33 @@ sn_coap_hdr_s *sn_coap_protocol_parse(struct coap_s *handle, sn_nsdl_addr_s *src
|
|||
/* * * * Manage received CoAP message duplicate detection * * * */
|
||||
|
||||
/* If no message duplication detected */
|
||||
if (sn_coap_protocol_linked_list_duplication_info_search(handle, src_addr_ptr, returned_dst_coap_msg_ptr->msg_id) == -1) {
|
||||
/* * * No Message duplication: Store received message for detecting later duplication * * */
|
||||
if (returned_dst_coap_msg_ptr->msg_type == COAP_MSG_TYPE_CONFIRMABLE ||
|
||||
returned_dst_coap_msg_ptr->msg_type == COAP_MSG_TYPE_NON_CONFIRMABLE) {
|
||||
|
||||
/* Get count of stored duplication messages */
|
||||
uint16_t stored_duplication_msgs_count = handle->count_duplication_msgs;
|
||||
if (sn_coap_protocol_linked_list_duplication_info_search(handle, src_addr_ptr, returned_dst_coap_msg_ptr->msg_id) == -1) {
|
||||
/* * * No Message duplication: Store received message for detecting later duplication * * */
|
||||
|
||||
/* Check if there is no room to store message for duplication detection purposes */
|
||||
if (stored_duplication_msgs_count >= handle->sn_coap_duplication_buffer_size) {
|
||||
/* Get oldest stored duplication message */
|
||||
coap_duplication_info_s *stored_duplication_info_ptr = ns_list_get_first(&handle->linked_list_duplication_msgs);
|
||||
/* Get count of stored duplication messages */
|
||||
uint16_t stored_duplication_msgs_count = handle->count_duplication_msgs;
|
||||
|
||||
/* Remove oldest stored duplication message for getting room for new duplication message */
|
||||
sn_coap_protocol_linked_list_duplication_info_remove(handle, stored_duplication_info_ptr->addr_ptr, stored_duplication_info_ptr->port, stored_duplication_info_ptr->msg_id);
|
||||
/* Check if there is no room to store message for duplication detection purposes */
|
||||
if (stored_duplication_msgs_count >= handle->sn_coap_duplication_buffer_size) {
|
||||
/* Get oldest stored duplication message */
|
||||
coap_duplication_info_s *stored_duplication_info_ptr = ns_list_get_first(&handle->linked_list_duplication_msgs);
|
||||
|
||||
/* Remove oldest stored duplication message for getting room for new duplication message */
|
||||
sn_coap_protocol_linked_list_duplication_info_remove(handle, stored_duplication_info_ptr->addr_ptr, stored_duplication_info_ptr->port, stored_duplication_info_ptr->msg_id);
|
||||
}
|
||||
|
||||
/* Store Duplication info to Linked list */
|
||||
sn_coap_protocol_linked_list_duplication_info_store(handle, src_addr_ptr, returned_dst_coap_msg_ptr->msg_id);
|
||||
} else { /* * * Message duplication detected * * */
|
||||
/* Set returned status to User */
|
||||
returned_dst_coap_msg_ptr->coap_status = COAP_STATUS_PARSER_DUPLICATED_MSG;
|
||||
// todo: send ACK to confirmable messages
|
||||
/* Because duplicate message, return with coap_status set */
|
||||
return returned_dst_coap_msg_ptr;
|
||||
}
|
||||
|
||||
/* Store Duplication info to Linked list */
|
||||
sn_coap_protocol_linked_list_duplication_info_store(handle, src_addr_ptr, returned_dst_coap_msg_ptr->msg_id);
|
||||
} else { /* * * Message duplication detected * * */
|
||||
/* Set returned status to User */
|
||||
returned_dst_coap_msg_ptr->coap_status = COAP_STATUS_PARSER_DUPLICATED_MSG;
|
||||
|
||||
/* Because duplicate message, return with coap_status set */
|
||||
return returned_dst_coap_msg_ptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -16,6 +16,11 @@
|
|||
#ifndef GRS_H_
|
||||
#define GRS_H_
|
||||
|
||||
#ifdef MBED_CLIENT_C_NEW_API
|
||||
|
||||
#include "sn_grs2.h"
|
||||
|
||||
#else
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -79,6 +84,9 @@ struct nsdl_s {
|
|||
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);
|
||||
|
@ -128,7 +136,7 @@ extern void sn_grs_mark_resources_as_registered(stru
|
|||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* MBED_CLIENT_C_NEW_API */
|
||||
|
||||
|
||||
#endif /* GRS_H_ */
|
||||
|
|
|
@ -0,0 +1,150 @@
|
|||
/*
|
||||
* 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_ */
|
|
@ -21,6 +21,9 @@
|
|||
* \brief General resource server.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef MBED_CLIENT_C_NEW_API
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
@ -1035,3 +1038,5 @@ void sn_grs_mark_resources_as_registered(struct nsdl_s *handle)
|
|||
temp_resource = sn_grs_get_next_resource(handle->grs, temp_resource);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
File diff suppressed because it is too large
Load Diff
|
@ -20,6 +20,8 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#ifndef MBED_CLIENT_C_NEW_API
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "ns_types.h"
|
||||
|
@ -223,6 +225,8 @@ struct nsdl_s *sn_nsdl_init(uint8_t (*sn_nsdl_tx_cb)(struct nsdl_s *, sn_nsdl_ca
|
|||
handle->sn_nsdl_endpoint_registered = SN_NSDL_ENDPOINT_NOT_REGISTERED;
|
||||
// By default bootstrap msgs are handled in nsdl
|
||||
handle->handle_bootstrap_msg = true;
|
||||
handle->context = NULL;
|
||||
|
||||
return handle;
|
||||
}
|
||||
|
||||
|
@ -2585,3 +2589,23 @@ bool sn_nsdl_check_uint_overflow(uint16_t resource_size, uint16_t param_a, uint1
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
extern int8_t sn_nsdl_set_context(struct nsdl_s * const handle, void * const context)
|
||||
{
|
||||
if (handle == NULL) {
|
||||
return SN_NSDL_FAILURE;
|
||||
}
|
||||
handle->context = context;
|
||||
return SN_NSDL_SUCCESS;
|
||||
}
|
||||
|
||||
extern void *sn_nsdl_get_context(const struct nsdl_s * const handle)
|
||||
{
|
||||
if (handle == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
return handle->context;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,19 @@
|
|||
#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
|
||||
|
|
@ -13,6 +13,7 @@ INCLUDE_DIRS =\
|
|||
../../../../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\
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
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
|
||||
|
||||
|
||||
|
|
@ -318,20 +318,23 @@ TEST(libCoap_builder, sn_coap_builder_calc_needed_packet_data_size)
|
|||
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(270);
|
||||
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(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;
|
||||
|
@ -343,7 +346,7 @@ TEST(libCoap_builder, sn_coap_builder_calc_needed_packet_data_size)
|
|||
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*)malloc(6);
|
||||
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);
|
||||
|
||||
|
@ -357,7 +360,7 @@ TEST(libCoap_builder, sn_coap_builder_calc_needed_packet_data_size)
|
|||
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*)malloc(6);
|
||||
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);
|
||||
|
||||
|
@ -372,6 +375,8 @@ TEST(libCoap_builder, sn_coap_builder_calc_needed_packet_data_size)
|
|||
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;
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
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
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
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
|
||||
|
|
@ -8,6 +8,7 @@
|
|||
#include "sn_coap_header.h"
|
||||
#include "sn_coap_header_internal.h"
|
||||
#include "sn_coap_protocol_internal.h"
|
||||
#include <assert.h>
|
||||
|
||||
int retCounter = 0;
|
||||
|
||||
|
@ -37,7 +38,9 @@ bool test_sn_coap_parser()
|
|||
|
||||
retCounter = 0;
|
||||
bool ret = true;
|
||||
uint8_t* ptr = (uint8_t*)malloc(20);
|
||||
// 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);
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
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
|
|
@ -384,24 +384,25 @@ TEST(libCoap_protocol, sn_coap_protocol_build)
|
|||
hdr2->options_list_ptr->use_size1 = true;
|
||||
hdr2->options_list_ptr->size1 = 0xFFFF01;
|
||||
|
||||
hdr2->payload_ptr = (uint8_t*)malloc(3);
|
||||
int buff_len = SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE + 20;
|
||||
hdr2->payload_ptr = (uint8_t*)malloc(buff_len);
|
||||
|
||||
for( int i=0; i < 8; i++ ){
|
||||
retCounter = 1 + i;
|
||||
sn_coap_builder_stub.expectedInt16 = 1;
|
||||
hdr2->payload_len = SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE + 20;
|
||||
hdr2->payload_len = buff_len;
|
||||
int8_t rett = sn_coap_protocol_build(handle, &addr, dst_packet_data_ptr, hdr2, NULL);
|
||||
CHECK( -2 == rett );
|
||||
}
|
||||
|
||||
retCounter = 11;
|
||||
sn_coap_builder_stub.expectedInt16 = 1;
|
||||
hdr2->payload_len = SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE + 20;
|
||||
hdr2->payload_len = buff_len;
|
||||
CHECK( 1 == sn_coap_protocol_build(handle, &addr, dst_packet_data_ptr, hdr2, NULL));
|
||||
|
||||
retCounter = 19;
|
||||
sn_coap_builder_stub.expectedInt16 = 1;
|
||||
hdr2->payload_len = SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE + 20;
|
||||
hdr2->payload_len = buff_len;
|
||||
CHECK( 1 == sn_coap_protocol_build(handle, &addr, dst_packet_data_ptr, hdr2, NULL));
|
||||
|
||||
free(hdr2->payload_ptr);
|
||||
|
@ -450,7 +451,6 @@ TEST(libCoap_protocol, sn_coap_protocol_parse)
|
|||
|
||||
retCounter = 1;
|
||||
struct coap_s * handle = sn_coap_protocol_init(myMalloc, myFree, null_tx_cb, NULL);
|
||||
|
||||
sn_nsdl_addr_s* addr = (sn_nsdl_addr_s*)malloc(sizeof(sn_nsdl_addr_s));
|
||||
memset(addr, 0, sizeof(sn_nsdl_addr_s));
|
||||
|
||||
|
@ -582,7 +582,7 @@ TEST(libCoap_protocol, sn_coap_protocol_parse)
|
|||
memset(list, 0, sizeof(sn_coap_options_list_s));
|
||||
sn_coap_parser_stub.expectedHeader->options_list_ptr = list;
|
||||
sn_coap_parser_stub.expectedHeader->options_list_ptr->block1 = 1;
|
||||
sn_coap_parser_stub.expectedHeader->msg_id = 4;
|
||||
sn_coap_parser_stub.expectedHeader->msg_id = 5;
|
||||
sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_CONFIRMABLE;
|
||||
sn_coap_parser_stub.expectedHeader->msg_code = COAP_MSG_CODE_REQUEST_GET;
|
||||
payload = (uint8_t*)malloc(17);
|
||||
|
@ -843,12 +843,13 @@ TEST(libCoap_protocol, sn_coap_protocol_parse)
|
|||
|
||||
retCounter = 20;
|
||||
sn_coap_builder_stub.expectedInt16 = 1;
|
||||
tmp_hdr.payload_ptr = (uint8_t*)malloc(3);
|
||||
int buff_size = SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE + 20;
|
||||
tmp_hdr.payload_ptr = (uint8_t*)malloc(buff_size);
|
||||
tmp_hdr.options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s));
|
||||
memset(tmp_hdr.options_list_ptr, 0, sizeof(sn_coap_options_list_s));
|
||||
tmp_hdr.options_list_ptr->block2 = 1;
|
||||
tmp_hdr.msg_id = 16;
|
||||
tmp_hdr.payload_len = SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE + 20;
|
||||
tmp_hdr.payload_len = buff_size;
|
||||
sn_coap_protocol_build(handle, &tmp_addr, dst_packet_data_ptr, &tmp_hdr, NULL);
|
||||
|
||||
free(tmp_hdr.options_list_ptr);
|
||||
|
@ -891,13 +892,14 @@ TEST(libCoap_protocol, sn_coap_protocol_parse)
|
|||
|
||||
retCounter = 21;
|
||||
sn_coap_builder_stub.expectedInt16 = 1;
|
||||
tmp_hdr.payload_ptr = (uint8_t*)malloc(3);
|
||||
int buff_len = SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE + 20;
|
||||
tmp_hdr.payload_ptr = (uint8_t*)malloc(buff_len);
|
||||
tmp_hdr.options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s));
|
||||
memset(tmp_hdr.options_list_ptr, 0, sizeof(sn_coap_options_list_s));
|
||||
tmp_hdr.options_list_ptr->block1 = -1;
|
||||
tmp_hdr.options_list_ptr->block2 = 1;
|
||||
tmp_hdr.msg_id = 17;
|
||||
tmp_hdr.payload_len = SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE + 20;
|
||||
tmp_hdr.payload_len = buff_len;
|
||||
|
||||
sn_coap_protocol_build(handle, &tmp_addr, dst_packet_data_ptr, &tmp_hdr, NULL);
|
||||
|
||||
|
@ -938,7 +940,8 @@ TEST(libCoap_protocol, sn_coap_protocol_parse)
|
|||
|
||||
retCounter = 20;
|
||||
sn_coap_builder_stub.expectedInt16 = 1;
|
||||
tmp_hdr.payload_ptr = (uint8_t*)malloc(3);
|
||||
buff_len = UINT16_MAX;
|
||||
tmp_hdr.payload_ptr = (uint8_t*)malloc(buff_len);
|
||||
// tmp_hdr.options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s));
|
||||
// memset(tmp_hdr.options_list_ptr, 0, sizeof(sn_coap_options_list_s));
|
||||
// tmp_hdr.options_list_ptr->block2 = 1;
|
||||
|
@ -1096,12 +1099,13 @@ TEST(libCoap_protocol, sn_coap_protocol_parse)
|
|||
|
||||
retCounter = 20;
|
||||
sn_coap_builder_stub.expectedInt16 = 1;
|
||||
tmp_hdr.payload_ptr = (uint8_t*)malloc(3);
|
||||
buff_len = SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE + 20;
|
||||
tmp_hdr.payload_ptr = (uint8_t*)malloc(buff_len);
|
||||
tmp_hdr.options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s));
|
||||
memset(tmp_hdr.options_list_ptr, 0, sizeof(sn_coap_options_list_s));
|
||||
tmp_hdr.options_list_ptr->block2 = 1;
|
||||
tmp_hdr.msg_id = 16;
|
||||
tmp_hdr.payload_len = SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE + 20;
|
||||
tmp_hdr.payload_len = buff_len;
|
||||
sn_coap_protocol_build(handle, &tmp_addr, dst_packet_data_ptr, &tmp_hdr, NULL);
|
||||
|
||||
free(tmp_hdr.options_list_ptr);
|
||||
|
@ -1145,13 +1149,14 @@ TEST(libCoap_protocol, sn_coap_protocol_parse)
|
|||
|
||||
retCounter = 21;
|
||||
sn_coap_builder_stub.expectedInt16 = 1;
|
||||
tmp_hdr.payload_ptr = (uint8_t*)malloc(3);
|
||||
buff_len = SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE + 20;
|
||||
tmp_hdr.payload_ptr = (uint8_t*)malloc(buff_len);
|
||||
tmp_hdr.options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s));
|
||||
memset(tmp_hdr.options_list_ptr, 0, sizeof(sn_coap_options_list_s));
|
||||
tmp_hdr.options_list_ptr->block1 = -1;
|
||||
tmp_hdr.options_list_ptr->block2 = 1;
|
||||
tmp_hdr.msg_id = 17;
|
||||
tmp_hdr.payload_len = SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE + 20;
|
||||
tmp_hdr.payload_len = buff_len;
|
||||
|
||||
sn_coap_protocol_build(handle, &tmp_addr, dst_packet_data_ptr, &tmp_hdr, NULL);
|
||||
|
||||
|
@ -1197,14 +1202,15 @@ TEST(libCoap_protocol, sn_coap_protocol_parse)
|
|||
|
||||
retCounter = 20;
|
||||
sn_coap_builder_stub.expectedInt16 = 1;
|
||||
tmp_hdr.payload_ptr = (uint8_t*)malloc(3);
|
||||
buff_len = SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE + 20;
|
||||
tmp_hdr.payload_ptr = (uint8_t*)malloc(buff_len);
|
||||
tmp_hdr.options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s));
|
||||
memset(tmp_hdr.options_list_ptr, 0, sizeof(sn_coap_options_list_s));
|
||||
tmp_hdr.options_list_ptr->use_size2 = true;
|
||||
tmp_hdr.options_list_ptr->size2 = 0xFF01;
|
||||
tmp_hdr.msg_id = 18;
|
||||
tmp_hdr.msg_code = COAP_MSG_CODE_RESPONSE_CREATED;
|
||||
tmp_hdr.payload_len = SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE + 20;
|
||||
tmp_hdr.payload_len = buff_len;
|
||||
sn_coap_protocol_build(handle, &tmp_addr, dst_packet_data_ptr, &tmp_hdr, NULL);
|
||||
|
||||
free(tmp_hdr.options_list_ptr);
|
||||
|
@ -1350,11 +1356,12 @@ TEST(libCoap_protocol, sn_coap_protocol_parse)
|
|||
|
||||
retCounter = 20;
|
||||
sn_coap_builder_stub.expectedInt16 = 1;
|
||||
tmp_hdr.payload_ptr = (uint8_t*)malloc(3);
|
||||
buff_len = SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE + 20;
|
||||
tmp_hdr.payload_ptr = (uint8_t*)malloc(buff_len);
|
||||
|
||||
tmp_hdr.msg_id = 20;
|
||||
tmp_hdr.msg_code = COAP_MSG_CODE_RESPONSE_CREATED;
|
||||
tmp_hdr.payload_len = SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE + 20;
|
||||
tmp_hdr.payload_len = buff_len;
|
||||
sn_coap_protocol_build(handle, &tmp_addr, dst_packet_data_ptr, &tmp_hdr, NULL);
|
||||
|
||||
free(tmp_hdr.options_list_ptr);
|
||||
|
@ -1425,12 +1432,13 @@ TEST(libCoap_protocol, sn_coap_protocol_parse)
|
|||
|
||||
retCounter = 20;
|
||||
sn_coap_builder_stub.expectedInt16 = 1;
|
||||
tmp_hdr.payload_ptr = (uint8_t*)malloc(3);
|
||||
buff_len = SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE + 20;
|
||||
tmp_hdr.payload_ptr = (uint8_t*)malloc(buff_len);
|
||||
tmp_hdr.options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s));
|
||||
memset(tmp_hdr.options_list_ptr, 0, sizeof(sn_coap_options_list_s));
|
||||
tmp_hdr.options_list_ptr->block2 = 1;
|
||||
tmp_hdr.msg_id = 41;
|
||||
tmp_hdr.payload_len = SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE + 20;
|
||||
tmp_hdr.payload_len = buff_len;
|
||||
sn_coap_protocol_build(handle, &tmp_addr, dst_packet_data_ptr, &tmp_hdr, NULL);
|
||||
|
||||
free(tmp_hdr.options_list_ptr);
|
||||
|
@ -1472,12 +1480,13 @@ TEST(libCoap_protocol, sn_coap_protocol_parse)
|
|||
|
||||
retCounter = 20;
|
||||
sn_coap_builder_stub.expectedInt16 = 1;
|
||||
tmp_hdr.payload_ptr = (uint8_t*)malloc(3);
|
||||
buff_len = SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE + 20;
|
||||
tmp_hdr.payload_ptr = (uint8_t*)malloc(buff_len);
|
||||
tmp_hdr.options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s));
|
||||
memset(tmp_hdr.options_list_ptr, 0, sizeof(sn_coap_options_list_s));
|
||||
tmp_hdr.options_list_ptr->block2 = 1;
|
||||
tmp_hdr.msg_id = 42;
|
||||
tmp_hdr.payload_len = SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE + 20;
|
||||
tmp_hdr.payload_len = buff_len;
|
||||
sn_coap_protocol_build(handle, &tmp_addr, dst_packet_data_ptr, &tmp_hdr, NULL);
|
||||
|
||||
free(tmp_hdr.options_list_ptr);
|
||||
|
@ -1519,12 +1528,13 @@ TEST(libCoap_protocol, sn_coap_protocol_parse)
|
|||
|
||||
retCounter = 20;
|
||||
sn_coap_builder_stub.expectedInt16 = 1;
|
||||
tmp_hdr.payload_ptr = (uint8_t*)malloc(3);
|
||||
buff_len = SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE + 20;
|
||||
tmp_hdr.payload_ptr = (uint8_t*)malloc(buff_len);
|
||||
tmp_hdr.options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s));
|
||||
memset(tmp_hdr.options_list_ptr, 0, sizeof(sn_coap_options_list_s));
|
||||
tmp_hdr.options_list_ptr->block2 = 1;
|
||||
tmp_hdr.msg_id = 43;
|
||||
tmp_hdr.payload_len = SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE + 20;
|
||||
tmp_hdr.payload_len = buff_len;
|
||||
sn_coap_protocol_build(handle, &tmp_addr, dst_packet_data_ptr, &tmp_hdr, NULL);
|
||||
|
||||
free(tmp_hdr.options_list_ptr);
|
||||
|
@ -1565,12 +1575,13 @@ TEST(libCoap_protocol, sn_coap_protocol_parse)
|
|||
|
||||
retCounter = 20;
|
||||
sn_coap_builder_stub.expectedInt16 = 1;
|
||||
tmp_hdr.payload_ptr = (uint8_t*)malloc(3);
|
||||
buff_len = SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE + 20;
|
||||
tmp_hdr.payload_ptr = (uint8_t*)malloc(buff_len);
|
||||
tmp_hdr.options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s));
|
||||
memset(tmp_hdr.options_list_ptr, 0, sizeof(sn_coap_options_list_s));
|
||||
tmp_hdr.options_list_ptr->block2 = 1;
|
||||
tmp_hdr.msg_id = 44;
|
||||
tmp_hdr.payload_len = SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE + 20;
|
||||
tmp_hdr.payload_len = buff_len;
|
||||
sn_coap_protocol_build(handle, &tmp_addr, dst_packet_data_ptr, &tmp_hdr, NULL);
|
||||
|
||||
free(tmp_hdr.options_list_ptr);
|
||||
|
@ -1610,12 +1621,13 @@ TEST(libCoap_protocol, sn_coap_protocol_parse)
|
|||
|
||||
retCounter = 20;
|
||||
sn_coap_builder_stub.expectedInt16 = 1;
|
||||
tmp_hdr.payload_ptr = (uint8_t*)malloc(3);
|
||||
buff_len = SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE + 20;
|
||||
tmp_hdr.payload_ptr = (uint8_t*)malloc(buff_len);
|
||||
tmp_hdr.options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s));
|
||||
memset(tmp_hdr.options_list_ptr, 0, sizeof(sn_coap_options_list_s));
|
||||
tmp_hdr.options_list_ptr->block2 = 1;
|
||||
tmp_hdr.msg_id = 45;
|
||||
tmp_hdr.payload_len = SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE + 20;
|
||||
tmp_hdr.payload_len = buff_len;
|
||||
sn_coap_protocol_build(handle, &tmp_addr, dst_packet_data_ptr, &tmp_hdr, NULL);
|
||||
|
||||
free(tmp_hdr.options_list_ptr);
|
||||
|
@ -1656,12 +1668,13 @@ TEST(libCoap_protocol, sn_coap_protocol_parse)
|
|||
|
||||
retCounter = 20;
|
||||
sn_coap_builder_stub.expectedInt16 = 1;
|
||||
tmp_hdr.payload_ptr = (uint8_t*)malloc(3);
|
||||
buff_len = SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE + 20;
|
||||
tmp_hdr.payload_ptr = (uint8_t*)malloc(buff_len);
|
||||
tmp_hdr.options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s));
|
||||
memset(tmp_hdr.options_list_ptr, 0, sizeof(sn_coap_options_list_s));
|
||||
tmp_hdr.options_list_ptr->block2 = 1;
|
||||
tmp_hdr.msg_id = 46;
|
||||
tmp_hdr.payload_len = SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE + 20;
|
||||
tmp_hdr.payload_len = buff_len;
|
||||
sn_coap_protocol_build(handle, &tmp_addr, dst_packet_data_ptr, &tmp_hdr, NULL);
|
||||
|
||||
free(tmp_hdr.options_list_ptr);
|
||||
|
@ -1706,12 +1719,13 @@ TEST(libCoap_protocol, sn_coap_protocol_parse)
|
|||
|
||||
retCounter = 20;
|
||||
sn_coap_builder_stub.expectedInt16 = 1;
|
||||
tmp_hdr.payload_ptr = (uint8_t*)malloc(3);
|
||||
buff_len = SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE + 20;
|
||||
tmp_hdr.payload_ptr = (uint8_t*)malloc(buff_len);
|
||||
tmp_hdr.options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s));
|
||||
memset(tmp_hdr.options_list_ptr, 0, sizeof(sn_coap_options_list_s));
|
||||
tmp_hdr.options_list_ptr->block2 = 1;
|
||||
tmp_hdr.msg_id = 47;
|
||||
tmp_hdr.payload_len = SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE + 20;
|
||||
tmp_hdr.payload_len = buff_len;
|
||||
sn_coap_protocol_build(handle, &tmp_addr, dst_packet_data_ptr, &tmp_hdr, NULL);
|
||||
|
||||
free(tmp_hdr.options_list_ptr);
|
||||
|
@ -1758,12 +1772,13 @@ TEST(libCoap_protocol, sn_coap_protocol_parse)
|
|||
|
||||
retCounter = 20;
|
||||
sn_coap_builder_stub.expectedInt16 = 1;
|
||||
tmp_hdr.payload_ptr = (uint8_t*)malloc(3);
|
||||
buff_len = SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE + 20;
|
||||
tmp_hdr.payload_ptr = (uint8_t*)malloc(buff_len);
|
||||
tmp_hdr.options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s));
|
||||
memset(tmp_hdr.options_list_ptr, 0, sizeof(sn_coap_options_list_s));
|
||||
tmp_hdr.options_list_ptr->block2 = 1;
|
||||
tmp_hdr.msg_id = 47;
|
||||
tmp_hdr.payload_len = SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE + 20;
|
||||
tmp_hdr.payload_len = buff_len;
|
||||
sn_coap_protocol_build(handle, &tmp_addr, dst_packet_data_ptr, &tmp_hdr, NULL);
|
||||
|
||||
free(tmp_hdr.options_list_ptr);
|
||||
|
@ -1942,10 +1957,11 @@ TEST(libCoap_protocol, sn_coap_protocol_parse)
|
|||
|
||||
retCounter = 20;
|
||||
sn_coap_builder_stub.expectedInt16 = 5;
|
||||
tmp_hdr.payload_ptr = (uint8_t*)malloc(3);
|
||||
buff_len = SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE + 20;
|
||||
tmp_hdr.payload_ptr = (uint8_t*)malloc(buff_len);
|
||||
tmp_hdr.msg_id = 18;
|
||||
tmp_hdr.msg_code = COAP_MSG_CODE_RESPONSE_CREATED;
|
||||
tmp_hdr.payload_len = SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE + 20;
|
||||
tmp_hdr.payload_len = buff_len;
|
||||
sn_coap_protocol_build(handle, &tmp_addr, dst_packet_data_ptr, &tmp_hdr, NULL);
|
||||
|
||||
free(tmp_hdr.options_list_ptr);
|
||||
|
@ -1981,10 +1997,11 @@ TEST(libCoap_protocol, sn_coap_protocol_parse)
|
|||
|
||||
retCounter = 20;
|
||||
sn_coap_builder_stub.expectedInt16 = 5;
|
||||
tmp_hdr.payload_ptr = (uint8_t*)malloc(3);
|
||||
buff_len = SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE + 20;
|
||||
tmp_hdr.payload_ptr = (uint8_t*)malloc(buff_len);
|
||||
tmp_hdr.msg_id = 18;
|
||||
tmp_hdr.msg_code = COAP_MSG_CODE_RESPONSE_CREATED;
|
||||
tmp_hdr.payload_len = SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE + 20;
|
||||
tmp_hdr.payload_len = buff_len;
|
||||
tmp_hdr.uri_path_ptr = (uint8_t*)malloc(7);
|
||||
snprintf((char *)tmp_hdr.uri_path_ptr, 7, "13/0/1");
|
||||
tmp_hdr.uri_path_len = 7;
|
||||
|
@ -2025,10 +2042,11 @@ TEST(libCoap_protocol, sn_coap_protocol_parse)
|
|||
|
||||
retCounter = 20;
|
||||
sn_coap_builder_stub.expectedInt16 = 5;
|
||||
tmp_hdr.payload_ptr = (uint8_t*)malloc(3);
|
||||
buff_len = SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE + 20;
|
||||
tmp_hdr.payload_ptr = (uint8_t*)malloc(buff_len);
|
||||
tmp_hdr.msg_id = 18;
|
||||
tmp_hdr.msg_code = COAP_MSG_CODE_RESPONSE_CREATED;
|
||||
tmp_hdr.payload_len = SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE + 20;
|
||||
tmp_hdr.payload_len = buff_len;
|
||||
tmp_hdr.uri_path_ptr = (uint8_t*)malloc(7);
|
||||
snprintf((char *)tmp_hdr.uri_path_ptr, 7, "13/0/1");
|
||||
tmp_hdr.uri_path_len = 7;
|
||||
|
@ -2070,10 +2088,11 @@ TEST(libCoap_protocol, sn_coap_protocol_exec)
|
|||
|
||||
retCounter = 20;
|
||||
sn_coap_builder_stub.expectedInt16 = 5;
|
||||
tmp_hdr.payload_ptr = (uint8_t*)malloc(3);
|
||||
int buff_size = SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE + 20;
|
||||
tmp_hdr.payload_ptr = (uint8_t*)malloc(buff_size);
|
||||
tmp_hdr.msg_id = 18;
|
||||
tmp_hdr.msg_code = COAP_MSG_CODE_RESPONSE_CREATED;
|
||||
tmp_hdr.payload_len = SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE + 20;
|
||||
tmp_hdr.payload_len = buff_size;
|
||||
sn_coap_protocol_build(handle, &tmp_addr, dst_packet_data_ptr, &tmp_hdr, NULL);
|
||||
|
||||
free(tmp_hdr.options_list_ptr);
|
||||
|
@ -2136,10 +2155,11 @@ TEST(libCoap_protocol, sn_coap_protocol_exec2)
|
|||
|
||||
retCounter = 20;
|
||||
sn_coap_builder_stub.expectedInt16 = 5;
|
||||
tmp_hdr.payload_ptr = (uint8_t*)malloc(3);
|
||||
int buf_len = SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE + 20;
|
||||
tmp_hdr.payload_ptr = (uint8_t*)malloc(buf_len);
|
||||
tmp_hdr.msg_id = 18;
|
||||
tmp_hdr.msg_code = COAP_MSG_CODE_RESPONSE_CREATED;
|
||||
tmp_hdr.payload_len = SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE + 20;
|
||||
tmp_hdr.payload_len = buf_len;
|
||||
sn_coap_protocol_build(handle, &tmp_addr, dst_packet_data_ptr, &tmp_hdr, NULL);
|
||||
|
||||
free(tmp_hdr.options_list_ptr);
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
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
|
||||
|
|
@ -646,10 +646,11 @@ bool test_sn_grs_process_coap()
|
|||
memset(hdr, 0, sizeof(sn_coap_hdr_s));
|
||||
hdr->msg_code = COAP_MSG_CODE_REQUEST_GET;
|
||||
hdr->msg_type = COAP_MSG_TYPE_RESET;
|
||||
hdr->uri_path_ptr = (uint8_t*)malloc(2);
|
||||
hdr->uri_path_ptr = (uint8_t*)calloc(2, 1);
|
||||
hdr->uri_path_len = 2;
|
||||
hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED;
|
||||
hdr->payload_ptr = (uint8_t*)malloc(2);
|
||||
hdr->payload_ptr = (uint8_t*)calloc(2, 1);
|
||||
hdr->payload_len = 2;
|
||||
|
||||
if( SN_NSDL_SUCCESS != sn_grs_process_coap(handle, hdr, addr) ){
|
||||
return false;
|
||||
|
@ -660,10 +661,11 @@ bool test_sn_grs_process_coap()
|
|||
memset(hdr, 0, sizeof(sn_coap_hdr_s));
|
||||
hdr->msg_code = COAP_MSG_CODE_REQUEST_POST;
|
||||
hdr->msg_type = COAP_MSG_TYPE_RESET;
|
||||
hdr->uri_path_ptr = (uint8_t*)malloc(2);
|
||||
hdr->uri_path_ptr = (uint8_t*)calloc(2, 1);
|
||||
hdr->uri_path_len = 2;
|
||||
hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED;
|
||||
hdr->payload_ptr = (uint8_t*)malloc(2);
|
||||
hdr->payload_len = 2;
|
||||
|
||||
if( SN_NSDL_SUCCESS != sn_grs_process_coap(handle, hdr, addr) ){
|
||||
return false;
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
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
|
||||
|
|
@ -186,5 +186,14 @@ 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());
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2015 ARM. All rights reserved.
|
||||
* Copyright (c) 2015 ARM. All rights reserved.
|
||||
*/
|
||||
#include "test_sn_nsdl.h"
|
||||
#include <string.h>
|
||||
|
@ -279,6 +279,7 @@ bool test_sn_nsdl_register_endpoint()
|
|||
sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_ptr[1] = '\0';
|
||||
sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_len = 1;
|
||||
sn_grs_stub.expectedInfo->resource_parameters_ptr->observable = 1;
|
||||
sn_grs_stub.expectedInfo->resource_parameters_ptr->coap_content_type = 0; // XXX: why was this left uninitialized? what was point of this test?
|
||||
|
||||
sn_grs_stub.expectedInfo->path = (uint8_t*)malloc(2);
|
||||
sn_grs_stub.expectedInfo->path[0] = 'a';
|
||||
|
@ -309,7 +310,7 @@ bool test_sn_nsdl_register_endpoint()
|
|||
sn_grs_stub.infoRetCounter = 1;
|
||||
sn_grs_stub.expectedInfo = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s));
|
||||
memset( sn_grs_stub.expectedInfo, 0, sizeof(sn_nsdl_resource_info_s));
|
||||
sn_grs_stub.expectedInfo->resource_parameters_ptr = (sn_nsdl_resource_parameters_s*)malloc(sizeof(sn_nsdl_resource_parameters_s));
|
||||
sn_grs_stub.expectedInfo->resource_parameters_ptr = (sn_nsdl_resource_parameters_s*)calloc(sizeof(sn_nsdl_resource_parameters_s), 1);
|
||||
sn_grs_stub.expectedInfo->resource_parameters_ptr->observable = 1;
|
||||
sn_grs_stub.expectedInfo->publish_uri = 1;
|
||||
eptr->binding_and_mode = 0x06;
|
||||
|
@ -351,6 +352,7 @@ bool test_sn_nsdl_register_endpoint()
|
|||
sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_ptr[1] = '\0';
|
||||
sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_len = 1;
|
||||
sn_grs_stub.expectedInfo->resource_parameters_ptr->observable = 1;
|
||||
sn_grs_stub.expectedInfo->resource_parameters_ptr->coap_content_type = 0;
|
||||
|
||||
sn_grs_stub.expectedInfo->path = (uint8_t*)malloc(2);
|
||||
sn_grs_stub.expectedInfo->path[0] = 'a';
|
||||
|
@ -617,6 +619,7 @@ bool test_sn_nsdl_register_endpoint()
|
|||
sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_ptr[1] = '\0';
|
||||
sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_len = 1;
|
||||
sn_grs_stub.expectedInfo->resource_parameters_ptr->observable = 1;
|
||||
sn_grs_stub.expectedInfo->resource_parameters_ptr->coap_content_type = 0;
|
||||
sn_grs_stub.expectedInfo->path = (uint8_t*)malloc(2);
|
||||
sn_grs_stub.expectedInfo->path[0] = 'a';
|
||||
sn_grs_stub.expectedInfo->path[1] = '\0';
|
||||
|
@ -830,7 +833,7 @@ bool test_sn_nsdl_update_registration()
|
|||
sn_grs_stub.infoRetCounter = 1;
|
||||
sn_grs_stub.expectedInfo = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s));
|
||||
memset( sn_grs_stub.expectedInfo, 0, sizeof(sn_nsdl_resource_info_s));
|
||||
sn_grs_stub.expectedInfo->resource_parameters_ptr = (sn_nsdl_resource_parameters_s*)malloc(sizeof(sn_nsdl_resource_parameters_s));
|
||||
sn_grs_stub.expectedInfo->resource_parameters_ptr = (sn_nsdl_resource_parameters_s*)calloc(sizeof(sn_nsdl_resource_parameters_s), 1);
|
||||
sn_grs_stub.expectedInfo->resource_parameters_ptr->observable = 1;
|
||||
sn_grs_stub.expectedInfo->publish_uri = 1;
|
||||
retCounter = 3;
|
||||
|
@ -1505,7 +1508,7 @@ bool test_sn_nsdl_process_coap()
|
|||
sn_coap_protocol_stub.expectedHeader->msg_code = COAP_MSG_CODE_RESPONSE_CREATED;
|
||||
sn_coap_protocol_stub.expectedHeader->options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s));
|
||||
memset(sn_coap_protocol_stub.expectedHeader->options_list_ptr, 0, sizeof(sn_coap_options_list_s));
|
||||
sn_coap_protocol_stub.expectedHeader->options_list_ptr->location_path_ptr = (uint8_t*)malloc(2);
|
||||
sn_coap_protocol_stub.expectedHeader->options_list_ptr->location_path_ptr = (uint8_t*)calloc(2, 1);
|
||||
sn_coap_protocol_stub.expectedHeader->options_list_ptr->location_path_len = 2;
|
||||
handle->register_msg_id = 5;
|
||||
|
||||
|
@ -2650,35 +2653,41 @@ bool test_set_NSP_address()
|
|||
handle->nsp_address_ptr->omalw_address_ptr->addr_ptr = (uint8_t*)malloc(2);
|
||||
memset( handle->nsp_address_ptr->omalw_address_ptr->addr_ptr, 0, 2 );
|
||||
|
||||
uint8_t* addr = (uint8_t*)malloc(2);
|
||||
memset(addr, 0, 2);
|
||||
// Note: the set_NSP_address() will read 4 bytes of source address
|
||||
uint8_t* addr4 = (uint8_t*)calloc(4, 1);
|
||||
|
||||
if( SN_NSDL_FAILURE != set_NSP_address(handle, addr, 0, SN_NSDL_ADDRESS_TYPE_IPV4) ){
|
||||
if( SN_NSDL_FAILURE != set_NSP_address(handle, addr4, 0, SN_NSDL_ADDRESS_TYPE_IPV4) ){
|
||||
return false;
|
||||
}
|
||||
handle->nsp_address_ptr->omalw_address_ptr->addr_ptr = NULL;
|
||||
|
||||
retCounter = 1;
|
||||
if( SN_NSDL_SUCCESS != set_NSP_address(handle, addr, 0, SN_NSDL_ADDRESS_TYPE_IPV4) ){
|
||||
if( SN_NSDL_SUCCESS != set_NSP_address(handle, addr4, 0, SN_NSDL_ADDRESS_TYPE_IPV4) ){
|
||||
return false;
|
||||
}
|
||||
free(handle->nsp_address_ptr->omalw_address_ptr->addr_ptr);
|
||||
handle->nsp_address_ptr->omalw_address_ptr->addr_ptr = NULL;
|
||||
|
||||
if( SN_NSDL_FAILURE != set_NSP_address(handle, addr, 0, SN_NSDL_ADDRESS_TYPE_IPV6) ){
|
||||
// Note: the set_NSP_address() will read 16 bytes of source address
|
||||
uint8_t* addr6 = (uint8_t*)calloc(16, 1);
|
||||
|
||||
if( SN_NSDL_FAILURE != set_NSP_address(handle, addr6, 0, SN_NSDL_ADDRESS_TYPE_IPV6) ){
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
handle->nsp_address_ptr->omalw_address_ptr->addr_ptr = NULL;
|
||||
handle->nsp_address_ptr->omalw_address_ptr->addr_ptr = (uint8_t*)malloc(2);
|
||||
handle->nsp_address_ptr->omalw_address_ptr->addr_len = 2;
|
||||
memset( handle->nsp_address_ptr->omalw_address_ptr->addr_ptr, 0, 2 );
|
||||
|
||||
retCounter = 1;
|
||||
if( SN_NSDL_SUCCESS != set_NSP_address(handle, addr, 0, SN_NSDL_ADDRESS_TYPE_IPV6) ){
|
||||
if( SN_NSDL_SUCCESS != set_NSP_address(handle, addr6, 0, SN_NSDL_ADDRESS_TYPE_IPV6) ){
|
||||
return false;
|
||||
}
|
||||
|
||||
free(addr);
|
||||
free(addr4);
|
||||
free(addr6);
|
||||
sn_nsdl_destroy(handle);
|
||||
return true;
|
||||
}
|
||||
|
@ -2880,7 +2889,7 @@ bool test_sn_nsdl_release_allocated_coap_msg_mem()
|
|||
memset(sn_grs_stub.expectedGrs,0, sizeof(struct grs_s));
|
||||
struct nsdl_s* handle = sn_nsdl_init(&nsdl_tx_callback, &nsdl_rx_callback, &myMalloc, &myFree);
|
||||
|
||||
sn_coap_hdr_s* list = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s));
|
||||
sn_coap_hdr_s* list = (sn_coap_hdr_s*)calloc(sizeof(sn_coap_hdr_s), 1);
|
||||
|
||||
sn_nsdl_release_allocated_coap_msg_mem(handle, list); //mem leak or pass
|
||||
|
||||
|
@ -2963,3 +2972,51 @@ bool test_sn_nsdl_set_duplicate_buffer_size()
|
|||
sn_nsdl_destroy(handle);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool test_sn_nsdl_set_context()
|
||||
{
|
||||
struct nsdl_s* handle = NULL;
|
||||
if (sn_nsdl_set_context(handle,NULL) == 0){
|
||||
printf("\n\neka\n\n");
|
||||
return false;
|
||||
}
|
||||
retCounter = 4;
|
||||
sn_grs_stub.expectedGrs = (struct grs_s *)malloc(sizeof(struct grs_s));
|
||||
memset(sn_grs_stub.expectedGrs,0, sizeof(struct grs_s));
|
||||
handle = sn_nsdl_init(&nsdl_tx_callback, &nsdl_rx_callback, &myMalloc, &myFree);
|
||||
|
||||
if (sn_nsdl_set_context(handle,NULL) != 0){
|
||||
printf("\n\ntoka\n\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
int somecontext = 1;
|
||||
if (sn_nsdl_set_context(handle,&somecontext) != 0){
|
||||
printf("\n\nkolmas\n\n");
|
||||
return false;
|
||||
}
|
||||
sn_nsdl_destroy(handle);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool test_sn_nsdl_get_context()
|
||||
{
|
||||
struct nsdl_s* handle = NULL;
|
||||
if (sn_nsdl_get_context(handle) != NULL){
|
||||
return false;
|
||||
}
|
||||
|
||||
retCounter = 4;
|
||||
sn_grs_stub.expectedGrs = (struct grs_s *)malloc(sizeof(struct grs_s));
|
||||
memset(sn_grs_stub.expectedGrs,0, sizeof(struct grs_s));
|
||||
handle = sn_nsdl_init(&nsdl_tx_callback, &nsdl_rx_callback, &myMalloc, &myFree);
|
||||
|
||||
int somecontext = 1;
|
||||
sn_nsdl_set_context(handle,&somecontext);
|
||||
if (sn_nsdl_get_context(handle) != &somecontext){
|
||||
return false;
|
||||
}
|
||||
|
||||
sn_nsdl_destroy(handle);
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -78,6 +78,10 @@ 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
|
||||
|
|
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* 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
|
Loading…
Reference in New Issue