Toyomasa Watarai / simple-mbed-cloud-client

Dependents:  

Committer:
MACRUM
Date:
Mon Jul 02 08:06:37 2018 +0000
Revision:
2:bf2124b482f9
Parent:
0:276e7a263c35
Update library

Who changed what in which revision?

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