summaryrefslogtreecommitdiffstats
path: root/qemu/roms/ipxe/src/include/ipxe/xfer.h
blob: 1167e5cba8d6484aa0d4bde126639b9b108184ce (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
#ifndef _IPXE_XFER_H
#define _IPXE_XFER_H

/** @file
 *
 * Data transfer interfaces
 *
 */

FILE_LICENCE ( GPL2_OR_LATER );

#include <stddef.h>
#include <stdarg.h>
#include <ipxe/interface.h>

struct xfer_metadata;
struct io_buffer;
struct sockaddr;
struct net_device;

/** Data transfer metadata */
struct xfer_metadata {
	/** Flags
	 *
	 * This is the bitwise OR of zero or more @c XFER_FL_XXX
	 * constants.
	 */
	unsigned int flags;
	/** Offset of data within stream
	 *
	 * This is an absolute offset if the @c XFER_FL_ABS_OFFSET
	 * flag is set, otherwise a relative offset.  (A freshly
	 * zeroed @c xfer_metadata structure therefore represents a
	 * relative offset of zero, i.e. no offset from the current
	 * position.)
	 */
	off_t offset;
	/** Source socket address, or NULL */
	struct sockaddr *src;
	/** Destination socket address, or NULL */
	struct sockaddr *dest;
	/** Network device, or NULL */
	struct net_device *netdev;
};

/** Offset is absolute */
#define XFER_FL_ABS_OFFSET 0x0001

/** Sender is relinquishing use of half-duplex channel */
#define XFER_FL_OVER 0x0002

/** This is the final data transfer */
#define XFER_FL_OUT 0x0004

/** Data content represents a command or status message
 *
 * The flag @c XFER_FL_RESPONSE is used to distinguish between a
 * command message and a status message.
 */
#define XFER_FL_CMD_STAT 0x0008

/** Data content is a response */
#define XFER_FL_RESPONSE 0x0010

/* Data transfer interface operations */

extern int xfer_vredirect ( struct interface *intf, int type,
			    va_list args );
#define xfer_vredirect_TYPE( object_type ) \
	typeof ( int ( object_type, int type, va_list args ) )

extern size_t xfer_window ( struct interface *intf );
#define xfer_window_TYPE( object_type ) \
	typeof ( size_t ( object_type ) )

extern void xfer_window_changed ( struct interface *intf );
#define xfer_window_changed_TYPE( object_type ) \
	typeof ( void ( object_type ) )

extern struct io_buffer * xfer_alloc_iob ( struct interface *intf,
					   size_t len );
#define xfer_alloc_iob_TYPE( object_type ) \
	typeof ( struct io_buffer * ( object_type, size_t len ) )

extern int xfer_deliver ( struct interface *intf,
			  struct io_buffer *iobuf,
			  struct xfer_metadata *meta );
#define xfer_deliver_TYPE( object_type )			\
	typeof ( int ( object_type, struct io_buffer *iobuf,	\
		       struct xfer_metadata *meta ) )

/* Data transfer interface helper functions */

extern int xfer_redirect ( struct interface *xfer, int type, ... );
extern int xfer_deliver_iob ( struct interface *intf,
			      struct io_buffer *iobuf );
extern int xfer_deliver_raw_meta ( struct interface *intf, const void *data,
				   size_t len, struct xfer_metadata *meta );
extern int xfer_deliver_raw ( struct interface *intf,
			      const void *data, size_t len );
extern int xfer_vprintf ( struct interface *intf,
			  const char *format, va_list args );
extern int __attribute__ (( format ( printf, 2, 3 ) ))
xfer_printf ( struct interface *intf, const char *format, ... );
extern int xfer_seek ( struct interface *intf, off_t offset );

#endif /* _IPXE_XFER_H */