Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
wakaama/management.c@0:f9d13e09cf11, 2017-04-24 (annotated)
- Committer:
- terencez
- Date:
- Mon Apr 24 23:03:31 2017 +0000
- Revision:
- 0:f9d13e09cf11
- Child:
- 3:a280069151ac
The first compiled submit.
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| terencez | 0:f9d13e09cf11 | 1 | /******************************************************************************* |
| terencez | 0:f9d13e09cf11 | 2 | * |
| terencez | 0:f9d13e09cf11 | 3 | * Copyright (c) 2013, 2014 Intel Corporation and others. |
| terencez | 0:f9d13e09cf11 | 4 | * All rights reserved. This program and the accompanying materials |
| terencez | 0:f9d13e09cf11 | 5 | * are made available under the terms of the Eclipse Public License v1.0 |
| terencez | 0:f9d13e09cf11 | 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. |
| terencez | 0:f9d13e09cf11 | 7 | * |
| terencez | 0:f9d13e09cf11 | 8 | * The Eclipse Public License is available at |
| terencez | 0:f9d13e09cf11 | 9 | * http://www.eclipse.org/legal/epl-v10.html |
| terencez | 0:f9d13e09cf11 | 10 | * The Eclipse Distribution License is available at |
| terencez | 0:f9d13e09cf11 | 11 | * http://www.eclipse.org/org/documents/edl-v10.php. |
| terencez | 0:f9d13e09cf11 | 12 | * |
| terencez | 0:f9d13e09cf11 | 13 | * Contributors: |
| terencez | 0:f9d13e09cf11 | 14 | * David Navarro, Intel Corporation - initial API and implementation |
| terencez | 0:f9d13e09cf11 | 15 | * domedambrosio - Please refer to git log |
| terencez | 0:f9d13e09cf11 | 16 | * Toby Jaffey - Please refer to git log |
| terencez | 0:f9d13e09cf11 | 17 | * |
| terencez | 0:f9d13e09cf11 | 18 | *******************************************************************************/ |
| terencez | 0:f9d13e09cf11 | 19 | /* |
| terencez | 0:f9d13e09cf11 | 20 | Copyright (c) 2013, 2014 Intel Corporation |
| terencez | 0:f9d13e09cf11 | 21 | |
| terencez | 0:f9d13e09cf11 | 22 | Redistribution and use in source and binary forms, with or without modification, |
| terencez | 0:f9d13e09cf11 | 23 | are permitted provided that the following conditions are met: |
| terencez | 0:f9d13e09cf11 | 24 | |
| terencez | 0:f9d13e09cf11 | 25 | * Redistributions of source code must retain the above copyright notice, |
| terencez | 0:f9d13e09cf11 | 26 | this list of conditions and the following disclaimer. |
| terencez | 0:f9d13e09cf11 | 27 | * Redistributions in binary form must reproduce the above copyright notice, |
| terencez | 0:f9d13e09cf11 | 28 | this list of conditions and the following disclaimer in the documentation |
| terencez | 0:f9d13e09cf11 | 29 | and/or other materials provided with the distribution. |
| terencez | 0:f9d13e09cf11 | 30 | * Neither the name of Intel Corporation nor the names of its contributors |
| terencez | 0:f9d13e09cf11 | 31 | may be used to endorse or promote products derived from this software |
| terencez | 0:f9d13e09cf11 | 32 | without specific prior written permission. |
| terencez | 0:f9d13e09cf11 | 33 | |
| terencez | 0:f9d13e09cf11 | 34 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
| terencez | 0:f9d13e09cf11 | 35 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| terencez | 0:f9d13e09cf11 | 36 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| terencez | 0:f9d13e09cf11 | 37 | IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, |
| terencez | 0:f9d13e09cf11 | 38 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
| terencez | 0:f9d13e09cf11 | 39 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| terencez | 0:f9d13e09cf11 | 40 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| terencez | 0:f9d13e09cf11 | 41 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| terencez | 0:f9d13e09cf11 | 42 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
| terencez | 0:f9d13e09cf11 | 43 | THE POSSIBILITY OF SUCH DAMAGE. |
| terencez | 0:f9d13e09cf11 | 44 | |
| terencez | 0:f9d13e09cf11 | 45 | David Navarro <david.navarro@intel.com> |
| terencez | 0:f9d13e09cf11 | 46 | |
| terencez | 0:f9d13e09cf11 | 47 | */ |
| terencez | 0:f9d13e09cf11 | 48 | |
| terencez | 0:f9d13e09cf11 | 49 | #include "internals.h" |
| terencez | 0:f9d13e09cf11 | 50 | #include <stdio.h> |
| terencez | 0:f9d13e09cf11 | 51 | |
| terencez | 0:f9d13e09cf11 | 52 | |
| terencez | 0:f9d13e09cf11 | 53 | #ifdef LWM2M_CLIENT_MODE |
| terencez | 0:f9d13e09cf11 | 54 | coap_status_t handle_dm_request(lwm2m_context_t * contextP, |
| terencez | 0:f9d13e09cf11 | 55 | lwm2m_uri_t * uriP, |
| terencez | 0:f9d13e09cf11 | 56 | void * fromSessionH, |
| terencez | 0:f9d13e09cf11 | 57 | coap_packet_t * message, |
| terencez | 0:f9d13e09cf11 | 58 | coap_packet_t * response) |
| terencez | 0:f9d13e09cf11 | 59 | { |
| terencez | 0:f9d13e09cf11 | 60 | coap_status_t result; |
| terencez | 0:f9d13e09cf11 | 61 | |
| terencez | 0:f9d13e09cf11 | 62 | switch (message->code) |
| terencez | 0:f9d13e09cf11 | 63 | { |
| terencez | 0:f9d13e09cf11 | 64 | case COAP_GET: |
| terencez | 0:f9d13e09cf11 | 65 | { |
| terencez | 0:f9d13e09cf11 | 66 | char * buffer = NULL; |
| terencez | 0:f9d13e09cf11 | 67 | int length = 0; |
| terencez | 0:f9d13e09cf11 | 68 | |
| terencez | 0:f9d13e09cf11 | 69 | result = object_read(contextP, uriP, &buffer, &length); |
| terencez | 0:f9d13e09cf11 | 70 | if (result == COAP_205_CONTENT) |
| terencez | 0:f9d13e09cf11 | 71 | { |
| terencez | 0:f9d13e09cf11 | 72 | if (IS_OPTION(message, COAP_OPTION_OBSERVE)) |
| terencez | 0:f9d13e09cf11 | 73 | { |
| terencez | 0:f9d13e09cf11 | 74 | result = handle_observe_request(contextP, uriP, fromSessionH, message, response); |
| terencez | 0:f9d13e09cf11 | 75 | } |
| terencez | 0:f9d13e09cf11 | 76 | if (result == COAP_205_CONTENT) |
| terencez | 0:f9d13e09cf11 | 77 | { |
| terencez | 0:f9d13e09cf11 | 78 | coap_set_payload(response, buffer, length); |
| terencez | 0:f9d13e09cf11 | 79 | // lwm2m_handle_packet will free buffer |
| terencez | 0:f9d13e09cf11 | 80 | } |
| terencez | 0:f9d13e09cf11 | 81 | } |
| terencez | 0:f9d13e09cf11 | 82 | } |
| terencez | 0:f9d13e09cf11 | 83 | break; |
| terencez | 0:f9d13e09cf11 | 84 | case COAP_POST: |
| terencez | 0:f9d13e09cf11 | 85 | { |
| terencez | 0:f9d13e09cf11 | 86 | if (!LWM2M_URI_IS_SET_INSTANCE(uriP)) |
| terencez | 0:f9d13e09cf11 | 87 | { |
| terencez | 0:f9d13e09cf11 | 88 | result = object_create(contextP, uriP, message->payload, message->payload_len); |
| terencez | 0:f9d13e09cf11 | 89 | if (result == COAP_201_CREATED) |
| terencez | 0:f9d13e09cf11 | 90 | { |
| terencez | 0:f9d13e09cf11 | 91 | //longest uri is /65535/65535 = 12 + 1 (null) chars |
| terencez | 0:f9d13e09cf11 | 92 | char location_path[13] = ""; |
| terencez | 0:f9d13e09cf11 | 93 | //instanceId expected |
| terencez | 0:f9d13e09cf11 | 94 | if ((uriP->flag & LWM2M_URI_FLAG_INSTANCE_ID) == 0) |
| terencez | 0:f9d13e09cf11 | 95 | { |
| terencez | 0:f9d13e09cf11 | 96 | result = COAP_500_INTERNAL_SERVER_ERROR; |
| terencez | 0:f9d13e09cf11 | 97 | break; |
| terencez | 0:f9d13e09cf11 | 98 | } |
| terencez | 0:f9d13e09cf11 | 99 | |
| terencez | 0:f9d13e09cf11 | 100 | if (sprintf(location_path, "/%d/%d", uriP->objectId, uriP->instanceId) < 0) |
| terencez | 0:f9d13e09cf11 | 101 | { |
| terencez | 0:f9d13e09cf11 | 102 | result = COAP_500_INTERNAL_SERVER_ERROR; |
| terencez | 0:f9d13e09cf11 | 103 | break; |
| terencez | 0:f9d13e09cf11 | 104 | } |
| terencez | 0:f9d13e09cf11 | 105 | coap_set_header_location_path(response, location_path); |
| terencez | 0:f9d13e09cf11 | 106 | } |
| terencez | 0:f9d13e09cf11 | 107 | } |
| terencez | 0:f9d13e09cf11 | 108 | else if (!LWM2M_URI_IS_SET_RESOURCE(uriP)) |
| terencez | 0:f9d13e09cf11 | 109 | { |
| terencez | 0:f9d13e09cf11 | 110 | if (object_isInstanceNew(contextP, uriP->objectId, uriP->instanceId)) |
| terencez | 0:f9d13e09cf11 | 111 | { |
| terencez | 0:f9d13e09cf11 | 112 | result = object_create(contextP, uriP, message->payload, message->payload_len); |
| terencez | 0:f9d13e09cf11 | 113 | } |
| terencez | 0:f9d13e09cf11 | 114 | else |
| terencez | 0:f9d13e09cf11 | 115 | { |
| terencez | 0:f9d13e09cf11 | 116 | result = object_write(contextP, uriP, message->payload, message->payload_len); |
| terencez | 0:f9d13e09cf11 | 117 | } |
| terencez | 0:f9d13e09cf11 | 118 | } |
| terencez | 0:f9d13e09cf11 | 119 | else |
| terencez | 0:f9d13e09cf11 | 120 | { |
| terencez | 0:f9d13e09cf11 | 121 | result = object_execute(contextP, uriP, message->payload, message->payload_len); |
| terencez | 0:f9d13e09cf11 | 122 | } |
| terencez | 0:f9d13e09cf11 | 123 | } |
| terencez | 0:f9d13e09cf11 | 124 | break; |
| terencez | 0:f9d13e09cf11 | 125 | case COAP_PUT: |
| terencez | 0:f9d13e09cf11 | 126 | { |
| terencez | 0:f9d13e09cf11 | 127 | if (LWM2M_URI_IS_SET_INSTANCE(uriP)) |
| terencez | 0:f9d13e09cf11 | 128 | { |
| terencez | 0:f9d13e09cf11 | 129 | result = object_write(contextP, uriP, message->payload, message->payload_len); |
| terencez | 0:f9d13e09cf11 | 130 | } |
| terencez | 0:f9d13e09cf11 | 131 | else |
| terencez | 0:f9d13e09cf11 | 132 | { |
| terencez | 0:f9d13e09cf11 | 133 | result = BAD_REQUEST_4_00; |
| terencez | 0:f9d13e09cf11 | 134 | } |
| terencez | 0:f9d13e09cf11 | 135 | } |
| terencez | 0:f9d13e09cf11 | 136 | break; |
| terencez | 0:f9d13e09cf11 | 137 | case COAP_DELETE: |
| terencez | 0:f9d13e09cf11 | 138 | { |
| terencez | 0:f9d13e09cf11 | 139 | if (LWM2M_URI_IS_SET_INSTANCE(uriP) && !LWM2M_URI_IS_SET_RESOURCE(uriP)) |
| terencez | 0:f9d13e09cf11 | 140 | { |
| terencez | 0:f9d13e09cf11 | 141 | result = object_delete(contextP, uriP); |
| terencez | 0:f9d13e09cf11 | 142 | } |
| terencez | 0:f9d13e09cf11 | 143 | else |
| terencez | 0:f9d13e09cf11 | 144 | { |
| terencez | 0:f9d13e09cf11 | 145 | result = BAD_REQUEST_4_00; |
| terencez | 0:f9d13e09cf11 | 146 | } |
| terencez | 0:f9d13e09cf11 | 147 | } |
| terencez | 0:f9d13e09cf11 | 148 | break; |
| terencez | 0:f9d13e09cf11 | 149 | default: |
| terencez | 0:f9d13e09cf11 | 150 | result = BAD_REQUEST_4_00; |
| terencez | 0:f9d13e09cf11 | 151 | break; |
| terencez | 0:f9d13e09cf11 | 152 | } |
| terencez | 0:f9d13e09cf11 | 153 | |
| terencez | 0:f9d13e09cf11 | 154 | return result; |
| terencez | 0:f9d13e09cf11 | 155 | } |
| terencez | 0:f9d13e09cf11 | 156 | #endif |
| terencez | 0:f9d13e09cf11 | 157 | |
| terencez | 0:f9d13e09cf11 | 158 | #ifdef LWM2M_SERVER_MODE |
| terencez | 0:f9d13e09cf11 | 159 | |
| terencez | 0:f9d13e09cf11 | 160 | #define ID_AS_STRING_MAX_LEN 8 |
| terencez | 0:f9d13e09cf11 | 161 | |
| terencez | 0:f9d13e09cf11 | 162 | static void dm_result_callback(lwm2m_transaction_t * transacP, |
| terencez | 0:f9d13e09cf11 | 163 | void * message) |
| terencez | 0:f9d13e09cf11 | 164 | { |
| terencez | 0:f9d13e09cf11 | 165 | dm_data_t * dataP = (dm_data_t *)transacP->userData; |
| terencez | 0:f9d13e09cf11 | 166 | |
| terencez | 0:f9d13e09cf11 | 167 | if (message == NULL) |
| terencez | 0:f9d13e09cf11 | 168 | { |
| terencez | 0:f9d13e09cf11 | 169 | dataP->callback(((lwm2m_client_t*)transacP->peerP)->internalID, |
| terencez | 0:f9d13e09cf11 | 170 | &dataP->uri, |
| terencez | 0:f9d13e09cf11 | 171 | COAP_503_SERVICE_UNAVAILABLE, |
| terencez | 0:f9d13e09cf11 | 172 | NULL, 0, |
| terencez | 0:f9d13e09cf11 | 173 | dataP->userData); |
| terencez | 0:f9d13e09cf11 | 174 | } |
| terencez | 0:f9d13e09cf11 | 175 | else |
| terencez | 0:f9d13e09cf11 | 176 | { |
| terencez | 0:f9d13e09cf11 | 177 | coap_packet_t * packet = (coap_packet_t *)message; |
| terencez | 0:f9d13e09cf11 | 178 | |
| terencez | 0:f9d13e09cf11 | 179 | //if packet is a CREATE response and the instanceId was assigned by the client |
| terencez | 0:f9d13e09cf11 | 180 | if (packet->code == COAP_201_CREATED |
| terencez | 0:f9d13e09cf11 | 181 | && packet->location_path != NULL) |
| terencez | 0:f9d13e09cf11 | 182 | { |
| terencez | 0:f9d13e09cf11 | 183 | char * locationString = NULL; |
| terencez | 0:f9d13e09cf11 | 184 | int result = 0; |
| terencez | 0:f9d13e09cf11 | 185 | lwm2m_uri_t locationUri; |
| terencez | 0:f9d13e09cf11 | 186 | |
| terencez | 0:f9d13e09cf11 | 187 | locationString = coap_get_multi_option_as_string(packet->location_path); |
| terencez | 0:f9d13e09cf11 | 188 | if (locationString == NULL) |
| terencez | 0:f9d13e09cf11 | 189 | { |
| terencez | 0:f9d13e09cf11 | 190 | fprintf(stderr, "Error: coap_get_multi_option_as_string() failed for Location_path option in dm_result_callback()\n"); |
| terencez | 0:f9d13e09cf11 | 191 | return; |
| terencez | 0:f9d13e09cf11 | 192 | } |
| terencez | 0:f9d13e09cf11 | 193 | |
| terencez | 0:f9d13e09cf11 | 194 | result = lwm2m_stringToUri(locationString, strlen(locationString), &locationUri); |
| terencez | 0:f9d13e09cf11 | 195 | if (result == 0) |
| terencez | 0:f9d13e09cf11 | 196 | { |
| terencez | 0:f9d13e09cf11 | 197 | fprintf(stderr, "Error: lwm2m_stringToUri() failed for Location_path option in dm_result_callback()\n"); |
| terencez | 0:f9d13e09cf11 | 198 | lwm2m_free(locationString); |
| terencez | 0:f9d13e09cf11 | 199 | return; |
| terencez | 0:f9d13e09cf11 | 200 | } |
| terencez | 0:f9d13e09cf11 | 201 | |
| terencez | 0:f9d13e09cf11 | 202 | ((dm_data_t*)transacP->userData)->uri.instanceId = locationUri.instanceId; |
| terencez | 0:f9d13e09cf11 | 203 | ((dm_data_t*)transacP->userData)->uri.flag = locationUri.flag; |
| terencez | 0:f9d13e09cf11 | 204 | |
| terencez | 0:f9d13e09cf11 | 205 | lwm2m_free(locationString); |
| terencez | 0:f9d13e09cf11 | 206 | } |
| terencez | 0:f9d13e09cf11 | 207 | |
| terencez | 0:f9d13e09cf11 | 208 | dataP->callback(((lwm2m_client_t*)transacP->peerP)->internalID, |
| terencez | 0:f9d13e09cf11 | 209 | &dataP->uri, |
| terencez | 0:f9d13e09cf11 | 210 | packet->code, |
| terencez | 0:f9d13e09cf11 | 211 | packet->payload, |
| terencez | 0:f9d13e09cf11 | 212 | packet->payload_len, |
| terencez | 0:f9d13e09cf11 | 213 | dataP->userData); |
| terencez | 0:f9d13e09cf11 | 214 | } |
| terencez | 0:f9d13e09cf11 | 215 | lwm2m_free(dataP); |
| terencez | 0:f9d13e09cf11 | 216 | } |
| terencez | 0:f9d13e09cf11 | 217 | |
| terencez | 0:f9d13e09cf11 | 218 | static int prv_make_operation(lwm2m_context_t * contextP, |
| terencez | 0:f9d13e09cf11 | 219 | uint16_t clientID, |
| terencez | 0:f9d13e09cf11 | 220 | lwm2m_uri_t * uriP, |
| terencez | 0:f9d13e09cf11 | 221 | coap_method_t method, |
| terencez | 0:f9d13e09cf11 | 222 | char * buffer, |
| terencez | 0:f9d13e09cf11 | 223 | int length, |
| terencez | 0:f9d13e09cf11 | 224 | lwm2m_result_callback_t callback, |
| terencez | 0:f9d13e09cf11 | 225 | void * userData) |
| terencez | 0:f9d13e09cf11 | 226 | { |
| terencez | 0:f9d13e09cf11 | 227 | lwm2m_client_t * clientP; |
| terencez | 0:f9d13e09cf11 | 228 | lwm2m_transaction_t * transaction; |
| terencez | 0:f9d13e09cf11 | 229 | dm_data_t * dataP; |
| terencez | 0:f9d13e09cf11 | 230 | |
| terencez | 0:f9d13e09cf11 | 231 | clientP = (lwm2m_client_t *)lwm2m_list_find((lwm2m_list_t *)contextP->clientList, clientID); |
| terencez | 0:f9d13e09cf11 | 232 | if (clientP == NULL) return COAP_404_NOT_FOUND; |
| terencez | 0:f9d13e09cf11 | 233 | |
| terencez | 0:f9d13e09cf11 | 234 | transaction = transaction_new(method, uriP, contextP->nextMID++, ENDPOINT_CLIENT, (void *)clientP); |
| terencez | 0:f9d13e09cf11 | 235 | if (transaction == NULL) return INTERNAL_SERVER_ERROR_5_00; |
| terencez | 0:f9d13e09cf11 | 236 | |
| terencez | 0:f9d13e09cf11 | 237 | if (buffer != NULL) |
| terencez | 0:f9d13e09cf11 | 238 | { |
| terencez | 0:f9d13e09cf11 | 239 | // TODO: Take care of fragmentation |
| terencez | 0:f9d13e09cf11 | 240 | coap_set_payload(transaction->message, buffer, length); |
| terencez | 0:f9d13e09cf11 | 241 | } |
| terencez | 0:f9d13e09cf11 | 242 | |
| terencez | 0:f9d13e09cf11 | 243 | if (callback != NULL) |
| terencez | 0:f9d13e09cf11 | 244 | { |
| terencez | 0:f9d13e09cf11 | 245 | dataP = (dm_data_t *)lwm2m_malloc(sizeof(dm_data_t)); |
| terencez | 0:f9d13e09cf11 | 246 | if (dataP == NULL) |
| terencez | 0:f9d13e09cf11 | 247 | { |
| terencez | 0:f9d13e09cf11 | 248 | transaction_free(transaction); |
| terencez | 0:f9d13e09cf11 | 249 | return COAP_500_INTERNAL_SERVER_ERROR; |
| terencez | 0:f9d13e09cf11 | 250 | } |
| terencez | 0:f9d13e09cf11 | 251 | memcpy(&dataP->uri, uriP, sizeof(lwm2m_uri_t)); |
| terencez | 0:f9d13e09cf11 | 252 | dataP->callback = callback; |
| terencez | 0:f9d13e09cf11 | 253 | dataP->userData = userData; |
| terencez | 0:f9d13e09cf11 | 254 | |
| terencez | 0:f9d13e09cf11 | 255 | transaction->callback = dm_result_callback; |
| terencez | 0:f9d13e09cf11 | 256 | transaction->userData = (void *)dataP; |
| terencez | 0:f9d13e09cf11 | 257 | } |
| terencez | 0:f9d13e09cf11 | 258 | |
| terencez | 0:f9d13e09cf11 | 259 | contextP->transactionList = (lwm2m_transaction_t *)LWM2M_LIST_ADD(contextP->transactionList, transaction); |
| terencez | 0:f9d13e09cf11 | 260 | |
| terencez | 0:f9d13e09cf11 | 261 | return transaction_send(contextP, transaction); |
| terencez | 0:f9d13e09cf11 | 262 | } |
| terencez | 0:f9d13e09cf11 | 263 | |
| terencez | 0:f9d13e09cf11 | 264 | int lwm2m_dm_read(lwm2m_context_t * contextP, |
| terencez | 0:f9d13e09cf11 | 265 | uint16_t clientID, |
| terencez | 0:f9d13e09cf11 | 266 | lwm2m_uri_t * uriP, |
| terencez | 0:f9d13e09cf11 | 267 | lwm2m_result_callback_t callback, |
| terencez | 0:f9d13e09cf11 | 268 | void * userData) |
| terencez | 0:f9d13e09cf11 | 269 | { |
| terencez | 0:f9d13e09cf11 | 270 | return prv_make_operation(contextP, clientID, uriP, |
| terencez | 0:f9d13e09cf11 | 271 | COAP_GET, NULL, 0, |
| terencez | 0:f9d13e09cf11 | 272 | callback, userData); |
| terencez | 0:f9d13e09cf11 | 273 | } |
| terencez | 0:f9d13e09cf11 | 274 | |
| terencez | 0:f9d13e09cf11 | 275 | int lwm2m_dm_write(lwm2m_context_t * contextP, |
| terencez | 0:f9d13e09cf11 | 276 | uint16_t clientID, |
| terencez | 0:f9d13e09cf11 | 277 | lwm2m_uri_t * uriP, |
| terencez | 0:f9d13e09cf11 | 278 | char * buffer, |
| terencez | 0:f9d13e09cf11 | 279 | int length, |
| terencez | 0:f9d13e09cf11 | 280 | lwm2m_result_callback_t callback, |
| terencez | 0:f9d13e09cf11 | 281 | void * userData) |
| terencez | 0:f9d13e09cf11 | 282 | { |
| terencez | 0:f9d13e09cf11 | 283 | if (!LWM2M_URI_IS_SET_INSTANCE(uriP) |
| terencez | 0:f9d13e09cf11 | 284 | || length == 0) |
| terencez | 0:f9d13e09cf11 | 285 | { |
| terencez | 0:f9d13e09cf11 | 286 | return COAP_400_BAD_REQUEST; |
| terencez | 0:f9d13e09cf11 | 287 | } |
| terencez | 0:f9d13e09cf11 | 288 | |
| terencez | 0:f9d13e09cf11 | 289 | if (LWM2M_URI_IS_SET_RESOURCE(uriP)) |
| terencez | 0:f9d13e09cf11 | 290 | { |
| terencez | 0:f9d13e09cf11 | 291 | return prv_make_operation(contextP, clientID, uriP, |
| terencez | 0:f9d13e09cf11 | 292 | COAP_PUT, buffer, length, |
| terencez | 0:f9d13e09cf11 | 293 | callback, userData); |
| terencez | 0:f9d13e09cf11 | 294 | } |
| terencez | 0:f9d13e09cf11 | 295 | else |
| terencez | 0:f9d13e09cf11 | 296 | { |
| terencez | 0:f9d13e09cf11 | 297 | return prv_make_operation(contextP, clientID, uriP, |
| terencez | 0:f9d13e09cf11 | 298 | COAP_POST, buffer, length, |
| terencez | 0:f9d13e09cf11 | 299 | callback, userData); |
| terencez | 0:f9d13e09cf11 | 300 | } |
| terencez | 0:f9d13e09cf11 | 301 | } |
| terencez | 0:f9d13e09cf11 | 302 | |
| terencez | 0:f9d13e09cf11 | 303 | int lwm2m_dm_execute(lwm2m_context_t * contextP, |
| terencez | 0:f9d13e09cf11 | 304 | uint16_t clientID, |
| terencez | 0:f9d13e09cf11 | 305 | lwm2m_uri_t * uriP, |
| terencez | 0:f9d13e09cf11 | 306 | char * buffer, |
| terencez | 0:f9d13e09cf11 | 307 | int length, |
| terencez | 0:f9d13e09cf11 | 308 | lwm2m_result_callback_t callback, |
| terencez | 0:f9d13e09cf11 | 309 | void * userData) |
| terencez | 0:f9d13e09cf11 | 310 | { |
| terencez | 0:f9d13e09cf11 | 311 | if (!LWM2M_URI_IS_SET_RESOURCE(uriP)) |
| terencez | 0:f9d13e09cf11 | 312 | { |
| terencez | 0:f9d13e09cf11 | 313 | return COAP_400_BAD_REQUEST; |
| terencez | 0:f9d13e09cf11 | 314 | } |
| terencez | 0:f9d13e09cf11 | 315 | |
| terencez | 0:f9d13e09cf11 | 316 | return prv_make_operation(contextP, clientID, uriP, |
| terencez | 0:f9d13e09cf11 | 317 | COAP_POST, buffer, length, |
| terencez | 0:f9d13e09cf11 | 318 | callback, userData); |
| terencez | 0:f9d13e09cf11 | 319 | } |
| terencez | 0:f9d13e09cf11 | 320 | |
| terencez | 0:f9d13e09cf11 | 321 | int lwm2m_dm_create(lwm2m_context_t * contextP, |
| terencez | 0:f9d13e09cf11 | 322 | uint16_t clientID, |
| terencez | 0:f9d13e09cf11 | 323 | lwm2m_uri_t * uriP, |
| terencez | 0:f9d13e09cf11 | 324 | char * buffer, |
| terencez | 0:f9d13e09cf11 | 325 | int length, |
| terencez | 0:f9d13e09cf11 | 326 | lwm2m_result_callback_t callback, |
| terencez | 0:f9d13e09cf11 | 327 | void * userData) |
| terencez | 0:f9d13e09cf11 | 328 | { |
| terencez | 0:f9d13e09cf11 | 329 | if (LWM2M_URI_IS_SET_RESOURCE(uriP) |
| terencez | 0:f9d13e09cf11 | 330 | || length == 0) |
| terencez | 0:f9d13e09cf11 | 331 | { |
| terencez | 0:f9d13e09cf11 | 332 | return COAP_400_BAD_REQUEST; |
| terencez | 0:f9d13e09cf11 | 333 | } |
| terencez | 0:f9d13e09cf11 | 334 | |
| terencez | 0:f9d13e09cf11 | 335 | return prv_make_operation(contextP, clientID, uriP, |
| terencez | 0:f9d13e09cf11 | 336 | COAP_POST, buffer, length, |
| terencez | 0:f9d13e09cf11 | 337 | callback, userData); |
| terencez | 0:f9d13e09cf11 | 338 | } |
| terencez | 0:f9d13e09cf11 | 339 | |
| terencez | 0:f9d13e09cf11 | 340 | int lwm2m_dm_delete(lwm2m_context_t * contextP, |
| terencez | 0:f9d13e09cf11 | 341 | uint16_t clientID, |
| terencez | 0:f9d13e09cf11 | 342 | lwm2m_uri_t * uriP, |
| terencez | 0:f9d13e09cf11 | 343 | lwm2m_result_callback_t callback, |
| terencez | 0:f9d13e09cf11 | 344 | void * userData) |
| terencez | 0:f9d13e09cf11 | 345 | { |
| terencez | 0:f9d13e09cf11 | 346 | if (!LWM2M_URI_IS_SET_INSTANCE(uriP) |
| terencez | 0:f9d13e09cf11 | 347 | || LWM2M_URI_IS_SET_RESOURCE(uriP)) |
| terencez | 0:f9d13e09cf11 | 348 | { |
| terencez | 0:f9d13e09cf11 | 349 | return COAP_400_BAD_REQUEST; |
| terencez | 0:f9d13e09cf11 | 350 | } |
| terencez | 0:f9d13e09cf11 | 351 | |
| terencez | 0:f9d13e09cf11 | 352 | return prv_make_operation(contextP, clientID, uriP, |
| terencez | 0:f9d13e09cf11 | 353 | COAP_DELETE, NULL, 0, |
| terencez | 0:f9d13e09cf11 | 354 | callback, userData); |
| terencez | 0:f9d13e09cf11 | 355 | } |
| terencez | 0:f9d13e09cf11 | 356 | #endif |