Skip to content

Commit

Permalink
Merge pull request #365 from wqx6/net_prov/net_type_option
Browse files Browse the repository at this point in the history
feat(network_prov): Add configuration option to choose network type (IEC-156)
  • Loading branch information
chshu authored Aug 27, 2024
2 parents 60c1426 + b67c9fb commit 7c63623
Show file tree
Hide file tree
Showing 16 changed files with 203 additions and 190 deletions.
17 changes: 16 additions & 1 deletion network_provisioning/Kconfig
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
menu "Network Provisioning Manager"

choice NETWORK_PROV_NETWORK_TYPE
prompt "Network Type"
default NETWORK_PROV_NETWORK_TYPE_WIFI if ESP_WIFI_ENABLED
default NETWORK_PROV_NETWORK_TYPE_THREAD if !ESP_WIFI_ENABLE && OPENTHREAD_ENABLED

config NETWORK_PROV_NETWORK_TYPE_WIFI
bool "Network Type - Wi-Fi"
depends on ESP_WIFI_ENABLED

config NETWORK_PROV_NETWORK_TYPE_THREAD
bool "Network Type - Thread"
depends on OPENTHREAD_ENABLED

endchoice

config NETWORK_PROV_SCAN_MAX_ENTRIES
int "Max Network Scan Result Entries"
default 16
Expand Down Expand Up @@ -51,7 +66,7 @@ menu "Network Provisioning Manager"

choice NETWORK_PROV_WIFI_STA_SCAN_METHOD
bool "Wifi Provisioning Scan Method"
depends on ESP_WIFI_ENABLED
depends on NETWORK_PROV_NETWORK_TYPE_WIFI
default NETWORK_PROV_WIFI_STA_ALL_CHANNEL_SCAN
config NETWORK_PROV_WIFI_STA_ALL_CHANNEL_SCAN
bool "All Channel Scan"
Expand Down
3 changes: 3 additions & 0 deletions network_provisioning/examples/thread_prov/sdkconfig.defaults
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ CONFIG_OPENTHREAD_ENABLED=y
CONFIG_OPENTHREAD_BORDER_ROUTER=n
CONFIG_OPENTHREAD_DNS64_CLIENT=y

# Network type
CONFIG_NETWORK_PROV_NETWORK_TYPE_THREAD=y

# LwIP
CONFIG_LWIP_TCPIP_TASK_STACK_SIZE=4096
CONFIG_LWIP_IPV6_NUM_ADDRESSES=8
Expand Down
2 changes: 1 addition & 1 deletion network_provisioning/idf_component.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: "1.0.0"
version: "1.0.1"
description: Network provisioning component for Wi-Fi or Thread devices
url: https://github.com/espressif/idf-extra-components/tree/master/network_provisioning
dependencies:
Expand Down
48 changes: 24 additions & 24 deletions network_provisioning/include/network_provisioning/manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
#include <protocomm.h>

