![](/media/cache/profiles/debfdc81854eac26ec993b55a659c6e1.jpg.50x50_q85.jpg)
mbed client lightswitch demo
Dependencies: mbed Socket lwip-eth lwip-sys lwip
Fork of mbed-client-classic-example-lwip by
mbed-client-c/source/libNsdl/src/include/sn_grs.h@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) 2011-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 | #ifndef GRS_H_ |
mbedAustin | 11:cada08fc8a70 | 17 | #define GRS_H_ |
mbedAustin | 11:cada08fc8a70 | 18 | |
mbedAustin | 11:cada08fc8a70 | 19 | |
mbedAustin | 11:cada08fc8a70 | 20 | #ifdef __cplusplus |
mbedAustin | 11:cada08fc8a70 | 21 | extern "C" { |
mbedAustin | 11:cada08fc8a70 | 22 | #endif |
mbedAustin | 11:cada08fc8a70 | 23 | |
mbedAustin | 11:cada08fc8a70 | 24 | |
mbedAustin | 11:cada08fc8a70 | 25 | #define SN_GRS_RESOURCE_ALREADY_EXISTS -2 |
mbedAustin | 11:cada08fc8a70 | 26 | #define SN_GRS_INVALID_PATH -3 |
mbedAustin | 11:cada08fc8a70 | 27 | #define SN_GRS_LIST_ADDING_FAILURE -4 |
mbedAustin | 11:cada08fc8a70 | 28 | #define SN_GRS_RESOURCE_UPDATED -5 |
mbedAustin | 11:cada08fc8a70 | 29 | |
mbedAustin | 11:cada08fc8a70 | 30 | #define ACCESS_DENIED -6 |
mbedAustin | 11:cada08fc8a70 | 31 | |
mbedAustin | 11:cada08fc8a70 | 32 | #define SN_GRS_DELETE_METHOD 0 |
mbedAustin | 11:cada08fc8a70 | 33 | #define SN_GRS_SEARCH_METHOD 1 |
mbedAustin | 11:cada08fc8a70 | 34 | |
mbedAustin | 11:cada08fc8a70 | 35 | #define SN_GRS_DEFAULT_ACCESS 0x0F |
mbedAustin | 11:cada08fc8a70 | 36 | |
mbedAustin | 11:cada08fc8a70 | 37 | #define SN_NDSL_RESOURCE_NOT_REGISTERED 0 |
mbedAustin | 11:cada08fc8a70 | 38 | #define SN_NDSL_RESOURCE_REGISTERING 1 |
mbedAustin | 11:cada08fc8a70 | 39 | #define SN_NDSL_RESOURCE_REGISTERED 2 |
mbedAustin | 11:cada08fc8a70 | 40 | |
mbedAustin | 11:cada08fc8a70 | 41 | /***** Structs *****/ |
mbedAustin | 11:cada08fc8a70 | 42 | |
mbedAustin | 11:cada08fc8a70 | 43 | typedef struct sn_grs_version_ { |
mbedAustin | 11:cada08fc8a70 | 44 | uint8_t major_version; |
mbedAustin | 11:cada08fc8a70 | 45 | uint8_t minor_version; |
mbedAustin | 11:cada08fc8a70 | 46 | uint8_t build; |
mbedAustin | 11:cada08fc8a70 | 47 | } sn_grs_version_s; |
mbedAustin | 11:cada08fc8a70 | 48 | |
mbedAustin | 11:cada08fc8a70 | 49 | typedef NS_LIST_HEAD(sn_nsdl_resource_info_s, link) resource_list_t; |
mbedAustin | 11:cada08fc8a70 | 50 | |
mbedAustin | 11:cada08fc8a70 | 51 | struct grs_s { |
mbedAustin | 11:cada08fc8a70 | 52 | struct coap_s *coap; |
mbedAustin | 11:cada08fc8a70 | 53 | |
mbedAustin | 11:cada08fc8a70 | 54 | uint16_t resource_root_count; |
mbedAustin | 11:cada08fc8a70 | 55 | resource_list_t resource_root_list; |
mbedAustin | 11:cada08fc8a70 | 56 | |
mbedAustin | 11:cada08fc8a70 | 57 | void *(*sn_grs_alloc)(uint16_t); |
mbedAustin | 11:cada08fc8a70 | 58 | void (*sn_grs_free)(void *); |
mbedAustin | 11:cada08fc8a70 | 59 | uint8_t (*sn_grs_tx_callback)(struct nsdl_s *, sn_nsdl_capab_e , uint8_t *, uint16_t, sn_nsdl_addr_s *); |
mbedAustin | 11:cada08fc8a70 | 60 | int8_t (*sn_grs_rx_callback)(struct nsdl_s *, sn_coap_hdr_s *, sn_nsdl_addr_s *); |
mbedAustin | 11:cada08fc8a70 | 61 | }; |
mbedAustin | 11:cada08fc8a70 | 62 | |
mbedAustin | 11:cada08fc8a70 | 63 | |
mbedAustin | 11:cada08fc8a70 | 64 | struct nsdl_s { |
mbedAustin | 11:cada08fc8a70 | 65 | struct grs_s *grs; |
mbedAustin | 11:cada08fc8a70 | 66 | |
mbedAustin | 11:cada08fc8a70 | 67 | uint8_t *oma_bs_address_ptr; /* Bootstrap address pointer. If null, no bootstrap in use */ |
mbedAustin | 11:cada08fc8a70 | 68 | uint8_t oma_bs_address_len; /* Bootstrap address length */ |
mbedAustin | 11:cada08fc8a70 | 69 | uint16_t oma_bs_port; /* Bootstrap port */ |
mbedAustin | 11:cada08fc8a70 | 70 | void (*sn_nsdl_oma_bs_done_cb)(sn_nsdl_oma_server_info_t *server_info_ptr); /* Callback to inform application when bootstrap is done */ |
mbedAustin | 11:cada08fc8a70 | 71 | |
mbedAustin | 11:cada08fc8a70 | 72 | sn_nsdl_ep_parameters_s *ep_information_ptr; // Endpoint parameters, Name, Domain etc.. |
mbedAustin | 11:cada08fc8a70 | 73 | sn_nsdl_oma_server_info_t *nsp_address_ptr; // NSP server address information |
mbedAustin | 11:cada08fc8a70 | 74 | uint8_t sn_nsdl_endpoint_registered; |
mbedAustin | 11:cada08fc8a70 | 75 | |
mbedAustin | 11:cada08fc8a70 | 76 | uint16_t register_msg_id; |
mbedAustin | 11:cada08fc8a70 | 77 | uint16_t unregister_msg_id; |
mbedAustin | 11:cada08fc8a70 | 78 | |
mbedAustin | 11:cada08fc8a70 | 79 | void *(*sn_nsdl_alloc)(uint16_t); |
mbedAustin | 11:cada08fc8a70 | 80 | void (*sn_nsdl_free)(void *); |
mbedAustin | 11:cada08fc8a70 | 81 | uint8_t (*sn_nsdl_tx_callback)(struct nsdl_s *, sn_nsdl_capab_e , uint8_t *, uint16_t, sn_nsdl_addr_s *); |
mbedAustin | 11:cada08fc8a70 | 82 | uint8_t (*sn_nsdl_rx_callback)(struct nsdl_s *, sn_coap_hdr_s *, sn_nsdl_addr_s *); |
mbedAustin | 11:cada08fc8a70 | 83 | }; |
mbedAustin | 11:cada08fc8a70 | 84 | |
mbedAustin | 11:cada08fc8a70 | 85 | /***** Function prototypes *****/ |
mbedAustin | 11:cada08fc8a70 | 86 | /** |
mbedAustin | 11:cada08fc8a70 | 87 | * \fn extern grs_s *sn_grs_init (uint8_t (*sn_grs_tx_callback_ptr)(sn_nsdl_capab_e , uint8_t *, uint16_t, |
mbedAustin | 11:cada08fc8a70 | 88 | * sn_nsdl_addr_s *), uint8_t (*sn_grs_rx_callback_ptr)(sn_coap_hdr_s *, sn_nsdl_addr_s *), |
mbedAustin | 11:cada08fc8a70 | 89 | * sn_grs_mem_s *sn_memory) |
mbedAustin | 11:cada08fc8a70 | 90 | * |
mbedAustin | 11:cada08fc8a70 | 91 | * \brief GRS library initialize function. |
mbedAustin | 11:cada08fc8a70 | 92 | * |
mbedAustin | 11:cada08fc8a70 | 93 | * This function initializes GRS and CoAP. |
mbedAustin | 11:cada08fc8a70 | 94 | * |
mbedAustin | 11:cada08fc8a70 | 95 | * \param sn_grs_tx_callback A function pointer to a transmit callback function. Should return 1 when succeed, 0 when failed |
mbedAustin | 11:cada08fc8a70 | 96 | * \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 |
mbedAustin | 11:cada08fc8a70 | 97 | * upper level (NSDL) to be proceed. |
mbedAustin | 11:cada08fc8a70 | 98 | * \param sn_memory A pointer to a structure containing the platform specific functions for memory allocation and free. |
mbedAustin | 11:cada08fc8a70 | 99 | * |
mbedAustin | 11:cada08fc8a70 | 100 | * \return success pointer to handle, failure = NULL |
mbedAustin | 11:cada08fc8a70 | 101 | * |
mbedAustin | 11:cada08fc8a70 | 102 | */ |
mbedAustin | 11:cada08fc8a70 | 103 | 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, |
mbedAustin | 11:cada08fc8a70 | 104 | sn_nsdl_addr_s *), int8_t (*sn_grs_rx_callback_ptr)(struct nsdl_s *, sn_coap_hdr_s *, sn_nsdl_addr_s *), void *(*sn_grs_alloc)(uint16_t), void (*sn_grs_free)(void *)); |
mbedAustin | 11:cada08fc8a70 | 105 | |
mbedAustin | 11:cada08fc8a70 | 106 | extern const sn_nsdl_resource_info_s *sn_grs_get_first_resource(struct grs_s *handle); |
mbedAustin | 11:cada08fc8a70 | 107 | extern const sn_nsdl_resource_info_s *sn_grs_get_next_resource(struct grs_s *handle, const sn_nsdl_resource_info_s *sn_grs_current_resource); |
mbedAustin | 11:cada08fc8a70 | 108 | extern int8_t sn_grs_process_coap(struct nsdl_s *handle, sn_coap_hdr_s *coap_packet_ptr, sn_nsdl_addr_s *src); |
mbedAustin | 11:cada08fc8a70 | 109 | extern sn_nsdl_resource_info_s *sn_grs_search_resource(struct grs_s *handle, uint16_t pathlen, uint8_t *path, uint8_t search_method); |
mbedAustin | 11:cada08fc8a70 | 110 | extern int8_t sn_grs_destroy(struct grs_s *handle); |
mbedAustin | 11:cada08fc8a70 | 111 | extern sn_grs_resource_list_s *sn_grs_list_resource(struct grs_s *handle, uint16_t pathlen, uint8_t *path); |
mbedAustin | 11:cada08fc8a70 | 112 | extern void sn_grs_free_resource_list(struct grs_s *handle, sn_grs_resource_list_s *list); |
mbedAustin | 11:cada08fc8a70 | 113 | extern int8_t sn_grs_update_resource(struct grs_s *handle, sn_nsdl_resource_info_s *res); |
mbedAustin | 11:cada08fc8a70 | 114 | extern int8_t sn_grs_send_coap_message(struct nsdl_s *handle, sn_nsdl_addr_s *address_ptr, sn_coap_hdr_s *coap_hdr_ptr); |
mbedAustin | 11:cada08fc8a70 | 115 | extern int8_t sn_grs_create_resource(struct grs_s *handle, sn_nsdl_resource_info_s *res); |
mbedAustin | 11:cada08fc8a70 | 116 | extern int8_t sn_grs_delete_resource(struct grs_s *handle, uint16_t pathlen, uint8_t *path); |
mbedAustin | 11:cada08fc8a70 | 117 | extern void sn_grs_mark_resources_as_registered(struct nsdl_s *handle); |
mbedAustin | 11:cada08fc8a70 | 118 | |
mbedAustin | 11:cada08fc8a70 | 119 | #ifdef __cplusplus |
mbedAustin | 11:cada08fc8a70 | 120 | } |
mbedAustin | 11:cada08fc8a70 | 121 | #endif |
mbedAustin | 11:cada08fc8a70 | 122 | |
mbedAustin | 11:cada08fc8a70 | 123 | |
mbedAustin | 11:cada08fc8a70 | 124 | |
mbedAustin | 11:cada08fc8a70 | 125 | |
mbedAustin | 11:cada08fc8a70 | 126 | #endif /* GRS_H_ */ |
mbedAustin | 11:cada08fc8a70 | 127 |