Skip to content

Commit 26492d8

Browse files
petrosyan-vancfriedt
authored andcommitted
drivers: cellular: introduce cellular_set_apn() API
Add a driver-level hook that lets applications provide (or override) the APN string at run-time instead of hard-coding it in individual drivers. Signed-off-by: Van Petrosyan <[email protected]>
1 parent da5eef6 commit 26492d8

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

include/zephyr/drivers/cellular.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,17 @@ typedef int (*cellular_api_get_registration_status)(const struct device *dev,
109109
enum cellular_access_technology tech,
110110
enum cellular_registration_status *status);
111111

112+
/** API for programming APN */
113+
typedef int (*cellular_api_set_apn)(const struct device *dev, const char *apn);
114+
112115
/** Cellular driver API */
113116
__subsystem struct cellular_driver_api {
114117
cellular_api_configure_networks configure_networks;
115118
cellular_api_get_supported_networks get_supported_networks;
116119
cellular_api_get_signal get_signal;
117120
cellular_api_get_modem_info get_modem_info;
118121
cellular_api_get_registration_status get_registration_status;
122+
cellular_api_set_apn set_apn;
119123
};
120124

121125
/**
@@ -250,6 +254,33 @@ static inline int cellular_get_registration_status(const struct device *dev,
250254
return api->get_registration_status(dev, tech, status);
251255
}
252256

257+
/**
258+
* @brief Set the APN used for PDP context
259+
*
260+
* @details Drivers are expected to copy the string immediately and return
261+
* once the request has been queued internally.
262+
*
263+
* @param dev Cellular device
264+
* @param apn Zero-terminated APN string (max length is driver-specific)
265+
*
266+
* @retval 0 if successful.
267+
* @retval -ENOSYS if API is not supported by cellular network device.
268+
* @retval -EINVAL if APN string invalid or too long.
269+
* @retval -EALREADY if APN identical to current one, nothing to do
270+
* @retval -EBUSY if modem is already dialled, APN cannot be changed
271+
* @retval Negative errno-code otherwise.
272+
*/
273+
static inline int cellular_set_apn(const struct device *dev, const char *apn)
274+
{
275+
const struct cellular_driver_api *api = (const struct cellular_driver_api *)dev->api;
276+
277+
if (api->set_apn == NULL) {
278+
return -ENOSYS;
279+
}
280+
281+
return api->set_apn(dev, apn);
282+
}
283+
253284
#ifdef __cplusplus
254285
}
255286
#endif

0 commit comments

Comments
 (0)