#include "esp_event.h"
#if CONFIG_ESP_WIFI_ENABLED
#ifdef CONFIG_NETWORK_PROV_NETWORK_TYPE_WIFI
#include "esp_wifi_types.h"
#endif
#if CONFIG_OPENTHREAD_ENABLED
#ifdef CONFIG_NETWORK_PROV_NETWORK_TYPE_THREAD
#include "openthread/dataset.h"
#endif
#include "network_provisioning/network_config.h"
Expand Down Expand Up @@ -40,55 +40,55 @@ typedef enum {
* Indicates that provisioning has started
*/
NETWORK_PROV_START,
#if CONFIG_ESP_WIFI_ENABLED
#ifdef CONFIG_NETWORK_PROV_NETWORK_TYPE_WIFI
/**
* Emitted when Wi-Fi AP credentials are received via `protocomm`
* endpoint `network_config`. The event data in this case is a pointer
* to the corresponding `wifi_sta_config_t` structure
*/
NETWORK_PROV_WIFI_CRED_RECV,
#endif // CONFIG_ESP_WIFI_ENABLED
#if CONFIG_OPENTHREAD_ENABLED
#endif // CONFIG_NETWORK_PROV_NETWORK_TYPE_WIFI
#ifdef CONFIG_NETWORK_PROV_NETWORK_TYPE_THREAD
/**
* Emitted when Thread Dataset is received via `protocomm` endpoint
* `network_config`, The event data in this case is a pointer to the
* corresponding `otOperationalDatasetTlvs` structure
*/
NETWORK_PROV_THREAD_DATASET_RECV,
#endif // CONFIG_OPENTHREAD_ENABLED
#if CONFIG_ESP_WIFI_ENABLED
#endif // CONFIG_NETWORK_PROV_NETWORK_TYPE_THREAD
#ifdef CONFIG_NETWORK_PROV_NETWORK_TYPE_WIFI
/**
* Emitted when device fails to connect to the AP of which the
* credentials were received earlier on event `NETWORK_PROV_WIFI_CRED_RECV`.
* The event data in this case is a pointer to the disconnection
* reason code with type `network_prov_wifi_sta_fail_reason_t`
*/
NETWORK_PROV_WIFI_CRED_FAIL,
#endif // CONFIG_ESP_WIFI_ENABLED
#if CONFIG_OPENTHREAD_ENABLED
#endif // CONFIG_NETWORK_PROV_NETWORK_TYPE_WIFI
#ifdef CONFIG_NETWORK_PROV_NETWORK_TYPE_THREAD
/**
* Emitted when device fails to connect to the Thread network of which
* dataset was received earlier on event `NETWORK_PROv_THREAD_DATASET_RECV`.
* The event data in this case is a pointer to the disconnection
* reason code with type `network_prov_thread_fail_reason_t`
*/
NETWORK_PROV_THREAD_DATASET_FAIL,
#endif // CONFIG_OPENTHREAD_ENABLED
#if CONFIG_ESP_WIFI_ENABLED
#endif // CONFIG_NETWORK_PROV_NETWORK_TYPE_THREAD
#ifdef CONFIG_NETWORK_PROV_NETWORK_TYPE_WIFI
/**
* Emitted when device successfully connects to the AP of which the
* credentials were received earlier on event `NETWORK_PROV_WIFI_CRED_RECV`
*/
NETWORK_PROV_WIFI_CRED_SUCCESS,
#endif // CONFIG_ESP_WIFI_ENABLED
#if CONFIG_OPENTHREAD_ENABLED
#endif // CONFIG_NETWORK_PROV_NETWORK_TYPE_WIFI
#ifdef CONFIG_NETWORK_PROV_NETWORK_TYPE_THREAD
/**
* Emitted when device successfully connects to the Thread etwork of
* which the dataset was received earlier on event
* `NETWORK_PROV_THREAD_DATASET_RECV`
*/
NETWORK_PROV_THREAD_DATASET_SUCCESS,
#endif // CONFIG_OPENTHREAD_ENABLED
#endif // CONFIG_NETWORK_PROV_NETWORK_TYPE_THREAD

/**
* Signals that provisioning service has stopped
Expand Down Expand Up @@ -175,15 +175,15 @@ typedef struct network_prov_scheme {
*/
esp_err_t (*set_config_endpoint) (void *config, const char *endpoint_name, uint16_t uuid);

#if CONFIG_ESP_WIFI_ENABLED
#ifdef CONFIG_NETWORK_PROV_NETWORK_TYPE_WIFI
/**
* Sets mode of operation of Wi-Fi during provisioning
* This is set to :
* - WIFI_MODE_APSTA for SoftAP transport
* - WIFI_MODE_STA for BLE transport
*/
wifi_mode_t wifi_mode;
#endif // CONFIG_ESP_WIFI_ENABLED
#endif // CONFIG_NETWORK_PROV_NETWORK_TYPE_WIFI
} network_prov_scheme_t;

/**
Expand Down Expand Up @@ -292,7 +292,7 @@ esp_err_t network_prov_mgr_init(network_prov_mgr_config_t config);
*/
void network_prov_mgr_deinit(void);

#if CONFIG_ESP_WIFI_ENABLED
#ifdef CONFIG_NETWORK_PROV_NETWORK_TYPE_WIFI
/**
* @brief Checks if device is provisioned
*
Expand All @@ -317,9 +317,9 @@ void network_prov_mgr_deinit(void);
* - ESP_ERR_INVALID_ARG : Null argument supplied
*/
esp_err_t network_prov_mgr_is_wifi_provisioned(bool *provisioned);
#endif // CONFIG_ESP_WIFI_ENABLED
#endif // CONFIG_NETWORK_PROV_NETWORK_TYPE_WIFI

#if CONFIG_OPENTHREAD_ENABLED
#ifdef CONFIG_NETWORK_PROV_NETWORK_TYPE_THREAD
/**
* @brief Checks if device is provisioned
*
Expand All @@ -337,7 +337,7 @@ esp_err_t network_prov_mgr_is_wifi_provisioned(bool *provisioned);
* - ESP_ERR_INVALID_ARG : Null argument supplied
*/
esp_err_t network_prov_mgr_is_thread_provisioned(bool *provisioned);
#endif // CONFIG_ESP_WIFI_ENABLED
#endif // CONFIG_NETWORK_PROV_NETWORK_TYPE_THREAD

