summaryrefslogtreecommitdiff
path: root/lib/avtp_pipeline/endpoint/openavb_endpoint.h
blob: 9e6708ae8f45e41589e21df8a4e26390eef5b49c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
/*************************************************************************************************************
Copyright (c) 2012-2015, Symphony Teleca Corporation, a Harman International Industries, Incorporated company
Copyright (c) 2016-2017, Harman International Industries, Incorporated
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
   list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
   this list of conditions and the following disclaimer in the documentation
   and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS LISTED "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS LISTED BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Attributions: The inih library portion of the source code is licensed from
Brush Technology and Ben Hoyt - Copyright (c) 2009, Brush Technology and Copyright (c) 2009, Ben Hoyt.
Complete license and copyright information can be found at
https://github.com/benhoyt/inih/commit/74d2ca064fb293bc60a77b0bd068075b293cf175.
*************************************************************************************************************/

/*
* HEADER SUMMARY : Declarations used by the endpoint code.
*/

#ifndef OPENAVB_ENDPOINT_H
#define OPENAVB_ENDPOINT_H

#include "openavb_types.h"
#include "openavb_srp_api.h"
#include "openavb_endpoint_cfg.h"
#include "openavb_tl.h"

#define AVB_ENDPOINT_HANDLE_INVALID (-1)
#define ENDPOINT_RECONNECT_SECONDS 	10
#define AVB_ENDPOINT_UNIX_PATH 		"/tmp/avb_endpoint"

typedef enum {
	clientNone,
	clientTalker,
	clientListener
} clientRole_t;


bool openavbEptClntService(int h, int timeout);
void openavbEptSrvrService(void);
int avbEndpointLoop(void);


typedef enum {
	// client messages
	OPENAVB_ENDPOINT_TALKER_REGISTER,
	OPENAVB_ENDPOINT_LISTENER_ATTACH,
	OPENAVB_ENDPOINT_CLIENT_STOP,
	OPENAVB_ENDPOINT_VERSION_REQUEST,

	// server messages
	OPENAVB_ENDPOINT_TALKER_CALLBACK,
	OPENAVB_ENDPOINT_LISTENER_CALLBACK,
	OPENAVB_ENDPOINT_VERSION_CALLBACK,
} openavbEndpointMsgType_t;

//////////////////////////////
// Client message parameters
//////////////////////////////
typedef struct {
	U8 			destAddr[ETH_ALEN];
	AVBTSpec_t	tSpec;
	U8			srClass;
	U8	        srRank;
	U32			latency;
	U32			txRate;
} openavbEndpointParams_TalkerRegister_t;

typedef struct {
	openavbSrpLsnrDeclSubtype_t lsnrDecl;
} openavbEndpointParams_ListenerAttach_t;

typedef struct {
} openavbEndpointParams_ClientStop_t;

typedef struct {
} openavbEndpointParams_VersionRequest_t;

//////////////////////////////
// Server messages parameters
//////////////////////////////
typedef struct {
	char		ifname[IFNAMSIZ + 10]; // Include space for the socket type prefix (e.g. "simple:eth0")
	U8 			destAddr[ETH_ALEN];
	openavbSrpLsnrDeclSubtype_t lsnrDecl;
	U32			classRate;
	U16			vlanID;
	U8			priority;
	U16			fwmark;
} openavbEndpointParams_TalkerCallback_t;

typedef struct {
	openavbSrpAttribType_t tlkrDecl;
	char		ifname[IFNAMSIZ + 10]; // Include space for the socket type prefix (e.g. "simple:eth0")
	U8 			destAddr[ETH_ALEN];
	AVBTSpec_t	tSpec;
	U8			srClass;
	U32			latency;
	openavbSrpFailInfo_t failInfo;
} openavbEndpointParams_ListenerCallback_t;

typedef struct {
	U32 		AVBVersion;
} openavbEndpointParams_VersionCallback_t;

#define OPENAVB_ENDPOINT_MSG_LEN sizeof(openavbEndpointMessage_t)

typedef struct clientStream_t {
	struct clientStream_t *next; // next link list pointer

	int				clientHandle;		// ID that links this info to client (talker or listener)

	// Information provided by the client (talker or listener)
	AVBStreamID_t	streamID;			// stream identifier
	clientRole_t	role;				// is client a talker or listener?

	// Information provided by the client (talker)
	AVBTSpec_t 		tSpec;				// traffic specification (bandwidth for reservation)
	SRClassIdx_t	srClass;			// AVB class
	U8 				srRank;				// AVB rank
	U32				latency;			// internal latency
	U32				txRate;				// frames per second

	// Information provided by SRP
	U8				priority;			// AVB priority to use for stream
	U16				vlanID;				// VLAN ID to use for stream
	U32				classRate;			// observation intervals per second

	// Information provided by MAAP
	void			*hndMaap;			// handle for MAAP address allocation
	U8				destAddr[ETH_ALEN];	// destination MAC address (from config or MAAP)

	// Information provided by Shaper
	void			*hndShaper;			// handle for Shaping configuration

	// Information provided by QMgr
	int				fwmark;				// mark to identify packets of this stream
} clientStream_t;

int startPTP(void);
int stopPTP(void);

