Skip to content

Commit c271284

Browse files
committed
Merge branch 'feature/unified_provisioning' into 'master'
Feature/unified provisioning See merge request sdk/ESP8266_RTOS_SDK!789
2 parents ae40917 + e7cf607 commit c271284

File tree

99 files changed

+11911
-3
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+11911
-3
lines changed

components/log/include/esp_log_internal.h

+7-3
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,13 @@
1616
#define __ESP_LOG_INTERNAL_H__
1717

1818
//these functions do not check level versus ESP_LOCAL_LEVEL, this should be done in esp_log.h
19-
void esp_log_buffer_hex_internal(const char *tag, const void *buffer, uint16_t buff_len, esp_log_level_t level);
20-
void esp_log_buffer_char_internal(const char *tag, const void *buffer, uint16_t buff_len, esp_log_level_t level);
21-
void esp_log_buffer_hexdump_internal( const char *tag, const void *buffer, uint16_t buff_len, esp_log_level_t log_level);
19+
#define esp_log_buffer_hex_internal(...)
20+
#define esp_log_buffer_char_internal(...)
21+
#define esp_log_buffer_hexdump_internal(...)
22+
/* TODO: Add the implementation of the below API's */
23+
// void esp_log_buffer_hex_internal(const char *tag, const void *buffer, uint16_t buff_len, esp_log_level_t level);
24+
// void esp_log_buffer_char_internal(const char *tag, const void *buffer, uint16_t buff_len, esp_log_level_t level);
25+
// void esp_log_buffer_hexdump_internal( const char *tag, const void *buffer, uint16_t buff_len, esp_log_level_t log_level);
2226

2327
#endif
2428

components/protocomm/CMakeLists.txt

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
set(COMPONENT_ADD_INCLUDEDIRS include/common
2+
include/security
3+
include/transports)
4+
set(COMPONENT_PRIV_INCLUDEDIRS proto-c src/common)
5+
set(COMPONENT_SRCS "src/common/protocomm.c"
6+
"src/security/security0.c"
7+
"src/security/security1.c"
8+
"proto-c/constants.pb-c.c"
9+
"proto-c/sec0.pb-c.c"
10+
"proto-c/sec1.pb-c.c"
11+
"proto-c/session.pb-c.c"
12+
"src/transports/protocomm_httpd.c")
13+
14+
set(COMPONENT_PRIV_REQUIRES protobuf-c mbedtls wifi_provisioning)
15+
16+
register_component()

