diff --git a/components/esp_modem/include/esp_modem_c_api_types.h b/components/esp_modem/include/esp_modem_c_api_types.h index 2c37b796b..94d8f9b6c 100644 --- a/components/esp_modem/include/esp_modem_c_api_types.h +++ b/components/esp_modem/include/esp_modem_c_api_types.h @@ -15,6 +15,7 @@ #pragma once #include "esp_modem_config.h" +#include "esp_netif.h" #ifdef __cplusplus extern "C" { @@ -22,7 +23,11 @@ extern "C" { typedef struct esp_modem_dce_wrap esp_modem_dce_t; -struct PdpContext; +typedef struct esp_modem_PdpContext_t { + size_t context_id; + const char *protocol_type; + const char *apn; +} esp_modem_PdpContext_t; /** * @defgroup ESP_MODEM_C_API ESP_MODEM C API diff --git a/components/esp_modem/include/generate/esp_modem_command_declare.inc b/components/esp_modem/include/generate/esp_modem_command_declare.inc index 1709bf9da..8a5a4b8cb 100644 --- a/components/esp_modem/include/generate/esp_modem_command_declare.inc +++ b/components/esp_modem/include/generate/esp_modem_command_declare.inc @@ -38,7 +38,7 @@ #define BOOL_OUT(param, name) bool* _ARG(param, name) #define INT_OUT(param, name) int* _ARG(param, name) #define INTEGER_LIST_IN(param, name) const int* _ARG(param, name) -#define STRUCT_OUT(struct_name, p1) struct struct_name* p1 +#define STRUCT_OUT(struct_name, p1) esp_modem_ ## struct_name ## _t* p1 #endif #define DECLARE_ALL_COMMAND_APIS(...) \ diff --git a/components/esp_modem/src/esp_modem_c_api.cpp b/components/esp_modem/src/esp_modem_c_api.cpp index 1f1bbfeae..15cd423fa 100644 --- a/components/esp_modem/src/esp_modem_c_api.cpp +++ b/components/esp_modem/src/esp_modem_c_api.cpp @@ -393,3 +393,14 @@ extern "C" esp_err_t esp_modem_reset(esp_modem_dce_t *dce_wrap) { return command_response_to_esp_err(dce_wrap->dce->reset()); } + +extern "C" esp_err_t esp_modem_set_pdp_context(esp_modem_dce_t *dce_wrap, esp_modem_PdpContext_t *c_api_pdp) +{ + if (dce_wrap == nullptr || dce_wrap->dce == nullptr) { + return ESP_ERR_INVALID_ARG; + } + esp_modem::PdpContext pdp{c_api_pdp->apn}; + pdp.context_id = c_api_pdp->context_id; + pdp.protocol_type = c_api_pdp->protocol_type; + return command_response_to_esp_err(dce_wrap->dce->set_pdp_context(pdp)); +}