/**
* @brief Checks whether the provisioning state machine is idle
Expand Down Expand Up @@ -569,7 +569,7 @@ esp_err_t network_prov_mgr_endpoint_register(const char *ep_name,
*/
void network_prov_mgr_endpoint_unregister(const char *ep_name);

#if CONFIG_ESP_WIFI_ENABLED
#ifdef CONFIG_NETWORK_PROV_NETWORK_TYPE_WIFI
/**
* @brief Get state of Wi-Fi Station during provisioning
*
Expand Down Expand Up @@ -660,9 +660,9 @@ esp_err_t network_prov_mgr_reset_wifi_sm_state_on_failure(void);
* - ESP_ERR_INVALID_STATE : Manager not initialized
*/
esp_err_t network_prov_mgr_reset_wifi_sm_state_for_reprovision(void);
#endif // CONFIG_ESP_WIFI_ENABLED
#endif // CONFIG_NETWORK_PROV_NETWORK_TYPE_WIFI

#if CONFIG_OPENTHREAD_ENABLED
#ifdef CONFIG_NETWORK_PROV_NETWORK_TYPE_THREAD
/**
* @brief Reset Thread provisioning config
*
Expand Down Expand Up @@ -752,7 +752,7 @@ esp_err_t network_prov_mgr_reset_thread_sm_state_on_failure(void);
*/
esp_err_t network_prov_mgr_reset_thread_sm_state_for_reprovision(void);

#endif // CONFIG_OPENTHREAD_ENABLED
#endif // CONFIG_NETWORK_PROV_NETWORK_TYPE_THREAD


