Lines Matching refs:chat

32 static void modem_chat_log_received_command(struct modem_chat *chat)  in modem_chat_log_received_command()  argument
37 for (uint16_t i = 0; i < chat->argc; i++) { in modem_chat_log_received_command()
38 argv_len = (uint16_t)strlen(chat->argv[i]); in modem_chat_log_received_command()
47 memcpy(&log_buffer[log_buffer_pos], chat->argv[i], argv_len); in modem_chat_log_received_command()
62 static void modem_chat_log_received_command(struct modem_chat *chat) in modem_chat_log_received_command() argument
68 static void modem_chat_script_stop(struct modem_chat *chat, enum modem_chat_script_result result) in modem_chat_script_stop() argument
70 if ((chat == NULL) || (chat->script == NULL)) { in modem_chat_script_stop()
76 LOG_DBG("%s: complete", chat->script->name); in modem_chat_script_stop()
78 LOG_WRN("%s: aborted", chat->script->name); in modem_chat_script_stop()
80 LOG_WRN("%s: timed out", chat->script->name); in modem_chat_script_stop()
84 if (chat->script->callback != NULL) { in modem_chat_script_stop()
85 chat->script->callback(chat, result, chat->user_data); in modem_chat_script_stop()
89 if ((chat->parse_match != NULL) && in modem_chat_script_stop()
90 ((chat->parse_match_type == MODEM_CHAT_MATCHES_INDEX_ABORT) || in modem_chat_script_stop()
91 (chat->parse_match_type == MODEM_CHAT_MATCHES_INDEX_RESPONSE))) { in modem_chat_script_stop()
92 chat->parse_match = NULL; in modem_chat_script_stop()
93 chat->parse_match_len = 0; in modem_chat_script_stop()
97 chat->script = NULL; in modem_chat_script_stop()
100 chat->matches[MODEM_CHAT_MATCHES_INDEX_ABORT] = NULL; in modem_chat_script_stop()
101 chat->matches_size[MODEM_CHAT_MATCHES_INDEX_ABORT] = 0; in modem_chat_script_stop()
102 chat->matches[MODEM_CHAT_MATCHES_INDEX_RESPONSE] = NULL; in modem_chat_script_stop()
103 chat->matches_size[MODEM_CHAT_MATCHES_INDEX_RESPONSE] = 0; in modem_chat_script_stop()
106 k_work_cancel_delayable(&chat->script_timeout_work); in modem_chat_script_stop()
107 k_work_cancel(&chat->script_send_work); in modem_chat_script_stop()
108 k_work_cancel_delayable(&chat->script_send_timeout_work); in modem_chat_script_stop()
111 atomic_clear_bit(&chat->script_state, MODEM_CHAT_SCRIPT_STATE_RUNNING_BIT); in modem_chat_script_stop()
114 chat->script_result = result; in modem_chat_script_stop()
117 k_sem_give(&chat->script_stopped_sem); in modem_chat_script_stop()
120 static void modem_chat_set_script_send_state(struct modem_chat *chat, in modem_chat_set_script_send_state() argument
123 chat->script_send_pos = 0; in modem_chat_set_script_send_state()
124 chat->script_send_state = state; in modem_chat_set_script_send_state()
127 static void modem_chat_script_send(struct modem_chat *chat) in modem_chat_script_send() argument
129 modem_chat_set_script_send_state(chat, MODEM_CHAT_SCRIPT_SEND_STATE_REQUEST); in modem_chat_script_send()
130 k_work_submit(&chat->script_send_work); in modem_chat_script_send()
133 static void modem_chat_script_set_response_matches(struct modem_chat *chat) in modem_chat_script_set_response_matches() argument
136 &chat->script->script_chats[chat->script_chat_it]; in modem_chat_script_set_response_matches()
138 chat->matches[MODEM_CHAT_MATCHES_INDEX_RESPONSE] = script_chat->response_matches; in modem_chat_script_set_response_matches()
139 chat->matches_size[MODEM_CHAT_MATCHES_INDEX_RESPONSE] = script_chat->response_matches_size; in modem_chat_script_set_response_matches()
142 static void modem_chat_script_clear_response_matches(struct modem_chat *chat) in modem_chat_script_clear_response_matches() argument
144 chat->matches[MODEM_CHAT_MATCHES_INDEX_RESPONSE] = NULL; in modem_chat_script_clear_response_matches()
145 chat->matches_size[MODEM_CHAT_MATCHES_INDEX_RESPONSE] = 0; in modem_chat_script_clear_response_matches()
148 static bool modem_chat_script_chat_has_request(struct modem_chat *chat) in modem_chat_script_chat_has_request() argument
151 &chat->script->script_chats[chat->script_chat_it]; in modem_chat_script_chat_has_request()
156 static bool modem_chat_script_chat_has_matches(struct modem_chat *chat) in modem_chat_script_chat_has_matches() argument
159 &chat->script->script_chats[chat->script_chat_it]; in modem_chat_script_chat_has_matches()
164 static uint16_t modem_chat_script_chat_get_send_timeout(struct modem_chat *chat) in modem_chat_script_chat_get_send_timeout() argument
167 &chat->script->script_chats[chat->script_chat_it]; in modem_chat_script_chat_get_send_timeout()
172 static bool modem_chat_script_chat_has_send_timeout(struct modem_chat *chat) in modem_chat_script_chat_has_send_timeout() argument
174 return modem_chat_script_chat_get_send_timeout(chat) > 0; in modem_chat_script_chat_has_send_timeout()
177 static void modem_chat_script_chat_schedule_send_timeout(struct modem_chat *chat) in modem_chat_script_chat_schedule_send_timeout() argument
179 uint16_t timeout = modem_chat_script_chat_get_send_timeout(chat); in modem_chat_script_chat_schedule_send_timeout()
181 k_work_schedule(&chat->script_send_timeout_work, K_MSEC(timeout)); in modem_chat_script_chat_schedule_send_timeout()
184 static void modem_chat_script_next(struct modem_chat *chat, bool initial) in modem_chat_script_next() argument
191 chat->script_chat_it = 0; in modem_chat_script_next()
194 chat->script_chat_it++; in modem_chat_script_next()
198 if (chat->script_chat_it == chat->script->script_chats_size) { in modem_chat_script_next()
199 modem_chat_script_stop(chat, MODEM_CHAT_SCRIPT_RESULT_SUCCESS); in modem_chat_script_next()
204 LOG_DBG("%s: step: %u", chat->script->name, chat->script_chat_it); in modem_chat_script_next()
206 script_chat = &chat->script->script_chats[chat->script_chat_it]; in modem_chat_script_next()
209 if (modem_chat_script_chat_has_request(chat)) { in modem_chat_script_next()
211 modem_chat_script_clear_response_matches(chat); in modem_chat_script_next()
212 modem_chat_script_send(chat); in modem_chat_script_next()
213 } else if (modem_chat_script_chat_has_matches(chat)) { in modem_chat_script_next()
214 modem_chat_script_set_response_matches(chat); in modem_chat_script_next()
216 modem_chat_script_chat_schedule_send_timeout(chat); in modem_chat_script_next()
220 static void modem_chat_script_start(struct modem_chat *chat, const struct modem_chat_script *script) in modem_chat_script_start() argument
223 chat->script = script; in modem_chat_script_start()
226 chat->matches[MODEM_CHAT_MATCHES_INDEX_ABORT] = script->abort_matches; in modem_chat_script_start()
227 chat->matches_size[MODEM_CHAT_MATCHES_INDEX_ABORT] = script->abort_matches_size; in modem_chat_script_start()
229 LOG_DBG("running script: %s", chat->script->name); in modem_chat_script_start()
232 modem_chat_script_next(chat, true); in modem_chat_script_start()
235 if (chat->script != NULL) { in modem_chat_script_start()
236 k_work_schedule(&chat->script_timeout_work, K_SECONDS(chat->script->timeout)); in modem_chat_script_start()
242 struct modem_chat *chat = CONTAINER_OF(item, struct modem_chat, script_run_work); in modem_chat_script_run_handler() local
245 modem_chat_script_start(chat, chat->pending_script); in modem_chat_script_run_handler()
251 struct modem_chat *chat = CONTAINER_OF(dwork, struct modem_chat, script_timeout_work); in modem_chat_script_timeout_handler() local
254 modem_chat_script_stop(chat, MODEM_CHAT_SCRIPT_RESULT_TIMEOUT); in modem_chat_script_timeout_handler()
259 struct modem_chat *chat = CONTAINER_OF(item, struct modem_chat, script_abort_work); in modem_chat_script_abort_handler() local
262 if (chat->script == NULL) { in modem_chat_script_abort_handler()
267 modem_chat_script_stop(chat, MODEM_CHAT_SCRIPT_RESULT_ABORT); in modem_chat_script_abort_handler()
271 static bool modem_chat_send_script_request_part(struct modem_chat *chat) in modem_chat_send_script_request_part() argument
274 &chat->script->script_chats[chat->script_chat_it]; in modem_chat_send_script_request_part()
281 switch (chat->script_send_state) { in modem_chat_send_script_request_part()
283 request_part = (uint8_t *)(&script_chat->request[chat->script_send_pos]); in modem_chat_send_script_request_part()
288 request_part = (uint8_t *)(&chat->delimiter[chat->script_send_pos]); in modem_chat_send_script_request_part()
289 request_size = chat->delimiter_size; in modem_chat_send_script_request_part()
296 request_part_size = request_size - chat->script_send_pos; in modem_chat_send_script_request_part()
297 ret = modem_pipe_transmit(chat->pipe, request_part, request_part_size); in modem_chat_send_script_request_part()
305 chat->script_send_pos += (uint16_t)ret; in modem_chat_send_script_request_part()
308 return request_size <= chat->script_send_pos; in modem_chat_send_script_request_part()
313 struct modem_chat *chat = CONTAINER_OF(item, struct modem_chat, script_send_work); in modem_chat_script_send_handler() local
315 if (chat->script == NULL) { in modem_chat_script_send_handler()
319 switch (chat->script_send_state) { in modem_chat_script_send_handler()
324 if (!modem_chat_send_script_request_part(chat)) { in modem_chat_script_send_handler()
328 modem_chat_set_script_send_state(chat, MODEM_CHAT_SCRIPT_SEND_STATE_DELIMITER); in modem_chat_script_send_handler()
332 if (!modem_chat_send_script_request_part(chat)) { in modem_chat_script_send_handler()
336 modem_chat_set_script_send_state(chat, MODEM_CHAT_SCRIPT_SEND_STATE_IDLE); in modem_chat_script_send_handler()
340 if (modem_chat_script_chat_has_matches(chat)) { in modem_chat_script_send_handler()
341 modem_chat_script_set_response_matches(chat); in modem_chat_script_send_handler()
342 } else if (modem_chat_script_chat_has_send_timeout(chat)) { in modem_chat_script_send_handler()
343 modem_chat_script_chat_schedule_send_timeout(chat); in modem_chat_script_send_handler()
345 modem_chat_script_next(chat, false); in modem_chat_script_send_handler()
352 struct modem_chat *chat = CONTAINER_OF(dwork, struct modem_chat, script_send_timeout_work); in modem_chat_script_send_timeout_handler() local
355 if (chat->script == NULL) { in modem_chat_script_send_timeout_handler()
359 modem_chat_script_next(chat, false); in modem_chat_script_send_timeout_handler()
363 static uint32_t get_receive_buf_length(struct modem_chat *chat) in get_receive_buf_length() argument
365 return chat->receive_buf_len; in get_receive_buf_length()
368 static void advertise_receive_buf_stats(struct modem_chat *chat) in advertise_receive_buf_stats() argument
372 length = get_receive_buf_length(chat); in advertise_receive_buf_stats()
373 modem_stats_buffer_advertise_length(&chat->receive_buf_stats, length); in advertise_receive_buf_stats()
377 static void modem_chat_parse_reset(struct modem_chat *chat) in modem_chat_parse_reset() argument
380 advertise_receive_buf_stats(chat); in modem_chat_parse_reset()
384 chat->receive_buf_len = 0; in modem_chat_parse_reset()
385 chat->delimiter_match_len = 0; in modem_chat_parse_reset()
386 chat->argc = 0; in modem_chat_parse_reset()
387 chat->parse_match = NULL; in modem_chat_parse_reset()
391 static void modem_chat_parse_save_match(struct modem_chat *chat) in modem_chat_parse_save_match() argument
396 chat->parse_match_len = chat->receive_buf_len + 1; in modem_chat_parse_save_match()
399 argv = &chat->receive_buf[chat->receive_buf_size - chat->parse_match_len]; in modem_chat_parse_save_match()
402 memcpy(argv, &chat->receive_buf[0], chat->parse_match_len - 1); in modem_chat_parse_save_match()
405 chat->argv[chat->argc] = argv; in modem_chat_parse_save_match()
408 chat->receive_buf[chat->receive_buf_size - 1] = '\0'; in modem_chat_parse_save_match()
411 chat->argc++; in modem_chat_parse_save_match()
414 static bool modem_chat_match_matches_received(struct modem_chat *chat, in modem_chat_match_matches_received() argument
418 if ((match->match[i] == chat->receive_buf[i]) || in modem_chat_match_matches_received()
429 static bool modem_chat_parse_find_match(struct modem_chat *chat) in modem_chat_parse_find_match() argument
432 for (uint16_t i = 0; i < ARRAY_SIZE(chat->matches); i++) { in modem_chat_parse_find_match()
434 for (uint16_t u = 0; u < chat->matches_size[i]; u++) { in modem_chat_parse_find_match()
436 if (chat->matches[i][u].match_size != chat->receive_buf_len) { in modem_chat_parse_find_match()
441 if (modem_chat_match_matches_received(chat, &chat->matches[i][u]) == in modem_chat_parse_find_match()
447 chat->parse_match = &chat->matches[i][u]; in modem_chat_parse_find_match()
448 chat->parse_match_type = i; in modem_chat_parse_find_match()
456 static bool modem_chat_parse_is_separator(struct modem_chat *chat) in modem_chat_parse_is_separator() argument
458 for (uint16_t i = 0; i < chat->parse_match->separators_size; i++) { in modem_chat_parse_is_separator()
459 if ((chat->parse_match->separators[i]) == in modem_chat_parse_is_separator()
460 (chat->receive_buf[chat->receive_buf_len - 1])) { in modem_chat_parse_is_separator()
468 static bool modem_chat_parse_end_del_start(struct modem_chat *chat) in modem_chat_parse_end_del_start() argument
470 for (uint8_t i = 0; i < chat->delimiter_size; i++) { in modem_chat_parse_end_del_start()
471 if (chat->receive_buf[chat->receive_buf_len - 1] == chat->delimiter[i]) { in modem_chat_parse_end_del_start()
479 static bool modem_chat_parse_end_del_complete(struct modem_chat *chat) in modem_chat_parse_end_del_complete() argument
482 if (chat->receive_buf_len < chat->delimiter_size) { in modem_chat_parse_end_del_complete()
487 return (memcmp(&chat->receive_buf[chat->receive_buf_len - chat->delimiter_size], in modem_chat_parse_end_del_complete()
488 chat->delimiter, chat->delimiter_size) == 0) in modem_chat_parse_end_del_complete()
493 static void modem_chat_on_command_received_unsol(struct modem_chat *chat) in modem_chat_on_command_received_unsol() argument
496 if (chat->parse_match->callback != NULL) { in modem_chat_on_command_received_unsol()
497 chat->parse_match->callback(chat, (char **)chat->argv, chat->argc, chat->user_data); in modem_chat_on_command_received_unsol()
501 static void modem_chat_on_command_received_abort(struct modem_chat *chat) in modem_chat_on_command_received_abort() argument
504 if (chat->parse_match->callback != NULL) { in modem_chat_on_command_received_abort()
505 chat->parse_match->callback(chat, (char **)chat->argv, chat->argc, chat->user_data); in modem_chat_on_command_received_abort()
509 modem_chat_script_stop(chat, MODEM_CHAT_SCRIPT_RESULT_ABORT); in modem_chat_on_command_received_abort()
512 static void modem_chat_on_command_received_resp(struct modem_chat *chat) in modem_chat_on_command_received_resp() argument
515 if (chat->parse_match->callback != NULL) { in modem_chat_on_command_received_resp()
516 chat->parse_match->callback(chat, (char **)chat->argv, chat->argc, chat->user_data); in modem_chat_on_command_received_resp()
520 if (chat->parse_match->partial) { in modem_chat_on_command_received_resp()
525 modem_chat_script_next(chat, false); in modem_chat_on_command_received_resp()
528 static bool modem_chat_parse_find_catch_all_match(struct modem_chat *chat) in modem_chat_parse_find_catch_all_match() argument
531 for (uint16_t i = 0; i < ARRAY_SIZE(chat->matches); i++) { in modem_chat_parse_find_catch_all_match()
533 for (uint16_t u = 0; u < chat->matches_size[i]; u++) { in modem_chat_parse_find_catch_all_match()
535 if (chat->matches[i][u].match_size == 0) { in modem_chat_parse_find_catch_all_match()
536 chat->parse_match = &chat->matches[i][u]; in modem_chat_parse_find_catch_all_match()
537 chat->parse_match_type = i; in modem_chat_parse_find_catch_all_match()
546 static void modem_chat_on_command_received(struct modem_chat *chat) in modem_chat_on_command_received() argument
548 modem_chat_log_received_command(chat); in modem_chat_on_command_received()
550 switch (chat->parse_match_type) { in modem_chat_on_command_received()
552 modem_chat_on_command_received_unsol(chat); in modem_chat_on_command_received()
556 modem_chat_on_command_received_abort(chat); in modem_chat_on_command_received()
560 modem_chat_on_command_received_resp(chat); in modem_chat_on_command_received()
565 static void modem_chat_on_unknown_command_received(struct modem_chat *chat) in modem_chat_on_unknown_command_received() argument
568 chat->receive_buf[chat->receive_buf_len - chat->delimiter_size] = '\0'; in modem_chat_on_unknown_command_received()
571 if (modem_chat_parse_find_catch_all_match(chat) == false) { in modem_chat_on_unknown_command_received()
572 LOG_DBG("%s", chat->receive_buf); in modem_chat_on_unknown_command_received()
577 chat->argv[0] = ""; in modem_chat_on_unknown_command_received()
578 chat->argv[1] = chat->receive_buf; in modem_chat_on_unknown_command_received()
579 chat->argc = 2; in modem_chat_on_unknown_command_received()
581 modem_chat_on_command_received(chat); in modem_chat_on_unknown_command_received()
584 static void modem_chat_process_byte(struct modem_chat *chat, uint8_t byte) in modem_chat_process_byte() argument
587 if (chat->receive_buf_size == chat->receive_buf_len) { in modem_chat_process_byte()
589 modem_chat_parse_reset(chat); in modem_chat_process_byte()
594 if (chat->argc == chat->argv_size) { in modem_chat_process_byte()
596 modem_chat_parse_reset(chat); in modem_chat_process_byte()
601 chat->receive_buf[chat->receive_buf_len] = byte; in modem_chat_process_byte()
602 chat->receive_buf_len++; in modem_chat_process_byte()
605 if (modem_chat_parse_end_del_complete(chat) == true) { in modem_chat_process_byte()
607 if (chat->receive_buf_len == chat->delimiter_size) { in modem_chat_process_byte()
609 modem_chat_parse_reset(chat); in modem_chat_process_byte()
614 if (chat->parse_match == NULL) { in modem_chat_process_byte()
616 modem_chat_on_unknown_command_received(chat); in modem_chat_process_byte()
619 modem_chat_parse_reset(chat); in modem_chat_process_byte()
624 if (chat->parse_arg_len > 0) { in modem_chat_process_byte()
625 chat->argv[chat->argc] = in modem_chat_process_byte()
626 &chat->receive_buf[chat->receive_buf_len - chat->delimiter_size - in modem_chat_process_byte()
627 chat->parse_arg_len]; in modem_chat_process_byte()
628 chat->receive_buf[chat->receive_buf_len - chat->delimiter_size] = '\0'; in modem_chat_process_byte()
629 chat->argc++; in modem_chat_process_byte()
633 modem_chat_on_command_received(chat); in modem_chat_process_byte()
636 modem_chat_parse_reset(chat); in modem_chat_process_byte()
641 if (modem_chat_parse_end_del_start(chat) == true) { in modem_chat_process_byte()
646 if (chat->parse_match == NULL) { in modem_chat_process_byte()
648 if (modem_chat_parse_find_match(chat) == false) { in modem_chat_process_byte()
653 modem_chat_parse_save_match(chat); in modem_chat_process_byte()
656 chat->parse_arg_len = 0; in modem_chat_process_byte()
661 if (modem_chat_parse_is_separator(chat) == true) { in modem_chat_process_byte()
663 if (chat->parse_arg_len == 0) { in modem_chat_process_byte()
665 chat->argv[chat->argc] = ""; in modem_chat_process_byte()
668 chat->argv[chat->argc] = in modem_chat_process_byte()
669 &chat->receive_buf[chat->receive_buf_len - chat->parse_arg_len - 1]; in modem_chat_process_byte()
672 chat->receive_buf[chat->receive_buf_len - 1] = '\0'; in modem_chat_process_byte()
676 chat->argc++; in modem_chat_process_byte()
679 chat->parse_arg_len = 0; in modem_chat_process_byte()
684 chat->parse_arg_len++; in modem_chat_process_byte()
687 static bool modem_chat_discard_byte(struct modem_chat *chat, uint8_t byte) in modem_chat_discard_byte() argument
689 for (uint8_t i = 0; i < chat->filter_size; i++) { in modem_chat_discard_byte()
690 if (byte == chat->filter[i]) { in modem_chat_discard_byte()
699 static void modem_chat_process_bytes(struct modem_chat *chat) in modem_chat_process_bytes() argument
701 for (uint16_t i = 0; i < chat->work_buf_len; i++) { in modem_chat_process_bytes()
702 if (modem_chat_discard_byte(chat, chat->work_buf[i])) { in modem_chat_process_bytes()
706 modem_chat_process_byte(chat, chat->work_buf[i]); in modem_chat_process_bytes()
711 static uint32_t get_work_buf_length(struct modem_chat *chat) in get_work_buf_length() argument
713 return chat->work_buf_len; in get_work_buf_length()
716 static void advertise_work_buf_stats(struct modem_chat *chat) in advertise_work_buf_stats() argument
720 length = get_work_buf_length(chat); in advertise_work_buf_stats()
721 modem_stats_buffer_advertise_length(&chat->work_buf_stats, length); in advertise_work_buf_stats()
727 struct modem_chat *chat = CONTAINER_OF(item, struct modem_chat, receive_work); in modem_chat_process_handler() local
731 ret = modem_pipe_receive(chat->pipe, chat->work_buf, sizeof(chat->work_buf)); in modem_chat_process_handler()
737 chat->work_buf_len = (size_t)ret; in modem_chat_process_handler()
740 advertise_work_buf_stats(chat); in modem_chat_process_handler()
744 modem_chat_process_bytes(chat); in modem_chat_process_handler()
745 k_work_submit(&chat->receive_work); in modem_chat_process_handler()
751 struct modem_chat *chat = (struct modem_chat *)user_data; in modem_chat_pipe_callback() local
755 k_work_submit(&chat->receive_work); in modem_chat_pipe_callback()
759 k_work_submit(&chat->script_send_work); in modem_chat_pipe_callback()
774 static uint32_t get_receive_buf_size(struct modem_chat *chat) in get_receive_buf_size() argument
776 return chat->receive_buf_size; in get_receive_buf_size()
779 static uint32_t get_work_buf_size(struct modem_chat *chat) in get_work_buf_size() argument
781 return sizeof(chat->work_buf); in get_work_buf_size()
784 static void init_buf_stats(struct modem_chat *chat) in init_buf_stats() argument
788 size = get_receive_buf_size(chat); in init_buf_stats()
789 modem_stats_buffer_init(&chat->receive_buf_stats, "chat_rx", size); in init_buf_stats()
790 size = get_work_buf_size(chat); in init_buf_stats()
791 modem_stats_buffer_init(&chat->work_buf_stats, "chat_work", size); in init_buf_stats()
795 int modem_chat_init(struct modem_chat *chat, const struct modem_chat_config *config) in modem_chat_init() argument
797 __ASSERT_NO_MSG(chat != NULL); in modem_chat_init()
808 memset(chat, 0x00, sizeof(*chat)); in modem_chat_init()
809 chat->pipe = NULL; in modem_chat_init()
810 chat->user_data = config->user_data; in modem_chat_init()
811 chat->receive_buf = config->receive_buf; in modem_chat_init()
812 chat->receive_buf_size = config->receive_buf_size; in modem_chat_init()
813 chat->argv = config->argv; in modem_chat_init()
814 chat->argv_size = config->argv_size; in modem_chat_init()
815 chat->delimiter = config->delimiter; in modem_chat_init()
816 chat->delimiter_size = config->delimiter_size; in modem_chat_init()
817 chat->filter = config->filter; in modem_chat_init()
818 chat->filter_size = config->filter_size; in modem_chat_init()
819 chat->matches[MODEM_CHAT_MATCHES_INDEX_UNSOL] = config->unsol_matches; in modem_chat_init()
820 chat->matches_size[MODEM_CHAT_MATCHES_INDEX_UNSOL] = config->unsol_matches_size; in modem_chat_init()
821 atomic_set(&chat->script_state, 0); in modem_chat_init()
822 k_sem_init(&chat->script_stopped_sem, 0, 1); in modem_chat_init()
823 k_work_init(&chat->receive_work, modem_chat_process_handler); in modem_chat_init()
824 k_work_init(&chat->script_run_work, modem_chat_script_run_handler); in modem_chat_init()
825 k_work_init_delayable(&chat->script_timeout_work, modem_chat_script_timeout_handler); in modem_chat_init()
826 k_work_init(&chat->script_abort_work, modem_chat_script_abort_handler); in modem_chat_init()
827 k_work_init(&chat->script_send_work, modem_chat_script_send_handler); in modem_chat_init()
828 k_work_init_delayable(&chat->script_send_timeout_work, in modem_chat_init()
832 init_buf_stats(chat); in modem_chat_init()
838 int modem_chat_attach(struct modem_chat *chat, struct modem_pipe *pipe) in modem_chat_attach() argument
840 chat->pipe = pipe; in modem_chat_attach()
841 modem_chat_parse_reset(chat); in modem_chat_attach()
842 modem_pipe_attach(chat->pipe, modem_chat_pipe_callback, chat); in modem_chat_attach()
846 int modem_chat_run_script_async(struct modem_chat *chat, const struct modem_chat_script *script) in modem_chat_run_script_async() argument
850 if (chat->pipe == NULL) { in modem_chat_run_script_async()
874 atomic_test_and_set_bit(&chat->script_state, MODEM_CHAT_SCRIPT_STATE_RUNNING_BIT); in modem_chat_run_script_async()
880 k_sem_reset(&chat->script_stopped_sem); in modem_chat_run_script_async()
882 chat->pending_script = script; in modem_chat_run_script_async()
883 k_work_submit(&chat->script_run_work); in modem_chat_run_script_async()
887 int modem_chat_run_script(struct modem_chat *chat, const struct modem_chat_script *script) in modem_chat_run_script() argument
891 ret = modem_chat_run_script_async(chat, script); in modem_chat_run_script()
896 ret = k_sem_take(&chat->script_stopped_sem, K_FOREVER); in modem_chat_run_script()
901 return (chat->script_result == MODEM_CHAT_SCRIPT_RESULT_SUCCESS) ? 0 : -EAGAIN; in modem_chat_run_script()
904 void modem_chat_script_abort(struct modem_chat *chat) in modem_chat_script_abort() argument
906 k_work_submit(&chat->script_abort_work); in modem_chat_script_abort()
909 void modem_chat_release(struct modem_chat *chat) in modem_chat_release() argument
913 if (chat->pipe) { in modem_chat_release()
914 modem_pipe_release(chat->pipe); in modem_chat_release()
917 k_work_cancel_sync(&chat->script_run_work, &sync); in modem_chat_release()
918 k_work_cancel_sync(&chat->script_abort_work, &sync); in modem_chat_release()
919 k_work_cancel_sync(&chat->receive_work, &sync); in modem_chat_release()
920 k_work_cancel_sync(&chat->script_send_work, &sync); in modem_chat_release()
922 chat->pipe = NULL; in modem_chat_release()
923 chat->receive_buf_len = 0; in modem_chat_release()
924 chat->work_buf_len = 0; in modem_chat_release()
925 chat->argc = 0; in modem_chat_release()
926 chat->script = NULL; in modem_chat_release()
927 chat->script_chat_it = 0; in modem_chat_release()
928 atomic_set(&chat->script_state, 0); in modem_chat_release()
929 chat->script_result = MODEM_CHAT_SCRIPT_RESULT_ABORT; in modem_chat_release()
930 k_sem_reset(&chat->script_stopped_sem); in modem_chat_release()
931 chat->script_send_state = MODEM_CHAT_SCRIPT_SEND_STATE_IDLE; in modem_chat_release()
932 chat->script_send_pos = 0; in modem_chat_release()
933 chat->parse_match = NULL; in modem_chat_release()
934 chat->parse_match_len = 0; in modem_chat_release()
935 chat->parse_arg_len = 0; in modem_chat_release()
936 chat->matches[MODEM_CHAT_MATCHES_INDEX_ABORT] = NULL; in modem_chat_release()
937 chat->matches_size[MODEM_CHAT_MATCHES_INDEX_ABORT] = 0; in modem_chat_release()
938 chat->matches[MODEM_CHAT_MATCHES_INDEX_RESPONSE] = NULL; in modem_chat_release()
939 chat->matches_size[MODEM_CHAT_MATCHES_INDEX_RESPONSE] = 0; in modem_chat_release()