mbed client on ethernet with LWIP
Dependencies: mbed Socket lwip-eth lwip-sys lwip
Fork of mbed-client-classic-example-lwip by
mbed-client/source/nsdlaccesshelper.cpp@11:cada08fc8a70, 2016-06-09 (annotated)
- Committer:
- mbedAustin
- Date:
- Thu Jun 09 17:08:36 2016 +0000
- Revision:
- 11:cada08fc8a70
Commit for public Consumption
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbedAustin | 11:cada08fc8a70 | 1 | /* |
mbedAustin | 11:cada08fc8a70 | 2 | * Copyright (c) 2015 ARM Limited. All rights reserved. |
mbedAustin | 11:cada08fc8a70 | 3 | * SPDX-License-Identifier: Apache-2.0 |
mbedAustin | 11:cada08fc8a70 | 4 | * Licensed under the Apache License, Version 2.0 (the License); you may |
mbedAustin | 11:cada08fc8a70 | 5 | * not use this file except in compliance with the License. |
mbedAustin | 11:cada08fc8a70 | 6 | * You may obtain a copy of the License at |
mbedAustin | 11:cada08fc8a70 | 7 | * |
mbedAustin | 11:cada08fc8a70 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
mbedAustin | 11:cada08fc8a70 | 9 | * |
mbedAustin | 11:cada08fc8a70 | 10 | * Unless required by applicable law or agreed to in writing, software |
mbedAustin | 11:cada08fc8a70 | 11 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT |
mbedAustin | 11:cada08fc8a70 | 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
mbedAustin | 11:cada08fc8a70 | 13 | * See the License for the specific language governing permissions and |
mbedAustin | 11:cada08fc8a70 | 14 | * limitations under the License. |
mbedAustin | 11:cada08fc8a70 | 15 | */ |
mbedAustin | 11:cada08fc8a70 | 16 | #include "include/nsdlaccesshelper.h" |
mbedAustin | 11:cada08fc8a70 | 17 | #include "include/m2mnsdlinterface.h" |
mbedAustin | 11:cada08fc8a70 | 18 | |
mbedAustin | 11:cada08fc8a70 | 19 | // callback function for NSDL library to call into |
mbedAustin | 11:cada08fc8a70 | 20 | M2MNsdlInterface *__nsdl_interface = NULL; |
mbedAustin | 11:cada08fc8a70 | 21 | |
mbedAustin | 11:cada08fc8a70 | 22 | uint8_t __nsdl_c_callback(struct nsdl_s *nsdl_handle, |
mbedAustin | 11:cada08fc8a70 | 23 | sn_coap_hdr_s *received_coap_ptr, |
mbedAustin | 11:cada08fc8a70 | 24 | sn_nsdl_addr_s *address, |
mbedAustin | 11:cada08fc8a70 | 25 | sn_nsdl_capab_e nsdl_capab) |
mbedAustin | 11:cada08fc8a70 | 26 | { |
mbedAustin | 11:cada08fc8a70 | 27 | uint8_t status = 0; |
mbedAustin | 11:cada08fc8a70 | 28 | if(__nsdl_interface) { |
mbedAustin | 11:cada08fc8a70 | 29 | status = __nsdl_interface->resource_callback(nsdl_handle,received_coap_ptr, |
mbedAustin | 11:cada08fc8a70 | 30 | address, nsdl_capab); |
mbedAustin | 11:cada08fc8a70 | 31 | } |
mbedAustin | 11:cada08fc8a70 | 32 | return status; |
mbedAustin | 11:cada08fc8a70 | 33 | } |
mbedAustin | 11:cada08fc8a70 | 34 | |
mbedAustin | 11:cada08fc8a70 | 35 | void* __nsdl_c_memory_alloc(uint16_t size) |
mbedAustin | 11:cada08fc8a70 | 36 | { |
mbedAustin | 11:cada08fc8a70 | 37 | void * val = NULL; |
mbedAustin | 11:cada08fc8a70 | 38 | if(__nsdl_interface) { |
mbedAustin | 11:cada08fc8a70 | 39 | val = __nsdl_interface->memory_alloc(size); |
mbedAustin | 11:cada08fc8a70 | 40 | } |
mbedAustin | 11:cada08fc8a70 | 41 | return val; |
mbedAustin | 11:cada08fc8a70 | 42 | } |
mbedAustin | 11:cada08fc8a70 | 43 | |
mbedAustin | 11:cada08fc8a70 | 44 | void __nsdl_c_memory_free(void *ptr) |
mbedAustin | 11:cada08fc8a70 | 45 | { |
mbedAustin | 11:cada08fc8a70 | 46 | if(__nsdl_interface) { |
mbedAustin | 11:cada08fc8a70 | 47 | __nsdl_interface->memory_free(ptr); |
mbedAustin | 11:cada08fc8a70 | 48 | } |
mbedAustin | 11:cada08fc8a70 | 49 | } |
mbedAustin | 11:cada08fc8a70 | 50 | |
mbedAustin | 11:cada08fc8a70 | 51 | uint8_t __nsdl_c_send_to_server(struct nsdl_s * nsdl_handle, |
mbedAustin | 11:cada08fc8a70 | 52 | sn_nsdl_capab_e protocol, |
mbedAustin | 11:cada08fc8a70 | 53 | uint8_t *data_ptr, |
mbedAustin | 11:cada08fc8a70 | 54 | uint16_t data_len, |
mbedAustin | 11:cada08fc8a70 | 55 | sn_nsdl_addr_s *address_ptr) |
mbedAustin | 11:cada08fc8a70 | 56 | { |
mbedAustin | 11:cada08fc8a70 | 57 | uint8_t status = 0; |
mbedAustin | 11:cada08fc8a70 | 58 | if(__nsdl_interface) { |
mbedAustin | 11:cada08fc8a70 | 59 | status = __nsdl_interface->send_to_server_callback(nsdl_handle, |
mbedAustin | 11:cada08fc8a70 | 60 | protocol, data_ptr, |
mbedAustin | 11:cada08fc8a70 | 61 | data_len, address_ptr); |
mbedAustin | 11:cada08fc8a70 | 62 | } |
mbedAustin | 11:cada08fc8a70 | 63 | return status; |
mbedAustin | 11:cada08fc8a70 | 64 | } |
mbedAustin | 11:cada08fc8a70 | 65 | |
mbedAustin | 11:cada08fc8a70 | 66 | uint8_t __nsdl_c_received_from_server(struct nsdl_s * nsdl_handle, |
mbedAustin | 11:cada08fc8a70 | 67 | sn_coap_hdr_s *coap_header, |
mbedAustin | 11:cada08fc8a70 | 68 | sn_nsdl_addr_s *address_ptr) |
mbedAustin | 11:cada08fc8a70 | 69 | { |
mbedAustin | 11:cada08fc8a70 | 70 | uint8_t status = 0; |
mbedAustin | 11:cada08fc8a70 | 71 | if(__nsdl_interface) { |
mbedAustin | 11:cada08fc8a70 | 72 | status = __nsdl_interface->received_from_server_callback(nsdl_handle, |
mbedAustin | 11:cada08fc8a70 | 73 | coap_header, |
mbedAustin | 11:cada08fc8a70 | 74 | address_ptr); |
mbedAustin | 11:cada08fc8a70 | 75 | } |
mbedAustin | 11:cada08fc8a70 | 76 | return status; |
mbedAustin | 11:cada08fc8a70 | 77 | } |
mbedAustin | 11:cada08fc8a70 | 78 | |
mbedAustin | 11:cada08fc8a70 | 79 | void __nsdl_c_bootstrap_done(sn_nsdl_oma_server_info_t *server_info_ptr) |
mbedAustin | 11:cada08fc8a70 | 80 | { |
mbedAustin | 11:cada08fc8a70 | 81 | if(__nsdl_interface) { |
mbedAustin | 11:cada08fc8a70 | 82 | __nsdl_interface->bootstrap_done_callback(server_info_ptr); |
mbedAustin | 11:cada08fc8a70 | 83 | } |
mbedAustin | 11:cada08fc8a70 | 84 | } |
mbedAustin | 11:cada08fc8a70 | 85 | |
mbedAustin | 11:cada08fc8a70 | 86 | void* __socket_malloc( void * context, size_t size) |
mbedAustin | 11:cada08fc8a70 | 87 | { |
mbedAustin | 11:cada08fc8a70 | 88 | (void) context; |
mbedAustin | 11:cada08fc8a70 | 89 | return malloc(size); |
mbedAustin | 11:cada08fc8a70 | 90 | } |
mbedAustin | 11:cada08fc8a70 | 91 | |
mbedAustin | 11:cada08fc8a70 | 92 | void __socket_free(void * context, void * ptr) |
mbedAustin | 11:cada08fc8a70 | 93 | { |
mbedAustin | 11:cada08fc8a70 | 94 | (void) context; |
mbedAustin | 11:cada08fc8a70 | 95 | free(ptr); |
mbedAustin | 11:cada08fc8a70 | 96 | } |