sandbox / mbed-client-c

Fork of mbed-client-c by Christopher Haster

Committer:
Yogesh Pande
Date:
Sat Apr 02 00:39:03 2016 +0300
Revision:
4:5d91b0f5038c
Parent:
1:43f5c94c6771
Latest mbed-client-c sources from Github.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Christopher Haster 1:43f5c94c6771 1 /*
Christopher Haster 1:43f5c94c6771 2 * Copyright (c) 2011-2015 ARM Limited. All rights reserved.
Christopher Haster 1:43f5c94c6771 3 * SPDX-License-Identifier: Apache-2.0
Christopher Haster 1:43f5c94c6771 4 * Licensed under the Apache License, Version 2.0 (the License); you may
Christopher Haster 1:43f5c94c6771 5 * not use this file except in compliance with the License.
Christopher Haster 1:43f5c94c6771 6 * You may obtain a copy of the License at
Christopher Haster 1:43f5c94c6771 7 *
Christopher Haster 1:43f5c94c6771 8 * http://www.apache.org/licenses/LICENSE-2.0
Christopher Haster 1:43f5c94c6771 9 *
Christopher Haster 1:43f5c94c6771 10 * Unless required by applicable law or agreed to in writing, software
Christopher Haster 1:43f5c94c6771 11 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
Christopher Haster 1:43f5c94c6771 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Christopher Haster 1:43f5c94c6771 13 * See the License for the specific language governing permissions and
Christopher Haster 1:43f5c94c6771 14 * limitations under the License.
Christopher Haster 1:43f5c94c6771 15 */
Christopher Haster 1:43f5c94c6771 16 #ifndef GRS_H_
Christopher Haster 1:43f5c94c6771 17 #define GRS_H_
Christopher Haster 1:43f5c94c6771 18
Christopher Haster 1:43f5c94c6771 19
Christopher Haster 1:43f5c94c6771 20 #ifdef __cplusplus
Christopher Haster 1:43f5c94c6771 21 extern "C" {
Christopher Haster 1:43f5c94c6771 22 #endif
Christopher Haster 1:43f5c94c6771 23
Christopher Haster 1:43f5c94c6771 24
Christopher Haster 1:43f5c94c6771 25 #define SN_GRS_RESOURCE_ALREADY_EXISTS -2
Christopher Haster 1:43f5c94c6771 26 #define SN_GRS_INVALID_PATH -3
Christopher Haster 1:43f5c94c6771 27 #define SN_GRS_LIST_ADDING_FAILURE -4
Christopher Haster 1:43f5c94c6771 28 #define SN_GRS_RESOURCE_UPDATED -5
Christopher Haster 1:43f5c94c6771 29
Christopher Haster 1:43f5c94c6771 30 #define ACCESS_DENIED -6
Christopher Haster 1:43f5c94c6771 31
Christopher Haster 1:43f5c94c6771 32 #define SN_GRS_DELETE_METHOD 0
Christopher Haster 1:43f5c94c6771 33 #define SN_GRS_SEARCH_METHOD 1
Christopher Haster 1:43f5c94c6771 34
Christopher Haster 1:43f5c94c6771 35 #define SN_GRS_DEFAULT_ACCESS 0x0F
Christopher Haster 1:43f5c94c6771 36
Christopher Haster 1:43f5c94c6771 37 #define SN_NDSL_RESOURCE_NOT_REGISTERED 0
Christopher Haster 1:43f5c94c6771 38 #define SN_NDSL_RESOURCE_REGISTERING 1
Christopher Haster 1:43f5c94c6771 39 #define SN_NDSL_RESOURCE_REGISTERED 2
Christopher Haster 1:43f5c94c6771 40
Christopher Haster 1:43f5c94c6771 41 /***** Structs *****/
Christopher Haster 1:43f5c94c6771 42
Christopher Haster 1:43f5c94c6771 43 typedef struct sn_grs_version_ {
Christopher Haster 1:43f5c94c6771 44 uint8_t major_version;
Christopher Haster 1:43f5c94c6771 45 uint8_t minor_version;
Christopher Haster 1:43f5c94c6771 46 uint8_t build;
Christopher Haster 1:43f5c94c6771 47 } sn_grs_version_s;
Christopher Haster 1:43f5c94c6771 48
Christopher Haster 1:43f5c94c6771 49 typedef NS_LIST_HEAD(sn_nsdl_resource_info_s, link) resource_list_t;
Christopher Haster 1:43f5c94c6771 50
Christopher Haster 1:43f5c94c6771 51 struct grs_s {
Christopher Haster 1:43f5c94c6771 52 struct coap_s *coap;
Christopher Haster 1:43f5c94c6771 53
Christopher Haster 1:43f5c94c6771 54 uint16_t resource_root_count;
Christopher Haster 1:43f5c94c6771 55 resource_list_t resource_root_list;
Christopher Haster 1:43f5c94c6771 56
Christopher Haster 1:43f5c94c6771 57 void *(*sn_grs_alloc)(uint16_t);
Christopher Haster 1:43f5c94c6771 58 void (*sn_grs_free)(void *);
Christopher Haster 1:43f5c94c6771 59 uint8_t (*sn_grs_tx_callback)(struct nsdl_s *, sn_nsdl_capab_e , uint8_t *, uint16_t, sn_nsdl_addr_s *);
Christopher Haster 1:43f5c94c6771 60 int8_t (*sn_grs_rx_callback)(struct nsdl_s *, sn_coap_hdr_s *, sn_nsdl_addr_s *);
Christopher Haster 1:43f5c94c6771 61 };
Christopher Haster 1:43f5c94c6771 62
Christopher Haster 1:43f5c94c6771 63
Christopher Haster 1:43f5c94c6771 64 struct nsdl_s {
Christopher Haster 1:43f5c94c6771 65 struct grs_s *grs;
Christopher Haster 1:43f5c94c6771 66
Christopher Haster 1:43f5c94c6771 67 uint8_t *oma_bs_address_ptr; /* Bootstrap address pointer. If null, no bootstrap in use */
Christopher Haster 1:43f5c94c6771 68 uint8_t oma_bs_address_len; /* Bootstrap address length */
Christopher Haster 1:43f5c94c6771 69 uint16_t oma_bs_port; /* Bootstrap port */
Christopher Haster 1:43f5c94c6771 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 */
Christopher Haster 1:43f5c94c6771 71
Christopher Haster 1:43f5c94c6771 72 sn_nsdl_ep_parameters_s *ep_information_ptr; // Endpoint parameters, Name, Domain etc..
Christopher Haster 1:43f5c94c6771 73 sn_nsdl_oma_server_info_t *nsp_address_ptr; // NSP server address information
Christopher Haster 1:43f5c94c6771 74 uint8_t sn_nsdl_endpoint_registered;
Christopher Haster 1:43f5c94c6771 75
Christopher Haster 1:43f5c94c6771 76 uint16_t register_msg_id;
Christopher Haster 1:43f5c94c6771 77 uint16_t unregister_msg_id;
Christopher Haster 1:43f5c94c6771 78
Christopher Haster 1:43f5c94c6771 79 void *(*sn_nsdl_alloc)(uint16_t);
Christopher Haster 1:43f5c94c6771 80 void (*sn_nsdl_free)(void *);
Christopher Haster 1:43f5c94c6771 81 uint8_t (*sn_nsdl_tx_callback)(struct nsdl_s *, sn_nsdl_capab_e , uint8_t *, uint16_t, sn_nsdl_addr_s *);
Christopher Haster 1:43f5c94c6771 82 uint8_t (*sn_nsdl_rx_callback)(struct nsdl_s *, sn_coap_hdr_s *, sn_nsdl_addr_s *);
Christopher Haster 1:43f5c94c6771 83 };
Christopher Haster 1:43f5c94c6771 84
Christopher Haster 1:43f5c94c6771 85 /***** Function prototypes *****/
Christopher Haster 1:43f5c94c6771 86 /**
Christopher Haster 1:43f5c94c6771 87 * \fn extern grs_s *sn_grs_init (uint8_t (*sn_grs_tx_callback_ptr)(sn_nsdl_capab_e , uint8_t *, uint16_t,
Christopher Haster 1:43f5c94c6771 88 * sn_nsdl_addr_s *), uint8_t (*sn_grs_rx_callback_ptr)(sn_coap_hdr_s *, sn_nsdl_addr_s *),
Christopher Haster 1:43f5c94c6771 89 * sn_grs_mem_s *sn_memory)
Christopher Haster 1:43f5c94c6771 90 *
Christopher Haster 1:43f5c94c6771 91 * \brief GRS library initialize function.
Christopher Haster 1:43f5c94c6771 92 *
Christopher Haster 1:43f5c94c6771 93 * This function initializes GRS and CoAP.
Christopher Haster 1:43f5c94c6771 94 *
Christopher Haster 1:43f5c94c6771 95 * \param sn_grs_tx_callback A function pointer to a transmit callback function. Should return 1 when succeed, 0 when failed
Christopher Haster 1:43f5c94c6771 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
Christopher Haster 1:43f5c94c6771 97 * upper level (NSDL) to be proceed.
Christopher Haster 1:43f5c94c6771 98 * \param sn_memory A pointer to a structure containing the platform specific functions for memory allocation and free.
Christopher Haster 1:43f5c94c6771 99 *
Christopher Haster 1:43f5c94c6771 100 * \return success pointer to handle, failure = NULL
Christopher Haster 1:43f5c94c6771 101 *
Christopher Haster 1:43f5c94c6771 102 */
Christopher Haster 1:43f5c94c6771 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,
Christopher Haster 1:43f5c94c6771 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 *));
Christopher Haster 1:43f5c94c6771 105
Christopher Haster 1:43f5c94c6771 106 extern const sn_nsdl_resource_info_s *sn_grs_get_first_resource(struct grs_s *handle);
Christopher Haster 1:43f5c94c6771 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);
Christopher Haster 1:43f5c94c6771 108 extern int8_t sn_grs_process_coap(struct nsdl_s *handle, sn_coap_hdr_s *coap_packet_ptr, sn_nsdl_addr_s *src);
Christopher Haster 1:43f5c94c6771 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);
Christopher Haster 1:43f5c94c6771 110 extern int8_t sn_grs_destroy(struct grs_s *handle);
Christopher Haster 1:43f5c94c6771 111 extern sn_grs_resource_list_s *sn_grs_list_resource(struct grs_s *handle, uint16_t pathlen, uint8_t *path);
Christopher Haster 1:43f5c94c6771 112 extern void sn_grs_free_resource_list(struct grs_s *handle, sn_grs_resource_list_s *list);
Christopher Haster 1:43f5c94c6771 113 extern int8_t sn_grs_update_resource(struct grs_s *handle, sn_nsdl_resource_info_s *res);
Christopher Haster 1:43f5c94c6771 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);
Christopher Haster 1:43f5c94c6771 115 extern int8_t sn_grs_create_resource(struct grs_s *handle, sn_nsdl_resource_info_s *res);
Christopher Haster 1:43f5c94c6771 116 extern int8_t sn_grs_delete_resource(struct grs_s *handle, uint16_t pathlen, uint8_t *path);
Christopher Haster 1:43f5c94c6771 117 extern void sn_grs_mark_resources_as_registered(struct nsdl_s *handle);
Christopher Haster 1:43f5c94c6771 118
Christopher Haster 1:43f5c94c6771 119 #ifdef __cplusplus
Christopher Haster 1:43f5c94c6771 120 }
Christopher Haster 1:43f5c94c6771 121 #endif
Christopher Haster 1:43f5c94c6771 122
Christopher Haster 1:43f5c94c6771 123
Christopher Haster 1:43f5c94c6771 124
Christopher Haster 1:43f5c94c6771 125
Christopher Haster 1:43f5c94c6771 126 #endif /* GRS_H_ */