| 1 |
/* |
| 2 |
* Copyright (c) 2019, Intel Corporation |
| 3 |
* |
| 4 |
* Redistribution and use in source and binary forms, with or without |
| 5 |
* modification, are permitted provided that the following conditions are met: |
| 6 |
* |
| 7 |
* * Redistributions of source code must retain the above copyright notice, |
| 8 |
* this list of conditions and the following disclaimer. |
| 9 |
* * Redistributions in binary form must reproduce the above copyright |
| 10 |
* notice, this list of conditions and the following disclaimer in the |
| 11 |
* documentation and/or other materials provided with the distribution. |
| 12 |
* * Neither the name of Intel Corporation nor the names of its contributors |
| 13 |
* may be used to endorse or promote products derived from this software |
| 14 |
* without specific prior written permission. |
| 15 |
* |
| 16 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 17 |
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 18 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 19 |
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE |
| 20 |
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 21 |
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 22 |
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 23 |
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 24 |
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 25 |
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 |
*/ |
| 27 |
|
| 28 |
#include <stdint.h> |
| 29 |
|
| 30 |
/* Calculate AVTP presentation time based on current time and informed |
| 31 |
* max_transit_time. |
| 32 |
* @avtp_time: Pointer to variable which the calculated time should be saved. |
| 33 |
* @max_transit_time: Max transit time for the network |
| 34 |
* |
| 35 |
* Returns: |
| 36 |
* 0: Success. |
| 37 |
* -1: If could not get current time. |
| 38 |
*/ |
| 39 |
int calculate_avtp_time(uint32_t *avtp_time, uint32_t max_transit_time); |
| 40 |
|
| 41 |
/* Given an AVTP presentation time, retrieve correspondent time on |
| 42 |
* CLOCK_REALTIME. |
| 43 |
* @avtp_time: AVTP presentation time to be converted. |
| 44 |
* @ts: Pointer to struct timespec where obtained time should be saved. |
| 45 |
* |
| 46 |
* Returns: |
| 47 |
* 0: Success. |
| 48 |
* -1: If could not get CLOCK_REALTIME. |
| 49 |
*/ |
| 50 |
int get_presentation_time(uint64_t avtp_time, struct timespec *tspec); |
| 51 |
|
| 52 |
/* Create TSN socket to listen for incomimg packets. |
| 53 |
* @ifname: Network interface name where to create the socket. |
| 54 |
* @macaddr: Stream destination MAC address. |
| 55 |
* @protocol: Protocol to listen to. |
| 56 |
* |
| 57 |
* Returns: |
| 58 |
* >= 0: Socket file descriptor. Should be closed with close() when done. |
| 59 |
* -1: Could not create socket. |
| 60 |
*/ |
| 61 |
int create_listener_socket(char *ifname, uint8_t macaddr[], int protocol); |
| 62 |
|
| 63 |
/* Create TSN socket to send packets. |
| 64 |
* @priority: SO_PRIORITY to be set in socket. |
| 65 |
* |
| 66 |
* Returns: |
| 67 |
* >= 0: Socket file descriptor. Should be closed with close() when done. |
| 68 |
* -1: Could not create socket. |
| 69 |
*/ |
| 70 |
int create_talker_socket(int priority); |
| 71 |
|
| 72 |
/* Set struct sockaddr_ll with TSN and socket parameters, so it can be used |
| 73 |
* later on sendo() or bind() calls. |
| 74 |
* @fd: Socket file descriptor. |
| 75 |
* @ifname: Network interface name where to create the socket. |
| 76 |
* @macaddr: Stream destination MAC address. |
| 77 |
* @sk_addr: Pointer to struct sockaddr_ll to be set up. |
| 78 |
* @protocol: Protocol used. |
| 79 |
* |
| 80 |
* Returns: |
| 81 |
* 0: Success. |
| 82 |
* -1: Could not get interface index. |
| 83 |
*/ |
| 84 |
int setup_socket_address(int fd, const char *ifname, uint8_t macaddr[], |
| 85 |
int protocol, struct sockaddr_ll *sk_addr); |
| 86 |
|
| 87 |
/* Write data to standard output. |
| 88 |
* @data: Data to be written. |
| 89 |
* @len: Number of bytes to be written. |
| 90 |
* |
| 91 |
* Returns: |
| 92 |
* 0: Success. It's only reported when all data is successfully written. |
| 93 |
* -1: Could not write all data. |
| 94 |
*/ |
| 95 |
int present_data(uint8_t *data, size_t len); |
| 96 |
|
| 97 |
/* Arm a timerfd to go off on informed time. |
| 98 |
* @fd: File descriptor of the timer. |
| 99 |
* @tspec: When the time should go off. |
| 100 |
* |
| 101 |
* Returns: |
| 102 |
* 0: Success. |
| 103 |
* -1: Could not arm timer. |
| 104 |
*/ |
| 105 |
int arm_timer(int fd, struct timespec *tspec); |