Lines Matching refs:msg

24 static const char *msg_type_str(struct ptp_msg *msg)  in msg_type_str()  argument
26 switch (ptp_msg_type(msg)) { in msg_type_str()
52 static void msg_timestamp_post_recv(struct ptp_msg *msg, struct ptp_timestamp *ts) in msg_timestamp_post_recv() argument
54 msg->timestamp.protocol._sec.high = net_ntohs(ts->seconds_high); in msg_timestamp_post_recv()
55 msg->timestamp.protocol._sec.low = net_ntohl(ts->seconds_low); in msg_timestamp_post_recv()
56 msg->timestamp.protocol.nanosecond = net_ntohl(ts->nanoseconds); in msg_timestamp_post_recv()
101 static uint8_t *msg_suffix(struct ptp_msg *msg) in msg_suffix() argument
105 switch (ptp_msg_type(msg)) { in msg_suffix()
107 suffix = msg->sync.suffix; in msg_suffix()
110 suffix = msg->delay_req.suffix; in msg_suffix()
113 suffix = msg->pdelay_req.suffix; in msg_suffix()
116 suffix = msg->pdelay_resp.suffix; in msg_suffix()
119 suffix = msg->follow_up.suffix; in msg_suffix()
122 suffix = msg->delay_resp.suffix; in msg_suffix()
125 suffix = msg->pdelay_resp_follow_up.suffix; in msg_suffix()
128 suffix = msg->announce.suffix; in msg_suffix()
131 suffix = msg->signaling.suffix; in msg_suffix()
134 suffix = msg->management.suffix; in msg_suffix()
141 static int msg_tlv_post_recv(struct ptp_msg *msg, int length) in msg_tlv_post_recv() argument
145 uint8_t *suffix = msg_suffix(msg); in msg_tlv_post_recv()
189 sys_slist_append(&msg->tlvs, &tlv_container->node); in msg_tlv_post_recv()
195 static void msg_tlv_free(struct ptp_msg *msg) in msg_tlv_free() argument
199 for (sys_snode_t *iter = sys_slist_get(&msg->tlvs); in msg_tlv_free()
201 iter = sys_slist_get(&msg->tlvs)) { in msg_tlv_free()
207 static void msg_tlv_pre_send(struct ptp_msg *msg) in msg_tlv_pre_send() argument
211 SYS_SLIST_FOR_EACH_CONTAINER(&msg->tlvs, tlv_container, node) { in msg_tlv_pre_send()
216 msg_tlv_free(msg); in msg_tlv_pre_send()
221 struct ptp_msg *msg = NULL; in ptp_msg_alloc() local
222 int ret = k_mem_slab_alloc(&msg_slab, (void **)&msg, K_FOREVER); in ptp_msg_alloc()
229 memset(msg, 0, sizeof(*msg)); in ptp_msg_alloc()
230 sys_slist_init(&msg->tlvs); in ptp_msg_alloc()
231 atomic_inc(&msg->ref); in ptp_msg_alloc()
233 return msg; in ptp_msg_alloc()
236 void ptp_msg_unref(struct ptp_msg *msg) in ptp_msg_unref() argument
238 __ASSERT_NO_MSG(msg != NULL); in ptp_msg_unref()
240 atomic_t val = atomic_dec(&msg->ref); in ptp_msg_unref()
246 msg_tlv_free(msg); in ptp_msg_unref()
247 k_mem_slab_free(&msg_slab, (void *)msg); in ptp_msg_unref()
250 void ptp_msg_ref(struct ptp_msg *msg) in ptp_msg_ref() argument
252 __ASSERT_NO_MSG(msg != NULL); in ptp_msg_ref()
254 atomic_inc(&msg->ref); in ptp_msg_ref()
257 enum ptp_msg_type ptp_msg_type(const struct ptp_msg *msg) in ptp_msg_type() argument
259 return (enum ptp_msg_type)(msg->header.type_major_sdo_id & 0xF); in ptp_msg_type()
268 struct ptp_msg *msg; in ptp_msg_from_pkt() local
301 msg = (struct ptp_msg *)((uintptr_t)hdr + NET_UDPH_LEN); in ptp_msg_from_pkt()
303 if (payload == net_ntohs(msg->header.msg_length)) { in ptp_msg_from_pkt()
304 return msg; in ptp_msg_from_pkt()
310 void ptp_msg_pre_send(struct ptp_msg *msg) in ptp_msg_pre_send() argument
314 msg_header_pre_send(&msg->header); in ptp_msg_pre_send()
316 switch (ptp_msg_type(msg)) { in ptp_msg_pre_send()
322 msg->timestamp.host.second = (uint64_t)(current / MSEC_PER_SEC); in ptp_msg_pre_send()
323 msg->timestamp.host.nanosecond = (current % MSEC_PER_SEC) * NSEC_PER_MSEC; in ptp_msg_pre_send()
328 msg_timestamp_pre_send(&msg->pdelay_resp.req_receipt_timestamp); in ptp_msg_pre_send()
329 msg_port_id_pre_send(&msg->pdelay_resp.req_port_id); in ptp_msg_pre_send()
332 msg_timestamp_pre_send(&msg->follow_up.precise_origin_timestamp); in ptp_msg_pre_send()
335 msg_timestamp_pre_send(&msg->delay_resp.receive_timestamp); in ptp_msg_pre_send()
336 msg_port_id_pre_send(&msg->delay_resp.req_port_id); in ptp_msg_pre_send()
339 msg_timestamp_pre_send(&msg->pdelay_resp_follow_up.resp_origin_timestamp); in ptp_msg_pre_send()
340 msg_port_id_pre_send(&msg->pdelay_resp_follow_up.req_port_id); in ptp_msg_pre_send()
343 msg->announce.current_utc_offset = net_htons(msg->announce.current_utc_offset); in ptp_msg_pre_send()
344 msg->announce.gm_clk_quality.offset_scaled_log_variance = in ptp_msg_pre_send()
345 net_htons(msg->announce.gm_clk_quality.offset_scaled_log_variance); in ptp_msg_pre_send()
346 msg->announce.steps_rm = net_htons(msg->announce.steps_rm); in ptp_msg_pre_send()
349 msg_port_id_pre_send(&msg->signaling.target_port_id); in ptp_msg_pre_send()
352 msg_port_id_pre_send(&msg->management.target_port_id); in ptp_msg_pre_send()
356 msg_tlv_pre_send(msg); in ptp_msg_pre_send()
359 int ptp_msg_post_recv(struct ptp_port *port, struct ptp_msg *msg, int cnt) in ptp_msg_post_recv() argument
373 enum ptp_msg_type type = ptp_msg_type(msg); in ptp_msg_post_recv()
382 if (msg_header_post_recv(&msg->header)) { in ptp_msg_post_recv()
387 LOG_DBG("Port %d received %s message", port->port_ds.id.port_number, msg_type_str(msg)); in ptp_msg_post_recv()
391 msg_timestamp_post_recv(msg, &msg->sync.origin_timestamp); in ptp_msg_post_recv()
398 msg_timestamp_post_recv(msg, &msg->pdelay_resp.req_receipt_timestamp); in ptp_msg_post_recv()
399 msg_port_id_post_recv(&msg->pdelay_resp.req_port_id); in ptp_msg_post_recv()
402 msg_timestamp_post_recv(msg, &msg->follow_up.precise_origin_timestamp); in ptp_msg_post_recv()
405 msg_timestamp_post_recv(msg, &msg->delay_resp.receive_timestamp); in ptp_msg_post_recv()
406 msg_port_id_post_recv(&msg->delay_resp.req_port_id); in ptp_msg_post_recv()
409 msg_timestamp_post_recv(msg, &msg->pdelay_resp_follow_up.resp_origin_timestamp); in ptp_msg_post_recv()
410 msg_port_id_post_recv(&msg->pdelay_resp_follow_up.req_port_id); in ptp_msg_post_recv()
415 msg->timestamp.host.second = (uint64_t)(current / MSEC_PER_SEC); in ptp_msg_post_recv()
416 msg->timestamp.host.nanosecond = (current % MSEC_PER_SEC) * NSEC_PER_MSEC; in ptp_msg_post_recv()
417 msg_timestamp_post_recv(msg, &msg->announce.origin_timestamp); in ptp_msg_post_recv()
418 msg->announce.current_utc_offset = net_ntohs(msg->announce.current_utc_offset); in ptp_msg_post_recv()
419 msg->announce.gm_clk_quality.offset_scaled_log_variance = in ptp_msg_post_recv()
420 net_ntohs(msg->announce.gm_clk_quality.offset_scaled_log_variance); in ptp_msg_post_recv()
421 msg->announce.steps_rm = net_ntohs(msg->announce.steps_rm); in ptp_msg_post_recv()
424 msg_port_id_post_recv(&msg->signaling.target_port_id); in ptp_msg_post_recv()
427 msg_port_id_post_recv(&msg->management.target_port_id); in ptp_msg_post_recv()
431 tlv_len = msg_tlv_post_recv(msg, cnt - msg_size[type]); in ptp_msg_post_recv()
437 if (msg_size[type] + tlv_len != msg->header.msg_length) { in ptp_msg_post_recv()
445 struct ptp_tlv *ptp_msg_add_tlv(struct ptp_msg *msg, int length) in ptp_msg_add_tlv() argument
448 uint8_t *suffix = msg_suffix(msg); in ptp_msg_add_tlv()
454 tlv_container = (struct ptp_tlv_container *)sys_slist_peek_tail(&msg->tlvs); in ptp_msg_add_tlv()
461 if ((intptr_t)(suffix + length) >= (intptr_t)&msg->ref) { in ptp_msg_add_tlv()
469 msg->header.msg_length += length; in ptp_msg_add_tlv()
484 bool ptp_msg_current_parent(const struct ptp_msg *msg) in ptp_msg_current_parent() argument
488 return ptp_port_id_eq(&pds->port_id, &msg->header.src_port_id); in ptp_msg_current_parent()