Lines Matching refs:cmux

148 static uint32_t modem_cmux_get_receive_buf_length(struct modem_cmux *cmux)  in modem_cmux_get_receive_buf_length()  argument
150 return cmux->receive_buf_len; in modem_cmux_get_receive_buf_length()
153 static uint32_t modem_cmux_get_receive_buf_size(struct modem_cmux *cmux) in modem_cmux_get_receive_buf_size() argument
155 return cmux->receive_buf_size; in modem_cmux_get_receive_buf_size()
158 static uint32_t modem_cmux_get_transmit_buf_length(struct modem_cmux *cmux) in modem_cmux_get_transmit_buf_length() argument
160 return ring_buf_size_get(&cmux->transmit_rb); in modem_cmux_get_transmit_buf_length()
163 static uint32_t modem_cmux_get_transmit_buf_size(struct modem_cmux *cmux) in modem_cmux_get_transmit_buf_size() argument
165 return ring_buf_capacity_get(&cmux->transmit_rb); in modem_cmux_get_transmit_buf_size()
168 static void modem_cmux_init_buf_stats(struct modem_cmux *cmux) in modem_cmux_init_buf_stats() argument
172 size = modem_cmux_get_receive_buf_size(cmux); in modem_cmux_init_buf_stats()
173 modem_stats_buffer_init(&cmux->receive_buf_stats, "cmux_rx", size); in modem_cmux_init_buf_stats()
174 size = modem_cmux_get_transmit_buf_size(cmux); in modem_cmux_init_buf_stats()
175 modem_stats_buffer_init(&cmux->transmit_buf_stats, "cmux_tx", size); in modem_cmux_init_buf_stats()
178 static void modem_cmux_advertise_transmit_buf_stats(struct modem_cmux *cmux) in modem_cmux_advertise_transmit_buf_stats() argument
182 length = modem_cmux_get_transmit_buf_length(cmux); in modem_cmux_advertise_transmit_buf_stats()
183 modem_stats_buffer_advertise_length(&cmux->transmit_buf_stats, length); in modem_cmux_advertise_transmit_buf_stats()
186 static void modem_cmux_advertise_receive_buf_stats(struct modem_cmux *cmux) in modem_cmux_advertise_receive_buf_stats() argument
190 length = modem_cmux_get_receive_buf_length(cmux); in modem_cmux_advertise_receive_buf_stats()
191 modem_stats_buffer_advertise_length(&cmux->receive_buf_stats, length); in modem_cmux_advertise_receive_buf_stats()
238 static void modem_cmux_raise_event(struct modem_cmux *cmux, enum modem_cmux_event event) in modem_cmux_raise_event() argument
240 if (cmux->callback == NULL) { in modem_cmux_raise_event()
244 cmux->callback(cmux, event, cmux->user_data); in modem_cmux_raise_event()
250 struct modem_cmux *cmux = (struct modem_cmux *)user_data; in modem_cmux_bus_callback() local
254 k_work_schedule(&cmux->receive_work, K_NO_WAIT); in modem_cmux_bus_callback()
258 k_work_schedule(&cmux->transmit_work, K_NO_WAIT); in modem_cmux_bus_callback()
266 static uint16_t modem_cmux_transmit_frame(struct modem_cmux *cmux, in modem_cmux_transmit_frame() argument
275 space = ring_buf_space_get(&cmux->transmit_rb) - MODEM_CMUX_FRAME_SIZE_MAX; in modem_cmux_transmit_frame()
308 ring_buf_put(&cmux->transmit_rb, buf, buf_idx); in modem_cmux_transmit_frame()
311 ring_buf_put(&cmux->transmit_rb, frame->data, data_len); in modem_cmux_transmit_frame()
316 ring_buf_put(&cmux->transmit_rb, buf, 2); in modem_cmux_transmit_frame()
317 k_work_schedule(&cmux->transmit_work, K_NO_WAIT); in modem_cmux_transmit_frame()
321 static bool modem_cmux_transmit_cmd_frame(struct modem_cmux *cmux, in modem_cmux_transmit_cmd_frame() argument
327 k_mutex_lock(&cmux->transmit_rb_lock, K_FOREVER); in modem_cmux_transmit_cmd_frame()
328 space = ring_buf_space_get(&cmux->transmit_rb); in modem_cmux_transmit_cmd_frame()
331 k_mutex_unlock(&cmux->transmit_rb_lock); in modem_cmux_transmit_cmd_frame()
340 modem_cmux_transmit_frame(cmux, frame); in modem_cmux_transmit_cmd_frame()
341 k_mutex_unlock(&cmux->transmit_rb_lock); in modem_cmux_transmit_cmd_frame()
345 static int16_t modem_cmux_transmit_data_frame(struct modem_cmux *cmux, in modem_cmux_transmit_data_frame() argument
351 k_mutex_lock(&cmux->transmit_rb_lock, K_FOREVER); in modem_cmux_transmit_data_frame()
353 if (cmux->flow_control_on == false) { in modem_cmux_transmit_data_frame()
354 k_mutex_unlock(&cmux->transmit_rb_lock); in modem_cmux_transmit_data_frame()
358 space = ring_buf_space_get(&cmux->transmit_rb); in modem_cmux_transmit_data_frame()
368 k_mutex_unlock(&cmux->transmit_rb_lock); in modem_cmux_transmit_data_frame()
373 ret = modem_cmux_transmit_frame(cmux, frame); in modem_cmux_transmit_data_frame()
374 k_mutex_unlock(&cmux->transmit_rb_lock); in modem_cmux_transmit_data_frame()
378 static void modem_cmux_acknowledge_received_frame(struct modem_cmux *cmux) in modem_cmux_acknowledge_received_frame() argument
384 if (sizeof(data) < cmux->frame.data_len) { in modem_cmux_acknowledge_received_frame()
389 memcpy(&frame, &cmux->frame, sizeof(cmux->frame)); in modem_cmux_acknowledge_received_frame()
390 memcpy(data, cmux->frame.data, cmux->frame.data_len); in modem_cmux_acknowledge_received_frame()
391 modem_cmux_wrap_command(&command, data, cmux->frame.data_len); in modem_cmux_acknowledge_received_frame()
394 frame.data_len = cmux->frame.data_len; in modem_cmux_acknowledge_received_frame()
396 if (modem_cmux_transmit_cmd_frame(cmux, &frame) == false) { in modem_cmux_acknowledge_received_frame()
401 static void modem_cmux_on_msc_command(struct modem_cmux *cmux, struct modem_cmux_command *command) in modem_cmux_on_msc_command() argument
404 modem_cmux_acknowledge_received_frame(cmux); in modem_cmux_on_msc_command()
408 static void modem_cmux_on_fcon_command(struct modem_cmux *cmux) in modem_cmux_on_fcon_command() argument
410 k_mutex_lock(&cmux->transmit_rb_lock, K_FOREVER); in modem_cmux_on_fcon_command()
411 cmux->flow_control_on = true; in modem_cmux_on_fcon_command()
412 k_mutex_unlock(&cmux->transmit_rb_lock); in modem_cmux_on_fcon_command()
413 modem_cmux_acknowledge_received_frame(cmux); in modem_cmux_on_fcon_command()
416 static void modem_cmux_on_fcoff_command(struct modem_cmux *cmux) in modem_cmux_on_fcoff_command() argument
418 k_mutex_lock(&cmux->transmit_rb_lock, K_FOREVER); in modem_cmux_on_fcoff_command()
419 cmux->flow_control_on = false; in modem_cmux_on_fcoff_command()
420 k_mutex_unlock(&cmux->transmit_rb_lock); in modem_cmux_on_fcoff_command()
421 modem_cmux_acknowledge_received_frame(cmux); in modem_cmux_on_fcoff_command()
424 static void modem_cmux_on_cld_command(struct modem_cmux *cmux, struct modem_cmux_command *command) in modem_cmux_on_cld_command() argument
427 modem_cmux_acknowledge_received_frame(cmux); in modem_cmux_on_cld_command()
430 if (cmux->state != MODEM_CMUX_STATE_DISCONNECTING && in modem_cmux_on_cld_command()
431 cmux->state != MODEM_CMUX_STATE_CONNECTED) { in modem_cmux_on_cld_command()
436 if (cmux->state == MODEM_CMUX_STATE_DISCONNECTING) { in modem_cmux_on_cld_command()
437 k_work_cancel_delayable(&cmux->disconnect_work); in modem_cmux_on_cld_command()
440 cmux->state = MODEM_CMUX_STATE_DISCONNECTED; in modem_cmux_on_cld_command()
441 k_mutex_lock(&cmux->transmit_rb_lock, K_FOREVER); in modem_cmux_on_cld_command()
442 cmux->flow_control_on = false; in modem_cmux_on_cld_command()
443 k_mutex_unlock(&cmux->transmit_rb_lock); in modem_cmux_on_cld_command()
445 modem_cmux_raise_event(cmux, MODEM_CMUX_EVENT_DISCONNECTED); in modem_cmux_on_cld_command()
446 k_event_clear(&cmux->event, MODEM_CMUX_EVENT_CONNECTED_BIT); in modem_cmux_on_cld_command()
447 k_event_post(&cmux->event, MODEM_CMUX_EVENT_DISCONNECTED_BIT); in modem_cmux_on_cld_command()
450 static void modem_cmux_on_control_frame_ua(struct modem_cmux *cmux) in modem_cmux_on_control_frame_ua() argument
452 if (cmux->state != MODEM_CMUX_STATE_CONNECTING) { in modem_cmux_on_control_frame_ua()
457 cmux->state = MODEM_CMUX_STATE_CONNECTED; in modem_cmux_on_control_frame_ua()
458 k_mutex_lock(&cmux->transmit_rb_lock, K_FOREVER); in modem_cmux_on_control_frame_ua()
459 cmux->flow_control_on = true; in modem_cmux_on_control_frame_ua()
460 k_mutex_unlock(&cmux->transmit_rb_lock); in modem_cmux_on_control_frame_ua()
461 k_work_cancel_delayable(&cmux->connect_work); in modem_cmux_on_control_frame_ua()
462 modem_cmux_raise_event(cmux, MODEM_CMUX_EVENT_CONNECTED); in modem_cmux_on_control_frame_ua()
463 k_event_clear(&cmux->event, MODEM_CMUX_EVENT_DISCONNECTED_BIT); in modem_cmux_on_control_frame_ua()
464 k_event_post(&cmux->event, MODEM_CMUX_EVENT_CONNECTED_BIT); in modem_cmux_on_control_frame_ua()
467 static void modem_cmux_on_control_frame_uih(struct modem_cmux *cmux) in modem_cmux_on_control_frame_uih() argument
471 if ((cmux->state != MODEM_CMUX_STATE_CONNECTED) && in modem_cmux_on_control_frame_uih()
472 (cmux->state != MODEM_CMUX_STATE_DISCONNECTING)) { in modem_cmux_on_control_frame_uih()
477 if (modem_cmux_wrap_command(&command, cmux->frame.data, cmux->frame.data_len) < 0) { in modem_cmux_on_control_frame_uih()
486 modem_cmux_on_cld_command(cmux, command); in modem_cmux_on_control_frame_uih()
490 modem_cmux_on_msc_command(cmux, command); in modem_cmux_on_control_frame_uih()
494 modem_cmux_on_fcon_command(cmux); in modem_cmux_on_control_frame_uih()
498 modem_cmux_on_fcoff_command(cmux); in modem_cmux_on_control_frame_uih()
507 static void modem_cmux_connect_response_transmit(struct modem_cmux *cmux) in modem_cmux_connect_response_transmit() argument
509 if (cmux == NULL) { in modem_cmux_connect_response_transmit()
514 .dlci_address = cmux->frame.dlci_address, in modem_cmux_connect_response_transmit()
515 .cr = cmux->frame.cr, in modem_cmux_connect_response_transmit()
516 .pf = cmux->frame.pf, in modem_cmux_connect_response_transmit()
523 modem_cmux_transmit_cmd_frame(cmux, &frame); in modem_cmux_connect_response_transmit()
526 static void modem_cmux_on_control_frame_sabm(struct modem_cmux *cmux) in modem_cmux_on_control_frame_sabm() argument
528 modem_cmux_connect_response_transmit(cmux); in modem_cmux_on_control_frame_sabm()
530 if ((cmux->state == MODEM_CMUX_STATE_CONNECTED) || in modem_cmux_on_control_frame_sabm()
531 (cmux->state == MODEM_CMUX_STATE_DISCONNECTING)) { in modem_cmux_on_control_frame_sabm()
536 cmux->state = MODEM_CMUX_STATE_CONNECTED; in modem_cmux_on_control_frame_sabm()
537 k_mutex_lock(&cmux->transmit_rb_lock, K_FOREVER); in modem_cmux_on_control_frame_sabm()
538 cmux->flow_control_on = true; in modem_cmux_on_control_frame_sabm()
539 k_mutex_unlock(&cmux->transmit_rb_lock); in modem_cmux_on_control_frame_sabm()
540 modem_cmux_raise_event(cmux, MODEM_CMUX_EVENT_CONNECTED); in modem_cmux_on_control_frame_sabm()
541 k_event_clear(&cmux->event, MODEM_CMUX_EVENT_DISCONNECTED_BIT); in modem_cmux_on_control_frame_sabm()
542 k_event_post(&cmux->event, MODEM_CMUX_EVENT_CONNECTED_BIT); in modem_cmux_on_control_frame_sabm()
545 static void modem_cmux_on_control_frame(struct modem_cmux *cmux) in modem_cmux_on_control_frame() argument
547 modem_cmux_log_received_frame(&cmux->frame); in modem_cmux_on_control_frame()
549 switch (cmux->frame.type) { in modem_cmux_on_control_frame()
551 modem_cmux_on_control_frame_ua(cmux); in modem_cmux_on_control_frame()
555 modem_cmux_on_control_frame_uih(cmux); in modem_cmux_on_control_frame()
559 modem_cmux_on_control_frame_sabm(cmux); in modem_cmux_on_control_frame()
568 static struct modem_cmux_dlci *modem_cmux_find_dlci(struct modem_cmux *cmux) in modem_cmux_find_dlci() argument
573 SYS_SLIST_FOR_EACH_NODE(&cmux->dlcis, node) { in modem_cmux_find_dlci()
576 if (dlci->dlci_address == cmux->frame.dlci_address) { in modem_cmux_find_dlci()
610 struct modem_cmux *cmux = dlci->cmux; in modem_cmux_on_dlci_frame_uih() local
619 written = ring_buf_put(&dlci->receive_rb, cmux->frame.data, cmux->frame.data_len); in modem_cmux_on_dlci_frame_uih()
621 if (written != cmux->frame.data_len) { in modem_cmux_on_dlci_frame_uih()
623 dlci->dlci_address, cmux->frame.data_len - written, cmux->frame.data_len); in modem_cmux_on_dlci_frame_uih()
630 struct modem_cmux *cmux = dlci->cmux; in modem_cmux_on_dlci_frame_sabm() local
632 modem_cmux_connect_response_transmit(cmux); in modem_cmux_on_dlci_frame_sabm()
648 struct modem_cmux *cmux = dlci->cmux; in modem_cmux_on_dlci_frame_disc() local
650 modem_cmux_connect_response_transmit(cmux); in modem_cmux_on_dlci_frame_disc()
661 static void modem_cmux_on_dlci_frame(struct modem_cmux *cmux) in modem_cmux_on_dlci_frame() argument
665 modem_cmux_log_received_frame(&cmux->frame); in modem_cmux_on_dlci_frame()
667 dlci = modem_cmux_find_dlci(cmux); in modem_cmux_on_dlci_frame()
670 cmux->frame.dlci_address); in modem_cmux_on_dlci_frame()
674 switch (cmux->frame.type) { in modem_cmux_on_dlci_frame()
697 static void modem_cmux_on_frame(struct modem_cmux *cmux) in modem_cmux_on_frame() argument
700 modem_cmux_advertise_receive_buf_stats(cmux); in modem_cmux_on_frame()
703 if (cmux->frame.dlci_address == 0) { in modem_cmux_on_frame()
704 modem_cmux_on_control_frame(cmux); in modem_cmux_on_frame()
706 modem_cmux_on_dlci_frame(cmux); in modem_cmux_on_frame()
710 static void modem_cmux_drop_frame(struct modem_cmux *cmux) in modem_cmux_drop_frame() argument
713 modem_cmux_advertise_receive_buf_stats(cmux); in modem_cmux_drop_frame()
717 cmux->receive_state = MODEM_CMUX_RECEIVE_STATE_SOF; in modem_cmux_drop_frame()
720 struct modem_cmux_frame *frame = &cmux->frame; in modem_cmux_drop_frame()
722 frame->data = cmux->receive_buf; in modem_cmux_drop_frame()
723 modem_cmux_log_frame(frame, "dropped", MIN(frame->data_len, cmux->receive_buf_size)); in modem_cmux_drop_frame()
727 static void modem_cmux_process_received_byte(struct modem_cmux *cmux, uint8_t byte) in modem_cmux_process_received_byte() argument
731 switch (cmux->receive_state) { in modem_cmux_process_received_byte()
734 cmux->receive_state = MODEM_CMUX_RECEIVE_STATE_RESYNC; in modem_cmux_process_received_byte()
753 cmux->receive_buf_len = 0; in modem_cmux_process_received_byte()
754 cmux->frame_header_len = 0; in modem_cmux_process_received_byte()
757 cmux->frame_header[cmux->frame_header_len] = byte; in modem_cmux_process_received_byte()
758 cmux->frame_header_len++; in modem_cmux_process_received_byte()
761 cmux->frame.cr = (byte & 0x02) ? true : false; in modem_cmux_process_received_byte()
764 cmux->frame.dlci_address = (byte >> 2) & 0x3F; in modem_cmux_process_received_byte()
767 cmux->receive_state = MODEM_CMUX_RECEIVE_STATE_CONTROL; in modem_cmux_process_received_byte()
772 cmux->frame_header[cmux->frame_header_len] = byte; in modem_cmux_process_received_byte()
773 cmux->frame_header_len++; in modem_cmux_process_received_byte()
776 cmux->frame.pf = (byte & MODEM_CMUX_PF) ? true : false; in modem_cmux_process_received_byte()
779 cmux->frame.type = byte & (~MODEM_CMUX_PF); in modem_cmux_process_received_byte()
782 cmux->receive_state = MODEM_CMUX_RECEIVE_STATE_LENGTH; in modem_cmux_process_received_byte()
787 cmux->frame_header[cmux->frame_header_len] = byte; in modem_cmux_process_received_byte()
788 cmux->frame_header_len++; in modem_cmux_process_received_byte()
791 cmux->frame.data_len = (byte >> 1); in modem_cmux_process_received_byte()
796 cmux->receive_state = MODEM_CMUX_RECEIVE_STATE_LENGTH_CONT; in modem_cmux_process_received_byte()
801 if (cmux->frame.data_len == 0) { in modem_cmux_process_received_byte()
803 cmux->receive_state = MODEM_CMUX_RECEIVE_STATE_FCS; in modem_cmux_process_received_byte()
808 cmux->receive_state = MODEM_CMUX_RECEIVE_STATE_DATA; in modem_cmux_process_received_byte()
813 cmux->frame_header[cmux->frame_header_len] = byte; in modem_cmux_process_received_byte()
814 cmux->frame_header_len++; in modem_cmux_process_received_byte()
817 cmux->frame.data_len |= ((uint16_t)byte) << 7; in modem_cmux_process_received_byte()
819 if (cmux->frame.data_len > cmux->receive_buf_size) { in modem_cmux_process_received_byte()
821 cmux->frame.data_len, cmux->receive_buf_size); in modem_cmux_process_received_byte()
823 cmux->receive_state = MODEM_CMUX_RECEIVE_STATE_DROP; in modem_cmux_process_received_byte()
828 cmux->receive_state = MODEM_CMUX_RECEIVE_STATE_DATA; in modem_cmux_process_received_byte()
833 if (cmux->receive_buf_len < cmux->receive_buf_size) { in modem_cmux_process_received_byte()
834 cmux->receive_buf[cmux->receive_buf_len] = byte; in modem_cmux_process_received_byte()
836 cmux->receive_buf_len++; in modem_cmux_process_received_byte()
839 if (cmux->frame.data_len == cmux->receive_buf_len) { in modem_cmux_process_received_byte()
841 cmux->receive_state = MODEM_CMUX_RECEIVE_STATE_FCS; in modem_cmux_process_received_byte()
847 if (cmux->receive_buf_len > cmux->receive_buf_size) { in modem_cmux_process_received_byte()
849 cmux->receive_buf_len, cmux->receive_buf_size); in modem_cmux_process_received_byte()
850 cmux->receive_state = MODEM_CMUX_RECEIVE_STATE_DROP; in modem_cmux_process_received_byte()
855 fcs = crc8_rohc(MODEM_CMUX_FCS_INIT_VALUE, cmux->frame_header, in modem_cmux_process_received_byte()
856 cmux->frame_header_len); in modem_cmux_process_received_byte()
857 if (cmux->frame.type == MODEM_CMUX_FRAME_TYPE_UIH) { in modem_cmux_process_received_byte()
860 fcs = 0xFF - crc8_rohc(fcs, cmux->frame.data, cmux->frame.data_len); in modem_cmux_process_received_byte()
868 cmux->receive_state = MODEM_CMUX_RECEIVE_STATE_DROP; in modem_cmux_process_received_byte()
872 cmux->receive_state = MODEM_CMUX_RECEIVE_STATE_EOF; in modem_cmux_process_received_byte()
876 modem_cmux_drop_frame(cmux); in modem_cmux_process_received_byte()
883 modem_cmux_drop_frame(cmux); in modem_cmux_process_received_byte()
888 cmux->frame.data = cmux->receive_buf; in modem_cmux_process_received_byte()
889 modem_cmux_on_frame(cmux); in modem_cmux_process_received_byte()
892 cmux->receive_state = MODEM_CMUX_RECEIVE_STATE_SOF; in modem_cmux_process_received_byte()
903 struct modem_cmux *cmux = CONTAINER_OF(dwork, struct modem_cmux, receive_work); in modem_cmux_receive_handler() local
907 ret = modem_pipe_receive(cmux->pipe, cmux->work_buf, sizeof(cmux->work_buf)); in modem_cmux_receive_handler()
917 modem_cmux_process_received_byte(cmux, cmux->work_buf[i]); in modem_cmux_receive_handler()
921 k_work_schedule(&cmux->receive_work, K_NO_WAIT); in modem_cmux_receive_handler()
924 static void modem_cmux_dlci_notify_transmit_idle(struct modem_cmux *cmux) in modem_cmux_dlci_notify_transmit_idle() argument
929 SYS_SLIST_FOR_EACH_NODE(&cmux->dlcis, node) { in modem_cmux_dlci_notify_transmit_idle()
938 struct modem_cmux *cmux = CONTAINER_OF(dwork, struct modem_cmux, transmit_work); in modem_cmux_transmit_handler() local
944 k_mutex_lock(&cmux->transmit_rb_lock, K_FOREVER); in modem_cmux_transmit_handler()
947 modem_cmux_advertise_transmit_buf_stats(cmux); in modem_cmux_transmit_handler()
951 transmit_rb_empty = ring_buf_is_empty(&cmux->transmit_rb); in modem_cmux_transmit_handler()
957 reserved_size = ring_buf_get_claim(&cmux->transmit_rb, &reserved, UINT32_MAX); in modem_cmux_transmit_handler()
959 ret = modem_pipe_transmit(cmux->pipe, reserved, reserved_size); in modem_cmux_transmit_handler()
961 ring_buf_get_finish(&cmux->transmit_rb, 0); in modem_cmux_transmit_handler()
969 ring_buf_get_finish(&cmux->transmit_rb, (uint32_t)ret); in modem_cmux_transmit_handler()
977 k_mutex_unlock(&cmux->transmit_rb_lock); in modem_cmux_transmit_handler()
980 modem_cmux_dlci_notify_transmit_idle(cmux); in modem_cmux_transmit_handler()
987 struct modem_cmux *cmux; in modem_cmux_connect_handler() local
994 cmux = CONTAINER_OF(dwork, struct modem_cmux, connect_work); in modem_cmux_connect_handler()
996 cmux->state = MODEM_CMUX_STATE_CONNECTING; in modem_cmux_connect_handler()
1007 modem_cmux_transmit_cmd_frame(cmux, &frame); in modem_cmux_connect_handler()
1008 k_work_schedule(&cmux->connect_work, MODEM_CMUX_T1_TIMEOUT); in modem_cmux_connect_handler()
1014 struct modem_cmux *cmux = CONTAINER_OF(dwork, struct modem_cmux, disconnect_work); in modem_cmux_disconnect_handler() local
1018 cmux->state = MODEM_CMUX_STATE_DISCONNECTING; in modem_cmux_disconnect_handler()
1037 modem_cmux_transmit_cmd_frame(cmux, &frame); in modem_cmux_disconnect_handler()
1038 k_work_schedule(&cmux->disconnect_work, MODEM_CMUX_T1_TIMEOUT); in modem_cmux_disconnect_handler()
1074 struct modem_cmux *cmux = dlci->cmux; in modem_cmux_dlci_pipe_api_open() local
1077 K_SPINLOCK(&cmux->work_lock) { in modem_cmux_dlci_pipe_api_open()
1078 if (!cmux->attached) { in modem_cmux_dlci_pipe_api_open()
1097 struct modem_cmux *cmux = dlci->cmux; in modem_cmux_dlci_pipe_api_transmit() local
1100 K_SPINLOCK(&cmux->work_lock) { in modem_cmux_dlci_pipe_api_transmit()
1101 if (!cmux->attached) { in modem_cmux_dlci_pipe_api_transmit()
1115 ret = modem_cmux_transmit_data_frame(cmux, &frame); in modem_cmux_dlci_pipe_api_transmit()
1140 struct modem_cmux *cmux = dlci->cmux; in modem_cmux_dlci_pipe_api_close() local
1143 K_SPINLOCK(&cmux->work_lock) { in modem_cmux_dlci_pipe_api_close()
1144 if (!cmux->attached) { in modem_cmux_dlci_pipe_api_close()
1190 modem_cmux_transmit_cmd_frame(dlci->cmux, &frame); in modem_cmux_dlci_open_handler()
1198 struct modem_cmux *cmux; in modem_cmux_dlci_close_handler() local
1206 cmux = dlci->cmux; in modem_cmux_dlci_close_handler()
1219 modem_cmux_transmit_cmd_frame(cmux, &frame); in modem_cmux_dlci_close_handler()
1223 static void modem_cmux_dlci_pipes_release(struct modem_cmux *cmux) in modem_cmux_dlci_pipes_release() argument
1229 SYS_SLIST_FOR_EACH_NODE(&cmux->dlcis, node) { in modem_cmux_dlci_pipes_release()
1237 void modem_cmux_init(struct modem_cmux *cmux, const struct modem_cmux_config *config) in modem_cmux_init() argument
1239 __ASSERT_NO_MSG(cmux != NULL); in modem_cmux_init()
1246 memset(cmux, 0x00, sizeof(*cmux)); in modem_cmux_init()
1247 cmux->callback = config->callback; in modem_cmux_init()
1248 cmux->user_data = config->user_data; in modem_cmux_init()
1249 cmux->receive_buf = config->receive_buf; in modem_cmux_init()
1250 cmux->receive_buf_size = config->receive_buf_size; in modem_cmux_init()
1251 sys_slist_init(&cmux->dlcis); in modem_cmux_init()
1252 cmux->state = MODEM_CMUX_STATE_DISCONNECTED; in modem_cmux_init()
1253 ring_buf_init(&cmux->transmit_rb, config->transmit_buf_size, config->transmit_buf); in modem_cmux_init()
1254 k_mutex_init(&cmux->transmit_rb_lock); in modem_cmux_init()
1255 k_work_init_delayable(&cmux->receive_work, modem_cmux_receive_handler); in modem_cmux_init()
1256 k_work_init_delayable(&cmux->transmit_work, modem_cmux_transmit_handler); in modem_cmux_init()
1257 k_work_init_delayable(&cmux->connect_work, modem_cmux_connect_handler); in modem_cmux_init()
1258 k_work_init_delayable(&cmux->disconnect_work, modem_cmux_disconnect_handler); in modem_cmux_init()
1259 k_event_init(&cmux->event); in modem_cmux_init()
1260 k_event_clear(&cmux->event, MODEM_CMUX_EVENT_CONNECTED_BIT); in modem_cmux_init()
1261 k_event_post(&cmux->event, MODEM_CMUX_EVENT_DISCONNECTED_BIT); in modem_cmux_init()
1264 modem_cmux_init_buf_stats(cmux); in modem_cmux_init()
1268 struct modem_pipe *modem_cmux_dlci_init(struct modem_cmux *cmux, struct modem_cmux_dlci *dlci, in modem_cmux_dlci_init() argument
1271 __ASSERT_NO_MSG(cmux != NULL); in modem_cmux_dlci_init()
1279 dlci->cmux = cmux; in modem_cmux_dlci_init()
1287 sys_slist_append(&dlci->cmux->dlcis, &dlci->node); in modem_cmux_dlci_init()
1296 int modem_cmux_attach(struct modem_cmux *cmux, struct modem_pipe *pipe) in modem_cmux_attach() argument
1298 if (cmux->pipe != NULL) { in modem_cmux_attach()
1302 cmux->pipe = pipe; in modem_cmux_attach()
1303 ring_buf_reset(&cmux->transmit_rb); in modem_cmux_attach()
1304 cmux->receive_state = MODEM_CMUX_RECEIVE_STATE_SOF; in modem_cmux_attach()
1305 modem_pipe_attach(cmux->pipe, modem_cmux_bus_callback, cmux); in modem_cmux_attach()
1307 K_SPINLOCK(&cmux->work_lock) { in modem_cmux_attach()
1308 cmux->attached = true; in modem_cmux_attach()
1314 int modem_cmux_connect(struct modem_cmux *cmux) in modem_cmux_connect() argument
1318 ret = modem_cmux_connect_async(cmux); in modem_cmux_connect()
1323 if (k_event_wait(&cmux->event, MODEM_CMUX_EVENT_CONNECTED_BIT, false, in modem_cmux_connect()
1331 int modem_cmux_connect_async(struct modem_cmux *cmux) in modem_cmux_connect_async() argument
1335 if (k_event_test(&cmux->event, MODEM_CMUX_EVENT_CONNECTED_BIT)) { in modem_cmux_connect_async()
1339 K_SPINLOCK(&cmux->work_lock) { in modem_cmux_connect_async()
1340 if (!cmux->attached) { in modem_cmux_connect_async()
1345 if (k_work_delayable_is_pending(&cmux->connect_work) == false) { in modem_cmux_connect_async()
1346 k_work_schedule(&cmux->connect_work, K_NO_WAIT); in modem_cmux_connect_async()
1355 int modem_cmux_disconnect(struct modem_cmux *cmux) in modem_cmux_disconnect() argument
1359 ret = modem_cmux_disconnect_async(cmux); in modem_cmux_disconnect()
1364 if (k_event_wait(&cmux->event, MODEM_CMUX_EVENT_DISCONNECTED_BIT, false, in modem_cmux_disconnect()
1372 int modem_cmux_disconnect_async(struct modem_cmux *cmux) in modem_cmux_disconnect_async() argument
1376 if (k_event_test(&cmux->event, MODEM_CMUX_EVENT_DISCONNECTED_BIT)) { in modem_cmux_disconnect_async()
1380 K_SPINLOCK(&cmux->work_lock) { in modem_cmux_disconnect_async()
1381 if (!cmux->attached) { in modem_cmux_disconnect_async()
1386 if (k_work_delayable_is_pending(&cmux->disconnect_work) == false) { in modem_cmux_disconnect_async()
1387 k_work_schedule(&cmux->disconnect_work, K_NO_WAIT); in modem_cmux_disconnect_async()
1394 void modem_cmux_release(struct modem_cmux *cmux) in modem_cmux_release() argument
1398 if (cmux->pipe == NULL) { in modem_cmux_release()
1402 K_SPINLOCK(&cmux->work_lock) { in modem_cmux_release()
1403 cmux->attached = false; in modem_cmux_release()
1407 modem_cmux_dlci_pipes_release(cmux); in modem_cmux_release()
1410 if (cmux->pipe) { in modem_cmux_release()
1411 modem_pipe_release(cmux->pipe); in modem_cmux_release()
1415 k_work_cancel_delayable_sync(&cmux->connect_work, &sync); in modem_cmux_release()
1416 k_work_cancel_delayable_sync(&cmux->disconnect_work, &sync); in modem_cmux_release()
1417 k_work_cancel_delayable_sync(&cmux->transmit_work, &sync); in modem_cmux_release()
1418 k_work_cancel_delayable_sync(&cmux->receive_work, &sync); in modem_cmux_release()
1421 cmux->pipe = NULL; in modem_cmux_release()
1424 k_event_clear(&cmux->event, MODEM_CMUX_EVENT_CONNECTED_BIT); in modem_cmux_release()
1425 k_event_post(&cmux->event, MODEM_CMUX_EVENT_DISCONNECTED_BIT); in modem_cmux_release()