forked from espressif/esp-idf
protocomm: remove "Wno-format" cflag and fix formatting errors
This commit is contained in:
@@ -48,5 +48,3 @@ idf_component_register(SRCS "${srcs}"
|
|||||||
PRIV_INCLUDE_DIRS "${priv_include_dirs}"
|
PRIV_INCLUDE_DIRS "${priv_include_dirs}"
|
||||||
PRIV_REQUIRES protobuf-c mbedtls console esp_http_server driver
|
PRIV_REQUIRES protobuf-c mbedtls console esp_http_server driver
|
||||||
REQUIRES bt)
|
REQUIRES bt)
|
||||||
|
|
||||||
target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")
|
|
||||||
|
@@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <inttypes.h>
|
||||||
|
|
||||||
#include <esp_err.h>
|
#include <esp_err.h>
|
||||||
#include <esp_log.h>
|
#include <esp_log.h>
|
||||||
@@ -149,7 +150,7 @@ esp_err_t protocomm_open_session(protocomm_t *pc, uint32_t session_id)
|
|||||||
if (pc->sec && pc->sec->new_transport_session) {
|
if (pc->sec && pc->sec->new_transport_session) {
|
||||||
esp_err_t ret = pc->sec->new_transport_session(pc->sec_inst, session_id);
|
esp_err_t ret = pc->sec->new_transport_session(pc->sec_inst, session_id);
|
||||||
if (ret != ESP_OK) {
|
if (ret != ESP_OK) {
|
||||||
ESP_LOGE(TAG, "Failed to launch new session with ID: %d", session_id);
|
ESP_LOGE(TAG, "Failed to launch new session with ID: %" PRId32, session_id);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -165,7 +166,7 @@ esp_err_t protocomm_close_session(protocomm_t *pc, uint32_t session_id)
|
|||||||
if (pc->sec && pc->sec->close_transport_session) {
|
if (pc->sec && pc->sec->close_transport_session) {
|
||||||
esp_err_t ret = pc->sec->close_transport_session(pc->sec_inst, session_id);
|
esp_err_t ret = pc->sec->close_transport_session(pc->sec_inst, session_id);
|
||||||
if (ret != ESP_OK) {
|
if (ret != ESP_OK) {
|
||||||
ESP_LOGE(TAG, "Error while closing session with ID: %d", session_id);
|
ESP_LOGE(TAG, "Error while closing session with ID: %" PRId32, session_id);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -9,6 +9,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <esp_err.h>
|
#include <esp_err.h>
|
||||||
#include <esp_log.h>
|
#include <esp_log.h>
|
||||||
|
#include <inttypes.h>
|
||||||
|
|
||||||
/* TODO: Currently MBEDTLS_ECDH_LEGACY_CONTEXT is enabled by default
|
/* TODO: Currently MBEDTLS_ECDH_LEGACY_CONTEXT is enabled by default
|
||||||
* when MBEDTLS_ECP_RESTARTABLE is enabled.
|
* when MBEDTLS_ECP_RESTARTABLE is enabled.
|
||||||
@@ -459,7 +460,7 @@ static esp_err_t sec1_new_session(protocomm_security_handle_t handle, uint32_t s
|
|||||||
|
|
||||||
if (cur_session->id != -1) {
|
if (cur_session->id != -1) {
|
||||||
/* Only one session is allowed at a time */
|
/* Only one session is allowed at a time */
|
||||||
ESP_LOGE(TAG, "Closing old session with id %u", cur_session->id);
|
ESP_LOGE(TAG, "Closing old session with id %" PRIu32, cur_session->id);
|
||||||
sec1_close_session(cur_session, session_id);
|
sec1_close_session(cur_session, session_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -503,7 +504,7 @@ static esp_err_t sec1_decrypt(protocomm_security_handle_t handle,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!cur_session || cur_session->id != session_id) {
|
if (!cur_session || cur_session->id != session_id) {
|
||||||
ESP_LOGE(TAG, "Session with ID %d not found", session_id);
|
ESP_LOGE(TAG, "Session with ID %" PRId32 "not found", session_id);
|
||||||
return ESP_ERR_INVALID_STATE;
|
return ESP_ERR_INVALID_STATE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -542,7 +543,7 @@ static esp_err_t sec1_req_handler(protocomm_security_handle_t handle,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (session_id != cur_session->id) {
|
if (session_id != cur_session->id) {
|
||||||
ESP_LOGE(TAG, "Invalid session ID : %d (expected %d)", session_id, cur_session->id);
|
ESP_LOGE(TAG, "Invalid session ID:%" PRId32 "(expected %" PRId32 ")", session_id, cur_session->id);
|
||||||
return ESP_ERR_INVALID_STATE;
|
return ESP_ERR_INVALID_STATE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -10,6 +10,7 @@
|
|||||||
#include <esp_err.h>
|
#include <esp_err.h>
|
||||||
#include <esp_log.h>
|
#include <esp_log.h>
|
||||||
#include <esp_check.h>
|
#include <esp_check.h>
|
||||||
|
#include <inttypes.h>
|
||||||
|
|
||||||
#include <mbedtls/gcm.h>
|
#include <mbedtls/gcm.h>
|
||||||
#include <mbedtls/error.h>
|
#include <mbedtls/error.h>
|
||||||
@@ -367,7 +368,7 @@ static esp_err_t sec2_new_session(protocomm_security_handle_t handle, uint32_t s
|
|||||||
|
|
||||||
if (cur_session->id != -1) {
|
if (cur_session->id != -1) {
|
||||||
/* Only one session is allowed at a time */
|
/* Only one session is allowed at a time */
|
||||||
ESP_LOGE(TAG, "Closing old session with id %u", cur_session->id);
|
ESP_LOGE(TAG, "Closing old session with id %" PRIu32, cur_session->id);
|
||||||
sec2_close_session(cur_session, session_id);
|
sec2_close_session(cur_session, session_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -411,7 +412,7 @@ static esp_err_t sec2_encrypt(protocomm_security_handle_t handle,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!cur_session || cur_session->id != session_id) {
|
if (!cur_session || cur_session->id != session_id) {
|
||||||
ESP_LOGE(TAG, "Session with ID %d not found", session_id);
|
ESP_LOGE(TAG, "Session with ID %" PRId32 "not found", session_id);
|
||||||
return ESP_ERR_INVALID_STATE;
|
return ESP_ERR_INVALID_STATE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -451,7 +452,7 @@ static esp_err_t sec2_decrypt(protocomm_security_handle_t handle,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!cur_session || cur_session->id != session_id) {
|
if (!cur_session || cur_session->id != session_id) {
|
||||||
ESP_LOGE(TAG, "Session with ID %d not found", session_id);
|
ESP_LOGE(TAG, "Session with ID %" PRId32 "not found", session_id);
|
||||||
return ESP_ERR_INVALID_STATE;
|
return ESP_ERR_INVALID_STATE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -490,7 +491,7 @@ static esp_err_t sec2_req_handler(protocomm_security_handle_t handle,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (session_id != cur_session->id) {
|
if (session_id != cur_session->id) {
|
||||||
ESP_LOGE(TAG, "Invalid session ID : %d (expected %d)", session_id, cur_session->id);
|
ESP_LOGE(TAG, "Invalid session ID:%" PRId32 "(expected %" PRId32 ")", session_id, cur_session->id);
|
||||||
return ESP_ERR_INVALID_STATE;
|
return ESP_ERR_INVALID_STATE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -4,6 +4,7 @@
|
|||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <inttypes.h>
|
||||||
#include <freertos/FreeRTOS.h>
|
#include <freertos/FreeRTOS.h>
|
||||||
#include <esp_system.h>
|
#include <esp_system.h>
|
||||||
#include <esp_log.h>
|
#include <esp_log.h>
|
||||||
@@ -209,7 +210,7 @@ esp_err_t simple_ble_deinit(void)
|
|||||||
esp_err_t simple_ble_start(simple_ble_cfg_t *cfg)
|
esp_err_t simple_ble_start(simple_ble_cfg_t *cfg)
|
||||||
{
|
{
|
||||||
g_ble_cfg_p = cfg;
|
g_ble_cfg_p = cfg;
|
||||||
ESP_LOGD(TAG, "Free mem at start of simple_ble_init %d", esp_get_free_heap_size());
|
ESP_LOGD(TAG, "Free mem at start of simple_ble_init %" PRIu32, esp_get_free_heap_size());
|
||||||
esp_err_t ret;
|
esp_err_t ret;
|
||||||
|
|
||||||
esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
|
esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
|
||||||
@@ -267,7 +268,7 @@ esp_err_t simple_ble_start(simple_ble_cfg_t *cfg)
|
|||||||
if (local_mtu_ret) {
|
if (local_mtu_ret) {
|
||||||
ESP_LOGE(TAG, "set local MTU failed, error code = 0x%x", local_mtu_ret);
|
ESP_LOGE(TAG, "set local MTU failed, error code = 0x%x", local_mtu_ret);
|
||||||
}
|
}
|
||||||
ESP_LOGD(TAG, "Free mem at end of simple_ble_init %d", esp_get_free_heap_size());
|
ESP_LOGD(TAG, "Free mem at end of simple_ble_init %" PRIu32, esp_get_free_heap_size());
|
||||||
|
|
||||||
/* set the security iocap & auth_req & key size & init key response key parameters to the stack*/
|
/* set the security iocap & auth_req & key size & init key response key parameters to the stack*/
|
||||||
esp_ble_auth_req_t auth_req= ESP_LE_AUTH_REQ_MITM;
|
esp_ble_auth_req_t auth_req= ESP_LE_AUTH_REQ_MITM;
|
||||||
@@ -294,7 +295,7 @@ esp_err_t simple_ble_start(simple_ble_cfg_t *cfg)
|
|||||||
esp_err_t simple_ble_stop(void)
|
esp_err_t simple_ble_stop(void)
|
||||||
{
|
{
|
||||||
esp_err_t err;
|
esp_err_t err;
|
||||||
ESP_LOGD(TAG, "Free mem at start of simple_ble_stop %d", esp_get_free_heap_size());
|
ESP_LOGD(TAG, "Free mem at start of simple_ble_stop %" PRIu32, esp_get_free_heap_size());
|
||||||
err = esp_bluedroid_disable();
|
err = esp_bluedroid_disable();
|
||||||
if (err != ESP_OK) {
|
if (err != ESP_OK) {
|
||||||
return ESP_FAIL;
|
return ESP_FAIL;
|
||||||
@@ -320,7 +321,7 @@ esp_err_t simple_ble_stop(void)
|
|||||||
}
|
}
|
||||||
ESP_LOGD(TAG, "esp_bt_controller_deinit called successfully");
|
ESP_LOGD(TAG, "esp_bt_controller_deinit called successfully");
|
||||||
|
|
||||||
ESP_LOGD(TAG, "Free mem at end of simple_ble_stop %d", esp_get_free_heap_size());
|
ESP_LOGD(TAG, "Free mem at end of simple_ble_stop %" PRIu32, esp_get_free_heap_size());
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -8,6 +8,7 @@
|
|||||||
#include <freertos/task.h>
|
#include <freertos/task.h>
|
||||||
#include <esp_log.h>
|
#include <esp_log.h>
|
||||||
#include <esp_err.h>
|
#include <esp_err.h>
|
||||||
|
#include <inttypes.h>
|
||||||
#include "esp_random.h"
|
#include "esp_random.h"
|
||||||
|
|
||||||
#include <esp_http_server.h>
|
#include <esp_http_server.h>
|
||||||
@@ -34,7 +35,7 @@ static void protocomm_httpd_session_close(void *ctx)
|
|||||||
* request is for the same session.
|
* request is for the same session.
|
||||||
*/
|
*/
|
||||||
if (sock_session_id != PROTOCOMM_NO_SESSION_ID) {
|
if (sock_session_id != PROTOCOMM_NO_SESSION_ID) {
|
||||||
ESP_LOGW(TAG, "Resetting socket session id as socket %d was closed", sock_session_id);
|
ESP_LOGW(TAG, "Resetting socket session id as socket %" PRId32 "was closed", sock_session_id);
|
||||||
sock_session_id = PROTOCOMM_NO_SESSION_ID;
|
sock_session_id = PROTOCOMM_NO_SESSION_ID;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -56,12 +57,12 @@ static esp_err_t common_post_handler(httpd_req_t *req)
|
|||||||
if (httpd_req_get_hdr_value_str(req, "Cookie", cookie_buf, sizeof(cookie_buf)) == ESP_OK) {
|
if (httpd_req_get_hdr_value_str(req, "Cookie", cookie_buf, sizeof(cookie_buf)) == ESP_OK) {
|
||||||
ESP_LOGD(TAG, "Received cookie %s", cookie_buf);
|
ESP_LOGD(TAG, "Received cookie %s", cookie_buf);
|
||||||
char session_cookie[20] = {0};
|
char session_cookie[20] = {0};
|
||||||
snprintf(session_cookie, sizeof(session_cookie), "session=%u", cookie_session_id);
|
snprintf(session_cookie, sizeof(session_cookie), "session=%" PRIu32, cookie_session_id);
|
||||||
/* If a cookie is found, check it against the session id. If it matches,
|
/* If a cookie is found, check it against the session id. If it matches,
|
||||||
* it means that this is a continuation of the same session.
|
* it means that this is a continuation of the same session.
|
||||||
*/
|
*/
|
||||||
if (strcmp(session_cookie, cookie_buf) == 0) {
|
if (strcmp(session_cookie, cookie_buf) == 0) {
|
||||||
ESP_LOGD(TAG, "Continuing Session %u", cookie_session_id);
|
ESP_LOGD(TAG, "Continuing Session %" PRIu32, cookie_session_id);
|
||||||
/* If we reach here, it means that the client supports cookies and so the
|
/* If we reach here, it means that the client supports cookies and so the
|
||||||
* socket session id would no more be required for checking.
|
* socket session id would no more be required for checking.
|
||||||
*/
|
*/
|
||||||
@@ -70,7 +71,7 @@ static esp_err_t common_post_handler(httpd_req_t *req)
|
|||||||
}
|
}
|
||||||
} else if (cur_sock_session_id == sock_session_id) {
|
} else if (cur_sock_session_id == sock_session_id) {
|
||||||
/* If the socket number matches, we assume it to be the same session */
|
/* If the socket number matches, we assume it to be the same session */
|
||||||
ESP_LOGD(TAG, "Continuing Socket Session %u", sock_session_id);
|
ESP_LOGD(TAG, "Continuing Socket Session %" PRIu32, sock_session_id);
|
||||||
same_session = true;
|
same_session = true;
|
||||||
}
|
}
|
||||||
if (!same_session) {
|
if (!same_session) {
|
||||||
@@ -78,11 +79,11 @@ static esp_err_t common_post_handler(httpd_req_t *req)
|
|||||||
* first close any existing sessions as applicable.
|
* first close any existing sessions as applicable.
|
||||||
*/
|
*/
|
||||||
if (cookie_session_id != PROTOCOMM_NO_SESSION_ID) {
|
if (cookie_session_id != PROTOCOMM_NO_SESSION_ID) {
|
||||||
ESP_LOGW(TAG, "Closing session with ID: %u", cookie_session_id);
|
ESP_LOGW(TAG, "Closing session with ID: %" PRIu32, cookie_session_id);
|
||||||
if (pc_httpd->sec && pc_httpd->sec->close_transport_session) {
|
if (pc_httpd->sec && pc_httpd->sec->close_transport_session) {
|
||||||
ret = pc_httpd->sec->close_transport_session(pc_httpd->sec_inst, cookie_session_id);
|
ret = pc_httpd->sec->close_transport_session(pc_httpd->sec_inst, cookie_session_id);
|
||||||
if (ret != ESP_OK) {
|
if (ret != ESP_OK) {
|
||||||
ESP_LOGW(TAG, "Error closing session with ID: %u", cookie_session_id);
|
ESP_LOGW(TAG, "Error closing session with ID: %" PRIu32, cookie_session_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cookie_session_id = PROTOCOMM_NO_SESSION_ID;
|
cookie_session_id = PROTOCOMM_NO_SESSION_ID;
|
||||||
@@ -104,7 +105,7 @@ static esp_err_t common_post_handler(httpd_req_t *req)
|
|||||||
}
|
}
|
||||||
cookie_session_id = cur_cookie_session_id;
|
cookie_session_id = cur_cookie_session_id;
|
||||||
sock_session_id = cur_sock_session_id;
|
sock_session_id = cur_sock_session_id;
|
||||||
ESP_LOGD(TAG, "New socket session ID: %d", sock_session_id);
|
ESP_LOGD(TAG, "New socket session ID: %" PRId32, sock_session_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (req->content_len <= 0) {
|
if (req->content_len <= 0) {
|
||||||
@@ -147,7 +148,7 @@ static esp_err_t common_post_handler(httpd_req_t *req)
|
|||||||
}
|
}
|
||||||
/* If this is a new session, send the session id in a cookie */
|
/* If this is a new session, send the session id in a cookie */
|
||||||
if (!same_session) {
|
if (!same_session) {
|
||||||
snprintf(cookie_buf, sizeof(cookie_buf), "session=%u", cookie_session_id);
|
snprintf(cookie_buf, sizeof(cookie_buf), "session=%" PRIu32, cookie_session_id);
|
||||||
ESP_LOGD(TAG, "Setting cookie %s", cookie_buf);
|
ESP_LOGD(TAG, "Setting cookie %s", cookie_buf);
|
||||||
httpd_resp_set_hdr(req, "Set-Cookie", cookie_buf);
|
httpd_resp_set_hdr(req, "Set-Cookie", cookie_buf);
|
||||||
}
|
}
|
||||||
|
@@ -7,6 +7,7 @@
|
|||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
#include <esp_log.h>
|
#include <esp_log.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <inttypes.h>
|
||||||
|
|
||||||
#include <protocomm.h>
|
#include <protocomm.h>
|
||||||
#include <protocomm_ble.h>
|
#include <protocomm_ble.h>
|
||||||
@@ -208,7 +209,7 @@ simple_ble_advertise(void)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
/* Take note of free heap space */
|
/* Take note of free heap space */
|
||||||
ESP_LOGD(TAG, "Minimum free heap size = %d, free Heap size = %d",
|
ESP_LOGD(TAG, "Minimum free heap size = %" PRIu32 ", free Heap size = %" PRIu32,
|
||||||
esp_get_minimum_free_heap_size(), esp_get_free_heap_size());
|
esp_get_minimum_free_heap_size(), esp_get_free_heap_size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -488,7 +489,7 @@ static int simple_ble_start(const simple_ble_cfg_t *cfg)
|
|||||||
{
|
{
|
||||||
ble_cfg_p = (void *)cfg;
|
ble_cfg_p = (void *)cfg;
|
||||||
int rc;
|
int rc;
|
||||||
ESP_LOGD(TAG, "Free memory at start of simple_ble_init %d", esp_get_free_heap_size());
|
ESP_LOGD(TAG, "Free memory at start of simple_ble_init %" PRIu32, esp_get_free_heap_size());
|
||||||
|
|
||||||
nimble_port_init();
|
nimble_port_init();
|
||||||
|
|
||||||
@@ -948,7 +949,7 @@ esp_err_t protocomm_ble_start(protocomm_t *pc, const protocomm_ble_config_t *con
|
|||||||
}
|
}
|
||||||
|
|
||||||
esp_err_t err = simple_ble_start(ble_config);
|
esp_err_t err = simple_ble_start(ble_config);
|
||||||
ESP_LOGD(TAG, "Free Heap size after simple_ble_start= %d", esp_get_free_heap_size());
|
ESP_LOGD(TAG, "Free Heap size after simple_ble_start= %" PRIu32, esp_get_free_heap_size());
|
||||||
|
|
||||||
if (err != ESP_OK) {
|
if (err != ESP_OK) {
|
||||||
ESP_LOGE(TAG, "simple_ble_start failed w/ error code 0x%x", err);
|
ESP_LOGE(TAG, "simple_ble_start failed w/ error code 0x%x", err);
|
||||||
|
Reference in New Issue
Block a user