Skip to content

Commit

Permalink
Merge pull request #28 from ARMmbed/release-2.1.1
Browse files Browse the repository at this point in the history
mbed-cloud-client 2.1.1
  • Loading branch information
teetak01 authored Dec 19, 2018
2 parents f84aeea + 7935aa5 commit 004a8cb
Show file tree
Hide file tree
Showing 11 changed files with 600 additions and 121 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
## Changelog for Pelion Device Management Client

### Release 2.1.1 (19.12.2018)

* Full support for asynchronous CoAP REST response with response code and payload for GET, PUT and POST requests. The feature is enabled via `ENABLE_ASYNC_REST_RESPONSE`.
* Updated Mbed CoAP to 4.7.2.

### Release 2.1.0 (11.12.2018)

#### Pelion Device Management Client

* Added Edge-specific translated device unregistration parameter `d` to registration message body.
* Start reconnection if no response received for CoAP ping.
* Updated Mbed CoAP to 4.7.1.

#### Factory configurator client

Expand Down Expand Up @@ -54,6 +60,7 @@
#### Pelion Device Management Client

* This version of client has been tested with Mbed OS 5.10.0.
* Updated Mbed CoAP to 4.6.3.

#### Factory configurator client

Expand Down
48 changes: 48 additions & 0 deletions mbed-client/mbed-client/coap_response.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright (c) 2015 ARM Limited. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
* Licensed under the Apache License, Version 2.0 (the License); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef COAP_RESPONSE_H
#define COAP_RESPONSE_H

// Note: Don't put any C++ code into this file as this file is included from C sources.

// These values are COAP response codes. See https://tools.ietf.org/html/rfc7252#section-5.9.1
typedef enum {
COAP_RESPONSE_CREATED = 65,
COAP_RESPONSE_DELETED = 66,
COAP_RESPONSE_VALID = 67,
COAP_RESPONSE_CHANGED = 68,
COAP_RESPONSE_CONTENT = 69,
COAP_RESPONSE_CONTINUE = 95,
COAP_RESPONSE_BAD_REQUEST = 128,
COAP_RESPONSE_UNAUTHORIZED = 129,
COAP_RESPONSE_BAD_OPTION = 130,
COAP_RESPONSE_FORBIDDEN = 131,
COAP_RESPONSE_NOT_FOUND = 132,
COAP_RESPONSE_METHOD_NOT_ALLOWED = 133,
COAP_RESPONSE_NOT_ACCEPTABLE = 134,
COAP_RESPONSE_REQUEST_ENTITY_INCOMPLETE = 136,
COAP_RESPONSE_PRECONDITION_FAILED = 140,
COAP_RESPONSE_REQUEST_ENTITY_TOO_LARGE = 141,
COAP_RESPONSE_UNSUPPORTED_CONTENT_FORMAT = 143,
COAP_RESPONSE_INTERNAL_SERVER_ERROR = 160,
COAP_RESPONSE_NOT_IMPLEMENTED = 161,
COAP_RESPONSE_BAD_GATEWAY = 162,
COAP_RESPONSE_SERVICE_UNAVAILABLE = 163,
COAP_RESPONSE_GATEWAY_TIMEOUT = 164,
COAP_RESPONSE_PROXYING_NOT_SUPPORTED = 165
} coap_response_code_e;
#endif

78 changes: 75 additions & 3 deletions mbed-client/mbed-client/m2mbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
#include "mbed-client/m2mreportobserver.h"
#include "mbed-client/functionpointer.h"
#include "mbed-client/m2mstringbuffer.h"
#ifdef ENABLE_ASYNC_REST_RESPONSE
#include "mbed-client/coap_response.h"
#endif
#include "nsdl-c/sn_nsdl.h"
#include "sn_coap_header.h"
#include "nsdl-c/sn_nsdl_lib.h"
Expand Down Expand Up @@ -143,13 +146,15 @@ class M2MBase : public M2MReportObserver {
} MessageDeliveryStatus;

typedef enum {
NOTIFICATION,
NOTIFICATION = 0,
DELAYED_POST_RESPONSE,
BLOCK_SUBSCRIBE,
PING
PING,
#ifdef ENABLE_ASYNC_REST_RESPONSE
DELAYED_RESPONSE,
#endif // ENABLE_ASYNC_REST_RESPONSE
} MessageType;


