NSDL C library

Dependents:   NSDL_HelloWorld_WiFi UbloxModemNanoServiceClient IOT-NSDL_HelloWorld LWM2M_NanoService_Ethernet ... more

Fork of nsdl_lib by Tero Heinonen

Note that use of this software requires acceptance of the Sensinode EULA: http://mbed.org/teams/Sensinode/code/nsdl_lib/wiki/EULA

Committer:
screamer
Date:
Wed Oct 09 14:18:21 2013 +0000
Revision:
1:01d723824294
Parent:
0:58c4f13c4b9a
Child:
2:ab50a2ab6ec9
Added doxygen markup

Who changed what in which revision?

UserRevisionLine numberNew contents of line
terohoo 0:58c4f13c4b9a 1 #ifdef __cplusplus
terohoo 0:58c4f13c4b9a 2 extern "C" {
terohoo 0:58c4f13c4b9a 3 #endif
terohoo 0:58c4f13c4b9a 4
terohoo 0:58c4f13c4b9a 5 #define SN_NSDL_CONST_MEMORY_ATTRIBUTE
terohoo 0:58c4f13c4b9a 6
terohoo 0:58c4f13c4b9a 7 #define RESOURCE_DIR_LEN 2
terohoo 0:58c4f13c4b9a 8 #define RESOURCE_DIR_PATH {'r','d'}
terohoo 0:58c4f13c4b9a 9
terohoo 0:58c4f13c4b9a 10 #define EP_NAME_PARAMETERS_LEN 2
terohoo 0:58c4f13c4b9a 11 #define EP_NAME_PARAMETERS {'h','='}
terohoo 0:58c4f13c4b9a 12
terohoo 0:58c4f13c4b9a 13 #define RT_PARAMETER_LEN 3
terohoo 0:58c4f13c4b9a 14 #define RT_PARAMETER {'r','t','='}
terohoo 0:58c4f13c4b9a 15
terohoo 0:58c4f13c4b9a 16 #define IF_PARAMETER_LEN 3
terohoo 0:58c4f13c4b9a 17 #define IF_PARAMETER {'i','f','='}
terohoo 0:58c4f13c4b9a 18
terohoo 0:58c4f13c4b9a 19 #define CON_PARAMETER_LEN 4
terohoo 0:58c4f13c4b9a 20 #define CON_PARAMETER {'c','o','n','='}
terohoo 0:58c4f13c4b9a 21
terohoo 0:58c4f13c4b9a 22 #define LT_PARAMETER_LEN 3
terohoo 0:58c4f13c4b9a 23 #define LT_PARAMETER {'l','t','='}
terohoo 0:58c4f13c4b9a 24
terohoo 0:58c4f13c4b9a 25 #define OBS_PARAMETER_LEN 3
terohoo 0:58c4f13c4b9a 26 #define OBS_PARAMETER {'o','b','s'}
terohoo 0:58c4f13c4b9a 27
terohoo 0:58c4f13c4b9a 28 #define COAP_CON_PARAMETER_LEN 3
terohoo 0:58c4f13c4b9a 29 #define COAP_CON_PARAMETER {'c','t','='}
terohoo 0:58c4f13c4b9a 30
terohoo 0:58c4f13c4b9a 31 #define EVENT_PATH_LEN 6
terohoo 0:58c4f13c4b9a 32 #define EVENT_PATH {'e','v','e','n','t','/'}
terohoo 0:58c4f13c4b9a 33
terohoo 0:58c4f13c4b9a 34 #define WELLKNOWN_PATH_LEN 16
terohoo 0:58c4f13c4b9a 35 #define WELLKNOWN_PATH (".well-known/core")
terohoo 0:58c4f13c4b9a 36
terohoo 0:58c4f13c4b9a 37 #define SN_NSDL_EP_REGISTER_MESSAGE 1
terohoo 0:58c4f13c4b9a 38 #define SN_NSDL_EP_UPDATE_MESSAGE 2
terohoo 0:58c4f13c4b9a 39
terohoo 0:58c4f13c4b9a 40 #define SN_NSDL_MSG_NO_TYPE 0
terohoo 0:58c4f13c4b9a 41 #define SN_NSDL_MSG_REGISTER 1
terohoo 0:58c4f13c4b9a 42 #define SN_NSDL_MSG_UNREGISTER 2
terohoo 0:58c4f13c4b9a 43 #define SN_NSDL_MSG_UPDATE 3
terohoo 0:58c4f13c4b9a 44 #define SN_NSDL_MSG_EVENT 4
terohoo 0:58c4f13c4b9a 45
terohoo 0:58c4f13c4b9a 46 #define SN_NSDL_MAX_MESSAGE_COUNT 1
terohoo 0:58c4f13c4b9a 47
terohoo 0:58c4f13c4b9a 48 #define SN_NSDL_ENDPOINT_NOT_REGISTERED 0
terohoo 0:58c4f13c4b9a 49 #define SN_NSDL_ENDPOINT_IS_REGISTERED 1
terohoo 0:58c4f13c4b9a 50
terohoo 0:58c4f13c4b9a 51 typedef struct sn_nsdl_ep_parameters_
terohoo 0:58c4f13c4b9a 52 {
terohoo 0:58c4f13c4b9a 53 uint8_t *endpoint_name_ptr;
terohoo 0:58c4f13c4b9a 54 uint8_t endpoint_name_len;
terohoo 0:58c4f13c4b9a 55
terohoo 0:58c4f13c4b9a 56 uint8_t *domain_name_ptr;
terohoo 0:58c4f13c4b9a 57 uint8_t domain_name_len;
terohoo 0:58c4f13c4b9a 58
terohoo 0:58c4f13c4b9a 59 uint8_t *type_ptr;
terohoo 0:58c4f13c4b9a 60 uint8_t type_len;
terohoo 0:58c4f13c4b9a 61
terohoo 0:58c4f13c4b9a 62 uint8_t *contex_ptr;
terohoo 0:58c4f13c4b9a 63 uint8_t contex_len;
terohoo 0:58c4f13c4b9a 64
terohoo 0:58c4f13c4b9a 65 uint8_t *lifetime_ptr;
terohoo 0:58c4f13c4b9a 66 uint8_t lifetime_len;
terohoo 0:58c4f13c4b9a 67
terohoo 0:58c4f13c4b9a 68 } sn_nsdl_ep_parameters_s;
terohoo 0:58c4f13c4b9a 69
terohoo 0:58c4f13c4b9a 70 typedef struct sn_nsdl_sent_messages_
terohoo 0:58c4f13c4b9a 71 {
terohoo 0:58c4f13c4b9a 72 uint16_t msg_id_number;
terohoo 0:58c4f13c4b9a 73 uint8_t message_type;
terohoo 0:58c4f13c4b9a 74 }sn_nsdl_sent_messages_s;
terohoo 0:58c4f13c4b9a 75
terohoo 0:58c4f13c4b9a 76 typedef struct sn_nsdl_mem_
terohoo 0:58c4f13c4b9a 77 {
terohoo 0:58c4f13c4b9a 78 void *(*sn_nsdl_alloc)(uint16_t);
terohoo 0:58c4f13c4b9a 79 void (*sn_nsdl_free)(void *);
terohoo 0:58c4f13c4b9a 80 }sn_nsdl_mem_s;
terohoo 0:58c4f13c4b9a 81
terohoo 0:58c4f13c4b9a 82 typedef struct sn_grs_resource_
terohoo 0:58c4f13c4b9a 83 {
terohoo 0:58c4f13c4b9a 84 uint8_t pathlen;
terohoo 0:58c4f13c4b9a 85 uint8_t *path;
terohoo 0:58c4f13c4b9a 86 }sn_grs_resource_s;
terohoo 0:58c4f13c4b9a 87
terohoo 0:58c4f13c4b9a 88 typedef struct sn_grs_resource_list_
terohoo 0:58c4f13c4b9a 89 {
terohoo 0:58c4f13c4b9a 90 uint8_t res_count; /* Number of resources */
terohoo 0:58c4f13c4b9a 91 sn_grs_resource_s *res;
terohoo 0:58c4f13c4b9a 92 }sn_grs_resource_list_s;
terohoo 0:58c4f13c4b9a 93
terohoo 0:58c4f13c4b9a 94 typedef enum sn_nsdl_resource_mode_
terohoo 0:58c4f13c4b9a 95 {
terohoo 0:58c4f13c4b9a 96 SN_GRS_STATIC,
terohoo 0:58c4f13c4b9a 97 SN_GRS_DYNAMIC,
terohoo 0:58c4f13c4b9a 98 SN_GRS_DIRECTORY
terohoo 0:58c4f13c4b9a 99 }sn_nsdl_resource_mode_e;
terohoo 0:58c4f13c4b9a 100
terohoo 0:58c4f13c4b9a 101 typedef enum sn_grs_resource_mutable_
terohoo 0:58c4f13c4b9a 102 {
terohoo 0:58c4f13c4b9a 103 SN_GRS_GET = 0x01,
terohoo 0:58c4f13c4b9a 104 SN_GRS_POST = 0x02,
terohoo 0:58c4f13c4b9a 105 SN_GRS_PUT = 0x04,
terohoo 0:58c4f13c4b9a 106 SN_GRS_DELETE = 0x08
terohoo 0:58c4f13c4b9a 107 }sn_grs_resource_mutable_e;
terohoo 0:58c4f13c4b9a 108
terohoo 0:58c4f13c4b9a 109 typedef enum sn_grs_resource_acl_
terohoo 0:58c4f13c4b9a 110 {
terohoo 0:58c4f13c4b9a 111 SN_GRS_GET_ALLOWED = 0x01 ,
terohoo 0:58c4f13c4b9a 112 SN_GRS_PUT_ALLOWED = 0x02,
terohoo 0:58c4f13c4b9a 113 SN_GRS_POST_ALLOWED = 0x04,
terohoo 0:58c4f13c4b9a 114 SN_GRS_DELETE_ALLOWED = 0x08
terohoo 0:58c4f13c4b9a 115 }sn_grs_resource_acl_e;
terohoo 0:58c4f13c4b9a 116
terohoo 0:58c4f13c4b9a 117 typedef struct sn_proto_info_
terohoo 0:58c4f13c4b9a 118 {
terohoo 0:58c4f13c4b9a 119 sn_nsdl_capab_e proto;
terohoo 0:58c4f13c4b9a 120 }sn_proto_info_s;
terohoo 0:58c4f13c4b9a 121
terohoo 0:58c4f13c4b9a 122 typedef struct sn_nsdl_resource_parameters_
terohoo 0:58c4f13c4b9a 123 {
terohoo 0:58c4f13c4b9a 124 uint8_t *resource_type_ptr;
terohoo 0:58c4f13c4b9a 125 uint16_t resource_type_len;
terohoo 0:58c4f13c4b9a 126
terohoo 0:58c4f13c4b9a 127 uint8_t *interface_description_ptr;
terohoo 0:58c4f13c4b9a 128 uint16_t interface_description_len;
terohoo 0:58c4f13c4b9a 129
terohoo 0:58c4f13c4b9a 130 uint8_t coap_content_type;
terohoo 0:58c4f13c4b9a 131
terohoo 0:58c4f13c4b9a 132 uint8_t mime_content_type;
terohoo 0:58c4f13c4b9a 133
terohoo 0:58c4f13c4b9a 134 uint8_t observable;
terohoo 0:58c4f13c4b9a 135
terohoo 0:58c4f13c4b9a 136 uint8_t registered;
terohoo 0:58c4f13c4b9a 137
terohoo 0:58c4f13c4b9a 138 }sn_nsdl_resource_parameters_s;
terohoo 0:58c4f13c4b9a 139
terohoo 0:58c4f13c4b9a 140 typedef struct sn_nsdl_resource_info_
terohoo 0:58c4f13c4b9a 141 {
terohoo 0:58c4f13c4b9a 142 sn_nsdl_resource_parameters_s *resource_parameters_ptr;
terohoo 0:58c4f13c4b9a 143
terohoo 0:58c4f13c4b9a 144 sn_nsdl_resource_mode_e mode; // STATIC etc..
terohoo 0:58c4f13c4b9a 145
terohoo 0:58c4f13c4b9a 146 uint16_t pathlen; // Address
terohoo 0:58c4f13c4b9a 147 uint8_t *path;
terohoo 0:58c4f13c4b9a 148
terohoo 0:58c4f13c4b9a 149 uint16_t resourcelen; // 0 if dynamic resource, resource information in static resource
terohoo 0:58c4f13c4b9a 150 uint8_t *resource; // NULL if dynamic resource
terohoo 0:58c4f13c4b9a 151
terohoo 0:58c4f13c4b9a 152 sn_grs_resource_acl_e access;
terohoo 0:58c4f13c4b9a 153
terohoo 0:58c4f13c4b9a 154 uint8_t (*sn_grs_dyn_res_callback)(sn_coap_hdr_s *, sn_nsdl_addr_s *, sn_proto_info_s *);
terohoo 0:58c4f13c4b9a 155
terohoo 0:58c4f13c4b9a 156 } sn_nsdl_resource_info_s;
terohoo 0:58c4f13c4b9a 157
terohoo 0:58c4f13c4b9a 158 /**
terohoo 0:58c4f13c4b9a 159 * \fn extern int8_t sn_nsdl_init (uint8_t (*sn_nsdl_tx_cb)(sn_nsdl_capab_e , uint8_t *, uint16_t, sn_nsdl_addr_s *),
terohoo 0:58c4f13c4b9a 160 * uint8_t (*sn_nsdl_rx_cb)(sn_coap_hdr_s *, sn_nsdl_addr_s *),
terohoo 0:58c4f13c4b9a 161 * sn_nsdl_mem_s *sn_memory)
terohoo 0:58c4f13c4b9a 162 *
terohoo 0:58c4f13c4b9a 163 *
terohoo 0:58c4f13c4b9a 164 * \brief Initialization function for NSDL library. Initializes NSDL, GRS, HTTP and CoAP.
terohoo 0:58c4f13c4b9a 165 *
terohoo 0:58c4f13c4b9a 166 * \param *sn_nsdl_tx_callback A callback function for sending messages.
terohoo 0:58c4f13c4b9a 167 *
terohoo 0:58c4f13c4b9a 168 * \param *sn_nsdl_rx_callback A callback function for parsed messages. If received message is not CoAP protocol message (eg. ACK), message for GRS (GET, PUT, POST, DELETE) or
terohoo 0:58c4f13c4b9a 169 * reply for some NSDL message (register message etc.), rx callback will be called.
terohoo 0:58c4f13c4b9a 170 *
terohoo 0:58c4f13c4b9a 171 * \param *sn_memory Memory structure which includes function pointers to the allocation and free functions.
terohoo 0:58c4f13c4b9a 172 *
terohoo 0:58c4f13c4b9a 173 * \return SN_NSDL_SUCCESS = 0, Failed = -1
terohoo 0:58c4f13c4b9a 174 */
terohoo 0:58c4f13c4b9a 175 int8_t sn_nsdl_init (uint8_t (*sn_nsdl_tx_cb)(sn_nsdl_capab_e , uint8_t *, uint16_t, sn_nsdl_addr_s *),
terohoo 0:58c4f13c4b9a 176 uint8_t (*sn_nsdl_rx_cb)(sn_coap_hdr_s *, sn_nsdl_addr_s *),
terohoo 0:58c4f13c4b9a 177 sn_nsdl_mem_s *sn_memory);
terohoo 0:58c4f13c4b9a 178
terohoo 0:58c4f13c4b9a 179 /**
terohoo 0:58c4f13c4b9a 180 * \fn extern uint8_t sn_nsdl_register_endpoint(sn_nsdl_ep_parameters_s *endpoint_info_ptr)
terohoo 0:58c4f13c4b9a 181 *
terohoo 0:58c4f13c4b9a 182 *
terohoo 0:58c4f13c4b9a 183 * \brief Registers endpoint to NSP server.
terohoo 0:58c4f13c4b9a 184 *
terohoo 0:58c4f13c4b9a 185 * \param *endpoint_info_ptr Contains endpoint information.
terohoo 0:58c4f13c4b9a 186 *
terohoo 0:58c4f13c4b9a 187 * \return SN_NSDL_SUCCESS = 0, Failed = -1
terohoo 0:58c4f13c4b9a 188 */
terohoo 0:58c4f13c4b9a 189 int8_t sn_nsdl_register_endpoint(sn_nsdl_ep_parameters_s *endpoint_info_ptr);
terohoo 0:58c4f13c4b9a 190
terohoo 0:58c4f13c4b9a 191 /**
terohoo 0:58c4f13c4b9a 192 * \fn extern int8_t sn_nsdl_unregister_endpoint(void)
terohoo 0:58c4f13c4b9a 193 *
terohoo 0:58c4f13c4b9a 194 *
terohoo 0:58c4f13c4b9a 195 * \brief Sends unregister-message to NSP server.
terohoo 0:58c4f13c4b9a 196 *
terohoo 0:58c4f13c4b9a 197 * \return SN_NSDL_SUCCESS = 0, Failed = -1
terohoo 0:58c4f13c4b9a 198 */
terohoo 0:58c4f13c4b9a 199 int8_t sn_nsdl_unregister_endpoint(void);
terohoo 0:58c4f13c4b9a 200 int8_t sn_nsdl_update_registration (sn_nsdl_ep_parameters_s *endpoint_parameters_ptr);
terohoo 0:58c4f13c4b9a 201 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);
terohoo 0:58c4f13c4b9a 202
terohoo 0:58c4f13c4b9a 203 /**
terohoo 0:58c4f13c4b9a 204 * \fn extern int8_t sn_nsdl_is_ep_registered(void)
terohoo 0:58c4f13c4b9a 205 *
terohoo 0:58c4f13c4b9a 206 *
terohoo 0:58c4f13c4b9a 207 * \brief Checks if endpoint is registered.
terohoo 0:58c4f13c4b9a 208 *
terohoo 0:58c4f13c4b9a 209 * \return 1 if endpointi registration is done SN_NSDL_SUCCESSfully, 0 if endpoint is not registered
terohoo 0:58c4f13c4b9a 210 */
terohoo 0:58c4f13c4b9a 211 int8_t sn_nsdl_is_ep_registered(void);
terohoo 0:58c4f13c4b9a 212
screamer 1:01d723824294 213 /**
terohoo 0:58c4f13c4b9a 214 * A function to inform NSDL-C library if application detects a fault in NSP registration. After calling this function
terohoo 0:58c4f13c4b9a 215 * , sn_nsdl_is_ep_registered() will return "not registered".
terohoo 0:58c4f13c4b9a 216 */
screamer 1:01d723824294 217
terohoo 0:58c4f13c4b9a 218 void sn_nsdl_nsp_lost(void);
terohoo 0:58c4f13c4b9a 219 /**
terohoo 0:58c4f13c4b9a 220 * \fn extern int8_t sn_nsdl_send_observation_notification(uint8_t *token_ptr, uint8_t token_len,
terohoo 0:58c4f13c4b9a 221 * uint8_t *payload_ptr, uint16_t payload_len,
terohoo 0:58c4f13c4b9a 222 * uint8_t *observe_ptr, uint8_t observe_len)
terohoo 0:58c4f13c4b9a 223 *
terohoo 0:58c4f13c4b9a 224 *
terohoo 0:58c4f13c4b9a 225 * \brief Sends observation message to NSP server
terohoo 0:58c4f13c4b9a 226 *
terohoo 0:58c4f13c4b9a 227 * \param *token_ptr Pointer to token to be used
terohoo 0:58c4f13c4b9a 228 * \param token_len Token length
terohoo 0:58c4f13c4b9a 229 * \param *payload_ptr Pointer to payload to be sent
terohoo 0:58c4f13c4b9a 230 * \param payload_len Payload length
terohoo 0:58c4f13c4b9a 231 * \param *observe_ptr Pointer to observe number to be sent
terohoo 0:58c4f13c4b9a 232 * \param observe_len Observe number len
terohoo 0:58c4f13c4b9a 233 *
terohoo 0:58c4f13c4b9a 234 * \return SN_NSDL_SUCCESS = 0, Failed = -1
terohoo 0:58c4f13c4b9a 235 */
terohoo 0:58c4f13c4b9a 236 extern uint16_t sn_nsdl_send_observation_notification(uint8_t *token_ptr, uint8_t token_len, uint8_t *payload_ptr, uint16_t payload_len, uint8_t *observe_ptr, uint8_t observe_len, sn_coap_msg_type_e message_type, uint8_t content_type);
terohoo 0:58c4f13c4b9a 237 int16_t sn_nsdl_get_capability(void);
terohoo 0:58c4f13c4b9a 238 uint32_t sn_nsdl_get_version(void);
terohoo 0:58c4f13c4b9a 239 int8_t sn_nsdl_process_http(uint8_t *packet, uint16_t *packet_len, sn_nsdl_addr_s *src);
terohoo 0:58c4f13c4b9a 240 int8_t sn_nsdl_process_coap(uint8_t *packet, uint16_t packet_len, sn_nsdl_addr_s *src);
terohoo 0:58c4f13c4b9a 241 int8_t sn_nsdl_exec(uint32_t time);
terohoo 0:58c4f13c4b9a 242 int8_t sn_nsdl_create_resource(sn_nsdl_resource_info_s *res);
terohoo 0:58c4f13c4b9a 243 int8_t sn_nsdl_update_resource(sn_nsdl_resource_info_s *res);
terohoo 0:58c4f13c4b9a 244 int8_t sn_nsdl_delete_resource(uint8_t pathlen, uint8_t *path);
terohoo 0:58c4f13c4b9a 245 sn_nsdl_resource_info_s *sn_nsdl_get_resource(uint8_t pathlen, uint8_t *path);
terohoo 0:58c4f13c4b9a 246 sn_grs_resource_list_s *sn_nsdl_list_resource(uint8_t pathlen, uint8_t *path);
terohoo 0:58c4f13c4b9a 247 int8_t sn_nsdl_send_coap_message(sn_nsdl_addr_s *address_ptr, sn_coap_hdr_s *coap_hdr_ptr);
terohoo 0:58c4f13c4b9a 248 /**
terohoo 0:58c4f13c4b9a 249 * \brief This function is used to set the NSP address given by an application.
terohoo 0:58c4f13c4b9a 250 * @return 0 on success, -1 on false to indicate that NSDL internal address pointer is not allocated (call nsdl_init() first).
terohoo 0:58c4f13c4b9a 251 */
terohoo 0:58c4f13c4b9a 252 int8_t set_NSP_address(uint8_t *NSP_address, uint16_t port, sn_nsdl_addr_type_e address_type);
terohoo 0:58c4f13c4b9a 253
terohoo 0:58c4f13c4b9a 254 /**
terohoo 0:58c4f13c4b9a 255 * \brief This function releases all allocated memory in nsdl and grs modules.
terohoo 0:58c4f13c4b9a 256 */
terohoo 0:58c4f13c4b9a 257 extern int8_t sn_nsdl_destroy(void);
terohoo 0:58c4f13c4b9a 258
terohoo 0:58c4f13c4b9a 259 /*
terohoo 0:58c4f13c4b9a 260 * \brief A function to request SN internal version information out of NSDL library in case of "error reporting" or similar.
terohoo 0:58c4f13c4b9a 261 * @return A string with \0 in the end. A human readable format. Please deliver this item to Sensinode in case if you're to report of errors.
terohoo 0:58c4f13c4b9a 262 */
terohoo 0:58c4f13c4b9a 263 //extern const char __code * sn_nsdl_get_library_version_info(void);
terohoo 0:58c4f13c4b9a 264
terohoo 0:58c4f13c4b9a 265 #ifdef __cplusplus
terohoo 0:58c4f13c4b9a 266 }
terohoo 0:58c4f13c4b9a 267 #endif