Lines Matching refs:port
82 static int port_msg_send(struct ptp_port *port, struct ptp_msg *msg, enum ptp_socket idx) in port_msg_send() argument
86 return ptp_transport_send(port, msg, idx); in port_msg_send()
117 static void port_synchronize(struct ptp_port *port, in port_synchronize() argument
131 port_timer_set_timeout(&port->timers.sync, in port_synchronize()
132 port->port_ds.announce_receipt_timeout, in port_synchronize()
133 port->port_ds.log_sync_interval); in port_synchronize()
136 static void port_ds_init(struct ptp_port *port) in port_ds_init() argument
138 struct ptp_port_ds *ds = &port->port_ds; in port_ds_init()
157 struct ptp_port *port = ptp_clock_port_from_iface(pkt->iface); in port_delay_req_timestamp_cb() local
161 if (!port || !msg) { in port_delay_req_timestamp_cb()
167 if (!ptp_port_id_eq(&port->port_ds.id, &msg->header.src_port_id) || in port_delay_req_timestamp_cb()
172 for (iter = sys_slist_peek_head(&port->delay_req_list); in port_delay_req_timestamp_cb()
184 net_if_unregister_timestamp_cb(&port->delay_req_ts_cb); in port_delay_req_timestamp_cb()
185 sys_slist_remove(&port->delay_req_list, last, iter); in port_delay_req_timestamp_cb()
195 port->port_ds.id.port_number, in port_delay_req_timestamp_cb()
198 if (iter == sys_slist_peek_tail(&port->delay_req_list)) { in port_delay_req_timestamp_cb()
199 net_if_unregister_timestamp_cb(&port->delay_req_ts_cb); in port_delay_req_timestamp_cb()
206 struct ptp_port *port = ptp_clock_port_from_iface(pkt->iface); in port_sync_timestamp_cb() local
209 if (!port || !msg) { in port_sync_timestamp_cb()
215 if (ptp_port_id_eq(&port->port_ds.id, &msg->header.src_port_id) && in port_sync_timestamp_cb()
231 resp->header.src_port_id = port->port_ds.id; in port_sync_timestamp_cb()
232 resp->header.sequence_id = port->seq_id.sync++; in port_sync_timestamp_cb()
233 resp->header.log_msg_interval = port->port_ds.log_sync_interval; in port_sync_timestamp_cb()
239 net_if_unregister_timestamp_cb(&port->sync_ts_cb); in port_sync_timestamp_cb()
241 port_msg_send(port, resp, PTP_SOCKET_GENERAL); in port_sync_timestamp_cb()
244 LOG_DBG("Port %d sends Follow_Up message", port->port_ds.id.port_number); in port_sync_timestamp_cb()
248 static int port_announce_msg_transmit(struct ptp_port *port) in port_announce_msg_transmit() argument
266 msg->header.src_port_id = port->port_ds.id; in port_announce_msg_transmit()
267 msg->header.sequence_id = port->seq_id.announce++; in port_announce_msg_transmit()
268 msg->header.log_msg_interval = port->port_ds.log_sync_interval; in port_announce_msg_transmit()
278 ret = port_msg_send(port, msg, PTP_SOCKET_GENERAL); in port_announce_msg_transmit()
285 LOG_DBG("Port %d sends Announce message", port->port_ds.id.port_number); in port_announce_msg_transmit()
289 static int port_delay_req_msg_transmit(struct ptp_port *port) in port_delay_req_msg_transmit() argument
303 msg->header.src_port_id = port->port_ds.id; in port_delay_req_msg_transmit()
304 msg->header.sequence_id = port->seq_id.delay++; in port_delay_req_msg_transmit()
307 net_if_register_timestamp_cb(&port->delay_req_ts_cb, in port_delay_req_msg_transmit()
309 port->iface, in port_delay_req_msg_transmit()
312 ret = port_msg_send(port, msg, PTP_SOCKET_EVENT); in port_delay_req_msg_transmit()
318 sys_slist_append(&port->delay_req_list, &msg->node); in port_delay_req_msg_transmit()
320 LOG_DBG("Port %d sends Delay_Req message", port->port_ds.id.port_number); in port_delay_req_msg_transmit()
324 static int port_sync_msg_transmit(struct ptp_port *port) in port_sync_msg_transmit() argument
341 msg->header.src_port_id = port->port_ds.id; in port_sync_msg_transmit()
342 msg->header.sequence_id = port->seq_id.sync; in port_sync_msg_transmit()
343 msg->header.log_msg_interval = port->port_ds.log_sync_interval; in port_sync_msg_transmit()
345 net_if_register_timestamp_cb(&port->sync_ts_cb, in port_sync_msg_transmit()
347 port->iface, in port_sync_msg_transmit()
350 ret = port_msg_send(port, msg, PTP_SOCKET_EVENT); in port_sync_msg_transmit()
356 LOG_DBG("Port %d sends Sync message", port->port_ds.id.port_number); in port_sync_msg_transmit()
368 struct ptp_port *port = (struct ptp_port *)k_timer_user_data_get(timer); in port_timer_to_handler() local
370 if (timer == &port->timers.announce) { in port_timer_to_handler()
371 atomic_set_bit(&port->timeouts, PTP_PORT_TIMER_ANNOUNCE_TO); in port_timer_to_handler()
372 } else if (timer == &port->timers.sync) { in port_timer_to_handler()
373 atomic_set_bit(&port->timeouts, PTP_PORT_TIMER_SYNC_TO); in port_timer_to_handler()
374 } else if (timer == &port->timers.delay) { in port_timer_to_handler()
375 atomic_set_bit(&port->timeouts, PTP_PORT_TIMER_DELAY_TO); in port_timer_to_handler()
376 } else if (timer == &port->timers.qualification) { in port_timer_to_handler()
377 atomic_set_bit(&port->timeouts, PTP_PORT_TIMER_QUALIFICATION_TO); in port_timer_to_handler()
437 static void port_delay_req_cleanup(struct ptp_port *port) in port_delay_req_cleanup() argument
443 SYS_SLIST_FOR_EACH_CONTAINER(&port->delay_req_list, msg, node) { in port_delay_req_cleanup()
452 sys_slist_remove(&port->delay_req_list, prev, &msg->node); in port_delay_req_cleanup()
457 static void port_clear_delay_req(struct ptp_port *port) in port_clear_delay_req() argument
462 SYS_SLIST_FOR_EACH_CONTAINER(&port->delay_req_list, msg, node) { in port_clear_delay_req()
464 sys_slist_remove(&port->delay_req_list, prev, &msg->node); in port_clear_delay_req()
469 static void port_sync_fup_ooo_handle(struct ptp_port *port, struct ptp_msg *msg) in port_sync_fup_ooo_handle() argument
471 struct ptp_msg *last = port->last_sync_fup; in port_sync_fup_ooo_handle()
479 port->last_sync_fup = msg; in port_sync_fup_ooo_handle()
488 port_synchronize(port, in port_sync_fup_ooo_handle()
494 ptp_msg_unref(port->last_sync_fup); in port_sync_fup_ooo_handle()
495 port->last_sync_fup = NULL; in port_sync_fup_ooo_handle()
500 port_synchronize(port, in port_sync_fup_ooo_handle()
506 ptp_msg_unref(port->last_sync_fup); in port_sync_fup_ooo_handle()
507 port->last_sync_fup = NULL; in port_sync_fup_ooo_handle()
509 ptp_msg_unref(port->last_sync_fup); in port_sync_fup_ooo_handle()
510 port->last_sync_fup = msg; in port_sync_fup_ooo_handle()
515 static int port_announce_msg_process(struct ptp_port *port, struct ptp_msg *msg) in port_announce_msg_process() argument
524 switch (ptp_port_state(port)) { in port_announce_msg_process()
539 ret = ptp_port_add_foreign_tt(port, msg); in port_announce_msg_process()
549 ret = ptp_port_update_current_time_transmitter(port, msg); in port_announce_msg_process()
558 static void port_sync_msg_process(struct ptp_port *port, struct ptp_msg *msg) in port_sync_msg_process() argument
560 enum ptp_port_state state = ptp_port_state(port); in port_sync_msg_process()
570 if (port->port_ds.log_sync_interval != msg->header.log_msg_interval) { in port_sync_msg_process()
571 port->port_ds.log_sync_interval = msg->header.log_msg_interval; in port_sync_msg_process()
574 msg->header.correction += port->port_ds.delay_asymmetry; in port_sync_msg_process()
577 port_synchronize(port, in port_sync_msg_process()
583 if (port->last_sync_fup) { in port_sync_msg_process()
584 ptp_msg_unref(port->last_sync_fup); in port_sync_msg_process()
585 port->last_sync_fup = NULL; in port_sync_msg_process()
591 port_sync_fup_ooo_handle(port, msg); in port_sync_msg_process()
594 static void port_follow_up_msg_process(struct ptp_port *port, struct ptp_msg *msg) in port_follow_up_msg_process() argument
596 enum ptp_port_state state = ptp_port_state(port); in port_follow_up_msg_process()
606 port_sync_fup_ooo_handle(port, msg); in port_follow_up_msg_process()
609 static int port_delay_req_msg_process(struct ptp_port *port, struct ptp_msg *msg) in port_delay_req_msg_process() argument
613 enum ptp_port_state state = ptp_port_state(port); in port_delay_req_msg_process()
630 resp->header.src_port_id = port->port_ds.id; in port_delay_req_msg_process()
632 resp->header.log_msg_interval = port->port_ds.log_min_delay_req_interval; in port_delay_req_msg_process()
644 ret = port_msg_send(port, resp, PTP_SOCKET_EVENT); in port_delay_req_msg_process()
651 LOG_DBG("Port %d responds to Delay_Req message", port->port_ds.id.port_number); in port_delay_req_msg_process()
655 static void port_delay_resp_msg_process(struct ptp_port *port, struct ptp_msg *msg) in port_delay_resp_msg_process() argument
660 enum ptp_port_state state = ptp_port_state(port); in port_delay_resp_msg_process()
666 if (!ptp_port_id_eq(&msg->delay_resp.req_port_id, &port->port_ds.id)) { in port_delay_resp_msg_process()
671 SYS_SLIST_FOR_EACH_CONTAINER(&port->delay_req_list, req, node) { in port_delay_resp_msg_process()
688 sys_slist_remove(&port->delay_req_list, prev, &req->node); in port_delay_resp_msg_process()
691 port->port_ds.log_min_delay_req_interval = msg->header.log_msg_interval; in port_delay_resp_msg_process()
694 static struct ptp_msg *port_management_resp_prepare(struct ptp_port *port, struct ptp_msg *req) in port_management_resp_prepare() argument
707 resp->header.src_port_id = port->port_ds.id; in port_management_resp_prepare()
709 resp->header.log_msg_interval = port->port_ds.log_min_delay_req_interval; in port_management_resp_prepare()
729 static int port_management_resp_tlv_fill(struct ptp_port *port, in port_management_resp_tlv_fill() argument
794 memcpy(mgmt->data, &port->port_ds, sizeof(struct ptp_tlv_port_ds)); in port_management_resp_tlv_fill()
813 length = sizeof(port->port_ds.log_announce_interval); in port_management_resp_tlv_fill()
814 *mgmt->data = port->port_ds.log_announce_interval; in port_management_resp_tlv_fill()
817 length = sizeof(port->port_ds.log_sync_interval); in port_management_resp_tlv_fill()
818 *mgmt->data = port->port_ds.log_sync_interval; in port_management_resp_tlv_fill()
821 length = sizeof(port->port_ds.version); in port_management_resp_tlv_fill()
822 *mgmt->data = port->port_ds.version; in port_management_resp_tlv_fill()
829 length = sizeof(port->port_ds.delay_mechanism); in port_management_resp_tlv_fill()
830 *(uint16_t *)mgmt->data = port->port_ds.delay_mechanism; in port_management_resp_tlv_fill()
850 static int port_management_set(struct ptp_port *port, in port_management_set() argument
858 port->port_ds.log_announce_interval = *tlv->data; in port_management_set()
862 port->port_ds.log_sync_interval = *tlv->data; in port_management_set()
872 return send_resp ? ptp_port_management_resp(port, req, tlv) : 0; in port_management_set()
875 static int port_enable(struct ptp_port *port) in port_enable() argument
877 while (!net_if_is_up(port->iface)) { in port_enable()
881 port->link_status = PORT_LINK_UP; in port_enable()
883 if (ptp_transport_open(port)) { in port_enable()
884 LOG_ERR("Couldn't open socket on Port %d.", port->port_ds.id.port_number); in port_enable()
888 port->port_ds.enable = true; in port_enable()
891 LOG_DBG("Port %d opened", port->port_ds.id.port_number); in port_enable()
895 static bool port_is_enabled(struct ptp_port *port) in port_is_enabled() argument
897 enum ptp_port_state state = ptp_port_state(port); in port_is_enabled()
907 static void port_disable(struct ptp_port *port) in port_disable() argument
909 k_timer_stop(&port->timers.announce); in port_disable()
910 k_timer_stop(&port->timers.delay); in port_disable()
911 k_timer_stop(&port->timers.sync); in port_disable()
912 k_timer_stop(&port->timers.qualification); in port_disable()
914 atomic_clear(&port->timeouts); in port_disable()
916 ptp_transport_close(port); in port_disable()
917 ptp_port_free_foreign_tts(port); in port_disable()
918 port->best = NULL; in port_disable()
920 net_if_unregister_timestamp_cb(&port->sync_ts_cb); in port_disable()
921 net_if_unregister_timestamp_cb(&port->delay_req_ts_cb); in port_disable()
924 port->port_ds.enable = false; in port_disable()
925 LOG_DBG("Port %d disabled", port->port_ds.id.port_number); in port_disable()
928 int port_state_update(struct ptp_port *port, enum ptp_port_event event, bool tt_diff) in port_state_update() argument
930 enum ptp_port_state next_state = port->state_machine(ptp_port_state(port), in port_state_update()
936 if (net_if_oper_state(port->iface) == NET_IF_OPER_UP) { in port_state_update()
937 next_state = port->state_machine(next_state, PTP_EVT_FAULT_CLEARED, false); in port_state_update()
942 if (port_is_enabled(port)) { in port_state_update()
943 port_disable(port); in port_state_update()
945 if (port_enable(port)) { in port_state_update()
950 next_state = port->state_machine(next_state, event, false); in port_state_update()
953 if (next_state != ptp_port_state(port)) { in port_state_update()
955 port->port_ds.id.port_number, in port_state_update()
956 port_state_str(ptp_port_state(port)), in port_state_update()
959 port->port_ds.state = next_state; in port_state_update()
973 struct ptp_port *port = ptp_clock_port_from_iface(iface); in port_link_monitor() local
976 if (!port) { in port_link_monitor()
980 if (iface_state & port->link_status) { in port_link_monitor()
981 port->link_status = iface_state; in port_link_monitor()
983 port->link_status = iface_state | PORT_LINK_CHANGED; in port_link_monitor()
985 port->port_ds.id.port_number, in port_link_monitor()
986 port->link_status & PORT_LINK_UP ? "up" : "down"); in port_link_monitor()
989 if (port->link_status & PORT_LINK_CHANGED) { in port_link_monitor()
992 port->link_status ^= PORT_LINK_CHANGED; in port_link_monitor()
995 if (port->link_status & PORT_LINK_DOWN) { in port_link_monitor()
999 ptp_port_event_handle(port, event, false); in port_link_monitor()
1004 struct ptp_port *port; in ptp_port_init() local
1018 port = &ports[dds->n_ports]; in ptp_port_init()
1020 port->iface = iface; in ptp_port_init()
1021 port->best = NULL; in ptp_port_init()
1022 port->socket[PTP_SOCKET_EVENT] = -1; in ptp_port_init()
1023 port->socket[PTP_SOCKET_GENERAL] = -1; in ptp_port_init()
1025 port->state_machine = dds->time_receiver_only ? ptp_tr_state_machine : ptp_state_machine; in ptp_port_init()
1026 port->last_sync_fup = NULL; in ptp_port_init()
1028 port_ds_init(port); in ptp_port_init()
1029 sys_slist_init(&port->foreign_list); in ptp_port_init()
1030 sys_slist_init(&port->delay_req_list); in ptp_port_init()
1032 port_timer_init(&port->timers.delay, port_timer_to_handler, port); in ptp_port_init()
1033 port_timer_init(&port->timers.announce, port_timer_to_handler, port); in ptp_port_init()
1034 port_timer_init(&port->timers.sync, port_timer_to_handler, port); in ptp_port_init()
1035 port_timer_init(&port->timers.qualification, port_timer_to_handler, port); in ptp_port_init()
1038 ptp_clock_port_add(port); in ptp_port_init()
1040 net_mgmt_init_event_callback(&port->link_cb, port_link_monitor, PORT_LINK_EVENT_MASK); in ptp_port_init()
1041 net_mgmt_add_event_callback(&port->link_cb); in ptp_port_init()
1043 LOG_DBG("Port %d initialized", port->port_ds.id.port_number); in ptp_port_init()
1046 enum ptp_port_event ptp_port_event_gen(struct ptp_port *port, int idx) in ptp_port_event_gen() argument
1061 cnt = ptp_transport_recv(port, msg, idx); in ptp_port_event_gen()
1068 ret = ptp_msg_post_recv(port, msg, cnt); in ptp_port_event_gen()
1074 if (ptp_port_id_eq(&msg->header.src_port_id, &port->port_ds.id)) { in ptp_port_event_gen()
1081 port_sync_msg_process(port, msg); in ptp_port_event_gen()
1084 if (port_delay_req_msg_process(port, msg)) { in ptp_port_event_gen()
1096 port_follow_up_msg_process(port, msg); in ptp_port_event_gen()
1099 port_delay_resp_msg_process(port, msg); in ptp_port_event_gen()
1102 if (port_announce_msg_process(port, msg)) { in ptp_port_event_gen()
1110 if (ptp_clock_management_msg_process(port, msg)) { in ptp_port_event_gen()
1122 void ptp_port_event_handle(struct ptp_port *port, enum ptp_port_event event, bool tt_diff) in ptp_port_event_handle() argument
1130 if (!port_state_update(port, event, tt_diff)) { in ptp_port_event_handle()
1135 k_timer_stop(&port->timers.announce); in ptp_port_event_handle()
1136 k_timer_stop(&port->timers.delay); in ptp_port_event_handle()
1137 k_timer_stop(&port->timers.sync); in ptp_port_event_handle()
1138 k_timer_stop(&port->timers.qualification); in ptp_port_event_handle()
1140 switch (port->port_ds.state) { in ptp_port_event_handle()
1146 port_disable(port); in ptp_port_event_handle()
1149 port_timer_set_timeout_random(&port->timers.announce, in ptp_port_event_handle()
1150 port->port_ds.announce_receipt_timeout, in ptp_port_event_handle()
1152 port->port_ds.log_announce_interval); in ptp_port_event_handle()
1155 port_timer_set_timeout(&port->timers.qualification, in ptp_port_event_handle()
1157 port->port_ds.log_announce_interval); in ptp_port_event_handle()
1162 port_timer_set_timeout(&port->timers.announce, in ptp_port_event_handle()
1164 port->port_ds.log_announce_interval); in ptp_port_event_handle()
1165 port_timer_set_timeout(&port->timers.sync, 1, port->port_ds.log_sync_interval); in ptp_port_event_handle()
1168 port_timer_set_timeout_random(&port->timers.announce, in ptp_port_event_handle()
1169 port->port_ds.announce_receipt_timeout, in ptp_port_event_handle()
1171 port->port_ds.log_announce_interval); in ptp_port_event_handle()
1174 if (port->last_sync_fup) { in ptp_port_event_handle()
1175 ptp_msg_unref(port->last_sync_fup); in ptp_port_event_handle()
1176 port->last_sync_fup = NULL; in ptp_port_event_handle()
1178 port_clear_delay_req(port); in ptp_port_event_handle()
1181 port_timer_set_timeout_random(&port->timers.announce, in ptp_port_event_handle()
1182 port->port_ds.announce_receipt_timeout, in ptp_port_event_handle()
1184 port->port_ds.log_announce_interval); in ptp_port_event_handle()
1185 port_timer_set_timeout_random(&port->timers.delay, in ptp_port_event_handle()
1188 port->port_ds.log_min_delay_req_interval); in ptp_port_event_handle()
1193 enum ptp_port_state ptp_port_state(struct ptp_port *port) in ptp_port_state() argument
1195 return (enum ptp_port_state)port->port_ds.state; in ptp_port_state()
1198 enum ptp_port_event ptp_port_timer_event_gen(struct ptp_port *port, struct k_timer *timer) in ptp_port_timer_event_gen() argument
1201 enum ptp_port_state state = ptp_port_state(port); in ptp_port_timer_event_gen()
1205 if (timer == &port->timers.qualification && in ptp_port_timer_event_gen()
1206 atomic_test_bit(&port->timeouts, PTP_PORT_TIMER_QUALIFICATION_TO)) { in ptp_port_timer_event_gen()
1207 LOG_DBG("Port %d Qualification timeout", port->port_ds.id.port_number); in ptp_port_timer_event_gen()
1208 atomic_clear_bit(&port->timeouts, PTP_PORT_TIMER_QUALIFICATION_TO); in ptp_port_timer_event_gen()
1216 if (timer == &port->timers.sync && in ptp_port_timer_event_gen()
1217 atomic_test_bit(&port->timeouts, PTP_PORT_TIMER_SYNC_TO)) { in ptp_port_timer_event_gen()
1218 LOG_DBG("Port %d TX Sync timeout", port->port_ds.id.port_number); in ptp_port_timer_event_gen()
1219 port_timer_set_timeout(&port->timers.sync, in ptp_port_timer_event_gen()
1221 port->port_ds.log_sync_interval); in ptp_port_timer_event_gen()
1222 atomic_clear_bit(&port->timeouts, PTP_PORT_TIMER_SYNC_TO); in ptp_port_timer_event_gen()
1224 return port_sync_msg_transmit(port) == 0 ? PTP_EVT_NONE : in ptp_port_timer_event_gen()
1228 if (timer == &port->timers.announce && in ptp_port_timer_event_gen()
1229 atomic_test_bit(&port->timeouts, PTP_PORT_TIMER_ANNOUNCE_TO)) { in ptp_port_timer_event_gen()
1231 port->port_ds.id.port_number); in ptp_port_timer_event_gen()
1232 port_timer_set_timeout(&port->timers.announce, in ptp_port_timer_event_gen()
1234 port->port_ds.log_announce_interval); in ptp_port_timer_event_gen()
1235 atomic_clear_bit(&port->timeouts, PTP_PORT_TIMER_ANNOUNCE_TO); in ptp_port_timer_event_gen()
1237 return port_announce_msg_transmit(port) == 0 ? PTP_EVT_NONE : in ptp_port_timer_event_gen()
1242 if (timer == &port->timers.delay && in ptp_port_timer_event_gen()
1243 atomic_test_bit(&port->timeouts, PTP_PORT_TIMER_DELAY_TO)) { in ptp_port_timer_event_gen()
1245 atomic_clear_bit(&port->timeouts, PTP_PORT_TIMER_DELAY_TO); in ptp_port_timer_event_gen()
1246 port_delay_req_cleanup(port); in ptp_port_timer_event_gen()
1247 port_timer_set_timeout(&port->timers.delay, in ptp_port_timer_event_gen()
1249 port->port_ds.log_announce_interval); in ptp_port_timer_event_gen()
1251 if (port_delay_req_msg_transmit(port) < 0) { in ptp_port_timer_event_gen()
1261 if ((timer == &port->timers.announce || timer == &port->timers.sync) && in ptp_port_timer_event_gen()
1262 (atomic_test_bit(&port->timeouts, PTP_PORT_TIMER_ANNOUNCE_TO) || in ptp_port_timer_event_gen()
1263 atomic_test_bit(&port->timeouts, PTP_PORT_TIMER_SYNC_TO))) { in ptp_port_timer_event_gen()
1266 port->port_ds.id.port_number, in ptp_port_timer_event_gen()
1267 timer == &port->timers.announce ? "Announce" : "RX Sync"); in ptp_port_timer_event_gen()
1269 atomic_clear_bit(&port->timeouts, PTP_PORT_TIMER_ANNOUNCE_TO); in ptp_port_timer_event_gen()
1270 atomic_clear_bit(&port->timeouts, PTP_PORT_TIMER_SYNC_TO); in ptp_port_timer_event_gen()
1272 if (port->best) { in ptp_port_timer_event_gen()
1273 port_clear_foreign_clock_records(port->best); in ptp_port_timer_event_gen()
1276 port_delay_req_cleanup(port); in ptp_port_timer_event_gen()
1277 port_timer_set_timeout_random(&port->timers.announce, in ptp_port_timer_event_gen()
1278 port->port_ds.announce_receipt_timeout, in ptp_port_timer_event_gen()
1280 port->port_ds.log_announce_interval); in ptp_port_timer_event_gen()
1297 struct ptp_dataset *ptp_port_best_foreign_ds(struct ptp_port *port) in ptp_port_best_foreign_ds() argument
1299 return port->best ? &port->best->dataset : NULL; in ptp_port_best_foreign_ds()
1302 struct ptp_foreign_tt_clock *ptp_port_best_foreign(struct ptp_port *port) in ptp_port_best_foreign() argument
1307 port->best = NULL; in ptp_port_best_foreign()
1309 if (port->port_ds.time_transmitter_only) { in ptp_port_best_foreign()
1313 SYS_SLIST_FOR_EACH_CONTAINER(&port->foreign_list, foreign, node) { in ptp_port_best_foreign()
1334 memcpy(&foreign->dataset.receiver, &port->port_ds.id, sizeof(port->port_ds.id)); in ptp_port_best_foreign()
1336 if (!port->best) { in ptp_port_best_foreign()
1337 port->best = foreign; in ptp_port_best_foreign()
1338 } else if (ptp_btca_ds_cmp(&foreign->dataset, &port->best->dataset)) { in ptp_port_best_foreign()
1339 port->best = foreign; in ptp_port_best_foreign()
1344 return port->best; in ptp_port_best_foreign()
1347 int ptp_port_add_foreign_tt(struct ptp_port *port, struct ptp_msg *msg) in ptp_port_add_foreign_tt() argument
1353 SYS_SLIST_FOR_EACH_CONTAINER(&port->foreign_list, foreign, node) { in ptp_port_add_foreign_tt()
1361 port->port_ds.id.port_number, in ptp_port_add_foreign_tt()
1376 foreign->port = port; in ptp_port_add_foreign_tt()
1378 sys_slist_append(&port->foreign_list, &foreign->node); in ptp_port_add_foreign_tt()
1398 void ptp_port_free_foreign_tts(struct ptp_port *port) in ptp_port_free_foreign_tts() argument
1403 while (!sys_slist_is_empty(&port->foreign_list)) { in ptp_port_free_foreign_tts()
1404 iter = sys_slist_get(&port->foreign_list); in ptp_port_free_foreign_tts()
1418 int ptp_port_update_current_time_transmitter(struct ptp_port *port, struct ptp_msg *msg) in ptp_port_update_current_time_transmitter() argument
1420 struct ptp_foreign_tt_clock *foreign = port->best; in ptp_port_update_current_time_transmitter()
1424 return ptp_port_add_foreign_tt(port, msg); in ptp_port_update_current_time_transmitter()
1433 port_timer_set_timeout_random(&port->timers.announce, in ptp_port_update_current_time_transmitter()
1434 port->port_ds.announce_receipt_timeout, in ptp_port_update_current_time_transmitter()
1436 port->port_ds.log_announce_interval); in ptp_port_update_current_time_transmitter()
1447 int ptp_port_management_msg_process(struct ptp_port *port, in ptp_port_management_msg_process() argument
1455 if (target_port != port->port_ds.id.port_number && target_port != 0xFFFF) { in ptp_port_management_msg_process()
1460 ret = port_management_set(port, msg, tlv); in ptp_port_management_msg_process()
1462 ret = ptp_port_management_resp(port, msg, tlv); in ptp_port_management_msg_process()
1468 int ptp_port_management_error(struct ptp_port *port, struct ptp_msg *msg, enum ptp_mgmt_err err) in ptp_port_management_error() argument
1475 struct ptp_msg *resp = port_management_resp_prepare(port, msg); in ptp_port_management_error()
1494 ret = port_msg_send(port, resp, PTP_SOCKET_GENERAL); in ptp_port_management_error()
1501 LOG_DBG("Port %d sends Menagement Error message", port->port_ds.id.port_number); in ptp_port_management_error()
1505 int ptp_port_management_resp(struct ptp_port *port, struct ptp_msg *req, struct ptp_tlv_mgmt *tlv) in ptp_port_management_resp() argument
1508 struct ptp_msg *resp = port_management_resp_prepare(port, req); in ptp_port_management_resp()
1514 ret = port_management_resp_tlv_fill(port, req, resp, tlv); in ptp_port_management_resp()
1519 ret = port_msg_send(port, resp, PTP_SOCKET_GENERAL); in ptp_port_management_resp()
1526 LOG_DBG("Port %d sends Menagement message response", port->port_ds.id.port_number); in ptp_port_management_resp()