joey shelton / LED_Demo

Dependencies:   MAX44000 PWM_Tone_Library nexpaq_mdk

Fork of LED_Demo by Maxim nexpaq

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers coap_message_handler.h Source File

coap_message_handler.h

00001 /*
00002  * Copyright (c) 2015-2016 ARM Limited. All Rights Reserved.
00003  *
00004  * SPDX-License-Identifier: Apache-2.0
00005  *
00006  * Licensed under the Apache License, Version 2.0 (the "License"); you may
00007  * not use this file except in compliance with the License.
00008  * You may obtain a copy of the License at
00009  *
00010  * http://www.apache.org/licenses/LICENSE-2.0
00011  *
00012  * Unless required by applicable law or agreed to in writing, software
00013  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
00014  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00015  * See the License for the specific language governing permissions and
00016  * limitations under the License.
00017  */
00018 
00019 #ifndef __COAP_MESSAGE_HANDLER_H__
00020 #define __COAP_MESSAGE_HANDLER_H__
00021 
00022 #include <inttypes.h>
00023 #include "sn_coap_header.h"
00024 #include "sn_nsdl.h"
00025 #include "ns_list.h"
00026 
00027 /**
00028  * \brief Service message response receive callback.
00029  *
00030  * Function that handles CoAP service message receiving and parsing
00031  *
00032  * \param msg_id           Id number of the current message.
00033  * \param response_ptr     Pointer to CoAP header structure.
00034  *
00035  * \return 0 for success / -1 for failure
00036   */
00037 typedef int coap_message_handler_response_recv(int8_t service_id, uint8_t source_address[static 16], uint16_t source_port, sn_coap_hdr_s *response_ptr);
00038 
00039 typedef struct coap_msg_handler_s {
00040     void *(*sn_coap_service_malloc)(uint16_t);
00041     void (*sn_coap_service_free)(void *);
00042 
00043     uint8_t (*sn_coap_tx_callback)(uint8_t *, uint16_t, sn_nsdl_addr_s *, void *);
00044 
00045     struct coap_s *coap;
00046 } coap_msg_handler_t;
00047 
00048 typedef struct coap_transaction {
00049     uint8_t remote_address[16];
00050     uint16_t remote_port;
00051     uint8_t token[4];
00052     uint16_t msg_id;
00053     int8_t service_id;
00054     uint8_t options;
00055     bool client_request: 1;
00056     uint8_t *data_ptr;
00057     uint16_t data_len;
00058     coap_message_handler_response_recv *resp_cb;
00059     ns_list_link_t link;
00060 } coap_transaction_t;
00061 
00062 
00063 extern coap_msg_handler_t *coap_message_handler_init(void *(*used_malloc_func_ptr)(uint16_t), void (*used_free_func_ptr)(void *),
00064                                   uint8_t (*used_tx_callback_ptr)(uint8_t *, uint16_t, sn_nsdl_addr_s *, void *));
00065 
00066 extern int8_t coap_message_handler_destroy(coap_msg_handler_t *handle);
00067 
00068 extern coap_transaction_t *coap_message_handler_transaction_valid(coap_transaction_t *tr_ptr);
00069 
00070 extern coap_transaction_t *coap_message_handler_find_transaction(uint8_t *address_ptr, uint16_t port);
00071 
00072 extern int16_t coap_message_handler_coap_msg_process(coap_msg_handler_t *handle, int8_t socket_id, uint8_t source_addr_ptr[static 16], uint16_t port,
00073                                                          uint8_t *data_ptr, uint16_t data_len, int16_t (cb)(int8_t, sn_coap_hdr_s *, coap_transaction_t *));
00074 
00075 extern uint16_t coap_message_handler_request_send(coap_msg_handler_t *handle, int8_t service_id, uint8_t options, const uint8_t destination_addr[static 16],
00076                                                       uint16_t destination_port, sn_coap_msg_type_e msg_type, sn_coap_msg_code_e msg_code, const char *uri, sn_coap_content_format_e cont_type,
00077                                                       const uint8_t *payload_ptr, uint16_t payload_len, coap_message_handler_response_recv *request_response_cb);
00078 
00079 extern int8_t coap_message_handler_response_send(coap_msg_handler_t *handle, int8_t service_id, uint8_t options, sn_coap_hdr_s *request_ptr, sn_coap_msg_code_e message_code,
00080         sn_coap_content_format_e content_type, const uint8_t *payload_ptr, uint16_t payload_len);
00081 
00082 extern int8_t coap_message_handler_exec(coap_msg_handler_t *handle, uint32_t current_time);
00083 
00084 #endif