1a74702c6SGeorge Wang/* Copyright (c) 2017 - 2022 LiteSpeed Technologies Inc.  See LICENSE. */
250aadb33SDmitri Tikhonov#ifndef LSQUIC_PARSE_GQUIC_BE_H
350aadb33SDmitri Tikhonov#define LSQUIC_PARSE_GQUIC_BE_H
450aadb33SDmitri Tikhonov
550aadb33SDmitri Tikhonov/* Header file to make it easy to reference gQUIC parsing functions.  This
650aadb33SDmitri Tikhonov * is only meant to be used internally.  The alternative would be to place
750aadb33SDmitri Tikhonov * all gQUIC-big-endian functions -- from all versions -- in a single file,
850aadb33SDmitri Tikhonov * and that would be a mess.
950aadb33SDmitri Tikhonov */
1050aadb33SDmitri Tikhonov
1150aadb33SDmitri Tikhonov#define CHECK_SPACE(need, pstart, pend)  \
1250aadb33SDmitri Tikhonov    do { if ((intptr_t) (need) > ((pend) - (pstart))) { return -1; } } while (0)
1350aadb33SDmitri Tikhonov
1450aadb33SDmitri Tikhonovuint64_t
15a5fa05f9SDmitri Tikhonovlsquic_gquic_be_read_float_time16 (const void *mem);
1650aadb33SDmitri Tikhonov
1750aadb33SDmitri Tikhonovvoid
18a5fa05f9SDmitri Tikhonovlsquic_gquic_be_write_float_time16 (lsquic_time_t time_us, void *mem);
1950aadb33SDmitri Tikhonov
2050aadb33SDmitri Tikhonovvoid
21a5fa05f9SDmitri Tikhonovlsquic_gquic_be_parse_packet_in_finish (lsquic_packet_in_t *packet_in,
2250aadb33SDmitri Tikhonov                                            struct packin_parse_state *state);
2350aadb33SDmitri Tikhonov
2450aadb33SDmitri Tikhonovint
25a5fa05f9SDmitri Tikhonovlsquic_gquic_be_gen_ver_nego_pkt (unsigned char *buf, size_t bufsz,
265392f7a3SLiteSpeed Tech                    const lsquic_cid_t *, unsigned version_bitmask);
2750aadb33SDmitri Tikhonov
2850aadb33SDmitri Tikhonovint
29a5fa05f9SDmitri Tikhonovlsquic_gquic_be_gen_stream_frame (unsigned char *buf, size_t buf_len,
305392f7a3SLiteSpeed Tech    lsquic_stream_id_t stream_id, uint64_t offset, int fin, size_t size,
315392f7a3SLiteSpeed Tech    gsf_read_f gsf_read, void *stream);
3250aadb33SDmitri Tikhonov
3350aadb33SDmitri Tikhonovint
34a5fa05f9SDmitri Tikhonovlsquic_gquic_be_parse_stream_frame (const unsigned char *buf, size_t rem_packet_sz,
3550aadb33SDmitri Tikhonov                       stream_frame_t *stream_frame);
3650aadb33SDmitri Tikhonov
3750aadb33SDmitri Tikhonovlsquic_packno_t
38a5fa05f9SDmitri Tikhonovlsquic_gquic_be_parse_ack_high (const unsigned char *buf, size_t buf_len);
3950aadb33SDmitri Tikhonov
4050aadb33SDmitri Tikhonovint
41a5fa05f9SDmitri Tikhonovlsquic_gquic_be_parse_ack_frame (const unsigned char *buf, size_t buf_len,
425392f7a3SLiteSpeed Tech                                                struct ack_info *, uint8_t);
4350aadb33SDmitri Tikhonov
4450aadb33SDmitri Tikhonovint
45a5fa05f9SDmitri Tikhonovlsquic_gquic_be_gen_stop_waiting_frame(unsigned char *buf, size_t buf_len,
46c7d81ce1SDmitri Tikhonov                lsquic_packno_t cur_packno, enum packno_bits bits,
4750aadb33SDmitri Tikhonov                lsquic_packno_t least_unacked_packno);
4850aadb33SDmitri Tikhonov
4950aadb33SDmitri Tikhonovint
50a5fa05f9SDmitri Tikhonovlsquic_gquic_be_parse_stop_waiting_frame (const unsigned char *buf, size_t buf_len,
51c7d81ce1SDmitri Tikhonov                 lsquic_packno_t cur_packno, enum packno_bits bits,
5250aadb33SDmitri Tikhonov                 lsquic_packno_t *least_unacked);
5350aadb33SDmitri Tikhonov
5450aadb33SDmitri Tikhonovint
55a5fa05f9SDmitri Tikhonovlsquic_gquic_be_skip_stop_waiting_frame (size_t buf_len, enum packno_bits bits);
5650aadb33SDmitri Tikhonov
5750aadb33SDmitri Tikhonovint
58a5fa05f9SDmitri Tikhonovlsquic_gquic_be_gen_window_update_frame (unsigned char *buf, int buf_len,
595392f7a3SLiteSpeed Tech                            lsquic_stream_id_t stream_id, uint64_t offset);
6050aadb33SDmitri Tikhonov
6150aadb33SDmitri Tikhonovint
62a5fa05f9SDmitri Tikhonovlsquic_gquic_be_parse_window_update_frame (const unsigned char *buf, size_t buf_len,
635392f7a3SLiteSpeed Tech                              lsquic_stream_id_t *stream_id, uint64_t *offset);
6450aadb33SDmitri Tikhonov
6550aadb33SDmitri Tikhonovint
66a5fa05f9SDmitri Tikhonovlsquic_gquic_be_gen_blocked_frame (unsigned char *buf, size_t buf_len,
675392f7a3SLiteSpeed Tech                            lsquic_stream_id_t stream_id);
6850aadb33SDmitri Tikhonov
6950aadb33SDmitri Tikhonovint
70a5fa05f9SDmitri Tikhonovlsquic_gquic_be_parse_blocked_frame (const unsigned char *buf, size_t buf_len,
715392f7a3SLiteSpeed Tech                                                lsquic_stream_id_t *stream_id);
7250aadb33SDmitri Tikhonov
7350aadb33SDmitri Tikhonovint
74a5fa05f9SDmitri Tikhonovlsquic_gquic_be_gen_rst_frame (unsigned char *buf, size_t buf_len,
755392f7a3SLiteSpeed Tech        lsquic_stream_id_t stream_id, uint64_t offset, uint64_t error_code);
7650aadb33SDmitri Tikhonov
7750aadb33SDmitri Tikhonovint
78a5fa05f9SDmitri Tikhonovlsquic_gquic_be_parse_rst_frame (const unsigned char *buf, size_t buf_len,
795392f7a3SLiteSpeed Tech    lsquic_stream_id_t *stream_id, uint64_t *offset, uint64_t *error_code);
8050aadb33SDmitri Tikhonov
8150aadb33SDmitri Tikhonovint
82a5fa05f9SDmitri Tikhonovlsquic_gquic_be_gen_ping_frame (unsigned char *buf, int buf_len);
8350aadb33SDmitri Tikhonov
847d09751dSDmitri Tikhonovsize_t
85a5fa05f9SDmitri Tikhonovlsquic_gquic_be_connect_close_frame_size (int app_error, unsigned error_code,
867d09751dSDmitri Tikhonov                                unsigned frame_type, size_t reason_len);
877d09751dSDmitri Tikhonov
8850aadb33SDmitri Tikhonovint
89a5fa05f9SDmitri Tikhonovlsquic_gquic_be_gen_connect_close_frame (unsigned char *buf, size_t buf_len,
905392f7a3SLiteSpeed Tech    int app_error, unsigned error_code, const char *reason, int reason_len);
9150aadb33SDmitri Tikhonov
9250aadb33SDmitri Tikhonovint
93a5fa05f9SDmitri Tikhonovlsquic_gquic_be_parse_connect_close_frame (const unsigned char *buf, size_t buf_len,
945392f7a3SLiteSpeed Tech        int *app_error, uint64_t *error_code,
955392f7a3SLiteSpeed Tech        uint16_t *reason_len, uint8_t *reason_offset);
9650aadb33SDmitri Tikhonov
9750aadb33SDmitri Tikhonovint
98a5fa05f9SDmitri Tikhonovlsquic_gquic_be_gen_goaway_frame(unsigned char *buf, size_t buf_len, uint32_t error_code,
995392f7a3SLiteSpeed Tech                     lsquic_stream_id_t last_good_stream_id, const char *reason,
10050aadb33SDmitri Tikhonov                     size_t reason_len);
10150aadb33SDmitri Tikhonov
10250aadb33SDmitri Tikhonovint
103a5fa05f9SDmitri Tikhonovlsquic_gquic_be_parse_goaway_frame (const unsigned char *buf, size_t buf_len,
1045392f7a3SLiteSpeed Tech               uint32_t *error_code, lsquic_stream_id_t *last_good_stream_id,
10550aadb33SDmitri Tikhonov                       uint16_t *reason_length, const char **reason);
10650aadb33SDmitri Tikhonov
10750aadb33SDmitri Tikhonovint
108a5fa05f9SDmitri Tikhonovlsquic_gquic_be_gen_ack_frame (unsigned char *outbuf, size_t outbuf_sz,
10950aadb33SDmitri Tikhonov        gaf_rechist_first_f rechist_first, gaf_rechist_next_f rechist_next,
11050aadb33SDmitri Tikhonov        gaf_rechist_largest_recv_f rechist_largest_recv,
1115392f7a3SLiteSpeed Tech        void *rechist, lsquic_time_t now, int *has_missing, lsquic_packno_t *,
1125392f7a3SLiteSpeed Tech        const uint64_t *);
11350aadb33SDmitri Tikhonov
1142f2f4363SDmitri Tikhonovint
1152f2f4363SDmitri Tikhonovlsquic_gquic_be_dec_stream_frame_size (unsigned char *buf, size_t new_size);
1162f2f4363SDmitri Tikhonov
11750aadb33SDmitri Tikhonov#endif
118