1 /** @file 2 * @brief Modem context header file. 3 * 4 * A modem context driver allowing application to handle all 5 * aspects of received protocol data. 6 */ 7 8 /* 9 * Copyright (c) 2019 Foundries.io 10 * 11 * SPDX-License-Identifier: Apache-2.0 12 */ 13 14 #ifndef ZEPHYR_INCLUDE_DRIVERS_MODEM_MODEM_CONTEXT_H_ 15 #define ZEPHYR_INCLUDE_DRIVERS_MODEM_MODEM_CONTEXT_H_ 16 17 #include <zephyr/kernel.h> 18 #include <zephyr/net/buf.h> 19 #include <zephyr/net/net_ip.h> 20 #include <zephyr/sys/ring_buffer.h> 21 #include <zephyr/drivers/gpio.h> 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 struct modem_iface { 28 const struct device *dev; 29 30 int (*read)(struct modem_iface *iface, uint8_t *buf, size_t size, 31 size_t *bytes_read); 32 int (*write)(struct modem_iface *iface, const uint8_t *buf, size_t size); 33 34 /* implementation data */ 35 void *iface_data; 36 }; 37 38 struct modem_cmd_handler { 39 void (*process)(struct modem_cmd_handler *cmd_handler, 40 struct modem_iface *iface); 41 42 /* implementation data */ 43 void *cmd_handler_data; 44 }; 45 46 struct modem_context { 47 /* modem data */ 48 char *data_manufacturer; 49 char *data_model; 50 char *data_revision; 51 char *data_imei; 52 #if defined(CONFIG_MODEM_SIM_NUMBERS) 53 char *data_imsi; 54 char *data_iccid; 55 #endif 56 #if defined(CONFIG_MODEM_CELL_INFO) 57 int data_operator; 58 int data_lac; 59 int data_cellid; 60 int data_act; 61 #endif 62 int *data_rssi; 63 bool is_automatic_oper; 64 65 /* interface config */ 66 struct modem_iface iface; 67 68 /* command handler config */ 69 struct modem_cmd_handler cmd_handler; 70 71 /* driver data */ 72 void *driver_data; 73 }; 74 75 /** 76 * @brief IP address to string 77 * 78 * @param addr: sockaddr to be converted 79 * @param buf: Buffer to store IP in string form 80 * @param buf_size: buffer size 81 * 82 * @retval 0 if ok, < 0 if error. 83 */ 84 int modem_context_sprint_ip_addr(const struct sockaddr *addr, char *buf, size_t buf_size); 85 86 /** 87 * @brief Get port from IP address 88 * 89 * @param addr: sockaddr 90 * @param port: store port 91 * 92 * @retval 0 if ok, < 0 if error. 93 */ 94 int modem_context_get_addr_port(const struct sockaddr *addr, uint16_t *port); 95 96 /** 97 * @brief Gets modem context by id. 98 * 99 * @param id: modem context id. 100 * 101 * @retval modem context or NULL. 102 */ 103 struct modem_context *modem_context_from_id(int id); 104 105 /** 106 * @brief Finds modem context which owns the iface device. 107 * 108 * @param *dev: device used by the modem iface. 109 * 110 * @retval Modem context or NULL. 111 */ 112 struct modem_context *modem_context_from_iface_dev(const struct device *dev); 113 114 /** 115 * @brief Registers modem context. 116 * 117 * @note Prepares modem context to be used. 118 * 119 * @param *ctx: modem context to register. 120 * 121 * @retval 0 if ok, < 0 if error. 122 */ 123 int modem_context_register(struct modem_context *ctx); 124 125 #ifdef __cplusplus 126 } 127 #endif 128 129 #endif /* ZEPHYR_INCLUDE_DRIVERS_MODEM_MODEM_CONTEXT_H_ */ 130