1 #ifndef _IPXE_ONCRPC_IOB_H
2 #define _IPXE_ONCRPC_IOB_H
3 
4 #include <stdint.h>
5 #include <string.h>
6 #include <ipxe/iobuf.h>
7 #include <ipxe/refcnt.h>
8 #include <ipxe/oncrpc.h>
9 
10 /** @file
11  *
12  * SUN ONC RPC protocol.
13  *
14  */
15 
16 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
17 
18 /**
19  * Add a string to the end of an I/O buffer
20  *
21  * @v io_buf            I/O buffer
22  * @v val               String
23  * @ret size            Size of the data written
24  */
25 #define oncrpc_iob_add_string( buf, str ) \
26 ( { \
27 	const char * _str = (str); \
28 	oncrpc_iob_add_array ( (buf), strlen ( _str ), _str ); \
29 } )
30 
31 /**
32  * Get a 32 bits integer from the beginning of an I/O buffer
33  *
34  * @v buf               I/O buffer
35  * @ret int             Integer
36  */
37 
38 #define oncrpc_iob_get_int( buf ) \
39 ( { \
40 	uint32_t *_val; \
41 	_val = (buf)->data; \
42 	iob_pull ( (buf), sizeof ( uint32_t ) ); \
43 	ntohl ( *_val ); \
44 } )
45 
46 /**
47  * Get a 64 bits integer from the beginning of an I/O buffer
48  *
49  * @v buf               I/O buffer
50  * @ret int             Integer
51  */
52 #define oncrpc_iob_get_int64( buf ) \
53 ( { \
54 	uint64_t *_val; \
55 	_val = (buf)->data; \
56 	iob_pull ( (buf), sizeof ( uint64_t ) ); \
57 	ntohll ( *_val ); \
58 } )
59 
60 
61 size_t oncrpc_iob_add_fields ( struct io_buffer *io_buf,
62                                const struct oncrpc_field fields[] );
63 
64 size_t oncrpc_iob_add_array ( struct io_buffer *io_buf, size_t length,
65                               const void *data );
66 
67 size_t oncrpc_iob_add_intarray ( struct io_buffer *io_buf, size_t length,
68                                  const uint32_t *array );
69 
70 size_t oncrpc_iob_add_cred ( struct io_buffer *io_buf,
71                              const struct oncrpc_cred *cred );
72 
73 size_t oncrpc_iob_get_cred ( struct io_buffer *io_buf,
74                              struct oncrpc_cred *cred );
75 
76 /**
77  * Add a 32 bits integer to the end of an I/O buffer
78  *
79  * @v io_buf            I/O buffer
80  * @v val               Integer
81  * @ret size            Size of the data written
82  */
oncrpc_iob_add_int(struct io_buffer * io_buf,uint32_t val)83 static inline size_t oncrpc_iob_add_int ( struct io_buffer *io_buf,
84                                           uint32_t val ) {
85 	* ( uint32_t * ) iob_put ( io_buf, sizeof ( val ) ) = htonl ( val );
86 	return ( sizeof ( val) );
87 }
88 
89 /**
90  * Add a 64 bits integer to the end of an I/O buffer
91  *
92  * @v io_buf            I/O buffer
93  * @v val               Integer
94  * @ret size            Size of the data written
95  */
oncrpc_iob_add_int64(struct io_buffer * io_buf,uint64_t val)96 static inline size_t oncrpc_iob_add_int64 ( struct io_buffer *io_buf,
97                                             uint64_t val ) {
98 	* ( uint64_t * ) iob_put ( io_buf, sizeof ( val ) ) = htonll ( val );
99 	return ( sizeof ( val) );
100 }
101 
102 #endif /* _IPXE_ONCRPC_IOB_H */
103