bool openavbEndpointServerOpen(void);
void openavbEndpointServerClose(void);
clientStream_t* findStream(AVBStreamID_t *streamID);
void delStream(clientStream_t* ps);
clientStream_t* addStream(int h, AVBStreamID_t *streamID);
void openavbEndPtLogAllStaticStreams(void);
bool x_talkerDeregister(clientStream_t *ps);
bool x_listenerDetach(clientStream_t *ps);


openavbRC strmRegCb(void *pv,
						  openavbSrpAttribType_t tlkrDecl,
						  U8 destAddr[],
						  AVBTSpec_t *tSpec,
						  SRClassIdx_t srClass,
						  U32 accumLatency,
						  openavbSrpFailInfo_t *failInfo);

openavbRC strmAttachCb(void* pv,
							 openavbSrpLsnrDeclSubtype_t lsnrDecl);


#include "openavb_endpoint_osal.h"


/**************************  Endpoint Client-Server  *************************/
// There is a single endpoint server for the entire talker/listener device
// There is an endpoint client for each stream.

// Endpoint client open a connection to endpoint server.
// (Note that the server never opens a connection to the client.)
int  openavbEptClntOpenSrvrConnection(tl_state_t *pTLState);
// Endpoint client close its connection to the server.
void openavbEptClntCloseSrvrConnection(int h);
// Endpoint server close its connection to the client.
void openavbEptSrvrCloseClientConnection(int h);

// Immediately after establishing connection with the endpoint server,
// the endpoint client checks that the server's version is the same as its own.
// The client sends a request to the cleint for its version.
// The server handles the request and sends its version to the requesting client.
// The clinet compares the recevied version to its own.
bool openavbEptClntRequestVersionFromServer(int h);
bool openavbEptSrvrHndlVerRqstFromClient(int h);
void openavbEptSrvrSendServerVersionToClient(int h, U32 AVBVersion);
void openavbEptClntCheckVerMatchesSrvr(int h, U32 AVBVersion);


// Each talker registers its stream with SRP via Endpoint.
// Endpoint communication is from client to server
bool openavbEptClntRegisterStream(int            h,
                              AVBStreamID_t *streamID,
                              U8             destAddr[],
                              AVBTSpec_t    *tSpec,
                              U8             srClass,
                              U8             srRank,
                              U32            latency,
                              U32            txRate);
bool openavbEptSrvrRegisterStream(int             h,
                              AVBStreamID_t  *streamID,
                              U8              destAddr[],
                              AVBTSpec_t     *tSpec,
                              U8              srClass,
                              U8              srRank,
                              U32             latency,
                              U32             txRate);

// Each lister attaches to the stream it wants to receive;
// specifically the listener indicates interest / declaration to SRP.
// Endpoint communication is from client to server.
bool openavbEptClntAttachStream(int                      h,
                            AVBStreamID_t           *streamID,
                            openavbSrpLsnrDeclSubtype_t  ld);
bool openavbEptSrvrAttachStream(int                      h,
                            AVBStreamID_t           *streamID,
                            openavbSrpLsnrDeclSubtype_t  ld);


// SRP notifies the talker when its stream has been established to taken down.
// Endpoint communication is from server to client.
void openavbEptSrvrNotifyTlkrOfSrpCb(int                      h,
                                 AVBStreamID_t           *streamID,
                                 char                    *ifname,
                                 U8                       destAddr[],
                                 openavbSrpLsnrDeclSubtype_t  lsnrDecl,
                                 U32                      classRate,
                                 U16                      vlanID,
                                 U8                       priority,
                                 U16                      fwmark);
void openavbEptClntNotifyTlkrOfSrpCb(int                      h,
                                 AVBStreamID_t           *streamID,
                                 char                    *ifname,
                                 U8                       destAddr[],
                                 openavbSrpLsnrDeclSubtype_t  lsnrDecl,
                                 U32                      classRate,
                                 U16                      vlanID,
                                 U8                       priority,
                                 U16                      fwmark);

// SRP notifies the listener when its stream is available, failed or gone away.
// Endpoint communication is from server to client.
void openavbEptSrvrNotifyLstnrOfSrpCb(int                 h,
                                  AVBStreamID_t      *streamID,
                                  char               *ifname,
                                  U8                  destAddr[],
                                  openavbSrpAttribType_t  tlkrDecl,
                                  AVBTSpec_t         *tSpec,
                                  U8                  srClass,
                                  U32                 latency,
                                  openavbSrpFailInfo_t   *failInfo);
void openavbEptClntNotifyLstnrOfSrpCb(int                 h,
                                  AVBStreamID_t      *streamID,
                                  char               *ifname,
                                  U8                  destAddr[],
                                  openavbSrpAttribType_t  tlkrDecl,
                                  AVBTSpec_t         *tSpec,
                                  U8                  srClass,
                                  U32                 latency,
                                  openavbSrpFailInfo_t   *failInfo);


// A talker can withdraw its stream registration at any time;
// a listener can withdraw its stream attachment at any time;
// in either case, endpoint communication is from client to server
bool openavbEptClntStopStream(int h, AVBStreamID_t *streamID);
bool openavbEptSrvrStopStream(int h, AVBStreamID_t *streamID);


#endif // OPENAVB_ENDPOINT_H