8 * This file defines the gPXE UDP API.
14 #include <gpxe/pkbuff.h>
15 #include <gpxe/if_ether.h>
21 #define UDP_MAX_HLEN 72
22 #define UDP_MAX_TXPKB ETH_MAX_MTU
23 #define UDP_MIN_TXPKB ETH_ZLEN
25 typedef uint16_t port_t;
37 struct udp_connection;
43 struct udp_operations {
48 * @v conn UDP connection
49 * @v buf Temporary data buffer
50 * @v len Length of temporary data buffer
52 * The application may use the temporary data buffer to
53 * construct the data to be sent. Note that merely filling
54 * the buffer will do nothing; the application must call
55 * udp_send() in order to actually transmit the data. Use of
56 * the buffer is not compulsory; the application may call
57 * udp_send() on any block of data.
59 void ( * senddata ) ( struct tcp_connection *conn, void *buf,
64 * @v conn UDP connection
66 * @v len Length of data
68 void ( * newdata ) ( struct udp_connection *conn,
69 void *data, size_t len );
76 struct udp_connection {
77 /** Address of the remote end of the connection */
79 /** Local port on which the connection receives packets */
81 /** Transmit buffer */
82 struct pk_buff *tx_pkb;
83 /** List of registered connections */
84 struct list_head list;
85 /** Operations table for this connection */
86 struct udp_operations *udp_op;
92 extern struct tcpip_protocol udp_protocol;
95 * Functions provided to the application layer
98 extern void udp_init ( struct udp_connection *conn, struct udp_operations *udp_op );
99 extern int udp_open ( struct udp_connection *conn, uint16_t local_port );
101 extern void udp_connect ( struct udp_connection *conn, struct sockaddr *peer );
102 extern void udp_close ( struct udp_connection *conn );
104 extern int udp_send ( struct udp_connection *conn, const void *data, size_t len );
105 extern int udp_sendto ( struct udp_connection *conn, struct sockaddr *peer, const void *data, size_t len );
107 static inline void * udp_buffer ( struct udp_connection *conn ) {
108 return conn->tx_pkb->data;
111 static inline int udp_buflen ( struct udp_connection *conn ) {
112 return pkb_len ( conn->tx_pkb );
115 #endif /* _GPXE_UDP_H */