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