hello
Dependents: nespresso_demo nespresso_endpoint EnvoyNespressoEndpointColorDetectorV2
Fork of nsdl by
sn_nsdl.c@0:f6e4e1bbb3fe, 2014-06-04 (annotated)
- Committer:
- GeofferyOmlette
- Date:
- Wed Jun 04 15:38:26 2014 +0000
- Revision:
- 0:f6e4e1bbb3fe
- Child:
- 2:05e4cd1a1542
hello
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
GeofferyOmlette | 0:f6e4e1bbb3fe | 1 | /** |
GeofferyOmlette | 0:f6e4e1bbb3fe | 2 | * \file sn_nsdl.c |
GeofferyOmlette | 0:f6e4e1bbb3fe | 3 | * |
GeofferyOmlette | 0:f6e4e1bbb3fe | 4 | * \brief Nano service device library |
GeofferyOmlette | 0:f6e4e1bbb3fe | 5 | * |
GeofferyOmlette | 0:f6e4e1bbb3fe | 6 | * Application interface to CoAP, GRS and NSP handling. |
GeofferyOmlette | 0:f6e4e1bbb3fe | 7 | * |
GeofferyOmlette | 0:f6e4e1bbb3fe | 8 | */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 9 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 10 | #include <string.h> |
GeofferyOmlette | 0:f6e4e1bbb3fe | 11 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 12 | #include "nsdl_types.h" |
GeofferyOmlette | 0:f6e4e1bbb3fe | 13 | #include "sn_nsdl.h" |
GeofferyOmlette | 0:f6e4e1bbb3fe | 14 | #include "sn_coap_header.h" |
GeofferyOmlette | 0:f6e4e1bbb3fe | 15 | #include "sn_coap_protocol.h" |
GeofferyOmlette | 0:f6e4e1bbb3fe | 16 | #include "sn_nsdl_lib.h" |
GeofferyOmlette | 0:f6e4e1bbb3fe | 17 | #include "sn_grs.h" |
GeofferyOmlette | 0:f6e4e1bbb3fe | 18 | #include "sn_linked_list.h" |
GeofferyOmlette | 0:f6e4e1bbb3fe | 19 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 20 | /* Defines */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 21 | #define RESOURCE_DIR_LEN 2 |
GeofferyOmlette | 0:f6e4e1bbb3fe | 22 | #define RESOURCE_DIR_PATH {'r','d'} |
GeofferyOmlette | 0:f6e4e1bbb3fe | 23 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 24 | #define EP_NAME_PARAMETERS_LEN 3 |
GeofferyOmlette | 0:f6e4e1bbb3fe | 25 | #define EP_NAME_PARAMETERS {'e','p','='} |
GeofferyOmlette | 0:f6e4e1bbb3fe | 26 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 27 | #define RT_PARAMETER_LEN 3 |
GeofferyOmlette | 0:f6e4e1bbb3fe | 28 | #define RT_PARAMETER {'r','t','='} |
GeofferyOmlette | 0:f6e4e1bbb3fe | 29 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 30 | #define DOMAIN_PARAMETER_LEN 2 |
GeofferyOmlette | 0:f6e4e1bbb3fe | 31 | #define DOMAIN_PARAMETER {'d','='} |
GeofferyOmlette | 0:f6e4e1bbb3fe | 32 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 33 | #define IF_PARAMETER_LEN 3 |
GeofferyOmlette | 0:f6e4e1bbb3fe | 34 | #define IF_PARAMETER {'i','f','='} |
GeofferyOmlette | 0:f6e4e1bbb3fe | 35 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 36 | #define CON_PARAMETER_LEN 4 |
GeofferyOmlette | 0:f6e4e1bbb3fe | 37 | #define CON_PARAMETER {'c','o','n','='} |
GeofferyOmlette | 0:f6e4e1bbb3fe | 38 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 39 | #define LT_PARAMETER_LEN 3 |
GeofferyOmlette | 0:f6e4e1bbb3fe | 40 | #define LT_PARAMETER {'l','t','='} |
GeofferyOmlette | 0:f6e4e1bbb3fe | 41 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 42 | #define OBS_PARAMETER_LEN 3 |
GeofferyOmlette | 0:f6e4e1bbb3fe | 43 | #define OBS_PARAMETER {'o','b','s'} |
GeofferyOmlette | 0:f6e4e1bbb3fe | 44 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 45 | #define AOBS_PARAMETER_LEN 8 |
GeofferyOmlette | 0:f6e4e1bbb3fe | 46 | #define AOBS_PARAMETER {'a','o','b','s',';','i','d','='} |
GeofferyOmlette | 0:f6e4e1bbb3fe | 47 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 48 | #define COAP_CON_PARAMETER_LEN 3 |
GeofferyOmlette | 0:f6e4e1bbb3fe | 49 | #define COAP_CON_PARAMETER {'c','t','='} |
GeofferyOmlette | 0:f6e4e1bbb3fe | 50 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 51 | #define EVENT_PATH_LEN 6 |
GeofferyOmlette | 0:f6e4e1bbb3fe | 52 | #define EVENT_PATH {'e','v','e','n','t','/'} |
GeofferyOmlette | 0:f6e4e1bbb3fe | 53 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 54 | #define SN_NSDL_EP_REGISTER_MESSAGE 1 |
GeofferyOmlette | 0:f6e4e1bbb3fe | 55 | #define SN_NSDL_EP_UPDATE_MESSAGE 2 |
GeofferyOmlette | 0:f6e4e1bbb3fe | 56 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 57 | #define SN_NSDL_MSG_NO_TYPE 0 |
GeofferyOmlette | 0:f6e4e1bbb3fe | 58 | #define SN_NSDL_MSG_REGISTER 1 |
GeofferyOmlette | 0:f6e4e1bbb3fe | 59 | #define SN_NSDL_MSG_UNREGISTER 2 |
GeofferyOmlette | 0:f6e4e1bbb3fe | 60 | #define SN_NSDL_MSG_UPDATE 3 |
GeofferyOmlette | 0:f6e4e1bbb3fe | 61 | #define SN_NSDL_MSG_EVENT 4 |
GeofferyOmlette | 0:f6e4e1bbb3fe | 62 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 63 | #define SN_NSDL_MAX_MESSAGE_COUNT 1 |
GeofferyOmlette | 0:f6e4e1bbb3fe | 64 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 65 | /* Constants */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 66 | SN_NSDL_CONST_MEMORY_ATTRIBUTE |
GeofferyOmlette | 0:f6e4e1bbb3fe | 67 | static uint8_t ep_name_parameter_string[] = EP_NAME_PARAMETERS; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 68 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 69 | SN_NSDL_CONST_MEMORY_ATTRIBUTE |
GeofferyOmlette | 0:f6e4e1bbb3fe | 70 | static uint8_t resource_path_ptr[] = RESOURCE_DIR_PATH; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 71 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 72 | SN_NSDL_CONST_MEMORY_ATTRIBUTE |
GeofferyOmlette | 0:f6e4e1bbb3fe | 73 | static uint8_t resource_type_parameter[] = RT_PARAMETER; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 74 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 75 | SN_NSDL_CONST_MEMORY_ATTRIBUTE |
GeofferyOmlette | 0:f6e4e1bbb3fe | 76 | static uint8_t obs_parameter[] = OBS_PARAMETER; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 77 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 78 | //SN_NSDL_CONST_MEMORY_ATTRIBUTE |
GeofferyOmlette | 0:f6e4e1bbb3fe | 79 | //static uint8_t aobs_parameter[] = AOBS_PARAMETER; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 80 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 81 | SN_NSDL_CONST_MEMORY_ATTRIBUTE |
GeofferyOmlette | 0:f6e4e1bbb3fe | 82 | static uint8_t if_description_parameter[] = IF_PARAMETER; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 83 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 84 | SN_NSDL_CONST_MEMORY_ATTRIBUTE |
GeofferyOmlette | 0:f6e4e1bbb3fe | 85 | static uint8_t ep_lifetime_parameter[] = LT_PARAMETER; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 86 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 87 | SN_NSDL_CONST_MEMORY_ATTRIBUTE |
GeofferyOmlette | 0:f6e4e1bbb3fe | 88 | static uint8_t ep_domain_parameter[] = DOMAIN_PARAMETER; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 89 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 90 | SN_NSDL_CONST_MEMORY_ATTRIBUTE |
GeofferyOmlette | 0:f6e4e1bbb3fe | 91 | static uint8_t coap_con_type_parameter[] = COAP_CON_PARAMETER; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 92 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 93 | SN_NSDL_CONST_MEMORY_ATTRIBUTE |
GeofferyOmlette | 0:f6e4e1bbb3fe | 94 | static uint8_t event_path_parameter[] = EVENT_PATH; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 95 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 96 | /* Global function pointers */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 97 | static void *(*sn_nsdl_alloc)(uint16_t) = 0; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 98 | static void (*sn_nsdl_free)(void*) = 0; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 99 | static uint8_t (*sn_nsdl_tx_callback)(sn_nsdl_capab_e , uint8_t *, uint16_t, sn_nsdl_addr_s *) = 0; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 100 | static uint8_t (*sn_nsdl_rx_callback)(sn_coap_hdr_s *, sn_nsdl_addr_s *) = 0; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 101 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 102 | /* Global variables */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 103 | static sn_nsdl_ep_parameters_s *ep_information_ptr = 0; // Endpoint parameters, Name, Domain etc.. |
GeofferyOmlette | 0:f6e4e1bbb3fe | 104 | static sn_nsdl_addr_s *nsp_address_ptr = 0; // NSP server address information |
GeofferyOmlette | 0:f6e4e1bbb3fe | 105 | static sn_linked_list_t *message_list_ptr = 0; // |
GeofferyOmlette | 0:f6e4e1bbb3fe | 106 | static uint8_t sn_nsdl_endpoint_registered = 0; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 107 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 108 | /* Function prototypes */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 109 | static int8_t sn_nsdl_internal_coap_send (sn_coap_hdr_s *coap_header_ptr, sn_nsdl_addr_s *dst_addr_ptr, uint8_t message_description); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 110 | static void sn_nsdl_resolve_nsp_address (void); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 111 | int8_t sn_nsdl_build_registration_body (sn_coap_hdr_s *message_ptr, uint8_t updating_registeration); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 112 | static uint16_t sn_nsdl_calculate_registration_body_size (uint8_t updating_registeration); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 113 | static uint8_t sn_nsdl_calculate_uri_query_option_len (sn_nsdl_ep_parameters_s *endpoint_info_ptr, uint8_t msg_type); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 114 | static int8_t sn_nsdl_fill_uri_query_options (sn_nsdl_ep_parameters_s *parameter_ptr, sn_coap_hdr_s *source_msg_ptr, uint8_t msg_type); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 115 | static int8_t sn_nsdl_local_rx_function (sn_coap_hdr_s *coap_packet_ptr, sn_nsdl_addr_s *address_ptr); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 116 | static int8_t sn_nsdl_resolve_ep_information (sn_coap_hdr_s *coap_packet_ptr); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 117 | static void sn_nsdl_mark_resources_as_registered (void); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 118 | static uint8_t sn_nsdl_itoa_len (uint8_t value); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 119 | static uint8_t *sn_nsdl_itoa (uint8_t *ptr, uint8_t value); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 120 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 121 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 122 | int8_t sn_nsdl_destroy(void) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 123 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 124 | if(message_list_ptr) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 125 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 126 | uint16_t size = sn_linked_list_count_nodes(message_list_ptr); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 127 | uint16_t i = 0; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 128 | sn_nsdl_sent_messages_s*tmp; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 129 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 130 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 131 | for(i=0;i<size;i++) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 132 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 133 | tmp = sn_linked_list_get_first_node(message_list_ptr); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 134 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 135 | if(tmp) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 136 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 137 | sn_linked_list_remove_current_node(message_list_ptr); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 138 | sn_nsdl_free(tmp); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 139 | tmp = 0; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 140 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 141 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 142 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 143 | if(!sn_linked_list_count_nodes(message_list_ptr)) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 144 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 145 | sn_linked_list_free(message_list_ptr); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 146 | message_list_ptr = 0; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 147 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 148 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 149 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 150 | if(ep_information_ptr) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 151 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 152 | if(ep_information_ptr->endpoint_name_ptr) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 153 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 154 | sn_nsdl_free(ep_information_ptr->endpoint_name_ptr); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 155 | ep_information_ptr->endpoint_name_ptr = 0; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 156 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 157 | if(ep_information_ptr->domain_name_ptr) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 158 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 159 | sn_nsdl_free(ep_information_ptr->domain_name_ptr); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 160 | ep_information_ptr->domain_name_ptr = 0; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 161 | ep_information_ptr->domain_name_len = 0; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 162 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 163 | if(ep_information_ptr->type_ptr) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 164 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 165 | sn_nsdl_free(ep_information_ptr->type_ptr); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 166 | ep_information_ptr->type_ptr = 0; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 167 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 168 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 169 | if(ep_information_ptr->lifetime_ptr) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 170 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 171 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 172 | sn_nsdl_free(ep_information_ptr->lifetime_ptr); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 173 | ep_information_ptr->lifetime_ptr = 0; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 174 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 175 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 176 | sn_nsdl_free(ep_information_ptr); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 177 | ep_information_ptr = 0; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 178 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 179 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 180 | if(nsp_address_ptr) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 181 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 182 | if(nsp_address_ptr->socket_information) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 183 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 184 | sn_nsdl_free(nsp_address_ptr->socket_information); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 185 | nsp_address_ptr->socket_information= 0; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 186 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 187 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 188 | if(nsp_address_ptr->addr_ptr) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 189 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 190 | sn_nsdl_free(nsp_address_ptr->addr_ptr); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 191 | nsp_address_ptr->addr_ptr = 0; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 192 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 193 | sn_nsdl_free(nsp_address_ptr); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 194 | nsp_address_ptr = 0; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 195 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 196 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 197 | /* Destroy also libCoap and grs part of libNsdl */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 198 | sn_grs_destroy(); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 199 | sn_coap_protocol_destroy(); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 200 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 201 | return 0; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 202 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 203 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 204 | int8_t sn_nsdl_init (uint8_t (*sn_nsdl_tx_cb)(sn_nsdl_capab_e , uint8_t *, uint16_t, sn_nsdl_addr_s *), |
GeofferyOmlette | 0:f6e4e1bbb3fe | 205 | uint8_t (*sn_nsdl_rx_cb)(sn_coap_hdr_s *, sn_nsdl_addr_s *), |
GeofferyOmlette | 0:f6e4e1bbb3fe | 206 | sn_nsdl_mem_s *sn_memory) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 207 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 208 | /* Check pointers and define function pointers */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 209 | if(!sn_memory || !sn_memory->sn_nsdl_alloc || !sn_memory->sn_nsdl_free || !sn_nsdl_tx_cb || !sn_nsdl_rx_cb) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 210 | return SN_NSDL_FAILURE; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 211 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 212 | /* Define function pointers */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 213 | sn_nsdl_alloc = sn_memory->sn_nsdl_alloc; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 214 | sn_nsdl_free = sn_memory->sn_nsdl_free; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 215 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 216 | sn_nsdl_tx_callback = sn_nsdl_tx_cb; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 217 | sn_nsdl_rx_callback = sn_nsdl_rx_cb; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 218 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 219 | sn_linked_list_init(sn_nsdl_alloc, sn_nsdl_free); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 220 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 221 | message_list_ptr = sn_linked_list_create(); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 222 | if(!message_list_ptr) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 223 | return SN_NSDL_FAILURE; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 224 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 225 | /* Initialize ep parameters struct */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 226 | if(!ep_information_ptr) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 227 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 228 | ep_information_ptr = sn_nsdl_alloc(sizeof(sn_nsdl_ep_parameters_s)); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 229 | if(!ep_information_ptr) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 230 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 231 | sn_linked_list_free(message_list_ptr); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 232 | return SN_NSDL_FAILURE; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 233 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 234 | memset(ep_information_ptr, 0, sizeof(sn_nsdl_ep_parameters_s)); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 235 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 236 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 237 | /* Initialize GRS */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 238 | if(sn_grs_init(sn_nsdl_tx_cb,&sn_nsdl_local_rx_function, sn_memory)) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 239 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 240 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 241 | sn_nsdl_free(ep_information_ptr); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 242 | ep_information_ptr = 0; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 243 | sn_linked_list_free(message_list_ptr); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 244 | return SN_NSDL_FAILURE; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 245 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 246 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 247 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 248 | // todo: Resolve NS server address -> v0.5 = hardcoded address |
GeofferyOmlette | 0:f6e4e1bbb3fe | 249 | sn_nsdl_resolve_nsp_address(); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 250 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 251 | sn_nsdl_endpoint_registered = SN_NSDL_ENDPOINT_NOT_REGISTERED; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 252 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 253 | return SN_NSDL_SUCCESS; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 254 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 255 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 256 | int8_t sn_nsdl_GET_with_QUERY(char * uri, uint16_t urilen, uint8_t*destination, uint16_t port, char *query, uint8_t query_len) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 257 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 258 | sn_coap_hdr_s *message_ptr; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 259 | sn_nsdl_addr_s *dst = 0; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 260 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 261 | message_ptr = sn_nsdl_alloc(sizeof(sn_coap_hdr_s)); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 262 | if(message_ptr == NULL) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 263 | return SN_NSDL_FAILURE; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 264 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 265 | memset(message_ptr, 0, sizeof(sn_coap_hdr_s)); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 266 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 267 | /* Fill message fields -> confirmable post to specified NSP path */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 268 | message_ptr->msg_type = COAP_MSG_TYPE_CONFIRMABLE; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 269 | message_ptr->msg_code = COAP_MSG_CODE_REQUEST_GET; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 270 | /* Allocate memory for the extended options list */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 271 | message_ptr->options_list_ptr = sn_nsdl_alloc(sizeof(sn_coap_options_list_s)); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 272 | if(message_ptr->options_list_ptr == NULL) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 273 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 274 | sn_nsdl_free(message_ptr); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 275 | message_ptr = 0; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 276 | return SN_NSDL_FAILURE; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 277 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 278 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 279 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 280 | memset(message_ptr->options_list_ptr, 0, sizeof(sn_coap_options_list_s)); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 281 | message_ptr->options_list_ptr->uri_query_len =query_len; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 282 | message_ptr->options_list_ptr->uri_query_ptr = (uint8_t *)query; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 283 | message_ptr->uri_path_len = urilen; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 284 | message_ptr->uri_path_ptr = (uint8_t *)uri; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 285 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 286 | /* Build and send coap message to NSP */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 287 | /* Local variables */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 288 | if(!dst) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 289 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 290 | //allocate only if previously not allocated |
GeofferyOmlette | 0:f6e4e1bbb3fe | 291 | dst = sn_nsdl_alloc(sizeof(sn_nsdl_addr_s)); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 292 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 293 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 294 | if(dst) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 295 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 296 | /* This is only for version 0.5 */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 297 | dst->type = SN_NSDL_ADDRESS_TYPE_IPV6; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 298 | dst->port = port; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 299 | dst->addr_len = 16; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 300 | if(!dst->addr_ptr) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 301 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 302 | dst->addr_ptr = sn_nsdl_alloc(dst->addr_len); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 303 | memcpy(dst->addr_ptr, destination, 16); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 304 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 305 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 306 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 307 | sn_grs_send_coap_message(dst, message_ptr); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 308 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 309 | if(dst->addr_ptr) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 310 | sn_nsdl_free(dst->addr_ptr); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 311 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 312 | if(dst) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 313 | sn_nsdl_free(dst); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 314 | message_ptr->uri_path_ptr = NULL; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 315 | message_ptr->options_list_ptr->uri_host_ptr = NULL; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 316 | message_ptr->options_list_ptr->uri_query_ptr = NULL; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 317 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 318 | sn_coap_parser_release_allocated_coap_msg_mem(message_ptr); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 319 | return SN_NSDL_SUCCESS; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 320 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 321 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 322 | int8_t sn_nsdl_GET(char * uri, uint16_t urilen, uint8_t*destination, uint16_t port) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 323 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 324 | sn_coap_hdr_s *message_ptr; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 325 | sn_nsdl_addr_s *dst = 0; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 326 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 327 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 328 | message_ptr = sn_nsdl_alloc(sizeof(sn_coap_hdr_s)); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 329 | if(message_ptr == NULL) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 330 | return SN_NSDL_FAILURE; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 331 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 332 | memset(message_ptr, 0, sizeof(sn_coap_hdr_s)); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 333 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 334 | /* Fill message fields -> confirmable post to specified NSP path */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 335 | message_ptr->msg_type = COAP_MSG_TYPE_CONFIRMABLE; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 336 | message_ptr->msg_code = COAP_MSG_CODE_REQUEST_GET; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 337 | /* Allocate memory for the extended options list */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 338 | message_ptr->options_list_ptr = sn_nsdl_alloc(sizeof(sn_coap_options_list_s)); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 339 | if(message_ptr->options_list_ptr == NULL) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 340 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 341 | sn_nsdl_free(message_ptr); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 342 | message_ptr = 0; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 343 | return SN_NSDL_FAILURE; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 344 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 345 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 346 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 347 | memset(message_ptr->options_list_ptr, 0, sizeof(sn_coap_options_list_s)); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 348 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 349 | message_ptr->uri_path_len = urilen; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 350 | message_ptr->uri_path_ptr = (uint8_t *)uri; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 351 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 352 | /* Build and send coap message to NSP */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 353 | /* Local variables */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 354 | if(!dst) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 355 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 356 | //allocate only if previously not allocated |
GeofferyOmlette | 0:f6e4e1bbb3fe | 357 | dst = sn_nsdl_alloc(sizeof(sn_nsdl_addr_s)); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 358 | memset(dst, 0, sizeof(sn_nsdl_addr_s)); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 359 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 360 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 361 | if(dst) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 362 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 363 | /* This is only for version 0.5 */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 364 | dst->type = SN_NSDL_ADDRESS_TYPE_IPV6; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 365 | dst->port = port; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 366 | dst->addr_len = 16; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 367 | if(!dst->addr_ptr) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 368 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 369 | dst->addr_ptr = sn_nsdl_alloc(dst->addr_len); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 370 | memcpy(dst->addr_ptr, destination, 16); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 371 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 372 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 373 | sn_grs_send_coap_message(dst, message_ptr); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 374 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 375 | if(dst->addr_ptr) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 376 | sn_nsdl_free(dst->addr_ptr); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 377 | if(dst) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 378 | sn_nsdl_free(dst); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 379 | message_ptr->uri_path_ptr = NULL; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 380 | message_ptr->options_list_ptr->uri_host_ptr = NULL; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 381 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 382 | sn_coap_parser_release_allocated_coap_msg_mem(message_ptr); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 383 | return SN_NSDL_SUCCESS; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 384 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 385 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 386 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 387 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 388 | int8_t sn_nsdl_register_endpoint(sn_nsdl_ep_parameters_s *endpoint_info_ptr) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 389 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 390 | /* Local variables */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 391 | sn_coap_hdr_s *register_message_ptr; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 392 | int8_t status = 0; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 393 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 394 | if(!endpoint_info_ptr) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 395 | return SN_NSDL_FAILURE; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 396 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 397 | /*** Build endpoint register message ***/ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 398 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 399 | /* Allocate memory for header struct */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 400 | register_message_ptr = sn_nsdl_alloc(sizeof(sn_coap_hdr_s)); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 401 | if(register_message_ptr == NULL) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 402 | return SN_NSDL_FAILURE; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 403 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 404 | memset(register_message_ptr, 0, sizeof(sn_coap_hdr_s)); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 405 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 406 | /* Fill message fields -> confirmable post to specified NSP path */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 407 | register_message_ptr->msg_type = COAP_MSG_TYPE_CONFIRMABLE; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 408 | register_message_ptr->msg_code = COAP_MSG_CODE_REQUEST_POST; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 409 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 410 | /* Allocate memory for the extended options list */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 411 | register_message_ptr->options_list_ptr = sn_nsdl_alloc(sizeof(sn_coap_options_list_s)); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 412 | if(register_message_ptr->options_list_ptr == NULL) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 413 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 414 | sn_nsdl_free(register_message_ptr); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 415 | register_message_ptr = 0; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 416 | return SN_NSDL_FAILURE; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 417 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 418 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 419 | memset(register_message_ptr->options_list_ptr, 0, sizeof(sn_coap_options_list_s)); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 420 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 421 | register_message_ptr->uri_path_len = sizeof(resource_path_ptr); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 422 | register_message_ptr->uri_path_ptr = resource_path_ptr; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 423 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 424 | /* Fill Uri-query options */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 425 | sn_nsdl_fill_uri_query_options(endpoint_info_ptr, register_message_ptr, SN_NSDL_EP_REGISTER_MESSAGE); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 426 | #ifndef REG_TEMPLATE |
GeofferyOmlette | 0:f6e4e1bbb3fe | 427 | /* Built body for message */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 428 | status = sn_nsdl_build_registration_body(register_message_ptr, 0); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 429 | if(status == SN_NSDL_FAILURE) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 430 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 431 | register_message_ptr->uri_path_ptr = NULL; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 432 | register_message_ptr->options_list_ptr->uri_host_ptr = NULL; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 433 | sn_coap_parser_release_allocated_coap_msg_mem(register_message_ptr); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 434 | return SN_NSDL_FAILURE; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 435 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 436 | #endif |
GeofferyOmlette | 0:f6e4e1bbb3fe | 437 | /* Build and send coap message to NSP */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 438 | status = sn_nsdl_internal_coap_send(register_message_ptr, nsp_address_ptr, SN_NSDL_MSG_REGISTER); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 439 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 440 | if(register_message_ptr->payload_ptr) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 441 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 442 | sn_nsdl_free(register_message_ptr->payload_ptr); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 443 | register_message_ptr->payload_ptr = NULL; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 444 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 445 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 446 | register_message_ptr->uri_path_ptr = NULL; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 447 | register_message_ptr->options_list_ptr->uri_host_ptr = NULL; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 448 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 449 | sn_coap_parser_release_allocated_coap_msg_mem(register_message_ptr); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 450 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 451 | if(ep_information_ptr) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 452 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 453 | if(ep_information_ptr->domain_name_ptr) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 454 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 455 | sn_nsdl_free(ep_information_ptr->domain_name_ptr); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 456 | ep_information_ptr->domain_name_ptr = 0; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 457 | ep_information_ptr->domain_name_len = 0; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 458 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 459 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 460 | if(ep_information_ptr->endpoint_name_ptr) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 461 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 462 | sn_nsdl_free(ep_information_ptr->endpoint_name_ptr); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 463 | ep_information_ptr->endpoint_name_ptr = 0; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 464 | ep_information_ptr->endpoint_name_len = 0; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 465 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 466 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 467 | if(endpoint_info_ptr->domain_name_ptr) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 468 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 469 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 470 | if(!ep_information_ptr->domain_name_ptr) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 471 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 472 | ep_information_ptr->domain_name_ptr = sn_nsdl_alloc(endpoint_info_ptr->domain_name_len); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 473 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 474 | if(!ep_information_ptr->domain_name_ptr) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 475 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 476 | return SN_NSDL_FAILURE; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 477 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 478 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 479 | memcpy(ep_information_ptr->domain_name_ptr, endpoint_info_ptr->domain_name_ptr, endpoint_info_ptr->domain_name_len); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 480 | ep_information_ptr->domain_name_len = endpoint_info_ptr->domain_name_len; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 481 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 482 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 483 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 484 | if(endpoint_info_ptr->endpoint_name_ptr) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 485 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 486 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 487 | if(!ep_information_ptr->endpoint_name_ptr) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 488 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 489 | ep_information_ptr->endpoint_name_ptr = sn_nsdl_alloc(endpoint_info_ptr->endpoint_name_len); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 490 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 491 | if(!ep_information_ptr->endpoint_name_ptr) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 492 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 493 | if(ep_information_ptr->domain_name_ptr) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 494 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 495 | sn_nsdl_free(ep_information_ptr->domain_name_ptr); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 496 | ep_information_ptr->domain_name_ptr = 0; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 497 | ep_information_ptr->domain_name_len = 0; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 498 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 499 | return SN_NSDL_FAILURE; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 500 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 501 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 502 | memcpy(ep_information_ptr->endpoint_name_ptr, endpoint_info_ptr->endpoint_name_ptr, endpoint_info_ptr->endpoint_name_len); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 503 | ep_information_ptr->endpoint_name_len = endpoint_info_ptr->endpoint_name_len; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 504 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 505 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 506 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 507 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 508 | return status; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 509 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 510 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 511 | int8_t sn_nsdl_unregister_endpoint(void) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 512 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 513 | /* Local variables */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 514 | sn_coap_hdr_s *unregister_message_ptr; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 515 | uint8_t *temp_ptr = 0; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 516 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 517 | /* Check that EP have been registered */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 518 | if(sn_nsdl_is_ep_registered()) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 519 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 520 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 521 | /* Memory allocation for unregister message */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 522 | unregister_message_ptr = sn_nsdl_alloc(sizeof(sn_coap_hdr_s)); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 523 | if(!unregister_message_ptr) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 524 | return SN_NSDL_FAILURE; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 525 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 526 | memset(unregister_message_ptr, 0, sizeof(sn_coap_hdr_s)); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 527 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 528 | /* Fill unregister message */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 529 | unregister_message_ptr->msg_type = COAP_MSG_TYPE_CONFIRMABLE; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 530 | unregister_message_ptr->msg_code = COAP_MSG_CODE_REQUEST_DELETE; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 531 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 532 | unregister_message_ptr->uri_path_len = (RESOURCE_DIR_LEN + 1 + ep_information_ptr->domain_name_len + 1 + ep_information_ptr->endpoint_name_len); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 533 | unregister_message_ptr->uri_path_ptr = sn_nsdl_alloc(unregister_message_ptr->uri_path_len); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 534 | if (!unregister_message_ptr->uri_path_ptr) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 535 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 536 | sn_coap_parser_release_allocated_coap_msg_mem(unregister_message_ptr); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 537 | return SN_NSDL_FAILURE; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 538 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 539 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 540 | temp_ptr = unregister_message_ptr->uri_path_ptr; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 541 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 542 | memcpy(temp_ptr,resource_path_ptr, RESOURCE_DIR_LEN); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 543 | temp_ptr += RESOURCE_DIR_LEN; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 544 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 545 | *temp_ptr++ = '/'; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 546 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 547 | memcpy(temp_ptr ,ep_information_ptr->domain_name_ptr, ep_information_ptr->domain_name_len); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 548 | temp_ptr += ep_information_ptr->domain_name_len; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 549 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 550 | *temp_ptr++ = '/'; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 551 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 552 | memcpy(temp_ptr ,ep_information_ptr->endpoint_name_ptr, ep_information_ptr->endpoint_name_len); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 553 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 554 | /* Send message */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 555 | sn_nsdl_internal_coap_send(unregister_message_ptr, nsp_address_ptr, SN_NSDL_MSG_UNREGISTER); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 556 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 557 | /* Free memory */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 558 | sn_coap_parser_release_allocated_coap_msg_mem(unregister_message_ptr); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 559 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 560 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 561 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 562 | return SN_NSDL_SUCCESS; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 563 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 564 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 565 | int8_t sn_nsdl_update_registration (sn_nsdl_ep_parameters_s *endpoint_info_ptr) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 566 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 567 | /* Local variables */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 568 | sn_coap_hdr_s *register_message_ptr; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 569 | uint8_t *temp_ptr; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 570 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 571 | /*** Build endpoint register update message ***/ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 572 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 573 | /* Allocate memory for header struct */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 574 | register_message_ptr = sn_nsdl_alloc(sizeof(sn_coap_hdr_s)); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 575 | if(register_message_ptr == NULL) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 576 | return SN_NSDL_FAILURE; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 577 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 578 | memset(register_message_ptr, 0, sizeof(sn_coap_hdr_s)); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 579 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 580 | /* Fill message fields -> confirmable post to specified NSP path */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 581 | register_message_ptr->msg_type = COAP_MSG_TYPE_CONFIRMABLE; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 582 | register_message_ptr->msg_code = COAP_MSG_CODE_REQUEST_PUT; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 583 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 584 | register_message_ptr->uri_path_len = sizeof(resource_path_ptr) + ep_information_ptr->domain_name_len + ep_information_ptr->endpoint_name_len + 2; // = rd/domain/endpoint |
GeofferyOmlette | 0:f6e4e1bbb3fe | 585 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 586 | register_message_ptr->uri_path_ptr = sn_nsdl_alloc(register_message_ptr->uri_path_len); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 587 | if(!register_message_ptr->uri_path_ptr) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 588 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 589 | sn_coap_parser_release_allocated_coap_msg_mem(register_message_ptr); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 590 | return SN_NSDL_FAILURE; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 591 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 592 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 593 | temp_ptr = register_message_ptr->uri_path_ptr; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 594 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 595 | /* rd/ */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 596 | memcpy(temp_ptr, resource_path_ptr, sizeof(resource_path_ptr)); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 597 | temp_ptr += sizeof(resource_path_ptr); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 598 | *temp_ptr++ = '/'; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 599 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 600 | /* rd/DOMAIN/ */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 601 | memcpy(temp_ptr, ep_information_ptr->domain_name_ptr, ep_information_ptr->domain_name_len); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 602 | temp_ptr += ep_information_ptr->domain_name_len; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 603 | *temp_ptr++ = '/'; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 604 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 605 | /* rd/domain/ENDPOINT */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 606 | memcpy(temp_ptr, ep_information_ptr->endpoint_name_ptr, ep_information_ptr->endpoint_name_len); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 607 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 608 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 609 | /* Allocate memory for the extended options list */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 610 | register_message_ptr->options_list_ptr = sn_nsdl_alloc(sizeof(sn_coap_options_list_s)); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 611 | if(register_message_ptr->options_list_ptr == NULL) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 612 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 613 | sn_coap_parser_release_allocated_coap_msg_mem(register_message_ptr); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 614 | return SN_NSDL_FAILURE; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 615 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 616 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 617 | memset(register_message_ptr->options_list_ptr, 0, sizeof(sn_coap_options_list_s)); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 618 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 619 | /* Fill Uri-query options */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 620 | sn_nsdl_fill_uri_query_options(endpoint_info_ptr, register_message_ptr, SN_NSDL_EP_UPDATE_MESSAGE); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 621 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 622 | /* Build and send coap message to NSP */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 623 | sn_nsdl_internal_coap_send(register_message_ptr, nsp_address_ptr, SN_NSDL_MSG_UPDATE); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 624 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 625 | if(register_message_ptr->payload_ptr) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 626 | sn_nsdl_free(register_message_ptr->payload_ptr); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 627 | sn_coap_parser_release_allocated_coap_msg_mem(register_message_ptr); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 628 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 629 | return SN_NSDL_SUCCESS; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 630 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 631 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 632 | int8_t sn_nsdl_send_eventing_message (uint8_t *event_name_ptr, uint16_t event_name_len, uint8_t *message_body_ptr, uint16_t message_body_len) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 633 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 634 | sn_coap_hdr_s *eventing_message_ptr; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 635 | int8_t status = 0; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 636 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 637 | /* Allocate and initialize memory for header struct */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 638 | eventing_message_ptr = sn_nsdl_alloc(sizeof(sn_coap_hdr_s)); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 639 | if(eventing_message_ptr == NULL) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 640 | return SN_NSDL_FAILURE; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 641 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 642 | memset(eventing_message_ptr, 0, sizeof(sn_coap_hdr_s)); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 643 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 644 | /* Fill header */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 645 | eventing_message_ptr->msg_type = COAP_MSG_TYPE_CONFIRMABLE; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 646 | eventing_message_ptr->msg_code = COAP_MSG_CODE_REQUEST_POST; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 647 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 648 | /* Fill uri path option */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 649 | eventing_message_ptr->uri_path_len = sizeof(event_path_parameter) + event_name_len; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 650 | eventing_message_ptr->uri_path_ptr = sn_nsdl_alloc(eventing_message_ptr->uri_path_len); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 651 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 652 | if(!eventing_message_ptr->uri_path_ptr) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 653 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 654 | sn_coap_parser_release_allocated_coap_msg_mem(eventing_message_ptr); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 655 | return SN_NSDL_FAILURE; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 656 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 657 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 658 | memcpy(eventing_message_ptr->uri_path_ptr, event_path_parameter, sizeof(event_path_parameter)); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 659 | memcpy(eventing_message_ptr->uri_path_ptr + sizeof(event_path_parameter), event_name_ptr, event_name_len); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 660 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 661 | /* Fill payload */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 662 | eventing_message_ptr->payload_len = message_body_len; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 663 | eventing_message_ptr->payload_ptr = message_body_ptr; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 664 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 665 | /* Send coap message */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 666 | status = sn_nsdl_internal_coap_send(eventing_message_ptr, nsp_address_ptr, SN_NSDL_MSG_EVENT); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 667 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 668 | eventing_message_ptr->payload_ptr = NULL; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 669 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 670 | sn_coap_parser_release_allocated_coap_msg_mem(eventing_message_ptr); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 671 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 672 | return status; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 673 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 674 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 675 | void sn_nsdl_nsp_lost(void) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 676 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 677 | sn_nsdl_endpoint_registered = SN_NSDL_ENDPOINT_NOT_REGISTERED; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 678 | return; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 679 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 680 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 681 | int8_t sn_nsdl_is_ep_registered(void) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 682 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 683 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 684 | return sn_nsdl_endpoint_registered; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 685 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 686 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 687 | uint16_t sn_nsdl_send_observation_notification(uint8_t *token_ptr, uint8_t token_len, |
GeofferyOmlette | 0:f6e4e1bbb3fe | 688 | uint8_t *payload_ptr, uint16_t payload_len, |
GeofferyOmlette | 0:f6e4e1bbb3fe | 689 | uint8_t *observe_ptr, uint8_t observe_len, |
GeofferyOmlette | 0:f6e4e1bbb3fe | 690 | sn_coap_msg_type_e message_type, uint8_t content_type) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 691 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 692 | sn_coap_hdr_s *notification_message_ptr; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 693 | uint16_t return_msg_id = 0; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 694 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 695 | /* Allocate and initialize memory for header struct */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 696 | notification_message_ptr = sn_nsdl_alloc(sizeof(sn_coap_hdr_s)); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 697 | if(notification_message_ptr == NULL) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 698 | return 0; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 699 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 700 | memset(notification_message_ptr, 0, sizeof(sn_coap_hdr_s)); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 701 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 702 | notification_message_ptr->options_list_ptr = sn_nsdl_alloc(sizeof(sn_coap_options_list_s)); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 703 | if(notification_message_ptr->options_list_ptr == NULL) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 704 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 705 | sn_nsdl_free(notification_message_ptr); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 706 | return 0; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 707 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 708 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 709 | memset(notification_message_ptr->options_list_ptr , 0, sizeof(sn_coap_options_list_s)); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 710 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 711 | /* Fill header */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 712 | notification_message_ptr->msg_type = message_type; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 713 | notification_message_ptr->msg_code = COAP_MSG_CODE_RESPONSE_CONTENT; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 714 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 715 | /* Fill token */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 716 | notification_message_ptr->token_len = token_len; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 717 | notification_message_ptr->token_ptr = token_ptr; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 718 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 719 | /* Fill payload */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 720 | notification_message_ptr->payload_len = payload_len; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 721 | notification_message_ptr->payload_ptr = payload_ptr; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 722 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 723 | /* Fill observe */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 724 | notification_message_ptr->options_list_ptr->observe_len = observe_len; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 725 | notification_message_ptr->options_list_ptr->observe_ptr = observe_ptr; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 726 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 727 | /* Fill content type */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 728 | if(content_type) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 729 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 730 | notification_message_ptr->content_type_len = 1; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 731 | notification_message_ptr->content_type_ptr = &content_type; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 732 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 733 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 734 | /* Send message */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 735 | if(sn_grs_send_coap_message(nsp_address_ptr,notification_message_ptr) == SN_NSDL_FAILURE) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 736 | return_msg_id = 0; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 737 | else |
GeofferyOmlette | 0:f6e4e1bbb3fe | 738 | return_msg_id = notification_message_ptr->msg_id; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 739 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 740 | /* Free memory */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 741 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 742 | notification_message_ptr->payload_ptr = NULL; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 743 | notification_message_ptr->options_list_ptr->observe_ptr = NULL; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 744 | notification_message_ptr->token_ptr = NULL; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 745 | notification_message_ptr->content_type_ptr = NULL; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 746 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 747 | sn_coap_parser_release_allocated_coap_msg_mem(notification_message_ptr); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 748 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 749 | return return_msg_id; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 750 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 751 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 752 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 753 | /* * * * * * * * * * * * * * * * * * * * * */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 754 | /* GRS Wrapper */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 755 | /* These are documented in sn_grs.c - file */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 756 | /* * * * * * * * * * * * * * * * * * * * * */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 757 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 758 | int16_t sn_nsdl_get_capability(void) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 759 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 760 | return sn_grs_get_capability(); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 761 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 762 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 763 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 764 | uint32_t sn_nsdl_get_version(void) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 765 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 766 | return sn_grs_get_version(); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 767 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 768 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 769 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 770 | int8_t sn_nsdl_process_http(uint8_t *packet_ptr, uint16_t *packet_len_ptr, sn_nsdl_addr_s *src_ptr) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 771 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 772 | return sn_grs_process_http(packet_ptr, packet_len_ptr, src_ptr); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 773 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 774 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 775 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 776 | int8_t sn_nsdl_process_coap(uint8_t *packet_ptr, uint16_t packet_len_ptr, sn_nsdl_addr_s *src_ptr) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 777 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 778 | return sn_grs_process_coap(packet_ptr, packet_len_ptr, src_ptr); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 779 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 780 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 781 | int8_t sn_nsdl_exec(uint32_t time) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 782 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 783 | return sn_grs_exec(time); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 784 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 785 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 786 | int8_t sn_nsdl_create_resource(sn_nsdl_resource_info_s *res_ptr) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 787 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 788 | return sn_grs_create_resource(res_ptr); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 789 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 790 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 791 | int8_t sn_nsdl_update_resource(sn_nsdl_resource_info_s *res_ptr) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 792 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 793 | return sn_grs_update_resource(res_ptr); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 794 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 795 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 796 | int8_t sn_nsdl_delete_resource(uint8_t pathlen, uint8_t *path_ptr) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 797 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 798 | return sn_grs_delete_resource(pathlen, path_ptr); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 799 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 800 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 801 | sn_nsdl_resource_info_s *sn_nsdl_get_resource(uint16_t pathlen, uint8_t *path_ptr) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 802 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 803 | return sn_grs_get_resource(pathlen, path_ptr); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 804 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 805 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 806 | sn_grs_resource_list_s *sn_nsdl_list_resource(uint16_t pathlen, uint8_t *path_ptr) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 807 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 808 | return sn_grs_list_resource(pathlen, path_ptr); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 809 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 810 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 811 | int8_t sn_nsdl_send_coap_message(sn_nsdl_addr_s *address_ptr, sn_coap_hdr_s *coap_hdr_ptr) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 812 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 813 | return sn_grs_send_coap_message(address_ptr, coap_hdr_ptr); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 814 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 815 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 816 | /********************/ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 817 | /* Static functions */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 818 | /********************/ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 819 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 820 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 821 | /** |
GeofferyOmlette | 0:f6e4e1bbb3fe | 822 | * \fn static int8_t sn_nsdl_send_coap_message(sn_coap_hdr_s *coap_header_ptr, sn_nsdl_addr_s *dst_addr_ptr, uint8_t message_description) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 823 | * |
GeofferyOmlette | 0:f6e4e1bbb3fe | 824 | * |
GeofferyOmlette | 0:f6e4e1bbb3fe | 825 | * \brief To send NSDL messages. Stores message id?s and message description to catch response from NSP server |
GeofferyOmlette | 0:f6e4e1bbb3fe | 826 | * |
GeofferyOmlette | 0:f6e4e1bbb3fe | 827 | * \param *coap_header_ptr Pointer to the CoAP message header to be sent |
GeofferyOmlette | 0:f6e4e1bbb3fe | 828 | * \param *dst_addr_ptr Pointer to the address structure that contains destination address information |
GeofferyOmlette | 0:f6e4e1bbb3fe | 829 | * \param message_description Message description to be stored to list for waiting response |
GeofferyOmlette | 0:f6e4e1bbb3fe | 830 | * |
GeofferyOmlette | 0:f6e4e1bbb3fe | 831 | * \return SN_NSDL_SUCCESS = 0, Failed = -1 |
GeofferyOmlette | 0:f6e4e1bbb3fe | 832 | */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 833 | static int8_t sn_nsdl_internal_coap_send(sn_coap_hdr_s *coap_header_ptr, sn_nsdl_addr_s *dst_addr_ptr, uint8_t message_description) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 834 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 835 | uint8_t *coap_message_ptr = NULL; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 836 | uint16_t coap_message_len = 0; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 837 | int16_t status = 0; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 838 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 839 | coap_message_len = sn_coap_builder_calc_needed_packet_data_size(coap_header_ptr); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 840 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 841 | if(coap_message_len == 0) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 842 | return SN_NSDL_FAILURE; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 843 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 844 | coap_message_ptr = sn_nsdl_alloc(coap_message_len); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 845 | if(!coap_message_ptr) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 846 | return SN_NSDL_FAILURE; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 847 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 848 | /* Build message */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 849 | status = sn_coap_protocol_build(dst_addr_ptr,coap_message_ptr, coap_header_ptr); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 850 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 851 | /* If message building failed */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 852 | if(status < 0) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 853 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 854 | sn_nsdl_free(coap_message_ptr); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 855 | return SN_NSDL_FAILURE; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 856 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 857 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 858 | /* If mesage type is confirmable, save it to list to wait for reply */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 859 | if(coap_header_ptr->msg_type == COAP_MSG_TYPE_CONFIRMABLE) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 860 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 861 | sn_nsdl_sent_messages_s *message_ptr = sn_nsdl_alloc(sizeof(sn_nsdl_sent_messages_s)); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 862 | if(message_ptr) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 863 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 864 | if(sn_linked_list_count_nodes(message_list_ptr) >= SN_NSDL_MAX_MESSAGE_COUNT) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 865 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 866 | sn_nsdl_sent_messages_s *message_temp_ptr = sn_linked_list_get_last_node(message_list_ptr); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 867 | if(message_temp_ptr) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 868 | sn_nsdl_free(message_temp_ptr); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 869 | sn_linked_list_remove_current_node(message_list_ptr); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 870 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 871 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 872 | message_ptr->message_type = message_description; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 873 | message_ptr->msg_id_number = coap_header_ptr->msg_id; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 874 | sn_linked_list_add_node(message_list_ptr, (void*)message_ptr); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 875 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 876 | status = SN_NSDL_SUCCESS; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 877 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 878 | else |
GeofferyOmlette | 0:f6e4e1bbb3fe | 879 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 880 | status = SN_NSDL_FAILURE; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 881 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 882 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 883 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 884 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 885 | sn_nsdl_tx_callback(SN_NSDL_PROTOCOL_COAP, coap_message_ptr, coap_message_len, dst_addr_ptr); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 886 | sn_nsdl_free(coap_message_ptr); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 887 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 888 | return status; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 889 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 890 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 891 | /** |
GeofferyOmlette | 0:f6e4e1bbb3fe | 892 | * \fn static void sn_nsdl_resolve_nsp_address(void) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 893 | * |
GeofferyOmlette | 0:f6e4e1bbb3fe | 894 | * \brief Resolves NSP server address. |
GeofferyOmlette | 0:f6e4e1bbb3fe | 895 | * |
GeofferyOmlette | 0:f6e4e1bbb3fe | 896 | * \note Application must set NSP address with set_nsp_address |
GeofferyOmlette | 0:f6e4e1bbb3fe | 897 | */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 898 | static void sn_nsdl_resolve_nsp_address(void) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 899 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 900 | /* Local variables */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 901 | if(!nsp_address_ptr) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 902 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 903 | //allocate only if previously not allocated |
GeofferyOmlette | 0:f6e4e1bbb3fe | 904 | nsp_address_ptr = sn_nsdl_alloc(sizeof(sn_nsdl_addr_s)); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 905 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 906 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 907 | if(nsp_address_ptr) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 908 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 909 | memset(nsp_address_ptr, 0, sizeof(sn_nsdl_addr_s)); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 910 | /* This is only for version 0.5 */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 911 | nsp_address_ptr->type = SN_NSDL_ADDRESS_TYPE_NONE; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 912 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 913 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 914 | /* Todo: get NSP address */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 915 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 916 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 917 | /** |
GeofferyOmlette | 0:f6e4e1bbb3fe | 918 | * \fn static int8_t sn_nsdl_build_registration_body(sn_coap_hdr_s *message_ptr) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 919 | * |
GeofferyOmlette | 0:f6e4e1bbb3fe | 920 | * \brief To build GRS resources to registration message payload |
GeofferyOmlette | 0:f6e4e1bbb3fe | 921 | * |
GeofferyOmlette | 0:f6e4e1bbb3fe | 922 | * \param *message_ptr Pointer to CoAP message header |
GeofferyOmlette | 0:f6e4e1bbb3fe | 923 | * |
GeofferyOmlette | 0:f6e4e1bbb3fe | 924 | * \return SN_NSDL_SUCCESS = 0, Failed = -1 |
GeofferyOmlette | 0:f6e4e1bbb3fe | 925 | */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 926 | int8_t sn_nsdl_build_registration_body(sn_coap_hdr_s *message_ptr, uint8_t updating_registeration) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 927 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 928 | /* Local variables */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 929 | uint8_t *temp_ptr; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 930 | sn_nsdl_resource_info_s *resource_temp_ptr; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 931 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 932 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 933 | /* Get list of resources */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 934 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 935 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 936 | /* Calculate needed memory and allocate */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 937 | message_ptr->payload_len = sn_nsdl_calculate_registration_body_size(updating_registeration); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 938 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 939 | /* If no resources to be registered, return SN_NSDL_SUCCESS */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 940 | if(!message_ptr->payload_len) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 941 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 942 | return SN_NSDL_SUCCESS; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 943 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 944 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 945 | message_ptr->payload_ptr = sn_nsdl_alloc(message_ptr->payload_len); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 946 | if(!message_ptr->payload_ptr) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 947 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 948 | return SN_NSDL_FAILURE; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 949 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 950 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 951 | /* Build message */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 952 | temp_ptr = message_ptr->payload_ptr; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 953 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 954 | resource_temp_ptr = sn_grs_get_first_resource(); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 955 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 956 | /* Loop trough all resources */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 957 | while(resource_temp_ptr) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 958 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 959 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 960 | /* if resource needs to be registered */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 961 | if(resource_temp_ptr->resource_parameters_ptr) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 962 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 963 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 964 | if(updating_registeration && resource_temp_ptr->resource_parameters_ptr->registered == SN_NDSL_RESOURCE_REGISTERED) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 965 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 966 | resource_temp_ptr = sn_grs_get_next_resource(); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 967 | continue; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 968 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 969 | else |
GeofferyOmlette | 0:f6e4e1bbb3fe | 970 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 971 | resource_temp_ptr->resource_parameters_ptr->registered = SN_NDSL_RESOURCE_REGISTERING; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 972 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 973 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 974 | /* If not first resource, add '.' to separator */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 975 | if(temp_ptr != message_ptr->payload_ptr) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 976 | *temp_ptr++ = ','; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 977 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 978 | *temp_ptr++ = '<'; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 979 | *temp_ptr++ = '/'; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 980 | memcpy(temp_ptr, resource_temp_ptr->path, resource_temp_ptr->pathlen); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 981 | temp_ptr += resource_temp_ptr->pathlen; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 982 | *temp_ptr++ = '>'; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 983 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 984 | /* Resource attributes */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 985 | if(resource_temp_ptr->resource_parameters_ptr->resource_type_len) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 986 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 987 | *temp_ptr++ = ';'; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 988 | memcpy(temp_ptr, resource_type_parameter, RT_PARAMETER_LEN); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 989 | temp_ptr += RT_PARAMETER_LEN; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 990 | *temp_ptr++ = '"'; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 991 | memcpy(temp_ptr, resource_temp_ptr->resource_parameters_ptr->resource_type_ptr, resource_temp_ptr->resource_parameters_ptr->resource_type_len); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 992 | temp_ptr += resource_temp_ptr->resource_parameters_ptr->resource_type_len; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 993 | *temp_ptr++ = '"'; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 994 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 995 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 996 | if(resource_temp_ptr->resource_parameters_ptr->interface_description_len) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 997 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 998 | *temp_ptr++ = ';'; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 999 | memcpy(temp_ptr, if_description_parameter, IF_PARAMETER_LEN); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1000 | temp_ptr += IF_PARAMETER_LEN; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1001 | *temp_ptr++ = '"'; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1002 | memcpy(temp_ptr, resource_temp_ptr->resource_parameters_ptr->interface_description_ptr, resource_temp_ptr->resource_parameters_ptr->interface_description_len); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1003 | temp_ptr += resource_temp_ptr->resource_parameters_ptr->interface_description_len; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1004 | *temp_ptr++ = '"'; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1005 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1006 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1007 | if(resource_temp_ptr->resource_parameters_ptr->coap_content_type != 0) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1008 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1009 | *temp_ptr++ = ';'; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1010 | memcpy(temp_ptr, coap_con_type_parameter, COAP_CON_PARAMETER_LEN); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1011 | temp_ptr += COAP_CON_PARAMETER_LEN; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1012 | *temp_ptr++ = '"'; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1013 | temp_ptr = sn_nsdl_itoa(temp_ptr, resource_temp_ptr->resource_parameters_ptr->coap_content_type); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1014 | *temp_ptr++ = '"'; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1015 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1016 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1017 | /* ;obs */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1018 | if(resource_temp_ptr->resource_parameters_ptr->observable) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1019 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1020 | *temp_ptr++ = ';'; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1021 | memcpy(temp_ptr, obs_parameter, OBS_PARAMETER_LEN); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1022 | temp_ptr += OBS_PARAMETER_LEN; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1023 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1024 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1025 | /* ;aobs;id= */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1026 | /* todo: aosb not supported ATM - needs fixing */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1027 | /* |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1028 | if((resource_temp_ptr->resource_parameters_ptr->auto_obs_len > 0 && resource_temp_ptr->resource_parameters_ptr->auto_obs_len <= 8) && |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1029 | resource_temp_ptr->resource_parameters_ptr->auto_obs_ptr) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1030 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1031 | uint8_t i = 0; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1032 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1033 | *temp_ptr++ = ';'; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1034 | memcpy(temp_ptr, aobs_parameter, AOBS_PARAMETER_LEN); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1035 | temp_ptr += AOBS_PARAMETER_LEN; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1036 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1037 | while(i < resource_temp_ptr->resource_parameters_ptr->auto_obs_len) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1038 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1039 | temp_ptr = sn_nsdl_itoa(temp_ptr, *(resource_temp_ptr->resource_parameters_ptr->auto_obs_ptr + i)); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1040 | i++; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1041 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1042 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1043 | */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1044 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1045 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1046 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1047 | resource_temp_ptr = sn_grs_get_next_resource(); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1048 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1049 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1050 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1051 | return SN_NSDL_SUCCESS; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1052 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1053 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1054 | /** |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1055 | * \fn static uint16_t sn_nsdl_calculate_registration_body_size(sn_grs_resource_list_s *grs_resources_list_ptr) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1056 | * |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1057 | * |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1058 | * \brief Calculates registration message payload size |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1059 | * |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1060 | * \param *grs_resources_list_ptr Pointer to list of GRS resources |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1061 | * |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1062 | * \return Needed payload size |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1063 | */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1064 | static uint16_t sn_nsdl_calculate_registration_body_size(uint8_t updating_registeration) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1065 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1066 | /* Local variables */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1067 | uint16_t return_value = 0; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1068 | sn_nsdl_resource_info_s *resource_temp_ptr; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1069 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1070 | /* check pointer */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1071 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1072 | resource_temp_ptr = sn_grs_get_first_resource(); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1073 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1074 | while(resource_temp_ptr) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1075 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1076 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1077 | if(resource_temp_ptr->resource_parameters_ptr) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1078 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1079 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1080 | if(updating_registeration && resource_temp_ptr->resource_parameters_ptr->registered == SN_NDSL_RESOURCE_REGISTERED) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1081 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1082 | resource_temp_ptr = sn_grs_get_next_resource(); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1083 | continue; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1084 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1085 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1086 | /* If not first resource, then '.' will be added */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1087 | if(return_value) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1088 | return_value++; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1089 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1090 | /* Count length for the resource path </path> */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1091 | return_value += (3 + resource_temp_ptr->pathlen); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1092 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1093 | /* Count lengths of the attributes */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1094 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1095 | /* Resource type parameter */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1096 | if(resource_temp_ptr->resource_parameters_ptr->resource_type_len) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1097 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1098 | /* ;rt="restype" */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1099 | return_value += (6 + resource_temp_ptr->resource_parameters_ptr->resource_type_len); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1100 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1101 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1102 | /* Interface description parameter */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1103 | if(resource_temp_ptr->resource_parameters_ptr->interface_description_len) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1104 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1105 | /* ;if="iftype" */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1106 | return_value += (6 + resource_temp_ptr->resource_parameters_ptr->interface_description_len); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1107 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1108 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1109 | if(resource_temp_ptr->resource_parameters_ptr->coap_content_type != 0) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1110 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1111 | /* ;if="content" */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1112 | return_value += 6; // all but not content |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1113 | return_value += sn_nsdl_itoa_len(resource_temp_ptr->resource_parameters_ptr->coap_content_type); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1114 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1115 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1116 | if(resource_temp_ptr->resource_parameters_ptr->observable) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1117 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1118 | /* ;obs */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1119 | return_value += 4; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1120 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1121 | /*todo: aobs not supported ATM - needs fixing*/ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1122 | /* |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1123 | if((resource_temp_ptr->resource_parameters_ptr->auto_obs_len > 0 && resource_temp_ptr->resource_parameters_ptr->auto_obs_len <= 8) && |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1124 | resource_temp_ptr->resource_parameters_ptr->auto_obs_ptr) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1125 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1126 | uint8_t i = resource_temp_ptr->resource_parameters_ptr->auto_obs_len; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1127 | // ;aobs;id= |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1128 | return_value += 9; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1129 | while(i--) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1130 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1131 | return_value += sn_nsdl_itoa_len(*(resource_temp_ptr->resource_parameters_ptr->auto_obs_ptr + i)); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1132 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1133 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1134 | */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1135 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1136 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1137 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1138 | resource_temp_ptr = sn_grs_get_next_resource(); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1139 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1140 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1141 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1142 | return return_value; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1143 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1144 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1145 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1146 | /** |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1147 | * \fn static uint8_t sn_nsdl_calculate_uri_query_option_len(sn_nsdl_ep_parameters_s *endpoint_info_ptr, uint8_t msg_type) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1148 | * |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1149 | * |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1150 | * \brief Calculates needed uri query option length |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1151 | * |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1152 | * \param *endpoint_info_ptr Pointer to endpoint info structure |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1153 | * \param msg_type Message type |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1154 | * |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1155 | * \return SN_NSDL_SUCCESS = 0, Failed = -1 |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1156 | */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1157 | static uint8_t sn_nsdl_calculate_uri_query_option_len(sn_nsdl_ep_parameters_s *endpoint_info_ptr, uint8_t msg_type) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1158 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1159 | uint8_t return_value = 0; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1160 | uint8_t number_of_parameters = 0; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1161 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1162 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1163 | if((endpoint_info_ptr->endpoint_name_len != 0) && (msg_type == SN_NSDL_EP_REGISTER_MESSAGE) && endpoint_info_ptr->endpoint_name_ptr != 0) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1164 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1165 | return_value += endpoint_info_ptr->endpoint_name_len; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1166 | return_value += EP_NAME_PARAMETERS_LEN; //ep= |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1167 | number_of_parameters++; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1168 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1169 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1170 | if((endpoint_info_ptr->type_len != 0) && (endpoint_info_ptr->type_ptr != 0)) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1171 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1172 | return_value+=endpoint_info_ptr->type_len; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1173 | return_value += RT_PARAMETER_LEN; //et= |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1174 | number_of_parameters++; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1175 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1176 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1177 | if((endpoint_info_ptr->lifetime_len != 0) && (endpoint_info_ptr->lifetime_ptr != 0)) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1178 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1179 | return_value+=endpoint_info_ptr->lifetime_len; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1180 | return_value += LT_PARAMETER_LEN; //lt= |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1181 | number_of_parameters++; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1182 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1183 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1184 | if((endpoint_info_ptr->domain_name_len != 0) && (endpoint_info_ptr->domain_name_ptr != 0)) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1185 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1186 | return_value+=endpoint_info_ptr->domain_name_len; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1187 | return_value += DOMAIN_PARAMETER_LEN; //d= |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1188 | number_of_parameters++; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1189 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1190 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1191 | if(number_of_parameters != 0) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1192 | return_value += (number_of_parameters - 1); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1193 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1194 | return return_value; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1195 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1196 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1197 | /** |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1198 | * \fn static int8_t sn_nsdl_fill_uri_query_options(sn_nsdl_ep_parameters_s *parameter_ptr, sn_coap_hdr_s *source_msg_ptr, uint8_t msg_type) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1199 | * |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1200 | * |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1201 | * \brief Fills uri-query options to message header struct |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1202 | * |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1203 | * \param *parameter_ptr Pointer to endpoint parameters struct |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1204 | * \param *source_msg_ptr Pointer to CoAP header struct |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1205 | * \param msg_type Message type |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1206 | * |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1207 | * \return SN_NSDL_SUCCESS = 0, Failed = -1 |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1208 | */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1209 | static int8_t sn_nsdl_fill_uri_query_options(sn_nsdl_ep_parameters_s *parameter_ptr, sn_coap_hdr_s *source_msg_ptr, uint8_t msg_type) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1210 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1211 | uint8_t *temp_ptr = NULL; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1212 | source_msg_ptr->options_list_ptr->uri_query_len = sn_nsdl_calculate_uri_query_option_len(parameter_ptr, msg_type); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1213 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1214 | if(source_msg_ptr->options_list_ptr->uri_query_len == 0) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1215 | return 0; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1216 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1217 | source_msg_ptr->options_list_ptr->uri_query_ptr = sn_nsdl_alloc(source_msg_ptr->options_list_ptr->uri_query_len); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1218 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1219 | if (source_msg_ptr->options_list_ptr->uri_query_ptr == NULL) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1220 | return SN_NSDL_FAILURE; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1221 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1222 | temp_ptr = source_msg_ptr->options_list_ptr->uri_query_ptr; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1223 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1224 | /******************************************************/ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1225 | /* If endpoint name is configured, fill needed fields */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1226 | /******************************************************/ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1227 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1228 | if((parameter_ptr->endpoint_name_len != 0) && (parameter_ptr->endpoint_name_ptr != 0) && (msg_type == SN_NSDL_EP_REGISTER_MESSAGE)) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1229 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1230 | /* fill endpoint name, first ?ep=, then endpoint name */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1231 | memcpy(temp_ptr, ep_name_parameter_string, sizeof(ep_name_parameter_string)); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1232 | temp_ptr += EP_NAME_PARAMETERS_LEN; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1233 | memcpy(temp_ptr, parameter_ptr->endpoint_name_ptr, parameter_ptr->endpoint_name_len); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1234 | temp_ptr += parameter_ptr->endpoint_name_len; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1235 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1236 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1237 | /******************************************************/ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1238 | /* If endpoint type is configured, fill needed fields */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1239 | /******************************************************/ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1240 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1241 | if((parameter_ptr->type_len != 0) && (parameter_ptr->type_ptr != 0)) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1242 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1243 | if(temp_ptr != source_msg_ptr->options_list_ptr->uri_query_ptr) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1244 | *temp_ptr++ = '&'; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1245 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1246 | memcpy(temp_ptr, resource_type_parameter, sizeof(resource_type_parameter)); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1247 | temp_ptr += RT_PARAMETER_LEN; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1248 | memcpy(temp_ptr, parameter_ptr->type_ptr, parameter_ptr->type_len); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1249 | temp_ptr += parameter_ptr->type_len; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1250 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1251 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1252 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1253 | /******************************************************/ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1254 | /* If lifetime is configured, fill needed fields */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1255 | /******************************************************/ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1256 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1257 | if((parameter_ptr->lifetime_len != 0) && (parameter_ptr->lifetime_ptr != 0)) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1258 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1259 | if(temp_ptr != source_msg_ptr->options_list_ptr->uri_query_ptr) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1260 | *temp_ptr++ = '&'; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1261 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1262 | memcpy(temp_ptr, ep_lifetime_parameter, sizeof(ep_lifetime_parameter)); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1263 | temp_ptr += LT_PARAMETER_LEN; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1264 | memcpy(temp_ptr, parameter_ptr->lifetime_ptr, parameter_ptr->lifetime_len); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1265 | temp_ptr += parameter_ptr->lifetime_len; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1266 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1267 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1268 | /******************************************************/ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1269 | /* If domain is configured, fill needed fields */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1270 | /******************************************************/ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1271 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1272 | if((parameter_ptr->domain_name_len != 0) && (parameter_ptr->domain_name_ptr != 0)) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1273 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1274 | if(temp_ptr != source_msg_ptr->options_list_ptr->uri_query_ptr) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1275 | *temp_ptr++ = '&'; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1276 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1277 | memcpy(temp_ptr, ep_domain_parameter, sizeof(ep_domain_parameter)); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1278 | temp_ptr += DOMAIN_PARAMETER_LEN; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1279 | memcpy(temp_ptr, parameter_ptr->domain_name_ptr, parameter_ptr->domain_name_len); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1280 | temp_ptr += parameter_ptr->domain_name_len; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1281 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1282 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1283 | return SN_NSDL_SUCCESS; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1284 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1285 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1286 | /** |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1287 | * \fn static uint8_t sn_nsdl_local_rx_function(sn_coap_hdr_s *coap_packet_ptr, sn_nsdl_addr_s *address_ptr) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1288 | * |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1289 | * \brief If received message is reply for the message that NSDL has been sent, it is processed here. Else, packet will be sent to application. |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1290 | * |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1291 | * \param *coap_packet_ptr Pointer to received CoAP packet |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1292 | * \param *address_ptr Pointer to source address struct |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1293 | * |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1294 | * \return SN_NSDL_SUCCESS = 0, Failed = -1 |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1295 | */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1296 | static int8_t sn_nsdl_local_rx_function(sn_coap_hdr_s *coap_packet_ptr, sn_nsdl_addr_s *address_ptr) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1297 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1298 | int8_t status = 0; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1299 | uint16_t number_of_messages; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1300 | sn_nsdl_sent_messages_s *sent_message_temp_ptr; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1301 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1302 | if((coap_packet_ptr == 0) || (address_ptr == 0)) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1303 | return -1; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1304 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1305 | /* If we wait for a response to some message.. */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1306 | number_of_messages = sn_linked_list_count_nodes(message_list_ptr); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1307 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1308 | if(number_of_messages) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1309 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1310 | while(number_of_messages--) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1311 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1312 | sent_message_temp_ptr = sn_linked_list_get_last_node(message_list_ptr); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1313 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1314 | if(sent_message_temp_ptr) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1315 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1316 | if(sent_message_temp_ptr->msg_id_number == coap_packet_ptr->msg_id) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1317 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1318 | switch(sent_message_temp_ptr->message_type) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1319 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1320 | case SN_NSDL_MSG_REGISTER: |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1321 | if(coap_packet_ptr->msg_code == COAP_MSG_CODE_RESPONSE_CREATED) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1322 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1323 | sn_nsdl_endpoint_registered = SN_NSDL_ENDPOINT_IS_REGISTERED; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1324 | sn_nsdl_mark_resources_as_registered(); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1325 | status = sn_nsdl_resolve_ep_information(coap_packet_ptr); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1326 | if(status != SN_NSDL_SUCCESS) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1327 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1328 | /* Node can be removed */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1329 | sn_nsdl_free(sent_message_temp_ptr); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1330 | sn_linked_list_remove_current_node(message_list_ptr); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1331 | return status; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1332 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1333 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1334 | break; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1335 | case SN_NSDL_MSG_UNREGISTER: |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1336 | if(coap_packet_ptr->msg_code == COAP_MSG_CODE_RESPONSE_DELETED) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1337 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1338 | if(ep_information_ptr->endpoint_name_ptr) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1339 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1340 | sn_nsdl_free(ep_information_ptr->endpoint_name_ptr); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1341 | ep_information_ptr->endpoint_name_ptr = 0; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1342 | ep_information_ptr->endpoint_name_len = 0; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1343 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1344 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1345 | if(ep_information_ptr->domain_name_ptr) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1346 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1347 | sn_nsdl_free(ep_information_ptr->domain_name_ptr); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1348 | ep_information_ptr->domain_name_ptr = 0; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1349 | ep_information_ptr->domain_name_len = 0; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1350 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1351 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1352 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1353 | break; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1354 | case SN_NSDL_MSG_EVENT: |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1355 | case SN_NSDL_MSG_UPDATE: |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1356 | break; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1357 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1358 | /* Node can be removed */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1359 | sn_nsdl_free(sent_message_temp_ptr); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1360 | sn_linked_list_remove_current_node(message_list_ptr); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1361 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1362 | sn_nsdl_rx_callback(coap_packet_ptr, address_ptr); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1363 | return SN_NSDL_SUCCESS; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1364 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1365 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1366 | sent_message_temp_ptr = sn_linked_list_get_previous_node(message_list_ptr); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1367 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1368 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1369 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1370 | /* No messages to wait for, or message was not response to our request */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1371 | status = sn_nsdl_rx_callback(coap_packet_ptr, address_ptr); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1372 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1373 | return status; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1374 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1375 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1376 | void sn_nsdl_mark_resources_as_registered(void) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1377 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1378 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1379 | sn_nsdl_resource_info_s *temp_resource; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1380 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1381 | temp_resource = sn_grs_get_first_resource(); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1382 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1383 | while(temp_resource) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1384 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1385 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1386 | if(temp_resource->resource_parameters_ptr->registered == SN_NDSL_RESOURCE_REGISTERING) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1387 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1388 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1389 | temp_resource->resource_parameters_ptr->registered = SN_NDSL_RESOURCE_REGISTERED; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1390 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1391 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1392 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1393 | temp_resource = sn_grs_get_next_resource(); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1394 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1395 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1396 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1397 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1398 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1399 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1400 | /** |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1401 | * \fn static int8_t sn_nsdl_resolve_ep_information(sn_coap_hdr_s *coap_packet_ptr) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1402 | * |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1403 | * |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1404 | * \brief Resolves endpoint information from received CoAP message |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1405 | * |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1406 | * \param *coap_packet_ptr Pointer to received CoAP message |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1407 | * |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1408 | * \return SN_NSDL_SUCCESS = 0, Failed = -1 |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1409 | */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1410 | static int8_t sn_nsdl_resolve_ep_information(sn_coap_hdr_s *coap_packet_ptr) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1411 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1412 | uint8_t *temp_ptr; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1413 | uint8_t parameter_count = 0; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1414 | uint16_t parameter_len = 0; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1415 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1416 | if(!coap_packet_ptr) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1417 | return SN_NSDL_FAILURE; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1418 | if(!coap_packet_ptr->options_list_ptr) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1419 | return SN_NSDL_FAILURE; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1420 | if(!coap_packet_ptr->options_list_ptr->location_path_ptr) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1421 | return SN_NSDL_FAILURE; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1422 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1423 | temp_ptr = coap_packet_ptr->options_list_ptr->location_path_ptr; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1424 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1425 | while(temp_ptr <= (coap_packet_ptr->options_list_ptr->location_path_ptr + coap_packet_ptr->options_list_ptr->location_path_len)) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1426 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1427 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1428 | if((temp_ptr == (coap_packet_ptr->options_list_ptr->location_path_ptr + coap_packet_ptr->options_list_ptr->location_path_len)) || (*temp_ptr == '/')) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1429 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1430 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1431 | parameter_count++; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1432 | if(parameter_count == 2) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1433 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1434 | if(!ep_information_ptr->domain_name_ptr) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1435 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1436 | ep_information_ptr->domain_name_len = parameter_len - 1; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1437 | ep_information_ptr->domain_name_ptr = sn_nsdl_alloc(ep_information_ptr->domain_name_len); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1438 | if(!ep_information_ptr->domain_name_ptr) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1439 | return SN_NSDL_FAILURE; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1440 | memcpy(ep_information_ptr->domain_name_ptr, temp_ptr - ep_information_ptr->domain_name_len, ep_information_ptr->domain_name_len); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1441 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1442 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1443 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1444 | if(parameter_count == 3) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1445 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1446 | if(!ep_information_ptr->endpoint_name_ptr) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1447 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1448 | ep_information_ptr->endpoint_name_len = parameter_len - 1; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1449 | ep_information_ptr->endpoint_name_ptr = sn_nsdl_alloc(ep_information_ptr->endpoint_name_len); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1450 | if(!ep_information_ptr->endpoint_name_ptr) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1451 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1452 | if(ep_information_ptr->domain_name_ptr) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1453 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1454 | sn_nsdl_free(ep_information_ptr->domain_name_ptr); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1455 | ep_information_ptr->domain_name_ptr = NULL; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1456 | ep_information_ptr->domain_name_len = 0; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1457 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1458 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1459 | return SN_NSDL_FAILURE; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1460 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1461 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1462 | memcpy(ep_information_ptr->endpoint_name_ptr, temp_ptr - ep_information_ptr->endpoint_name_len, ep_information_ptr->endpoint_name_len); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1463 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1464 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1465 | parameter_len = 0; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1466 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1467 | parameter_len++; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1468 | temp_ptr++; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1469 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1470 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1471 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1472 | return SN_NSDL_SUCCESS; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1473 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1474 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1475 | /** |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1476 | * \fn int8_t set_NSP_address(uint8_t *NSP_address, uint16_t port, sn_nsdl_addr_type_e address_type) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1477 | * \brief This function is used to set the NSP address given by an application. |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1478 | * \param uint8_t *NSP_address Pointer to NSP address Note! IPv6 address must always be 16 bytes long and IPv4 address must always be 4 bytes long! |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1479 | * \param uint16_t port NSP port |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1480 | * \param sn_nsdl_addr_type_e address_type NSP address type (SN_NSDL_ADDRESS_TYPE_IPV6 or SN_NSDL_ADDRESS_TYPE_IPV4) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1481 | * \return 0 on success, -1 on false to indicate that NSDL internal address pointer is not allocated (call nsdl_init() first). |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1482 | * |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1483 | */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1484 | int8_t set_NSP_address(uint8_t *NSP_address, uint16_t port, sn_nsdl_addr_type_e address_type) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1485 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1486 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1487 | /* Check parameters and source pointers */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1488 | if(!nsp_address_ptr || !NSP_address) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1489 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1490 | return -1; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1491 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1492 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1493 | nsp_address_ptr->type = address_type; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1494 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1495 | if(address_type == SN_NSDL_ADDRESS_TYPE_IPV4) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1496 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1497 | if(nsp_address_ptr->addr_ptr) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1498 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1499 | sn_nsdl_free(nsp_address_ptr->addr_ptr); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1500 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1501 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1502 | nsp_address_ptr->addr_len = 4; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1503 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1504 | nsp_address_ptr->addr_ptr = sn_nsdl_alloc(nsp_address_ptr->addr_len); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1505 | if(!nsp_address_ptr->addr_ptr) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1506 | return -1; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1507 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1508 | memcpy(nsp_address_ptr->addr_ptr, NSP_address, nsp_address_ptr->addr_len); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1509 | nsp_address_ptr->port = port; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1510 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1511 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1512 | else if(address_type == SN_NSDL_ADDRESS_TYPE_IPV6) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1513 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1514 | if(nsp_address_ptr->addr_ptr) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1515 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1516 | sn_nsdl_free(nsp_address_ptr->addr_ptr); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1517 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1518 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1519 | nsp_address_ptr->addr_len = 16; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1520 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1521 | nsp_address_ptr->addr_ptr = sn_nsdl_alloc(nsp_address_ptr->addr_len); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1522 | if(!nsp_address_ptr->addr_ptr) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1523 | return -1; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1524 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1525 | memcpy(nsp_address_ptr->addr_ptr, NSP_address, nsp_address_ptr->addr_len); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1526 | nsp_address_ptr->port = port; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1527 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1528 | return 0; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1529 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1530 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1531 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1532 | static uint8_t sn_nsdl_itoa_len(uint8_t value) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1533 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1534 | uint8_t i = 0; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1535 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1536 | do |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1537 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1538 | i++; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1539 | }while((value /= 10) > 0); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1540 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1541 | return i; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1542 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1543 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1544 | static uint8_t *sn_nsdl_itoa(uint8_t *ptr, uint8_t value) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1545 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1546 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1547 | uint8_t start = 0; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1548 | uint8_t end = 0; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1549 | uint8_t i; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1550 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1551 | i = 0; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1552 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1553 | /* ITOA */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1554 | do |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1555 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1556 | ptr[i++] = (value % 10) + '0'; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1557 | }while((value /= 10) > 0); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1558 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1559 | end = i - 1; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1560 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1561 | /* reverse (part of ITOA) */ |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1562 | while(start < end) |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1563 | { |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1564 | uint8_t chr; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1565 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1566 | chr = ptr[start]; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1567 | ptr[start] = ptr[end]; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1568 | ptr[end] = chr; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1569 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1570 | start++; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1571 | end--; |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1572 | |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1573 | } |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1574 | return (ptr + i); |
GeofferyOmlette | 0:f6e4e1bbb3fe | 1575 | } |