mirror of
https://github.com/espressif/esp-rainmaker.git
synced 2026-01-15 04:18:10 +00:00
rmaker_app_network: Expose the API to read the configured PoP
This commit is contained in:
@@ -2,6 +2,16 @@
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
## [1.3.0]
|
||||
|
||||
### Added
|
||||
- Exposed `app_network_get_device_pop()` API to get PoP string for a given pop_type
|
||||
- Added `app_network_get_device_pop_default()` API to get PoP using cached pop_type from `app_network_start()`
|
||||
- Added `app_network_get_device_service_name()` API to get the provisioning service name (BLE device name / SoftAP SSID)
|
||||
|
||||
### Fixed
|
||||
- Fixed buffer size for service name to accommodate longer `CONFIG_APP_NETWORK_PROV_NAME_PREFIX` values
|
||||
|
||||
## [1.2.0]
|
||||
|
||||
### Fixed
|
||||
|
||||
@@ -201,6 +201,9 @@ static esp_err_t read_random_bytes_from_nvs(uint8_t **random_bytes, size_t *len)
|
||||
}
|
||||
|
||||
static char *custom_pop;
|
||||
static app_network_pop_type_t s_cached_pop_type = POP_TYPE_NONE;
|
||||
static bool s_pop_type_cached = false;
|
||||
|
||||
esp_err_t app_network_set_custom_pop(const char *pop)
|
||||
{
|
||||
/* NULL PoP is not allowed here. Use POP_TYPE_NONE instead. */
|
||||
@@ -241,7 +244,7 @@ static esp_err_t get_device_service_name(char *service_name, size_t max)
|
||||
}
|
||||
|
||||
|
||||
static char *get_device_pop(app_network_pop_type_t pop_type)
|
||||
char *app_network_get_device_pop(app_network_pop_type_t pop_type)
|
||||
{
|
||||
if (pop_type == POP_TYPE_NONE) {
|
||||
return NULL;
|
||||
@@ -288,6 +291,30 @@ pop_err:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *app_network_get_device_pop_default(void)
|
||||
{
|
||||
if (!s_pop_type_cached) {
|
||||
ESP_LOGW(TAG, "PoP type not cached. Call app_network_start() first.");
|
||||
return NULL;
|
||||
}
|
||||
return app_network_get_device_pop(s_cached_pop_type);
|
||||
}
|
||||
|
||||
char *app_network_get_device_service_name(void)
|
||||
{
|
||||
/* Buffer size: prefix + "_" + 6 hex chars + null terminator */
|
||||
size_t buf_size = strlen(CONFIG_APP_NETWORK_PROV_NAME_PREFIX) + 1 + 6 + 1;
|
||||
char *service_name = malloc(buf_size);
|
||||
if (!service_name) {
|
||||
return NULL;
|
||||
}
|
||||
if (get_device_service_name(service_name, buf_size) != ESP_OK) {
|
||||
free(service_name);
|
||||
return NULL;
|
||||
}
|
||||
return service_name;
|
||||
}
|
||||
|
||||
static void network_event_handler(void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data)
|
||||
{
|
||||
|
||||
@@ -410,19 +437,24 @@ esp_err_t app_network_start_timer(void)
|
||||
|
||||
esp_err_t app_network_start(app_network_pop_type_t pop_type)
|
||||
{
|
||||
/* Cache the pop_type for later use by app_network_get_device_pop_default() */
|
||||
s_cached_pop_type = pop_type;
|
||||
s_pop_type_cached = true;
|
||||
|
||||
/* Do we want a proof-of-possession (ignored if Security 0 is selected):
|
||||
* - this should be a string with length > 0
|
||||
* - NULL if not used
|
||||
*/
|
||||
char *pop = get_device_pop(pop_type);
|
||||
char *pop = app_network_get_device_pop(pop_type);
|
||||
if ((pop_type != POP_TYPE_NONE) && (pop == NULL)) {
|
||||
return ESP_ERR_NO_MEM;
|
||||
}
|
||||
/* What is the Device Service Name that we want
|
||||
* This translates to :
|
||||
* - device name when scheme is network_prov_scheme_ble/wifi_prov_scheme_ble
|
||||
* Buffer size: prefix + "_" + 6 hex chars + null terminator
|
||||
*/
|
||||
char service_name[12];
|
||||
char service_name[strlen(CONFIG_APP_NETWORK_PROV_NAME_PREFIX) + 1 + 6 + 1];
|
||||
get_device_service_name(service_name, sizeof(service_name));
|
||||
/* What is the service key (Wi-Fi password)
|
||||
* NULL = Open network
|
||||
|
||||
@@ -105,6 +105,40 @@ esp_err_t app_network_set_custom_mfg_data(uint16_t device_type, uint8_t device_s
|
||||
*/
|
||||
esp_err_t app_network_set_custom_pop(const char *pop);
|
||||
|
||||
/** Get device PoP string
|
||||
*
|
||||
* Generate and return the Proof of Possession (PoP) string based on the specified type.
|
||||
* The caller is responsible for freeing the returned string.
|
||||
*
|
||||
* @param[in] pop_type The type of PoP to generate
|
||||
*
|
||||
* @return Pointer to the allocated PoP string on success (caller must free).
|
||||
* @return NULL on failure or if pop_type is POP_TYPE_NONE.
|
||||
*/
|
||||
char *app_network_get_device_pop(app_network_pop_type_t pop_type);
|
||||
|
||||
/** Get device PoP string using cached pop_type
|
||||
*
|
||||
* Returns the PoP string using the pop_type that was used in the last call to app_network_start().
|
||||
* The caller is responsible for freeing the returned string.
|
||||
*
|
||||
* @note This function should only be called after app_network_start() has been called.
|
||||
*
|
||||
* @return Pointer to the allocated PoP string on success (caller must free).
|
||||
* @return NULL if app_network_start() hasn't been called yet or on failure.
|
||||
*/
|
||||
char *app_network_get_device_pop_default(void);
|
||||
|
||||
/** Get device service name
|
||||
*
|
||||
* Returns the service name used for provisioning (e.g., BLE device name or SoftAP SSID).
|
||||
* The caller is responsible for freeing the returned string.
|
||||
*
|
||||
* @return Pointer to the allocated service name string on success (caller must free).
|
||||
* @return NULL on failure.
|
||||
*/
|
||||
char *app_network_get_device_service_name(void);
|
||||
|
||||
#if CONFIG_APP_WIFI_PROV_COMPAT
|
||||
#define APP_WIFI_EVENT APP_NETWORK_EVENT
|
||||
typedef app_network_event_t app_wifi_event_t;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
## IDF Component Manager Manifest File
|
||||
version: "1.2.0"
|
||||
version: "1.3.0"
|
||||
description: Network connectivity helper component for ESP RainMaker applications with WiFi and Thread support
|
||||
url: https://github.com/espressif/esp-rainmaker/tree/master/examples/common/rmaker_app_network
|
||||
repository: https://github.com/espressif/esp-rainmaker.git
|
||||
|
||||
Reference in New Issue
Block a user