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.
mbed-cloud-client/mbed-client/mbed-client-c/source/include/sn_grs.h@0:276e7a263c35, 2018-07-02 (annotated)
- Committer:
 - MACRUM
 - Date:
 - Mon Jul 02 06:30:39 2018 +0000
 - Revision:
 - 0:276e7a263c35
 
Initial commit
Who changed what in which revision?
| User | Revision | Line number | New contents of line | 
|---|---|---|---|
| MACRUM | 0:276e7a263c35 | 1 | /* | 
| MACRUM | 0:276e7a263c35 | 2 | * Copyright (c) 2011-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 | #ifndef GRS_H_ | 
| MACRUM | 0:276e7a263c35 | 17 | #define GRS_H_ | 
| MACRUM | 0:276e7a263c35 | 18 | |
| MACRUM | 0:276e7a263c35 | 19 | |
| MACRUM | 0:276e7a263c35 | 20 | #ifdef __cplusplus | 
| MACRUM | 0:276e7a263c35 | 21 | extern "C" { | 
| MACRUM | 0:276e7a263c35 | 22 | #endif | 
| MACRUM | 0:276e7a263c35 | 23 | |
| MACRUM | 0:276e7a263c35 | 24 | |
| MACRUM | 0:276e7a263c35 | 25 | #define SN_GRS_RESOURCE_ALREADY_EXISTS -2 | 
| MACRUM | 0:276e7a263c35 | 26 | #define SN_GRS_INVALID_PATH -3 | 
| MACRUM | 0:276e7a263c35 | 27 | #define SN_GRS_LIST_ADDING_FAILURE -4 | 
| MACRUM | 0:276e7a263c35 | 28 | #define SN_GRS_RESOURCE_UPDATED -5 | 
| MACRUM | 0:276e7a263c35 | 29 | |
| MACRUM | 0:276e7a263c35 | 30 | #define ACCESS_DENIED -6 | 
| MACRUM | 0:276e7a263c35 | 31 | |
| MACRUM | 0:276e7a263c35 | 32 | #define SN_GRS_DELETE_METHOD 0 | 
| MACRUM | 0:276e7a263c35 | 33 | #define SN_GRS_SEARCH_METHOD 1 | 
| MACRUM | 0:276e7a263c35 | 34 | |
| MACRUM | 0:276e7a263c35 | 35 | #define SN_GRS_DEFAULT_ACCESS 0x0F | 
| MACRUM | 0:276e7a263c35 | 36 | |
| MACRUM | 0:276e7a263c35 | 37 | #define SN_NDSL_RESOURCE_NOT_REGISTERED 0 | 
| MACRUM | 0:276e7a263c35 | 38 | #define SN_NDSL_RESOURCE_REGISTERING 1 | 
| MACRUM | 0:276e7a263c35 | 39 | #define SN_NDSL_RESOURCE_REGISTERED 2 | 
| MACRUM | 0:276e7a263c35 | 40 | |
| MACRUM | 0:276e7a263c35 | 41 | /***** Structs *****/ | 
| MACRUM | 0:276e7a263c35 | 42 | |
| MACRUM | 0:276e7a263c35 | 43 | typedef struct sn_grs_version_ { | 
| MACRUM | 0:276e7a263c35 | 44 | uint8_t major_version; | 
| MACRUM | 0:276e7a263c35 | 45 | uint8_t minor_version; | 
| MACRUM | 0:276e7a263c35 | 46 | uint8_t build; | 
| MACRUM | 0:276e7a263c35 | 47 | } sn_grs_version_s; | 
| MACRUM | 0:276e7a263c35 | 48 | |
| MACRUM | 0:276e7a263c35 | 49 | typedef NS_LIST_HEAD(sn_nsdl_dynamic_resource_parameters_s, link) resource_list_t; | 
| MACRUM | 0:276e7a263c35 | 50 | |
| MACRUM | 0:276e7a263c35 | 51 | struct grs_s { | 
| MACRUM | 0:276e7a263c35 | 52 | struct coap_s *coap; | 
| MACRUM | 0:276e7a263c35 | 53 | |
| MACRUM | 0:276e7a263c35 | 54 | void *(*sn_grs_alloc)(uint16_t); | 
| MACRUM | 0:276e7a263c35 | 55 | void (*sn_grs_free)(void *); | 
| MACRUM | 0:276e7a263c35 | 56 | uint8_t (*sn_grs_tx_callback)(struct nsdl_s *, sn_nsdl_capab_e , uint8_t *, uint16_t, sn_nsdl_addr_s *); | 
| MACRUM | 0:276e7a263c35 | 57 | int8_t (*sn_grs_rx_callback)(struct nsdl_s *, sn_coap_hdr_s *, sn_nsdl_addr_s *); | 
| MACRUM | 0:276e7a263c35 | 58 | |
| MACRUM | 0:276e7a263c35 | 59 | uint16_t resource_root_count; | 
| MACRUM | 0:276e7a263c35 | 60 | resource_list_t resource_root_list; | 
| MACRUM | 0:276e7a263c35 | 61 | }; | 
| MACRUM | 0:276e7a263c35 | 62 | |
| MACRUM | 0:276e7a263c35 | 63 | |
| MACRUM | 0:276e7a263c35 | 64 | struct nsdl_s { | 
| MACRUM | 0:276e7a263c35 | 65 | uint16_t update_register_msg_id; | 
| MACRUM | 0:276e7a263c35 | 66 | uint16_t register_msg_len; | 
| MACRUM | 0:276e7a263c35 | 67 | uint16_t update_register_msg_len; | 
| MACRUM | 0:276e7a263c35 | 68 | |
| MACRUM | 0:276e7a263c35 | 69 | uint16_t register_msg_id; | 
| MACRUM | 0:276e7a263c35 | 70 | uint16_t unregister_msg_id; | 
| MACRUM | 0:276e7a263c35 | 71 | |
| MACRUM | 0:276e7a263c35 | 72 | uint16_t bootstrap_msg_id; | 
| MACRUM | 0:276e7a263c35 | 73 | uint16_t oma_bs_port; /* Bootstrap port */ | 
| MACRUM | 0:276e7a263c35 | 74 | uint8_t oma_bs_address_len; /* Bootstrap address length */ | 
| MACRUM | 0:276e7a263c35 | 75 | unsigned int sn_nsdl_endpoint_registered:1; | 
| MACRUM | 0:276e7a263c35 | 76 | |
| MACRUM | 0:276e7a263c35 | 77 | struct grs_s *grs; | 
| MACRUM | 0:276e7a263c35 | 78 | uint8_t *oma_bs_address_ptr; /* Bootstrap address pointer. If null, no bootstrap in use */ | 
| MACRUM | 0:276e7a263c35 | 79 | sn_nsdl_ep_parameters_s *ep_information_ptr; // Endpoint parameters, Name, Domain etc.. | 
| MACRUM | 0:276e7a263c35 | 80 | sn_nsdl_oma_server_info_t *nsp_address_ptr; // NSP server address information | 
| MACRUM | 0:276e7a263c35 | 81 | /* Application definable context. This is useful for example when interfacing with c++ objects where a pointer to object is set as the | 
| MACRUM | 0:276e7a263c35 | 82 | * context, and in the callback functions the context pointer can be used to call methods for the correct instance of the c++ object. */ | 
| MACRUM | 0:276e7a263c35 | 83 | void *context; | 
| MACRUM | 0:276e7a263c35 | 84 | |
| MACRUM | 0:276e7a263c35 | 85 | void (*sn_nsdl_oma_bs_done_cb)(sn_nsdl_oma_server_info_t *server_info_ptr); /* Callback to inform application when bootstrap is done */ | 
| MACRUM | 0:276e7a263c35 | 86 | void *(*sn_nsdl_alloc)(uint16_t); | 
| MACRUM | 0:276e7a263c35 | 87 | void (*sn_nsdl_free)(void *); | 
| MACRUM | 0:276e7a263c35 | 88 | uint8_t (*sn_nsdl_tx_callback)(struct nsdl_s *, sn_nsdl_capab_e , uint8_t *, uint16_t, sn_nsdl_addr_s *); | 
| MACRUM | 0:276e7a263c35 | 89 | uint8_t (*sn_nsdl_rx_callback)(struct nsdl_s *, sn_coap_hdr_s *, sn_nsdl_addr_s *); | 
| MACRUM | 0:276e7a263c35 | 90 | void (*sn_nsdl_oma_bs_done_cb_handle)(sn_nsdl_oma_server_info_t *server_info_ptr, | 
| MACRUM | 0:276e7a263c35 | 91 | struct nsdl_s *handle); /* Callback to inform application when bootstrap is done with nsdl handle */ | 
| MACRUM | 0:276e7a263c35 | 92 | uint8_t (*sn_nsdl_auto_obs_token_callback)(struct nsdl_s *, const char*, uint8_t*); | 
| MACRUM | 0:276e7a263c35 | 93 | }; | 
| MACRUM | 0:276e7a263c35 | 94 | |
| MACRUM | 0:276e7a263c35 | 95 | /***** Function prototypes *****/ | 
| MACRUM | 0:276e7a263c35 | 96 | /** | 
| MACRUM | 0:276e7a263c35 | 97 | * \fn extern grs_s *sn_grs_init (uint8_t (*sn_grs_tx_callback_ptr)(sn_nsdl_capab_e , uint8_t *, uint16_t, | 
| MACRUM | 0:276e7a263c35 | 98 | * sn_nsdl_addr_s *), uint8_t (*sn_grs_rx_callback_ptr)(sn_coap_hdr_s *, sn_nsdl_addr_s *), | 
| MACRUM | 0:276e7a263c35 | 99 | * sn_grs_mem_s *sn_memory) | 
| MACRUM | 0:276e7a263c35 | 100 | * | 
| MACRUM | 0:276e7a263c35 | 101 | * \brief GRS library initialize function. | 
| MACRUM | 0:276e7a263c35 | 102 | * | 
| MACRUM | 0:276e7a263c35 | 103 | * This function initializes GRS and CoAP. | 
| MACRUM | 0:276e7a263c35 | 104 | * | 
| MACRUM | 0:276e7a263c35 | 105 | * \param sn_grs_tx_callback A function pointer to a transmit callback function. Should return 1 when succeed, 0 when failed | 
| MACRUM | 0:276e7a263c35 | 106 | * \param *sn_grs_rx_callback_ptr A function pointer to a receiving callback function. If received packet is not for GRS, it will be passed to | 
| MACRUM | 0:276e7a263c35 | 107 | * upper level (NSDL) to be proceed. | 
| MACRUM | 0:276e7a263c35 | 108 | * \param sn_memory A pointer to a structure containing the platform specific functions for memory allocation and free. | 
| MACRUM | 0:276e7a263c35 | 109 | * | 
| MACRUM | 0:276e7a263c35 | 110 | * \return success pointer to handle, failure = NULL | 
| MACRUM | 0:276e7a263c35 | 111 | * | 
| MACRUM | 0:276e7a263c35 | 112 | */ | 
| MACRUM | 0:276e7a263c35 | 113 | extern struct grs_s *sn_grs_init(uint8_t (*sn_grs_tx_callback_ptr)(struct nsdl_s *, sn_nsdl_capab_e , uint8_t *, uint16_t, | 
| MACRUM | 0:276e7a263c35 | 114 | sn_nsdl_addr_s *), | 
| MACRUM | 0:276e7a263c35 | 115 | int8_t (*sn_grs_rx_callback_ptr)(struct nsdl_s *, sn_coap_hdr_s *, sn_nsdl_addr_s *), | 
| MACRUM | 0:276e7a263c35 | 116 | void *(*sn_grs_alloc)(uint16_t), | 
| MACRUM | 0:276e7a263c35 | 117 | void (*sn_grs_free)(void *)); | 
| MACRUM | 0:276e7a263c35 | 118 | |
| MACRUM | 0:276e7a263c35 | 119 | extern sn_nsdl_dynamic_resource_parameters_s *sn_grs_get_first_resource(struct grs_s *handle); | 
| MACRUM | 0:276e7a263c35 | 120 | extern sn_nsdl_dynamic_resource_parameters_s *sn_grs_get_next_resource(struct grs_s *handle, | 
| MACRUM | 0:276e7a263c35 | 121 | const sn_nsdl_dynamic_resource_parameters_s *sn_grs_current_resource); | 
| MACRUM | 0:276e7a263c35 | 122 | extern int8_t sn_grs_process_coap(struct nsdl_s *handle, | 
| MACRUM | 0:276e7a263c35 | 123 | sn_coap_hdr_s *coap_packet_ptr, | 
| MACRUM | 0:276e7a263c35 | 124 | sn_nsdl_addr_s *src); | 
| MACRUM | 0:276e7a263c35 | 125 | extern sn_nsdl_dynamic_resource_parameters_s *sn_grs_search_resource(struct grs_s *handle, | 
| MACRUM | 0:276e7a263c35 | 126 | const char *path, | 
| MACRUM | 0:276e7a263c35 | 127 | uint8_t search_method); | 
| MACRUM | 0:276e7a263c35 | 128 | extern int8_t sn_grs_destroy(struct grs_s *handle); | 
| MACRUM | 0:276e7a263c35 | 129 | extern sn_grs_resource_list_s *sn_grs_list_resource(struct grs_s *handle, const char *path); | 
| MACRUM | 0:276e7a263c35 | 130 | extern void sn_grs_free_resource_list(struct grs_s *handle, sn_grs_resource_list_s *list); | 
| MACRUM | 0:276e7a263c35 | 131 | extern int8_t sn_grs_send_coap_message(struct nsdl_s *handle, | 
| MACRUM | 0:276e7a263c35 | 132 | sn_nsdl_addr_s *address_ptr, | 
| MACRUM | 0:276e7a263c35 | 133 | sn_coap_hdr_s *coap_hdr_ptr); | 
| MACRUM | 0:276e7a263c35 | 134 | extern int8_t sn_grs_put_resource(struct grs_s *handle, sn_nsdl_dynamic_resource_parameters_s *res); | 
| MACRUM | 0:276e7a263c35 | 135 | extern int8_t sn_grs_pop_resource(struct grs_s *handle, sn_nsdl_dynamic_resource_parameters_s *res); | 
| MACRUM | 0:276e7a263c35 | 136 | extern int8_t sn_grs_delete_resource(struct grs_s *handle, const char *path); | 
| MACRUM | 0:276e7a263c35 | 137 | extern void sn_grs_mark_resources_as_registered(struct nsdl_s *handle); | 
| MACRUM | 0:276e7a263c35 | 138 | |
| MACRUM | 0:276e7a263c35 | 139 | #ifdef __cplusplus | 
| MACRUM | 0:276e7a263c35 | 140 | } | 
| MACRUM | 0:276e7a263c35 | 141 | #endif | 
| MACRUM | 0:276e7a263c35 | 142 | |
| MACRUM | 0:276e7a263c35 | 143 | |
| MACRUM | 0:276e7a263c35 | 144 | |
| MACRUM | 0:276e7a263c35 | 145 | |
| MACRUM | 0:276e7a263c35 | 146 | #endif /* GRS_H_ */ |