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.
simple-mbed-cloud-client/mbed-cloud-client/mbed-client/source/nsdlaccesshelper.cpp@0:8f0bb79ddd48, 2021-05-04 (annotated)
- Committer:
- leothedragon
- Date:
- Tue May 04 08:55:12 2021 +0000
- Revision:
- 0:8f0bb79ddd48
nmn
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
leothedragon | 0:8f0bb79ddd48 | 1 | /* |
leothedragon | 0:8f0bb79ddd48 | 2 | * Copyright (c) 2015 ARM Limited. All rights reserved. |
leothedragon | 0:8f0bb79ddd48 | 3 | * SPDX-License-Identifier: Apache-2.0 |
leothedragon | 0:8f0bb79ddd48 | 4 | * Licensed under the Apache License, Version 2.0 (the License); you may |
leothedragon | 0:8f0bb79ddd48 | 5 | * not use this file except in compliance with the License. |
leothedragon | 0:8f0bb79ddd48 | 6 | * You may obtain a copy of the License at |
leothedragon | 0:8f0bb79ddd48 | 7 | * |
leothedragon | 0:8f0bb79ddd48 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
leothedragon | 0:8f0bb79ddd48 | 9 | * |
leothedragon | 0:8f0bb79ddd48 | 10 | * Unless required by applicable law or agreed to in writing, software |
leothedragon | 0:8f0bb79ddd48 | 11 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT |
leothedragon | 0:8f0bb79ddd48 | 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
leothedragon | 0:8f0bb79ddd48 | 13 | * See the License for the specific language governing permissions and |
leothedragon | 0:8f0bb79ddd48 | 14 | * limitations under the License. |
leothedragon | 0:8f0bb79ddd48 | 15 | */ |
leothedragon | 0:8f0bb79ddd48 | 16 | #include "include/nsdlaccesshelper.h" |
leothedragon | 0:8f0bb79ddd48 | 17 | #include "include/m2mnsdlinterface.h" |
leothedragon | 0:8f0bb79ddd48 | 18 | #include "sn_nsdl_lib.h" |
leothedragon | 0:8f0bb79ddd48 | 19 | #include "sn_grs.h" |
leothedragon | 0:8f0bb79ddd48 | 20 | #include <stdlib.h> |
leothedragon | 0:8f0bb79ddd48 | 21 | |
leothedragon | 0:8f0bb79ddd48 | 22 | // callback function for NSDL library to call into |
leothedragon | 0:8f0bb79ddd48 | 23 | uint8_t __nsdl_c_callback(struct nsdl_s *nsdl_handle, |
leothedragon | 0:8f0bb79ddd48 | 24 | sn_coap_hdr_s *received_coap_ptr, |
leothedragon | 0:8f0bb79ddd48 | 25 | sn_nsdl_addr_s *address, |
leothedragon | 0:8f0bb79ddd48 | 26 | sn_nsdl_capab_e nsdl_capab) |
leothedragon | 0:8f0bb79ddd48 | 27 | { |
leothedragon | 0:8f0bb79ddd48 | 28 | uint8_t status = 0; |
leothedragon | 0:8f0bb79ddd48 | 29 | M2MNsdlInterface *interface = (M2MNsdlInterface*)sn_nsdl_get_context(nsdl_handle); |
leothedragon | 0:8f0bb79ddd48 | 30 | if(interface) { |
leothedragon | 0:8f0bb79ddd48 | 31 | status = interface->resource_callback(nsdl_handle, |
leothedragon | 0:8f0bb79ddd48 | 32 | received_coap_ptr, |
leothedragon | 0:8f0bb79ddd48 | 33 | address, nsdl_capab); |
leothedragon | 0:8f0bb79ddd48 | 34 | } |
leothedragon | 0:8f0bb79ddd48 | 35 | return status; |
leothedragon | 0:8f0bb79ddd48 | 36 | } |
leothedragon | 0:8f0bb79ddd48 | 37 | |
leothedragon | 0:8f0bb79ddd48 | 38 | void* __nsdl_c_memory_alloc(uint16_t size) |
leothedragon | 0:8f0bb79ddd48 | 39 | { |
leothedragon | 0:8f0bb79ddd48 | 40 | if(size) |
leothedragon | 0:8f0bb79ddd48 | 41 | return malloc(size); |
leothedragon | 0:8f0bb79ddd48 | 42 | else |
leothedragon | 0:8f0bb79ddd48 | 43 | return 0; |
leothedragon | 0:8f0bb79ddd48 | 44 | } |
leothedragon | 0:8f0bb79ddd48 | 45 | |
leothedragon | 0:8f0bb79ddd48 | 46 | void __nsdl_c_memory_free(void *ptr) |
leothedragon | 0:8f0bb79ddd48 | 47 | { |
leothedragon | 0:8f0bb79ddd48 | 48 | if(ptr) |
leothedragon | 0:8f0bb79ddd48 | 49 | free(ptr); |
leothedragon | 0:8f0bb79ddd48 | 50 | } |
leothedragon | 0:8f0bb79ddd48 | 51 | |
leothedragon | 0:8f0bb79ddd48 | 52 | uint8_t __nsdl_c_send_to_server(struct nsdl_s * nsdl_handle, |
leothedragon | 0:8f0bb79ddd48 | 53 | sn_nsdl_capab_e protocol, |
leothedragon | 0:8f0bb79ddd48 | 54 | uint8_t *data_ptr, |
leothedragon | 0:8f0bb79ddd48 | 55 | uint16_t data_len, |
leothedragon | 0:8f0bb79ddd48 | 56 | sn_nsdl_addr_s *address_ptr) |
leothedragon | 0:8f0bb79ddd48 | 57 | { |
leothedragon | 0:8f0bb79ddd48 | 58 | uint8_t status = 0; |
leothedragon | 0:8f0bb79ddd48 | 59 | M2MNsdlInterface *interface = (M2MNsdlInterface*)sn_nsdl_get_context(nsdl_handle); |
leothedragon | 0:8f0bb79ddd48 | 60 | #if MBED_CONF_MBED_TRACE_ENABLE |
leothedragon | 0:8f0bb79ddd48 | 61 | coap_version_e version = COAP_VERSION_UNKNOWN; |
leothedragon | 0:8f0bb79ddd48 | 62 | sn_coap_hdr_s *header = sn_coap_parser(nsdl_handle->grs->coap, data_len, data_ptr, &version); |
leothedragon | 0:8f0bb79ddd48 | 63 | sn_nsdl_print_coap_data(header, true); |
leothedragon | 0:8f0bb79ddd48 | 64 | sn_coap_parser_release_allocated_coap_msg_mem(nsdl_handle->grs->coap, header); |
leothedragon | 0:8f0bb79ddd48 | 65 | #endif |
leothedragon | 0:8f0bb79ddd48 | 66 | if(interface) { |
leothedragon | 0:8f0bb79ddd48 | 67 | status = interface->send_to_server_callback(nsdl_handle, |
leothedragon | 0:8f0bb79ddd48 | 68 | protocol, data_ptr, |
leothedragon | 0:8f0bb79ddd48 | 69 | data_len, address_ptr); |
leothedragon | 0:8f0bb79ddd48 | 70 | } |
leothedragon | 0:8f0bb79ddd48 | 71 | return status; |
leothedragon | 0:8f0bb79ddd48 | 72 | } |
leothedragon | 0:8f0bb79ddd48 | 73 | |
leothedragon | 0:8f0bb79ddd48 | 74 | uint8_t __nsdl_c_received_from_server(struct nsdl_s * nsdl_handle, |
leothedragon | 0:8f0bb79ddd48 | 75 | sn_coap_hdr_s *coap_header, |
leothedragon | 0:8f0bb79ddd48 | 76 | sn_nsdl_addr_s *address_ptr) |
leothedragon | 0:8f0bb79ddd48 | 77 | { |
leothedragon | 0:8f0bb79ddd48 | 78 | uint8_t status = 0; |
leothedragon | 0:8f0bb79ddd48 | 79 | M2MNsdlInterface *interface = (M2MNsdlInterface*)sn_nsdl_get_context(nsdl_handle); |
leothedragon | 0:8f0bb79ddd48 | 80 | if(interface) { |
leothedragon | 0:8f0bb79ddd48 | 81 | status = interface->received_from_server_callback(nsdl_handle, |
leothedragon | 0:8f0bb79ddd48 | 82 | coap_header, |
leothedragon | 0:8f0bb79ddd48 | 83 | address_ptr); |
leothedragon | 0:8f0bb79ddd48 | 84 | } |
leothedragon | 0:8f0bb79ddd48 | 85 | return status; |
leothedragon | 0:8f0bb79ddd48 | 86 | } |
leothedragon | 0:8f0bb79ddd48 | 87 | |
leothedragon | 0:8f0bb79ddd48 | 88 | uint8_t __nsdl_c_auto_obs_token(struct nsdl_s *nsdl_handle, const char *path, uint8_t *token) |
leothedragon | 0:8f0bb79ddd48 | 89 | { |
leothedragon | 0:8f0bb79ddd48 | 90 | M2MNsdlInterface *interface = (M2MNsdlInterface*)sn_nsdl_get_context(nsdl_handle); |
leothedragon | 0:8f0bb79ddd48 | 91 | if(interface) { |
leothedragon | 0:8f0bb79ddd48 | 92 | return interface->find_auto_obs_token(path, token); |
leothedragon | 0:8f0bb79ddd48 | 93 | } |
leothedragon | 0:8f0bb79ddd48 | 94 | return 0; |
leothedragon | 0:8f0bb79ddd48 | 95 | } |