Skip to content

Commit

Permalink
pdn: make pdp_context_dynamic_params_get common
Browse files Browse the repository at this point in the history
- convert
link_api_pdp_context_dynamic_params_get
to
pdn_pdp_context_dynamic_params_get
and use it on both SLM and MOSH

Signed-off-by: Oguzhan Turk <[email protected]>
  • Loading branch information
TaeZStkyoht committed Jan 6, 2025
1 parent d1fa9c0 commit f69eac8
Show file tree
Hide file tree
Showing 6 changed files with 258 additions and 256 deletions.
24 changes: 13 additions & 11 deletions applications/serial_lte_modem/src/slm_ppp.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,19 +210,21 @@ static int ppp_start_internal(void)
return -EADDRNOTAVAIL;
}

ret = pdn_dynamic_params_get(PDP_CID, &ctx->ipcp.my_options.dns1_address,
&ctx->ipcp.my_options.dns2_address, &mtu);
if (ret) {
/* If any error happened on pdn getting with IPv4, try to parse with IPv6 */
ret = pdn_dynamic_params_get_v6(PDP_CID, NULL, NULL, &mtu);
if (ret && ret != -EBADMSG) {
return ret;
}
}
struct pdp_context_info populated_info = {};

if (mtu) {
populated_info.cid = PDP_CID;
ret = pdn_pdp_context_dynamic_params_get(&populated_info);

if (populated_info.ipv6_mtu) {
/* Set the PPP MTU to that of the LTE link. */
/* IPv6's MTU has more priority on dual-stack.
* Because, it must be at least 1280 for IPv6,
* while MTU of IPv6 may be less.
*/
mtu = MIN(populated_info.ipv6_mtu, sizeof(ppp_data_buf));
} else if (populated_info.ipv4_mtu) {
/* Set the PPP MTU to that of the LTE link. */
mtu = MIN(mtu, sizeof(ppp_data_buf));
mtu = MIN(populated_info.ipv4_mtu, sizeof(ppp_data_buf));
} else {
LOG_DBG("Could not retrieve MTU, using fallback value.");
mtu = CONFIG_SLM_PPP_FALLBACK_MTU;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -452,8 +452,8 @@ Modem libraries

* :ref:`pdn_readme` library:

* Added the :c:func:`pdn_dynamic_params_get_v6` function to get PDN parameters for IPv6-only.
* Changed logic DNS record expectation. Because ISP sends sometimes 1 and even 0.
* mark :c:func:`pdn_dynamic_params_get` as deprecated
* move :c:func:`link_api_pdp_context_dynamic_params_get` to common place as :c:func:`pdn_pdp_context_dynamic_params_get`

* :ref:`lte_lc_readme` library:

Expand Down
97 changes: 89 additions & 8 deletions include/modem/pdn.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
extern "C" {
#endif

#define AT_CMD_PDP_CONTEXT_READ_PDP_TYPE_STR_MAX_LEN (6 + 1)
#define APN_STR_MAX_LEN 64

/**
* @file pdn.h
* @brief Public APIs for the PDN library.
Expand Down Expand Up @@ -54,6 +57,88 @@ struct pdn_pdp_opt {
uint8_t secure_pco;
};

/**
* @brief PDP context information structure.
*
* This structure holds information about the PDP context.
*/
struct pdp_context_info {
/**
* @brief Context identifier.
*/
uint32_t cid;

/**
* @brief IPv4 Maximum Transmission Unit.
*/
uint32_t ipv4_mtu;

/**
* @brief IPv6 Maximum Transmission Unit.
*/
uint32_t ipv6_mtu;

/**
* @brief PDN identifier.
*/
uint32_t pdn_id;

/**
* @brief Indicates if PDN identifier is valid.
*/
bool pdn_id_valid;

/**
* @brief Indicates if the context is active.
*/
bool ctx_active;

/**
* @brief PDP type as a string.
*/
char pdp_type_str[AT_CMD_PDP_CONTEXT_READ_PDP_TYPE_STR_MAX_LEN];

/**
* @brief Access Point Name as a string.
*/
char apn_str[APN_STR_MAX_LEN];

/**
* @brief PDP type.
*/
char pdp_type;

/**
* @brief IPv4 address.
*/
struct in_addr ip_addr4;

/**
* @brief IPv6 address.
*/
struct in6_addr ip_addr6;

/**
* @brief Primary IPv4 DNS address.
*/
struct in_addr dns_addr4_primary;

/**
* @brief Secondary IPv4 DNS address.
*/
struct in_addr dns_addr4_secondary;

/**
* @brief Primary IPv6 DNS address.
*/
struct in6_addr dns_addr6_primary;

/**
* @brief Secondary IPv6 DNS address.
*/
struct in6_addr dns_addr6_secondary;
};

/** @brief PDN library event */
enum pdn_event {
/** +CNEC ESM error code */
Expand Down Expand Up @@ -182,6 +267,7 @@ int pdn_id_get(uint8_t cid);

/**
* @brief Retrieve dynamic parameters of a given PDP context.
* This is deprecated. Use pdn_pdp_context_dynamic_params_get instead.
*
* @param cid The PDP context ID.
* @param[out] dns4_pri The address of the primary IPv4 DNS server. Optional, can be NULL.
Expand All @@ -190,22 +276,17 @@ int pdn_id_get(uint8_t cid);
*
* @return Zero on success or an error code on failure.
*/
int pdn_dynamic_params_get(uint8_t cid, struct in_addr *dns4_pri,
__deprecated int pdn_dynamic_params_get(uint8_t cid, struct in_addr *dns4_pri,
struct in_addr *dns4_sec, unsigned int *ipv4_mtu);

/**
* @brief Retrieve dynamic parameters of a given PDP context.
*
* @param cid The PDP context ID.
* @param[out] dns6_pri The address of the primary IPv6 DNS server. Optional, can be NULL.
* @param[out] dns6_sec The address of the secondary IPv6 DNS server. Optional, can be NULL.
* @param[out] ipv6_mtu The IPv6 MTU. Optional, can be NULL.
* @param[inout] populated_info PDP context info.
*
* @return Zero on success or an error code on failure.
*/
int pdn_dynamic_params_get_v6(uint8_t cid, struct in6_addr *dns6_pri,
struct in6_addr *dns6_sec, unsigned int *ipv6_mtu);

int pdn_pdp_context_dynamic_params_get(struct pdp_context_info *populated_info);
/**
* @brief Retrieve the default Access Point Name (APN).
*
Expand Down
Loading

0 comments on commit f69eac8

Please sign in to comment.