Jim Carver / Mbed OS mbed-cloud-workshop-connect
Committer:
JimCarver
Date:
Fri Oct 12 21:22:49 2018 +0000
Revision:
0:6b753f761943
Initial commit

Who changed what in which revision?

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