Skip to content

Commit 5a19797

Browse files
Yogesh PandeYogesh Pande
authored andcommitted
Fix for IOTCLT-961 for next mbed-os release candidate
This PR is for fixing error found in integration testing for Bootstrap and Connector functionality. The corresponding fixes done here ARMmbed/mbed-client@6925e89 ARMmbed/mbed-client-classic@fbfb300
1 parent 22acfbf commit 5a19797

File tree

5 files changed

+114
-9
lines changed

5 files changed

+114
-9
lines changed

features/FEATURE_CLIENT/mbed-client-classic/source/m2mconnectionhandlerpimpl.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#include "eventOS_scheduler.h"
2828

2929
#include "mbed-trace/mbed_trace.h"
30-
#include "mbed.h"
3130

3231
#define TRACE_GROUP "mClt"
3332

@@ -103,7 +102,7 @@ M2MConnectionHandlerPimpl::M2MConnectionHandlerPimpl(M2MConnectionHandler* base,
103102
_address._address = _address_buffer;
104103

105104
if (_network_stack != M2MInterface::LwIP_IPv4) {
106-
error("ConnectionHandler: Unsupported network stack, only IPv4 is currently supported");
105+
tr_error("ConnectionHandler: Unsupported network stack, only IPv4 is currently supported");
107106
}
108107
_running = true;
109108
tr_debug("M2MConnectionHandlerPimpl::M2MConnectionHandlerPimpl() - Initializing thread");
@@ -117,6 +116,10 @@ M2MConnectionHandlerPimpl::M2MConnectionHandlerPimpl(M2MConnectionHandler* base,
117116
M2MConnectionHandlerPimpl::~M2MConnectionHandlerPimpl()
118117
{
119118
tr_debug("M2MConnectionHandlerPimpl::~M2MConnectionHandlerPimpl()");
119+
if(_socket_address) {
120+
delete _socket_address;
121+
_socket_address = NULL;
122+
}
120123
if (_socket) {
121124
delete _socket;
122125
_socket = 0;
@@ -163,6 +166,10 @@ bool M2MConnectionHandlerPimpl::resolve_server_address(const String& server_addr
163166
void M2MConnectionHandlerPimpl::dns_handler()
164167
{
165168
tr_debug("M2MConnectionHandlerPimpl::dns_handler()");
169+
if(_socket_address) {
170+
delete _socket_address;
171+
_socket_address = NULL;
172+
}
166173
_socket_address = new SocketAddress(_net_iface,_server_address.c_str(), _server_port);
167174
if(*_socket_address) {
168175
_address._address = (void*)_socket_address->get_ip_address();

features/FEATURE_CLIENT/mbed-client/docs/Introduction.md

Lines changed: 72 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ _interface->set_random_number_callback(&get_random_number);
6464

6565
mbed Client provides an API to add your own entropy source into the underlying SSL library. There is a default entropy source provided by mbed Client. It uses PRNG seeded with RTC for the security but some platforms do not have RTC, and for some, this level of security may not be strong enough.
6666

67-
Now, an application can pass its own entropy source to mbed Client as function pointer callback through an API, `set_entropy_callback(entropy_cb callback)`.
67+
Now, an application can pass its own entropy source to mbed Client as function pointer callback through an API `set_entropy_callback(entropy_cb callback)`.
6868

6969
Here is an example on how you can use it from an application:
7070

@@ -101,7 +101,18 @@ The maximum single UDP message size that mbed Client can receive is 1152 bytes.
101101

102102
For transferring larger amounts of data, the Blockwise feature must be deployed. When using this feature, mbed Client can handle messages up to 64KB. This feature is disabled by default.
103103

104-
To enable the Blockwise feature, you need to create a `config.json` file in the application level.
104+
For mbed OS, to enable Blockwise feature , create a `mbed_app.json` file in the application level and overwrite Blockwise value as described below:
105+
106+
*Example:*
107+
```
108+
"target_overrides": {
109+
"*": {
110+
"mbed-client.sn-coap-max-blockwise-payload-size": 1024
111+
}
112+
113+
```
114+
115+
For yotta based builds, to enable the Blockwise feature, you need to create a `config.json` file in the application level.
105116

106117
*Example:*
107118
```
@@ -115,9 +126,19 @@ Acceptable values for the `coap_max_blockwise_payload_size` flag are:
115126

116127
### CoAP message deduplication
117128

118-
Message duplication is disabled by default. More information about deduplication in the [CoAP specification](https://tools.ietf.org/html/rfc7252#page-24).
129+
By default, message deduplication is disabled. More information about deduplication in the [CoAP specification](https://tools.ietf.org/html/rfc7252#page-24).
130+
131+
For mbed OS, to enable message deduplication, create a `mbed_app.json` file in the application level and overwrite the deduplication value as described below:
132+
133+
*Example:*
134+
```
135+
"target_overrides": {
136+
"*": {
137+
"mbed-client.sn-coap-duplication-max-msgs-count": 1
138+
}
119139
120-
To enable message deduplication, you need to create a `config.json` file in the application level.
140+
```
141+
For yotta based builds, to enable message deduplication, you need to create a `config.json` file in the application level.
121142

122143
*Example:*
123144
```
@@ -127,6 +148,53 @@ To enable message deduplication, you need to create a `config.json` file in the
127148
```
128149
Recommended values for the `coap_duplication_max_msgs_count` flag are 0 to 6. Value 0 means that the feature is not used. It is not recommended to use higher value than 6, because it increases the memory consumption.
129150

151+
### Reconnectivity
152+
153+
Apart from standard CoAP features, mbed Client also handles reconnectivity logic on behalf of applications, thereby aiming to provide seamless connectivity experience and recovery from temporary network hiccups or service side disruptions.
154+
155+
The reconnection logic handles the following:
156+
157+
- Reconnection towards mDS; establishing the network connection and re-registration to mDS.
158+
- CoAP message resending logic. More information about resending in [CoAP specification](https://tools.ietf.org/html/rfc7252#section-4.8).
159+
160+
There are two parameters in the reconnection logic, both configurable by the application:
161+
162+
- Reconnection Retry
163+
- Reconnection Time Interval (in seconds)
164+
165+
mbed Client tries to establish a successful connection to the server by incrementing the reconnection trials every time there is a failed connection attempt.
166+
167+
The logic of the `Reconnection Timeout` is `Reconnection Retry count * Reconnection Time Interval` , where `Reconnection Retry count` is incremented by 1 with every failed reconnection attempt.
168+
169+
mbed Client continues to attempt a reconnection until `Reconnection Retry count` reaches the defined value (either by the application or the default value set in Client).
170+
171+
If mbed Client still cannot establish a connection and the set `Reconnection Retry count` is reached, it returns an error through a callback with an appropriate error code defining the reason for failed connection.
172+
173+
There are a few exceptions to the reconnection logic though. If mbed Client sends registration data that is rejected by the server, the client returns an error and does not attempt a reconnection as the server has rejected the data from the client. A typical example of such case would be passing a non-matching endpoint name or domain name against the client certificates.
174+
175+
Applications can define their own parameters for the reconnection logic.
176+
177+
For mbed OS, to overwrite the reconnection retry count and reconnection time interval, create a `mbed_app.json` file in the application level and overwrite the values as described below:
178+
179+
*Example:*
180+
```
181+
"target_overrides": {
182+
"*": {
183+
"mbed-client.reconnection-count": 3,
184+
"mbed-client.reconnection-interval": 5,
185+
}
186+
187+
```
188+
For yotta based builds, to overwrite the reconnection retry count and reconnection time interval, you need to create a `config.json` file in the application level.
189+
190+
*Example:*
191+
```
192+
{
193+
"reconnection_count": 3,
194+
"reconnection_interval": 5
195+
}
196+
```
197+
130198
## How to use the API
131199
More information on how to use the API effectively to create and configure Objects, Object Instances and Resources, can be found [here](Howto.md).
132200

features/FEATURE_CLIENT/mbed-client/docs/dev_man_serv_enable.md

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ The Client API allows setting values to Resources, an array of Resource Instance
6767

6868
The **Write** operation is used to overwrite the value of a Resource, an array of Resource Instances or multiple Resources from an Object Instance.
6969

70-
Whenever there is a valid `PUT` operation for any of the resources, the application will receive a callback:
70+
Whenever there is a valid `PUT` operation for any of the resources, the application will receive a callback:
7171

7272
```
7373
void value_updated(M2MBase *base, M2MBase::BaseType type)
@@ -119,6 +119,34 @@ void value_updated(M2MBase *base, M2MBase::BaseType type) {
119119
}
120120
}
121121
```
122+
By default, callbacks are handled in the `value_updated()` function but the application can also define a callback function for an individual resource.
123+
124+
Check the code snippet below for usage.
125+
126+
```
127+
static void value_updated_global(const char *name) {
128+
if(name) {
129+
...
130+
}
131+
}
132+
133+
void M2MLWClient::value_updated_function(const char* name) {
134+
if (name) {
135+
...
136+
}
137+
}
138+
139+
M2MResource* res = inst->create_dynamic_resource("D", "ResourceTest", true);
140+
char buffer[20];
141+
int size = sprintf(buffer,"%d",_value);
142+
res->set_operation(M2MBase::GET_PUT_POST_DELETE_ALLOWED);
143+
res->set_value((const uint8_t*)buffer, (const uint32_t)size);
144+
res->set_value_updated_function(value_updated_callback(this,&MbedClient::value_updated_function));
145+
/* Overloaded function can be used If callback function is not in class scope.
146+
res2->set_value_updated_function(value_updated_callback2(&value_updated_global));
147+
*/
148+
149+
```
122150

123151
## The Write Attributes operation
124152

@@ -182,7 +210,7 @@ if(_object) {
182210
(const uint32_t)size);
183211
res->set_execute_function(execute_callback(this,&M2MLWClient::execute_function));
184212
/* Overloaded function can be used If callback function is not in class scope.
185-
res->set_execute_function(&execute_function_2);
213+
res->set_execute_function(execute_callback_2(&execute_function_2));
186214
*/
187215
```
188216

features/FEATURE_CLIENT/mbed-client/module.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mbed-client",
3-
"version": "1.13.2",
3+
"version": "1.13.4",
44
"description": "mbed Client C++ API",
55
"keywords": [],
66
"author": "Yogesh Pande <[email protected]>",

features/FEATURE_CLIENT/mbed-client/source/m2minterfaceimpl.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,7 @@ void M2MInterfaceImpl::state_bootstrap_address_resolved( EventData *data)
603603
}
604604
address.port = event->_port;
605605
address.addr_ptr = (uint8_t*)event->_address->_address;
606+
address.addr_len = event->_address->_length;
606607
_connection_handler->start_listening_for_data();
607608

608609
// Include domain id to be part of endpoint name
@@ -816,6 +817,7 @@ void M2MInterfaceImpl::state_coap_data_received( EventData *data)
816817
}
817818
address.port = event->_address->_port;
818819
address.addr_ptr = (uint8_t*)event->_address->_address;
820+
address.addr_len = event->_address->_length;
819821

820822
// Process received data
821823
internal_event(STATE_PROCESSING_COAP_DATA);

0 commit comments

Comments
 (0)