1 // Copyright 2018 Espressif Systems (Shanghai) PTE LTD 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #pragma once 16 17 #include <sys/queue.h> 18 #include <protocomm_security.h> 19 #include <esp_err.h> 20 21 #define PROTOCOMM_NO_SESSION_ID UINT32_MAX 22 23 /* Bit Flags for indicating intended functionality of handler to either 24 * process request or establish secure session */ 25 #define REQ_EP (1 << 0) /*!< Flag indicating request handling endpoint */ 26 #define SEC_EP (1 << 1) /*!< Flag indicating security handling endpoint */ 27 #define VER_EP (1 << 2) /*!< Flag indicating version handling endpoint */ 28 29 /** 30 * @brief Protocomm endpoint table entry prototype 31 * 32 * The structure of an entry stored in the endpoint table. 33 */ 34 typedef struct protocomm_ep { 35 const char *ep_name; /*!< Unique endpoint name */ 36 protocomm_req_handler_t req_handler; /*!< Request handler function */ 37 38 /* Pointer to private data to be passed as a parameter to the handler 39 * function at the time of call. Set to NULL if not used. */ 40 void *priv_data; 41 42 uint32_t flag; /*!< Flag indicating endpoint functionality */ 43 44 /* Next endpoint entry in the singly linked list for storing endpoint handlers */ 45 SLIST_ENTRY(protocomm_ep) next; 46 } protocomm_ep_t; 47 48 /** 49 * @brief Prototype structure of a Protocomm instance 50 * 51 * This structure corresponds to a unique instance of protocomm returned, 52 * when the API protocomm_new() is called. The remaining Protocomm 53 * APIs require this object as the first parameter. 54 */ 55 struct protocomm { 56 /* Function Prototype of transport specific function, which is called 57 * internally when protocomm_add_endpoint() is invoked. */ 58 int (*add_endpoint)(const char *ep_name, protocomm_req_handler_t h, void *priv_data); 59 60 /* Function Prototype of transport specific function, which is called 61 * internally when protocomm_remove_endpoint() is invoked. */ 62 int (*remove_endpoint)(const char *ep_name); 63 64 /* Pointer to security layer to be used internally for 65 * establishing secure sessions */ 66 const protocomm_security_t *sec; 67 68 /* Handle to the security layer instance */ 69 protocomm_security_handle_t sec_inst; 70 71 /* Pointer to proof of possession object */ 72 protocomm_security_pop_t *pop; 73 74 /* Head of the singly linked list for storing endpoint handlers */ 75 SLIST_HEAD(eptable_t, protocomm_ep) endpoints; 76 77 /* Private data to be used internally by the protocomm instance */ 78 void* priv; 79 80 /* Application specific version string */ 81 const char* ver; 82 }; 83