Skip to content

Commit

Permalink
drivers: cellular: add signal and modem_info API
Browse files Browse the repository at this point in the history
Signed-off-by: Lucas Denefle <lucas.denefle@converge.io>
  • Loading branch information
ldenefle committed Nov 24, 2023
1 parent c27a181 commit 66aa74b
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 0 deletions.
39 changes: 39 additions & 0 deletions drivers/modem/modem_cellular.c
Expand Up @@ -7,6 +7,7 @@
#include <zephyr/kernel.h>
#include <zephyr/device.h>
#include <zephyr/drivers/gpio.h>
#include <zephyr/drivers/cellular.h>
#include <zephyr/modem/chat.h>
#include <zephyr/modem/cmux.h>
#include <zephyr/modem/pipe.h>
Expand Down Expand Up @@ -1925,3 +1926,41 @@ DT_INST_FOREACH_STATUS_OKAY(MODEM_CELLULAR_DEVICE_SWIR_HL7800)
#define DT_DRV_COMPAT telit_me910g1
DT_INST_FOREACH_STATUS_OKAY(MODEM_CELLULAR_DEVICE_TELIT_ME910G1)
#undef DT_DRV_COMPAT


int cellular_get_modem_info(const struct device *dev, enum cellular_modem_info_type type,
char *info, size_t size)
{
int rc = 0;

struct modem_cellular_data *data = (struct modem_cellular_data *)dev->data;

switch (type) {
case CELLULAR_MODEM_INFO_IMEI:
memcpy(info, &data->imei[0], MIN(size, sizeof(data->imei)));
break;
case CELLULAR_MODEM_INFO_IMSI:
memcpy(info, &data->imsi[0], MIN(size, sizeof(data->imsi)));
break;
case CELLULAR_MODEM_INFO_ICCID:
memcpy(info, &data->iccid[0], MIN(size, sizeof(data->iccid)));
break;
default:
rc = -ENODATA;
break;
}

return rc;
}

int cellular_get_signal(const struct device *dev, struct cellular_signal *signal)
{
struct modem_cellular_data *data = (struct modem_cellular_data *)dev->data;

if ((data->state != MODEM_CELLULAR_STATE_AWAIT_REGISTERED) &&
(data->state != MODEM_CELLULAR_STATE_CARRIER_ON)) {
return -ENODATA;
}
)
signal->rssi = data->rssi;
}
53 changes: 53 additions & 0 deletions include/zephyr/drivers/cellular.h
Expand Up @@ -52,6 +52,30 @@ struct cellular_network {
uint16_t size;
};

enum cellular_signal_quality {
CELLULAR_MODEM_SIGNAL_EXCELLENT,
CELLULAR_MODEM_SIGNAL_GOOD,
CELLULAR_MODEM_SIGNAL_BAD,
};

struct cellular_signal {
/* RSSI signal */
int16_t rssi;
/* Signal quality */
enum cellular_signal_quality quality;
/* Signal percentage */
uint8_t percentage;
};

enum cellular_modem_info_type {
/* International Mobile Equipment Identity */
CELLULAR_MODEM_INFO_IMEI,
/* International Mobile Subscriber Identity */
CELLULAR_MODEM_INFO_IMSI,
/* Integrated Circuit Card Identification Number (SIM) */
CELLULAR_MODEM_INFO_ICCID,
};

/**
* @brief Configure cellular networks for the device
*
Expand Down Expand Up @@ -90,6 +114,35 @@ int cellular_configure_networks(const struct device *dev, const struct cellular_
int cellular_get_supported_networks(const struct device *dev,
const struct cellular_network **networks, uint8_t *size);

/**
* @brief Get signal for the device
*
* @param dev Cellular network device instance
* @param signal Pointer to a struct containing signal information
*
* @retval 0 if successful.
* @retval -ENOTSUP if API is not supported by cellular network device.
* @retval -ENODATA if device is not in a state where signal can be polled
* @retval Negative errno-code otherwise.
*/
int cellular_get_signal(const struct device *dev, struct cellular_signal *signal);

/**
* @brief Get modem info for the device
*
* @param dev Cellular network device instance
* @param type Type of the modem info requested
* @param info Pointer of a string containing the result
* @param size Size of the result string
*
* @retval 0 if successful.
* @retval -ENOTSUP if API is not supported by cellular network device.
* @retval -ENODATA if modem does not provide info requested
* @retval Negative errno-code otherwise.
*/
int cellular_get_modem_info(const struct device *dev, enum cellular_modem_info_type type,
char *info, size_t size);

#ifdef __cplusplus
}
#endif
Expand Down

0 comments on commit 66aa74b

Please sign in to comment.