[sundance] Add reset completion check
[gpxe.git] / src / include / gpxe / tcpip.h
blobda89530e68cf814b69f02ca6fa9642b69ce113fb
1 #ifndef _GPXE_TCPIP_H
2 #define _GPXE_TCPIP_H
4 /** @file
6 * Transport-network layer interface
8 */
10 #include <stdint.h>
11 #include <gpxe/socket.h>
12 #include <gpxe/in.h>
13 #include <gpxe/tables.h>
15 struct io_buffer;
16 struct net_device;
18 /** Empty checksum value
20 * This is the TCP/IP checksum over a zero-length block of data.
22 #define TCPIP_EMPTY_CSUM 0xffff
24 /**
25 * TCP/IP socket address
27 * This contains the fields common to socket addresses for all TCP/IP
28 * address families.
30 struct sockaddr_tcpip {
31 /** Socket address family (part of struct @c sockaddr) */
32 sa_family_t st_family;
33 /** TCP/IP port */
34 uint16_t st_port;
35 /** Padding
37 * This ensures that a struct @c sockaddr_tcpip is large
38 * enough to hold a socket address for any TCP/IP address
39 * family.
41 char pad[ sizeof ( struct sockaddr ) -
42 ( sizeof ( sa_family_t ) + sizeof ( uint16_t ) ) ];
43 } __attribute__ (( may_alias ));
45 /**
46 * A transport-layer protocol of the TCP/IP stack (eg. UDP, TCP, etc)
48 struct tcpip_protocol {
49 /** Protocol name */
50 const char *name;
51 /**
52 * Process received packet
54 * @v iobuf I/O buffer
55 * @v st_src Partially-filled source address
56 * @v st_dest Partially-filled destination address
57 * @v pshdr_csum Pseudo-header checksum
58 * @ret rc Return status code
60 * This method takes ownership of the I/O buffer.
62 int ( * rx ) ( struct io_buffer *iobuf, struct sockaddr_tcpip *st_src,
63 struct sockaddr_tcpip *st_dest, uint16_t pshdr_csum );
64 /**
65 * Transport-layer protocol number
67 * This is a constant of the type IP_XXX
69 uint8_t tcpip_proto;
72 /**
73 * A network-layer protocol of the TCP/IP stack (eg. IPV4, IPv6, etc)
75 struct tcpip_net_protocol {
76 /** Protocol name */
77 const char *name;
78 /** Network address family */
79 sa_family_t sa_family;
80 /**
81 * Transmit packet
83 * @v iobuf I/O buffer
84 * @v tcpip_protocol Transport-layer protocol
85 * @v st_src Source address, or NULL to use default
86 * @v st_dest Destination address
87 * @v netdev Network device (or NULL to route automatically)
88 * @v trans_csum Transport-layer checksum to complete, or NULL
89 * @ret rc Return status code
91 * This function takes ownership of the I/O buffer.
93 int ( * tx ) ( struct io_buffer *iobuf,
94 struct tcpip_protocol *tcpip_protocol,
95 struct sockaddr_tcpip *st_src,
96 struct sockaddr_tcpip *st_dest,
97 struct net_device *netdev,
98 uint16_t *trans_csum );
101 /** Declare a TCP/IP transport-layer protocol */
102 #define __tcpip_protocol \
103 __table ( struct tcpip_protocol, tcpip_protocols, 01 )
105 /** Declare a TCP/IP network-layer protocol */
106 #define __tcpip_net_protocol \
107 __table ( struct tcpip_net_protocol, tcpip_net_protocols, 01 )
109 extern int tcpip_rx ( struct io_buffer *iobuf, uint8_t tcpip_proto,
110 struct sockaddr_tcpip *st_src,
111 struct sockaddr_tcpip *st_dest, uint16_t pshdr_csum );
112 extern int tcpip_tx ( struct io_buffer *iobuf, struct tcpip_protocol *tcpip,
113 struct sockaddr_tcpip *st_src,
114 struct sockaddr_tcpip *st_dest,
115 struct net_device *netdev,
116 uint16_t *trans_csum );
117 extern uint16_t tcpip_continue_chksum ( uint16_t partial,
118 const void *data, size_t len );
119 extern uint16_t tcpip_chksum ( const void *data, size_t len );
121 #endif /* _GPXE_TCPIP_H */