|
@@ -16,6 +16,7 @@
|
16
|
16
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
17
|
17
|
*/
|
18
|
18
|
|
|
19
|
+#include <string.h>
|
19
|
20
|
#include <errno.h>
|
20
|
21
|
#include <gpxe/xfer.h>
|
21
|
22
|
|
|
@@ -39,23 +40,75 @@ int deliver ( struct xfer_interface *xfer, struct io_buffer *iobuf ) {
|
39
|
40
|
}
|
40
|
41
|
|
41
|
42
|
/**
|
42
|
|
- * Null deliver datagram
|
|
43
|
+ * Deliver datagram as raw data
|
43
|
44
|
*
|
44
|
45
|
* @v xfer Data-transfer interface
|
45
|
46
|
* @v src Source interface
|
46
|
47
|
* @v iobuf Datagram I/O buffer
|
47
|
48
|
* @ret rc Return status code
|
|
49
|
+ *
|
|
50
|
+ * This function is intended to be used as the deliver() method for
|
|
51
|
+ * data transfer interfaces that prefer to handle raw data.
|
48
|
52
|
*/
|
49
|
|
-static int null_deliver ( struct xfer_interface *xfer __unused,
|
50
|
|
- struct xfer_interface *src __unused,
|
51
|
|
- struct io_buffer *iobuf ) {
|
|
53
|
+int deliver_as_raw ( struct xfer_interface *xfer,
|
|
54
|
+ struct xfer_interface *src,
|
|
55
|
+ struct io_buffer *iobuf ) {
|
|
56
|
+ int rc;
|
|
57
|
+
|
|
58
|
+ rc = xfer->op->deliver_raw ( xfer, src, iobuf->data,
|
|
59
|
+ iob_len ( iobuf ) );
|
52
|
60
|
free_iob ( iobuf );
|
|
61
|
+ return rc;
|
|
62
|
+}
|
|
63
|
+
|
|
64
|
+/**
|
|
65
|
+ * Deliver datagram as I/O buffer
|
|
66
|
+ *
|
|
67
|
+ * @v xfer Data-transfer interface
|
|
68
|
+ * @v src Source interface
|
|
69
|
+ * @v data Data buffer
|
|
70
|
+ * @v len Length of data buffer
|
|
71
|
+ * @ret rc Return status code
|
|
72
|
+ *
|
|
73
|
+ * This function is intended to be used as the deliver_raw() method
|
|
74
|
+ * for data transfer interfaces that prefer to handle I/O buffers.
|
|
75
|
+ */
|
|
76
|
+int deliver_as_iobuf ( struct xfer_interface *xfer,
|
|
77
|
+ struct xfer_interface *src,
|
|
78
|
+ const void *data, size_t len ) {
|
|
79
|
+ struct io_buffer *iobuf;
|
|
80
|
+
|
|
81
|
+#warning "Do we need interface-specific I/O buffer allocation?"
|
|
82
|
+ iobuf = alloc_iob ( len );
|
|
83
|
+ if ( ! iobuf )
|
|
84
|
+ return -ENOMEM;
|
|
85
|
+
|
|
86
|
+ memcpy ( iob_put ( iobuf, len ), data, len );
|
|
87
|
+ return xfer->op->deliver ( xfer, src, iobuf );
|
|
88
|
+}
|
|
89
|
+
|
|
90
|
+/**
|
|
91
|
+ * Null deliver datagram as raw data
|
|
92
|
+ *
|
|
93
|
+ * @v xfer Data-transfer interface
|
|
94
|
+ * @v src Source interface
|
|
95
|
+ * @v data Data buffer
|
|
96
|
+ * @v len Length of data buffer
|
|
97
|
+ * @ret rc Return status code
|
|
98
|
+ */
|
|
99
|
+static int null_deliver_raw ( struct xfer_interface *xfer,
|
|
100
|
+ struct xfer_interface *src,
|
|
101
|
+ const void *data __unused, size_t len ) {
|
|
102
|
+ DBGC ( src, "XFER %p->%p %zd bytes delivered %s\n", src, xfer, len,
|
|
103
|
+ ( ( xfer == &null_xfer ) ?
|
|
104
|
+ "before connection" : "after termination" ) );
|
53
|
105
|
return -EPIPE;
|
54
|
106
|
}
|
55
|
107
|
|
56
|
108
|
/** Null data transfer interface operations */
|
57
|
109
|
struct xfer_interface_operations null_xfer_ops = {
|
58
|
|
- .deliver = null_deliver,
|
|
110
|
+ .deliver = deliver_as_raw,
|
|
111
|
+ .deliver_raw = null_deliver_raw,
|
59
|
112
|
};
|
60
|
113
|
|
61
|
114
|
/**
|