mirror of
https://github.com/0xFEEDC0DE64/arduino-esp32.git
synced 2025-07-01 21:10:58 +02:00
Initial Esp32c3 Support (#5060)
This commit is contained in:
268
tools/sdk/esp32c3/include/protocomm/include/common/protocomm.h
Normal file
268
tools/sdk/esp32c3/include/protocomm/include/common/protocomm.h
Normal file
@ -0,0 +1,268 @@
|
||||
// Copyright 2018 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <protocomm_security.h>
|
||||
#include <esp_err.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Function prototype for protocomm endpoint handler
|
||||
*/
|
||||
typedef esp_err_t (*protocomm_req_handler_t)(
|
||||
uint32_t session_id, /*!< Session ID for identifying protocomm client */
|
||||
const uint8_t *inbuf, /*!< Pointer to user provided input data buffer */
|
||||
ssize_t inlen, /*!< Length o the input buffer */
|
||||
uint8_t **outbuf, /*!< Pointer to output buffer allocated by handler */
|
||||
ssize_t *outlen, /*!< Length of the allocated output buffer */
|
||||
void *priv_data /*!< Private data passed to the handler (NULL if not used) */
|
||||
);
|
||||
|
||||
/**
|
||||
* @brief This structure corresponds to a unique instance of protocomm
|
||||
* returned when the API `protocomm_new()` is called. The remaining
|
||||
* Protocomm APIs require this object as the first parameter.
|
||||
*
|
||||
* @note Structure of the protocomm object is kept private
|
||||
*/
|
||||
typedef struct protocomm protocomm_t;
|
||||
|
||||
/**
|
||||
* @brief Create a new protocomm instance
|
||||
*
|
||||
* This API will return a new dynamically allocated protocomm instance
|
||||
* with all elements of the protocomm_t structure initialized to NULL.
|
||||
*
|
||||
* @return
|
||||
* - protocomm_t* : On success
|
||||
* - NULL : No memory for allocating new instance
|
||||
*/
|
||||
protocomm_t *protocomm_new(void);
|
||||
|
||||
/**
|
||||
* @brief Delete a protocomm instance
|
||||
*
|
||||
* This API will deallocate a protocomm instance that was created
|
||||
* using `protocomm_new()`.
|
||||
*
|
||||
* @param[in] pc Pointer to the protocomm instance to be deleted
|
||||
*/
|
||||
void protocomm_delete(protocomm_t *pc);
|
||||
|
||||
/**
|
||||
* @brief Add endpoint request handler for a protocomm instance
|
||||
*
|
||||
* This API will bind an endpoint handler function to the specified
|
||||
* endpoint name, along with any private data that needs to be pass to
|
||||
* the handler at the time of call.
|
||||
*
|
||||
* @note
|
||||
* - An endpoint must be bound to a valid protocomm instance,
|
||||
* created using `protocomm_new()`.
|
||||
* - This function internally calls the registered `add_endpoint()`
|
||||
* function of the selected transport which is a member of the
|
||||
* protocomm_t instance structure.
|
||||
*
|
||||
* @param[in] pc Pointer to the protocomm instance
|
||||
* @param[in] ep_name Endpoint identifier(name) string
|
||||
* @param[in] h Endpoint handler function
|
||||
* @param[in] priv_data Pointer to private data to be passed as a
|
||||
* parameter to the handler function on call.
|
||||
* Pass NULL if not needed.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK : Success
|
||||
* - ESP_FAIL : Error adding endpoint / Endpoint with this name already exists
|
||||
* - ESP_ERR_NO_MEM : Error allocating endpoint resource
|
||||
* - ESP_ERR_INVALID_ARG : Null instance/name/handler arguments
|
||||
*/
|
||||
esp_err_t protocomm_add_endpoint(protocomm_t *pc, const char *ep_name,
|
||||
protocomm_req_handler_t h, void *priv_data);
|
||||
|
||||
/**
|
||||
* @brief Remove endpoint request handler for a protocomm instance
|
||||
*
|
||||
* This API will remove a registered endpoint handler identified by
|
||||
* an endpoint name.
|
||||
*
|
||||
* @note
|
||||
* - This function internally calls the registered `remove_endpoint()`
|
||||
* function which is a member of the protocomm_t instance structure.
|
||||
*
|
||||
* @param[in] pc Pointer to the protocomm instance
|
||||
* @param[in] ep_name Endpoint identifier(name) string
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK : Success
|
||||
* - ESP_ERR_NOT_FOUND : Endpoint with specified name doesn't exist
|
||||
* - ESP_ERR_INVALID_ARG : Null instance/name arguments
|
||||
*/
|
||||
esp_err_t protocomm_remove_endpoint(protocomm_t *pc, const char *ep_name);
|
||||
|
||||
/**
|
||||
* @brief Allocates internal resources for new transport session
|
||||
*
|
||||
* @note
|
||||
* - An endpoint must be bound to a valid protocomm instance,
|
||||
* created using `protocomm_new()`.
|
||||
*
|
||||
* @param[in] pc Pointer to the protocomm instance
|
||||
* @param[in] session_id Unique ID for a communication session
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK : Request handled successfully
|
||||
* - ESP_ERR_NO_MEM : Error allocating internal resource
|
||||
* - ESP_ERR_INVALID_ARG : Null instance/name arguments
|
||||
*/
|
||||
esp_err_t protocomm_open_session(protocomm_t *pc, uint32_t session_id);
|
||||
|
||||
/**
|
||||
* @brief Frees internal resources used by a transport session
|
||||
*
|
||||
* @note
|
||||
* - An endpoint must be bound to a valid protocomm instance,
|
||||
* created using `protocomm_new()`.
|
||||
*
|
||||
* @param[in] pc Pointer to the protocomm instance
|
||||
* @param[in] session_id Unique ID for a communication session
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK : Request handled successfully
|
||||
* - ESP_ERR_INVALID_ARG : Null instance/name arguments
|
||||
*/
|
||||
esp_err_t protocomm_close_session(protocomm_t *pc, uint32_t session_id);
|
||||
|
||||
/**
|
||||
* @brief Calls the registered handler of an endpoint session
|
||||
* for processing incoming data and generating the response
|
||||
*
|
||||
* @note
|
||||
* - An endpoint must be bound to a valid protocomm instance,
|
||||
* created using `protocomm_new()`.
|
||||
* - Resulting output buffer must be deallocated by the caller.
|
||||
*
|
||||
* @param[in] pc Pointer to the protocomm instance
|
||||
* @param[in] ep_name Endpoint identifier(name) string
|
||||
* @param[in] session_id Unique ID for a communication session
|
||||
* @param[in] inbuf Input buffer contains input request data which is to be
|
||||
* processed by the registered handler
|
||||
* @param[in] inlen Length of the input buffer
|
||||
* @param[out] outbuf Pointer to internally allocated output buffer,
|
||||
* where the resulting response data output from
|
||||
* the registered handler is to be stored
|
||||
* @param[out] outlen Buffer length of the allocated output buffer
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK : Request handled successfully
|
||||
* - ESP_FAIL : Internal error in execution of registered handler
|
||||
* - ESP_ERR_NO_MEM : Error allocating internal resource
|
||||
* - ESP_ERR_NOT_FOUND : Endpoint with specified name doesn't exist
|
||||
* - ESP_ERR_INVALID_ARG : Null instance/name arguments
|
||||
*/
|
||||
esp_err_t protocomm_req_handle(protocomm_t *pc, const char *ep_name, uint32_t session_id,
|
||||
const uint8_t *inbuf, ssize_t inlen,
|
||||
uint8_t **outbuf, ssize_t *outlen);
|
||||
|
||||
/**
|
||||
* @brief Add endpoint security for a protocomm instance
|
||||
*
|
||||
* This API will bind a security session establisher to the specified
|
||||
* endpoint name, along with any proof of possession that may be required
|
||||
* for authenticating a session client.
|
||||
*
|
||||
* @note
|
||||
* - An endpoint must be bound to a valid protocomm instance,
|
||||
* created using `protocomm_new()`.
|
||||
* - The choice of security can be any `protocomm_security_t` instance.
|
||||
* Choices `protocomm_security0` and `protocomm_security1` are readily available.
|
||||
*
|
||||
* @param[in] pc Pointer to the protocomm instance
|
||||
* @param[in] ep_name Endpoint identifier(name) string
|
||||
* @param[in] sec Pointer to endpoint security instance
|
||||
* @param[in] pop Pointer to proof of possession for authenticating a client
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK : Success
|
||||
* - ESP_FAIL : Error adding endpoint / Endpoint with this name already exists
|
||||
* - ESP_ERR_INVALID_STATE : Security endpoint already set
|
||||
* - ESP_ERR_NO_MEM : Error allocating endpoint resource
|
||||
* - ESP_ERR_INVALID_ARG : Null instance/name/handler arguments
|
||||
*/
|
||||
esp_err_t protocomm_set_security(protocomm_t *pc, const char *ep_name,
|
||||
const protocomm_security_t *sec,
|
||||
const protocomm_security_pop_t *pop);
|
||||
|
||||
/**
|
||||
* @brief Remove endpoint security for a protocomm instance
|
||||
*
|
||||
* This API will remove a registered security endpoint identified by
|
||||
* an endpoint name.
|
||||
*
|
||||
* @param[in] pc Pointer to the protocomm instance
|
||||
* @param[in] ep_name Endpoint identifier(name) string
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK : Success
|
||||
* - ESP_ERR_NOT_FOUND : Endpoint with specified name doesn't exist
|
||||
* - ESP_ERR_INVALID_ARG : Null instance/name arguments
|
||||
*/
|
||||
esp_err_t protocomm_unset_security(protocomm_t *pc, const char *ep_name);
|
||||
|
||||
/**
|
||||
* @brief Set endpoint for version verification
|
||||
*
|
||||
* This API can be used for setting an application specific protocol
|
||||
* version which can be verified by clients through the endpoint.
|
||||
*
|
||||
* @note
|
||||
* - An endpoint must be bound to a valid protocomm instance,
|
||||
* created using `protocomm_new()`.
|
||||
|
||||
* @param[in] pc Pointer to the protocomm instance
|
||||
* @param[in] ep_name Endpoint identifier(name) string
|
||||
* @param[in] version Version identifier(name) string
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK : Success
|
||||
* - ESP_FAIL : Error adding endpoint / Endpoint with this name already exists
|
||||
* - ESP_ERR_INVALID_STATE : Version endpoint already set
|
||||
* - ESP_ERR_NO_MEM : Error allocating endpoint resource
|
||||
* - ESP_ERR_INVALID_ARG : Null instance/name/handler arguments
|
||||
*/
|
||||
esp_err_t protocomm_set_version(protocomm_t *pc, const char *ep_name,
|
||||
const char *version);
|
||||
|
||||
/**
|
||||
* @brief Remove version verification endpoint from a protocomm instance
|
||||
*
|
||||
* This API will remove a registered version endpoint identified by
|
||||
* an endpoint name.
|
||||
*
|
||||
* @param[in] pc Pointer to the protocomm instance
|
||||
* @param[in] ep_name Endpoint identifier(name) string
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK : Success
|
||||
* - ESP_ERR_NOT_FOUND : Endpoint with specified name doesn't exist
|
||||
* - ESP_ERR_INVALID_ARG : Null instance/name arguments
|
||||
*/
|
||||
esp_err_t protocomm_unset_version(protocomm_t *pc, const char *ep_name);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@ -0,0 +1,108 @@
|
||||
// Copyright 2018 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <esp_err.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Proof Of Possession for authenticating a secure session
|
||||
*/
|
||||
typedef struct protocomm_security_pop {
|
||||
/**
|
||||
* Pointer to buffer containing the proof of possession data
|
||||
*/
|
||||
const uint8_t *data;
|
||||
|
||||
/**
|
||||
* Length (in bytes) of the proof of possession data
|
||||
*/
|
||||
uint16_t len;
|
||||
} protocomm_security_pop_t;
|
||||
|
||||
typedef void * protocomm_security_handle_t;
|
||||
|
||||
/**
|
||||
* @brief Protocomm security object structure.
|
||||
*
|
||||
* The member functions are used for implementing secure
|
||||
* protocomm sessions.
|
||||
*
|
||||
* @note This structure should not have any dynamic
|
||||
* members to allow re-entrancy
|
||||
*/
|
||||
typedef struct protocomm_security {
|
||||
/**
|
||||
* Unique version number of security implementation
|
||||
*/
|
||||
int ver;
|
||||
|
||||
/**
|
||||
* Function for initializing/allocating security
|
||||
* infrastructure
|
||||
*/
|
||||
esp_err_t (*init)(protocomm_security_handle_t *handle);
|
||||
|
||||
/**
|
||||
* Function for deallocating security infrastructure
|
||||
*/
|
||||
esp_err_t (*cleanup)(protocomm_security_handle_t handle);
|
||||
|
||||
/**
|
||||
* Starts new secure transport session with specified ID
|
||||
*/
|
||||
esp_err_t (*new_transport_session)(protocomm_security_handle_t handle,
|
||||
uint32_t session_id);
|
||||
|
||||
/**
|
||||
* Closes a secure transport session with specified ID
|
||||
*/
|
||||
esp_err_t (*close_transport_session)(protocomm_security_handle_t handle,
|
||||
uint32_t session_id);
|
||||
|
||||
/**
|
||||
* Handler function for authenticating connection
|
||||
* request and establishing secure session
|
||||
*/
|
||||
esp_err_t (*security_req_handler)(protocomm_security_handle_t handle,
|
||||
const protocomm_security_pop_t *pop,
|
||||
uint32_t session_id,
|
||||
const uint8_t *inbuf, ssize_t inlen,
|
||||
uint8_t **outbuf, ssize_t *outlen,
|
||||
void *priv_data);
|
||||
|
||||
/**
|
||||
* Function which implements the encryption algorithm
|
||||
*/
|
||||
esp_err_t (*encrypt)(protocomm_security_handle_t handle,
|
||||
uint32_t session_id,
|
||||
const uint8_t *inbuf, ssize_t inlen,
|
||||
uint8_t *outbuf, ssize_t *outlen);
|
||||
|
||||
/**
|
||||
* Function which implements the decryption algorithm
|
||||
*/
|
||||
esp_err_t (*decrypt)(protocomm_security_handle_t handle,
|
||||
uint32_t session_id,
|
||||
const uint8_t *inbuf, ssize_t inlen,
|
||||
uint8_t *outbuf, ssize_t *outlen);
|
||||
} protocomm_security_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@ -0,0 +1,33 @@
|
||||
// Copyright 2018 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <protocomm_security.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Protocomm security version 0 implementation
|
||||
*
|
||||
* This is a simple implementation to be used when no
|
||||
* security is required for the protocomm instance
|
||||
*/
|
||||
extern const protocomm_security_t protocomm_security0;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@ -0,0 +1,33 @@
|
||||
// Copyright 2018 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <protocomm_security.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Protocomm security version 1 implementation
|
||||
*
|
||||
* This is a full fledged security implementation using
|
||||
* Curve25519 key exchange and AES-256-CTR encryption
|
||||
*/
|
||||
extern const protocomm_security_t protocomm_security1;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@ -0,0 +1,110 @@
|
||||
// Copyright 2018 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <protocomm.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* BLE device name cannot be larger than this value
|
||||
* 31 bytes (max scan response size) - 1 byte (length) - 1 byte (type) = 29 bytes
|
||||
*/
|
||||
#define MAX_BLE_DEVNAME_LEN 29
|
||||
#define BLE_UUID128_VAL_LENGTH 16
|
||||
|
||||
/**
|
||||
* @brief This structure maps handler required by protocomm layer to
|
||||
* UUIDs which are used to uniquely identify BLE characteristics
|
||||
* from a smartphone or a similar client device.
|
||||
*/
|
||||
typedef struct name_uuid {
|
||||
/**
|
||||
* Name of the handler, which is passed to protocomm layer
|
||||
*/
|
||||
const char *name;
|
||||
|
||||
/**
|
||||
* UUID to be assigned to the BLE characteristic which is
|
||||
* mapped to the handler
|
||||
*/
|
||||
uint16_t uuid;
|
||||
} protocomm_ble_name_uuid_t;
|
||||
|
||||
/**
|
||||
* @brief Config parameters for protocomm BLE service
|
||||
*/
|
||||
typedef struct protocomm_ble_config {
|
||||
/**
|
||||
* BLE device name being broadcast at the time of provisioning
|
||||
*/
|
||||
char device_name[MAX_BLE_DEVNAME_LEN];
|
||||
|
||||
/**
|
||||
* 128 bit UUID of the provisioning service
|
||||
*/
|
||||
uint8_t service_uuid[BLE_UUID128_VAL_LENGTH];
|
||||
|
||||
/**
|
||||
* Number of entries in the Name-UUID lookup table
|
||||
*/
|
||||
ssize_t nu_lookup_count;
|
||||
|
||||
/**
|
||||
* Pointer to the Name-UUID lookup table
|
||||
*/
|
||||
protocomm_ble_name_uuid_t *nu_lookup;
|
||||
} protocomm_ble_config_t;
|
||||
|
||||
/**
|
||||
* @brief Start Bluetooth Low Energy based transport layer for provisioning
|
||||
*
|
||||
* Initialize and start required BLE service for provisioning. This includes
|
||||
* the initialization for characteristics/service for BLE.
|
||||
*
|
||||
* @param[in] pc Protocomm instance pointer obtained from protocomm_new()
|
||||
* @param[in] config Pointer to config structure for initializing BLE
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK : Success
|
||||
* - ESP_FAIL : Simple BLE start error
|
||||
* - ESP_ERR_NO_MEM : Error allocating memory for internal resources
|
||||
* - ESP_ERR_INVALID_STATE : Error in ble config
|
||||
* - ESP_ERR_INVALID_ARG : Null arguments
|
||||
*/
|
||||
esp_err_t protocomm_ble_start(protocomm_t *pc, const protocomm_ble_config_t *config);
|
||||
|
||||
/**
|
||||
* @brief Stop Bluetooth Low Energy based transport layer for provisioning
|
||||
*
|
||||
* Stops service/task responsible for BLE based interactions for provisioning
|
||||
*
|
||||
* @note You might want to optionally reclaim memory from Bluetooth.
|
||||
* Refer to the documentation of `esp_bt_mem_release` in that case.
|
||||
*
|
||||
* @param[in] pc Same protocomm instance that was passed to protocomm_ble_start()
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK : Success
|
||||
* - ESP_FAIL : Simple BLE stop error
|
||||
* - ESP_ERR_INVALID_ARG : Null / incorrect protocomm instance
|
||||
*/
|
||||
esp_err_t protocomm_ble_stop(protocomm_t *pc);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@ -0,0 +1,67 @@
|
||||
// Copyright 2018 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <protocomm.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define PROTOCOMM_CONSOLE_DEFAULT_CONFIG() { \
|
||||
.stack_size = 4096, \
|
||||
.task_priority = tskIDLE_PRIORITY + 3, \
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Config parameters for protocomm console
|
||||
*/
|
||||
typedef struct {
|
||||
size_t stack_size; /*!< Stack size of console task */
|
||||
unsigned task_priority; /*!< Priority of console task */
|
||||
} protocomm_console_config_t;
|
||||
|
||||
/**
|
||||
* @brief Start console based protocomm transport
|
||||
*
|
||||
* @note This is a singleton. ie. Protocomm can have multiple instances, but only
|
||||
* one instance can be bound to a console based transport layer.
|
||||
*
|
||||
* @param[in] pc Protocomm instance pointer obtained from protocomm_new()
|
||||
* @param[in] config Config param structure for protocomm console
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK : Success
|
||||
* - ESP_ERR_INVALID_ARG : Null arguments
|
||||
* - ESP_ERR_NOT_SUPPORTED : Transport layer bound to another protocomm instance
|
||||
* - ESP_ERR_INVALID_STATE : Transport layer already bound to this protocomm instance
|
||||
* - ESP_FAIL : Failed to start console thread
|
||||
*/
|
||||
esp_err_t protocomm_console_start(protocomm_t *pc, const protocomm_console_config_t *config);
|
||||
|
||||
/**
|
||||
* @brief Stop console protocomm transport
|
||||
*
|
||||
* @param[in] pc Same protocomm instance that was passed to protocomm_console_start()
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK : Success
|
||||
* - ESP_ERR_INVALID_ARG : Null / incorrect protocomm instance pointer
|
||||
*/
|
||||
esp_err_t protocomm_console_stop(protocomm_t *pc);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@ -0,0 +1,107 @@
|
||||
// Copyright 2018 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <protocomm.h>
|
||||
|
||||
#define PROTOCOMM_HTTPD_DEFAULT_CONFIG() { \
|
||||
.port = 80, \
|
||||
.stack_size = 4096, \
|
||||
.task_priority = tskIDLE_PRIORITY + 5, \
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Config parameters for protocomm HTTP server
|
||||
*/
|
||||
typedef struct {
|
||||
|
||||
uint16_t port; /*!< Port on which the HTTP server will listen */
|
||||
|
||||
/**
|
||||
* Stack size of server task, adjusted depending
|
||||
* upon stack usage of endpoint handler
|
||||
*/
|
||||
size_t stack_size;
|
||||
unsigned task_priority; /*!< Priority of server task */
|
||||
} protocomm_http_server_config_t; /*!< HTTP Server Configuration, if HTTP Server has not been started already */
|
||||
|
||||
/** Protocomm HTTPD Configuration Data
|
||||
*/
|
||||
typedef union {
|
||||
/** HTTP Server Handle, if ext_handle_provided is set to true
|
||||
*/
|
||||
void *handle;
|
||||
|
||||
/** HTTP Server Configuration, if a server is not already active
|
||||
*/
|
||||
protocomm_http_server_config_t config;
|
||||
} protocomm_httpd_config_data_t;
|
||||
|
||||
/**
|
||||
* @brief Config parameters for protocomm HTTP server
|
||||
*/
|
||||
typedef struct {
|
||||
/** Flag to indicate of an external HTTP Server Handle has been provided.
|
||||
* In such as case, protocomm will use the same HTTP Server and not start
|
||||
* a new one internally.
|
||||
*/
|
||||
bool ext_handle_provided;
|
||||
/** Protocomm HTTPD Configuration Data */
|
||||
protocomm_httpd_config_data_t data;
|
||||
} protocomm_httpd_config_t;
|
||||
|
||||
/**
|
||||
* @brief Start HTTPD protocomm transport
|
||||
*
|
||||
* This API internally creates a framework to allow endpoint registration and security
|
||||
* configuration for the protocomm.
|
||||
*
|
||||
* @note This is a singleton. ie. Protocomm can have multiple instances, but only
|
||||
* one instance can be bound to an HTTP transport layer.
|
||||
*
|
||||
* @param[in] pc Protocomm instance pointer obtained from protocomm_new()
|
||||
* @param[in] config Pointer to config structure for initializing HTTP server
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK : Success
|
||||
* - ESP_ERR_INVALID_ARG : Null arguments
|
||||
* - ESP_ERR_NOT_SUPPORTED : Transport layer bound to another protocomm instance
|
||||
* - ESP_ERR_INVALID_STATE : Transport layer already bound to this protocomm instance
|
||||
* - ESP_ERR_NO_MEM : Memory allocation for server resource failed
|
||||
* - ESP_ERR_HTTPD_* : HTTP server error on start
|
||||
*/
|
||||
esp_err_t protocomm_httpd_start(protocomm_t *pc, const protocomm_httpd_config_t *config);
|
||||
|
||||
/**
|
||||
* @brief Stop HTTPD protocomm transport
|
||||
*
|
||||
* This API cleans up the HTTPD transport protocomm and frees all the handlers registered
|
||||
* with the protocomm.
|
||||
*
|
||||
* @param[in] pc Same protocomm instance that was passed to protocomm_httpd_start()
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK : Success
|
||||
* - ESP_ERR_INVALID_ARG : Null / incorrect protocomm instance pointer
|
||||
*/
|
||||
esp_err_t protocomm_httpd_stop(protocomm_t *pc);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
Reference in New Issue
Block a user