enum MaxPathSize {
MAX_NAME_SIZE = 64,
MAX_INSTANCE_SIZE = 5,
Expand All @@ -172,6 +177,26 @@ class M2MBase : public M2MReportObserver {
const MessageType type,
void *client_args);

#ifdef ENABLE_ASYNC_REST_RESPONSE
/**
* \brief Type definition for an asynchronous CoAP request callback function.
* \param operation The operation, for example M2MBase::PUT_ALLOWED.
* \param token The token. Client needs to copy this if it cannot respond immediately.
* \param token_len The length of the token.
* \param buffer The payload of the request. Client needs to copy this if it cannot respond immediately.
* \param buffer_size The size of the payload.
* \param client_args Some pointer given by client when requesting asynchronus request callback using
* set_async_coap_request_cb.
*/
typedef void (*handle_async_coap_request_cb)(const M2MBase &base,
M2MBase::Operation operation,
const uint8_t *token,
const uint8_t token_len,
const uint8_t *buffer,
size_t buffer_size,
void *client_args);
#endif // ENABLE_ASYNC_REST_RESPONSE


typedef struct lwm2m_parameters {
//add multiple_instances
Expand Down Expand Up @@ -551,6 +576,33 @@ class M2MBase : public M2MReportObserver {
*/
M2MBase::lwm2m_parameters_s* get_lwm2m_parameters() const;

#ifdef ENABLE_ASYNC_REST_RESPONSE
/**
* \brief A trigger to send the async response for the CoAP request.
* \param code The code for the response, for example: 'COAP_RESPONSE_CHANGED'.
* \param payload Payload for the resource.
* \param payload_len Length of the payload.
* \param token Token for the incoming CoAP request.
* \param token_len Token length for the incoming CoAP request.
* \return True if a response is sent, else False.
*/
bool send_async_response_with_code(const uint8_t *payload,
size_t payload_len,
const uint8_t* token,
const uint8_t token_len,
coap_response_code_e code = COAP_RESPONSE_CHANGED);

/**
* @brief Sets the function that is executed when CoAP request arrives.
* Callback is not called if the request are invalid, for example content-type is not matching.
* In that case the error response is sent by the client itself.
* @param callback The function pointer that is called.
* @param client_args The argument which is passed to the callback function.
*/
bool set_async_coap_request_cb(handle_async_coap_request_cb callback, void *client_args);

#endif //ENABLE_ASYNC_REST_RESPONSE

/**
* @brief Returns the notification message id.
* @return Message id.
Expand Down Expand Up @@ -755,6 +807,26 @@ class M2MBase : public M2MReportObserver {
*/
void start_observation(const sn_coap_hdr_s &received_coap_header, M2MObservationHandler *observation_handler);

#ifdef ENABLE_ASYNC_REST_RESPONSE

/**
* @brief Executes the callback set in 'set_async_coap_request_cb'.
* @param coap_request CoAP request containing the requesting payload and payload size.
* @param operation Operation mode to be passed to the application.
* @param handled Caller to know whether callback is processed or not.
*/
void call_async_coap_request_callback(sn_coap_hdr_s *coap_request,
M2MBase::Operation operation,
bool &handled);

/**
* @brief Returns whether asynchronous callback is set or not.
* @return True if set otherwise False.
*/
bool is_async_coap_request_callback_set();

#endif //ENABLE_ASYNC_REST_RESPONSE

private:
static bool is_integer(const String &value);

Expand Down
25 changes: 22 additions & 3 deletions mbed-client/mbed-client/m2mobservationhandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
#ifndef M2M_OBSERVATION_HANDLER_H
#define M2M_OBSERVATION_HANDLER_H

// Needed for M2MBase::Operation
#include "m2mbase.h"
#include "mbed-client/coap_response.h"
//FORWARD DECLARATION
class M2MBase;
class M2MResourceInstance;

/*! \file m2mobservationhandler.h
Expand Down Expand Up @@ -67,12 +69,29 @@ class M2MObservationHandler

#ifndef DISABLE_DELAYED_RESPONSE
/**
* \brief A delayed response callback to be sent to the
* server due to a changed response.
* \brief Sends a delayed post response to the server with 'COAP_MSG_CODE_RESPONSE_CHANGED' response code.
* \param base The resource sending the response.
*/
virtual void send_delayed_response(M2MBase *base) = 0;
#endif

#ifdef ENABLE_ASYNC_REST_RESPONSE
/**
* \brief Sends async response to the server for the given operation with the given response code.
* \param base The resource sending the response.
* \param payload Payload for the resource.
* \param payload_len Length of the payload.
* \param token Token for the incoming CoAP request.
* \param token_len Token length for the incoming CoAP request.
* \param code The response code for the operation, for example: COAP_MSG_CODE_RESPONSE_CHANGED.
*/
virtual void send_asynchronous_response(M2MBase *base,
const uint8_t *payload,
size_t payload_len,
const uint8_t* token,
const uint8_t token_len,
coap_response_code_e code) = 0;
#endif
};


Expand Down
32 changes: 22 additions & 10 deletions mbed-client/mbed-client/m2mresource.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include "mbed-client/m2mvector.h"
#include "mbed-client/m2mresourcebase.h"
#include "mbed-client/m2mresourceinstance.h"
#include "mbed-client/coap_response.h"
#include <stdlib.h>

//FORWARD DECLARATION
class M2MObjectInstance;
Expand All @@ -31,7 +33,8 @@ typedef Vector<M2MResourceInstance *> M2MResourceInstanceList;
* instances associated with the given object.
*/

class M2MResource : public M2MResourceBase {
class M2MResource : public M2MResourceBase
{

friend class M2MObjectInstance;

Expand Down Expand Up @@ -129,25 +132,40 @@ class M2MResource : public M2MResourceBase {
#ifndef DISABLE_DELAYED_RESPONSE
/**
* \brief Sets whether the resource should send a delayed response for a POST request.
* This only works for resources which don't support multiple instances.
* Please use M2MBase::set_async_coap_request_cb method, if you are using
* ENABLE_ASYNC_REST_RESPONSE flag, because this method will be deprecated.
* \param delayed_response A boolean value to set the delayed response.
*/
#ifdef ENABLE_ASYNC_REST_RESPONSE
void set_delayed_response(bool delayed_response) m2m_deprecated;
#else
void set_delayed_response(bool delayed_response);

#endif
/**
* \brief A trigger to send the delayed response for the POST request.
* The delayed_response flag must be set before receiving the POST request
* and the value of the resource must be updated before calling this function.
* This sends the post response with code 'COAP_MSG_CODE_RESPONSE_CHANGED'.
* Please use M2MBase::send_async_response_with_code method, if you are using
* ENABLE_ASYNC_REST_RESPONSE flag, because this method will be deprecated.
* \return True if a response is sent, else false.
*/
bool send_delayed_post_response();

/**
* \brief Provides the value of the given token.
* \brief Provides the value of the token of the delayed post response.
* \param value[OUT] A pointer to the token value.
* \param value_length[OUT] The length of the token pointer.
*/
void get_delayed_token(uint8_t *&token, uint8_t &token_length);
#endif

/**
* \brief Returns the value set for delayed response for POST requests.
* \return The value for delayed response.
*/
bool delayed_response() const;
#endif //DISABLE_DELAYED_RESPONSE

/**
* \brief Removes a resource with a given name.
Expand Down Expand Up @@ -176,12 +194,6 @@ class M2MResource : public M2MResourceBase {
*/
uint16_t resource_instance_count() const;

/**
* \brief Returns the value set for delayed response.
* \return The value for delayed response.
*/
bool delayed_response() const;

/**
* \brief Returns the Observation Handler object.
* \return M2MObservationHandler object.
Expand Down
7 changes: 7 additions & 0 deletions mbed-client/source/include/m2mcallbackstorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ class M2MCallbackAssociation
// typedef bool(*write_resource_value_callback) (const M2MResourceBase& resource,
// const uint8_t *buffer, const size_t buffer_size, void *client_args);
M2MResourceBaseValueWriteCallback

#ifdef ENABLE_ASYNC_REST_RESPONSE
// typedef bool(*handle_async_coap_request_cb) (const M2MBase& base,
// M2MBase::Operation operation, const uint8_t *token, const uint8_t token_len,
// const uint8_t *buffer, size_t buffer_size, void *client_args);
,M2MBaseAsyncCoapRequestCallback
#endif // ENABLE_ASYNC_REST_RESPONSE
};

/**
Expand Down
Loading

0 comments on commit 004a8cb

Please sign in to comment.