#ifdef __cplusplus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
extern "C" {
#endif

#if CONFIG_ESP_WIFI_ENABLED
#ifdef CONFIG_NETWORK_PROV_NETWORK_TYPE_WIFI
/**
* @brief WiFi STA status for conveying back to the provisioning master
*/
Expand Down Expand Up @@ -74,9 +74,9 @@ typedef struct {
char bssid[6]; /*!< BSSID of the AP */
uint8_t channel; /*!< Channel of the AP */
} network_prov_config_set_wifi_data_t;
#endif // CONFIG_ESP_WIFI_ENABLED
#endif // CONFIG_NETWORK_PROV_NETWORK_TYPE_WIFI

#if CONFIG_OPENTHREAD_ENABLED
#ifdef CONFIG_NETWORK_PROV_NETWORK_TYPE_THREAD
/**
* @brief Thread status for conveying back to the provisioning master
*/
Expand Down Expand Up @@ -129,7 +129,7 @@ typedef struct {
uint8_t dataset[254];
uint8_t length;
} network_prov_config_set_thread_data_t;
#endif // CONFIG_OPENTHREAD_ENABLED
#endif // CONFIG_NETWORK_PROV_NETWORK_TYPE_THREAD

/**
* @brief Type of context data passed to each get/set/apply handler
Expand All @@ -148,7 +148,7 @@ typedef struct network_prov_ctx network_prov_ctx_t;
* (refer to `network_prov_config_data_handler()`) when calling `protocomm_add_endpoint()`.
*/
typedef struct network_prov_config_handlers {
#if CONFIG_ESP_WIFI_ENABLED
#ifdef CONFIG_NETWORK_PROV_NETWORK_TYPE_WIFI
/**
* Handler function called when connection status
* of the slave (in WiFi station mode) is requested
Expand All @@ -172,17 +172,17 @@ typedef struct network_prov_config_handlers {
* invoked again by the master.
*/
esp_err_t (*wifi_apply_config_handler)(network_prov_ctx_t **ctx);
#endif // CONFIG_ESP_WIFI_ENABLED
#endif // CONFIG_NETWORK_PROV_NETWORK_TYPE_WIFI

#if CONFIG_OPENTHREAD_ENABLED
#ifdef CONFIG_NETWORK_PROV_NETWORK_TYPE_THREAD
esp_err_t (*thread_get_status_handler)(network_prov_config_get_thread_data_t *resp_data,
network_prov_ctx_t **ctx);

esp_err_t (*thread_set_config_handler)(const network_prov_config_set_thread_data_t *req_data,
network_prov_ctx_t **ctx);

esp_err_t (*thread_apply_config_handler)(network_prov_ctx_t **ctx);
#endif // CONFIG_OPENTHREAD_ENABLED
#endif // CONFIG_NETWORK_PROV_NETWORK_TYPE_THREAD

/**
* Context pointer to be passed to above handler functions upon invocation
Expand Down
24 changes: 12 additions & 12 deletions network_provisioning/include/network_provisioning/network_scan.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@
extern "C" {
#endif
#include <sdkconfig.h>
#if CONFIG_ESP_WIFI_ENABLED
#ifdef CONFIG_NETWORK_PROV_NETWORK_TYPE_WIFI
#include <esp_wifi.h>

#define WIFI_SSID_LEN sizeof(((wifi_ap_record_t *)0)->ssid)
#define WIFI_BSSID_LEN sizeof(((wifi_ap_record_t *)0)->bssid)
#endif // CONFIG_ESP_WIFI_ENABLED
#endif // CONFIG_NETWORK_PROV_NETWORK_TYPE_WIFI

#if CONFIG_OPENTHREAD_ENABLED
#ifdef CONFIG_NETWORK_PROV_NETWORK_TYPE_THREAD
#include <openthread/dataset.h>
#include <openthread/platform/radio.h>
#endif // CONFIG_OPENTHREAD_ENABLED
#endif // CONFIG_NETWORK_PROV_NETWORK_TYPE_THREAD

/**
* @brief Type of context data passed to each get/set/apply handler
Expand All @@ -32,7 +32,7 @@ extern "C" {
*/
typedef struct network_prov_scan_ctx network_prov_scan_ctx_t;

#if CONFIG_ESP_WIFI_ENABLED
#ifdef CONFIG_NETWORK_PROV_NETWORK_TYPE_WIFI
/**
* @brief Structure of entries in the scan results list
*/
Expand Down Expand Up @@ -62,9 +62,9 @@ typedef struct {
*/
uint8_t auth;
} network_prov_scan_wifi_result_t;
#endif // CONFIG_ESP_WIFI_ENABLED
#endif // CONFIG_NETWORK_PROV_NETWORK_TYPE_WIFI

#if CONFIG_OPENTHREAD_ENABLED
#ifdef CONFIG_NETWORK_PROV_NETWORK_TYPE_THREAD
typedef struct {
uint16_t pan_id;
uint8_t ext_pan_id[OT_EXT_ADDRESS_SIZE];
Expand All @@ -74,7 +74,7 @@ typedef struct {
int8_t rssi;
uint8_t lqi;
} network_prov_scan_thread_result_t;
#endif // CONFIG_OPENTHREAD_ENABLED
#endif // CONFIG_NETWORK_PROV_NETWORK_TYPE_THREAD

/**
* @brief Internal handlers for receiving and responding to protocomm
Expand All @@ -84,7 +84,7 @@ typedef struct {
* (refer to `network_prov_scan_handler()`) when calling `protocomm_add_endpoint()`.
*/
typedef struct network_prov_scan_handlers {
#if CONFIG_ESP_WIFI_ENABLED
#ifdef CONFIG_NETWORK_PROV_NETWORK_TYPE_WIFI
/**
* Handler function called when scan start command is received
* with various scan parameters :
Expand Down Expand Up @@ -157,9 +157,9 @@ typedef struct network_prov_scan_handlers {
esp_err_t (*wifi_scan_result)(uint16_t result_index,
network_prov_scan_wifi_result_t *result,
network_prov_scan_ctx_t **ctx);
#endif // CONFIG_ESP_WIFI_ENABLED
#endif // CONFIG_NETWORK_PROV_NETWORK_TYPE_WIFI

#if CONFIG_OPENTHREAD_ENABLED
#ifdef CONFIG_NETWORK_PROV_NETWORK_TYPE_THREAD
esp_err_t (*thread_scan_start)(bool blocking, uint32_t channel_mask, network_prov_scan_ctx_t **ctx);

esp_err_t (*thread_scan_status)(bool *scan_finished,
Expand All @@ -169,7 +169,7 @@ typedef struct network_prov_scan_handlers {
esp_err_t (*thread_scan_result)(uint16_t result_index,
network_prov_scan_thread_result_t *result,
network_prov_scan_ctx_t **ctx);
#endif // CONFIG_OPENTHREAD_ENABLED
#endif // CONFIG_NETWORK_PROV_NETWORK_TYPE_THREAD

/**
* Context pointer to be passed to above handler functions upon invocation
Expand Down
Loading

0 comments on commit 7c63623

Please sign in to comment.