components/protocomm/component.mk

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
COMPONENT_ADD_INCLUDEDIRS :=
2+
COMPONENT_SRCDIRS :=
3+
4+
ifdef CONFIG_ENABLE_UNIFIED_PROVISIONING
5+
COMPONENT_ADD_INCLUDEDIRS := include/common include/security include/transports
6+
COMPONENT_PRIV_INCLUDEDIRS := proto-c src/common
7+
COMPONENT_SRCDIRS := src/common src/security proto-c src/transports
8+
endif
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,235 @@
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 <protocomm_security.h>
18+
#include <esp_err.h>
19+
20+
#ifdef __cplusplus
21+
extern "C" {
22+
#endif
23+
24+
/**
25+
* @brief Function prototype for protocomm endpoint handler
26+
*/
27+
typedef esp_err_t (*protocomm_req_handler_t)(
28+
uint32_t session_id, /*!< Session ID for identifying protocomm client */
29+
const uint8_t *inbuf, /*!< Pointer to user provided input data buffer */
30+
ssize_t inlen, /*!< Length o the input buffer */
31+
uint8_t **outbuf, /*!< Pointer to output buffer allocated by handler */
32+
ssize_t *outlen, /*!< Length of the allocated output buffer */
33+
void *priv_data /*!< Private data passed to the handler (NULL if not used) */
34+
);
35+
36+
/**
37+
* @brief This structure corresponds to a unique instance of protocomm
38+
* returned when the API `protocomm_new()` is called. The remaining
39+
* Protocomm APIs require this object as the first parameter.
40+
*
41+
* @note Structure of the protocomm object is kept private
42+
*/
43+
typedef struct protocomm protocomm_t;
44+
45+
/**
46+
* @brief Create a new protocomm instance
47+
*
48+
* This API will return a new dynamically allocated protocomm instance
49+
* with all elements of the protocomm_t structure initialized to NULL.
50+
*
51+
* @return
52+
* - protocomm_t* : On success
53+
* - NULL : No memory for allocating new instance
54+
*/
55+
protocomm_t *protocomm_new();
56+
57+
/**
58+
* @brief Delete a protocomm instance
59+
*
60+
* This API will deallocate a protocomm instance that was created
61+
* using `protocomm_new()`.
62+
*
63+
* @param[in] pc Pointer to the protocomm instance to be deleted
64+
*/
65+
void protocomm_delete(protocomm_t *pc);
66+
67+
/**
68+
* @brief Add endpoint request handler for a protocomm instance
69+
*
70+
* This API will bind an endpoint handler function to the specified
71+
* endpoint name, along with any private data that needs to be pass to
72+
* the handler at the time of call.
73+
*
74+
* @note
75+
* - An endpoint must be bound to a valid protocomm instance,
76+
* created using `protocomm_new()`.
77+
* - This function internally calls the registered `add_endpoint()`
78+
* function of the selected transport which is a member of the
79+
* protocomm_t instance structure.
80+
*
81+
* @param[in] pc Pointer to the protocomm instance
82+
* @param[in] ep_name Endpoint identifier(name) string
83+
* @param[in] h Endpoint handler function
84+
* @param[in] priv_data Pointer to private data to be passed as a
85+
* parameter to the handler function on call.
86+
* Pass NULL if not needed.
87+
*
88+
* @return
89+
* - ESP_OK : Success
90+
* - ESP_FAIL : Error adding endpoint / Endpoint with this name already exists
91+
* - ESP_ERR_NO_MEM : Error allocating endpoint resource
92+
* - ESP_ERR_INVALID_ARG : Null instance/name/handler arguments
93+
*/
94+
esp_err_t protocomm_add_endpoint(protocomm_t *pc, const char *ep_name,
95+
protocomm_req_handler_t h, void *priv_data);
96+
97+
/**
98+
* @brief Remove endpoint request handler for a protocomm instance
99+
*
100+
* This API will remove a registered endpoint handler identified by
101+
* an endpoint name.
102+
*
103+
* @note
104+
* - This function internally calls the registered `remove_endpoint()`
105+
* function which is a member of the protocomm_t instance structure.
106+
*
107+
* @param[in] pc Pointer to the protocomm instance
108+
* @param[in] ep_name Endpoint identifier(name) string
109+
*
110+
* @return
111+
* - ESP_OK : Success
112+
* - ESP_ERR_NOT_FOUND : Endpoint with specified name doesn't exist
113+
* - ESP_ERR_INVALID_ARG : Null instance/name arguments
114+
*/
115+
esp_err_t protocomm_remove_endpoint(protocomm_t *pc, const char *ep_name);
116+
117+
/**
118+
* @brief Calls the registered handler of an endpoint session
119+
* for processing incoming data and generating the response
120+
*
121+
* @note
122+
* - An endpoint must be bound to a valid protocomm instance,
123+
* created using `protocomm_new()`.
124+
* - Resulting output buffer must be deallocated by the caller.
125+
*
126+
* @param[in] pc Pointer to the protocomm instance
127+
* @param[in] ep_name Endpoint identifier(name) string
128+
* @param[in] session_id Unique ID for a communication session
129+
* @param[in] inbuf Input buffer contains input request data which is to be
130+
* processed by the registered handler
131+
* @param[in] inlen Length of the input buffer
132+
* @param[out] outbuf Pointer to internally allocated output buffer,
133+
* where the resulting response data output from
134+
* the registered handler is to be stored
135+
* @param[out] outlen Buffer length of the allocated output buffer
136+
*
137+
* @return
138+
* - ESP_OK : Request handled successfully
139+
* - ESP_FAIL : Internal error in execution of registered handler
140+
* - ESP_ERR_NO_MEM : Error allocating internal resource
141+
* - ESP_ERR_NOT_FOUND : Endpoint with specified name doesn't exist
142+
* - ESP_ERR_INVALID_ARG : Null instance/name arguments
143+
*/
144+
esp_err_t protocomm_req_handle(protocomm_t *pc, const char *ep_name, uint32_t session_id,
145+
const uint8_t *inbuf, ssize_t inlen,
146+
uint8_t **outbuf, ssize_t *outlen);
147+
148+
/**
149+
* @brief Add endpoint security for a protocomm instance
150+
*
151+
* This API will bind a security session establisher to the specified
152+
* endpoint name, along with any proof of possession that may be required
153+
* for authenticating a session client.
154+
*
155+
* @note
156+
* - An endpoint must be bound to a valid protocomm instance,
157+
* created using `protocomm_new()`.
158+
* - The choice of security can be any `protocomm_security_t` instance.
159+
* Choices `protocomm_security0` and `protocomm_security1` are readily available.
160+
*
161+
* @param[in] pc Pointer to the protocomm instance
162+
* @param[in] ep_name Endpoint identifier(name) string
163+
* @param[in] sec Pointer to endpoint security instance
164+
* @param[in] pop Pointer to proof of possession for authenticating a client
165+
*
166+
* @return
167+
* - ESP_OK : Success
168+
* - ESP_FAIL : Error adding endpoint / Endpoint with this name already exists
169+
* - ESP_ERR_INVALID_STATE : Security endpoint already set
170+
* - ESP_ERR_NO_MEM : Error allocating endpoint resource
171+
* - ESP_ERR_INVALID_ARG : Null instance/name/handler arguments
172+
*/
173+
esp_err_t protocomm_set_security(protocomm_t *pc, const char *ep_name,
174+
const protocomm_security_t *sec,
175+
const protocomm_security_pop_t *pop);
176+
177+
/**
178+
* @brief Remove endpoint security for a protocomm instance
179+
*
180+
* This API will remove a registered security endpoint identified by
181+
* an endpoint name.
182+
*
183+
* @param[in] pc Pointer to the protocomm instance
184+
* @param[in] ep_name Endpoint identifier(name) string
185+
*
186+
* @return
187+
* - ESP_OK : Success
188+
* - ESP_ERR_NOT_FOUND : Endpoint with specified name doesn't exist
189+
* - ESP_ERR_INVALID_ARG : Null instance/name arguments
190+
*/
191+
esp_err_t protocomm_unset_security(protocomm_t *pc, const char *ep_name);
192+
193+
/**
194+
* @brief Set endpoint for version verification
195+
*
196+
* This API can be used for setting an application specific protocol
197+
* version which can be verified by clients through the endpoint.
198+
*
199+
* @note
200+
* - An endpoint must be bound to a valid protocomm instance,
201+
* created using `protocomm_new()`.
202+
203+
* @param[in] pc Pointer to the protocomm instance
204+
* @param[in] ep_name Endpoint identifier(name) string
205+
* @param[in] version Version identifier(name) string
206+
*
207+
* @return
208+
* - ESP_OK : Success
209+
* - ESP_FAIL : Error adding endpoint / Endpoint with this name already exists
210+
* - ESP_ERR_INVALID_STATE : Version endpoint already set
211+
* - ESP_ERR_NO_MEM : Error allocating endpoint resource
212+
* - ESP_ERR_INVALID_ARG : Null instance/name/handler arguments
213+
*/
214+
esp_err_t protocomm_set_version(protocomm_t *pc, const char *ep_name,
215+
const char *version);
216+
217+
/**
218+
* @brief Remove version verification endpoint from a protocomm instance
219+
*
220+
* This API will remove a registered version endpoint identified by
221+
* an endpoint name.
222+
*
223+
* @param[in] pc Pointer to the protocomm instance
224+
* @param[in] ep_name Endpoint identifier(name) string
225+
*
226+
* @return
227+
* - ESP_OK : Success
228+
* - ESP_ERR_NOT_FOUND : Endpoint with specified name doesn't exist
229+
* - ESP_ERR_INVALID_ARG : Null instance/name arguments
230+
*/
231+
esp_err_t protocomm_unset_version(protocomm_t *pc, const char *ep_name);
232+
233+
#ifdef __cplusplus
234+
}
235+
#endif
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
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 <esp_err.h>
18+
19+
#ifdef __cplusplus
20+
extern "C" {
21+
#endif
22+
23+
/**
24+
* @brief Proof Of Possession for authenticating a secure session
25+
*/
26+
typedef struct protocomm_security_pop {
27+
/**
28+
* Pointer to buffer containing the proof of possession data
29+
*/
30+
const uint8_t *data;
31+
32+
/**
33+
* Length (in bytes) of the proof of possession data
34+
*/
35+
uint16_t len;
36+
} protocomm_security_pop_t;
37+
38+
/**
39+
* @brief Protocomm security object structure.
40+
*
41+
* The member functions are used for implementing secure
42+
* protocomm sessions.
43+
*
44+
* @note This structure should not have any dynamic
45+
* members to allow re-entrancy
46+
*/
47+
typedef struct protocomm_security {
48+
/**
49+
* Unique version number of security implementation
50+
*/
51+
int ver;
52+
53+
/**
54+
* Function for initializing/allocating security
55+
* infrastructure
56+
*/
57+
esp_err_t (*init)();
58+
59+
/**
60+
* Function for deallocating security infrastructure
61+
*/
62+
esp_err_t (*cleanup)();
63+
64+
/**
65+
* Starts new secure transport session with specified ID
66+
*/
67+
esp_err_t (*new_transport_session)(uint32_t session_id);
68+
69+
/**
70+
* Closes a secure transport session with specified ID
71+
*/
72+
esp_err_t (*close_transport_session)(uint32_t session_id);
73+
74+
/**
75+
* Handler function for authenticating connection
76+
* request and establishing secure session
77+
*/
78+
esp_err_t (*security_req_handler)(const protocomm_security_pop_t *pop,
79+
uint32_t session_id,
80+
const uint8_t *inbuf, ssize_t inlen,
81+
uint8_t **outbuf, ssize_t *outlen,
82+
void *priv_data);
83+
84+
/**
85+
* Function which implements the encryption algorithm
86+
*/
87+
esp_err_t (*encrypt)(uint32_t session_id,
88+
const uint8_t *inbuf, ssize_t inlen,
89+
uint8_t *outbuf, ssize_t *outlen);
90+
91+
/**
92+
* Function which implements the decryption algorithm
93+
*/
94+
esp_err_t (*decrypt)(uint32_t session_id,
95+
const uint8_t *inbuf, ssize_t inlen,
96+
uint8_t *outbuf, ssize_t *outlen);
97+
} protocomm_security_t;
98+
99+
#ifdef __cplusplus
100+
}
101+
#endif

0 commit comments

Comments
 (0)