scheme_console.c 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // Copyright 2019 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. #include <string.h>
  15. #include <esp_log.h>
  16. #include <esp_err.h>
  17. #include <esp_wifi.h>
  18. #include <protocomm.h>
  19. #include <protocomm_console.h>
  20. #include "wifi_provisioning/scheme_console.h"
  21. #include "wifi_provisioning_priv.h"
  22. static const char *TAG = "wifi_prov_scheme_console";
  23. extern const wifi_prov_scheme_t wifi_prov_scheme_console;
  24. static esp_err_t prov_start(protocomm_t *pc, void *config)
  25. {
  26. if (!pc) {
  27. ESP_LOGE(TAG, "Protocomm handle cannot be null");
  28. return ESP_ERR_INVALID_ARG;
  29. }
  30. if (!config) {
  31. ESP_LOGE(TAG, "Cannot start with null configuration");
  32. return ESP_ERR_INVALID_ARG;
  33. }
  34. protocomm_console_config_t *console_config = (protocomm_console_config_t *) config;
  35. /* Start protocomm console */
  36. esp_err_t err = protocomm_console_start(pc, console_config);
  37. if (err != ESP_OK) {
  38. ESP_LOGE(TAG, "Failed to start protocomm HTTP server");
  39. return ESP_FAIL;
  40. }
  41. return ESP_OK;
  42. }
  43. static void *new_config(void)
  44. {
  45. protocomm_console_config_t *console_config = malloc(sizeof(protocomm_console_config_t));
  46. if (!console_config) {
  47. ESP_LOGE(TAG, "Error allocating memory for new configuration");
  48. return NULL;
  49. }
  50. protocomm_console_config_t default_config = PROTOCOMM_CONSOLE_DEFAULT_CONFIG();
  51. memcpy(console_config, &default_config, sizeof(default_config));
  52. return console_config;
  53. }
  54. static void delete_config(void *config)
  55. {
  56. if (!config) {
  57. ESP_LOGE(TAG, "Cannot delete null configuration");
  58. return;
  59. }
  60. free(config);
  61. }
  62. static esp_err_t set_config_service(void *config, const char *service_name, const char *service_key)
  63. {
  64. return ESP_OK;
  65. }
  66. static esp_err_t set_config_endpoint(void *config, const char *endpoint_name, uint16_t uuid)
  67. {
  68. return ESP_OK;
  69. }
  70. const wifi_prov_scheme_t wifi_prov_scheme_console = {
  71. .prov_start = prov_start,
  72. .prov_stop = protocomm_console_stop,
  73. .new_config = new_config,
  74. .delete_config = delete_config,
  75. .set_config_service = set_config_service,
  76. .set_config_endpoint = set_config_endpoint,
  77. .wifi_mode = WIFI_MODE_STA
  78. };