Lines Matching refs:cfg
22 uint16_t modem_socket_next_packet_size(struct modem_socket_config *cfg, struct modem_socket *sock) in modem_socket_next_packet_size() argument
26 k_sem_take(&cfg->sem_lock, K_FOREVER); in modem_socket_next_packet_size()
35 k_sem_give(&cfg->sem_lock); in modem_socket_next_packet_size()
72 int modem_socket_packet_size_update(struct modem_socket_config *cfg, struct modem_socket *sock, in modem_socket_packet_size_update() argument
81 k_sem_take(&cfg->sem_lock, K_FOREVER); in modem_socket_packet_size_update()
92 k_sem_give(&cfg->sem_lock); in modem_socket_packet_size_update()
120 k_sem_give(&cfg->sem_lock); in modem_socket_packet_size_update()
128 k_sem_give(&cfg->sem_lock); in modem_socket_packet_size_update()
138 k_sem_give(&cfg->sem_lock); in modem_socket_packet_size_update()
150 int modem_socket_get(struct modem_socket_config *cfg, int family, int type, int proto) in modem_socket_get() argument
154 k_sem_take(&cfg->sem_lock, K_FOREVER); in modem_socket_get()
156 for (i = 0; i < cfg->sockets_len; i++) { in modem_socket_get()
157 if (cfg->sockets[i].id < cfg->base_socket_id) { in modem_socket_get()
162 if (i >= cfg->sockets_len) { in modem_socket_get()
163 k_sem_give(&cfg->sem_lock); in modem_socket_get()
167 cfg->sockets[i].sock_fd = zvfs_reserve_fd(); in modem_socket_get()
168 if (cfg->sockets[i].sock_fd < 0) { in modem_socket_get()
169 k_sem_give(&cfg->sem_lock); in modem_socket_get()
173 cfg->sockets[i].family = family; in modem_socket_get()
174 cfg->sockets[i].type = type; in modem_socket_get()
175 cfg->sockets[i].ip_proto = proto; in modem_socket_get()
176 cfg->sockets[i].id = (cfg->assign_id) ? (i + cfg->base_socket_id) : in modem_socket_get()
177 (cfg->base_socket_id + cfg->sockets_len); in modem_socket_get()
178 zvfs_finalize_typed_fd(cfg->sockets[i].sock_fd, &cfg->sockets[i], in modem_socket_get()
179 (const struct fd_op_vtable *)cfg->vtable, ZVFS_MODE_IFSOCK); in modem_socket_get()
181 k_sem_give(&cfg->sem_lock); in modem_socket_get()
182 return cfg->sockets[i].sock_fd; in modem_socket_get()
185 struct modem_socket *modem_socket_from_fd(struct modem_socket_config *cfg, int sock_fd) in modem_socket_from_fd() argument
189 k_sem_take(&cfg->sem_lock, K_FOREVER); in modem_socket_from_fd()
191 for (i = 0; i < cfg->sockets_len; i++) { in modem_socket_from_fd()
192 if (cfg->sockets[i].sock_fd == sock_fd) { in modem_socket_from_fd()
193 k_sem_give(&cfg->sem_lock); in modem_socket_from_fd()
194 return &cfg->sockets[i]; in modem_socket_from_fd()
198 k_sem_give(&cfg->sem_lock); in modem_socket_from_fd()
203 struct modem_socket *modem_socket_from_id(struct modem_socket_config *cfg, int id) in modem_socket_from_id() argument
207 if (id < cfg->base_socket_id) { in modem_socket_from_id()
211 k_sem_take(&cfg->sem_lock, K_FOREVER); in modem_socket_from_id()
213 for (i = 0; i < cfg->sockets_len; i++) { in modem_socket_from_id()
214 if (cfg->sockets[i].id == id) { in modem_socket_from_id()
215 k_sem_give(&cfg->sem_lock); in modem_socket_from_id()
216 return &cfg->sockets[i]; in modem_socket_from_id()
220 k_sem_give(&cfg->sem_lock); in modem_socket_from_id()
225 struct modem_socket *modem_socket_from_newid(struct modem_socket_config *cfg) in modem_socket_from_newid() argument
227 return modem_socket_from_id(cfg, cfg->base_socket_id + cfg->sockets_len); in modem_socket_from_newid()
230 void modem_socket_put(struct modem_socket_config *cfg, int sock_fd) in modem_socket_put() argument
232 struct modem_socket *sock = modem_socket_from_fd(cfg, sock_fd); in modem_socket_put()
238 k_sem_take(&cfg->sem_lock, K_FOREVER); in modem_socket_put()
240 sock->id = cfg->base_socket_id - 1; in modem_socket_put()
251 k_sem_give(&cfg->sem_lock); in modem_socket_put()
265 int modem_socket_poll(struct modem_socket_config *cfg, struct zsock_pollfd *fds, int nfds, in modem_socket_poll() argument
272 if (!cfg || nfds > CONFIG_ZVFS_POLL_MAX) { in modem_socket_poll()
279 sock = modem_socket_from_fd(cfg, fds[i].fd); in modem_socket_poll()
313 sock = modem_socket_from_fd(cfg, fds[i].fd); in modem_socket_poll()
341 int modem_socket_poll_prepare(struct modem_socket_config *cfg, struct modem_socket *sock, in modem_socket_poll_prepare() argument
392 void modem_socket_wait_data(struct modem_socket_config *cfg, struct modem_socket *sock) in modem_socket_wait_data() argument
394 k_sem_take(&cfg->sem_lock, K_FOREVER); in modem_socket_wait_data()
396 k_sem_give(&cfg->sem_lock); in modem_socket_wait_data()
401 void modem_socket_data_ready(struct modem_socket_config *cfg, struct modem_socket *sock) in modem_socket_data_ready() argument
403 k_sem_take(&cfg->sem_lock, K_FOREVER); in modem_socket_data_ready()
411 k_sem_give(&cfg->sem_lock); in modem_socket_data_ready()
414 int modem_socket_init(struct modem_socket_config *cfg, struct modem_socket *sockets, in modem_socket_init() argument
419 if (cfg == NULL || sockets == NULL || sockets_len < 1 || vtable == NULL) { in modem_socket_init()
424 cfg->sockets = sockets; in modem_socket_init()
425 cfg->sockets_len = sockets_len; in modem_socket_init()
426 cfg->base_socket_id = base_socket_id; in modem_socket_init()
427 cfg->assign_id = assign_id; in modem_socket_init()
428 k_sem_init(&cfg->sem_lock, 1, 1); in modem_socket_init()
429 cfg->vtable = vtable; in modem_socket_init()
432 for (int i = 0; i < cfg->sockets_len; i++) { in modem_socket_init()
434 memset(&cfg->sockets[i], 0, sizeof(cfg->sockets[i])); in modem_socket_init()
437 k_sem_init(&cfg->sockets[i].sem_data_ready, 0, 1); in modem_socket_init()
438 k_poll_signal_init(&cfg->sockets[i].sig_data_ready); in modem_socket_init()
439 cfg->sockets[i].id = -1; in modem_socket_init()
444 bool modem_socket_is_allocated(const struct modem_socket_config *cfg, in modem_socket_is_allocated() argument
448 if (cfg->assign_id == false && sock->id == (cfg->base_socket_id + cfg->sockets_len)) { in modem_socket_is_allocated()
453 return modem_socket_id_is_assigned(cfg, sock); in modem_socket_is_allocated()
456 bool modem_socket_id_is_assigned(const struct modem_socket_config *cfg, in modem_socket_id_is_assigned() argument
460 if ((cfg->base_socket_id <= sock->id) && in modem_socket_id_is_assigned()
461 (sock->id < (cfg->base_socket_id + cfg->sockets_len))) { in modem_socket_id_is_assigned()
467 int modem_socket_id_assign(const struct modem_socket_config *cfg, in modem_socket_id_assign() argument
471 if (cfg->assign_id) { in modem_socket_id_assign()
476 if (modem_socket_id_is_assigned(cfg, sock)) { in modem_socket_id_assign()
481 if (id < cfg->base_socket_id || (cfg->base_socket_id + cfg->sockets_len) <= id) { in modem_socket_id_assign()